@convex-dev/agent 0.1.7-alpha.2 → 0.1.8-alpha.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 (97) hide show
  1. package/README.md +55 -21
  2. package/dist/commonjs/client/index.d.ts +51 -51
  3. package/dist/commonjs/client/streaming.d.ts +3 -3
  4. package/dist/commonjs/client/streaming.d.ts.map +1 -1
  5. package/dist/commonjs/component/apiKeys.js +1 -1
  6. package/dist/commonjs/component/apiKeys.js.map +1 -1
  7. package/dist/commonjs/component/messages.d.ts +155 -155
  8. package/dist/commonjs/component/schema.d.ts +753 -753
  9. package/dist/commonjs/component/streams.d.ts +18 -18
  10. package/dist/commonjs/component/streams.d.ts.map +1 -1
  11. package/dist/commonjs/component/streams.js +4 -4
  12. package/dist/commonjs/component/streams.js.map +1 -1
  13. package/dist/commonjs/component/threads.d.ts +6 -6
  14. package/dist/commonjs/component/vector/index.d.ts +12 -12
  15. package/dist/commonjs/component/vector/tables.d.ts +6 -6
  16. package/dist/commonjs/mapping.d.ts +1 -1
  17. package/dist/commonjs/mapping.d.ts.map +1 -1
  18. package/dist/commonjs/react/deltas.d.ts +4 -4
  19. package/dist/commonjs/react/deltas.d.ts.map +1 -1
  20. package/dist/commonjs/react/deltas.js +1 -1
  21. package/dist/commonjs/react/deltas.js.map +1 -1
  22. package/dist/commonjs/react/index.d.ts +5 -5
  23. package/dist/commonjs/react/index.d.ts.map +1 -1
  24. package/dist/commonjs/react/index.js +5 -5
  25. package/dist/commonjs/react/index.js.map +1 -1
  26. package/dist/commonjs/react/optimisticallySendMessage.d.ts +2 -2
  27. package/dist/commonjs/react/optimisticallySendMessage.d.ts.map +1 -1
  28. package/dist/commonjs/react/toUIMessages.d.ts +2 -2
  29. package/dist/commonjs/react/toUIMessages.d.ts.map +1 -1
  30. package/dist/commonjs/react/toUIMessages.js +1 -1
  31. package/dist/commonjs/react/toUIMessages.js.map +1 -1
  32. package/dist/commonjs/react/usePaginatedQuery.d.ts.map +1 -1
  33. package/dist/commonjs/react/usePaginatedQuery.js +0 -1
  34. package/dist/commonjs/react/usePaginatedQuery.js.map +1 -1
  35. package/dist/commonjs/shared.d.ts +1 -1
  36. package/dist/commonjs/shared.d.ts.map +1 -1
  37. package/dist/commonjs/validators.d.ts +161 -161
  38. package/dist/commonjs/vitest.config.d.ts +3 -0
  39. package/dist/commonjs/vitest.config.d.ts.map +1 -0
  40. package/dist/commonjs/vitest.config.js +7 -0
  41. package/dist/commonjs/vitest.config.js.map +1 -0
  42. package/dist/commonjs.tsbuildinfo +1 -1
  43. package/dist/esm/client/index.d.ts +17 -17
  44. package/dist/esm/client/streaming.d.ts +3 -3
  45. package/dist/esm/client/streaming.d.ts.map +1 -1
  46. package/dist/esm/component/apiKeys.js +1 -1
  47. package/dist/esm/component/apiKeys.js.map +1 -1
  48. package/dist/esm/component/messages.d.ts +27 -27
  49. package/dist/esm/component/schema.d.ts +48 -48
  50. package/dist/esm/component/streams.d.ts.map +1 -1
  51. package/dist/esm/component/streams.js +4 -4
  52. package/dist/esm/component/streams.js.map +1 -1
  53. package/dist/esm/component/threads.d.ts +8 -8
  54. package/dist/esm/mapping.d.ts +1 -1
  55. package/dist/esm/mapping.d.ts.map +1 -1
  56. package/dist/esm/react/deltas.d.ts +4 -4
  57. package/dist/esm/react/deltas.d.ts.map +1 -1
  58. package/dist/esm/react/deltas.js +1 -1
  59. package/dist/esm/react/deltas.js.map +1 -1
  60. package/dist/esm/react/index.d.ts +5 -5
  61. package/dist/esm/react/index.d.ts.map +1 -1
  62. package/dist/esm/react/index.js +5 -5
  63. package/dist/esm/react/index.js.map +1 -1
  64. package/dist/esm/react/optimisticallySendMessage.d.ts +2 -2
  65. package/dist/esm/react/optimisticallySendMessage.d.ts.map +1 -1
  66. package/dist/esm/react/toUIMessages.d.ts +2 -2
  67. package/dist/esm/react/toUIMessages.d.ts.map +1 -1
  68. package/dist/esm/react/toUIMessages.js +1 -1
  69. package/dist/esm/react/toUIMessages.js.map +1 -1
  70. package/dist/esm/react/usePaginatedQuery.d.ts.map +1 -1
  71. package/dist/esm/react/usePaginatedQuery.js +0 -1
  72. package/dist/esm/react/usePaginatedQuery.js.map +1 -1
  73. package/dist/esm/shared.d.ts +1 -1
  74. package/dist/esm/shared.d.ts.map +1 -1
  75. package/dist/esm/validators.d.ts +19 -19
  76. package/dist/esm/vitest.config.d.ts +3 -0
  77. package/dist/esm/vitest.config.d.ts.map +1 -0
  78. package/dist/esm/vitest.config.js +7 -0
  79. package/dist/esm/vitest.config.js.map +1 -0
  80. package/dist/esm.tsbuildinfo +1 -1
  81. package/package.json +6 -5
  82. package/src/client/index.test.ts +271 -4
  83. package/src/client/streaming.ts +3 -3
  84. package/src/component/apiKeys.ts +1 -1
  85. package/src/component/streams.ts +9 -5
  86. package/src/mapping.test.ts +4 -4
  87. package/src/mapping.ts +1 -1
  88. package/src/react/deltas.test.ts +17 -3
  89. package/src/react/deltas.ts +4 -4
  90. package/src/react/index.ts +10 -10
  91. package/src/react/optimisticallySendMessage.ts +2 -2
  92. package/src/react/toUIMessages.test.ts +2 -8
  93. package/src/react/toUIMessages.ts +3 -3
  94. package/src/react/usePaginatedQuery.ts +0 -1
  95. package/src/shared.ts +1 -1
  96. package/src/validators.test.ts +4 -4
  97. package/src/vitest.config.ts +7 -0
