@celljs/ta-host 0.0.0-stage → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -2
- package/cell.schema.json +33 -0
- package/cell.yml +14 -0
- package/esm/node/client-channel.d.ts +31 -0
- package/esm/node/client-channel.js +84 -0
- package/esm/node/client-channel.js.map +1 -0
- package/esm/node/event-log.d.ts +28 -0
- package/esm/node/event-log.js +48 -0
- package/esm/node/event-log.js.map +1 -0
- package/esm/node/host-protocol.d.ts +27 -0
- package/esm/node/host-protocol.js +4 -0
- package/esm/node/host-protocol.js.map +1 -0
- package/esm/node/index.d.ts +13 -0
- package/esm/node/index.js +14 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/local-exec-environment-factory.d.ts +4 -0
- package/esm/node/local-exec-environment-factory.js +18 -0
- package/esm/node/local-exec-environment-factory.js.map +1 -0
- package/esm/node/module.d.ts +3 -0
- package/esm/node/module.js +4 -0
- package/esm/node/module.js.map +1 -0
- package/esm/node/receipt-book.d.ts +12 -0
- package/esm/node/receipt-book.js +38 -0
- package/esm/node/receipt-book.js.map +1 -0
- package/esm/node/remote-ui-context.d.ts +63 -0
- package/esm/node/remote-ui-context.js +130 -0
- package/esm/node/remote-ui-context.js.map +1 -0
- package/esm/node/ta-access.d.ts +30 -0
- package/esm/node/ta-access.js +107 -0
- package/esm/node/ta-access.js.map +1 -0
- package/esm/node/ta-errors.d.ts +11 -0
- package/esm/node/ta-errors.js +44 -0
- package/esm/node/ta-errors.js.map +1 -0
- package/esm/node/ta-event-util.d.ts +11 -0
- package/esm/node/ta-event-util.js +20 -0
- package/esm/node/ta-event-util.js.map +1 -0
- package/esm/node/ta-server-impl.d.ts +50 -0
- package/esm/node/ta-server-impl.js +226 -0
- package/esm/node/ta-server-impl.js.map +1 -0
- package/esm/node/ta-session-factory.d.ts +32 -0
- package/esm/node/ta-session-factory.js +151 -0
- package/esm/node/ta-session-factory.js.map +1 -0
- package/esm/node/ta-session-registry.d.ts +20 -0
- package/esm/node/ta-session-registry.js +85 -0
- package/esm/node/ta-session-registry.js.map +1 -0
- package/esm/node/ta-session.d.ts +53 -0
- package/esm/node/ta-session.js +157 -0
- package/esm/node/ta-session.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/client-channel.d.ts +32 -0
- package/lib/node/client-channel.d.ts.map +1 -0
- package/lib/node/client-channel.js +88 -0
- package/lib/node/client-channel.js.map +1 -0
- package/lib/node/client-channel.spec.d.ts +2 -0
- package/lib/node/client-channel.spec.d.ts.map +1 -0
- package/lib/node/client-channel.spec.js +106 -0
- package/lib/node/client-channel.spec.js.map +1 -0
- package/lib/node/event-log.d.ts +29 -0
- package/lib/node/event-log.d.ts.map +1 -0
- package/lib/node/event-log.js +52 -0
- package/lib/node/event-log.js.map +1 -0
- package/lib/node/event-log.spec.d.ts +2 -0
- package/lib/node/event-log.spec.d.ts.map +1 -0
- package/lib/node/event-log.spec.js +48 -0
- package/lib/node/event-log.spec.js.map +1 -0
- package/lib/node/host-protocol.d.ts +28 -0
- package/lib/node/host-protocol.d.ts.map +1 -0
- package/lib/node/host-protocol.js +7 -0
- package/lib/node/host-protocol.js.map +1 -0
- package/lib/node/index.d.ts +14 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +30 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/local-exec-environment-factory.d.ts +5 -0
- package/lib/node/local-exec-environment-factory.d.ts.map +1 -0
- package/lib/node/local-exec-environment-factory.js +21 -0
- package/lib/node/local-exec-environment-factory.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/receipt-book.d.ts +13 -0
- package/lib/node/receipt-book.d.ts.map +1 -0
- package/lib/node/receipt-book.js +42 -0
- package/lib/node/receipt-book.js.map +1 -0
- package/lib/node/receipt-book.spec.d.ts +2 -0
- package/lib/node/receipt-book.spec.d.ts.map +1 -0
- package/lib/node/receipt-book.spec.js +39 -0
- package/lib/node/receipt-book.spec.js.map +1 -0
- package/lib/node/remote-ui-context.d.ts +64 -0
- package/lib/node/remote-ui-context.d.ts.map +1 -0
- package/lib/node/remote-ui-context.js +134 -0
- package/lib/node/remote-ui-context.js.map +1 -0
- package/lib/node/remote-ui-context.spec.d.ts +2 -0
- package/lib/node/remote-ui-context.spec.d.ts.map +1 -0
- package/lib/node/remote-ui-context.spec.js +62 -0
- package/lib/node/remote-ui-context.spec.js.map +1 -0
- package/lib/node/ta-access.d.ts +31 -0
- package/lib/node/ta-access.d.ts.map +1 -0
- package/lib/node/ta-access.js +110 -0
- package/lib/node/ta-access.js.map +1 -0
- package/lib/node/ta-access.spec.d.ts +2 -0
- package/lib/node/ta-access.spec.d.ts.map +1 -0
- package/lib/node/ta-access.spec.js +25 -0
- package/lib/node/ta-access.spec.js.map +1 -0
- package/lib/node/ta-errors.d.ts +12 -0
- package/lib/node/ta-errors.d.ts.map +1 -0
- package/lib/node/ta-errors.js +47 -0
- package/lib/node/ta-errors.js.map +1 -0
- package/lib/node/ta-event-util.d.ts +12 -0
- package/lib/node/ta-event-util.d.ts.map +1 -0
- package/lib/node/ta-event-util.js +23 -0
- package/lib/node/ta-event-util.js.map +1 -0
- package/lib/node/ta-event-util.spec.d.ts +2 -0
- package/lib/node/ta-event-util.spec.d.ts.map +1 -0
- package/lib/node/ta-event-util.spec.js +28 -0
- package/lib/node/ta-event-util.spec.js.map +1 -0
- package/lib/node/ta-server-impl.d.ts +51 -0
- package/lib/node/ta-server-impl.d.ts.map +1 -0
- package/lib/node/ta-server-impl.js +229 -0
- package/lib/node/ta-server-impl.js.map +1 -0
- package/lib/node/ta-session-factory.d.ts +33 -0
- package/lib/node/ta-session-factory.d.ts.map +1 -0
- package/lib/node/ta-session-factory.js +154 -0
- package/lib/node/ta-session-factory.js.map +1 -0
- package/lib/node/ta-session-registry.d.ts +21 -0
- package/lib/node/ta-session-registry.d.ts.map +1 -0
- package/lib/node/ta-session-registry.js +86 -0
- package/lib/node/ta-session-registry.js.map +1 -0
- package/lib/node/ta-session.d.ts +54 -0
- package/lib/node/ta-session.d.ts.map +1 -0
- package/lib/node/ta-session.js +161 -0
- package/lib/node/ta-session.js.map +1 -0
- package/package.json +80 -4
- package/src/node/client-channel.spec.ts +117 -0
- package/src/node/client-channel.ts +94 -0
- package/src/node/event-log.spec.ts +52 -0
- package/src/node/event-log.ts +59 -0
- package/src/node/host-protocol.ts +32 -0
- package/src/node/index.ts +13 -0
- package/src/node/local-exec-environment-factory.ts +9 -0
- package/src/node/module.ts +4 -0
- package/src/node/receipt-book.spec.ts +41 -0
- package/src/node/receipt-book.ts +40 -0
- package/src/node/remote-ui-context.spec.ts +68 -0
- package/src/node/remote-ui-context.ts +168 -0
- package/src/node/ta-access.spec.ts +27 -0
- package/src/node/ta-access.ts +98 -0
- package/src/node/ta-errors.ts +55 -0
- package/src/node/ta-event-util.spec.ts +29 -0
- package/src/node/ta-event-util.ts +23 -0
- package/src/node/ta-server-impl.ts +264 -0
- package/src/node/ta-session-factory.ts +156 -0
- package/src/node/ta-session-registry.ts +75 -0
- package/src/node/ta-session.ts +193 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TaAccess = exports.TaAccessUtil = void 0;
|
|
13
|
+
const node_crypto_1 = require("node:crypto");
|
|
14
|
+
const node_fs_1 = require("node:fs");
|
|
15
|
+
const node_path_1 = require("node:path");
|
|
16
|
+
const core_1 = require("@celljs/core");
|
|
17
|
+
const node_1 = require("@celljs/rpc/lib/node");
|
|
18
|
+
const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
|
|
19
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
20
|
+
const node_2 = require("@celljs/web/lib/node");
|
|
21
|
+
const host_protocol_1 = require("./host-protocol");
|
|
22
|
+
const LOOPBACK_NAMES = new Set(['127.0.0.1', 'localhost', '[::1]']);
|
|
23
|
+
/** Runs before everything else that handles a request. */
|
|
24
|
+
const ACCESS_MIDDLEWARE_PRIORITY = 10000;
|
|
25
|
+
var TaAccessUtil;
|
|
26
|
+
(function (TaAccessUtil) {
|
|
27
|
+
/** From `Authorization: Bearer`, or `?token=` for browsers, whose WebSocket API cannot set headers. */
|
|
28
|
+
function tokenOf(request) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const header = request.headers.authorization;
|
|
31
|
+
if (header === null || header === void 0 ? void 0 : header.startsWith('Bearer ')) {
|
|
32
|
+
return header.slice('Bearer '.length);
|
|
33
|
+
}
|
|
34
|
+
return (_b = new URL((_a = request.url) !== null && _a !== void 0 ? _a : '/', 'http://localhost').searchParams.get('token')) !== null && _b !== void 0 ? _b : undefined;
|
|
35
|
+
}
|
|
36
|
+
TaAccessUtil.tokenOf = tokenOf;
|
|
37
|
+
function equals(a, b) {
|
|
38
|
+
const [left, right] = [Buffer.from(a), Buffer.from(b)];
|
|
39
|
+
return left.length === right.length && (0, node_crypto_1.timingSafeEqual)(left, right);
|
|
40
|
+
}
|
|
41
|
+
TaAccessUtil.equals = equals;
|
|
42
|
+
/** A page that rebinds its domain to 127.0.0.1 reaches the server with its own name in `Host`. */
|
|
43
|
+
function isLoopbackHost(host) {
|
|
44
|
+
return LOOPBACK_NAMES.has((host !== null && host !== void 0 ? host : '').replace(/:\d+$/, ''));
|
|
45
|
+
}
|
|
46
|
+
TaAccessUtil.isLoopbackHost = isLoopbackHost;
|
|
47
|
+
})(TaAccessUtil || (exports.TaAccessUtil = TaAccessUtil = {}));
|
|
48
|
+
/**
|
|
49
|
+
* The token of this server: `TA_SERVE_TOKEN`, which a parent process (the desktop app) can choose, or a
|
|
50
|
+
* random one. It lets in connections and requests, and is published in a file only this user can read.
|
|
51
|
+
*/
|
|
52
|
+
let TaAccess = class TaAccess {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.priority = ACCESS_MIDDLEWARE_PRIORITY;
|
|
55
|
+
this.token = process.env.TA_SERVE_TOKEN || (0, node_crypto_1.randomBytes)(32).toString('base64url');
|
|
56
|
+
this.infoFile = (0, node_path_1.join)(ta_brand_1.TaBrand.agentDir(), ta_protocol_1.TA_SERVE_FILE);
|
|
57
|
+
}
|
|
58
|
+
allows(request) {
|
|
59
|
+
const token = TaAccessUtil.tokenOf(request);
|
|
60
|
+
return token !== undefined && TaAccessUtil.equals(token, this.token) && this.acceptsHost(request);
|
|
61
|
+
}
|
|
62
|
+
/** Calls over a WebSocket were checked when it opened; this covers plain HTTP. */
|
|
63
|
+
async handle(ctx, next) {
|
|
64
|
+
if (node_1.RpcContext.connection() || this.allows(ctx.request)) {
|
|
65
|
+
await next();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
ctx.response.statusCode = 401;
|
|
69
|
+
ctx.response.end('Unauthorized');
|
|
70
|
+
}
|
|
71
|
+
async setServer(server) {
|
|
72
|
+
const publish = () => this.publish(server);
|
|
73
|
+
if (server.listening) {
|
|
74
|
+
publish();
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
server.once('listening', publish);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async onStop() {
|
|
81
|
+
(0, node_fs_1.rmSync)(this.infoFile, { force: true });
|
|
82
|
+
await this.sessions.closeAll();
|
|
83
|
+
}
|
|
84
|
+
acceptsHost(request) {
|
|
85
|
+
return !TaAccessUtil.isLoopbackHost(this.host) || TaAccessUtil.isLoopbackHost(request.headers.host);
|
|
86
|
+
}
|
|
87
|
+
publish(server) {
|
|
88
|
+
var _a;
|
|
89
|
+
const { port } = server.address();
|
|
90
|
+
const info = { url: `ws://${(_a = this.host) !== null && _a !== void 0 ? _a : '127.0.0.1'}:${port}${ta_protocol_1.TA_WEBSOCKET_PATH}`, token: this.token, pid: process.pid };
|
|
91
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.join)(this.infoFile, '..'), { recursive: true });
|
|
92
|
+
(0, node_fs_1.writeFileSync)(this.infoFile, JSON.stringify(info), { mode: 0o600 });
|
|
93
|
+
// The mode above only applies to a new file.
|
|
94
|
+
(0, node_fs_1.chmodSync)(this.infoFile, 0o600);
|
|
95
|
+
console.log(`ta serve: ${info.url} (token in ${this.infoFile})`);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.TaAccess = TaAccess;
|
|
99
|
+
__decorate([
|
|
100
|
+
(0, core_1.Value)('server.host'),
|
|
101
|
+
__metadata("design:type", String)
|
|
102
|
+
], TaAccess.prototype, "host", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
(0, core_1.Autowired)(host_protocol_1.TaSessionRegistry),
|
|
105
|
+
__metadata("design:type", Object)
|
|
106
|
+
], TaAccess.prototype, "sessions", void 0);
|
|
107
|
+
exports.TaAccess = TaAccess = __decorate([
|
|
108
|
+
(0, core_1.Component)([node_1.RpcWebSocketGuard, node_2.Middleware, node_2.ServerAware, core_1.ApplicationLifecycle])
|
|
109
|
+
], TaAccess);
|
|
110
|
+
//# sourceMappingURL=ta-access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-access.js","sourceRoot":"","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AC;QAChC,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,GAAG,cAAc,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;IACrE,CAAC;CACJ,CAAA;;AAjDsB;IADlB,IAAA,YAAK,EAAC,aAAa,CAAC;;sCACY;AAGd;IADlB,IAAA,gBAAS,EAAC,iCAAiB,CAAC;;0CACkB;mBARtC,QAAQ;IADpB,IAAA,gBAAS,EAAC,CAAC,wBAAiB,EAAE,iBAAU,EAAE,kBAAW,EAAE,2BAAoB,CAAC,CAAC;GACjE,QAAQ,CAsDpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-access.spec.d.ts","sourceRoot":"","sources":["../../src/node/ta-access.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const ta_access_1 = require("./ta-access");
|
|
5
|
+
const request = (url, headers = {}) => ({ url, headers });
|
|
6
|
+
(0, bun_test_1.describe)('TaAccessUtil', () => {
|
|
7
|
+
(0, bun_test_1.it)('reads the token from the header or the query', () => {
|
|
8
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.tokenOf(request('/api/ws', { authorization: 'Bearer abc' }))).toBe('abc');
|
|
9
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.tokenOf(request('/api/ws?token=abc'))).toBe('abc');
|
|
10
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.tokenOf(request('/api/ws'))).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
(0, bun_test_1.it)('compares tokens of any length', () => {
|
|
13
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.equals('abc', 'abc')).toBe(true);
|
|
14
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.equals('abc', 'abd')).toBe(false);
|
|
15
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.equals('abc', 'abcd')).toBe(false);
|
|
16
|
+
});
|
|
17
|
+
(0, bun_test_1.it)('knows the names of this machine', () => {
|
|
18
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.isLoopbackHost('127.0.0.1:3000')).toBe(true);
|
|
19
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.isLoopbackHost('localhost')).toBe(true);
|
|
20
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.isLoopbackHost('[::1]:3000')).toBe(true);
|
|
21
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.isLoopbackHost('evil.example:3000')).toBe(false);
|
|
22
|
+
(0, bun_test_1.expect)(ta_access_1.TaAccessUtil.isLoopbackHost(undefined)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=ta-access.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-access.spec.js","sourceRoot":"","sources":["../../src/node/ta-access.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAEhD,2CAA2C;AAE3C,MAAM,OAAO,GAAG,CAAC,GAAW,EAAE,OAAO,GAA2B,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAA+B,CAAC;AAExH,IAAA,mBAAQ,EAAC,cAAc,EAAE,GAAG,EAAE;IAC1B,IAAA,aAAE,EAAC,8CAA8C,EAAE,GAAG,EAAE;QACpD,IAAA,iBAAM,EAAC,wBAAY,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9F,IAAA,iBAAM,EAAC,wBAAY,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACv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ures of {@link TaServer} calls, which reach the client with their message and code. */
|
|
2
|
+
export declare namespace TaErrors {
|
|
3
|
+
function sessionNotFound(sessionId: string): Error;
|
|
4
|
+
function sessionLocked(sessionFile: string): Error;
|
|
5
|
+
function tooManySessions(max: number): Error;
|
|
6
|
+
function messageConflict(clientMessageId: string): Error;
|
|
7
|
+
function modelNotFound(model: string): Error;
|
|
8
|
+
function invalidArgument(message: string, hint: string): Error;
|
|
9
|
+
/** A command that pi refused or that failed. Other errors would lose their message on the way out. */
|
|
10
|
+
function commandFailed(cause: unknown): Error;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ta-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-errors.d.ts","sourceRoot":"","sources":["../../src/node/ta-errors.ts"],"names":[],"mappings":"AAQA,kGAAkG;AAClG,yBAAiB,QAAQ,CAAC;IACtB,SAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,KAAK,CAMxD;IAED,SAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,CAExD;IAED,SAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAElD;IAED,SAAgB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,KAAK,CAM9D;IAED,SAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAMlD;IAED,SAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAEpE;IAED,sGAAsG;IACtG,SAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAMnD;CACJ"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaErrors = void 0;
|
|
4
|
+
const core_1 = require("@celljs/core");
|
|
5
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
6
|
+
const TaError = core_1.ApplicationError.declare(ta_protocol_1.TA_RPC_ERROR_CODE, (code, message, hint) => ({
|
|
7
|
+
message,
|
|
8
|
+
data: { code, hint },
|
|
9
|
+
}));
|
|
10
|
+
/** The failures of {@link TaServer} calls, which reach the client with their message and code. */
|
|
11
|
+
var TaErrors;
|
|
12
|
+
(function (TaErrors) {
|
|
13
|
+
function sessionNotFound(sessionId) {
|
|
14
|
+
return TaError(ta_protocol_1.TaErrorCode.SESSION_NOT_FOUND, `No open session has the id ${sessionId}.`, 'Open it again with openSession and its session file: idle sessions are closed, their files stay.');
|
|
15
|
+
}
|
|
16
|
+
TaErrors.sessionNotFound = sessionNotFound;
|
|
17
|
+
function sessionLocked(sessionFile) {
|
|
18
|
+
return TaError(ta_protocol_1.TaErrorCode.SESSION_LOCKED, `The session ${sessionFile} is open elsewhere.`, 'Close it there first: a session has one writer.');
|
|
19
|
+
}
|
|
20
|
+
TaErrors.sessionLocked = sessionLocked;
|
|
21
|
+
function tooManySessions(max) {
|
|
22
|
+
return TaError(ta_protocol_1.TaErrorCode.TOO_MANY_SESSIONS, `${max} sessions are open, the limit of this server.`, 'Close a session, or raise ta.host.maxSessions.');
|
|
23
|
+
}
|
|
24
|
+
TaErrors.tooManySessions = tooManySessions;
|
|
25
|
+
function messageConflict(clientMessageId) {
|
|
26
|
+
return TaError(ta_protocol_1.TaErrorCode.MESSAGE_CONFLICT, `The message id ${clientMessageId} was used for a different message.`, 'Use a new clientMessageId for each message.');
|
|
27
|
+
}
|
|
28
|
+
TaErrors.messageConflict = messageConflict;
|
|
29
|
+
function modelNotFound(model) {
|
|
30
|
+
return TaError(ta_protocol_1.TaErrorCode.MODEL_NOT_FOUND, `The model ${model} is not known or has no credentials.`, 'Use <provider>/<model id>; getAvailableModels lists the ones that work.');
|
|
31
|
+
}
|
|
32
|
+
TaErrors.modelNotFound = modelNotFound;
|
|
33
|
+
function invalidArgument(message, hint) {
|
|
34
|
+
return TaError(ta_protocol_1.TaErrorCode.INVALID_ARGUMENT, message, hint);
|
|
35
|
+
}
|
|
36
|
+
TaErrors.invalidArgument = invalidArgument;
|
|
37
|
+
/** A command that pi refused or that failed. Other errors would lose their message on the way out. */
|
|
38
|
+
function commandFailed(cause) {
|
|
39
|
+
if (core_1.ApplicationError.is(cause)) {
|
|
40
|
+
return cause;
|
|
41
|
+
}
|
|
42
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
43
|
+
return TaError(ta_protocol_1.TaErrorCode.COMMAND_FAILED, message, 'The message comes from the agent; fix what it says and send the command again.');
|
|
44
|
+
}
|
|
45
|
+
TaErrors.commandFailed = commandFailed;
|
|
46
|
+
})(TaErrors || (exports.TaErrors = TaErrors = {}));
|
|
47
|
+
//# sourceMappingURL=ta-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-errors.js","sourceRoot":"","sources":["../../src/node/ta-errors.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAChD,qDAAuF;AAEvF,MAAM,OAAO,GAAG,uBAAgB,CAAC,OAAO,CAAsB,+BAAiB,EAAE,CAAC,IAAiB,EAAE,OAAe,EAAE,IAAY,EAAE,EAAE,CAAC,CAAC;IACpI,OAAO;IACP,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;CACvB,CAAC,CAAC,CAAC;AAEJ,kGAAkG;AAClG,IAAiB,QAAQ,CA6CxB;AA7CD,WAAiB,QAAQ;IACrB,SAAgB,eAAe,CAAC,SAAiB;QAC7C,OAAO,OAAO,CACV,yBAAW,CAAC,iBAAiB,EAC7B,8BAA8B,SAAS,GAAG,EAC1C,kGAAkG,CACrG,CAAC;IACN,CAAC;IANe,SAAA,eAAe,kBAM9B,CAAA;IAED,SAAgB,aAAa,CAAC,WAAmB;QAC7C,OAAO,OAAO,CAAC,yBAAW,CAAC,cAAc,EAAE,eAAe,WAAW,qBAAqB,EAAE,iDAAiD,CAAC,CAAC;IACnJ,CAAC;IAFe,SAAA,aAAa,gBAE5B,C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AgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).AgentSessionEvent;
|
|
3
|
+
export declare namespace TaEventUtil {
|
|
4
|
+
/**
|
|
5
|
+
* An event of pi as it goes on the wire, the JSON form of pi's RPC and JSON modes (pi does not export
|
|
6
|
+
* its function). pi's `message_update` holds the whole message so far: sent as is, a reply would cost
|
|
7
|
+
* the square of its length.
|
|
8
|
+
*/
|
|
9
|
+
function toWire(event: AgentSessionEvent): TaEvent;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=ta-event-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-event-util.d.ts","sourceRoot":"","sources":["../../src/node/ta-event-util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,KAAK,iBAAiB,GAAG,OAAO,iCAAiC,EAAU,UAAE,iBAAiB,EAAE,QAAQ,IAAE,EAAG,iBAAiB,CAAC;AAE/H,yBAAiB,WAAW,CAAC;IACzB;;;;OAIG;IACH,SAAgB,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAWxD;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaEventUtil = void 0;
|
|
4
|
+
var TaEventUtil;
|
|
5
|
+
(function (TaEventUtil) {
|
|
6
|
+
/**
|
|
7
|
+
* An event of pi as it goes on the wire, the JSON form of pi's RPC and JSON modes (pi does not export
|
|
8
|
+
* its function). pi's `message_update` holds the whole message so far: sent as is, a reply would cost
|
|
9
|
+
* the square of its length.
|
|
10
|
+
*/
|
|
11
|
+
function toWire(event) {
|
|
12
|
+
var _a;
|
|
13
|
+
if (event.type !== 'message_update') {
|
|
14
|
+
return event;
|
|
15
|
+
}
|
|
16
|
+
const { partial, ...delta } = event.assistantMessageEvent;
|
|
17
|
+
const block = delta.type === 'toolcall_start' ? partial === null || partial === void 0 ? void 0 : partial.content[(_a = delta.contentIndex) !== null && _a !== void 0 ? _a : -1] : undefined;
|
|
18
|
+
const assistantMessageEvent = block ? { ...delta, id: block.id, toolName: block.name } : delta;
|
|
19
|
+
return { type: 'message_update', usage: event.message.usage, assistantMessageEvent };
|
|
20
|
+
}
|
|
21
|
+
TaEventUtil.toWire = toWire;
|
|
22
|
+
})(TaEventUtil || (exports.TaEventUtil = TaEventUtil = {}));
|
|
23
|
+
//# sourceMappingURL=ta-event-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-event-util.js","sourceRoot":"","sources":["../../src/node/ta-event-util.ts"],"names":[],"mappings":";;;AAIA,IAAiB,WAAW,CAkB3B;AAlBD,WAAiB,WAAW;IACxB;;;;OAIG;IACH,SAAgB,MAAM,CAAC,KAAwB;;QAC3C,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YAClC,OAAO,KAAgB,CAAC;QAC5B,CAAC;QACD,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,qBAGnC,CAAC;QACF,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,KAAK,gBAAgB,CAAC,CAAC,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,OAAC,KAAK,CAAC,YAAY,mCAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACvG,MAAM,qBAAqB,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/F,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAG,KAAK,CAAC,OAA+B,CAAC,KAAK,EAAE,qBAAqB,EAAa,CAAC;IAC7H,CAAC;IAXe,YAAA,MAAM,SAWrB,CAAA;AACL,CAAC,EAlBgB,WAAW,aAAX,WAAW,GAAX,WAAW,QAkB3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-event-util.spec.d.ts","sourceRoot":"","sources":["../../src/node/ta-event-util.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
const ta_event_util_1 = require("./ta-event-util");
|
|
5
|
+
const toWire = (event) => ta_event_util_1.TaEventUtil.toWire(event);
|
|
6
|
+
(0, bun_test_1.describe)('TaEventUtil', () => {
|
|
7
|
+
(0, bun_test_1.it)('leaves other events as they are', () => {
|
|
8
|
+
const event = { type: 'agent_start' };
|
|
9
|
+
(0, bun_test_1.expect)(toWire(event)).toBe(event);
|
|
10
|
+
});
|
|
11
|
+
(0, bun_test_1.it)('sends a delta without the whole message', () => {
|
|
12
|
+
const wire = toWire({
|
|
13
|
+
type: 'message_update',
|
|
14
|
+
message: { role: 'assistant', usage: { input: 1 } },
|
|
15
|
+
assistantMessageEvent: { type: 'text_delta', contentIndex: 0, delta: 'x', partial: { content: ['a very long message'] } },
|
|
16
|
+
});
|
|
17
|
+
(0, bun_test_1.expect)(wire).toEqual({ type: 'message_update', usage: { input: 1 }, assistantMessageEvent: { type: 'text_delta', contentIndex: 0, delta: 'x' } });
|
|
18
|
+
});
|
|
19
|
+
(0, bun_test_1.it)('names the tool when a tool call starts', () => {
|
|
20
|
+
const wire = toWire({
|
|
21
|
+
type: 'message_update',
|
|
22
|
+
message: { role: 'assistant' },
|
|
23
|
+
assistantMessageEvent: { type: 'toolcall_start', contentIndex: 0, partial: { content: [{ type: 'toolCall', id: 'c1', name: 'bash' }] } },
|
|
24
|
+
});
|
|
25
|
+
(0, bun_test_1.expect)(wire.assistantMessageEvent).toEqual({ type: 'toolcall_start', contentIndex: 0, id: 'c1', toolName: 'bash' });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=ta-event-util.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-event-util.spec.js","sourceRoot":"","sources":["../../src/node/ta-event-util.spec.ts"],"names":[],"mappings":";;AAAA,uCAAgD;AAChD,mDAA8C;AAE9C,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,2BAAW,CAAC,MAAM,CAAC,KAAc,CAAQ,CAAC;AAE7E,IAAA,mBAAQ,EAAC,aAAa,EAAE,GAAG,EAAE;IACzB,IAAA,aAAE,EAAC,iCAAiC,EAAE,GAAG,EAAE;QACvC,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;QACtC,IAAA,iBAAM,EAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,yCAAyC,EAAE,GAAG,EAAE;QAC/C,MAAM,IAAI,GAAG,MAAM,CAAC;YAChB,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YACnD,qBAAqB,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,qBAAqB,CAAC,EAAE,EAAE;SAC5H,CAAC,CAAC;QACH,IAAA,iBAAM,EAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,qBAAqB,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACtJ,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,wCAAwC,EAAE,GAAG,EAAE;QAC9C,MAAM,IAAI,GAAG,MAAM,CAAC;YAChB,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YAC9B,qBAAqB,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;SAC3I,CAAC,CAAC;QACH,IAAA,iBAAM,EAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IACxH,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type RpcExtensionUIResponse, type TaAttachResult, type TaClientToolResult, type TaCommandResult, type TaOpenSessionOptions, type TaPromptInput, type TaPromptReceipt, TaServer, type TaSessionInfo, type ThinkingLevel } from '@celljs/ta-protocol';
|
|
2
|
+
import { TaSessionRegistry } from './host-protocol';
|
|
3
|
+
import type { TaSession } from './ta-session';
|
|
4
|
+
/** Each command does what the command of the same name does in pi's RPC mode. */
|
|
5
|
+
export declare class TaServerImpl implements TaServer {
|
|
6
|
+
protected readonly sessions: TaSessionRegistry;
|
|
7
|
+
openSession(options: TaOpenSessionOptions): Promise<TaSessionInfo>;
|
|
8
|
+
closeSession(sessionId: string): Promise<void>;
|
|
9
|
+
listSessions(): Promise<TaSessionInfo[]>;
|
|
10
|
+
attach(sessionId: string, afterSeq?: number): Promise<TaAttachResult>;
|
|
11
|
+
detach(sessionId: string): Promise<void>;
|
|
12
|
+
respondUi(sessionId: string, response: RpcExtensionUIResponse): Promise<boolean>;
|
|
13
|
+
/** Client tools are declared in the protocol and not run yet: nobody can be waiting. */
|
|
14
|
+
respondClientTool(_sessionId: string, _result: TaClientToolResult): Promise<boolean>;
|
|
15
|
+
prompt(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
16
|
+
steer(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
17
|
+
followUp(sessionId: string, input: TaPromptInput): Promise<TaPromptReceipt>;
|
|
18
|
+
abort(sessionId: string): Promise<void>;
|
|
19
|
+
clearQueue(sessionId: string): Promise<TaCommandResult<'clear_queue'>>;
|
|
20
|
+
newSession(sessionId: string, parentSession?: string): Promise<TaCommandResult<'new_session'>>;
|
|
21
|
+
getState(sessionId: string): Promise<TaCommandResult<'get_state'>>;
|
|
22
|
+
setModel(sessionId: string, provider: string, modelId: string): Promise<TaCommandResult<'set_model'>>;
|
|
23
|
+
cycleModel(sessionId: string): Promise<TaCommandResult<'cycle_model'>>;
|
|
24
|
+
getAvailableModels(sessionId: string): Promise<TaCommandResult<'get_available_models'>>;
|
|
25
|
+
setThinkingLevel(sessionId: string, level: ThinkingLevel): Promise<void>;
|
|
26
|
+
cycleThinkingLevel(sessionId: string): Promise<TaCommandResult<'cycle_thinking_level'>>;
|
|
27
|
+
getAvailableThinkingLevels(sessionId: string): Promise<TaCommandResult<'get_available_thinking_levels'>>;
|
|
28
|
+
setSteeringMode(sessionId: string, mode: 'all' | 'one-at-a-time'): Promise<void>;
|
|
29
|
+
setFollowUpMode(sessionId: string, mode: 'all' | 'one-at-a-time'): Promise<void>;
|
|
30
|
+
compact(sessionId: string, customInstructions?: string): Promise<TaCommandResult<'compact'>>;
|
|
31
|
+
setAutoCompaction(sessionId: string, enabled: boolean): Promise<void>;
|
|
32
|
+
setAutoRetry(sessionId: string, enabled: boolean): Promise<void>;
|
|
33
|
+
abortRetry(sessionId: string): Promise<void>;
|
|
34
|
+
bash(sessionId: string, command: string, excludeFromContext?: boolean): Promise<TaCommandResult<'bash'>>;
|
|
35
|
+
abortBash(sessionId: string): Promise<void>;
|
|
36
|
+
getSessionStats(sessionId: string): Promise<TaCommandResult<'get_session_stats'>>;
|
|
37
|
+
exportHtml(sessionId: string, outputPath?: string): Promise<TaCommandResult<'export_html'>>;
|
|
38
|
+
switchSession(sessionId: string, sessionPath: string): Promise<TaCommandResult<'switch_session'>>;
|
|
39
|
+
fork(sessionId: string, entryId: string): Promise<TaCommandResult<'fork'>>;
|
|
40
|
+
clone(sessionId: string): Promise<TaCommandResult<'clone'>>;
|
|
41
|
+
getForkMessages(sessionId: string): Promise<TaCommandResult<'get_fork_messages'>>;
|
|
42
|
+
getEntries(sessionId: string, since?: string): Promise<TaCommandResult<'get_entries'>>;
|
|
43
|
+
getTree(sessionId: string): Promise<TaCommandResult<'get_tree'>>;
|
|
44
|
+
getLastAssistantText(sessionId: string): Promise<TaCommandResult<'get_last_assistant_text'>>;
|
|
45
|
+
setSessionName(sessionId: string, name: string): Promise<void>;
|
|
46
|
+
getMessages(sessionId: string): Promise<TaCommandResult<'get_messages'>>;
|
|
47
|
+
getCommands(sessionId: string): Promise<TaCommandResult<'get_commands'>>;
|
|
48
|
+
protected on<T>(sessionId: string, command: (session: TaSession) => T | Promise<T>): Promise<T>;
|
|
49
|
+
protected guard<T>(command: () => Promise<T>): Promise<T>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=ta-server-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ta-server-impl.d.ts","sourceRoot":"","sources":["../../src/node/ta-server-impl.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAA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O,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CASrF;IAED,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAE/D;IAED,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAE3F;IAED,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO7D;IAED,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,CAEvE;IAED,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,CAYvE;IAED,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE9F;IAED,UAAgB,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAM9D;CACJ"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TaServerImpl = void 0;
|
|
13
|
+
const core_1 = require("@celljs/core");
|
|
14
|
+
const rpc_1 = require("@celljs/rpc");
|
|
15
|
+
const node_1 = require("@celljs/rpc/lib/node");
|
|
16
|
+
const ta_protocol_1 = require("@celljs/ta-protocol");
|
|
17
|
+
const host_protocol_1 = require("./host-protocol");
|
|
18
|
+
const ta_errors_1 = require("./ta-errors");
|
|
19
|
+
/** Each command does what the command of the same name does in pi's RPC mode. */
|
|
20
|
+
let TaServerImpl = class TaServerImpl {
|
|
21
|
+
async openSession(options) {
|
|
22
|
+
return this.guard(async () => (await this.sessions.open(options)).info());
|
|
23
|
+
}
|
|
24
|
+
closeSession(sessionId) {
|
|
25
|
+
return this.guard(() => this.sessions.close(sessionId));
|
|
26
|
+
}
|
|
27
|
+
async listSessions() {
|
|
28
|
+
return this.sessions.list().map(session => session.info());
|
|
29
|
+
}
|
|
30
|
+
attach(sessionId, afterSeq) {
|
|
31
|
+
return this.on(sessionId, session => session.attach(this.sessions.channel(node_1.RpcContext.requireConnection()), afterSeq));
|
|
32
|
+
}
|
|
33
|
+
detach(sessionId) {
|
|
34
|
+
return this.on(sessionId, session => session.detach(this.sessions.channel(node_1.RpcContext.requireConnection())));
|
|
35
|
+
}
|
|
36
|
+
respondUi(sessionId, response) {
|
|
37
|
+
return this.on(sessionId, session => session.respondUi(response));
|
|
38
|
+
}
|
|
39
|
+
/** Client tools are declared in the protocol and not run yet: nobody can be waiting. */
|
|
40
|
+
async respondClientTool(_sessionId, _result) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
prompt(sessionId, input) {
|
|
44
|
+
return this.on(sessionId, session => session.prompt(input));
|
|
45
|
+
}
|
|
46
|
+
steer(sessionId, input) {
|
|
47
|
+
return this.on(sessionId, session => session.steer(input));
|
|
48
|
+
}
|
|
49
|
+
followUp(sessionId, input) {
|
|
50
|
+
return this.on(sessionId, session => session.followUp(input));
|
|
51
|
+
}
|
|
52
|
+
abort(sessionId) {
|
|
53
|
+
return this.on(sessionId, ({ pi }) => pi.abort());
|
|
54
|
+
}
|
|
55
|
+
clearQueue(sessionId) {
|
|
56
|
+
return this.on(sessionId, ({ pi }) => pi.clearQueue());
|
|
57
|
+
}
|
|
58
|
+
newSession(sessionId, parentSession) {
|
|
59
|
+
return this.on(sessionId, ({ runtime }) => runtime.newSession(parentSession ? { parentSession } : undefined));
|
|
60
|
+
}
|
|
61
|
+
getState(sessionId) {
|
|
62
|
+
return this.on(sessionId, ({ pi }) => ({
|
|
63
|
+
model: pi.model,
|
|
64
|
+
thinkingLevel: pi.thinkingLevel,
|
|
65
|
+
isStreaming: pi.isStreaming,
|
|
66
|
+
isCompacting: pi.isCompacting,
|
|
67
|
+
steeringMode: pi.steeringMode,
|
|
68
|
+
followUpMode: pi.followUpMode,
|
|
69
|
+
sessionFile: pi.sessionFile,
|
|
70
|
+
sessionId: pi.sessionId,
|
|
71
|
+
sessionName: pi.sessionName,
|
|
72
|
+
autoCompactionEnabled: pi.autoCompactionEnabled,
|
|
73
|
+
messageCount: pi.messages.length,
|
|
74
|
+
pendingMessageCount: pi.pendingMessageCount,
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
setModel(sessionId, provider, modelId) {
|
|
78
|
+
return this.on(sessionId, async ({ pi }) => {
|
|
79
|
+
const model = pi.modelRuntime.getAvailableSnapshot().find(m => m.provider === provider && m.id === modelId);
|
|
80
|
+
if (!model) {
|
|
81
|
+
throw ta_errors_1.TaErrors.modelNotFound(`${provider}/${modelId}`);
|
|
82
|
+
}
|
|
83
|
+
await pi.setModel(model);
|
|
84
|
+
return model;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
cycleModel(sessionId) {
|
|
88
|
+
return this.on(sessionId, async ({ pi }) => { var _a; return (_a = (await pi.cycleModel())) !== null && _a !== void 0 ? _a : null; });
|
|
89
|
+
}
|
|
90
|
+
getAvailableModels(sessionId) {
|
|
91
|
+
return this.on(sessionId, ({ pi }) => ({ models: [...pi.modelRuntime.getAvailableSnapshot()] }));
|
|
92
|
+
}
|
|
93
|
+
setThinkingLevel(sessionId, level) {
|
|
94
|
+
return this.on(sessionId, ({ pi }) => pi.setThinkingLevel(level));
|
|
95
|
+
}
|
|
96
|
+
cycleThinkingLevel(sessionId) {
|
|
97
|
+
return this.on(sessionId, ({ pi }) => {
|
|
98
|
+
const level = pi.cycleThinkingLevel();
|
|
99
|
+
return level ? { level } : null;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getAvailableThinkingLevels(sessionId) {
|
|
103
|
+
return this.on(sessionId, ({ pi }) => ({ levels: pi.getAvailableThinkingLevels() }));
|
|
104
|
+
}
|
|
105
|
+
setSteeringMode(sessionId, mode) {
|
|
106
|
+
return this.on(sessionId, ({ pi }) => pi.setSteeringMode(mode));
|
|
107
|
+
}
|
|
108
|
+
setFollowUpMode(sessionId, mode) {
|
|
109
|
+
return this.on(sessionId, ({ pi }) => pi.setFollowUpMode(mode));
|
|
110
|
+
}
|
|
111
|
+
compact(sessionId, customInstructions) {
|
|
112
|
+
return this.on(sessionId, ({ pi }) => pi.compact(customInstructions));
|
|
113
|
+
}
|
|
114
|
+
setAutoCompaction(sessionId, enabled) {
|
|
115
|
+
return this.on(sessionId, ({ pi }) => pi.setAutoCompactionEnabled(enabled));
|
|
116
|
+
}
|
|
117
|
+
setAutoRetry(sessionId, enabled) {
|
|
118
|
+
return this.on(sessionId, ({ pi }) => pi.setAutoRetryEnabled(enabled));
|
|
119
|
+
}
|
|
120
|
+
abortRetry(sessionId) {
|
|
121
|
+
return this.on(sessionId, ({ pi }) => pi.abortRetry());
|
|
122
|
+
}
|
|
123
|
+
bash(sessionId, command, excludeFromContext) {
|
|
124
|
+
return this.on(sessionId, async ({ pi }) => {
|
|
125
|
+
const handled = await pi.extensionRunner.emitUserBash({
|
|
126
|
+
type: 'user_bash',
|
|
127
|
+
command,
|
|
128
|
+
excludeFromContext: excludeFromContext !== null && excludeFromContext !== void 0 ? excludeFromContext : false,
|
|
129
|
+
cwd: pi.sessionManager.getCwd(),
|
|
130
|
+
});
|
|
131
|
+
if (handled === null || handled === void 0 ? void 0 : handled.result) {
|
|
132
|
+
pi.recordBashResult(command, handled.result, { excludeFromContext });
|
|
133
|
+
return handled.result;
|
|
134
|
+
}
|
|
135
|
+
return pi.executeBash(command, undefined, { excludeFromContext, operations: handled === null || handled === void 0 ? void 0 : handled.operations });
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
abortBash(sessionId) {
|
|
139
|
+
return this.on(sessionId, ({ pi }) => pi.abortBash());
|
|
140
|
+
}
|
|
141
|
+
getSessionStats(sessionId) {
|
|
142
|
+
return this.on(sessionId, ({ pi }) => pi.getSessionStats());
|
|
143
|
+
}
|
|
144
|
+
exportHtml(sessionId, outputPath) {
|
|
145
|
+
return this.on(sessionId, async ({ pi }) => ({ path: await pi.exportToHtml(outputPath) }));
|
|
146
|
+
}
|
|
147
|
+
switchSession(sessionId, sessionPath) {
|
|
148
|
+
return this.on(sessionId, ({ runtime }) => runtime.switchSession(sessionPath));
|
|
149
|
+
}
|
|
150
|
+
fork(sessionId, entryId) {
|
|
151
|
+
return this.on(sessionId, async ({ runtime }) => {
|
|
152
|
+
var _a;
|
|
153
|
+
const result = await runtime.fork(entryId);
|
|
154
|
+
return { text: (_a = result.selectedText) !== null && _a !== void 0 ? _a : '', cancelled: result.cancelled };
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
clone(sessionId) {
|
|
158
|
+
return this.on(sessionId, async ({ pi, runtime }) => {
|
|
159
|
+
const leafId = pi.sessionManager.getLeafId();
|
|
160
|
+
if (!leafId) {
|
|
161
|
+
throw ta_errors_1.TaErrors.invalidArgument('This session has nothing to clone yet.', 'Send a message first.');
|
|
162
|
+
}
|
|
163
|
+
return { cancelled: (await runtime.fork(leafId, { position: 'at' })).cancelled };
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
getForkMessages(sessionId) {
|
|
167
|
+
return this.on(sessionId, ({ pi }) => ({ messages: pi.getUserMessagesForForking() }));
|
|
168
|
+
}
|
|
169
|
+
getEntries(sessionId, since) {
|
|
170
|
+
return this.on(sessionId, ({ pi }) => {
|
|
171
|
+
const entries = pi.sessionManager.getEntries();
|
|
172
|
+
const index = since === undefined ? -1 : entries.findIndex(entry => entry.id === since);
|
|
173
|
+
if (since !== undefined && index === -1) {
|
|
174
|
+
throw ta_errors_1.TaErrors.invalidArgument(`No entry has the id ${since}.`, 'Pass the id of an entry of this session.');
|
|
175
|
+
}
|
|
176
|
+
return { entries: entries.slice(index + 1), leafId: pi.sessionManager.getLeafId() };
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
getTree(sessionId) {
|
|
180
|
+
return this.on(sessionId, ({ pi }) => ({ tree: pi.sessionManager.getTree(), leafId: pi.sessionManager.getLeafId() }));
|
|
181
|
+
}
|
|
182
|
+
getLastAssistantText(sessionId) {
|
|
183
|
+
return this.on(sessionId, ({ pi }) => { var _a; return ({ text: (_a = pi.getLastAssistantText()) !== null && _a !== void 0 ? _a : null }); });
|
|
184
|
+
}
|
|
185
|
+
setSessionName(sessionId, name) {
|
|
186
|
+
return this.on(sessionId, ({ pi }) => {
|
|
187
|
+
if (!name.trim()) {
|
|
188
|
+
throw ta_errors_1.TaErrors.invalidArgument('A session name cannot be empty.', 'Pass a name with visible characters.');
|
|
189
|
+
}
|
|
190
|
+
pi.setSessionName(name.trim());
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
getMessages(sessionId) {
|
|
194
|
+
return this.on(sessionId, ({ pi }) => ({ messages: pi.messages }));
|
|
195
|
+
}
|
|
196
|
+
getCommands(sessionId) {
|
|
197
|
+
return this.on(sessionId, ({ pi }) => ({
|
|
198
|
+
commands: [
|
|
199
|
+
...pi.extensionRunner
|
|
200
|
+
.getRegisteredCommands()
|
|
201
|
+
.map(c => ({ name: c.invocationName, description: c.description, source: 'extension', sourceInfo: c.sourceInfo })),
|
|
202
|
+
...pi.promptTemplates.map(t => ({ name: t.name, description: t.description, source: 'prompt', sourceInfo: t.sourceInfo })),
|
|
203
|
+
...pi.resourceLoader
|
|
204
|
+
.getSkills()
|
|
205
|
+
.skills.map(s => ({ name: `skill:${s.name}`, description: s.description, source: 'skill', sourceInfo: s.sourceInfo })),
|
|
206
|
+
],
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
on(sessionId, command) {
|
|
210
|
+
return this.guard(async () => command(this.sessions.require(sessionId)));
|
|
211
|
+
}
|
|
212
|
+
async guard(command) {
|
|
213
|
+
try {
|
|
214
|
+
return await command();
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
throw ta_errors_1.TaErrors.commandFailed(error);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
exports.TaServerImpl = TaServerImpl;
|
|
222
|
+
__decorate([
|
|
223
|
+
(0, core_1.Autowired)(host_protocol_1.TaSessionRegistry),
|
|
224
|
+
__metadata("design:type", Object)
|
|
225
|
+
], TaServerImpl.prototype, "sessions", void 0);
|
|
226
|
+
exports.TaServerImpl = TaServerImpl = __decorate([
|
|
227
|
+
(0, rpc_1.Rpc)(ta_protocol_1.TaServer)
|
|
228
|
+
], TaServerImpl);
|
|
229
|
+
//# sourceMappingURL=ta-server-impl.js.map
|