playkit-sdk 1.1.4-beta.4 → 1.2.0-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,13 +6,28 @@ import EventEmitter from 'eventemitter3';
6
6
  /**
7
7
  * Message role in a conversation
8
8
  */
9
- type MessageRole = 'system' | 'user' | 'assistant';
9
+ type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
10
+ /**
11
+ * Tool call made by the assistant
12
+ */
13
+ interface ToolCall {
14
+ id: string;
15
+ type: 'function';
16
+ function: {
17
+ name: string;
18
+ arguments: string;
19
+ };
20
+ }
10
21
  /**
11
22
  * A message in a conversation
12
23
  */
13
24
  interface Message {
14
25
  role: MessageRole;
15
26
  content: string;
27
+ /** Tool calls made by the assistant (when role is 'assistant') */
28
+ tool_calls?: ToolCall[];
29
+ /** Tool call ID this message responds to (when role is 'tool') */
30
+ tool_call_id?: string;
16
31
  }
17
32
  /**
18
33
  * Generic API result wrapper
@@ -82,6 +97,17 @@ declare class PlayKitError extends Error {
82
97
  * Chat and text generation types
83
98
  */
84
99
 
100
+ /**
101
+ * Tool definition for function calling
102
+ */
103
+ interface ChatTool {
104
+ type: 'function';
105
+ function: {
106
+ name: string;
107
+ description: string;
108
+ parameters: Record<string, any>;
109
+ };
110
+ }
85
111
  /**
86
112
  * Configuration for text generation
87
113
  */
@@ -100,6 +126,15 @@ interface ChatConfig {
100
126
  stop?: string[];
101
127
  /** Top-p sampling */
102
128
  topP?: number;
129
+ /** Tools available for the model to use */
130
+ tools?: ChatTool[];
131
+ /** Tool choice: 'auto', 'required', 'none', or specific tool */
132
+ tool_choice?: 'auto' | 'required' | 'none' | {
133
+ type: 'function';
134
+ function: {
135
+ name: string;
136
+ };
137
+ };
103
138
  }
104
139
  /**
105
140
  * Configuration for streaming text generation
@@ -121,7 +156,7 @@ interface ChatResult {
121
156
  /** Model used for generation */
122
157
  model: string;
123
158
  /** Finish reason */
124
- finishReason: 'stop' | 'length' | 'content_filter' | 'null';
159
+ finishReason: 'stop' | 'length' | 'content_filter' | 'tool_calls' | 'null';
125
160
  /** Token usage information */
