@agimon-ai/po-artifact 0.0.0-alpha.4 → 0.0.0-alpha.41

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-BJL1H1QG.mjs +261 -0
  8. package/dist/artifactFiles-BJL1H1QG.mjs.map +1 -0
  9. package/dist/{artifactFiles-Cr2X2lhY.cjs → artifactFiles-C8dqPVra.cjs} +140 -76
  10. package/dist/artifactFiles-C8dqPVra.cjs.map +1 -0
  11. package/dist/artifactFiles.cjs +7 -1
  12. package/dist/artifactFiles.d.mts +14 -1
  13. package/dist/artifactFiles.d.mts.map +1 -1
  14. package/dist/artifactFiles.mjs +3 -1
  15. package/dist/artifacts-Bhobz1nK.mjs +38 -0
  16. package/dist/artifacts-Bhobz1nK.mjs.map +1 -0
  17. package/dist/artifacts-DG_b7DZH.cjs +85 -0
  18. package/dist/artifacts-DG_b7DZH.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 +875 -122
  22. package/dist/extensions/native.mjs.map +1 -1
  23. package/dist/extensions/server.cjs +179 -46
  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 +177 -44
  28. package/dist/extensions/server.mjs.map +1 -1
  29. package/dist/extensions/web.mjs +1077 -218
  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 +17 -17
  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 h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,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,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B;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"}
