@convex-dev/agent 0.3.2 → 0.6.0-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.
- package/dist/UIMessages.d.ts +3 -2
- package/dist/UIMessages.d.ts.map +1 -1
- package/dist/UIMessages.js +100 -19
- package/dist/UIMessages.js.map +1 -1
- package/dist/client/createTool.d.ts +129 -25
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +65 -8
- package/dist/client/createTool.js.map +1 -1
- package/dist/client/definePlaygroundAPI.d.ts +560 -35
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/files.d.ts.map +1 -1
- package/dist/client/files.js +4 -2
- package/dist/client/files.js.map +1 -1
- package/dist/client/index.d.ts +462 -37
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +26 -7
- package/dist/client/index.js.map +1 -1
- package/dist/client/messages.d.ts +114 -9
- package/dist/client/messages.d.ts.map +1 -1
- package/dist/client/mockModel.d.ts +17 -17
- package/dist/client/mockModel.d.ts.map +1 -1
- package/dist/client/mockModel.js +8 -6
- package/dist/client/mockModel.js.map +1 -1
- package/dist/client/saveInputMessages.d.ts +1 -1
- package/dist/client/saveInputMessages.d.ts.map +1 -1
- package/dist/client/saveInputMessages.js +1 -1
- package/dist/client/saveInputMessages.js.map +1 -1
- package/dist/client/search.d.ts +132 -14
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js +66 -19
- package/dist/client/search.js.map +1 -1
- package/dist/client/streamText.d.ts +4 -4
- package/dist/client/streamText.d.ts.map +1 -1
- package/dist/client/streamText.js.map +1 -1
- package/dist/client/streaming.d.ts +1491 -87
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/types.d.ts +26 -6
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/component.d.ts +862 -19
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/files.d.ts +12 -6
- package/dist/component/files.d.ts.map +1 -1
- package/dist/component/files.js +10 -2
- package/dist/component/files.js.map +1 -1
- package/dist/component/messages.d.ts +1247 -92
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/schema.d.ts +2823 -217
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +3 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/streams.js +1 -1
- package/dist/component/streams.js.map +1 -1
- package/dist/component/threads.d.ts +10 -10
- package/dist/component/vector/index.d.ts +1 -1
- package/dist/deltas.d.ts.map +1 -1
- package/dist/deltas.js +40 -5
- package/dist/deltas.js.map +1 -1
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +117 -25
- package/dist/mapping.js.map +1 -1
- package/dist/react/useThreadMessages.d.ts.map +1 -1
- package/dist/react/useThreadMessages.js +17 -9
- package/dist/react/useThreadMessages.js.map +1 -1
- package/dist/shared.d.ts +2 -2
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js.map +1 -1
- package/dist/validators.d.ts +12196 -624
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +152 -9
- package/dist/validators.js.map +1 -1
- package/package.json +24 -22
- package/src/UIMessages.combineUIMessages.test.ts +239 -0
- package/src/UIMessages.ts +184 -66
- package/src/client/createTool.ts +291 -67
- package/src/client/files.ts +4 -2
- package/src/client/index.test.ts +1 -0
- package/src/client/index.ts +46 -25
- package/src/client/mockModel.ts +36 -34
- package/src/client/saveInputMessages.ts +2 -2
- package/src/client/search.test.ts +166 -0
- package/src/client/search.ts +121 -38
- package/src/client/streamText.ts +5 -5
- package/src/client/types.ts +31 -18
- package/src/component/_generated/component.ts +2329 -338
- package/src/component/files.ts +11 -2
- package/src/component/messages.test.ts +7 -7
- package/src/component/schema.ts +3 -1
- package/src/component/setup.test.ts +7 -0
- package/src/component/streams.ts +1 -1
- package/src/deltas.test.ts +90 -0
- package/src/deltas.ts +47 -8
- package/src/fromUIMessages.test.ts +32 -27
- package/src/mapping.test.ts +48 -0
- package/src/mapping.ts +234 -142
- package/src/react/useThreadMessages.ts +21 -9
- package/src/shared.ts +2 -0
- package/src/toUIMessages.test.ts +539 -1
- package/src/validators.ts +179 -20
- package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
package/src/client/streamText.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
AgentPrompt,
|
|
18
18
|
GenerationOutputMetadata,
|
|
19
19
|
Options,
|
|
20
|
+
Output,
|
|
20
21
|
} from "./types.js";
|
|
21
22
|
import { startGeneration } from "./start.js";
|
|
22
23
|
import type { Agent } from "./index.js";
|
|
@@ -32,8 +33,7 @@ import { errorToString, willContinue } from "./utils.js";
|
|
|
32
33
|
*/
|
|
33
34
|
export async function streamText<
|
|
34
35
|
TOOLS extends ToolSet,
|
|
35
|
-
OUTPUT = never,
|
|
36
|
-
PARTIAL_OUTPUT = never,
|
|
36
|
+
OUTPUT extends Output<any, any, any> = never,
|
|
37
37
|
>(
|
|
38
38
|
ctx: ActionCtx,
|
|
39
39
|
component: AgentComponent,
|
|
@@ -43,7 +43,7 @@ export async function streamText<
|
|
|
43
43
|
*/
|
|
44
44
|
streamTextArgs: AgentPrompt &
|
|
45
45
|
Omit<
|
|
46
|
-
Parameters<typeof streamTextAi<TOOLS, OUTPUT
|
|
46
|
+
Parameters<typeof streamTextAi<TOOLS, OUTPUT>>[0],
|
|
47
47
|
"model" | "prompt" | "messages"
|
|
48
48
|
> & {
|
|
49
49
|
/**
|
|
@@ -73,7 +73,7 @@ export async function streamText<
|
|
|
73
73
|
saveStreamDeltas?: boolean | StreamingOptions;
|
|
74
74
|
agentForToolCtx?: Agent;
|
|
75
75
|
},
|
|
76
|
-
): Promise<StreamTextResult<TOOLS,
|
|
76
|
+
): Promise<StreamTextResult<TOOLS, OUTPUT> & GenerationOutputMetadata> {
|
|
77
77
|
const { threadId } = options ?? {};
|
|
78
78
|
const { args, userId, order, stepOrder, promptMessageId, ...call } =
|
|
79
79
|
await startGeneration(ctx, component, streamTextArgs, options);
|
|
@@ -141,7 +141,7 @@ export async function streamText<
|
|
|
141
141
|
await call.save({ step }, createPendingMessage);
|
|
142
142
|
return args.onStepFinish?.(step);
|
|
143
143
|
},
|
|
144
|
-
}) as StreamTextResult<TOOLS,
|
|
144
|
+
}) as StreamTextResult<TOOLS, OUTPUT>;
|
|
145
145
|
const stream = streamer?.consumeStream(
|
|
146
146
|
result.toUIMessageStream<AIUIMessage<TOOLS>>(),
|
|
147
147
|
);
|
package/src/client/types.ts
CHANGED
|
@@ -21,6 +21,14 @@ import type {
|
|
|
21
21
|
CallSettings,
|
|
22
22
|
generateObject,
|
|
23
23
|
} from "ai";
|
|
24
|
+
|
|
25
|
+
export interface Output<_T = any, _P = any, _E = any> {
|
|
26
|
+
name: string;
|
|
27
|
+
responseFormat: any;
|
|
28
|
+
parseCompleteOutput: any;
|
|
29
|
+
parsePartialOutput: any;
|
|
30
|
+
createElementStreamTransform: any;
|
|
31
|
+
}
|
|
24
32
|
import type {
|
|
25
33
|
GenericActionCtx,
|
|
26
34
|
GenericDataModel,
|
|
@@ -99,8 +107,21 @@ export type Config = {
|
|
|
99
107
|
* const myAgent = new Agent(components.agent, {
|
|
100
108
|
* ...
|
|
101
109
|
* textEmbeddingModel: openai.embedding("text-embedding-3-small")
|
|
110
|
+
* @deprecated — Use embeddingModel instead.
|
|
111
|
+
*/
|
|
112
|
+
textEmbeddingModel?: EmbeddingModel;
|
|
113
|
+
/**
|
|
114
|
+
* The model to use for text embeddings. Optional.
|
|
115
|
+
* If specified, it will use this for generating vector embeddings
|
|
116
|
+
* of chats, and can opt-in to doing vector search for automatic context
|
|
117
|
+
* on generateText, etc.
|
|
118
|
+
* e.g.
|
|
119
|
+
* import { openai } from "@ai-sdk/openai"
|
|
120
|
+
* const myAgent = new Agent(components.agent, {
|
|
121
|
+
* ...
|
|
122
|
+
* embeddingModel: openai.embedding("text-embedding-3-small")
|
|
102
123
|
*/
|
|
103
|
-
|
|
124
|
+
embeddingModel?: EmbeddingModel;
|
|
104
125
|
/**
|
|
105
126
|
* Options to determine what messages are included as context in message
|
|
106
127
|
* generation. To disable any messages automatically being added, pass:
|
|
@@ -330,14 +351,12 @@ export type AgentComponent = ComponentApi;
|
|
|
330
351
|
export type TextArgs<
|
|
331
352
|
AgentTools extends ToolSet,
|
|
332
353
|
TOOLS extends ToolSet | undefined = undefined,
|
|
333
|
-
OUTPUT = never,
|
|
334
|
-
OUTPUT_PARTIAL = never,
|
|
354
|
+
OUTPUT extends Output<any, any, any> = never,
|
|
335
355
|
> = Omit<
|
|
336
356
|
Parameters<
|
|
337
357
|
typeof generateText<
|
|
338
358
|
TOOLS extends undefined ? AgentTools : TOOLS,
|
|
339
|
-
OUTPUT
|
|
340
|
-
OUTPUT_PARTIAL
|
|
359
|
+
OUTPUT
|
|
341
360
|
>
|
|
342
361
|
>[0],
|
|
343
362
|
"model" | "prompt" | "messages"
|
|
@@ -352,14 +371,12 @@ export type TextArgs<
|
|
|
352
371
|
export type StreamingTextArgs<
|
|
353
372
|
AgentTools extends ToolSet,
|
|
354
373
|
TOOLS extends ToolSet | undefined = undefined,
|
|
355
|
-
OUTPUT = never,
|
|
356
|
-
OUTPUT_PARTIAL = never,
|
|
374
|
+
OUTPUT extends Output<any, any, any> = never,
|
|
357
375
|
> = Omit<
|
|
358
376
|
Parameters<
|
|
359
377
|
typeof streamText<
|
|
360
378
|
TOOLS extends undefined ? AgentTools : TOOLS,
|
|
361
|
-
OUTPUT
|
|
362
|
-
OUTPUT_PARTIAL
|
|
379
|
+
OUTPUT
|
|
363
380
|
>
|
|
364
381
|
>[0],
|
|
365
382
|
"model" | "prompt" | "messages"
|
|
@@ -474,15 +491,13 @@ export interface Thread<DefaultTools extends ToolSet> {
|
|
|
474
491
|
*/
|
|
475
492
|
generateText<
|
|
476
493
|
TOOLS extends ToolSet | undefined = undefined,
|
|
477
|
-
OUTPUT = never,
|
|
478
|
-
OUTPUT_PARTIAL = never,
|
|
494
|
+
OUTPUT extends Output<any, any, any> = never,
|
|
479
495
|
>(
|
|
480
496
|
generateTextArgs: AgentPrompt &
|
|
481
497
|
TextArgs<
|
|
482
498
|
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
483
499
|
TOOLS,
|
|
484
|
-
OUTPUT
|
|
485
|
-
OUTPUT_PARTIAL
|
|
500
|
+
OUTPUT
|
|
486
501
|
>,
|
|
487
502
|
options?: Options,
|
|
488
503
|
): Promise<
|
|
@@ -502,15 +517,13 @@ export interface Thread<DefaultTools extends ToolSet> {
|
|
|
502
517
|
*/
|
|
503
518
|
streamText<
|
|
504
519
|
TOOLS extends ToolSet | undefined = undefined,
|
|
505
|
-
OUTPUT = never,
|
|
506
|
-
PARTIAL_OUTPUT = never,
|
|
520
|
+
OUTPUT extends Output<any, any, any> = never,
|
|
507
521
|
>(
|
|
508
522
|
streamTextArgs: AgentPrompt &
|
|
509
523
|
StreamingTextArgs<
|
|
510
524
|
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
511
525
|
TOOLS,
|
|
512
|
-
OUTPUT
|
|
513
|
-
PARTIAL_OUTPUT
|
|
526
|
+
OUTPUT
|
|
514
527
|
>,
|
|
515
528
|
options?: Options & {
|
|
516
529
|
/**
|
|
@@ -528,7 +541,7 @@ export interface Thread<DefaultTools extends ToolSet> {
|
|
|
528
541
|
): Promise<
|
|
529
542
|
StreamTextResult<
|
|
530
543
|
TOOLS extends undefined ? DefaultTools : TOOLS,
|
|
531
|
-
|
|
544
|
+
OUTPUT
|
|
532
545
|
> &
|
|
533
546
|
ThreadOutputMetadata
|
|
534
547
|
>;
|