@convex-dev/agent 0.0.15-alpha.2 → 0.0.16
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 +24 -0
- package/dist/commonjs/client/index.d.ts +222 -50
- package/dist/commonjs/client/index.d.ts.map +1 -1
- package/dist/commonjs/client/index.js +74 -28
- package/dist/commonjs/client/index.js.map +1 -1
- package/dist/commonjs/component/messages.d.ts +5 -6
- package/dist/commonjs/component/messages.d.ts.map +1 -1
- package/dist/commonjs/component/messages.js +1 -6
- package/dist/commonjs/component/messages.js.map +1 -1
- package/dist/commonjs/component/schema.d.ts +10 -10
- package/dist/commonjs/component/schema.d.ts.map +1 -1
- package/dist/commonjs/component/schema.js +1 -2
- package/dist/commonjs/component/schema.js.map +1 -1
- package/dist/esm/client/index.d.ts +222 -50
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +74 -28
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/component/messages.d.ts +5 -6
- package/dist/esm/component/messages.d.ts.map +1 -1
- package/dist/esm/component/messages.js +1 -6
- package/dist/esm/component/messages.js.map +1 -1
- package/dist/esm/component/schema.d.ts +10 -10
- package/dist/esm/component/schema.d.ts.map +1 -1
- package/dist/esm/component/schema.js +1 -2
- package/dist/esm/component/schema.js.map +1 -1
- package/package.json +3 -2
- package/src/client/index.test.ts +68 -0
- package/src/client/index.ts +139 -83
- package/src/component/_generated/api.d.ts +0 -1
- package/src/component/messages.ts +1 -8
- package/src/component/schema.ts +1 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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z1M,CAAC;AACjC,OAAO,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC;AAEnB,eAAe,MAAM,CAAC"}
|
|
@@ -6,12 +6,11 @@ import vectorTables, { vVectorId } from "./vector/tables.js";
|
|
|
6
6
|
export const schema = defineSchema({
|
|
7
7
|
threads: defineTable({
|
|
8
8
|
userId: v.optional(v.string()), // Unset for anonymous
|
|
9
|
-
// TODO: is this bubbling up in continue?
|
|
10
|
-
defaultSystemPrompt: v.optional(v.string()),
|
|
11
9
|
title: v.optional(v.string()),
|
|
12
10
|
summary: v.optional(v.string()),
|
|
13
11
|
status: vThreadStatus,
|
|
14
12
|
// DEPRECATED
|
|
13
|
+
defaultSystemPrompt: v.optional(v.string()),
|
|
15
14
|
parentThreadIds: v.optional(v.array(v.id("threads"))),
|
|
16
15
|
order: /*DEPRECATED*/ v.optional(v.number()),
|
|
17
16
|
}).index("userId", ["userId"]),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EACL,aAAa,EACb,QAAQ,EACR,cAAc,EACd,KAAK,EACL,MAAM,EACN,OAAO,EACP,2BAA2B,EAC3B,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,YAAY,EAAE,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE7D,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,CAAC;IACjC,OAAO,EAAE,WAAW,CAAC;QACnB,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,sBAAsB;QACtD,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","s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0.16",
|
|
11
11
|
"license": "Apache-2.0",
|
|
12
12
|
"keywords": [
|
|
13
13
|
"convex",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"test": "vitest run --typecheck",
|
|
29
29
|
"test:watch": "vitest --typecheck",
|
|
30
30
|
"test:debug": "vitest --inspect-brk --no-file-parallelism",
|
|
31
|
-
"test:coverage": "vitest run --coverage --coverage.reporter=text"
|
|
31
|
+
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
32
|
+
"version": "pbcopy <<<$version; vim CHANGELOG.md && git add CHANGELOG.md"
|
|
32
33
|
},
|
|
33
34
|
"files": [
|
|
34
35
|
"dist",
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { filterOutOrphanedToolMessages, MessageDoc } from ".";
|
|
3
|
+
|
|
4
|
+
describe("filterOutOrphanedToolMessages", () => {
|
|
5
|
+
const call1: MessageDoc = {
|
|
6
|
+
_id: "call1",
|
|
7
|
+
_creationTime: Date.now(),
|
|
8
|
+
order: 1,
|
|
9
|
+
stepOrder: 1,
|
|
10
|
+
tool: true,
|
|
11
|
+
message: {
|
|
12
|
+
role: "assistant",
|
|
13
|
+
content: [
|
|
14
|
+
{
|
|
15
|
+
type: "tool-call",
|
|
16
|
+
toolCallId: "1",
|
|
17
|
+
toolName: "tool1",
|
|
18
|
+
args: { test: "test" },
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
status: "success",
|
|
23
|
+
threadId: "1",
|
|
24
|
+
};
|
|
25
|
+
const response1: MessageDoc = {
|
|
26
|
+
_id: "response1",
|
|
27
|
+
_creationTime: Date.now(),
|
|
28
|
+
order: 1,
|
|
29
|
+
stepOrder: 1,
|
|
30
|
+
tool: true,
|
|
31
|
+
message: {
|
|
32
|
+
role: "tool",
|
|
33
|
+
content: [
|
|
34
|
+
{
|
|
35
|
+
type: "tool-result",
|
|
36
|
+
toolCallId: "1",
|
|
37
|
+
toolName: "tool1",
|
|
38
|
+
result: { test: "test" },
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
status: "success",
|
|
43
|
+
threadId: "1",
|
|
44
|
+
};
|
|
45
|
+
const call2: MessageDoc = {
|
|
46
|
+
_id: "call2",
|
|
47
|
+
_creationTime: Date.now(),
|
|
48
|
+
order: 1,
|
|
49
|
+
stepOrder: 2,
|
|
50
|
+
tool: true,
|
|
51
|
+
message: {
|
|
52
|
+
role: "assistant",
|
|
53
|
+
content: [{ type: "text", text: "Hello" }],
|
|
54
|
+
},
|
|
55
|
+
status: "success",
|
|
56
|
+
threadId: "1",
|
|
57
|
+
};
|
|
58
|
+
test("should not filter out extra tool calls", () => {
|
|
59
|
+
expect(filterOutOrphanedToolMessages([call1, response1, call2])).toEqual([
|
|
60
|
+
call1,
|
|
61
|
+
response1,
|
|
62
|
+
call2,
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
test("should filter out extra tool calls", () => {
|
|
66
|
+
expect(filterOutOrphanedToolMessages([response1, call2])).toEqual([call2]);
|
|
67
|
+
});
|
|
68
|
+
});
|
package/src/client/index.ts
CHANGED
|
@@ -336,7 +336,6 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
336
336
|
const threadDoc = await ctx.runMutation(
|
|
337
337
|
this.component.messages.createThread,
|
|
338
338
|
{
|
|
339
|
-
defaultSystemPrompt: this.options.instructions,
|
|
340
339
|
userId: args?.userId,
|
|
341
340
|
title: args?.title,
|
|
342
341
|
summary: args?.summary,
|
|
@@ -459,13 +458,21 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
459
458
|
statuses: ["success"],
|
|
460
459
|
}
|
|
461
460
|
);
|
|
462
|
-
contextMessages.push(
|
|
461
|
+
contextMessages.push(
|
|
462
|
+
// Reverse since we fetched in descending order
|
|
463
|
+
...page.filter((m) => !included?.has(m._id)).reverse()
|
|
464
|
+
);
|
|
463
465
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
466
|
+
|
|
467
|
+
// Sort the raw MessageDocs by order and stepOrder
|
|
468
|
+
const sortedDocs = contextMessages.sort((a, b) =>
|
|
469
|
+
a.order === b.order ? a.stepOrder - b.stepOrder : a.order - b.order
|
|
470
|
+
);
|
|
471
|
+
|
|
472
|
+
// Ensure we don't include tool messages without a corresponding tool call
|
|
473
|
+
return filterOutOrphanedToolMessages(sortedDocs).map((m) =>
|
|
474
|
+
deserializeMessage(m.message!)
|
|
475
|
+
);
|
|
469
476
|
}
|
|
470
477
|
|
|
471
478
|
/**
|
|
@@ -699,14 +706,16 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
699
706
|
*/
|
|
700
707
|
tools?: ToolSet;
|
|
701
708
|
},
|
|
702
|
-
args: TextArgs<AgentTools, TOOLS, OUTPUT, OUTPUT_PARTIAL
|
|
709
|
+
args: TextArgs<AgentTools, TOOLS, OUTPUT, OUTPUT_PARTIAL>,
|
|
710
|
+
options?: Options
|
|
703
711
|
): Promise<
|
|
704
712
|
GenerateTextResult<TOOLS extends undefined ? AgentTools : TOOLS, OUTPUT> &
|
|
705
713
|
GenerationOutputMetadata
|
|
706
714
|
> {
|
|
707
715
|
const { args: aiArgs, messageId } = await this.saveMessagesAndFetchContext(
|
|
708
716
|
ctx,
|
|
709
|
-
|
|
717
|
+
args,
|
|
718
|
+
{ userId, threadId, ...options }
|
|
710
719
|
);
|
|
711
720
|
const toolCtx = { ...ctx, userId, threadId, messageId };
|
|
712
721
|
const tools = wrapTools(
|
|
@@ -714,6 +723,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
714
723
|
args.tools ?? threadTools ?? this.options.tools
|
|
715
724
|
) as TOOLS extends undefined ? AgentTools : TOOLS;
|
|
716
725
|
const saveOutputMessages =
|
|
726
|
+
options?.storageOptions?.saveOutputMessages ??
|
|
717
727
|
args.saveOutputMessages ??
|
|
718
728
|
this.options.storageOptions?.saveOutputMessages;
|
|
719
729
|
const model = aiArgs.model ?? this.options.chat;
|
|
@@ -800,7 +810,8 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
800
810
|
usageHandler?: UsageHandler;
|
|
801
811
|
tools?: ToolSet;
|
|
802
812
|
},
|
|
803
|
-
args: StreamingTextArgs<AgentTools, TOOLS, OUTPUT, PARTIAL_OUTPUT
|
|
813
|
+
args: StreamingTextArgs<AgentTools, TOOLS, OUTPUT, PARTIAL_OUTPUT>,
|
|
814
|
+
options?: Options
|
|
804
815
|
): Promise<
|
|
805
816
|
StreamTextResult<
|
|
806
817
|
TOOLS extends undefined ? AgentTools : TOOLS,
|
|
@@ -810,7 +821,8 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
810
821
|
> {
|
|
811
822
|
const { args: aiArgs, messageId } = await this.saveMessagesAndFetchContext(
|
|
812
823
|
ctx,
|
|
813
|
-
|
|
824
|
+
args,
|
|
825
|
+
{ userId, threadId, ...options }
|
|
814
826
|
);
|
|
815
827
|
const toolCtx = { ...ctx, userId, threadId, messageId };
|
|
816
828
|
const tools = wrapTools(
|
|
@@ -818,6 +830,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
818
830
|
args.tools ?? threadTools ?? this.options.tools
|
|
819
831
|
) as TOOLS extends undefined ? AgentTools : TOOLS;
|
|
820
832
|
const saveOutputMessages =
|
|
833
|
+
options?.storageOptions?.saveOutputMessages ??
|
|
821
834
|
args.saveOutputMessages ??
|
|
822
835
|
this.options.storageOptions?.saveOutputMessages;
|
|
823
836
|
const model = aiArgs.model ?? this.options.chat;
|
|
@@ -885,28 +898,23 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
885
898
|
},
|
|
886
899
|
>(
|
|
887
900
|
ctx: RunActionCtx | RunMutationCtx,
|
|
901
|
+
args: T,
|
|
888
902
|
{
|
|
889
|
-
id,
|
|
890
903
|
userId,
|
|
891
904
|
threadId,
|
|
892
905
|
parentMessageId,
|
|
893
|
-
|
|
894
|
-
|
|
906
|
+
contextOptions,
|
|
907
|
+
storageOptions,
|
|
895
908
|
}: {
|
|
896
909
|
userId: string | undefined;
|
|
897
910
|
threadId: string | undefined;
|
|
898
|
-
|
|
899
|
-
contextOptions?: ContextOptions;
|
|
900
|
-
storageOptions?: StorageOptions;
|
|
901
|
-
} & T
|
|
911
|
+
} & Options
|
|
902
912
|
): Promise<{
|
|
903
913
|
args: T;
|
|
904
914
|
messageId: string | undefined;
|
|
905
915
|
}> {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
const storageOptions: StorageOptions | Record<string, unknown> =
|
|
909
|
-
args.storageOptions ?? this.options.storageOptions ?? args;
|
|
916
|
+
contextOptions ||= this.options.contextOptions ?? (args as ContextOptions);
|
|
917
|
+
storageOptions ||= this.options.storageOptions ?? (args as StorageOptions);
|
|
910
918
|
const messages = promptOrMessagesToCoreMessages(args);
|
|
911
919
|
const contextMessages = await this.fetchContextMessages(ctx, {
|
|
912
920
|
userId,
|
|
@@ -923,7 +931,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
923
931
|
threadId,
|
|
924
932
|
userId,
|
|
925
933
|
messages: coreMessages,
|
|
926
|
-
metadata: coreMessages.length === 1 ? [{ id }] : undefined,
|
|
934
|
+
metadata: coreMessages.length === 1 ? [{ id: args.id }] : undefined,
|
|
927
935
|
pending: true,
|
|
928
936
|
// We should just fail if you pass in an ID for the message, fail those children
|
|
929
937
|
// failPendingSteps: true,
|
|
@@ -935,7 +943,7 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
935
943
|
return {
|
|
936
944
|
args: {
|
|
937
945
|
...rest,
|
|
938
|
-
system: system ?? this.options.instructions,
|
|
946
|
+
system: args.system ?? this.options.instructions,
|
|
939
947
|
messages: [...contextMessages, ...messages],
|
|
940
948
|
} as T,
|
|
941
949
|
messageId,
|
|
@@ -961,15 +969,18 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
961
969
|
threadId,
|
|
962
970
|
usageHandler,
|
|
963
971
|
}: { userId?: string; threadId?: string; usageHandler?: UsageHandler },
|
|
964
|
-
args: OurObjectArgs<T
|
|
972
|
+
args: OurObjectArgs<T>,
|
|
973
|
+
options?: Options
|
|
965
974
|
): Promise<GenerateObjectResult<T> & GenerationOutputMetadata> {
|
|
966
975
|
const { args: aiArgs, messageId } = await this.saveMessagesAndFetchContext(
|
|
967
976
|
ctx,
|
|
968
|
-
|
|
977
|
+
args,
|
|
978
|
+
{ userId, threadId, ...options }
|
|
969
979
|
);
|
|
970
980
|
const model = aiArgs.model ?? this.options.chat;
|
|
971
981
|
const trackUsage = usageHandler ?? this.options.usageHandler;
|
|
972
982
|
const saveOutputMessages =
|
|
983
|
+
options?.storageOptions?.saveOutputMessages ??
|
|
973
984
|
args.saveOutputMessages ??
|
|
974
985
|
this.options.storageOptions?.saveOutputMessages;
|
|
975
986
|
try {
|
|
@@ -1027,18 +1038,21 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
1027
1038
|
threadId,
|
|
1028
1039
|
usageHandler,
|
|
1029
1040
|
}: { userId?: string; threadId?: string; usageHandler?: UsageHandler },
|
|
1030
|
-
args: OurStreamObjectArgs<T
|
|
1041
|
+
args: OurStreamObjectArgs<T>,
|
|
1042
|
+
options?: Options
|
|
1031
1043
|
): Promise<
|
|
1032
1044
|
StreamObjectResult<DeepPartial<T>, T, never> & GenerationOutputMetadata
|
|
1033
1045
|
> {
|
|
1034
1046
|
// TODO: unify all this shared code between all the generate* and stream* functions
|
|
1035
1047
|
const { args: aiArgs, messageId } = await this.saveMessagesAndFetchContext(
|
|
1036
1048
|
ctx,
|
|
1037
|
-
|
|
1049
|
+
args,
|
|
1050
|
+
{ userId, threadId, ...options }
|
|
1038
1051
|
);
|
|
1039
1052
|
const model = aiArgs.model ?? this.options.chat;
|
|
1040
1053
|
const trackUsage = usageHandler ?? this.options.usageHandler;
|
|
1041
1054
|
const saveOutputMessages =
|
|
1055
|
+
options?.storageOptions?.saveOutputMessages ??
|
|
1042
1056
|
args.saveOutputMessages ??
|
|
1043
1057
|
this.options.storageOptions?.saveOutputMessages;
|
|
1044
1058
|
const stream = streamObject<T>({
|
|
@@ -1226,18 +1240,30 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
1226
1240
|
* @param spec Configuration for the agent acting as an action, including
|
|
1227
1241
|
* {@link ContextOptions} and maxSteps.
|
|
1228
1242
|
*/
|
|
1229
|
-
asTextAction(spec?: {
|
|
1243
|
+
asTextAction(spec?: {
|
|
1244
|
+
contextOptions?: ContextOptions;
|
|
1245
|
+
maxSteps?: number;
|
|
1246
|
+
storageOptions?: StorageOptions;
|
|
1247
|
+
}) {
|
|
1230
1248
|
const maxSteps = spec?.maxSteps ?? this.options.maxSteps;
|
|
1231
|
-
const contextOptions =
|
|
1232
|
-
spec?.contextOptions && this.mergedContextOptions(spec.contextOptions);
|
|
1233
|
-
|
|
1234
1249
|
return internalActionGeneric({
|
|
1235
1250
|
args: vTextArgs,
|
|
1236
1251
|
handler: async (ctx, args) => {
|
|
1252
|
+
const { contextOptions, storageOptions, ...rest } = args;
|
|
1237
1253
|
const value = await this.generateText(
|
|
1238
1254
|
ctx,
|
|
1239
1255
|
{ userId: args.userId, threadId: args.threadId },
|
|
1240
|
-
{ maxSteps, ...
|
|
1256
|
+
{ maxSteps, ...rest },
|
|
1257
|
+
{
|
|
1258
|
+
contextOptions:
|
|
1259
|
+
contextOptions ??
|
|
1260
|
+
spec?.contextOptions ??
|
|
1261
|
+
this.options.contextOptions,
|
|
1262
|
+
storageOptions:
|
|
1263
|
+
storageOptions ??
|
|
1264
|
+
spec?.storageOptions ??
|
|
1265
|
+
this.options.storageOptions,
|
|
1266
|
+
}
|
|
1241
1267
|
);
|
|
1242
1268
|
return value.text;
|
|
1243
1269
|
},
|
|
@@ -1250,21 +1276,36 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
1250
1276
|
* the normal parameters to {@link generateObject}, plus {@link ContextOptions}
|
|
1251
1277
|
* and maxSteps.
|
|
1252
1278
|
*/
|
|
1253
|
-
asObjectAction<T>(
|
|
1279
|
+
asObjectAction<T>(
|
|
1280
|
+
spec: OurObjectArgs<T> & { maxSteps?: number },
|
|
1281
|
+
options?: {
|
|
1282
|
+
contextOptions?: ContextOptions;
|
|
1283
|
+
storageOptions?: StorageOptions;
|
|
1284
|
+
}
|
|
1285
|
+
) {
|
|
1254
1286
|
const maxSteps = spec?.maxSteps ?? this.options.maxSteps;
|
|
1255
1287
|
return internalActionGeneric({
|
|
1256
1288
|
args: vSafeObjectArgs,
|
|
1257
1289
|
handler: async (ctx, args) => {
|
|
1290
|
+
const { contextOptions, storageOptions, ...rest } = args;
|
|
1258
1291
|
const value = await this.generateObject(
|
|
1259
1292
|
ctx,
|
|
1260
1293
|
{ userId: args.userId, threadId: args.threadId },
|
|
1261
1294
|
{
|
|
1262
1295
|
...spec,
|
|
1263
1296
|
maxSteps,
|
|
1264
|
-
...
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1297
|
+
...rest,
|
|
1298
|
+
} as unknown as OurObjectArgs<unknown>,
|
|
1299
|
+
{
|
|
1300
|
+
contextOptions:
|
|
1301
|
+
contextOptions ??
|
|
1302
|
+
options?.contextOptions ??
|
|
1303
|
+
this.options.contextOptions,
|
|
1304
|
+
storageOptions:
|
|
1305
|
+
storageOptions ??
|
|
1306
|
+
options?.storageOptions ??
|
|
1307
|
+
this.options.storageOptions,
|
|
1308
|
+
}
|
|
1268
1309
|
);
|
|
1269
1310
|
return value.object as T;
|
|
1270
1311
|
},
|
|
@@ -1272,6 +1313,34 @@ export class Agent<AgentTools extends ToolSet> {
|
|
|
1272
1313
|
}
|
|
1273
1314
|
}
|
|
1274
1315
|
|
|
1316
|
+
export function filterOutOrphanedToolMessages(docs: MessageDoc[]) {
|
|
1317
|
+
const toolCallIds = new Set<string>();
|
|
1318
|
+
const result: MessageDoc[] = [];
|
|
1319
|
+
for (const doc of docs) {
|
|
1320
|
+
if (
|
|
1321
|
+
doc.message?.role === "assistant" &&
|
|
1322
|
+
Array.isArray(doc.message.content)
|
|
1323
|
+
) {
|
|
1324
|
+
for (const content of doc.message.content) {
|
|
1325
|
+
if (content.type === "tool-call") {
|
|
1326
|
+
toolCallIds.add(content.toolCallId);
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
result.push(doc);
|
|
1330
|
+
} else if (doc.message?.role === "tool") {
|
|
1331
|
+
if (doc.message.content.every((c) => toolCallIds.has(c.toolCallId))) {
|
|
1332
|
+
result.push(doc);
|
|
1333
|
+
} else {
|
|
1334
|
+
console.debug("Filtering out orphaned tool message", doc);
|
|
1335
|
+
}
|
|
1336
|
+
} else {
|
|
1337
|
+
result.push(doc);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
return result;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
|
|
1275
1344
|
export type ToolCtx = RunActionCtx & {
|
|
1276
1345
|
userId?: string;
|
|
1277
1346
|
threadId?: string;
|
|
@@ -1372,6 +1441,21 @@ function wrapTools(
|
|
|
1372
1441
|
return output;
|
|
1373
1442
|
}
|
|
1374
1443
|
|
|
1444
|
+
type Options = {
|
|
1445
|
+
/**
|
|
1446
|
+
* The parent message id to use for the tool calls.
|
|
1447
|
+
*/
|
|
1448
|
+
parentMessageId?: string;
|
|
1449
|
+
/**
|
|
1450
|
+
* The context options to use for passing in message history to the LLM.
|
|
1451
|
+
*/
|
|
1452
|
+
contextOptions?: ContextOptions;
|
|
1453
|
+
/**
|
|
1454
|
+
* The storage options to use for saving the input and output messages to the thread.
|
|
1455
|
+
*/
|
|
1456
|
+
storageOptions?: StorageOptions;
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1375
1459
|
type TextArgs<
|
|
1376
1460
|
AgentTools extends ToolSet,
|
|
1377
1461
|
TOOLS extends ToolSet | undefined = undefined,
|
|
@@ -1402,20 +1486,7 @@ type TextArgs<
|
|
|
1402
1486
|
* specified in the tools array. e.g. {toolName: "getWeather", type: "tool"}
|
|
1403
1487
|
*/
|
|
1404
1488
|
toolChoice?: ToolChoice<TOOLS extends undefined ? AgentTools : TOOLS>;
|
|
1405
|
-
|
|
1406
|
-
/**
|
|
1407
|
-
* The parent message id to use for the tool calls.
|
|
1408
|
-
*/
|
|
1409
|
-
parentMessageId?: string;
|
|
1410
|
-
/**
|
|
1411
|
-
* The context options to use for passing in message history to the LLM.
|
|
1412
|
-
*/
|
|
1413
|
-
contextOptions?: ContextOptions;
|
|
1414
|
-
/**
|
|
1415
|
-
* The storage options to use for saving the input and output messages to the thread.
|
|
1416
|
-
*/
|
|
1417
|
-
storageOptions?: StorageOptions;
|
|
1418
|
-
} & ContextOptions &
|
|
1489
|
+
} & ContextOptions & // DEPRECATED: pass them in the subsequent parameter instead
|
|
1419
1490
|
StorageOptions;
|
|
1420
1491
|
|
|
1421
1492
|
type StreamingTextArgs<
|
|
@@ -1448,19 +1519,6 @@ type StreamingTextArgs<
|
|
|
1448
1519
|
* specified in the tools array. e.g. {toolName: "getWeather", type: "tool"}
|
|
1449
1520
|
*/
|
|
1450
1521
|
toolChoice?: ToolChoice<TOOLS extends undefined ? AgentTools : TOOLS>;
|
|
1451
|
-
// Non-AI SDK args
|
|
1452
|
-
/**
|
|
1453
|
-
* The parent message id to use for the tool calls.
|
|
1454
|
-
*/
|
|
1455
|
-
parentMessageId?: string;
|
|
1456
|
-
/**
|
|
1457
|
-
* The context options to use for passing in message history to the LLM.
|
|
1458
|
-
*/
|
|
1459
|
-
contextOptions?: ContextOptions;
|
|
1460
|
-
/**
|
|
1461
|
-
* The storage options to use for saving the input and output messages to the thread.
|
|
1462
|
-
*/
|
|
1463
|
-
storageOptions?: StorageOptions;
|
|
1464
1522
|
} & ContextOptions &
|
|
1465
1523
|
StorageOptions;
|
|
1466
1524
|
|
|
@@ -1492,19 +1550,6 @@ type BaseGenerateObjectOptions = StorageOptions &
|
|
|
1492
1550
|
experimental_telemetry?: TelemetrySettings;
|
|
1493
1551
|
providerOptions?: ProviderOptions;
|
|
1494
1552
|
experimental_providerMetadata?: ProviderMetadata;
|
|
1495
|
-
// Non-AI SDK args
|
|
1496
|
-
/**
|
|
1497
|
-
* The parent message id to use for the object generation.
|
|
1498
|
-
*/
|
|
1499
|
-
parentMessageId?: string;
|
|
1500
|
-
/**
|
|
1501
|
-
* The context options to use for passing in message history to the LLM.
|
|
1502
|
-
*/
|
|
1503
|
-
contextOptions?: ContextOptions;
|
|
1504
|
-
/**
|
|
1505
|
-
* The storage options to use for saving the input and output messages to the thread.
|
|
1506
|
-
*/
|
|
1507
|
-
storageOptions?: StorageOptions;
|
|
1508
1553
|
};
|
|
1509
1554
|
|
|
1510
1555
|
type GenerateObjectObjectOptions<T extends Record<string, unknown>> =
|
|
@@ -1536,6 +1581,8 @@ type GenerateObjectNoSchemaOptions = BaseGenerateObjectOptions & {
|
|
|
1536
1581
|
mode?: "json";
|
|
1537
1582
|
};
|
|
1538
1583
|
|
|
1584
|
+
// TODO: simplify this to just use the generateObject args, with an optional
|
|
1585
|
+
// model and tool/toolChoice types
|
|
1539
1586
|
type GenerateObjectArgs<T> =
|
|
1540
1587
|
T extends Record<string, unknown>
|
|
1541
1588
|
? GenerateObjectObjectOptions<T>
|
|
@@ -1569,6 +1616,10 @@ type ThreadOutputMetadata = GenerationOutputMetadata & {
|
|
|
1569
1616
|
messageId: string;
|
|
1570
1617
|
};
|
|
1571
1618
|
|
|
1619
|
+
/**
|
|
1620
|
+
* The interface for a thread returned from {@link createThread} or {@link continueThread}.
|
|
1621
|
+
* This is contextual to a thread and/or user.
|
|
1622
|
+
*/
|
|
1572
1623
|
interface Thread<DefaultTools extends ToolSet> {
|
|
1573
1624
|
/**
|
|
1574
1625
|
* The target threadId, from the startThread or continueThread initializers.
|
|
@@ -1594,7 +1645,8 @@ interface Thread<DefaultTools extends ToolSet> {
|
|
|
1594
1645
|
TOOLS,
|
|
1595
1646
|
OUTPUT,
|
|
1596
1647
|
OUTPUT_PARTIAL
|
|
1597
|
-
|
|
1648
|
+
>,
|
|
1649
|
+
options?: Options
|
|
1598
1650
|
): Promise<
|
|
1599
1651
|
GenerateTextResult<TOOLS extends undefined ? DefaultTools : TOOLS, OUTPUT> &
|
|
1600
1652
|
ThreadOutputMetadata
|
|
@@ -1620,7 +1672,8 @@ interface Thread<DefaultTools extends ToolSet> {
|
|
|
1620
1672
|
TOOLS,
|
|
1621
1673
|
OUTPUT,
|
|
1622
1674
|
PARTIAL_OUTPUT
|
|
1623
|
-
|
|
1675
|
+
>,
|
|
1676
|
+
options?: Options
|
|
1624
1677
|
): Promise<
|
|
1625
1678
|
StreamTextResult<
|
|
1626
1679
|
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
@@ -1639,7 +1692,8 @@ interface Thread<DefaultTools extends ToolSet> {
|
|
|
1639
1692
|
* @returns The result of the generateObject function.
|
|
1640
1693
|
*/
|
|
1641
1694
|
generateObject<T>(
|
|
1642
|
-
args: OurObjectArgs<T
|
|
1695
|
+
args: OurObjectArgs<T>,
|
|
1696
|
+
options?: Options
|
|
1643
1697
|
): Promise<GenerateObjectResult<T> & ThreadOutputMetadata>;
|
|
1644
1698
|
/**
|
|
1645
1699
|
* This behaves like {@link generateObject} from the "ai" package except that
|
|
@@ -1652,7 +1706,8 @@ interface Thread<DefaultTools extends ToolSet> {
|
|
|
1652
1706
|
* @returns The result of the generateObject function.
|
|
1653
1707
|
*/
|
|
1654
1708
|
generateObject(
|
|
1655
|
-
args: GenerateObjectNoSchemaOptions
|
|
1709
|
+
args: GenerateObjectNoSchemaOptions,
|
|
1710
|
+
options?: Options
|
|
1656
1711
|
): Promise<GenerateObjectResult<JSONValue> & ThreadOutputMetadata>;
|
|
1657
1712
|
/**
|
|
1658
1713
|
* This behaves like {@link streamObject} from the "ai" package except that
|
|
@@ -1665,7 +1720,8 @@ interface Thread<DefaultTools extends ToolSet> {
|
|
|
1665
1720
|
* @returns The result of the streamObject function.
|
|
1666
1721
|
*/
|
|
1667
1722
|
streamObject<T>(
|
|
1668
|
-
args: OurStreamObjectArgs<T
|
|
1723
|
+
args: OurStreamObjectArgs<T>,
|
|
1724
|
+
options?: Options
|
|
1669
1725
|
): Promise<
|
|
1670
1726
|
StreamObjectResult<DeepPartial<T>, T, never> & ThreadOutputMetadata
|
|
1671
1727
|
>;
|
|
@@ -80,14 +80,7 @@ export const updateThread = mutation({
|
|
|
80
80
|
args: {
|
|
81
81
|
threadId: v.id("threads"),
|
|
82
82
|
patch: v.object(
|
|
83
|
-
partial(
|
|
84
|
-
pick(vThread.fields, [
|
|
85
|
-
"title",
|
|
86
|
-
"summary",
|
|
87
|
-
"defaultSystemPrompt",
|
|
88
|
-
"status",
|
|
89
|
-
])
|
|
90
|
-
)
|
|
83
|
+
partial(pick(vThread.fields, ["title", "summary", "status"]))
|
|
91
84
|
),
|
|
92
85
|
},
|
|
93
86
|
handler: async (ctx, args) => {
|
package/src/component/schema.ts
CHANGED
|
@@ -16,12 +16,11 @@ import vectorTables, { vVectorId } from "./vector/tables.js";
|
|
|
16
16
|
export const schema = defineSchema({
|
|
17
17
|
threads: defineTable({
|
|
18
18
|
userId: v.optional(v.string()), // Unset for anonymous
|
|
19
|
-
// TODO: is this bubbling up in continue?
|
|
20
|
-
defaultSystemPrompt: v.optional(v.string()),
|
|
21
19
|
title: v.optional(v.string()),
|
|
22
20
|
summary: v.optional(v.string()),
|
|
23
21
|
status: vThreadStatus,
|
|
24
22
|
// DEPRECATED
|
|
23
|
+
defaultSystemPrompt: v.optional(v.string()),
|
|
25
24
|
parentThreadIds: v.optional(v.array(v.id("threads"))),
|
|
26
25
|
order: /*DEPRECATED*/ v.optional(v.number()),
|
|
27
26
|
}).index("userId", ["userId"]),
|