@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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NarrativeTransport } from '../transport';
|
|
2
|
+
import { ExecuteCommandParams, ExecuteCommandResult, PtyWriteParams, PtyWriteResult, PtyResizeParams, PtyResizeResult, PtyCloseParams, PtyCloseResult, PtySignalParams, PtySignalResult, ListSessionsResult } from '../types/command';
|
|
3
|
+
export declare class CommandApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
constructor(transport: NarrativeTransport);
|
|
6
|
+
execute(params: ExecuteCommandParams): Promise<ExecuteCommandResult>;
|
|
7
|
+
ptyWrite(params: PtyWriteParams): Promise<PtyWriteResult>;
|
|
8
|
+
ptyResize(params: PtyResizeParams): Promise<PtyResizeResult>;
|
|
9
|
+
ptyClose(params: PtyCloseParams): Promise<PtyCloseResult>;
|
|
10
|
+
ptySignal(params: PtySignalParams): Promise<PtySignalResult>;
|
|
11
|
+
listSessions(): Promise<ListSessionsResult>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommandApi = void 0;
|
|
4
|
+
class CommandApi {
|
|
5
|
+
constructor(transport) {
|
|
6
|
+
this.transport = transport;
|
|
7
|
+
}
|
|
8
|
+
async execute(params) {
|
|
9
|
+
return this.transport.request('execute_command', params);
|
|
10
|
+
}
|
|
11
|
+
async ptyWrite(params) {
|
|
12
|
+
return this.transport.request('pty_write', params);
|
|
13
|
+
}
|
|
14
|
+
async ptyResize(params) {
|
|
15
|
+
return this.transport.request('pty_resize', params);
|
|
16
|
+
}
|
|
17
|
+
async ptyClose(params) {
|
|
18
|
+
return this.transport.request('pty_close', params);
|
|
19
|
+
}
|
|
20
|
+
async ptySignal(params) {
|
|
21
|
+
return this.transport.request('pty_signal', params);
|
|
22
|
+
}
|
|
23
|
+
async listSessions() {
|
|
24
|
+
return this.transport.request('list_sessions', {});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.CommandApi = CommandApi;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NarrativeTransport } from '../transport';
|
|
2
|
+
import { FsReadParams, FsReadResult, FsWriteParams, FsWriteResult, FsDeleteParams, FsDeleteResult, FsApplyPatchParams, FsApplyPatchResult, FsExistsParams, FsExistsResult, FsListDirParams, FsListDirResult, FsMkdirParams, FsMkdirResult } from '../types/fs';
|
|
3
|
+
export declare class FsApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
constructor(transport: NarrativeTransport);
|
|
6
|
+
read(params: FsReadParams): Promise<FsReadResult>;
|
|
7
|
+
write(params: FsWriteParams): Promise<FsWriteResult>;
|
|
8
|
+
delete(params: FsDeleteParams): Promise<FsDeleteResult>;
|
|
9
|
+
applyPatch(params: FsApplyPatchParams): Promise<FsApplyPatchResult>;
|
|
10
|
+
exists(params: FsExistsParams): Promise<FsExistsResult>;
|
|
11
|
+
listDir(params: FsListDirParams): Promise<FsListDirResult>;
|
|
12
|
+
mkdir(params: FsMkdirParams): Promise<FsMkdirResult>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FsApi = void 0;
|
|
4
|
+
class FsApi {
|
|
5
|
+
constructor(transport) {
|
|
6
|
+
this.transport = transport;
|
|
7
|
+
}
|
|
8
|
+
async read(params) {
|
|
9
|
+
return this.transport.request('fs_read', params);
|
|
10
|
+
}
|
|
11
|
+
async write(params) {
|
|
12
|
+
return this.transport.request('fs_write', params);
|
|
13
|
+
}
|
|
14
|
+
async delete(params) {
|
|
15
|
+
return this.transport.request('fs_delete', params);
|
|
16
|
+
}
|
|
17
|
+
async applyPatch(params) {
|
|
18
|
+
return this.transport.request('fs_apply_patch', params);
|
|
19
|
+
}
|
|
20
|
+
async exists(params) {
|
|
21
|
+
return this.transport.request('fs_exists', params);
|
|
22
|
+
}
|
|
23
|
+
async listDir(params) {
|
|
24
|
+
return this.transport.request('fs_list_dir', params);
|
|
25
|
+
}
|
|
26
|
+
async mkdir(params) {
|
|
27
|
+
return this.transport.request('fs_mkdir', params);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.FsApi = FsApi;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { FsApi } from './fs.api';
|
|
2
|
+
export { CommandApi } from './command.api';
|
|
3
|
+
export { QueueApi } from './queue.api';
|
|
4
|
+
export { TimelineApi } from './timeline.api';
|
|
5
|
+
export { NarrativeApi } from './narrative.api';
|
|
6
|
+
export { SnapshotApi } from './snapshot.api';
|
|
7
|
+
export { TraceApi } from './trace.api';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraceApi = exports.SnapshotApi = exports.NarrativeApi = exports.TimelineApi = exports.QueueApi = exports.CommandApi = exports.FsApi = void 0;
|
|
4
|
+
var fs_api_1 = require("./fs.api");
|
|
5
|
+
Object.defineProperty(exports, "FsApi", { enumerable: true, get: function () { return fs_api_1.FsApi; } });
|
|
6
|
+
var command_api_1 = require("./command.api");
|
|
7
|
+
Object.defineProperty(exports, "CommandApi", { enumerable: true, get: function () { return command_api_1.CommandApi; } });
|
|
8
|
+
var queue_api_1 = require("./queue.api");
|
|
9
|
+
Object.defineProperty(exports, "QueueApi", { enumerable: true, get: function () { return queue_api_1.QueueApi; } });
|
|
10
|
+
var timeline_api_1 = require("./timeline.api");
|
|
11
|
+
Object.defineProperty(exports, "TimelineApi", { enumerable: true, get: function () { return timeline_api_1.TimelineApi; } });
|
|
12
|
+
var narrative_api_1 = require("./narrative.api");
|
|
13
|
+
Object.defineProperty(exports, "NarrativeApi", { enumerable: true, get: function () { return narrative_api_1.NarrativeApi; } });
|
|
14
|
+
var snapshot_api_1 = require("./snapshot.api");
|
|
15
|
+
Object.defineProperty(exports, "SnapshotApi", { enumerable: true, get: function () { return snapshot_api_1.SnapshotApi; } });
|
|
16
|
+
var trace_api_1 = require("./trace.api");
|
|
17
|
+
Object.defineProperty(exports, "TraceApi", { enumerable: true, get: function () { return trace_api_1.TraceApi; } });
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NarrativeTransport } from '../transport';
|
|
2
|
+
import { CreateObjectiveParams, CreateObjectiveResult, GetObjectiveParams, GetObjectiveResult, CreateThreadParams, CreateThreadResult, CreateAgentRunParams, CreateAgentRunResult, CompleteAgentRunParams, CompleteAgentRunResult } from '../types/narrative';
|
|
3
|
+
export declare class NarrativeApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
constructor(transport: NarrativeTransport);
|
|
6
|
+
createObjective(params: CreateObjectiveParams): Promise<CreateObjectiveResult>;
|
|
7
|
+
getObjective(params: GetObjectiveParams): Promise<GetObjectiveResult>;
|
|
8
|
+
createThread(params: CreateThreadParams): Promise<CreateThreadResult>;
|
|
9
|
+
createAgentRun(params: CreateAgentRunParams): Promise<CreateAgentRunResult>;
|
|
10
|
+
completeAgentRun(params: CompleteAgentRunParams): Promise<CompleteAgentRunResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NarrativeApi = void 0;
|
|
4
|
+
class NarrativeApi {
|
|
5
|
+
constructor(transport) {
|
|
6
|
+
this.transport = transport;
|
|
7
|
+
}
|
|
8
|
+
async createObjective(params) {
|
|
9
|
+
return this.transport.request('create_objective', params);
|
|
10
|
+
}
|
|
11
|
+
async getObjective(params) {
|
|
12
|
+
return this.transport.request('get_objective', params);
|
|
13
|
+
}
|
|
14
|
+
async createThread(params) {
|
|
15
|
+
return this.transport.request('create_thread', params);
|
|
16
|
+
}
|
|
17
|
+
async createAgentRun(params) {
|
|
18
|
+
return this.transport.request('create_agent_run', params);
|
|
19
|
+
}
|
|
20
|
+
async completeAgentRun(params) {
|
|
21
|
+
return this.transport.request('complete_agent_run', params);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.NarrativeApi = NarrativeApi;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NarrativeTransport } from '../transport';
|
|
2
|
+
import { QueueStatusResult, ForceReleaseParams, ForceReleaseResult, CancelTaskParams, CancelTaskResult } from '../types/queue';
|
|
3
|
+
export declare class QueueApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
constructor(transport: NarrativeTransport);
|
|
6
|
+
getStatus(): Promise<QueueStatusResult>;
|
|
7
|
+
forceRelease(params?: ForceReleaseParams): Promise<ForceReleaseResult>;
|
|
8
|
+
cancelTask(params: CancelTaskParams): Promise<CancelTaskResult>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueueApi = void 0;
|
|
4
|
+
class QueueApi {
|
|
5
|
+
constructor(transport) {
|
|
6
|
+
this.transport = transport;
|
|
7
|
+
}
|
|
8
|
+
async getStatus() {
|
|
9
|
+
return this.transport.request('get_queue_status', {});
|
|
10
|
+
}
|
|
11
|
+
async forceRelease(params = {}) {
|
|
12
|
+
return this.transport.request('force_release_window', params);
|
|
13
|
+
}
|
|
14
|
+
async cancelTask(params) {
|
|
15
|
+
return this.transport.request('cancel_task', params);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.QueueApi = QueueApi;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { NarrativeTransport } from '../transport';
|
|
2
|
+
import { CreateSnapshotParams, CreateSnapshotResult, SnapshotIdParam, CreateArchiveResult, ImportArchiveParams, ImportArchiveResult, ExportBundleParams, ExportBundleResult, AddBundleParams, AddBundleResult, BrowseSnapshotParams, BrowseResult, MergeSnapshotParams, MergeSnapshotResult, AddCommitParams, AddCommitResult, CheckRecoveryParams, RecoveryCheck, CheckoutSnapshotParams, CheckoutResult, DeleteResult, PruneSnapshotsParams, PruneResult } from '../types/snapshot';
|
|
3
|
+
export declare class SnapshotApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
constructor(transport: NarrativeTransport);
|
|
6
|
+
createSnapshot(params: CreateSnapshotParams): Promise<CreateSnapshotResult>;
|
|
7
|
+
createSnapshotArchive(params: SnapshotIdParam): Promise<CreateArchiveResult>;
|
|
8
|
+
importSnapshotArchive(params: ImportArchiveParams): Promise<ImportArchiveResult>;
|
|
9
|
+
exportSnapshotBundle(params: ExportBundleParams): Promise<ExportBundleResult>;
|
|
10
|
+
addSnapshotBundle(params: AddBundleParams): Promise<AddBundleResult>;
|
|
11
|
+
browseSnapshot(params: BrowseSnapshotParams): Promise<BrowseResult>;
|
|
12
|
+
mergeSnapshot(params: MergeSnapshotParams): Promise<MergeSnapshotResult>;
|
|
13
|
+
addCommit(params: AddCommitParams): Promise<AddCommitResult>;
|
|
14
|
+
checkSnapshotRecovery(params: CheckRecoveryParams): Promise<RecoveryCheck>;
|
|
15
|
+
checkoutSnapshot(params: CheckoutSnapshotParams): Promise<CheckoutResult>;
|
|
16
|
+
deleteSnapshot(params: SnapshotIdParam): Promise<DeleteResult>;
|
|
17
|
+
pruneSnapshots(params?: PruneSnapshotsParams): Promise<PruneResult>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SnapshotApi = void 0;
|
|
4
|
+
class SnapshotApi {
|
|
5
|
+
constructor(transport) {
|
|
6
|
+
this.transport = transport;
|
|
7
|
+
}
|
|
8
|
+
async createSnapshot(params) {
|
|
9
|
+
return this.transport.request('createSnapshot', params);
|
|
10
|
+
}
|
|
11
|
+
async createSnapshotArchive(params) {
|
|
12
|
+
return this.transport.request('createSnapshotArchive', params);
|
|
13
|
+
}
|
|
14
|
+
async importSnapshotArchive(params) {
|
|
15
|
+
return this.transport.request('importSnapshotArchive', params);
|
|
16
|
+
}
|
|
17
|
+
async exportSnapshotBundle(params) {
|
|
18
|
+
return this.transport.request('exportSnapshotBundle', params);
|
|
19
|
+
}
|
|
20
|
+
async addSnapshotBundle(params) {
|
|
21
|
+
return this.transport.request('addSnapshotBundle', params);
|
|
22
|
+
}
|
|
23
|
+
async browseSnapshot(params) {
|
|
24
|
+
return this.transport.request('browseSnapshot', params);
|
|
25
|
+
}
|
|
26
|
+
async mergeSnapshot(params) {
|
|
27
|
+
return this.transport.request('mergeSnapshot', params);
|
|
28
|
+
}
|
|
29
|
+
async addCommit(params) {
|
|
30
|
+
return this.transport.request('addCommit', params);
|
|
31
|
+
}
|
|
32
|
+
async checkSnapshotRecovery(params) {
|
|
33
|
+
return this.transport.request('checkSnapshotRecovery', params);
|
|
34
|
+
}
|
|
35
|
+
async checkoutSnapshot(params) {
|
|
36
|
+
return this.transport.request('checkoutSnapshot', params);
|
|
37
|
+
}
|
|
38
|
+
async deleteSnapshot(params) {
|
|
39
|
+
return this.transport.request('deleteSnapshot', params);
|
|
40
|
+
}
|
|
41
|
+
async pruneSnapshots(params = {}) {
|
|
42
|
+
return this.transport.request('pruneSnapshots', params);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.SnapshotApi = SnapshotApi;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NarrativeTransport } from '../transport';
|
|
2
|
+
import { GetTimelineParams, GetTimelineResult, RestoreSnapshotParams, RestoreSnapshotResult, GetSnapshotParams, GetSnapshotResult, DiffSnapshotsParams, SnapshotDiff, GetFileAtSnapshotParams, GetFileAtSnapshotResult } from '../types/timeline';
|
|
3
|
+
export declare class TimelineApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
constructor(transport: NarrativeTransport);
|
|
6
|
+
getTimeline(params?: GetTimelineParams): Promise<GetTimelineResult>;
|
|
7
|
+
restoreSnapshot(params: RestoreSnapshotParams): Promise<RestoreSnapshotResult>;
|
|
8
|
+
getSnapshot(params: GetSnapshotParams): Promise<GetSnapshotResult>;
|
|
9
|
+
diffSnapshots(params: DiffSnapshotsParams): Promise<SnapshotDiff>;
|
|
10
|
+
getFileAtSnapshot(params: GetFileAtSnapshotParams): Promise<GetFileAtSnapshotResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimelineApi = void 0;
|
|
4
|
+
class TimelineApi {
|
|
5
|
+
constructor(transport) {
|
|
6
|
+
this.transport = transport;
|
|
7
|
+
}
|
|
8
|
+
async getTimeline(params = {}) {
|
|
9
|
+
return this.transport.request('get_timeline', params);
|
|
10
|
+
}
|
|
11
|
+
async restoreSnapshot(params) {
|
|
12
|
+
return this.transport.request('restore_snapshot', params);
|
|
13
|
+
}
|
|
14
|
+
async getSnapshot(params) {
|
|
15
|
+
return this.transport.request('get_snapshot', params);
|
|
16
|
+
}
|
|
17
|
+
async diffSnapshots(params) {
|
|
18
|
+
return this.transport.request('diff_snapshots', params);
|
|
19
|
+
}
|
|
20
|
+
async getFileAtSnapshot(params) {
|
|
21
|
+
return this.transport.request('get_file_at_snapshot', params);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.TimelineApi = TimelineApi;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NarrativeTransport } from '../transport';
|
|
2
|
+
import { IngestTraceParams, IngestTraceResult, GetExecutionTraceParams, ExecutionTraceResult, GetThreadTraceParams, TraceSummaryResult, GetFileTraceParams, FileChangeResult, GetRecentTracesParams, IngestionSummaryResult } from '../types/trace';
|
|
3
|
+
export declare class TraceApi {
|
|
4
|
+
private readonly transport;
|
|
5
|
+
constructor(transport: NarrativeTransport);
|
|
6
|
+
ingestTrace(params: IngestTraceParams): Promise<IngestTraceResult>;
|
|
7
|
+
getExecutionTrace(params: GetExecutionTraceParams): Promise<ExecutionTraceResult>;
|
|
8
|
+
getThreadTrace(params: GetThreadTraceParams): Promise<TraceSummaryResult[]>;
|
|
9
|
+
getFileTrace(params: GetFileTraceParams): Promise<FileChangeResult[]>;
|
|
10
|
+
getRecentTraces(params?: GetRecentTracesParams): Promise<TraceSummaryResult[]>;
|
|
11
|
+
getPendingIngestions(): Promise<IngestionSummaryResult[]>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraceApi = void 0;
|
|
4
|
+
class TraceApi {
|
|
5
|
+
constructor(transport) {
|
|
6
|
+
this.transport = transport;
|
|
7
|
+
}
|
|
8
|
+
async ingestTrace(params) {
|
|
9
|
+
return this.transport.request('ingest_remote_execution_trace', params);
|
|
10
|
+
}
|
|
11
|
+
async getExecutionTrace(params) {
|
|
12
|
+
return this.transport.request('get_execution_trace', params);
|
|
13
|
+
}
|
|
14
|
+
async getThreadTrace(params) {
|
|
15
|
+
return this.transport.request('get_thread_trace', params);
|
|
16
|
+
}
|
|
17
|
+
async getFileTrace(params) {
|
|
18
|
+
return this.transport.request('get_file_trace', params);
|
|
19
|
+
}
|
|
20
|
+
async getRecentTraces(params = {}) {
|
|
21
|
+
return this.transport.request('get_recent_traces', params);
|
|
22
|
+
}
|
|
23
|
+
async getPendingIngestions() {
|
|
24
|
+
return this.transport.request('get_pending_ingestions', {});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TraceApi = TraceApi;
|
package/dist/binary.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the path to the codebolt-narrative binary.
|
|
3
|
+
*
|
|
4
|
+
* Resolution order:
|
|
5
|
+
* 1. Explicit path passed as argument
|
|
6
|
+
* 2. CODEBOLT_NARRATIVE_BINARY env var
|
|
7
|
+
* 3. Platform-specific npm package (@codebolt/narrative-{os}-{arch})
|
|
8
|
+
* 4. PATH lookup via `which`
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveBinary(explicitPath?: string): string;
|
package/dist/binary.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveBinary = resolveBinary;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const BINARY_NAME = process.platform === 'win32' ? 'codebolt-narrative.exe' : 'codebolt-narrative';
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the path to the codebolt-narrative binary.
|
|
10
|
+
*
|
|
11
|
+
* Resolution order:
|
|
12
|
+
* 1. Explicit path passed as argument
|
|
13
|
+
* 2. CODEBOLT_NARRATIVE_BINARY env var
|
|
14
|
+
* 3. Platform-specific npm package (@codebolt/narrative-{os}-{arch})
|
|
15
|
+
* 4. PATH lookup via `which`
|
|
16
|
+
*/
|
|
17
|
+
function resolveBinary(explicitPath) {
|
|
18
|
+
// 1. Explicit path
|
|
19
|
+
if (explicitPath) {
|
|
20
|
+
if (!(0, fs_1.existsSync)(explicitPath)) {
|
|
21
|
+
throw new Error(`Binary not found at explicit path: ${explicitPath}`);
|
|
22
|
+
}
|
|
23
|
+
return explicitPath;
|
|
24
|
+
}
|
|
25
|
+
// 2. Environment variable
|
|
26
|
+
const envPath = process.env.CODEBOLT_NARRATIVE_BINARY;
|
|
27
|
+
if (envPath) {
|
|
28
|
+
if (!(0, fs_1.existsSync)(envPath)) {
|
|
29
|
+
throw new Error(`CODEBOLT_NARRATIVE_BINARY points to non-existent path: ${envPath}`);
|
|
30
|
+
}
|
|
31
|
+
return envPath;
|
|
32
|
+
}
|
|
33
|
+
// 3. Platform-specific npm package
|
|
34
|
+
const platformPath = resolvePlatformPackage();
|
|
35
|
+
if (platformPath) {
|
|
36
|
+
return platformPath;
|
|
37
|
+
}
|
|
38
|
+
// 4. PATH lookup
|
|
39
|
+
const pathResult = resolveFromPath();
|
|
40
|
+
if (pathResult) {
|
|
41
|
+
return pathResult;
|
|
42
|
+
}
|
|
43
|
+
throw new Error(`Could not find ${BINARY_NAME} binary. Either:\n` +
|
|
44
|
+
` - Set CODEBOLT_NARRATIVE_BINARY env var to the binary path\n` +
|
|
45
|
+
` - Install a platform-specific @codebolt/narrative-* package\n` +
|
|
46
|
+
` - Ensure ${BINARY_NAME} is on your PATH`);
|
|
47
|
+
}
|
|
48
|
+
function resolvePlatformPackage() {
|
|
49
|
+
const platform = process.platform;
|
|
50
|
+
const arch = process.arch;
|
|
51
|
+
const packageName = `@codebolt/narrative-${platform}-${arch}`;
|
|
52
|
+
try {
|
|
53
|
+
const pkgJson = require.resolve(`${packageName}/package.json`);
|
|
54
|
+
const pkgDir = (0, path_1.dirname)(pkgJson);
|
|
55
|
+
let binaryPath = (0, path_1.join)(pkgDir, 'bin', BINARY_NAME);
|
|
56
|
+
// In Electron production builds the app is packed into an ASAR archive.
|
|
57
|
+
// Binaries inside an ASAR can't be executed directly, so we rewrite the
|
|
58
|
+
// path to the unpacked copy that electron-builder extracts automatically
|
|
59
|
+
// when the file matches an `asarUnpack` glob.
|
|
60
|
+
if (binaryPath.includes('app.asar')) {
|
|
61
|
+
binaryPath = binaryPath.replace('app.asar', 'app.asar.unpacked');
|
|
62
|
+
}
|
|
63
|
+
if ((0, fs_1.existsSync)(binaryPath)) {
|
|
64
|
+
return binaryPath;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Package not installed
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function resolveFromPath() {
|
|
73
|
+
try {
|
|
74
|
+
const cmd = process.platform === 'win32' ? 'where' : 'which';
|
|
75
|
+
const result = (0, child_process_1.execFileSync)(cmd, [BINARY_NAME], {
|
|
76
|
+
encoding: 'utf8',
|
|
77
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
78
|
+
});
|
|
79
|
+
const resolved = result.trim().split('\n')[0];
|
|
80
|
+
if (resolved && (0, fs_1.existsSync)(resolved)) {
|
|
81
|
+
return resolved;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// Not found on PATH
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { NarrativeTransport } from './transport';
|
|
2
|
+
import { FsApi } from './api/fs.api';
|
|
3
|
+
import { CommandApi } from './api/command.api';
|
|
4
|
+
import { QueueApi } from './api/queue.api';
|
|
5
|
+
import { TimelineApi } from './api/timeline.api';
|
|
6
|
+
import { NarrativeApi } from './api/narrative.api';
|
|
7
|
+
import { SnapshotApi } from './api/snapshot.api';
|
|
8
|
+
import { TraceApi } from './api/trace.api';
|
|
9
|
+
import { NarrativeNotificationMap } from './types/notifications';
|
|
10
|
+
export interface NarrativeClientOptions {
|
|
11
|
+
/** Unique environment identifier (required). */
|
|
12
|
+
environmentId: string;
|
|
13
|
+
/** Workspace root directory. */
|
|
14
|
+
workspace?: string;
|
|
15
|
+
/** Data directory for storage. */
|
|
16
|
+
dataDir?: string;
|
|
17
|
+
/** Max mutation slot hold time in ms. */
|
|
18
|
+
maxSlotMs?: number;
|
|
19
|
+
/** Log level for the engine. */
|
|
20
|
+
logLevel?: string;
|
|
21
|
+
/** Explicit binary path (overrides env var and PATH lookup). */
|
|
22
|
+
binaryPath?: string;
|
|
23
|
+
/** Request timeout in ms. */
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
/** Run as remote environment (disables FK constraints for imported snapshots). */
|
|
26
|
+
remote?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* High-level client for the Codebolt Narrative Engine.
|
|
30
|
+
*
|
|
31
|
+
* Provides typed domain APIs via lazy-init getters and typed notification events.
|
|
32
|
+
*
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const client = new NarrativeClient({
|
|
35
|
+
* environmentId: 'env-001',
|
|
36
|
+
* workspace: '/path/to/project',
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* await client.start();
|
|
40
|
+
*
|
|
41
|
+
* const { content } = await client.fs.read({ path: 'src/main.ts' });
|
|
42
|
+
* await client.snapshot.createSnapshot({ thread_id: 'thread-1', description: 'checkpoint' });
|
|
43
|
+
*
|
|
44
|
+
* client.on('execution.pty_data', (event) => process.stdout.write(event.data));
|
|
45
|
+
*
|
|
46
|
+
* await client.shutdown();
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare class NarrativeClient {
|
|
50
|
+
private readonly transport;
|
|
51
|
+
private readonly options;
|
|
52
|
+
private _fs?;
|
|
53
|
+
private _command?;
|
|
54
|
+
private _queue?;
|
|
55
|
+
private _timeline?;
|
|
56
|
+
private _narrative?;
|
|
57
|
+
private _snapshot?;
|
|
58
|
+
private _trace?;
|
|
59
|
+
constructor(options: NarrativeClientOptions);
|
|
60
|
+
start(): Promise<void>;
|
|
61
|
+
shutdown(): Promise<void>;
|
|
62
|
+
get isReady(): boolean;
|
|
63
|
+
get fs(): FsApi;
|
|
64
|
+
get command(): CommandApi;
|
|
65
|
+
get queue(): QueueApi;
|
|
66
|
+
get timeline(): TimelineApi;
|
|
67
|
+
get narrative(): NarrativeApi;
|
|
68
|
+
get snapshot(): SnapshotApi;
|
|
69
|
+
get trace(): TraceApi;
|
|
70
|
+
on<K extends keyof NarrativeNotificationMap>(event: K, listener: (data: NarrativeNotificationMap[K]) => void): this;
|
|
71
|
+
off<K extends keyof NarrativeNotificationMap>(event: K, listener: (data: NarrativeNotificationMap[K]) => void): this;
|
|
72
|
+
getTransport(): NarrativeTransport;
|
|
73
|
+
private buildArgs;
|
|
74
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NarrativeClient = void 0;
|
|
4
|
+
const transport_1 = require("./transport");
|
|
5
|
+
const binary_1 = require("./binary");
|
|
6
|
+
const fs_api_1 = require("./api/fs.api");
|
|
7
|
+
const command_api_1 = require("./api/command.api");
|
|
8
|
+
const queue_api_1 = require("./api/queue.api");
|
|
9
|
+
const timeline_api_1 = require("./api/timeline.api");
|
|
10
|
+
const narrative_api_1 = require("./api/narrative.api");
|
|
11
|
+
const snapshot_api_1 = require("./api/snapshot.api");
|
|
12
|
+
const trace_api_1 = require("./api/trace.api");
|
|
13
|
+
/**
|
|
14
|
+
* High-level client for the Codebolt Narrative Engine.
|
|
15
|
+
*
|
|
16
|
+
* Provides typed domain APIs via lazy-init getters and typed notification events.
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const client = new NarrativeClient({
|
|
20
|
+
* environmentId: 'env-001',
|
|
21
|
+
* workspace: '/path/to/project',
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* await client.start();
|
|
25
|
+
*
|
|
26
|
+
* const { content } = await client.fs.read({ path: 'src/main.ts' });
|
|
27
|
+
* await client.snapshot.createSnapshot({ thread_id: 'thread-1', description: 'checkpoint' });
|
|
28
|
+
*
|
|
29
|
+
* client.on('execution.pty_data', (event) => process.stdout.write(event.data));
|
|
30
|
+
*
|
|
31
|
+
* await client.shutdown();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class NarrativeClient {
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.options = options;
|
|
37
|
+
const binaryPath = (0, binary_1.resolveBinary)(options.binaryPath);
|
|
38
|
+
const args = this.buildArgs();
|
|
39
|
+
this.transport = new transport_1.NarrativeTransport({
|
|
40
|
+
binaryPath,
|
|
41
|
+
args,
|
|
42
|
+
timeoutMs: options.timeoutMs,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// --- Lifecycle ---
|
|
46
|
+
async start() {
|
|
47
|
+
await this.transport.start();
|
|
48
|
+
}
|
|
49
|
+
async shutdown() {
|
|
50
|
+
await this.transport.shutdown();
|
|
51
|
+
}
|
|
52
|
+
get isReady() {
|
|
53
|
+
return this.transport.isReady;
|
|
54
|
+
}
|
|
55
|
+
// --- Domain APIs (lazy-init getters) ---
|
|
56
|
+
get fs() {
|
|
57
|
+
if (!this._fs)
|
|
58
|
+
this._fs = new fs_api_1.FsApi(this.transport);
|
|
59
|
+
return this._fs;
|
|
60
|
+
}
|
|
61
|
+
get command() {
|
|
62
|
+
if (!this._command)
|
|
63
|
+
this._command = new command_api_1.CommandApi(this.transport);
|
|
64
|
+
return this._command;
|
|
65
|
+
}
|
|
66
|
+
get queue() {
|
|
67
|
+
if (!this._queue)
|
|
68
|
+
this._queue = new queue_api_1.QueueApi(this.transport);
|
|
69
|
+
return this._queue;
|
|
70
|
+
}
|
|
71
|
+
get timeline() {
|
|
72
|
+
if (!this._timeline)
|
|
73
|
+
this._timeline = new timeline_api_1.TimelineApi(this.transport);
|
|
74
|
+
return this._timeline;
|
|
75
|
+
}
|
|
76
|
+
get narrative() {
|
|
77
|
+
if (!this._narrative)
|
|
78
|
+
this._narrative = new narrative_api_1.NarrativeApi(this.transport);
|
|
79
|
+
return this._narrative;
|
|
80
|
+
}
|
|
81
|
+
get snapshot() {
|
|
82
|
+
if (!this._snapshot)
|
|
83
|
+
this._snapshot = new snapshot_api_1.SnapshotApi(this.transport);
|
|
84
|
+
return this._snapshot;
|
|
85
|
+
}
|
|
86
|
+
get trace() {
|
|
87
|
+
if (!this._trace)
|
|
88
|
+
this._trace = new trace_api_1.TraceApi(this.transport);
|
|
89
|
+
return this._trace;
|
|
90
|
+
}
|
|
91
|
+
// --- Typed notification events ---
|
|
92
|
+
on(event, listener) {
|
|
93
|
+
this.transport.on(event, listener);
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
off(event, listener) {
|
|
97
|
+
this.transport.off(event, listener);
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
// --- Escape hatch ---
|
|
101
|
+
getTransport() {
|
|
102
|
+
return this.transport;
|
|
103
|
+
}
|
|
104
|
+
// --- Internal ---
|
|
105
|
+
buildArgs() {
|
|
106
|
+
const args = [
|
|
107
|
+
'--environment-id', this.options.environmentId,
|
|
108
|
+
];
|
|
109
|
+
if (this.options.workspace) {
|
|
110
|
+
args.push('--workspace', this.options.workspace);
|
|
111
|
+
}
|
|
112
|
+
if (this.options.dataDir) {
|
|
113
|
+
args.push('--data-dir', this.options.dataDir);
|
|
114
|
+
}
|
|
115
|
+
if (this.options.maxSlotMs !== undefined) {
|
|
116
|
+
args.push('--max-slot-ms', String(this.options.maxSlotMs));
|
|
117
|
+
}
|
|
118
|
+
if (this.options.logLevel) {
|
|
119
|
+
args.push('--log-level', this.options.logLevel);
|
|
120
|
+
}
|
|
121
|
+
if (this.options.remote) {
|
|
122
|
+
args.push('--remote');
|
|
123
|
+
}
|
|
124
|
+
return args;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.NarrativeClient = NarrativeClient;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes mapped from Rust NarrativeError::to_rpc_code().
|
|
3
|
+
*/
|
|
4
|
+
export declare const PARSE_ERROR = -32700;
|
|
5
|
+
export declare const INVALID_REQUEST = -32600;
|
|
6
|
+
export declare const METHOD_NOT_FOUND = -32601;
|
|
7
|
+
export declare const IO_ERROR = -32000;
|
|
8
|
+
export declare const GIT_ERROR = -32001;
|
|
9
|
+
export declare const SQLITE_ERROR = -32002;
|
|
10
|
+
export declare const SLOT_UNAVAILABLE = -32010;
|
|
11
|
+
export declare const SLOT_TIMEOUT = -32011;
|
|
12
|
+
export declare const PREEMPTION = -32012;
|
|
13
|
+
export declare const INVALID_CONTEXT = -32020;
|
|
14
|
+
export declare const SNAPSHOT_NOT_FOUND = -32030;
|
|
15
|
+
export declare const PTY_ERROR = -32040;
|
|
16
|
+
export declare const SESSION_NOT_FOUND = -32041;
|
|
17
|
+
export declare const EXECUTION_ERROR = -32042;
|
|
18
|
+
export declare const QUEUE_ERROR = -32050;
|
|
19
|
+
export declare const FILE_NOT_FOUND = -32060;
|
|
20
|
+
export declare const MERGE_CONFLICT = -32070;
|
|
21
|
+
export declare const INVALID_OPERATION = -32600;
|
|
22
|
+
export declare const CONFIG_ERROR = -32603;
|
|
23
|
+
export declare class NarrativeRpcError extends Error {
|
|
24
|
+
readonly code: number;
|
|
25
|
+
readonly data?: unknown;
|
|
26
|
+
constructor(code: number, message: string, data?: unknown);
|
|
27
|
+
}
|
|
28
|
+
export declare function isSlotUnavailable(err: unknown): err is NarrativeRpcError;
|
|
29
|
+
export declare function isSlotTimeout(err: unknown): err is NarrativeRpcError;
|
|
30
|
+
export declare function isSnapshotNotFound(err: unknown): err is NarrativeRpcError;
|
|
31
|
+
export declare function isFileNotFound(err: unknown): err is NarrativeRpcError;
|
|
32
|
+
export declare function isSessionNotFound(err: unknown): err is NarrativeRpcError;
|
|
33
|
+
export declare function isMergeConflict(err: unknown): err is NarrativeRpcError;
|
|
34
|
+
export declare function isInvalidContext(err: unknown): err is NarrativeRpcError;
|
|
35
|
+
export declare function isMethodNotFound(err: unknown): err is NarrativeRpcError;
|