sarvam-agents-client 0.1.1 → 0.2.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 (318) hide show
  1. package/README.md +15 -0
  2. package/dist/apis/AgentConversationsApi.d.ts +44 -1
  3. package/dist/apis/AgentConversationsApi.js +104 -1
  4. package/dist/apis/AgentsApi.d.ts +77 -5
  5. package/dist/apis/AgentsApi.js +163 -5
  6. package/dist/apis/AppsApi.d.ts +43 -1
  7. package/dist/apis/AppsApi.js +108 -0
  8. package/dist/apis/ArtifactsApi.d.ts +31 -1
  9. package/dist/apis/ArtifactsApi.js +82 -0
  10. package/dist/apis/CustomAPIsApi.d.ts +124 -0
  11. package/dist/apis/CustomAPIsApi.js +305 -0
  12. package/dist/apis/ModelsApi.d.ts +26 -0
  13. package/dist/apis/ModelsApi.js +52 -0
  14. package/dist/apis/index.d.ts +2 -0
  15. package/dist/apis/index.js +2 -0
  16. package/dist/compose/agent.d.ts +40 -0
  17. package/dist/compose/agent.js +191 -0
  18. package/dist/compose/deploy.d.ts +30 -0
  19. package/dist/compose/deploy.js +146 -0
  20. package/dist/compose/errors.d.ts +48 -0
  21. package/dist/compose/errors.js +68 -0
  22. package/dist/compose/events.d.ts +63 -0
  23. package/dist/compose/events.js +100 -0
  24. package/dist/compose/fingerprint.d.ts +6 -0
  25. package/dist/compose/fingerprint.js +83 -0
  26. package/dist/compose/index.d.ts +13 -0
  27. package/dist/compose/index.js +33 -0
  28. package/dist/compose/run.d.ts +100 -0
  29. package/dist/compose/run.js +536 -0
  30. package/dist/compose/runState.d.ts +26 -0
  31. package/dist/compose/runState.js +79 -0
  32. package/dist/compose/settingsTransport.d.ts +24 -0
  33. package/dist/compose/settingsTransport.js +280 -0
  34. package/dist/compose/tools.d.ts +17 -0
  35. package/dist/compose/tools.js +29 -0
  36. package/dist/compose/transport.d.ts +34 -0
  37. package/dist/compose/transport.js +2 -0
  38. package/dist/esm/apis/AgentConversationsApi.d.ts +44 -1
  39. package/dist/esm/apis/AgentConversationsApi.js +104 -1
  40. package/dist/esm/apis/AgentsApi.d.ts +77 -5
  41. package/dist/esm/apis/AgentsApi.js +163 -5
  42. package/dist/esm/apis/AppsApi.d.ts +43 -1
  43. package/dist/esm/apis/AppsApi.js +109 -1
  44. package/dist/esm/apis/ArtifactsApi.d.ts +31 -1
  45. package/dist/esm/apis/ArtifactsApi.js +83 -1
  46. package/dist/esm/apis/CustomAPIsApi.d.ts +124 -0
  47. package/dist/esm/apis/CustomAPIsApi.js +301 -0
  48. package/dist/esm/apis/ModelsApi.d.ts +26 -0
  49. package/dist/esm/apis/ModelsApi.js +48 -0
  50. package/dist/esm/apis/index.d.ts +2 -0
  51. package/dist/esm/apis/index.js +2 -0
  52. package/dist/esm/compose/agent.d.ts +40 -0
  53. package/dist/esm/compose/agent.js +187 -0
  54. package/dist/esm/compose/deploy.d.ts +30 -0
  55. package/dist/esm/compose/deploy.js +137 -0
  56. package/dist/esm/compose/errors.d.ts +48 -0
  57. package/dist/esm/compose/errors.js +53 -0
  58. package/dist/esm/compose/events.d.ts +63 -0
  59. package/dist/esm/compose/events.js +97 -0
  60. package/dist/esm/compose/fingerprint.d.ts +6 -0
  61. package/dist/esm/compose/fingerprint.js +78 -0
  62. package/dist/esm/compose/index.d.ts +13 -0
  63. package/dist/esm/compose/index.js +8 -0
  64. package/dist/esm/compose/run.d.ts +100 -0
  65. package/dist/esm/compose/run.js +530 -0
  66. package/dist/esm/compose/runState.d.ts +26 -0
  67. package/dist/esm/compose/runState.js +75 -0
  68. package/dist/esm/compose/settingsTransport.d.ts +24 -0
  69. package/dist/esm/compose/settingsTransport.js +276 -0
  70. package/dist/esm/compose/tools.d.ts +17 -0
  71. package/dist/esm/compose/tools.js +19 -0
  72. package/dist/esm/compose/transport.d.ts +34 -0
  73. package/dist/esm/compose/transport.js +1 -0
  74. package/dist/esm/models/AgentChannelRef.d.ts +1 -0
  75. package/dist/esm/models/AgentChannelRef.js +2 -1
  76. package/dist/esm/models/AgentConversationDetail.d.ts +15 -2
  77. package/dist/esm/models/AgentConversationDetail.js +6 -4
  78. package/dist/esm/models/AgentConversationView.d.ts +11 -5
  79. package/dist/esm/models/AgentConversationView.js +4 -4
  80. package/dist/esm/models/AgentCreate.d.ts +8 -0
  81. package/dist/esm/models/AgentCreate.js +2 -0
  82. package/dist/esm/models/AgentCustomApiList.d.ts +33 -0
  83. package/dist/esm/models/AgentCustomApiList.js +44 -0
  84. package/dist/esm/models/AgentResource.d.ts +14 -0
  85. package/dist/esm/models/AgentResource.js +4 -0
  86. package/dist/esm/models/AgentSettingsResponse.d.ts +53 -0
  87. package/dist/esm/models/AgentSettingsResponse.js +52 -0
  88. package/dist/esm/models/AgentUpdate.d.ts +8 -0
  89. package/dist/esm/models/AgentUpdate.js +2 -0
  90. package/dist/esm/models/AppAccountView.d.ts +88 -0
  91. package/dist/esm/models/AppAccountView.js +79 -0
  92. package/dist/esm/models/AppAccountsView.d.ts +66 -0
  93. package/dist/esm/models/AppAccountsView.js +60 -0
  94. package/dist/esm/models/AppResource.d.ts +36 -0
  95. package/dist/esm/models/AppResource.js +12 -0
  96. package/dist/esm/models/AppResourceCheckView.d.ts +74 -0
  97. package/dist/esm/models/AppResourceCheckView.js +63 -0
  98. package/dist/esm/models/AppResourceView.d.ts +68 -0
  99. package/dist/esm/models/AppResourceView.js +67 -0
  100. package/dist/esm/models/AppResourcesView.d.ts +54 -0
  101. package/dist/esm/models/AppResourcesView.js +56 -0
  102. package/dist/esm/models/AppToolsResponse.d.ts +14 -0
  103. package/dist/esm/models/AppToolsResponse.js +4 -0
  104. package/dist/esm/models/AppView.d.ts +42 -0
  105. package/dist/esm/models/AppView.js +14 -0
  106. package/dist/esm/models/ArtifactVersionResponse.d.ts +94 -0
  107. package/dist/esm/models/ArtifactVersionResponse.js +80 -0
  108. package/dist/esm/models/AttachedAgent.d.ts +44 -0
  109. package/dist/esm/models/AttachedAgent.js +49 -0
  110. package/dist/esm/models/Auth.d.ts +30 -0
  111. package/dist/esm/models/Auth.js +52 -0
  112. package/dist/esm/models/BindCustomApiBody.d.ts +32 -0
  113. package/dist/esm/models/BindCustomApiBody.js +43 -0
  114. package/dist/esm/models/CollectionCreate.d.ts +4 -5
  115. package/dist/esm/models/CollectionCreate.js +3 -2
  116. package/dist/esm/models/CollectionResource.d.ts +13 -0
  117. package/dist/esm/models/CollectionResource.js +5 -0
  118. package/dist/esm/models/CollectionUpdate.d.ts +4 -5
  119. package/dist/esm/models/CollectionUpdate.js +3 -2
  120. package/dist/esm/models/ConversationArtifact.d.ts +14 -0
  121. package/dist/esm/models/ConversationArtifact.js +9 -0
  122. package/dist/esm/models/CustomApi.d.ts +102 -0
  123. package/dist/esm/models/CustomApi.js +90 -0
  124. package/dist/esm/models/CustomApiBasicAuth.d.ts +51 -0
  125. package/dist/esm/models/CustomApiBasicAuth.js +57 -0
  126. package/dist/esm/models/CustomApiBearerAuth.d.ts +45 -0
  127. package/dist/esm/models/CustomApiBearerAuth.js +53 -0
  128. package/dist/esm/models/CustomApiCreate.d.ts +57 -0
  129. package/dist/esm/models/CustomApiCreate.js +56 -0
  130. package/dist/esm/models/CustomApiHeader.d.ts +44 -0
  131. package/dist/esm/models/CustomApiHeader.js +47 -0
  132. package/dist/esm/models/CustomApiHeadersAuth.d.ts +46 -0
  133. package/dist/esm/models/CustomApiHeadersAuth.js +54 -0
  134. package/dist/esm/models/CustomApiList.d.ts +64 -0
  135. package/dist/esm/models/CustomApiList.js +64 -0
  136. package/dist/esm/models/CustomApiName.d.ts +44 -0
  137. package/dist/esm/models/CustomApiName.js +49 -0
  138. package/dist/esm/models/CustomApiUpdate.d.ts +58 -0
  139. package/dist/esm/models/CustomApiUpdate.js +50 -0
  140. package/dist/esm/models/CustomApiUpdateAuth.d.ts +30 -0
  141. package/dist/esm/models/CustomApiUpdateAuth.js +52 -0
  142. package/dist/esm/models/ErrorDetailItem.d.ts +5 -0
  143. package/dist/esm/models/FieldDefinition.d.ts +63 -0
  144. package/dist/esm/models/FieldDefinition.js +55 -0
  145. package/dist/esm/models/ListModels403Response.d.ts +23 -0
  146. package/dist/esm/models/ListModels403Response.js +45 -0
  147. package/dist/esm/models/ModelEndpointView.d.ts +38 -0
  148. package/dist/esm/models/ModelEndpointView.js +45 -0
  149. package/dist/esm/models/ModelView.d.ts +69 -0
  150. package/dist/esm/models/ModelView.js +56 -0
  151. package/dist/esm/models/ModelsResponse.d.ts +33 -0
  152. package/dist/esm/models/ModelsResponse.js +44 -0
  153. package/dist/esm/models/SettingsIssueView.d.ts +44 -0
  154. package/dist/esm/models/SettingsIssueView.js +51 -0
  155. package/dist/esm/models/VersionCommitBody.d.ts +44 -0
  156. package/dist/esm/models/VersionCommitBody.js +51 -0
  157. package/dist/esm/models/VersionUploadUrlBody.d.ts +32 -0
  158. package/dist/esm/models/VersionUploadUrlBody.js +43 -0
  159. package/dist/esm/models/index.d.ts +29 -0
  160. package/dist/esm/models/index.js +29 -0
  161. package/dist/models/AgentChannelRef.d.ts +1 -0
  162. package/dist/models/AgentChannelRef.js +2 -1
  163. package/dist/models/AgentConversationDetail.d.ts +15 -2
  164. package/dist/models/AgentConversationDetail.js +6 -4
  165. package/dist/models/AgentConversationView.d.ts +11 -5
  166. package/dist/models/AgentConversationView.js +4 -4
  167. package/dist/models/AgentCreate.d.ts +8 -0
  168. package/dist/models/AgentCreate.js +2 -0
  169. package/dist/models/AgentCustomApiList.d.ts +33 -0
  170. package/dist/models/AgentCustomApiList.js +51 -0
  171. package/dist/models/AgentResource.d.ts +14 -0
  172. package/dist/models/AgentResource.js +4 -0
  173. package/dist/models/AgentSettingsResponse.d.ts +53 -0
  174. package/dist/models/AgentSettingsResponse.js +59 -0
  175. package/dist/models/AgentUpdate.d.ts +8 -0
  176. package/dist/models/AgentUpdate.js +2 -0
  177. package/dist/models/AppAccountView.d.ts +88 -0
  178. package/dist/models/AppAccountView.js +87 -0
  179. package/dist/models/AppAccountsView.d.ts +66 -0
  180. package/dist/models/AppAccountsView.js +68 -0
  181. package/dist/models/AppResource.d.ts +36 -0
  182. package/dist/models/AppResource.js +12 -0
  183. package/dist/models/AppResourceCheckView.d.ts +74 -0
  184. package/dist/models/AppResourceCheckView.js +71 -0
  185. package/dist/models/AppResourceView.d.ts +68 -0
  186. package/dist/models/AppResourceView.js +74 -0
  187. package/dist/models/AppResourcesView.d.ts +54 -0
  188. package/dist/models/AppResourcesView.js +64 -0
  189. package/dist/models/AppToolsResponse.d.ts +14 -0
  190. package/dist/models/AppToolsResponse.js +4 -0
  191. package/dist/models/AppView.d.ts +42 -0
  192. package/dist/models/AppView.js +14 -0
  193. package/dist/models/ArtifactVersionResponse.d.ts +94 -0
  194. package/dist/models/ArtifactVersionResponse.js +88 -0
  195. package/dist/models/AttachedAgent.d.ts +44 -0
  196. package/dist/models/AttachedAgent.js +56 -0
  197. package/dist/models/Auth.d.ts +30 -0
  198. package/dist/models/Auth.js +58 -0
  199. package/dist/models/BindCustomApiBody.d.ts +32 -0
  200. package/dist/models/BindCustomApiBody.js +50 -0
  201. package/dist/models/CollectionCreate.d.ts +4 -5
  202. package/dist/models/CollectionCreate.js +3 -2
  203. package/dist/models/CollectionResource.d.ts +13 -0
  204. package/dist/models/CollectionResource.js +5 -0
  205. package/dist/models/CollectionUpdate.d.ts +4 -5
  206. package/dist/models/CollectionUpdate.js +3 -2
  207. package/dist/models/ConversationArtifact.d.ts +14 -0
  208. package/dist/models/ConversationArtifact.js +10 -0
  209. package/dist/models/CustomApi.d.ts +102 -0
  210. package/dist/models/CustomApi.js +98 -0
  211. package/dist/models/CustomApiBasicAuth.d.ts +51 -0
  212. package/dist/models/CustomApiBasicAuth.js +65 -0
  213. package/dist/models/CustomApiBearerAuth.d.ts +45 -0
  214. package/dist/models/CustomApiBearerAuth.js +61 -0
  215. package/dist/models/CustomApiCreate.d.ts +57 -0
  216. package/dist/models/CustomApiCreate.js +63 -0
  217. package/dist/models/CustomApiHeader.d.ts +44 -0
  218. package/dist/models/CustomApiHeader.js +54 -0
  219. package/dist/models/CustomApiHeadersAuth.d.ts +46 -0
  220. package/dist/models/CustomApiHeadersAuth.js +62 -0
  221. package/dist/models/CustomApiList.d.ts +64 -0
  222. package/dist/models/CustomApiList.js +71 -0
  223. package/dist/models/CustomApiName.d.ts +44 -0
  224. package/dist/models/CustomApiName.js +56 -0
  225. package/dist/models/CustomApiUpdate.d.ts +58 -0
  226. package/dist/models/CustomApiUpdate.js +57 -0
  227. package/dist/models/CustomApiUpdateAuth.d.ts +30 -0
  228. package/dist/models/CustomApiUpdateAuth.js +58 -0
  229. package/dist/models/ErrorDetailItem.d.ts +5 -0
  230. package/dist/models/FieldDefinition.d.ts +63 -0
  231. package/dist/models/FieldDefinition.js +62 -0
  232. package/dist/models/ListModels403Response.d.ts +23 -0
  233. package/dist/models/ListModels403Response.js +51 -0
  234. package/dist/models/ModelEndpointView.d.ts +38 -0
  235. package/dist/models/ModelEndpointView.js +52 -0
  236. package/dist/models/ModelView.d.ts +69 -0
  237. package/dist/models/ModelView.js +63 -0
  238. package/dist/models/ModelsResponse.d.ts +33 -0
  239. package/dist/models/ModelsResponse.js +51 -0
  240. package/dist/models/SettingsIssueView.d.ts +44 -0
  241. package/dist/models/SettingsIssueView.js +58 -0
  242. package/dist/models/VersionCommitBody.d.ts +44 -0
  243. package/dist/models/VersionCommitBody.js +58 -0
  244. package/dist/models/VersionUploadUrlBody.d.ts +32 -0
  245. package/dist/models/VersionUploadUrlBody.js +50 -0
  246. package/dist/models/index.d.ts +29 -0
  247. package/dist/models/index.js +29 -0
  248. package/package.json +15 -2
  249. package/src/apis/AgentConversationsApi.ts +172 -3
  250. package/src/apis/AgentsApi.ts +242 -7
  251. package/src/apis/AppsApi.ts +174 -3
  252. package/src/apis/ArtifactsApi.ts +144 -0
  253. package/src/apis/ClarifyApi.ts +3 -3
  254. package/src/apis/CollectionsApi.ts +3 -3
  255. package/src/apis/ConversationsApi.ts +3 -3
  256. package/src/apis/CronsApi.ts +3 -3
  257. package/src/apis/CustomAPIsApi.ts +471 -0
  258. package/src/apis/MessagesApi.ts +3 -3
  259. package/src/apis/ModelsApi.ts +70 -0
  260. package/src/apis/QueueApi.ts +3 -3
  261. package/src/apis/ResponsesApi.ts +3 -3
  262. package/src/apis/SkillsApi.ts +3 -3
  263. package/src/apis/index.ts +2 -0
  264. package/src/compose/agent.ts +223 -0
  265. package/src/compose/deploy.ts +168 -0
  266. package/src/compose/errors.ts +66 -0
  267. package/src/compose/events.ts +122 -0
  268. package/src/compose/fingerprint.ts +74 -0
  269. package/src/compose/index.ts +13 -0
  270. package/src/compose/run.ts +601 -0
  271. package/src/compose/runState.ts +95 -0
  272. package/src/compose/settingsTransport.ts +299 -0
  273. package/src/compose/tools.ts +27 -0
  274. package/src/compose/transport.ts +48 -0
  275. package/src/models/AgentChannelRef.ts +2 -1
  276. package/src/models/AgentConversationDetail.ts +21 -5
  277. package/src/models/AgentConversationView.ts +15 -8
  278. package/src/models/AgentCreate.ts +8 -0
  279. package/src/models/AgentCustomApiList.ts +74 -0
  280. package/src/models/AgentResource.ts +16 -0
  281. package/src/models/AgentSettingsResponse.ts +99 -0
  282. package/src/models/AgentUpdate.ts +8 -0
  283. package/src/models/AppAccountView.ts +143 -0
  284. package/src/models/AppAccountsView.ts +118 -0
  285. package/src/models/AppResource.ts +48 -0
  286. package/src/models/AppResourceCheckView.ts +117 -0
  287. package/src/models/AppResourceView.ts +120 -0
  288. package/src/models/AppResourcesView.ts +102 -0
  289. package/src/models/AppToolsResponse.ts +16 -0
  290. package/src/models/AppView.ts +56 -0
  291. package/src/models/ArtifactVersionResponse.ts +155 -0
  292. package/src/models/AttachedAgent.ts +83 -0
  293. package/src/models/Auth.ts +84 -0
  294. package/src/models/BindCustomApiBody.ts +66 -0
  295. package/src/models/CollectionCreate.ts +13 -5
  296. package/src/models/CollectionResource.ts +23 -0
  297. package/src/models/CollectionUpdate.ts +13 -5
  298. package/src/models/ConversationArtifact.ts +19 -0
  299. package/src/models/CustomApi.ts +175 -0
  300. package/src/models/CustomApiBasicAuth.ts +94 -0
  301. package/src/models/CustomApiBearerAuth.ts +85 -0
  302. package/src/models/CustomApiCreate.ts +108 -0
  303. package/src/models/CustomApiHeader.ts +82 -0
  304. package/src/models/CustomApiHeadersAuth.ts +93 -0
  305. package/src/models/CustomApiList.ts +120 -0
  306. package/src/models/CustomApiName.ts +83 -0
  307. package/src/models/CustomApiUpdate.ts +106 -0
  308. package/src/models/CustomApiUpdateAuth.ts +84 -0
  309. package/src/models/ErrorDetailItem.ts +5 -0
  310. package/src/models/FieldDefinition.ts +108 -0
  311. package/src/models/ListModels403Response.ts +73 -0
  312. package/src/models/ModelEndpointView.ts +74 -0
  313. package/src/models/ModelView.ts +122 -0
  314. package/src/models/ModelsResponse.ts +74 -0
  315. package/src/models/SettingsIssueView.ts +84 -0
  316. package/src/models/VersionCommitBody.ts +84 -0
  317. package/src/models/VersionUploadUrlBody.ts +66 -0
  318. package/src/models/index.ts +29 -0
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setDefaultClient = setDefaultClient;
4
+ exports.getDefaultClient = getDefaultClient;
5
+ exports.resolveTransport = resolveTransport;
6
+ exports.deploy = deploy;
7
+ exports.undeploy = undeploy;
8
+ exports.forget = forget;
9
+ exports.agentIdFor = agentIdFor;
10
+ const errors_js_1 = require("./errors.js");
11
+ const fingerprint_js_1 = require("./fingerprint.js");
12
+ const settingsTransport_js_1 = require("./settingsTransport.js");
13
+ let defaultClient = null;
14
+ /** Set (or clear, with null) the client used when deploy/undeploy/run get no client. */
15
+ function setDefaultClient(config) {
16
+ defaultClient = config;
17
+ }
18
+ function getDefaultClient() {
19
+ return defaultClient;
20
+ }
21
+ function resolveTransport(client, transport) {
22
+ if (transport)
23
+ return transport;
24
+ const config = client !== null && client !== void 0 ? client : defaultClient;
25
+ if (!config) {
26
+ throw new errors_js_1.UserError("no client configured: pass client (or transport) or call setDefaultClient(config)");
27
+ }
28
+ return new settingsTransport_js_1.SettingsTransport(config);
29
+ }
30
+ function storedHash(remote) {
31
+ const metadata = remote.settings["metadata"];
32
+ const h = metadata ? metadata.sdk_hash : undefined;
33
+ return typeof h === "string" ? h : undefined;
34
+ }
35
+ function changedFields(remote, agent) {
36
+ const want = (0, fingerprint_js_1.fingerprintBody)(agent.toSettings());
37
+ const have = (0, fingerprint_js_1.fingerprintBody)(remote.settings);
38
+ const keys = [];
39
+ const all = new Set([...Object.keys(want), ...Object.keys(have)]);
40
+ all.forEach((k) => {
41
+ // like Python's want.get(k) != have.get(k): a missing key equals null
42
+ const a = (0, fingerprint_js_1.canonicalJson)(want[k] === undefined ? null : want[k]);
43
+ const b = (0, fingerprint_js_1.canonicalJson)(have[k] === undefined ? null : have[k]);
44
+ if (a !== b)
45
+ keys.push(k);
46
+ });
47
+ keys.sort();
48
+ if (remote.instructions !== agent.instructions)
49
+ keys.push("instructions");
50
+ return keys;
51
+ }
52
+ async function update(transport, remote, agent, strict) {
53
+ const stored = storedHash(remote);
54
+ if (stored !== undefined && (0, fingerprint_js_1.settingsFingerprint)(remote.instructions, remote.settings) !== stored) {
55
+ const changed = changedFields(remote, agent);
56
+ if (strict)
57
+ throw new errors_js_1.DriftError(changed);
58
+ console.warn(`agent "${agent.name}" (${remote.agentId}) was edited outside the SDK; overwriting fields: ${changed.join(", ")}`);
59
+ }
60
+ else if (stored === agent.specHash()) {
61
+ return { agentId: remote.agentId, action: "unchanged" };
62
+ }
63
+ await transport.updateAgent(remote.agentId, agent);
64
+ return { agentId: remote.agentId, action: "updated" };
65
+ }
66
+ async function deployWith(agent, transport, strict, adopt) {
67
+ const found = await transport.findAgents(agent.name);
68
+ if (adopt !== undefined) {
69
+ const target = await transport.readAgent(adopt);
70
+ const metadata = target.settings["metadata"];
71
+ const owner = metadata ? metadata.sdk_name : undefined;
72
+ if (owner !== undefined && owner !== null && owner !== agent.name) {
73
+ throw new errors_js_1.UserError(`agent ${adopt} is managed by SDK agent "${owner}", cannot adopt it as "${agent.name}"`);
74
+ }
75
+ const others = found.filter((r) => r.agentId !== adopt).map((r) => r.agentId);
76
+ if (others.length) {
77
+ throw new errors_js_1.UserError(`cannot adopt ${adopt}: agent "${agent.name}" is already deployed as ${others.join(", ")}`);
78
+ }
79
+ await transport.updateAgent(adopt, agent);
80
+ return { agentId: adopt, action: "updated" };
81
+ }
82
+ if (found.length > 1)
83
+ throw new errors_js_1.DuplicateAgentsError(found.map((r) => r.agentId));
84
+ if (found.length === 0)
85
+ return { agentId: (await transport.createAgent(agent)).agentId, action: "created" };
86
+ return update(transport, found[0], agent, strict);
87
+ }
88
+ async function deploy(agent, opts = {}) {
89
+ const transport = resolveTransport(opts.client, opts.transport);
90
+ forget(agent.name); // this deploy may replace what cached runs of the name point at
91
+ return serialized(agent.name, () => { var _a; return deployWith(agent, transport, (_a = opts.strict) !== null && _a !== void 0 ? _a : false, opts.adopt); });
92
+ }
93
+ async function undeploy(name, opts = {}) {
94
+ const transport = resolveTransport(opts.client, opts.transport);
95
+ forget(name);
96
+ return serialized(name, async () => {
97
+ const found = await transport.findAgents(name);
98
+ for (const remote of found)
99
+ await transport.deleteAgent(remote.agentId);
100
+ return found.length > 0;
101
+ });
102
+ }
103
+ // Per-name tail: every deploy/undeploy of a name (cached or direct) queues behind the previous one, so they never
104
+ // overlap. forget() does not touch it.
105
+ const tails = new Map();
106
+ function serialized(name, fn) {
107
+ const prev = tails.get(name);
108
+ const p = prev ? prev.then(fn) : fn();
109
+ const tail = p.then(() => undefined, () => undefined);
110
+ tails.set(name, tail);
111
+ tail.then(() => {
112
+ if (tails.get(name) === tail)
113
+ tails.delete(name);
114
+ });
115
+ return p;
116
+ }
117
+ const cache = new Map();
118
+ /** Drop cached deployments of agent `name` (any owner); called by deploy() and undeploy(). */
119
+ function forget(name) {
120
+ cache.delete(name);
121
+ }
122
+ /**
123
+ * The server id for `agent`, deploying it first unless this owner already deployed this exact definition.
124
+ * Keyed by name, as the server is: a variant with the same name redeploys, chained after any in-flight deploy so
125
+ * deploys of one name never overlap.
126
+ */
127
+ function agentIdFor(agent, transport, owner) {
128
+ const hash = agent.specHash();
129
+ let owners = cache.get(agent.name);
130
+ if (!owners) {
131
+ owners = new WeakMap();
132
+ cache.set(agent.name, owners);
133
+ }
134
+ const prev = owners.get(owner);
135
+ if (prev && prev.hash === hash)
136
+ return prev.id;
137
+ const id = serialized(agent.name, () => deployWith(agent, transport, false)).then((d) => d.agentId);
138
+ const entry = { hash, id };
139
+ owners.set(owner, entry);
140
+ const slot = owners;
141
+ id.catch(() => {
142
+ if (slot.get(owner) === entry)
143
+ slot.delete(owner);
144
+ });
145
+ return id;
146
+ }
@@ -0,0 +1,48 @@
1
+ /** Error hierarchy for the compose layer. */
2
+ export declare class AgentsError extends Error {
3
+ constructor(message?: string);
4
+ }
5
+ /** The caller supplied an invalid value. */
6
+ export declare class UserError extends AgentsError {
7
+ /** The server's `{ code, path, message }` issues when it rejected agent settings. */
8
+ readonly issues: Array<{
9
+ code?: string;
10
+ path?: string;
11
+ message?: string;
12
+ }>;
13
+ constructor(message?: string, issues?: Array<{
14
+ code?: string;
15
+ path?: string;
16
+ message?: string;
17
+ }>);
18
+ }
19
+ export declare class ModelBehaviorError extends AgentsError {
20
+ }
21
+ export declare class MaxTurnsExceededError extends AgentsError {
22
+ }
23
+ export declare class MaxTokensExceededError extends AgentsError {
24
+ }
25
+ export declare class MaxToolCallsExceededError extends AgentsError {
26
+ }
27
+ /** The agent has not been deployed. */
28
+ export declare class NotDeployedError extends AgentsError {
29
+ }
30
+ /** A feature the SDK does not support yet. */
31
+ export declare class NotSupportedError extends AgentsError {
32
+ }
33
+ export declare class RunError extends AgentsError {
34
+ readonly code: string;
35
+ constructor(code: string, message: string);
36
+ }
37
+ export declare class DriftError extends AgentsError {
38
+ readonly changed: string[];
39
+ constructor(changed: string[]);
40
+ }
41
+ export declare class DuplicateAgentsError extends AgentsError {
42
+ readonly agentIds: string[];
43
+ constructor(agentIds: string[]);
44
+ }
45
+ export declare class NotSupportedByServerError extends AgentsError {
46
+ readonly features: string[];
47
+ constructor(features: string[]);
48
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /** Error hierarchy for the compose layer. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.NotSupportedByServerError = exports.DuplicateAgentsError = exports.DriftError = exports.RunError = exports.NotSupportedError = exports.NotDeployedError = exports.MaxToolCallsExceededError = exports.MaxTokensExceededError = exports.MaxTurnsExceededError = exports.ModelBehaviorError = exports.UserError = exports.AgentsError = void 0;
5
+ class AgentsError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ this.name = new.target.name;
10
+ }
11
+ }
12
+ exports.AgentsError = AgentsError;
13
+ /** The caller supplied an invalid value. */
14
+ class UserError extends AgentsError {
15
+ constructor(message, issues = []) {
16
+ super(message);
17
+ this.issues = issues;
18
+ }
19
+ }
20
+ exports.UserError = UserError;
21
+ class ModelBehaviorError extends AgentsError {
22
+ }
23
+ exports.ModelBehaviorError = ModelBehaviorError;
24
+ class MaxTurnsExceededError extends AgentsError {
25
+ }
26
+ exports.MaxTurnsExceededError = MaxTurnsExceededError;
27
+ class MaxTokensExceededError extends AgentsError {
28
+ }
29
+ exports.MaxTokensExceededError = MaxTokensExceededError;
30
+ class MaxToolCallsExceededError extends AgentsError {
31
+ }
32
+ exports.MaxToolCallsExceededError = MaxToolCallsExceededError;
33
+ /** The agent has not been deployed. */
34
+ class NotDeployedError extends AgentsError {
35
+ }
36
+ exports.NotDeployedError = NotDeployedError;
37
+ /** A feature the SDK does not support yet. */
38
+ class NotSupportedError extends AgentsError {
39
+ }
40
+ exports.NotSupportedError = NotSupportedError;
41
+ class RunError extends AgentsError {
42
+ constructor(code, message) {
43
+ super(`${code}: ${message}`);
44
+ this.code = code;
45
+ }
46
+ }
47
+ exports.RunError = RunError;
48
+ class DriftError extends AgentsError {
49
+ constructor(changed) {
50
+ super("deployed agent drifted: " + changed.join(", "));
51
+ this.changed = changed.slice();
52
+ }
53
+ }
54
+ exports.DriftError = DriftError;
55
+ class DuplicateAgentsError extends AgentsError {
56
+ constructor(agentIds) {
57
+ super("duplicate agents: " + agentIds.join(", "));
58
+ this.agentIds = agentIds.slice();
59
+ }
60
+ }
61
+ exports.DuplicateAgentsError = DuplicateAgentsError;
62
+ class NotSupportedByServerError extends AgentsError {
63
+ constructor(features) {
64
+ super("server does not support: " + features.join(", "));
65
+ this.features = features.slice();
66
+ }
67
+ }
68
+ exports.NotSupportedByServerError = NotSupportedByServerError;
@@ -0,0 +1,63 @@
1
+ /** Stream event model for `/v1/responses` UI-message-stream chunks. */
2
+ export interface ClarifyQuestion {
3
+ id: string;
4
+ prompt: string;
5
+ inputType?: string;
6
+ choices?: string[];
7
+ [key: string]: unknown;
8
+ }
9
+ export interface FunctionCallRequest {
10
+ callId: string;
11
+ name: string;
12
+ arguments: Record<string, unknown>;
13
+ }
14
+ export type Event = {
15
+ kind: "text_start";
16
+ id: string;
17
+ } | {
18
+ kind: "text_delta";
19
+ delta: string;
20
+ id?: string;
21
+ } | {
22
+ kind: "text_end";
23
+ id: string;
24
+ } | {
25
+ kind: "reasoning_delta";
26
+ delta: string;
27
+ } | {
28
+ kind: "tool_called";
29
+ callId: string;
30
+ name: string;
31
+ arguments: unknown;
32
+ } | {
33
+ kind: "tool_output";
34
+ callId: string;
35
+ output: unknown;
36
+ } | {
37
+ kind: "clarify_requested";
38
+ requestId: string;
39
+ questions: ClarifyQuestion[];
40
+ } | {
41
+ kind: "function_calls_requested";
42
+ requestId: string;
43
+ calls: FunctionCallRequest[];
44
+ expiresAt?: string;
45
+ } | {
46
+ kind: "stopped";
47
+ reason: string;
48
+ } | {
49
+ kind: "turn_finished";
50
+ reason: string;
51
+ } | {
52
+ kind: "turn_failed";
53
+ code: string;
54
+ message: string;
55
+ } | {
56
+ kind: "unknown";
57
+ chunk: Record<string, unknown>;
58
+ };
59
+ /**
60
+ * Map one stream chunk to an Event; `null` for chunks the runner ignores.
61
+ * Never throws: malformed chunks degrade to `{ kind: "unknown", chunk }`.
62
+ */
63
+ export declare function fromUiChunk(chunk: unknown): Event | null;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /** Stream event model for `/v1/responses` UI-message-stream chunks. */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.fromUiChunk = fromUiChunk;
5
+ const IGNORED = ["start", "start-step", "finish-step", "tool-input-start", "tool-input-delta"];
6
+ function isObject(v) {
7
+ return typeof v === "object" && v !== null && !Array.isArray(v);
8
+ }
9
+ function str(v, fallback) {
10
+ return typeof v === "string" && v !== "" ? v : fallback;
11
+ }
12
+ function text(v) {
13
+ return typeof v === "string" ? v : "";
14
+ }
15
+ /**
16
+ * Map one stream chunk to an Event; `null` for chunks the runner ignores.
17
+ * Never throws: malformed chunks degrade to `{ kind: "unknown", chunk }`.
18
+ */
19
+ function fromUiChunk(chunk) {
20
+ if (!isObject(chunk))
21
+ return { kind: "unknown", chunk: chunk };
22
+ try {
23
+ return map(chunk);
24
+ }
25
+ catch (_a) {
26
+ return { kind: "unknown", chunk };
27
+ }
28
+ }
29
+ function map(chunk) {
30
+ var _a, _b;
31
+ const type = chunk["type"];
32
+ const data = isObject(chunk["data"]) ? chunk["data"] : {};
33
+ if (typeof type === "string" && IGNORED.indexOf(type) !== -1)
34
+ return null;
35
+ switch (type) {
36
+ case "text-start":
37
+ return { kind: "text_start", id: text(chunk["id"]) };
38
+ case "text-delta": {
39
+ const ev = { kind: "text_delta", delta: text(chunk["delta"]) };
40
+ if (typeof chunk["id"] === "string")
41
+ ev.id = chunk["id"];
42
+ return ev;
43
+ }
44
+ case "text-end":
45
+ return { kind: "text_end", id: text(chunk["id"]) };
46
+ case "reasoning-delta":
47
+ return { kind: "reasoning_delta", delta: text(chunk["delta"]) };
48
+ case "tool-input-available":
49
+ return {
50
+ kind: "tool_called",
51
+ callId: text(chunk["toolCallId"]),
52
+ name: text(chunk["toolName"]),
53
+ arguments: chunk["input"],
54
+ };
55
+ case "tool-output-available":
56
+ return { kind: "tool_output", callId: text(chunk["toolCallId"]), output: chunk["output"] };
57
+ case "data-clarify-request": {
58
+ const questions = (_a = data["questions"]) !== null && _a !== void 0 ? _a : [];
59
+ if (!Array.isArray(questions))
60
+ throw new TypeError("questions must be a list");
61
+ return {
62
+ kind: "clarify_requested",
63
+ requestId: str(data["requestId"], text(chunk["id"])),
64
+ questions: questions,
65
+ };
66
+ }
67
+ case "data-function-call-request": {
68
+ const raw = (_b = data["calls"]) !== null && _b !== void 0 ? _b : [];
69
+ if (!Array.isArray(raw))
70
+ throw new TypeError("calls must be a list");
71
+ const calls = raw.map((c) => {
72
+ if (!isObject(c))
73
+ throw new TypeError("call must be an object");
74
+ const args = c["arguments"];
75
+ return {
76
+ callId: text(c["toolCallId"]),
77
+ name: text(c["name"]),
78
+ arguments: isObject(args) ? args : {},
79
+ };
80
+ });
81
+ const ev = {
82
+ kind: "function_calls_requested",
83
+ requestId: str(data["requestId"], text(chunk["id"])),
84
+ calls,
85
+ };
86
+ if (typeof data["expiresAt"] === "string")
87
+ ev.expiresAt = data["expiresAt"];
88
+ return ev;
89
+ }
90
+ case "data-stopped":
91
+ return { kind: "stopped", reason: str(data["reason"], "stopped") };
92
+ case "error":
93
+ return { kind: "turn_failed", code: str(chunk["code"], "turn_failed"), message: text(chunk["errorText"]) };
94
+ case "finish":
95
+ return { kind: "turn_finished", reason: str(chunk["finishReason"], "stop") };
96
+ default:
97
+ // data-output and data-output-error are unknown until structured output lands.
98
+ return { kind: "unknown", chunk };
99
+ }
100
+ }
@@ -0,0 +1,6 @@
1
+ /** Settings as fingerprinted: metadata keeps the user's keys but drops sdk_name/sdk_hash (and goes when empty). */
2
+ export declare function fingerprintBody(settings: Record<string, unknown>): Record<string, unknown>;
3
+ /** Canonical JSON: code-point-sorted keys, no spaces, ASCII-only strings, ECMAScript numbers. */
4
+ export declare function canonicalJson(value: unknown): string;
5
+ /** Hash of instructions + settings (minus metadata.sdk_*); the single source of truth for sdk_hash. */
6
+ export declare function settingsFingerprint(instructions: string, settings: Record<string, unknown>): string;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fingerprintBody = fingerprintBody;
4
+ exports.canonicalJson = canonicalJson;
5
+ exports.settingsFingerprint = settingsFingerprint;
6
+ const node_crypto_1 = require("node:crypto");
7
+ const errors_js_1 = require("./errors.js");
8
+ const SDK_KEYS = ["sdk_name", "sdk_hash"];
9
+ /** Settings as fingerprinted: metadata keeps the user's keys but drops sdk_name/sdk_hash (and goes when empty). */
10
+ function fingerprintBody(settings) {
11
+ const body = {};
12
+ for (const key of Object.keys(settings)) {
13
+ if (key !== "metadata")
14
+ body[key] = settings[key];
15
+ }
16
+ const metadata = settings["metadata"];
17
+ if (metadata !== null && typeof metadata === "object" && !Array.isArray(metadata)) {
18
+ const user = {};
19
+ let any = false;
20
+ for (const key of Object.keys(metadata)) {
21
+ if (SDK_KEYS.indexOf(key) === -1) {
22
+ user[key] = metadata[key];
23
+ any = true;
24
+ }
25
+ }
26
+ if (any)
27
+ body["metadata"] = user;
28
+ }
29
+ else if (metadata !== undefined && metadata !== null) {
30
+ body["metadata"] = metadata;
31
+ }
32
+ return body;
33
+ }
34
+ function compareCodePoints(a, b) {
35
+ const x = Array.from(a);
36
+ const y = Array.from(b);
37
+ const n = Math.min(x.length, y.length);
38
+ for (let i = 0; i < n; i++) {
39
+ const d = x[i].codePointAt(0) - y[i].codePointAt(0);
40
+ if (d !== 0)
41
+ return d;
42
+ }
43
+ return x.length - y.length;
44
+ }
45
+ /** A string as Python's json.dumps(ensure_ascii=True) writes it. */
46
+ function quote(s) {
47
+ const json = JSON.stringify(s); // short escapes for control characters, \uXXXX (lowercase) for lone surrogates
48
+ let out = "";
49
+ for (let i = 0; i < json.length; i++) {
50
+ const c = json.charCodeAt(i);
51
+ out += c > 0x7e ? "\\u" + c.toString(16).padStart(4, "0") : json[i];
52
+ }
53
+ return out;
54
+ }
55
+ /** Canonical JSON: code-point-sorted keys, no spaces, ASCII-only strings, ECMAScript numbers. */
56
+ function canonicalJson(value) {
57
+ if (value === null)
58
+ return "null";
59
+ if (value === true)
60
+ return "true";
61
+ if (value === false)
62
+ return "false";
63
+ if (typeof value === "number") {
64
+ if (!Number.isFinite(value))
65
+ throw new errors_js_1.UserError("NaN and Infinity cannot be fingerprinted");
66
+ return Number.isInteger(value) ? BigInt(value).toString() : JSON.stringify(value);
67
+ }
68
+ if (typeof value === "string")
69
+ return quote(value);
70
+ if (Array.isArray(value))
71
+ return "[" + value.map((v) => canonicalJson(v)).join(",") + "]";
72
+ if (typeof value === "object" && value !== undefined) {
73
+ const obj = value;
74
+ const keys = Object.keys(obj).filter((k) => obj[k] !== undefined).sort(compareCodePoints);
75
+ return "{" + keys.map((k) => quote(k) + ":" + canonicalJson(obj[k])).join(",") + "}";
76
+ }
77
+ throw new errors_js_1.UserError(`cannot fingerprint ${typeof value}`);
78
+ }
79
+ /** Hash of instructions + settings (minus metadata.sdk_*); the single source of truth for sdk_hash. */
80
+ function settingsFingerprint(instructions, settings) {
81
+ const raw = canonicalJson({ instructions, settings: fingerprintBody(settings) });
82
+ return (0, node_crypto_1.createHash)("sha256").update(raw, "utf8").digest("hex");
83
+ }
@@ -0,0 +1,13 @@
1
+ export * from "./errors.js";
2
+ export * from "./fingerprint.js";
3
+ export * from "./tools.js";
4
+ export * from "./agent.js";
5
+ export type { Event, ClarifyQuestion, FunctionCallRequest } from "./events.js";
6
+ export { SettingsTransport } from "./settingsTransport.js";
7
+ export type { RemoteAgent, SettingsWarning, TurnStream, Transport } from "./transport.js";
8
+ export { deploy, undeploy, setDefaultClient } from "./deploy.js";
9
+ export type { Deployment } from "./deploy.js";
10
+ export { run, RunResult, StreamedRunResult } from "./run.js";
11
+ export type { RunOptions, RunStreamEvent, ClarifyHandler } from "./run.js";
12
+ export { RunState } from "./runState.js";
13
+ export type { Interruption } from "./runState.js";
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RunState = exports.StreamedRunResult = exports.RunResult = exports.run = exports.setDefaultClient = exports.undeploy = exports.deploy = exports.SettingsTransport = void 0;
18
+ __exportStar(require("./errors.js"), exports);
19
+ __exportStar(require("./fingerprint.js"), exports);
20
+ __exportStar(require("./tools.js"), exports);
21
+ __exportStar(require("./agent.js"), exports);
22
+ var settingsTransport_js_1 = require("./settingsTransport.js");
23
+ Object.defineProperty(exports, "SettingsTransport", { enumerable: true, get: function () { return settingsTransport_js_1.SettingsTransport; } });
24
+ var deploy_js_1 = require("./deploy.js");
25
+ Object.defineProperty(exports, "deploy", { enumerable: true, get: function () { return deploy_js_1.deploy; } });
26
+ Object.defineProperty(exports, "undeploy", { enumerable: true, get: function () { return deploy_js_1.undeploy; } });
27
+ Object.defineProperty(exports, "setDefaultClient", { enumerable: true, get: function () { return deploy_js_1.setDefaultClient; } });
28
+ var run_js_1 = require("./run.js");
29
+ Object.defineProperty(exports, "run", { enumerable: true, get: function () { return run_js_1.run; } });
30
+ Object.defineProperty(exports, "RunResult", { enumerable: true, get: function () { return run_js_1.RunResult; } });
31
+ Object.defineProperty(exports, "StreamedRunResult", { enumerable: true, get: function () { return run_js_1.StreamedRunResult; } });
32
+ var runState_js_1 = require("./runState.js");
33
+ Object.defineProperty(exports, "RunState", { enumerable: true, get: function () { return runState_js_1.RunState; } });
@@ -0,0 +1,100 @@
1
+ /** run(): deploy the agent, drive one turn through a Transport, handle clarify questions, dropped streams and cancel. */
2
+ import type { Configuration } from "../runtime.js";
3
+ import type { Agent } from "./agent.js";
4
+ import type { ClarifyQuestion, Event } from "./events.js";
5
+ import { RunState } from "./runState.js";
6
+ import type { Interruption } from "./runState.js";
7
+ import type { Transport } from "./transport.js";
8
+ export type ClarifyHandler = (questions: ClarifyQuestion[]) => Record<string, unknown> | Promise<Record<string, unknown>>;
9
+ export interface RunOptions {
10
+ client?: Configuration;
11
+ transport?: Transport;
12
+ /** Continue this conversation (a previous `result.conversationId`). */
13
+ conversationId?: string;
14
+ /** Aborting stops reading, tells the server to stop the turn, and resolves with `finalOutput` undefined. */
15
+ signal?: AbortSignal;
16
+ /** Answers clarify questions; without it a question ends the run with an interruption. */
17
+ onClarify?: ClarifyHandler;
18
+ /** Not supported: the server caps turns per agent; set `new Agent({ limits: { maxTurns } })`. */
19
+ maxTurns?: never;
20
+ }
21
+ export type RunStreamEvent = {
22
+ type: "raw_model_stream_event";
23
+ data: {
24
+ type: "output_text_delta" | "reasoning_delta";
25
+ delta: string;
26
+ };
27
+ } | {
28
+ type: "run_item_stream_event";
29
+ name: "tool_called" | "tool_output" | "message_output_created";
30
+ item: unknown;
31
+ };
32
+ interface Outcome {
33
+ finalOutput: string | undefined;
34
+ outputText: string;
35
+ newItems: Event[];
36
+ interruptions: Interruption[];
37
+ conversationId: string | undefined;
38
+ cancelled: boolean;
39
+ }
40
+ export declare class RunResult {
41
+ readonly finalOutput: string | undefined;
42
+ readonly outputText: string;
43
+ readonly newItems: Event[];
44
+ readonly interruptions: Interruption[];
45
+ readonly conversationId: string | undefined;
46
+ /** @internal */
47
+ constructor(outcome: Outcome);
48
+ /** A RunState to answer the interruptions and continue; throws UserError when the run has no conversation. */
49
+ get state(): RunState;
50
+ }
51
+ interface Prepared {
52
+ agent: Agent;
53
+ input: string | RunState;
54
+ opts: RunOptions;
55
+ transport: Transport;
56
+ owner: object;
57
+ }
58
+ /** Returned by `run(..., { stream: true })`. Iterate it once (or use `toTextStream()`); leaving early cancels. */
59
+ export declare class StreamedRunResult implements AsyncIterable<RunStreamEvent> {
60
+ /** Settles when the run ends; rejects with the run's error. */
61
+ readonly completed: Promise<void>;
62
+ finalOutput: string | undefined;
63
+ outputText: string;
64
+ newItems: Event[];
65
+ interruptions: Interruption[];
66
+ conversationId: string | undefined;
67
+ cancelled: boolean;
68
+ private readonly queue;
69
+ private waiters;
70
+ private done;
71
+ private failure;
72
+ private consumed;
73
+ private readonly controller;
74
+ /** @internal */
75
+ constructor(prepared: Prepared);
76
+ get state(): RunState;
77
+ private push;
78
+ private end;
79
+ private notify;
80
+ private claim;
81
+ /**
82
+ * The event iterator. Hand-written rather than an async generator: a generator's return() queues behind a pending
83
+ * next(), so leaving while the server is quiet would neither settle nor cancel the run until another event came.
84
+ */
85
+ private events;
86
+ [Symbol.asyncIterator](): AsyncIterator<RunStreamEvent>;
87
+ /** The output text deltas as a ReadableStream; consumes this result's events. */
88
+ toTextStream(): ReadableStream<string>;
89
+ }
90
+ /**
91
+ * Run `agent` on `input` (a message, or a RunState holding answers), deploying it first if this owner has not
92
+ * deployed this exact definition. With `stream: true`, resolves at once with a StreamedRunResult.
93
+ */
94
+ export declare function run(agent: Agent, input: string | RunState, opts: RunOptions & {
95
+ stream: true;
96
+ }): Promise<StreamedRunResult>;
97
+ export declare function run(agent: Agent, input: string | RunState, opts?: RunOptions & {
98
+ stream?: false;
99
+ }): Promise<RunResult>;
100
+ export {};