outbound-sdk 0.7.0 → 0.8.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.
- package/dist/alerts/index.js +3 -3
- package/dist/audit/index.js +1 -1
- package/dist/benchmarks/index.js +3 -3
- package/dist/budget/index.d.ts +7 -0
- package/dist/budget/index.js +3 -3
- package/dist/cache/index.js +2 -2
- package/dist/cards/index.js +17 -5
- package/dist/chunks/{chunk-ZJCVLBAE.js → chunk-4GK56PRO.js} +667 -363
- package/dist/chunks/{chunk-MW4C6LTN.js → chunk-7TASUWPC.js} +2 -2
- package/dist/chunks/{chunk-M2VXGLLZ.js → chunk-CPACP4YD.js} +1 -1
- package/dist/chunks/{chunk-4AVYRVN5.js → chunk-FTK4JS65.js} +31 -10
- package/dist/chunks/{chunk-YW6FFVSZ.js → chunk-HXB2IOJJ.js} +1 -1
- package/dist/chunks/{chunk-Y7KECJAV.js → chunk-IKKCMWBK.js} +1 -1
- package/dist/chunks/{chunk-FHKSLCVW.js → chunk-KVAG5GM2.js} +19 -0
- package/dist/chunks/{chunk-7I3EPR23.js → chunk-MPE6VLLY.js} +3 -3
- package/dist/chunks/{chunk-UFQ4WMLU.js → chunk-NFWWA7MI.js} +1 -1
- package/dist/chunks/{chunk-GL7BABF2.js → chunk-OMCDMELK.js} +1 -1
- package/dist/chunks/{chunk-JRL3QRBS.js → chunk-OVTYA3IB.js} +88 -28
- package/dist/chunks/{chunk-HIAK2GCI.js → chunk-RMAHQ2OZ.js} +5 -1
- package/dist/chunks/{chunk-65YAGEWZ.js → chunk-RQLOPMMR.js} +153 -39
- package/dist/chunks/{chunk-OK3GAZMT.js → chunk-SYUMA3CP.js} +12 -0
- package/dist/chunks/{chunk-LVZGIKNF.js → chunk-U5AK6OJM.js} +1 -1
- package/dist/chunks/{chunk-KTYTE2BU.js → chunk-UAHYPASH.js} +20 -11
- package/dist/chunks/{chunk-BNDHEDHD.js → chunk-UOJG4VYF.js} +3 -3
- package/dist/chunks/{chunk-LD6F46UT.js → chunk-UWD65SK7.js} +2 -2
- package/dist/chunks/{chunk-I7DXXGNZ.js → chunk-UZLFZZ2U.js} +5 -5
- package/dist/chunks/{chunk-DNPNTD5W.js → chunk-VVDBCQLK.js} +1 -1
- package/dist/chunks/{chunk-IVH3NMQZ.js → chunk-WROJO6XB.js} +1 -1
- package/dist/chunks/chunk-XMCNRU4H.js +7279 -0
- package/dist/chunks/{chunk-QFC4ZHD3.js → chunk-XYHM4KHC.js} +1 -1
- package/dist/chunks/{chunk-NAWZ73QS.js → chunk-YFJ3OQZS.js} +8 -1
- package/dist/chunks/tools-II7GXAOM.js +23 -0
- package/dist/cli/args.d.ts +48 -0
- package/dist/cli/bin.js +14 -14
- package/dist/cli/commands.d.ts +0 -7
- package/dist/cli/config.d.ts +31 -2
- package/dist/cli/envelope.d.ts +2 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +19 -15
- package/dist/cli/listing.d.ts +5 -2
- package/dist/cli/mcp.d.ts +9 -0
- package/dist/cli/offered.d.ts +10 -0
- package/dist/cli/options.d.ts +6 -0
- package/dist/cli/progress.d.ts +27 -0
- package/dist/cli/serve.d.ts +17 -0
- package/dist/cli/update.d.ts +25 -2
- package/dist/clients/index.js +3 -3
- package/dist/combine/index.js +154 -35
- package/dist/combine/newest.d.ts +18 -0
- package/dist/combine/route.d.ts +19 -5
- package/dist/emailbison/index.js +22 -14
- package/dist/emailbison/map-sequence.d.ts +2 -1
- package/dist/exporter/index.js +1 -1
- package/dist/failover/index.js +3 -3
- package/dist/fixtures/index.js +4 -4
- package/dist/heyreach/capabilities.d.ts +4 -0
- package/dist/heyreach/conversations.d.ts +23 -0
- package/dist/heyreach/inbox.d.ts +0 -1
- package/dist/heyreach/index.js +251 -92
- package/dist/identity/index.js +2 -2
- package/dist/index.js +7 -7
- package/dist/insights/capped.d.ts +6 -6
- package/dist/insights/copy/index.d.ts +2 -0
- package/dist/insights/copy/reply-timing.d.ts +4 -0
- package/dist/insights/cost.d.ts +11 -1
- package/dist/insights/define.d.ts +25 -16
- package/dist/insights/inbox.d.ts +12 -0
- package/dist/insights/index.js +42 -6578
- package/dist/insights/inputs.generated.d.ts +60 -24
- package/dist/insights/ops/anomalies.d.ts +9 -0
- package/dist/insights/ops/index.d.ts +2 -0
- package/dist/insights/ops/period-comparison.d.ts +7 -8
- package/dist/insights/ops/pipeline-forecast.d.ts +10 -0
- package/dist/insights/ops/shared.d.ts +6 -1
- package/dist/insights/people/auto-replies.d.ts +11 -7
- package/dist/insights/people/dropped-replies.d.ts +13 -4
- package/dist/insights/people/hot-leads-read.d.ts +31 -0
- package/dist/insights/people/hot-leads.d.ts +15 -3
- package/dist/insights/people/index.d.ts +10 -2
- package/dist/insights/people/read.d.ts +1 -1
- package/dist/insights/registry.d.ts +14 -2
- package/dist/insights/run-cap.d.ts +10 -0
- package/dist/insights/senders/read.d.ts +0 -3
- package/dist/insights/tools.d.ts +12 -0
- package/dist/insights/tracked-reads.d.ts +53 -0
- package/dist/instantly/capabilities.d.ts +13 -1
- package/dist/instantly/index.js +122 -46
- package/dist/instantly/map-account.d.ts +2 -1
- package/dist/instantly/map-lead.d.ts +1 -0
- package/dist/instantly/map.d.ts +4 -3
- package/dist/internal/adapter.d.ts +17 -0
- package/dist/internal/capabilities.d.ts +13 -0
- package/dist/internal/engine/budget.d.ts +9 -1
- package/dist/internal/engine/engine.d.ts +2 -1
- package/dist/internal/engine/request.d.ts +2 -0
- package/dist/internal/errors.d.ts +5 -0
- package/dist/internal/hooks.d.ts +11 -0
- package/dist/internal/notes.d.ts +16 -0
- package/dist/internal/outbound/api.d.ts +14 -0
- package/dist/internal/outbound/core.d.ts +4 -1
- package/dist/internal/outbound/operation-shared.d.ts +2 -0
- package/dist/internal/sha256.d.ts +2 -0
- package/dist/internal/url.d.ts +1 -0
- package/dist/loader/index.js +3 -3
- package/dist/memory/index.js +6 -6
- package/dist/redact/index.d.ts +1 -1
- package/dist/redact/index.js +107 -19
- package/dist/redact/plugin.d.ts +26 -3
- package/dist/smartlead/index.js +22 -13
- package/dist/smartlead/map.d.ts +3 -2
- package/dist/sync/index.js +2 -2
- package/dist/tools/ai-sdk.js +5 -5
- package/dist/tools/by-name.d.ts +9 -1
- package/dist/tools/campaign-tools.d.ts +3 -1
- package/dist/tools/claude-agent.js +5 -5
- package/dist/tools/index.js +6 -6
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/shared.d.ts +5 -1
- package/dist/tracing/index.js +1 -1
- package/dist/webhooks/index.js +11 -11
- package/package.json +1 -1
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
|
+
TOOL_NAMES,
|
|
2
3
|
countReplies,
|
|
3
4
|
createTools,
|
|
4
5
|
describeReplyCounts,
|
|
6
|
+
leftOutReason,
|
|
5
7
|
repliesByPerson
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OVTYA3IB.js";
|
|
7
9
|
import {
|
|
8
10
|
resolveCampaign,
|
|
9
11
|
resolveList
|
|
10
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-FTK4JS65.js";
|
|
11
13
|
import {
|
|
12
14
|
plural as plural2
|
|
13
15
|
} from "./chunk-4PA526S7.js";
|
|
14
16
|
import {
|
|
15
17
|
createOutbound
|
|
16
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-RQLOPMMR.js";
|
|
17
19
|
import {
|
|
18
20
|
plural
|
|
19
21
|
} from "./chunk-PTZO4QXR.js";
|
|
@@ -23,10 +25,10 @@ import {
|
|
|
23
25
|
} from "./chunk-QGRZDTX4.js";
|
|
24
26
|
import {
|
|
25
27
|
fromEnv
|
|
26
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-7TASUWPC.js";
|
|
27
29
|
import {
|
|
28
30
|
OutboundError
|
|
29
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-XYHM4KHC.js";
|
|
30
32
|
import {
|
|
31
33
|
field,
|
|
32
34
|
isBoolean,
|
|
@@ -38,10 +40,11 @@ import {
|
|
|
38
40
|
toJson
|
|
39
41
|
} from "./chunk-45TXPJW7.js";
|
|
40
42
|
import {
|
|
43
|
+
findProvider,
|
|
41
44
|
providers
|
|
42
45
|
} from "./chunk-WH6V3YNN.js";
|
|
43
46
|
|
|
44
|
-
// src/cli/
|
|
47
|
+
// src/cli/args.ts
|
|
45
48
|
import { parseArgs } from "node:util";
|
|
46
49
|
|
|
47
50
|
// src/cli/by-name.ts
|
|
@@ -72,6 +75,119 @@ var searchCampaigns = async (outbound, { max, note, search, status }) => {
|
|
|
72
75
|
return matches.slice(0, max);
|
|
73
76
|
};
|
|
74
77
|
|
|
78
|
+
// src/cli/config.ts
|
|
79
|
+
import path from "node:path";
|
|
80
|
+
import { pathToFileURL } from "node:url";
|
|
81
|
+
var defineConfig = (config) => config;
|
|
82
|
+
var isPlugin = (value) => typeof value === "object" && value !== null && "name" in value && typeof value.name === "string";
|
|
83
|
+
var isConfigModule = (value) => typeof value === "object" && value !== null && "default" in value && typeof value.default === "object" && value.default !== null;
|
|
84
|
+
var isPluginList = (value) => Array.isArray(value) && value.every(isPlugin);
|
|
85
|
+
var isStore = (value) => typeof value === "object" && value !== null && "reserve" in value && typeof value.reserve === "function" && "pause" in value && typeof value.pause === "function" && "usage" in value && typeof value.usage === "function";
|
|
86
|
+
var loadConfig = async (file) => {
|
|
87
|
+
let loaded;
|
|
88
|
+
try {
|
|
89
|
+
loaded = await import(pathToFileURL(path.resolve(file)).href);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
throw new OutboundError(
|
|
92
|
+
"Invalid",
|
|
93
|
+
`Could not load the config file ${file}: ${error instanceof Error ? error.message : String(error)}`,
|
|
94
|
+
{ cause: error }
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
if (!isConfigModule(loaded)) {
|
|
98
|
+
throw new OutboundError(
|
|
99
|
+
"Invalid",
|
|
100
|
+
`The config file ${file} has no default export. Export defineConfig({ plugins: [...] })`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
const plugins = loaded.default.plugins ?? [];
|
|
104
|
+
if (!isPluginList(plugins)) {
|
|
105
|
+
throw new OutboundError(
|
|
106
|
+
"Invalid",
|
|
107
|
+
`The config file ${file} must export plugins as a list of plugins, such as [redact(), cache({ ttl: 300 })]`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
const { rateLimitStore } = loaded.default;
|
|
111
|
+
if (rateLimitStore !== void 0 && !isStore(rateLimitStore)) {
|
|
112
|
+
throw new OutboundError(
|
|
113
|
+
"Invalid",
|
|
114
|
+
`The config file ${file} must export rateLimitStore as a rate limit store, such as redisRateLimitStore({ evaluate })`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return { plugins, rateLimitStore };
|
|
118
|
+
};
|
|
119
|
+
var positiveInteger = (flag, value) => {
|
|
120
|
+
const parsed = Number(value);
|
|
121
|
+
if (!Number.isInteger(parsed) || parsed < 1) {
|
|
122
|
+
throw new OutboundError(
|
|
123
|
+
"Invalid",
|
|
124
|
+
`--${flag} takes a positive whole number, not "${value}"`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return parsed;
|
|
128
|
+
};
|
|
129
|
+
var wantsRedact = (flags, fromConfig, mcp) => {
|
|
130
|
+
if (flags["no-redact"] === true) {
|
|
131
|
+
if (flags.redact === true) {
|
|
132
|
+
throw new OutboundError(
|
|
133
|
+
"Invalid",
|
|
134
|
+
"--redact and --no-redact cannot both be set"
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (fromConfig) {
|
|
138
|
+
throw new OutboundError(
|
|
139
|
+
"Invalid",
|
|
140
|
+
"--no-redact conflicts with redact() in the config file. Remove one of them"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return !fromConfig && (flags.redact === true || mcp);
|
|
146
|
+
};
|
|
147
|
+
var capSetting = (mcp) => mcp ? "--max-requests on outbound mcp" : "--max-requests";
|
|
148
|
+
var insightCaps = (flags, mcp) => ({
|
|
149
|
+
capSetting: capSetting(mcp),
|
|
150
|
+
maxRequests: flags["max-requests"] === void 0 ? void 0 : positiveInteger("max-requests", flags["max-requests"])
|
|
151
|
+
});
|
|
152
|
+
var insightToolCaps = (flags, mcp) => {
|
|
153
|
+
const caps = insightCaps(flags, mcp);
|
|
154
|
+
return {
|
|
155
|
+
capSetting: caps.capSetting,
|
|
156
|
+
maxRequestsPerToolCall: caps.maxRequests
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
var setupFor = async (flags, mcp, note) => {
|
|
160
|
+
const loaded = flags.config === void 0 ? { plugins: [], rateLimitStore: void 0 } : await loadConfig(flags.config);
|
|
161
|
+
const configured = loaded.plugins;
|
|
162
|
+
const fromConfig = configured.some((plugin) => plugin.name === "redact");
|
|
163
|
+
const plugins = [];
|
|
164
|
+
if (wantsRedact(flags, fromConfig, mcp)) {
|
|
165
|
+
const { redact } = await import("../redact/index.js");
|
|
166
|
+
plugins.push(redact());
|
|
167
|
+
}
|
|
168
|
+
plugins.push(...configured);
|
|
169
|
+
if (flags.cache !== void 0) {
|
|
170
|
+
const ttl = positiveInteger("cache", flags.cache);
|
|
171
|
+
const { cache } = await import("../cache/index.js");
|
|
172
|
+
plugins.push(cache({ ttl }));
|
|
173
|
+
if (!mcp) {
|
|
174
|
+
note(
|
|
175
|
+
"--cache lasts one process, so the next run reads from the vendor again. It helps outbound mcp; to persist, list cache({ ttl, store }) in a --config file."
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (flags["max-requests"] !== void 0) {
|
|
180
|
+
const maxRequests = positiveInteger("max-requests", flags["max-requests"]);
|
|
181
|
+
const { budget } = await import("../budget/index.js");
|
|
182
|
+
plugins.push(budget({ maxRequests, per: "run", setting: capSetting(mcp) }));
|
|
183
|
+
}
|
|
184
|
+
if (!plugins.some((plugin) => plugin.name === "identity")) {
|
|
185
|
+
const { identity } = await import("../identity/index.js");
|
|
186
|
+
plugins.push(identity());
|
|
187
|
+
}
|
|
188
|
+
return { plugins, rateLimitStore: loaded.rateLimitStore };
|
|
189
|
+
};
|
|
190
|
+
|
|
75
191
|
// src/cli/envelope.ts
|
|
76
192
|
var Answer = class {
|
|
77
193
|
value;
|
|
@@ -153,7 +269,8 @@ var envelope = (printed, facts) => {
|
|
|
153
269
|
complete,
|
|
154
270
|
notes: [...notes],
|
|
155
271
|
provider: facts.provider ?? field(own, "provider") ?? null,
|
|
156
|
-
requests: facts.requests
|
|
272
|
+
requests: facts.requests,
|
|
273
|
+
throttledMs: facts.throttledMs
|
|
157
274
|
};
|
|
158
275
|
if (isString(insight)) {
|
|
159
276
|
meta.insight = insight;
|
|
@@ -161,7 +278,7 @@ var envelope = (printed, facts) => {
|
|
|
161
278
|
if (isToolResult(value)) {
|
|
162
279
|
const ok = value.ok === true;
|
|
163
280
|
const wrapped = {
|
|
164
|
-
data:
|
|
281
|
+
data: value.data ?? null,
|
|
165
282
|
meta,
|
|
166
283
|
next: value.next ?? null,
|
|
167
284
|
ok
|
|
@@ -180,30 +297,39 @@ var failedEnvelope = (failure2, facts) => ({
|
|
|
180
297
|
complete: false,
|
|
181
298
|
notes: [],
|
|
182
299
|
provider: facts.provider,
|
|
183
|
-
requests: facts.requests
|
|
300
|
+
requests: facts.requests,
|
|
301
|
+
throttledMs: facts.throttledMs
|
|
184
302
|
},
|
|
185
303
|
ok: false
|
|
186
304
|
});
|
|
187
305
|
|
|
188
306
|
// src/cli/listing.ts
|
|
189
|
-
var listed = async (walk, input, one, many) => {
|
|
307
|
+
var listed = async (walk, input, one, many, stop = "; more exist. Pass --limit to read more.") => {
|
|
190
308
|
const items = await walk.toArray();
|
|
309
|
+
const left = walk.meta?.notes ?? [];
|
|
191
310
|
if (!walk.truncated) {
|
|
192
311
|
return {
|
|
193
|
-
coverage: { complete: walk.meta?.complete ?? true, notes: [] },
|
|
312
|
+
coverage: { complete: walk.meta?.complete ?? true, notes: [...left] },
|
|
194
313
|
items
|
|
195
314
|
};
|
|
196
315
|
}
|
|
197
|
-
const note = `Stopped at ${plural2(items.length, one, many)}
|
|
316
|
+
const note = `Stopped at ${plural2(items.length, one, many)}${stop}`;
|
|
198
317
|
input.note(note);
|
|
199
|
-
return { coverage: { complete: false, notes: [note] }, items };
|
|
318
|
+
return { coverage: { complete: false, notes: [...left, note] }, items };
|
|
200
319
|
};
|
|
201
320
|
var listing = async (walk, input, one, many) => {
|
|
202
321
|
const { coverage, items } = await listed(walk, input, one, many);
|
|
203
322
|
return new Answer(toJson(items), coverage, true);
|
|
204
323
|
};
|
|
205
|
-
var
|
|
206
|
-
|
|
324
|
+
var WINDOW_LIMIT = 2e3;
|
|
325
|
+
var listedReplies = async (walk, input, byPerson, windowed = false) => {
|
|
326
|
+
const { coverage, items } = await listed(
|
|
327
|
+
walk,
|
|
328
|
+
input,
|
|
329
|
+
"reply",
|
|
330
|
+
"replies",
|
|
331
|
+
windowed ? ", the most a --since window reads without --limit; more exist. Pass --limit to read more, or a later --since." : void 0
|
|
332
|
+
);
|
|
207
333
|
const counted = `${describeReplyCounts(countReplies(items))}.`;
|
|
208
334
|
input.note(counted);
|
|
209
335
|
return new Answer(
|
|
@@ -268,6 +394,23 @@ var readNative = async (outbound, name, params) => {
|
|
|
268
394
|
return toJson(await outbound.native.read(name, given));
|
|
269
395
|
};
|
|
270
396
|
|
|
397
|
+
// src/cli/offered.ts
|
|
398
|
+
var offeredTools = async (outbound, flags) => {
|
|
399
|
+
const { insightTools } = await import("../insights/index.js");
|
|
400
|
+
return createTools(outbound, {
|
|
401
|
+
extra: insightTools(outbound, insightToolCaps(flags, false))
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
var describeTool = (tool) => ({
|
|
405
|
+
description: tool.description,
|
|
406
|
+
name: tool.name,
|
|
407
|
+
parameters: tool.parameters
|
|
408
|
+
});
|
|
409
|
+
var requiresInput = (tool) => {
|
|
410
|
+
const { parameters } = tool;
|
|
411
|
+
return isJsonObject(parameters) && Array.isArray(parameters.required) && parameters.required.length > 0;
|
|
412
|
+
};
|
|
413
|
+
|
|
271
414
|
// src/cli/commands.ts
|
|
272
415
|
var text = (input, name) => {
|
|
273
416
|
const value = input.flags[name];
|
|
@@ -332,19 +475,6 @@ var drawn = async (name, result2, input) => {
|
|
|
332
475
|
coverageOf(asJson(result2))
|
|
333
476
|
);
|
|
334
477
|
};
|
|
335
|
-
var offeredTools = async (outbound) => {
|
|
336
|
-
const { insightTools } = await import("../insights/index.js");
|
|
337
|
-
return createTools(outbound, { extra: insightTools(outbound) });
|
|
338
|
-
};
|
|
339
|
-
var describeTool = (tool) => ({
|
|
340
|
-
description: tool.description,
|
|
341
|
-
name: tool.name,
|
|
342
|
-
parameters: tool.parameters
|
|
343
|
-
});
|
|
344
|
-
var requiresInput = (tool) => {
|
|
345
|
-
const { parameters } = tool;
|
|
346
|
-
return isJsonObject(parameters) && Array.isArray(parameters.required) && parameters.required.length > 0;
|
|
347
|
-
};
|
|
348
478
|
var runInsight = async (outbound, input) => {
|
|
349
479
|
const { insightTools, listInsights, runInsightByName } = await import("../insights/index.js");
|
|
350
480
|
const [name] = input.positionals;
|
|
@@ -352,8 +482,18 @@ var runInsight = async (outbound, input) => {
|
|
|
352
482
|
return asJson(listInsights());
|
|
353
483
|
}
|
|
354
484
|
const insightInput = parseInput(text(input, "input"));
|
|
355
|
-
const [asTool] = wantsCard(input) ? insightTools(outbound, {
|
|
356
|
-
|
|
485
|
+
const [asTool] = wantsCard(input) ? insightTools(outbound, {
|
|
486
|
+
...insightToolCaps(input.flags, false),
|
|
487
|
+
only: [name]
|
|
488
|
+
}) : [];
|
|
489
|
+
return asTool === void 0 ? asJson(
|
|
490
|
+
await runInsightByName(
|
|
491
|
+
outbound,
|
|
492
|
+
name,
|
|
493
|
+
insightInput,
|
|
494
|
+
insightCaps(input.flags, false)
|
|
495
|
+
)
|
|
496
|
+
) : drawn(name, await asTool.call(insightInput), input);
|
|
357
497
|
};
|
|
358
498
|
var GLOBAL_FLAGS = [
|
|
359
499
|
"cache",
|
|
@@ -531,18 +671,29 @@ var COMMAND_TABLE = {
|
|
|
531
671
|
})
|
|
532
672
|
},
|
|
533
673
|
replies: {
|
|
534
|
-
flags: [
|
|
535
|
-
|
|
674
|
+
flags: [
|
|
675
|
+
"bodies",
|
|
676
|
+
"by",
|
|
677
|
+
"campaign",
|
|
678
|
+
"category",
|
|
679
|
+
"include-inbox",
|
|
680
|
+
"limit",
|
|
681
|
+
"since"
|
|
682
|
+
],
|
|
683
|
+
help: "replies [--campaign ID|NAME] [--category positive|negative|neutral|ooo|...] [--since ISO] [--limit N] [--bodies] [--by person] [--include-inbox] one record per message; --by person gives one row per person. --limit defaults to 50, or with --since to the whole window up to 2000. --include-inbox adds conversations outside every campaign (HeyReach)",
|
|
536
684
|
run: async (outbound, input) => {
|
|
537
685
|
const by = choice(input, "by", REPLIES_BY);
|
|
686
|
+
const since = text(input, "since");
|
|
687
|
+
const windowed = since !== void 0 && text(input, "limit") === void 0;
|
|
538
688
|
const walk = outbound.replies.listAll({
|
|
539
689
|
campaignId: await campaignOption(outbound, text(input, "campaign")),
|
|
540
690
|
category: choice(input, "category", replyCategorySchema.options),
|
|
541
691
|
include: input.flags.bodies === true ? ["body"] : void 0,
|
|
542
|
-
|
|
543
|
-
|
|
692
|
+
includeInbox: input.flags["include-inbox"] === true || void 0,
|
|
693
|
+
max: count(input, "limit", windowed ? WINDOW_LIMIT : 50),
|
|
694
|
+
since
|
|
544
695
|
});
|
|
545
|
-
return listedReplies(walk, input, by === "person");
|
|
696
|
+
return listedReplies(walk, input, by === "person", windowed);
|
|
546
697
|
}
|
|
547
698
|
},
|
|
548
699
|
senders: {
|
|
@@ -599,12 +750,19 @@ var COMMAND_TABLE = {
|
|
|
599
750
|
},
|
|
600
751
|
tool: {
|
|
601
752
|
flags: ["card", "input", "slack"],
|
|
602
|
-
help: "tool <name> [--input JSON] [--card | --slack] without --input, a tool that needs input
|
|
753
|
+
help: "tool <name> [--input JSON] [--card | --slack] without --input, a tool that needs input fails with what it takes (exit 2)",
|
|
603
754
|
run: async (outbound, input) => {
|
|
604
755
|
const name = required(input, 0, "a tool name");
|
|
605
|
-
const offered = await offeredTools(outbound);
|
|
756
|
+
const offered = await offeredTools(outbound, input.flags);
|
|
606
757
|
const tool = offered.find((candidate) => candidate.name === name);
|
|
607
758
|
if (tool === void 0) {
|
|
759
|
+
const { insightLeftOutReason } = await import("./tools-II7GXAOM.js");
|
|
760
|
+
const why = leftOutReason(outbound, name) ?? insightLeftOutReason(outbound, name);
|
|
761
|
+
if (why !== void 0) {
|
|
762
|
+
throw new OutboundError("Unsupported", why, {
|
|
763
|
+
provider: outbound.provider
|
|
764
|
+
});
|
|
765
|
+
}
|
|
608
766
|
throw new OutboundError(
|
|
609
767
|
"Invalid",
|
|
610
768
|
`Unknown tool "${name}".${didYouMean(
|
|
@@ -615,7 +773,16 @@ var COMMAND_TABLE = {
|
|
|
615
773
|
}
|
|
616
774
|
const given = text(input, "input");
|
|
617
775
|
if (given === void 0 && requiresInput(tool)) {
|
|
618
|
-
return
|
|
776
|
+
return {
|
|
777
|
+
data: describeTool(tool),
|
|
778
|
+
error: {
|
|
779
|
+
code: "InputRequired",
|
|
780
|
+
message: `${name} needs --input. data.parameters lists what it takes`,
|
|
781
|
+
retryable: false
|
|
782
|
+
},
|
|
783
|
+
next: `Run outbound tool ${name} --input '<JSON>' with the inputs data.parameters lists.`,
|
|
784
|
+
ok: false
|
|
785
|
+
};
|
|
619
786
|
}
|
|
620
787
|
return drawn(name, await tool.call(parseInput(given)), input);
|
|
621
788
|
}
|
|
@@ -623,8 +790,8 @@ var COMMAND_TABLE = {
|
|
|
623
790
|
tools: {
|
|
624
791
|
flags: [],
|
|
625
792
|
help: "tools",
|
|
626
|
-
run: async (outbound) => {
|
|
627
|
-
const offered = await offeredTools(outbound);
|
|
793
|
+
run: async (outbound, input) => {
|
|
794
|
+
const offered = await offeredTools(outbound, input.flags);
|
|
628
795
|
return offered.map(describeTool);
|
|
629
796
|
}
|
|
630
797
|
},
|
|
@@ -655,124 +822,384 @@ var listProviders = () => providers.map((provider) => ({
|
|
|
655
822
|
name: provider.name,
|
|
656
823
|
note: provider.note
|
|
657
824
|
}));
|
|
658
|
-
var GLOBAL_HELP = [
|
|
659
|
-
"Options:",
|
|
660
|
-
" --provider <id> the adapter to use, or all for every provider whose key is set (default: OUTBOUND_SDK_PROVIDER)",
|
|
661
|
-
" --compact print JSON on one line",
|
|
662
|
-
" --raw keep each record's raw vendor payload (left out by default)",
|
|
663
|
-
" --config <file> load plugins from a file whose default export is defineConfig({ plugins })",
|
|
664
|
-
" --redact mask personal fields (on by default for mcp)",
|
|
665
|
-
" --no-redact do not mask personal fields, even for mcp",
|
|
666
|
-
" --cache <seconds> reuse an answer for this long, within this process (for mcp; use a config-file store to persist)",
|
|
667
|
-
" --max-requests <n> the most vendor requests one command, or one MCP tool call, may make",
|
|
668
|
-
"",
|
|
669
|
-
"Each adapter reads its own key from the environment, for example INSTANTLY_API_KEY."
|
|
670
|
-
];
|
|
671
|
-
var helpText = () => [
|
|
672
|
-
"outbound: read-only access to outbound sending tools",
|
|
673
|
-
"",
|
|
674
|
-
"Usage: outbound <command> [options]",
|
|
675
|
-
"",
|
|
676
|
-
" providers",
|
|
677
|
-
...[...COMMANDS.values()].map((command) => ` ${command.help}`),
|
|
678
|
-
" mcp start a local MCP server on stdio (redact is on)",
|
|
679
|
-
" version print the installed version (also --version, -v)",
|
|
680
|
-
" update check npm for a newer version and say how to get it",
|
|
681
|
-
"",
|
|
682
|
-
...GLOBAL_HELP
|
|
683
|
-
].join("\n");
|
|
684
|
-
var commandHelp = (command) => [`Usage: outbound ${command.help}`, "", ...GLOBAL_HELP].join("\n");
|
|
685
825
|
|
|
686
|
-
// src/cli/
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
826
|
+
// src/cli/options.ts
|
|
827
|
+
var OPTIONS = {
|
|
828
|
+
bodies: { type: "boolean" },
|
|
829
|
+
by: { type: "string" },
|
|
830
|
+
cache: { type: "string" },
|
|
831
|
+
campaign: { type: "string" },
|
|
832
|
+
card: { type: "boolean" },
|
|
833
|
+
category: { type: "string" },
|
|
834
|
+
compact: { type: "boolean" },
|
|
835
|
+
config: { type: "string" },
|
|
836
|
+
from: { type: "string" },
|
|
837
|
+
help: { short: "h", type: "boolean" },
|
|
838
|
+
"include-inbox": { type: "boolean" },
|
|
839
|
+
input: { type: "string" },
|
|
840
|
+
limit: { type: "string" },
|
|
841
|
+
list: { type: "string" },
|
|
842
|
+
"max-requests": { type: "string" },
|
|
843
|
+
"no-redact": { type: "boolean" },
|
|
844
|
+
provider: { type: "string" },
|
|
845
|
+
raw: { type: "boolean" },
|
|
846
|
+
redact: { type: "boolean" },
|
|
847
|
+
search: { type: "string" },
|
|
848
|
+
sequence: { type: "boolean" },
|
|
849
|
+
settings: { type: "boolean" },
|
|
850
|
+
since: { type: "string" },
|
|
851
|
+
slack: { type: "boolean" },
|
|
852
|
+
stats: { type: "boolean" },
|
|
853
|
+
status: { type: "string" },
|
|
854
|
+
subsequences: { type: "boolean" },
|
|
855
|
+
to: { type: "string" },
|
|
856
|
+
tools: { type: "string" },
|
|
857
|
+
version: { short: "v", type: "boolean" }
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
// src/cli/update.ts
|
|
861
|
+
import { execFile } from "node:child_process";
|
|
862
|
+
import path2 from "node:path";
|
|
863
|
+
import process from "node:process";
|
|
864
|
+
import { setTimeout as setTimeoutPromise } from "node:timers/promises";
|
|
865
|
+
import { fileURLToPath } from "node:url";
|
|
866
|
+
import { promisify } from "node:util";
|
|
867
|
+
|
|
868
|
+
// src/cli/version.ts
|
|
869
|
+
import { readFileSync } from "node:fs";
|
|
870
|
+
import { z } from "zod";
|
|
871
|
+
var Manifest = z.object({
|
|
872
|
+
name: z.literal("outbound-sdk"),
|
|
873
|
+
version: z.string().min(1)
|
|
874
|
+
});
|
|
875
|
+
var packageVersion = () => Manifest.parse(
|
|
876
|
+
JSON.parse(
|
|
877
|
+
readFileSync(new URL("../../package.json", import.meta.url), "utf-8")
|
|
878
|
+
)
|
|
879
|
+
).version;
|
|
880
|
+
|
|
881
|
+
// src/cli/update.ts
|
|
882
|
+
var PACKAGE = "outbound-sdk";
|
|
883
|
+
var STANDALONE = /* @__PURE__ */ new Map([
|
|
884
|
+
["mcp", ["tools"]],
|
|
885
|
+
["providers", []],
|
|
886
|
+
["update", []],
|
|
887
|
+
["version", ["version"]]
|
|
888
|
+
]);
|
|
889
|
+
var execFileAsync = promisify(execFile);
|
|
890
|
+
var NpmFailedError = class extends Error {
|
|
891
|
+
code;
|
|
892
|
+
constructor(message, code, cause) {
|
|
893
|
+
super(message, { cause });
|
|
894
|
+
this.name = "NpmFailedError";
|
|
895
|
+
this.code = code;
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
var NPM_LINE = /^npm (?:error|ERR!) ?(?<said>.*)$/u;
|
|
899
|
+
var NPM_CODE = /^code (?<code>E[A-Z0-9]+)$/u;
|
|
900
|
+
var NPM_DETAIL = /^(?:code|syscall|path|errno|signal|cmd|cwd|command) /u;
|
|
901
|
+
var npmReason = (stderr) => {
|
|
902
|
+
const lines = stderr.split("\n").map((line) => NPM_LINE.exec(line.trim())?.groups?.said?.trim() ?? "").filter((line) => line !== "" && !line.startsWith("A complete log"));
|
|
903
|
+
const code = lines.map((line) => NPM_CODE.exec(line)?.groups?.code).find((found) => found !== void 0);
|
|
904
|
+
const tags = /* @__PURE__ */ new Set(["notarget", code?.toLowerCase()]);
|
|
905
|
+
const untag = (line) => {
|
|
906
|
+
const [first = "", ...rest] = line.split(" ");
|
|
907
|
+
return /^\d{3}$/u.test(first) || tags.has(first) ? rest.join(" ").trim() : line;
|
|
908
|
+
};
|
|
909
|
+
const said = lines.filter((line) => !NPM_DETAIL.test(line)).map(untag).find((line) => line !== "") ?? stderr.trim().split("\n").at(-1) ?? "";
|
|
910
|
+
return { code, said };
|
|
911
|
+
};
|
|
912
|
+
var runNpm = async (args) => {
|
|
695
913
|
try {
|
|
696
|
-
|
|
914
|
+
const { stdout } = await execFileAsync("npm", [...args], {
|
|
915
|
+
shell: process.platform === "win32"
|
|
916
|
+
});
|
|
917
|
+
return stdout;
|
|
697
918
|
} catch (error) {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
throw new OutboundError(
|
|
706
|
-
"Invalid",
|
|
707
|
-
`The config file ${file} has no default export. Export defineConfig({ plugins: [...] })`
|
|
919
|
+
const stderr = error instanceof Error && "stderr" in error ? String(error.stderr) : "";
|
|
920
|
+
const { code, said } = npmReason(stderr);
|
|
921
|
+
const label = code === void 0 ? "" : ` (${code})`;
|
|
922
|
+
throw new NpmFailedError(
|
|
923
|
+
`npm ${args.join(" ")} failed${label}${said === "" ? "" : `: ${said}`}`,
|
|
924
|
+
code,
|
|
925
|
+
error
|
|
708
926
|
);
|
|
709
927
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
928
|
+
};
|
|
929
|
+
var sleep = async (ms) => {
|
|
930
|
+
await setTimeoutPromise(ms);
|
|
931
|
+
};
|
|
932
|
+
var NOT_YET_SERVED = /* @__PURE__ */ new Set(["E404", "ETARGET"]);
|
|
933
|
+
var RETRY_EVERY_MS = 3e4;
|
|
934
|
+
var RETRY_FOR_MS = 15 * 6e4;
|
|
935
|
+
var installGlobal = async (npm, say, wait, version) => {
|
|
936
|
+
const target = `${PACKAGE}@${version}`;
|
|
937
|
+
const tries = RETRY_FOR_MS / RETRY_EVERY_MS;
|
|
938
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
939
|
+
try {
|
|
940
|
+
await npm(
|
|
941
|
+
attempt === 1 ? ["install", "--global", target] : ["install", "--global", "--prefer-online", target]
|
|
942
|
+
);
|
|
943
|
+
return;
|
|
944
|
+
} catch (error) {
|
|
945
|
+
const code = error instanceof NpmFailedError ? error.code : void 0;
|
|
946
|
+
if (code === void 0 || !NOT_YET_SERVED.has(code) || attempt > tries) {
|
|
947
|
+
throw error;
|
|
948
|
+
}
|
|
949
|
+
if (attempt === 1) {
|
|
950
|
+
say(
|
|
951
|
+
`npm lists ${version} but is not serving it yet, which happens for a few minutes after a release. Trying again every ${RETRY_EVERY_MS / 1e3} seconds for up to ${RETRY_FOR_MS / 6e4} minutes; Ctrl-C stops.`
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
await wait(RETRY_EVERY_MS);
|
|
955
|
+
}
|
|
716
956
|
}
|
|
717
|
-
return plugins;
|
|
718
957
|
};
|
|
719
|
-
var
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
)
|
|
958
|
+
var packageDir = () => path2.dirname(fileURLToPath(new URL("../../package.json", import.meta.url)));
|
|
959
|
+
var parts = (version) => version.split("-")[0]?.split(".").map((part) => Math.trunc(Number(part)) || 0) ?? [];
|
|
960
|
+
var older = (a, b) => {
|
|
961
|
+
const [left, right] = [parts(a), parts(b)];
|
|
962
|
+
for (let index = 0; index < 3; index += 1) {
|
|
963
|
+
const difference = (left[index] ?? 0) - (right[index] ?? 0);
|
|
964
|
+
if (difference !== 0) {
|
|
965
|
+
return difference < 0;
|
|
966
|
+
}
|
|
726
967
|
}
|
|
727
|
-
return
|
|
968
|
+
return false;
|
|
728
969
|
};
|
|
729
|
-
var
|
|
730
|
-
if (
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
970
|
+
var installKind = async (npm, dir) => {
|
|
971
|
+
if (dir.split(path2.sep).includes("_npx")) {
|
|
972
|
+
return "npx";
|
|
973
|
+
}
|
|
974
|
+
const printed = await npm(["root", "--global"]).catch(() => "");
|
|
975
|
+
const globalRoot = printed.trim();
|
|
976
|
+
return globalRoot !== "" && path2.dirname(dir) === path2.resolve(globalRoot) ? "global" : "project";
|
|
977
|
+
};
|
|
978
|
+
var update = async (npm, say, wait = sleep) => {
|
|
979
|
+
const installed = packageVersion();
|
|
980
|
+
const viewed = await npm(["view", PACKAGE, "version"]);
|
|
981
|
+
const latest = viewed.trim();
|
|
982
|
+
if (!older(installed, latest)) {
|
|
983
|
+
say(`${PACKAGE} ${installed} is the latest version.`);
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
say(`${PACKAGE} ${installed} is installed; ${latest} is the latest.`);
|
|
987
|
+
const kind = await installKind(npm, packageDir());
|
|
988
|
+
if (kind === "npx") {
|
|
989
|
+
say(`Run "npx ${PACKAGE}@latest <command>" to use ${latest}.`);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
992
|
+
if (kind === "project") {
|
|
993
|
+
say(`Run "npm install ${PACKAGE}@latest" in this project to update it.`);
|
|
994
|
+
return;
|
|
995
|
+
}
|
|
996
|
+
say(`Running "npm install --global ${PACKAGE}@${latest}"...`);
|
|
997
|
+
await installGlobal(npm, say, wait, latest);
|
|
998
|
+
say(`Updated ${PACKAGE} to ${latest}.`);
|
|
999
|
+
};
|
|
1000
|
+
var runSelf = async (name, flags, npm, say, wait = sleep) => {
|
|
1001
|
+
if (name === "version" || name === void 0 && flags.version === true) {
|
|
1002
|
+
say(packageVersion());
|
|
1003
|
+
return true;
|
|
1004
|
+
}
|
|
1005
|
+
if (name === "update" && flags.help !== true) {
|
|
1006
|
+
await update(npm, say, wait);
|
|
1007
|
+
return true;
|
|
1008
|
+
}
|
|
1009
|
+
return false;
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
// src/cli/args.ts
|
|
1013
|
+
var GLOBAL_HELP = [
|
|
1014
|
+
"Options:",
|
|
1015
|
+
" --provider <id> the adapter to use, or all for every provider whose key is set (default: OUTBOUND_SDK_PROVIDER)",
|
|
1016
|
+
" --compact print JSON on one line",
|
|
1017
|
+
" --raw keep each record's raw vendor payload (left out by default)",
|
|
1018
|
+
" --config <file> load plugins from a file whose default export is defineConfig({ plugins })",
|
|
1019
|
+
" --redact mask personal fields (on by default for mcp)",
|
|
1020
|
+
" --no-redact do not mask personal fields, even for mcp",
|
|
1021
|
+
" --cache <seconds> reuse an answer for this long, within this process (for mcp; use a config-file store to persist)",
|
|
1022
|
+
" --max-requests <n> the most vendor requests one command, or one MCP tool call, may make",
|
|
1023
|
+
"",
|
|
1024
|
+
"Each adapter reads its own key from the environment, for example INSTANTLY_API_KEY."
|
|
1025
|
+
];
|
|
1026
|
+
var helpText = () => [
|
|
1027
|
+
"outbound: read-only access to outbound sending tools",
|
|
1028
|
+
"",
|
|
1029
|
+
"Usage: outbound <command> [options]",
|
|
1030
|
+
"",
|
|
1031
|
+
" providers",
|
|
1032
|
+
...[...COMMANDS.values()].map((command) => ` ${command.help}`),
|
|
1033
|
+
" mcp [--tools a,b,...] start a local MCP server on stdio (redact is on); --tools offers only the tools named",
|
|
1034
|
+
" version print the installed version (also --version, -v)",
|
|
1035
|
+
" update check npm for a newer version and say how to get it",
|
|
1036
|
+
"",
|
|
1037
|
+
...GLOBAL_HELP
|
|
1038
|
+
].join("\n");
|
|
1039
|
+
var commandHelp = (command) => [`Usage: outbound ${command.help}`, "", ...GLOBAL_HELP].join("\n");
|
|
1040
|
+
var STRING_OPTIONS = new Set(
|
|
1041
|
+
Object.entries(OPTIONS).flatMap(
|
|
1042
|
+
([name, option]) => option.type === "string" ? [`--${name}`] : []
|
|
1043
|
+
)
|
|
1044
|
+
);
|
|
1045
|
+
var joinNegatives = (argv) => {
|
|
1046
|
+
const joined = [];
|
|
1047
|
+
for (const arg of argv) {
|
|
1048
|
+
const option = joined.at(-1);
|
|
1049
|
+
if (option !== void 0 && STRING_OPTIONS.has(option) && /^-\d/u.test(arg)) {
|
|
1050
|
+
joined[joined.length - 1] = `${option}=${arg}`;
|
|
1051
|
+
} else {
|
|
1052
|
+
joined.push(arg);
|
|
736
1053
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
1054
|
+
}
|
|
1055
|
+
return joined;
|
|
1056
|
+
};
|
|
1057
|
+
var PARSE_ERROR = /^ERR_PARSE_ARGS_/u;
|
|
1058
|
+
var isParseError = (error) => error instanceof Error && "code" in error && typeof error.code === "string" && PARSE_ERROR.test(error.code);
|
|
1059
|
+
var parseStrict = (argv) => {
|
|
1060
|
+
try {
|
|
1061
|
+
return parseArgs({
|
|
1062
|
+
allowPositionals: true,
|
|
1063
|
+
args: [...argv],
|
|
1064
|
+
options: OPTIONS
|
|
1065
|
+
});
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
if (!isParseError(error)) {
|
|
1068
|
+
throw error;
|
|
742
1069
|
}
|
|
743
|
-
|
|
1070
|
+
const [line = error.message] = error.message.split("\n");
|
|
1071
|
+
throw new OutboundError("Invalid", line, { cause: error });
|
|
744
1072
|
}
|
|
745
|
-
return !fromConfig && (flags.redact === true || mcp);
|
|
746
1073
|
};
|
|
747
|
-
var
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
if (wantsRedact(flags, fromConfig, mcp)) {
|
|
752
|
-
const { redact } = await import("../redact/index.js");
|
|
753
|
-
plugins.push(redact());
|
|
1074
|
+
var helpFor = (name, asked) => {
|
|
1075
|
+
const command = name === void 0 ? void 0 : COMMANDS.get(name);
|
|
1076
|
+
if (name === void 0 || name === "help" || asked && !command) {
|
|
1077
|
+
return helpText();
|
|
754
1078
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
1079
|
+
return asked && command ? commandHelp(command) : void 0;
|
|
1080
|
+
};
|
|
1081
|
+
var parse = (given) => {
|
|
1082
|
+
const argv = joinNegatives(given);
|
|
1083
|
+
const loose = parseArgs({
|
|
1084
|
+
allowPositionals: true,
|
|
1085
|
+
args: [...argv],
|
|
1086
|
+
options: OPTIONS,
|
|
1087
|
+
strict: false,
|
|
1088
|
+
tokens: true
|
|
1089
|
+
});
|
|
1090
|
+
const [name] = loose.positionals;
|
|
1091
|
+
const command = name === void 0 ? void 0 : COMMANDS.get(name);
|
|
1092
|
+
const named = name !== void 0 && name !== "help";
|
|
1093
|
+
if (named && !command && !STANDALONE.has(name)) {
|
|
1094
|
+
throw new OutboundError(
|
|
1095
|
+
"Invalid",
|
|
1096
|
+
`Unknown command "${name}".${didYouMean(name, [...COMMANDS.keys(), ...STANDALONE.keys(), "help", "providers"])} Run "outbound help"`
|
|
1097
|
+
);
|
|
765
1098
|
}
|
|
766
|
-
if (
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
1099
|
+
if (named) {
|
|
1100
|
+
checkFlags(
|
|
1101
|
+
name,
|
|
1102
|
+
command?.flags ?? STANDALONE.get(name) ?? [],
|
|
1103
|
+
loose.tokens.flatMap(
|
|
1104
|
+
(token) => token.kind === "option" ? [token.name] : []
|
|
1105
|
+
)
|
|
1106
|
+
);
|
|
770
1107
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1108
|
+
const { positionals, values } = parseStrict(argv);
|
|
1109
|
+
return {
|
|
1110
|
+
help: helpFor(name, values.help === true),
|
|
1111
|
+
name,
|
|
1112
|
+
rest: positionals.slice(1),
|
|
1113
|
+
values
|
|
1114
|
+
};
|
|
1115
|
+
};
|
|
1116
|
+
|
|
1117
|
+
// src/cli/output.ts
|
|
1118
|
+
var isRecord = (value) => isJsonObject(value) && "ref" in value && "schemaVersion" in value;
|
|
1119
|
+
var withoutRaw = (value) => {
|
|
1120
|
+
if (Array.isArray(value)) {
|
|
1121
|
+
return value.map(withoutRaw);
|
|
1122
|
+
}
|
|
1123
|
+
if (!isJsonObject(value)) {
|
|
1124
|
+
return value;
|
|
1125
|
+
}
|
|
1126
|
+
return Object.fromEntries(
|
|
1127
|
+
Object.entries(value).filter(([key]) => !(key === "raw" && isRecord(value))).map(([key, item]) => [key, withoutRaw(item)])
|
|
1128
|
+
);
|
|
1129
|
+
};
|
|
1130
|
+
var printJson = (write, value, options) => {
|
|
1131
|
+
const shown = options.raw === true ? value : withoutRaw(value);
|
|
1132
|
+
write(
|
|
1133
|
+
options.compact === true ? JSON.stringify(shown) : JSON.stringify(shown, null, 2)
|
|
1134
|
+
);
|
|
1135
|
+
};
|
|
1136
|
+
var printAnswer = (write, printed, options, facts) => {
|
|
1137
|
+
printJson(write, envelope(printed, facts), options);
|
|
1138
|
+
};
|
|
1139
|
+
var TEXT_COMMANDS = /* @__PURE__ */ new Set([
|
|
1140
|
+
"mcp",
|
|
1141
|
+
"update",
|
|
1142
|
+
"version"
|
|
1143
|
+
]);
|
|
1144
|
+
var printFailure = (write, run2, failure2, facts) => {
|
|
1145
|
+
if (!TEXT_COMMANDS.has(run2.name ?? "")) {
|
|
1146
|
+
printJson(write, failedEnvelope(failure2, facts), {
|
|
1147
|
+
compact: run2.argv.includes("--compact")
|
|
1148
|
+
});
|
|
774
1149
|
}
|
|
775
|
-
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
// src/cli/progress.ts
|
|
1153
|
+
var SAY_AFTER_MS = 2e3;
|
|
1154
|
+
var UNITS = [
|
|
1155
|
+
[864e5, "day"],
|
|
1156
|
+
[36e5, "hour"],
|
|
1157
|
+
[6e4, "minute"],
|
|
1158
|
+
[1e3, "second"]
|
|
1159
|
+
];
|
|
1160
|
+
var per = (perMs) => {
|
|
1161
|
+
const unit = UNITS.find(([ms]) => perMs === ms);
|
|
1162
|
+
return unit === void 0 ? `per ${perMs / 1e3}s` : `a ${unit[1]}`;
|
|
1163
|
+
};
|
|
1164
|
+
var seconds = (ms) => `${Math.max(1, Math.round(ms / 1e3))}s`;
|
|
1165
|
+
var nameOf = (provider) => findProvider(provider)?.name ?? provider;
|
|
1166
|
+
var limitOf = (event) => {
|
|
1167
|
+
const lane = event.lane === "default" ? "" : ` ${event.lane}`;
|
|
1168
|
+
const windows = event.windows.map((window) => `${window.requests} ${per(window.perMs)}`).join(" and ");
|
|
1169
|
+
return `${nameOf(event.provider)}'s${lane} rate limit${windows === "" ? "" : ` (${windows})`}`;
|
|
1170
|
+
};
|
|
1171
|
+
var describeWait = (event) => event.cause === "vendor" ? `Throttled by ${nameOf(event.provider)}: it answered 429 on ${limitOf(event)}, most likely because another process or tool on the same workspace is reading it too. Retrying in ${seconds(event.waitMs)}. To share one budget between processes, list a rateLimitStore in a --config file.` : `Waiting ${seconds(event.waitMs)} for ${limitOf(event)}\u2026`;
|
|
1172
|
+
var throttleMonitor = (now, say) => {
|
|
1173
|
+
let closedMs = 0;
|
|
1174
|
+
let spanStart = 0;
|
|
1175
|
+
let spanEnd = 0;
|
|
1176
|
+
let reason;
|
|
1177
|
+
const quietUntil = /* @__PURE__ */ new Map();
|
|
1178
|
+
return {
|
|
1179
|
+
hooks: {
|
|
1180
|
+
onThrottle: (event) => {
|
|
1181
|
+
const start = now();
|
|
1182
|
+
const end = start + event.waitMs;
|
|
1183
|
+
if (start > spanEnd) {
|
|
1184
|
+
closedMs += spanEnd - spanStart;
|
|
1185
|
+
spanStart = start;
|
|
1186
|
+
spanEnd = end;
|
|
1187
|
+
} else {
|
|
1188
|
+
spanEnd = Math.max(spanEnd, end);
|
|
1189
|
+
}
|
|
1190
|
+
reason = describeWait(event);
|
|
1191
|
+
const key = `${event.provider}#${event.lane}#${event.cause}`;
|
|
1192
|
+
if (event.waitMs > SAY_AFTER_MS && start >= (quietUntil.get(key) ?? Number.NEGATIVE_INFINITY)) {
|
|
1193
|
+
quietUntil.set(key, end);
|
|
1194
|
+
say(reason);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
total: () => ({
|
|
1199
|
+
ms: closedMs + Math.max(0, Math.min(now(), spanEnd) - spanStart),
|
|
1200
|
+
reason
|
|
1201
|
+
})
|
|
1202
|
+
};
|
|
776
1203
|
};
|
|
777
1204
|
|
|
778
1205
|
// src/cli/mcp.ts
|
|
@@ -781,7 +1208,7 @@ var PROTOCOL_VERSIONS = [
|
|
|
781
1208
|
"2025-03-26",
|
|
782
1209
|
"2024-11-05"
|
|
783
1210
|
];
|
|
784
|
-
var
|
|
1211
|
+
var PARSE_ERROR2 = -32700;
|
|
785
1212
|
var INVALID_REQUEST = -32600;
|
|
786
1213
|
var METHOD_NOT_FOUND = -32601;
|
|
787
1214
|
var INVALID_PARAMS = -32602;
|
|
@@ -807,6 +1234,24 @@ var describeLeftOut = (outbound, leftOut) => {
|
|
|
807
1234
|
};
|
|
808
1235
|
var hasRequestBudget = (value) => "requestBudget" in value && typeof value.requestBudget === "object" && value.requestBudget !== null && "reset" in value.requestBudget && typeof value.requestBudget.reset === "function";
|
|
809
1236
|
var budgetOf = (outbound) => hasRequestBudget(outbound) ? outbound.requestBudget : void 0;
|
|
1237
|
+
var NOTE_THROTTLE_AFTER_MS = 5e3;
|
|
1238
|
+
var withWait = (outcome, waitedMs, reason) => {
|
|
1239
|
+
if (waitedMs <= NOTE_THROTTLE_AFTER_MS) {
|
|
1240
|
+
return outcome;
|
|
1241
|
+
}
|
|
1242
|
+
const note = `This call waited ${Math.round(waitedMs / 1e3)}s on rate limits, so it was slow, not stuck. Last wait: ${reason ?? "unknown"}`;
|
|
1243
|
+
return outcome.ok ? {
|
|
1244
|
+
...outcome,
|
|
1245
|
+
meta: {
|
|
1246
|
+
...outcome.meta,
|
|
1247
|
+
notes: [...outcome.meta.notes, note],
|
|
1248
|
+
throttledMs: waitedMs
|
|
1249
|
+
}
|
|
1250
|
+
} : {
|
|
1251
|
+
...outcome,
|
|
1252
|
+
meta: { requests: outcome.meta?.requests ?? 0, throttledMs: waitedMs }
|
|
1253
|
+
};
|
|
1254
|
+
};
|
|
810
1255
|
var result = (id, value) => ({
|
|
811
1256
|
id,
|
|
812
1257
|
jsonrpc: "2.0",
|
|
@@ -850,7 +1295,10 @@ var createMcpServer = (outbound, options = {}) => {
|
|
|
850
1295
|
);
|
|
851
1296
|
}
|
|
852
1297
|
budget?.reset();
|
|
853
|
-
const
|
|
1298
|
+
const before = options.throttled?.().ms ?? 0;
|
|
1299
|
+
const called = await tool.call(field(params, "arguments") ?? {});
|
|
1300
|
+
const after = options.throttled?.();
|
|
1301
|
+
const outcome = withWait(called, (after?.ms ?? 0) - before, after?.reason);
|
|
854
1302
|
const structured = toJson(outcome);
|
|
855
1303
|
return result(id, {
|
|
856
1304
|
content: [{ text: JSON.stringify(outcome), type: "text" }],
|
|
@@ -900,7 +1348,7 @@ var createMcpServer = (outbound, options = {}) => {
|
|
|
900
1348
|
}
|
|
901
1349
|
const message = parseJson(line);
|
|
902
1350
|
if (message === void 0) {
|
|
903
|
-
return JSON.stringify(failure(null,
|
|
1351
|
+
return JSON.stringify(failure(null, PARSE_ERROR2, "Parse error"));
|
|
904
1352
|
}
|
|
905
1353
|
const response = await handle(message);
|
|
906
1354
|
return response === void 0 ? void 0 : JSON.stringify(response);
|
|
@@ -908,80 +1356,13 @@ var createMcpServer = (outbound, options = {}) => {
|
|
|
908
1356
|
};
|
|
909
1357
|
};
|
|
910
1358
|
|
|
911
|
-
// src/cli/options.ts
|
|
912
|
-
var OPTIONS = {
|
|
913
|
-
bodies: { type: "boolean" },
|
|
914
|
-
by: { type: "string" },
|
|
915
|
-
cache: { type: "string" },
|
|
916
|
-
campaign: { type: "string" },
|
|
917
|
-
card: { type: "boolean" },
|
|
918
|
-
category: { type: "string" },
|
|
919
|
-
compact: { type: "boolean" },
|
|
920
|
-
config: { type: "string" },
|
|
921
|
-
from: { type: "string" },
|
|
922
|
-
help: { short: "h", type: "boolean" },
|
|
923
|
-
input: { type: "string" },
|
|
924
|
-
limit: { type: "string" },
|
|
925
|
-
list: { type: "string" },
|
|
926
|
-
"max-requests": { type: "string" },
|
|
927
|
-
"no-redact": { type: "boolean" },
|
|
928
|
-
provider: { type: "string" },
|
|
929
|
-
raw: { type: "boolean" },
|
|
930
|
-
redact: { type: "boolean" },
|
|
931
|
-
search: { type: "string" },
|
|
932
|
-
sequence: { type: "boolean" },
|
|
933
|
-
settings: { type: "boolean" },
|
|
934
|
-
since: { type: "string" },
|
|
935
|
-
slack: { type: "boolean" },
|
|
936
|
-
stats: { type: "boolean" },
|
|
937
|
-
status: { type: "string" },
|
|
938
|
-
subsequences: { type: "boolean" },
|
|
939
|
-
to: { type: "string" },
|
|
940
|
-
version: { short: "v", type: "boolean" }
|
|
941
|
-
};
|
|
942
|
-
|
|
943
|
-
// src/cli/output.ts
|
|
944
|
-
var isRecord = (value) => isJsonObject(value) && "ref" in value && "schemaVersion" in value;
|
|
945
|
-
var withoutRaw = (value) => {
|
|
946
|
-
if (Array.isArray(value)) {
|
|
947
|
-
return value.map(withoutRaw);
|
|
948
|
-
}
|
|
949
|
-
if (!isJsonObject(value)) {
|
|
950
|
-
return value;
|
|
951
|
-
}
|
|
952
|
-
return Object.fromEntries(
|
|
953
|
-
Object.entries(value).filter(([key]) => !(key === "raw" && isRecord(value))).map(([key, item]) => [key, withoutRaw(item)])
|
|
954
|
-
);
|
|
955
|
-
};
|
|
956
|
-
var printJson = (write, value, options) => {
|
|
957
|
-
const shown = options.raw === true ? value : withoutRaw(value);
|
|
958
|
-
write(
|
|
959
|
-
options.compact === true ? JSON.stringify(shown) : JSON.stringify(shown, null, 2)
|
|
960
|
-
);
|
|
961
|
-
};
|
|
962
|
-
var printAnswer = (write, printed, options, facts) => {
|
|
963
|
-
printJson(write, envelope(printed, facts), options);
|
|
964
|
-
};
|
|
965
|
-
var TEXT_COMMANDS = /* @__PURE__ */ new Set([
|
|
966
|
-
"mcp",
|
|
967
|
-
"update",
|
|
968
|
-
"version"
|
|
969
|
-
]);
|
|
970
|
-
var printFailure = (write, run2, failure2, facts) => {
|
|
971
|
-
if (!TEXT_COMMANDS.has(run2.name ?? "")) {
|
|
972
|
-
printJson(write, failedEnvelope(failure2, facts), {
|
|
973
|
-
compact: run2.argv.includes("--compact")
|
|
974
|
-
});
|
|
975
|
-
}
|
|
976
|
-
};
|
|
977
|
-
|
|
978
1359
|
// src/cli/stdio.ts
|
|
979
|
-
import
|
|
1360
|
+
import process2 from "node:process";
|
|
980
1361
|
import { createInterface } from "node:readline";
|
|
981
1362
|
var serveStdio = async (server, options = {}) => {
|
|
982
|
-
const input = options.input ?? createInterface({ input:
|
|
1363
|
+
const input = options.input ?? createInterface({ input: process2.stdin });
|
|
983
1364
|
const write = options.write ?? ((line) => {
|
|
984
|
-
|
|
1365
|
+
process2.stdout.write(`${line}
|
|
985
1366
|
`);
|
|
986
1367
|
});
|
|
987
1368
|
for await (const line of input) {
|
|
@@ -992,175 +1373,74 @@ var serveStdio = async (server, options = {}) => {
|
|
|
992
1373
|
}
|
|
993
1374
|
};
|
|
994
1375
|
|
|
995
|
-
// src/cli/
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
import { fileURLToPath } from "node:url";
|
|
1000
|
-
import { promisify } from "node:util";
|
|
1001
|
-
|
|
1002
|
-
// src/cli/version.ts
|
|
1003
|
-
import { readFileSync } from "node:fs";
|
|
1004
|
-
import { z } from "zod";
|
|
1005
|
-
var Manifest = z.object({
|
|
1006
|
-
name: z.literal("outbound-sdk"),
|
|
1007
|
-
version: z.string().min(1)
|
|
1008
|
-
});
|
|
1009
|
-
var packageVersion = () => Manifest.parse(
|
|
1010
|
-
JSON.parse(
|
|
1011
|
-
readFileSync(new URL("../../package.json", import.meta.url), "utf-8")
|
|
1012
|
-
)
|
|
1013
|
-
).version;
|
|
1014
|
-
|
|
1015
|
-
// src/cli/update.ts
|
|
1016
|
-
var PACKAGE = "outbound-sdk";
|
|
1017
|
-
var STANDALONE = /* @__PURE__ */ new Map([
|
|
1018
|
-
["mcp", []],
|
|
1019
|
-
["providers", []],
|
|
1020
|
-
["update", []],
|
|
1021
|
-
["version", ["version"]]
|
|
1022
|
-
]);
|
|
1023
|
-
var execFileAsync = promisify(execFile);
|
|
1024
|
-
var runNpm = async (args) => {
|
|
1025
|
-
try {
|
|
1026
|
-
const { stdout } = await execFileAsync("npm", [...args], {
|
|
1027
|
-
shell: process2.platform === "win32"
|
|
1028
|
-
});
|
|
1029
|
-
return stdout;
|
|
1030
|
-
} catch (error) {
|
|
1031
|
-
const stderr = error instanceof Error && "stderr" in error ? String(error.stderr) : "";
|
|
1032
|
-
const said = stderr.trim().split("\n").at(-1) ?? "";
|
|
1033
|
-
throw new Error(
|
|
1034
|
-
`npm ${args.join(" ")} failed${said === "" ? "" : `: ${said}`}`,
|
|
1035
|
-
{ cause: error }
|
|
1036
|
-
);
|
|
1037
|
-
}
|
|
1038
|
-
};
|
|
1039
|
-
var packageDir = () => path2.dirname(fileURLToPath(new URL("../../package.json", import.meta.url)));
|
|
1040
|
-
var parts = (version) => version.split("-")[0]?.split(".").map((part) => Math.trunc(Number(part)) || 0) ?? [];
|
|
1041
|
-
var older = (a, b) => {
|
|
1042
|
-
const [left, right] = [parts(a), parts(b)];
|
|
1043
|
-
for (let index = 0; index < 3; index += 1) {
|
|
1044
|
-
const difference = (left[index] ?? 0) - (right[index] ?? 0);
|
|
1045
|
-
if (difference !== 0) {
|
|
1046
|
-
return difference < 0;
|
|
1047
|
-
}
|
|
1376
|
+
// src/cli/serve.ts
|
|
1377
|
+
var namedTools = (given) => {
|
|
1378
|
+
if (given === void 0) {
|
|
1379
|
+
return void 0;
|
|
1048
1380
|
}
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
const printed = await npm(["root", "--global"]).catch(() => "");
|
|
1056
|
-
const globalRoot = printed.trim();
|
|
1057
|
-
return globalRoot !== "" && path2.dirname(dir) === path2.resolve(globalRoot) ? "global" : "project";
|
|
1058
|
-
};
|
|
1059
|
-
var update = async (npm, say) => {
|
|
1060
|
-
const installed = packageVersion();
|
|
1061
|
-
const viewed = await npm(["view", PACKAGE, "version"]);
|
|
1062
|
-
const latest = viewed.trim();
|
|
1063
|
-
if (!older(installed, latest)) {
|
|
1064
|
-
say(`${PACKAGE} ${installed} is the latest version.`);
|
|
1065
|
-
return;
|
|
1066
|
-
}
|
|
1067
|
-
say(`${PACKAGE} ${installed} is installed; ${latest} is the latest.`);
|
|
1068
|
-
const kind = await installKind(npm, packageDir());
|
|
1069
|
-
if (kind === "npx") {
|
|
1070
|
-
say(`Run "npx ${PACKAGE}@latest <command>" to use ${latest}.`);
|
|
1071
|
-
return;
|
|
1072
|
-
}
|
|
1073
|
-
if (kind === "project") {
|
|
1074
|
-
say(`Run "npm install ${PACKAGE}@latest" in this project to update it.`);
|
|
1075
|
-
return;
|
|
1076
|
-
}
|
|
1077
|
-
say(`Running "npm install --global ${PACKAGE}@latest"...`);
|
|
1078
|
-
await npm(["install", "--global", `${PACKAGE}@latest`]);
|
|
1079
|
-
say(`Updated ${PACKAGE} to ${latest}.`);
|
|
1080
|
-
};
|
|
1081
|
-
var runSelf = async (name, flags, npm, say) => {
|
|
1082
|
-
if (name === "version" || name === void 0 && flags.version === true) {
|
|
1083
|
-
say(packageVersion());
|
|
1084
|
-
return true;
|
|
1085
|
-
}
|
|
1086
|
-
if (name === "update" && flags.help !== true) {
|
|
1087
|
-
await update(npm, say);
|
|
1088
|
-
return true;
|
|
1381
|
+
const names = given.split(",").map((name) => name.trim()).filter((name) => name !== "");
|
|
1382
|
+
if (names.length === 0) {
|
|
1383
|
+
throw new OutboundError(
|
|
1384
|
+
"Invalid",
|
|
1385
|
+
"--tools takes tool names separated by commas, such as --tools campaign_overview,hot_leads"
|
|
1386
|
+
);
|
|
1089
1387
|
}
|
|
1090
|
-
return
|
|
1388
|
+
return new Set(names);
|
|
1091
1389
|
};
|
|
1092
|
-
|
|
1093
|
-
// src/cli/index.ts
|
|
1094
|
-
var serve = async (outbound, io, unmasked) => {
|
|
1390
|
+
var serve = async (outbound, io, unmasked, wanted, caps) => {
|
|
1095
1391
|
const { insightTools } = await import("../insights/index.js");
|
|
1096
|
-
const offered = (instance) => createTools(instance, { extra: insightTools(instance) }).map(
|
|
1392
|
+
const offered = (instance) => createTools(instance, { extra: insightTools(instance, caps) }).map(
|
|
1097
1393
|
(tool) => tool.name
|
|
1098
1394
|
);
|
|
1099
|
-
const here =
|
|
1395
|
+
const here = offered(outbound);
|
|
1396
|
+
const masked = (unmasked === void 0 ? [] : offered(unmasked)).filter(
|
|
1397
|
+
(name) => !here.includes(name)
|
|
1398
|
+
);
|
|
1399
|
+
const known = [...here, ...masked];
|
|
1400
|
+
for (const name of wanted ?? []) {
|
|
1401
|
+
if (!known.includes(name)) {
|
|
1402
|
+
throw new OutboundError(
|
|
1403
|
+
"Invalid",
|
|
1404
|
+
`--tools: "${name}" is not a tool this server can offer.${didYouMean(name, known)} Run "outbound tools" to list them`
|
|
1405
|
+
);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
const keeps = (name) => wanted === void 0 || wanted.has(name);
|
|
1100
1409
|
const leftOut = Object.fromEntries(
|
|
1101
|
-
|
|
1410
|
+
masked.filter(keeps).map((name) => [
|
|
1102
1411
|
name,
|
|
1103
1412
|
`${name} is left out while the redact plugin is on: it needs what redact masks. Start the server with --no-redact to offer it; personal fields are then not masked.`
|
|
1104
1413
|
])
|
|
1105
1414
|
);
|
|
1106
1415
|
const server = createMcpServer(outbound, {
|
|
1107
|
-
|
|
1416
|
+
// Given the allowlist, so no insight's hint names an insight left out.
|
|
1417
|
+
extra: insightTools(outbound, {
|
|
1418
|
+
...caps,
|
|
1419
|
+
only: wanted === void 0 ? void 0 : [...wanted]
|
|
1420
|
+
}),
|
|
1108
1421
|
leftOut,
|
|
1422
|
+
only: TOOL_NAMES.filter(keeps),
|
|
1423
|
+
throttled: io.throttled,
|
|
1109
1424
|
version: packageVersion()
|
|
1110
1425
|
});
|
|
1111
1426
|
await serveStdio(server, { input: io.stdin?.() ?? [], write: io.stdout });
|
|
1112
1427
|
};
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
const command = name === void 0 ? void 0 : COMMANDS.get(name);
|
|
1116
|
-
if (name === void 0 || name === "help" || asked && !command) {
|
|
1117
|
-
return helpText();
|
|
1118
|
-
}
|
|
1119
|
-
return asked && command ? commandHelp(command) : void 0;
|
|
1120
|
-
};
|
|
1121
|
-
var parse = (argv) => {
|
|
1122
|
-
const loose = parseArgs({
|
|
1123
|
-
allowPositionals: true,
|
|
1124
|
-
args: [...argv],
|
|
1125
|
-
options: OPTIONS,
|
|
1126
|
-
strict: false,
|
|
1127
|
-
tokens: true
|
|
1128
|
-
});
|
|
1129
|
-
const [name] = loose.positionals;
|
|
1130
|
-
const command = name === void 0 ? void 0 : COMMANDS.get(name);
|
|
1131
|
-
const named = name !== void 0 && name !== "help";
|
|
1132
|
-
if (named && !command && !STANDALONE.has(name)) {
|
|
1133
|
-
throw new OutboundError(
|
|
1134
|
-
"Invalid",
|
|
1135
|
-
`Unknown command "${name}".${didYouMean(name, [...COMMANDS.keys(), ...STANDALONE.keys(), "help", "providers"])} Run "outbound help"`
|
|
1136
|
-
);
|
|
1137
|
-
}
|
|
1138
|
-
if (named) {
|
|
1139
|
-
checkFlags(
|
|
1140
|
-
name,
|
|
1141
|
-
command?.flags ?? STANDALONE.get(name) ?? [],
|
|
1142
|
-
loose.tokens.flatMap(
|
|
1143
|
-
(token) => token.kind === "option" ? [token.name] : []
|
|
1144
|
-
)
|
|
1145
|
-
);
|
|
1146
|
-
}
|
|
1147
|
-
const { positionals, values } = parseStrict(argv);
|
|
1148
|
-
return {
|
|
1149
|
-
help: helpFor(name, values.help === true),
|
|
1150
|
-
name,
|
|
1151
|
-
rest: positionals.slice(1),
|
|
1152
|
-
values
|
|
1153
|
-
};
|
|
1154
|
-
};
|
|
1428
|
+
|
|
1429
|
+
// src/cli/index.ts
|
|
1155
1430
|
var run = async (argv, io) => {
|
|
1156
1431
|
const counter = requestCounter();
|
|
1432
|
+
const monitor = throttleMonitor(io.runtime?.now ?? Date.now, io.stderr);
|
|
1157
1433
|
let provider = null;
|
|
1158
|
-
const facts = () => ({
|
|
1434
|
+
const facts = () => ({
|
|
1435
|
+
provider,
|
|
1436
|
+
requests: counter.sent(),
|
|
1437
|
+
throttledMs: monitor.total().ms
|
|
1438
|
+
});
|
|
1159
1439
|
let named;
|
|
1160
1440
|
try {
|
|
1161
1441
|
const { help, name, rest, values } = parse(argv);
|
|
1162
1442
|
named = name;
|
|
1163
|
-
if (await runSelf(name, values, io.npm ?? runNpm, io.stdout)) {
|
|
1443
|
+
if (await runSelf(name, values, io.npm ?? runNpm, io.stdout, io.sleep)) {
|
|
1164
1444
|
return 0;
|
|
1165
1445
|
}
|
|
1166
1446
|
if (help !== void 0) {
|
|
@@ -1173,18 +1453,36 @@ var run = async (argv, io) => {
|
|
|
1173
1453
|
}
|
|
1174
1454
|
const command = name === void 0 ? void 0 : COMMANDS.get(name);
|
|
1175
1455
|
const adapter = io.adapter ?? await fromEnv({ provider: values.provider });
|
|
1176
|
-
const plugins = await
|
|
1456
|
+
const { plugins, rateLimitStore } = await setupFor(
|
|
1457
|
+
values,
|
|
1458
|
+
command === void 0,
|
|
1459
|
+
io.stderr
|
|
1460
|
+
);
|
|
1177
1461
|
if (command !== void 0) {
|
|
1178
1462
|
plugins.push(counter);
|
|
1179
1463
|
}
|
|
1180
|
-
const outbound = createOutbound({
|
|
1464
|
+
const outbound = createOutbound({
|
|
1465
|
+
adapter,
|
|
1466
|
+
fetch: io.fetch,
|
|
1467
|
+
hooks: monitor.hooks,
|
|
1468
|
+
plugins,
|
|
1469
|
+
rateLimitStore,
|
|
1470
|
+
runtime: io.runtime
|
|
1471
|
+
});
|
|
1181
1472
|
({ provider } = outbound);
|
|
1182
1473
|
if (command === void 0) {
|
|
1183
1474
|
const unmasked = plugins.some((plugin) => plugin.name === "redact") ? createOutbound({
|
|
1184
1475
|
adapter,
|
|
1185
1476
|
plugins: plugins.filter((plugin) => plugin.name !== "redact")
|
|
1186
1477
|
}) : void 0;
|
|
1187
|
-
await serve(
|
|
1478
|
+
await serve(
|
|
1479
|
+
outbound,
|
|
1480
|
+
{ ...io, throttled: monitor.total },
|
|
1481
|
+
unmasked,
|
|
1482
|
+
namedTools(values.tools),
|
|
1483
|
+
// A tool call may spend what --max-requests allows, which replaces an insight's default cap.
|
|
1484
|
+
insightToolCaps(values, true)
|
|
1485
|
+
);
|
|
1188
1486
|
return 0;
|
|
1189
1487
|
}
|
|
1190
1488
|
const answer = await command.run(outbound, {
|
|
@@ -1193,7 +1491,11 @@ var run = async (argv, io) => {
|
|
|
1193
1491
|
positionals: rest
|
|
1194
1492
|
});
|
|
1195
1493
|
printAnswer(io.stdout, answer, values, facts());
|
|
1196
|
-
|
|
1494
|
+
const printed = valueOf(answer);
|
|
1495
|
+
if (name !== "tool" || field(printed, "ok") !== false) {
|
|
1496
|
+
return 0;
|
|
1497
|
+
}
|
|
1498
|
+
return field(field(printed, "error"), "code") === "InputRequired" ? 2 : 1;
|
|
1197
1499
|
} catch (error) {
|
|
1198
1500
|
const code = OutboundError.is(error) ? error.code : "Error";
|
|
1199
1501
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1205,6 +1507,8 @@ var run = async (argv, io) => {
|
|
|
1205
1507
|
|
|
1206
1508
|
export {
|
|
1207
1509
|
defineConfig,
|
|
1510
|
+
describeWait,
|
|
1511
|
+
throttleMonitor,
|
|
1208
1512
|
PROTOCOL_VERSIONS,
|
|
1209
1513
|
createMcpServer,
|
|
1210
1514
|
serveStdio,
|