@anvia/core 0.25.1 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -11
- package/dist/agent/index.d.ts +26 -68
- package/dist/agent/index.js +20 -17
- package/dist/agent-DGYY_onS.d.ts +145 -0
- package/dist/audio-generation/index.d.ts +12 -14
- package/dist/audio-generation/index.js +5 -39
- package/dist/audio-generation/index.js.map +1 -1
- package/dist/{chunk-MRQLEK2B.js → chunk-5XKDW36Z.js} +30 -7
- package/dist/chunk-5XKDW36Z.js.map +1 -0
- package/dist/chunk-6WGGTJE6.js +139 -0
- package/dist/chunk-6WGGTJE6.js.map +1 -0
- package/dist/chunk-A3UBYTJT.js +157 -0
- package/dist/chunk-A3UBYTJT.js.map +1 -0
- package/dist/{chunk-BCA4VZ5W.js → chunk-DMPUP4R3.js} +10 -10
- package/dist/chunk-DMPUP4R3.js.map +1 -0
- package/dist/{chunk-MNWK2USR.js → chunk-DZ3CKYTH.js} +29 -5
- package/dist/chunk-DZ3CKYTH.js.map +1 -0
- package/dist/{chunk-CWUJUSOS.js → chunk-FNQB2JEH.js} +1 -1
- package/dist/chunk-FNQB2JEH.js.map +1 -0
- package/dist/chunk-I6G7BC42.js +41 -0
- package/dist/chunk-I6G7BC42.js.map +1 -0
- package/dist/{chunk-VXONXP2G.js → chunk-IL3ZSNJI.js} +2720 -1704
- package/dist/chunk-IL3ZSNJI.js.map +1 -0
- package/dist/chunk-J6GNQART.js +122 -0
- package/dist/chunk-J6GNQART.js.map +1 -0
- package/dist/{chunk-MC3CCKEB.js → chunk-M3IOWB4Y.js} +124 -65
- package/dist/chunk-M3IOWB4Y.js.map +1 -0
- package/dist/chunk-QY5GZ7HR.js +39 -0
- package/dist/chunk-QY5GZ7HR.js.map +1 -0
- package/dist/{chunk-4BGN6PYF.js → chunk-R2LJSQUW.js} +192 -22
- package/dist/chunk-R2LJSQUW.js.map +1 -0
- package/dist/{chunk-WQKHFADH.js → chunk-RFDVKCIE.js} +3 -3
- package/dist/chunk-RFDVKCIE.js.map +1 -0
- package/dist/chunk-RMUBRRSK.js +34 -0
- package/dist/chunk-RMUBRRSK.js.map +1 -0
- package/dist/{chunk-I6XOQ4LK.js → chunk-RXKHOYEH.js} +1 -1
- package/dist/chunk-RXKHOYEH.js.map +1 -0
- package/dist/chunk-XDRSPSR7.js +38 -0
- package/dist/chunk-XDRSPSR7.js.map +1 -0
- package/dist/completion/index.d.ts +5 -36
- package/dist/completion/index.js +4 -5
- package/dist/dynamic-tools-i9woysFa.d.ts +33 -0
- package/dist/embeddings/index.d.ts +2 -2
- package/dist/embeddings/index.js +1 -2
- package/dist/{errors-2moLDuuN.d.ts → errors-CYKUcU89.d.ts} +2 -2
- package/dist/evals/index.d.ts +22 -15
- package/dist/evals/index.js +60 -38
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +23 -35
- package/dist/extractor/index.js +7 -21
- package/dist/guardrails/index.d.ts +2 -2
- package/dist/guardrails/index.js +1 -1
- package/dist/image-generation/index.d.ts +12 -14
- package/dist/image-generation/index.js +5 -39
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index-DxB74ybJ.d.ts +349 -0
- package/dist/index.d.ts +20 -17
- package/dist/index.js +31 -36
- package/dist/internal/agent.d.ts +152 -9
- package/dist/internal/agent.js +22 -17
- package/dist/{json-BVPssigK.d.ts → json-Zo7K3xmt.d.ts} +12 -11
- package/dist/loaders/index.d.ts +5 -10
- package/dist/loaders/index.js.map +1 -1
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.js +187 -2
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +4 -4
- package/dist/memory/index.js +6 -7
- package/dist/middleware-KynLg_RW.d.ts +56 -0
- package/dist/observability/index.d.ts +6 -3
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +40 -47
- package/dist/pipeline/index.js +99 -99
- package/dist/pipeline/index.js.map +1 -1
- package/dist/retry-D3Ruy-ba.d.ts +15 -0
- package/dist/skills/index.d.ts +4 -4
- package/dist/skills/index.js +5 -6
- package/dist/streaming/index.js +37 -3
- package/dist/streaming/index.js.map +1 -1
- package/dist/{think-tool-DfCMuO8e.d.ts → think-tool-DZqZj2LV.d.ts} +5 -5
- package/dist/tool/index.d.ts +8 -6
- package/dist/tool/index.js +12 -15
- package/dist/tool-C_8GudXn.d.ts +49 -0
- package/dist/transcription/index.d.ts +14 -16
- package/dist/transcription/index.js +5 -57
- package/dist/transcription/index.js.map +1 -1
- package/dist/type-utils-CtHVDRn_.d.ts +6 -0
- package/dist/{types-G12i56s2.d.ts → types-B3A4YxaA.d.ts} +1 -1
- package/dist/{types-BrLbKnEz.d.ts → types-BBEGKB9m.d.ts} +1 -1
- package/dist/{types-O-abTIin.d.ts → types-DT3nEemY.d.ts} +3 -3
- package/dist/{types-04LqWrmy.d.ts → types-DhQfwiZn.d.ts} +1 -1
- package/dist/{types-JJCxRnaZ.d.ts → types-DulRCYdB.d.ts} +2 -2
- package/dist/{types-BCTRUGex.d.ts → types-p55Jc-sr.d.ts} +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/vector-store/index.d.ts +5 -5
- package/dist/vector-store/index.js +4 -4
- package/package.json +3 -10
- package/dist/agent-x3YTyv5i.d.ts +0 -222
- package/dist/chunk-2NDQHV7V.js +0 -223
- package/dist/chunk-2NDQHV7V.js.map +0 -1
- package/dist/chunk-2ODTMRHP.js +0 -54
- package/dist/chunk-2ODTMRHP.js.map +0 -1
- package/dist/chunk-4BGN6PYF.js.map +0 -1
- package/dist/chunk-4HWN7734.js +0 -220
- package/dist/chunk-4HWN7734.js.map +0 -1
- package/dist/chunk-BCA4VZ5W.js.map +0 -1
- package/dist/chunk-CWUJUSOS.js.map +0 -1
- package/dist/chunk-I6XOQ4LK.js.map +0 -1
- package/dist/chunk-KYEBWN3E.js +0 -141
- package/dist/chunk-KYEBWN3E.js.map +0 -1
- package/dist/chunk-MC3CCKEB.js.map +0 -1
- package/dist/chunk-MNWK2USR.js.map +0 -1
- package/dist/chunk-MRQLEK2B.js.map +0 -1
- package/dist/chunk-OIMLU4SF.js +0 -20
- package/dist/chunk-OIMLU4SF.js.map +0 -1
- package/dist/chunk-Q25IWLBT.js +0 -138
- package/dist/chunk-Q25IWLBT.js.map +0 -1
- package/dist/chunk-UQX6EXWG.js +0 -33
- package/dist/chunk-UQX6EXWG.js.map +0 -1
- package/dist/chunk-VXONXP2G.js.map +0 -1
- package/dist/chunk-WQKHFADH.js.map +0 -1
- package/dist/chunk-XUUY2L2D.js +0 -42
- package/dist/chunk-XUUY2L2D.js.map +0 -1
- package/dist/chunk-YEBIVZM2.js +0 -225
- package/dist/chunk-YEBIVZM2.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -12
- package/dist/hooks/index.js +0 -17
- package/dist/hooks/index.js.map +0 -1
- package/dist/index-BxSbmOMr.d.ts +0 -257
- package/dist/middleware-Dp3d_pxi.d.ts +0 -90
- package/dist/request/index.d.ts +0 -28
- package/dist/request/index.js +0 -25
- package/dist/request/index.js.map +0 -1
- package/dist/tool-Cohdv5GC.d.ts +0 -65
- package/dist/types-D9JpeAPF.d.ts +0 -114
package/dist/chunk-YEBIVZM2.js
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PromptRequest
|
|
3
|
-
} from "./chunk-VXONXP2G.js";
|
|
4
|
-
import {
|
|
5
|
-
isSkillTool
|
|
6
|
-
} from "./chunk-YK4WAAS4.js";
|
|
7
|
-
import {
|
|
8
|
-
ToolSet
|
|
9
|
-
} from "./chunk-2NDQHV7V.js";
|
|
10
|
-
import {
|
|
11
|
-
createTool
|
|
12
|
-
} from "./chunk-4BGN6PYF.js";
|
|
13
|
-
import {
|
|
14
|
-
isStreamingCompletionModel
|
|
15
|
-
} from "./chunk-MC3CCKEB.js";
|
|
16
|
-
import {
|
|
17
|
-
getAssistantGenerationMetadata
|
|
18
|
-
} from "./chunk-ADH7NNCS.js";
|
|
19
|
-
|
|
20
|
-
// src/agent/agent.ts
|
|
21
|
-
import { z } from "zod";
|
|
22
|
-
|
|
23
|
-
// src/agent/ids.ts
|
|
24
|
-
function normalizeAgentId(id) {
|
|
25
|
-
if (typeof id !== "string") {
|
|
26
|
-
throw new TypeError("Agent id must be a string.");
|
|
27
|
-
}
|
|
28
|
-
const normalized = id.trim();
|
|
29
|
-
if (normalized.length === 0) {
|
|
30
|
-
throw new TypeError("Agent id must be a non-empty string.");
|
|
31
|
-
}
|
|
32
|
-
return normalized;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/agent/agent.ts
|
|
36
|
-
var DEFAULT_MAX_TURNS = 20;
|
|
37
|
-
var Agent = class {
|
|
38
|
-
id;
|
|
39
|
-
name;
|
|
40
|
-
description;
|
|
41
|
-
model;
|
|
42
|
-
instructions;
|
|
43
|
-
staticContext;
|
|
44
|
-
temperature;
|
|
45
|
-
maxTokens;
|
|
46
|
-
additionalParams;
|
|
47
|
-
toolSet;
|
|
48
|
-
providerTools;
|
|
49
|
-
toolChoice;
|
|
50
|
-
defaultMaxTurns;
|
|
51
|
-
hook;
|
|
52
|
-
outputSchema;
|
|
53
|
-
observers;
|
|
54
|
-
approvals;
|
|
55
|
-
guardrails;
|
|
56
|
-
dynamicContexts;
|
|
57
|
-
dynamicTools;
|
|
58
|
-
middlewares;
|
|
59
|
-
memory;
|
|
60
|
-
eventStore;
|
|
61
|
-
constructor(options) {
|
|
62
|
-
this.id = normalizeAgentId(options.id);
|
|
63
|
-
this.name = options.name;
|
|
64
|
-
this.description = options.description;
|
|
65
|
-
this.model = options.model;
|
|
66
|
-
this.instructions = options.instructions;
|
|
67
|
-
this.staticContext = [...options.staticContext ?? []];
|
|
68
|
-
this.temperature = options.temperature;
|
|
69
|
-
this.maxTokens = options.maxTokens;
|
|
70
|
-
this.additionalParams = options.additionalParams;
|
|
71
|
-
this.toolSet = options.toolSet ?? new ToolSet();
|
|
72
|
-
this.providerTools = [...options.providerTools ?? []];
|
|
73
|
-
this.toolChoice = options.toolChoice;
|
|
74
|
-
this.defaultMaxTurns = options.defaultMaxTurns ?? DEFAULT_MAX_TURNS;
|
|
75
|
-
this.hook = options.hook;
|
|
76
|
-
this.outputSchema = options.outputSchema;
|
|
77
|
-
this.observers = [...options.observers ?? []];
|
|
78
|
-
this.approvals = options.approvals;
|
|
79
|
-
this.guardrails = [...options.guardrails ?? []];
|
|
80
|
-
this.dynamicContexts = [...options.dynamicContexts ?? []];
|
|
81
|
-
this.dynamicTools = [...options.dynamicTools ?? []];
|
|
82
|
-
this.middlewares = [...options.middlewares ?? []];
|
|
83
|
-
this.memory = options.memory;
|
|
84
|
-
this.eventStore = options.eventStore;
|
|
85
|
-
}
|
|
86
|
-
prompt(prompt) {
|
|
87
|
-
return PromptRequest.fromAgent(this, prompt);
|
|
88
|
-
}
|
|
89
|
-
session(sessionId, options = {}) {
|
|
90
|
-
if (this.memory === void 0) {
|
|
91
|
-
throw new Error(`Agent "${this.id}" has no memory store configured.`);
|
|
92
|
-
}
|
|
93
|
-
const normalized = sessionId.trim();
|
|
94
|
-
if (normalized.length === 0) {
|
|
95
|
-
throw new TypeError("Session id must be a non-empty string.");
|
|
96
|
-
}
|
|
97
|
-
const context = {
|
|
98
|
-
sessionId: normalized
|
|
99
|
-
};
|
|
100
|
-
if (options.userId !== void 0) {
|
|
101
|
-
context.userId = options.userId;
|
|
102
|
-
}
|
|
103
|
-
if (options.metadata !== void 0) {
|
|
104
|
-
context.metadata = options.metadata;
|
|
105
|
-
}
|
|
106
|
-
return new AgentSession(this, context);
|
|
107
|
-
}
|
|
108
|
-
asTool(options) {
|
|
109
|
-
const description = options.description ?? this.description ?? `Prompt the ${options.name} agent.`;
|
|
110
|
-
return createTool({
|
|
111
|
-
name: options.name,
|
|
112
|
-
description,
|
|
113
|
-
input: z.object({
|
|
114
|
-
prompt: z.string().describe("The prompt to send to the agent.")
|
|
115
|
-
}),
|
|
116
|
-
output: z.string(),
|
|
117
|
-
execute: async ({ prompt }, context) => {
|
|
118
|
-
const request = this.prompt(prompt);
|
|
119
|
-
const childRequest = options.maxTurns === void 0 ? request : request.maxTurns(options.maxTurns);
|
|
120
|
-
if (options.stream === true && context.emitStreamEvent !== void 0 && this.model.capabilities.streaming && isStreamingCompletionModel(this.model)) {
|
|
121
|
-
let output = "";
|
|
122
|
-
const childStream = context.includeToolCallDeltas === false ? childRequest.stream({ includeToolCallDeltas: false }) : childRequest.stream();
|
|
123
|
-
for await (const event of childStream) {
|
|
124
|
-
const streamEvent = {
|
|
125
|
-
agentId: this.id,
|
|
126
|
-
event
|
|
127
|
-
};
|
|
128
|
-
if (this.name !== void 0) {
|
|
129
|
-
streamEvent.agentName = this.name;
|
|
130
|
-
}
|
|
131
|
-
await context.emitStreamEvent(streamEvent);
|
|
132
|
-
if (event.type === "final") {
|
|
133
|
-
output = event.output;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return output;
|
|
137
|
-
}
|
|
138
|
-
const response = await childRequest.send();
|
|
139
|
-
return response.output;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
getTool(toolName) {
|
|
144
|
-
const staticTool = this.toolSet.get(toolName);
|
|
145
|
-
if (staticTool !== void 0) {
|
|
146
|
-
return staticTool;
|
|
147
|
-
}
|
|
148
|
-
for (const registration of this.dynamicTools) {
|
|
149
|
-
const dynamicTool = dynamicToolSetFromIndex(registration.index)?.get(toolName);
|
|
150
|
-
if (dynamicTool !== void 0) {
|
|
151
|
-
return dynamicTool;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return void 0;
|
|
155
|
-
}
|
|
156
|
-
async callTool(toolName, args, context) {
|
|
157
|
-
if (this.toolSet.contains(toolName)) {
|
|
158
|
-
return this.toolSet.call(toolName, args, context);
|
|
159
|
-
}
|
|
160
|
-
for (const registration of this.dynamicTools) {
|
|
161
|
-
const toolSet = dynamicToolSetFromIndex(registration.index);
|
|
162
|
-
if (toolSet?.contains(toolName)) {
|
|
163
|
-
return toolSet.call(toolName, args, context);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return this.toolSet.call(toolName, args, context);
|
|
167
|
-
}
|
|
168
|
-
shouldApplyToolMiddleware(toolName) {
|
|
169
|
-
return !isSkillTool(this.getTool(toolName));
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
var AgentSession = class {
|
|
173
|
-
constructor(agent, context) {
|
|
174
|
-
this.agent = agent;
|
|
175
|
-
this.context = context;
|
|
176
|
-
}
|
|
177
|
-
agent;
|
|
178
|
-
context;
|
|
179
|
-
prompt(prompt) {
|
|
180
|
-
if (Array.isArray(prompt)) {
|
|
181
|
-
throw new TypeError("AgentSession.prompt does not accept Message[] transcripts.");
|
|
182
|
-
}
|
|
183
|
-
return PromptRequest.fromAgent(this.agent, prompt, { memoryContext: this.context });
|
|
184
|
-
}
|
|
185
|
-
async messages() {
|
|
186
|
-
const memory = this.agent.memory;
|
|
187
|
-
if (memory === void 0) {
|
|
188
|
-
throw new Error(`Agent "${this.agent.id}" has no memory store configured.`);
|
|
189
|
-
}
|
|
190
|
-
return memory.store.load(this.context);
|
|
191
|
-
}
|
|
192
|
-
async contextUsage() {
|
|
193
|
-
const messages = await this.messages();
|
|
194
|
-
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
195
|
-
const message = messages[index];
|
|
196
|
-
if (message === void 0) {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
const generation = getAssistantGenerationMetadata(message);
|
|
200
|
-
if (generation !== void 0) {
|
|
201
|
-
return generation.contextUsage;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return void 0;
|
|
205
|
-
}
|
|
206
|
-
async clear() {
|
|
207
|
-
const memory = this.agent.memory;
|
|
208
|
-
if (memory === void 0) {
|
|
209
|
-
throw new Error(`Agent "${this.agent.id}" has no memory store configured.`);
|
|
210
|
-
}
|
|
211
|
-
await memory.store.clear(this.context);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
function dynamicToolSetFromIndex(index) {
|
|
215
|
-
const maybeIndex = index;
|
|
216
|
-
return maybeIndex.toolSet instanceof ToolSet ? maybeIndex.toolSet : void 0;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export {
|
|
220
|
-
normalizeAgentId,
|
|
221
|
-
DEFAULT_MAX_TURNS,
|
|
222
|
-
Agent,
|
|
223
|
-
AgentSession
|
|
224
|
-
};
|
|
225
|
-
//# sourceMappingURL=chunk-YEBIVZM2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 ContextUsage,\n Document,\n JsonObject,\n JsonValue,\n Message as MessageType,\n ProviderTool,\n ToolChoice,\n} from \"../completion/index\";\nimport { getAssistantGenerationMetadata } from \"../completion/types\";\nimport type { GuardrailPolicy } from \"../guardrails\";\nimport type { PromptHook } from \"../hooks\";\nimport type { MemoryContext, 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 ToolCallStreamEvent,\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 providerTools: ProviderTool[];\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 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.providerTools = [...(options.providerTools ?? [])];\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 ?? [])];\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 const context: MemoryContext = {\n sessionId: normalized,\n };\n if (options.userId !== undefined) {\n context.userId = options.userId;\n }\n if (options.metadata !== undefined) {\n context.metadata = options.metadata;\n }\n return new AgentSession(this, context);\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 const childStream =\n context.includeToolCallDeltas === false\n ? childRequest.stream({ includeToolCallDeltas: false })\n : childRequest.stream();\n for await (const event of childStream) {\n const streamEvent: ToolCallStreamEvent = {\n agentId: this.id,\n event,\n };\n if (this.name !== undefined) {\n streamEvent.agentName = this.name;\n }\n await context.emitStreamEvent(streamEvent);\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 contextUsage(): Promise<ContextUsage | undefined> {\n const messages = await this.messages();\n for (let index = messages.length - 1; index >= 0; index -= 1) {\n const message = messages[index];\n if (message === undefined) {\n continue;\n }\n const generation = getAssistantGenerationMetadata(message);\n if (generation !== undefined) {\n return generation.contextUsage;\n }\n }\n return undefined;\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}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ACnB,SAAO,WAAW,mBAAmB,UAAU,WAAW,UAAU;AACtE;","names":[]}
|
package/dist/hooks/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { H as HookAction, P as PromptHook, T as ToolApprovalRequestOptions, a as ToolCallHookAction, R as RunControl, b as ToolCallControl } from '../types-D9JpeAPF.js';
|
|
2
|
-
export { C as CompletionCallHookArgs, c as CompletionErrorHookArgs, d as CompletionResponseHookArgs, e as HookResult, f as RunEndHookArgs, g as RunErrorHookArgs, h as RunStartHookArgs, i as ToolCallHookArgs, j as ToolCallHookResult, k as ToolErrorHookArgs, l as ToolHookArgs, m as ToolResultHookArgs, n as TurnEndHookArgs, o as TurnStartHookArgs } from '../types-D9JpeAPF.js';
|
|
3
|
-
import '../types-G12i56s2.js';
|
|
4
|
-
|
|
5
|
-
declare function createHook<RawResponse = unknown>(hook: PromptHook<RawResponse>): PromptHook<RawResponse>;
|
|
6
|
-
declare function cancelPrompt(reason: string): HookAction;
|
|
7
|
-
declare function skipTool(reason: string): ToolCallHookAction;
|
|
8
|
-
declare function requestToolApproval(options?: ToolApprovalRequestOptions): ToolCallHookAction;
|
|
9
|
-
declare const runControl: RunControl;
|
|
10
|
-
declare const toolCallControl: ToolCallControl;
|
|
11
|
-
|
|
12
|
-
export { HookAction, PromptHook, RunControl, ToolApprovalRequestOptions, ToolCallControl, ToolCallHookAction, cancelPrompt, createHook, requestToolApproval, runControl, skipTool, toolCallControl };
|
package/dist/hooks/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
cancelPrompt,
|
|
3
|
-
createHook,
|
|
4
|
-
requestToolApproval,
|
|
5
|
-
runControl,
|
|
6
|
-
skipTool,
|
|
7
|
-
toolCallControl
|
|
8
|
-
} from "../chunk-2ODTMRHP.js";
|
|
9
|
-
export {
|
|
10
|
-
cancelPrompt,
|
|
11
|
-
createHook,
|
|
12
|
-
requestToolApproval,
|
|
13
|
-
runControl,
|
|
14
|
-
skipTool,
|
|
15
|
-
toolCallControl
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
package/dist/hooks/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index-BxSbmOMr.d.ts
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { Y as ReasoningContentType, p as ToolCall, h as CompletionSource, o as ProviderToolCall, U as Usage, j as ContextUsage, M as Message, f as CompletionRequest, u as ToolResultContent, g as CompletionResponse, _ as ToolCallArgumentsMode, J as JsonObject, O as CompletionModelCapabilities, r as ToolDefinition, l as JsonValue } from './types-G12i56s2.js';
|
|
2
|
-
import { GuardrailDecisionRecord } from './guardrails/index.js';
|
|
3
|
-
import { g as ToolCallStreamEvent } from './tool-Cohdv5GC.js';
|
|
4
|
-
|
|
5
|
-
type PromptResponse = {
|
|
6
|
-
output: string;
|
|
7
|
-
usage: Usage;
|
|
8
|
-
contextUsage?: ContextUsage | undefined;
|
|
9
|
-
messages: Message[];
|
|
10
|
-
trace?: AgentTraceInfo | undefined;
|
|
11
|
-
guardrails?: GuardrailDecisionRecord[] | undefined;
|
|
12
|
-
sources?: CompletionSource[] | undefined;
|
|
13
|
-
providerToolCalls?: ProviderToolCall[] | undefined;
|
|
14
|
-
};
|
|
15
|
-
type AgentDeltaEvent = {
|
|
16
|
-
type: "text_delta";
|
|
17
|
-
delta: string;
|
|
18
|
-
} | {
|
|
19
|
-
type: "reasoning_delta";
|
|
20
|
-
delta: string;
|
|
21
|
-
id?: string;
|
|
22
|
-
contentType?: ReasoningContentType;
|
|
23
|
-
signature?: string;
|
|
24
|
-
} | {
|
|
25
|
-
type: "tool_call";
|
|
26
|
-
toolCall: ToolCall;
|
|
27
|
-
} | {
|
|
28
|
-
type: "source";
|
|
29
|
-
source: CompletionSource;
|
|
30
|
-
} | {
|
|
31
|
-
type: "provider_tool_call";
|
|
32
|
-
toolCall: ProviderToolCall;
|
|
33
|
-
};
|
|
34
|
-
type AgentErrorStreamEvent = {
|
|
35
|
-
type: "error";
|
|
36
|
-
error: unknown;
|
|
37
|
-
usage: Usage;
|
|
38
|
-
};
|
|
39
|
-
type AgentStreamOptions = {
|
|
40
|
-
/** @default true */
|
|
41
|
-
includeToolCallDeltas?: boolean;
|
|
42
|
-
};
|
|
43
|
-
type AgentToolCallDeltaEvent = {
|
|
44
|
-
type: "tool_call_delta";
|
|
45
|
-
turn: number;
|
|
46
|
-
id: string;
|
|
47
|
-
callId?: string;
|
|
48
|
-
name?: string;
|
|
49
|
-
argumentsDelta?: string;
|
|
50
|
-
argumentsMode?: ToolCallArgumentsMode;
|
|
51
|
-
signature?: string;
|
|
52
|
-
};
|
|
53
|
-
type AgentChildStreamEventBase<RawResponse = unknown> = {
|
|
54
|
-
type: "turn_start";
|
|
55
|
-
turn: number;
|
|
56
|
-
prompt: Message;
|
|
57
|
-
history: Message[];
|
|
58
|
-
} | {
|
|
59
|
-
type: "generation_start";
|
|
60
|
-
turn: number;
|
|
61
|
-
request: CompletionRequest;
|
|
62
|
-
modelInfo: AgentGenerationModelInfo;
|
|
63
|
-
} | {
|
|
64
|
-
type: "text_delta";
|
|
65
|
-
turn: number;
|
|
66
|
-
delta: string;
|
|
67
|
-
} | {
|
|
68
|
-
type: "reasoning_delta";
|
|
69
|
-
turn: number;
|
|
70
|
-
delta: string;
|
|
71
|
-
id?: string;
|
|
72
|
-
contentType?: ReasoningContentType;
|
|
73
|
-
signature?: string;
|
|
74
|
-
} | {
|
|
75
|
-
type: "tool_call";
|
|
76
|
-
turn: number;
|
|
77
|
-
toolCall: ToolCall;
|
|
78
|
-
} | {
|
|
79
|
-
type: "source";
|
|
80
|
-
turn: number;
|
|
81
|
-
source: CompletionSource;
|
|
82
|
-
} | {
|
|
83
|
-
type: "provider_tool_call";
|
|
84
|
-
turn: number;
|
|
85
|
-
toolCall: ProviderToolCall;
|
|
86
|
-
} | {
|
|
87
|
-
type: "tool_result";
|
|
88
|
-
turn: number;
|
|
89
|
-
toolName: string;
|
|
90
|
-
toolCallId?: string;
|
|
91
|
-
internalCallId: string;
|
|
92
|
-
args: string;
|
|
93
|
-
result: string;
|
|
94
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
95
|
-
} | {
|
|
96
|
-
type: "turn_end";
|
|
97
|
-
turn: number;
|
|
98
|
-
response: CompletionResponse<RawResponse>;
|
|
99
|
-
firstDeltaMs?: number | undefined;
|
|
100
|
-
} | {
|
|
101
|
-
type: "guardrail_decision";
|
|
102
|
-
turn?: number | undefined;
|
|
103
|
-
decision: GuardrailDecisionRecord;
|
|
104
|
-
} | {
|
|
105
|
-
type: "final";
|
|
106
|
-
runId: string;
|
|
107
|
-
output: string;
|
|
108
|
-
usage: Usage;
|
|
109
|
-
contextUsage?: ContextUsage | undefined;
|
|
110
|
-
messages: Message[];
|
|
111
|
-
trace?: AgentTraceInfo | undefined;
|
|
112
|
-
guardrails?: GuardrailDecisionRecord[] | undefined;
|
|
113
|
-
sources?: CompletionSource[] | undefined;
|
|
114
|
-
providerToolCalls?: ProviderToolCall[] | undefined;
|
|
115
|
-
} | AgentErrorStreamEvent;
|
|
116
|
-
type AgentChildStreamEventWithoutToolCallDeltas<RawResponse = unknown> = AgentChildStreamEventBase<RawResponse>;
|
|
117
|
-
type AgentChildStreamEvent<RawResponse = unknown> = AgentChildStreamEventBase<RawResponse> | AgentToolCallDeltaEvent;
|
|
118
|
-
type AgentChildStreamEventWithToolCallDeltas<RawResponse = unknown> = AgentChildStreamEvent<RawResponse>;
|
|
119
|
-
type AgentToolStreamEvent<ChildEvent> = {
|
|
120
|
-
type: "agent_tool_event";
|
|
121
|
-
turn: number;
|
|
122
|
-
toolName: string;
|
|
123
|
-
toolCallId?: string;
|
|
124
|
-
internalCallId: string;
|
|
125
|
-
agentId: string;
|
|
126
|
-
agentName?: string;
|
|
127
|
-
event: ChildEvent;
|
|
128
|
-
};
|
|
129
|
-
type AgentStreamEventWithoutToolCallDeltas<RawResponse = unknown> = AgentChildStreamEventWithoutToolCallDeltas<RawResponse> | AgentToolStreamEvent<AgentChildStreamEventWithoutToolCallDeltas<RawResponse>>;
|
|
130
|
-
type AgentStreamEvent<RawResponse = unknown> = AgentChildStreamEvent<RawResponse> | AgentToolStreamEvent<AgentChildStreamEvent<RawResponse>>;
|
|
131
|
-
type AgentStreamEventWithToolCallDeltas<RawResponse = unknown> = AgentStreamEvent<RawResponse>;
|
|
132
|
-
|
|
133
|
-
type AgentTraceInfo = {
|
|
134
|
-
traceId?: string | undefined;
|
|
135
|
-
observationId?: string | undefined;
|
|
136
|
-
};
|
|
137
|
-
type AgentTraceOptions = {
|
|
138
|
-
name?: string | undefined;
|
|
139
|
-
userId?: string | undefined;
|
|
140
|
-
sessionId?: string | undefined;
|
|
141
|
-
metadata?: Record<string, unknown> | undefined;
|
|
142
|
-
tags?: string[] | undefined;
|
|
143
|
-
version?: string | undefined;
|
|
144
|
-
traceId?: string | undefined;
|
|
145
|
-
failOnObserverError?: boolean | undefined;
|
|
146
|
-
promptRef?: AgentRunPromptRef | undefined;
|
|
147
|
-
};
|
|
148
|
-
type AgentRunPromptRef = {
|
|
149
|
-
name: string;
|
|
150
|
-
version?: number | undefined;
|
|
151
|
-
};
|
|
152
|
-
type AgentRunStartArgs = {
|
|
153
|
-
agentName?: string | undefined;
|
|
154
|
-
agentDescription?: string | undefined;
|
|
155
|
-
instructions?: string | undefined;
|
|
156
|
-
trace?: AgentTraceOptions | undefined;
|
|
157
|
-
prompt: Message;
|
|
158
|
-
promptRef?: AgentRunPromptRef | undefined;
|
|
159
|
-
history: Message[];
|
|
160
|
-
maxTurns: number;
|
|
161
|
-
};
|
|
162
|
-
type AgentRunEndArgs = {
|
|
163
|
-
output: string;
|
|
164
|
-
usage: Usage;
|
|
165
|
-
messages: Message[];
|
|
166
|
-
sources?: CompletionSource[] | undefined;
|
|
167
|
-
providerToolCalls?: ProviderToolCall[] | undefined;
|
|
168
|
-
};
|
|
169
|
-
type AgentRunErrorArgs = {
|
|
170
|
-
error: unknown;
|
|
171
|
-
usage: Usage;
|
|
172
|
-
messages: Message[];
|
|
173
|
-
};
|
|
174
|
-
type AgentGenerationModelInfo = {
|
|
175
|
-
provider: string;
|
|
176
|
-
defaultModel: string;
|
|
177
|
-
capabilities?: CompletionModelCapabilities | undefined;
|
|
178
|
-
};
|
|
179
|
-
type AgentGenerationStartArgs = {
|
|
180
|
-
turn: number;
|
|
181
|
-
request: CompletionRequest;
|
|
182
|
-
providerRequest?: JsonObject | undefined;
|
|
183
|
-
modelInfo?: AgentGenerationModelInfo | undefined;
|
|
184
|
-
};
|
|
185
|
-
type AgentGenerationEndArgs<RawResponse = unknown> = {
|
|
186
|
-
turn: number;
|
|
187
|
-
response: CompletionResponse<RawResponse>;
|
|
188
|
-
firstDeltaMs?: number | undefined;
|
|
189
|
-
};
|
|
190
|
-
type AgentGenerationErrorArgs = {
|
|
191
|
-
turn: number;
|
|
192
|
-
error: unknown;
|
|
193
|
-
};
|
|
194
|
-
type AgentGenerationUpdateArgs = {
|
|
195
|
-
turn: number;
|
|
196
|
-
delta: AgentDeltaEvent;
|
|
197
|
-
};
|
|
198
|
-
type AgentRunEventArgs = {
|
|
199
|
-
name: string;
|
|
200
|
-
attributes?: Record<string, JsonValue | undefined> | undefined;
|
|
201
|
-
level?: "DEFAULT" | "WARNING" | "ERROR" | undefined;
|
|
202
|
-
timestamp?: Date | string | undefined;
|
|
203
|
-
};
|
|
204
|
-
type AgentToolStartArgs = {
|
|
205
|
-
turn: number;
|
|
206
|
-
toolCall: ToolCall;
|
|
207
|
-
toolName: string;
|
|
208
|
-
args: string;
|
|
209
|
-
internalCallId: string;
|
|
210
|
-
toolCallId?: string | undefined;
|
|
211
|
-
toolDefinition?: ToolDefinition | undefined;
|
|
212
|
-
toolMetadata?: JsonObject | undefined;
|
|
213
|
-
};
|
|
214
|
-
type AgentToolEndArgs = AgentToolStartArgs & {
|
|
215
|
-
result: string;
|
|
216
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
217
|
-
skipped: boolean;
|
|
218
|
-
};
|
|
219
|
-
type AgentToolErrorArgs = AgentToolStartArgs & {
|
|
220
|
-
error: unknown;
|
|
221
|
-
};
|
|
222
|
-
type AgentToolStreamEventArgs = AgentToolStartArgs & {
|
|
223
|
-
event: ToolCallStreamEvent;
|
|
224
|
-
};
|
|
225
|
-
interface AgentGenerationObserver {
|
|
226
|
-
end(args: AgentGenerationEndArgs): void | Promise<void>;
|
|
227
|
-
error?(args: AgentGenerationErrorArgs): void | Promise<void>;
|
|
228
|
-
update?(args: AgentGenerationUpdateArgs): void | Promise<void>;
|
|
229
|
-
}
|
|
230
|
-
interface AgentToolObserver {
|
|
231
|
-
streamEvent?(args: AgentToolStreamEventArgs): void | Promise<void>;
|
|
232
|
-
end(args: AgentToolEndArgs): void | Promise<void>;
|
|
233
|
-
error?(args: AgentToolErrorArgs): void | Promise<void>;
|
|
234
|
-
}
|
|
235
|
-
interface AgentRunObserver {
|
|
236
|
-
readonly trace?: AgentTraceInfo | undefined;
|
|
237
|
-
startGeneration?(args: AgentGenerationStartArgs): AgentGenerationObserver | undefined | Promise<AgentGenerationObserver | undefined>;
|
|
238
|
-
startTool?(args: AgentToolStartArgs): AgentToolObserver | undefined | Promise<AgentToolObserver | undefined>;
|
|
239
|
-
end(args: AgentRunEndArgs): void | Promise<void>;
|
|
240
|
-
error?(args: AgentRunErrorArgs): void | Promise<void>;
|
|
241
|
-
event?(args: AgentRunEventArgs): void | Promise<void>;
|
|
242
|
-
}
|
|
243
|
-
interface AgentObserver {
|
|
244
|
-
startRun(args: AgentRunStartArgs): AgentRunObserver | undefined | Promise<AgentRunObserver | undefined>;
|
|
245
|
-
flush?(): void | Promise<void>;
|
|
246
|
-
shutdown?(): void | Promise<void>;
|
|
247
|
-
}
|
|
248
|
-
type AgentObserverRegistration = {
|
|
249
|
-
observer: AgentObserver;
|
|
250
|
-
failOnObserverError?: boolean | undefined;
|
|
251
|
-
};
|
|
252
|
-
type ObserveOptions = {
|
|
253
|
-
failOnObserverError?: boolean | undefined;
|
|
254
|
-
};
|
|
255
|
-
declare function createObserver(observer: AgentObserver): AgentObserver;
|
|
256
|
-
|
|
257
|
-
export { type AgentChildStreamEvent as A, type AgentToolObserver as B, type AgentToolStartArgs as C, type AgentToolStreamEventArgs as D, type AgentTraceInfo as E, createObserver as F, type ObserveOptions as O, type PromptResponse as P, type AgentChildStreamEventWithToolCallDeltas as a, type AgentChildStreamEventWithoutToolCallDeltas as b, type AgentErrorStreamEvent as c, type AgentStreamEvent as d, type AgentStreamEventWithToolCallDeltas as e, type AgentStreamEventWithoutToolCallDeltas as f, type AgentStreamOptions as g, type AgentToolCallDeltaEvent as h, type AgentObserver as i, type AgentTraceOptions as j, type AgentObserverRegistration as k, type AgentDeltaEvent as l, type AgentGenerationEndArgs as m, type AgentGenerationErrorArgs as n, type AgentGenerationModelInfo as o, type AgentGenerationObserver as p, type AgentGenerationStartArgs as q, type AgentGenerationUpdateArgs as r, type AgentRunEndArgs as s, type AgentRunErrorArgs as t, type AgentRunEventArgs as u, type AgentRunObserver as v, type AgentRunPromptRef as w, type AgentRunStartArgs as x, type AgentToolEndArgs as y, type AgentToolErrorArgs as z };
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { r as ToolDefinition, f as CompletionRequest, g as CompletionResponse, l as JsonValue, u as ToolResultContent } from './types-G12i56s2.js';
|
|
2
|
-
import { V as VectorMetadata, E as EmbeddingModel, c as EmbeddedDocument } from './types-BCTRUGex.js';
|
|
3
|
-
import { A as AnyTool, f as ToolCallContext, N as NormalizedToolOutput } from './tool-Cohdv5GC.js';
|
|
4
|
-
import { a as VectorSearchIndex } from './types-O-abTIin.js';
|
|
5
|
-
|
|
6
|
-
declare class ToolSet {
|
|
7
|
-
private readonly tools;
|
|
8
|
-
static fromTools(tools: AnyTool[]): ToolSet;
|
|
9
|
-
addTool(tool: AnyTool): this;
|
|
10
|
-
addTools(tools: AnyTool[] | ToolSet): this;
|
|
11
|
-
deleteTool(toolName: string): boolean;
|
|
12
|
-
contains(toolName: string): boolean;
|
|
13
|
-
get(toolName: string): AnyTool | undefined;
|
|
14
|
-
values(): AnyTool[];
|
|
15
|
-
getToolDefinitions(prompt?: string): Promise<ToolDefinition[]>;
|
|
16
|
-
call(toolName: string, args: string, context?: ToolCallContext): Promise<NormalizedToolOutput>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type ToolSearchDocument<Metadata extends VectorMetadata = VectorMetadata> = {
|
|
20
|
-
toolName: string;
|
|
21
|
-
definition: ToolDefinition;
|
|
22
|
-
text: string;
|
|
23
|
-
metadata?: Metadata | undefined;
|
|
24
|
-
};
|
|
25
|
-
type EmbedToolsOptions<Metadata extends VectorMetadata = VectorMetadata> = {
|
|
26
|
-
content?: ((tool: AnyTool, definition: ToolDefinition) => string | string[]) | undefined;
|
|
27
|
-
metadata?: ((tool: AnyTool, definition: ToolDefinition) => Metadata | undefined) | undefined;
|
|
28
|
-
concurrency?: number | undefined;
|
|
29
|
-
};
|
|
30
|
-
interface DynamicToolIndex<Metadata extends VectorMetadata = VectorMetadata> extends VectorSearchIndex<ToolSearchDocument<Metadata>, Metadata> {
|
|
31
|
-
readonly toolSet: ToolSet;
|
|
32
|
-
}
|
|
33
|
-
declare function embedTools<Metadata extends VectorMetadata = VectorMetadata>(model: EmbeddingModel, tools: AnyTool[] | ToolSet, options?: EmbedToolsOptions<Metadata>): Promise<Array<EmbeddedDocument<ToolSearchDocument<Metadata>, Metadata>>>;
|
|
34
|
-
declare function createToolIndex<Metadata extends VectorMetadata = VectorMetadata>(model: EmbeddingModel, tools: AnyTool[] | ToolSet, options?: EmbedToolsOptions<Metadata>): Promise<DynamicToolIndex<Metadata>>;
|
|
35
|
-
declare function isDynamicToolIndex(value: unknown): value is DynamicToolIndex;
|
|
36
|
-
|
|
37
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
38
|
-
type CompletionRequestMiddlewareArgs = {
|
|
39
|
-
turn: number;
|
|
40
|
-
request: CompletionRequest;
|
|
41
|
-
originalRequest: CompletionRequest;
|
|
42
|
-
};
|
|
43
|
-
type CompletionRequestMiddlewareResult = {
|
|
44
|
-
request: CompletionRequest;
|
|
45
|
-
} | undefined;
|
|
46
|
-
type CompletionResponseMiddlewareArgs<RawResponse = unknown> = {
|
|
47
|
-
turn: number;
|
|
48
|
-
request: CompletionRequest;
|
|
49
|
-
response: CompletionResponse<RawResponse>;
|
|
50
|
-
originalResponse: CompletionResponse<RawResponse>;
|
|
51
|
-
};
|
|
52
|
-
type CompletionResponseMiddlewareResult<RawResponse = unknown> = {
|
|
53
|
-
response: CompletionResponse<RawResponse>;
|
|
54
|
-
} | undefined;
|
|
55
|
-
type ToolInputMiddlewareArgs = {
|
|
56
|
-
toolName: string;
|
|
57
|
-
args: string;
|
|
58
|
-
originalArgs: string;
|
|
59
|
-
turn: number;
|
|
60
|
-
toolCallId?: string | undefined;
|
|
61
|
-
internalCallId: string;
|
|
62
|
-
};
|
|
63
|
-
type ToolInputMiddlewareResult = {
|
|
64
|
-
args: JsonValue | string;
|
|
65
|
-
} | undefined;
|
|
66
|
-
type ToolResultMiddlewareArgs = {
|
|
67
|
-
toolName: string;
|
|
68
|
-
args: string;
|
|
69
|
-
result: string;
|
|
70
|
-
originalResult: string;
|
|
71
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
72
|
-
originalStructuredResult?: ToolResultContent[] | undefined;
|
|
73
|
-
turn: number;
|
|
74
|
-
toolCallId?: string | undefined;
|
|
75
|
-
internalCallId: string;
|
|
76
|
-
};
|
|
77
|
-
type ToolOutputMiddlewareArgs = ToolResultMiddlewareArgs;
|
|
78
|
-
type ToolOutputMiddlewareResult = string | {
|
|
79
|
-
result?: string | undefined;
|
|
80
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
81
|
-
} | undefined;
|
|
82
|
-
interface AgentMiddleware<RawResponse = unknown> {
|
|
83
|
-
onCompletionRequest?(args: CompletionRequestMiddlewareArgs): MaybePromise<CompletionRequestMiddlewareResult>;
|
|
84
|
-
onCompletionResponse?(args: CompletionResponseMiddlewareArgs<RawResponse>): MaybePromise<CompletionResponseMiddlewareResult<RawResponse>>;
|
|
85
|
-
onToolInput?(args: ToolInputMiddlewareArgs): MaybePromise<ToolInputMiddlewareResult>;
|
|
86
|
-
onToolOutput?(args: ToolOutputMiddlewareArgs): MaybePromise<ToolOutputMiddlewareResult>;
|
|
87
|
-
}
|
|
88
|
-
declare function createMiddleware<RawResponse = unknown>(middleware: AgentMiddleware<RawResponse>): AgentMiddleware<RawResponse>;
|
|
89
|
-
|
|
90
|
-
export { type AgentMiddleware as A, type CompletionRequestMiddlewareArgs as C, type DynamicToolIndex as D, type EmbedToolsOptions as E, type ToolInputMiddlewareArgs as T, type CompletionRequestMiddlewareResult as a, type CompletionResponseMiddlewareArgs as b, type CompletionResponseMiddlewareResult as c, type ToolInputMiddlewareResult as d, type ToolOutputMiddlewareArgs as e, type ToolOutputMiddlewareResult as f, type ToolResultMiddlewareArgs as g, createMiddleware as h, type ToolSearchDocument as i, ToolSet as j, createToolIndex as k, embedTools as l, isDynamicToolIndex as m };
|
package/dist/request/index.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { M as Message } from '../types-G12i56s2.js';
|
|
2
|
-
import { d as ToolApprovalRequest } from '../tool-Cohdv5GC.js';
|
|
3
|
-
export { C as CompletionRetryContext, a as CompletionRetryOptions, P as PromptRequest } from '../agent-x3YTyv5i.js';
|
|
4
|
-
export { A as AgentChildStreamEvent, a as AgentChildStreamEventWithToolCallDeltas, b as AgentChildStreamEventWithoutToolCallDeltas, l as AgentDeltaEvent, c as AgentErrorStreamEvent, d as AgentStreamEvent, e as AgentStreamEventWithToolCallDeltas, f as AgentStreamEventWithoutToolCallDeltas, g as AgentStreamOptions, h as AgentToolCallDeltaEvent, P as PromptResponse } from '../index-BxSbmOMr.js';
|
|
5
|
-
import '../guardrails/index.js';
|
|
6
|
-
import '../types-D9JpeAPF.js';
|
|
7
|
-
import '../types-BrLbKnEz.js';
|
|
8
|
-
import '../middleware-Dp3d_pxi.js';
|
|
9
|
-
import '../types-BCTRUGex.js';
|
|
10
|
-
import '../types-O-abTIin.js';
|
|
11
|
-
|
|
12
|
-
declare class MaxTurnsError extends Error {
|
|
13
|
-
readonly maxTurns: number;
|
|
14
|
-
readonly chatHistory: Message[];
|
|
15
|
-
readonly prompt: Message;
|
|
16
|
-
constructor(maxTurns: number, chatHistory: Message[], prompt: Message);
|
|
17
|
-
}
|
|
18
|
-
declare class PromptCancelledError extends Error {
|
|
19
|
-
readonly chatHistory: Message[];
|
|
20
|
-
readonly reason: string;
|
|
21
|
-
constructor(chatHistory: Message[], reason: string);
|
|
22
|
-
}
|
|
23
|
-
declare class ToolApprovalRequiredError extends Error {
|
|
24
|
-
readonly request: ToolApprovalRequest;
|
|
25
|
-
constructor(request: ToolApprovalRequest);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { MaxTurnsError, PromptCancelledError, ToolApprovalRequiredError };
|