@larkup/marketplace 0.1.24 → 0.2.0

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 (40) hide show
  1. package/.env.example +3 -0
  2. package/CHANGELOG.md +180 -0
  3. package/README.md +34 -0
  4. package/db/drizzle/0000_hesitant_joseph.sql +69 -0
  5. package/db/drizzle/0001_deep_phil_sheldon.sql +1 -0
  6. package/db/drizzle/0002_jittery_living_mummy.sql +18 -0
  7. package/db/drizzle/meta/0000_snapshot.json +483 -0
  8. package/db/drizzle/meta/0001_snapshot.json +490 -0
  9. package/db/drizzle/meta/0002_snapshot.json +615 -0
  10. package/db/drizzle/meta/_journal.json +27 -0
  11. package/db/drizzle.config.ts +19 -0
  12. package/db/tsconfig.build.json +11 -0
  13. package/db/tsconfig.json +17 -0
  14. package/db/vitest.config.ts +11 -0
  15. package/package.json +31 -4
  16. package/src/db/builtin-tools.ts +613 -0
  17. package/src/db/client.ts +26 -0
  18. package/src/db/repo.test.ts +309 -0
  19. package/src/db/repo.ts +558 -0
  20. package/src/db/schema/audit.ts +27 -0
  21. package/src/db/schema/extensions.ts +73 -0
  22. package/src/db/schema/index.ts +5 -0
  23. package/src/db/schema/installations.ts +23 -0
  24. package/src/db/schema/publishers.ts +13 -0
  25. package/src/db/schema/versions.ts +22 -0
  26. package/src/db/seed.ts +33 -0
  27. package/src/db/validate.test.ts +79 -0
  28. package/src/db/validate.ts +84 -0
  29. package/src/output-sanitizer.test.ts +17 -0
  30. package/src/output-sanitizer.ts +8 -0
  31. package/src/storage-provider-s3.test.ts +110 -0
  32. package/src/storage-provider.ts +164 -13
  33. package/src/tool-extension.ts +247 -0
  34. package/src/tool-installer.ts +80 -109
  35. package/src/tool-loader.test.ts +120 -0
  36. package/src/tool-loader.ts +99 -37
  37. package/src/tool-manifest.schema.ts +89 -32
  38. package/src/tool-registry.ts +34 -111
  39. package/src/types.ts +217 -87
  40. package/vitest.config.ts +13 -0
@@ -2,46 +2,65 @@ import { promises as fs } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import type { InstalledTool } from './types';
5
- import { getInstalledTool } from './tool-installer';
5
+ import { getInstalledTool, resolveWorkspaceToolPath } from './tool-installer';
6
6
 
7
7
  /**
8
8
  * Dynamic tool loader — loads an installed tool's module at runtime.
9
- *
10
- * Resolution strategy:
11
- * ─────────────────────────────────────────────────────────────────────
12
- * 1. Check if the tool is recorded in `installed.json`
13
- * 2. Use the `resolvedPath` from the install record:
14
- * - For `local` (workspace): points to the monorepo package
15
- * - For `registry` (npm): points to `.larkup/tools/node_modules/...`
16
- * - For `sandbox`: points to the sandbox's tool directory
17
- * 3. Dynamic `import()` the resolved path
18
- * 4. Cache the module for the lifetime of the process
19
- * ─────────────────────────────────────────────────────────────────────
20
- *
21
- * Heavy dependencies (ffmpeg bindings, whisper, pdf-lib, etc.) are
22
- * only loaded when the tool is actually invoked via this loader.
23
9
  */
24
10
 
