@kairotic/app 0.0.0-stage → 0.2.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.
Files changed (96) hide show
  1. package/README.md +9 -2
  2. package/index.html +1101 -0
  3. package/kairotic/api.cljs +362 -0
  4. package/kairotic/assistant.cljs +505 -0
  5. package/kairotic/backends/gun-backend.js +371 -0
  6. package/kairotic/canvas.cljs +751 -0
  7. package/kairotic/code.cljs +108 -0
  8. package/kairotic/components.cljs +838 -0
  9. package/kairotic/core.cljs +96 -0
  10. package/kairotic/corefns.cljs +473 -0
  11. package/kairotic/docs.mjs +2 -0
  12. package/kairotic/engine.cljs +482 -0
  13. package/kairotic/examples.mjs +96 -0
  14. package/kairotic/faust.cljs +225 -0
  15. package/kairotic/help.cljs +1036 -0
  16. package/kairotic/hiccup.cljs +566 -0
  17. package/kairotic/input.cljs +271 -0
  18. package/kairotic/kfile.mjs +138 -0
  19. package/kairotic/library.cljs +214 -0
  20. package/kairotic/links.cljs +41 -0
  21. package/kairotic/mt.cljs +1604 -0
  22. package/kairotic/mtboxes.cljs +276 -0
  23. package/kairotic/packages/analysis.mjs +64 -0
  24. package/kairotic/packages/controls.mjs +28 -0
  25. package/kairotic/packages/data.mjs +22 -0
  26. package/kairotic/packages/faust-units/cmaes.mjs +82 -0
  27. package/kairotic/packages/faust-units/graph.mjs +212 -0
  28. package/kairotic/packages/faust-units/listen.mjs +125 -0
  29. package/kairotic/packages/faust-units/notation.mjs +139 -0
  30. package/kairotic/packages/faust-units/parse.mjs +439 -0
  31. package/kairotic/packages/faust-units/recipe.mjs +195 -0
  32. package/kairotic/packages/faust-units/render.mjs +69 -0
  33. package/kairotic/packages/faust-units/units.mjs +130 -0
  34. package/kairotic/packages/faust-units/view.mjs +353 -0
  35. package/kairotic/packages/faust-units.mjs +9 -0
  36. package/kairotic/packages/io.mjs +58 -0
  37. package/kairotic/packages/net.mjs +28 -0
  38. package/kairotic/packages/patterns.mjs +34 -0
  39. package/kairotic/packages/spatial.mjs +22 -0
  40. package/kairotic/packages/spectral/shift.mjs +169 -0
  41. package/kairotic/packages/spectral.mjs +16 -0
  42. package/kairotic/packages/synth.mjs +28 -0
  43. package/kairotic/packages/theory/counterpoint.mjs +798 -0
  44. package/kairotic/packages/theory/mirror.mjs +221 -0
  45. package/kairotic/packages/theory.mjs +46 -0
  46. package/kairotic/patterns.cljs +538 -0
  47. package/kairotic/presets.cljs +227 -0
  48. package/kairotic/quantize.cljs +782 -0
  49. package/kairotic/record.cljs +169 -0
  50. package/kairotic/release.cljs +90 -0
  51. package/kairotic/ring.cljs +129 -0
  52. package/kairotic/ringaudio.cljs +232 -0
  53. package/kairotic/ringcore.mjs +270 -0
  54. package/kairotic/score.cljs +176 -0
  55. package/kairotic/shapes.cljs +283 -0
  56. package/kairotic/signal.cljs +327 -0
  57. package/kairotic/sounds.cljs +565 -0
  58. package/kairotic/sounds.mjs +108 -0
  59. package/kairotic/span.cljs +129 -0
  60. package/kairotic/spell.cljs +281 -0
  61. package/kairotic/structure.cljs +145 -0
  62. package/kairotic/talk.cljs +115 -0
  63. package/kairotic/tempo.cljs +226 -0
  64. package/kairotic/treecanvas.cljs +299 -0
  65. package/kairotic/tutorials.mjs +1283 -0
  66. package/kairotic/vendor/codemirror.mjs +23 -0
  67. package/package.json +23 -4
  68. package/page/00-work.cljs +862 -0
  69. package/page/01-commands.cljs +1219 -0
  70. package/page/02-patch-view.cljs +1051 -0
  71. package/page/03-history-view.cljs +481 -0
  72. package/page/04-panels.cljs +448 -0
  73. package/page/05-gestures.cljs +1247 -0
  74. package/page/06-connection.cljs +219 -0
  75. package/page/07-claude.cljs +430 -0
  76. package/page/08-sessions.cljs +423 -0
  77. package/page/09-learn.cljs +602 -0
  78. package/page/10-embed.cljs +469 -0
  79. package/page/11-startup.cljs +61 -0
  80. package/page/12-feedback.cljs +172 -0
  81. package/page/13-perform.cljs +325 -0
  82. package/page/14-editor.cljs +656 -0
  83. package/page/15-presets.cljs +230 -0
  84. package/page/16-release.cljs +242 -0
  85. package/page/17-sounds.cljs +147 -0
  86. package/page/18-lines.cljs +594 -0
  87. package/page/19-files.cljs +247 -0
  88. package/page/19-html.cljs +152 -0
  89. package/page/20-talk.cljs +527 -0
  90. package/page/21-net.cljs +110 -0
  91. package/page/22-learn.cljs +303 -0
  92. package/page/23-ids.cljs +233 -0
  93. package/page/24-clipboard.cljs +136 -0
  94. package/page/25-tidy.cljs +74 -0
  95. package/page/26-probes.cljs +111 -0
  96. package/sources.mjs +2 -0
