llmz 0.7.1 → 0.9.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/README.md +45 -11
- package/dist/{_baseForOwn-buOZDFbK.cjs → _baseForOwn-BfWDTL8L.cjs} +0 -50
- package/dist/chat.d.ts +6 -6
- package/dist/common-BlRFtdf2.js +807 -0
- package/dist/common-BnvrDnIT.cjs +860 -0
- package/dist/compiler-C-OI9sim.cjs +547 -0
- package/dist/compiler-CW1VjQsn.js +473 -0
- package/dist/{component-BwixNVH8.cjs → component-C6Agl2ns.cjs} +3 -3
- package/dist/component.d.ts +4 -4
- package/dist/component.default.d.ts +70 -87
- package/dist/component.default.test.d.ts +1 -0
- package/dist/context.d.ts +14 -8
- package/dist/{custom-client-CMuy7fXU.js → custom-client-ChuZ63zp.js} +128 -30
- package/dist/{custom-client-Bp1TgTKk.cjs → custom-client-DAsGRnYc.cjs} +131 -33
- package/dist/{dual-modes-mNyMThtf.js → dual-modes-DDkoCp3R.js} +1771 -1489
- package/dist/{dual-modes-CfqTk9M8.cjs → dual-modes-DPXiuvNe.cjs} +1767 -1491
- package/dist/example-format.d.ts +8 -0
- package/dist/example.d.ts +45 -0
- package/dist/example.test.d.ts +1 -0
- package/dist/{execute-DP_17lYZ.js → execute-BWcdv9so.js} +77 -85
- package/dist/{execute-msui51b2.cjs → execute-DM2-7y86.cjs} +83 -92
- package/dist/{exit-BGi0Kk0y.cjs → exit-DUM96DN1.cjs} +3 -3
- package/dist/exit-parser.d.ts +2 -0
- package/dist/index.cjs +137 -217
- package/dist/index.d.ts +2 -0
- package/dist/index.js +115 -196
- package/dist/index.workerd.js +16664 -15533
- package/dist/inspect.d.ts +2 -0
- package/dist/{jsx-BWvT6ukg.cjs → jsx-owqxrquU.cjs} +2 -2
- package/dist/message-stream/instructions.d.ts +8 -0
- package/dist/message-stream/parser.d.ts +9 -0
- package/dist/message-stream/response-parser.d.ts +24 -0
- package/dist/message-stream/response-parser.test.d.ts +1 -0
- package/dist/message-stream/types.d.ts +3 -2
- package/dist/prompts/adherence.test.d.ts +1 -0
- package/dist/prompts/catalogue-examples.test.d.ts +1 -0
- package/dist/prompts/chat-mode/protocol.d.ts +2 -0
- package/dist/prompts/chat-mode/system.d.ts +2 -0
- package/dist/prompts/chat-mode/user.d.ts +2 -0
- package/dist/prompts/code-examples.d.ts +2 -0
- package/dist/prompts/code-examples.test.d.ts +1 -0
- package/dist/prompts/common.d.ts +2 -1
- package/dist/prompts/concrete-patterns.test.d.ts +1 -0
- package/dist/prompts/execution-history.d.ts +6 -0
- package/dist/prompts/execution-state.d.ts +3 -0
- package/dist/prompts/long-search.test.d.ts +1 -0
- package/dist/prompts/prompt.d.ts +31 -2
- package/dist/prompts/protocol-basics.d.ts +5 -0
- package/dist/prompts/protocol-simple.test.d.ts +1 -0
- package/dist/prompts/protocol.d.ts +13 -0
- package/dist/prompts/protocol.test.d.ts +1 -0
- package/dist/prompts/sections.test.d.ts +1 -0
- package/dist/prompts/worker-mode/protocol.d.ts +2 -0
- package/dist/prompts/worker-mode/system.d.ts +2 -0
- package/dist/prompts/worker-mode/user.d.ts +2 -0
- package/dist/runtime/citations.test.d.ts +1 -0
- package/dist/runtime/fixtures/long-search.d.ts +19 -0
- package/dist/runtime/fixtures/protocol-languages.d.ts +74 -0
- package/dist/runtime/fixtures/qwen-protocol-failures.d.ts +29 -0
- package/dist/runtime/generate.d.ts +2 -9
- package/dist/runtime/protocol-adherence.test.d.ts +1 -0
- package/dist/runtime/types.d.ts +13 -7
- package/dist/{tool-ReA9gxMp.cjs → tool-Dy6AJpJH.cjs} +4 -4
- package/dist/{truncator-B6aaJaN1.cjs → truncator-CLkouTCO.cjs} +3 -3
- package/dist/{typings-BwAz_TM9.cjs → typings-3lsqCbkn.cjs} +3 -3
- package/dist/{utils-ZpJm00ed.cjs → utils-3ESwP3yg.cjs} +2 -2
- package/dist/{vm-C5vf1LH3.js → vm-BLsHw1da.js} +3 -462
- package/dist/{vm-BjkJqSQH.cjs → vm-D6s1zF6M.cjs} +28 -489
- package/package.json +1 -1
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import { z } from '@bpinternal/zui';
|
|
2
|
-
import { Component } from './component.js';
|
|
2
|
+
import { Component, type ContainerComponentDefinition, type RenderedComponent } from './component.js';
|
|
3
|
+
declare const carouselProps: z.ZodObject<{
|
|
4
|
+
cards: z.ZodArray<z.ZodObject<{
|
|
5
|
+
title: z.ZodString;
|
|
6
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
7
|
+
body: z.ZodOptional<z.ZodString>;
|
|
8
|
+
image: z.ZodOptional<z.ZodObject<{
|
|
9
|
+
url: z.ZodString;
|
|
10
|
+
alt: z.ZodOptional<z.ZodString>;
|
|
11
|
+
}, "strip">>;
|
|
12
|
+
buttons: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
13
|
+
action: z.ZodDefault<z.ZodEnum<["say", "url", "postback"]>>;
|
|
14
|
+
label: z.ZodString;
|
|
15
|
+
value: z.ZodOptional<z.ZodString>;
|
|
16
|
+
url: z.ZodOptional<z.ZodString>;
|
|
17
|
+
}, "strip">, "many">>;
|
|
18
|
+
}, "strip">, "many">;
|
|
19
|
+
}, "strip">;
|
|
20
|
+
declare class CarouselComponent extends Component<ContainerComponentDefinition<typeof carouselProps>> {
|
|
21
|
+
render(props: Component['propsType'], children?: any[]): RenderedComponent;
|
|
22
|
+
}
|
|
3
23
|
export declare const DefaultComponents: {
|
|
4
24
|
Button: Component<{
|
|
5
25
|
type: "leaf";
|
|
@@ -8,13 +28,33 @@ export declare const DefaultComponents: {
|
|
|
8
28
|
aliases: string[];
|
|
9
29
|
generation: {
|
|
10
30
|
usage: string;
|
|
11
|
-
examples: {
|
|
31
|
+
examples: ({
|
|
32
|
+
props: {
|
|
33
|
+
action: string;
|
|
34
|
+
label: string;
|
|
35
|
+
};
|
|
36
|
+
}[] | {
|
|
12
37
|
props: {
|
|
38
|
+
action: string;
|
|
39
|
+
label: string;
|
|
40
|
+
url?: undefined;
|
|
41
|
+
value?: undefined;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
44
|
+
props: {
|
|
45
|
+
action: string;
|
|
46
|
+
label: string;
|
|
47
|
+
url: string;
|
|
48
|
+
value?: undefined;
|
|
49
|
+
};
|
|
50
|
+
} | {
|
|
51
|
+
props: {
|
|
52
|
+
url?: undefined;
|
|
13
53
|
action: string;
|
|
14
54
|
label: string;
|
|
15
55
|
value: string;
|
|
16
56
|
};
|
|
17
|
-
}[];
|
|
57
|
+
})[];
|
|
18
58
|
};
|
|
19
59
|
leaf: {
|
|
20
60
|
props: z.ZodObject<{
|
|
@@ -31,6 +71,7 @@ export declare const DefaultComponents: {
|
|
|
31
71
|
description: string;
|
|
32
72
|
aliases: never[];
|
|
33
73
|
generation: {
|
|
74
|
+
usage: string;
|
|
34
75
|
examples: {
|
|
35
76
|
props: {
|
|
36
77
|
url: string;
|
|
@@ -111,6 +152,7 @@ export declare const DefaultComponents: {
|
|
|
111
152
|
description: string;
|
|
112
153
|
aliases: never[];
|
|
113
154
|
generation: {
|
|
155
|
+
usage: string;
|
|
114
156
|
examples: {
|
|
115
157
|
props: {
|
|
116
158
|
title: string;
|
|
@@ -132,6 +174,7 @@ export declare const DefaultComponents: {
|
|
|
132
174
|
description: string;
|
|
133
175
|
aliases: never[];
|
|
134
176
|
generation: {
|
|
177
|
+
usage: string;
|
|
135
178
|
examples: {
|
|
136
179
|
props: {
|
|
137
180
|
url: string;
|
|
@@ -155,13 +198,33 @@ export declare const DefaultComponents: {
|
|
|
155
198
|
aliases: string[];
|
|
156
199
|
generation: {
|
|
157
200
|
usage: string;
|
|
158
|
-
examples: {
|
|
201
|
+
examples: ({
|
|
202
|
+
props: {
|
|
203
|
+
action: string;
|
|
204
|
+
label: string;
|
|
205
|
+
};
|
|
206
|
+
}[] | {
|
|
159
207
|
props: {
|
|
208
|
+
action: string;
|
|
209
|
+
label: string;
|
|
210
|
+
url?: undefined;
|
|
211
|
+
value?: undefined;
|
|
212
|
+
};
|
|
213
|
+
} | {
|
|
214
|
+
props: {
|
|
215
|
+
action: string;
|
|
216
|
+
label: string;
|
|
217
|
+
url: string;
|
|
218
|
+
value?: undefined;
|
|
219
|
+
};
|
|
220
|
+
} | {
|
|
221
|
+
props: {
|
|
222
|
+
url?: undefined;
|
|
160
223
|
action: string;
|
|
161
224
|
label: string;
|
|
162
225
|
value: string;
|
|
163
226
|
};
|
|
164
|
-
}[];
|
|
227
|
+
})[];
|
|
165
228
|
};
|
|
166
229
|
leaf: {
|
|
167
230
|
props: z.ZodObject<{
|
|
@@ -175,88 +238,7 @@ export declare const DefaultComponents: {
|
|
|
175
238
|
})[];
|
|
176
239
|
};
|
|
177
240
|
}>;
|
|
178
|
-
Carousel:
|
|
179
|
-
type: "container";
|
|
180
|
-
name: string;
|
|
181
|
-
description: string;
|
|
182
|
-
aliases: never[];
|
|
183
|
-
container: {
|
|
184
|
-
props: z.ZodObject<{}, "strip">;
|
|
185
|
-
children: {
|
|
186
|
-
description: string;
|
|
187
|
-
component: {
|
|
188
|
-
type: "container";
|
|
189
|
-
name: string;
|
|
190
|
-
description: string;
|
|
191
|
-
aliases: never[];
|
|
192
|
-
generation: {
|
|
193
|
-
examples: {
|
|
194
|
-
props: {
|
|
195
|
-
title: string;
|
|
196
|
-
subtitle: string;
|
|
197
|
-
};
|
|
198
|
-
body: string;
|
|
199
|
-
}[];
|
|
200
|
-
};
|
|
201
|
-
container: {
|
|
202
|
-
props: z.ZodObject<{
|
|
203
|
-
title: z.ZodString;
|
|
204
|
-
subtitle: z.ZodOptional<z.ZodString>;
|
|
205
|
-
}, "strip">;
|
|
206
|
-
children: ({
|
|
207
|
-
description: string;
|
|
208
|
-
component: {
|
|
209
|
-
type: "leaf";
|
|
210
|
-
name: string;
|
|
211
|
-
description: string;
|
|
212
|
-
aliases: never[];
|
|
213
|
-
generation: {
|
|
214
|
-
examples: {
|
|
215
|
-
props: {
|
|
216
|
-
url: string;
|
|
217
|
-
alt: string;
|
|
218
|
-
};
|
|
219
|
-
}[];
|
|
220
|
-
};
|
|
221
|
-
leaf: {
|
|
222
|
-
props: z.ZodObject<{
|
|
223
|
-
url: z.ZodString;
|
|
224
|
-
alt: z.ZodOptional<z.ZodString>;
|
|
225
|
-
}, "strip">;
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
} | {
|
|
229
|
-
description: string;
|
|
230
|
-
component: {
|
|
231
|
-
type: "leaf";
|
|
232
|
-
description: string;
|
|
233
|
-
name: string;
|
|
234
|
-
aliases: string[];
|
|
235
|
-
generation: {
|
|
236
|
-
usage: string;
|
|
237
|
-
examples: {
|
|
238
|
-
props: {
|
|
239
|
-
action: string;
|
|
240
|
-
label: string;
|
|
241
|
-
value: string;
|
|
242
|
-
};
|
|
243
|
-
}[];
|
|
244
|
-
};
|
|
245
|
-
leaf: {
|
|
246
|
-
props: z.ZodObject<{
|
|
247
|
-
action: z.ZodDefault<z.ZodEnum<["say", "url", "postback"]>>;
|
|
248
|
-
label: z.ZodString;
|
|
249
|
-
value: z.ZodOptional<z.ZodString>;
|
|
250
|
-
url: z.ZodOptional<z.ZodString>;
|
|
251
|
-
}, "strip">;
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
})[];
|
|
255
|
-
};
|
|
256
|
-
};
|
|
257
|
-
}[];
|
|
258
|
-
};
|
|
259
|
-
}>;
|
|
241
|
+
Carousel: CarouselComponent;
|
|
260
242
|
Text: Component<{
|
|
261
243
|
type: "default";
|
|
262
244
|
name: string;
|
|
@@ -293,3 +275,4 @@ export declare const DefaultComponents: {
|
|
|
293
275
|
};
|
|
294
276
|
}>;
|
|
295
277
|
};
|
|
278
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { z } from '@bpinternal/zui';
|
|
|
3
3
|
import { Chat } from './chat.js';
|
|
4
4
|
import { Component } from './component.js';
|
|
5
5
|
import { SnapshotSignal } from './errors.js';
|
|
6
|
+
import type { Example } from './example.js';
|
|
6
7
|
import { Exit } from './exit.js';
|
|
7
8
|
import { ValueOrGetter } from './getter.js';
|
|
8
9
|
import { HookedArray } from './handlers.js';
|
|
@@ -30,6 +31,8 @@ export type ContextTokens = {
|
|
|
30
31
|
transcript: number;
|
|
31
32
|
/** The ■ protocol reference documenting components and exits. */
|
|
32
33
|
protocol: number;
|
|
34
|
+
/** Consumer few-shot demonstrations, separate from the live transcript. */
|
|
35
|
+
examples: number;
|
|
33
36
|
/** Messages carried over from previous iterations (assistant responses, execution results, errors). */
|
|
34
37
|
iterations: number;
|
|
35
38
|
};
|
|
@@ -57,6 +60,7 @@ export type IterationParameters = {
|
|
|
57
60
|
objects: ObjectInstance[];
|
|
58
61
|
exits: Exit[];
|
|
59
62
|
instructions?: string;
|
|
63
|
+
examples?: Example[];
|
|
60
64
|
components: Component[];
|
|
61
65
|
model: Models | Models[];
|
|
62
66
|
temperature: number;
|
|
@@ -93,6 +97,8 @@ export declare namespace IterationStatuses {
|
|
|
93
97
|
/** The value returned by the executed code (or the context provided by a ThinkSignal). */
|
|
94
98
|
variables: unknown;
|
|
95
99
|
metadata?: Record<string, unknown>;
|
|
100
|
+
/** A tool paused execution; it did not finish or return normally. */
|
|
101
|
+
interrupted?: boolean;
|
|
96
102
|
};
|
|
97
103
|
};
|
|
98
104
|
type Callback = {
|
|
@@ -405,6 +411,7 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
|
|
|
405
411
|
get mutations(): ObjectMutation[];
|
|
406
412
|
trackMutation(mutation: ObjectMutation): void;
|
|
407
413
|
private _parameters;
|
|
414
|
+
get components(): Component[];
|
|
408
415
|
get transcript(): TranscriptArray;
|
|
409
416
|
get tools(): Tool<z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>>[];
|
|
410
417
|
get objects(): ObjectInstance[];
|
|
@@ -551,6 +558,7 @@ export declare class Context implements Serializable<Context.JSON> {
|
|
|
551
558
|
id: string;
|
|
552
559
|
chat?: Chat;
|
|
553
560
|
instructions?: ValueOrGetter<string, Context>;
|
|
561
|
+
examples?: ValueOrGetter<Example[], Context>;
|
|
554
562
|
objects?: ValueOrGetter<ObjectInstance[], Context>;
|
|
555
563
|
tools?: ValueOrGetter<Tool[], Context>;
|
|
556
564
|
exits?: ValueOrGetter<Exit[], Context>;
|
|
@@ -571,14 +579,10 @@ export declare class Context implements Serializable<Context.JSON> {
|
|
|
571
579
|
*/
|
|
572
580
|
maxTimeToFirstToken?: number;
|
|
573
581
|
/**
|
|
574
|
-
* Allow Cognitive to restart a failed stream on another model.
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
* current-iteration messages, including completed sends — consumers must
|
|
579
|
-
* retract/replace them, which is unsafe for irreversible external transports.
|
|
580
|
-
* Only TOOL/CODE execution waits for a successful stream. Streaming-only;
|
|
581
|
-
* defaults to false, which leaves progressive sending unchanged.
|
|
582
|
+
* Allow Cognitive to restart a failed stream on another model. Previews remain
|
|
583
|
+
* live and are retracted with a restart delta before replacement output.
|
|
584
|
+
* Completed sends and code always wait for a valid response and successful
|
|
585
|
+
* transport. Streaming-only; defaults to false.
|
|
582
586
|
*/
|
|
583
587
|
midStreamFallback?: boolean;
|
|
584
588
|
/**
|
|
@@ -588,6 +592,7 @@ export declare class Context implements Serializable<Context.JSON> {
|
|
|
588
592
|
transcriptionModel?: SttModels;
|
|
589
593
|
metadata: Record<string, any>;
|
|
590
594
|
snapshot?: Snapshot;
|
|
595
|
+
private _lastMessageWithoutExecutionState?;
|
|
591
596
|
iteration: number;
|
|
592
597
|
iterations: Iteration[];
|
|
593
598
|
nextIteration(): Promise<Iteration>;
|
|
@@ -605,6 +610,7 @@ export declare class Context implements Serializable<Context.JSON> {
|
|
|
605
610
|
constructor(props: {
|
|
606
611
|
chat?: Chat;
|
|
607
612
|
instructions?: ValueOrGetter<string, Context>;
|
|
613
|
+
examples?: ValueOrGetter<Example[], Context>;
|
|
608
614
|
objects?: ValueOrGetter<ObjectInstance[], Context>;
|
|
609
615
|
tools?: ValueOrGetter<Tool[], Context>;
|
|
610
616
|
exits?: ValueOrGetter<Exit[], Context>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { c as baseCreate, i as inspect, o as flatRest, r as extractType, s as copyArray, t as DualModePrompt } from "./dual-modes-DDkoCp3R.js";
|
|
1
2
|
import { a as Symbol, n as isArray, o as root, r as isObjectLike } from "./_overArg-CRYbj1NH.js";
|
|
2
3
|
import { D as isBuffer, E as baseUnary, M as baseAssignValue, R as isObject, T as nodeUtil, _ as baseGet, c as _getTag_default, f as getSymbols, h as Stack, k as isPrototype, s as Uint8Array, u as getAllKeys, v as toKey, x as keys, y as castPath, z as arrayMap } from "./_baseIteratee-P_firB7b.js";
|
|
3
|
-
import {
|
|
4
|
-
import { _ as getSymbolsIn, b as keysIn, g as getAllKeysIn, o as getTokenizer, x as assignValue, y as baseSlice } from "./utils-UBeAFeEI.js";
|
|
4
|
+
import { _ as getSymbolsIn, b as keysIn, g as getAllKeysIn, i as getErrorMessage, o as getTokenizer, x as assignValue, y as baseSlice } from "./utils-UBeAFeEI.js";
|
|
5
5
|
import { t as getPrototype } from "./_getPrototype-CG7Dxrrz.js";
|
|
6
6
|
import { t as isPlainObject } from "./isPlainObject-D39AzPO2.js";
|
|
7
7
|
import { t as Tool } from "./tool-Bv8N4IPj.js";
|
|
8
|
-
import { o as LoopExceededError } from "./errors-Cg1G0Awu.js";
|
|
8
|
+
import { l as ThinkSignal, o as LoopExceededError } from "./errors-Cg1G0Awu.js";
|
|
9
9
|
import { t as Exit } from "./exit-CDdxDBRT.js";
|
|
10
10
|
import { n as assertValidComponent } from "./component-DGG7d_Mz.js";
|
|
11
11
|
import { i as wrapContent, t as stripTruncationTags } from "./truncator-DZqEqnpD.js";
|
|
@@ -819,7 +819,8 @@ function parseExit(returnValue, exits) {
|
|
|
819
819
|
}
|
|
820
820
|
const schema = returnExit.zSchema;
|
|
821
821
|
const schemaType = schema._def.typeName;
|
|
822
|
-
|
|
822
|
+
const initialParse = schema.safeParse(valueToValidate);
|
|
823
|
+
let parsed = initialParse;
|
|
823
824
|
if (!parsed.success && alternativeValue !== void 0 && alternativeValue !== valueToValidate) {
|
|
824
825
|
const altParsed = schema.safeParse(alternativeValue);
|
|
825
826
|
if (altParsed.success) {
|
|
@@ -833,6 +834,7 @@ function parseExit(returnValue, exits) {
|
|
|
833
834
|
parsed = result.parsed;
|
|
834
835
|
}
|
|
835
836
|
if (!parsed.success) {
|
|
837
|
+
var _initialParse$error;
|
|
836
838
|
const getValueTypeDescription = (val) => {
|
|
837
839
|
if (val === null) return "null";
|
|
838
840
|
if (val === void 0) return "undefined";
|
|
@@ -894,6 +896,7 @@ function parseExit(returnValue, exits) {
|
|
|
894
896
|
"But expected one of:",
|
|
895
897
|
...expectedStatements.map((s) => ` ${s}`)
|
|
896
898
|
].join("\n"),
|
|
899
|
+
validationErrors: (((_initialParse$error = initialParse.error) === null || _initialParse$error === void 0 ? void 0 : _initialParse$error.issues) ?? []).map((issue) => `${issue.path.join(".") || "value"}: ${issue.message}`),
|
|
897
900
|
returnValue
|
|
898
901
|
};
|
|
899
902
|
}
|
|
@@ -1788,6 +1791,49 @@ var HookedArray = class extends Array {
|
|
|
1788
1791
|
}
|
|
1789
1792
|
};
|
|
1790
1793
|
//#endregion
|
|
1794
|
+
//#region src/prompts/execution-history.ts
|
|
1795
|
+
function describeOutcome(status) {
|
|
1796
|
+
switch (status.type) {
|
|
1797
|
+
case "thinking_requested": return status.thinking_requested.interrupted ? "a tool paused execution" : "code completed and returned control";
|
|
1798
|
+
case "execution_error": return "code execution failed";
|
|
1799
|
+
case "invalid_code_error": return "invalid code or protocol";
|
|
1800
|
+
case "exit_error": return "exit validation failed";
|
|
1801
|
+
default: return status.type;
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
/** Summarize observed effects, including failed calls and retracted deliveries. */
|
|
1805
|
+
function summarizeIterations(iterations, canTalk) {
|
|
1806
|
+
const history = [];
|
|
1807
|
+
const attempts = /* @__PURE__ */ new Map();
|
|
1808
|
+
const deliveredMessages = [];
|
|
1809
|
+
for (const [index, iteration] of iterations.entries()) {
|
|
1810
|
+
const calls = [];
|
|
1811
|
+
const lastRestart = iteration.traces.reduce((last, trace, traceIndex) => trace.type === "llm_call_restarted" ? traceIndex : last, -1);
|
|
1812
|
+
for (const [traceIndex, trace] of iteration.traces.entries()) {
|
|
1813
|
+
if (trace.type === "tool_call") {
|
|
1814
|
+
const name = trace.object ? `${trace.object}.${trace.tool_name}` : trace.tool_name;
|
|
1815
|
+
let outcome = "failed or paused";
|
|
1816
|
+
if (trace.success) outcome = trace.output instanceof ThinkSignal ? "paused for attention" : "succeeded";
|
|
1817
|
+
attempts.set(name, (attempts.get(name) ?? 0) + 1);
|
|
1818
|
+
calls.push(`${name}: ${outcome}`);
|
|
1819
|
+
}
|
|
1820
|
+
if (canTalk && trace.type === "yield") deliveredMessages.push({
|
|
1821
|
+
iteration: index + 1,
|
|
1822
|
+
content: trace.value,
|
|
1823
|
+
...traceIndex < lastRestart ? { retracted: true } : {}
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
const outcome = describeOutcome(iteration.status);
|
|
1827
|
+
const toolSummary = calls.length ? ` Tool attempts: ${calls.join("; ")}.` : "";
|
|
1828
|
+
history.push(`Iteration ${index + 1}: ${outcome}.${toolSummary}`);
|
|
1829
|
+
}
|
|
1830
|
+
return {
|
|
1831
|
+
history,
|
|
1832
|
+
toolAttempts: Object.fromEntries(attempts),
|
|
1833
|
+
deliveredMessages: canTalk ? deliveredMessages : void 0
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
//#endregion
|
|
1791
1837
|
//#region src/transcript.ts
|
|
1792
1838
|
const MAX_MESSAGE_LENGTH = 5e3;
|
|
1793
1839
|
function getMessagePreview(message) {
|
|
@@ -1991,7 +2037,7 @@ const ThinkExit = new Exit({
|
|
|
1991
2037
|
*/
|
|
1992
2038
|
const ListenExit = new Exit({
|
|
1993
2039
|
name: "listen",
|
|
1994
|
-
description: "
|
|
2040
|
+
description: "Stop talking and wait for the user to talk next."
|
|
1995
2041
|
});
|
|
1996
2042
|
/**
|
|
1997
2043
|
* Default exit used when no custom exits are provided.
|
|
@@ -2117,6 +2163,9 @@ var Iteration = class {
|
|
|
2117
2163
|
this._mutations.set(`${mutation.object ?? "global"}:${mutation.property}`, mutation);
|
|
2118
2164
|
}
|
|
2119
2165
|
_parameters;
|
|
2166
|
+
get components() {
|
|
2167
|
+
return this._parameters.components;
|
|
2168
|
+
}
|
|
2120
2169
|
get transcript() {
|
|
2121
2170
|
return this._parameters.transcript;
|
|
2122
2171
|
}
|
|
@@ -2234,6 +2283,7 @@ var Context = class {
|
|
|
2234
2283
|
id;
|
|
2235
2284
|
chat;
|
|
2236
2285
|
instructions;
|
|
2286
|
+
examples;
|
|
2237
2287
|
objects;
|
|
2238
2288
|
tools;
|
|
2239
2289
|
exits;
|
|
@@ -2254,14 +2304,10 @@ var Context = class {
|
|
|
2254
2304
|
*/
|
|
2255
2305
|
maxTimeToFirstToken;
|
|
2256
2306
|
/**
|
|
2257
|
-
* Allow Cognitive to restart a failed stream on another model.
|
|
2258
|
-
*
|
|
2259
|
-
*
|
|
2260
|
-
*
|
|
2261
|
-
* current-iteration messages, including completed sends — consumers must
|
|
2262
|
-
* retract/replace them, which is unsafe for irreversible external transports.
|
|
2263
|
-
* Only TOOL/CODE execution waits for a successful stream. Streaming-only;
|
|
2264
|
-
* defaults to false, which leaves progressive sending unchanged.
|
|
2307
|
+
* Allow Cognitive to restart a failed stream on another model. Previews remain
|
|
2308
|
+
* live and are retracted with a restart delta before replacement output.
|
|
2309
|
+
* Completed sends and code always wait for a valid response and successful
|
|
2310
|
+
* transport. Streaming-only; defaults to false.
|
|
2265
2311
|
*/
|
|
2266
2312
|
midStreamFallback;
|
|
2267
2313
|
/**
|
|
@@ -2271,6 +2317,7 @@ var Context = class {
|
|
|
2271
2317
|
transcriptionModel;
|
|
2272
2318
|
metadata;
|
|
2273
2319
|
snapshot;
|
|
2320
|
+
_lastMessageWithoutExecutionState;
|
|
2274
2321
|
iteration = 0;
|
|
2275
2322
|
iterations;
|
|
2276
2323
|
async nextIteration() {
|
|
@@ -2329,18 +2376,20 @@ var Context = class {
|
|
|
2329
2376
|
const tools = countText(parts.tools);
|
|
2330
2377
|
const transcript = countText(parts.transcript);
|
|
2331
2378
|
const protocol = countText(parts.protocol);
|
|
2379
|
+
const examples = countText(parts.examples);
|
|
2332
2380
|
const systemTokens = messages.filter((x) => x.role === "system").reduce((acc, x) => acc + countMessage(x), 0);
|
|
2333
2381
|
const otherTokens = messages.filter((x) => x.role !== "system").reduce((acc, x) => acc + countMessage(x), 0);
|
|
2334
2382
|
const isFirstIteration = this.iterations.length === 0 && !this.snapshot;
|
|
2335
|
-
const framework = Math.max(0, systemTokens - (instructions + tools + transcript + protocol));
|
|
2383
|
+
const framework = Math.max(0, systemTokens - (instructions + tools + transcript + protocol + examples));
|
|
2336
2384
|
const iterations = isFirstIteration ? 0 : otherTokens;
|
|
2337
2385
|
return {
|
|
2338
|
-
total: framework + instructions + tools + transcript + protocol + iterations + (isFirstIteration ? otherTokens : 0),
|
|
2386
|
+
total: framework + instructions + tools + transcript + protocol + examples + iterations + (isFirstIteration ? otherTokens : 0),
|
|
2339
2387
|
framework: framework + (isFirstIteration ? otherTokens : 0),
|
|
2340
2388
|
instructions,
|
|
2341
2389
|
tools,
|
|
2342
2390
|
transcript,
|
|
2343
2391
|
protocol,
|
|
2392
|
+
examples,
|
|
2344
2393
|
iterations
|
|
2345
2394
|
};
|
|
2346
2395
|
}
|
|
@@ -2348,24 +2397,50 @@ var Context = class {
|
|
|
2348
2397
|
var _this$snapshot2, _this$snapshot3;
|
|
2349
2398
|
const lastIteration = this.iterations.at(-1);
|
|
2350
2399
|
const promptProps = {
|
|
2400
|
+
iteration: {
|
|
2401
|
+
current: this.iterations.length + 1,
|
|
2402
|
+
limit: this.loop,
|
|
2403
|
+
resumed: !!this.snapshot,
|
|
2404
|
+
...summarizeIterations(this.iterations, parameters.components.length > 0)
|
|
2405
|
+
},
|
|
2351
2406
|
globalTools: parameters.tools,
|
|
2352
2407
|
objects: parameters.objects,
|
|
2353
2408
|
instructions: parameters.instructions,
|
|
2409
|
+
examples: parameters.examples,
|
|
2354
2410
|
transcript: parameters.transcript,
|
|
2355
2411
|
exits: parameters.components.length ? [...parameters.exits, ListenExit] : parameters.exits,
|
|
2356
2412
|
components: parameters.components
|
|
2357
2413
|
};
|
|
2358
2414
|
const { message: systemMessage, parts } = await this.version.getSystemMessage(promptProps);
|
|
2359
|
-
const
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2415
|
+
const previousLastMessage = this._lastMessageWithoutExecutionState;
|
|
2416
|
+
const withParts = (messages) => {
|
|
2417
|
+
var _this$version$getExec, _this$version;
|
|
2418
|
+
const last = messages.at(-1);
|
|
2419
|
+
this._lastMessageWithoutExecutionState = last;
|
|
2420
|
+
const state = ((_this$version$getExec = (_this$version = this.version).getExecutionState) === null || _this$version$getExec === void 0 ? void 0 : _this$version$getExec.call(_this$version, promptProps)) ?? "";
|
|
2421
|
+
if (state) messages[messages.length - 1] = Array.isArray(last.content) ? {
|
|
2422
|
+
...last,
|
|
2423
|
+
content: [...last.content, {
|
|
2424
|
+
type: "text",
|
|
2425
|
+
text: state.trim()
|
|
2426
|
+
}]
|
|
2427
|
+
} : {
|
|
2428
|
+
...last,
|
|
2429
|
+
content: (last.content ?? "") + state
|
|
2430
|
+
};
|
|
2431
|
+
return {
|
|
2432
|
+
messages,
|
|
2433
|
+
parts
|
|
2434
|
+
};
|
|
2435
|
+
};
|
|
2363
2436
|
if (((_this$snapshot2 = this.snapshot) === null || _this$snapshot2 === void 0 ? void 0 : _this$snapshot2.status.type) === "resolved") return withParts([systemMessage, this.version.getSnapshotResolvedMessage({ snapshot: this.snapshot })]);
|
|
2364
2437
|
if (((_this$snapshot3 = this.snapshot) === null || _this$snapshot3 === void 0 ? void 0 : _this$snapshot3.status.type) === "rejected") return withParts([systemMessage, this.version.getSnapshotRejectedMessage({ snapshot: this.snapshot })]);
|
|
2365
2438
|
if (!lastIteration) return withParts([systemMessage, await this.version.getInitialUserMessage(promptProps)]);
|
|
2366
|
-
const
|
|
2439
|
+
const history = lastIteration.messages.slice();
|
|
2440
|
+
if (previousLastMessage) history[history.length - 1] = previousLastMessage;
|
|
2441
|
+
const lastIterationMessages = [systemMessage, ...history.filter((x) => x.role !== "system")];
|
|
2367
2442
|
if ((lastIteration === null || lastIteration === void 0 ? void 0 : lastIteration.status.type) === "thinking_requested") {
|
|
2368
|
-
var _lastIteration$llm;
|
|
2443
|
+
var _lastIteration$llm, _lastIteration$llm2;
|
|
2369
2444
|
return withParts([
|
|
2370
2445
|
...lastIterationMessages,
|
|
2371
2446
|
{
|
|
@@ -2377,60 +2452,80 @@ var Context = class {
|
|
|
2377
2452
|
})
|
|
2378
2453
|
},
|
|
2379
2454
|
await this.version.getThinkingMessage({
|
|
2455
|
+
isChatEnabled: parameters.components.length > 0,
|
|
2380
2456
|
reason: lastIteration.status.thinking_requested.reason,
|
|
2381
|
-
variables: lastIteration.status.thinking_requested.variables
|
|
2457
|
+
variables: lastIteration.status.thinking_requested.variables,
|
|
2458
|
+
interrupted: lastIteration.status.thinking_requested.interrupted,
|
|
2459
|
+
discardedMessages: (_lastIteration$llm2 = lastIteration.llm) === null || _lastIteration$llm2 === void 0 || (_lastIteration$llm2 = _lastIteration$llm2.diagnostics) === null || _lastIteration$llm2 === void 0 ? void 0 : _lastIteration$llm2.some((diagnostic) => diagnostic.code === "send-after-run")
|
|
2382
2460
|
})
|
|
2383
2461
|
]);
|
|
2384
2462
|
}
|
|
2385
2463
|
if ((lastIteration === null || lastIteration === void 0 ? void 0 : lastIteration.status.type) === "exit_error") {
|
|
2386
|
-
var _lastIteration$
|
|
2464
|
+
var _lastIteration$llm3;
|
|
2387
2465
|
return withParts([
|
|
2388
2466
|
...lastIterationMessages,
|
|
2389
2467
|
{
|
|
2390
2468
|
role: "assistant",
|
|
2391
|
-
content: wrapContent(((_lastIteration$
|
|
2469
|
+
content: wrapContent(((_lastIteration$llm3 = lastIteration.llm) === null || _lastIteration$llm3 === void 0 ? void 0 : _lastIteration$llm3.output) ?? "", {
|
|
2392
2470
|
preserve: "top",
|
|
2393
2471
|
flex: 4,
|
|
2394
2472
|
minTokens: 25
|
|
2395
2473
|
})
|
|
2396
2474
|
},
|
|
2397
2475
|
await this.version.getInvalidCodeMessage({
|
|
2398
|
-
|
|
2399
|
-
|
|
2476
|
+
isChatEnabled: parameters.components.length > 0,
|
|
2477
|
+
code: lastIteration.next ? `■next=${lastIteration.next.name} ${JSON.stringify(lastIteration.next.props)}` : lastIteration.code ?? "// No code generated",
|
|
2478
|
+
message: `Invalid ■next block (${lastIteration.status.exit_error.exit}): ${lastIteration.status.exit_error.message}`,
|
|
2479
|
+
variables: lastIteration.variables,
|
|
2480
|
+
toolCalls: lastIteration.traces.filter((trace) => trace.type === "tool_call").map((trace) => ({
|
|
2481
|
+
tool: trace.tool_name,
|
|
2482
|
+
input: trace.input,
|
|
2483
|
+
success: trace.success,
|
|
2484
|
+
...trace.success ? { output: trace.output } : { error: getErrorMessage(trace.error) }
|
|
2485
|
+
}))
|
|
2400
2486
|
})
|
|
2401
2487
|
]);
|
|
2402
2488
|
}
|
|
2403
2489
|
if ((lastIteration === null || lastIteration === void 0 ? void 0 : lastIteration.status.type) === "invalid_code_error") {
|
|
2404
|
-
var _lastIteration$
|
|
2490
|
+
var _lastIteration$llm4;
|
|
2405
2491
|
return withParts([
|
|
2406
2492
|
...lastIterationMessages,
|
|
2407
2493
|
{
|
|
2408
2494
|
role: "assistant",
|
|
2409
|
-
content: wrapContent(((_lastIteration$
|
|
2495
|
+
content: wrapContent(((_lastIteration$llm4 = lastIteration.llm) === null || _lastIteration$llm4 === void 0 ? void 0 : _lastIteration$llm4.output) ?? "", {
|
|
2410
2496
|
preserve: "top",
|
|
2411
2497
|
flex: 4,
|
|
2412
2498
|
minTokens: 25
|
|
2413
2499
|
})
|
|
2414
2500
|
},
|
|
2415
2501
|
await this.version.getInvalidCodeMessage({
|
|
2502
|
+
isChatEnabled: parameters.components.length > 0,
|
|
2416
2503
|
code: lastIteration.code ?? "// No code generated",
|
|
2417
2504
|
message: lastIteration.status.invalid_code_error.message
|
|
2418
2505
|
})
|
|
2419
2506
|
]);
|
|
2420
2507
|
}
|
|
2421
2508
|
if ((lastIteration === null || lastIteration === void 0 ? void 0 : lastIteration.status.type) === "execution_error") {
|
|
2422
|
-
var _lastIteration$
|
|
2509
|
+
var _lastIteration$llm5;
|
|
2423
2510
|
return withParts([
|
|
2424
2511
|
...lastIterationMessages,
|
|
2425
2512
|
{
|
|
2426
2513
|
role: "assistant",
|
|
2427
|
-
content: wrapContent(((_lastIteration$
|
|
2514
|
+
content: wrapContent(((_lastIteration$llm5 = lastIteration.llm) === null || _lastIteration$llm5 === void 0 ? void 0 : _lastIteration$llm5.output) ?? "", {
|
|
2428
2515
|
preserve: "top",
|
|
2429
2516
|
flex: 4,
|
|
2430
2517
|
minTokens: 25
|
|
2431
2518
|
})
|
|
2432
2519
|
},
|
|
2433
2520
|
await this.version.getCodeExecutionErrorMessage({
|
|
2521
|
+
isChatEnabled: parameters.components.length > 0,
|
|
2522
|
+
variables: lastIteration.variables,
|
|
2523
|
+
toolCalls: lastIteration.traces.filter((trace) => trace.type === "tool_call").map((trace) => ({
|
|
2524
|
+
tool: trace.tool_name,
|
|
2525
|
+
input: trace.input,
|
|
2526
|
+
success: trace.success,
|
|
2527
|
+
...trace.success ? { output: trace.output } : { error: getErrorMessage(trace.error) }
|
|
2528
|
+
})),
|
|
2434
2529
|
message: lastIteration.status.execution_error.message,
|
|
2435
2530
|
stacktrace: lastIteration.status.execution_error.stack
|
|
2436
2531
|
})
|
|
@@ -2441,6 +2536,7 @@ var Context = class {
|
|
|
2441
2536
|
async _refreshIterationParameters() {
|
|
2442
2537
|
var _this$chat, _this$chat2;
|
|
2443
2538
|
const instructions = await getValue(this.instructions, this);
|
|
2539
|
+
const examples = await getValue(this.examples, this);
|
|
2444
2540
|
const transcript = new TranscriptArray(await getValue(((_this$chat = this.chat) === null || _this$chat === void 0 ? void 0 : _this$chat.transcript) ?? [], this));
|
|
2445
2541
|
const tools = Tool.withUniqueNames(await getValue(this.tools, this) ?? []);
|
|
2446
2542
|
const objects = await getValue(this.objects, this) ?? [];
|
|
@@ -2497,6 +2593,7 @@ var Context = class {
|
|
|
2497
2593
|
objects,
|
|
2498
2594
|
exits,
|
|
2499
2595
|
instructions,
|
|
2596
|
+
examples,
|
|
2500
2597
|
components,
|
|
2501
2598
|
model,
|
|
2502
2599
|
temperature,
|
|
@@ -2506,6 +2603,7 @@ var Context = class {
|
|
|
2506
2603
|
constructor(props) {
|
|
2507
2604
|
this.id = `llmz_${ulid()}`;
|
|
2508
2605
|
this.instructions = props.instructions;
|
|
2606
|
+
this.examples = props.examples;
|
|
2509
2607
|
this.objects = props.objects;
|
|
2510
2608
|
this.tools = props.tools;
|
|
2511
2609
|
this.exits = props.exits;
|