@kairos-computer/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +27 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +53 -0
- package/dist/agent.js.map +1 -0
- package/dist/cleanup.d.ts +24 -0
- package/dist/cleanup.d.ts.map +1 -0
- package/dist/cleanup.js +146 -0
- package/dist/cleanup.js.map +1 -0
- package/dist/convert.d.ts +31 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +235 -0
- package/dist/convert.js.map +1 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/loop.d.ts +25 -0
- package/dist/loop.d.ts.map +1 -0
- package/dist/loop.js +407 -0
- package/dist/loop.js.map +1 -0
- package/dist/prompt.d.ts +10 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +21 -0
- package/dist/prompt.js.map +1 -0
- package/dist/services/MessageQueue.d.ts +13 -0
- package/dist/services/MessageQueue.d.ts.map +1 -0
- package/dist/services/MessageQueue.js +8 -0
- package/dist/services/MessageQueue.js.map +1 -0
- package/dist/services/Persistence.d.ts +12 -0
- package/dist/services/Persistence.d.ts.map +1 -0
- package/dist/services/Persistence.js +8 -0
- package/dist/services/Persistence.js.map +1 -0
- package/dist/services/StopSignal.d.ts +12 -0
- package/dist/services/StopSignal.d.ts.map +1 -0
- package/dist/services/StopSignal.js +8 -0
- package/dist/services/StopSignal.js.map +1 -0
- package/dist/services/Streaming.d.ts +11 -0
- package/dist/services/Streaming.d.ts.map +1 -0
- package/dist/services/Streaming.js +7 -0
- package/dist/services/Streaming.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +5 -0
- package/dist/services/index.js.map +1 -0
- package/dist/stream.d.ts +8 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +36 -0
- package/dist/stream.js.map +1 -0
- package/dist/tools.d.ts +14 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +60 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { UIMessage } from "ai";
|
|
2
|
+
import { Effect, Layer } from "effect";
|
|
3
|
+
import type { ContextOverflowError, PersistenceError, StreamError } from "./errors.js";
|
|
4
|
+
import { type MessageQueue } from "./services/MessageQueue.js";
|
|
5
|
+
import { Persistence } from "./services/Persistence.js";
|
|
6
|
+
import { type StopSignal } from "./services/StopSignal.js";
|
|
7
|
+
import { type Streaming } from "./services/Streaming.js";
|
|
8
|
+
import type { AgentConfig, LoopResult } from "./types.js";
|
|
9
|
+
export declare class Agent {
|
|
10
|
+
private config;
|
|
11
|
+
constructor(config: AgentConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Run a conversation turn. Returns an Effect that requires
|
|
14
|
+
* the relevant services to be provided via layers.
|
|
15
|
+
*/
|
|
16
|
+
run(conversationId: string, messages: UIMessage[]): Effect.Effect<LoopResult, StreamError | ContextOverflowError | PersistenceError, Streaming | Persistence | MessageQueue | StopSignal>;
|
|
17
|
+
/**
|
|
18
|
+
* Convenience: run with provided layers, returns a Promise.
|
|
19
|
+
*/
|
|
20
|
+
runPromise(conversationId: string, messages: UIMessage[], layers?: {
|
|
21
|
+
streaming?: Layer.Layer<Streaming>;
|
|
22
|
+
persistence?: Layer.Layer<Persistence>;
|
|
23
|
+
messageQueue?: Layer.Layer<MessageQueue>;
|
|
24
|
+
stopSignal?: Layer.Layer<StopSignal>;
|
|
25
|
+
}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CAAA;QACxC,UAAU,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;KACrC,GACA,OAAO,CAAC,UAAU,CAAC;CAavB"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Effect, Layer, Option } from "effect";
|
|
2
|
+
import { runLoop } from "./loop.js";
|
|
3
|
+
import { NoopMessageQueueLayer, } from "./services/MessageQueue.js";
|
|
4
|
+
import { NoopPersistenceLayer, Persistence } from "./services/Persistence.js";
|
|
5
|
+
import { NoopStopSignalLayer } from "./services/StopSignal.js";
|
|
6
|
+
import { NoopStreamingLayer } from "./services/Streaming.js";
|
|
7
|
+
export class Agent {
|
|
8
|
+
config;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Run a conversation turn. Returns an Effect that requires
|
|
14
|
+
* the relevant services to be provided via layers.
|
|
15
|
+
*/
|
|
16
|
+
run(conversationId, messages) {
|
|
17
|
+
const config = this.config;
|
|
18
|
+
return Effect.gen(function* () {
|
|
19
|
+
const persistence = yield* Effect.serviceOption(Persistence);
|
|
20
|
+
const history = Option.isSome(persistence)
|
|
21
|
+
? yield* persistence.value.loadMessages(conversationId)
|
|
22
|
+
: [];
|
|
23
|
+
const allMessages = [...history, ...messages];
|
|
24
|
+
const system = typeof config.system === "function"
|
|
25
|
+
? config.system({ stepNumber: 0, steps: [], messages: allMessages })
|
|
26
|
+
: config.system;
|
|
27
|
+
const result = yield* runLoop({
|
|
28
|
+
model: config.model,
|
|
29
|
+
conversationId,
|
|
30
|
+
system,
|
|
31
|
+
tools: config.tools,
|
|
32
|
+
executeTools: config.executeTools,
|
|
33
|
+
initialMessages: allMessages,
|
|
34
|
+
callSettings: config.callSettings,
|
|
35
|
+
prepareStep: config.prepareStep,
|
|
36
|
+
onContextOverflow: config.onContextOverflow,
|
|
37
|
+
hooks: config.hooks,
|
|
38
|
+
});
|
|
39
|
+
if (Option.isSome(persistence)) {
|
|
40
|
+
yield* persistence.value.saveMessages(conversationId, result.messages);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Convenience: run with provided layers, returns a Promise.
|
|
47
|
+
*/
|
|
48
|
+
runPromise(conversationId, messages, layers) {
|
|
49
|
+
const layer = Layer.mergeAll(layers?.streaming ?? NoopStreamingLayer, layers?.persistence ?? NoopPersistenceLayer, layers?.messageQueue ?? NoopMessageQueueLayer, layers?.stopSignal ?? NoopStopSignalLayer);
|
|
50
|
+
return this.run(conversationId, messages).pipe(Effect.provide(layer), Effect.runPromise);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAM9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAEL,qBAAqB,GACtB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAC7E,OAAO,EAAE,mBAAmB,EAAmB,MAAM,0BAA0B,CAAA;AAC/E,OAAO,EAAE,kBAAkB,EAAkB,MAAM,yBAAyB,CAAA;AAG5E,MAAM,OAAO,KAAK;IACI;IAApB,YAAoB,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAAG,CAAC;IAE3C;;;OAGG;IACH,GAAG,CACD,cAAsB,EACtB,QAAqB;QAMrB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;QAE1B,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACzB,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,MAAM,CA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AK,CAAC,QAAQ,CAC1B,MAAM,EAAE,SAAS,IAAI,kBAAkB,EACvC,MAAM,EAAE,WAAW,IAAI,oBAAoB,EAC3C,MAAM,EAAE,YAAY,IAAI,qBAAqB,EAC7C,MAAM,EAAE,UAAU,IAAI,mBAAmB,CAC1C,CAAA;QAED,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,IAAI,CAC5C,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EACrB,MAAM,CAAC,UAAU,CAClB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message cleanup utilities that run before each doStream call.
|
|
3
|
+
* Fixes corrupted conversation history from interrupted streams,
|
|
4
|
+
* race conditions, or partial tool execution.
|
|
5
|
+
*/
|
|
6
|
+
import type { LanguageModelV3Prompt } from "@ai-sdk/provider";
|
|
7
|
+
/**
|
|
8
|
+
* Patch missing tool results in the prompt to prevent provider errors.
|
|
9
|
+
* When a stream is interrupted while a tool call is pending, the history
|
|
10
|
+
* has an assistant tool-call with no matching tool-result. This injects
|
|
11
|
+
* a synthetic error result so the model can see what happened.
|
|
12
|
+
*/
|
|
13
|
+
export declare function patchMissingToolResults(prompt: LanguageModelV3Prompt): void;
|
|
14
|
+
/**
|
|
15
|
+
* Deduplicate tool-call IDs in the prompt to prevent provider errors.
|
|
16
|
+
* Corrupted history can leave duplicate toolUse blocks (e.g., from
|
|
17
|
+
* saving after API errors). Renames duplicates with a suffix.
|
|
18
|
+
*/
|
|
19
|
+
export declare function deduplicateToolIds(prompt: LanguageModelV3Prompt): void;
|
|
20
|
+
/**
|
|
21
|
+
* Run all cleanup steps on a prompt before sending to the model.
|
|
22
|
+
*/
|
|
23
|
+
export declare function cleanupPrompt(prompt: LanguageModelV3Prompt): void;
|
|
24
|
+
//# sourceMappingURL=cleanup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../src/cleanup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAE7D;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CA2E3E;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CA8DtE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAGjE"}
|
package/dist/cleanup.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message cleanup utilities that run before each doStream call.
|
|
3
|
+
* Fixes corrupted conversation history from interrupted streams,
|
|
4
|
+
* race conditions, or partial tool execution.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Patch missing tool results in the prompt to prevent provider errors.
|
|
8
|
+
* When a stream is interrupted while a tool call is pending, the history
|
|
9
|
+
* has an assistant tool-call with no matching tool-result. This injects
|
|
10
|
+
* a synthetic error result so the model can see what happened.
|
|
11
|
+
*/
|
|
12
|
+
export function patchMissingToolResults(prompt) {
|
|
13
|
+
// Collect all tool-call IDs from assistant messages
|
|
14
|
+
const toolCallIds = new Map(); // id → toolName
|
|
15
|
+
for (const msg of prompt) {
|
|
16
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content))
|
|
17
|
+
continue;
|
|
18
|
+
for (const part of msg.content) {
|
|
19
|
+
if ("type" in part &&
|
|
20
|
+
part.type === "tool-call" &&
|
|
21
|
+
"toolCallId" in part &&
|
|
22
|
+
typeof part.toolCallId === "string") {
|
|
23
|
+
toolCallIds.set(part.toolCallId, "toolName" in part && typeof part.toolName === "string"
|
|
24
|
+
? part.toolName
|
|
25
|
+
: "unknown");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Remove IDs that have matching tool-result
|
|
30
|
+
for (const msg of prompt) {
|
|
31
|
+
if (msg.role !== "tool" || !Array.isArray(msg.content))
|
|
32
|
+
continue;
|
|
33
|
+
for (const part of msg.content) {
|
|
34
|
+
if ("type" in part &&
|
|
35
|
+
part.type === "tool-result" &&
|
|
36
|
+
"toolCallId" in part &&
|
|
37
|
+
typeof part.toolCallId === "string") {
|
|
38
|
+
toolCallIds.delete(part.toolCallId);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (toolCallIds.size === 0)
|
|
43
|
+
return;
|
|
44
|
+
// Insert synthetic tool-result messages after assistant messages with orphaned calls
|
|
45
|
+
for (let i = prompt.length - 1; i >= 0; i--) {
|
|
46
|
+
const msg = prompt[i];
|
|
47
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content))
|
|
48
|
+
continue;
|
|
49
|
+
const orphans = [];
|
|
50
|
+
for (const part of msg.content) {
|
|
51
|
+
if ("type" in part &&
|
|
52
|
+
part.type === "tool-call" &&
|
|
53
|
+
"toolCallId" in part &&
|
|
54
|
+
typeof part.toolCallId === "string" &&
|
|
55
|
+
toolCallIds.has(part.toolCallId)) {
|
|
56
|
+
orphans.push({
|
|
57
|
+
id: part.toolCallId,
|
|
58
|
+
name: toolCallIds.get(part.toolCallId),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (orphans.length === 0)
|
|
63
|
+
continue;
|
|
64
|
+
prompt.splice(i + 1, 0, {
|
|
65
|
+
role: "tool",
|
|
66
|
+
content: orphans.map(({ id, name }) => ({
|
|
67
|
+
type: "tool-result",
|
|
68
|
+
toolCallId: id,
|
|
69
|
+
toolName: name,
|
|
70
|
+
output: {
|
|
71
|
+
type: "text",
|
|
72
|
+
value: "Tool execution was interrupted.",
|
|
73
|
+
},
|
|
74
|
+
})),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Deduplicate tool-call IDs in the prompt to prevent provider errors.
|
|
80
|
+
* Corrupted history can leave duplicate toolUse blocks (e.g., from
|
|
81
|
+
* saving after API errors). Renames duplicates with a suffix.
|
|
82
|
+
*/
|
|
83
|
+
export function deduplicateToolIds(prompt) {
|
|
84
|
+
const seenIds = new Set();
|
|
85
|
+
const renames = new Map();
|
|
86
|
+
let counter = 0;
|
|
87
|
+
// Pass 1: rename duplicate tool-call IDs in assistant messages
|
|
88
|
+
for (const msg of prompt) {
|
|
89
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content))
|
|
90
|
+
continue;
|
|
91
|
+
for (const part of msg.content) {
|
|
92
|
+
if (!("type" in part) ||
|
|
93
|
+
part.type !== "tool-call" ||
|
|
94
|
+
!("toolCallId" in part) ||
|
|
95
|
+
typeof part.toolCallId !== "string") {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (seenIds.has(part.toolCallId)) {
|
|
99
|
+
const originalId = part.toolCallId;
|
|
100
|
+
const newId = `${originalId}-dedup-${++counter}`;
|
|
101
|
+
part.toolCallId = newId;
|
|
102
|
+
if (!renames.has(originalId))
|
|
103
|
+
renames.set(originalId, []);
|
|
104
|
+
renames.get(originalId).push(newId);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
seenIds.add(part.toolCallId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (renames.size === 0)
|
|
112
|
+
return;
|
|
113
|
+
// Pass 2: rename matching tool-result IDs
|
|
114
|
+
const resultCounts = new Map();
|
|
115
|
+
for (const msg of prompt) {
|
|
116
|
+
if (msg.role !== "tool" || !Array.isArray(msg.content))
|
|
117
|
+
continue;
|
|
118
|
+
for (const part of msg.content) {
|
|
119
|
+
if (!("type" in part) ||
|
|
120
|
+
part.type !== "tool-result" ||
|
|
121
|
+
!("toolCallId" in part) ||
|
|
122
|
+
typeof part.toolCallId !== "string") {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const originalId = part.toolCallId;
|
|
126
|
+
const newIds = renames.get(originalId);
|
|
127
|
+
if (!newIds)
|
|
128
|
+
continue;
|
|
129
|
+
const count = resultCounts.get(originalId) ?? 0;
|
|
130
|
+
resultCounts.set(originalId, count + 1);
|
|
131
|
+
// First occurrence is the original (kept as-is), subsequent match renames
|
|
132
|
+
if (count > 0 && count - 1 < newIds.length) {
|
|
133
|
+
;
|
|
134
|
+
part.toolCallId = newIds[count - 1];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Run all cleanup steps on a prompt before sending to the model.
|
|
141
|
+
*/
|
|
142
|
+
export function cleanupPrompt(prompt) {
|
|
143
|
+
deduplicateToolIds(prompt);
|
|
144
|
+
patchMissingToolResults(prompt);
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=cleanup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleanup.js","sourceRoot":"","sources":["../src/cleanup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAA6B;IACnE,oDAAoD;IACpD,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAC,gBAAgB;IAC9D,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,SAAQ;QACrE,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAC/B,IACE,MAAM,IAAI,IAAI;gBACd,IAAI,CAAC,IAAI,KAAK,WAAW;gBACzB,YAAY,IAAI,IAAI;gBACpB,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,EACnC,CAAC;gBACD,WAAW,CAAC,GAAG,CACb,IAAI,CAAC,UAAU,EAC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UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;YAClC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;YACtC,IAAI,CAAC,MAAM;gBAAE,SAAQ;YAErB,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;YAC/C,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;YAEvC,0EAA0E;YAC1E,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;gBAC3C,CAAC;gBAAC,IAA+B,CAAC,UAAU,GAAG,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;YAClE,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAA6B;IACzD,kBAAkB,CAAC,MAAM,CAAC,CAAA;IAC1B,uBAAuB,CAAC,MAAM,CAAC,CAAA;AACjC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversion utilities between AI SDK provider types (V3) and
|
|
3
|
+
* the higher-level AI SDK types (LanguageModelUsage, FinishReason, UIMessage, UIMessageChunk).
|
|
4
|
+
*
|
|
5
|
+
* These bridge the gap between model.doStream() output and what kai exposes.
|
|
6
|
+
*/
|
|
7
|
+
import type { LanguageModelV3StreamPart, LanguageModelV3Usage } from "@ai-sdk/provider";
|
|
8
|
+
import type { FinishReason, LanguageModelUsage, ToolSet, UIMessage, UIMessageChunk } from "ai";
|
|
9
|
+
import type { ParsedToolCall, ToolCallResult } from "./types.js";
|
|
10
|
+
export declare function toFinishReason(raw: string): FinishReason;
|
|
11
|
+
export declare const EMPTY_USAGE: LanguageModelUsage;
|
|
12
|
+
export declare function addUsage(a: LanguageModelUsage, b: LanguageModelUsage): LanguageModelUsage;
|
|
13
|
+
export declare function v3UsageToUsage(v3: LanguageModelV3Usage): LanguageModelUsage;
|
|
14
|
+
/** Convert ToolSet to the model tool format using AI SDK internals. */
|
|
15
|
+
export declare function prepareTools(tools: ToolSet): Promise<{
|
|
16
|
+
tools: Array<import("@ai-sdk/provider").LanguageModelV3FunctionTool | import("@ai-sdk/provider").LanguageModelV3ProviderTool> | undefined;
|
|
17
|
+
toolChoice: import("@ai-sdk/provider").LanguageModelV3ToolChoice | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function extractText(parts: LanguageModelV3StreamPart[]): string;
|
|
20
|
+
export declare function extractToolCalls(parts: LanguageModelV3StreamPart[]): ParsedToolCall[];
|
|
21
|
+
export declare function toUIChunk(part: LanguageModelV3StreamPart): UIMessageChunk | null;
|
|
22
|
+
/**
|
|
23
|
+
* Build a UIMessage for an assistant response. Tool calls and results
|
|
24
|
+
* are represented as ToolUIPart entries (type: `tool-${name}`).
|
|
25
|
+
*
|
|
26
|
+
* Note: UIMessage.parts is generic over the ToolSet, so we can't
|
|
27
|
+
* statically verify tool part shapes without the concrete tool types.
|
|
28
|
+
* The objects we build match the ToolUIPart runtime contract.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildAssistantMessage(text: string, toolCalls: ParsedToolCall[], toolResults?: ToolCallResult[], responseId?: string): UIMessage;
|
|
31
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACrB,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,OAAO,EACP,SAAS,EACT,cAAc,EACf,MAAM,IAAI,CAAA;AAEX,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAahE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAExD;AAID,eAAO,MAAM,WAAW,EAAE,kBAazB,CAAA;AAED,wBAAgB,QAAQ,CACtB,CAAC,EAAE,kBAAkB,EACrB,CAAC,EAAE,kBAAkB,GACpB,kBAAkB,CA+BpB;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,oBAAoB,GAAG,kBAAkB,CAgB3E;AAYD,uEAAuE;AACvE,wBAAsB,YAAY,CAAC,KAAK,EAAE,OAAO;;;GAMhD;AAID,wBAAgB,WAAW,CAAC,KAAK,EAAE,yBAAyB,EAAE,GAAG,MAAM,CAMtE;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,yBAAyB,EAAE,GACjC,cAAc,EAAE,CAmClB;AAID,wBAAgB,SAAS,CACvB,IAAI,EAAE,yBAAyB,GAC9B,cAAc,GAAG,IAAI,CAuCvB;AAMD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,cAAc,EAAE,EAC3B,WAAW,CAAC,EAAE,cAAc,EAAE,EAC9B,UAAU,CAAC,EAAE,MAAM,GAClB,SAAS,CAiDX"}
|
package/dist/convert.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversion utilities between AI SDK provider types (V3) and
|
|
3
|
+
* the higher-level AI SDK types (LanguageModelUsage, FinishReason, UIMessage, UIMessageChunk).
|
|
4
|
+
*
|
|
5
|
+
* These bridge the gap between model.doStream() output and what kai exposes.
|
|
6
|
+
*/
|
|
7
|
+
import { prepareToolsAndToolChoice } from "ai/internal";
|
|
8
|
+
// -- FinishReason -----------------------------------------------------------
|
|
9
|
+
const FINISH_REASON_MAP = {
|
|
10
|
+
stop: "stop",
|
|
11
|
+
length: "length",
|
|
12
|
+
"content-filter": "content-filter",
|
|
13
|
+
"tool-calls": "tool-calls",
|
|
14
|
+
error: "error",
|
|
15
|
+
other: "other",
|
|
16
|
+
};
|
|
17
|
+
export function toFinishReason(raw) {
|
|
18
|
+
return FINISH_REASON_MAP[raw] ?? "other";
|
|
19
|
+
}
|
|
20
|
+
// -- Usage ------------------------------------------------------------------
|
|
21
|
+
export const EMPTY_USAGE = {
|
|
22
|
+
inputTokens: undefined,
|
|
23
|
+
inputTokenDetails: {
|
|
24
|
+
noCacheTokens: undefined,
|
|
25
|
+
cacheReadTokens: undefined,
|
|
26
|
+
cacheWriteTokens: undefined,
|
|
27
|
+
},
|
|
28
|
+
outputTokens: undefined,
|
|
29
|
+
outputTokenDetails: {
|
|
30
|
+
textTokens: undefined,
|
|
31
|
+
reasoningTokens: undefined,
|
|
32
|
+
},
|
|
33
|
+
totalTokens: undefined,
|
|
34
|
+
};
|
|
35
|
+
export function addUsage(a, b) {
|
|
36
|
+
const add = addOptionalNumbers;
|
|
37
|
+
return {
|
|
38
|
+
inputTokens: add(a.inputTokens, b.inputTokens),
|
|
39
|
+
inputTokenDetails: {
|
|
40
|
+
noCacheTokens: add(a.inputTokenDetails?.noCacheTokens, b.inputTokenDetails?.noCacheTokens),
|
|
41
|
+
cacheReadTokens: add(a.inputTokenDetails?.cacheReadTokens, b.inputTokenDetails?.cacheReadTokens),
|
|
42
|
+
cacheWriteTokens: add(a.inputTokenDetails?.cacheWriteTokens, b.inputTokenDetails?.cacheWriteTokens),
|
|
43
|
+
},
|
|
44
|
+
outputTokens: add(a.outputTokens, b.outputTokens),
|
|
45
|
+
outputTokenDetails: {
|
|
46
|
+
textTokens: add(a.outputTokenDetails?.textTokens, b.outputTokenDetails?.textTokens),
|
|
47
|
+
reasoningTokens: add(a.outputTokenDetails?.reasoningTokens, b.outputTokenDetails?.reasoningTokens),
|
|
48
|
+
},
|
|
49
|
+
totalTokens: add(a.totalTokens, b.totalTokens),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export function v3UsageToUsage(v3) {
|
|
53
|
+
const add = addOptionalNumbers;
|
|
54
|
+
return {
|
|
55
|
+
inputTokens: v3.inputTokens.total,
|
|
56
|
+
inputTokenDetails: {
|
|
57
|
+
noCacheTokens: v3.inputTokens.noCache,
|
|
58
|
+
cacheReadTokens: v3.inputTokens.cacheRead,
|
|
59
|
+
cacheWriteTokens: v3.inputTokens.cacheWrite,
|
|
60
|
+
},
|
|
61
|
+
outputTokens: v3.outputTokens.total,
|
|
62
|
+
outputTokenDetails: {
|
|
63
|
+
textTokens: v3.outputTokens.text,
|
|
64
|
+
reasoningTokens: v3.outputTokens.reasoning,
|
|
65
|
+
},
|
|
66
|
+
totalTokens: add(v3.inputTokens.total, v3.outputTokens.total),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function addOptionalNumbers(a, b) {
|
|
70
|
+
if (a === undefined && b === undefined)
|
|
71
|
+
return undefined;
|
|
72
|
+
return (a ?? 0) + (b ?? 0);
|
|
73
|
+
}
|
|
74
|
+
// -- ToolSet → model tools (uses AI SDK's own conversion) -------------------
|
|
75
|
+
/** Convert ToolSet to the model tool format using AI SDK internals. */
|
|
76
|
+
export async function prepareTools(tools) {
|
|
77
|
+
return prepareToolsAndToolChoice({
|
|
78
|
+
tools,
|
|
79
|
+
toolChoice: undefined,
|
|
80
|
+
activeTools: undefined,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// -- Stream part extraction -------------------------------------------------
|
|
84
|
+
export function extractText(parts) {
|
|
85
|
+
const chunks = [];
|
|
86
|
+
for (const part of parts) {
|
|
87
|
+
if (part.type === "text-delta")
|
|
88
|
+
chunks.push(part.delta);
|
|
89
|
+
}
|
|
90
|
+
return chunks.join("");
|
|
91
|
+
}
|
|
92
|
+
export function extractToolCalls(parts) {
|
|
93
|
+
// Deduplicate: providers may emit both streaming (tool-input-start/delta/end)
|
|
94
|
+
// AND a final tool-call part for the same call. We keep one per toolCallId,
|
|
95
|
+
// preferring the tool-call part (has fully parsed input from the provider).
|
|
96
|
+
const byId = new Map();
|
|
97
|
+
const pending = new Map();
|
|
98
|
+
for (const part of parts) {
|
|
99
|
+
if (part.type === "tool-input-start") {
|
|
100
|
+
pending.set(part.id, { toolName: part.toolName, chunks: [] });
|
|
101
|
+
}
|
|
102
|
+
else if (part.type === "tool-input-delta") {
|
|
103
|
+
pending.get(part.id)?.chunks.push(part.delta);
|
|
104
|
+
}
|
|
105
|
+
else if (part.type === "tool-input-end") {
|
|
106
|
+
const entry = pending.get(part.id);
|
|
107
|
+
if (entry && !byId.has(part.id)) {
|
|
108
|
+
byId.set(part.id, {
|
|
109
|
+
type: "tool-call",
|
|
110
|
+
toolCallId: part.id,
|
|
111
|
+
toolName: entry.toolName,
|
|
112
|
+
input: safeParse(entry.chunks.join("")),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
pending.delete(part.id);
|
|
116
|
+
}
|
|
117
|
+
else if (part.type === "tool-call") {
|
|
118
|
+
// Overwrite streaming version — tool-call has provider-parsed input
|
|
119
|
+
byId.set(part.toolCallId, {
|
|
120
|
+
type: "tool-call",
|
|
121
|
+
toolCallId: part.toolCallId,
|
|
122
|
+
toolName: part.toolName,
|
|
123
|
+
input: typeof part.input === "string" ? safeParse(part.input) : part.input,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return Array.from(byId.values());
|
|
128
|
+
}
|
|
129
|
+
// -- V3 stream part → UIMessageChunk ---------------------------------------
|
|
130
|
+
export function toUIChunk(part) {
|
|
131
|
+
switch (part.type) {
|
|
132
|
+
case "text-start":
|
|
133
|
+
return { type: "text-start", id: part.id };
|
|
134
|
+
case "text-delta":
|
|
135
|
+
return { type: "text-delta", id: part.id, delta: part.delta };
|
|
136
|
+
case "text-end":
|
|
137
|
+
return { type: "text-end", id: part.id };
|
|
138
|
+
case "reasoning-start":
|
|
139
|
+
return { type: "reasoning-start", id: part.id };
|
|
140
|
+
case "reasoning-delta":
|
|
141
|
+
return { type: "reasoning-delta", id: part.id, delta: part.delta };
|
|
142
|
+
case "reasoning-end":
|
|
143
|
+
return { type: "reasoning-end", id: part.id };
|
|
144
|
+
case "tool-input-start":
|
|
145
|
+
return {
|
|
146
|
+
type: "tool-input-start",
|
|
147
|
+
toolCallId: part.id,
|
|
148
|
+
toolName: part.toolName,
|
|
149
|
+
};
|
|
150
|
+
case "tool-input-delta":
|
|
151
|
+
return {
|
|
152
|
+
type: "tool-input-delta",
|
|
153
|
+
toolCallId: part.id,
|
|
154
|
+
inputTextDelta: part.delta,
|
|
155
|
+
};
|
|
156
|
+
case "tool-call":
|
|
157
|
+
return {
|
|
158
|
+
type: "tool-input-available",
|
|
159
|
+
toolCallId: part.toolCallId,
|
|
160
|
+
toolName: part.toolName,
|
|
161
|
+
input: part.input,
|
|
162
|
+
};
|
|
163
|
+
// `finish` is NOT emitted here — the loop emits a message-level finish
|
|
164
|
+
// after the full turn completes (including tool execution). The per-step
|
|
165
|
+
// finish from doStream() is an internal signal, not a frontend event.
|
|
166
|
+
default:
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// -- Build UIMessage from step results --------------------------------------
|
|
171
|
+
let msgCounter = 0;
|
|
172
|
+
/**
|
|
173
|
+
* Build a UIMessage for an assistant response. Tool calls and results
|
|
174
|
+
* are represented as ToolUIPart entries (type: `tool-${name}`).
|
|
175
|
+
*
|
|
176
|
+
* Note: UIMessage.parts is generic over the ToolSet, so we can't
|
|
177
|
+
* statically verify tool part shapes without the concrete tool types.
|
|
178
|
+
* The objects we build match the ToolUIPart runtime contract.
|
|
179
|
+
*/
|
|
180
|
+
export function buildAssistantMessage(text, toolCalls, toolResults, responseId) {
|
|
181
|
+
const resultMap = new Map((toolResults ?? []).map((tr) => [tr.toolCallId, tr]));
|
|
182
|
+
// Build parts as a plain array — tool parts match ToolUIPart at runtime
|
|
183
|
+
// but can't be statically verified without the generic ToolSet parameter.
|
|
184
|
+
const parts = [];
|
|
185
|
+
if (text) {
|
|
186
|
+
parts.push({ type: "text", text });
|
|
187
|
+
}
|
|
188
|
+
for (const tc of toolCalls) {
|
|
189
|
+
const result = resultMap.get(tc.toolCallId);
|
|
190
|
+
if (result?.isError) {
|
|
191
|
+
parts.push({
|
|
192
|
+
type: `tool-${tc.toolName}`,
|
|
193
|
+
toolCallId: tc.toolCallId,
|
|
194
|
+
state: "output-error",
|
|
195
|
+
input: tc.input,
|
|
196
|
+
errorText: String(result.output),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else if (result) {
|
|
200
|
+
parts.push({
|
|
201
|
+
type: `tool-${tc.toolName}`,
|
|
202
|
+
toolCallId: tc.toolCallId,
|
|
203
|
+
state: "output-available",
|
|
204
|
+
input: tc.input,
|
|
205
|
+
output: result.output,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
parts.push({
|
|
210
|
+
type: `tool-${tc.toolName}`,
|
|
211
|
+
toolCallId: tc.toolCallId,
|
|
212
|
+
state: "input-available",
|
|
213
|
+
input: tc.input,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// UIMessage accepts parts as the generic UIMessagePart[] union.
|
|
218
|
+
// Our plain objects satisfy the runtime contract.
|
|
219
|
+
return {
|
|
220
|
+
id: `kai_${Date.now()}_${++msgCounter}`,
|
|
221
|
+
role: "assistant",
|
|
222
|
+
parts,
|
|
223
|
+
...(responseId ? { metadata: { responseId } } : {}),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
// -- Helpers ----------------------------------------------------------------
|
|
227
|
+
function safeParse(json) {
|
|
228
|
+
try {
|
|
229
|
+
return JSON.parse(json);
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return json;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAGvD,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aAChB,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,gEAAgE;IAChE,kDAAkD;IAClD,OAAO;QACL,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE;QACvC,IAAI,EAAE,WAAW;QACjB,KAAK;QACL,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvC,CAAA;AAChB,CAAC;AAED,8EAA8E;AAE9E,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { LanguageModelUsage } from "ai";
|
|
2
|
+
declare const StreamError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
3
|
+
readonly _tag: "StreamError";
|
|
4
|
+
} & Readonly<A>;
|
|
5
|
+
export declare class StreamError extends StreamError_base<{
|
|
6
|
+
readonly cause: unknown;
|
|
7
|
+
}> {
|
|
8
|
+
}
|
|
9
|
+
declare const ToolExecutionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
10
|
+
readonly _tag: "ToolExecutionError";
|
|
11
|
+
} & Readonly<A>;
|
|
12
|
+
export declare class ToolExecutionError extends ToolExecutionError_base<{
|
|
13
|
+
readonly toolName: string;
|
|
14
|
+
readonly toolCallId: string;
|
|
15
|
+
readonly cause: unknown;
|
|
16
|
+
}> {
|
|
17
|
+
}
|
|
18
|
+
declare const PersistenceError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
19
|
+
readonly _tag: "PersistenceError";
|
|
20
|
+
} & Readonly<A>;
|
|
21
|
+
export declare class PersistenceError extends PersistenceError_base<{
|
|
22
|
+
readonly cause: unknown;
|
|
23
|
+
}> {
|
|
24
|
+
}
|
|
25
|
+
declare const ContextOverflowError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
26
|
+
readonly _tag: "ContextOverflowError";
|
|
27
|
+
} & Readonly<A>;
|
|
28
|
+
export declare class ContextOverflowError extends ContextOverflowError_base<{
|
|
29
|
+
readonly usage: LanguageModelUsage;
|
|
30
|
+
}> {
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,IAAI,CAAA;;;;AAG5C,qBAAa,WAAY,SAAQ,iBAAgC;IAC/D,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;CAAG;;;;AAEL,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC7E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;CAAG;;;;AAEL,qBAAa,gBAAiB,SAAQ,sBAAqC;IACzE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;CAAG;;;;AAEL,qBAAa,oBAAqB,SAAQ,0BAExC;IACA,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAA;CACnC,CAAC;CAAG"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
export class StreamError extends Data.TaggedError("StreamError") {
|
|
3
|
+
}
|
|
4
|
+
export class ToolExecutionError extends Data.TaggedError("ToolExecutionError") {
|
|
5
|
+
}
|
|
6
|
+
export class PersistenceError extends Data.TaggedError("PersistenceError") {
|
|
7
|
+
}
|
|
8
|
+
export class ContextOverflowError extends Data.TaggedError("ContextOverflowError") {
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAE7B,MAAM,OAAO,WAAY,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAE7D;CAAG;AAEL,MAAM,OAAO,kBAAmB,SAAQ,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAI3E;CAAG;AAEL,MAAM,OAAO,gBAAiB,SAAQ,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAEvE;CAAG;AAEL,MAAM,OAAO,oBAAqB,SAAQ,IAAI,CAAC,WAAW,CACxD,sBAAsB,CAGtB;CAAG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Agent } from "./agent.js";
|
|
2
|
+
export { ContextOverflowError, PersistenceError, StreamError, ToolExecutionError, } from "./errors.js";
|
|
3
|
+
export type { LoopConfig } from "./loop.js";
|
|
4
|
+
export { runLoop } from "./loop.js";
|
|
5
|
+
export { MessageQueue, NoopMessageQueueLayer, NoopPersistenceLayer, NoopStopSignalLayer, NoopStreamingLayer, Persistence, StopSignal, Streaming, } from "./services/index.js";
|
|
6
|
+
export { executeTool, executeToolCalls } from "./tools.js";
|
|
7
|
+
export type { AgentConfig, AgentHooks, CallSettings, ExecuteToolsFn, FinishReason, LanguageModelUsage, LanguageModelV3, LoopFinishReason, LoopResult, ParsedToolCall, PrepareStepFn, StepConfig, StepContext, StepResult, StreamChunk, ToolCallResult, ToolSet, UIMessage, UIMessageChunk, } from "./types.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,SAAS,GACV,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE1D,YAAY,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,aAAa,EACb,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,cAAc,EACd,OAAO,EACP,SAAS,EACT,cAAc,GACf,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Agent } from "./agent.js";
|
|
2
|
+
export { ContextOverflowError, PersistenceError, StreamError, ToolExecutionError, } from "./errors.js";
|
|
3
|
+
export { runLoop } from "./loop.js";
|
|
4
|
+
export { MessageQueue, NoopMessageQueueLayer, NoopPersistenceLayer, NoopStopSignalLayer, NoopStreamingLayer, Persistence, StopSignal, Streaming, } from "./services/index.js";
|
|
5
|
+
export { executeTool, executeToolCalls } from "./tools.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,SAAS,GACV,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA"}
|