@convex-dev/agent 0.6.0-alpha.0 → 0.6.0-beta.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.
Files changed (75) hide show
  1. package/MIGRATION.md +153 -0
  2. package/dist/UIMessages.d.ts.map +1 -1
  3. package/dist/UIMessages.js +88 -0
  4. package/dist/UIMessages.js.map +1 -1
  5. package/dist/client/createTool.d.ts +18 -21
  6. package/dist/client/createTool.d.ts.map +1 -1
  7. package/dist/client/createTool.js +3 -2
  8. package/dist/client/createTool.js.map +1 -1
  9. package/dist/client/definePlaygroundAPI.d.ts +31 -31
  10. package/dist/client/index.d.ts +70 -23
  11. package/dist/client/index.d.ts.map +1 -1
  12. package/dist/client/index.js +126 -1
  13. package/dist/client/index.js.map +1 -1
  14. package/dist/client/messages.d.ts +9 -9
  15. package/dist/client/mockModel.d.ts.map +1 -1
  16. package/dist/client/mockModel.js +9 -2
  17. package/dist/client/mockModel.js.map +1 -1
  18. package/dist/client/search.d.ts +9 -9
  19. package/dist/client/search.d.ts.map +1 -1
  20. package/dist/client/search.js +12 -2
  21. package/dist/client/search.js.map +1 -1
  22. package/dist/client/start.d.ts +1 -1
  23. package/dist/client/start.d.ts.map +1 -1
  24. package/dist/client/start.js +29 -15
  25. package/dist/client/start.js.map +1 -1
  26. package/dist/client/streamText.d.ts.map +1 -1
  27. package/dist/client/streamText.js +37 -3
  28. package/dist/client/streamText.js.map +1 -1
  29. package/dist/client/streaming.d.ts +78 -67
  30. package/dist/client/streaming.d.ts.map +1 -1
  31. package/dist/client/streaming.js +64 -28
  32. package/dist/client/streaming.js.map +1 -1
  33. package/dist/client/types.d.ts +13 -12
  34. package/dist/client/types.d.ts.map +1 -1
  35. package/dist/component/_generated/component.d.ts +1 -0
  36. package/dist/component/_generated/component.d.ts.map +1 -1
  37. package/dist/component/messages.d.ts +107 -106
  38. package/dist/component/messages.d.ts.map +1 -1
  39. package/dist/component/messages.js +13 -3
  40. package/dist/component/messages.js.map +1 -1
  41. package/dist/component/schema.d.ts +40 -40
  42. package/dist/component/streams.d.ts +4 -4
  43. package/dist/component/threads.d.ts +17 -17
  44. package/dist/component/users.d.ts +3 -3
  45. package/dist/component/vector/index.d.ts +1 -1
  46. package/dist/deltas.d.ts.map +1 -1
  47. package/dist/deltas.js +0 -1
  48. package/dist/deltas.js.map +1 -1
  49. package/dist/mapping.d.ts +22 -0
  50. package/dist/mapping.d.ts.map +1 -1
  51. package/dist/mapping.js +99 -5
  52. package/dist/mapping.js.map +1 -1
  53. package/dist/react/useDeltaStreams.d.ts.map +1 -1
  54. package/dist/react/useDeltaStreams.js +5 -0
  55. package/dist/react/useDeltaStreams.js.map +1 -1
  56. package/dist/validators.d.ts +13 -13
  57. package/package.json +4 -2
  58. package/src/UIMessages.ts +126 -0
  59. package/src/client/approval.test.ts +494 -0
  60. package/src/client/createTool.ts +50 -52
  61. package/src/client/index.ts +170 -1
  62. package/src/client/mockModel.ts +9 -2
  63. package/src/client/search.test.ts +4 -5
  64. package/src/client/search.ts +18 -2
  65. package/src/client/start.ts +42 -25
  66. package/src/client/streamText.ts +36 -3
  67. package/src/client/streaming.integration.test.ts +1206 -0
  68. package/src/client/streaming.ts +67 -31
  69. package/src/client/types.ts +14 -12
  70. package/src/component/_generated/component.ts +53 -64
  71. package/src/component/messages.ts +12 -2
  72. package/src/deltas.ts +0 -1
  73. package/src/mapping.test.ts +143 -1
  74. package/src/mapping.ts +131 -6
  75. package/src/react/useDeltaStreams.ts +6 -0
