agents 0.3.0 → 0.3.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.
Files changed (67) hide show
  1. package/README.md +12 -326
  2. package/dist/ai-chat-agent.d.ts +1 -324
  3. package/dist/ai-chat-agent.js +3 -1147
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration.d.ts +1 -155
  6. package/dist/ai-chat-v5-migration.js +4 -151
  7. package/dist/ai-chat-v5-migration.js.map +1 -1
  8. package/dist/ai-react.d.ts +1 -286
  9. package/dist/ai-react.js +3 -632
  10. package/dist/ai-react.js.map +1 -1
  11. package/dist/ai-types.d.ts +7 -6
  12. package/dist/ai-types.js +12 -2
  13. package/dist/ai-types.js.map +1 -0
  14. package/dist/{client-QZa2Rq0l.js → client-C7SOlYfK.js} +2 -2
  15. package/dist/{client-QZa2Rq0l.js.map → client-C7SOlYfK.js.map} +1 -1
  16. package/dist/{client-DjTPRM8-.js → client-CEO0P7vN.js} +2 -2
  17. package/dist/client-CEO0P7vN.js.map +1 -0
  18. package/dist/{client-DFotUKH_.d.ts → client-CbcnyqCo.d.ts} +10 -10
  19. package/dist/client.d.ts +92 -7
  20. package/dist/client.js +1 -1
  21. package/dist/codemode/ai.d.ts +1 -27
  22. package/dist/codemode/ai.js +3 -146
  23. package/dist/codemode/ai.js.map +1 -1
  24. package/dist/{do-oauth-client-provider--To1Tsjj.d.ts → do-oauth-client-provider-BH9zFtSy.d.ts} +1 -1
  25. package/dist/{do-oauth-client-provider-B1fVIshX.js → do-oauth-client-provider-BfPFgQU0.js} +1 -1
  26. package/dist/{do-oauth-client-provider-B1fVIshX.js.map → do-oauth-client-provider-BfPFgQU0.js.map} +1 -1
  27. package/dist/{index-DLuxm_9W.d.ts → index-B7Ny-XfU.d.ts} +2 -2
  28. package/dist/index.d.ts +553 -38
  29. package/dist/index.js +5 -5
  30. package/dist/{context-DcbQ8o7k.d.ts → internal_context-neg89p5n.d.ts} +2 -2
  31. package/dist/{context-BkKbAa1R.js → internal_context-oN047Id3.js} +2 -2
  32. package/dist/internal_context-oN047Id3.js.map +1 -0
  33. package/dist/{context.d.ts → internal_context.d.ts} +1 -1
  34. package/dist/internal_context.js +3 -0
  35. package/dist/mcp/client.d.ts +1 -1
  36. package/dist/mcp/client.js +2 -2
  37. package/dist/mcp/do-oauth-client-provider.d.ts +1 -1
  38. package/dist/mcp/do-oauth-client-provider.js +1 -1
  39. package/dist/mcp/index.d.ts +3 -4
  40. package/dist/mcp/index.js +6 -6
  41. package/dist/mcp/index.js.map +1 -1
  42. package/dist/mcp/x402.d.ts +1 -1
  43. package/dist/{mcp-CPSfGUgd.d.ts → mcp-AK39tq6H.d.ts} +1 -1
  44. package/dist/observability/index.d.ts +1 -1
  45. package/dist/observability/index.js +5 -5
  46. package/dist/react.d.ts +14 -6
  47. package/dist/react.js +16 -8
  48. package/dist/react.js.map +1 -1
  49. package/dist/serializable.d.ts +33 -6
  50. package/dist/{src-BZDh910Z.js → src-CXf5SiV4.js} +6 -6
  51. package/dist/src-CXf5SiV4.js.map +1 -0
  52. package/dist/types-4b5tlB0u.js +15 -0
  53. package/dist/types-4b5tlB0u.js.map +1 -0
  54. package/dist/types-C5vR2Gzv.d.ts +13 -0
  55. package/dist/types.d.ts +2 -0
  56. package/dist/types.js +3 -0
  57. package/package.json +33 -25
  58. package/dist/ai-types-0OnT3FHg.d.ts +0 -127
  59. package/dist/ai-types-DEtF_8Km.js +0 -28
  60. package/dist/ai-types-DEtF_8Km.js.map +0 -1
  61. package/dist/client-CdM5I962.d.ts +0 -104
  62. package/dist/client-DjTPRM8-.js.map +0 -1
  63. package/dist/context-BkKbAa1R.js.map +0 -1
  64. package/dist/context.js +0 -3
  65. package/dist/index-CT2tCrLr.d.ts +0 -577
  66. package/dist/serializable-Crsj26mx.d.ts +0 -39
  67. package/dist/src-BZDh910Z.js.map +0 -1
