@intx/hub-sessions 0.1.2 → 0.2.2

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/LICENSE +176 -0
  2. package/README.md +84 -1
  3. package/dist/agent-repo.d.ts +89 -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 +185 -0
  7. package/dist/asset-service.d.ts +123 -0
  8. package/dist/asset-service.js +349 -0
  9. package/dist/available-skills-stanza.d.ts +21 -0
  10. package/dist/available-skills-stanza.js +32 -0
  11. package/dist/credential-push.d.ts +32 -0
  12. package/dist/credential-push.js +85 -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 +357 -0
  17. package/dist/hub-session-lookups.d.ts +17 -0
  18. package/dist/hub-session-lookups.js +204 -0
  19. package/dist/hub-session-orchestrator.d.ts +25 -0
  20. package/dist/hub-session-orchestrator.js +122 -0
  21. package/dist/index.d.ts +18 -0
  22. package/dist/index.js +16 -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 +1692 -0
  29. package/dist/repo-store/subscribe-kind.d.ts +53 -0
  30. package/dist/repo-store/subscribe-kind.js +179 -0
  31. package/dist/repo-store/types.d.ts +483 -0
  32. package/dist/repo-store/types.js +42 -0
  33. package/dist/session-service.d.ts +235 -0
  34. package/dist/session-service.js +997 -0
  35. package/dist/skill-kind.d.ts +41 -0
  36. package/dist/skill-kind.js +288 -0
  37. package/dist/substrate.d.ts +8 -0
  38. package/dist/substrate.js +21 -0
  39. package/dist/workflow-kind.d.ts +21 -0
  40. package/dist/workflow-kind.js +263 -0
  41. package/dist/workflow-run-event-log.d.ts +21 -0
  42. package/dist/workflow-run-event-log.js +51 -0
  43. package/dist/workflow-run-kind.d.ts +326 -0
  44. package/dist/workflow-run-kind.js +2646 -0
  45. package/dist/workflow-run-reader.d.ts +47 -0
  46. package/dist/workflow-run-reader.js +157 -0
  47. package/dist/ws/index.d.ts +3 -0
  48. package/dist/ws/index.js +3 -0
  49. package/dist/ws/sidecar-events.d.ts +134 -0
  50. package/dist/ws/sidecar-events.js +70 -0
  51. package/dist/ws/sidecar-handler.d.ts +184 -0
  52. package/dist/ws/sidecar-handler.js +1603 -0
  53. package/dist/ws/sidecar-token-authenticator.d.ts +15 -0
  54. package/dist/ws/sidecar-token-authenticator.js +24 -0
  55. package/package.json +34 -12
  56. package/src/agent-repo.test.ts +0 -310
  57. package/src/agent-repo.ts +0 -165
  58. package/src/agent-state-kind.test.ts +0 -247
  59. package/src/agent-state-kind.ts +0 -204
  60. package/src/asset-service.test.ts +0 -540
  61. package/src/asset-service.ts +0 -378
  62. package/src/available-skills-stanza.test.ts +0 -87
  63. package/src/available-skills-stanza.ts +0 -47
  64. package/src/credential-push.ts +0 -65
  65. package/src/event-collector-registry.test.ts +0 -73
  66. package/src/event-collector-registry.ts +0 -171
  67. package/src/event-collector.test.ts +0 -1387
  68. package/src/event-collector.ts +0 -424
  69. package/src/hub-session-lookups.ts +0 -206
  70. package/src/hub-session-orchestrator.test.ts +0 -510
  71. package/src/hub-session-orchestrator.ts +0 -213
  72. package/src/index.ts +0 -78
  73. package/src/repo-store/index.ts +0 -15
  74. package/src/repo-store/store.test.ts +0 -1169
  75. package/src/repo-store/store.ts +0 -428
  76. package/src/repo-store/types.ts +0 -253
  77. package/src/session-service.test.ts +0 -895
  78. package/src/session-service.ts +0 -464
  79. package/src/skill-kind.test.ts +0 -599
  80. package/src/skill-kind.ts +0 -350
  81. package/src/ws/index.ts +0 -18
  82. package/src/ws/sidecar-events.test.ts +0 -96
  83. package/src/ws/sidecar-events.ts +0 -231
  84. package/src/ws/sidecar-handler.test.ts +0 -2217
  85. package/src/ws/sidecar-handler.ts +0 -1574
  86. package/tsconfig.json +0 -4
  87. 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
- }