@agentropy/runtime 0.0.0-bootstrap.0 → 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.
- package/LICENSE +202 -0
- package/README.md +38 -1
- package/dist/a2a-client.d.ts +111 -0
- package/dist/a2a-client.js +386 -0
- package/dist/a2a-history.d.ts +27 -0
- package/dist/a2a-history.js +67 -0
- package/dist/a2a-http.d.ts +46 -0
- package/dist/a2a-http.js +183 -0
- package/dist/a2a-protocol.d.ts +77 -0
- package/dist/a2a-protocol.js +148 -0
- package/dist/a2a-push-receiver.d.ts +24 -0
- package/dist/a2a-push-receiver.js +161 -0
- package/dist/a2a-push.d.ts +85 -0
- package/dist/a2a-push.js +385 -0
- package/dist/a2a-server.d.ts +82 -0
- package/dist/a2a-server.js +523 -0
- package/dist/a2a-sse.d.ts +5 -0
- package/dist/a2a-sse.js +36 -0
- package/dist/a2a.d.ts +41 -0
- package/dist/a2a.js +40 -0
- package/dist/app.d.ts +256 -0
- package/dist/app.js +541 -0
- package/dist/audit.d.ts +229 -0
- package/dist/audit.js +718 -0
- package/dist/bounded-body.d.ts +32 -0
- package/dist/bounded-body.js +124 -0
- package/dist/communication.d.ts +62 -0
- package/dist/communication.js +142 -0
- package/dist/compaction.d.ts +24 -0
- package/dist/compaction.js +202 -0
- package/dist/federation.d.ts +108 -0
- package/dist/federation.js +241 -0
- package/dist/http-path.d.ts +7 -0
- package/dist/http-path.js +14 -0
- package/dist/human-actions.d.ts +62 -0
- package/dist/human-actions.js +359 -0
- package/dist/implementation.d.ts +47 -0
- package/dist/implementation.js +138 -0
- package/dist/inbox.d.ts +101 -0
- package/dist/inbox.js +389 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/ingress.d.ts +35 -0
- package/dist/ingress.js +86 -0
- package/dist/lifecycle.d.ts +45 -0
- package/dist/lifecycle.js +57 -0
- package/dist/limits.d.ts +43 -0
- package/dist/limits.js +71 -0
- package/dist/mcp.d.ts +111 -0
- package/dist/mcp.js +308 -0
- package/dist/memory.d.ts +25 -0
- package/dist/memory.js +134 -0
- package/dist/model-routing.d.ts +66 -0
- package/dist/model-routing.js +80 -0
- package/dist/otel.d.ts +60 -0
- package/dist/otel.js +72 -0
- package/dist/outbox.d.ts +116 -0
- package/dist/outbox.js +327 -0
- package/dist/policy-cache.d.ts +69 -0
- package/dist/policy-cache.js +178 -0
- package/dist/priority.d.ts +27 -0
- package/dist/priority.js +28 -0
- package/dist/quotas.d.ts +19 -0
- package/dist/quotas.js +47 -0
- package/dist/reasoning.d.ts +54 -0
- package/dist/reasoning.js +307 -0
- package/dist/registry.d.ts +101 -0
- package/dist/registry.js +369 -0
- package/dist/remote.d.ts +130 -0
- package/dist/remote.js +473 -0
- package/dist/runtime.d.ts +167 -0
- package/dist/runtime.js +1035 -0
- package/dist/skills.d.ts +86 -0
- package/dist/skills.js +376 -0
- package/dist/task-service.d.ts +239 -0
- package/dist/task-service.js +790 -0
- package/dist/tools.d.ts +140 -0
- package/dist/tools.js +476 -0
- package/dist/wake-index.d.ts +9 -0
- package/dist/wake-index.js +11 -0
- package/dist/wakeups.d.ts +142 -0
- package/dist/wakeups.js +501 -0
- package/dist/workflow.d.ts +36 -0
- package/dist/workflow.js +101 -0
- package/package.json +41 -5
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { AgentropyError, type Agent, type AgentDefinition, type AgentInstance, type AgentProfile, type AuditIntentWriter, type ConversationTurn, type HumanActionRequest, type HumanDecision, type InboxEntry, type InboxMarker, type PolicyDecisionPoint, type Store, type TaskEvent, type TaskHandle, type TaskSnapshot, type Telemetry, type CommunicationRouter, type ReasoningProvider, type WorkflowEngine, type ToolExecutor, type TrustedPrincipal, type DelegationRequest, type VersionedRef } from '@agentropy/core';
|
|
2
|
+
import { AuditForwarder, AuditService, type AuditAnchorSink, type AuditRetention } from './audit.js';
|
|
3
|
+
import { HumanActionService } from './human-actions.js';
|
|
4
|
+
import { InboxService } from './inbox.js';
|
|
5
|
+
import { OutboxRelay, type FaultHook } from './outbox.js';
|
|
6
|
+
import { type InboxPreferences, type PriorityPolicy } from './priority.js';
|
|
7
|
+
import { type RuntimeLimits } from './limits.js';
|
|
8
|
+
import type { QuotaResolver } from './quotas.js';
|
|
9
|
+
import { type MemoryOptions } from './memory.js';
|
|
10
|
+
import { type RemoteSyncOptions } from './remote.js';
|
|
11
|
+
import { DefinitionRegistry, InstanceDirectory } from './registry.js';
|
|
12
|
+
import { AgentRuntime, type RuntimeOptions } from './runtime.js';
|
|
13
|
+
import { TaskService, type GrantVerifier } from './task-service.js';
|
|
14
|
+
import { FileSystemSkillLoader, type InMemorySkillRegistry } from './skills.js';
|
|
15
|
+
import { type InMemoryToolRegistry, type ToolProviderRegistry } from './tools.js';
|
|
16
|
+
import { WakeupService, type OperationHandler } from './wakeups.js';
|
|
17
|
+
export interface LocalAppOptions {
|
|
18
|
+
store: Store;
|
|
19
|
+
/** Required: there is no implicit allow-all policy. */
|
|
20
|
+
pdp: PolicyDecisionPoint;
|
|
21
|
+
grants?: GrantVerifier;
|
|
22
|
+
/** Sink for committed audit intents; without one they stay in the Store's `audit` collection. */
|
|
23
|
+
audit?: AuditIntentWriter;
|
|
24
|
+
/** Deployment audit retention and floor (ADR-0022 §4; default 365 days, floor 30). */
|
|
25
|
+
auditRetention?: AuditRetention;
|
|
26
|
+
/** Independently protected sink for audit chain anchors (ADR-0022 §7). */
|
|
27
|
+
auditAnchors?: AuditAnchorSink;
|
|
28
|
+
now?: () => string;
|
|
29
|
+
profiles?: readonly AgentProfile[];
|
|
30
|
+
/** Tool registry, providers and executor backing `tool-use.listTools` / `tool-use.call`. */
|
|
31
|
+
tools?: {
|
|
32
|
+
registry: InMemoryToolRegistry;
|
|
33
|
+
providers: ToolProviderRegistry;
|
|
34
|
+
executor: ToolExecutor;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Skill registry (and loader, default `FileSystemSkillLoader`): definitions may then select `skills`, which are
|
|
38
|
+
* pinned at acceptance and readable through `AgentContext.skills` (FEAT-041.1).
|
|
39
|
+
*/
|
|
40
|
+
skills?: {
|
|
41
|
+
registry: InMemorySkillRegistry;
|
|
42
|
+
loader?: FileSystemSkillLoader;
|
|
43
|
+
};
|
|
44
|
+
/** Model provider behind `reasoning.complete` (bounded tools and budget), e.g. `openAICompatibleReasoning(…)`. */
|
|
45
|
+
reasoning?: ReasoningProvider;
|
|
46
|
+
/** Enables the reference `memory` capability (`remember`, `recall`) on the store (FEAT-045). */
|
|
47
|
+
memory?: MemoryOptions;
|
|
48
|
+
/** Deterministic workflow engine behind `workflow.start` / `workflow.status`; completions wake waiting tasks. */
|
|
49
|
+
workflow?: WorkflowEngine;
|
|
50
|
+
/** Minimum time between polls of a workflow engine that implements `poll` (default 5 s). */
|
|
51
|
+
workflowPollMs?: number;
|
|
52
|
+
/** Extra built-in operation handlers, e.g. `complete` for `reasoning` backed by a model client. */
|
|
53
|
+
operations?: Record<string, OperationHandler>;
|
|
54
|
+
runtime?: Omit<RuntimeOptions, 'tasks' | 'implementations' | 'capabilityProviders' | 'relay'>;
|
|
55
|
+
/** Operational limits (D-05); validated at startup, see DEFAULT_LIMITS. */
|
|
56
|
+
limits?: Partial<RuntimeLimits>;
|
|
57
|
+
faults?: FaultHook;
|
|
58
|
+
/** Spans and metrics (e.g. `openTelemetry({ api, tracer, meter })`); no-op by default. */
|
|
59
|
+
telemetry?: Telemetry;
|
|
60
|
+
/** Router for remote delegation targets (`target.remote`), with A2A or custom providers registered (FEAT-027.9). */
|
|
61
|
+
communication?: {
|
|
62
|
+
router: CommunicationRouter;
|
|
63
|
+
/** Refresh pace of remote task projections (default 1 s after a change, doubling to 30 s when quiet). */
|
|
64
|
+
sync?: RemoteSyncOptions;
|
|
65
|
+
/** Longest one call to a remote peer may take (default 30 s); longer is `RemoteUnavailable` (FIX-053). */
|
|
66
|
+
timeoutMs?: number;
|
|
67
|
+
};
|
|
68
|
+
/** Per-tenant quotas (M2-11): active tasks, accept rate, live instances. */
|
|
69
|
+
quotas?: QuotaResolver;
|
|
70
|
+
/** Relay leader lease, for several processes sharing one store (M2-06). */
|
|
71
|
+
relay?: {
|
|
72
|
+
relayId: string;
|
|
73
|
+
leaseMs?: number;
|
|
74
|
+
};
|
|
75
|
+
/** Give up on an outbox row after this many failed deliveries (default: never; see `OutboxRelayOptions.poisonAfter`). */
|
|
76
|
+
outboxPoisonAfter?: number;
|
|
77
|
+
/** Unconsumed events kept per subscription before back-pressure drops (default 1000). */
|
|
78
|
+
mailboxLimit?: number;
|
|
79
|
+
/** Briefing policy, per-user preferences and urgent push (M2-04). */
|
|
80
|
+
inbox?: {
|
|
81
|
+
policy?: PriorityPolicy;
|
|
82
|
+
preferences?: (user: TrustedPrincipal) => InboxPreferences | Promise<InboxPreferences>;
|
|
83
|
+
push?: (entry: InboxEntry) => Promise<boolean>;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* State of the loop `LocalApp.start()` runs (FEAT-037.1). A tick that throws (a store outage, a bug) is counted
|
|
88
|
+
* and reported, and the loop goes on; readiness probes read this to tell a live loop from a stalled one.
|
|
89
|
+
*/
|
|
90
|
+
export interface SchedulerStatus {
|
|
91
|
+
/** True between `start()` and the returned stop function settling. */
|
|
92
|
+
running: boolean;
|
|
93
|
+
startedAt?: string;
|
|
94
|
+
intervalMs?: number;
|
|
95
|
+
/** When the last tick completed without error. */
|
|
96
|
+
lastTickAt?: string;
|
|
97
|
+
/** Ticks that failed since the last successful one. */
|
|
98
|
+
consecutiveFailures: number;
|
|
99
|
+
/** Errors v1 code of the last failed tick, cleared by the next successful one. */
|
|
100
|
+
lastError?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface LocalApp {
|
|
103
|
+
readonly store: Store;
|
|
104
|
+
readonly definitions: DefinitionRegistry;
|
|
105
|
+
readonly instances: InstanceDirectory;
|
|
106
|
+
readonly tasks: TaskService;
|
|
107
|
+
readonly runtime: AgentRuntime;
|
|
108
|
+
readonly wakeups: WakeupService;
|
|
109
|
+
readonly inbox: InboxService;
|
|
110
|
+
readonly human: HumanActionService;
|
|
111
|
+
readonly relay: OutboxRelay;
|
|
112
|
+
/** Hands committed audit intents to `audit`; present only when a sink is configured (FEAT-075). */
|
|
113
|
+
readonly auditForwarder?: AuditForwarder;
|
|
114
|
+
/** Tenant-scoped audit read and hash-chain verification (needs `audit:read` / `audit:verify`). */
|
|
115
|
+
readonly auditLog: AuditService;
|
|
116
|
+
/** The effective, validated limits this app runs with. */
|
|
117
|
+
readonly limits: RuntimeLimits;
|
|
118
|
+
/** Register a definition and, for `native-ts` implementations, its handler. */
|
|
119
|
+
define(definition: AgentDefinition, handler?: Agent<never, unknown>): void;
|
|
120
|
+
/** `trace.traceparent`: optional W3C context from the caller's request (sanitized; never authorization). */
|
|
121
|
+
delegate<I>(request: DelegationRequest<I>, caller: TrustedPrincipal, trace?: {
|
|
122
|
+
traceparent?: string;
|
|
123
|
+
}): Promise<TaskHandle>;
|
|
124
|
+
getTask(taskId: string, caller: TrustedPrincipal): Promise<TaskSnapshot>;
|
|
125
|
+
listTasks(query: {
|
|
126
|
+
instanceId?: string;
|
|
127
|
+
status?: TaskSnapshot['status'][];
|
|
128
|
+
cursor?: string;
|
|
129
|
+
limit?: number;
|
|
130
|
+
/** Newest task first (default oldest first); the cursor then continues towards older tasks (revision 13). */
|
|
131
|
+
newestFirst?: boolean;
|
|
132
|
+
}, caller: TrustedPrincipal): Promise<{
|
|
133
|
+
tasks: TaskSnapshot[];
|
|
134
|
+
cursor: string;
|
|
135
|
+
cursors: string[];
|
|
136
|
+
}>;
|
|
137
|
+
listInstances(caller: TrustedPrincipal, ownerId?: string): Promise<AgentInstance[]>;
|
|
138
|
+
/** Owner-only: set the principals allowed to delegate to an instance (D-08). */
|
|
139
|
+
shareInstance(instanceId: string, principalIds: string[], caller: TrustedPrincipal): Promise<AgentInstance>;
|
|
140
|
+
/**
|
|
141
|
+
* Audited upgrade or rollback of the definition version an instance uses for future tasks (FEAT-028.3). Accepted
|
|
142
|
+
* tasks stay pinned to their snapshot. Policy action `agent:upgrade`.
|
|
143
|
+
*/
|
|
144
|
+
upgradeInstance(instanceId: string, change: {
|
|
145
|
+
version: string;
|
|
146
|
+
expectedRevision: number;
|
|
147
|
+
}, caller: TrustedPrincipal): Promise<AgentInstance>;
|
|
148
|
+
/**
|
|
149
|
+
* Trusted services: which versions of a definition are still referenced in the caller's tenant, by live instances
|
|
150
|
+
* and by non-terminal tasks — a version can be removed once both counts are zero (D-07 retirement constraint).
|
|
151
|
+
*/
|
|
152
|
+
versionsInUse(definitionId: string, caller: TrustedPrincipal): Promise<{
|
|
153
|
+
version: string;
|
|
154
|
+
instances: number;
|
|
155
|
+
activeTasks: number;
|
|
156
|
+
}[]>;
|
|
157
|
+
/** Stop accepting new tasks; retire once the last task ends. */
|
|
158
|
+
drainInstance(instanceId: string, caller: TrustedPrincipal): Promise<AgentInstance>;
|
|
159
|
+
getTaskByIdempotencyKey(key: string, caller: TrustedPrincipal): Promise<TaskSnapshot>;
|
|
160
|
+
getResult<O>(taskId: string, caller: TrustedPrincipal): Promise<O>;
|
|
161
|
+
cancel(taskId: string, caller: TrustedPrincipal, reason?: string): Promise<TaskSnapshot>;
|
|
162
|
+
/** Ends after the terminal event, or when `options.signal` aborts. */
|
|
163
|
+
subscribe(taskId: string, caller: TrustedPrincipal, from?: {
|
|
164
|
+
revision: number;
|
|
165
|
+
sequence: number;
|
|
166
|
+
}, options?: {
|
|
167
|
+
signal?: AbortSignal;
|
|
168
|
+
}): AsyncIterable<TaskEvent>;
|
|
169
|
+
submitTurn(turn: ConversationTurn, caller: TrustedPrincipal): Promise<TaskHandle>;
|
|
170
|
+
createInstance(req: {
|
|
171
|
+
definition: VersionedRef;
|
|
172
|
+
ownerId: string;
|
|
173
|
+
idempotencyKey: string;
|
|
174
|
+
}, caller: TrustedPrincipal): Promise<AgentInstance>;
|
|
175
|
+
suspendInstance(instanceId: string, caller: TrustedPrincipal): Promise<AgentInstance>;
|
|
176
|
+
resumeInstance(instanceId: string, caller: TrustedPrincipal): Promise<AgentInstance>;
|
|
177
|
+
retireInstance(instanceId: string, caller: TrustedPrincipal, opts?: {
|
|
178
|
+
force?: boolean;
|
|
179
|
+
}): Promise<AgentInstance>;
|
|
180
|
+
claimHumanAction(requestId: string, caller: TrustedPrincipal): Promise<HumanActionRequest>;
|
|
181
|
+
releaseHumanAction(requestId: string, caller: TrustedPrincipal): Promise<HumanActionRequest>;
|
|
182
|
+
getHumanAction(requestId: string, caller: TrustedPrincipal): Promise<HumanActionRequest>;
|
|
183
|
+
provideHumanInput(decision: HumanDecision, caller: TrustedPrincipal): Promise<void>;
|
|
184
|
+
listInbox(query: {
|
|
185
|
+
cursor?: string;
|
|
186
|
+
limit?: number;
|
|
187
|
+
}, caller: TrustedPrincipal): Promise<{
|
|
188
|
+
entries: InboxEntry[];
|
|
189
|
+
cursor: string;
|
|
190
|
+
}>;
|
|
191
|
+
markInbox(entryId: string, marker: InboxMarker, caller: TrustedPrincipal, presentedRevision?: number): Promise<void>;
|
|
192
|
+
reauthorize(taskId: string, caller: TrustedPrincipal): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* D-20 revocation checkpoint (trusted services only): stop running work under a revoked grant, drop cached policy
|
|
195
|
+
* decisions for it, and audit the revocation. Queued and future work is held by the dispatch gate.
|
|
196
|
+
*/
|
|
197
|
+
revokeAuthority(grantRef: string, caller: TrustedPrincipal): Promise<{
|
|
198
|
+
signalled: string[];
|
|
199
|
+
invalidatedDecisions: number;
|
|
200
|
+
}>;
|
|
201
|
+
/** Committed effects of a visible task (journal entries), e.g. to plan an authorized compensation. */
|
|
202
|
+
listEffects(taskId: string, caller: TrustedPrincipal): Promise<{
|
|
203
|
+
operation: string;
|
|
204
|
+
stepKey?: string;
|
|
205
|
+
at: string;
|
|
206
|
+
}[]>;
|
|
207
|
+
/**
|
|
208
|
+
* Refreshes one open remote projection from its peer now (FEAT-048.2); true when it changed. For trusted host
|
|
209
|
+
* code, such as the A2A push notification receiver after it authenticated a notification; not an AgentService
|
|
210
|
+
* operation, and it takes no principal.
|
|
211
|
+
*/
|
|
212
|
+
refreshRemote(taskId: string): Promise<boolean>;
|
|
213
|
+
/** Operator compaction of consumed and expired runtime records (trusted services only). */
|
|
214
|
+
compact(retainMs: number, caller: TrustedPrincipal): Promise<Awaited<ReturnType<WakeupService['compact']>>>;
|
|
215
|
+
/** Operator reconciliation: re-project the inbox from committed events (trusted services only). */
|
|
216
|
+
rebuildInbox(caller: TrustedPrincipal): Promise<{
|
|
217
|
+
created: number;
|
|
218
|
+
}>;
|
|
219
|
+
/** Trusted event ingress (e.g. a price feed adapter); duplicate event IDs are ignored. */
|
|
220
|
+
publishEvent(event: {
|
|
221
|
+
eventId: string;
|
|
222
|
+
source: string;
|
|
223
|
+
tenantId: string;
|
|
224
|
+
payload: unknown;
|
|
225
|
+
traceparent?: string;
|
|
226
|
+
}): Promise<boolean>;
|
|
227
|
+
/** Poll wake-ups and run due work until nothing is left (bounded); for tests, examples and batch use. */
|
|
228
|
+
runUntilIdle(maxRounds?: number): Promise<void>;
|
|
229
|
+
/**
|
|
230
|
+
* Periodic scheduler loop for a long-running process; returns a stop function that waits for the current tick
|
|
231
|
+
* and the running executions and never rejects. A tick that throws is counted (`agentropy.scheduler.errors`),
|
|
232
|
+
* handed to `options.onError` and does not stop the loop (FEAT-037.1). One tick runs at a time: an interval that
|
|
233
|
+
* fires while a tick is still in flight is skipped, so slow ticks never queue behind each other (FIX-050).
|
|
234
|
+
*
|
|
235
|
+
* Leases are renewed on a timer of their own, every `options.heartbeatMs` (default a third of `leaseMs`; an integer
|
|
236
|
+
* below `leaseMs`), from the start until the stop function has seen the last running execution settle. A tick held
|
|
237
|
+
* up by a slow store, policy point, peer or sink, and a shutdown that waits for long work, therefore cannot let
|
|
238
|
+
* another worker on the store recover an execution this one is still running (FIX-051). A failed heartbeat is
|
|
239
|
+
* counted and handed to `options.onError` like a failed tick.
|
|
240
|
+
*
|
|
241
|
+
* The stop function waits for running executions without bound, or, with `{ drainMs }`, for at most that long
|
|
242
|
+
* (FEAT-072): what is still running then is aborted and its lease expired, so another worker on the store resumes
|
|
243
|
+
* it at once instead of after `leaseMs`, and the stop function settles. Use it where a process is killed after a
|
|
244
|
+
* grace period (a pod's `terminationGracePeriodSeconds`). `intervalMs` is an integer in [1, 2^31-1]; a `drainMs`
|
|
245
|
+
* above 2^31-1 ms (about 24.8 days, the longest delay a Node.js timer keeps) waits that long (FIX-086).
|
|
246
|
+
*/
|
|
247
|
+
start(intervalMs?: number, options?: {
|
|
248
|
+
onError?: (error: AgentropyError) => void;
|
|
249
|
+
heartbeatMs?: number;
|
|
250
|
+
}): (options?: {
|
|
251
|
+
drainMs?: number;
|
|
252
|
+
}) => Promise<void>;
|
|
253
|
+
/** Snapshot of the loop's health: last successful tick, failures in a row, last error code. */
|
|
254
|
+
schedulerStatus(): SchedulerStatus;
|
|
255
|
+
}
|
|
256
|
+
export declare function createLocalApp(o: LocalAppOptions): LocalApp;
|