@larkup/cli 0.3.15 → 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.
@@ -3,7 +3,8 @@ import {
3
3
  getAnalyticsSummary,
4
4
  readUsageEvents,
5
5
  trackUsageEvent
6
- } from "./chunk-T2XKBURE.js";
6
+ } from "./chunk-SMQUSHD4.js";
7
+ import "./chunk-MEYK3O6D.js";
7
8
  import "./chunk-QGM4M3NI.js";
8
9
  export {
9
10
  estimateCost,
@@ -0,0 +1,10 @@
1
+ // ../../packages/core/src/workspace-host.ts
2
+ import { AsyncLocalStorage } from "async_hooks";
3
+ var scope = new AsyncLocalStorage();
4
+ function workspaceHost() {
5
+ return scope.getStore();
6
+ }
7
+
8
+ export {
9
+ workspaceHost
10
+ };
@@ -23,7 +23,7 @@ var BUILTIN_TOOLS = [
23
23
  description: "Help your AI understand your videos, so you can ask questions and get answers from the right moments.",
24
24
  longDescription: "Turn videos into knowledge your AI can understand. It listens to what is said, reads what appears on screen, and helps you find the moments that matter.",
25
25
  category: "media",
26
- version: "0.3.5",
26
+ version: "0.3.6",
27
27
  pricing: "free",
28
28
  emoji: "\u{1F3AC}",
29
29
  icon: "Film",
@@ -596,7 +596,7 @@ var BUILTIN_TOOLS = [
596
596
  description: "AI-powered form filling and document editing with Canvas-style live preview.",
597
597
  longDescription: "Open PDF, Word, PowerPoint, and text files in a split-view Canvas. AI fills forms using your knowledge base, edits content on request, and previews changes live. Supports PDF form fields (AcroForm), DOCX paragraphs/tables, PPTX slide text, and plain text editing. Uses pdf-lib (native) for PDF and the Docker sandbox for DOCX/PPTX via python-docx/python-pptx.",
598
598
  category: "utility",
599
- version: "0.2.28",
599
+ version: "0.3.0",
600
600
  pricing: "free",
601
601
  emoji: "\u{1F4DD}",
602
602
  icon: "FileEdit",
@@ -621,7 +621,7 @@ function normalizeToolDescriptor(descriptor) {
621
621
  }
622
622
  function compareToolVersions(left, right) {
623
623
  const parse = (version) => {
624
- const [core, suffix = ""] = version.split("-", 2);
624
+ const [core = "", suffix = ""] = version.split("-", 2);
625
625
  const parts = core.split(".").map((part) => Number.parseInt(part, 10) || 0);
626
626
  return { parts, stable: suffix.length === 0 };
627
627
  };
@@ -1,7 +1,10 @@
1
+ import {
2
+ workspaceHost
3
+ } from "./chunk-MEYK3O6D.js";
1
4
  import {
2
5
  getToolById,
3
6
  invalidateRegistryCache
4
- } from "./chunk-RJ2NIMTP.js";
7
+ } from "./chunk-QTJFKXSU.js";
5
8
  import {
6
9
  __require
7
10
  } from "./chunk-QGM4M3NI.js";
@@ -63,6 +66,8 @@ async function writeManifest(manifest) {
63
66
  await fs.writeFile(getManifestPath(), JSON.stringify(manifest, null, 2), "utf8");
64
67
  }
65
68
  async function getInstalledTools() {
69
+ const hosted = workspaceHost()?.tools;
70
+ if (hosted) return hosted.map(({ module: _module, ...tool }) => tool);
66
71
  const manifest = await readManifest();
67
72
  return [...manifest.tools];
68
73
  }
@@ -285,7 +290,7 @@ async function execInstallUnlocked(packageName, version, target, onProgress) {
285
290
  await fs.readFile(path.join(resolvedPath, "package.json"), "utf8")
286
291
  );
287
292
  const resolvedVersion = packageJson.version ?? version;
288
- const { compareToolVersions } = await import("./tool-registry-G35SY4WN.js");
293
+ const { compareToolVersions } = await import("./tool-registry-M25AVCE4.js");
289
294
  if (compareToolVersions(version, resolvedVersion) > 0) {
290
295
  throw new Error(`Version ${version} is not yet available. Please try again later.`);
291
296
  }
@@ -476,7 +481,7 @@ async function uninstallTool(toolId) {
476
481
  }
477
482
  }
478
483
  invalidateRegistryCache();
479
- const { unloadTool: unloadTool2 } = await import("./tool-loader-K6PLXSLW.js");
484
+ const { unloadTool: unloadTool2 } = await import("./tool-loader-PVQVSBBL.js");
480
485
  unloadTool2(toolId);
481
486
  } finally {
482
487
  uninstallingTools.delete(toolId);
@@ -525,6 +530,8 @@ async function getScopedImport(revision) {
525
530
  return importer;
526
531
  }
527
532
  async function loadTool(toolId) {
533
+ const hosted = workspaceHost()?.tools?.find((tool) => tool.id === toolId);
534
+ if (hosted) return hosted.module;
528
535
  const installed = await getInstalledTool(toolId);
529
536
  if (!installed) return null;
530
537
  const importPath = await resolveImportPath(installed);
@@ -600,7 +607,7 @@ function unloadTool(toolId) {
600
607
  moduleCache.delete(toolId);
601
608
  }
602
609
  async function hasCapability(capability) {
603
- const { getToolsWithCapability } = await import("./tool-registry-G35SY4WN.js");
610
+ const { getToolsWithCapability } = await import("./tool-registry-M25AVCE4.js");
604
611
  const tools = await getToolsWithCapability(capability);
605
612
  for (const t of tools) {
606
613
  const installed = await getInstalledTool(t.id);
@@ -1,3 +1,7 @@
1
+ import {
2
+ workspaceHost
3
+ } from "./chunk-MEYK3O6D.js";
4
+
1
5
  // ../../packages/core/src/analytics-store.ts
2
6
  import { promises as fs2 } from "fs";
3
7
  import path2 from "path";
@@ -149,11 +153,14 @@ async function getProjectWorkspace() {
149
153
  return readWorkspaceFile();
150
154
  }
151
155
  async function getActiveProject() {
156
+ const host = workspaceHost();
157
+ if (host) return host.project;
152
158
  const workspace = await getProjectWorkspace();
153
159
  const projectId = projectScope.getStore()?.projectId ?? workspace.activeProjectId;
154
160
  return workspace.projects.find((project) => project.id === projectId) ?? null;
155
161
  }
156
162
  async function getProjectDataDir() {
163
+ if (workspaceHost()) return null;
157
164
  const project = await getActiveProject();
158
165
  if (!project) return null;
159
166
  const dir = projectDir(project.id);
@@ -161,6 +168,7 @@ async function getProjectDataDir() {
161
168
  return dir;
162
169
  }
163
170
  async function requireProjectDataDir() {
171
+ if (workspaceHost()) throw new Error("This operation requires a workspace storage adapter.");
164
172
  const dir = await getProjectDataDir();
165
173
  if (dir) return dir;
166
174
  if (projectScope.getStore()?.projectId) {
@@ -6915,6 +6923,8 @@ async function readUsageEvents() {
6915
6923
  }
6916
6924
  }
6917
6925
  function trackUsageEvent(event) {
6926
+ const host = workspaceHost();
6927
+ if (host) return host.trackUsage(event);
6918
6928
  return serialize2(async () => {
6919
6929
  const events = await readUsageEvents();
6920
6930
  const fullEvent = {
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.15",
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.58",
61
- "@ai-sdk/deepseek": "^3.0.62",
62
- "@ai-sdk/gateway": "^4.0.108",
63
- "@ai-sdk/google": "^4.0.92",
64
- "@ai-sdk/mistral": "^4.0.61",
65
- "@ai-sdk/openai": "^4.0.89",
66
- "@ai-sdk/openai-compatible": "^3.0.66",
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
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.10",
75
+ "@napi-rs/canvas": "1.0.11",
73
76
  "@pinecone-database/pinecone": "^9.0.0",
74
- ai: "^7.0.133",
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(
@@ -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();
@@ -3,8 +3,9 @@ import {
3
3
  isToolLoaded,
4
4
  loadTool,
5
5
  unloadTool
6
- } from "./chunk-OFWLJSVC.js";
7
- import "./chunk-RJ2NIMTP.js";
6
+ } from "./chunk-SDP2LXLJ.js";
7
+ import "./chunk-MEYK3O6D.js";
8
+ import "./chunk-QTJFKXSU.js";
8
9
  import "./chunk-QGM4M3NI.js";
9
10
  export {
10
11
  hasCapability,
@@ -8,7 +8,7 @@ import {
8
8
  getToolsWithCapability,
9
9
  invalidateRegistryCache,
10
10
  mergeToolDescriptors
11
- } from "./chunk-RJ2NIMTP.js";
11
+ } from "./chunk-QTJFKXSU.js";
12
12
  import "./chunk-QGM4M3NI.js";
13
13
  export {
14
14
  buildRegistry,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@larkup/cli",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },
@@ -15,18 +15,18 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@ai-sdk/cohere": "^4.0.58",
19
- "@ai-sdk/deepseek": "^3.0.62",
20
- "@ai-sdk/gateway": "^4.0.108",
21
- "@ai-sdk/google": "^4.0.92",
22
- "@ai-sdk/mistral": "^4.0.61",
23
- "@ai-sdk/openai": "^4.0.89",
24
- "@ai-sdk/openai-compatible": "^3.0.66",
18
+ "@ai-sdk/cohere": "^4.0.61",
19
+ "@ai-sdk/deepseek": "^3.0.65",
20
+ "@ai-sdk/gateway": "^4.0.114",
21
+ "@ai-sdk/google": "^4.0.96",
22
+ "@ai-sdk/mistral": "^4.0.64",
23
+ "@ai-sdk/openai": "^4.0.94",
24
+ "@ai-sdk/openai-compatible": "^3.0.69",
25
25
  "@clack/prompts": "^1.7.0",
26
26
  "@lancedb/lancedb": "^0.40.0",
27
- "@napi-rs/canvas": "1.0.10",
27
+ "@napi-rs/canvas": "1.0.11",
28
28
  "@pinecone-database/pinecone": "^9.0.0",
29
- "ai": "^7.0.133",
29
+ "ai": "^7.0.141",
30
30
  "apache-arrow": "18.1.0",
31
31
  "chalk": "^6.0.0",
32
32
  "chromadb": "^3.5.0",
@@ -35,12 +35,12 @@
35
35
  "mammoth": "^1.12.0",
36
36
  "pdf-parse": "2.4.5",
37
37
  "zod": "^4.4.3",
38
- "@larkup/core": "0.7.4",
38
+ "@larkup/core": "0.8.0",
39
39
  "@larkup/vector-stores": "0.1.27",
40
- "@larkup/marketplace": "0.3.8"
40
+ "@larkup/marketplace": "0.3.9"
41
41
  },
42
42
  "devDependencies": {
43
- "tsup": "^8.5.1",
43
+ "tsup": "^9.0.0",
44
44
  "tsx": "^4.23.5",
45
45
  "typescript": "^7.0.2"
46
46
  },