Complete reference for TypeScript types and interfaces provided by the pika-shared package.
Overview
Section titled “Overview”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.
Installation
Section titled “Installation”npm install -D pika-sharedBenefits
Section titled “Benefits”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
Type Categories
Section titled “Type Categories”Agent & Tool Types
Section titled “Agent & Tool Types”Types for defining agents, tools, and their configurations.
- Agent & Tool Types -
AgentDefinition,ToolDefinition,FunctionSchema
Key Types:
AgentDefinition- Agent configurationLambdaToolDefinition- AWS Lambda toolsMcpToolDefinition- Model Context Protocol toolsInlineToolDefinition- Inline JavaScript toolsFunctionDefinition- Bedrock function schemasAccessRule- Access control rules
Session & User Types
Section titled “Session & User Types”Types for managing sessions, users, and chat interactions.
- Session & User Types -
ChatSession,ChatUser,ChatMessage
Key Types:
ChatSession- Chat session dataChatUser- User profile and custom dataChatMessage- Message structureSessionData- Session stateConverseRequest- Chat request payloadConverseResponse- Chat response structure
Chat App Types
Section titled “Chat App Types”Types for chat application configuration.
Key Types:
ChatApp- Complete chat app configurationChatAppForIdempotentCreateOrUpdate- For deploymentChatAppFeatures- Feature configuration objectChatAppOverride- Access control overrides
See: Chat App Configuration for detailed documentation.
Bedrock Types
Section titled “Bedrock Types”Types specific to AWS Bedrock integration.
Key Types:
BedrockActionGroupLambdaEvent- Event type for tool invocationsBedrockActionGroupLambdaResponse- Response formatFunctionDefinition- Bedrock function schemaActionGroupInvocationInput- Tool invocation input
See: Agent & Tool Types for Bedrock-specific types.
Tag Definition Types
Section titled “Tag Definition Types”Types for custom UI tags and widgets.
Key Types:
TagDefinition- Complete tag definitionTagDefinitionWidget- Widget configurationTagInstructionForLlm- LLM instructions for tagsWidgetRenderingContexts- Where widgets can render
See: Widget System Reference for tag system documentation.
Common Import Patterns
Section titled “Common Import Patterns”Agent Configuration
Section titled “Agent Configuration”import type { AgentDefinition, AgentDefinitionForCreate, ToolDefinition, LambdaToolDefinition} from 'pika-shared/types/chatbot/chatbot-types';Chat App Configuration
Section titled “Chat App Configuration”import type { ChatApp, ChatAppForIdempotentCreateOrUpdate, ChatAppFeatures} from 'pika-shared/types/chatbot/chatbot-types';Tool Implementation
Section titled “Tool Implementation”import type { BedrockActionGroupLambdaEvent, BedrockActionGroupLambdaResponse} from 'pika-shared/types/chatbot/bedrock';
import { createBedrockLambdaResponse, handleBedrockError, convertBedrockParamsToCorrectType} from 'pika-shared/util/bedrock';Session Management
Section titled “Session Management”import type { ChatSession, ChatUser, SessionData} from 'pika-shared/types/chatbot/chatbot-types';Utility Functions
Section titled “Utility Functions”The pika-shared package also provides utility functions:
Bedrock Utilities
Section titled “Bedrock Utilities”import { convertBedrockParamsToCorrectType, createBedrockLambdaResponse, handleBedrockError, normalizeSessionAttributes} from 'pika-shared/util/bedrock';Server Utilities
Section titled “Server Utilities”import { gzipAndBase64EncodeString, gunzipBase64EncodedString} from 'pika-shared/util/server-utils';Type-Safe Lambda Handler Example
Section titled “Type-Safe Lambda Handler Example”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}`);}Generic Types for Custom Data
Section titled “Generic Types for Custom Data”Many types support generics for custom user data:
// Define your custom user data structureinterface MyCustomData { accountId: string; accountType: 'free' | 'premium' | 'enterprise'; region: string;}
// Use with ChatUserimport 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 ChatSessionimport 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};Type Guards
Section titled “Type Guards”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';}Enums and Constants
Section titled “Enums and Constants”String literal types and arrays of valid values:
import { FeatureTypeArr, ClearConverseLambdaCacheTypes, SESSION_SEARCH_SORT_FIELDS} from 'pika-shared/types/chatbot/chatbot-types';
// Valid feature typestype FeatureType = (typeof FeatureTypeArr)[number]; // 'instruction' | 'history'
// Valid cache typestype CacheType = (typeof ClearConverseLambdaCacheTypes)[number];// 'agent' | 'tagDefinitions' | 'instructionAssistanceConfig' | 'all'
// Valid sort fields for session searchtype SortField = (typeof SESSION_SEARCH_SORT_FIELDS)[number];// 'createDate' | 'lastUpdate' | 'sessionId' | ...Version Compatibility
Section titled “Version Compatibility”The pika-shared package version should match your Pika Platform version:
{ "dependencies": { "pika-shared": "^1.0.0" }}Check compatibility in the Changelog.
Best Practices
Section titled “Best Practices”TypeScript Configuration
Section titled “TypeScript Configuration”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" }}Related Documentation
Section titled “Related Documentation”- Agent Configuration - Agent config schema
- Chat App Configuration - Chat app config schema
- Tool Configuration - Tool config schema
- Agent & Tool Types - Detailed agent/tool type reference
- Session & User Types - Detailed session/user type reference
Source Code
Section titled “Source Code”View the complete type definitions on GitHub: