@animalabs/mcpl-core 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anima Research
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # @animalabs/mcpl-core
2
+
3
+ > Published on npm as **`@animalabs/mcpl-core`**. Inside the connectome
4
+ > ecosystem it's consumed as a sibling source checkout under the
5
+ > `@connectome/mcpl-core` dependency key (`file:../mcpl-core-ts`) — npm keys
6
+ > `file:` deps by name, so both work side by side.
7
+
8
+ TypeScript core for **MCPL** — an MCP-superset wire protocol that adds
9
+ server-initiated **push events**, **channels** (bidirectional, push-driven
10
+ message streams), conversation **branches**, inference hooks, host-managed
11
+ state, and capability / feature-set negotiation on top of plain JSON-RPC.
12
+
13
+ This package is the shared, transport-agnostic core used across the connectome
14
+ agents (relays, bridges, hosts). It contains no business logic — just the wire
15
+ contract and a connection primitive.
16
+
17
+ ## What's in here
18
+
19
+ - **`McplConnection`** — a JSON-RPC 2.0 connection over a readable/writable
20
+ stream pair (`McplConnection.fromStreams(stdin, stdout)`), with a pull-based
21
+ `nextMessage()` for incoming requests/notifications and promise-based
22
+ `sendRequest()` / `sendResponse()` / `sendNotification()` / `sendError()`.
23
+ - **`method`** — the method-name constants: `initialize`, `push/event`,
24
+ `channels/*` (`list`, `open`, `close`, `publish`, `changed`, …),
25
+ `branches/*`, `inference/*`, `state/*`, `model/info`, …
26
+ - **Typed params/results** for every method (e.g. `ChannelDescriptor`,
27
+ `PushEventParams`, `ChannelsPublishParams`).
28
+ - **Content blocks** — `ContentBlock` (`text` / `image` / `audio`) plus helpers
29
+ like `textContent(...)`.
30
+ - **Capabilities & feature sets** — negotiation types (`InitializeCapabilities`,
31
+ `McplCapabilities`, `FeatureSetDeclaration`, context/inference hook caps).
32
+ - **Errors** — `ConnectionClosedError`, `ConnectionTimeoutError`, and `ERR_*`
33
+ protocol error codes.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ npm install @animalabs/mcpl-core
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```ts
44
+ import { McplConnection, textContent, method } from '@animalabs/mcpl-core';
45
+
46
+ const conn = McplConnection.fromStreams(process.stdin, process.stdout);
47
+
48
+ while (!conn.isClosed) {
49
+ const msg = await conn.nextMessage();
50
+ if (msg.type === 'request' && msg.request.method === 'tools/list') {
51
+ conn.sendResponse(msg.request.id, { tools: [] });
52
+ }
53
+ }
54
+
55
+ // server-initiated push:
56
+ conn.sendNotification(method.PUSH_EVENT, { /* … */ });
57
+ ```
58
+
59
+ ## Build & test
60
+
61
+ ```bash
62
+ npm install
63
+ npm run build # tsc → dist/
64
+ npm test
65
+ ```
66
+
67
+ ## License
68
+
69
+ MIT — see [LICENSE](./LICENSE).
@@ -0,0 +1,61 @@
1
+ /**
2
+ * MCPL capability negotiation types.
3
+ * Port of mcpl-core/src/capabilities.rs
4
+ *
5
+ * MCPL extensions ride on MCP's `initialize` handshake under
6
+ * `capabilities.experimental.mcpl`.
7
+ */
8
+ import type { FeatureSetDeclaration } from './methods.js';
9
+ export interface McplCapabilities {
10
+ version: string;
11
+ pushEvents?: boolean;
12
+ contextHooks?: ContextHooksCap;
13
+ inferenceRequest?: boolean | InferenceRequestCap;
14
+ streamObserver?: boolean;
15
+ rollback?: boolean;
16
+ channels?: boolean;
17
+ modelInfo?: boolean;
18
+ featureSets?: FeatureSetDeclaration[];
19
+ scopedAccess?: boolean;
20
+ }
21
+ export interface InferenceRequestCap {
22
+ streaming: boolean;
23
+ }
24
+ export interface ContextHooksCap {
25
+ beforeInference: boolean;
26
+ afterInference?: AfterInferenceCap;
27
+ }
28
+ export interface AfterInferenceCap {
29
+ blocking: boolean;
30
+ }
31
+ export interface ExperimentalCapabilities {
32
+ mcpl?: McplCapabilities;
33
+ }
34
+ export interface InitializeCapabilities {
35
+ experimental?: ExperimentalCapabilities;
36
+ tools?: Record<string, unknown>;
37
+ resources?: Record<string, unknown>;
38
+ prompts?: Record<string, unknown>;
39
+ logging?: Record<string, unknown>;
40
+ roots?: Record<string, unknown>;
41
+ sampling?: Record<string, unknown>;
42
+ }
43
+ export interface McplInitializeParams {
44
+ protocolVersion: string;
45
+ capabilities: InitializeCapabilities;
46
+ clientInfo: ImplementationInfo;
47
+ }
48
+ export interface McplInitializeResult {
49
+ protocolVersion: string;
50
+ capabilities: InitializeCapabilities;
51
+ serverInfo: ImplementationInfo;
52
+ }
53
+ export interface ImplementationInfo {
54
+ name: string;
55
+ version: string;
56
+ }
57
+ export declare function hasInferenceRequest(caps: McplCapabilities): boolean;
58
+ export declare function hasInferenceStreaming(caps: McplCapabilities): boolean;
59
+ /** Extract MCPL capabilities from an initialize result/params, if present. */
60
+ export declare function extractMcpl(caps: InitializeCapabilities): McplCapabilities | undefined;
61
+ //# sourceMappingURL=capabil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,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,sBAAsB,CAAC;IACrC,UAAU,EAAE,kBAAkB,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,sBAAsB,CAAC;IACrC,UAAU,EAAE,kBAAkB,CAAC;CAChC;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAEnE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAErE;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,IAAI,EAAE,sBAAsB,GAAG,gBAAgB,GAAG,SAAS,CAEtF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * MCPL capability negotiation types.
3
+ * Port of mcpl-core/src/capabilities.rs
4
+ *
5
+ * MCPL extensions ride on MCP's `initialize` handshake under
6
+ * `capabilities.experimental.mcpl`.
7
+ */
8
+ // ── Helper Functions ──
9
+ export function hasInferenceRequest(caps) {
10
+ return caps.inferenceRequest === true || (typeof caps.inferenceRequest === 'object' && caps.inferenceRequest !== null);
11
+ }
12
+ export function hasInferenceStreaming(caps) {
13
+ return typeof caps.inferenceRequest === 'object' && caps.inferenceRequest !== null && caps.inferenceRequest.streaming === true;
14
+ }
15
+ /** Extract MCPL capabilities from an initialize result/params, if present. */
16
+ export function extractMcpl(caps) {
17
+ return caps.experimental?.mcpl;
18
+ }
19
+ //# sourceMappingURL=capabilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA6DH,yBAAyB;AAEzB,MAAM,UAAU,mBAAmB,CAAC,IAAsB;IACxD,OAAO,IAAI,CAAC,gBAAgB,KAAK,IAAI,IAAI,CAAC,OAAO,IAAI,CAAC,gBAAgB,KAAK,QAAQ,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,CAAC,CAAC;AACzH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAsB;IAC1D,OAAO,OAAO,IAAI,CAAC,gBAAgB,KAAK,QAAQ,IAAI,IAAI,CAAC,gBAAgB,KAAK,IAAI,IAAI,IAAI,CAAC,gBAAgB,CAAC,SAAS,KAAK,IAAI,CAAC;AACjI,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,WAAW,CAAC,IAA4B;IACtD,OAAO,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC;AACjC,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Bidirectional async JSON-RPC 2.0 connection for MCPL.
3
+ * Port of mcpl-core/src/connection.rs
4
+ *
5
+ * Transport-agnostic: works over TCP, stdio, or any Node.js Readable/Writable pair.
6
+ * Messages are framed as newline-delimited JSON (one JSON object per line).
7
+ *
8
+ * Dual API:
9
+ * - Pull-based: `nextMessage()` returns the next incoming request/notification
10
+ * - Event-based: `.on('request', ...)` and `.on('notification', ...)`
11
+ *
12
+ * Responses to pending `sendRequest()` calls are routed internally and never
13
+ * surfaced through either API.
14
+ */
15
+ import type { EventEmitter as EventEmitterType } from 'node:events';
16
+ import * as net from 'node:net';
17
+ import type { Readable, Writable } from 'node:stream';
18
+ import type { JsonRpcId, JsonRpcRequest, JsonRpcNotification } from './types.js';
19
+ export type IncomingMessage = {
20
+ type: 'request';
21
+ request: JsonRpcRequest;
22
+ } | {
23
+ type: 'notification';
24
+ notification: JsonRpcNotification;
25
+ };
26
+ export interface McplConnectionEvents {
27
+ request: [request: JsonRpcRequest];
28
+ notification: [notification: JsonRpcNotification];
29
+ close: [];
30
+ error: [error: Error];
31
+ }
32
+ type TypedEmitter = {
33
+ on<K extends keyof McplConnectionEvents>(event: K, listener: (...args: McplConnectionEvents[K]) => void): TypedEmitter;
34
+ emit<K extends keyof McplConnectionEvents>(event: K, ...args: McplConnectionEvents[K]): boolean;
35
+ once<K extends keyof McplConnectionEvents>(event: K, listener: (...args: McplConnectionEvents[K]) => void): TypedEmitter;
36
+ removeListener<K extends keyof McplConnectionEvents>(event: K, listener: (...args: McplConnectionEvents[K]) => void): TypedEmitter;
37
+ } & EventEmitterType;
38
+ declare const McplConnection_base: new () => TypedEmitter;
39
+ export declare class McplConnection extends McplConnection_base {
40
+ private writer;
41
+ private rl;
42
+ private nextId;
43
+ private pending;
44
+ private incomingQueue;
45
+ private incomingWaiters;
46
+ private closed;
47
+ private constructor();
48
+ /** Create from a TCP socket. */
49
+ static fromTcp(socket: net.Socket): McplConnection;
50
+ /** Create from arbitrary readable/writable streams (e.g., stdin/stdout, child process). */
51
+ static fromStreams(readable: Readable, writable: Writable): McplConnection;
52
+ /** Accept a single TCP connection from a server and return an McplConnection. */
53
+ static acceptTcp(server: net.Server): Promise<McplConnection>;
54
+ /**
55
+ * Create from a WebSocket.
56
+ * Bridges WS message frames to the readline-based parser.
57
+ * Works with any WebSocket implementation that has `on('message')`, `send()`, and `on('close')`.
58
+ */
59
+ static fromWebSocket(ws: {
60
+ on(event: 'message', cb: (data: unknown) => void): void;
61
+ on(event: 'close', cb: () => void): void;
62
+ on(event: 'error', cb: (err: Error) => void): void;
63
+ send(data: string): void;
64
+ close(): void;
65
+ readyState?: number;
66
+ }): McplConnection;
67
+ get isClosed(): boolean;
68
+ /** Default timeout for sendRequest (ms). 0 = no timeout. */
69
+ requestTimeout: number;
70
+ /**
71
+ * Send a JSON-RPC request and wait for the response.
72
+ * Responses are matched by ID; incoming requests/notifications that arrive
73
+ * while waiting are queued for `nextMessage()` / event listeners.
74
+ *
75
+ * @param timeout Override the default request timeout (ms). 0 = no timeout.
76
+ */
77
+ sendRequest(method: string, params?: unknown, timeout?: number): Promise<unknown>;
78
+ /** Send a JSON-RPC notification (fire-and-forget, no response expected). */
79
+ sendNotification(method: string, params?: unknown): void;
80
+ /** Send a JSON-RPC success response (answering an incoming request). */
81
+ sendResponse(id: JsonRpcId, result: unknown): void;
82
+ /** Send a JSON-RPC error response. */
83
+ sendError(id: JsonRpcId, code: number, message: string): void;
84
+ /**
85
+ * Pull-based API: get the next incoming request or notification.
86
+ * Responses to our pending requests are routed internally (never returned here).
87
+ * Resolves when the next message arrives, or rejects on close.
88
+ */
89
+ nextMessage(): Promise<IncomingMessage>;
90
+ /** Close the connection. */
91
+ close(): void;
92
+ private writeLine;
93
+ private handleParsedMessage;
94
+ private routeResponse;
95
+ private routeIncoming;
96
+ private handleClose;
97
+ }
98
+ export {};
99
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAGhC,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EAEd,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAMpB,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,YAAY,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAEhE,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACnC,YAAY,EAAE,CAAC,YAAY,EAAE,mB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A4B;IAC5B,KAAK,IAAI,IAAI;IAWb,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,mBAAmB;IA0B3B,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,WAAW;CAoBpB"}
@@ -0,0 +1,280 @@
1
+ /**
2
+ * Bidirectional async JSON-RPC 2.0 connection for MCPL.
3
+ * Port of mcpl-core/src/connection.rs
4
+ *
5
+ * Transport-agnostic: works over TCP, stdio, or any Node.js Readable/Writable pair.
6
+ * Messages are framed as newline-delimited JSON (one JSON object per line).
7
+ *
8
+ * Dual API:
9
+ * - Pull-based: `nextMessage()` returns the next incoming request/notification
10
+ * - Event-based: `.on('request', ...)` and `.on('notification', ...)`
11
+ *
12
+ * Responses to pending `sendRequest()` calls are routed internally and never
13
+ * surfaced through either API.
14
+ */
15
+ import { EventEmitter } from 'node:events';
16
+ import * as readline from 'node:readline';
17
+ import { PassThrough } from 'node:stream';
18
+ import { makeRequest, makeResponse, makeErrorResponse, makeNotification } from './types.js';
19
+ import { ConnectionClosedError, RpcError } from './errors.js';
20
+ // ── Connection ──
21
+ export class McplConnection extends EventEmitter {
22
+ writer;
23
+ rl;
24
+ nextId = 1;
25
+ pending = new Map();
26
+ incomingQueue = [];
27
+ incomingWaiters = [];
28
+ closed = false;
29
+ constructor(readable, writable) {
30
+ super();
31
+ this.writer = writable;
32
+ this.rl = readline.createInterface({ input: readable, crlfDelay: Infinity });
33
+ this.rl.on('line', (line) => {
34
+ const trimmed = line.trim();
35
+ if (!trimmed)
36
+ return;
37
+ try {
38
+ const msg = JSON.parse(trimmed);
39
+ this.handleParsedMessage(msg);
40
+ }
41
+ catch (e) {
42
+ this.emit('error', new Error(`Malformed JSON-RPC message: ${e.message}`));
43
+ }
44
+ });
45
+ this.rl.on('close', () => {
46
+ this.handleClose();
47
+ });
48
+ readable.on('error', (err) => {
49
+ this.emit('error', err);
50
+ });
51
+ writable.on('error', (err) => {
52
+ this.emit('error', err);
53
+ });
54
+ }
55
+ // ── Factories ──
56
+ /** Create from a TCP socket. */
57
+ static fromTcp(socket) {
58
+ socket.setEncoding('utf-8');
59
+ return new McplConnection(socket, socket);
60
+ }
61
+ /** Create from arbitrary readable/writable streams (e.g., stdin/stdout, child process). */
62
+ static fromStreams(readable, writable) {
63
+ return new McplConnection(readable, writable);
64
+ }
65
+ /** Accept a single TCP connection from a server and return an McplConnection. */
66
+ static acceptTcp(server) {
67
+ return new Promise((resolve, reject) => {
68
+ server.once('connection', (socket) => {
69
+ resolve(McplConnection.fromTcp(socket));
70
+ });
71
+ server.once('error', reject);
72
+ });
73
+ }
74
+ /**
75
+ * Create from a WebSocket.
76
+ * Bridges WS message frames to the readline-based parser.
77
+ * Works with any WebSocket implementation that has `on('message')`, `send()`, and `on('close')`.
78
+ */
79
+ static fromWebSocket(ws) {
80
+ const readable = new PassThrough();
81
+ const writable = new PassThrough();
82
+ // WS message → readable stream (add newline for readline)
83
+ ws.on('message', (data) => {
84
+ const text = typeof data === 'string' ? data : String(data);
85
+ readable.push(text + '\n');
86
+ });
87
+ ws.on('close', () => {
88
+ readable.push(null); // EOF
89
+ });
90
+ ws.on('error', (err) => {
91
+ readable.destroy(err);
92
+ });
93
+ // Writable stream → WS message (strip trailing newline)
94
+ writable.on('data', (chunk) => {
95
+ const text = chunk.toString().replace(/\n$/, '');
96
+ if (text && ws.readyState === 1) { // OPEN
97
+ ws.send(text);
98
+ }
99
+ });
100
+ const conn = new McplConnection(readable, writable);
101
+ // Override close to also close the WebSocket
102
+ const originalClose = conn.close.bind(conn);
103
+ conn.close = () => {
104
+ originalClose();
105
+ ws.close();
106
+ };
107
+ return conn;
108
+ }
109
+ // ── Public API ──
110
+ get isClosed() {
111
+ return this.closed;
112
+ }
113
+ /** Default timeout for sendRequest (ms). 0 = no timeout. */
114
+ requestTimeout = 30_000;
115
+ /**
116
+ * Send a JSON-RPC request and wait for the response.
117
+ * Responses are matched by ID; incoming requests/notifications that arrive
118
+ * while waiting are queued for `nextMessage()` / event listeners.
119
+ *
120
+ * @param timeout Override the default request timeout (ms). 0 = no timeout.
121
+ */
122
+ async sendRequest(method, params, timeout) {
123
+ if (this.closed)
124
+ throw new ConnectionClosedError();
125
+ const id = this.nextId++;
126
+ const request = makeRequest(id, method, params);
127
+ const timeoutMs = timeout ?? this.requestTimeout;
128
+ return new Promise((resolve, reject) => {
129
+ let timer;
130
+ const cleanup = () => {
131
+ if (timer)
132
+ clearTimeout(timer);
133
+ this.pending.delete(String(id));
134
+ };
135
+ if (timeoutMs > 0) {
136
+ timer = setTimeout(() => {
137
+ const pending = this.pending.get(String(id));
138
+ if (pending) {
139
+ this.pending.delete(String(id));
140
+ reject(new RpcError(-32000, `Request timed out after ${timeoutMs}ms: ${method}`));
141
+ }
142
+ }, timeoutMs);
143
+ }
144
+ this.pending.set(String(id), {
145
+ resolve: (value) => { cleanup(); resolve(value); },
146
+ reject: (err) => { cleanup(); reject(err); },
147
+ timer,
148
+ });
149
+ this.writeLine(JSON.stringify(request));
150
+ });
151
+ }
152
+ /** Send a JSON-RPC notification (fire-and-forget, no response expected). */
153
+ sendNotification(method, params) {
154
+ if (this.closed)
155
+ return;
156
+ const notification = makeNotification(method, params);
157
+ this.writeLine(JSON.stringify(notification));
158
+ }
159
+ /** Send a JSON-RPC success response (answering an incoming request). */
160
+ sendResponse(id, result) {
161
+ if (this.closed)
162
+ return;
163
+ const response = makeResponse(id, result);
164
+ this.writeLine(JSON.stringify(response));
165
+ }
166
+ /** Send a JSON-RPC error response. */
167
+ sendError(id, code, message) {
168
+ if (this.closed)
169
+ return;
170
+ const response = makeErrorResponse(id, { code, message });
171
+ this.writeLine(JSON.stringify(response));
172
+ }
173
+ /**
174
+ * Pull-based API: get the next incoming request or notification.
175
+ * Responses to our pending requests are routed internally (never returned here).
176
+ * Resolves when the next message arrives, or rejects on close.
177
+ */
178
+ async nextMessage() {
179
+ // Drain queued messages first
180
+ const queued = this.incomingQueue.shift();
181
+ if (queued)
182
+ return queued;
183
+ if (this.closed)
184
+ throw new ConnectionClosedError();
185
+ // Wait for the next one
186
+ return new Promise((resolve, reject) => {
187
+ this.incomingWaiters.push({ resolve, reject });
188
+ });
189
+ }
190
+ /** Close the connection. */
191
+ close() {
192
+ if (this.closed)
193
+ return;
194
+ this.handleClose();
195
+ this.rl.close();
196
+ if ('destroy' in this.writer && typeof this.writer.destroy === 'function') {
197
+ this.writer.destroy();
198
+ }
199
+ }
200
+ // ── Internal ──
201
+ writeLine(json) {
202
+ this.writer.write(json + '\n');
203
+ }
204
+ handleParsedMessage(msg) {
205
+ if (msg.jsonrpc !== '2.0')
206
+ return; // Not a valid JSON-RPC 2.0 message
207
+ const hasId = msg.id != null;
208
+ const hasMethod = typeof msg.method === 'string';
209
+ const hasResult = 'result' in msg;
210
+ const hasError = 'error' in msg;
211
+ if (hasId && (hasResult || hasError)) {
212
+ // Response to one of our pending requests
213
+ this.routeResponse(msg);
214
+ }
215
+ else if (hasId && hasMethod) {
216
+ // Incoming request
217
+ this.routeIncoming({
218
+ type: 'request',
219
+ request: msg,
220
+ });
221
+ }
222
+ else if (hasMethod && !hasId) {
223
+ // Notification
224
+ this.routeIncoming({
225
+ type: 'notification',
226
+ notification: msg,
227
+ });
228
+ }
229
+ }
230
+ routeResponse(resp) {
231
+ const key = String(resp.id);
232
+ const pending = this.pending.get(key);
233
+ if (!pending)
234
+ return;
235
+ this.pending.delete(key);
236
+ if (resp.error) {
237
+ pending.reject(new RpcError(resp.error.code, resp.error.message));
238
+ }
239
+ else {
240
+ pending.resolve(resp.result);
241
+ }
242
+ }
243
+ routeIncoming(msg) {
244
+ // Emit events for EventEmitter consumers
245
+ if (msg.type === 'request') {
246
+ this.emit('request', msg.request);
247
+ }
248
+ else {
249
+ this.emit('notification', msg.notification);
250
+ }
251
+ // Feed pull-based consumers
252
+ const waiter = this.incomingWaiters.shift();
253
+ if (waiter) {
254
+ waiter.resolve(msg);
255
+ }
256
+ else {
257
+ this.incomingQueue.push(msg);
258
+ }
259
+ }
260
+ handleClose() {
261
+ if (this.closed)
262
+ return;
263
+ this.closed = true;
264
+ // Reject all pending requests and clear their timers
265
+ const closedErr = new ConnectionClosedError();
266
+ for (const [, pending] of this.pending) {
267
+ if (pending.timer)
268
+ clearTimeout(pending.timer);
269
+ pending.reject(closedErr);
270
+ }
271
+ this.pending.clear();
272
+ // Reject all pull-based waiters
273
+ for (const waiter of this.incomingWaiters) {
274
+ waiter.reject(closedErr);
275
+ }
276
+ this.incomingWaiters = [];
277
+ this.emit('close');
278
+ }
279
+ }
280
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAS1C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA+B9D,mBAAmB;AAEnB,MAAM,OAAO,cAAe,SAAS,YAAuC;IAClE,MAAM,CAAW;IACjB,EAAE,CAAqB;IACvB,MAAM,GAAG,CAAC,CAAC;IACX,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC5C,aAAa,GAAsB,EAAE,CAAC;IACtC,eAAe,GAGlB,EAAE,CAAC;IACA,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAoB,QAAkB,EAAE,QAAkB;QACxD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;QAEvB,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ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AC,CAAC;YAC/C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAErB,gCAAgC;QAChC,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YAC1C,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAE1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Error types for MCPL connections.
3
+ */
4
+ export declare class ConnectionError extends Error {
5
+ constructor(message: string);
6
+ }
7
+ export declare class ConnectionClosedError extends ConnectionError {
8
+ constructor();
9
+ }
10
+ export declare class ConnectionTimeoutError extends ConnectionError {
11
+ constructor();
12
+ }
13
+ export declare class RpcError extends ConnectionError {
14
+ readonly code: number;
15
+ constructor(code: number, message: string);
16
+ }
17
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,qBAAsB,SAAQ,eAAe;;CAKzD;AAED,qBAAa,sBAAuB,SAAQ,eAAe;;CAK1D;AAED,qBAAa,QAAS,SAAQ,eAAe;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Error types for MCPL connections.
3
+ */
4
+ export class ConnectionError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'ConnectionError';
8
+ }
9
+ }
10
+ export class ConnectionClosedError extends ConnectionError {
11
+ constructor() {
12
+ super('Connection closed');
13
+ this.name = 'ConnectionClosedError';
14
+ }
15
+ }
16
+ export class ConnectionTimeoutError extends ConnectionError {
17
+ constructor() {
18
+ super('Request timed out');
19
+ this.name = 'ConnectionTimeoutError';
20
+ }
21
+ }
22
+ export class RpcError extends ConnectionError {
23
+ code;
24
+ constructor(code, message) {
25
+ super(`RPC error ${code}: ${message}`);
26
+ this.name = 'RpcError';
27
+ this.code = code;
28
+ }
29
+ }
30
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IACxD;QACE,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,eAAe;IACzD;QACE,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF;AAED,MAAM,OAAO,QAAS,SAAQ,eAAe;IAClC,IAAI,CAAS;IAEtB,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,aAAa,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export * from './types.js';
2
+ export * from './methods.js';
3
+ export * from './capabilities.js';
4
+ export * from './connection.js';
5
+ export * from './errors.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './types.js';
2
+ export * from './methods.js';
3
+ export * from './capabilities.js';
4
+ export * from './connection.js';
5
+ export * from './errors.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,377 @@
1
+ /**
2
+ * MCPL method parameter and result types.
3
+ * Port of mcpl-core/src/methods.rs
4
+ *
5
+ * Property names use camelCase matching the JSON wire format.
6
+ */
7
+ import type { ContentBlock } from './types.js';
8
+ export interface FeatureSetDeclaration {
9
+ name: string;
10
+ description?: string;
11
+ uses: string[];
12
+ rollback: boolean;
13
+ hostState: boolean;
14
+ }
15
+ /** featureSets/update (Host → Server, Notification) */
16
+ export interface FeatureSetsUpdateParams {
17
+ enabled?: string[];
18
+ disabled?: string[];
19
+ scopes?: Record<string, ScopeConfig>;
20
+ }
21
+ export interface ScopeConfig {
22
+ whitelist?: string[];
23
+ blacklist?: string[];
24
+ }
25
+ /** featureSets/changed (Server → Host, Notification) */
26
+ export interface FeatureSetsChangedParams {
27
+ added?: Record<string, FeatureSetDeclaration>;
28
+ removed?: string[];
29
+ }
30
+ /** scope/elevate (Server → Host, Request) */
31
+ export interface ScopeElevateParams {
32
+ featureSet: string;
33
+ scope: ScopeElevateScope;
34
+ }
35
+ export interface ScopeElevateScope {
36
+ label: string;
37
+ payload?: unknown;
38
+ }
39
+ export interface ScopeElevateResult {
40
+ approved: boolean;
41
+ payload?: unknown;
42
+ reason?: string;
43
+ }
44
+ /** state/rollback (Host → Server, Request) */
45
+ export interface StateRollbackParams {
46
+ featureSet: string;
47
+ checkpoint: string;
48
+ }
49
+ export interface StateRollbackResult {
50
+ checkpoint: string;
51
+ success: boolean;
52
+ reason?: string;
53
+ /** Full state at the rolled-back checkpoint (for host-managed state). */
54
+ data?: unknown;
55
+ }
56
+ /** state/update (Server → Host, Request) */
57
+ export interface StateUpdateParams {
58
+ featureSet: string;
59
+ checkpoint: string;
60
+ parent: string | null;
61
+ /** Full state (mutually exclusive with patch). Both absent = opaque checkpoint. */
62
+ data?: unknown;
63
+ /** JSON Patch delta from parent (mutually exclusive with data). */
64
+ patch?: JsonPatchOperation[];
65
+ }
66
+ export interface StateUpdateResult {
67
+ accepted: boolean;
68
+ reason?: string;
69
+ }
70
+ /** state/get (Server → Host, Request) */
71
+ export interface StateGetParams {
72
+ featureSet: string;
73
+ }
74
+ export interface StateGetResult {
75
+ checkpoint: string | null;
76
+ data: unknown;
77
+ }
78
+ /** State checkpoint metadata (Section 8.2) */
79
+ export interface StateCheckpoint {
80
+ id: string;
81
+ featureSet: string;
82
+ timestamp: string;
83
+ parent?: string;
84
+ label?: string;
85
+ }
86
+ /**
87
+ * JSON Patch operation (RFC 6902) for host-managed state (Section 8.3).
88
+ * When a feature set declares `hostState: true`, the server sends patches
89
+ * in tool results, and the host applies them to reconstruct state.
90
+ */
91
+ export interface JsonPatchOperation {
92
+ op: 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test';
93
+ path: string;
94
+ value?: unknown;
95
+ from?: string;
96
+ }
97
+ /** State included in tool results when hostState is enabled */
98
+ export interface HostManagedState {
99
+ checkpoint: string;
100
+ patch?: JsonPatchOperation[];
101
+ }
102
+ /** push/event (Server → Host, Request) */
103
+ export interface PushEventParams {
104
+ featureSet: string;
105
+ eventId: string;
106
+ timestamp: string;
107
+ origin?: unknown;
108
+ payload: PushEventPayload;
109
+ }
110
+ export interface PushEventPayload {
111
+ content: ContentBlock[];
112
+ }
113
+ export interface PushEventResult {
114
+ accepted: boolean;
115
+ inferenceId?: string;
116
+ reason?: string;
117
+ }
118
+ export interface ModelInfo {
119
+ id: string;
120
+ vendor: string;
121
+ contextWindow: number;
122
+ capabilities: string[];
123
+ }
124
+ /** context/beforeInference (Host → Server, Request) */
125
+ export interface ContextBeforeInferenceParams {
126
+ inferenceId: string;
127
+ conversationId: string;
128
+ turnIndex: number;
129
+ userMessage?: string;
130
+ model: ModelInfo;
131
+ }
132
+ export interface ContextInjection {
133
+ namespace: string;
134
+ position: ContextInjectionPosition;
135
+ content: string | ContentBlock[];
136
+ metadata?: unknown;
137
+ }
138
+ export type ContextInjectionPosition = 'system' | 'beforeUser' | 'afterUser';
139
+ export interface ContextBeforeInferenceResult {
140
+ featureSet: string;
141
+ contextInjections: ContextInjection[];
142
+ }
143
+ /** context/afterInference (Host → Server, Request or Notification) */
144
+ export interface ContextAfterInferenceParams {
145
+ inferenceId: string;
146
+ conversationId: string;
147
+ turnIndex: number;
148
+ userMessage: string;
149
+ assistantMessage: string;
150
+ model: ModelInfo;
151
+ usage: InferenceUsage;
152
+ channels?: unknown;
153
+ }
154
+ export interface ContextAfterInferenceResult {
155
+ featureSet: string;
156
+ modifiedResponse?: string;
157
+ metadata?: unknown;
158
+ }
159
+ export interface InferenceUsage {
160
+ inputTokens: number;
161
+ outputTokens: number;
162
+ }
163
+ /** inference/request (Server → Host, Request) */
164
+ export interface InferenceRequestParams {
165
+ featureSet: string;
166
+ conversationId?: string;
167
+ stream?: boolean;
168
+ messages: InferenceMessage[];
169
+ preferences?: InferencePreferences;
170
+ }
171
+ export interface InferenceMessage {
172
+ role: string;
173
+ content: string;
174
+ }
175
+ export interface InferencePreferences {
176
+ maxTokens?: number;
177
+ temperature?: number;
178
+ }
179
+ export interface InferenceRequestResult {
180
+ content: string;
181
+ model: string;
182
+ finishReason: string;
183
+ usage: InferenceUsage;
184
+ }
185
+ /** inference/chunk (Host → Server, Notification) */
186
+ export interface InferenceChunkParams {
187
+ requestId: number;
188
+ index: number;
189
+ delta: string;
190
+ }
191
+ export type ModelInfoResult = ModelInfo;
192
+ export interface ChannelDescriptor {
193
+ id: string;
194
+ type: string;
195
+ label: string;
196
+ direction: ChannelDirection;
197
+ address?: unknown;
198
+ metadata?: unknown;
199
+ }
200
+ export type ChannelDirection = 'outbound' | 'inbound' | 'bidirectional';
201
+ /** channels/register (Server → Host, Request) */
202
+ export interface ChannelsRegisterParams {
203
+ channels: ChannelDescriptor[];
204
+ }
205
+ /** channels/changed (Server → Host, Notification) */
206
+ export interface ChannelsChangedParams {
207
+ added?: ChannelDescriptor[];
208
+ removed?: string[];
209
+ updated?: ChannelDescriptor[];
210
+ }
211
+ /** channels/list (Either direction, Request) */
212
+ export interface ChannelsListResult {
213
+ channels: ChannelDescriptor[];
214
+ }
215
+ /** channels/open (Host → Server, Request) */
216
+ export interface ChannelsOpenParams {
217
+ type: string;
218
+ address: unknown;
219
+ metadata?: unknown;
220
+ }
221
+ export interface ChannelsOpenResult {
222
+ channel: ChannelDescriptor;
223
+ }
224
+ /** channels/close (Host → Server, Request) */
225
+ export interface ChannelsCloseParams {
226
+ channelId: string;
227
+ }
228
+ export interface ChannelsCloseResult {
229
+ closed: boolean;
230
+ }
231
+ /** channels/outgoing/chunk (Host → Server, Notification) */
232
+ export interface ChannelsOutgoingChunkParams {
233
+ inferenceId: string;
234
+ conversationId: string;
235
+ channelId: string;
236
+ index: number;
237
+ delta: string;
238
+ }
239
+ /** channels/outgoing/complete (Host → Server, Notification) */
240
+ export interface ChannelsOutgoingCompleteParams {
241
+ inferenceId: string;
242
+ conversationId: string;
243
+ channelId: string;
244
+ content: ContentBlock[];
245
+ }
246
+ /** channels/publish (Host → Server, Notification or Request) */
247
+ export interface ChannelsPublishParams {
248
+ conversationId: string;
249
+ channelId: string;
250
+ stream?: boolean;
251
+ content: ContentBlock[];
252
+ }
253
+ export interface ChannelsPublishResult {
254
+ delivered: boolean;
255
+ messageId?: string;
256
+ }
257
+ /** channels/incoming (Server → Host, Request) */
258
+ export interface ChannelsIncomingParams {
259
+ messages: IncomingChannelMessage[];
260
+ }
261
+ export interface IncomingChannelMessage {
262
+ channelId: string;
263
+ messageId: string;
264
+ threadId?: string;
265
+ author: MessageAuthor;
266
+ timestamp: string;
267
+ content: ContentBlock[];
268
+ metadata?: unknown;
269
+ }
270
+ export interface MessageAuthor {
271
+ id: string;
272
+ name: string;
273
+ }
274
+ export interface ChannelsIncomingResult {
275
+ results: IncomingMessageResult[];
276
+ }
277
+ export interface IncomingMessageResult {
278
+ messageId: string;
279
+ accepted: boolean;
280
+ conversationId?: string;
281
+ }
282
+ export interface BranchInfo {
283
+ name: string;
284
+ head: number;
285
+ isCurrent: boolean;
286
+ parent: string | null;
287
+ branchPoint: number | null;
288
+ }
289
+ /** branches/list (Server → Host, Request) */
290
+ export interface BranchesListParams {
291
+ featureSet: string;
292
+ }
293
+ export interface BranchesListResult {
294
+ branches: BranchInfo[];
295
+ }
296
+ /** branches/current (Server → Host, Request) */
297
+ export interface BranchesCurrentParams {
298
+ featureSet: string;
299
+ }
300
+ export interface BranchesCurrentResult {
301
+ name: string;
302
+ head: number;
303
+ }
304
+ /** branches/create (Server → Host, Request) */
305
+ export interface BranchesCreateParams {
306
+ featureSet: string;
307
+ name: string;
308
+ from?: string;
309
+ atCheckpoint?: string;
310
+ }
311
+ export interface BranchesCreateResult {
312
+ accepted: boolean;
313
+ name?: string;
314
+ head?: number;
315
+ reason?: string;
316
+ }
317
+ /** branches/switch (Server → Host, Request) */
318
+ export interface BranchesSwitchParams {
319
+ featureSet: string;
320
+ name: string;
321
+ }
322
+ export interface BranchesSwitchResult {
323
+ accepted: boolean;
324
+ name?: string;
325
+ head?: number;
326
+ previous?: string;
327
+ reason?: string;
328
+ }
329
+ /** branches/delete (Server → Host, Request) */
330
+ export interface BranchesDeleteParams {
331
+ featureSet: string;
332
+ name: string;
333
+ }
334
+ export interface BranchesDeleteResult {
335
+ accepted: boolean;
336
+ name?: string;
337
+ reason?: string;
338
+ }
339
+ /** branches/changed (Host → Server, Notification) */
340
+ export interface BranchesChangedParams {
341
+ event: 'created' | 'switched' | 'deleted';
342
+ branch: string;
343
+ previous?: string;
344
+ head?: number;
345
+ parent?: string;
346
+ }
347
+ export declare const method: {
348
+ readonly INITIALIZE: "initialize";
349
+ readonly FEATURE_SETS_UPDATE: "featureSets/update";
350
+ readonly FEATURE_SETS_CHANGED: "featureSets/changed";
351
+ readonly SCOPE_ELEVATE: "scope/elevate";
352
+ readonly STATE_UPDATE: "state/update";
353
+ readonly STATE_GET: "state/get";
354
+ readonly STATE_ROLLBACK: "state/rollback";
355
+ readonly PUSH_EVENT: "push/event";
356
+ readonly CONTEXT_BEFORE_INFERENCE: "context/beforeInference";
357
+ readonly CONTEXT_AFTER_INFERENCE: "context/afterInference";
358
+ readonly INFERENCE_REQUEST: "inference/request";
359
+ readonly INFERENCE_CHUNK: "inference/chunk";
360
+ readonly MODEL_INFO: "model/info";
361
+ readonly CHANNELS_REGISTER: "channels/register";
362
+ readonly CHANNELS_CHANGED: "channels/changed";
363
+ readonly CHANNELS_LIST: "channels/list";
364
+ readonly CHANNELS_OPEN: "channels/open";
365
+ readonly CHANNELS_CLOSE: "channels/close";
366
+ readonly CHANNELS_OUTGOING_CHUNK: "channels/outgoing/chunk";
367
+ readonly CHANNELS_OUTGOING_COMPLETE: "channels/outgoing/complete";
368
+ readonly CHANNELS_PUBLISH: "channels/publish";
369
+ readonly CHANNELS_INCOMING: "channels/incoming";
370
+ readonly BRANCHES_LIST: "branches/list";
371
+ readonly BRANCHES_CURRENT: "branches/current";
372
+ readonly BRANCHES_CREATE: "branches/create";
373
+ readonly BRANCHES_SWITCH: "branches/switch";
374
+ readonly BRANCHES_DELETE: "branches/delete";
375
+ readonly BRANCHES_CHANGED: "branches/changed";
376
+ };
377
+ //# sourceMappingURL=methods.d.ts.map
@@ -0,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ED,qDAAqD;AACrD,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAID,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BT,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * MCPL method parameter and result types.
3
+ * Port of mcpl-core/src/methods.rs
4
+ *
5
+ * Property names use camelCase matching the JSON wire format.
6
+ */
7
+ // ── Method Name Constants ──
8
+ export const method = {
9
+ INITIALIZE: 'initialize',
10
+ FEATURE_SETS_UPDATE: 'featureSets/update',
11
+ FEATURE_SETS_CHANGED: 'featureSets/changed',
12
+ SCOPE_ELEVATE: 'scope/elevate',
13
+ STATE_UPDATE: 'state/update',
14
+ STATE_GET: 'state/get',
15
+ STATE_ROLLBACK: 'state/rollback',
16
+ PUSH_EVENT: 'push/event',
17
+ CONTEXT_BEFORE_INFERENCE: 'context/beforeInference',
18
+ CONTEXT_AFTER_INFERENCE: 'context/afterInference',
19
+ INFERENCE_REQUEST: 'inference/request',
20
+ INFERENCE_CHUNK: 'inference/chunk',
21
+ MODEL_INFO: 'model/info',
22
+ CHANNELS_REGISTER: 'channels/register',
23
+ CHANNELS_CHANGED: 'channels/changed',
24
+ CHANNELS_LIST: 'channels/list',
25
+ CHANNELS_OPEN: 'channels/open',
26
+ CHANNELS_CLOSE: 'channels/close',
27
+ CHANNELS_OUTGOING_CHUNK: 'channels/outgoing/chunk',
28
+ CHANNELS_OUTGOING_COMPLETE: 'channels/outgoing/complete',
29
+ CHANNELS_PUBLISH: 'channels/publish',
30
+ CHANNELS_INCOMING: 'channels/incoming',
31
+ BRANCHES_LIST: 'branches/list',
32
+ BRANCHES_CURRENT: 'branches/current',
33
+ BRANCHES_CREATE: 'branches/create',
34
+ BRANCHES_SWITCH: 'branches/switch',
35
+ BRANCHES_DELETE: 'branches/delete',
36
+ BRANCHES_CHANGED: 'branches/changed',
37
+ };
38
+ //# sourceMappingURL=methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/methods.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwaH,8BAA8B;AAE9B,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,UAAU,EAAE,YAAY;IACxB,mBAAmB,EAAE,oBAAoB;IACzC,oBAAoB,EAAE,qBAAqB;IAC3C,aAAa,EAAE,eAAe;IAC9B,YAAY,EAAE,cAAc;IAC5B,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE,gBAAgB;IAChC,UAAU,EAAE,YAAY;IACxB,wBAAwB,EAAE,yBAAyB;IACnD,uBAAuB,EAAE,wBAAwB;IACjD,iBAAiB,EAAE,mBAAmB;IACtC,eAAe,EAAE,iBAAiB;IAClC,UAAU,EAAE,YAAY;IACxB,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,aAAa,EAAE,eAAe;IAC9B,aAAa,EAAE,eAAe;IAC9B,cAAc,EAAE,gBAAgB;IAChC,uBAAuB,EAAE,yBAAyB;IAClD,0BAA0B,EAAE,4BAA4B;IACxD,gBAAgB,EAAE,kBAAkB;IACpC,iBAAiB,EAAE,mBAAmB;IACtC,aAAa,EAAE,eAAe;IAC9B,gBAAgB,EAAE,kBAAkB;IACpC,eAAe,EAAE,iBAAiB;IAClC,eAAe,EAAE,iBAAiB;IAClC,eAAe,EAAE,iBAAiB;IAClC,gBAAgB,EAAE,kBAAkB;CAC5B,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * JSON-RPC 2.0 message types for MCPL transport.
3
+ * Port of mcpl-core/src/types.rs
4
+ */
5
+ export type JsonRpcId = number | string;
6
+ export interface JsonRpcRequest {
7
+ jsonrpc: '2.0';
8
+ id: JsonRpcId;
9
+ method: string;
10
+ params?: unknown;
11
+ }
12
+ export interface JsonRpcResponse {
13
+ jsonrpc: '2.0';
14
+ id: JsonRpcId;
15
+ result?: unknown;
16
+ error?: JsonRpcError;
17
+ }
18
+ export interface JsonRpcNotification {
19
+ jsonrpc: '2.0';
20
+ method: string;
21
+ params?: unknown;
22
+ }
23
+ export interface JsonRpcError {
24
+ code: number;
25
+ message: string;
26
+ data?: unknown;
27
+ }
28
+ export type JsonRpcMessage = JsonRpcRequest | JsonRpcResponse | JsonRpcNotification;
29
+ export declare function makeRequest(id: JsonRpcId, method: string, params?: unknown): JsonRpcRequest;
30
+ export declare function makeResponse(id: JsonRpcId, result: unknown): JsonRpcResponse;
31
+ export declare function makeErrorResponse(id: JsonRpcId, error: JsonRpcError): JsonRpcResponse;
32
+ export declare function makeNotification(method: string, params?: unknown): JsonRpcNotification;
33
+ export type ContentBlock = TextContent | ImageContent | AudioContent | ResourceContent;
34
+ export interface TextContent {
35
+ type: 'text';
36
+ text: string;
37
+ }
38
+ export type ImageContent = {
39
+ type: 'image';
40
+ data: string;
41
+ mimeType?: string;
42
+ uri?: never;
43
+ } | {
44
+ type: 'image';
45
+ uri: string;
46
+ mimeType?: string;
47
+ data?: never;
48
+ };
49
+ export type AudioContent = {
50
+ type: 'audio';
51
+ data: string;
52
+ mimeType?: string;
53
+ uri?: never;
54
+ } | {
55
+ type: 'audio';
56
+ uri: string;
57
+ mimeType?: string;
58
+ data?: never;
59
+ };
60
+ export interface ResourceContent {
61
+ type: 'resource';
62
+ uri: string;
63
+ }
64
+ export declare function textContent(text: string): TextContent;
65
+ export declare const ERR_FEATURE_SET_NOT_ENABLED = -32001;
66
+ export declare const ERR_UNKNOWN_FEATURE_SET = -32003;
67
+ export declare const ERR_CHECKPOINT_NOT_FOUND = -32005;
68
+ export declare const ERR_CHANNEL_NOT_PERMITTED = -32017;
69
+ export declare const ERR_UNKNOWN_CHANNEL = -32023;
70
+ export declare const ERR_CHANNEL_OPEN_FAILED = -32024;
71
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAExC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,SAAS,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,SAAS,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,eAAe,GAAG,mBAAmB,CAAC;AAIpF,wBAAgB,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,cAAc,CAE3F;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAG,eAAe,CAE5E;AAED,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,GAAG,eAAe,CAErF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,mBAAmB,CAEtF;AAID,MAA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
3
+ * Port of mcpl-core/src/types.rs
4
+ */
5
+ // ── Constructors ──
6
+ export function makeRequest(id, method, params) {
7
+ return { jsonrpc: '2.0', id, method, ...(params !== undefined && { params }) };
8
+ }
9
+ export function makeResponse(id, result) {
10
+ return { jsonrpc: '2.0', id, result };
11
+ }
12
+ export function makeErrorResponse(id, error) {
13
+ return { jsonrpc: '2.0', id, error };
14
+ }
15
+ export function makeNotification(method, params) {
16
+ return { jsonrpc: '2.0', method, ...(params !== undefined && { params }) };
17
+ }
18
+ export function textContent(text) {
19
+ return { type: 'text', text };
20
+ }
21
+ // ── MCPL Error Codes ──
22
+ export const ERR_FEATURE_SET_NOT_ENABLED = -32001;
23
+ export const ERR_UNKNOWN_FEATURE_SET = -32003;
24
+ export const ERR_CHECKPOINT_NOT_FOUND = -32005;
25
+ export const ERR_CHANNEL_NOT_PERMITTED = -32017;
26
+ export const ERR_UNKNOWN_CHANNEL = -32023;
27
+ export const ERR_CHANNEL_OPEN_FAILED = -32024;
28
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkCH,qBAAqB;AAErB,MAAM,UAAU,WAAW,CAAC,EAAa,EAAE,MAAc,EAAE,MAAgB;IACzE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAAa,EAAE,MAAe;IACzD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,EAAa,EAAE,KAAmB;IAClE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,MAAgB;IAC/D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;AAC7E,CAAC;AA4CD,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AAED,yBAAyB;AAEzB,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,KAAK,CAAC;AAClD,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAK,CAAC;AAC9C,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAK,CAAC;AAC/C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,KAAK,CAAC;AAChD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,CAAC;AAC1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,KAAK,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@animalabs/mcpl-core",
3
+ "version": "0.1.0",
4
+ "description": "MCPL core: JSON-RPC connection, channels, push events, and capability types.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/anima-research/mcpl-core-ts.git"
9
+ },
10
+ "type": "module",
11
+ "main": "./dist/src/index.js",
12
+ "types": "./dist/src/index.d.ts",
13
+ "files": [
14
+ "dist/src"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "prepublishOnly": "npm run clean && npm run build",
22
+ "typecheck": "tsc --noEmit",
23
+ "test": "node --import tsx --test test/*.test.ts",
24
+ "clean": "rm -rf dist"
25
+ },
26
+ "devDependencies": {
27
+ "tsx": "^4.7.0",
28
+ "typescript": "^5.5.0",
29
+ "@types/node": "^20.0.0"
30
+ },
31
+ "engines": {
32
+ "node": ">=20.0.0"
33
+ }
34
+ }