llmz 0.1.5 → 0.2.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.
Files changed (75) hide show
  1. package/README.md +185 -98
  2. package/dist/chat.d.ts +34 -0
  3. package/dist/{chunk-TIZWOIDF.js → chunk-33AB6SVX.js} +134 -76
  4. package/dist/{chunk-EFEF2AL7.js → chunk-DH35WO5G.js} +93 -556
  5. package/dist/chunk-E5NHK3FS.js +1637 -0
  6. package/dist/{chunk-L74UZONX.js → chunk-HM5H556L.js} +3 -1
  7. package/dist/chunk-I56MPOVG.cjs +62 -0
  8. package/dist/{chunk-C7T6OJB4.cjs → chunk-IKLFMVSW.cjs} +144 -86
  9. package/dist/chunk-KWQTYXAT.js +62 -0
  10. package/dist/{chunk-JXD2KJVB.cjs → chunk-WWZ2W4WR.cjs} +103 -566
  11. package/dist/chunk-YGKQEVQQ.cjs +1637 -0
  12. package/dist/{chunk-ZPHRTTQX.cjs → chunk-YQT5G77W.cjs} +3 -1
  13. package/dist/compiler/compiler.d.ts +7 -2
  14. package/dist/compiler/index.d.ts +1 -1
  15. package/dist/compiler/plugins/async-wrapper.d.ts +11 -0
  16. package/dist/component-2NYFY6CW.cjs +14 -0
  17. package/dist/{component-2Z3KLWLX.js → component-ASNZHQUR.js} +3 -7
  18. package/dist/component.d.ts +3 -10
  19. package/dist/context.d.ts +88 -2
  20. package/dist/{dual-modes-HEXPFVUE.js → dual-modes-RMF7V7ZQ.js} +2 -4
  21. package/dist/dual-modes-ZZY6QPYT.cjs +10 -0
  22. package/dist/{execute-22PSGL7P.cjs → execute-BXPFSEVX.cjs} +331 -87
  23. package/dist/{execute-ZENBZBWL.js → execute-HIRXXR6X.js} +321 -77
  24. package/dist/index.cjs +502 -27
  25. package/dist/index.d.ts +8 -5
  26. package/dist/index.js +491 -16
  27. package/dist/message-stream/index.d.ts +9 -0
  28. package/dist/message-stream/instructions.d.ts +22 -0
  29. package/dist/message-stream/normalizer.d.ts +21 -0
  30. package/dist/message-stream/parser.d.ts +81 -0
  31. package/dist/message-stream/registry.d.ts +14 -0
  32. package/dist/message-stream/replayable.d.ts +27 -0
  33. package/dist/message-stream/sanitize.d.ts +10 -0
  34. package/dist/message-stream/stream.d.ts +54 -0
  35. package/dist/message-stream/types.d.ts +96 -0
  36. package/dist/message-stream/validator.d.ts +23 -0
  37. package/dist/message-stream/validator.test.d.ts +1 -0
  38. package/dist/prompts/chat-mode/system.md.d.ts +1 -1
  39. package/dist/prompts/chat-mode/user.md.d.ts +1 -1
  40. package/dist/prompts/common.d.ts +5 -5
  41. package/dist/prompts/prompt.d.ts +43 -6
  42. package/dist/prompts/protocol.d.ts +18 -0
  43. package/dist/prompts/worker-mode/system.md.d.ts +1 -1
  44. package/dist/prompts/worker-mode/user.md.d.ts +1 -1
  45. package/dist/result.d.ts +31 -0
  46. package/dist/runtime/execute.test.d.ts +1 -0
  47. package/dist/runtime/generate.d.ts +24 -1
  48. package/dist/runtime/interpret-result.d.ts +10 -0
  49. package/dist/runtime/types.d.ts +29 -4
  50. package/dist/truncator-7PGEGCHV.cjs +12 -0
  51. package/dist/{truncator-3U2QUUJJ.js → truncator-OZOBNYON.js} +3 -1
  52. package/dist/truncator.d.ts +2 -0
  53. package/dist/types.d.ts +8 -1
  54. package/dist/vm/drivers/quickjs.d.ts +2 -0
  55. package/dist/vm/index.d.ts +7 -0
  56. package/dist/vm/instrument.d.ts +1 -1
  57. package/dist/{vm-PYCKS77H.js → vm-44H4UKI2.js} +5 -4
  58. package/dist/{vm-VHB67FVH.cjs → vm-A3OTQVIR.cjs} +4 -3
  59. package/package.json +5 -5
  60. package/dist/chunk-2O3UTPVH.js +0 -813
  61. package/dist/chunk-3T5IU7OU.js +0 -186
  62. package/dist/chunk-BBX2LDZE.cjs +0 -813
  63. package/dist/chunk-CQ3UJW76.cjs +0 -186
  64. package/dist/compiler/plugins/async-iterator.d.ts +0 -6
  65. package/dist/compiler/plugins/braces-tsx.d.ts +0 -3
  66. package/dist/compiler/plugins/html-to-markdown.d.ts +0 -21
  67. package/dist/compiler/plugins/jsx-preserve-newlines.d.ts +0 -5
  68. package/dist/compiler/plugins/jsx-undefined-vars.d.ts +0 -14
  69. package/dist/component-NNHBHD72.cjs +0 -18
  70. package/dist/dual-modes-LLIWZCHC.cjs +0 -12
  71. package/dist/truncator-3ZN7W6NB.cjs +0 -10
  72. /package/dist/{compiler/plugins/html-to-markdown.test.d.ts → message-stream/instructions.test.d.ts} +0 -0
  73. /package/dist/{compiler/plugins/jsx-undefined-vars.test.d.ts → message-stream/normalizer.test.d.ts} +0 -0
  74. /package/dist/{component.test.d.ts → message-stream/parser.test.d.ts} +0 -0
  75. /package/dist/{vm/vm-jsx.test.d.ts → message-stream/stream.test.d.ts} +0 -0
