@intx/hub-sessions 0.3.0 → 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.
Files changed (67) hide show
  1. package/dist/agent-repo.d.ts +14 -2
  2. package/dist/agent-repo.js +17 -4
  3. package/dist/agent-state-kind.js +14 -63
  4. package/dist/asset-service.js +14 -10
  5. package/dist/credential-push.d.ts +48 -4
  6. package/dist/credential-push.js +138 -6
  7. package/dist/event-collector-registry.d.ts +2 -1
  8. package/dist/event-collector-registry.js +38 -9
  9. package/dist/event-collector.d.ts +11 -1
  10. package/dist/event-collector.js +36 -3
  11. package/dist/hub-session-lookups.d.ts +1 -1
  12. package/dist/hub-session-lookups.js +68 -72
  13. package/dist/hub-session-orchestrator.d.ts +2 -3
  14. package/dist/hub-session-orchestrator.js +13 -12
  15. package/dist/index.d.ts +7 -6
  16. package/dist/index.js +7 -6
  17. package/dist/reconciliation-scheduler.d.ts +14 -0
  18. package/dist/reconciliation-scheduler.js +55 -0
  19. package/dist/repo-store/index.d.ts +1 -0
  20. package/dist/repo-store/index.js +1 -0
  21. package/dist/repo-store/user-principal-gate.d.ts +26 -0
  22. package/dist/repo-store/user-principal-gate.js +78 -0
  23. package/dist/session-service.d.ts +66 -121
  24. package/dist/session-service.js +444 -411
  25. package/dist/sidecar-allocation/capability-policy.d.ts +27 -0
  26. package/dist/sidecar-allocation/capability-policy.js +124 -0
  27. package/dist/sidecar-allocation/contracts.d.ts +29 -6
  28. package/dist/sidecar-allocation/contracts.js +7 -2
  29. package/dist/sidecar-allocation/index.d.ts +4 -3
  30. package/dist/sidecar-allocation/index.js +3 -2
  31. package/dist/sidecar-allocation/operation.d.ts +10 -0
  32. package/dist/sidecar-allocation/operation.js +54 -0
  33. package/dist/sidecar-allocation/plugin-registry.d.ts +16 -3
  34. package/dist/sidecar-allocation/plugin-registry.js +36 -12
  35. package/dist/sidecar-allocation/reconciler.d.ts +16 -4
  36. package/dist/sidecar-allocation/reconciler.js +486 -92
  37. package/dist/skill-kind.js +8 -62
  38. package/dist/substrate.d.ts +1 -1
  39. package/dist/substrate.js +1 -1
  40. package/dist/workflow-allocation-service.d.ts +21 -15
  41. package/dist/workflow-allocation-service.js +440 -125
  42. package/dist/workflow-dispatch-service.d.ts +4 -2
  43. package/dist/workflow-dispatch-service.js +89 -26
  44. package/dist/workflow-kind.d.ts +12 -0
  45. package/dist/workflow-kind.js +17 -60
  46. package/dist/workflow-probe-gate.d.ts +99 -27
  47. package/dist/workflow-probe-gate.js +196 -21
  48. package/dist/workflow-run-kind.d.ts +112 -19
  49. package/dist/workflow-run-kind.js +626 -210
  50. package/dist/workflow-run-restore.d.ts +1 -0
  51. package/dist/workflow-run-restore.js +5 -1
  52. package/dist/workflow-source-pins.d.ts +8 -0
  53. package/dist/workflow-source-pins.js +14 -0
  54. package/dist/ws/index.d.ts +1 -1
  55. package/dist/ws/index.js +1 -1
  56. package/dist/ws/pending-tracker.d.ts +93 -0
  57. package/dist/ws/pending-tracker.js +132 -0
  58. package/dist/ws/sidecar-events.d.ts +43 -29
  59. package/dist/ws/sidecar-events.js +0 -2
  60. package/dist/ws/sidecar-handler.d.ts +122 -85
  61. package/dist/ws/sidecar-handler.js +925 -878
  62. package/dist/ws/sidecar-handler.test-helpers.d.ts +38 -0
  63. package/dist/ws/sidecar-handler.test-helpers.js +95 -0
  64. package/dist/ws/sidecar-token-authenticator.js +37 -23
  65. package/package.json +13 -13
  66. package/dist/sidecar-allocation/placement-policy.d.ts +0 -11
  67. package/dist/sidecar-allocation/placement-policy.js +0 -21
