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,113 @@
1
+ import { m as MCPServersState, t as Agent } from "./index-BygUGrr9.js";
2
+ import { n as RPCMethod, t as Method } from "./serializable-faDkMCai.js";
3
+ import { i as StreamOptions } from "./client-BAQA84dr.js";
4
+ import { PartySocket } from "partysocket";
5
+ import { usePartySocket } from "partysocket/react";
6
+
7
+ //#region src/react.d.ts
8
+ type QueryObject = Record<string, string | null>;
9
+ /**
10
+ * Options for the useAgent hook
11
+ * @template State Type of the Agent's state
12
+ */
13
+ type UseAgentOptions<State = unknown> = Omit<
14
+ Parameters<typeof usePartySocket>[0],
15
+ "party" | "room" | "query"
16
+ > & {
17
+ /** Name of the agent to connect to */
18
+ agent: string;
19
+ /** Name of the specific Agent instance */
20
+ name?: string;
21
+ /** Query parameters - can be static object or async function */
22
+ query?: QueryObject | (() => Promise<QueryObject>);
23
+ /** Dependencies for async query caching */
24
+ queryDeps?: unknown[];
25
+ /** Cache TTL in milliseconds for auth tokens/time-sensitive data */
26
+ cacheTtl?: number;
27
+ /** Called when the Agent's state is updated */
28
+ onStateUpdate?: (state: State, source: "server" | "client") => void;
29
+ /** Called when MCP server state is updated */
30
+ onMcpUpdate?: (mcpServers: MCPServersState) => void;
31
+ };
32
+ type AllOptional<T> = T extends [infer A, ...infer R]
33
+ ? undefined extends A
34
+ ? AllOptional<R>
35
+ : false
36
+ : true;
37
+ type RPCMethods<T> = {
38
+ [K in keyof T as T[K] extends RPCMethod<T[K]> ? K : never]: RPCMethod<T[K]>;
39
+ };
40
+ type OptionalParametersMethod<T extends RPCMethod> =
41
+ AllOptional<Parameters<T>> extends true ? T : never;
42
+ type AgentMethods<T> = Omit<RPCMethods<T>, keyof Agent<any, any>>;
43
+ type OptionalAgentMethods<T> = {
44
+ [K in keyof AgentMethods<T> as AgentMethods<T>[K] extends OptionalParametersMethod<
45
+ AgentMethods<T>[K]
46
+ >
47
+ ? K
48
+ : never]: OptionalParametersMethod<AgentMethods<T>[K]>;
49
+ };
50
+ type RequiredAgentMethods<T> = Omit<
51
+ AgentMethods<T>,
52
+ keyof OptionalAgentMethods<T>
53
+ >;
54
+ type AgentPromiseReturnType<T, K$1 extends keyof AgentMethods<T>> =
55
+ ReturnType<AgentMethods<T>[K$1]> extends Promise<any>
56
+ ? ReturnType<AgentMethods<T>[K$1]>
57
+ : Promise<ReturnType<AgentMethods<T>[K$1]>>;
58
+ type OptionalArgsAgentMethodCall<AgentT> = <
59
+ K$1 extends keyof OptionalAgentMethods<AgentT>
60
+ >(
61
+ method: K$1,
62
+ args?: Parameters<OptionalAgentMethods<AgentT>[K$1]>,
63
+ streamOptions?: StreamOptions
64
+ ) => AgentPromiseReturnType<AgentT, K$1>;
65
+ type RequiredArgsAgentMethodCall<AgentT> = <
66
+ K$1 extends keyof RequiredAgentMethods<AgentT>
67
+ >(
68
+ method: K$1,
69
+ args: Parameters<RequiredAgentMethods<AgentT>[K$1]>,
70
+ streamOptions?: StreamOptions
71
+ ) => AgentPromiseReturnType<AgentT, K$1>;
72
+ type AgentMethodCall<AgentT> = OptionalArgsAgentMethodCall<AgentT> &
73
+ RequiredArgsAgentMethodCall<AgentT>;
74
+ type UntypedAgentMethodCall = <T = unknown>(
75
+ method: string,
76
+ args?: unknown[],
77
+ streamOptions?: StreamOptions
78
+ ) => Promise<T>;
79
+ type AgentStub<T> = {
80
+ [K in keyof AgentMethods<T>]: (
81
+ ...args: Parameters<AgentMethods<T>[K]>
82
+ ) => AgentPromiseReturnType<AgentMethods<T>, K>;
83
+ };
84
+ type UntypedAgentStub = Record<string, Method>;
85
+ /**
86
+ * React hook for connecting to an Agent
87
+ */
88
+ declare function useAgent<State = unknown>(
89
+ options: UseAgentOptions<State>
90
+ ): PartySocket & {
91
+ agent: string;
92
+ name: string;
93
+ setState: (state: State) => void;
94
+ call: UntypedAgentMethodCall;
95
+ stub: UntypedAgentStub;
96
+ };
97
+ declare function useAgent<
98
+ AgentT extends {
99
+ get state(): State;
100
+ },
101
+ State
102
+ >(
103
+ options: UseAgentOptions<State>
104
+ ): PartySocket & {
105
+ agent: string;
106
+ name: string;
107
+ setState: (state: State) => void;
108
+ call: AgentMethodCall<AgentT>;
109
+ stub: AgentStub<AgentT>;
110
+ };
111
+ //#endregion
112
+ export { useAgent as n, UseAgentOptions as t };
113
+ //# sourceMappingURL=react-CMF2YDq6.d.ts.map
package/dist/react.d.ts CHANGED
@@ -1,30 +1,10 @@
1
- import { PartySocket } from 'partysocket';
2
- import { usePartySocket } from 'partysocket/react';
3
- import { StreamOptions } from './client.js';
4
-
5
- /**
6
- * Options for the useAgent hook
7
- * @template State Type of the Agent's state
8
- */
9
- type UseAgentOptions<State = unknown> = Omit<Parameters<typeof usePartySocket>[0], "party" | "room"> & {
10
- /** Name of the agent to connect to */
11
- agent: string;
12
- /** Name of the specific Agent instance */
13
- name?: string;
14
- /** Called when the Agent's state is updated */
15
- onStateUpdate?: (state: State, source: "server" | "client") => void;
16
- };
17
- /**
18
- * React hook for connecting to an Agent
19
- * @template State Type of the Agent's state
20
- * @param options Connection options
21
- * @returns WebSocket connection with setState and call methods
22
- */
23
- declare function useAgent<State = unknown>(options: UseAgentOptions<State>): PartySocket & {
24
- agent: string;
25
- name: string;
26
- setState: (state: State) => void;
27
- call: <T = unknown>(method: string, args?: unknown[], streamOptions?: StreamOptions) => Promise<T>;
28
- };
29
-
30
- export { type UseAgentOptions, useAgent };
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, t as UseAgentOptions } from "./react-CMF2YDq6.js";
10
+ export { UseAgentOptions, useAgent };
package/dist/react.js ADDED
@@ -0,0 +1,189 @@
1
+ import { t as MessageType } from "./ai-types-DKWQN9wb.js";
2
+ import { use, useCallback, useEffect, useMemo, useRef } from "react";
3
+ import { usePartySocket } from "partysocket/react";
4
+
5
+ //#region src/react.tsx
6
+ /**
7
+ * Convert a camelCase string to a kebab-case string
8
+ * @param str The string to convert
9
+ * @returns The kebab-case string
10
+ */
11
+ function camelCaseToKebabCase(str) {
12
+ if (str === str.toUpperCase() && str !== str.toLowerCase()) return str.toLowerCase().replace(/_/g, "-");
13
+ let kebabified = str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
14
+ kebabified = kebabified.startsWith("-") ? kebabified.slice(1) : kebabified;
15
+ return kebabified.replace(/_/g, "-").replace(/-$/, "");
16
+ }
17
+ const queryCache = /* @__PURE__ */ new Map();
18
+ function arraysEqual(a, b) {
19
+ if (a === b) return true;
20
+ if (a.length !== b.length) return false;
21
+ for (let i = 0; i < a.length; i++) if (!Object.is(a[i], b[i])) return false;
22
+ return true;
23
+ }
24
+ function findCacheEntry(targetKey) {
25
+ for (const [existingKey, entry] of queryCache.entries()) if (arraysEqual(existingKey, targetKey)) {
26
+ if (Date.now() > entry.expiresAt) {
27
+ queryCache.delete(existingKey);
28
+ return;
29
+ }
30
+ entry.refCount++;
31
+ return entry.promise;
32
+ }
33
+ }
34
+ function setCacheEntry(key, value, cacheTtl) {
35
+ for (const [existingKey] of queryCache.entries()) if (arraysEqual(existingKey, key)) {
36
+ queryCache.delete(existingKey);
37
+ break;
38
+ }
39
+ const expiresAt = cacheTtl ? Date.now() + cacheTtl : Date.now() + 300 * 1e3;
40
+ queryCache.set(key, {
41
+ promise: value,
42
+ refCount: 1,
43
+ expiresAt,
44
+ cacheTtl
45
+ });
46
+ }
47
+ function decrementCacheEntry(targetKey) {
48
+ for (const [existingKey, entry] of queryCache.entries()) if (arraysEqual(existingKey, targetKey)) {
49
+ entry.refCount--;
50
+ if (entry.refCount <= 0) queryCache.delete(existingKey);
51
+ return true;
52
+ }
53
+ return false;
54
+ }
55
+ function createCacheKey(agentNamespace, name, deps) {
56
+ return [
57
+ agentNamespace,
58
+ name || "default",
59
+ ...deps
60
+ ];
61
+ }
62
+ function useAgent(options) {
63
+ const agentNamespace = camelCaseToKebabCase(options.agent);
64
+ const { query, queryDeps, cacheTtl, ...restOptions } = options;
65
+ const pendingCallsRef = useRef(/* @__PURE__ */ new Map());
66
+ const cacheKey = useMemo(() => {
67
+ const deps = queryDeps || [];
68
+ return createCacheKey(agentNamespace, options.name, deps);
69
+ }, [
70
+ agentNamespace,
71
+ options.name,
72
+ queryDeps
73
+ ]);
74
+ const queryPromise = useMemo(() => {
75
+ if (!query || typeof query !== "function") return null;
76
+ const existingPromise = findCacheEntry(cacheKey);
77
+ if (existingPromise) return existingPromise;
78
+ const promise = query().catch((error) => {
79
+ console.error(`[useAgent] Query failed for agent "${options.agent}":`, error);
80
+ decrementCacheEntry(cacheKey);
81
+ throw error;
82
+ });
83
+ setCacheEntry(cacheKey, promise, cacheTtl);
84
+ return promise;
85
+ }, [
86
+ cacheKey,
87
+ query,
88
+ options.agent,
89
+ cacheTtl
90
+ ]);
91
+ let resolvedQuery;
92
+ if (query) if (typeof query === "function") {
93
+ const queryResult = use(queryPromise);
94
+ if (queryResult) {
95
+ for (const [key, value] of Object.entries(queryResult)) if (value !== null && value !== void 0 && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") console.warn(`[useAgent] Query parameter "${key}" is an object and will be converted to "[object Object]". Query parameters should be string, number, boolean, or null.`);
96
+ resolvedQuery = queryResult;
97
+ }
98
+ } else resolvedQuery = query;
99
+ useEffect(() => {
100
+ return () => {
101
+ if (queryPromise) decrementCacheEntry(cacheKey);
102
+ };
103
+ }, [cacheKey, queryPromise]);
104
+ const agent = usePartySocket({
105
+ party: agentNamespace,
106
+ prefix: "agents",
107
+ room: options.name || "default",
108
+ query: resolvedQuery,
109
+ ...restOptions,
110
+ onMessage: (message) => {
111
+ if (typeof message.data === "string") {
112
+ let parsedMessage;
113
+ try {
114
+ parsedMessage = JSON.parse(message.data);
115
+ } catch (_error) {
116
+ return options.onMessage?.(message);
117
+ }
118
+ if (parsedMessage.type === MessageType.CF_AGENT_STATE) {
119
+ options.onStateUpdate?.(parsedMessage.state, "server");
120
+ return;
121
+ }
122
+ if (parsedMessage.type === MessageType.CF_AGENT_MCP_SERVERS) {
123
+ options.onMcpUpdate?.(parsedMessage.mcp);
124
+ return;
125
+ }
126
+ if (parsedMessage.type === MessageType.RPC) {
127
+ const response = parsedMessage;
128
+ const pending = pendingCallsRef.current.get(response.id);
129
+ if (!pending) return;
130
+ if (!response.success) {
131
+ pending.reject(new Error(response.error));
132
+ pendingCallsRef.current.delete(response.id);
133
+ pending.stream?.onError?.(response.error);
134
+ return;
135
+ }
136
+ if ("done" in response) if (response.done) {
137
+ pending.resolve(response.result);
138
+ pendingCallsRef.current.delete(response.id);
139
+ pending.stream?.onDone?.(response.result);
140
+ } else pending.stream?.onChunk?.(response.result);
141
+ else {
142
+ pending.resolve(response.result);
143
+ pendingCallsRef.current.delete(response.id);
144
+ }
145
+ return;
146
+ }
147
+ }
148
+ options.onMessage?.(message);
149
+ }
150
+ });
151
+ const call = useCallback((method, args = [], streamOptions) => {
152
+ return new Promise((resolve, reject) => {
153
+ const id = Math.random().toString(36).slice(2);
154
+ pendingCallsRef.current.set(id, {
155
+ reject,
156
+ resolve,
157
+ stream: streamOptions
158
+ });
159
+ const request = {
160
+ args,
161
+ id,
162
+ method,
163
+ type: MessageType.RPC
164
+ };
165
+ agent.send(JSON.stringify(request));
166
+ });
167
+ }, [agent]);
168
+ agent.setState = (state) => {
169
+ agent.send(JSON.stringify({
170
+ state,
171
+ type: MessageType.CF_AGENT_STATE
172
+ }));
173
+ options.onStateUpdate?.(state, "client");
174
+ };
175
+ agent.call = call;
176
+ agent.agent = agentNamespace;
177
+ agent.name = options.name || "default";
178
+ agent.stub = new Proxy({}, { get: (_target, method) => {
179
+ return (...args) => {
180
+ return call(method, args);
181
+ };
182
+ } });
183
+ if (agent.agent !== agent.agent.toLowerCase()) console.warn(`Agent name: ${agent.agent} should probably be in lowercase. Received: ${agent.agent}`);
184
+ return agent;
185
+ }
186
+
187
+ //#endregion
188
+ export { useAgent };
189
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","names":["resolvedQuery: QueryObject | undefined","parsedMessage: Record<string, unknown>","request: RPCRequest"],"sources":["../src/react.tsx"],"sourcesContent":["import type { PartySocket } from \"partysocket\";\nimport { usePartySocket } from \"partysocket/react\";\nimport { useCallback, useRef, use, useMemo, useEffect } from \"react\";\nimport type { Agent, MCPServersState, RPCRequest, RPCResponse } from \"./\";\nimport type { StreamOptions } from \"./client\";\nimport type { Method, RPCMethod } from \"./serializable\";\nimport { MessageType } from \"./ai-types\";\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 */\nfunction 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\ntype QueryObject = Record<string, string | null>;\n\nconst queryCache = new Map<\n unknown[],\n {\n promise: Promise<QueryObject>;\n refCount: number;\n expiresAt: number;\n cacheTtl?: number;\n }\n>();\n\nfunction arraysEqual(a: unknown[], b: unknown[]): boolean {\n if (a === b) return true;\n if (a.length !== b.length) return false;\n\n for (let i = 0; i < a.length; i++) {\n if (!Object.is(a[i], b[i])) return false;\n }\n return true;\n}\n\nfunction findCacheEntry(\n targetKey: unknown[]\n): Promise<QueryObject> | undefined {\n for (const [existingKey, entry] of queryCache.entries()) {\n if (arraysEqual(existingKey, targetKey)) {\n // Check if entry has expired\n if (Date.now() > entry.expiresAt) {\n queryCache.delete(existingKey);\n return undefined;\n }\n entry.refCount++;\n return entry.promise;\n }\n }\n return undefined;\n}\n\nfunction setCacheEntry(\n key: unknown[],\n value: Promise<QueryObject>,\n cacheTtl?: number\n): void {\n // Remove any existing entry with matching members\n for (const [existingKey] of queryCache.entries()) {\n if (arraysEqual(existingKey, key)) {\n queryCache.delete(existingKey);\n break;\n }\n }\n\n const expiresAt = cacheTtl\n ? Date.now() + cacheTtl\n : Date.now() + 5 * 60 * 1000; // Default 5 minutes\n queryCache.set(key, { promise: value, refCount: 1, expiresAt, cacheTtl });\n}\n\nfunction decrementCacheEntry(targetKey: unknown[]): boolean {\n for (const [existingKey, entry] of queryCache.entries()) {\n if (arraysEqual(existingKey, targetKey)) {\n entry.refCount--;\n if (entry.refCount <= 0) {\n queryCache.delete(existingKey);\n }\n return true;\n }\n }\n return false;\n}\n\nfunction createCacheKey(\n agentNamespace: string,\n name: string | undefined,\n deps: unknown[]\n): unknown[] {\n return [agentNamespace, name || \"default\", ...deps];\n}\n\n/**\n * Options for the useAgent hook\n * @template State Type of the Agent's state\n */\nexport type UseAgentOptions<State = unknown> = Omit<\n Parameters<typeof usePartySocket>[0],\n \"party\" | \"room\" | \"query\"\n> & {\n /** Name of the agent to connect to */\n agent: string;\n /** Name of the specific Agent instance */\n name?: string;\n /** Query parameters - can be static object or async function */\n query?: QueryObject | (() => Promise<QueryObject>);\n /** Dependencies for async query caching */\n queryDeps?: unknown[];\n /** Cache TTL in milliseconds for auth tokens/time-sensitive data */\n cacheTtl?: number;\n /** Called when the Agent's state is updated */\n onStateUpdate?: (state: State, source: \"server\" | \"client\") => void;\n /** Called when MCP server state is updated */\n onMcpUpdate?: (mcpServers: MCPServersState) => void;\n};\n\ntype AllOptional<T> = T extends [infer A, ...infer R]\n ? undefined extends A\n ? AllOptional<R>\n : false\n : true; // no params means optional by default\n\ntype RPCMethods<T> = {\n [K in keyof T as T[K] extends RPCMethod<T[K]> ? K : never]: RPCMethod<T[K]>;\n};\n\ntype OptionalParametersMethod<T extends RPCMethod> =\n AllOptional<Parameters<T>> extends true ? T : never;\n\n// all methods of the Agent, excluding the ones that are declared in the base Agent class\n// biome-ignore lint: suppressions/parse\ntype AgentMethods<T> = Omit<RPCMethods<T>, keyof Agent<any, any>>;\n\ntype OptionalAgentMethods<T> = {\n [K in keyof AgentMethods<T> as AgentMethods<T>[K] extends OptionalParametersMethod<\n AgentMethods<T>[K]\n >\n ? K\n : never]: OptionalParametersMethod<AgentMethods<T>[K]>;\n};\n\ntype RequiredAgentMethods<T> = Omit<\n AgentMethods<T>,\n keyof OptionalAgentMethods<T>\n>;\n\ntype AgentPromiseReturnType<T, K extends keyof AgentMethods<T>> =\n // biome-ignore lint: suppressions/parse\n ReturnType<AgentMethods<T>[K]> extends Promise<any>\n ? ReturnType<AgentMethods<T>[K]>\n : Promise<ReturnType<AgentMethods<T>[K]>>;\n\ntype OptionalArgsAgentMethodCall<AgentT> = <\n K extends keyof OptionalAgentMethods<AgentT>\n>(\n method: K,\n args?: Parameters<OptionalAgentMethods<AgentT>[K]>,\n streamOptions?: StreamOptions\n) => AgentPromiseReturnType<AgentT, K>;\n\ntype RequiredArgsAgentMethodCall<AgentT> = <\n K extends keyof RequiredAgentMethods<AgentT>\n>(\n method: K,\n args: Parameters<RequiredAgentMethods<AgentT>[K]>,\n streamOptions?: StreamOptions\n) => AgentPromiseReturnType<AgentT, K>;\n\ntype AgentMethodCall<AgentT> = OptionalArgsAgentMethodCall<AgentT> &\n RequiredArgsAgentMethodCall<AgentT>;\n\ntype UntypedAgentMethodCall = <T = unknown>(\n method: string,\n args?: unknown[],\n streamOptions?: StreamOptions\n) => Promise<T>;\n\ntype AgentStub<T> = {\n [K in keyof AgentMethods<T>]: (\n ...args: Parameters<AgentMethods<T>[K]>\n ) => AgentPromiseReturnType<AgentMethods<T>, K>;\n};\n\n// we neet to use Method instead of RPCMethod here for retro-compatibility\ntype UntypedAgentStub = Record<string, Method>;\n\n/**\n * React hook for connecting to an Agent\n */\nexport function useAgent<State = unknown>(\n options: UseAgentOptions<State>\n): PartySocket & {\n agent: string;\n name: string;\n setState: (state: State) => void;\n call: UntypedAgentMethodCall;\n stub: UntypedAgentStub;\n};\nexport function useAgent<\n AgentT extends {\n get state(): State;\n },\n State\n>(\n options: UseAgentOptions<State>\n): PartySocket & {\n agent: string;\n name: string;\n setState: (state: State) => void;\n call: AgentMethodCall<AgentT>;\n stub: AgentStub<AgentT>;\n};\nexport function useAgent<State>(\n options: UseAgentOptions<unknown>\n): PartySocket & {\n agent: string;\n name: string;\n setState: (state: State) => void;\n call: UntypedAgentMethodCall | AgentMethodCall<unknown>;\n stub: UntypedAgentStub;\n} {\n const agentNamespace = camelCaseToKebabCase(options.agent);\n const { query, queryDeps, cacheTtl, ...restOptions } = options;\n\n // Keep track of pending RPC calls\n const pendingCallsRef = useRef(\n new Map<\n string,\n {\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n stream?: StreamOptions;\n }\n >()\n );\n\n // Handle both sync and async query patterns\n const cacheKey = useMemo(() => {\n const deps = queryDeps || [];\n return createCacheKey(agentNamespace, options.name, deps);\n }, [agentNamespace, options.name, queryDeps]);\n\n const queryPromise = useMemo(() => {\n if (!query || typeof query !== \"function\") {\n return null;\n }\n\n const existingPromise = findCacheEntry(cacheKey);\n if (existingPromise) {\n return existingPromise;\n }\n\n const promise = query().catch((error) => {\n console.error(\n `[useAgent] Query failed for agent \"${options.agent}\":`,\n error\n );\n decrementCacheEntry(cacheKey); // Remove failed promise from cache\n throw error; // Re-throw for Suspense error boundary\n });\n\n setCacheEntry(cacheKey, promise, cacheTtl);\n\n return promise;\n }, [cacheKey, query, options.agent, cacheTtl]);\n\n let resolvedQuery: QueryObject | undefined;\n\n if (query) {\n if (typeof query === \"function\") {\n // Use React's use() to resolve the promise\n const queryResult = use(queryPromise!);\n\n // Check for non-primitive values and warn\n if (queryResult) {\n for (const [key, value] of Object.entries(queryResult)) {\n if (\n value !== null &&\n value !== undefined &&\n typeof value !== \"string\" &&\n typeof value !== \"number\" &&\n typeof value !== \"boolean\"\n ) {\n console.warn(\n `[useAgent] Query parameter \"${key}\" is an object and will be converted to \"[object Object]\". ` +\n \"Query parameters should be string, number, boolean, or null.\"\n );\n }\n }\n resolvedQuery = queryResult;\n }\n } else {\n // Sync query - use directly\n resolvedQuery = query;\n }\n }\n\n // Cleanup cache on unmount\n useEffect(() => {\n return () => {\n if (queryPromise) {\n decrementCacheEntry(cacheKey);\n }\n };\n }, [cacheKey, queryPromise]);\n\n const agent = usePartySocket({\n party: agentNamespace,\n prefix: \"agents\",\n room: options.name || \"default\",\n query: resolvedQuery,\n ...restOptions,\n onMessage: (message) => {\n if (typeof message.data === \"string\") {\n let parsedMessage: Record<string, unknown>;\n try {\n parsedMessage = JSON.parse(message.data);\n } catch (_error) {\n // silently ignore invalid messages for now\n // TODO: log errors with log levels\n return options.onMessage?.(message);\n }\n if (parsedMessage.type === MessageType.CF_AGENT_STATE) {\n options.onStateUpdate?.(parsedMessage.state as State, \"server\");\n return;\n }\n if (parsedMessage.type === MessageType.CF_AGENT_MCP_SERVERS) {\n options.onMcpUpdate?.(parsedMessage.mcp as MCPServersState);\n return;\n }\n if (parsedMessage.type === MessageType.RPC) {\n const response = parsedMessage as RPCResponse;\n const pending = pendingCallsRef.current.get(response.id);\n if (!pending) return;\n\n if (!response.success) {\n pending.reject(new Error(response.error));\n pendingCallsRef.current.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 pendingCallsRef.current.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 pendingCallsRef.current.delete(response.id);\n }\n return;\n }\n }\n options.onMessage?.(message);\n }\n }) as PartySocket & {\n agent: string;\n name: string;\n setState: (state: State) => void;\n call: UntypedAgentMethodCall;\n stub: UntypedAgentStub;\n };\n // Create the call method\n const call = useCallback(\n <T = unknown,>(\n method: string,\n args: unknown[] = [],\n streamOptions?: StreamOptions\n ): Promise<T> => {\n return new Promise((resolve, reject) => {\n const id = Math.random().toString(36).slice(2);\n pendingCallsRef.current.set(id, {\n reject,\n resolve: resolve as (value: unknown) => void,\n stream: streamOptions\n });\n\n const request: RPCRequest = {\n args,\n id,\n method,\n type: MessageType.RPC\n };\n\n agent.send(JSON.stringify(request));\n });\n },\n [agent]\n );\n\n agent.setState = (state: State) => {\n agent.send(JSON.stringify({ state, type: MessageType.CF_AGENT_STATE }));\n options.onStateUpdate?.(state, \"client\");\n };\n\n agent.call = call;\n agent.agent = agentNamespace;\n agent.name = options.name || \"default\";\n // biome-ignore lint: suppressions/parse\n agent.stub = new Proxy<any>(\n {},\n {\n get: (_target, method) => {\n return (...args: unknown[]) => {\n return call(method as string, args);\n };\n }\n }\n );\n\n // warn if agent isn't in lowercase\n if (agent.agent !== agent.agent.toLowerCase()) {\n console.warn(\n `Agent name: ${agent.agent} should probably be in lowercase. Received: ${agent.agent}`\n );\n }\n\n return agent;\n}\n"],"mappings":"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"}
@@ -1,43 +1,130 @@
1
- import { z } from 'zod';
1
+ import { z } from "zod";
2
2
 
