@openclaw/slack 2026.7.2-beta.7 → 2026.8.1-beta.3

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 (87) hide show
  1. package/dist/{account-inspect-DEKpg9Ip.js → account-inspect-YJvFBbCR.js} +1 -1
  2. package/dist/account-inspect-api.js +1 -1
  3. package/dist/{accounts-CHAeNZOX.js → accounts-BlzxuYle.js} +7 -3
  4. package/dist/{accounts.runtime-BHD4Ma2R.js → accounts.runtime-CbabBL8x.js} +1 -1
  5. package/dist/{action-runtime-DfuYoMjG.js → action-runtime-D6jg2CQd.js} +193 -125
  6. package/dist/action-runtime.runtime-JtoOK9l5.js +2 -0
  7. package/dist/{actions-D3NuJvva.js → actions-DFk0ANVB.js} +116 -235
  8. package/dist/actions.runtime-CYLsYRai.js +2 -0
  9. package/dist/api.js +17 -17
  10. package/dist/{approval-handler.runtime-BA05P0QT.js → approval-handler.runtime-BNvAoKdK.js} +53 -14
  11. package/dist/{channel-B9fVdW3s.js → channel-CA5w7qDF.js} +209 -110
  12. package/dist/channel-config-api.js +1 -1
  13. package/dist/channel-plugin-api.js +1 -1
  14. package/dist/{channel-type-DXyos1d2.js → channel-type-CZWv55Wu.js} +9 -12
  15. package/dist/{config-adapter-CxBQH8fq.js → channel.setup-CpyYsEXH.js} +83 -25
  16. package/dist/{config-schema-SgZT6nXV.js → config-schema-CN3XZRX5.js} +27 -17
  17. package/dist/conversation-binding-route-DFVLUdYF.js +115 -0
  18. package/dist/{directory-config-CnCIAktf.js → directory-config-BGYyuzWh.js} +3 -3
  19. package/dist/directory-contract-api.js +1 -1
  20. package/dist/{directory-live-DKunWh3A.js → directory-live-DjUJQLbq.js} +13 -22
  21. package/dist/{doctor-contract-CsGH1Dfc.js → doctor-contract-BAy7-EUQ.js} +30 -3
  22. package/dist/doctor-contract-api.js +1 -1
  23. package/dist/{group-policy-NQZti9t-.js → group-policy-DyfB_ZIE.js} +282 -183
  24. package/dist/index.js +4 -1
  25. package/dist/{message-tool-api-DkhFpMoy.js → message-tool-api-CqMr5Rmc.js} +14 -3
  26. package/dist/message-tool-api.js +1 -1
  27. package/dist/{monitor-CmKz0wtI.js → monitor-Chrecrb9.js} +3 -3
  28. package/dist/{outbound-adapter-BkuMp2Vs.js → outbound-adapter-DuRqAQXK.js} +35 -23
  29. package/dist/{pipeline.runtime-DgtmuYCP.js → pipeline.runtime-Bbfd5VFW.js} +1386 -929
  30. package/dist/{policy-PRysPn23.js → policy-BKXSxrIS.js} +18 -14
  31. package/dist/{probe-CgDsSops.js → probe-BVA65leh.js} +38 -18
  32. package/dist/{provider-DmRizMZt.js → provider-CUUiwsg2.js} +3454 -2601
  33. package/dist/{relay-source-Blxj8xb4.js → relay-source-mhpMMRG-.js} +11 -21
  34. package/dist/{replies-4s_Vq_z9.js → replies-SnWyXcsL.js} +84 -27
  35. package/dist/{resolve-channels-yEqmM-3I.js → resolve-channels-BSpqC8jU.js} +39 -12
  36. package/dist/{resolve-users-BOrt5K-5.js → resolve-users-Dvz9pDe0.js} +28 -5
  37. package/dist/{runtime-api-QMb-Q5Ko.js → runtime-api-DBi7xc_g.js} +3 -3
  38. package/dist/runtime-api.js +11 -11
  39. package/dist/{scopes-BJSrkAp6.js → scopes-BSk4GZvZ.js} +1 -1
  40. package/dist/security-contract-api.js +1 -1
  41. package/dist/{send-DsLeZpST.js → send-CtnOxKCc.js} +249 -163
  42. package/dist/{send.runtime-gUdK6V3h.js → send.runtime-kYctMHSd.js} +1 -1
  43. package/dist/setup-entry.js +1 -4
  44. package/dist/setup-plugin-api.js +1 -1
  45. package/dist/{setup-surface-BeNzrMrJ.js → setup-surface-BPFfp6So.js} +6 -6
  46. package/dist/{shared-DgIN3Dcr.js → shared-DJBaslN7.js} +45 -45
  47. package/dist/{block-text-DkHaoGem.js → slack-client-kind-BXyOOICI.js} +17 -2
  48. package/dist/{slash-dispatch.runtime-zPkyl7dB.js → slash-dispatch.runtime-Cf2FTrnf.js} +2 -2
  49. package/dist/{streaming-compat-3_X-21wW.js → streaming-compat-B-e0mqM0.js} +3 -8
  50. package/dist/{target-parsing-N6lHogYZ.js → target-parsing-BnMD2ZqZ.js} +40 -2
  51. package/dist/{targets-KmjP2E8s.js → targets-Cx5W_n3W.js} +1 -1
  52. package/node_modules/@slack/bolt/node_modules/@types/node/README.md +1 -1
  53. package/node_modules/@slack/bolt/node_modules/@types/node/crypto.d.ts +1 -1
  54. package/node_modules/@slack/bolt/node_modules/@types/node/package.json +2 -2
  55. package/node_modules/@slack/socket-mode/node_modules/@types/node/README.md +1 -1
  56. package/node_modules/@slack/socket-mode/node_modules/@types/node/crypto.d.ts +1 -1
  57. package/node_modules/@slack/socket-mode/node_modules/@types/node/package.json +2 -2
  58. package/node_modules/@slack/web-api/node_modules/@types/node/README.md +1 -1
  59. package/node_modules/@slack/web-api/node_modules/@types/node/crypto.d.ts +1 -1
  60. package/node_modules/@slack/web-api/node_modules/@types/node/package.json +2 -2
  61. package/node_modules/undici/lib/cache/memory-cache-store.js +54 -9
  62. package/node_modules/undici/lib/cache/sqlite-cache-store.js +7 -1
  63. package/node_modules/undici/lib/core/request.js +12 -1
  64. package/node_modules/undici/lib/dispatcher/client-h1.js +11 -2
  65. package/node_modules/undici/lib/handler/cache-handler.js +246 -64
  66. package/node_modules/undici/lib/handler/cache-revalidation-handler.js +3 -3
  67. package/node_modules/undici/lib/handler/retry-handler.js +24 -0
  68. package/node_modules/undici/lib/interceptor/cache.js +159 -52
  69. package/node_modules/undici/lib/util/cache.js +324 -62
  70. package/node_modules/undici/lib/util/date.js +23 -6
  71. package/node_modules/undici/lib/web/cookies/util.js +79 -9
  72. package/node_modules/undici/package.json +1 -1
  73. package/openclaw.plugin.json +280 -33
  74. package/package.json +9 -11
  75. package/skills/slack/SKILL.md +10 -68
  76. package/dist/account-reply-mode-DrUXogvO.js +0 -14
  77. package/dist/action-runtime.runtime-DQErZYpz.js +0 -2
  78. package/dist/actions.runtime-BIRU_G4M.js +0 -2
  79. package/dist/channel.setup-CLP5oTvh.js +0 -56
  80. package/dist/preflight-audio.runtime-D5Bgags0.js +0 -3
  81. package/dist/slash-plugin-commands.runtime-Dosfcx3X.js +0 -2
  82. package/node_modules/p-map/index.d.ts +0 -155
  83. package/node_modules/p-map/index.js +0 -285
  84. package/node_modules/p-map/license +0 -9
  85. package/node_modules/p-map/package.json +0 -57
  86. package/node_modules/p-map/readme.md +0 -190
  87. package/dist/{security-audit-DR097212.js → security-audit-B_yKr7MW.js} +1 -1
