@convex-dev/agent 0.6.0-alpha.1 → 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 (181) hide show
  1. package/package.json +1 -1
  2. package/src/UIMessages.ts +135 -0
  3. package/src/client/index.ts +56 -14
  4. package/src/client/search.test.ts +4 -5
  5. package/src/client/search.ts +45 -4
  6. package/src/client/streaming.integration.test.ts +1206 -0
  7. package/src/client/streaming.ts +9 -2
  8. package/src/mapping.test.ts +136 -71
  9. package/src/mapping.ts +81 -28
  10. package/dist/UIMessages.d.ts +0 -46
  11. package/dist/UIMessages.d.ts.map +0 -1
  12. package/dist/UIMessages.js +0 -546
  13. package/dist/UIMessages.js.map +0 -1
  14. package/dist/client/createTool.d.ts +0 -167
  15. package/dist/client/createTool.d.ts.map +0 -1
  16. package/dist/client/createTool.js +0 -116
  17. package/dist/client/createTool.js.map +0 -1
  18. package/dist/client/defaultComponent.d.ts +0 -11
  19. package/dist/client/defaultComponent.d.ts.map +0 -1
  20. package/dist/client/defaultComponent.js +0 -7
  21. package/dist/client/defaultComponent.js.map +0 -1
  22. package/dist/client/definePlaygroundAPI.d.ts +0 -1725
  23. package/dist/client/definePlaygroundAPI.d.ts.map +0 -1
  24. package/dist/client/definePlaygroundAPI.js +0 -271
  25. package/dist/client/definePlaygroundAPI.js.map +0 -1
  26. package/dist/client/files.d.ts +0 -69
  27. package/dist/client/files.d.ts.map +0 -1
  28. package/dist/client/files.js +0 -181
  29. package/dist/client/files.js.map +0 -1
  30. package/dist/client/index.d.ts +0 -2091
  31. package/dist/client/index.d.ts.map +0 -1
  32. package/dist/client/index.js +0 -895
  33. package/dist/client/index.js.map +0 -1
  34. package/dist/client/messages.d.ts +0 -461
  35. package/dist/client/messages.d.ts.map +0 -1
  36. package/dist/client/messages.js +0 -106
  37. package/dist/client/messages.js.map +0 -1
  38. package/dist/client/mockModel.d.ts +0 -42
  39. package/dist/client/mockModel.d.ts.map +0 -1
  40. package/dist/client/mockModel.js +0 -182
  41. package/dist/client/mockModel.js.map +0 -1
  42. package/dist/client/saveInputMessages.d.ts +0 -20
  43. package/dist/client/saveInputMessages.d.ts.map +0 -1
  44. package/dist/client/saveInputMessages.js +0 -58
  45. package/dist/client/saveInputMessages.js.map +0 -1
  46. package/dist/client/search.d.ts +0 -493
  47. package/dist/client/search.d.ts.map +0 -1
  48. package/dist/client/search.js +0 -425
  49. package/dist/client/search.js.map +0 -1
  50. package/dist/client/start.d.ts +0 -84
  51. package/dist/client/start.d.ts.map +0 -1
  52. package/dist/client/start.js +0 -185
  53. package/dist/client/start.js.map +0 -1
  54. package/dist/client/streamText.d.ts +0 -46
  55. package/dist/client/streamText.d.ts.map +0 -1
  56. package/dist/client/streamText.js +0 -117
  57. package/dist/client/streamText.js.map +0 -1
  58. package/dist/client/streaming.d.ts +0 -3778
  59. package/dist/client/streaming.d.ts.map +0 -1
  60. package/dist/client/streaming.js +0 -314
  61. package/dist/client/streaming.js.map +0 -1
  62. package/dist/client/threads.d.ts +0 -46
  63. package/dist/client/threads.d.ts.map +0 -1
  64. package/dist/client/threads.js +0 -49
  65. package/dist/client/threads.js.map +0 -1
  66. package/dist/client/types.d.ts +0 -461
  67. package/dist/client/types.d.ts.map +0 -1
  68. package/dist/client/types.js +0 -2
  69. package/dist/client/types.js.map +0 -1
  70. package/dist/client/utils.d.ts +0 -4
  71. package/dist/client/utils.d.ts.map +0 -1
  72. package/dist/client/utils.js +0 -21
  73. package/dist/client/utils.js.map +0 -1
  74. package/dist/component/_generated/api.d.ts +0 -48
  75. package/dist/component/_generated/api.d.ts.map +0 -1
  76. package/dist/component/_generated/api.js +0 -31
  77. package/dist/component/_generated/api.js.map +0 -1
  78. package/dist/component/_generated/component.d.ts +0 -3120
  79. package/dist/component/_generated/component.d.ts.map +0 -1
  80. package/dist/component/_generated/component.js +0 -11
  81. package/dist/component/_generated/component.js.map +0 -1
  82. package/dist/component/_generated/dataModel.d.ts +0 -46
  83. package/dist/component/_generated/dataModel.d.ts.map +0 -1
  84. package/dist/component/_generated/dataModel.js +0 -11
  85. package/dist/component/_generated/dataModel.js.map +0 -1
  86. package/dist/component/_generated/server.d.ts +0 -121
  87. package/dist/component/_generated/server.d.ts.map +0 -1
  88. package/dist/component/_generated/server.js +0 -78
  89. package/dist/component/_generated/server.js.map +0 -1
  90. package/dist/component/apiKeys.d.ts +0 -11
  91. package/dist/component/apiKeys.d.ts.map +0 -1
  92. package/dist/component/apiKeys.js +0 -69
  93. package/dist/component/apiKeys.js.map +0 -1
  94. package/dist/component/convex.config.d.ts +0 -3
  95. package/dist/component/convex.config.d.ts.map +0 -1
  96. package/dist/component/convex.config.js +0 -3
  97. package/dist/component/convex.config.js.map +0 -1
  98. package/dist/component/files.d.ts +0 -97
  99. package/dist/component/files.d.ts.map +0 -1
  100. package/dist/component/files.js +0 -190
  101. package/dist/component/files.js.map +0 -1
  102. package/dist/component/messages.d.ts +0 -3851
  103. package/dist/component/messages.d.ts.map +0 -1
  104. package/dist/component/messages.js +0 -757
  105. package/dist/component/messages.js.map +0 -1
  106. package/dist/component/schema.d.ts +0 -8026
  107. package/dist/component/schema.d.ts.map +0 -1
  108. package/dist/component/schema.js +0 -147
  109. package/dist/component/schema.js.map +0 -1
  110. package/dist/component/streams.d.ts +0 -128
  111. package/dist/component/streams.d.ts.map +0 -1
  112. package/dist/component/streams.js +0 -413
  113. package/dist/component/streams.js.map +0 -1
  114. package/dist/component/threads.d.ts +0 -115
  115. package/dist/component/threads.d.ts.map +0 -1
  116. package/dist/component/threads.js +0 -208
  117. package/dist/component/threads.js.map +0 -1
  118. package/dist/component/users.d.ts +0 -52
  119. package/dist/component/users.d.ts.map +0 -1
  120. package/dist/component/users.js +0 -229
  121. package/dist/component/users.js.map +0 -1
  122. package/dist/component/vector/index.d.ts +0 -61
  123. package/dist/component/vector/index.d.ts.map +0 -1
  124. package/dist/component/vector/index.js +0 -146
  125. package/dist/component/vector/index.js.map +0 -1
  126. package/dist/component/vector/tables.d.ts +0 -58
  127. package/dist/component/vector/tables.d.ts.map +0 -1
  128. package/dist/component/vector/tables.js +0 -56
  129. package/dist/component/vector/tables.js.map +0 -1
  130. package/dist/deltas.d.ts +0 -43
  131. package/dist/deltas.d.ts.map +0 -1
  132. package/dist/deltas.js +0 -446
  133. package/dist/deltas.js.map +0 -1
  134. package/dist/mapping.d.ts +0 -72
  135. package/dist/mapping.d.ts.map +0 -1
  136. package/dist/mapping.js +0 -677
  137. package/dist/mapping.js.map +0 -1
  138. package/dist/react/SmoothText.d.ts +0 -5
  139. package/dist/react/SmoothText.d.ts.map +0 -1
  140. package/dist/react/SmoothText.js +0 -6
  141. package/dist/react/SmoothText.js.map +0 -1
  142. package/dist/react/index.d.ts +0 -25
  143. package/dist/react/index.d.ts.map +0 -1
  144. package/dist/react/index.js +0 -70
  145. package/dist/react/index.js.map +0 -1
  146. package/dist/react/optimisticallySendMessage.d.ts +0 -42
  147. package/dist/react/optimisticallySendMessage.d.ts.map +0 -1
  148. package/dist/react/optimisticallySendMessage.js +0 -74
  149. package/dist/react/optimisticallySendMessage.js.map +0 -1
  150. package/dist/react/types.d.ts +0 -12
  151. package/dist/react/types.d.ts.map +0 -1
  152. package/dist/react/types.js +0 -2
  153. package/dist/react/types.js.map +0 -1
  154. package/dist/react/useDeltaStreams.d.ts +0 -10
  155. package/dist/react/useDeltaStreams.d.ts.map +0 -1
  156. package/dist/react/useDeltaStreams.js +0 -106
  157. package/dist/react/useDeltaStreams.js.map +0 -1
  158. package/dist/react/useSmoothText.d.ts +0 -27
  159. package/dist/react/useSmoothText.d.ts.map +0 -1
  160. package/dist/react/useSmoothText.js +0 -68
  161. package/dist/react/useSmoothText.js.map +0 -1
  162. package/dist/react/useStreamingUIMessages.d.ts +0 -22
  163. package/dist/react/useStreamingUIMessages.d.ts.map +0 -1
  164. package/dist/react/useStreamingUIMessages.js +0 -92
  165. package/dist/react/useStreamingUIMessages.js.map +0 -1
  166. package/dist/react/useThreadMessages.d.ts +0 -104
  167. package/dist/react/useThreadMessages.d.ts.map +0 -1
  168. package/dist/react/useThreadMessages.js +0 -148
  169. package/dist/react/useThreadMessages.js.map +0 -1
  170. package/dist/react/useUIMessages.d.ts +0 -96
  171. package/dist/react/useUIMessages.d.ts.map +0 -1
  172. package/dist/react/useUIMessages.js +0 -108
  173. package/dist/react/useUIMessages.js.map +0 -1
  174. package/dist/shared.d.ts +0 -26
  175. package/dist/shared.d.ts.map +0 -1
  176. package/dist/shared.js +0 -67
  177. package/dist/shared.js.map +0 -1
  178. package/dist/validators.d.ts +0 -24516
  179. package/dist/validators.d.ts.map +0 -1
  180. package/dist/validators.js +0 -475
  181. package/dist/validators.js.map +0 -1