25
- const moduleCache = new Map<string, any>();
11
+ const moduleCache = new Map<string, { installationKey: string; module: unknown }>();
12
+
13
+ // A tool's compiled entry can still transitively import a workspace package
14
+ // (e.g. `@larkup/core`) whose own exports point at its raw TypeScript source
15
+ // for bundler consumers -- Node's native ESM resolver cannot follow that or
16
+ // the extension-less relative imports inside it. A namespaced tsx loader
17
+ // (already a resolvable dependency here) is scoped to only this import path,
18
+ // so it does not affect module resolution anywhere else in the process.
19
+ type ScopedImport = (specifier: string, parent: string) => Promise<unknown>;
20
+ const scopedImports = new Map<string, ScopedImport>();
21
+
22
+ /**
23
+ * A query string busts the cache for the *entry* module only -- the relative
24
+ * imports inside it resolve to plain paths Node has already cached, so a
25
+ * rebuilt tool kept serving its old implementation with only a fresh
26
+ * entry wrapper around it. Each namespace has its own module registry, so
27
+ * giving a rebuilt workspace tool a new namespace reloads the whole subgraph.
28
+ * Published installs are immutable and keep one namespace for the process.
29
+ */
30
+ async function getScopedImport(revision: string) {
31
+ const namespace = `larkup-marketplace-tools${revision === 'fixed' ? '' : `-${revision}`}`;
32
+ const existing = scopedImports.get(namespace);
33
+ if (existing) return existing;
34
+ const { register } = await import(/* webpackIgnore: true */ 'tsx/esm/api');
35
+ const importer = register({ namespace }).import as ScopedImport;
36
+ // Only the newest build of a given tool is ever imported again; keeping
37
+ // every namespace a long dev session produced would retain each one's
38
+ // module registry for the life of the process.
39
+ if (scopedImports.size >= 8) {
40
+ scopedImports.delete(scopedImports.keys().next().value as string);
41
+ }
42
+ scopedImports.set(namespace, importer);
43
+ return importer;
44
+ }
26
45
 
27
46
  /**
28
47
  * Load a tool's exported API. Returns `null` if the tool is not installed.
29
- *
30
- * The returned object is whatever the tool's entry point exports —
31
- * each tool defines its own public surface.
32
48
  */
