@wirecat/attio-cli 0.9.0 → 0.10.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 (206) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/contracts/wirecat.json +1 -0
  3. package/dist/bin/attio.js +11 -11
  4. package/dist/bundle/attio.js +5 -166
  5. package/dist/bundle/{chunk-6E5QWCBK.js → chunk-OGWKDPR5.js} +2 -1
  6. package/dist/bundle/chunk-TQAECZFO.js +13 -0
  7. package/dist/bundle/{definitions-FODOIPM2.js → definitions-J73IBAHT.js} +1 -1
  8. package/dist/bundle/program-NSBWZ25F.js +6201 -0
  9. package/dist/bundle/{schemas-YGSTNU6F.js → schemas-G3HFAS45.js} +576 -29
  10. package/dist/commands/api.js +1 -2
  11. package/dist/commands/crm.js +1 -4
  12. package/dist/commands/schedule.js +1 -1
  13. package/dist/commands/session.js +1 -2
  14. package/dist/config.js +1 -2
  15. package/dist/context.js +1 -1
  16. package/dist/identity.js +1 -0
  17. package/dist/program.js +1 -2
  18. package/dist/version.js +1 -1
  19. package/package.json +3 -3
  20. package/dist/activities.d.ts +0 -4
  21. package/dist/activities.d.ts.map +0 -1
  22. package/dist/activities.js.map +0 -1
  23. package/dist/bin/attio.d.ts +0 -3
  24. package/dist/bin/attio.d.ts.map +0 -1
  25. package/dist/bin/attio.js.map +0 -1
  26. package/dist/bundle/agent-C3SZOGZS.js +0 -38
  27. package/dist/bundle/all-profiles-673VSTRG.js +0 -320
  28. package/dist/bundle/anthropic-V4RZS5XM.js +0 -91
  29. package/dist/bundle/app-server-CTEDPA5H.js +0 -249
  30. package/dist/bundle/bun-F4M4KCNA.js +0 -169
  31. package/dist/bundle/bun-sqlite-33JTNHCK.js +0 -76
  32. package/dist/bundle/chunk-2R2EX5I6.js +0 -54
  33. package/dist/bundle/chunk-5EH7S4RM.js +0 -362
  34. package/dist/bundle/chunk-5N2V6XO7.js +0 -119
  35. package/dist/bundle/chunk-5WY6RURV.js +0 -161
  36. package/dist/bundle/chunk-6V7ZUJI6.js +0 -4072
  37. package/dist/bundle/chunk-AOKAYQSJ.js +0 -2338
  38. package/dist/bundle/chunk-AQ5RIOUE.js +0 -633
  39. package/dist/bundle/chunk-B4DVW2BA.js +0 -185
  40. package/dist/bundle/chunk-C7JPYWYQ.js +0 -77
  41. package/dist/bundle/chunk-D72URWJE.js +0 -532
  42. package/dist/bundle/chunk-DBHZ7TQ7.js +0 -69828
  43. package/dist/bundle/chunk-DFDN6AUB.js +0 -21
  44. package/dist/bundle/chunk-DNCLQPOM.js +0 -7
  45. package/dist/bundle/chunk-DPV53EZC.js +0 -206
  46. package/dist/bundle/chunk-E2L4R6EI.js +0 -388
  47. package/dist/bundle/chunk-EDWRHVHD.js +0 -218
  48. package/dist/bundle/chunk-EH6ZEJGT.js +0 -932
  49. package/dist/bundle/chunk-EV6B3GHM.js +0 -323
  50. package/dist/bundle/chunk-FBWECICU.js +0 -259
  51. package/dist/bundle/chunk-FFER7KJI.js +0 -407
  52. package/dist/bundle/chunk-FTH6WGYO.js +0 -24
  53. package/dist/bundle/chunk-G3PK5BZB.js +0 -1222
  54. package/dist/bundle/chunk-G46PNDWL.js +0 -58
  55. package/dist/bundle/chunk-G6NY7LFB.js +0 -230
  56. package/dist/bundle/chunk-GLU36VKA.js +0 -52
  57. package/dist/bundle/chunk-GZ7WBU5Y.js +0 -18
  58. package/dist/bundle/chunk-HMYBAVIE.js +0 -86
  59. package/dist/bundle/chunk-HOJJPSLU.js +0 -288
  60. package/dist/bundle/chunk-HUAHLO6N.js +0 -29
  61. package/dist/bundle/chunk-ISQ23VKV.js +0 -123
  62. package/dist/bundle/chunk-J2LSOG3A.js +0 -12766
  63. package/dist/bundle/chunk-K5L77R7P.js +0 -66
  64. package/dist/bundle/chunk-KKRFVN4X.js +0 -1835
  65. package/dist/bundle/chunk-KLRCTMES.js +0 -100
  66. package/dist/bundle/chunk-KYRYD4CR.js +0 -38
  67. package/dist/bundle/chunk-L5QLKUQR.js +0 -794
  68. package/dist/bundle/chunk-MFSWMNSZ.js +0 -334
  69. package/dist/bundle/chunk-MYK2F5LD.js +0 -1251
  70. package/dist/bundle/chunk-NBNQLNVV.js +0 -388
  71. package/dist/bundle/chunk-O3DZDITT.js +0 -274
  72. package/dist/bundle/chunk-OEEWVKJX.js +0 -53
  73. package/dist/bundle/chunk-P5XYQZVW.js +0 -80
  74. package/dist/bundle/chunk-P6OJKJJS.js +0 -1197
  75. package/dist/bundle/chunk-P6S3ZRVW.js +0 -106
  76. package/dist/bundle/chunk-PL5P7UKW.js +0 -25216
  77. package/dist/bundle/chunk-QBJRK733.js +0 -1068
  78. package/dist/bundle/chunk-QBYE26ZC.js +0 -131
  79. package/dist/bundle/chunk-QPPOIWPY.js +0 -1246
  80. package/dist/bundle/chunk-R2CEA7MK.js +0 -743
  81. package/dist/bundle/chunk-S4UUN6LD.js +0 -1410
  82. package/dist/bundle/chunk-S6JG4YUH.js +0 -72
  83. package/dist/bundle/chunk-SKUY7JDA.js +0 -164
  84. package/dist/bundle/chunk-T35IOBPJ.js +0 -1341
  85. package/dist/bundle/chunk-T3W4V4A6.js +0 -63
  86. package/dist/bundle/chunk-TB3LN5G2.js +0 -50
  87. package/dist/bundle/chunk-TCT5D2X2.js +0 -6848
  88. package/dist/bundle/chunk-TES7MB6I.js +0 -82
  89. package/dist/bundle/chunk-TXDR6YSF.js +0 -23
  90. package/dist/bundle/chunk-TY7NDMFY.js +0 -46
  91. package/dist/bundle/chunk-U7UTYALA.js +0 -353
  92. package/dist/bundle/chunk-UOWHMOU3.js +0 -188
  93. package/dist/bundle/chunk-UXDUWGX6.js +0 -2791
  94. package/dist/bundle/chunk-V5I3QHDU.js +0 -558
  95. package/dist/bundle/chunk-VCDIKCFE.js +0 -1007
  96. package/dist/bundle/chunk-VJHUMB7U.js +0 -338
  97. package/dist/bundle/chunk-W4KLHM2K.js +0 -95
  98. package/dist/bundle/chunk-W5LKEOGN.js +0 -142
  99. package/dist/bundle/chunk-WLDZWHSF.js +0 -170
  100. package/dist/bundle/chunk-WQEEYEWO.js +0 -3752
  101. package/dist/bundle/chunk-WRF6TY63.js +0 -1521
  102. package/dist/bundle/chunk-WXYOELRI.js +0 -108
  103. package/dist/bundle/chunk-WZBPUOWM.js +0 -76
  104. package/dist/bundle/chunk-XGNZD52X.js +0 -592
  105. package/dist/bundle/chunk-XQUUANA2.js +0 -24600
  106. package/dist/bundle/chunk-Y5E2WNWB.js +0 -35
  107. package/dist/bundle/chunk-YQH4J6YZ.js +0 -358
  108. package/dist/bundle/chunk-Z7Y2I5YR.js +0 -44045
  109. package/dist/bundle/chunk-ZBCC7MBN.js +0 -9671
  110. package/dist/bundle/chunk-ZVVMGPBJ.js +0 -50
  111. package/dist/bundle/command-contract-ZL67KMYL.js +0 -37
  112. package/dist/bundle/command-server-entry-COR2VDRU.js +0 -166
  113. package/dist/bundle/decode-33SGRQM6.js +0 -297
  114. package/dist/bundle/dispatch-2FTOHA5D.js +0 -411
  115. package/dist/bundle/dist-EM7KLEG4.js +0 -7577
  116. package/dist/bundle/dist-PAKDDIBT.js +0 -191
  117. package/dist/bundle/echarts-QMAA7HH5.js +0 -42501
  118. package/dist/bundle/embed-W4ZBXPWD.js +0 -38
  119. package/dist/bundle/embedder-73CCZC52.js +0 -111
  120. package/dist/bundle/failure-OHIXWTR6.js +0 -25
  121. package/dist/bundle/first-run-MOSUMMVX.js +0 -28
  122. package/dist/bundle/first-screen-GUXBF3SL.js +0 -38
  123. package/dist/bundle/instructions-4H7UREH2.js +0 -11
  124. package/dist/bundle/mcp-5HFPWC3W.js +0 -167
  125. package/dist/bundle/meeting-combined-QMIZOBBJ.js +0 -24
  126. package/dist/bundle/meeting-model-2UYVGXD5.js +0 -25
  127. package/dist/bundle/meeting-semantic-LEJPUIN3.js +0 -22
  128. package/dist/bundle/node-KM3CUABH.js +0 -2340
  129. package/dist/bundle/node-P3PUHKYH.js +0 -176
  130. package/dist/bundle/node-TLZSIHIJ.js +0 -21
  131. package/dist/bundle/node-sqlite-UHPODTKB.js +0 -74
  132. package/dist/bundle/oauth-T3DWL7OV.js +0 -20
  133. package/dist/bundle/open-ODWX32PF.js +0 -23
  134. package/dist/bundle/openai-GSXXHKPX.js +0 -238
  135. package/dist/bundle/process-AFIXYXWL.js +0 -91
  136. package/dist/bundle/program-SXSUG335.js +0 -35250
  137. package/dist/bundle/prompt-GVTYTFK7.js +0 -17
  138. package/dist/bundle/recognize-XDSZEZP5.js +0 -26
  139. package/dist/bundle/remote-ZWZKMEY6.js +0 -31
  140. package/dist/bundle/rerank-OBZQ54NL.js +0 -52
  141. package/dist/bundle/serve-NY5MUTNW.js +0 -199
  142. package/dist/bundle/server-JK334V5Y.js +0 -212
  143. package/dist/bundle/server-VOPYQCUD.js +0 -79
  144. package/dist/bundle/sqlite-runtime-2NHF4S6G.js +0 -20
  145. package/dist/bundle/state-YGWZZWPM.js +0 -36
  146. package/dist/bundle/store-LRQUTFJR.js +0 -306
  147. package/dist/bundle/store-ND6KU4RI.js +0 -181
  148. package/dist/bundle/store-maintenance-command-GLYGQM2V.js +0 -66
  149. package/dist/bundle/surface-P53WLLXP.js +0 -65
  150. package/dist/commands/api.d.ts +0 -12
  151. package/dist/commands/api.d.ts.map +0 -1
  152. package/dist/commands/api.js.map +0 -1
  153. package/dist/commands/crm.d.ts +0 -7
  154. package/dist/commands/crm.d.ts.map +0 -1
  155. package/dist/commands/crm.js.map +0 -1
  156. package/dist/commands/schedule.d.ts +0 -3
  157. package/dist/commands/schedule.d.ts.map +0 -1
  158. package/dist/commands/schedule.js.map +0 -1
  159. package/dist/commands/session.d.ts +0 -8
  160. package/dist/commands/session.d.ts.map +0 -1
  161. package/dist/commands/session.js.map +0 -1
  162. package/dist/config.d.ts +0 -13
  163. package/dist/config.d.ts.map +0 -1
  164. package/dist/config.js.map +0 -1
  165. package/dist/context.d.ts +0 -37
  166. package/dist/context.d.ts.map +0 -1
  167. package/dist/context.js.map +0 -1
  168. package/dist/generated/definitions.d.ts +0 -3
  169. package/dist/generated/definitions.d.ts.map +0 -1
  170. package/dist/generated/definitions.js.map +0 -1
  171. package/dist/generated/manifest.d.ts +0 -6
  172. package/dist/generated/manifest.d.ts.map +0 -1
  173. package/dist/generated/manifest.js.map +0 -1
  174. package/dist/generated/schemas.d.ts +0 -383
  175. package/dist/generated/schemas.d.ts.map +0 -1
  176. package/dist/generated/schemas.js.map +0 -1
  177. package/dist/generated/types.d.ts +0 -10166
  178. package/dist/generated/types.d.ts.map +0 -1
  179. package/dist/generated/types.js.map +0 -1
  180. package/dist/generated/wirecat-config.d.ts +0 -15
  181. package/dist/generated/wirecat-config.d.ts.map +0 -1
  182. package/dist/generated/wirecat-config.js.map +0 -1
  183. package/dist/hooks.d.ts +0 -33
  184. package/dist/hooks.d.ts.map +0 -1
  185. package/dist/hooks.js.map +0 -1
  186. package/dist/identity.d.ts +0 -33
  187. package/dist/identity.d.ts.map +0 -1
  188. package/dist/identity.js.map +0 -1
  189. package/dist/index.d.ts +0 -3
  190. package/dist/index.d.ts.map +0 -1
  191. package/dist/index.js.map +0 -1
  192. package/dist/links.d.ts +0 -10
  193. package/dist/links.d.ts.map +0 -1
  194. package/dist/links.js.map +0 -1
  195. package/dist/meetings.d.ts +0 -57
  196. package/dist/meetings.d.ts.map +0 -1
  197. package/dist/meetings.js.map +0 -1
  198. package/dist/program.d.ts +0 -6
  199. package/dist/program.d.ts.map +0 -1
  200. package/dist/program.js.map +0 -1
  201. package/dist/version.d.ts +0 -2
  202. package/dist/version.d.ts.map +0 -1
  203. package/dist/version.js.map +0 -1
  204. package/dist/wcat.d.ts +0 -3
  205. package/dist/wcat.d.ts.map +0 -1
  206. package/dist/wcat.js.map +0 -1
