@agimon-ai/po-artifact 0.0.0-alpha.7 → 0.0.0-alpha.71

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/dist/apiContracts.cjs +10 -2
  3. package/dist/apiContracts.cjs.map +1 -1
  4. package/dist/apiContracts.d.mts.map +1 -1
  5. package/dist/apiContracts.mjs +10 -2
  6. package/dist/apiContracts.mjs.map +1 -1
  7. package/dist/{artifactFiles-Cr2X2lhY.cjs → artifactFiles-BeaE-Ixw.cjs} +173 -76
  8. package/dist/artifactFiles-BeaE-Ixw.cjs.map +1 -0
  9. package/dist/artifactFiles-L95-6vSE.mjs +288 -0
  10. package/dist/artifactFiles-L95-6vSE.mjs.map +1 -0
  11. package/dist/artifactFiles.cjs +8 -1
  12. package/dist/artifactFiles.d.mts +17 -1
  13. package/dist/artifactFiles.d.mts.map +1 -1
  14. package/dist/artifactFiles.mjs +3 -1
  15. package/dist/artifacts-DfBCDN6k.mjs +40 -0
  16. package/dist/artifacts-DfBCDN6k.mjs.map +1 -0
  17. package/dist/artifacts-PC2mWroh.cjs +93 -0
  18. package/dist/artifacts-PC2mWroh.cjs.map +1 -0
  19. package/dist/artifacts-sIj4Xaeu.d.mts +32 -0
  20. package/dist/artifacts-sIj4Xaeu.d.mts.map +1 -0
  21. package/dist/extensions/native.mjs +1028 -224
  22. package/dist/extensions/native.mjs.map +1 -1
  23. package/dist/extensions/server.cjs +207 -63
  24. package/dist/extensions/server.cjs.map +1 -1
  25. package/dist/extensions/server.d.mts +2 -2
  26. package/dist/extensions/server.d.mts.map +1 -1
  27. package/dist/extensions/server.mjs +205 -61
  28. package/dist/extensions/server.mjs.map +1 -1
  29. package/dist/extensions/web.mjs +1114 -226
  30. package/dist/extensions/web.mjs.map +1 -1
  31. package/dist/index.cjs +3 -0
  32. package/dist/index.d.mts +8 -19
  33. package/dist/index.d.mts.map +1 -1
  34. package/dist/index.mjs +1 -1
  35. package/package.json +18 -18
  36. package/dist/artifactFiles-8yvD8PX3.mjs +0 -197
  37. package/dist/artifactFiles-8yvD8PX3.mjs.map +0 -1
  38. package/dist/artifactFiles-Cr2X2lhY.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.
@@ -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,15 @@ 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-PC2mWroh.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);
30
+ let node_stream = require("node:stream");
28
31
  let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
29
- //#region src/constants/artifacts.ts
30
- const ARTIFACT_DIRECTORY = "po-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
32
  //#region src/services/artifactFiles/artifactPaths.ts
61
33
  var ArtifactAccessError = class extends Error {
62
34
  status;
@@ -67,13 +39,15 @@ var ArtifactAccessError = class extends Error {
67
39
  };
68
40
  function artifactRoot(sessionId, environment) {
69
41
  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);
42
+ return node_path.default.join((0, _agimon_ai_po_core_piSettings.piAgentDirectory)(environment, environment.HOME), require_artifacts.ARTIFACT_DIRECTORY, sessionId);
71
43
  }
72
44
  function artifactMimeType(relativePath) {
73
- return ARTIFACT_CONTENT_TYPES[node_path.default.extname(relativePath).toLowerCase()] ?? "application/octet-stream";
45
+ return require_artifacts.ARTIFACT_CONTENT_TYPES[node_path.default.extname(relativePath).toLowerCase()] ?? "application/octet-stream";
74
46
  }
75
47
  //#endregion
76
48
  //#region src/services/artifactFiles/index.ts
