agents 0.0.0-4768b8d → 0.0.0-48849be

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 (64) hide show
  1. package/README.md +257 -27
  2. package/dist/ai-chat-agent.d.ts +77 -24
  3. package/dist/ai-chat-agent.js +540 -0
  4. package/dist/ai-chat-agent.js.map +1 -0
  5. package/dist/ai-chat-v5-migration-BSiGZmYU.js +155 -0
  6. package/dist/ai-chat-v5-migration-BSiGZmYU.js.map +1 -0
  7. package/dist/ai-chat-v5-migration.d.ts +155 -0
  8. package/dist/ai-chat-v5-migration.js +3 -0
  9. package/dist/ai-react.d.ts +77 -48
  10. package/dist/ai-react.js +270 -0
  11. package/dist/ai-react.js.map +1 -0
  12. package/dist/ai-types-DKWQN9wb.js +20 -0
  13. package/dist/ai-types-DKWQN9wb.js.map +1 -0
  14. package/dist/ai-types-DLtxDE4L.d.ts +95 -0
  15. package/dist/ai-types.d.ts +6 -49
  16. package/dist/ai-types.js +3 -0
  17. package/dist/cli.d.ts +8 -0
  18. package/dist/cli.js +27 -0
  19. package/dist/cli.js.map +1 -0
  20. package/dist/client-BAQA84dr.d.ts +104 -0
  21. package/dist/client-BZ-xTxF5.js +901 -0
  22. package/dist/client-BZ-xTxF5.js.map +1 -0
  23. package/dist/client-Cg1aBNFS.js +117 -0
  24. package/dist/client-Cg1aBNFS.js.map +1 -0
  25. package/dist/client-ctTw3KHG.d.ts +1440 -0
  26. package/dist/client.d.ts +16 -63
  27. package/dist/client.js +4 -0
  28. package/dist/codemode/ai.d.ts +27 -0
  29. package/dist/codemode/ai.js +151 -0
  30. package/dist/codemode/ai.js.map +1 -0
  31. package/dist/do-oauth-client-provider-Cs9QpXYp.js +93 -0
  32. package/dist/do-oauth-client-provider-Cs9QpXYp.js.map +1 -0
  33. package/dist/do-oauth-client-provider-UhQDpDb8.d.ts +134 -0
  34. package/dist/index-BUle9RiP.d.ts +58 -0
  35. package/dist/index-BygUGrr9.d.ts +578 -0
  36. package/dist/index.d.ts +69 -258
  37. package/dist/index.js +7 -0
  38. package/dist/mcp/client.d.ts +4 -675
  39. package/dist/mcp/client.js +4 -0
  40. package/dist/mcp/do-oauth-client-provider.d.ts +2 -0
  41. package/dist/mcp/do-oauth-client-provider.js +3 -0
  42. package/dist/mcp/index.d.ts +191 -39
  43. package/dist/mcp/index.js +1443 -0
  44. package/dist/mcp/index.js.map +1 -0
  45. package/dist/mcp/x402.d.ts +34 -0
  46. package/dist/mcp/x402.js +198 -0
  47. package/dist/mcp/x402.js.map +1 -0
  48. package/dist/mcp-BwPscEiF.d.ts +61 -0
  49. package/dist/observability/index.d.ts +3 -0
  50. package/dist/observability/index.js +7 -0
  51. package/dist/react-CMF2YDq6.d.ts +113 -0
  52. package/dist/react.d.ts +10 -30
  53. package/dist/react.js +189 -0
  54. package/dist/react.js.map +1 -0
  55. package/dist/schedule.d.ts +112 -25
  56. package/dist/schedule.js +96 -0
  57. package/dist/schedule.js.map +1 -0
  58. package/dist/serializable-faDkMCai.d.ts +39 -0
  59. package/dist/serializable.d.ts +7 -0
  60. package/dist/serializable.js +1 -0
  61. package/dist/src-BBJoK65j.js +1248 -0
  62. package/dist/src-BBJoK65j.js.map +1 -0
  63. package/package.json +130 -53
  64. package/src/index.ts +0 -919