@@ -1,185 +0,0 @@
1
- import { createRequire as __bundleRequire } from "node:module";
2
- const require = __bundleRequire(import.meta.url);
3
- import {
4
- PLAIN_HTTP_REFUSED,
5
- modelAddressAllowed,
6
- onThisComputer
7
- } from "./chunk-NBNQLNVV.js";
8
- import {
9
- readSharedSection,
10
- sharedConfigPath,
11
- writeSharedSection
12
- } from "./chunk-P6OJKJJS.js";
13
- import {
14
- unit
15
- } from "./chunk-VCDIKCFE.js";
16
- import {
17
- storePath
18
- } from "./chunk-2R2EX5I6.js";
19
- import {
20
- boolean,
21
- isoTimestamp,
22
- pipe,
23
- safeParse,
24
- strictObject,
25
- string
26
- } from "./chunk-S4UUN6LD.js";
27
- import {
28
- CliError
29
- } from "./chunk-S6JG4YUH.js";
30
- import {
31
- __name
32
- } from "./chunk-ZVVMGPBJ.js";
33
-
34
- // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/embeddings/remote.js
35
- import { setTimeout } from "node:timers/promises";
36
-
37
- // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/models/local-only.js
38
- var SECTION = "local_only";
39
- var Setting = strictObject({
40
- on: boolean(),
41
- at: pipe(string(), isoTimestamp())
42
- });
43
- var pathOf = /* @__PURE__ */ __name((env) => sharedConfigPath(storePath(env), env), "pathOf");
44
- var readLocalOnly = /* @__PURE__ */ __name((env) => {
45
- const section = readSharedSection(pathOf(env), SECTION);
46
- if (section === void 0 || section === null)
47
- return void 0;
48
- const checked = safeParse(Setting, section);
49
- return checked.success ? checked.output : { on: true, at: (/* @__PURE__ */ new Date(0)).toISOString() };
50
- }, "readLocalOnly");
51
- var localOnly = /* @__PURE__ */ __name((env) => readLocalOnly(env)?.on === true, "localOnly");
52
- var writeLocalOnly = /* @__PURE__ */ __name((env, on) => writeSharedSection(pathOf(env), SECTION, on ? { on: true, at: (/* @__PURE__ */ new Date()).toISOString() } : void 0), "writeLocalOnly");
53
- var localOnlyRefusal = /* @__PURE__ */ __name((what, where) => new CliError("permission_error", `local only is on: ${what} would go to ${where}, which is not this computer; nothing was sent. Choose a model on this computer, or turn local only off with \`models local-only set off\``, { reason: "local-only.refused" }), "localOnlyRefusal");
54
- var refuseOffComputer = /* @__PURE__ */ __name((env, address, what) => {
55
- if (!onThisComputer(address) && localOnly(env))
56
- throw localOnlyRefusal(what, hostOf(address));
57
- }, "refuseOffComputer");
58
- var hostOf = /* @__PURE__ */ __name((address) => {
59
- try {
60
- return new URL(address).host;
61
- } catch {
62
- return address;
63
- }
64
- }, "hostOf");
65
- var refuseModelAddress = /* @__PURE__ */ __name((env, address, what) => {
66
- if (!modelAddressAllowed(address))
67
- throw new CliError("validation_error", PLAIN_HTTP_REFUSED, { reason: "model.address-refused" });
68
- refuseOffComputer(env, address, what);
69
- }, "refuseModelAddress");
70
-
71
- // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/embeddings/remote.js
72
- var OPENAI_URL = "https://api.openai.com/v1";
73
- var OPENAI_MODELS = {
74
- "text-embedding-3-small": { dims: 1536, perMillion: 0.02 },
75
- "text-embedding-3-large": { dims: 3072, perMillion: 0.13 }
76
- };
77
- var DEFAULT_OPENAI_MODEL = "text-embedding-3-small";
78
- var PER_REQUEST = 256;
79
- var isLocal = /* @__PURE__ */ __name((baseUrl) => onThisComputer(baseUrl), "isLocal");
80
- var remoteModel = /* @__PURE__ */ __name(({ model = DEFAULT_OPENAI_MODEL, baseUrl, dims }) => {
81
- const known = baseUrl === void 0 ? OPENAI_MODELS[model] : void 0;
82
- if (baseUrl === void 0 && !known) {
83
- throw new CliError("validation_error", `OpenAI has no embedding model ${model} here \u2014 one of: ${Object.keys(OPENAI_MODELS).join(", ")}; another server takes --base-url`);
84
- }
85
- const size = dims ?? known?.dims;
86
- if (size === void 0)
87
- throw new CliError("validation_error", "with --base-url, say the vector size with --dims");
88
- return {
89
- provider: baseUrl === void 0 ? "openai" : `url:${new URL(baseUrl).host}`,
90
- model,
91
- dims: size,
92
- baseUrl: baseUrl ?? OPENAI_URL,
93
- shorten: known !== void 0 && size !== known.dims,
94
- ...known ? { price: { perMillion: known.perMillion, read: "2026-10-02" } } : {}
95
- };
96
- }, "remoteModel");
97
- var remoteKey = /* @__PURE__ */ __name(({ provider, model, dims }) => `${provider}:${model}:${dims}`, "remoteKey");
98
- var openRemote = /* @__PURE__ */ __name((remote, apiKey, { concurrency = 4, fetch: post = fetch, tries = 5, env }) => {
99
- refuseModelAddress(env ?? process.env, remote.baseUrl, "text to embed");
100
- const request = /* @__PURE__ */ __name(async (input) => {
101
- for (let attempt = 1; ; attempt++) {
102
- let response;
103
- try {
104
- response = await post(`${remote.baseUrl.replace(/\/$/, "")}/embeddings`, {
105
- method: "POST",
106
- headers: {
107
- "content-type": "application/json",
108
- ...apiKey ? { authorization: `Bearer ${apiKey}` } : {}
109
- },
110
- body: JSON.stringify({
111
- model: remote.model,
112
- input,
113
- encoding_format: "float",
114
- ...remote.shorten ? { dimensions: remote.dims } : {}
115
- })
116
- });
117
- } catch {
118
- if (attempt >= tries)
119
- throw new CliError("network_error", `${remote.provider} could not be reached`);
120
- await setTimeout(1e3 * attempt);
121
- continue;
122
- }
123
- if (response.ok) {
124
- const body = await response.json();
125
- const data = [...body.data ?? []].sort((a, b) => a.index - b.index);
126
- if (data.length !== input.length || data.some(({ embedding }) => embedding.length !== remote.dims)) {
127
- throw new CliError("invalid_response", `${remote.provider} answered with vectors of another number or size than ${input.length} \xD7 ${remote.dims}`);
128
- }
129
- return data.map(({ embedding }) => unit(Float32Array.from(embedding)));
130
- }
131
- const code = await errorCode(response);
132
- if (response.status === 401 || response.status === 403) {
133
- throw new CliError("authentication_error", `${remote.provider} refused the key (HTTP ${response.status}${code}) \u2014 set it again with \`models keys set\``);
134
- }
135
- const again = response.status === 429 || response.status >= 500;
136
- if (!again || attempt >= tries) {
137
- throw new CliError(response.status === 429 ? "rate_limited" : "provider_error", `${remote.provider} answered HTTP ${response.status}${code}`);
138
- }
139
- const wait = Number(response.headers.get("retry-after"));
140
- await setTimeout(Number.isFinite(wait) && wait > 0 ? wait * 1e3 : 1e3 * 2 ** attempt);
141
- }
142
- }, "request");
143
- return {
144
- model: { id: remote.model, dims: remote.dims },
145
- embed: /* @__PURE__ */ __name(async (texts) => {
146
- const parts = [];
147
- for (let start = 0; start < texts.length; start += PER_REQUEST)
148
- parts.push(texts.slice(start, start + PER_REQUEST));
149
- const results = new Array(parts.length);
150
- let next = 0;
151
- await Promise.all(Array.from({ length: Math.min(concurrency, parts.length) }, async () => {
152
- for (let index = next++; index < parts.length; index = next++)
153
- results[index] = await request(parts[index]);
154
- }));
155
- return results.flat();
156
- }, "embed"),
157
- close: /* @__PURE__ */ __name(async () => {
158
- }, "close")
159
- };
160
- }, "openRemote");
161
- var errorCode = /* @__PURE__ */ __name(async (response) => {
162
- try {
163
- const body = await response.json();
164
- const code = body.error?.code ?? body.error?.type;
165
- return typeof code === "string" && /^[\w.-]{1,64}$/.test(code) ? `, ${code}` : "";
166
- } catch {
167
- return "";
168
- }
169
- }, "errorCode");
170
-
171
- export {
172
- readLocalOnly,
173
- localOnly,
174
- writeLocalOnly,
175
- localOnlyRefusal,
176
- refuseOffComputer,
177
- refuseModelAddress,
178
- OPENAI_URL,
179
- OPENAI_MODELS,
180
- DEFAULT_OPENAI_MODEL,
181
- isLocal,
182
- remoteModel,
183
- remoteKey,
184
- openRemote
185
- };
@@ -1,77 +0,0 @@
1
- import { createRequire as __bundleRequire } from "node:module";
2
- const require = __bundleRequire(import.meta.url);
3
- import {
4
- __name
5
- } from "./chunk-ZVVMGPBJ.js";
6
-
7
- // node_modules/.pnpm/@wirecat+cli-core@2.0.0_@wirecat+cli-base@1.0.0_commander@15.0.0_esbuild@0.28.2_typescr_a82f624c57005d53c3f072e45c3a3a86/node_modules/@wirecat/cli-core/dist/http/listen.js
8
- import { createServer } from "node:http";
9
- import { pipeline, Readable } from "node:stream";
10
- var MAX_BODY = 4 * 1024 * 1024;
11
- var TooLarge = class extends Error {
12
- static {
13
- __name(this, "TooLarge");
14
- }
15
- };
16
- var readBody = /* @__PURE__ */ __name((incoming, limit) => new Promise((resolve, reject) => {
17
- if (Number(incoming.headers["content-length"] ?? 0) > limit)
18
- return reject(new TooLarge());
19
- const chunks = [];
20
- let size = 0;
21
- incoming.on("data", (chunk) => {
22
- size += chunk.length;
23
- if (size > limit) {
24
- incoming.destroy();
25
- reject(new TooLarge());
26
- } else
27
- chunks.push(chunk);
28
- });
29
- incoming.once("end", () => resolve(Buffer.concat(chunks)));
30
- incoming.once("error", reject);
31
- }), "readBody");
32
- var toRequest = /* @__PURE__ */ __name(async (incoming, origin, maxBody) => {
33
- const headers = new Headers();
34
- for (const [name, value] of Object.entries(incoming.headers)) {
35
- if (Array.isArray(value))
36
- for (const one of value)
37
- headers.append(name, one);
38
- else if (value !== void 0)
39
- headers.set(name, value);
40
- }
41
- const method = incoming.method ?? "GET";
42
- const body = method === "GET" || method === "HEAD" ? void 0 : await readBody(incoming, maxBody);
43
- if (body)
44
- headers.set("content-length", String(body.length));
45
- return new Request(new URL(incoming.url ?? "/", origin), { method, headers, ...body ? { body } : {} });
46
- }, "toRequest");
47
- var send = /* @__PURE__ */ __name(async (response, outgoing) => {
48
- outgoing.writeHead(response.status, Object.fromEntries(response.headers));
49
- if (!response.body)
50
- return void outgoing.end();
51
- const body = Readable.fromWeb(response.body);
52
- pipeline(body, outgoing, () => void 0);
53
- }, "send");
54
- var listen = /* @__PURE__ */ __name((handle, { host, port, maxBody = MAX_BODY }) => new Promise((resolve, reject) => {
55
- const server = createServer((incoming, outgoing) => {
56
- toRequest(incoming, `http://${host}`, maxBody).then(handle).then((response) => send(response, outgoing)).catch((error) => {
57
- if (!outgoing.headersSent)
58
- outgoing.writeHead(error instanceof TooLarge ? 413 : 500, { connection: "close" });
59
- outgoing.end();
60
- });
61
- });
62
- server.once("error", reject);
63
- server.listen(port, host, () => {
64
- const { port: bound } = server.address();
65
- resolve({
66
- url: new URL(`http://${host}:${bound}`),
67
- close: /* @__PURE__ */ __name(() => new Promise((done) => {
68
- server.close(() => done());
69
- server.closeAllConnections();
70
- }), "close")
71
- });
72
- });
73
- }), "listen");
74
-
75
- export {
76
- listen
77
- };