agents 0.0.0-dfa677f → 0.0.0-e135cf5

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 (74) hide show
  1. package/README.md +255 -27
  2. package/dist/ai-chat-agent.d.ts +59 -11
  3. package/dist/ai-chat-agent.js +532 -159
  4. package/dist/ai-chat-agent.js.map +1 -1
  5. package/dist/ai-chat-v5-migration-DBHGW4Hv.js +155 -0
  6. package/dist/ai-chat-v5-migration-DBHGW4Hv.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 +73 -72
  10. package/dist/ai-react.js +261 -185
  11. package/dist/ai-react.js.map +1 -1
  12. package/dist/ai-types-B3aQaFv3.js +20 -0
  13. package/dist/ai-types-B3aQaFv3.js.map +1 -0
  14. package/dist/ai-types-D5YoPrBZ.d.ts +95 -0
  15. package/dist/ai-types.d.ts +6 -69
  16. package/dist/ai-types.js +3 -1
  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-BfiZ3HQd.js +117 -0
  21. package/dist/client-BfiZ3HQd.js.map +1 -0
  22. package/dist/client-CbWe9FBd.d.ts +104 -0
  23. package/dist/client-DZhjV_XA.js +719 -0
  24. package/dist/client-DZhjV_XA.js.map +1 -0
  25. package/dist/client-DZuq0CXm.d.ts +5283 -0
  26. package/dist/client.d.ts +12 -79
  27. package/dist/client.js +3 -137
  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-CswoD5Lu.js +93 -0
  32. package/dist/do-oauth-client-provider-CswoD5Lu.js.map +1 -0
  33. package/dist/do-oauth-client-provider-DGc5pP0l.d.ts +55 -0
  34. package/dist/index-DHakc8tU.d.ts +566 -0
  35. package/dist/index-DhJCaDWd.d.ts +58 -0
  36. package/dist/index.d.ts +63 -302
  37. package/dist/index.js +7 -22
  38. package/dist/mcp/client.d.ts +4 -0
  39. package/dist/mcp/client.js +3 -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 +193 -0
  43. package/dist/mcp/index.js +1440 -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 +194 -0
  47. package/dist/mcp/x402.js.map +1 -0
  48. package/dist/mcp-Dw5vDrY8.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-Ce7gmqP6.d.ts +113 -0
  52. package/dist/react.d.ts +10 -39
  53. package/dist/react.js +185 -93
  54. package/dist/react.js.map +1 -1
  55. package/dist/schedule.d.ts +89 -12
  56. package/dist/schedule.js +46 -23
  57. package/dist/schedule.js.map +1 -1
  58. package/dist/serializable-CymX8ovI.d.ts +39 -0
  59. package/dist/serializable.d.ts +7 -0
  60. package/dist/serializable.js +1 -0
  61. package/dist/src-C8K3lu37.js +1231 -0
  62. package/dist/src-C8K3lu37.js.map +1 -0
  63. package/package.json +133 -51
  64. package/dist/ai-types.js.map +0 -1
  65. package/dist/chunk-HMLY7DHA.js +0 -16
  66. package/dist/chunk-HMLY7DHA.js.map +0 -1
  67. package/dist/chunk-KRBQHBPA.js +0 -599
  68. package/dist/chunk-KRBQHBPA.js.map +0 -1
  69. package/dist/client.js.map +0 -1
  70. package/dist/index.js.map +0 -1
  71. package/dist/mcp.d.ts +0 -58
  72. package/dist/mcp.js +0 -945
  73. package/dist/mcp.js.map +0 -1
  74. package/src/index.ts +0 -925
