@larkup/cli 0.3.14 → 0.3.16

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 (44) hide show
  1. package/dist/{analytics-store-5BPWULY4.js → analytics-store-4EI56OLE.js} +2 -1
  2. package/dist/{chunk-WH6SGG26.js → chunk-54YIZOXQ.js} +2 -2
  3. package/dist/{chunk-V5MXHOEA.js → chunk-6HRBZ7QP.js} +3 -3
  4. package/dist/{chunk-IJE2RPSN.js → chunk-6VBJAFWY.js} +62 -54
  5. package/dist/{chunk-DE4VP425.js → chunk-CUA3FHFQ.js} +2 -2
  6. package/dist/{chunk-LCK6D6SK.js → chunk-DTRGAEFR.js} +4 -4
  7. package/dist/{chunk-CQ7NVYHT.js → chunk-FMBWCTFV.js} +71 -62
  8. package/dist/chunk-GYXT77I3.js +515 -0
  9. package/dist/{chunk-Z3C6M6AJ.js → chunk-HYYSI5FE.js} +95 -64
  10. package/dist/chunk-MEYK3O6D.js +10 -0
  11. package/dist/{event-streams-JRBKH3UT.js → chunk-PFTSXAZG.js} +31 -32
  12. package/dist/{chunk-RJ2NIMTP.js → chunk-QTJFKXSU.js} +3 -3
  13. package/dist/{chunk-OFWLJSVC.js → chunk-SDP2LXLJ.js} +11 -4
  14. package/dist/{chunk-T2XKBURE.js → chunk-SMQUSHD4.js} +10 -0
  15. package/dist/chunk-TFGGCUFR.js +126 -0
  16. package/dist/{chunk-KA5D5NKN.js → chunk-VZAREDRR.js} +3 -3
  17. package/dist/{chunk-CVBK47OT.js → chunk-YOPP3ETL.js} +94 -77
  18. package/dist/{chunk-HX45PZFR.js → chunk-ZH2A3TFQ.js} +39 -39
  19. package/dist/{dist-es-2UI7ONZZ.js → dist-es-3SVFRI6P.js} +242 -219
  20. package/dist/{dist-es-Y73OHM5Y.js → dist-es-CM7567P2.js} +8 -9
  21. package/dist/{dist-es-UJY2ZAAU.js → dist-es-DC3KLBPR.js} +9 -10
  22. package/dist/{dist-es-OED5OOKX.js → dist-es-FEVR73CQ.js} +8 -9
  23. package/dist/{dist-es-5D5ADEYS.js → dist-es-IS5PH45I.js} +24 -32
  24. package/dist/{dist-es-KL7UCI6C.js → dist-es-KY7QTIEX.js} +22 -23
  25. package/dist/{dist-es-QQMKUAEQ.js → dist-es-M6OXVHSI.js} +2 -3
  26. package/dist/{dist-es-MAY5SYH5.js → dist-es-OB4H2RSG.js} +10 -11
  27. package/dist/{dist-es-IAOJLUTI.js → dist-es-PY4YS7TC.js} +9 -13
  28. package/dist/{dist-es-FI7PADBF.js → dist-es-ZDCXFYRX.js} +5 -6
  29. package/dist/{event-streams-IXBDR476.js → event-streams-KOWL2S4G.js} +3 -3
  30. package/dist/index.js +231 -65
  31. package/dist/{loadSso-S4KING47.js → loadSso-OLMNBQ4H.js} +67 -67
  32. package/dist/{signin-ALRQUKQQ.js → signin-NBTUJ5KD.js} +71 -71
  33. package/dist/{sso-oidc-D3TLLZUS.js → sso-oidc-WNK6HQX7.js} +77 -70
  34. package/dist/{sts-PHP2EVI2.js → sts-TGY2Y4DZ.js} +79 -76
  35. package/dist/{tool-loader-K6PLXSLW.js → tool-loader-PVQVSBBL.js} +3 -2
  36. package/dist/{tool-registry-G35SY4WN.js → tool-registry-M25AVCE4.js} +1 -1
  37. package/package.json +14 -14
  38. package/dist/chunk-FNZK42G6.js +0 -73
  39. package/dist/chunk-HBASLJRD.js +0 -1426
  40. package/dist/chunk-LREGQMME.js +0 -1280
  41. package/dist/chunk-M5367BNN.js +0 -184
  42. package/dist/chunk-WXRKGSWM.js +0 -34
  43. package/dist/chunk-XEB2OVD6.js +0 -648
  44. package/dist/chunk-XFLXM5WU.js +0 -2394
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  isToolInstalled,
7
7
  loadTool,
8
8
  uninstallTool
9
- } from "./chunk-OFWLJSVC.js";
9
+ } from "./chunk-SDP2LXLJ.js";
10
10
  import {
11
11
  ALL_MODELS,
12
12
  DEFAULT_CONFIG,
@@ -21,11 +21,14 @@ import {
21
21
  runWithProject,
22
22
  setActiveProject,
23
23
  trackUsageEvent
24
- } from "./chunk-T2XKBURE.js";
24
+ } from "./chunk-SMQUSHD4.js";
25
+ import {
26
+ workspaceHost
27
+ } from "./chunk-MEYK3O6D.js";
25
28
  import {
26
29
  getAllTools,
27
30
  getToolById
28
- } from "./chunk-RJ2NIMTP.js";
31
+ } from "./chunk-QTJFKXSU.js";
29
32
  import {
30
33
  __require
31
34
  } from "./chunk-QGM4M3NI.js";
@@ -36,7 +39,7 @@ import { Command } from "commander";
36
39
  // package.json
37
40
  var package_default = {
38
41
  name: "@larkup/cli",
39
- version: "0.3.14",
42
+ version: "0.3.16",
40
43
  engines: {
41
44
  node: ">=22"
42
45
  },
@@ -57,21 +60,21 @@ var package_default = {
57
60
  "type-check": "tsc --noEmit"
58
61
  },
59
62
  dependencies: {
60
- "@ai-sdk/cohere": "^4.0.54",
61
- "@ai-sdk/deepseek": "^3.0.58",
62
- "@ai-sdk/gateway": "^4.0.102",
63
- "@ai-sdk/google": "^4.0.87",
64
- "@ai-sdk/mistral": "^4.0.56",
65
- "@ai-sdk/openai": "^4.0.83",
66
- "@ai-sdk/openai-compatible": "^3.0.62",
63
+ "@ai-sdk/cohere": "^4.0.61",
64
+ "@ai-sdk/deepseek": "^3.0.65",
65
+ "@ai-sdk/gateway": "^4.0.114",
66
+ "@ai-sdk/google": "^4.0.96",
67
+ "@ai-sdk/mistral": "^4.0.64",
68
+ "@ai-sdk/openai": "^4.0.94",
69
+ "@ai-sdk/openai-compatible": "^3.0.69",
67
70
  "@clack/prompts": "^1.7.0",
68
- "@lancedb/lancedb": "^0.39.0",
71
+ "@lancedb/lancedb": "^0.40.0",
69
72
  "@larkup/core": "workspace:*",
70
73
  "@larkup/marketplace": "workspace:*",
71
74
  "@larkup/vector-stores": "workspace:*",
72
- "@napi-rs/canvas": "1.0.9",
75
+ "@napi-rs/canvas": "1.0.11",
73
76
  "@pinecone-database/pinecone": "^9.0.0",
74
- ai: "^7.0.126",
77
+ ai: "^7.0.141",
75
78
  "apache-arrow": "18.1.0",
76
79
  chalk: "^6.0.0",
77
80
  chromadb: "^3.5.0",
@@ -82,7 +85,7 @@ var package_default = {
82
85
  zod: "^4.4.3"
83
86
  },
84
87
  devDependencies: {
85
- tsup: "^8.5.1",
88
+ tsup: "^9.0.0",
86
89
  tsx: "^4.23.5",
87
90
  typescript: "^7.0.2"
88
91
  }
@@ -215,6 +218,8 @@ import { spawn as spawn2 } from "child_process";
215
218
  import { promises as fs } from "fs";
216
219
  import path from "path";
217
220
  async function readConfig() {
221
+ const host = workspaceHost();
222
+ if (host) return host.readConfig();
218
223
  const dir = await requireProjectDataDir();
219
224
  try {
220
225
  const raw = await fs.readFile(path.join(dir, "config.json"), "utf8");
@@ -252,6 +257,8 @@ async function readConfig() {
252
257
  }
253
258
  }
254
259
  async function writeConfig(config) {
260
+ const host = workspaceHost();
261
+ if (host) return host.writeConfig(config);
255
262
  const dir = await requireProjectDataDir();
256
263
  const next = { ...config, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
257
264
  await fs.writeFile(path.join(dir, "config.json"), JSON.stringify(next, null, 2), "utf8");
@@ -264,6 +271,130 @@ import path3 from "path";
264
271
  import { spawn, exec } from "child_process";
265
272
  import { promisify } from "util";
266
273
 
274
+ // ../../packages/runtime-kit/src/widget.js
275
+ function widgetScript(config = {}) {
276
+ const settings = {
277
+ title: config.widget?.title || "Ask us anything",
278
+ welcomeMessage: config.widget?.welcomeMessage || "Hi! How can I help?",
279
+ placeholder: config.widget?.placeholder || "Type a message\u2026",
280
+ primaryColor: config.widget?.primaryColor || "#111827",
281
+ position: config.widget?.position || "bottom-right",
282
+ darkMode: Boolean(config.widget?.darkMode),
283
+ logoUrl: config.widget?.logoUrl || ""
284
+ };
285
+ const browserSource = `(() => {
286
+ const defaults = ${JSON.stringify(settings)};
287
+ const script = document.currentScript || document.querySelector('script[data-larkup-widget]') || document.querySelector('script[src*="/widget.js"]');
288
+ const data = script?.dataset || {};
289
+ const host = String(data.host || new URL(script?.src || location.href, location.href).origin).replace(/\\/+$/, '');
290
+ const config = { ...defaults, title: data.title || defaults.title, welcomeMessage: data.welcomeMessage || defaults.welcomeMessage, placeholder: data.placeholder || defaults.placeholder, primaryColor: data.primaryColor || defaults.primaryColor, position: data.position || defaults.position, darkMode: data.theme ? data.theme === 'dark' : defaults.darkMode, logoUrl: data.logoUrl || defaults.logoUrl };
291
+ const mount = document.createElement('div'); mount.dataset.larkupWidget = ''; if (data.class) mount.className = data.class; document.body.appendChild(mount);
292
+ const root = mount.attachShadow({ mode: 'open' });
293
+ root.innerHTML = '<style>:host{all:initial}*{box-sizing:border-box}.w{--a:' + config.primaryColor + ';position:fixed;bottom:20px;z-index:2147483000;font:14px/1.45 ui-sans-serif,system-ui;color:#17191e}.right{right:20px}.left{left:20px}.p{width:min(390px,calc(100vw - 32px));height:min(620px,calc(100vh - 110px));display:none;flex-direction:column;overflow:hidden;background:#fff;border:1px solid #e1e3e8;border-radius:18px;box-shadow:0 20px 60px #11182738}.open .p{display:flex}.dark .p{background:#17191e;border-color:#343946;color:#f4f4f5;box-shadow:0 20px 60px #0009}.h{display:flex;gap:10px;align-items:center;padding:15px 16px;border-bottom:1px solid #e1e3e8}.dark .h{border-color:#343946}.d{width:9px;height:9px;border-radius:99px;background:var(--a)}strong{flex:1}.x,.b,.s{border:0;cursor:pointer}.x{background:transparent;color:inherit;font-size:20px}.m{flex:1;overflow:auto;display:flex;flex-direction:column;gap:10px;padding:16px}.a,.u,.empty{max-width:86%;padding:10px 12px;border-radius:14px;white-space:pre-wrap;overflow-wrap:anywhere}.a,.empty{align-self:flex-start;background:#f3f4f6}.dark .a,.dark .empty{background:#292d36}.u{align-self:flex-end;background:var(--a);color:#fff;border-bottom-right-radius:4px}.f{display:flex;gap:8px;padding:12px;border-top:1px solid #e1e3e8}.dark .f{border-color:#343946}textarea{flex:1;min-height:42px;resize:none;border:1px solid #d8dbe2;border-radius:12px;padding:10px;background:transparent;color:inherit;font:inherit}.s{width:42px;border-radius:12px;background:var(--a);color:#fff}.b{display:flex;align-items:center;justify-content:center;margin:12px 0 0 auto;width:56px;height:56px;border-radius:99px;background:var(--a);color:#fff;font-size:22px;box-shadow:0 10px 25px #11182740}.left .b{margin-left:0}.err{color:#dc2626}.dark .err{color:#fca5a5}.cb{background:#1e1e1e;color:#d4d4d4;border-radius:8px;overflow:hidden;margin:8px 0;font-family:monospace;font-size:13px;white-space:normal}.cb-h{display:flex;justify-content:space-between;background:#2d2d2d;padding:4px 8px;font-size:11px;color:#a0a0a0}.cb-h button{background:none;border:none;color:inherit;cursor:pointer;padding:0}.cb pre{margin:0;padding:8px;overflow-x:auto;white-space:pre}code{font-family:monospace;background:#0002;padding:2px 4px;border-radius:4px}a{color:var(--a)}@keyframes pulse{0%,100%{opacity:.5}50%{opacity:1}}</style><div class="w ' + (config.position === 'bottom-left' ? 'left' : 'right') + (config.darkMode ? ' dark' : '') + '"><section class="p" role="dialog"><header class="h"><i class="d"></i><strong></strong><button class="x" aria-label="Close chat">\xD7</button></header><main class="m"><div class="empty"></div></main><form class="f"><textarea rows="1"></textarea><button class="s" aria-label="Send">\u2191</button></form></section><button class="b" aria-label="Open chat"></button></div>';
294
+ const shell = root.querySelector('.w'), panel = root.querySelector('.p'), button = root.querySelector('.b'), close = root.querySelector('.x'), list = root.querySelector('.m'), empty = root.querySelector('.empty'), input = root.querySelector('textarea'), form = root.querySelector('form');
295
+ root.querySelector('strong').textContent = config.title; empty.textContent = config.welcomeMessage; input.placeholder = config.placeholder;
296
+ const iconNormal = config.logoUrl ? '<img src="' + config.logoUrl + '" style="width:28px;height:28px;border-radius:99px;object-fit:cover">' : '\u25CC';
297
+ button.innerHTML = iconNormal;
298
+ const toggle = (open) => { shell.classList.toggle('open', open); button.innerHTML = open ? '\xD7' : iconNormal; }; button.onclick = () => toggle(!shell.classList.contains('open')); close.onclick = () => toggle(false);
299
+ const add = (name, text) => { const el = document.createElement('div'); el.className = name; el.innerHTML = text; list.appendChild(el); list.scrollTop = list.scrollHeight; return el; };
300
+ const text = (line) => { try { if (line.startsWith('0:')) { const value = JSON.parse(line.slice(2)); return typeof value === 'string' ? value : ''; } if (!line.startsWith('data:')) return ''; const value = JSON.parse(line.slice(5)); return value?.type === 'text-delta' ? (value.delta || value.text || '') : ''; } catch { return ''; } };
301
+ const parseMD = (str) => { return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\\\`\\\`\\\`(\\w*)\\n([\\s\\S]*?)\\\`\\\`\\\`/g, '<div class="cb"><div class="cb-h"><span>$1</span><button type="button" onclick="navigator.clipboard.writeText(this.parentElement.nextElementSibling.textContent);this.textContent=\\'Copied!\\';setTimeout(()=>this.textContent=\\'Copy\\',2000)">Copy</button></div><pre><code>$2</code></pre></div>').replace(/\\\`([^\`]+)\\\`/g, '<code>$1</code>').replace(/\\*\\*([^*]+)\\*\\*/g, '<strong>$1</strong>').replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, '<a href="$2" target="_blank">$1</a>'); };
302
+ input.onkeydown = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); form.requestSubmit(); } };
303
+ form.onsubmit = async (event) => { event.preventDefault(); const question = input.value.trim(); if (!question) return; empty.remove(); add('u', parseMD(question)); input.value = ''; const answer = add('a', '<span style="animation:pulse 1s infinite">Thinking...</span>'); try { const response = await fetch(host + '/chat', { method: 'POST', headers: { 'Content-Type': 'application/json', ...(data.apiKey ? { Authorization: 'Bearer ' + data.apiKey } : {}) }, body: JSON.stringify({ messages: [{ role: 'user', content: question }] }) }); if (!response.ok) throw new Error((await response.json().catch(() => ({}))).error || 'Could not reach the assistant.'); const reader = response.body?.getReader(), decoder = new TextDecoder(); if (!reader) return; let buffer = ''; let fullText = ''; while (true) { const chunk = await reader.read(); buffer += decoder.decode(chunk.value || new Uint8Array(), { stream: !chunk.done }); const lines = buffer.split(/\\r?\\n/); buffer = lines.pop() || ''; for (const line of lines) { const t = text(line); if (t) { fullText += t; answer.innerHTML = parseMD(fullText); list.scrollTop = list.scrollHeight; } } if (chunk.done) break; } const t = text(buffer); if (t) { fullText += t; answer.innerHTML = parseMD(fullText); list.scrollTop = list.scrollHeight; } } catch (error) { answer.classList.add('err'); answer.textContent = error instanceof Error ? error.message : 'Could not reach the assistant.'; } };
304
+ window.LarkupWidget = { destroy: () => mount.remove() };
305
+ })();`;
306
+ return browserSource;
307
+ }
308
+
309
+ // ../../packages/runtime-kit/src/server-api.js
310
+ function serverOpenApiDocument(profile = "agent") {
311
+ const isAgent = profile === "agent";
312
+ const bearer = [{ bearerAuth: [] }];
313
+ const operation = (summary, tags, extra = {}) => ({
314
+ summary,
315
+ tags,
316
+ security: bearer,
317
+ responses: { 200: { description: "Successful response" } },
318
+ ...extra
319
+ });
320
+ const knowledge = ["Knowledge"];
321
+ const agent = ["Agent"];
322
+ return {
323
+ openapi: "3.1.0",
324
+ info: {
325
+ title: isAgent ? "Larkup Agent Server" : "Larkup Knowledge Server",
326
+ version: "1.0.0",
327
+ description: isAgent ? "Knowledge-base operations plus an AI SDK-compatible Agent API." : "Knowledge-base retrieval and content-management API."
328
+ },
329
+ security: bearer,
330
+ tags: [
331
+ { name: "Knowledge", description: "Knowledge base retrieval and management." },
332
+ ...isAgent ? [{ name: "Agent", description: "Agent chat streaming and loaded tools." }] : []
333
+ ],
334
+ paths: {
335
+ "/query": { post: operation("Query the RAG knowledge base", knowledge) },
336
+ "/chat": {
337
+ post: operation(
338
+ isAgent ? "Stream an Agent chat response" : "Stream a retrieval-grounded chat response",
339
+ isAgent ? agent : knowledge
340
+ )
341
+ },
342
+ "/documents": {
343
+ get: operation("List documents (paginated)", knowledge),
344
+ post: operation("Add a new document", knowledge)
345
+ },
346
+ "/documents/{id}": {
347
+ get: operation("Get a single document by ID", knowledge),
348
+ put: operation("Update a document", knowledge),
349
+ delete: operation("Delete a document", knowledge)
350
+ },
351
+ "/scrape": { post: operation("Scrape a URL and ingest into the corpus", knowledge) },
352
+ "/health": {
353
+ get: {
354
+ summary: "Health check",
355
+ tags: knowledge,
356
+ responses: { 200: { description: "OK" } }
357
+ }
358
+ },
359
+ "/models": {
360
+ get: operation("List chat providers and models available to this runtime", knowledge)
361
+ },
362
+ "/readiness": {
363
+ get: {
364
+ summary: "Check knowledge-store readiness",
365
+ tags: knowledge,
366
+ responses: {
367
+ 200: { description: "Knowledge store is connected" },
368
+ 503: { description: "Knowledge store is unavailable" }
369
+ }
370
+ }
371
+ },
372
+ "/corpus/summary": { get: operation("Get corpus summary statistics", knowledge) },
373
+ "/corpus": { post: operation("Get corpus documents with optional filtering", knowledge) },
374
+ "/corpus/export": { post: operation("Export full corpus as CSV or JSONL", knowledge) },
375
+ ...isAgent ? {
376
+ "/agent": { get: operation("Get Agent Runtime information", agent) },
377
+ "/agent/tools": { get: operation("List tools loaded by the Agent", agent) },
378
+ "/agent/capabilities": { get: operation("List grouped Agent capabilities", agent) },
379
+ "/agent/configuration": { get: operation("Get saved Agent prompt and skills", agent) },
380
+ "/agent/sandbox": {
381
+ get: operation("Check the configured Agent sandbox environment", agent)
382
+ },
383
+ "/agent/chat": {
384
+ post: operation(
385
+ "Stream an Agent response using the AI SDK UI message protocol",
386
+ agent
387
+ )
388
+ },
389
+ "/v1/chat/completions": {
390
+ post: operation("OpenAI-compatible Agent chat completions", agent)
391
+ }
392
+ } : {}
393
+ },
394
+ components: { securitySchemes: { bearerAuth: { type: "http", scheme: "bearer" } } }
395
+ };
396
+ }
397
+
267
398
  // ../../packages/vector-stores/src/registry.ts
268
399
  var VECTOR_STORES = {
269
400
  lancedb: {
@@ -1931,6 +2062,10 @@ const handler = async (req, res) => {
1931
2062
  )}, type: SERVER_PROFILE === "agent" ? "agent-server" : "knowledge-server", profile: SERVER_PROFILE })
1932
2063
  }
1933
2064
 
2065
+ if (req.method === "GET" && url.pathname === "/openapi.json") {
2066
+ return send(res, 200, ${JSON.stringify(serverOpenApiDocument(isAgentServer ? "agent" : "knowledge"))})
2067
+ }
2068
+
1934
2069
  if (req.method === "OPTIONS") {
1935
2070
  res.writeHead(204, {
1936
2071
  "Access-Control-Allow-Origin": "*",
@@ -2715,37 +2850,7 @@ for (const [i, hit] of data.hits.entries()) {
2715
2850
  `;
2716
2851
  }
2717
2852
  function widgetSource(config) {
2718
- const settings = {
2719
- title: config.widget?.title || "Ask us anything",
2720
- welcomeMessage: config.widget?.welcomeMessage || "Hi! How can I help?",
2721
- placeholder: config.widget?.placeholder || "Type a message\u2026",
2722
- primaryColor: config.widget?.primaryColor || "#111827",
2723
- position: config.widget?.position || "bottom-right",
2724
- darkMode: Boolean(config.widget?.darkMode),
2725
- logoUrl: config.widget?.logoUrl || ""
2726
- };
2727
- const browserSource = `(() => {
2728
- const defaults = ${JSON.stringify(settings)};
2729
- const script = document.currentScript || document.querySelector('script[data-larkup-widget]') || document.querySelector('script[src*="/widget.js"]');
2730
- const data = script?.dataset || {};
2731
- const host = String(data.host || new URL(script?.src || location.href, location.href).origin).replace(/\\/+$/, '');
2732
- const config = { ...defaults, title: data.title || defaults.title, welcomeMessage: data.welcomeMessage || defaults.welcomeMessage, placeholder: data.placeholder || defaults.placeholder, primaryColor: data.primaryColor || defaults.primaryColor, position: data.position || defaults.position, darkMode: data.theme ? data.theme === 'dark' : defaults.darkMode, logoUrl: data.logoUrl || defaults.logoUrl };
2733
- const mount = document.createElement('div'); mount.dataset.larkupWidget = ''; if (data.class) mount.className = data.class; document.body.appendChild(mount);
2734
- const root = mount.attachShadow({ mode: 'open' });
2735
- root.innerHTML = '<style>:host{all:initial}*{box-sizing:border-box}.w{--a:' + config.primaryColor + ';position:fixed;bottom:20px;z-index:2147483000;font:14px/1.45 ui-sans-serif,system-ui;color:#17191e}.right{right:20px}.left{left:20px}.p{width:min(390px,calc(100vw - 32px));height:min(620px,calc(100vh - 110px));display:none;flex-direction:column;overflow:hidden;background:#fff;border:1px solid #e1e3e8;border-radius:18px;box-shadow:0 20px 60px #11182738}.open .p{display:flex}.dark .p{background:#17191e;border-color:#343946;color:#f4f4f5;box-shadow:0 20px 60px #0009}.h{display:flex;gap:10px;align-items:center;padding:15px 16px;border-bottom:1px solid #e1e3e8}.dark .h{border-color:#343946}.d{width:9px;height:9px;border-radius:99px;background:var(--a)}strong{flex:1}.x,.b,.s{border:0;cursor:pointer}.x{background:transparent;color:inherit;font-size:20px}.m{flex:1;overflow:auto;display:flex;flex-direction:column;gap:10px;padding:16px}.a,.u,.empty{max-width:86%;padding:10px 12px;border-radius:14px;white-space:pre-wrap;overflow-wrap:anywhere}.a,.empty{align-self:flex-start;background:#f3f4f6}.dark .a,.dark .empty{background:#292d36}.u{align-self:flex-end;background:var(--a);color:#fff;border-bottom-right-radius:4px}.f{display:flex;gap:8px;padding:12px;border-top:1px solid #e1e3e8}.dark .f{border-color:#343946}textarea{flex:1;min-height:42px;resize:none;border:1px solid #d8dbe2;border-radius:12px;padding:10px;background:transparent;color:inherit;font:inherit}.s{width:42px;border-radius:12px;background:var(--a);color:#fff}.b{display:flex;align-items:center;justify-content:center;margin:12px 0 0 auto;width:56px;height:56px;border-radius:99px;background:var(--a);color:#fff;font-size:22px;box-shadow:0 10px 25px #11182740}.left .b{margin-left:0}.err{color:#dc2626}.dark .err{color:#fca5a5}.cb{background:#1e1e1e;color:#d4d4d4;border-radius:8px;overflow:hidden;margin:8px 0;font-family:monospace;font-size:13px;white-space:normal}.cb-h{display:flex;justify-content:space-between;background:#2d2d2d;padding:4px 8px;font-size:11px;color:#a0a0a0}.cb-h button{background:none;border:none;color:inherit;cursor:pointer;padding:0}.cb pre{margin:0;padding:8px;overflow-x:auto;white-space:pre}code{font-family:monospace;background:#0002;padding:2px 4px;border-radius:4px}a{color:var(--a)}@keyframes pulse{0%,100%{opacity:.5}50%{opacity:1}}</style><div class="w ' + (config.position === 'bottom-left' ? 'left' : 'right') + (config.darkMode ? ' dark' : '') + '"><section class="p" role="dialog"><header class="h"><i class="d"></i><strong></strong><button class="x" aria-label="Close chat">\xD7</button></header><main class="m"><div class="empty"></div></main><form class="f"><textarea rows="1"></textarea><button class="s" aria-label="Send">\u2191</button></form></section><button class="b" aria-label="Open chat"></button></div>';
2736
- const shell = root.querySelector('.w'), panel = root.querySelector('.p'), button = root.querySelector('.b'), close = root.querySelector('.x'), list = root.querySelector('.m'), empty = root.querySelector('.empty'), input = root.querySelector('textarea'), form = root.querySelector('form');
2737
- root.querySelector('strong').textContent = config.title; empty.textContent = config.welcomeMessage; input.placeholder = config.placeholder;
2738
- const iconNormal = config.logoUrl ? '<img src="' + config.logoUrl + '" style="width:28px;height:28px;border-radius:99px;object-fit:cover">' : '\u25CC';
2739
- button.innerHTML = iconNormal;
2740
- const toggle = (open) => { shell.classList.toggle('open', open); button.innerHTML = open ? '\xD7' : iconNormal; }; button.onclick = () => toggle(!shell.classList.contains('open')); close.onclick = () => toggle(false);
2741
- const add = (name, text) => { const el = document.createElement('div'); el.className = name; el.innerHTML = text; list.appendChild(el); list.scrollTop = list.scrollHeight; return el; };
2742
- const text = (line) => { try { if (line.startsWith('0:')) { const value = JSON.parse(line.slice(2)); return typeof value === 'string' ? value : ''; } if (!line.startsWith('data:')) return ''; const value = JSON.parse(line.slice(5)); return value?.type === 'text-delta' ? (value.delta || value.text || '') : ''; } catch { return ''; } };
2743
- const parseMD = (str) => { return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\\\`\\\`\\\`(\\w*)\\n([\\s\\S]*?)\\\`\\\`\\\`/g, '<div class="cb"><div class="cb-h"><span>$1</span><button type="button" onclick="navigator.clipboard.writeText(this.parentElement.nextElementSibling.textContent);this.textContent=\\'Copied!\\';setTimeout(()=>this.textContent=\\'Copy\\',2000)">Copy</button></div><pre><code>$2</code></pre></div>').replace(/\\\`([^\`]+)\\\`/g, '<code>$1</code>').replace(/\\*\\*([^*]+)\\*\\*/g, '<strong>$1</strong>').replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, '<a href="$2" target="_blank">$1</a>'); };
2744
- input.onkeydown = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); form.requestSubmit(); } };
2745
- form.onsubmit = async (event) => { event.preventDefault(); const question = input.value.trim(); if (!question) return; empty.remove(); add('u', parseMD(question)); input.value = ''; const answer = add('a', '<span style="animation:pulse 1s infinite">Thinking...</span>'); try { const response = await fetch(host + '/chat', { method: 'POST', headers: { 'Content-Type': 'application/json', ...(data.apiKey ? { Authorization: 'Bearer ' + data.apiKey } : {}) }, body: JSON.stringify({ messages: [{ role: 'user', content: question }] }) }); if (!response.ok) throw new Error((await response.json().catch(() => ({}))).error || 'Could not reach the assistant.'); const reader = response.body?.getReader(), decoder = new TextDecoder(); if (!reader) return; let buffer = ''; let fullText = ''; while (true) { const chunk = await reader.read(); buffer += decoder.decode(chunk.value || new Uint8Array(), { stream: !chunk.done }); const lines = buffer.split(/\\r?\\n/); buffer = lines.pop() || ''; for (const line of lines) { const t = text(line); if (t) { fullText += t; answer.innerHTML = parseMD(fullText); list.scrollTop = list.scrollHeight; } } if (chunk.done) break; } const t = text(buffer); if (t) { fullText += t; answer.innerHTML = parseMD(fullText); list.scrollTop = list.scrollHeight; } } catch (error) { answer.classList.add('err'); answer.textContent = error instanceof Error ? error.message : 'Could not reach the assistant.'; } };
2746
- window.LarkupWidget = { destroy: () => mount.remove() };
2747
- })();`;
2748
- return `export const widgetScript = ${JSON.stringify(browserSource)};
2853
+ return `export const widgetScript = ${JSON.stringify(widgetScript(config))};
2749
2854
  `;
2750
2855
  }
2751
2856
  function dockerfile() {
@@ -3193,6 +3298,8 @@ function connectionFile(dir) {
3193
3298
  return path2.join(dir, "mcp-connections.json");
3194
3299
  }
3195
3300
  async function readStoredConnections() {
3301
+ const host = workspaceHost();
3302
+ if (host) return await host.readState("mcp-connections") ?? [];
3196
3303
  const dir = await getProjectDataDir();
3197
3304
  if (!dir) return [];
3198
3305
  try {
@@ -3774,6 +3881,8 @@ async function docsPath(create) {
3774
3881
  return path6.join(dir, "documents.json");
3775
3882
  }
3776
3883
  async function readDocuments() {
3884
+ const host = workspaceHost();
3885
+ if (host) return host.readDocuments();
3777
3886
  const file = await docsPath(false);
3778
3887
  if (!file) return [];
3779
3888
  try {
@@ -3789,6 +3898,8 @@ async function readDocuments() {
3789
3898
  }
3790
3899
  }
3791
3900
  async function writeAll(docs) {
3901
+ const host = workspaceHost();
3902
+ if (host) return host.writeDocuments(docs);
3792
3903
  const file = await docsPath(true);
3793
3904
  if (!file) return;
3794
3905
  const temporaryFile = path6.join(
@@ -4205,8 +4316,8 @@ async function embedTexts(config, texts, abortSignal) {
4205
4316
  ...abortSignal ? { abortSignal } : {}
4206
4317
  });
4207
4318
  const totalTokens = texts.reduce((acc, t) => acc + Math.ceil(t.length / 4), 0);
4208
- const { trackUsageEvent: trackUsageEvent2, estimateCost: estimateCost2 } = await import("./analytics-store-5BPWULY4.js");
4209
- void trackUsageEvent2({
4319
+ const { trackUsageEvent: trackUsageEvent2, estimateCost: estimateCost2 } = await import("./analytics-store-4EI56OLE.js");
4320
+ await trackUsageEvent2({
4210
4321
  type: "embedding",
4211
4322
  embeddingModelId: config.embeddingModelId,
4212
4323
  embeddingTokens: totalTokens,
@@ -4743,6 +4854,8 @@ function isMissingFile(error) {
4743
4854
  return error?.code === "ENOENT";
4744
4855
  }
4745
4856
  async function readMediaAssets() {
4857
+ const host = workspaceHost();
4858
+ if (host) return host.readMediaAssets();
4746
4859
  const file = await assetsPath(false);
4747
4860
  if (!file) return [];
4748
4861
  try {
@@ -4758,6 +4871,8 @@ async function readMediaAssets() {
4758
4871
  }
4759
4872
  }
4760
4873
  async function writeAll2(assets) {
4874
+ const host = workspaceHost();
4875
+ if (host) return host.writeMediaAssets(assets);
4761
4876
  const file = await assetsPath(true);
4762
4877
  if (!file) return;
4763
4878
  const temporaryFile = path10.join(
@@ -4974,7 +5089,7 @@ var S3StorageProvider = class {
4974
5089
  }
4975
5090
  async client() {
4976
5091
  if (!this._client) {
4977
- const { S3Client } = await import("./dist-es-2UI7ONZZ.js");
5092
+ const { S3Client } = await import("./dist-es-3SVFRI6P.js");
4978
5093
  this._client = new S3Client({
4979
5094
  region: this.region,
4980
5095
  ...this._credentials ? { credentials: this._credentials } : {}
@@ -4993,7 +5108,7 @@ var S3StorageProvider = class {
4993
5108
  return { bucket: withoutScheme.slice(0, slashIndex), key: withoutScheme.slice(slashIndex + 1) };
4994
5109
  }
4995
5110
  async store(key, data, mimeType) {
4996
- const { PutObjectCommand } = await import("./dist-es-2UI7ONZZ.js");
5111
+ const { PutObjectCommand } = await import("./dist-es-3SVFRI6P.js");
4997
5112
  const client = await this.client();
4998
5113
  const objectKey = this.objectKey(key);
4999
5114
  await client.send(
@@ -5011,7 +5126,7 @@ var S3StorageProvider = class {
5011
5126
  return this.store(key, await fs9.readFile(sourcePath), mimeType);
5012
5127
  }
5013
5128
  async retrieve(uri) {
5014
- const { GetObjectCommand } = await import("./dist-es-2UI7ONZZ.js");
5129
+ const { GetObjectCommand } = await import("./dist-es-3SVFRI6P.js");
5015
5130
  const { bucket, key } = this.parseUri(uri);
5016
5131
  const client = await this.client();
5017
5132
  const response = await client.send(new GetObjectCommand({ Bucket: bucket, Key: key }));
@@ -5027,8 +5142,8 @@ var S3StorageProvider = class {
5027
5142
  return void 0;
5028
5143
  }
5029
5144
  async getReadUrl(uri, expiresInSecs) {
5030
- const { GetObjectCommand } = await import("./dist-es-2UI7ONZZ.js");
5031
- const { getSignedUrl } = await import("./dist-es-UJY2ZAAU.js");
5145
+ const { GetObjectCommand } = await import("./dist-es-3SVFRI6P.js");
5146
+ const { getSignedUrl } = await import("./dist-es-DC3KLBPR.js");
5032
5147
  const { bucket, key } = this.parseUri(uri);
5033
5148
  const client = await this.client();
5034
5149
  return getSignedUrl(client, new GetObjectCommand({ Bucket: bucket, Key: key }), {
@@ -5036,7 +5151,7 @@ var S3StorageProvider = class {
5036
5151
  });
5037
5152
  }
5038
5153
  async delete(uri) {
5039
- const { DeleteObjectCommand } = await import("./dist-es-2UI7ONZZ.js");
5154
+ const { DeleteObjectCommand } = await import("./dist-es-3SVFRI6P.js");
5040
5155
  const { bucket, key } = this.parseUri(uri);
5041
5156
  const client = await this.client();
5042
5157
  try {
@@ -5121,10 +5236,38 @@ async function readStateUncached(file) {
5121
5236
  }
5122
5237
  }
5123
5238
  var cached = null;
5239
+ async function readVideoKnowledgeState() {
5240
+ const host = workspaceHost();
5241
+ if (host) {
5242
+ const persisted = await host.readState(
5243
+ "video-knowledge"
5244
+ );
5245
+ if (!persisted) return cloneEmpty();
5246
+ if (persisted.schemaVersion !== 1)
5247
+ throw new Error("Unsupported hosted video knowledge schema.");
5248
+ return { ...cloneEmpty(), ...persisted };
5249
+ }
5250
+ const file = await dataPath(false);
5251
+ if (!file) return cloneEmpty();
5252
+ let key;
5253
+ try {
5254
+ const stat = await fs10.stat(file);
5255
+ key = `${file}:${stat.mtimeMs}:${stat.size}`;
5256
+ } catch (error) {
5257
+ if (isMissing(error)) return cloneEmpty();
5258
+ throw error;
5259
+ }
5260
+ if (cached?.key === key) return cached.state;
5261
+ const state = await readStateUncached(file);
5262
+ cached = { key, state };
5263
+ return state;
5264
+ }
5124
5265
  function invalidateVideoKnowledgeStateCache() {
5125
5266
  cached = null;
5126
5267
  }
5127
5268
  async function writeState2(state) {
5269
+ const host = workspaceHost();
5270
+ if (host) return host.writeState("video-knowledge", state);
5128
5271
  const file = await dataPath(true);
5129
5272
  if (!file) return;
5130
5273
  const temp = path12.join(
@@ -5142,6 +5285,8 @@ async function writeState2(state) {
5142
5285
  }
5143
5286
  var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
5144
5287
  async function acquireStateLock() {
5288
+ if (workspaceHost()) return async () => {
5289
+ };
5145
5290
  const file = await dataPath(true);
5146
5291
  if (!file) return async () => {
5147
5292
  };
@@ -5176,8 +5321,9 @@ function mutateVideoKnowledgeState(mutate) {
5176
5321
  const run = writeChain4.then(async () => {
5177
5322
  const release = await acquireStateLock();
5178
5323
  try {
5179
- const file = await dataPath(false);
5180
- const state = file ? await readStateUncached(file) : cloneEmpty();
5324
+ const host = workspaceHost();
5325
+ const file = host ? null : await dataPath(false);
5326
+ const state = host ? structuredClone(await readVideoKnowledgeState()) : file ? await readStateUncached(file) : cloneEmpty();
5181
5327
  const result = await mutate(state);
5182
5328
  await writeState2(state);
5183
5329
  invalidateVideoKnowledgeStateCache();
@@ -6575,7 +6721,9 @@ async function updateEnterpriseCommand() {
6575
6721
  const config = await readConfig();
6576
6722
  const enterprise = config.enterprise;
6577
6723
  if (!enterprise) {
6578
- throw new Error("This Project is not enrolled with an Enterprise profile. Run `larkup install --ee` first.");
6724
+ throw new Error(
6725
+ "This Project is not enrolled with an Enterprise profile. Run `larkup install --ee` first."
6726
+ );
6579
6727
  }
6580
6728
  const response = await fetch(enterpriseEndpoint(enterprise.dashboardUrl, "/api/client/config"), {
6581
6729
  headers: { Authorization: `Bearer ${enterprise.clientKey}` }
@@ -6601,10 +6749,16 @@ async function updateEnterpriseCommand() {
6601
6749
  continue;
6602
6750
  }
6603
6751
  const installResponse = await fetch(
6604
- enterpriseEndpoint(enterprise.dashboardUrl, `/api/client/tools/${encodeURIComponent(tool2.toolId)}/install`),
6752
+ enterpriseEndpoint(
6753
+ enterprise.dashboardUrl,
6754
+ `/api/client/tools/${encodeURIComponent(tool2.toolId)}/install`
6755
+ ),
6605
6756
  {
6606
6757
  method: "POST",
6607
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${enterprise.clientKey}` },
6758
+ headers: {
6759
+ "Content-Type": "application/json",
6760
+ Authorization: `Bearer ${enterprise.clientKey}`
6761
+ },
6608
6762
  body: JSON.stringify({})
6609
6763
  }
6610
6764
  );
@@ -6619,13 +6773,21 @@ async function updateEnterpriseCommand() {
6619
6773
  managedToolIds = managedToolIds.filter((id) => remoteToolIds.has(id));
6620
6774
  await writeConfig({
6621
6775
  ...config,
6622
- enterprise: { ...enterprise, managedToolIds, configurationVersion: profile.configurationVersion }
6776
+ enterprise: {
6777
+ ...enterprise,
6778
+ managedToolIds,
6779
+ configurationVersion: profile.configurationVersion
6780
+ }
6623
6781
  });
6624
- log.success(`Enterprise configuration updated (v${localVersion} \u2192 v${profile.configurationVersion}).`);
6782
+ log.success(
6783
+ `Enterprise configuration updated (v${localVersion} \u2192 v${profile.configurationVersion}).`
6784
+ );
6625
6785
  if (added.length) log.info(`Newly installed: ${added.join(", ")}`);
6626
6786
  if (removed.length) log.info(`Removed (revoked): ${removed.join(", ")}`);
6627
6787
  if (needsCredential.length) {
6628
- log.warn(`Needs credentials \u2014 run \`larkup enterprise-tool install <id> --api-key <key>\`: ${needsCredential.join(", ")}`);
6788
+ log.warn(
6789
+ `Needs credentials \u2014 run \`larkup enterprise-tool install <id> --api-key <key>\`: ${needsCredential.join(", ")}`
6790
+ );
6629
6791
  }
6630
6792
  if (!added.length && !removed.length && !needsCredential.length) {
6631
6793
  log.dim("No tool changes. Limits and policy were refreshed.");
@@ -6633,12 +6795,16 @@ async function updateEnterpriseCommand() {
6633
6795
  }
6634
6796
  async function enterpriseUpdateAvailable() {
6635
6797
  try {
6798
+ if (!await getActiveProject()) return false;
6636
6799
  const config = await readConfig();
6637
6800
  const enterprise = config.enterprise;
6638
6801
  if (!enterprise) return false;
6639
- const response = await fetch(enterpriseEndpoint(enterprise.dashboardUrl, "/api/client/config"), {
6640
- headers: { Authorization: `Bearer ${enterprise.clientKey}` }
6641
- });
6802
+ const response = await fetch(
6803
+ enterpriseEndpoint(enterprise.dashboardUrl, "/api/client/config"),
6804
+ {
6805
+ headers: { Authorization: `Bearer ${enterprise.clientKey}` }
6806
+ }
6807
+ );
6642
6808
  if (!response.ok) return false;
6643
6809
  const profile = await response.json();
6644
6810
  return profile.configurationVersion !== (enterprise.configurationVersion ?? 0);