@@ -0,0 +1,261 @@
1
+ import { n as ARTIFACT_CONTENT_TYPES, r as ARTIFACT_DIRECTORY } from "./artifacts-Bhobz1nK.mjs";
2
+ import { randomUUID } from "node:crypto";
3
+ import { constants } from "node:fs";
4
+ import fs from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { piAgentDirectory } from "@agimon-ai/po-core/piSettings";
7
+ //#region src/services/artifactFiles/artifactPaths.ts
8
+ var ArtifactAccessError = class extends Error {
9
+ status;
10
+ constructor(message, status) {
11
+ super(message);
12
+ this.status = status;
13
+ }
14
+ };
15
+ function artifactRoot(sessionId, environment) {
16
+ if (!/^[a-zA-Z0-9_-]+$/u.test(sessionId)) throw new ArtifactAccessError("Invalid artifact session identity.", 400);
17
+ return path.join(piAgentDirectory(environment, environment.HOME), ARTIFACT_DIRECTORY, sessionId);
18
+ }
19
+ function artifactMimeType(relativePath) {
20
+ return ARTIFACT_CONTENT_TYPES[path.extname(relativePath).toLowerCase()] ?? "application/octet-stream";
21
+ }
22
+ //#endregion
23
+ //#region src/services/artifactFiles/index.ts
24
+ /** A copy still being written: promoters write `.<name>.tmp` and rename it into place. */
25
+ const IN_FLIGHT_COPY = /^\..+\.tmp$/u;
26
+ function inside(root, candidate) {
27
+ const relative = path.relative(root, candidate);
28
+ return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
29
+ }
30
+ function codeOf(error) {
31
+ return error instanceof Error && "code" in error ? String(error.code) : void 0;
32
+ }
33
+ /** The owned directories must not redirect artifact access through a symlink. */
34
+ async function checkedRoot(root) {
35
+ const base = path.dirname(root);
36
+ for (const directory of [base, root]) {
37
+ const stat = await fs.lstat(directory);
38
+ if (!stat.isDirectory() || stat.isSymbolicLink()) throw new ArtifactAccessError("The artifact folder is unavailable.", 403);
39
+ }
40
+ const realBase = await fs.realpath(base);
41
+ const realRoot = await fs.realpath(root);
42
+ if (!inside(realBase, realRoot)) throw new ArtifactAccessError("The artifact folder is outside its storage directory.", 403);
43
+ return realRoot;
44
+ }
45
+ async function ensureArtifactRoot(root) {
46
+ await fs.mkdir(path.dirname(root), {
47
+ recursive: true,
48
+ mode: 448
49
+ });
50
+ await fs.mkdir(root, {
51
+ recursive: true,
52
+ mode: 448
53
+ });
54
+ await checkedRoot(root);
55
+ }
56
+ /** Open without following mutable ancestors. Node exposes no portable openat API. */
57
+ async function openContained(root, segments) {
58
+ if (process.platform === "darwin") return fs.open(path.join(root, ...segments), constants.O_RDONLY | constants.O_NONBLOCK | 536870912);
59
+ if (process.platform !== "linux") throw new ArtifactAccessError("Secure artifact reads require macOS or Linux.", 403);
60
+ const flags = constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW;
61
+ let directory = await fs.open(path.dirname(root), flags);
62
+ try {
63
+ for (const segment of [path.basename(root), ...segments.slice(0, -1)]) {
64
+ const child = await fs.open(`/proc/self/fd/${directory.fd}/${segment}`, flags);
65
+ await directory.close();
66
+ directory = child;
67
+ }
68
+ return await fs.open(`/proc/self/fd/${directory.fd}/${segments.at(-1)}`, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
69
+ } finally {
70
+ await directory.close();
71
+ }
72
+ }
73
+ function artifactSegments(requested) {
74
+ if (!requested || requested.includes("\0") || requested.includes("\\") || path.isAbsolute(requested) || requested.split("/").some((part) => part === ".." || part === "." || part === "")) throw new ArtifactAccessError("Invalid artifact path.", 400);
75
+ return requested.split("/");
76
+ }
77
+ function accessError(error, action) {
78
+ if (error instanceof ArtifactAccessError) return error;
79
+ if (codeOf(error) === "ENOENT" || codeOf(error) === "ENOTDIR") return new ArtifactAccessError("The artifact no longer exists.", 404);
80
+ if (codeOf(error) === "EACCES" || codeOf(error) === "EPERM" || codeOf(error) === "ELOOP") return new ArtifactAccessError(`The artifact cannot be ${action}.`, 403);
81
+ return error;
82
+ }
83
+ /** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */
84
+ async function openArtifact(root, requested, workflowVisible) {
85
+ const segments = artifactSegments(requested);
86
+ if (segments[0] === "workflow" && !workflowVisible?.(segments.slice(1).join("/"), "file")) throw new ArtifactAccessError("This workflow file is private.", 403);
87
+ try {
88
+ const realRoot = await checkedRoot(root);
89
+ const candidate = path.resolve(realRoot, requested);
90
+ if (!inside(realRoot, candidate)) throw new ArtifactAccessError("The artifact is outside this session folder.", 403);
91
+ let current = realRoot;
92
+ for (let index = 0; index < segments.length; index += 1) {
93
+ current = path.join(current, segments[index]);
94
+ const stat = await fs.lstat(current);
95
+ if (stat.isSymbolicLink()) throw new ArtifactAccessError("Artifact symlinks cannot be read.", 403);
96
+ if (index < segments.length - 1 ? !stat.isDirectory() : !stat.isFile()) throw new ArtifactAccessError("The artifact is not a regular file.", 404);
97
+ }
98
+ const real = await fs.realpath(candidate);
99
+ if (!inside(realRoot, real)) throw new ArtifactAccessError("The artifact is outside this session folder.", 403);
100
+ const expected = await fs.lstat(real);
101
+ const handle = await openContained(realRoot, segments);
102
+ try {
103
+ const stat = await handle.stat();
104
+ if (!stat.isFile() || stat.dev !== expected.dev || stat.ino !== expected.ino) throw new ArtifactAccessError("The artifact changed while it was opened. Try again.", 403);
105
+ return {
106
+ handle,
107
+ stat,
108
+ path: requested,
109
+ mimeType: artifactMimeType(requested)
110
+ };
111
+ } catch (error) {
112
+ await handle.close();
113
+ throw error;
114
+ }
115
+ } catch (error) {
116
+ throw accessError(error, "read");
117
+ }
118
+ }
119
+ /** Bound allocation and read length even when the file grows after its metadata was read. */
120
+ async function readArtifactBytes(handle, size, offset = 0) {
121
+ const bytes = new Uint8Array(size);
122
+ let read = 0;
123
+ while (read < size) {
124
+ const result = await handle.read(bytes, read, size - read, offset + read);
125
+ if (result.bytesRead === 0) break;
126
+ read += result.bytesRead;
127
+ }
128
+ return bytes.subarray(0, read);
129
+ }
130
+ /** Walk to the parent folder without following symlinks, creating missing folders on request. */
131
+ async function containedParent(realRoot, segments, create) {
132
+ let directory = realRoot;
133
+ for (const segment of segments.slice(0, -1)) {
134
+ directory = path.join(directory, segment);
135
+ if (create) await fs.mkdir(directory, { mode: 448 }).catch((error) => {
136
+ if (codeOf(error) !== "EEXIST") throw error;
137
+ });
138
+ const stat = await fs.lstat(directory);
139
+ if (stat.isSymbolicLink() || !stat.isDirectory()) throw new ArtifactAccessError("The artifact folder is not a directory.", 403);
140
+ }
141
+ return directory;
142
+ }
143
+ async function sameText(root, requested, bytes) {
144
+ try {
145
+ const file = await openArtifact(root, requested);
146
+ try {
147
+ if (file.stat.size !== bytes.length) return false;
148
+ return bytes.equals(await readArtifactBytes(file.handle, file.stat.size));
149
+ } finally {
150
+ await file.handle.close();
151
+ }
152
+ } catch (error) {
153
+ if (error instanceof ArtifactAccessError) return false;
154
+ throw error;
155
+ }
156
+ }
157
+ /**
158
+ * Publish text through a same-folder temp file and rename, skipping identical content so mtimes stay stable.
159
+ * ponytail: best-effort same-user guards, not race-resistant. Linux checks ancestors with lstat only;
160
+ * walk with openat-style /proc/self/fd handles like openContained if artifacts cross a trust boundary.
161
+ */
162
+ async function writeArtifactText(root, requested, text) {
163
+ const segments = artifactSegments(requested);
164
+ if (process.platform !== "darwin" && process.platform !== "linux") throw new ArtifactAccessError("Secure artifact writes require macOS or Linux.", 403);
165
+ const bytes = Buffer.from(text, "utf8");
166
+ try {
167
+ await ensureArtifactRoot(root);
168
+ const directory = await containedParent(await checkedRoot(root), segments, true);
169
+ if (await sameText(root, requested, bytes)) return;
170
+ const temp = path.join(directory, `.${segments.at(-1)}.${randomUUID()}.tmp`);
171
+ const flags = constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (process.platform === "darwin" ? 536870912 : 0);
172
+ const handle = await fs.open(temp, flags, 384);
173
+ try {
174
+ await handle.writeFile(bytes);
175
+ await handle.close();
176
+ await fs.rename(temp, path.join(directory, segments.at(-1)));
177
+ } catch (error) {
178
+ await handle.close().catch(() => void 0);
179
+ await fs.unlink(temp).catch(() => void 0);
180
+ throw error;
181
+ }
182
+ } catch (error) {
183
+ throw accessError(error, "written");
184
+ }
185
+ }
186
+ /** Remove one file or one empty folder. A missing target is already removed; nothing is deleted recursively. */
187
+ async function removeArtifact(root, requested) {
188
+ const segments = artifactSegments(requested);
189
+ try {
190
+ const target = path.join(await containedParent(await checkedRoot(root), segments, false), segments.at(-1));
191
+ const stat = await fs.lstat(target);
192
+ if (stat.isFile()) await fs.unlink(target);
193
+ else if (!stat.isDirectory()) throw new ArtifactAccessError("The artifact is not a file or folder.", 403);
194
+ else await fs.rmdir(target).catch((error) => {
195
+ if (codeOf(error) !== "ENOTEMPTY" && codeOf(error) !== "EEXIST") throw error;
196
+ });
197
+ } catch (error) {
198
+ if (codeOf(error) === "ENOENT") return;
199
+ throw accessError(error, "removed");
200
+ }
201
+ }
202
+ /** Discover persisted session roots without admitting symlinked or malformed owners. */
203
+ async function listArtifactSessions(environment) {
204
+ const parent = path.dirname(artifactRoot("discovery", environment));
205
+ try {
206
+ const stat = await fs.lstat(parent);
207
+ if (!stat.isDirectory() || stat.isSymbolicLink()) throw new ArtifactAccessError("The artifact storage directory is unavailable.", 403);
208
+ return (await fs.readdir(parent, { withFileTypes: true })).filter((entry) => entry.isDirectory() && /^[a-zA-Z0-9_-]+$/u.test(entry.name)).map((entry) => entry.name);
209
+ } catch (error) {
210
+ if (codeOf(error) === "ENOENT") return [];
211
+ throw error;
212
+ }
213
+ }
214
+ async function listArtifacts(root, workflowVisible) {
215
+ const items = [];
216
+ try {
217
+ const realRoot = await checkedRoot(root);
218
+ const visit = async (directory) => {
219
+ for (const entry of await fs.readdir(directory, { withFileTypes: true })) {
220
+ const location = path.join(directory, entry.name);
221
+ const relativePath = path.relative(realRoot, location).split(path.sep).join("/");
222
+ const segments = relativePath.split("/");
223
+ if (segments[0] === "workflow" && !workflowVisible?.(segments.slice(1).join("/"), entry.isDirectory() ? "directory" : "file")) continue;
224
+ if (entry.isDirectory()) {
225
+ const stat = await fs.lstat(location);
226
+ if (!stat.isDirectory() || stat.isSymbolicLink()) continue;
227
+ const real = await fs.realpath(location);
228
+ if (inside(realRoot, real)) await visit(real);
229
+ } else if (entry.isFile() && !IN_FLIGHT_COPY.test(entry.name)) try {
230
+ const file = await openArtifact(root, relativePath, workflowVisible);
231
+ try {
232
+ items.push({
233
+ path: relativePath,
234
+ name: entry.name,
235
+ size: file.stat.size,
236
+ modifiedAt: file.stat.mtimeMs
237
+ });
238
+ } finally {
239
+ await file.handle.close();
240
+ }
241
+ } catch (error) {
242
+ if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;
243
+ throw error;
244
+ }
245
+ }
246
+ };
247
+ await visit(realRoot);
248
+ items.sort((left, right) => right.modifiedAt - left.modifiedAt || (left.path < right.path ? -1 : left.path > right.path ? 1 : 0));
249
+ return { items };
250
+ } catch (error) {
251
+ if (codeOf(error) === "ENOENT") return { items: [] };
252
+ return {
253
+ items: [],
254
+ error: error instanceof Error ? error.message : "The artifact folder could not be read."
255
+ };
256
+ }
257
+ }
258
+ //#endregion
259
+ export { readArtifactBytes as a, ArtifactAccessError as c, openArtifact as i, artifactRoot as l, listArtifactSessions as n, removeArtifact as o, listArtifacts as r, writeArtifactText as s, ensureArtifactRoot as t };
260
+
261
+ //# sourceMappingURL=artifactFiles-BJL1H1QG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifactFiles-BJL1H1QG.mjs","names":[],"sources":["../src/services/artifactFiles/artifactPaths.ts","../src/services/artifactFiles/index.ts"],"sourcesContent":["import path from 'node:path';\n\nimport { piAgentDirectory } from '@agimon-ai/po-core/piSettings';\n\nimport { ARTIFACT_CONTENT_TYPES, ARTIFACT_DIRECTORY } from '../../constants/artifacts';\n\nexport class ArtifactAccessError extends Error {\n constructor(\n message: string,\n readonly status: 400 | 403 | 404 | 413,\n ) {\n super(message);\n }\n}\n\nexport function artifactRoot(sessionId: string, environment: Readonly<Record<string, string | undefined>>): string {\n if (!/^[a-zA-Z0-9_-]+$/u.test(sessionId)) throw new ArtifactAccessError('Invalid artifact session identity.', 400);\n return path.join(piAgentDirectory(environment, environment.HOME), ARTIFACT_DIRECTORY, sessionId);\n}\n\nexport function artifactMimeType(relativePath: string): string {\n return ARTIFACT_CONTENT_TYPES[path.extname(relativePath).toLowerCase()] ?? 'application/octet-stream';\n}\n","import { randomUUID } from 'node:crypto';\nimport { constants } from 'node:fs';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { WORKFLOW_ARTIFACT_DIRECTORY } from '../../constants/artifacts';\nimport type { ArtifactItem, ArtifactSnapshot, ArtifactWorkflowVisibility } from '../../types/artifacts';\nimport { ArtifactAccessError, artifactMimeType, artifactRoot } from './artifactPaths';\n\nexport { ArtifactAccessError, artifactMimeType, artifactRoot } from './artifactPaths';\n\n/** A copy still being written: promoters write `.<name>.tmp` and rename it into place. */\nconst IN_FLIGHT_COPY = /^\\..+\\.tmp$/u;\nfunction inside(root: string, candidate: string): boolean {\n const relative = path.relative(root, candidate);\n return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);\n}\n\nfunction codeOf(error: unknown): string | undefined {\n return error instanceof Error && 'code' in error ? String(error.code) : undefined;\n}\n\n/** The owned directories must not redirect artifact access through a symlink. */\nasync function checkedRoot(root: string): Promise<string> {\n const base = path.dirname(root);\n for (const directory of [base, root]) {\n const stat = await fs.lstat(directory);\n if (!stat.isDirectory() || stat.isSymbolicLink())\n throw new ArtifactAccessError('The artifact folder is unavailable.', 403);\n }\n const realBase = await fs.realpath(base);\n const realRoot = await fs.realpath(root);\n if (!inside(realBase, realRoot))\n throw new ArtifactAccessError('The artifact folder is outside its storage directory.', 403);\n return realRoot;\n}\n\nexport async function ensureArtifactRoot(root: string): Promise<void> {\n await fs.mkdir(path.dirname(root), { recursive: true, mode: 0o700 });\n await fs.mkdir(root, { recursive: true, mode: 0o700 });\n await checkedRoot(root);\n}\n\n/** Open without following mutable ancestors. Node exposes no portable openat API. */\nasync function openContained(root: string, segments: string[]): Promise<fs.FileHandle> {\n if (process.platform === 'darwin') {\n // Darwin O_NOFOLLOW_ANY checks every component atomically. Do not combine it with O_NOFOLLOW.\n return fs.open(path.join(root, ...segments), constants.O_RDONLY | constants.O_NONBLOCK | 0x20000000);\n }\n if (process.platform !== 'linux') throw new ArtifactAccessError('Secure artifact reads require macOS or Linux.', 403);\n const flags = constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW;\n let directory = await fs.open(path.dirname(root), flags);\n try {\n for (const segment of [path.basename(root), ...segments.slice(0, -1)]) {\n const child = await fs.open(`/proc/self/fd/${directory.fd}/${segment}`, flags);\n await directory.close();\n directory = child;\n }\n return await fs.open(\n `/proc/self/fd/${directory.fd}/${segments.at(-1)!}`,\n constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK,\n );\n } finally {\n await directory.close();\n }\n}\n\nfunction artifactSegments(requested: string | undefined): string[] {\n if (\n !requested ||\n requested.includes('\\0') ||\n requested.includes('\\\\') ||\n path.isAbsolute(requested) ||\n requested.split('/').some((part) => part === '..' || part === '.' || part === '')\n )\n throw new ArtifactAccessError('Invalid artifact path.', 400);\n return requested.split('/');\n}\n\nfunction accessError(error: unknown, action: string): unknown {\n if (error instanceof ArtifactAccessError) return error;\n if (codeOf(error) === 'ENOENT' || codeOf(error) === 'ENOTDIR')\n return new ArtifactAccessError('The artifact no longer exists.', 404);\n if (codeOf(error) === 'EACCES' || codeOf(error) === 'EPERM' || codeOf(error) === 'ELOOP')\n return new ArtifactAccessError(`The artifact cannot be ${action}.`, 403);\n return error;\n}\n\n/** One guarded open shared by metadata, text and byte reads. The caller closes the handle. */\nexport async function openArtifact(\n root: string,\n requested: string | undefined,\n workflowVisible?: ArtifactWorkflowVisibility,\n) {\n const segments = artifactSegments(requested);\n if (segments[0] === WORKFLOW_ARTIFACT_DIRECTORY && !workflowVisible?.(segments.slice(1).join('/'), 'file'))\n throw new ArtifactAccessError('This workflow file is private.', 403);\n try {\n const realRoot = await checkedRoot(root);\n const candidate = path.resolve(realRoot, requested!);\n if (!inside(realRoot, candidate))\n throw new ArtifactAccessError('The artifact is outside this session folder.', 403);\n let current = realRoot;\n for (let index = 0; index < segments.length; index += 1) {\n current = path.join(current, segments[index]!);\n const stat = await fs.lstat(current);\n if (stat.isSymbolicLink()) throw new ArtifactAccessError('Artifact symlinks cannot be read.', 403);\n if (index < segments.length - 1 ? !stat.isDirectory() : !stat.isFile())\n throw new ArtifactAccessError('The artifact is not a regular file.', 404);\n }\n const real = await fs.realpath(candidate);\n if (!inside(realRoot, real)) throw new ArtifactAccessError('The artifact is outside this session folder.', 403);\n const expected = await fs.lstat(real);\n const handle = await openContained(realRoot, segments);\n try {\n const stat = await handle.stat();\n if (!stat.isFile() || stat.dev !== expected.dev || stat.ino !== expected.ino)\n throw new ArtifactAccessError('The artifact changed while it was opened. Try again.', 403);\n return { handle, stat, path: requested!, mimeType: artifactMimeType(requested!) };\n } catch (error) {\n await handle.close();\n throw error;\n }\n } catch (error) {\n throw accessError(error, 'read');\n }\n}\n\n/** Bound allocation and read length even when the file grows after its metadata was read. */\nexport async function readArtifactBytes(handle: fs.FileHandle, size: number, offset = 0): Promise<Uint8Array> {\n const bytes = new Uint8Array(size);\n let read = 0;\n while (read < size) {\n const result = await handle.read(bytes, read, size - read, offset + read);\n if (result.bytesRead === 0) break;\n read += result.bytesRead;\n }\n return bytes.subarray(0, read);\n}\n\n/** Walk to the parent folder without following symlinks, creating missing folders on request. */\nasync function containedParent(realRoot: string, segments: string[], create: boolean): Promise<string> {\n let directory = realRoot;\n for (const segment of segments.slice(0, -1)) {\n directory = path.join(directory, segment);\n if (create)\n await fs.mkdir(directory, { mode: 0o700 }).catch((error: unknown) => {\n if (codeOf(error) !== 'EEXIST') throw error;\n });\n const stat = await fs.lstat(directory);\n if (stat.isSymbolicLink() || !stat.isDirectory())\n throw new ArtifactAccessError('The artifact folder is not a directory.', 403);\n }\n return directory;\n}\n\nasync function sameText(root: string, requested: string, bytes: Buffer): Promise<boolean> {\n try {\n const file = await openArtifact(root, requested);\n try {\n if (file.stat.size !== bytes.length) return false;\n return bytes.equals(await readArtifactBytes(file.handle, file.stat.size));\n } finally {\n await file.handle.close();\n }\n } catch (error) {\n if (error instanceof ArtifactAccessError) return false;\n throw error;\n }\n}\n\n/**\n * Publish text through a same-folder temp file and rename, skipping identical content so mtimes stay stable.\n * ponytail: best-effort same-user guards, not race-resistant. Linux checks ancestors with lstat only;\n * walk with openat-style /proc/self/fd handles like openContained if artifacts cross a trust boundary.\n */\nexport async function writeArtifactText(root: string, requested: string, text: string): Promise<void> {\n const segments = artifactSegments(requested);\n if (process.platform !== 'darwin' && process.platform !== 'linux')\n throw new ArtifactAccessError('Secure artifact writes require macOS or Linux.', 403);\n const bytes = Buffer.from(text, 'utf8');\n try {\n await ensureArtifactRoot(root);\n const directory = await containedParent(await checkedRoot(root), segments, true);\n if (await sameText(root, requested, bytes)) return;\n const temp = path.join(directory, `.${segments.at(-1)!}.${randomUUID()}.tmp`);\n // Darwin O_NOFOLLOW_ANY refuses a symlink in any component; O_EXCL refuses one at the leaf.\n const flags =\n constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (process.platform === 'darwin' ? 0x20000000 : 0);\n const handle = await fs.open(temp, flags, 0o600);\n try {\n await handle.writeFile(bytes);\n await handle.close();\n await fs.rename(temp, path.join(directory, segments.at(-1)!));\n } catch (error) {\n await handle.close().catch(() => undefined);\n await fs.unlink(temp).catch(() => undefined);\n throw error;\n }\n } catch (error) {\n throw accessError(error, 'written');\n }\n}\n\n/** Remove one file or one empty folder. A missing target is already removed; nothing is deleted recursively. */\nexport async function removeArtifact(root: string, requested: string): Promise<void> {\n const segments = artifactSegments(requested);\n try {\n const target = path.join(await containedParent(await checkedRoot(root), segments, false), segments.at(-1)!);\n const stat = await fs.lstat(target);\n if (stat.isFile()) await fs.unlink(target);\n else if (!stat.isDirectory()) throw new ArtifactAccessError('The artifact is not a file or folder.', 403);\n else\n await fs.rmdir(target).catch((error: unknown) => {\n if (codeOf(error) !== 'ENOTEMPTY' && codeOf(error) !== 'EEXIST') throw error;\n });\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return;\n throw accessError(error, 'removed');\n }\n}\n/** Discover persisted session roots without admitting symlinked or malformed owners. */\nexport async function listArtifactSessions(\n environment: Readonly<Record<string, string | undefined>>,\n): Promise<readonly string[]> {\n const parent = path.dirname(artifactRoot('discovery', environment));\n try {\n const stat = await fs.lstat(parent);\n if (!stat.isDirectory() || stat.isSymbolicLink())\n throw new ArtifactAccessError('The artifact storage directory is unavailable.', 403);\n const entries = await fs.readdir(parent, { withFileTypes: true });\n return entries\n .filter((entry) => entry.isDirectory() && /^[a-zA-Z0-9_-]+$/u.test(entry.name))\n .map((entry) => entry.name);\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return [];\n throw error;\n }\n}\n\nexport async function listArtifacts(\n root: string,\n workflowVisible?: ArtifactWorkflowVisibility,\n): Promise<ArtifactSnapshot> {\n const items: ArtifactItem[] = [];\n try {\n const realRoot = await checkedRoot(root);\n const visit = async (directory: string): Promise<void> => {\n for (const entry of await fs.readdir(directory, { withFileTypes: true })) {\n const location = path.join(directory, entry.name);\n const relativePath = path.relative(realRoot, location).split(path.sep).join('/');\n const segments = relativePath.split('/');\n if (\n segments[0] === WORKFLOW_ARTIFACT_DIRECTORY &&\n !workflowVisible?.(segments.slice(1).join('/'), entry.isDirectory() ? 'directory' : 'file')\n )\n continue;\n if (entry.isDirectory()) {\n // Recheck each directory rather than trusting a readdir entry across a rename.\n const stat = await fs.lstat(location);\n if (!stat.isDirectory() || stat.isSymbolicLink()) continue;\n const real = await fs.realpath(location);\n if (inside(realRoot, real)) await visit(real);\n } else if (entry.isFile() && !IN_FLIGHT_COPY.test(entry.name)) {\n try {\n const file = await openArtifact(root, relativePath, workflowVisible);\n try {\n items.push({ path: relativePath, name: entry.name, size: file.stat.size, modifiedAt: file.stat.mtimeMs });\n } finally {\n await file.handle.close();\n }\n } catch (error) {\n if (error instanceof ArtifactAccessError && (error.status === 404 || error.status === 403)) continue;\n throw error;\n }\n }\n }\n };\n await visit(realRoot);\n items.sort(\n (left, right) =>\n right.modifiedAt - left.modifiedAt || (left.path < right.path ? -1 : left.path > right.path ? 1 : 0),\n );\n return { items };\n } catch (error) {\n if (codeOf(error) === 'ENOENT') return { items: [] };\n return { items: [], error: error instanceof Error ? error.message : 'The artifact folder could not be read.' };\n }\n}\n"],"mappings":";;;;;;;AAMA,IAAa,sBAAb,cAAyC,MAAM;CAGlC;CAFX,YACE,SACA,QACA;EACA,MAAM,OAAO;EAFJ,KAAA,SAAA;CAGX;AACF;AAEA,SAAgB,aAAa,WAAmB,aAAmE;CACjH,IAAI,CAAC,oBAAoB,KAAK,SAAS,GAAG,MAAM,IAAI,oBAAoB,sCAAsC,GAAG;CACjH,OAAO,KAAK,KAAK,iBAAiB,aAAa,YAAY,IAAI,GAAG,oBAAoB,SAAS;AACjG;AAEA,SAAgB,iBAAiB,cAA8B;CAC7D,OAAO,uBAAuB,KAAK,QAAQ,YAAY,CAAC,CAAC,YAAY,MAAM;AAC7E;;;;ACVA,MAAM,iBAAiB;AACvB,SAAS,OAAO,MAAc,WAA4B;CACxD,MAAM,WAAW,KAAK,SAAS,MAAM,SAAS;CAC9C,OAAO,aAAa,QAAQ,CAAC,SAAS,WAAW,KAAK,KAAK,KAAK,KAAK,CAAC,KAAK,WAAW,QAAQ;AAChG;AAEA,SAAS,OAAO,OAAoC;CAClD,OAAO,iBAAiB,SAAS,UAAU,QAAQ,O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