agents 0.16.2 → 0.17.0

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 (122) hide show
  1. package/README.md +11 -8
  2. package/dist/{agent-tool-types-CTw3UJUP.d.ts → agent-tool-types-Cd1TZPfB.d.ts} +587 -137
  3. package/dist/agent-tool-types.d.ts +34 -18
  4. package/dist/agent-tool-types.js +20 -1
  5. package/dist/agent-tool-types.js.map +1 -0
  6. package/dist/agent-tools-BXlsuX0d.js +304 -0
  7. package/dist/agent-tools-BXlsuX0d.js.map +1 -0
  8. package/dist/agent-tools-_E8wxUIK.d.ts +119 -0
  9. package/dist/agent-tools.d.ts +24 -18
  10. package/dist/agent-tools.js.map +1 -1
  11. package/dist/ai-chat-agent.d.ts +1 -1
  12. package/dist/ai-chat-agent.js +1 -2
  13. package/dist/ai-chat-agent.js.map +1 -1
  14. package/dist/ai-chat-v5-migration.d.ts +1 -1
  15. package/dist/ai-chat-v5-migration.js +1 -2
  16. package/dist/ai-chat-v5-migration.js.map +1 -1
  17. package/dist/ai-react.d.ts +1 -1
  18. package/dist/ai-react.js +1 -2
  19. package/dist/ai-react.js.map +1 -1
  20. package/dist/ai-types.d.ts +1 -7
  21. package/dist/ai-types.js +2 -8
  22. package/dist/ai-types.js.map +1 -1
  23. package/dist/browser/ai.js +1 -1
  24. package/dist/browser/index.js +1 -1
  25. package/dist/chat/index.d.ts +1918 -72
  26. package/dist/chat/index.js +1730 -245
  27. package/dist/chat/index.js.map +1 -1
  28. package/dist/chat/react.d.ts +602 -0
  29. package/dist/chat/react.js +1506 -0
  30. package/dist/chat/react.js.map +1 -0
  31. package/dist/chat-sdk/index.d.ts +4 -4
  32. package/dist/{classPrivateFieldGet2-CZ7QjTXN.js → classPrivateFieldGet2-DZBYAB34.js} +5 -5
  33. package/dist/{classPrivateMethodInitSpec-D-0__zd9.js → classPrivateMethodInitSpec-qMjJ6sHQ.js} +2 -2
  34. package/dist/{client-BXJ9n2f7.js → client-BZ-B3NhC.js} +2 -2
  35. package/dist/client-BZ-B3NhC.js.map +1 -0
  36. package/dist/client-tools-aIBO0Fk7.d.ts +53 -0
  37. package/dist/client.d.ts +76 -57
  38. package/dist/client.js +33 -5
  39. package/dist/client.js.map +1 -1
  40. package/dist/{connector-CrKhowfD.js → connector-CdldGF3h.js} +5 -5
  41. package/dist/{connector-CrKhowfD.js.map → connector-CdldGF3h.js.map} +1 -1
  42. package/dist/email.js +1 -1
  43. package/dist/email.js.map +1 -1
  44. package/dist/{index-B7IbEeze.d.ts → index-CcbnKkNh.d.ts} +188 -14
  45. package/dist/index.d.ts +91 -71
  46. package/dist/index.js +562 -24
  47. package/dist/index.js.map +1 -1
  48. package/dist/mcp/client.d.ts +18 -14
  49. package/dist/mcp/client.js +1 -1
  50. package/dist/mcp/index.d.ts +30 -30
  51. package/dist/mcp/index.js +7 -7
  52. package/dist/mcp/index.js.map +1 -1
  53. package/dist/{agent-tools-3zLG7MgA.js → message-builder-BymO4N_D.js} +45 -126
  54. package/dist/message-builder-BymO4N_D.js.map +1 -0
  55. package/dist/observability/index.d.ts +1 -1
  56. package/dist/observability/index.js +4 -2
  57. package/dist/observability/index.js.map +1 -1
  58. package/dist/react.d.ts +123 -110
  59. package/dist/react.js +44 -11
  60. package/dist/react.js.map +1 -1
  61. package/dist/serializable.d.ts +1 -1
  62. package/dist/skills/compile.js +1 -1
  63. package/dist/skills/compile.js.map +1 -1
  64. package/dist/skills/index.js +5 -5
  65. package/dist/skills/index.js.map +1 -1
  66. package/dist/sub-routing.d.ts +6 -6
  67. package/dist/utils.js +1 -1
  68. package/dist/utils.js.map +1 -1
  69. package/dist/vite.js +5 -5
  70. package/dist/vite.js.map +1 -1
  71. package/dist/wire-types-nflOzNuU.js +240 -0
  72. package/dist/wire-types-nflOzNuU.js.map +1 -0
  73. package/dist/{workflow-types-SrZK_o9p.d.ts → workflow-types-Baz_PO5v.d.ts} +42 -22
  74. package/dist/workflow-types.d.ts +25 -21
  75. package/dist/workflow-types.js.map +1 -1
  76. package/dist/workflows.d.ts +22 -21
  77. package/dist/workflows.js +31 -7
  78. package/dist/workflows.js.map +1 -1
  79. package/docs/adding-to-existing-project.md +450 -0
  80. package/docs/agent-class.md +503 -0
  81. package/docs/agent-tools.md +552 -0
  82. package/docs/browse-the-web.md +430 -0
  83. package/docs/callable-methods.md +627 -0
  84. package/docs/chat-agents.md +1687 -0
  85. package/docs/chat-sdk.md +181 -0
  86. package/docs/client-sdk.md +520 -0
  87. package/docs/client-tools-continuation.md +177 -0
  88. package/docs/codemode.md +440 -0
  89. package/docs/configuration.md +775 -0
  90. package/docs/cross-domain-authentication.md +171 -0
  91. package/docs/durable-execution.md +537 -0
  92. package/docs/email.md +663 -0
  93. package/docs/get-current-agent.md +204 -0
  94. package/docs/getting-started.md +305 -0
  95. package/docs/http-websockets.md +668 -0
  96. package/docs/human-in-the-loop.md +661 -0
  97. package/docs/index.md +151 -0
  98. package/docs/long-running-agents.md +730 -0
  99. package/docs/mcp-client.md +620 -0
  100. package/docs/mcp-servers.md +526 -0
  101. package/docs/mcp-transports.md +308 -0
  102. package/docs/migration-to-ai-sdk-v5.md +96 -0
  103. package/docs/migration-to-ai-sdk-v6.md +163 -0
  104. package/docs/observability.md +261 -0
  105. package/docs/push-notifications.md +367 -0
  106. package/docs/queue.md +329 -0
  107. package/docs/readonly-connections.md +278 -0
  108. package/docs/resumable-streaming.md +127 -0
  109. package/docs/retries.md +444 -0
  110. package/docs/routing.md +749 -0
  111. package/docs/scheduling.md +898 -0
  112. package/docs/securing-mcp-servers.md +359 -0
  113. package/docs/server-driven-messages.md +477 -0
  114. package/docs/sessions.md +1024 -0
  115. package/docs/state.md +512 -0
  116. package/docs/sub-agents.md +389 -0
  117. package/docs/webhooks.md +604 -0
  118. package/docs/workflows.md +877 -0
  119. package/package.json +41 -14
  120. package/dist/agent-tools-3zLG7MgA.js.map +0 -1
  121. package/dist/agent-tools-DZhI5F6Q.d.ts +0 -14
  122. package/dist/client-BXJ9n2f7.js.map +0 -1