@@ -1,167 +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
- /**
35
- * Error message type for deprecated 'handler' property.
36
- * Using a string literal type causes TypeScript to show this message in errors.
37
- */
38
- type HANDLER_REMOVED_ERROR = "⚠️ 'handler' was removed in @convex-dev/agent v0.6.0. Rename to 'execute'. See: node_modules/@convex-dev/agent/MIGRATION.md";
39
- export type ToolOutputPropertiesCtx<INPUT, OUTPUT, Ctx extends ToolCtx = ToolCtx> = NeverOptional<OUTPUT, {
40
- /**
41
- * An async function that is called with the arguments from the tool call and produces a result.
42
- * If `execute` is not provided, the tool will not be executed automatically.
43
- *
44
- * @param input - The input of the tool call.
45
- * @param options.abortSignal - A signal that can be used to abort the tool call.
46
- */
47
- execute?: ToolExecuteFunctionCtx<INPUT, OUTPUT, Ctx>;
48
- outputSchema?: FlexibleSchema<OUTPUT>;
49
- /**
50
- * @deprecated Removed in v0.6.0. Use `execute` instead.
51
- */
52
- handler?: HANDLER_REMOVED_ERROR;
53
- }>;
54
- /**
55
- * Error message type for deprecated 'args' property.
56
- * Using a string literal type causes TypeScript to show this message in errors.
57
- */
58
- type ARGS_REMOVED_ERROR = "⚠️ 'args' was removed in @convex-dev/agent v0.6.0. Rename to 'inputSchema'. See: node_modules/@convex-dev/agent/MIGRATION.md";
59
- export type ToolInputProperties<INPUT> = {
60
- /**
61
- * The schema of the input that the tool expects.
62
- * The language model will use this to generate the input.
63
- * It is also used to validate the output of the language model.
64
- *
65
- * You can use descriptions on the schema properties to make the input understandable for the language model.
66
- */
67
- inputSchema: FlexibleSchema<INPUT>;
68
- /**
69
- * @deprecated Removed in v0.6.0. Use `inputSchema` instead.
70
- */
71
- args?: ARGS_REMOVED_ERROR;
72
- };
73
- /**
74
- * This is a wrapper around the ai.tool function that adds extra context to the
75
- * tool call, including the action context, userId, threadId, and messageId.
76
- * @param tool The tool. See https://sdk.vercel.ai/docs/ai-sdk-core/tools-and-tool-calling
77
- * Currently contains deprecated parameters `args` and `handler` to maintain backwards compatibility
78
- * but these will be removed in the future. Use `inputSchema` and `execute` instead, respectively.
79
- *
80
- * @returns A tool to be used with the AI SDK.
81
- */
82
- export declare function createTool<INPUT, OUTPUT, Ctx extends ToolCtx = ToolCtx>(def: {
83
- /**
84
- * An optional description of what the tool does.
85
- * Will be used by the language model to decide whether to use the tool.
86
- * Not used for provider-defined tools.
87
- */
88
- description?: string;
89
- /**
90
- * An optional title of the tool.
91
- */
92
- title?: string;
93
- /**
94
- * Additional provider-specific metadata. They are passed through
95
- * to the provider from the AI SDK and enable provider-specific
96
- * functionality that can be fully encapsulated in the provider.
97
- */
98
- providerOptions?: ProviderOptions;
99
- } & ToolInputProperties<INPUT> & {
100
- /**
101
- * An optional list of input examples that show the language
102
- * model what the input should look like.
103
- */
104
- inputExamples?: Array<{
105
- input: NoInfer<INPUT>;
106
- }>;
107
- /**
108
- * Whether the tool needs approval before it can be executed.
109
- */
110
- needsApproval?: boolean | ToolNeedsApprovalFunctionCtx<[
111
- INPUT
112
- ] extends [never] ? unknown : INPUT, Ctx>;
113
- /**
114
- * Strict mode setting for the tool.
115
- *
116
- * Providers that support strict mode will use this setting to determine
117
- * how the input should be generated. Strict mode will always produce
118
- * valid inputs, but it might limit what input schemas are supported.
119
- */
120
- strict?: boolean;
121
- /**
122
- * Provide the context to use, e.g. when defining the tool at runtime.
123
- */
124
- ctx?: Ctx;
125
- /**
126
- * Optional function that is called when the argument streaming starts.
127
- * Only called when the tool is used in a streaming context.
128
- */
129
- onInputStart?: (ctx: Ctx, options: ToolExecutionOptions) => void | PromiseLike<void>;
130
- /**
131
- * Optional function that is called when an argument streaming delta is available.
132
- * Only called when the tool is used in a streaming context.
133
- */
134
- onInputDelta?: (ctx: Ctx, options: {
135
- inputTextDelta: string;
136
- } & ToolExecutionOptions) => void | PromiseLike<void>;
137
- /**
138
- * Optional function that is called when a tool call can be started,
139
- * even if the execute function is not provided.
140
- */
141
- onInputAvailable?: (ctx: Ctx, options: {
142
- input: [INPUT] extends [never] ? unknown : INPUT;
143
- } & ToolExecutionOptions) => void | PromiseLike<void>;
144
- } & ToolOutputPropertiesCtx<INPUT, OUTPUT, Ctx> & {
145
- /**
146
- * Optional conversion function that maps the tool result to an output that can be used by the language model.
147
- *
148
- * If not provided, the tool result will be sent as a JSON object.
149
- */
150
- toModelOutput?: (ctx: Ctx, options: {
151
- /**
152
- * The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data.
153
- */
154
- toolCallId: string;
155
- /**
156
- * The input of the tool call.
157
- */
158
- input: [INPUT] extends [never] ? unknown : INPUT;
159
- /**
160
- * The output of the tool call.
161
- */
162
- output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>;
163
- }) => ToolResultOutput | PromiseLike<ToolResultOutput>;
164
- }): Tool<INPUT, OUTPUT>;
165
- export declare function wrapTools(ctx: ToolCtx, ...toolSets: (ToolSet | undefined)[]): ToolSet;
166
- export {};
167
- //# 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,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAWxC,MAAM,MAAM,OAAO,CAAC,SAAS,SAAS,gBAAgB,GAAG,gBAAgB,IACvE,gBAAgB,CAAC,S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CACb,GAAG,EAAE,GAAG,EACR,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,oBAAoB,KACvD,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,OAAO,GAAG,KAAK,CAAC;KAClD,GAAG,oBAAoB,KACrB,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;CAC/B,GAAG,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG;IAChD;;;;OAIG;IACH,aAAa,CAAC,EAAE,CACd,GAAG,EAAE,GAAG,EACR,OAAO,EAAE;QACP;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;QACnB;;WAEG;QACH,KAAK,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC;QACjD;;WAEG;QACH,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,MAAM,GACxB,GAAG,GACH,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,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,CA+FrB;AAMD,wBAAgB,SAAS,CACvB,GAAG,EAAE,OAAO,EACZ,GAAG,QAAQ,EAAE,CAAC,OAAO,GAAG,SAAS,CAAC,EAAE,GACnC,OAAO,CAgBT"}
@@ -1,116 +0,0 @@
1
- import { tool } from "ai";
2
- const MIGRATION_URL = "node_modules/@convex-dev/agent/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
- // Runtime backwards compat - types will show errors but runtime still works
21
- const inputSchema = def.inputSchema ?? def.args;
22
- if (!inputSchema)
23
- throw new Error("To use a Convex tool, you must provide an `inputSchema`");
24
- if (def.args && !def.inputSchema) {
25
- warnDeprecation("createTool.args", "createTool: 'args' is deprecated. Use 'inputSchema' instead.");
26
- }
27
- if (def.handler && !def.execute) {
28
- warnDeprecation("createTool.handler", "createTool: 'handler' is deprecated. Use 'execute' instead.");
29
- }
30
- const executeHandler = def.execute ?? def.handler;
31
- if (!executeHandler && !def.outputSchema)
32
- throw new Error("To use a Convex tool, you must either provide an execute" +
33
- " handler function, define an outputSchema, or both");
34
- const t = tool({
35
- type: "function",
36
- __acceptsCtx: true,
37
- ctx: def.ctx,
38
- description: def.description,
39
- title: def.title,
40
- providerOptions: def.providerOptions,
41
- inputSchema,
42
- inputExamples: def.inputExamples,
43
- needsApproval(input, options) {
44
- const needsApproval = def.needsApproval;
45
- if (!needsApproval || typeof needsApproval === "boolean")
46
- return Boolean(needsApproval);
47
- if (!getCtx(this)) {
48
- throw new Error("To use a Convex tool, you must either provide the ctx" +
49
- " at definition time (dynamically in an action), or use the Agent to" +
50
- " call it (which injects the ctx, userId and threadId)");
51
- }
52
- return needsApproval(getCtx(this), input, options);
53
- },
54
- strict: def.strict,
55
- ...(executeHandler
56
- ? {
57
- execute(input, options) {
58
- if (!getCtx(this)) {
59
- throw new Error("To use a Convex tool, you must either provide the ctx" +
60
- " at definition time (dynamically in an action), or use the Agent to" +
61
- " call it (which injects the ctx, userId and threadId)");
62
- }
63
- return executeHandler(getCtx(this), input, options);
64
- },
65
- }
66
- : {}),
67
- outputSchema: def.outputSchema,
68
- });
69
- if (def.onInputStart) {
70
- const origOnInputStart = def.onInputStart;
71
- t.onInputStart = function (options) {
72
- return origOnInputStart.call(this, getCtx(this), options);
73
- };
74
- }
75
- if (def.onInputDelta) {
76
- const origOnInputDelta = def.onInputDelta;
77
- t.onInputDelta = function (options) {
78
- return origOnInputDelta.call(this, getCtx(this), options);
79
- };
80
- }
81
- if (def.onInputAvailable) {
82
- const origOnInputAvailable = def.onInputAvailable;
83
- t.onInputAvailable = function (options) {
84
- return origOnInputAvailable.call(this, getCtx(this), options);
85
- };
86
- }
87
- if (def.toModelOutput) {
88
- const origToModelOutput = def.toModelOutput;
89
- t.toModelOutput = function (options) {
90
- return origToModelOutput.call(this, getCtx(this), options);
91
- };
92
- }
93
- return t;
94
- }
95
- function getCtx(tool) {
96
- return tool.ctx;
97
- }
98
- export function wrapTools(ctx, ...toolSets) {
99
- const output = {};
100
- for (const toolSet of toolSets) {
101
- if (!toolSet) {
102
- continue;
103
- }
104
- for (const [name, tool] of Object.entries(toolSet)) {
105
- if (tool && !tool.__acceptsCtx) {
106
- output[name] = tool;
107
- }
108
- else {
109
- const out = { ...tool, ctx };
110
- output[name] = out;
111
- }
112
- }
113
- }
114
- return output;
115
- }
116
- //# 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,6CAA6C,CAAC;AACpE,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAU,CAAC;AAC7C,SAAS,eAAe,CAAC,GAAW,EAAE,OAAe;IACnD,IAAI,CAAC,kBAAkB,CAAC,GAA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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"}