@qwen-code/qwen-code 0.18.0-preview.1 → 0.18.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 (141) hide show
  1. package/bundled/qc-helper/SKILL.md +1 -2
  2. package/bundled/qc-helper/docs/_meta.ts +1 -0
  3. package/bundled/qc-helper/docs/configuration/settings.md +20 -24
  4. package/bundled/qc-helper/docs/features/_meta.ts +0 -3
  5. package/bundled/qc-helper/docs/features/approval-mode.md +10 -14
  6. package/bundled/qc-helper/docs/features/commands.md +47 -23
  7. package/bundled/qc-helper/docs/features/followup-suggestions.md +2 -2
  8. package/bundled/qc-helper/docs/features/scheduled-tasks.md +1 -1
  9. package/bundled/qc-helper/docs/features/sub-agents.md +60 -0
  10. package/bundled/qc-helper/docs/qwen-serve-deploy-local.md +221 -0
  11. package/bundled/qc-helper/docs/qwen-serve.md +234 -24
  12. package/chunks/{agent-SXS4NQWS.js → agent-LOTJK6AH.js} +25 -19
  13. package/chunks/agent-headless-TU3EPMYU.js +50 -0
  14. package/chunks/{anthropicContentGenerator-4QBVSFSJ.js → anthropicContentGenerator-2HBRNQ3B.js} +7 -7
  15. package/chunks/{askUserQuestion-NOOLRWCJ.js → askUserQuestion-OGCMIBQM.js} +45 -3
  16. package/chunks/{ca-WRHFBIDH.js → ca-BARBRL6N.js} +48 -1
  17. package/chunks/{chunk-JMLIPZUU.js → chunk-2Y5SYSD3.js} +361 -583
  18. package/chunks/chunk-3DHXZ6EV.js +241 -0
  19. package/chunks/{chunk-AVLOK27J.js → chunk-3HTIVKZE.js} +1 -1
  20. package/chunks/{chunk-BNESGOSJ.js → chunk-55ZMG67I.js} +1 -1
  21. package/chunks/chunk-64WXLC72.js +98 -0
  22. package/chunks/{chunk-F6FLCHCS.js → chunk-6YIUGZTC.js} +1069 -211
  23. package/chunks/{chunk-C6WMLUNB.js → chunk-72LDN5PP.js} +1 -1
  24. package/chunks/{chunk-ERREX2ES.js → chunk-7BCMOPIM.js} +64 -24
  25. package/chunks/{chunk-6VFG3EUJ.js → chunk-A7B4ISQP.js} +1 -1
  26. package/chunks/{chunk-F5ORN4YO.js → chunk-B7HXHOHU.js} +1 -1
  27. package/chunks/{chunk-5RNZ2QKF.js → chunk-BIVG75CP.js} +1 -1
  28. package/chunks/{chunk-MVX64PNU.js → chunk-EYENRK4D.js} +1 -1
  29. package/chunks/{chunk-SZOEIL6S.js → chunk-H6BD2ELD.js} +1 -0
  30. package/chunks/{chunk-SCHRFI7O.js → chunk-HLPLOD42.js} +1 -1
  31. package/chunks/{chunk-R5PDRHEF.js → chunk-HR7SV7AY.js} +68 -47
  32. package/chunks/{chunk-JSYEZAYV.js → chunk-IDX6COTE.js} +2 -2
  33. package/chunks/{chunk-6KH2Q7XN.js → chunk-IWAYOW5Q.js} +17482 -11669
  34. package/chunks/chunk-J5MDQKJL.js +2230 -0
  35. package/chunks/{chunk-USE2VQ5P.js → chunk-JTQAQBTV.js} +21 -0
  36. package/chunks/{chunk-ZW7GBCRE.js → chunk-LBP46COL.js} +1014 -163
  37. package/chunks/chunk-LD2XBG6Z.js +102 -0
  38. package/chunks/{chunk-KOA52UTF.js → chunk-LEJ42GNY.js} +14 -14
  39. package/chunks/{chunk-D46KOV3C.js → chunk-M6VTDSVR.js} +1 -1
  40. package/chunks/{chunk-SHUT5MQY.js → chunk-MFBBBTNY.js} +1 -1
  41. package/chunks/{chunk-PLYZAP4W.js → chunk-OHEGWO4L.js} +101 -23
  42. package/chunks/{chunk-NQZ33PWX.js → chunk-PL3MVCWD.js} +11 -11
  43. package/chunks/chunk-QQDPRDVW.js +25 -0
  44. package/chunks/chunk-R7ODSGTK.js +159 -0
  45. package/chunks/{chunk-GBEPNWYB.js → chunk-SEGYWKIH.js} +1 -1
  46. package/chunks/chunk-SKBPNJEW.js +45 -0
  47. package/chunks/{chunk-UABFCMPA.js → chunk-SNGELLWX.js} +3 -1
  48. package/chunks/chunk-XBY7E2FX.js +605 -0
  49. package/chunks/{chunk-G763GDO6.js → chunk-XV4HCEVI.js} +36 -3
  50. package/chunks/{chunk-WFVXF3OM.js → chunk-Z2Z3GUXZ.js} +1 -0
  51. package/chunks/{chunk-BBTV54KB.js → chunk-ZTZ4DDQE.js} +2 -2
  52. package/chunks/{computer-use-CT6MU6P3.js → computer-use-3RH2DOM6.js} +25 -19
  53. package/chunks/contextCommand-K347QT6O.js +52 -0
  54. package/chunks/{cron-create-PIPMXQN4.js → cron-create-YJL3KFWI.js} +3 -3
  55. package/chunks/{cron-delete-6Y5XIDMS.js → cron-delete-WKWSJZQA.js} +3 -3
  56. package/chunks/{cron-list-A4WNRUWZ.js → cron-list-B52XEXAZ.js} +3 -3
  57. package/chunks/{de-M5RPB2NB.js → de-YGKK2BC4.js} +48 -1
  58. package/chunks/{devtools-IXE4UP72.js → devtools-FM6GJPYG.js} +1 -1
  59. package/chunks/{dist-R2SXPG74.js → dist-4LXD6L6X.js} +2 -2
  60. package/chunks/{dist-TE5QKMGR.js → dist-H6ONXVLG.js} +1 -1
  61. package/chunks/{dist-ZMQ4TXD5.js → dist-KAZ3SEBX.js} +2 -2
  62. package/chunks/{dist-BXDUQ2QY.js → dist-PK7DFCAW.js} +1 -1
  63. package/chunks/{edit-A4YK7AIB.js → edit-KU4PJGEX.js} +26 -20
  64. package/chunks/{en-UMYKQAZE.js → en-DHGYHIHX.js} +77 -2
  65. package/chunks/{enter-worktree-VNEQINLC.js → enter-worktree-PPYIDCWI.js} +25 -19
  66. package/chunks/enterPlanMode-5CZDMCB4.js +158 -0
  67. package/chunks/{exit-worktree-AVSMXC33.js → exit-worktree-UY3CGHKC.js} +25 -19
  68. package/chunks/exitPlanMode-3DN4QNSG.js +703 -0
  69. package/chunks/{fr-MPYXXXPW.js → fr-JXBKPJKQ.js} +48 -1
  70. package/chunks/{geminiContentGenerator-CR2WGARL.js → geminiContentGenerator-7A6I2RWB.js} +7 -7
  71. package/chunks/{getMachineId-bsd-F7GNPTER.js → getMachineId-bsd-4CASPIU4.js} +1 -1
  72. package/chunks/{getMachineId-darwin-T73DJL27.js → getMachineId-darwin-HPQPEMZR.js} +1 -1
  73. package/chunks/{getMachineId-linux-MKQTFPQM.js → getMachineId-linux-AUARKYHL.js} +1 -1
  74. package/chunks/{getMachineId-unsupported-MUR5KOQE.js → getMachineId-unsupported-S32ZDA2T.js} +1 -1
  75. package/chunks/{getMachineId-win-CDYFC6ZM.js → getMachineId-win-4EFLHYIJ.js} +1 -1
  76. package/chunks/{glob-5V32KOG5.js → glob-OFNQSS52.js} +25 -19
  77. package/chunks/{grep-PUTEPBR4.js → grep-6J2MSUM5.js} +28 -19
  78. package/chunks/{ja-NFZ32AB3.js → ja-TGPZSP2B.js} +48 -1
  79. package/chunks/{keychain-token-storage-UHGOCDD6.js → keychain-token-storage-6IU6ORQN.js} +3 -3
  80. package/chunks/{ls-34DLNYCD.js → ls-V3O6A5PT.js} +4 -4
  81. package/chunks/{lsp-NCDEHH3V.js → lsp-G2OCIFUA.js} +3 -3
  82. package/chunks/{monitor-EJBR5VCR.js → monitor-FKLHV423.js} +25 -19
  83. package/chunks/{notebook-edit-DZHGPP2L.js → notebook-edit-KTBYFKWG.js} +26 -20
  84. package/chunks/{openaiContentGenerator-4QNV3CHM.js → openaiContentGenerator-L5KSWQY7.js} +15 -14
  85. package/chunks/{pt-BR43FRBA.js → pt-TIBG6BIO.js} +48 -1
  86. package/chunks/{qwenContentGenerator-3XOCEMQO.js → qwenContentGenerator-PYOXLMBW.js} +27 -21
  87. package/chunks/{qwenOAuth2-KRJT35QH.js → qwenOAuth2-2KCKWDCF.js} +6 -5
  88. package/chunks/{read-file-VZ2SQQIX.js → read-file-JQVRK4NU.js} +11 -11
  89. package/chunks/ripGrep-2L4LPNAJ.js +48 -0
  90. package/chunks/{ru-DQCW2KHD.js → ru-JBCHCK4L.js} +48 -1
  91. package/chunks/{scheduler-H32DZVDV.js → scheduler-FGNXY4JQ.js} +25 -19
  92. package/chunks/send-message-SZFWNOCL.js +244 -0
  93. package/chunks/{serve-56G4B5W6.js → serve-N2IBLA3G.js} +13592 -4979
  94. package/chunks/{shell-Q77KNP4N.js → shell-PTEG6UX4.js} +25 -19
  95. package/chunks/{skill-CLWFJYBG.js → skill-X4NTK4NH.js} +64 -113
  96. package/chunks/{src-47L2LUOU.js → src-GLLQ3R5W.js} +307 -32
  97. package/chunks/{syntheticOutput-T5SWX3YF.js → syntheticOutput-IKAY5F6X.js} +4 -4
  98. package/chunks/task-create-MQICOJFV.js +19 -0
  99. package/chunks/task-list-RIHJCH32.js +151 -0
  100. package/chunks/{task-stop-3VHAQMYM.js → task-stop-FWZRFANS.js} +3 -3
  101. package/chunks/task-update-2LHPXOYM.js +408 -0
  102. package/chunks/team-create-2E4PF4KN.js +314 -0
  103. package/chunks/team-delete-DAUDQS4J.js +116 -0
  104. package/chunks/{todoWrite-EAGJGKO5.js → todoWrite-HTUACZES.js} +5 -5
  105. package/chunks/{tool-search-Q75AYDTP.js → tool-search-KTVULRES.js} +11 -11
  106. package/chunks/{web-fetch-SS6IKK6N.js → web-fetch-CZ7LLKPE.js} +5 -5
  107. package/chunks/workflow-L2ZUUDT2.js +960 -0
  108. package/chunks/{write-file-RENGC25N.js → write-file-ZEB2JDYH.js} +26 -20
  109. package/chunks/{zh-6VFXOAR5.js → zh-7H5OQC4I.js} +82 -7
  110. package/chunks/{zh-TW-IQZ4AD5M.js → zh-TW-P4IDHD3M.js} +79 -7
  111. package/cli.js +11248 -5119
  112. package/examples/agent/qwen-extension.json +1 -0
  113. package/examples/commands/qwen-extension.json +1 -0
  114. package/examples/context/qwen-extension.json +1 -0
  115. package/examples/mcp-server/qwen-extension.json +1 -0
  116. package/examples/skills/qwen-extension.json +1 -0
  117. package/examples/starter/QWEN.md +30 -0
  118. package/examples/starter/README.md +59 -0
  119. package/examples/starter/agents/diary.md +86 -0
  120. package/examples/starter/commands/writing/polish.md +13 -0
  121. package/examples/starter/example.ts +64 -0
  122. package/examples/starter/package.json +18 -0
  123. package/examples/starter/qwen-extension.json +12 -0
  124. package/examples/starter/skills/synonyms/SKILL.md +48 -0
  125. package/examples/starter/tsconfig.json +13 -0
  126. package/fzfWorker.js +1083 -0
  127. package/locales/ca.js +51 -0
  128. package/locales/de.js +51 -0
  129. package/locales/en.js +89 -2
  130. package/locales/fr.js +53 -2
  131. package/locales/ja.js +52 -2
  132. package/locales/pt.js +52 -2
  133. package/locales/ru.js +53 -2
  134. package/locales/zh-TW.js +90 -11
  135. package/locales/zh.js +94 -11
  136. package/package.json +3 -2
  137. package/bundled/qc-helper/docs/features/checkpointing.md +0 -77
  138. package/chunks/contextCommand-YODJQYIV.js +0 -46
  139. package/chunks/exitPlanMode-5SQYVROD.js +0 -229
  140. package/chunks/ripGrep-SBIZCPOL.js +0 -42
  141. package/chunks/send-message-YYF56TS7.js +0 -151