@@ -9493,7 +9493,7 @@ export declare const vRequest: import("convex/values").VObject<{
9493
9493
  method: import("convex/values").VString<string | undefined, "optional">;
9494
9494
  url: import("convex/values").VString<string | undefined, "optional">;
9495
9495
  }, "required", "url" | "body" | "headers" | "method" | `body.${string}` | `headers.${string}`>;
9496
- export declare const vFinishReason: import("convex/values").VUnion<"error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown", [import("convex/values").VLiteral<"stop", "required">, import("convex/values").VLiteral<"length", "required">, import("convex/values").VLiteral<"content-filter", "required">, import("convex/values").VLiteral<"tool-calls", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"other", "required">, import("convex/values").VLiteral<"unknown", "required">], "required", never>;
9496
+ export declare const vFinishReason: import("convex/values").VUnion<"length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown", [import("convex/values").VLiteral<"stop", "required">, import("convex/values").VLiteral<"length", "required">, import("convex/values").VLiteral<"content-filter", "required">, import("convex/values").VLiteral<"tool-calls", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"other", "required">, import("convex/values").VLiteral<"unknown", "required">], "required", never>;
9497
9497
  export declare const vUsage: import("convex/values").VObject<{
9498
9498
  reasoningTokens?: number | undefined;
9499
9499
  cachedInputTokens?: number | undefined;
@@ -9588,7 +9588,7 @@ export declare const vMessageWithMetadataInternal: import("convex/values").VObje
9588
9588
  type: "other";
9589
9589
  message: string;
9590
9590
  })[] | undefined;
