@kynetic-ai/spec 0.1.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.
- package/README.md +263 -0
- package/dist/acp/client.d.ts +159 -0
- package/dist/acp/client.d.ts.map +1 -0
- package/dist/acp/client.js +255 -0
- package/dist/acp/client.js.map +1 -0
- package/dist/acp/framing.d.ts +119 -0
- package/dist/acp/framing.d.ts.map +1 -0
- package/dist/acp/framing.js +302 -0
- package/dist/acp/framing.js.map +1 -0
- package/dist/acp/index.d.ts +14 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +13 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/types.d.ts +89 -0
- package/dist/acp/types.d.ts.map +1 -0
- package/dist/acp/types.js +99 -0
- package/dist/acp/types.js.map +1 -0
- package/dist/agents/adapters.d.ts +55 -0
- package/dist/agents/adapters.d.ts.map +1 -0
- package/dist/agents/adapters.js +84 -0
- package/dist/agents/adapters.js.map +1 -0
- package/dist/agents/index.d.ts +8 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +10 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/spawner.d.ts +53 -0
- package/dist/agents/spawner.d.ts.map +1 -0
- package/dist/agents/spawner.js +83 -0
- package/dist/agents/spawner.js.map +1 -0
- package/dist/cli/batch.d.ts +82 -0
- package/dist/cli/batch.d.ts.map +1 -0
- package/dist/cli/batch.js +162 -0
- package/dist/cli/batch.js.map +1 -0
- package/dist/cli/commands/clone-for-testing.d.ts +6 -0
- package/dist/cli/commands/clone-for-testing.d.ts.map +1 -0
- package/dist/cli/commands/clone-for-testing.js +176 -0
- package/dist/cli/commands/clone-for-testing.js.map +1 -0
- package/dist/cli/commands/derive.d.ts +6 -0
- package/dist/cli/commands/derive.d.ts.map +1 -0
- package/dist/cli/commands/derive.js +450 -0
- package/dist/cli/commands/derive.js.map +1 -0
- package/dist/cli/commands/help.d.ts +6 -0
- package/dist/cli/commands/help.d.ts.map +1 -0
- package/dist/cli/commands/help.js +196 -0
- package/dist/cli/commands/help.js.map +1 -0
- package/dist/cli/commands/inbox.d.ts +6 -0
- package/dist/cli/commands/inbox.d.ts.map +1 -0
- package/dist/cli/commands/inbox.js +235 -0
- package/dist/cli/commands/inbox.js.map +1 -0
- package/dist/cli/commands/index.d.ts +20 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +21 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/init.d.ts +6 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +245 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/item.d.ts +6 -0
- package/dist/cli/commands/item.d.ts.map +1 -0
- package/dist/cli/commands/item.js +1311 -0
- package/dist/cli/commands/item.js.map +1 -0
- package/dist/cli/commands/link.d.ts +6 -0
- package/dist/cli/commands/link.d.ts.map +1 -0
- package/dist/cli/commands/link.js +288 -0
- package/dist/cli/commands/link.js.map +1 -0
- package/dist/cli/commands/log.d.ts +16 -0
- package/dist/cli/commands/log.d.ts.map +1 -0
- package/dist/cli/commands/log.js +291 -0
- package/dist/cli/commands/log.js.map +1 -0
- package/dist/cli/commands/meta.d.ts +15 -0
- package/dist/cli/commands/meta.d.ts.map +1 -0
- package/dist/cli/commands/meta.js +1378 -0
- package/dist/cli/commands/meta.js.map +1 -0
- package/dist/cli/commands/module.d.ts +6 -0
- package/dist/cli/commands/module.d.ts.map +1 -0
- package/dist/cli/commands/module.js +102 -0
- package/dist/cli/commands/module.js.map +1 -0
- package/dist/cli/commands/ralph.d.ts +9 -0
- package/dist/cli/commands/ralph.d.ts.map +1 -0
- package/dist/cli/commands/ralph.js +465 -0
- package/dist/cli/commands/ralph.js.map +1 -0
- package/dist/cli/commands/search.d.ts +6 -0
- package/dist/cli/commands/search.d.ts.map +1 -0
- package/dist/cli/commands/search.js +134 -0
- package/dist/cli/commands/search.js.map +1 -0
- package/dist/cli/commands/session.d.ts +164 -0
- package/dist/cli/commands/session.d.ts.map +1 -0
- package/dist/cli/commands/session.js +745 -0
- package/dist/cli/commands/session.js.map +1 -0
- package/dist/cli/commands/setup.d.ts +26 -0
- package/dist/cli/commands/setup.d.ts.map +1 -0
- package/dist/cli/commands/setup.js +586 -0
- package/dist/cli/commands/setup.js.map +1 -0
- package/dist/cli/commands/shadow.d.ts +6 -0
- package/dist/cli/commands/shadow.d.ts.map +1 -0
- package/dist/cli/commands/shadow.js +299 -0
- package/dist/cli/commands/shadow.js.map +1 -0
- package/dist/cli/commands/task.d.ts +6 -0
- package/dist/cli/commands/task.d.ts.map +1 -0
- package/dist/cli/commands/task.js +1514 -0
- package/dist/cli/commands/task.js.map +1 -0
- package/dist/cli/commands/tasks.d.ts +6 -0
- package/dist/cli/commands/tasks.d.ts.map +1 -0
- package/dist/cli/commands/tasks.js +347 -0
- package/dist/cli/commands/tasks.js.map +1 -0
- package/dist/cli/commands/trait.d.ts +10 -0
- package/dist/cli/commands/trait.d.ts.map +1 -0
- package/dist/cli/commands/trait.js +295 -0
- package/dist/cli/commands/trait.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +6 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +626 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/exit-codes.d.ts +62 -0
- package/dist/cli/exit-codes.d.ts.map +1 -0
- package/dist/cli/exit-codes.js +65 -0
- package/dist/cli/exit-codes.js.map +1 -0
- package/dist/cli/help/content.d.ts +35 -0
- package/dist/cli/help/content.d.ts.map +1 -0
- package/dist/cli/help/content.js +312 -0
- package/dist/cli/help/content.js.map +1 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +85 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/introspection.d.ts +87 -0
- package/dist/cli/introspection.d.ts.map +1 -0
- package/dist/cli/introspection.js +127 -0
- package/dist/cli/introspection.js.map +1 -0
- package/dist/cli/output.d.ts +56 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +467 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/suggest.d.ts +16 -0
- package/dist/cli/suggest.d.ts.map +1 -0
- package/dist/cli/suggest.js +72 -0
- package/dist/cli/suggest.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/alignment.d.ts +113 -0
- package/dist/parser/alignment.d.ts.map +1 -0
- package/dist/parser/alignment.js +261 -0
- package/dist/parser/alignment.js.map +1 -0
- package/dist/parser/assess.d.ts +81 -0
- package/dist/parser/assess.d.ts.map +1 -0
- package/dist/parser/assess.js +197 -0
- package/dist/parser/assess.js.map +1 -0
- package/dist/parser/convention-validation.d.ts +48 -0
- package/dist/parser/convention-validation.d.ts.map +1 -0
- package/dist/parser/convention-validation.js +167 -0
- package/dist/parser/convention-validation.js.map +1 -0
- package/dist/parser/fix.d.ts +38 -0
- package/dist/parser/fix.d.ts.map +1 -0
- package/dist/parser/fix.js +185 -0
- package/dist/parser/fix.js.map +1 -0
- package/dist/parser/index.d.ts +12 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +13 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/items.d.ts +138 -0
- package/dist/parser/items.d.ts.map +1 -0
- package/dist/parser/items.js +321 -0
- package/dist/parser/items.js.map +1 -0
- package/dist/parser/meta.d.ts +120 -0
- package/dist/parser/meta.d.ts.map +1 -0
- package/dist/parser/meta.js +441 -0
- package/dist/parser/meta.js.map +1 -0
- package/dist/parser/refs.d.ts +185 -0
- package/dist/parser/refs.d.ts.map +1 -0
- package/dist/parser/refs.js +404 -0
- package/dist/parser/refs.js.map +1 -0
- package/dist/parser/shadow.d.ts +253 -0
- package/dist/parser/shadow.d.ts.map +1 -0
- package/dist/parser/shadow.js +1053 -0
- package/dist/parser/shadow.js.map +1 -0
- package/dist/parser/traits.d.ts +72 -0
- package/dist/parser/traits.d.ts.map +1 -0
- package/dist/parser/traits.js +120 -0
- package/dist/parser/traits.js.map +1 -0
- package/dist/parser/validate.d.ts +89 -0
- package/dist/parser/validate.d.ts.map +1 -0
- package/dist/parser/validate.js +817 -0
- package/dist/parser/validate.js.map +1 -0
- package/dist/parser/yaml.d.ts +326 -0
- package/dist/parser/yaml.d.ts.map +1 -0
- package/dist/parser/yaml.js +1383 -0
- package/dist/parser/yaml.js.map +1 -0
- package/dist/ralph/cli-renderer.d.ts +20 -0
- package/dist/ralph/cli-renderer.d.ts.map +1 -0
- package/dist/ralph/cli-renderer.js +179 -0
- package/dist/ralph/cli-renderer.js.map +1 -0
- package/dist/ralph/events.d.ts +65 -0
- package/dist/ralph/events.d.ts.map +1 -0
- package/dist/ralph/events.js +397 -0
- package/dist/ralph/events.js.map +1 -0
- package/dist/ralph/index.d.ts +8 -0
- package/dist/ralph/index.d.ts.map +1 -0
- package/dist/ralph/index.js +10 -0
- package/dist/ralph/index.js.map +1 -0
- package/dist/schema/common.d.ts +46 -0
- package/dist/schema/common.d.ts.map +1 -0
- package/dist/schema/common.js +71 -0
- package/dist/schema/common.js.map +1 -0
- package/dist/schema/inbox.d.ts +90 -0
- package/dist/schema/inbox.d.ts.map +1 -0
- package/dist/schema/inbox.js +30 -0
- package/dist/schema/inbox.js.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +7 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/meta.d.ts +762 -0
- package/dist/schema/meta.d.ts.map +1 -0
- package/dist/schema/meta.js +144 -0
- package/dist/schema/meta.js.map +1 -0
- package/dist/schema/spec.d.ts +912 -0
- package/dist/schema/spec.d.ts.map +1 -0
- package/dist/schema/spec.js +104 -0
- package/dist/schema/spec.js.map +1 -0
- package/dist/schema/task.d.ts +664 -0
- package/dist/schema/task.d.ts.map +1 -0
- package/dist/schema/task.js +130 -0
- package/dist/schema/task.js.map +1 -0
- package/dist/sessions/index.d.ts +11 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/sessions/index.js +13 -0
- package/dist/sessions/index.js.map +1 -0
- package/dist/sessions/store.d.ts +144 -0
- package/dist/sessions/store.d.ts.map +1 -0
- package/dist/sessions/store.js +325 -0
- package/dist/sessions/store.js.map +1 -0
- package/dist/sessions/types.d.ts +157 -0
- package/dist/sessions/types.d.ts.map +1 -0
- package/dist/sessions/types.js +90 -0
- package/dist/sessions/types.js.map +1 -0
- package/dist/strings/errors.d.ts +420 -0
- package/dist/strings/errors.d.ts.map +1 -0
- package/dist/strings/errors.js +282 -0
- package/dist/strings/errors.js.map +1 -0
- package/dist/strings/guidance.d.ts +65 -0
- package/dist/strings/guidance.d.ts.map +1 -0
- package/dist/strings/guidance.js +66 -0
- package/dist/strings/guidance.js.map +1 -0
- package/dist/strings/index.d.ts +12 -0
- package/dist/strings/index.d.ts.map +1 -0
- package/dist/strings/index.js +12 -0
- package/dist/strings/index.js.map +1 -0
- package/dist/strings/labels.d.ts +74 -0
- package/dist/strings/labels.d.ts.map +1 -0
- package/dist/strings/labels.js +75 -0
- package/dist/strings/labels.js.map +1 -0
- package/dist/strings/validation.d.ts +126 -0
- package/dist/strings/validation.d.ts.map +1 -0
- package/dist/strings/validation.js +135 -0
- package/dist/strings/validation.js.map +1 -0
- package/dist/utils/commit.d.ts +23 -0
- package/dist/utils/commit.d.ts.map +1 -0
- package/dist/utils/commit.js +67 -0
- package/dist/utils/commit.js.map +1 -0
- package/dist/utils/git.d.ts +57 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +192 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/grep.d.ts +28 -0
- package/dist/utils/grep.d.ts.map +1 -0
- package/dist/utils/grep.js +86 -0
- package/dist/utils/grep.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/time.d.ts +18 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +61 -0
- package/dist/utils/time.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 Framing Layer
|
|
3
|
+
*
|
|
4
|
+
* Handles bidirectional stdio communication with auto-incrementing IDs,
|
|
5
|
+
* request/response correlation, and timeout handling.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from 'node:events';
|
|
8
|
+
import type { JsonRpcErrorObject } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Options for JsonRpcFraming
|
|
11
|
+
*/
|
|
12
|
+
export interface JsonRpcFramingOptions {
|
|
13
|
+
/** Default timeout for pending requests in milliseconds (default: 30000) */
|
|
14
|
+
timeout?: number;
|
|
15
|
+
/** Per-method timeout overrides in milliseconds */
|
|
16
|
+
methodTimeouts?: Record<string, number>;
|
|
17
|
+
/** Input stream (default: process.stdin) */
|
|
18
|
+
stdin?: NodeJS.ReadableStream;
|
|
19
|
+
/** Output stream (default: process.stdout) */
|
|
20
|
+
stdout?: NodeJS.WritableStream;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Options for sendRequest
|
|
24
|
+
*/
|
|
25
|
+
export interface SendRequestOptions {
|
|
26
|
+
/**
|
|
27
|
+
* If true, don't log "Method not found" errors.
|
|
28
|
+
* Use for optional methods that may not be supported by all agents.
|
|
29
|
+
*/
|
|
30
|
+
silentMethodNotFound?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* JSON-RPC 2.0 Framing Layer
|
|
34
|
+
*
|
|
35
|
+
* Provides bidirectional JSON-RPC 2.0 communication over stdio with:
|
|
36
|
+
* - Auto-incrementing request IDs
|
|
37
|
+
* - Request/response correlation
|
|
38
|
+
* - Configurable timeout for pending requests (default 30s)
|
|
39
|
+
* - Per-method timeout overrides for long-running operations
|
|
40
|
+
* - Activity-based timeout reset (keepalive on incoming messages)
|
|
41
|
+
* - Event-based message handling
|
|
42
|
+
*/
|
|
43
|
+
export declare class JsonRpcFraming extends EventEmitter {
|
|
44
|
+
private nextId;
|
|
45
|
+
private pending;
|
|
46
|
+
private timeout;
|
|
47
|
+
private methodTimeouts;
|
|
48
|
+
private stdin;
|
|
49
|
+
private stdout;
|
|
50
|
+
private buffer;
|
|
51
|
+
private closed;
|
|
52
|
+
constructor(options?: JsonRpcFramingOptions);
|
|
53
|
+
/**
|
|
54
|
+
* Send a JSON-RPC request and wait for response
|
|
55
|
+
*/
|
|
56
|
+
sendRequest(method: string, params?: unknown, options?: SendRequestOptions): Promise<unknown>;
|
|
57
|
+
/**
|
|
58
|
+
* Send a JSON-RPC notification (no response expected)
|
|
59
|
+
*/
|
|
60
|
+
sendNotification(method: string, params?: unknown): void;
|
|
61
|
+
/**
|
|
62
|
+
* Send a JSON-RPC response (in response to a request)
|
|
63
|
+
*/
|
|
64
|
+
sendResponse(id: string | number, result: unknown): void;
|
|
65
|
+
/**
|
|
66
|
+
* Send a JSON-RPC error response
|
|
67
|
+
*/
|
|
68
|
+
sendError(id: string | number | null, error: JsonRpcErrorObject): void;
|
|
69
|
+
/**
|
|
70
|
+
* Close the framing layer
|
|
71
|
+
*/
|
|
72
|
+
close(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Check if the framing layer is closed
|
|
75
|
+
*/
|
|
76
|
+
isClosed(): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Reset timeout timers for all pending requests
|
|
79
|
+
*
|
|
80
|
+
* Called when activity is detected from the agent (incoming requests/responses),
|
|
81
|
+
* indicating the agent is still alive and working. This implements a keepalive
|
|
82
|
+
* mechanism that prevents timeout during long-running operations where the agent
|
|
83
|
+
* is actively making tool calls.
|
|
84
|
+
*/
|
|
85
|
+
private resetPendingTimers;
|
|
86
|
+
/**
|
|
87
|
+
* Send a JSON-RPC message
|
|
88
|
+
*/
|
|
89
|
+
private send;
|
|
90
|
+
/**
|
|
91
|
+
* Handle incoming data from stdin
|
|
92
|
+
*/
|
|
93
|
+
private handleData;
|
|
94
|
+
/**
|
|
95
|
+
* Process a complete line of input
|
|
96
|
+
*/
|
|
97
|
+
private processLine;
|
|
98
|
+
/**
|
|
99
|
+
* Handle a parsed JSON-RPC message
|
|
100
|
+
*/
|
|
101
|
+
private handleMessage;
|
|
102
|
+
/**
|
|
103
|
+
* Handle a JSON-RPC response
|
|
104
|
+
*/
|
|
105
|
+
private handleResponse;
|
|
106
|
+
/**
|
|
107
|
+
* Handle a JSON-RPC error response
|
|
108
|
+
*/
|
|
109
|
+
private handleErrorResponse;
|
|
110
|
+
/**
|
|
111
|
+
* Handle stdin end
|
|
112
|
+
*/
|
|
113
|
+
private handleEnd;
|
|
114
|
+
/**
|
|
115
|
+
* Handle stdin error
|
|
116
|
+
*/
|
|
117
|
+
private handleError;
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=framing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framing.d.ts","sourceRoot":"","sources":["../../src/acp/framing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAEV,kBAAkB,EAKnB,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAC9B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC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H,OAAO,CAAC,WAAW;CAKpB"}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 Framing Layer
|
|
3
|
+
*
|
|
4
|
+
* Handles bidirectional stdio communication with auto-incrementing IDs,
|
|
5
|
+
* request/response correlation, and timeout handling.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from 'node:events';
|
|
8
|
+
import { isError, isNotification, isRequest, isResponse } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Default timeouts for long-running methods (in milliseconds)
|
|
11
|
+
* These methods can legitimately take minutes, so they need longer timeouts.
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_METHOD_TIMEOUTS = {
|
|
14
|
+
'session/prompt': 5 * 60 * 1000, // 5 minutes
|
|
15
|
+
'session/resume': 5 * 60 * 1000, // 5 minutes
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* JSON-RPC 2.0 Framing Layer
|
|
19
|
+
*
|
|
20
|
+
* Provides bidirectional JSON-RPC 2.0 communication over stdio with:
|
|
21
|
+
* - Auto-incrementing request IDs
|
|
22
|
+
* - Request/response correlation
|
|
23
|
+
* - Configurable timeout for pending requests (default 30s)
|
|
24
|
+
* - Per-method timeout overrides for long-running operations
|
|
25
|
+
* - Activity-based timeout reset (keepalive on incoming messages)
|
|
26
|
+
* - Event-based message handling
|
|
27
|
+
*/
|
|
28
|
+
export class JsonRpcFraming extends EventEmitter {
|
|
29
|
+
nextId = 1;
|
|
30
|
+
pending = new Map();
|
|
31
|
+
timeout;
|
|
32
|
+
methodTimeouts;
|
|
33
|
+
stdin;
|
|
34
|
+
stdout;
|
|
35
|
+
buffer = '';
|
|
36
|
+
closed = false;
|
|
37
|
+
constructor(options = {}) {
|
|
38
|
+
super();
|
|
39
|
+
this.timeout = options.timeout ?? 30000;
|
|
40
|
+
// Merge default method timeouts with user-provided overrides
|
|
41
|
+
this.methodTimeouts = {
|
|
42
|
+
...DEFAULT_METHOD_TIMEOUTS,
|
|
43
|
+
...options.methodTimeouts,
|
|
44
|
+
};
|
|
45
|
+
this.stdin = options.stdin ?? process.stdin;
|
|
46
|
+
this.stdout = options.stdout ?? process.stdout;
|
|
47
|
+
// Set up stdin to receive data
|
|
48
|
+
if ('setEncoding' in this.stdin) {
|
|
49
|
+
this.stdin.setEncoding('utf8');
|
|
50
|
+
}
|
|
51
|
+
this.stdin.on('data', (chunk) => this.handleData(chunk.toString()));
|
|
52
|
+
this.stdin.on('end', () => this.handleEnd());
|
|
53
|
+
this.stdin.on('error', (err) => this.handleError(err));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Send a JSON-RPC request and wait for response
|
|
57
|
+
*/
|
|
58
|
+
async sendRequest(method, params, options) {
|
|
59
|
+
if (this.closed) {
|
|
60
|
+
throw new Error('JsonRpcFraming is closed');
|
|
61
|
+
}
|
|
62
|
+
const id = this.nextId++;
|
|
63
|
+
const request = {
|
|
64
|
+
jsonrpc: '2.0',
|
|
65
|
+
id,
|
|
66
|
+
method,
|
|
67
|
+
...(params !== undefined && { params }),
|
|
68
|
+
};
|
|
69
|
+
// Get timeout for this method (use per-method override if available)
|
|
70
|
+
const timeoutMs = this.methodTimeouts[method] ?? this.timeout;
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
// Set up timeout
|
|
73
|
+
const timer = setTimeout(() => {
|
|
74
|
+
this.pending.delete(id);
|
|
75
|
+
reject(new Error(`Request ${id} timed out after ${timeoutMs}ms (method: ${method})`));
|
|
76
|
+
}, timeoutMs);
|
|
77
|
+
// Store pending request with timeout info for potential resets
|
|
78
|
+
this.pending.set(id, { resolve, reject, timer, method, timeoutMs, id, options });
|
|
79
|
+
// Send the request
|
|
80
|
+
this.send(request);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Send a JSON-RPC notification (no response expected)
|
|
85
|
+
*/
|
|
86
|
+
sendNotification(method, params) {
|
|
87
|
+
if (this.closed) {
|
|
88
|
+
throw new Error('JsonRpcFraming is closed');
|
|
89
|
+
}
|
|
90
|
+
const notification = {
|
|
91
|
+
jsonrpc: '2.0',
|
|
92
|
+
method,
|
|
93
|
+
...(params !== undefined && { params }),
|
|
94
|
+
};
|
|
95
|
+
this.send(notification);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Send a JSON-RPC response (in response to a request)
|
|
99
|
+
*/
|
|
100
|
+
sendResponse(id, result) {
|
|
101
|
+
if (this.closed) {
|
|
102
|
+
throw new Error('JsonRpcFraming is closed');
|
|
103
|
+
}
|
|
104
|
+
const response = {
|
|
105
|
+
jsonrpc: '2.0',
|
|
106
|
+
id,
|
|
107
|
+
result,
|
|
108
|
+
};
|
|
109
|
+
this.send(response);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Send a JSON-RPC error response
|
|
113
|
+
*/
|
|
114
|
+
sendError(id, error) {
|
|
115
|
+
if (this.closed) {
|
|
116
|
+
throw new Error('JsonRpcFraming is closed');
|
|
117
|
+
}
|
|
118
|
+
const errorResponse = {
|
|
119
|
+
jsonrpc: '2.0',
|
|
120
|
+
id,
|
|
121
|
+
error,
|
|
122
|
+
};
|
|
123
|
+
this.send(errorResponse);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Close the framing layer
|
|
127
|
+
*/
|
|
128
|
+
close() {
|
|
129
|
+
if (this.closed)
|
|
130
|
+
return;
|
|
131
|
+
this.closed = true;
|
|
132
|
+
// Reject all pending requests
|
|
133
|
+
for (const [id, pending] of this.pending.entries()) {
|
|
134
|
+
clearTimeout(pending.timer);
|
|
135
|
+
pending.reject(new Error('JsonRpcFraming closed'));
|
|
136
|
+
this.pending.delete(id);
|
|
137
|
+
}
|
|
138
|
+
this.emit('close');
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Check if the framing layer is closed
|
|
142
|
+
*/
|
|
143
|
+
isClosed() {
|
|
144
|
+
return this.closed;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Reset timeout timers for all pending requests
|
|
148
|
+
*
|
|
149
|
+
* Called when activity is detected from the agent (incoming requests/responses),
|
|
150
|
+
* indicating the agent is still alive and working. This implements a keepalive
|
|
151
|
+
* mechanism that prevents timeout during long-running operations where the agent
|
|
152
|
+
* is actively making tool calls.
|
|
153
|
+
*/
|
|
154
|
+
resetPendingTimers() {
|
|
155
|
+
for (const pending of this.pending.values()) {
|
|
156
|
+
// Clear the old timer
|
|
157
|
+
clearTimeout(pending.timer);
|
|
158
|
+
// Create a new timer with the same timeout duration
|
|
159
|
+
pending.timer = setTimeout(() => {
|
|
160
|
+
this.pending.delete(pending.id);
|
|
161
|
+
pending.reject(new Error(`Request ${pending.id} timed out after ${pending.timeoutMs}ms (method: ${pending.method})`));
|
|
162
|
+
}, pending.timeoutMs);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Send a JSON-RPC message
|
|
167
|
+
*/
|
|
168
|
+
send(message) {
|
|
169
|
+
try {
|
|
170
|
+
const json = JSON.stringify(message);
|
|
171
|
+
this.stdout.write(`${json}\n`);
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
console.error(`Error sending message: ${err}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Handle incoming data from stdin
|
|
179
|
+
*/
|
|
180
|
+
handleData(chunk) {
|
|
181
|
+
this.buffer += chunk;
|
|
182
|
+
// Process complete lines
|
|
183
|
+
let newlineIndex = this.buffer.indexOf('\n');
|
|
184
|
+
while (newlineIndex !== -1) {
|
|
185
|
+
const line = this.buffer.slice(0, newlineIndex);
|
|
186
|
+
this.buffer = this.buffer.slice(newlineIndex + 1);
|
|
187
|
+
if (line.trim()) {
|
|
188
|
+
this.processLine(line);
|
|
189
|
+
}
|
|
190
|
+
newlineIndex = this.buffer.indexOf('\n');
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Process a complete line of input
|
|
195
|
+
*/
|
|
196
|
+
processLine(line) {
|
|
197
|
+
try {
|
|
198
|
+
const message = JSON.parse(line);
|
|
199
|
+
this.handleMessage(message);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// Malformed JSON - send parse error response
|
|
203
|
+
this.sendError(null, {
|
|
204
|
+
code: -32700,
|
|
205
|
+
message: 'Parse error',
|
|
206
|
+
data: { line },
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Handle a parsed JSON-RPC message
|
|
212
|
+
*/
|
|
213
|
+
handleMessage(message) {
|
|
214
|
+
if (isResponse(message)) {
|
|
215
|
+
this.handleResponse(message);
|
|
216
|
+
}
|
|
217
|
+
else if (isError(message)) {
|
|
218
|
+
this.handleErrorResponse(message);
|
|
219
|
+
}
|
|
220
|
+
else if (isRequest(message)) {
|
|
221
|
+
// Agent is sending us a request (e.g., tool call) - this proves it's alive
|
|
222
|
+
// Reset timeout timers for any pending requests
|
|
223
|
+
this.resetPendingTimers();
|
|
224
|
+
this.emit('request', message);
|
|
225
|
+
}
|
|
226
|
+
else if (isNotification(message)) {
|
|
227
|
+
// Agent is sending us a notification - also proves it's alive
|
|
228
|
+
this.resetPendingTimers();
|
|
229
|
+
this.emit('notification', message);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
// Invalid message
|
|
233
|
+
this.sendError(null, {
|
|
234
|
+
code: -32600,
|
|
235
|
+
message: 'Invalid Request',
|
|
236
|
+
data: message,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Handle a JSON-RPC response
|
|
242
|
+
*/
|
|
243
|
+
handleResponse(response) {
|
|
244
|
+
const pending = this.pending.get(response.id);
|
|
245
|
+
if (pending) {
|
|
246
|
+
clearTimeout(pending.timer);
|
|
247
|
+
this.pending.delete(response.id);
|
|
248
|
+
pending.resolve(response.result);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
// Unexpected response
|
|
252
|
+
console.error(`Warning: Received response for unknown request ID: ${response.id}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Handle a JSON-RPC error response
|
|
257
|
+
*/
|
|
258
|
+
handleErrorResponse(error) {
|
|
259
|
+
// JSON-RPC error code for "Method not found"
|
|
260
|
+
const METHOD_NOT_FOUND = -32601;
|
|
261
|
+
if (error.id === null) {
|
|
262
|
+
// Error without request ID - emit as event
|
|
263
|
+
this.emit('error', error.error);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const pending = this.pending.get(error.id);
|
|
267
|
+
if (pending) {
|
|
268
|
+
clearTimeout(pending.timer);
|
|
269
|
+
this.pending.delete(error.id);
|
|
270
|
+
// Skip logging for expected "Method not found" errors on optional methods
|
|
271
|
+
const isSilentMethodNotFound = pending.options?.silentMethodNotFound &&
|
|
272
|
+
error.error.code === METHOD_NOT_FOUND;
|
|
273
|
+
if (!isSilentMethodNotFound) {
|
|
274
|
+
console.error(`JSON-RPC error: ${error.error.message} (code: ${error.error.code}, method: ${pending.method})`);
|
|
275
|
+
}
|
|
276
|
+
const err = Object.assign(new Error(error.error.message), {
|
|
277
|
+
code: error.error.code,
|
|
278
|
+
data: error.error.data,
|
|
279
|
+
});
|
|
280
|
+
pending.reject(err);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
// Unexpected error response
|
|
284
|
+
console.error(`Warning: Received error for unknown request ID: ${error.id}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Handle stdin end
|
|
289
|
+
*/
|
|
290
|
+
handleEnd() {
|
|
291
|
+
this.close();
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Handle stdin error
|
|
295
|
+
*/
|
|
296
|
+
handleError(err) {
|
|
297
|
+
console.error(`Stdin error: ${err.message}`);
|
|
298
|
+
this.emit('error', err);
|
|
299
|
+
this.close();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=framing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framing.js","sourceRoot":"","sources":["../../src/acp/framing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAS3C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AA2C5E;;;GAGG;AACH,MAAM,uBAAuB,GAA2B;IACtD,gBAAgB,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,YAAY;IAC7C,gBAAgB,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,YAAY;CAC9C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,cAAe,SAAQ,YAAY;IACtC,MAAM,GAAG,CAAC,CAAC;IACX,OAAO,GAAG,IAAI,GAAG,EAAmC,CAAC;IACrD,OAAO,CAAS;IAChB,cAAc,CAAyB;IACvC,KAAK,CAAwB;IAC7B,MAAM,CAAwB;IAC9B,MAAM,GAAG,EAAE,CAAC;IACZ,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAY,UAAiC,EAAE;QAC7C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;QACxC,6DAA6D;QAC7D,IAAI,CAAC,cAAc,GAAG;YACpB,GAAG,uBAAuB;YAC1B,GAAG,OAAO,CAAC,cAAc;SAC1B,CAAC;QACF,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;QAE/C,+BAA+B;QAC/B,IAAI,aAAa,IAAI,IAAI,CAAC,KAAK,EAA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AK,CACX,mDAAmD,KAAK,CAAC,EAAE,EAAE,CAC9D,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACK,SAAS;QACf,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,GAAU;QAC5B,OAAO,CAAC,KAAK,CAAC,gBAAgB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACxB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP (Agent Communication Protocol) Module
|
|
3
|
+
*
|
|
4
|
+
* Provides a JSON-RPC 2.0 based client for Agent Client Protocol communication.
|
|
5
|
+
* Handles bidirectional stdio communication with ACP-compliant agents.
|
|
6
|
+
*/
|
|
7
|
+
export { ACPClient } from './client.js';
|
|
8
|
+
export type { ACPClientEvents, ACPClientOptions, SessionState } from './client.js';
|
|
9
|
+
export { JsonRpcFraming } from './framing.js';
|
|
10
|
+
export type { JsonRpcFramingOptions, SendRequestOptions, } from './framing.js';
|
|
11
|
+
export type { JsonRpcError, JsonRpcErrorObject, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, } from './types.js';
|
|
12
|
+
export { isError, isNotification, isRequest, isResponse, } from './types.js';
|
|
13
|
+
export type { AgentCapabilities, ClientCapabilities, ContentBlock, InitializeRequest, InitializeResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, RequestPermissionRequest, RequestPermissionResponse, SessionNotification, SessionUpdate, StopReason, TextContent, } from './types.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/acp/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGnF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,YAAY,EACV,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,OAAO,EACP,cAAc,EACd,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP (Agent Communication Protocol) Module
|
|
3
|
+
*
|
|
4
|
+
* Provides a JSON-RPC 2.0 based client for Agent Client Protocol communication.
|
|
5
|
+
* Handles bidirectional stdio communication with ACP-compliant agents.
|
|
6
|
+
*/
|
|
7
|
+
// Client
|
|
8
|
+
export { ACPClient } from './client.js';
|
|
9
|
+
// Framing layer
|
|
10
|
+
export { JsonRpcFraming } from './framing.js';
|
|
11
|
+
// Types - Type guards
|
|
12
|
+
export { isError, isNotification, isRequest, isResponse, } from './types.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/acp/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,SAAS;AACT,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,gBAAgB;AAChB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAgB9C,sBAAsB;AACtB,OAAO,EACL,OAAO,EACP,cAAc,EACd,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP (Agent Communication Protocol) Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports types from the official @agentclientprotocol/sdk
|
|
5
|
+
* to ensure spec compliance. Types are imported at compile-time only
|
|
6
|
+
* (zero runtime cost since TypeScript types are erased).
|
|
7
|
+
*
|
|
8
|
+
* We keep JSON-RPC 2.0 base types and type guards local since the SDK
|
|
9
|
+
* doesn't export them in the same way we use them.
|
|
10
|
+
*/
|
|
11
|
+
export type { AgentCapabilities, ClientCapabilities, ContentBlock, InitializeRequest, InitializeResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, RequestPermissionRequest, RequestPermissionResponse, SessionNotification, SessionUpdate, StopReason, TextContent, } from '@agentclientprotocol/sdk';
|
|
12
|
+
/**
|
|
13
|
+
* JSON-RPC 2.0 Request
|
|
14
|
+
*/
|
|
15
|
+
export interface JsonRpcRequest {
|
|
16
|
+
jsonrpc: '2.0';
|
|
17
|
+
id: string | number;
|
|
18
|
+
method: string;
|
|
19
|
+
params?: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* JSON-RPC 2.0 Response (success)
|
|
23
|
+
*/
|
|
24
|
+
export interface JsonRpcResponse {
|
|
25
|
+
jsonrpc: '2.0';
|
|
26
|
+
id: string | number;
|
|
27
|
+
result: unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* JSON-RPC 2.0 Error object
|
|
31
|
+
*/
|
|
32
|
+
export interface JsonRpcErrorObject {
|
|
33
|
+
code: number;
|
|
34
|
+
message: string;
|
|
35
|
+
data?: unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* JSON-RPC 2.0 Error response
|
|
39
|
+
*/
|
|
40
|
+
export interface JsonRpcError {
|
|
41
|
+
jsonrpc: '2.0';
|
|
42
|
+
id: string | number | null;
|
|
43
|
+
error: JsonRpcErrorObject;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* JSON-RPC 2.0 Notification (no response expected)
|
|
47
|
+
*/
|
|
48
|
+
export interface JsonRpcNotification {
|
|
49
|
+
jsonrpc: '2.0';
|
|
50
|
+
method: string;
|
|
51
|
+
params?: unknown;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Any JSON-RPC message type
|
|
55
|
+
*/
|
|
56
|
+
export type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse | JsonRpcError | JsonRpcNotification;
|
|
57
|
+
/**
|
|
58
|
+
* Check if a value is a non-null object
|
|
59
|
+
*/
|
|
60
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
61
|
+
/**
|
|
62
|
+
* Check if a value is a string
|
|
63
|
+
*/
|
|
64
|
+
export declare function isString(value: unknown): value is string;
|
|
65
|
+
/**
|
|
66
|
+
* Check if a value is a number
|
|
67
|
+
*/
|
|
68
|
+
export declare function isNumber(value: unknown): value is number;
|
|
69
|
+
/**
|
|
70
|
+
* Check if an object has a specific property with an optional specific value
|
|
71
|
+
*/
|
|
72
|
+
export declare function hasProperty<T extends string>(obj: unknown, key: T, value?: unknown): obj is Record<T, unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* Type guard for JSON-RPC Request
|
|
75
|
+
*/
|
|
76
|
+
export declare function isRequest(msg: unknown): msg is JsonRpcRequest;
|
|
77
|
+
/**
|
|
78
|
+
* Type guard for JSON-RPC Response
|
|
79
|
+
*/
|
|
80
|
+
export declare function isResponse(msg: unknown): msg is JsonRpcResponse;
|
|
81
|
+
/**
|
|
82
|
+
* Type guard for JSON-RPC Error
|
|
83
|
+
*/
|
|
84
|
+
export declare function isError(msg: unknown): msg is JsonRpcError;
|
|
85
|
+
/**
|
|
86
|
+
* Type guard for JSON-RPC Notification
|
|
87
|
+
*/
|
|
88
|
+
export declare function isNotification(msg: unknown): msg is JsonRpcNotification;
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/acp/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,UAAU,EACV,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAWlC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,EAAE,kBAAkB,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,cAAc,GACd,eAAe,GACf,YAAY,GACZ,mBAAmB,CAAC;AAQxB;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,CAAC,EACN,KAAK,CAAC,EAAE,OAAO,GACd,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAK3B;AASD;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,cAAc,CAS7D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,eAAe,CAS/D;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,YAAY,CAazD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,mBAAmB,CAQvE"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP (Agent Communication Protocol) Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports types from the official @agentclientprotocol/sdk
|
|
5
|
+
* to ensure spec compliance. Types are imported at compile-time only
|
|
6
|
+
* (zero runtime cost since TypeScript types are erased).
|
|
7
|
+
*
|
|
8
|
+
* We keep JSON-RPC 2.0 base types and type guards local since the SDK
|
|
9
|
+
* doesn't export them in the same way we use them.
|
|
10
|
+
*/
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// Validation Helpers
|
|
13
|
+
//
|
|
14
|
+
// Simple runtime type checks used by the JSON-RPC type guards.
|
|
15
|
+
// ============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Check if a value is a non-null object
|
|
18
|
+
*/
|
|
19
|
+
export function isObject(value) {
|
|
20
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if a value is a string
|
|
24
|
+
*/
|
|
25
|
+
export function isString(value) {
|
|
26
|
+
return typeof value === 'string';
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if a value is a number
|
|
30
|
+
*/
|
|
31
|
+
export function isNumber(value) {
|
|
32
|
+
return typeof value === 'number' && !Number.isNaN(value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if an object has a specific property with an optional specific value
|
|
36
|
+
*/
|
|
37
|
+
export function hasProperty(obj, key, value) {
|
|
38
|
+
if (!isObject(obj))
|
|
39
|
+
return false;
|
|
40
|
+
if (!(key in obj))
|
|
41
|
+
return false;
|
|
42
|
+
if (value !== undefined && obj[key] !== value)
|
|
43
|
+
return false;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// JSON-RPC Type Guards
|
|
48
|
+
//
|
|
49
|
+
// Runtime type guards for validating incoming messages.
|
|
50
|
+
// These work with unknown data and narrow to specific types.
|
|
51
|
+
// ============================================================================
|
|
52
|
+
/**
|
|
53
|
+
* Type guard for JSON-RPC Request
|
|
54
|
+
*/
|
|
55
|
+
export function isRequest(msg) {
|
|
56
|
+
return (isObject(msg) &&
|
|
57
|
+
hasProperty(msg, 'jsonrpc', '2.0') &&
|
|
58
|
+
'id' in msg &&
|
|
59
|
+
(isString(msg.id) || isNumber(msg.id)) &&
|
|
60
|
+
hasProperty(msg, 'method') &&
|
|
61
|
+
isString(msg.method));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Type guard for JSON-RPC Response
|
|
65
|
+
*/
|
|
66
|
+
export function isResponse(msg) {
|
|
67
|
+
return (isObject(msg) &&
|
|
68
|
+
hasProperty(msg, 'jsonrpc', '2.0') &&
|
|
69
|
+
'id' in msg &&
|
|
70
|
+
(isString(msg.id) || isNumber(msg.id)) &&
|
|
71
|
+
'result' in msg &&
|
|
72
|
+
!('error' in msg));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Type guard for JSON-RPC Error
|
|
76
|
+
*/
|
|
77
|
+
export function isError(msg) {
|
|
78
|
+
return (isObject(msg) &&
|
|
79
|
+
hasProperty(msg, 'jsonrpc', '2.0') &&
|
|
80
|
+
'id' in msg &&
|
|
81
|
+
(msg.id === null || isString(msg.id) || isNumber(msg.id)) &&
|
|
82
|
+
hasProperty(msg, 'error') &&
|
|
83
|
+
isObject(msg.error) &&
|
|
84
|
+
hasProperty(msg.error, 'code') &&
|
|
85
|
+
isNumber(msg.error.code) &&
|
|
86
|
+
hasProperty(msg.error, 'message') &&
|
|
87
|
+
isString(msg.error.message));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Type guard for JSON-RPC Notification
|
|
91
|
+
*/
|
|
92
|
+
export function isNotification(msg) {
|
|
93
|
+
return (isObject(msg) &&
|
|
94
|
+
hasProperty(msg, 'jsonrpc', '2.0') &&
|
|
95
|
+
!('id' in msg) &&
|
|
96
|
+
hasProperty(msg, 'method') &&
|
|
97
|
+
isString(msg.method));
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/acp/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA2FH,+EAA+E;AAC/E,qBAAqB;AACrB,EAAE;AACF,+DAA+D;AAC/D,+EAA+E;AAE/E;;GAEG;AACH,MAAM,UA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