llmz 0.8.0 → 1.0.1
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/DOCS.md +230 -1796
- package/ERRORS.md +98 -0
- package/README.md +96 -548
- package/dist/chat/chat.d.ts +63 -0
- package/dist/chat/component.d.ts +31 -0
- package/dist/chat/component.default.d.ts +58 -0
- package/dist/chat/response.d.ts +15 -0
- package/dist/compiler/compiler.d.ts +2 -7
- package/dist/compiler/plugins/dynamic-code.d.ts +7 -0
- package/dist/compiler/plugins/replace-comment.d.ts +2 -3
- package/dist/compiler/plugins/return-async.d.ts +5 -4
- package/dist/compiler/plugins/termination.d.ts +8 -0
- package/dist/compiler/plugins/tool-resolution.d.ts +4 -0
- package/dist/compiler/plugins/variable-extraction.d.ts +2 -8
- package/dist/component-BpMVZYOa.cjs +649 -0
- package/dist/component-C27qu6Zv.js +614 -0
- package/dist/context.d.ts +74 -385
- package/dist/custom-client-BDkgBR2w.js +1631 -0
- package/dist/custom-client-MytucGI-.cjs +1708 -0
- package/dist/custom-client.d.ts +12 -2
- package/dist/errors/catalog.d.ts +287 -0
- package/dist/errors/hooks.d.ts +2 -0
- package/dist/errors-H4JJFH3S.js +620 -0
- package/dist/errors-IhnTKUp7.cjs +871 -0
- package/dist/errors.d.ts +18 -36
- package/dist/execute-BYI_U5sR.js +1943 -0
- package/dist/execute-DLas4V2n.cjs +1944 -0
- package/dist/{exit-DUM96DN1.cjs → exit-BUgJ5qi5.cjs} +38 -28
- package/dist/{exit-CDdxDBRT.js → exit-CPNk3vbz.js} +37 -27
- package/dist/exit.d.ts +19 -16
- package/dist/index.cjs +181 -999
- package/dist/index.d.ts +25 -28
- package/dist/index.js +141 -974
- package/dist/index.workerd.js +7725 -9531
- package/dist/inspect.d.ts +19 -3
- package/dist/inspection.d.ts +38 -0
- package/dist/native-Bm6L9zOb.cjs +212 -0
- package/dist/native-DvTH9vFe.js +177 -0
- package/dist/objects.d.ts +2 -57
- package/dist/prompts/native.d.ts +2 -0
- package/dist/prompts/prompt.d.ts +10 -98
- package/dist/quickjs-variant-DJwYDSsb.cjs +1073 -0
- package/dist/quickjs-variant-DlPi9-Sx.js +984 -0
- package/dist/result.d.ts +30 -861
- package/dist/runtime/execute.d.ts +3 -2
- package/dist/runtime/execution-activity.d.ts +11 -0
- package/dist/runtime/execution-activity.test.d.ts +1 -0
- package/dist/runtime/execution-diagnostics.d.ts +11 -0
- package/dist/runtime/execution-diagnostics.test.d.ts +1 -0
- package/dist/runtime/execution-report.d.ts +48 -0
- package/dist/runtime/execution-report.test.d.ts +1 -0
- package/dist/runtime/execution-safety.test.d.ts +1 -0
- package/dist/runtime/exit-control-flow.test.d.ts +1 -0
- package/dist/runtime/fixtures/chat.d.ts +8 -0
- package/dist/runtime/fixtures/long-search.d.ts +19 -0
- package/dist/runtime/fixtures/long-search.test.d.ts +1 -0
- package/dist/runtime/fixtures/native-client.d.ts +33 -0
- package/dist/runtime/fixtures/protocol-languages.d.ts +74 -0
- package/dist/runtime/generate.d.ts +23 -27
- package/dist/runtime/generate.test.d.ts +1 -0
- package/dist/runtime/hook-provenance.test.d.ts +1 -0
- package/dist/runtime/inspection-hook.test.d.ts +1 -0
- package/dist/runtime/inspection-values.d.ts +14 -0
- package/dist/runtime/inspection-values.test.d.ts +1 -0
- package/dist/runtime/interruption-control-flow.test.d.ts +1 -0
- package/dist/runtime/interruption-settings.test.d.ts +1 -0
- package/dist/runtime/javascript-api.d.ts +59 -0
- package/dist/runtime/javascript-api.test.d.ts +1 -0
- package/dist/runtime/native-review.test.d.ts +1 -0
- package/dist/runtime/native-tools.d.ts +18 -0
- package/dist/runtime/native-tools.test.d.ts +1 -0
- package/dist/runtime/object-memory.test.d.ts +1 -0
- package/dist/runtime/protocol-adherence.test.d.ts +1 -0
- package/dist/runtime/single-tool.test.d.ts +1 -0
- package/dist/runtime/token-budget.d.ts +22 -0
- package/dist/runtime/token-budget.test.d.ts +1 -0
- package/dist/runtime/tool-wrapper.d.ts +4 -5
- package/dist/runtime/traces.test.d.ts +1 -0
- package/dist/runtime/truncation.test.d.ts +1 -0
- package/dist/runtime/types.d.ts +41 -36
- package/dist/runtime/variable-recovery.test.d.ts +1 -0
- package/dist/runtime/vm-context.d.ts +6 -1
- package/dist/runtime/worker-completion.test.d.ts +1 -0
- package/dist/runtime-names.d.ts +4 -0
- package/dist/schema-Aer_W7Al.js +45 -0
- package/dist/schema-DBkjo0b7.cjs +68 -0
- package/dist/schema.d.ts +10 -0
- package/dist/schema.test.d.ts +1 -0
- package/dist/session/compactor.d.ts +51 -0
- package/dist/session/compactor.test.d.ts +1 -0
- package/dist/session/history.d.ts +36 -0
- package/dist/session/history.test.d.ts +1 -0
- package/dist/session/json.d.ts +3 -0
- package/dist/session/json.test.d.ts +1 -0
- package/dist/session/memory-codec.d.ts +9 -0
- package/dist/session/memory-codec.test.d.ts +1 -0
- package/dist/session/memory-render.d.ts +15 -0
- package/dist/session/memory-render.test.d.ts +1 -0
- package/dist/session/memory.d.ts +112 -0
- package/dist/session/memory.test.d.ts +1 -0
- package/dist/session/messages.d.ts +17 -0
- package/dist/session/messages.test.d.ts +1 -0
- package/dist/session/serialization.d.ts +34 -0
- package/dist/session/serialization.test.d.ts +1 -0
- package/dist/session/session-memory.test.d.ts +1 -0
- package/dist/session/session.d.ts +117 -0
- package/dist/session/session.test.d.ts +1 -0
- package/dist/{transcript.d.ts → session/transcript.d.ts} +4 -8
- package/dist/session/transcript.test.d.ts +1 -0
- package/dist/{tool-Bv8N4IPj.js → tool--gK91eez.js} +144 -92
- package/dist/{tool-Dy6AJpJH.cjs → tool-Da_F-N-5.cjs} +146 -94
- package/dist/tool.d.ts +25 -17
- package/dist/truncate-BSoH2-nY.js +79 -0
- package/dist/truncate-nV3Mxr6-.cjs +102 -0
- package/dist/truncate.d.ts +24 -0
- package/dist/truncate.test.d.ts +1 -0
- package/dist/types.d.ts +27 -9
- package/dist/{typings-3lsqCbkn.cjs → typings-C1ihexWE.cjs} +38 -193
- package/dist/{typings-CrBa7Tyy.js → typings-D9_aC8aq.js} +38 -175
- package/dist/typings-formatter.d.ts +1 -1
- package/dist/typings.d.ts +3 -0
- package/dist/{uniq-BYQ7GWwb.js → uniq-DfUeSNaX.js} +2 -2
- package/dist/{uniq-G872RWmE.cjs → uniq-DiXgysNV.cjs} +6 -18
- package/dist/{_baseIteratee-P_firB7b.js → utils-BOFzb8Ok.js} +1134 -16
- package/dist/{_baseIteratee-CF4qP2a8.cjs → utils-CTlsXvdj.cjs} +1281 -84
- package/dist/vm/drivers/node.d.ts +1 -1
- package/dist/vm/drivers/quickjs.d.ts +1 -1
- package/dist/vm/errors.d.ts +4 -4
- package/dist/vm/index.d.ts +3 -4
- package/dist/vm/instrument.d.ts +14 -6
- package/dist/vm/member-proxy.d.ts +4 -0
- package/dist/vm/member-proxy.test.d.ts +1 -0
- package/dist/vm/memory.test.d.ts +1 -0
- package/dist/vm/return-semantics.test.d.ts +1 -0
- package/dist/vm/types.d.ts +18 -3
- package/dist/{vm-BLsHw1da.js → vm-8jxt8PTK.js} +1162 -180
- package/dist/{vm-D6s1zF6M.cjs → vm-XuVPuW3Y.cjs} +1195 -207
- package/package.json +13 -6
- package/dist/_baseForOwn-BfWDTL8L.cjs +0 -53
- package/dist/_baseForOwn-CFhWe_W6.js +0 -48
- package/dist/_getPrototype-CG7Dxrrz.js +0 -6
- package/dist/_getPrototype-DQDlNVVM.cjs +0 -10
- package/dist/_overArg-C5Hy7oCi.cjs +0 -196
- package/dist/_overArg-CRYbj1NH.js +0 -155
- package/dist/chat.d.ts +0 -401
- package/dist/common-DdArNQhl.cjs +0 -643
- package/dist/common-pgJjFu2Y.js +0 -596
- package/dist/compiler/plugins/track-tool-calls.d.ts +0 -33
- package/dist/compiler-C-OI9sim.cjs +0 -547
- package/dist/compiler-CW1VjQsn.js +0 -473
- package/dist/component-BXS8vAwO.cjs +0 -73
- package/dist/component-Dq7ZLdvy.js +0 -44
- package/dist/component.d.ts +0 -88
- package/dist/component.default.d.ts +0 -268
- package/dist/custom-client-2V9lmzUf.js +0 -2655
- package/dist/custom-client-HkM1Sdzv.cjs +0 -2726
- package/dist/dual-modes-Cb7ThvoV.cjs +0 -3020
- package/dist/dual-modes-Cy0_W4O2.js +0 -2930
- package/dist/errors-C962uJdS.cjs +0 -220
- package/dist/errors-Cg1G0Awu.js +0 -161
- package/dist/example.d.ts +0 -45
- package/dist/execute-Aw4cbIx-.js +0 -1080
- package/dist/execute-COIHOIKR.cjs +0 -1081
- package/dist/exit-parser.d.ts +0 -39
- package/dist/handlers.d.ts +0 -10
- package/dist/hoist.d.ts +0 -2
- package/dist/isEmpty-BhJRCqIF.js +0 -52
- package/dist/isEmpty-LY533Wmh.cjs +0 -57
- package/dist/jsx-B0iYyvfr.js +0 -100
- package/dist/jsx-D5Y2cPo-.cjs +0 -129
- package/dist/jsx.d.ts +0 -11
- package/dist/message-stream/index.d.ts +0 -9
- package/dist/message-stream/instructions.d.ts +0 -22
- package/dist/message-stream/normalizer.d.ts +0 -21
- package/dist/message-stream/parser.d.ts +0 -83
- package/dist/message-stream/registry.d.ts +0 -14
- package/dist/message-stream/replayable.d.ts +0 -27
- package/dist/message-stream/sanitize.d.ts +0 -10
- package/dist/message-stream/stream.d.ts +0 -54
- package/dist/message-stream/types.d.ts +0 -96
- package/dist/message-stream/validator.d.ts +0 -23
- package/dist/prompts/chat-mode/system.d.ts +0 -2
- package/dist/prompts/chat-mode/system.md.d.ts +0 -2
- package/dist/prompts/chat-mode/user.d.ts +0 -2
- package/dist/prompts/chat-mode/user.md.d.ts +0 -2
- package/dist/prompts/common.d.ts +0 -6
- package/dist/prompts/dual-modes.d.ts +0 -2
- package/dist/prompts/execution-history.d.ts +0 -6
- package/dist/prompts/execution-state.d.ts +0 -3
- package/dist/prompts/protocol.d.ts +0 -18
- package/dist/prompts/worker-mode/system.d.ts +0 -2
- package/dist/prompts/worker-mode/system.md.d.ts +0 -2
- package/dist/prompts/worker-mode/user.d.ts +0 -2
- package/dist/prompts/worker-mode/user.md.d.ts +0 -2
- package/dist/quickjs-variant-BYhMBpwU.js +0 -45
- package/dist/quickjs-variant-CsIwTVFC.cjs +0 -56
- package/dist/rolldown-runtime-EAsCxrDo.js +0 -14
- package/dist/runtime/interpret-result.d.ts +0 -22
- package/dist/snapshots.d.ts +0 -249
- package/dist/stack-traces-BIE_5Xwf.js +0 -21
- package/dist/stack-traces-ntw_qhoy.cjs +0 -26
- package/dist/truncator-CLkouTCO.cjs +0 -276
- package/dist/truncator-DZqEqnpD.js +0 -253
- package/dist/truncator.d.ts +0 -118
- package/dist/utils-3ESwP3yg.cjs +0 -1075
- package/dist/utils-UBeAFeEI.js +0 -950
- /package/dist/{citations.d.ts → chat/citations.d.ts} +0 -0
- /package/dist/{citations.test.d.ts → chat/citations.test.d.ts} +0 -0
- /package/dist/{component.default.test.d.ts → chat/component.default.test.d.ts} +0 -0
- /package/dist/{compiler/plugins/track-tool-calls.test.d.ts → chat/component.test.d.ts} +0 -0
- /package/dist/{example.test.d.ts → chat/response.test.d.ts} +0 -0
- /package/dist/{exit-parser.test.d.ts → compiler/plugins/dynamic-code.test.d.ts} +0 -0
- /package/dist/{handlers.test.d.ts → compiler/plugins/tool-resolution.test.d.ts} +0 -0
- /package/dist/{hoist.test.d.ts → errors/catalog.test.d.ts} +0 -0
- /package/dist/{message-stream/instructions.test.d.ts → exit.test.d.ts} +0 -0
- /package/dist/{message-stream/normalizer.test.d.ts → inspection.test.d.ts} +0 -0
- /package/dist/{message-stream/parser.test.d.ts → prompts/native.test.d.ts} +0 -0
- /package/dist/{message-stream/stream.test.d.ts → result.test.d.ts} +0 -0
- /package/dist/{message-stream/validator.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
- /package/dist/{prompts/common.test.d.ts → runtime/citations.test.d.ts} +0 -0
- /package/dist/{prompts/protocol.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
- /package/dist/runtime/{interpret-result.test.d.ts → context-registration.test.d.ts} +0 -0
- /package/dist/{transcript.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
- /package/dist/{truncator.test.d.ts → runtime/errors.test.d.ts} +0 -0
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Cognitive, type BotpressClientLike, Models, type SttModels } from '@botpress/cognitive';
|
|
2
|
-
import { Chat } from '../chat.js';
|
|
1
|
+
import { Cognitive, type CognitiveMessage, type BotpressClientLike, Models, type SttModels } from '@botpress/cognitive';
|
|
2
|
+
import { Chat } from '../chat/chat.js';
|
|
3
3
|
import { Context, Iteration } from '../context.js';
|
|
4
4
|
import { _CustomModelClient } from '../custom-client.js';
|
|
5
|
-
import type { Example } from '../example.js';
|
|
6
5
|
import { Exit, ExitResult } from '../exit.js';
|
|
7
6
|
import { ValueOrGetter } from '../getter.js';
|
|
7
|
+
import type { OnInspect } from '../inspection.js';
|
|
8
8
|
import { type ObjectInstance } from '../objects.js';
|
|
9
|
-
import {
|
|
9
|
+
import type { Session } from '../session/session.js';
|
|
10
10
|
import { type Tool } from '../tool.js';
|
|
11
11
|
import { Trace } from '../types.js';
|
|
12
12
|
export type ExecutionHooks = {
|
|
@@ -31,9 +31,21 @@ export type ExecutionHooks = {
|
|
|
31
31
|
* This hook will block the execution of the iteration until it resolves.
|
|
32
32
|
*
|
|
33
33
|
* This hook will be called before each iteration starts, regardless of the status.
|
|
34
|
-
*
|
|
34
|
+
* Use this for observation. Configure dynamic model arguments with their getters.
|
|
35
35
|
*/
|
|
36
|
-
onIterationStart?: (iteration: Iteration, controller: AbortController, context: Context) => Promise<void |
|
|
36
|
+
onIterationStart?: (iteration: Iteration, controller: AbortController, context: Context) => Promise<void> | void;
|
|
37
|
+
/** Customize the assembled request after compaction. Custom messages must fit the context budget. */
|
|
38
|
+
onBeforeRequest?: (event: {
|
|
39
|
+
messages: CognitiveMessage[];
|
|
40
|
+
iteration: Iteration;
|
|
41
|
+
controller: AbortController;
|
|
42
|
+
}) => Promise<{
|
|
43
|
+
messages: CognitiveMessage[];
|
|
44
|
+
} | void> | {
|
|
45
|
+
messages: CognitiveMessage[];
|
|
46
|
+
} | void;
|
|
47
|
+
/** Format runtime values; LLMz enforces the supplied budget on custom output. */
|
|
48
|
+
onInspect?: OnInspect;
|
|
37
49
|
/**
|
|
38
50
|
* BLOCKING HOOK
|
|
39
51
|
* This hook will block the execution of the iteration until it resolves.
|
|
@@ -84,6 +96,8 @@ export type ExecutionHooks = {
|
|
|
84
96
|
input: any;
|
|
85
97
|
controller: AbortController;
|
|
86
98
|
toolCallId: string;
|
|
99
|
+
/** Native run_javascript call owning this business call. */
|
|
100
|
+
nativeCallId?: string;
|
|
87
101
|
object?: string;
|
|
88
102
|
}) => Promise<{
|
|
89
103
|
input?: any;
|
|
@@ -104,6 +118,8 @@ export type ExecutionHooks = {
|
|
|
104
118
|
output: any;
|
|
105
119
|
controller: AbortController;
|
|
106
120
|
toolCallId: string;
|
|
121
|
+
/** Native run_javascript call owning this business call. */
|
|
122
|
+
nativeCallId?: string;
|
|
107
123
|
object?: string;
|
|
108
124
|
}) => Promise<{
|
|
109
125
|
output?: any;
|
|
@@ -112,10 +128,15 @@ export type ExecutionHooks = {
|
|
|
112
128
|
type Options = Partial<Pick<Context, 'loop' | 'timeout'>> & {
|
|
113
129
|
/**
|
|
114
130
|
* Optional cap on the model's context window, in tokens.
|
|
115
|
-
* The effective limit is `min(maxTokens, model
|
|
131
|
+
* The effective limit is `min(maxTokens, smallest configured model input limit)`.
|
|
116
132
|
* Useful to reduce cost and latency on models with very large context windows.
|
|
117
133
|
*/
|
|
118
134
|
maxTokens?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Default inspection budget for tool results, from 0 to 2,000 tokens.
|
|
137
|
+
* Defaults to 2,000. A tool's truncate() wrapper can override this limit.
|
|
138
|
+
*/
|
|
139
|
+
toolResultMaxTokens?: number;
|
|
119
140
|
/**
|
|
120
141
|
* Maximum time to wait for the first streamed token, in milliseconds, before
|
|
121
142
|
* the cognitive service falls back to the next model/provider. Only applies
|
|
@@ -124,13 +145,11 @@ type Options = Partial<Pick<Context, 'loop' | 'timeout'>> & {
|
|
|
124
145
|
*/
|
|
125
146
|
maxTimeToFirstToken?: number;
|
|
126
147
|
/**
|
|
127
|
-
* Allow Cognitive to restart failed
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* irreversible transports). Only TOOL/CODE execution waits for a successful
|
|
133
|
-
* stream. Streaming-only; defaults to false, preserving progressive sending.
|
|
148
|
+
* Allow Cognitive to restart a failed stream on another model. Previews remain
|
|
149
|
+
* live and are retracted with a restart delta before replacement output.
|
|
150
|
+
* Complete calls may execute while transport is open. Once execution starts,
|
|
151
|
+
* a stream failure or restart ends the iteration without replaying its effects.
|
|
152
|
+
* Streaming-only; defaults to false.
|
|
134
153
|
*/
|
|
135
154
|
midStreamFallback?: boolean;
|
|
136
155
|
/**
|
|
@@ -141,13 +160,15 @@ type Options = Partial<Pick<Context, 'loop' | 'timeout'>> & {
|
|
|
141
160
|
transcriptionModel?: SttModels;
|
|
142
161
|
};
|
|
143
162
|
export type ExecutionProps = {
|
|
163
|
+
/** Append input to this session before execution. Retains history, queued input, and JavaScript memory. */
|
|
164
|
+
session?: Session;
|
|
144
165
|
/**
|
|
145
166
|
* If provided, the execution will be run in "Chat Mode".
|
|
146
|
-
*
|
|
167
|
+
* Chat configures assistant text and rich component delivery. Conversation input belongs to the session.
|
|
147
168
|
* The execution can still end with a custom Exit, but a special ListenExit will be added to give back the chat control to the user.
|
|
148
169
|
*
|
|
149
|
-
* If `chat` is not provided, the execution will run in "Worker Mode"
|
|
150
|
-
* In Worker Mode, the execution
|
|
170
|
+
* If `chat` is not provided, the execution will run in "Worker Mode" without chat delivery.
|
|
171
|
+
* In Worker Mode, the execution uses the same session history and memory, and iterates until an Exit or its limit.
|
|
151
172
|
*/
|
|
152
173
|
chat?: Chat;
|
|
153
174
|
/**
|
|
@@ -157,14 +178,6 @@ export type ExecutionProps = {
|
|
|
157
178
|
* Dynamic instructions are evaluated at the start of each iteration, allowing for context-aware instructions.
|
|
158
179
|
*/
|
|
159
180
|
instructions?: ValueOrGetter<string, Context>;
|
|
160
|
-
/**
|
|
161
|
-
* Labeled examples of one situation and one response, kept outside the live transcript.
|
|
162
|
-
* Use `new Example({ situation, code })` or `new Example({ situation, messages, exit })`.
|
|
163
|
-
* Evaluated each iteration, like instructions. Examples must use the current
|
|
164
|
-
* component/exit catalog. They are kept intact when the prompt is truncated;
|
|
165
|
-
* select a small relevant set to leave room for tools and conversation.
|
|
166
|
-
*/
|
|
167
|
-
examples?: ValueOrGetter<Example[], Context>;
|
|
168
181
|
/**
|
|
169
182
|
* Objects available in the context.
|
|
170
183
|
* Objects are useful to scope related tools together and to provide data to the VM.
|
|
@@ -197,7 +210,7 @@ export type ExecutionProps = {
|
|
|
197
210
|
* Exits define the possible endpoints for the execution. Every execution will either end with an exit, or run out of iterations.
|
|
198
211
|
*
|
|
199
212
|
* When `chat` is provided, the built-in "ListenExit" is automatically added.
|
|
200
|
-
*
|
|
213
|
+
* In worker mode, omitting `exits` adds the built-in "DefaultExit". An explicit empty array provides no exits.
|
|
201
214
|
*
|
|
202
215
|
* Each exit has a name and can have aliases, which are alternative names for the exit that can be used to call it.
|
|
203
216
|
* Exits can also have a Zui schema to validate the return value when the exit is reached.
|
|
@@ -219,14 +232,6 @@ export type ExecutionProps = {
|
|
|
219
232
|
* Aborted iterations will end with IterationStatuses.Aborted and the execution will be marked as failed.
|
|
220
233
|
*/
|
|
221
234
|
signal?: AbortSignal;
|
|
222
|
-
/**
|
|
223
|
-
* A snapshot is a saved state of the execution context.
|
|
224
|
-
* It can be used to resume the execution of a context at a later time.
|
|
225
|
-
* This is useful for long-running executions that may need to be paused and resumed later.
|
|
226
|
-
* The snapshot MUST be settled, which means it has to be resolved or rejected.
|
|
227
|
-
* Providing an unsettled snapshot will throw an error.
|
|
228
|
-
*/
|
|
229
|
-
snapshot?: Snapshot;
|
|
230
235
|
/**
|
|
231
236
|
* The model to use for the LLM.
|
|
232
237
|
* This can be a static model name or a function that returns a model name based on the current context.
|
|
@@ -255,8 +260,8 @@ export type ExecutionProps = {
|
|
|
255
260
|
} & ExecutionHooks;
|
|
256
261
|
export type RuntimeCognitive = Pick<Cognitive, 'getModelDetails' | 'generateText'> & {
|
|
257
262
|
/**
|
|
258
|
-
* Streaming generation.
|
|
259
|
-
*
|
|
263
|
+
* Streaming generation. Assistant text streams as provisional previews; native
|
|
264
|
+
* tool calls can execute while text streams; both settle before the next iteration.
|
|
260
265
|
*/
|
|
261
266
|
generateTextStream?: Cognitive['generateTextStream'];
|
|
262
267
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Context, Iteration } from '../context.js';
|
|
2
|
+
import type { TruncationPolicy } from '../truncate.js';
|
|
2
3
|
import { type VMContext } from '../vm/types.js';
|
|
4
|
+
import type { JavaScriptApi } from './javascript-api.js';
|
|
3
5
|
import { ExecutionHooks } from './types.js';
|
|
4
6
|
type BuildVMContextProps = {
|
|
5
7
|
ctx: Context;
|
|
@@ -7,6 +9,9 @@ type BuildVMContextProps = {
|
|
|
7
9
|
controller: AbortController;
|
|
8
10
|
onBeforeTool?: ExecutionHooks['onBeforeTool'];
|
|
9
11
|
onAfterTool?: ExecutionHooks['onAfterTool'];
|
|
12
|
+
onTruncation?: (value: unknown, policy: TruncationPolicy) => void;
|
|
13
|
+
onToolResult?: (value: unknown) => void;
|
|
14
|
+
javascriptApi?: JavaScriptApi;
|
|
10
15
|
};
|
|
11
|
-
export declare const buildVMContext: ({ ctx, iteration, controller, onBeforeTool, onAfterTool, }: BuildVMContextProps) => VMContext;
|
|
16
|
+
export declare const buildVMContext: ({ ctx, iteration, controller, onBeforeTool, onAfterTool, onTruncation, onToolResult, javascriptApi, }: BuildVMContextProps) => VMContext;
|
|
12
17
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Runtime bindings are never tool names or retained user variables. */
|
|
2
|
+
export declare const RUNTIME_BINDING_NAMES: readonly ['$return', '$iterations', 'exit', 'inspect', 'chat'];
|
|
3
|
+
export declare const TERMINATION_BINDING_NAMES: readonly ['__llmz_guard', '__llmz_checkpoint', '__llmz_missing_tool'];
|
|
4
|
+
export declare const RESERVED_RUNTIME_NAMES: ReadonlySet<string>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { H as isLLMzError, b as InvalidConfigurationError } from "./errors-H4JJFH3S.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,68 @@
|
|
|
1
|
+
const require_errors = require("./errors-IhnTKUp7.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
|
+
});
|
package/dist/schema.d.ts
ADDED
|
@@ -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 @@
|
|
|
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,17 @@
|
|
|
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
|
+
export declare function createAssistantMessage(response: AssistantResponse): SessionMessage;
|
|
14
|
+
export declare function validateInputMessage(message: CognitiveMessage): void;
|
|
15
|
+
export declare function validateMessageContent(message: CognitiveMessage): void;
|
|
16
|
+
/** Add runtime context to an isolated request, leaving canonical history untouched. */
|
|
17
|
+
export declare function withMemoryOverview(history: readonly SessionMessage[], overview?: string): SessionMessage[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
latestResultId?: string;
|
|
27
|
+
compaction?: false | Omit<CompactionOptions, 'summarize'>;
|
|
28
|
+
};
|
|
29
|
+
/** Persisted counters, native identities, and exact values must describe one history. */
|
|
30
|
+
export declare function validateRestoredHistory(state: SessionState): void;
|
|
31
|
+
export declare function serializeGroup(group: HistoryGroup): SerializedHistoryGroup;
|
|
32
|
+
export declare function restoreGroup(group: SerializedHistoryGroup): HistoryGroup;
|
|
33
|
+
export declare function resultBytes(records: readonly SessionIterationRecord[]): number;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|