@@ -1,5 +1,9 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import { Agent, filterOutOrphanedToolMessages, type MessageDoc } from ".";
2
+ import {
3
+ Agent,
4
+ filterOutOrphanedToolMessages,
5
+ type MessageDoc,
6
+ } from "./index.js";
3
7
  import type { DataModelFromSchemaDefinition } from "convex/server";
4
8
  import {
5
9
  anyApi,
@@ -18,7 +22,8 @@ import { defineSchema } from "convex/server";
18
22
  import { MockLanguageModelV1 } from "ai/test";
19
23
  import type { LanguageModelV1, LanguageModelV1StreamPart } from "ai";
20
24
  import { simulateReadableStream } from "ai";
21
- import { components, initConvexTest } from "./setup.test";
25
+ import { components, initConvexTest } from "./setup.test.js";
26
+ import { z } from "zod";
22
27
 
23
28
  const schema = defineSchema({});
24
29
  type DataModel = DataModelFromSchemaDefinition<typeof schema>;
@@ -58,6 +63,16 @@ export const createThread = mutation({
58
63
  },
59
64
  });
60
65
 
66
+ export const createThreadMutation = agent.createThreadMutation();
67
+ export const generateObjectAction = agent.asObjectAction({
68
+ schema: z.object({
69
+ prompt: z.any().describe("The prompt passed in"),
70
+ }),
71
+ });
72
+ export const generateTextAction = agent.asTextAction({});
73
+ export const streamTextAction = agent.asTextAction({ stream: true });
74
+ export const saveMessageMutation = agent.asSaveMessagesMutation();
75
+
61
76
  export const createAndGenerate = action({
62
77
  args: {},
63
78
  handler: async (ctx) => {
@@ -71,11 +86,87 @@ export const createAndGenerate = action({
71
86
  },
72
87
  });
73
88
 
89
+ export const continueThreadAction = action({
90
+ args: { threadId: v.string(), userId: v.optional(v.string()) },
91
+ handler: async (ctx, args) => {
92
+ const { thread } = await agent.continueThread(ctx, args);
93
+ return { threadId: thread.threadId };
94
+ },
95
+ });
96
+
97
+ export const generateTextWithThread = action({
98
+ args: {
99
+ threadId: v.string(),
100
+ userId: v.optional(v.string()),
101
+ messages: v.array(v.any()),
102
+ contextOptions: v.optional(v.any()),
103
+ storageOptions: v.optional(v.any()),
104
+ },
105
+ handler: async (ctx, args) => {
106
+ const { thread } = await agent.continueThread(ctx, {
107
+ threadId: args.threadId,
108
+ userId: args.userId,
109
+ });
110
+ const result = await thread.generateText(
111
+ { messages: args.messages },
112
+ {
113
+ contextOptions: args.contextOptions,
114
+ storageOptions: args.storageOptions,
115
+ }
116
+ );
117
+ return { text: result.text };
118
+ },
119
+ });
120
+
121
+ export const generateObjectWithThread = action({
122
+ args: {
123
+ threadId: v.string(),
124
+ userId: v.optional(v.string()),
125
+ prompt: v.string(),
126
+ },
127
+ handler: async (ctx, args) => {
128
+ const { thread } = await agent.continueThread(ctx, {
129
+ threadId: args.threadId,
130
+ userId: args.userId,
131
+ });
132
+ const result = await thread.generateObject({
133
+ prompt: args.prompt,
134
+ schema: z.object({ prompt: z.any() }),
135
+ });
136
+ return { object: result.object };
137
+ },
138
+ });
139
+
140
+ export const fetchContextAction = action({
141
+ args: {
142
+ userId: v.optional(v.string()),
143
+ threadId: v.optional(v.string()),
144
+ messages: v.array(v.any()),
145
+ contextOptions: v.optional(v.any()),
146
+ },
147
+ handler: async (ctx, args) => {
148
+ const context = await agent.fetchContextMessages(ctx, {
149
+ userId: args.userId,
150
+ threadId: args.threadId,
151
+ messages: args.messages,
152
+ contextOptions: args.contextOptions,
153
+ });
154
+ return context;
155
+ },
156
+ });
157
+
74
158
  const testApi: ApiFromModules<{
75
159
  fns: {
76
160
  createAndGenerate: typeof createAndGenerate;
77
161
  createThread: typeof createThread;
78
162
  testQuery: typeof testQuery;
163
+ continueThreadAction: typeof continueThreadAction;
164
+ generateTextWithThread: typeof generateTextWithThread;
165
+ generateObjectWithThread: typeof generateObjectWithThread;
166
+ fetchContextAction: typeof fetchContextAction;
167
+ generateTextAction: typeof generateTextAction;
168
+ generateObjectAction: typeof generateObjectAction;
169
+ saveMessageMutation: typeof saveMessageMutation;
79
170
  };
80
171
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
172
  }>["fns"] = anyApi["index.test"] as any;
@@ -90,7 +181,7 @@ describe("Agent thick client", () => {
90
181
  const t = initConvexTest(schema);
91
182
  const result = await t.action(testApi.createAndGenerate, {});
92
183
  expect(result).toBeDefined();
93
- expect(result).toMatch("This is a sample response");
184
+ expect(result).toMatch("Hello");
94
185
  });
95
186
  });
