@intx/hub-sessions 0.2.2 → 0.4.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/README.md +3 -5
- package/dist/agent-repo.d.ts +23 -7
- package/dist/agent-repo.js +19 -6
- package/dist/agent-state-kind.js +18 -63
- package/dist/asset-service.d.ts +1 -20
- package/dist/asset-service.js +19 -97
- package/dist/committed-source-tree.d.ts +10 -0
- package/dist/committed-source-tree.js +35 -0
- package/dist/credential-push.d.ts +52 -7
- package/dist/credential-push.js +178 -22
- package/dist/event-collector-registry.d.ts +3 -2
- package/dist/event-collector-registry.js +42 -13
- package/dist/event-collector.d.ts +12 -2
- package/dist/event-collector.js +45 -4
- package/dist/hub-session-lookups.d.ts +125 -7
- package/dist/hub-session-lookups.js +541 -86
- package/dist/hub-session-orchestrator.d.ts +2 -3
- package/dist/hub-session-orchestrator.js +22 -56
- package/dist/index.d.ts +19 -9
- package/dist/index.js +16 -7
- package/dist/reconciliation-scheduler.d.ts +14 -0
- package/dist/reconciliation-scheduler.js +55 -0
- package/dist/repo-store/index.d.ts +2 -1
- package/dist/repo-store/index.js +1 -0
- package/dist/repo-store/store.d.ts +1 -1
- package/dist/repo-store/store.js +138 -1
- package/dist/repo-store/subscribe-kind.d.ts +6 -3
- package/dist/repo-store/subscribe-kind.js +42 -77
- package/dist/repo-store/types.d.ts +94 -6
- package/dist/repo-store/user-principal-gate.d.ts +26 -0
- package/dist/repo-store/user-principal-gate.js +78 -0
- package/dist/session-service.d.ts +252 -126
- package/dist/session-service.js +851 -624
- package/dist/sidecar-allocation/capability-policy.d.ts +27 -0
- package/dist/sidecar-allocation/capability-policy.js +124 -0
- package/dist/sidecar-allocation/contracts.d.ts +101 -0
- package/dist/sidecar-allocation/contracts.js +26 -0
- package/dist/sidecar-allocation/index.d.ts +5 -0
- package/dist/sidecar-allocation/index.js +4 -0
- package/dist/sidecar-allocation/operation.d.ts +10 -0
- package/dist/sidecar-allocation/operation.js +54 -0
- package/dist/sidecar-allocation/plugin-registry.d.ts +24 -0
- package/dist/sidecar-allocation/plugin-registry.js +61 -0
- package/dist/sidecar-allocation/reconciler.d.ts +54 -0
- package/dist/sidecar-allocation/reconciler.js +825 -0
- package/dist/skill-kind.js +12 -62
- package/dist/substrate.d.ts +3 -3
- package/dist/substrate.js +1 -1
- package/dist/workflow-allocation-service.d.ts +64 -0
- package/dist/workflow-allocation-service.js +554 -0
- package/dist/workflow-closure-resolution.d.ts +106 -0
- package/dist/workflow-closure-resolution.js +123 -0
- package/dist/workflow-definition-ensure.d.ts +24 -0
- package/dist/workflow-definition-ensure.js +75 -0
- package/dist/workflow-dispatch-service.d.ts +42 -0
- package/dist/workflow-dispatch-service.js +209 -0
- package/dist/workflow-dispatch-settlement.d.ts +29 -0
- package/dist/workflow-dispatch-settlement.js +140 -0
- package/dist/workflow-kind.d.ts +29 -1
- package/dist/workflow-kind.js +143 -139
- package/dist/workflow-probe-gate.d.ts +286 -0
- package/dist/workflow-probe-gate.js +382 -0
- package/dist/workflow-run-kind.d.ts +239 -32
- package/dist/workflow-run-kind.js +874 -188
- package/dist/workflow-run-reader.d.ts +1 -1
- package/dist/workflow-run-reader.js +3 -7
- package/dist/workflow-run-restore.d.ts +16 -0
- package/dist/workflow-run-restore.js +30 -0
- package/dist/workflow-source-closure.d.ts +35 -0
- package/dist/workflow-source-closure.js +342 -0
- package/dist/workflow-source-pins.d.ts +8 -0
- package/dist/workflow-source-pins.js +14 -0
- package/dist/ws/index.d.ts +3 -3
- package/dist/ws/index.js +2 -2
- package/dist/ws/pending-tracker.d.ts +93 -0
- package/dist/ws/pending-tracker.js +132 -0
- package/dist/ws/sidecar-events.d.ts +139 -37
- package/dist/ws/sidecar-events.js +2 -2
- package/dist/ws/sidecar-handler.d.ts +218 -60
- package/dist/ws/sidecar-handler.js +1713 -732
- package/dist/ws/sidecar-handler.test-helpers.d.ts +38 -0
- package/dist/ws/sidecar-handler.test-helpers.js +95 -0
- package/dist/ws/sidecar-token-authenticator.d.ts +3 -1
- package/dist/ws/sidecar-token-authenticator.js +78 -7
- package/package.json +14 -13
- package/dist/available-skills-stanza.d.ts +0 -21
- package/dist/available-skills-stanza.js +0 -32
|
@@ -22,7 +22,7 @@ export type WorkflowRunEvent = {
|
|
|
22
22
|
* path computation) with direct `isomorphic-git` tree/blob reads. It
|
|
23
23
|
* never writes, so it carries no authorize gate of its own; callers
|
|
24
24
|
* gate access at their own boundary (the REST routes use a
|
|
25
|
-
* `workflow-run:<
|
|
25
|
+
* `workflow-run:<runId>` grant check).
|
|
26
26
|
*/
|
|
27
27
|
export interface WorkflowRunReader {
|
|
28
28
|
/**
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import git from "isomorphic-git";
|
|
3
|
-
import { WORKFLOW_RUN_EVENTS_DIR, WORKFLOW_RUN_RUNS_PREFIX, } from "./workflow-run-kind.js";
|
|
3
|
+
import { requireEventSeq, WORKFLOW_RUN_EVENTS_DIR, WORKFLOW_RUN_RUNS_PREFIX, } from "./workflow-run-kind.js";
|
|
4
4
|
import { WORKFLOW_RUN_EVENTS_FILE, splitCombinedEventLog, } from "./workflow-run-event-log.js";
|
|
5
|
-
const EVENT_FILENAME_RE = /^(0|[1-9][0-9]*)\.json$/;
|
|
6
5
|
export function createWorkflowRunReader(repoStore) {
|
|
7
6
|
function repoDirOrNull(repoId) {
|
|
8
7
|
try {
|
|
@@ -106,12 +105,9 @@ export function createWorkflowRunReader(repoStore) {
|
|
|
106
105
|
for (const entry of tree.tree) {
|
|
107
106
|
if (entry.type !== "blob")
|
|
108
107
|
continue;
|
|
109
|
-
const m = EVENT_FILENAME_RE.exec(entry.path);
|
|
110
|
-
if (m === null || m[1] === undefined)
|
|
111
|
-
continue;
|
|
112
|
-
const seq = Number.parseInt(m[1], 10);
|
|
113
|
-
const blob = await git.readBlob({ fs, dir, oid: entry.oid });
|
|
114
108
|
const path = `${eventsDir}/${entry.path}`;
|
|
109
|
+
const seq = requireEventSeq(entry.path, path);
|
|
110
|
+
const blob = await git.readBlob({ fs, dir, oid: entry.oid });
|
|
115
111
|
const parsed = parseEventObject(new TextDecoder().decode(blob.blob), path);
|
|
116
112
|
const type = parsed["type"];
|
|
117
113
|
if (typeof type !== "string") {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgentRepoStore } from "./agent-repo.js";
|
|
2
|
+
import type { AllocatedSidecarTarget, SidecarAllocationRouter } from "./ws/sidecar-handler.js";
|
|
3
|
+
export declare const WORKFLOW_RUN_RESTORE_REFS: readonly ["refs/heads/main", "refs/heads/events"];
|
|
4
|
+
/**
|
|
5
|
+
* Replay every authoritative workflow-run ref the runtime understands onto an
|
|
6
|
+
* exact replacement allocation. Refs are sent sequentially and the function
|
|
7
|
+
* resolves only after the worker acknowledges each one, making it a barrier
|
|
8
|
+
* the deploy path can place before supervisor spawn.
|
|
9
|
+
*/
|
|
10
|
+
export declare function restoreWorkflowRunToAllocation(args: {
|
|
11
|
+
agentRepoStore: AgentRepoStore;
|
|
12
|
+
allocationRouter: Pick<SidecarAllocationRouter, "sendWorkflowRunPackToAllocation">;
|
|
13
|
+
allocationTarget: AllocatedSidecarTarget;
|
|
14
|
+
agentAddress: string;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { deriveWorkflowRunRepoId } from "@intx/workflow-deploy";
|
|
2
|
+
export const WORKFLOW_RUN_RESTORE_REFS = [
|
|
3
|
+
"refs/heads/main",
|
|
4
|
+
"refs/heads/events",
|
|
5
|
+
];
|
|
6
|
+
/**
|
|
7
|
+
* Replay every authoritative workflow-run ref the runtime understands onto an
|
|
8
|
+
* exact replacement allocation. Refs are sent sequentially and the function
|
|
9
|
+
* resolves only after the worker acknowledges each one, making it a barrier
|
|
10
|
+
* the deploy path can place before supervisor spawn.
|
|
11
|
+
*/
|
|
12
|
+
export async function restoreWorkflowRunToAllocation(args) {
|
|
13
|
+
const { agentRepoStore, allocationRouter, allocationTarget, agentAddress } = args;
|
|
14
|
+
const principal = { kind: "hub" };
|
|
15
|
+
const repoId = {
|
|
16
|
+
kind: "workflow-run",
|
|
17
|
+
id: deriveWorkflowRunRepoId(agentAddress),
|
|
18
|
+
};
|
|
19
|
+
for (const ref of WORKFLOW_RUN_RESTORE_REFS) {
|
|
20
|
+
args.signal?.throwIfAborted();
|
|
21
|
+
const tip = await agentRepoStore.repoStore.resolveRef(principal, repoId, ref);
|
|
22
|
+
args.signal?.throwIfAborted();
|
|
23
|
+
if (tip === null)
|
|
24
|
+
continue;
|
|
25
|
+
const pack = await agentRepoStore.repoStore.createPack(principal, repoId, ref);
|
|
26
|
+
args.signal?.throwIfAborted();
|
|
27
|
+
await allocationRouter.sendWorkflowRunPackToAllocation(allocationTarget, agentAddress, pack.pack, pack.ref, pack.commitSha, args.signal);
|
|
28
|
+
}
|
|
29
|
+
args.signal?.throwIfAborted();
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type PackumentFetcher, type RegistryConfig } from "@intx/tool-packaging";
|
|
2
|
+
import type { ToolPackageManifest } from "@intx/types/tool-packages";
|
|
3
|
+
import type { WorkflowDefinitionAssetSource } from "@intx/types/workflow-sources";
|
|
4
|
+
import type { CommittedTreeEntry } from "./repo-store/types.js";
|
|
5
|
+
/** Git-tree reads pinned to the source's commit. */
|
|
6
|
+
export interface SourceTreeReads {
|
|
7
|
+
readBlob(path: string): Promise<Uint8Array>;
|
|
8
|
+
listDir(path: string): Promise<CommittedTreeEntry[]>;
|
|
9
|
+
treeOid(path: string): Promise<string | null>;
|
|
10
|
+
}
|
|
11
|
+
export interface ResolveSourceWorkflowClosureArgs {
|
|
12
|
+
/** A source whose `package.format` is `"source"`. */
|
|
13
|
+
readonly source: WorkflowDefinitionAssetSource;
|
|
14
|
+
readonly reads: SourceTreeReads;
|
|
15
|
+
/**
|
|
16
|
+
* The registry name external deps are stamped with in the frozen closure.
|
|
17
|
+
* The sidecar resolves each entry's `source.registry` against its own
|
|
18
|
+
* registry map at materialization, so this MUST be a name that map is keyed
|
|
19
|
+
* by (the sidecar's npm registry, e.g. `"npmjs"`); an unknown name fails the
|
|
20
|
+
* materialization loud. The caller owns the sidecar's registry configuration,
|
|
21
|
+
* so it supplies the name here rather than the walk inventing one.
|
|
22
|
+
*/
|
|
23
|
+
readonly registryName: string;
|
|
24
|
+
/** URL and credentials for the npm registry external deps resolve against. */
|
|
25
|
+
readonly registryConfig: RegistryConfig;
|
|
26
|
+
/** Test seam for external packument fetches. */
|
|
27
|
+
readonly fetchPackument?: PackumentFetcher;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolve a source-format workflow definition's dependency closure to a frozen
|
|
31
|
+
* `ToolPackageManifest`: a `format:"source"` entry for the workflow package and
|
|
32
|
+
* each workspace-local dependency (identity = git tree oid), plus tarball
|
|
33
|
+
* entries for the external npm closure.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveSourceWorkflowClosure(args: ResolveSourceWorkflowClosureArgs): Promise<ToolPackageManifest>;
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// Hub-side dependency-closure resolution for a SOURCE-format workflow
|
|
2
|
+
// definition -- a codebase living as a subtree of a hub git asset at a
|
|
3
|
+
// pinned commit.
|
|
4
|
+
//
|
|
5
|
+
// Unlike the registry and tarball arms (which resolve against npm packuments
|
|
6
|
+
// with SRI integrity), a source package has no packument: its content
|
|
7
|
+
// identity is the git tree oid of its subtree, and its dependency closure is
|
|
8
|
+
// a DISJOINT UNION of two origins built by construction --
|
|
9
|
+
// - workspace-local members (other subtrees in the SAME asset) become
|
|
10
|
+
// `format:"source"` entries and are walked recursively, and
|
|
11
|
+
// - external npm dependencies are resolved through the pristine registry
|
|
12
|
+
// walker (which keeps its SRI invariant intact) into tarball entries.
|
|
13
|
+
// A member name never appears in the external set, so the two origins cannot
|
|
14
|
+
// collide on a workspace member; the one residual collision (an external
|
|
15
|
+
// transitive dep whose `name@version` equals a member's) is detected and
|
|
16
|
+
// fails loud rather than silently picking an origin.
|
|
17
|
+
import { HttpRegistrySource, createClosureResolver, } from "@intx/tool-packaging";
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a source-format workflow definition's dependency closure to a frozen
|
|
20
|
+
* `ToolPackageManifest`: a `format:"source"` entry for the workflow package and
|
|
21
|
+
* each workspace-local dependency (identity = git tree oid), plus tarball
|
|
22
|
+
* entries for the external npm closure.
|
|
23
|
+
*/
|
|
24
|
+
export async function resolveSourceWorkflowClosure(args) {
|
|
25
|
+
const { source, reads, registryName, registryConfig, fetchPackument } = args;
|
|
26
|
+
if (source.package.format !== "source") {
|
|
27
|
+
throw new Error("resolveSourceWorkflowClosure: source.package.format must be 'source'");
|
|
28
|
+
}
|
|
29
|
+
const { commitSha, packageName } = source.package;
|
|
30
|
+
const assetId = source.assetId;
|
|
31
|
+
const { members, rootName, catalog } = await enumerateMembers(reads);
|
|
32
|
+
const selected = selectMember(members, packageName);
|
|
33
|
+
// BFS over the reachable workspace members. A dependency classifies by NAME,
|
|
34
|
+
// never by parsing its range: a name that is a member recurses (a
|
|
35
|
+
// workspace-local edge); the workspace root's own name is an invalid target
|
|
36
|
+
// (the root is not a member) and fails loud regardless of how the range is
|
|
37
|
+
// spelled; anything else is external and resolves through the registry walker.
|
|
38
|
+
//
|
|
39
|
+
// External deps collect by name, and a second member contributing the same
|
|
40
|
+
// name at a DIFFERENT resolved range fails loud rather than silently
|
|
41
|
+
// collapsing to one pin -- the walker resolves a single range per name, so a
|
|
42
|
+
// silent overwrite would drop a real constraint. This is a DELIBERATE v1
|
|
43
|
+
// limitation: two members with drifting-but-compatible ranges (e.g. `^1.0.0`
|
|
44
|
+
// and `^1.2.0`) that npm/bun would reconcile to one version are rejected here,
|
|
45
|
+
// not intersected. Aligning the ranges across members, or declaring the dep
|
|
46
|
+
// once in the root `catalog`, resolves it. (Semver intersection across
|
|
47
|
+
// members is tracked separately as INTR-460.)
|
|
48
|
+
const sourceEntries = [];
|
|
49
|
+
const externalPins = new Map();
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
const queue = [selected.name];
|
|
52
|
+
while (queue.length > 0) {
|
|
53
|
+
const memberName = queue.shift();
|
|
54
|
+
if (memberName === undefined || seen.has(memberName))
|
|
55
|
+
continue;
|
|
56
|
+
seen.add(memberName);
|
|
57
|
+
const member = members.get(memberName);
|
|
58
|
+
if (member === undefined) {
|
|
59
|
+
throw new Error(`resolveSourceWorkflowClosure: internal -- member ${JSON.stringify(memberName)} was queued but not enumerated`);
|
|
60
|
+
}
|
|
61
|
+
const treeOid = await reads.treeOid(member.packageDir);
|
|
62
|
+
if (treeOid === null) {
|
|
63
|
+
throw new Error(`resolveSourceWorkflowClosure: subtree ${JSON.stringify(member.packageDir)} not found at commit ${commitSha}`);
|
|
64
|
+
}
|
|
65
|
+
sourceEntries.push({
|
|
66
|
+
name: member.name,
|
|
67
|
+
version: member.version,
|
|
68
|
+
source: {
|
|
69
|
+
kind: "asset",
|
|
70
|
+
assetId,
|
|
71
|
+
package: {
|
|
72
|
+
format: "source",
|
|
73
|
+
commitSha,
|
|
74
|
+
packageDir: member.packageDir,
|
|
75
|
+
treeOid,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
for (const [depName, depSpec] of Object.entries(member.dependencies)) {
|
|
80
|
+
if (members.has(depName)) {
|
|
81
|
+
queue.push(depName);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (rootName !== undefined && depName === rootName) {
|
|
85
|
+
throw new Error(`resolveSourceWorkflowClosure: member ${JSON.stringify(member.name)} depends on the workspace root ${JSON.stringify(rootName)}, which is not a workspace member`);
|
|
86
|
+
}
|
|
87
|
+
const resolvedSpec = resolveExternalSpec(depName, depSpec, catalog);
|
|
88
|
+
const existing = externalPins.get(depName);
|
|
89
|
+
if (existing !== undefined && existing !== resolvedSpec) {
|
|
90
|
+
throw new Error(`resolveSourceWorkflowClosure: workspace members pin external ${JSON.stringify(depName)} at conflicting ranges ${JSON.stringify(existing)} and ${JSON.stringify(resolvedSpec)}; the closure resolves a single range per name`);
|
|
91
|
+
}
|
|
92
|
+
externalPins.set(depName, resolvedSpec);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const externalEntries = externalPins.size > 0
|
|
96
|
+
? await resolveExternalClosure(externalPins, registryName, registryConfig, fetchPackument)
|
|
97
|
+
: [];
|
|
98
|
+
return {
|
|
99
|
+
schemaVersion: "1",
|
|
100
|
+
topLevel: [{ name: selected.name, version: selected.version }],
|
|
101
|
+
entries: mergeDisjoint(sourceEntries, externalEntries),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Read the workspace members from the asset's tree. A repo with no
|
|
106
|
+
* `workspaces` field is a single package rooted at the tree (the root IS the
|
|
107
|
+
* one member). A `workspaces` monorepo enumerates its members from the globs;
|
|
108
|
+
* the root is the workspace root, NOT a member -- its `name`/`catalog` inform
|
|
109
|
+
* dependency classification but it contributes no closure entry.
|
|
110
|
+
*/
|
|
111
|
+
async function enumerateMembers(reads) {
|
|
112
|
+
const root = await readPackageJSON(reads, ".");
|
|
113
|
+
if (root.workspaces === undefined) {
|
|
114
|
+
// A pnpm monorepo declares its members in `pnpm-workspace.yaml`, not the
|
|
115
|
+
// package.json `workspaces` field, so a pnpm root reaches here looking like
|
|
116
|
+
// a single package. Detect that layout and fail loud rather than silently
|
|
117
|
+
// misread the private root as the workflow. Full pnpm support is tracked in
|
|
118
|
+
// INTR-461.
|
|
119
|
+
if (await rootHasPnpmWorkspaceFile(reads)) {
|
|
120
|
+
throw new Error(`resolveSourceWorkflowClosure: the asset root declares a pnpm-workspace.yaml; the pnpm workspace layout is not supported -- declare members via a package.json "workspaces" array`);
|
|
121
|
+
}
|
|
122
|
+
// Single-package: the root is the workflow package itself, so it must
|
|
123
|
+
// declare a name and version.
|
|
124
|
+
const member = requireMember(root, ".");
|
|
125
|
+
return {
|
|
126
|
+
members: new Map([[member.name, member]]),
|
|
127
|
+
rootName: root.name,
|
|
128
|
+
catalog: root.catalog,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const members = new Map();
|
|
132
|
+
for (const glob of root.workspaces) {
|
|
133
|
+
for (const packageDir of await expandWorkspaceGlob(reads, glob)) {
|
|
134
|
+
// A `<dir>/*` glob matches every subdirectory, but not all are packages
|
|
135
|
+
// (docs, fixtures, ...). Skip a directory with no package.json rather than
|
|
136
|
+
// fail the whole resolution, matching how bun/yarn/pnpm treat a
|
|
137
|
+
// non-package directory that a workspace glob happens to match. A
|
|
138
|
+
// directory that HAS a package.json must still parse and declare a name
|
|
139
|
+
// and version, so a malformed member fails loud.
|
|
140
|
+
if (!(await dirHasPackageJSON(reads, packageDir)))
|
|
141
|
+
continue;
|
|
142
|
+
const parsed = await readPackageJSON(reads, packageDir);
|
|
143
|
+
const member = requireMember(parsed, packageDir);
|
|
144
|
+
if (members.has(member.name)) {
|
|
145
|
+
throw new Error(`resolveSourceWorkflowClosure: workspace member ${JSON.stringify(member.name)} is declared by more than one package directory`);
|
|
146
|
+
}
|
|
147
|
+
members.set(member.name, member);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (members.size === 0) {
|
|
151
|
+
throw new Error(`resolveSourceWorkflowClosure: workspaces ${JSON.stringify(root.workspaces)} matched no member packages`);
|
|
152
|
+
}
|
|
153
|
+
return { members, rootName: root.name, catalog: root.catalog };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Turn a parsed package.json at `packageDir` into a workspace member, failing
|
|
157
|
+
* loud if it does not declare both a string `name` and `version` (the closure
|
|
158
|
+
* entry it produces is keyed on `name@version`).
|
|
159
|
+
*/
|
|
160
|
+
function requireMember(parsed, packageDir) {
|
|
161
|
+
if (parsed.name === undefined || parsed.version === undefined) {
|
|
162
|
+
const blobPath = packageDir === "." ? "package.json" : `${packageDir}/package.json`;
|
|
163
|
+
throw new Error(`resolveSourceWorkflowClosure: ${blobPath} must declare string "name" and "version"`);
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
name: parsed.name,
|
|
167
|
+
version: parsed.version,
|
|
168
|
+
packageDir,
|
|
169
|
+
dependencies: parsed.dependencies,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Expand one `workspaces` glob to the member directories it names. Supports
|
|
174
|
+
* `<base>/*` (each subtree directly under `<base>`) and an exact path (no glob
|
|
175
|
+
* character). Any richer shape (`**`, a mid-segment `*`, braces, negation)
|
|
176
|
+
* fails loud rather than risk mis-enumerating the workspace.
|
|
177
|
+
*/
|
|
178
|
+
async function expandWorkspaceGlob(reads, glob) {
|
|
179
|
+
const trimmed = glob.replace(/\/+$/, "");
|
|
180
|
+
if (!/[*{}!]/.test(trimmed)) {
|
|
181
|
+
return [trimmed];
|
|
182
|
+
}
|
|
183
|
+
const suffix = "/*";
|
|
184
|
+
const base = trimmed.slice(0, -suffix.length);
|
|
185
|
+
if (trimmed.endsWith(suffix) && !/[*{}!]/.test(base)) {
|
|
186
|
+
const children = await reads.listDir(base === "" ? "." : base);
|
|
187
|
+
return children
|
|
188
|
+
.filter((child) => child.type === "tree")
|
|
189
|
+
.map((child) => (base === "" ? child.name : `${base}/${child.name}`));
|
|
190
|
+
}
|
|
191
|
+
throw new Error(`resolveSourceWorkflowClosure: unsupported workspaces glob ${JSON.stringify(glob)}; only "<dir>/*" and exact paths are supported`);
|
|
192
|
+
}
|
|
193
|
+
/** Whether `dir` holds a `package.json` blob (i.e. is a package directory). */
|
|
194
|
+
async function dirHasPackageJSON(reads, dir) {
|
|
195
|
+
const entries = await reads.listDir(dir);
|
|
196
|
+
return entries.some((entry) => entry.name === "package.json" && entry.type === "blob");
|
|
197
|
+
}
|
|
198
|
+
/** Whether the tree root holds a `pnpm-workspace.yaml` blob (the pnpm layout). */
|
|
199
|
+
async function rootHasPnpmWorkspaceFile(reads) {
|
|
200
|
+
const entries = await reads.listDir(".");
|
|
201
|
+
return entries.some((entry) => entry.name === "pnpm-workspace.yaml" && entry.type === "blob");
|
|
202
|
+
}
|
|
203
|
+
function selectMember(members, packageName) {
|
|
204
|
+
if (packageName !== undefined) {
|
|
205
|
+
const member = members.get(packageName);
|
|
206
|
+
if (member === undefined) {
|
|
207
|
+
throw new Error(`resolveSourceWorkflowClosure: workflow member ${JSON.stringify(packageName)} is not a workspace member`);
|
|
208
|
+
}
|
|
209
|
+
return member;
|
|
210
|
+
}
|
|
211
|
+
if (members.size !== 1) {
|
|
212
|
+
throw new Error("resolveSourceWorkflowClosure: a monorepo source requires a packageName selector");
|
|
213
|
+
}
|
|
214
|
+
const [only] = members.values();
|
|
215
|
+
if (only === undefined) {
|
|
216
|
+
throw new Error("resolveSourceWorkflowClosure: internal -- no members");
|
|
217
|
+
}
|
|
218
|
+
return only;
|
|
219
|
+
}
|
|
220
|
+
async function readPackageJSON(reads, packageDir) {
|
|
221
|
+
const blobPath = packageDir === "." ? "package.json" : `${packageDir}/package.json`;
|
|
222
|
+
let bytes;
|
|
223
|
+
try {
|
|
224
|
+
bytes = await reads.readBlob(blobPath);
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
throw new Error(`resolveSourceWorkflowClosure: could not read ${blobPath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
228
|
+
}
|
|
229
|
+
let raw;
|
|
230
|
+
try {
|
|
231
|
+
raw = JSON.parse(new TextDecoder().decode(bytes));
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
throw new Error(`resolveSourceWorkflowClosure: ${blobPath} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
235
|
+
}
|
|
236
|
+
if (!isRecord(raw)) {
|
|
237
|
+
throw new Error(`resolveSourceWorkflowClosure: ${blobPath} is not an object`);
|
|
238
|
+
}
|
|
239
|
+
// `name`/`version` are optional here: a private workspace root routinely
|
|
240
|
+
// omits them. A member that omits either fails loud where it is turned into a
|
|
241
|
+
// WorkspaceMember (`requireMember`), not here.
|
|
242
|
+
const nameRaw = raw["name"];
|
|
243
|
+
const versionRaw = raw["version"];
|
|
244
|
+
const name = typeof nameRaw === "string" ? nameRaw : undefined;
|
|
245
|
+
const version = typeof versionRaw === "string" ? versionRaw : undefined;
|
|
246
|
+
const depsRaw = raw["dependencies"];
|
|
247
|
+
const dependencies = {};
|
|
248
|
+
if (isRecord(depsRaw)) {
|
|
249
|
+
for (const [k, v] of Object.entries(depsRaw)) {
|
|
250
|
+
if (typeof v === "string")
|
|
251
|
+
dependencies[k] = v;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const workspacesRaw = raw["workspaces"];
|
|
255
|
+
let workspaces;
|
|
256
|
+
if (workspacesRaw === undefined) {
|
|
257
|
+
workspaces = undefined;
|
|
258
|
+
}
|
|
259
|
+
else if (Array.isArray(workspacesRaw) &&
|
|
260
|
+
workspacesRaw.every((w) => typeof w === "string")) {
|
|
261
|
+
workspaces = workspacesRaw;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
throw new Error(`resolveSourceWorkflowClosure: ${blobPath} "workspaces" must be an array of glob strings; the object form ({ packages, catalog, catalogs }) is not supported`);
|
|
265
|
+
}
|
|
266
|
+
const catalogRaw = raw["catalog"];
|
|
267
|
+
let catalog;
|
|
268
|
+
if (isRecord(catalogRaw)) {
|
|
269
|
+
catalog = {};
|
|
270
|
+
for (const [k, v] of Object.entries(catalogRaw)) {
|
|
271
|
+
if (typeof v === "string")
|
|
272
|
+
catalog[k] = v;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return { name, version, dependencies, workspaces, catalog };
|
|
276
|
+
}
|
|
277
|
+
function isRecord(value) {
|
|
278
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Translate an EXTERNAL dependency specifier (one whose name is not a workspace
|
|
282
|
+
* member) to a concrete npm range the registry walker can pick against:
|
|
283
|
+
* - `workspace:` protocol -- the name is not a member, so this is an invalid
|
|
284
|
+
* workspace reference; fail loud.
|
|
285
|
+
* - bare `catalog:` -- expand against the root `catalog` object; fail loud if
|
|
286
|
+
* the catalog declares no entry for this name.
|
|
287
|
+
* - named `catalog:<name>` -- not supported; fail loud.
|
|
288
|
+
* - plain range -- pass through.
|
|
289
|
+
*/
|
|
290
|
+
function resolveExternalSpec(depName, spec, catalog) {
|
|
291
|
+
if (spec.startsWith("workspace:")) {
|
|
292
|
+
throw new Error(`resolveSourceWorkflowClosure: ${depName} uses ${JSON.stringify(spec)} but is not a workspace member`);
|
|
293
|
+
}
|
|
294
|
+
if (spec === "catalog:") {
|
|
295
|
+
const range = catalog?.[depName];
|
|
296
|
+
if (range === undefined) {
|
|
297
|
+
throw new Error(`resolveSourceWorkflowClosure: ${depName} uses the default catalog but the workspace root declares no "catalog" entry for it`);
|
|
298
|
+
}
|
|
299
|
+
return range;
|
|
300
|
+
}
|
|
301
|
+
if (spec.startsWith("catalog:")) {
|
|
302
|
+
throw new Error(`resolveSourceWorkflowClosure: ${depName} uses named catalog ${JSON.stringify(spec)}, which is not supported`);
|
|
303
|
+
}
|
|
304
|
+
return spec;
|
|
305
|
+
}
|
|
306
|
+
async function resolveExternalClosure(pins, registryName, registryConfig, fetchPackument) {
|
|
307
|
+
const registrySource = new HttpRegistrySource({
|
|
308
|
+
name: registryName,
|
|
309
|
+
config: registryConfig,
|
|
310
|
+
...(fetchPackument !== undefined ? { fetchPackument } : {}),
|
|
311
|
+
});
|
|
312
|
+
const resolver = createClosureResolver({
|
|
313
|
+
registries: new Map([[registryName, registrySource]]),
|
|
314
|
+
defaultRegistry: registryName,
|
|
315
|
+
});
|
|
316
|
+
const rootPins = [...pins].map(([name, version]) => ({
|
|
317
|
+
name,
|
|
318
|
+
version,
|
|
319
|
+
}));
|
|
320
|
+
const manifest = await resolver.resolveClosure(rootPins);
|
|
321
|
+
return [...manifest.entries];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Union the source and external entries, deduped on `name@version`. A key that
|
|
325
|
+
* appears in BOTH origins is an unrepresentable collision (the manifest keys on
|
|
326
|
+
* `name@version` with neither treeOid nor SRI participating), so fail loud
|
|
327
|
+
* rather than silently picking one origin.
|
|
328
|
+
*/
|
|
329
|
+
function mergeDisjoint(sourceEntries, externalEntries) {
|
|
330
|
+
const byKey = new Map();
|
|
331
|
+
for (const entry of sourceEntries) {
|
|
332
|
+
byKey.set(`${entry.name}@${entry.version}`, entry);
|
|
333
|
+
}
|
|
334
|
+
for (const entry of externalEntries) {
|
|
335
|
+
const key = `${entry.name}@${entry.version}`;
|
|
336
|
+
if (byKey.has(key)) {
|
|
337
|
+
throw new Error(`resolveSourceWorkflowClosure: ${key} resolved from both a workspace member and an external registry; the closure cannot represent both origins`);
|
|
338
|
+
}
|
|
339
|
+
byKey.set(key, entry);
|
|
340
|
+
}
|
|
341
|
+
return [...byKey.values()];
|
|
342
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WorkflowProjectionWithSources } from "@intx/types/sidecar";
|
|
2
|
+
import type { HarnessConfig } from "@intx/types/runtime";
|
|
3
|
+
import { type ApprovalSet } from "@intx/workflow-deploy";
|
|
4
|
+
export declare function buildReferencedWorkflowSourcePins(args: {
|
|
5
|
+
projection: WorkflowProjectionWithSources["definition"];
|
|
6
|
+
config: HarnessConfig;
|
|
7
|
+
operatorApprovals: ApprovalSet;
|
|
8
|
+
}): Promise<readonly WorkflowProjectionWithSources[]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { computeWireDefinitionHash } from "@intx/types/wire-definition-hash";
|
|
2
|
+
import { buildInertBodyStepSources, enumerateInertBodies, } from "@intx/workflow-deploy";
|
|
3
|
+
export async function buildReferencedWorkflowSourcePins(args) {
|
|
4
|
+
return Promise.all(enumerateInertBodies(args.projection).map(async (body) => ({
|
|
5
|
+
definition: body.definition,
|
|
6
|
+
sources: buildInertBodyStepSources({
|
|
7
|
+
definition: body.definition,
|
|
8
|
+
workflowId: body.ref,
|
|
9
|
+
config: args.config,
|
|
10
|
+
operatorApprovals: args.operatorApprovals,
|
|
11
|
+
}),
|
|
12
|
+
approvedWireHash: await computeWireDefinitionHash(body.definition),
|
|
13
|
+
})));
|
|
14
|
+
}
|
package/dist/ws/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createSidecarRouter, type SidecarRouter, type SidecarRouterConfig, type SidecarConnection, type SidecarAuthIdentity, type SidecarAuthenticator, type SendPackOptions, type WsHandle, } from "./sidecar-handler.js";
|
|
2
|
-
export { createSidecarTokenAuthenticator, type CreateSidecarTokenAuthenticatorDeps, } from "./sidecar-token-authenticator.js";
|
|
3
|
-
export { createSidecarEmitter, type SidecarEventEmitter, type SidecarEventMap, type SidecarEventType, type SidecarEventListener, type SidecarLookups, type SidecarMailPersistedRow, type SidecarMailPersistedPayload, } from "./sidecar-events.js";
|
|
1
|
+
export { createSidecarRouter, SidecarIdentityValidationError, type SidecarRouter, type SidecarRouterConfig, type SenderDeploySettledOutcome, type AllocatedSenderDeployAttempt, type SidecarConnection, type SidecarAuthIdentity, type SidecarAuthenticator, type AllocatedSidecarTarget, type SidecarAllocationRouter, type SendPackOptions, type WsHandle, } from "./sidecar-handler.js";
|
|
2
|
+
export { createSidecarCredentialResolver, createSidecarTokenAuthenticator, type CreateSidecarTokenAuthenticatorDeps, } from "./sidecar-token-authenticator.js";
|
|
3
|
+
export { createSidecarEmitter, type SidecarEventEmitter, type SidecarEventMap, type SidecarEventType, type SidecarEventListener, type SidecarLookups, type SidecarMailPersistedRow, type SidecarMailPersistedPayload, type MailTriggeredRunGrantsResult, type WorkflowRunPackSource, } from "./sidecar-events.js";
|
package/dist/ws/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createSidecarRouter, } from "./sidecar-handler.js";
|
|
2
|
-
export { createSidecarTokenAuthenticator, } from "./sidecar-token-authenticator.js";
|
|
1
|
+
export { createSidecarRouter, SidecarIdentityValidationError, } from "./sidecar-handler.js";
|
|
2
|
+
export { createSidecarCredentialResolver, createSidecarTokenAuthenticator, } from "./sidecar-token-authenticator.js";
|
|
3
3
|
export { createSidecarEmitter, } from "./sidecar-events.js";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export type WsHandle = {
|
|
2
|
+
send(data: string): void;
|
|
3
|
+
close(): void;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Arms a one-shot timeout and returns the canceller for it.
|
|
7
|
+
*
|
|
8
|
+
* The tracker's timeouts are the only thing about it that depends on time
|
|
9
|
+
* passing, and a caller that wants them settled on demand rather than by
|
|
10
|
+
* waiting has nowhere to reach in: the global timer is not addressable from
|
|
11
|
+
* outside. Injecting the arming function makes the timeout observable and
|
|
12
|
+
* cancellable by whoever owns the tracker, so a test can fire a timeout, or
|
|
13
|
+
* assert one was disarmed, without a real duration elapsing.
|
|
14
|
+
*
|
|
15
|
+
* Returning the canceller rather than a handle keeps the timer's identity
|
|
16
|
+
* private to whichever implementation armed it.
|
|
17
|
+
*/
|
|
18
|
+
export type ScheduleTimeout = (handler: () => void, ms: number) => () => void;
|
|
19
|
+
export type PendingEntry<Key, Value, Meta> = {
|
|
20
|
+
key: Key;
|
|
21
|
+
ws: WsHandle;
|
|
22
|
+
/**
|
|
23
|
+
* Opaque per-entry payload for settle-time ownership checks. The pack
|
|
24
|
+
* tracker stores the send-site `{ agentAddress, repoId }` so an ack/reject
|
|
25
|
+
* is honored only when it comes from the connection that owns the transfer
|
|
26
|
+
* for the same repo; the other trackers pass `undefined`.
|
|
27
|
+
*/
|
|
28
|
+
meta: Meta;
|
|
29
|
+
resolve(value: Value): void;
|
|
30
|
+
reject(error: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Disarms this entry's timeout.
|
|
33
|
+
*
|
|
34
|
+
* Runs at most once per entry, which is why it need not be idempotent and
|
|
35
|
+
* `ScheduleTimeout` does not ask its implementations for that: each of the
|
|
36
|
+
* four settle paths cancels and drops the entry from the map in one
|
|
37
|
+
* synchronous block, and a timeout that fires drops the entry itself, so
|
|
38
|
+
* nothing can reach the entry to cancel it a second time.
|
|
39
|
+
*/
|
|
40
|
+
cancelTimeout(): void;
|
|
41
|
+
};
|
|
42
|
+
export declare class PendingTracker<Key, Value = void, Meta = undefined> {
|
|
43
|
+
private readonly schedule;
|
|
44
|
+
private readonly entries;
|
|
45
|
+
/**
|
|
46
|
+
* `schedule` defaults to the global timer, which is what every production
|
|
47
|
+
* caller wants; it is injectable so a caller can drive the timeouts.
|
|
48
|
+
*/
|
|
49
|
+
constructor(schedule?: ScheduleTimeout);
|
|
50
|
+
/**
|
|
51
|
+
* Register a pending round-trip and arm its timeout. The entry is stored
|
|
52
|
+
* before the caller sends its frame, so a synchronous reply (loopback
|
|
53
|
+
* transports, tests) settles it. When `timeoutMs` elapses the entry is
|
|
54
|
+
* dropped and `reject` is invoked with `timeoutMessage` — the same
|
|
55
|
+
* rejection path an error reply frame uses, so per-site cleanup (routing
|
|
56
|
+
* rollback, address bookkeeping) runs exactly once either way.
|
|
57
|
+
*
|
|
58
|
+
* `meta` is the opaque per-entry payload settle-time ownership checks read
|
|
59
|
+
* off `get`; pass `undefined` when the round-trip carries none.
|
|
60
|
+
*/
|
|
61
|
+
register(key: Key, ws: WsHandle, options: {
|
|
62
|
+
timeoutMs: number;
|
|
63
|
+
timeoutMessage: string;
|
|
64
|
+
resolve(value: Value): void;
|
|
65
|
+
reject(error: string): void;
|
|
66
|
+
}, meta: Meta): void;
|
|
67
|
+
has(key: Key): boolean;
|
|
68
|
+
get(key: Key): PendingEntry<Key, Value, Meta> | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Settle a pending entry as resolved. No-op when the entry is already
|
|
71
|
+
* gone (timed out or swept on disconnect).
|
|
72
|
+
*/
|
|
73
|
+
resolve(key: Key, value: Value): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Settle a pending entry as rejected. No-op when the entry is already
|
|
76
|
+
* gone (timed out or swept on disconnect).
|
|
77
|
+
*/
|
|
78
|
+
reject(key: Key, error: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Drop a pending entry without settling it. The caller rejects its own
|
|
81
|
+
* promise directly — used when a frame provably never reached the wire, so
|
|
82
|
+
* the failure must not take the normal rejection path (the deploy
|
|
83
|
+
* "failed to send" path, which must report `frameSent: false` and must not
|
|
84
|
+
* let the armed timer fire later and double-reject).
|
|
85
|
+
*/
|
|
86
|
+
delete(key: Key): void;
|
|
87
|
+
/**
|
|
88
|
+
* Reject every pending entry owned by `ws` — the disconnect sweep. Each
|
|
89
|
+
* entry's reject closure runs its own per-site cleanup (address
|
|
90
|
+
* bookkeeping), identical to a frame-error rejection.
|
|
91
|
+
*/
|
|
92
|
+
rejectAllForWs(ws: WsHandle, error: string): void;
|
|
93
|
+
}
|