@nylorun/runtime 0.9.0-beta → 0.11.0-beta
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/CHANGELOG.md +81 -0
- package/README.md +110 -37
- package/dist/adapters/execution/restate.d.ts +130 -0
- package/dist/adapters/execution/restate.js +442 -0
- package/dist/adapters/media.d.ts +2 -2
- package/dist/adapters/media.js +2 -2
- package/dist/adapters/observe.d.ts +2 -1
- package/dist/adapters/observe.js +2 -3
- package/dist/adapters/sandbox/virtual.js +1 -1
- package/dist/adapters/streams/s2.d.ts +18 -0
- package/dist/adapters/streams/s2.js +361 -0
- package/dist/assets.d.ts +2 -2
- package/dist/assets.js +5 -3
- package/dist/core/executors.d.ts +15 -3
- package/dist/core/executors.js +40 -5
- package/dist/core/flow-host.d.ts +225 -0
- package/dist/core/flow-host.js +518 -0
- package/dist/core/limits.d.ts +40 -0
- package/dist/core/limits.js +76 -0
- package/dist/core/runtime.d.ts +5 -90
- package/dist/core/runtime.js +3 -1447
- package/dist/core/sandbox-routes.d.ts +40 -0
- package/dist/core/sandbox-routes.js +106 -0
- package/dist/core/turn-manifest.d.ts +50 -0
- package/dist/core/turn-manifest.js +66 -0
- package/dist/execution/memory.d.ts +54 -0
- package/dist/execution/memory.js +217 -0
- package/dist/execution/types.d.ts +125 -0
- package/dist/execution/types.js +52 -0
- package/dist/host/config-for.d.ts +17 -0
- package/dist/host/config-for.js +27 -0
- package/dist/host/config.d.ts +16 -0
- package/dist/host/create-host.d.ts +56 -0
- package/dist/host/create-host.js +420 -0
- package/dist/host/environment.d.ts +13 -0
- package/dist/host/environment.js +53 -0
- package/dist/host/execution.d.ts +61 -0
- package/dist/host/execution.js +69 -0
- package/dist/host/http.d.ts +39 -0
- package/dist/host/http.js +142 -0
- package/dist/host/index.d.ts +8 -0
- package/dist/host/index.js +7 -0
- package/dist/host/logger.d.ts +3 -0
- package/dist/host/logger.js +18 -0
- package/dist/host/main.d.ts +3 -0
- package/dist/host/main.js +201 -0
- package/dist/host/stack-config.d.ts +72 -0
- package/dist/host/stack-config.js +193 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +4 -2
- package/dist/infra/database.d.ts +16 -0
- package/dist/infra/database.js +31 -0
- package/dist/infra/execution.d.ts +39 -0
- package/dist/infra/execution.js +68 -0
- package/dist/infra/index.d.ts +42 -0
- package/dist/infra/index.js +56 -0
- package/dist/infra/readiness.d.ts +33 -0
- package/dist/infra/readiness.js +53 -0
- package/dist/infra/streams.d.ts +17 -0
- package/dist/infra/streams.js +33 -0
- package/dist/infra/workers.d.ts +39 -0
- package/dist/infra/workers.js +31 -0
- package/dist/mcp/connect.d.ts +1 -0
- package/dist/mcp/connect.js +2 -0
- package/dist/mcp/pool.d.ts +3 -1
- package/dist/mcp/pool.js +2 -1
- package/dist/mcp/stdio.d.ts +2 -0
- package/dist/mcp/stdio.js +3 -1
- package/dist/model/auth-store.d.ts +1 -1
- package/dist/model/auth-store.js +2 -2
- package/dist/model/models.d.ts +4 -0
- package/dist/model/models.js +22 -26
- package/dist/model/pi-model.d.ts +2 -2
- package/dist/model/pi-model.js +6 -6
- package/dist/model/settings.d.ts +5 -1
- package/dist/model/settings.js +6 -2
- package/dist/sandbox/manager.d.ts +26 -8
- package/dist/sandbox/manager.js +95 -47
- package/dist/sandbox/select.d.ts +5 -4
- package/dist/sandbox/select.js +18 -13
- package/dist/sandbox/share.d.ts +23 -0
- package/dist/sandbox/share.js +58 -0
- package/dist/sandbox/types.d.ts +2 -2
- package/dist/store/canonical.d.ts +5 -0
- package/dist/store/canonical.js +17 -0
- package/dist/store/cursor.d.ts +9 -0
- package/dist/store/cursor.js +18 -0
- package/dist/store/memory.d.ts +57 -0
- package/dist/store/memory.js +643 -0
- package/dist/store/ownership.d.ts +19 -0
- package/dist/store/ownership.js +33 -0
- package/dist/store/postgres/connect.d.ts +25 -0
- package/dist/store/postgres/connect.js +25 -0
- package/dist/store/postgres/locking.d.ts +16 -0
- package/dist/store/postgres/locking.js +22 -0
- package/dist/store/postgres/migrations/001_initial.d.ts +27 -0
- package/dist/store/postgres/migrations/001_initial.js +196 -0
- package/dist/store/postgres/migrations/index.d.ts +49 -0
- package/dist/store/postgres/migrations/index.js +75 -0
- package/dist/store/postgres/names.d.ts +11 -0
- package/dist/store/postgres/names.js +42 -0
- package/dist/store/postgres/store.d.ts +11 -0
- package/dist/store/postgres/store.js +790 -0
- package/dist/store/postgres/tenants.d.ts +90 -0
- package/dist/store/postgres/tenants.js +207 -0
- package/dist/store/types.d.ts +440 -0
- package/dist/store/types.js +10 -0
- package/dist/streams/basin.d.ts +23 -0
- package/dist/streams/basin.js +51 -0
- package/dist/streams/memory.d.ts +25 -0
- package/dist/streams/memory.js +124 -0
- package/dist/streams/relay.d.ts +37 -0
- package/dist/streams/relay.js +254 -0
- package/dist/streams/types.d.ts +115 -0
- package/dist/streams/types.js +86 -0
- package/dist/tenant/actions.d.ts +153 -0
- package/dist/tenant/actions.js +191 -0
- package/dist/tenant/advance.d.ts +15 -0
- package/dist/tenant/advance.js +439 -0
- package/dist/tenant/auth.d.ts +11 -0
- package/dist/tenant/auth.js +34 -0
- package/dist/tenant/commands.d.ts +3 -0
- package/dist/tenant/commands.js +384 -0
- package/dist/tenant/context.d.ts +140 -0
- package/dist/tenant/context.js +40 -0
- package/dist/tenant/effects.d.ts +20 -0
- package/dist/tenant/effects.js +539 -0
- package/dist/tenant/envelope.d.ts +7 -0
- package/dist/tenant/envelope.js +22 -0
- package/dist/tenant/ephemeral.d.ts +42 -0
- package/dist/tenant/ephemeral.js +224 -0
- package/dist/tenant/http.d.ts +32 -0
- package/dist/tenant/http.js +51 -0
- package/dist/tenant/live.d.ts +92 -0
- package/dist/tenant/live.js +290 -0
- package/dist/tenant/logger.d.ts +9 -0
- package/dist/tenant/logger.js +25 -0
- package/dist/tenant/model-setting.d.ts +16 -0
- package/dist/tenant/model-setting.js +12 -0
- package/dist/tenant/module.d.ts +38 -0
- package/dist/tenant/module.js +319 -0
- package/dist/tenant/paths.d.ts +28 -0
- package/dist/tenant/paths.js +91 -0
- package/dist/tenant/pool.d.ts +10 -0
- package/dist/tenant/pool.js +54 -0
- package/dist/tenant/principals.d.ts +13 -0
- package/dist/tenant/principals.js +37 -0
- package/dist/tenant/quarantine-error.d.ts +6 -0
- package/dist/tenant/quarantine-error.js +9 -0
- package/dist/tenant/quarantine.d.ts +27 -0
- package/dist/tenant/quarantine.js +72 -0
- package/dist/tenant/reset.d.ts +22 -0
- package/dist/tenant/reset.js +81 -0
- package/dist/tenant/routes-tenant.d.ts +12 -0
- package/dist/tenant/routes-tenant.js +126 -0
- package/dist/tenant/routes.d.ts +9 -0
- package/dist/tenant/routes.js +142 -0
- package/dist/tenant/runtime.d.ts +81 -0
- package/dist/tenant/runtime.js +298 -0
- package/dist/tenant/scheduler.d.ts +25 -0
- package/dist/tenant/scheduler.js +84 -0
- package/dist/tenant/session.d.ts +60 -0
- package/dist/tenant/session.js +94 -0
- package/dist/tenant/sessions.d.ts +34 -0
- package/dist/tenant/sessions.js +149 -0
- package/dist/tenant/status.d.ts +37 -0
- package/dist/tenant/status.js +130 -0
- package/dist/tenant/store-memory.d.ts +16 -0
- package/dist/tenant/store-memory.js +111 -0
- package/dist/tenant/store-pg.d.ts +15 -0
- package/dist/tenant/store-pg.js +140 -0
- package/dist/tenant/streams.d.ts +126 -0
- package/dist/tenant/streams.js +419 -0
- package/dist/tenant/sweep.d.ts +15 -0
- package/dist/tenant/sweep.js +122 -0
- package/dist/tenant/types.d.ts +205 -0
- package/dist/tenant/types.js +23 -0
- package/dist/tenant/worker.d.ts +84 -0
- package/dist/tenant/worker.js +189 -0
- package/dist/vault/kek.d.ts +5 -2
- package/dist/vault/kek.js +7 -10
- package/dist/vault/service.d.ts +37 -31
- package/dist/vault/service.js +439 -359
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +14 -11
- package/dist/adapters/sandbox/microsandbox.d.ts +0 -2
- package/dist/adapters/sandbox/microsandbox.js +0 -238
- package/dist/core/main.js +0 -35
- package/dist/core/store.d.ts +0 -30
- package/dist/core/store.js +0 -202
- /package/dist/{core/main.d.ts → host/config.js} +0 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { Action, ActionOutcome } from "@nylorun/core/contracts";
|
|
2
|
+
import type { JsonValue, WorkflowManifest } from "@nylorun/core/define";
|
|
3
|
+
import type { HostEffect } from "@nylorun/harness/run";
|
|
4
|
+
import type { Wake } from "../execution/types.js";
|
|
5
|
+
import type { EffectDoc, Tx } from "../store/types.js";
|
|
6
|
+
import { type FlowLimits } from "./limits.js";
|
|
7
|
+
/** Deterministic agent session id: derive(workflowSessionId, path, …parts). */
|
|
8
|
+
export declare function deriveSessionId(workflowSessionId: string, path: string, ...parts: string[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* Linked agent session id for a flow agent effect.
|
|
11
|
+
* Verifier agents (`context.role === "verify-agent"`) get a unique session per
|
|
12
|
+
* (path, turnId, iterations) so prior verdicts cannot leak across Loop iterations.
|
|
13
|
+
*/
|
|
14
|
+
export declare function deriveAgentEffectSessionId(workflowSessionId: string, path: string, request: {
|
|
15
|
+
readonly turnId: string;
|
|
16
|
+
readonly iterations?: string;
|
|
17
|
+
readonly context?: Record<string, unknown>;
|
|
18
|
+
}): string;
|
|
19
|
+
export declare function isWorkflowManifest(manifest: unknown): manifest is WorkflowManifest;
|
|
20
|
+
/** Flow tool-node effect: `tool` with path/key and no agent capabilityId. */
|
|
21
|
+
export declare function isFlowToolEffect(request: HostEffect): boolean;
|
|
22
|
+
export declare function isFlowEffect(request: HostEffect): boolean;
|
|
23
|
+
export type FlowLink = {
|
|
24
|
+
readonly workflowSessionId: string;
|
|
25
|
+
readonly path: string;
|
|
26
|
+
readonly effectId: string;
|
|
27
|
+
readonly turnId: string;
|
|
28
|
+
};
|
|
29
|
+
export type FlowHostSession = {
|
|
30
|
+
id: string;
|
|
31
|
+
agentId: string;
|
|
32
|
+
ownerUserId: string;
|
|
33
|
+
manifest: any;
|
|
34
|
+
manifestHash: string;
|
|
35
|
+
implementationVersion: string;
|
|
36
|
+
status: string;
|
|
37
|
+
activeTurnId: string | null;
|
|
38
|
+
info?: any;
|
|
39
|
+
vaultIds?: readonly string[];
|
|
40
|
+
credentialSelections?: readonly unknown[];
|
|
41
|
+
creation?: unknown;
|
|
42
|
+
waits?: unknown;
|
|
43
|
+
lastOutput?: JsonValue;
|
|
44
|
+
/** The turn `status`, `lastOutput` and `error` describe, once it ended. */
|
|
45
|
+
lastTurnId?: string;
|
|
46
|
+
error?: string;
|
|
47
|
+
};
|
|
48
|
+
/** How a linked agent turn ended. */
|
|
49
|
+
export type LinkedTurnEnd = {
|
|
50
|
+
readonly turnId: string;
|
|
51
|
+
} & ({
|
|
52
|
+
readonly status: "completed";
|
|
53
|
+
readonly output: JsonValue;
|
|
54
|
+
} | {
|
|
55
|
+
readonly status: "failed" | "cancelled";
|
|
56
|
+
readonly error?: string;
|
|
57
|
+
});
|
|
58
|
+
export type FlowWait = {
|
|
59
|
+
readonly sessionId: string;
|
|
60
|
+
readonly path: string;
|
|
61
|
+
readonly interactionId: string;
|
|
62
|
+
readonly kind: string;
|
|
63
|
+
readonly invocationId?: string;
|
|
64
|
+
readonly wait?: unknown;
|
|
65
|
+
readonly status?: string;
|
|
66
|
+
};
|
|
67
|
+
export type CancelSiblingResult = {
|
|
68
|
+
readonly cancelledActions: string[];
|
|
69
|
+
readonly uncertainActions: string[];
|
|
70
|
+
readonly agentSessionIds: string[];
|
|
71
|
+
};
|
|
72
|
+
export type CascadeCancelPlan = {
|
|
73
|
+
/** Linked agent sessions to cancel, deepest path first. */
|
|
74
|
+
readonly agentSessionIds: string[];
|
|
75
|
+
readonly pendingActionIds: string[];
|
|
76
|
+
readonly claimedActionIds: string[];
|
|
77
|
+
};
|
|
78
|
+
/** Wakes a session after commit (`DurableExecution.wake` through the Tenant context). */
|
|
79
|
+
type Schedule = (sessionId: string, wake: Wake) => void | Promise<void>;
|
|
80
|
+
/** Effect documents as the flow host writes them. */
|
|
81
|
+
export type FlowEffect = EffectDoc & {
|
|
82
|
+
agentSessionId?: string;
|
|
83
|
+
outcome?: ActionOutcome;
|
|
84
|
+
error?: string;
|
|
85
|
+
};
|
|
86
|
+
/** Active agent turns + pending/claimed actions for one workflow turn. */
|
|
87
|
+
export declare function countActiveFlowWork(t: Tx, workflowSessionId: string, turnId: string): Promise<number>;
|
|
88
|
+
/** The `commands` document key of a session command's idempotency key (`tenant/commands.ts`). */
|
|
89
|
+
export declare function commandKey(sessionId: string, idempotencyKey: string): string;
|
|
90
|
+
/** The idempotency key of the message a flow `agent` effect sends its linked session. */
|
|
91
|
+
export declare function linkedMessageKey(request: HostEffect): string;
|
|
92
|
+
/**
|
|
93
|
+
* The linked turn an `agent` effect started: the turn its message opened, or undefined until
|
|
94
|
+
* that message commits.
|
|
95
|
+
*/
|
|
96
|
+
export declare function linkedTurnOf(t: Tx, agentSessionId: string, request: HostEffect): Promise<string | undefined>;
|
|
97
|
+
/**
|
|
98
|
+
* How the linked turn an `agent` effect started ended, or undefined while it has not: before
|
|
99
|
+
* its message commits, the linked session's status and `lastOutput` describe an earlier turn.
|
|
100
|
+
* `agent` is the linked session, read in the caller's transaction.
|
|
101
|
+
*/
|
|
102
|
+
export declare function linkedTurnEnd(t: Tx, effect: Pick<FlowEffect, "request" | "agentSessionId">, agent: FlowHostSession | undefined): Promise<LinkedTurnEnd | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* After a linked agent turn ends, settle the `agent` effect that started it and wake the
|
|
105
|
+
* workflow. `turnId` is the linked session's turn that ended; an effect bound to another turn
|
|
106
|
+
* (a later iteration whose message has not committed yet) is left alone.
|
|
107
|
+
*/
|
|
108
|
+
export declare function wakeLinkedWorkflow(input: {
|
|
109
|
+
readonly t: Tx;
|
|
110
|
+
readonly agentSessionId: string;
|
|
111
|
+
readonly turnId: string | null;
|
|
112
|
+
readonly output?: JsonValue;
|
|
113
|
+
readonly failed?: boolean;
|
|
114
|
+
readonly cancelled?: boolean;
|
|
115
|
+
readonly error?: string;
|
|
116
|
+
readonly schedule: Schedule;
|
|
117
|
+
}): Promise<void>;
|
|
118
|
+
/** Pending workflow `agent` effects with a linked session, for the Tenant sweep. */
|
|
119
|
+
export declare function pendingAgentEffects(t: Tx): Promise<FlowEffect[]>;
|
|
120
|
+
/**
|
|
121
|
+
* Tenant sweep: settle one pending `agent` effect whose linked turn already finished (the
|
|
122
|
+
* linked settle normally does this in its own transaction). Runs in its own transaction and
|
|
123
|
+
* locks the linked agent (child) session before the workflow (parent), per the lock order in
|
|
124
|
+
* `store/types.ts`. Only the linked turn the effect started settles it (`linkedTurnEnd`): the
|
|
125
|
+
* linked session may still show an earlier iteration's settled turn while this effect's message
|
|
126
|
+
* is not committed. A linked session still `running` or `runnable` is left to the sweep's
|
|
127
|
+
* orphan re-wake; a paused one surfaces on the workflow when the workflow settles. Returns
|
|
128
|
+
* true when it changed something.
|
|
129
|
+
*/
|
|
130
|
+
export declare function reconcilePendingAgentEffect(input: {
|
|
131
|
+
readonly t: Tx;
|
|
132
|
+
readonly effectId: string;
|
|
133
|
+
readonly schedule: Schedule;
|
|
134
|
+
}): Promise<boolean>;
|
|
135
|
+
/** Claimed `fn`/`verify` Actions, for the re-offer after a Tenant opens. */
|
|
136
|
+
export declare function claimedFnVerifyActions(t: Tx): Promise<Action[]>;
|
|
137
|
+
/**
|
|
138
|
+
* Re-offer one claimed `fn`/`verify` Action (SD-P7 / WF-C9): they are pure or repeat-safe, so
|
|
139
|
+
* a claim left by an executor of an earlier process is offered again at once rather than
|
|
140
|
+
* after its lease. The next claim bumps the generation, which fences a late result. Locks
|
|
141
|
+
* only the Action's session. Returns true when it re-offered.
|
|
142
|
+
*/
|
|
143
|
+
export declare function reofferFnVerifyClaim(t: Tx, actionId: string): Promise<boolean>;
|
|
144
|
+
/** Path depth for deepest-first cancel ordering. */
|
|
145
|
+
export declare function pathDepth(path: string): number;
|
|
146
|
+
/**
|
|
147
|
+
* Plan a cancel cascade for a workflow session: linked agents deepest first,
|
|
148
|
+
* then pending → cancelled and claimed → uncertain actions (SD-P11 / WF-R53).
|
|
149
|
+
*/
|
|
150
|
+
export declare function planCancelCascade(input: {
|
|
151
|
+
readonly t: Tx;
|
|
152
|
+
readonly workflowSessionId: string;
|
|
153
|
+
readonly turnId: string | null;
|
|
154
|
+
}): Promise<CascadeCancelPlan>;
|
|
155
|
+
/**
|
|
156
|
+
* Cancel sibling work under a Parallel/Map parent when one branch fails (PAR-R6).
|
|
157
|
+
* Agent turns listed in `agentSessionIds` are returned for the caller to cancel;
|
|
158
|
+
* pending actions → cancelled, claimed tool actions → uncertain.
|
|
159
|
+
* When `cancelEffectIds` is provided, those effects are marked cancelled and their
|
|
160
|
+
* paths are included in the sibling path set.
|
|
161
|
+
*/
|
|
162
|
+
export declare function cancelSiblingWork(input: {
|
|
163
|
+
readonly t: Tx;
|
|
164
|
+
readonly workflowSessionId: string;
|
|
165
|
+
readonly turnId: string;
|
|
166
|
+
/** Paths of siblings still running (not the failed branch). */
|
|
167
|
+
readonly siblingPaths?: readonly string[];
|
|
168
|
+
/** Effect ids the flow engine marked for fail-fast cancel. */
|
|
169
|
+
readonly cancelEffectIds?: readonly string[];
|
|
170
|
+
}): Promise<CancelSiblingResult>;
|
|
171
|
+
/**
|
|
172
|
+
* Apply cancel fencing to workflow-session actions (pending→cancelled, claimed→uncertain).
|
|
173
|
+
*/
|
|
174
|
+
export declare function fenceWorkflowActions(input: {
|
|
175
|
+
readonly t: Tx;
|
|
176
|
+
readonly workflowSessionId: string;
|
|
177
|
+
readonly turnId: string | null;
|
|
178
|
+
}): Promise<{
|
|
179
|
+
cancelled: string[];
|
|
180
|
+
uncertain: string[];
|
|
181
|
+
}>;
|
|
182
|
+
/**
|
|
183
|
+
* Aggregate human waits across the workflow session and linked agent sessions (WF-R51).
|
|
184
|
+
*/
|
|
185
|
+
export declare function aggregateWaits(input: {
|
|
186
|
+
readonly t: Tx;
|
|
187
|
+
readonly workflowSessionId: string;
|
|
188
|
+
}): Promise<FlowWait[]>;
|
|
189
|
+
/**
|
|
190
|
+
* Look up which session owns an interaction id. Used for 409 foreign approvals (WF-R52).
|
|
191
|
+
*/
|
|
192
|
+
export declare function findInteractionOwner(input: {
|
|
193
|
+
readonly t: Tx;
|
|
194
|
+
readonly workflowSessionId: string;
|
|
195
|
+
readonly interactionId: string;
|
|
196
|
+
}): Promise<{
|
|
197
|
+
sessionId: string;
|
|
198
|
+
path: string;
|
|
199
|
+
} | undefined>;
|
|
200
|
+
/**
|
|
201
|
+
* If approve/respond targets an interaction owned by a linked agent session,
|
|
202
|
+
* return a 409 message naming that session (WF-R52 / LOOP-A4).
|
|
203
|
+
*/
|
|
204
|
+
export declare function foreignInteractionConflict(input: {
|
|
205
|
+
readonly t: Tx;
|
|
206
|
+
readonly workflowSessionId: string;
|
|
207
|
+
readonly interactionId: string;
|
|
208
|
+
}): Promise<{
|
|
209
|
+
status: 409;
|
|
210
|
+
message: string;
|
|
211
|
+
ownerSessionId: string;
|
|
212
|
+
} | undefined>;
|
|
213
|
+
/**
|
|
214
|
+
* When concurrency slots free, re-enter the workflow so queued effects can start
|
|
215
|
+
* (status stays `queued` until the effect resolver dispatches them). Returns
|
|
216
|
+
* true when a wake was scheduled.
|
|
217
|
+
*/
|
|
218
|
+
export declare function wakeForQueuedEffects(input: {
|
|
219
|
+
readonly t: Tx;
|
|
220
|
+
readonly workflowSessionId: string;
|
|
221
|
+
readonly turnId: string;
|
|
222
|
+
readonly limits: FlowLimits;
|
|
223
|
+
readonly schedule: Schedule;
|
|
224
|
+
}): Promise<boolean>;
|
|
225
|
+
export {};
|