33
49
  export async function loadTool<T = any>(toolId: string): Promise<T | null> {
34
- // Check cache first
35
- if (moduleCache.has(toolId)) return moduleCache.get(toolId) as T;
36
-
37
50
  const installed = await getInstalledTool(toolId);
38
51
  if (!installed) return null;
52
+ // Determine what to import
53
+ const importPath = await resolveImportPath(installed);
54
+ const revision = await entryRevision(installed, importPath);
55
+ const installationKey = `${installed.source}:${installed.resolvedPath}:${installed.version}:${installed.installedAt}:${revision}`;
56
+ const cached = moduleCache.get(toolId);
57
+ if (cached?.installationKey === installationKey) return cached.module as T;
39
58
 
40
59
  try {
41
- // Determine what to import
42
- const importPath = await resolveImportPath(installed);
43
- const mod = await import(/* webpackIgnore: true */ importPath);
44
- moduleCache.set(toolId, mod);
60
+ const busted = cacheBustFileImport(importPath, installationKey);
61
+ const importer = await getScopedImport(revision);
62
+ const mod = await importer(busted, import.meta.url);
63
+ moduleCache.set(toolId, { installationKey, module: mod });
45
64
  return mod as T;
46
65
  } catch (err) {
47
66
  console.error(`[marketplace] Failed to load tool "${toolId}":`, err);
@@ -49,28 +68,71 @@ export async function loadTool<T = any>(toolId: string): Promise<T | null> {
49
68
  }
50
69
  }
51
70
 
71
+ /**
72
+ * A workspace tool is developed in place: its entry is rebuilt from source
73
+ * while the host keeps running, and nothing about the *installation* changes
74
+ * when that happens. Node's ESM cache is process-wide and unaffected by the
75
+ * host's own hot reload, so without this a rebuilt tool kept serving the
76
+ * build that was current when the server started. Published installs are
77
+ * immutable, so they keep the cheaper key.
78
+ */
79
+ async function entryRevision(installed: InstalledTool, importPath: string): Promise<string> {
80
+ if (installed.source !== 'local' || !importPath.startsWith('file:')) return 'fixed';
81
+ try {
82
+ // The whole build output, not just the entry: a change is far more often
83
+ // in a module the entry re-exports than in the entry file itself.
84
+ const directory = path.dirname(new URL(importPath).pathname);
85
+ const files = await fs.readdir(directory, { withFileTypes: true });
86
+ let newest = 0;
87
+ let total = 0;
88
+ for (const file of files) {
89
+ if (!file.isFile()) continue;
90
+ const { mtimeMs, size } = await fs.stat(path.join(directory, file.name));
91
+ newest = Math.max(newest, mtimeMs);
92
+ total += size;
93
+ }
94
+ return newest > 0 ? `${newest}-${total}` : 'fixed';
95
+ } catch {
96
+ return 'fixed';
97
+ }
98
+ }
99
+
100
+ /** A reinstall may keep the same local path, so key file imports by installation too. */
101
+ function cacheBustFileImport(importPath: string, installationKey: string): string {
102
+ if (!importPath.startsWith('file:')) return importPath;
103
+ const url = new URL(importPath);
104
+ url.searchParams.set('larkup-installation', installationKey);
105
+ return url.href;
106
+ }
107
+
52
108
  /**
53
109
  * Resolve the import path for a tool based on its install source.
54
- *
55
- * - `local` (workspace): import by package name (Node resolves via workspace symlink)
56
- * - `registry` (npm): import from the isolated node_modules via absolute path
57
- * - `sandbox`: import from the sandbox tool path
58
110
  */
59
111
  async function resolveImportPath(installed: InstalledTool): Promise<string> {
60
112
  switch (installed.source) {
61
- case 'local':
62
- // In monorepo, the package name resolves via pnpm workspace linking
63
- return installed.packageName;
113
+ case 'local': {
114
+ // Workspace tools are recorded with their absolute package directory so
115
+ // Next.js can load them even when pnpm has not linked the package into
116
+ // the app's node_modules tree yet. Older manifests still fall back to
117
+ // the package specifier.
118
+ try {
119
+ await fs.access(path.join(installed.resolvedPath, 'package.json'));
120
+ return resolvePackageEntry(installed.resolvedPath);
121
+ } catch {
122
+ // Local manifest entries can outlive a workspace directory rename.
123
+ // Re-discover the package before asking Node to resolve its specifier
124
+ // from the host app's node_modules directory.
125
+ const workspacePath = await resolveWorkspaceToolPath(installed.packageName);
126
+ if (workspacePath) return resolvePackageEntry(workspacePath);
127
+ return installed.packageName;
128
+ }
129
+ }
64
130
 
65
131
  case 'registry':
66
132
  case 'sandbox':
67
- // Node ESM cannot import a package directory by absolute path. Resolve
68
- // the package's declared ESM entry so isolated marketplace installs work
69
- // the same way as a normal package-name import.
70
133
  return resolvePackageEntry(installed.resolvedPath);
71
134
 
72
135
  default:
73
- // Fallback: try package name (backwards compat)
74
136
  return installed.packageName;
75
137
  }
76
138
  }
@@ -1,20 +1,10 @@
1
- import type { ToolDescriptor, ToolCategory, ToolPricing } from './types';
1
+ import type { ToolDescriptor, ToolCategory, ToolDistribution, ToolPricing } from './types';
2
2
 
3
3
  /**
4
4
  * Tool manifest schema validation.
5
- *
6
- * Provides a validation utility for `tool.manifest.json` files.
7
- * Contributors creating new tools can validate their manifest
8
- * against this schema to ensure correctness before publishing.
9
- *
10
- * Schema version: 1.0
11
5
  */
12
6
 
13
- /* ------------------------------------------------------------------ */
14
- /* Constants */
15
- /* ------------------------------------------------------------------ */
16
-
17
- export const MANIFEST_SCHEMA_VERSION = '1.0';
7
+ export const MANIFEST_SCHEMA_VERSION = '3.0';
18
8
 
19
9
  export const VALID_CATEGORIES: ToolCategory[] = [
20
10
  'media',
@@ -28,36 +18,18 @@ export const VALID_CATEGORIES: ToolCategory[] = [
28
18
  ];
29
19
 
30
20
  export const VALID_PRICING_TIERS: ToolPricing[] = ['free', 'pro', 'enterprise'];
21
+ export const VALID_DISTRIBUTIONS: ToolDistribution[] = ['public', 'private'];
31
22
 
32
23
  export const VALID_CONFIG_FIELD_TYPES = ['text', 'password', 'select', 'toggle'] as const;
33
24
 
34
- /* ------------------------------------------------------------------ */
35
- /* Validation result */
36
- /* ------------------------------------------------------------------ */
37
-
38
25
  export interface ManifestValidationResult {
39
26
  valid: boolean;
40
27
  errors: string[];
41
28
  warnings: string[];
42
29
  }
43
30
 
44
- /* ------------------------------------------------------------------ */
45
- /* Validator */
46
- /* ------------------------------------------------------------------ */
47
-
48
31
  /**
49
32
  * Validate a tool manifest object against the ToolDescriptor schema.
50
- *
51
- * @example
52
- * ```typescript
53
- * import { validateToolManifest } from "@larkup/marketplace/manifest"
54
- * import manifest from "./tool.manifest.json"
55
- *
56
- * const result = validateToolManifest(manifest)
57
- * if (!result.valid) {
58
- * console.error("Manifest errors:", result.errors)
59
- * }
60
- * ```
61
33
  */
62
34
  export function validateToolManifest(manifest: Record<string, unknown>): ManifestValidationResult {
63
35
  const errors: string[] = [];
@@ -95,6 +67,13 @@ export function validateToolManifest(manifest: Record<string, unknown>): Manifes
95
67
  errors.push(`"pricing" must be one of: ${VALID_PRICING_TIERS.join(', ')}`);
96
68
  }
97
69
 
70
+ if (
71
+ manifest.distribution !== undefined &&
72
+ !VALID_DISTRIBUTIONS.includes(manifest.distribution as ToolDistribution)
73
+ ) {
74
+ errors.push(`"distribution" must be one of: ${VALID_DISTRIBUTIONS.join(', ')}`);
75
+ }
76
+
98
77
  // version semver-ish check
99
78
  if (typeof manifest.version === 'string' && !/^\d+\.\d+\.\d+/.test(manifest.version)) {
100
79
  errors.push(`"version" should follow semver format (e.g., "0.1.0")`);
@@ -127,6 +106,37 @@ export function validateToolManifest(manifest: Record<string, unknown>): Manifes
127
106
  }
128
107
  }
129
108
 
109
+ if (manifest.requiresSandbox !== undefined && typeof manifest.requiresSandbox !== 'boolean') {
110
+ errors.push(`"requiresSandbox" must be a boolean`);
111
+ }
112
+
113
+ if (manifest.manifestVersion === '3.0') {
114
+ if (manifest.kind !== 'tool') errors.push(`v3 manifests must set "kind" to "tool"`);
115
+ const entrypoints = manifest.entrypoints as Record<string, unknown> | undefined;
116
+ if (!entrypoints || typeof entrypoints.server !== 'string') {
117
+ errors.push(`v3 manifests must declare "entrypoints.server"`);
118
+ }
119
+ const runtime = manifest.runtime as Record<string, unknown> | undefined;
120
+ if (
121
+ !runtime ||
122
+ typeof runtime.protocolVersion !== 'string' ||
123
+ typeof runtime.defaultMode !== 'string' ||
124
+ !Array.isArray(runtime.modes) ||
125
+ runtime.modes.length === 0
126
+ ) {
127
+ errors.push(
128
+ `v3 manifests must declare runtime.protocolVersion, runtime.defaultMode, and runtime.modes`,
129
+ );
130
+ }
131
+ const billing = manifest.billing as Record<string, unknown> | undefined;
132
+ if (
133
+ billing &&
134
+ (typeof billing.entitlementVersion !== 'string' || !Array.isArray(billing.meters))
135
+ ) {
136
+ errors.push(`"billing" must declare entitlementVersion and meters`);
137
+ }
138
+ }
139
+
130
140
  if (manifest.configSchema !== undefined) {
131
141
  if (!Array.isArray(manifest.configSchema)) {
132
142
  errors.push(`"configSchema" must be an array`);
@@ -141,6 +151,54 @@ export function validateToolManifest(manifest: Record<string, unknown>): Manifes
141
151
  `configSchema[${i}].type must be one of: ${VALID_CONFIG_FIELD_TYPES.join(', ')}`,
142
152
  );
143
153
  }
154
+ if (field.verification !== undefined) {
155
+ const verification = field.verification as Record<string, unknown>;
156
+ if (typeof verification.endpoint !== 'string' || !verification.endpoint.startsWith('/')) {
157
+ errors.push(`configSchema[${i}].verification.endpoint must be an app-relative path`);
158
+ }
159
+ }
160
+ if (field.serverManaged !== undefined && typeof field.serverManaged !== 'boolean') {
161
+ errors.push(`configSchema[${i}].serverManaged must be a boolean`);
162
+ }
163
+ if (field.readOnly !== undefined && typeof field.readOnly !== 'boolean') {
164
+ errors.push(`configSchema[${i}].readOnly must be a boolean`);
165
+ }
166
+ if (field.providerField !== undefined && typeof field.providerField !== 'string') {
167
+ errors.push(`configSchema[${i}].providerField must be a string`);
168
+ }
169
+ if (
170
+ field.defaultValueByProvider !== undefined &&
171
+ (typeof field.defaultValueByProvider !== 'object' ||
172
+ Array.isArray(field.defaultValueByProvider))
173
+ ) {
174
+ errors.push(`configSchema[${i}].defaultValueByProvider must be an object`);
175
+ }
176
+ if (
177
+ field.globalConfigKey !== undefined &&
178
+ !['visionProvider', 'chatProvider'].includes(String(field.globalConfigKey))
179
+ ) {
180
+ errors.push(`configSchema[${i}].globalConfigKey must name a supported AI provider field`);
181
+ }
182
+ if (
183
+ field.defaultFromGlobalConfigKey !== undefined &&
184
+ !['visionProvider', 'chatProvider', 'visionModelId', 'chatModelId'].includes(
185
+ String(field.defaultFromGlobalConfigKey),
186
+ )
187
+ ) {
188
+ errors.push(
189
+ `configSchema[${i}].defaultFromGlobalConfigKey must name a supported AI provider field`,
190
+ );
191
+ }
192
+ if (field.visibleWhen !== undefined) {
193
+ const visibleWhen = field.visibleWhen as Record<string, unknown>;
194
+ if (
195
+ typeof visibleWhen.field !== 'string' ||
196
+ !('equals' in visibleWhen) ||
197
+ !['string', 'boolean', 'object'].includes(typeof visibleWhen.equals)
198
+ ) {
199
+ errors.push(`configSchema[${i}].visibleWhen must declare field and equals`);
200
+ }
201
+ }
144
202
  }