126
161
  usage?: {
127
162
  promptTokens: number;
@@ -132,6 +167,8 @@ interface ChatResult {
132
167
  id?: string;
133
168
  /** Timestamp of creation */
134
169
  created?: number;
170
+ /** Tool calls made by the model */
171
+ tool_calls?: ToolCall[];
135
172
  }
136
173
  /**
137
174
  * Configuration for structured output generation
@@ -176,6 +213,45 @@ interface StreamChunk {
176
213
  delta?: string;
177
214
  error?: string;
178
215
  }
216
+ /**
217
+ * NPC Action parameter types
218
+ */
219
+ type NpcActionParamType = 'string' | 'number' | 'boolean' | 'stringEnum';
220
+ /**
221
+ * NPC Action parameter definition
222
+ */
223
+ interface NpcActionParameter {
224
+ name: string;
225
+ description: string;
226
+ type: NpcActionParamType;
227
+ required?: boolean;
228
+ enumOptions?: string[];
229
+ }
230
+ /**
231
+ * NPC Action definition
232
+ */
233
+ interface NpcAction {
234
+ actionName: string;
235
+ description: string;
236
+ parameters?: NpcActionParameter[];
237
+ enabled?: boolean;
238
+ }
239
+ /**
240
+ * NPC Action call result
241
+ */
242
+ interface NpcActionCall {
243
+ id: string;
244
+ actionName: string;
245
+ arguments: Record<string, any>;
246
+ }
247
+ /**
248
+ * Response from NPC with actions
249
+ */
250
+ interface NpcActionResponse {
251
+ text: string;
252
+ actionCalls: NpcActionCall[];
253
+ hasActions: boolean;
254
+ }
179
255
 
180
256
  /**
181
257
  * Image generation types
@@ -469,6 +545,18 @@ declare class PlayerClient extends EventEmitter {
469
545
  * Chat provider for HTTP communication with chat API
470
546
  */
471
547
 
548
+ /**
549
+ * Chat config with tools support
550
+ */
551
+ interface ChatConfigWithTools extends ChatConfig {
552
+ tools?: ChatTool[];
553
+ tool_choice?: 'auto' | 'required' | 'none' | {
554
+ type: 'function';
555
+ function: {
556
+ name: string;
557
+ };
558
+ };
559
+ }
472
560
  declare class ChatProvider {
473
561
  private authManager;
474
562
  private config;
@@ -487,16 +575,45 @@ declare class ChatProvider {
487
575
  * Make a streaming chat completion request
488
576
  */
489
577
  chatCompletionStream(chatConfig: ChatConfig): Promise<ReadableStreamDefaultReader<Uint8Array>>;
578
+ /**
579
+ * Make a chat completion request with tools (non-streaming)
580
+ */
581
+ chatCompletionWithTools(chatConfig: ChatConfigWithTools): Promise<ChatCompletionResponse>;
582
+ /**
583
+ * Make a streaming chat completion request with tools
584
+ */
585
+ chatCompletionWithToolsStream(chatConfig: ChatConfigWithTools): Promise<ReadableStreamDefaultReader<Uint8Array>>;
490
586
  /**
491
587
  * Generate structured output using JSON schema
588
+ * Uses the /chat endpoint with response_format for structured output
492
589
  */
493
- generateStructured(schemaName: string, prompt: string, model?: string, temperature?: number): Promise<any>;
590
+ generateStructured(schemaName: string, prompt: string, model?: string, temperature?: number, schema?: Record<string, any>, schemaDescription?: string): Promise<any>;
494
591
  }
495
592
 
496
593
  /**
497
594
  * Chat client for AI text generation
498
595
  */
499
596
 
597
+ /**
598
+ * Config for text generation with tools
599
+ */
600
+ interface ChatWithToolsConfig extends ChatConfig {
601
+ tools: ChatTool[];
602
+ tool_choice?: 'auto' | 'required' | 'none' | {
603
+ type: 'function';
604
+ function: {
605
+ name: string;
606
+ };
607
+ };
608
+ }
609
+ /**
610
+ * Config for streaming text generation with tools
611
+ */
612
+ interface ChatWithToolsStreamConfig extends ChatWithToolsConfig {
613
+ onChunk: (chunk: string) => void;
614
+ onComplete?: (result: ChatResult) => void;
615
+ onError?: (error: Error) => void;
616
+ }
500
617
  declare class ChatClient {
501
618
  private provider;
502
619
  private model;
@@ -521,6 +638,15 @@ declare class ChatClient {
521
638
  * Simple chat with streaming
522
639
  */
523
640
  chatStream(message: string, onChunk: (chunk: string) => void, onComplete?: (fullText: string) => void, systemPrompt?: string): Promise<void>;
641
+ /**
642
+ * Generate text with tool calling support (non-streaming)
643
+ */
644
+ textGenerationWithTools(config: ChatWithToolsConfig): Promise<ChatResult>;
645
+ /**
646
+ * Generate text with tool calling support (streaming)
647
+ * Text streams first, complete result with tool_calls returned in onComplete
648
+ */
649
+ textGenerationWithToolsStream(config: ChatWithToolsStreamConfig): Promise<void>;
524
650
  }
525
651
 
526
652
  /**
@@ -605,8 +731,34 @@ declare class NPCClient extends EventEmitter {
605
731
  talkStream(message: string, onChunk: (chunk: string) => void, onComplete?: (fullText: string) => void): Promise<void>;
606
732
  /**
607
733
  * Talk with structured output
734
+ * @deprecated Use talkWithActions instead for NPC decision-making with actions
608
735
  */
609
736
  talkStructured<T = any>(message: string, schemaName: string): Promise<T>;
737
+ /**
738
+ * Talk to the NPC with available actions (non-streaming)
739
+ * @param message The message to send
740
+ * @param actions List of actions the NPC can perform
741
+ * @returns Response containing text and any action calls
742
+ */
743
+ talkWithActions(message: string, actions: NpcAction[]): Promise<NpcActionResponse>;
744
+ /**
745
+ * Talk to the NPC with actions (streaming)
746
+ * Text streams first, action calls are returned in onComplete
747
+ */
748
+ talkWithActionsStream(message: string, actions: NpcAction[], onChunk: (chunk: string) => void, onComplete?: (response: NpcActionResponse) => void): Promise<void>;
749
+ /**
750
+ * Report action results back to the conversation
751
+ * Call this after executing actions to let the NPC know the results
752
+ */
753
+ reportActionResults(results: Record<string, string>): void;
754
+ /**
755
+ * Report a single action result
756
+ */
757
+ reportActionResult(callId: string, result: string): void;
758
+ /**
759
+ * Parse tool arguments from JSON string
760
+ */
761
+ private parseToolArguments;
610
762
  /**
611
763
  * Get conversation history
612
764
  */