@memberjunction/skip-types v2.48.0
MemberJunction Skip Types
Type 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.
Overview
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.
Installation
npm install @memberjunction/skip-types
Key Components
Request 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
Response Types
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
Message and Conversation Types
SkipMessage
- Individual message in a conversation with Skip- Includes role, content, conversationDetailID
- Optional: error, hiddenToUser, userRating, userFeedback, reflectionInsights
SkipConversation
- Collection of messages forming a conversation- Includes id, name, userId, messages array
- Optional: description, artifacts
Component Types
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 events
SkipComponentInitFunction
- Initialization function for componentsSkipComponentObject
- Interface exposed by componentsSkipComponentOption
- Alternative component optionsSimpleDataContext
- Simplified data context for components
Learning Cycle Types
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
Data Types
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 entity
SkipSubProcessResponse
- 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
Specialized Response Types
SkipAPIAnalysisCompleteResponse
- Response for completed analysis- Includes dataContext, resultType, executionResults
- Optional: component, drillDown, scriptText, newDataItems
SkipAPIClarifyingQuestionResponse
- 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
Artifact Types
SkipAPIArtifact
- Artifact information with versionsSkipAPIArtifactType
- Artifact type definitionSkipAPIArtifactVersion
- Version information for artifactsSkipAPIArtifactRequest
- Request to create/update artifacts
Usage Examples
Creating a Skip API Request
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"
}
]
};
Handling Skip API Responses
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);
}
}
Working with Skip Components and Callbacks
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);
// Set up event handlers that use callbacks
document.getElementById('refresh').addEventListener('click', () => {
callbacks?.RefreshData();
});
document.getElementById('open-record').addEventListener('click', () => {
callbacks?.OpenEntityRecord('Customer', { ID: 123 });
});
// Update user state when something changes
const newState = { selectedRegion: 'North' };
callbacks?.UpdateUserState(newState);
};
// Register the init function globally so it can be called from the container
window.initSkipComponent = initComponent;
Working with Learning Cycles
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);
}
}
Supported LLM Vendors
The vendorDriverName
in SkipAPIRequestAPIKey
supports the following AI providers:
OpenAILLM
- OpenAI modelsMistralLLM
- Mistral AI modelsGeminiLLM
- Google Gemini modelsAnthropicLLM
- Anthropic Claude modelsGroqLLM
- Groq models
Dependencies
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
TypeScript Configuration
This package is built with TypeScript and includes type definitions. No additional @types packages are required.
Contributing
Contributions to extend or improve the type definitions are welcome. Please ensure that any additions maintain backward compatibility and follow the established naming conventions.
Naming Conventions
- Use PascalCase for class and interface names
- Prefix Skip-specific types with
Skip
- Use descriptive names that clearly indicate the type's purpose
- Group related types together in the source file
License
ISC
8 months ago
4 months ago
8 months ago
6 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
6 months ago
6 months ago
5 months ago
8 months ago
8 months ago
8 months ago
6 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
5 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
9 months ago
5 months ago
9 months ago
9 months ago
9 months ago
9 months ago
8 months ago
7 months ago
5 months ago
9 months ago
9 months ago
5 months ago
5 months ago
8 months ago
8 months ago
7 months ago
9 months ago
9 months ago
9 months ago
5 months ago
5 months ago
8 months ago
8 months ago
5 months ago
6 months ago
10 months ago
5 months ago
8 months ago
4 months ago
10 months ago
6 months ago
11 months ago
10 months ago
11 months ago
6 months ago
11 months ago
4 months ago
8 months ago
8 months ago
12 months ago
6 months ago
6 months ago
8 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago