llmz 0.3.1 → 0.5.0
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/{chunk-XMFQVARN.js → chunk-4POZJQXN.js} +29 -4
- package/dist/{chunk-KG5E3UZZ.cjs → chunk-5WBNTV42.cjs} +34 -9
- package/dist/{chunk-OVRDJMZJ.cjs → chunk-KTDBAJBB.cjs} +73 -17
- package/dist/{chunk-OXEKAOVI.js → chunk-LOX7GOR6.js} +73 -17
- package/dist/component.d.ts +32 -0
- package/dist/component.default.d.ts +120 -64
- package/dist/context.d.ts +7 -1
- package/dist/{dual-modes-BYABHBDI.js → dual-modes-S5TJ5JVJ.js} +1 -1
- package/dist/{dual-modes-HO6RRIZ5.cjs → dual-modes-TCMWBZIH.cjs} +2 -2
- package/dist/{execute-DPCZ6PKH.js → execute-FF7D46TY.js} +10 -5
- package/dist/{execute-2H4F7GFE.cjs → execute-IK6O4SU2.cjs} +25 -20
- package/dist/index.cjs +75 -116
- package/dist/index.js +67 -108
- package/dist/index.workerd.js +164 -124
- package/dist/prompts/chat-mode/system.md.d.ts +1 -1
- package/dist/runtime/types.d.ts +7 -1
- package/dist/transcript.d.ts +37 -1
- package/package.json +2 -2
package/dist/component.d.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import { z } from '@bpinternal/zui';
|
|
2
2
|
import { JsxComponent } from './jsx.js';
|
|
3
|
+
import type { BodyFormat, GenerativeComponentMetadata } from './message-stream/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated TSX-era examples are no longer shown to the model — llmz
|
|
6
|
+
* generates ■-protocol blocks, not TSX. Use `generation.examples`
|
|
7
|
+
* ({ props?, body? }) instead.
|
|
8
|
+
*/
|
|
3
9
|
export type ExampleUsage = {
|
|
4
10
|
name: string;
|
|
5
11
|
description: string;
|
|
6
12
|
code: string;
|
|
7
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Optional body configuration for components that accept a message body
|
|
16
|
+
* (`default` and `container` types). Controls how the body is documented to
|
|
17
|
+
* the model in the ■ protocol reference.
|
|
18
|
+
*/
|
|
19
|
+
export type ComponentBodyOptions = {
|
|
20
|
+
/** How the body should be written: 'markdown' (default), 'text' (plain prose) or 'code'. */
|
|
21
|
+
format?: BodyFormat;
|
|
22
|
+
/** Model-facing description of what the body must contain. */
|
|
23
|
+
description?: string;
|
|
24
|
+
/** Whether a body is required. Defaults to true. */
|
|
25
|
+
required?: boolean;
|
|
26
|
+
};
|
|
8
27
|
export type ComponentChild = {
|
|
9
28
|
description: string;
|
|
10
29
|
component: ComponentDefinition;
|
|
@@ -15,7 +34,12 @@ export type DefaultComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<
|
|
|
15
34
|
name: string;
|
|
16
35
|
aliases: string[];
|
|
17
36
|
description: string;
|
|
37
|
+
/** @deprecated Not shown to the model. Use `generation.examples` instead. */
|
|
18
38
|
examples?: ExampleUsage[];
|
|
39
|
+
/** Body configuration for the ■ protocol reference (format, description, required). */
|
|
40
|
+
body?: ComponentBodyOptions;
|
|
41
|
+
/** Model-facing generation metadata: usage guidance and ■-protocol examples ({ props?, body? }). */
|
|
42
|
+
generation?: GenerativeComponentMetadata;
|
|
19
43
|
default: {
|
|
20
44
|
props: T;
|
|
21
45
|
children: Array<ComponentChild>;
|
|
@@ -26,7 +50,10 @@ export type LeafComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any
|
|
|
26
50
|
name: string;
|
|
27
51
|
description: string;
|
|
28
52
|
aliases?: string[];
|
|
53
|
+
/** @deprecated Not shown to the model. Use `generation.examples` instead. */
|
|
29
54
|
examples?: ExampleUsage[];
|
|
55
|
+
/** Model-facing generation metadata: usage guidance and ■-protocol examples ({ props? }). */
|
|
56
|
+
generation?: GenerativeComponentMetadata;
|
|
30
57
|
leaf: {
|
|
31
58
|
props: T;
|
|
32
59
|
};
|
|
@@ -36,7 +63,12 @@ export type ContainerComponentDefinition<T extends z.ZodObject<any> = z.ZodObjec
|
|
|
36
63
|
name: string;
|
|
37
64
|
description: string;
|
|
38
65
|
aliases?: string[];
|
|
66
|
+
/** @deprecated Not shown to the model. Use `generation.examples` instead. */
|
|
39
67
|
examples?: ExampleUsage[];
|
|
68
|
+
/** Body configuration for the ■ protocol reference (format, description, required). */
|
|
69
|
+
body?: ComponentBodyOptions;
|
|
70
|
+
/** Model-facing generation metadata: usage guidance and ■-protocol examples ({ props?, body? }). */
|
|
71
|
+
generation?: GenerativeComponentMetadata;
|
|
40
72
|
container: {
|
|
41
73
|
props: T;
|
|
42
74
|
children: Array<ComponentChild>;
|
|
@@ -6,11 +6,16 @@ export declare const DefaultComponents: {
|
|
|
6
6
|
description: string;
|
|
7
7
|
name: string;
|
|
8
8
|
aliases: string[];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
generation: {
|
|
10
|
+
usage: string;
|
|
11
|
+
examples: {
|
|
12
|
+
props: {
|
|
13
|
+
action: string;
|
|
14
|
+
label: string;
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
14
19
|
leaf: {
|
|
15
20
|
props: z.ZodObject<{
|
|
16
21
|
action: z.ZodDefault<z.ZodEnum<["say", "url", "postback"]>>;
|
|
@@ -25,11 +30,14 @@ export declare const DefaultComponents: {
|
|
|
25
30
|
name: string;
|
|
26
31
|
description: string;
|
|
27
32
|
aliases: never[];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
generation: {
|
|
34
|
+
examples: {
|
|
35
|
+
props: {
|
|
36
|
+
url: string;
|
|
37
|
+
alt: string;
|
|
38
|
+
};
|
|
39
|
+
}[];
|
|
40
|
+
};
|
|
33
41
|
leaf: {
|
|
34
42
|
props: z.ZodObject<{
|
|
35
43
|
url: z.ZodString;
|
|
@@ -42,11 +50,14 @@ export declare const DefaultComponents: {
|
|
|
42
50
|
name: string;
|
|
43
51
|
description: string;
|
|
44
52
|
aliases: never[];
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
generation: {
|
|
54
|
+
examples: {
|
|
55
|
+
props: {
|
|
56
|
+
url: string;
|
|
57
|
+
name: string;
|
|
58
|
+
};
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
50
61
|
leaf: {
|
|
51
62
|
props: z.ZodObject<{
|
|
52
63
|
url: z.ZodString;
|
|
@@ -59,11 +70,14 @@ export declare const DefaultComponents: {
|
|
|
59
70
|
name: string;
|
|
60
71
|
description: string;
|
|
61
72
|
aliases: never[];
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
73
|
+
generation: {
|
|
74
|
+
examples: {
|
|
75
|
+
props: {
|
|
76
|
+
url: string;
|
|
77
|
+
title: string;
|
|
78
|
+
};
|
|
79
|
+
}[];
|
|
80
|
+
};
|
|
67
81
|
leaf: {
|
|
68
82
|
props: z.ZodObject<{
|
|
69
83
|
url: z.ZodString;
|
|
@@ -76,11 +90,14 @@ export declare const DefaultComponents: {
|
|
|
76
90
|
name: string;
|
|
77
91
|
description: string;
|
|
78
92
|
aliases: never[];
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
generation: {
|
|
94
|
+
examples: {
|
|
95
|
+
props: {
|
|
96
|
+
url: string;
|
|
97
|
+
title: string;
|
|
98
|
+
};
|
|
99
|
+
}[];
|
|
100
|
+
};
|
|
84
101
|
leaf: {
|
|
85
102
|
props: z.ZodObject<{
|
|
86
103
|
url: z.ZodString;
|
|
@@ -93,11 +110,15 @@ export declare const DefaultComponents: {
|
|
|
93
110
|
name: string;
|
|
94
111
|
description: string;
|
|
95
112
|
aliases: never[];
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
113
|
+
generation: {
|
|
114
|
+
examples: {
|
|
115
|
+
props: {
|
|
116
|
+
title: string;
|
|
117
|
+
subtitle: string;
|
|
118
|
+
};
|
|
119
|
+
body: string;
|
|
120
|
+
}[];
|
|
121
|
+
};
|
|
101
122
|
container: {
|
|
102
123
|
props: z.ZodObject<{
|
|
103
124
|
title: z.ZodString;
|
|
@@ -110,11 +131,14 @@ export declare const DefaultComponents: {
|
|
|
110
131
|
name: string;
|
|
111
132
|
description: string;
|
|
112
133
|
aliases: never[];
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
134
|
+
generation: {
|
|
135
|
+
examples: {
|
|
136
|
+
props: {
|
|
137
|
+
url: string;
|
|
138
|
+
alt: string;
|
|
139
|
+
};
|
|
140
|
+
}[];
|
|
141
|
+
};
|
|
118
142
|
leaf: {
|
|
119
143
|
props: z.ZodObject<{
|
|
120
144
|
url: z.ZodString;
|
|
@@ -129,11 +153,16 @@ export declare const DefaultComponents: {
|
|
|
129
153
|
description: string;
|
|
130
154
|
name: string;
|
|
131
155
|
aliases: string[];
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
156
|
+
generation: {
|
|
157
|
+
usage: string;
|
|
158
|
+
examples: {
|
|
159
|
+
props: {
|
|
160
|
+
action: string;
|
|
161
|
+
label: string;
|
|
162
|
+
value: string;
|
|
163
|
+
};
|
|
164
|
+
}[];
|
|
165
|
+
};
|
|
137
166
|
leaf: {
|
|
138
167
|
props: z.ZodObject<{
|
|
139
168
|
action: z.ZodDefault<z.ZodEnum<["say", "url", "postback"]>>;
|
|
@@ -151,11 +180,6 @@ export declare const DefaultComponents: {
|
|
|
151
180
|
name: string;
|
|
152
181
|
description: string;
|
|
153
182
|
aliases: never[];
|
|
154
|
-
examples: {
|
|
155
|
-
name: string;
|
|
156
|
-
description: string;
|
|
157
|
-
code: string;
|
|
158
|
-
}[];
|
|
159
183
|
container: {
|
|
160
184
|
props: z.ZodObject<{}, "strip">;
|
|
161
185
|
children: {
|
|
@@ -165,11 +189,15 @@ export declare const DefaultComponents: {
|
|
|
165
189
|
name: string;
|
|
166
190
|
description: string;
|
|
167
191
|
aliases: never[];
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
192
|
+
generation: {
|
|
193
|
+
examples: {
|
|
194
|
+
props: {
|
|
195
|
+
title: string;
|
|
196
|
+
subtitle: string;
|
|
197
|
+
};
|
|
198
|
+
body: string;
|
|
199
|
+
}[];
|
|
200
|
+
};
|
|
173
201
|
container: {
|
|
174
202
|
props: z.ZodObject<{
|
|
175
203
|
title: z.ZodString;
|
|
@@ -182,11 +210,14 @@ export declare const DefaultComponents: {
|
|
|
182
210
|
name: string;
|
|
183
211
|
description: string;
|
|
184
212
|
aliases: never[];
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
213
|
+
generation: {
|
|
214
|
+
examples: {
|
|
215
|
+
props: {
|
|
216
|
+
url: string;
|
|
217
|
+
alt: string;
|
|
218
|
+
};
|
|
219
|
+
}[];
|
|
220
|
+
};
|
|
190
221
|
leaf: {
|
|
191
222
|
props: z.ZodObject<{
|
|
192
223
|
url: z.ZodString;
|
|
@@ -201,11 +232,16 @@ export declare const DefaultComponents: {
|
|
|
201
232
|
description: string;
|
|
202
233
|
name: string;
|
|
203
234
|
aliases: string[];
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
235
|
+
generation: {
|
|
236
|
+
usage: string;
|
|
237
|
+
examples: {
|
|
238
|
+
props: {
|
|
239
|
+
action: string;
|
|
240
|
+
label: string;
|
|
241
|
+
value: string;
|
|
242
|
+
};
|
|
243
|
+
}[];
|
|
244
|
+
};
|
|
209
245
|
leaf: {
|
|
210
246
|
props: z.ZodObject<{
|
|
211
247
|
action: z.ZodDefault<z.ZodEnum<["say", "url", "postback"]>>;
|
|
@@ -226,11 +262,31 @@ export declare const DefaultComponents: {
|
|
|
226
262
|
name: string;
|
|
227
263
|
aliases: string[];
|
|
228
264
|
description: string;
|
|
229
|
-
|
|
230
|
-
|
|
265
|
+
generation: {
|
|
266
|
+
examples: {
|
|
267
|
+
body: string;
|
|
268
|
+
}[];
|
|
269
|
+
};
|
|
270
|
+
default: {
|
|
271
|
+
props: z.ZodObject<{}, "strip">;
|
|
272
|
+
children: never[];
|
|
273
|
+
};
|
|
274
|
+
}>;
|
|
275
|
+
Speech: Component<{
|
|
276
|
+
type: "default";
|
|
277
|
+
name: string;
|
|
278
|
+
aliases: string[];
|
|
279
|
+
description: string;
|
|
280
|
+
body: {
|
|
281
|
+
format: "text";
|
|
231
282
|
description: string;
|
|
232
|
-
|
|
233
|
-
|
|
283
|
+
};
|
|
284
|
+
generation: {
|
|
285
|
+
usage: string;
|
|
286
|
+
examples: {
|
|
287
|
+
body: string;
|
|
288
|
+
}[];
|
|
289
|
+
};
|
|
234
290
|
default: {
|
|
235
291
|
props: z.ZodObject<{}, "strip">;
|
|
236
292
|
children: never[];
|
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Models } from '@botpress/cognitive';
|
|
1
|
+
import { Models, SttModels } from '@botpress/cognitive';
|
|
2
2
|
import { z } from '@bpinternal/zui';
|
|
3
3
|
import { Chat } from './chat.js';
|
|
4
4
|
import { Component } from './component.js';
|
|
@@ -564,6 +564,11 @@ export declare class Context implements Serializable<Context.JSON> {
|
|
|
564
564
|
* before the cognitive service falls back to the next model/provider.
|
|
565
565
|
*/
|
|
566
566
|
maxTimeToFirstToken?: number;
|
|
567
|
+
/**
|
|
568
|
+
* STT model used by the cognitive service to transcribe audio attachments
|
|
569
|
+
* when the target LLM does not support audio natively. Defaults to 'fast'.
|
|
570
|
+
*/
|
|
571
|
+
transcriptionModel?: SttModels;
|
|
567
572
|
metadata: Record<string, any>;
|
|
568
573
|
snapshot?: Snapshot;
|
|
569
574
|
iteration: number;
|
|
@@ -595,6 +600,7 @@ export declare class Context implements Serializable<Context.JSON> {
|
|
|
595
600
|
timeout?: number;
|
|
596
601
|
maxTokens?: number;
|
|
597
602
|
maxTimeToFirstToken?: number;
|
|
603
|
+
transcriptionModel?: SttModels;
|
|
598
604
|
});
|
|
599
605
|
toJSON(): {
|
|
600
606
|
id: string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkKTDBAJBBcjs = require('./chunk-KTDBAJBB.cjs');
|
|
4
4
|
require('./chunk-KIN7Y247.cjs');
|
|
5
5
|
require('./chunk-HEAQAEFZ.cjs');
|
|
6
6
|
require('./chunk-GOWPACSK.cjs');
|
|
7
7
|
require('./chunk-HC2QZTVT.cjs');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.DualModePrompt =
|
|
10
|
+
exports.DualModePrompt = _chunkKTDBAJBBcjs.DualModePrompt;
|
|
@@ -11,11 +11,11 @@ import {
|
|
|
11
11
|
SuccessExecutionResult,
|
|
12
12
|
_CustomModelClient,
|
|
13
13
|
parseExit
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-4POZJQXN.js";
|
|
15
15
|
import {
|
|
16
16
|
StreamingMessageParser,
|
|
17
17
|
toParsedAssistantResponse
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-LOX7GOR6.js";
|
|
19
19
|
import "./chunk-UGHFNCPD.js";
|
|
20
20
|
import "./chunk-TDALRNGL.js";
|
|
21
21
|
import "./chunk-GDJTKI7J.js";
|
|
@@ -168,6 +168,9 @@ var generateCode = async ({
|
|
|
168
168
|
ended_at: startedAt,
|
|
169
169
|
model: model.id
|
|
170
170
|
});
|
|
171
|
+
const hasAudioParts = messages.some(
|
|
172
|
+
(message) => Array.isArray(message.content) && message.content.some((part) => part.type === "audio")
|
|
173
|
+
);
|
|
171
174
|
const input = {
|
|
172
175
|
model: iteration.model,
|
|
173
176
|
temperature: iteration.temperature,
|
|
@@ -175,7 +178,8 @@ var generateCode = async ({
|
|
|
175
178
|
reasoningEffort: iteration.reasoningEffort,
|
|
176
179
|
messages,
|
|
177
180
|
stopSequences: ctx.version.getStopTokens(),
|
|
178
|
-
meta: metadata ? { metadata } : void 0
|
|
181
|
+
meta: metadata ? { metadata } : void 0,
|
|
182
|
+
options: hasAudioParts ? { transcriptionModel: ctx.transcriptionModel ?? "fast" } : void 0
|
|
179
183
|
};
|
|
180
184
|
let responseMetadata;
|
|
181
185
|
let raw;
|
|
@@ -232,7 +236,7 @@ var generateCode = async ({
|
|
|
232
236
|
...input,
|
|
233
237
|
// Passed through to the cognitive request: fall back to the next
|
|
234
238
|
// model/provider when the first token takes too long
|
|
235
|
-
...ctx.maxTimeToFirstToken ? { options: { maxTimeToFirstToken: ctx.maxTimeToFirstToken } } : {}
|
|
239
|
+
...ctx.maxTimeToFirstToken ? { options: { ...input.options, maxTimeToFirstToken: ctx.maxTimeToFirstToken } } : {}
|
|
236
240
|
},
|
|
237
241
|
{ signal: streamController.signal }
|
|
238
242
|
);
|
|
@@ -735,7 +739,7 @@ var executeContext = async (props) => {
|
|
|
735
739
|
return result;
|
|
736
740
|
};
|
|
737
741
|
var executeContextInternal = async (props) => {
|
|
738
|
-
var _a, _b, _c, _d;
|
|
742
|
+
var _a, _b, _c, _d, _e;
|
|
739
743
|
const controller = createJoinedAbortController([props.signal]);
|
|
740
744
|
const { onIterationStart, onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
|
|
741
745
|
const client = props.client ?? new Client();
|
|
@@ -749,6 +753,7 @@ var executeContextInternal = async (props) => {
|
|
|
749
753
|
timeout: (_b = props.options) == null ? void 0 : _b.timeout,
|
|
750
754
|
maxTokens: (_c = props.options) == null ? void 0 : _c.maxTokens,
|
|
751
755
|
maxTimeToFirstToken: (_d = props.options) == null ? void 0 : _d.maxTimeToFirstToken,
|
|
756
|
+
transcriptionModel: (_e = props.options) == null ? void 0 : _e.transcriptionModel,
|
|
752
757
|
exits: props.exits,
|
|
753
758
|
snapshot: props.snapshot,
|
|
754
759
|
model: props.model,
|
|
@@ -11,11 +11,11 @@ var _chunk3UZKLXADcjs = require('./chunk-3UZKLXAD.cjs');
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunk5WBNTV42cjs = require('./chunk-5WBNTV42.cjs');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _chunkKTDBAJBBcjs = require('./chunk-KTDBAJBB.cjs');
|
|
19
19
|
require('./chunk-RGUG3UMF.cjs');
|
|
20
20
|
require('./chunk-PZE6PIPG.cjs');
|
|
21
21
|
require('./chunk-HMMM32RG.cjs');
|
|
@@ -168,6 +168,9 @@ var generateCode = async ({
|
|
|
168
168
|
ended_at: startedAt,
|
|
169
169
|
model: model.id
|
|
170
170
|
});
|
|
171
|
+
const hasAudioParts = messages.some(
|
|
172
|
+
(message) => Array.isArray(message.content) && message.content.some((part) => part.type === "audio")
|
|
173
|
+
);
|
|
171
174
|
const input = {
|
|
172
175
|
model: iteration.model,
|
|
173
176
|
temperature: iteration.temperature,
|
|
@@ -175,7 +178,8 @@ var generateCode = async ({
|
|
|
175
178
|
reasoningEffort: iteration.reasoningEffort,
|
|
176
179
|
messages,
|
|
177
180
|
stopSequences: ctx.version.getStopTokens(),
|
|
178
|
-
meta: metadata ? { metadata } : void 0
|
|
181
|
+
meta: metadata ? { metadata } : void 0,
|
|
182
|
+
options: hasAudioParts ? { transcriptionModel: _nullishCoalesce(ctx.transcriptionModel, () => ( "fast")) } : void 0
|
|
179
183
|
};
|
|
180
184
|
let responseMetadata;
|
|
181
185
|
let raw;
|
|
@@ -223,7 +227,7 @@ var generateCode = async ({
|
|
|
223
227
|
}
|
|
224
228
|
};
|
|
225
229
|
if (typeof cognitive.generateTextStream === "function") {
|
|
226
|
-
const parser = new (0,
|
|
230
|
+
const parser = new (0, _chunkKTDBAJBBcjs.StreamingMessageParser)();
|
|
227
231
|
const fence = new LeadingFenceFilter();
|
|
228
232
|
const streamController = createJoinedAbortController([controller.signal]);
|
|
229
233
|
const requestedAt = Date.now();
|
|
@@ -232,7 +236,7 @@ var generateCode = async ({
|
|
|
232
236
|
...input,
|
|
233
237
|
// Passed through to the cognitive request: fall back to the next
|
|
234
238
|
// model/provider when the first token takes too long
|
|
235
|
-
...ctx.maxTimeToFirstToken ? { options: { maxTimeToFirstToken: ctx.maxTimeToFirstToken } } : {}
|
|
239
|
+
...ctx.maxTimeToFirstToken ? { options: { ...input.options, maxTimeToFirstToken: ctx.maxTimeToFirstToken } } : {}
|
|
236
240
|
},
|
|
237
241
|
{ signal: streamController.signal }
|
|
238
242
|
);
|
|
@@ -282,7 +286,7 @@ var generateCode = async ({
|
|
|
282
286
|
await dispatchSends(parser.push(remaining));
|
|
283
287
|
}
|
|
284
288
|
await dispatchSends(parser.finish());
|
|
285
|
-
assistantResponse =
|
|
289
|
+
assistantResponse = _chunkKTDBAJBBcjs.toParsedAssistantResponse.call(void 0, parser.items, raw);
|
|
286
290
|
} else {
|
|
287
291
|
const response = await cognitive.generateText(input, { signal: controller.signal }).catch((thrown) => {
|
|
288
292
|
throw new (0, _chunkPK72FAKDcjs.CognitiveError)(`LLM generation failed: ${_chunkGOWPACSKcjs.getErrorMessage.call(void 0, thrown)}`);
|
|
@@ -432,7 +436,7 @@ var applyNextExit = async ({
|
|
|
432
436
|
if (!next) {
|
|
433
437
|
throw new Error("applyNextExit called without a \u25A0next block on the iteration");
|
|
434
438
|
}
|
|
435
|
-
const attempt = (props) =>
|
|
439
|
+
const attempt = (props) => _chunk5WBNTV42cjs.parseExit.call(void 0, Object.keys(props).length ? { action: next.name, value: props } : { action: next.name }, iteration.exits);
|
|
436
440
|
let parsedExit = attempt(next.props);
|
|
437
441
|
const keys = Object.keys(next.props);
|
|
438
442
|
if (!parsedExit.success && keys.length === 1 && ["props", "value", "data"].includes(keys[0])) {
|
|
@@ -735,12 +739,12 @@ var executeContext = async (props) => {
|
|
|
735
739
|
return result;
|
|
736
740
|
};
|
|
737
741
|
var executeContextInternal = async (props) => {
|
|
738
|
-
var _a, _b, _c, _d;
|
|
742
|
+
var _a, _b, _c, _d, _e;
|
|
739
743
|
const controller = createJoinedAbortController([props.signal]);
|
|
740
744
|
const { onIterationStart, onIterationEnd, onTrace, onExit, onBeforeExecution, onAfterTool, onBeforeTool } = props;
|
|
741
745
|
const client = _nullishCoalesce(props.client, () => ( new (0, _client.Client)()));
|
|
742
|
-
const cognitive = _cognitive.Cognitive.isCognitiveClient(client) ||
|
|
743
|
-
const ctx = new (0,
|
|
746
|
+
const cognitive = _cognitive.Cognitive.isCognitiveClient(client) || _chunk5WBNTV42cjs._CustomModelClient.isCustomClient(client) ? client : new (0, _cognitive.Cognitive)({ client });
|
|
747
|
+
const ctx = new (0, _chunk5WBNTV42cjs.Context)({
|
|
744
748
|
chat: props.chat,
|
|
745
749
|
instructions: props.instructions,
|
|
746
750
|
objects: props.objects,
|
|
@@ -749,6 +753,7 @@ var executeContextInternal = async (props) => {
|
|
|
749
753
|
timeout: (_b = props.options) == null ? void 0 : _b.timeout,
|
|
750
754
|
maxTokens: (_c = props.options) == null ? void 0 : _c.maxTokens,
|
|
751
755
|
maxTimeToFirstToken: (_d = props.options) == null ? void 0 : _d.maxTimeToFirstToken,
|
|
756
|
+
transcriptionModel: (_e = props.options) == null ? void 0 : _e.transcriptionModel,
|
|
752
757
|
exits: props.exits,
|
|
753
758
|
snapshot: props.snapshot,
|
|
754
759
|
model: props.model,
|
|
@@ -758,7 +763,7 @@ var executeContextInternal = async (props) => {
|
|
|
758
763
|
try {
|
|
759
764
|
while (true) {
|
|
760
765
|
if (ctx.iterations.length >= ctx.loop) {
|
|
761
|
-
return new (0,
|
|
766
|
+
return new (0, _chunk5WBNTV42cjs.ErrorExecutionResult)(ctx, new (0, _chunkPK72FAKDcjs.LoopExceededError)());
|
|
762
767
|
}
|
|
763
768
|
const iteration = await ctx.nextIteration();
|
|
764
769
|
const unsubscribeTrace = iteration.traces.onPush((traces) => {
|
|
@@ -789,7 +794,7 @@ var executeContextInternal = async (props) => {
|
|
|
789
794
|
}
|
|
790
795
|
}
|
|
791
796
|
});
|
|
792
|
-
return new (0,
|
|
797
|
+
return new (0, _chunk5WBNTV42cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")));
|
|
793
798
|
}
|
|
794
799
|
const iterationResult = await executeIterationWithErrorHandling({
|
|
795
800
|
iteration,
|
|
@@ -819,7 +824,7 @@ var executeContextInternal = async (props) => {
|
|
|
819
824
|
}
|
|
820
825
|
}
|
|
821
826
|
} catch (error) {
|
|
822
|
-
return new (0,
|
|
827
|
+
return new (0, _chunk5WBNTV42cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(error, () => ( "Unknown error")));
|
|
823
828
|
}
|
|
824
829
|
};
|
|
825
830
|
var executeIterationStartHook = async ({
|
|
@@ -906,7 +911,7 @@ var executeIterationWithErrorHandling = async ({
|
|
|
906
911
|
if (!controller.signal.aborted) {
|
|
907
912
|
return {
|
|
908
913
|
type: "return",
|
|
909
|
-
result: new (0,
|
|
914
|
+
result: new (0, _chunk5WBNTV42cjs.ErrorExecutionResult)(ctx, err)
|
|
910
915
|
};
|
|
911
916
|
}
|
|
912
917
|
await finalizeIteration({
|
|
@@ -922,7 +927,7 @@ var executeIterationWithErrorHandling = async ({
|
|
|
922
927
|
});
|
|
923
928
|
return {
|
|
924
929
|
type: "return",
|
|
925
|
-
result: new (0,
|
|
930
|
+
result: new (0, _chunk5WBNTV42cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(controller.signal.reason, () => ( "The operation was aborted")))
|
|
926
931
|
};
|
|
927
932
|
}
|
|
928
933
|
};
|
|
@@ -934,7 +939,7 @@ var transformIterationResult = ({
|
|
|
934
939
|
const exitName = iteration.status.exit_success.exit_name;
|
|
935
940
|
return {
|
|
936
941
|
type: "return",
|
|
937
|
-
result: new (0,
|
|
942
|
+
result: new (0, _chunk5WBNTV42cjs.SuccessExecutionResult)(ctx, {
|
|
938
943
|
exit: iteration.exits.find((x) => x.name === exitName),
|
|
939
944
|
result: iteration.status.exit_success.return_value
|
|
940
945
|
})
|
|
@@ -943,17 +948,17 @@ var transformIterationResult = ({
|
|
|
943
948
|
if (iteration.status.type === "callback_requested") {
|
|
944
949
|
return {
|
|
945
950
|
type: "return",
|
|
946
|
-
result: new (0,
|
|
951
|
+
result: new (0, _chunk5WBNTV42cjs.PartialExecutionResult)(
|
|
947
952
|
ctx,
|
|
948
953
|
iteration.status.callback_requested.signal,
|
|
949
|
-
|
|
954
|
+
_chunk5WBNTV42cjs.Snapshot.fromSignal(iteration.status.callback_requested.signal)
|
|
950
955
|
)
|
|
951
956
|
};
|
|
952
957
|
}
|
|
953
958
|
if (iteration.status.type === "aborted") {
|
|
954
959
|
return {
|
|
955
960
|
type: "return",
|
|
956
|
-
result: new (0,
|
|
961
|
+
result: new (0, _chunk5WBNTV42cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( "The operation was aborted")))
|
|
957
962
|
};
|
|
958
963
|
}
|
|
959
964
|
if (iteration.status.type === "thinking_requested" || iteration.status.type === "exit_error" || iteration.status.type === "execution_error" || iteration.status.type === "invalid_code_error") {
|
|
@@ -961,7 +966,7 @@ var transformIterationResult = ({
|
|
|
961
966
|
}
|
|
962
967
|
return {
|
|
963
968
|
type: "return",
|
|
964
|
-
result: new (0,
|
|
969
|
+
result: new (0, _chunk5WBNTV42cjs.ErrorExecutionResult)(ctx, _nullishCoalesce(iteration.error, () => ( `Unknown error. Status: ${iteration.status.type}`)))
|
|
965
970
|
};
|
|
966
971
|
};
|
|
967
972
|
var executeIteration = async ({
|