@@ -0,0 +1,95 @@
1
+ import { UIMessage } from "ai";
2
+
3
+ //#region src/ai-types.d.ts
4
+
5
+ /**
6
+ * Enum for message types to improve type safety and maintainability
7
+ */
8
+ declare enum MessageType {
9
+ CF_AGENT_CHAT_MESSAGES = "cf_agent_chat_messages",
10
+ CF_AGENT_USE_CHAT_REQUEST = "cf_agent_use_chat_request",
11
+ CF_AGENT_USE_CHAT_RESPONSE = "cf_agent_use_chat_response",
12
+ CF_AGENT_CHAT_CLEAR = "cf_agent_chat_clear",
13
+ CF_AGENT_CHAT_REQUEST_CANCEL = "cf_agent_chat_request_cancel",
14
+ CF_AGENT_MCP_SERVERS = "cf_agent_mcp_servers",
15
+ CF_MCP_AGENT_EVENT = "cf_mcp_agent_event",
16
+ CF_AGENT_STATE = "cf_agent_state",
17
+ RPC = "rpc"
18
+ }
19
+ /**
20
+ * Types of messages sent from the Agent to clients
21
+ */
22
+ type OutgoingMessage<ChatMessage extends UIMessage = UIMessage> =
23
+ | {
24
+ /** Indicates this message is a command to clear chat history */
25
+ type: MessageType.CF_AGENT_CHAT_CLEAR;
26
+ }
27
+ | {
28
+ /** Indicates this message contains updated chat messages */
29
+ type: MessageType.CF_AGENT_CHAT_MESSAGES;
30
+ /** Array of chat messages */
31
+ messages: ChatMessage[];
32
+ }
33
+ | {
34
+ /** Indicates this message is a response to a chat request */
35
+ type: MessageType.CF_AGENT_USE_CHAT_RESPONSE;
36
+ /** Unique ID of the request this response corresponds to */
37
+ id: string;
38
+ /** Content body of the response */
39
+ body: string;
40
+ /** Whether this is the final chunk of the response */
41
+ done: boolean;
42
+ /** Whether this response contains an error */
43
+ error?: boolean;
44
+ }
45
+ | {
46
+ /** Indicates this message is a command to clear chat history */
47
+ type: MessageType.CF_AGENT_CHAT_CLEAR;
48
+ };
49
+ /**
50
+ * Types of messages sent from clients to the Agent
51
+ */
52
+ type IncomingMessage<ChatMessage extends UIMessage = UIMessage> =
53
+ | {
54
+ /** Indicates this message is a command to clear chat history */
55
+ type: MessageType.CF_AGENT_CHAT_CLEAR;
56
+ }
57
+ | {
58
+ /** Indicates this message is a request to the chat API */
59
+ type: MessageType.CF_AGENT_USE_CHAT_REQUEST;
60
+ /** Unique ID for this request */
61
+ id: string;
62
+ /** Request initialization options */
63
+ init: Pick<
64
+ RequestInit,
65
+ | "method"
66
+ | "keepalive"
67
+ | "headers"
68
+ | "body"
69
+ | "redirect"
70
+ | "integrity"
71
+ | "credentials"
72
+ | "mode"
73
+ | "referrer"
74
+ | "referrerPolicy"
75
+ | "window"
76
+ >;
77
+ }
78
+ | {
79
+ /** Indicates this message is a command to clear chat history */
80
+ type: MessageType.CF_AGENT_CHAT_CLEAR;
81
+ }
82
+ | {
83
+ /** Indicates this message contains updated chat messages */
84
+ type: MessageType.CF_AGENT_CHAT_MESSAGES;
85
+ /** Array of chat messages */
86
+ messages: ChatMessage[];
87
+ }
88
+ | {
89
+ /** Indicates the user wants to stop generation of this message */
90
+ type: MessageType.CF_AGENT_CHAT_REQUEST_CANCEL;
91
+ id: string;
92
+ };
93
+ //#endregion
94
+ export { MessageType as n, OutgoingMessage as r, IncomingMessage as t };
95
+ //# sourceMappingURL=ai-types-D5YoPrBZ.d.ts.map
@@ -1,69 +1,6 @@
1
- import { Message } from "ai";
2
-
3
- /**
4
- * Types of messages sent from the Agent to clients
5
- */
6
- type OutgoingMessage =
7
- | {
8
- /** Indicates this message contains updated chat messages */
9
- type: "cf_agent_chat_messages";
10
- /** Array of chat messages */
11
- messages: Message[];
12
- }
13
- | {
14
- /** Indicates this message is a response to a chat request */
15
- type: "cf_agent_use_chat_response";
16
- /** Unique ID of the request this response corresponds to */
17
- id: string;
18
- /** Content body of the response */
19
- body: string;
20
- /** Whether this is the final chunk of the response */
21
- done: boolean;
22
- }
23
- | {
24
- /** Indicates this message contains updated chat messages */
25
- type: "cf_agent_chat_messages";
26
- /** Array of chat messages */
27
- messages: Message[];
28
- }
29
- | {
30
- /** Indicates this message is a command to clear chat history */
31
- type: "cf_agent_chat_clear";
32
- };
33
- /**
34
- * Types of messages sent from clients to the Agent
35
- */
36
- type IncomingMessage =
37
- | {
38
- /** Indicates this message is a request to the chat API */
39
- type: "cf_agent_use_chat_request";
40
- /** Unique ID for this request */
41
- id: string;
42
- /** Request initialization options */
43
- init: Pick<
44
- RequestInit,
45
- | "method"
46
- | "keepalive"
47
- | "headers"
48
- | "body"
49
- | "redirect"
50
- | "integrity"
51
- | "credentials"
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
- };
68
-
69
- export type { IncomingMessage, OutgoingMessage };
1
+ import {
2
+ n as MessageType,
3
+ r as OutgoingMessage,
4
+ t as IncomingMessage
5
+ } from "./ai-types-D5YoPrBZ.js";
6
+ export { IncomingMessage, MessageType, OutgoingMessage };
package/dist/ai-types.js CHANGED
@@ -1 +1,3 @@
1
- //# sourceMappingURL=ai-types.js.map
1
+ import { t as MessageType } from "./ai-types-B3aQaFv3.js";
2
+
3
+ export { MessageType };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import * as yargs0 from "yargs";
3
+
4
+ //#region src/cli.d.ts
5
+ declare function createCli(argv?: string[]): yargs0.Argv<{}>;
6
+ //#endregion
7
+ export { createCli };
8
+ //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from "node:url";
3
+ import yargs from "yargs";
4
+ import { hideBin } from "yargs/helpers";
5
+
6
+ //#region src/cli.ts
7
+ function createCli(argv = process.argv) {
8
+ return yargs(hideBin(argv)).scriptName("agents").usage("$0 <command> [options]").command(["init", "create"], "Initialize an agents project", (cmd) => cmd, async () => {
9
+ console.log("agents init: not implemented yet");
10
+ process.exit(0);
11
+ }).command("dev", "Start development server", (cmd) => cmd, async () => {
12
+ console.log("agents dev: not implemented yet");
13
+ process.exit(0);
14
+ }).command("deploy", "Deploy agents to Cloudflare", (cmd) => cmd, async () => {
15
+ console.log("agents deploy: not implemented yet");
16
+ process.exit(0);
17
+ }).command("mcp", "The agents mcp server", (cmd) => cmd, async () => {
18
+ console.log("agents mcp: not implemented yet");
19
+ process.exit(0);
20
+ }).demandCommand(1, "Please provide a command").strict().help();
21
+ }
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ if (process.argv[1] && fileURLToPath(new URL(process.argv[1], "file://")) === __filename) createCli().parse();
24
+
25
+ //#endregion
26
+ export { createCli };
27
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { fileURLToPath } from \"node:url\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\n\nexport function createCli(argv = process.argv) {\n return yargs(hideBin(argv))\n .scriptName(\"agents\")\n .usage(\"$0 <command> [options]\")\n .command(\n [\"init\", \"create\"],\n \"Initialize an agents project\",\n (cmd) => cmd,\n async () => {\n console.log(\"agents init: not implemented yet\");\n process.exit(0);\n }\n )\n .command(\n \"dev\",\n \"Start development server\",\n (cmd) => cmd,\n async () => {\n console.log(\"agents dev: not implemented yet\");\n process.exit(0);\n }\n )\n .command(\n \"deploy\",\n \"Deploy agents to Cloudflare\",\n (cmd) => cmd,\n async () => {\n console.log(\"agents deploy: not implemented yet\");\n process.exit(0);\n }\n )\n .command(\n \"mcp\",\n \"The agents mcp server\",\n (cmd) => cmd,\n async () => {\n console.log(\"agents mcp: not implemented yet\");\n process.exit(0);\n }\n )\n .demandCommand(1, \"Please provide a command\")\n .strict()\n .help();\n}\n\n// Run CLI if this is the main module\nconst __filename = fileURLToPath(import.meta.url);\n\n// Check if this file was run directly (not imported)\nif (\n process.argv[1] &&\n fileURLToPath(new URL(process.argv[1], \"file://\")) === __filename\n) {\n void createCli().parse();\n}\n"],"mappings":";;;;;;AAMA,SAAgB,UAAU,OAAO,QAAQ,MAAM;AAC7C,QAAO,MAAM,QAAQ,KAAK,CAAC,CACxB,WAAW,SAAS,CACpB,MAAM,yBAAyB,CAC/B,QACC,CAAC,QAAQ,SAAS,EAClB,iCACC,QAAQ,KACT,YAAY;AACV,UAAQ,IAAI,mCAAmC;AAC/C,UAAQ,KAAK,EAAE;GAElB,CACA,QACC,OACA,6BACC,QAAQ,KACT,YAAY;AACV,UAAQ,IAAI,kCAAkC;AAC9C,UAAQ,KAAK,EAAE;GAElB,CACA,QACC,UACA,gCACC,QAAQ,KACT,YAAY;AACV,UAAQ,IAAI,qCAAqC;AACjD,UAAQ,KAAK,EAAE;GAElB,CACA,QACC,OACA,0BACC,QAAQ,KACT,YAAY;AACV,UAAQ,IAAI,kCAAkC;AAC9C,UAAQ,KAAK,EAAE;GAElB,CACA,cAAc,GAAG,2BAA2B,CAC5C,QAAQ,CACR,MAAM;;AAIX,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AAGjD,IACE,QAAQ,KAAK,MACb,cAAc,IAAI,IAAI,QAAQ,KAAK,IAAI,UAAU,CAAC,KAAK,WAEvD,CAAK,WAAW,CAAC,OAAO"}
@@ -0,0 +1,117 @@
1
+ import { t as MessageType } from "./ai-types-B3aQaFv3.js";
2
+ import { PartySocket } from "partysocket";
3
+
4
+ //#region src/client.ts
5
+ /**
6
+ * Convert a camelCase string to a kebab-case string
7
+ * @param str The string to convert
8
+ * @returns The kebab-case string
9
+ */
10
+ function camelCaseToKebabCase(str) {
11
+ if (str === str.toUpperCase() && str !== str.toLowerCase()) return str.toLowerCase().replace(/_/g, "-");
12
+ let kebabified = str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
13
+ kebabified = kebabified.startsWith("-") ? kebabified.slice(1) : kebabified;
14
+ return kebabified.replace(/_/g, "-").replace(/-$/, "");
15
+ }
16
+ /**
17
+ * WebSocket client for connecting to an Agent
18
+ */
19
+ var AgentClient = class extends PartySocket {
20
+ /**
21
+ * @deprecated Use agentFetch instead
22
+ */
23
+ static fetch(_opts) {
24
+ throw new Error("AgentClient.fetch is not implemented, use agentFetch instead");
25
+ }
26
+ constructor(options) {
27
+ const agentNamespace = camelCaseToKebabCase(options.agent);
28
+ super({
29
+ party: agentNamespace,
30
+ prefix: "agents",
31
+ room: options.name || "default",
32
+ ...options
33
+ });
34
+ this._pendingCalls = /* @__PURE__ */ new Map();
35
+ this.agent = agentNamespace;
36
+ this.name = options.name || "default";
37
+ this.options = options;
38
+ this.addEventListener("message", (event) => {
39
+ if (typeof event.data === "string") {
40
+ let parsedMessage;
41
+ try {
42
+ parsedMessage = JSON.parse(event.data);
43
+ } catch (_error) {
44
+ return;
45
+ }
46
+ if (parsedMessage.type === MessageType.CF_AGENT_STATE) {
47
+ this.options.onStateUpdate?.(parsedMessage.state, "server");
48
+ return;
49
+ }
50
+ if (parsedMessage.type === MessageType.RPC) {
51
+ const response = parsedMessage;
52
+ const pending = this._pendingCalls.get(response.id);
53
+ if (!pending) return;
54
+ if (!response.success) {
55
+ pending.reject(new Error(response.error));
56
+ this._pendingCalls.delete(response.id);
57
+ pending.stream?.onError?.(response.error);
58
+ return;
59
+ }
60
+ if ("done" in response) if (response.done) {
61
+ pending.resolve(response.result);
62
+ this._pendingCalls.delete(response.id);
63
+ pending.stream?.onDone?.(response.result);
64
+ } else pending.stream?.onChunk?.(response.result);
65
+ else {
66
+ pending.resolve(response.result);
67
+ this._pendingCalls.delete(response.id);
68
+ }
69
+ }
70
+ }
71
+ });
72
+ }
73
+ setState(state) {
74
+ this.send(JSON.stringify({
75
+ state,
76
+ type: MessageType.CF_AGENT_STATE
77
+ }));
78
+ this.options.onStateUpdate?.(state, "client");
79
+ }
80
+ async call(method, args = [], streamOptions) {
81
+ return new Promise((resolve, reject) => {
82
+ const id = Math.random().toString(36).slice(2);
83
+ this._pendingCalls.set(id, {
84
+ reject,
85
+ resolve: (value) => resolve(value),
86
+ stream: streamOptions,
87
+ type: null
88
+ });
89
+ const request = {
90
+ args,
91
+ id,
92
+ method,
93
+ type: MessageType.RPC
94
+ };
95
+ this.send(JSON.stringify(request));
96
+ });
97
+ }
98
+ };
99
+ /**
100
+ * Make an HTTP request to an Agent
101
+ * @param opts Connection options
102
+ * @param init Request initialization options
103
+ * @returns Promise resolving to a Response
104
+ */
105
+ function agentFetch(opts, init) {
106
+ const agentNamespace = camelCaseToKebabCase(opts.agent);
107
+ return PartySocket.fetch({
108
+ party: agentNamespace,
109
+ prefix: "agents",
110
+ room: opts.name || "default",
111
+ ...opts
112
+ }, init);
113
+ }
114
+
115
+ //#endregion
116
+ export { agentFetch as n, camelCaseToKebabCase as r, AgentClient as t };
117
+ //# sourceMappingURL=client-BfiZ3HQd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-BfiZ3HQd.js","names":["parsedMessage: Record<string, unknown>","request: RPCRequest"],"sources":["../src/client.ts"],"sourcesContent":["import {\n type PartyFetchOptions,\n PartySocket,\n type PartySocketOptions\n} from \"partysocket\";\nimport type { RPCRequest, RPCResponse } from \"./\";\nimport type {\n SerializableReturnValue,\n SerializableValue\n} from \"./serializable\";\nimport { MessageType } from \"./ai-types\";\n\n/**\n * Options for creating an AgentClient\n */\nexport type AgentClientOptions<State = unknown> = Omit<\n PartySocketOptions,\n \"party\" | \"room\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n /** Called when the Agent's state is updated */\n onStateUpdate?: (state: State, source: \"server\" | \"client\") => void;\n};\n\n/**\n * Options for streaming RPC calls\n */\nexport type StreamOptions = {\n /** Called when a chunk of data is received */\n onChunk?: (chunk: unknown) => void;\n /** Called when the stream ends */\n onDone?: (finalChunk: unknown) => void;\n /** Called when an error occurs */\n onError?: (error: string) => void;\n};\n\n/**\n * Options for the agentFetch function\n */\nexport type AgentClientFetchOptions = Omit<\n PartyFetchOptions,\n \"party\" | \"room\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n};\n\n/**\n * Convert a camelCase string to a kebab-case string\n * @param str The string to convert\n * @returns The kebab-case string\n */\nexport function camelCaseToKebabCase(str: string): string {\n // If string is all uppercase, convert to lowercase\n if (str === str.toUpperCase() && str !== str.toLowerCase()) {\n return str.toLowerCase().replace(/_/g, \"-\");\n }\n\n // Otherwise handle camelCase to kebab-case\n let kebabified = str.replace(\n /[A-Z]/g,\n (letter) => `-${letter.toLowerCase()}`\n );\n kebabified = kebabified.startsWith(\"-\") ? kebabified.slice(1) : kebabified;\n // Convert any remaining underscores to hyphens and remove trailing -'s\n return kebabified.replace(/_/g, \"-\").replace(/-$/, \"\");\n}\n\n/**\n * WebSocket client for connecting to an Agent\n */\nexport class AgentClient<State = unknown> extends PartySocket {\n /**\n * @deprecated Use agentFetch instead\n */\n static fetch(_opts: PartyFetchOptions): Promise<Response> {\n throw new Error(\n \"AgentClient.fetch is not implemented, use agentFetch instead\"\n );\n }\n agent: string;\n name: string;\n private options: AgentClientOptions<State>;\n private _pendingCalls = new Map<\n string,\n {\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n stream?: StreamOptions;\n type?: unknown;\n }\n >();\n\n constructor(options: AgentClientOptions<State>) {\n const agentNamespace = camelCaseToKebabCase(options.agent);\n super({\n party: agentNamespace,\n prefix: \"agents\",\n room: options.name || \"default\",\n ...options\n });\n this.agent = agentNamespace;\n this.name = options.name || \"default\";\n this.options = options;\n\n this.addEventListener(\"message\", (event) => {\n if (typeof event.data === \"string\") {\n let parsedMessage: Record<string, unknown>;\n try {\n parsedMessage = JSON.parse(event.data);\n } catch (_error) {\n // silently ignore invalid messages for now\n // TODO: log errors with log levels\n return;\n }\n if (parsedMessage.type === MessageType.CF_AGENT_STATE) {\n this.options.onStateUpdate?.(parsedMessage.state as State, \"server\");\n return;\n }\n if (parsedMessage.type === MessageType.RPC) {\n const response = parsedMessage as RPCResponse;\n const pending = this._pendingCalls.get(response.id);\n if (!pending) return;\n\n if (!response.success) {\n pending.reject(new Error(response.error));\n this._pendingCalls.delete(response.id);\n pending.stream?.onError?.(response.error);\n return;\n }\n\n // Handle streaming responses\n if (\"done\" in response) {\n if (response.done) {\n pending.resolve(response.result);\n this._pendingCalls.delete(response.id);\n pending.stream?.onDone?.(response.result);\n } else {\n pending.stream?.onChunk?.(response.result);\n }\n } else {\n // Non-streaming response\n pending.resolve(response.result);\n this._pendingCalls.delete(response.id);\n }\n }\n }\n });\n }\n\n setState(state: State) {\n this.send(JSON.stringify({ state, type: MessageType.CF_AGENT_STATE }));\n this.options.onStateUpdate?.(state, \"client\");\n }\n\n /**\n * Call a method on the Agent\n * @param method Name of the method to call\n * @param args Arguments to pass to the method\n * @param streamOptions Options for handling streaming responses\n * @returns Promise that resolves with the method's return value\n */\n call<T extends SerializableReturnValue>(\n method: string,\n args?: SerializableValue[],\n streamOptions?: StreamOptions\n ): Promise<T>;\n call<T = unknown>(\n method: string,\n args?: unknown[],\n streamOptions?: StreamOptions\n ): Promise<T>;\n async call<T>(\n method: string,\n args: unknown[] = [],\n streamOptions?: StreamOptions\n ): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const id = Math.random().toString(36).slice(2);\n this._pendingCalls.set(id, {\n reject,\n resolve: (value: unknown) => resolve(value as T),\n stream: streamOptions,\n type: null as T\n });\n\n const request: RPCRequest = {\n args,\n id,\n method,\n type: MessageType.RPC\n };\n\n this.send(JSON.stringify(request));\n });\n }\n}\n\n/**\n * Make an HTTP request to an Agent\n * @param opts Connection options\n * @param init Request initialization options\n * @returns Promise resolving to a Response\n */\nexport function agentFetch(opts: AgentClientFetchOptions, init?: RequestInit) {\n const agentNamespace = camelCaseToKebabCase(opts.agent);\n\n return PartySocket.fetch(\n {\n party: agentNamespace,\n prefix: \"agents\",\n room: opts.name || \"default\",\n ...opts\n },\n init\n );\n}\n"],"mappings":";;;;;;;;;AAyDA,SAAgB,qBAAqB,KAAqB;AAExD,KAAI,QAAQ,IAAI,aAAa,IAAI,QAAQ,IAAI,aAAa,CACxD,QAAO,IAAI,aAAa,CAAC,QAAQ,MAAM,IAAI;CAI7C,IAAI,aAAa,IAAI,QACnB,WACC,WAAW,IAAI,OAAO,aAAa,GACrC;AACD,cAAa,WAAW,WAAW,IAAI,GAAG,WAAW,MAAM,EAAE,GAAG;AAEhE,QAAO,WAAW,QAAQ,MAAM,IAAI,CAAC,QAAQ,MAAM,GAAG;;;;;AAMxD,IAAa,cAAb,cAAkD,YAAY;;;;CAI5D,OAAO,MAAM,OAA6C;AACxD,QAAM,IAAI,MACR,+DACD;;CAeH,YAAY,SAAoC;EAC9C,MAAM,iBAAiB,qBAAqB,QAAQ,MAAM;AAC1D,QAAM;GACJ,OAAO;GACP,QAAQ;GACR,MAAM,QAAQ,QAAQ;GACtB,GAAG;GACJ,CAAC;uCAjBoB,IAAI,KAQzB;AAUD,OAAK,QAAQ;AACb,OAAK,OAAO,QAAQ,QAAQ;AAC5B,OAAK,UAAU;AAEf,OAAK,iBAAiB,YAAY,UAAU;AAC1C,OAAI,OAAO,MAAM,SAAS,UAAU;IAClC,IAAIA;AACJ,QAAI;AACF,qBAAgB,KAAK,MAAM,MAAM,KAAK;aAC/B,QAAQ;AAGf;;AAEF,QAAI,cAAc,SAAS,YAAY,gBAAgB;AACrD,UAAK,QAAQ,gBAAgB,cAAc,OAAgB,SAAS;AACpE;;AAEF,QAAI,cAAc,SAAS,YAAY,KAAK;KAC1C,MAAM,WAAW;KACjB,MAAM,UAAU,KAAK,cAAc,IAAI,SAAS,GAAG;AACnD,SAAI,CAAC,QAAS;AAEd,SAAI,CAAC,SAAS,SAAS;AACrB,cAAQ,OAAO,IAAI,MAAM,SAAS,MAAM,CAAC;AACzC,WAAK,cAAc,OAAO,SAAS,GAAG;AACtC,cAAQ,QAAQ,UAAU,SAAS,MAAM;AACzC;;AAIF,SAAI,UAAU,SACZ,KAAI,SAAS,MAAM;AACjB,cAAQ,QAAQ,SAAS,OAAO;AAChC,WAAK,cAAc,OAAO,SAAS,GAAG;AACtC,cAAQ,QAAQ,SAAS,SAAS,OAAO;WAEzC,SAAQ,QAAQ,UAAU,SAAS,OAAO;UAEvC;AAEL,cAAQ,QAAQ,SAAS,OAAO;AAChC,WAAK,cAAc,OAAO,SAAS,GAAG;;;;IAI5C;;CAGJ,SAAS,OAAc;AACrB,OAAK,KAAK,KAAK,UAAU;GAAE;GAAO,MAAM,YAAY;GAAgB,CAAC,CAAC;AACtE,OAAK,QAAQ,gBAAgB,OAAO,SAAS;;CAoB/C,MAAM,KACJ,QACA,OAAkB,EAAE,EACpB,eACY;AACZ,SAAO,IAAI,SAAY,SAAS,WAAW;GACzC,MAAM,KAAK,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE;AAC9C,QAAK,cAAc,IAAI,IAAI;IACzB;IACA,UAAU,UAAmB,QAAQ,MAAW;IAChD,QAAQ;IACR,MAAM;IACP,CAAC;GAEF,MAAMC,UAAsB;IAC1B;IACA;IACA;IACA,MAAM,YAAY;IACnB;AAED,QAAK,KAAK,KAAK,UAAU,QAAQ,CAAC;IAClC;;;;;;;;;AAUN,SAAgB,WAAW,MAA+B,MAAoB;CAC5E,MAAM,iBAAiB,qBAAqB,KAAK,MAAM;AAEvD,QAAO,YAAY,MACjB;EACE,OAAO;EACP,QAAQ;EACR,MAAM,KAAK,QAAQ;EACnB,GAAG;EACJ,EACD,KACD"}
@@ -0,0 +1,104 @@
1
+ import {
2
+ i as SerializableValue,
3
+ r as SerializableReturnValue
4
+ } from "./serializable-CymX8ovI.js";
5
+ import {
6
+ PartyFetchOptions,
7
+ PartySocket,
8
+ PartySocketOptions
9
+ } from "partysocket";
10
+
11
+ //#region src/client.d.ts
12
+
13
+ /**
14
+ * Options for creating an AgentClient
15
+ */
16
+ type AgentClientOptions<State = unknown> = Omit<
17
+ PartySocketOptions,
18
+ "party" | "room"
19
+ > & {
20
+ /** Name of the agent to connect to */
21
+ agent: string;
22
+ /** Name of the specific Agent instance */
23
+ name?: string;
24
+ /** Called when the Agent's state is updated */
25
+ onStateUpdate?: (state: State, source: "server" | "client") => void;
26
+ };
27
+ /**
28
+ * Options for streaming RPC calls
29
+ */
30
+ type StreamOptions = {
31
+ /** Called when a chunk of data is received */
32
+ onChunk?: (chunk: unknown) => void;
33
+ /** Called when the stream ends */
34
+ onDone?: (finalChunk: unknown) => void;
35
+ /** Called when an error occurs */
36
+ onError?: (error: string) => void;
37
+ };
38
+ /**
39
+ * Options for the agentFetch function
40
+ */
41
+ type AgentClientFetchOptions = Omit<PartyFetchOptions, "party" | "room"> & {
42
+ /** Name of the agent to connect to */
43
+ agent: string;
44
+ /** Name of the specific Agent instance */
45
+ name?: string;
46
+ };
47
+ /**
48
+ * Convert a camelCase string to a kebab-case string
49
+ * @param str The string to convert
50
+ * @returns The kebab-case string
51
+ */
52
+ declare function camelCaseToKebabCase(str: string): string;
53
+ /**
54
+ * WebSocket client for connecting to an Agent
55
+ */
56
+ declare class AgentClient<State = unknown> extends PartySocket {
57
+ /**
58
+ * @deprecated Use agentFetch instead
59
+ */
60
+ static fetch(_opts: PartyFetchOptions): Promise<Response>;
61
+ agent: string;
62
+ name: string;
63
+ private options;
64
+ private _pendingCalls;
65
+ constructor(options: AgentClientOptions<State>);
66
+ setState(state: State): void;
67
+ /**
68
+ * Call a method on the Agent
69
+ * @param method Name of the method to call
70
+ * @param args Arguments to pass to the method
71
+ * @param streamOptions Options for handling streaming responses
72
+ * @returns Promise that resolves with the method's return value
73
+ */
74
+ call<T extends SerializableReturnValue>(
75
+ method: string,
76
+ args?: SerializableValue[],
77
+ streamOptions?: StreamOptions
78
+ ): Promise<T>;
79
+ call<T = unknown>(
80
+ method: string,
81
+ args?: unknown[],
82
+ streamOptions?: StreamOptions
83
+ ): Promise<T>;
84
+ }
85
+ /**
86
+ * Make an HTTP request to an Agent
87
+ * @param opts Connection options
88
+ * @param init Request initialization options
89
+ * @returns Promise resolving to a Response
90
+ */
91
+ declare function agentFetch(
92
+ opts: AgentClientFetchOptions,
93
+ init?: RequestInit
94
+ ): Promise<Response>;
95
+ //#endregion
96
+ export {
97
+ agentFetch as a,
98
+ StreamOptions as i,
99
+ AgentClientFetchOptions as n,
100
+ camelCaseToKebabCase as o,
101
+ AgentClientOptions as r,
102
+ AgentClient as t
103
+ };
104
+ //# sourceMappingURL=client-CbWe9FBd.d.ts.map