@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.
Files changed (87) hide show
  1. package/README.md +3 -5
  2. package/dist/agent-repo.d.ts +23 -7
  3. package/dist/agent-repo.js +19 -6
  4. package/dist/agent-state-kind.js +18 -63
  5. package/dist/asset-service.d.ts +1 -20
  6. package/dist/asset-service.js +19 -97
  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 +52 -7
  10. package/dist/credential-push.js +178 -22
  11. package/dist/event-collector-registry.d.ts +3 -2
  12. package/dist/event-collector-registry.js +42 -13
  13. package/dist/event-collector.d.ts +12 -2
  14. package/dist/event-collector.js +45 -4
  15. package/dist/hub-session-lookups.d.ts +125 -7
  16. package/dist/hub-session-lookups.js +541 -86
  17. package/dist/hub-session-orchestrator.d.ts +2 -3
  18. package/dist/hub-session-orchestrator.js +22 -56
  19. package/dist/index.d.ts +19 -9
  20. package/dist/index.js +16 -7
  21. package/dist/reconciliation-scheduler.d.ts +14 -0
  22. package/dist/reconciliation-scheduler.js +55 -0
  23. package/dist/repo-store/index.d.ts +2 -1
  24. package/dist/repo-store/index.js +1 -0
  25. package/dist/repo-store/store.d.ts +1 -1
  26. package/dist/repo-store/store.js +138 -1
  27. package/dist/repo-store/subscribe-kind.d.ts +6 -3
  28. package/dist/repo-store/subscribe-kind.js +42 -77
  29. package/dist/repo-store/types.d.ts +94 -6
  30. package/dist/repo-store/user-principal-gate.d.ts +26 -0
  31. package/dist/repo-store/user-principal-gate.js +78 -0
  32. package/dist/session-service.d.ts +252 -126
  33. package/dist/session-service.js +851 -624
  34. package/dist/sidecar-allocation/capability-policy.d.ts +27 -0
  35. package/dist/sidecar-allocation/capability-policy.js +124 -0
  36. package/dist/sidecar-allocation/contracts.d.ts +101 -0
  37. package/dist/sidecar-allocation/contracts.js +26 -0
  38. package/dist/sidecar-allocation/index.d.ts +5 -0
  39. package/dist/sidecar-allocation/index.js +4 -0
  40. package/dist/sidecar-allocation/operation.d.ts +10 -0
  41. package/dist/sidecar-allocation/operation.js +54 -0
  42. package/dist/sidecar-allocation/plugin-registry.d.ts +24 -0
  43. package/dist/sidecar-allocation/plugin-registry.js +61 -0
  44. package/dist/sidecar-allocation/reconciler.d.ts +54 -0
  45. package/dist/sidecar-allocation/reconciler.js +825 -0
  46. package/dist/skill-kind.js +12 -62
  47. package/dist/substrate.d.ts +3 -3
  48. package/dist/substrate.js +1 -1
  49. package/dist/workflow-allocation-service.d.ts +64 -0
  50. package/dist/workflow-allocation-service.js +554 -0
  51. package/dist/workflow-closure-resolution.d.ts +106 -0
  52. package/dist/workflow-closure-resolution.js +123 -0
  53. package/dist/workflow-definition-ensure.d.ts +24 -0
  54. package/dist/workflow-definition-ensure.js +75 -0
  55. package/dist/workflow-dispatch-service.d.ts +42 -0
  56. package/dist/workflow-dispatch-service.js +209 -0
  57. package/dist/workflow-dispatch-settlement.d.ts +29 -0
  58. package/dist/workflow-dispatch-settlement.js +140 -0
  59. package/dist/workflow-kind.d.ts +29 -1
  60. package/dist/workflow-kind.js +143 -139
  61. package/dist/workflow-probe-gate.d.ts +286 -0
  62. package/dist/workflow-probe-gate.js +382 -0
  63. package/dist/workflow-run-kind.d.ts +239 -32
  64. package/dist/workflow-run-kind.js +874 -188
  65. package/dist/workflow-run-reader.d.ts +1 -1
  66. package/dist/workflow-run-reader.js +3 -7
  67. package/dist/workflow-run-restore.d.ts +16 -0
  68. package/dist/workflow-run-restore.js +30 -0
  69. package/dist/workflow-source-closure.d.ts +35 -0
  70. package/dist/workflow-source-closure.js +342 -0
  71. package/dist/workflow-source-pins.d.ts +8 -0
  72. package/dist/workflow-source-pins.js +14 -0
  73. package/dist/ws/index.d.ts +3 -3
  74. package/dist/ws/index.js +2 -2
  75. package/dist/ws/pending-tracker.d.ts +93 -0
  76. package/dist/ws/pending-tracker.js +132 -0
  77. package/dist/ws/sidecar-events.d.ts +139 -37
  78. package/dist/ws/sidecar-events.js +2 -2
  79. package/dist/ws/sidecar-handler.d.ts +218 -60
  80. package/dist/ws/sidecar-handler.js +1713 -732
  81. package/dist/ws/sidecar-handler.test-helpers.d.ts +38 -0
  82. package/dist/ws/sidecar-handler.test-helpers.js +95 -0
  83. package/dist/ws/sidecar-token-authenticator.d.ts +3 -1
  84. package/dist/ws/sidecar-token-authenticator.js +78 -7
  85. package/package.json +14 -13
  86. package/dist/available-skills-stanza.d.ts +0 -21
  87. package/dist/available-skills-stanza.js +0 -32
@@ -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,67 +219,18 @@ 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
  }
