@wirecat/tg-cli 0.132.0 → 0.134.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 (160) hide show
  1. package/README.md +139 -319
  2. package/contracts/wirecat.json +82 -2
  3. package/dist/bin/tg.js +2 -2
  4. package/dist/bot/generated/types.d.ts +188 -0
  5. package/dist/bot/generated/types.d.ts.map +1 -1
  6. package/dist/bundle/{adapter-OXVMOWVE.js → adapter-Y4IXTXAG.js} +104 -68
  7. package/dist/bundle/agent-G7VHOJMS.js +37 -0
  8. package/dist/bundle/{all-profiles-6OQC7PBL.js → all-profiles-SUGID6CX.js} +62 -20
  9. package/dist/bundle/{anthropic-YFMIHFW5.js → anthropic-4QKTXT4B.js} +5 -5
  10. package/dist/bundle/{app-server-S7CJPJXN.js → app-server-TPOD6LIJ.js} +75 -65
  11. package/dist/bundle/{bot-api-KJ6EZ4R6.js → bot-api-KBESP422.js} +73 -91
  12. package/dist/bundle/{bot-history-JYCXDFW4.js → bot-history-3EORA23G.js} +23 -22
  13. package/dist/bundle/{bun-FVTOBYZ2.js → bun-FL76M4M2.js} +2 -2
  14. package/dist/bundle/{bun-sqlite-KDGWBNOR.js → bun-sqlite-H37OSTAJ.js} +6 -6
  15. package/dist/bundle/{chunk-JZJV3DYK.js → chunk-2GT563YH.js} +2 -2
  16. package/dist/bundle/{chunk-EPR67IRV.js → chunk-2JWY7CXJ.js} +4 -4
  17. package/dist/bundle/{chunk-UGD4SCUI.js → chunk-3O25FAPA.js} +3 -4
  18. package/dist/bundle/{chunk-AERP2QR6.js → chunk-3PG6QVQZ.js} +11 -25
  19. package/dist/bundle/{chunk-DXPGMUOR.js → chunk-3QQWTP77.js} +2 -2
  20. package/dist/bundle/{chunk-FIUH52FE.js → chunk-3ZNO27UE.js} +1 -1
  21. package/dist/bundle/{chunk-Y57EKZZK.js → chunk-4R2ZJGFF.js} +3274 -1674
  22. package/dist/bundle/{chunk-6LPUK62N.js → chunk-4S2DHHJM.js} +2 -100
  23. package/dist/bundle/{chunk-LF6FACSW.js → chunk-4X6BX3XP.js} +144 -10
  24. package/dist/bundle/{chunk-LZ3HFDYL.js → chunk-6DGVK5KS.js} +2 -2
  25. package/dist/bundle/chunk-6DJJVFSG.js +388 -0
  26. package/dist/bundle/{chunk-BSXS7VAC.js → chunk-6MEHKUN6.js} +1 -1
  27. package/dist/bundle/{chunk-44A2XRDE.js → chunk-6UNLEQA5.js} +31 -20
  28. package/dist/bundle/{chunk-M2TV6BDB.js → chunk-77E7Q4EQ.js} +7 -7
  29. package/dist/bundle/chunk-7GGDCQJ5.js +353 -0
  30. package/dist/bundle/{chunk-OGZZUDJJ.js → chunk-AHVWZDXO.js} +79 -64
  31. package/dist/bundle/{chunk-YVI5SQPY.js → chunk-ANBI3OXK.js} +1 -1
  32. package/dist/bundle/{chunk-PR4F3TYK.js → chunk-AYWST6NA.js} +60 -51
  33. package/dist/bundle/{chunk-7SEVVE3X.js → chunk-CA7DY2YU.js} +3 -3
  34. package/dist/bundle/{chunk-O43PARFS.js → chunk-CDKXZLMP.js} +273 -176
  35. package/dist/bundle/{chunk-YAPO7QNO.js → chunk-CNGNR4CY.js} +6 -6
  36. package/dist/bundle/{chunk-2UGSIHLV.js → chunk-CSXCCK6J.js} +2 -2
  37. package/dist/bundle/{chunk-N5LZ6L4D.js → chunk-DG35TQ6P.js} +3 -3
  38. package/dist/bundle/{chunk-LMGVPDXN.js → chunk-EXMAWEHC.js} +2 -2
  39. package/dist/bundle/{chunk-A5D3J7XZ.js → chunk-FR3ATU5I.js} +4 -4
  40. package/dist/bundle/{chunk-JDNDWZYS.js → chunk-FR4Y5CGW.js} +4 -4
  41. package/dist/bundle/{chunk-YSNQGOUI.js → chunk-GIGZTI74.js} +2115 -1975
  42. package/dist/bundle/{chunk-3QHKZLBU.js → chunk-H3TLAYGY.js} +4 -4
  43. package/dist/bundle/{chunk-KJICORS4.js → chunk-HD7DV5B2.js} +65 -43
  44. package/dist/bundle/{chunk-NLRGMP7M.js → chunk-HETHFOHC.js} +3 -3
  45. package/dist/bundle/{chunk-4YB7JU2W.js → chunk-HEZK4W3U.js} +6 -6
  46. package/dist/bundle/{chunk-2LZD2VFV.js → chunk-IJ7R2WMK.js} +4 -4
  47. package/dist/bundle/{chunk-4ZTVJHWU.js → chunk-ITJ7DGNA.js} +4 -4
  48. package/dist/bundle/{chunk-5UPEEMEF.js → chunk-J5RB4ASI.js} +142 -372
  49. package/dist/bundle/{chunk-IY7CTAOQ.js → chunk-JAL443BH.js} +9 -9
  50. package/dist/bundle/{chunk-U7PHJSTX.js → chunk-JCDD5T3A.js} +2 -2
  51. package/dist/bundle/{chunk-BLZEQVP4.js → chunk-JHZJBNDO.js} +2 -2
  52. package/dist/bundle/chunk-JWLODUN3.js +555 -0
  53. package/dist/bundle/{chunk-4CKYANQH.js → chunk-JWNSG5GI.js} +1 -1
  54. package/dist/bundle/{chunk-YRXSNH3R.js → chunk-JXEO5EIN.js} +2 -2
  55. package/dist/bundle/{chunk-DSJNZXTP.js → chunk-K5FK6WWN.js} +1 -1
  56. package/dist/bundle/{chunk-LG3K5NHX.js → chunk-L47PFECD.js} +7 -7
  57. package/dist/bundle/{chunk-OIRNHSAH.js → chunk-L4PNDW4S.js} +6 -6
  58. package/dist/bundle/{chunk-WAVRUADL.js → chunk-M323L5SG.js} +30 -15
  59. package/dist/bundle/{chunk-AUZWIBHJ.js → chunk-MMDFPBFZ.js} +43 -64
  60. package/dist/bundle/{chunk-FKGYXIN7.js → chunk-MUV73B5A.js} +7 -7
  61. package/dist/bundle/chunk-MXA3FU2R.js +116 -0
  62. package/dist/bundle/{chunk-42MXCMW6.js → chunk-NUD4CBHK.js} +3 -3
  63. package/dist/bundle/{chunk-PG37E63A.js → chunk-NYEVPAF2.js} +511 -472
  64. package/dist/bundle/{chunk-QS46C5SW.js → chunk-O3QBO6NW.js} +17 -17
  65. package/dist/bundle/{chunk-CFWFESBO.js → chunk-O4ZOQJ6W.js} +9 -9
  66. package/dist/bundle/{chunk-74UPKW7H.js → chunk-OJSPB4LA.js} +2 -2
  67. package/dist/bundle/{chunk-JNWKV3QV.js → chunk-PCBVSHKD.js} +4 -4
  68. package/dist/bundle/{chunk-5RDNBG7D.js → chunk-PK5WEGPJ.js} +2 -2
  69. package/dist/bundle/{chunk-5D4AEUVA.js → chunk-PL5P7UKW.js} +434 -1
  70. package/dist/bundle/{chunk-BMI2NWFI.js → chunk-PRI2XTM7.js} +35 -12
  71. package/dist/bundle/chunk-PRM7GKBV.js +340 -0
  72. package/dist/bundle/{chunk-ZZ32DXTH.js → chunk-PZ2ZFPGO.js} +1 -1
  73. package/dist/bundle/chunk-QYRK4XXH.js +727 -0
  74. package/dist/bundle/{chunk-QNEAPLOP.js → chunk-RVA3CRSY.js} +12 -12
  75. package/dist/bundle/{chunk-4EDJJQJI.js → chunk-SPXNI53Z.js} +38 -9
  76. package/dist/bundle/{chunk-ZRW3DF25.js → chunk-TI5U6AUT.js} +34 -28
  77. package/dist/bundle/{chunk-SMQ45RZX.js → chunk-TKWYXM7L.js} +9 -60
  78. package/dist/bundle/{chunk-ZJIGVT6Z.js → chunk-TZCFJJEU.js} +6 -6
  79. package/dist/bundle/chunk-UTTEAOJ3.js +7 -0
  80. package/dist/bundle/chunk-V6G4LTXU.js +50 -0
  81. package/dist/bundle/{chunk-JMJOWT4N.js → chunk-VH4J7IIS.js} +1 -1
  82. package/dist/bundle/{chunk-UAFSDTID.js → chunk-VNJRWFHP.js} +1 -1
  83. package/dist/bundle/chunk-W2QSDPG6.js +80 -0
  84. package/dist/bundle/{chunk-ESOFH7PA.js → chunk-WGGUKQE7.js} +134 -558
  85. package/dist/bundle/{chunk-NWDADTPE.js → chunk-WPXVJGSL.js} +3 -3
  86. package/dist/bundle/{chunk-NWCFO37P.js → chunk-XLNV3U6N.js} +3 -3
  87. package/dist/bundle/{chunk-JPSRC732.js → chunk-XS4EE7MO.js} +17 -15
  88. package/dist/bundle/{chunk-FPSRT2TX.js → chunk-XVRLD3LN.js} +2 -2
  89. package/dist/bundle/{chunk-O3AM32YN.js → chunk-XZ6XEAJP.js} +18 -18
  90. package/dist/bundle/{chunk-B4LGDOG5.js → chunk-YHTSJMZ5.js} +3734 -3380
  91. package/dist/bundle/chunk-YPJCURT6.js +108 -0
  92. package/dist/bundle/{chunk-HBSKP7OV.js → chunk-Z77R76S2.js} +1 -1
  93. package/dist/bundle/{chunk-PYECFCPD.js → chunk-ZC7OEYDX.js} +1 -1
  94. package/dist/bundle/{chunk-IYJ4B632.js → chunk-ZW2N2GI2.js} +12 -12
  95. package/dist/bundle/command-contract-LEFXJAA3.js +37 -0
  96. package/dist/bundle/{command-server-entry-TM264M2J.js → command-server-entry-WQAE5UGU.js} +27 -27
  97. package/dist/bundle/{decode-RJFOSHCE.js → decode-2J2DOVGV.js} +5 -5
  98. package/dist/bundle/{dispatch-7OZP3X4O.js → dispatch-IZ2TP5GW.js} +8 -8
  99. package/dist/bundle/dist-PAKDDIBT.js +191 -0
  100. package/dist/bundle/{echarts-PYKF4D7B.js → echarts-GFIIHZ4U.js} +2 -2
  101. package/dist/bundle/{embed-JFN6Z5TG.js → embed-AGOXADHW.js} +6 -6
  102. package/dist/bundle/{embedder-WN54JIMY.js → embedder-PCIXGM2Y.js} +9 -9
  103. package/dist/bundle/{entry-Z6LO6N6S.js → entry-HUQXUV52.js} +9 -9
  104. package/dist/bundle/{failure-UONA2IA5.js → failure-JSRHZ2S6.js} +2 -2
  105. package/dist/bundle/{first-run-WQAKES7G.js → first-run-2LXN7B33.js} +12 -12
  106. package/dist/bundle/first-screen-VUE6RCSF.js +37 -0
  107. package/dist/bundle/{instructions-PR4BBBTM.js → instructions-RSLTJVFJ.js} +1 -1
  108. package/dist/bundle/{mcp-O6ACR2DX.js → mcp-MMENCB7I.js} +2 -2
  109. package/dist/bundle/meeting-combined-PBNPHOM3.js +23 -0
  110. package/dist/bundle/{meeting-model-YVTUOM4H.js → meeting-model-SI77WMMK.js} +11 -11
  111. package/dist/bundle/{meeting-semantic-X4KG6RNV.js → meeting-semantic-WRXWUR4M.js} +6 -6
  112. package/dist/bundle/{node-OVS5LTVZ.js → node-5XGMCUGQ.js} +2 -2
  113. package/dist/bundle/{node-sqlite-LC44SM4Z.js → node-sqlite-ES7SQSIC.js} +7 -7
  114. package/dist/bundle/{oauth-NSVUFQCW.js → oauth-QFM4Y6N7.js} +8 -8
  115. package/dist/bundle/{open-XN5SJFVY.js → open-2MD2DKGQ.js} +5 -5
  116. package/dist/bundle/{openai-WOYZHJNL.js → openai-6TMKJKYO.js} +15 -15
  117. package/dist/bundle/{process-UFBRGTQC.js → process-VA2DP7MY.js} +1 -1
  118. package/dist/bundle/{program-RAGBRRQH.js → program-K3SLEA42.js} +70 -63
  119. package/dist/bundle/{prompt-6HAKBUQN.js → prompt-VZSPCE6E.js} +5 -5
  120. package/dist/bundle/{proxy-transport-5EJVFUTC.js → proxy-transport-OJU2EOOC.js} +5 -5
  121. package/dist/bundle/{recognize-CN5COBVJ.js → recognize-LH3ZZEIL.js} +4 -4
  122. package/dist/bundle/{remote-STX5AMGE.js → remote-JNW5HN2I.js} +9 -9
  123. package/dist/bundle/{rerank-ZCOWTXIJ.js → rerank-P23UJMII.js} +7 -7
  124. package/dist/bundle/{serve-XMQEOIG2.js → serve-VSLLMILH.js} +15 -15
  125. package/dist/bundle/{server-PGGUD3DM.js → server-FBRRRKCS.js} +68 -57
  126. package/dist/bundle/server-TA4QP7PG.js +78 -0
  127. package/dist/bundle/{sqlite-runtime-PS4DSOIU.js → sqlite-runtime-LWATDAAU.js} +6 -6
  128. package/dist/bundle/{state-GL4ZC57O.js → state-3AFJL2EL.js} +6 -6
  129. package/dist/bundle/{store-VISFXSHL.js → store-6TLYL2VU.js} +30 -17
  130. package/dist/bundle/{store-HJ76TLWD.js → store-PEXV5DNA.js} +24 -19
  131. package/dist/bundle/store-maintenance-command-IYJLUQ5X.js +65 -0
  132. package/dist/bundle/surface-L4VY4WFG.js +64 -0
  133. package/dist/bundle/tg.js +13 -13
  134. package/dist/telegram/adapter.d.ts +9 -2
  135. package/dist/telegram/adapter.d.ts.map +1 -1
  136. package/dist/telegram/adapter.js +5 -6
  137. package/dist/telegram/adapter.js.map +1 -1
  138. package/dist/telegram/messages.d.ts +12 -0
  139. package/dist/telegram/messages.d.ts.map +1 -1
  140. package/dist/telegram/messages.js +40 -0
  141. package/dist/telegram/messages.js.map +1 -1
  142. package/dist/version.d.ts +1 -1
  143. package/dist/version.js +1 -1
  144. package/package.json +3 -3
  145. package/skills/tg-cli/SKILL.md +80 -576
  146. package/skills/tg-cli/references/files.md +64 -0
  147. package/skills/tg-cli/references/history.md +22 -0
  148. package/skills/tg-cli/references/mcp-and-bots.md +54 -0
  149. package/skills/tg-cli/references/messages.md +115 -0
  150. package/skills/tg-cli/references/people.md +85 -0
  151. package/skills/tg-cli/references/search.md +132 -0
  152. package/skills/tg-cli/references/setup.md +91 -0
  153. package/skills/tg-cli/references/stats.md +45 -0
  154. package/skills/tg-cli/references/tasks.md +54 -0
  155. package/dist/bundle/chunk-VKE77B3F.js +0 -2
  156. package/dist/bundle/command-contract-FRH7LBGE.js +0 -37
  157. package/dist/bundle/first-screen-4RFG22SA.js +0 -35
  158. package/dist/bundle/meeting-combined-MHWTZOF2.js +0 -23
  159. package/dist/bundle/server-WTNYWCZ4.js +0 -69
  160. package/dist/bundle/store-maintenance-command-SMARMN5C.js +0 -60
