kenso 0.1.72 → 0.1.73
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/CHANGELOG.md +4 -0
- package/README.md +3 -0
- package/dist/kenso.js +1492 -621
- package/dist/operations.json +1 -1
- package/docs/README.md +2 -1
- package/docs/connect.md +73 -0
- package/docs/output-and-errors.md +27 -0
- package/docs/reference.md +73 -4
- package/package.json +2 -2
- package/skill/kenso-cli/SKILL.md +2 -0
package/dist/kenso.js
CHANGED
|
@@ -93,8 +93,8 @@ var init_exit_codes = __esm({
|
|
|
93
93
|
});
|
|
94
94
|
|
|
95
95
|
// src/core/redact.ts
|
|
96
|
-
function redact(
|
|
97
|
-
return
|
|
96
|
+
function redact(text4) {
|
|
97
|
+
return text4.replace(KEY_PATTERN, "ken_***").replace(KENSO_KEY_PATTERN, "$1***").replace(RUN_TOKEN_PATTERN, "krt_***").replace(BEARER_PATTERN, "$1***").replace(AUTH_HEADER_PATTERN, "$1***");
|
|
98
98
|
}
|
|
99
99
|
var KEY_PATTERN, KENSO_KEY_PATTERN, RUN_TOKEN_PATTERN, BEARER_PATTERN, AUTH_HEADER_PATTERN;
|
|
100
100
|
var init_redact = __esm({
|
|
@@ -137,9 +137,9 @@ function asRecord(value) {
|
|
|
137
137
|
function nonEmptyString(value) {
|
|
138
138
|
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
139
139
|
}
|
|
140
|
-
function errorFromResponse(status,
|
|
140
|
+
function errorFromResponse(status, body2, requestId) {
|
|
141
141
|
const defaults = defaultsForStatus(status);
|
|
142
|
-
const envelope = asRecord(
|
|
142
|
+
const envelope = asRecord(body2);
|
|
143
143
|
const canonical2 = asRecord(envelope?.error);
|
|
144
144
|
let code = defaults.code;
|
|
145
145
|
let exitCode = defaults.exitCode;
|
|
@@ -156,9 +156,9 @@ function errorFromResponse(status, body, requestId) {
|
|
|
156
156
|
} else if (envelope) {
|
|
157
157
|
message = nonEmptyString(envelope.message) ?? nonEmptyString(envelope.detail) ?? nonEmptyString(envelope.title);
|
|
158
158
|
requestId = requestId ?? nonEmptyString(envelope.requestId) ?? nonEmptyString(envelope.traceId);
|
|
159
|
-
} else if (typeof
|
|
160
|
-
const
|
|
161
|
-
message =
|
|
159
|
+
} else if (typeof body2 === "string" && body2.trim() !== "") {
|
|
160
|
+
const text4 = body2.trim();
|
|
161
|
+
message = text4.length > MAX_TEXT_MESSAGE ? `${text4.slice(0, MAX_TEXT_MESSAGE)}...` : text4;
|
|
162
162
|
}
|
|
163
163
|
if (code === "workspace_required") {
|
|
164
164
|
exitCode = ExitCode.Usage;
|
|
@@ -178,7 +178,7 @@ function errorFromResponse(status, body, requestId) {
|
|
|
178
178
|
hint,
|
|
179
179
|
next,
|
|
180
180
|
requestId,
|
|
181
|
-
details:
|
|
181
|
+
details: body2
|
|
182
182
|
});
|
|
183
183
|
}
|
|
184
184
|
var KensoError, WORKSPACE_NEXT, MAX_TEXT_MESSAGE;
|
|
@@ -252,16 +252,16 @@ function cleanProfile(value) {
|
|
|
252
252
|
}
|
|
253
253
|
function readConfig(env = process.env) {
|
|
254
254
|
const file = configPath(env);
|
|
255
|
-
let
|
|
255
|
+
let text4;
|
|
256
256
|
try {
|
|
257
|
-
|
|
257
|
+
text4 = readFileSync(file, "utf8");
|
|
258
258
|
} catch (err) {
|
|
259
259
|
if (err.code === "ENOENT") return defaultConfig();
|
|
260
260
|
throw err;
|
|
261
261
|
}
|
|
262
262
|
let parsed2;
|
|
263
263
|
try {
|
|
264
|
-
parsed2 = JSON.parse(
|
|
264
|
+
parsed2 = JSON.parse(text4);
|
|
265
265
|
} catch {
|
|
266
266
|
throw new KensoError({
|
|
267
267
|
code: "config_invalid",
|
|
@@ -367,22 +367,22 @@ import { setTimeout as delay } from "node:timers/promises";
|
|
|
367
367
|
function asRecord2(value) {
|
|
368
368
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
369
369
|
}
|
|
370
|
-
function unwrap(
|
|
371
|
-
const record = asRecord2(
|
|
370
|
+
function unwrap(body2) {
|
|
371
|
+
const record = asRecord2(body2);
|
|
372
372
|
if (record && "success" in record && "data" in record) return record.data;
|
|
373
|
-
return
|
|
373
|
+
return body2;
|
|
374
374
|
}
|
|
375
375
|
function interruptedError() {
|
|
376
376
|
return new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted });
|
|
377
377
|
}
|
|
378
|
-
function parseBody(
|
|
379
|
-
if (
|
|
380
|
-
const looksJson = contentType?.includes("json") || /^\s*[[{]/.test(
|
|
381
|
-
if (!looksJson) return
|
|
378
|
+
function parseBody(text4, contentType) {
|
|
379
|
+
if (text4 === "") return null;
|
|
380
|
+
const looksJson = contentType?.includes("json") || /^\s*[[{]/.test(text4);
|
|
381
|
+
if (!looksJson) return text4;
|
|
382
382
|
try {
|
|
383
|
-
return JSON.parse(
|
|
383
|
+
return JSON.parse(text4);
|
|
384
384
|
} catch {
|
|
385
|
-
return
|
|
385
|
+
return text4;
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
function retryAfterMs(headers) {
|
|
@@ -420,6 +420,15 @@ function describeNetworkError(err) {
|
|
|
420
420
|
}
|
|
421
421
|
return String(err);
|
|
422
422
|
}
|
|
423
|
+
function noApiKeyError() {
|
|
424
|
+
return new KensoError({
|
|
425
|
+
code: "no_api_key",
|
|
426
|
+
message: "No Kenso API key is configured.",
|
|
427
|
+
exitCode: ExitCode.Auth,
|
|
428
|
+
hint: "Set KENSO_API_KEY, or save a key with kenso auth login --with-key.",
|
|
429
|
+
next: "kenso auth login"
|
|
430
|
+
});
|
|
431
|
+
}
|
|
423
432
|
var KEN_VERSION, REQUEST_TIMEOUT_MS, TRANSIENT_STATUSES, MAX_TRANSIENT_RETRIES, DEFAULT_RATE_LIMIT_BUDGET_MS, MIN_RATE_LIMIT_WAIT_MS, MAX_RATE_LIMIT_WAIT_MS, KensoClient;
|
|
424
433
|
var init_http = __esm({
|
|
425
434
|
"src/core/http.ts"() {
|
|
@@ -454,21 +463,13 @@ var init_http = __esm({
|
|
|
454
463
|
}
|
|
455
464
|
/** Sends one API call. Throws KensoError on a non-2xx answer after retries. */
|
|
456
465
|
async request(req) {
|
|
457
|
-
if (!req.anonymous && !this.opts.apiKey)
|
|
458
|
-
throw new KensoError({
|
|
459
|
-
code: "no_api_key",
|
|
460
|
-
message: "No Kenso API key is configured.",
|
|
461
|
-
exitCode: ExitCode.Auth,
|
|
462
|
-
hint: "Set KENSO_API_KEY, or save a key with kenso auth login --with-key.",
|
|
463
|
-
next: "kenso auth login"
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
+
if (!req.anonymous && !this.opts.apiKey) throw noApiKeyError();
|
|
466
467
|
if (req.method === "GET" && (req.body !== void 0 || req.form !== void 0)) {
|
|
467
468
|
throw usageError("A GET request cannot carry a body.", { field: "data", hint: "Send the values in the query string, or use another method." });
|
|
468
469
|
}
|
|
469
470
|
const url = this.buildUrl(req.path, req.query);
|
|
470
471
|
const headers = this.buildHeaders(req);
|
|
471
|
-
const
|
|
472
|
+
const body2 = req.form ?? (req.body !== void 0 ? JSON.stringify(req.body) : void 0);
|
|
472
473
|
const mayRetryTransient = req.method !== "POST" || req.retrySafe === true;
|
|
473
474
|
const callerSignal = req.signal ?? this.opts.signal;
|
|
474
475
|
let attempt = 0;
|
|
@@ -481,10 +482,10 @@ var init_http = __esm({
|
|
|
481
482
|
const signal = callerSignal ? AbortSignal.any([callerSignal, timeout]) : timeout;
|
|
482
483
|
const started = Date.now();
|
|
483
484
|
let res;
|
|
484
|
-
let
|
|
485
|
+
let text4;
|
|
485
486
|
try {
|
|
486
|
-
res = await this.fetchImpl(url, { method: req.method, headers, body, signal });
|
|
487
|
-
|
|
487
|
+
res = await this.fetchImpl(url, { method: req.method, headers, body: body2, signal });
|
|
488
|
+
text4 = await res.text();
|
|
488
489
|
} catch (err) {
|
|
489
490
|
if (callerSignal?.aborted) throw interruptedError();
|
|
490
491
|
if (!isNetworkFailure(err)) {
|
|
@@ -511,7 +512,7 @@ var init_http = __esm({
|
|
|
511
512
|
}
|
|
512
513
|
const requestId = res.headers.get("x-request-id") ?? void 0;
|
|
513
514
|
this.opts.onResponse?.({ method: req.method, url, status: res.status, ms: Date.now() - started, requestId });
|
|
514
|
-
const parsed2 = parseBody(
|
|
515
|
+
const parsed2 = parseBody(text4, res.headers.get("content-type"));
|
|
515
516
|
if (res.status === 429) {
|
|
516
517
|
const remaining = this.rateLimitBudgetMs - this.rateLimitWaitedMs;
|
|
517
518
|
if (remaining <= 0) throw errorFromResponse(res.status, parsed2, requestId);
|
|
@@ -548,14 +549,14 @@ var init_http = __esm({
|
|
|
548
549
|
const page = { ...req, query };
|
|
549
550
|
if (cursor2 !== void 0 && inBody) page.body = { ...asRecord2(req.body), cursor: cursor2 };
|
|
550
551
|
const res = await this.request(page);
|
|
551
|
-
const
|
|
552
|
-
if (Array.isArray(
|
|
553
|
-
yield*
|
|
552
|
+
const body2 = res.body;
|
|
553
|
+
if (Array.isArray(body2)) {
|
|
554
|
+
yield* body2;
|
|
554
555
|
return;
|
|
555
556
|
}
|
|
556
|
-
const record = asRecord2(
|
|
557
|
+
const record = asRecord2(body2);
|
|
557
558
|
if (!record || !Array.isArray(record.data)) {
|
|
558
|
-
yield unwrap(
|
|
559
|
+
yield unwrap(body2);
|
|
559
560
|
return;
|
|
560
561
|
}
|
|
561
562
|
yield* record.data;
|
|
@@ -566,6 +567,42 @@ var init_http = __esm({
|
|
|
566
567
|
cursor2 = next;
|
|
567
568
|
}
|
|
568
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Opens a server-sent events answer (DEV-11921) with the headers and credential request() sends. Only the wait for
|
|
572
|
+
* the answer's headers is timed (120 s): the body stays open as long as the server keeps it open, until `signal`
|
|
573
|
+
* aborts. No retries here: the stream reader decides when to connect again. Throws KensoError on a non-2xx answer
|
|
574
|
+
* or a network failure; the caller reads `body` and closes it.
|
|
575
|
+
*/
|
|
576
|
+
async openStream(req, signal) {
|
|
577
|
+
if (!req.anonymous && !this.opts.apiKey) throw noApiKeyError();
|
|
578
|
+
const url = this.buildUrl(req.path, req.query);
|
|
579
|
+
const headers = this.buildHeaders({ ...req, headers: { Accept: "text/event-stream", ...req.headers } });
|
|
580
|
+
const connect = new AbortController();
|
|
581
|
+
const timer = setTimeout(() => connect.abort(new DOMException("No answer in time.", "TimeoutError")), REQUEST_TIMEOUT_MS);
|
|
582
|
+
const started = Date.now();
|
|
583
|
+
let res;
|
|
584
|
+
try {
|
|
585
|
+
res = await this.fetchImpl(url, { method: req.method, headers, signal: AbortSignal.any([signal, connect.signal]) });
|
|
586
|
+
} catch (err) {
|
|
587
|
+
if (signal.aborted) throw interruptedError();
|
|
588
|
+
if (!isNetworkFailure(err)) {
|
|
589
|
+
throw new KensoError({ code: "request_invalid", message: redact(`The request could not be sent: ${err instanceof Error ? err.message : String(err)}`), exitCode: ExitCode.Error });
|
|
590
|
+
}
|
|
591
|
+
const reason = describeNetworkError(err);
|
|
592
|
+
this.opts.onResponse?.({ method: req.method, url, ms: Date.now() - started, error: reason });
|
|
593
|
+
throw new KensoError({ code: "network_error", message: redact(`Could not reach ${new URL(url).origin}: ${reason}`), exitCode: ExitCode.Server });
|
|
594
|
+
} finally {
|
|
595
|
+
clearTimeout(timer);
|
|
596
|
+
}
|
|
597
|
+
const requestId = res.headers.get("x-request-id") ?? void 0;
|
|
598
|
+
this.opts.onResponse?.({ method: req.method, url, status: res.status, ms: Date.now() - started, requestId });
|
|
599
|
+
if (!res.ok) throw errorFromResponse(res.status, parseBody(await res.text(), res.headers.get("content-type")), requestId);
|
|
600
|
+
return res;
|
|
601
|
+
}
|
|
602
|
+
/** Waits `ms` (the test sleep when one is set); Ctrl-C ends the wait at once with an Interrupted error. */
|
|
603
|
+
pause(ms) {
|
|
604
|
+
return this.wait(ms, this.opts.signal);
|
|
605
|
+
}
|
|
569
606
|
/** Waits between retries; Ctrl-C (the signal) ends the wait at once with an Interrupted error. */
|
|
570
607
|
async wait(ms, signal) {
|
|
571
608
|
if (signal?.aborted) throw interruptedError();
|
|
@@ -2173,13 +2210,13 @@ function pickFields(value, paths) {
|
|
|
2173
2210
|
return out;
|
|
2174
2211
|
}
|
|
2175
2212
|
function cellText(value, max = TABLE_MAX_CELL) {
|
|
2176
|
-
let
|
|
2177
|
-
if (value === null || value === void 0)
|
|
2178
|
-
else if (typeof value === "string")
|
|
2179
|
-
else if (isScalar(value))
|
|
2180
|
-
else
|
|
2181
|
-
|
|
2182
|
-
return
|
|
2213
|
+
let text4;
|
|
2214
|
+
if (value === null || value === void 0) text4 = "";
|
|
2215
|
+
else if (typeof value === "string") text4 = value;
|
|
2216
|
+
else if (isScalar(value)) text4 = String(value);
|
|
2217
|
+
else text4 = JSON.stringify(value);
|
|
2218
|
+
text4 = text4.replace(/\s*\n\s*/g, " ");
|
|
2219
|
+
return text4.length > max ? `${text4.slice(0, max - 3)}...` : text4;
|
|
2183
2220
|
}
|
|
2184
2221
|
function alignRows(rows) {
|
|
2185
2222
|
const widths = [];
|
|
@@ -2275,8 +2312,8 @@ var init_output = __esm({
|
|
|
2275
2312
|
}
|
|
2276
2313
|
}
|
|
2277
2314
|
/** Text to stdout exactly as given: no JSON wrapping, no newline added, --output/--fields/--query not applied. */
|
|
2278
|
-
writeRaw(
|
|
2279
|
-
this.write(
|
|
2315
|
+
writeRaw(text4) {
|
|
2316
|
+
this.write(text4);
|
|
2280
2317
|
}
|
|
2281
2318
|
info(message) {
|
|
2282
2319
|
this.writeErr(`${redact(message)}
|
|
@@ -2406,11 +2443,11 @@ var init_output = __esm({
|
|
|
2406
2443
|
const width = Math.max(0, ...keys.map((k) => k.length));
|
|
2407
2444
|
return keys.map((key) => `${key.padEnd(width)} ${cellText(value[key], Number.POSITIVE_INFINITY)}`.trimEnd()).join("\n");
|
|
2408
2445
|
}
|
|
2409
|
-
write(
|
|
2410
|
-
this.stdout.write(
|
|
2446
|
+
write(text4) {
|
|
2447
|
+
this.stdout.write(text4);
|
|
2411
2448
|
}
|
|
2412
|
-
writeErr(
|
|
2413
|
-
this.stderr.write(
|
|
2449
|
+
writeErr(text4) {
|
|
2450
|
+
this.stderr.write(text4);
|
|
2414
2451
|
}
|
|
2415
2452
|
};
|
|
2416
2453
|
}
|
|
@@ -2421,7 +2458,7 @@ var VERSION;
|
|
|
2421
2458
|
var init_version = __esm({
|
|
2422
2459
|
"src/core/version.ts"() {
|
|
2423
2460
|
"use strict";
|
|
2424
|
-
VERSION = true ? "0.1.
|
|
2461
|
+
VERSION = true ? "0.1.73" : "0.0.0-dev";
|
|
2425
2462
|
}
|
|
2426
2463
|
});
|
|
2427
2464
|
|
|
@@ -2519,8 +2556,8 @@ async function loadWorkspaceFeatures(ctx, opts = {}) {
|
|
|
2519
2556
|
}
|
|
2520
2557
|
const hit = cache[key];
|
|
2521
2558
|
if (isFresh(hit, now)) return { features: hit.features.filter((f) => typeof f === "string") };
|
|
2522
|
-
const
|
|
2523
|
-
const timeout = AbortSignal.timeout(
|
|
2559
|
+
const timeoutMs2 = opts.timeoutMs ?? FETCH_TIMEOUT_MS;
|
|
2560
|
+
const timeout = AbortSignal.timeout(timeoutMs2);
|
|
2524
2561
|
let features;
|
|
2525
2562
|
try {
|
|
2526
2563
|
const signal = AbortSignal.any([ctx.signal, timeout]);
|
|
@@ -2529,7 +2566,7 @@ async function loadWorkspaceFeatures(ctx, opts = {}) {
|
|
|
2529
2566
|
if (me && !Array.isArray(me.features) && Array.isArray(me.data?.features)) me = me.data;
|
|
2530
2567
|
features = Array.isArray(me?.features) ? me.features.filter((f) => typeof f === "string") : [];
|
|
2531
2568
|
} catch (err) {
|
|
2532
|
-
return { features: [], error: timeout.aborted ? `timed out after ${
|
|
2569
|
+
return { features: [], error: timeout.aborted ? `timed out after ${timeoutMs2} ms` : reasonOf(err) };
|
|
2533
2570
|
}
|
|
2534
2571
|
if (file) {
|
|
2535
2572
|
try {
|
|
@@ -2587,8 +2624,8 @@ function readFromDisk() {
|
|
|
2587
2624
|
function loadManifest() {
|
|
2588
2625
|
if (override) return override;
|
|
2589
2626
|
if (!parsed) {
|
|
2590
|
-
const
|
|
2591
|
-
parsed =
|
|
2627
|
+
const text4 = readFromDisk();
|
|
2628
|
+
parsed = text4 ? JSON.parse(text4) : EMPTY;
|
|
2592
2629
|
}
|
|
2593
2630
|
return parsed;
|
|
2594
2631
|
}
|
|
@@ -2693,27 +2730,27 @@ async function readStream(stream, maxBytes = DEFAULT_MAX_BYTES) {
|
|
|
2693
2730
|
return Buffer.concat(chunks).toString("utf8");
|
|
2694
2731
|
}
|
|
2695
2732
|
async function readDataArg(value, stdin) {
|
|
2696
|
-
let
|
|
2733
|
+
let text4;
|
|
2697
2734
|
let source;
|
|
2698
2735
|
if (value === "-") {
|
|
2699
2736
|
source = "stdin";
|
|
2700
|
-
|
|
2737
|
+
text4 = await readStream(stdin ?? process.stdin);
|
|
2701
2738
|
} else if (value.startsWith("@")) {
|
|
2702
2739
|
const path = value.slice(1);
|
|
2703
2740
|
source = path;
|
|
2704
2741
|
if (path === "") throw usageError("Name a file after @, for example @body.json.");
|
|
2705
2742
|
try {
|
|
2706
|
-
|
|
2743
|
+
text4 = await readFile(path, "utf8");
|
|
2707
2744
|
} catch (err) {
|
|
2708
2745
|
throw fileUnreadable(path, err);
|
|
2709
2746
|
}
|
|
2710
2747
|
} else {
|
|
2711
2748
|
source = "the inline value";
|
|
2712
|
-
|
|
2749
|
+
text4 = value;
|
|
2713
2750
|
}
|
|
2714
|
-
if (
|
|
2751
|
+
if (text4.trim() === "") throw usageError(`No JSON in ${source}: it is empty.`);
|
|
2715
2752
|
try {
|
|
2716
|
-
return JSON.parse(
|
|
2753
|
+
return JSON.parse(text4);
|
|
2717
2754
|
} catch (err) {
|
|
2718
2755
|
throw usageError(`Invalid JSON in ${source}: ${err instanceof Error ? err.message : String(err)}`, {
|
|
2719
2756
|
hint: `Pass JSON inline ('{"name":"x"}'), from a file (@body.json) or from stdin (-).`
|
|
@@ -2735,8 +2772,8 @@ import { readFile as readFile2 } from "node:fs/promises";
|
|
|
2735
2772
|
function isSecretFlag(name, type) {
|
|
2736
2773
|
return type === "string" && SECRET_NAME.test(name);
|
|
2737
2774
|
}
|
|
2738
|
-
function readValue(flag, source,
|
|
2739
|
-
const value =
|
|
2775
|
+
function readValue(flag, source, text4) {
|
|
2776
|
+
const value = text4.replace(/\r?\n$/, "");
|
|
2740
2777
|
if (value === "") throw usageError(`--${flag} read nothing from ${source}.`, { field: flag, hint: `Put the value in ${source}, or pass env:NAME.` });
|
|
2741
2778
|
return value;
|
|
2742
2779
|
}
|
|
@@ -2758,13 +2795,13 @@ async function readSecretFlag(ctx, flag, raw) {
|
|
|
2758
2795
|
}
|
|
2759
2796
|
if (raw.startsWith("@") && !raw.startsWith("@@") && raw.length > 1) {
|
|
2760
2797
|
const path = raw.slice(1);
|
|
2761
|
-
let
|
|
2798
|
+
let text4;
|
|
2762
2799
|
try {
|
|
2763
|
-
|
|
2800
|
+
text4 = await readFile2(path, "utf8");
|
|
2764
2801
|
} catch (err) {
|
|
2765
2802
|
throw fileUnreadable(path, err, flag, `--${flag} @path reads a file. A value that itself starts with @ is written @@, for example @@Spring2026.`);
|
|
2766
2803
|
}
|
|
2767
|
-
return readValue(flag, path,
|
|
2804
|
+
return readValue(flag, path, text4);
|
|
2768
2805
|
}
|
|
2769
2806
|
if (raw.startsWith("env:") && raw.length > 4) {
|
|
2770
2807
|
const name = raw.slice(4);
|
|
@@ -2780,9 +2817,9 @@ async function readSecretFlag(ctx, flag, raw) {
|
|
|
2780
2817
|
ctx.output.warn(`--${flag} typed on the command line lands in shell history. Next time pass - (stdin), @file or env:NAME.`);
|
|
2781
2818
|
return raw.startsWith("@@") ? raw.slice(1) : raw;
|
|
2782
2819
|
}
|
|
2783
|
-
function maskSecrets(
|
|
2784
|
-
if (secrets.size === 0 ||
|
|
2785
|
-
const out = { ...
|
|
2820
|
+
function maskSecrets(body2, secrets) {
|
|
2821
|
+
if (secrets.size === 0 || body2 === null || typeof body2 !== "object" || Array.isArray(body2)) return body2;
|
|
2822
|
+
const out = { ...body2 };
|
|
2786
2823
|
for (const key of secrets) if (typeof out[key] === "string") out[key] = "***";
|
|
2787
2824
|
return out;
|
|
2788
2825
|
}
|
|
@@ -2798,6 +2835,262 @@ var init_secret_flags = __esm({
|
|
|
2798
2835
|
}
|
|
2799
2836
|
});
|
|
2800
2837
|
|
|
2838
|
+
// src/core/sse.ts
|
|
2839
|
+
var SseParser;
|
|
2840
|
+
var init_sse = __esm({
|
|
2841
|
+
"src/core/sse.ts"() {
|
|
2842
|
+
"use strict";
|
|
2843
|
+
SseParser = class {
|
|
2844
|
+
/**
|
|
2845
|
+
* The id a reconnect sends as Last-Event-ID. It moves when an event ends (its blank line), not at its `id:` line, so
|
|
2846
|
+
* a frame the connection cut off before its end is asked for again.
|
|
2847
|
+
*/
|
|
2848
|
+
lastEventId;
|
|
2849
|
+
/** The `retry:` the server asked for, in ms. */
|
|
2850
|
+
retryMs;
|
|
2851
|
+
/** Comment lines read: the server's keepalives. */
|
|
2852
|
+
comments = 0;
|
|
2853
|
+
buffer = "";
|
|
2854
|
+
started = false;
|
|
2855
|
+
data = [];
|
|
2856
|
+
type = "";
|
|
2857
|
+
/** The last `id:` read, kept across events; it becomes lastEventId when its event ends. */
|
|
2858
|
+
idBuffer;
|
|
2859
|
+
blockHasId = false;
|
|
2860
|
+
constructor(lastEventId = "") {
|
|
2861
|
+
this.lastEventId = lastEventId;
|
|
2862
|
+
this.idBuffer = lastEventId;
|
|
2863
|
+
}
|
|
2864
|
+
/** Feeds decoded text and returns the events it completed. A CR at the end waits for the next chunk (it may be CRLF). */
|
|
2865
|
+
push(text4) {
|
|
2866
|
+
this.buffer += text4;
|
|
2867
|
+
if (!this.started && this.buffer.length > 0) {
|
|
2868
|
+
this.started = true;
|
|
2869
|
+
if (this.buffer.startsWith("\uFEFF")) this.buffer = this.buffer.slice(1);
|
|
2870
|
+
}
|
|
2871
|
+
const events = [];
|
|
2872
|
+
for (; ; ) {
|
|
2873
|
+
const end = this.buffer.search(/[\r\n]/);
|
|
2874
|
+
if (end < 0) break;
|
|
2875
|
+
const cr2 = this.buffer[end] === "\r";
|
|
2876
|
+
if (cr2 && end === this.buffer.length - 1) break;
|
|
2877
|
+
const line = this.buffer.slice(0, end);
|
|
2878
|
+
this.buffer = this.buffer.slice(end + (cr2 && this.buffer[end + 1] === "\n" ? 2 : 1));
|
|
2879
|
+
const event = this.line(line);
|
|
2880
|
+
if (event) events.push(event);
|
|
2881
|
+
}
|
|
2882
|
+
return events;
|
|
2883
|
+
}
|
|
2884
|
+
/** The end of the stream: a CR left waiting ends its line. An event the server never closed with a blank line is dropped, as the spec says. */
|
|
2885
|
+
end() {
|
|
2886
|
+
if (this.buffer.endsWith("\r")) this.push("\n");
|
|
2887
|
+
this.buffer = "";
|
|
2888
|
+
this.idBuffer = this.lastEventId;
|
|
2889
|
+
this.reset();
|
|
2890
|
+
}
|
|
2891
|
+
line(line) {
|
|
2892
|
+
if (line === "") return this.dispatch();
|
|
2893
|
+
if (line.startsWith(":")) {
|
|
2894
|
+
this.comments++;
|
|
2895
|
+
return void 0;
|
|
2896
|
+
}
|
|
2897
|
+
const colon = line.indexOf(":");
|
|
2898
|
+
const field = colon < 0 ? line : line.slice(0, colon);
|
|
2899
|
+
let value = colon < 0 ? "" : line.slice(colon + 1);
|
|
2900
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
2901
|
+
if (field === "event") this.type = value;
|
|
2902
|
+
else if (field === "data") this.data.push(value);
|
|
2903
|
+
else if (field === "id" && !value.includes("\0")) {
|
|
2904
|
+
this.idBuffer = value;
|
|
2905
|
+
this.blockHasId = true;
|
|
2906
|
+
} else if (field === "retry" && /^\d+$/.test(value)) this.retryMs = Number(value);
|
|
2907
|
+
return void 0;
|
|
2908
|
+
}
|
|
2909
|
+
dispatch() {
|
|
2910
|
+
this.lastEventId = this.idBuffer;
|
|
2911
|
+
const event = this.data.length === 0 ? void 0 : { event: this.type || "message", data: this.data.join("\n"), ...this.blockHasId ? { id: this.idBuffer } : {} };
|
|
2912
|
+
this.reset();
|
|
2913
|
+
return event;
|
|
2914
|
+
}
|
|
2915
|
+
reset() {
|
|
2916
|
+
this.data = [];
|
|
2917
|
+
this.type = "";
|
|
2918
|
+
this.blockHasId = false;
|
|
2919
|
+
}
|
|
2920
|
+
};
|
|
2921
|
+
}
|
|
2922
|
+
});
|
|
2923
|
+
|
|
2924
|
+
// src/generated/stream.ts
|
|
2925
|
+
function streamOptions(flags) {
|
|
2926
|
+
const opts = {};
|
|
2927
|
+
if (typeof flags.until === "string") {
|
|
2928
|
+
const names = flags.until.split(",").map((name) => name.trim()).filter((name) => name !== "");
|
|
2929
|
+
if (names.length === 0) throw usageError("--until needs an event name, such as --until done.", { field: "until" });
|
|
2930
|
+
opts.until = new Set(names);
|
|
2931
|
+
}
|
|
2932
|
+
if (typeof flags["max-events"] === "string") {
|
|
2933
|
+
const raw = flags["max-events"].trim();
|
|
2934
|
+
const value = Number(raw);
|
|
2935
|
+
if (!/^\d+$/.test(raw) || !Number.isSafeInteger(value) || value < 1) {
|
|
2936
|
+
throw usageError(`--max-events must be a whole number of 1 or more (got "${flags["max-events"]}").`, { field: "max-events" });
|
|
2937
|
+
}
|
|
2938
|
+
opts.maxEvents = value;
|
|
2939
|
+
}
|
|
2940
|
+
if (flags.once === true) opts.once = true;
|
|
2941
|
+
return opts;
|
|
2942
|
+
}
|
|
2943
|
+
function eventLine(event) {
|
|
2944
|
+
let data;
|
|
2945
|
+
try {
|
|
2946
|
+
data = JSON.parse(event.data);
|
|
2947
|
+
} catch {
|
|
2948
|
+
data = event.data;
|
|
2949
|
+
}
|
|
2950
|
+
return `${JSON.stringify({ event: event.event, ...event.id !== void 0 ? { id: event.id } : {}, data })}
|
|
2951
|
+
`;
|
|
2952
|
+
}
|
|
2953
|
+
function backoffMs(failures) {
|
|
2954
|
+
return Math.min(MAX_BACKOFF_MS, 1e3 * 2 ** Math.max(0, failures - 1));
|
|
2955
|
+
}
|
|
2956
|
+
function retryable(err) {
|
|
2957
|
+
if (!(err instanceof KensoError)) return false;
|
|
2958
|
+
if (err.code === "network_error") return true;
|
|
2959
|
+
const status = err.httpStatus;
|
|
2960
|
+
return status === 408 || status === 429 || status !== void 0 && status >= 500;
|
|
2961
|
+
}
|
|
2962
|
+
function isEventStream(res) {
|
|
2963
|
+
return (res.headers.get("content-type") ?? "").toLowerCase().includes("text/event-stream");
|
|
2964
|
+
}
|
|
2965
|
+
async function readConnection(ctx, res, parser, opts, printed) {
|
|
2966
|
+
const result = { progressed: false, finished: false };
|
|
2967
|
+
if (!res.body) return { ...result, dropped: "the answer had no body" };
|
|
2968
|
+
const reader = res.body.getReader();
|
|
2969
|
+
const decoder = new TextDecoder();
|
|
2970
|
+
let stopped;
|
|
2971
|
+
const stop = (why) => {
|
|
2972
|
+
stopped ??= why;
|
|
2973
|
+
reader.cancel().catch(() => void 0);
|
|
2974
|
+
};
|
|
2975
|
+
let idle = setTimeout(() => stop("idle"), STREAM_IDLE_MS);
|
|
2976
|
+
const onAbort = () => stop("interrupted");
|
|
2977
|
+
ctx.signal.addEventListener("abort", onAbort, { once: true });
|
|
2978
|
+
try {
|
|
2979
|
+
for (; ; ) {
|
|
2980
|
+
const { done: done2, value } = await reader.read();
|
|
2981
|
+
if (done2 || stopped) break;
|
|
2982
|
+
clearTimeout(idle);
|
|
2983
|
+
idle = setTimeout(() => stop("idle"), STREAM_IDLE_MS);
|
|
2984
|
+
for (const event of parser.push(decoder.decode(value, { stream: true }))) {
|
|
2985
|
+
ctx.output.writeRaw(eventLine(event));
|
|
2986
|
+
if (!SESSION_EVENTS.has(event.event)) result.progressed = true;
|
|
2987
|
+
printed.count++;
|
|
2988
|
+
if (event.event === "bye") result.bye = byeReason(event.data);
|
|
2989
|
+
if (opts.until?.has(event.event) || opts.maxEvents !== void 0 && printed.count >= opts.maxEvents) {
|
|
2990
|
+
stop("done");
|
|
2991
|
+
break;
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
if (stopped) break;
|
|
2995
|
+
}
|
|
2996
|
+
} catch (err) {
|
|
2997
|
+
if (!stopped) result.dropped = err instanceof Error ? err.message : String(err);
|
|
2998
|
+
} finally {
|
|
2999
|
+
clearTimeout(idle);
|
|
3000
|
+
ctx.signal.removeEventListener("abort", onAbort);
|
|
3001
|
+
parser.end();
|
|
3002
|
+
}
|
|
3003
|
+
if (stopped === "done" || stopped === "interrupted" || ctx.signal.aborted) result.finished = true;
|
|
3004
|
+
else if (stopped === "idle") result.dropped = `no data for ${STREAM_IDLE_MS / 1e3} s`;
|
|
3005
|
+
return result;
|
|
3006
|
+
}
|
|
3007
|
+
function byeReason(data) {
|
|
3008
|
+
try {
|
|
3009
|
+
const reason = JSON.parse(data).reason;
|
|
3010
|
+
return typeof reason === "string" && reason !== "" ? reason : "bye";
|
|
3011
|
+
} catch {
|
|
3012
|
+
return "bye";
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
async function followEventStream(ctx, req, opts) {
|
|
3016
|
+
let lastEventId = "";
|
|
3017
|
+
let retryMs;
|
|
3018
|
+
let failures = 0;
|
|
3019
|
+
const printed = { count: 0 };
|
|
3020
|
+
for (; ; ) {
|
|
3021
|
+
if (ctx.signal.aborted) return ExitCode.Ok;
|
|
3022
|
+
const headers = { ...req.headers };
|
|
3023
|
+
if (lastEventId !== "") headers["Last-Event-ID"] = lastEventId;
|
|
3024
|
+
const connection = new AbortController();
|
|
3025
|
+
let res;
|
|
3026
|
+
try {
|
|
3027
|
+
res = await ctx.client.openStream({ ...req, headers }, AbortSignal.any([ctx.signal, connection.signal]));
|
|
3028
|
+
} catch (err) {
|
|
3029
|
+
if (ctx.signal.aborted) return ExitCode.Ok;
|
|
3030
|
+
failures++;
|
|
3031
|
+
if (opts.once || !retryable(err) || failures >= MAX_FAILED_CONNECTS) throw err;
|
|
3032
|
+
const waitMs2 = Math.max(backoffMs(failures), retryMs ?? 0);
|
|
3033
|
+
ctx.output.info(`Could not open the stream (${err.message}); trying again in ${Math.round(waitMs2 / 1e3)} s.`);
|
|
3034
|
+
if (!await pause(ctx, waitMs2)) return ExitCode.Ok;
|
|
3035
|
+
continue;
|
|
3036
|
+
}
|
|
3037
|
+
if (!isEventStream(res)) {
|
|
3038
|
+
const body2 = parseBody(await res.text(), res.headers.get("content-type"));
|
|
3039
|
+
if (body2 !== null && body2 !== "") ctx.output.object(body2);
|
|
3040
|
+
return ExitCode.Ok;
|
|
3041
|
+
}
|
|
3042
|
+
const parser = new SseParser(lastEventId);
|
|
3043
|
+
const ended = await readConnection(ctx, res, parser, opts, printed);
|
|
3044
|
+
connection.abort();
|
|
3045
|
+
lastEventId = parser.lastEventId;
|
|
3046
|
+
retryMs = parser.retryMs ?? retryMs;
|
|
3047
|
+
if (ended.finished) return ExitCode.Ok;
|
|
3048
|
+
if (opts.once) return ExitCode.Ok;
|
|
3049
|
+
const progressed = ended.progressed || parser.comments > 0;
|
|
3050
|
+
failures = progressed ? 0 : failures + 1;
|
|
3051
|
+
if (failures >= MAX_FAILED_CONNECTS) {
|
|
3052
|
+
throw new KensoError({
|
|
3053
|
+
code: "stream_closed",
|
|
3054
|
+
message: `The stream closed ${failures} times in a row before any event or keepalive${ended.dropped ? ` (${ended.dropped})` : ended.bye !== void 0 ? ` (the server said bye: ${ended.bye})` : ""}.`,
|
|
3055
|
+
exitCode: ExitCode.Server,
|
|
3056
|
+
hint: "Try again later; --verbose shows each connect."
|
|
3057
|
+
});
|
|
3058
|
+
}
|
|
3059
|
+
const why = ended.bye !== void 0 ? `the server said bye: ${ended.bye}` : ended.dropped ?? "the server closed it";
|
|
3060
|
+
const waitMs = !progressed ? Math.max(backoffMs(failures), retryMs ?? 0) : ended.bye !== void 0 ? retryMs ?? 0 : Math.max(1e3, retryMs ?? 0);
|
|
3061
|
+
ctx.output.info(`Stream ended (${why}); reconnecting${lastEventId !== "" ? ` after event ${lastEventId}` : ""}${waitMs >= 1e3 ? ` in ${Math.round(waitMs / 1e3)} s` : ""}.`);
|
|
3062
|
+
if (waitMs > 0 && !await pause(ctx, waitMs)) return ExitCode.Ok;
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
async function pause(ctx, ms) {
|
|
3066
|
+
try {
|
|
3067
|
+
await ctx.client.pause(ms);
|
|
3068
|
+
return true;
|
|
3069
|
+
} catch (err) {
|
|
3070
|
+
if (ctx.signal.aborted) return false;
|
|
3071
|
+
throw err;
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
var STREAM_IDLE_MS, MAX_FAILED_CONNECTS, SESSION_EVENTS, MAX_BACKOFF_MS, STREAM_FLAG_SPECS;
|
|
3075
|
+
var init_stream = __esm({
|
|
3076
|
+
"src/generated/stream.ts"() {
|
|
3077
|
+
"use strict";
|
|
3078
|
+
init_errors();
|
|
3079
|
+
init_exit_codes();
|
|
3080
|
+
init_http();
|
|
3081
|
+
init_sse();
|
|
3082
|
+
STREAM_IDLE_MS = 6e4;
|
|
3083
|
+
MAX_FAILED_CONNECTS = 8;
|
|
3084
|
+
SESSION_EVENTS = /* @__PURE__ */ new Set(["hello", "bye"]);
|
|
3085
|
+
MAX_BACKOFF_MS = 3e4;
|
|
3086
|
+
STREAM_FLAG_SPECS = [
|
|
3087
|
+
{ flag: "until", type: "string", description: "End after the first event with this name (comma-separated names: done,error)." },
|
|
3088
|
+
{ flag: "max-events", type: "integer", description: "End after this many events." },
|
|
3089
|
+
{ flag: "once", type: "boolean", description: "End when the server closes the stream instead of reconnecting." }
|
|
3090
|
+
];
|
|
3091
|
+
}
|
|
3092
|
+
});
|
|
3093
|
+
|
|
2801
3094
|
// node_modules/.pnpm/csv-stringify@6.9.0/node_modules/csv-stringify/lib/utils/get.js
|
|
2802
3095
|
var charCodeOfDot, reEscapeChar, rePropName, reIsDeepProp, reIsPlainProp, getTag, isSymbol, isKey, stringToPath, castPath, toKey, get;
|
|
2803
3096
|
var init_get = __esm({
|
|
@@ -3551,13 +3844,13 @@ function byRow(results) {
|
|
|
3551
3844
|
}
|
|
3552
3845
|
async function readResults(path) {
|
|
3553
3846
|
const results = /* @__PURE__ */ new Map();
|
|
3554
|
-
let
|
|
3847
|
+
let text4;
|
|
3555
3848
|
try {
|
|
3556
|
-
|
|
3849
|
+
text4 = await readFile3(path, "utf8");
|
|
3557
3850
|
} catch {
|
|
3558
3851
|
return results;
|
|
3559
3852
|
}
|
|
3560
|
-
for (const line of
|
|
3853
|
+
for (const line of text4.split("\n")) {
|
|
3561
3854
|
if (line.trim() === "") continue;
|
|
3562
3855
|
try {
|
|
3563
3856
|
const value = JSON.parse(line);
|
|
@@ -4169,7 +4462,7 @@ async function runBatch(spec, ctx) {
|
|
|
4169
4462
|
else if (stop) status = stop.status;
|
|
4170
4463
|
else if (chunksDone.size === chunkCount) status = "done";
|
|
4171
4464
|
else status = "interrupted";
|
|
4172
|
-
const
|
|
4465
|
+
const interrupted7 = fatal === void 0 && stop === void 0 && status === "interrupted";
|
|
4173
4466
|
const ordered = byRow(results.values());
|
|
4174
4467
|
try {
|
|
4175
4468
|
await writeFileAtomic(files.resultsNdjson, ndjson(ordered));
|
|
@@ -4201,7 +4494,7 @@ async function runBatch(spec, ctx) {
|
|
|
4201
4494
|
if (stop) {
|
|
4202
4495
|
summary.stopped = { code: stop.code, message: stop.message, ...stop.hint ? { hint: stop.hint } : {} };
|
|
4203
4496
|
summary.next = `kenso runs resume ${record.runId}`;
|
|
4204
|
-
} else if (
|
|
4497
|
+
} else if (interrupted7) {
|
|
4205
4498
|
summary.interrupted = true;
|
|
4206
4499
|
summary.next = `kenso runs resume ${record.runId}`;
|
|
4207
4500
|
}
|
|
@@ -4209,7 +4502,7 @@ async function runBatch(spec, ctx) {
|
|
|
4209
4502
|
ctx.output.summary(summary);
|
|
4210
4503
|
let exitCode;
|
|
4211
4504
|
if (stop) exitCode = stop.exitCode;
|
|
4212
|
-
else if (
|
|
4505
|
+
else if (interrupted7) exitCode = ExitCode.Interrupted;
|
|
4213
4506
|
else if (ordered.some((r) => PROBLEM_STATUSES.has(r.status))) exitCode = ExitCode.Partial;
|
|
4214
4507
|
else exitCode = ExitCode.Ok;
|
|
4215
4508
|
return {
|
|
@@ -6046,23 +6339,23 @@ async function readRaw(pathOrDash, stdin) {
|
|
|
6046
6339
|
throw fileUnreadable(pathOrDash, err);
|
|
6047
6340
|
}
|
|
6048
6341
|
}
|
|
6049
|
-
function stripBom(
|
|
6050
|
-
return
|
|
6342
|
+
function stripBom(text4) {
|
|
6343
|
+
return text4.charCodeAt(0) === 65279 ? text4.slice(1) : text4;
|
|
6051
6344
|
}
|
|
6052
|
-
function detectFormat(path,
|
|
6345
|
+
function detectFormat(path, text4) {
|
|
6053
6346
|
const ext = path === "-" ? "" : extname(path).toLowerCase();
|
|
6054
6347
|
if (ext === ".csv") return "csv";
|
|
6055
6348
|
if (ext === ".jsonl" || ext === ".ndjson") return "jsonl";
|
|
6056
|
-
return stripBom(
|
|
6349
|
+
return stripBom(text4).trimStart().startsWith("{") ? "jsonl" : "csv";
|
|
6057
6350
|
}
|
|
6058
6351
|
function badFile(message, hint) {
|
|
6059
6352
|
return new KensoError({ code: "file_unreadable", message, exitCode: ExitCode.Usage, field: "file", hint });
|
|
6060
6353
|
}
|
|
6061
|
-
function parseCsv(
|
|
6354
|
+
function parseCsv(text4, source) {
|
|
6062
6355
|
let headers = [];
|
|
6063
6356
|
let records;
|
|
6064
6357
|
try {
|
|
6065
|
-
records = parse(
|
|
6358
|
+
records = parse(text4, {
|
|
6066
6359
|
columns: (header) => {
|
|
6067
6360
|
headers = header.map((h) => String(h));
|
|
6068
6361
|
return headers;
|
|
@@ -6085,11 +6378,11 @@ function parseCsv(text3, source) {
|
|
|
6085
6378
|
});
|
|
6086
6379
|
return { headers, rows };
|
|
6087
6380
|
}
|
|
6088
|
-
function parseJsonl(
|
|
6381
|
+
function parseJsonl(text4, source) {
|
|
6089
6382
|
const headers = [];
|
|
6090
6383
|
const seen = /* @__PURE__ */ new Set();
|
|
6091
6384
|
const rows = [];
|
|
6092
|
-
const lines = stripBom(
|
|
6385
|
+
const lines = stripBom(text4).split("\n");
|
|
6093
6386
|
lines.forEach((raw, i) => {
|
|
6094
6387
|
const line = raw.trim();
|
|
6095
6388
|
if (line === "") return;
|
|
@@ -6115,10 +6408,10 @@ function parseJsonl(text3, source) {
|
|
|
6115
6408
|
async function readInput(pathOrDash, opts) {
|
|
6116
6409
|
const { path, bytes } = await readRaw(pathOrDash, opts?.stdin);
|
|
6117
6410
|
const sha2563 = createHash2("sha256").update(bytes).digest("hex");
|
|
6118
|
-
const
|
|
6411
|
+
const text4 = bytes.toString("utf8");
|
|
6119
6412
|
const source = path === "-" ? "stdin" : pathOrDash;
|
|
6120
|
-
const format = detectFormat(path,
|
|
6121
|
-
const parsed2 = format === "csv" ? parseCsv(
|
|
6413
|
+
const format = detectFormat(path, text4);
|
|
6414
|
+
const parsed2 = format === "csv" ? parseCsv(text4, source) : parseJsonl(text4, source);
|
|
6122
6415
|
return { path, format, sha256: sha2563, ...parsed2 };
|
|
6123
6416
|
}
|
|
6124
6417
|
function idText(value) {
|
|
@@ -6126,8 +6419,8 @@ function idText(value) {
|
|
|
6126
6419
|
if (typeof value === "string" && value.trim() !== "") return value.trim();
|
|
6127
6420
|
return void 0;
|
|
6128
6421
|
}
|
|
6129
|
-
function looksLikeCsvHeader(
|
|
6130
|
-
const first = stripBom(
|
|
6422
|
+
function looksLikeCsvHeader(text4, column) {
|
|
6423
|
+
const first = stripBom(text4).split("\n").map((l) => l.trim()).find((l) => l !== "");
|
|
6131
6424
|
if (first === void 0) return false;
|
|
6132
6425
|
if (first.includes(",")) return true;
|
|
6133
6426
|
const name = first.replace(/^"(.*)"$/, "$1");
|
|
@@ -6135,18 +6428,18 @@ function looksLikeCsvHeader(text3, column) {
|
|
|
6135
6428
|
}
|
|
6136
6429
|
async function readIds(pathOrDash, opts) {
|
|
6137
6430
|
const { path, bytes } = await readRaw(pathOrDash, opts?.stdin);
|
|
6138
|
-
const
|
|
6431
|
+
const text4 = bytes.toString("utf8");
|
|
6139
6432
|
const source = path === "-" ? "stdin" : pathOrDash;
|
|
6140
6433
|
const column = opts?.column?.trim() || void 0;
|
|
6141
6434
|
const ext = path === "-" ? "" : extname(path).toLowerCase();
|
|
6142
6435
|
let format;
|
|
6143
|
-
if (ext === ".csv" || ext === ".jsonl" || ext === ".ndjson") format = detectFormat(path,
|
|
6144
|
-
else if (stripBom(
|
|
6145
|
-
else format = column !== void 0 || looksLikeCsvHeader(
|
|
6436
|
+
if (ext === ".csv" || ext === ".jsonl" || ext === ".ndjson") format = detectFormat(path, text4);
|
|
6437
|
+
else if (stripBom(text4).trimStart().startsWith("{")) format = "jsonl";
|
|
6438
|
+
else format = column !== void 0 || looksLikeCsvHeader(text4, column) ? "csv" : "text";
|
|
6146
6439
|
if (format === "text") {
|
|
6147
|
-
return stripBom(
|
|
6440
|
+
return stripBom(text4).split("\n").map((line) => line.trim()).filter((line) => line !== "");
|
|
6148
6441
|
}
|
|
6149
|
-
const { headers, rows } = format === "csv" ? parseCsv(
|
|
6442
|
+
const { headers, rows } = format === "csv" ? parseCsv(text4, source) : parseJsonl(text4, source);
|
|
6150
6443
|
const key = column ?? (headers.includes("id") ? "id" : headers.includes("contactId") ? "contactId" : void 0);
|
|
6151
6444
|
if (key === void 0 || !headers.includes(key)) {
|
|
6152
6445
|
throw usageError(
|
|
@@ -6202,32 +6495,32 @@ function paramIndex(op) {
|
|
|
6202
6495
|
for (const param of all) if (!index.has(param.flag)) index.set(param.flag, param);
|
|
6203
6496
|
return index;
|
|
6204
6497
|
}
|
|
6205
|
-
function convert(
|
|
6206
|
-
if (!param) return
|
|
6498
|
+
function convert(text4, param, key) {
|
|
6499
|
+
if (!param) return text4;
|
|
6207
6500
|
switch (param.type) {
|
|
6208
6501
|
case "integer":
|
|
6209
6502
|
case "number": {
|
|
6210
|
-
const value = Number(
|
|
6503
|
+
const value = Number(text4);
|
|
6211
6504
|
if (!Number.isFinite(value) || param.type === "integer" && !Number.isSafeInteger(value)) {
|
|
6212
|
-
throw usageError(`${key} must be a ${param.type === "integer" ? "whole number" : "number"} (got "${
|
|
6505
|
+
throw usageError(`${key} must be a ${param.type === "integer" ? "whole number" : "number"} (got "${text4}").`, { field: key });
|
|
6213
6506
|
}
|
|
6214
6507
|
return value;
|
|
6215
6508
|
}
|
|
6216
6509
|
case "boolean": {
|
|
6217
|
-
const lower =
|
|
6510
|
+
const lower = text4.toLowerCase();
|
|
6218
6511
|
if (lower === "true" || lower === "false") return lower === "true";
|
|
6219
|
-
throw usageError(`${key} must be true or false (got "${
|
|
6512
|
+
throw usageError(`${key} must be true or false (got "${text4}").`, { field: key });
|
|
6220
6513
|
}
|
|
6221
6514
|
case "array":
|
|
6222
|
-
return
|
|
6515
|
+
return text4.split(",").map((item) => item.trim()).filter((item) => item !== "");
|
|
6223
6516
|
case "object":
|
|
6224
6517
|
try {
|
|
6225
|
-
return JSON.parse(
|
|
6518
|
+
return JSON.parse(text4);
|
|
6226
6519
|
} catch {
|
|
6227
|
-
throw usageError(`${key} must be JSON (got "${
|
|
6520
|
+
throw usageError(`${key} must be JSON (got "${text4}").`, { field: key });
|
|
6228
6521
|
}
|
|
6229
6522
|
default:
|
|
6230
|
-
return
|
|
6523
|
+
return text4;
|
|
6231
6524
|
}
|
|
6232
6525
|
}
|
|
6233
6526
|
function rowToValues(row, index) {
|
|
@@ -6237,9 +6530,9 @@ function rowToValues(row, index) {
|
|
|
6237
6530
|
const param = index.get(key);
|
|
6238
6531
|
const name = param?.name ?? key;
|
|
6239
6532
|
if (typeof raw === "string") {
|
|
6240
|
-
const
|
|
6241
|
-
if (
|
|
6242
|
-
values[name] =
|
|
6533
|
+
const text4 = raw.trim();
|
|
6534
|
+
if (text4 === "") continue;
|
|
6535
|
+
values[name] = text4 === "null" ? null : convert(text4, param, key);
|
|
6243
6536
|
} else {
|
|
6244
6537
|
values[name] = raw;
|
|
6245
6538
|
}
|
|
@@ -6280,8 +6573,8 @@ function rateLimitRemaining(headers) {
|
|
|
6280
6573
|
const value = Number(headers.get("ratelimit-remaining") ?? "");
|
|
6281
6574
|
return headers.has("ratelimit-remaining") && Number.isFinite(value) ? value : void 0;
|
|
6282
6575
|
}
|
|
6283
|
-
function answerId(
|
|
6284
|
-
const record = isRecord2(
|
|
6576
|
+
function answerId(body2) {
|
|
6577
|
+
const record = isRecord2(body2) ? isRecord2(body2.data) ? body2.data : body2 : void 0;
|
|
6285
6578
|
const id = record?.id;
|
|
6286
6579
|
return typeof id === "number" || typeof id === "string" && id !== "" ? String(id) : void 0;
|
|
6287
6580
|
}
|
|
@@ -6452,6 +6745,10 @@ function operationFlags(op) {
|
|
|
6452
6745
|
description: "Request body as JSON: inline, @file or - for stdin. Flags win over its keys."
|
|
6453
6746
|
});
|
|
6454
6747
|
}
|
|
6748
|
+
if (op.stream === "sse") {
|
|
6749
|
+
for (const f of STREAM_FLAG_SPECS) flags.push({ flag: f.flag, type: f.type, required: false, description: f.description });
|
|
6750
|
+
return flags;
|
|
6751
|
+
}
|
|
6455
6752
|
if (op.list) {
|
|
6456
6753
|
if (!taken.has("limit")) flags.push({ flag: "limit", type: "integer", required: false, description: "Page size." });
|
|
6457
6754
|
if (!taken.has("cursor")) flags.push({ flag: "cursor", type: "string", required: false, description: "Start at this cursor (from a previous page)." });
|
|
@@ -6483,19 +6780,20 @@ function operationExamples(op) {
|
|
|
6483
6780
|
const examples = op.method === "GET" ? [first] : [`${first} --dry-run`, isDestructive(op) ? `${first} --yes` : first];
|
|
6484
6781
|
if (op.body && op.body.format !== "multipart") examples.push(`${base} --data @body.json`);
|
|
6485
6782
|
if (op.list) examples.push(`${base} --all`);
|
|
6783
|
+
if (op.stream === "sse") examples.push(`${base} --until <event>`, `${base} --max-events 1`);
|
|
6486
6784
|
return examples;
|
|
6487
6785
|
}
|
|
6488
6786
|
function missing(op, flag) {
|
|
6489
6787
|
return usageError(`--${flag} is required for ${commandOf(op)}.`, { field: flag, hint: `Usage: ${usageLine(op)}`, next: `${commandOf(op)} --help` });
|
|
6490
6788
|
}
|
|
6491
6789
|
function parseNumber(raw, flag, integer) {
|
|
6492
|
-
const
|
|
6493
|
-
const value = Number(
|
|
6790
|
+
const text4 = raw.trim();
|
|
6791
|
+
const value = Number(text4);
|
|
6494
6792
|
if (integer) {
|
|
6495
|
-
if (!/^-?\d+$/.test(
|
|
6793
|
+
if (!/^-?\d+$/.test(text4) || !Number.isSafeInteger(value)) {
|
|
6496
6794
|
throw usageError(`--${flag} must be a whole number (got "${raw}").`, { field: flag });
|
|
6497
6795
|
}
|
|
6498
|
-
} else if (
|
|
6796
|
+
} else if (text4 === "" || !Number.isFinite(value)) {
|
|
6499
6797
|
throw usageError(`--${flag} must be a number (got "${raw}").`, { field: flag });
|
|
6500
6798
|
}
|
|
6501
6799
|
return value;
|
|
@@ -6549,16 +6847,16 @@ function buildRequest(op, values) {
|
|
|
6549
6847
|
if (Object.keys(query).length > 0) request.query = query;
|
|
6550
6848
|
if (!op.body) return request;
|
|
6551
6849
|
const data = values[DATA_KEY];
|
|
6552
|
-
const
|
|
6850
|
+
const body2 = isRecord3(data) ? { ...data } : {};
|
|
6553
6851
|
for (const [key, value] of Object.entries(values)) {
|
|
6554
6852
|
if (key === DATA_KEY || key === IDEMPOTENCY_KEY || routeNames.has(key) || queryNames.has(key) || value === void 0) continue;
|
|
6555
|
-
|
|
6853
|
+
body2[key] = value;
|
|
6556
6854
|
}
|
|
6557
6855
|
if (op.body.format === "multipart") {
|
|
6558
6856
|
const file = fileProp(op);
|
|
6559
|
-
if (file?.required && isBlank(
|
|
6857
|
+
if (file?.required && isBlank(body2[file.name])) throw missing(op, "file");
|
|
6560
6858
|
const form = new FormData();
|
|
6561
|
-
for (const [key, value] of Object.entries(
|
|
6859
|
+
for (const [key, value] of Object.entries(body2)) {
|
|
6562
6860
|
if (value === void 0 || value === null) continue;
|
|
6563
6861
|
if (file && key === file.name) {
|
|
6564
6862
|
for (const path2 of Array.isArray(value) ? value : [value]) {
|
|
@@ -6575,13 +6873,13 @@ function buildRequest(op, values) {
|
|
|
6575
6873
|
return request;
|
|
6576
6874
|
}
|
|
6577
6875
|
if (data !== void 0 && !isRecord3(data)) {
|
|
6578
|
-
if (Object.keys(
|
|
6876
|
+
if (Object.keys(body2).length > 0) {
|
|
6579
6877
|
throw usageError("--data is not a JSON object, so it cannot be combined with body flags.", { field: "data" });
|
|
6580
6878
|
}
|
|
6581
6879
|
request.body = data;
|
|
6582
6880
|
return request;
|
|
6583
6881
|
}
|
|
6584
|
-
request.body =
|
|
6882
|
+
request.body = body2;
|
|
6585
6883
|
return request;
|
|
6586
6884
|
}
|
|
6587
6885
|
async function collectValues(ctx, op, flags) {
|
|
@@ -6687,6 +6985,7 @@ async function runOperation(ctx, op, flags) {
|
|
|
6687
6985
|
const secrets = secretParams(op);
|
|
6688
6986
|
checkSecretSources(flags, secrets.map((s) => s.flag));
|
|
6689
6987
|
const values = await collectValues(ctx, op, flags);
|
|
6988
|
+
const stream = op.stream === "sse" ? streamOptions(flags) : void 0;
|
|
6690
6989
|
if (typeof flags.each === "string") {
|
|
6691
6990
|
const { runEach: runEach2 } = await Promise.resolve().then(() => (init_each(), each_exports));
|
|
6692
6991
|
const typed = Object.fromEntries(secrets.flatMap((s) => typeof flags[s.flag] === "string" ? [[s.name, flags[s.flag]]] : []));
|
|
@@ -6699,6 +6998,7 @@ async function runOperation(ctx, op, flags) {
|
|
|
6699
6998
|
}
|
|
6700
6999
|
if (isDestructive(op)) await confirmDestructive(ctx, `${commandOf(op)} sends ${req.method} ${req.path}`, `${sameCommand(ctx, op, flags)} --yes`);
|
|
6701
7000
|
req.signal = ctx.signal;
|
|
7001
|
+
if (stream) return followEventStream(ctx, req, stream);
|
|
6702
7002
|
if (op.list && flags.all === true) {
|
|
6703
7003
|
if (isRecord3(req.body) && Array.isArray(req.body.countBy) && req.body.countBy.length > 0) {
|
|
6704
7004
|
throw usageError("--all prints rows, not counts. Ask for countBy on one page (--limit 1), or leave it out.", { field: "all" });
|
|
@@ -6728,9 +7028,9 @@ function normalizedNotes(op) {
|
|
|
6728
7028
|
return (op.description ?? "").trim().replace(/\n[ \t]+/g, "\n");
|
|
6729
7029
|
}
|
|
6730
7030
|
function helpNotes(op) {
|
|
6731
|
-
const
|
|
6732
|
-
if (
|
|
6733
|
-
const head =
|
|
7031
|
+
const text4 = normalizedNotes(op);
|
|
7032
|
+
if (text4.length <= HELP_NOTES_MAX) return text4;
|
|
7033
|
+
const head = text4.slice(0, HELP_NOTES_MAX);
|
|
6734
7034
|
const end = Math.max(head.lastIndexOf(". "), head.lastIndexOf(".\n"));
|
|
6735
7035
|
return end > HELP_NOTES_MAX / 3 ? head.slice(0, end + 1) : `${head.trimEnd()}...`;
|
|
6736
7036
|
}
|
|
@@ -6740,14 +7040,14 @@ function helpFlagText(f) {
|
|
|
6740
7040
|
if (enumText && base.endsWith(enumText)) base = base.slice(0, -enumText.length);
|
|
6741
7041
|
const placeholder = f.param ? /^\S+ \((?:path|query|body), ([\w-]+)\)$/.exec(base) : null;
|
|
6742
7042
|
if (placeholder) return { text: `${placeholder[1]}${enumText}`, cut: false };
|
|
6743
|
-
let
|
|
6744
|
-
const sentence = /\.(?=\s+[A-Z])/.exec(
|
|
6745
|
-
if (sentence)
|
|
6746
|
-
if (
|
|
6747
|
-
const head =
|
|
6748
|
-
|
|
7043
|
+
let text4 = base;
|
|
7044
|
+
const sentence = /\.(?=\s+[A-Z])/.exec(text4);
|
|
7045
|
+
if (sentence) text4 = text4.slice(0, sentence.index + 1);
|
|
7046
|
+
if (text4.length > HELP_FLAG_MAX) {
|
|
7047
|
+
const head = text4.slice(0, HELP_FLAG_MAX);
|
|
7048
|
+
text4 = `${head.slice(0, Math.max(head.lastIndexOf(" "), HELP_FLAG_MAX / 2)).replace(/[,;:]$/, "")}...`;
|
|
6749
7049
|
}
|
|
6750
|
-
return { text: `${
|
|
7050
|
+
return { text: `${text4}${enumText}`, cut: text4 !== base };
|
|
6751
7051
|
}
|
|
6752
7052
|
function operationToCommand(op) {
|
|
6753
7053
|
const flags = {};
|
|
@@ -6755,11 +7055,11 @@ function operationToCommand(op) {
|
|
|
6755
7055
|
for (const f of operationFlags(op)) {
|
|
6756
7056
|
const shown = helpFlagText(f);
|
|
6757
7057
|
cut ||= shown.cut;
|
|
6758
|
-
const
|
|
7058
|
+
const text4 = f.location === "body" && isSecretFlag(f.flag, f.type) ? `${shown.text} ${SECRET_HELP}` : shown.text;
|
|
6759
7059
|
const spec = {
|
|
6760
7060
|
type: f.type === "boolean" ? "boolean" : "string",
|
|
6761
7061
|
// The dispatcher would enforce `required` before --each rows can fill it, so the command checks it instead.
|
|
6762
|
-
description: f.required ? `${
|
|
7062
|
+
description: f.required ? `${text4} (required)` : text4
|
|
6763
7063
|
};
|
|
6764
7064
|
if (f.multiple) spec.multiple = true;
|
|
6765
7065
|
if (FOOTER_FLAGS.has(f.flag) && !f.param) spec.helpHidden = true;
|
|
@@ -6769,7 +7069,8 @@ function operationToCommand(op) {
|
|
|
6769
7069
|
const flag = flags[name];
|
|
6770
7070
|
if (flag && !flags[alias]) flag.aliases = [alias];
|
|
6771
7071
|
}
|
|
6772
|
-
const write2 = op.
|
|
7072
|
+
const write2 = op.stream === "sse" ? `
|
|
7073
|
+
${STREAM_HELP}` : op.method === "GET" ? "" : isDestructive(op) ? "\nIt deletes, archives or removes, so it needs --yes (on a terminal it asks). Run it with --dry-run first." : "\nA write: it sends at once. Run it with --dry-run first, then without.";
|
|
6773
7074
|
const api = `API: ${op.method} ${op.path} (${op.id}).${write2}`;
|
|
6774
7075
|
const named = [...op.routeParams, ...op.queryParams].find((p) => p.flag !== p.name);
|
|
6775
7076
|
const keys = named ? `keys fill flags, by flag or API name: ${named.flag} or ${named.name}` : "keys fill flags";
|
|
@@ -6779,7 +7080,7 @@ function operationToCommand(op) {
|
|
|
6779
7080
|
// The same text helpNotes measures, so the pointer shows only when something was left out.
|
|
6780
7081
|
cut || normalizedNotes(op).length > HELP_NOTES_MAX ? `Full notes: kenso describe ${op.resource} ${op.action}.` : ""
|
|
6781
7082
|
].filter(Boolean);
|
|
6782
|
-
const footer = [rows, ...more.length ? [more.join(" ")] : []];
|
|
7083
|
+
const footer = [...op.stream === "sse" ? [] : [rows], ...more.length ? [more.join(" ")] : []];
|
|
6783
7084
|
return {
|
|
6784
7085
|
resource: op.resource,
|
|
6785
7086
|
action: op.action,
|
|
@@ -6801,7 +7102,7 @@ ${api}` : api,
|
|
|
6801
7102
|
run: (ctx, args) => runOperation(ctx, op, args.flags)
|
|
6802
7103
|
};
|
|
6803
7104
|
}
|
|
6804
|
-
var DATA_KEY, IDEMPOTENCY_KEY, IDEMPOTENCY_KEY_FLAG, SCALAR_TYPES, FLAG_ALIASES, LIST_PARAM_TEXT, HELP_NOTES_MAX, HELP_FLAG_MAX, FOOTER_FLAGS;
|
|
7105
|
+
var STREAM_HELP, DATA_KEY, IDEMPOTENCY_KEY, IDEMPOTENCY_KEY_FLAG, SCALAR_TYPES, FLAG_ALIASES, LIST_PARAM_TEXT, HELP_NOTES_MAX, HELP_FLAG_MAX, FOOTER_FLAGS;
|
|
6805
7106
|
var init_execute = __esm({
|
|
6806
7107
|
"src/generated/execute.ts"() {
|
|
6807
7108
|
"use strict";
|
|
@@ -6811,6 +7112,8 @@ var init_execute = __esm({
|
|
|
6811
7112
|
init_http();
|
|
6812
7113
|
init_input();
|
|
6813
7114
|
init_secret_flags();
|
|
7115
|
+
init_stream();
|
|
7116
|
+
STREAM_HELP = "A live stream: it prints one JSON line per event ({event, id, data}) as it arrives and runs until Ctrl-C, reconnecting when the server closes it (with Last-Event-ID once events carry an id). --until <event> ends after that event, --max-events <n> after n events, --once when the server closes it.";
|
|
6814
7117
|
DATA_KEY = "$data";
|
|
6815
7118
|
IDEMPOTENCY_KEY = "$idempotencyKey";
|
|
6816
7119
|
IDEMPOTENCY_KEY_FLAG = "idempotency-key";
|
|
@@ -6908,8 +7211,8 @@ function firstValue(row, columns2) {
|
|
|
6908
7211
|
const value = row[column];
|
|
6909
7212
|
if (value === void 0 || value === null) continue;
|
|
6910
7213
|
if (typeof value === "string") {
|
|
6911
|
-
const
|
|
6912
|
-
if (
|
|
7214
|
+
const text4 = value.trim();
|
|
7215
|
+
if (text4 !== "") return text4;
|
|
6913
7216
|
continue;
|
|
6914
7217
|
}
|
|
6915
7218
|
if (Array.isArray(value) && value.length === 0) continue;
|
|
@@ -6925,10 +7228,10 @@ function textValue(value, field) {
|
|
|
6925
7228
|
}
|
|
6926
7229
|
function integerValue(value, field, min) {
|
|
6927
7230
|
if (value === void 0) return void 0;
|
|
6928
|
-
let
|
|
6929
|
-
if (typeof value === "number")
|
|
6930
|
-
else if (typeof value === "string")
|
|
6931
|
-
const number =
|
|
7231
|
+
let text4;
|
|
7232
|
+
if (typeof value === "number") text4 = String(value);
|
|
7233
|
+
else if (typeof value === "string") text4 = /^\d{1,3}(,\d{3})+$/.test(value) ? value.replace(/,/g, "") : value;
|
|
7234
|
+
const number = text4 !== void 0 && /^-?\d+$/.test(text4) ? Number(text4) : Number.NaN;
|
|
6932
7235
|
if (!Number.isSafeInteger(number) || min !== void 0 && number < min) {
|
|
6933
7236
|
const kind = min === 1 ? "a positive whole number" : min === 0 ? "a whole number of 0 or more" : "a whole number";
|
|
6934
7237
|
throw new RowInvalid("invalid_value", `${field} must be ${kind} (got ${JSON.stringify(value)}).`);
|
|
@@ -7049,25 +7352,25 @@ function toBody(row, columns2) {
|
|
|
7049
7352
|
const value = (field) => firstValue(row, columns2.sources.get(field));
|
|
7050
7353
|
const domains = domainsOf(row, columns2);
|
|
7051
7354
|
if (domains.length === 0) throw new RowInvalid("domain_required", "An account needs a domain: a domain, website or domains column.");
|
|
7052
|
-
const
|
|
7355
|
+
const body2 = {};
|
|
7053
7356
|
const name = textValue(value("name"), "name");
|
|
7054
|
-
if (name !== void 0)
|
|
7055
|
-
|
|
7357
|
+
if (name !== void 0) body2.name = name;
|
|
7358
|
+
body2.domains = domains;
|
|
7056
7359
|
for (const field of TEXT_FIELDS.slice(1)) {
|
|
7057
|
-
const
|
|
7058
|
-
if (
|
|
7360
|
+
const text4 = textValue(value(field), field);
|
|
7361
|
+
if (text4 !== void 0) body2[field] = text4;
|
|
7059
7362
|
}
|
|
7060
7363
|
const employeeCount = integerValue(value("employeeCount"), "employeeCount", 0);
|
|
7061
|
-
if (employeeCount !== void 0)
|
|
7364
|
+
if (employeeCount !== void 0) body2.employeeCount = employeeCount;
|
|
7062
7365
|
for (const field of INTEGER_FIELDS) {
|
|
7063
7366
|
const number = integerValue(value(field), field);
|
|
7064
|
-
if (number !== void 0)
|
|
7367
|
+
if (number !== void 0) body2[field] = number;
|
|
7065
7368
|
}
|
|
7066
7369
|
for (const field of ID_FIELDS) {
|
|
7067
7370
|
const id = idValue(value(field), field);
|
|
7068
|
-
if (id !== void 0)
|
|
7371
|
+
if (id !== void 0) body2[field] = id;
|
|
7069
7372
|
}
|
|
7070
|
-
return
|
|
7373
|
+
return body2;
|
|
7071
7374
|
}
|
|
7072
7375
|
function accountResult(row, r) {
|
|
7073
7376
|
const id = r.accountId !== void 0 && r.accountId !== null ? { id: String(r.accountId) } : {};
|
|
@@ -7262,6 +7565,14 @@ var init_batch = __esm({
|
|
|
7262
7565
|
}
|
|
7263
7566
|
});
|
|
7264
7567
|
|
|
7568
|
+
// docs/connect.md
|
|
7569
|
+
var connect_default;
|
|
7570
|
+
var init_connect = __esm({
|
|
7571
|
+
"docs/connect.md"() {
|
|
7572
|
+
connect_default = '# Connect accounts in the browser\n\n`kenso connect <kind>` connects an inbox, a calendar, a CRM, GitHub or another account that signs in with OAuth. It starts the connect, prints the link, waits until the connection shows up in Kenso, and prints it as JSON.\n\nThe sign-in itself happens in a browser, always. Kenso refuses to finish an OAuth connect for an API key or an agent, on purpose: the account belongs to the person who signs in. So the CLI never finishes it. It hands the link to the person and watches.\n\n```bash\nkenso connect inbox --provider google\n```\n\n```\nTo connect the mailbox, open https://accounts.google.com/o/oauth2/v2/auth?...\nWaiting up to 10 minutes for the connection (Ctrl-C stops waiting).\n```\n\nOnce the person signs in, it prints the new inbox and exits 0:\n\n```json\n{"connected":true,"kind":"inbox","connection":{"id":4812,"email":"sam@acme.com","provider":"google","status":"warmup"}}\n```\n\n## Kinds\n\n| Command | Connects | Watches |\n|---|---|---|\n| `connect inbox --provider google\\|microsoft` | A sending inbox (`--purpose campaign`, the default) or your own mailbox (`--purpose primary`) | `GET /v1/inboxes` for a new inbox, or one signed in again |\n| `connect calendar --provider google\\|microsoft` | A calendar, with email unless `--access calendar_only`. `--account-id cacc_...` signs one in again | `GET /v1/calendar-accounts` |\n| `connect video --provider zoom\\|webex` | Nothing: only a signed-in person can start a Zoom or Webex connect, so it says where in the app and waits | `GET /v1/video-connections` |\n| `connect crm --provider <crm>` | hubspot, salesforce, pipedrive, attio, highlevel, dynamics (`--base-url`), zoho | `GET /v1/crm-connections` |\n| `connect hubspot-knowledge` | HubSpot as a Knowledge source | `GET /v1/knowledge/sources` |\n| `connect github` | The Kenso GitHub app, for Knowledge | `GET /v1/integrations/github/installations` |\n| `connect migration` | Outreach, as a migration source. `--connection-id` signs one in again | `GET /v1/migration-connections` |\n| `connect linkedin` | A LinkedIn account. `--linkedin-account-id` signs one in again | The account the start adds |\n| `connect whatsapp` | A WhatsApp account. `--whatsapp-account-id` signs one in again | The account the start adds |\n| `connect facebook`, `connect instagram` | A Facebook or Instagram account (beta workspaces) | The account the start adds |\n\nCRMs that connect with an API key (close, twenty) and the API-key migration sources (Instantly, Smartlead, ...) need no browser: use `kenso crm-connections create` and `kenso migration-connections create`. Slack, Teams and the dialers have their own generated commands, such as `kenso slack-connection start`.\n\n## Under a coding agent\n\nWhen the CLI runs under a coding agent (Claude Code, Codex, Cursor ...), it never opens a browser. It prints the link on stderr and asks the agent to hand it to its person:\n\n```\nTo connect the mailbox, open https://accounts.google.com/o/oauth2/v2/auth?...\nAsk the person you are working with to open the link and finish the sign-in in their browser. Waiting up to 10 minutes.\n```\n\nA person at a desktop gets the link opened in their browser too. `--no-browser` only prints it.\n\nAn agent that cannot wait runs `--no-wait`: the command prints the start answer, link included, as JSON and ends. It then checks the list itself, for example `kenso inboxes list`.\n\n## Flags\n\n| Flag | What it does |\n|---|---|\n| `--timeout <seconds>` | How long to wait, 600 by default. Most links expire after 10 minutes; LinkedIn and WhatsApp links after an hour |\n| `--no-wait` | Print the start answer and end |\n| `--no-browser` | Never open a browser |\n| `--dry-run` | Print the request it would send and the route it would watch, and send nothing |\n\nIt checks every 5 seconds, and only items of the provider (or vendor, or account) you named. A connect counts when a new item shows up, or when a known one takes a new sign-in: its `connectedAt` moves, or it comes back from a disconnected status. So signing an account in again counts, and another inbox leaving warmup or a CRM resuming its sync does not.\n\n## Exit codes\n\n| Code | When |\n|---|---|\n| 0 | Connected (or, for `video`, connected already) |\n| 1 | `connect_timeout`: nothing showed up in time. `connect_failed`: the account\'s sign-in failed (`credentials_error`, `connect_failed`) |\n| 2 | A bad flag, such as an unknown `--provider` |\n| 3, 4, 6, 8 | The API\'s answer, as for every command (`kenso docs output-and-errors`) |\n| 130 | Ctrl-C |\n\nA Google or Microsoft mailbox you connect as `--purpose primary` that is not your login email waits for a confirmation in app.ken.so after the sign-in. It shows up only once you confirm it there, so the command times out with that hint.\n';
|
|
7573
|
+
}
|
|
7574
|
+
});
|
|
7575
|
+
|
|
7265
7576
|
// docs/crm.md
|
|
7266
7577
|
var crm_default;
|
|
7267
7578
|
var init_crm = __esm({
|
|
@@ -7282,7 +7593,7 @@ var init_leads = __esm({
|
|
|
7282
7593
|
var output_and_errors_default;
|
|
7283
7594
|
var init_output_and_errors = __esm({
|
|
7284
7595
|
"docs/output-and-errors.md"() {
|
|
7285
|
-
output_and_errors_default = '# Output and errors\n\nEvery command follows one contract, so a script or an agent can parse any of them the same way.\n\n## stdout and stderr\n\n- **stdout carries data only.** Progress, warnings, notices and errors go to stderr.\n- No colors, spinners or pagers. On a terminal you get readable tables; in a pipe you get JSON.\n- A batch command (an import, update, remove, tag or `--each` write) takes `--yes`; without it, the command plans or refuses.\n- A command that deletes, archives or removes, such as `kenso tags delete --tag-id 7`, `kenso campaigns archive` or `kenso api DELETE /v1/tags/7`, needs `--yes` too. Without it, a person at a terminal is asked to confirm; anywhere else (a pipe, a script, CI, a coding agent) it sends nothing and fails with `confirmation_required`, whose `next` is the same command with `--yes`.\n- Any other single write, such as `kenso tags create` or a write through `kenso api` or `kenso mcp call`, sends at once: add `--dry-run` to print the request first (it sends nothing), then run the command without it.\n- A command with no dry run, such as `kenso contacts export`, `kenso auth logout` or `kenso workspace use`, refuses `--dry-run` with `usage_error` (exit 2) and does nothing. Its help ends with `No --dry-run`, and `kenso describe <resource> <action>` shows `"dryRun": false`.\n\n## Formats\n\n| What the command returns | stdout is a terminal | stdout is a pipe or file |\n|---|---|---|\n| One object | key-value lines | compact JSON on one line |\n| A list | a table (first 8 scalar fields, cells cut at 60 characters) | NDJSON: one JSON object per line |\n| A batch run | key-value lines | one JSON summary object |\n| No content (HTTP 204) | nothing | nothing |\n\n`-o` or `--output` picks the format: `json`, `ndjson`, `table` or `ids`. `--json` is the same as `-o json`.\n\n- `-o json` on a list prints one JSON array. On a terminal, `-o json` pretty-prints an object.\n- `-o ids` prints one id per line, ready for `--ids -`. Items without an `id` are skipped with one warning.\n\n```bash\nkenso campaigns list --limit 3\nkenso campaigns list --limit 3 -o json\nkenso contacts list --campaign-id 812 --all -o ids\n```\n\n## Shape the output\n\n- `--fields a,b.c` keeps only those fields (dots reach into nested objects).\n- `--query <JMESPath>` filters or reshapes in-process, so you need no `jq`. On a list it sees the whole list. There is no `--jq`: `--query` takes JMESPath, not jq syntax.\n- Neither applies to a batch summary, which always prints in full.\n\n```bash\nkenso campaigns list --fields id,name,status\nkenso campaigns list --all --query "[?status==\'active\'].id"\nkenso me get --query "length(features)"\n```\n\n## Lists and pages\n\nA list command prints one page. When there are more, it prints the command for the next page on stderr, for example `next: kenso tags list --limit 1 --cursor MQ`. `--all` follows every page and streams the items. `--limit` sets the page size and `--cursor` starts at a cursor.\n\n`accounts search`, `contacts search` and `people search` page the same way: one page with the `next:` command, or every page with `--all`. A search that asks for counts (`countBy` in `--data`) prints the whole answer instead: `data`, `pagination` and `counts`. Counts cover every match whatever the page, so ask for them on one page (`--limit 1`): `--all` with `countBy` is a usage error.\n\n```bash\nkenso tags list --limit 50\nkenso tags list --all\n```\n\n## Errors\n\nWhen stderr is not a terminal, an error is one JSON line on stderr:\n\n```json\n{"error":{"code":"unknown_flag","message":"Unknown flag --fiel for kenso contacts import.","field":"fiel","hint":"did you mean --file?","next":"kenso contacts import --help"}}\n```\n\n| Key | Always there | Meaning |\n|---|---|---|\n| `code` | yes | A stable snake_case code to branch on |\n| `message` | yes | One sentence for a person |\n| `field` | no | The flag or input field at fault |\n| `hint` | no | What to change |\n| `next` | no | The exact command to run next, such as `kenso auth login`, `kenso workspace list --search <name>` or the same command with `--yes` |\n| `httpStatus` | no | The API\'s HTTP status, when the API answered |\n| `requestId` | no | The API\'s request id: quote it when you contact Kenso support |\n\nOn a terminal the same error prints as text: `Error: <message>`, then `field:`, `hint:`, `next:` and `requestId:` lines. The key never appears in an error.\n\n### How API errors map\n\nThe CLI looks at the HTTP status first, then at the API\'s own `error.code`, which wins when present.\n\n| HTTP status | Default code | Exit |\n|---|---|---|\n| 400, 422 | `validation_failed` | 2 |\n| 401 | `unauthorized` (`next`: `kenso auth login`) | 3 |\n| 403 | `forbidden`: the key\'s user or role cannot do this in this workspace | 3 |\n| 404 | `not_found` | 4 |\n| 409 | `conflict` | 7 |\n| 429 | `rate_limited`, after the CLI waited and retried | 6 |\n| 5xx | `server_error`, after retries where they are safe | 8 |\n| anything else | `http_error` | 1 |\n\nTwo API codes change the exit code: `workspace_required` exits 2 with `"next":"kenso workspace list --search <name>"`, and `limit_reached` (the plan\'s or the campaign\'s lead limit) exits 6.\n\n### Errors from the CLI itself\n\n| Code | Exit | When |\n|---|---|---|\n| `usage_error` | 2 | A required flag or argument is missing, two flags conflict (`--yes` with `--dry-run`), or `--dry-run` on a command that has no dry run |\n| `unknown_command` | 2 | No such command; `hint` suggests the closest one |\n| `unknown_flag`, `invalid_flag`, `invalid_flag_value`, `unexpected_argument` | 2 | A flag or argument the command does not take |\n| `invalid_query` | 2 | `--query` is not valid JMESPath |\n| `confirmation_required` | 2 | A delete, archive or remove ran without `--yes` where nobody can confirm: nothing was sent; `next` adds `--yes` |\n| `cancelled` | 2 | A person answered no to the confirmation: nothing was sent |\n| `file_unreadable` | 2 | An input file is missing, is a folder, cannot be opened, or cannot be parsed; the message names the line, such as `leads.csv line 3: a quote is not closed.` |\n| `config_invalid` | 2 | `~/.kenso/config.json` is not valid JSON: fix or delete it |\n| `feature_not_enabled` | 2 | Every action of the resource is a beta command your workspace has not enabled |\n| `invalid_key_format`, `key_required` | 2 | `auth login --with-key` read something that is not a Kenso key, or stdin is a terminal instead of a pipe |\n| `invalid_workspace_id` | 2 | `kenso workspace use` got an id that is not a positive whole number |\n| `unknown_topic` | 2 | `kenso docs` got a topic it does not have; `hint` lists the topics |\n| `file_unwritable` | 2 or 1 | An output file cannot be written: `contacts export --out` (2), `skill install` (1) |\n| `no_api_key` | 3 | No key in `KENSO_API_KEY` or the profile (`next`: `kenso auth login`) |\n| `browser_login_unavailable`, `access_denied`, `login_expired` | 3 | Browser login is off, was denied, or timed out |\n| `run_not_found` | 4 | `kenso runs show` or `resume` got an unknown run id |\n| `docs_not_found` | 4 | `kenso docs reference` before the reference was generated (a source checkout without `pnpm build`) |\n| `run_in_progress`, `already_filled` | 7 | Another process is working on the run, or `studio fill` already ran with this file and these flags |\n| `skill_exists` | 7 | `kenso skill install` found a different `SKILL.md`; `next` adds `--force` to replace it |\n| `job_timeout`, `job_failed`, `job_canceled` | 1 | `kenso jobs wait` (or a command that waits on a job) ran out of time, or the job failed or was canceled |\n| `mcp_tool_error` | 1 | `kenso mcp call`: the MCP tool answered with an error |\n| `unsafe_path` | 1 | `studio pull` refused a file path that would land outside `--dir` |\n| `network_error` | 8 | The API could not be reached after retries |\n| `upload_failed`, `download_failed` | 8 or 1 | A signed upload or download of a Studio file failed: 8 when storage was unreachable or answered 5xx, 1 on a 4xx (often an expired link: run the command again) |\n| `pull_incomplete` | 8 | `studio pull`: a file came back with neither text nor a download link |\n| `unexpected_response` | 1 or 8 | The API answered something the CLI could not read |\n| `unexpected_error` | 1 | A bug: run again with `--verbose` and report it |\n| `interrupted` | 130 | Ctrl-C |\n\n## Exit codes\n\n| Code | Meaning |\n|---|---|\n| 0 | OK, including a batch where every row succeeded or was skipped |\n| 1 | Unexpected error |\n| 2 | Usage or input error: a bad flag, a bad file, a validation error |\n| 3 | Auth: no key, an invalid, revoked or expired key, or HTTP 401 or 403 |\n| 4 | Not found |\n| 5 | Partial: the batch finished and some rows failed, were not found or were invalid. See `results.csv` |\n| 6 | Rate limited after retries, or a plan or campaign lead limit stopped the run (`limit_reached`) |\n| 7 | Conflict or invalid state (HTTP 409), or a run another process holds |\n| 8 | Server error after retries (5xx), or the API is unreachable |\n| 9 | Answer refused: a Kenso sandbox run stopped because an answer held a credential or something shaped like one |\n| 130 | Interrupted. A batch run can be resumed: see its `next` |\n\nSkipped rows (duplicates, blocklisted, already contacted) are not failures: a batch with only created, updated and skipped rows exits 0.\n\n## Flags\n\n- Command flags go after the command: `kenso contacts import --campaign 812`. Global flags can go anywhere.\n- A boolean flag takes `--flag`, `--no-flag`, `--flag=true` and `--flag=false`.\n- A flag that carries a secret (`--password`, `--api-key`, `--api-secret`, any `--\u2026-token` or `--\u2026-secret`) also takes `-` (read stdin), `@file` (read the file) or `env:NAME` (read that environment variable), so the value stays out of shell history: `printf \'%s\' "$FATHOM_KEY" | kenso fathom-connection connect --api-key -`. A value typed on the command line still works and prints one warning. A typed secret that itself starts with `@` is written `@@` (`--password @@Spring2026` sends `@Spring2026`); one that is exactly `-` or starts with `env:` has to come through `@file` or `env:NAME`. `-` refuses a terminal, an empty value is refused, and only one flag can read stdin. `--dry-run` shows a secret as `***`. With `--each`, the plan, its `next` and the run record keep `@file` or `env:NAME` as typed and `kenso runs resume` reads it again; a secret from stdin is refused there.\n- `--help` on any command prints its flags, arguments and examples. `kenso describe <resource> <action>` prints the same as JSON, with the body schema.\n\n## Beta commands\n\nCommands that need a workspace feature flag (CRM, Studio and others) are beta. Help and `kenso describe` hide the ones your workspace has not enabled and say how many they hid; `--all-commands` shows them. Calling a hidden command still works: Kenso decides. `kenso <resource>` on a resource whose every action is hidden answers `feature_not_enabled` (exit 2) and names the flags it needs.\n\n```bash\nkenso --help --all-commands\nkenso describe --all-commands\n```\n\n## What the CLI sends\n\nEvery API call carries `Authorization: Bearer <key>`, `Ken-Version: 1.1`, `X-Ken-Workspace-Id` (when a workspace is picked), `User-Agent: kenso-cli/<version> (node <version>; <platform>)` and `X-Ken-Client: Kenso CLI`. When a coding agent runs the CLI, `X-Ken-Client` names it (`Kenso CLI via Claude Code`) and writes carry `X-Ken-Actor: agent`, so Kenso\'s activity log shows who made a change.\n';
|
|
7596
|
+
output_and_errors_default = '# Output and errors\n\nEvery command follows one contract, so a script or an agent can parse any of them the same way.\n\n## stdout and stderr\n\n- **stdout carries data only.** Progress, warnings, notices and errors go to stderr.\n- No colors, spinners or pagers. On a terminal you get readable tables; in a pipe you get JSON.\n- A batch command (an import, update, remove, tag or `--each` write) takes `--yes`; without it, the command plans or refuses.\n- A command that deletes, archives or removes, such as `kenso tags delete --tag-id 7`, `kenso campaigns archive` or `kenso api DELETE /v1/tags/7`, needs `--yes` too. Without it, a person at a terminal is asked to confirm; anywhere else (a pipe, a script, CI, a coding agent) it sends nothing and fails with `confirmation_required`, whose `next` is the same command with `--yes`.\n- Any other single write, such as `kenso tags create` or a write through `kenso api` or `kenso mcp call`, sends at once: add `--dry-run` to print the request first (it sends nothing), then run the command without it.\n- A command with no dry run, such as `kenso contacts export`, `kenso auth logout` or `kenso workspace use`, refuses `--dry-run` with `usage_error` (exit 2) and does nothing. Its help ends with `No --dry-run`, and `kenso describe <resource> <action>` shows `"dryRun": false`.\n\n## Formats\n\n| What the command returns | stdout is a terminal | stdout is a pipe or file |\n|---|---|---|\n| One object | key-value lines | compact JSON on one line |\n| A list | a table (first 8 scalar fields, cells cut at 60 characters) | NDJSON: one JSON object per line |\n| A batch run | key-value lines | one JSON summary object |\n| No content (HTTP 204) | nothing | nothing |\n\n`-o` or `--output` picks the format: `json`, `ndjson`, `table` or `ids`. `--json` is the same as `-o json`.\n\n- `-o json` on a list prints one JSON array. On a terminal, `-o json` pretty-prints an object.\n- `-o ids` prints one id per line, ready for `--ids -`. Items without an `id` are skipped with one warning.\n\n```bash\nkenso campaigns list --limit 3\nkenso campaigns list --limit 3 -o json\nkenso contacts list --campaign-id 812 --all -o ids\n```\n\n## Shape the output\n\n- `--fields a,b.c` keeps only those fields (dots reach into nested objects).\n- `--query <JMESPath>` filters or reshapes in-process, so you need no `jq`. On a list it sees the whole list. There is no `--jq`: `--query` takes JMESPath, not jq syntax.\n- Neither applies to a batch summary, which always prints in full.\n\n```bash\nkenso campaigns list --fields id,name,status\nkenso campaigns list --all --query "[?status==\'active\'].id"\nkenso me get --query "length(features)"\n```\n\n## Lists and pages\n\nA list command prints one page. When there are more, it prints the command for the next page on stderr, for example `next: kenso tags list --limit 1 --cursor MQ`. `--all` follows every page and streams the items. `--limit` sets the page size and `--cursor` starts at a cursor.\n\n`accounts search`, `contacts search` and `people search` page the same way: one page with the `next:` command, or every page with `--all`. A search that asks for counts (`countBy` in `--data`) prints the whole answer instead: `data`, `pagination` and `counts`. Counts cover every match whatever the page, so ask for them on one page (`--limit 1`): `--all` with `countBy` is a usage error.\n\n```bash\nkenso tags list --limit 50\nkenso tags list --all\n```\n\n## Live streams\n\n`kenso sync events` and `kenso onboarding-builds events` follow a live stream of server-sent events. They print one JSON line per event as it arrives, on a terminal too, with the event\'s name, its id when it has one, and its data:\n\n```json\n{"event":"hello","data":{"buildId":"obd_2x","status":"building","stage":"read","lastEventId":0}}\n{"event":"stage","id":"41","data":{"stage":"plan"}}\n{"event":"done","id":"42","data":{}}\n```\n\nA stream has no time limit while events arrive. The server ends each connection after 15 minutes with a `bye` event; the command then connects again at once, and after a dropped connection or 60 s without even a keepalive, after a second. A connection that brought nothing but `hello` and `bye` (a server that is restarting) backs off 1, 2, 4 ... 30 s. Once events carry an id (`onboarding-builds events`), it sends the last whole event\'s id as `Last-Event-ID`, so no event is lost or printed twice. A refusal (401, 403, 404) ends it at once; eight failed or empty connects in a row end it with the last error.\n\nIt runs until Ctrl-C (exit 130; every line printed is whole), or until one of these:\n\n| Flag | Ends the command |\n|---|---|\n| `--until <event>` | After the first event with that name; several names are comma-separated: `--until done,error` |\n| `--max-events <n>` | After n events, `hello` and `bye` included |\n| `--once` | When the server closes the connection, instead of connecting again |\n\n```bash\nkenso onboarding-builds events --build-id obd_2x --until done,error\nkenso sync events --max-events 2 # hello, then the first poke\n```\n\n`--output`, `--fields` and `--query` do not apply to a stream. `--last-event-id` starts an onboarding build stream after that id.\n\n## Errors\n\nWhen stderr is not a terminal, an error is one JSON line on stderr:\n\n```json\n{"error":{"code":"unknown_flag","message":"Unknown flag --fiel for kenso contacts import.","field":"fiel","hint":"did you mean --file?","next":"kenso contacts import --help"}}\n```\n\n| Key | Always there | Meaning |\n|---|---|---|\n| `code` | yes | A stable snake_case code to branch on |\n| `message` | yes | One sentence for a person |\n| `field` | no | The flag or input field at fault |\n| `hint` | no | What to change |\n| `next` | no | The exact command to run next, such as `kenso auth login`, `kenso workspace list --search <name>` or the same command with `--yes` |\n| `httpStatus` | no | The API\'s HTTP status, when the API answered |\n| `requestId` | no | The API\'s request id: quote it when you contact Kenso support |\n\nOn a terminal the same error prints as text: `Error: <message>`, then `field:`, `hint:`, `next:` and `requestId:` lines. The key never appears in an error.\n\n### How API errors map\n\nThe CLI looks at the HTTP status first, then at the API\'s own `error.code`, which wins when present.\n\n| HTTP status | Default code | Exit |\n|---|---|---|\n| 400, 422 | `validation_failed` | 2 |\n| 401 | `unauthorized` (`next`: `kenso auth login`) | 3 |\n| 403 | `forbidden`: the key\'s user or role cannot do this in this workspace | 3 |\n| 404 | `not_found` | 4 |\n| 409 | `conflict` | 7 |\n| 429 | `rate_limited`, after the CLI waited and retried | 6 |\n| 5xx | `server_error`, after retries where they are safe | 8 |\n| anything else | `http_error` | 1 |\n\nTwo API codes change the exit code: `workspace_required` exits 2 with `"next":"kenso workspace list --search <name>"`, and `limit_reached` (the plan\'s or the campaign\'s lead limit) exits 6.\n\n### Errors from the CLI itself\n\n| Code | Exit | When |\n|---|---|---|\n| `usage_error` | 2 | A required flag or argument is missing, two flags conflict (`--yes` with `--dry-run`), or `--dry-run` on a command that has no dry run |\n| `unknown_command` | 2 | No such command; `hint` suggests the closest one |\n| `unknown_flag`, `invalid_flag`, `invalid_flag_value`, `unexpected_argument` | 2 | A flag or argument the command does not take |\n| `invalid_query` | 2 | `--query` is not valid JMESPath |\n| `confirmation_required` | 2 | A delete, archive or remove ran without `--yes` where nobody can confirm: nothing was sent; `next` adds `--yes` |\n| `cancelled` | 2 | A person answered no to the confirmation: nothing was sent |\n| `file_unreadable` | 2 | An input file is missing, is a folder, cannot be opened, or cannot be parsed; the message names the line, such as `leads.csv line 3: a quote is not closed.` |\n| `config_invalid` | 2 | `~/.kenso/config.json` is not valid JSON: fix or delete it |\n| `feature_not_enabled` | 2 | Every action of the resource is a beta command your workspace has not enabled |\n| `invalid_key_format`, `key_required` | 2 | `auth login --with-key` read something that is not a Kenso key, or stdin is a terminal instead of a pipe |\n| `invalid_workspace_id` | 2 | `kenso workspace use` got an id that is not a positive whole number |\n| `unknown_topic` | 2 | `kenso docs` got a topic it does not have; `hint` lists the topics |\n| `file_unwritable` | 2 or 1 | An output file cannot be written: `contacts export --out` (2), `skill install` (1) |\n| `no_api_key` | 3 | No key in `KENSO_API_KEY` or the profile (`next`: `kenso auth login`) |\n| `browser_login_unavailable`, `access_denied`, `login_expired` | 3 | Browser login is off, was denied, or timed out |\n| `run_not_found` | 4 | `kenso runs show` or `resume` got an unknown run id |\n| `docs_not_found` | 4 | `kenso docs reference` before the reference was generated (a source checkout without `pnpm build`) |\n| `run_in_progress`, `already_filled` | 7 | Another process is working on the run, or `studio fill` already ran with this file and these flags |\n| `skill_exists` | 7 | `kenso skill install` found a different `SKILL.md`; `next` adds `--force` to replace it |\n| `job_timeout`, `job_failed`, `job_canceled` | 1 | `kenso jobs wait` (or a command that waits on a job) ran out of time, or the job failed or was canceled |\n| `mcp_tool_error` | 1 | `kenso mcp call`: the MCP tool answered with an error |\n| `unsafe_path` | 1 | `studio pull` refused a file path that would land outside `--dir` |\n| `network_error` | 8 | The API could not be reached after retries |\n| `upload_failed`, `download_failed` | 8 or 1 | A signed upload or download of a Studio file failed: 8 when storage was unreachable or answered 5xx, 1 on a 4xx (often an expired link: run the command again) |\n| `pull_incomplete` | 8 | `studio pull`: a file came back with neither text nor a download link |\n| `unexpected_response` | 1 or 8 | The API answered something the CLI could not read |\n| `unexpected_error` | 1 | A bug: run again with `--verbose` and report it |\n| `interrupted` | 130 | Ctrl-C |\n\n## Exit codes\n\n| Code | Meaning |\n|---|---|\n| 0 | OK, including a batch where every row succeeded or was skipped |\n| 1 | Unexpected error |\n| 2 | Usage or input error: a bad flag, a bad file, a validation error |\n| 3 | Auth: no key, an invalid, revoked or expired key, or HTTP 401 or 403 |\n| 4 | Not found |\n| 5 | Partial: the batch finished and some rows failed, were not found or were invalid. See `results.csv` |\n| 6 | Rate limited after retries, or a plan or campaign lead limit stopped the run (`limit_reached`) |\n| 7 | Conflict or invalid state (HTTP 409), or a run another process holds |\n| 8 | Server error after retries (5xx), or the API is unreachable |\n| 9 | Answer refused: a Kenso sandbox run stopped because an answer held a credential or something shaped like one |\n| 130 | Interrupted. A batch run can be resumed: see its `next` |\n\nSkipped rows (duplicates, blocklisted, already contacted) are not failures: a batch with only created, updated and skipped rows exits 0.\n\n## Flags\n\n- Command flags go after the command: `kenso contacts import --campaign 812`. Global flags can go anywhere.\n- A boolean flag takes `--flag`, `--no-flag`, `--flag=true` and `--flag=false`.\n- A flag that carries a secret (`--password`, `--api-key`, `--api-secret`, any `--\u2026-token` or `--\u2026-secret`) also takes `-` (read stdin), `@file` (read the file) or `env:NAME` (read that environment variable), so the value stays out of shell history: `printf \'%s\' "$FATHOM_KEY" | kenso fathom-connection connect --api-key -`. A value typed on the command line still works and prints one warning. A typed secret that itself starts with `@` is written `@@` (`--password @@Spring2026` sends `@Spring2026`); one that is exactly `-` or starts with `env:` has to come through `@file` or `env:NAME`. `-` refuses a terminal, an empty value is refused, and only one flag can read stdin. `--dry-run` shows a secret as `***`. With `--each`, the plan, its `next` and the run record keep `@file` or `env:NAME` as typed and `kenso runs resume` reads it again; a secret from stdin is refused there.\n- `--help` on any command prints its flags, arguments and examples. `kenso describe <resource> <action>` prints the same as JSON, with the body schema.\n\n## Beta commands\n\nCommands that need a workspace feature flag (CRM, Studio and others) are beta. Help and `kenso describe` hide the ones your workspace has not enabled and say how many they hid; `--all-commands` shows them. Calling a hidden command still works: Kenso decides. `kenso <resource>` on a resource whose every action is hidden answers `feature_not_enabled` (exit 2) and names the flags it needs.\n\n```bash\nkenso --help --all-commands\nkenso describe --all-commands\n```\n\n## What the CLI sends\n\nEvery API call carries `Authorization: Bearer <key>`, `Ken-Version: 1.1`, `X-Ken-Workspace-Id` (when a workspace is picked), `User-Agent: kenso-cli/<version> (node <version>; <platform>)` and `X-Ken-Client: Kenso CLI`. When a coding agent runs the CLI, `X-Ken-Client` names it (`Kenso CLI via Claude Code`) and writes carry `X-Ken-Actor: agent`, so Kenso\'s activity log shows who made a change.\n';
|
|
7286
7597
|
}
|
|
7287
7598
|
});
|
|
7288
7599
|
|
|
@@ -7290,7 +7601,7 @@ var init_output_and_errors = __esm({
|
|
|
7290
7601
|
var README_default;
|
|
7291
7602
|
var init_README = __esm({
|
|
7292
7603
|
"docs/README.md"() {
|
|
7293
|
-
README_default = '# Kenso CLI\n\nThe Kenso CLI (`kenso`) is the command line for Kenso. It does bulk work in your Kenso workspace from files: add thousands of leads to a campaign, update or clean them up, import accounts and people, and build Studio templates. It is made for coding agents (Claude Code, Codex, Cursor) and the people who drive them: JSON on stdout, fixed exit codes, a dry run before every bulk write, and runs you can resume.\n\nEvery API operation a workspace member can call is also a command, such as `kenso campaigns list` or `kenso tags create`. So the CLI reaches what the Kenso MCP reaches, straight against `https://api.ken.so`.\n\n## Install\n\nOn macOS or Linux, with or without Node, run the [install script](https://ken.so/install.sh): fetch it with `curl -fsSL` and pipe it to `sh`. It installs a standalone build that brings its own Node.js, checks the download against the release\'s `SHA256SUMS`, puts the CLI in `~/.local/share/kenso` and links `~/.local/bin/kenso`. Run it again to update.\n\nWith Homebrew, on macOS or Linux, the same standalone build:\n\n```bash\nbrew install ken-technology/tap/kenso\n```\n\n`brew upgrade kenso` updates it.\n\nWith Node 22 or newer, on any system, Windows included:\n\n```bash\nnpm i -g kenso\nkenso --version\n```\n\nTo run it once without installing, use `npx kenso --version`. On an older Node, kenso stops with one line that says so.\n\nEvery way to install:\n\n| Way | Systems | Needs |\n|---|---|---|\n| Install script, above | macOS, Linux (glibc) | Nothing |\n| Homebrew, above | macOS, Linux | Homebrew |\n| npm, above | Any | Node 22 or newer |\n| Standalone build: unpack it and put its `bin` folder on your PATH | macOS, Linux, Windows | Nothing |\n\nThe standalone builds are at `https://downloads.ken.so/desktop/cli/<version>/`, one per system: `kenso-<version>-darwin-arm64.tar.gz`, `darwin-x64`, `linux-arm64`, `linux-x64` and `kenso-<version>-windows-x64.zip`, with their `SHA256SUMS`. `https://downloads.ken.so/desktop/cli/latest.yml` names the newest version. The builds come out nightly and Homebrew follows them, so a command added that day reaches npm first.\n\n### Tab completion\n\nTab completes resources, actions and flags once you install the script for your shell. The script asks `kenso` for the candidates on each Tab, so it stays right as the CLI updates: install it once.\n\n```bash\n# zsh: add this line to ~/.zshrc\nsource <(kenso completion zsh)\n# bash: add this line to ~/.bashrc (on bash 3.2, the macOS default, use: eval "$(kenso completion bash)")\nsource <(kenso completion bash)\n# fish: save the script once\nkenso completion fish > ~/.config/fish/completions/kenso.fish\n```\n\n### Update notice\n\nWhen a newer version is out, `kenso` says so on stderr after the command\'s own output, at most once a week: `kenso 0.1.40 is out (you have 0.1.35): npm i -g kenso@latest`. It checks `registry.npmjs.org` at most once every 7 days and never delays a command by more than about a second. A standalone build checks `latest.yml` on `downloads.ken.so` instead and names its own update: the install script, or `brew upgrade kenso` when Homebrew installed it. It stays quiet when stderr is not a terminal, in CI (`CI` set) and under a coding agent. Set `KENSO_NO_UPDATE_NOTIFIER=1` to turn it off.\n\n## 60-second quickstart\n\n1. Create an API key in app.ken.so at Settings > Integrations > API keys.\n2. Save the key, pick a workspace, then plan and apply a CSV import:\n\n```bash\necho $KEY | kenso auth login --with-key\nkenso workspace list --search acme\nkenso workspace use 1234\nkenso campaigns list --limit 5\nkenso contacts import --campaign 812 --file leads.csv --dry-run\nkenso contacts import --campaign 812 --file leads.csv --yes\n```\n\n`workspace list` and `workspace use` are only needed when your key reaches more than one workspace.\n\nThe dry run reads the file, maps the columns, checks every row, asks Kenso for a credit estimate, and writes nothing. It prints the plan, with the exact apply command in `next`:\n\n```json\n{"run":"r_tdi5cdnx","dryRun":true,"command":"contacts import","rows":4,"valid":2,"invalid":2,"chunks":1,"chunkSize":1000,"campaignId":812,"mapping":{"Email":"email","First Name":"firstName","Last Name":"lastName","Company":"companyName","Pain Point":"customVariables.pain_point"},"customVariableKeys":["pain_point"],"estimate":{"kind":"leads","totalMillicredits":2000,"availableMillicredits":500000,"sufficient":true},"credits":{"needed":2,"available":500,"sufficient":true},"next":"kenso contacts import --campaign 812 --file leads.csv --yes","plan":"/home/you/.kenso/runs/r_tdi5cdnx/plan.json","invalidRows":"/home/you/.kenso/runs/r_tdi5cdnx/invalid.csv"}\n```\n\nThe apply sends the rows and prints one summary. Every input row has one line in `results.csv`:\n\n```json\n{"run":"r_tdi5cdnx","rows":4,"ok":0,"created":1,"updated":0,"skipped":{"duplicate":1},"failed":0,"notFound":0,"invalid":2,"changed":1,"results":"/home/you/.kenso/runs/r_tdi5cdnx/results.csv","resultsNdjson":"/home/you/.kenso/runs/r_tdi5cdnx/results.ndjson","invalidRows":"/home/you/.kenso/runs/r_tdi5cdnx/invalid.csv","resumed":false,"durationMs":1840,"campaignId":812,"notSendable":0}\n```\n\nThis run exits 5 because two rows were invalid: open `invalid.csv` to see why, fix those rows, and import them again. Running the same command again is safe: an email that is already in the campaign comes back `updated` or `skipped`, never as a second lead.\n\n## CLI or MCP\n\n- **Use the CLI for volume:** anything that starts from a file, anything over about 50 records, anything you may need to rerun or resume. Records never pass through the model\'s context: the agent passes a file path and reads a short summary.\n- **Use the MCP for conversation and single records:** look up a campaign, draft a reply, read a report. The MCP is at `https://mcp.ken.so/mcp`, signs in with OAuth and needs no install ([connection guide](https://ken.so/mcp)).\n- **Both use the same API and the same permissions.** `kenso mcp call` reaches MCP-only tools, such as skills, from the shell.\n\n## Docs\n\nEvery page is in the package and prints offline with `kenso docs <topic>`.\n\n| Page | Topic | What it covers |\n|---|---|---|\n| [Authentication](auth.md) | `auth` | API keys, browser login, profiles, workspaces, `doctor` |\n| [Leads](leads.md) | `leads` | Import, update, remove, pause, tag and export leads, with recipes |\n| [Batch runs](batch.md) | `batch` | Dry run and apply, run folders, results files, resume, rate limits, `--each` |\n| [Output and errors](output-and-errors.md) | `output-and-errors` | The output contract, error JSON, error codes, exit codes |\n| [CRM (beta)](crm.md) | `crm` | Accounts, people, opportunities and CRM sync |\n| [Studio (beta)](studio.md) | `studio` | Pull, push, validate, preview and fill templates |\n| [Agent work (beta)](work.md) | `work` | My agent: your own coding agent writes Kenso\'s AI work with `kenso work run`, or pull and submit |\n| [Webhooks](webhooks.md) | `webhooks` | Build a webhook handler locally: `kenso webhooks listen --forward-to`, `trigger`, the signature |\n| [Developer sandbox](sandbox.md) | `sandbox` | `kenso sandbox`: a workspace of your own where sends are simulated, its test key, the reserved test leads |\n| [Coding agents](agents.md) | `agents` | Claude Code, Codex, Cursor, the Agent Skill, environment variables, sandboxes |\n| Command reference | `reference` | Every command with its flags, generated from the CLI at build time: `kenso docs reference`, or `docs/reference.md` in the installed package |\n\n```bash\nkenso docs\nkenso docs leads\n```\n\nFor machine-readable help, run `kenso describe`: it prints every command, its flags and its body schema as JSON.\n';
|
|
7604
|
+
README_default = '# Kenso CLI\n\nThe Kenso CLI (`kenso`) is the command line for Kenso. It does bulk work in your Kenso workspace from files: add thousands of leads to a campaign, update or clean them up, import accounts and people, and build Studio templates. It is made for coding agents (Claude Code, Codex, Cursor) and the people who drive them: JSON on stdout, fixed exit codes, a dry run before every bulk write, and runs you can resume.\n\nEvery API operation a workspace member can call is also a command, such as `kenso campaigns list` or `kenso tags create`. So the CLI reaches what the Kenso MCP reaches, straight against `https://api.ken.so`.\n\n## Install\n\nOn macOS or Linux, with or without Node, run the [install script](https://ken.so/install.sh): fetch it with `curl -fsSL` and pipe it to `sh`. It installs a standalone build that brings its own Node.js, checks the download against the release\'s `SHA256SUMS`, puts the CLI in `~/.local/share/kenso` and links `~/.local/bin/kenso`. Run it again to update.\n\nWith Homebrew, on macOS or Linux, the same standalone build:\n\n```bash\nbrew install ken-technology/tap/kenso\n```\n\n`brew upgrade kenso` updates it.\n\nWith Node 22 or newer, on any system, Windows included:\n\n```bash\nnpm i -g kenso\nkenso --version\n```\n\nTo run it once without installing, use `npx kenso --version`. On an older Node, kenso stops with one line that says so.\n\nEvery way to install:\n\n| Way | Systems | Needs |\n|---|---|---|\n| Install script, above | macOS, Linux (glibc) | Nothing |\n| Homebrew, above | macOS, Linux | Homebrew |\n| npm, above | Any | Node 22 or newer |\n| Standalone build: unpack it and put its `bin` folder on your PATH | macOS, Linux, Windows | Nothing |\n\nThe standalone builds are at `https://downloads.ken.so/desktop/cli/<version>/`, one per system: `kenso-<version>-darwin-arm64.tar.gz`, `darwin-x64`, `linux-arm64`, `linux-x64` and `kenso-<version>-windows-x64.zip`, with their `SHA256SUMS`. `https://downloads.ken.so/desktop/cli/latest.yml` names the newest version. The builds come out nightly and Homebrew follows them, so a command added that day reaches npm first.\n\n### Tab completion\n\nTab completes resources, actions and flags once you install the script for your shell. The script asks `kenso` for the candidates on each Tab, so it stays right as the CLI updates: install it once.\n\n```bash\n# zsh: add this line to ~/.zshrc\nsource <(kenso completion zsh)\n# bash: add this line to ~/.bashrc (on bash 3.2, the macOS default, use: eval "$(kenso completion bash)")\nsource <(kenso completion bash)\n# fish: save the script once\nkenso completion fish > ~/.config/fish/completions/kenso.fish\n```\n\n### Update notice\n\nWhen a newer version is out, `kenso` says so on stderr after the command\'s own output, at most once a week: `kenso 0.1.40 is out (you have 0.1.35): npm i -g kenso@latest`. It checks `registry.npmjs.org` at most once every 7 days and never delays a command by more than about a second. A standalone build checks `latest.yml` on `downloads.ken.so` instead and names its own update: the install script, or `brew upgrade kenso` when Homebrew installed it. It stays quiet when stderr is not a terminal, in CI (`CI` set) and under a coding agent. Set `KENSO_NO_UPDATE_NOTIFIER=1` to turn it off.\n\n## 60-second quickstart\n\n1. Create an API key in app.ken.so at Settings > Integrations > API keys.\n2. Save the key, pick a workspace, then plan and apply a CSV import:\n\n```bash\necho $KEY | kenso auth login --with-key\nkenso workspace list --search acme\nkenso workspace use 1234\nkenso campaigns list --limit 5\nkenso contacts import --campaign 812 --file leads.csv --dry-run\nkenso contacts import --campaign 812 --file leads.csv --yes\n```\n\n`workspace list` and `workspace use` are only needed when your key reaches more than one workspace.\n\nThe dry run reads the file, maps the columns, checks every row, asks Kenso for a credit estimate, and writes nothing. It prints the plan, with the exact apply command in `next`:\n\n```json\n{"run":"r_tdi5cdnx","dryRun":true,"command":"contacts import","rows":4,"valid":2,"invalid":2,"chunks":1,"chunkSize":1000,"campaignId":812,"mapping":{"Email":"email","First Name":"firstName","Last Name":"lastName","Company":"companyName","Pain Point":"customVariables.pain_point"},"customVariableKeys":["pain_point"],"estimate":{"kind":"leads","totalMillicredits":2000,"availableMillicredits":500000,"sufficient":true},"credits":{"needed":2,"available":500,"sufficient":true},"next":"kenso contacts import --campaign 812 --file leads.csv --yes","plan":"/home/you/.kenso/runs/r_tdi5cdnx/plan.json","invalidRows":"/home/you/.kenso/runs/r_tdi5cdnx/invalid.csv"}\n```\n\nThe apply sends the rows and prints one summary. Every input row has one line in `results.csv`:\n\n```json\n{"run":"r_tdi5cdnx","rows":4,"ok":0,"created":1,"updated":0,"skipped":{"duplicate":1},"failed":0,"notFound":0,"invalid":2,"changed":1,"results":"/home/you/.kenso/runs/r_tdi5cdnx/results.csv","resultsNdjson":"/home/you/.kenso/runs/r_tdi5cdnx/results.ndjson","invalidRows":"/home/you/.kenso/runs/r_tdi5cdnx/invalid.csv","resumed":false,"durationMs":1840,"campaignId":812,"notSendable":0}\n```\n\nThis run exits 5 because two rows were invalid: open `invalid.csv` to see why, fix those rows, and import them again. Running the same command again is safe: an email that is already in the campaign comes back `updated` or `skipped`, never as a second lead.\n\n## CLI or MCP\n\n- **Use the CLI for volume:** anything that starts from a file, anything over about 50 records, anything you may need to rerun or resume. Records never pass through the model\'s context: the agent passes a file path and reads a short summary.\n- **Use the MCP for conversation and single records:** look up a campaign, draft a reply, read a report. The MCP is at `https://mcp.ken.so/mcp`, signs in with OAuth and needs no install ([connection guide](https://ken.so/mcp)).\n- **Both use the same API and the same permissions.** `kenso mcp call` reaches MCP-only tools, such as skills, from the shell.\n\n## Docs\n\nEvery page is in the package and prints offline with `kenso docs <topic>`.\n\n| Page | Topic | What it covers |\n|---|---|---|\n| [Authentication](auth.md) | `auth` | API keys, browser login, profiles, workspaces, `doctor` |\n| [Leads](leads.md) | `leads` | Import, update, remove, pause, tag and export leads, with recipes |\n| [Batch runs](batch.md) | `batch` | Dry run and apply, run folders, results files, resume, rate limits, `--each` |\n| [Output and errors](output-and-errors.md) | `output-and-errors` | The output contract, error JSON, error codes, exit codes, live streams |\n| [CRM (beta)](crm.md) | `crm` | Accounts, people, opportunities and CRM sync |\n| [Studio (beta)](studio.md) | `studio` | Pull, push, validate, preview and fill templates |\n| [Agent work (beta)](work.md) | `work` | My agent: your own coding agent writes Kenso\'s AI work with `kenso work run`, or pull and submit |\n| [Webhooks](webhooks.md) | `webhooks` | Build a webhook handler locally: `kenso webhooks listen --forward-to`, `trigger`, the signature |\n| [Developer sandbox](sandbox.md) | `sandbox` | `kenso sandbox`: a workspace of your own where sends are simulated, its test key, the reserved test leads |\n| [Connect accounts](connect.md) | `connect` | `kenso connect`: an inbox, calendar, CRM, GitHub or other OAuth account, signed in by the person in a browser |\n| [Coding agents](agents.md) | `agents` | Claude Code, Codex, Cursor, the Agent Skill, environment variables, sandboxes |\n| Command reference | `reference` | Every command with its flags, generated from the CLI at build time: `kenso docs reference`, or `docs/reference.md` in the installed package |\n\n```bash\nkenso docs\nkenso docs leads\n```\n\nFor machine-readable help, run `kenso describe`: it prints every command, its flags and its body schema as JSON.\n';
|
|
7294
7605
|
}
|
|
7295
7606
|
});
|
|
7296
7607
|
|
|
@@ -7330,7 +7641,7 @@ var init_work = __esm({
|
|
|
7330
7641
|
var SKILL_default;
|
|
7331
7642
|
var init_SKILL = __esm({
|
|
7332
7643
|
"skill/kenso-cli/SKILL.md"() {
|
|
7333
|
-
SKILL_default = '---\nname: kenso-cli\ndescription: The Kenso CLI (kenso) for work from a file (of any size, even a few ids) or over about 50 records - import, update, remove (delete), pause, tag or export leads, import CRM accounts and people, edit Studio templates as local files and fill them, run an API operation per file row, resume an interrupted run, write the Kenso AI work a workspace gave to its own coding agent (My agent, with kenso work run, or work pull and submit with subagents), sign in with a key from a variable (pipe it to kenso auth login --with-key, no check first). For records listed in the message (under about 50), one record or a question, use the Kenso MCP.\n---\n\n1. Every write runs first with `--dry-run`; apply with the plan\'s `next` (a delete, archive or remove applies with `--yes`). `--yes` at once only to continue an interrupted run or apply what the person confirmed. A command with no dry run refuses `--dry-run` (exit 2, nothing ran): read its `--help`, then run it without.\n2. Many rows: one command on the file as it is (`--file`, `--ids`, `--each`). Run kenso only: no python, awk or shell tests, not even on a file or variable.\n3. Any output\'s `next` is the command to run; errors are JSON on stderr. `--force` only with the person\'s OK.\n4. Ids are flags: `--campaign-id 812` (or `--campaign 812`, the same flag). `--workspace <id>`; by name `kenso workspace list --search acme`. `--json` is `-o json`; `--query` takes JMESPath (there is no `--jq`). Other commands: `kenso --help`; `kenso api <METHOD> <path>` only when none fits.\n\n```bash\nkenso contacts import --campaign 812 --file leads.csv --dry-run # skips leads already in; --map \'{"Pain": "customVariables.pain_point", "Notes": null}\'; over 200 MB --server-import\nkenso contacts update --file edits.csv --match id --dry-run # also one lead; or --match email --campaign 812\nkenso contacts remove --ids ids.txt --dry-run # also pause, resume, restore; over 1,000: --confirm <count>\nkenso contacts remove --where \'{"campaignIds": [812], "filters": [{"conditions": {"field": "ContactCompany.Name", "operator": 2, "value": "acme"}}]}\' --dry-run # also pause, resume; 2 = contains; no search first\nkenso contacts tag --tag 31 --ids ids.txt --dry-run # tag, restore: --ids only, so first kenso contacts list --campaign-id 812 --all -o ids > ids.txt\nkenso contact-imports create --source campaign --source-campaign-id 10601 --campaign-id 812 --dry-run # copy another campaign\'s leads in\nkenso contacts export --campaign 812 --out leads.csv # a segment: kenso contact-exports create --segment-id 55\nkenso runs resume <runId> # an interrupted run; terminal lost: kenso runs list finds it. A changed file is a new run\nkenso accounts import --file accounts.csv --dry-run # companies; a file of people: kenso people import --file people.csv\nkenso studio push 12 --dir ./tpl # to preview local edits push first (draft; live needs --publish), then studio preview 12\nkenso studio fill 12 --accounts ids.txt --dry-run # or --campaign 10546 --contacts leads.csv\nkenso opportunities update --each rows.csv --dry-run # any API command on a file of rows (CSV or JSONL; keys fill flags and body). One record: kenso campaigns update --campaign-id 812 --name Q4 --dry-run\nkenso mcp call list_skills # only to list Ken\'s skills\nkenso logs tail --status 4xx,5xx --since 10m # stream the workspace\'s failed API calls, one line each; Ctrl-C stops (exit 4 = not on for the workspace yet)\n```\n\nCharges: `accounts import` per new account, `studio fill` per page (again for ids from another file): show the estimate. `pinned_by_user`: with the person\'s OK, rerun with `--overwrite-pinned`. Workflows: `kenso workflows brief` first; secrets only as `{{secrets.NAME}}`. Key: `KENSO_API_KEY`, or pipe a variable, no check: `printf \'%s\' "$KEY" | kenso auth login --with-key`; never in a flag, output or file.\n\n## Work (beta): My agent\n\nA workspace can set a kind of Kenso AI work (personalization, qualification, segmentation, rewriting, meeting brief, call brief, workflow prompt) to My agent in Settings > AI work: then it waits for the person\'s own coding agent, at 0 Kenso AI credits. The `kenso work` commands take no `--dry-run`. Never read the items\' text into the chat: the files carry it.\n\n```bash\nkenso work status # what waits, per kind\nkenso work run --agent claude # does it all: claims, runs headless agents, submits; stops when the queue is empty. Other agents need --allow-unconfined; exit 6 = the plan\'s usage limit\nkenso work pull --files 4 --per-file 10 # by hand: prints the work file paths, never the items\nkenso work submit <dir>/*.answers.json # pull\'s next; exit 5 = some answers rejected (see each <claimId>.results.json)\nkenso work release <claimId> # give back work you will not finish\n```\n\nBy hand in a chat: run `kenso work pull`, then give each work file to its own subagent with only its path ("Read this work file and write its answers file as its rules say"), then run pull\'s `next`. More: `kenso docs work`.\n\n## Setup\n\n`kenso` missing: `curl -fsSL https://ken.so/install.sh | sh` (macOS or Linux, no Node needed) or `npm i -g kenso` (Node 22 or newer), or run a command as `npx -y kenso@latest <command>`. Then `kenso auth login` (the person approves in the browser) and `kenso doctor`. `kenso agent setup -y` installs this skill and the Kenso MCP server (`https://mcp.ken.so/mcp`) for the agent; the person signs in to the MCP once in the agent.\n\n## No Kenso account yet\n\nThe CLI signs in with a Kenso API key. If the user has no Kenso account, send them to https://app.ken.so/get-started to create one, then create a key in Kenso at Settings > Integrations > API keys.\n';
|
|
7644
|
+
SKILL_default = '---\nname: kenso-cli\ndescription: The Kenso CLI (kenso) for work from a file (of any size, even a few ids) or over about 50 records - import, update, remove (delete), pause, tag or export leads, import CRM accounts and people, edit Studio templates as local files and fill them, run an API operation per file row, resume an interrupted run, write the Kenso AI work a workspace gave to its own coding agent (My agent, with kenso work run, or work pull and submit with subagents), sign in with a key from a variable (pipe it to kenso auth login --with-key, no check first). For records listed in the message (under about 50), one record or a question, use the Kenso MCP.\n---\n\n1. Every write runs first with `--dry-run`; apply with the plan\'s `next` (a delete, archive or remove applies with `--yes`). `--yes` at once only to continue an interrupted run or apply what the person confirmed. A command with no dry run refuses `--dry-run` (exit 2, nothing ran): read its `--help`, then run it without.\n2. Many rows: one command on the file as it is (`--file`, `--ids`, `--each`). Run kenso only: no python, awk or shell tests, not even on a file or variable.\n3. Any output\'s `next` is the command to run; errors are JSON on stderr. `--force` only with the person\'s OK.\n4. Ids are flags: `--campaign-id 812` (or `--campaign 812`, the same flag). `--workspace <id>`; by name `kenso workspace list --search acme`. `--json` is `-o json`; `--query` takes JMESPath (there is no `--jq`). Other commands: `kenso --help`; `kenso api <METHOD> <path>` only when none fits.\n\n```bash\nkenso contacts import --campaign 812 --file leads.csv --dry-run # skips leads already in; --map \'{"Pain": "customVariables.pain_point", "Notes": null}\'; over 200 MB --server-import\nkenso contacts update --file edits.csv --match id --dry-run # also one lead; or --match email --campaign 812\nkenso contacts remove --ids ids.txt --dry-run # also pause, resume, restore; over 1,000: --confirm <count>\nkenso contacts remove --where \'{"campaignIds": [812], "filters": [{"conditions": {"field": "ContactCompany.Name", "operator": 2, "value": "acme"}}]}\' --dry-run # also pause, resume; 2 = contains; no search first\nkenso contacts tag --tag 31 --ids ids.txt --dry-run # tag, restore: --ids only, so first kenso contacts list --campaign-id 812 --all -o ids > ids.txt\nkenso contact-imports create --source campaign --source-campaign-id 10601 --campaign-id 812 --dry-run # copy another campaign\'s leads in\nkenso contacts export --campaign 812 --out leads.csv # a segment: kenso contact-exports create --segment-id 55\nkenso runs resume <runId> # an interrupted run; terminal lost: kenso runs list finds it. A changed file is a new run\nkenso accounts import --file accounts.csv --dry-run # companies; a file of people: kenso people import --file people.csv\nkenso studio push 12 --dir ./tpl # to preview local edits push first (draft; live needs --publish), then studio preview 12\nkenso studio fill 12 --accounts ids.txt --dry-run # or --campaign 10546 --contacts leads.csv\nkenso opportunities update --each rows.csv --dry-run # any API command on a file of rows (CSV or JSONL; keys fill flags and body). One record: kenso campaigns update --campaign-id 812 --name Q4 --dry-run\nkenso mcp call list_skills # only to list Ken\'s skills\nkenso logs tail --status 4xx,5xx --since 10m # stream the workspace\'s failed API calls, one line each; Ctrl-C stops (exit 4 = not on for the workspace yet)\nkenso connect inbox --provider google # also calendar, crm, github, linkedin ...: hand the printed link to the person (only they can sign in), it waits and prints the connection\nkenso onboarding-builds events --build-id obd_2x --until done,error # live streams: one JSON line per event, reconnects itself\n```\n\nCharges: `accounts import` per new account, `studio fill` per page (again for ids from another file): show the estimate. `pinned_by_user`: with the person\'s OK, rerun with `--overwrite-pinned`. Workflows: `kenso workflows brief` first; secrets only as `{{secrets.NAME}}`. Key: `KENSO_API_KEY`, or pipe a variable, no check: `printf \'%s\' "$KEY" | kenso auth login --with-key`; never in a flag, output or file.\n\n## Work (beta): My agent\n\nA workspace can set a kind of Kenso AI work (personalization, qualification, segmentation, rewriting, meeting brief, call brief, workflow prompt) to My agent in Settings > AI work: then it waits for the person\'s own coding agent, at 0 Kenso AI credits. The `kenso work` commands take no `--dry-run`. Never read the items\' text into the chat: the files carry it.\n\n```bash\nkenso work status # what waits, per kind\nkenso work run --agent claude # does it all: claims, runs headless agents, submits; stops when the queue is empty. Other agents need --allow-unconfined; exit 6 = the plan\'s usage limit\nkenso work pull --files 4 --per-file 10 # by hand: prints the work file paths, never the items\nkenso work submit <dir>/*.answers.json # pull\'s next; exit 5 = some answers rejected (see each <claimId>.results.json)\nkenso work release <claimId> # give back work you will not finish\n```\n\nBy hand in a chat: run `kenso work pull`, then give each work file to its own subagent with only its path ("Read this work file and write its answers file as its rules say"), then run pull\'s `next`. More: `kenso docs work`.\n\n## Setup\n\n`kenso` missing: `curl -fsSL https://ken.so/install.sh | sh` (macOS or Linux, no Node needed) or `npm i -g kenso` (Node 22 or newer), or run a command as `npx -y kenso@latest <command>`. Then `kenso auth login` (the person approves in the browser) and `kenso doctor`. `kenso agent setup -y` installs this skill and the Kenso MCP server (`https://mcp.ken.so/mcp`) for the agent; the person signs in to the MCP once in the agent.\n\n## No Kenso account yet\n\nThe CLI signs in with a Kenso API key. If the user has no Kenso account, send them to https://app.ken.so/get-started to create one, then create a key in Kenso at Settings > Integrations > API keys.\n';
|
|
7334
7645
|
}
|
|
7335
7646
|
});
|
|
7336
7647
|
|
|
@@ -7347,6 +7658,7 @@ var init_embedded = __esm({
|
|
|
7347
7658
|
init_agents();
|
|
7348
7659
|
init_auth();
|
|
7349
7660
|
init_batch();
|
|
7661
|
+
init_connect();
|
|
7350
7662
|
init_crm();
|
|
7351
7663
|
init_leads();
|
|
7352
7664
|
init_output_and_errors();
|
|
@@ -7367,6 +7679,7 @@ var init_embedded = __esm({
|
|
|
7367
7679
|
"work.md": work_default,
|
|
7368
7680
|
"webhooks.md": webhooks_default,
|
|
7369
7681
|
"sandbox.md": sandbox_default,
|
|
7682
|
+
"connect.md": connect_default,
|
|
7370
7683
|
"agents.md": agents_default
|
|
7371
7684
|
};
|
|
7372
7685
|
SKILL = SKILL_default;
|
|
@@ -7399,12 +7712,13 @@ var init_content = __esm({
|
|
|
7399
7712
|
{ topic: "auth", file: "auth.md", title: "Authentication", description: "API keys, browser login, profiles, workspaces, doctor" },
|
|
7400
7713
|
{ topic: "leads", file: "leads.md", title: "Leads", description: "Import, update, remove, pause, tag and export leads, with recipes" },
|
|
7401
7714
|
{ topic: "batch", file: "batch.md", title: "Batch runs", description: "Dry run and apply, run folders, results files, resume, rate limits, --each" },
|
|
7402
|
-
{ topic: "output-and-errors", file: "output-and-errors.md", title: "Output and errors", description: "The output contract, error JSON, error codes, exit codes" },
|
|
7715
|
+
{ topic: "output-and-errors", file: "output-and-errors.md", title: "Output and errors", description: "The output contract, error JSON, error codes, exit codes, live streams" },
|
|
7403
7716
|
{ topic: "crm", file: "crm.md", title: "CRM (beta)", description: "Accounts, people, opportunities and CRM sync" },
|
|
7404
7717
|
{ topic: "studio", file: "studio.md", title: "Studio (beta)", description: "Pull, push, validate, preview and fill templates" },
|
|
7405
7718
|
{ topic: "work", file: "work.md", title: "Agent work (beta)", description: "My agent: your own coding agent writes Kenso AI work with kenso work run, or pull and submit" },
|
|
7406
7719
|
{ topic: "webhooks", file: "webhooks.md", title: "Webhooks", description: "Build a webhook handler locally: kenso webhooks listen --forward-to, trigger, the signature" },
|
|
7407
7720
|
{ topic: "sandbox", file: "sandbox.md", title: "Developer sandbox", description: "kenso sandbox: a workspace of your own where sends are simulated, its test key, the reserved test leads" },
|
|
7721
|
+
{ topic: "connect", file: "connect.md", title: "Connect accounts", description: "kenso connect: an inbox, calendar, CRM, GitHub or other OAuth account, signed in by the person in a browser" },
|
|
7408
7722
|
{ topic: "agents", file: "agents.md", title: "Coding agents", description: "kenso agent setup for Claude Code, Codex, Cursor, Gemini CLI and OpenCode, the Agent Skill, environment variables, sandboxes" },
|
|
7409
7723
|
{ topic: "reference", file: "reference.md", title: "Command reference", description: "Every command with its flags, generated from the CLI at build time" }
|
|
7410
7724
|
];
|
|
@@ -7417,11 +7731,11 @@ var init_content = __esm({
|
|
|
7417
7731
|
function isRecord4(value) {
|
|
7418
7732
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
7419
7733
|
}
|
|
7420
|
-
function parseJson(
|
|
7734
|
+
function parseJson(text4) {
|
|
7421
7735
|
try {
|
|
7422
|
-
return JSON.parse(
|
|
7736
|
+
return JSON.parse(text4);
|
|
7423
7737
|
} catch {
|
|
7424
|
-
return
|
|
7738
|
+
return text4;
|
|
7425
7739
|
}
|
|
7426
7740
|
}
|
|
7427
7741
|
function eventData(event) {
|
|
@@ -7529,8 +7843,8 @@ var init_client = __esm({
|
|
|
7529
7843
|
}
|
|
7530
7844
|
async notify(method, params) {
|
|
7531
7845
|
const res = await this.post(method, { jsonrpc: "2.0", method, ...params ? { params } : {} });
|
|
7532
|
-
const
|
|
7533
|
-
if (!res.ok) throw errorFromResponse(res.status, parseJson(
|
|
7846
|
+
const text4 = await res.text();
|
|
7847
|
+
if (!res.ok) throw errorFromResponse(res.status, parseJson(text4));
|
|
7534
7848
|
}
|
|
7535
7849
|
async rpc(method, params) {
|
|
7536
7850
|
const id = this.nextId++;
|
|
@@ -7555,9 +7869,9 @@ var init_client = __esm({
|
|
|
7555
7869
|
}
|
|
7556
7870
|
return message.result;
|
|
7557
7871
|
}
|
|
7558
|
-
findInJson(
|
|
7559
|
-
if (
|
|
7560
|
-
return asMessages(parseJson(
|
|
7872
|
+
findInJson(text4, id) {
|
|
7873
|
+
if (text4.trim() === "") return void 0;
|
|
7874
|
+
return asMessages(parseJson(text4)).find((m) => m.id === id);
|
|
7561
7875
|
}
|
|
7562
7876
|
/** Reads SSE events until the message answering `id` arrives, then stops reading. */
|
|
7563
7877
|
async readSse(res, id) {
|
|
@@ -7661,11 +7975,11 @@ function readExisting(path) {
|
|
|
7661
7975
|
throw new KensoError({ code: "file_unreadable", message: `Cannot read ${path}${code ? ` (${code})` : ""}.`, exitCode: ExitCode.Usage });
|
|
7662
7976
|
}
|
|
7663
7977
|
}
|
|
7664
|
-
function write(path,
|
|
7978
|
+
function write(path, text4) {
|
|
7665
7979
|
try {
|
|
7666
7980
|
mkdirSync3(dirname(path), { recursive: true });
|
|
7667
7981
|
const temp = `${path}.${process.pid}.tmp`;
|
|
7668
|
-
writeFileSync3(temp,
|
|
7982
|
+
writeFileSync3(temp, text4);
|
|
7669
7983
|
renameSync3(temp, path);
|
|
7670
7984
|
} catch (err) {
|
|
7671
7985
|
const code = err.code;
|
|
@@ -7714,11 +8028,11 @@ var init_install = __esm({
|
|
|
7714
8028
|
throw usageError(`--client must be one of ${CLIENT_CHOICES.join(", ")} (got "${clientFlag}").`, { field: "client", next: "kenso skill install --help" });
|
|
7715
8029
|
}
|
|
7716
8030
|
const client = clientFlag ?? (ctx.agent ? AGENT_CLIENTS2[ctx.agent.name] : void 0) ?? "all";
|
|
7717
|
-
const
|
|
8031
|
+
const text4 = await skillText();
|
|
7718
8032
|
const targets = folders(ctx, client, dir).map(({ client: c, folder }) => {
|
|
7719
8033
|
const path = join8(folder, "SKILL.md");
|
|
7720
8034
|
const existing = readExisting(path);
|
|
7721
|
-
const status = existing === void 0 ? "created" : existing ===
|
|
8035
|
+
const status = existing === void 0 ? "created" : existing === text4 ? "unchanged" : "replaced";
|
|
7722
8036
|
return { client: c, path, status };
|
|
7723
8037
|
});
|
|
7724
8038
|
const conflicts = targets.filter((t) => t.status === "replaced");
|
|
@@ -7739,7 +8053,7 @@ var init_install = __esm({
|
|
|
7739
8053
|
});
|
|
7740
8054
|
}
|
|
7741
8055
|
for (const target of targets) {
|
|
7742
|
-
if (target.status !== "unchanged") write(target.path,
|
|
8056
|
+
if (target.status !== "unchanged") write(target.path, text4);
|
|
7743
8057
|
}
|
|
7744
8058
|
if (dir !== void 0 && basename2(resolve4(dir)) !== SKILL_NAME) {
|
|
7745
8059
|
ctx.output.warn(`Agents expect the skill's folder to be named ${SKILL_NAME}, like the skill: ${resolve4(dir)} is not.`);
|
|
@@ -7756,28 +8070,28 @@ var init_install = __esm({
|
|
|
7756
8070
|
import { spawnSync } from "node:child_process";
|
|
7757
8071
|
import { existsSync as existsSync4, readFileSync as readFileSync8 } from "node:fs";
|
|
7758
8072
|
import { delimiter, join as join9 } from "node:path";
|
|
7759
|
-
function parse2(
|
|
8073
|
+
function parse2(text4) {
|
|
7760
8074
|
try {
|
|
7761
|
-
const doc = JSON.parse(
|
|
8075
|
+
const doc = JSON.parse(text4);
|
|
7762
8076
|
return isDoc(doc) ? doc : void 0;
|
|
7763
8077
|
} catch {
|
|
7764
8078
|
return void 0;
|
|
7765
8079
|
}
|
|
7766
8080
|
}
|
|
7767
|
-
function stripJsonc(
|
|
8081
|
+
function stripJsonc(text4) {
|
|
7768
8082
|
let out = "";
|
|
7769
|
-
for (let i = 0; i <
|
|
7770
|
-
const ch =
|
|
8083
|
+
for (let i = 0; i < text4.length; i++) {
|
|
8084
|
+
const ch = text4[i];
|
|
7771
8085
|
if (ch === '"') {
|
|
7772
|
-
const str = /^"(?:[^"\\]|\\.)*"/.exec(
|
|
8086
|
+
const str = /^"(?:[^"\\]|\\.)*"/.exec(text4.slice(i))?.[0] ?? text4.slice(i);
|
|
7773
8087
|
out += str;
|
|
7774
8088
|
i += str.length - 1;
|
|
7775
|
-
} else if (ch === "/" &&
|
|
7776
|
-
while (i <
|
|
8089
|
+
} else if (ch === "/" && text4[i + 1] === "/") {
|
|
8090
|
+
while (i < text4.length && text4[i] !== "\n") i++;
|
|
7777
8091
|
out += "\n";
|
|
7778
|
-
} else if (ch === "/" &&
|
|
7779
|
-
const close =
|
|
7780
|
-
i = close === -1 ?
|
|
8092
|
+
} else if (ch === "/" && text4[i + 1] === "*") {
|
|
8093
|
+
const close = text4.indexOf("*/", i + 2);
|
|
8094
|
+
i = close === -1 ? text4.length : close + 1;
|
|
7781
8095
|
} else {
|
|
7782
8096
|
out += ch;
|
|
7783
8097
|
}
|
|
@@ -7792,14 +8106,14 @@ function servers(record, keys = ["url"]) {
|
|
|
7792
8106
|
return typeof url === "string" ? [{ name, url }] : [];
|
|
7793
8107
|
});
|
|
7794
8108
|
}
|
|
7795
|
-
function mcpServersOf(
|
|
7796
|
-
const doc = readJson2(
|
|
8109
|
+
function mcpServersOf(text4, keys) {
|
|
8110
|
+
const doc = readJson2(text4);
|
|
7797
8111
|
return doc === void 0 ? void 0 : servers(doc.mcpServers, keys);
|
|
7798
8112
|
}
|
|
7799
|
-
function tomlServers(
|
|
8113
|
+
function tomlServers(text4) {
|
|
7800
8114
|
const entries2 = [];
|
|
7801
8115
|
let name;
|
|
7802
|
-
for (const line of
|
|
8116
|
+
for (const line of text4.split(/\r?\n/)) {
|
|
7803
8117
|
const header = /^\s*\[([^\]]+)\]\s*(#.*)?$/.exec(line);
|
|
7804
8118
|
if (header) {
|
|
7805
8119
|
const m = /^mcp_servers\.(?:"([^"]+)"|'([^']+)'|([A-Za-z0-9_-]+))$/.exec(header[1].trim());
|
|
@@ -7849,9 +8163,9 @@ function manualStep(client, env, url) {
|
|
|
7849
8163
|
function mcpState(client, env, url) {
|
|
7850
8164
|
const t = TARGETS[client];
|
|
7851
8165
|
const file = t.file(env);
|
|
7852
|
-
const
|
|
7853
|
-
if (
|
|
7854
|
-
const entries2 = t.entries(
|
|
8166
|
+
const text4 = readText(file);
|
|
8167
|
+
if (text4 === void 0) return { status: "missing", file };
|
|
8168
|
+
const entries2 = t.entries(text4);
|
|
7855
8169
|
if (entries2 === void 0) return { status: "unknown", file, detail: `${file} could not be read as JSON` };
|
|
7856
8170
|
const match = entries2.find((e) => canonical(e.url) === canonical(url));
|
|
7857
8171
|
if (match) return { status: "registered", file, name: match.name };
|
|
@@ -7878,10 +8192,10 @@ function addMcp(client, env, url) {
|
|
|
7878
8192
|
const after = mcpState(client, env, url);
|
|
7879
8193
|
return after.status === "registered" ? { ...after, status: "added" } : { ...state, status: "failed", detail: `${bin} answered OK but ${t.file(env)} does not list kenso`, next };
|
|
7880
8194
|
}
|
|
7881
|
-
const
|
|
7882
|
-
const doc =
|
|
8195
|
+
const text4 = readText(state.file);
|
|
8196
|
+
const doc = text4 === void 0 || text4.trim() === "" ? {} : parse2(text4);
|
|
7883
8197
|
if (doc === void 0) return { ...state, status: "skipped", detail: `${state.file} is not plain JSON, so it was left as it is`, next };
|
|
7884
|
-
if (
|
|
8198
|
+
if (text4 === void 0 && client === "opencode") doc.$schema = "https://opencode.ai/config.json";
|
|
7885
8199
|
t.merge(doc, url);
|
|
7886
8200
|
write(state.file, `${JSON.stringify(doc, null, 2)}
|
|
7887
8201
|
`);
|
|
@@ -7898,14 +8212,14 @@ var init_mcp_config = __esm({
|
|
|
7898
8212
|
init_install();
|
|
7899
8213
|
SERVER_NAME = "kenso";
|
|
7900
8214
|
isDoc = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7901
|
-
readJson2 = (
|
|
8215
|
+
readJson2 = (text4) => parse2(text4) ?? parse2(stripJsonc(text4));
|
|
7902
8216
|
TARGETS = {
|
|
7903
8217
|
"claude-code": {
|
|
7904
8218
|
bins: ["claude"],
|
|
7905
8219
|
folder: claudeDir,
|
|
7906
8220
|
file: (env) => env.CLAUDE_CONFIG_DIR?.trim() ? join9(env.CLAUDE_CONFIG_DIR.trim(), ".claude.json") : join9(home(env), ".claude.json"),
|
|
7907
8221
|
// User scope only: that is where setup adds it, and it reaches every project.
|
|
7908
|
-
entries: (
|
|
8222
|
+
entries: (text4) => mcpServersOf(text4),
|
|
7909
8223
|
command: (url) => ["claude", "mcp", "add", "--scope", "user", "--transport", "http", SERVER_NAME, url],
|
|
7910
8224
|
signIn: "In Claude Code, run /mcp, select kenso and sign in."
|
|
7911
8225
|
},
|
|
@@ -7921,7 +8235,7 @@ var init_mcp_config = __esm({
|
|
|
7921
8235
|
bins: ["cursor", "cursor-agent"],
|
|
7922
8236
|
folder: (env) => join9(home(env), ".cursor"),
|
|
7923
8237
|
file: (env) => join9(home(env), ".cursor", "mcp.json"),
|
|
7924
|
-
entries: (
|
|
8238
|
+
entries: (text4) => mcpServersOf(text4),
|
|
7925
8239
|
merge: (doc, url) => {
|
|
7926
8240
|
const all = isDoc(doc.mcpServers) ? doc.mcpServers : doc.mcpServers = {};
|
|
7927
8241
|
all[SERVER_NAME] = { url };
|
|
@@ -7933,7 +8247,7 @@ var init_mcp_config = __esm({
|
|
|
7933
8247
|
folder: (env) => join9(home(env), ".gemini"),
|
|
7934
8248
|
file: (env) => join9(home(env), ".gemini", "settings.json"),
|
|
7935
8249
|
// httpUrl is Gemini CLI's Streamable HTTP key; url is SSE.
|
|
7936
|
-
entries: (
|
|
8250
|
+
entries: (text4) => mcpServersOf(text4, ["httpUrl", "url"]),
|
|
7937
8251
|
command: (url) => ["gemini", "mcp", "add", "--scope", "user", "--transport", "http", SERVER_NAME, url],
|
|
7938
8252
|
signIn: "In Gemini CLI, run /mcp auth kenso."
|
|
7939
8253
|
},
|
|
@@ -7942,8 +8256,8 @@ var init_mcp_config = __esm({
|
|
|
7942
8256
|
folder: (env) => join9(xdgConfigDir(env), "opencode"),
|
|
7943
8257
|
file: opencodeFile,
|
|
7944
8258
|
// OpenCode 1.x lists servers under mcp; newer configs nest them under mcp.servers.
|
|
7945
|
-
entries: (
|
|
7946
|
-
const doc = readJson2(
|
|
8259
|
+
entries: (text4) => {
|
|
8260
|
+
const doc = readJson2(text4);
|
|
7947
8261
|
if (doc === void 0) return void 0;
|
|
7948
8262
|
return [...servers(doc.mcp), ...isDoc(doc.mcp) ? servers(doc.mcp.servers) : []];
|
|
7949
8263
|
},
|
|
@@ -8021,11 +8335,11 @@ var init_setup = __esm({
|
|
|
8021
8335
|
const print = (value) => flags.json === true ? ctx.output.writeRaw(`${JSON.stringify(value, null, 2)}
|
|
8022
8336
|
`) : ctx.output.object(value);
|
|
8023
8337
|
const clients = pickClients(ctx, clientFlag, status);
|
|
8024
|
-
const
|
|
8338
|
+
const text4 = await skillText();
|
|
8025
8339
|
const rows = clients.map((client) => {
|
|
8026
8340
|
const path = join10(skillsFolder(client, ctx.env), SKILL_NAME, "SKILL.md");
|
|
8027
8341
|
const existing = readExisting(path);
|
|
8028
|
-
const skill = existing === void 0 ? "missing" : existing ===
|
|
8342
|
+
const skill = existing === void 0 ? "missing" : existing === text4 ? "installed" : "different";
|
|
8029
8343
|
return { client, present: isPresent(client, ctx.env), skill: { path, status: skill }, mcp: mcpState(client, ctx.env, url) };
|
|
8030
8344
|
});
|
|
8031
8345
|
const signIn = (row) => row.mcp.status === "registered" || row.mcp.status === "added" ? signInStep(row.client) : row.mcp.next;
|
|
@@ -8056,7 +8370,7 @@ var init_setup = __esm({
|
|
|
8056
8370
|
}
|
|
8057
8371
|
for (const row of rows) {
|
|
8058
8372
|
const was = row.skill.status;
|
|
8059
|
-
if (was !== "installed") write(row.skill.path,
|
|
8373
|
+
if (was !== "installed") write(row.skill.path, text4);
|
|
8060
8374
|
row.skill.status = was === "installed" ? "unchanged" : was === "different" ? "replaced" : "created";
|
|
8061
8375
|
row.mcp = addMcp(row.client, ctx.env, url);
|
|
8062
8376
|
row.next = signIn(row);
|
|
@@ -8142,10 +8456,10 @@ var init_api3 = __esm({
|
|
|
8142
8456
|
if (method === "GET" && typeof flags.data === "string") {
|
|
8143
8457
|
throw usageError("--data cannot be used with GET.", { field: "data", hint: "Put the values in the query string, or use POST, PUT or PATCH." });
|
|
8144
8458
|
}
|
|
8145
|
-
const
|
|
8459
|
+
const body2 = typeof flags.data === "string" ? await readDataArg(flags.data, ctx.stdin) : void 0;
|
|
8146
8460
|
const noWorkspace = flags["no-workspace"] === true;
|
|
8147
8461
|
if (ctx.flags.dryRun) {
|
|
8148
|
-
ctx.output.object({ dryRun: true, request: { method, path, ...
|
|
8462
|
+
ctx.output.object({ dryRun: true, request: { method, path, ...body2 !== void 0 ? { body: body2 } : {} } });
|
|
8149
8463
|
return ExitCode.Ok;
|
|
8150
8464
|
}
|
|
8151
8465
|
if (all) {
|
|
@@ -8156,7 +8470,7 @@ var init_api3 = __esm({
|
|
|
8156
8470
|
const quoted = /^[\w\-./]+$/.test(path) ? path : `'${path.replace(/'/g, `'\\''`)}'`;
|
|
8157
8471
|
await confirmDestructive(ctx, `kenso api sends DELETE ${path}`, `kenso api DELETE ${quoted} --yes`);
|
|
8158
8472
|
}
|
|
8159
|
-
const res = await ctx.client.request({ method, path, body, noWorkspace, signal: ctx.signal });
|
|
8473
|
+
const res = await ctx.client.request({ method, path, body: body2, noWorkspace, signal: ctx.signal });
|
|
8160
8474
|
if (res.body !== null && res.body !== "") ctx.output.object(res.body);
|
|
8161
8475
|
return ExitCode.Ok;
|
|
8162
8476
|
}
|
|
@@ -8180,6 +8494,37 @@ var init_api_key = __esm({
|
|
|
8180
8494
|
}
|
|
8181
8495
|
});
|
|
8182
8496
|
|
|
8497
|
+
// src/core/browser.ts
|
|
8498
|
+
function hasDisplay(env, platform) {
|
|
8499
|
+
if (platform === "darwin" || platform === "win32") return true;
|
|
8500
|
+
return Boolean(env.DISPLAY) || Boolean(env.WAYLAND_DISPLAY);
|
|
8501
|
+
}
|
|
8502
|
+
function openBrowser(url, deps) {
|
|
8503
|
+
let parsed2;
|
|
8504
|
+
try {
|
|
8505
|
+
parsed2 = new URL(url);
|
|
8506
|
+
} catch {
|
|
8507
|
+
return;
|
|
8508
|
+
}
|
|
8509
|
+
if (parsed2.protocol !== "https:" && parsed2.protocol !== "http:") return;
|
|
8510
|
+
try {
|
|
8511
|
+
if (deps.platform === "darwin") {
|
|
8512
|
+
deps.spawn("open", [url]);
|
|
8513
|
+
} else if (deps.platform === "win32") {
|
|
8514
|
+
if (/[&|^<>"%]/.test(url)) return;
|
|
8515
|
+
deps.spawn("cmd", ["/c", "start", "", url]);
|
|
8516
|
+
} else {
|
|
8517
|
+
deps.spawn("xdg-open", [url]);
|
|
8518
|
+
}
|
|
8519
|
+
} catch {
|
|
8520
|
+
}
|
|
8521
|
+
}
|
|
8522
|
+
var init_browser = __esm({
|
|
8523
|
+
"src/core/browser.ts"() {
|
|
8524
|
+
"use strict";
|
|
8525
|
+
}
|
|
8526
|
+
});
|
|
8527
|
+
|
|
8183
8528
|
// src/commands/auth/browser-login.ts
|
|
8184
8529
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
8185
8530
|
import { hostname as osHostname } from "node:os";
|
|
@@ -8213,8 +8558,8 @@ function deviceNameFor(opts, deps) {
|
|
|
8213
8558
|
function positiveNumber(value, fallback) {
|
|
8214
8559
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : fallback;
|
|
8215
8560
|
}
|
|
8216
|
-
function parseStarted(
|
|
8217
|
-
const data = unwrap(
|
|
8561
|
+
function parseStarted(body2, status) {
|
|
8562
|
+
const data = unwrap(body2);
|
|
8218
8563
|
if (!data || typeof data.loginId !== "string" || typeof data.userCode !== "string" || typeof data.verificationUrl !== "string") {
|
|
8219
8564
|
throw unexpected("the login start", status);
|
|
8220
8565
|
}
|
|
@@ -8226,8 +8571,8 @@ function parseStarted(body, status) {
|
|
|
8226
8571
|
interval: positiveNumber(data.interval, DEFAULT_INTERVAL)
|
|
8227
8572
|
};
|
|
8228
8573
|
}
|
|
8229
|
-
function parsePickedUp(
|
|
8230
|
-
const data = unwrap(
|
|
8574
|
+
function parsePickedUp(body2, status) {
|
|
8575
|
+
const data = unwrap(body2);
|
|
8231
8576
|
if (!data || typeof data.apiKey !== "string" || data.apiKey === "") throw unexpected("the login pickup", status);
|
|
8232
8577
|
const id = (value) => typeof value === "number" || typeof value === "string" ? value : void 0;
|
|
8233
8578
|
return {
|
|
@@ -8238,30 +8583,6 @@ function parsePickedUp(body, status) {
|
|
|
8238
8583
|
expiresAt: typeof data.expiresAt === "string" ? data.expiresAt : void 0
|
|
8239
8584
|
};
|
|
8240
8585
|
}
|
|
8241
|
-
function hasDisplay(env, platform) {
|
|
8242
|
-
if (platform === "darwin" || platform === "win32") return true;
|
|
8243
|
-
return Boolean(env.DISPLAY) || Boolean(env.WAYLAND_DISPLAY);
|
|
8244
|
-
}
|
|
8245
|
-
function openBrowser(url, deps) {
|
|
8246
|
-
let parsed2;
|
|
8247
|
-
try {
|
|
8248
|
-
parsed2 = new URL(url);
|
|
8249
|
-
} catch {
|
|
8250
|
-
return;
|
|
8251
|
-
}
|
|
8252
|
-
if (parsed2.protocol !== "https:" && parsed2.protocol !== "http:") return;
|
|
8253
|
-
try {
|
|
8254
|
-
if (deps.platform === "darwin") {
|
|
8255
|
-
deps.spawn("open", [url]);
|
|
8256
|
-
} else if (deps.platform === "win32") {
|
|
8257
|
-
if (/[&|^<>"%]/.test(url)) return;
|
|
8258
|
-
deps.spawn("cmd", ["/c", "start", "", url]);
|
|
8259
|
-
} else {
|
|
8260
|
-
deps.spawn("xdg-open", [url]);
|
|
8261
|
-
}
|
|
8262
|
-
} catch {
|
|
8263
|
-
}
|
|
8264
|
-
}
|
|
8265
8586
|
async function wait(ms, ctx, deps) {
|
|
8266
8587
|
if (ctx.signal.aborted) throw interrupted3();
|
|
8267
8588
|
try {
|
|
@@ -8379,8 +8700,8 @@ async function poll(ctx, deps, started) {
|
|
|
8379
8700
|
default:
|
|
8380
8701
|
}
|
|
8381
8702
|
if (err.httpStatus === 404) throw expired();
|
|
8382
|
-
const
|
|
8383
|
-
if (
|
|
8703
|
+
const transient2 = err.code === "network_error" || err.httpStatus !== void 0 && err.httpStatus >= 500;
|
|
8704
|
+
if (transient2 && ++failures < MAX_CONSECUTIVE_POLL_FAILURES) continue;
|
|
8384
8705
|
throw err;
|
|
8385
8706
|
}
|
|
8386
8707
|
}
|
|
@@ -8389,6 +8710,7 @@ var MAX_DEVICE_NAME, SLOW_DOWN_STEP_SECONDS, DEFAULT_EXPIRES_IN, DEFAULT_INTERVA
|
|
|
8389
8710
|
var init_browser_login = __esm({
|
|
8390
8711
|
"src/commands/auth/browser-login.ts"() {
|
|
8391
8712
|
"use strict";
|
|
8713
|
+
init_browser();
|
|
8392
8714
|
init_config();
|
|
8393
8715
|
init_errors();
|
|
8394
8716
|
init_exit_codes();
|
|
@@ -8500,16 +8822,16 @@ var init_login = __esm({
|
|
|
8500
8822
|
next: PIPE_EXAMPLE
|
|
8501
8823
|
});
|
|
8502
8824
|
}
|
|
8503
|
-
let
|
|
8825
|
+
let text4;
|
|
8504
8826
|
try {
|
|
8505
|
-
|
|
8827
|
+
text4 = await readStream(stdin, MAX_KEY_INPUT_BYTES);
|
|
8506
8828
|
} catch {
|
|
8507
8829
|
throw invalidKey("stdin holds more than one API key's worth of text.");
|
|
8508
8830
|
}
|
|
8509
|
-
const key = (
|
|
8831
|
+
const key = (text4.trim().split(/\r?\n/)[0] ?? "").trim();
|
|
8510
8832
|
if (key === "") throw invalidKey("stdin was empty: pipe the API key in.");
|
|
8511
8833
|
if (!API_KEY_PATTERN.test(key)) throw invalidKey("stdin does not hold a Kenso API key.");
|
|
8512
|
-
let
|
|
8834
|
+
let body2;
|
|
8513
8835
|
try {
|
|
8514
8836
|
const res = await ctx.client.request({
|
|
8515
8837
|
method: "GET",
|
|
@@ -8519,7 +8841,7 @@ var init_login = __esm({
|
|
|
8519
8841
|
headers: { Authorization: `Bearer ${key}` },
|
|
8520
8842
|
signal: ctx.signal
|
|
8521
8843
|
});
|
|
8522
|
-
|
|
8844
|
+
body2 = res.body;
|
|
8523
8845
|
} catch (err) {
|
|
8524
8846
|
if (err instanceof KensoError && err.exitCode === ExitCode.Auth) {
|
|
8525
8847
|
throw new KensoError({
|
|
@@ -8534,7 +8856,7 @@ var init_login = __esm({
|
|
|
8534
8856
|
}
|
|
8535
8857
|
throw err;
|
|
8536
8858
|
}
|
|
8537
|
-
const me = unwrap(
|
|
8859
|
+
const me = unwrap(body2) ?? {};
|
|
8538
8860
|
const ids2 = (Array.isArray(me.workspaces) ? me.workspaces : []).map((w) => String(w.id));
|
|
8539
8861
|
const wanted = ctx.flags.workspace;
|
|
8540
8862
|
let workspaceId;
|
|
@@ -8779,10 +9101,10 @@ var init_status2 = __esm({
|
|
|
8779
9101
|
// src/commands/capture/connect.ts
|
|
8780
9102
|
var connect_exports = {};
|
|
8781
9103
|
__export(connect_exports, {
|
|
8782
|
-
default: () =>
|
|
9104
|
+
default: () => connect_default2
|
|
8783
9105
|
});
|
|
8784
|
-
var PROVIDERS, command9,
|
|
8785
|
-
var
|
|
9106
|
+
var PROVIDERS, command9, connect_default2;
|
|
9107
|
+
var init_connect2 = __esm({
|
|
8786
9108
|
"src/commands/capture/connect.ts"() {
|
|
8787
9109
|
"use strict";
|
|
8788
9110
|
init_errors();
|
|
@@ -8839,7 +9161,7 @@ var init_connect = __esm({
|
|
|
8839
9161
|
}
|
|
8840
9162
|
}
|
|
8841
9163
|
};
|
|
8842
|
-
|
|
9164
|
+
connect_default2 = command9;
|
|
8843
9165
|
}
|
|
8844
9166
|
});
|
|
8845
9167
|
|
|
@@ -8957,7 +9279,7 @@ var init_capture = __esm({
|
|
|
8957
9279
|
"use strict";
|
|
8958
9280
|
actions5 = {
|
|
8959
9281
|
status: () => Promise.resolve().then(() => (init_status2(), status_exports2)).then((m) => m.default),
|
|
8960
|
-
connect: () => Promise.resolve().then(() => (
|
|
9282
|
+
connect: () => Promise.resolve().then(() => (init_connect2(), connect_exports)).then((m) => m.default),
|
|
8961
9283
|
private: () => Promise.resolve().then(() => (init_private(), private_exports)).then((m) => m.default),
|
|
8962
9284
|
disconnect: () => Promise.resolve().then(() => (init_disconnect(), disconnect_exports)).then((m) => m.default),
|
|
8963
9285
|
"teammates-see": () => Promise.resolve().then(() => (init_teammates_see(), teammates_see_exports)).then((m) => m.default)
|
|
@@ -9078,6 +9400,553 @@ var init_completion2 = __esm({
|
|
|
9078
9400
|
}
|
|
9079
9401
|
});
|
|
9080
9402
|
|
|
9403
|
+
// src/commands/connect/kinds.ts
|
|
9404
|
+
var kinds_exports = {};
|
|
9405
|
+
__export(kinds_exports, {
|
|
9406
|
+
KINDS: () => KINDS
|
|
9407
|
+
});
|
|
9408
|
+
function text(flags, name) {
|
|
9409
|
+
const value = flags[name];
|
|
9410
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
9411
|
+
}
|
|
9412
|
+
function oneOf(flags, name, values, required) {
|
|
9413
|
+
const value = text(flags, name);
|
|
9414
|
+
if (value === void 0) {
|
|
9415
|
+
if (required) throw usageError(`--${name} is required: ${values.join(" or ")}.`, { field: name });
|
|
9416
|
+
return void 0;
|
|
9417
|
+
}
|
|
9418
|
+
if (!values.includes(value)) throw usageError(`--${name} is ${values.join(" or ")} (got "${value}").`, { field: name });
|
|
9419
|
+
return value;
|
|
9420
|
+
}
|
|
9421
|
+
function wholeNumber(flags, name) {
|
|
9422
|
+
const value = text(flags, name);
|
|
9423
|
+
if (value === void 0) return void 0;
|
|
9424
|
+
const parsed2 = Number(value);
|
|
9425
|
+
if (!/^\d+$/.test(value) || !Number.isSafeInteger(parsed2)) throw usageError(`--${name} must be a whole number (got "${value}").`, { field: name });
|
|
9426
|
+
return parsed2;
|
|
9427
|
+
}
|
|
9428
|
+
function body(values) {
|
|
9429
|
+
return Object.fromEntries(Object.entries(values).filter(([, value]) => value !== void 0));
|
|
9430
|
+
}
|
|
9431
|
+
var PROVIDER_FLAG, API_KEY_CRMS, KINDS;
|
|
9432
|
+
var init_kinds = __esm({
|
|
9433
|
+
"src/commands/connect/kinds.ts"() {
|
|
9434
|
+
"use strict";
|
|
9435
|
+
init_errors();
|
|
9436
|
+
PROVIDER_FLAG = (values) => ({ type: "string", description: `${values} (required)` });
|
|
9437
|
+
API_KEY_CRMS = ["close", "twenty"];
|
|
9438
|
+
KINDS = [
|
|
9439
|
+
{
|
|
9440
|
+
name: "inbox",
|
|
9441
|
+
label: "the mailbox",
|
|
9442
|
+
summary: "Connect a Google or Microsoft inbox in the browser",
|
|
9443
|
+
description: "Starts an inbox connect (POST /v1/inboxes/connect-sessions) and watches GET /v1/inboxes until a new inbox, or a disconnected one signed in again, shows up. --purpose campaign (the default) connects a sending inbox; primary connects your own mailbox. A Microsoft answer also prints the admin consent link for the whole tenant.",
|
|
9444
|
+
flags: {
|
|
9445
|
+
provider: PROVIDER_FLAG("google or microsoft"),
|
|
9446
|
+
purpose: { type: "string", description: "campaign (a sending inbox, the default) or primary (your own mailbox)" },
|
|
9447
|
+
"return-to": { type: "string", description: "The app.ken.so page the browser lands on after the sign-in, a path such as /inboxes" }
|
|
9448
|
+
},
|
|
9449
|
+
examples: ["kenso connect inbox --provider google", "kenso connect inbox --provider microsoft --purpose primary"],
|
|
9450
|
+
operationIds: ["inboxes.create-connect-session", "inboxes.list"],
|
|
9451
|
+
start: (flags) => ({
|
|
9452
|
+
method: "POST",
|
|
9453
|
+
path: "/v1/inboxes/connect-sessions",
|
|
9454
|
+
body: body({
|
|
9455
|
+
provider: oneOf(flags, "provider", ["google", "microsoft"], true),
|
|
9456
|
+
purpose: oneOf(flags, "purpose", ["campaign", "primary"], false) ?? "campaign",
|
|
9457
|
+
returnTo: text(flags, "return-to")
|
|
9458
|
+
})
|
|
9459
|
+
}),
|
|
9460
|
+
watch: {
|
|
9461
|
+
path: "/v1/inboxes",
|
|
9462
|
+
pageSize: 200,
|
|
9463
|
+
key: "id",
|
|
9464
|
+
// The list names a Microsoft mailbox microsoft, or azure when it came from a Microsoft tenant order.
|
|
9465
|
+
filter: (item, flags) => text(flags, "provider") === "microsoft" ? item.provider === "microsoft" || item.provider === "azure" : item.provider === text(flags, "provider"),
|
|
9466
|
+
ok: ["active", "warmup"],
|
|
9467
|
+
reconnectFrom: ["disconnected", "connection_error"]
|
|
9468
|
+
},
|
|
9469
|
+
timeoutHint: "A primary mailbox that is not your login email waits for a confirmation in app.ken.so after the sign-in: finish it there, then check kenso inboxes list."
|
|
9470
|
+
},
|
|
9471
|
+
{
|
|
9472
|
+
name: "calendar",
|
|
9473
|
+
label: "the calendar",
|
|
9474
|
+
summary: "Connect a Google or Microsoft calendar in the browser",
|
|
9475
|
+
description: "Starts a calendar connect (POST /v1/calendar-accounts/connect-sessions) and watches GET /v1/calendar-accounts until a new account, or the one --account-id names, is connected. --access calendar_only leaves email out.",
|
|
9476
|
+
flags: {
|
|
9477
|
+
provider: PROVIDER_FLAG("google or microsoft"),
|
|
9478
|
+
access: { type: "string", description: "calendar_and_email (the default) or calendar_only" },
|
|
9479
|
+
"account-id": { type: "string", description: "Sign an account in again (its cacc_ id) instead of adding one" }
|
|
9480
|
+
},
|
|
9481
|
+
examples: ["kenso connect calendar --provider google", "kenso connect calendar --provider microsoft --account-id cacc_123"],
|
|
9482
|
+
operationIds: ["calendar-accounts.create-connect-session", "calendar-accounts.list"],
|
|
9483
|
+
start: (flags) => ({
|
|
9484
|
+
method: "POST",
|
|
9485
|
+
path: "/v1/calendar-accounts/connect-sessions",
|
|
9486
|
+
body: body({
|
|
9487
|
+
provider: oneOf(flags, "provider", ["google", "microsoft"], true),
|
|
9488
|
+
access: oneOf(flags, "access", ["calendar_and_email", "calendar_only"], false),
|
|
9489
|
+
accountId: text(flags, "account-id")
|
|
9490
|
+
})
|
|
9491
|
+
}),
|
|
9492
|
+
watch: {
|
|
9493
|
+
path: "/v1/calendar-accounts",
|
|
9494
|
+
key: "id",
|
|
9495
|
+
filter: (item, flags) => item.provider === text(flags, "provider") && (text(flags, "account-id") === void 0 || item.id === text(flags, "account-id")),
|
|
9496
|
+
ok: ["connected"],
|
|
9497
|
+
stamps: ["connectedAt"]
|
|
9498
|
+
}
|
|
9499
|
+
},
|
|
9500
|
+
{
|
|
9501
|
+
name: "video",
|
|
9502
|
+
label: "Zoom or Webex",
|
|
9503
|
+
summary: "Wait for a Zoom or Webex connection made in the app",
|
|
9504
|
+
description: "Kenso lets only a signed-in person start a Zoom or Webex connect: the API refuses an API key or an agent. So this prints where to connect it in app.ken.so and watches GET /v1/video-connections until the provider shows connected. When it is connected already, it prints it at once.",
|
|
9505
|
+
flags: { provider: PROVIDER_FLAG("zoom or webex") },
|
|
9506
|
+
examples: ["kenso connect video --provider zoom"],
|
|
9507
|
+
operationIds: ["video-connections.list"],
|
|
9508
|
+
manual: {
|
|
9509
|
+
check: (flags) => void oneOf(flags, "provider", ["zoom", "webex"], true),
|
|
9510
|
+
text: "Kenso lets only a signed-in person connect Zoom or Webex: connect it in app.ken.so at Settings > Calendar."
|
|
9511
|
+
},
|
|
9512
|
+
watch: {
|
|
9513
|
+
path: "/v1/video-connections",
|
|
9514
|
+
key: "provider",
|
|
9515
|
+
filter: (item, flags) => item.provider === text(flags, "provider"),
|
|
9516
|
+
ok: ["connected"],
|
|
9517
|
+
stamps: ["connectedAt", "connectedAs"]
|
|
9518
|
+
}
|
|
9519
|
+
},
|
|
9520
|
+
{
|
|
9521
|
+
name: "crm",
|
|
9522
|
+
label: "the CRM",
|
|
9523
|
+
summary: "Connect a CRM (HubSpot, Salesforce, Pipedrive ...) in the browser",
|
|
9524
|
+
description: "Starts a CRM connect (POST /v1/crm-connections) and watches GET /v1/crm-connections until the CRM is connected. Browser sign-in CRMs: hubspot, salesforce, pipedrive, attio, highlevel, dynamics (with --base-url) and zoho. close and twenty connect with an API key instead: kenso crm-connections create --provider close --api-key @key.txt.",
|
|
9525
|
+
flags: {
|
|
9526
|
+
provider: PROVIDER_FLAG("hubspot, salesforce, pipedrive, attio, highlevel, dynamics or zoho"),
|
|
9527
|
+
"base-url": { type: "string", description: "The CRM's https URL (dynamics)" },
|
|
9528
|
+
"return-path": { type: "string", description: "The app.ken.so page the browser lands on after the sign-in, a path starting with /" }
|
|
9529
|
+
},
|
|
9530
|
+
examples: ["kenso connect crm --provider hubspot", "kenso connect crm --provider dynamics --base-url https://acme.crm.dynamics.com"],
|
|
9531
|
+
operationIds: ["crm-connections.create", "crm-connections.list"],
|
|
9532
|
+
start: (flags) => {
|
|
9533
|
+
const provider = text(flags, "provider");
|
|
9534
|
+
if (provider === void 0) throw usageError("--provider is required: hubspot, salesforce, pipedrive, attio, highlevel, dynamics or zoho.", { field: "provider" });
|
|
9535
|
+
if (API_KEY_CRMS.includes(provider)) {
|
|
9536
|
+
throw usageError(`${provider} connects with an API key, not in the browser.`, {
|
|
9537
|
+
field: "provider",
|
|
9538
|
+
next: `kenso crm-connections create --provider ${provider} --api-key @key.txt`
|
|
9539
|
+
});
|
|
9540
|
+
}
|
|
9541
|
+
return { method: "POST", path: "/v1/crm-connections", body: body({ provider, baseUrl: text(flags, "base-url"), returnPath: text(flags, "return-path") }) };
|
|
9542
|
+
},
|
|
9543
|
+
watch: {
|
|
9544
|
+
path: "/v1/crm-connections",
|
|
9545
|
+
key: "id",
|
|
9546
|
+
filter: (item, flags) => item.provider === text(flags, "provider"),
|
|
9547
|
+
ok: ["connected"],
|
|
9548
|
+
reconnectFrom: ["needs_reconnect", "disconnected"],
|
|
9549
|
+
stamps: ["connectedAt"]
|
|
9550
|
+
}
|
|
9551
|
+
},
|
|
9552
|
+
{
|
|
9553
|
+
name: "hubspot-knowledge",
|
|
9554
|
+
label: "HubSpot for Knowledge",
|
|
9555
|
+
summary: "Connect HubSpot as a Knowledge source in the browser",
|
|
9556
|
+
description: "Starts the HubSpot Knowledge connect (POST /v1/knowledge/hubspot/connect-sessions) and watches GET /v1/knowledge/sources until a HubSpot source is added or signed in again.",
|
|
9557
|
+
flags: {},
|
|
9558
|
+
examples: ["kenso connect hubspot-knowledge"],
|
|
9559
|
+
operationIds: ["knowledge-hubspot.create-connect-session", "knowledge-sources.list"],
|
|
9560
|
+
start: () => ({ method: "POST", path: "/v1/knowledge/hubspot/connect-sessions" }),
|
|
9561
|
+
watch: { path: "/v1/knowledge/sources", key: "id", filter: (item) => item.kind === "hubspot", ok: ["pending", "ok", "changed"] }
|
|
9562
|
+
},
|
|
9563
|
+
{
|
|
9564
|
+
name: "github",
|
|
9565
|
+
label: "GitHub",
|
|
9566
|
+
summary: "Install the Kenso GitHub app in the browser",
|
|
9567
|
+
description: "Gets the GitHub app install link (GET /v1/integrations/github/install-url) and watches GET /v1/integrations/github/installations until a new installation is active.",
|
|
9568
|
+
flags: {},
|
|
9569
|
+
examples: ["kenso connect github"],
|
|
9570
|
+
operationIds: ["github-installations.get-install-url", "github-installations.list"],
|
|
9571
|
+
start: () => ({ method: "GET", path: "/v1/integrations/github/install-url" }),
|
|
9572
|
+
watch: { path: "/v1/integrations/github/installations", key: "installationId", ok: ["active"] }
|
|
9573
|
+
},
|
|
9574
|
+
{
|
|
9575
|
+
name: "migration",
|
|
9576
|
+
label: "the migration source",
|
|
9577
|
+
summary: "Connect a migration source (Outreach) in the browser",
|
|
9578
|
+
description: "Starts a migration source connect (POST /v1/migration-connections/connect-sessions) and watches GET /v1/migration-connections until it is active. Outreach is the browser sign-in source; the API-key sources (Instantly, Smartlead ...) connect with kenso migration-connections create.",
|
|
9579
|
+
flags: {
|
|
9580
|
+
vendor: { type: "string", description: "outreach (the default)" },
|
|
9581
|
+
"connection-id": { type: "string", description: "Sign an existing connection in again instead of adding one" }
|
|
9582
|
+
},
|
|
9583
|
+
examples: ["kenso connect migration", "kenso connect migration --connection-id 42"],
|
|
9584
|
+
operationIds: ["migration-connections.create-connect-session", "migration-connections.list"],
|
|
9585
|
+
start: (flags) => ({
|
|
9586
|
+
method: "POST",
|
|
9587
|
+
path: "/v1/migration-connections/connect-sessions",
|
|
9588
|
+
body: body({ vendor: text(flags, "vendor") ?? "outreach", connectionId: wholeNumber(flags, "connection-id") })
|
|
9589
|
+
}),
|
|
9590
|
+
watch: {
|
|
9591
|
+
path: "/v1/migration-connections",
|
|
9592
|
+
key: "id",
|
|
9593
|
+
filter: (item, flags) => item.vendor === (text(flags, "vendor") ?? "outreach") && (text(flags, "connection-id") === void 0 || String(item.id) === text(flags, "connection-id")),
|
|
9594
|
+
ok: ["active"],
|
|
9595
|
+
stamps: ["lastVerifiedAt"]
|
|
9596
|
+
}
|
|
9597
|
+
},
|
|
9598
|
+
{
|
|
9599
|
+
name: "linkedin",
|
|
9600
|
+
label: "the LinkedIn account",
|
|
9601
|
+
summary: "Connect a LinkedIn account in the browser",
|
|
9602
|
+
description: "Starts a LinkedIn connect (POST /v1/linkedin-accounts/connect-sessions), which adds the account as connecting, and watches it until it is connected or the sign-in fails. It can use credits, as in the app.",
|
|
9603
|
+
flags: {
|
|
9604
|
+
"linkedin-account-id": { type: "string", description: "Sign an existing account in again instead of adding one" },
|
|
9605
|
+
"import-connections": { type: "boolean", description: "Import the account's connections once it is connected" },
|
|
9606
|
+
"network-only": { type: "boolean", description: "Use the account for its network only, not for sending" }
|
|
9607
|
+
},
|
|
9608
|
+
examples: ["kenso connect linkedin", "kenso connect linkedin --linkedin-account-id 42"],
|
|
9609
|
+
operationIds: ["linkedin-accounts.create-connect-session", "linkedin-accounts.get"],
|
|
9610
|
+
start: (flags) => ({
|
|
9611
|
+
method: "POST",
|
|
9612
|
+
path: "/v1/linkedin-accounts/connect-sessions",
|
|
9613
|
+
body: body({
|
|
9614
|
+
linkedInAccountId: wholeNumber(flags, "linkedin-account-id"),
|
|
9615
|
+
importConnections: flags["import-connections"] === true ? true : void 0,
|
|
9616
|
+
networkOnly: flags["network-only"] === true ? true : void 0
|
|
9617
|
+
})
|
|
9618
|
+
}),
|
|
9619
|
+
rowId: "linkedInAccountId",
|
|
9620
|
+
reconnectId: (flags) => text(flags, "linkedin-account-id"),
|
|
9621
|
+
watch: { path: "/v1/linkedin-accounts/{id}", key: "id", ok: ["connected"], failed: ["connect_failed", "credentials_error"], stamps: ["updatedAt"] }
|
|
9622
|
+
},
|
|
9623
|
+
{
|
|
9624
|
+
name: "whatsapp",
|
|
9625
|
+
label: "the WhatsApp account",
|
|
9626
|
+
summary: "Connect a WhatsApp account in the browser",
|
|
9627
|
+
description: "Starts a WhatsApp connect (POST /v1/whatsapp-accounts/connect-sessions), which adds the account as connecting, and watches it until it is connected or the sign-in fails. It can use credits, as in the app.",
|
|
9628
|
+
flags: { "whatsapp-account-id": { type: "string", description: "Sign an existing account in again instead of adding one" } },
|
|
9629
|
+
examples: ["kenso connect whatsapp"],
|
|
9630
|
+
operationIds: ["whatsapp-accounts.create-connect-session", "whatsapp-accounts.get"],
|
|
9631
|
+
start: (flags) => ({
|
|
9632
|
+
method: "POST",
|
|
9633
|
+
path: "/v1/whatsapp-accounts/connect-sessions",
|
|
9634
|
+
body: body({ whatsappAccountId: wholeNumber(flags, "whatsapp-account-id") })
|
|
9635
|
+
}),
|
|
9636
|
+
rowId: "whatsappAccountId",
|
|
9637
|
+
reconnectId: (flags) => text(flags, "whatsapp-account-id"),
|
|
9638
|
+
watch: {
|
|
9639
|
+
path: "/v1/whatsapp-accounts/{id}",
|
|
9640
|
+
key: "id",
|
|
9641
|
+
ok: ["connected"],
|
|
9642
|
+
failed: ["connect_failed", "credentials_error"],
|
|
9643
|
+
stamps: ["connectedAt", "statusChangedAt"]
|
|
9644
|
+
}
|
|
9645
|
+
},
|
|
9646
|
+
{
|
|
9647
|
+
name: "facebook",
|
|
9648
|
+
label: "the Facebook account",
|
|
9649
|
+
summary: "Connect a Facebook account in the browser",
|
|
9650
|
+
description: "Starts a Facebook connect (POST /v1/facebook-accounts/connect-sessions, or its reconnect session with --facebook-account-id) and watches the account until it is connected or the sign-in fails.",
|
|
9651
|
+
flags: { "facebook-account-id": { type: "string", description: "Sign an existing account in again instead of adding one" } },
|
|
9652
|
+
examples: ["kenso connect facebook"],
|
|
9653
|
+
operationIds: ["facebook-accounts.create-connect-session", "facebook-accounts.create-reconnect-session", "facebook-accounts.get"],
|
|
9654
|
+
start: (flags) => {
|
|
9655
|
+
const id = wholeNumber(flags, "facebook-account-id");
|
|
9656
|
+
return { method: "POST", path: id === void 0 ? "/v1/facebook-accounts/connect-sessions" : `/v1/facebook-accounts/${id}/reconnect-sessions` };
|
|
9657
|
+
},
|
|
9658
|
+
rowId: "facebookAccountId",
|
|
9659
|
+
reconnectId: (flags) => text(flags, "facebook-account-id"),
|
|
9660
|
+
watch: { path: "/v1/facebook-accounts/{id}", key: "id", ok: ["connected"], failed: ["connect_failed", "credentials_error"], stamps: ["updatedAt"] }
|
|
9661
|
+
},
|
|
9662
|
+
{
|
|
9663
|
+
name: "instagram",
|
|
9664
|
+
label: "the Instagram account",
|
|
9665
|
+
summary: "Connect an Instagram account in the browser",
|
|
9666
|
+
description: "Starts an Instagram connect (POST /v1/instagram-accounts/connect-sessions), which adds the account as connecting, and watches it until it is connected or the sign-in fails.",
|
|
9667
|
+
flags: {
|
|
9668
|
+
name: { type: "string", description: "A name for the account in Kenso (at most 100 characters)" },
|
|
9669
|
+
"instagram-account-id": { type: "string", description: "Sign an existing account in again instead of adding one" }
|
|
9670
|
+
},
|
|
9671
|
+
examples: ["kenso connect instagram --name 'Acme brand'"],
|
|
9672
|
+
operationIds: ["instagram-accounts.create-connect-session", "instagram-accounts.get"],
|
|
9673
|
+
start: (flags) => ({
|
|
9674
|
+
method: "POST",
|
|
9675
|
+
path: "/v1/instagram-accounts/connect-sessions",
|
|
9676
|
+
body: body({ name: text(flags, "name"), instagramAccountId: wholeNumber(flags, "instagram-account-id") })
|
|
9677
|
+
}),
|
|
9678
|
+
rowId: "instagramAccountId",
|
|
9679
|
+
reconnectId: (flags) => text(flags, "instagram-account-id"),
|
|
9680
|
+
watch: { path: "/v1/instagram-accounts/{id}", key: "id", ok: ["connected"], failed: ["error", "locked"], stamps: ["updatedAt"] }
|
|
9681
|
+
}
|
|
9682
|
+
];
|
|
9683
|
+
}
|
|
9684
|
+
});
|
|
9685
|
+
|
|
9686
|
+
// src/commands/connect/run.ts
|
|
9687
|
+
var run_exports = {};
|
|
9688
|
+
__export(run_exports, {
|
|
9689
|
+
POLL_INTERVAL_MS: () => POLL_INTERVAL_MS,
|
|
9690
|
+
connectCommand: () => connectCommand,
|
|
9691
|
+
runConnect: () => runConnect
|
|
9692
|
+
});
|
|
9693
|
+
import { spawn as nodeSpawn2 } from "node:child_process";
|
|
9694
|
+
import { setTimeout as delay3 } from "node:timers/promises";
|
|
9695
|
+
function interrupted4() {
|
|
9696
|
+
return new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted });
|
|
9697
|
+
}
|
|
9698
|
+
function isRecord5(value) {
|
|
9699
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
9700
|
+
}
|
|
9701
|
+
function keyText(value) {
|
|
9702
|
+
if (typeof value === "string") return value === "" ? void 0 : value;
|
|
9703
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
9704
|
+
return void 0;
|
|
9705
|
+
}
|
|
9706
|
+
function timeoutMs(flags) {
|
|
9707
|
+
const raw = flags.timeout;
|
|
9708
|
+
if (raw === void 0) return DEFAULT_TIMEOUT_SECONDS * 1e3;
|
|
9709
|
+
const value = Number(raw);
|
|
9710
|
+
if (typeof raw !== "string" || !/^\d+$/.test(raw.trim()) || value < 1) {
|
|
9711
|
+
throw usageError(`--timeout must be a whole number of seconds, 1 or more (got "${String(raw)}").`, { field: "timeout" });
|
|
9712
|
+
}
|
|
9713
|
+
return value * 1e3;
|
|
9714
|
+
}
|
|
9715
|
+
function linkOf(answer) {
|
|
9716
|
+
for (const field of LINK_FIELDS) {
|
|
9717
|
+
const value = answer[field];
|
|
9718
|
+
if (typeof value === "string" && value !== "") return value;
|
|
9719
|
+
}
|
|
9720
|
+
return void 0;
|
|
9721
|
+
}
|
|
9722
|
+
function commandLine3(kind, flags) {
|
|
9723
|
+
const parts2 = ["kenso connect", kind.name];
|
|
9724
|
+
for (const [name, value] of Object.entries(flags)) {
|
|
9725
|
+
if (value === void 0 || value === false || name === "no-wait") continue;
|
|
9726
|
+
if (value === true) parts2.push(`--${name}`);
|
|
9727
|
+
else for (const item of Array.isArray(value) ? value : [value]) parts2.push(`--${name} ${/^[\w@%+=:,./-]+$/.test(item) ? item : `'${item.replace(/'/g, `'\\''`)}'`}`);
|
|
9728
|
+
}
|
|
9729
|
+
return parts2.join(" ");
|
|
9730
|
+
}
|
|
9731
|
+
async function read(ctx, kind, flags, rowId) {
|
|
9732
|
+
if (rowId !== void 0) {
|
|
9733
|
+
const res = await ctx.client.request({ method: "GET", path: kind.watch.path.replace("{id}", encodeURIComponent(rowId)), signal: ctx.signal });
|
|
9734
|
+
const row = unwrap(res.body);
|
|
9735
|
+
return isRecord5(row) ? [row] : [];
|
|
9736
|
+
}
|
|
9737
|
+
const items = [];
|
|
9738
|
+
const page = kind.watch.pageSize !== void 0 ? { pageSize: kind.watch.pageSize } : void 0;
|
|
9739
|
+
for await (const item of ctx.client.paginate({ method: "GET", path: kind.watch.path, signal: ctx.signal }, page)) {
|
|
9740
|
+
if (isRecord5(item) && (!kind.watch.filter || kind.watch.filter(item, flags))) items.push(item);
|
|
9741
|
+
}
|
|
9742
|
+
return items;
|
|
9743
|
+
}
|
|
9744
|
+
function keyOf(kind, item, rowId) {
|
|
9745
|
+
return rowId ?? keyText(item[kind.watch.key]);
|
|
9746
|
+
}
|
|
9747
|
+
function byKey(kind, items, rowId) {
|
|
9748
|
+
const map = /* @__PURE__ */ new Map();
|
|
9749
|
+
for (const item of items) {
|
|
9750
|
+
const key = keyOf(kind, item, rowId);
|
|
9751
|
+
if (key !== void 0) map.set(key, item);
|
|
9752
|
+
}
|
|
9753
|
+
return map;
|
|
9754
|
+
}
|
|
9755
|
+
function settle(kind, items, baseline, rowId) {
|
|
9756
|
+
const { ok, failed = [], stamps = [], reconnectFrom } = kind.watch;
|
|
9757
|
+
for (const item of items) {
|
|
9758
|
+
const key = keyOf(kind, item, rowId);
|
|
9759
|
+
if (key === void 0) continue;
|
|
9760
|
+
const status = typeof item.status === "string" ? item.status : "";
|
|
9761
|
+
const before = baseline.get(key);
|
|
9762
|
+
if (!before) return failed.includes(status) ? { failed: item } : { connected: item };
|
|
9763
|
+
const statusMoved = before.status !== item.status;
|
|
9764
|
+
if (failed.includes(status) && statusMoved) return { failed: item };
|
|
9765
|
+
const reconnected = statusMoved && (reconnectFrom === void 0 || reconnectFrom.includes(String(before.status)));
|
|
9766
|
+
const stamped = stamps.some((field) => JSON.stringify(before[field]) !== JSON.stringify(item[field]));
|
|
9767
|
+
if (ok.includes(status) && (reconnected || stamped)) return { connected: item };
|
|
9768
|
+
}
|
|
9769
|
+
return void 0;
|
|
9770
|
+
}
|
|
9771
|
+
function transient(err) {
|
|
9772
|
+
if (!(err instanceof KensoError)) return false;
|
|
9773
|
+
return err.code === "network_error" || err.httpStatus !== void 0 && err.httpStatus >= 500;
|
|
9774
|
+
}
|
|
9775
|
+
async function wait2(ms, ctx, deps) {
|
|
9776
|
+
if (ctx.signal.aborted) throw interrupted4();
|
|
9777
|
+
try {
|
|
9778
|
+
await deps.sleep(ms, ctx.signal);
|
|
9779
|
+
} catch (err) {
|
|
9780
|
+
if (ctx.signal.aborted) throw interrupted4();
|
|
9781
|
+
throw err;
|
|
9782
|
+
}
|
|
9783
|
+
if (ctx.signal.aborted) throw interrupted4();
|
|
9784
|
+
}
|
|
9785
|
+
async function watch(ctx, kind, flags, rowId, baseline, limitMs, deps) {
|
|
9786
|
+
const deadline = deps.now() + limitMs;
|
|
9787
|
+
let failures = 0;
|
|
9788
|
+
for (; ; ) {
|
|
9789
|
+
await wait2(Math.max(0, Math.min(POLL_INTERVAL_MS, deadline - deps.now())), ctx, deps);
|
|
9790
|
+
try {
|
|
9791
|
+
const outcome = settle(kind, await read(ctx, kind, flags, rowId), baseline, rowId);
|
|
9792
|
+
failures = 0;
|
|
9793
|
+
if (outcome && "connected" in outcome) return outcome.connected;
|
|
9794
|
+
if (outcome) {
|
|
9795
|
+
throw new KensoError({
|
|
9796
|
+
code: "connect_failed",
|
|
9797
|
+
message: `The connect of ${kind.label} ended with status ${String(outcome.failed.status)}.`,
|
|
9798
|
+
exitCode: ExitCode.Error,
|
|
9799
|
+
hint: "Run the command again for a new link, and check the sign-in in the browser.",
|
|
9800
|
+
next: commandLine3(kind, flags),
|
|
9801
|
+
details: outcome.failed
|
|
9802
|
+
});
|
|
9803
|
+
}
|
|
9804
|
+
} catch (err) {
|
|
9805
|
+
if (ctx.signal.aborted) throw interrupted4();
|
|
9806
|
+
if (!transient(err) || ++failures >= MAX_POLL_FAILURES) throw err;
|
|
9807
|
+
ctx.output.warn(`Checking the connection failed (${err.message}); trying again.`);
|
|
9808
|
+
}
|
|
9809
|
+
if (deps.now() >= deadline) {
|
|
9810
|
+
const minutes = Math.round(limitMs / 6e4);
|
|
9811
|
+
throw new KensoError({
|
|
9812
|
+
code: "connect_timeout",
|
|
9813
|
+
message: `No ${kind.label} connection showed up within ${minutes >= 1 ? `${minutes} minute${minutes === 1 ? "" : "s"}` : `${limitMs / 1e3} s`}.`,
|
|
9814
|
+
exitCode: ExitCode.Error,
|
|
9815
|
+
hint: ["If the sign-in did not finish or the link expired, run the command again for a new link.", kind.timeoutHint].filter(Boolean).join(" "),
|
|
9816
|
+
next: commandLine3(kind, flags)
|
|
9817
|
+
});
|
|
9818
|
+
}
|
|
9819
|
+
}
|
|
9820
|
+
}
|
|
9821
|
+
function announce(ctx, kind, flags, link, answer, waiting, limitMs, deps) {
|
|
9822
|
+
if (link) ctx.output.info(`To connect ${kind.label}, open ${link}`);
|
|
9823
|
+
if (typeof answer.adminConsentUrl === "string" && answer.adminConsentUrl !== "") {
|
|
9824
|
+
ctx.output.info(`A Microsoft 365 admin can approve Kenso for the whole organization at ${answer.adminConsentUrl}`);
|
|
9825
|
+
}
|
|
9826
|
+
if (kind.manual) ctx.output.info(kind.manual.text);
|
|
9827
|
+
if (waiting) {
|
|
9828
|
+
const minutes = Math.max(1, Math.round(limitMs / 6e4));
|
|
9829
|
+
ctx.output.info(
|
|
9830
|
+
ctx.agent ? `Ask the person you are working with to ${link ? "open the link and finish the sign-in in their browser" : "do that"}. Waiting up to ${minutes} minute${minutes === 1 ? "" : "s"}.` : `Waiting up to ${minutes} minute${minutes === 1 ? "" : "s"} for the connection (Ctrl-C stops waiting).`
|
|
9831
|
+
);
|
|
9832
|
+
}
|
|
9833
|
+
if (link && !ctx.agent && flags["no-browser"] !== true && hasDisplay(ctx.env, deps.platform)) openBrowser(link, deps);
|
|
9834
|
+
}
|
|
9835
|
+
async function runConnect(ctx, kind, flags, overrides) {
|
|
9836
|
+
const deps = { ...defaultDeps2, ...overrides };
|
|
9837
|
+
const limitMs = timeoutMs(flags);
|
|
9838
|
+
kind.manual?.check(flags);
|
|
9839
|
+
const start = kind.start?.(flags);
|
|
9840
|
+
if (ctx.flags.dryRun) {
|
|
9841
|
+
const request = start ? { method: start.method, path: start.path, ...start.body !== void 0 ? { body: start.body } : {} } : null;
|
|
9842
|
+
ctx.output.object({ dryRun: true, kind: kind.name, request, watch: { method: "GET", path: kind.watch.path } });
|
|
9843
|
+
return ExitCode.Ok;
|
|
9844
|
+
}
|
|
9845
|
+
const waiting = flags["no-wait"] !== true;
|
|
9846
|
+
const before = waiting && kind.rowId === void 0 ? byKey(kind, await read(ctx, kind, flags, void 0)) : /* @__PURE__ */ new Map();
|
|
9847
|
+
if (kind.manual && waiting) {
|
|
9848
|
+
const connected = [...before.values()].find((item) => typeof item.status === "string" && kind.watch.ok.includes(item.status));
|
|
9849
|
+
if (connected) {
|
|
9850
|
+
ctx.output.object({ connected: true, alreadyConnected: true, kind: kind.name, connection: connected });
|
|
9851
|
+
return ExitCode.Ok;
|
|
9852
|
+
}
|
|
9853
|
+
}
|
|
9854
|
+
let answer = {};
|
|
9855
|
+
let link;
|
|
9856
|
+
let rowId;
|
|
9857
|
+
if (start) {
|
|
9858
|
+
const res = await ctx.client.request({ ...start, signal: ctx.signal });
|
|
9859
|
+
const data = unwrap(res.body);
|
|
9860
|
+
answer = isRecord5(data) ? data : {};
|
|
9861
|
+
link = linkOf(answer);
|
|
9862
|
+
if (!link) {
|
|
9863
|
+
if (keyText(answer[kind.watch.key]) !== void 0) {
|
|
9864
|
+
ctx.output.object({ connected: true, kind: kind.name, connection: answer });
|
|
9865
|
+
return ExitCode.Ok;
|
|
9866
|
+
}
|
|
9867
|
+
throw new KensoError({ code: "unexpected_response", message: `The connect start for ${kind.label} answered without a link to open.`, exitCode: ExitCode.Server, httpStatus: res.status, requestId: res.requestId });
|
|
9868
|
+
}
|
|
9869
|
+
if (kind.rowId) rowId = keyText(answer[kind.rowId]) ?? kind.reconnectId?.(flags);
|
|
9870
|
+
}
|
|
9871
|
+
announce(ctx, kind, flags, link, answer, waiting, limitMs, deps);
|
|
9872
|
+
if (!waiting) {
|
|
9873
|
+
ctx.output.object({ kind: kind.name, ...answer });
|
|
9874
|
+
return ExitCode.Ok;
|
|
9875
|
+
}
|
|
9876
|
+
let baseline = before;
|
|
9877
|
+
if (kind.rowId) {
|
|
9878
|
+
if (rowId === void 0) {
|
|
9879
|
+
throw new KensoError({ code: "unexpected_response", message: `The connect start for ${kind.label} answered without the account id to watch.`, exitCode: ExitCode.Server });
|
|
9880
|
+
}
|
|
9881
|
+
baseline = kind.reconnectId?.(flags) === void 0 ? /* @__PURE__ */ new Map([[rowId, { status: "connecting" }]]) : byKey(kind, await read(ctx, kind, flags, rowId), rowId);
|
|
9882
|
+
if (baseline.size === 0) baseline.set(rowId, { status: "connecting" });
|
|
9883
|
+
}
|
|
9884
|
+
const connection = await watch(ctx, kind, flags, rowId, baseline, limitMs, deps);
|
|
9885
|
+
ctx.output.object({ connected: true, kind: kind.name, connection });
|
|
9886
|
+
return ExitCode.Ok;
|
|
9887
|
+
}
|
|
9888
|
+
function connectCommand(kind) {
|
|
9889
|
+
return {
|
|
9890
|
+
resource: "connect",
|
|
9891
|
+
action: kind.name,
|
|
9892
|
+
summary: kind.summary,
|
|
9893
|
+
description: `${kind.description}
|
|
9894
|
+
|
|
9895
|
+
The connect finishes in a browser: Kenso refuses to complete a sign-in for an API key or an agent, so the person you work for opens the link. It prints the link on stderr (and opens it at a desktop when no coding agent runs it), checks every ${POLL_INTERVAL_MS / 1e3} s, and prints {connected, kind, connection} on stdout once the connection shows up. --no-wait prints the start answer, link included, and ends.`,
|
|
9896
|
+
flags: { ...kind.flags, ...COMMON_FLAGS },
|
|
9897
|
+
examples: [...kind.examples, `${kind.examples[0] ?? `kenso connect ${kind.name}`} --no-wait`],
|
|
9898
|
+
operationIds: kind.operationIds,
|
|
9899
|
+
dryRun: true,
|
|
9900
|
+
run: (ctx, args) => runConnect(ctx, kind, args.flags)
|
|
9901
|
+
};
|
|
9902
|
+
}
|
|
9903
|
+
var POLL_INTERVAL_MS, DEFAULT_TIMEOUT_SECONDS, MAX_POLL_FAILURES, LINK_FIELDS, defaultDeps2, COMMON_FLAGS;
|
|
9904
|
+
var init_run = __esm({
|
|
9905
|
+
"src/commands/connect/run.ts"() {
|
|
9906
|
+
"use strict";
|
|
9907
|
+
init_browser();
|
|
9908
|
+
init_errors();
|
|
9909
|
+
init_exit_codes();
|
|
9910
|
+
init_http();
|
|
9911
|
+
POLL_INTERVAL_MS = 5e3;
|
|
9912
|
+
DEFAULT_TIMEOUT_SECONDS = 600;
|
|
9913
|
+
MAX_POLL_FAILURES = 5;
|
|
9914
|
+
LINK_FIELDS = ["authorizationUrl", "authorizeUrl", "installUrl", "url"];
|
|
9915
|
+
defaultDeps2 = {
|
|
9916
|
+
sleep: (ms, signal) => delay3(ms, void 0, signal ? { signal } : void 0),
|
|
9917
|
+
now: () => Date.now(),
|
|
9918
|
+
spawn: (command48, args) => {
|
|
9919
|
+
const child = nodeSpawn2(command48, args, { detached: true, stdio: "ignore" });
|
|
9920
|
+
child.on("error", () => {
|
|
9921
|
+
});
|
|
9922
|
+
child.unref();
|
|
9923
|
+
},
|
|
9924
|
+
platform: process.platform
|
|
9925
|
+
};
|
|
9926
|
+
COMMON_FLAGS = {
|
|
9927
|
+
timeout: { type: "string", description: `Seconds to wait for the connection (default ${DEFAULT_TIMEOUT_SECONDS})` },
|
|
9928
|
+
"no-wait": { type: "boolean", description: "Print the link as JSON and end, without waiting for the connection" },
|
|
9929
|
+
"no-browser": { type: "boolean", description: "Print the link only; never open a browser" }
|
|
9930
|
+
};
|
|
9931
|
+
}
|
|
9932
|
+
});
|
|
9933
|
+
|
|
9934
|
+
// src/commands/connect/index.ts
|
|
9935
|
+
var KIND_NAMES, load, actions7;
|
|
9936
|
+
var init_connect3 = __esm({
|
|
9937
|
+
"src/commands/connect/index.ts"() {
|
|
9938
|
+
"use strict";
|
|
9939
|
+
KIND_NAMES = ["inbox", "calendar", "video", "crm", "hubspot-knowledge", "github", "migration", "linkedin", "whatsapp", "facebook", "instagram"];
|
|
9940
|
+
load = (name) => async () => {
|
|
9941
|
+
const [{ KINDS: KINDS2 }, { connectCommand: connectCommand2 }] = await Promise.all([Promise.resolve().then(() => (init_kinds(), kinds_exports)), Promise.resolve().then(() => (init_run(), run_exports))]);
|
|
9942
|
+
const kind = KINDS2.find((k) => k.name === name);
|
|
9943
|
+
if (!kind) throw new Error(`no connect kind ${name}`);
|
|
9944
|
+
return connectCommand2(kind);
|
|
9945
|
+
};
|
|
9946
|
+
actions7 = Object.fromEntries(KIND_NAMES.map((name) => [name, load(name)]));
|
|
9947
|
+
}
|
|
9948
|
+
});
|
|
9949
|
+
|
|
9081
9950
|
// src/commands/contacts/common.ts
|
|
9082
9951
|
import { createHash as createHash3 } from "node:crypto";
|
|
9083
9952
|
import { readFile as readFile6 } from "node:fs/promises";
|
|
@@ -9085,8 +9954,8 @@ import { resolve as resolve5 } from "node:path";
|
|
|
9085
9954
|
function stringFlag2(flags, name) {
|
|
9086
9955
|
const value = flags[name];
|
|
9087
9956
|
if (typeof value !== "string") return void 0;
|
|
9088
|
-
const
|
|
9089
|
-
return
|
|
9957
|
+
const text4 = value.trim();
|
|
9958
|
+
return text4 === "" ? void 0 : text4;
|
|
9090
9959
|
}
|
|
9091
9960
|
function requireFlag(flags, name, command48, hint) {
|
|
9092
9961
|
const value = stringFlag2(flags, name);
|
|
@@ -9094,9 +9963,9 @@ function requireFlag(flags, name, command48, hint) {
|
|
|
9094
9963
|
return value;
|
|
9095
9964
|
}
|
|
9096
9965
|
function positiveId(value) {
|
|
9097
|
-
const
|
|
9098
|
-
if (!/^[0-9]+$/.test(
|
|
9099
|
-
const id = Number(
|
|
9966
|
+
const text4 = value.trim();
|
|
9967
|
+
if (!/^[0-9]+$/.test(text4)) return void 0;
|
|
9968
|
+
const id = Number(text4);
|
|
9100
9969
|
return Number.isSafeInteger(id) && id > 0 ? id : void 0;
|
|
9101
9970
|
}
|
|
9102
9971
|
function idFlag(flags, name, command48) {
|
|
@@ -9155,7 +10024,7 @@ function failedRow(row, err, extra = {}) {
|
|
|
9155
10024
|
function invalidRow(row, reason, error, extra = {}) {
|
|
9156
10025
|
return { row, status: "invalid", reason, ...error ? { error } : {}, ...extra };
|
|
9157
10026
|
}
|
|
9158
|
-
function
|
|
10027
|
+
function isRecord6(value) {
|
|
9159
10028
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
9160
10029
|
}
|
|
9161
10030
|
function warnDropped(ctx, mapping) {
|
|
@@ -9326,9 +10195,9 @@ function targetName(target) {
|
|
|
9326
10195
|
return "field" in target ? target.field : `${CUSTOM_PREFIX}${target.customKey}`;
|
|
9327
10196
|
}
|
|
9328
10197
|
function overrideTarget(column, value, mode) {
|
|
9329
|
-
const
|
|
9330
|
-
if (
|
|
9331
|
-
const raw =
|
|
10198
|
+
const text4 = value.trim();
|
|
10199
|
+
if (text4.startsWith(CUSTOM_PREFIX)) {
|
|
10200
|
+
const raw = text4.slice(CUSTOM_PREFIX.length);
|
|
9332
10201
|
const problem = customVariableKeyProblem(raw);
|
|
9333
10202
|
if (problem) {
|
|
9334
10203
|
const why = problem === "reserved_name" ? "is a name Kenso keeps for its own fields" : "is not a usable variable key (a letter, then letters, digits and _)";
|
|
@@ -9336,7 +10205,7 @@ function overrideTarget(column, value, mode) {
|
|
|
9336
10205
|
}
|
|
9337
10206
|
return { customKey: normalizeVariableName(raw) };
|
|
9338
10207
|
}
|
|
9339
|
-
const field = fieldOf(
|
|
10208
|
+
const field = fieldOf(text4);
|
|
9340
10209
|
if (!field) {
|
|
9341
10210
|
throw usageError(`--map "${column}": "${value}" is not a field. Use one of ${FIELD_LIST}, customVariables.<key>, or null.`, { field: "map" });
|
|
9342
10211
|
}
|
|
@@ -9412,10 +10281,10 @@ function buildMapping(headers, overrides, mode) {
|
|
|
9412
10281
|
function readCell(value) {
|
|
9413
10282
|
if (value === void 0) return { kind: "blank" };
|
|
9414
10283
|
if (value === null) return { kind: "null" };
|
|
9415
|
-
const
|
|
9416
|
-
if (
|
|
9417
|
-
if (
|
|
9418
|
-
return { kind: "value", text:
|
|
10284
|
+
const text4 = (typeof value === "string" ? value : typeof value === "object" ? JSON.stringify(value) : String(value)).trim();
|
|
10285
|
+
if (text4 === "") return { kind: "blank" };
|
|
10286
|
+
if (text4 === "null") return { kind: "null" };
|
|
10287
|
+
return { kind: "value", text: text4 };
|
|
9419
10288
|
}
|
|
9420
10289
|
function rowValues(row, mapping, mode) {
|
|
9421
10290
|
const out = { fields: {}, customVariables: {} };
|
|
@@ -9540,34 +10409,34 @@ var init_import_rows = __esm({
|
|
|
9540
10409
|
});
|
|
9541
10410
|
|
|
9542
10411
|
// src/commands/contacts/import-send.ts
|
|
9543
|
-
import { setTimeout as
|
|
10412
|
+
import { setTimeout as delay4 } from "node:timers/promises";
|
|
9544
10413
|
async function abortableSleep(ms, signal) {
|
|
9545
10414
|
try {
|
|
9546
|
-
await
|
|
10415
|
+
await delay4(ms, void 0, { signal });
|
|
9547
10416
|
} catch (err) {
|
|
9548
10417
|
if (signal.aborted) throw new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted });
|
|
9549
10418
|
throw err;
|
|
9550
10419
|
}
|
|
9551
10420
|
}
|
|
9552
|
-
function
|
|
10421
|
+
function text2(value) {
|
|
9553
10422
|
return typeof value === "string" && value.trim() !== "" ? value : void 0;
|
|
9554
10423
|
}
|
|
9555
10424
|
function idText2(value) {
|
|
9556
10425
|
return typeof value === "number" || typeof value === "string" && value !== "" ? String(value) : void 0;
|
|
9557
10426
|
}
|
|
9558
|
-
function mapCreateAnswer(chunk,
|
|
9559
|
-
const data = unwrap(
|
|
9560
|
-
const record =
|
|
10427
|
+
function mapCreateAnswer(chunk, body2) {
|
|
10428
|
+
const data = unwrap(body2);
|
|
10429
|
+
const record = isRecord6(data) ? data : {};
|
|
9561
10430
|
const results = [];
|
|
9562
10431
|
let limitMessage;
|
|
9563
10432
|
const email = (item) => item.contact.email ? { email: item.contact.email } : {};
|
|
9564
10433
|
if (Array.isArray(record.results)) {
|
|
9565
10434
|
for (const entry of record.results) {
|
|
9566
|
-
if (!
|
|
10435
|
+
if (!isRecord6(entry) || typeof entry.index !== "number") continue;
|
|
9567
10436
|
const item = chunk[entry.index];
|
|
9568
10437
|
if (!item) continue;
|
|
9569
|
-
const reason =
|
|
9570
|
-
const message =
|
|
10438
|
+
const reason = text2(entry.reason);
|
|
10439
|
+
const message = text2(entry.message);
|
|
9571
10440
|
const id = idText2(entry.id);
|
|
9572
10441
|
const base = {
|
|
9573
10442
|
row: item.row,
|
|
@@ -9588,9 +10457,9 @@ function mapCreateAnswer(chunk, body) {
|
|
|
9588
10457
|
}
|
|
9589
10458
|
const failed = /* @__PURE__ */ new Map();
|
|
9590
10459
|
for (const entry of Array.isArray(record.failed) ? record.failed : []) {
|
|
9591
|
-
if (!
|
|
9592
|
-
const error =
|
|
9593
|
-
failed.set(entry.index, { code:
|
|
10460
|
+
if (!isRecord6(entry) || typeof entry.index !== "number") continue;
|
|
10461
|
+
const error = isRecord6(entry.error) ? entry.error : entry;
|
|
10462
|
+
failed.set(entry.index, { code: text2(error.code) ?? "failed", message: text2(error.message) });
|
|
9594
10463
|
}
|
|
9595
10464
|
chunk.forEach((item, index) => {
|
|
9596
10465
|
const failure = failed.get(index);
|
|
@@ -9643,20 +10512,20 @@ var init_import_send = __esm({
|
|
|
9643
10512
|
});
|
|
9644
10513
|
|
|
9645
10514
|
// src/batch/jobs.ts
|
|
9646
|
-
import { setTimeout as
|
|
9647
|
-
function
|
|
10515
|
+
import { setTimeout as delay5 } from "node:timers/promises";
|
|
10516
|
+
function interrupted5() {
|
|
9648
10517
|
return new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted });
|
|
9649
10518
|
}
|
|
9650
10519
|
async function defaultSleep(ms, signal) {
|
|
9651
10520
|
try {
|
|
9652
|
-
await
|
|
10521
|
+
await delay5(ms, void 0, signal ? { signal } : void 0);
|
|
9653
10522
|
} catch (err) {
|
|
9654
|
-
if (signal?.aborted) throw
|
|
10523
|
+
if (signal?.aborted) throw interrupted5();
|
|
9655
10524
|
throw err;
|
|
9656
10525
|
}
|
|
9657
10526
|
}
|
|
9658
|
-
function toJob(
|
|
9659
|
-
const data = unwrap(
|
|
10527
|
+
function toJob(body2, jobId, type) {
|
|
10528
|
+
const data = unwrap(body2);
|
|
9660
10529
|
const record = data !== null && typeof data === "object" && !Array.isArray(data) ? data : {};
|
|
9661
10530
|
const rawId = record.id;
|
|
9662
10531
|
return {
|
|
@@ -9669,29 +10538,29 @@ function toJob(body, jobId, type) {
|
|
|
9669
10538
|
async function waitForJob(client, jobId, type, opts = {}) {
|
|
9670
10539
|
const id = String(jobId).trim();
|
|
9671
10540
|
if (id === "") throw usageError("Name the job id.", { field: "jobId" });
|
|
9672
|
-
const
|
|
10541
|
+
const timeoutMs2 = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
9673
10542
|
const intervalMs = opts.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
9674
10543
|
const now = opts.now ?? Date.now;
|
|
9675
10544
|
const sleep = opts.sleep ?? ((ms) => defaultSleep(ms, opts.signal));
|
|
9676
10545
|
const started = now();
|
|
9677
10546
|
for (; ; ) {
|
|
9678
|
-
if (opts.signal?.aborted) throw
|
|
10547
|
+
if (opts.signal?.aborted) throw interrupted5();
|
|
9679
10548
|
const res = await client.request({ method: "GET", path: `/v1/jobs/${encodeURIComponent(id)}`, query: { type }, signal: opts.signal });
|
|
9680
10549
|
const job = toJob(res.body, id, type);
|
|
9681
10550
|
if (TERMINAL_JOB_STATUSES.includes(job.status)) return job;
|
|
9682
10551
|
opts.onProgress?.(job);
|
|
9683
10552
|
const elapsed = now() - started;
|
|
9684
|
-
if (elapsed >=
|
|
10553
|
+
if (elapsed >= timeoutMs2) {
|
|
9685
10554
|
throw new KensoError({
|
|
9686
10555
|
code: "job_timeout",
|
|
9687
|
-
message: `Job ${id} is still ${job.status} after ${Math.round(
|
|
10556
|
+
message: `Job ${id} is still ${job.status} after ${Math.round(timeoutMs2 / 1e3)} s.`,
|
|
9688
10557
|
exitCode: ExitCode.Error,
|
|
9689
10558
|
hint: "The job keeps running on the server. Wait for it again.",
|
|
9690
10559
|
next: `kenso jobs wait ${id} --type ${type}`
|
|
9691
10560
|
});
|
|
9692
10561
|
}
|
|
9693
10562
|
const interval = elapsed >= FAST_PHASE_MS ? Math.max(intervalMs, SLOW_INTERVAL_MS) : intervalMs;
|
|
9694
|
-
await sleep(Math.min(interval, Math.max(0,
|
|
10563
|
+
await sleep(Math.min(interval, Math.max(0, timeoutMs2 - elapsed)));
|
|
9695
10564
|
}
|
|
9696
10565
|
}
|
|
9697
10566
|
var TERMINAL_JOB_STATUSES, DEFAULT_TIMEOUT_MS, DEFAULT_INTERVAL_MS, SLOW_INTERVAL_MS, FAST_PHASE_MS;
|
|
@@ -9715,8 +10584,8 @@ __export(wait_exports, {
|
|
|
9715
10584
|
default: () => wait_default,
|
|
9716
10585
|
parseDuration: () => parseDuration
|
|
9717
10586
|
});
|
|
9718
|
-
function parseDuration(
|
|
9719
|
-
const match = /^(\d+(?:\.\d+)?)\s*([smh]?)$/i.exec(
|
|
10587
|
+
function parseDuration(text4) {
|
|
10588
|
+
const match = /^(\d+(?:\.\d+)?)\s*([smh]?)$/i.exec(text4.trim());
|
|
9720
10589
|
if (!match) return void 0;
|
|
9721
10590
|
const ms = Number(match[1]) * (UNIT_MS[(match[2] || "s").toLowerCase()] ?? 1e3);
|
|
9722
10591
|
return Number.isFinite(ms) ? Math.round(ms) : void 0;
|
|
@@ -9747,12 +10616,12 @@ var init_wait = __esm({
|
|
|
9747
10616
|
const type = typeof flags.type === "string" ? flags.type.trim() : "";
|
|
9748
10617
|
if (type === "") throw usageError("--type needs a value, for example contact_import.", { field: "type" });
|
|
9749
10618
|
const timeoutText = typeof flags.timeout === "string" ? flags.timeout : "10m";
|
|
9750
|
-
const
|
|
9751
|
-
if (
|
|
10619
|
+
const timeoutMs2 = parseDuration(timeoutText);
|
|
10620
|
+
if (timeoutMs2 === void 0) {
|
|
9752
10621
|
throw usageError(`--timeout "${timeoutText}" is not a duration.`, { field: "timeout", hint: "Use 90s, 10m, 1h or a number of seconds." });
|
|
9753
10622
|
}
|
|
9754
10623
|
const job = await waitForJob(ctx.client, jobId, type, {
|
|
9755
|
-
timeoutMs,
|
|
10624
|
+
timeoutMs: timeoutMs2,
|
|
9756
10625
|
signal: ctx.signal,
|
|
9757
10626
|
onProgress: (j) => {
|
|
9758
10627
|
const done2 = j.progress ? `, ${j.progress.completed}/${j.progress.total ?? "?"}` : "";
|
|
@@ -9825,8 +10694,8 @@ function report(campaignId, job) {
|
|
|
9825
10694
|
}
|
|
9826
10695
|
async function serverImport(ctx, opts) {
|
|
9827
10696
|
const timeoutText = opts.timeout ?? DEFAULT_TIMEOUT;
|
|
9828
|
-
const
|
|
9829
|
-
if (
|
|
10697
|
+
const timeoutMs2 = parseDuration(timeoutText);
|
|
10698
|
+
if (timeoutMs2 === void 0) throw usageError(`--timeout "${timeoutText}" is not a duration.`, { field: "timeout", hint: "Use 90s, 10m, 1h or a number of seconds." });
|
|
9830
10699
|
const upload2 = await readUpload2(opts.file);
|
|
9831
10700
|
const mappings = opts.mapping ? columnMappings(opts.mapping) : void 0;
|
|
9832
10701
|
if (opts.dryRun) {
|
|
@@ -9849,12 +10718,12 @@ async function serverImport(ctx, opts) {
|
|
|
9849
10718
|
form.append("file", new Blob([upload2.bytes], { type: "text/csv" }), upload2.name);
|
|
9850
10719
|
const res = await ctx.client.request({ method: "POST", path: "/v1/contact-imports", form, signal: ctx.signal });
|
|
9851
10720
|
const created = unwrap(res.body);
|
|
9852
|
-
const jobId =
|
|
10721
|
+
const jobId = isRecord6(created) ? created.id : void 0;
|
|
9853
10722
|
if (typeof jobId !== "number" && (typeof jobId !== "string" || jobId === "")) {
|
|
9854
10723
|
throw new KensoError({ code: "unexpected_response", message: "The import was accepted, but the answer had no job id.", exitCode: ExitCode.Error });
|
|
9855
10724
|
}
|
|
9856
10725
|
const job = await waitForJob(ctx.client, jobId, "contact_import", {
|
|
9857
|
-
timeoutMs,
|
|
10726
|
+
timeoutMs: timeoutMs2,
|
|
9858
10727
|
signal: ctx.signal,
|
|
9859
10728
|
onProgress: (j) => ctx.output.progress(`import job ${j.id}: ${j.status}${j.progress ? `, ${j.progress.completed}/${j.progress.total ?? "?"}` : ""}`)
|
|
9860
10729
|
});
|
|
@@ -9924,7 +10793,7 @@ async function readOverrides(ctx, flags, file) {
|
|
|
9924
10793
|
async function readCampaign(ctx, campaignId) {
|
|
9925
10794
|
const res = await ctx.client.request({ method: "GET", path: `/v1/campaigns/${campaignId}` });
|
|
9926
10795
|
const campaign = unwrap(res.body);
|
|
9927
|
-
const channel =
|
|
10796
|
+
const channel = isRecord6(campaign) && typeof campaign.channel === "string" ? campaign.channel.toLowerCase() : "";
|
|
9928
10797
|
return { linkedInOnly: LINKEDIN_ONLY_CHANNELS.has(channel) ? true : void 0 };
|
|
9929
10798
|
}
|
|
9930
10799
|
async function estimate(ctx, leadCount) {
|
|
@@ -9932,7 +10801,7 @@ async function estimate(ctx, leadCount) {
|
|
|
9932
10801
|
try {
|
|
9933
10802
|
const res = await ctx.client.request({ method: "POST", path: "/v1/credits/estimates", body: { kind: "leads", leadCount } });
|
|
9934
10803
|
const data = unwrap(res.body);
|
|
9935
|
-
if (!
|
|
10804
|
+
if (!isRecord6(data)) return { estimate: data ?? null };
|
|
9936
10805
|
const credits = (key) => typeof data[key] === "number" ? data[key] / 1e3 : void 0;
|
|
9937
10806
|
return {
|
|
9938
10807
|
estimate: data,
|
|
@@ -10071,11 +10940,11 @@ __export(update_exports, {
|
|
|
10071
10940
|
});
|
|
10072
10941
|
async function emailIndex(ctx, campaignId) {
|
|
10073
10942
|
const index = /* @__PURE__ */ new Map();
|
|
10074
|
-
let
|
|
10943
|
+
let read2 = 0;
|
|
10075
10944
|
for await (const contact of ctx.client.paginate({ method: "GET", path: "/v1/contacts", query: { campaignId } }, { pageSize: PAGE_SIZE })) {
|
|
10076
|
-
|
|
10077
|
-
if (
|
|
10078
|
-
if (!
|
|
10945
|
+
read2++;
|
|
10946
|
+
if (read2 % 2e3 === 0) ctx.output.progress(`read ${read2} contacts of campaign ${campaignId}`);
|
|
10947
|
+
if (!isRecord6(contact)) continue;
|
|
10079
10948
|
const email = typeof contact.email === "string" ? contact.email.trim().toLowerCase() : "";
|
|
10080
10949
|
const id = typeof contact.id === "number" ? contact.id : typeof contact.id === "string" ? positiveId(contact.id) : void 0;
|
|
10081
10950
|
if (email !== "" && id !== void 0 && !index.has(email)) index.set(email, id);
|
|
@@ -10134,13 +11003,13 @@ function planUpdate(rows, mapping, match, emails) {
|
|
|
10134
11003
|
}
|
|
10135
11004
|
return { items, local, matched, unmatched };
|
|
10136
11005
|
}
|
|
10137
|
-
function mapUpdateAnswer(chunk,
|
|
10138
|
-
const data = unwrap(
|
|
10139
|
-
const entries2 =
|
|
11006
|
+
function mapUpdateAnswer(chunk, body2) {
|
|
11007
|
+
const data = unwrap(body2);
|
|
11008
|
+
const entries2 = isRecord6(data) && Array.isArray(data.results) ? data.results : [];
|
|
10140
11009
|
const rowOf = new Map(chunk.map((u) => [u.item.contactId, u.row]));
|
|
10141
11010
|
const results = [];
|
|
10142
11011
|
for (const entry of entries2) {
|
|
10143
|
-
if (!
|
|
11012
|
+
if (!isRecord6(entry)) continue;
|
|
10144
11013
|
const contactId = typeof entry.contactId === "number" ? entry.contactId : Number(entry.contactId);
|
|
10145
11014
|
const row = rowOf.get(contactId);
|
|
10146
11015
|
if (row === void 0) continue;
|
|
@@ -10282,9 +11151,9 @@ function chunkAttempts(env) {
|
|
|
10282
11151
|
return async (runId, chunkIndex) => {
|
|
10283
11152
|
earlier ??= (async () => {
|
|
10284
11153
|
const path2 = join11(runsRoot(env), runId, ATTEMPTS_FILE);
|
|
10285
|
-
const
|
|
11154
|
+
const text4 = await readFile8(path2, "utf8").catch(() => "");
|
|
10286
11155
|
const indexes3 = new Set(
|
|
10287
|
-
|
|
11156
|
+
text4.split("\n").filter((line) => line.trim() !== "").map(Number)
|
|
10288
11157
|
);
|
|
10289
11158
|
return { path: path2, indexes: indexes3 };
|
|
10290
11159
|
})();
|
|
@@ -10313,7 +11182,7 @@ __export(bulk_ids_exports, {
|
|
|
10313
11182
|
idsFromFile: () => idsFromFile,
|
|
10314
11183
|
mapBulkAnswer: () => mapBulkAnswer,
|
|
10315
11184
|
markRemovedEarlier: () => markRemovedEarlier,
|
|
10316
|
-
pause: () =>
|
|
11185
|
+
pause: () => pause2,
|
|
10317
11186
|
remove: () => remove,
|
|
10318
11187
|
restore: () => restore,
|
|
10319
11188
|
resume: () => resume
|
|
@@ -10325,11 +11194,11 @@ function idItems(raw) {
|
|
|
10325
11194
|
const items = [];
|
|
10326
11195
|
const invalid = [];
|
|
10327
11196
|
const firstRowOf = /* @__PURE__ */ new Map();
|
|
10328
|
-
raw.forEach((
|
|
11197
|
+
raw.forEach((text4, i) => {
|
|
10329
11198
|
const row = i + 1;
|
|
10330
|
-
const id = positiveId(
|
|
11199
|
+
const id = positiveId(text4);
|
|
10331
11200
|
if (id === void 0) {
|
|
10332
|
-
invalid.push(invalidRow(row, "invalid_id", `"${
|
|
11201
|
+
invalid.push(invalidRow(row, "invalid_id", `"${text4}" is not a contact id.`));
|
|
10333
11202
|
return;
|
|
10334
11203
|
}
|
|
10335
11204
|
const first = firstRowOf.get(id);
|
|
@@ -10346,9 +11215,9 @@ async function idsFromFile(ctx, path) {
|
|
|
10346
11215
|
let ids2;
|
|
10347
11216
|
let input;
|
|
10348
11217
|
if (path === "-") {
|
|
10349
|
-
const
|
|
10350
|
-
ids2 = await readIds("-", { stdin: Readable.from([
|
|
10351
|
-
input = { path: "-", sha256: createHash4("sha256").update(
|
|
11218
|
+
const text4 = await readStream(ctx.stdin ?? process.stdin);
|
|
11219
|
+
ids2 = await readIds("-", { stdin: Readable.from([text4]) });
|
|
11220
|
+
input = { path: "-", sha256: createHash4("sha256").update(text4).digest("hex") };
|
|
10352
11221
|
} else {
|
|
10353
11222
|
ids2 = await readIds(path);
|
|
10354
11223
|
input = { path: resolve7(path), sha256: await fileSha256(path) };
|
|
@@ -10357,10 +11226,10 @@ async function idsFromFile(ctx, path) {
|
|
|
10357
11226
|
}
|
|
10358
11227
|
async function searchIds(ctx, where) {
|
|
10359
11228
|
const filters = await readDataArg(where, ctx.stdin);
|
|
10360
|
-
if (!
|
|
10361
|
-
const
|
|
10362
|
-
delete
|
|
10363
|
-
delete
|
|
11229
|
+
if (!isRecord6(filters)) throw usageError("--where must be a JSON object of contacts search filters.", { field: "where" });
|
|
11230
|
+
const body2 = { ...filters };
|
|
11231
|
+
delete body2.cursor;
|
|
11232
|
+
delete body2.limit;
|
|
10364
11233
|
const ids2 = [];
|
|
10365
11234
|
const seen = /* @__PURE__ */ new Set();
|
|
10366
11235
|
let cursor2;
|
|
@@ -10368,15 +11237,15 @@ async function searchIds(ctx, where) {
|
|
|
10368
11237
|
const res = await ctx.client.request({
|
|
10369
11238
|
method: "POST",
|
|
10370
11239
|
path: "/v1/contacts/search",
|
|
10371
|
-
body: { ...
|
|
11240
|
+
body: { ...body2, limit: SEARCH_PAGE, ...cursor2 ? { cursor: cursor2 } : {} },
|
|
10372
11241
|
// A search reads only: resending it is safe.
|
|
10373
11242
|
retrySafe: true
|
|
10374
11243
|
});
|
|
10375
11244
|
const page = unwrap(res.body);
|
|
10376
|
-
const data =
|
|
10377
|
-
for (const contact of data) if (
|
|
11245
|
+
const data = isRecord6(res.body) && Array.isArray(res.body.data) ? res.body.data : Array.isArray(page) ? page : [];
|
|
11246
|
+
for (const contact of data) if (isRecord6(contact) && (typeof contact.id === "number" || typeof contact.id === "string")) ids2.push(String(contact.id));
|
|
10378
11247
|
ctx.output.progress(`found ${ids2.length} contacts`);
|
|
10379
|
-
const pagination =
|
|
11248
|
+
const pagination = isRecord6(res.body) && isRecord6(res.body.pagination) ? res.body.pagination : void 0;
|
|
10380
11249
|
const next = pagination?.nextCursor;
|
|
10381
11250
|
if (pagination?.hasMore !== true || typeof next !== "string" || next === "" || seen.has(next)) break;
|
|
10382
11251
|
seen.add(next);
|
|
@@ -10422,14 +11291,14 @@ async function collectIds(ctx, flags, kind, dryRun2) {
|
|
|
10422
11291
|
if (where !== void 0) return idsFromWhere(ctx, kind, flags, where, dryRun2);
|
|
10423
11292
|
return idsFromRun(ctx, run);
|
|
10424
11293
|
}
|
|
10425
|
-
function mapBulkAnswer(chunk,
|
|
10426
|
-
const data = unwrap(
|
|
10427
|
-
const record =
|
|
11294
|
+
function mapBulkAnswer(chunk, body2) {
|
|
11295
|
+
const data = unwrap(body2);
|
|
11296
|
+
const record = isRecord6(data) ? data : {};
|
|
10428
11297
|
const succeeded = new Set((Array.isArray(record.succeeded) ? record.succeeded : []).map((id) => String(id)));
|
|
10429
11298
|
const failed = /* @__PURE__ */ new Map();
|
|
10430
11299
|
for (const entry of Array.isArray(record.failed) ? record.failed : []) {
|
|
10431
|
-
if (!
|
|
10432
|
-
const error =
|
|
11300
|
+
if (!isRecord6(entry) || entry.id === void 0 || entry.id === null) continue;
|
|
11301
|
+
const error = isRecord6(entry.error) ? entry.error : entry;
|
|
10433
11302
|
const code = typeof error.code === "string" && error.code !== "" ? error.code : "failed";
|
|
10434
11303
|
failed.set(String(entry.id), { code, ...typeof error.message === "string" && error.message !== "" ? { message: error.message } : {} });
|
|
10435
11304
|
}
|
|
@@ -10541,7 +11410,7 @@ function bulkCommand(kind) {
|
|
|
10541
11410
|
}
|
|
10542
11411
|
};
|
|
10543
11412
|
}
|
|
10544
|
-
var CHUNK_SIZE4, SEARCH_PAGE, CONFIRM_ABOVE, REMOVE_RESEND_DELAY_MS, NOTHING_TO_DO, ROUTES, remove, restore,
|
|
11413
|
+
var CHUNK_SIZE4, SEARCH_PAGE, CONFIRM_ABOVE, REMOVE_RESEND_DELAY_MS, NOTHING_TO_DO, ROUTES, remove, restore, pause2, resume;
|
|
10545
11414
|
var init_bulk_ids = __esm({
|
|
10546
11415
|
"src/commands/contacts/bulk-ids.ts"() {
|
|
10547
11416
|
"use strict";
|
|
@@ -10569,7 +11438,7 @@ var init_bulk_ids = __esm({
|
|
|
10569
11438
|
};
|
|
10570
11439
|
remove = bulkCommand("remove");
|
|
10571
11440
|
restore = bulkCommand("restore");
|
|
10572
|
-
|
|
11441
|
+
pause2 = bulkCommand("pause");
|
|
10573
11442
|
resume = bulkCommand("resume");
|
|
10574
11443
|
}
|
|
10575
11444
|
});
|
|
@@ -10676,7 +11545,7 @@ function idText3(value) {
|
|
|
10676
11545
|
return typeof value === "number" || typeof value === "string" && value !== "" ? String(value) : void 0;
|
|
10677
11546
|
}
|
|
10678
11547
|
function exportIdOf(job) {
|
|
10679
|
-
const resource =
|
|
11548
|
+
const resource = isRecord6(job.resource) ? idText3(job.resource.id) : void 0;
|
|
10680
11549
|
if (resource) return resource;
|
|
10681
11550
|
const url = typeof job.downloadUrl === "string" ? CONTENT_PATH.exec(job.downloadUrl)?.[1] : void 0;
|
|
10682
11551
|
return url ?? String(job.id);
|
|
@@ -10708,15 +11577,15 @@ async function download(ctx, job, exportId, out) {
|
|
|
10708
11577
|
hint: `Download it with: kenso contact-exports content --export-id ${exportId}`
|
|
10709
11578
|
});
|
|
10710
11579
|
}
|
|
10711
|
-
const
|
|
11580
|
+
const body2 = typeof res.body === "string" ? res.body : res.body === null ? "" : JSON.stringify(res.body);
|
|
10712
11581
|
const path = resolve8(out);
|
|
10713
11582
|
try {
|
|
10714
|
-
await writeFile3(path,
|
|
11583
|
+
await writeFile3(path, body2, { mode: 384 });
|
|
10715
11584
|
} catch (err) {
|
|
10716
11585
|
const code = err.code;
|
|
10717
11586
|
throw new KensoError({ code: "file_unwritable", message: `Cannot write ${out}${code ? ` (${code})` : ""}.`, exitCode: ExitCode.Usage, field: "out" });
|
|
10718
11587
|
}
|
|
10719
|
-
return { rows: countRows(
|
|
11588
|
+
return { rows: countRows(body2), path };
|
|
10720
11589
|
}
|
|
10721
11590
|
var COMMAND4, JOB_TYPE, DEFAULT_TIMEOUT2, CONTENT_PATH, command17, export_default;
|
|
10722
11591
|
var init_export = __esm({
|
|
@@ -10751,12 +11620,12 @@ var init_export = __esm({
|
|
|
10751
11620
|
const campaignId = idFlag(flags, "campaign", COMMAND4);
|
|
10752
11621
|
const out = stringFlag2(flags, "out");
|
|
10753
11622
|
const timeoutText = stringFlag2(flags, "timeout") ?? DEFAULT_TIMEOUT2;
|
|
10754
|
-
const
|
|
10755
|
-
if (
|
|
11623
|
+
const timeoutMs2 = parseDuration(timeoutText);
|
|
11624
|
+
if (timeoutMs2 === void 0) throw usageError(`--timeout "${timeoutText}" is not a duration.`, { field: "timeout", hint: "Use 90s, 10m, 1h or a number of seconds." });
|
|
10756
11625
|
const res = await ctx.client.request({ method: "POST", path: "/v1/contact-exports", body: { kind: "contacts", campaignId }, signal: ctx.signal });
|
|
10757
11626
|
const created = unwrap(res.body);
|
|
10758
|
-
const jobId =
|
|
10759
|
-
if (!
|
|
11627
|
+
const jobId = isRecord6(created) ? idText3(created.id) : void 0;
|
|
11628
|
+
if (!isRecord6(created) || jobId === void 0) {
|
|
10760
11629
|
throw new KensoError({ code: "unexpected_response", message: "The export was created, but the answer had no job id.", exitCode: ExitCode.Error });
|
|
10761
11630
|
}
|
|
10762
11631
|
if (out === void 0 && flags.wait !== true) {
|
|
@@ -10769,7 +11638,7 @@ var init_export = __esm({
|
|
|
10769
11638
|
return ExitCode.Ok;
|
|
10770
11639
|
}
|
|
10771
11640
|
const job = await waitForJob(ctx.client, jobId, JOB_TYPE, {
|
|
10772
|
-
timeoutMs,
|
|
11641
|
+
timeoutMs: timeoutMs2,
|
|
10773
11642
|
signal: ctx.signal,
|
|
10774
11643
|
onProgress: (j) => ctx.output.progress(`export job ${j.id}: ${j.status}`)
|
|
10775
11644
|
});
|
|
@@ -10796,11 +11665,11 @@ var init_export = __esm({
|
|
|
10796
11665
|
});
|
|
10797
11666
|
|
|
10798
11667
|
// src/commands/contacts/index.ts
|
|
10799
|
-
var
|
|
11668
|
+
var actions8;
|
|
10800
11669
|
var init_contacts = __esm({
|
|
10801
11670
|
"src/commands/contacts/index.ts"() {
|
|
10802
11671
|
"use strict";
|
|
10803
|
-
|
|
11672
|
+
actions8 = {
|
|
10804
11673
|
import: () => Promise.resolve().then(() => (init_import2(), import_exports2)).then((m) => m.default),
|
|
10805
11674
|
update: () => Promise.resolve().then(() => (init_update(), update_exports)).then((m) => m.default),
|
|
10806
11675
|
remove: () => Promise.resolve().then(() => (init_bulk_ids(), bulk_ids_exports)).then((m) => m.remove),
|
|
@@ -10840,8 +11709,8 @@ function printJson(ctx, value) {
|
|
|
10840
11709
|
async function entries() {
|
|
10841
11710
|
const out = [];
|
|
10842
11711
|
for (const [resource, area] of Object.entries(handWritten)) {
|
|
10843
|
-
for (const [action,
|
|
10844
|
-
const spec = await
|
|
11712
|
+
for (const [action, load2] of Object.entries(area)) {
|
|
11713
|
+
const spec = await load2();
|
|
10845
11714
|
out.push({ resource, action, command: commandName(spec), summary: spec.summary, gates: spec.beta?.featureGates, spec });
|
|
10846
11715
|
}
|
|
10847
11716
|
}
|
|
@@ -10886,7 +11755,7 @@ function detailOf(entry) {
|
|
|
10886
11755
|
const spec = entry.spec;
|
|
10887
11756
|
const ids2 = entry.op ? [entry.op.id] : spec?.operationIds ?? [];
|
|
10888
11757
|
const op = entry.op ?? (ids2.length === 1 ? findOperationById(ids2[0]) : void 0);
|
|
10889
|
-
const
|
|
11758
|
+
const body2 = entry.op?.body;
|
|
10890
11759
|
const out = {
|
|
10891
11760
|
command: entry.command,
|
|
10892
11761
|
summary: entry.summary,
|
|
@@ -10896,7 +11765,7 @@ function detailOf(entry) {
|
|
|
10896
11765
|
operationIds: ids2,
|
|
10897
11766
|
flags: flagsOf(entry),
|
|
10898
11767
|
positionals: (spec?.positionals ?? []).map((p) => ({ name: p.name, required: p.required === true, description: p.description })),
|
|
10899
|
-
body:
|
|
11768
|
+
body: body2 ? { format: body2.format, ...body2.schema !== void 0 ? { schema: body2.schema } : {}, ...body2.schemaTruncated ? { schemaTruncated: true } : {} } : null,
|
|
10900
11769
|
list: op?.list ?? false,
|
|
10901
11770
|
examples: entry.op ? operationExamples(entry.op) : spec?.examples ?? [],
|
|
10902
11771
|
beta: entry.gates !== void 0,
|
|
@@ -10974,11 +11843,11 @@ var init_describe = __esm({
|
|
|
10974
11843
|
});
|
|
10975
11844
|
|
|
10976
11845
|
// src/commands/describe/index.ts
|
|
10977
|
-
var
|
|
11846
|
+
var actions9;
|
|
10978
11847
|
var init_describe2 = __esm({
|
|
10979
11848
|
"src/commands/describe/index.ts"() {
|
|
10980
11849
|
"use strict";
|
|
10981
|
-
|
|
11850
|
+
actions9 = {
|
|
10982
11851
|
"": () => Promise.resolve().then(() => (init_describe(), describe_exports)).then((m) => m.default)
|
|
10983
11852
|
};
|
|
10984
11853
|
}
|
|
@@ -11027,8 +11896,8 @@ var init_docs = __esm({
|
|
|
11027
11896
|
next: "kenso docs"
|
|
11028
11897
|
});
|
|
11029
11898
|
}
|
|
11030
|
-
const
|
|
11031
|
-
if (
|
|
11899
|
+
const text4 = await topicText(topic);
|
|
11900
|
+
if (text4 === void 0) {
|
|
11032
11901
|
throw new KensoError({
|
|
11033
11902
|
code: "docs_not_found",
|
|
11034
11903
|
message: `docs/${topic.file} is not in this install of the CLI.`,
|
|
@@ -11037,7 +11906,7 @@ var init_docs = __esm({
|
|
|
11037
11906
|
next: "kenso describe --all-commands"
|
|
11038
11907
|
});
|
|
11039
11908
|
}
|
|
11040
|
-
ctx.output.writeRaw(
|
|
11909
|
+
ctx.output.writeRaw(text4.endsWith("\n") ? text4 : `${text4}
|
|
11041
11910
|
`);
|
|
11042
11911
|
return ExitCode.Ok;
|
|
11043
11912
|
}
|
|
@@ -11047,11 +11916,11 @@ var init_docs = __esm({
|
|
|
11047
11916
|
});
|
|
11048
11917
|
|
|
11049
11918
|
// src/commands/docs/index.ts
|
|
11050
|
-
var
|
|
11919
|
+
var actions10;
|
|
11051
11920
|
var init_docs2 = __esm({
|
|
11052
11921
|
"src/commands/docs/index.ts"() {
|
|
11053
11922
|
"use strict";
|
|
11054
|
-
|
|
11923
|
+
actions10 = {
|
|
11055
11924
|
"": () => Promise.resolve().then(() => (init_docs(), docs_exports)).then((m) => m.default)
|
|
11056
11925
|
};
|
|
11057
11926
|
}
|
|
@@ -11080,7 +11949,7 @@ function configCheck(env) {
|
|
|
11080
11949
|
const octal = mode.toString(8).padStart(4, "0");
|
|
11081
11950
|
return mode === 384 ? { name: "config_permissions", ok: true, detail: `${file} is ${octal}` } : { name: "config_permissions", ok: false, detail: `${file} is ${octal}: run chmod 600 ${file}` };
|
|
11082
11951
|
}
|
|
11083
|
-
var MIN_NODE_MAJOR, command20,
|
|
11952
|
+
var MIN_NODE_MAJOR, command20, actions11;
|
|
11084
11953
|
var init_doctor = __esm({
|
|
11085
11954
|
"src/commands/doctor/index.ts"() {
|
|
11086
11955
|
"use strict";
|
|
@@ -11153,18 +12022,18 @@ var init_doctor = __esm({
|
|
|
11153
12022
|
return keyFailed ? ExitCode.Auth : ExitCode.Error;
|
|
11154
12023
|
}
|
|
11155
12024
|
};
|
|
11156
|
-
|
|
12025
|
+
actions11 = {
|
|
11157
12026
|
"": async () => command20
|
|
11158
12027
|
};
|
|
11159
12028
|
}
|
|
11160
12029
|
});
|
|
11161
12030
|
|
|
11162
12031
|
// src/commands/jobs/index.ts
|
|
11163
|
-
var
|
|
12032
|
+
var actions12;
|
|
11164
12033
|
var init_jobs2 = __esm({
|
|
11165
12034
|
"src/commands/jobs/index.ts"() {
|
|
11166
12035
|
"use strict";
|
|
11167
|
-
|
|
12036
|
+
actions12 = {
|
|
11168
12037
|
wait: () => Promise.resolve().then(() => (init_wait(), wait_exports)).then((m) => m.default)
|
|
11169
12038
|
};
|
|
11170
12039
|
}
|
|
@@ -11175,10 +12044,10 @@ var tail_exports = {};
|
|
|
11175
12044
|
__export(tail_exports, {
|
|
11176
12045
|
default: () => tail_default
|
|
11177
12046
|
});
|
|
11178
|
-
import { setTimeout as
|
|
11179
|
-
function duration(
|
|
11180
|
-
const days = /^(\d+(?:\.\d+)?)\s*d$/i.exec(
|
|
11181
|
-
return days ? Math.round(Number(days[1]) * 864e5) : parseDuration(
|
|
12047
|
+
import { setTimeout as delay6 } from "node:timers/promises";
|
|
12048
|
+
function duration(text4) {
|
|
12049
|
+
const days = /^(\d+(?:\.\d+)?)\s*d$/i.exec(text4.trim());
|
|
12050
|
+
return days ? Math.round(Number(days[1]) * 864e5) : parseDuration(text4);
|
|
11182
12051
|
}
|
|
11183
12052
|
function nonEmpty2(flags, name) {
|
|
11184
12053
|
const value = flags[name];
|
|
@@ -11253,9 +12122,9 @@ var init_tail = __esm({
|
|
|
11253
12122
|
let newest;
|
|
11254
12123
|
const fetchPage = async (after, cursor2) => {
|
|
11255
12124
|
const res = await ctx.client.request({ method: "GET", path: "/v1/api-requests", query: query(after, cursor2) });
|
|
11256
|
-
const
|
|
12125
|
+
const body2 = res.body;
|
|
11257
12126
|
const rows = unwrap(res.body);
|
|
11258
|
-
const next =
|
|
12127
|
+
const next = body2?.pagination?.hasMore === true ? body2.pagination.nextCursor : void 0;
|
|
11259
12128
|
return { rows: Array.isArray(rows) ? rows : [], nextCursor: next || void 0 };
|
|
11260
12129
|
};
|
|
11261
12130
|
const pollOnce = async () => {
|
|
@@ -11299,22 +12168,22 @@ var init_tail = __esm({
|
|
|
11299
12168
|
}
|
|
11300
12169
|
};
|
|
11301
12170
|
let first = true;
|
|
11302
|
-
let
|
|
12171
|
+
let backoffMs2 = intervalMs;
|
|
11303
12172
|
while (!ctx.signal.aborted) {
|
|
11304
12173
|
try {
|
|
11305
12174
|
await pollOnce();
|
|
11306
12175
|
first = false;
|
|
11307
|
-
|
|
12176
|
+
backoffMs2 = intervalMs;
|
|
11308
12177
|
} catch (err) {
|
|
11309
12178
|
if (ctx.signal.aborted) break;
|
|
11310
12179
|
if (first && err instanceof KensoError && err.httpStatus === 404 && err.field === void 0) {
|
|
11311
12180
|
throw new KensoError({ code: "not_found", message: "Request logs are not on for this workspace yet.", exitCode: ExitCode.NotFound, httpStatus: 404 });
|
|
11312
12181
|
}
|
|
11313
12182
|
if (!survivable(err)) throw err;
|
|
11314
|
-
|
|
11315
|
-
ctx.output.warn(`Polling failed (${err.message}); trying again in ${
|
|
12183
|
+
backoffMs2 = err instanceof KensoError && err.exitCode === ExitCode.RateLimited ? Math.max(intervalMs, RATE_LIMITED_WAIT_MS) : intervalMs;
|
|
12184
|
+
ctx.output.warn(`Polling failed (${err.message}); trying again in ${backoffMs2 / 1e3} s.`);
|
|
11316
12185
|
}
|
|
11317
|
-
await
|
|
12186
|
+
await delay6(backoffMs2, void 0, { signal: ctx.signal }).catch(() => void 0);
|
|
11318
12187
|
}
|
|
11319
12188
|
return ExitCode.Ok;
|
|
11320
12189
|
}
|
|
@@ -11324,11 +12193,11 @@ var init_tail = __esm({
|
|
|
11324
12193
|
});
|
|
11325
12194
|
|
|
11326
12195
|
// src/commands/logs/index.ts
|
|
11327
|
-
var
|
|
12196
|
+
var actions13;
|
|
11328
12197
|
var init_logs = __esm({
|
|
11329
12198
|
"src/commands/logs/index.ts"() {
|
|
11330
12199
|
"use strict";
|
|
11331
|
-
|
|
12200
|
+
actions13 = {
|
|
11332
12201
|
tail: () => Promise.resolve().then(() => (init_tail(), tail_exports)).then((m) => m.default)
|
|
11333
12202
|
};
|
|
11334
12203
|
}
|
|
@@ -11360,11 +12229,11 @@ function mcpClient(ctx) {
|
|
|
11360
12229
|
onResponse: ctx.flags.verbose ? ({ method, status, ms, error }) => ctx.output.info(`POST ${url} ${method} -> ${status ?? error ?? "error"} (${ms} ms)`) : void 0
|
|
11361
12230
|
});
|
|
11362
12231
|
}
|
|
11363
|
-
function writeRaw(ctx,
|
|
11364
|
-
ctx.output.writeRaw(
|
|
12232
|
+
function writeRaw(ctx, text4) {
|
|
12233
|
+
ctx.output.writeRaw(text4.endsWith("\n") ? text4 : `${text4}
|
|
11365
12234
|
`);
|
|
11366
12235
|
}
|
|
11367
|
-
var
|
|
12236
|
+
var init_connect4 = __esm({
|
|
11368
12237
|
"src/commands/mcp/connect.ts"() {
|
|
11369
12238
|
"use strict";
|
|
11370
12239
|
init_errors();
|
|
@@ -11378,7 +12247,7 @@ var call_exports = {};
|
|
|
11378
12247
|
__export(call_exports, {
|
|
11379
12248
|
default: () => call_default
|
|
11380
12249
|
});
|
|
11381
|
-
function
|
|
12250
|
+
function isRecord7(value) {
|
|
11382
12251
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
11383
12252
|
}
|
|
11384
12253
|
function textOf(result) {
|
|
@@ -11391,7 +12260,7 @@ var init_call = __esm({
|
|
|
11391
12260
|
init_errors();
|
|
11392
12261
|
init_exit_codes();
|
|
11393
12262
|
init_input();
|
|
11394
|
-
|
|
12263
|
+
init_connect4();
|
|
11395
12264
|
command22 = {
|
|
11396
12265
|
resource: "mcp",
|
|
11397
12266
|
action: "call",
|
|
@@ -11411,7 +12280,7 @@ var init_call = __esm({
|
|
|
11411
12280
|
let args = {};
|
|
11412
12281
|
if (typeof flags.args === "string") {
|
|
11413
12282
|
const parsed3 = await readDataArg(flags.args, ctx.stdin);
|
|
11414
|
-
if (!
|
|
12283
|
+
if (!isRecord7(parsed3)) throw usageError("--args must be a JSON object.", { field: "args", hint: `For example --args '{"limit":5}'.` });
|
|
11415
12284
|
args = parsed3;
|
|
11416
12285
|
}
|
|
11417
12286
|
if (typeof flags.operation === "string") args = { ...args, operation: flags.operation };
|
|
@@ -11420,11 +12289,11 @@ var init_call = __esm({
|
|
|
11420
12289
|
return ExitCode.Ok;
|
|
11421
12290
|
}
|
|
11422
12291
|
const result = await mcpClient(ctx).callTool(tool, args);
|
|
11423
|
-
const
|
|
12292
|
+
const text4 = textOf(result);
|
|
11424
12293
|
if (result.isError === true) {
|
|
11425
12294
|
throw new KensoError({
|
|
11426
12295
|
code: "mcp_tool_error",
|
|
11427
|
-
message:
|
|
12296
|
+
message: text4 || `The MCP tool ${tool} returned an error.`,
|
|
11428
12297
|
exitCode: ExitCode.Error,
|
|
11429
12298
|
details: result
|
|
11430
12299
|
});
|
|
@@ -11433,12 +12302,12 @@ var init_call = __esm({
|
|
|
11433
12302
|
ctx.output.object(result.structuredContent);
|
|
11434
12303
|
return ExitCode.Ok;
|
|
11435
12304
|
}
|
|
11436
|
-
if (
|
|
12305
|
+
if (text4 === "") return ExitCode.Ok;
|
|
11437
12306
|
let parsed2;
|
|
11438
12307
|
try {
|
|
11439
|
-
parsed2 = JSON.parse(
|
|
12308
|
+
parsed2 = JSON.parse(text4);
|
|
11440
12309
|
} catch {
|
|
11441
|
-
writeRaw(ctx,
|
|
12310
|
+
writeRaw(ctx, text4);
|
|
11442
12311
|
return ExitCode.Ok;
|
|
11443
12312
|
}
|
|
11444
12313
|
ctx.output.object(parsed2);
|
|
@@ -11459,7 +12328,7 @@ var init_tools = __esm({
|
|
|
11459
12328
|
"src/commands/mcp/tools.ts"() {
|
|
11460
12329
|
"use strict";
|
|
11461
12330
|
init_exit_codes();
|
|
11462
|
-
|
|
12331
|
+
init_connect4();
|
|
11463
12332
|
command23 = {
|
|
11464
12333
|
resource: "mcp",
|
|
11465
12334
|
action: "tools",
|
|
@@ -11480,11 +12349,11 @@ var init_tools = __esm({
|
|
|
11480
12349
|
});
|
|
11481
12350
|
|
|
11482
12351
|
// src/commands/mcp/index.ts
|
|
11483
|
-
var
|
|
12352
|
+
var actions14;
|
|
11484
12353
|
var init_mcp = __esm({
|
|
11485
12354
|
"src/commands/mcp/index.ts"() {
|
|
11486
12355
|
"use strict";
|
|
11487
|
-
|
|
12356
|
+
actions14 = {
|
|
11488
12357
|
call: () => Promise.resolve().then(() => (init_call(), call_exports)).then((m) => m.default),
|
|
11489
12358
|
tools: () => Promise.resolve().then(() => (init_tools(), tools_exports)).then((m) => m.default)
|
|
11490
12359
|
};
|
|
@@ -11514,10 +12383,10 @@ var init_stage_history = __esm({
|
|
|
11514
12383
|
beta: { featureGates: { all: ["opportunities"] } },
|
|
11515
12384
|
operationIds: ["opportunities.get-stage-history"],
|
|
11516
12385
|
async run(ctx, { positionals }) {
|
|
11517
|
-
const
|
|
11518
|
-
const id = /^\d+$/.test(
|
|
12386
|
+
const text4 = (positionals[0] ?? "").trim();
|
|
12387
|
+
const id = /^\d+$/.test(text4) ? Number(text4) : Number.NaN;
|
|
11519
12388
|
if (!Number.isSafeInteger(id) || id < 1) {
|
|
11520
|
-
throw usageError(`opportunityId must be a positive whole number (got "${
|
|
12389
|
+
throw usageError(`opportunityId must be a positive whole number (got "${text4}").`, {
|
|
11521
12390
|
field: "opportunityId",
|
|
11522
12391
|
next: "kenso opportunities stage-history <opportunityId>"
|
|
11523
12392
|
});
|
|
@@ -11532,11 +12401,11 @@ var init_stage_history = __esm({
|
|
|
11532
12401
|
});
|
|
11533
12402
|
|
|
11534
12403
|
// src/commands/opportunities/index.ts
|
|
11535
|
-
var
|
|
12404
|
+
var actions15;
|
|
11536
12405
|
var init_opportunities = __esm({
|
|
11537
12406
|
"src/commands/opportunities/index.ts"() {
|
|
11538
12407
|
"use strict";
|
|
11539
|
-
|
|
12408
|
+
actions15 = {
|
|
11540
12409
|
"stage-history": () => Promise.resolve().then(() => (init_stage_history(), stage_history_exports)).then((m) => m.default)
|
|
11541
12410
|
};
|
|
11542
12411
|
}
|
|
@@ -11552,23 +12421,23 @@ function toBody2(row, columns2) {
|
|
|
11552
12421
|
const value = (field) => firstValue(row, columns2.sources.get(field));
|
|
11553
12422
|
const person = {};
|
|
11554
12423
|
for (const field of PERSON_FIELDS) {
|
|
11555
|
-
const
|
|
11556
|
-
if (
|
|
12424
|
+
const text4 = textValue(value(field), field);
|
|
12425
|
+
if (text4 !== void 0) person[field] = text4;
|
|
11557
12426
|
}
|
|
11558
12427
|
const fullName = person.fullName ?? ([person.firstName, person.lastName].filter(Boolean).join(" ") || void 0);
|
|
11559
12428
|
if (fullName === void 0) {
|
|
11560
12429
|
throw new RowInvalid("name_required", "A person needs a name: a fullName column, or firstName and lastName.");
|
|
11561
12430
|
}
|
|
11562
|
-
const
|
|
12431
|
+
const body2 = { person: { fullName, ...person } };
|
|
11563
12432
|
const accountId = idValue(value("accountId"), "accountId");
|
|
11564
12433
|
const accountDomain = textValue(value("accountDomain"), "accountDomain");
|
|
11565
|
-
if (accountId !== void 0)
|
|
11566
|
-
else if (accountDomain !== void 0)
|
|
12434
|
+
if (accountId !== void 0) body2.accountId = accountId;
|
|
12435
|
+
else if (accountDomain !== void 0) body2.accountDomain = accountDomain;
|
|
11567
12436
|
const role = textValue(value("role"), "role");
|
|
11568
|
-
if (role !== void 0)
|
|
12437
|
+
if (role !== void 0) body2.role = role;
|
|
11569
12438
|
const priority = integerValue(value("priority"), "priority");
|
|
11570
|
-
if (priority !== void 0)
|
|
11571
|
-
return
|
|
12439
|
+
if (priority !== void 0) body2.priority = priority;
|
|
12440
|
+
return body2;
|
|
11572
12441
|
}
|
|
11573
12442
|
function personResult(row, r) {
|
|
11574
12443
|
const id = r.personId !== void 0 && r.personId !== null ? { id: String(r.personId) } : {};
|
|
@@ -11715,11 +12584,11 @@ var init_import3 = __esm({
|
|
|
11715
12584
|
});
|
|
11716
12585
|
|
|
11717
12586
|
// src/commands/people/index.ts
|
|
11718
|
-
var
|
|
12587
|
+
var actions16;
|
|
11719
12588
|
var init_people = __esm({
|
|
11720
12589
|
"src/commands/people/index.ts"() {
|
|
11721
12590
|
"use strict";
|
|
11722
|
-
|
|
12591
|
+
actions16 = {
|
|
11723
12592
|
import: () => Promise.resolve().then(() => (init_import3(), import_exports3)).then((m) => m.default)
|
|
11724
12593
|
};
|
|
11725
12594
|
}
|
|
@@ -11748,9 +12617,9 @@ var init_list = __esm({
|
|
|
11748
12617
|
},
|
|
11749
12618
|
examples: ["kenso runs list", "kenso runs list --limit 5 -o json"],
|
|
11750
12619
|
async run(ctx, { flags }) {
|
|
11751
|
-
const
|
|
11752
|
-
const limit = /^\d+$/.test(
|
|
11753
|
-
if (!(limit >= 1 && limit <= 1e3)) throw usageError(`--limit must be a whole number from 1 to 1000 (got "${
|
|
12620
|
+
const text4 = typeof flags.limit === "string" ? flags.limit.trim() : "20";
|
|
12621
|
+
const limit = /^\d+$/.test(text4) ? Number(text4) : Number.NaN;
|
|
12622
|
+
if (!(limit >= 1 && limit <= 1e3)) throw usageError(`--limit must be a whole number from 1 to 1000 (got "${text4}").`, { field: "limit" });
|
|
11754
12623
|
const runs = await listRuns(ctx.env);
|
|
11755
12624
|
await ctx.output.list(
|
|
11756
12625
|
runs.slice(0, limit).map((run) => ({ runId: run.runId, command: run.command, status: run.status, rows: run.rows ?? null, createdAt: run.createdAt }))
|
|
@@ -11937,11 +12806,11 @@ var init_resume = __esm({
|
|
|
11937
12806
|
});
|
|
11938
12807
|
|
|
11939
12808
|
// src/commands/runs/index.ts
|
|
11940
|
-
var
|
|
12809
|
+
var actions17;
|
|
11941
12810
|
var init_runs2 = __esm({
|
|
11942
12811
|
"src/commands/runs/index.ts"() {
|
|
11943
12812
|
"use strict";
|
|
11944
|
-
|
|
12813
|
+
actions17 = {
|
|
11945
12814
|
list: () => Promise.resolve().then(() => (init_list(), list_exports)).then((m) => m.default),
|
|
11946
12815
|
show: () => Promise.resolve().then(() => (init_show(), show_exports)).then((m) => m.default),
|
|
11947
12816
|
resume: () => Promise.resolve().then(() => (init_resume(), resume_exports)).then((m) => m.default)
|
|
@@ -12059,9 +12928,9 @@ var init_create = __esm({
|
|
|
12059
12928
|
operationIds: ["sandboxes.create"],
|
|
12060
12929
|
async run(ctx) {
|
|
12061
12930
|
requireLiveKey(ctx);
|
|
12062
|
-
let
|
|
12931
|
+
let body2;
|
|
12063
12932
|
try {
|
|
12064
|
-
|
|
12933
|
+
body2 = (await ctx.client.request({ method: "POST", path: "/v1/sandboxes", signal: ctx.signal })).body;
|
|
12065
12934
|
} catch (err) {
|
|
12066
12935
|
if (err instanceof KensoError && err.httpStatus === 409 && hasDetailCode(err, "sandbox_exists")) {
|
|
12067
12936
|
throw new KensoError({
|
|
@@ -12076,7 +12945,7 @@ var init_create = __esm({
|
|
|
12076
12945
|
}
|
|
12077
12946
|
throw err;
|
|
12078
12947
|
}
|
|
12079
|
-
const sandbox = unwrap(
|
|
12948
|
+
const sandbox = unwrap(body2) ?? {};
|
|
12080
12949
|
const testKey = sandbox.testKey ?? {};
|
|
12081
12950
|
saveTestKey(ctx, String(sandbox.id), testKey);
|
|
12082
12951
|
ctx.output.object({
|
|
@@ -12240,11 +13109,11 @@ var init_reset = __esm({
|
|
|
12240
13109
|
});
|
|
12241
13110
|
|
|
12242
13111
|
// src/commands/sandbox/index.ts
|
|
12243
|
-
var
|
|
13112
|
+
var actions18;
|
|
12244
13113
|
var init_sandbox2 = __esm({
|
|
12245
13114
|
"src/commands/sandbox/index.ts"() {
|
|
12246
13115
|
"use strict";
|
|
12247
|
-
|
|
13116
|
+
actions18 = {
|
|
12248
13117
|
create: () => Promise.resolve().then(() => (init_create(), create_exports)).then((m) => m.default),
|
|
12249
13118
|
delete: () => Promise.resolve().then(() => (init_delete(), delete_exports)).then((m) => m.default),
|
|
12250
13119
|
key: () => Promise.resolve().then(() => (init_key(), key_exports)).then((m) => m.default),
|
|
@@ -12255,11 +13124,11 @@ var init_sandbox2 = __esm({
|
|
|
12255
13124
|
});
|
|
12256
13125
|
|
|
12257
13126
|
// src/commands/skill/index.ts
|
|
12258
|
-
var
|
|
13127
|
+
var actions19;
|
|
12259
13128
|
var init_skill = __esm({
|
|
12260
13129
|
"src/commands/skill/index.ts"() {
|
|
12261
13130
|
"use strict";
|
|
12262
|
-
|
|
13131
|
+
actions19 = {
|
|
12263
13132
|
install: () => Promise.resolve().then(() => (init_install(), install_exports)).then((m) => m.default)
|
|
12264
13133
|
};
|
|
12265
13134
|
}
|
|
@@ -12267,9 +13136,9 @@ var init_skill = __esm({
|
|
|
12267
13136
|
|
|
12268
13137
|
// src/commands/studio/common.ts
|
|
12269
13138
|
function positiveId2(value, field) {
|
|
12270
|
-
const
|
|
12271
|
-
const id = /^\d+$/.test(
|
|
12272
|
-
if (!Number.isSafeInteger(id) || id < 1) throw usageError(`${field} must be a positive whole number (got "${
|
|
13139
|
+
const text4 = (value ?? "").trim();
|
|
13140
|
+
const id = /^\d+$/.test(text4) ? Number(text4) : Number.NaN;
|
|
13141
|
+
if (!Number.isSafeInteger(id) || id < 1) throw usageError(`${field} must be a positive whole number (got "${text4}").`, { field });
|
|
12273
13142
|
return id;
|
|
12274
13143
|
}
|
|
12275
13144
|
function validationFailed(validation, message, next) {
|
|
@@ -12398,7 +13267,7 @@ var init_folder = __esm({
|
|
|
12398
13267
|
|
|
12399
13268
|
// src/commands/studio/transfer.ts
|
|
12400
13269
|
import { createHash as createHash6 } from "node:crypto";
|
|
12401
|
-
function
|
|
13270
|
+
function interrupted6() {
|
|
12402
13271
|
return new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted });
|
|
12403
13272
|
}
|
|
12404
13273
|
async function presigned(url, init, what, code, signal) {
|
|
@@ -12406,7 +13275,7 @@ async function presigned(url, init, what, code, signal) {
|
|
|
12406
13275
|
try {
|
|
12407
13276
|
res = await globalThis.fetch(url, { ...init, signal });
|
|
12408
13277
|
} catch (err) {
|
|
12409
|
-
if (signal.aborted) throw
|
|
13278
|
+
if (signal.aborted) throw interrupted6();
|
|
12410
13279
|
const cause = err?.cause?.code;
|
|
12411
13280
|
throw new KensoError({
|
|
12412
13281
|
code,
|
|
@@ -12851,7 +13720,7 @@ var init_preview = __esm({
|
|
|
12851
13720
|
});
|
|
12852
13721
|
|
|
12853
13722
|
// src/commands/studio/fill-runs.ts
|
|
12854
|
-
import { setTimeout as
|
|
13723
|
+
import { setTimeout as delay7 } from "node:timers/promises";
|
|
12855
13724
|
async function estimateFill(ctx, templateId, count) {
|
|
12856
13725
|
const parts2 = [];
|
|
12857
13726
|
for (let left = count; left > 0; left -= RUN_SIZE) {
|
|
@@ -12883,7 +13752,7 @@ async function estimateFill(ctx, templateId, count) {
|
|
|
12883
13752
|
async function waitForRun(client, runId, opts) {
|
|
12884
13753
|
const sleep = opts.sleep ?? (async (ms) => {
|
|
12885
13754
|
try {
|
|
12886
|
-
await
|
|
13755
|
+
await delay7(ms, void 0, { signal: opts.signal });
|
|
12887
13756
|
} catch (err) {
|
|
12888
13757
|
if (opts.signal.aborted) throw new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted });
|
|
12889
13758
|
throw err;
|
|
@@ -12894,7 +13763,7 @@ async function waitForRun(client, runId, opts) {
|
|
|
12894
13763
|
const run = unwrap(res.body) ?? {};
|
|
12895
13764
|
opts.onPoll?.(run);
|
|
12896
13765
|
if (run.state && TERMINAL_RUN_STATES.has(run.state)) return run;
|
|
12897
|
-
await sleep(opts.intervalMs ??
|
|
13766
|
+
await sleep(opts.intervalMs ?? POLL_INTERVAL_MS2);
|
|
12898
13767
|
}
|
|
12899
13768
|
}
|
|
12900
13769
|
function runResults(items, run, key) {
|
|
@@ -12935,7 +13804,7 @@ function runsOf(results) {
|
|
|
12935
13804
|
}
|
|
12936
13805
|
return [...runs.values()];
|
|
12937
13806
|
}
|
|
12938
|
-
var RUN_SIZE,
|
|
13807
|
+
var RUN_SIZE, POLL_INTERVAL_MS2, TERMINAL_RUN_STATES;
|
|
12939
13808
|
var init_fill_runs = __esm({
|
|
12940
13809
|
"src/commands/studio/fill-runs.ts"() {
|
|
12941
13810
|
"use strict";
|
|
@@ -12943,7 +13812,7 @@ var init_fill_runs = __esm({
|
|
|
12943
13812
|
init_exit_codes();
|
|
12944
13813
|
init_http();
|
|
12945
13814
|
RUN_SIZE = 500;
|
|
12946
|
-
|
|
13815
|
+
POLL_INTERVAL_MS2 = 5e3;
|
|
12947
13816
|
TERMINAL_RUN_STATES = /* @__PURE__ */ new Set(["completed", "failed", "cancelled"]);
|
|
12948
13817
|
}
|
|
12949
13818
|
});
|
|
@@ -13010,13 +13879,13 @@ async function refuseRefill(ctx, args, target) {
|
|
|
13010
13879
|
next: unfinished ? `kenso runs resume ${earlier.runId}` : `kenso runs show ${earlier.runId}`
|
|
13011
13880
|
});
|
|
13012
13881
|
}
|
|
13013
|
-
async function fillChunk(ctx, templateId, target,
|
|
13882
|
+
async function fillChunk(ctx, templateId, target, wait3, chunk, chunkCtx) {
|
|
13014
13883
|
const ids2 = chunk.map((item) => item.id);
|
|
13015
|
-
const
|
|
13016
|
-
const res = await chunkCtx.client.request({ method: "POST", path: "/v1/asset-runs", body, signal: chunkCtx.signal });
|
|
13884
|
+
const body2 = target.campaignId !== void 0 ? { templateId, campaignId: target.campaignId, contactIds: ids2 } : { templateId, accountIds: ids2 };
|
|
13885
|
+
const res = await chunkCtx.client.request({ method: "POST", path: "/v1/asset-runs", body: body2, signal: chunkCtx.signal });
|
|
13017
13886
|
let run = unwrap(res.body) ?? {};
|
|
13018
13887
|
ctx.output.info(`Run ${run.id} started for ${ids2.length} ${target.flag} (${run.state ?? "queued"}).`);
|
|
13019
|
-
if (
|
|
13888
|
+
if (wait3 && run.id !== void 0) {
|
|
13020
13889
|
const created = run;
|
|
13021
13890
|
try {
|
|
13022
13891
|
run = await waitForRun(chunkCtx.client, run.id, {
|
|
@@ -13099,7 +13968,7 @@ var init_fill = __esm({
|
|
|
13099
13968
|
ctx.output.object({ ...estimateOutput(templateId, target, estimate2), next });
|
|
13100
13969
|
return ExitCode.Ok;
|
|
13101
13970
|
}
|
|
13102
|
-
const
|
|
13971
|
+
const wait3 = flags.wait === true;
|
|
13103
13972
|
const outcome = await runBatch(
|
|
13104
13973
|
{
|
|
13105
13974
|
command: COMMAND6,
|
|
@@ -13109,7 +13978,7 @@ var init_fill = __esm({
|
|
|
13109
13978
|
rowOf: (item) => item.row,
|
|
13110
13979
|
chunkSize: RUN_SIZE,
|
|
13111
13980
|
concurrency: 1,
|
|
13112
|
-
execChunk: (chunk, chunkCtx) => fillChunk(ctx, templateId, target,
|
|
13981
|
+
execChunk: (chunk, chunkCtx) => fillChunk(ctx, templateId, target, wait3, chunk, chunkCtx),
|
|
13113
13982
|
summarize: (results) => ({
|
|
13114
13983
|
templateId,
|
|
13115
13984
|
...target.campaignId !== void 0 ? { campaignId: target.campaignId } : {},
|
|
@@ -13128,11 +13997,11 @@ var init_fill = __esm({
|
|
|
13128
13997
|
});
|
|
13129
13998
|
|
|
13130
13999
|
// src/commands/studio/index.ts
|
|
13131
|
-
var
|
|
14000
|
+
var actions20;
|
|
13132
14001
|
var init_studio2 = __esm({
|
|
13133
14002
|
"src/commands/studio/index.ts"() {
|
|
13134
14003
|
"use strict";
|
|
13135
|
-
|
|
14004
|
+
actions20 = {
|
|
13136
14005
|
pull: () => Promise.resolve().then(() => (init_pull(), pull_exports)).then((m) => m.default),
|
|
13137
14006
|
push: () => Promise.resolve().then(() => (init_push(), push_exports)).then((m) => m.default),
|
|
13138
14007
|
validate: () => Promise.resolve().then(() => (init_validate(), validate_exports)).then((m) => m.default),
|
|
@@ -13166,20 +14035,20 @@ function signingSecret(env) {
|
|
|
13166
14035
|
`, { mode: 384 });
|
|
13167
14036
|
return secret;
|
|
13168
14037
|
}
|
|
13169
|
-
function signatureHeaders(secret, id,
|
|
14038
|
+
function signatureHeaders(secret, id, body2, nowMs = Date.now()) {
|
|
13170
14039
|
const timestamp = String(Math.floor(nowMs / 1e3));
|
|
13171
14040
|
const key = Buffer.from(secret.slice("whsec_".length), "base64");
|
|
13172
|
-
const signature = createHmac("sha256", key).update(`${id}.${timestamp}.${
|
|
14041
|
+
const signature = createHmac("sha256", key).update(`${id}.${timestamp}.${body2}`).digest("base64");
|
|
13173
14042
|
return { "svix-id": id, "svix-timestamp": timestamp, "svix-signature": `v1,${signature}` };
|
|
13174
14043
|
}
|
|
13175
|
-
function forwardUrl(
|
|
13176
|
-
const trimmed =
|
|
14044
|
+
function forwardUrl(text4) {
|
|
14045
|
+
const trimmed = text4.trim();
|
|
13177
14046
|
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `http://${trimmed}`;
|
|
13178
14047
|
let url;
|
|
13179
14048
|
try {
|
|
13180
14049
|
url = new URL(withScheme);
|
|
13181
14050
|
} catch {
|
|
13182
|
-
throw usageError(`--forward-to "${
|
|
14051
|
+
throw usageError(`--forward-to "${text4}" is not a URL.`, { field: "forward-to", hint: "Use the URL of your handler, for example http://localhost:3000/hook." });
|
|
13183
14052
|
}
|
|
13184
14053
|
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
13185
14054
|
throw usageError(`--forward-to must be an http or https URL, not ${url.protocol}`, { field: "forward-to" });
|
|
@@ -13238,7 +14107,7 @@ __export(listen_exports, {
|
|
|
13238
14107
|
liveBody: () => liveBody
|
|
13239
14108
|
});
|
|
13240
14109
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
13241
|
-
import { setTimeout as
|
|
14110
|
+
import { setTimeout as delay8 } from "node:timers/promises";
|
|
13242
14111
|
function eventTypes(value) {
|
|
13243
14112
|
const list2 = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
|
|
13244
14113
|
return list2.flatMap((item) => item.split(",")).map((item) => item.trim()).filter((item) => item !== "");
|
|
@@ -13271,8 +14140,8 @@ function readBody(req) {
|
|
|
13271
14140
|
req.on("error", reject);
|
|
13272
14141
|
});
|
|
13273
14142
|
}
|
|
13274
|
-
function reply(res, status,
|
|
13275
|
-
res.writeHead(status, { "content-type": "application/json" }).end(JSON.stringify(
|
|
14143
|
+
function reply(res, status, body2) {
|
|
14144
|
+
res.writeHead(status, { "content-type": "application/json" }).end(JSON.stringify(body2));
|
|
13276
14145
|
}
|
|
13277
14146
|
var MIN_POLL_MS, MAX_POLL_MS, MAX_TRIGGER_BYTES, command39, listen_default;
|
|
13278
14147
|
var init_listen = __esm({
|
|
@@ -13349,8 +14218,8 @@ var init_listen = __esm({
|
|
|
13349
14218
|
const server = createServer((req, res) => {
|
|
13350
14219
|
if (req.method !== "POST" || req.url !== "/events") return reply(res, 404, { error: "not_found" });
|
|
13351
14220
|
if (req.headers.authorization !== `Bearer ${token}`) return reply(res, 401, { error: "unauthorized" });
|
|
13352
|
-
readBody(req).then(async (
|
|
13353
|
-
const sent = JSON.parse(
|
|
14221
|
+
readBody(req).then(async (text4) => {
|
|
14222
|
+
const sent = JSON.parse(text4);
|
|
13354
14223
|
const result = await deliver({ eventId: sent.eventId, type: sent.type, timestamp: sent.timestamp, source: "trigger", body: JSON.stringify(sent.data) });
|
|
13355
14224
|
reply(res, 200, { forward: result ?? null });
|
|
13356
14225
|
}).catch(() => reply(res, 400, { error: "invalid_event" }));
|
|
@@ -13368,8 +14237,8 @@ var init_listen = __esm({
|
|
|
13368
14237
|
try {
|
|
13369
14238
|
const page = await poll2(ctx, types, cursor2);
|
|
13370
14239
|
for (const event of page.events ?? []) {
|
|
13371
|
-
const
|
|
13372
|
-
await deliver({ eventId: event.eventId ?? "", type: event.name ?? "", timestamp: event.timestamp ?? "", source: "live", body });
|
|
14240
|
+
const body2 = JSON.stringify(liveBody(event, workspaceId));
|
|
14241
|
+
await deliver({ eventId: event.eventId ?? "", type: event.name ?? "", timestamp: event.timestamp ?? "", source: "live", body: body2 });
|
|
13373
14242
|
}
|
|
13374
14243
|
cursor2 = page.cursor ?? cursor2;
|
|
13375
14244
|
waitMs = page.hasMore ? 0 : Math.min(MAX_POLL_MS, Math.max(MIN_POLL_MS, page.nextPollMs ?? MAX_POLL_MS));
|
|
@@ -13378,7 +14247,7 @@ var init_listen = __esm({
|
|
|
13378
14247
|
ctx.output.warn(`Polling failed (${err.message}); trying again in ${MAX_POLL_MS / 1e3} s.`);
|
|
13379
14248
|
}
|
|
13380
14249
|
}
|
|
13381
|
-
await
|
|
14250
|
+
await delay8(waitMs, void 0, { signal: ctx.signal }).catch(() => void 0);
|
|
13382
14251
|
}
|
|
13383
14252
|
} catch (err) {
|
|
13384
14253
|
if (!ctx.signal.aborted) throw err;
|
|
@@ -13481,11 +14350,11 @@ var init_trigger = __esm({
|
|
|
13481
14350
|
});
|
|
13482
14351
|
|
|
13483
14352
|
// src/commands/webhooks/index.ts
|
|
13484
|
-
var
|
|
14353
|
+
var actions21;
|
|
13485
14354
|
var init_webhooks2 = __esm({
|
|
13486
14355
|
"src/commands/webhooks/index.ts"() {
|
|
13487
14356
|
"use strict";
|
|
13488
|
-
|
|
14357
|
+
actions21 = {
|
|
13489
14358
|
listen: () => Promise.resolve().then(() => (init_listen(), listen_exports)).then((m) => m.default),
|
|
13490
14359
|
trigger: () => Promise.resolve().then(() => (init_trigger(), trigger_exports)).then((m) => m.default)
|
|
13491
14360
|
};
|
|
@@ -13495,14 +14364,14 @@ var init_webhooks2 = __esm({
|
|
|
13495
14364
|
// src/commands/work/common.ts
|
|
13496
14365
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
13497
14366
|
import { join as join16 } from "node:path";
|
|
13498
|
-
import { setTimeout as
|
|
14367
|
+
import { setTimeout as delay9 } from "node:timers/promises";
|
|
13499
14368
|
function unavailable(err) {
|
|
13500
14369
|
return err instanceof KensoError && (err.code === "network_error" || err.httpStatus === 502 || err.httpStatus === 503 || err.httpStatus === 504);
|
|
13501
14370
|
}
|
|
13502
|
-
async function
|
|
14371
|
+
async function pause3(ms, signal) {
|
|
13503
14372
|
if (signal.aborted) return false;
|
|
13504
14373
|
try {
|
|
13505
|
-
await
|
|
14374
|
+
await delay9(ms, void 0, { signal });
|
|
13506
14375
|
return true;
|
|
13507
14376
|
} catch {
|
|
13508
14377
|
return false;
|
|
@@ -13516,21 +14385,21 @@ async function untilAvailable(ctx, call, signal) {
|
|
|
13516
14385
|
if (!unavailable(err) || waits >= MAX_UNAVAILABLE_WAITS) throw err;
|
|
13517
14386
|
const status = err.httpStatus;
|
|
13518
14387
|
ctx.output.info(`Kenso did not answer (${status ? `HTTP ${status}` : "network error"}): asking again in ${Math.round(WORK_TIMING.unavailableMs / 1e3)} s.`);
|
|
13519
|
-
if (!await
|
|
14388
|
+
if (!await pause3(WORK_TIMING.unavailableMs, signal)) throw err;
|
|
13520
14389
|
}
|
|
13521
14390
|
}
|
|
13522
14391
|
}
|
|
13523
|
-
function
|
|
14392
|
+
function isRecord8(value) {
|
|
13524
14393
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13525
14394
|
}
|
|
13526
|
-
function
|
|
14395
|
+
function text3(flags, name) {
|
|
13527
14396
|
const value = flags[name];
|
|
13528
14397
|
if (typeof value !== "string") return void 0;
|
|
13529
14398
|
const trimmed = value.trim();
|
|
13530
14399
|
return trimmed === "" ? void 0 : trimmed;
|
|
13531
14400
|
}
|
|
13532
|
-
function
|
|
13533
|
-
const raw =
|
|
14401
|
+
function wholeNumber2(flags, name, min, max, fallback) {
|
|
14402
|
+
const raw = text3(flags, name);
|
|
13534
14403
|
if (raw === void 0) return fallback;
|
|
13535
14404
|
const value = /^\d+$/.test(raw) ? Number(raw) : Number.NaN;
|
|
13536
14405
|
if (!(Number.isSafeInteger(value) && value >= min && value <= max)) {
|
|
@@ -13539,7 +14408,7 @@ function wholeNumber(flags, name, min, max, fallback) {
|
|
|
13539
14408
|
return value;
|
|
13540
14409
|
}
|
|
13541
14410
|
function campaignFlag(flags) {
|
|
13542
|
-
return
|
|
14411
|
+
return wholeNumber2(flags, "campaign", 1, Number.MAX_SAFE_INTEGER);
|
|
13543
14412
|
}
|
|
13544
14413
|
function liveOnlyFlag(flags) {
|
|
13545
14414
|
return flags["live-only"] === true;
|
|
@@ -13551,13 +14420,13 @@ function kindsFlag(flags) {
|
|
|
13551
14420
|
return kinds.length > 0 ? kinds : void 0;
|
|
13552
14421
|
}
|
|
13553
14422
|
function durationFlag(flags, name, fallback) {
|
|
13554
|
-
const raw =
|
|
14423
|
+
const raw = text3(flags, name) ?? fallback;
|
|
13555
14424
|
const ms = parseDuration(raw);
|
|
13556
14425
|
if (ms === void 0 || ms <= 0) throw usageError(`--${name} must be a duration such as 90s, 15m or 1h (got "${raw}").`, { field: name });
|
|
13557
14426
|
return ms;
|
|
13558
14427
|
}
|
|
13559
14428
|
function leaseMinutes(flags) {
|
|
13560
|
-
const raw =
|
|
14429
|
+
const raw = text3(flags, "lease") ?? "30m";
|
|
13561
14430
|
const ms = parseDuration(raw);
|
|
13562
14431
|
const minutes = ms === void 0 ? Number.NaN : Math.floor(ms / 6e4);
|
|
13563
14432
|
if (!(minutes >= MIN_LEASE_MINUTES && minutes <= MAX_LEASE_MINUTES)) {
|
|
@@ -13586,10 +14455,10 @@ function explainNotFound(err) {
|
|
|
13586
14455
|
});
|
|
13587
14456
|
}
|
|
13588
14457
|
async function claimWork(ctx, req, headers, waitSignal) {
|
|
13589
|
-
const
|
|
13590
|
-
if (req.kinds)
|
|
13591
|
-
if (req.campaignId !== void 0)
|
|
13592
|
-
if (req.liveOnly)
|
|
14458
|
+
const body2 = { limit: req.limit, leaseMinutes: req.leaseMinutes };
|
|
14459
|
+
if (req.kinds) body2.kinds = req.kinds;
|
|
14460
|
+
if (req.campaignId !== void 0) body2.campaignId = req.campaignId;
|
|
14461
|
+
if (req.liveOnly) body2.scope = "live";
|
|
13593
14462
|
const key = randomUUID2();
|
|
13594
14463
|
let res;
|
|
13595
14464
|
try {
|
|
@@ -13598,7 +14467,7 @@ async function claimWork(ctx, req, headers, waitSignal) {
|
|
|
13598
14467
|
() => ctx.client.request({
|
|
13599
14468
|
method: "POST",
|
|
13600
14469
|
path: "/v1/agent-work/claims",
|
|
13601
|
-
body,
|
|
14470
|
+
body: body2,
|
|
13602
14471
|
retrySafe: true,
|
|
13603
14472
|
headers: { "Idempotency-Key": key, ...headers },
|
|
13604
14473
|
signal: UNTIL_DONE
|
|
@@ -13609,7 +14478,7 @@ async function claimWork(ctx, req, headers, waitSignal) {
|
|
|
13609
14478
|
throw explainNotFound(err);
|
|
13610
14479
|
}
|
|
13611
14480
|
const data = unwrap(res.body);
|
|
13612
|
-
if (!
|
|
14481
|
+
if (!isRecord8(data) || typeof data.id !== "string" || !Array.isArray(data.items) || data.items.length === 0) return null;
|
|
13613
14482
|
return {
|
|
13614
14483
|
id: data.id,
|
|
13615
14484
|
kind: typeof data.kind === "string" ? data.kind : "",
|
|
@@ -13646,7 +14515,7 @@ async function releaseClaim(ctx, claimId, headers = {}) {
|
|
|
13646
14515
|
throw explainNotFound(err);
|
|
13647
14516
|
}
|
|
13648
14517
|
const data = unwrap(res.body);
|
|
13649
|
-
return
|
|
14518
|
+
return isRecord8(data) && typeof data.released === "number" ? data.released : 0;
|
|
13650
14519
|
}
|
|
13651
14520
|
var BETA, KINDS_TEXT, MAX_PER_FILE, MIN_LEASE_MINUTES, MAX_LEASE_MINUTES, KIND_FLAG, CAMPAIGN_FLAG, LIVE_ONLY_FLAG, PER_FILE_FLAG, LEASE_FLAG, OUT_FLAG2, UNTIL_DONE, WORK_TIMING, MAX_UNAVAILABLE_WAITS;
|
|
13652
14521
|
var init_common3 = __esm({
|
|
@@ -13707,7 +14576,7 @@ var init_status3 = __esm({
|
|
|
13707
14576
|
throw explainNotFound(err);
|
|
13708
14577
|
}
|
|
13709
14578
|
const data = unwrap(res.body);
|
|
13710
|
-
const kinds =
|
|
14579
|
+
const kinds = isRecord8(data) && Array.isArray(data.kinds) ? data.kinds.filter(isRecord8) : [];
|
|
13711
14580
|
await ctx.output.list(
|
|
13712
14581
|
kinds.map((k) => ({
|
|
13713
14582
|
kind: k.kind ?? null,
|
|
@@ -13773,18 +14642,18 @@ function isObject2(value) {
|
|
|
13773
14642
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
13774
14643
|
}
|
|
13775
14644
|
function readAnswersFile(path, work) {
|
|
13776
|
-
let
|
|
14645
|
+
let text4;
|
|
13777
14646
|
try {
|
|
13778
|
-
const
|
|
13779
|
-
if (typeof
|
|
13780
|
-
|
|
14647
|
+
const read2 = readRegularFile(path, "answers file");
|
|
14648
|
+
if (typeof read2 !== "string") return read2;
|
|
14649
|
+
text4 = read2;
|
|
13781
14650
|
} catch (err) {
|
|
13782
14651
|
const code = err.code;
|
|
13783
14652
|
return { ok: false, error: code === "ENOENT" ? "the answers file was not written" : "the answers file could not be read" };
|
|
13784
14653
|
}
|
|
13785
14654
|
let doc;
|
|
13786
14655
|
try {
|
|
13787
|
-
doc = JSON.parse(
|
|
14656
|
+
doc = JSON.parse(text4.charCodeAt(0) === 65279 ? text4.slice(1) : text4);
|
|
13788
14657
|
} catch {
|
|
13789
14658
|
return { ok: false, error: "the answers file is not valid JSON" };
|
|
13790
14659
|
}
|
|
@@ -13827,9 +14696,9 @@ function readAnswersFile(path, work) {
|
|
|
13827
14696
|
return { ok: true, answers, dropped, agent: { ...cli ? { cli } : {}, ...model ? { model } : {} } };
|
|
13828
14697
|
}
|
|
13829
14698
|
function readWorkFile(path) {
|
|
13830
|
-
const
|
|
13831
|
-
if (typeof
|
|
13832
|
-
const doc = JSON.parse(
|
|
14699
|
+
const text4 = readRegularFile(path, "work file");
|
|
14700
|
+
if (typeof text4 !== "string") throw new Error(text4.error);
|
|
14701
|
+
const doc = JSON.parse(text4);
|
|
13833
14702
|
if (!isObject2(doc) || typeof doc.claimId !== "string" || !Array.isArray(doc.items)) {
|
|
13834
14703
|
throw new Error("the work file is not a work file");
|
|
13835
14704
|
}
|
|
@@ -14134,10 +15003,10 @@ var init_pull2 = __esm({
|
|
|
14134
15003
|
const kinds = kindsFlag(flags);
|
|
14135
15004
|
const campaignId = campaignFlag(flags);
|
|
14136
15005
|
const liveOnly = liveOnlyFlag(flags);
|
|
14137
|
-
const files =
|
|
14138
|
-
const perFile =
|
|
15006
|
+
const files = wholeNumber2(flags, "files", 1, MAX_FILES, 16);
|
|
15007
|
+
const perFile = wholeNumber2(flags, "per-file", 1, MAX_PER_FILE, 10);
|
|
14139
15008
|
const lease = leaseMinutes(flags);
|
|
14140
|
-
const folder = new WorkRunFolder(ctx, "work pull", flags,
|
|
15009
|
+
const folder = new WorkRunFolder(ctx, "work pull", flags, text3(flags, "out"));
|
|
14141
15010
|
const written = [];
|
|
14142
15011
|
let items = 0;
|
|
14143
15012
|
let queueEmpty = false;
|
|
@@ -14177,11 +15046,11 @@ var init_pull2 = __esm({
|
|
|
14177
15046
|
}
|
|
14178
15047
|
throw err;
|
|
14179
15048
|
}
|
|
14180
|
-
const
|
|
15049
|
+
const interrupted7 = ctx.signal.aborted;
|
|
14181
15050
|
const result = summary();
|
|
14182
|
-
await folder.finish(
|
|
15051
|
+
await folder.finish(interrupted7 ? "interrupted" : "done", written.length, items, result);
|
|
14183
15052
|
ctx.output.summary(result);
|
|
14184
|
-
return
|
|
15053
|
+
return interrupted7 ? ExitCode.Interrupted : ExitCode.Ok;
|
|
14185
15054
|
}
|
|
14186
15055
|
};
|
|
14187
15056
|
pull_default2 = command42;
|
|
@@ -14214,12 +15083,12 @@ async function sendAnswers(ctx, claimId, answers, agent, headers, waitSignal) {
|
|
|
14214
15083
|
const results = /* @__PURE__ */ new Map();
|
|
14215
15084
|
let pending = answers;
|
|
14216
15085
|
for (let round = 1; round <= SUBMIT_ROUNDS && pending.length > 0; round++) {
|
|
14217
|
-
if (round > 1 && !await
|
|
15086
|
+
if (round > 1 && !await pause3(WORK_TIMING.retryMs, waitSignal)) break;
|
|
14218
15087
|
const again = [];
|
|
14219
15088
|
for (let at = 0; at < pending.length; at += MAX_ANSWERS_PER_CALL) {
|
|
14220
15089
|
const chunk = pending.slice(at, at + MAX_ANSWERS_PER_CALL);
|
|
14221
|
-
const
|
|
14222
|
-
if (agent.cli !== void 0 || agent.model !== void 0)
|
|
15090
|
+
const body2 = { answers: chunk };
|
|
15091
|
+
if (agent.cli !== void 0 || agent.model !== void 0) body2.agent = agent;
|
|
14223
15092
|
const key = randomUUID3();
|
|
14224
15093
|
let res;
|
|
14225
15094
|
try {
|
|
@@ -14228,7 +15097,7 @@ async function sendAnswers(ctx, claimId, answers, agent, headers, waitSignal) {
|
|
|
14228
15097
|
() => ctx.client.request({
|
|
14229
15098
|
method: "POST",
|
|
14230
15099
|
path: `/v1/agent-work/claims/${encodeURIComponent(claimId)}/answers`,
|
|
14231
|
-
body,
|
|
15100
|
+
body: body2,
|
|
14232
15101
|
retrySafe: true,
|
|
14233
15102
|
headers: { "Idempotency-Key": key, ...headers },
|
|
14234
15103
|
signal: UNTIL_DONE
|
|
@@ -14239,10 +15108,10 @@ async function sendAnswers(ctx, claimId, answers, agent, headers, waitSignal) {
|
|
|
14239
15108
|
throw explainNotFound(err);
|
|
14240
15109
|
}
|
|
14241
15110
|
const data = unwrap(res.body);
|
|
14242
|
-
const entries2 =
|
|
15111
|
+
const entries2 = isRecord8(data) && Array.isArray(data.results) ? data.results : [];
|
|
14243
15112
|
chunk.forEach((answer, i) => {
|
|
14244
15113
|
const entry = entries2[i];
|
|
14245
|
-
if (!
|
|
15114
|
+
if (!isRecord8(entry)) return;
|
|
14246
15115
|
const status = typeof entry.status === "string" && STATUSES2.has(entry.status) ? entry.status : "rejected";
|
|
14247
15116
|
const result = {
|
|
14248
15117
|
itemId: answer.itemId,
|
|
@@ -14268,12 +15137,12 @@ async function writeResults(answersPath, claimId, results, totals) {
|
|
|
14268
15137
|
return path;
|
|
14269
15138
|
}
|
|
14270
15139
|
async function submitAnswersFile(ctx, answersPath, work, opts = {}) {
|
|
14271
|
-
const
|
|
14272
|
-
if (!
|
|
14273
|
-
const agent = { cli:
|
|
14274
|
-
await opts.check?.(
|
|
14275
|
-
const sent = await sendAnswers(ctx, work.claimId,
|
|
14276
|
-
const results = [...sent, ...
|
|
15140
|
+
const read2 = readAnswersFile(answersPath, work);
|
|
15141
|
+
if (!read2.ok) throw usageError(`${answersPath}: ${read2.error}.`, { field: "answers-file" });
|
|
15142
|
+
const agent = { cli: read2.agent.cli ?? agentName(opts.fallbackAgent?.cli), model: read2.agent.model ?? agentName(opts.fallbackAgent?.model) };
|
|
15143
|
+
await opts.check?.(read2.answers, agent);
|
|
15144
|
+
const sent = await sendAnswers(ctx, work.claimId, read2.answers, agent, opts.headers ?? {}, opts.signal ?? ctx.signal);
|
|
15145
|
+
const results = [...sent, ...read2.dropped.map(droppedResult)];
|
|
14277
15146
|
const totals = tally(results);
|
|
14278
15147
|
const resultsPath = await writeResults(answersPath, work.claimId, results, totals);
|
|
14279
15148
|
return { claimId: work.claimId, results, totals, resultsPath };
|
|
@@ -14350,8 +15219,8 @@ var init_submit = __esm({
|
|
|
14350
15219
|
const paths = [...new Set(positionals.map((p) => resolve14(p)))];
|
|
14351
15220
|
const jobs = paths.map((path) => {
|
|
14352
15221
|
const work = workFileNextTo(path);
|
|
14353
|
-
const
|
|
14354
|
-
if (!
|
|
15222
|
+
const read2 = readAnswersFile(path, work);
|
|
15223
|
+
if (!read2.ok) throw usageError(`${path}: ${read2.error}. Nothing was sent.`, { field: "answers-file" });
|
|
14355
15224
|
return { path, work };
|
|
14356
15225
|
});
|
|
14357
15226
|
const totals = zeroTotals();
|
|
@@ -14421,11 +15290,11 @@ var init_release = __esm({
|
|
|
14421
15290
|
});
|
|
14422
15291
|
|
|
14423
15292
|
// src/work/job.ts
|
|
14424
|
-
import { spawn as
|
|
15293
|
+
import { spawn as nodeSpawn3 } from "node:child_process";
|
|
14425
15294
|
import { rmSync as rmSync3, statSync as statSync2 } from "node:fs";
|
|
14426
15295
|
import { access, constants as constants2 } from "node:fs/promises";
|
|
14427
15296
|
import { delimiter as delimiter2, join as join20 } from "node:path";
|
|
14428
|
-
import { setTimeout as
|
|
15297
|
+
import { setTimeout as delay10 } from "node:timers/promises";
|
|
14429
15298
|
function childEnv(parent, adapter, extra) {
|
|
14430
15299
|
const scrub = new Set(adapter.scrubEnv.map((name) => name.toUpperCase()));
|
|
14431
15300
|
const env = {};
|
|
@@ -14479,7 +15348,7 @@ function signalTree(child, signal, runAs) {
|
|
|
14479
15348
|
if (process.platform === "win32") {
|
|
14480
15349
|
if (child.exitCode !== null || child.signalCode !== null) return;
|
|
14481
15350
|
const args = ["/pid", String(pid), "/T", ...signal === "SIGKILL" ? ["/F"] : []];
|
|
14482
|
-
|
|
15351
|
+
nodeSpawn3("taskkill", args, { stdio: "ignore", windowsHide: true }).on("error", () => {
|
|
14483
15352
|
});
|
|
14484
15353
|
return;
|
|
14485
15354
|
}
|
|
@@ -14518,7 +15387,7 @@ async function groupGone(pid, runAs) {
|
|
|
14518
15387
|
while (Date.now() < deadline) {
|
|
14519
15388
|
if (runAs) {
|
|
14520
15389
|
if (!await sudoKill(runAs, "SIGKILL", pid)) return;
|
|
14521
|
-
await
|
|
15390
|
+
await delay10(100);
|
|
14522
15391
|
continue;
|
|
14523
15392
|
}
|
|
14524
15393
|
try {
|
|
@@ -14526,7 +15395,7 @@ async function groupGone(pid, runAs) {
|
|
|
14526
15395
|
} catch {
|
|
14527
15396
|
return;
|
|
14528
15397
|
}
|
|
14529
|
-
await
|
|
15398
|
+
await delay10(25);
|
|
14530
15399
|
}
|
|
14531
15400
|
}
|
|
14532
15401
|
function runChild(spawnFn, bin, built, job, env, signal, runAs) {
|
|
@@ -14602,8 +15471,8 @@ function runChild(spawnFn, bin, built, job, env, signal, runAs) {
|
|
|
14602
15471
|
if (signal?.aborted) stop("abort");
|
|
14603
15472
|
});
|
|
14604
15473
|
}
|
|
14605
|
-
function tail(
|
|
14606
|
-
const flat =
|
|
15474
|
+
function tail(text4) {
|
|
15475
|
+
const flat = text4.replace(/\s+/g, " ").trim();
|
|
14607
15476
|
return flat.length > DETAIL_TAIL ? "..." + flat.slice(flat.length - DETAIL_TAIL) : flat;
|
|
14608
15477
|
}
|
|
14609
15478
|
async function confirmToolsVerdict(adapter, verdict, loginCheck) {
|
|
@@ -14654,23 +15523,23 @@ async function runAgentJob(adapter, job, deps) {
|
|
|
14654
15523
|
built: { ...built, args: [...runAs.sudo.slice(1), ...sudoArgs(runAs.name, bin, built.args, Object.keys(keep), temp)] },
|
|
14655
15524
|
env: { PATH: SUDO_PATH, ...keep }
|
|
14656
15525
|
} : { command: bin, built, env: childEnv(env, adapter, built.env) };
|
|
14657
|
-
const run = await runChild(deps?.spawn ??
|
|
15526
|
+
const run = await runChild(deps?.spawn ?? nodeSpawn3, launch.command, launch.built, job, launch.env, signal, runAs);
|
|
14658
15527
|
if (run.stopped === "abort") throw signal?.reason ?? new Error("aborted");
|
|
14659
15528
|
if (run.stopped === "timeout") {
|
|
14660
15529
|
const late = readAnswersFile(answersPath, work);
|
|
14661
15530
|
return result("timeout", run.exitCode, `the agent ran longer than ${job.timeoutMs} ms and was stopped`, late.ok ? answersPath : void 0);
|
|
14662
15531
|
}
|
|
14663
15532
|
if (run.spawnError && run.exitCode === null) return result("fatal", null, `the agent could not start: ${run.spawnError.message}`);
|
|
14664
|
-
const
|
|
14665
|
-
if (
|
|
14666
|
-
const dropped =
|
|
15533
|
+
const read2 = readAnswersFile(answersPath, work);
|
|
15534
|
+
if (read2.ok) {
|
|
15535
|
+
const dropped = read2.dropped.length > 0 ? `${read2.dropped.length} answers dropped` : void 0;
|
|
14667
15536
|
return result("ok", run.exitCode, dropped, answersPath);
|
|
14668
15537
|
}
|
|
14669
15538
|
let verdict = adapter.classify({ exitCode: run.exitCode, stdout: run.stdout, stderr: run.stderr });
|
|
14670
15539
|
if (job.agentTools) verdict = await confirmToolsVerdict(adapter, verdict, () => adapter.login.check(bin, env, runAs));
|
|
14671
|
-
if (verdict === "ok") return result("no_answers", run.exitCode,
|
|
15540
|
+
if (verdict === "ok") return result("no_answers", run.exitCode, read2.error);
|
|
14672
15541
|
const said = tail(run.stderr) || tail(run.stdout);
|
|
14673
|
-
return result(verdict, run.exitCode, said ? `${
|
|
15542
|
+
return result(verdict, run.exitCode, said ? `${read2.error}; the agent said: ${said}` : read2.error);
|
|
14674
15543
|
}
|
|
14675
15544
|
var OUTPUT_CAP_BYTES, KILL_GRACE_MS, KENSO_ENV_PREFIX, MAX_TIMER_MS, DETAIL_TAIL, Tail, liveGroups, KILL_ON, hooksInstalled;
|
|
14676
15545
|
var init_job = __esm({
|
|
@@ -14711,10 +15580,10 @@ var init_job = __esm({
|
|
|
14711
15580
|
|
|
14712
15581
|
// src/work/adapters/common.ts
|
|
14713
15582
|
import { execFile as execFile2 } from "node:child_process";
|
|
14714
|
-
function verdictForError(
|
|
14715
|
-
if (USAGE_LIMIT.test(
|
|
14716
|
-
if (AUTH.test(
|
|
14717
|
-
if (TRANSIENT.test(
|
|
15583
|
+
function verdictForError(text4) {
|
|
15584
|
+
if (USAGE_LIMIT.test(text4)) return "usage_limit";
|
|
15585
|
+
if (AUTH.test(text4)) return "auth";
|
|
15586
|
+
if (TRANSIENT.test(text4)) return "transient";
|
|
14718
15587
|
return "fatal";
|
|
14719
15588
|
}
|
|
14720
15589
|
function classifyByExit(r) {
|
|
@@ -14723,9 +15592,9 @@ function classifyByExit(r) {
|
|
|
14723
15592
|
${errorTail(r.stdout)}`);
|
|
14724
15593
|
}
|
|
14725
15594
|
function lastJsonObject(stdout) {
|
|
14726
|
-
const parse3 = (
|
|
15595
|
+
const parse3 = (text4) => {
|
|
14727
15596
|
try {
|
|
14728
|
-
const value = JSON.parse(
|
|
15597
|
+
const value = JSON.parse(text4);
|
|
14729
15598
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
14730
15599
|
} catch {
|
|
14731
15600
|
return void 0;
|
|
@@ -14751,8 +15620,8 @@ function classifyResultJson(r) {
|
|
|
14751
15620
|
return verdictForError(`${errorTail(said)}
|
|
14752
15621
|
${errorTail(r.stderr)}`);
|
|
14753
15622
|
}
|
|
14754
|
-
function plain(
|
|
14755
|
-
return
|
|
15623
|
+
function plain(text4) {
|
|
15624
|
+
return text4.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "");
|
|
14756
15625
|
}
|
|
14757
15626
|
function runStatus(bin, args, env, adapter, runAs) {
|
|
14758
15627
|
const command48 = runAs ? runAs.sudo[0] ?? "/usr/bin/sudo" : bin;
|
|
@@ -14788,7 +15657,7 @@ var init_common4 = __esm({
|
|
|
14788
15657
|
AUTH = /not logged in|not authenticated|authentication (required|failed|error)|401 unauthori[sz]ed|invalid[ _-]api[ _-]key|please run \/?login|log ?in (again|required)|login required|(oauth |access )?token (has )?expired|could not be refreshed|invalid (credentials|token)|(status|http|api error)[: ]*(401|403)\b/i;
|
|
14789
15658
|
TRANSIENT = /overloaded|internal server error|service unavailable|bad gateway|gateway timeout|temporarily unavailable|(status|http|api error)[: ]*5\d\d\b|timed? ?out|ETIMEDOUT|ECONNRESET|ECONNREFUSED|EAI_AGAIN|ENOTFOUND|socket hang up|network error|fetch failed|connection (reset|refused|closed|error)|stream (error|disconnected)/i;
|
|
14790
15659
|
ERROR_TAIL_CHARS = 1500;
|
|
14791
|
-
errorTail = (
|
|
15660
|
+
errorTail = (text4) => text4.slice(-ERROR_TAIL_CHARS);
|
|
14792
15661
|
STATUS_TIMEOUT_MS = 2e4;
|
|
14793
15662
|
}
|
|
14794
15663
|
});
|
|
@@ -14914,10 +15783,10 @@ var init_codex = __esm({
|
|
|
14914
15783
|
async check(bin, env, runAs) {
|
|
14915
15784
|
const out = await runStatus(bin, ["login", "status"], env, codex, runAs);
|
|
14916
15785
|
if (!out) return "unknown";
|
|
14917
|
-
const
|
|
15786
|
+
const text4 = `${out.stdout}
|
|
14918
15787
|
${out.stderr}`;
|
|
14919
|
-
if (/logged in using chatgpt/i.test(
|
|
14920
|
-
if (/not logged in|logged in using an api key/i.test(
|
|
15788
|
+
if (/logged in using chatgpt/i.test(text4)) return "ok";
|
|
15789
|
+
if (/not logged in|logged in using an api key/i.test(text4)) return "logged_out";
|
|
14921
15790
|
return "unknown";
|
|
14922
15791
|
},
|
|
14923
15792
|
loginCommand: "codex login"
|
|
@@ -15006,10 +15875,10 @@ var init_grok = __esm({
|
|
|
15006
15875
|
async check(bin, env, runAs) {
|
|
15007
15876
|
const out = await runStatus(bin, ["models"], env, grok, runAs);
|
|
15008
15877
|
if (!out) return "unknown";
|
|
15009
|
-
const
|
|
15878
|
+
const text4 = `${out.stdout}
|
|
15010
15879
|
${out.stderr}`;
|
|
15011
|
-
if (/logged in with grok\.com/i.test(
|
|
15012
|
-
if (/not authenticated|not logged in/i.test(
|
|
15880
|
+
if (/logged in with grok\.com/i.test(text4)) return "ok";
|
|
15881
|
+
if (/not authenticated|not logged in/i.test(text4)) return "logged_out";
|
|
15013
15882
|
return "unknown";
|
|
15014
15883
|
},
|
|
15015
15884
|
loginCommand: "grok login"
|
|
@@ -15129,18 +15998,18 @@ var init_adapters = __esm({
|
|
|
15129
15998
|
|
|
15130
15999
|
// src/work/scan.ts
|
|
15131
16000
|
import { createHmac as createHmac2, randomBytes as randomBytes4 } from "node:crypto";
|
|
15132
|
-
function fold(
|
|
15133
|
-
return
|
|
16001
|
+
function fold(text4) {
|
|
16002
|
+
return text4.normalize("NFKC").replace(/[^A-Za-z0-9]/g, "").toLowerCase();
|
|
15134
16003
|
}
|
|
15135
|
-
function entropy(
|
|
16004
|
+
function entropy(text4) {
|
|
15136
16005
|
const counts2 = /* @__PURE__ */ new Map();
|
|
15137
|
-
for (const c of
|
|
16006
|
+
for (const c of text4) counts2.set(c, (counts2.get(c) ?? 0) + 1);
|
|
15138
16007
|
let bits = 0;
|
|
15139
|
-
for (const n of counts2.values()) bits -= n /
|
|
16008
|
+
for (const n of counts2.values()) bits -= n / text4.length * Math.log2(n / text4.length);
|
|
15140
16009
|
return bits;
|
|
15141
16010
|
}
|
|
15142
|
-
function hasHighEntropyRun(
|
|
15143
|
-
for (const word of
|
|
16011
|
+
function hasHighEntropyRun(text4) {
|
|
16012
|
+
for (const word of text4.split(/\s+/)) {
|
|
15144
16013
|
if (LINK.test(word)) continue;
|
|
15145
16014
|
for (const m of word.matchAll(/[A-Za-z0-9+/=_-]{32,}/g)) {
|
|
15146
16015
|
const run = m[0];
|
|
@@ -15155,18 +16024,18 @@ function stringValues(value, out = []) {
|
|
|
15155
16024
|
else if (value !== null && typeof value === "object") for (const v of Object.values(value)) stringValues(v, out);
|
|
15156
16025
|
return out;
|
|
15157
16026
|
}
|
|
15158
|
-
function decodings(
|
|
16027
|
+
function decodings(text4) {
|
|
15159
16028
|
const out = [];
|
|
15160
|
-
for (const m of
|
|
16029
|
+
for (const m of text4.matchAll(/[A-Za-z0-9+/_-]{20,}={0,2}/g)) {
|
|
15161
16030
|
for (const encoding of ["base64", "base64url"]) {
|
|
15162
16031
|
const decoded = Buffer.from(m[0], encoding).toString("utf8");
|
|
15163
16032
|
if (decoded.length >= WINDOW && /^[\x20-\x7e\s]+$/.test(decoded)) out.push(decoded);
|
|
15164
16033
|
}
|
|
15165
16034
|
}
|
|
15166
|
-
for (const m of
|
|
15167
|
-
if (/%[0-9a-fA-F]{2}/.test(
|
|
16035
|
+
for (const m of text4.matchAll(/(?:[0-9a-fA-F]{2}){16,}/g)) out.push(Buffer.from(m[0], "hex").toString("utf8"));
|
|
16036
|
+
if (/%[0-9a-fA-F]{2}/.test(text4)) {
|
|
15168
16037
|
try {
|
|
15169
|
-
out.push(decodeURIComponent(
|
|
16038
|
+
out.push(decodeURIComponent(text4));
|
|
15170
16039
|
} catch {
|
|
15171
16040
|
}
|
|
15172
16041
|
}
|
|
@@ -15250,12 +16119,12 @@ var init_scan = __esm({
|
|
|
15250
16119
|
exact = /* @__PURE__ */ new Set();
|
|
15251
16120
|
folded = /* @__PURE__ */ new Set();
|
|
15252
16121
|
/** Adds a credential file's text: its JSON string values (keys skipped), or the whole text when it is not JSON. */
|
|
15253
|
-
add(
|
|
16122
|
+
add(text4) {
|
|
15254
16123
|
let values;
|
|
15255
16124
|
try {
|
|
15256
|
-
values = stringValues(JSON.parse(
|
|
16125
|
+
values = stringValues(JSON.parse(text4));
|
|
15257
16126
|
} catch {
|
|
15258
|
-
values = [
|
|
16127
|
+
values = [text4];
|
|
15259
16128
|
}
|
|
15260
16129
|
for (const value of values) {
|
|
15261
16130
|
for (const run of value.match(TOKEN_RUN) ?? []) {
|
|
@@ -15277,11 +16146,11 @@ var init_scan = __esm({
|
|
|
15277
16146
|
hash(window) {
|
|
15278
16147
|
return createHmac2("sha256", this.key).update(window).digest("base64url");
|
|
15279
16148
|
}
|
|
15280
|
-
addWindows(
|
|
15281
|
-
for (let i = 0; i + WINDOW <=
|
|
16149
|
+
addWindows(text4, into) {
|
|
16150
|
+
for (let i = 0; i + WINDOW <= text4.length; i++) into.add(this.hash(text4.slice(i, i + WINDOW)));
|
|
15282
16151
|
}
|
|
15283
|
-
anyWindow(
|
|
15284
|
-
for (let i = 0; i + WINDOW <=
|
|
16152
|
+
anyWindow(text4, set) {
|
|
16153
|
+
for (let i = 0; i + WINDOW <= text4.length; i++) if (set.has(this.hash(text4.slice(i, i + WINDOW)))) return true;
|
|
15285
16154
|
return false;
|
|
15286
16155
|
}
|
|
15287
16156
|
};
|
|
@@ -15347,8 +16216,8 @@ var init_credentials = __esm({
|
|
|
15347
16216
|
if (files.required.length === 0) throw unreadable(`where ${agent} keeps its login in a box is not known`);
|
|
15348
16217
|
const scanner = new _AnswerScanner(user, agent, warn);
|
|
15349
16218
|
for (const rel of files.required) {
|
|
15350
|
-
const
|
|
15351
|
-
if (
|
|
16219
|
+
const read2 = await scanner.read(rel);
|
|
16220
|
+
if (read2 !== "ok") throw unreadable(`~/${rel} of ${user.name} ${read2 === "missing" ? "does not exist" : "could not be read"}`);
|
|
15352
16221
|
}
|
|
15353
16222
|
for (const rel of files.optional) await scanner.read(rel);
|
|
15354
16223
|
return scanner;
|
|
@@ -15370,8 +16239,8 @@ var init_credentials = __esm({
|
|
|
15370
16239
|
async refresh() {
|
|
15371
16240
|
const files = CREDENTIAL_FILES[this.agent];
|
|
15372
16241
|
for (const rel of [...files.required, ...files.optional]) {
|
|
15373
|
-
const
|
|
15374
|
-
if (
|
|
16242
|
+
const read2 = await this.read(rel);
|
|
16243
|
+
if (read2 !== "ok" && files.required.includes(rel) && !this.warned) {
|
|
15375
16244
|
this.warned = true;
|
|
15376
16245
|
this.warn(`Could not read ${this.user.name}'s ~/${rel} again: the answer scan goes on with what it read before.`);
|
|
15377
16246
|
}
|
|
@@ -15399,11 +16268,11 @@ function agentGuide(opts) {
|
|
|
15399
16268
|
const parts2 = opts.kensoKey ? [JOB, KENSO, ...browser ? [BROWSER] : [], NEVER] : [JOB, NO_KENSO, NEVER];
|
|
15400
16269
|
return parts2.join("\n");
|
|
15401
16270
|
}
|
|
15402
|
-
function writeAgentGuide(dir,
|
|
16271
|
+
function writeAgentGuide(dir, text4, mode = WORK_FILE_MODE) {
|
|
15403
16272
|
for (const name of GUIDE_FILES) {
|
|
15404
16273
|
const fd = openSync2(join23(dir, name), "wx", mode);
|
|
15405
16274
|
try {
|
|
15406
|
-
writeFileSync6(fd,
|
|
16275
|
+
writeFileSync6(fd, text4, "utf8");
|
|
15407
16276
|
fchmodSync2(fd, mode);
|
|
15408
16277
|
} finally {
|
|
15409
16278
|
closeSync2(fd);
|
|
@@ -15616,7 +16485,7 @@ var init_pool = __esm({
|
|
|
15616
16485
|
|
|
15617
16486
|
// src/commands/work/agent.ts
|
|
15618
16487
|
function agentFlag(flags) {
|
|
15619
|
-
const agentId =
|
|
16488
|
+
const agentId = text3(flags, "agent") ?? "";
|
|
15620
16489
|
const adapter = getAdapter(agentId.toLowerCase());
|
|
15621
16490
|
if (!adapter) throw usageError(`--agent must be one of ${Object.keys(ADAPTERS).join(", ")} (got "${agentId}").`, { field: "agent" });
|
|
15622
16491
|
return adapter;
|
|
@@ -15636,11 +16505,11 @@ async function checkAgent(ctx, adapter, flags, runAs) {
|
|
|
15636
16505
|
const name = AGENT_NAMES[adapter.id];
|
|
15637
16506
|
const tools = flags["agent-tools"] === true;
|
|
15638
16507
|
if ((!adapter.confined || tools) && flags["allow-unconfined"] !== true) throw unconfinedError(adapter, tools);
|
|
15639
|
-
const bin = await resolveBinary(adapter, ctx.env,
|
|
16508
|
+
const bin = await resolveBinary(adapter, ctx.env, text3(flags, "agent-bin"));
|
|
15640
16509
|
if (bin === void 0) {
|
|
15641
16510
|
throw new KensoError({
|
|
15642
16511
|
code: "agent_not_installed",
|
|
15643
|
-
message: `${name} is not installed here: ${
|
|
16512
|
+
message: `${name} is not installed here: ${text3(flags, "agent-bin") ?? adapter.binaries.join(" or ")} was not found on PATH.`,
|
|
15644
16513
|
exitCode: ExitCode.Error,
|
|
15645
16514
|
field: "agent",
|
|
15646
16515
|
hint: `${INSTALL[adapter.id]}, log in to it, then run again. Or point --agent-bin at it.`
|
|
@@ -15707,13 +16576,13 @@ async function readRunToken(ctx) {
|
|
|
15707
16576
|
if (stdin.isTTY === true) {
|
|
15708
16577
|
throw new KensoError({ code: "token_required", message: "--token-stdin reads the run token from a pipe, not a terminal.", exitCode: ExitCode.Usage, field: "token-stdin" });
|
|
15709
16578
|
}
|
|
15710
|
-
let
|
|
16579
|
+
let text4;
|
|
15711
16580
|
try {
|
|
15712
|
-
|
|
16581
|
+
text4 = await readStream(stdin, MAX_TOKEN_INPUT_BYTES);
|
|
15713
16582
|
} catch {
|
|
15714
16583
|
throw invalidToken("stdin holds more than one Kenso run token's worth of text.");
|
|
15715
16584
|
}
|
|
15716
|
-
const token = (
|
|
16585
|
+
const token = (text4.split(/\r?\n/)[0] ?? "").trim();
|
|
15717
16586
|
if (!RUN_TOKEN.test(token)) throw invalidToken("The first line of stdin is not a Kenso run token (krt_ and 43 characters).");
|
|
15718
16587
|
return token;
|
|
15719
16588
|
}
|
|
@@ -15728,7 +16597,7 @@ function requireSharedRunsDir(ctx, out) {
|
|
|
15728
16597
|
}
|
|
15729
16598
|
function agentToolsFlag(flags, allowWeb) {
|
|
15730
16599
|
if (flags["agent-tools"] !== true) return false;
|
|
15731
|
-
if (flags["token-stdin"] !== true ||
|
|
16600
|
+
if (flags["token-stdin"] !== true || text3(flags, "agent-user") === void 0) {
|
|
15732
16601
|
throw usageError("--agent-tools works only in a Kenso sandbox, with --token-stdin and --agent-user.", { field: "agent-tools" });
|
|
15733
16602
|
}
|
|
15734
16603
|
if (!allowWeb) {
|
|
@@ -15740,14 +16609,14 @@ function agentKeyFailed(message) {
|
|
|
15740
16609
|
return new KensoError({ code: "agent_key_failed", message, exitCode: ExitCode.Error, field: "agent-tools" });
|
|
15741
16610
|
}
|
|
15742
16611
|
async function fetchAgentKey(ctx, headers) {
|
|
15743
|
-
let
|
|
16612
|
+
let body2;
|
|
15744
16613
|
try {
|
|
15745
16614
|
const res = await untilAvailable(
|
|
15746
16615
|
ctx,
|
|
15747
16616
|
() => ctx.client.request({ method: "POST", path: "/v1/agent-work/agent-key", retrySafe: true, headers }),
|
|
15748
16617
|
ctx.signal
|
|
15749
16618
|
);
|
|
15750
|
-
|
|
16619
|
+
body2 = res.body;
|
|
15751
16620
|
} catch (err) {
|
|
15752
16621
|
if (ctx.signal.aborted || err instanceof KensoError && err.code === "interrupted") {
|
|
15753
16622
|
throw new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted });
|
|
@@ -15756,8 +16625,8 @@ async function fetchAgentKey(ctx, headers) {
|
|
|
15756
16625
|
const status = err instanceof KensoError && err.httpStatus !== void 0 ? `HTTP ${err.httpStatus}` : "no answer";
|
|
15757
16626
|
throw agentKeyFailed(`Kenso did not give this run its agent key (${status}), so the run stopped before any work was claimed.`);
|
|
15758
16627
|
}
|
|
15759
|
-
const data = unwrap(
|
|
15760
|
-
if (!
|
|
16628
|
+
const data = unwrap(body2);
|
|
16629
|
+
if (!isRecord8(data) || typeof data.apiKey !== "string" || !API_KEY_PATTERN.test(data.apiKey)) {
|
|
15761
16630
|
throw agentKeyFailed("Kenso's answer held no agent key, so the run stopped before any work was claimed.");
|
|
15762
16631
|
}
|
|
15763
16632
|
return { apiKey: data.apiKey, expiresAt: typeof data.expiresAt === "string" ? data.expiresAt : "" };
|
|
@@ -15838,12 +16707,12 @@ var init_stop = __esm({
|
|
|
15838
16707
|
});
|
|
15839
16708
|
|
|
15840
16709
|
// src/commands/work/run.ts
|
|
15841
|
-
var
|
|
15842
|
-
__export(
|
|
16710
|
+
var run_exports2 = {};
|
|
16711
|
+
__export(run_exports2, {
|
|
15843
16712
|
default: () => run_default
|
|
15844
16713
|
});
|
|
15845
16714
|
var FAILURES_IN_A_ROW, command45, run_default;
|
|
15846
|
-
var
|
|
16715
|
+
var init_run2 = __esm({
|
|
15847
16716
|
"src/commands/work/run.ts"() {
|
|
15848
16717
|
"use strict";
|
|
15849
16718
|
init_errors();
|
|
@@ -15904,34 +16773,34 @@ var init_run = __esm({
|
|
|
15904
16773
|
ownCredential: (flags) => flags["token-stdin"] === true,
|
|
15905
16774
|
async run(ctx, { flags }) {
|
|
15906
16775
|
const adapter = agentFlag(flags);
|
|
15907
|
-
const parallel =
|
|
15908
|
-
const perFile =
|
|
15909
|
-
const maxItems =
|
|
16776
|
+
const parallel = wholeNumber2(flags, "parallel", 1, MAX_PARALLEL, MAX_PARALLEL);
|
|
16777
|
+
const perFile = wholeNumber2(flags, "per-file", 1, MAX_PER_FILE, 10);
|
|
16778
|
+
const maxItems = wholeNumber2(flags, "max-items", 1, Number.MAX_SAFE_INTEGER);
|
|
15910
16779
|
const kinds = kindsFlag(flags);
|
|
15911
16780
|
const campaignId = campaignFlag(flags);
|
|
15912
16781
|
const liveOnly = liveOnlyFlag(flags);
|
|
15913
16782
|
const lease = leaseMinutes(flags);
|
|
15914
|
-
const
|
|
15915
|
-
if (
|
|
16783
|
+
const timeoutMs2 = durationFlag(flags, "timeout", "15m");
|
|
16784
|
+
if (timeoutMs2 >= lease * 6e4) {
|
|
15916
16785
|
throw usageError(`--timeout must be shorter than --lease (${lease}m): the claim lets go of its items when the lease ends.`, { field: "timeout" });
|
|
15917
16786
|
}
|
|
15918
|
-
const model =
|
|
16787
|
+
const model = text3(flags, "model");
|
|
15919
16788
|
const allowWeb = flags["no-research"] !== true;
|
|
15920
16789
|
const agentTools = agentToolsFlag(flags, allowWeb);
|
|
15921
|
-
const
|
|
16790
|
+
const watch2 = flags.watch === true;
|
|
15922
16791
|
const name = AGENT_NAMES[adapter.id];
|
|
15923
16792
|
if (flags["token-stdin"] === true) ctx.client = ctx.client.withApiKey(await readRunToken(ctx));
|
|
15924
|
-
const agentUser =
|
|
16793
|
+
const agentUser = text3(flags, "agent-user");
|
|
15925
16794
|
let runAs;
|
|
15926
16795
|
if (agentUser !== void 0) {
|
|
15927
|
-
requireSharedRunsDir(ctx,
|
|
16796
|
+
requireSharedRunsDir(ctx, text3(flags, "out"));
|
|
15928
16797
|
runAs = await checkAgentUser(agentUser);
|
|
15929
16798
|
}
|
|
15930
16799
|
const bin = await checkAgent(ctx, adapter, flags, runAs);
|
|
15931
16800
|
const scanner = runAs ? await AnswerScanner.load(runAs, adapter.id, (m) => ctx.output.warn(m)) : void 0;
|
|
15932
16801
|
const headers = { "X-Ken-Client": `Kenso CLI work run via ${adapter.id}` };
|
|
15933
16802
|
const tools = agentTools ? await prepareAgentTools(ctx, headers, scanner, name) : void 0;
|
|
15934
|
-
const folder = new WorkRunFolder(ctx, "work run", flags,
|
|
16803
|
+
const folder = new WorkRunFolder(ctx, "work run", flags, text3(flags, "out"), runAs !== void 0);
|
|
15935
16804
|
const started = Date.now();
|
|
15936
16805
|
const stop = new AbortController();
|
|
15937
16806
|
const quit = new AbortController();
|
|
@@ -16015,11 +16884,11 @@ var init_run = __esm({
|
|
|
16015
16884
|
}
|
|
16016
16885
|
if (claim === null) {
|
|
16017
16886
|
if (quit.signal.aborted) return null;
|
|
16018
|
-
if (!
|
|
16887
|
+
if (!watch2) {
|
|
16019
16888
|
halt("queue_empty");
|
|
16020
16889
|
return null;
|
|
16021
16890
|
}
|
|
16022
|
-
if (!await
|
|
16891
|
+
if (!await pause3(WORK_TIMING.watchMs, quit.signal)) return null;
|
|
16023
16892
|
continue;
|
|
16024
16893
|
}
|
|
16025
16894
|
claims++;
|
|
@@ -16060,7 +16929,7 @@ var init_run = __esm({
|
|
|
16060
16929
|
answersFile: work.answersFile,
|
|
16061
16930
|
instruction: buildInstruction({ workFile: workFileName(claim.id), answersFile: work.answersFile, allowWeb, agentTools }),
|
|
16062
16931
|
...model ? { model } : {},
|
|
16063
|
-
timeoutMs,
|
|
16932
|
+
timeoutMs: timeoutMs2,
|
|
16064
16933
|
allowWeb,
|
|
16065
16934
|
...agentTools ? { agentTools: true } : {},
|
|
16066
16935
|
...folder.tmpDir ? { tmpDir: folder.tmpDir } : {}
|
|
@@ -16193,16 +17062,16 @@ var init_run = __esm({
|
|
|
16193
17062
|
});
|
|
16194
17063
|
|
|
16195
17064
|
// src/commands/work/index.ts
|
|
16196
|
-
var
|
|
17065
|
+
var actions22;
|
|
16197
17066
|
var init_work2 = __esm({
|
|
16198
17067
|
"src/commands/work/index.ts"() {
|
|
16199
17068
|
"use strict";
|
|
16200
|
-
|
|
17069
|
+
actions22 = {
|
|
16201
17070
|
status: () => Promise.resolve().then(() => (init_status3(), status_exports3)).then((m) => m.default),
|
|
16202
17071
|
pull: () => Promise.resolve().then(() => (init_pull2(), pull_exports2)).then((m) => m.default),
|
|
16203
17072
|
submit: () => Promise.resolve().then(() => (init_submit(), submit_exports)).then((m) => m.default),
|
|
16204
17073
|
release: () => Promise.resolve().then(() => (init_release(), release_exports)).then((m) => m.default),
|
|
16205
|
-
run: () => Promise.resolve().then(() => (
|
|
17074
|
+
run: () => Promise.resolve().then(() => (init_run2(), run_exports2)).then((m) => m.default)
|
|
16206
17075
|
};
|
|
16207
17076
|
}
|
|
16208
17077
|
});
|
|
@@ -16214,9 +17083,9 @@ __export(list_exports3, {
|
|
|
16214
17083
|
});
|
|
16215
17084
|
function parseLimit(value) {
|
|
16216
17085
|
if (value === void 0) return void 0;
|
|
16217
|
-
const
|
|
16218
|
-
const limit = Number(
|
|
16219
|
-
if (!/^\d+$/.test(
|
|
17086
|
+
const text4 = String(value).trim();
|
|
17087
|
+
const limit = Number(text4);
|
|
17088
|
+
if (!/^\d+$/.test(text4) || limit < 1 || limit > MAX_LIMIT) {
|
|
16220
17089
|
throw usageError(`--limit must be a whole number from 1 to ${MAX_LIMIT}.`, { field: "limit" });
|
|
16221
17090
|
}
|
|
16222
17091
|
return limit;
|
|
@@ -16293,7 +17162,7 @@ var init_use = __esm({
|
|
|
16293
17162
|
next: "kenso workspace list --search <name>"
|
|
16294
17163
|
});
|
|
16295
17164
|
}
|
|
16296
|
-
let
|
|
17165
|
+
let body2;
|
|
16297
17166
|
try {
|
|
16298
17167
|
const res = await ctx.client.request({
|
|
16299
17168
|
method: "GET",
|
|
@@ -16302,7 +17171,7 @@ var init_use = __esm({
|
|
|
16302
17171
|
headers: { "X-Ken-Workspace-Id": workspaceId },
|
|
16303
17172
|
signal: ctx.signal
|
|
16304
17173
|
});
|
|
16305
|
-
|
|
17174
|
+
body2 = res.body;
|
|
16306
17175
|
} catch (err) {
|
|
16307
17176
|
if (err instanceof KensoError && (err.httpStatus === 404 || err.httpStatus === 403 || err.httpStatus === 400)) {
|
|
16308
17177
|
throw new KensoError({
|
|
@@ -16318,7 +17187,7 @@ var init_use = __esm({
|
|
|
16318
17187
|
}
|
|
16319
17188
|
throw err;
|
|
16320
17189
|
}
|
|
16321
|
-
const workspace = unwrap(
|
|
17190
|
+
const workspace = unwrap(body2) ?? {};
|
|
16322
17191
|
const profileName = ctx.auth.profileName;
|
|
16323
17192
|
const existing = readConfig(ctx.env).profiles[profileName] ?? {};
|
|
16324
17193
|
writeProfile(profileName, { ...existing, workspaceId }, { env: ctx.env });
|
|
@@ -16335,11 +17204,11 @@ var init_use = __esm({
|
|
|
16335
17204
|
});
|
|
16336
17205
|
|
|
16337
17206
|
// src/commands/workspace/index.ts
|
|
16338
|
-
var
|
|
17207
|
+
var actions23;
|
|
16339
17208
|
var init_workspace = __esm({
|
|
16340
17209
|
"src/commands/workspace/index.ts"() {
|
|
16341
17210
|
"use strict";
|
|
16342
|
-
|
|
17211
|
+
actions23 = {
|
|
16343
17212
|
list: () => Promise.resolve().then(() => (init_list3(), list_exports3)).then((m) => m.default),
|
|
16344
17213
|
use: () => Promise.resolve().then(() => (init_use(), use_exports)).then((m) => m.default)
|
|
16345
17214
|
};
|
|
@@ -16347,10 +17216,10 @@ var init_workspace = __esm({
|
|
|
16347
17216
|
});
|
|
16348
17217
|
|
|
16349
17218
|
// src/commands/registry.ts
|
|
16350
|
-
function topLevel(name,
|
|
17219
|
+
function topLevel(name, load2, of) {
|
|
16351
17220
|
return {
|
|
16352
17221
|
"": async () => {
|
|
16353
|
-
const spec = await
|
|
17222
|
+
const spec = await load2();
|
|
16354
17223
|
return { ...spec, resource: name, action: "", brief: `same as ${of.slice("kenso ".length)}`, examples: spec.examples.map((e) => e.replace(of, `kenso ${name}`)) };
|
|
16355
17224
|
}
|
|
16356
17225
|
};
|
|
@@ -16365,6 +17234,7 @@ var init_registry = __esm({
|
|
|
16365
17234
|
init_auth2();
|
|
16366
17235
|
init_capture();
|
|
16367
17236
|
init_completion2();
|
|
17237
|
+
init_connect3();
|
|
16368
17238
|
init_contacts();
|
|
16369
17239
|
init_describe2();
|
|
16370
17240
|
init_docs2();
|
|
@@ -16388,25 +17258,26 @@ var init_registry = __esm({
|
|
|
16388
17258
|
auth: actions4,
|
|
16389
17259
|
capture: actions5,
|
|
16390
17260
|
completion: actions6,
|
|
16391
|
-
|
|
16392
|
-
|
|
16393
|
-
|
|
16394
|
-
|
|
16395
|
-
|
|
17261
|
+
connect: actions7,
|
|
17262
|
+
contacts: actions8,
|
|
17263
|
+
describe: actions9,
|
|
17264
|
+
docs: actions10,
|
|
17265
|
+
doctor: actions11,
|
|
17266
|
+
jobs: actions12,
|
|
16396
17267
|
login: topLevel("login", actions4.login, "kenso auth login"),
|
|
16397
17268
|
logout: topLevel("logout", actions4.logout, "kenso auth logout"),
|
|
16398
|
-
logs:
|
|
16399
|
-
mcp:
|
|
16400
|
-
opportunities:
|
|
16401
|
-
people:
|
|
16402
|
-
runs:
|
|
16403
|
-
sandbox:
|
|
16404
|
-
skill:
|
|
16405
|
-
studio:
|
|
16406
|
-
webhooks:
|
|
17269
|
+
logs: actions13,
|
|
17270
|
+
mcp: actions14,
|
|
17271
|
+
opportunities: actions15,
|
|
17272
|
+
people: actions16,
|
|
17273
|
+
runs: actions17,
|
|
17274
|
+
sandbox: actions18,
|
|
17275
|
+
skill: actions19,
|
|
17276
|
+
studio: actions20,
|
|
17277
|
+
webhooks: actions21,
|
|
16407
17278
|
whoami: topLevel("whoami", actions4.status, "kenso auth status"),
|
|
16408
|
-
work:
|
|
16409
|
-
workspace:
|
|
17279
|
+
work: actions22,
|
|
17280
|
+
workspace: actions23
|
|
16410
17281
|
};
|
|
16411
17282
|
resourceAliases = { leads: "contacts" };
|
|
16412
17283
|
}
|
|
@@ -16418,9 +17289,9 @@ function lazyFeatures(opts) {
|
|
|
16418
17289
|
return () => {
|
|
16419
17290
|
pending ??= (async () => {
|
|
16420
17291
|
if (opts.features) return opts.features;
|
|
16421
|
-
const
|
|
16422
|
-
if (!
|
|
16423
|
-
const lookup = await
|
|
17292
|
+
const load2 = opts.loadFeatures ?? (opts.env ? () => featuresFromEnv(opts.env) : void 0);
|
|
17293
|
+
if (!load2) return [];
|
|
17294
|
+
const lookup = await load2();
|
|
16424
17295
|
if (lookup.error) opts.warn?.(`Beta commands hidden: could not load workspace features (${lookup.error}).`);
|
|
16425
17296
|
return lookup.features;
|
|
16426
17297
|
})();
|
|
@@ -16447,10 +17318,10 @@ async function visibleSpecs(specs, opts, getFeatures, hidden) {
|
|
|
16447
17318
|
}
|
|
16448
17319
|
return visible;
|
|
16449
17320
|
}
|
|
16450
|
-
function wrap(
|
|
17321
|
+
function wrap(text4, indent) {
|
|
16451
17322
|
const out = [];
|
|
16452
17323
|
let line = "";
|
|
16453
|
-
for (const word of
|
|
17324
|
+
for (const word of text4.split(" ")) {
|
|
16454
17325
|
if (line && indent.length + line.length + 1 + word.length > 110) {
|
|
16455
17326
|
out.push(indent + line);
|
|
16456
17327
|
line = word;
|
|
@@ -16483,11 +17354,11 @@ function columns(rows, indent = " ", maxWidth = 28) {
|
|
|
16483
17354
|
const width = Math.min(maxWidth, Math.max(0, ...rows.map(([left]) => left.length)));
|
|
16484
17355
|
return rows.map(([left, right]) => `${indent}${left.padEnd(width)} ${right}`.trimEnd()).join("\n");
|
|
16485
17356
|
}
|
|
16486
|
-
function withAgentBlock(
|
|
16487
|
-
return agent ? `${
|
|
17357
|
+
function withAgentBlock(text4, agent) {
|
|
17358
|
+
return agent ? `${text4}
|
|
16488
17359
|
|
|
16489
17360
|
${FOR_AGENTS}
|
|
16490
|
-
` : `${
|
|
17361
|
+
` : `${text4}
|
|
16491
17362
|
`;
|
|
16492
17363
|
}
|
|
16493
17364
|
function commandName(spec) {
|
|
@@ -16505,7 +17376,7 @@ function flagLabel(name, flag) {
|
|
|
16505
17376
|
}
|
|
16506
17377
|
async function loadArea(resource) {
|
|
16507
17378
|
const area = handWritten[resource] ?? {};
|
|
16508
|
-
const specs = await Promise.all(Object.values(area).map((
|
|
17379
|
+
const specs = await Promise.all(Object.values(area).map((load2) => load2()));
|
|
16509
17380
|
return specs.sort((a, b) => a.action.localeCompare(b.action));
|
|
16510
17381
|
}
|
|
16511
17382
|
async function renderTopHelp(opts) {
|
|
@@ -16543,8 +17414,8 @@ async function renderTopHelp(opts) {
|
|
|
16543
17414
|
names.push(withPositionals(spec, spec.action));
|
|
16544
17415
|
groups.set(hint, names);
|
|
16545
17416
|
}
|
|
16546
|
-
const
|
|
16547
|
-
if (
|
|
17417
|
+
const actions25 = [...groups.entries()].map(([hint, names]) => `${names.join(", ")}${hint}`);
|
|
17418
|
+
if (actions25.length > 0) rows.push([resource, actions25.join(", ")]);
|
|
16548
17419
|
}
|
|
16549
17420
|
const at = 4 + Math.min(22, Math.max(0, ...rows.map(([left]) => left.length)));
|
|
16550
17421
|
lines.push(
|
|
@@ -16557,7 +17428,7 @@ async function renderTopHelp(opts) {
|
|
|
16557
17428
|
const [area = "", action = ""] = name.split(" ");
|
|
16558
17429
|
byArea.set(area, [...byArea.get(area) ?? [], action]);
|
|
16559
17430
|
}
|
|
16560
|
-
const named = [...byArea.entries()].map(([area,
|
|
17431
|
+
const named = [...byArea.entries()].map(([area, actions25]) => `${area} ${actions25.join("|")}`);
|
|
16561
17432
|
lines.push(wrap(`Beta, hidden here but they run (the server decides): ${named.join(", ")}.`, " "));
|
|
16562
17433
|
}
|
|
16563
17434
|
const generated = await listGenerated({ features: opts.allCommands ? [] : getFeatures, env: opts.env });
|
|
@@ -16565,13 +17436,13 @@ async function renderTopHelp(opts) {
|
|
|
16565
17436
|
if (visible.length > 0) {
|
|
16566
17437
|
const byResource = /* @__PURE__ */ new Map();
|
|
16567
17438
|
for (const g of visible) {
|
|
16568
|
-
const
|
|
16569
|
-
|
|
16570
|
-
byResource.set(g.resource,
|
|
17439
|
+
const actions25 = byResource.get(g.resource) ?? [];
|
|
17440
|
+
actions25.push(`${g.action}${g.beta ? " (beta)" : ""}`);
|
|
17441
|
+
byResource.set(g.resource, actions25);
|
|
16571
17442
|
}
|
|
16572
17443
|
const sorted2 = [...byResource.entries()].sort(([a], [b]) => a.localeCompare(b));
|
|
16573
17444
|
if (opts.allCommands) {
|
|
16574
|
-
const generatedRows = sorted2.map(([resource,
|
|
17445
|
+
const generatedRows = sorted2.map(([resource, actions25]) => [resource, actions25.sort().join(", ")]);
|
|
16575
17446
|
lines.push("", "API resources (kenso <resource> <action>):", columns(generatedRows));
|
|
16576
17447
|
} else {
|
|
16577
17448
|
const names = new Set(sorted2.map(([resource]) => resource));
|
|
@@ -16858,8 +17729,8 @@ async function fetchLatest(fetchImpl, signal, install) {
|
|
|
16858
17729
|
}
|
|
16859
17730
|
const res = await fetchImpl(REGISTRY_URL, { signal, headers: { accept: "application/json" } });
|
|
16860
17731
|
if (!res.ok) return void 0;
|
|
16861
|
-
const
|
|
16862
|
-
return typeof
|
|
17732
|
+
const body2 = await res.json();
|
|
17733
|
+
return typeof body2?.version === "string" && RELEASE.test(body2.version) ? body2.version : void 0;
|
|
16863
17734
|
}
|
|
16864
17735
|
function startUpdateNotice(argv, opts = {}) {
|
|
16865
17736
|
try {
|
|
@@ -16930,7 +17801,7 @@ function resources() {
|
|
|
16930
17801
|
const names = Object.entries(handWritten).filter(([, area]) => Object.keys(area).length > 0).map(([resource]) => resource);
|
|
16931
17802
|
return sorted([...names, ...Object.keys(resourceAliases), ...loadManifest().operations.map((op) => op.resource)]);
|
|
16932
17803
|
}
|
|
16933
|
-
function
|
|
17804
|
+
function actions24(resource) {
|
|
16934
17805
|
const own = Object.keys(handWritten[resource] ?? {}).filter((action) => action !== "");
|
|
16935
17806
|
return sorted([...own, ...loadManifest().operations.filter((op) => op.resource === resource).map((op) => op.action)]);
|
|
16936
17807
|
}
|
|
@@ -16995,7 +17866,7 @@ async function completions(words, globals) {
|
|
|
16995
17866
|
return flagsOf2(spec, globals, positionals.length === 0);
|
|
16996
17867
|
}
|
|
16997
17868
|
if (positionals.length === 0) return resources();
|
|
16998
|
-
if (!spec) return positionals.length === 1 ?
|
|
17869
|
+
if (!spec) return positionals.length === 1 ? actions24(resourceAliases[positionals[0]] ?? positionals[0]) : [];
|
|
16999
17870
|
const given = positionals.length - commandWords;
|
|
17000
17871
|
const declared = spec.positionals ?? [];
|
|
17001
17872
|
if (given < declared.length || declared.at(-1)?.variadic === true) {
|
|
@@ -17089,9 +17960,9 @@ function normalizeBooleans(argv, names, strict) {
|
|
|
17089
17960
|
async function knownCommands() {
|
|
17090
17961
|
const commands = /* @__PURE__ */ new Set();
|
|
17091
17962
|
for (const [resource, area] of Object.entries(handWritten)) {
|
|
17092
|
-
const
|
|
17093
|
-
if (
|
|
17094
|
-
for (const action of
|
|
17963
|
+
const actions25 = Object.keys(area);
|
|
17964
|
+
if (actions25.length > 0) commands.add(resource);
|
|
17965
|
+
for (const action of actions25) commands.add(action ? `${resource} ${action}` : resource);
|
|
17095
17966
|
}
|
|
17096
17967
|
for (const g of await listGenerated({ features: [] })) {
|
|
17097
17968
|
commands.add(g.resource);
|
|
@@ -17248,7 +18119,7 @@ async function main(argv, env = process.env, overrides = {}) {
|
|
|
17248
18119
|
const agent = detectAgent(env);
|
|
17249
18120
|
const controller = new AbortController();
|
|
17250
18121
|
const active = { controller, info: (message) => output.info(message) };
|
|
17251
|
-
const
|
|
18122
|
+
const interrupted7 = () => controller.signal.aborted;
|
|
17252
18123
|
let verbose = false;
|
|
17253
18124
|
try {
|
|
17254
18125
|
const loose = parseArgs({ args: normalizeBooleans(argv, new Set(GLOBAL_BOOLEANS), void 0), options: GLOBAL_OPTIONS, strict: false, allowPositionals: true });
|
|
@@ -17258,13 +18129,13 @@ async function main(argv, env = process.env, overrides = {}) {
|
|
|
17258
18129
|
return ExitCode.Ok;
|
|
17259
18130
|
}
|
|
17260
18131
|
verbose = loose.values.verbose === true;
|
|
17261
|
-
const
|
|
18132
|
+
const text4 = (value) => typeof value === "string" ? value : void 0;
|
|
17262
18133
|
const helpOptions = {
|
|
17263
18134
|
agent,
|
|
17264
18135
|
allCommands: loose.values["all-commands"] === true,
|
|
17265
18136
|
env,
|
|
17266
18137
|
// Cached features, else GET /v1/me with a 1,500 ms timeout, with main's env, flags and test overrides.
|
|
17267
|
-
loadFeatures: () => featuresFromEnv(env, { profile:
|
|
18138
|
+
loadFeatures: () => featuresFromEnv(env, { profile: text4(loose.values.profile), workspace: text4(loose.values.workspace) }, { fetchImpl: overrides.fetchImpl, sleep: overrides.sleep, signal: controller.signal }),
|
|
17268
18139
|
warn: (message) => {
|
|
17269
18140
|
lookupFailed = true;
|
|
17270
18141
|
output.info(message);
|
|
@@ -17316,15 +18187,15 @@ async function main(argv, env = process.env, overrides = {}) {
|
|
|
17316
18187
|
enterRun(active);
|
|
17317
18188
|
try {
|
|
17318
18189
|
const code = await spec.run(ctx, args);
|
|
17319
|
-
return
|
|
18190
|
+
return interrupted7() ? ExitCode.Interrupted : code;
|
|
17320
18191
|
} finally {
|
|
17321
18192
|
leaveRun(active);
|
|
17322
18193
|
}
|
|
17323
18194
|
} catch (err) {
|
|
17324
18195
|
let error;
|
|
17325
18196
|
if (err instanceof KensoError) {
|
|
17326
|
-
error =
|
|
17327
|
-
} else if (
|
|
18197
|
+
error = interrupted7() && err.exitCode !== ExitCode.Interrupted ? new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted }) : err;
|
|
18198
|
+
} else if (interrupted7()) {
|
|
17328
18199
|
error = new KensoError({ code: "interrupted", message: "Interrupted.", exitCode: ExitCode.Interrupted });
|
|
17329
18200
|
} else {
|
|
17330
18201
|
error = new KensoError({
|