@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.
- package/LICENSE +176 -0
- package/README.md +84 -1
- package/dist/agent-repo.d.ts +89 -0
- package/dist/agent-repo.js +109 -0
- package/dist/agent-state-kind.d.ts +12 -0
- package/dist/agent-state-kind.js +185 -0
- package/dist/asset-service.d.ts +123 -0
- package/dist/asset-service.js +349 -0
- package/dist/available-skills-stanza.d.ts +21 -0
- package/dist/available-skills-stanza.js +32 -0
- package/dist/credential-push.d.ts +32 -0
- package/dist/credential-push.js +85 -0
- package/dist/event-collector-registry.d.ts +20 -0
- package/dist/event-collector-registry.js +115 -0
- package/dist/event-collector.d.ts +39 -0
- package/dist/event-collector.js +357 -0
- package/dist/hub-session-lookups.d.ts +17 -0
- package/dist/hub-session-lookups.js +204 -0
- package/dist/hub-session-orchestrator.d.ts +25 -0
- package/dist/hub-session-orchestrator.js +122 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +16 -0
- package/dist/package-registry-kind.d.ts +70 -0
- package/dist/package-registry-kind.js +260 -0
- package/dist/repo-store/index.d.ts +4 -0
- package/dist/repo-store/index.js +3 -0
- package/dist/repo-store/store.d.ts +41 -0
- package/dist/repo-store/store.js +1692 -0
- package/dist/repo-store/subscribe-kind.d.ts +53 -0
- package/dist/repo-store/subscribe-kind.js +179 -0
- package/dist/repo-store/types.d.ts +483 -0
- package/dist/repo-store/types.js +42 -0
- package/dist/session-service.d.ts +235 -0
- package/dist/session-service.js +997 -0
- package/dist/skill-kind.d.ts +41 -0
- package/dist/skill-kind.js +288 -0
- package/dist/substrate.d.ts +8 -0
- package/dist/substrate.js +21 -0
- package/dist/workflow-kind.d.ts +21 -0
- package/dist/workflow-kind.js +263 -0
- package/dist/workflow-run-event-log.d.ts +21 -0
- package/dist/workflow-run-event-log.js +51 -0
- package/dist/workflow-run-kind.d.ts +326 -0
- package/dist/workflow-run-kind.js +2646 -0
- package/dist/workflow-run-reader.d.ts +47 -0
- package/dist/workflow-run-reader.js +157 -0
- package/dist/ws/index.d.ts +3 -0
- package/dist/ws/index.js +3 -0
- package/dist/ws/sidecar-events.d.ts +134 -0
- package/dist/ws/sidecar-events.js +70 -0
- package/dist/ws/sidecar-handler.d.ts +184 -0
- package/dist/ws/sidecar-handler.js +1603 -0
- package/dist/ws/sidecar-token-authenticator.d.ts +15 -0
- package/dist/ws/sidecar-token-authenticator.js +24 -0
- package/package.json +34 -12
- package/src/agent-repo.test.ts +0 -310
- package/src/agent-repo.ts +0 -165
- package/src/agent-state-kind.test.ts +0 -247
- package/src/agent-state-kind.ts +0 -204
- package/src/asset-service.test.ts +0 -540
- package/src/asset-service.ts +0 -378
- package/src/available-skills-stanza.test.ts +0 -87
- package/src/available-skills-stanza.ts +0 -47
- package/src/credential-push.ts +0 -65
- package/src/event-collector-registry.test.ts +0 -73
- package/src/event-collector-registry.ts +0 -171
- package/src/event-collector.test.ts +0 -1387
- package/src/event-collector.ts +0 -424
- package/src/hub-session-lookups.ts +0 -206
- package/src/hub-session-orchestrator.test.ts +0 -510
- package/src/hub-session-orchestrator.ts +0 -213
- package/src/index.ts +0 -78
- package/src/repo-store/index.ts +0 -15
- package/src/repo-store/store.test.ts +0 -1169
- package/src/repo-store/store.ts +0 -428
- package/src/repo-store/types.ts +0 -253
- package/src/session-service.test.ts +0 -895
- package/src/session-service.ts +0 -464
- package/src/skill-kind.test.ts +0 -599
- package/src/skill-kind.ts +0 -350
- package/src/ws/index.ts +0 -18
- package/src/ws/sidecar-events.test.ts +0 -96
- package/src/ws/sidecar-events.ts +0 -231
- package/src/ws/sidecar-handler.test.ts +0 -2217
- package/src/ws/sidecar-handler.ts +0 -1574
- package/tsconfig.json +0 -4
- 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
|
-
}
|