3
- type Schedule = z.infer<typeof unstable_scheduleSchema>;
4
- declare function unstable_getSchedulePrompt(event: {
5
- date: Date;
6
- }): string;
7
- declare const unstable_scheduleSchema: z.ZodObject<{
3
+ //#region src/schedule.d.ts
4
+
5
+ /**
6
+ * Get the schedule prompt for a given event
7
+ * @param event - The event to get the schedule prompt for
8
+ * @returns The schedule prompt
9
+ */
10
+ declare function getSchedulePrompt(event: { date: Date }): string;
11
+ /**
12
+ * @deprecated this has been renamed to getSchedulePrompt, and unstable_getSchedulePrompt will be removed in the next major version
13
+ * @param event - The event to get the schedule prompt for
14
+ * @returns The schedule prompt
15
+ */
16
+ declare function unstable_getSchedulePrompt(event: { date: Date }): string;
17
+ /**
18
+ * The schema for the schedule prompt
19
+ */
20
+ declare const scheduleSchema: z.ZodObject<
21
+ {
8
22
  description: z.ZodString;
9
- when: z.ZodObject<{
10
- type: z.ZodEnum<["scheduled", "delayed", "cron", "no-schedule"]>;
23
+ when: z.ZodObject<
24
+ {
25
+ cron: z.ZodOptional<z.ZodString>;
11
26
  date: z.ZodOptional<z.ZodDate>;
12
27
  delayInSeconds: z.ZodOptional<z.ZodNumber>;
13
- cron: z.ZodOptional<z.ZodString>;
14
- }, "strip", z.ZodTypeAny, {
15
- type: "scheduled" | "delayed" | "cron" | "no-schedule";
28
+ type: z.ZodEnum<["scheduled", "delayed", "cron", "no-schedule"]>;
29
+ },
30
+ "strip",
31
+ z.ZodTypeAny,
32
+ {
33
+ type: "cron" | "scheduled" | "delayed" | "no-schedule";
34
+ date?: Date | undefined;
16
35
  cron?: string | undefined;
17
36
  delayInSeconds?: number | undefined;
37
+ },
38
+ {
39
+ type: "cron" | "scheduled" | "delayed" | "no-schedule";
18
40
  date?: Date | undefined;
19
- }, {
20
- type: "scheduled" | "delayed" | "cron" | "no-schedule";
21
41
  cron?: string | undefined;
22
42
  delayInSeconds?: number | undefined;
23
- date?: Date | undefined;
24
- }>;
25
- }, "strip", z.ZodTypeAny, {
43
+ }
44
+ >;
45
+ },
46
+ "strip",
47
+ z.ZodTypeAny,
48
+ {
26
49
  description: string;
27
50
  when: {
28
- type: "scheduled" | "delayed" | "cron" | "no-schedule";
29
- cron?: string | undefined;
30
- delayInSeconds?: number | undefined;
31
- date?: Date | undefined;
51
+ type: "cron" | "scheduled" | "delayed" | "no-schedule";
52
+ date?: Date | undefined;
53
+ cron?: string | undefined;
54
+ delayInSeconds?: number | undefined;
32
55
  };
33
- }, {
56
+ },
57
+ {
34
58
  description: string;
35
59
  when: {
36
- type: "scheduled" | "delayed" | "cron" | "no-schedule";
60
+ type: "cron" | "scheduled" | "delayed" | "no-schedule";
61
+ date?: Date | undefined;
62
+ cron?: string | undefined;
63
+ delayInSeconds?: number | undefined;
64
+ };
65
+ }
66
+ >;
67
+ /**
68
+ * The type for the schedule prompt
69
+ */
70
+ type Schedule = z.infer<typeof scheduleSchema>;
71
+ /**
72
+ * @deprecated this has been renamed to scheduleSchema, and unstable_scheduleSchema will be removed in the next major version
73
+ * @returns The schedule schema
74
+ */
75
+ declare const unstable_scheduleSchema: z.ZodObject<
76
+ {
77
+ description: z.ZodString;
78
+ when: z.ZodObject<
79
+ {
80
+ cron: z.ZodOptional<z.ZodString>;
81
+ date: z.ZodOptional<z.ZodDate>;
82
+ delayInSeconds: z.ZodOptional<z.ZodNumber>;
83
+ type: z.ZodEnum<["scheduled", "delayed", "cron", "no-schedule"]>;
84
+ },
85
+ "strip",
86
+ z.ZodTypeAny,
87
+ {
88
+ type: "cron" | "scheduled" | "delayed" | "no-schedule";
89
+ date?: Date | undefined;
37
90
  cron?: string | undefined;
38
91
  delayInSeconds?: number | undefined;
92
+ },
93
+ {
94
+ type: "cron" | "scheduled" | "delayed" | "no-schedule";
39
95
  date?: Date | undefined;
96
+ cron?: string | undefined;
97
+ delayInSeconds?: number | undefined;
98
+ }
99
+ >;
100
+ },
101
+ "strip",
102
+ z.ZodTypeAny,
103
+ {
104
+ description: string;
105
+ when: {
106
+ type: "cron" | "scheduled" | "delayed" | "no-schedule";
107
+ date?: Date | undefined;
108
+ cron?: string | undefined;
109
+ delayInSeconds?: number | undefined;
40
110
  };
41
- }>;
42
-
43
- export { type Schedule, unstable_getSchedulePrompt, unstable_scheduleSchema };
111
+ },
112
+ {
113
+ description: string;
114
+ when: {
115
+ type: "cron" | "scheduled" | "delayed" | "no-schedule";
116
+ date?: Date | undefined;
117
+ cron?: string | undefined;
118
+ delayInSeconds?: number | undefined;
119
+ };
120
+ }
121
+ >;
122
+ //#endregion
123
+ export {
124
+ Schedule,
125
+ getSchedulePrompt,
126
+ scheduleSchema,
127
+ unstable_getSchedulePrompt,
128
+ unstable_scheduleSchema
129
+ };
130
+ //# sourceMappingURL=schedule.d.ts.map
@@ -0,0 +1,96 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schedule.ts
4
+ /**
5
+ * Get the schedule prompt for a given event
6
+ * @param event - The event to get the schedule prompt for
7
+ * @returns The schedule prompt
8
+ */
9
+ function getSchedulePrompt(event) {
10
+ return `
11
+ [Schedule Parser Component]
12
+
13
+ Current time: ${event.date.toUTCString()}
14
+
15
+ This component parses natural language scheduling requests into a structured format. It extracts:
16
+ 1. A clean task description (without timing information)
17
+ 2. Scheduling details in one of these formats:
18
+ - scheduled: Specific date/time events
19
+ - delayed: Relative time delays (in seconds)
20
+ - cron: Recurring patterns
21
+ - no-schedule: Tasks without timing
22
+
23
+ Rules:
24
+ - Task descriptions should be clean and focused on the action
25
+ - Use numbers (0-6) for days in cron patterns (0=Sunday)
26
+ - For recurring tasks, use standard cron syntax
27
+ - For relative times, convert to seconds
28
+ - For specific dates, use the current time as reference
29
+
30
+ Example outputs:
31
+ {
32
+ "description": "meeting with team",
33
+ "when": {
34
+ "type": "scheduled",
35
+ "date": "tomorrow at 14:00"
36
+ }
37
+ }
38
+
39
+ {
40
+ "description": "backup database",
41
+ "when": {
42
+ "type": "cron",
43
+ "cron": "0 0 * * *"
44
+ }
45
+ }
46
+
47
+ {
48
+ "description": "send report",
49
+ "when": {
50
+ "type": "delayed",
51
+ "delayInSeconds": 1800
52
+ }
53
+ }
54
+
55
+ [End Schedule Parser Component]
56
+ `;
57
+ }
58
+ let didWarnAboutUnstableGetSchedulePrompt = false;
59
+ /**
60
+ * @deprecated this has been renamed to getSchedulePrompt, and unstable_getSchedulePrompt will be removed in the next major version
61
+ * @param event - The event to get the schedule prompt for
62
+ * @returns The schedule prompt
63
+ */
64
+ function unstable_getSchedulePrompt(event) {
65
+ if (!didWarnAboutUnstableGetSchedulePrompt) {
66
+ didWarnAboutUnstableGetSchedulePrompt = true;
67
+ console.warn("unstable_getSchedulePrompt is deprecated, use getSchedulePrompt instead. unstable_getSchedulePrompt will be removed in the next major version.");
68
+ }
69
+ return getSchedulePrompt(event);
70
+ }
71
+ /**
72
+ * The schema for the schedule prompt
73
+ */
74
+ const scheduleSchema = z.object({
75
+ description: z.string().describe("A description of the task"),
76
+ when: z.object({
77
+ cron: z.string().optional().describe("execute task on a recurring interval specified as cron syntax (only use if the type is cron)"),
78
+ date: z.coerce.date().optional().describe("execute task at the specified date and time (only use if the type is scheduled)"),
79
+ delayInSeconds: z.number().optional().describe("execute task after a delay in seconds (only use if the type is delayed)"),
80
+ type: z.enum([
81
+ "scheduled",
82
+ "delayed",
83
+ "cron",
84
+ "no-schedule"
85
+ ]).describe("The type of scheduling details")
86
+ })
87
+ });
88
+ /**
89
+ * @deprecated this has been renamed to scheduleSchema, and unstable_scheduleSchema will be removed in the next major version
90
+ * @returns The schedule schema
91
+ */
92
+ const unstable_scheduleSchema = scheduleSchema;
93
+
94
+ //#endregion
95
+ export { getSchedulePrompt, scheduleSchema, unstable_getSchedulePrompt, unstable_scheduleSchema };
96
+ //# sourceMappingURL=schedule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schedule.js","names":[],"sources":["../src/schedule.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * Get the schedule prompt for a given event\n * @param event - The event to get the schedule prompt for\n * @returns The schedule prompt\n */\nexport function getSchedulePrompt(event: { date: Date }) {\n return `\n[Schedule Parser Component]\n\nCurrent time: ${event.date.toUTCString()}\n\nThis component parses natural language scheduling requests into a structured format. It extracts:\n1. A clean task description (without timing information)\n2. Scheduling details in one of these formats:\n - scheduled: Specific date/time events\n - delayed: Relative time delays (in seconds)\n - cron: Recurring patterns\n - no-schedule: Tasks without timing\n\nRules:\n- Task descriptions should be clean and focused on the action\n- Use numbers (0-6) for days in cron patterns (0=Sunday)\n- For recurring tasks, use standard cron syntax\n- For relative times, convert to seconds\n- For specific dates, use the current time as reference\n\nExample outputs:\n{\n \"description\": \"meeting with team\",\n \"when\": {\n \"type\": \"scheduled\",\n \"date\": \"tomorrow at 14:00\"\n }\n}\n\n{\n \"description\": \"backup database\",\n \"when\": {\n \"type\": \"cron\",\n \"cron\": \"0 0 * * *\"\n }\n}\n\n{\n \"description\": \"send report\",\n \"when\": {\n \"type\": \"delayed\",\n \"delayInSeconds\": 1800\n }\n}\n\n[End Schedule Parser Component]\n`;\n}\n\nlet didWarnAboutUnstableGetSchedulePrompt = false;\n\n/**\n * @deprecated this has been renamed to getSchedulePrompt, and unstable_getSchedulePrompt will be removed in the next major version\n * @param event - The event to get the schedule prompt for\n * @returns The schedule prompt\n */\nexport function unstable_getSchedulePrompt(event: { date: Date }) {\n if (!didWarnAboutUnstableGetSchedulePrompt) {\n didWarnAboutUnstableGetSchedulePrompt = true;\n console.warn(\n \"unstable_getSchedulePrompt is deprecated, use getSchedulePrompt instead. unstable_getSchedulePrompt will be removed in the next major version.\"\n );\n }\n return getSchedulePrompt(event);\n}\n\n/**\n * The schema for the schedule prompt\n */\nexport const scheduleSchema = z.object({\n description: z.string().describe(\"A description of the task\"),\n when: z.object({\n cron: z\n .string()\n .optional()\n .describe(\n \"execute task on a recurring interval specified as cron syntax (only use if the type is cron)\"\n ),\n date: z.coerce\n .date()\n .optional()\n .describe(\n \"execute task at the specified date and time (only use if the type is scheduled)\"\n ),\n delayInSeconds: z\n .number()\n .optional()\n .describe(\n \"execute task after a delay in seconds (only use if the type is delayed)\"\n ),\n type: z\n .enum([\"scheduled\", \"delayed\", \"cron\", \"no-schedule\"])\n .describe(\"The type of scheduling details\")\n })\n});\n\n/**\n * The type for the schedule prompt\n */\nexport type Schedule = z.infer<typeof scheduleSchema>;\n\n/**\n * @deprecated this has been renamed to scheduleSchema, and unstable_scheduleSchema will be removed in the next major version\n * @returns The schedule schema\n */\nexport const unstable_scheduleSchema = scheduleSchema;\n"],"mappings":";;;;;;;;AAOA,SAAgB,kBAAkB,OAAuB;AACvD,QAAO;;;gBAGO,MAAM,KAAK,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CzC,IAAI,wCAAwC;;;;;;AAO5C,SAAgB,2BAA2B,OAAuB;AAChE,KAAI,CAAC,uCAAuC;AAC1C,0CAAwC;AACxC,UAAQ,KACN,iJACD;;AAEH,QAAO,kBAAkB,MAAM;;;;;AAMjC,MAAa,iBAAiB,EAAE,OAAO;CACrC,aAAa,EAAE,QAAQ,CAAC,SAAS,4BAA4B;CAC7D,MAAM,EAAE,OAAO;EACb,MAAM,EACH,QAAQ,CACR,UAAU,CACV,SACC,+FACD;EACH,MAAM,EAAE,OACL,MAAM,CACN,UAAU,CACV,SACC,kFACD;EACH,gBAAgB,EACb,QAAQ,CACR,UAAU,CACV,SACC,0EACD;EACH,MAAM,EACH,KAAK;GAAC;GAAa;GAAW;GAAQ;GAAc,CAAC,CACrD,SAAS,iCAAiC;EAC9C,CAAC;CACH,CAAC;;;;;AAWF,MAAa,0BAA0B"}