agents 0.0.0-f913299 → 0.0.0-fac1fe8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +159 -33
- package/dist/ai-chat-agent.d.ts +56 -6
- package/dist/ai-chat-agent.js +286 -97
- package/dist/ai-chat-agent.js.map +1 -1
- package/dist/ai-chat-v5-migration.d.ts +152 -0
- package/dist/ai-chat-v5-migration.js +19 -0
- package/dist/ai-react.d.ts +71 -65
- package/dist/ai-react.js +193 -72
- package/dist/ai-react.js.map +1 -1
- package/dist/ai-types.d.ts +40 -18
- package/dist/ai-types.js +6 -0
- package/dist/chunk-AVYJQSLW.js +17 -0
- package/dist/chunk-AVYJQSLW.js.map +1 -0
- package/dist/chunk-LL2AFX7V.js +109 -0
- package/dist/chunk-LL2AFX7V.js.map +1 -0
- package/dist/chunk-MH46VMM4.js +612 -0
- package/dist/chunk-MH46VMM4.js.map +1 -0
- package/dist/chunk-QEVM4BVL.js +116 -0
- package/dist/chunk-QEVM4BVL.js.map +1 -0
- package/dist/chunk-UJVEAURM.js +150 -0
- package/dist/chunk-UJVEAURM.js.map +1 -0
- package/dist/chunk-YDUDMOL6.js +1296 -0
- package/dist/chunk-YDUDMOL6.js.map +1 -0
- package/dist/client-CvaJdLQA.d.ts +5015 -0
- package/dist/client.d.ts +16 -2
- package/dist/client.js +7 -133
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +284 -22
- package/dist/index.js +15 -4
- package/dist/mcp/client.d.ts +11 -0
- package/dist/mcp/client.js +9 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/do-oauth-client-provider.d.ts +42 -0
- package/dist/mcp/do-oauth-client-provider.js +7 -0
- package/dist/mcp/do-oauth-client-provider.js.map +1 -0
- package/dist/mcp/index.d.ts +97 -0
- package/dist/mcp/index.js +1025 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/observability/index.d.ts +46 -0
- package/dist/observability/index.js +11 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/react.d.ts +89 -5
- package/dist/react.js +53 -32
- package/dist/react.js.map +1 -1
- package/dist/schedule.d.ts +81 -7
- package/dist/schedule.js +19 -8
- package/dist/schedule.js.map +1 -1
- package/dist/serializable.d.ts +32 -0
- package/dist/serializable.js +1 -0
- package/dist/serializable.js.map +1 -0
- package/package.json +95 -43
- package/src/index.ts +1243 -184
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-X6BBKLSC.js +0 -568
- package/dist/chunk-X6BBKLSC.js.map +0 -1
- /package/dist/{chunk-HMLY7DHA.js.map → ai-chat-v5-migration.js.map} +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { UIMessage } from "ai";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AI SDK v5 Migration following https://jhak.im/blog/ai-sdk-migration-handling-previously-saved-messages
|
|
5
|
+
* Using exact types from the official AI SDK documentation
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* AI SDK v5 Message Part types reference (from official AI SDK documentation)
|
|
9
|
+
*
|
|
10
|
+
* The migration logic below transforms legacy messages to match these official AI SDK v5 formats:
|
|
11
|
+
* - TextUIPart: { type: "text", text: string, state?: "streaming" | "done" }
|
|
12
|
+
* - ReasoningUIPart: { type: "reasoning", text: string, state?: "streaming" | "done", providerMetadata?: Record<string, unknown> }
|
|
13
|
+
* - FileUIPart: { type: "file", mediaType: string, filename?: string, url: string }
|
|
14
|
+
* - 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 }
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Tool invocation from v4 format
|
|
18
|
+
*/
|
|
19
|
+
type ToolInvocation = {
|
|
20
|
+
toolCallId: string;
|
|
21
|
+
toolName: string;
|
|
22
|
+
args: Record<string, unknown>;
|
|
23
|
+
result?: unknown;
|
|
24
|
+
state: "partial-call" | "call" | "result" | "error";
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Legacy part from v4 format
|
|
28
|
+
*/
|
|
29
|
+
type LegacyPart = {
|
|
30
|
+
type: string;
|
|
31
|
+
text?: string;
|
|
32
|
+
url?: string;
|
|
33
|
+
data?: string;
|
|
34
|
+
mimeType?: string;
|
|
35
|
+
mediaType?: string;
|
|
36
|
+
filename?: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Legacy message format from AI SDK v4
|
|
40
|
+
*/
|
|
41
|
+
type LegacyMessage = {
|
|
42
|
+
id?: string;
|
|
43
|
+
role: string;
|
|
44
|
+
content: string;
|
|
45
|
+
reasoning?: string;
|
|
46
|
+
toolInvocations?: ToolInvocation[];
|
|
47
|
+
parts?: LegacyPart[];
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Corrupt content item
|
|
52
|
+
*/
|
|
53
|
+
type CorruptContentItem = {
|
|
54
|
+
type: string;
|
|
55
|
+
text: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Corrupted message format - has content as array instead of parts
|
|
59
|
+
*/
|
|
60
|
+
type CorruptArrayMessage = {
|
|
61
|
+
id?: string;
|
|
62
|
+
role: string;
|
|
63
|
+
content: CorruptContentItem[];
|
|
64
|
+
reasoning?: string;
|
|
65
|
+
toolInvocations?: ToolInvocation[];
|
|
66
|
+
[key: string]: unknown;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Union type for messages that could be in any format
|
|
70
|
+
*/
|
|
71
|
+
type MigratableMessage = LegacyMessage | CorruptArrayMessage | UIMessage;
|
|
72
|
+
/**
|
|
73
|
+
* Checks if a message is already in the UIMessage format (has parts array)
|
|
74
|
+
*/
|
|
75
|
+
declare function isUIMessage(message: unknown): message is UIMessage;
|
|
76
|
+
/**
|
|
77
|
+
* Input message that could be in any format - using unknown for flexibility
|
|
78
|
+
*/
|
|
79
|
+
type InputMessage = {
|
|
80
|
+
id?: string;
|
|
81
|
+
role?: string;
|
|
82
|
+
content?: unknown;
|
|
83
|
+
reasoning?: string;
|
|
84
|
+
toolInvocations?: unknown[];
|
|
85
|
+
parts?: unknown[];
|
|
86
|
+
[key: string]: unknown;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Automatic message transformer following the blog post pattern
|
|
90
|
+
* Handles comprehensive migration from AI SDK v4 to v5 format
|
|
91
|
+
* @param message - Message in any legacy format
|
|
92
|
+
* @param index - Index for ID generation fallback
|
|
93
|
+
* @returns UIMessage in v5 format
|
|
94
|
+
*/
|
|
95
|
+
declare function autoTransformMessage(
|
|
96
|
+
message: InputMessage,
|
|
97
|
+
index?: number
|
|
98
|
+
): UIMessage;
|
|
99
|
+
/**
|
|
100
|
+
* Legacy single message migration for backward compatibility
|
|
101
|
+
*/
|
|
102
|
+
declare function migrateToUIMessage(message: MigratableMessage): UIMessage;
|
|
103
|
+
/**
|
|
104
|
+
* Automatic message transformer for arrays following the blog post pattern
|
|
105
|
+
* @param messages - Array of messages in any format
|
|
106
|
+
* @returns Array of UIMessages in v5 format
|
|
107
|
+
*/
|
|
108
|
+
declare function autoTransformMessages(messages: unknown[]): UIMessage[];
|
|
109
|
+
/**
|
|
110
|
+
* Migrates an array of messages to UIMessage format (legacy compatibility)
|
|
111
|
+
* @param messages - Array of messages in old or new format
|
|
112
|
+
* @returns Array of UIMessages in the new format
|
|
113
|
+
*/
|
|
114
|
+
declare function migrateMessagesToUIFormat(
|
|
115
|
+
messages: MigratableMessage[]
|
|
116
|
+
): UIMessage[];
|
|
117
|
+
/**
|
|
118
|
+
* Checks if any messages in an array need migration
|
|
119
|
+
* @param messages - Array of messages to check
|
|
120
|
+
* @returns true if any messages are not in proper UIMessage format
|
|
121
|
+
*/
|
|
122
|
+
declare function needsMigration(messages: unknown[]): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Analyzes the corruption types in a message array for debugging
|
|
125
|
+
* @param messages - Array of messages to analyze
|
|
126
|
+
* @returns Statistics about corruption types found
|
|
127
|
+
*/
|
|
128
|
+
declare function analyzeCorruption(messages: unknown[]): {
|
|
129
|
+
total: number;
|
|
130
|
+
clean: number;
|
|
131
|
+
legacyString: number;
|
|
132
|
+
corruptArray: number;
|
|
133
|
+
unknown: number;
|
|
134
|
+
examples: {
|
|
135
|
+
legacyString?: unknown;
|
|
136
|
+
corruptArray?: unknown;
|
|
137
|
+
unknown?: unknown;
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export {
|
|
142
|
+
type CorruptArrayMessage,
|
|
143
|
+
type LegacyMessage,
|
|
144
|
+
type MigratableMessage,
|
|
145
|
+
analyzeCorruption,
|
|
146
|
+
autoTransformMessage,
|
|
147
|
+
autoTransformMessages,
|
|
148
|
+
isUIMessage,
|
|
149
|
+
migrateMessagesToUIFormat,
|
|
150
|
+
migrateToUIMessage,
|
|
151
|
+
needsMigration
|
|
152
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeCorruption,
|
|
3
|
+
autoTransformMessage,
|
|
4
|
+
autoTransformMessages,
|
|
5
|
+
isUIMessage,
|
|
6
|
+
migrateMessagesToUIFormat,
|
|
7
|
+
migrateToUIMessage,
|
|
8
|
+
needsMigration
|
|
9
|
+
} from "./chunk-UJVEAURM.js";
|
|
10
|
+
export {
|
|
11
|
+
analyzeCorruption,
|
|
12
|
+
autoTransformMessage,
|
|
13
|
+
autoTransformMessages,
|
|
14
|
+
isUIMessage,
|
|
15
|
+
migrateMessagesToUIFormat,
|
|
16
|
+
migrateToUIMessage,
|
|
17
|
+
needsMigration
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=ai-chat-v5-migration.js.map
|
package/dist/ai-react.d.ts
CHANGED
|
@@ -1,86 +1,92 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { useChat } from "@ai-sdk/react";
|
|
1
|
+
import { UseChatOptions, useChat } from "@ai-sdk/react";
|
|
2
|
+
import { UIMessage, ChatInit } from "ai";
|
|
4
3
|
import { useAgent } from "./react.js";
|
|
5
4
|
import "partysocket";
|
|
6
5
|
import "partysocket/react";
|
|
6
|
+
import "./index.js";
|
|
7
|
+
import "cloudflare:workers";
|
|
8
|
+
import "@modelcontextprotocol/sdk/client/index.js";
|
|
9
|
+
import "@modelcontextprotocol/sdk/types.js";
|
|
10
|
+
import "partyserver";
|
|
11
|
+
import "./client-CvaJdLQA.js";
|
|
12
|
+
import "zod";
|
|
13
|
+
import "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
14
|
+
import "@modelcontextprotocol/sdk/client/sse.js";
|
|
15
|
+
import "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
16
|
+
import "./mcp/do-oauth-client-provider.js";
|
|
17
|
+
import "@modelcontextprotocol/sdk/client/auth.js";
|
|
18
|
+
import "@modelcontextprotocol/sdk/shared/auth.js";
|
|
19
|
+
import "./observability/index.js";
|
|
20
|
+
import "./ai-types.js";
|
|
7
21
|
import "./client.js";
|
|
22
|
+
import "./serializable.js";
|
|
8
23
|
|
|
24
|
+
type AITool<Input = unknown, Output = unknown> = {
|
|
25
|
+
description?: string;
|
|
26
|
+
inputSchema?: unknown;
|
|
27
|
+
execute?: (input: Input) => Output | Promise<Output>;
|
|
28
|
+
};
|
|
9
29
|
type GetInitialMessagesOptions = {
|
|
10
30
|
agent: string;
|
|
11
31
|
name: string;
|
|
12
32
|
url: string;
|
|
13
33
|
};
|
|
34
|
+
type UseChatParams<M extends UIMessage = UIMessage> = ChatInit<M> &
|
|
35
|
+
UseChatOptions<M>;
|
|
14
36
|
/**
|
|
15
37
|
* Options for the useAgentChat hook
|
|
16
38
|
*/
|
|
17
|
-
type UseAgentChatOptions
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
type UseAgentChatOptions<
|
|
40
|
+
State,
|
|
41
|
+
ChatMessage extends UIMessage = UIMessage
|
|
42
|
+
> = Omit<UseChatParams<ChatMessage>, "fetch"> & {
|
|
43
|
+
/** Agent connection from useAgent */
|
|
44
|
+
agent: ReturnType<typeof useAgent<State>>;
|
|
45
|
+
getInitialMessages?:
|
|
46
|
+
| undefined
|
|
47
|
+
| null
|
|
48
|
+
| ((options: GetInitialMessagesOptions) => Promise<ChatMessage[]>);
|
|
49
|
+
/** Request credentials */
|
|
50
|
+
credentials?: RequestCredentials;
|
|
51
|
+
/** Request headers */
|
|
52
|
+
headers?: HeadersInit;
|
|
53
|
+
/**
|
|
54
|
+
* @description Whether to automatically resolve tool calls that do not require human interaction.
|
|
55
|
+
* @experimental
|
|
56
|
+
*/
|
|
57
|
+
experimental_automaticToolResolution?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* @description Tools object for automatic detection of confirmation requirements.
|
|
60
|
+
* Tools without execute function will require confirmation.
|
|
61
|
+
*/
|
|
62
|
+
tools?: Record<string, AITool<unknown, unknown>>;
|
|
63
|
+
/**
|
|
64
|
+
* @description Manual override for tools requiring confirmation.
|
|
65
|
+
* If not provided, will auto-detect from tools object.
|
|
66
|
+
*/
|
|
67
|
+
toolsRequiringConfirmation?: string[];
|
|
68
|
+
};
|
|
28
69
|
/**
|
|
29
70
|
* React hook for building AI chat interfaces using an Agent
|
|
30
71
|
* @param options Chat options including the agent connection
|
|
31
72
|
* @returns Chat interface controls and state with added clearHistory method
|
|
32
73
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Automatically detects which tools require confirmation based on their configuration.
|
|
76
|
+
* Tools require confirmation if they have no execute function AND are not server-executed.
|
|
77
|
+
* @param tools - Record of tool name to tool definition
|
|
78
|
+
* @returns Array of tool names that require confirmation
|
|
79
|
+
*/
|
|
80
|
+
declare function detectToolsRequiringConfirmation(
|
|
81
|
+
tools?: Record<string, AITool<unknown, unknown>>
|
|
82
|
+
): string[];
|
|
83
|
+
declare function useAgentChat<
|
|
84
|
+
State = unknown,
|
|
85
|
+
ChatMessage extends UIMessage = UIMessage
|
|
86
|
+
>(
|
|
87
|
+
options: UseAgentChatOptions<State, ChatMessage>
|
|
88
|
+
): ReturnType<typeof useChat<ChatMessage>> & {
|
|
42
89
|
clearHistory: () => void;
|
|
43
|
-
messages: ai.UIMessage[];
|
|
44
|
-
error: undefined | Error;
|
|
45
|
-
append: (
|
|
46
|
-
message: Message | ai.CreateMessage,
|
|
47
|
-
chatRequestOptions?: ai.ChatRequestOptions
|
|
48
|
-
) => Promise<string | null | undefined>;
|
|
49
|
-
reload: (
|
|
50
|
-
chatRequestOptions?: ai.ChatRequestOptions
|
|
51
|
-
) => Promise<string | null | undefined>;
|
|
52
|
-
stop: () => void;
|
|
53
|
-
input: string;
|
|
54
|
-
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
55
|
-
handleInputChange: (
|
|
56
|
-
e:
|
|
57
|
-
| React.ChangeEvent<HTMLInputElement>
|
|
58
|
-
| React.ChangeEvent<HTMLTextAreaElement>
|
|
59
|
-
) => void;
|
|
60
|
-
handleSubmit: (
|
|
61
|
-
event?: {
|
|
62
|
-
preventDefault?: () => void;
|
|
63
|
-
},
|
|
64
|
-
chatRequestOptions?: ai.ChatRequestOptions
|
|
65
|
-
) => void;
|
|
66
|
-
metadata?: Object;
|
|
67
|
-
isLoading: boolean;
|
|
68
|
-
status: "submitted" | "streaming" | "ready" | "error";
|
|
69
|
-
data?: ai.JSONValue[];
|
|
70
|
-
setData: (
|
|
71
|
-
data:
|
|
72
|
-
| ai.JSONValue[]
|
|
73
|
-
| undefined
|
|
74
|
-
| ((data: ai.JSONValue[] | undefined) => ai.JSONValue[] | undefined)
|
|
75
|
-
) => void;
|
|
76
|
-
id: string;
|
|
77
|
-
addToolResult: ({
|
|
78
|
-
toolCallId,
|
|
79
|
-
result,
|
|
80
|
-
}: {
|
|
81
|
-
toolCallId: string;
|
|
82
|
-
result: any;
|
|
83
|
-
}) => void;
|
|
84
90
|
};
|
|
85
91
|
|
|
86
|
-
export { useAgentChat };
|
|
92
|
+
export { type AITool, detectToolsRequiringConfirmation, useAgentChat };
|