@intx/hub-sessions 0.1.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 (113) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +82 -1
  3. package/dist/agent-repo.d.ts +93 -0
  4. package/dist/agent-repo.js +109 -0
  5. package/dist/agent-state-kind.d.ts +12 -0
  6. package/dist/agent-state-kind.js +189 -0
  7. package/dist/asset-service.d.ts +104 -0
  8. package/dist/asset-service.js +267 -0
  9. package/dist/committed-source-tree.d.ts +10 -0
  10. package/dist/committed-source-tree.js +35 -0
  11. package/dist/credential-push.d.ts +33 -0
  12. package/dist/credential-push.js +109 -0
  13. package/dist/event-collector-registry.d.ts +20 -0
  14. package/dist/event-collector-registry.js +115 -0
  15. package/dist/event-collector.d.ts +39 -0
  16. package/dist/event-collector.js +365 -0
  17. package/dist/hub-session-lookups.d.ts +135 -0
  18. package/dist/hub-session-lookups.js +663 -0
  19. package/dist/hub-session-orchestrator.d.ts +25 -0
  20. package/dist/hub-session-orchestrator.js +87 -0
  21. package/dist/index.d.ts +27 -0
  22. package/dist/index.js +24 -0
  23. package/dist/package-registry-kind.d.ts +70 -0
  24. package/dist/package-registry-kind.js +260 -0
  25. package/dist/repo-store/index.d.ts +4 -0
  26. package/dist/repo-store/index.js +3 -0
  27. package/dist/repo-store/store.d.ts +41 -0
  28. package/dist/repo-store/store.js +1829 -0
  29. package/dist/repo-store/subscribe-kind.d.ts +56 -0
  30. package/dist/repo-store/subscribe-kind.js +144 -0
  31. package/dist/repo-store/types.d.ts +571 -0
  32. package/dist/repo-store/types.js +42 -0
  33. package/dist/session-service.d.ts +416 -0
  34. package/dist/session-service.js +1191 -0
  35. package/dist/sidecar-allocation/contracts.d.ts +78 -0
  36. package/dist/sidecar-allocation/contracts.js +21 -0
  37. package/dist/sidecar-allocation/index.d.ts +4 -0
  38. package/dist/sidecar-allocation/index.js +3 -0
  39. package/dist/sidecar-allocation/placement-policy.d.ts +11 -0
  40. package/dist/sidecar-allocation/placement-policy.js +21 -0
  41. package/dist/sidecar-allocation/plugin-registry.d.ts +11 -0
  42. package/dist/sidecar-allocation/plugin-registry.js +37 -0
  43. package/dist/sidecar-allocation/reconciler.d.ts +42 -0
  44. package/dist/sidecar-allocation/reconciler.js +431 -0
  45. package/dist/skill-kind.d.ts +41 -0
  46. package/dist/skill-kind.js +292 -0
  47. package/dist/substrate.d.ts +8 -0
  48. package/dist/substrate.js +21 -0
  49. package/dist/workflow-allocation-service.d.ts +58 -0
  50. package/dist/workflow-allocation-service.js +239 -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 +40 -0
  56. package/dist/workflow-dispatch-service.js +146 -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 +37 -0
  60. package/dist/workflow-kind.js +310 -0
  61. package/dist/workflow-probe-gate.d.ts +214 -0
  62. package/dist/workflow-probe-gate.js +207 -0
  63. package/dist/workflow-run-event-log.d.ts +21 -0
  64. package/dist/workflow-run-event-log.js +51 -0
  65. package/dist/workflow-run-kind.d.ts +440 -0
  66. package/dist/workflow-run-kind.js +2916 -0
  67. package/dist/workflow-run-reader.d.ts +47 -0
  68. package/dist/workflow-run-reader.js +153 -0
  69. package/dist/workflow-run-restore.d.ts +15 -0
  70. package/dist/workflow-run-restore.js +26 -0
  71. package/dist/workflow-source-closure.d.ts +35 -0
  72. package/dist/workflow-source-closure.js +342 -0
  73. package/dist/ws/index.d.ts +3 -0
  74. package/dist/ws/index.js +3 -0
  75. package/dist/ws/sidecar-events.d.ts +222 -0
  76. package/dist/ws/sidecar-events.js +72 -0
  77. package/dist/ws/sidecar-handler.d.ts +305 -0
  78. package/dist/ws/sidecar-handler.js +2537 -0
  79. package/dist/ws/sidecar-token-authenticator.d.ts +17 -0
  80. package/dist/ws/sidecar-token-authenticator.js +81 -0
  81. package/package.json +35 -12
  82. package/src/agent-repo.test.ts +0 -310
  83. package/src/agent-repo.ts +0 -165
  84. package/src/agent-state-kind.test.ts +0 -247
  85. package/src/agent-state-kind.ts +0 -204
  86. package/src/asset-service.test.ts +0 -540
  87. package/src/asset-service.ts +0 -378
  88. package/src/available-skills-stanza.test.ts +0 -87
  89. package/src/available-skills-stanza.ts +0 -47
  90. package/src/credential-push.ts +0 -65
  91. package/src/event-collector-registry.test.ts +0 -73
  92. package/src/event-collector-registry.ts +0 -171
  93. package/src/event-collector.test.ts +0 -1387
  94. package/src/event-collector.ts +0 -424
  95. package/src/hub-session-lookups.ts +0 -206
  96. package/src/hub-session-orchestrator.test.ts +0 -510
  97. package/src/hub-session-orchestrator.ts +0 -213
  98. package/src/index.ts +0 -78
  99. package/src/repo-store/index.ts +0 -15
  100. package/src/repo-store/store.test.ts +0 -1169
  101. package/src/repo-store/store.ts +0 -428
  102. package/src/repo-store/types.ts +0 -253
  103. package/src/session-service.test.ts +0 -895
  104. package/src/session-service.ts +0 -464
  105. package/src/skill-kind.test.ts +0 -599
  106. package/src/skill-kind.ts +0 -350
  107. package/src/ws/index.ts +0 -18
  108. package/src/ws/sidecar-events.test.ts +0 -96
  109. package/src/ws/sidecar-events.ts +0 -231
  110. package/src/ws/sidecar-handler.test.ts +0 -2217
  111. package/src/ws/sidecar-handler.ts +0 -1574
  112. package/tsconfig.json +0 -4
  113. package/tsconfig.tsbuildinfo +0 -1