230
+ // Fail closed on any kind not handled above. The tenant-level
231
+ // `workflow` principal kind (`@intx/types` principalKinds) is a
232
+ // grant owner, not a skill bearer, and never carries a skill repo
233
+ // push here -- so it is intentionally left denied.
284
234
  return {
285
235
  allowed: false,
286
236
  reason: `unknown principal kind: ${principal.kind}`,
@@ -1,8 +1,8 @@
1
- export { DEFAULT_CONSUMED_RETENTION_MS, dequeueToProcessing, enqueueInbox, markConsumed, readOwnedMessageIds, readProcessingEntry, replayProcessingToInbox, WORKFLOW_RUN_AGENT_STATE_PREFIX, } from "./workflow-run-kind.js";
2
- export type { WorkflowRunSupervisorPrincipal, WorkflowRunWorkflowProcessPrincipal, DequeueToProcessingResult, EnqueueInboxArgs, EnqueueInboxResult, MarkConsumedArgs, MarkConsumedResult, ReplayProcessingToInboxOpts, ReplayProcessingToInboxResult, } 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
+ 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";
5
5
  export { subscribeKind } from "./repo-store/subscribe-kind.js";
6
6
  export type { SubscribeKindEntry } from "./repo-store/subscribe-kind.js";
7
7
  export { createAgentRepoStore } from "./agent-repo.js";
8
- export type { Principal, RepoId, RepoStore, WriteResult, InitRepoOpts, NewlyTerminalRun, } from "./repo-store/types.js";
8
+ export type { CommittedReads, CommittedTreeEntry, Principal, RepoId, RepoStore, WriteResult, InitRepoOpts, NewlyTerminalRun, } from "./repo-store/types.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, readOwnedMessageIds, readProcessingEntry, replayProcessingToInbox, WORKFLOW_RUN_AGENT_STATE_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";
@@ -0,0 +1,64 @@
1
+ import { type DB, type SidecarAllocation } from "@intx/db";
2
+ import { SidecarCapabilityRule, type CredentialCipher } from "@intx/types";
3
+ import type { ToolPackagePin } from "@intx/types/tool-packages";
4
+ import type { WorkflowDefinitionSource } from "@intx/types/workflow-sources";
5
+ import type { DeployContent } from "./agent-repo.js";
6
+ import { type SidecarPluginRegistry } from "./sidecar-allocation/index.js";
7
+ import { type DeployWorkflowDefinitionResult, type PreparedWorkflowDeployer } from "./session-service.js";
8
+ import type { SidecarAllocationRouter } from "./ws/sidecar-handler.js";
9
+ import { type SidecarReconciliationContext } from "./sidecar-allocation/operation.js";
10
+ export declare class WorkflowProvisioningError extends Error {
11
+ readonly code: string;
12
+ constructor(code: string, message: string);
13
+ }
14
+ export type PrepareProvisionedWorkflowDeploymentArgs = {
15
+ readonly tenantId: string;
16
+ readonly anchorRunId: string;
17
+ readonly deploymentDomain: string;
18
+ /** Where the definition's bytes come from at probe time. */
19
+ readonly source: WorkflowDefinitionSource;
20
+ /** The `interchange.workflow` entry-module path the sidecar evaluates. */
21
+ readonly entry: string;
22
+ /**
23
+ * A `name@range` spec for the definition package. REQUIRED for the `registry`
24
+ * and asset-`tarball` variants; omitted for the asset-`source` variant.
25
+ */
26
+ readonly pin?: string;
27
+ readonly definitionAssetId: string;
28
+ readonly sessionId: string;
29
+ readonly sourceAuthorityPrincipalId: string;
30
+ readonly sourceOfferingIds: readonly string[];
31
+ readonly defaultSourceOfferingId: string;
32
+ readonly deployContent: DeployContent;
33
+ readonly toolPackagePins?: readonly ToolPackagePin[];
34
+ };
35
+ export type PreparedProvisionedWorkflowDeployment = {
36
+ readonly anchorRunId: string;
37
+ readonly deploymentAddress: string;
38
+ readonly allocationId: string;
39
+ readonly status: "pending";
40
+ };
41
+ export type WorkflowAllocationService = {
42
+ initialize?(): Promise<void>;
43
+ reconcileReleasingProbes?(): Promise<void>;
44
+ prepareProvisionedDeployment(args: PrepareProvisionedWorkflowDeploymentArgs): Promise<PreparedProvisionedWorkflowDeployment>;
45
+ deployReadyAllocation(allocation: SidecarAllocation, reconciliation: SidecarReconciliationContext): Promise<DeployWorkflowDefinitionResult | null>;
46
+ };
47
+ export type WorkflowAllocationServiceDeps = {
48
+ readonly db: DB["db"];
49
+ readonly deploymentPlugins: SidecarPluginRegistry;
50
+ readonly probePlugins: SidecarPluginRegistry;
51
+ readonly preparedDeployer: PreparedWorkflowDeployer;
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;
57
+ readonly createAllocationId?: () => string;
58
+ readonly createSidecarId?: () => string;
59
+ readonly createToken?: () => string;
60
+ readonly connectTimeoutMs?: number;
61
+ readonly operationTimeoutMs?: number;
62
+ readonly now?: () => Date;
63
+ };
64
+ export declare function createWorkflowAllocationService({ db, deploymentPlugins, probePlugins, preparedDeployer, credentialCipher, probeCapabilityRules, allocationRouter, hubWebSocketUrl, createAllocationId, createSidecarId, createToken, connectTimeoutMs, operationTimeoutMs, now, }: WorkflowAllocationServiceDeps): WorkflowAllocationService;