llmz 0.1.4 → 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 +6 -6
  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
@@ -1,4 +1,6 @@
1
+ import type { MessageDelta } from '../chat.js';
1
2
  import { Context, Iteration } from '../context.js';
3
+ import type { ParsedSend } from '../prompts/prompt.js';
2
4
  import { RuntimeCognitive } from './types.js';
3
5
  type GenerateCodeProps = {
4
6
  iteration: Iteration;
@@ -6,6 +8,27 @@ type GenerateCodeProps = {
6
8
  cognitive: RuntimeCognitive;
7
9
  controller: AbortController;
8
10
  metadata?: Record<string, string>;
11
+ /**
12
+ * Called for each completed `■send` block. On streaming clients this fires
13
+ * while the model is still generating — messages are delivered progressively.
14
+ */
15
+ onSend?: (send: ParsedSend) => Promise<void>;
16
+ /**
17
+ * Called for each `■send` body chunk as it is parsed from the stream
18
+ * (streaming clients only). Best-effort: errors are ignored.
19
+ */
20
+ onSendDelta?: (delta: MessageDelta) => Promise<void> | void;
21
+ /**
22
+ * Called as soon as the model opens a `■run` block, while the code is still
23
+ * being generated (streaming clients only). Used to pre-warm the VM.
24
+ */
25
+ onRunStart?: () => void;
26
+ /**
27
+ * Called with the code of the first `■run` block the moment it is fully
28
+ * parsed — the rest of the response (e.g. `■next`) may still be streaming
29
+ * (streaming clients only). Used to start executing the code early.
30
+ */
31
+ onRunComplete?: (code: string) => void;
9
32
  };
10
- export declare const generateCode: ({ iteration, ctx, cognitive, controller, metadata }: GenerateCodeProps) => Promise<void>;
33
+ export declare const generateCode: ({ iteration, ctx, cognitive, controller, metadata, onSend, onSendDelta, onRunStart, onRunComplete, }: GenerateCodeProps) => Promise<void>;
11
34
  export {};
@@ -9,4 +9,14 @@ type InterpretVMResultProps = {
9
9
  onExit?: ExecutionHooks['onExit'];
10
10
  };
11
11
  export declare const interpretVMResult: ({ iteration, result, controller, startedAt, onExit, }: InterpretVMResultProps) => Promise<void>;
12
+ /**
13
+ * Applies the `■next=<exit>` block of the current iteration: validates the exit
14
+ * name and props against the available exits, runs the onExit hook, and ends
15
+ * the iteration with exit_success or exit_error.
16
+ */
17
+ export declare const applyNextExit: ({ iteration, controller, onExit, }: {
18
+ iteration: Iteration;
19
+ controller: AbortController;
20
+ onExit?: ExecutionHooks["onExit"];
21
+ }) => Promise<void>;
12
22
  export {};
@@ -1,4 +1,4 @@
1
- import { Cognitive, CognitiveBeta, type BotpressClientLike, Models } from '@botpress/cognitive';
1
+ import { Cognitive, CognitiveBeta, type BotpressClientLike, type CognitiveLike, Models } from '@botpress/cognitive';
2
2
  import { Chat } from '../chat.js';
3
3
  import { Context, Iteration } from '../context.js';
4
4
  import { _CustomModelClient } from '../custom-client.js';
@@ -17,10 +17,13 @@ export type ExecutionHooks = {
17
17
  *
18
18
  * This hook is called for each trace that is generated during the iteration.
19
19
  * It is useful for logging, debugging, or monitoring the execution of the iteration.
20
+ * The abort controller can be used to stop the execution when a trace reveals
21
+ * something that should halt it (e.g. a forbidden tool call).
20
22
  */
21
23
  onTrace?: (event: {
22
24
  trace: Trace;
23
25
  iteration: number;
26
+ controller: AbortController;
24
27
  }) => void;
25
28
  /**
26
29
  * BLOCKING HOOK
@@ -50,8 +53,9 @@ export type ExecutionHooks = {
50
53
  * It is useful for logging, sending notifications, or performing actions based on the exit.
51
54
  * It can also be used to throw an error and preventing the exit from being successful.
52
55
  * If this hook throws an error, the execution will keep iterating with the error as context.
56
+ * The abort controller can be used to stop the execution entirely instead of iterating.
53
57
  */
54
- onExit?: <T = unknown>(result: ExitResult<T>) => Promise<void> | void;
58
+ onExit?: <T = unknown>(result: ExitResult<T>, controller: AbortController) => Promise<void> | void;
55
59
  /**
56
60
  * BLOCKING HOOK
57
61
  * This hook will block the execution of the iteration until it resolves.
@@ -104,7 +108,21 @@ export type ExecutionHooks = {
104
108
  output?: any;
105
109
  } | void>;
106
110
  };
107
- type Options = Partial<Pick<Context, 'loop' | 'timeout'>>;
111
+ type Options = Partial<Pick<Context, 'loop' | 'timeout'>> & {
112
+ /**
113
+ * Optional cap on the model's context window, in tokens.
114
+ * The effective limit is `min(maxTokens, model's max input tokens)`.
115
+ * Useful to reduce cost and latency on models with very large context windows.
116
+ */
117
+ maxTokens?: number;
118
+ /**
119
+ * Maximum time to wait for the first streamed token, in milliseconds, before
120
+ * the cognitive service falls back to the next model/provider. Only applies
121
+ * to streaming clients (CognitiveBeta / Cognitive v2), and works best when
122
+ * `model` is an array of fallback models.
123
+ */
124
+ maxTimeToFirstToken?: number;
125
+ };
108
126
  export type ExecutionProps = {
109
127
  /**
110
128
  * If provided, the execution will be run in "Chat Mode".
@@ -211,5 +229,12 @@ export type ExecutionProps = {
211
229
  */
212
230
  metadata?: Record<string, string>;
213
231
  } & ExecutionHooks;
214
- export type RuntimeCognitive = Pick<Cognitive, 'getModelDetails' | 'generateContent'>;
232
+ export type RuntimeCognitive = Pick<Cognitive, 'getModelDetails' | 'generateContent'> & {
233
+ /**
234
+ * Streaming generation. Only available on clients backed by the Cognitive v2
235
+ * (beta) API — when present, the runtime streams the response and parses
236
+ * ■ blocks incrementally.
237
+ */
238
+ generateContentStream?: CognitiveLike['generateContentStream'];
239
+ };
215
240
  export {};
@@ -0,0 +1,12 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkYQT5G77Wcjs = require('./chunk-YQT5G77W.cjs');
6
+ require('./chunk-FPLSJF4S.cjs');
7
+ require('./chunk-HC2QZTVT.cjs');
8
+
9
+
10
+
11
+
12
+ exports.stripTruncationTags = _chunkYQT5G77Wcjs.stripTruncationTags; exports.truncateWrappedContent = _chunkYQT5G77Wcjs.truncateWrappedContent; exports.wrapContent = _chunkYQT5G77Wcjs.wrapContent;
@@ -1,10 +1,12 @@
1
1
  import {
2
+ stripTruncationTags,
2
3
  truncateWrappedContent,
3
4
  wrapContent
4
- } from "./chunk-L74UZONX.js";
5
+ } from "./chunk-HM5H556L.js";
5
6
  import "./chunk-YX27XM67.js";
