@agimon-ai/po-artifact 0.0.0-alpha.2 → 0.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/LICENSE +149 -21
  2. package/README.md +1 -1
  3. package/dist/apiContracts.cjs +10 -2
  4. package/dist/apiContracts.cjs.map +1 -1
  5. package/dist/apiContracts.d.mts.map +1 -1
  6. package/dist/apiContracts.mjs +10 -2
  7. package/dist/apiContracts.mjs.map +1 -1
  8. package/dist/{artifactFiles-Bo5Mhwq0.cjs → artifactFiles-BmBU9Olm.cjs} +138 -76
  9. package/dist/artifactFiles-BmBU9Olm.cjs.map +1 -0
  10. package/dist/{artifactFiles-B8w_HQXv.mjs → artifactFiles-DyIkevXc.mjs} +119 -57
  11. package/dist/artifactFiles-DyIkevXc.mjs.map +1 -0
  12. package/dist/artifactFiles.cjs +7 -1
  13. package/dist/artifactFiles.d.mts +14 -1
  14. package/dist/artifactFiles.d.mts.map +1 -1
  15. package/dist/artifactFiles.mjs +3 -1
  16. package/dist/artifacts-Bhobz1nK.mjs +38 -0
  17. package/dist/artifacts-Bhobz1nK.mjs.map +1 -0
  18. package/dist/artifacts-DG_b7DZH.cjs +85 -0
  19. package/dist/artifacts-DG_b7DZH.cjs.map +1 -0
  20. package/dist/artifacts-sIj4Xaeu.d.mts +32 -0
  21. package/dist/artifacts-sIj4Xaeu.d.mts.map +1 -0
  22. package/dist/extensions/native.mjs +640 -32
  23. package/dist/extensions/native.mjs.map +1 -1
  24. package/dist/extensions/server.cjs +163 -44
  25. package/dist/extensions/server.cjs.map +1 -1
  26. package/dist/extensions/server.d.mts +2 -2
  27. package/dist/extensions/server.d.mts.map +1 -1
  28. package/dist/extensions/server.mjs +161 -42
  29. package/dist/extensions/server.mjs.map +1 -1
  30. package/dist/extensions/web.mjs +848 -136
  31. package/dist/extensions/web.mjs.map +1 -1
  32. package/dist/index.cjs +3 -0
  33. package/dist/index.d.mts +8 -19
  34. package/dist/index.d.mts.map +1 -1
  35. package/dist/index.mjs +1 -1
  36. package/package.json +20 -20
  37. package/dist/artifactFiles-B8w_HQXv.mjs.map +0 -1
  38. package/dist/artifactFiles-Bo5Mhwq0.cjs.map +0 -1
package/LICENSE CHANGED
@@ -1,21 +1,149 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Vuong Ngo
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ License text copyright © 2017 MariaDB Corporation Ab, All Rights Reserved.
2
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
3
+
4
+ Parameters
5
+
6
+ Licensor: Agimon Pty Ltd
7
+ Licensed Work: Po, the software in the Po source repository and the
8
+ packages released from it, in each version released by
9
+ the Licensor.
10
+ The Licensed Work is (c) 2026 Agimon Pty Ltd.
11
+ Material identified as third-party in the "Third-party
12
+ components" section at the end of this file or in a
13
+ NOTICE file, and any package or directory whose own
14
+ license file grants a different license, is not part of
15
+ the Licensed Work and remains under its own license.
16
+ Additional Use Grant: You may make production use of the Licensed Work if
17
+ your use is Eligible Use. "Eligible Use" is production use that falls
18
+ within at least one of the following:
19
+
20
+ (a) Personal Use. Use by an individual for their own personal purposes,
21
+ and not on behalf of, or for the benefit of, an employer, client, or
22
+ other Organization. Use by an individual in the course of employment
23
+ or engagement by an Organization is use by that Organization.
24
+
25
+ (b) Small Organization Use. Use by or on behalf of an Organization whose
26
+ Annual Revenue is less than USD 1,000,000.
27
+
28
+ (c) Non-profit, Education and Research Use. Use, regardless of Annual
29
+ Revenue, by (i) an Organization registered or recognized as a
30
+ non-profit or charitable organization under the laws of its
31
+ jurisdiction, for its non-profit purposes; (ii) an accredited school,
32
+ college, or university, for teaching, learning, or academic research;
33
+ or (iii) a publicly funded research institution, for its research.
34
+
35
+ (d) Service Provider Use. Use by a consultant, contractor, agency, or other
36
+ service provider, regardless of its own Annual Revenue, solely to
37
+ build, deploy, host, operate, or support the Licensed Work for a client
38
+ whose own use would be Eligible Use under (a), (b), or (c). A service
39
+ provider's use for its own purposes is Eligible Use only if the service
40
+ provider itself qualifies under (b) or (c).
41
+
42
+
43
+ Hosted services. Offering the Licensed Work to third parties as a hosted
44
+ or managed service whose primary value is the Licensed Work is Eligible
45
+ Use only if each such third party's own use would be Eligible Use.
46
+
47
+ Definitions. "Organization" means any company, partnership, sole
48
+ proprietorship, trust, association, government body, or other entity, and
49
+ includes an individual acting in a business or professional capacity.
50
+ "Affiliate" means any entity that directly or indirectly controls, is
51
+ controlled by, or is under common control with an Organization, where
52
+ "control" means ownership of more than 50% of the voting interests of an
53
+ entity or the power to direct its management and policies by contract or
54
+ otherwise. "Annual Revenue" means the total gross revenue of an
55
+ Organization and all of its Affiliates combined, from all sources and
56
+ whether or not related to the Licensed Work, for its most recently
57
+ completed fiscal year, or, if it has not completed a fiscal year, for the
58
+ twelve months before the use (or since its formation, if shorter),
59
+ converted into US dollars at the average exchange rate for that period.
60
+ Proceeds of equity or debt financing are not revenue.
61
+
62
+ Threshold. If an Organization stops qualifying under (b), its existing
63
+ production use remains Eligible Use for 90 days after it stops
64
+ qualifying, after which it must obtain a commercial license or stop
65
+ production use. Use that was Eligible Use when it occurred never requires
66
+ a commercial license after the fact.
67
+ Change Date: Four years from the date a version of the Licensed Work
68
+ is first publicly released by the Licensor.
69
+ Change License: Apache License, Version 2.0
70
+
71
+ For information about alternative licensing arrangements for the Licensed
72
+ Work, please visit: https://agimon.ai/licensing
73
+
74
+ Notice
75
+
76
+ The Business Source License (this document, or the "License") is not an Open
77
+ Source license. However, the Licensed Work will eventually be made available
78
+ under an Open Source License, as stated in this License.
79
+
80
+ -----------------------------------------------------------------------------
81
+
82
+ Business Source License 1.1
83
+
84
+ Terms
85
+
86
+ The Licensor hereby grants you the right to copy, modify, create derivative
87
+ works, redistribute, and make non-production use of the Licensed Work. The
88
+ Licensor may make an Additional Use Grant, above, permitting limited
89
+ production use.
90
+
91
+ Effective on the Change Date, or the fourth anniversary of the first publicly
92
+ available distribution of a specific version of the Licensed Work under this
93
+ License, whichever comes first, the Licensor hereby grants you rights under
94
+ the terms of the Change License, and the rights granted in the paragraph
95
+ above terminate.
96
+
97
+ If your use of the Licensed Work does not comply with the requirements
98
+ currently in effect as described in this License, you must purchase a
99
+ commercial license from the Licensor, its affiliated entities, or authorized
100
+ resellers, or you must refrain from using the Licensed Work.
101
+
102
+ All copies of the original and modified Licensed Work, and derivative works
103
+ of the Licensed Work, are subject to this License. This License applies
104
+ separately for each version of the Licensed Work and the Change Date may vary
105
+ for each version of the Licensed Work released by Licensor.
106
+
107
+ You must conspicuously display this License on each original or modified copy
108
+ of the Licensed Work. If you receive the Licensed Work in original or
109
+ modified form from a third party, the terms and conditions set forth in this
110
+ License apply to your use of that work.
111
+
112
+ Any use of the Licensed Work in violation of this License will automatically
113
+ terminate your rights under this License for the current and all other
114
+ versions of the Licensed Work.
115
+
116
+ This License does not grant you any right in any trademark or logo of
117
+ Licensor or its affiliates (provided that you may use a trademark or logo of
118
+ Licensor as expressly required by this License).
119
+
120
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
121
+ AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
122
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
123
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
124
+ TITLE.
125
+
126
+ MariaDB hereby grants you permission to use this License’s text to license
127
+ your works, and to refer to it using the trademark “Business Source License”,
128
+ as long as you comply with the Covenants of Licensor below.
129
+
130
+ Covenants of Licensor
131
+
132
+ In consideration of the right to use this License’s text and the “Business
133
+ Source License” name and trademark, Licensor covenants to MariaDB, and to all
134
+ other recipients of the licensed work to be provided by Licensor:
135
+
136
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
137
+ or a license that is compatible with GPL Version 2.0 or a later version,
138
+ where “compatible” means that software provided under the Change License can
139
+ be included in a program with software provided under GPL Version 2.0 or a
140
+ later version. Licensor may specify additional Change Licenses without
141
+ limitation.
142
+
143
+ 2. To either: (a) specify an additional grant of rights to use that does not
144
+ impose any additional restriction on the right granted in this License, as
145
+ the Additional Use Grant; or (b) insert the text “None”.
146
+
147
+ 3. To specify a Change Date.
148
+
149
+ 4. Not to modify this License in any other way.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Always-loaded session artifact storage and web/native views.
4
4
 