@@ -1,286 +1 @@
1
- import "./context-DcbQ8o7k.js";
2
- import "./client-DFotUKH_.js";
3
- import "./ai-types-0OnT3FHg.js";
4
- import "./index-CT2tCrLr.js";
5
- import "./client-CdM5I962.js";
6
- import { useAgent } from "./react.js";
7
- import { ChatInit, JSONSchema7, Tool, UIMessage } from "ai";
8
- import { UseChatOptions, useChat } from "@ai-sdk/react";
9
-
10
- //#region src/ai-react.d.ts
11
- /**
12
- * JSON Schema type for tool parameters.
13
- * Re-exported from the AI SDK for convenience.
14
- * @deprecated Import JSONSchema7 directly from "ai" instead.
15
- */
16
- type JSONSchemaType = JSONSchema7;
17
- /**
18
- * Definition for a tool that can be executed on the client.
19
- * Tools with an `execute` function are automatically registered with the server.
20
- *
21
- * Note: Uses `parameters` (JSONSchema7) rather than AI SDK's `inputSchema` (FlexibleSchema)
22
- * because client tools must be serializable for the wire format. Zod schemas cannot be
23
- * serialized, so we require raw JSON Schema here.
24
- *
25
- * @deprecated Use AI SDK's native tool pattern instead. Define tools on the server with
26
- * `tool()` from "ai", and handle client-side execution via the `onToolCall` callback
27
- * in `useAgentChat`. For tools requiring user approval, use `needsApproval` on the server.
28
- */
29
- type AITool<Input = unknown, Output = unknown> = {
30
- /** Human-readable description of what the tool does */
31
- description?: Tool["description"];
32
- /** JSON Schema defining the tool's input parameters */
33
- parameters?: JSONSchema7;
34
- /**
35
- * @deprecated Use `parameters` instead. Will be removed in a future version.
36
- */
37
- inputSchema?: JSONSchema7;
38
- /**
39
- * Function to execute the tool on the client.
40
- * If provided, the tool schema is automatically sent to the server.
41
- */
42
- execute?: (input: Input) => Output | Promise<Output>;
43
- };
44
- /**
45
- * Schema for a client tool sent to the server.
46
- * This is the wire format - what gets sent in the request body.
47
- * Must match the server-side ClientToolSchema type in ai-chat-agent.ts.
48
- *
49
- * @deprecated Use AI SDK's native tool pattern instead. Define tools on the server.
50
- */
51
- type ClientToolSchema = {
52
- /** Unique name for the tool */
53
- name: string;
54
- /** Human-readable description of what the tool does */
55
- description?: Tool["description"];
56
- /** JSON Schema defining the tool's input parameters */
57
- parameters?: JSONSchema7;
58
- };
59
- /**
60
- * Extracts tool schemas from tools that have client-side execute functions.
61
- * These schemas are automatically sent to the server with each request.
62
- * @param tools - Record of tool name to tool definition
63
- * @returns Array of tool schemas to send to server, or undefined if none
64
- *
65
- * @deprecated Use AI SDK's native tool pattern instead. Define tools on the server
66
- * and use `onToolCall` callback for client-side execution.
67
- */
68
- declare function extractClientToolSchemas(
69
- tools?: Record<string, AITool<unknown, unknown>>
70
- ): ClientToolSchema[] | undefined;
71
- type GetInitialMessagesOptions = {
72
- agent: string;
73
- name: string;
74
- url: string;
75
- };
76
- type UseChatParams<M extends UIMessage = UIMessage> = ChatInit<M> &
77
- UseChatOptions<M>;
78
- /**
79
- * Options for preparing the send messages request.
80
- * Used by prepareSendMessagesRequest callback.
81
- */
82
- type PrepareSendMessagesRequestOptions<
83
- ChatMessage extends UIMessage = UIMessage
84
- > = {
85
- /** The chat ID */
86
- id: string;
87
- /** Messages to send */
88
- messages: ChatMessage[];
89
- /** What triggered this request */
90
- trigger: "submit-message" | "regenerate-message";
91
- /** ID of the message being sent (if applicable) */
92
- messageId?: string;
93
- /** Request metadata */
94
- requestMetadata?: unknown;
95
- /** Current body (if any) */
96
- body?: Record<string, unknown>;
97
- /** Current credentials (if any) */
98
- credentials?: RequestCredentials;
99
- /** Current headers (if any) */
100
- headers?: HeadersInit;
101
- /** API endpoint */
102
- api?: string;
103
- };
104
- /**
105
- * Return type for prepareSendMessagesRequest callback.
106
- * Allows customizing headers, body, and credentials for each request.
107
- * All fields are optional; only specify what you need to customize.
108
- */
109
- type PrepareSendMessagesRequestResult = {
110
- /** Custom headers to send with the request */
111
- headers?: HeadersInit;
112
- /** Custom body data to merge with the request */
113
- body?: Record<string, unknown>;
114
- /** Custom credentials option */
115
- credentials?: RequestCredentials;
116
- /** Custom API endpoint */
117
- api?: string;
118
- };
119
- /**
120
- * Callback for handling client-side tool execution.
121
- * Called when a tool without server-side execute is invoked.
122
- */
123
- type OnToolCallCallback = (options: {
124
- /** The tool call that needs to be handled */
125
- toolCall: {
126
- toolCallId: string;
127
- toolName: string;
128
- input: unknown;
129
- };
130
- /** Function to provide the tool output */
131
- addToolOutput: (options: { toolCallId: string; output: unknown }) => void;
132
- }) => void | Promise<void>;
133
- /**
134
- * Options for the useAgentChat hook
135
- */
136
- type UseAgentChatOptions<
137
- State,
138
- ChatMessage extends UIMessage = UIMessage
139
- > = Omit<UseChatParams<ChatMessage>, "fetch"> & {
140
- /** Agent connection from useAgent */
141
- agent: ReturnType<typeof useAgent<State>>;
142
- getInitialMessages?:
143
- | undefined
144
- | null
145
- | ((options: GetInitialMessagesOptions) => Promise<ChatMessage[]>);
146
- /** Request credentials */
147
- credentials?: RequestCredentials;
148
- /** Request headers */
149
- headers?: HeadersInit;
150
- /**
151
- * Callback for handling client-side tool execution.
152
- * Called when a tool without server-side `execute` is invoked by the LLM.
153
- *
154
- * Use this for:
155
- * - Tools that need browser APIs (geolocation, camera, etc.)
156
- * - Tools that need user interaction before providing a result
157
- * - Tools requiring approval before execution
158
- *
159
- * @example
160
- * ```typescript
161
- * onToolCall: async ({ toolCall, addToolOutput }) => {
162
- * if (toolCall.toolName === 'getLocation') {
163
- * const position = await navigator.geolocation.getCurrentPosition();
164
- * addToolOutput({
165
- * toolCallId: toolCall.toolCallId,
166
- * output: { lat: position.coords.latitude, lng: position.coords.longitude }
167
- * });
168
- * }
169
- * }
170
- * ```
171
- */
172
- onToolCall?: OnToolCallCallback;
173
- /**
174
- * @deprecated Use `onToolCall` callback instead for automatic tool execution.
175
- * @description Whether to automatically resolve tool calls that do not require human interaction.
176
- * @experimental
177
- */
178
- experimental_automaticToolResolution?: boolean;
179
- /**
180
- * @deprecated Use `onToolCall` callback instead. Define tools on the server
181
- * and handle client-side execution via `onToolCall`.
182
- *
183
- * Tools that can be executed on the client.
184
- */
185
- tools?: Record<string, AITool<unknown, unknown>>;
186
- /**
187
- * @deprecated Use `needsApproval` on server-side tools instead.
188
- * @description Manual override for tools requiring confirmation.
189
- * If not provided, will auto-detect from tools object (tools without execute require confirmation).
190
- */
191
- toolsRequiringConfirmation?: string[];
192
- /**
193
- * When true, the server automatically continues the conversation after
194
- * receiving client-side tool results, similar to how server-executed tools
195
- * work with maxSteps in streamText. The continuation is merged into the
196
- * same assistant message.
197
- *
198
- * When false (default), the client calls sendMessage() after tool results
199
- * to continue the conversation, which creates a new assistant message.
200
- *
201
- * @default false
202
- */
203
- autoContinueAfterToolResult?: boolean;
204
- /**
205
- * @deprecated Use `sendAutomaticallyWhen` from AI SDK instead.
206
- *
207
- * When true (default), automatically sends the next message only after
208
- * all pending confirmation-required tool calls have been resolved.
209
- * When false, sends immediately after each tool result.
210
- *
211
- * Only applies when `autoContinueAfterToolResult` is false.
212
- *
213
- * @default true
214
- */
215
- autoSendAfterAllConfirmationsResolved?: boolean;
216
- /**
217
- * Set to false to disable automatic stream resumption.
218
- * @default true
219
- */
220
- resume?: boolean;
221
- /**
222
- * Callback to customize the request before sending messages.
223
- * Use this for advanced scenarios like adding custom headers or dynamic context.
224
- *
225
- * Note: Client tool schemas are automatically sent when tools have `execute` functions.
226
- * This callback can add additional data alongside the auto-extracted schemas.
227
- */
228
- prepareSendMessagesRequest?: (
229
- options: PrepareSendMessagesRequestOptions<ChatMessage>
230
- ) =>
231
- | PrepareSendMessagesRequestResult
232
- | Promise<PrepareSendMessagesRequestResult>;
233
- };
234
- /**
235
- * React hook for building AI chat interfaces using an Agent
236
- * @param options Chat options including the agent connection
237
- * @returns Chat interface controls and state with added clearHistory method
238
- */
239
- /**
240
- * Automatically detects which tools require confirmation based on their configuration.
241
- * Tools require confirmation if they have no execute function AND are not server-executed.
242
- * @param tools - Record of tool name to tool definition
243
- * @returns Array of tool names that require confirmation
244
- *
245
- * @deprecated Use `needsApproval` on server-side tools instead.
246
- */
247
- declare function detectToolsRequiringConfirmation(
248
- tools?: Record<string, AITool<unknown, unknown>>
249
- ): string[];
250
- /**
251
- * Return type for addToolOutput function
252
- */
253
- type AddToolOutputOptions = {
254
- /** The ID of the tool call to provide output for */
255
- toolCallId: string;
256
- /** The name of the tool (optional, for type safety) */
257
- toolName?: string;
258
- /** The output to provide */
259
- output: unknown;
260
- };
261
- declare function useAgentChat<
262
- State = unknown,
263
- ChatMessage extends UIMessage = UIMessage
264
- >(
265
- options: UseAgentChatOptions<State, ChatMessage>
266
- ): Omit<ReturnType<typeof useChat<ChatMessage>>, "addToolOutput"> & {
267
- clearHistory: () => void;
268
- /**
269
- * Provide output for a tool call. Use this for tools that require user interaction
270
- * or client-side execution.
271
- */
272
- addToolOutput: (opts: AddToolOutputOptions) => void;
273
- };
274
- //#endregion
275
- export {
276
- AITool,
277
- ClientToolSchema,
278
- JSONSchemaType,
279
- OnToolCallCallback,
280
- PrepareSendMessagesRequestOptions,
281
- PrepareSendMessagesRequestResult,
282
- detectToolsRequiringConfirmation,
283
- extractClientToolSchemas,
284
- useAgentChat
285
- };
286
- //# sourceMappingURL=ai-react.d.ts.map
1
+ export * from "@cloudflare/ai-chat/react";