@@ -0,0 +1,155 @@
1
+ //#region src/ai-chat-v5-migration.ts
2
+ /**
3
+ * Tool call state mapping for v4 to v5 migration
4
+ */
5
+ const STATE_MAP = {
6
+ "partial-call": "input-streaming",
7
+ call: "input-available",
8
+ result: "output-available",
9
+ error: "output-error"
10
+ };
11
+ /**
12
+ * Checks if a message is already in the UIMessage format (has parts array)
13
+ */
14
+ function isUIMessage(message) {
15
+ return typeof message === "object" && message !== null && "parts" in message && Array.isArray(message.parts);
16
+ }
17
+ /**
18
+ * Type guard to check if a message is in legacy format (content as string)
19
+ */
20
+ function isLegacyMessage(message) {
21
+ return typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.role === "string" && typeof message.content === "string";
22
+ }
23
+ /**
24
+ * Type guard to check if a message has corrupted array content format
25
+ * Detects: {role: "user", content: [{type: "text", text: "..."}]}
26
+ */
27
+ function isCorruptArrayMessage(message) {
28
+ return typeof message === "object" && message !== null && "role" in message && "content" in message && typeof message.role === "string" && Array.isArray(message.content) && !("parts" in message);
29
+ }
30
+ /**
31
+ * Automatic message transformer following the blog post pattern
32
+ * Handles comprehensive migration from AI SDK v4 to v5 format
33
+ * @param message - Message in any legacy format
34
+ * @param index - Index for ID generation fallback
35
+ * @returns UIMessage in v5 format
36
+ */
37
+ function autoTransformMessage(message, index = 0) {
38
+ if (isUIMessage(message)) return message;
39
+ const parts = [];
40
+ if (message.reasoning) parts.push({
41
+ type: "reasoning",
42
+ text: message.reasoning
43
+ });
44
+ if (message.toolInvocations && Array.isArray(message.toolInvocations)) message.toolInvocations.forEach((inv) => {
45
+ if (typeof inv === "object" && inv !== null && "toolName" in inv) {
46
+ const invObj = inv;
47
+ parts.push({
48
+ type: `tool-${invObj.toolName}`,
49
+ toolCallId: invObj.toolCallId,
50
+ state: STATE_MAP[invObj.state] || "input-available",
51
+ input: invObj.args,
52
+ output: invObj.result !== void 0 ? invObj.result : null
53
+ });
54
+ }
55
+ });
56
+ if (message.parts && Array.isArray(message.parts)) message.parts.forEach((part) => {
57
+ if (typeof part === "object" && part !== null && "type" in part) {
58
+ const partObj = part;
59
+ if (partObj.type === "file") parts.push({
60
+ type: "file",
61
+ url: partObj.url || (partObj.data ? `data:${partObj.mimeType || partObj.mediaType};base64,${partObj.data}` : void 0),
62
+ mediaType: partObj.mediaType || partObj.mimeType,
63
+ filename: partObj.filename
64
+ });
65
+ }
66
+ });
67
+ if (Array.isArray(message.content)) message.content.forEach((item) => {
68
+ if (typeof item === "object" && item !== null && "text" in item) {
69
+ const itemObj = item;
70
+ parts.push({
71
+ type: itemObj.type || "text",
72
+ text: itemObj.text || ""
73
+ });
74
+ }
75
+ });
76
+ if (!parts.length && message.content !== void 0) parts.push({
77
+ type: "text",
78
+ text: typeof message.content === "string" ? message.content : JSON.stringify(message.content)
79
+ });
80
+ if (!parts.length) parts.push({
81
+ type: "text",
82
+ text: typeof message === "string" ? message : JSON.stringify(message)
83
+ });
84
+ return {
85
+ id: message.id || `msg-${index}`,
86
+ role: message.role === "data" ? "system" : message.role || "user",
87
+ parts
88
+ };
89
+ }
90
+ /**
91
+ * Legacy single message migration for backward compatibility
92
+ */
93
+ function migrateToUIMessage(message) {
94
+ return autoTransformMessage(message);
95
+ }
96
+ /**
97
+ * Automatic message transformer for arrays following the blog post pattern
98
+ * @param messages - Array of messages in any format
99
+ * @returns Array of UIMessages in v5 format
100
+ */
101
+ function autoTransformMessages(messages) {
102
+ return messages.map((msg, i) => autoTransformMessage(msg, i));
103
+ }
104
+ /**
105
+ * Migrates an array of messages to UIMessage format (legacy compatibility)
106
+ * @param messages - Array of messages in old or new format
107
+ * @returns Array of UIMessages in the new format
108
+ */
109
+ function migrateMessagesToUIFormat(messages) {
110
+ return autoTransformMessages(messages);
111
+ }
112
+ /**
113
+ * Checks if any messages in an array need migration
114
+ * @param messages - Array of messages to check
115
+ * @returns true if any messages are not in proper UIMessage format
116
+ */
117
+ function needsMigration(messages) {
118
+ return messages.some((message) => {
119
+ if (isUIMessage(message)) return false;
120
+ if (isCorruptArrayMessage(message)) return true;
121
+ if (isLegacyMessage(message)) return true;
122
+ return true;
123
+ });
124
+ }
125
+ /**
126
+ * Analyzes the corruption types in a message array for debugging
127
+ * @param messages - Array of messages to analyze
128
+ * @returns Statistics about corruption types found
129
+ */
130
+ function analyzeCorruption(messages) {
131
+ const stats = {
132
+ total: messages.length,
133
+ clean: 0,
134
+ legacyString: 0,
135
+ corruptArray: 0,
136
+ unknown: 0,
137
+ examples: {}
138
+ };
139
+ for (const message of messages) if (isUIMessage(message)) stats.clean++;
140
+ else if (isCorruptArrayMessage(message)) {
141
+ stats.corruptArray++;
142
+ if (!stats.examples.corruptArray) stats.examples.corruptArray = message;
143
+ } else if (isLegacyMessage(message)) {
144
+ stats.legacyString++;
145
+ if (!stats.examples.legacyString) stats.examples.legacyString = message;
146
+ } else {
147
+ stats.unknown++;
148
+ if (!stats.examples.unknown) stats.examples.unknown = message;
149
+ }
150
+ return stats;
151
+ }
152
+
153
+ //#endregion
154
+ export { migrateMessagesToUIFormat as a, isUIMessage as i, autoTransformMessage as n, migrateToUIMessage as o, autoTransformMessages as r, needsMigration as s, analyzeCorruption as t };
155
+ //# sourceMappingURL=ai-chat-v5-migration-BSiGZmYU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-chat-v5-migration-BSiGZmYU.js","names":["parts: TransformMessagePart[]"],"sources":["../src/ai-chat-v5-migration.ts"],"sourcesContent":["import type { UIMessage } from \"ai\";\n\n/**\n * AI SDK v5 Migration following https://jhak.im/blog/ai-sdk-migration-handling-previously-saved-messages\n * Using exact types from the official AI SDK documentation\n */\n\n/**\n * AI SDK v5 Message Part types reference (from official AI SDK documentation)\n *\n * The migration logic below transforms legacy messages to match these official AI SDK v5 formats:\n * - TextUIPart: { type: \"text\", text: string, state?: \"streaming\" | \"done\" }\n * - ReasoningUIPart: { type: \"reasoning\", text: string, state?: \"streaming\" | \"done\", providerMetadata?: Record<string, unknown> }\n * - FileUIPart: { type: \"file\", mediaType: string, filename?: string, url: string }\n * - ToolUIPart: { type: `tool-${string}`, toolCallId: string, state: \"input-streaming\" | \"input-available\" | \"output-available\" | \"output-error\", input?: Record<string, unknown>, output?: unknown, errorText?: string, providerExecuted?: boolean }\n */\n\n/**\n * Tool invocation from v4 format\n */\ntype ToolInvocation = {\n toolCallId: string;\n toolName: string;\n args: Record<string, unknown>;\n result?: unknown;\n state: \"partial-call\" | \"call\" | \"result\" | \"error\";\n};\n\n/**\n * Legacy part from v4 format\n */\ntype LegacyPart = {\n type: string;\n text?: string;\n url?: string;\n data?: string;\n mimeType?: string;\n mediaType?: string;\n filename?: string;\n};\n\n/**\n * Legacy message format from AI SDK v4\n */\nexport type LegacyMessage = {\n id?: string;\n role: string;\n content: string;\n reasoning?: string;\n toolInvocations?: ToolInvocation[];\n parts?: LegacyPart[];\n [key: string]: unknown;\n};\n\n/**\n * Corrupt content item\n */\ntype CorruptContentItem = {\n type: string;\n text: string;\n};\n\n/**\n * Corrupted message format - has content as array instead of parts\n */\nexport type CorruptArrayMessage = {\n id?: string;\n role: string;\n content: CorruptContentItem[];\n reasoning?: string;\n toolInvocations?: ToolInvocation[];\n [key: string]: unknown;\n};\n\n/**\n * Union type for messages that could be in any format\n */\nexport type MigratableMessage = LegacyMessage | CorruptArrayMessage | UIMessage;\n\n/**\n * Tool call state mapping for v4 to v5 migration\n */\nconst STATE_MAP = {\n \"partial-call\": \"input-streaming\",\n call: \"input-available\",\n result: \"output-available\",\n error: \"output-error\"\n} as const;\n\n/**\n * Checks if a message is already in the UIMessage format (has parts array)\n */\nexport function isUIMessage(message: unknown): message is UIMessage {\n return (\n typeof message === \"object\" &&\n message !== null &&\n \"parts\" in message &&\n Array.isArray((message as { parts: unknown }).parts)\n );\n}\n\n/**\n * Type guard to check if a message is in legacy format (content as string)\n */\nfunction isLegacyMessage(message: unknown): message is LegacyMessage {\n return (\n typeof message === \"object\" &&\n message !== null &&\n \"role\" in message &&\n \"content\" in message &&\n typeof (message as { role: unknown }).role === \"string\" &&\n typeof (message as { content: unknown }).content === \"string\"\n );\n}\n\n/**\n * Type guard to check if a message has corrupted array content format\n * Detects: {role: \"user\", content: [{type: \"text\", text: \"...\"}]}\n */\nfunction isCorruptArrayMessage(\n message: unknown\n): message is CorruptArrayMessage {\n return (\n typeof message === \"object\" &&\n message !== null &&\n \"role\" in message &&\n \"content\" in message &&\n typeof (message as { role: unknown }).role === \"string\" &&\n Array.isArray((message as { content: unknown }).content) &&\n !(\"parts\" in message) // Ensure it's not already a UIMessage\n );\n}\n\n/**\n * Internal message part type for transformation\n */\ntype TransformMessagePart = {\n type: string;\n text?: string;\n toolCallId?: string;\n state?: string;\n input?: Record<string, unknown>;\n output?: unknown;\n url?: string;\n mediaType?: string;\n errorText?: string;\n filename?: string;\n};\n\n/**\n * Input message that could be in any format - using unknown for flexibility\n */\ntype InputMessage = {\n id?: string;\n role?: string;\n content?: unknown;\n reasoning?: string;\n toolInvocations?: unknown[];\n parts?: unknown[];\n [key: string]: unknown;\n};\n\n/**\n * Automatic message transformer following the blog post pattern\n * Handles comprehensive migration from AI SDK v4 to v5 format\n * @param message - Message in any legacy format\n * @param index - Index for ID generation fallback\n * @returns UIMessage in v5 format\n */\nexport function autoTransformMessage(\n message: InputMessage,\n index = 0\n): UIMessage {\n // Already in v5 format\n if (isUIMessage(message)) {\n return message;\n }\n\n const parts: TransformMessagePart[] = [];\n\n // Handle reasoning transformation\n if (message.reasoning) {\n parts.push({\n type: \"reasoning\",\n text: message.reasoning\n });\n }\n\n // Handle tool invocations transformation\n if (message.toolInvocations && Array.isArray(message.toolInvocations)) {\n message.toolInvocations.forEach((inv: unknown) => {\n if (typeof inv === \"object\" && inv !== null && \"toolName\" in inv) {\n const invObj = inv as ToolInvocation;\n parts.push({\n type: `tool-${invObj.toolName}`,\n toolCallId: invObj.toolCallId,\n state:\n STATE_MAP[invObj.state as keyof typeof STATE_MAP] ||\n \"input-available\",\n input: invObj.args,\n output: invObj.result !== undefined ? invObj.result : null\n });\n }\n });\n }\n\n // Handle file parts transformation\n if (message.parts && Array.isArray(message.parts)) {\n message.parts.forEach((part: unknown) => {\n if (typeof part === \"object\" && part !== null && \"type\" in part) {\n const partObj = part as LegacyPart;\n if (partObj.type === \"file\") {\n parts.push({\n type: \"file\",\n url:\n partObj.url ||\n (partObj.data\n ? `data:${partObj.mimeType || partObj.mediaType};base64,${partObj.data}`\n : undefined),\n mediaType: partObj.mediaType || partObj.mimeType,\n filename: partObj.filename\n });\n }\n }\n });\n }\n\n // Handle corrupt array format: {role: \"user\", content: [{type: \"text\", text: \"...\"}]}\n if (Array.isArray(message.content)) {\n message.content.forEach((item: unknown) => {\n if (typeof item === \"object\" && item !== null && \"text\" in item) {\n const itemObj = item as CorruptContentItem;\n parts.push({\n type: itemObj.type || \"text\",\n text: itemObj.text || \"\"\n });\n }\n });\n }\n\n // Fallback: convert plain content to text part\n if (!parts.length && message.content !== undefined) {\n parts.push({\n type: \"text\",\n text:\n typeof message.content === \"string\"\n ? message.content\n : JSON.stringify(message.content)\n });\n }\n\n // If still no parts, create a default text part\n if (!parts.length) {\n parts.push({\n type: \"text\",\n text: typeof message === \"string\" ? message : JSON.stringify(message)\n });\n }\n\n return {\n id: message.id || `msg-${index}`,\n role:\n message.role === \"data\"\n ? \"system\"\n : (message.role as \"user\" | \"assistant\" | \"system\") || \"user\",\n parts: parts as UIMessage[\"parts\"]\n };\n}\n\n/**\n * Legacy single message migration for backward compatibility\n */\nexport function migrateToUIMessage(message: MigratableMessage): UIMessage {\n return autoTransformMessage(message as InputMessage);\n}\n\n/**\n * Automatic message transformer for arrays following the blog post pattern\n * @param messages - Array of messages in any format\n * @returns Array of UIMessages in v5 format\n */\nexport function autoTransformMessages(messages: unknown[]): UIMessage[] {\n return messages.map((msg, i) => autoTransformMessage(msg as InputMessage, i));\n}\n\n/**\n * Migrates an array of messages to UIMessage format (legacy compatibility)\n * @param messages - Array of messages in old or new format\n * @returns Array of UIMessages in the new format\n */\nexport function migrateMessagesToUIFormat(\n messages: MigratableMessage[]\n): UIMessage[] {\n return autoTransformMessages(messages as InputMessage[]);\n}\n\n/**\n * Checks if any messages in an array need migration\n * @param messages - Array of messages to check\n * @returns true if any messages are not in proper UIMessage format\n */\nexport function needsMigration(messages: unknown[]): boolean {\n return messages.some((message) => {\n // If it's already a UIMessage, no migration needed\n if (isUIMessage(message)) {\n return false;\n }\n\n // Check for corrupt array format specifically\n if (isCorruptArrayMessage(message)) {\n return true;\n }\n\n // Check for legacy string format\n if (isLegacyMessage(message)) {\n return true;\n }\n\n // Any other format needs migration\n return true;\n });\n}\n\n/**\n * Analyzes the corruption types in a message array for debugging\n * @param messages - Array of messages to analyze\n * @returns Statistics about corruption types found\n */\nexport function analyzeCorruption(messages: unknown[]): {\n total: number;\n clean: number;\n legacyString: number;\n corruptArray: number;\n unknown: number;\n examples: {\n legacyString?: unknown;\n corruptArray?: unknown;\n unknown?: unknown;\n };\n} {\n const stats = {\n total: messages.length,\n clean: 0,\n legacyString: 0,\n corruptArray: 0,\n unknown: 0,\n examples: {} as {\n legacyString?: unknown;\n corruptArray?: unknown;\n unknown?: unknown;\n }\n };\n\n for (const message of messages) {\n if (isUIMessage(message)) {\n stats.clean++;\n } else if (isCorruptArrayMessage(message)) {\n stats.corruptArray++;\n if (!stats.examples.corruptArray) {\n stats.examples.corruptArray = message;\n }\n } else if (isLegacyMessage(message)) {\n stats.legacyString++;\n if (!stats.examples.legacyString) {\n stats.examples.legacyString = message;\n }\n } else {\n stats.unknown++;\n if (!stats.examples.unknown) {\n stats.examples.unknown = message;\n }\n }\n }\n\n return stats;\n}\n"],"mappings":"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"}
@@ -0,0 +1,155 @@
1
+ import { UIMessage } from "ai";
2
+
3
+ //#region src/ai-chat-v5-migration.d.ts
4
+
5
+ /**
6
+ * AI SDK v5 Migration following https://jhak.im/blog/ai-sdk-migration-handling-previously-saved-messages
7
+ * Using exact types from the official AI SDK documentation
8
+ */
9
+ /**
10
+ * AI SDK v5 Message Part types reference (from official AI SDK documentation)
11
+ *
12
+ * The migration logic below transforms legacy messages to match these official AI SDK v5 formats:
13
+ * - TextUIPart: { type: "text", text: string, state?: "streaming" | "done" }
14
+ * - ReasoningUIPart: { type: "reasoning", text: string, state?: "streaming" | "done", providerMetadata?: Record<string, unknown> }
15
+ * - FileUIPart: { type: "file", mediaType: string, filename?: string, url: string }
16
+ * - ToolUIPart: { type: `tool-${string}`, toolCallId: string, state: "input-streaming" | "input-available" | "output-available" | "output-error", input?: Record<string, unknown>, output?: unknown, errorText?: string, providerExecuted?: boolean }
17
+ */
18
+ /**
19
+ * Tool invocation from v4 format
20
+ */
21
+ type ToolInvocation = {
22
+ toolCallId: string;
23
+ toolName: string;
24
+ args: Record<string, unknown>;
25
+ result?: unknown;
26
+ state: "partial-call" | "call" | "result" | "error";
27
+ };
28
+ /**
29
+ * Legacy part from v4 format
30
+ */
31
+ type LegacyPart = {
32
+ type: string;
33
+ text?: string;
34
+ url?: string;
35
+ data?: string;
36
+ mimeType?: string;
37
+ mediaType?: string;
38
+ filename?: string;
39
+ };
40
+ /**
41
+ * Legacy message format from AI SDK v4
42
+ */
43
+ type LegacyMessage = {
44
+ id?: string;
45
+ role: string;
46
+ content: string;
47
+ reasoning?: string;
48
+ toolInvocations?: ToolInvocation[];
49
+ parts?: LegacyPart[];
50
+ [key: string]: unknown;
51
+ };
52
+ /**
53
+ * Corrupt content item
54
+ */
55
+ type CorruptContentItem = {
56
+ type: string;
57
+ text: string;
58
+ };
59
+ /**
60
+ * Corrupted message format - has content as array instead of parts
61
+ */
62
+ type CorruptArrayMessage = {
63
+ id?: string;
64
+ role: string;
65
+ content: CorruptContentItem[];
66
+ reasoning?: string;
67
+ toolInvocations?: ToolInvocation[];
68
+ [key: string]: unknown;
69
+ };
70
+ /**
71
+ * Union type for messages that could be in any format
72
+ */
73
+ type MigratableMessage = LegacyMessage | CorruptArrayMessage | UIMessage;
74
+ /**
75
+ * Checks if a message is already in the UIMessage format (has parts array)
76
+ */
77
+ declare function isUIMessage(message: unknown): message is UIMessage;
78
+ /**
79
+ * Input message that could be in any format - using unknown for flexibility
80
+ */
81
+ type InputMessage = {
82
+ id?: string;
83
+ role?: string;
84
+ content?: unknown;
85
+ reasoning?: string;
86
+ toolInvocations?: unknown[];
87
+ parts?: unknown[];
88
+ [key: string]: unknown;
89
+ };
90
+ /**
91
+ * Automatic message transformer following the blog post pattern
92
+ * Handles comprehensive migration from AI SDK v4 to v5 format
93
+ * @param message - Message in any legacy format
94
+ * @param index - Index for ID generation fallback
95
+ * @returns UIMessage in v5 format
96
+ */
97
+ declare function autoTransformMessage(
98
+ message: InputMessage,
99
+ index?: number
100
+ ): UIMessage;
101
+ /**
102
+ * Legacy single message migration for backward compatibility
103
+ */
104
+ declare function migrateToUIMessage(message: MigratableMessage): UIMessage;
105
+ /**
106
+ * Automatic message transformer for arrays following the blog post pattern
107
+ * @param messages - Array of messages in any format
108
+ * @returns Array of UIMessages in v5 format
109
+ */
110
+ declare function autoTransformMessages(messages: unknown[]): UIMessage[];
111
+ /**
112
+ * Migrates an array of messages to UIMessage format (legacy compatibility)
113
+ * @param messages - Array of messages in old or new format
114
+ * @returns Array of UIMessages in the new format
115
+ */
116
+ declare function migrateMessagesToUIFormat(
117
+ messages: MigratableMessage[]
118
+ ): UIMessage[];
119
+ /**
120
+ * Checks if any messages in an array need migration
121
+ * @param messages - Array of messages to check
122
+ * @returns true if any messages are not in proper UIMessage format
123
+ */
124
+ declare function needsMigration(messages: unknown[]): boolean;
125
+ /**
126
+ * Analyzes the corruption types in a message array for debugging
127
+ * @param messages - Array of messages to analyze
128
+ * @returns Statistics about corruption types found
129
+ */
130
+ declare function analyzeCorruption(messages: unknown[]): {
131
+ total: number;
132
+ clean: number;
133
+ legacyString: number;
134
+ corruptArray: number;
135
+ unknown: number;
136
+ examples: {
137
+ legacyString?: unknown;
138
+ corruptArray?: unknown;
139
+ unknown?: unknown;
140
+ };
141
+ };
142
+ //#endregion
143
+ export {
144
+ CorruptArrayMessage,
145
+ LegacyMessage,
146
+ MigratableMessage,
147
+ analyzeCorruption,
148
+ autoTransformMessage,
149
+ autoTransformMessages,
150
+ isUIMessage,
151
+ migrateMessagesToUIFormat,
152
+ migrateToUIMessage,
153
+ needsMigration
154
+ };
155
+ //# sourceMappingURL=ai-chat-v5-migration.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { a as migrateMessagesToUIFormat, i as isUIMessage, n as autoTransformMessage, o as migrateToUIMessage, r as autoTransformMessages, s as needsMigration, t as analyzeCorruption } from "./ai-chat-v5-migration-BSiGZmYU.js";
2
+
3
+ export { analyzeCorruption, autoTransformMessage, autoTransformMessages, isUIMessage, migrateMessagesToUIFormat, migrateToUIMessage, needsMigration };
@@ -1,60 +1,89 @@
1
- import * as ai from 'ai';
2
- import { Message } from 'ai';
3
- import { useChat } from '@ai-sdk/react';
4
- import { useAgent } from './react.js';
5
- import 'partysocket';
6
- import 'partysocket/react';
7
- import './client.js';
1
+ import "./client-ctTw3KHG.js";
2
+ import "./mcp-BwPscEiF.js";
3
+ import "./do-oauth-client-provider-UhQDpDb8.js";
4
+ import "./index-BUle9RiP.js";
5
+ import "./ai-types-DLtxDE4L.js";
6
+ import "./index-BygUGrr9.js";
7
+ import "./serializable-faDkMCai.js";
8
+ import "./client-BAQA84dr.js";
9
+ import { n as useAgent } from "./react-CMF2YDq6.js";
10
+ import { UseChatOptions, useChat } from "@ai-sdk/react";
11
+ import { ChatInit, UIMessage } from "ai";
8
12
 
