@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
package/src/types.ts CHANGED
@@ -1,47 +1,162 @@
1
1
  /**
2
2
  * Marketplace type contracts.
3
- *
4
- * These types define the plugin/tool system that powers the Larkup Hub.
5
- * Tools are optional features users can install from the marketplace UI.
6
- *
7
- * Architecture:
8
- * - Tools are standalone npm packages published as `@larkup/tool-*`
9
- * - Each package ships a `tool.manifest.json` describing its capabilities
10
- * - Install downloads real packages into `.larkup/tools/node_modules/`
11
- * - The Hub API (apps/hub) serves the remote catalog and tracks installs
12
- * - The loader resolves installed tools at runtime from the isolated dir
13
3
  */
14
4
 
15
- /* ------------------------------------------------------------------ */
16
- /* Tool lifecycle */
17
- /* ------------------------------------------------------------------ */
18
-
19
5
  export type ToolStatus = 'available' | 'installing' | 'installed' | 'error';
20
6
 
21
7
  export type ToolCategory =
22
- | 'media'
23
- | 'search'
24
- | 'analytics'
25
- | 'integration'
26
- | 'embedding'
27
- | 'ai'
28
- | 'automation'
29
- | 'utility';
8
+ 'media' | 'search' | 'analytics' | 'integration' | 'embedding' | 'ai' | 'automation' | 'utility';
30
9
 
31
10
  export type ToolPricing = 'free' | 'pro' | 'enterprise';
11
+ /** Controls who can discover and install a published Marketplace tool. */
12
+ export type ToolDistribution = 'public' | 'private';
13
+
14
+ /** A native process is a local runtime launched without a container engine. */
15
+ export type ToolRuntimeMode =
16
+ 'local' | 'local-docker' | 'local-process' | 'managed-cloud' | 'custom-remote';
17
+
18
+ export interface ToolRuntimeModeDescriptor {
19
+ id: ToolRuntimeMode;
20
+ label: string;
21
+ description: string;
22
+ /** Optional visual mark shown by host runtime pickers. */
23
+ icon?: string;
24
+ /** Config field that contains the remote endpoint for remote modes. */
25
+ endpointConfigKey?: string;
26
+ /** Config field that contains the bearer credential for remote modes. */
27
+ credentialConfigKey?: string;
28
+ /** OCI image used by a local or self-hosted runtime. */
29
+ image?: string;
30
+ /** Relative path to a compose file shipped by the npm package. */
31
+ composeFile?: string;
32
+ requiresGpu?: boolean;
33
+ /** Shown before a local runtime is enabled, e.g. its image download size. */
34
+ setupNotice?: string;
35
+ }
36
+
37
+ export interface ToolRuntimeDescriptor {
38
+ protocolVersion: string;
39
+ defaultMode: ToolRuntimeMode;
40
+ modes: ToolRuntimeModeDescriptor[];
41
+ healthPath?: string;
42
+ }
43
+
44
+ export interface ToolEntrypoints {
45
+ /** Server-safe module export containing the ToolExtension contract. */
46
+ server: string;
47
+ /** Optional agent tool registration export. */
48
+ agent?: string;
49
+ /** Optional browser bundle. Third-party bundles must be sandboxed by the host. */
50
+ ui?: string;
51
+ }
52
+
53
+ export interface ToolMeterDescriptor {
54
+ id: string;
55
+ unit: string;
56
+ description: string;
57
+ }
58
+
59
+ export interface ToolBillingDescriptor {
60
+ model: 'free' | 'subscription' | 'usage' | 'hybrid';
61
+ meters: ToolMeterDescriptor[];
62
+ /** Billing stays provider-neutral; a future payment service maps plans to entitlements. */
63
+ entitlementVersion: string;
64
+ }
65
+
66
+ export interface ToolUsageField {
67
+ key: string;
68
+ label: string;
69
+ format?: 'number' | 'minutes';
70
+ }
71
+
72
+ export interface ToolUsageVisualization {
73
+ usedKey: string;
74
+ limitKey: string;
75
+ }
76
+
77
+ /** Tool-declared support request metadata rendered by the generic host UI. */
78
+ export interface ToolUsageSupport {
79
+ contactLabel?: string;
80
+ description?: string;
81
+ /** Config key containing the safe-to-share installation identifier. */
82
+ userIdConfigKey?: string;
83
+ }
84
+
85
+ /** Declarative usage values a tool client exposes through the host. */
86
+ export interface ToolUsageDescriptor {
87
+ label?: string;
88
+ fields: ToolUsageField[];
89
+ /** Limit a metered usage panel to the runtime modes where it applies. */
90
+ visibleWhenRuntimeMode?: ToolRuntimeMode[];
91
+ visualization?: ToolUsageVisualization;
92
+ support?: ToolUsageSupport;
93
+ }
94
+
95
+ export interface ToolUiSurface {
96
+ id: string;
97
+ slot: 'data-indexing' | 'settings' | 'chat-result' | 'asset-actions';
98
+ title: string;
99
+ description?: string;
100
+ entrypoint?: string;
101
+ /** Media kinds a data-indexing surface can collect inputs for. */
102
+ appliesTo?: Array<'image' | 'video' | 'audio'>;
103
+ /** Declarative form rendered by the host; tool code and copy stay with the tool. */
104
+ form?: {
105
+ submitLabel?: string;
106
+ fields: Array<{
107
+ key: string;
108
+ type: 'textarea' | 'select' | 'checkbox';
109
+ label: string;
110
+ description?: string;
111
+ placeholder?: string;
112
+ defaultValue?: string | boolean;
113
+ options?: Array<{
114
+ label: string;
115
+ value: string;
116
+ description?: string;
117
+ /** Declarative companion values selected with this option. */
118
+ setValues?: Record<string, string | boolean>;
119
+ }>;
120
+ requiredWhen?: { field: string; equals: string | boolean };
121
+ }>;
122
+ };
123
+ /**
124
+ * Optional, tool-declared workload estimates. The host supplies the source
125
+ * duration and renders these provider-neutral values in its generic form.
126
+ */
127
+ estimate?: {
128
+ modeField: string;
129
+ variants: Array<{
130
+ value: string;
131
+ analyzedFramesPerSourceMinute: number;
132
+ ocrFramesPerSourceMinute: number;
133
+ processingSecondsPerSourceMinute: number;
134
+ maxProcessingSecondsPerSourceMinute?: number;
135
+ fixedOverheadSeconds?: number;
136
+ maxFixedOverheadSeconds?: number;
137
+ creditsPerSourceMinute: number;
138
+ }>;
139
+ };
140
+ }
141
+
142
+ export interface ToolUiDescriptor {
143
+ isolation: 'sandboxed-iframe' | 'host';
144
+ surfaces: ToolUiSurface[];
145
+ }
32
146
 
