MemberJunction: Skip AI Assistant - Types that are used between the MJAPI and the Skip API as well as the UI within MemberJunction Explorer
npm install @memberjunction/skip-typesType definitions and interfaces for the Skip AI Assistant integration with MemberJunction. This package provides the contract between the MemberJunction API, Skip API, and the MemberJunction Explorer UI.
The @memberjunction/skip-types package contains TypeScript type definitions, interfaces, and enums that facilitate communication between different components of the MemberJunction Skip AI assistant system. It ensures type safety and consistent data structures when interacting with the Skip API or rendering Skip-generated content in MemberJunction applications.
``bash`
npm install @memberjunction/skip-types
Types used for making requests to the Skip API:
- SkipAPIRequest - Base interface for Skip API requestsSkipAPIRequestAPIKey
- - API key configuration for LLM vendorsSkipAPIRunScriptRequest
- - Request to run an existing scriptSkipRequestPhase
- - Defines the different phases of Skip requests:initial_request
- - Starting a new conversation or after component creationclarify_question_response
- - Responding to Skip's clarifying questionsdata_gathering_response
- - Returning requested data to Skipdata_gathering_failure
- - Reporting data gathering errorsrun_existing_script
- - Running previously processed scriptschat_with_a_record
- - Simple record chatting feature
Types used for handling responses from the Skip API:
- SkipAPIResponse - Base interface for Skip API responsesMJAPISkipResult
- - Response format from MJAPI to the UISkipResponsePhase
- - Defines the different phases of Skip responses:status_update
- - Status update during processingclarifying_question
- - Skip needs more informationdata_request
- - Skip needs additional dataanalysis_complete
- - Analysis finished with resultschat_with_a_record_complete
- - Record chat completed
- SkipMessage - Individual message in a conversation with SkipSkipConversation
- Includes role, content, conversationDetailID
- Optional: error, hiddenToUser, userRating, userFeedback, reflectionInsights
- - Collection of messages forming a conversation
- Includes id, name, userId, messages array
- Optional: description, artifacts
Types for Skip-generated components and visualizations:
- SkipComponent - Component generated by SkipSkipComponentCallbacks
- - Interface for callbacks from components:RefreshData()
- - Refresh the data contextOpenEntityRecord(entityName, key)
- - Open a specific recordUpdateUserState(userState)
- - Update user-specific stateNotifyEvent(eventName, eventData)
- - Send custom eventsSkipComponentInitFunction
- - Initialization function for componentsSkipComponentObject
- - Interface exposed by componentsSkipComponentOption
- - Alternative component optionsSimpleDataContext
- - Simplified data context for components
- SkipAPILearningCycleRequest - Request for Skip to learn from conversation historySkipAPILearningCycleResponse
- - Response from learning cycle processingSkipAPIAgentNote
- - Notes that Skip can generate during learningSkipAPIAgentNoteType
- - Types of notes Skip can generateSkipAPIAgentRequest
- - Format for Skip's human-in-the-loop requestsSkipLearningCycleQueryChange
- - Query changes during learningSkipLearningCycleRequestChange
- - Request changes during learningSkipLearningCycleNoteChange
- - Note changes during learning
- SkipDataRequest - Format for Skip to request additional dataSkipDataRequestType
- - Types of data requests Skip can make:sql
- - Fully executable SQL statementstored_query
- - Stored query from Queries entitySkipSubProcessResponse
- - Results from sandboxed script executionSkipEntityInfo
- - Entity metadata information for SkipSkipEntityFieldInfo
- - Field metadata for entitiesSkipEntityFieldValueInfo
- - Possible values for entity fieldsSkipEntityRelationshipInfo
- - Relationship metadata for entitiesSkipQueryInfo
- - Stored query informationSkipQueryFieldInfo
- - Field information for queriesSkipColumnInfo
- - Column information for report data
- SkipAPIAnalysisCompleteResponse - Response for completed analysisSkipAPIClarifyingQuestionResponse
- Includes dataContext, resultType, executionResults
- Optional: component, drillDown, scriptText, newDataItems
- - Response when Skip needs clarificationSkipAPIDataRequestResponse
- - Response when Skip needs more dataSkipAPIChatWithRecordResponse
- - Response for chat-with-record featureSkipAPIAnalysisDrillDown
- - Drill-down information for reportsSkipAPIAnalysisDrillDownFilter
- - Individual drill-down filter
- SkipAPIArtifact - Artifact information with versionsSkipAPIArtifactType
- - Artifact type definitionSkipAPIArtifactVersion
- - Version information for artifactsSkipAPIArtifactRequest
- - Request to create/update artifacts
`typescript
import {
SkipAPIRequest,
SkipMessage,
SkipRequestPhase
} from '@memberjunction/skip-types';
// Create a new Skip API request
const request: SkipAPIRequest = {
messages: [
{
role: "user",
content: "Show me sales by region from last quarter",
conversationDetailID: "12345"
}
],
dataContext: myDataContext,
entities: myEntityMetadata,
queries: myStoredQueries,
conversationID: "conv-123",
organizationID: "org-456",
requestPhase: SkipRequestPhase.initial_request,
apiKeys: [
{
vendorDriverName: "AnthropicLLM",
apiKey: "YOUR_API_KEY"
}
]
};
`
`typescript
import {
MJAPISkipResult,
SkipAPIAnalysisCompleteResponse,
SkipResponsePhase
} from '@memberjunction/skip-types';
function handleSkipResponse(result: MJAPISkipResult) {
if (result.Success) {
if (result.ResponsePhase === SkipResponsePhase.analysis_complete) {
// Parse the result JSON into the appropriate type
const response = JSON.parse(result.Result) as SkipAPIAnalysisCompleteResponse;
// Now you can access the analysis results
console.log("Report title:", response.reportTitle);
console.log("Analysis:", response.analysis);
// Handle different result types
if (response.resultType === "data") {
// Handle table data from executionResults.tableData
displayTable(response.executionResults.tableData);
} else if (response.resultType === "plot") {
// Handle plot data from executionResults.plotData
renderPlot(response.executionResults.plotData);
} else if (response.resultType === "html") {
// Handle custom component
renderComponent(response.component);
}
} else if (result.ResponsePhase === SkipResponsePhase.clarifying_question) {
// Handle clarifying questions
const questionResponse = JSON.parse(result.Result) as SkipAPIClarifyingQuestionResponse;
promptUserForAnswer(questionResponse.clarifyingQuestion);
} else if (result.ResponsePhase === SkipResponsePhase.data_request) {
// Handle data requests
const dataRequest = JSON.parse(result.Result) as SkipAPIDataRequestResponse;
fetchAdditionalData(dataRequest.dataRequest);
}
} else {
console.error("Skip API request failed:", result.Status);
}
}
`
`typescript
import {
SkipComponentInitFunction,
SimpleDataContext,
SkipComponentCallbacks
} from '@memberjunction/skip-types';
// Init function that would be called by the container application
const initComponent: SkipComponentInitFunction = (
data: SimpleDataContext,
userState?: any,
callbacks?: SkipComponentCallbacks
) => {
// Initialize the component with the data
renderChart(data.data_item_1);
document.getElementById('open-record').addEventListener('click', () => {
callbacks?.OpenEntityRecord('Customer', { ID: 123 });
});
};
// Register the init function globally so it can be called from the container
window.initSkipComponent = initComponent;
`
`typescript
import {
SkipAPILearningCycleRequest,
SkipAPILearningCycleResponse,
SkipConversation
} from '@memberjunction/skip-types';
// Create a learning cycle request
const learningRequest: SkipAPILearningCycleRequest = {
organizationId: "org-456",
learningCycleId: "cycle-123",
newConversations: conversationsSinceLastCycle,
entities: entityMetadata,
queries: storedQueries,
notes: existingNotes,
noteTypes: availableNoteTypes,
requests: existingRequests,
lastLearningCycleDate: lastCycleDate,
apiKeys: [
{
vendorDriverName: "AnthropicLLM",
apiKey: "YOUR_API_KEY"
}
]
};
// Handle learning cycle response
function handleLearningResponse(response: SkipAPILearningCycleResponse) {
if (response.success) {
// Process note changes
response.noteChanges.forEach(change => {
if (change.changeType === 'add') {
addNote(change.note);
} else if (change.changeType === 'update') {
updateNote(change.note);
} else if (change.changeType === 'delete') {
deleteNote(change.note);
}
});
// Process query changes
response.queryChanges.forEach(change => {
// Handle query additions, updates, deletions
});
// Process request changes
response.requestChanges.forEach(change => {
// Handle request changes
});
} else {
console.error("Learning cycle failed:", response.error);
}
}
`
The vendorDriverName in SkipAPIRequestAPIKey supports the following AI providers:OpenAILLM
- - OpenAI modelsMistralLLM
- - Mistral AI modelsGeminiLLM
- - Google Gemini modelsAnthropicLLM
- - Anthropic Claude modelsGroqLLM
- - Groq models
This package relies on the following MemberJunction packages:
- @memberjunction/core - Core MemberJunction types (CompositeKey)@memberjunction/core-entities
- - Core entity definitions@memberjunction/data-context
- - Data context types and utilities
This package is built with TypeScript and includes type definitions. No additional @types packages are required.
Contributions to extend or improve the type definitions are welcome. Please ensure that any additions maintain backward compatibility and follow the established naming conventions.
ISC