5
5
  Each session owns a durable folder under the configured Po agent directory:
6
- `doom-artifacts/<session-id>/`. The agent's system prompt names that folder for
6
+ `po-artifacts/<session-id>/`. The agent's system prompt names that folder for
7
7
  user-designated artifacts and important deliverable documents. Ordinary source
8
8
  edits stay in the project.
9
9
 
@@ -14,14 +14,21 @@ const ArtifactsPayloadSchema = typebox.Type.Object({
14
14
  size: N,
15
15
  modifiedAt: N
16
16
  })),
17
+ temporaryRoot: typebox.Type.Optional(S),
17
18
  error: typebox.Type.Optional(S)
18
19
  });
20
+ const scopeQuery = {
21
+ name: "scope",
22
+ in: "query",
23
+ required: false,
24
+ schema: typebox.Type.Union([typebox.Type.Literal("artifacts"), typebox.Type.Literal("temporary")])
25
+ };
19
26
  const query = [{
20
27
  name: "path",
21
28
  in: "query",
22
29
  required: true,
23
30
  schema: typebox.Type.String({ minLength: 1 })
24
- }];
31
+ }, scopeQuery];
25
32
  const apiContracts = (0, _agimon_ai_po_core_apiContracts.defineApiContract)({
26
33
  version: 1,
27
34
  dynamic: [],
@@ -33,7 +40,8 @@ const apiContracts = (0, _agimon_ai_po_core_apiContracts.defineApiContract)({
33
40
  path: "/",
34
41
  method: "GET",
35
42
  authentication: "owner",
36
- description: "List regular artifacts in the current session folder by modification time.",
43
+ description: "List regular artifacts or temporary files in the current session folder by modification time.",
44
+ parameters: [scopeQuery],
37
45
  responses: (0, _agimon_ai_po_core_apiContracts.jsonApiResponses)(ArtifactsPayloadSchema)
38
46
  },
39
47
  {
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.cjs","names":["Type","defineApiContract","jsonApiResponses"],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nexport const ArtifactsPayloadSchema = Type.Object({\n items: Type.Array(Type.Object({ path: S, name: S, size: N, modifiedAt: N })),\n error: Type.Optional(S),\n});\nconst query = [{ name: 'path', in: 'query' as const, required: true, schema: Type.String({ minLength: 1 }) }];\nexport const apiContracts = defineApiContract({\n version: 1,\n dynamic: [],\n http: [\n {\n id: 'artifacts.list',\n scope: 'session',\n basePath: 'artifacts',\n path: '/',\n method: 'GET',\n authentication: 'owner',\n description: 'List regular artifacts in the current session folder by modification time.',\n responses: jsonApiResponses(ArtifactsPayloadSchema),\n },\n {\n id: 'artifacts.preview',\n scope: 'session',\n basePath: 'artifacts',\n path: '/preview',\n method: 'GET',\n authentication: 'owner',\n description: 'Read bounded text preview from the current session artifact folder.',\n parameters: query,\n responses: jsonApiResponses(\n Type.Object({\n path: S,\n content: S,\n mimeType: S,\n unavailable: Type.Optional(Type.Boolean()),\n reason: Type.Optional(S),\n }),\n ),\n },\n {\n id: 'artifacts.content',\n scope: 'session',\n basePath: 'artifacts',\n path: '/content',\n method: 'GET',\n authentication: 'owner',\n description: 'Read bounded artifact bytes, with range and version checks.',\n parameters: [\n ...query,\n { name: 'Range', in: 'header', required: false, schema: S },\n { name: 'If-Match', in: 'header', required: false, schema: S },\n ],\n responses: {\n '200': { description: 'Artifact bytes.', contentType: 'application/octet-stream' },\n '206': { description: 'Artifact byte range.', contentType: 'application/octet-stream' },\n '400': { description: 'Invalid artifact path.' },\n '403': { description: 'Artifact access rejected.' },\n '404': { description: 'Artifact missing.' },\n '412': { description: 'Artifact changed.' },\n '413': { description: 'Artifact too large.' },\n '416': { description: 'Invalid byte range.' },\n },\n },\n ],\n sockets: (['global', 'workspace'] as const).map((scope) => ({\n id: 'artifacts.channel',\n scope,\n service: 'po.hub',\n member: 'artifacts',\n kind: 'channel',\n direction: 'server-to-client',\n description: 'Current-session artifact metadata in the hub frame payload.',\n input: ArtifactsPayloadSchema,\n })),\n});\nexport default apiContracts;\n"],"mappings":";;;;;;;AAGA,MAAM,IAAIA,QAAAA,KAAK,OAAO;AACtB,MAAM,IAAIA,QAAAA,KAAK,OAAO;AACtB,MAAa,yBAAyBA,QAAAA,KAAK,OAAO;CAChD,OAAOA,QAAAA,KAAK,MAAMA,QAAAA,KAAK,OAAO;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,YAAY;CAAE,CAAC,CAAC;CAC3E,OAAOA,QAAAA,KAAK,SAAS,CAAC;AACxB,CAAC;AACD,MAAM,QAAQ,CAAC;CAAE,MAAM;CAAQ,IAAI;CAAkB,UAAU;CAAM,QAAQA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;AAAE,CAAC;AAC5G,MAAa,gBAAA,GAAeC,gCAAAA,kBAAAA,CAAkB;CAC5C,SAAS;CACT,SAAS,CAAC;CACV,MAAM;EACJ;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAA,GAAWC,gCAAAA,iBAAAA,CAAiB,sBAAsB;EACpD;EACA;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY;GACZ,YAAA,GAAWA,gCAAAA,iBAAAA,CACTF,QAAAA,KAAK,OAAO;IACV,MAAM;IACN,SAAS;IACT,UAAU;IACV,aAAaA,QAAAA,KAAK,SAASA,QAAAA,KAAK,QAAQ,CAAC;IACzC,QAAQA,QAAAA,KAAK,SAAS,CAAC;GACzB,CAAC,CACH;EACF;EACA;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY;IACV,GAAG;IACH;KAAE,MAAM;KAAS,IAAI;KAAU,UAAU;KAAO,QAAQ;IAAE;IAC1D;KAAE,MAAM;KAAY,IAAI;KAAU,UAAU;KAAO,QAAQ;IAAE;GAC/D;GACA,WAAW;IACT,OAAO;KAAE,aAAa;KAAmB,aAAa;IAA2B;IACjF,OAAO;KAAE,aAAa;KAAwB,aAAa;IAA2B;IACtF,OAAO,EAAE,aAAa,yBAAyB;IAC/C,OAAO,EAAE,aAAa,4BAA4B;IAClD,OAAO,EAAE,aAAa,oBAAoB;IAC1C,OAAO,EAAE,aAAa,oBAAoB;IAC1C,OAAO,EAAE,aAAa,sBAAsB;IAC5C,OAAO,EAAE,aAAa,sBAAsB;GAC9C;EACF;CACF;CACA,SAAU,CAAC,UAAU,WAAW,CAAC,CAAW,KAAK,WAAW;EAC1D,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO;CACT,EAAE;AACJ,CAAC"}
1
+ {"version":3,"file":"apiContracts.cjs","names":["Type","defineApiContract","jsonApiResponses"],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nexport const ArtifactsPayloadSchema = Type.Object({\n items: Type.Array(Type.Object({ path: S, name: S, size: N, modifiedAt: N })),\n temporaryRoot: Type.Optional(S),\n error: Type.Optional(S),\n});\nconst scopeQuery = {\n name: 'scope',\n in: 'query' as const,\n required: false,\n schema: Type.Union([Type.Literal('artifacts'), Type.Literal('temporary')]),\n};\nconst query = [\n { name: 'path', in: 'query' as const, required: true, schema: Type.String({ minLength: 1 }) },\n scopeQuery,\n];\nexport const apiContracts = defineApiContract({\n version: 1,\n dynamic: [],\n http: [\n {\n id: 'artifacts.list',\n scope: 'session',\n basePath: 'artifacts',\n path: '/',\n method: 'GET',\n authentication: 'owner',\n description: 'List regular artifacts or temporary files in the current session folder by modification time.',\n parameters: [scopeQuery],\n responses: jsonApiResponses(ArtifactsPayloadSchema),\n },\n {\n id: 'artifacts.preview',\n scope: 'session',\n basePath: 'artifacts',\n path: '/preview',\n method: 'GET',\n authentication: 'owner',\n description: 'Read bounded text preview from the current session artifact folder.',\n parameters: query,\n responses: jsonApiResponses(\n Type.Object({\n path: S,\n content: S,\n mimeType: S,\n unavailable: Type.Optional(Type.Boolean()),\n reason: Type.Optional(S),\n }),\n ),\n },\n {\n id: 'artifacts.content',\n scope: 'session',\n basePath: 'artifacts',\n path: '/content',\n method: 'GET',\n authentication: 'owner',\n description: 'Read bounded artifact bytes, with range and version checks.',\n parameters: [\n ...query,\n { name: 'Range', in: 'header', required: false, schema: S },\n { name: 'If-Match', in: 'header', required: false, schema: S },\n ],\n responses: {\n '200': { description: 'Artifact bytes.', contentType: 'application/octet-stream' },\n '206': { description: 'Artifact byte range.', contentType: 'application/octet-stream' },\n '400': { description: 'Invalid artifact path.' },\n '403': { description: 'Artifact access rejected.' },\n '404': { description: 'Artifact missing.' },\n '412': { description: 'Artifact changed.' },\n '413': { description: 'Artifact too large.' },\n '416': { description: 'Invalid byte range.' },\n },\n },\n ],\n sockets: (['global', 'workspace'] as const).map((scope) => ({\n id: 'artifacts.channel',\n scope,\n service: 'po.hub',\n member: 'artifacts',\n kind: 'channel',\n direction: 'server-to-client',\n description: 'Current-session artifact metadata in the hub frame payload.',\n input: ArtifactsPayloadSchema,\n })),\n});\nexport default apiContracts;\n"],"mappings":";;;;;;;AAGA,MAAM,IAAIA,QAAAA,KAAK,OAAO;AACtB,MAAM,IAAIA,QAAAA,KAAK,OAAO;AACtB,MAAa,yBAAyBA,QAAAA,KAAK,OAAO;CAChD,OAAOA,QAAAA,KAAK,MAAMA,QAAAA,KAAK,OAAO;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,YAAY;CAAE,CAAC,CAAC;CAC3E,eAAeA,QAAAA,KAAK,SAAS,CAAC;CAC9B,OAAOA,QAAAA,KAAK,SAAS,CAAC;AACxB,CAAC;AACD,MAAM,aAAa;CACjB,MAAM;CACN,IAAI;CACJ,UAAU;CACV,QAAQA,QAAAA,KAAK,MAAM,CAACA,QAAAA,KAAK,QAAQ,WAAW,GAAGA,QAAAA,KAAK,QAAQ,WAAW,CAAC,CAAC;AAC3E;AACA,MAAM,QAAQ,CACZ;CAAE,MAAM;CAAQ,IAAI;CAAkB,UAAU;CAAM,QAAQA,QAAAA,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;AAAE,GAC5F,UACF;AACA,MAAa,gBAAA,GAAeC,gCAAAA,kBAAAA,CAAkB;CAC5C,SAAS;CACT,SAAS,CAAC;CACV,MAAM;EACJ;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY,CAAC,UAAU;GACvB,YAAA,GAAWC,gCAAAA,iBAAAA,CAAiB,sBAAsB;EACpD;EACA;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY;GACZ,YAAA,GAAWA,gCAAAA,iBAAAA,CACTF,QAAAA,KAAK,OAAO;IACV,MAAM;IACN,SAAS;IACT,UAAU;IACV,aAAaA,QAAAA,KAAK,SAASA,QAAAA,KAAK,QAAQ,CAAC;IACzC,QAAQA,QAAAA,KAAK,SAAS,CAAC;GACzB,CAAC,CACH;EACF;EACA;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY;IACV,GAAG;IACH;KAAE,MAAM;KAAS,IAAI;KAAU,UAAU;KAAO,QAAQ;IAAE;IAC1D;KAAE,MAAM;KAAY,IAAI;KAAU,UAAU;KAAO,QAAQ;IAAE;GAC/D;GACA,WAAW;IACT,OAAO;KAAE,aAAa;KAAmB,aAAa;IAA2B;IACjF,OAAO;KAAE,aAAa;KAAwB,aAAa;IAA2B;IACtF,OAAO,EAAE,aAAa,yBAAyB;IAC/C,OAAO,EAAE,aAAa,4BAA4B;IAClD,OAAO,EAAE,aAAa,oBAAoB;IAC1C,OAAO,EAAE,aAAa,oBAAoB;IAC1C,OAAO,EAAE,aAAa,sBAAsB;IAC5C,OAAO,EAAE,aAAa,sBAAsB;GAC9C;EACF;CACF;CACA,SAAU,CAAC,UAAU,WAAW,CAAC,CAAW,KAAK,WAAW;EAC1D,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO;CACT,EAAE;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.d.mts","names":[],"sources":["../src/schemas/apiContracts.ts"],"mappings":";;qBAUa"}
1
+ {"version":3,"file":"apiContracts.d.mts","names":[],"sources":["../src/schemas/apiContracts.ts"],"mappings":";;qBAoBa"}
@@ -10,14 +10,21 @@ const ArtifactsPayloadSchema = Type.Object({
10
10
  size: N,
11
11
  modifiedAt: N
12
12
  })),
13
+ temporaryRoot: Type.Optional(S),
13
14
  error: Type.Optional(S)
14
15
  });
