@agentapps/station 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/api-key-store.d.ts +46 -0
- package/dist/api-key-store.d.ts.map +1 -0
- package/dist/api-key-store.js +84 -0
- package/dist/api-key-store.js.map +1 -0
- package/dist/app-station.d.ts +129 -0
- package/dist/app-station.d.ts.map +1 -0
- package/dist/app-station.js +706 -0
- package/dist/app-station.js.map +1 -0
- package/dist/approval-manager.d.ts +75 -0
- package/dist/approval-manager.d.ts.map +1 -0
- package/dist/approval-manager.js +96 -0
- package/dist/approval-manager.js.map +1 -0
- package/dist/document-store.d.ts +86 -0
- package/dist/document-store.d.ts.map +1 -0
- package/dist/document-store.js +230 -0
- package/dist/document-store.js.map +1 -0
- package/dist/file-handlers/object-store.d.ts +113 -0
- package/dist/file-handlers/object-store.d.ts.map +1 -0
- package/dist/file-handlers/object-store.js +273 -0
- package/dist/file-handlers/object-store.js.map +1 -0
- package/dist/file-handlers/signed-url.d.ts +44 -0
- package/dist/file-handlers/signed-url.d.ts.map +1 -0
- package/dist/file-handlers/signed-url.js +68 -0
- package/dist/file-handlers/signed-url.js.map +1 -0
- package/dist/file-handlers/volume-handlers.d.ts +136 -0
- package/dist/file-handlers/volume-handlers.d.ts.map +1 -0
- package/dist/file-handlers/volume-handlers.js +426 -0
- package/dist/file-handlers/volume-handlers.js.map +1 -0
- package/dist/in-process-runtime.d.ts +49 -0
- package/dist/in-process-runtime.d.ts.map +1 -0
- package/dist/in-process-runtime.js +50 -0
- package/dist/in-process-runtime.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/local-process-runtime.d.ts +28 -0
- package/dist/local-process-runtime.d.ts.map +1 -0
- package/dist/local-process-runtime.js +134 -0
- package/dist/local-process-runtime.js.map +1 -0
- package/dist/oauth-manager.d.ts +90 -0
- package/dist/oauth-manager.d.ts.map +1 -0
- package/dist/oauth-manager.js +148 -0
- package/dist/oauth-manager.js.map +1 -0
- package/dist/oauth-pages.d.ts +9 -0
- package/dist/oauth-pages.d.ts.map +1 -0
- package/dist/oauth-pages.js +59 -0
- package/dist/oauth-pages.js.map +1 -0
- package/dist/permission-enforcer.d.ts +52 -0
- package/dist/permission-enforcer.d.ts.map +1 -0
- package/dist/permission-enforcer.js +144 -0
- package/dist/permission-enforcer.js.map +1 -0
- package/dist/policy-store.d.ts +34 -0
- package/dist/policy-store.d.ts.map +1 -0
- package/dist/policy-store.js +35 -0
- package/dist/policy-store.js.map +1 -0
- package/dist/secrets-manager.d.ts +32 -0
- package/dist/secrets-manager.d.ts.map +1 -0
- package/dist/secrets-manager.js +12 -0
- package/dist/secrets-manager.js.map +1 -0
- package/dist/server.d.ts +383 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +1974 -0
- package/dist/server.js.map +1 -0
- package/dist/telemetry.d.ts +9 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +9 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +40 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volume-handlers.d.ts","sourceRoot":"","sources":["../../src/file-handlers/volume-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAE,KAAK,QAAQ,EAA4B,KAAK,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAS7F;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAK5D;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MA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CA0B3E;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,GAAG,EAAE,oBAAoB,EACzB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAmB7B;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,oBAAoB,EACzB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAmC7B;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,GAAG,EAAE,oBAAoB,EACzB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CA4BjC;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,oBAAoB,EACzB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAS7B;AAMD;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,oBAAoB,EACzB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAyGzC;AAED,wDAAwD;AACxD,eAAO,MAAM,oBAAoB,aAO/B,CAAC"}
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace Volume handlers for the Agent Apps Station.
|
|
3
|
+
*
|
|
4
|
+
* One Volume per Workspace (VOL-REQ-1), rooted at
|
|
5
|
+
*
|
|
6
|
+
* {VOLUMES_BASE_PATH}/ws_{workspaceId}/workspace/
|
|
7
|
+
*
|
|
8
|
+
* API mode answers the `file_volume_*` Requests (VOL-REQ-3) for Installations
|
|
9
|
+
* holding the `volume` Permission (VOL-REQ-2). Mount mode hands the same
|
|
10
|
+
* directory to the Instance (VOL-REQ-5), so both modes see the same files
|
|
11
|
+
* (VOL-REQ-6). All paths are relative to the root and never escape it
|
|
12
|
+
* (VOL-NFR-1).
|
|
13
|
+
*/
|
|
14
|
+
import { mkdir, readdir, readFile, rm, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { homedir } from 'node:os';
|
|
16
|
+
import { join, resolve, sep } from 'node:path';
|
|
17
|
+
import { ErrorCode, FileErrorCode } from '@agentapps/protocol';
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Config
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
/** Default base path for volume storage (under the user's home directory). */
|
|
22
|
+
const DEFAULT_VOLUMES_BASE_PATH = join(homedir(), '.agentapps', 'data');
|
|
23
|
+
/**
|
|
24
|
+
* Resolve the volumes base path from the environment or fall back to the
|
|
25
|
+
* default. Callers can also pass an explicit override.
|
|
26
|
+
*
|
|
27
|
+
* @spec VOL-REQ-1
|
|
28
|
+
*/
|
|
29
|
+
export function getVolumesBasePath(override) {
|
|
30
|
+
if (override)
|
|
31
|
+
return resolve(override);
|
|
32
|
+
const env = process.env.AGENTAPPS_VOLUMES_BASE_PATH;
|
|
33
|
+
if (env)
|
|
34
|
+
return resolve(env);
|
|
35
|
+
return resolve(DEFAULT_VOLUMES_BASE_PATH);
|
|
36
|
+
}
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Path resolution & security
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
/**
|
|
41
|
+
* Resolve a relative path (from the instance) to an absolute host path
|
|
42
|
+
* inside the Workspace's Volume root.
|
|
43
|
+
*
|
|
44
|
+
* Rejects with `INVALID_ARGUMENTS` (VOL-REQ-3): absolute paths (leading slash
|
|
45
|
+
* or backslash, or a drive letter), any literal `..` segment, and any path
|
|
46
|
+
* whose resolution escapes the root.
|
|
47
|
+
*
|
|
48
|
+
* @spec VOL-REQ-3
|
|
49
|
+
* @returns The absolute host path, or throws with code `INVALID_ARGUMENTS`.
|
|
50
|
+
*/
|
|
51
|
+
export function resolveVolumePath(volumeRoot, relPath) {
|
|
52
|
+
const root = resolve(volumeRoot);
|
|
53
|
+
if (relPath.startsWith('/') || relPath.startsWith('\\') || /^[A-Za-z]:/.test(relPath)) {
|
|
54
|
+
throw invalidPath('Absolute paths are not allowed; use a path relative to the Volume root');
|
|
55
|
+
}
|
|
56
|
+
// Reject literal '..' segments (allow names like '..foo' or 'foo..bar')
|
|
57
|
+
const segments = relPath.split(/[\\/]/);
|
|
58
|
+
if (segments.includes('..')) {
|
|
59
|
+
throw invalidPath('Path traversal detected: ".." segment in path');
|
|
60
|
+
}
|
|
61
|
+
// Join and resolve — normalises the path
|
|
62
|
+
const target = resolve(join(root, relPath));
|
|
63
|
+
// Final check: the resolved path must be within the volume root.
|
|
64
|
+
// The target must either be the root itself, or start with root + separator.
|
|
65
|
+
// This correctly allows filenames like '..foo.txt' (which resolve to
|
|
66
|
+
// root/..foo.txt) while blocking actual traversal (root/../etc → /etc).
|
|
67
|
+
if (target !== root && !target.startsWith(root + sep)) {
|
|
68
|
+
throw invalidPath('Path traversal detected: resolved path escapes volume root');
|
|
69
|
+
}
|
|
70
|
+
return target;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Build the Volume root for a Workspace: one per Workspace, shared by every
|
|
74
|
+
* Installation in it.
|
|
75
|
+
*
|
|
76
|
+
* {volumesBasePath}/ws_{workspaceId}/workspace/
|
|
77
|
+
*
|
|
78
|
+
* @spec VOL-REQ-1
|
|
79
|
+
*/
|
|
80
|
+
export function buildVolumeRoot(volumesBasePath, workspaceId) {
|
|
81
|
+
return join(volumesBasePath, `ws_${workspaceId}`, 'workspace');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Decide the mount path handed to an Instance in mount mode.
|
|
85
|
+
*
|
|
86
|
+
* Returns the absolute Volume root when the App declares
|
|
87
|
+
* `runtime.mountVolume: true` AND the Installation holds the `volume`
|
|
88
|
+
* Permission; `undefined` otherwise, so no mount is provided without the
|
|
89
|
+
* Permission (VOL-REQ-2, VOL-REQ-4).
|
|
90
|
+
*
|
|
91
|
+
* @spec VOL-REQ-5
|
|
92
|
+
*/
|
|
93
|
+
export function resolveMountPath(options) {
|
|
94
|
+
if (options.mountVolume !== true)
|
|
95
|
+
return undefined;
|
|
96
|
+
if (options.permissions?.volume !== true)
|
|
97
|
+
return undefined;
|
|
98
|
+
return resolve(buildVolumeRoot(options.volumesBasePath, options.workspaceId));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* List directory entries.
|
|
102
|
+
*
|
|
103
|
+
* `path` is relative to the volume root. An empty string lists the root.
|
|
104
|
+
*
|
|
105
|
+
* @spec VOL-REQ-3
|
|
106
|
+
*/
|
|
107
|
+
export async function volumeReadDir(ctx, path) {
|
|
108
|
+
try {
|
|
109
|
+
const volumeRoot = buildVolumeRoot(ctx.volumesBasePath, ctx.workspaceId);
|
|
110
|
+
const absPath = resolveVolumePath(volumeRoot, path || '.');
|
|
111
|
+
const entries = await readdir(absPath, { withFileTypes: true });
|
|
112
|
+
const result = [];
|
|
113
|
+
for (const entry of entries) {
|
|
114
|
+
let size = 0;
|
|
115
|
+
let mtime;
|
|
116
|
+
try {
|
|
117
|
+
const s = await stat(join(absPath, entry.name));
|
|
118
|
+
size = entry.isDirectory() ? 0 : s.size;
|
|
119
|
+
mtime = s.mtime;
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Broken symlink or race — skip
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
result.push({
|
|
126
|
+
name: entry.name,
|
|
127
|
+
type: entry.isDirectory() ? 'directory' : 'file',
|
|
128
|
+
size,
|
|
129
|
+
modifiedAt: mtime.toISOString(),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return { success: true, data: result };
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
return toErrorResult(err);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Read a file as base64-encoded bytes.
|
|
140
|
+
*
|
|
141
|
+
* @spec VOL-REQ-3
|
|
142
|
+
*/
|
|
143
|
+
export async function volumeReadFile(ctx, path) {
|
|
144
|
+
try {
|
|
145
|
+
const volumeRoot = buildVolumeRoot(ctx.volumesBasePath, ctx.workspaceId);
|
|
146
|
+
const absPath = resolveVolumePath(volumeRoot, path);
|
|
147
|
+
const s = await stat(absPath);
|
|
148
|
+
if (s.isDirectory()) {
|
|
149
|
+
return {
|
|
150
|
+
success: false,
|
|
151
|
+
error: 'Path is a directory, not a file',
|
|
152
|
+
errorCode: FileErrorCode.INVALID_PATH,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const buf = await readFile(absPath);
|
|
156
|
+
return {
|
|
157
|
+
success: true,
|
|
158
|
+
data: {
|
|
159
|
+
data: buf.toString('base64'),
|
|
160
|
+
size: buf.length,
|
|
161
|
+
modifiedAt: s.mtime.toISOString(),
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
return toErrorResult(err);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Write base64-encoded bytes to a file. Creates parent directories.
|
|
171
|
+
*
|
|
172
|
+
* @spec VOL-REQ-3
|
|
173
|
+
*/
|
|
174
|
+
export async function volumeWriteFile(ctx, path, dataBase64) {
|
|
175
|
+
try {
|
|
176
|
+
const volumeRoot = buildVolumeRoot(ctx.volumesBasePath, ctx.workspaceId);
|
|
177
|
+
const absPath = resolveVolumePath(volumeRoot, path);
|
|
178
|
+
// Ensure the volume root exists
|
|
179
|
+
await mkdir(volumeRoot, { recursive: true });
|
|
180
|
+
// Create parent directories
|
|
181
|
+
const parentDir = join(absPath, '..');
|
|
182
|
+
await mkdir(parentDir, { recursive: true });
|
|
183
|
+
const buf = Buffer.from(dataBase64, 'base64');
|
|
184
|
+
await writeFile(absPath, buf);
|
|
185
|
+
return { success: true };
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
return toErrorResult(err);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Delete a file or directory. If the target is a directory and
|
|
193
|
+
* `recursive` is false, the delete fails.
|
|
194
|
+
*
|
|
195
|
+
* @spec VOL-REQ-3
|
|
196
|
+
*/
|
|
197
|
+
export async function volumeDelete(ctx, path, recursive) {
|
|
198
|
+
try {
|
|
199
|
+
const volumeRoot = buildVolumeRoot(ctx.volumesBasePath, ctx.workspaceId);
|
|
200
|
+
const absPath = resolveVolumePath(volumeRoot, path);
|
|
201
|
+
// Prevent deleting the volume root itself
|
|
202
|
+
if (absPath === resolve(volumeRoot)) {
|
|
203
|
+
return {
|
|
204
|
+
success: false,
|
|
205
|
+
error: 'Cannot delete the volume root',
|
|
206
|
+
errorCode: FileErrorCode.INVALID_PATH,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const s = await stat(absPath);
|
|
210
|
+
if (s.isDirectory() && !recursive) {
|
|
211
|
+
// Check if directory is empty
|
|
212
|
+
const entries = await readdir(absPath);
|
|
213
|
+
if (entries.length > 0) {
|
|
214
|
+
return {
|
|
215
|
+
success: false,
|
|
216
|
+
error: 'Directory is not empty — use recursive: true to delete',
|
|
217
|
+
errorCode: FileErrorCode.INVALID_PATH,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// Use rmdir for empty directories (rm with recursive:false fails on dirs)
|
|
221
|
+
await rmdir(absPath);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
await rm(absPath, { recursive });
|
|
225
|
+
}
|
|
226
|
+
return { success: true };
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
return toErrorResult(err);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Stat a path — returns type, size, createdAt, modifiedAt.
|
|
234
|
+
*
|
|
235
|
+
* @spec VOL-REQ-3
|
|
236
|
+
*/
|
|
237
|
+
export async function volumeStat(ctx, path) {
|
|
238
|
+
try {
|
|
239
|
+
const volumeRoot = buildVolumeRoot(ctx.volumesBasePath, ctx.workspaceId);
|
|
240
|
+
const absPath = resolveVolumePath(volumeRoot, path || '.');
|
|
241
|
+
const s = await stat(absPath);
|
|
242
|
+
const isDir = s.isDirectory();
|
|
243
|
+
// Compute the relative path for the response
|
|
244
|
+
// Use substring instead of path.relative to avoid '..' normalisation
|
|
245
|
+
const rootStr = resolve(volumeRoot);
|
|
246
|
+
const relPath = absPath === rootStr ? '.' : absPath.slice(rootStr.length + 1); // +1 for the separator
|
|
247
|
+
// Normalise to forward slashes (container-side convention)
|
|
248
|
+
const normalisedPath = relPath.split(sep).join('/') || '.';
|
|
249
|
+
return {
|
|
250
|
+
success: true,
|
|
251
|
+
data: {
|
|
252
|
+
path: normalisedPath,
|
|
253
|
+
type: isDir ? 'directory' : 'file',
|
|
254
|
+
size: isDir ? 0 : s.size,
|
|
255
|
+
createdAt: s.birthtime.toISOString(),
|
|
256
|
+
modifiedAt: s.mtime.toISOString(),
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
return toErrorResult(err);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Create a directory and any missing parents.
|
|
266
|
+
*
|
|
267
|
+
* @spec VOL-REQ-3
|
|
268
|
+
*/
|
|
269
|
+
export async function volumeMkdir(ctx, path) {
|
|
270
|
+
try {
|
|
271
|
+
const volumeRoot = buildVolumeRoot(ctx.volumesBasePath, ctx.workspaceId);
|
|
272
|
+
const absPath = resolveVolumePath(volumeRoot, path);
|
|
273
|
+
await mkdir(absPath, { recursive: true });
|
|
274
|
+
return { success: true };
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
return toErrorResult(err);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// ---------------------------------------------------------------------------
|
|
281
|
+
// Request dispatch
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
/**
|
|
284
|
+
* Dispatch a `file_volume_*` request message to the appropriate handler.
|
|
285
|
+
*
|
|
286
|
+
* @returns The response message to send back to the instance, or `null`
|
|
287
|
+
* if the message type is not a recognised volume request.
|
|
288
|
+
*
|
|
289
|
+
* @spec VOL-REQ-2
|
|
290
|
+
*/
|
|
291
|
+
export async function handleVolumeRequest(ctx, msg) {
|
|
292
|
+
const type = msg.type;
|
|
293
|
+
const requestId = msg.requestId;
|
|
294
|
+
const sessionId = msg.sessionId;
|
|
295
|
+
const path = msg.path ?? '';
|
|
296
|
+
if (!VOLUME_REQUEST_TYPES.has(type))
|
|
297
|
+
return null;
|
|
298
|
+
const baseResponse = {
|
|
299
|
+
id: `vol-${type}-${requestId}`,
|
|
300
|
+
timestamp: new Date().toISOString(),
|
|
301
|
+
version: '2.0',
|
|
302
|
+
sessionId,
|
|
303
|
+
requestId,
|
|
304
|
+
};
|
|
305
|
+
// VOL-REQ-2: without the `volume` Permission every request is denied.
|
|
306
|
+
if (ctx.permissions?.volume !== true) {
|
|
307
|
+
const reason = 'The volume Permission is not granted to this Installation';
|
|
308
|
+
return {
|
|
309
|
+
...baseResponse,
|
|
310
|
+
type: `${type}_result`,
|
|
311
|
+
success: false,
|
|
312
|
+
error: reason,
|
|
313
|
+
code: ErrorCode.PERMISSION_DENIED,
|
|
314
|
+
details: { layer: 'permission', permission: 'volume', reason },
|
|
315
|
+
...(type === 'file_volume_read_dir' ? { entries: [] } : {}),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
switch (type) {
|
|
319
|
+
case 'file_volume_read_dir': {
|
|
320
|
+
const result = await volumeReadDir(ctx, path);
|
|
321
|
+
return {
|
|
322
|
+
...baseResponse,
|
|
323
|
+
type: 'file_volume_read_dir_result',
|
|
324
|
+
success: result.success,
|
|
325
|
+
entries: result.success ? (result.data ?? []) : [],
|
|
326
|
+
error: result.error,
|
|
327
|
+
code: result.errorCode,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
case 'file_volume_read_file': {
|
|
331
|
+
const result = await volumeReadFile(ctx, path);
|
|
332
|
+
return {
|
|
333
|
+
...baseResponse,
|
|
334
|
+
type: 'file_volume_read_file_result',
|
|
335
|
+
success: result.success,
|
|
336
|
+
data: result.success ? result.data?.data : undefined,
|
|
337
|
+
error: result.error,
|
|
338
|
+
code: result.errorCode,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
case 'file_volume_write_file': {
|
|
342
|
+
const dataBase64 = msg.data ?? '';
|
|
343
|
+
const result = await volumeWriteFile(ctx, path, dataBase64);
|
|
344
|
+
return {
|
|
345
|
+
...baseResponse,
|
|
346
|
+
type: 'file_volume_write_file_result',
|
|
347
|
+
success: result.success,
|
|
348
|
+
error: result.error,
|
|
349
|
+
code: result.errorCode,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
case 'file_volume_delete': {
|
|
353
|
+
const recursive = msg.recursive ?? false;
|
|
354
|
+
const result = await volumeDelete(ctx, path, recursive);
|
|
355
|
+
return {
|
|
356
|
+
...baseResponse,
|
|
357
|
+
type: 'file_volume_delete_result',
|
|
358
|
+
success: result.success,
|
|
359
|
+
error: result.error,
|
|
360
|
+
code: result.errorCode,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
case 'file_volume_stat': {
|
|
364
|
+
const result = await volumeStat(ctx, path);
|
|
365
|
+
return {
|
|
366
|
+
...baseResponse,
|
|
367
|
+
type: 'file_volume_stat_result',
|
|
368
|
+
success: result.success,
|
|
369
|
+
stat: result.success ? result.data : undefined,
|
|
370
|
+
error: result.error,
|
|
371
|
+
code: result.errorCode,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
case 'file_volume_mkdir': {
|
|
375
|
+
const result = await volumeMkdir(ctx, path);
|
|
376
|
+
return {
|
|
377
|
+
...baseResponse,
|
|
378
|
+
type: 'file_volume_mkdir_result',
|
|
379
|
+
success: result.success,
|
|
380
|
+
error: result.error,
|
|
381
|
+
code: result.errorCode,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
default:
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
/** Set of all `file_volume_*` request request types. */
|
|
389
|
+
export const VOLUME_REQUEST_TYPES = new Set([
|
|
390
|
+
'file_volume_read_dir',
|
|
391
|
+
'file_volume_read_file',
|
|
392
|
+
'file_volume_write_file',
|
|
393
|
+
'file_volume_delete',
|
|
394
|
+
'file_volume_stat',
|
|
395
|
+
'file_volume_mkdir',
|
|
396
|
+
]);
|
|
397
|
+
// ---------------------------------------------------------------------------
|
|
398
|
+
// Helpers
|
|
399
|
+
// ---------------------------------------------------------------------------
|
|
400
|
+
/** Convert a caught error into a VolumeResult with the right error code. */
|
|
401
|
+
function toErrorResult(err) {
|
|
402
|
+
const code = err?.code;
|
|
403
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
404
|
+
// Map common fs error codes to protocol error codes
|
|
405
|
+
let errorCode;
|
|
406
|
+
if (code === ErrorCode.INVALID_ARGUMENTS) {
|
|
407
|
+
errorCode = ErrorCode.INVALID_ARGUMENTS;
|
|
408
|
+
}
|
|
409
|
+
else if (code === 'ENOENT') {
|
|
410
|
+
errorCode = FileErrorCode.FILE_NOT_FOUND;
|
|
411
|
+
}
|
|
412
|
+
else if (code === 'EACCES') {
|
|
413
|
+
errorCode = FileErrorCode.INVALID_PATH;
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
errorCode = code;
|
|
417
|
+
}
|
|
418
|
+
return { success: false, error: message, errorCode };
|
|
419
|
+
}
|
|
420
|
+
/** Build the error thrown for a path the Volume refuses (VOL-REQ-3). */
|
|
421
|
+
function invalidPath(message) {
|
|
422
|
+
const err = new Error(message);
|
|
423
|
+
err.code = ErrorCode.INVALID_ARGUMENTS;
|
|
424
|
+
return err;
|
|
425
|
+
}
|
|
426
|
+
//# source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AAC;SAAM,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,SAAS,GAAG,aAAa,CAAC,YAAY,CAAC;IACzC,CAAC;SAAM,CAAC;QACN,SAAS,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AACvD,CAAC;AAED,wEAAwE;AACxE,SAAS,WAAW,CAAC,OAAe;IAClC,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9B,GAA6B,CAAC,IAAI,GAAG,SAAS,CAAC,iBAAiB,CAAC;IAClE,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Instances run as message handlers in the same process — no child
|
|
5
|
+
* processes, no containers. Used for dev mode, tests, and simple
|
|
6
|
+
* standalone apps.
|
|
7
|
+
*/
|
|
8
|
+
import { type Transport } from '@agentapps/protocol';
|
|
9
|
+
import type { InstanceHandle, RuntimeAdapter, SpawnConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* App factory — sets up an app instance on the given transport.
|
|
12
|
+
*
|
|
13
|
+
* This is the contract `@agentapps/sdk`'s `createApp()` will implement:
|
|
14
|
+
* the factory receives one end of a transport and registers tool handlers,
|
|
15
|
+
* event emitters, etc. on it.
|
|
16
|
+
*
|
|
17
|
+
* For tests, a simple factory can be written inline:
|
|
18
|
+
* ```ts
|
|
19
|
+
* const echoFactory: AppFactory = (transport) => {
|
|
20
|
+
* transport.onMessage((msg) => {
|
|
21
|
+
* if (msg.type === 'list_tools') {
|
|
22
|
+
* transport.send({ ...envelope, type: 'tools_list', tools: [...] });
|
|
23
|
+
* }
|
|
24
|
+
* });
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export type AppFactory = (transport: Transport, environment?: InstanceEnvironment) => void | Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* What the Station hands an in-process Instance at spawn. In a child process
|
|
31
|
+
* the same values travel as environment variables.
|
|
32
|
+
*/
|
|
33
|
+
export interface InstanceEnvironment {
|
|
34
|
+
/** Volume in mount mode; `AGENTAPPS_VOLUME_PATH` for child processes (VOL-REQ-5). */
|
|
35
|
+
volumePath?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* In-process runtime adapter. Each `spawn()` call runs the AppFactory
|
|
39
|
+
* with a fresh in-process transport pair, so the app station communicates
|
|
40
|
+
* with the "instance" via direct function calls.
|
|
41
|
+
*/
|
|
42
|
+
export declare class InProcessRuntime implements RuntimeAdapter {
|
|
43
|
+
private readonly factory;
|
|
44
|
+
private counter;
|
|
45
|
+
private instances;
|
|
46
|
+
constructor(factory: AppFactory);
|
|
47
|
+
spawn(config: SpawnConfig): Promise<InstanceHandle>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=in-process-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-process-runtime.d.ts","sourceRoot":"","sources":["../src/in-process-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAGL,KAAK,SAAS,EAEf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,SAAS,EAAE,SAAS,EACpB,WAAW,CAAC,EAAE,mBAAmB,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,qFAAqF;IACrF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,cAAc;IAOzC,OAAO,CAAC,QAAQ,CAAC,OAAO;IANpC,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,SAAS,CAGb;gBAEyB,OAAO,EAAE,UAAU;IAE1C,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC;CA+B1D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process runtime adapter.
|
|
3
|
+
*
|
|
4
|
+
* Instances run as message handlers in the same process — no child
|
|
5
|
+
* processes, no containers. Used for dev mode, tests, and simple
|
|
6
|
+
* standalone apps.
|
|
7
|
+
*/
|
|
8
|
+
import { createInProcessTransportPair, } from '@agentapps/protocol';
|
|
9
|
+
/**
|
|
10
|
+
* In-process runtime adapter. Each `spawn()` call runs the AppFactory
|
|
11
|
+
* with a fresh in-process transport pair, so the app station communicates
|
|
12
|
+
* with the "instance" via direct function calls.
|
|
13
|
+
*/
|
|
14
|
+
export class InProcessRuntime {
|
|
15
|
+
factory;
|
|
16
|
+
counter = 0;
|
|
17
|
+
instances = new Map();
|
|
18
|
+
constructor(factory) {
|
|
19
|
+
this.factory = factory;
|
|
20
|
+
}
|
|
21
|
+
async spawn(config) {
|
|
22
|
+
this.counter++;
|
|
23
|
+
const instanceId = `inproc_${config.installationId}_${this.counter}`;
|
|
24
|
+
const [controllerSide, appSide] = createInProcessTransportPair();
|
|
25
|
+
// Run the factory — it registers its handlers on appSide
|
|
26
|
+
await this.factory(appSide, { volumePath: config.volumePath });
|
|
27
|
+
const state = { controllerSide, appSide, alive: true };
|
|
28
|
+
this.instances.set(instanceId, state);
|
|
29
|
+
const self = this;
|
|
30
|
+
return {
|
|
31
|
+
instanceId,
|
|
32
|
+
send(msg) {
|
|
33
|
+
controllerSide.send(msg);
|
|
34
|
+
},
|
|
35
|
+
onMessage(handler) {
|
|
36
|
+
return controllerSide.onMessage(handler);
|
|
37
|
+
},
|
|
38
|
+
async stop(_gracePeriodMs) {
|
|
39
|
+
state.alive = false;
|
|
40
|
+
self.instances.delete(instanceId);
|
|
41
|
+
await controllerSide.close();
|
|
42
|
+
await appSide.close();
|
|
43
|
+
},
|
|
44
|
+
isAlive() {
|
|
45
|
+
return state.alive;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=in-process-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-process-runtime.js","sourceRoot":"","sources":["../src/in-process-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,4BAA4B,GAI7B,MAAM,qBAAqB,CAAC;AAmC7B;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAOE;IANrB,OAAO,GAAG,CAAC,CAAC;IACZ,SAAS,GAAG,IAAI,GAAG,EAGxB,CAAC;IAEJ,YAA6B,OAAmB;QAAnB,YAAO,GAAP,OAAO,CAAY;IAAG,CAAC;IAEpD,KAAK,CAAC,KAAK,CAAC,MAAmB;QAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,UAAU,GAAG,UAAU,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACrE,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,4BAA4B,EAAE,CAAC;QAEjE,yDAAyD;QACzD,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;QAE/D,MAAM,KAAK,GAAG,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACvD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAEtC,MAAM,IAAI,GAAG,IAAI,CAAC;QAClB,OAAO;YACL,UAAU;YACV,IAAI,CAAC,GAAgB;gBACnB,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC3B,CAAC;YACD,SAAS,CAAC,OAAmC;gBAC3C,OAAO,cAAc,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC3C,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,cAAsB;gBAC/B,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;gBACpB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBAClC,MAAM,cAAc,CAAC,KAAK,EAAE,CAAC;gBAC7B,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;YACxB,CAAC;YACD,OAAO;gBACL,OAAO,KAAK,CAAC,KAAK,CAAC;YACrB,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @agentapps/station — the Agent Apps Station.
|
|
3
|
+
*
|
|
4
|
+
* Central server: brokers tenant sessions, proxies traffic, and owns
|
|
5
|
+
* instance lifecycle — spawn on first session, idle teardown (default
|
|
6
|
+
* 30 min) — behind runtime adapters (in-process / local process).
|
|
7
|
+
*/
|
|
8
|
+
export { PROTOCOL_VERSION } from '@agentapps/protocol';
|
|
9
|
+
/** Default idle timeout before an on-demand instance is torn down (ms). */
|
|
10
|
+
export declare const DEFAULT_IDLE_TIMEOUT_MS: number;
|
|
11
|
+
export { type ApiKeyStore, generateApiKey, hashApiKey, InMemoryApiKeyStore, } from './api-key-store.js';
|
|
12
|
+
export { AppStation, type AppStationConfig } from './app-station.js';
|
|
13
|
+
export { ApprovalManager, type ApprovalOutcome, DEFAULT_APPROVAL_TIMEOUT_MS, type PendingApprovalInfo, } from './approval-manager.js';
|
|
14
|
+
export { type DocumentStore, FileDocumentStore, handleStorageRequest, InMemoryDocumentStore, pageDocuments, STORAGE_DEFAULT_LIMIT, STORAGE_MAX_LIMIT, type StoragePage, type StorageQuery, } from './document-store.js';
|
|
15
|
+
export { generateObjectId, handleObjectRequest, type ObjectRequestScope, type ObjectServeResult, ObjectStore, type ObjectStoreOptions, type StoredObjectMeta, toObjectInfo, } from './file-handlers/object-store.js';
|
|
16
|
+
export { createObjectLinkToken, getStationSecret, type ObjectLinkPayload, type ObjectLinkValidationResult, validateObjectLinkToken, } from './file-handlers/signed-url.js';
|
|
17
|
+
export { buildVolumeRoot, getVolumesBasePath, handleVolumeRequest, resolveMountPath, resolveVolumePath, VOLUME_REQUEST_TYPES, type VolumeHandlerContext, volumeMkdir, } from './file-handlers/volume-handlers.js';
|
|
18
|
+
export { type AppFactory, InProcessRuntime, type InstanceEnvironment, } from './in-process-runtime.js';
|
|
19
|
+
export { LocalProcessRuntime, type LocalProcessRuntimeOptions, } from './local-process-runtime.js';
|
|
20
|
+
export { type OAuthCallbackResult, OAuthManager, type OAuthStartParams, type OAuthTokens, } from './oauth-manager.js';
|
|
21
|
+
export { appVisible, defaultPolicy, evaluatePolicy, type PolicyDecision, type ToolCallFacts, toolVisible, } from './permission-enforcer.js';
|
|
22
|
+
export { InMemoryPolicyStore, type PolicyStore, policyFor } from './policy-store.js';
|
|
23
|
+
export type { SecretsContext, SecretsManager } from './secrets-manager.js';
|
|
24
|
+
export { type AppEntry, type ServerInfo, type StationEndpoint, type StationInstallation, StationServer, type StationServerOptions, serve, } from './server.js';
|
|
25
|
+
export { NOOP_TELEMETRY, NoopTelemetryProvider, type SpanHandle, type TelemetryAttributes, type TelemetryProvider, } from './telemetry.js';
|
|
26
|
+
export type { InstanceHandle, RuntimeAdapter, SpawnConfig } from './types.js';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,2EAA2E;AAC3E,eAAO,MAAM,uBAAuB,QAAiB,CAAC;AAGtD,OAAO,EACL,KAAK,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ACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,KAAK,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAErF,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3E,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,GACN,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,KAAK,UAAU,EACf,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @agentapps/station — the Agent Apps Station.
|
|
3
|
+
*
|
|
4
|
+
* Central server: brokers tenant sessions, proxies traffic, and owns
|
|
5
|
+
* instance lifecycle — spawn on first session, idle teardown (default
|
|
6
|
+
* 30 min) — behind runtime adapters (in-process / local process).
|
|
7
|
+
*/
|
|
8
|
+
export { PROTOCOL_VERSION } from '@agentapps/protocol';
|
|
9
|
+
/** Default idle timeout before an on-demand instance is torn down (ms). */
|
|
10
|
+
export const DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1000;
|
|
11
|
+
// Auth & permissions
|
|
12
|
+
export { generateApiKey, hashApiKey, InMemoryApiKeyStore, } from './api-key-store.js';
|
|
13
|
+
// Core
|
|
14
|
+
export { AppStation } from './app-station.js';
|
|
15
|
+
export { ApprovalManager, DEFAULT_APPROVAL_TIMEOUT_MS, } from './approval-manager.js';
|
|
16
|
+
// Storage (document store)
|
|
17
|
+
export { FileDocumentStore, handleStorageRequest, InMemoryDocumentStore, pageDocuments, STORAGE_DEFAULT_LIMIT, STORAGE_MAX_LIMIT, } from './document-store.js';
|
|
18
|
+
// Objects (immutable blobs with a URL) + signed temporary links
|
|
19
|
+
export { generateObjectId, handleObjectRequest, ObjectStore, toObjectInfo, } from './file-handlers/object-store.js';
|
|
20
|
+
export { createObjectLinkToken, getStationSecret, validateObjectLinkToken, } from './file-handlers/signed-url.js';
|
|
21
|
+
// Volume storage handlers
|
|
22
|
+
export { buildVolumeRoot, getVolumesBasePath, handleVolumeRequest, resolveMountPath, resolveVolumePath, VOLUME_REQUEST_TYPES, volumeMkdir, } from './file-handlers/volume-handlers.js';
|
|
23
|
+
// Runtime adapters
|
|
24
|
+
export { InProcessRuntime, } from './in-process-runtime.js';
|
|
25
|
+
export { LocalProcessRuntime, } from './local-process-runtime.js';
|
|
26
|
+
// OAuth
|
|
27
|
+
export { OAuthManager, } from './oauth-manager.js';
|
|
28
|
+
export { appVisible, defaultPolicy, evaluatePolicy, toolVisible, } from './permission-enforcer.js';
|
|
29
|
+
export { InMemoryPolicyStore, policyFor } from './policy-store.js';
|
|
30
|
+
// Server
|
|
31
|
+
export { StationServer, serve, } from './server.js';
|
|
32
|
+
// Telemetry
|
|
33
|
+
export { NOOP_TELEMETRY, NoopTelemetryProvider, } from './telemetry.js';
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtD,qBAAqB;AACrB,OAAO,EAEL,cAAc,EACd,UAAU,EACV,mBAAmB,GACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO;AACP,OAAO,EAAE,UAAU,EAAyB,MAAM,kBAAkB,CAAC;AACrE,OAAO,EACL,eAAe,EAEf,2BAA2B,GAE5B,MAAM,uBAAuB,CAAC;AAC/B,2BAA2B;AAC3B,OAAO,EAEL,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,qBAAqB,EACrB,iBAAiB,GAGlB,MAAM,qBAAqB,CAAC;AAC7B,gEAAgE;AAChE,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EAGnB,WAAW,EAGX,YAAY,GACb,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAGhB,uBAAuB,GACxB,MAAM,+BAA+B,CAAC;AACvC,0BAA0B;AAC1B,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EAEpB,WAAW,GACZ,MAAM,oCAAoC,CAAC;AAC5C,mBAAmB;AACnB,OAAO,EAEL,gBAAgB,GAEjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,mBAAmB,GAEpB,MAAM,4BAA4B,CAAC;AACpC,QAAQ;AACR,OAAO,EAEL,YAAY,GAGb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EAGd,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAoB,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGrF,SAAS;AACT,OAAO,EAKL,aAAa,EAEb,KAAK,GACN,MAAM,aAAa,CAAC;AACrB,YAAY;AACZ,OAAO,EACL,cAAc,EACd,qBAAqB,GAItB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LocalProcessRuntime — runtime adapter that spawns apps as child processes
|
|
3
|
+
* communicating via stdio (MCP JSON-lines framing).
|
|
4
|
+
*
|
|
5
|
+
* Each spawn() creates a new node child process, wires a StdioTransport
|
|
6
|
+
* across stdin/stdout, and returns an InstanceHandle for lifecycle management.
|
|
7
|
+
*/
|
|
8
|
+
import type { InstanceHandle, RuntimeAdapter, SpawnConfig } from './types.js';
|
|
9
|
+
export interface LocalProcessRuntimeOptions {
|
|
10
|
+
/** Path to the app entry file (e.g., './dist/app.js'). */
|
|
11
|
+
entryPoint: string;
|
|
12
|
+
/** Node executable path (default: 'node'). */
|
|
13
|
+
nodePath?: string;
|
|
14
|
+
/** Additional environment variables for the child process. */
|
|
15
|
+
env?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
export declare class LocalProcessRuntime implements RuntimeAdapter {
|
|
18
|
+
private readonly options;
|
|
19
|
+
private counter;
|
|
20
|
+
private instances;
|
|
21
|
+
constructor(options: LocalProcessRuntimeOptions);
|
|
22
|
+
spawn(config: SpawnConfig): Promise<InstanceHandle>;
|
|
23
|
+
/** Get the number of tracked instances. */
|
|
24
|
+
get instanceCount(): number;
|
|
25
|
+
/** Set a request for when a child process exits (for crash detection). */
|
|
26
|
+
onExit(instanceId: string, request: (code: number | null, signal: NodeJS.Signals | null) => void): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=local-process-runtime.d.ts.map
|