@convex-dev/agent 0.1.18 → 0.2.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/client/createTool.d.ts +30 -11
- package/dist/client/createTool.d.ts.map +1 -1
- package/dist/client/createTool.js +24 -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 +68 -23
- package/dist/client/definePlaygroundAPI.d.ts.map +1 -1
- package/dist/client/definePlaygroundAPI.js +7 -20
- package/dist/client/definePlaygroundAPI.js.map +1 -1
- package/dist/client/files.d.ts +14 -4
- package/dist/client/files.d.ts.map +1 -1
- package/dist/client/files.js +66 -11
- package/dist/client/files.js.map +1 -1
- package/dist/client/index.d.ts +323 -780
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +445 -543
- package/dist/client/index.js.map +1 -1
- package/dist/client/messages.d.ts +256 -0
- package/dist/client/messages.d.ts.map +1 -0
- package/dist/client/messages.js +97 -0
- package/dist/client/messages.js.map +1 -0
- package/dist/client/search.d.ts +35 -12
- package/dist/client/search.d.ts.map +1 -1
- package/dist/client/search.js +21 -4
- package/dist/client/search.js.map +1 -1
- package/dist/client/streaming.d.ts +21 -21
- package/dist/client/streaming.d.ts.map +1 -1
- package/dist/client/streaming.js +35 -40
- 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 +159 -75
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/_generated/api.d.ts +261 -209
- package/dist/component/messages.d.ts +314 -105
- package/dist/component/messages.d.ts.map +1 -1
- package/dist/component/messages.js +141 -83
- package/dist/component/messages.js.map +1 -1
- package/dist/component/schema.d.ts +631 -870
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/schema.js +11 -16
- package/dist/component/schema.js.map +1 -1
- package/dist/component/streams.d.ts +29 -149
- package/dist/component/streams.d.ts.map +1 -1
- package/dist/component/streams.js +104 -60
- package/dist/component/streams.js.map +1 -1
- package/dist/component/threads.d.ts +4 -4
- package/dist/component/users.d.ts +3 -3
- package/dist/mapping.d.ts +15 -16
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +208 -62
- package/dist/mapping.js.map +1 -1
- package/dist/parts.d.ts +3 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +34 -0
- package/dist/parts.js.map +1 -0
- package/dist/react/SmoothText.d.ts +5 -0
- package/dist/react/SmoothText.d.ts.map +1 -0
- package/dist/react/SmoothText.js +6 -0
- package/dist/react/SmoothText.js.map +1 -0
- package/dist/react/deltas.d.ts +3 -5
- package/dist/react/deltas.d.ts.map +1 -1
- package/dist/react/deltas.js +89 -53
- package/dist/react/deltas.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +31 -11
- package/dist/react/index.js.map +1 -1
- package/dist/react/optimisticallySendMessage.d.ts.map +1 -1
- package/dist/react/optimisticallySendMessage.js +2 -8
- 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/react/useSmoothText.d.ts +13 -12
- package/dist/react/useSmoothText.d.ts.map +1 -1
- package/dist/react/useSmoothText.js +1 -1
- package/dist/react/useSmoothText.js.map +1 -1
- package/dist/validators.d.ts +751 -1464
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +39 -80
- package/dist/validators.js.map +1 -1
- package/package.json +34 -30
- package/src/client/createTool.ts +66 -40
- package/src/client/defaultComponent.ts +17 -0
- package/src/client/definePlaygroundAPI.ts +17 -31
- package/src/client/files.ts +94 -17
- package/src/client/index.test.ts +28 -38
- package/src/client/index.ts +785 -977
- package/src/client/messages.ts +205 -0
- package/src/client/search.ts +37 -10
- package/src/client/streaming.ts +53 -56
- package/src/client/threads.ts +78 -0
- package/src/client/types.ts +239 -131
- package/src/component/_generated/api.d.ts +261 -209
- package/src/component/messages.test.ts +182 -40
- package/src/component/messages.ts +165 -108
- package/src/component/schema.ts +11 -17
- package/src/component/streams.ts +180 -69
- package/src/mapping.ts +253 -96
- package/src/parts.ts +39 -0
- package/src/react/SmoothText.tsx +9 -0
- package/src/react/deltas.test.ts +38 -42
- package/src/react/deltas.ts +116 -65
- package/src/react/index.ts +35 -13
- package/src/react/optimisticallySendMessage.ts +2 -8
- package/src/react/toUIMessages.test.ts +154 -36
- package/src/react/toUIMessages.ts +136 -57
- package/src/react/useSmoothText.ts +14 -15
- package/src/validators.test.ts +1 -117
- package/src/validators.ts +57 -107
- 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
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { FlexibleSchema } from "@ai-sdk/provider-utils";
|
|
2
|
+
import type { Tool, ToolCallOptions, ToolSet } from "ai";
|
|
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: FlexibleSchema<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,31 @@ 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.ZodTypeAny | Schema<any>;
|
|
45
|
-
type inferParameters<PARAMETERS extends ToolParameters> = PARAMETERS extends Schema<any> ? PARAMETERS["_type"] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
|
46
|
-
export {};
|
|
47
66
|
//# 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,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAEzD,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,C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SAAS,CACvB,GAAG,EAAE,OAAO,EACZ,GAAG,QAAQ,EAAE,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,GACnC,OAAO,CAiBT"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { tool } from "ai";
|
|
2
|
-
import { z } from "zod";
|
|
3
2
|
/**
|
|
4
3
|
* This is a wrapper around the ai.tool function that adds extra context to the
|
|
5
4
|
* tool call, including the action context, userId, threadId, and messageId.
|
|
@@ -7,22 +6,37 @@ import { z } from "zod";
|
|
|
7
6
|
* but swap parameters for args and handler for execute.
|
|
8
7
|
* @returns A tool to be used with the AI SDK.
|
|
9
8
|
*/
|
|
10
|
-
export function createTool(
|
|
11
|
-
const
|
|
9
|
+
export function createTool(def) {
|
|
10
|
+
const t = tool({
|
|
11
|
+
type: "function",
|
|
12
12
|
__acceptsCtx: true,
|
|
13
|
-
ctx:
|
|
14
|
-
description:
|
|
15
|
-
|
|
13
|
+
ctx: def.ctx,
|
|
14
|
+
description: def.description,
|
|
15
|
+
inputSchema: def.args,
|
|
16
16
|
async execute(args, options) {
|
|
17
|
-
if (!this
|
|
17
|
+
if (!getCtx(this)) {
|
|
18
18
|
throw new Error("To use a Convex tool, you must either provide the ctx" +
|
|
19
19
|
" at definition time (dynamically in an action), or use the Agent to" +
|
|
20
20
|
" call it (which injects the ctx, userId and threadId)");
|
|
21
21
|
}
|
|
22
|
-
return
|
|
22
|
+
return def.handler(getCtx(this), args, options);
|
|
23
23
|
},
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
providerOptions: def.providerOptions,
|
|
25
|
+
});
|
|
26
|
+
if (def.onInputStart) {
|
|
27
|
+
t.onInputStart = def.onInputStart.bind(t, getCtx(t));
|
|
28
|
+
}
|
|
29
|
+
if (def.onInputDelta) {
|
|
30
|
+
t.onInputDelta = def.onInputDelta.bind(t, getCtx(t));
|
|
31
|
+
}
|
|
32
|
+
if (def.onInputAvailable) {
|
|
33
|
+
t.onInputAvailable = def.onInputAvailable.bind(t, getCtx(t));
|
|
34
|
+
}
|
|
35
|
+
return t;
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
function getCtx(tool) {
|
|
39
|
+
return tool.ctx;
|
|
26
40
|
}
|
|
27
41
|
export function wrapTools(ctx, ...toolSets) {
|
|
28
42
|
const output = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTool.js","sourceRoot":"","sources":["../../src/client/createTool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createTool.js","sourceRoot":"","sources":["../../src/client/createTool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAa1B;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAA+C,GA0DxE;IACC,MAAM,CAAC,GAAG,IAAI,CAAC;QACb,IAAI,EAAE,UAAU;QAChB,YAAY,EAAE,IAAI;QAClB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,WAAW,EAAE,GAAG,CAAC,IAAI;QACrB,KAAK,CAAC,OAAO,CAAC,IAAW,EAAE,OAAwB;YACjD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CACb,uDAAuD;oBACrD,qEAAqE;oBACrE,uDAAuD,CAC1D,CAAC;YACJ,CAAC;YACD,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC;QACD,eAAe,EAAE,GAAG,CAAC,eAAe;KACrC,CAAC,CAAC;IACH,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;QACrB,CAAC,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;QACrB,CAAC,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACzB,CAAC,CAAC,gBAAgB,GAAG,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type
|
|
1
|
+
import { type ApiFromModules, type GenericActionCtx, type GenericDataModel, type GenericQueryCtx } from "convex/server";
|
|
2
|
+
import { type Agent, type AgentComponent } from "./index.js";
|
|
3
3
|
export type PlaygroundAPI = ApiFromModules<{
|
|
4
4
|
playground: ReturnType<typeof definePlaygroundAPI>;
|
|
5
5
|
}>["playground"];
|
|
@@ -118,6 +118,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
118
118
|
} | {
|
|
119
119
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
120
120
|
signature?: string | undefined;
|
|
121
|
+
state?: "streaming" | "done" | undefined;
|
|
121
122
|
type: "reasoning";
|
|
122
123
|
text: string;
|
|
123
124
|
} | {
|
|
@@ -126,6 +127,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
126
127
|
data: string;
|
|
127
128
|
} | {
|
|
128
129
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
130
|
+
providerExecuted?: boolean | undefined;
|
|
129
131
|
type: "tool-call";
|
|
130
132
|
toolCallId: string;
|
|
131
133
|
toolName: string;
|
|
@@ -137,6 +139,8 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
137
139
|
content: {
|
|
138
140
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
139
141
|
args?: any;
|
|
142
|
+
providerExecuted?: boolean | undefined;
|
|
143
|
+
isError?: boolean | undefined;
|
|
140
144
|
experimental_content?: ({
|
|
141
145
|
type: "text";
|
|
142
146
|
text: string;
|
|
@@ -145,7 +149,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
145
149
|
type: "image";
|
|
146
150
|
data: string;
|
|
147
151
|
})[] | undefined;
|
|
148
|
-
isError?: boolean | undefined;
|
|
149
152
|
type: "tool-result";
|
|
150
153
|
toolCallId: string;
|
|
151
154
|
toolName: string;
|
|
@@ -159,25 +162,28 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
159
162
|
text?: string | undefined;
|
|
160
163
|
reasoning?: string | undefined;
|
|
161
164
|
usage?: {
|
|
165
|
+
reasoningTokens?: number | undefined;
|
|
166
|
+
cachedInputTokens?: number | undefined;
|
|
162
167
|
promptTokens: number;
|
|
163
168
|
completionTokens: number;
|
|
164
169
|
totalTokens: number;
|
|
165
170
|
} | undefined;
|
|
166
171
|
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
167
|
-
sources?: {
|
|
172
|
+
sources?: ({
|
|
168
173
|
title?: string | undefined;
|
|
174
|
+
type?: "source" | undefined;
|
|
169
175
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
170
176
|
id: string;
|
|
171
177
|
sourceType: "url";
|
|
172
178
|
url: string;
|
|
173
|
-
}[] | undefined;
|
|
174
|
-
reasoningDetails?: ({
|
|
175
|
-
signature?: string | undefined;
|
|
176
|
-
type: "text";
|
|
177
|
-
text: string;
|
|
178
179
|
} | {
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
filename?: string | undefined;
|
|
181
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
182
|
+
id: string;
|
|
183
|
+
title: string;
|
|
184
|
+
type: "source";
|
|
185
|
+
sourceType: "document";
|
|
186
|
+
mediaType: string;
|
|
181
187
|
})[] | undefined;
|
|
182
188
|
warnings?: ({
|
|
183
189
|
details?: string | undefined;
|
|
@@ -192,6 +198,20 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
192
198
|
message: string;
|
|
193
199
|
})[] | undefined;
|
|
194
200
|
finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
|
|
201
|
+
reasoningDetails?: ({
|
|
202
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
203
|
+
signature?: string | undefined;
|
|
204
|
+
state?: "streaming" | "done" | undefined;
|
|
205
|
+
type: "reasoning";
|
|
206
|
+
text: string;
|
|
207
|
+
} | {
|
|
208
|
+
signature?: string | undefined;
|
|
209
|
+
type: "text";
|
|
210
|
+
text: string;
|
|
211
|
+
} | {
|
|
212
|
+
type: "redacted";
|
|
213
|
+
data: string;
|
|
214
|
+
})[] | undefined;
|
|
195
215
|
_id: string;
|
|
196
216
|
_creationTime: number;
|
|
197
217
|
status: "pending" | "success" | "failed";
|
|
@@ -209,7 +229,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
209
229
|
instructions: string | undefined;
|
|
210
230
|
contextOptions: import("./types.js").ContextOptions | undefined;
|
|
211
231
|
storageOptions: import("./types.js").StorageOptions | undefined;
|
|
212
|
-
maxSteps: number | undefined;
|
|
213
232
|
maxRetries: number | undefined;
|
|
214
233
|
tools: string[];
|
|
215
234
|
}[]>>;
|
|
@@ -259,6 +278,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
259
278
|
} | {
|
|
260
279
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
261
280
|
signature?: string | undefined;
|
|
281
|
+
state?: "streaming" | "done" | undefined;
|
|
262
282
|
type: "reasoning";
|
|
263
283
|
text: string;
|
|
264
284
|
} | {
|
|
@@ -267,6 +287,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
267
287
|
data: string;
|
|
268
288
|
} | {
|
|
269
289
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
290
|
+
providerExecuted?: boolean | undefined;
|
|
270
291
|
type: "tool-call";
|
|
271
292
|
toolCallId: string;
|
|
272
293
|
toolName: string;
|
|
@@ -278,6 +299,8 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
278
299
|
content: {
|
|
279
300
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
280
301
|
args?: any;
|
|
302
|
+
providerExecuted?: boolean | undefined;
|
|
303
|
+
isError?: boolean | undefined;
|
|
281
304
|
experimental_content?: ({
|
|
282
305
|
type: "text";
|
|
283
306
|
text: string;
|
|
@@ -286,7 +309,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
286
309
|
type: "image";
|
|
287
310
|
data: string;
|
|
288
311
|
})[] | undefined;
|
|
289
|
-
isError?: boolean | undefined;
|
|
290
312
|
type: "tool-result";
|
|
291
313
|
toolCallId: string;
|
|
292
314
|
toolName: string;
|
|
@@ -364,6 +386,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
364
386
|
} | {
|
|
365
387
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
366
388
|
signature?: string | undefined;
|
|
389
|
+
state?: "streaming" | "done" | undefined;
|
|
367
390
|
type: "reasoning";
|
|
368
391
|
text: string;
|
|
369
392
|
} | {
|
|
@@ -372,6 +395,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
372
395
|
data: string;
|
|
373
396
|
} | {
|
|
374
397
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
398
|
+
providerExecuted?: boolean | undefined;
|
|
375
399
|
type: "tool-call";
|
|
376
400
|
toolCallId: string;
|
|
377
401
|
toolName: string;
|
|
@@ -383,6 +407,8 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
383
407
|
content: {
|
|
384
408
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
385
409
|
args?: any;
|
|
410
|
+
providerExecuted?: boolean | undefined;
|
|
411
|
+
isError?: boolean | undefined;
|
|
386
412
|
experimental_content?: ({
|
|
387
413
|
type: "text";
|
|
388
414
|
text: string;
|
|
@@ -391,7 +417,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
391
417
|
type: "image";
|
|
392
418
|
data: string;
|
|
393
419
|
})[] | undefined;
|
|
394
|
-
isError?: boolean | undefined;
|
|
395
420
|
type: "tool-result";
|
|
396
421
|
toolCallId: string;
|
|
397
422
|
toolName: string;
|
|
@@ -463,6 +488,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
463
488
|
} | {
|
|
464
489
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
465
490
|
signature?: string | undefined;
|
|
491
|
+
state?: "streaming" | "done" | undefined;
|
|
466
492
|
type: "reasoning";
|
|
467
493
|
text: string;
|
|
468
494
|
} | {
|
|
@@ -471,6 +497,7 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
471
497
|
data: string;
|
|
472
498
|
} | {
|
|
473
499
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
500
|
+
providerExecuted?: boolean | undefined;
|
|
474
501
|
type: "tool-call";
|
|
475
502
|
toolCallId: string;
|
|
476
503
|
toolName: string;
|
|
@@ -482,6 +509,8 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
482
509
|
content: {
|
|
483
510
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
484
511
|
args?: any;
|
|
512
|
+
providerExecuted?: boolean | undefined;
|
|
513
|
+
isError?: boolean | undefined;
|
|
485
514
|
experimental_content?: ({
|
|
486
515
|
type: "text";
|
|
487
516
|
text: string;
|
|
@@ -490,7 +519,6 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
490
519
|
type: "image";
|
|
491
520
|
data: string;
|
|
492
521
|
})[] | undefined;
|
|
493
|
-
isError?: boolean | undefined;
|
|
494
522
|
type: "tool-result";
|
|
495
523
|
toolCallId: string;
|
|
496
524
|
toolName: string;
|
|
@@ -504,25 +532,28 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
504
532
|
text?: string | undefined;
|
|
505
533
|
reasoning?: string | undefined;
|
|
506
534
|
usage?: {
|
|
535
|
+
reasoningTokens?: number | undefined;
|
|
536
|
+
cachedInputTokens?: number | undefined;
|
|
507
537
|
promptTokens: number;
|
|
508
538
|
completionTokens: number;
|
|
509
539
|
totalTokens: number;
|
|
510
540
|
} | undefined;
|
|
511
541
|
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
512
|
-
sources?: {
|
|
542
|
+
sources?: ({
|
|
513
543
|
title?: string | undefined;
|
|
544
|
+
type?: "source" | undefined;
|
|
514
545
|
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
515
546
|
id: string;
|
|
516
547
|
sourceType: "url";
|
|
517
548
|
url: string;
|
|
518
|
-
}[] | undefined;
|
|
519
|
-
reasoningDetails?: ({
|
|
520
|
-
signature?: string | undefined;
|
|
521
|
-
type: "text";
|
|
522
|
-
text: string;
|
|
523
549
|
} | {
|
|
524
|
-
|
|
525
|
-
|
|
550
|
+
filename?: string | undefined;
|
|
551
|
+
providerMetadata?: Record<string, Record<string, any>> | undefined;
|
|
552
|
+
id: string;
|
|
553
|
+
title: string;
|
|
554
|
+
type: "source";
|
|
555
|
+
sourceType: "document";
|
|
556
|
+
mediaType: string;
|
|
526
557
|
})[] | undefined;
|
|
527
558
|
warnings?: ({
|
|
528
559
|
details?: string | undefined;
|
|
@@ -537,6 +568,20 @@ export declare function definePlaygroundAPI<DataModel extends GenericDataModel>(
|
|
|
537
568
|
message: string;
|
|
538
569
|
})[] | undefined;
|
|
539
570
|
finishReason?: "length" | "error" | "other" | "stop" | "content-filter" | "tool-calls" | "unknown" | undefined;
|
|
571
|
+
reasoningDetails?: ({
|
|
572
|
+
providerOptions?: Record<string, Record<string, any>> | undefined;
|
|
573
|
+
signature?: string | undefined;
|
|
574
|
+
state?: "streaming" | "done" | undefined;
|
|
575
|
+
type: "reasoning";
|
|
576
|
+
text: string;
|
|
577
|
+
} | {
|
|
578
|
+
signature?: string | undefined;
|
|
579
|
+
type: "text";
|
|
580
|
+
text: string;
|
|
581
|
+
} | {
|
|
582
|
+
type: "redacted";
|
|
583
|
+
data: string;
|
|
584
|
+
})[] | undefined;
|
|
540
585
|
_id: string;
|
|
541
586
|
_creationTime: number;
|
|
542
587
|
status: "pending" | "success" | "failed";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definePlaygroundAPI.d.ts","sourceRoot":"","sources":["../../src/client/definePlaygroundAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,
|
|
1
|
+
{"version":3,"file":"definePlaygroundAPI.d.ts","sourceRoot":"","sources":["../../src/client/definePlaygroundAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,e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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgRF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { vMessageDoc, vThreadDoc, vPaginationResult, vMessage, vContextOptions, vStorageOptions, listMessages as listMessages_, createThread as createThread_, } from "./index.js";
|
|
1
|
+
import { actionGeneric, mutationGeneric, paginationOptsValidator, queryGeneric, } from "convex/server";
|
|
3
2
|
import { v } from "convex/values";
|
|
4
|
-
import { deserializeMessage } from "
|
|
3
|
+
import { createThread as createThread_, listMessages as listMessages_, deserializeMessage, vContextOptions, vMessage, vMessageDoc, vPaginationResult, vStorageOptions, vThreadDoc, } from "./index.js";
|
|
5
4
|
// Playground API definition
|
|
6
5
|
export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLookup, }) {
|
|
7
6
|
function validateAgents(agents) {
|
|
@@ -15,9 +14,7 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
|
|
|
15
14
|
await ctx.runQuery(component.apiKeys.validate, { apiKey });
|
|
16
15
|
}
|
|
17
16
|
const isApiKeyValid = queryGeneric({
|
|
18
|
-
args: {
|
|
19
|
-
apiKey: v.string(),
|
|
20
|
-
},
|
|
17
|
+
args: { apiKey: v.string() },
|
|
21
18
|
handler: async (ctx, args) => {
|
|
22
19
|
try {
|
|
23
20
|
await validateApiKey(ctx, args.apiKey);
|
|
@@ -57,17 +54,13 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
|
|
|
57
54
|
instructions: agent.options.instructions,
|
|
58
55
|
contextOptions: agent.options.contextOptions,
|
|
59
56
|
storageOptions: agent.options.storageOptions,
|
|
60
|
-
|
|
61
|
-
maxRetries: agent.options.maxRetries,
|
|
57
|
+
maxRetries: agent.options.callSettings?.maxRetries,
|
|
62
58
|
tools: agent.options.tools ? Object.keys(agent.options.tools) : [],
|
|
63
59
|
}));
|
|
64
60
|
},
|
|
65
61
|
});
|
|
66
62
|
const listUsers = queryGeneric({
|
|
67
|
-
args: {
|
|
68
|
-
apiKey: v.string(),
|
|
69
|
-
paginationOpts: paginationOptsValidator,
|
|
70
|
-
},
|
|
63
|
+
args: { apiKey: v.string(), paginationOpts: paginationOptsValidator },
|
|
71
64
|
handler: async (ctx, args) => {
|
|
72
65
|
await validateApiKey(ctx, args.apiKey);
|
|
73
66
|
const users = await ctx.runQuery(component.users.listUsersWithThreads, {
|
|
@@ -81,10 +74,7 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
|
|
|
81
74
|
}))),
|
|
82
75
|
};
|
|
83
76
|
},
|
|
84
|
-
returns: vPaginationResult(v.object({
|
|
85
|
-
_id: v.string(),
|
|
86
|
-
name: v.string(),
|
|
87
|
-
})),
|
|
77
|
+
returns: vPaginationResult(v.object({ _id: v.string(), name: v.string() })),
|
|
88
78
|
});
|
|
89
79
|
// List threads for a user (query)
|
|
90
80
|
const listThreads = queryGeneric({
|
|
@@ -106,10 +96,7 @@ export function definePlaygroundAPI(component, { agents: agentsOrFn, userNameLoo
|
|
|
106
96
|
const { page: [last], } = await ctx.runQuery(component.messages.listMessagesByThreadId, {
|
|
107
97
|
threadId: thread._id,
|
|
108
98
|
order: "desc",
|
|
109
|
-
paginationOpts: {
|
|
110
|
-
numItems: 1,
|
|
111
|
-
cursor: null,
|
|
112
|
-
},
|
|
99
|
+
paginationOpts: { numItems: 1, cursor: null },
|
|
113
100
|
});
|
|
114
101
|
return {
|
|
115
102
|
...thread,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definePlaygroundAPI.js","sourceRoot":"","sources":["../../src/client/definePlaygroundAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"definePlaygroundAPI.js","sourceRoot":"","sources":["../../src/client/definePlaygroundAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,YAAY,GAKb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EACL,YAAY,IAAI,aAAa,EAC7B,YAAY,IAAI,aAAa,EAC7B,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,UAAU,GAGX,MAAM,YAAY,CAAC;AAWpB,4BAA4B;AAC5B,MAAM,UAAU,mBAAmB,CACjC,SAAyB,EACzB,EACE,MAAM,EAAE,UAAU,EAClB,cAAc,GAOf;IAED,SAAS,cAAc,CAAC,MAAe;QACrC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;gBACxB,OAAO,CAAC,IAAI,CACV,oCAAoC,KAAK,CAAC,OAAO,CAAC,YAAY,GAAG,CAClE,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,UAAU,cAAc,CAAC,GAAgB,EAAE,MAAc;QAC5D,MAAM,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,aAAa,GAAG,YAAY,CAAC;QACjC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5B,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAC3B,IAAI,CAAC;gBACH,MAAM,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AC,GAAG,CAAC,CAAC;YAC9C,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,oBAAoB,CAAC,GAAG,EAAE;gBACrD,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC;gBAC/C,cAAc,EAAE,IAAI,CAAC,cAAc;gBACnC,yBAAyB,EAAE,IAAI,CAAC,eAAe;aAChD,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,CAAC,GAAG,KAAK,IAAI,CAAC,eAAe,CAC/D,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,aAAa;QACb,SAAS;QACT,WAAW;QACX,YAAY;QACZ,UAAU;QACV,YAAY;QACZ,YAAY;QACZ,kBAAkB;KACnB,CAAC;AACJ,CAAC"}
|
package/dist/client/files.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { FilePart, ImagePart } from "ai";
|
|
1
|
+
import type { FilePart, ImagePart, ModelMessage } from "ai";
|
|
2
2
|
import type { Id } from "../component/_generated/dataModel.js";
|
|
3
3
|
import type { ActionCtx, AgentComponent, QueryCtx, RunMutationCtx } from "./types.js";
|
|
4
|
+
import type { Message } from "../validators.js";
|
|
4
5
|
export declare const MAX_FILE_SIZE: number;
|
|
5
6
|
type File = {
|
|
6
7
|
url: string;
|
|
@@ -14,13 +15,16 @@ type File = {
|
|
|
14
15
|
* @param ctx A ctx object from an action.
|
|
15
16
|
* @param component The agent component.
|
|
16
17
|
* @param blob The blob to store.
|
|
17
|
-
* @param filename The filename to store.
|
|
18
|
-
* @param sha256 The sha256 hash of the file. If not provided, it will be
|
|
18
|
+
* @param args.filename The filename to store.
|
|
19
|
+
* @param args.sha256 The sha256 hash of the file. If not provided, it will be
|
|
19
20
|
* computed. However, to ensure no corruption during transfer, you can
|
|
20
21
|
* calculate this on the client to enforce integrity.
|
|
21
22
|
* @returns The URL, fileId, and storageId of the stored file.
|
|
22
23
|
*/
|
|
23
|
-
export declare function storeFile(ctx: ActionCtx | RunMutationCtx, component: AgentComponent, blob: Blob, filename
|
|
24
|
+
export declare function storeFile(ctx: ActionCtx | RunMutationCtx, component: AgentComponent, blob: Blob, { filename, sha256 }?: {
|
|
25
|
+
filename?: string;
|
|
26
|
+
sha256?: string;
|
|
27
|
+
}): Promise<{
|
|
24
28
|
file: File;
|
|
25
29
|
filePart: FilePart;
|
|
26
30
|
imagePart: ImagePart | undefined;
|
|
@@ -52,5 +56,11 @@ export declare function getFile(ctx: ActionCtx | QueryCtx, component: AgentCompo
|
|
|
52
56
|
filePart: FilePart;
|
|
53
57
|
imagePart: ImagePart | undefined;
|
|
54
58
|
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Process messages to inline file and image URLs that point to localhost
|
|
61
|
+
* by converting them to base64. This solves the problem of LLMs not being
|
|
62
|
+
* able to access localhost URLs.
|
|
63
|
+
*/
|
|
64
|
+
export declare function inlineMessagesFiles(messages: (ModelMessage | Message)[]): Promise<(ModelMessage | Message)[]>;
|
|
55
65
|
export {};
|
|
56
66
|
//# sourceMappingURL=files.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/client/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/client/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,QAAQ,EACR,SAAS,EACT,YAAY,EAEb,MAAM,IAAI,CAAC;AACZ,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,QAAQ,EACR,cAAc,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