9591
- finishReason?: "error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
9591
+ finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
9592
9592
  reasoningDetails?: ({
9593
9593
  providerOptions?: Record<string, Record<string, any>> | undefined;
9594
9594
  providerMetadata?: Record<string, Record<string, any>> | undefined;
@@ -12242,7 +12242,7 @@ export declare const vMessageWithMetadataInternal: import("convex/values").VObje
12242
12242
  text: import("convex/values").VString<string | undefined, "optional">;
12243
12243
  fileIds: import("convex/values").VArray<import("convex/values").GenericId<"files">[] | undefined, import("convex/values").VId<import("convex/values").GenericId<"files">, "required">, "optional">;
12244
12244
  status: import("convex/values").VUnion<"pending" | "success" | "failed" | undefined, [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"success", "required">, import("convex/values").VLiteral<"failed", "required">], "optional", never>;
12245
- finishReason: import("convex/values").VUnion<"error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined, [import("convex/values").VLiteral<"stop", "required">, import("convex/values").VLiteral<"length", "required">, import("convex/values").VLiteral<"content-filter", "required">, import("convex/values").VLiteral<"tool-calls", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"other", "required">, import("convex/values").VLiteral<"unknown", "required">], "optional", never>;
12245
+ finishReason: import("convex/values").VUnion<"length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined, [import("convex/values").VLiteral<"stop", "required">, import("convex/values").VLiteral<"length", "required">, import("convex/values").VLiteral<"content-filter", "required">, import("convex/values").VLiteral<"tool-calls", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"other", "required">, import("convex/values").VLiteral<"unknown", "required">], "optional", never>;
12246
12246
  model: import("convex/values").VString<string | undefined, "optional">;
12247
12247
  provider: import("convex/values").VString<string | undefined, "optional">;
12248
12248
  providerMetadata: import("convex/values").VRecord<Record<string, Record<string, any>> | undefined, import("convex/values").VString<string, "required">, import("convex/values").VRecord<Record<string, any>, import("convex/values").VString<string, "required">, import("convex/values").VAny<any, "required", string>, "required", string>, "optional", string>;
@@ -12476,7 +12476,7 @@ export declare const vMessageWithMetadata: import("convex/values").VObject<{
12476
12476
  type: "other";
12477
12477
  message: string;
12478
12478
  })[] | undefined;
12479
- finishReason?: "error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
12479
+ finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
12480
12480
  reasoningDetails?: ({
12481
12481
  providerOptions?: Record<string, Record<string, any>> | undefined;
12482
12482
  providerMetadata?: Record<string, Record<string, any>> | undefined;
@@ -15130,7 +15130,7 @@ export declare const vMessageWithMetadata: import("convex/values").VObject<{
15130
15130
  }, "required", "providerOptions" | "role" | `providerOptions.${string}` | "content">], "required", "providerOptions" | "role" | `providerOptions.${string}` | "content">;
15131
15131
  text: import("convex/values").VString<string | undefined, "optional">;
15132
15132
  status: import("convex/values").VUnion<"pending" | "success" | "failed" | undefined, [import("convex/values").VLiteral<"pending", "required">, import("convex/values").VLiteral<"success", "required">, import("convex/values").VLiteral<"failed", "required">], "optional", never>;
15133
- finishReason: import("convex/values").VUnion<"error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined, [import("convex/values").VLiteral<"stop", "required">, import("convex/values").VLiteral<"length", "required">, import("convex/values").VLiteral<"content-filter", "required">, import("convex/values").VLiteral<"tool-calls", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"other", "required">, import("convex/values").VLiteral<"unknown", "required">], "optional", never>;
15133
+ finishReason: import("convex/values").VUnion<"length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined, [import("convex/values").VLiteral<"stop", "required">, import("convex/values").VLiteral<"length", "required">, import("convex/values").VLiteral<"content-filter", "required">, import("convex/values").VLiteral<"tool-calls", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"other", "required">, import("convex/values").VLiteral<"unknown", "required">], "optional", never>;
15134
15134
  model: import("convex/values").VString<string | undefined, "optional">;
15135
15135
  provider: import("convex/values").VString<string | undefined, "optional">;
15136
15136
  providerMetadata: import("convex/values").VRecord<Record<string, Record<string, any>> | undefined, import("convex/values").VString<string, "required">, import("convex/values").VRecord<Record<string, any>, import("convex/values").VString<string, "required">, import("convex/values").VAny<any, "required", string>, "required", string>, "optional", string>;
@@ -21905,7 +21905,7 @@ export declare const vMessageDoc: import("convex/values").VObject<{
21905
21905
  type: "other";
21906
21906
  message: string;
21907
21907
  })[] | undefined;
21908
- finishReason?: "error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
21908
+ finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
21909
21909
  reasoningDetails?: ({
21910
21910
  providerOptions?: Record<string, Record<string, any>> | undefined;
21911
21911
  providerMetadata?: Record<string, Record<string, any>> | undefined;
@@ -21920,13 +21920,13 @@ export declare const vMessageDoc: import("convex/values").VObject<{
21920
21920
  type: "redacted";
21921
21921
  data: string;
21922
21922
  })[] | undefined;
21923
+ _id: string;
21924
+ _creationTime: number;
21923
21925
  status: "pending" | "success" | "failed";
21924
21926
  order: number;
21925
- _creationTime: number;
21926
21927
  threadId: string;
21927
21928
  stepOrder: number;
21928
21929
  tool: boolean;
21929
- _id: string;
21930
21930
  }, {
21931
21931
  _id: import("convex/values").VString<string, "required">;
21932
21932
  _creationTime: import("convex/values").VFloat64<number, "required">;
@@ -24438,7 +24438,7 @@ export declare const vMessageDoc: import("convex/values").VObject<{
24438
24438
  type: import("convex/values").VLiteral<"other", "required">;
24439
24439
  message: import("convex/values").VString<string, "required">;
24440
24440
  }, "required", "type" | "message">], "required", "type" | "message" | "tool" | "setting" | "details" | `tool.${string}`>, "optional">;
24441
- finishReason: import("convex/values").VUnion<"error" | "length" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined, [import("convex/values").VLiteral<"stop", "required">, import("convex/values").VLiteral<"length", "required">, import("convex/values").VLiteral<"content-filter", "required">, import("convex/values").VLiteral<"tool-calls", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"other", "required">, import("convex/values").VLiteral<"unknown", "required">], "optional", never>;
24441
+ finishReason: import("convex/values").VUnion<"length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined, [import("convex/values").VLiteral<"stop", "required">, import("convex/values").VLiteral<"length", "required">, import("convex/values").VLiteral<"content-filter", "required">, import("convex/values").VLiteral<"tool-calls", "required">, import("convex/values").VLiteral<"error", "required">, import("convex/values").VLiteral<"other", "required">, import("convex/values").VLiteral<"unknown", "required">], "optional", never>;
24442
24442
  reasoning: import("convex/values").VString<string | undefined, "optional">;
24443
24443
  reasoningDetails: import("convex/values").VArray<({
24444
24444
  providerOptions?: Record<string, Record<string, any>> | undefined;
@@ -24494,15 +24494,15 @@ export declare const vMessageDoc: import("convex/values").VObject<{
24494
24494
  data: import("convex/values").VString<string, "required">;
24495
24495
  }, "required", "type" | "data">], "required", "type" | "providerOptions" | "text" | "providerMetadata" | `providerOptions.${string}` | `providerMetadata.${string}` | "data" | "signature">, "optional">;
24496
24496
  id: import("convex/values").VString<string | undefined, "optional">;
24497
- }, "required", "id" | "status" | "userId" | "order" | "_creationTime" | "threadId" | "stepOrder" | "embeddingId" | "fileIds" | "error" | "agentName" | "model" | "provider" | "providerOptions" | "message" | "text" | "providerMetadata" | `providerOptions.${string}` | `providerMetadata.${string}` | "reasoning" | "tool" | "usage" | "sources" | "warnings" | "finishReason" | "reasoningDetails" | "message.providerOptions" | "message.role" | `message.providerOptions.${string}` | "message.content" | "usage.promptTokens" | "usage.completionTokens" | "usage.totalTokens" | "usage.reasoningTokens" | "usage.cachedInputTokens" | "_id">;
24497
+ }, "required", "_id" | "_creationTime" | "id" | "status" | "userId" | "order" | "threadId" | "stepOrder" | "embeddingId" | "fileIds" | "error" | "agentName" | "model" | "provider" | "providerOptions" | "message" | "text" | "providerMetadata" | `providerOptions.${string}` | `providerMetadata.${string}` | "reasoning" | "tool" | "usage" | "sources" | "warnings" | "finishReason" | "reasoningDetails" | "message.providerOptions" | "message.role" | `message.providerOptions.${string}` | "message.content" | "usage.promptTokens" | "usage.completionTokens" | "usage.totalTokens" | "usage.reasoningTokens" | "usage.cachedInputTokens">;
24498
24498
  export type MessageDoc = Infer<typeof vMessageDoc>;
