@celljs/ta-host 4.10.0 → 4.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/README.en.md +4 -4
- package/README.md +4 -4
- package/esm/node/client-tool-broker.d.ts +6 -2
- package/esm/node/client-tool-broker.js +11 -4
- package/esm/node/host-protocol.d.ts +12 -7
- package/esm/node/index.d.ts +1 -0
- package/esm/node/index.js +1 -0
- package/esm/node/package-hosts.d.ts +6 -0
- package/esm/node/package-hosts.js +36 -1
- package/esm/node/package-server-impl.d.ts +0 -1
- package/esm/node/package-server-impl.js +0 -3
- package/esm/node/relay-bridge.d.ts +12 -2
- package/esm/node/relay-bridge.js +93 -3
- package/esm/node/rooms-bridge.d.ts +60 -0
- package/esm/node/rooms-bridge.js +155 -0
- package/esm/node/session-catalog.d.ts +7 -3
- package/esm/node/session-catalog.js +12 -4
- package/esm/node/session-info-util.d.ts +2 -1
- package/esm/node/session-info-util.js +34 -7
- package/esm/node/session-list-feed.d.ts +28 -0
- package/esm/node/session-list-feed.js +62 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +2 -0
- package/esm/node/sign-in/sign-in-flow.js +9 -0
- package/esm/node/sign-in/sign-in-provider.js +3 -2
- package/esm/node/slash-command-util.d.ts +43 -0
- package/esm/node/slash-command-util.js +105 -0
- package/esm/node/ta-event-util.d.ts +9 -2
- package/esm/node/ta-event-util.js +31 -5
- package/esm/node/ta-server-impl.d.ts +13 -5
- package/esm/node/ta-server-impl.js +34 -16
- package/esm/node/ta-session-factory.d.ts +16 -1
- package/esm/node/ta-session-factory.js +42 -14
- package/esm/node/ta-session-registry.d.ts +4 -1
- package/esm/node/ta-session-registry.js +8 -0
- package/esm/node/ta-session.d.ts +8 -2
- package/esm/node/ta-session.js +41 -4
- package/esm/node/web-extension-catalog.d.ts +5 -1
- package/esm/node/web-extension-catalog.js +15 -19
- package/esm/node/web-extension-util.js +7 -3
- package/esm/node/workspace-files.d.ts +16 -12
- package/esm/node/workspace-files.js +14 -10
- package/esm/node/workspace-protocol.d.ts +1 -1
- package/lib/node/client-tool-broker.d.ts +6 -2
- package/lib/node/client-tool-broker.js +11 -4
- package/lib/node/host-protocol.d.ts +12 -7
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +1 -0
- package/lib/node/package-hosts.d.ts +6 -0
- package/lib/node/package-hosts.js +35 -0
- package/lib/node/package-server-impl.d.ts +0 -1
- package/lib/node/package-server-impl.js +0 -3
- package/lib/node/relay-bridge.d.ts +12 -2
- package/lib/node/relay-bridge.js +91 -1
- package/lib/node/rooms-bridge.d.ts +61 -0
- package/lib/node/rooms-bridge.js +158 -0
- package/lib/node/session-catalog.d.ts +7 -3
- package/lib/node/session-catalog.js +12 -4
- package/lib/node/session-info-util.d.ts +2 -1
- package/lib/node/session-info-util.js +34 -7
- package/lib/node/session-list-feed.d.ts +29 -0
- package/lib/node/session-list-feed.js +66 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +2 -0
- package/lib/node/sign-in/sign-in-flow.js +10 -1
- package/lib/node/sign-in/sign-in-provider.js +3 -2
- package/lib/node/slash-command-util.d.ts +44 -0
- package/lib/node/slash-command-util.js +108 -0
- package/lib/node/ta-event-util.d.ts +9 -2
- package/lib/node/ta-event-util.js +31 -5
- package/lib/node/ta-server-impl.d.ts +13 -5
- package/lib/node/ta-server-impl.js +32 -14
- package/lib/node/ta-session-factory.d.ts +16 -1
- package/lib/node/ta-session-factory.js +42 -14
- package/lib/node/ta-session-registry.d.ts +4 -1
- package/lib/node/ta-session-registry.js +8 -0
- package/lib/node/ta-session.d.ts +8 -2
- package/lib/node/ta-session.js +41 -4
- package/lib/node/web-extension-catalog.d.ts +5 -1
- package/lib/node/web-extension-catalog.js +15 -19
- package/lib/node/web-extension-util.js +7 -3
- package/lib/node/workspace-files.d.ts +16 -12
- package/lib/node/workspace-files.js +13 -9
- package/lib/node/workspace-protocol.d.ts +1 -1
- package/package.json +10 -10
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var RoomsBridge_1;
|
|
11
|
+
import { ApplicationLifecycle, Autowired, Component } from '@celljs/core';
|
|
12
|
+
import { Rpc } from '@celljs/rpc';
|
|
13
|
+
import { RpcContext } from '@celljs/rpc/lib/node';
|
|
14
|
+
import { TaClient, TaRoomServer, TaRoomWatchUtil, } from '@celljs/ta-protocol';
|
|
15
|
+
import { RELAY_BRIDGE } from './relay-bridge.js';
|
|
16
|
+
import { TaErrors } from './ta-errors.js';
|
|
17
|
+
/** The id of {@link RoomsBridge}. */
|
|
18
|
+
export const ROOMS_BRIDGE = Symbol('RoomsBridge');
|
|
19
|
+
/**
|
|
20
|
+
* The rooms of this Ta (docs/design/ta-link.md 3): RelayHubs, connected to its rooms while ta serve runs, so that
|
|
21
|
+
* the owner hears who asks to join without a page open; the clients that watch hear what happens in them, and
|
|
22
|
+
* the server side of packages has them as TaExtensionHost.rooms.
|
|
23
|
+
*/
|
|
24
|
+
let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
|
|
25
|
+
constructor() {
|
|
26
|
+
/** The connections that watch, and what they hear: messages and the state too, or the state of some keys. */
|
|
27
|
+
this.watchers = new Map();
|
|
28
|
+
this.rooms = {
|
|
29
|
+
getIdentity: async () => RoomsBridge_1.identity(await this.hubs.identity()),
|
|
30
|
+
setName: async (name) => RoomsBridge_1.identity(await this.hubs.setName(name)),
|
|
31
|
+
listRooms: async () => this.hubs.list(),
|
|
32
|
+
createRoom: input => this.hubs.create(input),
|
|
33
|
+
invite: (room, options) => this.hubs.invite(room, options !== null && options !== void 0 ? options : {}),
|
|
34
|
+
join: link => this.hubs.join(link),
|
|
35
|
+
listRequests: () => this.hubs.requests(),
|
|
36
|
+
answer: (room, ask, accept) => this.hubs.answer(room, ask, accept),
|
|
37
|
+
removeMember: (room, member) => this.hubs.remove(room, member),
|
|
38
|
+
leave: room => this.hubs.leave(room),
|
|
39
|
+
send: (room, data, to) => this.hubs.send(room, data, to),
|
|
40
|
+
getState: (room, prefix) => this.hubs.getState(room, prefix),
|
|
41
|
+
setState: (room, key, value, version) => this.hubs.setState(room, key, value, version),
|
|
42
|
+
listFriends: async () => this.hubs.friends().map(({ id, name, rooms, metAt, seenAt }) => ({ id, name, rooms, metAt, seenAt })),
|
|
43
|
+
removeFriend: async (id) => this.hubs.removeFriend(id),
|
|
44
|
+
onEvent: listener => this.hubs.onEvent(listener),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
get hubs() {
|
|
48
|
+
return this.relay.hubs;
|
|
49
|
+
}
|
|
50
|
+
onStart() {
|
|
51
|
+
this.hubs.onEvent(event => this.broadcast(event));
|
|
52
|
+
this.hubs.start();
|
|
53
|
+
}
|
|
54
|
+
onStop() {
|
|
55
|
+
this.hubs.stop();
|
|
56
|
+
}
|
|
57
|
+
/** `watch` undefined: no more. */
|
|
58
|
+
watch(connection, watch) {
|
|
59
|
+
if (watch === undefined) {
|
|
60
|
+
this.watchers.delete(connection);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!this.watchers.has(connection)) {
|
|
64
|
+
connection.onClose(() => this.watchers.delete(connection));
|
|
65
|
+
}
|
|
66
|
+
this.watchers.set(connection, watch);
|
|
67
|
+
}
|
|
68
|
+
broadcast(event) {
|
|
69
|
+
for (const [connection, watch] of this.watchers) {
|
|
70
|
+
if (!connection.closed && TaRoomWatchUtil.hears(watch, event)) {
|
|
71
|
+
connection
|
|
72
|
+
.client(TaClient)
|
|
73
|
+
.onRoomEvent(event)
|
|
74
|
+
.catch(() => undefined);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
static identity({ id, name }) {
|
|
79
|
+
return { id, name };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
__decorate([
|
|
83
|
+
Autowired({ id: RELAY_BRIDGE, detached: true }),
|
|
84
|
+
__metadata("design:type", Function)
|
|
85
|
+
], RoomsBridge.prototype, "relay", void 0);
|
|
86
|
+
RoomsBridge = RoomsBridge_1 = __decorate([
|
|
87
|
+
Component([ROOMS_BRIDGE, ApplicationLifecycle])
|
|
88
|
+
], RoomsBridge);
|
|
89
|
+
export { RoomsBridge };
|
|
90
|
+
/** The rooms for clients (TaRoomServer): those of RoomsBridge, what goes wrong said as the errors of Ta. */
|
|
91
|
+
let TaRoomServerImpl = class TaRoomServerImpl {
|
|
92
|
+
get rooms() {
|
|
93
|
+
return this.bridge.rooms;
|
|
94
|
+
}
|
|
95
|
+
getIdentity() {
|
|
96
|
+
return TaErrors.guard(() => this.rooms.getIdentity());
|
|
97
|
+
}
|
|
98
|
+
setName(name) {
|
|
99
|
+
return TaErrors.guard(() => this.rooms.setName(name));
|
|
100
|
+
}
|
|
101
|
+
listRooms() {
|
|
102
|
+
return TaErrors.guard(() => this.rooms.listRooms());
|
|
103
|
+
}
|
|
104
|
+
createRoom(input) {
|
|
105
|
+
return TaErrors.guard(() => this.rooms.createRoom(input));
|
|
106
|
+
}
|
|
107
|
+
invite(room, options) {
|
|
108
|
+
return TaErrors.guard(() => this.rooms.invite(room, options !== null && options !== void 0 ? options : undefined));
|
|
109
|
+
}
|
|
110
|
+
join(link) {
|
|
111
|
+
return TaErrors.guard(() => this.rooms.join(link));
|
|
112
|
+
}
|
|
113
|
+
listRequests() {
|
|
114
|
+
return TaErrors.guard(() => this.rooms.listRequests());
|
|
115
|
+
}
|
|
116
|
+
answer(room, ask, accept) {
|
|
117
|
+
return TaErrors.guard(() => this.rooms.answer(room, ask, accept === true));
|
|
118
|
+
}
|
|
119
|
+
removeMember(room, member) {
|
|
120
|
+
return TaErrors.guard(() => this.rooms.removeMember(room, member));
|
|
121
|
+
}
|
|
122
|
+
leave(room) {
|
|
123
|
+
return TaErrors.guard(() => this.rooms.leave(room));
|
|
124
|
+
}
|
|
125
|
+
send(room, data, to) {
|
|
126
|
+
return TaErrors.guard(() => this.rooms.send(room, data, to !== null && to !== void 0 ? to : undefined));
|
|
127
|
+
}
|
|
128
|
+
getState(room, prefix) {
|
|
129
|
+
return TaErrors.guard(() => this.rooms.getState(room, prefix !== null && prefix !== void 0 ? prefix : undefined));
|
|
130
|
+
}
|
|
131
|
+
setState(room, key, value, version) {
|
|
132
|
+
return TaErrors.guard(() => this.rooms.setState(room, key, value, version !== null && version !== void 0 ? version : undefined));
|
|
133
|
+
}
|
|
134
|
+
listFriends() {
|
|
135
|
+
return TaErrors.guard(() => this.rooms.listFriends());
|
|
136
|
+
}
|
|
137
|
+
removeFriend(id) {
|
|
138
|
+
return TaErrors.guard(() => this.rooms.removeFriend(id));
|
|
139
|
+
}
|
|
140
|
+
async watch(messages, state) {
|
|
141
|
+
this.bridge.watch(RpcContext.requireConnection(), TaRoomWatchUtil.of(messages !== null && messages !== void 0 ? messages : undefined, state));
|
|
142
|
+
}
|
|
143
|
+
async unwatch() {
|
|
144
|
+
this.bridge.watch(RpcContext.requireConnection(), undefined);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
__decorate([
|
|
148
|
+
Autowired(ROOMS_BRIDGE),
|
|
149
|
+
__metadata("design:type", RoomsBridge)
|
|
150
|
+
], TaRoomServerImpl.prototype, "bridge", void 0);
|
|
151
|
+
TaRoomServerImpl = __decorate([
|
|
152
|
+
Rpc(TaRoomServer)
|
|
153
|
+
], TaRoomServerImpl);
|
|
154
|
+
export { TaRoomServerImpl };
|
|
155
|
+
//# sourceMappingURL=rooms-bridge.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
|
|
2
|
-
import type { TaSavedSessionInfo } from '@celljs/ta-protocol';
|
|
2
|
+
import type { TaSavedSessionInfo, TaSavedSessionQuery } from '@celljs/ta-protocol';
|
|
3
3
|
import { TaSessionCatalog } from './host-protocol.js';
|
|
4
4
|
import { PiDirectories } from './remote/remote-protocol.js';
|
|
5
5
|
/** What a list shows of a session file, with the directory pi worked in, before it is a location. */
|
|
@@ -60,10 +60,14 @@ export declare class DefaultTaSessionCatalog implements TaSessionCatalog {
|
|
|
60
60
|
version: string;
|
|
61
61
|
summary?: SessionSummary;
|
|
62
62
|
}>;
|
|
63
|
-
list(open?: ReadonlySet<string
|
|
63
|
+
list(open?: ReadonlySet<string>, query?: TaSavedSessionQuery): Promise<TaSavedSessionInfo[]>;
|
|
64
64
|
/** Where pi keeps the sessions it creates (SessionManager.create without a directory). */
|
|
65
65
|
protected sessionsDir(): Promise<string>;
|
|
66
66
|
protected files(root: string): Promise<string[]>;
|
|
67
|
-
|
|
67
|
+
/**
|
|
68
|
+
* What the file holds; undefined, without reading it, when it was last written before `since`: its last
|
|
69
|
+
* message came before then too, and a list of a window leaves it out (an archive of thousands is not read).
|
|
70
|
+
*/
|
|
71
|
+
protected summary(file: string, since?: number): Promise<SessionSummary | undefined>;
|
|
68
72
|
}
|
|
69
73
|
export {};
|
|
@@ -146,15 +146,16 @@ let DefaultTaSessionCatalog = class DefaultTaSessionCatalog {
|
|
|
146
146
|
/** By file: its size and time when read, and what it held. */
|
|
147
147
|
this.cache = new Map();
|
|
148
148
|
}
|
|
149
|
-
async list(open = new Set()) {
|
|
149
|
+
async list(open = new Set(), query = {}) {
|
|
150
150
|
const files = await this.files(await this.sessionsDir());
|
|
151
151
|
// An open session's file grows with every message: it is not read again for a list that leaves it out.
|
|
152
152
|
const closed = files.filter(file => !open.has(file));
|
|
153
|
+
const { since, before } = query;
|
|
153
154
|
const sessions = [];
|
|
154
155
|
for (let i = 0; i < closed.length; i += BATCH) {
|
|
155
156
|
await Promise.all(closed.slice(i, i + BATCH).map(async (file) => {
|
|
156
|
-
const summary = await this.summary(file);
|
|
157
|
-
if (summary) {
|
|
157
|
+
const summary = await this.summary(file, since);
|
|
158
|
+
if (summary && (since === undefined || summary.updatedAt >= since) && (before === undefined || summary.updatedAt < before)) {
|
|
158
159
|
const { piCwd, ...info } = summary;
|
|
159
160
|
sessions.push({ ...info, sessionFile: file, cwd: piCwd && this.directories.fromPi(piCwd) });
|
|
160
161
|
}
|
|
@@ -185,7 +186,11 @@ let DefaultTaSessionCatalog = class DefaultTaSessionCatalog {
|
|
|
185
186
|
}));
|
|
186
187
|
return files.flat();
|
|
187
188
|
}
|
|
188
|
-
|
|
189
|
+
/**
|
|
190
|
+
* What the file holds; undefined, without reading it, when it was last written before `since`: its last
|
|
191
|
+
* message came before then too, and a list of a window leaves it out (an archive of thousands is not read).
|
|
192
|
+
*/
|
|
193
|
+
async summary(file, since) {
|
|
189
194
|
const stats = await stat(file).catch(() => undefined);
|
|
190
195
|
if (!(stats === null || stats === void 0 ? void 0 : stats.isFile())) {
|
|
191
196
|
return undefined;
|
|
@@ -195,6 +200,9 @@ let DefaultTaSessionCatalog = class DefaultTaSessionCatalog {
|
|
|
195
200
|
if ((cached === null || cached === void 0 ? void 0 : cached.version) === version) {
|
|
196
201
|
return cached.summary;
|
|
197
202
|
}
|
|
203
|
+
if (since !== undefined && stats.mtimeMs < since) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
198
206
|
const text = await readFile(file, 'utf8').catch(() => undefined);
|
|
199
207
|
const summary = text === undefined ? undefined : SessionCatalogUtil.summarize(text, stats.mtimeMs);
|
|
200
208
|
this.cache.set(file, { version, summary });
|
|
@@ -14,7 +14,8 @@ export declare namespace SessionInfoUtil {
|
|
|
14
14
|
/**
|
|
15
15
|
* The text of the last message of the user or the agent that has some, on one line and cut to a preview's
|
|
16
16
|
* length, as a messaging app shows the last thing said under its name: without its context, the marks of
|
|
17
|
-
* markdown at the start of its lines, and the thinking and tool calls of the agent
|
|
17
|
+
* markdown at the start of its lines, and the thinking and tool calls of the agent; a skill the user ran is
|
|
18
|
+
* `/skill:name` and what follows, as the title says it, not the skill's file.
|
|
18
19
|
*/
|
|
19
20
|
function lastMessage(messages: readonly MessageLike[]): string | undefined;
|
|
20
21
|
/** The time of the last message that has one, else `fallback`. */
|
|
@@ -14,9 +14,7 @@ export var SessionInfoUtil;
|
|
|
14
14
|
if (message.role !== 'user') {
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
const skill = TaSkillUse.parse(said);
|
|
19
|
-
const line = (skill ? TaSkillUse.command(skill) : said)
|
|
17
|
+
const line = userWords(text(message.content))
|
|
20
18
|
.split('\n')
|
|
21
19
|
.map(part => part.trim())
|
|
22
20
|
.find(Boolean);
|
|
@@ -30,7 +28,8 @@ export var SessionInfoUtil;
|
|
|
30
28
|
/**
|
|
31
29
|
* The text of the last message of the user or the agent that has some, on one line and cut to a preview's
|
|
32
30
|
* length, as a messaging app shows the last thing said under its name: without its context, the marks of
|
|
33
|
-
* markdown at the start of its lines, and the thinking and tool calls of the agent
|
|
31
|
+
* markdown at the start of its lines, and the thinking and tool calls of the agent; a skill the user ran is
|
|
32
|
+
* `/skill:name` and what follows, as the title says it, not the skill's file.
|
|
34
33
|
*/
|
|
35
34
|
function lastMessage(messages) {
|
|
36
35
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
@@ -38,10 +37,10 @@ export var SessionInfoUtil;
|
|
|
38
37
|
if (message.role !== 'user' && message.role !== 'assistant') {
|
|
39
38
|
continue;
|
|
40
39
|
}
|
|
41
|
-
const said = message.role === 'user' ?
|
|
40
|
+
const said = message.role === 'user' ? userWords(text(message.content)) : TaAgentSummary.strip(text(message.content));
|
|
42
41
|
// A list asks for it every few seconds: only the start of a long reply is read, enough for a preview.
|
|
43
|
-
const
|
|
44
|
-
|
|
42
|
+
const read = said.slice(0, PREVIEW_READ);
|
|
43
|
+
const line = (withoutFences(read) || read)
|
|
45
44
|
.split('\n')
|
|
46
45
|
.map(part => part
|
|
47
46
|
.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+\.\s+)/, '')
|
|
@@ -57,6 +56,34 @@ export var SessionInfoUtil;
|
|
|
57
56
|
return undefined;
|
|
58
57
|
}
|
|
59
58
|
SessionInfoUtil.lastMessage = lastMessage;
|
|
59
|
+
/**
|
|
60
|
+
* The text without its fenced blocks, as a messenger says no more than [code] of them: code, and the cards a
|
|
61
|
+
* reply draws (a card's language, as `ta-glance`), are not what was said.
|
|
62
|
+
*/
|
|
63
|
+
function withoutFences(text) {
|
|
64
|
+
var _a;
|
|
65
|
+
const kept = [];
|
|
66
|
+
let fence;
|
|
67
|
+
for (const line of text.split('\n')) {
|
|
68
|
+
const mark = (_a = /^\s*(`{3,}|~{3,})/.exec(line)) === null || _a === void 0 ? void 0 : _a[1];
|
|
69
|
+
if (!fence && mark) {
|
|
70
|
+
fence = mark;
|
|
71
|
+
}
|
|
72
|
+
else if (fence && mark && mark[0] === fence[0] && mark.length >= fence.length && !line.trim().slice(mark.length)) {
|
|
73
|
+
fence = undefined;
|
|
74
|
+
}
|
|
75
|
+
else if (!fence) {
|
|
76
|
+
kept.push(line);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return kept.join('\n').trim();
|
|
80
|
+
}
|
|
81
|
+
/** What the user typed of a message: without its context and pi's notes of images, a skill as `/skill:name` and what follows. */
|
|
82
|
+
function userWords(content) {
|
|
83
|
+
const said = TaImageNote.strip(TaMessageContext.strip(content));
|
|
84
|
+
const skill = TaSkillUse.parse(said);
|
|
85
|
+
return skill ? TaSkillUse.command(skill) : said;
|
|
86
|
+
}
|
|
60
87
|
/** The time of the last message that has one, else `fallback`. */
|
|
61
88
|
function updatedAt(messages, fallback) {
|
|
62
89
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RpcConnection } from '@celljs/rpc/lib/node';
|
|
2
|
+
import { type TaSessionInfo } from '@celljs/ta-protocol';
|
|
3
|
+
/** At most one list per connection in this time, the latest; the first change leaves at once. */
|
|
4
|
+
export declare const SESSION_LIST_MS = 250;
|
|
5
|
+
interface Watcher {
|
|
6
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
7
|
+
lastAt: number;
|
|
8
|
+
/** The list it was sent last, as JSON: the same again is not sent. */
|
|
9
|
+
sent?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The open sessions told to the connections that watch them (TaServer.watchSessions): the whole list each time
|
|
13
|
+
* what a list shows of it changes, so that every page shows the same at once, rather than what it read a few
|
|
14
|
+
* seconds before. A session streams hundreds of events a second, of which few change the list: those come
|
|
15
|
+
* here (`changed`), and a moment of them leaves as one list, only when it differs from the one sent.
|
|
16
|
+
*/
|
|
17
|
+
export declare class SessionListFeed {
|
|
18
|
+
protected readonly list: () => TaSessionInfo[];
|
|
19
|
+
protected readonly intervalMs: number;
|
|
20
|
+
protected readonly watchers: Map<RpcConnection, Watcher>;
|
|
21
|
+
constructor(list: () => TaSessionInfo[], intervalMs?: number);
|
|
22
|
+
/** The list now; the connection is told of each change from now on, until it closes. */
|
|
23
|
+
watch(connection: RpcConnection): TaSessionInfo[];
|
|
24
|
+
/** What a list shows changed: a session opened or closed, or one of them changed. */
|
|
25
|
+
changed(): void;
|
|
26
|
+
protected schedule(connection: RpcConnection, watcher: Watcher): void;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TaClient } from '@celljs/ta-protocol';
|
|
2
|
+
/** At most one list per connection in this time, the latest; the first change leaves at once. */
|
|
3
|
+
export const SESSION_LIST_MS = 250;
|
|
4
|
+
/**
|
|
5
|
+
* The open sessions told to the connections that watch them (TaServer.watchSessions): the whole list each time
|
|
6
|
+
* what a list shows of it changes, so that every page shows the same at once, rather than what it read a few
|
|
7
|
+
* seconds before. A session streams hundreds of events a second, of which few change the list: those come
|
|
8
|
+
* here (`changed`), and a moment of them leaves as one list, only when it differs from the one sent.
|
|
9
|
+
*/
|
|
10
|
+
export class SessionListFeed {
|
|
11
|
+
constructor(list, intervalMs = SESSION_LIST_MS) {
|
|
12
|
+
this.list = list;
|
|
13
|
+
this.intervalMs = intervalMs;
|
|
14
|
+
this.watchers = new Map();
|
|
15
|
+
}
|
|
16
|
+
/** The list now; the connection is told of each change from now on, until it closes. */
|
|
17
|
+
watch(connection) {
|
|
18
|
+
const list = this.list();
|
|
19
|
+
let watcher = this.watchers.get(connection);
|
|
20
|
+
if (!watcher) {
|
|
21
|
+
const created = { lastAt: Number.NEGATIVE_INFINITY };
|
|
22
|
+
this.watchers.set(connection, created);
|
|
23
|
+
connection.onClose(() => {
|
|
24
|
+
clearTimeout(created.timer);
|
|
25
|
+
this.watchers.delete(connection);
|
|
26
|
+
});
|
|
27
|
+
watcher = created;
|
|
28
|
+
}
|
|
29
|
+
watcher.sent = JSON.stringify(list);
|
|
30
|
+
return list;
|
|
31
|
+
}
|
|
32
|
+
/** What a list shows changed: a session opened or closed, or one of them changed. */
|
|
33
|
+
changed() {
|
|
34
|
+
for (const [connection, watcher] of this.watchers) {
|
|
35
|
+
this.schedule(connection, watcher);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
schedule(connection, watcher) {
|
|
39
|
+
if (watcher.timer !== undefined) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const wait = Math.max(0, watcher.lastAt + this.intervalMs - performance.now());
|
|
43
|
+
watcher.timer = setTimeout(() => {
|
|
44
|
+
watcher.timer = undefined;
|
|
45
|
+
watcher.lastAt = performance.now();
|
|
46
|
+
if (connection.closed) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const list = this.list();
|
|
50
|
+
const json = JSON.stringify(list);
|
|
51
|
+
if (json === watcher.sent) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
watcher.sent = json;
|
|
55
|
+
connection
|
|
56
|
+
.client(TaClient)
|
|
57
|
+
.onSessions(list)
|
|
58
|
+
.catch(() => undefined);
|
|
59
|
+
}, wait);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=session-list-feed.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { IncomingMessage } from 'node:http';
|
|
2
2
|
import type { AccessStore } from './access-store.js';
|
|
3
3
|
import { type SignInAccount, type SignInProvider } from './sign-in-provider.js';
|
|
4
|
+
/** Sign-ins under way at most: anyone may start one without a token, and each is kept until it ends or expires. */
|
|
5
|
+
export declare const MAX_PENDING_SIGN_INS = 1000;
|
|
4
6
|
interface Pending {
|
|
5
7
|
provider: string;
|
|
6
8
|
verifier: string;
|
|
@@ -4,6 +4,8 @@ import { SignInError } from './sign-in-provider.js';
|
|
|
4
4
|
/** How long the browser has with the provider, and a link of {@link SignInFlow.bindUrl}. */
|
|
5
5
|
const PENDING_TTL_MS = 10 * 60 * 1000;
|
|
6
6
|
const BIND_TTL_MS = 5 * 60 * 1000;
|
|
7
|
+
/** Sign-ins under way at most: anyone may start one without a token, and each is kept until it ends or expires. */
|
|
8
|
+
export const MAX_PENDING_SIGN_INS = 1000;
|
|
7
9
|
export var SignInUtil;
|
|
8
10
|
(function (SignInUtil) {
|
|
9
11
|
/**
|
|
@@ -64,6 +66,13 @@ export class SignInFlow {
|
|
|
64
66
|
if (bind) {
|
|
65
67
|
this.binds.delete(bind);
|
|
66
68
|
}
|
|
69
|
+
// The oldest goes first: a flood of starts takes no more memory, and costs only sign-ins as old.
|
|
70
|
+
for (const oldest of this.pending.keys()) {
|
|
71
|
+
if (this.pending.size < MAX_PENDING_SIGN_INS) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
this.pending.delete(oldest);
|
|
75
|
+
}
|
|
67
76
|
const state = randomBytes(18).toString('base64url');
|
|
68
77
|
const { verifier, challenge } = SignInUtil.pkce();
|
|
69
78
|
const redirectUri = SignInUtil.redirectUri(origin, provider.id);
|
|
@@ -130,8 +130,9 @@ export class OidcSignIn {
|
|
|
130
130
|
throw new SignInError(`${this.name}: ${(_b = (_a = token.error_description) !== null && _a !== void 0 ? _a : token.error) !== null && _b !== void 0 ? _b : 'no access token'}`);
|
|
131
131
|
}
|
|
132
132
|
const user = await SignInHttp.json(userinfo_endpoint, { headers: { Authorization: `Bearer ${token.access_token}`, Accept: 'application/json' } });
|
|
133
|
-
//
|
|
134
|
-
|
|
133
|
+
// Only an address the provider says it verified (some say "true" as a string): one it does not vouch for
|
|
134
|
+
// (no email_verified, as Microsoft Entra) may be any address the user typed, and would match TA_ALLOWED_USERS.
|
|
135
|
+
const email = user.email && (user.email_verified === true || user.email_verified === 'true') ? user.email : undefined;
|
|
135
136
|
if (!email && (this.options.requireEmail || !user.sub)) {
|
|
136
137
|
throw new SignInError(`${this.name}: the account has no verified email address`);
|
|
137
138
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { TaSlashCommand } from '@celljs/ta-protocol';
|
|
2
|
+
type Descriptions = Readonly<Record<string, string>>;
|
|
3
|
+
type SourceInfo = TaSlashCommand['sourceInfo'];
|
|
4
|
+
/** What the `/` menu lists, as pi has them: commands of extensions by the names they are run by, prompt templates, skills. */
|
|
5
|
+
export interface SlashCommandSources {
|
|
6
|
+
commands: readonly {
|
|
7
|
+
invocationName: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
sourceInfo: SourceInfo;
|
|
10
|
+
}[];
|
|
11
|
+
prompts: readonly {
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
sourceInfo: SourceInfo;
|
|
15
|
+
}[];
|
|
16
|
+
skills: readonly {
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
sourceInfo: SourceInfo;
|
|
20
|
+
}[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The descriptions in other languages of the commands of the `/` menu: `pi.descriptions` of the package.json
|
|
24
|
+
* of the package each command or skill comes from, by its name there (`loop`, `skill:ta-game`), each a
|
|
25
|
+
* string by language (`{ "zh-CN": "…" }`). The package is the nearest directory up from its file with a package.json.
|
|
26
|
+
*/
|
|
27
|
+
export declare namespace SlashCommandUtil {
|
|
28
|
+
/** The commands of the `/` menu, in pi's order (its `get_commands`), with their descriptions in other languages. */
|
|
29
|
+
function list({ commands, prompts, skills }: SlashCommandSources): TaSlashCommand[];
|
|
30
|
+
/**
|
|
31
|
+
* The names the commands of extensions are run by, as pi's extension runner gives them: a name two
|
|
32
|
+
* extensions register is `name:1`, `name:2`, in the order the extensions loaded.
|
|
33
|
+
*/
|
|
34
|
+
function invocationNames<C extends {
|
|
35
|
+
name: string;
|
|
36
|
+
}>(commands: readonly C[]): (C & {
|
|
37
|
+
invocationName: string;
|
|
38
|
+
})[];
|
|
39
|
+
function withDescriptions(commands: readonly TaSlashCommand[]): TaSlashCommand[];
|
|
40
|
+
/** `pi.descriptions` of the package `directory` is in, with only what is text. */
|
|
41
|
+
function descriptionsOf(directory: string): Record<string, Descriptions> | undefined;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* The descriptions in other languages of the commands of the `/` menu: `pi.descriptions` of the package.json
|
|
5
|
+
* of the package each command or skill comes from, by its name there (`loop`, `skill:ta-game`), each a
|
|
6
|
+
* string by language (`{ "zh-CN": "…" }`). The package is the nearest directory up from its file with a package.json.
|
|
7
|
+
*/
|
|
8
|
+
export var SlashCommandUtil;
|
|
9
|
+
(function (SlashCommandUtil) {
|
|
10
|
+
/** The commands of the `/` menu, in pi's order (its `get_commands`), with their descriptions in other languages. */
|
|
11
|
+
function list({ commands, prompts, skills }) {
|
|
12
|
+
return withDescriptions([
|
|
13
|
+
...commands.map(c => ({ name: c.invocationName, description: c.description, source: 'extension', sourceInfo: c.sourceInfo })),
|
|
14
|
+
...prompts.map(p => ({ name: p.name, description: p.description, source: 'prompt', sourceInfo: p.sourceInfo })),
|
|
15
|
+
...skills.map(s => ({ name: `skill:${s.name}`, description: s.description, source: 'skill', sourceInfo: s.sourceInfo })),
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
SlashCommandUtil.list = list;
|
|
19
|
+
/**
|
|
20
|
+
* The names the commands of extensions are run by, as pi's extension runner gives them: a name two
|
|
21
|
+
* extensions register is `name:1`, `name:2`, in the order the extensions loaded.
|
|
22
|
+
*/
|
|
23
|
+
function invocationNames(commands) {
|
|
24
|
+
var _a;
|
|
25
|
+
const counts = new Map();
|
|
26
|
+
for (const command of commands) {
|
|
27
|
+
counts.set(command.name, ((_a = counts.get(command.name)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
28
|
+
}
|
|
29
|
+
const seen = new Map();
|
|
30
|
+
const taken = new Set();
|
|
31
|
+
return commands.map(command => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const occurrence = ((_a = seen.get(command.name)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
34
|
+
seen.set(command.name, occurrence);
|
|
35
|
+
let invocationName = ((_b = counts.get(command.name)) !== null && _b !== void 0 ? _b : 0) > 1 ? `${command.name}:${occurrence}` : command.name;
|
|
36
|
+
for (let suffix = occurrence; taken.has(invocationName);) {
|
|
37
|
+
suffix++;
|
|
38
|
+
invocationName = `${command.name}:${suffix}`;
|
|
39
|
+
}
|
|
40
|
+
taken.add(invocationName);
|
|
41
|
+
return { ...command, invocationName };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
SlashCommandUtil.invocationNames = invocationNames;
|
|
45
|
+
function withDescriptions(commands) {
|
|
46
|
+
const packages = new Map();
|
|
47
|
+
return commands.map(command => {
|
|
48
|
+
var _a;
|
|
49
|
+
const { path } = command.sourceInfo;
|
|
50
|
+
if (!isAbsolute(path)) {
|
|
51
|
+
return command;
|
|
52
|
+
}
|
|
53
|
+
const directory = dirname(path);
|
|
54
|
+
if (!packages.has(directory)) {
|
|
55
|
+
packages.set(directory, descriptionsOf(directory));
|
|
56
|
+
}
|
|
57
|
+
const descriptions = (_a = packages.get(directory)) === null || _a === void 0 ? void 0 : _a[command.name];
|
|
58
|
+
return descriptions ? { ...command, descriptions } : command;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
SlashCommandUtil.withDescriptions = withDescriptions;
|
|
62
|
+
/** `pi.descriptions` of the package `directory` is in, with only what is text. */
|
|
63
|
+
function descriptionsOf(directory) {
|
|
64
|
+
var _a, _b;
|
|
65
|
+
const root = packageRoot(directory);
|
|
66
|
+
if (!root) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
let declared;
|
|
70
|
+
try {
|
|
71
|
+
declared = (_b = (_a = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))) === null || _a === void 0 ? void 0 : _a.pi) === null || _b === void 0 ? void 0 : _b.descriptions;
|
|
72
|
+
}
|
|
73
|
+
catch (_c) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
if (!isRecord(declared)) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
const byName = {};
|
|
80
|
+
for (const [name, texts] of Object.entries(declared)) {
|
|
81
|
+
const languages = isRecord(texts)
|
|
82
|
+
? Object.entries(texts).filter((entry) => typeof entry[1] === 'string' && entry[1].trim() !== '')
|
|
83
|
+
: [];
|
|
84
|
+
if (languages.length > 0) {
|
|
85
|
+
byName[name] = Object.fromEntries(languages);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return byName;
|
|
89
|
+
}
|
|
90
|
+
SlashCommandUtil.descriptionsOf = descriptionsOf;
|
|
91
|
+
function packageRoot(directory) {
|
|
92
|
+
for (let current = directory;; current = dirname(current)) {
|
|
93
|
+
if (existsSync(join(current, 'package.json'))) {
|
|
94
|
+
return current;
|
|
95
|
+
}
|
|
96
|
+
if (dirname(current) === current) {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function isRecord(value) {
|
|
102
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
103
|
+
}
|
|
104
|
+
})(SlashCommandUtil || (SlashCommandUtil = {}));
|
|
105
|
+
//# sourceMappingURL=slash-command-util.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TaConversation, type TaEvent, type TaMessage } from '@celljs/ta-protocol';
|
|
2
2
|
type AgentSessionEvent = import('@earendil-works/pi-coding-agent', { with: { 'resolution-mode': 'import' } }).AgentSessionEvent;
|
|
3
3
|
export declare namespace TaEventUtil {
|
|
4
4
|
/**
|
|
@@ -15,7 +15,14 @@ export declare namespace TaEventUtil {
|
|
|
15
15
|
function leanMessage(message: TaMessage): TaMessage;
|
|
16
16
|
/** The result of a tool, or a message of one, without the bytes of its images. */
|
|
17
17
|
function leanResult<T>(result: T): T;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* A conversation as clients get it: its messages and the results of its calls lean, and the images of the
|
|
20
|
+
* messages of the user without their bytes but with their size (`TaShownImage`): they come with
|
|
21
|
+
* `getMessageImage` once shown, and a conversation with pictures opens as fast as one without. Events keep
|
|
22
|
+
* them: a message just sent shows on every device at once.
|
|
23
|
+
*/
|
|
19
24
|
function leanConversation(conversation: TaConversation): TaConversation;
|
|
25
|
+
/** A message as a page of the conversation gives it: `leanMessage`, and the images of the user's without their bytes. */
|
|
26
|
+
function leanShown(message: TaMessage): TaMessage;
|
|
20
27
|
}
|
|
21
28
|
export {};
|