49
+ /** A copy still being written: promoters write `.<name>.tmp` and rename it into place. */
50
+ const IN_FLIGHT_COPY = /^\..+\.tmp$/u;
77
51
  function inside(root, candidate) {
78
52
  const relative = node_path.default.relative(root, candidate);
79
53
  return relative !== ".." && !relative.startsWith(`..${node_path.default.sep}`) && !node_path.default.isAbsolute(relative);
@@ -121,15 +95,25 @@ async function openContained(root, segments) {
121
95
  await directory.close();
122
96
  }
123
97
  }
124
- /** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */
125
- async function openArtifact(root, requested) {
98
+ function artifactSegments(requested) {
126
99
  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);
100
+ return requested.split("/");
101
+ }
102
+ function accessError(error, action) {
103
+ if (error instanceof ArtifactAccessError) return error;
104
+ if (codeOf(error) === "ENOENT" || codeOf(error) === "ENOTDIR") return new ArtifactAccessError("The artifact no longer exists.", 404);
105
+ if (codeOf(error) === "EACCES" || codeOf(error) === "EPERM" || codeOf(error) === "ELOOP") return new ArtifactAccessError(`The artifact cannot be ${action}.`, 403);
106
+ return error;
107
+ }
108
+ /** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */
109
+ async function openArtifact(root, requested, workflowVisible) {
110
+ const segments = artifactSegments(requested);
111
+ if (segments[0] === "workflow" && !workflowVisible?.(segments.slice(1).join("/"), "file")) throw new ArtifactAccessError("This workflow file is private.", 403);
127
112
  try {
128
113
  const realRoot = await checkedRoot(root);
129
114
  const candidate = node_path.default.resolve(realRoot, requested);
130
115
  if (!inside(realRoot, candidate)) throw new ArtifactAccessError("The artifact is outside this session folder.", 403);
131
116
  let current = realRoot;
132
- const segments = requested.split("/");
133
117
  for (let index = 0; index < segments.length; index += 1) {
134
118
  current = node_path.default.join(current, segments[index]);
135
119
  const stat = await node_fs_promises.default.lstat(current);
@@ -154,10 +138,7 @@ async function openArtifact(root, requested) {
154
138
  throw error;
155
139
  }
156
140
  } 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;
141
+ throw accessError(error, "read");
161
142
  }
162
143
  }
163
144
  /** Bound allocation and read length even when the file grows after its metadata was read. */
@@ -171,43 +152,131 @@ async function readArtifactBytes(handle, size, offset = 0) {
171
152
  }
172
153
  return bytes.subarray(0, read);
173
154
  }