@@ -0,0 +1,171 @@
1
+ # Cross-Domain Authentication
2
+
3
+ When your Agents are deployed, to keep things secure, send a token from the client, then verify it on the server. This mirrors the shape used in PartyKit’s auth guide.
4
+
5
+ ## WebSocket authentication
6
+
7
+ WebSockets are not HTTP, so the handshake is limited when making cross-domain connections.
8
+
9
+ **What you cannot send**
10
+
11
+ - Custom headers during the upgrade
12
+ - `Authorization: Bearer ...` on connect
13
+
14
+ **What works**
15
+
16
+ - Put a signed, short-lived token in the connection URL as query parameters
17
+ - Verify the token in your server’s connect path
18
+
19
+ > Tip: never place raw secrets in URLs. Prefer a JWT or a signed token that expires quickly and is scoped to the user or room.
20
+
21
+ ### Same origin
22
+
23
+ If the client and server share the origin, the browser will send cookies during the WebSocket handshake. Session based auth can work here. Prefer HTTP-only cookies.
24
+
25
+ ### Cross origin
26
+
27
+ Cookies do not help across origins. Pass credentials in the URL query, then verify on the server.
28
+
29
+ ## Usage examples
30
+
31
+ ### Static authentication
32
+
33
+ ```ts
34
+ import { useAgent } from "agents/react";
35
+
36
+ function ChatComponent() {
37
+ const agent = useAgent({
38
+ agent: "my-agent",
39
+ query: {
40
+ token: "demo-token-123",
41
+ userId: "demo-user"
42
+ }
43
+ });
44
+
45
+ // Use agent to make calls, access state, etc.
46
+ }
47
+ ```
48
+
49
+ ### Async authentication
50
+
51
+ Build query values right before connect. Use Suspense for async setup.
52
+
53
+ ```ts
54
+ import { useAgent } from "agents/react";
55
+ import { Suspense, useCallback } from "react";
56
+
57
+ function ChatComponent() {
58
+ const asyncQuery = useCallback(async () => {
59
+ const [token, user] = await Promise.all([getAuthToken(), getCurrentUser()]);
60
+ return {
61
+ token,
62
+ userId: user.id,
63
+ timestamp: Date.now().toString()
64
+ };
65
+ }, []);
66
+
67
+ const agent = useAgent({
68
+ agent: "my-agent",
69
+ query: asyncQuery
70
+ });
71
+
72
+ // Use agent to make calls, access state, etc.
73
+ }
74
+
75
+ <Suspense fallback={<div>Authenticating...</div>}>
76
+ <ChatComponent />
77
+ </Suspense>
78
+ ```
79
+
80
+ ### JWT refresh pattern
81
+
82
+ Refresh the token when the connection fails due to authentication error.
83
+
84
+ ```ts
85
+ import { useAgent } from "agents/react";
86
+ import { useCallback, useEffect } from "react";
87
+
88
+ const validateToken = async (token: string) => {
89
+ // An example of how you might implement this
90
+ const res = await fetch(`${API_HOST}/api/users/me`, {
91
+ headers: {
92
+ Authorization: `Bearer ${token}`
93
+ }
94
+ });
95
+
96
+ return res.ok;
97
+ };
98
+
99
+ const refreshToken = () => {
100
+ // Depends on implementation:
101
+ // - You could use a longer-lived token to refresh the expired token
102
+ // - De-auth the app and prompt the user to log in manually
103
+ // - ...
104
+ };
105
+
106
+ function useJWTAgent(agentName: string) {
107
+ const asyncQuery = useCallback(async () => {
108
+ let token = localStorage.getItem("jwt");
109
+
110
+ // If no token OR the token is no longer valid
111
+ // request a fresh token
112
+ if (!token && !(await validateToken(token))) {
113
+ token = await refreshToken();
114
+ localStorage.setItem("jwt", token);
115
+ }
116
+
117
+ return {
118
+ token
119
+ };
120
+ }, []);
121
+
122
+ const agent = useAgent({
123
+ agent: agentName,
124
+ query: asyncQuery,
125
+ queryDeps: [] // Run on mount
126
+ });
127
+ }
128
+ ```
129
+
130
+ ## Cross-domain authentication
131
+
132
+ Pass credentials in the URL when connecting to another host, then verify on the server.
133
+
134
+ ```ts
135
+ import { useAgent } from "agents/react";
136
+ import { useCallback } from "react";
137
+
138
+ // Static cross-domain auth
139
+ function StaticCrossDomainAuth() {
140
+ const agent = useAgent({
141
+ agent: "my-agent",
142
+ host: "http://localhost:8788",
143
+ query: {
144
+ token: "demo-token-123",
145
+ userId: "demo-user"
146
+ }
147
+ });
148
+
149
+ // Use agent to make calls, access state, etc.
150
+ }
151
+
152
+ // Async cross-domain auth
153
+ function AsyncCrossDomainAuth() {
154
+ const asyncQuery = useCallback(async () => {
155
+ const [token, user] = await Promise.all([getAuthToken(), getCurrentUser()]);
156
+ return {
157
+ token,
158
+ userId: user.id,
159
+ timestamp: Date.now().toString()
160
+ };
161
+ }, []);
162
+
163
+ const agent = useAgent({
164
+ agent: "my-agent",
165
+ host: "http://localhost:8788",
166
+ query: asyncQuery
167
+ });
168
+
169
+ // Use agent to make calls, access state, etc.
170
+ }
171
+ ```