@intx/hub-sessions 0.2.2 → 0.3.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 (73) hide show
  1. package/README.md +3 -5
  2. package/dist/agent-repo.d.ts +9 -5
  3. package/dist/agent-repo.js +2 -2
  4. package/dist/agent-state-kind.js +4 -0
  5. package/dist/asset-service.d.ts +1 -20
  6. package/dist/asset-service.js +9 -91
  7. package/dist/committed-source-tree.d.ts +10 -0
  8. package/dist/committed-source-tree.js +35 -0
  9. package/dist/credential-push.d.ts +7 -6
  10. package/dist/credential-push.js +42 -18
  11. package/dist/event-collector-registry.d.ts +1 -1
  12. package/dist/event-collector-registry.js +4 -4
  13. package/dist/event-collector.d.ts +1 -1
  14. package/dist/event-collector.js +10 -2
  15. package/dist/hub-session-lookups.d.ts +125 -7
  16. package/dist/hub-session-lookups.js +539 -80
  17. package/dist/hub-session-orchestrator.js +14 -49
  18. package/dist/index.d.ts +17 -8
  19. package/dist/index.js +14 -6
  20. package/dist/repo-store/index.d.ts +1 -1
  21. package/dist/repo-store/store.d.ts +1 -1
  22. package/dist/repo-store/store.js +138 -1
  23. package/dist/repo-store/subscribe-kind.d.ts +6 -3
  24. package/dist/repo-store/subscribe-kind.js +42 -77
  25. package/dist/repo-store/types.d.ts +94 -6
  26. package/dist/session-service.d.ts +277 -96
  27. package/dist/session-service.js +741 -547
  28. package/dist/sidecar-allocation/contracts.d.ts +78 -0
  29. package/dist/sidecar-allocation/contracts.js +21 -0
  30. package/dist/sidecar-allocation/index.d.ts +4 -0
  31. package/dist/sidecar-allocation/index.js +3 -0
  32. package/dist/sidecar-allocation/placement-policy.d.ts +11 -0
  33. package/dist/sidecar-allocation/placement-policy.js +21 -0
  34. package/dist/sidecar-allocation/plugin-registry.d.ts +11 -0
  35. package/dist/sidecar-allocation/plugin-registry.js +37 -0
  36. package/dist/sidecar-allocation/reconciler.d.ts +42 -0
  37. package/dist/sidecar-allocation/reconciler.js +431 -0
  38. package/dist/skill-kind.js +4 -0
  39. package/dist/substrate.d.ts +3 -3
  40. package/dist/substrate.js +1 -1
  41. package/dist/workflow-allocation-service.d.ts +58 -0
  42. package/dist/workflow-allocation-service.js +239 -0
  43. package/dist/workflow-closure-resolution.d.ts +106 -0
  44. package/dist/workflow-closure-resolution.js +123 -0
  45. package/dist/workflow-definition-ensure.d.ts +24 -0
  46. package/dist/workflow-definition-ensure.js +75 -0
  47. package/dist/workflow-dispatch-service.d.ts +40 -0
  48. package/dist/workflow-dispatch-service.js +146 -0
  49. package/dist/workflow-dispatch-settlement.d.ts +29 -0
  50. package/dist/workflow-dispatch-settlement.js +140 -0
  51. package/dist/workflow-kind.d.ts +17 -1
  52. package/dist/workflow-kind.js +127 -80
  53. package/dist/workflow-probe-gate.d.ts +214 -0
  54. package/dist/workflow-probe-gate.js +207 -0
  55. package/dist/workflow-run-kind.d.ts +128 -14
  56. package/dist/workflow-run-kind.js +353 -83
  57. package/dist/workflow-run-reader.d.ts +1 -1
  58. package/dist/workflow-run-reader.js +3 -7
  59. package/dist/workflow-run-restore.d.ts +15 -0
  60. package/dist/workflow-run-restore.js +26 -0
  61. package/dist/workflow-source-closure.d.ts +35 -0
  62. package/dist/workflow-source-closure.js +342 -0
  63. package/dist/ws/index.d.ts +3 -3
  64. package/dist/ws/index.js +1 -1
  65. package/dist/ws/sidecar-events.d.ts +100 -12
  66. package/dist/ws/sidecar-events.js +2 -0
  67. package/dist/ws/sidecar-handler.d.ts +128 -7
  68. package/dist/ws/sidecar-handler.js +1069 -135
  69. package/dist/ws/sidecar-token-authenticator.d.ts +3 -1
  70. package/dist/ws/sidecar-token-authenticator.js +64 -7
  71. package/package.json +14 -13
  72. package/dist/available-skills-stanza.d.ts +0 -21
  73. package/dist/available-skills-stanza.js +0 -32