@@ -1,78 +1,20 @@
1
1
  ---
2
2
  name: slack
3
- description: "Slack tool actions: send/read/edit/delete messages, react, pin/unpin, list pins/reactions/emoji, member info."
3
+ description: "Slack messaging workflows through OpenClaw's message tool."
4
4
  metadata: { "openclaw": { "emoji": "💬", "requires": { "config": ["channels.slack"] } } }
5
+ allowed-tools: ["message"]
5
6
  ---
6
7
 
7
8
  # Slack
8
9
 
9
- Use the `slack` tool. Reuse `channelId` and Slack timestamp message IDs from context when present.
10
+ Use the `message` tool with `channel: "slack"`. The tool schema lists the actions enabled for the current Slack account; do not assume an action that is not present.
10
11
 
11
- ## Inputs
12
+ ## Workflow
12
13
 
13
- - `channelId`: Slack channel ID.
14
- - `messageId`: Slack timestamp, e.g. `1712023032.1234`.
15
- - `to`: `channel:<id>` or `user:<id>` for sends.
16
- - `emoji`: Unicode or `:name:` for reactions.
14
+ - Prefer stable Slack IDs from context. Sends outside the current conversation use `channel:<id>` or `user:<id>` targets.
15
+ - Keep replies in the current thread unless the user asks for a top-level post. For another thread, pass its Slack timestamp as `threadId`; use the same timestamp as `messageId` for message-specific actions.
16
+ - Before editing, deleting, pinning, or reacting to an ambiguous message, read the conversation and resolve its exact ID.
17
+ - When multiple Slack accounts are configured, pass `accountId` rather than guessing.
18
+ - Confirm destructive deletes when the target or intent is unclear.
17
19
 
