@aimo-supa-agent/node 0.0.0-stage → 0.1.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 (84) hide show
  1. package/README.md +7 -2
  2. package/dist/agent.d.ts +91 -0
  3. package/dist/agent.js +1421 -0
  4. package/dist/agent.js.map +1 -0
  5. package/dist/api.d.ts +31 -0
  6. package/dist/api.js +86 -0
  7. package/dist/api.js.map +1 -0
  8. package/dist/budget-guard.d.ts +23 -0
  9. package/dist/budget-guard.js +67 -0
  10. package/dist/budget-guard.js.map +1 -0
  11. package/dist/cli.d.ts +2 -0
  12. package/dist/cli.js +99 -0
  13. package/dist/cli.js.map +1 -0
  14. package/dist/config.d.ts +40 -0
  15. package/dist/config.js +69 -0
  16. package/dist/config.js.map +1 -0
  17. package/dist/coordinator.d.ts +25 -0
  18. package/dist/coordinator.js +262 -0
  19. package/dist/coordinator.js.map +1 -0
  20. package/dist/fake-runtime.d.ts +8 -0
  21. package/dist/fake-runtime.js +21 -0
  22. package/dist/fake-runtime.js.map +1 -0
  23. package/dist/memory-cache.d.ts +28 -0
  24. package/dist/memory-cache.js +61 -0
  25. package/dist/memory-cache.js.map +1 -0
  26. package/dist/network.d.ts +21 -0
  27. package/dist/network.js +101 -0
  28. package/dist/network.js.map +1 -0
  29. package/dist/startup.d.ts +24 -0
  30. package/dist/startup.js +52 -0
  31. package/dist/startup.js.map +1 -0
  32. package/dist/store.d.ts +51 -0
  33. package/dist/store.js +160 -0
  34. package/dist/store.js.map +1 -0
  35. package/node_modules/@super-agent/protocol/dist/index.d.ts +495 -0
  36. package/node_modules/@super-agent/protocol/dist/index.js +81 -0
  37. package/node_modules/@super-agent/protocol/dist/index.js.map +1 -0
  38. package/node_modules/@super-agent/protocol/dist/interaction.d.ts +185 -0
  39. package/node_modules/@super-agent/protocol/dist/interaction.js +206 -0
  40. package/node_modules/@super-agent/protocol/dist/interaction.js.map +1 -0
  41. package/node_modules/@super-agent/protocol/dist/invariants.d.ts +23 -0
  42. package/node_modules/@super-agent/protocol/dist/invariants.js +58 -0
  43. package/node_modules/@super-agent/protocol/dist/invariants.js.map +1 -0
  44. package/node_modules/@super-agent/protocol/package.json +16 -0
  45. package/node_modules/@super-agent/runtime-codex/dist/index.d.ts +49 -0
  46. package/node_modules/@super-agent/runtime-codex/dist/index.js +237 -0
  47. package/node_modules/@super-agent/runtime-codex/dist/index.js.map +1 -0
  48. package/node_modules/@super-agent/runtime-codex/dist/managed.d.ts +9 -0
  49. package/node_modules/@super-agent/runtime-codex/dist/managed.js +82 -0
  50. package/node_modules/@super-agent/runtime-codex/dist/managed.js.map +1 -0
  51. package/node_modules/@super-agent/runtime-codex/package.json +16 -0
  52. package/node_modules/@super-agent/runtime-grok/dist/acp.d.ts +30 -0
  53. package/node_modules/@super-agent/runtime-grok/dist/acp.js +100 -0
  54. package/node_modules/@super-agent/runtime-grok/dist/acp.js.map +1 -0
  55. package/node_modules/@super-agent/runtime-grok/dist/cli.d.ts +33 -0
  56. package/node_modules/@super-agent/runtime-grok/dist/cli.js +163 -0
  57. package/node_modules/@super-agent/runtime-grok/dist/cli.js.map +1 -0
  58. package/node_modules/@super-agent/runtime-grok/dist/index.d.ts +22 -0
  59. package/node_modules/@super-agent/runtime-grok/dist/index.js +127 -0
  60. package/node_modules/@super-agent/runtime-grok/dist/index.js.map +1 -0
  61. package/node_modules/@super-agent/runtime-grok/dist/managed.d.ts +48 -0
  62. package/node_modules/@super-agent/runtime-grok/dist/managed.js +47 -0
  63. package/node_modules/@super-agent/runtime-grok/dist/managed.js.map +1 -0
  64. package/node_modules/@super-agent/runtime-grok/package.json +16 -0
  65. package/node_modules/@super-agent/tool-broker/dist/artifacts.d.ts +20 -0
  66. package/node_modules/@super-agent/tool-broker/dist/artifacts.js +187 -0
  67. package/node_modules/@super-agent/tool-broker/dist/artifacts.js.map +1 -0
  68. package/node_modules/@super-agent/tool-broker/dist/browser.d.ts +45 -0
  69. package/node_modules/@super-agent/tool-broker/dist/browser.js +245 -0
  70. package/node_modules/@super-agent/tool-broker/dist/browser.js.map +1 -0
  71. package/node_modules/@super-agent/tool-broker/dist/evidence.d.ts +60 -0
  72. package/node_modules/@super-agent/tool-broker/dist/evidence.js +172 -0
  73. package/node_modules/@super-agent/tool-broker/dist/evidence.js.map +1 -0
  74. package/node_modules/@super-agent/tool-broker/dist/index.d.ts +62 -0
  75. package/node_modules/@super-agent/tool-broker/dist/index.js +402 -0
  76. package/node_modules/@super-agent/tool-broker/dist/index.js.map +1 -0
  77. package/node_modules/@super-agent/tool-broker/dist/mcp.d.ts +2 -0
  78. package/node_modules/@super-agent/tool-broker/dist/mcp.js +48 -0
  79. package/node_modules/@super-agent/tool-broker/dist/mcp.js.map +1 -0
  80. package/node_modules/@super-agent/tool-broker/dist/runtime.d.ts +75 -0
  81. package/node_modules/@super-agent/tool-broker/dist/runtime.js +16 -0
  82. package/node_modules/@super-agent/tool-broker/dist/runtime.js.map +1 -0
  83. package/node_modules/@super-agent/tool-broker/package.json +18 -0
  84. package/package.json +30 -4
