@chatbotkit/agent 1.30.1 → 1.31.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/dist/cjs/execute.cjs +28 -14
- package/dist/cjs/execute.d.ts +22 -9
- package/dist/esm/execute.d.ts +22 -9
- package/dist/esm/execute.js +28 -14
- package/package.json +2 -2
package/dist/cjs/execute.cjs
CHANGED
|
@@ -5,7 +5,7 @@ exports.execute = execute;
|
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
7
7
|
async function* complete(options) {
|
|
8
|
-
const { client, tools, abortSignal, ...request } = options;
|
|
8
|
+
const { client, tools, abortSignal, conversationId, ...request } = (options);
|
|
9
9
|
const channelToTool = new Map();
|
|
10
10
|
const functions = tools
|
|
11
11
|
? Object.entries(tools).map(([name, tool]) => {
|
|
@@ -43,15 +43,31 @@ async function* complete(options) {
|
|
|
43
43
|
};
|
|
44
44
|
})
|
|
45
45
|
: undefined;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
let stream;
|
|
47
|
+
if (typeof conversationId === 'string') {
|
|
48
|
+
const streamRequest = ({
|
|
49
|
+
...request,
|
|
50
|
+
functions,
|
|
51
|
+
limits: {
|
|
52
|
+
iterations: 1,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
stream = client.conversation
|
|
56
|
+
.complete(conversationId, streamRequest)
|
|
57
|
+
.stream({ abortSignal });
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const streamRequest = ({
|
|
61
|
+
...request,
|
|
62
|
+
functions,
|
|
63
|
+
limits: {
|
|
64
|
+
iterations: 1,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
stream = client.conversation.complete(null, streamRequest).stream({
|
|
68
|
+
abortSignal,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
55
71
|
const toolEventQueue = [];
|
|
56
72
|
const runningToolPromises = [];
|
|
57
73
|
const executeToolAsync = async (channel, name, tool, args) => {
|
|
@@ -142,7 +158,6 @@ async function* complete(options) {
|
|
|
142
158
|
}
|
|
143
159
|
async function* execute(options) {
|
|
144
160
|
const { client, tools = {}, maxIterations = 100, abortSignal, ...request } = options;
|
|
145
|
-
const messages = request.messages || [];
|
|
146
161
|
let exitResult = null;
|
|
147
162
|
let internalAbort = null;
|
|
148
163
|
const systemTools = {
|
|
@@ -273,7 +288,6 @@ The goal is to complete the assigned task efficiently and effectively. Follow th
|
|
|
273
288
|
for await (const event of complete({
|
|
274
289
|
...request,
|
|
275
290
|
client,
|
|
276
|
-
messages,
|
|
277
291
|
tools: allTools,
|
|
278
292
|
abortSignal: iterSignal,
|
|
279
293
|
extensions: {
|
|
@@ -281,8 +295,8 @@ The goal is to complete the assigned task efficiently and effectively. Follow th
|
|
|
281
295
|
backstory: systemInstruction,
|
|
282
296
|
},
|
|
283
297
|
})) {
|
|
284
|
-
if (event.type === 'message') {
|
|
285
|
-
messages.push(event.data);
|
|
298
|
+
if (event.type === 'message' && 'messages' in request) {
|
|
299
|
+
request.messages.push(event.data);
|
|
286
300
|
}
|
|
287
301
|
if (event.type === 'result') {
|
|
288
302
|
if (event.data.end.reason) {
|
package/dist/cjs/execute.d.ts
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
export function complete(options:
|
|
1
|
+
export function complete(options: CompleteOptions): AsyncGenerator<ConversationCompleteStreamType | ConversationCompleteMessageStreamType | ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent, void, unknown>;
|
|
2
|
+
export function execute(options: ExecuteOptions): AsyncGenerator<ConversationCompleteStreamType | ConversationCompleteMessageStreamType | ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent | IterationEvent | ExitEvent, void, unknown>;
|
|
3
|
+
export type ZodObject = import("zod").ZodObject<any>;
|
|
4
|
+
export type ChatBotKit = import("@chatbotkit/sdk").ChatBotKit;
|
|
5
|
+
export type ConversationCompleteRequest = any;
|
|
6
|
+
export type ConversationCompleteStreamType = any;
|
|
7
|
+
export type ConversationCompleteMessageRequest = any;
|
|
8
|
+
export type ConversationCompleteMessageStreamType = any;
|
|
9
|
+
export type LocalCompleteOptions = Omit<ConversationCompleteRequest, "functions" | "limits"> & {
|
|
2
10
|
client: ChatBotKit;
|
|
11
|
+
conversationId?: undefined;
|
|
3
12
|
tools?: Tools;
|
|
4
13
|
abortSignal?: AbortSignal;
|
|
5
|
-
}
|
|
6
|
-
export
|
|
14
|
+
};
|
|
15
|
+
export type RemoteCompleteOptions = Omit<ConversationCompleteMessageRequest, "functions" | "limits"> & {
|
|
7
16
|
client: ChatBotKit;
|
|
17
|
+
conversationId: string;
|
|
8
18
|
tools?: Tools;
|
|
9
|
-
maxIterations?: number;
|
|
10
19
|
abortSignal?: AbortSignal;
|
|
11
|
-
}
|
|
12
|
-
export type
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
};
|
|
21
|
+
export type CompleteOptions = LocalCompleteOptions | RemoteCompleteOptions;
|
|
22
|
+
export type LocalExecuteOptions = LocalCompleteOptions & {
|
|
23
|
+
maxIterations?: number;
|
|
24
|
+
};
|
|
25
|
+
export type RemoteExecuteOptions = RemoteCompleteOptions & {
|
|
26
|
+
maxIterations?: number;
|
|
27
|
+
};
|
|
28
|
+
export type ExecuteOptions = LocalExecuteOptions | RemoteExecuteOptions;
|
|
16
29
|
export type ToolDefinition<T extends ZodObject> = {
|
|
17
30
|
description: string;
|
|
18
31
|
input?: T;
|
package/dist/esm/execute.d.ts
CHANGED
|
@@ -1,18 +1,31 @@
|
|
|
1
|
-
export function complete(options:
|
|
1
|
+
export function complete(options: CompleteOptions): AsyncGenerator<ConversationCompleteStreamType | ConversationCompleteMessageStreamType | ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent, void, unknown>;
|
|
2
|
+
export function execute(options: ExecuteOptions): AsyncGenerator<ConversationCompleteStreamType | ConversationCompleteMessageStreamType | ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent | IterationEvent | ExitEvent, void, unknown>;
|
|
3
|
+
export type ZodObject = import("zod").ZodObject<any>;
|
|
4
|
+
export type ChatBotKit = import("@chatbotkit/sdk").ChatBotKit;
|
|
5
|
+
export type ConversationCompleteRequest = import("@chatbotkit/sdk/conversation/v1").ConversationCompleteRequest;
|
|
6
|
+
export type ConversationCompleteStreamType = import("@chatbotkit/sdk/conversation/v1").ConversationCompleteStreamType;
|
|
7
|
+
export type ConversationCompleteMessageRequest = import("@chatbotkit/sdk/conversation/v1").ConversationCompleteMessageRequest;
|
|
8
|
+
export type ConversationCompleteMessageStreamType = import("@chatbotkit/sdk/conversation/v1").ConversationCompleteMessageStreamType;
|
|
9
|
+
export type LocalCompleteOptions = Omit<ConversationCompleteRequest, "functions" | "limits"> & {
|
|
2
10
|
client: ChatBotKit;
|
|
11
|
+
conversationId?: undefined;
|
|
3
12
|
tools?: Tools;
|
|
4
13
|
abortSignal?: AbortSignal;
|
|
5
|
-
}
|
|
6
|
-
export
|
|
14
|
+
};
|
|
15
|
+
export type RemoteCompleteOptions = Omit<ConversationCompleteMessageRequest, "functions" | "limits"> & {
|
|
7
16
|
client: ChatBotKit;
|
|
17
|
+
conversationId: string;
|
|
8
18
|
tools?: Tools;
|
|
9
|
-
maxIterations?: number;
|
|
10
19
|
abortSignal?: AbortSignal;
|
|
11
|
-
}
|
|
12
|
-
export type
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
};
|
|
21
|
+
export type CompleteOptions = LocalCompleteOptions | RemoteCompleteOptions;
|
|
22
|
+
export type LocalExecuteOptions = LocalCompleteOptions & {
|
|
23
|
+
maxIterations?: number;
|
|
24
|
+
};
|
|
25
|
+
export type RemoteExecuteOptions = RemoteCompleteOptions & {
|
|
26
|
+
maxIterations?: number;
|
|
27
|
+
};
|
|
28
|
+
export type ExecuteOptions = LocalExecuteOptions | RemoteExecuteOptions;
|
|
16
29
|
export type ToolDefinition<T extends ZodObject> = {
|
|
17
30
|
description: string;
|
|
18
31
|
input?: T;
|
package/dist/esm/execute.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
3
3
|
export async function* complete(options) {
|
|
4
|
-
const { client, tools, abortSignal, ...request } = options;
|
|
4
|
+
const { client, tools, abortSignal, conversationId, ...request } = (options);
|
|
5
5
|
const channelToTool = new Map();
|
|
6
6
|
const functions = tools
|
|
7
7
|
? Object.entries(tools).map(([name, tool]) => {
|
|
@@ -39,15 +39,31 @@ export async function* complete(options) {
|
|
|
39
39
|
};
|
|
40
40
|
})
|
|
41
41
|
: undefined;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
let stream;
|
|
43
|
+
if (typeof conversationId === 'string') {
|
|
44
|
+
const streamRequest = ({
|
|
45
|
+
...request,
|
|
46
|
+
functions,
|
|
47
|
+
limits: {
|
|
48
|
+
iterations: 1,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
stream = client.conversation
|
|
52
|
+
.complete(conversationId, streamRequest)
|
|
53
|
+
.stream({ abortSignal });
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const streamRequest = ({
|
|
57
|
+
...request,
|
|
58
|
+
functions,
|
|
59
|
+
limits: {
|
|
60
|
+
iterations: 1,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
stream = client.conversation.complete(null, streamRequest).stream({
|
|
64
|
+
abortSignal,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
51
67
|
const toolEventQueue = [];
|
|
52
68
|
const runningToolPromises = [];
|
|
53
69
|
const executeToolAsync = async (channel, name, tool, args) => {
|
|
@@ -138,7 +154,6 @@ export async function* complete(options) {
|
|
|
138
154
|
}
|
|
139
155
|
export async function* execute(options) {
|
|
140
156
|
const { client, tools = {}, maxIterations = 100, abortSignal, ...request } = options;
|
|
141
|
-
const messages = request.messages || [];
|
|
142
157
|
let exitResult = null;
|
|
143
158
|
let internalAbort = null;
|
|
144
159
|
const systemTools = {
|
|
@@ -269,7 +284,6 @@ The goal is to complete the assigned task efficiently and effectively. Follow th
|
|
|
269
284
|
for await (const event of complete({
|
|
270
285
|
...request,
|
|
271
286
|
client,
|
|
272
|
-
messages,
|
|
273
287
|
tools: allTools,
|
|
274
288
|
abortSignal: iterSignal,
|
|
275
289
|
extensions: {
|
|
@@ -277,8 +291,8 @@ The goal is to complete the assigned task efficiently and effectively. Follow th
|
|
|
277
291
|
backstory: systemInstruction,
|
|
278
292
|
},
|
|
279
293
|
})) {
|
|
280
|
-
if (event.type === 'message') {
|
|
281
|
-
messages.push(event.data);
|
|
294
|
+
if (event.type === 'message' && 'messages' in request) {
|
|
295
|
+
request.messages.push(event.data);
|
|
282
296
|
}
|
|
283
297
|
if (event.type === 'result') {
|
|
284
298
|
if (event.data.end.reason) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatbotkit/agent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.1",
|
|
4
4
|
"description": "ChatBotKit Agent implementation",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"engines": {
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
"js-yaml": "^4.1.0",
|
|
140
140
|
"zod": "^3.25.76",
|
|
141
141
|
"zod-to-json-schema": "^3.24.6",
|
|
142
|
-
"@chatbotkit/sdk": "1.
|
|
142
|
+
"@chatbotkit/sdk": "1.31.1"
|
|
143
143
|
},
|
|
144
144
|
"devDependencies": {
|
|
145
145
|
"@types/js-yaml": "^4.0.9",
|