33
- /* ------------------------------------------------------------------ */
34
- /* Tool descriptor (the registry entry / manifest schema) */
35
- /* ------------------------------------------------------------------ */
147
+ export interface ToolPermissions {
148
+ fsRead?: boolean;
149
+ fsWrite?: boolean;
150
+ exec?: boolean;
151
+ httpAllow?: string[];
152
+ }
36
153
 
37
154
  /**
38
- * The canonical shape for every marketplace tool. Each tool defines
39
- * one of these — either hardcoded in the registry or loaded from a
40
- * `tool.manifest.json` file inside the package (future).
41
- *
42
- * Schema version: 1.0
155
+ * The canonical shape for every marketplace tool.
43
156
  */
44
157
  export interface ToolDescriptor {
158
+ manifestVersion?: '1.0' | '2.0' | '3.0';
159
+ kind?: 'tool';
45
160
  /** Unique identifier: "video-audio", "clip-embeddings", etc. */
46
161
  id: string;
47
162
  /** User-facing display name */
@@ -54,8 +169,8 @@ export interface ToolDescriptor {
54
169
  version: string;
55
170
  /** Current pricing tier — "free" for all launch tools */
56
171
  pricing: ToolPricing;
57
-
58
- /* ---- Icon system (priority: emoji > iconUrl > icon) ------------ */
172
+ /** Public tools are catalog-visible; private tools require a Hub workspace grant. */
173
+ distribution?: ToolDistribution;
59
174
 
60
175
  /** Emoji icon for lightweight display (e.g., "🎬"). Primary choice. */
61
176
  emoji?: string;
@@ -67,26 +182,25 @@ export interface ToolDescriptor {
67
182
  /** Lucide icon name — fallback when no emoji/image is set */
68
183
  icon: string;
69
184
 
70
- /* ---- Package metadata ------------------------------------------ */
71
-
72
185
  /** npm package name or "built-in" */
73
186
  packageName: string;
74
187
  /** Approximate install size for user display */
75
188
  installSize: string;
76
189
  /** System dependencies required (e.g., "ffmpeg") */
77
190
  systemDeps?: string[];
191
+ /**
192
+ * Whether this tool must run in an isolated code-execution sandbox. Omitted
193
+ * legacy manifests are normalized to `true` by the Hub.
194
+ */
195
+ requiresSandbox?: boolean;
78
196
  /** Author / publisher */
79
197
  author: string;
80
198
 
81
- /* ---- Capabilities & config ------------------------------------- */
82
-
83
199
  /** Features this tool provides (used by core to route work) */
84
200
  capabilities: string[];
85
201
  /** Tool-specific configuration schema */
86
202
  configSchema?: ToolConfigField[];
87
203
 
88
- /* ---- Marketplace metadata -------------------------------------- */
89
-
90
204
  /** Tags for search and filtering (e.g., ["transcription", "ffmpeg"]) */
91
205
  tags?: string[];
92
206
  /** Total download/install count (local tracking; future: remote API) */
@@ -102,10 +216,20 @@ export interface ToolDescriptor {
102
216
  /** Last updated date (ISO 8601) */
103
217
  updatedAt?: string;
104
218
 
105
- /* ---- Flags ----------------------------------------------------- */
106
-
107
219
  /** Whether this tool is a placeholder (coming soon) */
108
220
  comingSoon?: boolean;
221
+ trustLevel?: 'sandboxed' | 'elevated';
222
+ permissions?: ToolPermissions;
223
+ /** Optional v3 extension entrypoints loaded only after installation. */
224
+ entrypoints?: ToolEntrypoints;
225
+ /** Local Docker, managed cloud, and custom remote runtime choices. */
226
+ runtime?: ToolRuntimeDescriptor;
227
+ /** Provider-neutral metering contract for subscriptions and pay-as-you-go. */
228
+ billing?: ToolBillingDescriptor;
229
+ /** Optional, manifest-driven usage summary for installed-tool settings. */
230
+ usage?: ToolUsageDescriptor;
231
+ /** UI surfaces contributed by the installed tool. */
232
+ ui?: ToolUiDescriptor;
109
233
  }
110
234
 
111
235
  export interface ToolConfigField {
@@ -115,19 +239,51 @@ export interface ToolConfigField {
115
239
  defaultValue?: string;
116
240
  help?: string;
117
241
  required?: boolean;
118
- options?: { label: string; value: string }[];
242
+ options?: ToolConfigOption[];
243
+ /** For a model selector, the provider field used to filter its options. */
244
+ providerField?: string;
245
+ /** Provider-specific defaults used when the saved model belongs to another provider. */
246
+ defaultValueByProvider?: Record<string, string>;
247
+ /** Optional host AI Models key used as this field's unsaved default. */
248
+ globalConfigKey?: 'visionProvider' | 'chatProvider';
249
+ /** Uses a workspace AI setting as the unsaved default without writing to it. */
250
+ defaultFromGlobalConfigKey?: 'visionProvider' | 'chatProvider' | 'visionModelId' | 'chatModelId';
251
+ /** Optional visual group. Settings forms render each group in its own card. */
252
+ group?: string;
253
+ /** Declarative verification request. Omit it to hide Verify for this field. */
254
+ verification?: ToolConfigVerification;
255
+ /** Preferred desktop width in a schema-driven settings grid. */
256
+ layout?: 'full' | 'half';
257
+ /** Render this field only when another configuration field has a matching value. */
258
+ visibleWhen?: {
259
+ field: string;
260
+ equals: string | boolean | Array<string | boolean>;
261
+ };
262
+ /**
263
+ * Set by the tool's own backend (e.g. device provisioning), never by the
264
+ * client. Settings forms must not render an input for it, and config
265
+ * saves must not let a client request overwrite or clear it.
266
+ */
267
+ serverManaged?: boolean;
268
+ /** Render a server-managed value as a non-editable status value. */
269
+ readOnly?: boolean;
119
270
  }
120
271
 
121
- /* ------------------------------------------------------------------ */
122
- /* Installed tool state (persisted to disk) */
123
- /* ------------------------------------------------------------------ */
272
+ export interface ToolConfigOption {
273
+ label: string;
274
+ value: string;
275
+ /** Short text shown with the option; longer text moves into the hover hint. */
276
+ description?: string;
277
+ icon?: string;
278
+ image?: string;
279
+ }
124
280
 
125
- /**
126
- * Where the tool was installed from.
127
- * - `registry`: Downloaded from npm / Hub API (the standard path)
128
- * - `local`: Workspace package (monorepo development mode)
129
- * - `sandbox`: Installed inside a remote sandbox (E2B / Modal)
130
- */
281
+ export interface ToolConfigVerification {
282
+ endpoint: string;
283
+ method?: 'POST' | 'PUT';
284
+ /** Maps request keys to config field keys. "$value" is the current field. */
285
+ fields?: Record<string, string>;
286
+ }
131
287
  export type ToolSource = 'registry' | 'local' | 'sandbox';
132
288
 
133
289
  export interface InstalledTool {
@@ -136,12 +292,7 @@ export interface InstalledTool {
136
292
  installedAt: string;
137
293
  /** npm package name (e.g., "@larkup/tool-video-audio") */
138
294
  packageName: string;
139
- /**
140
- * Absolute path to the resolved module entry point.
141
- * Set after install — used by the loader for `import(resolvedPath)`.
142
- * For local (monorepo) installs, this is the workspace path.
143
- * For registry installs, this is inside `.larkup/tools/node_modules/`.
144
- */
295
+ /** Absolute path to the resolved module entry point. */
145
296
  resolvedPath: string;
146
297
  /** Where this tool was installed from */
147
298
  source: ToolSource;
@@ -156,17 +307,8 @@ export interface InstalledToolsManifest {
156
307
  updatedAt: string;
157
308
  }
158
309
 
159
- /* ------------------------------------------------------------------ */
160
- /* Install progress */
161
- /* ------------------------------------------------------------------ */
162
-
163
310
  export type InstallStage =
164
- | 'checking-deps'
165
- | 'downloading'
166
- | 'installing'
167
- | 'configuring'
168
- | 'completed'
169
- | 'failed';
311
+ 'checking-deps' | 'downloading' | 'installing' | 'configuring' | 'completed' | 'failed';
170
312
 
171
313
  export interface InstallProgress {
172
314
  toolId: string;
@@ -177,23 +319,11 @@ export interface InstallProgress {
177
319
  error?: string;
178
320
  }
179
321
 
180
- /* ------------------------------------------------------------------ */
181
- /* Deployment target */
182
- /* ------------------------------------------------------------------ */
183
-
184
322
  /**
185
323
  * Determines how tool installation and loading behaves.
186
- * - `local`: User's machine (CLI, Desktop, or `pnpm run dev`)
187
- * - `docker`: Inside a Docker container (VPS / self-hosted)
188
- * - `serverless`: Vercel / AWS Lambda (cannot install at runtime)
189
- * - `sandbox`: E2B / Modal sandbox (ephemeral, can install dynamically)
190
324
  */
191
325
  export type DeploymentTarget = 'local' | 'docker' | 'serverless' | 'sandbox';
192
326
 
193
- /* ------------------------------------------------------------------ */
194
- /* Hub API configuration */
195
- /* ------------------------------------------------------------------ */
196
-
197
327
  export interface HubConfig {
198
328
  /** Base URL of the Hub API (e.g., "https://hub.larkup.de") */
199
329
  baseUrl: string;
@@ -204,15 +334,6 @@ export interface HubConfig {
204
334
  /** Default Hub API URL. Can be overridden via LARKUP_HUB_URL env var. */
205
335
  export const DEFAULT_HUB_URL = process.env.LARKUP_HUB_URL ?? 'https://hub.larkup.de';
206
336
 
207
- /* ------------------------------------------------------------------ */
208
- /* Storage provider abstraction */
209
- /* ------------------------------------------------------------------ */
210
-
211
- /**
212
- * Abstraction over where media files are stored. Ships with a local
213
- * provider; cloud providers (S3, UploadThing, GCS) can be added later
214
- * without changing any upstream code.
215
- */
216
337
  export interface StorageProvider {
217
338
  id: string;
218
339
  name: string;
@@ -224,6 +345,15 @@ export interface StorageProvider {
224
345
  retrieve(uri: string): Promise<Buffer>;
225
346
  /** Resolve a URI to a local file without buffering it in memory, when supported. */
226
347
  resolvePath?(uri: string): Promise<string | undefined>;
348
+ /**
349
+ * A short-lived, range-capable HTTPS URL for this file, when the backing
350
+ * store supports direct remote access (S3). A bounded caller (FFmpeg
351
+ * seeking a range for watch_original, a remote GPU worker) can fetch just
352
+ * the bytes it needs through this URL instead of a full local download.
353
+ * Absent for stores with no such notion (local disk) -- callers fall back
354
+ * to resolvePath/retrieve.
355
+ */
356
+ getReadUrl?(uri: string, expiresInSecs: number): Promise<string | undefined>;
227
357
  /** Delete a file by its storage URI */
228
358
  delete(uri: string): Promise<void>;
229
359
  /** Get storage usage stats */
@@ -0,0 +1,13 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ['src/**/*.test.ts'],
6
+ // src/db/** requires a real Postgres connection and already has its own
7
+ // dedicated runner (`pnpm db:test`, db/vitest.config.ts) -- keep it out
8
+ // of the default `pnpm test` so this doesn't fail without a database.
9
+ exclude: ['node_modules/**', 'db/**', 'src/db/**'],
10
+ environment: 'node',
11
+ fileParallelism: false,
12
+ },
13
+ });