@@ -0,0 +1,495 @@
1
+ import type { MessageProcessingPhase, MessageProcessingStatus } from './interaction.js';
2
+ export declare const PROTOCOL_VERSION: "1.0";
3
+ export declare const ENGINES: readonly ["codex", "grok"];
4
+ export type Engine = typeof ENGINES[number];
5
+ export type TaskStatus = 'queued' | 'blocked' | 'running' | 'waiting_input' | 'waiting_device' | 'awaiting_approval' | 'pausing' | 'paused' | 'switching' | 'awaiting_review' | 'succeeded' | 'failed' | 'cancelled';
6
+ export type RunState = 'created' | 'dispatched' | 'starting' | 'running' | 'waiting_input' | 'stopping' | 'paused' | 'succeeded' | 'failed' | 'cancelled' | 'lost' | 'result_unknown';
7
+ export interface ListResponse<T> {
8
+ items: T[];
9
+ next_cursor?: string | null;
10
+ }
11
+ export interface User {
12
+ id: string;
13
+ email: string;
14
+ name: string;
15
+ tenant_id: string;
16
+ }
17
+ export interface AuthSession {
18
+ access_token: string;
19
+ refresh_token: string;
20
+ expires_in: number;
21
+ user: User;
22
+ }
23
+ export interface EngineCapability {
24
+ engine: Engine;
25
+ ready: boolean;
26
+ models: string[];
27
+ local_profile_id?: string;
28
+ reason?: string;
29
+ vision?: 'unsupported' | 'available';
30
+ vision_reason?: string;
31
+ }
32
+ export interface Capabilities {
33
+ generation: number;
34
+ engines: EngineCapability[];
35
+ tools: string[];
36
+ slots: {
37
+ browser: number;
38
+ worker: number;
39
+ };
40
+ }
41
+ export interface Device {
42
+ id: string;
43
+ name: string;
44
+ status: 'online' | 'offline' | 'busy';
45
+ last_seen_at: string | null;
46
+ capabilities: Capabilities;
47
+ version: number;
48
+ revoked?: boolean;
49
+ }
50
+ export interface ExecutionSettings {
51
+ default_engine: Engine;
52
+ default_device_id: string | null;
53
+ assistant_device_id: string | null;
54
+ memory_global_read?: boolean;
55
+ version: number;
56
+ }
57
+ export interface MemoryBinding {
58
+ provider: 'agent-recall';
59
+ configured: boolean;
60
+ url: string | null;
61
+ project: string | null;
62
+ account: {
63
+ id: string;
64
+ email: string | null;
65
+ } | null;
66
+ version: number;
67
+ }
68
+ export interface Task {
69
+ id: string;
70
+ title: string;
71
+ goal: string;
72
+ status: TaskStatus;
73
+ reason_code: string | null;
74
+ engine: Engine;
75
+ model_id: string | null;
76
+ device_id: string | null;
77
+ device_name?: string | null;
78
+ current_run_id: string | null;
79
+ created_at: string;
80
+ updated_at: string;
81
+ version: number;
82
+ parent_task_id?: string | null;
83
+ root_task_id?: string | null;
84
+ plan_id?: string | null;
85
+ depends_on_task_ids?: string[];
86
+ deliverables?: string[];
87
+ delivery_status?: DeliveryStatus | null;
88
+ memory_scope?: MemoryScope | null;
89
+ budget?: Partial<RuntimeBudgetLimits> | null;
90
+ }
91
+ export type DeliveryStatus = 'not_submitted' | 'pending' | 'accepted' | 'rejected' | 'needs_input';
92
+ export interface PlanItem {
93
+ item_key: string;
94
+ title: string;
95
+ goal: string;
96
+ deliverables: string[];
97
+ engine: Engine;
98
+ device_id: string;
99
+ model_id?: string;
100
+ depends_on_keys?: string[];
101
+ parent_item_key?: string | null;
102
+ memory_scope?: MemoryScope | null;
103
+ }
104
+ export type EvidenceReference = {
105
+ kind: 'artifact' | 'step' | 'checkpoint';
106
+ id: string;
107
+ };
108
+ export interface DeliveryCheck {
109
+ deliverable_index: number;
110
+ passed: boolean;
111
+ evidence_refs: EvidenceReference[];
112
+ }
113
+ export interface TaskReviewInput {
114
+ run_id: string;
115
+ verdict: 'accept' | 'reject' | 'needs_input';
116
+ summary: string;
117
+ checks: DeliveryCheck[];
118
+ }
119
+ export interface CoordinatorEvent {
120
+ id: string;
121
+ type: 'delivery.submitted' | 'delivery.rejected' | 'task.failed' | 'task.cancelled' | 'task.result_unknown' | 'plan.settled';
122
+ task_id: string | null;
123
+ run_id: string | null;
124
+ plan_id: string | null;
125
+ delivery_id: string | null;
126
+ source_message_id: string | null;
127
+ status: 'pending' | 'completed';
128
+ reason_code: string | null;
129
+ created_at: string;
130
+ version: number;
131
+ }
132
+ export interface TaskDelivery {
133
+ id: string;
134
+ task_id: string;
135
+ run_id: string;
136
+ status: Exclude<DeliveryStatus, 'not_submitted'>;
137
+ deliverables: string[];
138
+ checkpoint_id: string | null;
139
+ artifact_ids: string[];
140
+ created_at: string;
141
+ version: number;
142
+ }
143
+ export interface ArtifactMetadata {
144
+ id: string;
145
+ task_id: string;
146
+ run_id: string | null;
147
+ name: string;
148
+ mime: string;
149
+ size: number;
150
+ status: string;
151
+ created_at: string;
152
+ version?: number;
153
+ integrity?: 'server_snapshot' | 'legacy_unverified';
154
+ finalized_at?: string | null;
155
+ evidence_kind?: 'page_capture' | 'screenshot' | 'memory_retrieval';
156
+ provenance?: 'tool_broker' | null;
157
+ captured_at?: string | null;
158
+ source_url?: string | null;
159
+ fresh?: boolean;
160
+ stale?: boolean;
161
+ }
162
+ export interface TaskReview extends TaskReviewInput {
163
+ id: string;
164
+ task_id: string;
165
+ created_at: string;
166
+ version: number;
167
+ }
168
+ export interface TaskEvidence {
169
+ task: Task;
170
+ run: Run | null;
171
+ delivery: TaskDelivery | null;
172
+ deliverables: string[];
173
+ result_text: string | null;
174
+ checkpoint: {
175
+ id: string;
176
+ created_at: string;
177
+ } | null;
178
+ evidence_error?: 'artifact_delivery_unavailable' | 'artifact_missing' | null;
179
+ steps: ToolStep[];
180
+ artifacts: ArtifactMetadata[];
181
+ reviews: TaskReview[];
182
+ }
183
+ export interface Run {
184
+ id: string;
185
+ task_id: string;
186
+ state: RunState;
187
+ engine: Engine;
188
+ device_id: string;
189
+ model_id: string;
190
+ lease_epoch: string;
191
+ summary: string;
192
+ result_text?: string | null;
193
+ created_at: string;
194
+ }
195
+ export type ToolStepStatus = 'running' | 'succeeded' | 'failed' | 'cancelled' | 'result_unknown';
196
+ export type ToolStepError = 'tool_failed' | 'invalid_arguments' | 'not_authorized' | 'cancelled' | 'result_unknown';
197
+ /** Safe lifecycle metadata only. Tool arguments, outputs, URLs and arbitrary error text never belong here. */
198
+ export interface ToolStepUpdate {
199
+ step_id: string;
200
+ tool: string;
201
+ status: ToolStepStatus;
202
+ started_at: string;
203
+ completed_at: string | null;
204
+ error_code: ToolStepError | null;
205
+ }
206
+ export interface ToolStep extends Omit<ToolStepUpdate, 'step_id'> {
207
+ id: string;
208
+ run_id: string;
209
+ title: string;
210
+ created_at: string;
211
+ version: number;
212
+ }
213
+ export interface Message {
214
+ id: string;
215
+ role: 'user' | 'assistant' | 'system';
216
+ content: string;
217
+ task_id: string | null;
218
+ created_at: string;
219
+ memory_scope?: MemoryScope | null;
220
+ schedule_id?: string | null;
221
+ client_message_id?: string | null;
222
+ source_message_id?: string | null;
223
+ processing_status?: MessageProcessingStatus | null;
224
+ processing_phase?: MessageProcessingPhase | null;
225
+ reason_code?: string | null;
226
+ action_id?: string | null;
227
+ }
228
+ export type ObservationSource = 'task_result' | 'page';
229
+ export interface ObservationSuggestion {
230
+ id: string;
231
+ status: 'pending' | 'confirmed' | 'dismissed';
232
+ goal: string;
233
+ reason: string;
234
+ fingerprint: string;
235
+ task_id?: string | null;
236
+ created_at: string;
237
+ }
238
+ export interface ObservationRule {
239
+ id: string;
240
+ kind: 'observation';
241
+ title: string;
242
+ enabled: boolean;
243
+ device_id: string;
244
+ engine: Engine;
245
+ project: string | null;
246
+ sites: string[];
247
+ source: ObservationSource;
248
+ goal: string;
249
+ cooldown_minutes: number;
250
+ task_id?: string | null;
251
+ match?: 'status' | 'delivery' | 'reason' | null;
252
+ value?: string | null;
253
+ url?: string | null;
254
+ condition?: string | null;
255
+ next_eligible_at: string;
256
+ last_status: string;
257
+ last_fingerprint: string | null;
258
+ consecutive_failures: number;
259
+ suggestions: ObservationSuggestion[];
260
+ version: number;
261
+ }
262
+ export interface TakeoverCheck {
263
+ name: 'authority' | 'reconciliation' | 'engine' | 'browser' | 'site_login' | 'artifacts';
264
+ status: 'pass' | 'fail' | 'unknown';
265
+ detail: string;
266
+ }
267
+ export type MemoryProvenance = 'user_statement' | 'tool_observation' | 'model_inference';
268
+ export interface Question {
269
+ id: string;
270
+ task_id: string;
271
+ run_id: string;
272
+ text: string;
273
+ options: string[];
274
+ status: 'open' | 'answered' | 'cancelled';
275
+ version: number;
276
+ created_at: string;
277
+ }
278
+ export type MemoryType = 'preference' | 'website' | 'procedure' | 'project' | 'experience';
279
+ export type MemoryStatus = 'candidate' | 'verified' | 'stale' | 'expired' | 'superseded';
280
+ export type MemoryRole = 'user' | 'planner' | 'worker';
281
+ export interface MemoryAccess {
282
+ role: MemoryRole;
283
+ project: string | null;
284
+ sites: string[];
285
+ global_preference: boolean;
286
+ statuses: MemoryStatus[];
287
+ max_version: number | null;
288
+ }
289
+ export interface Memory {
290
+ id: string;
291
+ title: string;
292
+ content: string | null;
293
+ type: MemoryType;
294
+ site: string | null;
295
+ status: MemoryStatus;
296
+ version: number;
297
+ updated_at: string;
298
+ fresh?: boolean;
299
+ stale?: boolean;
300
+ stale_reason?: string | null;
301
+ }
302
+ export type CostSource = 'supplier_reported' | 'estimated' | 'unavailable';
303
+ export { canTransitionRun, canStartReplacement, moneyToTicks, ticksToMoney, summarizeCosts } from './invariants.js';
304
+ export interface CostTotal {
305
+ currency: string;
306
+ amount: string;
307
+ source: CostSource;
308
+ }
309
+ export interface CostSummary {
310
+ totals: CostTotal[];
311
+ input_tokens: number;
312
+ output_tokens: number;
313
+ unknown_count: number;
314
+ request_count: number;
315
+ coverage: number;
316
+ as_of: string;
317
+ reserved_hold_usd?: string | null;
318
+ reserved_unknown_count?: number;
319
+ }
320
+ export interface CostPoint {
321
+ date: string;
322
+ currency: string;
323
+ amount: string;
324
+ source: CostSource;
325
+ input_tokens: number;
326
+ output_tokens: number;
327
+ }
328
+ export interface CostBreakdown {
329
+ key: string;
330
+ label: string;
331
+ currency: string;
332
+ amount: string;
333
+ request_count: number;
334
+ unknown_count: number;
335
+ }
336
+ export interface Budget {
337
+ monthly_limit_usd: string | null;
338
+ task_limit_usd: string | null;
339
+ used_usd: string;
340
+ version: number;
341
+ unknown_count?: number;
342
+ category_limits?: Partial<Record<BudgetCategory, Partial<RuntimeBudgetLimits>>>;
343
+ reserved_hold_usd?: string | null;
344
+ reserved_unknown_count?: number;
345
+ }
346
+ export type BudgetCategory = 'worker' | 'assistant' | 'review' | 'proactive';
347
+ export type ActivityKind = 'run' | 'assistant' | 'review' | 'proactive';
348
+ /** Prefix of the single activity id shared by reserve, heartbeat, usage, release, and settlement. */
349
+ export declare const ACTIVITY_ID_PREFIXES: readonly ["run", "assistant", "review", "proactive", "event"];
350
+ export type ActivityIdPrefix = typeof ACTIVITY_ID_PREFIXES[number];
351
+ /**
352
+ * Canonical activity id. Worker runs use `run:<runId>`. Chat planning uses `assistant:<messageId>`.
353
+ * Scheduled planning uses `proactive:<messageId>`. Delivery review uses `review:<deliveryId>`.
354
+ * Event coordination uses `event:<eventId>` and activity_kind `assistant`.
355
+ * Callers must not link a cost by bare id, run id, or “the first reservation on this run”.
356
+ */
357
+ export declare function canonicalActivityId(prefix: ActivityIdPrefix, rawId: string): string;
358
+ /** Attempt ids are `${root}#N`. The root stays stable; N is the execution attempt. */
359
+ export declare function activityRootId(activityId: string): string;
360
+ /** One page-observation command has one budget activity. The fingerprint is not the activity id. */
361
+ export declare function observationActivityId(commandId: string): string;
362
+ /** A heartbeat older than this does not keep an already-expired hold in force. */
363
+ export declare const BUDGET_HEARTBEAT_MS = 45000;
364
+ export type BudgetWriteMode = 'merge' | 'replace';
365
+ export declare const BUDGET_LIMIT_KEYS: readonly ["max_total_tokens", "max_model_calls", "max_tool_steps", "max_runtime_ms"];
366
+ export type BudgetLimitKey = typeof BUDGET_LIMIT_KEYS[number];
367
+ export type BudgetStopReason = 'token_limit' | 'time_limit' | 'model_call_limit' | 'tool_step_limit' | 'budget_exhausted' | 'budget_unknown';
368
+ /** Observable run limits. These are not a provider-enforced dollar ceiling. */
369
+ export interface RuntimeBudgetLimits {
370
+ max_total_tokens: number;
371
+ max_model_calls: number;
372
+ max_tool_steps: number;
373
+ max_runtime_ms: number;
374
+ }
375
+ export declare const DEFAULT_BUDGET_LIMITS: Record<BudgetCategory, RuntimeBudgetLimits>;
376
+ /** Explicit configuration may raise a category above its default, but not without a bound. */
377
+ export declare const BUDGET_LIMIT_CEILING: RuntimeBudgetLimits;
378
+ export declare const BUDGET_IN_FLIGHT_BOUNDARY = "\u505C\u6B62\u53EA\u963B\u65AD\u4E0B\u4E00\u6B21\u53D7\u7BA1\u6A21\u578B\u8C03\u7528\u548C\u5DE5\u5177\u6B65\u9AA4\u3002\u5DF2\u7ECF\u53D1\u51FA\u7684 Grok \u8BF7\u6C42\uFF0C\u4EE5\u53CA Codex \u5F53\u524D\u5185\u90E8\u56DE\u5408\uFF0C\u4ECD\u53EF\u80FD\u5B8C\u6210\u5E76\u8BB0\u5165\u7528\u91CF\u3002\u672A\u77E5\u91D1\u989D\u4E0D\u6309 0 \u7F8E\u5143\u8BA1\u7B97\uFF0C\u4E5F\u4E0D\u6784\u6210\u4F9B\u5E94\u5546\u8D26\u6237\u786C\u989D\u5EA6\u3002";
379
+ export declare const BUDGET_RECOVERY: Record<BudgetStopReason, string>;
380
+ export interface MemoryScope {
381
+ project: string | null;
382
+ sites: string[];
383
+ global_preference: boolean;
384
+ statuses: string[];
385
+ max_version: number | null;
386
+ }
387
+ /**
388
+ * `requested` is inside `ceiling` when it cannot read anything the ceiling forbids.
389
+ * A null project ceiling allows a narrower project. A null max_version ceiling allows a lower cap.
390
+ * Empty sites and global_preference false are closed, not wildcards.
391
+ */
392
+ export declare function memoryScopeWithin(requested: MemoryScope, ceiling: MemoryScope): boolean;
393
+ export interface BudgetGrant {
394
+ grant_id: string;
395
+ category: BudgetCategory;
396
+ limits: RuntimeBudgetLimits | null;
397
+ ceiling?: RuntimeBudgetLimits;
398
+ money_treatment: 'known' | 'unknown_not_zero' | 'unconfigured';
399
+ in_flight_boundary: string;
400
+ dollar_cap: 'not_enforced';
401
+ status?: string;
402
+ expires_at?: string;
403
+ activity_kind?: ActivityKind;
404
+ activity_id?: string;
405
+ task_id?: string | null;
406
+ run_id?: string | null;
407
+ device_id?: string | null;
408
+ executable?: boolean;
409
+ prior_activity_id?: string | null;
410
+ attempt?: number;
411
+ stop_reason?: BudgetStopReason | null;
412
+ recovery?: string;
413
+ }
414
+ /** A stored grant may be reread after it ends. Only a reserved, unexpired grant for this activity and device may start work. */
415
+ export declare function grantExecutable(grant: Pick<BudgetGrant, 'status' | 'expires_at' | 'limits' | 'activity_id' | 'device_id'>, expected: {
416
+ activityId: string;
417
+ deviceId?: string | null;
418
+ now?: number;
419
+ }): boolean;
420
+ export interface Frame {
421
+ frame_id: string;
422
+ image_base64: string;
423
+ width: number;
424
+ height: number;
425
+ captured_at: string;
426
+ viewport_version: string;
427
+ tab_id: string | null;
428
+ }
429
+ export interface ApiError {
430
+ error: {
431
+ code: string;
432
+ message: string;
433
+ retryable: boolean;
434
+ request_id?: string;
435
+ };
436
+ }
437
+ export interface ServerEvent {
438
+ event_id: string;
439
+ stream_seq: string;
440
+ type: string;
441
+ occurred_at: string;
442
+ task_id?: string | null;
443
+ run_id?: string | null;
444
+ entity_version?: number;
445
+ payload: Record<string, unknown>;
446
+ }
447
+ export interface RuntimeSelection {
448
+ engine: Engine;
449
+ model_id: string;
450
+ local_profile_id: string;
451
+ }
452
+ export interface RunStartPayload {
453
+ command_id: string;
454
+ tenant_id: string;
455
+ task_id: string;
456
+ run_id: string;
457
+ device_id: string;
458
+ lease_epoch: string;
459
+ scope_version_id: string;
460
+ capability_generation: number;
461
+ runtime: RuntimeSelection;
462
+ expires_at: string;
463
+ lease_valid_for_ms: number;
464
+ checkpoint_id: string | null;
465
+ budget_grant_id: string;
466
+ }
467
+ export interface WireMessage<T = Record<string, unknown>> {
468
+ protocol_version: '1.0';
469
+ message_id: string;
470
+ kind: string;
471
+ sent_at: string;
472
+ payload: T;
473
+ }
474
+ export interface RunContext {
475
+ run: Run;
476
+ task: Task;
477
+ scope: Record<string, unknown>;
478
+ checkpoint: Record<string, unknown> | null;
479
+ run_ticket: string;
480
+ lease_valid_for_ms: number;
481
+ budget?: BudgetGrant | null;
482
+ }
483
+ export interface PairingStart {
484
+ pairing_id: string;
485
+ code: string;
486
+ polling_secret: string;
487
+ expires_at: string;
488
+ }
489
+ export interface PairingResult {
490
+ status: 'pending' | 'claimed';
491
+ device_id?: string;
492
+ tenant_id?: string;
493
+ }
494
+ export declare const TERMINAL_RUN_STATES: Set<RunState>;
495
+ export * from './interaction.js';
@@ -0,0 +1,81 @@
1
+ export const PROTOCOL_VERSION = '1.0';
2
+ export const ENGINES = ['codex', 'grok'];
3
+ export { canTransitionRun, canStartReplacement, moneyToTicks, ticksToMoney, summarizeCosts } from './invariants.js';
4
+ /** Prefix of the single activity id shared by reserve, heartbeat, usage, release, and settlement. */
5
+ export const ACTIVITY_ID_PREFIXES = ['run', 'assistant', 'review', 'proactive', 'event'];
6
+ /**
7
+ * Canonical activity id. Worker runs use `run:<runId>`. Chat planning uses `assistant:<messageId>`.
8
+ * Scheduled planning uses `proactive:<messageId>`. Delivery review uses `review:<deliveryId>`.
9
+ * Event coordination uses `event:<eventId>` and activity_kind `assistant`.
10
+ * Callers must not link a cost by bare id, run id, or “the first reservation on this run”.
11
+ */
12
+ export function canonicalActivityId(prefix, rawId) {
13
+ return `${prefix}:${rawId}`;
14
+ }
15
+ /** Attempt ids are `${root}#N`. The root stays stable; N is the execution attempt. */
16
+ export function activityRootId(activityId) {
17
+ const mark = activityId.lastIndexOf('#');
18
+ if (mark > 0 && /^\d+$/.test(activityId.slice(mark + 1)))
19
+ return activityId.slice(0, mark);
20
+ return activityId;
21
+ }
22
+ /** One page-observation command has one budget activity. The fingerprint is not the activity id. */
23
+ export function observationActivityId(commandId) {
24
+ return canonicalActivityId('proactive', `observation:${commandId}`);
25
+ }
26
+ /** A heartbeat older than this does not keep an already-expired hold in force. */
27
+ export const BUDGET_HEARTBEAT_MS = 45_000;
28
+ export const BUDGET_LIMIT_KEYS = ['max_total_tokens', 'max_model_calls', 'max_tool_steps', 'max_runtime_ms'];
29
+ export const DEFAULT_BUDGET_LIMITS = {
30
+ worker: { max_total_tokens: 200_000, max_model_calls: 40, max_tool_steps: 80, max_runtime_ms: 1_200_000 },
31
+ assistant: { max_total_tokens: 80_000, max_model_calls: 12, max_tool_steps: 40, max_runtime_ms: 600_000 },
32
+ review: { max_total_tokens: 40_000, max_model_calls: 6, max_tool_steps: 12, max_runtime_ms: 180_000 },
33
+ proactive: { max_total_tokens: 40_000, max_model_calls: 4, max_tool_steps: 20, max_runtime_ms: 600_000 },
34
+ };
35
+ /** Explicit configuration may raise a category above its default, but not without a bound. */
36
+ export const BUDGET_LIMIT_CEILING = { max_total_tokens: 5_000_000, max_model_calls: 2_000, max_tool_steps: 5_000, max_runtime_ms: 8 * 60 * 60 * 1000 };
37
+ export const BUDGET_IN_FLIGHT_BOUNDARY = '停止只阻断下一次受管模型调用和工具步骤。已经发出的 Grok 请求,以及 Codex 当前内部回合,仍可能完成并记入用量。未知金额不按 0 美元计算,也不构成供应商账户硬额度。';
38
+ export const BUDGET_RECOVERY = {
39
+ token_limit: '这个任务的 Token 已用到当前上限。提高对应活动的 Token 上限后可以继续。',
40
+ model_call_limit: '这个任务的模型调用次数已用到当前上限。提高上限后可以继续。',
41
+ tool_step_limit: '这个任务的工具步骤已用到当前上限。提高上限后可以继续。',
42
+ time_limit: '这一次活动的运行时间已到上限。提高单次时长后可以再开始一次。',
43
+ budget_exhausted: '金额预算已用完。提高本月或本任务金额上限后,才能开始新的模型调用。',
44
+ budget_unknown: '还有费用没核算清楚,不能按 0 计算。确认费用或调整金额上限前,不会开始新的模型调用。',
45
+ };
46
+ /**
47
+ * `requested` is inside `ceiling` when it cannot read anything the ceiling forbids.
48
+ * A null project ceiling allows a narrower project. A null max_version ceiling allows a lower cap.
49
+ * Empty sites and global_preference false are closed, not wildcards.
50
+ */
51
+ export function memoryScopeWithin(requested, ceiling) {
52
+ if (ceiling.project && requested.project !== ceiling.project)
53
+ return false;
54
+ if (requested.sites.some(site => !ceiling.sites.includes(site)))
55
+ return false;
56
+ if (requested.global_preference && !ceiling.global_preference)
57
+ return false;
58
+ if (requested.statuses.some(status => !ceiling.statuses.includes(status)))
59
+ return false;
60
+ if (ceiling.max_version != null && (requested.max_version == null || requested.max_version > ceiling.max_version))
61
+ return false;
62
+ return true;
63
+ }
64
+ /** A stored grant may be reread after it ends. Only a reserved, unexpired grant for this activity and device may start work. */
65
+ export function grantExecutable(grant, expected) {
66
+ if (!grant.limits)
67
+ return false;
68
+ if (grant.status !== 'reserved')
69
+ return false;
70
+ const now = expected.now ?? Date.now();
71
+ if (!grant.expires_at || !Number.isFinite(Date.parse(grant.expires_at)) || Date.parse(grant.expires_at) <= now)
72
+ return false;
73
+ if (grant.activity_id !== expected.activityId)
74
+ return false;
75
+ if (expected.deviceId && grant.device_id && grant.device_id !== expected.deviceId)
76
+ return false;
77
+ return true;
78
+ }
79
+ export const TERMINAL_RUN_STATES = new Set(['succeeded', 'failed', 'cancelled', 'paused']);
80
+ export * from './interaction.js';
81
+ //# sourceMapp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