13
+ //#region src/ai-react.d.ts
14
+ type AITool<Input = unknown, Output = unknown> = {
15
+ description?: string;
16
+ inputSchema?: unknown;
17
+ execute?: (input: Input) => Output | Promise<Output>;
18
+ };
9
19
  type GetInitialMessagesOptions = {
10
- agent: string;
11
- name: string;
12
- url: string;
20
+ agent: string;
21
+ name: string;
22
+ url: string;
13
23
  };
24
+ type UseChatParams<M extends UIMessage = UIMessage> = ChatInit<M> &
25
+ UseChatOptions<M>;
14
26
  /**
15
27
  * Options for the useAgentChat hook
16
28
  */
17
- type UseAgentChatOptions<State> = Omit<Parameters<typeof useChat>[0] & {
18
- /** Agent connection from useAgent */
19
- agent: ReturnType<typeof useAgent<State>>;
20
- getInitialMessages?: undefined | null | ((options: GetInitialMessagesOptions) => Promise<Message[]>);
21
- }, "fetch">;
29
+ type UseAgentChatOptions<
30
+ State,
31
+ ChatMessage extends UIMessage = UIMessage
32
+ > = Omit<UseChatParams<ChatMessage>, "fetch"> & {
33
+ /** Agent connection from useAgent */
34
+ agent: ReturnType<typeof useAgent<State>>;
35
+ getInitialMessages?:
36
+ | undefined
37
+ | null
38
+ | ((options: GetInitialMessagesOptions) => Promise<ChatMessage[]>);
39
+ /** Request credentials */
40
+ credentials?: RequestCredentials;
41
+ /** Request headers */
42
+ headers?: HeadersInit;
43
+ /**
44
+ * @description Whether to automatically resolve tool calls that do not require human interaction.
45
+ * @experimental
46
+ */
47
+ experimental_automaticToolResolution?: boolean;
48
+ /**
49
+ * @description Tools object for automatic detection of confirmation requirements.
50
+ * Tools without execute function will require confirmation.
51
+ */
52
+ tools?: Record<string, AITool<unknown, unknown>>;
53
+ /**
54
+ * @description Manual override for tools requiring confirmation.
55
+ * If not provided, will auto-detect from tools object.
56
+ */
57
+ toolsRequiringConfirmation?: string[];
58
+ /**
59
+ * When true (default), automatically sends the next message only after
60
+ * all pending confirmation-required tool calls have been resolved.
61
+ * @default true
62
+ */
63
+ autoSendAfterAllConfirmationsResolved?: boolean;
64
+ };
22
65
  /**
23
66
  * React hook for building AI chat interfaces using an Agent
24
67
  * @param options Chat options including the agent connection
25
68
  * @returns Chat interface controls and state with added clearHistory method
26
69
  */
