llmz 0.9.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 -582
- 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 +70 -377
- 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 +176 -1237
- package/dist/index.d.ts +25 -28
- package/dist/index.js +137 -1213
- package/dist/index.workerd.js +8427 -10771
- package/dist/inspect.d.ts +18 -4
- 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 -101
- 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-diagnostics.d.ts +11 -0
- package/dist/runtime/execution-report.d.ts +48 -0
- package/dist/runtime/fixtures/chat.d.ts +8 -0
- package/dist/runtime/fixtures/long-search.d.ts +1 -1
- package/dist/runtime/fixtures/native-client.d.ts +33 -0
- package/dist/runtime/fixtures/protocol-languages.d.ts +1 -1
- package/dist/runtime/generate.d.ts +23 -20
- 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/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 +39 -31
- 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-BlRFtdf2.js +0 -807
- package/dist/common-BnvrDnIT.cjs +0 -860
- 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-C6Agl2ns.cjs +0 -73
- package/dist/component-DGG7d_Mz.js +0 -44
- package/dist/component.d.ts +0 -88
- package/dist/component.default.d.ts +0 -278
- package/dist/custom-client-ChuZ63zp.js +0 -2658
- package/dist/custom-client-DAsGRnYc.cjs +0 -2729
- package/dist/dual-modes-DDkoCp3R.js +0 -3006
- package/dist/dual-modes-DPXiuvNe.cjs +0 -3090
- package/dist/errors-C962uJdS.cjs +0 -220
- package/dist/errors-Cg1G0Awu.js +0 -161
- package/dist/example-format.d.ts +0 -8
- package/dist/example.d.ts +0 -45
- package/dist/execute-BWcdv9so.js +0 -1059
- package/dist/execute-DM2-7y86.cjs +0 -1060
- 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/isPlainObject-CSxXVKCk.cjs +0 -56
- package/dist/isPlainObject-D39AzPO2.js +0 -51
- package/dist/jsx-CIgdGGVs.js +0 -52
- package/dist/jsx-owqxrquU.cjs +0 -75
- package/dist/jsx.d.ts +0 -11
- package/dist/message-stream/index.d.ts +0 -9
- package/dist/message-stream/instructions.d.ts +0 -30
- package/dist/message-stream/normalizer.d.ts +0 -21
- package/dist/message-stream/parser.d.ts +0 -89
- package/dist/message-stream/registry.d.ts +0 -14
- package/dist/message-stream/replayable.d.ts +0 -27
- package/dist/message-stream/response-parser.d.ts +0 -24
- 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 -97
- package/dist/message-stream/validator.d.ts +0 -23
- package/dist/prompts/chat-mode/protocol.d.ts +0 -2
- 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/code-examples.d.ts +0 -2
- package/dist/prompts/common.d.ts +0 -7
- 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-basics.d.ts +0 -5
- package/dist/prompts/protocol.d.ts +0 -31
- package/dist/prompts/worker-mode/protocol.d.ts +0 -2
- 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/fixtures/qwen-protocol-failures.d.ts +0 -29
- 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/response-parser.test.d.ts → result.test.d.ts} +0 -0
- /package/dist/{message-stream/stream.test.d.ts → runtime/chat-delivery.test.d.ts} +0 -0
- /package/dist/{message-stream/validator.test.d.ts → runtime/compatibility-regressions.test.d.ts} +0 -0
- /package/dist/{prompts/adherence.test.d.ts → runtime/context-registration.test.d.ts} +0 -0
- /package/dist/{prompts/catalogue-examples.test.d.ts → runtime/error-recovery.test.d.ts} +0 -0
- /package/dist/{prompts/code-examples.test.d.ts → runtime/errors.test.d.ts} +0 -0
- /package/dist/{prompts/common.test.d.ts → runtime/execution-activity.test.d.ts} +0 -0
- /package/dist/{prompts/concrete-patterns.test.d.ts → runtime/execution-diagnostics.test.d.ts} +0 -0
- /package/dist/{prompts/long-search.test.d.ts → runtime/execution-report.test.d.ts} +0 -0
- /package/dist/{prompts/protocol-simple.test.d.ts → runtime/execution-safety.test.d.ts} +0 -0
- /package/dist/{prompts/protocol.test.d.ts → runtime/exit-control-flow.test.d.ts} +0 -0
- /package/dist/{prompts/sections.test.d.ts → runtime/fixtures/long-search.test.d.ts} +0 -0
- /package/dist/runtime/{interpret-result.test.d.ts → generate.test.d.ts} +0 -0
- /package/dist/{transcript.test.d.ts → runtime/hook-provenance.test.d.ts} +0 -0
- /package/dist/{truncator.test.d.ts → runtime/inspection-hook.test.d.ts} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ExecutionResult } from '../result.js';
|
|
2
|
-
import { ExecutionProps } from './types.js';
|
|
3
|
-
|
|
2
|
+
import type { ExecutionProps } from './types.js';
|
|
3
|
+
/** Each iteration joins generation and execution before settling its transcript. */
|
|
4
|
+
export declare function executeContext(props: ExecutionProps): Promise<ExecutionResult>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Iteration } from '../context.js';
|
|
2
|
+
import { type InspectionIdentity, type Inspector } from '../inspection.js';
|
|
3
|
+
import type { Traces } from '../types.js';
|
|
4
|
+
export type ExecutionActivity = {
|
|
5
|
+
calls: Traces.ToolCall[];
|
|
6
|
+
deliveries: Traces.MessageDelivery[];
|
|
7
|
+
};
|
|
8
|
+
/** Collect recorded operations, excluding ordinary assistant text delivery. */
|
|
9
|
+
export declare function getExecutionActivity(iteration: Iteration): ExecutionActivity;
|
|
10
|
+
export declare function renderToolCalls(activity: ExecutionActivity, includeRecoveryValues?: boolean, inspector?: Inspector, identity?: InspectionIdentity): string | undefined;
|
|
11
|
+
export declare function renderMessageDeliveries({ deliveries }: ExecutionActivity, cancelled?: boolean, inspector?: Inspector, identity?: InspectionIdentity): string | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InspectionIdentity, Inspector } from '../inspection.js';
|
|
2
|
+
import type { TruncatePreserve } from '../truncate.js';
|
|
3
|
+
/** XML-style boundaries keep diagnostic text separate from recovery instructions. */
|
|
4
|
+
export declare function reportSection(name: string, content: string, maxTokens?: number, options?: {
|
|
5
|
+
heading?: string;
|
|
6
|
+
preserve?: TruncatePreserve;
|
|
7
|
+
}): string;
|
|
8
|
+
/** Show the specific failure and guest source, never the host's implementation stack. */
|
|
9
|
+
export declare function renderExecutionDiagnostics(error: unknown, message: string, inspector: Inspector, identity: InspectionIdentity): string[];
|
|
10
|
+
/** Keep failure sites visible even when they are near the end of a long program. */
|
|
11
|
+
export declare function renderSourceTrace(stack: string, inspector: Inspector, identity: InspectionIdentity): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type InspectionPolicyLookup } from '../inspect.js';
|
|
2
|
+
import { type InspectionIdentity, type Inspector } from '../inspection.js';
|
|
3
|
+
import type { MemoryReport } from '../session/memory.js';
|
|
4
|
+
import { type ExecutionActivity } from './execution-activity.js';
|
|
5
|
+
export { renderMessageDeliveries } from './execution-activity.js';
|
|
6
|
+
export type ExecutionOutcome = {
|
|
7
|
+
type: 'inspect';
|
|
8
|
+
value: unknown;
|
|
9
|
+
available: boolean;
|
|
10
|
+
explicit: boolean;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'exit';
|
|
13
|
+
name: string;
|
|
14
|
+
value: unknown;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'error';
|
|
17
|
+
message: string;
|
|
18
|
+
error?: unknown;
|
|
19
|
+
exitName?: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'cancelled';
|
|
22
|
+
message: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: 'interrupted';
|
|
25
|
+
reason: 'stream' | 'thinking';
|
|
26
|
+
message?: string;
|
|
27
|
+
context?: unknown;
|
|
28
|
+
stacktrace?: string;
|
|
29
|
+
};
|
|
30
|
+
export type ExecutionReport = {
|
|
31
|
+
outcome: ExecutionOutcome;
|
|
32
|
+
activity: ExecutionActivity;
|
|
33
|
+
memory: MemoryReport;
|
|
34
|
+
source?: {
|
|
35
|
+
requested?: string;
|
|
36
|
+
executed?: string;
|
|
37
|
+
};
|
|
38
|
+
requiresExit?: boolean;
|
|
39
|
+
iteration?: number;
|
|
40
|
+
identity?: InspectionIdentity;
|
|
41
|
+
inspector?: Inspector;
|
|
42
|
+
maxTokens?: number;
|
|
43
|
+
policies?: InspectionPolicyLookup;
|
|
44
|
+
};
|
|
45
|
+
/** Format one settled outcome; execution is responsible for deciding what happened. */
|
|
46
|
+
export declare function renderExecutionReport({ outcome, activity, memory, source, requiresExit, iteration, identity, inspector, maxTokens, policies, }: ExecutionReport): string;
|
|
47
|
+
/** Keep the requested assistant call intact while disclosing the source the host actually ran. */
|
|
48
|
+
export declare function renderExecutionOverride(executedCode?: string, requestedCode?: string, inspector?: Inspector, identity?: InspectionIdentity): string | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Chat, type ChatMessage, type MessageDeltaHandler, type MessageMetadata } from '../../chat/chat.js';
|
|
2
|
+
import type { Component } from '../../chat/component.js';
|
|
3
|
+
/** Collect both delivery paths when testing execution order and receipts. */
|
|
4
|
+
export declare function createRecordingChat({ handler, onMessageDelta, components, }: {
|
|
5
|
+
handler: (message: ChatMessage, metadata: MessageMetadata) => Promise<void> | void;
|
|
6
|
+
onMessageDelta?: MessageDeltaHandler;
|
|
7
|
+
components?: Component[];
|
|
8
|
+
}): Chat;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CognitiveMetadata, CognitiveResponse, CognitiveStreamChunk, CognitiveToolCall } from '@botpress/cognitive';
|
|
2
|
+
import { _CustomModelClient, type RuntimeGenerateContentInput } from '../../custom-client.js';
|
|
3
|
+
export declare const nativeMetadata: CognitiveMetadata;
|
|
4
|
+
export declare const nativeCall: (name: string, input?: Record<string, unknown>, id?: string) => CognitiveToolCall;
|
|
5
|
+
export declare const javascript: (code: string) => CognitiveResponse;
|
|
6
|
+
export declare const response: (output?: string, toolCalls?: CognitiveToolCall[]) => CognitiveResponse;
|
|
7
|
+
export declare class NativeClient extends _CustomModelClient {
|
|
8
|
+
responses: CognitiveResponse[];
|
|
9
|
+
requests: RuntimeGenerateContentInput[];
|
|
10
|
+
constructor(responses: CognitiveResponse[]);
|
|
11
|
+
getModelDetails(id: string): Promise<{
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
input: {
|
|
16
|
+
maxTokens: number;
|
|
17
|
+
costPer1MTokens: number;
|
|
18
|
+
};
|
|
19
|
+
output: {
|
|
20
|
+
maxTokens: number;
|
|
21
|
+
costPer1MTokens: number;
|
|
22
|
+
};
|
|
23
|
+
tags: never[];
|
|
24
|
+
lifecycle: 'production';
|
|
25
|
+
}>;
|
|
26
|
+
generateText(input: RuntimeGenerateContentInput): Promise<CognitiveResponse>;
|
|
27
|
+
}
|
|
28
|
+
export declare class NativeStreamClient extends NativeClient {
|
|
29
|
+
size: number;
|
|
30
|
+
probe: () => void;
|
|
31
|
+
constructor(responses: CognitiveResponse[], size?: number, probe?: () => void);
|
|
32
|
+
generateTextStream(input: RuntimeGenerateContentInput): AsyncGenerator<CognitiveStreamChunk>;
|
|
33
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Synthetic multilingual inputs
|
|
1
|
+
/** Synthetic multilingual inputs for native protocol boundary tests. */
|
|
2
2
|
export declare const protocolLanguages: readonly [{
|
|
3
3
|
readonly language: 'English';
|
|
4
4
|
readonly hello: 'Hello!';
|
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import { RuntimeCognitive } from './types.js';
|
|
1
|
+
import type { CognitiveMessage, CognitiveMetadata, CognitiveResponse, CognitiveToolCall } from '@botpress/cognitive';
|
|
2
|
+
import type { MessageDelta, MessageMetadata } from '../chat/chat.js';
|
|
3
|
+
import type { Context, Iteration } from '../context.js';
|
|
4
|
+
import type { ExecutionHooks, RuntimeCognitive } from './types.js';
|
|
5
|
+
export { countNativeRequestTokens } from './token-budget.js';
|
|
6
|
+
/** A custom provider adapter can return the full assistant message, including opaque continuation data. */
|
|
7
|
+
export type NativeResponse = CognitiveResponse & {
|
|
8
|
+
assistantMessage?: CognitiveMessage;
|
|
9
|
+
continuation?: unknown;
|
|
10
|
+
};
|
|
11
|
+
export type NativeGeneration = {
|
|
12
|
+
attempt: number;
|
|
13
|
+
output: string;
|
|
14
|
+
toolCalls: CognitiveToolCall[];
|
|
15
|
+
assistantMessage?: CognitiveMessage;
|
|
16
|
+
continuation?: unknown;
|
|
17
|
+
metadata: CognitiveMetadata;
|
|
18
|
+
messageMetadata: MessageMetadata;
|
|
19
|
+
};
|
|
5
20
|
type GenerateCodeProps = {
|
|
6
21
|
iteration: Iteration;
|
|
7
22
|
ctx: Context;
|
|
8
23
|
cognitive: RuntimeCognitive;
|
|
9
24
|
controller: AbortController;
|
|
10
25
|
metadata?: Record<string, string>;
|
|
11
|
-
/**
|
|
12
|
-
* Called for each send after a complete, valid response and successful transport.
|
|
13
|
-
*/
|
|
14
|
-
onSend?: (send: ParsedSend, metadata: MessageMetadata) => Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Called for each `■send` body chunk as it is parsed from the stream
|
|
17
|
-
* (streaming clients only), or with a restart delta before replacement output.
|
|
18
|
-
* Text errors are best-effort; restart errors terminate generation.
|
|
19
|
-
*/
|
|
20
26
|
onSendDelta?: (delta: MessageDelta) => Promise<void> | void;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*/
|
|
25
|
-
onRunStart?: () => void;
|
|
27
|
+
onBeforeRequest?: ExecutionHooks['onBeforeRequest'];
|
|
28
|
+
/** Start a complete normalized call without waiting for execution or the stream tail. */
|
|
29
|
+
onToolCalls?: (calls: CognitiveToolCall[]) => boolean;
|
|
26
30
|
};
|
|
27
|
-
export declare
|
|
28
|
-
export {};
|
|
31
|
+
export declare function generateCode({ iteration, ctx, cognitive, controller, metadata, onSendDelta, onToolCalls, onBeforeRequest, }: GenerateCodeProps): Promise<NativeGeneration>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InspectionPolicyLookup } from '../inspect.js';
|
|
2
|
+
import type { TruncationPolicy } from '../truncate.js';
|
|
3
|
+
/** Explicit display policies apply only to unchanged values in this JavaScript execution. */
|
|
4
|
+
export declare class InspectionValues {
|
|
5
|
+
private readonly _primitives;
|
|
6
|
+
private readonly _objects;
|
|
7
|
+
capture(value: unknown, policy: TruncationPolicy): void;
|
|
8
|
+
captureDefault(value: unknown, maxTokens: number): void;
|
|
9
|
+
private _register;
|
|
10
|
+
/** Match unchanged VM copies without rebuilding a wrapped display graph. */
|
|
11
|
+
readonly getPolicy: InspectionPolicyLookup;
|
|
12
|
+
private _objectKey;
|
|
13
|
+
private _mergePolicy;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ComponentRegistry, RenderedComponent } from '../chat/component.js';
|
|
2
|
+
import type { Iteration } from '../context.js';
|
|
3
|
+
import { ThinkSignal } from '../errors.js';
|
|
4
|
+
import type { Exit } from '../exit.js';
|
|
5
|
+
/** A child message keeps its identity from preparation through acknowledged delivery. */
|
|
6
|
+
export type PreparedMessage = {
|
|
7
|
+
id: string;
|
|
8
|
+
component: RenderedComponent;
|
|
9
|
+
};
|
|
10
|
+
export type JavaScriptOutcome = {
|
|
11
|
+
type: 'inspect';
|
|
12
|
+
value: unknown;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'exit';
|
|
15
|
+
exit: Exit;
|
|
16
|
+
value: unknown;
|
|
17
|
+
};
|
|
18
|
+
type DecisionReceipt = Readonly<{
|
|
19
|
+
__llmz_decision: string;
|
|
20
|
+
}>;
|
|
21
|
+
type TerminalOutcome = Extract<JavaScriptOutcome, {
|
|
22
|
+
type: 'exit';
|
|
23
|
+
}>;
|
|
24
|
+
export type JavaScriptBindings = {
|
|
25
|
+
exit(name?: string, value?: unknown): never;
|
|
26
|
+
inspect(value: unknown): DecisionReceipt;
|
|
27
|
+
chat: Readonly<Record<string, (input: unknown) => void>>;
|
|
28
|
+
};
|
|
29
|
+
export type JavaScriptApi = {
|
|
30
|
+
bindings: JavaScriptBindings;
|
|
31
|
+
resolve(value: unknown): JavaScriptOutcome | undefined;
|
|
32
|
+
isReceipt(value: unknown): boolean;
|
|
33
|
+
getTerminalOutcome(): TerminalOutcome | undefined;
|
|
34
|
+
/** The first host interruption closes execution before guest handlers can consume it. */
|
|
35
|
+
getInterruption(): ThinkSignal | undefined;
|
|
36
|
+
throwIfTerminated(): void;
|
|
37
|
+
track<T>(operation: () => Promise<T>): Promise<T>;
|
|
38
|
+
assertOpen(): void;
|
|
39
|
+
/** Record validation failures and close host operations on critical configuration errors. */
|
|
40
|
+
reportError(error: unknown): void;
|
|
41
|
+
/** Called at program settlement, before background work can invoke another host operation. */
|
|
42
|
+
complete(): void;
|
|
43
|
+
/** Joins automatic message delivery and business work before the iteration can settle. */
|
|
44
|
+
close(): Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
type JavaScriptApiOptions = {
|
|
47
|
+
iteration: Pick<Iteration, 'id' | 'nativeCallId'>;
|
|
48
|
+
components: ComponentRegistry;
|
|
49
|
+
exits: readonly Exit[];
|
|
50
|
+
deliver(messages: readonly PreparedMessage[]): Promise<void>;
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
onError?(error: unknown): void;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Component methods send synchronously; the runtime joins delivery in close().
|
|
56
|
+
* Inspection returns a decision, while exit latches an outcome and stops the program.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createJavaScriptApi({ iteration, components, exits, deliver, signal, onError, }: JavaScriptApiOptions): JavaScriptApi;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CognitiveTool, CognitiveToolCall } from '@botpress/cognitive';
|
|
2
|
+
export declare const WORKER_RESPONSE_INSTRUCTION = "You are running in worker mode. Respond only with a run_javascript tool call. Keep assistant text empty: do not send messages, preambles, progress updates, explanations, acknowledgements such as \"Done\", Markdown, or JSON outside the tool call. This applies before and after tools, during recovery, and when completing the task.";
|
|
3
|
+
export declare const RUN_JAVASCRIPT_TOOL: CognitiveTool;
|
|
4
|
+
/** Select delivery guidance without changing the native tool name or input schema. */
|
|
5
|
+
export declare function getRunJavaScriptTool(chat: boolean): CognitiveTool;
|
|
6
|
+
export type ValidatedNativeCall = {
|
|
7
|
+
id: string;
|
|
8
|
+
code: string;
|
|
9
|
+
};
|
|
10
|
+
export type NativeCallValidation = {
|
|
11
|
+
valid: true;
|
|
12
|
+
call?: ValidatedNativeCall;
|
|
13
|
+
} | {
|
|
14
|
+
valid: false;
|
|
15
|
+
errors: string[];
|
|
16
|
+
};
|
|
17
|
+
/** Validate the entire response before any delivery or business action begins. */
|
|
18
|
+
export declare function validateNativeToolCalls(calls: readonly CognitiveToolCall[]): NativeCallValidation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CognitiveMessage } from '@botpress/cognitive';
|
|
2
|
+
/**
|
|
3
|
+
* Estimate text, structured arguments, schemas, and message scaffolding. Media
|
|
4
|
+
* URLs carry bytes or locations, not model text. Cognitive does not expose a
|
|
5
|
+
* media-token estimator; actual media usage is reported by the provider.
|
|
6
|
+
*/
|
|
7
|
+
export declare function countNativeRequestTokens(messages: CognitiveMessage[], tools: unknown): number;
|
|
8
|
+
type ModelLimits = {
|
|
9
|
+
input: {
|
|
10
|
+
maxTokens: number;
|
|
11
|
+
};
|
|
12
|
+
output: {
|
|
13
|
+
maxTokens: number;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/** Reserve output space within every model that can receive this request. */
|
|
17
|
+
export declare function resolveTokenBudget(model: ModelLimits | readonly ModelLimits[], maxTokens?: number): {
|
|
18
|
+
limit: number;
|
|
19
|
+
output: number;
|
|
20
|
+
input: number;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { Chat } from '../chat.js';
|
|
2
1
|
import { Iteration } from '../context.js';
|
|
3
2
|
import { type Tool } from '../tool.js';
|
|
4
|
-
import {
|
|
3
|
+
import type { TruncationPolicy } from '../truncate.js';
|
|
5
4
|
import { ExecutionHooks } from './types.js';
|
|
6
5
|
type ToolWrapperProps = {
|
|
7
|
-
chat?: Chat;
|
|
8
6
|
tool: Tool;
|
|
9
7
|
object?: string;
|
|
10
|
-
traces: Trace[];
|
|
11
8
|
iteration: Iteration;
|
|
12
9
|
beforeHook?: ExecutionHooks['onBeforeTool'];
|
|
13
10
|
afterHook?: ExecutionHooks['onAfterTool'];
|
|
11
|
+
onTruncation?: (value: unknown, policy: TruncationPolicy) => void;
|
|
12
|
+
onResult?: (value: unknown) => void;
|
|
14
13
|
controller: AbortController;
|
|
15
14
|
};
|
|
16
|
-
export declare function wrapTool({
|
|
15
|
+
export declare function wrapTool({ tool, object, iteration, beforeHook, afterHook, onTruncation, onResult, controller, }: ToolWrapperProps): (input: any) => Promise<any>;
|
|
17
16
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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
|
|
@@ -126,8 +147,9 @@ type Options = Partial<Pick<Context, 'loop' | 'timeout'>> & {
|
|
|
126
147
|
/**
|
|
127
148
|
* Allow Cognitive to restart a failed stream on another model. Previews remain
|
|
128
149
|
* live and are retracted with a restart delta before replacement output.
|
|
129
|
-
*
|
|
130
|
-
*
|
|
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.
|
|
131
153
|
*/
|
|
132
154
|
midStreamFallback?: boolean;
|
|
133
155
|
/**
|
|
@@ -138,13 +160,15 @@ type Options = Partial<Pick<Context, 'loop' | 'timeout'>> & {
|
|
|
138
160
|
transcriptionModel?: SttModels;
|
|
139
161
|
};
|
|
140
162
|
export type ExecutionProps = {
|
|
163
|
+
/** Append input to this session before execution. Retains history, queued input, and JavaScript memory. */
|
|
164
|
+
session?: Session;
|
|
141
165
|
/**
|
|
142
166
|
* If provided, the execution will be run in "Chat Mode".
|
|
143
|
-
*
|
|
167
|
+
* Chat configures assistant text and rich component delivery. Conversation input belongs to the session.
|
|
144
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.
|
|
145
169
|
*
|
|
146
|
-
* If `chat` is not provided, the execution will run in "Worker Mode"
|
|
147
|
-
* 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.
|
|
148
172
|
*/
|
|
149
173
|
chat?: Chat;
|
|
150
174
|
/**
|
|
@@ -154,14 +178,6 @@ export type ExecutionProps = {
|
|
|
154
178
|
* Dynamic instructions are evaluated at the start of each iteration, allowing for context-aware instructions.
|
|
155
179
|
*/
|
|
156
180
|
instructions?: ValueOrGetter<string, Context>;
|
|
157
|
-
/**
|
|
158
|
-
* Labeled examples of one situation and one response, kept outside the live transcript.
|
|
159
|
-
* Use `new Example({ situation, code })` or `new Example({ situation, messages, exit })`.
|
|
160
|
-
* Evaluated each iteration, like instructions. Examples must use the current
|
|
161
|
-
* component/exit catalog. They are kept intact when the prompt is truncated;
|
|
162
|
-
* select a small relevant set to leave room for tools and conversation.
|
|
163
|
-
*/
|
|
164
|
-
examples?: ValueOrGetter<Example[], Context>;
|
|
165
181
|
/**
|
|
166
182
|
* Objects available in the context.
|
|
167
183
|
* Objects are useful to scope related tools together and to provide data to the VM.
|
|
@@ -194,7 +210,7 @@ export type ExecutionProps = {
|
|
|
194
210
|
* Exits define the possible endpoints for the execution. Every execution will either end with an exit, or run out of iterations.
|
|
195
211
|
*
|
|
196
212
|
* When `chat` is provided, the built-in "ListenExit" is automatically added.
|
|
197
|
-
*
|
|
213
|
+
* In worker mode, omitting `exits` adds the built-in "DefaultExit". An explicit empty array provides no exits.
|
|
198
214
|
*
|
|
199
215
|
* Each exit has a name and can have aliases, which are alternative names for the exit that can be used to call it.
|
|
200
216
|
* Exits can also have a Zui schema to validate the return value when the exit is reached.
|
|
@@ -216,14 +232,6 @@ export type ExecutionProps = {
|
|
|
216
232
|
* Aborted iterations will end with IterationStatuses.Aborted and the execution will be marked as failed.
|
|
217
233
|
*/
|
|
218
234
|
signal?: AbortSignal;
|
|
219
|
-
/**
|
|
220
|
-
* A snapshot is a saved state of the execution context.
|
|
221
|
-
* It can be used to resume the execution of a context at a later time.
|
|
222
|
-
* This is useful for long-running executions that may need to be paused and resumed later.
|
|
223
|
-
* The snapshot MUST be settled, which means it has to be resolved or rejected.
|
|
224
|
-
* Providing an unsettled snapshot will throw an error.
|
|
225
|
-
*/
|
|
226
|
-
snapshot?: Snapshot;
|
|
227
235
|
/**
|
|
228
236
|
* The model to use for the LLM.
|
|
229
237
|
* This can be a static model name or a function that returns a model name based on the current context.
|
|
@@ -252,8 +260,8 @@ export type ExecutionProps = {
|
|
|
252
260
|
} & ExecutionHooks;
|
|
253
261
|
export type RuntimeCognitive = Pick<Cognitive, 'getModelDetails' | 'generateText'> & {
|
|
254
262
|
/**
|
|
255
|
-
* Streaming generation.
|
|
256
|
-
*
|
|
263
|
+
* Streaming generation. Assistant text streams as provisional previews; native
|
|
264
|
+
* tool calls can execute while text streams; both settle before the next iteration.
|
|
257
265
|
*/
|
|
258
266
|
generateTextStream?: Cognitive['generateTextStream'];
|
|
259
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 };
|