@wirecat/yandex-disk-cli 0.0.0-stage → 0.1.0

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 (235) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +204 -0
  3. package/README.md +243 -2
  4. package/contracts/wirecat.json +1554 -0
  5. package/dist/bin/ydisk.d.ts +3 -0
  6. package/dist/bin/ydisk.d.ts.map +1 -0
  7. package/dist/bin/ydisk.js +40 -0
  8. package/dist/bin/ydisk.js.map +1 -0
  9. package/dist/bundle/all-profiles-4OLZF3RT.js +279 -0
  10. package/dist/bundle/anthropic-DKB4OJXZ.js +91 -0
  11. package/dist/bundle/app-server-G4545SSV.js +247 -0
  12. package/dist/bundle/bun-RXEQKFED.js +169 -0
  13. package/dist/bundle/bun-sqlite-VHT5LN7U.js +76 -0
  14. package/dist/bundle/chunk-2BITUXGC.js +12289 -0
  15. package/dist/bundle/chunk-2CLWDQKA.js +39330 -0
  16. package/dist/bundle/chunk-2JFDOPKA.js +9575 -0
  17. package/dist/bundle/chunk-3GVI2MAO.js +106 -0
  18. package/dist/bundle/chunk-3SZBWBMI.js +131 -0
  19. package/dist/bundle/chunk-44VSEXW6.js +4054 -0
  20. package/dist/bundle/chunk-4YPRRQBE.js +95 -0
  21. package/dist/bundle/chunk-5COYRL5B.js +379 -0
  22. package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
  23. package/dist/bundle/chunk-5DM7DIZL.js +1402 -0
  24. package/dist/bundle/chunk-6R2DVTVZ.js +24 -0
  25. package/dist/bundle/chunk-762BS35H.js +2787 -0
  26. package/dist/bundle/chunk-AG64V7AB.js +1233 -0
  27. package/dist/bundle/chunk-BC5HGIXB.js +334 -0
  28. package/dist/bundle/chunk-BH7LFEX7.js +36 -0
  29. package/dist/bundle/chunk-BLNPGY7N.js +53 -0
  30. package/dist/bundle/chunk-CNIA2LJF.js +372 -0
  31. package/dist/bundle/chunk-COSXMDC7.js +230 -0
  32. package/dist/bundle/chunk-D72URWJE.js +532 -0
  33. package/dist/bundle/chunk-D7FO33KU.js +785 -0
  34. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  35. package/dist/bundle/chunk-DJH26PQ3.js +1396 -0
  36. package/dist/bundle/chunk-DJPT7IUC.js +64567 -0
  37. package/dist/bundle/chunk-DTMSCZDW.js +209 -0
  38. package/dist/bundle/chunk-E6LGZ5LX.js +16 -0
  39. package/dist/bundle/chunk-E6YRIHS5.js +92 -0
  40. package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
  41. package/dist/bundle/chunk-F3DDSZTF.js +78 -0
  42. package/dist/bundle/chunk-F4WWTQNL.js +188 -0
  43. package/dist/bundle/chunk-FDDAUASC.js +1028 -0
  44. package/dist/bundle/chunk-FMNPG6N2.js +170 -0
  45. package/dist/bundle/chunk-FOKJ4POB.js +274 -0
  46. package/dist/bundle/chunk-G22C7JG6.js +731 -0
  47. package/dist/bundle/chunk-GA442SYZ.js +161 -0
  48. package/dist/bundle/chunk-GEBSW7UK.js +6848 -0
  49. package/dist/bundle/chunk-GGRKWAOK.js +594 -0
  50. package/dist/bundle/chunk-HHINRNZA.js +788 -0
  51. package/dist/bundle/chunk-HUZCL33L.js +128 -0
  52. package/dist/bundle/chunk-IALSIQVT.js +142 -0
  53. package/dist/bundle/chunk-IOXR2QBX.js +398 -0
  54. package/dist/bundle/chunk-J5CXR6VX.js +63 -0
  55. package/dist/bundle/chunk-J5PWSTOX.js +82 -0
  56. package/dist/bundle/chunk-J7BVAEHR.js +364 -0
  57. package/dist/bundle/chunk-JH46HMZW.js +1334 -0
  58. package/dist/bundle/chunk-JOBO7F6W.js +52 -0
  59. package/dist/bundle/chunk-JXZ5B3L5.js +2333 -0
  60. package/dist/bundle/chunk-KBIAMDZN.js +66 -0
  61. package/dist/bundle/chunk-KFVDL2QS.js +146 -0
  62. package/dist/bundle/chunk-LNHTLSR5.js +288 -0
  63. package/dist/bundle/chunk-M24RAKMJ.js +58 -0
  64. package/dist/bundle/chunk-MDQ57Q3H.js +1197 -0
  65. package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
  66. package/dist/bundle/chunk-MLXQ4X5L.js +206 -0
  67. package/dist/bundle/chunk-NQAKARHE.js +54 -0
  68. package/dist/bundle/chunk-OF7VVUDQ.js +23 -0
  69. package/dist/bundle/chunk-OQVPE3XK.js +324 -0
  70. package/dist/bundle/chunk-OR3QG7UR.js +259 -0
  71. package/dist/bundle/chunk-OUUYVROP.js +76 -0
  72. package/dist/bundle/chunk-PQBAM64O.js +168 -0
  73. package/dist/bundle/chunk-PYVIA7WF.js +88 -0
  74. package/dist/bundle/chunk-Q6HK3PHE.js +72 -0
  75. package/dist/bundle/chunk-QB3KECV2.js +218 -0
  76. package/dist/bundle/chunk-QGWXSFYN.js +73 -0
  77. package/dist/bundle/chunk-RC5QAAAE.js +29 -0
  78. package/dist/bundle/chunk-RMJ26HLB.js +18 -0
  79. package/dist/bundle/chunk-S4UUN6LD.js +1410 -0
  80. package/dist/bundle/chunk-T7ZUDA4C.js +72 -0
  81. package/dist/bundle/chunk-TRCSMVV5.js +72 -0
  82. package/dist/bundle/chunk-UD2BQEKA.js +46 -0
  83. package/dist/bundle/chunk-V4TL55GS.js +1068 -0
  84. package/dist/bundle/chunk-VJNWN5VU.js +4072 -0
  85. package/dist/bundle/chunk-VRRNBLMA.js +1227 -0
  86. package/dist/bundle/chunk-WUCMMNFJ.js +771 -0
  87. package/dist/bundle/chunk-XDESE3NY.js +44 -0
  88. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  89. package/dist/bundle/chunk-XQUUANA2.js +24600 -0
  90. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  91. package/dist/bundle/chunk-Z2QEON7B.js +2275 -0
  92. package/dist/bundle/chunk-ZMJ56GME.js +7 -0
  93. package/dist/bundle/chunk-ZTSB3D7Q.js +100 -0
  94. package/dist/bundle/chunk-ZVJWD3FK.js +38 -0
  95. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  96. package/dist/bundle/command-contract-YIOYGPJA.js +40 -0
  97. package/dist/bundle/command-server-entry-MHBQDXS4.js +169 -0
  98. package/dist/bundle/decode-NUGJIOUW.js +297 -0
  99. package/dist/bundle/definitions-AILHKEQT.js +2005 -0
  100. package/dist/bundle/dispatch-5LC4UEGY.js +411 -0
  101. package/dist/bundle/dist-4I2W6X2I.js +7577 -0
  102. package/dist/bundle/echarts-MHSH6PGC.js +42501 -0
  103. package/dist/bundle/embed-ZDXTHHYS.js +38 -0
  104. package/dist/bundle/embedder-XFEELFUL.js +111 -0
  105. package/dist/bundle/failure-5S7VPBYK.js +25 -0
  106. package/dist/bundle/first-run-JHCHT3RJ.js +29 -0
  107. package/dist/bundle/first-screen-FHGQ6QRV.js +40 -0
  108. package/dist/bundle/instructions-WKSMBUFX.js +11 -0
  109. package/dist/bundle/mcp-HS2ZDUVR.js +167 -0
  110. package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
  111. package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
  112. package/dist/bundle/meeting-combined-K4U4NYRZ.js +25 -0
  113. package/dist/bundle/meeting-model-KCEG6Y5O.js +26 -0
  114. package/dist/bundle/meeting-semantic-VYGSV3H6.js +22 -0
  115. package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
  116. package/dist/bundle/node-CM6NC6UE.js +176 -0
  117. package/dist/bundle/node-KM3CUABH.js +2340 -0
  118. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  119. package/dist/bundle/node-sqlite-5YDQ3LIJ.js +74 -0
  120. package/dist/bundle/notes-search-PGO7KM2U.js +62 -0
  121. package/dist/bundle/oauth-NY4C5UCK.js +20 -0
  122. package/dist/bundle/open-YNUTA6ZE.js +23 -0
  123. package/dist/bundle/openai-4CVT5PHH.js +241 -0
  124. package/dist/bundle/process-2XT3TL27.js +91 -0
  125. package/dist/bundle/program-FMIVF5T6.js +31904 -0
  126. package/dist/bundle/prompt-VNWY3H6S.js +17 -0
  127. package/dist/bundle/recognize-JS4PBPSZ.js +26 -0
  128. package/dist/bundle/remote-RCLFH4V2.js +32 -0
  129. package/dist/bundle/rerank-EG6VKYGO.js +52 -0
  130. package/dist/bundle/schemas-ED2LHKXK.js +645 -0
  131. package/dist/bundle/serve-AHG25QXB.js +199 -0
  132. package/dist/bundle/server-5FTB7WM3.js +78 -0
  133. package/dist/bundle/server-JNZVSAZE.js +209 -0
  134. package/dist/bundle/sqlite-runtime-XSZOAQPF.js +20 -0
  135. package/dist/bundle/state-XGVAJFF7.js +36 -0
  136. package/dist/bundle/store-OHSCWZEV.js +177 -0
  137. package/dist/bundle/store-PKSPKJXL.js +293 -0
  138. package/dist/bundle/store-maintenance-command-KAWGBSWK.js +69 -0
  139. package/dist/bundle/ydisk.js +183 -0
  140. package/dist/commands/api.d.ts +9 -0
  141. package/dist/commands/api.d.ts.map +1 -0
  142. package/dist/commands/api.js +59 -0
  143. package/dist/commands/api.js.map +1 -0
  144. package/dist/commands/comments.d.ts +3 -0
  145. package/dist/commands/comments.d.ts.map +1 -0
  146. package/dist/commands/comments.js +114 -0
  147. package/dist/commands/comments.js.map +1 -0
  148. package/dist/commands/files.d.ts +3 -0
  149. package/dist/commands/files.d.ts.map +1 -0
  150. package/dist/commands/files.js +272 -0
  151. package/dist/commands/files.js.map +1 -0
  152. package/dist/commands/library.d.ts +13 -0
  153. package/dist/commands/library.d.ts.map +1 -0
  154. package/dist/commands/library.js +118 -0
  155. package/dist/commands/library.js.map +1 -0
  156. package/dist/commands/session.d.ts +3 -0
  157. package/dist/commands/session.d.ts.map +1 -0
  158. package/dist/commands/session.js +99 -0
  159. package/dist/commands/session.js.map +1 -0
  160. package/dist/config.d.ts +18 -0
  161. package/dist/config.d.ts.map +1 -0
  162. package/dist/config.js +62 -0
  163. package/dist/config.js.map +1 -0
  164. package/dist/context.d.ts +80 -0
  165. package/dist/context.d.ts.map +1 -0
  166. package/dist/context.js +77 -0
  167. package/dist/context.js.map +1 -0
  168. package/dist/generated/definitions.d.ts +3 -0
  169. package/dist/generated/definitions.d.ts.map +1 -0
  170. package/dist/generated/definitions.js +2001 -0
  171. package/dist/generated/definitions.js.map +1 -0
  172. package/dist/generated/manifest.d.ts +6 -0
  173. package/dist/generated/manifest.d.ts.map +1 -0
  174. package/dist/generated/manifest.js +1473 -0
  175. package/dist/generated/manifest.js.map +1 -0
  176. package/dist/generated/schemas.d.ts +127 -0
  177. package/dist/generated/schemas.d.ts.map +1 -0
  178. package/dist/generated/schemas.js +545 -0
  179. package/dist/generated/schemas.js.map +1 -0
  180. package/dist/generated/types.d.ts +829 -0
  181. package/dist/generated/types.d.ts.map +1 -0
  182. package/dist/generated/types.js +5 -0
  183. package/dist/generated/types.js.map +1 -0
  184. package/dist/identity.d.ts +10 -0
  185. package/dist/identity.d.ts.map +1 -0
  186. package/dist/identity.js +33 -0
  187. package/dist/identity.js.map +1 -0
  188. package/dist/index.d.ts +3 -0
  189. package/dist/index.d.ts.map +1 -0
  190. package/dist/index.js +3 -0
  191. package/dist/index.js.map +1 -0
  192. package/dist/program.d.ts +6 -0
  193. package/dist/program.d.ts.map +1 -0
  194. package/dist/program.js +65 -0
  195. package/dist/program.js.map +1 -0
  196. package/dist/sample/comments.d.ts +61 -0
  197. package/dist/sample/comments.d.ts.map +1 -0
  198. package/dist/sample/comments.js +39 -0
  199. package/dist/sample/comments.js.map +1 -0
  200. package/dist/sample/records.d.ts +16 -0
  201. package/dist/sample/records.d.ts.map +1 -0
  202. package/dist/sample/records.js +22 -0
  203. package/dist/sample/records.js.map +1 -0
  204. package/dist/sample/transport.d.ts +42 -0
  205. package/dist/sample/transport.d.ts.map +1 -0
  206. package/dist/sample/transport.js +153 -0
  207. package/dist/sample/transport.js.map +1 -0
  208. package/dist/version.d.ts +2 -0
  209. package/dist/version.d.ts.map +1 -0
  210. package/dist/version.js +2 -0
  211. package/dist/version.js.map +1 -0
  212. package/dist/wcat.d.ts +3 -0
  213. package/dist/wcat.d.ts.map +1 -0
  214. package/dist/wcat.js +4 -0
  215. package/dist/wcat.js.map +1 -0
  216. package/dist/yandex/source.d.ts +39 -0
  217. package/dist/yandex/source.d.ts.map +1 -0
  218. package/dist/yandex/source.js +189 -0
  219. package/dist/yandex/source.js.map +1 -0
  220. package/dist/yandex/transport.d.ts +41 -0
  221. package/dist/yandex/transport.d.ts.map +1 -0
  222. package/dist/yandex/transport.js +152 -0
  223. package/dist/yandex/transport.js.map +1 -0
  224. package/dist/yandex/writes.d.ts +27 -0
  225. package/dist/yandex/writes.d.ts.map +1 -0
  226. package/dist/yandex/writes.js +61 -0
  227. package/dist/yandex/writes.js.map +1 -0
  228. package/package.json +88 -4
  229. package/skills/yandex-disk-cli/SKILL.md +46 -0
  230. package/skills/yandex-disk-cli/references/api/api-disk-operations-operation-id.md +13 -0
  231. package/skills/yandex-disk-cli/references/api/api-disk-public-resources.md +50 -0
  232. package/skills/yandex-disk-cli/references/api/api-disk-resources.md +171 -0
  233. package/skills/yandex-disk-cli/references/api/api-disk-trash-resources.md +48 -0
  234. package/skills/yandex-disk-cli/references/api/api-disk.md +13 -0
  235. package/skills/yandex-disk-cli/references/api.md +17 -0