174
- async function listArtifacts(root) {
155
+ /** Walk to the parent folder without following symlinks, creating missing folders on request. */
156
+ async function containedParent(realRoot, segments, create) {
157
+ let directory = realRoot;
158
+ for (const segment of segments.slice(0, -1)) {
159
+ directory = node_path.default.join(directory, segment);
160
+ if (create) await node_fs_promises.default.mkdir(directory, { mode: 448 }).catch((error) => {
161
+ if (codeOf(error) !== "EEXIST") throw error;
162
+ });
163
+ const stat = await node_fs_promises.default.lstat(directory);
164
+ if (stat.isSymbolicLink() || !stat.isDirectory()) throw new ArtifactAccessError("The artifact folder is not a directory.", 403);
165
+ }
166
+ return directory;
167
+ }
168
+ async function sameText(root, requested, bytes) {
169
+ try {
170
+ const file = await openArtifact(root, requested);
171
+ try {
172
+ if (file.stat.size !== bytes.length) return false;
173
+ return bytes.equals(await readArtifactBytes(file.handle, file.stat.size));
174
+ } finally {
175
+ await file.handle.close();
176
+ }
177
+ } catch (error) {
178
+ if (error instanceof ArtifactAccessError) return false;
179
+ throw error;
180
+ }
181
+ }
182
+ /**
183
+ * Publish text through a same-folder temp file and rename, skipping identical content so mtimes stay stable.
184
+ * ponytail: best-effort same-user guards, not race-resistant. Linux checks ancestors with lstat only;
185
+ * walk with openat-style /proc/self/fd handles like openContained if artifacts cross a trust boundary.
186
+ */
187
+ async function writeArtifactText(root, requested, text) {
188
+ const segments = artifactSegments(requested);
189
+ if (process.platform !== "darwin" && process.platform !== "linux") throw new ArtifactAccessError("Secure artifact writes require macOS or Linux.", 403);
190
+ const bytes = Buffer.from(text, "utf8");
191
+ try {
192
+ await ensureArtifactRoot(root);
193
+ const directory = await containedParent(await checkedRoot(root), segments, true);
194
+ if (await sameText(root, requested, bytes)) return;
195
+ const temp = node_path.default.join(directory, `.${segments.at(-1)}.${(0, node_crypto.randomUUID)()}.tmp`);
196
+ const flags = node_fs.constants.O_WRONLY | node_fs.constants.O_CREAT | node_fs.constants.O_EXCL | (process.platform === "darwin" ? 536870912 : 0);
197
+ const handle = await node_fs_promises.default.open(temp, flags, 384);
198
+ try {
199
+ await handle.writeFile(bytes);
200
+ await handle.close();
201
+ await node_fs_promises.default.rename(temp, node_path.default.join(directory, segments.at(-1)));
202
+ } catch (error) {
203
+ await handle.close().catch(() => void 0);
204
+ await node_fs_promises.default.unlink(temp).catch(() => void 0);
205
+ throw error;
206
+ }
207
+ } catch (error) {
208
+ throw accessError(error, "written");
209
+ }
210
+ }
211
+ /** Remove one file or one empty folder. A missing target is already removed; nothing is deleted recursively. */
212
+ async function removeArtifact(root, requested) {
213
+ const segments = artifactSegments(requested);
214
+ try {
215
+ const target = node_path.default.join(await containedParent(await checkedRoot(root), segments, false), segments.at(-1));
216
+ const stat = await node_fs_promises.default.lstat(target);
217
+ if (stat.isFile()) await node_fs_promises.default.unlink(target);
218
+ else if (!stat.isDirectory()) throw new ArtifactAccessError("The artifact is not a file or folder.", 403);
219
+ else await node_fs_promises.default.rmdir(target).catch((error) => {
220
+ if (codeOf(error) !== "ENOTEMPTY" && codeOf(error) !== "EEXIST") throw error;
221
+ });
222
+ } catch (error) {
223
+ if (codeOf(error) === "ENOENT") return;
224
+ throw accessError(error, "removed");
225
+ }
226
+ }
227
+ /** Discover persisted session roots without admitting symlinked or malformed owners. */
228
+ async function listArtifactSessions(environment) {
229
+ const parent = node_path.default.dirname(artifactRoot("discovery", environment));
230
+ try {
231
+ const stat = await node_fs_promises.default.lstat(parent);
232
+ if (!stat.isDirectory() || stat.isSymbolicLink()) throw new ArtifactAccessError("The artifact storage directory is unavailable.", 403);
233
+ 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);
234
+ } catch (error) {
235
+ if (codeOf(error) === "ENOENT") return [];
236
+ throw error;
237
+ }
238
+ }
239
+ async function listArtifacts(root, workflowVisible, signal) {
175
240
  const items = [];
176
241
  try {
242
+ signal?.throwIfAborted();
177
243
  const realRoot = await checkedRoot(root);
178
244
  const visit = async (directory) => {
179
245
  for (const entry of await node_fs_promises.default.readdir(directory, { withFileTypes: true })) {
246
+ signal?.throwIfAborted();
180
247
  const location = node_path.default.join(directory, entry.name);
248
+ const relativePath = node_path.default.relative(realRoot, location).split(node_path.default.sep).join("/");
249
+ const segments = relativePath.split("/");
250
+ if (segments[0] === "workflow" && !workflowVisible?.(segments.slice(1).join("/"), entry.isDirectory() ? "directory" : "file")) continue;
181
251
  if (entry.isDirectory()) {
182
252
  const stat = await node_fs_promises.default.lstat(location);
183
253
  if (!stat.isDirectory() || stat.isSymbolicLink()) continue;
184
254
  const real = await node_fs_promises.default.realpath(location);
185
255
  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("/");
256
+ } else if (entry.isFile() && !IN_FLIGHT_COPY.test(entry.name)) try {
257
+ const file = await openArtifact(root, relativePath, workflowVisible);
188
258
  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;
259
+ items.push({
260
+ path: relativePath,
261
+ name: entry.name,
262
+ size: file.stat.size,
263
+ modifiedAt: file.stat.mtimeMs
264
+ });
265
+ } finally {
266
+ await file.handle.close();
203
267
  }
268
+ } catch (error) {
269
+ if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;
270
+ throw error;
204
271
  }
205
272
  }
206
273
  };
207
274
  await visit(realRoot);
275
+ signal?.throwIfAborted();
208
276
  items.sort((left, right) => right.modifiedAt - left.modifiedAt || (left.path < right.path ? -1 : left.path > right.path ? 1 : 0));
209
277
  return { items };
210
278
  } catch (error) {
279
+ signal?.throwIfAborted();
211
280
  if (codeOf(error) === "ENOENT") return { items: [] };
212
281
  return {
213
282
  items: [],
@@ -215,31 +284,35 @@ async function listArtifacts(root) {
215
284
  };
216
285
  }
217
286
  }