145
203
  }
146
204
  }
@@ -168,7 +226,6 @@ export function validateToolManifest(manifest: Record<string, unknown>): Manifes
168
226
 
169
227
  /**
170
228
  * Generate a minimal tool manifest template.
171
- * Useful for bootstrapping new tool packages.
172
229
  */
173
230
  export function generateManifestTemplate(toolId: string): Partial<ToolDescriptor> {
174
231
  return {
@@ -5,24 +5,18 @@ import { DEFAULT_HUB_URL } from './types';
5
5
 
6
6
  /**
7
7
  * Tool registry — resolves tool descriptors from multiple sources.
8
- *
9
- * Resolution order:
10
- * 1. Local `tool.manifest.json` files from workspace packages
11
- * 2. Hub API (remote catalog) when available
12
- * 3. Hardcoded fallback for offline / development
13
- *
14
- * In the monorepo, tools under `packages/tools/` ship their own
15
- * `tool.manifest.json`. This registry reads those at startup.
16
- * When the Hub API is live, it supplements with remotely-published tools.
17
8
  */
18
9
 
19
- /* ------------------------------------------------------------------ */
20
- /* Local manifest discovery */
21
- /* ------------------------------------------------------------------ */
22
-
23
10
  /** Cached registry — populated on first access. */
24
11
  let cachedRegistry: Record<string, ToolDescriptor> | null = null;
25
12
 
13
+ /** Kept loadable for installed workspaces, but no longer offered for new installs. */
14
+ const RETIRED_CATALOG_TOOL_IDS = new Set(['video-audio']);
15
+
16
+ function normalizeToolDescriptor(descriptor: ToolDescriptor): ToolDescriptor {
17
+ return { ...descriptor, requiresSandbox: descriptor.requiresSandbox !== false };
18
+ }
19
+
26
20
  /**
27
21
  * Compare the numeric portions of two semver versions. Marketplace manifests
28
22
  * use stable releases, but accepting a suffix keeps a pre-release catalog
@@ -63,20 +57,15 @@ export function mergeToolDescriptors(
63
57
  return merged;
64
58
  }
65
59
 
66
- /**
67
- * Scan workspace tool directories for `tool.manifest.json` files.
68
- * This is used in monorepo development and in Docker builds where
69
- * tools are bundled at build time.
70
- */
71
60
  async function discoverLocalManifests(): Promise<Record<string, ToolDescriptor>> {
72
61
  const registry: Record<string, ToolDescriptor> = {};
73
62
 
74
63
  // Try multiple possible tool directories
75
64
  const searchPaths = [
76
- // Monorepo development: packages/tools/*
77
- path.resolve(process.cwd(), 'packages', 'tools'),
65
+ // Monorepo development: packages/marketplace-tools/*
66
+ path.resolve(process.cwd(), 'packages', 'marketplace-tools'),
78
67
  // Next.js dev server runs in apps/web
79
- path.resolve(process.cwd(), '..', '..', 'packages', 'tools'),
68
+ path.resolve(process.cwd(), '..', '..', 'packages', 'marketplace-tools'),
80
69
  // Installed tools: .larkup/tools/node_modules/@larkup
81
70
  path.resolve(process.cwd(), '.larkup', 'tools', 'node_modules', '@larkup'),
82
71
  path.resolve(process.cwd(), '..', '..', '.larkup', 'tools', 'node_modules', '@larkup'),
@@ -92,8 +81,8 @@ async function discoverLocalManifests(): Promise<Record<string, ToolDescriptor>>
92
81
  const manifestPath = path.join(searchPath, entry.name, 'tool.manifest.json');
93
82
  try {
94
83
  const raw = await fs.readFile(manifestPath, 'utf8');
95
- const manifest = JSON.parse(raw) as ToolDescriptor;
96
- if (manifest.id) {
84
+ const manifest = normalizeToolDescriptor(JSON.parse(raw) as ToolDescriptor);
85
+ if (manifest.id && !RETIRED_CATALOG_TOOL_IDS.has(manifest.id)) {
97
86
  registry[manifest.id] = manifest;
98
87
  }
99
88
  } catch {
@@ -108,10 +97,6 @@ async function discoverLocalManifests(): Promise<Record<string, ToolDescriptor>>
108
97
  return registry;
109
98
  }
110
99
 
111
- /* ------------------------------------------------------------------ */
112
- /* Hub API fetching */
113
- /* ------------------------------------------------------------------ */
114
-
115
100
  /**
116
101
  * Fetch the full tool catalog from the remote Hub API.
117
102
  * Falls back gracefully if the Hub is unreachable.
@@ -133,7 +118,9 @@ async function fetchHubCatalog(hubUrl?: string): Promise<Record<string, ToolDesc
133
118
  const data = (await res.json()) as { tools: ToolDescriptor[] };
134
119
  const registry: Record<string, ToolDescriptor> = {};
135
120
  for (const tool of data.tools ?? []) {
136
- if (tool.id) registry[tool.id] = tool;
121
+ if (tool.id && !RETIRED_CATALOG_TOOL_IDS.has(tool.id)) {
122
+ registry[tool.id] = normalizeToolDescriptor(tool);
123
+ }
137
124
  }
138
125
  return registry;
139
126
  } catch {
@@ -149,6 +136,7 @@ export async function fetchToolFromHub(
149
136
  toolId: string,
150
137
  hubUrl?: string,
151
138
  ): Promise<ToolDescriptor | null> {
139
+ if (RETIRED_CATALOG_TOOL_IDS.has(toolId)) return null;
152
140
  const baseUrl = hubUrl ?? DEFAULT_HUB_URL;
153
141
  try {
154
142
  const controller = new AbortController();
@@ -168,81 +156,11 @@ export async function fetchToolFromHub(
168
156
  }
169
157
  }
170
158
 
171
- /* ------------------------------------------------------------------ */
172
- /* Hardcoded fallback (offline safety net) */
173
- /* ------------------------------------------------------------------ */
174
-
175
159
  /**
176
160
  * Minimal hardcoded registry for offline / first-run scenarios
177
- * where neither manifests nor Hub are available. This ensures the
178
- * marketplace always has something to show.
161
+ * where neither manifests nor Hub are available.
179
162
  */
180
163
  const FALLBACK_REGISTRY: Record<string, ToolDescriptor> = {
181
- 'video-audio': {
182
- id: 'video-audio',
183
- name: 'Video Intelligence',
184
- description:
185
- 'Build evidence-backed video timelines with adaptive attention and bounded source rewind.',
186
- category: 'media',
187
- version: '0.3.6',
188
- pricing: 'free',
189
- emoji: '🎬',
190
- icon: 'Film',
191
- packageName: '@larkup/tool-video-audio',
192
- installSize: '~15 MB',
193
- author: 'Larkup',
194
- capabilities: [
195
- 'video-indexing',
196
- 'audio-indexing',
197
- 'transcription',
198
- 'frame-extraction',
199
- 'youtube-import',
200
- 'attention-driven-analysis',
201
- 'temporal-evidence',
202
- 'bounded-source-rewind',
203
- ],
204
- tags: ['video intelligence', 'temporal reasoning', 'transcription', 'ffmpeg', 'video', 'audio'],
205
- downloads: 0,
206
- repositoryUrl: 'https://github.com/Larkup-AI/larkup',
207
- license: 'Apache-2.0',
208
- updatedAt: '2026-07-20',
209
- configSchema: [
210
- {
211
- key: 'frameInterval',
212
- label: 'Baseline coverage interval (seconds)',
213
- type: 'text',
214
- defaultValue: '10',
215
- help: 'Baseline cadence for duration-aware coverage frames; scene changes and a reserved ending pass are added separately.',
216
- },
217
- {
218
- key: 'audioProvider',
219
- label: 'Audio Provider',
220
- type: 'select',
221
- help: 'Choose the provider used only for audio and video transcription.',
222
- options: [
223
- { label: 'OpenAI', value: 'openai' },
224
- { label: 'Groq', value: 'groq' },
225
- { label: 'Deepgram', value: 'deepgram' },
226
- { label: 'ElevenLabs', value: 'elevenlabs' },
227
- { label: 'Local Whisper', value: 'local' },
228
- ],
229
- },
230
- {
231
- key: 'audioLanguage',
232
- label: 'Transcription language',
233
- type: 'text',
234
- defaultValue: 'auto',
235
- help: 'Use auto for provider language detection, or enter a language code such as ar, ar-EG, en, or de to override it.',
236
- },
237
- {
238
- key: 'audioApiKey',
239
- label: 'Audio API Key',
240
- type: 'password',
241
- help: 'Required for the selected audio provider and kept separate from the chat model key.',
242
- },
243
- ],
244
- },
245
-
246
164
  'clip-embeddings': {
247
165
  id: 'clip-embeddings',
248
166
  name: 'CLIP Image Search',
@@ -254,6 +172,7 @@ const FALLBACK_REGISTRY: Record<string, ToolDescriptor> = {
254
172
  icon: 'ScanEye',
255
173
  packageName: '@larkup/tool-clip-embeddings',
256
174
  installSize: '~200 MB',
175
+ requiresSandbox: true,
257
176
  author: 'Larkup',
258
177
  capabilities: ['clip-embeddings', 'image-similarity'],
259
178
  tags: ['clip', 'siglip', 'image-search', 'visual-similarity'],
@@ -276,6 +195,7 @@ const FALLBACK_REGISTRY: Record<string, ToolDescriptor> = {
276
195
  packageName: '@larkup/tool-doc-editor',
277
196
  installSize: '~5 MB',
278
197
  systemDeps: ['docker'],
198
+ requiresSandbox: true,
279
199
  author: 'Larkup',
280
200
  capabilities: ['document-editing', 'form-filling', 'document-preview'],
281
201
  tags: ['pdf', 'docx', 'pptx', 'form', 'canvas', 'editor', 'fill'],
@@ -286,34 +206,37 @@ const FALLBACK_REGISTRY: Record<string, ToolDescriptor> = {
286
206
  },
287
207
  };
288
208
 
289
- /* ------------------------------------------------------------------ */
290
- /* Public API */
291
- /* ------------------------------------------------------------------ */
292
-
293
209
  /**
294
- * Build the full tool registry by merging sources.
295
- * Priority: local manifests > Hub API > hardcoded fallback.
210
+ * Build the full tool registry by merging sources. The deployed Hub is the
211
+ * source of truth in normal operation; local manifests are a development and
212
+ * offline recovery path, never a silent production override.
296
213
  * Cached after first call for the process lifetime.
297
214
  */
298
215
  export async function buildRegistry(opts?: {
299
216
  hubUrl?: string;
300
217
  skipHub?: boolean;
218
+ preferLocal?: boolean;
301
219
  }): Promise<Record<string, ToolDescriptor>> {
302
220
  if (cachedRegistry) return cachedRegistry;
303
221
 
304
222
  // Start with hardcoded fallback.
305
223
  let registry = { ...FALLBACK_REGISTRY };
306
224
 
307
- // Layer Hub API catalog over the offline fallback.
225
+ // Layer Hub API catalog over the offline fallback. A non-empty response is
226
+ // authoritative so every client sees the Neon-backed catalog consistently.
227
+ let hubAvailable = false;
308
228
  if (!opts?.skipHub) {
309
229
  const hubCatalog = await fetchHubCatalog(opts?.hubUrl);
310
- registry = mergeToolDescriptors(registry, hubCatalog);
230
+ if (Object.keys(hubCatalog).length > 0) {
231
+ registry = mergeToolDescriptors(registry, hubCatalog);
232
+ hubAvailable = true;
233
+ }
311
234
  }
312
235
 
313
- // A local workspace manifest wins on equal versions, while an older
314
- // installed package cannot hide a newer catalog release that repairs it.
315
- const localManifests = await discoverLocalManifests();
316
- registry = mergeToolDescriptors(registry, localManifests);
236
+ if (!hubAvailable || opts?.preferLocal) {
237
+ const localManifests = await discoverLocalManifests();
238
+ registry = mergeToolDescriptors(registry, localManifests);
239
+ }
317
240
 
318
241
  cachedRegistry = registry;
319
242
  return registry;