@convex-dev/agent 0.1.16-alpha.1 → 0.1.16-alpha.3

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 (59) hide show
  1. package/README.md +26 -15
  2. package/dist/client/createTool.d.ts +2 -2
  3. package/dist/client/createTool.d.ts.map +1 -1
  4. package/dist/client/createTool.js.map +1 -1
  5. package/dist/client/files.js +2 -2
  6. package/dist/client/files.js.map +1 -1
  7. package/dist/client/index.d.ts +12 -11
  8. package/dist/client/index.d.ts.map +1 -1
  9. package/dist/client/index.js +58 -36
  10. package/dist/client/index.js.map +1 -1
  11. package/dist/client/search.d.ts +2 -3
  12. package/dist/client/search.d.ts.map +1 -1
  13. package/dist/client/search.js +2 -1
  14. package/dist/client/search.js.map +1 -1
  15. package/dist/client/types.d.ts +7 -9
  16. package/dist/client/types.d.ts.map +1 -1
  17. package/dist/component/messages.d.ts +1 -1
  18. package/dist/component/messages.d.ts.map +1 -1
  19. package/dist/component/messages.js +5 -5
  20. package/dist/component/messages.js.map +1 -1
  21. package/dist/component/schema.d.ts.map +1 -1
  22. package/dist/component/schema.js.map +1 -1
  23. package/dist/mapping.d.ts.map +1 -1
  24. package/dist/mapping.js +3 -1
  25. package/dist/mapping.js.map +1 -1
  26. package/dist/validators.js +1 -2
  27. package/dist/validators.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/client/createTool.ts +9 -6
  30. package/src/client/files.ts +8 -8
  31. package/src/client/index.test.ts +14 -12
  32. package/src/client/index.ts +156 -116
  33. package/src/client/listMessages.ts +1 -1
  34. package/src/client/search.ts +14 -14
  35. package/src/client/streaming.ts +7 -7
  36. package/src/client/types.ts +29 -23
  37. package/src/component/apiKeys.ts +1 -1
  38. package/src/component/files.test.ts +1 -1
  39. package/src/component/files.ts +6 -6
  40. package/src/component/messages.test.ts +6 -6
  41. package/src/component/messages.ts +44 -43
  42. package/src/component/schema.ts +1 -2
  43. package/src/component/streams.ts +27 -27
  44. package/src/component/threads.test.ts +4 -4
  45. package/src/component/threads.ts +4 -4
  46. package/src/component/users.test.ts +2 -2
  47. package/src/component/users.ts +4 -4
  48. package/src/component/vector/index.ts +11 -11
  49. package/src/component/vector/tables.ts +6 -6
  50. package/src/mapping.test.ts +4 -4
  51. package/src/mapping.ts +18 -17
  52. package/src/react/deltas.test.ts +16 -16
  53. package/src/react/deltas.ts +13 -13
  54. package/src/react/index.ts +11 -11
  55. package/src/react/optimisticallySendMessage.ts +2 -2
  56. package/src/react/toUIMessages.test.ts +10 -10
  57. package/src/react/toUIMessages.ts +6 -6
  58. package/src/react/useSmoothText.ts +6 -6
  59. package/src/validators.ts +24 -24
