@agentropy/runtime 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 (85) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +39 -2
  3. package/dist/a2a-client.d.ts +111 -0
  4. package/dist/a2a-client.js +386 -0
  5. package/dist/a2a-history.d.ts +27 -0
  6. package/dist/a2a-history.js +67 -0
  7. package/dist/a2a-http.d.ts +46 -0
  8. package/dist/a2a-http.js +183 -0
  9. package/dist/a2a-protocol.d.ts +77 -0
  10. package/dist/a2a-protocol.js +148 -0
  11. package/dist/a2a-push-receiver.d.ts +24 -0
  12. package/dist/a2a-push-receiver.js +161 -0
  13. package/dist/a2a-push.d.ts +85 -0
  14. package/dist/a2a-push.js +385 -0
  15. package/dist/a2a-server.d.ts +82 -0
  16. package/dist/a2a-server.js +523 -0
  17. package/dist/a2a-sse.d.ts +5 -0
  18. package/dist/a2a-sse.js +36 -0
  19. package/dist/a2a.d.ts +41 -0
  20. package/dist/a2a.js +40 -0
  21. package/dist/app.d.ts +256 -0
  22. package/dist/app.js +541 -0
  23. package/dist/audit.d.ts +229 -0
  24. package/dist/audit.js +718 -0
  25. package/dist/bounded-body.d.ts +32 -0
  26. package/dist/bounded-body.js +124 -0
  27. package/dist/communication.d.ts +62 -0
  28. package/dist/communication.js +142 -0
  29. package/dist/compaction.d.ts +24 -0
  30. package/dist/compaction.js +202 -0
  31. package/dist/federation.d.ts +108 -0
  32. package/dist/federation.js +241 -0
  33. package/dist/http-path.d.ts +7 -0
  34. package/dist/http-path.js +14 -0
  35. package/dist/human-actions.d.ts +62 -0
  36. package/dist/human-actions.js +359 -0
  37. package/dist/implementation.d.ts +47 -0
  38. package/dist/implementation.js +138 -0
  39. package/dist/inbox.d.ts +101 -0
  40. package/dist/inbox.js +389 -0
  41. package/dist/index.d.ts +32 -0
  42. package/dist/index.js +32 -0
  43. package/dist/ingress.d.ts +35 -0
  44. package/dist/ingress.js +86 -0
  45. package/dist/lifecycle.d.ts +45 -0
  46. package/dist/lifecycle.js +57 -0
  47. package/dist/limits.d.ts +43 -0
  48. package/dist/limits.js +71 -0
  49. package/dist/mcp.d.ts +111 -0
  50. package/dist/mcp.js +308 -0
  51. package/dist/memory.d.ts +25 -0
  52. package/dist/memory.js +134 -0
  53. package/dist/model-routing.d.ts +66 -0
  54. package/dist/model-routing.js +80 -0
  55. package/dist/otel.d.ts +60 -0
  56. package/dist/otel.js +72 -0
  57. package/dist/outbox.d.ts +116 -0
  58. package/dist/outbox.js +327 -0
  59. package/dist/policy-cache.d.ts +69 -0
  60. package/dist/policy-cache.js +178 -0
  61. package/dist/priority.d.ts +27 -0
  62. package/dist/priority.js +28 -0
  63. package/dist/quotas.d.ts +19 -0
  64. package/dist/quotas.js +47 -0
  65. package/dist/reasoning.d.ts +54 -0
  66. package/dist/reasoning.js +307 -0
  67. package/dist/registry.d.ts +101 -0
  68. package/dist/registry.js +369 -0
  69. package/dist/remote.d.ts +130 -0
  70. package/dist/remote.js +473 -0
  71. package/dist/runtime.d.ts +167 -0
  72. package/dist/runtime.js +1035 -0
  73. package/dist/skills.d.ts +86 -0
  74. package/dist/skills.js +376 -0
  75. package/dist/task-service.d.ts +239 -0
  76. package/dist/task-service.js +790 -0
  77. package/dist/tools.d.ts +140 -0
  78. package/dist/tools.js +476 -0
  79. package/dist/wake-index.d.ts +9 -0
  80. package/dist/wake-index.js +11 -0
  81. package/dist/wakeups.d.ts +142 -0
  82. package/dist/wakeups.js +501 -0
  83. package/dist/workflow.d.ts +36 -0
  84. package/dist/workflow.js +101 -0
  85. package/package.json +48 -3
