@adelin-io/cli 0.1.6 → 0.1.8

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.
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "packageName": "@adelin-io/cli",
4
- "version": "0.1.6",
4
+ "version": "0.1.8",
5
5
  "compilerVersion": "6.0.3",
6
6
  "hostProtocol": 1,
7
7
  "files": {
8
8
  "skill/README.md": "6b96a61882b5a8de3982c7a235ef9f056b8e9f1b33b56e223dd1af9e3b8d6c85",
9
- "skill/SKILL.md": "1981e2e97b4ac4f4464c8a9411fb5f93ed9ec9cfa51f14fbad2a354205cadf27",
9
+ "skill/SKILL.md": "2c04692018ff39bad43c7024619a8fe708bae0f197b132ba9fc392b6f6047dd4",
10
10
  "skill/authoring/access.md": "06de3c7bdd3085ba69e9965e76d8ce0566df8a15c7619a5b887495d7c6ee9335",
11
11
  "skill/authoring/analytics.md": "d6292c05e1981ca233621541941006d10cef8454f87844b21d44dcecdf94067f",
12
- "skill/authoring/app-memory.md": "f664c2c5ae849424eb49a2d0adb2648bf5af19fc5a07145a6f74fb949bb2b917",
12
+ "skill/authoring/app-memory.md": "8e11505eac37ca675cc451aba881d81ec92867e2e8297c17c9a1b4669e6da446",
13
13
  "skill/authoring/app-requirements.md": "294a1542691b189e9fef8423ef67c0fe2dbbf20152cc912ebe16115995c8ab7a",
14
14
  "skill/authoring/app-structure.md": "c8e067e80c365c45cd523739436d74099ec36c3991c427117aa3110414b53355",
15
- "skill/authoring/assets.md": "e2ee01420acb60f61202fdb757b5fae9785afc609768122879b17265b3b95cd4",
15
+ "skill/authoring/assets.md": "3e2976d69d344d304a4668dbf969c57c0c13d3171de34151b213fef934b33973",
16
16
  "skill/authoring/auth.md": "1af2c3affd7ee61928daeb5248494dd9c9b9e0e25a3069b1073812d18597f2fb",
17
17
  "skill/authoring/content-binding.md": "124090ebdd6011bdd7c5f9c94f715ab15ad2af7741fae90fc5d3e2c7a2f442a8",
18
18
  "skill/authoring/i18n.md": "a264167e27b9ea02c76647146601ee0d1d9a83e9d33d7cd60d9d0b39d9ee1f60",
19
19
  "skill/authoring/language.md": "533d597b785f6df99234f7e83be80d8ea1818cd24062b4f51ec5e4091a2db393",
20
- "skill/authoring/local-workflow.md": "9a989715d7a84c7a6520009cf9a2eeff532efbe051085a702ae93d6f29e0b6d9",
20
+ "skill/authoring/local-workflow.md": "4b34f0551bdb1c5ea00de453e4895016a360a0518f87276d498de42c1497f3a8",
21
21
  "skill/authoring/offline/connectivity.md": "e00cb804cfdcda2950cb190432e8f36cd13d99b36075b5ceec71438671393e81",
22
22
  "skill/authoring/offline/example.md": "2e79d91f05d7a55b4a3f136f0db28d02e458c9fc24b77ab0e074fff7ab635447",
23
23
  "skill/authoring/offline/history-sync.md": "65652b536a84c47ddf04519e3dac35a9bed836fba67043fd43dabd77af3cd3ec",
@@ -47,7 +47,7 @@
47
47
  "skill/design/design-guide.md": "cc981df68755971801f826532c16d4aa15c1c3b0c09638d99dba1714c165302f",
48
48
  "skill/design/edge-to-edge.md": "d163b0e3ae393377546508d7eab0d44cfab139d022a360e993a734c73394119e",
49
49
  "skill/design/icons.md": "c3c6dfc57d2d346dac34ef6f876371943ed36e810730edc224196bc967da9248",
50
- "skill/design/responsive-layout.md": "c83763be82e29ec16799256aa4a0d8e4570bce117b1a29d6d90ca3c98ccf7449",
50
+ "skill/design/responsive-layout.md": "8fce1fa378731f1ed5c795cdb72a73dae4b2e3581861a90c14fc3f5ae634b51b",
51
51
  "skill/design/safe-area.md": "a6522b995454adb2d459a4651086c108d5d9b2399f9399e40c6d320237947820",
52
52
  "skill/design/streaming-playbook.md": "13bcab8d9232d6514337fcd112022968011db895b1aed66f7976bd3bc81c83d5",
53
53
  "skill/design/visual-review.md": "87d5025a7a365656cbbb1a1eac817b69eb0f066c812d0a94322d7a02c6b3207a",
@@ -145,7 +145,7 @@
145
145
  "skill/reference/components.md": "447e9d1c1c476095c73f2470d9a49bdd9973e7419aca9b580422ba28a3b2da5b",
146
146
  "skill/reference/packages.md": "4811247543f11bf3776e1d4217e7558f8a226efd8f144b09e2956aed1453fc39",
147
147
  "skill/scripts/assemble-checkout.mjs": "3f35e00a76075b3b0e8c72b5477184a986b15ae1e933317ceaad9a08cbeb589c",
148
- "skill/scripts/local-save.mjs": "c8b4f81ffdf2bbc87d47edf4f97438b4381fe9b10a98c9ba28e288c5fe6d7eed",
148
+ "skill/scripts/local-save.mjs": "54f9532d57cb9dd754bbaa4d517c8a3229c2ea6fbe43236bdc15fda2822cde9f",
149
149
  "skill/scripts/materialize.mjs": "8c00ec43de43698c5d7ef918e6d2f0c2f4eb01c51172b67ea36f7544cfe5b03f",
150
150
  "skill/scripts/workspace-state.mjs": "e8a2a8d85ac0add04a5a19fcb20183cdc0929387c4487f7747b81baa1ae2ecff",
151
151
  "types/adelin-access.d.ts": "80933fc8c2c2ac80f3769bb3358c754675c9bc68eb893dd292a8bd589d984dc1",
@@ -170,5 +170,5 @@
170
170
  "types/adelin-worklets.d.ts": "f56edc56715df189933f180605ee8c41a785d11ad0c0d454258f1c1f71159ab9",
171
171
  "workspace-tsconfig.json": "a1321a0ea06e5fb9d4e3c1a7d92045e730b44114ab10553172142cb978b9147a"
172
172
  },