287
+ /** Guarded, bounded download opener for trusted server-side registered artifacts. */
288
+ async function openArtifactDownload(root, requested) {
289
+ const { handle, stat } = await openArtifact(root, requested);
290
+ return {
291
+ identity: [
292
+ stat.dev,
293
+ stat.ino,
294
+ stat.size,
295
+ stat.mtimeMs,
296
+ stat.ctimeMs
297
+ ].join(":"),
298
+ size: stat.size,
299
+ close: () => handle.close(),
300
+ stream: () => stat.size === 0 ? new ReadableStream({ async start(controller) {
301
+ await handle.close();
302
+ controller.close();
303
+ } }) : node_stream.Readable.toWeb(handle.createReadStream({
304
+ start: 0,
305
+ end: stat.size - 1
306
+ }))
307
+ };
308
+ }
218
309
  //#endregion
219
- Object.defineProperty(exports, "ARTIFACT_REFRESH_MS", {
220
- enumerable: true,
221
- get: function() {
222
- return ARTIFACT_REFRESH_MS;
223
- }
224
- });
225
310
  Object.defineProperty(exports, "ArtifactAccessError", {
226
311
  enumerable: true,
227
312
  get: function() {
228
313
  return ArtifactAccessError;
229
314
  }
230
315
  });
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
316
  Object.defineProperty(exports, "__toESM", {
244
317
  enumerable: true,
245
318
  get: function() {
@@ -258,6 +331,12 @@ Object.defineProperty(exports, "ensureArtifactRoot", {
258
331
  return ensureArtifactRoot;
259
332
  }
260
333
  });
334
+ Object.defineProperty(exports, "listArtifactSessions", {
335
+ enumerable: true,
336
+ get: function() {
337
+ return listArtifactSessions;
338
+ }
339
+ });
261
340
  Object.defineProperty(exports, "listArtifacts", {
262
341
  enumerable: true,
263
342
  get: function() {
@@ -270,11 +349,29 @@ Object.defineProperty(exports, "openArtifact", {
270
349
  return openArtifact;
271
350
  }
272
351
  });
352
+ Object.defineProperty(exports, "openArtifactDownload", {
353
+ enumerable: true,
354
+ get: function() {
355
+ return openArtifactDownload;
356
+ }
357
+ });
273
358
  Object.defineProperty(exports, "readArtifactBytes", {
274
359
  enumerable: true,
275
360
  get: function() {
276
361
  return readArtifactBytes;
277
362
  }
278
363
  });
364
+ Object.defineProperty(exports, "removeArtifact", {
365
+ enumerable: true,
366
+ get: function() {
367
+ return removeArtifact;
368
+ }
369
+ });
370
+ Object.defineProperty(exports, "writeArtifactText", {
371
+ enumerable: true,
372
+ get: function() {
373
+ return writeArtifactText;
374
+ }
375
+ });
279
376
 
280
- //# sourceMappingURL=artifactFiles-Cr2X2lhY.cjs.map
377
+ //# sourceMappingURL=artifactFiles-BeaE-Ixw.cjs.map