nanocodex 0.4.0 → 0.6.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 (196) hide show
  1. package/README.md +944 -78
  2. package/actions/events.mjs +14 -25
  3. package/actions/index.d.mts +1 -0
  4. package/actions/index.mjs +11 -1
  5. package/actions/session.d.mts +29 -1
  6. package/actions/session.mjs +22 -0
  7. package/actions/turn.d.mts +15 -6
  8. package/actions/turn.mjs +10 -0
  9. package/actions/voice.d.mts +26 -0
  10. package/actions/voice.mjs +54 -0
  11. package/browser/Agent.d.mts +41 -24
  12. package/browser/Agent.mjs +7 -84
  13. package/browser/ChatGptSubscription.d.mts +7 -0
  14. package/browser/ChatGptSubscription.mjs +19 -0
  15. package/browser/InlineAgent.mjs +267 -0
  16. package/browser/Transport.d.mts +80 -0
  17. package/browser/Transport.mjs +63 -0
  18. package/browser/Voice.d.mts +86 -0
  19. package/browser/Voice.mjs +316 -0
  20. package/browser/VoiceSession.mjs +763 -0
  21. package/browser/WorkerAgent.d.mts +65 -0
  22. package/browser/WorkerAgent.mjs +1467 -0
  23. package/browser/agent.worker.mjs +3 -0
  24. package/browser/config.d.mts +36 -0
  25. package/browser/config.mjs +439 -0
  26. package/browser/engine.mjs +13 -0
  27. package/browser/harness.mjs +55 -0
  28. package/browser/host.d.mts +33 -5
  29. package/browser/host.mjs +320 -26
  30. package/browser/hostManagedWebSocket.d.mts +14 -0
  31. package/browser/hostManagedWebSocket.mjs +110 -0
  32. package/browser/index.d.mts +64 -1
  33. package/browser/index.mjs +22 -1
  34. package/browser/indexeddb-durability-store.mjs +210 -0
  35. package/browser/workspace.d.mts +16 -0
  36. package/browser/workspace.mjs +107 -0
  37. package/cloud/Client.d.mts +83 -0
  38. package/cloud/Client.mjs +231 -0
  39. package/cloud/Decorator.d.mts +31 -0
  40. package/cloud/Decorator.mjs +37 -0
  41. package/cloud/Dialog.d.mts +113 -0
  42. package/cloud/Dialog.mjs +366 -0
  43. package/cloud/Errors.d.mts +22 -0
  44. package/cloud/Errors.mjs +39 -0
  45. package/cloud/Principal.d.mts +26 -0
  46. package/cloud/Principal.mjs +88 -0
  47. package/cloud/RemoteProvider.mjs +88 -0
  48. package/cloud/Transport.d.mts +47 -0
  49. package/cloud/Transport.mjs +454 -0
  50. package/cloud/actions/account.d.mts +9 -0
  51. package/cloud/actions/account.mjs +19 -0
  52. package/cloud/actions/agent.d.mts +18 -0
  53. package/cloud/actions/agent.mjs +429 -0
  54. package/cloud/actions/connection.d.mts +133 -0
  55. package/cloud/actions/connection.mjs +580 -0
  56. package/cloud/actions/grant.d.mts +10 -0
  57. package/cloud/actions/grant.mjs +12 -0
  58. package/cloud/actions/index.d.mts +7 -0
  59. package/cloud/actions/index.mjs +7 -0
  60. package/cloud/actions/machineUsd.d.mts +23 -0
  61. package/cloud/actions/machineUsd.mjs +37 -0
  62. package/cloud/actions/model.d.mts +12 -0
  63. package/cloud/actions/model.mjs +50 -0
  64. package/cloud/actions/mpp.d.mts +28 -0
  65. package/cloud/actions/mpp.mjs +39 -0
  66. package/cloud/index.d.mts +30 -0
  67. package/cloud/index.mjs +9 -0
  68. package/cloud/internal.mjs +533 -0
  69. package/cloud/mercator.mjs +108 -0
  70. package/cloud/server/HostPrincipal.d.mts +34 -0
  71. package/cloud/server/HostPrincipal.mjs +202 -0
  72. package/cloud/server/index.d.mts +1 -0
  73. package/cloud/server/index.mjs +1 -0
  74. package/cloud/types.d.mts +212 -0
  75. package/cloudflare/Agent.d.mts +136 -0
  76. package/cloudflare/Agent.mjs +784 -0
  77. package/cloudflare/egress-subject.mjs +19 -0
  78. package/cloudflare/egress.d.mts +41 -0
  79. package/cloudflare/egress.mjs +119 -0
  80. package/cloudflare/event-socket.mjs +316 -0
  81. package/cloudflare/index.d.mts +7 -0
  82. package/cloudflare/index.mjs +6 -0
  83. package/host/Agent.d.mts +55 -0
  84. package/host/Agent.mjs +1 -0
  85. package/host/index.d.mts +71 -0
  86. package/host/index.mjs +10 -0
  87. package/index.d.mts +46 -0
  88. package/index.mjs +11 -0
  89. package/internal.mjs +673 -61
  90. package/managed/Agent.d.mts +459 -0
  91. package/managed/Agent.mjs +1824 -0
  92. package/managed/ManagedError.d.mts +9 -0
  93. package/managed/ManagedError.mjs +8 -0
  94. package/managed/README.md +244 -0
  95. package/managed/Voice.mjs +209 -0
  96. package/managed/index.d.mts +22 -0
  97. package/managed/index.mjs +2 -0
  98. package/managed/internal.mjs +119 -0
  99. package/node/Agent.d.mts +35 -8
  100. package/node/Agent.mjs +116 -25
  101. package/node/ChatGptSubscription.d.mts +9 -0
  102. package/node/ChatGptSubscription.mjs +17 -0
  103. package/node/Transport.d.mts +41 -0
  104. package/node/Transport.mjs +46 -0
  105. package/node/host.mjs +99 -17
  106. package/node/index.d.mts +45 -1
  107. package/node/index.mjs +16 -1
  108. package/node/workspace.d.mts +10 -0
  109. package/node/workspace.mjs +198 -0
  110. package/package.json +145 -11
  111. package/pkg-node/nanocodex.d.ts +523 -11
  112. package/pkg-node/nanocodex.js +2038 -179
  113. package/pkg-node/nanocodex_bg.wasm.d.ts +100 -29
  114. package/pkg-web/.nanocodex-bindgen-stamp +6 -0
  115. package/pkg-web/nanocodex-build.json +1 -0
  116. package/pkg-web/nanocodex.d.ts +623 -40
  117. package/pkg-web/nanocodex.js +2031 -178
  118. package/pkg-web/nanocodex_bg.js +2667 -0
  119. package/pkg-web/nanocodex_bg.wasm +0 -0
  120. package/pkg-web/nanocodex_bg.wasm.d.ts +100 -29
  121. package/pkg-web/nanocodex_worker.js +9 -0
  122. package/runtime/chatgpt-subscription.mjs +212 -0
  123. package/runtime/cloudflare-durability-store.d.mts +26 -0
  124. package/runtime/cloudflare-durability-store.mjs +14 -0
  125. package/runtime/code-evaluator.worker.mjs +137 -0
  126. package/runtime/code-runtime.mjs +1 -243
  127. package/runtime/durability-store.d.mts +85 -0
  128. package/runtime/durability-store.mjs +752 -0
  129. package/runtime/durability.mjs +174 -0
  130. package/runtime/managed-transport.mjs +461 -0
  131. package/runtime/mcp-runtime.mjs +534 -0
  132. package/runtime/postgres-durability-store.d.mts +64 -0
  133. package/runtime/postgres-durability-store.mjs +581 -0
  134. package/runtime/quickjs-evaluator.d.mts +17 -0
  135. package/runtime/quickjs-evaluator.mjs +236 -0
  136. package/runtime/response-controls.mjs +42 -0
  137. package/runtime/response-lanes.mjs +72 -0
  138. package/runtime/responses-transport.mjs +22 -0
  139. package/runtime/subagents.d.mts +107 -0
  140. package/runtime/subagents.mjs +54 -0
  141. package/runtime/subscription-store.d.mts +8 -0
  142. package/runtime/subscription-store.mjs +42 -0
  143. package/runtime/tempo-provider.d.mts +125 -0
  144. package/runtime/tempo-provider.mjs +264 -0
  145. package/runtime/tool-configuration.mjs +1 -0
  146. package/runtime/tool-router.mjs +1 -0
  147. package/runtime/utf8.mjs +1 -0
  148. package/runtime/worker-evaluator.mjs +162 -0
  149. package/runtime/workspace.d.mts +1 -0
  150. package/runtime/workspace.mjs +1 -0
  151. package/tools/Tools.d.mts +56 -0
  152. package/tools/Tools.mjs +136 -0
  153. package/tools/artifact.d.mts +1 -0
  154. package/tools/artifact.mjs +1 -0
  155. package/tools/attachment.mjs +1 -0
  156. package/tools/bash.d.mts +1 -0
  157. package/tools/bash.mjs +1 -0
  158. package/tools/browser/accountInfo.mjs +795 -0
  159. package/tools/browser/browserBuffer.mjs +18 -0
  160. package/tools/browser/browserCompiler.mjs +155 -0
  161. package/tools/browser/browserEgress.mjs +161 -0
  162. package/tools/browser/browserPython.mjs +133 -0
  163. package/tools/browser/browserShell.mjs +1075 -0
  164. package/tools/browser/browserSprintf.mjs +4 -0
  165. package/tools/browser/browserSsh.mjs +201 -0
  166. package/tools/browser/browserZlib.mjs +136 -0
  167. package/tools/browser/compiler.worker.mjs +160 -0
  168. package/tools/browser/devTunnelsSshBrowser.mjs +13 -0
  169. package/tools/browser/index.d.mts +209 -0
  170. package/tools/browser/index.mjs +174 -0
  171. package/tools/browser/opfsGit.mjs +248 -0
  172. package/tools/browser/python.worker.mjs +114 -0
  173. package/tools/browser/threadGit.mjs +197 -0
  174. package/tools/browser/unsupportedNodeRsa.mjs +5 -0
  175. package/tools/browser/workspace.mjs +83 -0
  176. package/tools/dataset.d.mts +1 -0
  177. package/tools/dataset.mjs +1 -0
  178. package/tools/datasetContract.mjs +1 -0
  179. package/tools/datasetEngine.mjs +1 -0
  180. package/tools/hostedCatalog.d.mts +1 -0
  181. package/tools/hostedCatalog.mjs +1 -0
  182. package/tools/index.d.mts +49 -0
  183. package/tools/index.mjs +19 -0
  184. package/tools/namedTool.mjs +1 -0
  185. package/tools/repository-workspace.d.mts +1 -0
  186. package/tools/repository-workspace.mjs +1 -0
  187. package/tools/ssh.d.mts +1 -0
  188. package/tools/ssh.mjs +1 -0
  189. package/tools/standard.mjs +1 -0
  190. package/tools/standardDescriptions.mjs +1 -0
  191. package/types.d.mts +431 -16
  192. package/worker/ChatGptSubscription.d.mts +9 -0
  193. package/worker/ChatGptSubscription.mjs +29 -0
  194. package/worker/index.d.mts +18 -0
  195. package/worker/index.mjs +5 -0
  196. package/pkg-node/nanocodex_bg.wasm +0 -0