173
- "contractId": "ac1c6146c29893957efa89a9c96a60870ceccc09bca4f408ff1ca2ec92cfc686"
173
+ "contractId": "dcfca25ac8ebdc6c85e3a820833af53d51d595f02df824223b937818c600eec8"
174
174
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adelin-io/cli",
3
3
  "private": false,
4
- "version": "0.1.6",
4
+ "version": "0.1.8",
5
5
  "description": "Adelin CLI, local app builder, and agent skill",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,9 +1,9 @@
1
1
  {
2
- "scripts/adelin.mjs": "0f32c49e80aade2bec981bed622292bfebc819c25bc0a38fbf9582850426f6da",
2
+ "scripts/adelin.mjs": "db7b0a7327d788152e703f4b2e7d00e087e43b1f89b99fc06ed04d277245d7e8",
3
3
  "scripts/assemble-checkout.mjs": "3f35e00a76075b3b0e8c72b5477184a986b15ae1e933317ceaad9a08cbeb589c",
4
- "scripts/local-save.mjs": "c8b4f81ffdf2bbc87d47edf4f97438b4381fe9b10a98c9ba28e288c5fe6d7eed",
4
+ "scripts/local-save.mjs": "54f9532d57cb9dd754bbaa4d517c8a3229c2ea6fbe43236bdc15fda2822cde9f",
5
5
  "scripts/materialize.mjs": "8c00ec43de43698c5d7ef918e6d2f0c2f4eb01c51172b67ea36f7544cfe5b03f",
6
- "scripts/runtime.mjs": "311b6f780b0c2d1206bdd63013bc671420c60fd7f9a0985e233c953091260c2d",
6
+ "scripts/runtime.mjs": "5e62c0df5d4d5cd27daa634bae5ba95a7eef0007e76f853eff7a027d0063ab6c",
7
7
  "scripts/typecheck.mjs": "2ed3b248bd1d8f8152cda2a57f8975da39028e5eb63a7475678af6fc5117042c",
8
8
  "scripts/workspace-state.mjs": "e8a2a8d85ac0add04a5a19fcb20183cdc0929387c4487f7747b81baa1ae2ecff"
9
9
  }
