gcf-board 0.8.1 → 0.9.1
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 +106 -104
- package/dist/server/app.js +143 -14
- package/dist/server/chat.js +21 -9
- package/dist/server/cli.js +5 -0
- package/dist/server/files.js +17 -0
- package/dist/server/runs.js +22 -6
- package/dist/server/talks.js +22 -1
- package/dist/web/assets/index-UzVgbCWq.css +1 -0
- package/dist/web/assets/index-m10Wkvhe.js +39 -0
- package/dist/web/index.html +2 -2
- package/node_modules/gcf-session/lib/chat.js +9 -4
- package/node_modules/gcf-session/lib/index.js +1 -0
- package/node_modules/gcf-session/lib/thread.js +78 -24
- package/node_modules/gcf-session/package.json +1 -1
- package/node_modules/gcf-session/types/index.d.ts +9 -2
- package/package.json +1 -1
- package/dist/web/assets/index-C56_xyF9.js +0 -39
- package/dist/web/assets/index-D0-5TaR1.css +0 -1
package/dist/web/index.html
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>GCF board</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-m10Wkvhe.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="/assets/index-UzVgbCWq.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
|
@@ -311,12 +311,17 @@ function imagesOf(c, paths) {
|
|
|
311
311
|
* engine. An input line's message has its `paths` (pictures), its `id` (which its `say` event
|
|
312
312
|
* carries, AD-35), its `entry` in the input, and `retry` when an earlier session took it.
|
|
313
313
|
* Returns whether it went: a closing session or a missing picture refuses it.
|
|
314
|
-
*
|
|
314
|
+
* `own`: the operator's own words, when a prefix goes before them.
|
|
315
|
+
* @param {{paths?: string[], id?: string, entry?: any, retry?: boolean, own?: string}} [m]
|
|
315
316
|
*/
|
|
316
317
|
function say(c, text, by, m = {}) {
|
|
317
|
-
const { paths = [], id, entry = null, retry } = m;
|
|
318
|
+
const { paths = [], id, entry = null, retry, own = text } = m;
|
|
318
319
|
const refused = (why) => {
|
|
319
|
-
post(c, {
|
|
320
|
+
post(c, {
|
|
321
|
+
type: 'error',
|
|
322
|
+
text: `${why}, not sent: ${own.slice(0, 80)}`,
|
|
323
|
+
...(id ? { id } : {}),
|
|
324
|
+
});
|
|
320
325
|
|
|
321
326
|
return false;
|
|
322
327
|
};
|
|
@@ -380,7 +385,7 @@ function heard(c, e, m) {
|
|
|
380
385
|
const text = c.prefix ? `${c.prefix}\n\n${e.text}` : e.text;
|
|
381
386
|
const paths = Array.isArray(e.images) ? e.images : [];
|
|
382
387
|
// The context goes with the message that goes: a refused one leaves it for the next.
|
|
383
|
-
if (say(c, text, 'operator', { paths, id, ...m }) && c.prefix) {
|
|
388
|
+
if (say(c, text, 'operator', { paths, id, own: e.text, ...m }) && c.prefix) {
|
|
384
389
|
c.prefix = null;
|
|
385
390
|
c.onPrefix?.();
|
|
386
391
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
openSync,
|
|
13
13
|
readFileSync,
|
|
14
14
|
readdirSync,
|
|
15
|
+
renameSync,
|
|
15
16
|
rmSync,
|
|
16
17
|
writeFileSync,
|
|
17
18
|
} from 'node:fs';
|
|
@@ -70,11 +71,15 @@ const GIT_OPTS = String.raw`(?:(?:${GIT_OPT})\s+)*`;
|
|
|
70
71
|
const GIT_CHANGES = new RegExp(String.raw`\bgit\s+${GIT_OPTS}(?:${GIT_VERBS})\b`);
|
|
71
72
|
|
|
72
73
|
export const threadDir = (dir, t) => path.join(chatsDir(dir), t);
|
|
73
|
-
|
|
74
|
+
// A bound thread's mark: `chats/items/<item>` or `chats/entries/<entry>`, the thread's id.
|
|
75
|
+
const markOf = (dir, kind, key) => path.join(chatsDir(dir), kind, key);
|
|
74
76
|
|
|
75
|
-
/** The thread `t`'s record, `{id, item, sessions, created_at, in_at}
|
|
77
|
+
/** The thread `t`'s record, `{id, item, entry, sessions, created_at, in_at}`; no `entry`: null. */
|
|
76
78
|
export function readThread(dir, t) {
|
|
77
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
entry: null,
|
|
81
|
+
...JSON.parse(readFileSync(path.join(threadDir(dir, t), 'thread.json'), 'utf8')),
|
|
82
|
+
};
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
const writeThread = (dir, t, rec) =>
|
|
@@ -142,10 +147,10 @@ export function setThreadAgent(dir, t, pick) {
|
|
|
142
147
|
return kept;
|
|
143
148
|
}
|
|
144
149
|
|
|
145
|
-
/** The thread
|
|
146
|
-
|
|
150
|
+
/** The thread of mark `kind/key`, or null. */
|
|
151
|
+
function boundTo(dir, kind, key) {
|
|
147
152
|
try {
|
|
148
|
-
const t = readFileSync(
|
|
153
|
+
const t = readFileSync(markOf(dir, kind, key), 'utf8').trim();
|
|
149
154
|
|
|
150
155
|
return THREAD_ID.test(t) && existsSync(threadDir(dir, t)) ? t : null;
|
|
151
156
|
} catch {
|
|
@@ -153,26 +158,71 @@ export function threadOf(dir, item) {
|
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
|
|
161
|
+
/** The thread bound to `item`, or null (AD-46). */
|
|
162
|
+
export const threadOf = (dir, item) => boundTo(dir, 'items', item);
|
|
163
|
+
|
|
164
|
+
/** The thread bound to inbox entry `entry` (Draft with agent), or null. */
|
|
165
|
+
export const threadOfEntry = (dir, entry) => boundTo(dir, 'entries', entry);
|
|
166
|
+
|
|
156
167
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
168
|
+
* Bind new thread `t` to `key`, exclusively: the thread that holds the mark, `t` when it took
|
|
169
|
+
* it. Taken by a thread made just now: that one, and `t` goes. A mark whose thread is gone (its
|
|
170
|
+
* folder erased by hand) is stale: `t` takes it over.
|
|
159
171
|
*/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
function takeMark(dir, kind, key, t) {
|
|
173
|
+
const had = markOnce(dir, [kind, key], t);
|
|
174
|
+
if (had) return had;
|
|
175
|
+
// A stale mark is moved aside under this thread's own name, then taken exclusively again: of
|
|
176
|
+
// two at once, the one whose move fails finds the other's mark on its last try.
|
|
177
|
+
// shortcut: a mark read between another's create and its write looks stale (empty); two boards
|
|
178
|
+
// on one project in that instant could still split a thread.
|
|
179
|
+
const aside = `${markOf(dir, kind, key)}.${t}`;
|
|
180
|
+
try {
|
|
181
|
+
renameSync(markOf(dir, kind, key), aside);
|
|
182
|
+
rmSync(aside, { force: true });
|
|
183
|
+
} catch {
|
|
184
|
+
// Moved by the other one: its mark wins below.
|
|
172
185
|
}
|
|
173
186
|
|
|
187
|
+
return markOnce(dir, [kind, key], t, true);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* One exclusive try at the mark: `t` when taken, the thread that holds it, or null for a stale
|
|
192
|
+
* one (`last`: throw then). `t`'s folder goes when it does not get the mark.
|
|
193
|
+
*/
|
|
194
|
+
function markOnce(dir, [kind, key], t, last = false) {
|
|
195
|
+
try {
|
|
196
|
+
writeFileSync(markOf(dir, kind, key), t, { flag: 'wx' });
|
|
197
|
+
|
|
198
|
+
return t;
|
|
199
|
+
} catch (e) {
|
|
200
|
+
const taken = /** @type {any} */ (e).code === 'EEXIST';
|
|
201
|
+
const won = taken ? boundTo(dir, kind, key) : null;
|
|
202
|
+
if (!won && taken && !last) return null;
|
|
203
|
+
rmSync(threadDir(dir, t), { recursive: true, force: true });
|
|
204
|
+
if (won) return won;
|
|
205
|
+
throw e;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A new thread, its id; bound to `item` or to inbox `entry`, the one it already has (AD-46).
|
|
211
|
+
* Ids and the marks are made exclusively: two at once never take one id, nor give an item or an
|
|
212
|
+
* entry two threads. Both `item` and `entry` is a RangeError.
|
|
213
|
+
*/
|
|
214
|
+
export function createThread(dir, { item = null, entry = null } = {}) {
|
|
215
|
+
if (item && entry) throw new RangeError('a thread is bound to an item or an entry, not both');
|
|
216
|
+
const [kind, key] = item ? ['items', item] : ['entries', entry];
|
|
217
|
+
const had = key ? boundTo(dir, kind, key) : null;
|
|
218
|
+
if (had) return had;
|
|
219
|
+
mkdirSync(path.join(chatsDir(dir), kind), { recursive: true });
|
|
220
|
+
const t = newDir(dir);
|
|
221
|
+
const won = key ? takeMark(dir, kind, key, t) : t;
|
|
222
|
+
if (won !== t) return won;
|
|
223
|
+
|
|
174
224
|
const now = new Date().toISOString();
|
|
175
|
-
writeThread(dir, t, { id: t, item, sessions: [], created_at: now, in_at: 0 });
|
|
225
|
+
writeThread(dir, t, { id: t, item, entry, sessions: [], created_at: now, in_at: 0 });
|
|
176
226
|
|
|
177
227
|
return t;
|
|
178
228
|
}
|
|
@@ -344,7 +394,7 @@ function closed(s) {
|
|
|
344
394
|
try {
|
|
345
395
|
const e = JSON.parse(l);
|
|
346
396
|
|
|
347
|
-
return e?.type === 'say' ? [String(e.text ?? '').slice(0, 80)] : [];
|
|
397
|
+
return e?.type === 'say' ? [{ text: String(e.text ?? '').slice(0, 80), id: e.id }] : [];
|
|
348
398
|
} catch {
|
|
349
399
|
return [];
|
|
350
400
|
}
|
|
@@ -362,8 +412,12 @@ function closed(s) {
|
|
|
362
412
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 200);
|
|
363
413
|
}
|
|
364
414
|
|
|
365
|
-
for (const text of says)
|
|
366
|
-
postTo(out, {
|
|
415
|
+
for (const { text, id } of says)
|
|
416
|
+
postTo(out, {
|
|
417
|
+
type: 'error',
|
|
418
|
+
text: `the agent was closed, not sent: ${text}`,
|
|
419
|
+
...(typeof id === 'string' ? { id } : {}),
|
|
420
|
+
});
|
|
367
421
|
postTo(out, { type: 'closed', dropped: says.length });
|
|
368
422
|
}
|
|
369
423
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gcf-session",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "The session engine of GCF: one agent session and a run as a chain of them, the chat protocol, the provider adapters. Bundled by gcf-harness-aif-ext and gcf-board, never published.",
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,8 @@ export type ChatEvent = At &
|
|
|
43
43
|
| { type: 'waiting'; kind: 'card' | 'text' | 'stop' }
|
|
44
44
|
| { type: 'timeout'; kind: 'card' | 'text' }
|
|
45
45
|
| { type: 'interrupt' }
|
|
46
|
-
|
|
46
|
+
/** `id`: the input line of the operator's message it did not send, when it has one. */
|
|
47
|
+
| { type: 'error'; text: string; id?: string }
|
|
47
48
|
| { type: 'background'; tasks: { id: string; description: string }[] }
|
|
48
49
|
| {
|
|
49
50
|
type: 'question';
|
|
@@ -131,6 +132,8 @@ export interface Rule {
|
|
|
131
132
|
export interface Thread {
|
|
132
133
|
id: string;
|
|
133
134
|
item: string | null;
|
|
135
|
+
/** The inbox entry the thread drafts an item from (Draft with agent); null for none. */
|
|
136
|
+
entry: string | null;
|
|
134
137
|
sessions: { session_id?: string; ended: string; kind: string; summary?: string }[];
|
|
135
138
|
created_at: string;
|
|
136
139
|
in_at: number;
|
|
@@ -168,8 +171,12 @@ export declare function setThreadAgent(
|
|
|
168
171
|
pick: { model?: string | null; effort?: string | null },
|
|
169
172
|
): AgentPick;
|
|
170
173
|
export declare function presetsOf(agent: string): AgentPresets;
|
|
171
|
-
export declare function createThread(
|
|
174
|
+
export declare function createThread(
|
|
175
|
+
dir: string,
|
|
176
|
+
opts?: { item?: string | null; entry?: string | null },
|
|
177
|
+
): string;
|
|
172
178
|
export declare function threadOf(dir: string, item: string): string | null;
|
|
179
|
+
export declare function threadOfEntry(dir: string, entry: string): string | null;
|
|
173
180
|
export declare function threadDir(dir: string, t: string): string;
|
|
174
181
|
export declare function readThread(dir: string, t: string): Thread;
|
|
175
182
|
export declare function listThreads(dir: string): Thread[];
|
package/package.json
CHANGED