@@ -1,7 +1,6 @@
1
1
  import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
- CLIENT_INFO_META_KEY,
5
4
  DEFAULT_MAX_SUBSCRIPTIONS,
6
5
  McpServer,
7
6
  ProtocolErrorCode,
@@ -24,12 +23,7 @@ import {
24
23
  serverIdentityOf,
25
24
  setNegotiatedProtocolVersion,
26
25
  validateEnvelopeMeta
27
- } from "./chunk-5D4AEUVA.js";
28
- import {
29
- agentOf,
30
- clientHash,
31
- currentCaller
32
- } from "./chunk-LG3K5NHX.js";
26
+ } from "./chunk-PL5P7UKW.js";
33
27
  import {
34
28
  __name
35
29
  } from "./chunk-ZVVMGPBJ.js";
@@ -541,95 +535,7 @@ function toError(value) {
541
535
  }
542
536
  __name(toError, "toError");
543
537
 
544
- // node_modules/.pnpm/@wirecat+cli-core@0.675.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.102.1_commander@15_4538b457841b7e7d546b8c440ab6644a/node_modules/@wirecat/cli-core/dist/mcp/caller.js
545
- var callingAgent = /* @__PURE__ */ __name((fallback, caller = currentCaller()) => {
546
- const client = caller?.agent?.client?.name;
547
- if (client && client !== "unknown")
548
- return client;
549
- const kind = caller?.agent?.kind;
550
- return kind && kind !== "mcp-client" ? kind : fallback;
551
- }, "callingAgent");
552
- var CALLER_META_KEY = "wirecat.dev/caller";
553
- var PROXY_CLIENT_NAME = "all-profiles";
554
- var NAME = /^[\w .@()/+-]{1,64}$/;
555
- var plain = /* @__PURE__ */ __name((value) => typeof value === "string" && NAME.test(value.trim()) ? value.trim() : void 0, "plain");
556
- var clientFrom = /* @__PURE__ */ __name((value) => {
557
- if (!value || typeof value !== "object")
558
- return void 0;
559
- const { name, version } = value;
560
- const named = plain(name);
561
- if (!named)
562
- return void 0;
563
- const versioned = plain(version);
564
- return { name: named, ...versioned ? { version: versioned } : {} };
565
- }, "clientFrom");
566
- var callerOf = /* @__PURE__ */ __name((ctx, tool, source) => {
567
- const meta = ctx?.mcpReq?._meta;
568
- const requestId = ctx?.mcpReq?.id;
569
- const initialized = source.client?.();
570
- const proxied = initialized?.name === PROXY_CLIENT_NAME && !ctx?.http ? passedOn(meta?.[CALLER_META_KEY], tool) : void 0;
571
- if (proxied)
572
- return proxied;
573
- const client = clientFrom(meta?.[CLIENT_INFO_META_KEY]) ?? clientFrom(initialized);
574
- const mcp = /* @__PURE__ */ __name((connection) => ({
575
- tool,
576
- ...requestId === void 0 ? {} : { request_id: String(requestId) },
577
- ...connection ? { connection_id: connection } : {}
578
- }), "mcp");
579
- const auth = ctx?.http?.authInfo;
580
- if (auth) {
581
- const registered = plain(auth.extra?.clientName);
582
- return {
583
- via: "mcp-http",
584
- agent: {
585
- kind: "mcp-client",
586
- session_id: ctx?.sessionId ?? null,
587
- client: {
588
- name: registered ?? client?.name ?? "unknown",
589
- ...client?.version ? { version: client.version } : {},
590
- id: clientHash(auth.clientId)
591
- }
592
- },
593
- mcp: mcp(ctx?.sessionId)
594
- };
595
- }
596
- const agent = agentOf(source.env) ?? { kind: "mcp-client", session_id: null };
597
- return { via: "mcp-stdio", agent: { ...agent, ...client ? { client } : {} }, mcp: mcp(source.connectionId) };
598
- }, "callerOf");
599
- var passedOn = /* @__PURE__ */ __name((value, tool) => {
600
- if (!value || typeof value !== "object")
601
- return void 0;
602
- const { via, agent, mcp } = value;
603
- if (via !== "mcp-stdio" && via !== "mcp-http")
604
- return void 0;
605
- const a = agent && typeof agent === "object" ? agent : void 0;
606
- const kind = plain(a?.kind);
607
- const session = typeof a?.session_id === "string" && /^[A-Za-z0-9._:-]{1,128}$/.test(a.session_id) ? a.session_id : null;
608
- const client = clientFrom(a?.client);
609
- const id = a?.client && typeof a.client === "object" ? a.client.id : void 0;
610
- const m = mcp && typeof mcp === "object" ? mcp : {};
611
- const request = plain(m.request_id);
612
- const connection = typeof m.connection_id === "string" && /^[\w-]{1,128}$/.test(m.connection_id) ? m.connection_id : void 0;
613
- return {
614
- via,
615
- ...kind ? {
616
- agent: {
617
- kind,
618
- session_id: session,
619
- ...a?.from_chat === true ? { from_chat: true } : {},
620
- ...client ? { client: { ...client, ...typeof id === "string" && /^[0-9a-f]{8}$/.test(id) ? { id } : {} } } : {}
621
- }
622
- } : {},
623
- mcp: {
624
- tool,
625
- ...request ? { request_id: request } : {},
626
- ...connection ? { connection_id: connection } : {},
627
- proxied: true
628
- }
629
- };
630
- }, "passedOn");
631
-
632
- // node_modules/.pnpm/@wirecat+cli-core@0.675.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.102.1_commander@15_4538b457841b7e7d546b8c440ab6644a/node_modules/@wirecat/cli-core/dist/mcp/stdio-wire.js
538
+ // node_modules/.pnpm/@wirecat+cli-core@0.714.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.122.0_commander@15_dd9fedf917a0d541ef7fdcdb0be0e64b/node_modules/@wirecat/cli-core/dist/mcp/stdio-wire.js
633
539
  import { PassThrough, Writable } from "node:stream";
