llmz 0.9.0 → 1.0.2

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 (238) hide show
  1. package/DOCS.md +232 -1794
  2. package/ERRORS.md +101 -0
  3. package/README.md +96 -582
  4. package/dist/chat/chat.d.ts +63 -0
  5. package/dist/chat/component.d.ts +31 -0
  6. package/dist/chat/component.default.d.ts +58 -0
  7. package/dist/chat/response.d.ts +15 -0
  8. package/dist/compiler/compiler.d.ts +2 -7
  9. package/dist/compiler/plugins/dynamic-code.d.ts +7 -0
  10. package/dist/compiler/plugins/replace-comment.d.ts +2 -3
  11. package/dist/compiler/plugins/return-async.d.ts +5 -4
  12. package/dist/compiler/plugins/termination.d.ts +8 -0
  13. package/dist/compiler/plugins/tool-resolution.d.ts +4 -0
  14. package/dist/compiler/plugins/variable-extraction.d.ts +2 -8
  15. package/dist/component-CMFoCHyu.cjs +649 -0
  16. package/dist/component-DncqP4fB.js +614 -0
  17. package/dist/context.d.ts +71 -378
  18. package/dist/custom-client-C-WXvLD9.js +1655 -0
  19. package/dist/custom-client-Cgt9_0r1.cjs +1732 -0
  20. package/dist/custom-client.d.ts +12 -2
  21. package/dist/errors/catalog.d.ts +294 -0
  22. package/dist/errors/hooks.d.ts +2 -0
  23. package/dist/errors-C6ppQUZX.cjs +893 -0
  24. package/dist/errors-Crk5P8jo.js +636 -0
  25. package/dist/errors.d.ts +24 -36
  26. package/dist/execute-CiYvPs5Q.js +2061 -0
  27. package/dist/execute-DTTfacsi.cjs +2062 -0
  28. package/dist/{exit-DUM96DN1.cjs → exit-BOtKWPuT.cjs} +38 -28
  29. package/dist/{exit-CDdxDBRT.js → exit-DMPwCSba.js} +37 -27
  30. package/dist/exit.d.ts +19 -16
  31. package/dist/index.cjs +177 -1237
  32. package/dist/index.d.ts +25 -28
  33. package/dist/index.js +137 -1213
  34. package/dist/index.workerd.js +8974 -11145
  35. package/dist/inspect.d.ts +18 -4
  36. package/dist/inspection.d.ts +40 -0
  37. package/dist/native-0bq5ATZM.cjs +212 -0
  38. package/dist/native-n_718Z-T.js +177 -0
  39. package/dist/objects.d.ts +2 -57
  40. package/dist/prompts/native.d.ts +2 -0
  41. package/dist/prompts/prompt.d.ts +10 -101
  42. package/dist/quickjs-variant-21IO97PF.cjs +1080 -0
  43. package/dist/quickjs-variant-CtuGagsb.js +985 -0
  44. package/dist/result.d.ts +30 -861
  45. package/dist/runtime/execute.d.ts +3 -2
  46. package/dist/runtime/execution-activity.d.ts +11 -0
  47. package/dist/runtime/execution-diagnostics.d.ts +11 -0
  48. package/dist/runtime/execution-report.d.ts +51 -0
  49. package/dist/runtime/fixtures/chat.d.ts +8 -0
  50. package/dist/runtime/fixtures/long-search.d.ts +1 -1
  51. package/dist/runtime/fixtures/native-client.d.ts +33 -0
  52. package/dist/runtime/fixtures/protocol-languages.d.ts +1 -1
  53. package/dist/runtime/forced-inspection.d.ts +13 -0
  54. package/dist/runtime/forced-inspection.test.d.ts +1 -0
  55. package/dist/runtime/generate.d.ts +23 -20
  56. package/dist/runtime/generate.test.d.ts +1 -0
  57. package/dist/runtime/hook-provenance.test.d.ts +1 -0
  58. package/dist/runtime/inspection-hook.test.d.ts +1 -0
  59. package/dist/runtime/inspection-values.d.ts +14 -0
  60. package/dist/runtime/inspection-values.test.d.ts +1 -0
  61. package/dist/runtime/interruption-control-flow.test.d.ts +1 -0
  62. package/dist/runtime/interruption-settings.test.d.ts +1 -0
  63. package/dist/runtime/javascript-api.d.ts +62 -0
  64. package/dist/runtime/javascript-api.test.d.ts +1 -0
  65. package/dist/runtime/native-review.test.d.ts +1 -0
  66. package/dist/runtime/native-tools.d.ts +18 -0
  67. package/dist/runtime/native-tools.test.d.ts +1 -0
  68. package/dist/runtime/object-memory.test.d.ts +1 -0
  69. package/dist/runtime/single-tool.test.d.ts +1 -0
  70. package/dist/runtime/think-signal.test.d.ts +1 -0
  71. package/dist/runtime/token-budget.d.ts +22 -0
  72. package/dist/runtime/token-budget.test.d.ts +1 -0
  73. package/dist/runtime/tool-wrapper.d.ts +6 -5
  74. package/dist/runtime/traces.test.d.ts +1 -0
  75. package/dist/runtime/truncation.test.d.ts +1 -0
  76. package/dist/runtime/types.d.ts +47 -31
  77. package/dist/runtime/variable-recovery.test.d.ts +1 -0
  78. package/dist/runtime/vm-context.d.ts +6 -1
  79. package/dist/runtime/worker-completion.test.d.ts +1 -0
  80. package/dist/runtime-names.d.ts +4 -0
  81. package/dist/schema-CXlnbb3n.cjs +68 -0
  82. package/dist/schema-GE4ISPCR.js +45 -0
  83. package/dist/schema.d.ts +10 -0
  84. package/dist/schema.test.d.ts +1 -0
  85. package/dist/session/compactor.d.ts +51 -0
  86. package/dist/session/compactor.test.d.ts +1 -0
  87. package/dist/session/history.d.ts +36 -0
  88. package/dist/session/history.test.d.ts +1 -0
  89. package/dist/session/json.d.ts +3 -0
  90. package/dist/session/json.test.d.ts +1 -0
  91. package/dist/session/memory-codec.d.ts +9 -0
  92. package/dist/session/memory-codec.test.d.ts +1 -0
  93. package/dist/session/memory-render.d.ts +15 -0
  94. package/dist/session/memory-render.test.d.ts +1 -0
  95. package/dist/session/memory.d.ts +112 -0
  96. package/dist/session/memory.test.d.ts +1 -0
  97. package/dist/session/messages.d.ts +19 -0
  98. package/dist/session/messages.test.d.ts +1 -0
  99. package/dist/session/serialization.d.ts +36 -0
  100. package/dist/session/serialization.test.d.ts +1 -0
  101. package/dist/session/session-memory.test.d.ts +1 -0
  102. package/dist/session/session.d.ts +121 -0
  103. package/dist/session/session.test.d.ts +1 -0
  104. package/dist/session/speaker.test.d.ts +1 -0
  105. package/dist/{transcript.d.ts → session/transcript.d.ts} +4 -8
  106. package/dist/session/transcript.test.d.ts +1 -0
  107. package/dist/{tool-Bv8N4IPj.js → tool-DstssiAs.js} +144 -92
  108. package/dist/{tool-Dy6AJpJH.cjs → tool-_wK9hQOb.cjs} +146 -94
  109. package/dist/tool.d.ts +25 -17
  110. package/dist/truncate-BEKbdo3t.js +79 -0
  111. package/dist/truncate-uomAMGPs.cjs +102 -0
  112. package/dist/truncate.d.ts +24 -0
  113. package/dist/truncate.test.d.ts +1 -0
  114. package/dist/types.d.ts +33 -9
  115. package/dist/{typings-3lsqCbkn.cjs → typings-BA_XxAcY.cjs} +38 -193
  116. package/dist/{typings-CrBa7Tyy.js → typings-BEVDvtuk.js} +38 -175
  117. package/dist/typings-formatter.d.ts +1 -1
  118. package/dist/typings.d.ts +3 -0
  119. package/dist/{uniq-BYQ7GWwb.js → uniq-DfUeSNaX.js} +2 -2
  120. package/dist/{uniq-G872RWmE.cjs → uniq-DiXgysNV.cjs} +6 -18
  121. package/dist/{_baseIteratee-P_firB7b.js → utils-BOFzb8Ok.js} +1134 -16
  122. package/dist/{_baseIteratee-CF4qP2a8.cjs → utils-CTlsXvdj.cjs} +1281 -84
  123. package/dist/vm/drivers/node.d.ts +1 -1
  124. package/dist/vm/drivers/quickjs.d.ts +1 -1
  125. package/dist/vm/errors.d.ts +4 -4
  126. package/dist/vm/index.d.ts +3 -4
  127. package/dist/vm/instrument.d.ts +14 -6
  128. package/dist/vm/member-proxy.d.ts +4 -0
  129. package/dist/vm/member-proxy.test.d.ts +1 -0
  130. package/dist/vm/memory.test.d.ts +1 -0
  131. package/dist/vm/return-semantics.test.d.ts +1 -0
  132. package/dist/vm/types.d.ts +20 -3
  133. package/dist/{vm-BLsHw1da.js → vm-C7SfutHn.js} +1187 -180
  134. package/dist/{vm-D6s1zF6M.cjs → vm-gmekHc0i.cjs} +1221 -207
  135. package/package.json +13 -6
  136. package/dist/_baseForOwn-BfWDTL8L.cjs +0 -53
  137. package/dist/_baseForOwn-CFhWe_W6.js +0 -48
  138. package/dist/_getPrototype-CG7Dxrrz.js +0 -6
  139. package/dist/_getPrototype-DQDlNVVM.cjs +0 -10
  140. package/dist/_overArg-C5Hy7oCi.cjs +0 -196
  141. package/dist/_overArg-CRYbj1NH.js +0 -155
  142. package/dist/chat.d.ts +0 -401
  143. package/dist/common-BlRFtdf2.js +0 -807
  144. package/dist/common-BnvrDnIT.cjs +0 -860
  145. package/dist/compiler/plugins/track-tool-calls.d.ts +0 -33
  146. package/dist/compiler-C-OI9sim.cjs +0 -547
  147. package/dist/compiler-CW1VjQsn.js +0 -473
  148. package/dist/component-C6Agl2ns.cjs +0 -73
  149. package/dist/component-DGG7d_Mz.js +0 -44
  150. package/dist/component.d.ts +0 -88
  151. package/dist/component.default.d.ts +0 -278
  152. package/dist/custom-client-ChuZ63zp.js +0 -2658
  153. package/dist/custom-client-DAsGRnYc.cjs +0 -2729
  154. package/dist/dual-modes-DDkoCp3R.js +0 -3006
  155. package/dist/dual-modes-DPXiuvNe.cjs +0 -3090
  156. package/dist/errors-C962uJdS.cjs +0 -220
  157. package/dist/errors-Cg1G0Awu.js +0 -161
  158. package/dist/example-format.d.ts +0 -8
  159. package/dist/example.d.ts +0 -45
  160. package/dist/execute-BWcdv9so.js +0 -1059
  161. package/dist/execute-DM2-7y86.cjs +0 -1060
  162. package/dist/exit-parser.d.ts +0 -39
  163. package/dist/handlers.d.ts +0 -10
  164. package/dist/hoist.d.ts +0 -2
  165. package/dist/isEmpty-BhJRCqIF.js +0 -52
  166. package/dist/isEmpty-LY533Wmh.cjs +0 -57
  167. package/dist/isPlainObject-CSxXVKCk.cjs +0 -56
  168. package/dist/isPlainObject-D39AzPO2.js +0 -51
  169. package/dist/jsx-CIgdGGVs.js +0 -52
  170. package/dist/jsx-owqxrquU.cjs +0 -75
  171. package/dist/jsx.d.ts +0 -11
  172. package/dist/message-stream/index.d.ts +0 -9
  173. package/dist/message-stream/instructions.d.ts +0 -30
  174. package/dist/message-stream/normalizer.d.ts +0 -21
  175. package/dist/message-stream/parser.d.ts +0 -89
  176. package/dist/message-stream/registry.d.ts +0 -14
  177. package/dist/message-stream/replayable.d.ts +0 -27
  178. package/dist/message-stream/response-parser.d.ts +0 -24
  179. package/dist/message-stream/sanitize.d.ts +0 -10
  180. package/dist/message-stream/stream.d.ts +0 -54
  181. package/dist/message-stream/types.d.ts +0 -97
  182. package/dist/message-stream/validator.d.ts +0 -23
  183. package/dist/prompts/chat-mode/protocol.d.ts +0 -2
  184. package/dist/prompts/chat-mode/system.d.ts +0 -2
  185. package/dist/prompts/chat-mode/system.md.d.ts +0 -2
  186. package/dist/prompts/chat-mode/user.d.ts +0 -2
  187. package/dist/prompts/chat-mode/user.md.d.ts +0 -2
  188. package/dist/prompts/code-examples.d.ts +0 -2
  189. package/dist/prompts/common.d.ts +0 -7
  190. package/dist/prompts/dual-modes.d.ts +0 -2
  191. package/dist/prompts/execution-history.d.ts +0 -6
  192. package/dist/prompts/execution-state.d.ts +0 -3
  193. package/dist/prompts/protocol-basics.d.ts +0 -5
  194. package/dist/prompts/protocol.d.ts +0 -31
  195. package/dist/prompts/worker-mode/protocol.d.ts +0 -2
  196. package/dist/prompts/worker-mode/system.d.ts +0 -2
  197. package/dist/prompts/worker-mode/system.md.d.ts +0 -2
  198. package/dist/prompts/worker-mode/user.d.ts +0 -2
  199. package/dist/prompts/worker-mode/user.md.d.ts +0 -2
  200. package/dist/quickjs-variant-BYhMBpwU.js +0 -45
  201. package/dist/quickjs-variant-CsIwTVFC.cjs +0 -56
  202. package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
  203. package/dist/runtime/fixtures/qwen-protocol-failures.d.ts +0 -29
  204. package/dist/runtime/interpret-result.d.ts +0 -22
  205. package/dist/snapshots.d.ts +0 -249
  206. package/dist/stack-traces-BIE_5Xwf.js +0 -21
  207. package/dist/stack-traces-ntw_qhoy.cjs +0 -26
  208. package/dist/truncator-CLkouTCO.cjs +0 -276
  209. package/dist/truncator-DZqEqnpD.js +0 -253
  210. package/dist/truncator.d.ts +0 -118
  211. package/dist/utils-3ESwP3yg.cjs +0 -1075
  212. package/dist/utils-UBeAFeEI.js +0 -950
  213. /package/dist/{citations.d.ts → chat/citations.d.ts} +0 -0
  214. /package/dist/{citations.test.d.ts → chat/citations.test.d.ts} +0 -0
  215. /package/dist/{component.default.test.d.ts → chat/component.default.test.d.ts} +0 -0
  216. /package/dist/{compiler/plugins/track-tool-calls.test.d.ts → chat/component.test.d.ts} +0 -0
  217. /package/dist/{example.test.d.ts → chat/response.test.d.ts} +0 -0
  218. /package/dist/{exit-parser.test.d.ts → compiler/plugins/dynamic-code.test.d.ts} +0 -0
  219. /package/dist/{handlers.test.d.ts → compiler/plugins/tool-resolution.test.d.ts} +0 -0
  220. /package/dist/{hoist.test.d.ts → errors/catalog.test.d.ts} +0 -0
  221. /package/dist/{message-stream/instructions.test.d.ts → exit.test.d.ts} +0 -0
  222. /package/dist/{message-stream/normalizer.test.d.ts → inspection.test.d.ts} +0 -0
  223. /package/dist/{message-stream/parser.test.d.ts → prompts/native.test.d.ts} +0 -0
  224. /package/dist/{message-stream/response-parser.test.d.ts → result.test.d.ts} +0 -0
  225. /package/dist/{message-stream/stream.test.d.ts → runtime/chat-completion.test.d.ts} +0 -0
  226. /package/dist/{message-stream/validator.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
  227. /package/dist/{prompts/adherence.test.d.ts → runtime/chat-last-speaker.test.d.ts} +0 -0
  228. /package/dist/{prompts/catalogue-examples.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
  229. /package/dist/{prompts/code-examples.test.d.ts → runtime/context-registration.test.d.ts} +0 -0
  230. /package/dist/{prompts/common.test.d.ts → runtime/empty-completion.test.d.ts} +0 -0
  231. /package/dist/{prompts/concrete-patterns.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
  232. /package/dist/{prompts/long-search.test.d.ts → runtime/errors.test.d.ts} +0 -0
  233. /package/dist/{prompts/protocol-simple.test.d.ts → runtime/execution-activity.test.d.ts} +0 -0
  234. /package/dist/{prompts/protocol.test.d.ts → runtime/execution-diagnostics.test.d.ts} +0 -0
  235. /package/dist/{prompts/sections.test.d.ts → runtime/execution-report.test.d.ts} +0 -0
  236. /package/dist/runtime/{interpret-result.test.d.ts → execution-safety.test.d.ts} +0 -0
  237. /package/dist/{transcript.test.d.ts → runtime/exit-control-flow.test.d.ts} +0 -0
  238. /package/dist/{truncator.test.d.ts → runtime/fixtures/long-search.test.d.ts} +0 -0
@@ -0,0 +1,68 @@
1
+ const require_errors = require("./errors-C6ppQUZX.cjs");
2
+ let _bpinternal_zui = require("@bpinternal/zui");
3
+ //#region src/schema.ts
4
+ const INPUT_SCHEMA_OPTIONS = {
5
+ target: "openApi3",
6
+ effectStrategy: "input",
7
+ pipeStrategy: "input"
8
+ };
9
+ /** Describe values supplied to a schema; JavaScript effects remain in the original validator. */
10
+ function toModelSchema(schema) {
11
+ try {
12
+ return _bpinternal_zui.transforms.toJSONSchema(schema);
13
+ } catch {
14
+ try {
15
+ return _bpinternal_zui.transforms.toJSONSchemaLegacy(schema, INPUT_SCHEMA_OPTIONS);
16
+ } catch (cause) {
17
+ throw new require_errors.InvalidConfigurationError(`Cannot describe schema input: ${String(cause)}`, { cause });
18
+ }
19
+ }
20
+ }
21
+ /** Async tool inputs still run their validator exactly once, including before retries. */
22
+ async function parseSchemaAsync(schema, value, subject) {
23
+ try {
24
+ return await schema.safeParseAsync(value);
25
+ } catch (cause) {
26
+ if (require_errors.isLLMzError(cause)) throw cause;
27
+ throw new require_errors.InvalidConfigurationError(`${subject} schema evaluation failed: ${String(cause)}`, { cause });
28
+ }
29
+ }
30
+ /** Exit, component and property APIs are synchronous. Tool inputs use safeParseAsync instead. */
31
+ function parseSchemaSync(schema, value, subject) {
32
+ try {
33
+ return schema.safeParse(value);
34
+ } catch (cause) {
35
+ if (require_errors.isLLMzError(cause)) throw cause;
36
+ throw new require_errors.InvalidConfigurationError(`${subject} schema could not be evaluated synchronously. Use synchronous transforms and refinements here; put asynchronous validation in a tool input schema. ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
37
+ }
38
+ }
39
+ /** Unwrap root effects without executing them or losing the original schema. */
40
+ function schemaInput(schema) {
41
+ if (_bpinternal_zui.z.is.zuiEffects(schema)) return schemaInput(schema.innerType());
42
+ return _bpinternal_zui.z.is.zuiPipeline(schema) ? schemaInput(schema._def.in) : schema;
43
+ }
44
+ //#endregion
45
+ Object.defineProperty(exports, "parseSchemaAsync", {
46
+ enumerable: true,
47
+ get: function() {
48
+ return parseSchemaAsync;
49
+ }
50
+ });
51
+ Object.defineProperty(exports, "parseSchemaSync", {
52
+ enumerable: true,
53
+ get: function() {
54
+ return parseSchemaSync;
55
+ }
56
+ });
57
+ Object.defineProperty(exports, "schemaInput", {
58
+ enumerable: true,
59
+ get: function() {
60
+ return schemaInput;
61
+ }
62
+ });
63
+ Object.defineProperty(exports, "toModelSchema", {
64
+ enumerable: true,
65
+ get: function() {
66
+ return toModelSchema;
67
+ }
68
+ });
@@ -0,0 +1,45 @@
1
+ import { U as isLLMzError, b as InvalidConfigurationError } from "./errors-Crk5P8jo.js";
2
+ import { transforms, z } from "@bpinternal/zui";
3
+ //#region src/schema.ts
4
+ const INPUT_SCHEMA_OPTIONS = {
5
+ target: "openApi3",
6
+ effectStrategy: "input",
7
+ pipeStrategy: "input"
8
+ };
9
+ /** Describe values supplied to a schema; JavaScript effects remain in the original validator. */
10
+ function toModelSchema(schema) {
11
+ try {
12
+ return transforms.toJSONSchema(schema);
13
+ } catch {
14
+ try {
15
+ return transforms.toJSONSchemaLegacy(schema, INPUT_SCHEMA_OPTIONS);
16
+ } catch (cause) {
17
+ throw new InvalidConfigurationError(`Cannot describe schema input: ${String(cause)}`, { cause });
18
+ }
19
+ }
20
+ }
21
+ /** Async tool inputs still run their validator exactly once, including before retries. */
22
+ async function parseSchemaAsync(schema, value, subject) {
23
+ try {
24
+ return await schema.safeParseAsync(value);
25
+ } catch (cause) {
26
+ if (isLLMzError(cause)) throw cause;
27
+ throw new InvalidConfigurationError(`${subject} schema evaluation failed: ${String(cause)}`, { cause });
28
+ }
29
+ }
30
+ /** Exit, component and property APIs are synchronous. Tool inputs use safeParseAsync instead. */
31
+ function parseSchemaSync(schema, value, subject) {
32
+ try {
33
+ return schema.safeParse(value);
34
+ } catch (cause) {
35
+ if (isLLMzError(cause)) throw cause;
36
+ throw new InvalidConfigurationError(`${subject} schema could not be evaluated synchronously. Use synchronous transforms and refinements here; put asynchronous validation in a tool input schema. ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
37
+ }
38
+ }
39
+ /** Unwrap root effects without executing them or losing the original schema. */
40
+ function schemaInput(schema) {
41
+ if (z.is.zuiEffects(schema)) return schemaInput(schema.innerType());
42
+ return z.is.zuiPipeline(schema) ? schemaInput(schema._def.in) : schema;
43
+ }
44
+ //#endregion
45
+ export { toModelSchema as i, parseSchemaSync as n, schemaInput as r, parseSchemaAsync as t };
@@ -0,0 +1,10 @@
1
+ import { z } from '@bpinternal/zui';
2
+ import type { JSONSchema7 } from 'json-schema';
3
+ /** Describe values supplied to a schema; JavaScript effects remain in the original validator. */
4
+ export declare function toModelSchema(schema: z.ZodType): JSONSchema7;
5
+ /** Async tool inputs still run their validator exactly once, including before retries. */
6
+ export declare function parseSchemaAsync<T extends z.ZodType>(schema: T, value: unknown, subject: string): Promise<z.SafeParseReturnType<T["_input"], T["_output"]>>;
7
+ /** Exit, component and property APIs are synchronous. Tool inputs use safeParseAsync instead. */
8
+ export declare function parseSchemaSync<T extends z.ZodType>(schema: T, value: unknown, subject: string): z.SafeParseReturnType<T["_input"], T["_output"]>;
9
+ /** Unwrap root effects without executing them or losing the original schema. */
10
+ export declare function schemaInput(schema: z.ZodType): z.ZodType;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ import { type BotpressClientLike, type Models } from '@botpress/cognitive';
2
+ import type { RuntimeCognitive } from '../runtime/types.js';
3
+ import type { SessionMessage } from './messages.js';
4
+ import type { Session, SessionCompaction } from './session.js';
5
+ import type { Transcript } from './transcript.js';
6
+ export type SummaryRequest = {
7
+ /** A detached copy of the history being replaced; queued input is excluded. */
8
+ messages: readonly SessionMessage[];
9
+ maxTokens: number;
10
+ signal?: AbortSignal;
11
+ };
12
+ export type CompactionOptions = {
13
+ /** Start automatic compaction at this fraction of the input budget. Default: 0.85. */
14
+ triggerRatio?: number;
15
+ /** Aim for this fraction after compaction. Default: 0.65. */
16
+ targetRatio?: number;
17
+ /** Prefer to keep this many recent iterations; a hard overflow may require fewer. Default: 2. */
18
+ keepRecentIterations?: number;
19
+ /** Maximum summary length, reduced further when the request has less space. Default: 1024. */
20
+ maxSummaryTokens?: number;
21
+ /** Defaults to the execution model, or 'fast' for standalone summarization. */
22
+ model?: Models | Models[];
23
+ /** Replace the built-in LLM summarizer. Invalid or oversized output never replaces history. */
24
+ summarize?: (request: SummaryRequest) => Promise<string>;
25
+ };
26
+ export type SummarizeOptions = {
27
+ client: RuntimeCognitive | BotpressClientLike;
28
+ model?: Models | Models[];
29
+ maxTokens?: number;
30
+ /** Optional cap on the summarizer's context window, including its output reserve. */
31
+ contextWindow?: number;
32
+ signal?: AbortSignal;
33
+ /** Metadata attached to the summarizer's Cognitive usage records. */
34
+ metadata?: Record<string, string>;
35
+ };
36
+ export declare function resolveCompaction(options?: CompactionOptions): Readonly<{
37
+ triggerRatio: number;
38
+ targetRatio: number;
39
+ keepRecentIterations: number;
40
+ maxSummaryTokens: number;
41
+ model: Models[] | Models | undefined;
42
+ summarize: ((request: SummaryRequest) => Promise<string>) | undefined;
43
+ }>;
44
+ /** Select whole settled iterations, then summarize only after proving the mandatory input can fit. */
45
+ export declare function prepareAutoCompaction(session: Session, options: SummarizeOptions & {
46
+ iterationId: string;
47
+ inputLimit: number;
48
+ measure(retainedIds: readonly string[], summary?: Transcript.SummaryMessage): number;
49
+ }): Promise<SessionCompaction | undefined>;
50
+ /** Summarize in bounded segments, including when the source history exceeds the model window. */
51
+ export declare function summarizeMessages(messages: readonly SessionMessage[], options: SummarizeOptions, custom?: CompactionOptions['summarize']): Promise<Transcript.SummaryMessage>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { CognitiveMessage } from '@botpress/cognitive';
2
+ import type { MemoryValue } from './memory-codec.js';
3
+ import { type SessionMessage } from './messages.js';
4
+ import type { Transcript } from './transcript.js';
5
+ export type SessionIteration = {
6
+ id: string;
7
+ number: number;
8
+ turn: number;
9
+ turnId: string;
10
+ timestamp: number;
11
+ };
12
+ export type SessionIterationRecord = SessionIteration & {
13
+ outcome: string;
14
+ error?: string;
15
+ } & ({
16
+ hasResult: true;
17
+ result: MemoryValue;
18
+ unavailable?: never;
19
+ } | {
20
+ hasResult: false;
21
+ result?: never;
22
+ unavailable?: string;
23
+ });
24
+ export type HistoryGroup = {
25
+ id: string;
26
+ turn: number;
27
+ iteration?: SessionIterationRecord;
28
+ messages: SessionMessage[];
29
+ /** Preserve typed external events and compaction summaries alongside native model input. */
30
+ source?: Transcript.EventMessage | Transcript.SummaryMessage;
31
+ };
32
+ export declare function pendingCallIds(group: HistoryGroup): string[];
33
+ export declare function validateBatch(message: CognitiveMessage): void;
34
+ export declare function validateGroup(group: HistoryGroup): void;
35
+ /** Select whole iterations and the inputs belonging to their turns. */
36
+ export declare function compactHistory(groups: readonly HistoryGroup[], retained: ReadonlySet<string>, currentTurn: number, pendingId?: string): HistoryGroup[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare function stableJSON(value: unknown): string;
2
+ /** Native provider payloads must survive the advertised JSON persistence API. */
3
+ export declare function assertPersistableData(data: unknown): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ /** Exact, bounded session data. Model-facing previews are never used as stored values. */
2
+ export type MemoryValue = null | undefined | boolean | number | string | MemoryValue[] | {
3
+ [key: string]: MemoryValue;
4
+ };
5
+ export type EncodedMemoryValue = ['negative-zero'] | ['undefined'] | ['value', null | boolean | number | string] | ['array', EncodedMemoryValue[]] | ['object', [string, EncodedMemoryValue][]];
6
+ export declare function encodeMemoryValue(value: unknown, seen?: Set<object>): EncodedMemoryValue;
7
+ export declare function decodeMemoryValue(value: EncodedMemoryValue): MemoryValue;
8
+ export declare const cloneMemoryValue: (value: unknown) => MemoryValue;
9
+ export declare function freezeMemoryValue<T>(value: T): T;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { type Inspector } from '../inspection.js';
2
+ import type { MemoryValue, NamedMemoryBinding, ObjectPropertyMemory } from './memory.js';
3
+ import type { SessionIterationRecord } from './session.js';
4
+ export declare function memoryValueType(value: MemoryValue): string;
5
+ export declare function previewMemoryValue(value: MemoryValue): string;
6
+ export declare function renderMemory(options: {
7
+ bindings: readonly NamedMemoryBinding[];
8
+ properties: readonly ObjectPropertyMemory[];
9
+ iterations?: readonly SessionIterationRecord[];
10
+ latestResultId?: string;
11
+ turn: number;
12
+ now?: number;
13
+ maxChars?: number;
14
+ inspector?: Inspector;
15
+ }): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,112 @@
1
+ import type { JSONSchema7Definition } from 'json-schema';
2
+ import type { Inspector } from '../inspection.js';
3
+ import type { ObjectInstance } from '../objects.js';
4
+ import type { ObjectMutation } from '../types.js';
5
+ import { type EncodedMemoryValue, type MemoryValue } from './memory-codec.js';
6
+ export { MemoryCapacityError } from '../errors.js';
7
+ export { cloneMemoryValue, decodeMemoryValue, type MemoryValue } from './memory-codec.js';
8
+ export { previewMemoryValue } from './memory-render.js';
9
+ export type VariableWrite = {
10
+ name: string;
11
+ timestamp: number;
12
+ kind?: 'assignment' | 'mutation';
13
+ };
14
+ export type MemoryProvenance = {
15
+ timestamp?: number;
16
+ turn?: number;
17
+ turnId?: string;
18
+ id?: string;
19
+ number?: number;
20
+ };
21
+ export type MemoryChange = {
22
+ name: string;
23
+ type: string;
24
+ preview: string;
25
+ provenance: MemoryProvenance;
26
+ };
27
+ export type ObjectPropertyMemory = {
28
+ hostValue?: MemoryValue;
29
+ object: string;
30
+ property: string;
31
+ value: MemoryValue;
32
+ type: string;
33
+ schema?: JSONSchema7Definition;
34
+ writable: boolean;
35
+ description?: string;
36
+ provenance: MemoryProvenance;
37
+ };
38
+ export type MemoryBinding = {
39
+ value: MemoryValue;
40
+ created: MemoryProvenance;
41
+ assigned: MemoryProvenance;
42
+ updated?: MemoryProvenance;
43
+ };
44
+ export type NamedMemoryBinding = MemoryBinding & {
45
+ name: string;
46
+ };
47
+ export type SerializedMemory = {
48
+ version: 2;
49
+ maxBytes: number;
50
+ variables: {
51
+ name: string;
52
+ value: EncodedMemoryValue;
53
+ created: MemoryProvenance;
54
+ assigned: MemoryProvenance;
55
+ updated?: MemoryProvenance;
56
+ }[];
57
+ objects?: (Omit<ObjectPropertyMemory, 'value' | 'hostValue'> & {
58
+ value: EncodedMemoryValue;
59
+ hostValue?: EncodedMemoryValue;
60
+ })[];
61
+ };
62
+ export type MemoryAssignment = MemoryProvenance & {
63
+ variableWrites?: VariableWrite[];
64
+ captureErrors?: {
65
+ name: string;
66
+ reason: string;
67
+ }[];
68
+ };
69
+ export type MemoryReport = {
70
+ created: MemoryChange[];
71
+ updated: MemoryChange[];
72
+ unavailable: {
73
+ name: string;
74
+ reason: string;
75
+ }[];
76
+ resultAvailable: boolean;
77
+ };
78
+ export declare class Memory {
79
+ private _bindings;
80
+ private _objectProperties;
81
+ private _activeObjects;
82
+ private readonly _additionalBytes;
83
+ readonly maxBytes: number;
84
+ constructor(options?: {
85
+ variables?: Record<string, unknown>;
86
+ maxBytes?: number;
87
+ /** Bytes retained by the owning Session, outside named/object memory. */
88
+ additionalBytes?: () => number;
89
+ });
90
+ private _assertName;
91
+ /** Object values remain authoritative in the host; this inventory never injects mutable duplicates. */
92
+ syncObjects(objects: readonly Pick<ObjectInstance, 'name' | 'properties'>[], observation?: MemoryProvenance): Promise<void>;
93
+ getObjectPropertyValue(object: string, property: string): MemoryValue;
94
+ /** Reject collisions before executing code, even if the conflicting declaration would run later. */
95
+ assertNamesAvailable(names: Iterable<string>): void;
96
+ recordObjectMutations(mutations: readonly ObjectMutation[], provenance: MemoryProvenance): MemoryChange[];
97
+ get variables(): Record<string, MemoryValue>;
98
+ get bindings(): readonly NamedMemoryBinding[];
99
+ get objectProperties(): readonly ObjectPropertyMemory[];
100
+ assign(variables: Record<string, unknown>, metadata: MemoryAssignment): MemoryReport;
101
+ render(options: {
102
+ turn: number;
103
+ now?: number;
104
+ maxChars?: number;
105
+ inspector?: Inspector;
106
+ }): string;
107
+ serialize(): SerializedMemory;
108
+ toJSON(): SerializedMemory;
109
+ static fromJSON(state: SerializedMemory): Memory;
110
+ static restore(state: SerializedMemory, additionalBytes?: () => number): Memory;
111
+ assertCapacity(additionalBytes?: number): void;
112
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { CognitiveMessage, CognitiveToolCall } from '@botpress/cognitive';
2
+ import { type Transcript } from './transcript.js';
3
+ /** A native message plus opaque adapter fields, preserved without interpreting them. */
4
+ export type SessionMessage = CognitiveMessage & Record<string, unknown>;
5
+ export type SessionInput = CognitiveMessage | Transcript.Message;
6
+ export type AssistantResponse = {
7
+ output: string;
8
+ toolCalls?: CognitiveToolCall[];
9
+ assistantMessage?: CognitiveMessage;
10
+ continuation?: unknown;
11
+ };
12
+ export declare function normalizeInput(message: SessionInput): SessionMessage;
13
+ /** Only actual participant content counts as speech, including image/audio-only messages. */
14
+ export declare function inputSpeaker(message: SessionMessage): 'user' | 'assistant' | null;
15
+ export declare function createAssistantMessage(response: AssistantResponse): SessionMessage;
16
+ export declare function validateInputMessage(message: CognitiveMessage): void;
17
+ export declare function validateMessageContent(message: CognitiveMessage): void;
18
+ /** Add runtime context to an isolated request, leaving canonical history untouched. */
19
+ export declare function withMemoryOverview(history: readonly SessionMessage[], overview?: string): SessionMessage[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { CompactionOptions } from './compactor.js';
2
+ import { type HistoryGroup, type SessionIterationRecord } from './history.js';
3
+ import { type EncodedMemoryValue } from './memory-codec.js';
4
+ import type { SerializedMemory } from './memory.js';
5
+ import { type SessionMessage } from './messages.js';
6
+ type SerializedHistoryGroup = Omit<HistoryGroup, 'iteration'> & {
7
+ iteration?: Omit<SessionIterationRecord, 'result'> & {
8
+ result?: EncodedMemoryValue;
9
+ };
10
+ };
11
+ export type PendingInput = {
12
+ id: string;
13
+ message: SessionMessage;
14
+ source?: HistoryGroup['source'];
15
+ };
16
+ export type SessionState = {
17
+ version: 3;
18
+ id: string;
19
+ turn: number;
20
+ turnId: string;
21
+ iteration: number;
22
+ groups: SerializedHistoryGroup[];
23
+ memory: SerializedMemory;
24
+ pendingInputs: PendingInput[];
25
+ activeTurn: boolean;
26
+ /** Acknowledged conversation speaker, independent of retained/compacted history. Absent in older snapshots. */
27
+ lastSpeaker?: 'user' | 'assistant' | null;
28
+ latestResultId?: string;
29
+ compaction?: false | Omit<CompactionOptions, 'summarize'>;
30
+ };
31
+ /** Persisted counters, native identities, and exact values must describe one history. */
32
+ export declare function validateRestoredHistory(state: SessionState): void;
33
+ export declare function serializeGroup(group: HistoryGroup): SerializedHistoryGroup;
34
+ export declare function restoreGroup(group: SerializedHistoryGroup): HistoryGroup;
35
+ export declare function resultBytes(records: readonly SessionIterationRecord[]): number;
36
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,121 @@
1
+ import type { Inspector } from '../inspection.js';
2
+ import { resolveCompaction, type CompactionOptions, type SummarizeOptions } from './compactor.js';
3
+ import { type SessionIteration, type SessionIterationRecord } from './history.js';
4
+ import { type MemoryValue } from './memory-codec.js';
5
+ import { Memory, type MemoryAssignment, type MemoryReport } from './memory.js';
6
+ import { type AssistantResponse, type SessionInput, type SessionMessage } from './messages.js';
7
+ import { type SessionState } from './serialization.js';
8
+ import type { Transcript } from './transcript.js';
9
+ export type { SessionIteration, SessionIterationRecord } from './history.js';
10
+ export type { SessionInput, SessionMessage } from './messages.js';
11
+ export type IterationCapture = MemoryAssignment & {
12
+ id: string;
13
+ variables?: Record<string, unknown>;
14
+ hasResult?: boolean;
15
+ result?: unknown;
16
+ };
17
+ export declare namespace Session {
18
+ type JSON = SessionState;
19
+ }
20
+ export type SessionOptions = {
21
+ variables?: Record<string, unknown>;
22
+ maxBytes?: number;
23
+ /** Automatic LLM summarization is enabled by default. Set false to preserve history and fail on overflow. */
24
+ compaction?: false | CompactionOptions;
25
+ };
26
+ export type SessionCompaction = {
27
+ summary: Transcript.SummaryMessage;
28
+ retainedIterationIds: readonly string[];
29
+ /** Commit only after the final request and all request hooks pass their budget checks. */
30
+ commit(): void;
31
+ };
32
+ /**
33
+ * Owns canonical native conversation history and its exact JavaScript memory.
34
+ * Reuse a Session across execute() calls; persist toJSON(), not prompt previews.
35
+ */
36
+ export declare class Session {
37
+ #private;
38
+ readonly id: string;
39
+ readonly memory: Memory;
40
+ readonly compaction: false | ReturnType<typeof resolveCompaction>;
41
+ constructor(options?: SessionOptions);
42
+ get turn(): number;
43
+ get turnId(): string;
44
+ get iteration(): number;
45
+ get messages(): SessionMessage[];
46
+ /** Retained conversation plus queued input, preserving event and summary roles. Returns a detached copy. */
47
+ get transcript(): SessionInput[];
48
+ /** Last participant who spoke in the active history. Events and queued inputs do not count. */
49
+ get lastSpeaker(): 'user' | 'assistant' | null;
50
+ /** Record acknowledged text or component delivery, never generation alone. */
51
+ recordAssistantDelivery(iterationId: string): void;
52
+ get pendingMessages(): SessionMessage[];
53
+ get hasActiveTurn(): boolean;
54
+ get status(): 'idle' | 'pending' | 'active';
55
+ get retainedIterationIds(): string[];
56
+ get pendingCalls(): Array<{
57
+ iterationId: string;
58
+ callId: string;
59
+ }>;
60
+ /** Exact retained execution results, newest first. Each access returns a frozen copy. */
61
+ get iterations(): readonly SessionIterationRecord[];
62
+ getBindings(): Record<string, MemoryValue>;
63
+ renderMemory(options?: {
64
+ now?: number;
65
+ maxChars?: number;
66
+ inspector?: Inspector;
67
+ }): string;
68
+ /** Prevent concurrent execute() calls from changing a shared session. */
69
+ acquire(): () => void;
70
+ /**
71
+ * Queue new input for the next turn. Appending during an execution never
72
+ * changes the batch currently being processed. Identical messages stay distinct.
73
+ */
74
+ append(input: SessionInput | readonly SessionInput[]): void;
75
+ /** Claim queued input, or continue the current turn after a failed execution. */
76
+ beginTurn(): void;
77
+ /** Mark the active input batch complete without consuming newly queued input. */
78
+ completeTurn(): void;
79
+ nextIteration(id?: string): SessionIteration;
80
+ appendAssistant(iterationId: string, response: AssistantResponse): void;
81
+ appendToolResult(iterationId: string, callId: string, content: string): void;
82
+ /** Capture successful writes and the inspection result even when later delivery fails. */
83
+ commitIteration(input: IterationCapture): MemoryReport;
84
+ /** Set the outcome once, after generation, code and delivery have all finished. */
85
+ settleIteration(iterationId: string, outcome?: {
86
+ outcome: string;
87
+ error?: string;
88
+ }): void;
89
+ /** Reserve failure metadata before model generation or side effects begin. */
90
+ assertCapacityForIteration(info: SessionIteration): void;
91
+ /** Discard a preflight failure that generated no response and ran no code. */
92
+ cancelIteration(iterationId: string): void;
93
+ /** Runtime feedback without inventing a tool-call identity or user turn. */
94
+ appendContext(content: string): void;
95
+ /**
96
+ * Build ephemeral model input. Canonical user text/tool results remain intact;
97
+ * the dynamic inventory is generated once, on the final eligible input only.
98
+ */
99
+ requestMessages(options?: {
100
+ memory?: boolean | string;
101
+ now?: number;
102
+ maxMemoryChars?: number;
103
+ inspector?: Inspector;
104
+ /** Preview compaction without discarding retained history or results. */
105
+ retainedIterationIds?: Iterable<string>;
106
+ /** Preview a prepared summary without changing the transcript. */
107
+ summary?: Transcript.SummaryMessage;
108
+ }): SessionMessage[];
109
+ /** Keep complete iterations, pruning their automatic results in the same operation. */
110
+ prune(retainedIds: Iterable<string>): void;
111
+ /** Summarize processed conversation without changing it. Queued inputs remain for the next turn. */
112
+ summarize(options: SummarizeOptions): Promise<Transcript.SummaryMessage | undefined>;
113
+ /** Replace older complete history with a summary, preserving named memory and queued input. */
114
+ compact(options: SummarizeOptions & {
115
+ keepRecentIterations?: number;
116
+ }): Promise<Transcript.SummaryMessage | undefined>;
117
+ /** @internal Prepare a transactional summary; callers must validate its final request before committing. */
118
+ prepareCompaction(retainedIds: Iterable<string>, options: SummarizeOptions): Promise<SessionCompaction | undefined>;
119
+ toJSON(): Session.JSON;
120
+ static fromJSON(state: Session.JSON, options?: Pick<SessionOptions, 'compaction'>): Session;
121
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -4,8 +4,7 @@ export declare namespace Transcript {
4
4
  *
5
5
  * - `image`: a picture the model can see.
6
6
  * - `audio`: a voice message — spoken audio of what the user said. Messages
7
- * carrying an audio attachment are presented to the model as spoken turns
8
- * (tagged `modality="voice"` in the prompt) and the audio is sent as model
7
+ * carrying an audio attachment are presented as spoken turns, with audio sent as model
9
8
  * input: audio-capable models hear it directly, others receive a
10
9
  * transcription (see `@botpress/cognitive`'s `transcriptionModel` option).
11
10
  *
@@ -13,8 +12,7 @@ export declare namespace Transcript {
13
12
  *
14
13
  * `id` is an optional stable identifier for referencing the attachment from
15
14
  * the message content (e.g. `screenshot-A` in a screen-share event log). It
16
- * is used as the attachment's reference in the prompt; without it, a
17
- * positional letter (A, B, C...) is auto-assigned.
15
+ * is preserved next to the attachment in the native message.
18
16
  *
19
17
  * `alt` is an optional human-readable description shown to the model next to
20
18
  * the attachment (e.g. "Screenshot of the checkout error page").
@@ -66,7 +64,5 @@ export declare namespace Transcript {
66
64
  }
67
65
  /** Whether the message is a spoken turn: explicit voice modality or an audio attachment. */
68
66
  export declare function isVoiceMessage(message: Transcript.Message): boolean;
69
- export declare class TranscriptArray extends Array<Transcript.Message> {
70
- constructor(items?: Transcript.Message[]);
71
- toString(): string;
72
- }
67
+ /** Validate the convenience input shape before converting it to a native message. */
68
+ export declare function validateTranscriptMessage(message: Transcript.Message): void;
@@ -0,0 +1 @@
1
+ export {};