2.48.0 • Published 4 months ago

@memberjunction/skip-types v2.48.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

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 requests
  • SkipAPIRequestAPIKey - API key configuration for LLM vendors
  • SkipAPIRunScriptRequest - Request to run an existing script
  • SkipRequestPhase - Defines the different phases of Skip requests:
    • initial_request - Starting a new conversation or after component creation
    • clarify_question_response - Responding to Skip's clarifying questions
    • data_gathering_response - Returning requested data to Skip
    • data_gathering_failure - Reporting data gathering errors
    • run_existing_script - Running previously processed scripts
    • chat_with_a_record - Simple record chatting feature

Response Types

Types used for handling responses from the Skip API:

  • SkipAPIResponse - Base interface for Skip API responses
  • MJAPISkipResult - Response format from MJAPI to the UI
  • SkipResponsePhase - Defines the different phases of Skip responses:
    • status_update - Status update during processing
    • clarifying_question - Skip needs more information
    • data_request - Skip needs additional data
    • analysis_complete - Analysis finished with results
    • chat_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 Skip
  • SkipComponentCallbacks - Interface for callbacks from components:
    • RefreshData() - Refresh the data context
    • OpenEntityRecord(entityName, key) - Open a specific record
    • UpdateUserState(userState) - Update user-specific state
    • NotifyEvent(eventName, eventData) - Send custom events
  • SkipComponentInitFunction - Initialization function for components
  • SkipComponentObject - Interface exposed by components
  • SkipComponentOption - Alternative component options
  • SimpleDataContext - Simplified data context for components

Learning Cycle Types

  • SkipAPILearningCycleRequest - Request for Skip to learn from conversation history
  • SkipAPILearningCycleResponse - Response from learning cycle processing
  • SkipAPIAgentNote - Notes that Skip can generate during learning
  • SkipAPIAgentNoteType - Types of notes Skip can generate
  • SkipAPIAgentRequest - Format for Skip's human-in-the-loop requests
  • SkipLearningCycleQueryChange - Query changes during learning
  • SkipLearningCycleRequestChange - Request changes during learning
  • SkipLearningCycleNoteChange - Note changes during learning

Data Types

  • SkipDataRequest - Format for Skip to request additional data
  • SkipDataRequestType - Types of data requests Skip can make:
    • sql - Fully executable SQL statement
    • stored_query - Stored query from Queries entity
  • SkipSubProcessResponse - Results from sandboxed script execution
  • SkipEntityInfo - Entity metadata information for Skip
  • SkipEntityFieldInfo - Field metadata for entities
  • SkipEntityFieldValueInfo - Possible values for entity fields
  • SkipEntityRelationshipInfo - Relationship metadata for entities
  • SkipQueryInfo - Stored query information
  • SkipQueryFieldInfo - Field information for queries
  • SkipColumnInfo - 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 clarification
  • SkipAPIDataRequestResponse - Response when Skip needs more data
  • SkipAPIChatWithRecordResponse - Response for chat-with-record feature
  • SkipAPIAnalysisDrillDown - Drill-down information for reports
  • SkipAPIAnalysisDrillDownFilter - Individual drill-down filter

Artifact Types

  • SkipAPIArtifact - Artifact information with versions
  • SkipAPIArtifactType - Artifact type definition
  • SkipAPIArtifactVersion - Version information for artifacts
  • SkipAPIArtifactRequest - 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 models
  • MistralLLM - Mistral AI models
  • GeminiLLM - Google Gemini models
  • AnthropicLLM - Anthropic Claude models
  • GroqLLM - 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

2.23.2

8 months ago

2.46.0

4 months ago

2.23.1

8 months ago

2.34.0

6 months ago

2.19.4

9 months ago

2.19.5

9 months ago

2.19.2

9 months ago

2.19.3

9 months ago

2.19.0

9 months ago

2.19.1

9 months ago

2.34.2

6 months ago

2.34.1

6 months ago

2.45.0

5 months ago

2.22.1

8 months ago

2.22.0

8 months ago

2.22.2

8 months ago

2.33.0

6 months ago

2.18.3

9 months ago

2.18.1

9 months ago

2.18.2

9 months ago

2.18.0

9 months ago

2.21.0

9 months ago

2.44.0

5 months ago

2.29.0

7 months ago

2.29.2

7 months ago

2.29.1

7 months ago

2.32.0

7 months ago

2.32.2

7 months ago

2.32.1

7 months ago

2.17.0

9 months ago

2.43.0

5 months ago

2.20.2

9 months ago

2.20.3

9 months ago

2.20.0

9 months ago

2.20.1

9 months ago

2.28.0

8 months ago

2.31.0

7 months ago

2.39.0