6
7
  import "./chunk-34GJUS6U.js";
7
8
  export {
9
+ stripTruncationTags,
8
10
  truncateWrappedContent,
9
11
  wrapContent
10
12
  };
@@ -113,4 +113,6 @@ export declare function wrapContent(content: string, options?: Partial<TruncateO
113
113
  * ```
114
114
  */
115
115
  export declare function truncateWrappedContent<T extends MessageLike>({ messages, tokenLimit, throwOnFailure, }: Options<T>): T[];
116
+ /** Removes truncation wrapper tags from content, leaving the wrapped content intact. */
117
+ export declare const stripTruncationTags: (content: string) => string;
116
118
  export {};
package/dist/types.d.ts CHANGED
@@ -55,6 +55,13 @@ export declare namespace Traces {
55
55
  model: string;
56
56
  code: string;
57
57
  }>;
58
+ /**
59
+ * Emitted on streaming clients the moment the model starts writing a `■run`
60
+ * block — before the code is fully generated. Useful to show a
61
+ * "writing code..." indicator while waiting for `llm_call_success` (which
62
+ * carries the final code) and the subsequent execution.
63
+ */
64
+ type CodeGenerationStart = TraceTemplate<'code_generation_started', {}>;
58
65
  type AbortTrace = TraceTemplate<'abort_signal', {
59
66
  reason: string;
60
67
  }>;
@@ -70,7 +77,7 @@ export declare namespace Traces {
70
77
  started_at: number;
71
78
  ended_at?: number;
72
79
  } & Content;
73
- type Trace = Comment | Log | ToolCall | ToolSlow | PropertyMutation | YieldTrace | LLMCallStart | LLMCallSuccess | ThinkSignal | CodeExecution | CodeExecutionException | InvalidCodeExceptionTrace | AbortTrace;
80
+ type Trace = Comment | Log | ToolCall | ToolSlow | PropertyMutation | YieldTrace | LLMCallStart | LLMCallSuccess | CodeGenerationStart | ThinkSignal | CodeExecution | CodeExecutionException | InvalidCodeExceptionTrace | AbortTrace;
74
81
  }
75
82
  export type Trace = Traces.Trace;
76
83
  export type VMExecutionResult = {
@@ -1,5 +1,7 @@
1
+ import { type QuickJSWASMModule } from 'quickjs-emscripten-core';
1
2
  import type { VMExecutionResult } from '../../types.js';
2
3
  import type { DriverExecutionContext, VMDriver } from '../types.js';
4
+ export declare const loadQuickJSModule: () => Promise<QuickJSWASMModule>;
3
5
  export declare class QuickJSDriver implements VMDriver {
4
6
  execute(ctx: DriverExecutionContext): Promise<VMExecutionResult>;
5
7
  private _pumpEventLoop;
@@ -1,3 +1,10 @@
1
1
  import type { Trace, VMExecutionResult } from '../types.js';
2
2
  import type { VMContext } from './types.js';
3
+ /**
4
+ * Pre-warms the VM so the first execution doesn't pay the QuickJS WASM
5
+ * instantiation cost. Fire-and-forget: called as soon as the model starts
6
+ * writing a `■run` block, so the module loads while the code is still being
7
+ * generated. No-op when the QuickJS driver is disabled or already loaded.
8
+ */
9
+ export declare const warmupVM: () => void;
3
10
  export declare function runAsyncFunction(context: VMContext, code: string, traces?: Trace[], signal?: AbortSignal | null, timeout?: number): Promise<VMExecutionResult>;
@@ -3,7 +3,7 @@ import { type CompiledCode } from '../compiler/index.js';
3
3
  import { SnapshotSignal } from '../errors.js';
4
4
  import type { Trace } from '../types.js';
5
5
  import { VMContext } from './types.js';
6
- export declare const NO_TRACKING: readonly [string, string, string, string, string, string];
6
+ export declare const NO_TRACKING: readonly [string, string, string, string, string];
7
7
  export type InstrumentationState = {
8
8
  currentToolCall: SnapshotSignal['toolCall'] | undefined;
9
9
  };
@@ -1,10 +1,11 @@
1
1
  import {
2
- runAsyncFunction
3
- } from "./chunk-EFEF2AL7.js";
2
+ runAsyncFunction,
3
+ warmupVM
4
+ } from "./chunk-DH35WO5G.js";
4
5
  import "./chunk-WSVDMGMR.js";
5
6
  import "./chunk-YEAWWJSJ.js";
6
- import "./chunk-XTEHT2TK.js";
7
7
  import "./chunk-34GJUS6U.js";
8
8
  export {
9
- runAsyncFunction
9
+ runAsyncFunction,
10
+ warmupVM
10
11
  };
@@ -1,10 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkJXD2KJVBcjs = require('./chunk-JXD2KJVB.cjs');
3
+
4
+ var _chunkWWZ2W4WRcjs = require('./chunk-WWZ2W4WR.cjs');
4
5
  require('./chunk-PK72FAKD.cjs');
5
6
  require('./chunk-KIN7Y247.cjs');
6
- require('./chunk-5ZF6NTYI.cjs');
7
7
  require('./chunk-HC2QZTVT.cjs');
8
8
 
9
9
 
10
- exports.runAsyncFunction = _chunkJXD2KJVBcjs.runAsyncFunction;
10
+
11
+ exports.runAsyncFunction = _chunkWWZ2W4WRcjs.runAsyncFunction; exports.warmupVM = _chunkWWZ2W4WRcjs.warmupVM;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "llmz",
3
3
  "type": "module",
4
4
  "description": "LLMz - An LLM-native Typescript VM built on top of Zui",
5
- "version": "0.1.4",
5
+ "version": "0.2.0",
6
6
  "types": "./dist/index.d.ts",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
@@ -30,11 +30,8 @@
30
30
  "author": "",
31
31
  "license": "ISC",
32
32
  "dependencies": {
33
- "@babel/core": "^7.26.0",
34
33
  "@babel/generator": "^7.26.3",
35
34
  "@babel/parser": "^7.26.3",
36
- "@babel/plugin-transform-react-jsx": "^7.25.9",
37
- "@babel/preset-typescript": "^7.26.0",
38
35
  "@babel/standalone": "^7.26.4",
39
36
  "@babel/traverse": "^7.26.4",
40
37
  "@babel/types": "^7.26.3",
@@ -42,6 +39,8 @@
42
39
  "bytes": "^3.1.2",
43
40
  "exponential-backoff": "^3.1.1",
44
41
  "handlebars": "^4.7.8",
42
+ "json5": "^2.2.3",
43
+ "jsonrepair": "^3.10.0",
45
44
  "lodash-es": "^4.17.21",
46
45
  "lru-cache": "~11.0.2",
47
46
  "ms": "^2.1.3",
@@ -50,6 +49,7 @@
50
49
  "ulid": "^2.3.0"
51
50
  },
52
51
  "devDependencies": {
52
+ "@babel/core": "^7.26.0",
53
53
  "@botpress/cli": "workspace:*",
54
54
  "@microsoft/api-extractor": "^7.49.0",
55
55
  "@types/babel__core": "^7.20.5",
@@ -71,9 +71,9 @@
71
71
  "tsx": "^4.19.2"
72
72
  },
73
73
  "peerDependencies": {
74
- "@botpress/client": "1.48.0",
74
+ "@botpress/client": "1.49.0",
75
75
  "@botpress/cognitive": "0.6.2",
76
- "@bpinternal/thicktoken": "^2.0.0",
76
+ "@bpinternal/thicktoken": "^3.0.0",
77
77
  "@bpinternal/zui": "^2.3.1"
78
78
  },
79
79
  "dependenciesMeta": {