@@ -0,0 +1,239 @@
1
+ import { type AcceptanceEnvironment, type AcceptanceSnapshot, type AgentInvocation, type AuditEvent, type ConversationTurn, type DelegationRequest, type ExecutionRecord, type PolicyDecisionPoint, type RetryPolicy, type Store, type StoreTx, type StoredDocument, type TaskEventType, type Telemetry, type TaskHandle, type TaskSnapshot, type TRANSITION_EVENT_TYPES, type TaskStatus, type TrustedPrincipal, type VersionedRef, type WakeupRequest } from '@agentropy/core';
2
+ import { type QuotaResolver } from './quotas.js';
3
+ import type { FaultHook } from './outbox.js';
4
+ import type { DefinitionRegistry, InstanceDirectory } from './registry.js';
5
+ export interface TaskRecord {
6
+ taskId: string;
7
+ tenantId: string;
8
+ status: TaskStatus;
9
+ instanceId: string;
10
+ ownerId: string;
11
+ callerId: string;
12
+ /** Principal type of the delegating caller (dispatch-time policy checks use it). */
13
+ callerType?: TrustedPrincipal['type'];
14
+ /** Resource budget from the delegation request (cost units = model tokens for `reasoning`). */
15
+ budget?: {
16
+ maxCostUnits?: number;
17
+ maxActivations?: number;
18
+ };
19
+ /** Trace context of the accepting span (W3C traceparent); parent of every execution span of this task. */
20
+ traceparent?: string;
21
+ parentTaskId?: string;
22
+ depth: number;
23
+ definition: VersionedRef;
24
+ input: unknown;
25
+ correlationId: string;
26
+ snapshot: AcceptanceSnapshot;
27
+ retryPolicy: RetryPolicy;
28
+ activation: number;
29
+ attempt: number;
30
+ deadline?: string;
31
+ cancelRequestedAt?: string;
32
+ waitingOn?: WakeupRequest;
33
+ output?: unknown;
34
+ outcome?: {
35
+ code: string;
36
+ message: string;
37
+ };
38
+ createdAt: string;
39
+ updatedAt: string;
40
+ /** The delegating caller's grant; the acting instance works under it and it is re-checked at protected effects. */
41
+ grantRef?: string;
42
+ /** Fencing token of the current lease. */
43
+ leaseEpoch?: number;
44
+ }
45
+ export interface StoredExecution extends ExecutionRecord {
46
+ /** Earliest time the pool may lease it (retry backoff). */
47
+ runAt: string;
48
+ leaseExpiresAt?: string;
49
+ /** Tenant of the task, for fair dispatch and per-tenant concurrency across workers (M3-02). */
50
+ tenantId?: string;
51
+ /** Worker that holds (or last held) the lease. */
52
+ workerId?: string;
53
+ }
54
+ export interface IdempotencyRecord {
55
+ tenantId: string;
56
+ taskId: string;
57
+ fingerprint: string;
58
+ }
59
+ /** Outbox row: one TaskEvent plus delivery bookkeeping (messaging contract, R-29). */
60
+ export interface OutboxRecord {
61
+ eventId: string;
62
+ type: TaskEventType;
63
+ aggregateId: string;
64
+ tenantId: string;
65
+ revision: number;
66
+ sequence: number;
67
+ status: TaskStatus;
68
+ occurredAt: string;
69
+ data?: unknown;
70
+ /** Status and outcome at commit time (kept for consumers that predate TaskEvent). */
71
+ payload: {
72
+ status: TaskStatus;
73
+ outcome?: {
74
+ code: string;
75
+ message: string;
76
+ };
77
+ };
78
+ correlationId: string;
79
+ /** 0 until every relay consumer has accepted it. */
80
+ published: 0 | 1;
81
+ attempts: number;
82
+ lastError?: string;
83
+ /** Given up on after `poisonAfter` failed deliveries: marked published without every consumer having it. */
84
+ poisoned?: boolean;
85
+ }
86
+ /** Users whose inbox shows a human-action request: its named assignees, else the task owner. */
87
+ export declare const actionUsers: (a: {
88
+ assignees: {
89
+ principalIds?: string[];
90
+ };
91
+ }, task: {
92
+ ownerId: string;
93
+ }) => string[];
94
+ /** ADR-0024 activation eligibility gate: scheduler metadata, never a task status (store doc revision = gateRevision). */
95
+ export interface DispatchGate {
96
+ taskId: string;
97
+ /** Task revision observed when the gate was written. */
98
+ taskRevision: number;
99
+ reason: 'policy-indeterminate' | 'policy-denied' | 'authority-expired' | 'authority-revoked';
100
+ /** Present while a bounded PDP retry is scheduled; null when reauthorization (or an operator) is required. */
101
+ nextCheckAt: string | null;
102
+ /** Grant to evaluate at the next check (set by reauthorization); applied to the task at lease time. */
103
+ grantRef?: string;
104
+ lastDecisionAt: string;
105
+ /** Gate evaluations since the last reauthorization (not Execution.attempt). */
106
+ attempt: number;
107
+ }
108
+ export interface GrantVerifier {
109
+ /** Validates a delegated authority reference at a protected boundary (never cached across operations). */
110
+ check(ref: string, tenantId: string): Promise<'valid' | 'expired' | 'revoked'>;
111
+ /**
112
+ * Optional (D-15): derive a grant no wider than `ref`, scoped to one target agent instance, for a child task.
113
+ * Throwing denies the delegation.
114
+ */
115
+ narrow?(ref: string, scope: {
116
+ tenantId: string;
117
+ agentInstanceId: string;
118
+ parentTaskId?: string;
119
+ }): Promise<string>;
120
+ }
121
+ export type IdKind = 'task' | 'execution' | 'event' | 'wakeup' | 'action' | 'entry' | 'audit' | 'invalidation';
122
+ export interface TaskServiceOptions {
123
+ store: Store;
124
+ definitions: DefinitionRegistry;
125
+ instances: InstanceDirectory;
126
+ acceptance: AcceptanceEnvironment;
127
+ pdp: PolicyDecisionPoint;
128
+ grants?: GrantVerifier;
129
+ now: () => string;
130
+ newId?: (kind: IdKind) => string;
131
+ limits?: {
132
+ maxDepth?: number;
133
+ maxFanOut?: number;
134
+ maxInputBytes?: number;
135
+ };
136
+ /** Fault hook for audit-intent and recovery tests; production passes nothing. */
137
+ faults?: FaultHook;
138
+ /** Spans and metrics (observability contract); defaults to no-op. */
139
+ telemetry?: Telemetry;
140
+ /** Per-tenant quotas (M2-11), checked inside the accepting transaction. */
141
+ quotas?: QuotaResolver;
142
+ }
143
+ export declare const DEFAULT_RETRY: RetryPolicy;
144
+ export declare const hashKey: (...parts: string[]) => string;
145
+ export declare function toSnapshot(t: TaskRecord, revision: number): TaskSnapshot;
146
+ export declare class TaskService {
147
+ readonly o: TaskServiceOptions;
148
+ private readonly cancelHooks;
149
+ constructor(o: TaskServiceOptions);
150
+ newId(kind: IdKind): string;
151
+ /** The runtime registers to hear cancel requests for running executions. */
152
+ onCancelRequested(hook: (taskId: string) => void): void;
153
+ get telemetry(): Telemetry;
154
+ /**
155
+ * Accept a task (see `accept`) inside an `agentropy.task.accept` span. `trace.traceparent` is an untrusted
156
+ * correlation hint from ingress or the parent capability span: it is sanitized and never used for authorization.
157
+ */
158
+ delegate<I>(request: DelegationRequest<I>, caller: TrustedPrincipal, trace?: {
159
+ traceparent?: string;
160
+ }): Promise<TaskHandle>;
161
+ private accept;
162
+ /**
163
+ * One user message → one turn task on the caller's own conversational instance (Agent v1 "Conversation
164
+ * turn model"). The turn handler reads `conversation.briefing` and replies; it does not wait for children.
165
+ */
166
+ submitTurn(turn: ConversationTurn, caller: TrustedPrincipal): Promise<TaskHandle>;
167
+ /**
168
+ * Owner visibility (R-13, M2-05): tasks the caller delegated or owns (a trusted service sees its tenant), oldest
169
+ * first, or newest first with `newestFirst` (FIX-062), with an opaque cursor. `cursors[i]` resumes right after
170
+ * `tasks[i]`, so a caller that stops inside the page can continue from the item it stopped at. Other users' and
171
+ * tenants' tasks are never listed.
172
+ */
173
+ listTasks(query: {
174
+ instanceId?: string;
175
+ status?: TaskStatus[];
176
+ cursor?: string;
177
+ limit?: number;
178
+ newestFirst?: boolean;
179
+ }, caller: TrustedPrincipal): Promise<{
180
+ tasks: TaskSnapshot[];
181
+ cursor: string;
182
+ cursors: string[];
183
+ }>;
184
+ getTask(taskId: string, caller: TrustedPrincipal): Promise<TaskSnapshot>;
185
+ getTaskByIdempotencyKey(key: string, caller: TrustedPrincipal): Promise<TaskSnapshot>;
186
+ getResult<O>(taskId: string, caller: TrustedPrincipal): Promise<O>;
187
+ cancel(taskId: string, caller: TrustedPrincipal, reason?: string): Promise<TaskSnapshot>;
188
+ /**
189
+ * The cancel request of a running task: recorded on the task and announced. The worker running it sees the request
190
+ * through the store (its next heartbeat or tick) and stops the handler, and a result that arrives late is fenced.
191
+ */
192
+ private requestCancel;
193
+ /**
194
+ * A parent that was cancelled or failed takes its open children with it (Agent v1 revision 15): a child that is not
195
+ * running is cancelled at once (T10, its own children follow), a running child is asked to stop (the worker acts on
196
+ * it at its next heartbeat), and an open remote projection is marked so the next sync cancels it at the peer. The
197
+ * parent's own cancel was the audited act; this is the runtime carrying it out, like a deadline.
198
+ */
199
+ private endChildren;
200
+ visible(taskId: string, caller: TrustedPrincipal): Promise<StoredDocument<TaskRecord>>;
201
+ checkGrant(caller: TrustedPrincipal): Promise<void>;
202
+ /**
203
+ * D-08 delegation governance: an instance accepts work from its owner, principals the owner shared it with,
204
+ * agents whose own instance has the same owner (or a shared one), and trusted services. Everyone else in the
205
+ * tenant gets NotFound, so instance IDs do not reveal other users' agents. Policy (PDP) still applies after this.
206
+ */
207
+ private checkInstanceAccess;
208
+ /**
209
+ * The visible target instance, and the caller's idempotency record when it could be read in the same
210
+ * transaction (`null` when it was not read).
211
+ */
212
+ private resolveTarget;
213
+ private handleFor;
214
+ /** Mandatory audit intent in the caller's transaction (SEC-03); failure aborts it with AuditCommitUnavailable. */
215
+ audit(tx: StoreTx, principal: {
216
+ id: string;
217
+ tenantId: string;
218
+ }, event: Omit<AuditEvent, 'at' | 'tenantId' | 'principalId'>): Promise<void>;
219
+ /**
220
+ * ADR-0024: a trusted principal re-establishes authority for a task held by the dispatch gate. Nothing is
221
+ * dispatched here; the next scheduler pass re-evaluates the gate with a fresh policy decision and the new grant.
222
+ */
223
+ reauthorize(taskId: string, caller: TrustedPrincipal): Promise<void>;
224
+ /**
225
+ * Append one TaskEvent to the outbox in the caller's transaction. Without `type` it is the transition
226
+ * event for the status the task just entered (sequence 0); otherwise a non-transition event at the
227
+ * current revision with the next sequence number.
228
+ */
229
+ emit(tx: StoreTx, t: TaskRecord, revision: number, type?: Exclude<TaskEventType, (typeof TRANSITION_EVENT_TYPES)[number]>, data?: unknown): Promise<OutboxRecord>;
230
+ transition(tx: StoreTx, cur: StoredDocument<TaskRecord>, to: TaskStatus, edge: string, patch?: Partial<TaskRecord>): Promise<StoredDocument<TaskRecord>>;
231
+ /** Terminal transition: aborts queued/leased executions (E7) and revokes wake-ups and subscriptions. */
232
+ terminate(tx: StoreTx, cur: StoredDocument<TaskRecord>, to: 'failed' | 'cancelled' | 'completed', edge: string, outcome?: {
233
+ code: string;
234
+ message: string;
235
+ }, output?: unknown): Promise<StoredDocument<TaskRecord>>;
236
+ queueExecution(tx: StoreTx, taskId: string, activation: number, attempt: number, trigger: AgentInvocation['trigger'], runAt: string,
237
+ /** The task's tenant when the caller already holds it; otherwise it is read. */
238
+ knownTenantId?: string): Promise<string>;
239
+ }