5 months ago

2.16.1

9 months ago

2.16.0

9 months ago

2.42.1

5 months ago

2.42.0

5 months ago

2.27.1

8 months ago

2.27.0

8 months ago

2.30.0

7 months ago

2.15.2

9 months ago

2.15.0

9 months ago

2.15.1

9 months ago

2.38.0

5 months ago

2.41.0

5 months ago

2.26.1

8 months ago

2.26.0

8 months ago

2.37.1

5 months ago

2.37.0

6 months ago

2.14.0

10 months ago

2.40.0

5 months ago

2.25.0

8 months ago

2.48.0

4 months ago

2.13.4

10 months ago

2.36.0

6 months ago

2.13.2

11 months ago

2.13.3

10 months ago

2.13.0

11 months ago

2.36.1

6 months ago

2.13.1

11 months ago

2.47.0

4 months ago

2.24.1

8 months ago

2.24.0

8 months ago

2.12.0

12 months ago

2.35.1

6 months ago

2.35.0

6 months ago

2.23.0

8 months ago

2.11.0

12 months ago

2.10.0

12 months ago

2.9.0

12 months ago

2.8.0

1 year ago

2.7.0

1 year ago

2.7.1

1 year ago

2.6.1

1 year ago

2.6.0

1 year ago

2.5.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.0.0

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

2.3.0

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.3

1 year ago

1.8.1

1 year ago

1.8.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.5.0

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.5.1

1 year ago

2.1.5

1 year ago

2.1.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.11

1 year ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.8-next.6

2 years ago

1.0.8-next.5

2 years ago

1.0.8-next.4

2 years ago

1.0.8-next.3

2 years ago

1.0.8-next.2

2 years ago

1.0.8-next.1

2 years ago

1.0.8-next.0

2 years ago

1.0.7-next.0

2 years ago

1.0.8-beta.0

2 years ago

1.0.2

2 years ago

1.0.6

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.9.96

2 years ago

0.9.97

2 years ago

0.9.93

2 years ago

0.9.95

2 years ago

0.9.92

2 years ago

0.9.91

2 years ago

0.9.90

2 years ago

0.9.89

2 years ago

0.9.86

2 years ago

0.9.87

2 years ago

0.9.88

2 years ago

0.9.85

2 years ago

0.9.83

2 years ago

0.9.84

2 years ago

0.9.82

2 years ago

0.9.80

2 years ago

0.9.78

2 years ago

0.9.79

2 years ago

0.9.75

2 years ago

0.9.76

2 years ago

0.9.77

2 years ago

0.9.72

2 years ago

0.9.73

2 years ago

0.9.74

2 years ago

0.9.70

2 years ago

0.9.69

2 years ago

0.9.67

2 years ago

0.9.68

2 years ago

0.9.66

2 years ago

0.9.64

2 years ago

0.9.65

2 years ago

0.9.63

2 years ago

0.9.61

2 years ago

0.9.62

2 years ago

0.9.60

2 years ago

0.9.59

2 years ago

0.9.57

2 years ago

0.9.58

2 years ago

0.9.56

2 years ago

0.9.53

2 years ago

0.9.54

2 years ago

0.9.55

2 years ago

0.9.52

2 years ago

0.9.50

2 years ago

0.9.51

2 years ago

0.9.45

2 years ago

0.9.47

2 years ago

0.9.48

2 years ago

0.9.44

2 years ago

0.9.49

2 years ago

0.9.42

2 years ago

0.9.43

2 years ago

0.9.34

2 years ago

0.9.35

2 years ago

0.9.36

2 years ago

0.9.37

2 years ago

0.9.32

2 years ago

0.9.33

2 years ago

0.9.38

2 years ago

0.9.39

2 years ago

0.9.41

2 years ago

0.9.40

2 years ago

0.9.31

2 years ago

0.9.30

2 years ago

0.9.28

2 years ago

0.9.29

2 years ago

0.9.23

2 years ago

0.9.24

2 years ago

0.9.25

2 years ago

0.9.26

2 years ago

0.9.21

2 years ago

0.9.22

2 years ago

0.9.27

2 years ago

0.9.20

2 years ago

0.9.17

2 years ago

0.9.18

2 years ago

0.9.19

2 years ago

0.9.13

2 years ago

0.9.14

2 years ago

0.9.15

2 years ago

0.9.16

2 years ago

0.9.12

2 years ago

0.9.11

2 years ago

0.9.8

2 years ago

0.9.7

2 years ago

0.9.9

2 years ago

0.9.10

2 years ago

0.9.6

2 years ago

0.9.5

2 years ago

0.9.4

2 years ago

0.9.3

2 years ago

0.9.2

2 years ago