Skip to content

Shared Types & Interfaces

Complete reference for TypeScript types and interfaces provided by the pika-shared package.

The pika-shared package provides comprehensive TypeScript types for building type-safe Pika applications. These types ensure compile-time validation and provide excellent IDE support.

Terminal window
npm install -D pika-shared

Using pika-shared types provides:

  • Compile-time validation - Catch errors before runtime
  • IntelliSense support - Auto-completion and inline documentation in your IDE
  • Consistent interfaces - Shared types across frontend and backend
  • Automatic refactoring - When types change, your IDE can help update code
  • Self-documenting code - Types serve as inline documentation

Types for defining agents, tools, and their configurations.

Key Types:

  • AgentDefinition - Agent configuration
  • LambdaToolDefinition - AWS Lambda tools
  • McpToolDefinition - Model Context Protocol tools
  • InlineToolDefinition - Inline JavaScript tools
  • FunctionDefinition - Bedrock function schemas
  • AccessRule - Access control rules

Types for managing sessions, users, and chat interactions.

Key Types:

  • ChatSession - Chat session data
  • ChatUser - User profile and custom data
  • ChatMessage - Message structure
  • SessionData - Session state
  • ConverseRequest - Chat request payload
  • ConverseResponse - Chat response structure

Types for chat application configuration.

Key Types:

  • ChatApp - Complete chat app configuration
  • ChatAppForIdempotentCreateOrUpdate - For deployment
  • ChatAppFeatures - Feature configuration object
  • ChatAppOverride - Access control overrides

See: Chat App Configuration for detailed documentation.

Types specific to AWS Bedrock integration.

Key Types:

  • BedrockActionGroupLambdaEvent - Event type for tool invocations
  • BedrockActionGroupLambdaResponse - Response format
  • FunctionDefinition - Bedrock function schema
  • ActionGroupInvocationInput - Tool invocation input

See: Agent & Tool Types for Bedrock-specific types.

Types for custom UI tags and widgets.

Key Types:

  • TagDefinition - Complete tag definition
  • TagDefinitionWidget - Widget configuration
  • TagInstructionForLlm - LLM instructions for tags
  • WidgetRenderingContexts - Where widgets can render

See: Widget System Reference for tag system documentation.

import type {
AgentDefinition,
AgentDefinitionForCreate,
ToolDefinition,
LambdaToolDefinition
} from 'pika-shared/types/chatbot/chatbot-types';
import type {
ChatApp,
ChatAppForIdempotentCreateOrUpdate,
ChatAppFeatures
} from 'pika-shared/types/chatbot/chatbot-types';
import type {
BedrockActionGroupLambdaEvent,
BedrockActionGroupLambdaResponse
} from 'pika-shared/types/chatbot/bedrock';
import {
createBedrockLambdaResponse,
handleBedrockError,
convertBedrockParamsToCorrectType
} from 'pika-shared/util/bedrock';
import type {
ChatSession,
ChatUser,
SessionData
} from 'pika-shared/types/chatbot/chatbot-types';

The pika-shared package also provides utility functions:

import {
convertBedrockParamsToCorrectType,
createBedrockLambdaResponse,
handleBedrockError,
normalizeSessionAttributes
} from 'pika-shared/util/bedrock';
import {
gzipAndBase64EncodeString,
gunzipBase64EncodedString
} from 'pika-shared/util/server-utils';

Complete example of a type-safe Lambda handler:

import { Handler } from 'aws-lambda';
import type {
BedrockActionGroupLambdaEvent,
BedrockActionGroupLambdaResponse
} from 'pika-shared/types/chatbot/bedrock';
import {
createBedrockLambdaResponse,
handleBedrockError,
convertBedrockParamsToCorrectType
} from 'pika-shared/util/bedrock';
export const handler: Handler = async (
event: BedrockActionGroupLambdaEvent
): Promise<BedrockActionGroupLambdaResponse> => {
try {
// Convert and validate parameters
const params = convertBedrockParamsToCorrectType(event.parameters);
// Your business logic
const result = await processRequest(event.function, params);
// Create properly formatted response
return createBedrockLambdaResponse(
JSON.stringify(result),
event.actionGroup,
event.messageVersion,
event.function
);
} catch (error) {
return handleBedrockError(error, event);
}
};
interface RequestParams {
city?: string;
units?: string;
}
async function processRequest(
functionName: string,
params: RequestParams
): Promise<unknown> {
if (functionName === 'get_weather') {
const { city, units = 'celsius' } = params;
// Fetch weather data...
return { temperature: 72, units, city };
}
throw new Error(`Unknown function: ${functionName}`);
}

Many types support generics for custom user data:

// Define your custom user data structure
interface MyCustomData {
accountId: string;
accountType: 'free' | 'premium' | 'enterprise';
region: string;
}
// Use with ChatUser
import type { ChatUser } from 'pika-shared/types/chatbot/chatbot-types';
const user: ChatUser<MyCustomData> = {
userId: 'user-123',
firstName: 'John',
lastName: 'Doe',
customData: {
accountId: 'acct-456',
accountType: 'premium',
region: 'us-east'
}
};
// Use with ChatSession
import type { ChatSession } from 'pika-shared/types/chatbot/chatbot-types';
const session: ChatSession<MyCustomData> = {
userId: 'user-123',
sessionId: 'session-789',
chatAppId: 'support-chat',
customData: {
accountId: 'acct-456',
accountType: 'premium',
region: 'us-east'
},
// ... other fields
};

Helper functions for runtime type checking:

import type { UserType } from 'pika-shared/types/chatbot/chatbot-types';
function isInternalUser(userType: UserType): boolean {
return userType === 'internal-user';
}
function isExternalUser(userType: UserType): boolean {
return userType === 'external-user';
}

String literal types and arrays of valid values:

import {
FeatureTypeArr,
ClearConverseLambdaCacheTypes,
SESSION_SEARCH_SORT_FIELDS
} from 'pika-shared/types/chatbot/chatbot-types';
// Valid feature types
type FeatureType = (typeof FeatureTypeArr)[number]; // 'instruction' | 'history'
// Valid cache types
type CacheType = (typeof ClearConverseLambdaCacheTypes)[number];
// 'agent' | 'tagDefinitions' | 'instructionAssistanceConfig' | 'all'
// Valid sort fields for session search
type SortField = (typeof SESSION_SEARCH_SORT_FIELDS)[number];
// 'createDate' | 'lastUpdate' | 'sessionId' | ...

The pika-shared package version should match your Pika Platform version:

{
"dependencies": {
"pika-shared": "^1.0.0"
}
}

Check compatibility in the Changelog.

Recommended tsconfig.json settings for using pika-shared:

{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"moduleResolution": "node"
}
}

View the complete type definitions on GitHub: