@onereach/step-create-chat-completion 0.0.7-rc.58 → 0.0.7-rc.60

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