@codebolt/narrative 1.11.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/dist/api/command.api.d.ts +12 -0
- package/dist/api/command.api.js +27 -0
- package/dist/api/fs.api.d.ts +13 -0
- package/dist/api/fs.api.js +30 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +17 -0
- package/dist/api/narrative.api.d.ts +11 -0
- package/dist/api/narrative.api.js +24 -0
- package/dist/api/queue.api.d.ts +9 -0
- package/dist/api/queue.api.js +18 -0
- package/dist/api/snapshot.api.d.ts +18 -0
- package/dist/api/snapshot.api.js +45 -0
- package/dist/api/timeline.api.d.ts +11 -0
- package/dist/api/timeline.api.js +24 -0
- package/dist/api/trace.api.d.ts +12 -0
- package/dist/api/trace.api.js +27 -0
- package/dist/binary.d.ts +10 -0
- package/dist/binary.js +88 -0
- package/dist/client.d.ts +74 -0
- package/dist/client.js +127 -0
- package/dist/errors.d.ts +35 -0
- package/dist/errors.js +68 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +69 -0
- package/dist/transport.d.ts +42 -0
- package/dist/transport.js +184 -0
- package/dist/types/command.d.ts +59 -0
- package/dist/types/command.js +2 -0
- package/dist/types/common.d.ts +10 -0
- package/dist/types/common.js +2 -0
- package/dist/types/fs.d.ts +69 -0
- package/dist/types/fs.js +2 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.js +26 -0
- package/dist/types/jsonrpc.d.ts +22 -0
- package/dist/types/jsonrpc.js +2 -0
- package/dist/types/narrative.d.ts +67 -0
- package/dist/types/narrative.js +2 -0
- package/dist/types/notifications.d.ts +23 -0
- package/dist/types/notifications.js +2 -0
- package/dist/types/queue.d.ts +38 -0
- package/dist/types/queue.js +2 -0
- package/dist/types/snapshot.d.ts +128 -0
- package/dist/types/snapshot.js +3 -0
- package/dist/types/timeline.d.ts +64 -0
- package/dist/types/timeline.js +2 -0
- package/dist/types/trace.d.ts +105 -0
- package/dist/types/trace.js +3 -0
- package/package.json +26 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error codes mapped from Rust NarrativeError::to_rpc_code().
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NarrativeRpcError = exports.CONFIG_ERROR = exports.INVALID_OPERATION = exports.MERGE_CONFLICT = exports.FILE_NOT_FOUND = exports.QUEUE_ERROR = exports.EXECUTION_ERROR = exports.SESSION_NOT_FOUND = exports.PTY_ERROR = exports.SNAPSHOT_NOT_FOUND = exports.INVALID_CONTEXT = exports.PREEMPTION = exports.SLOT_TIMEOUT = exports.SLOT_UNAVAILABLE = exports.SQLITE_ERROR = exports.GIT_ERROR = exports.IO_ERROR = exports.METHOD_NOT_FOUND = exports.INVALID_REQUEST = exports.PARSE_ERROR = void 0;
|
|
7
|
+
exports.isSlotUnavailable = isSlotUnavailable;
|
|
8
|
+
exports.isSlotTimeout = isSlotTimeout;
|
|
9
|
+
exports.isSnapshotNotFound = isSnapshotNotFound;
|
|
10
|
+
exports.isFileNotFound = isFileNotFound;
|
|
11
|
+
exports.isSessionNotFound = isSessionNotFound;
|
|
12
|
+
exports.isMergeConflict = isMergeConflict;
|
|
13
|
+
exports.isInvalidContext = isInvalidContext;
|
|
14
|
+
exports.isMethodNotFound = isMethodNotFound;
|
|
15
|
+
// Standard JSON-RPC errors
|
|
16
|
+
exports.PARSE_ERROR = -32700;
|
|
17
|
+
exports.INVALID_REQUEST = -32600;
|
|
18
|
+
exports.METHOD_NOT_FOUND = -32601;
|
|
19
|
+
// Narrative engine errors
|
|
20
|
+
exports.IO_ERROR = -32000;
|
|
21
|
+
exports.GIT_ERROR = -32001;
|
|
22
|
+
exports.SQLITE_ERROR = -32002;
|
|
23
|
+
exports.SLOT_UNAVAILABLE = -32010;
|
|
24
|
+
exports.SLOT_TIMEOUT = -32011;
|
|
25
|
+
exports.PREEMPTION = -32012;
|
|
26
|
+
exports.INVALID_CONTEXT = -32020;
|
|
27
|
+
exports.SNAPSHOT_NOT_FOUND = -32030;
|
|
28
|
+
exports.PTY_ERROR = -32040;
|
|
29
|
+
exports.SESSION_NOT_FOUND = -32041;
|
|
30
|
+
exports.EXECUTION_ERROR = -32042;
|
|
31
|
+
exports.QUEUE_ERROR = -32050;
|
|
32
|
+
exports.FILE_NOT_FOUND = -32060;
|
|
33
|
+
exports.MERGE_CONFLICT = -32070;
|
|
34
|
+
exports.INVALID_OPERATION = -32600;
|
|
35
|
+
exports.CONFIG_ERROR = -32603;
|
|
36
|
+
class NarrativeRpcError extends Error {
|
|
37
|
+
constructor(code, message, data) {
|
|
38
|
+
super(message);
|
|
39
|
+
this.name = 'NarrativeRpcError';
|
|
40
|
+
this.code = code;
|
|
41
|
+
this.data = data;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.NarrativeRpcError = NarrativeRpcError;
|
|
45
|
+
function isSlotUnavailable(err) {
|
|
46
|
+
return err instanceof NarrativeRpcError && err.code === exports.SLOT_UNAVAILABLE;
|
|
47
|
+
}
|
|
48
|
+
function isSlotTimeout(err) {
|
|
49
|
+
return err instanceof NarrativeRpcError && err.code === exports.SLOT_TIMEOUT;
|
|
50
|
+
}
|
|
51
|
+
function isSnapshotNotFound(err) {
|
|
52
|
+
return err instanceof NarrativeRpcError && err.code === exports.SNAPSHOT_NOT_FOUND;
|
|
53
|
+
}
|
|
54
|
+
function isFileNotFound(err) {
|
|
55
|
+
return err instanceof NarrativeRpcError && err.code === exports.FILE_NOT_FOUND;
|
|
56
|
+
}
|
|
57
|
+
function isSessionNotFound(err) {
|
|
58
|
+
return err instanceof NarrativeRpcError && err.code === exports.SESSION_NOT_FOUND;
|
|
59
|
+
}
|
|
60
|
+
function isMergeConflict(err) {
|
|
61
|
+
return err instanceof NarrativeRpcError && err.code === exports.MERGE_CONFLICT;
|
|
62
|
+
}
|
|
63
|
+
function isInvalidContext(err) {
|
|
64
|
+
return err instanceof NarrativeRpcError && err.code === exports.INVALID_CONTEXT;
|
|
65
|
+
}
|
|
66
|
+
function isMethodNotFound(err) {
|
|
67
|
+
return err instanceof NarrativeRpcError && err.code === exports.METHOD_NOT_FOUND;
|
|
68
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { NarrativeClient, NarrativeClientOptions } from './client';
|
|
2
|
+
export { NarrativeTransport, TransportOptions } from './transport';
|
|
3
|
+
export { resolveBinary } from './binary';
|
|
4
|
+
export { NarrativeRpcError, PARSE_ERROR, INVALID_REQUEST, METHOD_NOT_FOUND, IO_ERROR, GIT_ERROR, SQLITE_ERROR, SLOT_UNAVAILABLE, SLOT_TIMEOUT, PREEMPTION, INVALID_CONTEXT, SNAPSHOT_NOT_FOUND, PTY_ERROR, SESSION_NOT_FOUND, EXECUTION_ERROR, QUEUE_ERROR, FILE_NOT_FOUND, MERGE_CONFLICT, INVALID_OPERATION, CONFIG_ERROR, isSlotUnavailable, isSlotTimeout, isSnapshotNotFound, isFileNotFound, isSessionNotFound, isMergeConflict, isInvalidContext, isMethodNotFound, } from './errors';
|
|
5
|
+
export { FsApi, CommandApi, QueueApi, TimelineApi, NarrativeApi, SnapshotApi, TraceApi, } from './api';
|
|
6
|
+
export * from './types';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TraceApi = exports.SnapshotApi = exports.NarrativeApi = exports.TimelineApi = exports.QueueApi = exports.CommandApi = exports.FsApi = exports.isMethodNotFound = exports.isInvalidContext = exports.isMergeConflict = exports.isSessionNotFound = exports.isFileNotFound = exports.isSnapshotNotFound = exports.isSlotTimeout = exports.isSlotUnavailable = exports.CONFIG_ERROR = exports.INVALID_OPERATION = exports.MERGE_CONFLICT = exports.FILE_NOT_FOUND = exports.QUEUE_ERROR = exports.EXECUTION_ERROR = exports.SESSION_NOT_FOUND = exports.PTY_ERROR = exports.SNAPSHOT_NOT_FOUND = exports.INVALID_CONTEXT = exports.PREEMPTION = exports.SLOT_TIMEOUT = exports.SLOT_UNAVAILABLE = exports.SQLITE_ERROR = exports.GIT_ERROR = exports.IO_ERROR = exports.METHOD_NOT_FOUND = exports.INVALID_REQUEST = exports.PARSE_ERROR = exports.NarrativeRpcError = exports.resolveBinary = exports.NarrativeTransport = exports.NarrativeClient = void 0;
|
|
18
|
+
// Client
|
|
19
|
+
var client_1 = require("./client");
|
|
20
|
+
Object.defineProperty(exports, "NarrativeClient", { enumerable: true, get: function () { return client_1.NarrativeClient; } });
|
|
21
|
+
// Transport
|
|
22
|
+
var transport_1 = require("./transport");
|
|
23
|
+
Object.defineProperty(exports, "NarrativeTransport", { enumerable: true, get: function () { return transport_1.NarrativeTransport; } });
|
|
24
|
+
// Binary resolution
|
|
25
|
+
var binary_1 = require("./binary");
|
|
26
|
+
Object.defineProperty(exports, "resolveBinary", { enumerable: true, get: function () { return binary_1.resolveBinary; } });
|
|
27
|
+
// Errors
|
|
28
|
+
var errors_1 = require("./errors");
|
|
29
|
+
Object.defineProperty(exports, "NarrativeRpcError", { enumerable: true, get: function () { return errors_1.NarrativeRpcError; } });
|
|
30
|
+
// Error codes
|
|
31
|
+
Object.defineProperty(exports, "PARSE_ERROR", { enumerable: true, get: function () { return errors_1.PARSE_ERROR; } });
|
|
32
|
+
Object.defineProperty(exports, "INVALID_REQUEST", { enumerable: true, get: function () { return errors_1.INVALID_REQUEST; } });
|
|
33
|
+
Object.defineProperty(exports, "METHOD_NOT_FOUND", { enumerable: true, get: function () { return errors_1.METHOD_NOT_FOUND; } });
|
|
34
|
+
Object.defineProperty(exports, "IO_ERROR", { enumerable: true, get: function () { return errors_1.IO_ERROR; } });
|
|
35
|
+
Object.defineProperty(exports, "GIT_ERROR", { enumerable: true, get: function () { return errors_1.GIT_ERROR; } });
|
|
36
|
+
Object.defineProperty(exports, "SQLITE_ERROR", { enumerable: true, get: function () { return errors_1.SQLITE_ERROR; } });
|
|
37
|
+
Object.defineProperty(exports, "SLOT_UNAVAILABLE", { enumerable: true, get: function () { return errors_1.SLOT_UNAVAILABLE; } });
|
|
38
|
+
Object.defineProperty(exports, "SLOT_TIMEOUT", { enumerable: true, get: function () { return errors_1.SLOT_TIMEOUT; } });
|
|
39
|
+
Object.defineProperty(exports, "PREEMPTION", { enumerable: true, get: function () { return errors_1.PREEMPTION; } });
|
|
40
|
+
Object.defineProperty(exports, "INVALID_CONTEXT", { enumerable: true, get: function () { return errors_1.INVALID_CONTEXT; } });
|
|
41
|
+
Object.defineProperty(exports, "SNAPSHOT_NOT_FOUND", { enumerable: true, get: function () { return errors_1.SNAPSHOT_NOT_FOUND; } });
|
|
42
|
+
Object.defineProperty(exports, "PTY_ERROR", { enumerable: true, get: function () { return errors_1.PTY_ERROR; } });
|
|
43
|
+
Object.defineProperty(exports, "SESSION_NOT_FOUND", { enumerable: true, get: function () { return errors_1.SESSION_NOT_FOUND; } });
|
|
44
|
+
Object.defineProperty(exports, "EXECUTION_ERROR", { enumerable: true, get: function () { return errors_1.EXECUTION_ERROR; } });
|
|
45
|
+
Object.defineProperty(exports, "QUEUE_ERROR", { enumerable: true, get: function () { return errors_1.QUEUE_ERROR; } });
|
|
46
|
+
Object.defineProperty(exports, "FILE_NOT_FOUND", { enumerable: true, get: function () { return errors_1.FILE_NOT_FOUND; } });
|
|
47
|
+
Object.defineProperty(exports, "MERGE_CONFLICT", { enumerable: true, get: function () { return errors_1.MERGE_CONFLICT; } });
|
|
48
|
+
Object.defineProperty(exports, "INVALID_OPERATION", { enumerable: true, get: function () { return errors_1.INVALID_OPERATION; } });
|
|
49
|
+
Object.defineProperty(exports, "CONFIG_ERROR", { enumerable: true, get: function () { return errors_1.CONFIG_ERROR; } });
|
|
50
|
+
// Predicates
|
|
51
|
+
Object.defineProperty(exports, "isSlotUnavailable", { enumerable: true, get: function () { return errors_1.isSlotUnavailable; } });
|
|
52
|
+
Object.defineProperty(exports, "isSlotTimeout", { enumerable: true, get: function () { return errors_1.isSlotTimeout; } });
|
|
53
|
+
Object.defineProperty(exports, "isSnapshotNotFound", { enumerable: true, get: function () { return errors_1.isSnapshotNotFound; } });
|
|
54
|
+
Object.defineProperty(exports, "isFileNotFound", { enumerable: true, get: function () { return errors_1.isFileNotFound; } });
|
|
55
|
+
Object.defineProperty(exports, "isSessionNotFound", { enumerable: true, get: function () { return errors_1.isSessionNotFound; } });
|
|
56
|
+
Object.defineProperty(exports, "isMergeConflict", { enumerable: true, get: function () { return errors_1.isMergeConflict; } });
|
|
57
|
+
Object.defineProperty(exports, "isInvalidContext", { enumerable: true, get: function () { return errors_1.isInvalidContext; } });
|
|
58
|
+
Object.defineProperty(exports, "isMethodNotFound", { enumerable: true, get: function () { return errors_1.isMethodNotFound; } });
|
|
59
|
+
// Domain APIs
|
|
60
|
+
var api_1 = require("./api");
|
|
61
|
+
Object.defineProperty(exports, "FsApi", { enumerable: true, get: function () { return api_1.FsApi; } });
|
|
62
|
+
Object.defineProperty(exports, "CommandApi", { enumerable: true, get: function () { return api_1.CommandApi; } });
|
|
63
|
+
Object.defineProperty(exports, "QueueApi", { enumerable: true, get: function () { return api_1.QueueApi; } });
|
|
64
|
+
Object.defineProperty(exports, "TimelineApi", { enumerable: true, get: function () { return api_1.TimelineApi; } });
|
|
65
|
+
Object.defineProperty(exports, "NarrativeApi", { enumerable: true, get: function () { return api_1.NarrativeApi; } });
|
|
66
|
+
Object.defineProperty(exports, "SnapshotApi", { enumerable: true, get: function () { return api_1.SnapshotApi; } });
|
|
67
|
+
Object.defineProperty(exports, "TraceApi", { enumerable: true, get: function () { return api_1.TraceApi; } });
|
|
68
|
+
// Types
|
|
69
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export interface TransportOptions {
|
|
3
|
+
/** CLI args to pass to the binary. */
|
|
4
|
+
args: string[];
|
|
5
|
+
/** Path to the binary. */
|
|
6
|
+
binaryPath: string;
|
|
7
|
+
/** Default request timeout in ms. */
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* JSON-RPC 2.0 stdio transport.
|
|
12
|
+
*
|
|
13
|
+
* Spawns the codebolt-narrative binary, sends newline-delimited JSON
|
|
14
|
+
* requests on stdin, and reads newline-delimited JSON responses/notifications
|
|
15
|
+
* from stdout.
|
|
16
|
+
*/
|
|
17
|
+
export declare class NarrativeTransport extends EventEmitter {
|
|
18
|
+
private process;
|
|
19
|
+
private readline;
|
|
20
|
+
private nextId;
|
|
21
|
+
private pending;
|
|
22
|
+
private readonly options;
|
|
23
|
+
private _ready;
|
|
24
|
+
constructor(options: TransportOptions);
|
|
25
|
+
get isReady(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Start the engine process and wait for the "ready" signal on stderr.
|
|
28
|
+
*/
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Send a JSON-RPC request and await the response.
|
|
32
|
+
*/
|
|
33
|
+
request<T = unknown>(method: string, params?: unknown): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Gracefully shut down the engine process.
|
|
36
|
+
*
|
|
37
|
+
* Closes stdin (engine exits on EOF), then SIGTERM, then SIGKILL.
|
|
38
|
+
*/
|
|
39
|
+
shutdown(): Promise<void>;
|
|
40
|
+
private handleLine;
|
|
41
|
+
private handleProcessExit;
|
|
42
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NarrativeTransport = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const readline_1 = require("readline");
|
|
6
|
+
const events_1 = require("events");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
const DEFAULT_TIMEOUT_MS = 30000;
|
|
9
|
+
/**
|
|
10
|
+
* JSON-RPC 2.0 stdio transport.
|
|
11
|
+
*
|
|
12
|
+
* Spawns the codebolt-narrative binary, sends newline-delimited JSON
|
|
13
|
+
* requests on stdin, and reads newline-delimited JSON responses/notifications
|
|
14
|
+
* from stdout.
|
|
15
|
+
*/
|
|
16
|
+
class NarrativeTransport extends events_1.EventEmitter {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super();
|
|
19
|
+
this.process = null;
|
|
20
|
+
this.readline = null;
|
|
21
|
+
this.nextId = 1;
|
|
22
|
+
this.pending = new Map();
|
|
23
|
+
this._ready = false;
|
|
24
|
+
this.options = options;
|
|
25
|
+
}
|
|
26
|
+
get isReady() {
|
|
27
|
+
return this._ready;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Start the engine process and wait for the "ready" signal on stderr.
|
|
31
|
+
*/
|
|
32
|
+
async start() {
|
|
33
|
+
if (this.process) {
|
|
34
|
+
throw new Error('Transport already started');
|
|
35
|
+
}
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const proc = (0, child_process_1.spawn)(this.options.binaryPath, this.options.args, {
|
|
38
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
39
|
+
});
|
|
40
|
+
this.process = proc;
|
|
41
|
+
// Wait for ready signal on stderr
|
|
42
|
+
let readyResolved = false;
|
|
43
|
+
const stderrRl = (0, readline_1.createInterface)({ input: proc.stderr });
|
|
44
|
+
stderrRl.on('line', (line) => {
|
|
45
|
+
if (!readyResolved && line.includes('ready')) {
|
|
46
|
+
readyResolved = true;
|
|
47
|
+
this._ready = true;
|
|
48
|
+
resolve();
|
|
49
|
+
}
|
|
50
|
+
this.emit('stderr', line);
|
|
51
|
+
});
|
|
52
|
+
// Parse stdout line by line for JSON-RPC messages
|
|
53
|
+
this.readline = (0, readline_1.createInterface)({ input: proc.stdout });
|
|
54
|
+
this.readline.on('line', (line) => {
|
|
55
|
+
this.handleLine(line);
|
|
56
|
+
});
|
|
57
|
+
proc.on('error', (err) => {
|
|
58
|
+
if (!readyResolved) {
|
|
59
|
+
readyResolved = true;
|
|
60
|
+
reject(err);
|
|
61
|
+
}
|
|
62
|
+
this.handleProcessExit(-1);
|
|
63
|
+
});
|
|
64
|
+
proc.on('exit', (code) => {
|
|
65
|
+
this.handleProcessExit(code ?? -1);
|
|
66
|
+
});
|
|
67
|
+
// Timeout for startup
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
if (!readyResolved) {
|
|
70
|
+
readyResolved = true;
|
|
71
|
+
reject(new Error('Engine failed to become ready within 10s'));
|
|
72
|
+
}
|
|
73
|
+
}, 10000);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Send a JSON-RPC request and await the response.
|
|
78
|
+
*/
|
|
79
|
+
async request(method, params = {}) {
|
|
80
|
+
if (!this.process || !this.process.stdin) {
|
|
81
|
+
throw new Error('Transport not started');
|
|
82
|
+
}
|
|
83
|
+
const id = this.nextId++;
|
|
84
|
+
const request = {
|
|
85
|
+
jsonrpc: '2.0',
|
|
86
|
+
method,
|
|
87
|
+
params,
|
|
88
|
+
id,
|
|
89
|
+
};
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
const timeoutMs = this.options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
92
|
+
const timer = setTimeout(() => {
|
|
93
|
+
this.pending.delete(id);
|
|
94
|
+
reject(new errors_1.NarrativeRpcError(-32000, `Request timeout after ${timeoutMs}ms for method: ${method}`));
|
|
95
|
+
}, timeoutMs);
|
|
96
|
+
this.pending.set(id, {
|
|
97
|
+
resolve: resolve,
|
|
98
|
+
reject,
|
|
99
|
+
timer,
|
|
100
|
+
});
|
|
101
|
+
const json = JSON.stringify(request) + '\n';
|
|
102
|
+
this.process.stdin.write(json);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Gracefully shut down the engine process.
|
|
107
|
+
*
|
|
108
|
+
* Closes stdin (engine exits on EOF), then SIGTERM, then SIGKILL.
|
|
109
|
+
*/
|
|
110
|
+
async shutdown() {
|
|
111
|
+
if (!this.process) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this._ready = false;
|
|
115
|
+
const proc = this.process;
|
|
116
|
+
this.process = null;
|
|
117
|
+
// Close stdin — engine exits on EOF
|
|
118
|
+
proc.stdin?.end();
|
|
119
|
+
return new Promise((resolve) => {
|
|
120
|
+
const forceKillTimer = setTimeout(() => {
|
|
121
|
+
proc.kill('SIGKILL');
|
|
122
|
+
resolve();
|
|
123
|
+
}, 5000);
|
|
124
|
+
const termTimer = setTimeout(() => {
|
|
125
|
+
proc.kill('SIGTERM');
|
|
126
|
+
}, 1000);
|
|
127
|
+
proc.on('exit', () => {
|
|
128
|
+
clearTimeout(termTimer);
|
|
129
|
+
clearTimeout(forceKillTimer);
|
|
130
|
+
resolve();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
handleLine(line) {
|
|
135
|
+
const trimmed = line.trim();
|
|
136
|
+
if (!trimmed)
|
|
137
|
+
return;
|
|
138
|
+
let msg;
|
|
139
|
+
try {
|
|
140
|
+
msg = JSON.parse(trimmed);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
this.emit('parse_error', trimmed);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// Notification: no id field
|
|
147
|
+
if (!('id' in msg) || msg.id === undefined) {
|
|
148
|
+
const notification = msg;
|
|
149
|
+
this.emit('notification', notification);
|
|
150
|
+
this.emit(notification.method, notification.params);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
// Response: has id field
|
|
154
|
+
const response = msg;
|
|
155
|
+
if (response.id === null)
|
|
156
|
+
return;
|
|
157
|
+
const pending = this.pending.get(response.id);
|
|
158
|
+
if (!pending)
|
|
159
|
+
return;
|
|
160
|
+
this.pending.delete(response.id);
|
|
161
|
+
clearTimeout(pending.timer);
|
|
162
|
+
if (response.error) {
|
|
163
|
+
pending.reject(new errors_1.NarrativeRpcError(response.error.code, response.error.message, response.error.data));
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
pending.resolve(response.result);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
handleProcessExit(code) {
|
|
170
|
+
this._ready = false;
|
|
171
|
+
// Reject all pending requests
|
|
172
|
+
for (const [id, pending] of this.pending) {
|
|
173
|
+
clearTimeout(pending.timer);
|
|
174
|
+
pending.reject(new errors_1.NarrativeRpcError(-32000, `Engine process exited with code ${code}`));
|
|
175
|
+
}
|
|
176
|
+
this.pending.clear();
|
|
177
|
+
if (this.readline) {
|
|
178
|
+
this.readline.close();
|
|
179
|
+
this.readline = null;
|
|
180
|
+
}
|
|
181
|
+
this.emit('exit', code);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.NarrativeTransport = NarrativeTransport;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { NarrativeContext } from './common';
|
|
2
|
+
export interface ExecuteCommandParams {
|
|
3
|
+
command: string;
|
|
4
|
+
cwd?: string;
|
|
5
|
+
env?: Record<string, string>;
|
|
6
|
+
cols?: number;
|
|
7
|
+
rows?: number;
|
|
8
|
+
is_mutating?: boolean;
|
|
9
|
+
context: NarrativeContext;
|
|
10
|
+
}
|
|
11
|
+
export interface ExecuteCommandResult {
|
|
12
|
+
session_id: string;
|
|
13
|
+
pid: number;
|
|
14
|
+
execution_id: string;
|
|
15
|
+
snapshot_before: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PtyWriteParams {
|
|
18
|
+
session_id: string;
|
|
19
|
+
data: string;
|
|
20
|
+
}
|
|
21
|
+
export interface PtyWriteResult {
|
|
22
|
+
success: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface PtyResizeParams {
|
|
25
|
+
session_id: string;
|
|
26
|
+
cols: number;
|
|
27
|
+
rows: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PtyResizeResult {
|
|
30
|
+
success: boolean;
|
|
31
|
+
cols: number;
|
|
32
|
+
rows: number;
|
|
33
|
+
}
|
|
34
|
+
export interface PtyCloseParams {
|
|
35
|
+
session_id: string;
|
|
36
|
+
}
|
|
37
|
+
export interface PtyCloseResult {
|
|
38
|
+
success: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface PtySignalParams {
|
|
41
|
+
session_id: string;
|
|
42
|
+
signal: string;
|
|
43
|
+
}
|
|
44
|
+
export interface PtySignalResult {
|
|
45
|
+
success: boolean;
|
|
46
|
+
signal: string;
|
|
47
|
+
}
|
|
48
|
+
export interface SessionInfo {
|
|
49
|
+
id: string;
|
|
50
|
+
pid: number;
|
|
51
|
+
shell: string;
|
|
52
|
+
cwd: string;
|
|
53
|
+
cols: number;
|
|
54
|
+
rows: number;
|
|
55
|
+
}
|
|
56
|
+
export interface ListSessionsResult {
|
|
57
|
+
sessions: SessionInfo[];
|
|
58
|
+
count: number;
|
|
59
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execution context required for all mutating operations.
|
|
3
|
+
* Links the operation to a specific agent run in the narrative hierarchy.
|
|
4
|
+
*/
|
|
5
|
+
export interface NarrativeContext {
|
|
6
|
+
/** The agent run ID (resolves the full hierarchy via DB). */
|
|
7
|
+
agent_run_id: string;
|
|
8
|
+
/** Optional metadata to attach to this operation. */
|
|
9
|
+
metadata?: unknown;
|
|
10
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { NarrativeContext } from './common';
|
|
2
|
+
export interface FsReadParams {
|
|
3
|
+
path: string;
|
|
4
|
+
encoding?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface FsReadResult {
|
|
7
|
+
content: string;
|
|
8
|
+
encoding: string;
|
|
9
|
+
}
|
|
10
|
+
export interface FsWriteParams {
|
|
11
|
+
path: string;
|
|
12
|
+
content: string;
|
|
13
|
+
encoding?: string;
|
|
14
|
+
context: NarrativeContext;
|
|
15
|
+
}
|
|
16
|
+
export interface FsWriteResult {
|
|
17
|
+
success: boolean;
|
|
18
|
+
path: string;
|
|
19
|
+
change_id: string;
|
|
20
|
+
snapshot_id: string;
|
|
21
|
+
bytes_written: number;
|
|
22
|
+
}
|
|
23
|
+
export interface FsDeleteParams {
|
|
24
|
+
path: string;
|
|
25
|
+
context: NarrativeContext;
|
|
26
|
+
}
|
|
27
|
+
export interface FsDeleteResult {
|
|
28
|
+
success: boolean;
|
|
29
|
+
path: string;
|
|
30
|
+
change_id: string;
|
|
31
|
+
snapshot_id: string;
|
|
32
|
+
}
|
|
33
|
+
export interface FsApplyPatchParams {
|
|
34
|
+
path: string;
|
|
35
|
+
patch: string;
|
|
36
|
+
context: NarrativeContext;
|
|
37
|
+
}
|
|
38
|
+
export interface FsApplyPatchResult {
|
|
39
|
+
success: boolean;
|
|
40
|
+
path: string;
|
|
41
|
+
change_id: string;
|
|
42
|
+
snapshot_id: string;
|
|
43
|
+
}
|
|
44
|
+
export interface FsExistsParams {
|
|
45
|
+
path: string;
|
|
46
|
+
}
|
|
47
|
+
export interface FsExistsResult {
|
|
48
|
+
exists: boolean;
|
|
49
|
+
is_directory: boolean;
|
|
50
|
+
}
|
|
51
|
+
export interface FsListDirParams {
|
|
52
|
+
path: string;
|
|
53
|
+
}
|
|
54
|
+
export interface DirEntry {
|
|
55
|
+
name: string;
|
|
56
|
+
path: string;
|
|
57
|
+
is_directory: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface FsListDirResult {
|
|
60
|
+
entries: DirEntry[];
|
|
61
|
+
}
|
|
62
|
+
export interface FsMkdirParams {
|
|
63
|
+
path: string;
|
|
64
|
+
context: NarrativeContext;
|
|
65
|
+
}
|
|
66
|
+
export interface FsMkdirResult {
|
|
67
|
+
success: boolean;
|
|
68
|
+
path: string;
|
|
69
|
+
}
|
package/dist/types/fs.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './jsonrpc';
|
|
2
|
+
export * from './common';
|
|
3
|
+
export * from './fs';
|
|
4
|
+
export * from './command';
|
|
5
|
+
export * from './queue';
|
|
6
|
+
export * from './timeline';
|
|
7
|
+
export * from './narrative';
|
|
8
|
+
export * from './snapshot';
|
|
9
|
+
export * from './trace';
|
|
10
|
+
export * from './notifications';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./jsonrpc"), exports);
|
|
18
|
+
__exportStar(require("./common"), exports);
|
|
19
|
+
__exportStar(require("./fs"), exports);
|
|
20
|
+
__exportStar(require("./command"), exports);
|
|
21
|
+
__exportStar(require("./queue"), exports);
|
|
22
|
+
__exportStar(require("./timeline"), exports);
|
|
23
|
+
__exportStar(require("./narrative"), exports);
|
|
24
|
+
__exportStar(require("./snapshot"), exports);
|
|
25
|
+
__exportStar(require("./trace"), exports);
|
|
26
|
+
__exportStar(require("./notifications"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface JsonRpcRequest {
|
|
2
|
+
jsonrpc: '2.0';
|
|
3
|
+
method: string;
|
|
4
|
+
params: unknown;
|
|
5
|
+
id: number;
|
|
6
|
+
}
|
|
7
|
+
export interface JsonRpcError {
|
|
8
|
+
code: number;
|
|
9
|
+
message: string;
|
|
10
|
+
data?: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface JsonRpcResponse {
|
|
13
|
+
jsonrpc: '2.0';
|
|
14
|
+
result?: unknown;
|
|
15
|
+
error?: JsonRpcError;
|
|
16
|
+
id: number | null;
|
|
17
|
+
}
|
|
18
|
+
export interface JsonRpcNotification {
|
|
19
|
+
jsonrpc: '2.0';
|
|
20
|
+
method: string;
|
|
21
|
+
params: unknown;
|
|
22
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface CreateObjectiveParams {
|
|
2
|
+
description: string;
|
|
3
|
+
metadata?: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface CreateObjectiveResult {
|
|
6
|
+
objective_id: string;
|
|
7
|
+
id: string;
|
|
8
|
+
description: string;
|
|
9
|
+
status: string;
|
|
10
|
+
created_at: string;
|
|
11
|
+
}
|
|
12
|
+
export interface GetObjectiveParams {
|
|
13
|
+
id: string;
|
|
14
|
+
include_threads?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface ThreadInfo {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
parent_thread_id: string | null;
|
|
20
|
+
status: string;
|
|
21
|
+
}
|
|
22
|
+
export interface GetObjectiveResult {
|
|
23
|
+
id: string;
|
|
24
|
+
description: string;
|
|
25
|
+
status: string;
|
|
26
|
+
created_at: string;
|
|
27
|
+
updated_at: string;
|
|
28
|
+
metadata: unknown;
|
|
29
|
+
threads?: ThreadInfo[];
|
|
30
|
+
}
|
|
31
|
+
export interface CreateThreadParams {
|
|
32
|
+
objective_id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
parent_thread_id?: string;
|
|
35
|
+
metadata?: unknown;
|
|
36
|
+
}
|
|
37
|
+
export interface CreateThreadResult {
|
|
38
|
+
thread_id: string;
|
|
39
|
+
id: string;
|
|
40
|
+
objective_id: string;
|
|
41
|
+
parent_thread_id: string | null;
|
|
42
|
+
name: string;
|
|
43
|
+
status: string;
|
|
44
|
+
created_at: string;
|
|
45
|
+
}
|
|
46
|
+
export interface CreateAgentRunParams {
|
|
47
|
+
thread_id: string;
|
|
48
|
+
agent_name: string;
|
|
49
|
+
metadata?: unknown;
|
|
50
|
+
}
|
|
51
|
+
export interface CreateAgentRunResult {
|
|
52
|
+
agent_run_id: string;
|
|
53
|
+
id: string;
|
|
54
|
+
thread_id: string;
|
|
55
|
+
agent_name: string;
|
|
56
|
+
status: string;
|
|
57
|
+
started_at: string;
|
|
58
|
+
}
|
|
59
|
+
export interface CompleteAgentRunParams {
|
|
60
|
+
id: string;
|
|
61
|
+
status: string;
|
|
62
|
+
}
|
|
63
|
+
export interface CompleteAgentRunResult {
|
|
64
|
+
success: boolean;
|
|
65
|
+
id: string;
|
|
66
|
+
status: string;
|
|
67
|
+
}
|