24499
24499
  export declare const vThreadDoc: import("convex/values").VObject<{
24500
24500
  userId?: string | undefined;
24501
24501
  title?: string | undefined;
24502
24502
  summary?: string | undefined;
24503
- status: "active" | "archived";
24504
- _creationTime: number;
24505
24503
  _id: string;
24504
+ _creationTime: number;
24505
+ status: "active" | "archived";
24506
24506
  }, {
24507
24507
  _id: import("convex/values").VString<string, "required">;
24508
24508
  _creationTime: import("convex/values").VFloat64<number, "required">;
@@ -24510,7 +24510,7 @@ export declare const vThreadDoc: import("convex/values").VObject<{
24510
24510
  title: import("convex/values").VString<string | undefined, "optional">;
24511
24511
  summary: import("convex/values").VString<string | undefined, "optional">;
24512
24512
  status: import("convex/values").VUnion<"active" | "archived", [import("convex/values").VLiteral<"active", "required">, import("convex/values").VLiteral<"archived", "required">], "required", never>;
24513
- }, "required", "status" | "userId" | "title" | "summary" | "_creationTime" | "_id">;
24513
+ }, "required", "_id" | "_creationTime" | "status" | "userId" | "title" | "summary">;
24514
24514
  export type ThreadDoc = Infer<typeof vThreadDoc>;