@@ -0,0 +1,1233 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ array,
5
+ boolean,
6
+ endsWith,
7
+ getDotPath,
8
+ integer,
9
+ isoTimestamp,
10
+ literal,
11
+ maxLength,
12
+ minLength,
13
+ minValue,
14
+ nullable,
15
+ number,
16
+ optional,
17
+ picklist,
18
+ pipe,
19
+ record,
20
+ regex,
21
+ safeParse,
22
+ strictObject,
23
+ string,
24
+ union,
25
+ unknown,
26
+ variant
27
+ } from "./chunk-S4UUN6LD.js";
28
+ import {
29
+ errorCodes,
30
+ isCliError,
31
+ visibleControls
32
+ } from "./chunk-T7ZUDA4C.js";
33
+ import {
34
+ __name
35
+ } from "./chunk-ZVVMGPBJ.js";
36
+
37
+ // node_modules/.pnpm/@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_commander@15.0.0_esbuild@0.28._2fe0e09d29eda9827e2087fd1a1cce67/node_modules/@wirecat/cli-base/dist/exit-codes.js
38
+ var EXIT_CODES = {
39
+ validation_error: 2,
40
+ configuration_error: 3,
41
+ authentication_error: 4,
42
+ permission_error: 5,
43
+ not_found: 6,
44
+ confirmation_required: 7,
45
+ rate_limited: 8,
46
+ timeout: 9,
47
+ network_error: 10,
48
+ provider_error: 11,
49
+ provider_unavailable: 12,
50
+ invalid_response: 13,
51
+ outcome_unknown: 14,
52
+ conflict: 15,
53
+ cancelled: 130
54
+ };
55
+ var exitCodeFor = /* @__PURE__ */ __name((code) => EXIT_CODES[code], "exitCodeFor");
56
+ var GENERIC_FAILURE = 1;
57
+
58
+ // node_modules/.pnpm/@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_commander@15.0.0_esbuild@0.28._2fe0e09d29eda9827e2087fd1a1cce67/node_modules/@wirecat/cli-base/dist/standards/effects.js
59
+ var EFFECT_LEVELS = ["none", "read", "write"];
60
+ var effectsSchema = strictObject({
61
+ remote: picklist(EFFECT_LEVELS),
62
+ local: picklist(EFFECT_LEVELS)
63
+ });
64
+ var writes = /* @__PURE__ */ __name((effects) => effects === void 0 || effects.remote === "write" || effects.local === "write", "writes");
65
+
66
+ // node_modules/.pnpm/@valibot+to-json-schema@1.8.0_valibot@1.5.0_typescript@7.0.2_/node_modules/@valibot/to-json-schema/dist/index.mjs
67
+ function addError(errors, message) {
68
+ if (errors) {
69
+ errors.push(message);
70
+ return errors;
71
+ }
72
+ return [message];
73
+ }
74
+ __name(addError, "addError");
75
+ var ESCAPE_REGEX = /[.*+?^${}()|[\]\\]/g;
76
+ function escapeRegExp(string2) {
77
+ return string2.replace(ESCAPE_REGEX, "\\$&");
78
+ }
79
+ __name(escapeRegExp, "escapeRegExp");
80
+ function handleError(message, config) {
81
+ switch (config?.errorMode) {
82
+ case "ignore":
83
+ break;
84
+ case "warn":
85
+ console.warn(message);
86
+ break;
87
+ default:
88
+ throw new Error(message);
89
+ }
90
+ }
91
+ __name(handleError, "handleError");
92
+ function isJsonConstValue(value) {
93
+ return typeof value === "boolean" || typeof value === "number" && Number.isFinite(value) || typeof value === "string";
94
+ }
95
+ __name(isJsonConstValue, "isJsonConstValue");
96
+ function isJsonEnumValues(values) {
97
+ return values.every(isJsonConstValue);
98
+ }
99
+ __name(isJsonEnumValues, "isJsonEnumValues");
100
+ var ReferenceMap = class extends Map {
101
+ static {
102
+ __name(this, "ReferenceMap");
103
+ }
104
+ /**
105
+ * Creates an empty schema reference map.
106
+ */
107
+ constructor() {
108
+ super();
109
+ this.count = 0;
110
+ this.usedIds = /* @__PURE__ */ new Set();
111
+ }
112
+ /**
113
+ * Adds a schema reference and reserves its ID.
114
+ *
115
+ * @param schema The Valibot schema.
116
+ * @param referenceId The reference ID.
117
+ *
118
+ * @returns The reference map.
119
+ */
120
+ set(schema, referenceId) {
121
+ this.usedIds.add(referenceId);
122
+ return super.set(schema, referenceId);
123
+ }
124
+ /**
125
+ * Creates a reference ID that is not yet used.
126
+ *
127
+ * @param definitions The JSON Schema definitions.
128
+ *
129
+ * @returns The unused reference ID.
130
+ */
131
+ createId(definitions) {
132
+ while (this.usedIds.has(`${this.count}`) || `${this.count}` in definitions) this.count++;
133
+ return `${this.count++}`;
134
+ }
135
+ };
136
+ function getLowerBound(current, value) {
137
+ if (typeof current !== "number" || !Number.isFinite(current) || value > current) return value;
138
+ return current;
139
+ }
140
+ __name(getLowerBound, "getLowerBound");
141
+ function getUpperBound(current, value) {
142
+ if (typeof current !== "number" || !Number.isFinite(current) || value < current) return value;
143
+ return current;
144
+ }
145
+ __name(getUpperBound, "getUpperBound");
146
+ // @__NO_SIDE_EFFECTS__
147
+ function getNotRestriction(current, value) {
148
+ return current !== void 0 ? { anyOf: [current, value] } : value;
149
+ }
150
+ __name(getNotRestriction, "getNotRestriction");
151
+ function intersectEnum(jsonSchema, values) {
152
+ let enumValues = jsonSchema.enum ?? values;
153
+ if (jsonSchema.enum) {
154
+ const valueSet = new Set(values);
155
+ enumValues = enumValues.filter((value) => valueSet.has(value));
156
+ }
157
+ if (enumValues.length) jsonSchema.enum = [...new Set(enumValues)];
158
+ else {
159
+ delete jsonSchema.enum;
160
+ jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, {});
161
+ }
162
+ }
163
+ __name(intersectEnum, "intersectEnum");
164
+ function convertAction(jsonSchema, valibotAction, config) {
165
+ if (config?.ignoreActions?.includes(valibotAction.type)) return jsonSchema;
166
+ let errors;
167
+ switch (valibotAction.type) {
168
+ case "base64":
169
+ jsonSchema.contentEncoding = "base64";
170
+ break;
171
+ case "bic":
172
+ case "cuid2":
173
+ case "decimal":
174
+ case "digits":
175
+ case "domain":
176
+ case "emoji":
177
+ case "hash":
178
+ case "hexadecimal":
179
+ case "hex_color":
180
+ case "isrc":
181
+ case "iso_time_second":
182
+ case "iso_week":
183
+ case "ksuid":
184
+ case "mac":
185
+ case "mac48":
186
+ case "mac64":
187
+ case "nanoid":
188
+ case "octal":
189
+ case "slug":
190
+ case "ulid":
191
+ if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
192
+ else jsonSchema.pattern = valibotAction.requirement.source;
193
+ break;
194
+ case "description":
195
+ jsonSchema.description = valibotAction.description;
196
+ break;
197
+ case "email":
198
+ case "rfc_email":
199
+ jsonSchema.format = "email";
200
+ break;
201
+ case "ends_with":
202
+ if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
203
+ else jsonSchema.pattern = `${escapeRegExp(valibotAction.requirement)}$`;
204
+ break;
205
+ case "empty":
206
+ if (jsonSchema.type === "array") jsonSchema.maxItems = 0;
207
+ else {
208
+ if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
209
+ jsonSchema.maxLength = 0;
210
+ }
211
+ break;
212
+ case "entries":
213
+ if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
214
+ errors = addError(errors, 'The requirement of the "entries" action must be a non-negative integer.');
215
+ break;
216
+ }
217
+ jsonSchema.minProperties = getLowerBound(jsonSchema.minProperties, valibotAction.requirement);
218
+ jsonSchema.maxProperties = getUpperBound(jsonSchema.maxProperties, valibotAction.requirement);
219
+ break;
220
+ case "examples":
221
+ if (Array.isArray(jsonSchema.examples)) jsonSchema.examples = [...jsonSchema.examples, ...valibotAction.examples];
222
+ else jsonSchema.examples = valibotAction.examples;
223
+ break;
224
+ case "gt_value":
225
+ if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
226
+ errors = addError(errors, `The "gt_value" action is not supported on type "${jsonSchema.type}".`);
227
+ break;
228
+ }
229
+ if (!Number.isFinite(valibotAction.requirement)) {
230
+ errors = addError(errors, 'The requirement of the "gt_value" action is not JSON compatible.');
231
+ break;
232
+ }
233
+ if (config?.target === "openapi-3.0") {
234
+ errors = addError(errors, 'The "gt_value" action is not supported for OpenAPI 3.0.');
235
+ break;
236
+ }
237
+ jsonSchema.exclusiveMinimum = getLowerBound(jsonSchema.exclusiveMinimum, valibotAction.requirement);
238
+ break;
239
+ case "includes":
240
+ if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
241
+ else jsonSchema.pattern = escapeRegExp(valibotAction.requirement);
242
+ break;
243
+ case "integer":
244
+ jsonSchema.type = "integer";
245
+ break;
246
+ case "ipv4":
247
+ jsonSchema.format = "ipv4";
248
+ break;
249
+ case "ipv6":
250
+ jsonSchema.format = "ipv6";
251
+ break;
252
+ case "iso_date":
253
+ jsonSchema.format = "date";
254
+ break;
255
+ case "iso_date_time":
256
+ case "iso_timestamp":
257
+ jsonSchema.format = "date-time";
258
+ break;
259
+ case "iso_time":
260
+ jsonSchema.format = "time";
261
+ break;
262
+ case "jws_compact":
263
+ if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
264
+ else jsonSchema.pattern = valibotAction.requirement.source;
265
+ break;
266
+ case "length":
267
+ if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
268
+ errors = addError(errors, 'The requirement of the "length" action must be a non-negative integer.');
269
+ break;
270
+ }
271
+ if (jsonSchema.type === "array") {
272
+ jsonSchema.minItems = getLowerBound(jsonSchema.minItems, valibotAction.requirement);
273
+ jsonSchema.maxItems = getUpperBound(jsonSchema.maxItems, valibotAction.requirement);
274
+ } else {
275
+ if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
276
+ jsonSchema.minLength = getLowerBound(jsonSchema.minLength, valibotAction.requirement);
277
+ jsonSchema.maxLength = getUpperBound(jsonSchema.maxLength, valibotAction.requirement);
278
+ }
279
+ break;
280
+ case "lt_value":
281
+ if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
282
+ errors = addError(errors, `The "lt_value" action is not supported on type "${jsonSchema.type}".`);
283
+ break;
284
+ }
285
+ if (!Number.isFinite(valibotAction.requirement)) {
286
+ errors = addError(errors, 'The requirement of the "lt_value" action is not JSON compatible.');
287
+ break;
288
+ }
289
+ if (config?.target === "openapi-3.0") {
290
+ errors = addError(errors, 'The "lt_value" action is not supported for OpenAPI 3.0.');
291
+ break;
292
+ }
293
+ jsonSchema.exclusiveMaximum = getUpperBound(jsonSchema.exclusiveMaximum, valibotAction.requirement);
294
+ break;
295
+ case "max_entries":
296
+ if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
297
+ errors = addError(errors, 'The requirement of the "max_entries" action must be a non-negative integer.');
298
+ break;
299
+ }
300
+ jsonSchema.maxProperties = getUpperBound(jsonSchema.maxProperties, valibotAction.requirement);
301
+ break;
302
+ case "max_length":
303
+ if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
304
+ errors = addError(errors, 'The requirement of the "max_length" action must be a non-negative integer.');
305
+ break;
306
+ }
307
+ if (jsonSchema.type === "array") jsonSchema.maxItems = getUpperBound(jsonSchema.maxItems, valibotAction.requirement);
308
+ else {
309
+ if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
310
+ jsonSchema.maxLength = getUpperBound(jsonSchema.maxLength, valibotAction.requirement);
311
+ }
312
+ break;
313
+ case "max_value":
314
+ if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
315
+ errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`);
316
+ break;
317
+ }
318
+ if (!Number.isFinite(valibotAction.requirement)) {
319
+ errors = addError(errors, 'The requirement of the "max_value" action is not JSON compatible.');
320
+ break;
321
+ }
322
+ jsonSchema.maximum = getUpperBound(jsonSchema.maximum, valibotAction.requirement);
323
+ break;
324
+ case "metadata":
325
+ if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title;
326
+ if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description;
327
+ if (Array.isArray(valibotAction.metadata.examples)) if (Array.isArray(jsonSchema.examples)) jsonSchema.examples = [...jsonSchema.examples, ...valibotAction.metadata.examples];
328
+ else jsonSchema.examples = valibotAction.metadata.examples;
329
+ for (const key of Object.keys(valibotAction.metadata)) if (key !== "title" && key !== "description" && key !== "examples" && key !== "__proto__") jsonSchema[key] = valibotAction.metadata[key];
330
+ break;
331
+ case "min_entries":
332
+ if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
333
+ errors = addError(errors, 'The requirement of the "min_entries" action must be a non-negative integer.');
334
+ break;
335
+ }
336
+ jsonSchema.minProperties = getLowerBound(jsonSchema.minProperties, valibotAction.requirement);
337
+ break;
338
+ case "min_length":
339
+ if (!Number.isInteger(valibotAction.requirement) || valibotAction.requirement < 0) {
340
+ errors = addError(errors, 'The requirement of the "min_length" action must be a non-negative integer.');
341
+ break;
342
+ }
343
+ if (jsonSchema.type === "array") jsonSchema.minItems = getLowerBound(jsonSchema.minItems, valibotAction.requirement);
344
+ else {
345
+ if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
346
+ jsonSchema.minLength = getLowerBound(jsonSchema.minLength, valibotAction.requirement);
347
+ }
348
+ break;
349
+ case "min_value":
350
+ if (jsonSchema.type !== "number" && jsonSchema.type !== "integer") {
351
+ errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`);
352
+ break;
353
+ }
354
+ if (!Number.isFinite(valibotAction.requirement)) {
355
+ errors = addError(errors, 'The requirement of the "min_value" action is not JSON compatible.');
356
+ break;
357
+ }
358
+ jsonSchema.minimum = getLowerBound(jsonSchema.minimum, valibotAction.requirement);
359
+ break;
360
+ case "multiple_of":
361
+ jsonSchema.multipleOf = valibotAction.requirement;
362
+ break;
363
+ case "non_empty":
364
+ if (jsonSchema.type === "array") jsonSchema.minItems = getLowerBound(jsonSchema.minItems, 1);
365
+ else {
366
+ if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
367
+ jsonSchema.minLength = getLowerBound(jsonSchema.minLength, 1);
368
+ }
369
+ break;
370
+ case "not_value":
371
+ if (!isJsonConstValue(valibotAction.requirement)) {
372
+ errors = addError(errors, 'The requirement of the "not_value" action is not JSON compatible.');
373
+ break;
374
+ }
375
+ jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, config?.target === "openapi-3.0" ? { enum: [valibotAction.requirement] } : { const: valibotAction.requirement });
376
+ break;
377
+ case "not_values":
378
+ if (!isJsonEnumValues(valibotAction.requirement)) {
379
+ errors = addError(errors, 'A requirement of the "not_values" action is not JSON compatible.');
380
+ break;
381
+ }
382
+ if (valibotAction.requirement.length) jsonSchema.not = /* @__PURE__ */ getNotRestriction(jsonSchema.not, { enum: [...new Set(valibotAction.requirement)] });
383
+ break;
384
+ case "regex":
385
+ if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema.");
386
+ if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
387
+ else jsonSchema.pattern = valibotAction.requirement.source;
388
+ break;
389
+ case "safe_integer":
390
+ jsonSchema.type = "integer";
391
+ jsonSchema.minimum = getLowerBound(jsonSchema.minimum, Number.MIN_SAFE_INTEGER);
392
+ jsonSchema.maximum = getUpperBound(jsonSchema.maximum, Number.MAX_SAFE_INTEGER);
393
+ break;
394
+ case "starts_with":
395
+ if (jsonSchema.pattern) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with another regex action.`);
396
+ else jsonSchema.pattern = `^${escapeRegExp(valibotAction.requirement)}`;
397
+ break;
398
+ case "title":
399
+ jsonSchema.title = valibotAction.title;
400
+ break;
401
+ case "url":
402
+ jsonSchema.format = "uri";
403
+ break;
404
+ case "uuid":
405
+ jsonSchema.format = "uuid";
406
+ break;
407
+ case "value":
408
+ if (!isJsonConstValue(valibotAction.requirement)) {
409
+ errors = addError(errors, 'The requirement of the "value" action is not JSON compatible.');
410
+ break;
411
+ }
412
+ if (config?.target === "openapi-3.0") intersectEnum(jsonSchema, [valibotAction.requirement]);
413
+ else if ("const" in jsonSchema && jsonSchema.const !== valibotAction.requirement) errors = addError(errors, `The "${valibotAction.type}" action is not supported in combination with a different "const" restriction.`);
414
+ else jsonSchema.const = valibotAction.requirement;
415
+ break;
416
+ case "values":
417
+ if (!isJsonEnumValues(valibotAction.requirement)) {
418
+ errors = addError(errors, 'A requirement of the "values" action is not JSON compatible.');
419
+ break;
420
+ }
421
+ intersectEnum(jsonSchema, valibotAction.requirement);
422
+ break;
423
+ default:
424
+ errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`);
425
+ }
426
+ if (config?.overrideAction) {
427
+ const actionOverride = config.overrideAction({
428
+ valibotAction,
429
+ jsonSchema,
430
+ errors
431
+ });
432
+ if (actionOverride) return { ...actionOverride };
433
+ }
434
+ if (errors) for (const message of errors) handleError(message, config);
435
+ return jsonSchema;
436
+ }
437
+ __name(convertAction, "convertAction");
438
+ function flattenPipe(pipe2) {
439
+ return pipe2.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item);
440
+ }
441
+ __name(flattenPipe, "flattenPipe");
442
+ function getDefinitionRef(referenceId) {
443
+ return `#/$defs/${referenceId.replaceAll("~", "~0").replaceAll("/", "~1")}`;
444
+ }
445
+ __name(getDefinitionRef, "getDefinitionRef");
446
+ function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) {
447
+ if (!skipRef) {
448
+ const referenceId = context.referenceMap.get(valibotSchema);
449
+ if (referenceId) {
450
+ jsonSchema.$ref = getDefinitionRef(referenceId);
451
+ if (config?.overrideRef) {
452
+ const refOverride = config.overrideRef({
453
+ ...context,
454
+ referenceId,
455
+ valibotSchema,
456
+ jsonSchema
457
+ });
458
+ if (refOverride) jsonSchema.$ref = refOverride;
459
+ }
460
+ return jsonSchema;
461
+ }
462
+ }
463
+ if ("pipe" in valibotSchema) {
464
+ const flatPipe = flattenPipe(valibotSchema.pipe);
465
+ let startIndex = 0;
466
+ let stopIndex = flatPipe.length - 1;
467
+ if (config?.typeMode === "input") {
468
+ const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "to_bigint" || item.type === "to_boolean" || item.type === "to_date" || item.type === "to_number" || item.type === "to_string" || item.type === "transform"));
469
+ if (inputStopIndex !== -1) stopIndex = inputStopIndex;
470
+ } else if (config?.typeMode === "output") {
471
+ const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema");
472
+ if (outputStartIndex !== -1) startIndex = outputStartIndex;
473
+ }
474
+ for (let index = startIndex; index <= stopIndex; index++) {
475
+ const valibotPipeItem = flatPipe[index];
476
+ if (valibotPipeItem.kind === "schema") {
477
+ if (index > startIndex) handleError('Set the "typeMode" config to "input" or "output" to convert pipelines with multiple schemas.', config);
478
+ jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true);
479
+ } else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config);
480
+ }
481
+ return jsonSchema;
482
+ }
483
+ let errors;
484
+ switch (valibotSchema.type) {
485
+ case "boolean":
486
+ jsonSchema.type = "boolean";
487
+ break;
488
+ case "null":
489
+ if (config?.target === "openapi-3.0") jsonSchema.enum = [null];
490
+ else jsonSchema.type = "null";
491
+ break;
492
+ case "number":
493
+ jsonSchema.type = "number";
494
+ break;
495
+ case "string":
496
+ jsonSchema.type = "string";
497
+ break;
498
+ case "array":
499
+ jsonSchema.type = "array";
500
+ jsonSchema.items = convertSchema({}, valibotSchema.item, config, context);
501
+ break;
502
+ case "tuple":
503
+ case "tuple_with_rest":
504
+ case "loose_tuple":
505
+ case "strict_tuple":
506
+ jsonSchema.type = "array";
507
+ if (config?.target === "openapi-3.0") {
508
+ jsonSchema.items = { anyOf: [] };
509
+ jsonSchema.minItems = valibotSchema.items.length;
510
+ for (const item of valibotSchema.items) jsonSchema.items.anyOf.push(convertSchema({}, item, config, context));
511
+ if (valibotSchema.type === "tuple_with_rest") jsonSchema.items.anyOf.push(convertSchema({}, valibotSchema.rest, config, context));
512
+ else if (valibotSchema.type === "strict_tuple" || valibotSchema.type === "tuple") jsonSchema.maxItems = valibotSchema.items.length;
513
+ } else if (config?.target === "draft-2020-12") {
514
+ jsonSchema.prefixItems = [];
515
+ jsonSchema.minItems = valibotSchema.items.length;
516
+ for (const item of valibotSchema.items) jsonSchema.prefixItems.push(convertSchema({}, item, config, context));
517
+ if (valibotSchema.type === "tuple_with_rest") jsonSchema.items = convertSchema({}, valibotSchema.rest, config, context);
518
+ else if (valibotSchema.type === "strict_tuple") jsonSchema.items = false;
519
+ } else {
520
+ jsonSchema.items = [];
521
+ jsonSchema.minItems = valibotSchema.items.length;
522
+ for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context));
523
+ if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context);
524
+ else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false;
525
+ }
526
+ break;
527
+ case "object":
528
+ case "object_with_rest":
529
+ case "loose_object":
530
+ case "strict_object":
531
+ jsonSchema.type = "object";
532
+ jsonSchema.properties = {};
533
+ jsonSchema.required = [];
534
+ for (const key in valibotSchema.entries) {
535
+ const entry = valibotSchema.entries[key];
536
+ jsonSchema.properties[key] = convertSchema({}, entry, config, context);
537
+ if (entry.type !== "exact_optional" && entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key);
538
+ }
539
+ if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context);
540
+ else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false;
541
+ break;
542
+ case "record":
543
+ if (config?.target === "openapi-3.0" && "pipe" in valibotSchema.key) errors = addError(errors, 'The "record" schema with a schema for the key that contains a "pipe" cannot be converted to JSON Schema.');
544
+ if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`);
545
+ jsonSchema.type = "object";
546
+ if (config?.target !== "openapi-3.0") jsonSchema.propertyNames = convertSchema({}, valibotSchema.key, config, context);
547
+ jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context);
548
+ break;
549
+ case "any":
550
+ case "unknown":
551
+ break;
552
+ case "never":
553
+ jsonSchema.not = {};
554
+ break;
555
+ case "nullable":
556
+ case "nullish":
557
+ if (config?.target === "openapi-3.0") {
558
+ const innerSchema = convertSchema({}, valibotSchema.wrapped, config, context);
559
+ Object.assign(jsonSchema, innerSchema);
560
+ jsonSchema.nullable = true;
561
+ } else jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }];
562
+ if (valibotSchema.default !== void 0) jsonSchema.default = typeof valibotSchema.default === "function" ? valibotSchema.default() : valibotSchema.default;
563
+ break;
564
+ case "exact_optional":
565
+ case "optional":
566
+ case "undefinedable":
567
+ jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context);
568
+ if (valibotSchema.default !== void 0) jsonSchema.default = typeof valibotSchema.default === "function" ? valibotSchema.default() : valibotSchema.default;
569
+ break;
570
+ case "literal":
571
+ if (!isJsonConstValue(valibotSchema.literal)) {
572
+ errors = addError(errors, 'The value of the "literal" schema is not JSON compatible.');
573
+ break;
574
+ }
575
+ if (config?.target === "openapi-3.0") jsonSchema.enum = [valibotSchema.literal];
576
+ else jsonSchema.const = valibotSchema.literal;
577
+ break;
578
+ case "enum":
579
+ case "picklist": {
580
+ const options = valibotSchema.options;
581
+ if (!options.every((option) => typeof option === "string" || typeof option === "number" && Number.isFinite(option))) {
582
+ errors = addError(errors, `An option of the "${valibotSchema.type}" schema is not JSON compatible.`);
583
+ break;
584
+ }
585
+ jsonSchema.enum = options;
586
+ if (options.every((option) => typeof option === "string")) jsonSchema.type = "string";
587
+ else if (options.every((option) => typeof option === "number")) jsonSchema.type = "number";
588
+ else if (config?.target !== "openapi-3.0") jsonSchema.type = ["string", "number"];
589
+ break;
590
+ }
591
+ case "union":
592
+ jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
593
+ break;
594
+ case "variant":
595
+ jsonSchema.oneOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
596
+ break;
597
+ case "intersect":
598
+ jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
599
+ break;
600
+ case "lazy": {
601
+ let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter);
602
+ if (!wrappedValibotSchema) {
603
+ wrappedValibotSchema = valibotSchema.getter(void 0);
604
+ context.getterMap.set(valibotSchema.getter, wrappedValibotSchema);
605
+ }
606
+ let referenceId = context.referenceMap.get(wrappedValibotSchema);
607
+ if (!referenceId) {
608
+ referenceId = context.referenceMap.createId(context.definitions);
609
+ context.referenceMap.set(wrappedValibotSchema, referenceId);
610
+ context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true);
611
+ }
612
+ jsonSchema.$ref = getDefinitionRef(referenceId);
613
+ if (config?.overrideRef) {
614
+ const refOverride = config.overrideRef({
615
+ ...context,
616
+ referenceId,
617
+ valibotSchema: wrappedValibotSchema,
618
+ jsonSchema
619
+ });
620
+ if (refOverride) jsonSchema.$ref = refOverride;
621
+ }
622
+ break;
623
+ }
624
+ default:
625
+ errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`);
626
+ }
627
+ if (config?.overrideSchema) {
628
+ const schemaOverride = config.overrideSchema({
629
+ ...context,
630
+ referenceId: context.referenceMap.get(valibotSchema),
631
+ valibotSchema,
632
+ jsonSchema,
633
+ errors
634
+ });
635
+ if (schemaOverride) return { ...schemaOverride };
636
+ }
637
+ if (errors) for (const message of errors) handleError(message, config);
638
+ return jsonSchema;
639
+ }
640
+ __name(convertSchema, "convertSchema");
641
+ var store;
642
+ function getGlobalDefs() {
643
+ return store;
644
+ }
645
+ __name(getGlobalDefs, "getGlobalDefs");
646
+ function toJsonSchema(schema, config) {
647
+ const context = {
648
+ definitions: {},
649
+ referenceMap: new ReferenceMap(),
650
+ getterMap: /* @__PURE__ */ new Map()
651
+ };
652
+ const definitions = config?.definitions ?? getGlobalDefs();
653
+ if (definitions) {
654
+ for (const key in definitions) context.referenceMap.set(definitions[key], key);
655
+ for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true);
656
+ }
657
+ const jsonSchema = convertSchema({}, schema, config, context);
658
+ const target = config?.target ?? "draft-07";
659
+ if (target === "draft-2020-12") jsonSchema.$schema = "https://json-schema.org/draft/2020-12/schema";
660
+ else if (target === "draft-07") jsonSchema.$schema = "http://json-schema.org/draft-07/schema#";
661
+ if (context.referenceMap.size) jsonSchema.$defs = context.definitions;
662
+ return jsonSchema;
663
+ }
664
+ __name(toJsonSchema, "toJsonSchema");
665
+ var SUPPORTED_TARGETS = [
666
+ "draft-07",
667
+ "draft-2020-12",
668
+ "openapi-3.0"
669
+ ];
670
+ function toStandardJsonSchema(schema) {
671
+ return { "~standard": {
672
+ ...schema["~standard"],
673
+ jsonSchema: {
674
+ input(options) {
675
+ if (SUPPORTED_TARGETS.includes(options.target)) return toJsonSchema(schema, {
676
+ typeMode: "input",
677
+ target: options.target,
678
+ ...options.libraryOptions
679
+ });
680
+ throw new Error(`Unsupported target: ${options.target}`);
681
+ },
682
+ output(options) {
683
+ if (SUPPORTED_TARGETS.includes(options.target)) return toJsonSchema(schema, {
684
+ typeMode: "output",
685
+ target: options.target,
686
+ ...options.libraryOptions
687
+ });
688
+ throw new Error(`Unsupported target: ${options.target}`);
689
+ }
690
+ }
691
+ } };
692
+ }
693
+ __name(toStandardJsonSchema, "toStandardJsonSchema");
694
+
695
+ // node_modules/.pnpm/@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_commander@15.0.0_esbuild@0.28._2fe0e09d29eda9827e2087fd1a1cce67/node_modules/@wirecat/cli-base/dist/standards/registry.js
696
+ var word = pipe(string(), regex(/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/, "a lower-case word, words joined by -"));
697
+ var SNAKE_CASE = /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/;
698
+ var text = pipe(string(), regex(/\S/, "must not be empty"));
699
+ var dottedId = pipe(string(), regex(/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/, "dotted lower-case words, such as `page.next`"));
700
+ var RegistryError = class extends Error {
701
+ static {
702
+ __name(this, "RegistryError");
703
+ }
704
+ registry;
705
+ problems;
706
+ constructor(registry, problems) {
707
+ super(`${registry} registry: ${problems.join("; ")}`);
708
+ this.registry = registry;
709
+ this.problems = problems;
710
+ this.name = "RegistryError";
711
+ }
712
+ };
713
+ var issuesOf = /* @__PURE__ */ __name((issues) => issues.map((issue) => {
714
+ const path = getDotPath(issue);
715
+ return path ? `${path}: ${issue.message}` : issue.message;
716
+ }), "issuesOf");
717
+ var parseRegistry = /* @__PURE__ */ __name((registry, schema, input, check = () => []) => {
718
+ const parsed = safeParse(schema, input);
719
+ if (!parsed.success)
720
+ throw new RegistryError(registry, issuesOf(parsed.issues));
721
+ const problems = check(parsed.output);
722
+ if (problems.length > 0)
723
+ throw new RegistryError(registry, problems);
724
+ return parsed.output;
725
+ }, "parseRegistry");
726
+ var duplicates = /* @__PURE__ */ __name((values) => [...new Set(values.filter((value, index) => values.indexOf(value) !== index))].sort(), "duplicates");
727
+ var jsonSchemaOf = /* @__PURE__ */ __name((schema, definitions) => toJsonSchema(schema, { target: "draft-2020-12", ...definitions ? { definitions } : {} }), "jsonSchemaOf");
728
+ var PLACEHOLDER = /\{([a-z][a-z0-9]*(?:_[a-z0-9]+)*)\}/g;
729
+ var placeholders = /* @__PURE__ */ __name((template) => [...template.matchAll(PLACEHOLDER)].map((match) => match[1] ?? ""), "placeholders");
730
+ var fill = /* @__PURE__ */ __name((template, values) => template.replace(PLACEHOLDER, (_, name) => {
731
+ const value = values[name];
732
+ if (value === void 0)
733
+ throw new Error(`no value for {${name}} in "${template}"`);
734
+ return String(value);
735
+ }), "fill");
736
+
737
+ // node_modules/.pnpm/@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_commander@15.0.0_esbuild@0.28._2fe0e09d29eda9827e2087fd1a1cce67/node_modules/@wirecat/cli-base/dist/standards/output.js
738
+ var MAX_NEXT_STEPS = 2;
739
+ var COMPACT_FLAG = "--compact";
740
+ var isoTime = pipe(string(), isoTimestamp("an ISO 8601 time in UTC"), endsWith("Z", "an ISO 8601 time in UTC, ending in `Z`"));
741
+ var localTime = pipe(string(), regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}[+-]\d{2}:\d{2}$/, "an ISO 8601 time with its offset"));
742
+ var reference = pipe(string(), regex(/^[a-z]+:\S+$/, "a reference such as `note:42`"));
743
+ var nextStepSchema = variant("kind", [
744
+ strictObject({
745
+ kind: literal("command"),
746
+ step: dottedId,
747
+ /** The command path as one string, `messages list` — what the MCP router tools take as `command`. */
748
+ command: text,
749
+ args: record(string(), unknown()),
750
+ /**
751
+ * The whole line to type, with the tool and the profile it ran with: `tg personal mcp config`. Only the CLI
752
+ * knows the profile, so it fills this; MCP answers leave it out.
753
+ */
754
+ line: optional(text),
755
+ why: text,
756
+ /** True only when the target command is known to write nothing, here or at the provider. */
757
+ safe_to_auto_execute: boolean()
758
+ }),
759
+ /** Something only the person can do — sign in on the phone, approve a device. */
760
+ strictObject({
761
+ kind: literal("user_action"),
762
+ step: dottedId,
763
+ why: text,
764
+ safe_to_auto_execute: literal(false)
765
+ })
766
+ ]);
767
+ var missingSchema = strictObject({
768
+ field: text,
769
+ why: text,
770
+ /** Left out when there is nothing to run that would fill the field. */
771
+ step: optional(dottedId)
772
+ });
773
+ var limit = pipe(number(), integer(), minValue(1));
774
+ var totalSchema = strictObject({
775
+ value: pipe(number(), integer(), minValue(0)),
776
+ relation: picklist(["eq", "gte"])
777
+ });
778
+ var pageSchema = variant("mode", [
779
+ strictObject({
780
+ mode: literal("page"),
781
+ limit,
782
+ has_more: boolean(),
783
+ next_page: optional(pipe(number(), integer(), minValue(2))),
784
+ total: optional(totalSchema)
785
+ }),
786
+ strictObject({
787
+ mode: literal("cursor"),
788
+ limit,
789
+ has_more: boolean(),
790
+ next_cursor: optional(text),
791
+ total: optional(totalSchema)
792
+ })
793
+ ]);
794
+ var issueSchema = strictObject({
795
+ code: picklist(errorCodes),
796
+ reason: optional(dottedId),
797
+ /** The account, provider or source that is missing from the answer. */
798
+ source: text
799
+ });
800
+ var rankingSchema = strictObject({
801
+ applied: boolean(),
802
+ reason_id: optional(dottedId),
803
+ provider: text,
804
+ model: text,
805
+ endpoint: text,
806
+ sent: pipe(number(), integer(), minValue(0)),
807
+ cost_usd: nullable(pipe(number(), minValue(0))),
808
+ usage: optional(strictObject({
809
+ input: pipe(number(), integer(), minValue(0)),
810
+ output: pipe(number(), integer(), minValue(0))
811
+ })),
812
+ ms: pipe(number(), integer(), minValue(0))
813
+ });
814
+ var querySchema = strictObject({
815
+ chat: optional(strictObject({ word: text, chat_id: text, title: nullable(text) })),
816
+ respelled: optional(array(strictObject({ word: text, tried: pipe(array(text), minLength(1)) })))
817
+ });
818
+ var metaSchema = strictObject({
819
+ run_id: text,
820
+ duration_ms: pipe(number(), integer(), minValue(0)),
821
+ accounts: optional(array(text)),
822
+ complete: boolean(),
823
+ issues: optional(array(issueSchema)),
824
+ truncated: optional(boolean()),
825
+ timezone: optional(text),
826
+ /** When the command answered, for an agent that plans from "now" (WC-TIME-7); `timezone` names the zone of `now_local`. */
827
+ now: optional(isoTime),
828
+ now_local: optional(localTime),
829
+ window: optional(strictObject({ since: optional(isoTime), until: optional(isoTime) })),
830
+ ranking: optional(rankingSchema),
831
+ query: optional(querySchema)
832
+ });
833
+ var offsetOf = /* @__PURE__ */ __name((at, zone) => {
834
+ const name = new Intl.DateTimeFormat("en-US", { timeZone: zone, timeZoneName: "longOffset" }).formatToParts(at).find((part) => part.type === "timeZoneName")?.value ?? "GMT";
835
+ return name === "GMT" ? "+00:00" : name.slice(3);
836
+ }, "offsetOf");
837
+ var clockMeta = /* @__PURE__ */ __name((at, zone) => {
838
+ const offset = offsetOf(at, zone);
839
+ const sign = offset.startsWith("-") ? -1 : 1;
840
+ const [hours = 0, minutes = 0] = offset.slice(1).split(":").map(Number);
841
+ const wall = new Date(at + sign * (hours * 60 + minutes) * 6e4).toISOString().slice(0, -1);
842
+ return { now: new Date(at).toISOString(), now_local: `${wall}${offset}`, timezone: zone };
843
+ }, "clockMeta");
844
+ var nextSteps = optional(pipe(array(nextStepSchema), maxLength(MAX_NEXT_STEPS)));
845
+ var listEnvelopeSchema = /* @__PURE__ */ __name((item) => strictObject({
846
+ items: array(item),
847
+ page: pageSchema,
848
+ next: nextSteps,
849
+ missing: optional(array(missingSchema)),
850
+ meta: metaSchema
851
+ }), "listEnvelopeSchema");
852
+ var itemEnvelopeSchema = /* @__PURE__ */ __name((item) => strictObject({
853
+ item,
854
+ next: nextSteps,
855
+ missing: optional(array(missingSchema)),
856
+ meta: metaSchema
857
+ }), "itemEnvelopeSchema");
858
+ var jsonlEndSchema = strictObject({
859
+ type: literal("end"),
860
+ complete: boolean(),
861
+ issues: optional(array(issueSchema)),
862
+ page: pageSchema
863
+ });
864
+ var jsonlOf = /* @__PURE__ */ __name(({ items, page, meta }) => [
865
+ ...items.map((data) => JSON.stringify({ type: "item", data })),
866
+ JSON.stringify({ type: "end", complete: meta.complete, ...meta.issues ? { issues: meta.issues } : {}, page })
867
+ ].join("\n"), "jsonlOf");
868
+
869
+ // node_modules/.pnpm/@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_commander@15.0.0_esbuild@0.28._2fe0e09d29eda9827e2087fd1a1cce67/node_modules/@wirecat/cli-base/dist/standards/errors.js
870
+ var CRASH_CODE = "internal_error";
871
+ var CRASH_REASON = "command.crashed";
872
+ var errorObjectSchema = strictObject({
873
+ error: strictObject({
874
+ code: picklist([...errorCodes, CRASH_CODE]),
875
+ reason: dottedId,
876
+ message: text,
877
+ /** The option or argument at fault. */
878
+ param: optional(text),
879
+ details: optional(record(string(), unknown())),
880
+ next: optional(pipe(array(nextStepSchema), maxLength(MAX_NEXT_STEPS))),
881
+ /** Whether running the same command again may work and cannot do harm; never for a write that may have landed. */
882
+ retry: strictObject({
883
+ safe: boolean(),
884
+ after_ms: optional(pipe(number(), integer(), minValue(0)))
885
+ }),
886
+ /** Optional until every CLI keeps a run for each failure. */
887
+ run_id: optional(text)
888
+ })
889
+ });
890
+ var reasonSchema = strictObject({
891
+ reason: dottedId,
892
+ code: picklist([...errorCodes, CRASH_CODE]),
893
+ /** `{name}` placeholders, each one of `details`. */
894
+ message: pipe(text, maxLength(120)),
895
+ details: array(pipe(string(), regex(SNAKE_CASE, "a snake_case key"))),
896
+ step: optional(dottedId)
897
+ });
898
+ var defineReasons = /* @__PURE__ */ __name((input) => parseRegistry("error reasons", array(reasonSchema), input, (reasons) => [
899
+ ...duplicates(reasons.map((entry) => entry.reason)).map((reason) => `"${reason}" is listed twice`),
900
+ ...reasons.flatMap((entry) => placeholders(entry.message).filter((name) => !entry.details.includes(name)).map((name) => `${entry.reason}: the message names {${name}}, which is not one of its details`))
901
+ ]), "defineReasons");
902
+ var COMMON_DETAILS = ["attempts", "status", "request_id", "operation", "operation_id"];
903
+ var BASE_REASONS = defineReasons([
904
+ { reason: "input.invalid", code: "validation_error", message: "the input is not valid", details: [] },
905
+ {
906
+ reason: "batch.read-budget",
907
+ code: "validation_error",
908
+ message: "batch stored-text read budget exhausted",
909
+ details: []
910
+ },
911
+ { reason: "batch.output-budget", code: "validation_error", message: "batch output budget exhausted", details: [] },
912
+ { reason: "config.invalid", code: "configuration_error", message: "the configuration is not valid", details: [] },
913
+ {
914
+ reason: "keyring.unreachable",
915
+ code: "configuration_error",
916
+ message: "the OS keyring did not answer, and no file holds the sign-in",
917
+ details: []
918
+ },
919
+ { reason: "auth.failed", code: "authentication_error", message: "the sign-in did not work", details: [] },
920
+ { reason: "access.denied", code: "permission_error", message: "this account may not do that", details: [] },
921
+ { reason: "item.not-found", code: "not_found", message: "nothing found by that name", details: [] },
922
+ {
923
+ reason: "tool.not-installed",
924
+ code: "not_found",
925
+ message: "no wcat-<name> program by that name is on PATH",
926
+ details: ["tool", "installed"]
927
+ },
928
+ {
929
+ reason: "confirmation.required",
930
+ code: "confirmation_required",
931
+ message: "this changes something; confirm it",
932
+ details: []
933
+ },
934
+ { reason: "provider.rate-limited", code: "rate_limited", message: "too many requests; wait", details: [] },
935
+ { reason: "command.timed-out", code: "timeout", message: "the command took too long", details: ["timeout_ms"] },
936
+ { reason: "network.failed", code: "network_error", message: "the network did not answer", details: [] },
937
+ { reason: "provider.refused", code: "provider_error", message: "the provider refused", details: [] },
938
+ { reason: "provider.unavailable", code: "provider_unavailable", message: "the provider is down", details: [] },
939
+ {
940
+ reason: "provider.invalid-response",
941
+ code: "invalid_response",
942
+ message: "the answer could not be read",
943
+ details: []
944
+ },
945
+ {
946
+ reason: "output.too-large",
947
+ code: "invalid_response",
948
+ message: "the output is over {max_bytes} bytes",
949
+ details: ["max_bytes", "buffered_bytes", "partial_output"]
950
+ },
951
+ {
952
+ reason: "output.fields-unavailable",
953
+ code: "invalid_response",
954
+ message: "fields can be picked only from whole JSON values",
955
+ details: []
956
+ },
957
+ { reason: "outcome.unknown", code: "outcome_unknown", message: "it is not known whether it worked", details: [] },
958
+ {
959
+ reason: "write.conflict",
960
+ code: "conflict",
961
+ message: "it changed since it was read; read it again",
962
+ details: []
963
+ },
964
+ { reason: "command.cancelled", code: "cancelled", message: "the command was cancelled", details: [] },
965
+ { reason: CRASH_REASON, code: CRASH_CODE, message: "the command failed; this is a bug", details: [] }
966
+ ]);
967
+
968
+ // node_modules/.pnpm/@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_commander@15.0.0_esbuild@0.28._2fe0e09d29eda9827e2087fd1a1cce67/node_modules/@wirecat/cli-base/dist/standards/steps.js
969
+ var SAME_COMMAND = "*";
970
+ var commandPath = pipe(string(), regex(/^[a-z][a-z0-9-]*( [a-z][a-z0-9-]*)*$/, "a command path such as `messages sync`"));
971
+ var stepSchema = union([
972
+ strictObject({
973
+ id: dottedId,
974
+ kind: optional(literal("command"), "command"),
975
+ command: union([literal(SAME_COMMAND), commandPath]),
976
+ args: array(strictObject({
977
+ name: pipe(string(), regex(SNAKE_CASE, "an argument or option name in snake_case")),
978
+ required: boolean()
979
+ })),
980
+ why: pipe(text, maxLength(120))
981
+ }),
982
+ strictObject({ id: dottedId, kind: literal("user_action"), why: pipe(text, maxLength(120)) })
983
+ ]);
984
+ var argsOf = /* @__PURE__ */ __name((step) => step.kind === "command" ? step.args : [], "argsOf");
985
+ var defineSteps = /* @__PURE__ */ __name((input) => parseRegistry("steps", array(stepSchema), input, (steps) => [
986
+ ...duplicates(steps.map((step) => step.id)).map((id) => `"${id}" is listed twice`),
987
+ ...steps.flatMap((step) => duplicates(argsOf(step).map((arg) => arg.name)).map((name) => `${step.id}: argument "${name}" is listed twice`))
988
+ ]), "defineSteps");
989
+ var BINDS = /^[^\p{Cc}\u2028\u2029]*$/u;
990
+ var binds = /* @__PURE__ */ __name((value) => typeof value === "number" || typeof value === "boolean" || typeof value === "string" && BINDS.test(value), "binds");
991
+ var stepOf = /* @__PURE__ */ __name((definition, input = {}) => {
992
+ const args = input.args ?? {};
993
+ if (definition.kind === "user_action")
994
+ return {
995
+ kind: "user_action",
996
+ step: definition.id,
997
+ why: fill(definition.why, { ...input.values }),
998
+ safe_to_auto_execute: false
999
+ };
1000
+ const command = definition.command === SAME_COMMAND ? input.command : definition.command;
1001
+ if (!command)
1002
+ throw new Error(`${definition.id}: the step runs the same command, so pass the command`);
1003
+ const known = new Set(definition.args.map((arg) => arg.name));
1004
+ if (definition.command !== SAME_COMMAND) {
1005
+ for (const name of Object.keys(args))
1006
+ if (!known.has(name))
1007
+ throw new Error(`${definition.id}: no argument "${name}"`);
1008
+ }
1009
+ for (const arg of definition.args)
1010
+ if (arg.required && args[arg.name] === void 0)
1011
+ throw new Error(`${definition.id}: argument "${arg.name}" is required`);
1012
+ for (const [name, value] of Object.entries(args))
1013
+ if (!(Array.isArray(value) ? value.every(binds) : binds(value)))
1014
+ throw new Error(`${definition.id}: "${name}" is not a value an option takes`);
1015
+ const target = input.targets?.(command);
1016
+ if (input.targets && !target)
1017
+ throw new Error(`${definition.id}: no command "${command}"`);
1018
+ const names = new Set(target?.names ?? []);
1019
+ if (target) {
1020
+ for (const name of Object.keys(args))
1021
+ if (!names.has(name))
1022
+ throw new Error(`${definition.id}: "${command}" takes no "${name}"`);
1023
+ }
1024
+ const scalars = Object.fromEntries(Object.entries(args).filter((entry) => ["string", "number"].includes(typeof entry[1])));
1025
+ return {
1026
+ kind: "command",
1027
+ step: definition.id,
1028
+ command,
1029
+ args: { ...args },
1030
+ why: fill(definition.why, { ...scalars, ...input.values }),
1031
+ safe_to_auto_execute: target?.effects !== void 0 && !writes(target.effects)
1032
+ };
1033
+ }, "stepOf");
1034
+ var STEPS = defineSteps([
1035
+ {
1036
+ id: "page.next",
1037
+ command: SAME_COMMAND,
1038
+ args: [
1039
+ { name: "cursor", required: false },
1040
+ { name: "page", required: false },
1041
+ { name: "limit", required: false }
1042
+ ],
1043
+ why: "{shown} shown, more exist"
1044
+ }
1045
+ ]);
1046
+
1047
+ // node_modules/.pnpm/@wirecat+cli-base@0.110.0_@scalar+openapi-upgrader@0.4.6_commander@15.0.0_esbuild@0.28._2fe0e09d29eda9827e2087fd1a1cce67/node_modules/@wirecat/cli-base/dist/failure.js
1048
+ var recognise = /* @__PURE__ */ __name((failure) => {
1049
+ if (isCliError(failure))
1050
+ return failure;
1051
+ if (!(failure instanceof Error) || failure.name !== "CliError")
1052
+ return void 0;
1053
+ const { code, details } = failure;
1054
+ if (!errorCodes.includes(code))
1055
+ return void 0;
1056
+ return {
1057
+ code,
1058
+ message: failure.message,
1059
+ details: typeof details === "object" && details !== null ? details : {}
1060
+ };
1061
+ }, "recognise");
1062
+ var reasonFor = /* @__PURE__ */ __name((code, named, reasons) => reasons.find((entry) => entry.reason === named && entry.code === code) ?? BASE_REASONS.find((entry) => entry.reason === named && entry.code === code) ?? // The first base reason for each code is its fallback.
1063
+ BASE_REASONS.find((entry) => entry.code === code), "reasonFor");
1064
+ var nextFor = /* @__PURE__ */ __name((reason, details, context) => {
1065
+ const definition = reason.step ? context.steps?.find((step) => step.id === reason.step) : void 0;
1066
+ if (!definition)
1067
+ return [];
1068
+ const known = new Set(definition.kind === "command" ? definition.args.map((arg) => arg.name) : []);
1069
+ const args = Object.fromEntries(Object.entries(details).filter(([key, value]) => known.has(key) && value !== void 0));
1070
+ try {
1071
+ return [stepOf(definition, { args, ...context.targets ? { targets: context.targets } : {} })];
1072
+ } catch {
1073
+ return [];
1074
+ }
1075
+ }, "nextFor");
1076
+ var TRANSIENT = [
1077
+ "rate_limited",
1078
+ "timeout",
1079
+ "network_error",
1080
+ "provider_unavailable"
1081
+ ];
1082
+ var retryOf = /* @__PURE__ */ __name((code, details, effects) => {
1083
+ const transient = details.retryable !== false && (TRANSIENT.includes(code) || code === "provider_error" && details.retryable === true);
1084
+ const safe = code !== "outcome_unknown" && transient && (!writes(effects) || details.sent === false);
1085
+ const after = details.retry_after_ms;
1086
+ return safe && typeof after === "number" && Number.isInteger(after) && after >= 0 ? { safe, after_ms: after } : { safe };
1087
+ }, "retryOf");
1088
+ var errorObjectOf = /* @__PURE__ */ __name((failure, context = {}) => {
1089
+ const reasons = context.reasons ?? [];
1090
+ const recognised = recognise(failure);
1091
+ if (!recognised) {
1092
+ const reason2 = reasonFor(CRASH_CODE, CRASH_REASON, reasons);
1093
+ return {
1094
+ error: {
1095
+ code: CRASH_CODE,
1096
+ reason: reason2.reason,
1097
+ message: reason2.message,
1098
+ retry: { safe: false },
1099
+ ...context.runId ? { run_id: context.runId } : {}
1100
+ }
1101
+ };
1102
+ }
1103
+ const { code, message, details } = recognised;
1104
+ const reason = reasonFor(code, details.reason, reasons);
1105
+ const allowed = /* @__PURE__ */ new Set([...COMMON_DETAILS, ...context.details ?? [], ...reason.details]);
1106
+ allowed.delete("cause");
1107
+ const kept = Object.fromEntries(Object.entries(details).filter(([key, value]) => allowed.has(key) && value !== void 0));
1108
+ const next = nextFor(reason, details, context);
1109
+ const runId = context.runId ?? (typeof details.run_id === "string" ? details.run_id : void 0);
1110
+ return {
1111
+ error: {
1112
+ code,
1113
+ reason: reason.reason,
1114
+ message,
1115
+ ...typeof details.param === "string" ? { param: details.param } : {},
1116
+ ...Object.keys(kept).length > 0 ? { details: kept } : {},
1117
+ ...next.length > 0 ? { next } : {},
1118
+ retry: retryOf(code, details, context.effects),
1119
+ ...runId ? { run_id: runId } : {}
1120
+ }
1121
+ };
1122
+ }, "errorObjectOf");
1123
+ var exitCodeOfError = /* @__PURE__ */ __name(({ error }) => error.code === CRASH_CODE ? GENERIC_FAILURE : EXIT_CODES[error.code], "exitCodeOfError");
1124
+ var exitCodeOfAnswer = /* @__PURE__ */ __name((meta, partial = false) => {
1125
+ if (meta.complete || partial)
1126
+ return 0;
1127
+ const code = meta.issues?.[0]?.code;
1128
+ return code === void 0 ? GENERIC_FAILURE : EXIT_CODES[code];
1129
+ }, "exitCodeOfAnswer");
1130
+ var kebab = /* @__PURE__ */ __name((name) => name.replaceAll("_", "-"), "kebab");
1131
+ var commandLine = /* @__PURE__ */ __name((cli, step) => [
1132
+ cli,
1133
+ step.command,
1134
+ ...Object.entries(step.args).map(([name, value]) => value === true ? `--${kebab(name)}` : `--${kebab(name)} ${JSON.stringify(value)}`)
1135
+ ].join(" "), "commandLine");
1136
+ var STACK_FRAMES = 10;
1137
+ var errorRecordOf = /* @__PURE__ */ __name((failure, object, options) => {
1138
+ const thrown = failure instanceof Error ? failure : void 0;
1139
+ const { cause, ...details } = recognise(failure)?.details ?? {};
1140
+ const stack = thrown?.stack?.split("\n").slice(1, STACK_FRAMES + 1).map((line) => visibleControls(line.trim()));
1141
+ const reason = thrown?.cause ?? cause;
1142
+ return {
1143
+ time: (options.time ?? /* @__PURE__ */ new Date()).toISOString(),
1144
+ severity: "error",
1145
+ body: "command.failed",
1146
+ ...object.error.run_id ? { run_id: object.error.run_id } : {},
1147
+ command: options.command,
1148
+ attributes: {
1149
+ code: object.error.code,
1150
+ reason: object.error.reason,
1151
+ message: object.error.message,
1152
+ ...Object.keys(details).length > 0 ? { details } : {},
1153
+ ...thrown ? { name: thrown.name, thrown_message: visibleControls(thrown.message) } : { thrown: String(failure) },
1154
+ ...reason === void 0 ? {} : { cause: visibleControls(reason instanceof Error ? reason.message : String(reason)) },
1155
+ ...stack && stack.length > 0 ? { stack } : {}
1156
+ },
1157
+ resource: { service: options.service, version: options.version }
1158
+ };
1159
+ }, "errorRecordOf");
1160
+ var renderError = /* @__PURE__ */ __name((object, options) => {
1161
+ if (!options.interactive)
1162
+ return [JSON.stringify(object), ...options.record ? [JSON.stringify(options.record)] : []].join("\n");
1163
+ const { message, next, run_id: runId } = object.error;
1164
+ const step = next?.[0];
1165
+ return [
1166
+ `\u2717 ${visibleControls(message)}`,
1167
+ ...step?.kind === "command" ? [`\u2192 ${visibleControls(step.why)}: ${visibleControls(step.line ?? commandLine(options.cli, step))}`] : step ? [`\u2192 ${visibleControls(step.why)}`] : [],
1168
+ ...options.record ? [JSON.stringify(options.record, null, 2)] : runId ? [`details: ${options.cli} runs show ${runId}`] : []
1169
+ ].join("\n");
1170
+ }, "renderError");
1171
+ var mcpErrorResult = /* @__PURE__ */ __name((object) => ({
1172
+ content: [{ type: "text", text: JSON.stringify(object) }],
1173
+ structuredContent: object,
1174
+ isError: true
1175
+ }), "mcpErrorResult");
1176
+ var catchCrashes = /* @__PURE__ */ __name((options) => {
1177
+ const target = options.target ?? process;
1178
+ const write = options.write ?? ((text2) => process.stderr.write(`${text2}
1179
+ `));
1180
+ const exit = options.exit ?? ((code) => process.exit(code));
1181
+ const crashed = /* @__PURE__ */ __name((failure) => {
1182
+ const object = errorObjectOf(failure, options);
1183
+ write(renderError(object, { cli: options.cli, interactive: options.interactive }));
1184
+ exit(exitCodeOfError(object));
1185
+ }, "crashed");
1186
+ target.on("uncaughtException", crashed);
1187
+ target.on("unhandledRejection", crashed);
1188
+ return () => {
1189
+ target.off("uncaughtException", crashed);
1190
+ target.off("unhandledRejection", crashed);
1191
+ };
1192
+ }, "catchCrashes");
1193
+
1194
+ export {
1195
+ EXIT_CODES,
1196
+ exitCodeFor,
1197
+ GENERIC_FAILURE,
1198
+ effectsSchema,
1199
+ writes,
1200
+ toJsonSchema,
1201
+ toStandardJsonSchema,
1202
+ word,
1203
+ SNAKE_CASE,
1204
+ text,
1205
+ dottedId,
1206
+ RegistryError,
1207
+ parseRegistry,
1208
+ duplicates,
1209
+ jsonSchemaOf,
1210
+ MAX_NEXT_STEPS,
1211
+ COMPACT_FLAG,
1212
+ isoTime,
1213
+ reference,
1214
+ pageSchema,
1215
+ clockMeta,
1216
+ listEnvelopeSchema,
1217
+ itemEnvelopeSchema,
1218
+ jsonlOf,
1219
+ CRASH_CODE,
1220
+ errorObjectSchema,
1221
+ defineReasons,
1222
+ defineSteps,
1223
+ stepOf,
1224
+ STEPS,
1225
+ retryOf,
1226
+ errorObjectOf,
1227
+ exitCodeOfError,
1228
+ exitCodeOfAnswer,
1229
+ errorRecordOf,
1230
+ renderError,
1231
+ mcpErrorResult,
1232
+ catchCrashes
1233
+ };