@jini-ai/http-kit 0.4.1 → 0.4.2
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.
- package/CHANGELOG.md +4 -0
- package/package.json +7 -7
- package/dist/active-context.d.ts +0 -99
- package/dist/active-context.js +0 -77
- package/dist/agents.d.ts +0 -64
- package/dist/agents.js +0 -23
- package/dist/attachments.d.ts +0 -534
- package/dist/attachments.js +0 -1032
- package/dist/cancel-owned-runs.d.ts +0 -44
- package/dist/cancel-owned-runs.js +0 -35
- package/dist/component-catalog.d.ts +0 -74
- package/dist/component-catalog.js +0 -74
- package/dist/connectors.d.ts +0 -165
- package/dist/connectors.js +0 -474
- package/dist/daemon-status.d.ts +0 -72
- package/dist/daemon-status.js +0 -60
- package/dist/db-ops.d.ts +0 -116
- package/dist/db-ops.js +0 -191
- package/dist/delegated-tools.d.ts +0 -146
- package/dist/delegated-tools.js +0 -286
- package/dist/frontend-control.d.ts +0 -131
- package/dist/frontend-control.js +0 -77
- package/dist/frontend-sessions.d.ts +0 -100
- package/dist/frontend-sessions.js +0 -180
- package/dist/health.d.ts +0 -91
- package/dist/health.js +0 -53
- package/dist/host-tools.d.ts +0 -174
- package/dist/host-tools.js +0 -338
- package/dist/media.d.ts +0 -131
- package/dist/media.js +0 -352
- package/dist/memory.d.ts +0 -230
- package/dist/memory.js +0 -331
- package/dist/model-proxy.d.ts +0 -45
- package/dist/model-proxy.js +0 -619
- package/dist/origin-validation.d.ts +0 -64
- package/dist/origin-validation.js +0 -226
- package/dist/read-only-tools.d.ts +0 -67
- package/dist/read-only-tools.js +0 -59
- package/dist/remote-run-events.d.ts +0 -66
- package/dist/remote-run-events.js +0 -230
- package/dist/research.d.ts +0 -42
- package/dist/research.js +0 -316
- package/dist/route-manifest.d.ts +0 -31
- package/dist/route-manifest.js +0 -103
- package/dist/routines.d.ts +0 -114
- package/dist/routines.js +0 -320
- package/dist/runs.d.ts +0 -79
- package/dist/runs.js +0 -232
- package/dist/terminals.d.ts +0 -125
- package/dist/terminals.js +0 -349
- package/dist/tool-catalog.d.ts +0 -68
- package/dist/tool-catalog.js +0 -68
- package/dist/workspace-root.d.ts +0 -69
- package/dist/workspace-root.js +0 -63
- package/dist/xai.d.ts +0 -86
- package/dist/xai.js +0 -668
package/dist/host-tools.js
DELETED
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module host-tools
|
|
3
|
-
*
|
|
4
|
-
* Generic "open a working directory in a local host tool" surface, ported
|
|
5
|
-
* from the routes-classification table's `host-tools.ts` MIXED row (see
|
|
6
|
-
* `source-map.md`): the editor catalogue, `$PATH`/mac-bundle probing, and
|
|
7
|
-
* guarded detached-spawn machinery have zero OD dependency and are ported
|
|
8
|
-
* here in full. `GET /api/editors` (which uses solely this machinery) was
|
|
9
|
-
* mounted first; `POST /api/resources/:resourceRef/open-in` (OD's `POST
|
|
10
|
-
* /api/projects/:id/open-in`) is now ported too, now that a generic
|
|
11
|
-
* workspace-root port exists (`workspace-root.ts`) to stand in for OD's
|
|
12
|
-
* `projectStore.getProject`/`projectFiles.resolveProjectDir` — see that
|
|
13
|
-
* route's own doc below for the exact mapping.
|
|
14
|
-
*
|
|
15
|
-
* The probing functions take an injectable `HostToolProbeEnv` (filesystem
|
|
16
|
-
* `access`, `env`, `platform`) rather than reading `process.env`/`fs`
|
|
17
|
-
* directly, so every platform/found/missing branch is exercisable from a
|
|
18
|
-
* single-OS test runner without touching the real filesystem.
|
|
19
|
-
*/
|
|
20
|
-
import { spawn as nodeSpawn } from 'node:child_process';
|
|
21
|
-
import { access as fsAccess, constants as fsConstants } from 'node:fs/promises';
|
|
22
|
-
import { createCommandInvocation } from '@jini-ai/platform';
|
|
23
|
-
import { createApiError } from '@jini-ai/protocol';
|
|
24
|
-
import { defineJsonRoute, mountJsonRoute } from './adapter.js';
|
|
25
|
-
import { validationError } from './request.js';
|
|
26
|
-
import { err, ok } from './types.js';
|
|
27
|
-
import { denyAllWorkspaceRoots, resolveWorkspaceRoot, WorkspaceRootDeniedError } from './workspace-root.js';
|
|
28
|
-
const MAC_OPEN_COMMAND = '/usr/bin/open';
|
|
29
|
-
/** The cross-platform-staple + macOS-bundle editor/tool catalogue, unchanged from the origin. */
|
|
30
|
-
export const CATALOGUE = [
|
|
31
|
-
{ id: 'cursor', label: 'Cursor', icon: 'sparkles', command: 'cursor', macOpenBundle: 'Cursor' },
|
|
32
|
-
{ id: 'vscode', label: 'VS Code', icon: 'file-code', command: 'code', macOpenBundle: 'Visual Studio Code' },
|
|
33
|
-
{ id: 'windsurf', label: 'Windsurf', icon: 'sparkles', command: 'windsurf', macOpenBundle: 'Windsurf' },
|
|
34
|
-
{ id: 'zed', label: 'Zed', icon: 'edit', command: 'zed', macOpenBundle: 'Zed' },
|
|
35
|
-
{ id: 'qoder', label: 'Qoder', icon: 'sparkles', command: 'qoder', macOpenBundle: ['Qoder', 'QoderWork'] },
|
|
36
|
-
{ id: 'antigravity', label: 'Antigravity', icon: 'orbit', command: 'antigravity', macOpenBundle: ['Antigravity', 'Google Antigravity'] },
|
|
37
|
-
{ id: 'webstorm', label: 'WebStorm', icon: 'edit', command: 'webstorm', macOpenBundle: 'WebStorm' },
|
|
38
|
-
{ id: 'idea', label: 'IntelliJ IDEA', icon: 'edit', command: 'idea', macOpenBundle: 'IntelliJ IDEA' },
|
|
39
|
-
{ id: 'xcode', label: 'Xcode', icon: 'file-code', macOpenBundle: ['Xcode', 'Xcode-beta', 'Xcode Beta'], platforms: ['darwin'] },
|
|
40
|
-
{ id: 'finder', label: 'Finder', icon: 'folder', command: MAC_OPEN_COMMAND, commandArgs: (workingDir) => ['-R', workingDir], platforms: ['darwin'] },
|
|
41
|
-
{ id: 'explorer', label: 'Explorer', icon: 'folder', command: 'explorer', platforms: ['win32'] },
|
|
42
|
-
{ id: 'file-manager', label: 'File Manager', icon: 'folder', command: 'xdg-open', platforms: ['linux'] },
|
|
43
|
-
{ id: 'terminal', label: 'Terminal', icon: 'sliders', macOpenBundle: 'Terminal', platforms: ['darwin'] },
|
|
44
|
-
// darwin-only: Warp cold-starts ignore the cwd argument on win32/linux, so the
|
|
45
|
-
// "open in Warp" UX is broken on those platforms (origin's #4544).
|
|
46
|
-
{ id: 'warp', label: 'Warp', icon: 'sliders', macOpenBundle: 'Warp', platforms: ['darwin'] },
|
|
47
|
-
];
|
|
48
|
-
/** Maps Node's `process.platform` to this module's tri-state `Platform`; anything else (aix, freebsd, sunos, ...) is `'unknown'`. */
|
|
49
|
-
export function currentPlatform(nodePlatform = process.platform) {
|
|
50
|
-
switch (nodePlatform) {
|
|
51
|
-
case 'darwin':
|
|
52
|
-
return 'darwin';
|
|
53
|
-
case 'win32':
|
|
54
|
-
return 'win32';
|
|
55
|
-
case 'linux':
|
|
56
|
-
return 'linux';
|
|
57
|
-
default:
|
|
58
|
-
return 'unknown';
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
export function applicableForPlatform(entry, platform) {
|
|
62
|
-
if (platform === 'unknown')
|
|
63
|
-
return false;
|
|
64
|
-
if (entry.platforms && !entry.platforms.includes(platform))
|
|
65
|
-
return false;
|
|
66
|
-
if (entry.excludedPlatforms && entry.excludedPlatforms.includes(platform))
|
|
67
|
-
return false;
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
export function defaultProbeEnv() {
|
|
71
|
-
return { access: fsAccess, env: process.env, platform: currentPlatform() };
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* `$PATH` directories to probe, plus the common macOS/Linux locations a login shell would have
|
|
75
|
-
* that a GUI-launched daemon's thin inherited `PATH` often lacks (no `/usr/local/bin`, no
|
|
76
|
-
* `/opt/homebrew/bin`) — without these, CLI shims installed via an editor's "Install command"
|
|
77
|
-
* action are invisible to a daemon launched by double-clicking an app bundle.
|
|
78
|
-
*/
|
|
79
|
-
export function pathDirs(probeEnv) {
|
|
80
|
-
const raw = probeEnv.env.PATH ?? '';
|
|
81
|
-
const sep = probeEnv.platform === 'win32' ? ';' : ':';
|
|
82
|
-
const home = probeEnv.env.HOME ?? '';
|
|
83
|
-
const extras = probeEnv.platform === 'darwin'
|
|
84
|
-
? ['/usr/local/bin', '/opt/homebrew/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', `${home}/.local/bin`]
|
|
85
|
-
: probeEnv.platform === 'linux'
|
|
86
|
-
? ['/usr/local/bin', '/usr/bin', '/bin', `${home}/.local/bin`]
|
|
87
|
-
: [];
|
|
88
|
-
return [...raw.split(sep), ...extras].filter((dir) => dir.length > 0);
|
|
89
|
-
}
|
|
90
|
-
export async function probeCommandOnPath(command, probeEnv) {
|
|
91
|
-
if (command.includes('/')) {
|
|
92
|
-
try {
|
|
93
|
-
await probeEnv.access(command, fsConstants.X_OK);
|
|
94
|
-
return command;
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const dirs = pathDirs(probeEnv);
|
|
101
|
-
const suffixes = probeEnv.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
|
|
102
|
-
for (const dir of dirs) {
|
|
103
|
-
for (const suffix of suffixes) {
|
|
104
|
-
const candidate = `${dir}/${command}${suffix}`;
|
|
105
|
-
try {
|
|
106
|
-
await probeEnv.access(candidate, fsConstants.X_OK);
|
|
107
|
-
return candidate;
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
// not here
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
async function resolveMacOpenCommand(probeEnv) {
|
|
117
|
-
try {
|
|
118
|
-
await probeEnv.access(MAC_OPEN_COMMAND, fsConstants.X_OK);
|
|
119
|
-
return MAC_OPEN_COMMAND;
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
return (await probeCommandOnPath('open', probeEnv)) ?? MAC_OPEN_COMMAND;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
export async function probeMacBundle(name, probeEnv) {
|
|
126
|
-
if (probeEnv.platform !== 'darwin')
|
|
127
|
-
return null;
|
|
128
|
-
const names = Array.isArray(name) ? name : [name];
|
|
129
|
-
const home = probeEnv.env.HOME ?? '';
|
|
130
|
-
const candidates = [
|
|
131
|
-
(bundleName) => `/Applications/${bundleName}.app`,
|
|
132
|
-
(bundleName) => `${home}/Applications/${bundleName}.app`,
|
|
133
|
-
(bundleName) => `/System/Applications/${bundleName}.app`,
|
|
134
|
-
(bundleName) => `/System/Applications/Utilities/${bundleName}.app`,
|
|
135
|
-
(bundleName) => `/System/Library/CoreServices/${bundleName}.app`,
|
|
136
|
-
];
|
|
137
|
-
for (const bundleName of names) {
|
|
138
|
-
for (const candidate of candidates) {
|
|
139
|
-
const path = candidate(bundleName);
|
|
140
|
-
try {
|
|
141
|
-
await probeEnv.access(path, fsConstants.R_OK);
|
|
142
|
-
return { name: bundleName, path };
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
// not here
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
export async function resolveEntry(entry, probeEnv = defaultProbeEnv()) {
|
|
152
|
-
if (entry.command) {
|
|
153
|
-
const resolved = await probeCommandOnPath(entry.command, probeEnv);
|
|
154
|
-
if (resolved) {
|
|
155
|
-
return {
|
|
156
|
-
available: true,
|
|
157
|
-
resolvedPath: resolved,
|
|
158
|
-
launch: { command: resolved, argsForDir: entry.commandArgs ?? ((workingDir) => [workingDir]) },
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (entry.macOpenBundle && probeEnv.platform === 'darwin') {
|
|
163
|
-
const bundle = await probeMacBundle(entry.macOpenBundle, probeEnv);
|
|
164
|
-
if (bundle) {
|
|
165
|
-
return {
|
|
166
|
-
available: true,
|
|
167
|
-
resolvedPath: bundle.path,
|
|
168
|
-
launch: {
|
|
169
|
-
command: await resolveMacOpenCommand(probeEnv),
|
|
170
|
-
argsForDir: entry.macOpenArgs
|
|
171
|
-
? (workingDir) => entry.macOpenArgs(bundle.name, workingDir)
|
|
172
|
-
: (workingDir) => ['-a', bundle.name, workingDir],
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
return { available: false };
|
|
178
|
-
}
|
|
179
|
-
/** Resolves the concrete `{command, args}` a caller would spawn to open `workingDir` in `editorId`, or `available: false` if that tool isn't installed/known. */
|
|
180
|
-
export async function resolveHostToolLaunchPlan(editorId, workingDir, probeEnv = defaultProbeEnv()) {
|
|
181
|
-
const entry = CATALOGUE.find((c) => c.id === editorId);
|
|
182
|
-
if (!entry)
|
|
183
|
-
return { available: false };
|
|
184
|
-
const probe = await resolveEntry(entry, probeEnv);
|
|
185
|
-
if (!probe.available)
|
|
186
|
-
return { available: false };
|
|
187
|
-
return {
|
|
188
|
-
available: true,
|
|
189
|
-
resolvedPath: probe.resolvedPath,
|
|
190
|
-
command: probe.launch.command,
|
|
191
|
-
args: probe.launch.argsForDir(workingDir),
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Spawns a detached host-tool launch and waits for the OS to confirm it actually started. Node
|
|
196
|
-
* emits `'spawn'` once the child is running and `'error'` when the launch is refused (missing
|
|
197
|
-
* binary, quarantine, EACCES) — `'error'` arrives on a later tick, so this must be awaited before
|
|
198
|
-
* a caller replies, otherwise a launch the OS rejected would be reported as success (origin's
|
|
199
|
-
* #3871).
|
|
200
|
-
*
|
|
201
|
-
* Deliberately never passes `shell: true`: on Windows that would route the launch through
|
|
202
|
-
* `cmd.exe`, which shell-interprets args — and one of them is a caller-supplied directory path,
|
|
203
|
-
* so a path containing `&`/`|`/`^`/`>` etc. would inject commands. `command` is already resolved
|
|
204
|
-
* to an absolute path (including `.exe`/`.cmd`), so it's routed through `createCommandInvocation`
|
|
205
|
-
* (`@jini-ai/platform`), which runs a `.cmd`/`.bat` via `cmd.exe` with
|
|
206
|
-
* `CommandLineToArgvW`-safe verbatim args and everything else directly — no shell, no
|
|
207
|
-
* metacharacter interpretation.
|
|
208
|
-
*/
|
|
209
|
-
export function launchHostTool(command, args, spawnImpl = nodeSpawn) {
|
|
210
|
-
return new Promise((resolve) => {
|
|
211
|
-
const invocation = createCommandInvocation({ command, args });
|
|
212
|
-
const child = spawnImpl(invocation.command, invocation.args, {
|
|
213
|
-
detached: true,
|
|
214
|
-
stdio: 'ignore',
|
|
215
|
-
windowsHide: process.platform === 'win32',
|
|
216
|
-
windowsVerbatimArguments: invocation.windowsVerbatimArguments,
|
|
217
|
-
});
|
|
218
|
-
let settled = false;
|
|
219
|
-
child.once('spawn', () => {
|
|
220
|
-
if (settled)
|
|
221
|
-
return;
|
|
222
|
-
settled = true;
|
|
223
|
-
child.unref();
|
|
224
|
-
resolve({ ok: true });
|
|
225
|
-
});
|
|
226
|
-
child.once('error', (spawnError) => {
|
|
227
|
-
if (settled)
|
|
228
|
-
return;
|
|
229
|
-
settled = true;
|
|
230
|
-
resolve({ ok: false, error: spawnError instanceof Error ? spawnError.message : String(spawnError) });
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
/** Probes every catalogue entry applicable to the current platform and reports which are actually installed. */
|
|
235
|
-
export async function listAvailableEditors(probeEnv = defaultProbeEnv()) {
|
|
236
|
-
const filtered = CATALOGUE.filter((entry) => applicableForPlatform(entry, probeEnv.platform));
|
|
237
|
-
const editors = await Promise.all(filtered.map(async (entry) => {
|
|
238
|
-
const probe = await resolveEntry(entry, probeEnv);
|
|
239
|
-
return {
|
|
240
|
-
id: entry.id,
|
|
241
|
-
label: entry.label,
|
|
242
|
-
icon: entry.icon,
|
|
243
|
-
available: probe.available,
|
|
244
|
-
...(probe.available ? { resolvedPath: probe.resolvedPath } : {}),
|
|
245
|
-
...(entry.platforms ? { platforms: entry.platforms } : {}),
|
|
246
|
-
};
|
|
247
|
-
}));
|
|
248
|
-
return { editors, platform: probeEnv.platform };
|
|
249
|
-
}
|
|
250
|
-
/** `GET /api/editors` — lists the host-tool catalogue applicable to this platform with live availability. */
|
|
251
|
-
export const hostEditorsRoute = defineJsonRoute({
|
|
252
|
-
method: 'get',
|
|
253
|
-
path: '/api/editors',
|
|
254
|
-
parse: () => ok(undefined),
|
|
255
|
-
handle: async () => ok(await listAvailableEditors()),
|
|
256
|
-
});
|
|
257
|
-
function isRecord(value) {
|
|
258
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
259
|
-
}
|
|
260
|
-
function parseOpenResourceInEditor(input) {
|
|
261
|
-
const resourceRef = input.params.resourceRef;
|
|
262
|
-
if (typeof resourceRef !== 'string' || resourceRef.length === 0) {
|
|
263
|
-
return err(validationError('resourceRef must be a non-empty path parameter'));
|
|
264
|
-
}
|
|
265
|
-
if (!isRecord(input.body))
|
|
266
|
-
return err(validationError('body must be a JSON object'));
|
|
267
|
-
const editorId = input.body.editorId;
|
|
268
|
-
if (typeof editorId !== 'string' || editorId.length === 0) {
|
|
269
|
-
return err(validationError('editorId is required', [{ path: 'editorId', message: 'required non-empty string' }]));
|
|
270
|
-
}
|
|
271
|
-
const detail = input.body.detail;
|
|
272
|
-
if (detail !== undefined && (typeof detail !== 'string' || detail.length === 0)) {
|
|
273
|
-
return err(validationError('detail must be a non-empty string when provided'));
|
|
274
|
-
}
|
|
275
|
-
return ok({ resourceRef, editorId, ...(detail === undefined ? {} : { detail }) });
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* `POST /api/resources/:resourceRef/open-in` — launches `editorId` (from
|
|
279
|
-
* {@link CATALOGUE}) rooted at the working directory `deps.resolveRoot`
|
|
280
|
-
* resolves for `resourceRef`. Ported from OD's `POST
|
|
281
|
-
* /api/projects/:id/open-in`: `projectId` generalizes to the opaque
|
|
282
|
-
* `resourceRef` this package already uses (`active-context.ts`,
|
|
283
|
-
* `cancel-owned-runs.ts`), and `getProject`/`resolveProjectDir` generalize
|
|
284
|
-
* to the injected {@link WorkspaceRootResolver}. `PROJECT_NOT_FOUND` (an
|
|
285
|
-
* OD-product-only code with no `@jini-ai/protocol` equivalent — see
|
|
286
|
-
* `response.ts`'s file-map note) becomes a generic `NOT_FOUND` when the
|
|
287
|
-
* resolver denies. `EDITOR_NOT_AVAILABLE` (OD's 409 for "installed catalogue
|
|
288
|
-
* entry, but not found on this machine") becomes `CONFLICT`, which already
|
|
289
|
-
* maps to 409 in this package's `ERROR_STATUS_BY_CODE`.
|
|
290
|
-
*
|
|
291
|
-
* The launch-failure message is returned to the caller verbatim (unlike
|
|
292
|
-
* `runs.ts`'s SEC-005 redaction of internal agent-run errors): this is a
|
|
293
|
-
* same-origin, explicitly-consented, single local action the caller just
|
|
294
|
-
* asked for (open the tool it named, at the directory it's authorized to
|
|
295
|
-
* open) — the underlying spawn error (e.g. a quarantined/missing binary) is
|
|
296
|
-
* operationally useful to the caller and does not cross a trust boundary
|
|
297
|
-
* the way an internal agent-run exception can.
|
|
298
|
-
*/
|
|
299
|
-
export const openResourceInEditorRoute = defineJsonRoute({
|
|
300
|
-
method: 'post',
|
|
301
|
-
path: '/api/resources/:resourceRef/open-in',
|
|
302
|
-
requireSameOrigin: true,
|
|
303
|
-
parse: parseOpenResourceInEditor,
|
|
304
|
-
handle: async (input, deps) => {
|
|
305
|
-
const entry = CATALOGUE.find((c) => c.id === input.editorId);
|
|
306
|
-
if (!entry)
|
|
307
|
-
return err(createApiError('BAD_REQUEST', `unknown editor: ${input.editorId}`));
|
|
308
|
-
const probeEnv = deps.probeEnv ?? defaultProbeEnv();
|
|
309
|
-
if (!applicableForPlatform(entry, probeEnv.platform)) {
|
|
310
|
-
return err(createApiError('BAD_REQUEST', `${entry.label} is not available on ${probeEnv.platform}`));
|
|
311
|
-
}
|
|
312
|
-
let resolvedDir;
|
|
313
|
-
try {
|
|
314
|
-
resolvedDir = await resolveWorkspaceRoot({ resourceRef: input.resourceRef, ...(input.detail === undefined ? {} : { detail: input.detail }) }, { resolver: deps.resolveRoot ?? denyAllWorkspaceRoots });
|
|
315
|
-
}
|
|
316
|
-
catch (error) {
|
|
317
|
-
if (error instanceof WorkspaceRootDeniedError) {
|
|
318
|
-
return err(createApiError('NOT_FOUND', `resource "${input.resourceRef}" was not found`));
|
|
319
|
-
}
|
|
320
|
-
throw error;
|
|
321
|
-
}
|
|
322
|
-
const launchPlan = await resolveHostToolLaunchPlan(input.editorId, resolvedDir, probeEnv);
|
|
323
|
-
if (!launchPlan.available || !launchPlan.command || !launchPlan.args) {
|
|
324
|
-
return err(createApiError('CONFLICT', `${entry.label} is not installed`));
|
|
325
|
-
}
|
|
326
|
-
const launch = await launchHostTool(launchPlan.command, launchPlan.args, deps.spawnImpl ?? nodeSpawn);
|
|
327
|
-
if (!launch.ok) {
|
|
328
|
-
return err(createApiError('INTERNAL_ERROR', `failed to launch ${entry.label}: ${launch.error}`));
|
|
329
|
-
}
|
|
330
|
-
return ok({ ok: true, editorId: input.editorId, path: resolvedDir });
|
|
331
|
-
},
|
|
332
|
-
});
|
|
333
|
-
/** Mounts `GET /api/editors` and `POST /api/resources/:resourceRef/open-in` on `app`. A pack's `http(app, services)` calls this directly. */
|
|
334
|
-
export function registerHostToolsRoutes(app, adapter, openInDeps = {}) {
|
|
335
|
-
mountJsonRoute(app, hostEditorsRoute, {}, adapter);
|
|
336
|
-
mountJsonRoute(app, openResourceInEditorRoute, openInDeps, adapter);
|
|
337
|
-
}
|
|
338
|
-
//# sourceMappingURL=host-tools.js.map
|
package/dist/media.d.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import type { Express } from 'express';
|
|
2
|
-
import { type AdapterContext } from './adapter.js';
|
|
3
|
-
type MediaSurface = 'image' | 'video' | 'audio';
|
|
4
|
-
type AudioKind = 'music' | 'speech' | 'sfx';
|
|
5
|
-
type MediaSpeechFormat = 'mp3' | 'wav' | 'flac' | 'aac' | 'opus';
|
|
6
|
-
interface MediaImageReference {
|
|
7
|
-
readonly dataUrl: string;
|
|
8
|
-
}
|
|
9
|
-
interface MediaGenerationRequest {
|
|
10
|
-
readonly surface: MediaSurface;
|
|
11
|
-
readonly model: string;
|
|
12
|
-
readonly prompt?: string;
|
|
13
|
-
readonly aspect?: string;
|
|
14
|
-
readonly length?: number;
|
|
15
|
-
readonly duration?: number;
|
|
16
|
-
readonly voice?: string;
|
|
17
|
-
readonly audioKind?: AudioKind;
|
|
18
|
-
readonly language?: string;
|
|
19
|
-
readonly loop?: boolean;
|
|
20
|
-
readonly promptInfluence?: number;
|
|
21
|
-
readonly imageRef?: MediaImageReference;
|
|
22
|
-
readonly imageRefs?: readonly MediaImageReference[];
|
|
23
|
-
readonly wireModel?: string;
|
|
24
|
-
readonly speechFormat?: MediaSpeechFormat;
|
|
25
|
-
}
|
|
26
|
-
interface MediaGenerationResult {
|
|
27
|
-
readonly bytes: Buffer;
|
|
28
|
-
readonly providerNote: string;
|
|
29
|
-
readonly suggestedExt?: string;
|
|
30
|
-
readonly providerId: string;
|
|
31
|
-
readonly usedStubFallback: boolean;
|
|
32
|
-
readonly warnings: readonly string[];
|
|
33
|
-
}
|
|
34
|
-
interface MediaDispatchEngine {
|
|
35
|
-
generate(request: MediaGenerationRequest): Promise<MediaGenerationResult>;
|
|
36
|
-
}
|
|
37
|
-
type MediaTaskStatus = 'queued' | 'running' | 'done' | 'failed' | 'interrupted';
|
|
38
|
-
interface MediaTaskError {
|
|
39
|
-
readonly message: string;
|
|
40
|
-
readonly status?: number;
|
|
41
|
-
readonly code?: string;
|
|
42
|
-
}
|
|
43
|
-
interface MediaTask {
|
|
44
|
-
readonly id: string;
|
|
45
|
-
readonly ownerRef: string;
|
|
46
|
-
readonly status: MediaTaskStatus;
|
|
47
|
-
readonly surface?: string;
|
|
48
|
-
readonly model?: string;
|
|
49
|
-
readonly progress: readonly string[];
|
|
50
|
-
readonly file: unknown | null;
|
|
51
|
-
readonly error: MediaTaskError | null;
|
|
52
|
-
readonly startedAt: number;
|
|
53
|
-
readonly endedAt: number | null;
|
|
54
|
-
readonly createdAt: number;
|
|
55
|
-
readonly updatedAt: number;
|
|
56
|
-
}
|
|
57
|
-
interface MediaTaskCreateInput {
|
|
58
|
-
readonly id: string;
|
|
59
|
-
readonly ownerRef: string;
|
|
60
|
-
readonly status?: MediaTaskStatus;
|
|
61
|
-
readonly surface?: string;
|
|
62
|
-
readonly model?: string;
|
|
63
|
-
readonly progress?: readonly string[];
|
|
64
|
-
readonly file?: unknown | null;
|
|
65
|
-
readonly error?: MediaTaskError | null;
|
|
66
|
-
readonly startedAt?: number;
|
|
67
|
-
}
|
|
68
|
-
interface MediaTaskPatch {
|
|
69
|
-
readonly status?: MediaTaskStatus;
|
|
70
|
-
readonly surface?: string | null;
|
|
71
|
-
readonly model?: string | null;
|
|
72
|
-
readonly progress?: readonly string[];
|
|
73
|
-
readonly file?: unknown | null;
|
|
74
|
-
readonly error?: MediaTaskError | null;
|
|
75
|
-
readonly endedAt?: number | null;
|
|
76
|
-
}
|
|
77
|
-
interface MediaTaskListOptions {
|
|
78
|
-
readonly includeTerminal?: boolean;
|
|
79
|
-
}
|
|
80
|
-
interface MediaTaskStore {
|
|
81
|
-
create(input: MediaTaskCreateInput): Promise<MediaTask>;
|
|
82
|
-
get(id: string): Promise<MediaTask | null>;
|
|
83
|
-
update(id: string, patch: MediaTaskPatch): Promise<MediaTask | null>;
|
|
84
|
-
listByOwner(ownerRef: string, options?: MediaTaskListOptions): Promise<MediaTask[]>;
|
|
85
|
-
delete(id: string): Promise<void>;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Diagnostic detail for an internal-error response the public API deliberately does not disclose
|
|
89
|
-
* (SEC-005), matching `delegated-tools.ts`'s `DelegatedToolsInternalErrorContext` precedent.
|
|
90
|
-
*/
|
|
91
|
-
export interface MediaInternalErrorContext {
|
|
92
|
-
readonly source: 'media-generate-dispatch' | 'media-task-store';
|
|
93
|
-
readonly taskId: string | null;
|
|
94
|
-
readonly ownerRef: string | null;
|
|
95
|
-
readonly correlationId: string;
|
|
96
|
-
readonly error: unknown;
|
|
97
|
-
}
|
|
98
|
-
export interface MediaHttpDeps {
|
|
99
|
-
readonly engine: MediaDispatchEngine;
|
|
100
|
-
readonly taskStore: MediaTaskStore;
|
|
101
|
-
/** Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005). Defaults to `console.error`. */
|
|
102
|
-
readonly onInternalError?: (context: MediaInternalErrorContext) => void;
|
|
103
|
-
}
|
|
104
|
-
interface MediaGenerateRequest {
|
|
105
|
-
readonly ownerRef: string;
|
|
106
|
-
readonly request: MediaGenerationRequest;
|
|
107
|
-
}
|
|
108
|
-
interface MediaTaskListQuery {
|
|
109
|
-
readonly ownerRef: string;
|
|
110
|
-
readonly options: MediaTaskListOptions;
|
|
111
|
-
}
|
|
112
|
-
export interface MediaGenerateResponse {
|
|
113
|
-
readonly task: MediaTask;
|
|
114
|
-
}
|
|
115
|
-
export declare const mediaGenerateRoute: import("./types.js").JsonRouteSpec<MediaGenerateRequest, MediaGenerateResponse, MediaHttpDeps>;
|
|
116
|
-
export interface MediaTaskResponse {
|
|
117
|
-
readonly task: MediaTask;
|
|
118
|
-
}
|
|
119
|
-
export declare const mediaTaskGetRoute: import("./types.js").JsonRouteSpec<string, MediaTaskResponse, MediaHttpDeps>;
|
|
120
|
-
export interface MediaTaskDeleteResponse {
|
|
121
|
-
readonly ok: true;
|
|
122
|
-
}
|
|
123
|
-
export declare const mediaTaskDeleteRoute: import("./types.js").JsonRouteSpec<string, MediaTaskDeleteResponse, MediaHttpDeps>;
|
|
124
|
-
export interface MediaTaskListResponse {
|
|
125
|
-
readonly tasks: readonly MediaTask[];
|
|
126
|
-
}
|
|
127
|
-
export declare const mediaTaskListRoute: import("./types.js").JsonRouteSpec<MediaTaskListQuery, MediaTaskListResponse, MediaHttpDeps>;
|
|
128
|
-
/** Mounts every media route on `app`. A pack's `http(app, services)` calls this directly. */
|
|
129
|
-
export declare function registerMediaRoutes(app: Express, deps: MediaHttpDeps, adapter: AdapterContext): void;
|
|
130
|
-
export {};
|
|
131
|
-
//# sourceMappingURL=media.d.ts.map
|