@anvia/core 0.11.1 → 0.11.3
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 +13 -31
- package/dist/agent/index.js +14 -36
- package/dist/{agent-DoF-xWGj.d.ts → agent-Bcpuodu2.d.ts} +8 -125
- package/dist/audio-generation/index.d.ts +4 -3
- package/dist/audio-generation/index.js +1 -1
- package/dist/audio-generation/index.js.map +1 -1
- package/dist/{chunk-VJ7AZVLS.js → chunk-2GXGB6U5.js} +6 -6
- package/dist/chunk-2GXGB6U5.js.map +1 -0
- package/dist/{chunk-T22FYPE2.js → chunk-5EDHXYH5.js} +6 -6
- 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-IFQVPV32.js → chunk-7CQAERL3.js} +318 -543
- package/dist/chunk-7CQAERL3.js.map +1 -0
- package/dist/{chunk-BVGDCFQW.js → chunk-FV5B4SGK.js} +7 -7
- package/dist/{chunk-AREAH2X5.js → chunk-JNO4AR7Q.js} +4 -240
- package/dist/chunk-JNO4AR7Q.js.map +1 -0
- package/dist/{chunk-W4DZU6IW.js → chunk-JS5MGVNM.js} +50 -48
- package/dist/chunk-JS5MGVNM.js.map +1 -0
- package/dist/{chunk-XXT2UCAR.js → chunk-M6RPFHG7.js} +2 -2
- package/dist/chunk-M6RPFHG7.js.map +1 -0
- package/dist/chunk-MLMXQ2OV.js +205 -0
- package/dist/chunk-MLMXQ2OV.js.map +1 -0
- package/dist/{chunk-M4T4ID34.js → chunk-NI637AGP.js} +6 -6
- package/dist/chunk-NI637AGP.js.map +1 -0
- package/dist/chunk-NPZDYOE6.js +53 -0
- package/dist/chunk-NPZDYOE6.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-246MPVBE.js → chunk-V3WTT7TE.js} +2 -2
- package/dist/completion/index.d.ts +8 -6
- package/dist/completion/index.js +2 -2
- package/dist/{create-completion-7GNUka0b.d.ts → create-completion-Y6YsYbQB.d.ts} +2 -2
- package/dist/embeddings/index.d.ts +6 -5
- package/dist/embeddings/index.js +1 -1
- package/dist/evals/index.d.ts +9 -9
- package/dist/evals/index.js +16 -14
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +9 -9
- package/dist/extractor/index.js +14 -12
- package/dist/hooks/index.d.ts +12 -0
- package/dist/hooks/index.js +18 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/image-generation/index.d.ts +4 -3
- package/dist/image-generation/index.js +1 -1
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index-CD9jb9Or.d.ts +198 -0
- package/dist/index.d.ts +17 -15
- package/dist/index.js +26 -31
- package/dist/internal/agent.d.ts +9 -9
- package/dist/internal/agent.js +11 -9
- package/dist/loaders/index.d.ts +8 -7
- package/dist/loaders/index.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/memory/index.d.ts +4 -40
- package/dist/memory/index.js +1 -1
- package/dist/{middleware-D7nRBusA.d.ts → middleware-ByyL6Rj0.d.ts} +4 -4
- package/dist/model-listing/index.d.ts +14 -12
- package/dist/model-listing/index.js +1 -1
- package/dist/model-listing/index.js.map +1 -1
- package/dist/observability/index.d.ts +3 -138
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +9 -9
- package/dist/pipeline/index.js +3 -3
- package/dist/request/index.d.ts +27 -0
- package/dist/request/index.js +23 -0
- package/dist/request/index.js.map +1 -0
- package/dist/skills/index.d.ts +4 -4
- package/dist/skills/index.js +7 -7
- package/dist/{think-tool-DmBR-YzU.d.ts → think-tool-B065hm73.d.ts} +1 -1
- package/dist/tool/index.d.ts +6 -6
- package/dist/tool/index.js +6 -6
- package/dist/{tool-Hlcb459D.d.ts → tool-B8K543oQ.d.ts} +1 -1
- package/dist/transcription/index.d.ts +3 -3
- package/dist/{types-CiFIAGqq.d.ts → types-7F_IKQQW.d.ts} +2 -2
- package/dist/{types-DrkBkjzk.d.ts → types-BzUuhjKr.d.ts} +1 -1
- package/dist/types-CGML74sE.d.ts +114 -0
- package/dist/types-CqG6d7Ce.d.ts +42 -0
- package/dist/{types-IB2e9u5M.d.ts → types-DHHZztGO.d.ts} +1 -1
- package/dist/{types-B0cuzkjP.d.ts → types-Pl4PFQWL.d.ts} +2 -2
- package/dist/{types-CP3iyh6j.d.ts → types-q9G7Bvwl.d.ts} +9 -9
- package/dist/ui/index.d.ts +2 -28
- package/dist/ui/index.js +2 -12
- package/dist/vector-store/index.d.ts +5 -5
- package/dist/vector-store/index.js +4 -4
- package/package.json +10 -2
- package/dist/chunk-5G3VME2D.js.map +0 -1
- package/dist/chunk-AREAH2X5.js.map +0 -1
- package/dist/chunk-IFQVPV32.js.map +0 -1
- package/dist/chunk-M4T4ID34.js.map +0 -1
- package/dist/chunk-VJ7AZVLS.js.map +0 -1
- package/dist/chunk-W4DZU6IW.js.map +0 -1
- package/dist/chunk-XXT2UCAR.js.map +0 -1
- package/dist/types-C2ArxcON.d.ts +0 -65
- /package/dist/{chunk-T22FYPE2.js.map → chunk-5EDHXYH5.js.map} +0 -0
- /package/dist/{chunk-BVGDCFQW.js.map → chunk-FV5B4SGK.js.map} +0 -0
- /package/dist/{chunk-246MPVBE.js.map → chunk-V3WTT7TE.js.map} +0 -0
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,38 +1,20 @@
|
|
|
1
|
-
import { D as DynamicContextOptions,
|
|
2
|
-
export {
|
|
3
|
-
import { M as Message, C as CompletionModel, e as JsonValue, o as ToolChoice } from '../types-CP3iyh6j.js';
|
|
4
|
-
import { d as ToolApprovalRequest, A as AnyTool, e as ToolApprovalsOptions } from '../tool-Hlcb459D.js';
|
|
5
|
-
export { b as ToolApprovalDecision } from '../tool-Hlcb459D.js';
|
|
6
|
-
export { A as AgentChildStreamEvent, a as AgentStreamEvent, P as PromptResponse } from '../types-C2ArxcON.js';
|
|
7
|
-
import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-D7nRBusA.js';
|
|
8
|
-
export { C as CompletionRequestMiddlewareArgs, a as CompletionRequestMiddlewareResult, b as CompletionResponseMiddlewareArgs, c as CompletionResponseMiddlewareResult, T as ToolInputMiddlewareArgs, d as ToolInputMiddlewareResult, f as ToolOutputMiddlewareArgs, g as ToolOutputMiddlewareResult, h as ToolResultMiddlewareArgs, i as createMiddleware, j as createToolMiddleware } from '../middleware-D7nRBusA.js';
|
|
1
|
+
import { D as DynamicContextOptions, a as DynamicToolOptions, b as AgentEventStore, c as AgentEventStoreOptions, A as Agent } from '../agent-Bcpuodu2.js';
|
|
2
|
+
export { d as AgentEventAppendInput, e as AgentEventRecord, f as AgentEventStoreInclude, g as AgentSession, h as AgentToolOptions } from '../agent-Bcpuodu2.js';
|
|
9
3
|
import { Z as ZodSchema } from '../zod-schema-C7F4clpm.js';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { a as
|
|
14
|
-
import {
|
|
15
|
-
import '../types-
|
|
4
|
+
import { C as CompletionModel, e as JsonValue, n as ToolChoice } from '../types-q9G7Bvwl.js';
|
|
5
|
+
import { P as PromptHook } from '../types-CGML74sE.js';
|
|
6
|
+
import { a as McpServer } from '../types-7F_IKQQW.js';
|
|
7
|
+
import { M as MemoryStore, a as MemoryOptions } from '../types-CqG6d7Ce.js';
|
|
8
|
+
import { b as AgentObserver, O as ObserveOptions } from '../index-CD9jb9Or.js';
|
|
9
|
+
import { a as SkillSet } from '../types-BzUuhjKr.js';
|
|
10
|
+
import { k as ToolSearchDocument, l as ToolSet, A as AgentMiddleware, e as ToolMiddleware } from '../middleware-ByyL6Rj0.js';
|
|
11
|
+
import { A as AnyTool, e as ToolApprovalsOptions } from '../tool-B8K543oQ.js';
|
|
12
|
+
import { a as VectorSearchIndex } from '../types-Pl4PFQWL.js';
|
|
16
13
|
import 'zod';
|
|
17
14
|
import '@modelcontextprotocol/sdk/client/sse.js';
|
|
18
15
|
import '@modelcontextprotocol/sdk/client/stdio.js';
|
|
19
16
|
import '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
20
|
-
|
|
21
|
-
declare class MaxTurnsError extends Error {
|
|
22
|
-
readonly maxTurns: number;
|
|
23
|
-
readonly chatHistory: Message[];
|
|
24
|
-
readonly prompt: Message;
|
|
25
|
-
constructor(maxTurns: number, chatHistory: Message[], prompt: Message);
|
|
26
|
-
}
|
|
27
|
-
declare class PromptCancelledError extends Error {
|
|
28
|
-
readonly chatHistory: Message[];
|
|
29
|
-
readonly reason: string;
|
|
30
|
-
constructor(chatHistory: Message[], reason: string);
|
|
31
|
-
}
|
|
32
|
-
declare class ToolApprovalRequiredError extends Error {
|
|
33
|
-
readonly request: ToolApprovalRequest;
|
|
34
|
-
constructor(request: ToolApprovalRequest);
|
|
35
|
-
}
|
|
17
|
+
import '../types-DHHZztGO.js';
|
|
36
18
|
|
|
37
19
|
declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
38
20
|
private readonly completionModel;
|
|
@@ -94,4 +76,4 @@ declare class AgentBuilder<M extends CompletionModel = CompletionModel> {
|
|
|
94
76
|
private buildInstructions;
|
|
95
77
|
}
|
|
96
78
|
|
|
97
|
-
export { AgentBuilder, AgentEventStore, AgentEventStoreOptions,
|
|
79
|
+
export { Agent, AgentBuilder, AgentEventStore, AgentEventStoreOptions, DynamicContextOptions, DynamicToolOptions };
|
package/dist/agent/index.js
CHANGED
|
@@ -1,43 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBuilder
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
PromptCancelledError,
|
|
7
|
-
ToolApprovalRequiredError,
|
|
8
|
-
cancelPrompt,
|
|
9
|
-
createHook,
|
|
10
|
-
requestToolApproval,
|
|
11
|
-
runControl,
|
|
12
|
-
skipTool,
|
|
13
|
-
toolCallControl
|
|
14
|
-
} from "../chunk-IFQVPV32.js";
|
|
15
|
-
import "../chunk-XUUY2L2D.js";
|
|
16
|
-
import "../chunk-XXT2UCAR.js";
|
|
3
|
+
} from "../chunk-NI637AGP.js";
|
|
4
|
+
import "../chunk-MLMXQ2OV.js";
|
|
5
|
+
import "../chunk-7CQAERL3.js";
|
|
17
6
|
import "../chunk-YK4WAAS4.js";
|
|
18
|
-
import
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import "../chunk-
|
|
23
|
-
import "../chunk-MMHG7WAM.js";
|
|
24
|
-
import "../chunk-5G3VME2D.js";
|
|
25
|
-
import "../chunk-WJO6NVE2.js";
|
|
26
|
-
import "../chunk-WQKHFADH.js";
|
|
27
|
-
import "../chunk-W4DZU6IW.js";
|
|
7
|
+
import "../chunk-XUUY2L2D.js";
|
|
8
|
+
import "../chunk-FV5B4SGK.js";
|
|
9
|
+
import "../chunk-5EDHXYH5.js";
|
|
10
|
+
import "../chunk-M6RPFHG7.js";
|
|
11
|
+
import "../chunk-JS5MGVNM.js";
|
|
28
12
|
import "../chunk-OIMLU4SF.js";
|
|
13
|
+
import "../chunk-SRBW3LD7.js";
|
|
14
|
+
import "../chunk-5LFGEMIW.js";
|
|
15
|
+
import "../chunk-WQKHFADH.js";
|
|
16
|
+
import "../chunk-NPZDYOE6.js";
|
|
17
|
+
import "../chunk-MMHG7WAM.js";
|
|
29
18
|
export {
|
|
30
|
-
AgentBuilder
|
|
31
|
-
MaxTurnsError,
|
|
32
|
-
PromptCancelledError,
|
|
33
|
-
ToolApprovalRequiredError,
|
|
34
|
-
cancelPrompt,
|
|
35
|
-
createHook,
|
|
36
|
-
createMiddleware,
|
|
37
|
-
createToolMiddleware,
|
|
38
|
-
requestToolApproval,
|
|
39
|
-
runControl,
|
|
40
|
-
skipTool,
|
|
41
|
-
toolCallControl
|
|
19
|
+
AgentBuilder
|
|
42
20
|
};
|
|
43
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,127 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
type HookAction = {
|
|
10
|
-
type: "continue";
|
|
11
|
-
} | {
|
|
12
|
-
type: "terminate";
|
|
13
|
-
reason: string;
|
|
14
|
-
};
|
|
15
|
-
type ToolApprovalRequestOptions = {
|
|
16
|
-
reason?: string;
|
|
17
|
-
rejectMessage?: string;
|
|
18
|
-
};
|
|
19
|
-
type ToolCallHookAction = {
|
|
20
|
-
type: "continue";
|
|
21
|
-
} | {
|
|
22
|
-
type: "skip";
|
|
23
|
-
reason: string;
|
|
24
|
-
} | {
|
|
25
|
-
type: "terminate";
|
|
26
|
-
reason: string;
|
|
27
|
-
} | ({
|
|
28
|
-
type: "approval_request";
|
|
29
|
-
} & ToolApprovalRequestOptions);
|
|
30
|
-
type RunControl = {
|
|
31
|
-
continue(): HookAction;
|
|
32
|
-
cancel(reason: string): HookAction;
|
|
33
|
-
};
|
|
34
|
-
type ToolCallControl = {
|
|
35
|
-
run(): ToolCallHookAction;
|
|
36
|
-
skip(reason: string): ToolCallHookAction;
|
|
37
|
-
cancel(reason: string): ToolCallHookAction;
|
|
38
|
-
requestApproval(options?: ToolApprovalRequestOptions): ToolCallHookAction;
|
|
39
|
-
};
|
|
40
|
-
type HookResult = HookAction | undefined;
|
|
41
|
-
type ToolCallHookResult = ToolCallHookAction | undefined;
|
|
42
|
-
type HookCallback<Args> = (args: Args) => HookAction | Promise<HookAction | undefined> | Promise<void> | void;
|
|
43
|
-
type ToolCallHookCallback<Args> = (args: Args) => ToolCallHookAction | Promise<ToolCallHookAction | undefined> | Promise<void> | void;
|
|
44
|
-
type CompletionCallHookArgs = {
|
|
45
|
-
prompt: Message;
|
|
46
|
-
history: Message[];
|
|
47
|
-
run: RunControl;
|
|
48
|
-
};
|
|
49
|
-
type RunStartHookArgs = {
|
|
50
|
-
prompt: Message;
|
|
51
|
-
history: Message[];
|
|
52
|
-
maxTurns: number;
|
|
53
|
-
run: RunControl;
|
|
54
|
-
};
|
|
55
|
-
type RunEndHookArgs = {
|
|
56
|
-
output: string;
|
|
57
|
-
usage: Usage;
|
|
58
|
-
messages: Message[];
|
|
59
|
-
run: RunControl;
|
|
60
|
-
};
|
|
61
|
-
type RunErrorHookArgs = {
|
|
62
|
-
error: unknown;
|
|
63
|
-
usage: Usage;
|
|
64
|
-
messages: Message[];
|
|
65
|
-
run: RunControl;
|
|
66
|
-
};
|
|
67
|
-
type TurnStartHookArgs = {
|
|
68
|
-
turn: number;
|
|
69
|
-
prompt: Message;
|
|
70
|
-
history: Message[];
|
|
71
|
-
run: RunControl;
|
|
72
|
-
};
|
|
73
|
-
type TurnEndHookArgs<RawResponse = unknown> = {
|
|
74
|
-
turn: number;
|
|
75
|
-
response: CompletionResponse<RawResponse>;
|
|
76
|
-
run: RunControl;
|
|
77
|
-
};
|
|
78
|
-
type CompletionResponseHookArgs<RawResponse = unknown> = {
|
|
79
|
-
prompt: Message;
|
|
80
|
-
response: CompletionResponse<RawResponse>;
|
|
81
|
-
run: RunControl;
|
|
82
|
-
};
|
|
83
|
-
type CompletionErrorHookArgs = {
|
|
84
|
-
prompt: Message;
|
|
85
|
-
error: unknown;
|
|
86
|
-
run: RunControl;
|
|
87
|
-
};
|
|
88
|
-
type ToolHookArgs = {
|
|
89
|
-
toolName: string;
|
|
90
|
-
toolCallId?: string;
|
|
91
|
-
internalCallId: string;
|
|
92
|
-
args: string;
|
|
93
|
-
};
|
|
94
|
-
type ToolCallHookArgs = ToolHookArgs & {
|
|
95
|
-
tool: ToolCallControl;
|
|
96
|
-
};
|
|
97
|
-
type ToolResultHookArgs = ToolHookArgs & {
|
|
98
|
-
result: string;
|
|
99
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
100
|
-
run: RunControl;
|
|
101
|
-
};
|
|
102
|
-
type ToolErrorHookArgs = ToolHookArgs & {
|
|
103
|
-
error: unknown;
|
|
104
|
-
run: RunControl;
|
|
105
|
-
};
|
|
106
|
-
declare function createHook<RawResponse = unknown>(hook: PromptHook<RawResponse>): PromptHook<RawResponse>;
|
|
107
|
-
declare function cancelPrompt(reason: string): HookAction;
|
|
108
|
-
declare function skipTool(reason: string): ToolCallHookAction;
|
|
109
|
-
declare function requestToolApproval(options?: ToolApprovalRequestOptions): ToolCallHookAction;
|
|
110
|
-
declare const runControl: RunControl;
|
|
111
|
-
declare const toolCallControl: ToolCallControl;
|
|
112
|
-
interface PromptHook<RawResponse = unknown> {
|
|
113
|
-
onRunStart?: HookCallback<RunStartHookArgs>;
|
|
114
|
-
onRunEnd?: HookCallback<RunEndHookArgs>;
|
|
115
|
-
onRunError?: HookCallback<RunErrorHookArgs>;
|
|
116
|
-
onTurnStart?: HookCallback<TurnStartHookArgs>;
|
|
117
|
-
onTurnEnd?: HookCallback<TurnEndHookArgs<RawResponse>>;
|
|
118
|
-
onCompletionCall?: HookCallback<CompletionCallHookArgs>;
|
|
119
|
-
onCompletionResponse?: HookCallback<CompletionResponseHookArgs<RawResponse>>;
|
|
120
|
-
onCompletionError?: HookCallback<CompletionErrorHookArgs>;
|
|
121
|
-
onToolCall?: ToolCallHookCallback<ToolCallHookArgs>;
|
|
122
|
-
onToolResult?: HookCallback<ToolResultHookArgs>;
|
|
123
|
-
onToolError?: HookCallback<ToolErrorHookArgs>;
|
|
124
|
-
}
|
|
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 { P as PromptHook } from './types-CGML74sE.js';
|
|
3
|
+
import { c as MemoryContext, e as MemoryRegistration, S as SessionOptions } from './types-CqG6d7Ce.js';
|
|
4
|
+
import { c as AgentTraceOptions, P as PromptResponse, a as AgentStreamEvent, d as AgentObserverRegistration } from './index-CD9jb9Or.js';
|
|
5
|
+
import { e as ToolApprovalsOptions, T as Tool, A as AnyTool, f as ToolCallContext, N as NormalizedToolOutput } from './tool-B8K543oQ.js';
|
|
6
|
+
import { A as AgentMiddleware, e as ToolMiddleware, k as ToolSearchDocument, l as ToolSet } from './middleware-ByyL6Rj0.js';
|
|
7
|
+
import { V as VectorFilter, c as VectorSearchResult, a as VectorSearchIndex } from './types-Pl4PFQWL.js';
|
|
125
8
|
|
|
126
9
|
declare class PromptRequest<M extends CompletionModel = CompletionModel> {
|
|
127
10
|
private readonly agent;
|
|
@@ -316,4 +199,4 @@ declare class AgentSession<M extends CompletionModel = CompletionModel> {
|
|
|
316
199
|
clear(): Promise<void>;
|
|
317
200
|
}
|
|
318
201
|
|
|
319
|
-
export { Agent as A, type
|
|
202
|
+
export { Agent as A, type DynamicContextOptions as D, PromptRequest as P, type DynamicToolOptions as a, type AgentEventStore as b, type AgentEventStoreOptions as c, type AgentEventAppendInput as d, type AgentEventRecord as e, type AgentEventStoreInclude as f, AgentSession as g, type AgentToolOptions as h, type AgentEventStoreRegistration as i, type AgentOptions as j, DEFAULT_MAX_TURNS as k, type DynamicContextRegistration as l, type DynamicToolRegistration as m };
|
|
@@ -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,11 +11,12 @@ 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
20
|
declare class AudioGenerationRequestBuilder<Model extends AudioGenerationModel = AudioGenerationModel> {
|
|
20
21
|
private readonly model;
|
|
21
22
|
private request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/audio-generation/
|
|
1
|
+
{"version":3,"sources":["../../src/audio-generation/request.ts"],"sourcesContent":["import type { JsonValue } from \"../completion/types\";\nimport type { AudioGenerationModel, AudioGenerationRequest } from \"./types\";\n\nexport class AudioGenerationRequestBuilder<\n Model extends AudioGenerationModel = AudioGenerationModel,\n> {\n private request: AudioGenerationRequest = {\n text: \"\",\n voice: \"\",\n speed: 1,\n };\n\n constructor(private readonly model: Model) {}\n\n text(text: string): this {\n this.request = { ...this.request, text };\n return this;\n }\n\n voice(voice: string): this {\n this.request = { ...this.request, voice };\n return this;\n }\n\n speed(speed: number): this {\n this.request = { ...this.request, speed };\n return this;\n }\n\n additionalParams(additionalParams: JsonValue): this {\n this.request = { ...this.request, additionalParams };\n return this;\n }\n\n build(): AudioGenerationRequest {\n return { ...this.request };\n }\n\n send(): Promise<Awaited<ReturnType<Model[\"audioGeneration\"]>>> {\n return this.model.audioGeneration(this.build()) as Promise<\n Awaited<ReturnType<Model[\"audioGeneration\"]>>\n >;\n }\n}\n\nexport function audioGenerationRequest<Model extends AudioGenerationModel>(\n model: Model,\n): AudioGenerationRequestBuilder<Model> {\n return new AudioGenerationRequestBuilder(model);\n}\n"],"mappings":";AAGO,IAAM,gCAAN,MAEL;AAAA,EAOA,YAA6B,OAAc;AAAd;AAAA,EAAe;AAAA,EAAf;AAAA,EANrB,UAAkC;AAAA,IACxC,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EAIA,KAAK,MAAoB;AACvB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,KAAK;AACvC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAqB;AACzB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,MAAM;AACxC,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAqB;AACzB,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,MAAM;AACxC,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,kBAAmC;AAClD,SAAK,UAAU,EAAE,GAAG,KAAK,SAAS,iBAAiB;AACnD,WAAO;AAAA,EACT;AAAA,EAEA,QAAgC;AAC9B,WAAO,EAAE,GAAG,KAAK,QAAQ;AAAA,EAC3B;AAAA,EAEA,OAA+D;AAC7D,WAAO,KAAK,MAAM,gBAAgB,KAAK,MAAM,CAAC;AAAA,EAGhD;AACF;AAEO,SAAS,uBACd,OACsC;AACtC,SAAO,IAAI,8BAA8B,KAAK;AAChD;","names":[]}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBuilder
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NI637AGP.js";
|
|
4
4
|
import {
|
|
5
5
|
extractRagText
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7CQAERL3.js";
|
|
7
7
|
import {
|
|
8
8
|
createTool
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-5EDHXYH5.js";
|
|
10
10
|
import {
|
|
11
11
|
CompletionRequestBuilder
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-SRBW3LD7.js";
|
|
13
13
|
import {
|
|
14
14
|
CompletionCapabilityError,
|
|
15
15
|
Message,
|
|
16
16
|
Usage
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-5LFGEMIW.js";
|
|
18
18
|
|
|
19
19
|
// src/extractor/extractor.ts
|
|
20
20
|
var SUBMIT_TOOL_NAME = "submit";
|
|
@@ -138,4 +138,4 @@ export {
|
|
|
138
138
|
Extractor,
|
|
139
139
|
ExtractorBuilder
|
|
140
140
|
};
|
|
141
|
-
//# sourceMappingURL=chunk-
|
|
141
|
+
//# sourceMappingURL=chunk-2GXGB6U5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/extractor/extractor.ts"],"sourcesContent":["import type { Agent } from \"../agent/agent\";\nimport { AgentBuilder } from \"../agent/builder\";\nimport {\n CompletionCapabilityError,\n type CompletionModel,\n CompletionRequestBuilder,\n type CompletionResponse,\n type JsonValue,\n type Message,\n Message as MessageFactory,\n type ToolChoice,\n Usage,\n} from \"../completion/index\";\nimport { extractRagText } from \"../internal/rag-text\";\nimport type { ZodSchema } from \"../schema/zod-schema\";\nimport { createTool } from \"../tool/index\";\n\nconst SUBMIT_TOOL_NAME = \"submit\";\n\nconst DEFAULT_EXTRACTOR_INSTRUCTIONS =\n \"You are an AI assistant whose purpose is to extract structured data from the provided text.\\n\" +\n \"You have access to a `submit` function that defines the structure of the data to extract.\\n\" +\n \"Always call the `submit` function with the structured data. Use default or null values when information is missing.\";\n\nexport type ExtractionResponse<T> = {\n data: T;\n usage: Usage;\n messages: Message[];\n};\n\nexport class ExtractionError extends Error {\n constructor(\n message: string,\n readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"ExtractionError\";\n }\n}\n\nexport class Extractor<T, M extends CompletionModel = CompletionModel> {\n constructor(\n private readonly agent: Agent<M>,\n private readonly schema: ZodSchema<T>,\n private readonly retryCount: number,\n ) {}\n\n async extract(text: string | Message): Promise<T> {\n return (await this.extractWithUsage(text)).data;\n }\n\n async extractWithUsage(text: string | Message): Promise<ExtractionResponse<T>> {\n return this.run(text);\n }\n\n async extractWithHistory(text: string | Message, history: Message[]): Promise<T> {\n return (await this.run(text, history)).data;\n }\n\n getInner(): Agent<M> {\n return this.agent;\n }\n\n private async run(text: string | Message, history?: Message[]): Promise<ExtractionResponse<T>> {\n let usage = Usage.empty();\n let lastError: unknown;\n const prompt = typeof text === \"string\" ? MessageFactory.user(text) : text;\n\n for (let attempt = 0; attempt <= this.retryCount; attempt += 1) {\n try {\n const toolDefs = await this.agent.toolSet.getToolDefinitions(extractRagText(prompt));\n const response = await new CompletionRequestBuilder(this.agent.model, prompt)\n .instructions(this.agent.instructions)\n .messages(history ?? [])\n .documents(this.agent.staticContext)\n .tools(toolDefs)\n .temperature(this.agent.temperature)\n .maxTokens(this.agent.maxTokens)\n .additionalParams(this.agent.additionalParams)\n .toolChoice(this.agent.toolChoice)\n .send();\n usage = Usage.add(usage, response.usage);\n const data = extractSubmittedData(response, this.schema);\n return {\n data,\n usage,\n messages: [\n ...(history ?? []),\n prompt,\n MessageFactory.assistant(response.choice, response.messageId),\n ],\n };\n } catch (error) {\n if (error instanceof CompletionCapabilityError) {\n throw error;\n }\n lastError = error;\n }\n }\n\n throw new ExtractionError(\"No data extracted\", lastError);\n }\n}\n\nexport class ExtractorBuilder<T, M extends CompletionModel = CompletionModel> {\n private readonly agentBuilder: AgentBuilder<M>;\n private retryCount = 0;\n\n constructor(\n model: M,\n private readonly schema: ZodSchema<T>,\n ) {\n this.agentBuilder = new AgentBuilder(\"extractor\", model)\n .instructions(DEFAULT_EXTRACTOR_INSTRUCTIONS)\n .tool(\n createTool({\n name: SUBMIT_TOOL_NAME,\n description: \"Submit the structured data extracted from the provided text.\",\n input: schema,\n output: schema,\n execute: (args) => args,\n }),\n )\n .toolChoice(\"required\");\n }\n\n instructions(instructions: string): this {\n this.agentBuilder.instructions(instructions);\n return this;\n }\n\n context(text: string, id?: string): this {\n this.agentBuilder.context(text, id);\n return this;\n }\n\n temperature(temperature: number): this {\n this.agentBuilder.temperature(temperature);\n return this;\n }\n\n maxTokens(maxTokens: number): this {\n this.agentBuilder.maxTokens(maxTokens);\n return this;\n }\n\n additionalParams(params: JsonValue): this {\n this.agentBuilder.additionalParams(params);\n return this;\n }\n\n toolChoice(toolChoice: ToolChoice): this {\n this.agentBuilder.toolChoice(toolChoice);\n return this;\n }\n\n retries(retries: number): this {\n this.retryCount = Math.max(0, Math.trunc(retries));\n return this;\n }\n\n build(): Extractor<T, M> {\n return new Extractor(this.agentBuilder.build(), this.schema, this.retryCount);\n }\n}\n\nfunction extractSubmittedData<T>(response: CompletionResponse, schema: ZodSchema<T>): T {\n const submitted = response.choice\n .filter((content) => content.type === \"tool_call\")\n .filter((toolCall) => toolCall.function.name === SUBMIT_TOOL_NAME)\n .at(-1);\n\n if (submitted === undefined) {\n throw new ExtractionError(\"The model did not call the submit tool\");\n }\n\n return schema.parse(submitted.function.arguments);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiBA,IAAM,mBAAmB;AAEzB,IAAM,iCACJ;AAUK,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YACE,SACS,OACT;AACA,UAAM,OAAO;AAFJ;AAGT,SAAK,OAAO;AAAA,EACd;AAAA,EAJW;AAKb;AAEO,IAAM,YAAN,MAAgE;AAAA,EACrE,YACmB,OACA,QACA,YACjB;AAHiB;AACA;AACA;AAAA,EAChB;AAAA,EAHgB;AAAA,EACA;AAAA,EACA;AAAA,EAGnB,MAAM,QAAQ,MAAoC;AAChD,YAAQ,MAAM,KAAK,iBAAiB,IAAI,GAAG;AAAA,EAC7C;AAAA,EAEA,MAAM,iBAAiB,MAAwD;AAC7E,WAAO,KAAK,IAAI,IAAI;AAAA,EACtB;AAAA,EAEA,MAAM,mBAAmB,MAAwB,SAAgC;AAC/E,YAAQ,MAAM,KAAK,IAAI,MAAM,OAAO,GAAG;AAAA,EACzC;AAAA,EAEA,WAAqB;AACnB,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAc,IAAI,MAAwB,SAAqD;AAC7F,QAAI,QAAQ,MAAM,MAAM;AACxB,QAAI;AACJ,UAAM,SAAS,OAAO,SAAS,WAAW,QAAe,KAAK,IAAI,IAAI;AAEtE,aAAS,UAAU,GAAG,WAAW,KAAK,YAAY,WAAW,GAAG;AAC9D,UAAI;AACF,cAAM,WAAW,MAAM,KAAK,MAAM,QAAQ,mBAAmB,eAAe,MAAM,CAAC;AACnF,cAAM,WAAW,MAAM,IAAI,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A,YAAY,aAA2B;AACrC,SAAK,aAAa,YAAY,WAAW;AACzC,WAAO;AAAA,EACT;AAAA,EAEA,UAAU,WAAyB;AACjC,SAAK,aAAa,UAAU,SAAS;AACrC,WAAO;AAAA,EACT;AAAA,EAEA,iBAAiB,QAAyB;AACxC,SAAK,aAAa,iBAAiB,MAAM;AACzC,WAAO;AAAA,EACT;AAAA,EAEA,WAAW,YAA8B;AACvC,SAAK,aAAa,WAAW,UAAU;AACvC,WAAO;AAAA,EACT;AAAA,EAEA,QAAQ,SAAuB;AAC7B,SAAK,aAAa,KAAK,IAAI,GAAG,KAAK,MAAM,OAAO,CAAC;AACjD,WAAO;AAAA,EACT;AAAA,EAEA,QAAyB;AACvB,WAAO,IAAI,UAAU,KAAK,aAAa,MAAM,GAAG,KAAK,QAAQ,KAAK,UAAU;AAAA,EAC9E;AACF;AAEA,SAAS,qBAAwB,UAA8B,QAAyB;AACtF,QAAM,YAAY,SAAS,OACxB,OAAO,CAAC,YAAY,QAAQ,SAAS,WAAW,EAChD,OAAO,CAAC,aAAa,SAAS,SAAS,SAAS,gBAAgB,EAChE,GAAG,EAAE;AAER,MAAI,cAAc,QAAW;AAC3B,UAAM,IAAI,gBAAgB,wCAAwC;AAAA,EACpE;AAEA,SAAO,OAAO,MAAM,UAAU,SAAS,SAAS;AAClD;","names":[]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
cosineSimilarity,
|
|
3
|
+
embedText
|
|
4
|
+
} from "./chunk-JS5MGVNM.js";
|
|
4
5
|
import {
|
|
5
6
|
toProviderJsonSchema
|
|
6
7
|
} from "./chunk-WQKHFADH.js";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "./chunk-W4DZU6IW.js";
|
|
9
|
+
compact
|
|
10
|
+
} from "./chunk-MMHG7WAM.js";
|
|
11
11
|
|
|
12
12
|
// src/vector-store/index.ts
|
|
13
13
|
import { z } from "zod";
|
|
@@ -325,4 +325,4 @@ export {
|
|
|
325
325
|
InMemoryVectorIndex,
|
|
326
326
|
createVectorSearchTool
|
|
327
327
|
};
|
|
328
|
-
//# sourceMappingURL=chunk-
|
|
328
|
+
//# sourceMappingURL=chunk-5EDHXYH5.js.map
|
|
@@ -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,O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AQ,QAAQ;AAAA,MACd,CAAC,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,IA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