@onereach/step-create-chat-completion 0.0.7-rc.57 → 0.0.7-rc.59

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.
package/dist/index.d.ts DELETED
@@ -1,691 +0,0 @@
1
- import { CONFIG, IThreadId, RESULT, LOCAL, IEvent, IThread, IStepId, STATE, IActionEvent, ACTION } from '@onereach/flow-sdk/types/index.js';
2
- import { ChatCompletion, ChatCompletionToolMessageParam, ChatCompletionMessageFunctionToolCall, ChatCompletionChunk as ChatCompletionChunk$1, ChatCompletionMessageParam } from 'openai/resources';
3
- import { z } from 'zod/v4-mini';
4
- import * as zod_v4_core from 'zod/v4/core';
5
- import Step from '@onereach/flow-sdk/step.js';
6
- import { ChatCompletionMessageFunctionToolCall as ChatCompletionMessageFunctionToolCall$1, ChatCompletionMessageParam as ChatCompletionMessageParam$1, ChatCompletionToolMessageParam as ChatCompletionToolMessageParam$2 } from 'openai/resources.js';
7
- import { ChatCompletion as ChatCompletion$1, ChatCompletionToolMessageParam as ChatCompletionToolMessageParam$1, ChatCompletionChunk } from 'openai/resources.mjs';
8
-
9
- declare const dataInSchema: z.ZodMiniObject<{
10
- provider: z.ZodMiniString<string>;
11
- model: z.ZodMiniString<string>;
12
- accountKey: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniString<string>]>, z.ZodMiniTransform<string | undefined, string | undefined>>;
13
- typeOfStep: z.ZodMiniEnum<{
14
- chat: "chat";
15
- completion: "completion";
16
- }>;
17
- systemMessage: z.ZodMiniOptional<z.ZodMiniString<string>>;
18
- userMessage: z.ZodMiniOptional<z.ZodMiniString<string>>;
19
- switchAssistantsMessage: z.ZodMiniDefault<z.ZodMiniBoolean<boolean>>;
20
- assistantsFirstMessage: z.ZodMiniOptional<z.ZodMiniString<string>>;
21
- temperature: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniNumber<unknown>]>, z.ZodMiniTransform<number | undefined, number | "" | undefined>>;
22
- topP: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniNumber<unknown>]>, z.ZodMiniTransform<number | undefined, number | "" | undefined>>;
23
- maxTokens: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniNumber<unknown>]>, z.ZodMiniTransform<number | undefined, number | "" | undefined>>;
24
- presencePenalty: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniNumber<unknown>]>, z.ZodMiniTransform<number | undefined, number | "" | undefined>>;
25
- frequencyPenalty: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniNumber<unknown>]>, z.ZodMiniTransform<number | undefined, number | "" | undefined>>;
26
- n: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniNumber<unknown>]>, z.ZodMiniTransform<number | undefined, number | "" | undefined>>;
27
- stop: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
28
- token: z.ZodMiniString<string>;
29
- }, z.core.$strip>>>;
30
- reasoningEffort: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniEnum<{
31
- none: "none";
32
- low: "low";
33
- medium: "medium";
34
- high: "high";
35
- }>]>, z.ZodMiniTransform<"none" | "low" | "medium" | "high" | undefined, "" | "none" | "low" | "medium" | "high" | undefined>>;
36
- streamResponse: z.ZodMiniDefault<z.ZodMiniBoolean<boolean>>;
37
- streamSettings: z.ZodMiniOptional<z.ZodMiniObject<{
38
- maxBufferLength: z.ZodMiniNumber<unknown>;
39
- debounceDuration: z.ZodMiniNumber<unknown>;
40
- }, z.core.$strip>>;
41
- customHistory: z.ZodMiniDefault<z.ZodMiniBoolean<boolean>>;
42
- historyLength: z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniUndefined, z.ZodMiniLiteral<"">, z.ZodMiniNumber<unknown>]>, z.ZodMiniTransform<number | undefined, number | "" | undefined>>;
43
- historyMode: z.ZodMiniOptional<z.ZodMiniEnum<{
44
- mergefield: "mergefield";
45
- codeHistory: "codeHistory";
46
- }>>;
47
- historyMergefield: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
48
- role: z.ZodMiniLiteral<"system">;
49
- content: z.ZodMiniString<string>;
50
- }, z.core.$strip>, z.ZodMiniObject<{
51
- role: z.ZodMiniLiteral<"user">;
52
- content: z.ZodMiniString<string>;
53
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
54
- }, z.core.$strip>, z.ZodMiniObject<{
55
- role: z.ZodMiniLiteral<"assistant">;
56
- content: z.ZodMiniNullable<z.ZodMiniString<string>>;
57
- tool_calls: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
58
- id: z.ZodMiniString<string>;
59
- type: z.ZodMiniLiteral<"function">;
60
- function: z.ZodMiniObject<{
61
- name: z.ZodMiniString<string>;
62
- arguments: z.ZodMiniString<string>;
63
- }, z.core.$strip>;
64
- }, z.core.$strip>>>;
65
- }, z.core.$strip>, z.ZodMiniObject<{
66
- role: z.ZodMiniLiteral<"tool">;
67
- content: z.ZodMiniString<string>;
68
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
69
- tool_call_id: z.ZodMiniString<string>;
70
- }, z.core.$strip>], "role">>>;
71
- historyCode: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
72
- role: z.ZodMiniLiteral<"system">;
73
- content: z.ZodMiniString<string>;
74
- }, z.core.$strip>, z.ZodMiniObject<{
75
- role: z.ZodMiniLiteral<"user">;
76
- content: z.ZodMiniString<string>;
77
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
78
- }, z.core.$strip>, z.ZodMiniObject<{
79
- role: z.ZodMiniLiteral<"assistant">;
80
- content: z.ZodMiniNullable<z.ZodMiniString<string>>;
81
- tool_calls: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
82
- id: z.ZodMiniString<string>;
83
- type: z.ZodMiniLiteral<"function">;
84
- function: z.ZodMiniObject<{
85
- name: z.ZodMiniString<string>;
86
- arguments: z.ZodMiniString<string>;
87
- }, z.core.$strip>;
88
- }, z.core.$strip>>>;
89
- }, z.core.$strip>, z.ZodMiniObject<{
90
- role: z.ZodMiniLiteral<"tool">;
91
- content: z.ZodMiniString<string>;
92
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
93
- tool_call_id: z.ZodMiniString<string>;
94
- }, z.core.$strip>], "role">>>;
95
- functionsList: z.ZodMiniArray<z.ZodMiniObject<{
96
- name: z.ZodMiniString<string>;
97
- description: z.ZodMiniOptional<z.ZodMiniString<string>>;
98
- parameters: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniObject<{
99
- type: z.ZodMiniLiteral<"object">;
100
- properties: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniObject<{
101
- type: z.ZodMiniEnum<{
102
- string: "string";
103
- number: "number";
104
- boolean: "boolean";
105
- object: "object";
106
- array: "array";
107
- }>;
108
- description: z.ZodMiniOptional<z.ZodMiniString<string>>;
109
- items: z.ZodMiniOptional<z.ZodMiniObject<{
110
- type: z.ZodMiniEnum<{
111
- string: "string";
112
- number: "number";
113
- boolean: "boolean";
114
- object: "object";
115
- }>;
116
- description: z.ZodMiniOptional<z.ZodMiniString<string>>;
117
- }, z.core.$strip>>;
118
- }, z.core.$strip>>;
119
- }, z.core.$strip>, z.ZodMiniTransform<{
120
- type: "object";
121
- properties: Record<string, {
122
- type: "string" | "number" | "boolean" | "object" | "array";
123
- description?: string | undefined;
124
- items?: {
125
- type: "string" | "number" | "boolean" | "object";
126
- description?: string | undefined;
127
- } | undefined;
128
- }>;
129
- } & {
130
- additionalProperties: false;
131
- required: string[];
132
- }, {
133
- type: "object";
134
- properties: Record<string, {
135
- type: "string" | "number" | "boolean" | "object" | "array";
136
- description?: string | undefined;
137
- items?: {
138
- type: "string" | "number" | "boolean" | "object";
139
- description?: string | undefined;
140
- } | undefined;
141
- }>;
142
- } & {
143
- additionalProperties: false;
144
- required: string[];
145
- }>>>;
146
- strict: z.ZodMiniBoolean<boolean>;
147
- }, z.core.$strip>>;
148
- useState: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
149
- stateSettings: z.ZodMiniOptional<z.ZodMiniObject<{
150
- stateFunction: z.ZodMiniFunction<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
151
- }, z.core.$strip>>;
152
- processError: z.ZodMiniBoolean<boolean>;
153
- processTimeout: z.ZodMiniBoolean<boolean>;
154
- timeoutDuration: z.ZodMiniString<string>;
155
- }, z.core.$strip>;
156
- type DataIn = z.infer<typeof dataInSchema>;
157
-
158
- interface BaseConfig extends CONFIG {
159
- dataIn: DataIn;
160
- }
161
-
162
- type ManagedThreadLocal = {
163
- active: boolean;
164
- parent: IThreadId;
165
- };
166
-
167
- type BaseChildResultCancel = {
168
- status: 'cancel';
169
- };
170
- type BaseChildResult = BaseChildResultCancel | Error;
171
- type BaseChildLocal = ManagedThreadLocal;
172
- interface BaseChildConfig<TResult extends RESULT<CONFIG> = BaseChildResult, TLocal extends LOCAL<CONFIG> = BaseChildLocal> extends BaseConfig {
173
- result: TResult;
174
- local: TLocal;
175
- }
176
-
177
- declare const cancelContextClassId = "cncl_ctrl";
178
- declare const parentEvents: {
179
- readonly cancel: "st_cancel";
180
- };
181
- type ParentEventName = typeof parentEvents;
182
- declare const cancelContentEvents: {
183
- readonly cancel: "cnl_cancel";
184
- };
185
- type CancelContentEventName = typeof cancelContentEvents;
186
- type CancelContextEvents = IEvent<unknown, CancelContentEventName['cancel']>;
187
- type CancelContextState = {
188
- class: typeof cancelContextClassId;
189
- };
190
- interface CancelContextConfig extends BaseChildConfig {
191
- state: CancelContextState;
192
- events: CancelContextEvents;
193
- }
194
-
195
- type ChatCompletionOut = ChatCompletion;
196
- type ChatCompletionState = {
197
- cancelled: boolean;
198
- contentReady: boolean;
199
- chatCompletion?: ChatCompletion;
200
- toolsResults: ChatCompletionToolMessageParam[];
201
- };
202
- type ChatCompletionCancelEvent = IEvent<unknown, ParentEventName['cancel']>;
203
- type ChatCompletionEvent = ChatCompletionCancelEvent;
204
- interface ChatCompletionConfig extends BaseConfig {
205
- dataOut: ChatCompletionOut;
206
- state: ChatCompletionState;
207
- events: ChatCompletionEvent;
208
- }
209
-
210
- declare class BaseStep<T extends BaseConfig> extends Step<T> {
211
- resolveDataIn(): Promise<{
212
- provider: string;
213
- model: string;
214
- accountKey: string | undefined;
215
- typeOfStep: "chat" | "completion";
216
- switchAssistantsMessage: boolean;
217
- temperature: number | undefined;
218
- topP: number | undefined;
219
- maxTokens: number | undefined;
220
- presencePenalty: number | undefined;
221
- frequencyPenalty: number | undefined;
222
- n: number | undefined;
223
- reasoningEffort: "none" | "low" | "medium" | "high" | undefined;
224
- streamResponse: boolean;
225
- customHistory: boolean;
226
- historyLength: number | undefined;
227
- functionsList: {
228
- name: string;
229
- strict: boolean;
230
- description?: string | undefined;
231
- parameters?: ({
232
- type: "object";
233
- properties: Record<string, {
234
- type: "string" | "number" | "boolean" | "object" | "array";
235
- description?: string | undefined;
236
- items?: {
237
- type: "string" | "number" | "boolean" | "object";
238
- description?: string | undefined;
239
- } | undefined;
240
- }>;
241
- } & {
242
- additionalProperties: false;
243
- required: string[];
244
- }) | undefined;
245
- }[];
246
- processError: boolean;
247
- processTimeout: boolean;
248
- timeoutDuration: string;
249
- systemMessage?: string | undefined;
250
- userMessage?: string | undefined;
251
- assistantsFirstMessage?: string | undefined;
252
- stop?: {
253
- token: string;
254
- }[] | undefined;
255
- streamSettings?: {
256
- maxBufferLength: number;
257
- debounceDuration: number;
258
- } | undefined;
259
- historyMode?: "mergefield" | "codeHistory" | undefined;
260
- historyMergefield?: ({
261
- role: "system";
262
- content: string;
263
- } | {
264
- role: "user";
265
- content: string;
266
- name?: string | undefined;
267
- } | {
268
- role: "assistant";
269
- content: string | null;
270
- tool_calls?: {
271
- id: string;
272
- type: "function";
273
- function: {
274
- name: string;
275
- arguments: string;
276
- };
277
- }[] | undefined;
278
- } | {
279
- role: "tool";
280
- content: string;
281
- tool_call_id: string;
282
- name?: string | undefined;
283
- })[] | undefined;
284
- historyCode?: ({
285
- role: "system";
286
- content: string;
287
- } | {
288
- role: "user";
289
- content: string;
290
- name?: string | undefined;
291
- } | {
292
- role: "assistant";
293
- content: string | null;
294
- tool_calls?: {
295
- id: string;
296
- type: "function";
297
- function: {
298
- name: string;
299
- arguments: string;
300
- };
301
- }[] | undefined;
302
- } | {
303
- role: "tool";
304
- content: string;
305
- tool_call_id: string;
306
- name?: string | undefined;
307
- })[] | undefined;
308
- useState?: boolean | undefined;
309
- stateSettings?: {
310
- stateFunction: zod_v4_core.$InferOuterFunctionType<zod_v4_core.$ZodFunctionArgs, zod_v4_core.$ZodFunctionOut>;
311
- } | undefined;
312
- }>;
313
- }
314
-
315
- declare class CancelContext extends BaseStep<CancelContextConfig> {
316
- static readonly class = "cncl_ctrl";
317
- static start(thread: IThread<ChatCompletionConfig>): Promise<void>;
318
- static stop(thread: IThread<ChatCompletionConfig>): Promise<void>;
319
- static getThreadId(stepId: IStepId): IThreadId;
320
- runStep(): void;
321
- initialize(): void;
322
- onCancel(): void;
323
- }
324
-
325
- declare const requestContextClassId = "rqst_ctx";
326
- type RequestContextState = {
327
- class: typeof requestContextClassId;
328
- };
329
- type RequestContextResultOk = {
330
- status: 'ok';
331
- };
332
- type RequestContextResult = RequestContextResultOk | RESULT<BaseChildConfig>;
333
- interface RequestContextConfig extends BaseChildConfig<RequestContextResult> {
334
- state: RequestContextState;
335
- result: RequestContextResult;
336
- }
337
-
338
- declare const toolsContextClassId = "tl_ctrl";
339
- declare const toolContextEvents: {
340
- readonly callTool: "tl_run_call";
341
- readonly lastToolCallReceived: "tl_rsp_end";
342
- };
343
- type ToolContextEventName = typeof toolContextEvents;
344
- type ToolCallTask = {
345
- status: 'pending' | 'completed' | 'failed';
346
- call: ChatCompletionMessageFunctionToolCall;
347
- /** result of the tool call, if completed */
348
- result?: unknown;
349
- };
350
- type TasksMap = Record<ChatCompletionMessageFunctionToolCall['id'], ToolCallTask>;
351
- type ToolsContextResultOk = {
352
- status: 'ok';
353
- messages: ChatCompletionToolMessageParam[];
354
- };
355
- type ToolsContextResult = ToolsContextResultOk | RESULT<BaseChildConfig>;
356
- type CallToolParameters = {
357
- toolCall: ChatCompletionMessageFunctionToolCall;
358
- };
359
- type ToolsContextEventCallTool = IEvent<CallToolParameters, ToolContextEventName['callTool']>;
360
- type ToolsContextEventLastToolReceived = IEvent<unknown, ToolContextEventName['lastToolCallReceived']>;
361
- type ToolsContextEvent = ToolsContextEventCallTool | ToolsContextEventLastToolReceived;
362
- type ToolsContextState = {
363
- class: typeof toolsContextClassId;
364
- /** tool calls from LLM response */
365
- tasks: TasksMap;
366
- /** flag to indicate if there are more tasks to process */
367
- expectMoreTasks: boolean;
368
- };
369
- interface ToolsContextConfig extends BaseChildConfig<ToolsContextResult> {
370
- state: ToolsContextState;
371
- events: ToolsContextEvent;
372
- }
373
-
374
- declare const contentContextEvents: {
375
- readonly handleContent: "hnd_cnt";
376
- };
377
- type ContentContentEventName = typeof contentContextEvents;
378
- type ContentContextHandleContentEvent = IEvent<{
379
- content: ChatCompletionChunk | ChatCompletion$1;
380
- }, ContentContentEventName['handleContent']>;
381
- type ContentContextEvent = ContentContextHandleContentEvent;
382
- type ContentContextState = {
383
- requestComplete: boolean;
384
- chatCompletion?: ChatCompletion$1;
385
- /**
386
- * Are tool calls ready?
387
- * - `undefined` - no tools to wait for
388
- * - `false` - tools are processing
389
- * - `true` - tools finished processing
390
- */
391
- toolsReady?: boolean;
392
- toolsResults?: ChatCompletionToolMessageParam$1[];
393
- };
394
- type ContentContextOkResult = {
395
- status: 'ok';
396
- chatCompletion: ChatCompletion$1;
397
- toolsResults: ChatCompletionToolMessageParam$1[];
398
- };
399
- type ContentContextResult = ContentContextOkResult | RESULT<BaseChildConfig>;
400
- interface ContentContextConfig extends BaseChildConfig<ContentContextResult> {
401
- state: ContentContextState;
402
- result: ContentContextResult;
403
- events: ContentContextEvent;
404
- }
405
-
406
- declare abstract class AbstractContentContext<T extends ContentContextConfig> extends BaseStep<T> {
407
- static get class(): string;
408
- static getInitialState<T extends ContentContextConfig>(): STATE<T>;
409
- runStep(): void | Promise<void>;
410
- initialize(): void;
411
- abstract onHandleContent(event: ContentContextHandleContentEvent): void | Promise<void>;
412
- protected abstract onAllContentReceived(): void | Promise<void>;
413
- protected abstract tryToComplete(): void | Promise<void>;
414
- onRequestContextEnd(event: IActionEvent<RequestContextConfig, ACTION.end>): Promise<void>;
415
- onToolsContextEnd(event: IActionEvent<ToolsContextConfig, ACTION.end>): Promise<void>;
416
- protected callFunction(toolCall: ChatCompletionMessageFunctionToolCall$1): Promise<void>;
417
- protected handleMultipleChoices(): void;
418
- protected initToolsContextThread(): Promise<void>;
419
- protected cancel(): void;
420
- protected complete(): void;
421
- }
422
-
423
- type SimpleContentContextHandleContentEvent = IEvent<{
424
- content: ChatCompletion;
425
- }, ContentContentEventName['handleContent']>;
426
- type SimpleContentContextEvent = SimpleContentContextHandleContentEvent;
427
- interface SimpleContentContextConfig extends ContentContextConfig {
428
- events: SimpleContentContextEvent;
429
- }
430
-
431
- declare class SimpleContentContext extends AbstractContentContext<SimpleContentContextConfig> {
432
- static readonly class = "cnt_cxt_smp";
433
- static getInitialState(): STATE<SimpleContentContextConfig>;
434
- onHandleContent(event: SimpleContentContextHandleContentEvent): Promise<void>;
435
- onAllContentReceived(): void;
436
- protected tryToComplete(): void;
437
- }
438
-
439
- declare const streamContentContextClassId = "cnt_cxt_str";
440
- type StreamContentContextHandleContentEvent = IEvent<{
441
- content: ChatCompletionChunk$1;
442
- }, ContentContentEventName['handleContent']>;
443
- type StreamContentContextEvent = StreamContentContextHandleContentEvent;
444
- type ContentChunkEvent = {
445
- content: string;
446
- index: number;
447
- ts: number;
448
- };
449
- type ContentEndEvent = {
450
- lastChunkReceived: true;
451
- };
452
- type ContentEvent = ContentChunkEvent | ContentEndEvent;
453
- type StreamContentContextState = Omit<ContentContextState, 'class'> & {
454
- class: typeof streamContentContextClassId;
455
- /** aggregated result of the LLM response */
456
- partialChatCompletion: Partial<ChatCompletion>;
457
- /** queue of response chunks */
458
- events: ContentEvent[];
459
- /** last index for a chunk to be processed by worker */
460
- index: number;
461
- /** marker for end of response stream */
462
- lastChunkReceived: boolean;
463
- /** When `true` means worker finished the processing the queue */
464
- workerComplete: boolean;
465
- };
466
- interface StreamContentContextConfig extends ContentContextConfig {
467
- events: StreamContentContextEvent;
468
- state: StreamContentContextState;
469
- }
470
-
471
- declare const streamContentContextWorkerClassId = "str_wrk";
472
- declare const streamWorkerExits: {
473
- readonly chunk: "chunk";
474
- };
475
- type ContentChunk = {
476
- content: string;
477
- index: number;
478
- ts: number;
479
- };
480
- type StreamContentContextWorkerOut = {
481
- chunk: ContentChunk;
482
- };
483
- type StreamContentContextWorkerState = {
484
- class: typeof streamContentContextWorkerClassId;
485
- event: ContentChunk;
486
- };
487
- type StreamContentContextWorkerResult = undefined | RESULT<BaseChildConfig>;
488
- interface StreamContentContextWorkerConfig extends BaseChildConfig<StreamContentContextWorkerResult> {
489
- dataOut: StreamContentContextWorkerOut;
490
- state: StreamContentContextWorkerState;
491
- }
492
-
493
- declare class StreamContentContextWorker extends BaseStep<StreamContentContextWorkerConfig> {
494
- static readonly class = "str_wrk";
495
- static start(thread: IThread<StreamContentContextConfig>, event: ContentChunk): Promise<void>;
496
- static isBusy(thread: IThread<StreamContentContextConfig>): boolean;
497
- static getThreadId(stepId: IStepId): IThreadId;
498
- runStep(): void;
499
- }
500
-
501
- declare class StreamContentContext extends AbstractContentContext<StreamContentContextConfig> {
502
- static readonly class = "cnt_cxt_str";
503
- static getInitialState(): STATE<StreamContentContextConfig>;
504
- runStep(): Promise<void>;
505
- /**
506
- * Handler of the worker thread end event.
507
- */
508
- onWorkerThreadEnd(event: IActionEvent<StreamContentContextWorkerConfig, ACTION.end>): void;
509
- /**
510
- * Handles a single chunk of the streaming response from the OpenAI API.
511
- */
512
- onHandleContent(event: StreamContentContextHandleContentEvent): void;
513
- /**
514
- * Handles the notification that all response chunks were received from the OpenAI API.
515
- */
516
- protected onAllContentReceived(): void;
517
- private onToolCall;
518
- /**
519
- * Tries to flush the queue of response chunks to the controller thread.
520
- * If the first event in the queue is not full, it waits for a debounce duration before flushing.
521
- * If the first event is full, it flushes it immediately.
522
- */
523
- private scheduleNextContentEvent;
524
- /**
525
- * Compacts the content into the controller thread's events queue.
526
- * If the content is too long, it splits it into multiple events.
527
- * If the last event is not full, it extends it with the new content.
528
- */
529
- private addContentToQueue;
530
- /**
531
- * Processes the next event in the controller thread's queue.
532
- * If the worker thread is busy, it skips processing.
533
- * If the event is the termination marker, it notifies the end of the controller thread.
534
- * If the event is ready for processing, it starts the worker thread to handle it.
535
- */
536
- private tryRunWorker;
537
- private isEventReady;
538
- private getEventToProcess;
539
- protected tryToComplete(): void;
540
- protected get maxChunkContentLength(): number;
541
- protected get debounceDuration(): number;
542
- }
543
-
544
- declare const historyContextClassId = "hst_ctrl";
545
- declare const historyContextEvents: {
546
- readonly appendToHistory: "hst_append";
547
- readonly prepareHistory: "hst_prepare";
548
- readonly adjustOnCancel: "hst_cncl";
549
- };
550
- type HistoryContextEventName = typeof historyContextEvents;
551
- type HistoryContextAppendParameters = {
552
- message: ChatCompletionMessageParam | ChatCompletionMessageParam[];
553
- };
554
- type HistoryContextEventAppendToHistory = IEvent<HistoryContextAppendParameters, HistoryContextEventName['appendToHistory']>;
555
- type HistoryContextEventPrepareHistory = IEvent<unknown, HistoryContextEventName['prepareHistory']>;
556
- type HistoryContextEventAdjustOnCancel = IEvent<unknown, HistoryContextEventName['adjustOnCancel']>;
557
- type HistoryContextEvent = HistoryContextEventAppendToHistory | HistoryContextEventPrepareHistory | HistoryContextEventAdjustOnCancel;
558
- type HistoryContextState = {
559
- class: typeof historyContextClassId;
560
- /** messages to send to OpenAI API */
561
- messages: ChatCompletionMessageParam[];
562
- };
563
- interface HistoryContextConfig extends BaseConfig {
564
- state: HistoryContextState;
565
- events: HistoryContextEvent;
566
- }
567
-
568
- declare class HistoryContext extends BaseStep<HistoryContextConfig> {
569
- static readonly class = "hst_ctrl";
570
- static start(thread: IThread<ChatCompletionConfig>): Promise<void>;
571
- static prepareHistory<T extends ChatCompletionConfig>(thread: IThread<T>): Promise<void>;
572
- static appendToHistory<T extends ChatCompletionConfig>(thread: IThread<T>, message: ChatCompletionMessageParam$1 | ChatCompletionMessageParam$1[]): Promise<void>;
573
- static adjustOnCancel<T extends ChatCompletionConfig>(thread: IThread<T>): Promise<void>;
574
- static getHistory<T extends CONFIG>(thread: IThread<T>): ChatCompletionMessageParam$1[];
575
- static getThreadId(stepId: IStepId): IThreadId;
576
- runStep(): void;
577
- initialize(): void;
578
- onAdjustOnCancel(): void;
579
- onPrepareHistory(): void;
580
- onAppendToHistory(event: HistoryContextEventAppendToHistory): void;
581
- }
582
-
583
- declare class RequestContext extends BaseStep<RequestContextConfig> {
584
- static readonly class = "rqst_ctx";
585
- static start<T extends ContentContextConfig>(thread: IThread<T>): Promise<RequestContextResult>;
586
- static getThreadId(stepId: IStepId): IThreadId;
587
- runStep(): Promise<void>;
588
- private cancel;
589
- private complete;
590
- private getHistory;
591
- private get openAiService();
592
- private get responseHandler();
593
- }
594
-
595
- declare const toolsContextWorkerClassId = "tl_wrk";
596
- type ToolsContextParsedArguments = Record<string, unknown>;
597
- type ToolsContextWorkerMergeField = {
598
- function: {
599
- name: string;
600
- arguments: ToolsContextParsedArguments;
601
- };
602
- };
603
- type ToolsContextWorkerOut = ToolsContextWorkerMergeField;
604
- type ToolsContextWorkerState = {
605
- class: typeof toolsContextWorkerClassId;
606
- };
607
- type ToolsContextWorkerLocal = {
608
- toolCall: ChatCompletionMessageFunctionToolCall;
609
- parsedArguments: ToolsContextParsedArguments;
610
- } & LOCAL<BaseChildConfig>;
611
- type ThreadWorkerResultOk = {
612
- status: 'ok';
613
- /** id of the tool call that was processed */
614
- toolCallId: string;
615
- /** result of the tool call */
616
- data: unknown;
617
- };
618
- type ThreadWorkerResult = ThreadWorkerResultOk | RESULT<BaseChildConfig>;
619
- interface ToolsContextWorkerConfig extends BaseChildConfig<ThreadWorkerResult, ToolsContextWorkerLocal> {
620
- dataOut: ToolsContextWorkerOut;
621
- state: ToolsContextWorkerState;
622
- }
623
-
624
- declare class ToolsContextWorker extends BaseStep<ToolsContextWorkerConfig> {
625
- static readonly class = "tl_wrk";
626
- static start(thread: IThread<ToolsContextConfig>, toolCall: ChatCompletionMessageFunctionToolCall$1): Promise<void>;
627
- static getThreadId(toolCall: ChatCompletionMessageFunctionToolCall$1): IThreadId;
628
- /**
629
- * Initializes the tool worker thread to handle processing of repackaged content chunks.
630
- */
631
- runStep(): void;
632
- protected getExitName(): string;
633
- }
634
-
635
- declare class ToolsContext extends BaseStep<ToolsContextConfig> {
636
- static readonly class = "tl_ctrl";
637
- static start<T extends ContentContextConfig>(thread: IThread<T>): Promise<void>;
638
- static callTool<T extends ContentContextConfig>(thread: IThread<T>, toolCall: ChatCompletionMessageFunctionToolCall$1): Promise<void>;
639
- /**
640
- * Notify tools context thread that no more tool calls are expected
641
- */
642
- static lastToolCallReceived<T extends ContentContextConfig>(thread: IThread<T>): Promise<void>;
643
- static getThreadId(stepId: IStepId): IThreadId;
644
- runStep(): void;
645
- initialize(): void;
646
- onCallTool(event: ToolsContextEventCallTool): void;
647
- onLastToolCallReceived(): void;
648
- onWorkerThreadEnd(event: IActionEvent<ToolsContextWorkerConfig, ACTION.end>): void;
649
- /**
650
- * Starts the tool worker thread to process the tool call.
651
- */
652
- protected startToolWorkerThread(toolCall: ChatCompletionMessageFunctionToolCall$1): void;
653
- protected setToolCallResult(toolCallId: string, result: unknown): void;
654
- protected tryEndToolsContextThread(): void;
655
- protected get messages(): ChatCompletionToolMessageParam$2[];
656
- }
657
-
658
- declare class CreateChatCompletionStep extends BaseStep<ChatCompletionConfig> {
659
- runStep(): void;
660
- initialize(): Promise<void>;
661
- onContentContextEnd(event: IActionEvent<ContentContextConfig, ACTION.end>): Promise<void>;
662
- onHistoryContextEnd(event: IActionEvent<HistoryContextConfig, ACTION.end>): Promise<void>;
663
- onCancel(): Promise<void>;
664
- private tryToExitStep;
665
- /**
666
- * Reset the step so it can handle new request
667
- *
668
- * - Reset state of initial thread (e.g. main) to original state;
669
- * - End CancelContext thread;
670
- * - End ContentController (with child thread);
671
- *
672
- * @throws if there any issues with stopping threads
673
- */
674
- private resetStep;
675
- private resetState;
676
- private validateMergeFieldType;
677
- private get contentContext();
678
- }
679
-
680
- declare const states: {
681
- hst_ctrl: typeof HistoryContext;
682
- rqst_ctx: typeof RequestContext;
683
- tl_ctrl: typeof ToolsContext;
684
- tl_wrk: typeof ToolsContextWorker;
685
- cnt_cxt_smp: typeof SimpleContentContext;
686
- cnt_cxt_str: typeof StreamContentContext;
687
- str_wrk: typeof StreamContentContextWorker;
688
- cncl_ctrl: typeof CancelContext;
689
- };
690
-
691
- export { type CallToolParameters, type CancelContentEventName, type CancelContextConfig, type CancelContextEvents, type CancelContextState, type ChatCompletionCancelEvent, type ChatCompletionConfig, type ChatCompletionEvent, type ChatCompletionOut, type ChatCompletionState, type ContentChunk, type ContentChunkEvent, type ContentContentEventName, type ContentContextConfig, type ContentContextEvent, type ContentContextHandleContentEvent, type ContentContextOkResult, type ContentContextResult, type ContentContextState, type ContentEndEvent, type ContentEvent, type HistoryContextAppendParameters, type HistoryContextConfig, type HistoryContextEvent, type HistoryContextEventAdjustOnCancel, type HistoryContextEventAppendToHistory, type HistoryContextEventName, type HistoryContextEventPrepareHistory, type HistoryContextState, type ParentEventName, type RequestContextConfig, type RequestContextResult, type RequestContextResultOk, type RequestContextState, type SimpleContentContextConfig, type SimpleContentContextEvent, type SimpleContentContextHandleContentEvent, type StreamContentContextConfig, type StreamContentContextEvent, type StreamContentContextHandleContentEvent, type StreamContentContextState, type StreamContentContextWorkerConfig, type StreamContentContextWorkerOut, type StreamContentContextWorkerResult, type StreamContentContextWorkerState, type TasksMap, type ThreadWorkerResult, type ThreadWorkerResultOk, type ToolCallTask, type ToolContextEventName, type ToolsContextConfig, type ToolsContextEvent, type ToolsContextEventCallTool, type ToolsContextEventLastToolReceived, type ToolsContextParsedArguments, type ToolsContextResult, type ToolsContextResultOk, type ToolsContextState, type ToolsContextWorkerConfig, type ToolsContextWorkerLocal, type ToolsContextWorkerMergeField, type ToolsContextWorkerOut, type ToolsContextWorkerState, cancelContentEvents, cancelContextClassId, contentContextEvents, historyContextClassId, historyContextEvents, parentEvents, requestContextClassId, states, CreateChatCompletionStep as step, streamContentContextClassId, streamContentContextWorkerClassId, streamWorkerExits, toolContextEvents, toolsContextClassId, toolsContextWorkerClassId };