@@ -0,0 +1,371 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ // Kairotic · a backend outside claude.ai (Study 17)
3
+ //
4
+ // Inside claude.ai a Kairotic page gets its database, rooms, user and Claude from the viewer
5
+ // (`window.claude.use("db" | "room" | "user" | "sample")`). Anywhere else — GitHub Pages, a local
6
+ // server — this file gives the page the same four things, with the same shape, so the page does not
7
+ // change:
8
+ //
9
+ // db collection(path) / doc(path) → set · update · delete · get · onSnapshot (GUN)
10
+ // room presence(obj) · onPeers(fn) · join(name) → room · leave() (GUN)
11
+ // user id() · can(what) · profiles(ids) (a local key pair)
12
+ // sample sample(input, {tools, onText, signal, modelTier}) · limits() (Claude API, your own key)
13
+ //
14
+ // Data lives in GUN, a graph that syncs between browsers through relay peers. Everything under
15
+ // data/users/<you>/ (your solo works) is encrypted with a key pair that never leaves this browser;
16
+ // rooms are readable by whoever has their link, as in claude.ai. Each document is stored as JSON in
17
+ // one field (GUN has no arrays). Deleting leaves a tombstone. Claude is called with the Anthropic API
18
+ // key you paste into the page, kept only in this browser's storage and sent only to api.anthropic.com.
19
+ (function () {
20
+ "use strict";
21
+
22
+ const store = {
23
+ get(k) { try { return window.localStorage.getItem(k); } catch (_) { return null; } },
24
+ set(k, v) { try { window.localStorage.setItem(k, v); } catch (_) { /* private mode */ } },
25
+ del(k) { try { window.localStorage.removeItem(k); } catch (_) { /* private mode */ } },
26
+ };
27
+
28
+ const rid = (n) => {
29
+ const a = new Uint8Array(n || 12);
30
+ crypto.getRandomValues(a);
31
+ return Array.from(a, (b) => "abcdefghijklmnopqrstuvwxyz0123456789"[b % 36]).join("");
32
+ };
33
+
34
+ // ───────── from GUN's localStorage to IndexedDB ─────────
35
+ // The localStorage adapter kept the graph under "gun/" as {soul: node}, nodes with their states: the
36
+ // shape GUN takes in an incoming put, so giving it back as one ('in') merges it by those states (what
37
+ // a relay has that is newer stays) and stores it in IndexedDB. Only the souls of this app are taken
38
+ // (other GUN apps of the same origin share that key). When the page opens again a minute later or more,
39
+ // those souls leave "gun/" (the key goes if nothing else is left), which frees the space.
40
+ function migrateLocalStorage(gun, app) {
41
+ const KEY = "gun/", DONE = "kairotic.gun-migrated";
42
+ const ours = (soul) => soul === app || soul.indexOf(app + "/") === 0;
43
+ let raw = null, graph = null;
44
+ try { raw = window.localStorage.getItem(KEY); } catch (_) { return; }
45
+ if (!raw) return;
46
+ try { graph = JSON.parse(raw); } catch (_) { return; }
47
+ if (!graph || typeof graph !== "object") return;
48
+ const souls = Object.keys(graph).filter(ours);
49
+ const done = Number(store.get(DONE)) || 0;
50
+ if (done) {
51
+ // brought over in an earlier visit (at least a minute ago, so IndexedDB has written it): free the space
52
+ if (Date.now() - done < 60000) return;
53
+ const rest = Object.keys(graph).filter((s) => !ours(s));
54
+ try {
55
+ if (!rest.length) window.localStorage.removeItem(KEY);
56
+ else if (souls.length) {
57
+ const kept = {};
58
+ rest.forEach((s) => { kept[s] = graph[s]; });
59
+ window.localStorage.setItem(KEY, JSON.stringify(kept));
60
+ }
61
+ } catch (_) { /* it stays: it is only read */ }
62
+ return;
63
+ }
64
+ if (!souls.length) { store.set(DONE, String(Date.now())); return; }
65
+ const put = {};
66
+ souls.forEach((s) => { put[s] = graph[s]; });
67
+ try {
68
+ gun._.on("in", { "#": rid(9), put: put });
69
+ store.set(DONE, String(Date.now()));
70
+ console.info("Kairotic: " + souls.length + " nodes moved from localStorage to IndexedDB");
71
+ } catch (e) { console.warn("Kairotic: the data in localStorage could not be moved to IndexedDB", e); }
72
+ }
73
+
74
+ function create(opts) {
75
+ opts = opts || {};
76
+ const Gun = window.Gun, SEA = Gun && Gun.SEA;
77
+ if (!Gun || !SEA) throw new Error("Kairotic: gun.js and sea.js must be loaded before gun-backend.js");
78
+ const app = opts.app || "kairotic-v1";
79
+ // Where this browser keeps its copy of the graph. GUN's own localStorage adapter keeps everything it
80
+ // has seen (the works, and the rooms that come from a relay) as one JSON of at most 5 MB: once full,
81
+ // every save fails with "localStorage max!". With GUN's RAD on IndexedDB (site/vendor/gun/lib/) there
82
+ // is room for much more; what an earlier version left in localStorage is brought over once.
83
+ const rad = !!window.RindexedDB && opts.localStorage !== true;
84
+ const gun = Gun({ peers: opts.peers || [], localStorage: !rad && opts.localStorage !== false,
85
+ file: opts.file || "kairotic-radata" });
86
+ if (rad) migrateLocalStorage(gun, app);
87
+ const root = gun.get(app);
88
+ const nodeAt = (path) => String(path).split("/").filter(Boolean).reduce((n, s) => n.get(s), root);
89
+
90
+ // ───────── identity: a key pair kept in this browser ─────────
91
+ let pairP = null;
92
+ const pair = () => pairP || (pairP = (async () => {
93
+ const saved = store.get("kairotic.pair");
94
+ if (saved) { try { return JSON.parse(saved); } catch (_) { /* make a new one */ } }
95
+ const p = await SEA.pair();
96
+ store.set("kairotic.pair", JSON.stringify(p));
97
+ return p;
98
+ })());
99
+ // ids with no "/" or "." so they can be path segments
100
+ const uidOf = (p) => p.pub.replace(/[^A-Za-z0-9_-]/g, "").slice(0, 32);
101
+
102
+ // ───────── encoding: JSON, encrypted under data/users/ ─────────
103
+ const privatePath = (path) => /^data\/users\//.test(String(path));
104
+ async function encode(path, obj) {
105
+ const json = JSON.stringify(obj);
106
+ return privatePath(path) ? await SEA.encrypt(json, await pair()) : json;
107
+ }
108
+ async function decode(path, raw) {
109
+ if (raw == null) return null;
110
+ try {
111
+ if (privatePath(path)) {
112
+ const json = await SEA.decrypt(raw, await pair());
113
+ return json == null ? null : (typeof json === "string" ? JSON.parse(json) : json);
114
+ }
115
+ return JSON.parse(raw);
116
+ } catch (_) { return null; }
117
+ }
118
+
119
+ // a put resolves when a peer (or local storage) acknowledges it, or after a moment anyway
120
+ const put = (node, value) => new Promise((resolve, reject) => {
121
+ let done = false;
122
+ const t = setTimeout(() => { if (!done) { done = true; resolve(); } }, 1500);
123
+ node.put(value, (ack) => {
124
+ if (done) return;
125
+ done = true; clearTimeout(t);
126
+ if (ack && ack.err) reject(new Error(String(ack.err))); else resolve();
127
+ });
128
+ });
129
+
130
+ // a document as written (json and del): read from IndexedDB, a large one can arrive in parts
131
+ const whole = (data) => "json" in data && "del" in data;
132
+
133
+ function docSnap(id, path, data) {
134
+ return decode(path, data && !data.del ? data.json : null).then((obj) => ({
135
+ id, exists: obj != null, data: () => obj,
136
+ }));
137
+ }
138
+
139
+ class DocRef {
140
+ constructor(path) { this.path = String(path); this.id = this.path.split("/").filter(Boolean).pop(); }
141
+ async set(obj) { await put(nodeAt(this.path), { json: await encode(this.path, obj), del: false, t: Date.now() }); }
142
+ async update(obj) {
143
+ const cur = await this.get();
144
+ await this.set(Object.assign({}, cur.exists ? cur.data() : {}, obj));
145
+ }
146
+ async delete() { await put(nodeAt(this.path), { json: null, del: true, t: Date.now() }); }
147
+ // one read: the first whole value that arrives (GUN's once is unreliable without local storage), or
148
+ // what has arrived after a moment. A document is whole when it has both json and del: read from
149
+ // IndexedDB (RAD), a large one can arrive in parts, and its first part may not have json yet
150
+ get() {
151
+ return new Promise((resolve) => {
152
+ let done = false, last = null;
153
+ const chain = nodeAt(this.path);
154
+ const finish = (data) => {
155
+ if (done) return;
156
+ done = true;
157
+ try { chain.off(); } catch (_) { /* already off */ }
158
+ resolve(docSnap(this.id, this.path, data));
159
+ };
160
+ chain.on((data) => {
161
+ last = data;
162
+ if (data && whole(data)) finish(data);
163
+ });
164
+ setTimeout(() => finish(last), 1200);
165
+ });
166
+ }
167
+ onSnapshot(cb, err) {
168
+ const chain = nodeAt(this.path);
169
+ let alive = true;
170
+ chain.on((data) => {
171
+ if (data && !whole(data)) return; // a part of it (see get): the rest is coming
172
+ docSnap(this.id, this.path, data).then((s) => { if (alive) cb(s); }).catch((e) => err && err(e));
173
+ });
174
+ return () => { alive = false; chain.off(); };
175
+ }
176
+ }
177
+
178
+ class CollRef {
179
+ constructor(path) { this.path = String(path); }
180
+ doc(id) { return new DocRef(this.path + "/" + (id || rid(16))); }
181
+ // every document of the collection, read as they arrive (GUN has no "end"): settles after a quiet moment
182
+ get() {
183
+ return new Promise((resolve) => {
184
+ const seen = {};
185
+ let timer = null;
186
+ const settle = () => {
187
+ Promise.all(Object.keys(seen).map((k) => docSnap(k, this.path + "/" + k, seen[k])))
188
+ .then((docs) => resolve({ docs: docs.filter((d) => d.exists) }));
189
+ };
190
+ const poke = () => { clearTimeout(timer); timer = setTimeout(settle, 700); };
191
+ const chain = nodeAt(this.path).map();
192
+ chain.on((data, key) => { seen[key] = data; poke(); });
193
+ poke();
194
+ setTimeout(() => { try { chain.off(); } catch (_) { /* already off */ } }, 5000);
195
+ });
196
+ }
197
+ onSnapshot(cb, err) {
198
+ const docs = {};
199
+ let alive = true, timer = null;
200
+ const emit = () => {
201
+ clearTimeout(timer);
202
+ timer = setTimeout(() => {
203
+ Promise.all(Object.keys(docs).map((k) => docSnap(k, this.path + "/" + k, docs[k])))
204
+ .then((snaps) => { if (alive) cb({ docs: snaps }); })
205
+ .catch((e) => err && err(e));
206
+ }, 40);
207
+ };
208
+ const chain = nodeAt(this.path).map();
209
+ chain.on((data, key) => { if (data && !whole(data)) return; docs[key] = data; emit(); });
210
+ emit();
211
+ return () => { alive = false; chain.off(); };
212
+ }
213
+ }
214
+
215
+ const db = {
216
+ collection: (path) => new CollRef(path),
217
+ doc: (path) => new DocRef(path),
218
+ };
219
+
220
+ // ───────── rooms: presence in GUN, renewed while the page is open ─────────
221
+ const tab = rid(10);
222
+ const LIVE_MS = 15000, BEAT_MS = 5000;
223
+
224
+ function makeRoom(name) {
225
+ const where = root.get("presence").get(name);
226
+ let mine = null, beat = null, watching = null, peersTimer = null;
227
+ const entries = {};
228
+ const room = {
229
+ name,
230
+ presence(obj) {
231
+ mine = obj || {};
232
+ const send = async () => put(where.get(tab), { json: JSON.stringify(mine), by: uidOf(await pair()), t: Date.now() });
233
+ clearInterval(beat);
234
+ beat = setInterval(send, BEAT_MS);
235
+ return send();
236
+ },
237
+ onPeers(cb) {
238
+ let last = "";
239
+ const report = () => {
240
+ const now = Date.now();
241
+ const peers = Object.keys(entries)
242
+ .filter((k) => entries[k] && entries[k].t > now - LIVE_MS)
243
+ .map((k) => {
244
+ let p = {};
245
+ try { p = JSON.parse(entries[k].json || "{}"); } catch (_) { /* ignore */ }
246
+ return { peer: k, by: entries[k].by, isMe: k === tab, sameTab: k === tab, kind: "human", presence: p };
247
+ });
248
+ const sig = JSON.stringify(peers);
249
+ if (sig !== last) { last = sig; cb({ peers }); }
250
+ };
251
+ watching = where.map();
252
+ watching.on((data, key) => { entries[key] = data; report(); });
253
+ peersTimer = setInterval(report, 2000);
254
+ report();
255
+ },
256
+ join(sub) { return Promise.resolve(makeRoom(sub)); },
257
+ leave() {
258
+ clearInterval(beat); clearInterval(peersTimer);
259
+ if (watching) watching.off();
260
+ return put(where.get(tab), { json: "{}", t: 0 });
261
+ },
262
+ };
263
+ return room;
264
+ }
265
+
266
+ const room = makeRoom("lobby");
267
+ window.addEventListener("beforeunload", () => { room.leave(); });
268
+
269
+ // ───────── user ─────────
270
+ const user = {
271
+ id: () => pair().then(uidOf),
272
+ can: () => Promise.resolve(true),
273
+ profiles: () => Promise.resolve({}),
274
+ };
275
+
276
+ // the relays this page syncs through, and how each one is now: open, connecting or waiting (GUN
277
+ // tries again on its own while one does not answer)
278
+ const relays = () => Object.keys(gun._.opt.peers || {}).map((url) => {
279
+ const w = (gun._.opt.peers[url] || {}).wire;
280
+ return { url, state: !w ? "waiting" : w.readyState === 1 ? "open" : w.readyState === 0 ? "connecting" : "waiting" };
281
+ });
282
+
283
+ return { kind: "gun", gun, db, room, user, relays, sample: makeSample(opts) };
284
+ }
285
+
286
+ // ───────── Claude with your own API key ─────────
287
+ // Same call as claude.ai's sample capability: sample(input, {tools, onText, signal, modelTier}).
288
+ // The tool loop runs here: Claude asks for a tool, the page's execute runs, the result goes back.
289
+ const KEY = "kairotic.anthropicKey";
290
+ const MODELS = { quick: "claude-haiku-5-5", default: "claude-sonnet-5-5", complex: "claude-opus-5-5" };
291
+
292
+ function makeSample(opts) {
293
+ const api = (opts && opts.api) || "https://api.anthropic.com/v1/messages";
294
+ const fail = (code, message, text) => Object.assign({ code, message }, text ? { text } : {});
295
+
296
+ async function sample(input, o) {
297
+ o = o || {};
298
+ const key = store.get(KEY);
299
+ if (!key) throw fail("not_granted", "No Anthropic API key: paste yours in the Claude tab (it stays in this browser).");
300
+ const tier = MODELS[o.modelTier] ? o.modelTier : "default";
301
+ const model = store.get("kairotic.model") || MODELS[tier];
302
+ const messages = typeof input === "string" ? [{ role: "user", content: input }]
303
+ : input.map((m) => ({ role: m.role, content: m.content }));
304
+ const tools = (o.tools || []).map((t) => ({
305
+ name: t.name, description: t.description,
306
+ input_schema: t.inputSchema || { type: "object", properties: {} },
307
+ }));
308
+ let text = "", truncated = false;
309
+ for (let round = 0; round < 10; round++) {
310
+ let res;
311
+ try {
312
+ res = await fetch(api, {
313
+ method: "POST", signal: o.signal,
314
+ headers: { "content-type": "application/json", "x-api-key": key, "anthropic-version": "2023-06-01",
315
+ "anthropic-dangerous-direct-browser-access": "true" },
316
+ body: JSON.stringify(Object.assign({ model, max_tokens: 16000, messages }, tools.length ? { tools } : {})),
317
+ });
318
+ } catch (e) {
319
+ if (o.signal && o.signal.aborted) throw fail("cancelled", "stopped", text || undefined);
320
+ throw fail("upstream_error", String(e && e.message || e), text || undefined);
321
+ }
322
+ if (!res.ok) {
323
+ const body = await res.text().catch(() => "");
324
+ if (res.status === 401 || res.status === 403) throw fail("not_granted", "The API key was refused: " + body.slice(0, 200));
325
+ if (res.status === 429) throw fail("rate_limited", "Too many requests or out of credit: " + body.slice(0, 200), text || undefined);
326
+ if (res.status === 400 && /prompt is too long/i.test(body)) throw fail("prompt_too_large", body.slice(0, 200));
327
+ if (/credit balance|billing/i.test(body)) throw fail("no_credit", body.slice(0, 300));
328
+ if (res.status === 529 || res.status === 503 || /overloaded/i.test(body)) throw fail("overloaded", res.status + " " + body.slice(0, 200), text || undefined);
329
+ if (res.status === 404 && /model/i.test(body)) throw fail("no_model", model + ": " + body.slice(0, 200));
330
+ throw fail("upstream_error", res.status + " " + body.slice(0, 300), text || undefined);
331
+ }
332
+ const msg = await res.json();
333
+ const said = (msg.content || []).filter((b) => b.type === "text").map((b) => b.text).join("");
334
+ if (said) {
335
+ const delta = (text ? "\n\n" : "") + said;
336
+ text += delta;
337
+ if (o.onText) try { o.onText({ text, delta }); } catch (_) { /* the page's problem */ }
338
+ }
339
+ const calls = (msg.content || []).filter((b) => b.type === "tool_use");
340
+ if (msg.stop_reason !== "tool_use" || !calls.length) {
341
+ truncated = msg.stop_reason === "max_tokens";
342
+ break;
343
+ }
344
+ messages.push({ role: "assistant", content: msg.content });
345
+ const results = await Promise.all(calls.map(async (c) => {
346
+ const tool = (o.tools || []).find((t) => t.name === c.name);
347
+ try {
348
+ if (!tool) throw new Error("no tool " + c.name);
349
+ const out = await tool.execute(c.input || {}, { signal: o.signal });
350
+ const s = typeof out === "string" ? out : JSON.stringify(out);
351
+ return { type: "tool_result", tool_use_id: c.id, content: s.slice(0, 32768) };
352
+ } catch (e) {
353
+ return { type: "tool_result", tool_use_id: c.id, content: "Error: " + (e && e.message || e), is_error: true };
354
+ }
355
+ }));
356
+ messages.push({ role: "user", content: results });
357
+ if (o.signal && o.signal.aborted) throw fail("cancelled", "stopped", text || undefined);
358
+ }
359
+ if (!text.trim()) throw fail("empty_completion", "Claude wrote nothing");
360
+ return { text, truncated, modelTierApplied: tier };
361
+ }
362
+ sample.limits = () => Promise.resolve({ maxPromptBytes: 262144, tools: { maxCount: 16 } });
363
+ sample.byok = true;
364
+ sample.hasKey = () => !!store.get(KEY);
365
+ sample.setKey = (k) => { if (k) store.set(KEY, String(k).trim()); else store.del(KEY); };
366
+ return sample;
367
+ }
368
+
369
+ // an embed has no database nor rooms, but Claude (with the viewer's key) can still make its patch
370
+ window.KairoticGun = { create, sample: makeSample };
371
+ })();