@@ -1,7 +1,6 @@
1
1
  import { type } from "arktype";
2
2
  import { getLogger } from "@intx/log";
3
- import { glob, repoActionToGrantVerb } from "@intx/hub-common";
4
- import { UserPrincipal, } from "./repo-store/index.js";
3
+ import { authorizeUserPrincipal, } from "./repo-store/index.js";
5
4
  const logger = getLogger(["hub-sessions", "skill-kind"]);
6
5
  /**
7
6
  * arktype schema for the SKILL.md frontmatter. Required fields are
@@ -220,66 +219,13 @@ export const skillAuthorize = (principal, repoId, ref, action) => {
220
219
  }
221
220
  }
222
221
  if (principal.kind === "user") {
223
- // The route layer has already pre-resolved the grant verdict and
224
- // attached it as `authz`. The substrate does NOT re-query the
225
- // grant store here; it (a) checks the bearer-token's claims
226
- // bound the requested (ref, action) and have not expired, and
227
- // (b) sanity-checks that the pre-resolved verdict targets this
228
- // exact resource and grant verb. Both gates must pass before the
229
- // verdict's `effect` is honoured.
230
- const parsed = UserPrincipal(principal);
231
- if (parsed instanceof type.errors) {
232
- return {
233
- allowed: false,
234
- reason: `user principal is malformed: ${parsed.summary}`,
235
- };
236
- }
237
- if (!parsed.tokenClaims.actions.includes(action)) {
238
- return {
239
- allowed: false,
240
- reason: `token does not grant action ${action}`,
241
- };
242
- }
243
- // `ref === "*"` is the substrate's sentinel for a bulk read used
244
- // by `listRefs`. The advertise-refs layer applies the per-ref
245
- // refPattern filter on the listing it returns, so gating the bulk
246
- // read on refPattern here would prevent any token with a
247
- // narrow-pattern (e.g. `refs/heads/main`) from listing refs at
248
- // all. Only the action and expiry are enforced for the bulk read;
249
- // every other call site passes a concrete ref and is gated below.
250
- if (ref !== "*" && !glob.match(parsed.tokenClaims.refPattern, ref)) {
251
- return {
252
- allowed: false,
253
- reason: `token refPattern ${parsed.tokenClaims.refPattern} does not match ${ref}`,
254
- };
255
- }
256
- if (Date.now() >= parsed.tokenClaims.expiresAt) {
257
- return {
258
- allowed: false,
259
- reason: `token expired at ${parsed.tokenClaims.expiresAt}`,
260
- };
261
- }
262
- const expectedResource = `asset:${repoId.id}`;
263
- if (parsed.authz.resource !== expectedResource) {
264
- return {
265
- allowed: false,
266
- reason: `authz verdict resource ${parsed.authz.resource} does not match ${expectedResource}`,
267
- };
268
- }
269
- const expectedGrantVerb = repoActionToGrantVerb(action);
270
- if (parsed.authz.grantVerb !== expectedGrantVerb) {
271
- return {
272
- allowed: false,
273
- reason: `authz verdict grantVerb ${parsed.authz.grantVerb} does not match ${expectedGrantVerb}`,
274
- };
275
- }
276
- if (parsed.authz.effect === "allow") {
277
- return { allowed: true };
278
- }
279
- return {
280
- allowed: false,
281
- reason: `authz verdict denied for ${expectedResource} ${expectedGrantVerb}`,
282
- };
222
+ return authorizeUserPrincipal({
223
+ principal,
224
+ repoId,
225
+ ref,
226
+ action,
227
+ resourcePrefix: "asset",
228
+ });
283
229
  }
284
230
  // Fail closed on any kind not handled above. The tenant-level
285
231
  // `workflow` principal kind (`@intx/types` principalKinds) is a
@@ -1,4 +1,4 @@
1
- export { DEFAULT_CONSUMED_RETENTION_MS, dequeueToProcessing, enqueueInbox, markConsumed, parseEventSeq, readOwnedMessageIds, readCommittedWorkflowRunLifecycle, readWorkflowRunLifecycle, readProcessingEntry, replayProcessingToInbox, requireEventSeq, StaleInboxEnqueueError, WORKFLOW_RUN_AGENT_STATE_PREFIX, WORKFLOW_RUN_EVENTS_DIR, WORKFLOW_RUN_RUNS_PREFIX, } from "./workflow-run-kind.js";
1
+ export { classifyTerminalEvent, DEFAULT_CONSUMED_RETENTION_MS, dequeueToProcessing, enqueueInbox, markConsumed, parseEventSeq, scanRunsForBoot, readCommittedWorkflowRunLifecycle, readWorkflowRunLifecycle, readProcessingEntry, replayProcessingToInbox, requireEventSeq, StaleInboxEnqueueError, WORKFLOW_RUN_AGENT_STATE_PREFIX, WORKFLOW_RUN_PARTS_DIR, WORKFLOW_RUN_EVENTS_DIR, WORKFLOW_RUN_RUNS_PREFIX, MAX_MAIL_PART_PATH_COMPONENT_BYTES, } from "./workflow-run-kind.js";
2
2
  export type { WorkflowRunSupervisorPrincipal, WorkflowRunWorkflowProcessPrincipal, DequeueToProcessingResult, EnqueueAlreadyPresentReason, EnqueueInboxArgs, EnqueueInboxOutcome, EnqueueInboxResult, MarkConsumedArgs, MarkConsumedResult, WorkflowRunLifecycle, ReplayProcessingToInboxOpts, ReplayProcessingToInboxResult, } from "./workflow-run-kind.js";
3
3
  export { encodeCombinedEventLog, splitCombinedEventLog, WORKFLOW_RUN_EVENTS_FILE, } from "./workflow-run-event-log.js";
4
4
  export { workflowDefinitionEnvelopeSchema } from "./workflow-kind.js";
package/dist/substrate.js CHANGED
@@ -14,7 +14,7 @@
14
14
  // runs nowhere near a database -- can import it without dragging `@intx/db`
15
15
  // into its boot graph. Every symbol re-exported here is defined in a db-free
16
16
  // module. The barrel still re-exports all of these for hub-side consumers.
17
- export { DEFAULT_CONSUMED_RETENTION_MS, dequeueToProcessing, enqueueInbox, markConsumed, parseEventSeq, readOwnedMessageIds, readCommittedWorkflowRunLifecycle, readWorkflowRunLifecycle, readProcessingEntry, replayProcessingToInbox, requireEventSeq, StaleInboxEnqueueError, WORKFLOW_RUN_AGENT_STATE_PREFIX, WORKFLOW_RUN_EVENTS_DIR, WORKFLOW_RUN_RUNS_PREFIX, } from "./workflow-run-kind.js";
17
+ export { classifyTerminalEvent, DEFAULT_CONSUMED_RETENTION_MS, dequeueToProcessing, enqueueInbox, markConsumed, parseEventSeq, scanRunsForBoot, readCommittedWorkflowRunLifecycle, readWorkflowRunLifecycle, readProcessingEntry, replayProcessingToInbox, requireEventSeq, StaleInboxEnqueueError, WORKFLOW_RUN_AGENT_STATE_PREFIX, WORKFLOW_RUN_PARTS_DIR, WORKFLOW_RUN_EVENTS_DIR, WORKFLOW_RUN_RUNS_PREFIX, MAX_MAIL_PART_PATH_COMPONENT_BYTES, } from "./workflow-run-kind.js";
18
18
  export { encodeCombinedEventLog, splitCombinedEventLog, WORKFLOW_RUN_EVENTS_FILE, } from "./workflow-run-event-log.js";
19
19
  export { workflowDefinitionEnvelopeSchema } from "./workflow-kind.js";
20
20
  export { subscribeKind } from "./repo-store/subscribe-kind.js";
@@ -1,16 +1,17 @@
1
1
  import { type DB, type SidecarAllocation } from "@intx/db";
2
- import { type CredentialCipher, type SidecarPlacementRequirement } from "@intx/types";
2
+ import { SidecarCapabilityRule, type CredentialCipher } from "@intx/types";
3
3
  import type { ToolPackagePin } from "@intx/types/tool-packages";
4
4
  import type { WorkflowDefinitionSource } from "@intx/types/workflow-sources";
5
5
  import type { DeployContent } from "./agent-repo.js";
6
6
  import { type SidecarPluginRegistry } from "./sidecar-allocation/index.js";
7
7
  import { type DeployWorkflowDefinitionResult, type PreparedWorkflowDeployer } from "./session-service.js";
8
8
  import type { SidecarAllocationRouter } from "./ws/sidecar-handler.js";
9
- export declare class ExclusiveWorkflowPlacementError extends Error {
9
+ import { type SidecarReconciliationContext } from "./sidecar-allocation/operation.js";
10
+ export declare class WorkflowProvisioningError extends Error {
10
11
  readonly code: string;
11
12
  constructor(code: string, message: string);
12
13
  }
13
- export type PrepareExclusiveWorkflowDeploymentArgs = {
14
+ export type PrepareProvisionedWorkflowDeploymentArgs = {
14
15
  readonly tenantId: string;
15
16
  readonly anchorRunId: string;
16
17
  readonly deploymentDomain: string;
@@ -24,9 +25,6 @@ export type PrepareExclusiveWorkflowDeploymentArgs = {
24
25
  */