@@ -0,0 +1,241 @@
1
+ // Force strict mode and setup for ESM
2
+ "use strict";
3
+ import {
4
+ Mutex,
5
+ getInboxesDir,
6
+ require_proper_lockfile
7
+ } from "./chunk-J5MDQKJL.js";
8
+ import {
9
+ atomicWriteJSON
10
+ } from "./chunk-B7HXHOHU.js";
11
+ import {
12
+ createDebugLogger,
13
+ isNodeError
14
+ } from "./chunk-HR7SV7AY.js";
15
+ import {
16
+ init_esbuild_shims
17
+ } from "./chunk-A4BMJM77.js";
18
+ import {
19
+ __name,
20
+ __toESM
21
+ } from "./chunk-J2S4EL5Y.js";
22
+
23
+ // packages/core/src/agents/team/leaderPermissionBridge.ts
24
+ init_esbuild_shims();
25
+ var leaderCallbacks = null;
26
+ function registerLeader(callbacks) {
27
+ leaderCallbacks = callbacks;
28
+ }
29
+ __name(registerLeader, "registerLeader");
30
+ function getLeader() {
31
+ return leaderCallbacks;
32
+ }
33
+ __name(getLeader, "getLeader");
34
+ function unregisterLeader() {
35
+ leaderCallbacks = null;
36
+ }
37
+ __name(unregisterLeader, "unregisterLeader");
38
+ function forwardApproval(teammateName, teammateColor, details) {
39
+ if (!leaderCallbacks) {
40
+ return false;
41
+ }
42
+ leaderCallbacks.enqueueApproval({
43
+ teammateName,
44
+ teammateColor,
45
+ details
46
+ });
47
+ return true;
48
+ }
49
+ __name(forwardApproval, "forwardApproval");
50
+ function wrapConfirmWithBadge(original, teammateName, respond, _teammateColor) {
51
+ return {
52
+ ...original,
53
+ title: `[${teammateName}] ${original.title}`,
54
+ onConfirm: /* @__PURE__ */ __name(async (outcome, payload) => {
55
+ await respond(outcome, payload);
56
+ }, "onConfirm")
57
+ };
58
+ }
59
+ __name(wrapConfirmWithBadge, "wrapConfirmWithBadge");
60
+
61
+ // packages/core/src/agents/team/mailbox.ts
62
+ init_esbuild_shims();
63
+ var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
64
+ import * as fs from "node:fs/promises";
65
+ import * as path from "node:path";
66
+ var debug = createDebugLogger("AGENTS_TEAM_MAILBOX");
67
+ var LOCK_OPTIONS = {
68
+ retries: {
69
+ retries: 10,
70
+ minTimeout: 5,
71
+ maxTimeout: 100,
72
+ factor: 2,
73
+ // Jitter the backoff so cross-process contenders don't retry in
74
+ // lockstep (thundering herd) and starve each other out of the
75
+ // retry budget.
76
+ randomize: true
77
+ },
78
+ stale: 5e3,
79
+ // Stale locks from crashed processes are expected in multi-agent
80
+ // scenarios; log at debug level for traceability without noise.
81
+ onCompromised: /* @__PURE__ */ __name((err) => {
82
+ debug.debug("mailbox lock compromised:", err?.message ?? err);
83
+ }, "onCompromised")
84
+ };
85
+ var inboxLocks = /* @__PURE__ */ new Map();
86
+ function getInboxLock(inboxPath) {
87
+ let lock = inboxLocks.get(inboxPath);
88
+ if (!lock) {
89
+ lock = new Mutex();
90
+ inboxLocks.set(inboxPath, lock);
91
+ }
92
+ return lock;
93
+ }
94
+ __name(getInboxLock, "getInboxLock");
95
+ function disposeInboxLocks(teamName) {
96
+ const dir = getInboxesDir(teamName);
97
+ let evicted = 0;
98
+ for (const key of inboxLocks.keys()) {
99
+ if (path.dirname(key) === dir) {
100
+ inboxLocks.delete(key);
101
+ evicted++;
102
+ }
103
+ }
104
+ return evicted;
105
+ }
106
+ __name(disposeInboxLocks, "disposeInboxLocks");
107
+ async function withInboxLock(inboxPath, fn) {
108
+ return getInboxLock(inboxPath).runExclusive(async () => {
109
+ const release = await import_proper_lockfile.default.lock(inboxPath, LOCK_OPTIONS);
110
+ try {
111
+ return await fn();
112
+ } finally {
113
+ await release();
114
+ }
115
+ });
116
+ }
117
+ __name(withInboxLock, "withInboxLock");
118
+ function getInboxPath(teamName, agentName) {
119
+ return path.join(getInboxesDir(teamName), `${agentName}.json`);
120
+ }
121
+ __name(getInboxPath, "getInboxPath");
122
+ async function readInbox(teamName, agentName) {
123
+ const inboxPath = getInboxPath(teamName, agentName);
124
+ try {
125
+ const raw = await fs.readFile(inboxPath, "utf-8");
126
+ return JSON.parse(raw);
127
+ } catch (err) {
128
+ if (isNodeError(err) && err.code === "ENOENT") return [];
129
+ throw err;
130
+ }
131
+ }
132
+ __name(readInbox, "readInbox");
133
+ var READ_RETENTION_MS = 5 * 60 * 1e3;
134
+ async function writeMessage(teamName, toAgentName, message) {
135
+ const inboxPath = getInboxPath(teamName, toAgentName);
136
+ await ensureInboxFile(inboxPath);
137
+ await withInboxLock(inboxPath, async () => {
138
+ const messages = await readInboxRaw(inboxPath);
139
+ const cutoff = Date.now() - READ_RETENTION_MS;
140
+ const compacted = messages.filter((m) => {
141
+ if (!m.read) return true;
142
+ const ts = Date.parse(m.timestamp);
143
+ return Number.isNaN(ts) || ts >= cutoff;
144
+ });
145
+ compacted.push(message);
146
+ await atomicWriteJSON(inboxPath, compacted);
147
+ });
148
+ }
149
+ __name(writeMessage, "writeMessage");
150
+ async function consumeUnread(teamName, agentName, type) {
151
+ const inboxPath = getInboxPath(teamName, agentName);
152
+ await ensureInboxFile(inboxPath);
153
+ return withInboxLock(inboxPath, async () => {
154
+ const messages = await readInboxRaw(inboxPath);
155
+ const predicate = /* @__PURE__ */ __name((m) => !m.read && (type === void 0 || m.type === type), "predicate");
156
+ const matching = messages.filter(predicate);
157
+ if (matching.length === 0) return [];
158
+ const updated = messages.map(
159
+ (m) => predicate(m) ? { ...m, read: true } : m
160
+ );
161
+ await atomicWriteJSON(inboxPath, updated);
162
+ return matching;
163
+ });
164
+ }
165
+ __name(consumeUnread, "consumeUnread");
166
+ async function clearInbox(teamName, agentName) {
167
+ const inboxPath = getInboxPath(teamName, agentName);
168
+ try {
169
+ await fs.unlink(inboxPath);
170
+ } catch (err) {
171
+ if (!isNodeError(err) || err.code !== "ENOENT") throw err;
172
+ }
173
+ }
174
+ __name(clearInbox, "clearInbox");
175
+ async function clearAllInboxes(teamName) {
176
+ const dir = getInboxesDir(teamName);
177
+ await fs.rm(dir, { recursive: true, force: true });
178
+ disposeInboxLocks(teamName);
179
+ }
180
+ __name(clearAllInboxes, "clearAllInboxes");
181
+ async function sendStructuredMessage(teamName, toAgentName, opts) {
182
+ await writeMessage(teamName, toAgentName, {
183
+ from: opts.from,
184
+ text: opts.text,
185
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
186
+ read: false,
187
+ type: opts.type,
188
+ color: opts.color,
189
+ summary: opts.summary
190
+ });
191
+ }
192
+ __name(sendStructuredMessage, "sendStructuredMessage");
193
+ async function ensureInboxFile(inboxPath) {
194
+ await fs.mkdir(path.dirname(inboxPath), { recursive: true });
195
+ try {
196
+ await fs.writeFile(inboxPath, "[]\n", { flag: "wx" });
197
+ } catch (err) {
198
+ if (!isNodeError(err) || err.code !== "EEXIST") throw err;
199
+ }
200
+ }
201
+ __name(ensureInboxFile, "ensureInboxFile");
202
+ async function readInboxRaw(inboxPath) {
203
+ try {
204
+ const raw = await fs.readFile(inboxPath, "utf-8");
205
+ return JSON.parse(raw);
206
+ } catch (err) {
207
+ if (isNodeError(err) && err.code === "ENOENT") return [];
208
+ const errMsg = err instanceof Error ? err.message : String(err);
209
+ debug.warn(`Quarantining corrupt inbox at ${inboxPath}: ${errMsg}`);
210
+ try {
211
+ await fs.rename(inboxPath, `${inboxPath}.corrupt-${Date.now()}`);
212
+ } catch (renameErr) {
213
+ const renameMsg = renameErr instanceof Error ? renameErr.message : String(renameErr);
214
+ debug.warn(`Failed to quarantine ${inboxPath}: ${renameMsg}`);
215
+ throw err instanceof Error ? err : new Error(`Failed to read inbox at ${inboxPath}: ${errMsg}`);
216
+ }
217
+ return [];
218
+ }
219
+ }
220
+ __name(readInboxRaw, "readInboxRaw");
221
+
222
+ export {
223
+ registerLeader,
224
+ getLeader,
225
+ unregisterLeader,
226
+ forwardApproval,
227
+ wrapConfirmWithBadge,
228
+ disposeInboxLocks,
229
+ getInboxPath,
230
+ readInbox,
231
+ writeMessage,
232
+ consumeUnread,
233
+ clearInbox,
234
+ clearAllInboxes,
235
+ sendStructuredMessage
236
+ };
237
+ /**
238
+ * @license
239
+ * Copyright 2025 Qwen
240
+ * SPDX-License-Identifier: Apache-2.0
241
+ */
@@ -5,7 +5,7 @@ import {
5
5
  Storage,
6
6
  resolvePath,
7
7
  sanitizeCwd
8
- } from "./chunk-R5PDRHEF.js";
8
+ } from "./chunk-HR7SV7AY.js";
9
9
  import {
10
10
  init_esbuild_shims
11
11
  } from "./chunk-A4BMJM77.js";