24515
24515
  export {};
24516
24516
  //# sourceMappingURL=validators.d.ts.map
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "email": "support@convex.dev",
8
8
  "url": "https://github.com/get-convex/agent/issues"
9
9
  },
10
- "version": "0.6.0-alpha.0",
10
+ "version": "0.6.0-beta.0",
11
11
  "license": "Apache-2.0",
12
12
  "keywords": [
13
13
  "convex",
@@ -41,7 +41,8 @@
41
41
  },
42
42
  "files": [
43
43
  "dist",
44
- "src"
44
+ "src",
45
+ "MIGRATION.md"
45
46
  ],
46
47
  "exports": {
47
48
  "./package.json": "./package.json",
@@ -84,6 +85,7 @@
84
85
  },
85
86
  "devDependencies": {
86
87
  "@ai-sdk/anthropic": "^3.0.13",
88
+ "@ai-sdk/google": "^3.0.30",
87
89
  "@ai-sdk/groq": "^3.0.8",
88
90
  "@ai-sdk/openai": "^3.0.10",
89
91
  "@ai-sdk/provider": "^3.0.3",
package/src/UIMessages.ts CHANGED
@@ -396,6 +396,51 @@ function createAssistantUIMessage<
396
396
  ? ("streaming" as const)
397
397
  : lastMessage.status;
398
398
 
399
+ // Extract approval parts from raw message content for UI rendering
400
+ type ApprovalPart =
401
+ | { type: "tool-approval-request"; approvalId: string; toolCallId: string }
402
+ | {
403
+ type: "tool-approval-response";
404
+ approvalId: string;
405
+ approved: boolean;
406
+ reason?: string;
407
+ };
408
+ const approvalParts: ApprovalPart[] = [];
409
+
410
+ // Extract execution-denied tool results from raw content for UI rendering
411
+ // (these are converted to text format for provider compatibility in start.ts)
412
+ type ExecutionDeniedInfo = {
413
+ toolCallId: string;
414
+ reason?: string;
415
+ };
416
+ const executionDeniedResults: ExecutionDeniedInfo[] = [];
417
+
418
+ for (const message of group) {
419
+ const rawContent = message.message?.content;
420
+ if (Array.isArray(rawContent)) {
421
+ for (const part of rawContent) {
422
+ if (
423
+ part.type === "tool-approval-request" ||
424
+ part.type === "tool-approval-response"
425
+ ) {
426
+ approvalParts.push(part as ApprovalPart);
427
+ }
428
+ // Check for execution-denied in tool-result outputs
429
+ if (
430
+ part.type === "tool-result" &&
431
+ typeof part.output === "object" &&
432
+ part.output !== null &&
433
+ (part.output as { type?: string }).type === "execution-denied"
434
+ ) {
435
+ executionDeniedResults.push({
436
+ toolCallId: part.toolCallId as string,
437
+ reason: (part.output as { reason?: string }).reason,
438
+ });
439
+ }
440
+ }
441
+ }
442
+ }
443
+
399
444
  // Collect all parts from all messages
400
445
  const allParts: UIMessage<METADATA, DATA_PARTS, TOOLS>["parts"] = [];
401
446
 
@@ -477,6 +522,9 @@ function createAssistantUIMessage<
477
522
  break;
478
523
  }
