@convex-dev/agent 0.6.0-alpha.0 → 0.6.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 (192) hide show
  1. package/MIGRATION.md +153 -0
  2. package/package.json +4 -2
  3. package/src/UIMessages.ts +135 -0
  4. package/src/client/approval.test.ts +350 -0
  5. package/src/client/createTool.ts +50 -52
  6. package/src/client/index.ts +162 -1
  7. package/src/client/mockModel.ts +9 -2
  8. package/src/client/search.test.ts +4 -5
  9. package/src/client/search.ts +47 -2
  10. package/src/client/start.ts +41 -24
  11. package/src/client/streamText.ts +27 -3
  12. package/src/client/streaming.integration.test.ts +1206 -0
  13. package/src/client/streaming.ts +41 -12
  14. package/src/client/types.ts +14 -12
  15. package/src/component/_generated/component.ts +53 -64
  16. package/src/component/messages.ts +12 -2
  17. package/src/deltas.ts +0 -1
  18. package/src/mapping.test.ts +143 -1
  19. package/src/mapping.ts +115 -6
  20. package/src/react/useDeltaStreams.ts +6 -0
  21. package/dist/UIMessages.d.ts +0 -46
  22. package/dist/UIMessages.d.ts.map +0 -1
  23. package/dist/UIMessages.js +0 -546
  24. package/dist/UIMessages.js.map +0 -1
  25. package/dist/client/createTool.d.ts +0 -170
  26. package/dist/client/createTool.d.ts.map +0 -1
  27. package/dist/client/createTool.js +0 -115
  28. package/dist/client/createTool.js.map +0 -1
  29. package/dist/client/defaultComponent.d.ts +0 -11
  30. package/dist/client/defaultComponent.d.ts.map +0 -1
  31. package/dist/client/defaultComponent.js +0 -7
  32. package/dist/client/defaultComponent.js.map +0 -1
  33. package/dist/client/definePlaygroundAPI.d.ts +0 -1725
  34. package/dist/client/definePlaygroundAPI.d.ts.map +0 -1
  35. package/dist/client/definePlaygroundAPI.js +0 -271
  36. package/dist/client/definePlaygroundAPI.js.map +0 -1
  37. package/dist/client/files.d.ts +0 -69
  38. package/dist/client/files.d.ts.map +0 -1
  39. package/dist/client/files.js +0 -181
  40. package/dist/client/files.js.map +0 -1
  41. package/dist/client/index.d.ts +0 -2044
  42. package/dist/client/index.d.ts.map +0 -1
  43. package/dist/client/index.js +0 -804
  44. package/dist/client/index.js.map +0 -1
  45. package/dist/client/messages.d.ts +0 -461
  46. package/dist/client/messages.d.ts.map +0 -1
  47. package/dist/client/messages.js +0 -106
  48. package/dist/client/messages.js.map +0 -1
  49. package/dist/client/mockModel.d.ts +0 -42
  50. package/dist/client/mockModel.d.ts.map +0 -1
  51. package/dist/client/mockModel.js +0 -175
  52. package/dist/client/mockModel.js.map +0 -1
  53. package/dist/client/saveInputMessages.d.ts +0 -20
  54. package/dist/client/saveInputMessages.d.ts.map +0 -1
  55. package/dist/client/saveInputMessages.js +0 -58
  56. package/dist/client/saveInputMessages.js.map +0 -1
  57. package/dist/client/search.d.ts +0 -493
  58. package/dist/client/search.d.ts.map +0 -1
  59. package/dist/client/search.js +0 -425
  60. package/dist/client/search.js.map +0 -1
  61. package/dist/client/start.d.ts +0 -84
  62. package/dist/client/start.d.ts.map +0 -1
  63. package/dist/client/start.js +0 -171
  64. package/dist/client/start.js.map +0 -1
  65. package/dist/client/streamText.d.ts +0 -46
  66. package/dist/client/streamText.d.ts.map +0 -1
  67. package/dist/client/streamText.js +0 -93
  68. package/dist/client/streamText.js.map +0 -1
  69. package/dist/client/streaming.d.ts +0 -3767
  70. package/dist/client/streaming.d.ts.map +0 -1
  71. package/dist/client/streaming.js +0 -294
  72. package/dist/client/streaming.js.map +0 -1
  73. package/dist/client/threads.d.ts +0 -46
  74. package/dist/client/threads.d.ts.map +0 -1
  75. package/dist/client/threads.js +0 -49
  76. package/dist/client/threads.js.map +0 -1
  77. package/dist/client/types.d.ts +0 -460
  78. package/dist/client/types.d.ts.map +0 -1
  79. package/dist/client/types.js +0 -2
  80. package/dist/client/types.js.map +0 -1
  81. package/dist/client/utils.d.ts +0 -4
  82. package/dist/client/utils.d.ts.map +0 -1
  83. package/dist/client/utils.js +0 -21
  84. package/dist/client/utils.js.map +0 -1
  85. package/dist/component/_generated/api.d.ts +0 -48
  86. package/dist/component/_generated/api.d.ts.map +0 -1
  87. package/dist/component/_generated/api.js +0 -31
  88. package/dist/component/_generated/api.js.map +0 -1
  89. package/dist/component/_generated/component.d.ts +0 -3119
  90. package/dist/component/_generated/component.d.ts.map +0 -1
  91. package/dist/component/_generated/component.js +0 -11
  92. package/dist/component/_generated/component.js.map +0 -1
  93. package/dist/component/_generated/dataModel.d.ts +0 -46
  94. package/dist/component/_generated/dataModel.d.ts.map +0 -1
  95. package/dist/component/_generated/dataModel.js +0 -11
  96. package/dist/component/_generated/dataModel.js.map +0 -1
  97. package/dist/component/_generated/server.d.ts +0 -121
  98. package/dist/component/_generated/server.d.ts.map +0 -1
  99. package/dist/component/_generated/server.js +0 -78
  100. package/dist/component/_generated/server.js.map +0 -1
  101. package/dist/component/apiKeys.d.ts +0 -11
  102. package/dist/component/apiKeys.d.ts.map +0 -1
  103. package/dist/component/apiKeys.js +0 -69
  104. package/dist/component/apiKeys.js.map +0 -1
  105. package/dist/component/convex.config.d.ts +0 -3
  106. package/dist/component/convex.config.d.ts.map +0 -1
  107. package/dist/component/convex.config.js +0 -3
  108. package/dist/component/convex.config.js.map +0 -1
  109. package/dist/component/files.d.ts +0 -97
  110. package/dist/component/files.d.ts.map +0 -1
  111. package/dist/component/files.js +0 -190
  112. package/dist/component/files.js.map +0 -1
  113. package/dist/component/messages.d.ts +0 -3850
  114. package/dist/component/messages.d.ts.map +0 -1
  115. package/dist/component/messages.js +0 -747
  116. package/dist/component/messages.js.map +0 -1
  117. package/dist/component/schema.d.ts +0 -8026
  118. package/dist/component/schema.d.ts.map +0 -1
  119. package/dist/component/schema.js +0 -147
  120. package/dist/component/schema.js.map +0 -1
  121. package/dist/component/streams.d.ts +0 -128
  122. package/dist/component/streams.d.ts.map +0 -1
  123. package/dist/component/streams.js +0 -413
  124. package/dist/component/streams.js.map +0 -1
  125. package/dist/component/threads.d.ts +0 -115
  126. package/dist/component/threads.d.ts.map +0 -1
  127. package/dist/component/threads.js +0 -208
  128. package/dist/component/threads.js.map +0 -1
  129. package/dist/component/users.d.ts +0 -52
  130. package/dist/component/users.d.ts.map +0 -1
  131. package/dist/component/users.js +0 -229
  132. package/dist/component/users.js.map +0 -1
  133. package/dist/component/vector/index.d.ts +0 -61
  134. package/dist/component/vector/index.d.ts.map +0 -1
  135. package/dist/component/vector/index.js +0 -146
  136. package/dist/component/vector/index.js.map +0 -1
  137. package/dist/component/vector/tables.d.ts +0 -58
  138. package/dist/component/vector/tables.d.ts.map +0 -1
  139. package/dist/component/vector/tables.js +0 -56
  140. package/dist/component/vector/tables.js.map +0 -1
  141. package/dist/deltas.d.ts +0 -43
  142. package/dist/deltas.d.ts.map +0 -1
  143. package/dist/deltas.js +0 -447
  144. package/dist/deltas.js.map +0 -1
  145. package/dist/mapping.d.ts +0 -54
  146. package/dist/mapping.d.ts.map +0 -1
  147. package/dist/mapping.js +0 -626
  148. package/dist/mapping.js.map +0 -1
  149. package/dist/react/SmoothText.d.ts +0 -5
  150. package/dist/react/SmoothText.d.ts.map +0 -1
  151. package/dist/react/SmoothText.js +0 -6
  152. package/dist/react/SmoothText.js.map +0 -1
  153. package/dist/react/index.d.ts +0 -25
  154. package/dist/react/index.d.ts.map +0 -1
  155. package/dist/react/index.js +0 -70
  156. package/dist/react/index.js.map +0 -1
  157. package/dist/react/optimisticallySendMessage.d.ts +0 -42
  158. package/dist/react/optimisticallySendMessage.d.ts.map +0 -1
  159. package/dist/react/optimisticallySendMessage.js +0 -74
  160. package/dist/react/optimisticallySendMessage.js.map +0 -1
  161. package/dist/react/types.d.ts +0 -12
  162. package/dist/react/types.d.ts.map +0 -1
  163. package/dist/react/types.js +0 -2
  164. package/dist/react/types.js.map +0 -1
  165. package/dist/react/useDeltaStreams.d.ts +0 -10
  166. package/dist/react/useDeltaStreams.d.ts.map +0 -1
  167. package/dist/react/useDeltaStreams.js +0 -101
  168. package/dist/react/useDeltaStreams.js.map +0 -1
  169. package/dist/react/useSmoothText.d.ts +0 -27
  170. package/dist/react/useSmoothText.d.ts.map +0 -1
  171. package/dist/react/useSmoothText.js +0 -68
  172. package/dist/react/useSmoothText.js.map +0 -1
  173. package/dist/react/useStreamingUIMessages.d.ts +0 -22
  174. package/dist/react/useStreamingUIMessages.d.ts.map +0 -1
  175. package/dist/react/useStreamingUIMessages.js +0 -92
  176. package/dist/react/useStreamingUIMessages.js.map +0 -1
  177. package/dist/react/useThreadMessages.d.ts +0 -104
  178. package/dist/react/useThreadMessages.d.ts.map +0 -1
  179. package/dist/react/useThreadMessages.js +0 -148
  180. package/dist/react/useThreadMessages.js.map +0 -1
  181. package/dist/react/useUIMessages.d.ts +0 -96
  182. package/dist/react/useUIMessages.d.ts.map +0 -1
  183. package/dist/react/useUIMessages.js +0 -108
  184. package/dist/react/useUIMessages.js.map +0 -1
  185. package/dist/shared.d.ts +0 -26
  186. package/dist/shared.d.ts.map +0 -1
  187. package/dist/shared.js +0 -67
  188. package/dist/shared.js.map +0 -1
  189. package/dist/validators.d.ts +0 -24516
  190. package/dist/validators.d.ts.map +0 -1
  191. package/dist/validators.js +0 -475
  192. package/dist/validators.js.map +0 -1
