agents 0.30.1 → 0.31.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 (126) hide show
  1. package/README.md +2 -1
  2. package/dist/{agent-routing-CDbpVjYq.d.ts → agent-routing-wS1TimZ_.d.ts} +64 -603
  3. package/dist/agent-routing.d.ts +1 -1
  4. package/dist/agent-tool-types.d.ts +1 -1
  5. package/dist/{agent-tools-C8DH8Yii.d.ts → agent-tools-Bamxxb6Y.d.ts} +2 -2
  6. package/dist/agent-tools.d.ts +1 -1
  7. package/dist/{ai-iXw0uOGj.d.ts → ai-CDn3Abax.d.ts} +30 -4
  8. package/dist/{ai-sdk-DRPh2rRa.js → ai-sdk-Kon40i0q.js} +2 -36
  9. package/dist/ai-sdk-Kon40i0q.js.map +1 -0
  10. package/dist/ai-sdk-hW3vntnk.d.ts +72 -0
  11. package/dist/browser/ai.d.ts +1 -1
  12. package/dist/browser/ai.js +16 -3
  13. package/dist/browser/ai.js.map +1 -1
  14. package/dist/browser/index.d.ts +64 -16
  15. package/dist/browser/index.js +4 -4
  16. package/dist/browser/tools/ai-sdk.d.ts +7 -70
  17. package/dist/browser/tools/ai-sdk.js +4 -4
  18. package/dist/browser/tools/ai-sdk.js.map +1 -1
  19. package/dist/browser/tools/pi.d.ts +9 -15
  20. package/dist/browser/tools/pi.js +6 -14
  21. package/dist/browser/tools/pi.js.map +1 -1
  22. package/dist/browser/tools/tanstack-ai.d.ts +46 -23
  23. package/dist/browser/tools/tanstack-ai.js +8 -4
  24. package/dist/browser/tools/tanstack-ai.js.map +1 -1
  25. package/dist/{browser-DccPw_wW.js → browser-1eUbPvC2.js} +413 -14
  26. package/dist/browser-1eUbPvC2.js.map +1 -0
  27. package/dist/{browser-DlXhSAdf.d.ts → browser-D9RNpJuT.d.ts} +254 -20
  28. package/dist/browser-tool-BhjCcNVE.d.ts +71 -0
  29. package/dist/browser-tool-lGnvEBLJ.js +497 -0
  30. package/dist/browser-tool-lGnvEBLJ.js.map +1 -0
  31. package/dist/capability-id-B3J8Nok_.js +13 -0
  32. package/dist/capability-id-B3J8Nok_.js.map +1 -0
  33. package/dist/chat/index.d.ts +2 -2
  34. package/dist/chat-sdk/index.d.ts +3 -3
  35. package/dist/chat-sdk/index.js +1 -1
  36. package/dist/client-4OlMIJx-.js.map +1 -1
  37. package/dist/{client-BnYbNT3z.js → client-DMWujQJ1.js} +68 -244
  38. package/dist/client-DMWujQJ1.js.map +1 -0
  39. package/dist/{client-C27CtRZr.d.ts → client-wn4-yqGz.d.ts} +9 -7
  40. package/dist/client.d.ts +1 -1
  41. package/dist/{connector-DAXBOIIi.js → connector-CM-uuxKM.js} +96 -8
  42. package/dist/connector-CM-uuxKM.js.map +1 -0
  43. package/dist/{connector-20DJ6p4k.d.ts → connector-DZ71EjE-.d.ts} +109 -9
  44. package/dist/experimental/webmcp.js +1 -1
  45. package/dist/{handler-stateless-Bly_nSH3.js → handler-stateless-B5hU3dxK.js} +35 -2
  46. package/dist/handler-stateless-B5hU3dxK.js.map +1 -0
  47. package/dist/{handler-stateless-DxYpJ_XF.d.ts → handler-stateless-C90kD5_R.d.ts} +3 -47
  48. package/dist/harness/container/index.d.ts +15 -15
  49. package/dist/harness/opencode/index.js.map +1 -1
  50. package/dist/harness/pi/index.d.ts +4 -3
  51. package/dist/harness/pi/index.js +31 -10
  52. package/dist/harness/pi/index.js.map +1 -1
  53. package/dist/harness/think/index.d.ts +2 -1
  54. package/dist/{images-xaDv2Fqe.js → images-CfuRCjwq.js} +1 -5
  55. package/dist/images-CfuRCjwq.js.map +1 -0
  56. package/dist/{index-DCxk3OSJ.d.ts → index-8k4qsX1T.d.ts} +2 -28
  57. package/dist/index.d.ts +14 -14
  58. package/dist/index.js +2 -2
  59. package/dist/internal-hosts-Kfp5A392.d.ts +230 -0
  60. package/dist/internal-kmw70xwR.js.map +1 -1
  61. package/dist/invoker-BC1SZ3q1.js +26 -0
  62. package/dist/invoker-BC1SZ3q1.js.map +1 -0
  63. package/dist/invoker-DoLFPJZV.d.ts +21 -0
  64. package/dist/mcp/client/index.d.ts +15 -1
  65. package/dist/mcp/client/index.js +2 -2
  66. package/dist/mcp/client/x402.d.ts +7 -5
  67. package/dist/mcp/client/x402.js +34 -1
  68. package/dist/mcp/client/x402.js.map +1 -1
  69. package/dist/mcp/index.d.ts +561 -27
  70. package/dist/mcp/index.js +180 -3
  71. package/dist/mcp/index.js.map +1 -1
  72. package/dist/mcp/server/index.d.ts +1 -1
  73. package/dist/mcp/server/index.js +1 -1
  74. package/dist/models/ai-sdk/index.d.ts +2 -2
  75. package/dist/models/ai-sdk/index.js +1 -1
  76. package/dist/models/opencode/index.d.ts +2 -2
  77. package/dist/models/opencode/index.js +1 -1
  78. package/dist/models/pi-ai/index.d.ts +3 -28
  79. package/dist/models/pi-ai/index.js +31 -16
  80. package/dist/models/pi-ai/index.js.map +1 -1
  81. package/dist/protocol-BEgrJYC5.d.ts +29 -29
  82. package/dist/react.d.ts +2 -2
  83. package/dist/routing/index.d.ts +1 -1
  84. package/dist/serializable.d.ts +1 -1
  85. package/dist/{session-store-yvwq1f9x.js → session-7CDgVE0z.js} +455 -33
  86. package/dist/session-7CDgVE0z.js.map +1 -0
  87. package/dist/{session-store-_IK6dV-w.d.ts → session-store-B7Ca-u1t.d.ts} +8 -1
  88. package/dist/settings-Dk2il2Hf.js.map +1 -1
  89. package/dist/{src-DfLzdwlK.js → src-BGolXG_H.js} +18 -2
  90. package/dist/src-BGolXG_H.js.map +1 -0
  91. package/dist/sub-routing.d.ts +12 -12
  92. package/dist/tool-CTp72Jb_.d.ts +10 -10
  93. package/dist/tool-DoVberpN.d.ts +22 -22
  94. package/dist/tool-helpers-BodWi4gd.js +256 -0
  95. package/dist/tool-helpers-BodWi4gd.js.map +1 -0
  96. package/dist/{transport-CPh7YGiw.d.ts → transport-5moD2pW5.d.ts} +1 -43
  97. package/dist/types-D2naO3rA.d.ts +49 -0
  98. package/dist/voice/index.d.ts +1 -1
  99. package/dist/workflow-types.d.ts +1 -1
  100. package/dist/workflows.d.ts +1 -1
  101. package/dist/workflows.js +1 -1
  102. package/docs/browse-the-web.md +247 -413
  103. package/docs/harnesses/pi.md +27 -27
  104. package/docs/index.md +4 -4
  105. package/docs/mcp-client.md +2 -0
  106. package/docs/mcp-servers.md +25 -6
  107. package/docs/models-pi-ai.md +9 -11
  108. package/docs/models.md +1 -8
  109. package/docs/securing-mcp-servers.md +113 -302
  110. package/package.json +8 -3
  111. package/dist/ai-sdk-DRPh2rRa.js.map +0 -1
  112. package/dist/browser-DccPw_wW.js.map +0 -1
  113. package/dist/browser-tool-B1mhifin.js +0 -616
  114. package/dist/browser-tool-B1mhifin.js.map +0 -1
  115. package/dist/browser-tool-Cxjk5sgG.d.ts +0 -92
  116. package/dist/client-BnYbNT3z.js.map +0 -1
  117. package/dist/connector-DAXBOIIi.js.map +0 -1
  118. package/dist/handler-stateless-Bly_nSH3.js.map +0 -1
  119. package/dist/images-xaDv2Fqe.js.map +0 -1
  120. package/dist/invoker-CG0_p_Wq.d.ts +0 -20
  121. package/dist/invoker-CHMnoxIA.js +0 -57
  122. package/dist/invoker-CHMnoxIA.js.map +0 -1
  123. package/dist/session-store-yvwq1f9x.js.map +0 -1
  124. package/dist/src-DfLzdwlK.js.map +0 -1
  125. package/dist/tool-helpers-O5BDVEAY.js +0 -58
  126. package/dist/tool-helpers-O5BDVEAY.js.map +0 -1