18
- ## Actions
19
-
20
- ```json
21
- { "action": "sendMessage", "to": "channel:C123", "content": "Hello" }
22
- ```
23
-
24
- ```json
25
- { "action": "readMessages", "channelId": "C123", "limit": 20 }
26
- ```
27
-
28
- ```json
29
- {
30
- "action": "react",
31
- "channelId": "C123",
32
- "messageId": "1712023032.1234",
33
- "emoji": ":white_check_mark:"
34
- }
35
- ```
36
-
37
- ```json
38
- { "action": "reactions", "channelId": "C123", "messageId": "1712023032.1234" }
39
- ```
40
-
41
- ```json
42
- {
43
- "action": "editMessage",
44
- "channelId": "C123",
45
- "messageId": "1712023032.1234",
46
- "content": "Updated text"
47
- }
48
- ```
49
-
50
- ```json
51
- { "action": "deleteMessage", "channelId": "C123", "messageId": "1712023032.1234" }
52
- ```
53
-
54
- ```json
55
- { "action": "pinMessage", "channelId": "C123", "messageId": "1712023032.1234" }
56
- ```
57
-
58
- ```json
59
- { "action": "unpinMessage", "channelId": "C123", "messageId": "1712023032.1234" }
60
- ```
61
-
62
- ```json
63
- { "action": "listPins", "channelId": "C123" }
64
- ```
65
-
66
- ```json
67
- { "action": "memberInfo", "userId": "U123" }
68
- ```
69
-
70
- ```json
71
- { "action": "emojiList" }
72
- ```
73
-
74
- ## Safety
75
-
76
- - Confirm destructive deletes when context is unclear.
77
- - Keep outbound messages short; avoid Markdown tables.
78
- - Prefer thread/message IDs over fuzzy channel names.
20
+ Slack formatting, mentions, tables, charts, and interactive controls are described automatically by the current `message` tool hints. Follow those hints instead of maintaining a second action or formatting catalog here.
@@ -1,14 +0,0 @@
1
- //#region extensions/slack/src/account-reply-mode.ts
2
- function normalizeSlackChatType(raw) {
3
- const value = raw?.trim().toLowerCase();
4
- if (!value) return;
5
- if (value === "direct" || value === "dm") return "direct";
6
- if (value === "group" || value === "channel") return value;
7
- }
8
- function resolveSlackReplyToMode(account, chatType) {
9
- const normalized = normalizeSlackChatType(chatType ?? void 0);
10
- if (normalized && account.replyToModeByChatType?.[normalized] !== void 0) return account.replyToModeByChatType[normalized] ?? "off";
11
- return account.replyToMode ?? "off";
12
- }
13
- //#endregion
14
- export { resolveSlackReplyToMode as t };
@@ -1,2 +0,0 @@
1
- import { t as handleSlackAction } from "./action-runtime-DfuYoMjG.js";
2
- export { handleSlackAction };
@@ -1,2 +0,0 @@
1
- import { a as listSlackEmojis, c as pinSlackMessage, d as removeOwnSlackReactions, f as removeSlackReaction, h as unpinSlackMessage, i as getSlackMemberInfo, l as reactSlackMessage, m as sendSlackMessage, n as downloadSlackFile, o as listSlackPins, p as resolveSlackConversationName, r as editSlackMessage, s as listSlackReactions, t as deleteSlackMessage, u as readSlackMessages } from "./actions-D3NuJvva.js";
2
- export { deleteSlackMessage, downloadSlackFile, editSlackMessage, getSlackMemberInfo, listSlackEmojis, listSlackPins, listSlackReactions, pinSlackMessage, reactSlackMessage, readSlackMessages, removeOwnSlackReactions, removeSlackReaction, resolveSlackConversationName, sendSlackMessage, unpinSlackMessage };
@@ -1,56 +0,0 @@
1
- import { a as slackSetupContract, c as isSlackSetupAccountConfigured, i as slackSetupAdapter, o as SLACK_CHANNEL, r as createSlackSetupWizardProxy, s as describeSlackSetupAccount, t as slackBaseConfigAdapter } from "./config-adapter-CxBQH8fq.js";
2
- import { t as SlackChannelConfigSchema } from "./config-schema-SgZT6nXV.js";
3
- //#region extensions/slack/src/channel.setup.ts
4
- const slackSetupWizard = createSlackSetupWizardProxy(async () => ({ slackSetupWizard: (await import("./setup-surface-BeNzrMrJ.js")).slackSetupWizard }));
5
- const slackSetupPlugin = {
6
- id: SLACK_CHANNEL,
7
- meta: {
8
- id: SLACK_CHANNEL,
9
- label: "Slack",
10
- selectionLabel: "Slack (Socket Mode)",
11
- detailLabel: "Slack Bot",
12
- docsPath: "/channels/slack",
13
- docsLabel: "slack",
14
- blurb: "supported (Socket Mode).",
15
- systemImage: "number",
16
- markdownCapable: true,
17
- preferSessionLookupForAnnounceTarget: true
18
- },
19
- setupWizard: slackSetupWizard,
20
- capabilities: {
21
- chatTypes: [
22
- "direct",
23
- "channel",
24
- "thread"
25
- ],
26
- reactions: true,
27
- threads: true,
28
- media: true,
29
- nativeCommands: true
30
- },
31
- commands: {
32
- nativeCommandsAutoEnabled: false,
33
- nativeSkillsAutoEnabled: false,
34
- resolveNativeCommandName: ({ commandKey, defaultName }) => commandKey === "status" ? "agentstatus" : defaultName
35
- },
36
- streaming: { blockStreamingCoalesceDefaults: {
37
- minChars: 1500,
38
- idleMs: 1e3
39
- } },
40
- reload: { configPrefixes: ["channels.slack"] },
41
- configSchema: SlackChannelConfigSchema,
42
- config: {
43
- ...slackBaseConfigAdapter,
44
- hasConfiguredState: ({ env }) => [
45
- "SLACK_APP_TOKEN",
46
- "SLACK_BOT_TOKEN",
47
- "SLACK_USER_TOKEN"
48
- ].some((key) => typeof env?.[key] === "string" && env[key]?.trim().length > 0),
49
- isConfigured: (account) => isSlackSetupAccountConfigured(account),
50
- describeAccount: (account) => describeSlackSetupAccount(account)
51
- },
52
- setup: slackSetupAdapter,
53
- setupContract: slackSetupContract
54
- };
55
- //#endregion
56
- export { slackSetupPlugin as t };
@@ -1,3 +0,0 @@
1
- import { sendDurableMessageBatch } from "openclaw/plugin-sdk/channel-outbound";
2
- import { transcribeFirstAudio } from "openclaw/plugin-sdk/media-runtime";
3
- export { sendDurableMessageBatch, transcribeFirstAudio };
@@ -1,2 +0,0 @@
1
- import { listProviderPluginCommandSpecs } from "openclaw/plugin-sdk/command-auth-native";
2
- export { listProviderPluginCommandSpecs };
@@ -1,155 +0,0 @@
1
- type BaseOptions = {
2
- /**
3
- Number of concurrently pending promises returned by `mapper`.
4
-
5
- Must be an integer from 1 and up or `Infinity`.
6
-
7
- @default Infinity
8
- */
9
- readonly concurrency?: number;
10
- };
11
-
12
- export type Options = BaseOptions & {
13
- /**
14
- When `true`, the first mapper rejection will be rejected back to the consumer.
15
-
16
- When `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) containing all the errors from the rejected promises.
17
-
18
- Caveat: When `true`, any already-started async mappers will continue to run until they resolve or reject. In the case of infinite concurrency with sync iterables, *all* mappers are invoked on startup and will continue after the first rejection. Use the `signal` option for abort control.
19
-
20
- @default true
21
- */
22
- readonly stopOnError?: boolean;
23
-
24
- /**
25
- You can abort the promises using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
26
-
27
- @example
28
- ```
29
- import pMap from 'p-map';
30
- import delay from 'delay';
31
-
32
- const abortController = new AbortController();
33
-
34
- setTimeout(() => {
35
- abortController.abort();
36
- }, 500);
37
-
38
- const mapper = async value => value;
39
-
40
- await pMap([delay(1000), delay(1000)], mapper, {signal: abortController.signal});
41
- // Throws AbortError (DOMException) after 500 ms.
42
- ```
43
- */
44
- readonly signal?: AbortSignal | undefined;
45
- };
46
-
47
- export type IterableOptions = BaseOptions & {
48
- /**
49
- Maximum number of promises returned by `mapper` that have resolved but not yet collected by the consumer of the async iterable. Calls to `mapper` will be limited so that there is never too much backpressure.
50
-
51
- Useful whenever you are consuming the iterable slower than what the mapper function can produce concurrently. For example, to avoid making an overwhelming number of HTTP requests if you are saving each of the results to a database.
52
-
53
- Default: `options.concurrency`
54
- */
55
- readonly backpressure?: number;
56
- };
57
-
58
- type MaybePromise<T> = T | Promise<T>;
59
-
60
- /**
61
- Function which is called for every item in `input`. Expected to return a `Promise` or value.
62
-
63
- @param element - Iterated element.
64
- @param index - Index of the element in the source array.
65
- */
66
- export type Mapper<Element = any, NewElement = unknown> = (
67
- element: Element,
68
- index: number
69
- ) => MaybePromise<NewElement | typeof pMapSkip>;
70
-
71
- /**
72
- @param input - Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item. Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
73
- @param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
74
- @returns A `Promise` that is fulfilled when all promises in `input` and the ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
75
-
76
- @example
77
- ```
78
- import pMap from 'p-map';
79
- import got from 'got';
80
-
81
- const sites = [
82
- getWebsiteFromUsername('sindresorhus'), //=> Promise
83
- 'https://avajs.dev',
84
- 'https://github.com'
85
- ];
86
-
87
- const mapper = async site => {
88
- const {requestUrl} = await got.head(site);
89
- return requestUrl;
90
- };
91
-
92
- const result = await pMap(sites, mapper, {concurrency: 2});
93
-
94
- console.log(result);
95
- //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
96
- ```
97
- */
98
- export default function pMap<Element, NewElement>(
99
- input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>,
100
- mapper: Mapper<Element, NewElement>,
101
- options?: Options
102
- ): Promise<Array<Exclude<NewElement, typeof pMapSkip>>>;
103
-
104
- /**
105
- @param input - Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item. Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
106
- @param mapper - Function which is called for every item in `input`. Expected to return a `Promise` or value.
107
- @returns An async iterable that streams each return value from `mapper` in order.
108
-
109
- @example
110
- ```
111
- import {pMapIterable} from 'p-map';
112
-
113
- // Multiple posts are fetched concurrently, with limited concurrency and backpressure
114
- for await (const post of pMapIterable(postIds, getPostMetadata, {concurrency: 8})) {
115
- console.log(post);
116
- };
117
- ```
118
- */
119
- export function pMapIterable<Element, NewElement>(
120
- input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>,
121
- mapper: Mapper<Element, NewElement>,
122
- options?: IterableOptions
123
- ): AsyncIterable<Exclude<NewElement, typeof pMapSkip>>;
124
-
125
- /**
126
- Return this value from a `mapper` function to skip including the value in the returned array.
127
-
128
- @example
129
- ```
130
- import pMap, {pMapSkip} from 'p-map';
131
- import got from 'got';
132
-
133
- const sites = [
134
- getWebsiteFromUsername('sindresorhus'), //=> Promise
135
- 'https://avajs.dev',
136
- 'https://example.invalid',
137
- 'https://github.com'
138
- ];
139
-
140
- const mapper = async site => {
141
- try {
142
- const {requestUrl} = await got.head(site);
143
- return requestUrl;
144
- } catch {
145
- return pMapSkip;
146
- }
147
- };
148
-
149
- const result = await pMap(sites, mapper, {concurrency: 2});
150
-
151
- console.log(result);
152
- //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
153
- ```
154
- */
155
- export const pMapSkip: unique symbol;
@@ -1,285 +0,0 @@
1
- export default async function pMap(
2
- iterable,
3
- mapper,
4
- {
5
- concurrency = Number.POSITIVE_INFINITY,
6
- stopOnError = true,
7
- signal,
8
- } = {},
9
- ) {
10
- return new Promise((resolve_, reject_) => {
11
- if (iterable[Symbol.iterator] === undefined && iterable[Symbol.asyncIterator] === undefined) {
12
- throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
13
- }
14
-
15
- if (typeof mapper !== 'function') {
16
- throw new TypeError('Mapper function is required');
17
- }
18
-
19
- if (!((Number.isSafeInteger(concurrency) && concurrency >= 1) || concurrency === Number.POSITIVE_INFINITY)) {
20
- throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
21
- }
22
-
23
- const result = [];
24
- const errors = [];
25
- const skippedIndexesMap = new Map();
26
- let isRejected = false;
27
- let isResolved = false;
28
- let isIterableDone = false;
29
- let resolvingCount = 0;
30
- let currentIndex = 0;
31
- const iterator = iterable[Symbol.iterator] === undefined ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
32
-
33
- const signalListener = () => {
34
- reject(signal.reason);
35
- };
36
-
37
- const cleanup = () => {
38
- signal?.removeEventListener('abort', signalListener);
39
- };
40
-
41
- const resolve = value => {
42
- resolve_(value);
43
- cleanup();
44
- };
45
-
46
- const reject = reason => {
47
- isRejected = true;
48
- isResolved = true;
49
- reject_(reason);
50
- cleanup();
51
- };
52
-
53
- if (signal) {
54
- if (signal.aborted) {
55
- reject(signal.reason);
56
- return;
57
- }
58
-
59
- signal.addEventListener('abort', signalListener, {once: true});
60
- }
61
-
62
- const next = async () => {
63
- if (isResolved) {
64
- return;
65
- }
66
-
67
- const nextItem = await iterator.next();
68
-
69
- const index = currentIndex;
70
- currentIndex++;
71
-
72
- // Note: `iterator.next()` can be called many times in parallel.
73
- // This can cause multiple calls to this `next()` function to
74
- // receive a `nextItem` with `done === true`.
75
- // The shutdown logic that rejects/resolves must be protected
76
- // so it runs only one time as the `skippedIndex` logic is
77
- // non-idempotent.
78
- if (nextItem.done) {
79
- isIterableDone = true;
80
-
81
- if (resolvingCount === 0 && !isResolved) {
82
- if (!stopOnError && errors.length > 0) {
83
- reject(new AggregateError(errors)); // eslint-disable-line unicorn/error-message
84
- return;
85
- }
86
-
87
- isResolved = true;
88
-
89
- if (skippedIndexesMap.size === 0) {
90
- resolve(result);
91
- return;
92
- }
93
-
94
- const pureResult = [];
95
-
96
- // Support multiple `pMapSkip`'s.
97
- for (const [index, value] of result.entries()) {
98
- if (skippedIndexesMap.get(index) === pMapSkip) {
99
- continue;
100
- }
101
-
102
- pureResult.push(value);
103
- }
104
-
105
- resolve(pureResult);
106
- }
107
-
108
- return;
109
- }
110
-
111
- resolvingCount++;
112
-
113
- // Intentionally detached
114
- (async () => {
115
- try {
116
- const element = await nextItem.value;
117
-
118
- if (isResolved) {
119
- return;
120
- }
121
-
122
- const value = await mapper(element, index);
123
-
124
- // Use Map to stage the index of the element.
125
- if (value === pMapSkip) {
126
- skippedIndexesMap.set(index, value);
127
- }
128
-
129
- result[index] = value;
130
-
131
- resolvingCount--;
132
- await next();
133
- } catch (error) {
134
- if (stopOnError) {
135
- reject(error);
136
- } else {
137
- errors.push(error);
138
- resolvingCount--;
139
-
140
- // In that case we can't really continue regardless of `stopOnError` state
141
- // since an iterable is likely to continue throwing after it throws once.
142
- // If we continue calling `next()` indefinitely we will likely end up
143
- // in an infinite loop of failed iteration.
144
- try {
145
- await next();
146
- } catch (error) {
147
- reject(error);
148
- }
149
- }
150
- }
151
- })();
152
- };
153
-
154
- // Create the concurrent runners in a detached (non-awaited)
155
- // promise. We need this so we can await the `next()` calls
156
- // to stop creating runners before hitting the concurrency limit
157
- // if the iterable has already been marked as done.
158
- // NOTE: We *must* do this for async iterators otherwise we'll spin up
159
- // infinite `next()` calls by default and never start the event loop.
160
- (async () => {
161
- for (let index = 0; index < concurrency; index++) {
162
- try {
163
- // eslint-disable-next-line no-await-in-loop
164
- await next();
165
- } catch (error) {
166
- reject(error);
167
- break;
168
- }
169
-
170
- if (isIterableDone || isRejected) {
171
- break;
172
- }
173
- }
174
- })();
175
- });
176
- }
177
-
178
- export function pMapIterable(
179
- iterable,
180
- mapper,
181
- {
182
- concurrency = Number.POSITIVE_INFINITY,
183
- backpressure = concurrency,
184
- } = {},
185
- ) {
186
- if (iterable[Symbol.iterator] === undefined && iterable[Symbol.asyncIterator] === undefined) {
187
- throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
188
- }
189
-
190
- if (typeof mapper !== 'function') {
191
- throw new TypeError('Mapper function is required');
192
- }
193
-
194
- if (!((Number.isSafeInteger(concurrency) && concurrency >= 1) || concurrency === Number.POSITIVE_INFINITY)) {
195
- throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
196
- }
197
-
198
- if (!((Number.isSafeInteger(backpressure) && backpressure >= concurrency) || backpressure === Number.POSITIVE_INFINITY)) {
199
- throw new TypeError(`Expected \`backpressure\` to be an integer from \`concurrency\` (${concurrency}) and up or \`Infinity\`, got \`${backpressure}\` (${typeof backpressure})`);
200
- }
201
-
202
- return {
203
- async * [Symbol.asyncIterator]() {
204
- const iterator = iterable[Symbol.asyncIterator] === undefined ? iterable[Symbol.iterator]() : iterable[Symbol.asyncIterator]();
205
-
206
- const promises = [];
207
- let pendingPromisesCount = 0;
208
- let isDone = false;
209
- let index = 0;
210
-
211
- function trySpawn() {
212
- if (isDone || !(pendingPromisesCount < concurrency && promises.length < backpressure)) {
213
- return;
214
- }
215
-
216
- pendingPromisesCount++;
217
-
218
- const promise = (async () => {
219
- const {done, value} = await iterator.next();
220
-
221
- if (done) {
222
- pendingPromisesCount--;
223
- return {done: true};
224
- }
225
-
226
- // Spawn if still below concurrency and backpressure limit
227
- trySpawn();
228
-
229
- try {
230
- const currentIndex = index++;
231
- const returnValue = await mapper(await value, currentIndex);
232
-
233
- pendingPromisesCount--;
234
-
235
- if (returnValue === pMapSkip) {
236
- const index = promises.indexOf(promise);
237
-
238
- if (index > 0) {
239
- promises.splice(index, 1);
240
- }
241
- }
242
-
243
- // Spawn if still below backpressure limit and just dropped below concurrency limit
244
- trySpawn();
245
-
246
- return {done: false, value: returnValue};
247
- } catch (error) {
248
- pendingPromisesCount--;
249
- isDone = true;
250
- return {error};
251
- }
252
- })();
253
-
254
- promises.push(promise);
255
- }
256
-
257
- trySpawn();
258
-
259
- while (promises.length > 0) {
260
- const {error, done, value} = await promises[0]; // eslint-disable-line no-await-in-loop
261
-
262
- promises.shift();
263
-
264
- if (error) {
265
- throw error;
266
- }
267
-
268
- if (done) {
269
- return;
270
- }
271
-
272
- // Spawn if just dropped below backpressure limit and below the concurrency limit
273
- trySpawn();
274
-
275
- if (value === pMapSkip) {
276
- continue;
277
- }
278
-
279
- yield value;
280
- }
281
- },
282
- };
283
- }
284
-
285
- export const pMapSkip = Symbol('skip');
@@ -1,9 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,57 +0,0 @@
1
- {
2
- "name": "p-map",
3
- "version": "7.0.6",
4
- "description": "Map over promises concurrently",
5
- "license": "MIT",
6
- "repository": "sindresorhus/p-map",
7
- "funding": "https://github.com/sponsors/sindresorhus",
8
- "author": {
9
- "name": "Sindre Sorhus",
10
- "email": "sindresorhus@gmail.com",
11
- "url": "https://sindresorhus.com"
12
- },
13
- "type": "module",
14
- "exports": {
15
- "types": "./index.d.ts",
16
- "default": "./index.js"
17
- },
18
- "sideEffects": false,
19
- "engines": {
20
- "node": ">=18"
21
- },
22
- "scripts": {
23
- "test": "xo && ava && tsd"
24
- },
25
- "files": [
26
- "index.js",
27
- "index.d.ts"
28
- ],
29
- "keywords": [
30
- "promise",
31
- "map",
32
- "resolved",
33
- "wait",
34
- "collection",
35
- "iterable",
36
- "iterator",
37
- "race",
38
- "fulfilled",
39
- "async",
40
- "await",
41
- "promises",
42
- "concurrently",
43
- "concurrency",
44
- "parallel",
45
- "bluebird"
46
- ],
47
- "devDependencies": {
48
- "ava": "^5.2.0",
49
- "chalk": "^5.3.0",
50
- "delay": "^6.0.0",
51
- "in-range": "^3.0.0",
52
- "random-int": "^3.0.0",
53
- "time-span": "^5.1.0",
54
- "tsd": "^0.29.0",
55
- "xo": "^0.56.0"
56
- }
57
- }