25
26
  readonly pin?: string;
26
27
  readonly definitionAssetId: string;
27
- readonly placement: SidecarPlacementRequirement & {
28
- readonly sharing: "exclusive";
29
- };
30
28
  readonly sessionId: string;
31
29
  readonly sourceAuthorityPrincipalId: string;
32
30
  readonly sourceOfferingIds: readonly string[];
@@ -34,25 +32,33 @@ export type PrepareExclusiveWorkflowDeploymentArgs = {
34
32
  readonly deployContent: DeployContent;
35
33
  readonly toolPackagePins?: readonly ToolPackagePin[];
36
34
  };
37
- export type PreparedExclusiveWorkflowDeployment = {
35
+ export type PreparedProvisionedWorkflowDeployment = {
38
36
  readonly anchorRunId: string;
39
37
  readonly deploymentAddress: string;
40
38
  readonly allocationId: string;
41
39
  readonly status: "pending";
42
40
  };
43
41
  export type WorkflowAllocationService = {
44
- prepareExclusiveDeployment(args: PrepareExclusiveWorkflowDeploymentArgs): Promise<PreparedExclusiveWorkflowDeployment>;
45
- deployReadyAllocation(allocation: SidecarAllocation): Promise<DeployWorkflowDefinitionResult | null>;
42
+ initialize?(): Promise<void>;
43
+ reconcileReleasingProbes?(): Promise<void>;
44
+ prepareProvisionedDeployment(args: PrepareProvisionedWorkflowDeploymentArgs): Promise<PreparedProvisionedWorkflowDeployment>;
45
+ deployReadyAllocation(allocation: SidecarAllocation, reconciliation: SidecarReconciliationContext): Promise<DeployWorkflowDefinitionResult | null>;
46
46
  };
47
47
  export type WorkflowAllocationServiceDeps = {
48
48
  readonly db: DB["db"];
49
- readonly plugins: SidecarPluginRegistry;
49
+ readonly deploymentPlugins: SidecarPluginRegistry;
50
+ readonly probePlugins: SidecarPluginRegistry;
50
51
  readonly preparedDeployer: PreparedWorkflowDeployer;
51
- readonly credentialCipher?: CredentialCipher;
52
- readonly allocationRouter: Pick<SidecarAllocationRouter, "isAllocatedWorkflowActive">;
52
+ /** Decrypts tenant-owned credential bindings for provisioned deployments. */
53
+ readonly credentialCipher: CredentialCipher;
54
+ readonly probeCapabilityRules?: readonly SidecarCapabilityRule[];
55
+ readonly allocationRouter: Pick<SidecarAllocationRouter, "disconnectAllocation" | "fenceAllocation" | "isAllocatedWorkflowActive" | "retireAllocation" | "sendProbeToAllocation" | "waitForAllocatedSidecar">;
56
+ readonly hubWebSocketUrl: string;
53
57
  readonly createAllocationId?: () => string;
58
+ readonly createSidecarId?: () => string;
59
+ readonly createToken?: () => string;
60
+ readonly connectTimeoutMs?: number;
61
+ readonly operationTimeoutMs?: number;
54
62
  readonly now?: () => Date;
55
63
  };
56
- /** Resolve the tenant-inherited sidecar placement into one launch decision. */
57
- export declare function resolveWorkflowSidecarPlacement(db: DB["db"], tenantId: string): Promise<SidecarPlacementRequirement | null>;
58
- export declare function createWorkflowAllocationService({ db, plugins, preparedDeployer, credentialCipher, allocationRouter, createAllocationId, now, }: WorkflowAllocationServiceDeps): WorkflowAllocationService;
64
+ export declare function createWorkflowAllocationService({ db, deploymentPlugins, probePlugins, preparedDeployer, credentialCipher, probeCapabilityRules, allocationRouter, hubWebSocketUrl, createAllocationId, createSidecarId, createToken, connectTimeoutMs, operationTimeoutMs, now, }: WorkflowAllocationServiceDeps): WorkflowAllocationService;