27
- declare function useAgentChat<State = unknown>(options: UseAgentChatOptions<State>): {
28
- /**
29
- * Set the chat messages and synchronize with the Agent
30
- * @param messages New messages to set
31
- */
32
- setMessages: (messages: Message[]) => void;
33
- /**
34
- * Clear chat history on both client and Agent
35
- */
36
- clearHistory: () => void;
37
- messages: ai.UIMessage[];
38
- error: undefined | Error;
39
- append: (message: Message | ai.CreateMessage, chatRequestOptions?: ai.ChatRequestOptions) => Promise<string | null | undefined>;
40
- reload: (chatRequestOptions?: ai.ChatRequestOptions) => Promise<string | null | undefined>;
41
- stop: () => void;
42
- input: string;
43
- setInput: React.Dispatch<React.SetStateAction<string>>;
44
- handleInputChange: (e: React.ChangeEvent<HTMLInputElement> | React.ChangeEvent<HTMLTextAreaElement>) => void;
45
- handleSubmit: (event?: {
46
- preventDefault?: () => void;
47
- }, chatRequestOptions?: ai.ChatRequestOptions) => void;
48
- metadata?: Object;
49
- isLoading: boolean;
50
- status: "submitted" | "streaming" | "ready" | "error";
51
- data?: ai.JSONValue[];
52
- setData: (data: ai.JSONValue[] | undefined | ((data: ai.JSONValue[] | undefined) => ai.JSONValue[] | undefined)) => void;
53
- id: string;
54
- addToolResult: ({ toolCallId, result, }: {
55
- toolCallId: string;
56
- result: any;
57
- }) => void;
70
+ /**
71
+ * Automatically detects which tools require confirmation based on their configuration.
72
+ * Tools require confirmation if they have no execute function AND are not server-executed.
73
+ * @param tools - Record of tool name to tool definition
74
+ * @returns Array of tool names that require confirmation
75
+ */
76
+ declare function detectToolsRequiringConfirmation(
77
+ tools?: Record<string, AITool<unknown, unknown>>
78
+ ): string[];
79
+ declare function useAgentChat<
80
+ State = unknown,
81
+ ChatMessage extends UIMessage = UIMessage
82
+ >(
83
+ options: UseAgentChatOptions<State, ChatMessage>
84
+ ): ReturnType<typeof useChat<ChatMessage>> & {
85
+ clearHistory: () => void;
58
86
  };
59
-
60
- export { useAgentChat };
87
+ //#endregion
88
+ export { AITool, detectToolsRequiringConfirmation, useAgentChat };
89
+ //# sourceMappingURL=ai-react.d.ts.map