@@ -1,8 +1,13 @@
1
- import { type AgentDeployFrame, type HubFrame, type RepoId } from "@intx/types/sidecar";
1
+ import type { GrantWalkSnapshot } from "@intx/types";
2
+ import { type AgentDeployFrame, type HubFrame, type RepoId, type RunGrantsFrame, type CredentialDelivery, type WorkflowSourceAssetMount, type WorkflowProjectionDefinition } from "@intx/types/sidecar";
2
3
  import type { ConnectorThreadState, HarnessConfig, InferenceSource } from "@intx/types/runtime";
4
+ import type { SidecarCredentialIdentity } from "../sidecar-allocation/contracts.js";
5
+ import type { ToolPackageManifest } from "@intx/types/tool-packages";
6
+ import type { WorkflowDefinitionSource } from "@intx/types/workflow-sources";
3
7
  import { type SidecarEventEmitter, type SidecarLookups } from "./sidecar-events.js";
4
8
  export type SidecarConnection = {
5
9
  sidecarId: string;
10
+ identity: SidecarAuthIdentity;
6
11
  agentAddresses: Set<string>;
7
12
  workflowAddresses: Set<string>;
8
13
  send(frame: HubFrame): void;
@@ -20,15 +25,59 @@ export type SendPackOptions = {
20
25
  * Override the `repoId` emitted on the wire. The agent-state flow
21
26
  * defaults to `{ kind: "agent-state", id: agentAddress }`; asset
22
27
  * packs must pass the SOURCE asset's id so audit can correlate the
23
- * pack back to its hub-side origin.
28
+ * pack back to its hub-side origin. Workflow-run restoration uses a
29
+ * dedicated allocation-bound sender that supplies its derived repo id.
24
30
  */
25
31
  repoId?: RepoId;
26
32
  };
33
+ /**
34
+ * Everything a `sendProbe` caller supplies to populate the outbound
35
+ * `workflow.probe.request` frame: where the definition's bytes come from, the
36
+ * frozen dependency closure the hub already resolved, and the
37
+ * `interchange.workflow` entry-module path whose evaluation produces the
38
+ * `WorkflowDefinition`. The `requestId` is minted inside `sendProbe`, not
39
+ * supplied here.
40
+ */
41
+ export type SendProbeArgs = {
42
+ source: WorkflowDefinitionSource;
43
+ closure: ToolPackageManifest;
44
+ entry: string;
45
+ /** Hub assets a `kind:"asset"` closure entry reads from, delivered inline. */
46
+ assets?: WorkflowSourceAssetMount[];
47
+ };
48
+ /**
49
+ * The payload a `sendProbe` promise resolves with, lifted off the sidecar's
50
+ * `workflow.probe.result` frame: the inert needs-surface projection of the
51
+ * probed workflow, the inert grant set derived from it, the un-flattened grant
52
+ * walk snapshot the set is derived from, and the projection's content hash.
53
+ */
54
+ export type WorkflowProbeResult = {
55
+ projection: WorkflowProjectionDefinition;
56
+ grants: string[];
57
+ grantWalkSnapshot: GrantWalkSnapshot;
58
+ wireHash: string;
59
+ };
27
60
  export type SidecarRouter = {
28
61
  handleOpen(ws: WsHandle): void;
29
62
  handleMessage(ws: WsHandle, data: string): void;
30
63
  handleClose(ws: WsHandle): void;
31
- routeMail(agentAddress: string, rawMessage: string): boolean;
64
+ routeMail(agentAddress: string, rawMessage: string, messageId?: string): boolean;
65
+ /**
66
+ * Deliver a run's authorization grants to the sidecar hosting the named
67
+ * deployment-level mail address, ahead of the trigger mail that starts the
68
+ * run. Routes through the same per-address channel as `routeMail`: over the
69
+ * live connection when the deployment is connected, and into the disconnect
70
+ * queue when the deployment dropped in the window before its first
71
+ * reconnect (while its address is still on `agentAddresses`) -- so grants
72
+ * are queued for a disconnected deployment exactly when the trigger mail is,
73
+ * and ride the same reconnect flush. After a challenged reconnect the
74
+ * address moves to `workflowAddresses`, which carries no queue (that
75
+ * generation's in-flight state is reconstructed sidecar-locally); a
76
+ * `run.grants` then has no queue to ride and this returns `false`. Returns
77
+ * `false` whenever the address is unroutable; the caller keeps any stable-run
78
+ * grant reservation so a later first-delivery attempt reuses it.
79
+ */
80
+ sendRunGrants(agentAddress: string, runId: string, stepGrants: RunGrantsFrame["stepGrants"]): boolean;
32
81
  /**
33
82
  * Returns the current connector-thread state for the named agent, or
34
83
  * `null` if the agent has no active connector thread (or if the
@@ -55,8 +104,26 @@ export type SidecarRouter = {
55
104
  sendAgentDeploy(agentAddress: string, config: HarnessConfig, workflow?: AgentDeployFrame["workflow"]): Promise<{
56
105
  publicKey: string;
57
106
  }>;
107
+ /**
108
+ * Ask a connected sidecar to probe a code-sourced workflow WITHOUT
109
+ * deploying it, and resolve with the sidecar's inert answer (needs-surface
110
+ * projection + grant set + content hash). Selects any connected sidecar via
111
+ * `findSidecarForNewAgent` -- the probe runs in the sidecar's pre-deploy
112
+ * state, so it needs no deployed agent and enters no address map -- and
113
+ * correlates the round-trip purely by a minted `requestId`. Rejects if no
114
+ * sidecar is connected, if the probe times out (`probeTimeoutMs`), if the
115
+ * sidecar answers `workflow.probe.error`, or if the sidecar disconnects with
116
+ * the probe in flight.
117
+ *
118
+ * Optional so existing `SidecarRouter` consumers -- and their test doubles
119
+ * -- that never probe need not implement it, mirroring `DeployRouter`'s
120
+ * optional `undeploy`. The concrete `createSidecarRouter` always provides
121
+ * it.
122
+ */
123
+ sendProbe?(args: SendProbeArgs): Promise<WorkflowProbeResult>;
58
124
  sendAgentUndeploy(agentAddress: string, reason: string): Promise<void>;
59
125
  sendSourcesUpdate(agentAddress: string, sources: InferenceSource[], defaultSource: string): Promise<void>;
126
+ sendCredentialsUpdate(agentAddress: string, delivery: CredentialDelivery): Promise<void>;
60
127
  sendPack(agentAddress: string, pack: Uint8Array, ref: string, commitSha: string, options?: SendPackOptions): Promise<void>;
61
128
  /**
62
129
  * Bind a per-step workflow-substrate address to a sidecar for the staging
@@ -137,9 +204,48 @@ export type SidecarRouter = {
137
204
  * principal (e.g. an operator user) can be added as an additional arm
138
205
  * without changing existing consumers.
139
206
  */
140
- export type SidecarAuthIdentity = {
141
- kind: "sidecar";
142
- sidecarId: string;
207
+ export type SidecarAuthIdentity = SidecarCredentialIdentity;
208
+ export type AllocatedSidecarTarget = {
209
+ readonly allocationId: string;
210
+ readonly generation: number;
211
+ };
212
+ export type SidecarAllocationRouter = {
213
+ /** Advance the in-memory trust boundary before provisioning a generation. */
214
+ fenceAllocation(allocationId: string, generation: number): void;
215
+ /** Resolve once the exact authenticated allocation generation is connected. */
216
+ waitForAllocatedSidecar(target: AllocatedSidecarTarget, timeoutMs: number): Promise<void>;
217
+ /** Check exact allocated readiness without parking a reconciliation worker. */
218
+ isAllocatedSidecarReady(target: AllocatedSidecarTarget): Promise<boolean>;
219
+ /** Check whether the exact generation already hosts its workflow supervisor. */
220
+ isAllocatedWorkflowActive(target: AllocatedSidecarTarget): Promise<boolean>;
221
+ sendAgentDeployToAllocation(target: AllocatedSidecarTarget, agentAddress: string, config: HarnessConfig, workflow?: AgentDeployFrame["workflow"]): Promise<{
222
+ publicKey: string;
223
+ }>;
224
+ sendPackToAllocation(target: AllocatedSidecarTarget, agentAddress: string, pack: Uint8Array, ref: string, commitSha: string, options?: SendPackOptions): Promise<void>;
225
+ /**
226
+ * Restore one Hub-authoritative workflow-run ref onto the exact allocation
227
+ * generation before its deployment address is routed or supervisor spawned.
228
+ */
229
+ sendWorkflowRunPackToAllocation(target: AllocatedSidecarTarget, agentAddress: string, pack: Uint8Array, ref: string, commitSha: string): Promise<void>;
230
+ bindAllocatedStepRoute(target: AllocatedSidecarTarget, stepAddress: string): Promise<void>;
231
+ unbindAllocatedStepRoute(target: AllocatedSidecarTarget, stepAddress: string): void;
232
+ sendProvisionStepToAllocation(target: AllocatedSidecarTarget, agentAddress: string, config: HarnessConfig): Promise<void>;
233
+ /**
234
+ * Deliver one durable workflow trigger to the exact allocation generation.
235
+ * Grants and mail are written to the same websocket in FIFO order. The
236
+ * returned promise proves only that both frames were sent; the sidecar's
237
+ * durable-inbox acknowledgement is surfaced separately through
238
+ * `mail.inbound.acknowledged`.
239
+ */
240
+ sendWorkflowRunDispatchToAllocation(target: AllocatedSidecarTarget, agentAddress: string, runId: string, stepGrants: RunGrantsFrame["stepGrants"], rawMessage: string, messageId: string): Promise<void>;
241
+ /** Deliver an idempotent signal to the exact exclusive generation. */
242
+ sendSignalDeliverToAllocation(target: AllocatedSidecarTarget, opts: {
243
+ agentAddress: string;
244
+ runId: string;
245
+ signalName: string;
246
+ signalId: string;
247
+ payload: unknown;
248
+ }): Promise<void>;
143
249
  };
144
250
  /**
145
251
  * Resolves the credentials a sidecar presents on the handshake to a
@@ -161,10 +267,24 @@ export type SidecarRouterConfig = {
161
267
  * identity. Required: without it a connection could route on an
162
268
  * unverified frame claim. Return null to reject the handshake. */
163
269
  authenticateSidecar: SidecarAuthenticator;
270
+ /** Revalidate durable identity at registration and routing boundaries. */
271
+ validateSidecarIdentity?: (identity: SidecarAuthIdentity, use: "registration" | "readiness" | "routing") => Promise<boolean>;
164
272
  challengeTimeoutMs?: number;
273
+ /** Timeout for a `sendProbe` round-trip. A probe materializes a workflow's
274
+ * dependency closure and evaluates it on the sidecar, so it can run longer
275
+ * than a routine `sendRequest`; it gets its own timeout rather than sharing
276
+ * the request timeout. */
277
+ probeTimeoutMs?: number;
165
278
  disconnectQueueMaxSize?: number;
166
279
  disconnectQueueTTLMs?: number;
167
280
  pingTimeoutMs?: number;
281
+ /** Interval between redelivery attempts of a connected-window `mail.inbound`
282
+ * the sidecar has not yet acknowledged with `mail.inbound.ack`. */
283
+ mailAckRetryIntervalMs?: number;
284
+ /** Maximum redelivery attempts before the hub stops retrying an un-acked
285
+ * connected-window `mail.inbound`. Bounds the retry so a sidecar that never
286
+ * acks does not accumulate an unbounded timer per delivery. */
287
+ mailAckMaxRetries?: number;
168
288
  /** Query handlers the wire layer issues during frame processing.
169
289
  * Each lookup is one-handler-returns-a-value; for multi-subscriber
170
290
  * notifications use `router.events.on(...)` instead.
@@ -181,4 +301,5 @@ export type WsHandle = {
181
301
  send(data: string): void;
182
302
  close(): void;
183
303
  };
184
- export declare function createSidecarRouter(config: SidecarRouterConfig): SidecarRouter;
304
+ export declare const DEFAULT_PROBE_TIMEOUT_MS = 60000;
305
+ export declare function createSidecarRouter(config: SidecarRouterConfig): SidecarRouter & SidecarAllocationRouter;