@@ -142,6 +142,7 @@ var _MessageContentParser = (_class = class {
142
142
  }, _class);
143
143
  var _createRegex = () => new RegExp(REGEXP, "g");
144
144
  var _renderRemainingWrappers = (content) => content.replace(_createRegex(), "$2");
145
+ var stripTruncationTags = (content) => _renderRemainingWrappers(content);
145
146
  var _countTotalTokens = (parts) => parts.reduce((acc, x) => acc + x.reduce((acc2, y) => acc2 + y.tokens, 0), 0);
146
147
  var _getTwoBiggestTruncables = (parts) => {
147
148
  var _a, _b;
@@ -168,4 +169,5 @@ var _getTwoBiggestTruncables = (parts) => {
168
169
 
169
170
 
170
171
 
171
- exports.wrapContent = wrapContent; exports.truncateWrappedContent = truncateWrappedContent;
172
+
173
+ exports.wrapContent = wrapContent; exports.truncateWrappedContent = truncateWrappedContent; exports.stripTruncationTags = stripTruncationTags;
@@ -2,8 +2,6 @@ import { type TransformOptions } from '@babel/core';
2
2
  import { ToolCallEntry } from './plugins/track-tool-calls.js';
3
3
  export declare const DEFAULT_TRANSFORM_OPTIONS: TransformOptions;
4
4
  export declare const Identifiers: {
5
- JSXFnIdentifier: string;
6
- AsyncIterYieldFnIdentifier: string;
7
5
  ConsoleObjIdentifier: string;
8
6
  LineTrackingFnIdentifier: string;
9
7
  VariableTrackingFnIdentifier: string;
@@ -12,6 +10,13 @@ export declare const Identifiers: {
12
10
  CommentFnIdentifier: string;
13
11
  };
14
12
  export type CompiledCode = ReturnType<typeof compile>;
13
+ /**
14
+ * Whether the code contains a top-level `return` statement (one that would
15
+ * return from the generated code itself, not from a nested function). Unlike a
16
+ * regex, this ignores `return` inside comments, strings and nested functions.
17
+ * Falls back to a word-boundary match if the code cannot be parsed.
18
+ */
19
+ export declare function hasTopLevelReturn(code: string): boolean;
15
20
  export declare function compile(code: string): {
16
21
  code: string;
17
22
  codeWithMarkers: string;
@@ -1,2 +1,2 @@
1
- export { Identifiers, compile } from './compiler.js';
1
+ export { Identifiers, compile, hasTopLevelReturn } from './compiler.js';
2
2
  export type { CompiledCode } from './compiler.js';
@@ -0,0 +1,11 @@
1
+ export declare const USER_CODE_START_MARKER = "/* __LLMZ_USER_CODE_START__ */";
2
+ export declare const USER_CODE_END_MARKER = "/* __LLMZ_USER_CODE_END__ */";
3
+ /**
4
+ * Wraps user code in an async function so top-level `await` and `return` parse,
5
+ * and so plugins can target the `__fn__` declaration. The wrapper is removed
6
+ * after transformation — drivers re-wrap the bare statements themselves.
7
+ */
8
+ export declare const AsyncWrapper: {
9
+ preProcessing: (code: string) => string;
10
+ postProcessing: (code: string) => string;
11
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunkI56MPOVGcjs = require('./chunk-I56MPOVG.cjs');
7
+ require('./chunk-5ZF6NTYI.cjs');
8
+ require('./chunk-HC2QZTVT.cjs');
9
+
10
+
11
+
12
+
13
+
14
+ exports.Component = _chunkI56MPOVGcjs.Component; exports.assertValidComponent = _chunkI56MPOVGcjs.assertValidComponent; exports.isAnyComponent = _chunkI56MPOVGcjs.isAnyComponent; exports.isComponent = _chunkI56MPOVGcjs.isComponent;
@@ -1,18 +1,14 @@
1
1
  import {
2
2
  Component,
3
3
  assertValidComponent,
4
- getComponentReference,
5
4
  isAnyComponent,
6
- isComponent,
7
- renderToTsx
8
- } from "./chunk-3T5IU7OU.js";
5
+ isComponent
6
+ } from "./chunk-KWQTYXAT.js";
9
7
  import "./chunk-XTEHT2TK.js";
10
8
  import "./chunk-34GJUS6U.js";
11
9
  export {
12
10
  Component,
13
11
  assertValidComponent,
14
- getComponentReference,
15
12
  isAnyComponent,
16
- isComponent,
17
- renderToTsx
13
+ isComponent
18
14
  };
@@ -10,13 +10,12 @@ export type ComponentChild = {
10
10
  component: ComponentDefinition;
11
11
  };
12
12
  export declare function assertValidComponent(component: ComponentDefinition): asserts component is ComponentDefinition;
13
- export declare function getComponentReference(component: ComponentDefinition): string;
14
13
  export type DefaultComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any>> = {
15
14
  type: 'default';
16
15
  name: string;
17
16
  aliases: string[];
18
17
  description: string;
19
- examples: ExampleUsage[];
18
+ examples?: ExampleUsage[];
20
19
  default: {
21
20
  props: T;
22
21
  children: Array<ComponentChild>;
@@ -27,7 +26,7 @@ export type LeafComponentDefinition<T extends z.ZodObject<any> = z.ZodObject<any
27
26
  name: string;
28
27
  description: string;
29
28
  aliases?: string[];
30
- examples: ExampleUsage[];
29
+ examples?: ExampleUsage[];
31
30
  leaf: {
32
31
  props: T;
33
32
  };
@@ -37,7 +36,7 @@ export type ContainerComponentDefinition<T extends z.ZodObject<any> = z.ZodObjec
37
36
  name: string;
38
37
  description: string;
39
38
  aliases?: string[];
40
- examples: ExampleUsage[];
39
+ examples?: ExampleUsage[];
41
40
  container: {
42
41
  props: T;
43
42
  children: Array<ComponentChild>;
@@ -54,10 +53,4 @@ export declare class Component<T extends ComponentDefinition = ComponentDefiniti
54
53
  }
55
54
  export declare function isComponent<T extends ComponentDefinition>(rendered: RenderedComponent<any>, component: Component<T>): rendered is RenderedComponent<ExtractComponentProps<T>>;
56
55
  export declare function isAnyComponent(message: unknown): message is RenderedComponent;
57
- /**
58
- * Converts a RenderedComponent back to TSX code
59
- * @param component The rendered component to convert
60
- * @returns A string containing the TSX representation of the component
61
- */
62
- export declare function renderToTsx(component: RenderedComponent): string;
63
56
  export {};
package/dist/context.d.ts CHANGED
@@ -7,11 +7,49 @@ import { Exit } from './exit.js';
7
7
  import { ValueOrGetter } from './getter.js';
8
8
  import { HookedArray } from './handlers.js';
9
9
  import { ObjectInstance } from './objects.js';
10
- import { LLMzPrompts, Prompt } from './prompts/prompt.js';
10
+ import { LLMzPrompts, ParsedNext, ParsedSend, Prompt } from './prompts/prompt.js';
11
11
  import { Snapshot } from './snapshots.js';
12
12
  import { Tool } from './tool.js';
13
13
  import { Transcript, TranscriptArray } from './transcript.js';
14
14
  import { ObjectMutation, Serializable, Trace } from './types.js';
15
+ /**
16
+ * Tokenizer-measured size of each part of the prompt, before truncation.
17
+ * Useful to understand what is eating up the context window.
18
+ */
19
+ export type ContextTokens = {
20
+ /** Total measured size of the prompt (sum of all the parts below). */
21
+ total: number;
22
+ /** Static prompt scaffolding: response format, VM rules, security guidelines, recap. */
23
+ framework: number;
24
+ /** The identity / instructions section. */
25
+ instructions: number;
26
+ /** tools.d.ts — tools, objects and variable typings. */
27
+ tools: number;
28
+ /** The conversation transcript. */
29
+ transcript: number;
30
+ /** The ■ protocol reference documenting components and exits. */
31
+ protocol: number;
32
+ /** Messages carried over from previous iterations (assistant responses, execution results, errors). */
33
+ iterations: number;
34
+ };
35
+ /** Token usage of a single iteration's LLM call. */
36
+ export type TokenUsage = {
37
+ /** Input tokens consumed, as reported by the LLM provider. Zero until the call completes. */
38
+ input: number;
39
+ /** Output tokens produced, as reported by the LLM provider. Zero until the call completes. */
40
+ output: number;
41
+ /** Total tokens (input + output). */
42
+ total: number;
43
+ /**
44
+ * The effective context window limit of this call, in tokens:
45
+ * `min(options.maxTokens, model's max input tokens)`. Use it to compute the
46
+ * percentage of context used (e.g. `context.total / limit`).
47
+ * Undefined until the LLM call starts.
48
+ */
49
+ limit?: number;
50
+ /** Measured context size by part of the prompt (pre-truncation). */
51
+ context: ContextTokens;
52
+ };
15
53
  export type IterationParameters = {
16
54
  transcript: TranscriptArray;
17
55
  tools: Tool[];
@@ -51,7 +89,8 @@ export declare namespace IterationStatuses {
51
89
  type: 'thinking_requested';
52
90
  thinking_requested: {
53
91
  reason?: string;
54
- variables: Record<string, unknown>;
92
+ /** The value returned by the executed code (or the context provided by a ThinkSignal). */
93
+ variables: unknown;
55
94
  metadata?: Record<string, unknown>;
56
95
  };
57
96
  };
@@ -327,7 +366,10 @@ export declare namespace Iteration {
327
366
  spend: number;
328
367
  output: string;
329
368
  model: string;
369
+ time_to_first_token?: number;
370
+ time_to_last_token?: number;
330
371
  };
372
+ tokens?: TokenUsage;
331
373
  transcript: Transcript.Message[];
332
374
  tools: Tool.JSON[];
333
375
  objects: ObjectInstance.JSON[];
@@ -342,8 +384,18 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
342
384
  id: string;
343
385
  messages: LLMzPrompts.Message[];
344
386
  code?: string;
387
+ /** Messages (`■send` blocks) parsed from the assistant response, in order. */
388
+ sends?: ParsedSend[];
389
+ /** The `■next` exit parsed from the assistant response, if any. */
390
+ next?: ParsedNext;
345
391
  traces: HookedArray<Trace>;
346
392
  variables: Record<string, any>;
393
+ /**
394
+ * Token usage of this iteration's LLM call. The `context` breakdown is measured
395
+ * when the prompt is assembled; `input`/`output` are filled in once the LLM call
396
+ * completes, from the provider-reported usage.
397
+ */
398
+ tokens?: TokenUsage;
347
399
  started_ts: number;
348
400
  ended_ts?: number;
349
401
  status: IterationStatus;
@@ -369,6 +421,10 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
369
421
  spend: number;
370
422
  output: string;
371
423
  model: string;
424
+ /** Milliseconds between the LLM call start and the first streamed token. Only set on streaming clients. */
425
+ time_to_first_token?: number;
426
+ /** Milliseconds between the LLM call start and the last streamed token. Only set on streaming clients. */
427
+ time_to_last_token?: number;
372
428
  usage: {
373
429
  inputCost: number;
374
430
  outputCost: number;
@@ -420,6 +476,10 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
420
476
  spend: number;
421
477
  output: string;
422
478
  model: string;
479
+ /** Milliseconds between the LLM call start and the first streamed token. Only set on streaming clients. */
480
+ time_to_first_token?: number;
481
+ /** Milliseconds between the LLM call start and the last streamed token. Only set on streaming clients. */
482
+ time_to_last_token?: number;
423
483
  usage: {
424
484
  inputCost: number;
425
485
  outputCost: number;
@@ -427,6 +487,7 @@ export declare class Iteration implements Serializable<Iteration.JSON> {
427
487
  outputTokens: number;
428
488
  };
429
489
  } | undefined;
490
+ tokens: TokenUsage | undefined;
430
491
  transcript: Transcript.Message[];
431
492
  tools: {
432
493
  name: string;
@@ -493,12 +554,30 @@ export declare class Context implements Serializable<Context.JSON> {
493
554
  version: Prompt;
494
555
  timeout: number;
495
556
  loop: number;
557
+ /**
558
+ * Optional cap on the model's context window. The effective limit is
559
+ * `min(maxTokens, model's max input tokens)`.
560
+ */
561
+ maxTokens?: number;
562
+ /**
563
+ * Maximum time to wait for the first streamed token, in milliseconds,
564
+ * before the cognitive service falls back to the next model/provider.
565
+ */
566
+ maxTimeToFirstToken?: number;
496
567
  metadata: Record<string, any>;
497
568
  snapshot?: Snapshot;
498
569
  iteration: number;
499
570
  iterations: Iteration[];
500
571
  nextIteration(): Promise<Iteration>;
501
572
  private _getIterationVariables;
573
+ /**
574
+ * Measures the token size of each part of the prompt (pre-truncation).
575
+ * The named parts come from the system prompt; everything else in the system
576
+ * message is `framework`. Non-system messages count towards `iterations`,
577
+ * except the very first user message of a fresh execution (task recap),
578
+ * which is prompt scaffolding.
579
+ */
580
+ private _measureContextTokens;
502
581
  private _getIterationMessages;
503
582
  private _refreshIterationParameters;
504
583
  constructor(props: {
@@ -514,6 +593,8 @@ export declare class Context implements Serializable<Context.JSON> {
514
593
  metadata?: Record<string, any>;
515
594
  snapshot?: Snapshot;
516
595
  timeout?: number;
596
+ maxTokens?: number;
597
+ maxTimeToFirstToken?: number;
517
598
  });
518
599
  toJSON(): {
519
600
  id: string;
@@ -539,6 +620,10 @@ export declare class Context implements Serializable<Context.JSON> {
539
620
  spend: number;
540
621
  output: string;
541
622
  model: string;
623
+ /** Milliseconds between the LLM call start and the first streamed token. Only set on streaming clients. */
624
+ time_to_first_token?: number;
625
+ /** Milliseconds between the LLM call start and the last streamed token. Only set on streaming clients. */
626
+ time_to_last_token?: number;
542
627
  usage: {
543
628
  inputCost: number;
544
629
  outputCost: number;
@@ -546,6 +631,7 @@ export declare class Context implements Serializable<Context.JSON> {
546
631
  outputTokens: number;
547
632
  };
548
633
  } | undefined;
634
+ tokens: TokenUsage | undefined;
549
635
  transcript: Transcript.Message[];
550
636
  tools: {
551
637
  name: string;
@@ -1,10 +1,8 @@
1
1
  import {
2
2
  DualModePrompt
3
- } from "./chunk-2O3UTPVH.js";
3
+ } from "./chunk-E5NHK3FS.js";
4
4
  import "./chunk-YEAWWJSJ.js";
5
- import "./chunk-3T5IU7OU.js";
6
- import "./chunk-XTEHT2TK.js";
7
- import "./chunk-L74UZONX.js";
5
+ import "./chunk-HM5H556L.js";
8
6
  import "./chunk-YX27XM67.js";
9
7
  import "./chunk-34GJUS6U.js";
10
8
  export {
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkYGKQEVQQcjs = require('./chunk-YGKQEVQQ.cjs');
4
+ require('./chunk-KIN7Y247.cjs');
5
+ require('./chunk-YQT5G77W.cjs');
6
+ require('./chunk-FPLSJF4S.cjs');
7
+ require('./chunk-HC2QZTVT.cjs');
8
+
9
+
10
+ exports.DualModePrompt = _chunkYGKQEVQQcjs.DualModePrompt;