@convex-dev/agent 0.1.18-alpha.1 → 0.2.0-alpha.2
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/client/createTool.d.ts +31 -10
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +25 -10
- package/dist/client/createTool.js.map +1 -1
- package/dist/client/defaultComponent.d.ts +11 -0
- package/dist/client/defaultComponent.d.ts.map +1 -0
- package/dist/client/defaultComponent.js +7 -0
- package/dist/client/defaultComponent.js.map +1 -0
- package/dist/client/definePlaygroundAPI.d.ts +174 -199
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/definePlaygroundAPI.js +17 -35
- package/dist/client/definePlaygroundAPI.js.map +1 -1
- package/dist/client/files.d.ts +6 -3
- package/dist/client/files.d.ts.map +1 -1
- package/dist/client/files.js +7 -7
- package/dist/client/files.js.map +1 -1
- package/dist/client/index.d.ts +152 -589
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +138 -222
- package/dist/client/index.js.map +1 -1
- package/dist/client/messages.d.ts +538 -0
- package/dist/client/messages.d.ts.map +1 -0
- package/dist/client/messages.js +91 -0
- package/dist/client/messages.js.map +1 -0
- package/dist/client/search.d.ts +30 -7
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js +20 -3
- package/dist/client/search.js.map +1 -1
- package/dist/client/streaming.d.ts +3 -2
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/streaming.js.map +1 -1
- package/dist/client/threads.d.ts +46 -0
- package/dist/client/threads.d.ts.map +1 -0
- package/dist/client/threads.js +49 -0
- package/dist/client/threads.js.map +1 -0
- package/dist/client/types.d.ts +39 -42
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +437 -75
- package/dist/component/messages.d.ts +254 -55
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/messages.js +29 -25
- package/dist/component/messages.js.map +1 -1
- package/dist/component/schema.d.ts +1459 -158
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +8 -14
- package/dist/component/schema.js.map +1 -1
- package/dist/component/streams.d.ts +180 -6
- package/dist/component/streams.d.ts.map +1 -1
- package/dist/mapping.d.ts +11 -15
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +191 -61
- package/dist/mapping.js.map +1 -1
- package/dist/react/deltas.d.ts +0 -3
- package/dist/react/deltas.d.ts.map +1 -1
- package/dist/react/deltas.js +140 -44
- package/dist/react/deltas.js.map +1 -1
- package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
- package/dist/react/optimisticallySendMessage.js +2 -1
- package/dist/react/optimisticallySendMessage.js.map +1 -1
- package/dist/react/toUIMessages.d.ts +5 -4
- package/dist/react/toUIMessages.d.ts.map +1 -1
- package/dist/react/toUIMessages.js +103 -40
- package/dist/react/toUIMessages.js.map +1 -1
- package/dist/validators.d.ts +1978 -1210
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +90 -54
- package/dist/validators.js.map +1 -1
- package/package.json +32 -28
- package/src/client/createTool.ts +69 -38
- package/src/client/defaultComponent.ts +17 -0
- package/src/client/definePlaygroundAPI.ts +29 -43
- package/src/client/files.ts +7 -8
- package/src/client/index.test.ts +20 -18
- package/src/client/index.ts +228 -434
- package/src/client/messages.ts +191 -0
- package/src/client/search.ts +30 -6
- package/src/client/streaming.ts +4 -3
- package/src/client/threads.ts +78 -0
- package/src/client/types.ts +50 -72
- package/src/component/_generated/api.d.ts +437 -75
- package/src/component/messages.test.ts +182 -40
- package/src/component/messages.ts +30 -32
- package/src/component/schema.ts +8 -14
- package/src/mapping.ts +230 -94
- package/src/react/deltas.ts +165 -52
- package/src/react/optimisticallySendMessage.ts +4 -1
- package/src/react/toUIMessages.test.ts +154 -36
- package/src/react/toUIMessages.ts +136 -57
- package/src/validators.test.ts +2 -101
- package/src/validators.ts +111 -68
- package/dist/client/listMessages.d.ts +0 -22
- package/dist/client/listMessages.d.ts.map +0 -1
- package/dist/client/listMessages.js +0 -25
- package/dist/client/listMessages.js.map +0 -1
- package/src/client/listMessages.ts +0 -38
- package/src/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Schema, Tool,
|
|
2
|
-
import { z } from "zod";
|
|
1
|
+
import type { Schema, Tool, ToolCallOptions, ToolSet } from "ai";
|
|
2
|
+
import { z } from "zod/v3";
|
|
3
3
|
import type { Agent } from "./index.js";
|
|
4
4
|
import type { GenericActionCtx, GenericDataModel } from "convex/server";
|
|
5
|
+
import type { ProviderOptions } from "../validators.js";
|
|
5
6
|
export type ToolCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericActionCtx<DataModel> & {
|
|
6
7
|
agent: Agent;
|
|
7
8
|
userId?: string;
|
|
@@ -15,7 +16,7 @@ export type ToolCtx<DataModel extends GenericDataModel = GenericDataModel> = Gen
|
|
|
15
16
|
* but swap parameters for args and handler for execute.
|
|
16
17
|
* @returns A tool to be used with the AI SDK.
|
|
17
18
|
*/
|
|
18
|
-
export declare function createTool<
|
|
19
|
+
export declare function createTool<INPUT, OUTPUT, Ctx extends ToolCtx = ToolCtx>(def: {
|
|
19
20
|
/**
|
|
20
21
|
An optional description of what the tool does.
|
|
21
22
|
Will be used by the language model to decide whether to use the tool.
|
|
@@ -27,7 +28,7 @@ export declare function createTool<PARAMETERS extends ToolParameters, RESULT, Ct
|
|
|
27
28
|
It is also used to validate the output of the language model.
|
|
28
29
|
Use descriptions to make the input understandable for the language model.
|
|
29
30
|
*/
|
|
30
|
-
args:
|
|
31
|
+
args: ToolParameters<INPUT>;
|
|
31
32
|
/**
|
|
32
33
|
An async function that is called with the arguments from the tool call and produces a result.
|
|
33
34
|
If not provided, the tool will not be executed automatically.
|
|
@@ -35,13 +36,33 @@ export declare function createTool<PARAMETERS extends ToolParameters, RESULT, Ct
|
|
|
35
36
|
@args is the input of the tool call.
|
|
36
37
|
@options.abortSignal is a signal that can be used to abort the tool call.
|
|
37
38
|
*/
|
|
38
|
-
handler: (ctx: Ctx, args:
|
|
39
|
+
handler: (ctx: Ctx, args: INPUT, options: ToolCallOptions) => PromiseLike<OUTPUT>;
|
|
40
|
+
/**
|
|
41
|
+
* Provide the context to use, e.g. when defining the tool at runtime.
|
|
42
|
+
*/
|
|
39
43
|
ctx?: Ctx;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Optional function that is called when the argument streaming starts.
|
|
46
|
+
* Only called when the tool is used in a streaming context.
|
|
47
|
+
*/
|
|
48
|
+
onInputStart?: (ctx: Ctx, options: ToolCallOptions) => void | PromiseLike<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Optional function that is called when an argument streaming delta is available.
|
|
51
|
+
* Only called when the tool is used in a streaming context.
|
|
52
|
+
*/
|
|
53
|
+
onInputDelta?: (ctx: Ctx, options: {
|
|
54
|
+
inputTextDelta: string;
|
|
55
|
+
} & ToolCallOptions) => void | PromiseLike<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Optional function that is called when a tool call can be started,
|
|
58
|
+
* even if the execute function is not provided.
|
|
59
|
+
*/
|
|
60
|
+
onInputAvailable?: (ctx: Ctx, options: {
|
|
61
|
+
input: [INPUT] extends [never] ? undefined : INPUT;
|
|
62
|
+
} & ToolCallOptions) => void | PromiseLike<void>;
|
|
63
|
+
providerOptions?: ProviderOptions;
|
|
64
|
+
}): Tool<INPUT, OUTPUT>;
|
|
43
65
|
export declare function wrapTools(ctx: ToolCtx, ...toolSets: (ToolSet | undefined)[]): ToolSet;
|
|
44
|
-
type ToolParameters = z.
|
|
45
|
-
type inferParameters<PARAMETERS extends ToolParameters> = PARAMETERS extends Schema<any> ? PARAMETERS["_type"] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
|
66
|
+
type ToolParameters<T> = z.Schema<T> | Schema<T>;
|
|
46
67
|
export {};
|
|
47
68
|
//# sourceMappingURL=createTool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTool.d.ts","sourceRoot":"","sources":["../../src/client/createTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"createTool.d.ts","sourceRoot":"","sources":["../../src/client/createTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAEjE,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAC3B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,MAAM,OAAO,CAAC,SAAS,SAAS,gBAAgB,GAAG,gBAAgB,IACvE,gBAAgB,CAAC,SAAS,CAAC,GAAG;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEJ;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,OAAO,GAAG,OAAO,EAAE,GAAG,EAAE;IAC5E;;;;SAIK;IACL,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;SAIK;IACL,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;IAC5B;;;;;;SAMK;IACL,OAAO,EAAE,CACP,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,eAAe,KACrB,WAAW,CAAC,MAAM,CAAC,CAAC;IACzB;;OAEG;IACH,GAAG,CAAC,EAAE,GAAG,CAAC;IACV;;;OAGG;IACH,YAAY,CAAC,EAAE,CACb,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,eAAe,KACrB,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC9B;;;OAGG;IACH,YAAY,CAAC,EAAE,CACb,GAAG,EAAE,GAAG,EACR,OAAO,EAAE;QACP,cAAc,EAAE,MAAM,CAAC;KACxB,GAAG,eAAe,KAChB,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC9B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CACjB,GAAG,EAAE,GAAG,EACR,OAAO,EAAE;QACP,KAAK,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC;KACpD,GAAG,eAAe,KAChB,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAG9B,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CA6BtB;AAOD,wBAAgB,SAAS,CACvB,GAAG,EAAE,OAAO,EACZ,GAAG,QAAQ,EAAE,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,GACnC,OAAO,CAiBT;AAGD,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { tool } from "ai";
|
|
2
|
-
import { z } from "zod";
|
|
2
|
+
import { z } from "zod/v3";
|
|
3
3
|
/**
|
|
4
4
|
* This is a wrapper around the ai.tool function that adds extra context to the
|
|
5
5
|
* tool call, including the action context, userId, threadId, and messageId.
|
|
@@ -7,22 +7,37 @@ import { z } from "zod";
|
|
|
7
7
|
* but swap parameters for args and handler for execute.
|
|
8
8
|
* @returns A tool to be used with the AI SDK.
|
|
9
9
|
*/
|
|
10
|
-
export function createTool(
|
|
11
|
-
const
|
|
10
|
+
export function createTool(def) {
|
|
11
|
+
const t = tool({
|
|
12
|
+
type: "function",
|
|
12
13
|
__acceptsCtx: true,
|
|
13
|
-
ctx:
|
|
14
|
-
description:
|
|
15
|
-
|
|
14
|
+
ctx: def.ctx,
|
|
15
|
+
description: def.description,
|
|
16
|
+
inputSchema: def.args,
|
|
16
17
|
async execute(args, options) {
|
|
17
|
-
if (!this
|
|
18
|
+
if (!getCtx(this)) {
|
|
18
19
|
throw new Error("To use a Convex tool, you must either provide the ctx" +
|
|
19
20
|
" at definition time (dynamically in an action), or use the Agent to" +
|
|
20
21
|
" call it (which injects the ctx, userId and threadId)");
|
|
21
22
|
}
|
|
22
|
-
return
|
|
23
|
+
return def.handler(getCtx(this), args, options);
|
|
23
24
|
},
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
providerOptions: def.providerOptions,
|
|
26
|
+
});
|
|
27
|
+
if (def.onInputStart) {
|
|
28
|
+
t.onInputStart = def.onInputStart.bind(t, getCtx(t));
|
|
29
|
+
}
|
|
30
|
+
if (def.onInputDelta) {
|
|
31
|
+
t.onInputDelta = def.onInputDelta.bind(t, getCtx(t));
|
|
32
|
+
}
|
|
33
|
+
if (def.onInputAvailable) {
|
|
34
|
+
t.onInputAvailable = def.onInputAvailable.bind(t, getCtx(t));
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
function getCtx(tool) {
|
|
40
|
+
return tool.ctx;
|
|
26
41
|
}
|
|
27
42
|
export function wrapTools(ctx, ...toolSets) {
|
|
28
43
|
const output = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTool.js","sourceRoot":"","sources":["../../src/client/createTool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,
|
|
1
|
+
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AAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,8DAA8D;AAC9D,SAAS,MAAM,CAAsB,IAAS;IAC5C,OAAQ,IAAqB,CAAC,GAAG,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,GAAY,EACZ,GAAG,QAAiC;IAEpC,MAAM,MAAM,GAAG,EAAa,CAAC;IAC7B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,SAAS;QACX,CAAC;QACD,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,8DAA8D;YAC9D,IAAI,CAAE,IAAY,CAAC,YAAY,EAAE,CAAC;gBAChC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,CAAC;gBAC7B,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AgentComponent } from "./types.js";
|
|
2
|
+
export type CustomComponent = {
|
|
3
|
+
/**
|
|
4
|
+
* If you have a custom name for the agent component, you can pass it here
|
|
5
|
+
* as components.myAgentName.
|
|
6
|
+
*/
|
|
7
|
+
component?: AgentComponent;
|
|
8
|
+
};
|
|
9
|
+
export declare function componentAPI(args?: CustomComponent): AgentComponent;
|
|
10
|
+
export declare const defaultComponent: AgentComponent;
|
|
11
|
+
//# sourceMappingURL=defaultComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultComponent.d.ts","sourceRoot":"","sources":["../../src/client/defaultComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,SAAS,CAAC,EAAE,cAAc,CAAC;CAC5B,CAAC;AAEF,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,eAAe,GAAG,cAAc,CAEnE;AAED,eAAO,MAAM,gBAAgB,EACN,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultComponent.js","sourceRoot":"","sources":["../../src/client/defaultComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAWlD,MAAM,UAAU,YAAY,CAAC,IAAsB;IACjD,OAAO,IAAI,EAAE,SAAS,IAAI,gBAAgB,CAAC;AAC7C,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,EAAE;KAChD,KAAkC,CAAC"}
|