479
524
  case "tool-result": {
525
+ // Note: execution-denied outputs are handled separately via pre-extraction
526
+ // from raw content (converted to text format for providers in start.ts).
527
+ // See executionDeniedResults processing at the end of this function.
480
528
  const typedPart = contentPart as unknown as ToolResultPart & {
481
529
  output: { type: string; value?: unknown; reason?: string };
482
530
  };
@@ -642,6 +690,84 @@ function createAssistantUIMessage<
642
690
  }
643
691
  }
644
692
 
693
+ // Final output states that should not be overwritten by approval processing
694
+ const finalStates = new Set([
695
+ "output-available",
696
+ "output-error",
697
+ "output-denied",
698
+ ]);
699
+
700
+ // Process approval parts to update tool call states
701
+ for (const approvalPart of approvalParts) {
702
+ if (approvalPart.type === "tool-approval-request") {
703
+ const toolCallPart = allParts.find(
704
+ (part) =>
705
+ "toolCallId" in part && part.toolCallId === approvalPart.toolCallId,
706
+ ) as ToolUIPart | undefined;
707
+
708
+ if (toolCallPart) {
709
+ // Always set approval info (needed for response matching), but only
710
+ // update state if not in a final state
711
+ (toolCallPart as ToolUIPart & { approval?: object }).approval = {
712
+ id: approvalPart.approvalId,
713
+ };
714
+ if (!finalStates.has(toolCallPart.state)) {
715
+ toolCallPart.state = "approval-requested";
716
+ }
717
+ }
718
+ } else if (approvalPart.type === "tool-approval-response") {
719
+ const toolCallPart = allParts.find(
720
+ (part) =>
721
+ "approval" in part &&
722
+ (part as ToolUIPart & { approval?: { id: string } }).approval?.id ===
723
+ approvalPart.approvalId,
724
+ ) as ToolUIPart | undefined;
725
+
726
+ if (toolCallPart) {
727
+ // Always update approval info, but only update state if not in a final state
728
+ (toolCallPart as ToolUIPart & { approval?: object }).approval = {
729
+ id: approvalPart.approvalId,
730
+ approved: approvalPart.approved,
731
+ reason: approvalPart.reason,
732
+ };
733
+ if (!finalStates.has(toolCallPart.state)) {
734
+ if (approvalPart.approved) {
735
+ toolCallPart.state = "approval-responded";
736
+ } else {
737
+ toolCallPart.state = "output-denied";
738
+ }
739
+ }
740
+ }
741
+ }
742
+ }
743
+
744
+ // Process execution-denied results to update tool call states
745
+ for (const denied of executionDeniedResults) {
746
+ const toolCallPart = allParts.find(
747
+ (part) =>
748
+ "toolCallId" in part && part.toolCallId === denied.toolCallId,
749
+ ) as ToolUIPart | undefined;
750
+
751
+ if (toolCallPart) {
752
+ toolCallPart.state = "output-denied";
753
+ if (!("approval" in toolCallPart) || !toolCallPart.approval) {
754
+ (toolCallPart as ToolUIPart & { approval?: object }).approval = {
755
+ id: "",
756
+ approved: false,
757
+ reason: denied.reason,
758
+ };
759
+ } else {
760
+ const approval = (
761
+ toolCallPart as ToolUIPart & {
762
+ approval: { approved?: boolean; reason?: string };
763
+ }
764
+ ).approval;
765
+ approval.approved = false;
766
+ approval.reason = denied.reason;
767
+ }
768
+ }
769
+ }
770
+
645
771
  return {
646
772
  ...common,
647
773
  role: "assistant",