634
540
  var lineReader = /* @__PURE__ */ __name((onMessage) => {
635
541
  let rest = "";
@@ -723,9 +629,5 @@ var answeredWire = /* @__PURE__ */ __name((source, sink) => {
723
629
  export {
724
630
  StdioServerTransport,
725
631
  serveStdio,
726
- callingAgent,
727
- CALLER_META_KEY,
728
- PROXY_CLIENT_NAME,
729
- callerOf,
730
632
  answeredWire
731
633
  };
@@ -3,12 +3,97 @@ const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  CliError,
5
5
  isCliError
6
- } from "./chunk-5RDNBG7D.js";
6
+ } from "./chunk-PK5WEGPJ.js";
7
7
  import {
8
8
  __name
9
9
  } from "./chunk-ZVVMGPBJ.js";
10
10
 
11
- // node_modules/.pnpm/@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/hosts.js
11
+ // node_modules/.pnpm/@wirecat+cli-base@0.122.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/body.js
12
+ var interrupted = /* @__PURE__ */ __name((signal) => isCliError(signal.reason) ? signal.reason : new CliError(signal.reason instanceof Error && signal.reason.name === "TimeoutError" ? "timeout" : "cancelled", "HTTP response read was interrupted"), "interrupted");
13
+ var checked = /* @__PURE__ */ __name((signal) => {
14
+ if (signal?.aborted)
15
+ throw interrupted(signal);
16
+ }, "checked");
17
+ var abortable = /* @__PURE__ */ __name(async (pending, signal) => {
18
+ if (!signal)
19
+ return pending;
20
+ let abort = /* @__PURE__ */ __name(() => {
21
+ }, "abort");
22
+ const stopped = new Promise((_, reject) => {
23
+ abort = /* @__PURE__ */ __name(() => reject(interrupted(signal)), "abort");
24
+ signal.addEventListener("abort", abort, { once: true });
25
+ if (signal.aborted)
26
+ abort();
27
+ });
28
+ try {
29
+ return await Promise.race([pending, stopped]);
30
+ } finally {
31
+ signal.removeEventListener("abort", abort);
32
+ }
33
+ }, "abortable");
34
+ var readJsonResponse = /* @__PURE__ */ __name(async (response, options) => {
35
+ const { maxBytes, signal } = options ?? {};
36
+ if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
37
+ throw new CliError("validation_error", "maxBytes must be a positive safe integer");
38
+ if (signal !== void 0 && !(signal instanceof AbortSignal))
39
+ throw new CliError("validation_error", "signal must be an AbortSignal");
40
+ if (signal?.aborted) {
41
+ void response.body?.cancel().catch(() => {
42
+ });
43
+ throw interrupted(signal);
44
+ }
45
+ const length = response.headers.get("content-length");
46
+ if (length !== null && (!/^\d+$/.test(length) || Number(length) > maxBytes)) {
47
+ void response.body?.cancel().catch(() => {
48
+ });
49
+ throw new CliError("invalid_response", "HTTP response exceeds the byte budget");
50
+ }
51
+ if (!response.body)
52
+ throw new CliError("invalid_response", "HTTP response has no body");
53
+ if (response.body.locked)
54
+ throw new CliError("invalid_response", "HTTP response body is already in use");
55
+ const reader = response.body.getReader();
56
+ const chunks = [];
57
+ let bytes = 0;
58
+ try {
59
+ for (; ; ) {
60
+ checked(signal);
61
+ const part = await abortable(reader.read(), signal);
62
+ checked(signal);
63
+ if (part.done)
64
+ break;
65
+ if (!(part.value instanceof Uint8Array))
66
+ throw new CliError("invalid_response", "HTTP response is not bytes");
67
+ bytes += part.value.byteLength;
68
+ if (bytes > maxBytes)
69
+ throw new CliError("invalid_response", "HTTP response exceeds the byte budget");
70
+ if (part.value.byteLength)
71
+ chunks.push(new Uint8Array(part.value));
72
+ }
73
+ const body = new Uint8Array(bytes);
74
+ let offset = 0;
75
+ for (const chunk of chunks) {
76
+ body.set(chunk, offset);
77
+ offset += chunk.byteLength;
78
+ }
79
+ try {
80
+ return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
81
+ } catch {
82
+ throw new CliError("invalid_response", "HTTP response is not valid UTF-8 JSON");
83
+ }
84
+ } catch (error) {
85
+ checked(signal);
86
+ if (isCliError(error))
87
+ throw error;
88
+ throw new CliError("network_error", "HTTP response could not be read");
89
+ } finally {
90
+ void reader.cancel().catch(() => {
91
+ });
92
+ reader.releaseLock();
93
+ }
94
+ }, "readJsonResponse");
95
+
96
+ // node_modules/.pnpm/@wirecat+cli-base@0.122.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/hosts.js
12
97
  var LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
13
98
  var HOST_PATTERN = new RegExp(`^(?:${LABEL}(?:\\.${LABEL})*|\\*\\.${LABEL}(?:\\.${LABEL})+)$`);
14
99
  var hostProblems = /* @__PURE__ */ __name((hosts) => [
@@ -20,7 +105,7 @@ var hostCovered = /* @__PURE__ */ __name((hostname, hosts) => {
20
105
  return hosts.some((host) => host.startsWith("*.") ? name.endsWith(host.slice(1)) : name === host);
21
106
  }, "hostCovered");
22
107
 
23
- // node_modules/.pnpm/@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/fetch.js
108
+ // node_modules/.pnpm/@wirecat+cli-base@0.122.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/fetch.js
24
109
  var HOST_FETCH_TIMEOUT_MS = 3e4;
25
110
  var REDIRECTS = 5;
26
111
  var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
@@ -46,7 +131,7 @@ var released = /* @__PURE__ */ __name((response, clear) => {
46
131
  return Object.defineProperties(wrapped, { url: { value: url }, redirected: { value: redirected } });
47
132
  }, "released");
48
133
  var undeclared = /* @__PURE__ */ __name((url) => new CliError("configuration_error", `${url.hostname} is not a host this CLI declares: add "${url.hostname}" to \`hosts\` in its WCAT identity and run cli-dev manifest`, { reason: "network.host-undeclared", sent: false }), "undeclared");
49
- var checked = /* @__PURE__ */ __name((url, hosts) => {
134
+ var checked2 = /* @__PURE__ */ __name((url, hosts) => {
50
135
  if (url.protocol !== "https:" && url.protocol !== "http:")
51
136
  throw new CliError("validation_error", `only http and https are fetched, not ${url.protocol.replace(/:$/, "")}`, {
52
137
  sent: false
@@ -55,14 +140,35 @@ var checked = /* @__PURE__ */ __name((url, hosts) => {
55
140
  throw undeclared(url);
56
141
  return url;
57
142
  }, "checked");
143
+ var ENCODED_SLASH = /%2f|%5c/i;
144
+ var scopeOf = /* @__PURE__ */ __name((scope) => {
145
+ if (scope === void 0)
146
+ return void 0;
147
+ if (!URL.canParse(scope))
148
+ throw new CliError("configuration_error", `credentialScope ${scope} is not a URL`);
149
+ const { origin, pathname } = new URL(scope);
150
+ const prefix = pathname.endsWith("/") ? pathname : `${pathname}/`;
151
+ return (url) => url.origin === origin && (url.pathname === pathname || url.pathname.startsWith(prefix)) && !ENCODED_SLASH.test(url.pathname);
152
+ }, "scopeOf");
153
+ var signedHeaders = /* @__PURE__ */ __name((headers) => CREDENTIAL_HEADERS.some((name) => headers.has(name)), "signedHeaders");
154
+ var NOT_SENT = /* @__PURE__ */ new Set(["EAI_AGAIN", "ENOTFOUND", "ECONNREFUSED"]);
155
+ var neverSent = /* @__PURE__ */ __name((error) => {
156
+ for (let at = error, depth = 0; at instanceof Error && depth < 4; at = at.cause, depth++) {
157
+ const code = at.code;
158
+ if (typeof code === "string" && NOT_SENT.has(code))
159
+ return true;
160
+ }
161
+ return false;
162
+ }, "neverSent");
58
163
  var hostFetch = /* @__PURE__ */ __name((options) => {
59
164
  const problems = hostProblems(options.hosts);
60
165
  if (problems.length > 0)
61
166
  throw new CliError("configuration_error", problems.join("; "));
62
167
  const { hosts, fetch: send = globalThis.fetch, timeoutMs = HOST_FETCH_TIMEOUT_MS, redirects = REDIRECTS } = options;
168
+ const inScope = scopeOf(options.credentialScope);
63
169
  return async (input, init = {}) => {
64
170
  const request = input instanceof Request ? input : void 0;
65
- let url = checked(new URL(request?.url ?? String(input)), hosts);
171
+ let url = checked2(new URL(request?.url ?? String(input)), hosts);
66
172
  const caller = init.signal ?? request?.signal;
67
173
  const timeout = deadline(timeoutMs);
68
174
  const signal = caller ? AbortSignal.any([caller, timeout.signal]) : timeout.signal;
@@ -70,8 +176,14 @@ var hostFetch = /* @__PURE__ */ __name((options) => {
70
176
  let method = (init.method ?? request?.method ?? "GET").toUpperCase();
71
177
  let body = init.body ?? request?.body ?? void 0;
72
178
  const headers = new Headers(init.headers ?? request?.headers);
179
+ if (inScope && signedHeaders(headers) && !inScope(url))
180
+ throw new CliError("configuration_error", `the sign-in goes only under ${options.credentialScope}, not ${url.origin}${url.pathname}`, {
181
+ sent: false
182
+ });
183
+ let answered = false;
73
184
  try {
74
185
  let response = await send(input, { ...init, signal, ...follow ? { redirect: "manual" } : {} });
186
+ answered = true;
75
187
  for (let hop = 0; follow && REDIRECT_STATUSES.has(response.status); hop += 1) {
76
188
  const location = response.headers.get("location");
77
189
  if (!location)
@@ -80,7 +192,7 @@ var hostFetch = /* @__PURE__ */ __name((options) => {
80
192
  throw new CliError("invalid_response", `more than ${redirects} redirects from ${url.hostname}`);
81
193
  void response.body?.cancel().catch(() => {
82
194
  });
83
- const next = checked(new URL(location, url), hosts);
195
+ const next = checked2(new URL(location, url), hosts);
84
196
  if (response.status === 303 || (response.status === 301 || response.status === 302) && method === "POST") {
85
197
  method = method === "HEAD" ? "HEAD" : "GET";
86
198
  body = void 0;
@@ -88,7 +200,7 @@ var hostFetch = /* @__PURE__ */ __name((options) => {
88
200
  headers.delete("content-length");
89
201
  } else if (body instanceof ReadableStream)
90
202
  throw new CliError("invalid_response", `${url.hostname} redirected a streamed body, which cannot be sent again`);
91
- if (next.origin !== url.origin)
203
+ if (inScope ? !inScope(next) : next.origin !== url.origin)
92
204
  for (const name of CREDENTIAL_HEADERS)
93
205
  headers.delete(name);
94
206
  url = next;
@@ -103,12 +215,15 @@ var hostFetch = /* @__PURE__ */ __name((options) => {
103
215
  throw isCliError(caller.reason) ? caller.reason : new CliError("cancelled", "request cancelled");
104
216
  if (timeout.signal.aborted)
105
217
  throw new CliError("timeout", `${url.hostname} did not answer within ${timeoutMs} ms`, { retryable: true });
106
- throw new CliError("network_error", `${url.hostname} could not be reached`, { retryable: true });
218
+ throw new CliError("network_error", `${url.hostname} could not be reached`, {
219
+ retryable: true,
220
+ ...!answered && neverSent(error) ? { sent: false } : {}
221
+ });
107
222
  }
108
223
  };
109
224
  }, "hostFetch");
110
225
 
111
- // node_modules/.pnpm/@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/index.js
226
+ // node_modules/.pnpm/@wirecat+cli-base@0.122.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/index.js
112
227
  var parseRetryAfter = /* @__PURE__ */ __name((header, now) => {
113
228
  if (!header)
114
229
  return void 0;
@@ -131,8 +246,25 @@ var parseRateLimitReset = /* @__PURE__ */ __name((header, now) => {
131
246
  return delta > 0 ? delta : void 0;
132
247
  }, "parseRateLimitReset");
133
248
  var providerWaitMs = /* @__PURE__ */ __name((headers, now) => parseRetryAfter(headers.get("retry-after"), now) ?? parseRateLimitReset(headers.get("x-ratelimit-reset"), now), "providerWaitMs");
249
+ var statusToCode = /* @__PURE__ */ __name((status) => {
250
+ if (status === 400 || status === 422)
251
+ return "validation_error";
252
+ if (status === 401)
253
+ return "authentication_error";
254
+ if (status === 403)
255
+ return "permission_error";
256
+ if (status === 404)
257
+ return "not_found";
258
+ if (status === 408)
259
+ return "timeout";
260
+ if (status === 429)
261
+ return "rate_limited";
262
+ if (status === 502 || status === 503 || status === 504)
263
+ return "provider_unavailable";
264
+ return "provider_error";
265
+ }, "statusToCode");
134
266
 
135
- // node_modules/.pnpm/@wirecat+cli-core@0.675.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.102.1_commander@15_4538b457841b7e7d546b8c440ab6644a/node_modules/@wirecat/cli-core/dist/models/endpoint.js
267
+ // node_modules/.pnpm/@wirecat+cli-core@0.714.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.122.0_commander@15_dd9fedf917a0d541ef7fdcdb0be0e64b/node_modules/@wirecat/cli-core/dist/models/endpoint.js
136
268
  var endpoint = /* @__PURE__ */ __name((value) => {
137
269
  try {
138
270
  const url = new URL(value);
@@ -186,8 +318,10 @@ var endpointFetch = /* @__PURE__ */ __name((address, timeoutMs) => {
186
318
  }, "endpointFetch");
187
319
 
188
320
  export {
321
+ readJsonResponse,
189
322
  hostFetch,
190
323
  providerWaitMs,
324
+ statusToCode,
191
325
  endpoint,
192
326
  onThisComputer,
193
327
  modelAddressAllowed,
@@ -5,12 +5,12 @@ import {
5
5
  } from "./chunk-Y5E2WNWB.js";
6
6
  import {
7
7
  CliError
8
- } from "./chunk-5RDNBG7D.js";
8
+ } from "./chunk-PK5WEGPJ.js";
9
9
  import {
10
10
  __name
11
11
  } from "./chunk-ZVVMGPBJ.js";
12
12
 
13
- // node_modules/.pnpm/@wirecat+cli-core@0.675.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.102.1_commander@15_4538b457841b7e7d546b8c440ab6644a/node_modules/@wirecat/cli-core/dist/store/vector-extension.js
13
+ // node_modules/.pnpm/@wirecat+cli-core@0.714.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.122.0_commander@15_dd9fedf917a0d541ef7fdcdb0be0e64b/node_modules/@wirecat/cli-core/dist/store/vector-extension.js
14
14
  import { readFileSync } from "node:fs";
15
15
  var musl = /* @__PURE__ */ __name(() => {
16
16
  if (process.platform !== "linux")