@@ -44,6 +44,110 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
44
44
  mod
45
45
  ));
46
46
 
47
+ // skills/adelin-app-generation/scripts/cli-auth-page.mjs
48
+ function render({ tone, icon, title: title2, body, note: note2, retry, footer }) {
49
+ return `<!doctype html>
50
+ <html lang="en">
51
+ <head>
52
+ <meta charset="utf-8">
53
+ <meta name="viewport" content="width=device-width,initial-scale=1">
54
+ <title>${title2} | Adelin CLI</title>
55
+ <style>${STYLE}</style>
56
+ </head>
57
+ <body>
58
+ <div class="brand">${mark(36, "brand")}<span>Adelin</span></div>
59
+ <main>
60
+ <div class="link ${tone}" aria-hidden="true">
61
+ <span class="tile cli"><svg width="28" height="28" viewBox="0 0 24 24" stroke-width="2" ${STROKE}><path d="m5 7 5 5-5 5M13 17h6"/></svg></span>
62
+ <span class="line"></span><span class="dot"><svg width="20" height="20" viewBox="0 0 20 20" stroke-width="2.2" ${STROKE}><path d="${icon}"/></svg></span><span class="line"></span>
63
+ <span class="tile">${mark(36, "tile")}</span>
64
+ </div>
65
+ <div><h1>${title2}</h1><p>${body}</p></div>
66
+ ${note2 ? `<p class="note">${note2}</p>` : ""}${retry ? '<p class="retry">To try again, run <code>adelin login</code></p>' : ""}
67
+ </main>
68
+ ${footer ? `<footer>${footer}</footer>` : ""}
69
+ </body>
70
+ </html>
71
+ `;
72
+ }
73
+ function sendSignInPage(res, result) {
74
+ let page = PAGES[result];
75
+ return new Promise((resolve16) => {
76
+ if (res.destroyed) return resolve16();
77
+ res.once("close", resolve16), res.writeHead(page.status, {
78
+ "Content-Type": "text/html; charset=utf-8",
79
+ "Cache-Control": "no-store",
80
+ Connection: "close",
81
+ "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'"
82
+ }), res.end(render(page));
83
+ });
84
+ }
85
+ var CHECK, ALERT, PAGES, MARK, STROKE, STYLE, mark, init_cli_auth_page = __esm({
86
+ "skills/adelin-app-generation/scripts/cli-auth-page.mjs"() {
87
+ CHECK = "m4.5 10.5 3.5 3.5 7.5-8", ALERT = "M10 4.5v6.5M10 15v.1", PAGES = {
88
+ complete: {
89
+ status: 200,
90
+ tone: "ok",
91
+ icon: CHECK,
92
+ title: "You're signed in",
93
+ body: "Adelin CLI is connected. Return to your terminal to continue.",
94
+ note: "You can close this tab.",
95
+ footer: "Change its apps or disconnect it any time in Adelin, under Settings, Connected code agents."
96
+ },
97
+ denied: {
98
+ status: 200,
99
+ tone: "err",
100
+ icon: "m5 5 10 10M15 5 5 15",
101
+ title: "Connection denied",
102
+ body: "Adelin CLI wasn't given access to your account. You can close this tab.",
103
+ retry: !0
104
+ },
105
+ changed: {
106
+ status: 200,
107
+ tone: "info",
108
+ icon: "M15.5 8A6 6 0 0 0 5 6.5L3.5 8M3.5 4v4h4M4.5 12A6 6 0 0 0 15 13.5l1.5-1.5M16.5 16v-4h-4",
109
+ title: "Your app access changed",
110
+ body: "Adelin CLI is opening a new tab so you can review your apps again. You can close this one."
111
+ },
112
+ failed: {
113
+ status: 500,
114
+ tone: "err",
115
+ icon: ALERT,
116
+ title: "Sign-in didn't finish",
117
+ body: "Adelin CLI couldn't sign you in. Return to your terminal for details.",
118
+ retry: !0
119
+ },
120
+ invalid: {
121
+ status: 400,
122
+ tone: "err",
123
+ icon: ALERT,
124
+ title: "This sign-in link isn't valid",
125
+ body: "It may belong to an earlier sign-in.",
126
+ retry: !0
127
+ }
128
+ }, MARK = "M108.106 99.0001H86.8545L54.0527 39.1173L21.7139 99.0001H0L54.0527 0.497146L108.106 99.0001ZM106.618 0C137.364 0 155.01 18.0697 157.696 44.2764C159.277 59.6984 154.594 72.605 145.794 82.085C134.211 94.5628 117.078 97.9958 117.032 98.005L106.618 78.6036C106.618 78.6036 135.877 78.6032 134.885 45.2716C134.47 31.3417 121.991 19.4024 106.618 19.4024H73.8887L63.4746 0H106.618Z", STROKE = 'fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"', STYLE = `:root{color-scheme:light dark;--page:#EDF5FC;--card:#FFF;--text:#333;--strong:#1F1F1F;--muted:#5C5C5C;--edge:rgba(16,24,40,.13);--tile:#FFF;--sunken:#ECEEF3;--line:#9AA7C7;--ok:#0E7C68;--on-ok:#FFF;--err:#BC183E;--err-bg:rgba(188,24,62,.1);--info:#1844BC;--info-bg:rgba(24,68,188,.12);--shadow:0 0 15px rgba(0,0,0,.08)}
129
+ @media (prefers-color-scheme:dark){:root{--page:#14181B;--card:#000;--text:#DDD;--strong:#FFF;--muted:#BDBDBD;--edge:rgba(255,255,255,.12);--tile:#1C1D20;--sunken:#141414;--line:#56616E;--ok:#3CDBBE;--on-ok:#04251E;--err:#FF5C7F;--err-bg:rgba(255,92,127,.16);--info:#399CFF;--info-bg:rgba(57,156,255,.22);--shadow:0 0 20px rgba(0,0,0,.6)}}
130
+ *{box-sizing:border-box}
131
+ body{margin:0;min-height:100vh;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:28px;padding:32px 16px;background:var(--page);color:var(--text);font:16px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif}
132
+ .brand{display:flex;align-items:center;gap:10px;font-size:24px;font-weight:600;line-height:1;color:var(--strong)}
133
+ main{width:100%;max-width:480px;padding:44px 32px 36px;border-radius:14px;background:var(--card);box-shadow:var(--shadow);display:flex;flex-direction:column;align-items:center;gap:24px;text-align:center}
134
+ .link{display:flex;align-items:center}
135
+ .tile{width:60px;height:60px;border-radius:16px;display:flex;align-items:center;justify-content:center;background:var(--tile);border:1px solid var(--edge)}
136
+ .tile.cli{background:#101828;color:#FFF}
137
+ .line{width:28px;border-top:2px dashed var(--line)}
138
+ .dot{width:40px;height:40px;border-radius:50%;display:flex;align-items:center;justify-content:center;background:var(--err-bg);color:var(--err)}
139
+ .ok .line{border-top:2px solid var(--ok)}
140
+ .ok .dot{background:var(--ok);color:var(--on-ok)}
141
+ .info .dot{background:var(--info-bg);color:var(--info)}
142
+ h1{margin:0 0 10px;font-size:28px;font-weight:600;line-height:1.2;letter-spacing:-.01em;color:var(--strong);text-wrap:balance}
143
+ p{margin:0;text-wrap:balance}
144
+ .note,footer{font-size:14px;color:var(--muted)}
145
+ .retry{width:100%;padding:14px 16px;border-radius:10px;background:var(--sunken);font-size:14px;color:var(--muted)}
146
+ code{font:15px ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--strong)}
147
+ footer{max-width:440px;text-align:center;text-wrap:balance}`, mark = (width, id10) => `<svg width="${width}" height="${Math.round(width * 99 / 158)}" viewBox="0 0 158 99" aria-hidden="true"><defs><linearGradient id="${id10}" x1="57" y1="4" x2="158" y2="99" gradientUnits="userSpaceOnUse"><stop stop-color="#7C3AED"/><stop offset="1" stop-color="#2962FF"/></linearGradient></defs><path d="${MARK}" fill="url(#${id10})"/></svg>`;
148
+ }
149
+ });
150
+
47
151
  // skills/adelin-app-generation/scripts/cli-server.mjs