@@ -117,15 +117,15 @@ describe("toUIMessages", () => {
117
117
  expect(uiMessages).toHaveLength(2);
118
118
  expect(uiMessages[0].role).toBe("user");
119
119
  expect(uiMessages[0].parts.filter((p) => p.type === "text")).toHaveLength(
120
- 1
120
+ 1,
121
121
  );
122
122
  expect(uiMessages[1].role).toBe("assistant");
123
123
  expect(
124
- uiMessages[1].parts.filter((p) => p.type === "tool-invocation")
124
+ uiMessages[1].parts.filter((p) => p.type === "tool-invocation"),
125
125
  ).toHaveLength(1);
126
126
  expect(
127
127
  uiMessages[1].parts.filter((p) => p.type === "tool-invocation")[0]
128
- .toolInvocation
128
+ .toolInvocation,
129
129
  ).toEqual({
130
130
  toolName: "myTool",
131
131
  toolCallId: "call1",
@@ -169,19 +169,19 @@ describe("toUIMessages", () => {
169
169
  expect(uiMessages[0].role).toBe("assistant");
170
170
  expect(uiMessages[0].content).toBe("Here's one idea. Here's another idea.");
171
171
  expect(
172
- uiMessages[0].parts.filter((p) => p.type === "reasoning")
172
+ uiMessages[0].parts.filter((p) => p.type === "reasoning"),
173
173
  ).toHaveLength(1);
174
174
  expect(uiMessages[0].parts[0].type).toBe("reasoning");
175
175
  assert(uiMessages[0].parts[0].type === "reasoning");
176
176
  expect(uiMessages[0].parts[0].reasoning).toBe(
177
- "I'm thinking...I'm thinking..."
177
+ "I'm thinking...I'm thinking...",
178
178
  );
179
179
 
180
180
  expect(uiMessages[0].parts.filter((p) => p.type === "text")).toHaveLength(
181
- 1
181
+ 1,
182
182
  );
183
183
  expect(uiMessages[0].parts.filter((p) => p.type === "text")[0].text).toBe(
184
- "Here's one idea. Here's another idea."
184
+ "Here's one idea. Here's another idea.",
185
185
  );
186
186
  });
187
187
 
@@ -226,11 +226,11 @@ describe("toUIMessages", () => {
226
226
  expect(uiMessages).toHaveLength(1);
227
227
  expect(uiMessages[0].role).toBe("assistant");
228
228
  expect(
229
- uiMessages[0].parts.filter((p) => p.type === "tool-invocation")
229
+ uiMessages[0].parts.filter((p) => p.type === "tool-invocation"),
230
230
  ).toHaveLength(1);
231
231
  expect(
232
232
  uiMessages[0].parts.filter((p) => p.type === "tool-invocation")[0]
233
- .toolInvocation
233
+ .toolInvocation,
234
234
  ).toEqual({
235
235
  toolName: "myTool",
236
236
  toolCallId: "call1",
@@ -277,7 +277,7 @@ describe("toUIMessages", () => {
277
277
  expect(uiMessages[0].role).toBe("assistant");
278
278
  // Should have a tool-invocation part
279
279
  expect(uiMessages[0].parts.some((p) => p.type === "tool-invocation")).toBe(
280
- true
280
+ true,
281
281
  );
282
282
  });
283
283
 
@@ -13,7 +13,7 @@ export type UIMessage = AIUIMessage & {
13
13
  };
14
14
 
15
15
  export function toUIMessages(
16
- messages: (MessageDoc & { streaming?: boolean })[]
16
+ messages: (MessageDoc & { streaming?: boolean })[],
17
17
  ): UIMessage[] {
18
18
  const uiMessages: UIMessage[] = [];
19
19
  let assistantMessage: UIMessage | undefined;
@@ -63,7 +63,7 @@ export function toUIMessages(
63
63
  if (coreMessage.role === "tool" && !assistantMessage) {
64
64
  console.warn(
65
65
  "Tool message without preceding assistant message.. skipping",
66
- message
66
+ message,
67
67
  );
68
68
  continue;
69
69
  }
@@ -118,7 +118,7 @@ export function toUIMessages(
118
118
  toolInvocation: {
119
119
  state: "call",
120
120
  step: assistantMessage.parts.filter(
121
- (part) => part.type === "tool-invocation"
121
+ (part) => part.type === "tool-invocation",
122
122
  ).length,
123
123
  toolCallId: contentPart.toolCallId,
124
124
  toolName: contentPart.toolName,
@@ -130,7 +130,7 @@ export function toUIMessages(
130
130
  const call = assistantMessage.parts.find(
131
131
  (part) =>
132
132
  part.type === "tool-invocation" &&
133
- part.toolInvocation.toolCallId === contentPart.toolCallId
133
+ part.toolInvocation.toolCallId === contentPart.toolCallId,
134
134
  ) as ToolInvocationUIPart | undefined;
135
135
  const toolInvocation: ToolInvocationUIPart["toolInvocation"] = {
136
136
  state: "result",
@@ -141,7 +141,7 @@ export function toUIMessages(
141
141
  step:
142
142
  call?.toolInvocation.step ??
143
143
  assistantMessage.parts.filter(
144
- (part) => part.type === "tool-invocation"
144
+ (part) => part.type === "tool-invocation",
145
145
  ).length,
146
146
  };
147
147
  if (call) {
@@ -149,7 +149,7 @@ export function toUIMessages(
149
149
  } else {
150
150
  console.warn(
151
151
  "Tool result without preceding tool call.. adding anyways",
152
- contentPart
152
+ contentPart,
153
153
  );
154
154
  assistantMessage.parts.push({
155
155
  type: "tool-invocation",
@@ -29,7 +29,7 @@ export function useSmoothText(
29
29
  * This will start streaming the first value it sees.
30
30
  */
31
31
  startStreaming?: boolean;
32
- } = {}
32
+ } = {},
33
33
  ): [string, { cursor: number; isStreaming: boolean }] {
34
34
  const [visibleText, setVisibleText] = useState(startStreaming ? "" : text);
35
35
  const smoothState = useRef({
@@ -52,11 +52,11 @@ export function useSmoothText(
52
52
  // Smooth out the charsPerSec by averaging it with the previous value.
53
53
  smoothState.current.charsPerMs = Math.min(
54
54
  (2 * latestCharsPerMs + smoothState.current.charsPerMs) / 3,
55
- smoothState.current.charsPerMs * 2
55
+ smoothState.current.charsPerMs * 2,
56
56
  );
57
57
  smoothState.current.tick = Math.max(
58
58
  smoothState.current.tick,
59
- Date.now() - 2 * MS_PER_FRAME
59
+ Date.now() - 2 * MS_PER_FRAME,
60
60
  );
61
61
 
62
62
  function update() {
@@ -66,14 +66,14 @@ export function useSmoothText(
66
66
  const now = Date.now();
67
67
  const timeSinceLastUpdate = Math.min(
68
68
  MAX_TIME_JUMP_MS,
69
- now - smoothState.current.tick
69
+ now - smoothState.current.tick,
70
70
  );
71
71
  const chars = Math.floor(
72
- timeSinceLastUpdate * smoothState.current.charsPerMs
72
+ timeSinceLastUpdate * smoothState.current.charsPerMs,
73
73
  );
74
74
  smoothState.current.cursor = Math.min(
75
75
  smoothState.current.cursor + chars,
76
- text.length
76
+ text.length,
77
77
  );
78
78
  smoothState.current.tick = now;
79
79
  setVisibleText(text.slice(0, smoothState.current.cursor));
package/src/validators.ts CHANGED
@@ -11,7 +11,7 @@ import { vVectorDimension } from "./component/vector/tables.js";
11
11
 
12
12
  export const vProviderOptions = v.record(
13
13
  v.string(),
14
- v.record(v.string(), v.any())
14
+ v.record(v.string(), v.any()),
15
15
  );
16
16
  const providerOptions = v.optional(vProviderOptions);
17
17
  export type ProviderOptions = Infer<typeof providerOptions>;
@@ -22,12 +22,12 @@ export type ProviderMetadata = Infer<typeof providerMetadata>;
22
22
 
23
23
  export const vThreadStatus = v.union(
24
24
  v.literal("active"),
25
- v.literal("archived") // unused
25
+ v.literal("archived"), // unused
26
26
  );
27
27
  export const vMessageStatus = v.union(
28
28
  v.literal("pending"),
29
29
  v.literal("success"),
30
- v.literal("failed")
30
+ v.literal("failed"),
31
31
  );
32
32
  export type MessageStatus = Infer<typeof vMessageStatus>;
33
33
 
@@ -35,7 +35,7 @@ export const vRole = v.union(
35
35
  v.literal("system"),
36
36
  v.literal("user"),
37
37
  v.literal("assistant"),
38
- v.literal("tool")
38
+ v.literal("tool"),
39
39
  );
40
40
 
41
41
  export const vTextPart = v.object({
@@ -61,7 +61,7 @@ export const vFilePart = v.object({
61
61
 
62
62
  export const vUserContent = v.union(
63
63
  v.string(),
64
- v.array(v.union(vTextPart, vImagePart, vFilePart))
64
+ v.array(v.union(vTextPart, vImagePart, vFilePart)),
65
65
  );
66
66
 
67
67
  export const vReasoningPart = v.object({
@@ -87,8 +87,8 @@ export const vReasoningDetails = v.array(
87
87
  v.object({
88
88
  type: v.literal("redacted"),
89
89
  data: v.string(),
90
- })
91
- )
90
+ }),
91
+ ),
92
92
  );
93
93
 
94
94
  export const vToolCallPart = v.object({
@@ -107,9 +107,9 @@ export const vAssistantContent = v.union(
107
107
  vFilePart,
108
108
  vReasoningPart,
109
109
  vRedactedReasoningPart,
110
- vToolCallPart
111
- )
112
- )
110
+ vToolCallPart,
111
+ ),
112
+ ),
113
113
  );
114
114
 
115
115
  const vToolResultContent = v.array(
@@ -122,8 +122,8 @@ const vToolResultContent = v.array(
122
122
  type: v.literal("image"),
123
123
  data: v.string(),
124
124
  mimeType: v.optional(v.string()),
125
- })
126
- )
125
+ }),
126
+ ),
127
127
  );
128
128
 
129
129
  const vToolResultPart = v.object({
@@ -171,7 +171,7 @@ export const vMessage = v.union(
171
171
  vUserMessage,
172
172
  vAssistantMessage,
173
173
  vToolMessage,
174
- vSystemMessage
174
+ vSystemMessage,
175
175
  );
176
176
  export type Message = Infer<typeof vMessage>;
177
177
 
@@ -221,7 +221,7 @@ export const vFinishReason = v.union(
221
221
  v.literal("tool-calls"),
222
222
  v.literal("error"),
223
223
  v.literal("other"),
224
- v.literal("unknown")
224
+ v.literal("unknown"),
225
225
  );
226
226
 
227
227
  export const vUsage = v.object({
@@ -245,7 +245,7 @@ export const vLanguageModelV1CallWarning = v.union(
245
245
  v.object({
246
246
  type: v.literal("other"),
247
247
  message: v.string(),
248
- })
248
+ }),
249
249
  );
250
250
 
251
251
  export const vMessageWithMetadataInternal = v.object({
@@ -307,7 +307,7 @@ export const vContextOptions = v.object({
307
307
 
308
308
  export const vStorageOptions = v.object({
309
309
  saveMessages: v.optional(
310
- v.union(v.literal("all"), v.literal("none"), v.literal("promptAndOutput"))
310
+ v.union(v.literal("all"), v.literal("none"), v.literal("promptAndOutput")),
311
311
  ),
312
312
  });
313
313
 
@@ -352,8 +352,8 @@ export const vTextArgs = v.object({
352
352
  v.object({
353
353
  type: v.literal("tool"),
354
354
  toolName: v.string(),
355
- })
356
- )
355
+ }),
356
+ ),
357
357
  ),
358
358
  maxSteps: v.optional(v.number()),
359
359
  experimental_continueSteps: v.optional(v.boolean()),
@@ -382,8 +382,8 @@ export function vPaginationResult<
382
382
  v.union(
383
383
  v.literal("SplitRecommended"),
384
384
  v.literal("SplitRequired"),
385
- v.null()
386
- )
385
+ v.null(),
386
+ ),
387
387
  ),
388
388
  });
389
389
  }
@@ -413,7 +413,7 @@ export const vTextStreamPart = v.union(
413
413
  toolName: v.string(),
414
414
  argsTextDelta: v.string(),
415
415
  }),
416
- vToolResultPart
416
+ vToolResultPart,
417
417
  );
418
418
  export type TextStreamPart = Infer<typeof vTextStreamPart>;
419
419
 
@@ -432,8 +432,8 @@ export const vStreamArgs = v.optional(
432
432
  v.object({
433
433
  kind: v.literal("deltas"),
434
434
  cursors: v.array(vStreamCursor),
435
- })
436
- )
435
+ }),
436
+ ),
437
437
  );
438
438
  export type StreamArgs = Infer<typeof vStreamArgs>;
439
439
 
@@ -442,7 +442,7 @@ export const vStreamMessage = v.object({
442
442
  status: v.union(
443
443
  v.literal("streaming"),
444
444
  v.literal("finished"),
445
- v.literal("aborted")
445
+ v.literal("aborted"),
446
446
  ),
447
447
  order: v.number(),
448
448
  stepOrder: v.number(),