gcf-board 0.16.5 → 0.16.9

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.
@@ -23,7 +23,7 @@ import { isUpload, saveUpload, UPLOAD_MAX } from './upload.js';
23
23
  import { addProject, listProjects, projectOf, removeProject } from './registry.js';
24
24
  import { allThemes } from './themes.js';
25
25
  import { adoptRuns, busyCheck, keepProjects, sweepRuns, closeReport, forgetProject, resumeQueue, runsOf, startRun, unqueue, } from './runs.js';
26
- import { acceptProposal, agentDefaults, agentPresets, chatCard, chatOf, designTalk, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, startTalk, stopTalk, talkEntry, talkId, talkLive, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
26
+ import { acceptProposal, agentDefaults, agentPresets, chatCard, chatOf, entryTalk, listTalks, openTalk, pickTalk, prepareTalk, startDesign, startTalk, stopTalk, talkEntry, talkId, talkLive, talkSaid, talkWaits, watchTalks, writeTalk, } from './talks.js';
27
27
  import { threadDir, threadOfEntry } from 'gcf-session';
28
28
  const send = (res, status, body) => {
29
29
  res.writeHead(status, { 'content-type': 'application/json; charset=utf-8' });
@@ -792,9 +792,7 @@ export function createApp(o) {
792
792
  throw new HttpError(409, 'the usage limit holds for the account: start after its reset');
793
793
  drafting.add(key);
794
794
  try {
795
- const { id, say } = designTalk(p, board, m[2], startGiven(body));
796
- await prepareTalk(p, board, id);
797
- await sendTalk(p, id, { type: 'say', text: say }, board);
795
+ const id = await startDesign(p, board, m[2], startGiven(body), (t, say) => sendTalk(p, t, { type: 'say', text: say }, board));
798
796
  broadcast({ type: 'talks', project: p.name });
799
797
  send(res, 201, { thread: id });
800
798
  }
@@ -7,7 +7,7 @@
7
7
  // and what became of them (AD-33) are in `proposals.json`.
8
8
  import { spawn, spawnSync } from 'node:child_process';
9
9
  import { randomBytes } from 'node:crypto';
10
- import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, statSync, writeFileSync, } from 'node:fs';
10
+ import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync, } from 'node:fs';
11
11
  import os from 'node:os';
12
12
  import path from 'node:path';
13
13
  import { fileURLToPath } from 'node:url';
@@ -335,10 +335,17 @@ export function designTalk(p, board, start, given) {
335
335
  const t = createThread(p.path, { start: { id: start } });
336
336
  let file = '';
337
337
  if (given.file && name) {
338
- const att = path.join(writeDir(p, t), 'att');
339
- mkdirSync(att, { recursive: true });
340
- writeFileSync(path.join(att, name), given.file.text);
341
- file = path.relative(p.path, path.join(att, name)).replaceAll('\\', '/');
338
+ try {
339
+ const att = path.join(writeDir(p, t), 'att');
340
+ mkdirSync(att, { recursive: true });
341
+ writeFileSync(path.join(att, name), given.file.text);
342
+ file = path.relative(p.path, path.join(att, name)).replaceAll('\\', '/');
343
+ }
344
+ catch (e) {
345
+ // The GDD not kept: no thread stays for it, as for a first message that never went.
346
+ rmSync(dirOf(p, t), { recursive: true, force: true });
347
+ throw e;
348
+ }
342
349
  }
343
350
  const say = s.say
344
351
  .replaceAll('{file}', file)
@@ -347,6 +354,21 @@ export function designTalk(p, board, start, given) {
347
354
  .replaceAll('{text}', text);
348
355
  return { id: t, say };
349
356
  }
357
+ /**
358
+ * Design start `start` (designTalk), its first message sent by `send`: the thread's id. A send
359
+ * that fails takes the thread away with it, so no empty thread stays in the list.
360
+ */
361
+ export async function startDesign(p, board, start, given, send) {
362
+ const { id, say } = designTalk(p, board, start, given);
363
+ try {
364
+ await send(id, say);
365
+ }
366
+ catch (e) {
367
+ rmSync(dirOf(p, id), { recursive: true, force: true });
368
+ throw e;
369
+ }
370
+ return id;
371
+ }
350
372
  // A GDD's name kept in gcf/source/: the board's file route shows `[\w./-]` names only.
351
373
  const GDD_NAME = /^[\w][\w.-]*\.md$/;
352
374
  /**