pi-harness-runtime 1.1.336 → 1.1.338
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/index.ts +21 -12
- package/package.json +1 -1
- package/packages/a2a-adapter/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/architecture-generator/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-refactor/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/cache-strategy/package.json +1 -1
- package/packages/capability-registry/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/cli-plugin-sdk/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/clipboard-plugin/package.json +1 -1
- package/packages/code-generation/package.json +1 -1
- package/packages/code-review/package.json +1 -1
- package/packages/codex-adapter/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/connection-runtime/dist/index.d.ts +11 -0
- package/packages/connection-runtime/dist/index.js +11 -0
- package/packages/connection-runtime/dist/registry.d.ts +69 -0
- package/packages/connection-runtime/dist/registry.js +117 -0
- package/packages/connection-runtime/dist/supervisor.d.ts +89 -0
- package/packages/connection-runtime/dist/supervisor.js +169 -0
- package/packages/connection-runtime/dist/types.d.ts +70 -0
- package/packages/connection-runtime/dist/types.js +16 -0
- package/packages/connection-runtime/package.json +24 -0
- package/packages/connection-runtime/src/index.ts +12 -0
- package/packages/connection-runtime/src/registry.ts +142 -0
- package/packages/connection-runtime/src/supervisor.ts +224 -0
- package/packages/connection-runtime/src/types.ts +88 -0
- package/packages/context-compiler/package.json +1 -1
- package/packages/context-discovery/package.json +1 -1
- package/packages/context-manager/package.json +1 -1
- package/packages/contracts/dist/approvals.d.ts +273 -0
- package/packages/contracts/dist/approvals.js +93 -0
- package/packages/contracts/dist/base.d.ts +78 -0
- package/packages/contracts/dist/base.js +82 -0
- package/packages/contracts/dist/events.d.ts +99 -0
- package/packages/contracts/dist/events.js +65 -0
- package/packages/contracts/dist/index.d.ts +20 -0
- package/packages/contracts/dist/index.js +20 -0
- package/packages/contracts/dist/jobs.d.ts +234 -0
- package/packages/contracts/dist/jobs.js +79 -0
- package/packages/contracts/dist/notifications.d.ts +317 -0
- package/packages/contracts/dist/notifications.js +85 -0
- package/packages/contracts/dist/projects.d.ts +171 -0
- package/packages/contracts/dist/projects.js +62 -0
- package/packages/contracts/dist/sessions.d.ts +226 -0
- package/packages/contracts/dist/sessions.js +82 -0
- package/packages/contracts/package.json +24 -0
- package/packages/contracts/src/approvals.ts +115 -0
- package/packages/contracts/src/base.ts +126 -0
- package/packages/contracts/src/events.ts +78 -0
- package/packages/contracts/src/index.ts +21 -0
- package/packages/contracts/src/jobs.ts +101 -0
- package/packages/contracts/src/notifications.ts +104 -0
- package/packages/contracts/src/projects.ts +81 -0
- package/packages/contracts/src/sessions.ts +104 -0
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cost-optimizer/package.json +1 -1
- package/packages/dependency-analyzer/package.json +1 -1
- package/packages/django-plugin/package.json +1 -1
- package/packages/doc-generator/package.json +1 -1
- package/packages/durable-review/package.json +1 -1
- package/packages/e2e-tester/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/evaluation-runner/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-sink/dist/index.d.ts +12 -0
- package/packages/event-sink/dist/index.js +12 -0
- package/packages/event-sink/dist/outbox.d.ts +51 -0
- package/packages/event-sink/dist/outbox.js +88 -0
- package/packages/event-sink/dist/projection.d.ts +41 -0
- package/packages/event-sink/dist/projection.js +62 -0
- package/packages/event-sink/dist/sink.d.ts +81 -0
- package/packages/event-sink/dist/sink.js +106 -0
- package/packages/event-sink/package.json +28 -0
- package/packages/event-sink/src/index.ts +15 -0
- package/packages/event-sink/src/outbox.ts +119 -0
- package/packages/event-sink/src/projection.ts +84 -0
- package/packages/event-sink/src/sink.ts +167 -0
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/feedback-collector/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/framework-detector/package.json +1 -1
- package/packages/framework-plugin-sdk/package.json +1 -1
- package/packages/frappe-plugin/package.json +1 -1
- package/packages/generic-web-plugin/package.json +1 -1
- package/packages/health-monitor/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-graph/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/laravel-plugin/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/mcp-adapter/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/milestone-manager/package.json +1 -1
- package/packages/model-registry/package.json +1 -1
- package/packages/nextjs-plugin/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/observability/package.json +1 -1
- package/packages/okf-indexer/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/permission-mode/dist/checker.d.ts +66 -0
- package/packages/permission-mode/dist/checker.js +64 -0
- package/packages/permission-mode/dist/index.d.ts +12 -0
- package/packages/permission-mode/dist/index.js +11 -0
- package/packages/permission-mode/dist/manager.d.ts +65 -0
- package/packages/permission-mode/dist/manager.js +91 -0
- package/packages/permission-mode/dist/mode.d.ts +31 -0
- package/packages/permission-mode/dist/mode.js +47 -0
- package/packages/permission-mode/package.json +24 -0
- package/packages/permission-mode/src/checker.ts +103 -0
- package/packages/permission-mode/src/index.ts +13 -0
- package/packages/permission-mode/src/manager.ts +154 -0
- package/packages/permission-mode/src/mode.ts +73 -0
- package/packages/privilege-broker/package.json +1 -1
- package/packages/project-analyzer/package.json +1 -1
- package/packages/project-bootstrap/package.json +1 -1
- package/packages/projection-engine/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/prompt-versioning/package.json +1 -1
- package/packages/provider-adapter-sdk/package.json +1 -1
- package/packages/provider-router/package.json +1 -1
- package/packages/provider-selector/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/rate-limiter/package.json +1 -1
- package/packages/react-vite-plugin/package.json +1 -1
- package/packages/relay/dist/client.d.ts +53 -0
- package/packages/relay/dist/client.js +95 -0
- package/packages/relay/dist/index.d.ts +9 -0
- package/packages/relay/dist/index.js +8 -0
- package/packages/relay/dist/server.d.ts +58 -0
- package/packages/relay/dist/server.js +93 -0
- package/packages/relay/dist/types.d.ts +35 -0
- package/packages/relay/dist/types.js +4 -0
- package/packages/relay/package.json +24 -0
- package/packages/relay/src/client.ts +119 -0
- package/packages/relay/src/index.ts +10 -0
- package/packages/relay/src/server.ts +120 -0
- package/packages/relay/src/types.ts +38 -0
- package/packages/release-manager/package.json +1 -1
- package/packages/requirement-compiler/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/scheduler/package.json +1 -1
- package/packages/scheduler-adapter/package.json +1 -1
- package/packages/session/package.json +1 -1
- package/packages/session-api/package.json +1 -1
- package/packages/session-export/package.json +1 -1
- package/packages/shared-context/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skill-registry/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/sprint-planner/package.json +1 -1
- package/packages/subscription-engine/package.json +1 -1
- package/packages/task-compiler/package.json +1 -1
- package/packages/telegram/package.json +1 -1
- package/packages/tencentdb-memory/package.json +1 -1
- package/packages/tencentdb-sync/package.json +1 -1
- package/packages/test-data-generator/package.json +1 -1
- package/packages/test-generator/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/token-optimizer/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/voice-api/dist/index.d.ts +14 -0
- package/packages/voice-api/dist/index.js +12 -0
- package/packages/voice-api/dist/line.d.ts +100 -0
- package/packages/voice-api/dist/line.js +147 -0
- package/packages/voice-api/dist/provider.d.ts +23 -0
- package/packages/voice-api/dist/provider.js +154 -0
- package/packages/voice-api/dist/telegram.d.ts +74 -0
- package/packages/voice-api/dist/telegram.js +119 -0
- package/packages/voice-api/dist/transcriber.d.ts +48 -0
- package/packages/voice-api/dist/transcriber.js +118 -0
- package/packages/voice-api/dist/types.d.ts +75 -0
- package/packages/voice-api/dist/types.js +4 -0
- package/packages/voice-api/package.json +24 -0
- package/packages/voice-api/src/index.ts +15 -0
- package/packages/voice-api/src/line.ts +229 -0
- package/packages/voice-api/src/provider.ts +186 -0
- package/packages/voice-api/src/telegram.ts +191 -0
- package/packages/voice-api/src/transcriber.ts +136 -0
- package/packages/voice-api/src/types.ts +79 -0
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/workflow-events/package.json +1 -1
- package/packages/workspace-scanner/package.json +1 -1
- package/packages/worktree/package.json +1 -1
- package/packages/write-review/package.json +1 -1
package/index.ts
CHANGED
|
@@ -2054,8 +2054,20 @@ let _nc: {
|
|
|
2054
2054
|
ctx: Record<string, unknown>,
|
|
2055
2055
|
options?: { approveLabel?: string; rejectLabel?: string },
|
|
2056
2056
|
) => Promise<unknown>;
|
|
2057
|
+
notifyWithButtons?: (
|
|
2058
|
+
event: string,
|
|
2059
|
+
ctx: Record<string, unknown>,
|
|
2060
|
+
buttons: Array<{ text: string; action: string; targetId: string; url?: string }>,
|
|
2061
|
+
) => Promise<unknown>;
|
|
2057
2062
|
} | null = null;
|
|
2058
2063
|
|
|
2064
|
+
// Type for _nc.center
|
|
2065
|
+
type NcCenter = {
|
|
2066
|
+
notifyWithApproval: Function;
|
|
2067
|
+
notify: Function;
|
|
2068
|
+
notifyWithButtons?: Function;
|
|
2069
|
+
};
|
|
2070
|
+
|
|
2059
2071
|
/**
|
|
2060
2072
|
* Fire a Telegram notification event. Logs delivery outcomes.
|
|
2061
2073
|
* Silently skips if Telegram is not configured.
|
|
@@ -2063,12 +2075,7 @@ let _nc: {
|
|
|
2063
2075
|
async function nc(event: string, ctx: Record<string, unknown>): Promise<void> {
|
|
2064
2076
|
if (!_nc) return;
|
|
2065
2077
|
try {
|
|
2066
|
-
const
|
|
2067
|
-
center: {
|
|
2068
|
-
notifyWithApproval: Function;
|
|
2069
|
-
notify: Function;
|
|
2070
|
-
};
|
|
2071
|
-
};
|
|
2078
|
+
const center = _nc!.center as NcCenter;
|
|
2072
2079
|
|
|
2073
2080
|
// Import policy engine dynamically to check if approval buttons needed
|
|
2074
2081
|
// This is a simple sync check - can be replaced with Jev-powered evaluation
|
|
@@ -2077,9 +2084,9 @@ async function nc(event: string, ctx: Record<string, unknown>): Promise<void> {
|
|
|
2077
2084
|
// Capture results for logging
|
|
2078
2085
|
let results: unknown;
|
|
2079
2086
|
if (requiresApproval(event)) {
|
|
2080
|
-
results = await
|
|
2087
|
+
results = await center.notifyWithApproval(event as never, ctx as never);
|
|
2081
2088
|
} else {
|
|
2082
|
-
results = await
|
|
2089
|
+
results = await center.notify(event as never, ctx as never);
|
|
2083
2090
|
}
|
|
2084
2091
|
|
|
2085
2092
|
// Log delivery outcomes to file
|
|
@@ -2730,10 +2737,11 @@ export default async function (pi: ExtensionAPI) {
|
|
|
2730
2737
|
const doneToken = _createPendingAction(sessionId, "done", projectRoot, "plan");
|
|
2731
2738
|
|
|
2732
2739
|
// Use event type based on stage
|
|
2733
|
-
|
|
2740
|
+
if (hasReviewMarker) {
|
|
2734
2741
|
// Review stage: buttons are Code again and Done
|
|
2735
2742
|
const codeAgainToken = _createPendingAction(sessionId, "code_again", projectRoot, "review");
|
|
2736
|
-
|
|
2743
|
+
// SAFETY: _nc.center is always an object with notifyWithButtons in our usage
|
|
2744
|
+
void (_nc as unknown as { center: { notifyWithButtons: Function } }).center.notifyWithButtons("CodexReviewDetected", {
|
|
2737
2745
|
requirement: msg.text,
|
|
2738
2746
|
taskTitle: sessionId,
|
|
2739
2747
|
details: {
|
|
@@ -2746,9 +2754,10 @@ export default async function (pi: ExtensionAPI) {
|
|
|
2746
2754
|
{ text: "Code again", action: PING_PONG_ACTIONS.CODE_AGAIN, targetId: codeAgainToken },
|
|
2747
2755
|
{ text: "Done", action: PING_PONG_ACTIONS.DONE, targetId: doneToken },
|
|
2748
2756
|
]);
|
|
2749
|
-
|
|
2757
|
+
} else {
|
|
2750
2758
|
// Plan stage: buttons are Code and Done
|
|
2751
|
-
|
|
2759
|
+
// SAFETY: _nc.center is always an object with notifyWithButtons in our usage
|
|
2760
|
+
void (_nc as unknown as { center: { notifyWithButtons: Function } }).center.notifyWithButtons("CodexPlanDetected", {
|
|
2752
2761
|
requirement: msg.text, // Full text, no truncation
|
|
2753
2762
|
taskTitle: sessionId,
|
|
2754
2763
|
details: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-harness/capability-registry",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.338",
|
|
4
4
|
"description": "Capability Registry for pi-harness-runtime — tracks model capabilities and enables capability-based routing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection Runtime for pi-harness
|
|
3
|
+
*
|
|
4
|
+
* Inspired by T3Code's client-runtime:
|
|
5
|
+
* - Jittered exponential backoff for reconnection
|
|
6
|
+
* - One transport retry owner per environment
|
|
7
|
+
* - Shared subscription logic across clients
|
|
8
|
+
*/
|
|
9
|
+
export * from './supervisor.js';
|
|
10
|
+
export * from './registry.js';
|
|
11
|
+
export * from './types.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection Runtime for pi-harness
|
|
3
|
+
*
|
|
4
|
+
* Inspired by T3Code's client-runtime:
|
|
5
|
+
* - Jittered exponential backoff for reconnection
|
|
6
|
+
* - One transport retry owner per environment
|
|
7
|
+
* - Shared subscription logic across clients
|
|
8
|
+
*/
|
|
9
|
+
export * from './supervisor.js';
|
|
10
|
+
export * from './registry.js';
|
|
11
|
+
export * from './types.js';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection Registry
|
|
3
|
+
*
|
|
4
|
+
* Scopes connections by environment/context.
|
|
5
|
+
* Tracks active connections and their state.
|
|
6
|
+
*/
|
|
7
|
+
import { ConnectionSupervisor } from './supervisor.js';
|
|
8
|
+
export interface RegistryEntry {
|
|
9
|
+
id: string;
|
|
10
|
+
supervisor: ConnectionSupervisor;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
lastConnectedAt?: Date;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Connection Registry
|
|
17
|
+
*
|
|
18
|
+
* Manages multiple connections by ID.
|
|
19
|
+
* Connections persist even after disconnect (for reconnection).
|
|
20
|
+
*/
|
|
21
|
+
export declare class ConnectionRegistry {
|
|
22
|
+
private connections;
|
|
23
|
+
private onChange?;
|
|
24
|
+
constructor(onChange?: (entries: RegistryEntry[]) => void);
|
|
25
|
+
/**
|
|
26
|
+
* Register a new connection
|
|
27
|
+
*/
|
|
28
|
+
register(id: string, supervisor: ConnectionSupervisor, metadata?: Record<string, unknown>): RegistryEntry;
|
|
29
|
+
/**
|
|
30
|
+
* Unregister a connection
|
|
31
|
+
*/
|
|
32
|
+
unregister(id: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Get a connection by ID
|
|
35
|
+
*/
|
|
36
|
+
get(id: string): RegistryEntry | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Get all connections
|
|
39
|
+
*/
|
|
40
|
+
list(): RegistryEntry[];
|
|
41
|
+
/**
|
|
42
|
+
* Get connections by state
|
|
43
|
+
*/
|
|
44
|
+
listByState(state: string): RegistryEntry[];
|
|
45
|
+
/**
|
|
46
|
+
* Update connection metadata
|
|
47
|
+
*/
|
|
48
|
+
updateMetadata(id: string, metadata: Record<string, unknown>): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Update last connected timestamp
|
|
51
|
+
*/
|
|
52
|
+
touch(id: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Clear all connections
|
|
55
|
+
*/
|
|
56
|
+
clear(): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Get count of connections
|
|
59
|
+
*/
|
|
60
|
+
size(): number;
|
|
61
|
+
/**
|
|
62
|
+
* Check if connection exists
|
|
63
|
+
*/
|
|
64
|
+
has(id: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Notify change listeners
|
|
67
|
+
*/
|
|
68
|
+
private notifyChange;
|
|
69
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection Registry
|
|
3
|
+
*
|
|
4
|
+
* Scopes connections by environment/context.
|
|
5
|
+
* Tracks active connections and their state.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Connection Registry
|
|
9
|
+
*
|
|
10
|
+
* Manages multiple connections by ID.
|
|
11
|
+
* Connections persist even after disconnect (for reconnection).
|
|
12
|
+
*/
|
|
13
|
+
export class ConnectionRegistry {
|
|
14
|
+
connections = new Map();
|
|
15
|
+
onChange;
|
|
16
|
+
constructor(onChange) {
|
|
17
|
+
this.onChange = onChange;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Register a new connection
|
|
21
|
+
*/
|
|
22
|
+
register(id, supervisor, metadata) {
|
|
23
|
+
const entry = {
|
|
24
|
+
id,
|
|
25
|
+
supervisor,
|
|
26
|
+
metadata,
|
|
27
|
+
createdAt: new Date(),
|
|
28
|
+
};
|
|
29
|
+
this.connections.set(id, entry);
|
|
30
|
+
this.notifyChange();
|
|
31
|
+
return entry;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Unregister a connection
|
|
35
|
+
*/
|
|
36
|
+
unregister(id) {
|
|
37
|
+
const entry = this.connections.get(id);
|
|
38
|
+
if (entry) {
|
|
39
|
+
entry.supervisor.disconnect().catch(() => { });
|
|
40
|
+
this.connections.delete(id);
|
|
41
|
+
this.notifyChange();
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get a connection by ID
|
|
48
|
+
*/
|
|
49
|
+
get(id) {
|
|
50
|
+
return this.connections.get(id);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get all connections
|
|
54
|
+
*/
|
|
55
|
+
list() {
|
|
56
|
+
return Array.from(this.connections.values());
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get connections by state
|
|
60
|
+
*/
|
|
61
|
+
listByState(state) {
|
|
62
|
+
return this.list().filter(e => e.supervisor.getState() === state);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Update connection metadata
|
|
66
|
+
*/
|
|
67
|
+
updateMetadata(id, metadata) {
|
|
68
|
+
const entry = this.connections.get(id);
|
|
69
|
+
if (entry) {
|
|
70
|
+
entry.metadata = { ...entry.metadata, ...metadata };
|
|
71
|
+
this.notifyChange();
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Update last connected timestamp
|
|
78
|
+
*/
|
|
79
|
+
touch(id) {
|
|
80
|
+
const entry = this.connections.get(id);
|
|
81
|
+
if (entry) {
|
|
82
|
+
entry.lastConnectedAt = new Date();
|
|
83
|
+
this.notifyChange();
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Clear all connections
|
|
90
|
+
*/
|
|
91
|
+
async clear() {
|
|
92
|
+
const promises = this.list().map(e => e.supervisor.disconnect());
|
|
93
|
+
await Promise.allSettled(promises);
|
|
94
|
+
this.connections.clear();
|
|
95
|
+
this.notifyChange();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get count of connections
|
|
99
|
+
*/
|
|
100
|
+
size() {
|
|
101
|
+
return this.connections.size;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Check if connection exists
|
|
105
|
+
*/
|
|
106
|
+
has(id) {
|
|
107
|
+
return this.connections.has(id);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Notify change listeners
|
|
111
|
+
*/
|
|
112
|
+
notifyChange() {
|
|
113
|
+
if (this.onChange) {
|
|
114
|
+
this.onChange(this.list());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connection Supervisor
|
|
3
|
+
*
|
|
4
|
+
* Inspired by T3Code's connection supervisor:
|
|
5
|
+
* - Jittered exponential backoff for reconnection
|
|
6
|
+
* - Resets delay after successful connection
|
|
7
|
+
* - Cap at maxDelay to prevent thundering herd
|
|
8
|
+
*/
|
|
9
|
+
import type { EventEmitter } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Connection Supervisor options
|
|
12
|
+
*/
|
|
13
|
+
export interface SupervisorOptions {
|
|
14
|
+
/** Transport to manage */
|
|
15
|
+
transport: EventEmitter & {
|
|
16
|
+
open(): Promise<void>;
|
|
17
|
+
close(): Promise<void>;
|
|
18
|
+
isConnected(): boolean;
|
|
19
|
+
};
|
|
20
|
+
/** Initial retry delay in ms */
|
|
21
|
+
initialDelay?: number;
|
|
22
|
+
/** Maximum retry delay in ms */
|
|
23
|
+
maxDelay?: number;
|
|
24
|
+
/** Maximum retries (0 = infinite) */
|
|
25
|
+
maxRetries?: number;
|
|
26
|
+
/** Enable jitter */
|
|
27
|
+
jitter?: boolean;
|
|
28
|
+
/** Callback when connected */
|
|
29
|
+
onConnected?: () => void;
|
|
30
|
+
/** Callback when disconnected */
|
|
31
|
+
onDisconnected?: () => void;
|
|
32
|
+
/** Callback on error */
|
|
33
|
+
onError?: (error: Error) => void;
|
|
34
|
+
/** Callback on retry attempt */
|
|
35
|
+
onRetry?: (attempt: number, delay: number) => void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Connection Supervisor
|
|
39
|
+
*
|
|
40
|
+
* Manages transport connection with automatic reconnection using
|
|
41
|
+
* jittered exponential backoff.
|
|
42
|
+
*/
|
|
43
|
+
export declare class ConnectionSupervisor {
|
|
44
|
+
private transport;
|
|
45
|
+
private delay;
|
|
46
|
+
private maxDelay;
|
|
47
|
+
private maxRetries;
|
|
48
|
+
private jitter;
|
|
49
|
+
private retries;
|
|
50
|
+
private state;
|
|
51
|
+
private stopping;
|
|
52
|
+
private onConnected?;
|
|
53
|
+
private onDisconnected?;
|
|
54
|
+
private onError?;
|
|
55
|
+
private onRetry?;
|
|
56
|
+
constructor(options: SupervisorOptions);
|
|
57
|
+
/**
|
|
58
|
+
* Current connection state
|
|
59
|
+
*/
|
|
60
|
+
getState(): "connected" | "connecting" | "error" | "idle" | "reconnecting" | "stopped";
|
|
61
|
+
/**
|
|
62
|
+
* Number of retries attempted
|
|
63
|
+
*/
|
|
64
|
+
getRetries(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Start the connection
|
|
67
|
+
*/
|
|
68
|
+
connect(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Stop the connection
|
|
71
|
+
*/
|
|
72
|
+
disconnect(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Force reconnection
|
|
75
|
+
*/
|
|
76
|
+
reconnect(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Handle connection error with backoff
|
|
79
|
+
*/
|
|
80
|
+
private handleConnectionError;
|
|
81
|
+
/**
|
|
82
|
+
* Attempt connection with backoff
|
|
83
|
+
*/
|
|
84
|
+
private attemptConnection;
|
|
85
|
+
/**
|
|
86
|
+
* Get initial delay (allows override)
|
|
87
|
+
*/
|
|
88
|
+
protected getInitialDelay(): number;
|
|
89
|
+
}
|