package/dist/mcp/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { getAgentByName } from "../agent-routing.js";
2
2
  import "../types.js";
3
- import { i as getCurrentAgent, t as Agent } from "../src-DfLzdwlK.js";
4
- import { c as RPCServerTransport, i as normalizeServerId, l as RPC_DO_PREFIX, n as MCP_SERVER_ID_MAX_LENGTH, s as RPCClientTransport, u as isDurableObjectNamespace } from "../client-BnYbNT3z.js";
5
- import { n as getMcpAuthContext, r as runWithAuthContext, t as createStatelessMcpHandler } from "../handler-stateless-Bly_nSH3.js";
3
+ import { i as getCurrentAgent, t as Agent } from "../src-BGolXG_H.js";
4
+ import { c as RPCClientTransport, i as normalizeServerId, l as RPC_DO_PREFIX, n as MCP_SERVER_ID_MAX_LENGTH, u as isDurableObjectNamespace } from "../client-DMWujQJ1.js";
5
+ import { n as getMcpAuthContext, r as runWithAuthContext, t as createStatelessMcpHandler } from "../handler-stateless-B5hU3dxK.js";
6
6
  import { SSEClientTransport, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
7
7
  import { ElicitRequestSchema, InitializeRequestSchema, JSONRPCMessageSchema, SUPPORTED_PROTOCOL_VERSIONS, isInitializeRequest, isJSONRPCErrorResponse, isJSONRPCNotification, isJSONRPCRequest, isJSONRPCResultResponse } from "@modelcontextprotocol/sdk/types.js";
8
8
  import { McpServer, Server } from "@modelcontextprotocol/server";
@@ -986,6 +986,183 @@ DurableObjectEventStore.SEQ_PAD = 16;
986
986
  DurableObjectEventStore.DELETE_CHUNK = 128;
987
987
  DurableObjectEventStore.REPLAY_LIMIT = 1e3;
988
988
  //#endregion
989
+ //#region src/mcp/rpc-server.ts
990
+ function makeInvalidRequestError(id) {
991
+ return {
992
+ jsonrpc: "2.0",
993
+ id: id ?? null,
994
+ error: {
995
+ code: -32600,
996
+ message: "Invalid Request"
997
+ }
998
+ };
999
+ }
1000
+ function validateBatch(batch) {
1001
+ if (batch.length === 0) throw new Error("Invalid JSON-RPC batch: array must not be empty");
1002
+ }
1003
+ var RPCServerTransport = class {
1004
+ constructor(options) {
1005
+ this._started = false;
1006
+ this._pendingRequests = /* @__PURE__ */ new Map();
1007
+ this._pendingContinuations = [];
1008
+ this._timeout = options?.timeout ?? 6e4;
1009
+ }
1010
+ setProtocolVersion(version) {
1011
+ this._protocolVersion = version;
1012
+ }
1013
+ getProtocolVersion() {
1014
+ return this._protocolVersion;
1015
+ }
1016
+ async start() {
1017
+ if (this._started) throw new Error("Transport already started");
1018
+ this._started = true;
1019
+ }
1020
+ async close() {
1021
+ this._started = false;
1022
+ this.onclose?.();
1023
+ const error = /* @__PURE__ */ new Error("Transport closed");
1024
+ for (const pending of this._pendingRequests.values()) {
1025
+ clearTimeout(pending.timeoutId);
1026
+ pending.reject(error);
1027
+ }
1028
+ this._pendingRequests.clear();
1029
+ for (const pending of this._pendingContinuations) {
1030
+ clearTimeout(pending.timeoutId);
1031
+ pending.reject(error);
1032
+ }
1033
+ this._pendingContinuations = [];
1034
+ }
1035
+ _makeTimeout(onTimeout) {
1036
+ return setTimeout(onTimeout, this._timeout);
1037
+ }
1038
+ _appendPending(pending, message) {
1039
+ pending.messages.push(message);
1040
+ }
1041
+ _completePending(pending, message) {
1042
+ pending.messages.push(message);
1043
+ clearTimeout(pending.timeoutId);
1044
+ const messages = pending.messages;
1045
+ queueMicrotask(() => {
1046
+ pending.resolve(messages.length === 1 ? messages[0] : messages);
1047
+ });
1048
+ }
1049
+ _completeRequest(key, message) {
1050
+ const pending = this._pendingRequests.get(key);
1051
+ if (!pending) return false;
1052
+ this._pendingRequests.delete(key);
1053
+ this._completePending(pending, message);
1054
+ return true;
1055
+ }
1056
+ _appendRequest(key, message) {
1057
+ const pending = this._pendingRequests.get(key);
1058
+ if (!pending) return false;
1059
+ this._appendPending(pending, message);
1060
+ return true;
1061
+ }
1062
+ _completeContinuation(message) {
1063
+ const pending = this._pendingContinuations.shift();
1064
+ if (!pending) return false;
1065
+ this._completePending(pending, message);
1066
+ return true;
1067
+ }
1068
+ _appendContinuation(message) {
1069
+ const pending = this._pendingContinuations[0];
1070
+ if (!pending) return false;
1071
+ this._appendPending(pending, message);
1072
+ return true;
1073
+ }
1074
+ async send(message, options) {
1075
+ if (!this._started) throw new Error("Transport not started");
1076
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
1077
+ const id = message.id;
1078
+ if (id === void 0) {
1079
+ this.onerror?.(/* @__PURE__ */ new Error(`RPC response missing id: ${JSON.stringify(message)}`));
1080
+ return;
1081
+ }
1082
+ if (this._completeRequest(id.toString(), message)) return;
1083
+ if (this._completeContinuation(message)) return;
1084
+ this.onerror?.(/* @__PURE__ */ new Error(`No pending RPC request found for response: ${JSON.stringify(message)}`));
1085
+ return;
1086
+ }
1087
+ const relatedRequestId = options?.relatedRequestId?.toString();
1088
+ const expectsResponse = "id" in message;
1089
+ if (relatedRequestId) {
1090
+ if (expectsResponse) {
1091
+ if (this._completeRequest(relatedRequestId, message)) return;
1092
+ } else if (this._appendRequest(relatedRequestId, message)) return;
1093
+ }
1094
+ if (expectsResponse) {
1095
+ if (this._completeContinuation(message)) return;
1096
+ } else if (this._appendContinuation(message)) return;
1097
+ this.onerror?.(/* @__PURE__ */ new Error(`No pending RPC request found for message: ${JSON.stringify(message)}`));
1098
+ }
1099
+ /**
1100
+ * @internal Called by McpAgent.handleMcpMessage() — not for external use.
1101
+ *
1102
+ * Wait for the next unmatched send() call that expects a client response or
1103
+ * completes a resumed tool call.
1104
+ *
1105
+ * Used after resolving an elicitation response: the original tool call has
1106
+ * already returned the elicitation request to the RPC client, and the resumed
1107
+ * tool handler will eventually send the final tool result. That final response
1108
+ * has the original tool request id, so there is no active handle() waiter left
1109
+ * for id-based routing; this continuation waiter receives it instead.
1110
+ */
1111
+ async _awaitPendingResponse() {
1112
+ if (!this._started) throw new Error("Transport not started");
1113
+ return await new Promise((resolve, reject) => {
1114
+ const pending = {
1115
+ messages: [],
1116
+ resolve,
1117
+ reject,
1118
+ timeoutId: this._makeTimeout(() => {
1119
+ const index = this._pendingContinuations.indexOf(pending);
1120
+ if (index !== -1) this._pendingContinuations.splice(index, 1);
1121
+ reject(/* @__PURE__ */ new Error(`Request timeout: No response received within ${this._timeout}ms`));
1122
+ })
1123
+ };
1124
+ this._pendingContinuations.push(pending);
1125
+ });
1126
+ }
1127
+ async handle(message) {
1128
+ if (!this._started) throw new Error("Transport not started");
1129
+ if (Array.isArray(message)) {
1130
+ validateBatch(message);
1131
+ const flattened = (await Promise.all(message.map((msg) => this.handle(msg)))).flatMap((response) => {
1132
+ if (response === void 0) return [];
1133
+ return Array.isArray(response) ? response : [response];
1134
+ });
1135
+ return flattened.length === 0 ? void 0 : flattened;
1136
+ }
1137
+ try {
1138
+ JSONRPCMessageSchema.parse(message);
1139
+ } catch {
1140
+ return makeInvalidRequestError(typeof message === "object" && message !== null && "id" in message ? message.id : null);
1141
+ }
1142
+ if (!("id" in message)) {
1143
+ this.onmessage?.(message);
1144
+ return;
1145
+ }
1146
+ const id = message.id?.toString();
1147
+ if (!id) return makeInvalidRequestError(message.id);
1148
+ if (this._pendingRequests.has(id)) throw new Error(`Duplicate pending RPC request id: ${id}`);
1149
+ const responsePromise = new Promise((resolve, reject) => {
1150
+ const pending = {
1151
+ messages: [],
1152
+ resolve,
1153
+ reject,
1154
+ timeoutId: this._makeTimeout(() => {
1155
+ this._pendingRequests.delete(id);
1156
+ reject(/* @__PURE__ */ new Error(`Request timeout: No response received within ${this._timeout}ms`));
1157
+ })
1158
+ };
1159
+ this._pendingRequests.set(id, pending);
1160
+ });
1161
+ this.onmessage?.(message);
1162
+ return await responsePromise;
1163
+ }
1164
+ };
1165
+ //#endregion
989
1166
  //#region src/mcp/client/transports.ts
990
1167
  /**
991
1168
  * Deprecated transport wrappers