@bradygaster/squad-sdk 0.8.0 → 0.8.3
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/dist/adapter/client.d.ts +24 -4
- package/dist/adapter/client.d.ts.map +1 -1
- package/dist/adapter/client.js +368 -78
- package/dist/adapter/client.js.map +1 -1
- package/dist/adapter/types.d.ts +38 -0
- package/dist/adapter/types.d.ts.map +1 -1
- package/dist/agents/index.d.ts +6 -3
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +132 -23
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/lifecycle.d.ts.map +1 -1
- package/dist/agents/lifecycle.js +28 -2
- package/dist/agents/lifecycle.js.map +1 -1
- package/dist/agents/model-selector.d.ts.map +1 -1
- package/dist/agents/model-selector.js +10 -37
- package/dist/agents/model-selector.js.map +1 -1
- package/dist/casting/index.d.ts.map +1 -1
- package/dist/casting/index.js +10 -2
- package/dist/casting/index.js.map +1 -1
- package/dist/client/event-bus.d.ts.map +1 -1
- package/dist/client/event-bus.js +0 -1
- package/dist/client/event-bus.js.map +1 -1
- package/dist/client/index.d.ts +7 -4
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +22 -10
- package/dist/client/index.js.map +1 -1
- package/dist/config/init.d.ts.map +1 -1
- package/dist/config/init.js +19 -12
- package/dist/config/init.js.map +1 -1
- package/dist/coordinator/coordinator.d.ts.map +1 -1
- package/dist/coordinator/coordinator.js +73 -55
- package/dist/coordinator/coordinator.js.map +1 -1
- package/dist/coordinator/index.d.ts +19 -4
- package/dist/coordinator/index.d.ts.map +1 -1
- package/dist/coordinator/index.js +138 -21
- package/dist/coordinator/index.js.map +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/ralph/index.d.ts +3 -1
- package/dist/ralph/index.d.ts.map +1 -1
- package/dist/ralph/index.js +83 -16
- package/dist/ralph/index.js.map +1 -1
- package/dist/resolution.d.ts +59 -0
- package/dist/resolution.d.ts.map +1 -1
- package/dist/resolution.js +145 -0
- package/dist/resolution.js.map +1 -1
- package/dist/runtime/config.d.ts +3 -2
- package/dist/runtime/config.d.ts.map +1 -1
- package/dist/runtime/config.js +7 -6
- package/dist/runtime/config.js.map +1 -1
- package/dist/runtime/constants.d.ts +35 -0
- package/dist/runtime/constants.d.ts.map +1 -0
- package/dist/runtime/constants.js +58 -0
- package/dist/runtime/constants.js.map +1 -0
- package/dist/runtime/event-bus-otel-bridge.d.ts +19 -0
- package/dist/runtime/event-bus-otel-bridge.d.ts.map +1 -0
- package/dist/runtime/event-bus-otel-bridge.js +61 -0
- package/dist/runtime/event-bus-otel-bridge.js.map +1 -0
- package/dist/runtime/event-bus-ws-bridge.d.ts +35 -0
- package/dist/runtime/event-bus-ws-bridge.d.ts.map +1 -0
- package/dist/runtime/event-bus-ws-bridge.js +55 -0
- package/dist/runtime/event-bus-ws-bridge.js.map +1 -0
- package/dist/runtime/event-payloads.d.ts +108 -0
- package/dist/runtime/event-payloads.d.ts.map +1 -0
- package/dist/runtime/event-payloads.js +28 -0
- package/dist/runtime/event-payloads.js.map +1 -0
- package/dist/runtime/health.d.ts.map +1 -1
- package/dist/runtime/health.js +2 -1
- package/dist/runtime/health.js.map +1 -1
- package/dist/runtime/otel-bridge.d.ts +52 -0
- package/dist/runtime/otel-bridge.d.ts.map +1 -0
- package/dist/runtime/otel-bridge.js +132 -0
- package/dist/runtime/otel-bridge.js.map +1 -0
- package/dist/runtime/otel-init.d.ts +72 -0
- package/dist/runtime/otel-init.d.ts.map +1 -0
- package/dist/runtime/otel-init.js +68 -0
- package/dist/runtime/otel-init.js.map +1 -0
- package/dist/runtime/otel-metrics.d.ts +42 -0
- package/dist/runtime/otel-metrics.d.ts.map +1 -0
- package/dist/runtime/otel-metrics.js +196 -0
- package/dist/runtime/otel-metrics.js.map +1 -0
- package/dist/runtime/otel.d.ts +53 -0
- package/dist/runtime/otel.d.ts.map +1 -0
- package/dist/runtime/otel.js +127 -0
- package/dist/runtime/otel.js.map +1 -0
- package/dist/runtime/squad-observer.d.ts +75 -0
- package/dist/runtime/squad-observer.d.ts.map +1 -0
- package/dist/runtime/squad-observer.js +190 -0
- package/dist/runtime/squad-observer.js.map +1 -0
- package/dist/runtime/streaming.d.ts +9 -0
- package/dist/runtime/streaming.d.ts.map +1 -1
- package/dist/runtime/streaming.js +37 -1
- package/dist/runtime/streaming.js.map +1 -1
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +57 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/upstream/index.d.ts +8 -0
- package/dist/upstream/index.d.ts.map +1 -0
- package/dist/upstream/index.js +7 -0
- package/dist/upstream/index.js.map +1 -0
- package/dist/upstream/resolver.d.ts +37 -0
- package/dist/upstream/resolver.d.ts.map +1 -0
- package/dist/upstream/resolver.js +234 -0
- package/dist/upstream/resolver.js.map +1 -0
- package/dist/upstream/types.d.ts +55 -0
- package/dist/upstream/types.d.ts.map +1 -0
- package/dist/upstream/types.js +11 -0
- package/dist/upstream/types.js.map +1 -0
- package/package.json +84 -2
|
@@ -11,7 +11,10 @@ export { SquadCoordinator, } from './coordinator.js';
|
|
|
11
11
|
export { DirectResponseHandler, } from './direct-response.js';
|
|
12
12
|
// --- M1-10 Fan-Out ---
|
|
13
13
|
export { spawnParallel, aggregateSessionEvents, } from './fan-out.js';
|
|
14
|
-
// ---
|
|
14
|
+
// --- M3-4 Response Tiers ---
|
|
15
|
+
export { selectResponseTier, getTier, } from './response-tiers.js';
|
|
16
|
+
import { trace, SpanStatusCode } from '@opentelemetry/api';
|
|
17
|
+
const tracer = trace.getTracer('squad-sdk');
|
|
15
18
|
export class Coordinator {
|
|
16
19
|
client = null;
|
|
17
20
|
eventBus = null;
|
|
@@ -19,36 +22,150 @@ export class Coordinator {
|
|
|
19
22
|
hookPipeline = null;
|
|
20
23
|
toolRegistry = null;
|
|
21
24
|
config;
|
|
22
|
-
|
|
25
|
+
initialized = false;
|
|
26
|
+
unsubscribers = [];
|
|
27
|
+
constructor(config, deps) {
|
|
23
28
|
this.config = config;
|
|
24
|
-
|
|
29
|
+
if (deps) {
|
|
30
|
+
this.client = deps.client ?? null;
|
|
31
|
+
this.eventBus = deps.eventBus ?? null;
|
|
32
|
+
this.agentManager = deps.agentManager ?? null;
|
|
33
|
+
this.hookPipeline = deps.hookPipeline ?? null;
|
|
34
|
+
this.toolRegistry = deps.toolRegistry ?? null;
|
|
35
|
+
}
|
|
25
36
|
}
|
|
26
|
-
/** Initialize the coordinator:
|
|
37
|
+
/** Initialize the coordinator: wire up event subscriptions and mark ready */
|
|
27
38
|
async initialize() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
const span = tracer.startSpan('squad.coordinator.initialize');
|
|
40
|
+
try {
|
|
41
|
+
if (this.eventBus) {
|
|
42
|
+
this.unsubscribers.push(this.eventBus.subscribe('session:created', (event) => {
|
|
43
|
+
console.log(`[Coordinator] Session created: ${event.sessionId ?? 'unknown'}`);
|
|
44
|
+
}));
|
|
45
|
+
this.unsubscribers.push(this.eventBus.subscribe('session:error', (event) => {
|
|
46
|
+
console.log(`[Coordinator] Session error: ${event.sessionId ?? 'unknown'}`);
|
|
47
|
+
}));
|
|
48
|
+
this.unsubscribers.push(this.eventBus.subscribe('session:destroyed', (event) => {
|
|
49
|
+
console.log(`[Coordinator] Session destroyed: ${event.sessionId ?? 'unknown'}`);
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
this.initialized = true;
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
56
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
57
|
+
throw err;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
span.end();
|
|
61
|
+
}
|
|
34
62
|
}
|
|
35
63
|
/** Route an incoming user message to the appropriate agent(s) */
|
|
36
64
|
async route(message) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
const span = tracer.startSpan('squad.coordinator.route');
|
|
66
|
+
span.setAttribute('message.length', message.length);
|
|
67
|
+
try {
|
|
68
|
+
const lower = message.toLowerCase().trim();
|
|
69
|
+
let decision;
|
|
70
|
+
// Direct response: status queries, factual questions
|
|
71
|
+
if (/^(status|help|what is|who is|how many|show|list)\b/.test(lower)) {
|
|
72
|
+
decision = {
|
|
73
|
+
tier: 'direct',
|
|
74
|
+
agents: [],
|
|
75
|
+
parallel: false,
|
|
76
|
+
rationale: `Direct response for informational query: "${message}"`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Agent name mention — route to that specific agent
|
|
81
|
+
const agentMention = lower.match(/@(\w+)/);
|
|
82
|
+
if (agentMention) {
|
|
83
|
+
decision = {
|
|
84
|
+
tier: 'standard',
|
|
85
|
+
agents: [agentMention[1]],
|
|
86
|
+
parallel: false,
|
|
87
|
+
rationale: `Routed to mentioned agent: ${agentMention[1]}`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else if (/\bteam\b/.test(lower)) {
|
|
91
|
+
// Team-wide task — fan-out to all agents
|
|
92
|
+
decision = {
|
|
93
|
+
tier: 'full',
|
|
94
|
+
agents: ['all'],
|
|
95
|
+
parallel: true,
|
|
96
|
+
rationale: 'Team-wide task detected — fan-out to all agents',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Default: route to lead agent (Keaton)
|
|
101
|
+
decision = {
|
|
102
|
+
tier: 'standard',
|
|
103
|
+
agents: ['lead'],
|
|
104
|
+
parallel: false,
|
|
105
|
+
rationale: 'Default routing to lead agent (Keaton)',
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
span.setAttribute('routing.tier', decision.tier);
|
|
110
|
+
span.setAttribute('target.agents', decision.agents.join(','));
|
|
111
|
+
span.setAttribute('routing.reason', decision.rationale);
|
|
112
|
+
return decision;
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
116
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
span.end();
|
|
121
|
+
}
|
|
41
122
|
}
|
|
42
|
-
/** Execute a routing decision:
|
|
123
|
+
/** Execute a routing decision: emit routing event on EventBus */
|
|
43
124
|
async execute(decision, message) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
125
|
+
const span = tracer.startSpan('squad.coordinator.execute');
|
|
126
|
+
span.setAttribute('routing.tier', decision.tier);
|
|
127
|
+
span.setAttribute('target.agents', decision.agents.join(','));
|
|
128
|
+
try {
|
|
129
|
+
if (this.eventBus) {
|
|
130
|
+
await this.eventBus.emit({
|
|
131
|
+
type: 'coordinator:routing',
|
|
132
|
+
payload: { decision, message },
|
|
133
|
+
timestamp: new Date(),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
139
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
span.end();
|
|
144
|
+
}
|
|
47
145
|
}
|
|
48
|
-
/** Graceful shutdown */
|
|
146
|
+
/** Graceful shutdown: unsubscribe from events and release references */
|
|
49
147
|
async shutdown() {
|
|
50
|
-
|
|
51
|
-
|
|
148
|
+
const span = tracer.startSpan('squad.coordinator.shutdown');
|
|
149
|
+
try {
|
|
150
|
+
for (const unsub of this.unsubscribers) {
|
|
151
|
+
unsub();
|
|
152
|
+
}
|
|
153
|
+
this.unsubscribers = [];
|
|
154
|
+
this.initialized = false;
|
|
155
|
+
this.client = null;
|
|
156
|
+
this.eventBus = null;
|
|
157
|
+
this.agentManager = null;
|
|
158
|
+
this.hookPipeline = null;
|
|
159
|
+
this.toolRegistry = null;
|
|
160
|
+
}
|
|
161
|
+
catch (err) {
|
|
162
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err instanceof Error ? err.message : String(err) });
|
|
163
|
+
span.recordException(err instanceof Error ? err : new Error(String(err)));
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
span.end();
|
|
168
|
+
}
|
|
52
169
|
}
|
|
53
170
|
}
|
|
54
171
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/coordinator/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,2BAA2B;AAC3B,OAAO,EACL,gBAAgB,GAKjB,MAAM,kBAAkB,CAAC;AAE1B,+BAA+B;AAC/B,OAAO,EACL,qBAAqB,GAItB,MAAM,sBAAsB,CAAC;AAE9B,wBAAwB;AACxB,OAAO,EACL,aAAa,EACb,sBAAsB,GAIvB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/coordinator/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,2BAA2B;AAC3B,OAAO,EACL,gBAAgB,GAKjB,MAAM,kBAAkB,CAAC;AAE1B,+BAA+B;AAC/B,OAAO,EACL,qBAAqB,GAItB,MAAM,sBAAsB,CAAC;AAE9B,wBAAwB;AACxB,OAAO,EACL,aAAa,EACb,sBAAsB,GAIvB,MAAM,cAAc,CAAC;AAEtB,8BAA8B;AAC9B,OAAO,EACL,kBAAkB,EAClB,OAAO,GAIR,MAAM,qBAAqB,CAAC;AAS7B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,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC1G,IAAI,CAAC,eAAe,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC1E,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* This module has ZERO side effects. Safe to import as a library.
|
|
4
4
|
* CLI entry point lives in src/cli-entry.ts.
|
|
5
5
|
*/
|
|
6
|
-
export declare const VERSION
|
|
7
|
-
export { resolveSquad, resolveGlobalSquadPath, ensureSquadPath } from './resolution.js';
|
|
6
|
+
export declare const VERSION: string;
|
|
7
|
+
export { resolveSquad, resolveSquadPaths, resolveGlobalSquadPath, ensureSquadPath, ensureSquadPathDual, ensureSquadPathResolved } from './resolution.js';
|
|
8
|
+
export type { ResolvedSquadPaths, SquadDirConfig } from './resolution.js';
|
|
9
|
+
export { MODELS, TIMEOUTS, AGENT_ROLES } from './runtime/constants.js';
|
|
8
10
|
export * from './config/index.js';
|
|
9
11
|
export * from './agents/onboarding.js';
|
|
10
12
|
export * from './casting/index.js';
|
|
@@ -19,7 +21,15 @@ export * from './runtime/telemetry.js';
|
|
|
19
21
|
export * from './runtime/offline.js';
|
|
20
22
|
export * from './runtime/i18n.js';
|
|
21
23
|
export * from './runtime/benchmarks.js';
|
|
24
|
+
export * from './runtime/otel.js';
|
|
25
|
+
export { createOTelTransport, bridgeEventBusToOTel } from './runtime/otel-bridge.js';
|
|
26
|
+
export * from './runtime/otel-metrics.js';
|
|
27
|
+
export { initSquadTelemetry } from './runtime/otel-init.js';
|
|
28
|
+
export type { SquadTelemetryOptions, SquadTelemetryHandle } from './runtime/otel-init.js';
|
|
29
|
+
export { SquadObserver, classifyFile } from './runtime/squad-observer.js';
|
|
30
|
+
export type { SquadFileChange, SquadFileCategory, SquadObserverConfig } from './runtime/squad-observer.js';
|
|
22
31
|
export * from './marketplace/index.js';
|
|
23
32
|
export * from './build/index.js';
|
|
24
33
|
export * from './sharing/index.js';
|
|
34
|
+
export * from './upstream/index.js';
|
|
25
35
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,eAAO,MAAM,OAAO,EAAE,MAAoB,CAAC;AAG3C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,eAAe,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACzJ,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACvE,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAChH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACnF,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrF,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC1E,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAE3G,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
* This module has ZERO side effects. Safe to import as a library.
|
|
4
4
|
* CLI entry point lives in src/cli-entry.ts.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const pkg = require('../package.json');
|
|
9
|
+
export const VERSION = pkg.version;
|
|
7
10
|
// Export public API
|
|
8
|
-
export { resolveSquad, resolveGlobalSquadPath, ensureSquadPath } from './resolution.js';
|
|
11
|
+
export { resolveSquad, resolveSquadPaths, resolveGlobalSquadPath, ensureSquadPath, ensureSquadPathDual, ensureSquadPathResolved } from './resolution.js';
|
|
12
|
+
export { MODELS, TIMEOUTS, AGENT_ROLES } from './runtime/constants.js';
|
|
9
13
|
export * from './config/index.js';
|
|
10
14
|
export * from './agents/onboarding.js';
|
|
11
15
|
export * from './casting/index.js';
|
|
@@ -18,7 +22,13 @@ export * from './runtime/telemetry.js';
|
|
|
18
22
|
export * from './runtime/offline.js';
|
|
19
23
|
export * from './runtime/i18n.js';
|
|
20
24
|
export * from './runtime/benchmarks.js';
|
|
25
|
+
export * from './runtime/otel.js';
|
|
26
|
+
export { createOTelTransport, bridgeEventBusToOTel } from './runtime/otel-bridge.js';
|
|
27
|
+
export * from './runtime/otel-metrics.js';
|
|
28
|
+
export { initSquadTelemetry } from './runtime/otel-init.js';
|
|
29
|
+
export { SquadObserver, classifyFile } from './runtime/squad-observer.js';
|
|
21
30
|
export * from './marketplace/index.js';
|
|
22
31
|
export * from './build/index.js';
|
|
23
32
|
export * from './sharing/index.js';
|
|
33
|
+
export * from './upstream/index.js';
|
|
24
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,OAAO,GAAW,GAAG,CAAC,OAAO,CAAC;AAE3C,oBAAoB;AACpB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,eAAe,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAEzJ,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACvE,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEjE,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACrF,cAAc,2BAA2B,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG1E,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
|
package/dist/ralph/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* 2. Watchdog: Periodic health checks on session pool
|
|
11
11
|
* 3. Cloud heartbeat: External health signal (future)
|
|
12
12
|
*/
|
|
13
|
-
import type { EventBus } from '../
|
|
13
|
+
import type { EventBus } from '../runtime/event-bus.js';
|
|
14
14
|
export interface MonitorConfig {
|
|
15
15
|
/** Team root directory */
|
|
16
16
|
teamRoot: string;
|
|
@@ -41,6 +41,8 @@ export declare class RalphMonitor {
|
|
|
41
41
|
private config;
|
|
42
42
|
private state;
|
|
43
43
|
private eventBus;
|
|
44
|
+
private unsubscribers;
|
|
45
|
+
private healthCheckTimer;
|
|
44
46
|
constructor(config: MonitorConfig);
|
|
45
47
|
/** Start monitoring — subscribe to EventBus and begin health checks */
|
|
46
48
|
start(eventBus: EventBus): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ralph/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ralph/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAc,MAAM,yBAAyB,CAAC;AAIpE,MAAM,WAAW,aAAa;IAC5B,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IAEjB,iDAAiD;IACjD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,oDAAoD;IACpD,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IAC/C,YAAY,EAAE,IAAI,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,qCAAqC;IACrC,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;IAC7B,4BAA4B;IAC5B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACrC,6CAA6C;IAC7C,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAID,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,aAAa,CAAsB;IAC3C,OAAO,CAAC,gBAAgB,CAA+C;gBAE3D,MAAM,EAAE,aAAa;IASjC,uEAAuE;IACjE,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB9C,iDAAiD;IACjD,OAAO,CAAC,WAAW;IA6CnB,2DAA2D;IACrD,WAAW,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAc/C,6CAA6C;IAC7C,SAAS,IAAI,eAAe,EAAE;IAI9B,8CAA8C;IACxC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAyB5B"}
|
package/dist/ralph/index.js
CHANGED
|
@@ -10,11 +10,14 @@
|
|
|
10
10
|
* 2. Watchdog: Periodic health checks on session pool
|
|
11
11
|
* 3. Cloud heartbeat: External health signal (future)
|
|
12
12
|
*/
|
|
13
|
+
import { writeFile } from 'node:fs/promises';
|
|
13
14
|
// --- Ralph Monitor ---
|
|
14
15
|
export class RalphMonitor {
|
|
15
16
|
config;
|
|
16
17
|
state;
|
|
17
18
|
eventBus = null;
|
|
19
|
+
unsubscribers = [];
|
|
20
|
+
healthCheckTimer = null;
|
|
18
21
|
constructor(config) {
|
|
19
22
|
this.config = config;
|
|
20
23
|
this.state = {
|
|
@@ -22,29 +25,76 @@ export class RalphMonitor {
|
|
|
22
25
|
agents: new Map(),
|
|
23
26
|
observations: [],
|
|
24
27
|
};
|
|
25
|
-
// TODO: PRD 8 — Load persisted state from statePath if exists
|
|
26
|
-
// TODO: PRD 8 — Initialize as persistent SDK session via resumeSession('squad-ralph')
|
|
27
28
|
}
|
|
28
29
|
/** Start monitoring — subscribe to EventBus and begin health checks */
|
|
29
30
|
async start(eventBus) {
|
|
30
31
|
this.eventBus = eventBus;
|
|
31
|
-
//
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
// Subscribe to session lifecycle events
|
|
33
|
+
this.unsubscribers.push(eventBus.subscribe('session:created', (event) => this.handleEvent(event)));
|
|
34
|
+
this.unsubscribers.push(eventBus.subscribe('session:destroyed', (event) => this.handleEvent(event)));
|
|
35
|
+
this.unsubscribers.push(eventBus.subscribe('session:error', (event) => this.handleEvent(event)));
|
|
36
|
+
this.unsubscribers.push(eventBus.subscribe('agent:milestone', (event) => this.handleEvent(event)));
|
|
37
|
+
// Start periodic health check
|
|
38
|
+
const interval = this.config.healthCheckInterval ?? 30_000;
|
|
39
|
+
this.healthCheckTimer = setInterval(() => {
|
|
40
|
+
void this.healthCheck();
|
|
41
|
+
}, interval);
|
|
35
42
|
}
|
|
36
43
|
/** Handle an incoming event from the EventBus */
|
|
37
44
|
handleEvent(event) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
const agentName = event.agentName ?? 'unknown';
|
|
46
|
+
const sessionId = event.sessionId ?? 'unknown';
|
|
47
|
+
switch (event.type) {
|
|
48
|
+
case 'session:created': {
|
|
49
|
+
this.state.agents.set(agentName, {
|
|
50
|
+
agentName,
|
|
51
|
+
sessionId,
|
|
52
|
+
status: 'working',
|
|
53
|
+
lastActivity: event.timestamp,
|
|
54
|
+
milestones: [],
|
|
55
|
+
});
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case 'session:destroyed': {
|
|
59
|
+
this.state.agents.delete(agentName);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case 'session:error': {
|
|
63
|
+
const existing = this.state.agents.get(agentName);
|
|
64
|
+
if (existing) {
|
|
65
|
+
existing.status = 'error';
|
|
66
|
+
existing.lastActivity = event.timestamp;
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case 'agent:milestone': {
|
|
71
|
+
const agent = this.state.agents.get(agentName);
|
|
72
|
+
if (agent) {
|
|
73
|
+
const payload = event.payload;
|
|
74
|
+
if (payload?.milestone) {
|
|
75
|
+
agent.milestones.push(payload.milestone);
|
|
76
|
+
}
|
|
77
|
+
if (payload?.task) {
|
|
78
|
+
agent.currentTask = payload.task;
|
|
79
|
+
}
|
|
80
|
+
agent.lastActivity = event.timestamp;
|
|
81
|
+
agent.status = 'working';
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
41
86
|
}
|
|
42
87
|
/** Run a health check across all tracked agent sessions */
|
|
43
88
|
async healthCheck() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
89
|
+
const now = new Date();
|
|
90
|
+
const staleThreshold = this.config.staleSessionThreshold ?? 300_000;
|
|
91
|
+
for (const agent of this.state.agents.values()) {
|
|
92
|
+
if (agent.status === 'error')
|
|
93
|
+
continue;
|
|
94
|
+
const elapsed = now.getTime() - agent.lastActivity.getTime();
|
|
95
|
+
agent.status = elapsed > staleThreshold ? 'stale' : agent.status === 'stale' ? 'idle' : agent.status;
|
|
96
|
+
}
|
|
97
|
+
this.state.lastHealthCheck = now;
|
|
48
98
|
return Array.from(this.state.agents.values());
|
|
49
99
|
}
|
|
50
100
|
/** Get current work status for all agents */
|
|
@@ -53,9 +103,26 @@ export class RalphMonitor {
|
|
|
53
103
|
}
|
|
54
104
|
/** Stop monitoring and persist final state */
|
|
55
105
|
async stop() {
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
106
|
+
// Unsubscribe from EventBus
|
|
107
|
+
for (const unsub of this.unsubscribers) {
|
|
108
|
+
unsub();
|
|
109
|
+
}
|
|
110
|
+
this.unsubscribers = [];
|
|
111
|
+
// Stop health check timer
|
|
112
|
+
if (this.healthCheckTimer !== null) {
|
|
113
|
+
clearInterval(this.healthCheckTimer);
|
|
114
|
+
this.healthCheckTimer = null;
|
|
115
|
+
}
|
|
116
|
+
// Persist state if statePath is configured
|
|
117
|
+
if (this.config.statePath) {
|
|
118
|
+
const serializable = {
|
|
119
|
+
lastHealthCheck: this.state.lastHealthCheck?.toISOString() ?? null,
|
|
120
|
+
agents: Array.from(this.state.agents.entries()),
|
|
121
|
+
observations: this.state.observations,
|
|
122
|
+
};
|
|
123
|
+
await writeFile(this.config.statePath, JSON.stringify(serializable, null, 2), 'utf-8');
|
|
124
|
+
}
|
|
125
|
+
this.eventBus = null;
|
|
59
126
|
}
|
|
60
127
|
}
|
|
61
128
|
//# sourceMappingURL=index.js.map
|
package/dist/ralph/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ralph/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ralph/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAY,MAAM,kBAAkB,CAAC;AAqCvD,wBAAwB;AAExB,MAAM,OAAO,YAAY;IACf,MAAM,CAAgB;IACtB,KAAK,CAAe;IACpB,QAAQ,GAAoB,IAAI,CAAC;IACjC,aAAa,GAAmB,EAAE,CAAC;IACnC,gBAAgB,GAA0C,IAAI,CAAC;IAEvE,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG;YACX,eAAe,EAAE,IAAI;YACrB,MAAM,EAAE,IAAI,GAAG,EAAE;YACjB,YAAY,EAAE,EAAE;SACjB,CAAC;IACJ,CAAC;IAED,uEAAuE;IACvE,KAAK,CAAC,KAAK,CAAC,QAAkB;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,wCAAwC;QACxC,IAAI,CAAC,aAAa,CAAC,IAAI,CACrB,QAAQ,CAAC,SAAS,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAC1E,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,IAAI,CACrB,QAAQ,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAC5E,CAAC;QACF,IAAI,CAAC,aAAa,CAAC,IAAI,CACrB,QAAQ,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,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CAAC,EAAE,OAAO,CAAC,CAAC;QACzF,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CACF"}
|
package/dist/resolution.d.ts
CHANGED
|
@@ -2,10 +2,41 @@
|
|
|
2
2
|
* Squad directory resolution — walk-up and global path algorithms.
|
|
3
3
|
*
|
|
4
4
|
* resolveSquad() — find .squad/ by walking up from startDir to .git boundary
|
|
5
|
+
* resolveSquadPaths() — dual-root resolution (projectDir / teamDir) for remote squad mode
|
|
5
6
|
* resolveGlobalSquadPath() — platform-specific global config directory
|
|
6
7
|
*
|
|
8
|
+
* Dual-root resolution and remote mode design ported from @spboyer (Shayne Boyer)'s
|
|
9
|
+
* PR bradygaster/squad#131. Original concept: resolveSquadPaths() with config.json
|
|
10
|
+
* pointer for team identity separation.
|
|
11
|
+
*
|
|
7
12
|
* @module resolution
|
|
8
13
|
*/
|
|
14
|
+
/**
|
|
15
|
+
* Schema for `.squad/config.json` — controls remote squad mode.
|
|
16
|
+
* Named SquadDirConfig to avoid collision with the runtime SquadConfig.
|
|
17
|
+
*/
|
|
18
|
+
export interface SquadDirConfig {
|
|
19
|
+
version: number;
|
|
20
|
+
teamRoot: string;
|
|
21
|
+
projectKey: string | null;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolved paths for dual-root squad mode.
|
|
25
|
+
*
|
|
26
|
+
* In **local** mode, projectDir and teamDir point to the same `.squad/` directory.
|
|
27
|
+
* In **remote** mode, config.json specifies a `teamRoot` that resolves to a
|
|
28
|
+
* separate directory for team identity (agents, casting, skills).
|
|
29
|
+
*/
|
|
30
|
+
export interface ResolvedSquadPaths {
|
|
31
|
+
mode: 'local' | 'remote';
|
|
32
|
+
/** Project-local .squad/ (decisions, logs) */
|
|
33
|
+
projectDir: string;
|
|
34
|
+
/** Team identity root (agents, casting, skills) */
|
|
35
|
+
teamDir: string;
|
|
36
|
+
config: SquadDirConfig | null;
|
|
37
|
+
name: '.squad' | '.ai-team';
|
|
38
|
+
isLegacy: boolean;
|
|
39
|
+
}
|
|
9
40
|
/**
|
|
10
41
|
* Walk up the directory tree from `startDir` looking for a `.squad/` directory.
|
|
11
42
|
*
|
|
@@ -18,6 +49,18 @@
|
|
|
18
49
|
* @returns Absolute path to `.squad/` or `null`.
|
|
19
50
|
*/
|
|
20
51
|
export declare function resolveSquad(startDir?: string): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve dual-root squad paths (projectDir / teamDir).
|
|
54
|
+
*
|
|
55
|
+
* - Walks up from `startDir` looking for `.squad/` (or `.ai-team/` for legacy repos).
|
|
56
|
+
* - If `.squad/config.json` exists with a valid `teamRoot` → **remote** mode:
|
|
57
|
+
* teamDir is resolved relative to the **project root** (parent of .squad/).
|
|
58
|
+
* - Otherwise → **local** mode: projectDir === teamDir.
|
|
59
|
+
*
|
|
60
|
+
* @param startDir - Directory to start searching from. Defaults to `process.cwd()`.
|
|
61
|
+
* @returns Resolved paths, or `null` if no squad directory is found.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveSquadPaths(startDir?: string): ResolvedSquadPaths | null;
|
|
21
64
|
/**
|
|
22
65
|
* Return the platform-specific global Squad configuration directory.
|
|
23
66
|
*
|
|
@@ -44,4 +87,20 @@ export declare function resolveGlobalSquadPath(): string;
|
|
|
44
87
|
* @throws If `filePath` is outside `.squad/` and not in the system temp directory.
|
|
45
88
|
*/
|
|
46
89
|
export declare function ensureSquadPath(filePath: string, squadRoot: string): string;
|
|
90
|
+
/**
|
|
91
|
+
* Validate that a file path is within either the projectDir or teamDir
|
|
92
|
+
* (or the system temp directory). For use in dual-root / remote mode.
|
|
93
|
+
*
|
|
94
|
+
* @param filePath - Absolute path to validate.
|
|
95
|
+
* @param projectDir - Absolute path to the project-local .squad/ directory.
|
|
96
|
+
* @param teamDir - Absolute path to the team identity directory.
|
|
97
|
+
* @returns The resolved absolute filePath if it is safe.
|
|
98
|
+
* @throws If filePath is outside both roots and not in the system temp directory.
|
|
99
|
+
*/
|
|
100
|
+
export declare function ensureSquadPathDual(filePath: string, projectDir: string, teamDir: string): string;
|
|
101
|
+
/**
|
|
102
|
+
* ensureSquadPath that works with resolved dual-root paths.
|
|
103
|
+
* Convenience wrapper around ensureSquadPathDual.
|
|
104
|
+
*/
|
|
105
|
+
export declare function ensureSquadPathResolved(filePath: string, paths: ResolvedSquadPaths): string;
|
|
47
106
|
//# sourceMappingURL=resolution.d.ts.map
|
package/dist/resolution.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../src/resolution.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resolution.d.ts","sourceRoot":"","sources":["../src/resolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzB,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAC;IAC5B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA2B7D;AAuED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAiC9E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAuB/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAmB3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAyBjG;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,MAAM,CAE3F"}
|