16
+ const scopeQuery = {
17
+ name: "scope",
18
+ in: "query",
19
+ required: false,
20
+ schema: Type.Union([Type.Literal("artifacts"), Type.Literal("temporary")])
21
+ };
15
22
  const query = [{
16
23
  name: "path",
17
24
  in: "query",
18
25
  required: true,
19
26
  schema: Type.String({ minLength: 1 })
20
- }];
27
+ }, scopeQuery];
21
28
  const apiContracts = defineApiContract({
22
29
  version: 1,
23
30
  dynamic: [],
@@ -29,7 +36,8 @@ const apiContracts = defineApiContract({
29
36
  path: "/",
30
37
  method: "GET",
31
38
  authentication: "owner",
32
- description: "List regular artifacts in the current session folder by modification time.",
39
+ description: "List regular artifacts or temporary files in the current session folder by modification time.",
40
+ parameters: [scopeQuery],
33
41
  responses: jsonApiResponses(ArtifactsPayloadSchema)
34
42
  },
35
43
  {
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nexport const ArtifactsPayloadSchema = Type.Object({\n items: Type.Array(Type.Object({ path: S, name: S, size: N, modifiedAt: N })),\n error: Type.Optional(S),\n});\nconst query = [{ name: 'path', in: 'query' as const, required: true, schema: Type.String({ minLength: 1 }) }];\nexport const apiContracts = defineApiContract({\n version: 1,\n dynamic: [],\n http: [\n {\n id: 'artifacts.list',\n scope: 'session',\n basePath: 'artifacts',\n path: '/',\n method: 'GET',\n authentication: 'owner',\n description: 'List regular artifacts in the current session folder by modification time.',\n responses: jsonApiResponses(ArtifactsPayloadSchema),\n },\n {\n id: 'artifacts.preview',\n scope: 'session',\n basePath: 'artifacts',\n path: '/preview',\n method: 'GET',\n authentication: 'owner',\n description: 'Read bounded text preview from the current session artifact folder.',\n parameters: query,\n responses: jsonApiResponses(\n Type.Object({\n path: S,\n content: S,\n mimeType: S,\n unavailable: Type.Optional(Type.Boolean()),\n reason: Type.Optional(S),\n }),\n ),\n },\n {\n id: 'artifacts.content',\n scope: 'session',\n basePath: 'artifacts',\n path: '/content',\n method: 'GET',\n authentication: 'owner',\n description: 'Read bounded artifact bytes, with range and version checks.',\n parameters: [\n ...query,\n { name: 'Range', in: 'header', required: false, schema: S },\n { name: 'If-Match', in: 'header', required: false, schema: S },\n ],\n responses: {\n '200': { description: 'Artifact bytes.', contentType: 'application/octet-stream' },\n '206': { description: 'Artifact byte range.', contentType: 'application/octet-stream' },\n '400': { description: 'Invalid artifact path.' },\n '403': { description: 'Artifact access rejected.' },\n '404': { description: 'Artifact missing.' },\n '412': { description: 'Artifact changed.' },\n '413': { description: 'Artifact too large.' },\n '416': { description: 'Invalid byte range.' },\n },\n },\n ],\n sockets: (['global', 'workspace'] as const).map((scope) => ({\n id: 'artifacts.channel',\n scope,\n service: 'po.hub',\n member: 'artifacts',\n kind: 'channel',\n direction: 'server-to-client',\n description: 'Current-session artifact metadata in the hub frame payload.',\n input: ArtifactsPayloadSchema,\n })),\n});\nexport default apiContracts;\n"],"mappings":";;;AAGA,MAAM,IAAI,KAAK,OAAO;AACtB,MAAM,IAAI,KAAK,OAAO;AACtB,MAAa,yBAAyB,KAAK,OAAO;CAChD,OAAO,KAAK,MAAM,KAAK,OAAO;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,YAAY;CAAE,CAAC,CAAC;CAC3E,OAAO,KAAK,SAAS,CAAC;AACxB,CAAC;AACD,MAAM,QAAQ,CAAC;CAAE,MAAM;CAAQ,IAAI;CAAkB,UAAU;CAAM,QAAQ,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;AAAE,CAAC;AAC5G,MAAa,eAAe,kBAAkB;CAC5C,SAAS;CACT,SAAS,CAAC;CACV,MAAM;EACJ;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,WAAW,iBAAiB,sBAAsB;EACpD;EACA;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY;GACZ,WAAW,iBACT,KAAK,OAAO;IACV,MAAM;IACN,SAAS;IACT,UAAU;IACV,aAAa,KAAK,SAAS,KAAK,QAAQ,CAAC;IACzC,QAAQ,KAAK,SAAS,CAAC;GACzB,CAAC,CACH;EACF;EACA;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY;IACV,GAAG;IACH;KAAE,MAAM;KAAS,IAAI;KAAU,UAAU;KAAO,QAAQ;IAAE;IAC1D;KAAE,MAAM;KAAY,IAAI;KAAU,UAAU;KAAO,QAAQ;IAAE;GAC/D;GACA,WAAW;IACT,OAAO;KAAE,aAAa;KAAmB,aAAa;IAA2B;IACjF,OAAO;KAAE,aAAa;KAAwB,aAAa;IAA2B;IACtF,OAAO,EAAE,aAAa,yBAAyB;IAC/C,OAAO,EAAE,aAAa,4BAA4B;IAClD,OAAO,EAAE,aAAa,oBAAoB;IAC1C,OAAO,EAAE,aAAa,oBAAoB;IAC1C,OAAO,EAAE,aAAa,sBAAsB;IAC5C,OAAO,EAAE,aAAa,sBAAsB;GAC9C;EACF;CACF;CACA,SAAU,CAAC,UAAU,WAAW,CAAC,CAAW,KAAK,WAAW;EAC1D,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO;CACT,EAAE;AACJ,CAAC"}
1
+ {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nconst S = Type.String();\nconst N = Type.Number();\nexport const ArtifactsPayloadSchema = Type.Object({\n items: Type.Array(Type.Object({ path: S, name: S, size: N, modifiedAt: N })),\n temporaryRoot: Type.Optional(S),\n error: Type.Optional(S),\n});\nconst scopeQuery = {\n name: 'scope',\n in: 'query' as const,\n required: false,\n schema: Type.Union([Type.Literal('artifacts'), Type.Literal('temporary')]),\n};\nconst query = [\n { name: 'path', in: 'query' as const, required: true, schema: Type.String({ minLength: 1 }) },\n scopeQuery,\n];\nexport const apiContracts = defineApiContract({\n version: 1,\n dynamic: [],\n http: [\n {\n id: 'artifacts.list',\n scope: 'session',\n basePath: 'artifacts',\n path: '/',\n method: 'GET',\n authentication: 'owner',\n description: 'List regular artifacts or temporary files in the current session folder by modification time.',\n parameters: [scopeQuery],\n responses: jsonApiResponses(ArtifactsPayloadSchema),\n },\n {\n id: 'artifacts.preview',\n scope: 'session',\n basePath: 'artifacts',\n path: '/preview',\n method: 'GET',\n authentication: 'owner',\n description: 'Read bounded text preview from the current session artifact folder.',\n parameters: query,\n responses: jsonApiResponses(\n Type.Object({\n path: S,\n content: S,\n mimeType: S,\n unavailable: Type.Optional(Type.Boolean()),\n reason: Type.Optional(S),\n }),\n ),\n },\n {\n id: 'artifacts.content',\n scope: 'session',\n basePath: 'artifacts',\n path: '/content',\n method: 'GET',\n authentication: 'owner',\n description: 'Read bounded artifact bytes, with range and version checks.',\n parameters: [\n ...query,\n { name: 'Range', in: 'header', required: false, schema: S },\n { name: 'If-Match', in: 'header', required: false, schema: S },\n ],\n responses: {\n '200': { description: 'Artifact bytes.', contentType: 'application/octet-stream' },\n '206': { description: 'Artifact byte range.', contentType: 'application/octet-stream' },\n '400': { description: 'Invalid artifact path.' },\n '403': { description: 'Artifact access rejected.' },\n '404': { description: 'Artifact missing.' },\n '412': { description: 'Artifact changed.' },\n '413': { description: 'Artifact too large.' },\n '416': { description: 'Invalid byte range.' },\n },\n },\n ],\n sockets: (['global', 'workspace'] as const).map((scope) => ({\n id: 'artifacts.channel',\n scope,\n service: 'po.hub',\n member: 'artifacts',\n kind: 'channel',\n direction: 'server-to-client',\n description: 'Current-session artifact metadata in the hub frame payload.',\n input: ArtifactsPayloadSchema,\n })),\n});\nexport default apiContracts;\n"],"mappings":";;;AAGA,MAAM,IAAI,KAAK,OAAO;AACtB,MAAM,IAAI,KAAK,OAAO;AACtB,MAAa,yBAAyB,KAAK,OAAO;CAChD,OAAO,KAAK,MAAM,KAAK,OAAO;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,YAAY;CAAE,CAAC,CAAC;CAC3E,eAAe,KAAK,SAAS,CAAC;CAC9B,OAAO,KAAK,SAAS,CAAC;AACxB,CAAC;AACD,MAAM,aAAa;CACjB,MAAM;CACN,IAAI;CACJ,UAAU;CACV,QAAQ,KAAK,MAAM,CAAC,KAAK,QAAQ,WAAW,GAAG,KAAK,QAAQ,WAAW,CAAC,CAAC;AAC3E;AACA,MAAM,QAAQ,CACZ;CAAE,MAAM;CAAQ,IAAI;CAAkB,UAAU;CAAM,QAAQ,KAAK,OAAO,EAAE,WAAW,EAAE,CAAC;AAAE,GAC5F,UACF;AACA,MAAa,eAAe,kBAAkB;CAC5C,SAAS;CACT,SAAS,CAAC;CACV,MAAM;EACJ;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY,CAAC,UAAU;GACvB,WAAW,iBAAiB,sBAAsB;EACpD;EACA;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY;GACZ,WAAW,iBACT,KAAK,OAAO;IACV,MAAM;IACN,SAAS;IACT,UAAU;IACV,aAAa,KAAK,SAAS,KAAK,QAAQ,CAAC;IACzC,QAAQ,KAAK,SAAS,CAAC;GACzB,CAAC,CACH;EACF;EACA;GACE,IAAI;GACJ,OAAO;GACP,UAAU;GACV,MAAM;GACN,QAAQ;GACR,gBAAgB;GAChB,aAAa;GACb,YAAY;IACV,GAAG;IACH;KAAE,MAAM;KAAS,IAAI;KAAU,UAAU;KAAO,QAAQ;IAAE;IAC1D;KAAE,MAAM;KAAY,IAAI;KAAU,UAAU;KAAO,QAAQ;IAAE;GAC/D;GACA,WAAW;IACT,OAAO;KAAE,aAAa;KAAmB,aAAa;IAA2B;IACjF,OAAO;KAAE,aAAa;KAAwB,aAAa;IAA2B;IACtF,OAAO,EAAE,aAAa,yBAAyB;IAC/C,OAAO,EAAE,aAAa,4BAA4B;IAClD,OAAO,EAAE,aAAa,oBAAoB;IAC1C,OAAO,EAAE,aAAa,oBAAoB;IAC1C,OAAO,EAAE,aAAa,sBAAsB;IAC5C,OAAO,EAAE,aAAa,sBAAsB;GAC9C;EACF;CACF;CACA,SAAU,CAAC,UAAU,WAAW,CAAC,CAAW,KAAK,WAAW;EAC1D,IAAI;EACJ;EACA,SAAS;EACT,QAAQ;EACR,MAAM;EACN,WAAW;EACX,aAAa;EACb,OAAO;CACT,EAAE;AACJ,CAAC"}
@@ -20,43 +20,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  enumerable: true
21
21
  }) : target, mod));
22
22
  //#endregion
23
+ const require_artifacts = require("./artifacts-DG_b7DZH.cjs");
24
+ let node_crypto = require("node:crypto");
23
25
  let node_fs = require("node:fs");
24
26
  let node_fs_promises = require("node:fs/promises");
25
27
  node_fs_promises = __toESM(node_fs_promises, 1);
26
28
  let node_path = require("node:path");
27
29
  node_path = __toESM(node_path, 1);
28
30
  let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
29
- //#region src/constants/artifacts.ts
30
- const ARTIFACT_DIRECTORY = "doom-artifacts";
31
- const MAX_PREVIEW_BYTES = 1048576;
32
- const MAX_CONTENT_BYTES = 26214400;
33
- const ARTIFACT_REFRESH_MS = 2e3;
34
- const ARTIFACT_CONTENT_TYPES = {
35
- ".avif": "image/avif",
36
- ".bmp": "image/bmp",
37
- ".gif": "image/gif",
38
- ".jpeg": "image/jpeg",
39
- ".jpg": "image/jpeg",
40
- ".png": "image/png",
41
- ".svg": "image/svg+xml",
42
- ".webp": "image/webp",
43
- ".ico": "image/vnd.microsoft.icon",
44
- ".mp3": "audio/mpeg",
45
- ".wav": "audio/wav",
46
- ".m4a": "audio/mp4",
47
- ".ogg": "audio/ogg",
48
- ".m4v": "video/mp4",
49
- ".mov": "video/quicktime",
50
- ".mp4": "video/mp4",
51
- ".webm": "video/webm",
52
- ".pdf": "application/pdf",
53
- ".md": "text/markdown; charset=utf-8",
54
- ".markdown": "text/markdown; charset=utf-8",
55
- ".txt": "text/plain; charset=utf-8",
56
- ".html": "text/html; charset=utf-8",
57
- ".htm": "text/html; charset=utf-8"
58
- };
59
- //#endregion
60
31
  //#region src/services/artifactFiles/artifactPaths.ts
61
32
  var ArtifactAccessError = class extends Error {
62
33
  status;
@@ -67,10 +38,10 @@ var ArtifactAccessError = class extends Error {
67
38
  };
68
39
  function artifactRoot(sessionId, environment) {
69
40
  if (!/^[a-zA-Z0-9_-]+$/u.test(sessionId)) throw new ArtifactAccessError("Invalid artifact session identity.", 400);
70
- return node_path.default.join((0, _agimon_ai_po_core_piSettings.piAgentDirectory)(environment, environment.HOME), ARTIFACT_DIRECTORY, sessionId);
41
+ return node_path.default.join((0, _agimon_ai_po_core_piSettings.piAgentDirectory)(environment, environment.HOME), require_artifacts.ARTIFACT_DIRECTORY, sessionId);
71
42
  }
72
43
  function artifactMimeType(relativePath) {
73
- return ARTIFACT_CONTENT_TYPES[node_path.default.extname(relativePath).toLowerCase()] ?? "application/octet-stream";
44
+ return require_artifacts.ARTIFACT_CONTENT_TYPES[node_path.default.extname(relativePath).toLowerCase()] ?? "application/octet-stream";
74
45
  }
75
46
  //#endregion
76
47
  //#region src/services/artifactFiles/index.ts
@@ -121,15 +92,25 @@ async function openContained(root, segments) {
121
92
  await directory.close();
122
93
  }
123
94
  }
124
- /** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */
125
- async function openArtifact(root, requested) {
95
+ function artifactSegments(requested) {
126
96
  if (!requested || requested.includes("\0") || requested.includes("\\") || node_path.default.isAbsolute(requested) || requested.split("/").some((part) => part === ".." || part === "." || part === "")) throw new ArtifactAccessError("Invalid artifact path.", 400);
97
+ return requested.split("/");
98
+ }
99
+ function accessError(error, action) {
100
+ if (error instanceof ArtifactAccessError) return error;
101
+ if (codeOf(error) === "ENOENT" || codeOf(error) === "ENOTDIR") return new ArtifactAccessError("The artifact no longer exists.", 404);
102
+ if (codeOf(error) === "EACCES" || codeOf(error) === "EPERM" || codeOf(error) === "ELOOP") return new ArtifactAccessError(`The artifact cannot be ${action}.`, 403);
103
+ return error;
104
+ }
105
+ /** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */
106
+ async function openArtifact(root, requested, workflowVisible) {
107
+ const segments = artifactSegments(requested);
108
+ if (segments[0] === "workflow" && !workflowVisible?.(segments.slice(1).join("/"), "file")) throw new ArtifactAccessError("This workflow file is private.", 403);
127
109
  try {
128
110
  const realRoot = await checkedRoot(root);
129
111
  const candidate = node_path.default.resolve(realRoot, requested);
130
112
  if (!inside(realRoot, candidate)) throw new ArtifactAccessError("The artifact is outside this session folder.", 403);
131
113
  let current = realRoot;
132
- const segments = requested.split("/");
133
114
  for (let index = 0; index < segments.length; index += 1) {
134
115
  current = node_path.default.join(current, segments[index]);
135
116
  const stat = await node_fs_promises.default.lstat(current);
@@ -154,10 +135,7 @@ async function openArtifact(root, requested) {
154
135
  throw error;
155
136
  }
156
137
  } catch (error) {
157
- if (error instanceof ArtifactAccessError) throw error;
158
- if (codeOf(error) === "ENOENT" || codeOf(error) === "ENOTDIR") throw new ArtifactAccessError("The artifact no longer exists.", 404);
159
- if (codeOf(error) === "EACCES" || codeOf(error) === "EPERM" || codeOf(error) === "ELOOP") throw new ArtifactAccessError("The artifact cannot be read.", 403);
160
- throw error;
138
+ throw accessError(error, "read");
161
139
  }
162
140
  }
163
141
  /** Bound allocation and read length even when the file grows after its metadata was read. */
@@ -171,36 +149,120 @@ async function readArtifactBytes(handle, size, offset = 0) {
171
149
  }
172
150
  return bytes.subarray(0, read);
173
151
  }
174
- async function listArtifacts(root) {
152
+ /** Walk to the parent folder without following symlinks, creating missing folders on request. */
153
+ async function containedParent(realRoot, segments, create) {
154
+ let directory = realRoot;
155
+ for (const segment of segments.slice(0, -1)) {
156
+ directory = node_path.default.join(directory, segment);
157
+ if (create) await node_fs_promises.default.mkdir(directory, { mode: 448 }).catch((error) => {
158
+ if (codeOf(error) !== "EEXIST") throw error;
159
+ });
160
+ const stat = await node_fs_promises.default.lstat(directory);
161
+ if (stat.isSymbolicLink() || !stat.isDirectory()) throw new ArtifactAccessError("The artifact folder is not a directory.", 403);
162
+ }
163
+ return directory;
164
+ }
165
+ async function sameText(root, requested, bytes) {
166
+ try {
167
+ const file = await openArtifact(root, requested);
168
+ try {
169
+ if (file.stat.size !== bytes.length) return false;
170
+ return bytes.equals(await readArtifactBytes(file.handle, file.stat.size));
171
+ } finally {
172
+ await file.handle.close();
173
+ }
174
+ } catch (error) {
175
+ if (error instanceof ArtifactAccessError) return false;
176
+ throw error;
177
+ }
178
+ }
179
+ /**
180
+ * Publish text through a same-folder temp file and rename, skipping identical content so mtimes stay stable.
181
+ * ponytail: best-effort same-user guards, not race-resistant. Linux checks ancestors with lstat only;
182
+ * walk with openat-style /proc/self/fd handles like openContained if artifacts cross a trust boundary.
183
+ */
184
+ async function writeArtifactText(root, requested, text) {
185
+ const segments = artifactSegments(requested);
186
+ if (process.platform !== "darwin" && process.platform !== "linux") throw new ArtifactAccessError("Secure artifact writes require macOS or Linux.", 403);
187
+ const bytes = Buffer.from(text, "utf8");
188
+ try {
189
+ await ensureArtifactRoot(root);
190
+ const directory = await containedParent(await checkedRoot(root), segments, true);
191
+ if (await sameText(root, requested, bytes)) return;
192
+ const temp = node_path.default.join(directory, `.${segments.at(-1)}.${(0, node_crypto.randomUUID)()}.tmp`);
193
+ const flags = node_fs.constants.O_WRONLY | node_fs.constants.O_CREAT | node_fs.constants.O_EXCL | (process.platform === "darwin" ? 536870912 : 0);
194
+ const handle = await node_fs_promises.default.open(temp, flags, 384);
195
+ try {
196
+ await handle.writeFile(bytes);
197
+ await handle.close();
198
+ await node_fs_promises.default.rename(temp, node_path.default.join(directory, segments.at(-1)));
199
+ } catch (error) {
200
+ await handle.close().catch(() => void 0);
201
+ await node_fs_promises.default.unlink(temp).catch(() => void 0);
202
+ throw error;
203
+ }
204
+ } catch (error) {
205
+ throw accessError(error, "written");
206
+ }
207
+ }
208
+ /** Remove one file or one empty folder. A missing target is already removed; nothing is deleted recursively. */
209
+ async function removeArtifact(root, requested) {
210
+ const segments = artifactSegments(requested);
211
+ try {
212
+ const target = node_path.default.join(await containedParent(await checkedRoot(root), segments, false), segments.at(-1));
213
+ const stat = await node_fs_promises.default.lstat(target);
214
+ if (stat.isFile()) await node_fs_promises.default.unlink(target);
215
+ else if (!stat.isDirectory()) throw new ArtifactAccessError("The artifact is not a file or folder.", 403);
216
+ else await node_fs_promises.default.rmdir(target).catch((error) => {
217
+ if (codeOf(error) !== "ENOTEMPTY" && codeOf(error) !== "EEXIST") throw error;
218
+ });
219
+ } catch (error) {
220
+ if (codeOf(error) === "ENOENT") return;
221
+ throw accessError(error, "removed");
222
+ }
223
+ }
224
+ /** Discover persisted session roots without admitting symlinked or malformed owners. */
225
+ async function listArtifactSessions(environment) {
226
+ const parent = node_path.default.dirname(artifactRoot("discovery", environment));
227
+ try {
228
+ const stat = await node_fs_promises.default.lstat(parent);
229
+ if (!stat.isDirectory() || stat.isSymbolicLink()) throw new ArtifactAccessError("The artifact storage directory is unavailable.", 403);
230
+ return (await node_fs_promises.default.readdir(parent, { withFileTypes: true })).filter((entry) => entry.isDirectory() && /^[a-zA-Z0-9_-]+$/u.test(entry.name)).map((entry) => entry.name);
231
+ } catch (error) {
232
+ if (codeOf(error) === "ENOENT") return [];
233
+ throw error;
234
+ }
235
+ }
236
+ async function listArtifacts(root, workflowVisible) {
175
237
  const items = [];
176
238
  try {
177
239
  const realRoot = await checkedRoot(root);
178
240
  const visit = async (directory) => {
179
241
  for (const entry of await node_fs_promises.default.readdir(directory, { withFileTypes: true })) {
180
242
  const location = node_path.default.join(directory, entry.name);
243
+ const relativePath = node_path.default.relative(realRoot, location).split(node_path.default.sep).join("/");
244
+ const segments = relativePath.split("/");
245
+ if (segments[0] === "workflow" && !workflowVisible?.(segments.slice(1).join("/"), entry.isDirectory() ? "directory" : "file")) continue;
181
246
  if (entry.isDirectory()) {
182
247
  const stat = await node_fs_promises.default.lstat(location);
183
248
  if (!stat.isDirectory() || stat.isSymbolicLink()) continue;
184
249
  const real = await node_fs_promises.default.realpath(location);
185
250
  if (inside(realRoot, real)) await visit(real);
186
- } else if (entry.isFile()) {
187
- const relativePath = node_path.default.relative(realRoot, location).split(node_path.default.sep).join("/");
251
+ } else if (entry.isFile()) try {
252
+ const file = await openArtifact(root, relativePath, workflowVisible);
188
253
  try {
189
- const file = await openArtifact(root, relativePath);
190
- try {
191
- items.push({
192
- path: relativePath,
193
- name: entry.name,
194
- size: file.stat.size,
195
- modifiedAt: file.stat.mtimeMs
196
- });
197
- } finally {
198
- await file.handle.close();
199
- }
200
- } catch (error) {
201
- if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;
202
- throw error;
254
+ items.push({
255
+ path: relativePath,
256
+ name: entry.name,
257
+ size: file.stat.size,
258
+ modifiedAt: file.stat.mtimeMs
259
+ });
260
+ } finally {
261
+ await file.handle.close();
203
262
  }
263
+ } catch (error) {
264
+ if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;
265
+ throw error;
204
266
  }
205
267
  }
206
268
  };
@@ -216,30 +278,12 @@ async function listArtifacts(root) {
216
278
  }
217
279
  }
218
280
  //#endregion
219
- Object.defineProperty(exports, "ARTIFACT_REFRESH_MS", {
220
- enumerable: true,
221
- get: function() {
222
- return ARTIFACT_REFRESH_MS;
223
- }
224
- });
225
281
  Object.defineProperty(exports, "ArtifactAccessError", {
226
282
  enumerable: true,
227
283
  get: function() {
228
284
  return ArtifactAccessError;
229
285
  }
230
286
  });
231
- Object.defineProperty(exports, "MAX_CONTENT_BYTES", {
232
- enumerable: true,
233
- get: function() {
234
- return MAX_CONTENT_BYTES;
235
- }
236
- });
237
- Object.defineProperty(exports, "MAX_PREVIEW_BYTES", {
238
- enumerable: true,
239
- get: function() {
240
- return MAX_PREVIEW_BYTES;
241
- }
242
- });
243
287
  Object.defineProperty(exports, "__toESM", {
244
288
  enumerable: true,
245
289
  get: function() {
@@ -258,6 +302,12 @@ Object.defineProperty(exports, "ensureArtifactRoot", {
258
302
  return ensureArtifactRoot;
259
303
  }
260
304
  });
305
+ Object.defineProperty(exports, "listArtifactSessions", {
306
+ enumerable: true,
307
+ get: function() {
308
+ return listArtifactSessions;
309
+ }
310
+ });
261
311
  Object.defineProperty(exports, "listArtifacts", {
262
312
  enumerable: true,
263
313
  get: function() {
@@ -276,5 +326,17 @@ Object.defineProperty(exports, "readArtifactBytes", {
276
326
  return readArtifactBytes;
277
327
  }
278
328
  });
329
+ Object.defineProperty(exports, "removeArtifact", {
330
+ enumerable: true,
331
+ get: function() {
332
+ return removeArtifact;
333
+ }
334
+ });
335
+ Object.defineProperty(exports, "writeArtifactText", {
336
+ enumerable: true,
337
+ get: function() {
338
+ return writeArtifactText;
339
+ }
340
+ });
279
341
 
280
- //# sourceMappingURL=artifactFiles-Bo5Mhwq0.cjs.map
342
+ //# sourceMappingURL=artifactFiles-BmBU9Olm.cjs.map