48
152
  import { existsSync, readFileSync } from "node:fs";
49
153
  import { dirname, join, resolve } from "node:path";
@@ -193,10 +297,11 @@ function openBrowser(url) {
193
297
  child2.on("error", () => {
194
298
  }), child2.unref();
195
299
  }
196
- var MAX_AUTH_BYTES, MAX_FILE_BYTES, LOGIN_TIMEOUT_MS, LOOPBACK, CliAuth, init_cli_auth = __esm({
300
+ var MAX_AUTH_BYTES, MAX_FILE_BYTES, LOGIN_TIMEOUT_MS, LOGIN_ATTEMPTS, LOOPBACK, CliAuth, init_cli_auth = __esm({
197
301
  "skills/adelin-app-generation/scripts/cli-auth.mjs"() {
302
+ init_cli_auth_page();
198
303
  init_cli_server();
199
- MAX_AUTH_BYTES = 16 * 1024, MAX_FILE_BYTES = 64 * 1024, LOGIN_TIMEOUT_MS = 5 * 6e4, LOOPBACK = "127.0.0.1";
304
+ MAX_AUTH_BYTES = 16 * 1024, MAX_FILE_BYTES = 64 * 1024, LOGIN_TIMEOUT_MS = 5 * 6e4, LOGIN_ATTEMPTS = 3, LOOPBACK = "127.0.0.1";
200
305
  CliAuth = class {
201
306
  constructor(mcpUrl, {
202
307
  path = configPath(),
@@ -218,7 +323,10 @@ var MAX_AUTH_BYTES, MAX_FILE_BYTES, LOGIN_TIMEOUT_MS, LOOPBACK, CliAuth, init_cl
218
323
  });
219
324
  let address = callback.address();
220
325
  if (!address || typeof address == "string") throw new Error("Could not start OAuth callback.");
221
- let redirectUri = `http://${LOOPBACK}:${address.port}/callback`, origin = new URL(this.mcpUrl).origin, loginTimer;
326
+ let redirectUri = `http://${LOOPBACK}:${address.port}/callback`, origin = new URL(this.mcpUrl).origin, loginTimer, waiting = [], answerBrowser = (result) => Promise.race([
327
+ Promise.all(waiting.splice(0).map((res) => sendSignInPage(res, result))),
328
+ delay(2e3, void 0, { ref: !1 })
329
+ ]);
222
330
  try {
223
331
  let registration = await readJson(await this.fetcher(`${origin}/oauth/register`, {
224
332
  method: "POST",
@@ -239,7 +347,7 @@ var MAX_AUTH_BYTES, MAX_FILE_BYTES, LOGIN_TIMEOUT_MS, LOOPBACK, CliAuth, init_cl
239
347
  if (typeof registration.client_id != "string" || !registration.client_id)
240
348
  throw new Error("Adelin did not register the CLI.");
241
349
  let recovery;
242
- for (let attempt = 0; attempt < 3; attempt++) {
350
+ for (let attempt = 0; attempt < LOGIN_ATTEMPTS; attempt++) {
243
351
  let verifier = randomBytes(32).toString("base64url"), challenge = createHash("sha256").update(verifier).digest("base64url"), state = randomBytes(32).toString("base64url");
244
352
  callback.removeAllListeners("request");
245
353
  let authorize = new URL(`${origin}/oauth/authorize`);
@@ -256,24 +364,26 @@ var MAX_AUTH_BYTES, MAX_FILE_BYTES, LOGIN_TIMEOUT_MS, LOOPBACK, CliAuth, init_cl
256
364
  recovery && authorize.searchParams.set("adelin_recovery", recovery);
257
365
  let answer = await new Promise((resolveCode, reject) => {
258
366
  loginTimer = setTimeout(() => reject(new Error("Adelin login timed out.")), LOGIN_TIMEOUT_MS), callback.on("request", (req, res) => {
259
- let url = new URL(req.url ?? "/", redirectUri), provided = Buffer.from(url.searchParams.get("state") ?? ""), expected = Buffer.from(state), valid = url.pathname === "/callback" && req.method === "GET" && provided.length === expected.length && timingSafeEqual(provided, expected);
260
- if (res.writeHead(valid ? 200 : 400, {
261
- "Content-Type": "text/html; charset=utf-8",
262
- "Cache-Control": "no-store",
263
- "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'"
264
- }), res.end(valid ? "<h1>Adelin sign-in complete</h1><p>You can close this tab.</p>" : "<h1>Invalid Adelin sign-in callback</h1>"), !valid) return;
265
- clearTimeout(loginTimer);
367
+ let url = new URL(req.url ?? "/", redirectUri), provided = Buffer.from(url.searchParams.get("state") ?? ""), expected = Buffer.from(state);
368
+ if (!(url.pathname === "/callback" && req.method === "GET" && provided.length === expected.length && timingSafeEqual(provided, expected))) return void sendSignInPage(res, "invalid");
369
+ waiting.push(res), clearTimeout(loginTimer);
266
370
  let receivedCode = url.searchParams.get("code");
267
371
  if (url.searchParams.get("error") === "APP_SELECTION_CHANGED" && /^[A-Za-z0-9_-]{43}$/.test(url.searchParams.get("error_description") ?? ""))
268
372
  return resolveCode({ recovery: url.searchParams.get("error_description") });
269
- receivedCode ? resolveCode({ code: receivedCode }) : reject(new Error("Adelin login was denied."));
373
+ resolveCode(receivedCode ? { code: receivedCode } : { error: url.searchParams.get("error") });
270
374
  }), this.onUrl(authorize.href), Promise.resolve(this.browser(authorize.href)).catch(reject);
271
375
  });
272
- if (answer.recovery) {
273
- recovery = answer.recovery;
376
+ if (answer.recovery && attempt < LOGIN_ATTEMPTS - 1) {
377
+ await answerBrowser("changed"), recovery = answer.recovery;
274
378
  continue;
275
379
  }
276
- let code = answer.code, token = await readJson(await this.fetcher(`${origin}/oauth/token`, {
380
+ if (answer.recovery) break;
381
+ let code = answer.code;
382
+ if (!code) {
383
+ let denied = answer.error === "access_denied";
384
+ throw await answerBrowser(denied ? "denied" : "failed"), new Error(denied ? "Adelin login was denied." : "Adelin login did not finish. Run adelin login again.");
385
+ }
386
+ let token = await readJson(await this.fetcher(`${origin}/oauth/token`, {
277
387
  method: "POST",
278
388
  redirect: "error",
279
389
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
@@ -290,11 +400,11 @@ var MAX_AUTH_BYTES, MAX_FILE_BYTES, LOGIN_TIMEOUT_MS, LOOPBACK, CliAuth, init_cl
290
400
  return await withCredentialLock(this.path, () => saveCredential(this.path, tokenFields(
291
401
  token,
292
402
  { mcpUrl: this.mcpUrl, clientId: registration.client_id }
293
- ))), { signedIn: !0 };
403
+ ))), await answerBrowser("complete"), { signedIn: !0 };
294
404
  }
295
405
  throw new Error("App access changed. Start login again.");
296
406
  } finally {
297
- clearTimeout(loginTimer), callback.close();
407
+ clearTimeout(loginTimer), await answerBrowser("failed"), callback.close();
298
408
  }
299
409
  }
300
410
  async accessToken() {
@@ -121,7 +121,8 @@ function validateJournal(value, appId) {
121
121
  value.schema !== 1 || value.appId !== appId || !UUID.test(value.operationId) ||
122
122
  !SHA256.test(value.digest) || !value.request || typeof value.request !== 'object' ||
123
123
  Array.isArray(value.request) ||
124
- !exactKeys(value.request, ['app_id', 'lease_id', 'chat_session_id', 'epoch', 'operation_id', 'files']) ||
124
+ !exactKeys(value.request, ['app_id', 'lease_id', 'chat_session_id', 'epoch', 'operation_id', 'files', ...(value.request.task_id === undefined ? [] : ['task_id'])]) ||
125
+ value.request.task_id !== undefined && !UUID.test(value.request.task_id) ||
125
126
  value.request.app_id !== appId ||
126
127
  value.request.operation_id !== value.operationId ||
127
128
  !UUID.test(value.request.lease_id) || !UUID.test(value.request.chat_session_id) ||
@@ -187,7 +188,8 @@ function validatedTerminal(value, journal) {
187
188
  !['committed', 'mixed'].includes(value.state) ||
188
189
  value.operationId !== journal.operationId ||
189
190
  (value.appId !== undefined && value.appId !== journal.appId) ||
190
- Object.keys(value).some(key => !['state', 'operationId', 'appId', 'files', 'draftRevision', 'replay', 'previewUrl'].includes(key)) ||
191
+ Object.keys(value).some(key => !['state', 'operationId', 'appId', 'files', 'draftRevision', 'replay', 'previewUrl', 'task'].includes(key)) ||
192
+ value.task !== undefined && (!exactKeys(value.task, ['taskId', 'saveToken', 'settled']) || !UUID.test(value.task.taskId) || !UUID.test(value.task.saveToken) || typeof value.task.settled !== 'boolean' || journal.request.task_id !== undefined && value.task.taskId.toLowerCase() !== journal.request.task_id.toLowerCase()) ||
191
193
  value.previewUrl !== undefined && !isPreviewUrl(value.previewUrl) ||
192
194
  !Array.isArray(value.files) || value.files.length !== journal.submitted.length)
193
195
  refuse('Save result does not match the pending operation.');
@@ -273,7 +275,8 @@ function prepareSaveLocked(destination, appId, session, options) {
273
275
  if (files.length === 0) return { state: 'no_changes', appId };
274
276
  const operationId = randomUUID();
275
277
  const request = { app_id: appId, lease_id: session.leaseId,
276
- chat_session_id: session.chatSessionId, epoch: session.epoch, operation_id: operationId, files };
278
+ chat_session_id: session.chatSessionId, epoch: session.epoch, operation_id: operationId, files, ...(options.taskId ? { task_id: options.taskId } : {}) };
279
+ if (options.taskId !== undefined && !UUID.test(options.taskId)) refuse('Invalid app task id.');
277
280
  if (Buffer.byteLength(JSON.stringify(request), 'utf8') > MAX_REQUEST_BYTES)
278
281
  refuse('Serialized save request exceeds the HTTP body limit.');
279
282
  const journal = journalFor(appId, request);
@@ -409,7 +412,7 @@ function applySaveLocked(destination, appId, response, options) {
409
412
  }
410
413
  if (changedManifest) writeAtomic(root, MANIFEST, manifestText(manifest));
411
414
  const report = { schema: 1, appId, operationId: journal.operationId,
412
- state: 'settled', outcomes, ...(previewUrl === undefined ? {} : { previewUrl }) };
415
+ state: 'settled', outcomes, ...(terminal.task ? { task: terminal.task } : {}), ...(previewUrl === undefined ? {} : { previewUrl }) };
413
416
  writeAtomic(root, SAVE_OUTCOME, JSON.stringify(report) + '\n');
414
417
  const requestPath = assertSafeTarget(root, SAVE_REQUEST);
415
418
  if (lstatIfPresent(requestPath)) {