@@ -1,171 +0,0 @@
1
- // Registry of active event collectors, keyed by agent address.
2
- //
3
- // The hub creates a collector when an instance starts and removes it when the
4
- // instance ends or the sidecar disconnects. The hub session orchestrator's
5
- // `agent.event` listener looks up the collector by agent address and
6
- // dispatches the event.
7
-
8
- import type { DB } from "@intx/db";
9
- import type { InferenceEvent } from "@intx/types/runtime";
10
- import type { SessionStatus } from "@intx/types";
11
- import { getLogger } from "@intx/log";
12
-
13
- import {
14
- createEventCollector,
15
- type EventCollector,
16
- type TurnFinalized,
17
- } from "./event-collector";
18
-
19
- const log = getLogger(["hub", "event-collector-registry"]);
20
-
21
- export type EventCollectorRegistry = {
22
- create(
23
- agentAddress: string,
24
- tenantId: string,
25
- sessionId: string,
26
- instanceId: string,
27
- ): void;
28
- dispatch(agentAddress: string, event: InferenceEvent): void;
29
- abandon(agentAddress: string): void;
30
- has(agentAddress: string): boolean;
31
- getStatus(agentAddress: string): SessionStatus | undefined;
32
- getAccumulatedText(agentAddress: string): string | undefined;
33
- getCurrentTurnId(agentAddress: string): string | null | undefined;
34
- getLastTurnId(agentAddress: string): string | null | undefined;
35
- };
36
-
37
- export type EventCollectorRegistryConfig = {
38
- db: DB["db"];
39
- onTurnFinalized?: (agentAddress: string, turn: TurnFinalized) => void;
40
- };
41
-
42
- export function deriveStatus(event: InferenceEvent): SessionStatus | null {
43
- switch (event.type) {
44
- case "inference.start":
45
- return { status: "busy" };
46
- case "connector.reply":
47
- return { status: "idle" };
48
- case "reactor.gate.blocked":
49
- if (event.data.reason === "approval")
50
- return { status: "waiting_approval" };
51
- return null;
52
- case "reactor.gate.cleared":
53
- return { status: "busy" };
54
- case "reactor.done":
55
- return { status: "idle" };
56
- case "reactor.error":
57
- if (event.data.fatal) return { status: "idle" };
58
- return null;
59
- default:
60
- return null;
61
- }
62
- }
63
-
64
- export function createEventCollectorRegistry(
65
- config: EventCollectorRegistryConfig,
66
- ): EventCollectorRegistry {
67
- const { db, onTurnFinalized } = config;
68
- const collectors = new Map<string, EventCollector>();
69
- const statuses = new Map<string, SessionStatus>();
70
-
71
- function create(
72
- agentAddress: string,
73
- tenantId: string,
74
- sessionId: string,
75
- instanceId: string,
76
- ): void {
77
- if (collectors.has(agentAddress)) {
78
- log.warn`Collector already exists for ${agentAddress}, replacing`;
79
- abandon(agentAddress);
80
- }
81
-
82
- const collector = createEventCollector({
83
- db,
84
- sessionId,
85
- instanceId,
86
- tenantId,
87
- ...(onTurnFinalized
88
- ? {
89
- onTurnFinalized: (turn: TurnFinalized) =>
90
- onTurnFinalized(agentAddress, turn),
91
- }
92
- : {}),
93
- });
94
- collectors.set(agentAddress, collector);
95
- statuses.set(agentAddress, { status: "idle" });
96
- }
97
-
98
- function removeCollector(agentAddress: string): void {
99
- collectors.delete(agentAddress);
100
- statuses.delete(agentAddress);
101
- }
102
-
103
- function dispatch(agentAddress: string, event: InferenceEvent): void {
104
- const collector = collectors.get(agentAddress);
105
- if (collector === undefined) {
106
- return;
107
- }
108
-
109
- const derived = deriveStatus(event);
110
- if (derived !== null) {
111
- statuses.set(agentAddress, derived);
112
- }
113
-
114
- const isTerminal =
115
- event.type === "reactor.done" ||
116
- (event.type === "reactor.error" && event.data.fatal);
117
-
118
- collector
119
- .onEvent(event)
120
- .catch((err: unknown) => {
121
- log.warn`Failed to persist event ${event.type} seq=${String(event.seq)} for ${agentAddress}: ${err instanceof Error ? err.message : String(err)}`;
122
- })
123
- .finally(() => {
124
- if (isTerminal) {
125
- removeCollector(agentAddress);
126
- }
127
- });
128
- }
129
-
130
- function abandon(agentAddress: string): void {
131
- const collector = collectors.get(agentAddress);
132
- if (collector === undefined) return;
133
-
134
- collector.abandon().catch((err: unknown) => {
135
- log.warn`Failed to abandon collector for ${agentAddress}: ${err instanceof Error ? err.message : String(err)}`;
136
- });
137
-
138
- removeCollector(agentAddress);
139
- }
140
-
141
- function has(agentAddress: string): boolean {
142
- return collectors.has(agentAddress);
143
- }
144
-
145
- function getStatus(agentAddress: string): SessionStatus | undefined {
146
- return statuses.get(agentAddress);
147
- }
148
-
149
- function getAccumulatedText(agentAddress: string): string | undefined {
150
- return collectors.get(agentAddress)?.getAccumulatedText();
151
- }
152
-
153
- function getCurrentTurnId(agentAddress: string): string | null | undefined {
154
- return collectors.get(agentAddress)?.getCurrentTurnId();
155
- }
156
-
157
- function getLastTurnId(agentAddress: string): string | null | undefined {
158
- return collectors.get(agentAddress)?.getLastTurnId();
159
- }
160
-
161
- return {
162
- create,
163
- dispatch,
164
- abandon,
165
- has,
166
- getStatus,
167
- getAccumulatedText,
168
- getCurrentTurnId,
169
- getLastTurnId,
170
- };
171
- }