agents 0.0.0-d7d2876 → 0.0.0-df716f2
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 +2 -6
- package/dist/ai-chat-agent.d.ts +23 -27
- package/dist/ai-react.d.ts +45 -71
- package/dist/ai-types.d.ts +40 -60
- package/dist/client.d.ts +37 -57
- package/dist/index.d.ts +176 -219
- package/dist/mcp/client.d.ts +675 -0
- package/dist/mcp/index.d.ts +45 -0
- package/dist/react.d.ts +15 -24
- package/dist/schedule.d.ts +20 -30
- package/package.json +17 -4
- package/src/index.ts +116 -85
- package/dist/ai-chat-agent.js +0 -170
- package/dist/ai-chat-agent.js.map +0 -1
- package/dist/ai-react.js +0 -189
- package/dist/ai-react.js.map +0 -1
- package/dist/ai-types.js +0 -1
- package/dist/ai-types.js.map +0 -1
- package/dist/chunk-HMLY7DHA.js +0 -16
- package/dist/chunk-HMLY7DHA.js.map +0 -1
- package/dist/chunk-X6BBKLSC.js +0 -568
- package/dist/chunk-X6BBKLSC.js.map +0 -1
- package/dist/client.js +0 -138
- package/dist/client.js.map +0 -1
- package/dist/index.js +0 -20
- package/dist/index.js.map +0 -1
- package/dist/react.js +0 -97
- package/dist/react.js.map +0 -1
- package/dist/schedule.js +0 -73
- package/dist/schedule.js.map +0 -1
package/README.md
CHANGED
|
@@ -316,18 +316,14 @@ Create meaningful conversations with intelligence:
|
|
|
316
316
|
|
|
317
317
|
```ts
|
|
318
318
|
import { AIChatAgent } from "agents/ai-chat-agent";
|
|
319
|
-
import {
|
|
319
|
+
import { openai } from "@ai-sdk/openai";
|
|
320
320
|
|
|
321
321
|
export class DialogueAgent extends AIChatAgent {
|
|
322
322
|
async onChatMessage(onFinish) {
|
|
323
323
|
return createDataStreamResponse({
|
|
324
324
|
execute: async (dataStream) => {
|
|
325
|
-
const ai = createOpenAI({
|
|
326
|
-
apiKey: this.env.OPENAI_API_KEY,
|
|
327
|
-
});
|
|
328
|
-
|
|
329
325
|
const stream = streamText({
|
|
330
|
-
model:
|
|
326
|
+
model: openai("gpt-4o"),
|
|
331
327
|
messages: this.messages,
|
|
332
328
|
onFinish, // call onFinish so that messages get saved
|
|
333
329
|
});
|
package/dist/ai-chat-agent.d.ts
CHANGED
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
import { Agent, AgentContext } from
|
|
2
|
-
import { Message, StreamTextOnFinishCallback, ToolSet } from
|
|
3
|
-
import { Connection, WSMessage } from
|
|
4
|
-
import
|
|
1
|
+
import { Agent, AgentContext } from './index.js';
|
|
2
|
+
import { Message, StreamTextOnFinishCallback, ToolSet } from 'ai';
|
|
3
|
+
import { Connection, WSMessage } from 'partyserver';
|
|
4
|
+
import 'node:async_hooks';
|
|
5
|
+
import 'cloudflare:workers';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Extension of Agent with built-in chat capabilities
|
|
8
9
|
* @template Env Environment type containing bindings
|
|
9
10
|
*/
|
|
10
|
-
declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Save messages on the server side and trigger AI response
|
|
30
|
-
* @param messages Chat messages to save
|
|
31
|
-
*/
|
|
32
|
-
saveMessages(messages: Message[]): Promise<void>;
|
|
11
|
+
declare class AIChatAgent<Env = unknown, State = unknown> extends Agent<Env, State> {
|
|
12
|
+
#private;
|
|
13
|
+
/** Array of chat messages for the current conversation */
|
|
14
|
+
messages: Message[];
|
|
15
|
+
constructor(ctx: AgentContext, env: Env);
|
|
16
|
+
onMessage(connection: Connection, message: WSMessage): Promise<void>;
|
|
17
|
+
onRequest(request: Request): Promise<Response>;
|
|
18
|
+
/**
|
|
19
|
+
* Handle incoming chat messages and generate a response
|
|
20
|
+
* @param onFinish Callback to be called when the response is finished
|
|
21
|
+
* @returns Response to send to the client or undefined
|
|
22
|
+
*/
|
|
23
|
+
onChatMessage(onFinish: StreamTextOnFinishCallback<ToolSet>): Promise<Response | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Save messages on the server side and trigger AI response
|
|
26
|
+
* @param messages Chat messages to save
|
|
27
|
+
*/
|
|
28
|
+
saveMessages(messages: Message[]): Promise<void>;
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
export { AIChatAgent };
|
package/dist/ai-react.d.ts
CHANGED
|
@@ -1,86 +1,60 @@
|
|
|
1
|
-
import * as ai from
|
|
2
|
-
import { Message } from
|
|
3
|
-
import { useChat } from
|
|
4
|
-
import { useAgent } from
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
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';
|
|
8
8
|
|
|
9
9
|
type GetInitialMessagesOptions = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
agent: string;
|
|
11
|
+
name: string;
|
|
12
|
+
url: string;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Options for the useAgentChat hook
|
|
16
16
|
*/
|
|
17
|
-
type UseAgentChatOptions = Omit<
|
|
18
|
-
Parameters<typeof useChat>[0] & {
|
|
17
|
+
type UseAgentChatOptions<State> = Omit<Parameters<typeof useChat>[0] & {
|
|
19
18
|
/** Agent connection from useAgent */
|
|
20
|
-
agent: ReturnType<typeof useAgent
|
|
21
|
-
getInitialMessages?:
|
|
22
|
-
|
|
23
|
-
| null
|
|
24
|
-
| ((options: GetInitialMessagesOptions) => Promise<Message[]>);
|
|
25
|
-
},
|
|
26
|
-
"fetch"
|
|
27
|
-
>;
|
|
19
|
+
agent: ReturnType<typeof useAgent<State>>;
|
|
20
|
+
getInitialMessages?: undefined | null | ((options: GetInitialMessagesOptions) => Promise<Message[]>);
|
|
21
|
+
}, "fetch">;
|
|
28
22
|
/**
|
|
29
23
|
* React hook for building AI chat interfaces using an Agent
|
|
30
24
|
* @param options Chat options including the agent connection
|
|
31
25
|
* @returns Chat interface controls and state with added clearHistory method
|
|
32
26
|
*/
|
|
33
|
-
declare function useAgentChat(options: UseAgentChatOptions): {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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;
|
|
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;
|
|
84
58
|
};
|
|
85
59
|
|
|
86
60
|
export { useAgentChat };
|
package/dist/ai-types.d.ts
CHANGED
|
@@ -1,69 +1,49 @@
|
|
|
1
|
-
import { Message } from
|
|
1
|
+
import { Message } from 'ai';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Types of messages sent from the Agent to clients
|
|
5
5
|
*/
|
|
6
|
-
type OutgoingMessage =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
| {
|
|
30
|
-
/** Indicates this message is a command to clear chat history */
|
|
31
|
-
type: "cf_agent_chat_clear";
|
|
32
|
-
};
|
|
6
|
+
type OutgoingMessage = {
|
|
7
|
+
/** Indicates this message contains updated chat messages */
|
|
8
|
+
type: "cf_agent_chat_messages";
|
|
9
|
+
/** Array of chat messages */
|
|
10
|
+
messages: Message[];
|
|
11
|
+
} | {
|
|
12
|
+
/** Indicates this message is a response to a chat request */
|
|
13
|
+
type: "cf_agent_use_chat_response";
|
|
14
|
+
/** Unique ID of the request this response corresponds to */
|
|
15
|
+
id: string;
|
|
16
|
+
/** Content body of the response */
|
|
17
|
+
body: string;
|
|
18
|
+
/** Whether this is the final chunk of the response */
|
|
19
|
+
done: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
/** Indicates this message contains updated chat messages */
|
|
22
|
+
type: "cf_agent_chat_messages";
|
|
23
|
+
/** Array of chat messages */
|
|
24
|
+
messages: Message[];
|
|
25
|
+
} | {
|
|
26
|
+
/** Indicates this message is a command to clear chat history */
|
|
27
|
+
type: "cf_agent_chat_clear";
|
|
28
|
+
};
|
|
33
29
|
/**
|
|
34
30
|
* Types of messages sent from clients to the Agent
|
|
35
31
|
*/
|
|
36
|
-
type IncomingMessage =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
| "mode"
|
|
53
|
-
| "referrer"
|
|
54
|
-
| "referrerPolicy"
|
|
55
|
-
| "window"
|
|
56
|
-
>;
|
|
57
|
-
}
|
|
58
|
-
| {
|
|
59
|
-
/** Indicates this message is a command to clear chat history */
|
|
60
|
-
type: "cf_agent_chat_clear";
|
|
61
|
-
}
|
|
62
|
-
| {
|
|
63
|
-
/** Indicates this message contains updated chat messages */
|
|
64
|
-
type: "cf_agent_chat_messages";
|
|
65
|
-
/** Array of chat messages */
|
|
66
|
-
messages: Message[];
|
|
67
|
-
};
|
|
32
|
+
type IncomingMessage = {
|
|
33
|
+
/** Indicates this message is a request to the chat API */
|
|
34
|
+
type: "cf_agent_use_chat_request";
|
|
35
|
+
/** Unique ID for this request */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Request initialization options */
|
|
38
|
+
init: Pick<RequestInit, "method" | "keepalive" | "headers" | "body" | "redirect" | "integrity" | "credentials" | "mode" | "referrer" | "referrerPolicy" | "window">;
|
|
39
|
+
} | {
|
|
40
|
+
/** Indicates this message is a command to clear chat history */
|
|
41
|
+
type: "cf_agent_chat_clear";
|
|
42
|
+
} | {
|
|
43
|
+
/** Indicates this message contains updated chat messages */
|
|
44
|
+
type: "cf_agent_chat_messages";
|
|
45
|
+
/** Array of chat messages */
|
|
46
|
+
messages: Message[];
|
|
47
|
+
};
|
|
68
48
|
|
|
69
49
|
export type { IncomingMessage, OutgoingMessage };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,68 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PartySocketOptions,
|
|
3
|
-
PartyFetchOptions,
|
|
4
|
-
PartySocket,
|
|
5
|
-
} from "partysocket";
|
|
1
|
+
import { PartySocketOptions, PartyFetchOptions, PartySocket } from 'partysocket';
|
|
6
2
|
|
|
7
3
|
/**
|
|
8
4
|
* Options for creating an AgentClient
|
|
9
5
|
*/
|
|
10
|
-
type AgentClientOptions<State = unknown> = Omit<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
name?: string;
|
|
18
|
-
/** Called when the Agent's state is updated */
|
|
19
|
-
onStateUpdate?: (state: State, source: "server" | "client") => void;
|
|
6
|
+
type AgentClientOptions<State = unknown> = Omit<PartySocketOptions, "party" | "room"> & {
|
|
7
|
+
/** Name of the agent to connect to */
|
|
8
|
+
agent: string;
|
|
9
|
+
/** Name of the specific Agent instance */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** Called when the Agent's state is updated */
|
|
12
|
+
onStateUpdate?: (state: State, source: "server" | "client") => void;
|
|
20
13
|
};
|
|
21
14
|
/**
|
|
22
15
|
* Options for streaming RPC calls
|
|
23
16
|
*/
|
|
24
17
|
type StreamOptions = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
/** Called when a chunk of data is received */
|
|
19
|
+
onChunk?: (chunk: unknown) => void;
|
|
20
|
+
/** Called when the stream ends */
|
|
21
|
+
onDone?: (finalChunk: unknown) => void;
|
|
22
|
+
/** Called when an error occurs */
|
|
23
|
+
onError?: (error: string) => void;
|
|
31
24
|
};
|
|
32
25
|
/**
|
|
33
26
|
* Options for the agentFetch function
|
|
34
27
|
*/
|
|
35
28
|
type AgentClientFetchOptions = Omit<PartyFetchOptions, "party" | "room"> & {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
/** Name of the agent to connect to */
|
|
30
|
+
agent: string;
|
|
31
|
+
/** Name of the specific Agent instance */
|
|
32
|
+
name?: string;
|
|
40
33
|
};
|
|
41
34
|
/**
|
|
42
35
|
* WebSocket client for connecting to an Agent
|
|
43
36
|
*/
|
|
44
37
|
declare class AgentClient<State = unknown> extends PartySocket {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
method: string,
|
|
63
|
-
args?: unknown[],
|
|
64
|
-
streamOptions?: StreamOptions
|
|
65
|
-
): Promise<T>;
|
|
38
|
+
#private;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use agentFetch instead
|
|
41
|
+
*/
|
|
42
|
+
static fetch(_opts: PartyFetchOptions): Promise<Response>;
|
|
43
|
+
agent: string;
|
|
44
|
+
name: string;
|
|
45
|
+
constructor(options: AgentClientOptions<State>);
|
|
46
|
+
setState(state: State): void;
|
|
47
|
+
/**
|
|
48
|
+
* Call a method on the Agent
|
|
49
|
+
* @param method Name of the method to call
|
|
50
|
+
* @param args Arguments to pass to the method
|
|
51
|
+
* @param streamOptions Options for handling streaming responses
|
|
52
|
+
* @returns Promise that resolves with the method's return value
|
|
53
|
+
*/
|
|
54
|
+
call<T = unknown>(method: string, args?: unknown[], streamOptions?: StreamOptions): Promise<T>;
|
|
66
55
|
}
|
|
67
56
|
/**
|
|
68
57
|
* Make an HTTP request to an Agent
|
|
@@ -70,15 +59,6 @@ declare class AgentClient<State = unknown> extends PartySocket {
|
|
|
70
59
|
* @param init Request initialization options
|
|
71
60
|
* @returns Promise resolving to a Response
|
|
72
61
|
*/
|
|
73
|
-
declare function agentFetch(
|
|
74
|
-
opts: AgentClientFetchOptions,
|
|
75
|
-
init?: RequestInit
|
|
76
|
-
): Promise<Response>;
|
|
62
|
+
declare function agentFetch(opts: AgentClientFetchOptions, init?: RequestInit): Promise<Response>;
|
|
77
63
|
|
|
78
|
-
export {
|
|
79
|
-
AgentClient,
|
|
80
|
-
type AgentClientFetchOptions,
|
|
81
|
-
type AgentClientOptions,
|
|
82
|
-
type StreamOptions,
|
|
83
|
-
agentFetch,
|
|
84
|
-
};
|
|
64
|
+
export { AgentClient, type AgentClientFetchOptions, type AgentClientOptions, type StreamOptions, agentFetch };
|