@anvia/core 0.11.2 → 0.12.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/dist/agent/index.d.ts +14 -11
- package/dist/agent/index.js +11 -10
- package/dist/{agent-Bq2KtSaw.d.ts → agent-BWF8_O8k.d.ts} +17 -8
- package/dist/audio-generation/index.d.ts +3 -3
- package/dist/{chunk-N6REB3DH.js → chunk-4AJJIIAQ.js} +9 -7
- package/dist/chunk-4AJJIIAQ.js.map +1 -0
- package/dist/{chunk-WJO6NVE2.js → chunk-5LFGEMIW.js} +1 -1
- package/dist/{chunk-WJO6NVE2.js.map → chunk-5LFGEMIW.js.map} +1 -1
- package/dist/{chunk-DOS77JZC.js → chunk-JNO4AR7Q.js} +2 -2
- package/dist/{chunk-SISUMRUX.js → chunk-KTTIPWE7.js} +467 -111
- package/dist/chunk-KTTIPWE7.js.map +1 -0
- package/dist/{chunk-R75SGHCI.js → chunk-MIJUAWHU.js} +6 -6
- package/dist/{chunk-5EDHXYH5.js → chunk-PGFYN5ZX.js} +12 -7
- package/dist/chunk-PGFYN5ZX.js.map +1 -0
- package/dist/{chunk-X3SWV6W6.js → chunk-R7F2JF7J.js} +7 -7
- package/dist/chunk-R7F2JF7J.js.map +1 -0
- package/dist/{chunk-5G3VME2D.js → chunk-SRBW3LD7.js} +2 -2
- package/dist/chunk-SRBW3LD7.js.map +1 -0
- package/dist/{chunk-62RUYGMM.js → chunk-TIH4QM55.js} +12 -3
- package/dist/chunk-TIH4QM55.js.map +1 -0
- package/dist/chunk-YRERPIA5.js +451 -0
- package/dist/chunk-YRERPIA5.js.map +1 -0
- package/dist/{chunk-V3WTT7TE.js → chunk-ZGIE73BH.js} +2 -2
- package/dist/completion/index.d.ts +8 -6
- package/dist/completion/index.js +2 -2
- package/dist/{create-completion-BEbtU5pX.d.ts → create-completion-Y6YsYbQB.d.ts} +2 -2
- package/dist/evals/index.d.ts +9 -8
- package/dist/evals/index.js +14 -13
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +9 -8
- package/dist/extractor/index.js +12 -11
- package/dist/guardrails/index.d.ts +211 -0
- package/dist/guardrails/index.js +35 -0
- package/dist/guardrails/index.js.map +1 -0
- package/dist/hooks/index.d.ts +3 -3
- package/dist/image-generation/index.d.ts +3 -3
- package/dist/{index-CTNzKidE.d.ts → index-DsWWqP0Q.d.ts} +9 -2
- package/dist/index.d.ts +13 -12
- package/dist/index.js +37 -19
- package/dist/internal/agent.d.ts +9 -8
- package/dist/internal/agent.js +10 -9
- package/dist/loaders/index.d.ts +1 -1
- package/dist/mcp/index.d.ts +5 -4
- package/dist/memory/index.d.ts +3 -3
- package/dist/{middleware-CG7l0rR3.d.ts → middleware-BTR0eRtx.d.ts} +3 -3
- package/dist/model-listing/index.d.ts +2 -1
- package/dist/observability/index.d.ts +4 -3
- package/dist/pipeline/index.d.ts +9 -8
- package/dist/pipeline/index.js +3 -3
- package/dist/request/index.d.ts +9 -8
- package/dist/request/index.js +9 -8
- package/dist/skills/index.d.ts +5 -4
- package/dist/skills/index.js +6 -6
- package/dist/{think-tool-B8Rqw2i_.d.ts → think-tool-Bn3HHu_z.d.ts} +4 -1
- package/dist/tool/index.d.ts +6 -5
- package/dist/tool/index.js +6 -6
- package/dist/{tool-BLypI31e.d.ts → tool-DGELXD2z.d.ts} +4 -1
- package/dist/transcription/index.d.ts +3 -3
- package/dist/{types-KKjICcrA.d.ts → types-9VPKg7ih.d.ts} +1 -1
- package/dist/{types-D-YTJdLj.d.ts → types-Bx_ZtjPi.d.ts} +1 -1
- package/dist/{types-CCxnnJjU.d.ts → types-CGML74sE.d.ts} +1 -1
- package/dist/{types-CNfjQ5rB.d.ts → types-CqG6d7Ce.d.ts} +1 -1
- package/dist/{types-CIwm9p4w.d.ts → types-Dc83Qzch.d.ts} +2 -2
- package/dist/{types-C8loR4il.d.ts → types-q9G7Bvwl.d.ts} +8 -8
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +2 -2
- package/dist/vector-store/index.d.ts +5 -4
- package/dist/vector-store/index.js +3 -3
- package/package.json +6 -2
- package/dist/chunk-5EDHXYH5.js.map +0 -1
- package/dist/chunk-5G3VME2D.js.map +0 -1
- package/dist/chunk-62RUYGMM.js.map +0 -1
- package/dist/chunk-N6REB3DH.js.map +0 -1
- package/dist/chunk-SISUMRUX.js.map +0 -1
- package/dist/chunk-X3SWV6W6.js.map +0 -1
- /package/dist/{chunk-DOS77JZC.js.map → chunk-JNO4AR7Q.js.map} +0 -0
- /package/dist/{chunk-R75SGHCI.js.map → chunk-MIJUAWHU.js.map} +0 -0
- /package/dist/{chunk-V3WTT7TE.js.map → chunk-ZGIE73BH.js.map} +0 -0
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { D as DynamicContextOptions, a as DynamicToolOptions, b as AgentEventStore, c as AgentEventStoreOptions, A as Agent } from '../agent-
|
|
2
|
-
export { d as AgentEventAppendInput, e as AgentEventRecord, f as AgentEventStoreInclude, g as AgentSession, h as AgentToolOptions } from '../agent-
|
|
1
|
+
import { D as DynamicContextOptions, a as DynamicToolOptions, b as AgentEventStore, c as AgentEventStoreOptions, A as Agent } from '../agent-BWF8_O8k.js';
|
|
2
|
+
export { d as AgentEventAppendInput, e as AgentEventRecord, f as AgentEventStoreInclude, g as AgentSession, h as AgentToolOptions } from '../agent-BWF8_O8k.js';
|
|
3
3
|
import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
|
|
4
|
-
import { C as CompletionModel, e as JsonValue, n as ToolChoice } from '../types-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { A as
|
|
12
|
-
import {
|
|
4
|
+
import { C as CompletionModel, e as JsonValue, n as ToolChoice } from '../types-q9G7Bvwl.js';
|
|
5
|
+
import { GuardrailPolicyInput } from '../guardrails/index.js';
|
|
6
|
+
import { P as PromptHook } from '../types-CGML74sE.js';
|
|
7
|
+
import { a as McpServer } from '../types-Dc83Qzch.js';
|
|
8
|
+
import { M as MemoryStore, a as MemoryOptions } from '../types-CqG6d7Ce.js';
|
|
9
|
+
import { b as AgentObserver, O as ObserveOptions } from '../index-DsWWqP0Q.js';
|
|
10
|
+
import { a as SkillSet } from '../types-Bx_ZtjPi.js';
|
|
11
|
+
import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-BTR0eRtx.js';
|
|
12
|
+
import { A as AnyTool, e as ToolApprovalsOptions } from '../tool-DGELXD2z.js';
|
|
13
|
+
import { a as VectorSearchIndex } from '../types-9VPKg7ih.js';
|
|
13
14
|
import 'zod';
|
|
14
15
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
15
16
|
import '@modelcontextprotocol/sdk/client/stdio.js';
|
|
@@ -31,6 +32,7 @@ declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
|
31
32
|
private requestHook;
|
|
32
33
|
private schema;
|
|
33
34
|
private approvalOptions;
|
|
35
|
+
private guardrailPolicies;
|
|
34
36
|
private skillInstructionBlocks;
|
|
35
37
|
private observerRegistrations;
|
|
36
38
|
private dynamicContextRegistrations;
|
|
@@ -69,6 +71,7 @@ declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
|
69
71
|
toolMiddlewares(middlewares: ToolMiddleware[]): this;
|
|
70
72
|
observe(observer: AgentObserver, options?: ObserveOptions): this;
|
|
71
73
|
approvals(options: ToolApprovalsOptions): this;
|
|
74
|
+
guardrails(policies: GuardrailPolicyInput): this;
|
|
72
75
|
memory(store: MemoryStore, options?: MemoryOptions): this;
|
|
73
76
|
eventStore(store: AgentEventStore, options?: AgentEventStoreOptions): this;
|
|
74
77
|
outputSchema(schema: ZodSchema): this;
|
package/dist/agent/index.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBuilder
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-TIH4QM55.js";
|
|
4
|
+
import "../chunk-4AJJIIAQ.js";
|
|
5
|
+
import "../chunk-KTTIPWE7.js";
|
|
6
6
|
import "../chunk-YK4WAAS4.js";
|
|
7
7
|
import "../chunk-XUUY2L2D.js";
|
|
8
|
-
import "../chunk-
|
|
9
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-R7F2JF7J.js";
|
|
9
|
+
import "../chunk-PGFYN5ZX.js";
|
|
10
|
+
import "../chunk-NPZDYOE6.js";
|
|
11
|
+
import "../chunk-MMHG7WAM.js";
|
|
10
12
|
import "../chunk-M6RPFHG7.js";
|
|
13
|
+
import "../chunk-SRBW3LD7.js";
|
|
14
|
+
import "../chunk-5LFGEMIW.js";
|
|
15
|
+
import "../chunk-WQKHFADH.js";
|
|
11
16
|
import "../chunk-JS5MGVNM.js";
|
|
12
17
|
import "../chunk-OIMLU4SF.js";
|
|
13
|
-
import "../chunk-
|
|
14
|
-
import "../chunk-WJO6NVE2.js";
|
|
15
|
-
import "../chunk-WQKHFADH.js";
|
|
16
|
-
import "../chunk-NPZDYOE6.js";
|
|
17
|
-
import "../chunk-MMHG7WAM.js";
|
|
18
|
+
import "../chunk-YRERPIA5.js";
|
|
18
19
|
export {
|
|
19
20
|
AgentBuilder
|
|
20
21
|
};
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import { C as CompletionModel, M as Message, D as Document, e as JsonValue, n as ToolChoice, J as JsonObject } from './types-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { c as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import { C as CompletionModel, M as Message, D as Document, e as JsonValue, n as ToolChoice, J as JsonObject } from './types-q9G7Bvwl.js';
|
|
2
|
+
import { GuardrailPolicyInput, GuardrailPolicy } from './guardrails/index.js';
|
|
3
|
+
import { P as PromptHook } from './types-CGML74sE.js';
|
|
4
|
+
import { c as MemoryContext, e as MemoryRegistration, S as SessionOptions } from './types-CqG6d7Ce.js';
|
|
5
|
+
import { c as AgentTraceOptions, P as PromptResponse, a as AgentStreamEvent, d as AgentObserverRegistration } from './index-DsWWqP0Q.js';
|
|
6
|
+
import { e as ToolApprovalsOptions, T as Tool, A as AnyTool, f as ToolCallContext, N as NormalizedToolOutput } from './tool-DGELXD2z.js';
|
|
7
|
+
import { A as AgentMiddleware, e as ToolMiddleware, k as ToolSearchDocument, l as ToolSet } from './middleware-BTR0eRtx.js';
|
|
8
|
+
import { V as VectorFilter, c as VectorSearchResult, a as VectorSearchIndex } from './types-9VPKg7ih.js';
|
|
8
9
|
|
|
9
10
|
declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
10
11
|
private readonly agent;
|
|
11
|
-
private
|
|
12
|
+
private promptMessage;
|
|
12
13
|
private readonly memoryContext;
|
|
13
14
|
private chatHistory;
|
|
14
15
|
private maxTurnCount;
|
|
15
16
|
private activeHook;
|
|
16
17
|
private approvalOptions;
|
|
18
|
+
private guardrailPolicies;
|
|
19
|
+
private guardrailDecisions;
|
|
17
20
|
private concurrency;
|
|
18
21
|
private traceOptions;
|
|
19
22
|
private requestMiddlewares;
|
|
@@ -27,6 +30,7 @@ declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
|
27
30
|
maxTurns(maxTurns: number): this;
|
|
28
31
|
withHook(hook: PromptHook): this;
|
|
29
32
|
approvals(options: ToolApprovalsOptions): this;
|
|
33
|
+
guardrails(policies: GuardrailPolicyInput): this;
|
|
30
34
|
/**
|
|
31
35
|
* @deprecated Use `withHook` instead.
|
|
32
36
|
*/
|
|
@@ -50,6 +54,9 @@ declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
|
50
54
|
private runCompletion;
|
|
51
55
|
private providerTraceRequest;
|
|
52
56
|
private executeToolCalls;
|
|
57
|
+
private runOutputGuardrailsForResponse;
|
|
58
|
+
private recordGuardrailDecision;
|
|
59
|
+
private guardrailRunContext;
|
|
53
60
|
private startRunObservers;
|
|
54
61
|
private recordAgentEvent;
|
|
55
62
|
private runCompletionCallHook;
|
|
@@ -87,6 +94,7 @@ type AgentOptions<M extends CompletionModel = CompletionModel> = {
|
|
|
87
94
|
outputSchema?: JsonObject | undefined;
|
|
88
95
|
observers?: AgentObserverRegistration[] | undefined;
|
|
89
96
|
approvals?: ToolApprovalsOptions | undefined;
|
|
97
|
+
guardrails?: GuardrailPolicy[] | undefined;
|
|
90
98
|
dynamicContexts?: DynamicContextRegistration[] | undefined;
|
|
91
99
|
dynamicTools?: DynamicToolRegistration[] | undefined;
|
|
92
100
|
middlewares?: AgentMiddleware[] | undefined;
|
|
@@ -167,6 +175,7 @@ declare class Agent<M extends CompletionModel = CompletionModel> {
|
|
|
167
175
|
readonly outputSchema: JsonObject | undefined;
|
|
168
176
|
readonly observers: AgentObserverRegistration[];
|
|
169
177
|
readonly approvals: ToolApprovalsOptions | undefined;
|
|
178
|
+
readonly guardrails: GuardrailPolicy[];
|
|
170
179
|
readonly dynamicContexts: DynamicContextRegistration[];
|
|
171
180
|
readonly dynamicTools: DynamicToolRegistration[];
|
|
172
181
|
readonly middlewares: AgentMiddleware[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { e as JsonValue } from '../types-
|
|
1
|
+
import { e as JsonValue } from '../types-q9G7Bvwl.js';
|
|
2
2
|
|
|
3
3
|
type AudioGenerationRequest = {
|
|
4
4
|
text: string;
|
|
@@ -11,9 +11,9 @@ type AudioGenerationResponse<RawResponse = unknown> = {
|
|
|
11
11
|
mediaType?: string | undefined;
|
|
12
12
|
rawResponse: RawResponse;
|
|
13
13
|
};
|
|
14
|
-
interface AudioGenerationModel<RawResponse = unknown> {
|
|
14
|
+
interface AudioGenerationModel<RawResponse = unknown, ModelName extends string = string> {
|
|
15
15
|
readonly provider?: string | undefined;
|
|
16
|
-
readonly defaultModel?:
|
|
16
|
+
readonly defaultModel?: ModelName | undefined;
|
|
17
17
|
audioGeneration(request: AudioGenerationRequest): Promise<AudioGenerationResponse<RawResponse>>;
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PromptRequest
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KTTIPWE7.js";
|
|
4
4
|
import {
|
|
5
5
|
isSkillTool
|
|
6
6
|
} from "./chunk-YK4WAAS4.js";
|
|
7
7
|
import {
|
|
8
8
|
ToolSet
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-R7F2JF7J.js";
|
|
10
10
|
import {
|
|
11
11
|
createTool
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import {
|
|
14
|
-
isStreamingCompletionModel
|
|
15
|
-
} from "./chunk-5G3VME2D.js";
|
|
12
|
+
} from "./chunk-PGFYN5ZX.js";
|
|
16
13
|
import {
|
|
17
14
|
compact
|
|
18
15
|
} from "./chunk-MMHG7WAM.js";
|
|
16
|
+
import {
|
|
17
|
+
isStreamingCompletionModel
|
|
18
|
+
} from "./chunk-SRBW3LD7.js";
|
|
19
19
|
|
|
20
20
|
// src/agent/agent.ts
|
|
21
21
|
import { z } from "zod";
|
|
@@ -51,6 +51,7 @@ var Agent = class {
|
|
|
51
51
|
outputSchema;
|
|
52
52
|
observers;
|
|
53
53
|
approvals;
|
|
54
|
+
guardrails;
|
|
54
55
|
dynamicContexts;
|
|
55
56
|
dynamicTools;
|
|
56
57
|
middlewares;
|
|
@@ -77,6 +78,7 @@ var Agent = class {
|
|
|
77
78
|
this.outputSchema = options.outputSchema;
|
|
78
79
|
this.observers = options.observers ?? [];
|
|
79
80
|
this.approvals = options.approvals;
|
|
81
|
+
this.guardrails = [...options.guardrails ?? []];
|
|
80
82
|
this.dynamicContexts = options.dynamicContexts ?? [];
|
|
81
83
|
this.dynamicTools = options.dynamicTools ?? [];
|
|
82
84
|
this.middlewares = options.middlewares ?? options.toolMiddlewares ?? [];
|
|
@@ -202,4 +204,4 @@ export {
|
|
|
202
204
|
Agent,
|
|
203
205
|
AgentSession
|
|
204
206
|
};
|
|
205
|
-
//# sourceMappingURL=chunk-
|
|
207
|
+
//# sourceMappingURL=chunk-4AJJIIAQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/agent/agent.ts","../src/agent/ids.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { isStreamingCompletionModel } from \"../completion/create-completion\";\nimport type {\n CompletionModel,\n Document,\n JsonObject,\n JsonValue,\n Message as MessageType,\n ToolChoice,\n} from \"../completion/index\";\nimport type { GuardrailPolicy } from \"../guardrails\";\nimport type { PromptHook } from \"../hooks\";\nimport { compact } from \"../internal/compact\";\nimport type { MemoryRegistration, SessionOptions } from \"../memory/types\";\nimport type { AgentObserverRegistration } from \"../observability\";\nimport { PromptRequest } from \"../request\";\nimport { createTool } from \"../tool/create-tool\";\nimport type { ToolSearchDocument } from \"../tool/dynamic-tools\";\nimport type { AgentMiddleware } from \"../tool/middleware\";\nimport { isSkillTool } from \"../tool/skill-tool-marker\";\nimport type {\n AnyTool,\n NormalizedToolOutput,\n Tool,\n ToolApprovalsOptions,\n ToolCallContext,\n} from \"../tool/tool\";\nimport { ToolSet } from \"../tool/tool-set\";\nimport type { VectorSearchIndex } from \"../vector-store\";\nimport { normalizeAgentId } from \"./ids\";\nimport type {\n AgentEventStoreRegistration,\n AgentOptions,\n AgentToolOptions,\n DynamicContextRegistration,\n DynamicToolRegistration,\n} from \"./types\";\n\nexport const DEFAULT_MAX_TURNS = 20;\n\nexport class Agent<M extends CompletionModel = CompletionModel> {\n readonly id: string;\n readonly name: string | undefined;\n readonly description: string | undefined;\n readonly model: M;\n readonly instructions: string | undefined;\n readonly staticContext: Document[];\n readonly temperature: number | undefined;\n readonly maxTokens: number | undefined;\n readonly additionalParams: JsonValue | undefined;\n readonly toolSet: ToolSet;\n readonly toolChoice: ToolChoice | undefined;\n readonly defaultMaxTurns: number | undefined;\n readonly hook: PromptHook | undefined;\n readonly outputSchema: JsonObject | undefined;\n readonly observers: AgentObserverRegistration[];\n readonly approvals: ToolApprovalsOptions | undefined;\n readonly guardrails: GuardrailPolicy[];\n readonly dynamicContexts: DynamicContextRegistration[];\n readonly dynamicTools: DynamicToolRegistration[];\n readonly middlewares: AgentMiddleware[];\n /**\n * @deprecated Use `middlewares` instead.\n */\n readonly toolMiddlewares: AgentMiddleware[];\n readonly memory: MemoryRegistration | undefined;\n readonly eventStore: AgentEventStoreRegistration | undefined;\n\n constructor(options: AgentOptions<M>) {\n this.id = normalizeAgentId(options.id);\n this.name = options.name;\n this.description = options.description;\n this.model = options.model;\n this.instructions = options.instructions;\n this.staticContext = options.staticContext ?? [];\n this.temperature = options.temperature;\n this.maxTokens = options.maxTokens;\n this.additionalParams = options.additionalParams;\n this.toolSet = options.toolSet ?? new ToolSet();\n this.toolChoice = options.toolChoice;\n this.defaultMaxTurns = options.defaultMaxTurns ?? DEFAULT_MAX_TURNS;\n this.hook = options.hook;\n this.outputSchema = options.outputSchema;\n this.observers = options.observers ?? [];\n this.approvals = options.approvals;\n this.guardrails = [...(options.guardrails ?? [])];\n this.dynamicContexts = options.dynamicContexts ?? [];\n this.dynamicTools = options.dynamicTools ?? [];\n this.middlewares = options.middlewares ?? options.toolMiddlewares ?? [];\n this.toolMiddlewares = this.middlewares;\n this.memory = options.memory;\n this.eventStore = options.eventStore;\n }\n\n prompt(prompt: string | MessageType | MessageType[]): PromptRequest<M> {\n return PromptRequest.fromAgent(this, prompt);\n }\n\n session(sessionId: string, options: SessionOptions = {}): AgentSession<M> {\n if (this.memory === undefined) {\n throw new Error(`Agent \"${this.id}\" has no memory store configured.`);\n }\n const normalized = sessionId.trim();\n if (normalized.length === 0) {\n throw new TypeError(\"Session id must be a non-empty string.\");\n }\n return new AgentSession(this, {\n sessionId: normalized,\n ...(options.userId !== undefined && { userId: options.userId }),\n ...(options.metadata !== undefined && { metadata: options.metadata }),\n });\n }\n\n asTool(options: AgentToolOptions): Tool<{ prompt: string }, string> {\n const description =\n options.description ?? this.description ?? `Prompt the ${options.name} agent.`;\n\n return createTool({\n name: options.name,\n description,\n input: z.object({\n prompt: z.string().describe(\"The prompt to send to the agent.\"),\n }),\n output: z.string(),\n execute: async ({ prompt }, context: ToolCallContext) => {\n const request = this.prompt(prompt);\n const childRequest =\n options.maxTurns === undefined ? request : request.maxTurns(options.maxTurns);\n if (\n options.stream === true &&\n context.emitStreamEvent !== undefined &&\n this.model.capabilities.streaming &&\n isStreamingCompletionModel(this.model)\n ) {\n let output = \"\";\n for await (const event of childRequest.stream()) {\n await context.emitStreamEvent(\n compact({\n agentId: this.id,\n agentName: this.name,\n event,\n }),\n );\n if (event.type === \"final\") {\n output = event.output;\n }\n }\n return output;\n }\n const response = await childRequest.send();\n return response.output;\n },\n });\n }\n\n getTool(toolName: string): AnyTool | undefined {\n const staticTool = this.toolSet.get(toolName);\n if (staticTool !== undefined) {\n return staticTool;\n }\n\n for (const registration of this.dynamicTools) {\n const dynamicTool = dynamicToolSetFromIndex(registration.index)?.get(toolName);\n if (dynamicTool !== undefined) {\n return dynamicTool;\n }\n }\n\n return undefined;\n }\n\n async callTool(\n toolName: string,\n args: string,\n context?: ToolCallContext,\n ): Promise<NormalizedToolOutput> {\n if (this.toolSet.contains(toolName)) {\n return this.toolSet.call(toolName, args, context);\n }\n\n for (const registration of this.dynamicTools) {\n const toolSet = dynamicToolSetFromIndex(registration.index);\n if (toolSet?.contains(toolName)) {\n return toolSet.call(toolName, args, context);\n }\n }\n\n return this.toolSet.call(toolName, args, context);\n }\n\n shouldApplyToolMiddleware(toolName: string): boolean {\n return !isSkillTool(this.getTool(toolName));\n }\n}\n\nexport class AgentSession<M extends CompletionModel = CompletionModel> {\n constructor(\n private readonly agent: Agent<M>,\n private readonly context: {\n sessionId: string;\n userId?: string | undefined;\n metadata?: JsonObject | undefined;\n },\n ) {}\n\n prompt(prompt: string | MessageType): PromptRequest<M> {\n if (Array.isArray(prompt)) {\n throw new TypeError(\"AgentSession.prompt does not accept Message[] transcripts.\");\n }\n return PromptRequest.fromAgent(this.agent, prompt, { memoryContext: this.context });\n }\n\n async messages(): Promise<MessageType[]> {\n const memory = this.agent.memory;\n if (memory === undefined) {\n throw new Error(`Agent \"${this.agent.id}\" has no memory store configured.`);\n }\n return memory.store.load(this.context);\n }\n\n async clear(): Promise<void> {\n const memory = this.agent.memory;\n if (memory === undefined) {\n throw new Error(`Agent \"${this.agent.id}\" has no memory store configured.`);\n }\n await memory.store.clear(this.context);\n }\n}\n\nfunction dynamicToolSetFromIndex(\n index: VectorSearchIndex<ToolSearchDocument>,\n): ToolSet | undefined {\n const maybeIndex = index as { toolSet?: unknown };\n return maybeIndex.toolSet instanceof ToolSet ? maybeIndex.toolSet : undefined;\n}\n","export function normalizeAgentId(id: string): string {\n if (typeof id !== \"string\") {\n throw new TypeError(\"Agent id must be a string.\");\n }\n\n const normalized = id.trim();\n if (normalized.length === 0) {\n throw new TypeError(\"Agent id must be a non-empty string.\");\n }\n\n return normalized;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS;;;ACAX,SAAS,iBAAiB,IAAoB;AACnD,MAAI,OAAO,OAAO,UAAU;AAC1B,UAAM,IAAI,UAAU,4BAA4B;AAAA,EAClD;AAEA,QAAM,aAAa,GAAG,KAAK;AAC3B,MAAI,WAAW,WAAW,GAAG;AAC3B,UAAM,IAAI,UAAU,sCAAsC;AAAA,EAC5D;AAEA,SAAO;AACT;;;AD2BO,IAAM,oBAAoB;AAE1B,IAAM,QAAN,MAAyD;AAAA,EACrD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA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AM,OAAO,MAAM,MAAM,KAAK,OAAO;AAAA,EACvC;AACF;AAEA,SAAS,wBACP,OACqB;AACrB,QAAM,aAAa;AACnB,SAAO,WAAW,mBAAmB,UAAU,WAAW,UAAU;AACtE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/completion/types.ts"],"sourcesContent":["export type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonObject | JsonValue[];\nexport type JsonObject = { [key: string]: JsonValue | undefined };\n\nexport type Document = {\n id: string;\n text: string;\n additionalProps?: Record<string, string>;\n};\n\nexport type Text = {\n type: \"text\";\n text: string;\n signature?: string;\n};\n\nexport type ImageDetail = \"auto\" | \"low\" | \"high\";\n\nexport type ImageContent = {\n type: \"image\";\n source:\n | {\n type: \"url\";\n url: string;\n }\n | {\n type: \"base64\";\n data: string;\n mediaType: string;\n };\n detail?: ImageDetail;\n};\n\nexport type DocumentContent = {\n type: \"document\";\n source:\n | {\n type: \"url\";\n url: string;\n mediaType: string;\n filename?: string;\n }\n | {\n type: \"base64\";\n data: string;\n mediaType: string;\n filename?: string;\n }\n | {\n type: \"text\";\n text: string;\n mediaType?: string;\n filename?: string;\n };\n};\n\nexport type Reasoning = {\n type: \"reasoning\";\n text: string;\n id?: string;\n content?: ReasoningContent[];\n};\n\nexport type ReasoningContent =\n | {\n type: \"text\";\n text: string;\n signature?: string;\n }\n | {\n type: \"summary\";\n text: string;\n }\n | {\n type: \"encrypted\";\n data: string;\n }\n | {\n type: \"redacted\";\n data: string;\n };\n\nexport type ReasoningContentType = ReasoningContent[\"type\"];\n\nexport type ToolFunction = {\n name: string;\n arguments: JsonValue;\n};\n\nexport type ToolCall = {\n type: \"tool_call\";\n id: string;\n callId?: string;\n function: ToolFunction;\n signature?: string;\n additionalParams?: JsonValue;\n};\n\nexport type ToolResultContent =\n | { type: \"text\"; text: string }\n | { type: \"image\"; data: string; mediaType?: string };\n\nexport type ToolResult = {\n type: \"tool_result\";\n id: string;\n callId?: string;\n content: ToolResultContent[];\n};\n\nexport type UserContent = Text | ImageContent | DocumentContent;\nexport type AssistantContent = Text | ToolCall | Reasoning | ImageContent;\nexport type ToolContent = ToolResult;\n\nexport type SystemMessage = {\n role: \"system\";\n content: string;\n};\n\nexport type UserMessage = {\n role: \"user\";\n content: UserContent[];\n};\n\nexport type AssistantMessage = {\n role: \"assistant\";\n id?: string;\n content: AssistantContent[];\n};\n\nexport type ToolMessage = {\n role: \"tool\";\n content: ToolContent[];\n};\n\nexport type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage;\n\nexport const UserContent = {\n text(text: string): Text {\n return { type: \"text\", text };\n },\n imageUrl(url: string, options: { detail?: ImageDetail } = {}): ImageContent {\n const image: ImageContent = { type: \"image\", source: { type: \"url\", url } };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n imageBase64(\n data: string,\n mediaType: string,\n options: { detail?: ImageDetail } = {},\n ): ImageContent {\n const image: ImageContent = {\n type: \"image\",\n source: { type: \"base64\", data, mediaType },\n };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n documentUrl(\n url: string,\n mediaType: string,\n options: { filename?: string | undefined } = {},\n ): DocumentContent {\n return {\n type: \"document\",\n source:\n options.filename === undefined\n ? { type: \"url\", url, mediaType }\n : { type: \"url\", url, mediaType, filename: options.filename },\n };\n },\n documentBase64(\n data: string,\n mediaType: string,\n options: { filename?: string | undefined } = {},\n ): DocumentContent {\n return {\n type: \"document\",\n source:\n options.filename === undefined\n ? { type: \"base64\", data, mediaType }\n : { type: \"base64\", data, mediaType, filename: options.filename },\n };\n },\n documentText(text: string): Text {\n return { type: \"text\", text };\n },\n};\n\nexport const ToolContent = {\n toolResult(id: string, content: string | ToolResultContent[], callId?: string): ToolResult {\n const normalized =\n typeof content === \"string\" ? [{ type: \"text\" as const, text: content }] : content;\n return callId === undefined\n ? { type: \"tool_result\", id, content: normalized }\n : { type: \"tool_result\", id, callId, content: normalized };\n },\n};\n\nexport function serializeToolResultOutput(output: unknown): string {\n if (typeof output === \"string\") {\n return output;\n }\n\n try {\n const serialized = JSON.stringify(output);\n return serialized === undefined ? String(output) : serialized;\n } catch {\n return String(output);\n }\n}\n\nexport function isToolResultContentArray(value: unknown): value is ToolResultContent[] {\n return (\n Array.isArray(value) &&\n value.length > 0 &&\n value.every((item) => {\n if (typeof item !== \"object\" || item === null || !(\"type\" in item)) {\n return false;\n }\n if (item.type === \"text\") {\n return \"text\" in item && typeof item.text === \"string\";\n }\n if (item.type === \"image\") {\n return (\n \"data\" in item &&\n typeof item.data === \"string\" &&\n (!(\"mediaType\" in item) ||\n item.mediaType === undefined ||\n typeof item.mediaType === \"string\")\n );\n }\n return false;\n })\n );\n}\n\nexport const AssistantContent = {\n text(text: string): Text {\n return { type: \"text\", text };\n },\n imageUrl(url: string, options: { detail?: ImageDetail } = {}): ImageContent {\n const image: ImageContent = { type: \"image\", source: { type: \"url\", url } };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n imageBase64(\n data: string,\n mediaType: string,\n options: { detail?: ImageDetail } = {},\n ): ImageContent {\n const image: ImageContent = {\n type: \"image\",\n source: { type: \"base64\", data, mediaType },\n };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n reasoning(text: string, id?: string): Reasoning {\n return id === undefined ? { type: \"reasoning\", text } : { type: \"reasoning\", text, id };\n },\n reasoningFromContent(content: ReasoningContent[], id?: string): Reasoning {\n const text = reasoningDisplayText(content);\n const reasoning: Reasoning = { type: \"reasoning\", text, content };\n return id === undefined ? reasoning : { ...reasoning, id };\n },\n reasoningSummary(text: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"summary\", text }], id);\n },\n reasoningEncrypted(data: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"encrypted\", data }], id);\n },\n reasoningRedacted(data: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"redacted\", data }], id);\n },\n toolCall(id: string, name: string, args: JsonValue, callId?: string): ToolCall {\n const base: ToolCall = {\n type: \"tool_call\",\n id,\n function: {\n name,\n arguments: args,\n },\n };\n return callId === undefined ? base : { ...base, callId };\n },\n};\n\nexport function reasoningDisplayText(reasoning: Reasoning | ReasoningContent[]): string {\n const content = Array.isArray(reasoning) ? reasoning : reasoning.content;\n if (content === undefined) {\n return Array.isArray(reasoning) ? \"\" : reasoning.text;\n }\n return content\n .flatMap((item) => {\n if (item.type === \"text\" || item.type === \"summary\") {\n return [item.text];\n }\n return [];\n })\n .join(\"\");\n}\n\nexport const Message = {\n system(content: string): Message {\n return { role: \"system\", content };\n },\n user(content: string | UserContent[]): Message {\n return {\n role: \"user\",\n content: typeof content === \"string\" ? [UserContent.text(content)] : content,\n };\n },\n assistant(content: string | AssistantContent[], id?: string): Message {\n const normalized = typeof content === \"string\" ? [AssistantContent.text(content)] : content;\n return id === undefined\n ? { role: \"assistant\", content: normalized }\n : { role: \"assistant\", id, content: normalized };\n },\n tool(content: ToolContent | ToolContent[]): Message {\n return {\n role: \"tool\",\n content: Array.isArray(content) ? content : [content],\n };\n },\n toolResult(id: string, output: unknown, options: { callId?: string | undefined } = {}): Message {\n const content = isToolResultContentArray(output) ? output : serializeToolResultOutput(output);\n return Message.tool(ToolContent.toolResult(id, content, options.callId));\n },\n};\n\nexport type ToolChoice =\n | \"auto\"\n | \"required\"\n | \"none\"\n | {\n type: \"function\";\n name: string;\n };\n\nexport type ToolDefinition = {\n name: string;\n description: string;\n parameters: JsonObject;\n};\n\nexport type Usage = {\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n cachedInputTokens: number;\n cacheCreationInputTokens: number;\n};\n\nexport const Usage = {\n empty(): Usage {\n return {\n inputTokens: 0,\n outputTokens: 0,\n totalTokens: 0,\n cachedInputTokens: 0,\n cacheCreationInputTokens: 0,\n };\n },\n add(left: Usage, right: Usage): Usage {\n return {\n inputTokens: left.inputTokens + right.inputTokens,\n outputTokens: left.outputTokens + right.outputTokens,\n totalTokens: left.totalTokens + right.totalTokens,\n cachedInputTokens: left.cachedInputTokens + right.cachedInputTokens,\n cacheCreationInputTokens: left.cacheCreationInputTokens + right.cacheCreationInputTokens,\n };\n },\n};\n\nexport type CompletionRequest = {\n model?: string;\n instructions?: string;\n chatHistory: Message[];\n documents: Document[];\n tools: ToolDefinition[];\n temperature?: number;\n maxTokens?: number;\n toolChoice?: ToolChoice;\n additionalParams?: JsonValue;\n outputSchema?: JsonObject;\n};\n\nexport type CompletionResponse<RawResponse = unknown> = {\n choice: AssistantContent[];\n usage: Usage;\n rawResponse: RawResponse;\n messageId?: string;\n};\n\nexport type CompletionModelCapabilities = {\n streaming: boolean;\n tools: boolean;\n toolChoice: boolean;\n imageInput: boolean;\n documentInput: boolean;\n outputSchema: boolean;\n reasoning: boolean;\n};\n\nexport interface CompletionModel<RawResponse = unknown> {\n readonly provider: string;\n readonly defaultModel: string;\n readonly capabilities: CompletionModelCapabilities;\n traceRequest?(\n request: CompletionRequest,\n options?: { stream?: boolean | undefined },\n ): JsonObject | undefined;\n completion(request: CompletionRequest): Promise<CompletionResponse<RawResponse>>;\n}\n\nexport type CompletionStreamEvent<RawResponse = unknown> =\n | {\n type: \"text_delta\";\n delta: string;\n }\n | {\n type: \"reasoning_delta\";\n delta: string;\n id?: string;\n contentType?: ReasoningContentType;\n signature?: string;\n }\n | {\n type: \"tool_call_delta\";\n id: string;\n callId?: string;\n name?: string;\n argumentsDelta?: string;\n signature?: string;\n }\n | {\n type: \"tool_call\";\n toolCall: ToolCall;\n }\n | {\n type: \"message_id\";\n id: string;\n }\n | {\n type: \"final\";\n response: CompletionResponse<RawResponse>;\n }\n | {\n type: \"error\";\n error: unknown;\n };\n\nexport interface StreamingCompletionModel<RawResponse = unknown>\n extends CompletionModel<RawResponse> {\n streamCompletion(request: CompletionRequest): AsyncIterable<CompletionStreamEvent<RawResponse>>;\n}\n\nexport class CompletionCapabilityError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CompletionCapabilityError\";\n }\n}\n\nexport function assertCompletionRequestSupported(\n model: CompletionModel,\n request: CompletionRequest,\n options: { streaming?: boolean | undefined } = {},\n): void {\n const modelLabel = `${model.provider}:${request.model ?? model.defaultModel}`;\n const capabilities = model.capabilities;\n\n if (options.streaming === true && !capabilities.streaming) {\n throw new CompletionCapabilityError(`${modelLabel} does not support streaming completions.`);\n }\n\n if (request.tools.length > 0 && !capabilities.tools) {\n throw new CompletionCapabilityError(`${modelLabel} does not support tool definitions.`);\n }\n\n if (request.toolChoice !== undefined && !capabilities.toolChoice) {\n throw new CompletionCapabilityError(`${modelLabel} does not support tool choice.`);\n }\n\n if (request.outputSchema !== undefined && !capabilities.outputSchema) {\n throw new CompletionCapabilityError(`${modelLabel} does not support output schemas.`);\n }\n\n if (!capabilities.imageInput && requestHasImageInput(request)) {\n throw new CompletionCapabilityError(`${modelLabel} does not support image input.`);\n }\n\n if (!capabilities.documentInput && requestHasFileDocumentInput(request)) {\n throw new CompletionCapabilityError(`${modelLabel} does not support document file input.`);\n }\n}\n\nexport function textFromAssistantContent(content: AssistantContent[]): string {\n return content.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n}\n\nfunction requestHasImageInput(request: CompletionRequest): boolean {\n return request.chatHistory.some((message) =>\n message.role === \"system\" ? false : message.content.some((content) => content.type === \"image\"),\n );\n}\n\nfunction requestHasFileDocumentInput(request: CompletionRequest): boolean {\n return request.chatHistory.some((message) =>\n message.role === \"user\"\n ? message.content.some(\n (content) => content.type === \"document\" && content.source.type !== \"text\",\n )\n : false,\n );\n}\n"],"mappings":";AAwIO,IAAM,cAAc;AAAA,EACzB,KAAK,MAAoB;AACvB,WAAO,EAAE,MAAM,QAAQ,KAAK;AAAA,EAC9B;AAAA,EACA,SAAS,KAAa,UAAoC,CAAC,GAAiB;AAC1E,UAAM,QAAsB,EAAE,MAAM,SAAS,QAAQ,EAAE,MAAM,OAAO,IAAI,EAAE;AAC1E,QAA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,YAAY,QAAQ,SAAS,cAAc,QAAQ,OAAO,SAAS;AAAA,IACtE,IACA;AAAA,EACN;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/completion/types.ts"],"sourcesContent":["export type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonObject | JsonValue[];\nexport type JsonObject = { [key: string]: JsonValue | undefined };\n\nexport type Document = {\n id: string;\n text: string;\n additionalProps?: Record<string, string>;\n};\n\nexport type Text = {\n type: \"text\";\n text: string;\n signature?: string;\n};\n\nexport type ImageDetail = \"auto\" | \"low\" | \"high\";\n\nexport type ImageContent = {\n type: \"image\";\n source:\n | {\n type: \"url\";\n url: string;\n }\n | {\n type: \"base64\";\n data: string;\n mediaType: string;\n };\n detail?: ImageDetail;\n};\n\nexport type DocumentContent = {\n type: \"document\";\n source:\n | {\n type: \"url\";\n url: string;\n mediaType: string;\n filename?: string;\n }\n | {\n type: \"base64\";\n data: string;\n mediaType: string;\n filename?: string;\n }\n | {\n type: \"text\";\n text: string;\n mediaType?: string;\n filename?: string;\n };\n};\n\nexport type Reasoning = {\n type: \"reasoning\";\n text: string;\n id?: string;\n content?: ReasoningContent[];\n};\n\nexport type ReasoningContent =\n | {\n type: \"text\";\n text: string;\n signature?: string;\n }\n | {\n type: \"summary\";\n text: string;\n }\n | {\n type: \"encrypted\";\n data: string;\n }\n | {\n type: \"redacted\";\n data: string;\n };\n\nexport type ReasoningContentType = ReasoningContent[\"type\"];\n\nexport type ToolFunction = {\n name: string;\n arguments: JsonValue;\n};\n\nexport type ToolCall = {\n type: \"tool_call\";\n id: string;\n callId?: string;\n function: ToolFunction;\n signature?: string;\n additionalParams?: JsonValue;\n};\n\nexport type ToolResultContent =\n | { type: \"text\"; text: string }\n | { type: \"image\"; data: string; mediaType?: string };\n\nexport type ToolResult = {\n type: \"tool_result\";\n id: string;\n callId?: string;\n content: ToolResultContent[];\n};\n\nexport type UserContent = Text | ImageContent | DocumentContent;\nexport type AssistantContent = Text | ToolCall | Reasoning | ImageContent;\nexport type ToolContent = ToolResult;\n\nexport type SystemMessage = {\n role: \"system\";\n content: string;\n};\n\nexport type UserMessage = {\n role: \"user\";\n content: UserContent[];\n};\n\nexport type AssistantMessage = {\n role: \"assistant\";\n id?: string;\n content: AssistantContent[];\n};\n\nexport type ToolMessage = {\n role: \"tool\";\n content: ToolContent[];\n};\n\nexport type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage;\n\nexport const UserContent = {\n text(text: string): Text {\n return { type: \"text\", text };\n },\n imageUrl(url: string, options: { detail?: ImageDetail } = {}): ImageContent {\n const image: ImageContent = { type: \"image\", source: { type: \"url\", url } };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n imageBase64(\n data: string,\n mediaType: string,\n options: { detail?: ImageDetail } = {},\n ): ImageContent {\n const image: ImageContent = {\n type: \"image\",\n source: { type: \"base64\", data, mediaType },\n };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n documentUrl(\n url: string,\n mediaType: string,\n options: { filename?: string | undefined } = {},\n ): DocumentContent {\n return {\n type: \"document\",\n source:\n options.filename === undefined\n ? { type: \"url\", url, mediaType }\n : { type: \"url\", url, mediaType, filename: options.filename },\n };\n },\n documentBase64(\n data: string,\n mediaType: string,\n options: { filename?: string | undefined } = {},\n ): DocumentContent {\n return {\n type: \"document\",\n source:\n options.filename === undefined\n ? { type: \"base64\", data, mediaType }\n : { type: \"base64\", data, mediaType, filename: options.filename },\n };\n },\n documentText(text: string): Text {\n return { type: \"text\", text };\n },\n};\n\nexport const ToolContent = {\n toolResult(id: string, content: string | ToolResultContent[], callId?: string): ToolResult {\n const normalized =\n typeof content === \"string\" ? [{ type: \"text\" as const, text: content }] : content;\n return callId === undefined\n ? { type: \"tool_result\", id, content: normalized }\n : { type: \"tool_result\", id, callId, content: normalized };\n },\n};\n\nexport function serializeToolResultOutput(output: unknown): string {\n if (typeof output === \"string\") {\n return output;\n }\n\n try {\n const serialized = JSON.stringify(output);\n return serialized === undefined ? String(output) : serialized;\n } catch {\n return String(output);\n }\n}\n\nexport function isToolResultContentArray(value: unknown): value is ToolResultContent[] {\n return (\n Array.isArray(value) &&\n value.length > 0 &&\n value.every((item) => {\n if (typeof item !== \"object\" || item === null || !(\"type\" in item)) {\n return false;\n }\n if (item.type === \"text\") {\n return \"text\" in item && typeof item.text === \"string\";\n }\n if (item.type === \"image\") {\n return (\n \"data\" in item &&\n typeof item.data === \"string\" &&\n (!(\"mediaType\" in item) ||\n item.mediaType === undefined ||\n typeof item.mediaType === \"string\")\n );\n }\n return false;\n })\n );\n}\n\nexport const AssistantContent = {\n text(text: string): Text {\n return { type: \"text\", text };\n },\n imageUrl(url: string, options: { detail?: ImageDetail } = {}): ImageContent {\n const image: ImageContent = { type: \"image\", source: { type: \"url\", url } };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n imageBase64(\n data: string,\n mediaType: string,\n options: { detail?: ImageDetail } = {},\n ): ImageContent {\n const image: ImageContent = {\n type: \"image\",\n source: { type: \"base64\", data, mediaType },\n };\n if (options.detail !== undefined) {\n image.detail = options.detail;\n }\n return image;\n },\n reasoning(text: string, id?: string): Reasoning {\n return id === undefined ? { type: \"reasoning\", text } : { type: \"reasoning\", text, id };\n },\n reasoningFromContent(content: ReasoningContent[], id?: string): Reasoning {\n const text = reasoningDisplayText(content);\n const reasoning: Reasoning = { type: \"reasoning\", text, content };\n return id === undefined ? reasoning : { ...reasoning, id };\n },\n reasoningSummary(text: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"summary\", text }], id);\n },\n reasoningEncrypted(data: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"encrypted\", data }], id);\n },\n reasoningRedacted(data: string, id?: string): Reasoning {\n return AssistantContent.reasoningFromContent([{ type: \"redacted\", data }], id);\n },\n toolCall(id: string, name: string, args: JsonValue, callId?: string): ToolCall {\n const base: ToolCall = {\n type: \"tool_call\",\n id,\n function: {\n name,\n arguments: args,\n },\n };\n return callId === undefined ? base : { ...base, callId };\n },\n};\n\nexport function reasoningDisplayText(reasoning: Reasoning | ReasoningContent[]): string {\n const content = Array.isArray(reasoning) ? reasoning : reasoning.content;\n if (content === undefined) {\n return Array.isArray(reasoning) ? \"\" : reasoning.text;\n }\n return content\n .flatMap((item) => {\n if (item.type === \"text\" || item.type === \"summary\") {\n return [item.text];\n }\n return [];\n })\n .join(\"\");\n}\n\nexport const Message = {\n system(content: string): Message {\n return { role: \"system\", content };\n },\n user(content: string | UserContent[]): Message {\n return {\n role: \"user\",\n content: typeof content === \"string\" ? [UserContent.text(content)] : content,\n };\n },\n assistant(content: string | AssistantContent[], id?: string): Message {\n const normalized = typeof content === \"string\" ? [AssistantContent.text(content)] : content;\n return id === undefined\n ? { role: \"assistant\", content: normalized }\n : { role: \"assistant\", id, content: normalized };\n },\n tool(content: ToolContent | ToolContent[]): Message {\n return {\n role: \"tool\",\n content: Array.isArray(content) ? content : [content],\n };\n },\n toolResult(id: string, output: unknown, options: { callId?: string | undefined } = {}): Message {\n const content = isToolResultContentArray(output) ? output : serializeToolResultOutput(output);\n return Message.tool(ToolContent.toolResult(id, content, options.callId));\n },\n};\n\nexport type ToolChoice =\n | \"auto\"\n | \"required\"\n | \"none\"\n | {\n type: \"function\";\n name: string;\n };\n\nexport type ToolDefinition = {\n name: string;\n description: string;\n parameters: JsonObject;\n};\n\nexport type Usage = {\n inputTokens: number;\n outputTokens: number;\n totalTokens: number;\n cachedInputTokens: number;\n cacheCreationInputTokens: number;\n};\n\nexport const Usage = {\n empty(): Usage {\n return {\n inputTokens: 0,\n outputTokens: 0,\n totalTokens: 0,\n cachedInputTokens: 0,\n cacheCreationInputTokens: 0,\n };\n },\n add(left: Usage, right: Usage): Usage {\n return {\n inputTokens: left.inputTokens + right.inputTokens,\n outputTokens: left.outputTokens + right.outputTokens,\n totalTokens: left.totalTokens + right.totalTokens,\n cachedInputTokens: left.cachedInputTokens + right.cachedInputTokens,\n cacheCreationInputTokens: left.cacheCreationInputTokens + right.cacheCreationInputTokens,\n };\n },\n};\n\nexport type CompletionRequest<ModelName extends string = string> = {\n model?: ModelName;\n instructions?: string;\n chatHistory: Message[];\n documents: Document[];\n tools: ToolDefinition[];\n temperature?: number;\n maxTokens?: number;\n toolChoice?: ToolChoice;\n additionalParams?: JsonValue;\n outputSchema?: JsonObject;\n};\n\nexport type CompletionResponse<RawResponse = unknown> = {\n choice: AssistantContent[];\n usage: Usage;\n rawResponse: RawResponse;\n messageId?: string;\n};\n\nexport type CompletionModelCapabilities = {\n streaming: boolean;\n tools: boolean;\n toolChoice: boolean;\n imageInput: boolean;\n documentInput: boolean;\n outputSchema: boolean;\n reasoning: boolean;\n};\n\nexport interface CompletionModel<RawResponse = unknown, ModelName extends string = string> {\n readonly provider: string;\n readonly defaultModel: ModelName;\n readonly capabilities: CompletionModelCapabilities;\n traceRequest?(\n request: CompletionRequest<ModelName>,\n options?: { stream?: boolean | undefined },\n ): JsonObject | undefined;\n completion(request: CompletionRequest<ModelName>): Promise<CompletionResponse<RawResponse>>;\n}\n\nexport type CompletionStreamEvent<RawResponse = unknown> =\n | {\n type: \"text_delta\";\n delta: string;\n }\n | {\n type: \"reasoning_delta\";\n delta: string;\n id?: string;\n contentType?: ReasoningContentType;\n signature?: string;\n }\n | {\n type: \"tool_call_delta\";\n id: string;\n callId?: string;\n name?: string;\n argumentsDelta?: string;\n signature?: string;\n }\n | {\n type: \"tool_call\";\n toolCall: ToolCall;\n }\n | {\n type: \"message_id\";\n id: string;\n }\n | {\n type: \"final\";\n response: CompletionResponse<RawResponse>;\n }\n | {\n type: \"error\";\n error: unknown;\n };\n\nexport interface StreamingCompletionModel<RawResponse = unknown, ModelName extends string = string>\n extends CompletionModel<RawResponse, ModelName> {\n streamCompletion(\n request: CompletionRequest<ModelName>,\n ): AsyncIterable<CompletionStreamEvent<RawResponse>>;\n}\n\nexport class CompletionCapabilityError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"CompletionCapabilityError\";\n }\n}\n\nexport function assertCompletionRequestSupported(\n model: CompletionModel,\n request: CompletionRequest,\n options: { streaming?: boolean | undefined } = {},\n): void {\n const modelLabel = `${model.provider}:${request.model ?? model.defaultModel}`;\n const capabilities = model.capabilities;\n\n if (options.streaming === true && !capabilities.streaming) {\n throw new CompletionCapabilityError(`${modelLabel} does not support streaming completions.`);\n }\n\n if (request.tools.length > 0 && !capabilities.tools) {\n throw new CompletionCapabilityError(`${modelLabel} does not support tool definitions.`);\n }\n\n if (request.toolChoice !== undefined && !capabilities.toolChoice) {\n throw new CompletionCapabilityError(`${modelLabel} does not support tool choice.`);\n }\n\n if (request.outputSchema !== undefined && !capabilities.outputSchema) {\n throw new CompletionCapabilityError(`${modelLabel} does not support output schemas.`);\n }\n\n if (!capabilities.imageInput && requestHasImageInput(request)) {\n throw new CompletionCapabilityError(`${modelLabel} does not support image input.`);\n }\n\n if (!capabilities.documentInput && requestHasFileDocumentInput(request)) {\n throw new CompletionCapabilityError(`${modelLabel} does not support document file input.`);\n }\n}\n\nexport function textFromAssistantContent(content: AssistantContent[]): string {\n return content.flatMap((item) => (item.type === \"text\" ? [item.text] : [])).join(\"\\n\");\n}\n\nfunction requestHasImageInput(request: CompletionRequest): boolean {\n return request.chatHistory.some((message) =>\n message.role === \"system\" ? false : message.content.some((content) => content.type === \"image\"),\n );\n}\n\nfunction requestHasFileDocumentInput(request: CompletionRequest): boolean {\n return request.chatHistory.some((message) =>\n message.role === \"user\"\n ? message.content.some(\n (content) => content.type === \"document\" && content.source.type !== \"text\",\n )\n : false,\n );\n}\n"],"mappings":";AAwIO,IAAM,cAAc;AAAA,EACzB,KAAK,MAAoB;AACvB,WAAO,EAAE,MAAM,QAAQ,KAAK;AAAA,EAC9B;AAAA,EACA,SAAS,KAAa,UAAoC,CAAC,GAAiB;AAC1E,UAAM,QAAsB,EAAE,MAAM,SAAS,QAAQ,EAAE,MAAM,OAAO,IAAI,EAAE;AAC1E,QAAI,QAAQ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QAAQ,SAAS,cAAc,QAAQ,OAAO,SAAS;AAAA,IACtE,IACA;AAAA,EACN;AACF;","names":[]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
UserContent,
|
|
6
6
|
reasoningDisplayText,
|
|
7
7
|
serializeToolResultOutput
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-5LFGEMIW.js";
|
|
9
9
|
|
|
10
10
|
// src/ui/messages.ts
|
|
11
11
|
function uiMessagesToCoreMessages(messages) {
|
|
@@ -262,4 +262,4 @@ export {
|
|
|
262
262
|
uiMessagesToCoreMessages,
|
|
263
263
|
coreMessagesToUIMessages
|
|
264
264
|
};
|
|
265
|
-
//# sourceMappingURL=chunk-
|
|
265
|
+
//# sourceMappingURL=chunk-JNO4AR7Q.js.map
|