@agimon-ai/po-artifact 0.0.0-alpha.2 → 0.0.0-alpha.21
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 +149 -21
- package/README.md +1 -1
- package/dist/apiContracts.cjs +10 -2
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/apiContracts.mjs +10 -2
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/{artifactFiles-Bo5Mhwq0.cjs → artifactFiles-BmBU9Olm.cjs} +138 -76
- package/dist/artifactFiles-BmBU9Olm.cjs.map +1 -0
- package/dist/{artifactFiles-B8w_HQXv.mjs → artifactFiles-DyIkevXc.mjs} +119 -57
- package/dist/artifactFiles-DyIkevXc.mjs.map +1 -0
- package/dist/artifactFiles.cjs +7 -1
- package/dist/artifactFiles.d.mts +14 -1
- package/dist/artifactFiles.d.mts.map +1 -1
- package/dist/artifactFiles.mjs +3 -1
- package/dist/artifacts-Bhobz1nK.mjs +38 -0
- package/dist/artifacts-Bhobz1nK.mjs.map +1 -0
- package/dist/artifacts-DG_b7DZH.cjs +85 -0
- package/dist/artifacts-DG_b7DZH.cjs.map +1 -0
- package/dist/artifacts-sIj4Xaeu.d.mts +32 -0
- package/dist/artifacts-sIj4Xaeu.d.mts.map +1 -0
- package/dist/extensions/native.mjs +640 -32
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +163 -44
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts +2 -2
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +161 -42
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +848 -136
- package/dist/extensions/web.mjs.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.mts +8 -19
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +20 -20
- package/dist/artifactFiles-B8w_HQXv.mjs.map +0 -1
- package/dist/artifactFiles-Bo5Mhwq0.cjs.map +0 -1
|
@@ -1,9 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as ARTIFACT_REFRESH_MS, s as MAX_PREVIEW_BYTES, t as ARTIFACTS_SERVICE } from "../artifacts-Bhobz1nK.mjs";
|
|
2
|
+
import { a as readArtifactBytes, c as ArtifactAccessError, i as openArtifact, l as artifactRoot, n as listArtifactSessions, r as listArtifacts, t as ensureArtifactRoot } from "../artifactFiles-DyIkevXc.mjs";
|
|
2
3
|
import path from "node:path";
|
|
3
|
-
import { composeServerProviderOverrides, defineServerPlugin } from "@agimon-ai/po-core/
|
|
4
|
-
import { composeRootHooks, defineChannel, defineHook, defineRoot, defineRoute } from "@agimon-ai/po-core/extensionFile";
|
|
4
|
+
import { composeServerProviderOverrides, defineServerPlugin } from "@agimon-ai/po-core/serverPlugin";
|
|
5
|
+
import { composeRootHooks, composeRootInjects, defineChannel, defineHook, defineRoot, defineRoute } from "@agimon-ai/po-core/extensionFile";
|
|
6
|
+
import { Service } from "@deepseek-ai/cordis";
|
|
5
7
|
import { clearTimeout, setTimeout } from "node:timers";
|
|
6
8
|
import { Hono } from "hono";
|
|
9
|
+
//#region src/services/artifacts/index.ts
|
|
10
|
+
/** Roots come only from admitted host configuration, never a file request. */
|
|
11
|
+
function createArtifactStorage(environment) {
|
|
12
|
+
const policies = /* @__PURE__ */ new Map();
|
|
13
|
+
return {
|
|
14
|
+
async rootForSession(sessionId, admittedEnvironment = environment) {
|
|
15
|
+
const root = artifactRoot(sessionId, admittedEnvironment);
|
|
16
|
+
try {
|
|
17
|
+
await ensureArtifactRoot(root);
|
|
18
|
+
return root;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error instanceof ArtifactAccessError && error.status === 404) return void 0;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
sessions: (admittedEnvironment = environment) => listArtifactSessions(admittedEnvironment),
|
|
25
|
+
registerWorkflowVisibility(policy) {
|
|
26
|
+
const owner = Symbol("workflow visibility");
|
|
27
|
+
policies.set(owner, policy);
|
|
28
|
+
return () => {
|
|
29
|
+
policies.delete(owner);
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
workflowVisible: (relativePath, kind) => policies.size > 0 && [...policies.values()].every((policy) => policy(relativePath, kind))
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Publish the same storage instance used by this scope's artifact reader. */
|
|
36
|
+
var ArtifactsService = class extends Service {
|
|
37
|
+
storage;
|
|
38
|
+
constructor(context, storage) {
|
|
39
|
+
super(context, ARTIFACTS_SERVICE);
|
|
40
|
+
this.storage = storage;
|
|
41
|
+
}
|
|
42
|
+
rootForSession(sessionId, environment) {
|
|
43
|
+
return this.storage.rootForSession(sessionId, environment);
|
|
44
|
+
}
|
|
45
|
+
sessions(environment) {
|
|
46
|
+
return this.storage.sessions(environment);
|
|
47
|
+
}
|
|
48
|
+
registerWorkflowVisibility(policy) {
|
|
49
|
+
return this.storage.registerWorkflowVisibility(policy);
|
|
50
|
+
}
|
|
51
|
+
workflowVisible(relativePath, kind) {
|
|
52
|
+
return this.storage.workflowVisible(relativePath, kind);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
function createArtifactsPlugin(storage) {
|
|
56
|
+
return (context) => {
|
|
57
|
+
new ArtifactsService(context, storage);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/extensions/(backend)/root.server.ts
|
|
62
|
+
var root_server_default$1 = defineRoot(({ host }) => {
|
|
63
|
+
const storage = createArtifactStorage(Object.freeze({ ...host.context.environment }));
|
|
64
|
+
return {
|
|
65
|
+
value: storage,
|
|
66
|
+
services: [createArtifactsPlugin(storage)]
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
//#endregion
|
|
7
70
|
//#region src/types/artifacts.ts
|
|
8
71
|
const artifactsChannelType = "artifacts";
|
|
9
72
|
//#endregion
|
|
@@ -21,8 +84,9 @@ async function prepareArtifactRoot(root) {
|
|
|
21
84
|
throw error;
|
|
22
85
|
}
|
|
23
86
|
}
|
|
24
|
-
function createArtifactSession({ host }) {
|
|
87
|
+
function createArtifactSession({ host }, storage) {
|
|
25
88
|
const environment = Object.freeze({ ...host.context.environment });
|
|
89
|
+
const artifactStorage = storage ?? createArtifactStorage(environment);
|
|
26
90
|
let active;
|
|
27
91
|
let timer;
|
|
28
92
|
let pending;
|
|
@@ -32,7 +96,10 @@ function createArtifactSession({ host }) {
|
|
|
32
96
|
const runtime = active;
|
|
33
97
|
if (!runtime || closed) return Promise.resolve();
|
|
34
98
|
pending = (async () => {
|
|
35
|
-
const snapshot =
|
|
99
|
+
const snapshot = {
|
|
100
|
+
...await listArtifacts(runtime.root, artifactStorage.workflowVisible),
|
|
101
|
+
...environment.PO_SESSION_TEMP_DIR ? { temporaryRoot: environment.PO_SESSION_TEMP_DIR } : {}
|
|
102
|
+
};
|
|
36
103
|
if (closed || active !== runtime) return;
|
|
37
104
|
const fingerprint = JSON.stringify(snapshot);
|
|
38
105
|
if (fingerprint === runtime.fingerprint) return;
|
|
@@ -100,9 +167,13 @@ function createArtifactSession({ host }) {
|
|
|
100
167
|
//#endregion
|
|
101
168
|
//#region src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.ts
|
|
102
169
|
const createArtifactServerRoot = (context) => {
|
|
103
|
-
const
|
|
170
|
+
const storage = context.root;
|
|
171
|
+
const runtime = createArtifactSession(context, storage);
|
|
104
172
|
return {
|
|
105
|
-
value:
|
|
173
|
+
value: {
|
|
174
|
+
...runtime,
|
|
175
|
+
storage
|
|
176
|
+
},
|
|
106
177
|
activities: runtime.activities,
|
|
107
178
|
onDispose: runtime.onDispose
|
|
108
179
|
};
|
|
@@ -115,7 +186,7 @@ var root_server_default = defineRoot(createArtifactServerRoot);
|
|
|
115
186
|
function snapshotOf(value) {
|
|
116
187
|
if (typeof value !== "object" || value === null) return false;
|
|
117
188
|
const snapshot = value;
|
|
118
|
-
return Array.isArray(snapshot.items) && (snapshot.error === void 0 || typeof snapshot.error === "string") && snapshot.items.every((item) => typeof item === "object" && item !== null && typeof item.path === "string" && typeof item.name === "string" && typeof item.size === "number" && Number.isFinite(item.size) && typeof item.modifiedAt === "number" && Number.isFinite(item.modifiedAt));
|
|
189
|
+
return Array.isArray(snapshot.items) && (snapshot.error === void 0 || typeof snapshot.error === "string") && (snapshot.temporaryRoot === void 0 || typeof snapshot.temporaryRoot === "string") && snapshot.items.every((item) => typeof item === "object" && item !== null && typeof item.path === "string" && typeof item.name === "string" && typeof item.size === "number" && Number.isFinite(item.size) && typeof item.modifiedAt === "number" && Number.isFinite(item.modifiedAt));
|
|
119
190
|
}
|
|
120
191
|
function createArtifactsChannel() {
|
|
121
192
|
return {
|
|
@@ -138,7 +209,10 @@ function createArtifactsChannel() {
|
|
|
138
209
|
(async () => {
|
|
139
210
|
let snapshot;
|
|
140
211
|
try {
|
|
141
|
-
snapshot =
|
|
212
|
+
snapshot = {
|
|
213
|
+
...await listArtifacts(artifactRoot(scope.sessionId, scope.environment ?? {})),
|
|
214
|
+
...scope.environment?.PO_SESSION_TEMP_DIR ? { temporaryRoot: scope.environment.PO_SESSION_TEMP_DIR } : {}
|
|
215
|
+
};
|
|
142
216
|
} catch (error) {
|
|
143
217
|
snapshot = {
|
|
144
218
|
items: [],
|
|
@@ -171,32 +245,44 @@ const routes = {
|
|
|
171
245
|
list: {
|
|
172
246
|
method: "GET",
|
|
173
247
|
path: "/",
|
|
248
|
+
query: ["scope"],
|
|
174
249
|
response: void 0
|
|
175
250
|
},
|
|
176
251
|
preview: {
|
|
177
252
|
method: "GET",
|
|
178
253
|
path: "/preview",
|
|
179
|
-
query: ["path"],
|
|
254
|
+
query: ["path", "scope"],
|
|
180
255
|
response: void 0
|
|
181
256
|
},
|
|
182
257
|
content: {
|
|
183
258
|
method: "GET",
|
|
184
259
|
path: "/content",
|
|
185
|
-
query: ["path"],
|
|
260
|
+
query: ["path", "scope"],
|
|
186
261
|
raw: true
|
|
187
262
|
}
|
|
188
263
|
};
|
|
189
264
|
//#endregion
|
|
190
265
|
//#region src/services/artifactsApi/index.ts
|
|
191
|
-
function createArtifactsApi(root) {
|
|
266
|
+
function createArtifactsApi(root, options = {}) {
|
|
192
267
|
const app = new Hono();
|
|
268
|
+
const selectedRoot = (scope) => {
|
|
269
|
+
if (scope === void 0 || scope === "artifacts") return root;
|
|
270
|
+
if (scope !== "temporary") throw new ArtifactAccessError("Invalid file scope.", 400);
|
|
271
|
+
if (!options.temporaryRoot) throw new ArtifactAccessError("Temporary files are unavailable for this session.", 404);
|
|
272
|
+
return options.temporaryRoot;
|
|
273
|
+
};
|
|
193
274
|
app.onError((error, context) => context.json({ error: error instanceof ArtifactAccessError ? error.message : "The artifact could not be read." }, error instanceof ArtifactAccessError ? error.status : 500));
|
|
194
275
|
app.get(routes.list.path, async (context) => {
|
|
195
|
-
const
|
|
196
|
-
|
|
276
|
+
const selected = selectedRoot(context.req.query("scope"));
|
|
277
|
+
const snapshot = await listArtifacts(selected, selected === root ? options.workflowVisible : () => true);
|
|
278
|
+
return context.json({
|
|
279
|
+
...snapshot,
|
|
280
|
+
...options.temporaryRoot ? { temporaryRoot: options.temporaryRoot } : {}
|
|
281
|
+
}, snapshot.error === void 0 ? 200 : 500);
|
|
197
282
|
});
|
|
198
283
|
app.get(routes.preview.path, async (context) => {
|
|
199
|
-
const
|
|
284
|
+
const selected = selectedRoot(context.req.query("scope"));
|
|
285
|
+
const file = await openArtifact(selected, context.req.query("path"), selected === root ? options.workflowVisible : () => true);
|
|
200
286
|
try {
|
|
201
287
|
const preview = {
|
|
202
288
|
path: file.path,
|
|
@@ -228,7 +314,8 @@ function createArtifactsApi(root) {
|
|
|
228
314
|
}
|
|
229
315
|
});
|
|
230
316
|
app.get(routes.content.path, async (context) => {
|
|
231
|
-
const
|
|
317
|
+
const selected = selectedRoot(context.req.query("scope"));
|
|
318
|
+
const file = await openArtifact(selected, context.req.query("path"), selected === root ? options.workflowVisible : () => true);
|
|
232
319
|
try {
|
|
233
320
|
if (file.stat.size > 26214400) throw new ArtifactAccessError("This artifact is too large to download.", 413);
|
|
234
321
|
const version = `"${file.stat.dev}-${file.stat.ino}-${file.stat.size}-${file.stat.mtimeMs}-${file.stat.ctimeMs}"`;
|
|
@@ -292,19 +379,25 @@ function createArtifactsApi(root) {
|
|
|
292
379
|
});
|
|
293
380
|
return app;
|
|
294
381
|
}
|
|
382
|
+
function createArtifactApi(storage) {
|
|
383
|
+
return {
|
|
384
|
+
basePath: "artifacts",
|
|
385
|
+
start(context) {
|
|
386
|
+
if (!context.sessionId) throw new Error("Artifacts requires a session identity.");
|
|
387
|
+
const app = createArtifactsApi(artifactRoot(context.sessionId, context.environment ?? {}), {
|
|
388
|
+
temporaryRoot: context.environment?.PO_SESSION_TEMP_DIR,
|
|
389
|
+
workflowVisible: storage?.workflowVisible
|
|
390
|
+
});
|
|
391
|
+
return {
|
|
392
|
+
fetch: (request) => app.fetch(request),
|
|
393
|
+
close: () => void 0
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
295
398
|
//#endregion
|
|
296
399
|
//#region src/extensions/workspaces/sessions/(backend)/api/artifacts/route.server.ts
|
|
297
|
-
var route_server_default = defineRoute({
|
|
298
|
-
basePath: "artifacts",
|
|
299
|
-
start(context) {
|
|
300
|
-
if (!context.sessionId) throw new Error("Artifacts requires a session identity.");
|
|
301
|
-
const app = createArtifactsApi(artifactRoot(context.sessionId, context.environment ?? {}));
|
|
302
|
-
return {
|
|
303
|
-
fetch: (request) => app.fetch(request),
|
|
304
|
-
close: () => void 0
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
});
|
|
400
|
+
var route_server_default = defineRoute(({ root }) => createArtifactApi(root.storage));
|
|
308
401
|
//#endregion
|
|
309
402
|
//#region src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server.ts
|
|
310
403
|
var before_agent_start_server_default = defineHook((context) => context.root.beforeAgentStart);
|
|
@@ -314,44 +407,70 @@ var tool_execution_end_server_default = defineHook((context) => context.root.too
|
|
|
314
407
|
//#endregion
|
|
315
408
|
//#region generated/server.ts
|
|
316
409
|
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
410
|
+
/* v8 ignore next -- generated normalization branch */
|
|
411
|
+
const defined = (values) => values.filter((value) => value !== void 0);
|
|
317
412
|
const via = (identity, value) => value === void 0 ? void 0 : {
|
|
318
413
|
...identity,
|
|
319
414
|
...value
|
|
320
415
|
};
|
|
321
|
-
const
|
|
416
|
+
const serverPlugin = defineServerPlugin({
|
|
322
417
|
name: "@agimon-ai/po-artifact",
|
|
323
|
-
providerOverrides: composeServerProviderOverrides(root_server_default),
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
418
|
+
providerOverrides: composeServerProviderOverrides(root_server_default$1, root_server_default),
|
|
419
|
+
injects: composeRootInjects({
|
|
420
|
+
global: [root_server_default$1],
|
|
421
|
+
workspace: [root_server_default$1],
|
|
422
|
+
session: [root_server_default$1, root_server_default]
|
|
423
|
+
}),
|
|
424
|
+
global: async (context) => {
|
|
425
|
+
const scopeGlobal = await context.scopeRoot("global", root_server_default$1, context);
|
|
426
|
+
return {
|
|
427
|
+
...composeRootHooks(scopeGlobal),
|
|
428
|
+
get channels() {
|
|
429
|
+
return [() => via({ frameType: "artifacts" }, artifacts_server_default())];
|
|
430
|
+
},
|
|
431
|
+
services: [...scopeGlobal.services ?? []]
|
|
432
|
+
};
|
|
433
|
+
},
|
|
434
|
+
workspace: async (context) => {
|
|
435
|
+
const scopeGlobal = await context.scopeRoot("global", root_server_default$1, context);
|
|
436
|
+
return {
|
|
437
|
+
...composeRootHooks(scopeGlobal),
|
|
438
|
+
get channels() {
|
|
439
|
+
return defined([context.hosted("global") ? void 0 : () => via({ frameType: "artifacts" }, artifacts_server_default())]);
|
|
440
|
+
},
|
|
441
|
+
services: [...scopeGlobal.services ?? []]
|
|
442
|
+
};
|
|
443
|
+
},
|
|
330
444
|
session: async (context) => {
|
|
331
|
-
const
|
|
332
|
-
const
|
|
445
|
+
const scopeGlobal = await context.scopeRoot("global", root_server_default$1, context);
|
|
446
|
+
const contextGlobal = {
|
|
333
447
|
...context,
|
|
448
|
+
root: scopeGlobal.value
|
|
449
|
+
};
|
|
450
|
+
const scopeSession = await context.scopeRoot("session", root_server_default, contextGlobal);
|
|
451
|
+
const contextSession = {
|
|
452
|
+
...contextGlobal,
|
|
334
453
|
root: scopeSession.value
|
|
335
454
|
};
|
|
336
455
|
return {
|
|
337
|
-
...composeRootHooks(scopeSession),
|
|
456
|
+
...composeRootHooks(scopeGlobal, scopeSession),
|
|
338
457
|
get api() {
|
|
339
458
|
return [at(route_server_default, contextSession)];
|
|
340
459
|
},
|
|
341
460
|
get channels() {
|
|
342
|
-
return [() => via({ frameType: "artifacts" }, artifacts_server_default())];
|
|
461
|
+
return defined([context.hosted("global") ? void 0 : () => via({ frameType: "artifacts" }, artifacts_server_default())]);
|
|
343
462
|
},
|
|
344
463
|
get hooks() {
|
|
345
464
|
return [via({ event: "before_agent_start" }, at(before_agent_start_server_default, contextSession)), via({ event: "tool_execution_end" }, at(tool_execution_end_server_default, contextSession))];
|
|
346
465
|
},
|
|
347
|
-
services: [...scopeSession.services ?? []],
|
|
466
|
+
services: [...scopeGlobal.services ?? [], ...scopeSession.services ?? []],
|
|
348
467
|
get activities() {
|
|
349
|
-
return [...scopeSession.activities ?? []];
|
|
468
|
+
return [...scopeGlobal.activities ?? [], ...scopeSession.activities ?? []];
|
|
350
469
|
}
|
|
351
470
|
};
|
|
352
471
|
}
|
|
353
472
|
});
|
|
354
473
|
//#endregion
|
|
355
|
-
export {
|
|
474
|
+
export { serverPlugin as default, serverPlugin };
|
|
356
475
|
|
|
357
476
|
//# sourceMappingURL=server.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","names":["rootSession","channelArtifacts","apiRoute","hookBeforeAgentStart","hookToolExecutionEnd"],"sources":["../../src/types/artifacts.ts","../../src/services/artifactSession/index.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/services/artifactChannel/index.ts","../../src/extensions/(backend)/channel/artifacts.server.ts","../../src/types/apiRoutes.ts","../../src/services/artifactsApi/index.ts","../../src/extensions/workspaces/sessions/(backend)/api/artifacts/route.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/tool-execution-end.server.ts","../../generated/server.ts"],"sourcesContent":["export interface ArtifactItem {\n /** Relative to the current session's artifact directory. */\n path: string;\n name: string;\n size: number;\n modifiedAt: number;\n}\n\nexport interface ArtifactSnapshot {\n items: ArtifactItem[];\n error?: string;\n}\n\nexport interface ArtifactPreview {\n path: string;\n content: string;\n mimeType: string;\n unavailable?: boolean;\n reason?: string;\n}\n\nexport const artifactsChannelType = 'artifacts';\n","import { clearTimeout, setTimeout } from 'node:timers';\n\nimport type { DoomHeadlessActivity, DoomHeadlessExecutionContext, DoomHeadlessHook } from '@agimon-ai/po-core/headless';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport { ARTIFACT_REFRESH_MS } from '../../constants/artifacts';\nimport { artifactsChannelType } from '../../types/artifacts';\nimport { ArtifactAccessError, artifactRoot, ensureArtifactRoot, listArtifacts } from '../artifactFiles';\n\n/**\n * Creates the session artifact folder. Resolves false when the host has no artifact folder\n * (the edge build in M1 rejects with a 404); Node never rejects with that status here.\n */\nasync function prepareArtifactRoot(root: string): Promise<boolean> {\n try {\n await ensureArtifactRoot(root);\n return true;\n } catch (error) {\n if (error instanceof ArtifactAccessError && error.status === 404) return false;\n throw error;\n }\n}\n\nexport function createArtifactSession({ host }: DoomServerPluginContext) {\n const environment = Object.freeze({ ...host.context.environment });\n let active: { context: DoomHeadlessExecutionContext; root: string; fingerprint?: string } | undefined;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let pending: Promise<void> | undefined;\n let closed = false;\n\n const refresh = (): Promise<void> => {\n if (pending) return pending;\n const runtime = active;\n if (!runtime || closed) return Promise.resolve();\n pending = (async () => {\n const snapshot = await listArtifacts(runtime.root);\n if (closed || active !== runtime) return;\n const fingerprint = JSON.stringify(snapshot);\n if (fingerprint === runtime.fingerprint) return;\n runtime.fingerprint = fingerprint;\n host.context.directEvents?.publish(artifactsChannelType, runtime.context.sessionId, snapshot);\n })().finally(() => {\n pending = undefined;\n });\n return pending;\n };\n const schedule = (): void => {\n if (!active || closed) return;\n timer = setTimeout(() => {\n timer = undefined;\n void refresh().finally(schedule);\n }, ARTIFACT_REFRESH_MS);\n };\n const stop = async (): Promise<void> => {\n active = undefined;\n if (timer !== undefined) clearTimeout(timer);\n timer = undefined;\n await pending;\n };\n const activity: DoomHeadlessActivity = {\n name: 'artifacts',\n async start(context) {\n if (closed) throw new Error('Artifact session is closed.');\n await stop();\n const root = artifactRoot(context.sessionId, environment);\n if (!(await prepareArtifactRoot(root))) return stop;\n if (closed) throw new Error('Artifact session is closed.');\n active = { context, root };\n await refresh();\n schedule();\n return stop;\n },\n };\n const beforeAgentStart: DoomHeadlessHook = {\n event: 'before_agent_start',\n async handle(event, context) {\n const root = artifactRoot(context.sessionId, environment);\n const systemPrompt = typeof event.systemPrompt === 'string' ? event.systemPrompt : '';\n if (!(await prepareArtifactRoot(root))) return { systemPrompt };\n const declaration = `Session artifact folder: ${root}`;\n if (systemPrompt.includes(declaration)) return { systemPrompt };\n return {\n systemPrompt:\n `${systemPrompt}\\n\\n${declaration}\\nSave user-designated artifacts and important deliverable documents in this folder, using descriptive filenames. Keep ordinary repository source edits in their existing locations. Do not move existing documents or overwrite artifacts without the user's intent. This folder belongs only to the current session.`.trim(),\n };\n },\n };\n const toolExecutionEnd: DoomHeadlessHook = {\n event: 'tool_execution_end',\n handle(_event, context) {\n return active?.context.sessionId === context.sessionId ? refresh() : undefined;\n },\n };\n return {\n activities: [activity],\n beforeAgentStart,\n toolExecutionEnd,\n onDispose: async () => {\n closed = true;\n await stop();\n },\n };\n}\n","import type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport { createArtifactSession } from '../../../../../services/artifactSession';\n\nexport const createArtifactServerRoot = (context: DoomServerPluginContext) => {\n const runtime = createArtifactSession(context);\n return { value: runtime, activities: runtime.activities, onDispose: runtime.onDispose };\n};\nexport type ArtifactServerScope = ReturnType<typeof createArtifactServerRoot>['value'];\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\n\nimport { createArtifactServerRoot } from './_lib/serverRoot';\n\nexport default defineRoot(createArtifactServerRoot);\n","import type { DoomHubChannel } from '@agimon-ai/po-core/hubChannel';\n\nimport { artifactsChannelType, type ArtifactSnapshot } from '../../types/artifacts';\nimport { artifactRoot, listArtifacts } from '../artifactFiles';\n\nfunction snapshotOf(value: unknown): value is ArtifactSnapshot {\n if (typeof value !== 'object' || value === null) return false;\n const snapshot = value as Partial<ArtifactSnapshot>;\n return (\n Array.isArray(snapshot.items) &&\n (snapshot.error === undefined || typeof snapshot.error === 'string') &&\n snapshot.items.every(\n (item) =>\n typeof item === 'object' &&\n item !== null &&\n typeof item.path === 'string' &&\n typeof item.name === 'string' &&\n typeof item.size === 'number' &&\n Number.isFinite(item.size) &&\n typeof item.modifiedAt === 'number' &&\n Number.isFinite(item.modifiedAt),\n )\n );\n}\n\nexport function createArtifactsChannel(): DoomHubChannel {\n return {\n frameType: artifactsChannelType,\n start(host) {\n const sessions = new Map<string, { snapshot?: ArtifactSnapshot; unsubscribe: () => void }>();\n return {\n payloadFor(scope) {\n return sessions.get(scope.sessionId)?.snapshot;\n },\n sessionAdded(scope) {\n sessions.get(scope.sessionId)?.unsubscribe();\n const state: { snapshot?: ArtifactSnapshot; unsubscribe: () => void } = { unsubscribe: () => undefined };\n sessions.set(scope.sessionId, state);\n state.unsubscribe = host.directEvents.subscribe(\n artifactsChannelType,\n scope.sessionId,\n (snapshot) => {\n if (!snapshotOf(snapshot) || sessions.get(scope.sessionId) !== state) return;\n state.snapshot = snapshot;\n host.publish(scope.sessionId, snapshot);\n },\n { replayLatest: true },\n );\n void (async () => {\n let snapshot: ArtifactSnapshot;\n try {\n snapshot = await listArtifacts(artifactRoot(scope.sessionId, scope.environment ?? {}));\n } catch (error) {\n snapshot = {\n items: [],\n error: error instanceof Error ? error.message : 'The artifact folder could not be read.',\n };\n }\n // A live session event wins over the earlier seed read.\n if (sessions.get(scope.sessionId) !== state || state.snapshot !== undefined) return;\n state.snapshot = snapshot;\n host.publish(scope.sessionId, snapshot);\n })();\n },\n sessionRemoved(sessionId) {\n sessions.get(sessionId)?.unsubscribe();\n sessions.delete(sessionId);\n },\n close() {\n for (const state of sessions.values()) state.unsubscribe();\n sessions.clear();\n },\n };\n },\n };\n}\n","import { defineChannel } from '@agimon-ai/po-core/extensionFile';\n\nimport { createArtifactsChannel } from '../../../services/artifactChannel';\n\nexport default defineChannel(createArtifactsChannel);\n","import type { ApiResponseOf, ApiRoutes } from '@agimon-ai/po-core/web';\n\nimport type { ArtifactPreview, ArtifactSnapshot } from './artifacts';\n\nconst routes = {\n list: {\n method: 'GET',\n path: '/',\n response: undefined as unknown as ApiResponseOf<ArtifactSnapshot>,\n },\n preview: {\n method: 'GET',\n path: '/preview',\n query: ['path'],\n response: undefined as unknown as ApiResponseOf<ArtifactPreview>,\n },\n content: {\n method: 'GET',\n path: '/content',\n query: ['path'],\n raw: true,\n },\n} as const satisfies ApiRoutes;\n\nexport default routes;\n","import path from 'node:path';\n\nimport type { DoomApi, DoomApiContext } from '@agimon-ai/po-core/packageApi';\nimport { Hono } from 'hono';\n\nimport { MAX_CONTENT_BYTES, MAX_PREVIEW_BYTES } from '../../constants/artifacts';\nimport routes from '../../types/apiRoutes';\nimport type { ArtifactPreview } from '../../types/artifacts';\nimport { ArtifactAccessError, artifactRoot, listArtifacts, openArtifact, readArtifactBytes } from '../artifactFiles';\n\nexport function createArtifactsApi(root: string): Hono {\n const app = new Hono();\n app.onError((error, context) =>\n context.json(\n { error: error instanceof ArtifactAccessError ? error.message : 'The artifact could not be read.' },\n error instanceof ArtifactAccessError ? error.status : 500,\n ),\n );\n app.get(routes.list.path, async (context) => {\n const snapshot = await listArtifacts(root);\n return context.json(snapshot, snapshot.error === undefined ? 200 : 500);\n });\n app.get(routes.preview.path, async (context) => {\n const file = await openArtifact(root, context.req.query('path'));\n try {\n const preview: ArtifactPreview = { path: file.path, content: '', mimeType: file.mimeType };\n if (file.stat.size > MAX_PREVIEW_BYTES) {\n return context.json({\n ...preview,\n unavailable: true,\n reason: 'This artifact is too large for a text preview.',\n });\n }\n const bytes = await readArtifactBytes(file.handle, MAX_PREVIEW_BYTES + 1);\n if (bytes.byteLength > MAX_PREVIEW_BYTES)\n return context.json({\n ...preview,\n unavailable: true,\n reason: 'This artifact is too large for a text preview.',\n });\n if (bytes.subarray(0, 8192).includes(0))\n return context.json({ ...preview, unavailable: true, reason: 'This artifact is binary.' });\n return context.json({ ...preview, content: new TextDecoder().decode(bytes) });\n } finally {\n await file.handle.close();\n }\n });\n app.get(routes.content.path, async (context) => {\n const file = await openArtifact(root, context.req.query('path'));\n try {\n if (file.stat.size > MAX_CONTENT_BYTES)\n throw new ArtifactAccessError('This artifact is too large to download.', 413);\n const version = `\"${file.stat.dev}-${file.stat.ino}-${file.stat.size}-${file.stat.mtimeMs}-${file.stat.ctimeMs}\"`;\n const name = encodeURIComponent(path.basename(file.path)).replace(\n /[!'()*]/gu,\n (value) => `%${value.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n const headers = new Headers({\n 'content-type': file.mimeType,\n 'content-disposition': `attachment; filename*=UTF-8''${name}`,\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n 'content-security-policy': \"default-src 'none'; sandbox\",\n 'accept-ranges': 'bytes',\n etag: version,\n });\n const expectedVersion = context.req.header('if-match');\n if (expectedVersion !== undefined && expectedVersion !== version)\n return new Response(null, { status: 412, headers });\n let start = 0;\n let end = file.stat.size - 1;\n const range = context.req.header('range');\n if (range !== undefined) {\n const match = /^bytes=(\\d*)-(\\d*)$/u.exec(range);\n if (\n !match ||\n (!match[1] && !match[2]) ||\n file.stat.size === 0 ||\n [match[1], match[2]].some((value) => value !== '' && !Number.isSafeInteger(Number(value)))\n ) {\n headers.set('content-range', `bytes */${file.stat.size}`);\n return new Response(null, { status: 416, headers });\n }\n if (match[1] === '') {\n const suffix = Number(match[2]);\n start = suffix > 0 ? Math.max(0, file.stat.size - suffix) : file.stat.size;\n } else {\n start = Number(match[1]);\n end = match[2] === '' ? end : Math.min(end, Number(match[2]));\n }\n if (start > end || start >= file.stat.size) {\n headers.set('content-range', `bytes */${file.stat.size}`);\n return new Response(null, { status: 416, headers });\n }\n headers.set('content-range', `bytes ${start}-${end}/${file.stat.size}`);\n }\n const bytes = await readArtifactBytes(file.handle, Math.max(0, end - start + 1), start);\n const after = await file.handle.stat();\n if (after.size !== file.stat.size || after.mtimeMs !== file.stat.mtimeMs || after.ctimeMs !== file.stat.ctimeMs)\n return new Response(null, { status: 412, headers });\n headers.set('content-length', String(bytes.byteLength));\n return new Response(bytes, { status: range === undefined ? 200 : 206, headers });\n } finally {\n await file.handle.close();\n }\n });\n return app;\n}\n\nexport const api: DoomApi = {\n basePath: 'artifacts',\n start(context: DoomApiContext) {\n if (!context.sessionId) throw new Error('Artifacts requires a session identity.');\n const app = createArtifactsApi(artifactRoot(context.sessionId, context.environment ?? {}));\n return { fetch: (request) => app.fetch(request), close: () => undefined };\n },\n};\n","import { defineRoute } from '@agimon-ai/po-core/extensionFile';\n\nimport { api } from '../../../../../../services/artifactsApi';\n\nexport default defineRoute(api);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { ArtifactServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(\n (context: WithRoot<DoomServerPluginContext, ArtifactServerScope>) => context.root.beforeAgentStart,\n);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { DoomServerPluginContext } from '@agimon-ai/po-core/serverFacet';\n\nimport type { ArtifactServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(\n (context: WithRoot<DoomServerPluginContext, ArtifactServerScope>) => context.root.toolExecutionEnd,\n);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type DoomServerSessionPlugin } from '@agimon-ai/po-core/serverFacet';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverFacet';\nimport { composeRootHooks } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport channelArtifacts from '../src/extensions/(backend)/channel/artifacts.server';\nimport apiRoute from '../src/extensions/workspaces/sessions/(backend)/api/artifacts/route.server';\nimport hookBeforeAgentStart from '../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server';\nimport hookToolExecutionEnd from '../src/extensions/workspaces/sessions/(backend)/hook/tool-execution-end.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const facet = defineServerPlugin({\n name: '@agimon-ai/po-artifact',\n providerOverrides: composeServerProviderOverrides(rootSession),\n global: () => ({\n get channels(): DoomServerSessionPlugin['channels'] { return [() => via({ frameType: 'artifacts' }, channelArtifacts())]; },\n }),\n workspace: () => ({\n get channels(): DoomServerSessionPlugin['channels'] { return [() => via({ frameType: 'artifacts' }, channelArtifacts())]; },\n }),\n session: async (context) => {\n const scopeSession = await rootSession(context);\n const contextSession = { ...context, root: scopeSession.value };\n return {\n ...composeRootHooks(scopeSession),\n get api(): DoomServerSessionPlugin['api'] { return [at(apiRoute, contextSession)]; },\n get channels(): DoomServerSessionPlugin['channels'] { return [() => via({ frameType: 'artifacts' }, channelArtifacts())]; },\n get hooks(): DoomServerSessionPlugin['hooks'] { return [via({ event: 'before_agent_start' }, at(hookBeforeAgentStart, contextSession)), via({ event: 'tool_execution_end' }, at(hookToolExecutionEnd, contextSession))]; },\n services: [...(scopeSession.services ?? [])],\n get activities(): DoomServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default facet;\n"],"mappings":";;;;;;;AAqBA,MAAa,uBAAuB;;;;;;;ACRpC,eAAe,oBAAoB,MAAgC;CACjE,IAAI;EACF,MAAM,mBAAmB,IAAI;EAC7B,OAAO;CACT,SAAS,OAAO;EACd,IAAI,iBAAiB,uBAAuB,MAAM,WAAW,KAAK,OAAO;EACzE,MAAM;CACR;AACF;AAEA,SAAgB,sBAAsB,EAAE,QAAiC;CACvE,MAAM,cAAc,OAAO,OAAO,EAAE,GAAG,KAAK,QAAQ,YAAY,CAAC;CACjE,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI,SAAS;CAEb,MAAM,gBAA+B;EACnC,IAAI,SAAS,OAAO;EACpB,MAAM,UAAU;EAChB,IAAI,CAAC,WAAW,QAAQ,OAAO,QAAQ,QAAQ;EAC/C,WAAW,YAAY;GACrB,MAAM,WAAW,MAAM,cAAc,QAAQ,IAAI;GACjD,IAAI,UAAU,WAAW,SAAS;GAClC,MAAM,cAAc,KAAK,UAAU,QAAQ;GAC3C,IAAI,gBAAgB,QAAQ,aAAa;GACzC,QAAQ,cAAc;GACtB,KAAK,QAAQ,cAAc,QAAQ,sBAAsB,QAAQ,QAAQ,WAAW,QAAQ;EAC9F,EAAA,CAAG,CAAC,CAAC,cAAc;GACjB,UAAU,KAAA;EACZ,CAAC;EACD,OAAO;CACT;CACA,MAAM,iBAAuB;EAC3B,IAAI,CAAC,UAAU,QAAQ;EACvB,QAAQ,iBAAiB;GACvB,QAAQ,KAAA;GACR,QAAa,CAA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EAC1B,MAAM,eAAe,MAAMD,oBAAY,OAAO;EAC9C,MAAM,iBAAiB;GAAE,GAAG;GAAS,MAAM,aAAa;EAAM;EAC9D,OAAO;GACL,GAAG,iBAAiB,YAAY;GAChC,IAAI,MAAsC;IAAE,OAAO,CAAC,GAAGE,sBAAU,cAAc,CAAC;GAAG;GACnF,IAAI,WAAgD;IAAE,OAAO,OAAO,IAAI,EAAE,WAAW,YAAY,GAAGD,yBAAiB,CAAC,CAAC;GAAG;GAC1H,IAAI,QAA0C;IAAE,OAAO,CAAC,IAAI,EAAE,OAAO,qBAAqB,GAAG,GAAGE,mCAAsB,cAAc,CAAC,GAAG,IAAI,EAAE,OAAO,qBAAqB,GAAG,GAAGC,mCAAsB,cAAc,CAAC,CAAC;GAAG;GACzN,UAAU,CAAC,GAAI,aAAa,YAAY,CAAC,CAAE;GAC3C,IAAI,aAAoD;IAAE,OAAO,CAAC,GAAI,aAAa,cAAc,CAAC,CAAE;GAAG;EACzG;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"server.mjs","names":["rootGlobal","rootSession","channelArtifacts","apiRoute","hookBeforeAgentStart","hookToolExecutionEnd"],"sources":["../../src/services/artifacts/index.ts","../../src/extensions/(backend)/root.server.ts","../../src/types/artifacts.ts","../../src/services/artifactSession/index.ts","../../src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/services/artifactChannel/index.ts","../../src/extensions/(backend)/channel/artifacts.server.ts","../../src/types/apiRoutes.ts","../../src/services/artifactsApi/index.ts","../../src/extensions/workspaces/sessions/(backend)/api/artifacts/route.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server.ts","../../src/extensions/workspaces/sessions/(backend)/hook/tool-execution-end.server.ts","../../generated/server.ts"],"sourcesContent":["import { type Context, Service } from '@deepseek-ai/cordis';\n\nimport { ARTIFACTS_SERVICE } from '../../constants/artifacts';\nimport type { ArtifactWorkflowVisibility } from '../../types/artifacts';\nimport { ArtifactAccessError, artifactRoot, ensureArtifactRoot, listArtifactSessions } from '../artifactFiles';\nimport type { ArtifactStorage } from './type';\n\n/** Roots come only from admitted host configuration, never a file request. */\nexport function createArtifactStorage(environment: Readonly<Record<string, string | undefined>>): ArtifactStorage {\n const policies = new Map<symbol, ArtifactWorkflowVisibility>();\n return {\n async rootForSession(sessionId, admittedEnvironment = environment) {\n const root = artifactRoot(sessionId, admittedEnvironment);\n try {\n await ensureArtifactRoot(root);\n return root;\n } catch (error) {\n if (error instanceof ArtifactAccessError && error.status === 404) return undefined;\n throw error;\n }\n },\n sessions: (admittedEnvironment = environment) => listArtifactSessions(admittedEnvironment),\n registerWorkflowVisibility(policy) {\n const owner = Symbol('workflow visibility');\n policies.set(owner, policy);\n return () => {\n policies.delete(owner);\n };\n },\n workflowVisible: (relativePath, kind) =>\n policies.size > 0 && [...policies.values()].every((policy) => policy(relativePath, kind)),\n };\n}\n\n/** Publish the same storage instance used by this scope's artifact reader. */\nexport class ArtifactsService extends Service implements ArtifactStorage {\n constructor(\n context: Context,\n private readonly storage: ArtifactStorage,\n ) {\n super(context, ARTIFACTS_SERVICE);\n }\n rootForSession(sessionId: string, environment?: Readonly<Record<string, string | undefined>>) {\n return this.storage.rootForSession(sessionId, environment);\n }\n sessions(environment?: Readonly<Record<string, string | undefined>>) {\n return this.storage.sessions(environment);\n }\n registerWorkflowVisibility(policy: ArtifactWorkflowVisibility) {\n return this.storage.registerWorkflowVisibility(policy);\n }\n workflowVisible(relativePath: string, kind: 'file' | 'directory') {\n return this.storage.workflowVisible(relativePath, kind);\n }\n}\n\nexport function createArtifactsPlugin(storage: ArtifactStorage): (context: Context) => void {\n return (context) => {\n new ArtifactsService(context, storage);\n };\n}\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context {\n 'po/artifacts': ArtifactsService;\n }\n}\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverPlugin';\n\nimport { createArtifactStorage, createArtifactsPlugin } from '../../services/artifacts';\n\nexport default defineRoot(({ host }: PoServerPluginContext) => {\n const storage = createArtifactStorage(Object.freeze({ ...host.context.environment }));\n return { value: storage, services: [createArtifactsPlugin(storage)] };\n});\n","export type ArtifactScope = 'artifacts' | 'temporary';\n\n/** Workflow owns the visibility of its reserved artifact subtree. */\nexport type ArtifactWorkflowVisibility = (relativePath: string, kind: 'file' | 'directory') => boolean;\n\nexport interface ArtifactItem {\n /** Relative to the current session's artifact directory. */\n path: string;\n name: string;\n size: number;\n modifiedAt: number;\n}\n\nexport interface ArtifactSnapshot {\n items: ArtifactItem[];\n /** Host-admitted root used only to recognize session temporary-file references. */\n temporaryRoot?: string;\n error?: string;\n}\n\nexport interface ArtifactPreview {\n path: string;\n content: string;\n mimeType: string;\n unavailable?: boolean;\n reason?: string;\n}\n\nexport const artifactsChannelType = 'artifacts';\n","import { clearTimeout, setTimeout } from 'node:timers';\n\nimport type { PoHeadlessActivity, PoHeadlessExecutionContext, PoHeadlessHook } from '@agimon-ai/po-core/headless';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverPlugin';\n\nimport { ARTIFACT_REFRESH_MS } from '../../constants/artifacts';\nimport { artifactsChannelType } from '../../types/artifacts';\nimport { ArtifactAccessError, artifactRoot, ensureArtifactRoot, listArtifacts } from '../artifactFiles';\nimport { createArtifactStorage } from '../artifacts';\nimport type { ArtifactStorage } from '../artifacts/type';\n\n/**\n * Creates the session artifact folder. Resolves false when the host has no artifact folder\n * (the edge build in M1 rejects with a 404); Node never rejects with that status here.\n */\nasync function prepareArtifactRoot(root: string): Promise<boolean> {\n try {\n await ensureArtifactRoot(root);\n return true;\n } catch (error) {\n if (error instanceof ArtifactAccessError && error.status === 404) return false;\n throw error;\n }\n}\n\nexport function createArtifactSession({ host }: PoServerPluginContext, storage?: ArtifactStorage) {\n const environment = Object.freeze({ ...host.context.environment });\n const artifactStorage = storage ?? createArtifactStorage(environment);\n let active: { context: PoHeadlessExecutionContext; root: string; fingerprint?: string } | undefined;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let pending: Promise<void> | undefined;\n let closed = false;\n\n const refresh = (): Promise<void> => {\n if (pending) return pending;\n const runtime = active;\n if (!runtime || closed) return Promise.resolve();\n pending = (async () => {\n const snapshot = {\n ...(await listArtifacts(runtime.root, artifactStorage.workflowVisible)),\n ...(environment.PO_SESSION_TEMP_DIR ? { temporaryRoot: environment.PO_SESSION_TEMP_DIR } : {}),\n };\n if (closed || active !== runtime) return;\n const fingerprint = JSON.stringify(snapshot);\n if (fingerprint === runtime.fingerprint) return;\n runtime.fingerprint = fingerprint;\n host.context.directEvents?.publish(artifactsChannelType, runtime.context.sessionId, snapshot);\n })().finally(() => {\n pending = undefined;\n });\n return pending;\n };\n const schedule = (): void => {\n if (!active || closed) return;\n timer = setTimeout(() => {\n timer = undefined;\n void refresh().finally(schedule);\n }, ARTIFACT_REFRESH_MS);\n };\n const stop = async (): Promise<void> => {\n active = undefined;\n if (timer !== undefined) clearTimeout(timer);\n timer = undefined;\n await pending;\n };\n const activity: PoHeadlessActivity = {\n name: 'artifacts',\n async start(context) {\n if (closed) throw new Error('Artifact session is closed.');\n await stop();\n const root = artifactRoot(context.sessionId, environment);\n if (!(await prepareArtifactRoot(root))) return stop;\n if (closed) throw new Error('Artifact session is closed.');\n active = { context, root };\n await refresh();\n schedule();\n return stop;\n },\n };\n const beforeAgentStart: PoHeadlessHook = {\n event: 'before_agent_start',\n async handle(event, context) {\n const root = artifactRoot(context.sessionId, environment);\n const systemPrompt = typeof event.systemPrompt === 'string' ? event.systemPrompt : '';\n if (!(await prepareArtifactRoot(root))) return { systemPrompt };\n const declaration = `Session artifact folder: ${root}`;\n if (systemPrompt.includes(declaration)) return { systemPrompt };\n return {\n systemPrompt:\n `${systemPrompt}\\n\\n${declaration}\\nSave user-designated artifacts and important deliverable documents in this folder, using descriptive filenames. Keep ordinary repository source edits in their existing locations. Do not move existing documents or overwrite artifacts without the user's intent. This folder belongs only to the current session.`.trim(),\n };\n },\n };\n const toolExecutionEnd: PoHeadlessHook = {\n event: 'tool_execution_end',\n handle(_event, context) {\n return active?.context.sessionId === context.sessionId ? refresh() : undefined;\n },\n };\n return {\n activities: [activity],\n beforeAgentStart,\n toolExecutionEnd,\n onDispose: async () => {\n closed = true;\n await stop();\n },\n };\n}\n","import type { WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverPlugin';\n\nimport type { ArtifactStorage } from '../../../../../services/artifacts/type';\nimport { createArtifactSession } from '../../../../../services/artifactSession';\n\nexport const createArtifactServerRoot = (context: WithRoot<PoServerPluginContext, ArtifactStorage>) => {\n const storage = context.root;\n const runtime = createArtifactSession(context, storage);\n return { value: { ...runtime, storage }, activities: runtime.activities, onDispose: runtime.onDispose };\n};\nexport type ArtifactServerScope = ReturnType<typeof createArtifactServerRoot>['value'];\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\n\nimport { createArtifactServerRoot } from './_lib/serverRoot';\n\nexport default defineRoot(createArtifactServerRoot);\n","import type { PoHubChannel } from '@agimon-ai/po-core/hubChannel';\n\nimport { artifactsChannelType, type ArtifactSnapshot } from '../../types/artifacts';\nimport { artifactRoot, listArtifacts } from '../artifactFiles';\n\nfunction snapshotOf(value: unknown): value is ArtifactSnapshot {\n if (typeof value !== 'object' || value === null) return false;\n const snapshot = value as Partial<ArtifactSnapshot>;\n return (\n Array.isArray(snapshot.items) &&\n (snapshot.error === undefined || typeof snapshot.error === 'string') &&\n (snapshot.temporaryRoot === undefined || typeof snapshot.temporaryRoot === 'string') &&\n snapshot.items.every(\n (item) =>\n typeof item === 'object' &&\n item !== null &&\n typeof item.path === 'string' &&\n typeof item.name === 'string' &&\n typeof item.size === 'number' &&\n Number.isFinite(item.size) &&\n typeof item.modifiedAt === 'number' &&\n Number.isFinite(item.modifiedAt),\n )\n );\n}\n\nexport function createArtifactsChannel(): PoHubChannel {\n return {\n frameType: artifactsChannelType,\n start(host) {\n const sessions = new Map<string, { snapshot?: ArtifactSnapshot; unsubscribe: () => void }>();\n return {\n payloadFor(scope) {\n return sessions.get(scope.sessionId)?.snapshot;\n },\n sessionAdded(scope) {\n sessions.get(scope.sessionId)?.unsubscribe();\n const state: { snapshot?: ArtifactSnapshot; unsubscribe: () => void } = { unsubscribe: () => undefined };\n sessions.set(scope.sessionId, state);\n state.unsubscribe = host.directEvents.subscribe(\n artifactsChannelType,\n scope.sessionId,\n (snapshot) => {\n if (!snapshotOf(snapshot) || sessions.get(scope.sessionId) !== state) return;\n state.snapshot = snapshot;\n host.publish(scope.sessionId, snapshot);\n },\n { replayLatest: true },\n );\n void (async () => {\n let snapshot: ArtifactSnapshot;\n try {\n snapshot = {\n ...(await listArtifacts(artifactRoot(scope.sessionId, scope.environment ?? {}))),\n ...(scope.environment?.PO_SESSION_TEMP_DIR\n ? { temporaryRoot: scope.environment.PO_SESSION_TEMP_DIR }\n : {}),\n };\n } catch (error) {\n snapshot = {\n items: [],\n error: error instanceof Error ? error.message : 'The artifact folder could not be read.',\n };\n }\n // A live session event wins over the earlier seed read.\n if (sessions.get(scope.sessionId) !== state || state.snapshot !== undefined) return;\n state.snapshot = snapshot;\n host.publish(scope.sessionId, snapshot);\n })();\n },\n sessionRemoved(sessionId) {\n sessions.get(sessionId)?.unsubscribe();\n sessions.delete(sessionId);\n },\n close() {\n for (const state of sessions.values()) state.unsubscribe();\n sessions.clear();\n },\n };\n },\n };\n}\n","import { defineChannel } from '@agimon-ai/po-core/extensionFile';\n\nimport { createArtifactsChannel } from '../../../services/artifactChannel';\n\nexport default defineChannel(createArtifactsChannel);\n","import type { ApiResponseOf, ApiRoutes } from '@agimon-ai/po-core/web';\n\nimport type { ArtifactPreview, ArtifactSnapshot } from './artifacts';\n\nconst routes = {\n list: {\n method: 'GET',\n path: '/',\n query: ['scope'],\n response: undefined as unknown as ApiResponseOf<ArtifactSnapshot>,\n },\n preview: {\n method: 'GET',\n path: '/preview',\n query: ['path', 'scope'],\n response: undefined as unknown as ApiResponseOf<ArtifactPreview>,\n },\n content: {\n method: 'GET',\n path: '/content',\n query: ['path', 'scope'],\n raw: true,\n },\n} as const satisfies ApiRoutes;\n\nexport default routes;\n","import path from 'node:path';\n\nimport type { PoApi, PoApiContext } from '@agimon-ai/po-core/packageApi';\nimport { Hono } from 'hono';\n\nimport { MAX_CONTENT_BYTES, MAX_PREVIEW_BYTES } from '../../constants/artifacts';\nimport routes from '../../types/apiRoutes';\nimport type { ArtifactPreview, ArtifactWorkflowVisibility } from '../../types/artifacts';\nimport { ArtifactAccessError, artifactRoot, listArtifacts, openArtifact, readArtifactBytes } from '../artifactFiles';\nimport type { ArtifactStorage } from '../artifacts/type';\n\nexport function createArtifactsApi(\n root: string,\n options: { temporaryRoot?: string; workflowVisible?: ArtifactWorkflowVisibility } = {},\n): Hono {\n const app = new Hono();\n const selectedRoot = (scope: string | undefined): string => {\n if (scope === undefined || scope === 'artifacts') return root;\n if (scope !== 'temporary') throw new ArtifactAccessError('Invalid file scope.', 400);\n if (!options.temporaryRoot) throw new ArtifactAccessError('Temporary files are unavailable for this session.', 404);\n return options.temporaryRoot;\n };\n app.onError((error, context) =>\n context.json(\n { error: error instanceof ArtifactAccessError ? error.message : 'The artifact could not be read.' },\n error instanceof ArtifactAccessError ? error.status : 500,\n ),\n );\n app.get(routes.list.path, async (context) => {\n const selected = selectedRoot(context.req.query('scope'));\n const snapshot = await listArtifacts(selected, selected === root ? options.workflowVisible : () => true);\n return context.json(\n { ...snapshot, ...(options.temporaryRoot ? { temporaryRoot: options.temporaryRoot } : {}) },\n snapshot.error === undefined ? 200 : 500,\n );\n });\n app.get(routes.preview.path, async (context) => {\n const selected = selectedRoot(context.req.query('scope'));\n const file = await openArtifact(\n selected,\n context.req.query('path'),\n selected === root ? options.workflowVisible : () => true,\n );\n try {\n const preview: ArtifactPreview = { path: file.path, content: '', mimeType: file.mimeType };\n if (file.stat.size > MAX_PREVIEW_BYTES) {\n return context.json({\n ...preview,\n unavailable: true,\n reason: 'This artifact is too large for a text preview.',\n });\n }\n const bytes = await readArtifactBytes(file.handle, MAX_PREVIEW_BYTES + 1);\n if (bytes.byteLength > MAX_PREVIEW_BYTES)\n return context.json({\n ...preview,\n unavailable: true,\n reason: 'This artifact is too large for a text preview.',\n });\n if (bytes.subarray(0, 8192).includes(0))\n return context.json({ ...preview, unavailable: true, reason: 'This artifact is binary.' });\n return context.json({ ...preview, content: new TextDecoder().decode(bytes) });\n } finally {\n await file.handle.close();\n }\n });\n app.get(routes.content.path, async (context) => {\n const selected = selectedRoot(context.req.query('scope'));\n const file = await openArtifact(\n selected,\n context.req.query('path'),\n selected === root ? options.workflowVisible : () => true,\n );\n try {\n if (file.stat.size > MAX_CONTENT_BYTES)\n throw new ArtifactAccessError('This artifact is too large to download.', 413);\n const version = `\"${file.stat.dev}-${file.stat.ino}-${file.stat.size}-${file.stat.mtimeMs}-${file.stat.ctimeMs}\"`;\n const name = encodeURIComponent(path.basename(file.path)).replace(\n /[!'()*]/gu,\n (value) => `%${value.charCodeAt(0).toString(16).toUpperCase()}`,\n );\n const headers = new Headers({\n 'content-type': file.mimeType,\n 'content-disposition': `attachment; filename*=UTF-8''${name}`,\n 'cache-control': 'no-store',\n 'x-content-type-options': 'nosniff',\n 'content-security-policy': \"default-src 'none'; sandbox\",\n 'accept-ranges': 'bytes',\n etag: version,\n });\n const expectedVersion = context.req.header('if-match');\n if (expectedVersion !== undefined && expectedVersion !== version)\n return new Response(null, { status: 412, headers });\n let start = 0;\n let end = file.stat.size - 1;\n const range = context.req.header('range');\n if (range !== undefined) {\n const match = /^bytes=(\\d*)-(\\d*)$/u.exec(range);\n if (\n !match ||\n (!match[1] && !match[2]) ||\n file.stat.size === 0 ||\n [match[1], match[2]].some((value) => value !== '' && !Number.isSafeInteger(Number(value)))\n ) {\n headers.set('content-range', `bytes */${file.stat.size}`);\n return new Response(null, { status: 416, headers });\n }\n if (match[1] === '') {\n const suffix = Number(match[2]);\n start = suffix > 0 ? Math.max(0, file.stat.size - suffix) : file.stat.size;\n } else {\n start = Number(match[1]);\n end = match[2] === '' ? end : Math.min(end, Number(match[2]));\n }\n if (start > end || start >= file.stat.size) {\n headers.set('content-range', `bytes */${file.stat.size}`);\n return new Response(null, { status: 416, headers });\n }\n headers.set('content-range', `bytes ${start}-${end}/${file.stat.size}`);\n }\n const bytes = await readArtifactBytes(file.handle, Math.max(0, end - start + 1), start);\n const after = await file.handle.stat();\n if (after.size !== file.stat.size || after.mtimeMs !== file.stat.mtimeMs || after.ctimeMs !== file.stat.ctimeMs)\n return new Response(null, { status: 412, headers });\n headers.set('content-length', String(bytes.byteLength));\n return new Response(bytes, { status: range === undefined ? 200 : 206, headers });\n } finally {\n await file.handle.close();\n }\n });\n return app;\n}\n\nexport function createArtifactApi(storage?: ArtifactStorage): PoApi {\n return {\n basePath: 'artifacts',\n start(context: PoApiContext) {\n if (!context.sessionId) throw new Error('Artifacts requires a session identity.');\n const app = createArtifactsApi(artifactRoot(context.sessionId, context.environment ?? {}), {\n temporaryRoot: context.environment?.PO_SESSION_TEMP_DIR,\n workflowVisible: storage?.workflowVisible,\n });\n return { fetch: (request) => app.fetch(request), close: () => undefined };\n },\n };\n}\n\nexport const api: PoApi = createArtifactApi();\n","import { defineRoute, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverPlugin';\n\nimport { createArtifactApi } from '../../../../../../services/artifactsApi';\nimport type { ArtifactServerScope } from '../../_lib/serverRoot';\n\nexport default defineRoute(({ root }: WithRoot<PoServerPluginContext, ArtifactServerScope>) =>\n createArtifactApi(root.storage),\n);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverPlugin';\n\nimport type { ArtifactServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(\n (context: WithRoot<PoServerPluginContext, ArtifactServerScope>) => context.root.beforeAgentStart,\n);\n","import { defineHook, type WithRoot } from '@agimon-ai/po-core/extensionFile';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverPlugin';\n\nimport type { ArtifactServerScope } from '../_lib/serverRoot';\n\nexport default defineHook(\n (context: WithRoot<PoServerPluginContext, ArtifactServerScope>) => context.root.toolExecutionEnd,\n);\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverPlugin';\nimport { composeRootHooks, composeRootInjects } from '@agimon-ai/po-core/extensionFile';\n\nimport rootGlobal from '../src/extensions/(backend)/root.server';\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport channelArtifacts from '../src/extensions/(backend)/channel/artifacts.server';\nimport apiRoute from '../src/extensions/workspaces/sessions/(backend)/api/artifacts/route.server';\nimport hookBeforeAgentStart from '../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.server';\nimport hookToolExecutionEnd from '../src/extensions/workspaces/sessions/(backend)/hook/tool-execution-end.server';\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\n/* v8 ignore next -- generated normalization branch */\nconst defined = <T>(values: readonly (T | undefined)[]): T[] =>\n values.filter((value): value is T => value !== undefined);\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const serverPlugin = defineServerPlugin({\n name: '@agimon-ai/po-artifact',\n providerOverrides: composeServerProviderOverrides(rootGlobal, rootSession),\n injects: composeRootInjects({ global: [rootGlobal], workspace: [rootGlobal], session: [rootGlobal, rootSession] }),\n global: async (context) => {\n const scopeGlobal = await context.scopeRoot('global', rootGlobal, context);\n return {\n ...composeRootHooks(scopeGlobal),\n get channels(): PoServerSessionPlugin['channels'] { return [() => via({ frameType: 'artifacts' }, channelArtifacts())]; },\n services: [...(scopeGlobal.services ?? [])],\n };\n },\n workspace: async (context) => {\n const scopeGlobal = await context.scopeRoot('global', rootGlobal, context);\n return {\n ...composeRootHooks(scopeGlobal),\n get channels(): PoServerSessionPlugin['channels'] { return defined([context.hosted('global') ? undefined : () => via({ frameType: 'artifacts' }, channelArtifacts())]); },\n services: [...(scopeGlobal.services ?? [])],\n };\n },\n session: async (context) => {\n const scopeGlobal = await context.scopeRoot('global', rootGlobal, context);\n const contextGlobal = { ...context, root: scopeGlobal.value };\n const scopeSession = await context.scopeRoot('session', rootSession, contextGlobal);\n const contextSession = { ...contextGlobal, root: scopeSession.value };\n return {\n ...composeRootHooks(scopeGlobal, scopeSession),\n get api(): PoServerSessionPlugin['api'] { return [at(apiRoute, contextSession)]; },\n get channels(): PoServerSessionPlugin['channels'] { return defined([context.hosted('global') ? undefined : () => via({ frameType: 'artifacts' }, channelArtifacts())]); },\n get hooks(): PoServerSessionPlugin['hooks'] { return [via({ event: 'before_agent_start' }, at(hookBeforeAgentStart, contextSession)), via({ event: 'tool_execution_end' }, at(hookToolExecutionEnd, contextSession))]; },\n services: [...(scopeGlobal.services ?? []), ...(scopeSession.services ?? [])],\n get activities(): PoServerSessionPlugin['activities'] { return [...(scopeGlobal.activities ?? []), ...(scopeSession.activities ?? [])]; },\n };\n },\n});\n\nexport default serverPlugin;\n"],"mappings":";;;;;;;;;;AAQA,SAAgB,sBAAsB,aAA4E;CAChH,MAAM,2BAAW,IAAI,IAAwC;CAC7D,OAAO;EACL,MAAM,eAAe,WAAW,sBAAsB,aAAa;GACjE,MAAM,OAAO,aAAa,WAAW,mBAAmB;GACxD,IAAI;IACF,MAAM,mBAAmB,IAAI;IAC7B,OAAO;GACT,SAAS,OAAO;IACd,IAAI,iBAAiB,uBAAuB,MAAM,WAAW,KAAK,OAAO,KAAA;IACzE,MAAM;GACR;EACF;EACA,WAAW,sBAAsB,gBAAgB,qBAAqB,mBAAmB;EACzF,2BAA2B,QAAQ;GACj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