sim 2.2.9-preview.213.1 → 2.2.9-preview.215.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/protocol/workspace-operation-wait.d.ts +3 -3
- package/dist/context.d.ts +1 -0
- package/dist/index.js +269 -190
- package/dist/runtime/called-operations.d.ts +61 -13
- package/dist/runtime/derive.d.ts +3 -0
- package/dist/runtime/request.d.ts +2 -1
- package/dist/runtime.js +269 -190
- package/dist/transfer/upload-session.d.ts +12 -4
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -3411,6 +3411,8 @@ import { dirname } from "node:path";
|
|
|
3411
3411
|
function truncate(str, sliceLength, suffix = "...") {
|
|
3412
3412
|
return str.length > sliceLength ? str.slice(0, sliceLength) + suffix : str;
|
|
3413
3413
|
}
|
|
3414
|
+
var UNPAIRED_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
3415
|
+
var JSONB_UNSAFE = new RegExp(`${UNPAIRED_SURROGATE.source}|\\u0000`, "g");
|
|
3414
3416
|
var MARKDOWN_ESCAPABLE = new Set("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");
|
|
3415
3417
|
function stripTrailingSlashes(value) {
|
|
3416
3418
|
let end = value.length;
|
|
@@ -17377,16 +17379,106 @@ var V2_OPERATIONS = {
|
|
|
17377
17379
|
}
|
|
17378
17380
|
};
|
|
17379
17381
|
|
|
17382
|
+
// src/runtime/derive.ts
|
|
17383
|
+
var ACTION_SEGMENTS = new Set([
|
|
17384
|
+
"upsert",
|
|
17385
|
+
"query",
|
|
17386
|
+
"search",
|
|
17387
|
+
"export",
|
|
17388
|
+
"import",
|
|
17389
|
+
"deploy",
|
|
17390
|
+
"rollback"
|
|
17391
|
+
]);
|
|
17392
|
+
function deriveCommandPath(operation) {
|
|
17393
|
+
const spec = V2_OPERATIONS[operation];
|
|
17394
|
+
const segments = spec.path.replace("/api/v2/", "").split("/");
|
|
17395
|
+
const resource = segments[0];
|
|
17396
|
+
const nouns = segments.slice(1).filter((segment) => !segment.startsWith("["));
|
|
17397
|
+
const last = nouns[nouns.length - 1];
|
|
17398
|
+
if (last && ACTION_SEGMENTS.has(last))
|
|
17399
|
+
return [resource, last];
|
|
17400
|
+
const isItem = spec.path.endsWith("]");
|
|
17401
|
+
const verb = spec.method === "GET" ? isItem ? "get" : "list" : spec.method === "POST" ? "create" : spec.method === "DELETE" ? "delete" : "update";
|
|
17402
|
+
return last ? [resource, last, verb] : [resource, verb];
|
|
17403
|
+
}
|
|
17404
|
+
function kebab(value) {
|
|
17405
|
+
return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);
|
|
17406
|
+
}
|
|
17407
|
+
function camel(flag) {
|
|
17408
|
+
return flag.replace(/-([a-z])/g, (_match, character) => character.toUpperCase());
|
|
17409
|
+
}
|
|
17410
|
+
function commandPath(command) {
|
|
17411
|
+
const names = [];
|
|
17412
|
+
for (let current = command;current?.parent; current = current.parent) {
|
|
17413
|
+
names.unshift(current.name());
|
|
17414
|
+
}
|
|
17415
|
+
return names;
|
|
17416
|
+
}
|
|
17417
|
+
|
|
17380
17418
|
// src/runtime/called-operations.ts
|
|
17381
17419
|
var CALLED_OPERATIONS = new WeakMap;
|
|
17382
17420
|
var RUNS_OPERATION = new WeakMap;
|
|
17383
|
-
|
|
17384
|
-
|
|
17385
|
-
|
|
17421
|
+
class OperationClient {
|
|
17422
|
+
client;
|
|
17423
|
+
operations;
|
|
17424
|
+
caller;
|
|
17425
|
+
constructor(client, operations, caller) {
|
|
17426
|
+
this.client = client;
|
|
17427
|
+
this.operations = operations;
|
|
17428
|
+
this.caller = caller;
|
|
17429
|
+
}
|
|
17430
|
+
requireWorkspace(explicit, options) {
|
|
17431
|
+
return this.client.requireWorkspace(explicit, options);
|
|
17432
|
+
}
|
|
17433
|
+
async request(operation, { params, ...options } = {}) {
|
|
17434
|
+
return this.client.request(this.route(operation, params), {
|
|
17435
|
+
...options,
|
|
17436
|
+
method: V2_OPERATIONS[operation].method
|
|
17437
|
+
});
|
|
17438
|
+
}
|
|
17439
|
+
async requestRaw(operation, { params, ...options } = {}) {
|
|
17440
|
+
return this.client.requestRaw(this.route(operation, params), {
|
|
17441
|
+
...options,
|
|
17442
|
+
method: V2_OPERATIONS[operation].method
|
|
17443
|
+
});
|
|
17444
|
+
}
|
|
17445
|
+
async requestAllPages(operation, { params, ...options }) {
|
|
17446
|
+
return requestAllPages(this.client, this.route(operation, params), {
|
|
17447
|
+
...options,
|
|
17448
|
+
method: V2_OPERATIONS[operation].method
|
|
17449
|
+
});
|
|
17450
|
+
}
|
|
17451
|
+
over(client) {
|
|
17452
|
+
return new OperationClient(client, this.operations, this.caller);
|
|
17453
|
+
}
|
|
17454
|
+
route(operation, params) {
|
|
17455
|
+
if (!this.operations.has(operation)) {
|
|
17456
|
+
throw new Error(`"${this.caller}" calls ${operation}, which it does not declare`);
|
|
17457
|
+
}
|
|
17458
|
+
return resolvePath(V2_OPERATIONS[operation].path, params);
|
|
17459
|
+
}
|
|
17460
|
+
}
|
|
17461
|
+
function caller(command) {
|
|
17462
|
+
return `sim ${commandPath(command).join(" ")}`;
|
|
17463
|
+
}
|
|
17464
|
+
function connect(command, expects = []) {
|
|
17465
|
+
const operations = new Set(CALLED_OPERATIONS.get(command));
|
|
17466
|
+
const missing = operations.size === 0 ? "what it calls" : expects.find((o) => !operations.has(o));
|
|
17467
|
+
if (missing) {
|
|
17468
|
+
throw new Error(`"${caller(command)}" calls the API without declaring ${missing}`);
|
|
17469
|
+
}
|
|
17470
|
+
const { client, profile } = clientFrom(command);
|
|
17471
|
+
return { client: new OperationClient(client, operations, caller(command)), profile };
|
|
17386
17472
|
}
|
|
17387
|
-
function callsOperations(command, operations) {
|
|
17473
|
+
function callsOperations(command, operations, { runs } = {}) {
|
|
17388
17474
|
CALLED_OPERATIONS.set(command, operations);
|
|
17389
|
-
|
|
17475
|
+
if (runs)
|
|
17476
|
+
RUNS_OPERATION.set(command, runs);
|
|
17477
|
+
return () => connect(command, operations);
|
|
17478
|
+
}
|
|
17479
|
+
function apiCommand(parent, name, operations, declaration = {}) {
|
|
17480
|
+
const command = parent.command(name);
|
|
17481
|
+
return [command, callsOperations(command, operations, declaration)];
|
|
17390
17482
|
}
|
|
17391
17483
|
|
|
17392
17484
|
// src/commands/auth.ts
|
|
@@ -17486,17 +17578,16 @@ function requireStoredAuthentication(profile) {
|
|
|
17486
17578
|
return authProfile;
|
|
17487
17579
|
}
|
|
17488
17580
|
async function getWorkspaceById(client, workspaceId) {
|
|
17489
|
-
const
|
|
17490
|
-
|
|
17581
|
+
const response = await client.request("getWorkspace", {
|
|
17582
|
+
params: { workspaceId }
|
|
17583
|
+
});
|
|
17491
17584
|
return response.data;
|
|
17492
17585
|
}
|
|
17493
17586
|
async function chooseWorkspace(client) {
|
|
17494
17587
|
if (!process.stdin.isTTY) {
|
|
17495
17588
|
throw new SimApiError("No workspace provided. Pass --workspace <id> when creating a profile non-interactively.", 0);
|
|
17496
17589
|
}
|
|
17497
|
-
const
|
|
17498
|
-
const workspaces = await requestAllPages(client, operation.path, {
|
|
17499
|
-
method: operation.method,
|
|
17590
|
+
const workspaces = await client.requestAllPages("listWorkspaces", {
|
|
17500
17591
|
query: { sortBy: "name", sortOrder: "asc" },
|
|
17501
17592
|
pageSize: 100,
|
|
17502
17593
|
limit: MAX_INTERACTIVE_WORKSPACES + 1
|
|
@@ -17525,9 +17616,11 @@ Available workspaces:`);
|
|
|
17525
17616
|
}
|
|
17526
17617
|
}
|
|
17527
17618
|
function addProfileCommand() {
|
|
17528
|
-
|
|
17619
|
+
const add = new Command("add");
|
|
17620
|
+
const connectAdd = callsOperations(add, ["getWorkspace", "listWorkspaces"]);
|
|
17621
|
+
return add.description("Add a workspace profile that shares the active stored login").argument("<name>", "Name for the new profile").option("-w, --workspace <id>", "Existing workspace to use; omit for an interactive picker").action(async (profileName, _options, command) => {
|
|
17529
17622
|
validateNewProfileName(profileName);
|
|
17530
|
-
const { client, profile } =
|
|
17623
|
+
const { client, profile } = connectAdd();
|
|
17531
17624
|
const authProfile = requireStoredAuthentication(profile);
|
|
17532
17625
|
const credential = readStoredCredential(authProfile);
|
|
17533
17626
|
const workspaceId = globalsOf(command).workspace;
|
|
@@ -17835,11 +17928,8 @@ async function verifyProfile(client, profile) {
|
|
|
17835
17928
|
}
|
|
17836
17929
|
let keyType = null;
|
|
17837
17930
|
let authenticated = null;
|
|
17838
|
-
const metaOperation = V2_OPERATIONS.getMeta;
|
|
17839
17931
|
try {
|
|
17840
|
-
const response = await client.request(
|
|
17841
|
-
method: metaOperation.method
|
|
17842
|
-
});
|
|
17932
|
+
const response = await client.request("getMeta");
|
|
17843
17933
|
const reportedKeyType = toRecord(toRecord(response).data).keyType;
|
|
17844
17934
|
if (reportedKeyType === "personal" || reportedKeyType === "workspace" || reportedKeyType === "oauth_access_token") {
|
|
17845
17935
|
keyType = reportedKeyType;
|
|
@@ -17867,9 +17957,10 @@ async function verifyProfile(client, profile) {
|
|
|
17867
17957
|
detail: `no workspace to check against — run: sim configure --profile ${safeOneLine(profile.name)} --set-workspace <id>`
|
|
17868
17958
|
};
|
|
17869
17959
|
}
|
|
17870
|
-
const operation = V2_OPERATIONS.getWorkspace;
|
|
17871
17960
|
try {
|
|
17872
|
-
const response = await client.request(
|
|
17961
|
+
const response = await client.request("getWorkspace", {
|
|
17962
|
+
params: { workspaceId: profile.workspaceId }
|
|
17963
|
+
});
|
|
17873
17964
|
const { id, name, memberCount } = response.data;
|
|
17874
17965
|
return {
|
|
17875
17966
|
status: "verified",
|
|
@@ -17909,8 +18000,10 @@ function presentVerification(verification) {
|
|
|
17909
18000
|
}
|
|
17910
18001
|
}
|
|
17911
18002
|
function whoamiCommand() {
|
|
17912
|
-
const whoami = new Command("whoami")
|
|
17913
|
-
|
|
18003
|
+
const whoami = new Command("whoami");
|
|
18004
|
+
const connectWhoami = callsOperations(whoami, ["getMeta", "getWorkspace"]);
|
|
18005
|
+
return whoami.description("Show the resolved profile, where each setting came from, and whether it works").option("--no-verify", "Skip the API check and only print the resolved settings").action(async (options) => {
|
|
18006
|
+
const { client, profile } = connectWhoami();
|
|
17914
18007
|
const { sources } = profile;
|
|
17915
18008
|
const authentication = presentAuthentication(sources.credential);
|
|
17916
18009
|
const verification = options.verify ? await verifyProfile(client, profile) : {
|
|
@@ -17958,7 +18051,6 @@ function whoamiCommand() {
|
|
|
17958
18051
|
if (exitCode !== 0)
|
|
17959
18052
|
setSoftExitCode(exitCode);
|
|
17960
18053
|
});
|
|
17961
|
-
return callsOperations(whoami, ["getMeta", "getWorkspace"]);
|
|
17962
18054
|
}
|
|
17963
18055
|
var PROFILE_COLUMNS = [
|
|
17964
18056
|
{ header: "", value: (row) => row.active ? styles3().green("*") : " " },
|
|
@@ -19820,35 +19912,6 @@ var CLI_CONTRACT = {
|
|
|
19820
19912
|
getFileUpload: { hidden: true }
|
|
19821
19913
|
};
|
|
19822
19914
|
|
|
19823
|
-
// src/runtime/derive.ts
|
|
19824
|
-
var ACTION_SEGMENTS = new Set([
|
|
19825
|
-
"upsert",
|
|
19826
|
-
"query",
|
|
19827
|
-
"search",
|
|
19828
|
-
"export",
|
|
19829
|
-
"import",
|
|
19830
|
-
"deploy",
|
|
19831
|
-
"rollback"
|
|
19832
|
-
]);
|
|
19833
|
-
function deriveCommandPath(operation) {
|
|
19834
|
-
const spec = V2_OPERATIONS[operation];
|
|
19835
|
-
const segments = spec.path.replace("/api/v2/", "").split("/");
|
|
19836
|
-
const resource = segments[0];
|
|
19837
|
-
const nouns = segments.slice(1).filter((segment) => !segment.startsWith("["));
|
|
19838
|
-
const last = nouns[nouns.length - 1];
|
|
19839
|
-
if (last && ACTION_SEGMENTS.has(last))
|
|
19840
|
-
return [resource, last];
|
|
19841
|
-
const isItem = spec.path.endsWith("]");
|
|
19842
|
-
const verb = spec.method === "GET" ? isItem ? "get" : "list" : spec.method === "POST" ? "create" : spec.method === "DELETE" ? "delete" : "update";
|
|
19843
|
-
return last ? [resource, last, verb] : [resource, verb];
|
|
19844
|
-
}
|
|
19845
|
-
function kebab(value) {
|
|
19846
|
-
return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);
|
|
19847
|
-
}
|
|
19848
|
-
function camel(flag) {
|
|
19849
|
-
return flag.replace(/-([a-z])/g, (_match, character) => character.toUpperCase());
|
|
19850
|
-
}
|
|
19851
|
-
|
|
19852
19915
|
// src/output/truncation.ts
|
|
19853
19916
|
var TRUNCATION_FLAG = /^truncated$|^[A-Za-z0-9]+Truncated$/;
|
|
19854
19917
|
var NEGATED_TRUNCATION_FLAG = /^(?:not|un|non|never)Truncated$|(?:Not|Un|Non|Never)Truncated$/;
|
|
@@ -20250,7 +20313,6 @@ function assertWorkspaceOperationOutcome(report, timedOut = false) {
|
|
|
20250
20313
|
}
|
|
20251
20314
|
async function waitWorkspaceOperation(client, workspaceId, operationId, timeoutSeconds, initial) {
|
|
20252
20315
|
const deadline = timeoutSeconds === 0 ? Number.POSITIVE_INFINITY : Date.now() + timeoutSeconds * 1000;
|
|
20253
|
-
const path = resolvePath(V2_OPERATIONS.getWorkspaceOperation.path, { workspaceId, operationId });
|
|
20254
20316
|
let report = initial;
|
|
20255
20317
|
let delay = 1000;
|
|
20256
20318
|
for (;; ) {
|
|
@@ -20265,7 +20327,8 @@ async function waitWorkspaceOperation(client, workspaceId, operationId, timeoutS
|
|
|
20265
20327
|
throw new SimApiError("Waiting timed out before a status response; reconcile using the same operation ID", 0, "OPERATION_WAIT_TIMEOUT", { workspaceId, operationId }, 4);
|
|
20266
20328
|
}
|
|
20267
20329
|
try {
|
|
20268
|
-
const nextReport = readWorkspaceOperation(await client.request(
|
|
20330
|
+
const nextReport = readWorkspaceOperation(await client.request("getWorkspaceOperation", {
|
|
20331
|
+
params: { workspaceId, operationId },
|
|
20269
20332
|
signal: Number.isFinite(remaining) ? AbortSignal.timeout(Math.max(1, Math.ceil(remaining))) : undefined
|
|
20270
20333
|
}));
|
|
20271
20334
|
if (nextReport.workspaceId !== workspaceId || nextReport.operationId !== operationId)
|
|
@@ -20293,9 +20356,10 @@ async function waitWorkspaceOperation(client, workspaceId, operationId, timeoutS
|
|
|
20293
20356
|
}
|
|
20294
20357
|
}
|
|
20295
20358
|
function attachWorkspaceOperationWait(operations) {
|
|
20296
|
-
|
|
20359
|
+
const [wait, connectWait] = apiCommand(operations, "wait", ["getWorkspaceOperation"]);
|
|
20360
|
+
wait.argument("<operationId>", "Operation ID returned by import, fork, push, or pull").allowExcessArguments(false).description("Wait for copy and deployment readiness; exit 3 for configuration, 1 for failure, or 4 for timeout").option("--wait-timeout <seconds>", "Maximum total wait (default 3600; 0 waits indefinitely)").action(async (operationId, options) => {
|
|
20297
20361
|
const timeout = workspaceWaitTimeout(options.waitTimeout);
|
|
20298
|
-
const { client, profile } =
|
|
20362
|
+
const { client, profile } = connectWait();
|
|
20299
20363
|
const workspaceId = client.requireWorkspace();
|
|
20300
20364
|
const result = await waitWorkspaceOperation(client, workspaceId, operationId, timeout);
|
|
20301
20365
|
renderResult("getWorkspaceOperation", profile.output, result.report, CLI_CONTRACT.getWorkspaceOperation ?? {});
|
|
@@ -20643,7 +20707,7 @@ function boundedRequest(request) {
|
|
|
20643
20707
|
async function buildRequest(operation, positional, flags, workspaceId) {
|
|
20644
20708
|
const commandSpec = CLI_CONTRACT[operation] ?? {};
|
|
20645
20709
|
const spec = V2_OPERATIONS[operation];
|
|
20646
|
-
|
|
20710
|
+
const params = {};
|
|
20647
20711
|
let positionalIndex = 0;
|
|
20648
20712
|
for (const param of spec.pathParams) {
|
|
20649
20713
|
const pathFlag = commandSpec.pathFlags?.[param];
|
|
@@ -20660,7 +20724,7 @@ async function buildRequest(operation, positional, flags, workspaceId) {
|
|
|
20660
20724
|
if (typeof value !== "string" || value.length === 0) {
|
|
20661
20725
|
throw new SimApiError(pathFlag ? `--${flagName} cannot be empty` : `<${argumentName}> cannot be empty`, 0);
|
|
20662
20726
|
}
|
|
20663
|
-
|
|
20727
|
+
params[param] = value;
|
|
20664
20728
|
}
|
|
20665
20729
|
const query = {};
|
|
20666
20730
|
const body = {};
|
|
@@ -20733,7 +20797,7 @@ async function buildRequest(operation, positional, flags, workspaceId) {
|
|
|
20733
20797
|
throw new SimApiError(`--${variant.name} must be a JSON ${variant.kind}`, 0);
|
|
20734
20798
|
}
|
|
20735
20799
|
return boundedRequest({
|
|
20736
|
-
|
|
20800
|
+
params,
|
|
20737
20801
|
query,
|
|
20738
20802
|
body: { ...body, [variant.property]: parsed },
|
|
20739
20803
|
...headerSlot
|
|
@@ -20747,14 +20811,14 @@ async function buildRequest(operation, positional, flags, workspaceId) {
|
|
|
20747
20811
|
throw new SimApiError("--body must be a JSON object", 0);
|
|
20748
20812
|
}
|
|
20749
20813
|
return boundedRequest({
|
|
20750
|
-
|
|
20814
|
+
params,
|
|
20751
20815
|
query,
|
|
20752
20816
|
body: { ...body, ...parsed },
|
|
20753
20817
|
...headerSlot
|
|
20754
20818
|
});
|
|
20755
20819
|
}
|
|
20756
20820
|
return boundedRequest({
|
|
20757
|
-
|
|
20821
|
+
params,
|
|
20758
20822
|
query,
|
|
20759
20823
|
body: spec.body ? body : undefined,
|
|
20760
20824
|
...headerSlot
|
|
@@ -21130,7 +21194,7 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
21130
21194
|
if (commandSpec.allWorkspaces && requestFlags.allWorkspaces && requestFlags.workspace) {
|
|
21131
21195
|
throw new SimApiError("--all-workspaces cannot be combined with --workspace", 0);
|
|
21132
21196
|
}
|
|
21133
|
-
const { client, profile } =
|
|
21197
|
+
const { client, profile } = connect(host);
|
|
21134
21198
|
const hasWorkspaceField = Boolean(operationSpec.query && PROFILE_INJECTED_FIELD in operationSpec.query || operationSpec.body && PROFILE_INJECTED_FIELD in operationSpec.body);
|
|
21135
21199
|
const omitsWorkspace = commandSpec.allWorkspaces && requestFlags.allWorkspaces === true;
|
|
21136
21200
|
const needsWorkspace = (hasWorkspaceField || commandSpec.profileWorkspacePath === true) && !omitsWorkspace;
|
|
@@ -21164,8 +21228,8 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
21164
21228
|
do {
|
|
21165
21229
|
const pageSize = Math.min(DEFAULT_PAGE_SIZE, limit - rows.length);
|
|
21166
21230
|
const pageLimit = "limit" in (operationSpec[paging] ?? {}) ? { limit: pageSize } : {};
|
|
21167
|
-
const page = await client.request(
|
|
21168
|
-
|
|
21231
|
+
const page = await client.request(operation, {
|
|
21232
|
+
params: request.params,
|
|
21169
21233
|
headers: request.headers,
|
|
21170
21234
|
query: paging === "query" ? { ...request.query, ...pageLimit, cursor } : request.query,
|
|
21171
21235
|
body: paging === "body" ? { ...request.body ?? {}, ...pageLimit, ...cursor ? { cursor } : {} } : request.body
|
|
@@ -21188,8 +21252,8 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
21188
21252
|
}
|
|
21189
21253
|
let result;
|
|
21190
21254
|
try {
|
|
21191
|
-
result = await client.request(
|
|
21192
|
-
|
|
21255
|
+
result = await client.request(operation, {
|
|
21256
|
+
params: request.params,
|
|
21193
21257
|
headers: request.headers,
|
|
21194
21258
|
query: request.query,
|
|
21195
21259
|
body: request.body
|
|
@@ -21344,7 +21408,7 @@ function argumentSyntax(command) {
|
|
|
21344
21408
|
return argument.required ? `<${name}>` : `[${name}]`;
|
|
21345
21409
|
}).join(" ");
|
|
21346
21410
|
}
|
|
21347
|
-
function
|
|
21411
|
+
function commandPath2(command) {
|
|
21348
21412
|
const names = [];
|
|
21349
21413
|
let current = command;
|
|
21350
21414
|
while (current) {
|
|
@@ -21366,7 +21430,7 @@ function addParseErrorGuidance(command) {
|
|
|
21366
21430
|
outputError(message, write);
|
|
21367
21431
|
if (message.startsWith("error: missing required argument ")) {
|
|
21368
21432
|
const syntax = argumentSyntax(command);
|
|
21369
|
-
const example = syntax ? `${
|
|
21433
|
+
const example = syntax ? `${commandPath2(command)} ${syntax}` : commandPath2(command);
|
|
21370
21434
|
write(`Example: ${example}
|
|
21371
21435
|
`);
|
|
21372
21436
|
return;
|
|
@@ -21375,13 +21439,13 @@ function addParseErrorGuidance(command) {
|
|
|
21375
21439
|
if (!token)
|
|
21376
21440
|
return;
|
|
21377
21441
|
if (looksLikeAnId(token) && command.registeredArguments.length > 0) {
|
|
21378
|
-
write(`Example: ${
|
|
21442
|
+
write(`Example: ${commandPath2(command)} -- ${token}
|
|
21379
21443
|
`);
|
|
21380
21444
|
return;
|
|
21381
21445
|
}
|
|
21382
21446
|
const flags = command.options.filter((option) => !option.hidden).map((option) => option.flags);
|
|
21383
|
-
write(flags.length > 0 ? `Options for ${
|
|
21384
|
-
` : `${
|
|
21447
|
+
write(flags.length > 0 ? `Options for ${commandPath2(command)}: ${flags.join(", ")}
|
|
21448
|
+
` : `${commandPath2(command)} takes no options.
|
|
21385
21449
|
`);
|
|
21386
21450
|
}
|
|
21387
21451
|
});
|
|
@@ -21441,7 +21505,7 @@ function refuseHelpAfterUnknownCommand(program) {
|
|
|
21441
21505
|
}
|
|
21442
21506
|
function configureOperation(command, operation, spec) {
|
|
21443
21507
|
const operationSpec = V2_OPERATIONS[operation];
|
|
21444
|
-
|
|
21508
|
+
callsOperations(command, spec.workspaceOperation ? [operation, "getWorkspaceOperation"] : [operation], { runs: operation });
|
|
21445
21509
|
command.allowExcessArguments(false);
|
|
21446
21510
|
for (const alias of spec.aliases ?? [])
|
|
21447
21511
|
command.alias(alias);
|
|
@@ -21668,12 +21732,9 @@ async function credentialValues(provider, raw) {
|
|
|
21668
21732
|
}
|
|
21669
21733
|
return values;
|
|
21670
21734
|
}
|
|
21671
|
-
async function createServiceAccount(
|
|
21672
|
-
const { client, profile } = clientFrom(command);
|
|
21735
|
+
async function createServiceAccount({ client, profile }, providerId, options) {
|
|
21673
21736
|
const workspaceId = client.requireWorkspace();
|
|
21674
|
-
const
|
|
21675
|
-
const catalog = await client.request(discovery.path, {
|
|
21676
|
-
method: discovery.method,
|
|
21737
|
+
const catalog = await client.request("listCredentialProviders", {
|
|
21677
21738
|
query: { workspaceId }
|
|
21678
21739
|
});
|
|
21679
21740
|
const provider = serviceAccountProvider(catalog.data, providerId);
|
|
@@ -21681,9 +21742,7 @@ async function createServiceAccount(command, providerId, options) {
|
|
|
21681
21742
|
throw new SimApiError(`--id is required for ${providerId}.`, 0);
|
|
21682
21743
|
}
|
|
21683
21744
|
const credentialFields = await credentialValues(provider, options.credentials);
|
|
21684
|
-
const
|
|
21685
|
-
const response = await client.request(operation.path, {
|
|
21686
|
-
method: operation.method,
|
|
21745
|
+
const response = await client.request("createServiceAccountCredential", {
|
|
21687
21746
|
body: {
|
|
21688
21747
|
workspaceId,
|
|
21689
21748
|
type: "service_account",
|
|
@@ -21696,11 +21755,8 @@ async function createServiceAccount(command, providerId, options) {
|
|
|
21696
21755
|
});
|
|
21697
21756
|
renderResult("createServiceAccountCredential", profile.output, response.data, SERVICE_ACCOUNT_RESULT);
|
|
21698
21757
|
}
|
|
21699
|
-
async function createConnectionLink(
|
|
21700
|
-
const
|
|
21701
|
-
const operation = V2_OPERATIONS.createCredentialConnection;
|
|
21702
|
-
const response = await client.request(operation.path, {
|
|
21703
|
-
method: operation.method,
|
|
21758
|
+
async function createConnectionLink({ client, profile }, body) {
|
|
21759
|
+
const response = await client.request("createCredentialConnection", {
|
|
21704
21760
|
body: {
|
|
21705
21761
|
workspaceId: client.requireWorkspace(),
|
|
21706
21762
|
...body
|
|
@@ -21727,11 +21783,14 @@ function attachCredentialCommands(program) {
|
|
|
21727
21783
|
if (!credentials)
|
|
21728
21784
|
throw new Error("The generated credentials command group is missing");
|
|
21729
21785
|
acceptNameOnUpdate(credentials);
|
|
21730
|
-
const create = credentials
|
|
21731
|
-
|
|
21732
|
-
|
|
21733
|
-
|
|
21734
|
-
|
|
21786
|
+
const [create, connectCreate] = apiCommand(credentials, "create", ["listCredentialProviders", "createServiceAccountCredential"], { runs: "createServiceAccountCredential" });
|
|
21787
|
+
create.argument("<providerId>", "Service-account provider to create a credential for").description(describeOperation(V2_OPERATIONS.createServiceAccountCredential, "Create a service-account credential using its discovered provider schema")).requiredOption("--name <displayName>", "Name shown for the credential in Sim (required)").requiredOption("--credentials <json|@file>", "Provider credentials as JSON (or @path / @- to read a file or stdin) (required)").option("--description <description>", "Optional credential description").option("--id <credentialId>", "Client-generated credential ID when provider discovery requires it").action((providerId, options) => createServiceAccount(connectCreate(), providerId, options));
|
|
21788
|
+
const [connect, connectLink] = apiCommand(credentials, "connect", ["createCredentialConnection"]);
|
|
21789
|
+
connect.argument("<providerId>", "OAuth provider to connect").description(describeOperation(V2_OPERATIONS.createCredentialConnection, "Create a short-lived link for connecting an OAuth provider")).requiredOption("--name <displayName>", "Name shown for the new credential in Sim (required)").action(async (providerId, options) => createConnectionLink(connectLink(), { providerId, displayName: options.name }));
|
|
21790
|
+
const [reconnect, reconnectLink] = apiCommand(credentials, "reconnect", [
|
|
21791
|
+
"createCredentialConnection"
|
|
21792
|
+
]);
|
|
21793
|
+
reconnect.argument("<credentialId>", "Existing OAuth credential to re-authorize").description(describeOperation(V2_OPERATIONS.createCredentialConnection, "Create a short-lived link for reconnecting an OAuth credential")).action((credentialId) => createConnectionLink(reconnectLink(), { credentialId }));
|
|
21735
21794
|
}
|
|
21736
21795
|
|
|
21737
21796
|
// src/http/ndjson.ts
|
|
@@ -21817,7 +21876,8 @@ function ignoreBrokenPipe(stream) {
|
|
|
21817
21876
|
};
|
|
21818
21877
|
}
|
|
21819
21878
|
function attachChat(program) {
|
|
21820
|
-
const chat = program
|
|
21879
|
+
const [chat, connectChat] = apiCommand(program, "chat", ["chat"]);
|
|
21880
|
+
chat.description("Ask Sim and print the reply").argument("<message>", "What to ask Sim").allowExcessArguments(false).option("-c, --conversation <id>", "Continue the conversation with this ID").addHelpText("after", `
|
|
21821
21881
|
Each turn prints the reply on stdout and the conversation ID on stderr; pass
|
|
21822
21882
|
that ID back with -c to continue the same conversation. With --output json or
|
|
21823
21883
|
yaml the reply is not streamed — the finished result is printed as one
|
|
@@ -21827,17 +21887,16 @@ Examples:
|
|
|
21827
21887
|
$ sim chat "What workflows do I have?"
|
|
21828
21888
|
$ sim chat -c 3f2a… "Which of those run on a schedule?"
|
|
21829
21889
|
$ sim --output json chat "Summarize yesterday's failed runs" | jq -r '.content'
|
|
21830
|
-
`).action(async (message, options
|
|
21890
|
+
`).action(async (message, options) => {
|
|
21831
21891
|
if (message.trim() === "") {
|
|
21832
21892
|
throw new SimApiError("<message> cannot be empty", 0);
|
|
21833
21893
|
}
|
|
21834
21894
|
if (options.conversation !== undefined && options.conversation.trim() === "") {
|
|
21835
21895
|
throw new SimApiError("-c/--conversation cannot be empty — pass the conversation id printed on stderr after each turn", 0);
|
|
21836
21896
|
}
|
|
21837
|
-
const { client, profile } =
|
|
21897
|
+
const { client, profile } = connectChat();
|
|
21838
21898
|
const workspaceId = client.requireWorkspace();
|
|
21839
|
-
const response = await client.requestRaw(
|
|
21840
|
-
method: "POST",
|
|
21899
|
+
const response = await client.requestRaw("chat", {
|
|
21841
21900
|
body: {
|
|
21842
21901
|
workspaceId,
|
|
21843
21902
|
message,
|
|
@@ -21883,7 +21942,6 @@ Examples:
|
|
|
21883
21942
|
restorePipeHandling?.();
|
|
21884
21943
|
}
|
|
21885
21944
|
});
|
|
21886
|
-
callsOperations(chat, ["chat"]);
|
|
21887
21945
|
}
|
|
21888
21946
|
|
|
21889
21947
|
// src/commands/protocol/files-get.ts
|
|
@@ -22064,16 +22122,16 @@ function isTerminalSafeContentType(contentType) {
|
|
|
22064
22122
|
"image/svg+xml"
|
|
22065
22123
|
].includes(mediaType);
|
|
22066
22124
|
}
|
|
22067
|
-
async function downloadToOutput(
|
|
22125
|
+
async function downloadToOutput(connectDownload, operation, params, options) {
|
|
22068
22126
|
const target = options.outputFile;
|
|
22069
22127
|
const writesToStdout = target === undefined || target === "-";
|
|
22070
22128
|
if (writesToStdout && options.force) {
|
|
22071
22129
|
throw new SimApiError("--force requires --output-file <path>", 0);
|
|
22072
22130
|
}
|
|
22073
|
-
const { client, profile } =
|
|
22131
|
+
const { client, profile } = connectDownload();
|
|
22074
22132
|
const workspaceId = client.requireWorkspace();
|
|
22075
|
-
const response = await client.requestRaw(
|
|
22076
|
-
|
|
22133
|
+
const response = await client.requestRaw(operation, {
|
|
22134
|
+
params,
|
|
22077
22135
|
query: { workspaceId }
|
|
22078
22136
|
});
|
|
22079
22137
|
if (!response.body) {
|
|
@@ -22091,18 +22149,18 @@ async function downloadToOutput(command, operation, pathParams, options) {
|
|
|
22091
22149
|
}
|
|
22092
22150
|
const savedTarget = await saveToFile(response.body, target, Boolean(options.force));
|
|
22093
22151
|
printProtocolResult(profile.output, {
|
|
22094
|
-
id:
|
|
22152
|
+
id: params.fileId,
|
|
22095
22153
|
path: savedTarget,
|
|
22096
22154
|
status: "saved"
|
|
22097
22155
|
});
|
|
22098
22156
|
}
|
|
22099
22157
|
function attachFileGet(files) {
|
|
22100
|
-
const get
|
|
22101
|
-
|
|
22158
|
+
const [get, connectGet] = apiCommand(files, "get", ["downloadFile"]);
|
|
22159
|
+
get.argument("<fileId>", "File whose content to read").allowExcessArguments(false).description("Download a file’s content to stdout or a local file").option("-o, --output-file <path>", "Write content to a file instead of stdout").option("--force", "Overwrite --output-file if it already exists").action((fileId, options) => downloadToOutput(connectGet, "downloadFile", { fileId }, options));
|
|
22102
22160
|
}
|
|
22103
22161
|
function attachFileVersionDownload(versions) {
|
|
22104
|
-
const download
|
|
22105
|
-
|
|
22162
|
+
const [download, connectDownload] = apiCommand(versions, "download", ["downloadFileVersion"]);
|
|
22163
|
+
download.argument("<fileId>", "File identifier.").argument("<version>", "Version number.").allowExcessArguments(false).description("Download the content of one version of a file").option("-o, --output-file <path>", "Write content to a file instead of stdout").option("--force", "Overwrite --output-file if it already exists").action((fileId, version, options) => downloadToOutput(connectDownload, "downloadFileVersion", { fileId, version }, options));
|
|
22106
22164
|
}
|
|
22107
22165
|
|
|
22108
22166
|
// src/transfer/upload-session.ts
|
|
@@ -22228,8 +22286,8 @@ async function uploadParts(client, workspaceId, session, transfer, file) {
|
|
|
22228
22286
|
for (let n = first;n < first + PART_URL_BATCH && n <= transfer.partCount; n++) {
|
|
22229
22287
|
partNumbers.push(n);
|
|
22230
22288
|
}
|
|
22231
|
-
const signed = await client.request(
|
|
22232
|
-
|
|
22289
|
+
const signed = await client.request(session.operations.parts, {
|
|
22290
|
+
params: session.params,
|
|
22233
22291
|
query: { workspaceId },
|
|
22234
22292
|
headers: { "upload-token": session.uploadToken },
|
|
22235
22293
|
body: { partNumbers }
|
|
@@ -22277,8 +22335,8 @@ async function finishUploadSession(client, workspaceId, session, path) {
|
|
|
22277
22335
|
await streamed?.verifyComplete();
|
|
22278
22336
|
await streamed?.close();
|
|
22279
22337
|
await snapshot?.dispose().catch(() => {});
|
|
22280
|
-
const completed = await client.request(
|
|
22281
|
-
|
|
22338
|
+
const completed = await client.request(session.operations.complete, {
|
|
22339
|
+
params: session.params,
|
|
22282
22340
|
query: { workspaceId },
|
|
22283
22341
|
headers: { "upload-token": session.uploadToken }
|
|
22284
22342
|
});
|
|
@@ -22286,9 +22344,9 @@ async function finishUploadSession(client, workspaceId, session, path) {
|
|
|
22286
22344
|
} catch (error) {
|
|
22287
22345
|
await streamed?.close();
|
|
22288
22346
|
const profile = embeddedProfile();
|
|
22289
|
-
const cleanupClient = profile ? new SimClient({ ...profile, signal: AbortSignal.timeout(5000) }) : client;
|
|
22290
|
-
await cleanupClient.request(session.
|
|
22291
|
-
|
|
22347
|
+
const cleanupClient = profile ? client.over(new SimClient({ ...profile, signal: AbortSignal.timeout(5000) })) : client;
|
|
22348
|
+
await cleanupClient.request(session.operations.abort, {
|
|
22349
|
+
params: session.params,
|
|
22292
22350
|
query: { workspaceId },
|
|
22293
22351
|
headers: { "upload-token": session.uploadToken }
|
|
22294
22352
|
}).catch(() => {
|
|
@@ -22303,12 +22361,17 @@ async function finishUploadSession(client, workspaceId, session, path) {
|
|
|
22303
22361
|
|
|
22304
22362
|
// src/commands/protocol/files-upload.ts
|
|
22305
22363
|
function attachFileUpload(files) {
|
|
22306
|
-
|
|
22307
|
-
|
|
22364
|
+
const [upload, connectUpload] = apiCommand(files, "upload", [
|
|
22365
|
+
"createFileUpload",
|
|
22366
|
+
"createFileUploadPartUrls",
|
|
22367
|
+
"completeFileUpload",
|
|
22368
|
+
"abortFileUpload"
|
|
22369
|
+
]);
|
|
22370
|
+
upload.argument("<path>", "Local file to upload").allowExcessArguments(false).description("Upload a file to the workspace").option("--folder <path>", "Folder path as shown in the app; defaults to the root folder").option("--name <name>", "Store it under a different name").action(async (path, options) => {
|
|
22371
|
+
const { client, profile } = connectUpload();
|
|
22308
22372
|
const workspaceId = client.requireWorkspace();
|
|
22309
22373
|
const { name, size } = await localFile(path, options.name);
|
|
22310
|
-
const created = await client.request(
|
|
22311
|
-
method: "POST",
|
|
22374
|
+
const created = await client.request("createFileUpload", {
|
|
22312
22375
|
body: {
|
|
22313
22376
|
workspaceId,
|
|
22314
22377
|
name,
|
|
@@ -22319,7 +22382,12 @@ function attachFileUpload(files) {
|
|
|
22319
22382
|
});
|
|
22320
22383
|
const { session, uploadToken, transfer } = created.data;
|
|
22321
22384
|
const completed = await finishUploadSession(client, workspaceId, {
|
|
22322
|
-
|
|
22385
|
+
operations: {
|
|
22386
|
+
parts: "createFileUploadPartUrls",
|
|
22387
|
+
complete: "completeFileUpload",
|
|
22388
|
+
abort: "abortFileUpload"
|
|
22389
|
+
},
|
|
22390
|
+
params: { uploadId: session.id },
|
|
22323
22391
|
uploadToken,
|
|
22324
22392
|
transfer,
|
|
22325
22393
|
size
|
|
@@ -22356,12 +22424,18 @@ var UPLOAD_RECIPES = [
|
|
|
22356
22424
|
];
|
|
22357
22425
|
var LANGUAGE_TAG_HELP = "Document language tag: hyphen-separated letter and digit subtags, for example en or en-US";
|
|
22358
22426
|
function attachKnowledgeDocumentUpload(documents) {
|
|
22359
|
-
|
|
22360
|
-
|
|
22427
|
+
const [upload, connectUpload] = apiCommand(documents, "upload", [
|
|
22428
|
+
"createKnowledgeDocumentUpload",
|
|
22429
|
+
"createKnowledgeDocumentUploadPartUrls",
|
|
22430
|
+
"completeKnowledgeDocumentUpload",
|
|
22431
|
+
"abortKnowledgeDocumentUpload"
|
|
22432
|
+
]);
|
|
22433
|
+
upload.argument("<knowledgeBaseId>", "Knowledge base to upload into").argument("<path>", "Local file to upload").allowExcessArguments(false).description("Upload a document to a knowledge base").option("--name <name>", "Store it under a different name").option("--tag <value...>", "Document tags, in tag1 through tag7 order").addOption(new Option("--recipe <name>", "Document processing recipe").choices(UPLOAD_RECIPES)).option("--lang <code>", LANGUAGE_TAG_HELP).action(async (knowledgeBaseId, path, options) => {
|
|
22434
|
+
const { client, profile } = connectUpload();
|
|
22361
22435
|
const workspaceId = client.requireWorkspace();
|
|
22362
22436
|
const { name, size } = await localFile(path, options.name);
|
|
22363
|
-
const created = await client.request(
|
|
22364
|
-
|
|
22437
|
+
const created = await client.request("createKnowledgeDocumentUpload", {
|
|
22438
|
+
params: { knowledgeBaseId },
|
|
22365
22439
|
body: {
|
|
22366
22440
|
workspaceId,
|
|
22367
22441
|
name,
|
|
@@ -22372,7 +22446,12 @@ function attachKnowledgeDocumentUpload(documents) {
|
|
|
22372
22446
|
});
|
|
22373
22447
|
const { session, uploadToken, transfer } = created.data;
|
|
22374
22448
|
const completed = await finishUploadSession(client, workspaceId, {
|
|
22375
|
-
|
|
22449
|
+
operations: {
|
|
22450
|
+
parts: "createKnowledgeDocumentUploadPartUrls",
|
|
22451
|
+
complete: "completeKnowledgeDocumentUpload",
|
|
22452
|
+
abort: "abortKnowledgeDocumentUpload"
|
|
22453
|
+
},
|
|
22454
|
+
params: { knowledgeBaseId, uploadId: session.id },
|
|
22376
22455
|
uploadToken,
|
|
22377
22456
|
transfer,
|
|
22378
22457
|
size
|
|
@@ -22411,16 +22490,16 @@ function safeBaseName(name) {
|
|
|
22411
22490
|
return base && base !== "." && base !== ".." ? base : null;
|
|
22412
22491
|
}
|
|
22413
22492
|
function attachKnowledgeExport(knowledge) {
|
|
22414
|
-
const exportCommand
|
|
22493
|
+
const [exportCommand, connectExport] = apiCommand(knowledge, "export", ["exportKnowledgeBase"]);
|
|
22494
|
+
exportCommand.argument("<knowledgeBaseId>", "Knowledge base to export").allowExcessArguments(false).description("Export a knowledge base as a .simkb.zip bundle").option("-o, --output-file <path>", "Write the bundle to this path instead of the name the server suggests; pass - to stream it to stdout").option("--force", "Overwrite --output-file if it already exists").option("--no-vectors", "Leave chunk vectors out of the bundle, so an import re-embeds every chunk").action(async (knowledgeBaseId, options) => {
|
|
22415
22495
|
const writesToStdout = options.outputFile === "-";
|
|
22416
22496
|
if (writesToStdout && options.force) {
|
|
22417
22497
|
throw new SimApiError("--force requires --output-file <path>", 0);
|
|
22418
22498
|
}
|
|
22419
|
-
const { client, profile } =
|
|
22499
|
+
const { client, profile } = connectExport();
|
|
22420
22500
|
const workspaceId = client.requireWorkspace();
|
|
22421
|
-
const
|
|
22422
|
-
|
|
22423
|
-
method: operation.method,
|
|
22501
|
+
const response = await client.requestRaw("exportKnowledgeBase", {
|
|
22502
|
+
params: { knowledgeBaseId },
|
|
22424
22503
|
query: { workspaceId, vectors: options.vectors }
|
|
22425
22504
|
});
|
|
22426
22505
|
if (!response.body) {
|
|
@@ -22444,7 +22523,6 @@ function attachKnowledgeExport(knowledge) {
|
|
|
22444
22523
|
vectors: options.vectors
|
|
22445
22524
|
});
|
|
22446
22525
|
});
|
|
22447
|
-
callsOperations(exportCommand, ["exportKnowledgeBase"]);
|
|
22448
22526
|
}
|
|
22449
22527
|
|
|
22450
22528
|
// src/commands/protocol/logs-follow.ts
|
|
@@ -22603,12 +22681,12 @@ function remember(state, rows) {
|
|
|
22603
22681
|
excess -= 1;
|
|
22604
22682
|
}
|
|
22605
22683
|
}
|
|
22606
|
-
async function collectUnprinted(client,
|
|
22684
|
+
async function collectUnprinted(client, query, state, pageSize, maxPages) {
|
|
22607
22685
|
const rows = [];
|
|
22608
22686
|
let cursor = null;
|
|
22609
22687
|
let truncated = false;
|
|
22610
22688
|
for (let page = 0;page < maxPages; page += 1) {
|
|
22611
|
-
const response = await client.request(
|
|
22689
|
+
const response = await client.request("listLogs", {
|
|
22612
22690
|
query: { ...query, limit: pageSize, cursor }
|
|
22613
22691
|
});
|
|
22614
22692
|
const page_rows = response?.data ?? [];
|
|
@@ -22647,7 +22725,8 @@ function inSeconds(ms) {
|
|
|
22647
22725
|
return Math.round(ms / 100) / 10;
|
|
22648
22726
|
}
|
|
22649
22727
|
function attachLogsFollow(logs) {
|
|
22650
|
-
|
|
22728
|
+
const [follow, connectFollow] = apiCommand(logs, "follow", ["listLogs"]);
|
|
22729
|
+
follow.description("Watch runs live as they arrive, printing each new run once").option("--workflow <id>", "Only follow runs of this workflow (repeatable)", collect, []).option("--folder <path>", "Only follow runs of workflows in this folder (repeatable)", collect, []).option("--trigger <type>", "Only follow runs with this trigger type (repeatable)", collect, []).addOption(new Option("--level <level>", "Only follow runs at this severity").choices([
|
|
22651
22730
|
...V2_OPERATIONS.listLogs.query.level.values
|
|
22652
22731
|
])).addOption(new Option("--details <level>", "Response detail level; full names each run’s workflow").choices([...V2_OPERATIONS.listLogs.query.details.values]).default("full")).option("-n, --lines <count>", "Recent runs to print before watching", String(DEFAULT_BACKLOG)).option("--interval <seconds>", "Seconds between polls", String(DEFAULT_INTERVAL_SECONDS)).addHelpText("after", `
|
|
22653
22732
|
Each run prints once, when it is first seen, so its status is the status it had
|
|
@@ -22661,11 +22740,10 @@ Examples:
|
|
|
22661
22740
|
$ sim logs follow --level error
|
|
22662
22741
|
$ sim logs follow --workflow 00000000-0000-4000-8000-000000000000 -n 0
|
|
22663
22742
|
$ sim --output json logs follow | jq -r '.runId'
|
|
22664
|
-
`).action(async (options
|
|
22743
|
+
`).action(async (options) => {
|
|
22665
22744
|
const lines = nonNegativeInteger(options.lines, "--lines");
|
|
22666
22745
|
const delay = intervalMs(options.interval);
|
|
22667
|
-
const { client, profile } =
|
|
22668
|
-
const path = V2_OPERATIONS.listLogs.path;
|
|
22746
|
+
const { client, profile } = connectFollow();
|
|
22669
22747
|
const query = {
|
|
22670
22748
|
workspaceId: client.requireWorkspace(),
|
|
22671
22749
|
workflowIds: options.workflow?.length ? options.workflow.join(",") : undefined,
|
|
@@ -22681,7 +22759,7 @@ Examples:
|
|
|
22681
22759
|
const interrupt = watchForInterrupt();
|
|
22682
22760
|
const state = { seen: new Map, floor: null };
|
|
22683
22761
|
try {
|
|
22684
|
-
const seed = await collectUnprinted(client,
|
|
22762
|
+
const seed = await collectUnprinted(client, query, state, Math.max(lines, 1), 1);
|
|
22685
22763
|
remember(state, seed.rows);
|
|
22686
22764
|
state.floor = seed.rows.at(-1)?.startedAt ?? null;
|
|
22687
22765
|
if (seed.truncated && seed.rows.length < lines) {
|
|
@@ -22695,7 +22773,7 @@ Examples:
|
|
|
22695
22773
|
break;
|
|
22696
22774
|
let fresh;
|
|
22697
22775
|
try {
|
|
22698
|
-
fresh = await collectUnprinted(client,
|
|
22776
|
+
fresh = await collectUnprinted(client, query, state, POLL_PAGE_SIZE, MAX_PAGES_PER_POLL);
|
|
22699
22777
|
} catch (error) {
|
|
22700
22778
|
if (!isTransient(error))
|
|
22701
22779
|
throw error;
|
|
@@ -22732,25 +22810,21 @@ var COLUMNS2 = [
|
|
|
22732
22810
|
{ header: "folder", value: (entry) => text(decodeFolderPath(entry.folderPath)) },
|
|
22733
22811
|
{ header: "updated", value: (entry) => timestamp2(entry.updatedAt) }
|
|
22734
22812
|
];
|
|
22735
|
-
function operationPath(operation) {
|
|
22736
|
-
return V2_OPERATIONS[operation].path;
|
|
22737
|
-
}
|
|
22738
22813
|
async function listResources(client, config, workspaceId, folderPath, search, limit) {
|
|
22739
22814
|
const query = { workspaceId, folderPath, search, sortBy: "name", sortOrder: "asc" };
|
|
22740
|
-
const path = operationPath(config.resources);
|
|
22741
22815
|
const paginated = "cursor" in V2_OPERATIONS[config.resources].query;
|
|
22742
22816
|
if (!paginated) {
|
|
22743
|
-
const page = await client.request(
|
|
22817
|
+
const page = await client.request(config.resources, { query });
|
|
22744
22818
|
return page.data.slice(0, limit);
|
|
22745
22819
|
}
|
|
22746
|
-
return requestAllPages(
|
|
22820
|
+
return client.requestAllPages(config.resources, {
|
|
22747
22821
|
query,
|
|
22748
22822
|
pageSize: DEFAULT_PAGE_SIZE,
|
|
22749
22823
|
limit
|
|
22750
22824
|
});
|
|
22751
22825
|
}
|
|
22752
22826
|
async function listFolders(client, operation, workspaceId, parentPath, search) {
|
|
22753
|
-
const page = await client.request(
|
|
22827
|
+
const page = await client.request(operation, {
|
|
22754
22828
|
query: { workspaceId, parentPath, search, sortBy: "name", sortOrder: "asc" }
|
|
22755
22829
|
});
|
|
22756
22830
|
return page.data;
|
|
@@ -22775,14 +22849,15 @@ function entriesFor(config, folders, resources) {
|
|
|
22775
22849
|
].sort((left, right) => left.name.localeCompare(right.name) || left.kind.localeCompare(right.kind));
|
|
22776
22850
|
}
|
|
22777
22851
|
function attachResourceDirectoryCommands(group, config) {
|
|
22778
|
-
|
|
22852
|
+
const [ls, connectLs] = apiCommand(group, "ls", [config.resources, config.folders]);
|
|
22853
|
+
ls.argument("[path]", "Folder path to list; defaults to the root folder").allowExcessArguments(false).description(`List ${config.kind} resources and child folders together`).option("--search <text>", "Filter folders and resources by name").addOption(new Option("--limit <n>", "Maximum combined items to return (0 for everything)").default("0")).action(async (path, options) => {
|
|
22779
22854
|
const rawLimit = Number(options.limit);
|
|
22780
22855
|
if (!Number.isSafeInteger(rawLimit) || rawLimit < 0) {
|
|
22781
22856
|
throw new SimApiError("--limit must be a whole number of 0 or more (0 for everything)", 0);
|
|
22782
22857
|
}
|
|
22783
22858
|
const limit = rawLimit === 0 ? Number.POSITIVE_INFINITY : rawLimit;
|
|
22784
22859
|
const folderPath = encodeFolderPath(path ?? "/");
|
|
22785
|
-
const { client, profile } =
|
|
22860
|
+
const { client, profile } = connectLs();
|
|
22786
22861
|
const workspaceId = client.requireWorkspace();
|
|
22787
22862
|
const [folders, resources] = await Promise.all([
|
|
22788
22863
|
listFolders(client, config.folders, workspaceId, folderPath, options.search),
|
|
@@ -22792,11 +22867,10 @@ function attachResourceDirectoryCommands(group, config) {
|
|
|
22792
22867
|
const shown = entries.slice(0, limit);
|
|
22793
22868
|
printList(profile.output, shown, COLUMNS2);
|
|
22794
22869
|
});
|
|
22795
|
-
|
|
22796
|
-
|
|
22797
|
-
const
|
|
22798
|
-
const result = await client.request(
|
|
22799
|
-
method: operation.method,
|
|
22870
|
+
const [mkdir, connectMkdir] = apiCommand(group, "mkdir", [config.createFolder]);
|
|
22871
|
+
mkdir.argument("<path>", "Folder path to create; the leading / is optional").allowExcessArguments(false).description(`Create a ${config.kind} directory at a path`).action(async (path) => {
|
|
22872
|
+
const { client, profile } = connectMkdir();
|
|
22873
|
+
const result = await client.request(config.createFolder, {
|
|
22800
22874
|
body: { workspaceId: client.requireWorkspace(), path: encodeFolderPath(path) }
|
|
22801
22875
|
});
|
|
22802
22876
|
renderResult(config.createFolder, profile.output, result.data ?? result, {});
|
|
@@ -22845,7 +22919,10 @@ async function watchImport(client, workspaceId, job) {
|
|
|
22845
22919
|
let reported = null;
|
|
22846
22920
|
while (!IMPORT_SETTLED.has(current.status)) {
|
|
22847
22921
|
await sleep2(IMPORT_POLL_MS);
|
|
22848
|
-
const next = await client.request(
|
|
22922
|
+
const next = await client.request("getTableImport", {
|
|
22923
|
+
params: { importId: current.id },
|
|
22924
|
+
query: { workspaceId }
|
|
22925
|
+
});
|
|
22849
22926
|
current = next.data;
|
|
22850
22927
|
const line = progressLine(current);
|
|
22851
22928
|
if (hasProgressTerminal() && line !== reported) {
|
|
@@ -22875,8 +22952,15 @@ function validateTargetOptions(options) {
|
|
|
22875
22952
|
return intoExisting;
|
|
22876
22953
|
}
|
|
22877
22954
|
function attachTableImport(tables) {
|
|
22878
|
-
|
|
22879
|
-
|
|
22955
|
+
const [importCommand, connectImport] = apiCommand(tables, "import", [
|
|
22956
|
+
"createTableImport",
|
|
22957
|
+
"createTableImportPartUrls",
|
|
22958
|
+
"completeTableImport",
|
|
22959
|
+
"cancelTableImport",
|
|
22960
|
+
"getTableImport"
|
|
22961
|
+
]);
|
|
22962
|
+
importCommand.argument("[path]", "Local CSV file to import; omit when using --file-id").allowExcessArguments(false).description("Import a CSV, into a new table by default").option("--name <name>", "Identifier for the new table: letters, numbers, and underscores; defaults to the sanitized file name").option("--table-id <id>", "Import into this existing table instead of creating one").addOption(new Option("--mode <append|replace>", "How to write into --table-id (default: append)").choices(["append", "replace"])).option("--folder <path>", "Folder path for the new table, as shown in the app").option("--file-id <id>", "Import a file already in the workspace instead of a local path").option("--mapping <json|@file>", "Column mapping (--table-id only)").option("--create-columns <json|@file>", "Columns to create (--table-id only)").option("--timezone <iana>", "Timezone for date parsing, e.g. America/New_York").option("-y, --yes", "Confirm this destructive operation (required with --mode replace)").option("--no-wait", "Return once the import is queued instead of watching it").action(async (path, options) => {
|
|
22963
|
+
const { client, profile } = connectImport();
|
|
22880
22964
|
const workspaceId = client.requireWorkspace();
|
|
22881
22965
|
if (Boolean(path) === Boolean(options.fileId)) {
|
|
22882
22966
|
throw new SimApiError("Pass exactly one of <path> or --file-id <id>", 0);
|
|
@@ -22906,8 +22990,7 @@ function attachTableImport(tables) {
|
|
|
22906
22990
|
...options.folder !== undefined ? { folderPath: encodeFolderPath(options.folder) } : {}
|
|
22907
22991
|
};
|
|
22908
22992
|
}
|
|
22909
|
-
const started = await client.request(
|
|
22910
|
-
method: "POST",
|
|
22993
|
+
const started = await client.request("createTableImport", {
|
|
22911
22994
|
body: {
|
|
22912
22995
|
workspaceId,
|
|
22913
22996
|
source,
|
|
@@ -22922,12 +23005,18 @@ function attachTableImport(tables) {
|
|
|
22922
23005
|
if (!local || !started.data.uploadToken || !started.data.transfer) {
|
|
22923
23006
|
throw new Error("Local table import did not return an upload transfer");
|
|
22924
23007
|
}
|
|
22925
|
-
|
|
22926
|
-
|
|
23008
|
+
const completed = await finishUploadSession(client, workspaceId, {
|
|
23009
|
+
operations: {
|
|
23010
|
+
parts: "createTableImportPartUrls",
|
|
23011
|
+
complete: "completeTableImport",
|
|
23012
|
+
abort: "cancelTableImport"
|
|
23013
|
+
},
|
|
23014
|
+
params: { importId: job.id },
|
|
22927
23015
|
uploadToken: started.data.uploadToken,
|
|
22928
23016
|
transfer: started.data.transfer,
|
|
22929
23017
|
size: local.size
|
|
22930
23018
|
}, path);
|
|
23019
|
+
job = completed;
|
|
22931
23020
|
}
|
|
22932
23021
|
if (!options.wait) {
|
|
22933
23022
|
printProtocolResult(profile.output, {
|
|
@@ -23045,13 +23134,13 @@ function withEmbeddedFileReferences(body) {
|
|
|
23045
23134
|
}
|
|
23046
23135
|
async function runWithResultStream(workflowId, command) {
|
|
23047
23136
|
const flags = command.optsWithGlobals();
|
|
23048
|
-
const { client, profile } =
|
|
23137
|
+
const { client, profile } = connect(command, ["executeWorkflow"]);
|
|
23049
23138
|
const operation = V2_OPERATIONS.executeWorkflow;
|
|
23050
23139
|
const commandSpec = CLI_CONTRACT.executeWorkflow ?? {};
|
|
23051
23140
|
try {
|
|
23052
23141
|
const request = await buildRequest("executeWorkflow", [workflowId], flags, profile.workspaceId);
|
|
23053
|
-
const response = await client.requestRaw(
|
|
23054
|
-
|
|
23142
|
+
const response = await client.requestRaw("executeWorkflow", {
|
|
23143
|
+
params: request.params,
|
|
23055
23144
|
query: request.query,
|
|
23056
23145
|
body: withEmbeddedFileReferences(request.body),
|
|
23057
23146
|
headers: { ...request.headers, accept: WORKFLOW_RESULT_STREAM_CONTENT_TYPE }
|
|
@@ -23189,11 +23278,11 @@ async function followRun(workflowId, command) {
|
|
|
23189
23278
|
const includeThinking = flags.includeThinking === true;
|
|
23190
23279
|
const includeToolCalls = flags.includeToolCalls === true;
|
|
23191
23280
|
const negotiates = includeThinking || includeToolCalls;
|
|
23192
|
-
const { client, profile } =
|
|
23281
|
+
const { client, profile } = connect(command, ["executeWorkflow"]);
|
|
23193
23282
|
const operation = V2_OPERATIONS.executeWorkflow;
|
|
23194
23283
|
const request = await buildRequest("executeWorkflow", [workflowId], flags, profile.workspaceId);
|
|
23195
|
-
const response = await client.requestRaw(
|
|
23196
|
-
|
|
23284
|
+
const response = await client.requestRaw("executeWorkflow", {
|
|
23285
|
+
params: request.params,
|
|
23197
23286
|
query: request.query,
|
|
23198
23287
|
body: {
|
|
23199
23288
|
...withEmbeddedFileReferences(request.body),
|
|
@@ -23269,10 +23358,7 @@ function normalizeBlockName(name) {
|
|
|
23269
23358
|
return name.toLowerCase().replace(/\s+/g, "").replace(/\./g, "");
|
|
23270
23359
|
}
|
|
23271
23360
|
async function loadWorkflowBlocks(client, workflowId) {
|
|
23272
|
-
const
|
|
23273
|
-
const raw = await client.request(resolvePath(operation.path, { workflowId }), {
|
|
23274
|
-
method: operation.method
|
|
23275
|
-
});
|
|
23361
|
+
const raw = await client.request("getWorkflowState", { params: { workflowId } });
|
|
23276
23362
|
const state = isRecordLike(raw) && isRecordLike(raw.data) ? raw.data : raw;
|
|
23277
23363
|
const blocks = isRecordLike(state) && isRecordLike(state.blocks) ? Object.entries(state.blocks) : [];
|
|
23278
23364
|
return blocks.map(([key, block]) => ({
|
|
@@ -23326,9 +23412,8 @@ function keyByTyped(payload, typedBy) {
|
|
|
23326
23412
|
}
|
|
23327
23413
|
return { ...payload, blockOutputs };
|
|
23328
23414
|
}
|
|
23329
|
-
async function readRunByName(runId, typed, command) {
|
|
23415
|
+
async function readRunByName(runId, typed, command, { client, profile }) {
|
|
23330
23416
|
const flags = command.optsWithGlobals();
|
|
23331
|
-
const { client, profile } = clientFrom(command);
|
|
23332
23417
|
const operation = V2_OPERATIONS.getWorkflowRun;
|
|
23333
23418
|
const spec = CLI_CONTRACT.getWorkflowRun ?? {};
|
|
23334
23419
|
await buildRequest("getWorkflowRun", [runId], flags, profile.workspaceId);
|
|
@@ -23337,8 +23422,8 @@ async function readRunByName(runId, typed, command) {
|
|
|
23337
23422
|
const request = await buildRequest("getWorkflowRun", [runId], { ...flags, selectOutput: selection.resolved }, profile.workspaceId);
|
|
23338
23423
|
let result;
|
|
23339
23424
|
try {
|
|
23340
|
-
result = await client.request(
|
|
23341
|
-
|
|
23425
|
+
result = await client.request("getWorkflowRun", {
|
|
23426
|
+
params: request.params,
|
|
23342
23427
|
headers: request.headers,
|
|
23343
23428
|
query: request.query,
|
|
23344
23429
|
body: request.body
|
|
@@ -23355,6 +23440,7 @@ function attachWorkflowRunGet(runs) {
|
|
|
23355
23440
|
throw new Error("workflows runs get must be registered before block names can be attached to it");
|
|
23356
23441
|
}
|
|
23357
23442
|
const previous = held;
|
|
23443
|
+
const connectGet = callsOperations(get, ["getWorkflowRun", "getWorkflowState"]);
|
|
23358
23444
|
get.action(async (runId, _options, command) => {
|
|
23359
23445
|
const raw = command.optsWithGlobals().selectOutput;
|
|
23360
23446
|
if (raw === undefined) {
|
|
@@ -23367,7 +23453,7 @@ function attachWorkflowRunGet(runs) {
|
|
|
23367
23453
|
await previous(command.processedArgs);
|
|
23368
23454
|
return;
|
|
23369
23455
|
}
|
|
23370
|
-
await readRunByName(runId, typed, command);
|
|
23456
|
+
await readRunByName(runId, typed, command, connectGet());
|
|
23371
23457
|
});
|
|
23372
23458
|
}
|
|
23373
23459
|
|
|
@@ -23449,18 +23535,18 @@ function runSpec() {
|
|
|
23449
23535
|
return CLI_CONTRACT.getWorkflowRun ?? {};
|
|
23450
23536
|
}
|
|
23451
23537
|
function attachWorkflowRunWait(runs) {
|
|
23452
|
-
|
|
23538
|
+
const [wait, connectWait] = apiCommand(runs, "wait", ["getWorkflowRun"]);
|
|
23539
|
+
wait.argument("<runId>", V2_OPERATIONS.getWorkflowRun.pathParamDocs?.runId).allowExcessArguments(false).description("Wait for a run to reach a terminal state, then show it").addOption(new Option("--workflow <workflowId>", "Workflow ID (required)").makeOptionMandatory()).addOption(new Option(WAIT_TIMEOUT_FLAG, `Give up after this many seconds, or 0 to wait indefinitely (default: ${DEFAULT_WAIT_TIMEOUT_SECONDS}). Bounds the whole wait; SIM_TIMEOUT_SECONDS bounds one request`)).action(async (runId, options) => {
|
|
23453
23540
|
const timeoutSeconds = options.waitTimeout === undefined ? DEFAULT_WAIT_TIMEOUT_SECONDS : parseWaitTimeout(options.waitTimeout);
|
|
23454
|
-
const { client, profile } =
|
|
23455
|
-
const
|
|
23456
|
-
const path = resolvePath(operation.path, { workflowId: options.workflow, runId });
|
|
23541
|
+
const { client, profile } = connectWait();
|
|
23542
|
+
const params = { workflowId: options.workflow, runId };
|
|
23457
23543
|
const startedAt = Date.now();
|
|
23458
23544
|
const deadline = timeoutSeconds === 0 ? Number.POSITIVE_INFINITY : startedAt + timeoutSeconds * 1000;
|
|
23459
23545
|
const progress = waitProgress();
|
|
23460
23546
|
let delayMs = FIRST_POLL_DELAY_MS;
|
|
23461
23547
|
try {
|
|
23462
23548
|
while (true) {
|
|
23463
|
-
const raw = await client.request(
|
|
23549
|
+
const raw = await client.request("getWorkflowRun", { params });
|
|
23464
23550
|
const snapshot = readRun(raw);
|
|
23465
23551
|
const outcome = classify(snapshot);
|
|
23466
23552
|
if (outcome) {
|
|
@@ -24812,17 +24898,16 @@ async function readSecretValue(options) {
|
|
|
24812
24898
|
return exitCli(CANCELLED_EXIT_CODE);
|
|
24813
24899
|
}
|
|
24814
24900
|
}
|
|
24815
|
-
async function setSecret(name, options,
|
|
24901
|
+
async function setSecret(name, options, connectSet, redactionSpellings) {
|
|
24816
24902
|
if (redactionSpellings.size > 1) {
|
|
24817
24903
|
throw new SimApiError("Pass either --unredacted or --no-unredacted, not both: they are one setting, and commander keeps only whichever came last.", 0);
|
|
24818
24904
|
}
|
|
24819
24905
|
const description = validateWorkspaceOnlyFlag("description", options.description, options.scope);
|
|
24820
24906
|
const unredacted = validateWorkspaceOnlyFlag("unredacted", options.unredacted, options.scope);
|
|
24821
24907
|
const value = await readSecretValue(options);
|
|
24822
|
-
const { client, profile } =
|
|
24823
|
-
const
|
|
24824
|
-
|
|
24825
|
-
method: operation.method,
|
|
24908
|
+
const { client, profile } = connectSet();
|
|
24909
|
+
const response = await client.request("setSecret", {
|
|
24910
|
+
params: { name },
|
|
24826
24911
|
body: {
|
|
24827
24912
|
workspaceId: client.requireWorkspace(),
|
|
24828
24913
|
scope: options.scope,
|
|
@@ -24838,7 +24923,8 @@ function attachSecretCommands(program) {
|
|
|
24838
24923
|
if (!secrets)
|
|
24839
24924
|
throw new Error("The generated secrets command group is missing");
|
|
24840
24925
|
const redactionSpellings = new Set;
|
|
24841
|
-
|
|
24926
|
+
const [set, connectSet] = apiCommand(secrets, "set", ["setSecret"]);
|
|
24927
|
+
set.argument("<name>", "Secret name, as referenced in workflows").description(describeOperation(V2_OPERATIONS.setSecret, "Create or replace a named secret, such as an API key or environment variable")).addOption(new Option("--scope <scope>", "Secret ownership scope (required)").choices([...SECRET_SCOPES]).makeOptionMandatory()).option("--value <value|@file>", "Secret value. Passing it inline exposes it to shell history and process listings; @path reads it from a file and @- from stdin, verbatim — a trailing newline is part of the value, so write the file with printf rather than echo. Prefix a literal leading @ with a second one").option("--description <description>", "What the secret is for, shown to teammates; workspace scope only. Omit to leave an existing description unchanged").option("--unredacted", `${V2_OPERATIONS.setSecret.body.unredacted.describe} Pass --no-unredacted to restore redaction`).option("--no-unredacted", "Send --unredacted as false").on("option:unredacted", () => redactionSpellings.add("--unredacted")).on("option:no-unredacted", () => redactionSpellings.add("--no-unredacted")).action((name, options) => setSecret(name, options, connectSet, redactionSpellings));
|
|
24842
24928
|
}
|
|
24843
24929
|
|
|
24844
24930
|
// src/telemetry/transport.ts
|
|
@@ -24899,13 +24985,6 @@ var FIRST_RUN_NOTICE = [
|
|
|
24899
24985
|
""
|
|
24900
24986
|
].join(`
|
|
24901
24987
|
`);
|
|
24902
|
-
function commandPath2(command) {
|
|
24903
|
-
const names = [];
|
|
24904
|
-
for (let current = command;current?.parent; current = current.parent) {
|
|
24905
|
-
names.unshift(current.name());
|
|
24906
|
-
}
|
|
24907
|
-
return names;
|
|
24908
|
-
}
|
|
24909
24988
|
function typedFlags(command) {
|
|
24910
24989
|
const flags = new Set;
|
|
24911
24990
|
for (let current = command;current; current = current.parent) {
|
|
@@ -25014,7 +25093,7 @@ function createCommandTelemetry(options = {}) {
|
|
|
25014
25093
|
return {
|
|
25015
25094
|
observe(program) {
|
|
25016
25095
|
program.hook("preAction", (_root, action) => {
|
|
25017
|
-
const path =
|
|
25096
|
+
const path = commandPath(action);
|
|
25018
25097
|
if (path[0] === EXCLUDED_ROOT_COMMAND || !isReportable({}))
|
|
25019
25098
|
return;
|
|
25020
25099
|
const state = loadTelemetryState();
|
|
@@ -25303,7 +25382,7 @@ function explainFailure(error, program) {
|
|
|
25303
25382
|
if (error instanceof SimApiError) {
|
|
25304
25383
|
let output = program.opts().output;
|
|
25305
25384
|
try {
|
|
25306
|
-
output =
|
|
25385
|
+
output = profileFrom(program).output;
|
|
25307
25386
|
} catch {}
|
|
25308
25387
|
if (output === "json" || output === "yaml") {
|
|
25309
25388
|
const payload = {
|