@@ -2,7 +2,7 @@
2
2
  "use strict";
3
3
  import {
4
4
  import_websocket
5
- } from "./chunk-SZOEIL6S.js";
5
+ } from "./chunk-H6BD2ELD.js";
6
6
  import {
7
7
  init_esbuild_shims
8
8
  } from "./chunk-A4BMJM77.js";
@@ -0,0 +1,98 @@
1
+ // Force strict mode and setup for ESM
2
+ "use strict";
3
+ import {
4
+ init_esbuild_shims
5
+ } from "./chunk-A4BMJM77.js";
6
+ import {
7
+ __name
8
+ } from "./chunk-J2S4EL5Y.js";
9
+
10
+ // packages/core/src/utils/abortController.ts
11
+ init_esbuild_shims();
12
+ import { setMaxListeners } from "node:events";
13
+ var DEFAULT_MAX_LISTENERS = 50;
14
+ function createAbortController(maxListeners = DEFAULT_MAX_LISTENERS) {
15
+ const controller = new AbortController();
16
+ setMaxListeners(maxListeners, controller.signal);
17
+ return controller;
18
+ }
19
+ __name(createAbortController, "createAbortController");
20
+ function asSignal(parent) {
21
+ if (!parent) return void 0;
22
+ return parent instanceof AbortController ? parent.signal : parent;
23
+ }
24
+ __name(asSignal, "asSignal");
25
+ function createChildAbortController(parent, maxListeners) {
26
+ const child = createAbortController(maxListeners);
27
+ const parentSignal = asSignal(parent);
28
+ if (!parentSignal) return child;
29
+ if (parentSignal.aborted) {
30
+ child.abort(parentSignal.reason);
31
+ return child;
32
+ }
33
+ const weakParent = new WeakRef(parentSignal);
34
+ const handler = /* @__PURE__ */ __name(() => {
35
+ child.abort(weakParent.deref()?.reason);
36
+ }, "handler");
37
+ parentSignal.addEventListener("abort", handler, { once: true });
38
+ child.signal.addEventListener(
39
+ "abort",
40
+ () => {
41
+ weakParent.deref()?.removeEventListener("abort", handler);
42
+ },
43
+ { once: true }
44
+ );
45
+ return child;
46
+ }
47
+ __name(createChildAbortController, "createChildAbortController");
48
+ function combineAbortSignals(signals, options) {
49
+ const controller = createAbortController(options?.maxListeners);
50
+ const alreadyAborted = signals.find((s) => s?.aborted);
51
+ if (alreadyAborted) {
52
+ controller.abort(alreadyAborted.reason);
53
+ return { signal: controller.signal, cleanup: /* @__PURE__ */ __name(() => {
54
+ }, "cleanup") };
55
+ }
56
+ const cleanups = [];
57
+ for (const sourceSignal of signals) {
58
+ if (!sourceSignal) continue;
59
+ if (sourceSignal.aborted) {
60
+ controller.abort(sourceSignal.reason);
61
+ break;
62
+ }
63
+ const handler = /* @__PURE__ */ __name(() => controller.abort(sourceSignal.reason), "handler");
64
+ sourceSignal.addEventListener("abort", handler, { once: true });
65
+ cleanups.push(() => sourceSignal.removeEventListener("abort", handler));
66
+ }
67
+ const timeoutMs = options?.timeoutMs;
68
+ if (timeoutMs !== void 0 && timeoutMs > 0 && !controller.signal.aborted) {
69
+ const timeoutId = setTimeout(() => {
70
+ controller.abort(new DOMException("Operation timed out", "TimeoutError"));
71
+ }, timeoutMs);
72
+ cleanups.push(() => clearTimeout(timeoutId));
73
+ }
74
+ let done = false;
75
+ const cleanup = /* @__PURE__ */ __name(() => {
76
+ if (done) return;
77
+ done = true;
78
+ for (const fn of cleanups) fn();
79
+ }, "cleanup");
80
+ if (controller.signal.aborted) {
81
+ cleanup();
82
+ } else {
83
+ controller.signal.addEventListener("abort", cleanup, { once: true });
84
+ }
85
+ return { signal: controller.signal, cleanup };
86
+ }
87
+ __name(combineAbortSignals, "combineAbortSignals");
88
+
89
+ export {
90
+ createAbortController,
91
+ createChildAbortController,
92
+ combineAbortSignals
93
+ };
94
+ /**
95
+ * @license
96
+ * Copyright 2025 Qwen
97
+ * SPDX-License-Identifier: Apache-2.0
98
+ */