@@ -1,170 +0,0 @@
1
- import type { ToolResultOutput } from "@ai-sdk/provider-utils";
2
- import type { FlexibleSchema, ModelMessage, Tool, ToolExecutionOptions, ToolSet } from "ai";
3
- import type { GenericActionCtx, GenericDataModel } from "convex/server";
4
- import type { ProviderOptions } from "../validators.js";
5
- import type { Agent } from "./index.js";
6
- export type ToolCtx<DataModel extends GenericDataModel = GenericDataModel> = GenericActionCtx<DataModel> & {
7
- agent?: Agent;
8
- userId?: string;
9
- threadId?: string;
10
- messageId?: string;
11
- };
12
- /**
13
- * Function that is called to determine if the tool needs approval before it can be executed.
14
- */
15
- export type ToolNeedsApprovalFunctionCtx<INPUT, Ctx extends ToolCtx = ToolCtx> = (ctx: Ctx, input: INPUT, options: {
16
- /**
17
- * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
18
- */
19
- toolCallId: string;
20
- /**
21
- * Messages that were sent to the language model to initiate the response that contained the tool call.
22
- * The messages **do not** include the system prompt nor the assistant response that contained the tool call.
23
- */
24
- messages: ModelMessage[];
25
- /**
26
- * Additional context.
27
- *
28
- * Experimental (can break in patch releases).
29
- */
30
- experimental_context?: unknown;
31
- }) => boolean | PromiseLike<boolean>;
32
- export type ToolExecuteFunctionCtx<INPUT, OUTPUT, Ctx extends ToolCtx = ToolCtx> = (ctx: Ctx, input: INPUT, options: ToolExecutionOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT>;
33
- type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
34
- export type ToolOutputPropertiesCtx<INPUT, OUTPUT, Ctx extends ToolCtx = ToolCtx> = NeverOptional<OUTPUT, {
35
- /**
36
- * An async function that is called with the arguments from the tool call and produces a result.
37
- * If `execute` (or `handler`) is not provided, the tool will not be executed automatically.
38
- *
39
- * @param input - The input of the tool call.
40
- * @param options.abortSignal - A signal that can be used to abort the tool call.
41
- */
42
- execute: ToolExecuteFunctionCtx<INPUT, OUTPUT, Ctx>;
43
- outputSchema?: FlexibleSchema<OUTPUT>;
44
- handler?: never;
45
- } | {
46
- /** @deprecated Use execute instead. */
47
- handler: ToolExecuteFunctionCtx<INPUT, OUTPUT, Ctx>;
48
- outputSchema?: FlexibleSchema<OUTPUT>;
49
- execute?: never;
50
- } | {
51
- outputSchema: FlexibleSchema<OUTPUT>;
52
- execute?: never;
53
- handler?: never;
54
- }>;
55
- export type ToolInputProperties<INPUT> = {
56
- /**
57
- * The schema of the input that the tool expects.
58
- * The language model will use this to generate the input.
59
- * It is also used to validate the output of the language model.
60
- *
61
- * You can use descriptions on the schema properties to make the input understandable for the language model.
62
- */
63
- inputSchema: FlexibleSchema<INPUT>;
64
- args?: never;
65
- } | {
66
- /**
67
- * The schema of the input that the tool expects. The language model will use this to generate the input.
68
- * It is also used to validate the output of the language model.
69
- * Use descriptions to make the input understandable for the language model.
70
- *
71
- * @deprecated Use inputSchema instead.
72
- */
73
- args: FlexibleSchema<INPUT>;
74
- inputSchema?: never;
75
- };
76
- /**
77
- * This is a wrapper around the ai.tool function that adds extra context to the
78
- * tool call, including the action context, userId, threadId, and messageId.
79
- * @param tool The tool. See https://sdk.vercel.ai/docs/ai-sdk-core/tools-and-tool-calling
80
- * Currently contains deprecated parameters `args` and `handler` to maintain backwards compatibility
81
- * but these will be removed in the future. Use `inputSchema` and `execute` instead, respectively.
82
- *
83
- * @returns A tool to be used with the AI SDK.
84
- */
85
- export declare function createTool<INPUT, OUTPUT, Ctx extends ToolCtx = ToolCtx>(def: {
86
- /**
87
- * An optional description of what the tool does.
88
- * Will be used by the language model to decide whether to use the tool.
89
- * Not used for provider-defined tools.
90
- */
91
- description?: string;
92
- /**
93
- * An optional title of the tool.
94
- */
95
- title?: string;
96
- /**
97
- * Additional provider-specific metadata. They are passed through
98
- * to the provider from the AI SDK and enable provider-specific
99
- * functionality that can be fully encapsulated in the provider.
100
- */
101
- providerOptions?: ProviderOptions;
102
- } & ToolInputProperties<INPUT> & {
103
- /**
104
- * An optional list of input examples that show the language
105
- * model what the input should look like.
106
- */
107
- inputExamples?: Array<{
108
- input: NoInfer<INPUT>;
109
- }>;
110
- /**
111
- * Whether the tool needs approval before it can be executed.
112
- */
113
- needsApproval?: boolean | ToolNeedsApprovalFunctionCtx<[
114
- INPUT
115
- ] extends [never] ? unknown : INPUT, Ctx>;
116
- /**
117
- * Strict mode setting for the tool.
118
- *
119
- * Providers that support strict mode will use this setting to determine
120
- * how the input should be generated. Strict mode will always produce
121
- * valid inputs, but it might limit what input schemas are supported.
122
- */
123
- strict?: boolean;
124
- /**
125
- * Provide the context to use, e.g. when defining the tool at runtime.
126
- */
127
- ctx?: Ctx;
128
- /**
129
- * Optional function that is called when the argument streaming starts.
130
- * Only called when the tool is used in a streaming context.
131
- */
132
- onInputStart?: (ctx: Ctx, options: ToolExecutionOptions) => void | PromiseLike<void>;
133
- /**
134
- * Optional function that is called when an argument streaming delta is available.
135
- * Only called when the tool is used in a streaming context.
136
- */
137
- onInputDelta?: (ctx: Ctx, options: {
138
- inputTextDelta: string;
139
- } & ToolExecutionOptions) => void | PromiseLike<void>;
140
- /**
141
- * Optional function that is called when a tool call can be started,
142
- * even if the execute function is not provided.
143
- */
144
- onInputAvailable?: (ctx: Ctx, options: {
145
- input: [INPUT] extends [never] ? unknown : INPUT;
146
- } & ToolExecutionOptions) => void | PromiseLike<void>;
147
- } & ToolOutputPropertiesCtx<INPUT, OUTPUT, Ctx> & {
148
- /**
149
- * Optional conversion function that maps the tool result to an output that can be used by the language model.
150
- *
151
- * If not provided, the tool result will be sent as a JSON object.
152
- */
153
- toModelOutput?: (ctx: Ctx, options: {
154
- /**
155
- * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
156
- */
157
- toolCallId: string;
158
- /**
159
- * The input of the tool call.
160
- */
161
- input: [INPUT] extends [never] ? unknown : INPUT;
162
- /**
163
- * The output of the tool call.
164
- */
165
- output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>;
166
- }) => ToolResultOutput | PromiseLike<ToolResultOutput>;
167
- }): Tool<INPUT, OUTPUT>;
168
- export declare function wrapTools(ctx: ToolCtx, ...toolSets: (ToolSet | undefined)[]): ToolSet;
169
- export {};
170
- //# sourceMappingURL=createTool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createTool.d.ts","sourceRoot":"","sources":["../../src/client/createTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACR,MAAM,IAAI,CAAC;AAEZ,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,M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,GACtB,GAAG,GACH,OAAO,CAAC,MAAM,CAAC,CAAC;KACvB,KACE,gBAAgB,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC;CACvD,GACF,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CA8FrB;AAMD,wBAAgB,SAAS,CACvB,GAAG,EAAE,OAAO,EACZ,GAAG,QAAQ,EAAE,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,GACnC,OAAO,CAgBT"}
@@ -1,115 +0,0 @@
1
- import { tool } from "ai";
2
- const MIGRATION_URL = "https://github.com/get-convex/agent/blob/main/MIGRATION.md";
3
- const warnedDeprecations = new Set();
4
- function warnDeprecation(key, message) {
5
- if (!warnedDeprecations.has(key)) {
6
- warnedDeprecations.add(key);
7
- console.warn(`[@convex-dev/agent] ${message}\n See: ${MIGRATION_URL}`);
8
- }
9
- }
10
- /**
11
- * This is a wrapper around the ai.tool function that adds extra context to the
12
- * tool call, including the action context, userId, threadId, and messageId.
13
- * @param tool The tool. See https://sdk.vercel.ai/docs/ai-sdk-core/tools-and-tool-calling
14
- * Currently contains deprecated parameters `args` and `handler` to maintain backwards compatibility
15
- * but these will be removed in the future. Use `inputSchema` and `execute` instead, respectively.
16
- *
17
- * @returns A tool to be used with the AI SDK.
18
- */
19
- export function createTool(def) {
20
- const inputSchema = def.inputSchema ?? def.args;
21
- if (!inputSchema)
22
- throw new Error("To use a Convex tool, you must provide an `inputSchema` (or `args`)");
23
- if (def.args && !def.inputSchema) {
24
- warnDeprecation("createTool.args", "createTool: 'args' is deprecated. Use 'inputSchema' instead.");
25
- }
26
- if (def.handler && !def.execute) {
27
- warnDeprecation("createTool.handler", "createTool: 'handler' is deprecated. Use 'execute' instead.");
28
- }
29
- const executeHandler = def.execute ?? def.handler;
30
- if (!executeHandler && !def.outputSchema)
31
- throw new Error("To use a Convex tool, you must either provide an execute" +
32
- " handler function, define an outputSchema, or both");
33
- const t = tool({
34
- type: "function",
35
- __acceptsCtx: true,
36
- ctx: def.ctx,
37
- description: def.description,
38
- title: def.title,
39
- providerOptions: def.providerOptions,
40
- inputSchema,
41
- inputExamples: def.inputExamples,
42
- needsApproval(input, options) {
43
- const needsApproval = def.needsApproval;
44
- if (!needsApproval || typeof needsApproval === "boolean")
45
- return Boolean(needsApproval);
46
- if (!getCtx(this)) {
47
- throw new Error("To use a Convex tool, you must either provide the ctx" +
48
- " at definition time (dynamically in an action), or use the Agent to" +
49
- " call it (which injects the ctx, userId and threadId)");
50
- }
51
- return needsApproval(getCtx(this), input, options);
52
- },
53
- strict: def.strict,
54
- ...(executeHandler
55
- ? {
56
- execute(input, options) {
57
- if (!getCtx(this)) {
58
- throw new Error("To use a Convex tool, you must either provide the ctx" +
59
- " at definition time (dynamically in an action), or use the Agent to" +
60
- " call it (which injects the ctx, userId and threadId)");
61
- }
62
- return executeHandler(getCtx(this), input, options);
63
- },
64
- }
65
- : {}),
66
- outputSchema: def.outputSchema,
67
- });
68
- if (def.onInputStart) {
69
- const origOnInputStart = def.onInputStart;
70
- t.onInputStart = function (options) {
71
- return origOnInputStart.call(this, getCtx(this), options);
72
- };
73
- }
74
- if (def.onInputDelta) {
75
- const origOnInputDelta = def.onInputDelta;
76
- t.onInputDelta = function (options) {
77
- return origOnInputDelta.call(this, getCtx(this), options);
78
- };
79
- }
80
- if (def.onInputAvailable) {
81
- const origOnInputAvailable = def.onInputAvailable;
82
- t.onInputAvailable = function (options) {
83
- return origOnInputAvailable.call(this, getCtx(this), options);
84
- };
85
- }
86
- if (def.toModelOutput) {
87
- const origToModelOutput = def.toModelOutput;
88
- t.toModelOutput = function (options) {
89
- return origToModelOutput.call(this, getCtx(this), options);
90
- };
91
- }
92
- return t;
93
- }
94
- function getCtx(tool) {
95
- return tool.ctx;
96
- }
97
- export function wrapTools(ctx, ...toolSets) {
98
- const output = {};
99
- for (const toolSet of toolSets) {
100
- if (!toolSet) {
101
- continue;
102
- }
103
- for (const [name, tool] of Object.entries(toolSet)) {
104
- if (tool && !tool.__acceptsCtx) {
105
- output[name] = tool;
106
- }
107
- else {
108
- const out = { ...tool, ctx };
109
- output[name] = out;
110
- }
111
- }
112
- }
113
- return output;
114
- }
115
- //# sourceMappingURL=createTool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createTool.js","sourceRoot":"","sources":["../../src/client/createTool.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAK1B,MAAM,aAAa,GAAG,4DAA4D,CAAC;AACnF,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;AAC7C,SAAS,eAAe,CAAC,GAAW,EAAE,OAAe;IACnD,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,uBAAuB,OAAO,YAAY,aAAa,EAAE,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AA6GD;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,GAmGG;IAEH,MAAM,WAAW,GAAG,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC;IAChD,IAAI,CAAC,WAAW;QACd,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IAEzF,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACjC,eAAe,CACb,iBAAiB,EACjB,8DAA8D,CAC/D,CAAC;IACJ,CAAC;IACD,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QAChC,eAAe,CACb,oBAAoB,EACpB,6DAA6D,CAC9D,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC;IAClD,IAAI,CAAC,cAAc,IAAI,CAAC,GAAG,CAAC,YAAY;QACtC,MAAM,IAAI,KA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M,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,IAAI,IAAI,IAAI,CAAE,IAAY,CAAC,YAAY,EAAE,CAAC;gBACxC,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"}
@@ -1,11 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,7 +0,0 @@
1
- import { componentsGeneric } from "convex/server";
2
- export function componentAPI(args) {
3
- return args?.component ?? defaultComponent;
4
- }
5
- export const defaultComponent = componentsGeneric()
6
- .agent;
7
- //# sourceMappingURL=defaultComponent.js.map
@@ -1 +0,0 @@
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"}