@@ -0,0 +1,459 @@
1
+ import type { Model, PromptInput, ReasoningMode, Thinking, TurnUsage } from "../types.mjs";
2
+ import type { AgentId } from "../runtime/subagents.mjs";
3
+
4
+ export type HistorySource = Readonly<{ turn_id: string; cursor: string }>;
5
+ export type HistoryCitation = Readonly<{
6
+ thread_id: string;
7
+ title: string;
8
+ sources: readonly HistorySource[];
9
+ }>;
10
+ export type SessionSearchHit = Readonly<{
11
+ session_id: string;
12
+ title: string;
13
+ turn_id: string;
14
+ cursor: string;
15
+ score: number;
16
+ snippet: string;
17
+ }>;
18
+ export type FindSessionsRequest = Readonly<{
19
+ query: string;
20
+ limit?: number | undefined;
21
+ }>;
22
+ export type FindSessionsResponse = Readonly<{
23
+ query: string;
24
+ results: readonly SessionSearchHit[];
25
+ citations: readonly HistoryCitation[];
26
+ }>;
27
+ export type ReadSessionRequest = Readonly<{
28
+ session_id: string;
29
+ turn_ids?: readonly string[] | undefined;
30
+ }>;
31
+ export type SessionTurn = Readonly<{
32
+ session_id: string;
33
+ title: string;
34
+ turn_id: string;
35
+ cursor: string;
36
+ user: string;
37
+ assistant: string;
38
+ }>;
39
+ export type ReadSessionResponse = Readonly<{
40
+ turns: readonly SessionTurn[];
41
+ citations: readonly HistoryCitation[];
42
+ }>;
43
+ export type MemoryKey = Readonly<{ id: number; version: number }>;
44
+ export type MemoryRecord = Readonly<{
45
+ key: MemoryKey;
46
+ content: string;
47
+ created_at_ms: number;
48
+ updated_at_ms: number;
49
+ last_scanned_at_ms: number | null;
50
+ scan_count: number;
51
+ last_used_at_ms: number | null;
52
+ use_count: number;
53
+ probation_until_ms: number | null;
54
+ }>;
55
+ export type MemoryCandidate = Readonly<{
56
+ key: MemoryKey;
57
+ preview: string;
58
+ score: number;
59
+ }>;
60
+ export type MemoryScanOperation = Readonly<{
61
+ operation: "scan";
62
+ query: string;
63
+ limit?: number | undefined;
64
+ }>;
65
+ export type MemoryReadOperation = Readonly<{ operation: "read"; keys: readonly MemoryKey[] }>;
66
+ export type MemoryPutOperation = Readonly<{
67
+ operation: "put";
68
+ content: string;
69
+ replace?: MemoryKey | undefined;
70
+ }>;
71
+ export type MemoryDeleteOperation = Readonly<{ operation: "delete"; key: MemoryKey }>;
72
+ export type MemoryOperation =
73
+ | MemoryScanOperation
74
+ | MemoryReadOperation
75
+ | MemoryPutOperation
76
+ | MemoryDeleteOperation;
77
+ export type MemoryScanResult = Readonly<{
78
+ operation: "scan";
79
+ abstained: boolean;
80
+ candidates: readonly MemoryCandidate[];
81
+ }>;
82
+ export type MemoryReadResult = Readonly<{
83
+ operation: "read";
84
+ memories: readonly MemoryRecord[];
85
+ }>;
86
+ export type MemoryPutResult = Readonly<{
87
+ operation: "put";
88
+ memory: MemoryRecord;
89
+ replaced: boolean;
90
+ }>;
91
+ export type MemoryDeleteResult = Readonly<{ operation: "delete"; key: MemoryKey }>;
92
+ export type MemoryResult =
93
+ | MemoryScanResult
94
+ | MemoryReadResult
95
+ | MemoryPutResult
96
+ | MemoryDeleteResult;
97
+
98
+ export type Organization = Readonly<{
99
+ id: string;
100
+ name: string | null;
101
+ rootTeam: Readonly<{ id: string; name: string | null }>;
102
+ authorizationEpoch: number;
103
+ createdAt: number;
104
+ updatedAt: number;
105
+ }>;
106
+ export type OrganizationUpdate = Readonly<{ name: string | null }>;
107
+
108
+ export type Options = Readonly<{
109
+ /** Managed service origin. Defaults to the current browser origin. */
110
+ baseUrl?: string | URL | undefined;
111
+ /** Server credential. Browsers omit this and authenticate with the account cookie. */
112
+ apiKey?: string | undefined;
113
+ /** Platform-compatible fetch implementation, primarily for non-browser hosts and tests. */
114
+ fetch?: typeof globalThis.fetch | undefined;
115
+ /** WebSocket factory for Node/RN. Authorization is supplied only to this private handshake callback. */
116
+ toolsTransport?: ((target: URL, options: Readonly<{
117
+ headers?: Readonly<Record<string, string>>;
118
+ credentials?: "include";
119
+ }>) => import("../tools/Tools.mjs").AttachmentSocket | Promise<import("../tools/Tools.mjs").AttachmentSocket>) | Readonly<{
120
+ connect(target: URL, options: Readonly<{
121
+ headers?: Readonly<Record<string, string>>;
122
+ credentials?: "include";
123
+ }>): import("../tools/Tools.mjs").AttachmentSocket | Promise<import("../tools/Tools.mjs").AttachmentSocket>;
124
+ }> | undefined;
125
+ }>;
126
+
127
+ export type CreateSettings = Readonly<{
128
+ model: Model;
129
+ thinking: Thinking;
130
+ reasoningMode: ReasoningMode;
131
+ fastMode: boolean;
132
+ }>;
133
+
134
+ export type SettingsPatch = Readonly<Partial<CreateSettings>>;
135
+
136
+ export type NetworkPolicy = Readonly<{ access: "enabled" | "disabled" }> | Readonly<{ access: "restricted"; allowed_domains: readonly string[] }>;
137
+ export type Environment = Readonly<{
138
+ files?: readonly Readonly<{ path: string; content: string }>[];
139
+ skills?: readonly Readonly<{ name: string; instructions: string }>[];
140
+ setup_commands?: readonly string[];
141
+ network?: NetworkPolicy;
142
+ }>;
143
+ export type Configuration = Readonly<{
144
+ settings?: Readonly<{ model: CreateSettings["model"]; thinking: CreateSettings["thinking"]; reasoning_mode: "standard" | "pro"; fast_mode: boolean }>;
145
+ instructions?: string;
146
+ tools?: readonly string[];
147
+ /** Omission retains existing delegation. Explicit enablement defaults to six concurrent children. */
148
+ multi_agent?: Readonly<{ enabled: false }> | Readonly<{ enabled: true; max_concurrent_subagents?: number }>;
149
+ output_schema?: Record<string, unknown>;
150
+ prompt_cache?: "implicit" | "explicit";
151
+ environment?: Environment;
152
+ }>;
153
+ export type Template<T> = Readonly<{ id: string; created_at: number; configuration: T }>;
154
+ export type TemplateCatalog<T> = Readonly<{
155
+ list(options?: Options): Promise<{ data: Template<T>[] }>;
156
+ get(id: string, options?: Options): Promise<Template<T>>;
157
+ put(id: string, configuration: T, options?: Options): Promise<Template<T>>;
158
+ delete(id: string, options?: Options): Promise<void>;
159
+ }>;
160
+ export const definitions: TemplateCatalog<Configuration>;
161
+ export const environments: TemplateCatalog<Environment>;
162
+ export type EnvironmentState = Readonly<{ state: "uninitialized" | "running" | "ready" | "failed"; step: number; error: string | null }>;
163
+ export type UsagePage = Readonly<{ data: readonly Readonly<{ cursor: string; turn_id: string; created_at: number; type: string; usage: TurnUsage | null }>[]; has_more: boolean }>;
164
+ export type Artifact = Readonly<{ id: string; turn_id: string; path: string; digest: string; size: number; created_at: number }>;
165
+ export type ArtifactPage = Readonly<{ data: readonly Artifact[]; publications: readonly Readonly<{ turn_id: string; state: "ready" | "failed"; error: string | null }>[] }>;
166
+ export type WebhookState = Readonly<{ endpoint: { url: string } | null; deliveries: readonly Readonly<{ id: string; attempt: number; retry_at: number; status: "pending" | "delivered" | "failed" }>[] }>;
167
+
168
+ export type CreateOptions = Options & Readonly<{
169
+ /**
170
+ * Account-scoped creation key: 1–256 printable ASCII characters without spaces.
171
+ * Persist before calling to retry after restart; omission generates a key per invocation.
172
+ * Replay requires compatible retained settings/configuration. Use open() once the ID is known.
173
+ */
174
+ idempotencyKey?: string | undefined;
175
+ configuration?: Configuration;
176
+ definitionId?: string;
177
+ environmentTemplateId?: string;
178
+ /** Complete immutable starting policy. GPT-6 Astra requires at least low reasoning. */
179
+ settings?: CreateSettings | undefined;
180
+ }>;
181
+
182
+ export type CreateAndPromptOptions = CreateOptions & Readonly<{
183
+ /** Required durable identity for both the new session and its first turn. */
184
+ idempotencyKey: string;
185
+ input: PromptInput;
186
+ /** Stops waiting for admission; it does not cancel or delete durable work. */
187
+ signal?: AbortSignal | undefined;
188
+ }>;
189
+
190
+ export type Capabilities = Readonly<{
191
+ durable_turns: true;
192
+ resumable_events: true;
193
+ live_steer: true;
194
+ live_cancel: true;
195
+ workspace: "cloudflare-computer";
196
+ /** Tools can target explicit sandbox and connected-user environments. */
197
+ execution_environments: true;
198
+ /** Canonical commands select an execution hand from the root of their logical cwd. */
199
+ execution_namespace: "cwd-root-v1";
200
+ /** Native processes cannot yet access peer mounts through filesystem syscalls. */
201
+ native_cross_mounts: false;
202
+ }>;
203
+
204
+ export type State = Readonly<{
205
+ agent_id: string;
206
+ session_id: string;
207
+ has_snapshot: boolean;
208
+ completed_turns: number;
209
+ accepted_turns: number;
210
+ last_active: number;
211
+ active_turns: readonly string[];
212
+ agent_loaded: boolean;
213
+ connected_clients: number;
214
+ capabilities: Capabilities;
215
+ latest_event_cursor: string;
216
+ stream_error: string | null;
217
+ settings: Readonly<{
218
+ model: Model;
219
+ thinking: Thinking;
220
+ reasoning_mode: ReasoningMode;
221
+ fast_mode: boolean;
222
+ }>;
223
+ }>;
224
+
225
+ export type Summary = Readonly<{
226
+ title: string;
227
+ createdAt: number;
228
+ updatedAt: number;
229
+ turnCount: number;
230
+ }>;
231
+
232
+ export type TurnState =
233
+ | "accepted"
234
+ | "cancelling"
235
+ | "completed"
236
+ | "cancelled"
237
+ | "failed";
238
+
239
+ export type TurnView = Readonly<{
240
+ turn_id: string;
241
+ state: TurnState;
242
+ input: PromptInput;
243
+ accepted_cursor: string;
244
+ terminal_cursor: string | null;
245
+ created_at: number;
246
+ accepted_at: number;
247
+ updated_at: number;
248
+ attempt_count: number;
249
+ retry_at: number | null;
250
+ error?: string | undefined;
251
+ terminal?: TerminalEventData | undefined;
252
+ }>;
253
+
254
+ export type EventData = Readonly<{
255
+ cursor: string;
256
+ created_at: number;
257
+ turn_id: string | null;
258
+ }> & (
259
+ | { type: "agent_created"; agent_id: string; capabilities: Capabilities }
260
+ | { type: "turn_accepted"; id: string; input: PromptInput; replayed: boolean }
261
+ | { type: "turn_cancelling"; id: string; error?: string; retry_at?: number }
262
+ | CompletedEventData
263
+ | { type: "turn_cancelled"; id: string }
264
+ | { type: "turn_retryable"; id: string; error: string }
265
+ | { type: "turn_failed"; id: string; error: string }
266
+ | { type: "event"; event: unknown; agent_id?: AgentId | undefined }
267
+ | { type: "stream_failed"; error: string }
268
+ );
269
+
270
+ export type CompletedEventData = Readonly<{
271
+ type: "turn_completed";
272
+ id: string;
273
+ final_message: string;
274
+ usage: TurnUsage | null;
275
+ citations: readonly HistoryCitation[];
276
+ usage_error?: string | undefined;
277
+ }>;
278
+
279
+ export type TerminalEventData =
280
+ | CompletedEventData
281
+ | Readonly<{ type: "turn_cancelled"; id: string }>
282
+ | Readonly<{ type: "turn_failed"; id: string; error: string }>;
283
+
284
+ export type Event = Readonly<{
285
+ cursor: string;
286
+ createdAt: number | undefined;
287
+ turnId: string | null;
288
+ type: EventData["type"] | string;
289
+ data: EventData;
290
+ }>;
291
+
292
+ export type WatchEventsOptions = Readonly<{
293
+ /** Resume after a durable decimal cursor, or tail atomically from `"latest"`. Defaults to `"0"`. */
294
+ cursor?: string | "latest" | undefined;
295
+ signal?: AbortSignal | undefined;
296
+ }>;
297
+
298
+ export type EventHistoryOptions = Readonly<({
299
+ /** Fetch events strictly before this durable cursor. Omit both boundaries for the newest page. */
300
+ before?: string | undefined;
301
+ after?: never;
302
+ } | {
303
+ /** Fetch events strictly after this durable cursor, including `"0"` for the beginning. */
304
+ after?: string | undefined;
305
+ before?: never;
306
+ }) & {
307
+ /** Page size from 1 through 256. Defaults to 128. */
308
+ limit?: number | undefined;
309
+ signal?: AbortSignal | undefined;
310
+ }>;
311
+
312
+ export type EventHistoryPage = Readonly<{
313
+ /** Events are always in ascending cursor order, for either page direction. */
314
+ data: readonly Event[];
315
+ /** More events remain in the requested direction (older by default). */
316
+ hasMore: boolean;
317
+ /** Durable head captured with the page. Forward paging must reach it before switching to a watcher. */
318
+ latestCursor: string;
319
+ }>;
320
+
321
+ export type PromptOptions = Readonly<{
322
+ input: PromptInput;
323
+ /** Stable request key. A random key is generated when omitted. */
324
+ idempotencyKey?: string | undefined;
325
+ /** Optional stable turn identifier. */
326
+ id?: string | undefined;
327
+ signal?: AbortSignal | undefined;
328
+ }>;
329
+
330
+ export type TurnResult = Readonly<{
331
+ turnId: string;
332
+ finalMessage: string;
333
+ usage: TurnUsage | null;
334
+ citations: readonly HistoryCitation[];
335
+ usageError?: string | undefined;
336
+ cursor?: string | undefined;
337
+ }>;
338
+
339
+ export type TurnResultOptions = Readonly<{
340
+ /** Cancels only this result observer; it never cancels the durable server turn. */
341
+ signal?: AbortSignal | undefined;
342
+ }>;
343
+
344
+ export type Turn = Readonly<{
345
+ idempotencyKey: string;
346
+ accepted(): Promise<string>;
347
+ state(): Promise<TurnView>;
348
+ withdrawSteer(options: Readonly<{ messageId: string }>): Promise<Readonly<{ turn_id: string; message_id: string; withdrawn: boolean }>>;
349
+ steer(options: Readonly<{ input: PromptInput; messageId?: string }>): Promise<Readonly<{ turn_id: string; state: "steering" }>>;
350
+ /** With a caller-supplied prompt ID, cancellation does not wait for the prompt response. */
351
+ cancel(): Promise<TurnView | Readonly<{ turn_id: string; state: "cancelling" }>>;
352
+ result(options?: TurnResultOptions): Promise<TurnResult>;
353
+ }>;
354
+
355
+ export type CreateAndPromptResult = Readonly<{
356
+ agent: Agent;
357
+ turn: Turn;
358
+ }>;
359
+
360
+ export type CronTriggerConfig = Readonly<{
361
+ /** A fresh session per occurrence (default on create), or continue this conversation. Omit on update to retain the mode. */
362
+ session_mode?: "new" | "continue" | undefined;
363
+ /** Five-field cron expression, with minute precision. */
364
+ cron: string;
365
+ /** IANA time zone. Defaults to UTC. */
366
+ timezone?: string | undefined;
367
+ /** Text prompt submitted for each occurrence, at most 64 KiB. */
368
+ input: string;
369
+ /** Defaults to true; false pauses future occurrences. */
370
+ enabled?: boolean | undefined;
371
+ }>;
372
+
373
+ export type CronTrigger = Readonly<{
374
+ id: string;
375
+ session_mode: "new" | "continue";
376
+ /** Session containing last_turn_id; null before a run or on legacy servers. */
377
+ last_agent_id: string | null;
378
+ cron: string;
379
+ timezone: string;
380
+ input: string;
381
+ enabled: boolean;
382
+ /** Unix milliseconds; null while paused. */
383
+ next_run_at: number | null;
384
+ /** Scheduled time of the last accepted occurrence, in Unix milliseconds. */
385
+ last_run_at: number | null;
386
+ last_turn_id: string | null;
387
+ last_skipped_at: number | null;
388
+ created_at: number;
389
+ updated_at: number;
390
+ }>;
391
+
392
+ export type Agent = Readonly<{
393
+ requiredActions: Readonly<{
394
+ list(): Promise<{ data: readonly Readonly<{ call_id: string; session_id: string; source_call_id: string; name: string; input: unknown; deadline_at: number }>[] }>;
395
+ submit(callId: string, outcome: import("nanocodex-tools/hosted").HostedToolCallOutcome): Promise<void>;
396
+ }>;
397
+
398
+ configuration(): Promise<Configuration>;
399
+ environment(): Promise<EnvironmentState>;
400
+ usage(options?: { after?: string }): Promise<UsagePage>;
401
+ requests(options?: { after?: string; agentId?: string }): Promise<{ data: readonly Readonly<{ id: string; cursor: string; agent_id: string; turn_id: string | null; type: string; created_at: number; payload: Record<string, unknown> }>[]; has_more: boolean }>;
402
+ webhook: Readonly<{ get(): Promise<WebhookState>; create(url: string): Promise<{ url: string; secret: string }>; delete(): Promise<void> }>;
403
+ artifacts: Readonly<{ list(options?: { turnId?: string }): Promise<ArtifactPage>; download(id: string): Promise<ArrayBuffer> }>;
404
+
405
+ type: "managed";
406
+ id: string;
407
+ /** Account-owned list metadata, present on handles returned by `list()`. */
408
+ summary?: Summary | undefined;
409
+ turn: Readonly<{ prompt(options: PromptOptions): Turn }>;
410
+ settings: Readonly<{
411
+ read(): Promise<CreateSettings>;
412
+ update(patch: SettingsPatch): Promise<CreateSettings>;
413
+ }>;
414
+ triggers: Readonly<{
415
+ list(): Promise<readonly CronTrigger[]>;
416
+ get(id: string): Promise<CronTrigger>;
417
+ /** Create or replace an account-owned schedule using a stable id. */
418
+ put(id: string, config: CronTriggerConfig): Promise<CronTrigger>;
419
+ delete(id: string): Promise<void>;
420
+ }>;
421
+ /** Reverse-tool endpoint with cookie/bearer transport retained in a private closure. */
422
+ toolsTarget(): import("../tools/Tools.mjs").AttachmentTarget;
423
+ events: Readonly<{
424
+ page(options?: EventHistoryOptions): Promise<EventHistoryPage>;
425
+ /**
426
+ * Each iterator has a private 4,096-event/32-MiB buffer. A lagging iterator
427
+ * fails with an actionable resume cursor instead of dropping durable events.
428
+ */
429
+ watch(options?: WatchEventsOptions): AsyncIterableIterator<Event>;
430
+ }>;
431
+ state(): Promise<State>;
432
+ delete(): Promise<void>;
433
+ }>;
434
+
435
+ export function create(options?: CreateOptions): Promise<Agent>;
436
+ /** Create a session and admit its first turn with one durable client mutation. */
437
+ export function createAndPrompt(options: CreateAndPromptOptions): Promise<CreateAndPromptResult>;
438
+ export function list(options?: Options): Promise<readonly Agent[]>;
439
+ export function get(id: string, options?: Options): Promise<Agent>;
440
+ /** Open a handle immediately; each subsequent operation verifies ownership server-side. */
441
+ export function open(id: string, options?: Options): Agent;
442
+ export function remove(id: string, options?: Options): Promise<void>;
443
+ export { remove as delete };
444
+ export function findSessions(request: FindSessionsRequest, options?: Options): Promise<FindSessionsResponse>;
445
+ export function readSession(request: ReadSessionRequest, options?: Options): Promise<ReadSessionResponse>;
446
+ /** List the authenticated account's hosted durable memory. */
447
+ export function listMemories(options?: Options): Promise<readonly MemoryRecord[]>;
448
+ /** Compare-and-swap delete one hosted durable memory; deleting an absent id is idempotent. */
449
+ export function deleteMemory(key: MemoryKey, options?: Options): Promise<void>;
450
+ export function memory(operation: MemoryScanOperation, options?: Options): Promise<MemoryScanResult>;
451
+ export function memory(operation: MemoryReadOperation, options?: Options): Promise<MemoryReadResult>;
452
+ export function memory(operation: MemoryPutOperation, options?: Options): Promise<MemoryPutResult>;
453
+ export function memory(operation: MemoryDeleteOperation, options?: Options): Promise<MemoryDeleteResult>;
454
+ export function memory(operation: MemoryOperation, options?: Options): Promise<MemoryResult>;
455
+ export function getOrganization(options?: Options): Promise<Organization>;
456
+ export function updateOrganization(request: OrganizationUpdate, options?: Options): Promise<Organization>;
457
+
458
+ /** Verifies HMAC and a five-minute timestamp window. Persist the returned ID to deduplicate deliveries. Consumes the request body. */
459
+ export function verifyWebhook(request: Request, secret: string): Promise<Readonly<{ id: string; type: string; agent_id: string; turn_id: string | null; cursor: string; created_at: number }>>;