96
187
 
@@ -164,12 +255,14 @@ function mockModel(): LanguageModelV1 {
164
255
  return new MockLanguageModelV1({
165
256
  provider: "mock",
166
257
  modelId: "mock",
258
+ defaultObjectGenerationMode: "json",
259
+ // supportsStructuredOutputs: true,
167
260
  doGenerate: async ({ prompt }) => ({
168
261
  finishReason: "stop",
169
262
  usage: { completionTokens: 10, promptTokens: 3 },
170
263
  logprobs: undefined,
171
264
  rawCall: { rawPrompt: null, rawSettings: {} },
172
- text: `This is a sample response to ${JSON.stringify(prompt)}`,
265
+ text: JSON.stringify({ prompt }),
173
266
  }),
174
267
  doStream: async ({ prompt }) => ({
175
268
  stream: simulateReadableStream({
@@ -192,3 +285,177 @@ function mockModel(): LanguageModelV1 {
192
285
  }),
193
286
  });
194
287
  }
288
+
289
+ describe("Agent option variations and normal behavior", () => {
290
+ test("Agent can be constructed with minimal options", () => {
291
+ const a = new Agent(components.agent, { chat: mockModel() });
292
+ expect(a).toBeInstanceOf(Agent);
293
+ });
294
+
295
+ test("Agent can be constructed with all options", () => {
296
+ const a = new Agent(components.agent, {
297
+ name: "full",
298
+ chat: mockModel(),
299
+ instructions: "Test instructions",
300
+ contextOptions: { recentMessages: 5 },
301
+ storageOptions: { saveMessages: "all" },
302
+ maxSteps: 2,
303
+ maxRetries: 1,
304
+ usageHandler: async () => {},
305
+ rawRequestResponseHandler: async () => {},
306
+ });
307
+ expect(a.options.name).toBe("full");
308
+ });
309
+ });
310
+
311
+ describe("Agent thread management", () => {
312
+ test("createThread returns threadId (mutation context)", async () => {
313
+ const t = initConvexTest(schema);
314
+ const { threadId } = await t.run(async (ctx) =>
315
+ agent.createThread(ctx, { userId: "2" })
316
+ );
317
+ expect(threadId).toBeTypeOf("string");
318
+ });
319
+
320
+ test("continueThread returns thread object", async () => {
321
+ const t = initConvexTest(schema);
322
+ const { threadId } = await t.run(async (ctx) =>
323
+ agent.createThread(ctx, { userId: "3" })
324
+ );
325
+ const result = await t.action(testApi.continueThreadAction, {
326
+ threadId,
327
+ userId: "3",
328
+ });
329
+ expect(result.threadId).toBe(threadId);
330
+ });
331
+ });
332
+
333
+ describe("Agent message operations", () => {
334
+ test("saveMessage and saveMessages store messages", async () => {
335
+ const t = initConvexTest(schema);
336
+ const { threadId } = await t.run(async (ctx) =>
337
+ agent.createThread(ctx, { userId: "4" })
338
+ );
339
+ const { messageId } = await t.run(async (ctx) =>
340
+ agent.saveMessage(ctx, {
341
+ threadId,
342
+ userId: "4",
343
+ message: { role: "user", content: "Hello" },
344
+ })
345
+ );
346
+ expect(messageId).toBeTypeOf("string");
347
+
348
+ const { lastMessageId, messages } = await t.run(async (ctx) =>
349
+ agent.saveMessages(ctx, {
350
+ threadId,
351
+ userId: "4",
352
+ messages: [
353
+ { role: "user", content: "Hi" },
354
+ { role: "assistant", content: "Hello!" },
355
+ ],
356
+ })
357
+ );
358
+ expect(messages.length).toBe(2);
359
+ expect(lastMessageId).toBe(messages[1]._id);
360
+ });
361
+ });
362
+
363
+ describe("Agent text/object generation", () => {
364
+ test("generateText with custom context and storage options", async () => {
365
+ const t = initConvexTest(schema);
366
+ const { threadId } = await t.run(async (ctx) =>
367
+ agent.createThread(ctx, { userId: "5" })
368
+ );
369
+ const result = await t.action(testApi.generateTextWithThread, {
370
+ threadId,
371
+ userId: "5",
372
+ messages: [{ role: "user", content: "Test" }],
373
+ contextOptions: { recentMessages: 1 },
374
+ storageOptions: { saveMessages: "all" },
375
+ });
376
+ expect(result.text).toMatch(/Test/);
377
+ });
378
+
379
+ test("generateObject returns object", async () => {
380
+ const t = initConvexTest(schema);
381
+ const { threadId } = await t.run(async (ctx) =>
382
+ agent.createThread(ctx, { userId: "6" })
383
+ );
384
+ const result = await t.action(testApi.generateObjectWithThread, {
385
+ threadId,
386
+ userId: "6",
387
+ prompt: "Object please",
388
+ });
389
+ expect(result.object).toBeDefined();
390
+ });
391
+ });
392
+
393
+ describe("Agent-generated mutations/actions/queries", () => {
394
+ test("createThreadMutation works via t.mutation", async () => {
395
+ const t = initConvexTest(schema);
396
+ // This test is for the registered mutation, not the agent method
397
+ const result = await t.mutation(testApi.createThread, {});
398
+ expect(result.threadId).toBeTypeOf("string");
399
+ });
400
+
401
+ test("asTextAction and asObjectAction work via t.action", async () => {
402
+ const t = initConvexTest(schema);
403
+ const { threadId } = await t.run(async (ctx) =>
404
+ agent.createThread(ctx, { userId: "8" })
405
+ );
406
+ const textResult = await t.action(testApi.generateTextAction, {
407
+ userId: "8",
408
+ threadId,
409
+ messages: [{ role: "user", content: "Say hi" }],
410
+ });
411
+ expect(textResult.text).toMatch(/Say hi/);
412
+
413
+ const objResult = await t.action(testApi.generateObjectAction, {
414
+ userId: "8",
415
+ threadId,
416
+ messages: [{ role: "user", content: "Give object" }],
417
+ });
418
+ expect(objResult.object).toBeDefined();
419
+ });
420
+
421
+ test("asSaveMessagesMutation works via t.mutation", async () => {
422
+ const t = initConvexTest(schema);
423
+ const { threadId } = await t.run(async (ctx) =>
424
+ agent.createThread(ctx, { userId: "9" })
425
+ );
426
+ const result = await t.mutation(testApi.saveMessageMutation, {
427
+ threadId,
428
+ messages: [
429
+ {
430
+ message: { role: "user", content: "Saved via mutation" },
431
+ // add more metadata fields as needed
432
+ },
433
+ ],
434
+ });
435
+ expect(result.lastMessageId).toBeDefined();
436
+ expect(result.messageIds.length).toBe(1);
437
+ });
438
+ });
439
+
440
+ describe("Agent context and search options", () => {
441
+ test("fetchContextMessages returns context messages", async () => {
442
+ const t = initConvexTest(schema);
443
+ const { threadId } = await t.run(async (ctx) =>
444
+ agent.createThread(ctx, { userId: "10" })
445
+ );
446
+ await t.run(async (ctx) =>
447
+ agent.saveMessage(ctx, {
448
+ threadId,
449
+ userId: "10",
450
+ message: { role: "user", content: "Context test" },
451
+ })
452
+ );
453
+ const context = await t.action(testApi.fetchContextAction, {
454
+ userId: "10",
455
+ threadId,
456
+ messages: [{ role: "user", content: "Context test" }],
457
+ contextOptions: { recentMessages: 1 },
458
+ });
459
+ expect(context.length).toBeGreaterThan(0);
460
+ });
461
+ });
@@ -8,9 +8,9 @@ import type {
8
8
  ProviderOptions,
9
9
  StreamDelta,
10
10
  TextStreamPart,
11
- } from "../validators";
12
- import type { AgentComponent, MessageDoc } from "./index";
13
- import type { RunActionCtx } from "./types";
11
+ } from "../validators.js";
12
+ import type { AgentComponent, MessageDoc } from "./index.js";
13
+ import type { RunActionCtx } from "./types.js";
14
14
 
15
15
  export type StreamingOptions = {
16
16
  /**
@@ -1,5 +1,5 @@
1
1
  import { v } from "convex/values";
2
- import { mutation, query } from "./_generated/server";
2
+ import { mutation, query } from "./_generated/server.js";
3
3
 
4
4
  export const issue = mutation({
5
5
  args: {
@@ -1,15 +1,19 @@
1
1
  import { omit, pick } from "convex-helpers";
2
2
  import { v } from "convex/values";
3
- import { type StreamDelta, vStreamDelta, vStreamMessage } from "../validators";
4
- import { internal } from "./_generated/api";
5
- import type { Id } from "./_generated/dataModel";
3
+ import {
4
+ type StreamDelta,
5
+ vStreamDelta,
6
+ vStreamMessage,
7
+ } from "../validators.js";
8
+ import { internal } from "./_generated/api.js";
9
+ import type { Id } from "./_generated/dataModel.js";
6
10
  import {
7
11
  internalMutation,
8
12
  mutation,
9
13
  type MutationCtx,
10
14
  query,
11
- } from "./_generated/server";
12
- import schema from "./schema";
15
+ } from "./_generated/server.js";
16
+ import schema from "./schema.js";
13
17
 
14
18
  const MAX_DELTAS_PER_REQUEST = 1000;
15
19
  const MAX_DELTAS_PER_STREAM = 100;
@@ -6,13 +6,13 @@ import {
6
6
  serializeMessage,
7
7
  deserializeMessage,
8
8
  serializeContent,
9
- } from "./mapping";
9
+ } from "./mapping.js";
10
10
  import { api } from "./component/_generated/api.js";
11
- import type { AgentComponent, ActionCtx } from "./client/types";
12
- import { vMessage } from "./validators";
11
+ import type { AgentComponent, ActionCtx } from "./client/types.js";
12
+ import { vMessage } from "./validators.js";
13
13
  import fs from "fs";
14
14
  import path from "path";
15
- import type { SerializedContent } from "./mapping";
15
+ import type { SerializedContent } from "./mapping.js";
16
16
  import { validate } from "convex-helpers/validators";
17
17
 
18
18
  const testAssetsDir = path.join(__dirname, "../test-assets");
package/src/mapping.ts CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  type UserContent,
16
16
  } from "ai";
17
17
  import { assert } from "convex-helpers";
18
- import type { MessageWithMetadata } from "./validators";
18
+ import type { MessageWithMetadata } from "./validators.js";
19
19
  import type { ActionCtx, AgentComponent } from "./client/types.js";
20
20
  import type { RunMutationCtx } from "./client/types.js";
21
21
  import { MAX_FILE_SIZE, storeFile } from "./client/files.js";
@@ -1,6 +1,10 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { mergeDeltas, applyDeltasToStreamMessage } from "./deltas";
3
- import type { StreamMessage, StreamDelta, TextStreamPart } from "../validators";
2
+ import { mergeDeltas, applyDeltasToStreamMessage } from "./deltas.js";
3
+ import type {
4
+ StreamMessage,
5
+ StreamDelta,
6
+ TextStreamPart,
7
+ } from "../validators.js";
4
8
  import { omit } from "convex-helpers";
5
9
 
6
10
  function makeStreamMessage(
@@ -287,7 +291,17 @@ describe("mergeDeltas", () => {
287
291
  expect(messages1.map((m) => omit(m, ["_creationTime"]))).toEqual(
288
292
  messages2.map((m) => omit(m, ["_creationTime"]))
289
293
  );
290
- expect(streams1).toEqual(streams2);
294
+ expect(
295
+ streams1.map((s) => ({
296
+ ...s,
297
+ messages: s.messages.map((m) => omit(m, ["_creationTime"])),
298
+ }))
299
+ ).toEqual(
300
+ streams2.map((s) => ({
301
+ ...s,
302
+ messages: s.messages.map((m) => omit(m, ["_creationTime"])),
303
+ }))
304
+ );
291
305
  expect(changed1).toBe(changed2);
292
306
  // Inputs should remain unchanged
293
307
  expect(streamMessages).toEqual([makeStreamMessage(streamId, 8, 0)]);
@@ -1,13 +1,13 @@
1
1
  import type { TextPart, ToolCallPart, ToolResultPart } from "ai";
2
- import type { MessageDoc } from "../client";
2
+ import type { MessageDoc } from "../client/index.js";
3
3
  import type {
4
4
  Message,
5
5
  StreamDelta,
6
6
  StreamMessage,
7
7
  TextStreamPart,
8
- } from "../validators";
9
- import type { UIMessage } from "./toUIMessages";
10
- import { toUIMessages } from "./toUIMessages";
8
+ } from "../validators.js";
9
+ import type { UIMessage } from "./toUIMessages.js";
10
+ import { toUIMessages } from "./toUIMessages.js";
11
11
 
12
12
  export { toUIMessages, type UIMessage };
13
13
 
@@ -6,24 +6,24 @@ import {
6
6
  type UsePaginatedQueryResult,
7
7
  useQuery,
8
8
  } from "convex/react";
9
- import { usePaginatedQuery } from "./usePaginatedQuery";
9
+ import { usePaginatedQuery } from "./usePaginatedQuery.js";
10
10
  import type { FunctionArgs } from "convex/server";
11
11
  import { useMemo, useState } from "react";
12
- import type { MessageDoc } from "../client";
13
- import type { SyncStreamsReturnValue } from "../client/types";
14
- import type { StreamArgs } from "../validators";
15
- import type { UIMessage } from "./toUIMessages";
16
- import { toUIMessages } from "./toUIMessages";
17
- import { mergeDeltas } from "./deltas";
12
+ import type { MessageDoc } from "../client/index.js";
13
+ import type { SyncStreamsReturnValue } from "../client/types.js";
14
+ import type { StreamArgs } from "../validators.js";
15
+ import type { UIMessage } from "./toUIMessages.js";
16
+ import { toUIMessages } from "./toUIMessages.js";
17
+ import { mergeDeltas } from "./deltas.js";
18
18
  import type {
19
19
  ThreadQuery,
20
20
  ThreadStreamQuery,
21
21
  ThreadMessagesArgs,
22
22
  ThreadMessagesResult,
23
- } from "./types";
23
+ } from "./types.js";
24
24
 
25
- export { optimisticallySendMessage } from "./optimisticallySendMessage";
26
- export { useSmoothText } from "./useSmoothText";
25
+ export { optimisticallySendMessage } from "./optimisticallySendMessage.js";
26
+ export { useSmoothText } from "./useSmoothText.js";
27
27
  export { toUIMessages, type UIMessage };
28
28
 
29
29
  /**
@@ -1,7 +1,7 @@
1
1
  import { insertAtTop } from "convex/react";
2
- import type { MessageDoc } from "../client";
2
+ import type { MessageDoc } from "../client/index.js";
3
3
  import type { OptimisticLocalStore } from "convex/browser";
4
- import type { ThreadQuery } from "./types";
4
+ import type { ThreadQuery } from "./types.js";
5
5
 
6
6
  export function optimisticallySendMessage(
7
7
  query: ThreadQuery<unknown, MessageDoc>
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { toUIMessages } from "./toUIMessages";
3
- import type { MessageDoc } from "../client";
2
+ import { toUIMessages } from "./toUIMessages.js";
3
+ import type { MessageDoc } from "../client/index.js";
4
4
 
5
5
  // Helper to create a base message doc
6
6
  function baseMessageDoc(overrides: Partial<MessageDoc> = {}): MessageDoc {
@@ -93,12 +93,6 @@ describe("toUIMessages", () => {
93
93
  ],
94
94
  },
95
95
  tool: true,
96
- files: [
97
- {
98
- mimeType: "text/plain",
99
- data: "asdfasdfasdf",
100
- },
101
- ],
102
96
  reasoning: "I'm thinking...",
103
97
  text: "I'm thinking...",
104
98
  }),
@@ -1,8 +1,8 @@
1
1
  import type { ToolInvocationUIPart } from "@ai-sdk/ui-utils";
2
2
  import type { UIMessage as AIUIMessage } from "ai";
3
- import type { MessageDoc } from "../client";
4
- import { deserializeMessage, toUIFilePart } from "../mapping";
5
- import type { MessageStatus } from "../validators";
3
+ import type { MessageDoc } from "../client/index.js";
4
+ import { deserializeMessage, toUIFilePart } from "../mapping.js";
5
+ import type { MessageStatus } from "../validators.js";
6
6
 
7
7
  export type UIMessage = AIUIMessage & {
8
8
  key: string;
@@ -279,7 +279,6 @@ export function usePaginatedQuery<Query extends PaginatedQueryReference>(
279
279
  allItems.push(...currResult.page);
280
280
  }
281
281
  return [allItems, currResult];
282
- // eslint-disable-next-line react-hooks/exhaustive-deps
283
282
  }, [
284
283
  resultsObject,
285
284
  currState.pageKeys,
package/src/shared.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { CoreMessage } from "ai";
2
- import type { Message } from "./validators";
2
+ import type { Message } from "./validators.js";
3
3
 
4
4
  export const DEFAULT_RECENT_MESSAGES = 100;
5
5
 
@@ -16,9 +16,9 @@ import type {
16
16
  } from "ai";
17
17
  import type { Infer } from "convex/values";
18
18
  import { expectTypeOf, test } from "vitest";
19
- import type { ContextOptions, StorageOptions } from "./client";
20
- import type { SerializeUrlsAndUint8Arrays } from "./mapping";
21
- import type { TextStreamPart } from "./validators";
19
+ import type { ContextOptions, StorageOptions } from "./client/types.js";
20
+ import type { SerializeUrlsAndUint8Arrays } from "./mapping.js";
21
+ import type { TextStreamPart } from "./validators.js";
22
22
  import {
23
23
  vAssistantContent,
24
24
  vAssistantMessage,
@@ -36,7 +36,7 @@ import {
36
36
  vToolMessage,
37
37
  vUserContent,
38
38
  vUserMessage,
39
- } from "./validators";
39
+ } from "./validators.js";
40
40
 
41
41
  // type assertion
42
42
  type OurUserContent = SerializeUrlsAndUint8Arrays<UserContent>;
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: "edge-runtime",
6
+ },
7
+ });