@anvia/core 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/agent/agent-tool.js +10 -8
- package/dist/agent/agent.js +24 -22
- package/dist/agent/index.d.ts +12 -12
- package/dist/agent/index.js +30 -28
- package/dist/agent/interactions/index.d.ts +1 -1
- package/dist/agent/resolve-options.js +8 -8
- package/dist/agent/resolved-agent.js +25 -23
- package/dist/agent/team/agent-team.js +30 -28
- package/dist/agent/team/index.js +30 -28
- package/dist/agent/tool-catalog.js +7 -7
- package/dist/{agent-C9VhENdj.d.ts → agent-D3iyrJQb.d.ts} +9 -9
- package/dist/{chunk-UTAB3XQI.js → chunk-2JZV4LUS.js} +2 -2
- package/dist/{chunk-G336L2IE.js → chunk-4BDSO4PQ.js} +2 -2
- package/dist/{chunk-KZGSXJKU.js → chunk-4VDDYI6P.js} +4 -4
- package/dist/{chunk-LKIABZNR.js → chunk-5SJBSCG2.js} +3 -3
- package/dist/{chunk-MHOJJYDK.js → chunk-647TQE3E.js} +2 -2
- package/dist/chunk-6OO5C5GW.js +32 -0
- package/dist/chunk-6OO5C5GW.js.map +1 -0
- package/dist/{chunk-UOGM62JL.js → chunk-7TUAAGVR.js} +3 -3
- package/dist/{chunk-RT5LUEO3.js → chunk-A3DGCDGF.js} +11 -11
- package/dist/{chunk-J4SINPUA.js → chunk-B57NNDEF.js} +23 -11
- package/dist/chunk-B57NNDEF.js.map +1 -0
- package/dist/{chunk-B47EXUHL.js → chunk-CJKGTEN4.js} +2 -2
- package/dist/{chunk-HP34GRQX.js → chunk-E44DRLUL.js} +2 -2
- package/dist/{chunk-T4KS577P.js → chunk-FSBDE6RF.js} +7 -6
- package/dist/chunk-FSBDE6RF.js.map +1 -0
- package/dist/{chunk-F3E2RLC7.js → chunk-GE46NHN4.js} +3 -3
- package/dist/{chunk-CKKNO4XB.js → chunk-GSVOMQEE.js} +2 -2
- package/dist/{chunk-IDNL6IH4.js → chunk-HJ6KTQTZ.js} +7 -1
- package/dist/chunk-HJ6KTQTZ.js.map +1 -0
- package/dist/{chunk-T4IAJJUU.js → chunk-IYDGPF3C.js} +3 -3
- package/dist/{chunk-PPJ7SYQL.js → chunk-JMNIWUFV.js} +3 -3
- package/dist/{chunk-72LBHKYP.js → chunk-JWD43K7W.js} +2 -2
- package/dist/{chunk-MNYMLWWA.js → chunk-KNZNSNP4.js} +2 -2
- package/dist/{chunk-4S4OECPW.js → chunk-KRUDSNFN.js} +11 -11
- package/dist/{chunk-O6DTOCBM.js → chunk-KX2TRKO2.js} +2 -2
- package/dist/{chunk-BDDC72GF.js → chunk-LJGQ6VQB.js} +2 -2
- package/dist/chunk-NMPDZTBM.js +1 -0
- package/dist/chunk-NMPDZTBM.js.map +1 -0
- package/dist/{chunk-6N4ENZO4.js → chunk-OYHU4HNC.js} +2 -2
- package/dist/{chunk-Y7JTHNCU.js → chunk-RFFOL6ON.js} +2 -2
- package/dist/{chunk-47NTHIVB.js → chunk-SCFWN3T2.js} +2 -1
- package/dist/chunk-SCFWN3T2.js.map +1 -0
- package/dist/{chunk-QUS6S2NB.js → chunk-SIXS4CCU.js} +2 -2
- package/dist/{chunk-IV6YQTY2.js → chunk-T3ZOZEAB.js} +2 -2
- package/dist/{chunk-AOG6KSV4.js → chunk-T4UW4SUK.js} +3 -3
- package/dist/{chunk-BUPC72Y2.js → chunk-V5DWNXVH.js} +3 -3
- package/dist/{chunk-SIYZDPVH.js → chunk-VKRGWGA4.js} +39 -30
- package/dist/chunk-VKRGWGA4.js.map +1 -0
- package/dist/{chunk-5FCZ64HM.js → chunk-WCWSPU74.js} +3 -3
- package/dist/{chunk-XV3DH5GC.js → chunk-Y365ABZY.js} +5 -5
- package/dist/{chunk-BDKFFFVX.js → chunk-YMTBHHLQ.js} +64 -15
- package/dist/chunk-YMTBHHLQ.js.map +1 -0
- package/dist/{chunk-XJRNBTIV.js → chunk-YNA3UR42.js} +2 -2
- package/dist/chunk-YOLOFTAY.js +144 -0
- package/dist/chunk-YOLOFTAY.js.map +1 -0
- package/dist/{chunk-TIZGADU4.js → chunk-ZGDUEOSH.js} +7 -7
- package/dist/{chunk-TIZGADU4.js.map → chunk-ZGDUEOSH.js.map} +1 -1
- package/dist/completion/generate-completion.js +6 -4
- package/dist/completion/index.d.ts +3 -4
- package/dist/completion/index.js +6 -4
- package/dist/completion/stream-accumulator.js +2 -2
- package/dist/completion/types.js +1 -1
- package/dist/{dynamic-tools-CNHSPXr1.d.ts → dynamic-tools-BXXLc34l.d.ts} +3 -3
- package/dist/evals/advanced-metrics.js +9 -7
- package/dist/evals/cli.js +8 -6
- package/dist/evals/index.d.ts +5 -5
- package/dist/evals/index.js +12 -10
- package/dist/evals/judge.js +8 -6
- package/dist/evals/metrics.js +8 -6
- package/dist/evals/runner.js +7 -5
- package/dist/extractor/extractor.js +7 -5
- package/dist/extractor/index.d.ts +1 -1
- package/dist/extractor/index.js +7 -5
- package/dist/guardrails/index.d.ts +4 -4
- package/dist/image-generation/index.d.ts +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.js +44 -38
- package/dist/internal/agent-runtime/agent-run.js +20 -18
- package/dist/internal/agent-runtime/continuation-state.js +6 -4
- package/dist/internal/agent-runtime/interaction-suspension.js +6 -4
- package/dist/internal/agent-runtime/memory.js +8 -6
- package/dist/internal/agent-runtime/prepared-tool-call.js +2 -2
- package/dist/internal/agent-runtime/retrieval.js +5 -5
- package/dist/internal/agent-runtime/tool-execution.js +16 -14
- package/dist/internal/agent.d.ts +45 -12
- package/dist/internal/agent.js +25 -23
- package/dist/internal/completion-request.js +2 -2
- package/dist/internal/team-runtime/member.js +7 -5
- package/dist/internal/team-runtime/run.js +28 -26
- package/dist/internal/team-runtime/tools.js +4 -4
- package/dist/mcp/index.d.ts +4 -4
- package/dist/memory/compaction.js +7 -5
- package/dist/memory/index.d.ts +3 -3
- package/dist/memory/index.js +7 -5
- package/dist/{middleware-CWjnMbiH.d.ts → middleware-DORuwSy-.d.ts} +67 -4
- package/dist/observability/group.js +7 -5
- package/dist/observability/index.d.ts +5 -5
- package/dist/observability/index.js +7 -5
- package/dist/pipeline/index.d.ts +10 -10
- package/dist/pipeline/index.js +8 -6
- package/dist/pipeline/pipeline.js +8 -6
- package/dist/provider-output-error-CQD0MWey.d.ts +221 -0
- package/dist/schema/index.js +7 -0
- package/dist/schema/standard-json-schema.js +10 -0
- package/dist/schema/standard-json-schema.js.map +1 -0
- package/dist/schema/standard-schema.js +11 -0
- package/dist/schema/standard-schema.js.map +1 -0
- package/dist/skills/index.d.ts +4 -4
- package/dist/skills/index.js +12 -12
- package/dist/skills/load.js +11 -11
- package/dist/skills/tools.js +10 -10
- package/dist/speech-generation/index.d.ts +1 -1
- package/dist/speech-generation/index.js +1 -1
- package/dist/{text-GbW4WYMg.d.ts → text-CklbSG7K.d.ts} +1 -1
- package/dist/{think-tool-YWsV98I5.d.ts → think-tool-2unWbq1w.d.ts} +1 -1
- package/dist/tool/create-tool.js +3 -3
- package/dist/tool/dynamic-tools.js +6 -6
- package/dist/tool/index.d.ts +8 -8
- package/dist/tool/index.js +11 -11
- package/dist/tool/question-tool.js +4 -4
- package/dist/tool/think-tool.js +4 -4
- package/dist/tool/tool.js +1 -1
- package/dist/{tool-DQMZpZSS.d.ts → tool-D_jV3cRZ.d.ts} +38 -1
- package/dist/transcription/index.d.ts +1 -1
- package/dist/{types-DfRPfehE.d.ts → types-0t3BczrD.d.ts} +2 -2
- package/dist/{types-CODGMHnp.d.ts → types-ChyQISt-.d.ts} +1 -1
- package/dist/{types-Bqw0AuFl.d.ts → types-CqiX-4_C.d.ts} +1 -1
- package/dist/{types-C1xYKXF2.d.ts → types-Cu2tEf3V.d.ts} +1 -1
- package/dist/{types-CiHjqE6J.d.ts → types-DYqZKDA8.d.ts} +140 -0
- package/dist/{types-CafU6Ux5.d.ts → types-DhWxTobb.d.ts} +37 -1
- package/dist/vector-store/index.d.ts +4 -4
- package/dist/vector-store/index.js +8 -8
- package/package.json +9 -1
- package/dist/chunk-47NTHIVB.js.map +0 -1
- package/dist/chunk-BDKFFFVX.js.map +0 -1
- package/dist/chunk-IDNL6IH4.js.map +0 -1
- package/dist/chunk-J4SINPUA.js.map +0 -1
- package/dist/chunk-SIYZDPVH.js.map +0 -1
- package/dist/chunk-T4KS577P.js.map +0 -1
- package/dist/provider-output-error-OQ4fjw5W.d.ts +0 -107
- /package/dist/{chunk-UTAB3XQI.js.map → chunk-2JZV4LUS.js.map} +0 -0
- /package/dist/{chunk-G336L2IE.js.map → chunk-4BDSO4PQ.js.map} +0 -0
- /package/dist/{chunk-KZGSXJKU.js.map → chunk-4VDDYI6P.js.map} +0 -0
- /package/dist/{chunk-LKIABZNR.js.map → chunk-5SJBSCG2.js.map} +0 -0
- /package/dist/{chunk-MHOJJYDK.js.map → chunk-647TQE3E.js.map} +0 -0
- /package/dist/{chunk-UOGM62JL.js.map → chunk-7TUAAGVR.js.map} +0 -0
- /package/dist/{chunk-RT5LUEO3.js.map → chunk-A3DGCDGF.js.map} +0 -0
- /package/dist/{chunk-B47EXUHL.js.map → chunk-CJKGTEN4.js.map} +0 -0
- /package/dist/{chunk-HP34GRQX.js.map → chunk-E44DRLUL.js.map} +0 -0
- /package/dist/{chunk-F3E2RLC7.js.map → chunk-GE46NHN4.js.map} +0 -0
- /package/dist/{chunk-CKKNO4XB.js.map → chunk-GSVOMQEE.js.map} +0 -0
- /package/dist/{chunk-T4IAJJUU.js.map → chunk-IYDGPF3C.js.map} +0 -0
- /package/dist/{chunk-PPJ7SYQL.js.map → chunk-JMNIWUFV.js.map} +0 -0
- /package/dist/{chunk-72LBHKYP.js.map → chunk-JWD43K7W.js.map} +0 -0
- /package/dist/{chunk-MNYMLWWA.js.map → chunk-KNZNSNP4.js.map} +0 -0
- /package/dist/{chunk-4S4OECPW.js.map → chunk-KRUDSNFN.js.map} +0 -0
- /package/dist/{chunk-O6DTOCBM.js.map → chunk-KX2TRKO2.js.map} +0 -0
- /package/dist/{chunk-BDDC72GF.js.map → chunk-LJGQ6VQB.js.map} +0 -0
- /package/dist/{chunk-6N4ENZO4.js.map → chunk-OYHU4HNC.js.map} +0 -0
- /package/dist/{chunk-Y7JTHNCU.js.map → chunk-RFFOL6ON.js.map} +0 -0
- /package/dist/{chunk-QUS6S2NB.js.map → chunk-SIXS4CCU.js.map} +0 -0
- /package/dist/{chunk-IV6YQTY2.js.map → chunk-T3ZOZEAB.js.map} +0 -0
- /package/dist/{chunk-AOG6KSV4.js.map → chunk-T4UW4SUK.js.map} +0 -0
- /package/dist/{chunk-BUPC72Y2.js.map → chunk-V5DWNXVH.js.map} +0 -0
- /package/dist/{chunk-5FCZ64HM.js.map → chunk-WCWSPU74.js.map} +0 -0
- /package/dist/{chunk-XV3DH5GC.js.map → chunk-Y365ABZY.js.map} +0 -0
- /package/dist/{chunk-XJRNBTIV.js.map → chunk-YNA3UR42.js.map} +0 -0
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
import { M as ModelCallOptions } from './model-call-options-CZkSw_xN.js';
|
|
2
2
|
|
|
3
3
|
type JsonPrimitive = string | number | boolean | null;
|
|
4
|
+
/** Any JSON-compatible value: primitives, objects, or readonly arrays of JSON values. */
|
|
4
5
|
type JsonValue = JsonPrimitive | JsonObject | readonly JsonValue[];
|
|
5
6
|
type JsonObject = {
|
|
6
7
|
[key: string]: JsonValue;
|
|
7
8
|
};
|
|
9
|
+
/** A retrievable text document passed to a completion as grounding context. */
|
|
8
10
|
type Document = {
|
|
9
11
|
id: string;
|
|
10
12
|
text: string;
|
|
13
|
+
/** String metadata rendered as a `<metadata ... />` header above the text when documents are serialized into prompts. */
|
|
11
14
|
additionalProps?: Record<string, string>;
|
|
12
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* A text segment, optionally carrying a provider reasoning signature.
|
|
18
|
+
*/
|
|
13
19
|
type TextPart = Readonly<{
|
|
14
20
|
type: "text";
|
|
15
21
|
text: string;
|
|
22
|
+
/** Provider signature preserved so reasoning can be replayed on later turns. */
|
|
16
23
|
signature?: string;
|
|
17
24
|
}>;
|
|
25
|
+
/** Image input fidelity hint forwarded to providers that support it. */
|
|
18
26
|
type ImageDetail = "auto" | "low" | "high";
|
|
27
|
+
/**
|
|
28
|
+
* File payload for image/file parts: a remote URL, base64 data, or literal text
|
|
29
|
+
* interpreted as a document.
|
|
30
|
+
*/
|
|
19
31
|
type FileData = Readonly<{
|
|
20
32
|
type: "url";
|
|
21
33
|
url: string;
|
|
@@ -26,6 +38,7 @@ type FileData = Readonly<{
|
|
|
26
38
|
type: "text";
|
|
27
39
|
text: string;
|
|
28
40
|
}>;
|
|
41
|
+
/** Image input with an optional media type override and detail hint. */
|
|
29
42
|
type ImagePart = Readonly<{
|
|
30
43
|
type: "image";
|
|
31
44
|
image: Exclude<FileData, Readonly<{
|
|
@@ -35,18 +48,27 @@ type ImagePart = Readonly<{
|
|
|
35
48
|
mediaType?: string;
|
|
36
49
|
detail?: ImageDetail;
|
|
37
50
|
}>;
|
|
51
|
+
/** Document/file input part; non-text data is rejected by models without `documentInput`. */
|
|
38
52
|
type FilePart = Readonly<{
|
|
39
53
|
type: "file";
|
|
40
54
|
data: FileData;
|
|
41
55
|
mediaType: string;
|
|
42
56
|
filename?: string;
|
|
43
57
|
}>;
|
|
58
|
+
/** Model reasoning content, replayable across turns to preserve thinking state. */
|
|
44
59
|
type ReasoningPart = Readonly<{
|
|
45
60
|
type: "reasoning";
|
|
46
61
|
text: string;
|
|
47
62
|
id?: string;
|
|
48
63
|
details?: readonly ReasoningDetail[];
|
|
49
64
|
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Reasoning detail variants:
|
|
67
|
+
*
|
|
68
|
+
* - `text` / `summary`: displayable reasoning text
|
|
69
|
+
* - `encrypted` / `redacted`: opaque payloads that can only be echoed back to
|
|
70
|
+
* the provider; their content is not readable by the application
|
|
71
|
+
*/
|
|
50
72
|
type ReasoningDetail = Readonly<{
|
|
51
73
|
type: "text";
|
|
52
74
|
text: string;
|
|
@@ -62,6 +84,7 @@ type ReasoningDetail = Readonly<{
|
|
|
62
84
|
data: string;
|
|
63
85
|
}>;
|
|
64
86
|
type ReasoningContentType = ReasoningDetail["type"];
|
|
87
|
+
/** A tool call requested by the model; `signature` preserves provider replay state. */
|
|
65
88
|
type ToolCallPart = Readonly<{
|
|
66
89
|
type: "tool-call";
|
|
67
90
|
toolCallId: string;
|
|
@@ -70,7 +93,17 @@ type ToolCallPart = Readonly<{
|
|
|
70
93
|
input: JsonValue;
|
|
71
94
|
signature?: string;
|
|
72
95
|
}>;
|
|
96
|
+
/** The content variants allowed inside a tool result payload. */
|
|
73
97
|
type ToolResultContentPart = TextPart | FilePart;
|
|
98
|
+
/**
|
|
99
|
+
* Outcome of one tool execution, as recorded in tool messages:
|
|
100
|
+
*
|
|
101
|
+
* - `text` / `json`: successful result as plain text or JSON
|
|
102
|
+
* - `content`: successful result as mixed content parts
|
|
103
|
+
* - `execution-denied`: the call was blocked (e.g. by a required approval)
|
|
104
|
+
* - `error-text` / `error-json`: failure surfaced to the model so the run can
|
|
105
|
+
* continue instead of aborting
|
|
106
|
+
*/
|
|
74
107
|
type ToolResultOutput = Readonly<{
|
|
75
108
|
type: "text";
|
|
76
109
|
value: string;
|
|
@@ -90,6 +123,7 @@ type ToolResultOutput = Readonly<{
|
|
|
90
123
|
type: "error-json";
|
|
91
124
|
value: JsonValue;
|
|
92
125
|
}>;
|
|
126
|
+
/** Tool result reported back to the model, matched to its call via `toolCallId`. */
|
|
93
127
|
type ToolResultPart = Readonly<{
|
|
94
128
|
type: "tool-result";
|
|
95
129
|
toolCallId: string;
|
|
@@ -97,6 +131,7 @@ type ToolResultPart = Readonly<{
|
|
|
97
131
|
toolName: string;
|
|
98
132
|
output: ToolResultOutput;
|
|
99
133
|
}>;
|
|
134
|
+
/** Human decision on a tool call that required approval before execution. */
|
|
100
135
|
type ToolApprovalResponsePart = Readonly<{
|
|
101
136
|
type: "tool-approval-response";
|
|
102
137
|
interactionId: string;
|
|
@@ -106,10 +141,12 @@ type ToolApprovalResponsePart = Readonly<{
|
|
|
106
141
|
approved: boolean;
|
|
107
142
|
reason?: string;
|
|
108
143
|
}>;
|
|
144
|
+
/** Answer to one question asked by a tool suspended on a human interaction. */
|
|
109
145
|
type ToolQuestionAnswer = Readonly<{
|
|
110
146
|
questionId: string;
|
|
111
147
|
value: string;
|
|
112
148
|
}>;
|
|
149
|
+
/** Answers to tool questions, delivered back through the suspended run. */
|
|
113
150
|
type ToolQuestionResponsePart = Readonly<{
|
|
114
151
|
type: "tool-question-response";
|
|
115
152
|
interactionId: string;
|
|
@@ -118,8 +155,11 @@ type ToolQuestionResponsePart = Readonly<{
|
|
|
118
155
|
toolName: string;
|
|
119
156
|
answers: readonly ToolQuestionAnswer[];
|
|
120
157
|
}>;
|
|
158
|
+
/** A tool or human-interaction response delivered inside a `role: "tool"` message. */
|
|
121
159
|
type ToolInteractionResponsePart = ToolApprovalResponsePart | ToolQuestionResponsePart;
|
|
160
|
+
/** Content parts allowed in user messages. */
|
|
122
161
|
type UserContentPart = TextPart | ImagePart | FilePart;
|
|
162
|
+
/** Content parts allowed in assistant messages, including replayed reasoning and tool calls. */
|
|
123
163
|
type AssistantContentPart = TextPart | ImagePart | FilePart | ReasoningPart | ToolCallPart;
|
|
124
164
|
type SystemMessage<Metadata extends JsonObject = JsonObject> = Readonly<{
|
|
125
165
|
role: "system";
|
|
@@ -142,12 +182,25 @@ type ToolMessage<Metadata extends JsonObject = JsonObject> = Readonly<{
|
|
|
142
182
|
content: readonly (ToolResultPart | ToolInteractionResponsePart)[];
|
|
143
183
|
metadata?: Metadata;
|
|
144
184
|
}>;
|
|
185
|
+
/**
|
|
186
|
+
* A conversation message from the system, user, assistant, or tool role.
|
|
187
|
+
*
|
|
188
|
+
* Framework-generated metadata (provider, model, usage of the generation that
|
|
189
|
+
* produced an assistant message) is stored under the `anvia` key of `metadata`;
|
|
190
|
+
* read it back with {@link getAssistantGenerationMetadata}.
|
|
191
|
+
*/
|
|
145
192
|
type Message<Metadata extends JsonObject = JsonObject> = SystemMessage<Metadata> | UserMessage<Metadata> | AssistantMessage<Metadata> | ToolMessage<Metadata>;
|
|
193
|
+
/** Joins the human-readable text of a reasoning part or its details. */
|
|
146
194
|
declare function reasoningDisplayText(reasoning: ReasoningPart | readonly ReasoningDetail[]): string;
|
|
195
|
+
/**
|
|
196
|
+
* How the model may call tools: freely, mandatorily, never, or a named function.
|
|
197
|
+
* Requires the model's `toolChoice` capability.
|
|
198
|
+
*/
|
|
147
199
|
type ToolChoice = "auto" | "required" | "none" | {
|
|
148
200
|
type: "function";
|
|
149
201
|
name: string;
|
|
150
202
|
};
|
|
203
|
+
/** JSON Schema-shaped tool description sent to the model (a local tool's public face). */
|
|
151
204
|
type ToolDefinition = {
|
|
152
205
|
name: string;
|
|
153
206
|
description: string;
|
|
@@ -166,7 +219,9 @@ type ProviderTool = {
|
|
|
166
219
|
configuration?: JsonObject;
|
|
167
220
|
};
|
|
168
221
|
type CompletionTool = ToolDefinition | ProviderTool;
|
|
222
|
+
/** Narrows an unknown value to a well-formed {@link ProviderTool}. */
|
|
169
223
|
declare function isProviderTool(value: unknown): value is ProviderTool;
|
|
224
|
+
/** A grounding source (e.g. web result) returned by the provider, with optional text offsets. */
|
|
170
225
|
type CompletionSource = {
|
|
171
226
|
type: "url";
|
|
172
227
|
url: string;
|
|
@@ -175,6 +230,7 @@ type CompletionSource = {
|
|
|
175
230
|
startIndex?: number;
|
|
176
231
|
endIndex?: number;
|
|
177
232
|
};
|
|
233
|
+
/** A tool call executed on the provider side, surfaced for observability. */
|
|
178
234
|
type ProviderToolCall = {
|
|
179
235
|
id: string;
|
|
180
236
|
name: string;
|
|
@@ -188,15 +244,18 @@ type ProviderToolCall = {
|
|
|
188
244
|
* only aggregate key and should equal the sum of the other buckets.
|
|
189
245
|
*/
|
|
190
246
|
type UsageDetails = Record<string, number>;
|
|
247
|
+
/** Model context window bounds; unset input/output caps fall back to the window. */
|
|
191
248
|
type ModelContextLimits = {
|
|
192
249
|
contextWindow: number;
|
|
193
250
|
maxInputTokens?: number;
|
|
194
251
|
maxOutputTokens?: number;
|
|
195
252
|
};
|
|
253
|
+
/** Identifies a model together with its context limits. */
|
|
196
254
|
type CompletionModelInfo = {
|
|
197
255
|
modelId: string;
|
|
198
256
|
context: ModelContextLimits;
|
|
199
257
|
};
|
|
258
|
+
/** Snapshot of how much of a model's context window a request consumed. */
|
|
200
259
|
type ContextUsage = {
|
|
201
260
|
model: CompletionModelInfo;
|
|
202
261
|
usedTokens: number;
|
|
@@ -204,9 +263,13 @@ type ContextUsage = {
|
|
|
204
263
|
usedPercent: number;
|
|
205
264
|
remainingPercent: number;
|
|
206
265
|
};
|
|
266
|
+
/** Computes context usage, or undefined when the model or usage data is unusable. */
|
|
207
267
|
declare function calculateContextUsage(usage: Usage, model: CompletionModelInfo | undefined): ContextUsage | undefined;
|
|
268
|
+
/** Attaches context usage to a response when model limits are known. */
|
|
208
269
|
declare function withContextUsage<RawResponse>(response: CompletionResponse<RawResponse>, model: CompletionModelInfo | undefined): CompletionResponse<RawResponse>;
|
|
270
|
+
/** Resolves a model's context limits: explicit override wins over catalog lookup. */
|
|
209
271
|
declare function resolveModelContextLimits(modelId: string, catalog: Readonly<Record<string, ModelContextLimits>>, override?: ModelContextLimits): ModelContextLimits | undefined;
|
|
272
|
+
/** Provider/model/usage metadata embedded in assistant message metadata by the runtime. */
|
|
210
273
|
type AssistantGenerationMetadata = {
|
|
211
274
|
provider: string;
|
|
212
275
|
modelId: string;
|
|
@@ -217,6 +280,13 @@ type AssistantGenerationMetadata = {
|
|
|
217
280
|
sources?: CompletionSource[];
|
|
218
281
|
providerToolCalls?: ProviderToolCall[];
|
|
219
282
|
};
|
|
283
|
+
/**
|
|
284
|
+
* Token usage for one or more generations.
|
|
285
|
+
*
|
|
286
|
+
* `cachedInputTokens` counts input tokens served from the provider's prompt
|
|
287
|
+
* cache; `cacheCreationInputTokens` counts input tokens billed for writing to
|
|
288
|
+
* that cache. Both are subsets of `inputTokens`.
|
|
289
|
+
*/
|
|
220
290
|
type Usage = {
|
|
221
291
|
inputTokens: number;
|
|
222
292
|
outputTokens: number;
|
|
@@ -225,12 +295,26 @@ type Usage = {
|
|
|
225
295
|
cacheCreationInputTokens: number;
|
|
226
296
|
details?: UsageDetails;
|
|
227
297
|
};
|
|
298
|
+
/**
|
|
299
|
+
* Helpers for constructing and combining token usage.
|
|
300
|
+
*/
|
|
228
301
|
declare const Usage: {
|
|
302
|
+
/** Returns an all-zero usage value. */
|
|
229
303
|
empty(): Usage;
|
|
304
|
+
/**
|
|
305
|
+
* Sums two usage values bucket by bucket. `details` are merged only when
|
|
306
|
+
* both sides carry them; if either side omits them, the result omits them.
|
|
307
|
+
*/
|
|
230
308
|
add(left: Usage, right: Usage): Usage;
|
|
309
|
+
/** Returns true when every bucket, including `details`, is zero. */
|
|
231
310
|
isEmpty(usage: Usage): boolean;
|
|
232
311
|
};
|
|
312
|
+
/**
|
|
313
|
+
* Reads the generation metadata the runtime embeds in assistant messages, when
|
|
314
|
+
* present and structurally valid.
|
|
315
|
+
*/
|
|
233
316
|
declare function getAssistantGenerationMetadata(message: Message): AssistantGenerationMetadata | undefined;
|
|
317
|
+
/** Provider-agnostic completion request assembled by the runtime for adapters. */
|
|
234
318
|
type CompletionRequest = {
|
|
235
319
|
instructions?: string;
|
|
236
320
|
chatHistory: Message[];
|
|
@@ -240,25 +324,45 @@ type CompletionRequest = {
|
|
|
240
324
|
temperature?: number;
|
|
241
325
|
maxTokens?: number;
|
|
242
326
|
toolChoice?: ToolChoice;
|
|
327
|
+
/** Values for the model's declared completion controls; validated before sending. */
|
|
243
328
|
controls?: Readonly<Record<string, string>>;
|
|
329
|
+
/** Provider-specific passthrough options; never validated by the core runtime. */
|
|
244
330
|
providerOptions?: JsonObject;
|
|
331
|
+
/** JSON Schema the output must conform to; requires the `outputSchema` capability. */
|
|
245
332
|
outputSchema?: JsonObject;
|
|
246
333
|
};
|
|
334
|
+
/** Normalized finish reasons:
|
|
335
|
+
*
|
|
336
|
+
* - `stop`: the model finished naturally
|
|
337
|
+
* - `length`: an output token limit was hit
|
|
338
|
+
* - `content-filter`: output was blocked by a safety filter
|
|
339
|
+
* - `tool-calls`: the model stopped to request tool calls
|
|
340
|
+
* - `other`: any provider-specific reason
|
|
341
|
+
*/
|
|
247
342
|
type CompletionFinishReason = "stop" | "length" | "content-filter" | "tool-calls" | "other";
|
|
343
|
+
/** A provider's raw completion response: normalized parts plus usage and metadata. */
|
|
248
344
|
type CompletionResponse<RawResponse = unknown> = {
|
|
249
345
|
choice: AssistantContentPart[];
|
|
250
346
|
usage: Usage;
|
|
251
347
|
finishReason?: CompletionFinishReason;
|
|
252
348
|
providerFinishReason?: string;
|
|
253
349
|
contextUsage?: ContextUsage;
|
|
350
|
+
/** The provider SDK's original response object, unmodified. */
|
|
254
351
|
rawResponse: RawResponse;
|
|
255
352
|
messageId?: string;
|
|
256
353
|
sources?: CompletionSource[];
|
|
257
354
|
providerToolCalls?: ProviderToolCall[];
|
|
258
355
|
};
|
|
356
|
+
/** Final result of a completion: typed output, plain text, full content, and usage. */
|
|
259
357
|
type CompletionResult<Output = string, RawResponse = unknown> = {
|
|
358
|
+
/**
|
|
359
|
+
* The typed output. When an output schema was requested this is the parsed,
|
|
360
|
+
* validated object; otherwise it is the plain text.
|
|
361
|
+
*/
|
|
260
362
|
output: Output;
|
|
363
|
+
/** The generated text, joined from the response's text parts. */
|
|
261
364
|
text: string;
|
|
365
|
+
/** Every content part the model produced, including reasoning and tool calls. */
|
|
262
366
|
content: readonly AssistantContentPart[];
|
|
263
367
|
usage: Usage;
|
|
264
368
|
finishReason?: CompletionFinishReason;
|
|
@@ -269,6 +373,7 @@ type CompletionResult<Output = string, RawResponse = unknown> = {
|
|
|
269
373
|
sources?: readonly CompletionSource[];
|
|
270
374
|
providerToolCalls?: readonly ProviderToolCall[];
|
|
271
375
|
};
|
|
376
|
+
/** Feature flags a model declares; requests are validated against these at runtime. */
|
|
272
377
|
type CompletionModelCapabilities = {
|
|
273
378
|
streaming: boolean;
|
|
274
379
|
tools: boolean;
|
|
@@ -279,6 +384,7 @@ type CompletionModelCapabilities = {
|
|
|
279
384
|
reasoning: boolean;
|
|
280
385
|
providerTools?: boolean;
|
|
281
386
|
};
|
|
387
|
+
/** A selectable model control exposed to applications (e.g. "reasoning effort"). */
|
|
282
388
|
type CompletionModelSelectControl<Option extends string = string> = Readonly<{
|
|
283
389
|
type: "select";
|
|
284
390
|
label: string;
|
|
@@ -286,24 +392,50 @@ type CompletionModelSelectControl<Option extends string = string> = Readonly<{
|
|
|
286
392
|
description?: string | undefined;
|
|
287
393
|
defaultValue?: Option | undefined;
|
|
288
394
|
}>;
|
|
395
|
+
/** Named set of controls a model supports, keyed by control id. */
|
|
289
396
|
type CompletionModelControls = Readonly<Record<string, CompletionModelSelectControl<string>>>;
|
|
397
|
+
/** Marker type for models that accept no completion controls. */
|
|
290
398
|
type NoCompletionModelControls = Readonly<Record<string, never>>;
|
|
399
|
+
/** The option values a model's controls accept, keyed by control id. */
|
|
291
400
|
type CompletionControlValues<Controls extends CompletionModelControls> = Readonly<Partial<{
|
|
292
401
|
[Key in keyof Controls]: Controls[Key] extends CompletionModelSelectControl<infer Option> ? Option : never;
|
|
293
402
|
}>>;
|
|
403
|
+
/** Extracts a model's control types, defaulting to the open controls record. */
|
|
294
404
|
type CompletionModelControlsOf<Model> = Model extends CompletionModel<unknown, infer Controls> ? Controls : CompletionModelControls;
|
|
405
|
+
/**
|
|
406
|
+
* The provider-agnostic model contract every adapter implements: non-streaming
|
|
407
|
+
* completions plus capability, context, and control metadata.
|
|
408
|
+
*/
|
|
295
409
|
interface CompletionModel<RawResponse = unknown, Controls extends CompletionModelControls = CompletionModelControls> {
|
|
296
410
|
readonly provider: string;
|
|
297
411
|
readonly modelId: string;
|
|
298
412
|
readonly contextLimits?: ModelContextLimits | undefined;
|
|
299
413
|
readonly capabilities: CompletionModelCapabilities;
|
|
300
414
|
readonly controls?: Controls | undefined;
|
|
415
|
+
/**
|
|
416
|
+
* Returns a JSON-safe representation of the outgoing request for
|
|
417
|
+
* observability traces, or undefined to omit the trace payload. Errors
|
|
418
|
+
* thrown here are swallowed by the runtime and recorded as a trace error.
|
|
419
|
+
*/
|
|
301
420
|
traceRequest?(request: CompletionRequest, options?: {
|
|
302
421
|
stream?: boolean | undefined;
|
|
303
422
|
}): JsonObject | undefined;
|
|
304
423
|
completion(request: CompletionRequest, options?: ModelCallOptions): Promise<CompletionResponse<RawResponse>>;
|
|
305
424
|
}
|
|
425
|
+
/** How a `tool_call_delta` updates arguments: append to, or replace, accumulated JSON. */
|
|
306
426
|
type ToolCallArgumentsMode = "append" | "replace";
|
|
427
|
+
/**
|
|
428
|
+
* Incremental completion stream content:
|
|
429
|
+
*
|
|
430
|
+
* - `text_delta` / `reasoning_delta`: incremental text or reasoning content
|
|
431
|
+
* - `tool_call_delta`: partial tool call input; argument fragments accumulate
|
|
432
|
+
* according to `argumentsMode` (`append` continues the JSON string, `replace`
|
|
433
|
+
* restarts it)
|
|
434
|
+
* - `tool_call`: a complete tool call
|
|
435
|
+
* - `source`: a grounding source discovered during generation
|
|
436
|
+
* - `provider_tool_call`: progress on a provider-executed tool
|
|
437
|
+
* - `message_id`: the id of the message being generated
|
|
438
|
+
*/
|
|
307
439
|
type CompletionStreamPart = {
|
|
308
440
|
type: "text_delta";
|
|
309
441
|
delta: string;
|
|
@@ -312,6 +444,7 @@ type CompletionStreamPart = {
|
|
|
312
444
|
delta: string;
|
|
313
445
|
id?: string;
|
|
314
446
|
contentType?: ReasoningContentType;
|
|
447
|
+
/** Provider signature preserved for reasoning replay. */
|
|
315
448
|
signature?: string;
|
|
316
449
|
} | {
|
|
317
450
|
type: "tool_call_delta";
|
|
@@ -334,6 +467,7 @@ type CompletionStreamPart = {
|
|
|
334
467
|
type: "message_id";
|
|
335
468
|
id: string;
|
|
336
469
|
};
|
|
470
|
+
/** Raw model stream events: stream parts, the final response, or a terminal error. */
|
|
337
471
|
type CompletionModelStreamEvent<RawResponse = unknown> = CompletionStreamPart | {
|
|
338
472
|
type: "final";
|
|
339
473
|
response: CompletionResponse<RawResponse>;
|
|
@@ -342,6 +476,7 @@ type CompletionModelStreamEvent<RawResponse = unknown> = CompletionStreamPart |
|
|
|
342
476
|
error: unknown;
|
|
343
477
|
usage?: Usage;
|
|
344
478
|
};
|
|
479
|
+
/** High-level stream events: stream parts, the final typed result, or a terminal error. */
|
|
345
480
|
type CompletionStreamEvent<Output = string, RawResponse = unknown> = CompletionStreamPart | {
|
|
346
481
|
type: "final";
|
|
347
482
|
result: CompletionResult<Output, RawResponse>;
|
|
@@ -350,16 +485,21 @@ type CompletionStreamEvent<Output = string, RawResponse = unknown> = CompletionS
|
|
|
350
485
|
error: unknown;
|
|
351
486
|
usage: Usage;
|
|
352
487
|
};
|
|
488
|
+
/** A completion model that can additionally stream events as they are produced. */
|
|
353
489
|
interface StreamingCompletionModel<RawResponse = unknown, Controls extends CompletionModelControls = CompletionModelControls> extends CompletionModel<RawResponse, Controls> {
|
|
354
490
|
streamCompletion(request: CompletionRequest, options?: ModelCallOptions): AsyncIterable<CompletionModelStreamEvent<RawResponse>>;
|
|
355
491
|
}
|
|
492
|
+
/** Thrown when a request uses a capability the target model does not declare. */
|
|
356
493
|
declare class CompletionCapabilityError extends Error {
|
|
357
494
|
constructor(message: string);
|
|
358
495
|
}
|
|
496
|
+
/** Validates a request against a model's declared capabilities; throws {@link CompletionCapabilityError}. */
|
|
359
497
|
declare function assertCompletionRequestSupported(model: CompletionModel, request: CompletionRequest, options?: {
|
|
360
498
|
streaming?: boolean | undefined;
|
|
361
499
|
}): void;
|
|
500
|
+
/** Validates control values against a model's controls; throws {@link CompletionCapabilityError}. */
|
|
362
501
|
declare function assertCompletionControlsSupported(model: CompletionModel, controls: Readonly<Record<string, string | undefined>> | undefined): void;
|
|
502
|
+
/** Joins the text parts of assistant content with newlines. */
|
|
363
503
|
declare function textFromAssistantContent(content: readonly AssistantContentPart[]): string;
|
|
364
504
|
|
|
365
505
|
export { type CompletionStreamPart as $, type AssistantContentPart as A, type ToolDefinition as B, type CompletionControlValues as C, type Document as D, type ToolMessage as E, type FileData as F, type ToolResultContentPart as G, type ToolResultOutput as H, type ImageDetail as I, type JsonObject as J, type ToolResultPart as K, type UserContentPart as L, type Message as M, type NoCompletionModelControls as N, type UserMessage as O, type ProviderTool as P, calculateContextUsage as Q, type ReasoningContentType as R, type SystemMessage as S, type TextPart as T, Usage as U, getAssistantGenerationMetadata as V, isProviderTool as W, resolveModelContextLimits as X, withContextUsage as Y, CompletionCapabilityError as Z, type CompletionModelCapabilities as _, type AssistantGenerationMetadata as a, type StreamingCompletionModel as a0, type ToolApprovalResponsePart as a1, type ToolCallArgumentsMode as a2, type ToolInteractionResponsePart as a3, type ToolQuestionAnswer as a4, type ToolQuestionResponsePart as a5, type UsageDetails as a6, assertCompletionControlsSupported as a7, assertCompletionRequestSupported as a8, reasoningDisplayText as a9, textFromAssistantContent as aa, type AssistantMessage as b, type CompletionFinishReason as c, type CompletionModel as d, type CompletionModelControls as e, type CompletionModelControlsOf as f, type CompletionModelInfo as g, type CompletionModelSelectControl as h, type CompletionModelStreamEvent as i, type CompletionRequest as j, type CompletionResponse as k, type CompletionResult as l, type CompletionSource as m, type CompletionStreamEvent as n, type CompletionTool as o, type ContextUsage as p, type FilePart as q, type ImagePart as r, type JsonPrimitive as s, type JsonValue as t, type ModelContextLimits as u, type ProviderToolCall as v, type ReasoningDetail as w, type ReasoningPart as x, type ToolCallPart as y, type ToolChoice as z };
|
|
@@ -1,19 +1,31 @@
|
|
|
1
|
-
import { U as Usage, J as JsonObject, M as Message, S as SystemMessage, d as CompletionModel } from './types-
|
|
1
|
+
import { U as Usage, J as JsonObject, M as Message, S as SystemMessage, d as CompletionModel } from './types-DYqZKDA8.js';
|
|
2
2
|
import { b as RetrySetting } from './retry-CjvSlKGW.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Granularity at which produced messages are persisted:
|
|
6
|
+
*
|
|
7
|
+
* - `message`: after each individual message
|
|
8
|
+
* - `turn`: after each agent turn completes
|
|
9
|
+
* - `run`: once when the run finishes
|
|
10
|
+
*/
|
|
4
11
|
type MemorySavePolicy = "message" | "turn" | "run";
|
|
12
|
+
/** Identifies a conversation within a memory store. */
|
|
5
13
|
type MemoryScope = {
|
|
6
14
|
sessionId: string;
|
|
7
15
|
userId?: string | undefined;
|
|
8
16
|
metadata?: JsonObject | undefined;
|
|
9
17
|
};
|
|
18
|
+
/** Options controlling how a memory scope is reduced to a storage key. */
|
|
10
19
|
type MemoryScopeKeyOptions = {
|
|
20
|
+
/** Includes `scope.userId` in the derived key. */
|
|
11
21
|
includeUserId?: boolean | undefined;
|
|
22
|
+
/** Metadata entries (by key) included in the derived key. */
|
|
12
23
|
metadataKeys?: readonly string[] | undefined;
|
|
13
24
|
};
|
|
14
25
|
type CreateMemoryScopeKeyOptions = MemoryScopeKeyOptions & {
|
|
15
26
|
scope: MemoryScope;
|
|
16
27
|
};
|
|
28
|
+
/** Either key-derivation options or a custom resolver function. */
|
|
17
29
|
type MemoryScopeKeyResolver = MemoryScopeKeyOptions | ((options: {
|
|
18
30
|
scope: MemoryScope;
|
|
19
31
|
}) => string);
|
|
@@ -42,6 +54,7 @@ type MemoryConversationListOptions = {
|
|
|
42
54
|
type MemoryConversationGetOptions = {
|
|
43
55
|
ref: string;
|
|
44
56
|
};
|
|
57
|
+
/** Persisted summary of a stored conversation. */
|
|
45
58
|
type MemoryConversationSummary = {
|
|
46
59
|
/** Opaque, store-specific reference used to retrieve this exact conversation. */
|
|
47
60
|
ref: string;
|
|
@@ -52,6 +65,7 @@ type MemoryConversationSummary = {
|
|
|
52
65
|
updatedAt: string;
|
|
53
66
|
messageCount: number;
|
|
54
67
|
};
|
|
68
|
+
/** One stored message with its position and originating run/turn. */
|
|
55
69
|
type MemoryConversationMessage = {
|
|
56
70
|
position: number;
|
|
57
71
|
runId: string;
|
|
@@ -59,6 +73,7 @@ type MemoryConversationMessage = {
|
|
|
59
73
|
createdAt: string;
|
|
60
74
|
message: Message;
|
|
61
75
|
};
|
|
76
|
+
/** A full stored conversation: summary plus replayable messages. */
|
|
62
77
|
type MemoryConversation = MemoryConversationSummary & {
|
|
63
78
|
messages: MemoryConversationMessage[];
|
|
64
79
|
};
|
|
@@ -67,6 +82,11 @@ interface MemoryInspector {
|
|
|
67
82
|
listConversations(options: MemoryConversationListOptions): Promise<MemoryConversationSummary[]>;
|
|
68
83
|
getConversation(options: MemoryConversationGetOptions): Promise<MemoryConversation | undefined>;
|
|
69
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Append-only conversation storage. The runtime loads history at run start,
|
|
87
|
+
* appends produced messages per the configured {@link MemorySavePolicy}, and
|
|
88
|
+
* clears on demand. `load` must return the canonical, replayable history.
|
|
89
|
+
*/
|
|
70
90
|
interface MemoryStore {
|
|
71
91
|
readonly inspector?: MemoryInspector | undefined;
|
|
72
92
|
readonly compaction?: MemoryCompactionCapability | undefined;
|
|
@@ -74,12 +94,16 @@ interface MemoryStore {
|
|
|
74
94
|
load(options: MemoryLoadOptions): Promise<Message[]>;
|
|
75
95
|
append(options: MemoryAppendOptions): Promise<void>;
|
|
76
96
|
clear(options: MemoryClearOptions): Promise<void>;
|
|
97
|
+
/** Records a failed run for debugging; unsupported stores may omit it. */
|
|
77
98
|
recordError?(options: MemoryErrorOptions): Promise<void>;
|
|
78
99
|
}
|
|
100
|
+
/** Metadata embedded in a compaction summary message. */
|
|
79
101
|
type MemoryCompactionMetadata = {
|
|
102
|
+
/** Schema version of the compaction marker. */
|
|
80
103
|
version: 1;
|
|
81
104
|
compactedMessageCount: number;
|
|
82
105
|
};
|
|
106
|
+
/** A system message that stores a summary checkpoint in the conversation history. */
|
|
83
107
|
type MemoryCompactionMessage = Omit<SystemMessage, "metadata"> & {
|
|
84
108
|
metadata: {
|
|
85
109
|
anvia: {
|
|
@@ -104,6 +128,7 @@ type MemoryCompactionReplacePrefixOptions = {
|
|
|
104
128
|
replacement: MemoryCompactionMessage;
|
|
105
129
|
runId: string;
|
|
106
130
|
};
|
|
131
|
+
/** Result of a prefix replacement: `conflict` means the revision was stale and the replacement was rejected. */
|
|
107
132
|
type MemoryCompactionReplacePrefixResult = {
|
|
108
133
|
status: "committed" | "conflict";
|
|
109
134
|
};
|
|
@@ -126,9 +151,11 @@ type MemoryCompactorResult = {
|
|
|
126
151
|
summary: string;
|
|
127
152
|
usage?: Usage | undefined;
|
|
128
153
|
};
|
|
154
|
+
/** Summarizes a list of messages into a compact replacement. */
|
|
129
155
|
type MemoryCompactor = (input: MemoryCompactorInput) => Promise<MemoryCompactorResult>;
|
|
130
156
|
/** Counts the approximate or exact model tokens represented by a message list. */
|
|
131
157
|
type MemoryTokenCounter = (messages: readonly Message[]) => number | Promise<number>;
|
|
158
|
+
/** Options for the built-in, model-backed summary compactor. */
|
|
132
159
|
type CreateSummaryMemoryCompactorOptions = {
|
|
133
160
|
model: CompletionModel;
|
|
134
161
|
instructions?: string | undefined;
|
|
@@ -140,21 +167,29 @@ type CreateSummaryMemoryCompactorOptions = {
|
|
|
140
167
|
type MemoryCompactionConflictRetryOptions = {
|
|
141
168
|
maxAttempts: number;
|
|
142
169
|
};
|
|
170
|
+
/** When and how session memory is compacted. */
|
|
143
171
|
type MemoryCompactionOptions = {
|
|
144
172
|
trigger: {
|
|
173
|
+
/** Compaction runs when the projected context exceeds this token count. */
|
|
145
174
|
afterTokens: number;
|
|
146
175
|
};
|
|
147
176
|
retention?: {
|
|
177
|
+
/** Messages within this token budget of the end stay unsummarized. */
|
|
148
178
|
recentTokens?: number | undefined;
|
|
149
179
|
};
|
|
180
|
+
/** Overrides the default approximate counter; use a model counter for exact budgets. */
|
|
150
181
|
tokenCounter?: MemoryTokenCounter | undefined;
|
|
151
182
|
compactor: MemoryCompactor;
|
|
183
|
+
/** `false` disables retrying when a store reports a revision conflict. */
|
|
152
184
|
conflictRetries?: false | MemoryCompactionConflictRetryOptions | undefined;
|
|
153
185
|
};
|
|
186
|
+
/** Memory settings for an agent. */
|
|
154
187
|
type MemoryOptions = {
|
|
188
|
+
/** @default "message" */
|
|
155
189
|
savePolicy?: MemorySavePolicy | undefined;
|
|
156
190
|
compaction?: MemoryCompactionOptions | undefined;
|
|
157
191
|
};
|
|
192
|
+
/** Measurements recorded for one compaction attempt. */
|
|
158
193
|
type MemoryCompactionInfo = {
|
|
159
194
|
originalMessageCount: number;
|
|
160
195
|
compactedMessageCount: number;
|
|
@@ -166,6 +201,7 @@ type MemoryCompactionInfo = {
|
|
|
166
201
|
attempts: number;
|
|
167
202
|
usage: Usage;
|
|
168
203
|
};
|
|
204
|
+
/** Outcome of a compaction attempt: performed, or skipped because there was nothing to compact. */
|
|
169
205
|
type MemoryCompactionResult = ({
|
|
170
206
|
type: "compacted";
|
|
171
207
|
} & MemoryCompactionInfo) | {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { V as VectorMetadata, b as VectorMetadataValue, E as EmbeddingModel, a as EmbeddedDocument } from '../types-Cr4uiYo5.js';
|
|
2
|
-
import { T as Tool } from '../tool-
|
|
3
|
-
import { V as VectorFilter, d as VectorStore, R as RetrieveDocumentsOptions, a as VectorSearchResult, f as RetrieveHybridDocumentsOptions, I as IndexStrategy, g as VectorStoreUpsertOptions, h as VectorSearchRequest, b as VectorInspectRequest, c as VectorInspectPage, i as VectorSearchToolOptions } from '../types-
|
|
4
|
-
export { D as DenseVectorSearchToolOptions, j as HybridVectorSearchRequest, k as HybridVectorSearchToolOptions, H as HybridVectorStore, L as LshOptions, l as RetrieveDocumentsBaseOptions, e as VectorFusion, m as VectorInspectItem, n as VectorMetric, o as VectorSearchToolBaseOptions } from '../types-
|
|
2
|
+
import { T as Tool } from '../tool-D_jV3cRZ.js';
|
|
3
|
+
import { V as VectorFilter, d as VectorStore, R as RetrieveDocumentsOptions, a as VectorSearchResult, f as RetrieveHybridDocumentsOptions, I as IndexStrategy, g as VectorStoreUpsertOptions, h as VectorSearchRequest, b as VectorInspectRequest, c as VectorInspectPage, i as VectorSearchToolOptions } from '../types-ChyQISt-.js';
|
|
4
|
+
export { D as DenseVectorSearchToolOptions, j as HybridVectorSearchRequest, k as HybridVectorSearchToolOptions, H as HybridVectorStore, L as LshOptions, l as RetrieveDocumentsBaseOptions, e as VectorFusion, m as VectorInspectItem, n as VectorMetric, o as VectorSearchToolBaseOptions } from '../types-ChyQISt-.js';
|
|
5
5
|
import { b as RetrySetting } from '../retry-CjvSlKGW.js';
|
|
6
|
-
import { J as JsonObject } from '../types-
|
|
6
|
+
import { J as JsonObject } from '../types-DYqZKDA8.js';
|
|
7
7
|
import { T as TextDocument, b as TextDocumentChunkingOptions } from '../text-document-B-X7Vxq1.js';
|
|
8
8
|
import '../model-call-options-CZkSw_xN.js';
|
|
9
9
|
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InMemoryVectorStore,
|
|
3
3
|
createVectorSearchTool
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-JWD43K7W.js";
|
|
5
|
+
import {
|
|
6
|
+
ingestVectorDocuments,
|
|
7
|
+
ingestVectorText
|
|
8
|
+
} from "../chunk-QHGYCYV6.js";
|
|
5
9
|
import "../chunk-ESOFEAYK.js";
|
|
6
10
|
import {
|
|
7
11
|
retrieveDocuments
|
|
@@ -10,10 +14,6 @@ import {
|
|
|
10
14
|
matchesVectorFilter,
|
|
11
15
|
vectorFilter
|
|
12
16
|
} from "../chunk-5WLIHNNJ.js";
|
|
13
|
-
import {
|
|
14
|
-
ingestVectorDocuments,
|
|
15
|
-
ingestVectorText
|
|
16
|
-
} from "../chunk-QHGYCYV6.js";
|
|
17
17
|
import "../chunk-ERN7P6Q4.js";
|
|
18
18
|
import "../chunk-7F53DOML.js";
|
|
19
19
|
import "../chunk-HHMLE3TZ.js";
|
|
@@ -23,10 +23,10 @@ import "../chunk-KO5NMTAM.js";
|
|
|
23
23
|
import "../chunk-TFIOU6UR.js";
|
|
24
24
|
import "../chunk-GPVXCY5I.js";
|
|
25
25
|
import "../chunk-5V533R7F.js";
|
|
26
|
-
import "../chunk-
|
|
26
|
+
import "../chunk-Y365ABZY.js";
|
|
27
|
+
import "../chunk-647TQE3E.js";
|
|
27
28
|
import "../chunk-YZVFIW5D.js";
|
|
28
|
-
import "../chunk-
|
|
29
|
-
import "../chunk-47NTHIVB.js";
|
|
29
|
+
import "../chunk-SCFWN3T2.js";
|
|
30
30
|
import "../chunk-J6S6MT7O.js";
|
|
31
31
|
import "../chunk-BONQTXRQ.js";
|
|
32
32
|
import "../chunk-4C7AXYOM.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anvia/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Core runtime primitives for context-aware Anvia agents.",
|
|
5
5
|
"author": "anvia",
|
|
6
6
|
"license": "MIT",
|
|
@@ -113,12 +113,20 @@
|
|
|
113
113
|
"yaml": "^2.9.0"
|
|
114
114
|
},
|
|
115
115
|
"peerDependencies": {
|
|
116
|
+
"@valibot/to-json-schema": "^1.7.1",
|
|
116
117
|
"zod": "^4.4.0"
|
|
117
118
|
},
|
|
119
|
+
"peerDependenciesMeta": {
|
|
120
|
+
"@valibot/to-json-schema": {
|
|
121
|
+
"optional": true
|
|
122
|
+
}
|
|
123
|
+
},
|
|
118
124
|
"devDependencies": {
|
|
119
125
|
"@types/node": "^24.9.1",
|
|
126
|
+
"@valibot/to-json-schema": "^1.7.1",
|
|
120
127
|
"tsup": "^8.5.0",
|
|
121
128
|
"typescript": "^5.9.3",
|
|
129
|
+
"valibot": "^1.5.0",
|
|
122
130
|
"vitest": "^4.0.8",
|
|
123
131
|
"zod": "^4.5.4"
|
|
124
132
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/tool/tool.ts"],"sourcesContent":["import { isJsonValue } from \"../completion/json\";\nimport { parseMessage } from \"../completion/message-schema\";\nimport type {\n JsonObject,\n JsonValue,\n ToolDefinition,\n ToolResultContentPart,\n ToolResultOutput,\n} from \"../completion/types\";\n\nexport type ToolApprovalRunContext = {\n agentId: string;\n runId: string;\n sessionId?: string;\n metadata?: JsonObject;\n};\n\nexport type ToolApprovalContext<Args = unknown> = {\n toolName: string;\n args: Args;\n rawArgs: string;\n toolCallId: string;\n callId?: string;\n internalCallId: string;\n run: ToolApprovalRunContext;\n};\n\nexport type ToolApprovalRequirement = {\n reason?: string | undefined;\n};\n\nexport type ToolRequiresApproval<Args = unknown> =\n | boolean\n | ToolApprovalRequirement\n | ((\n args: Args,\n context: ToolApprovalContext<Args>,\n ) => boolean | ToolApprovalRequirement | Promise<boolean | ToolApprovalRequirement>);\n\nexport type ToolCallStreamEvent = {\n agentId: string;\n agentName?: string | undefined;\n event: unknown;\n};\n\nexport type ToolCallContext = {\n emitStreamEvent?(event: ToolCallStreamEvent): void | Promise<void>;\n abortSignal?: AbortSignal | undefined;\n};\n\nexport interface Tool<Args = unknown, Output = unknown> {\n readonly name: string;\n readonly requiresApproval?: ToolRequiresApproval<Args>;\n definition(prompt: string): ToolDefinition | Promise<ToolDefinition>;\n call(args: Args, context?: ToolCallContext): Output | Promise<Output>;\n parseInput?(args: JsonValue): Args;\n}\n\nexport type AnyTool = Omit<Tool<unknown, unknown>, \"requiresApproval\"> & {\n readonly requiresApproval?: unknown;\n};\n\nconst richToolOutput: unique symbol = Symbol.for(\"anvia.tool-output.content\");\n\nexport type RichToolOutput = Readonly<{\n [richToolOutput]: true;\n content: readonly ToolResultContentPart[];\n}>;\n\nexport type NormalizedToolOutput = ToolResultOutput;\n\nexport class ToolResultSerializationError extends TypeError {\n constructor(readonly output: unknown) {\n super(\"Tool output must be a string, a strict JSON value, or ToolOutput.content(...).\");\n this.name = \"ToolResultSerializationError\";\n }\n}\n\nexport const ToolOutput = {\n content(content: readonly ToolResultContentPart[]): RichToolOutput {\n return { [richToolOutput]: true, content };\n },\n};\n\nexport function normalizeToolResultOutput(output: unknown): NormalizedToolOutput {\n if (typeof output === \"string\") {\n return { type: \"text\", value: output };\n }\n if (isRichToolOutput(output)) {\n try {\n const message = parseMessage({\n role: \"tool\",\n content: [\n {\n type: \"tool-result\",\n toolCallId: \"validation\",\n toolName: \"validation\",\n output: { type: \"content\", value: output.content },\n },\n ],\n });\n if (message.role !== \"tool\") throw new TypeError(\"Unexpected message role\");\n const result = message.content[0];\n if (result?.type !== \"tool-result\") throw new TypeError(\"Unexpected tool result part\");\n if (result?.output.type !== \"content\") throw new TypeError(\"Unexpected tool output\");\n return result.output;\n } catch {\n throw new ToolResultSerializationError(output);\n }\n }\n if (isJsonValue(output)) {\n return { type: \"json\", value: output };\n }\n throw new ToolResultSerializationError(output);\n}\n\nexport function toolResultContentToText(content: readonly ToolResultContentPart[]): string {\n return content\n .map((item) => (item.type === \"text\" ? item.text : `[file:${item.mediaType}]`))\n .join(\"\\n\");\n}\n\nfunction isRichToolOutput(value: unknown): value is RichToolOutput {\n if (typeof value !== \"object\" || value === null) return false;\n return Object.getOwnPropertyDescriptor(value, richToolOutput)?.value === true;\n}\n\nexport function parseToolArgs(args: string): JsonValue {\n const value: unknown = JSON.parse(args);\n if (!isJsonValue(value)) {\n throw new TypeError(\"Tool arguments must be a JSON value.\");\n }\n return value;\n}\n"],"mappings":";;;;;;;;AA8DA,IAAM,iBAAgC,uBAAO,IAAI,2BAA2B;AASrE,IAAM,+BAAN,cAA2C,UAAU;AAAA,EAC1D,YAAqB,QAAiB;AACpC,UAAM,gFAAgF;AADnE;AAEnB,SAAK,OAAO;AAAA,EACd;AAAA,EAHqB;AAIvB;AAEO,IAAM,aAAa;AAAA,EACxB,QAAQ,SAA2D;AACjE,WAAO,EAAE,CAAC,cAAc,GAAG,MAAM,QAAQ;AAAA,EAC3C;AACF;AAEO,SAAS,0BAA0B,QAAuC;AAC/E,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,MAAM,QAAQ,OAAO,OAAO;AAAA,EACvC;AACA,MAAI,iBAAiB,MAAM,GAAG;AAC5B,QAAI;AACF,YAAM,UAAU,aAAa;AAAA,QAC3B,MAAM;AAAA,QACN,SAAS;AAAA,UACP;AAAA,YACE,MAAM;AAAA,YACN,YAAY;AAAA,YACZ,UAAU;AAAA,YACV,QAAQ,EAAE,MAAM,WAAW,OAAO,OAAO,QAAQ;AAAA,UACnD;AAAA,QACF;AAAA,MACF,CAAC;AACD,UAAI,QAAQ,SAAS,OAAQ,OAAM,IAAI,UAAU,yBAAyB;AAC1E,YAAM,SAAS,QAAQ,QAAQ,CAAC;AAChC,UAAI,QAAQ,SAAS,cAAe,OAAM,IAAI,UAAU,6BAA6B;AACrF,UAAI,QAAQ,OAAO,SAAS,UAAW,OAAM,IAAI,UAAU,wBAAwB;AACnF,aAAO,OAAO;AAAA,IAChB,QAAQ;AACN,YAAM,IAAI,6BAA6B,MAAM;AAAA,IAC/C;AAAA,EACF;AACA,MAAI,YAAY,MAAM,GAAG;AACvB,WAAO,EAAE,MAAM,QAAQ,OAAO,OAAO;AAAA,EACvC;AACA,QAAM,IAAI,6BAA6B,MAAM;AAC/C;AAEO,SAAS,wBAAwB,SAAmD;AACzF,SAAO,QACJ,IAAI,CAAC,SAAU,KAAK,SAAS,SAAS,KAAK,OAAO,SAAS,KAAK,SAAS,GAAI,EAC7E,KAAK,IAAI;AACd;AAEA,SAAS,iBAAiB,OAAyC;AACjE,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,SAAO,OAAO,yBAAyB,OAAO,cAAc,GAAG,UAAU;AAC3E;AAEO,SAAS,cAAc,MAAyB;AACrD,QAAM,QAAiB,KAAK,MAAM,IAAI;AACtC,MAAI,CAAC,YAAY,KAAK,GAAG;AACvB,UAAM,IAAI,UAAU,sCAAsC;AAAA,EAC5D;AACA,SAAO;AACT;","names":[]}
|