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/index.js
CHANGED
|
@@ -7615,6 +7615,8 @@ import { dirname as dirname3 } from "node:path";
|
|
|
7615
7615
|
function truncate(str, sliceLength, suffix = "...") {
|
|
7616
7616
|
return str.length > sliceLength ? str.slice(0, sliceLength) + suffix : str;
|
|
7617
7617
|
}
|
|
7618
|
+
var UNPAIRED_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
7619
|
+
var JSONB_UNSAFE = new RegExp(`${UNPAIRED_SURROGATE.source}|\\u0000`, "g");
|
|
7618
7620
|
var MARKDOWN_ESCAPABLE = new Set("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");
|
|
7619
7621
|
function stripTrailingSlashes(value) {
|
|
7620
7622
|
let end = value.length;
|
|
@@ -17328,16 +17330,106 @@ var V2_OPERATIONS = {
|
|
|
17328
17330
|
}
|
|
17329
17331
|
};
|
|
17330
17332
|
|
|
17333
|
+
// src/runtime/derive.ts
|
|
17334
|
+
var ACTION_SEGMENTS = new Set([
|
|
17335
|
+
"upsert",
|
|
17336
|
+
"query",
|
|
17337
|
+
"search",
|
|
17338
|
+
"export",
|
|
17339
|
+
"import",
|
|
17340
|
+
"deploy",
|
|
17341
|
+
"rollback"
|
|
17342
|
+
]);
|
|
17343
|
+
function deriveCommandPath(operation) {
|
|
17344
|
+
const spec = V2_OPERATIONS[operation];
|
|
17345
|
+
const segments = spec.path.replace("/api/v2/", "").split("/");
|
|
17346
|
+
const resource = segments[0];
|
|
17347
|
+
const nouns = segments.slice(1).filter((segment) => !segment.startsWith("["));
|
|
17348
|
+
const last = nouns[nouns.length - 1];
|
|
17349
|
+
if (last && ACTION_SEGMENTS.has(last))
|
|
17350
|
+
return [resource, last];
|
|
17351
|
+
const isItem = spec.path.endsWith("]");
|
|
17352
|
+
const verb = spec.method === "GET" ? isItem ? "get" : "list" : spec.method === "POST" ? "create" : spec.method === "DELETE" ? "delete" : "update";
|
|
17353
|
+
return last ? [resource, last, verb] : [resource, verb];
|
|
17354
|
+
}
|
|
17355
|
+
function kebab(value) {
|
|
17356
|
+
return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);
|
|
17357
|
+
}
|
|
17358
|
+
function camel(flag) {
|
|
17359
|
+
return flag.replace(/-([a-z])/g, (_match, character) => character.toUpperCase());
|
|
17360
|
+
}
|
|
17361
|
+
function commandPath(command) {
|
|
17362
|
+
const names = [];
|
|
17363
|
+
for (let current = command;current?.parent; current = current.parent) {
|
|
17364
|
+
names.unshift(current.name());
|
|
17365
|
+
}
|
|
17366
|
+
return names;
|
|
17367
|
+
}
|
|
17368
|
+
|
|
17331
17369
|
// src/runtime/called-operations.ts
|
|
17332
17370
|
var CALLED_OPERATIONS = new WeakMap;
|
|
17333
17371
|
var RUNS_OPERATION = new WeakMap;
|
|
17334
|
-
|
|
17335
|
-
|
|
17336
|
-
|
|
17372
|
+
class OperationClient {
|
|
17373
|
+
client;
|
|
17374
|
+
operations;
|
|
17375
|
+
caller;
|
|
17376
|
+
constructor(client, operations, caller) {
|
|
17377
|
+
this.client = client;
|
|
17378
|
+
this.operations = operations;
|
|
17379
|
+
this.caller = caller;
|
|
17380
|
+
}
|
|
17381
|
+
requireWorkspace(explicit, options) {
|
|
17382
|
+
return this.client.requireWorkspace(explicit, options);
|
|
17383
|
+
}
|
|
17384
|
+
async request(operation, { params, ...options } = {}) {
|
|
17385
|
+
return this.client.request(this.route(operation, params), {
|
|
17386
|
+
...options,
|
|
17387
|
+
method: V2_OPERATIONS[operation].method
|
|
17388
|
+
});
|
|
17389
|
+
}
|
|
17390
|
+
async requestRaw(operation, { params, ...options } = {}) {
|
|
17391
|
+
return this.client.requestRaw(this.route(operation, params), {
|
|
17392
|
+
...options,
|
|
17393
|
+
method: V2_OPERATIONS[operation].method
|
|
17394
|
+
});
|
|
17395
|
+
}
|
|
17396
|
+
async requestAllPages(operation, { params, ...options }) {
|
|
17397
|
+
return requestAllPages(this.client, this.route(operation, params), {
|
|
17398
|
+
...options,
|
|
17399
|
+
method: V2_OPERATIONS[operation].method
|
|
17400
|
+
});
|
|
17401
|
+
}
|
|
17402
|
+
over(client) {
|
|
17403
|
+
return new OperationClient(client, this.operations, this.caller);
|
|
17404
|
+
}
|
|
17405
|
+
route(operation, params) {
|
|
17406
|
+
if (!this.operations.has(operation)) {
|
|
17407
|
+
throw new Error(`"${this.caller}" calls ${operation}, which it does not declare`);
|
|
17408
|
+
}
|
|
17409
|
+
return resolvePath(V2_OPERATIONS[operation].path, params);
|
|
17410
|
+
}
|
|
17411
|
+
}
|
|
17412
|
+
function caller(command) {
|
|
17413
|
+
return `sim ${commandPath(command).join(" ")}`;
|
|
17414
|
+
}
|
|
17415
|
+
function connect(command, expects = []) {
|
|
17416
|
+
const operations = new Set(CALLED_OPERATIONS.get(command));
|
|
17417
|
+
const missing = operations.size === 0 ? "what it calls" : expects.find((o) => !operations.has(o));
|
|
17418
|
+
if (missing) {
|
|
17419
|
+
throw new Error(`"${caller(command)}" calls the API without declaring ${missing}`);
|
|
17420
|
+
}
|
|
17421
|
+
const { client, profile } = clientFrom(command);
|
|
17422
|
+
return { client: new OperationClient(client, operations, caller(command)), profile };
|
|
17337
17423
|
}
|
|
17338
|
-
function callsOperations(command, operations) {
|
|
17424
|
+
function callsOperations(command, operations, { runs } = {}) {
|
|
17339
17425
|
CALLED_OPERATIONS.set(command, operations);
|
|
17340
|
-
|
|
17426
|
+
if (runs)
|
|
17427
|
+
RUNS_OPERATION.set(command, runs);
|
|
17428
|
+
return () => connect(command, operations);
|
|
17429
|
+
}
|
|
17430
|
+
function apiCommand(parent, name, operations, declaration = {}) {
|
|
17431
|
+
const command = parent.command(name);
|
|
17432
|
+
return [command, callsOperations(command, operations, declaration)];
|
|
17341
17433
|
}
|
|
17342
17434
|
|
|
17343
17435
|
// src/commands/auth.ts
|
|
@@ -17437,17 +17529,16 @@ function requireStoredAuthentication(profile) {
|
|
|
17437
17529
|
return authProfile;
|
|
17438
17530
|
}
|
|
17439
17531
|
async function getWorkspaceById(client, workspaceId) {
|
|
17440
|
-
const
|
|
17441
|
-
|
|
17532
|
+
const response = await client.request("getWorkspace", {
|
|
17533
|
+
params: { workspaceId }
|
|
17534
|
+
});
|
|
17442
17535
|
return response.data;
|
|
17443
17536
|
}
|
|
17444
17537
|
async function chooseWorkspace(client) {
|
|
17445
17538
|
if (!process.stdin.isTTY) {
|
|
17446
17539
|
throw new SimApiError("No workspace provided. Pass --workspace <id> when creating a profile non-interactively.", 0);
|
|
17447
17540
|
}
|
|
17448
|
-
const
|
|
17449
|
-
const workspaces = await requestAllPages(client, operation.path, {
|
|
17450
|
-
method: operation.method,
|
|
17541
|
+
const workspaces = await client.requestAllPages("listWorkspaces", {
|
|
17451
17542
|
query: { sortBy: "name", sortOrder: "asc" },
|
|
17452
17543
|
pageSize: 100,
|
|
17453
17544
|
limit: MAX_INTERACTIVE_WORKSPACES + 1
|
|
@@ -17476,9 +17567,11 @@ Available workspaces:`);
|
|
|
17476
17567
|
}
|
|
17477
17568
|
}
|
|
17478
17569
|
function addProfileCommand() {
|
|
17479
|
-
|
|
17570
|
+
const add = new Command("add");
|
|
17571
|
+
const connectAdd = callsOperations(add, ["getWorkspace", "listWorkspaces"]);
|
|
17572
|
+
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) => {
|
|
17480
17573
|
validateNewProfileName(profileName);
|
|
17481
|
-
const { client, profile } =
|
|
17574
|
+
const { client, profile } = connectAdd();
|
|
17482
17575
|
const authProfile = requireStoredAuthentication(profile);
|
|
17483
17576
|
const credential = readStoredCredential(authProfile);
|
|
17484
17577
|
const workspaceId = globalsOf(command).workspace;
|
|
@@ -17786,11 +17879,8 @@ async function verifyProfile(client, profile) {
|
|
|
17786
17879
|
}
|
|
17787
17880
|
let keyType = null;
|
|
17788
17881
|
let authenticated = null;
|
|
17789
|
-
const metaOperation = V2_OPERATIONS.getMeta;
|
|
17790
17882
|
try {
|
|
17791
|
-
const response = await client.request(
|
|
17792
|
-
method: metaOperation.method
|
|
17793
|
-
});
|
|
17883
|
+
const response = await client.request("getMeta");
|
|
17794
17884
|
const reportedKeyType = toRecord(toRecord(response).data).keyType;
|
|
17795
17885
|
if (reportedKeyType === "personal" || reportedKeyType === "workspace" || reportedKeyType === "oauth_access_token") {
|
|
17796
17886
|
keyType = reportedKeyType;
|
|
@@ -17818,9 +17908,10 @@ async function verifyProfile(client, profile) {
|
|
|
17818
17908
|
detail: `no workspace to check against — run: sim configure --profile ${safeOneLine(profile.name)} --set-workspace <id>`
|
|
17819
17909
|
};
|
|
17820
17910
|
}
|
|
17821
|
-
const operation = V2_OPERATIONS.getWorkspace;
|
|
17822
17911
|
try {
|
|
17823
|
-
const response = await client.request(
|
|
17912
|
+
const response = await client.request("getWorkspace", {
|
|
17913
|
+
params: { workspaceId: profile.workspaceId }
|
|
17914
|
+
});
|
|
17824
17915
|
const { id, name, memberCount } = response.data;
|
|
17825
17916
|
return {
|
|
17826
17917
|
status: "verified",
|
|
@@ -17860,8 +17951,10 @@ function presentVerification(verification) {
|
|
|
17860
17951
|
}
|
|
17861
17952
|
}
|
|
17862
17953
|
function whoamiCommand() {
|
|
17863
|
-
const whoami = new Command("whoami")
|
|
17864
|
-
|
|
17954
|
+
const whoami = new Command("whoami");
|
|
17955
|
+
const connectWhoami = callsOperations(whoami, ["getMeta", "getWorkspace"]);
|
|
17956
|
+
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) => {
|
|
17957
|
+
const { client, profile } = connectWhoami();
|
|
17865
17958
|
const { sources } = profile;
|
|
17866
17959
|
const authentication = presentAuthentication(sources.credential);
|
|
17867
17960
|
const verification = options.verify ? await verifyProfile(client, profile) : {
|
|
@@ -17909,7 +18002,6 @@ function whoamiCommand() {
|
|
|
17909
18002
|
if (exitCode !== 0)
|
|
17910
18003
|
setSoftExitCode(exitCode);
|
|
17911
18004
|
});
|
|
17912
|
-
return callsOperations(whoami, ["getMeta", "getWorkspace"]);
|
|
17913
18005
|
}
|
|
17914
18006
|
var PROFILE_COLUMNS = [
|
|
17915
18007
|
{ header: "", value: (row) => row.active ? styles3().green("*") : " " },
|
|
@@ -19771,35 +19863,6 @@ var CLI_CONTRACT = {
|
|
|
19771
19863
|
getFileUpload: { hidden: true }
|
|
19772
19864
|
};
|
|
19773
19865
|
|
|
19774
|
-
// src/runtime/derive.ts
|
|
19775
|
-
var ACTION_SEGMENTS = new Set([
|
|
19776
|
-
"upsert",
|
|
19777
|
-
"query",
|
|
19778
|
-
"search",
|
|
19779
|
-
"export",
|
|
19780
|
-
"import",
|
|
19781
|
-
"deploy",
|
|
19782
|
-
"rollback"
|
|
19783
|
-
]);
|
|
19784
|
-
function deriveCommandPath(operation) {
|
|
19785
|
-
const spec = V2_OPERATIONS[operation];
|
|
19786
|
-
const segments = spec.path.replace("/api/v2/", "").split("/");
|
|
19787
|
-
const resource = segments[0];
|
|
19788
|
-
const nouns = segments.slice(1).filter((segment) => !segment.startsWith("["));
|
|
19789
|
-
const last = nouns[nouns.length - 1];
|
|
19790
|
-
if (last && ACTION_SEGMENTS.has(last))
|
|
19791
|
-
return [resource, last];
|
|
19792
|
-
const isItem = spec.path.endsWith("]");
|
|
19793
|
-
const verb = spec.method === "GET" ? isItem ? "get" : "list" : spec.method === "POST" ? "create" : spec.method === "DELETE" ? "delete" : "update";
|
|
19794
|
-
return last ? [resource, last, verb] : [resource, verb];
|
|
19795
|
-
}
|
|
19796
|
-
function kebab(value) {
|
|
19797
|
-
return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);
|
|
19798
|
-
}
|
|
19799
|
-
function camel(flag) {
|
|
19800
|
-
return flag.replace(/-([a-z])/g, (_match, character) => character.toUpperCase());
|
|
19801
|
-
}
|
|
19802
|
-
|
|
19803
19866
|
// src/output/truncation.ts
|
|
19804
19867
|
var TRUNCATION_FLAG = /^truncated$|^[A-Za-z0-9]+Truncated$/;
|
|
19805
19868
|
var NEGATED_TRUNCATION_FLAG = /^(?:not|un|non|never)Truncated$|(?:Not|Un|Non|Never)Truncated$/;
|
|
@@ -20201,7 +20264,6 @@ function assertWorkspaceOperationOutcome(report, timedOut = false) {
|
|
|
20201
20264
|
}
|
|
20202
20265
|
async function waitWorkspaceOperation(client, workspaceId, operationId, timeoutSeconds, initial) {
|
|
20203
20266
|
const deadline = timeoutSeconds === 0 ? Number.POSITIVE_INFINITY : Date.now() + timeoutSeconds * 1000;
|
|
20204
|
-
const path = resolvePath(V2_OPERATIONS.getWorkspaceOperation.path, { workspaceId, operationId });
|
|
20205
20267
|
let report = initial;
|
|
20206
20268
|
let delay = 1000;
|
|
20207
20269
|
for (;; ) {
|
|
@@ -20216,7 +20278,8 @@ async function waitWorkspaceOperation(client, workspaceId, operationId, timeoutS
|
|
|
20216
20278
|
throw new SimApiError("Waiting timed out before a status response; reconcile using the same operation ID", 0, "OPERATION_WAIT_TIMEOUT", { workspaceId, operationId }, 4);
|
|
20217
20279
|
}
|
|
20218
20280
|
try {
|
|
20219
|
-
const nextReport = readWorkspaceOperation(await client.request(
|
|
20281
|
+
const nextReport = readWorkspaceOperation(await client.request("getWorkspaceOperation", {
|
|
20282
|
+
params: { workspaceId, operationId },
|
|
20220
20283
|
signal: Number.isFinite(remaining) ? AbortSignal.timeout(Math.max(1, Math.ceil(remaining))) : undefined
|
|
20221
20284
|
}));
|
|
20222
20285
|
if (nextReport.workspaceId !== workspaceId || nextReport.operationId !== operationId)
|
|
@@ -20244,9 +20307,10 @@ async function waitWorkspaceOperation(client, workspaceId, operationId, timeoutS
|
|
|
20244
20307
|
}
|
|
20245
20308
|
}
|
|
20246
20309
|
function attachWorkspaceOperationWait(operations) {
|
|
20247
|
-
|
|
20310
|
+
const [wait, connectWait] = apiCommand(operations, "wait", ["getWorkspaceOperation"]);
|
|
20311
|
+
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) => {
|
|
20248
20312
|
const timeout = workspaceWaitTimeout(options.waitTimeout);
|
|
20249
|
-
const { client, profile } =
|
|
20313
|
+
const { client, profile } = connectWait();
|
|
20250
20314
|
const workspaceId = client.requireWorkspace();
|
|
20251
20315
|
const result = await waitWorkspaceOperation(client, workspaceId, operationId, timeout);
|
|
20252
20316
|
renderResult("getWorkspaceOperation", profile.output, result.report, CLI_CONTRACT.getWorkspaceOperation ?? {});
|
|
@@ -20594,7 +20658,7 @@ function boundedRequest(request) {
|
|
|
20594
20658
|
async function buildRequest(operation, positional, flags, workspaceId) {
|
|
20595
20659
|
const commandSpec = CLI_CONTRACT[operation] ?? {};
|
|
20596
20660
|
const spec = V2_OPERATIONS[operation];
|
|
20597
|
-
|
|
20661
|
+
const params = {};
|
|
20598
20662
|
let positionalIndex = 0;
|
|
20599
20663
|
for (const param of spec.pathParams) {
|
|
20600
20664
|
const pathFlag = commandSpec.pathFlags?.[param];
|
|
@@ -20611,7 +20675,7 @@ async function buildRequest(operation, positional, flags, workspaceId) {
|
|
|
20611
20675
|
if (typeof value !== "string" || value.length === 0) {
|
|
20612
20676
|
throw new SimApiError(pathFlag ? `--${flagName} cannot be empty` : `<${argumentName}> cannot be empty`, 0);
|
|
20613
20677
|
}
|
|
20614
|
-
|
|
20678
|
+
params[param] = value;
|
|
20615
20679
|
}
|
|
20616
20680
|
const query = {};
|
|
20617
20681
|
const body = {};
|
|
@@ -20684,7 +20748,7 @@ async function buildRequest(operation, positional, flags, workspaceId) {
|
|
|
20684
20748
|
throw new SimApiError(`--${variant.name} must be a JSON ${variant.kind}`, 0);
|
|
20685
20749
|
}
|
|
20686
20750
|
return boundedRequest({
|
|
20687
|
-
|
|
20751
|
+
params,
|
|
20688
20752
|
query,
|
|
20689
20753
|
body: { ...body, [variant.property]: parsed },
|
|
20690
20754
|
...headerSlot
|
|
@@ -20698,14 +20762,14 @@ async function buildRequest(operation, positional, flags, workspaceId) {
|
|
|
20698
20762
|
throw new SimApiError("--body must be a JSON object", 0);
|
|
20699
20763
|
}
|
|
20700
20764
|
return boundedRequest({
|
|
20701
|
-
|
|
20765
|
+
params,
|
|
20702
20766
|
query,
|
|
20703
20767
|
body: { ...body, ...parsed },
|
|
20704
20768
|
...headerSlot
|
|
20705
20769
|
});
|
|
20706
20770
|
}
|
|
20707
20771
|
return boundedRequest({
|
|
20708
|
-
|
|
20772
|
+
params,
|
|
20709
20773
|
query,
|
|
20710
20774
|
body: spec.body ? body : undefined,
|
|
20711
20775
|
...headerSlot
|
|
@@ -21081,7 +21145,7 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
21081
21145
|
if (commandSpec.allWorkspaces && requestFlags.allWorkspaces && requestFlags.workspace) {
|
|
21082
21146
|
throw new SimApiError("--all-workspaces cannot be combined with --workspace", 0);
|
|
21083
21147
|
}
|
|
21084
|
-
const { client, profile } =
|
|
21148
|
+
const { client, profile } = connect(host);
|
|
21085
21149
|
const hasWorkspaceField = Boolean(operationSpec.query && PROFILE_INJECTED_FIELD in operationSpec.query || operationSpec.body && PROFILE_INJECTED_FIELD in operationSpec.body);
|
|
21086
21150
|
const omitsWorkspace = commandSpec.allWorkspaces && requestFlags.allWorkspaces === true;
|
|
21087
21151
|
const needsWorkspace = (hasWorkspaceField || commandSpec.profileWorkspacePath === true) && !omitsWorkspace;
|
|
@@ -21115,8 +21179,8 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
21115
21179
|
do {
|
|
21116
21180
|
const pageSize = Math.min(DEFAULT_PAGE_SIZE, limit - rows.length);
|
|
21117
21181
|
const pageLimit = "limit" in (operationSpec[paging] ?? {}) ? { limit: pageSize } : {};
|
|
21118
|
-
const page = await client.request(
|
|
21119
|
-
|
|
21182
|
+
const page = await client.request(operation, {
|
|
21183
|
+
params: request.params,
|
|
21120
21184
|
headers: request.headers,
|
|
21121
21185
|
query: paging === "query" ? { ...request.query, ...pageLimit, cursor } : request.query,
|
|
21122
21186
|
body: paging === "body" ? { ...request.body ?? {}, ...pageLimit, ...cursor ? { cursor } : {} } : request.body
|
|
@@ -21139,8 +21203,8 @@ async function executeOperation(operation, commandSpec, operationSpec, invocatio
|
|
|
21139
21203
|
}
|
|
21140
21204
|
let result;
|
|
21141
21205
|
try {
|
|
21142
|
-
result = await client.request(
|
|
21143
|
-
|
|
21206
|
+
result = await client.request(operation, {
|
|
21207
|
+
params: request.params,
|
|
21144
21208
|
headers: request.headers,
|
|
21145
21209
|
query: request.query,
|
|
21146
21210
|
body: request.body
|
|
@@ -21295,7 +21359,7 @@ function argumentSyntax(command) {
|
|
|
21295
21359
|
return argument.required ? `<${name}>` : `[${name}]`;
|
|
21296
21360
|
}).join(" ");
|
|
21297
21361
|
}
|
|
21298
|
-
function
|
|
21362
|
+
function commandPath2(command) {
|
|
21299
21363
|
const names = [];
|
|
21300
21364
|
let current = command;
|
|
21301
21365
|
while (current) {
|
|
@@ -21317,7 +21381,7 @@ function addParseErrorGuidance(command) {
|
|
|
21317
21381
|
outputError(message, write);
|
|
21318
21382
|
if (message.startsWith("error: missing required argument ")) {
|
|
21319
21383
|
const syntax = argumentSyntax(command);
|
|
21320
|
-
const example = syntax ? `${
|
|
21384
|
+
const example = syntax ? `${commandPath2(command)} ${syntax}` : commandPath2(command);
|
|
21321
21385
|
write(`Example: ${example}
|
|
21322
21386
|
`);
|
|
21323
21387
|
return;
|
|
@@ -21326,13 +21390,13 @@ function addParseErrorGuidance(command) {
|
|
|
21326
21390
|
if (!token)
|
|
21327
21391
|
return;
|
|
21328
21392
|
if (looksLikeAnId(token) && command.registeredArguments.length > 0) {
|
|
21329
|
-
write(`Example: ${
|
|
21393
|
+
write(`Example: ${commandPath2(command)} -- ${token}
|
|
21330
21394
|
`);
|
|
21331
21395
|
return;
|
|
21332
21396
|
}
|
|
21333
21397
|
const flags = command.options.filter((option) => !option.hidden).map((option) => option.flags);
|
|
21334
|
-
write(flags.length > 0 ? `Options for ${
|
|
21335
|
-
` : `${
|
|
21398
|
+
write(flags.length > 0 ? `Options for ${commandPath2(command)}: ${flags.join(", ")}
|
|
21399
|
+
` : `${commandPath2(command)} takes no options.
|
|
21336
21400
|
`);
|
|
21337
21401
|
}
|
|
21338
21402
|
});
|
|
@@ -21392,7 +21456,7 @@ function refuseHelpAfterUnknownCommand(program) {
|
|
|
21392
21456
|
}
|
|
21393
21457
|
function configureOperation(command, operation, spec) {
|
|
21394
21458
|
const operationSpec = V2_OPERATIONS[operation];
|
|
21395
|
-
|
|
21459
|
+
callsOperations(command, spec.workspaceOperation ? [operation, "getWorkspaceOperation"] : [operation], { runs: operation });
|
|
21396
21460
|
command.allowExcessArguments(false);
|
|
21397
21461
|
for (const alias of spec.aliases ?? [])
|
|
21398
21462
|
command.alias(alias);
|
|
@@ -21619,12 +21683,9 @@ async function credentialValues(provider, raw) {
|
|
|
21619
21683
|
}
|
|
21620
21684
|
return values;
|
|
21621
21685
|
}
|
|
21622
|
-
async function createServiceAccount(
|
|
21623
|
-
const { client, profile } = clientFrom(command);
|
|
21686
|
+
async function createServiceAccount({ client, profile }, providerId, options) {
|
|
21624
21687
|
const workspaceId = client.requireWorkspace();
|
|
21625
|
-
const
|
|
21626
|
-
const catalog = await client.request(discovery.path, {
|
|
21627
|
-
method: discovery.method,
|
|
21688
|
+
const catalog = await client.request("listCredentialProviders", {
|
|
21628
21689
|
query: { workspaceId }
|
|
21629
21690
|
});
|
|
21630
21691
|
const provider = serviceAccountProvider(catalog.data, providerId);
|
|
@@ -21632,9 +21693,7 @@ async function createServiceAccount(command, providerId, options) {
|
|
|
21632
21693
|
throw new SimApiError(`--id is required for ${providerId}.`, 0);
|
|
21633
21694
|
}
|
|
21634
21695
|
const credentialFields = await credentialValues(provider, options.credentials);
|
|
21635
|
-
const
|
|
21636
|
-
const response = await client.request(operation.path, {
|
|
21637
|
-
method: operation.method,
|
|
21696
|
+
const response = await client.request("createServiceAccountCredential", {
|
|
21638
21697
|
body: {
|
|
21639
21698
|
workspaceId,
|
|
21640
21699
|
type: "service_account",
|
|
@@ -21647,11 +21706,8 @@ async function createServiceAccount(command, providerId, options) {
|
|
|
21647
21706
|
});
|
|
21648
21707
|
renderResult("createServiceAccountCredential", profile.output, response.data, SERVICE_ACCOUNT_RESULT);
|
|
21649
21708
|
}
|
|
21650
|
-
async function createConnectionLink(
|
|
21651
|
-
const
|
|
21652
|
-
const operation = V2_OPERATIONS.createCredentialConnection;
|
|
21653
|
-
const response = await client.request(operation.path, {
|
|
21654
|
-
method: operation.method,
|
|
21709
|
+
async function createConnectionLink({ client, profile }, body) {
|
|
21710
|
+
const response = await client.request("createCredentialConnection", {
|
|
21655
21711
|
body: {
|
|
21656
21712
|
workspaceId: client.requireWorkspace(),
|
|
21657
21713
|
...body
|
|
@@ -21678,11 +21734,14 @@ function attachCredentialCommands(program) {
|
|
|
21678
21734
|
if (!credentials)
|
|
21679
21735
|
throw new Error("The generated credentials command group is missing");
|
|
21680
21736
|
acceptNameOnUpdate(credentials);
|
|
21681
|
-
const create = credentials
|
|
21682
|
-
|
|
21683
|
-
|
|
21684
|
-
|
|
21685
|
-
|
|
21737
|
+
const [create, connectCreate] = apiCommand(credentials, "create", ["listCredentialProviders", "createServiceAccountCredential"], { runs: "createServiceAccountCredential" });
|
|
21738
|
+
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));
|
|
21739
|
+
const [connect, connectLink] = apiCommand(credentials, "connect", ["createCredentialConnection"]);
|
|
21740
|
+
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 }));
|
|
21741
|
+
const [reconnect, reconnectLink] = apiCommand(credentials, "reconnect", [
|
|
21742
|
+
"createCredentialConnection"
|
|
21743
|
+
]);
|
|
21744
|
+
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 }));
|
|
21686
21745
|
}
|
|
21687
21746
|
|
|
21688
21747
|
// src/http/ndjson.ts
|
|
@@ -21768,7 +21827,8 @@ function ignoreBrokenPipe(stream) {
|
|
|
21768
21827
|
};
|
|
21769
21828
|
}
|
|
21770
21829
|
function attachChat(program) {
|
|
21771
|
-
const chat = program
|
|
21830
|
+
const [chat, connectChat] = apiCommand(program, "chat", ["chat"]);
|
|
21831
|
+
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", `
|
|
21772
21832
|
Each turn prints the reply on stdout and the conversation ID on stderr; pass
|
|
21773
21833
|
that ID back with -c to continue the same conversation. With --output json or
|
|
21774
21834
|
yaml the reply is not streamed — the finished result is printed as one
|
|
@@ -21778,17 +21838,16 @@ Examples:
|
|
|
21778
21838
|
$ sim chat "What workflows do I have?"
|
|
21779
21839
|
$ sim chat -c 3f2a… "Which of those run on a schedule?"
|
|
21780
21840
|
$ sim --output json chat "Summarize yesterday's failed runs" | jq -r '.content'
|
|
21781
|
-
`).action(async (message, options
|
|
21841
|
+
`).action(async (message, options) => {
|
|
21782
21842
|
if (message.trim() === "") {
|
|
21783
21843
|
throw new SimApiError("<message> cannot be empty", 0);
|
|
21784
21844
|
}
|
|
21785
21845
|
if (options.conversation !== undefined && options.conversation.trim() === "") {
|
|
21786
21846
|
throw new SimApiError("-c/--conversation cannot be empty — pass the conversation id printed on stderr after each turn", 0);
|
|
21787
21847
|
}
|
|
21788
|
-
const { client, profile } =
|
|
21848
|
+
const { client, profile } = connectChat();
|
|
21789
21849
|
const workspaceId = client.requireWorkspace();
|
|
21790
|
-
const response = await client.requestRaw(
|
|
21791
|
-
method: "POST",
|
|
21850
|
+
const response = await client.requestRaw("chat", {
|
|
21792
21851
|
body: {
|
|
21793
21852
|
workspaceId,
|
|
21794
21853
|
message,
|
|
@@ -21834,7 +21893,6 @@ Examples:
|
|
|
21834
21893
|
restorePipeHandling?.();
|
|
21835
21894
|
}
|
|
21836
21895
|
});
|
|
21837
|
-
callsOperations(chat, ["chat"]);
|
|
21838
21896
|
}
|
|
21839
21897
|
|
|
21840
21898
|
// src/commands/protocol/files-get.ts
|
|
@@ -22015,16 +22073,16 @@ function isTerminalSafeContentType(contentType) {
|
|
|
22015
22073
|
"image/svg+xml"
|
|
22016
22074
|
].includes(mediaType);
|
|
22017
22075
|
}
|
|
22018
|
-
async function downloadToOutput(
|
|
22076
|
+
async function downloadToOutput(connectDownload, operation, params, options) {
|
|
22019
22077
|
const target = options.outputFile;
|
|
22020
22078
|
const writesToStdout = target === undefined || target === "-";
|
|
22021
22079
|
if (writesToStdout && options.force) {
|
|
22022
22080
|
throw new SimApiError("--force requires --output-file <path>", 0);
|
|
22023
22081
|
}
|
|
22024
|
-
const { client, profile } =
|
|
22082
|
+
const { client, profile } = connectDownload();
|
|
22025
22083
|
const workspaceId = client.requireWorkspace();
|
|
22026
|
-
const response = await client.requestRaw(
|
|
22027
|
-
|
|
22084
|
+
const response = await client.requestRaw(operation, {
|
|
22085
|
+
params,
|
|
22028
22086
|
query: { workspaceId }
|
|
22029
22087
|
});
|
|
22030
22088
|
if (!response.body) {
|
|
@@ -22042,18 +22100,18 @@ async function downloadToOutput(command, operation, pathParams, options) {
|
|
|
22042
22100
|
}
|
|
22043
22101
|
const savedTarget = await saveToFile(response.body, target, Boolean(options.force));
|
|
22044
22102
|
printProtocolResult(profile.output, {
|
|
22045
|
-
id:
|
|
22103
|
+
id: params.fileId,
|
|
22046
22104
|
path: savedTarget,
|
|
22047
22105
|
status: "saved"
|
|
22048
22106
|
});
|
|
22049
22107
|
}
|
|
22050
22108
|
function attachFileGet(files) {
|
|
22051
|
-
const get
|
|
22052
|
-
|
|
22109
|
+
const [get, connectGet] = apiCommand(files, "get", ["downloadFile"]);
|
|
22110
|
+
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));
|
|
22053
22111
|
}
|
|
22054
22112
|
function attachFileVersionDownload(versions) {
|
|
22055
|
-
const download
|
|
22056
|
-
|
|
22113
|
+
const [download, connectDownload] = apiCommand(versions, "download", ["downloadFileVersion"]);
|
|
22114
|
+
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));
|
|
22057
22115
|
}
|
|
22058
22116
|
|
|
22059
22117
|
// src/transfer/upload-session.ts
|
|
@@ -22179,8 +22237,8 @@ async function uploadParts(client, workspaceId, session, transfer, file) {
|
|
|
22179
22237
|
for (let n = first;n < first + PART_URL_BATCH && n <= transfer.partCount; n++) {
|
|
22180
22238
|
partNumbers.push(n);
|
|
22181
22239
|
}
|
|
22182
|
-
const signed = await client.request(
|
|
22183
|
-
|
|
22240
|
+
const signed = await client.request(session.operations.parts, {
|
|
22241
|
+
params: session.params,
|
|
22184
22242
|
query: { workspaceId },
|
|
22185
22243
|
headers: { "upload-token": session.uploadToken },
|
|
22186
22244
|
body: { partNumbers }
|
|
@@ -22228,8 +22286,8 @@ async function finishUploadSession(client, workspaceId, session, path) {
|
|
|
22228
22286
|
await streamed?.verifyComplete();
|
|
22229
22287
|
await streamed?.close();
|
|
22230
22288
|
await snapshot?.dispose().catch(() => {});
|
|
22231
|
-
const completed = await client.request(
|
|
22232
|
-
|
|
22289
|
+
const completed = await client.request(session.operations.complete, {
|
|
22290
|
+
params: session.params,
|
|
22233
22291
|
query: { workspaceId },
|
|
22234
22292
|
headers: { "upload-token": session.uploadToken }
|
|
22235
22293
|
});
|
|
@@ -22237,9 +22295,9 @@ async function finishUploadSession(client, workspaceId, session, path) {
|
|
|
22237
22295
|
} catch (error) {
|
|
22238
22296
|
await streamed?.close();
|
|
22239
22297
|
const profile = embeddedProfile();
|
|
22240
|
-
const cleanupClient = profile ? new SimClient({ ...profile, signal: AbortSignal.timeout(5000) }) : client;
|
|
22241
|
-
await cleanupClient.request(session.
|
|
22242
|
-
|
|
22298
|
+
const cleanupClient = profile ? client.over(new SimClient({ ...profile, signal: AbortSignal.timeout(5000) })) : client;
|
|
22299
|
+
await cleanupClient.request(session.operations.abort, {
|
|
22300
|
+
params: session.params,
|
|
22243
22301
|
query: { workspaceId },
|
|
22244
22302
|
headers: { "upload-token": session.uploadToken }
|
|
22245
22303
|
}).catch(() => {
|
|
@@ -22254,12 +22312,17 @@ async function finishUploadSession(client, workspaceId, session, path) {
|
|
|
22254
22312
|
|
|
22255
22313
|
// src/commands/protocol/files-upload.ts
|
|
22256
22314
|
function attachFileUpload(files) {
|
|
22257
|
-
|
|
22258
|
-
|
|
22315
|
+
const [upload, connectUpload] = apiCommand(files, "upload", [
|
|
22316
|
+
"createFileUpload",
|
|
22317
|
+
"createFileUploadPartUrls",
|
|
22318
|
+
"completeFileUpload",
|
|
22319
|
+
"abortFileUpload"
|
|
22320
|
+
]);
|
|
22321
|
+
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) => {
|
|
22322
|
+
const { client, profile } = connectUpload();
|
|
22259
22323
|
const workspaceId = client.requireWorkspace();
|
|
22260
22324
|
const { name, size } = await localFile(path, options.name);
|
|
22261
|
-
const created = await client.request(
|
|
22262
|
-
method: "POST",
|
|
22325
|
+
const created = await client.request("createFileUpload", {
|
|
22263
22326
|
body: {
|
|
22264
22327
|
workspaceId,
|
|
22265
22328
|
name,
|
|
@@ -22270,7 +22333,12 @@ function attachFileUpload(files) {
|
|
|
22270
22333
|
});
|
|
22271
22334
|
const { session, uploadToken, transfer } = created.data;
|
|
22272
22335
|
const completed = await finishUploadSession(client, workspaceId, {
|
|
22273
|
-
|
|
22336
|
+
operations: {
|
|
22337
|
+
parts: "createFileUploadPartUrls",
|
|
22338
|
+
complete: "completeFileUpload",
|
|
22339
|
+
abort: "abortFileUpload"
|
|
22340
|
+
},
|
|
22341
|
+
params: { uploadId: session.id },
|
|
22274
22342
|
uploadToken,
|
|
22275
22343
|
transfer,
|
|
22276
22344
|
size
|
|
@@ -22307,12 +22375,18 @@ var UPLOAD_RECIPES = [
|
|
|
22307
22375
|
];
|
|
22308
22376
|
var LANGUAGE_TAG_HELP = "Document language tag: hyphen-separated letter and digit subtags, for example en or en-US";
|
|
22309
22377
|
function attachKnowledgeDocumentUpload(documents) {
|
|
22310
|
-
|
|
22311
|
-
|
|
22378
|
+
const [upload, connectUpload] = apiCommand(documents, "upload", [
|
|
22379
|
+
"createKnowledgeDocumentUpload",
|
|
22380
|
+
"createKnowledgeDocumentUploadPartUrls",
|
|
22381
|
+
"completeKnowledgeDocumentUpload",
|
|
22382
|
+
"abortKnowledgeDocumentUpload"
|
|
22383
|
+
]);
|
|
22384
|
+
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) => {
|
|
22385
|
+
const { client, profile } = connectUpload();
|
|
22312
22386
|
const workspaceId = client.requireWorkspace();
|
|
22313
22387
|
const { name, size } = await localFile(path, options.name);
|
|
22314
|
-
const created = await client.request(
|
|
22315
|
-
|
|
22388
|
+
const created = await client.request("createKnowledgeDocumentUpload", {
|
|
22389
|
+
params: { knowledgeBaseId },
|
|
22316
22390
|
body: {
|
|
22317
22391
|
workspaceId,
|
|
22318
22392
|
name,
|
|
@@ -22323,7 +22397,12 @@ function attachKnowledgeDocumentUpload(documents) {
|
|
|
22323
22397
|
});
|
|
22324
22398
|
const { session, uploadToken, transfer } = created.data;
|
|
22325
22399
|
const completed = await finishUploadSession(client, workspaceId, {
|
|
22326
|
-
|
|
22400
|
+
operations: {
|
|
22401
|
+
parts: "createKnowledgeDocumentUploadPartUrls",
|
|
22402
|
+
complete: "completeKnowledgeDocumentUpload",
|
|
22403
|
+
abort: "abortKnowledgeDocumentUpload"
|
|
22404
|
+
},
|
|
22405
|
+
params: { knowledgeBaseId, uploadId: session.id },
|
|
22327
22406
|
uploadToken,
|
|
22328
22407
|
transfer,
|
|
22329
22408
|
size
|
|
@@ -22362,16 +22441,16 @@ function safeBaseName(name) {
|
|
|
22362
22441
|
return base && base !== "." && base !== ".." ? base : null;
|
|
22363
22442
|
}
|
|
22364
22443
|
function attachKnowledgeExport(knowledge) {
|
|
22365
|
-
const exportCommand
|
|
22444
|
+
const [exportCommand, connectExport] = apiCommand(knowledge, "export", ["exportKnowledgeBase"]);
|
|
22445
|
+
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) => {
|
|
22366
22446
|
const writesToStdout = options.outputFile === "-";
|
|
22367
22447
|
if (writesToStdout && options.force) {
|
|
22368
22448
|
throw new SimApiError("--force requires --output-file <path>", 0);
|
|
22369
22449
|
}
|
|
22370
|
-
const { client, profile } =
|
|
22450
|
+
const { client, profile } = connectExport();
|
|
22371
22451
|
const workspaceId = client.requireWorkspace();
|
|
22372
|
-
const
|
|
22373
|
-
|
|
22374
|
-
method: operation.method,
|
|
22452
|
+
const response = await client.requestRaw("exportKnowledgeBase", {
|
|
22453
|
+
params: { knowledgeBaseId },
|
|
22375
22454
|
query: { workspaceId, vectors: options.vectors }
|
|
22376
22455
|
});
|
|
22377
22456
|
if (!response.body) {
|
|
@@ -22395,7 +22474,6 @@ function attachKnowledgeExport(knowledge) {
|
|
|
22395
22474
|
vectors: options.vectors
|
|
22396
22475
|
});
|
|
22397
22476
|
});
|
|
22398
|
-
callsOperations(exportCommand, ["exportKnowledgeBase"]);
|
|
22399
22477
|
}
|
|
22400
22478
|
|
|
22401
22479
|
// src/commands/protocol/logs-follow.ts
|
|
@@ -22554,12 +22632,12 @@ function remember(state, rows) {
|
|
|
22554
22632
|
excess -= 1;
|
|
22555
22633
|
}
|
|
22556
22634
|
}
|
|
22557
|
-
async function collectUnprinted(client,
|
|
22635
|
+
async function collectUnprinted(client, query, state, pageSize, maxPages) {
|
|
22558
22636
|
const rows = [];
|
|
22559
22637
|
let cursor = null;
|
|
22560
22638
|
let truncated = false;
|
|
22561
22639
|
for (let page = 0;page < maxPages; page += 1) {
|
|
22562
|
-
const response = await client.request(
|
|
22640
|
+
const response = await client.request("listLogs", {
|
|
22563
22641
|
query: { ...query, limit: pageSize, cursor }
|
|
22564
22642
|
});
|
|
22565
22643
|
const page_rows = response?.data ?? [];
|
|
@@ -22598,7 +22676,8 @@ function inSeconds(ms) {
|
|
|
22598
22676
|
return Math.round(ms / 100) / 10;
|
|
22599
22677
|
}
|
|
22600
22678
|
function attachLogsFollow(logs) {
|
|
22601
|
-
|
|
22679
|
+
const [follow, connectFollow] = apiCommand(logs, "follow", ["listLogs"]);
|
|
22680
|
+
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([
|
|
22602
22681
|
...V2_OPERATIONS.listLogs.query.level.values
|
|
22603
22682
|
])).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", `
|
|
22604
22683
|
Each run prints once, when it is first seen, so its status is the status it had
|
|
@@ -22612,11 +22691,10 @@ Examples:
|
|
|
22612
22691
|
$ sim logs follow --level error
|
|
22613
22692
|
$ sim logs follow --workflow 00000000-0000-4000-8000-000000000000 -n 0
|
|
22614
22693
|
$ sim --output json logs follow | jq -r '.runId'
|
|
22615
|
-
`).action(async (options
|
|
22694
|
+
`).action(async (options) => {
|
|
22616
22695
|
const lines = nonNegativeInteger(options.lines, "--lines");
|
|
22617
22696
|
const delay = intervalMs(options.interval);
|
|
22618
|
-
const { client, profile } =
|
|
22619
|
-
const path = V2_OPERATIONS.listLogs.path;
|
|
22697
|
+
const { client, profile } = connectFollow();
|
|
22620
22698
|
const query = {
|
|
22621
22699
|
workspaceId: client.requireWorkspace(),
|
|
22622
22700
|
workflowIds: options.workflow?.length ? options.workflow.join(",") : undefined,
|
|
@@ -22632,7 +22710,7 @@ Examples:
|
|
|
22632
22710
|
const interrupt = watchForInterrupt();
|
|
22633
22711
|
const state = { seen: new Map, floor: null };
|
|
22634
22712
|
try {
|
|
22635
|
-
const seed = await collectUnprinted(client,
|
|
22713
|
+
const seed = await collectUnprinted(client, query, state, Math.max(lines, 1), 1);
|
|
22636
22714
|
remember(state, seed.rows);
|
|
22637
22715
|
state.floor = seed.rows.at(-1)?.startedAt ?? null;
|
|
22638
22716
|
if (seed.truncated && seed.rows.length < lines) {
|
|
@@ -22646,7 +22724,7 @@ Examples:
|
|
|
22646
22724
|
break;
|
|
22647
22725
|
let fresh;
|
|
22648
22726
|
try {
|
|
22649
|
-
fresh = await collectUnprinted(client,
|
|
22727
|
+
fresh = await collectUnprinted(client, query, state, POLL_PAGE_SIZE, MAX_PAGES_PER_POLL);
|
|
22650
22728
|
} catch (error) {
|
|
22651
22729
|
if (!isTransient(error))
|
|
22652
22730
|
throw error;
|
|
@@ -22683,25 +22761,21 @@ var COLUMNS2 = [
|
|
|
22683
22761
|
{ header: "folder", value: (entry) => text(decodeFolderPath(entry.folderPath)) },
|
|
22684
22762
|
{ header: "updated", value: (entry) => timestamp2(entry.updatedAt) }
|
|
22685
22763
|
];
|
|
22686
|
-
function operationPath(operation) {
|
|
22687
|
-
return V2_OPERATIONS[operation].path;
|
|
22688
|
-
}
|
|
22689
22764
|
async function listResources(client, config, workspaceId, folderPath, search, limit) {
|
|
22690
22765
|
const query = { workspaceId, folderPath, search, sortBy: "name", sortOrder: "asc" };
|
|
22691
|
-
const path = operationPath(config.resources);
|
|
22692
22766
|
const paginated = "cursor" in V2_OPERATIONS[config.resources].query;
|
|
22693
22767
|
if (!paginated) {
|
|
22694
|
-
const page = await client.request(
|
|
22768
|
+
const page = await client.request(config.resources, { query });
|
|
22695
22769
|
return page.data.slice(0, limit);
|
|
22696
22770
|
}
|
|
22697
|
-
return requestAllPages(
|
|
22771
|
+
return client.requestAllPages(config.resources, {
|
|
22698
22772
|
query,
|
|
22699
22773
|
pageSize: DEFAULT_PAGE_SIZE,
|
|
22700
22774
|
limit
|
|
22701
22775
|
});
|
|
22702
22776
|
}
|
|
22703
22777
|
async function listFolders(client, operation, workspaceId, parentPath, search) {
|
|
22704
|
-
const page = await client.request(
|
|
22778
|
+
const page = await client.request(operation, {
|
|
22705
22779
|
query: { workspaceId, parentPath, search, sortBy: "name", sortOrder: "asc" }
|
|
22706
22780
|
});
|
|
22707
22781
|
return page.data;
|
|
@@ -22726,14 +22800,15 @@ function entriesFor(config, folders, resources) {
|
|
|
22726
22800
|
].sort((left, right) => left.name.localeCompare(right.name) || left.kind.localeCompare(right.kind));
|
|
22727
22801
|
}
|
|
22728
22802
|
function attachResourceDirectoryCommands(group, config) {
|
|
22729
|
-
|
|
22803
|
+
const [ls, connectLs] = apiCommand(group, "ls", [config.resources, config.folders]);
|
|
22804
|
+
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) => {
|
|
22730
22805
|
const rawLimit = Number(options.limit);
|
|
22731
22806
|
if (!Number.isSafeInteger(rawLimit) || rawLimit < 0) {
|
|
22732
22807
|
throw new SimApiError("--limit must be a whole number of 0 or more (0 for everything)", 0);
|
|
22733
22808
|
}
|
|
22734
22809
|
const limit = rawLimit === 0 ? Number.POSITIVE_INFINITY : rawLimit;
|
|
22735
22810
|
const folderPath = encodeFolderPath(path ?? "/");
|
|
22736
|
-
const { client, profile } =
|
|
22811
|
+
const { client, profile } = connectLs();
|
|
22737
22812
|
const workspaceId = client.requireWorkspace();
|
|
22738
22813
|
const [folders, resources] = await Promise.all([
|
|
22739
22814
|
listFolders(client, config.folders, workspaceId, folderPath, options.search),
|
|
@@ -22743,11 +22818,10 @@ function attachResourceDirectoryCommands(group, config) {
|
|
|
22743
22818
|
const shown = entries.slice(0, limit);
|
|
22744
22819
|
printList(profile.output, shown, COLUMNS2);
|
|
22745
22820
|
});
|
|
22746
|
-
|
|
22747
|
-
|
|
22748
|
-
const
|
|
22749
|
-
const result = await client.request(
|
|
22750
|
-
method: operation.method,
|
|
22821
|
+
const [mkdir, connectMkdir] = apiCommand(group, "mkdir", [config.createFolder]);
|
|
22822
|
+
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) => {
|
|
22823
|
+
const { client, profile } = connectMkdir();
|
|
22824
|
+
const result = await client.request(config.createFolder, {
|
|
22751
22825
|
body: { workspaceId: client.requireWorkspace(), path: encodeFolderPath(path) }
|
|
22752
22826
|
});
|
|
22753
22827
|
renderResult(config.createFolder, profile.output, result.data ?? result, {});
|
|
@@ -22796,7 +22870,10 @@ async function watchImport(client, workspaceId, job) {
|
|
|
22796
22870
|
let reported = null;
|
|
22797
22871
|
while (!IMPORT_SETTLED.has(current.status)) {
|
|
22798
22872
|
await sleep2(IMPORT_POLL_MS);
|
|
22799
|
-
const next = await client.request(
|
|
22873
|
+
const next = await client.request("getTableImport", {
|
|
22874
|
+
params: { importId: current.id },
|
|
22875
|
+
query: { workspaceId }
|
|
22876
|
+
});
|
|
22800
22877
|
current = next.data;
|
|
22801
22878
|
const line = progressLine(current);
|
|
22802
22879
|
if (hasProgressTerminal() && line !== reported) {
|
|
@@ -22826,8 +22903,15 @@ function validateTargetOptions(options) {
|
|
|
22826
22903
|
return intoExisting;
|
|
22827
22904
|
}
|
|
22828
22905
|
function attachTableImport(tables) {
|
|
22829
|
-
|
|
22830
|
-
|
|
22906
|
+
const [importCommand, connectImport] = apiCommand(tables, "import", [
|
|
22907
|
+
"createTableImport",
|
|
22908
|
+
"createTableImportPartUrls",
|
|
22909
|
+
"completeTableImport",
|
|
22910
|
+
"cancelTableImport",
|
|
22911
|
+
"getTableImport"
|
|
22912
|
+
]);
|
|
22913
|
+
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) => {
|
|
22914
|
+
const { client, profile } = connectImport();
|
|
22831
22915
|
const workspaceId = client.requireWorkspace();
|
|
22832
22916
|
if (Boolean(path) === Boolean(options.fileId)) {
|
|
22833
22917
|
throw new SimApiError("Pass exactly one of <path> or --file-id <id>", 0);
|
|
@@ -22857,8 +22941,7 @@ function attachTableImport(tables) {
|
|
|
22857
22941
|
...options.folder !== undefined ? { folderPath: encodeFolderPath(options.folder) } : {}
|
|
22858
22942
|
};
|
|
22859
22943
|
}
|
|
22860
|
-
const started = await client.request(
|
|
22861
|
-
method: "POST",
|
|
22944
|
+
const started = await client.request("createTableImport", {
|
|
22862
22945
|
body: {
|
|
22863
22946
|
workspaceId,
|
|
22864
22947
|
source,
|
|
@@ -22873,12 +22956,18 @@ function attachTableImport(tables) {
|
|
|
22873
22956
|
if (!local || !started.data.uploadToken || !started.data.transfer) {
|
|
22874
22957
|
throw new Error("Local table import did not return an upload transfer");
|
|
22875
22958
|
}
|
|
22876
|
-
|
|
22877
|
-
|
|
22959
|
+
const completed = await finishUploadSession(client, workspaceId, {
|
|
22960
|
+
operations: {
|
|
22961
|
+
parts: "createTableImportPartUrls",
|
|
22962
|
+
complete: "completeTableImport",
|
|
22963
|
+
abort: "cancelTableImport"
|
|
22964
|
+
},
|
|
22965
|
+
params: { importId: job.id },
|
|
22878
22966
|
uploadToken: started.data.uploadToken,
|
|
22879
22967
|
transfer: started.data.transfer,
|
|
22880
22968
|
size: local.size
|
|
22881
22969
|
}, path);
|
|
22970
|
+
job = completed;
|
|
22882
22971
|
}
|
|
22883
22972
|
if (!options.wait) {
|
|
22884
22973
|
printProtocolResult(profile.output, {
|
|
@@ -22996,13 +23085,13 @@ function withEmbeddedFileReferences(body) {
|
|
|
22996
23085
|
}
|
|
22997
23086
|
async function runWithResultStream(workflowId, command) {
|
|
22998
23087
|
const flags = command.optsWithGlobals();
|
|
22999
|
-
const { client, profile } =
|
|
23088
|
+
const { client, profile } = connect(command, ["executeWorkflow"]);
|
|
23000
23089
|
const operation = V2_OPERATIONS.executeWorkflow;
|
|
23001
23090
|
const commandSpec = CLI_CONTRACT.executeWorkflow ?? {};
|
|
23002
23091
|
try {
|
|
23003
23092
|
const request = await buildRequest("executeWorkflow", [workflowId], flags, profile.workspaceId);
|
|
23004
|
-
const response = await client.requestRaw(
|
|
23005
|
-
|
|
23093
|
+
const response = await client.requestRaw("executeWorkflow", {
|
|
23094
|
+
params: request.params,
|
|
23006
23095
|
query: request.query,
|
|
23007
23096
|
body: withEmbeddedFileReferences(request.body),
|
|
23008
23097
|
headers: { ...request.headers, accept: WORKFLOW_RESULT_STREAM_CONTENT_TYPE }
|
|
@@ -23140,11 +23229,11 @@ async function followRun(workflowId, command) {
|
|
|
23140
23229
|
const includeThinking = flags.includeThinking === true;
|
|
23141
23230
|
const includeToolCalls = flags.includeToolCalls === true;
|
|
23142
23231
|
const negotiates = includeThinking || includeToolCalls;
|
|
23143
|
-
const { client, profile } =
|
|
23232
|
+
const { client, profile } = connect(command, ["executeWorkflow"]);
|
|
23144
23233
|
const operation = V2_OPERATIONS.executeWorkflow;
|
|
23145
23234
|
const request = await buildRequest("executeWorkflow", [workflowId], flags, profile.workspaceId);
|
|
23146
|
-
const response = await client.requestRaw(
|
|
23147
|
-
|
|
23235
|
+
const response = await client.requestRaw("executeWorkflow", {
|
|
23236
|
+
params: request.params,
|
|
23148
23237
|
query: request.query,
|
|
23149
23238
|
body: {
|
|
23150
23239
|
...withEmbeddedFileReferences(request.body),
|
|
@@ -23220,10 +23309,7 @@ function normalizeBlockName(name) {
|
|
|
23220
23309
|
return name.toLowerCase().replace(/\s+/g, "").replace(/\./g, "");
|
|
23221
23310
|
}
|
|
23222
23311
|
async function loadWorkflowBlocks(client, workflowId) {
|
|
23223
|
-
const
|
|
23224
|
-
const raw = await client.request(resolvePath(operation.path, { workflowId }), {
|
|
23225
|
-
method: operation.method
|
|
23226
|
-
});
|
|
23312
|
+
const raw = await client.request("getWorkflowState", { params: { workflowId } });
|
|
23227
23313
|
const state = isRecordLike(raw) && isRecordLike(raw.data) ? raw.data : raw;
|
|
23228
23314
|
const blocks = isRecordLike(state) && isRecordLike(state.blocks) ? Object.entries(state.blocks) : [];
|
|
23229
23315
|
return blocks.map(([key, block]) => ({
|
|
@@ -23277,9 +23363,8 @@ function keyByTyped(payload, typedBy) {
|
|
|
23277
23363
|
}
|
|
23278
23364
|
return { ...payload, blockOutputs };
|
|
23279
23365
|
}
|
|
23280
|
-
async function readRunByName(runId, typed, command) {
|
|
23366
|
+
async function readRunByName(runId, typed, command, { client, profile }) {
|
|
23281
23367
|
const flags = command.optsWithGlobals();
|
|
23282
|
-
const { client, profile } = clientFrom(command);
|
|
23283
23368
|
const operation = V2_OPERATIONS.getWorkflowRun;
|
|
23284
23369
|
const spec = CLI_CONTRACT.getWorkflowRun ?? {};
|
|
23285
23370
|
await buildRequest("getWorkflowRun", [runId], flags, profile.workspaceId);
|
|
@@ -23288,8 +23373,8 @@ async function readRunByName(runId, typed, command) {
|
|
|
23288
23373
|
const request = await buildRequest("getWorkflowRun", [runId], { ...flags, selectOutput: selection.resolved }, profile.workspaceId);
|
|
23289
23374
|
let result;
|
|
23290
23375
|
try {
|
|
23291
|
-
result = await client.request(
|
|
23292
|
-
|
|
23376
|
+
result = await client.request("getWorkflowRun", {
|
|
23377
|
+
params: request.params,
|
|
23293
23378
|
headers: request.headers,
|
|
23294
23379
|
query: request.query,
|
|
23295
23380
|
body: request.body
|
|
@@ -23306,6 +23391,7 @@ function attachWorkflowRunGet(runs) {
|
|
|
23306
23391
|
throw new Error("workflows runs get must be registered before block names can be attached to it");
|
|
23307
23392
|
}
|
|
23308
23393
|
const previous = held;
|
|
23394
|
+
const connectGet = callsOperations(get, ["getWorkflowRun", "getWorkflowState"]);
|
|
23309
23395
|
get.action(async (runId, _options, command) => {
|
|
23310
23396
|
const raw = command.optsWithGlobals().selectOutput;
|
|
23311
23397
|
if (raw === undefined) {
|
|
@@ -23318,7 +23404,7 @@ function attachWorkflowRunGet(runs) {
|
|
|
23318
23404
|
await previous(command.processedArgs);
|
|
23319
23405
|
return;
|
|
23320
23406
|
}
|
|
23321
|
-
await readRunByName(runId, typed, command);
|
|
23407
|
+
await readRunByName(runId, typed, command, connectGet());
|
|
23322
23408
|
});
|
|
23323
23409
|
}
|
|
23324
23410
|
|
|
@@ -23400,18 +23486,18 @@ function runSpec() {
|
|
|
23400
23486
|
return CLI_CONTRACT.getWorkflowRun ?? {};
|
|
23401
23487
|
}
|
|
23402
23488
|
function attachWorkflowRunWait(runs) {
|
|
23403
|
-
|
|
23489
|
+
const [wait, connectWait] = apiCommand(runs, "wait", ["getWorkflowRun"]);
|
|
23490
|
+
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) => {
|
|
23404
23491
|
const timeoutSeconds = options.waitTimeout === undefined ? DEFAULT_WAIT_TIMEOUT_SECONDS : parseWaitTimeout(options.waitTimeout);
|
|
23405
|
-
const { client, profile } =
|
|
23406
|
-
const
|
|
23407
|
-
const path = resolvePath(operation.path, { workflowId: options.workflow, runId });
|
|
23492
|
+
const { client, profile } = connectWait();
|
|
23493
|
+
const params = { workflowId: options.workflow, runId };
|
|
23408
23494
|
const startedAt = Date.now();
|
|
23409
23495
|
const deadline = timeoutSeconds === 0 ? Number.POSITIVE_INFINITY : startedAt + timeoutSeconds * 1000;
|
|
23410
23496
|
const progress = waitProgress();
|
|
23411
23497
|
let delayMs = FIRST_POLL_DELAY_MS;
|
|
23412
23498
|
try {
|
|
23413
23499
|
while (true) {
|
|
23414
|
-
const raw = await client.request(
|
|
23500
|
+
const raw = await client.request("getWorkflowRun", { params });
|
|
23415
23501
|
const snapshot = readRun(raw);
|
|
23416
23502
|
const outcome = classify(snapshot);
|
|
23417
23503
|
if (outcome) {
|
|
@@ -24763,17 +24849,16 @@ async function readSecretValue(options) {
|
|
|
24763
24849
|
return exitCli(CANCELLED_EXIT_CODE);
|
|
24764
24850
|
}
|
|
24765
24851
|
}
|
|
24766
|
-
async function setSecret(name, options,
|
|
24852
|
+
async function setSecret(name, options, connectSet, redactionSpellings) {
|
|
24767
24853
|
if (redactionSpellings.size > 1) {
|
|
24768
24854
|
throw new SimApiError("Pass either --unredacted or --no-unredacted, not both: they are one setting, and commander keeps only whichever came last.", 0);
|
|
24769
24855
|
}
|
|
24770
24856
|
const description = validateWorkspaceOnlyFlag("description", options.description, options.scope);
|
|
24771
24857
|
const unredacted = validateWorkspaceOnlyFlag("unredacted", options.unredacted, options.scope);
|
|
24772
24858
|
const value = await readSecretValue(options);
|
|
24773
|
-
const { client, profile } =
|
|
24774
|
-
const
|
|
24775
|
-
|
|
24776
|
-
method: operation.method,
|
|
24859
|
+
const { client, profile } = connectSet();
|
|
24860
|
+
const response = await client.request("setSecret", {
|
|
24861
|
+
params: { name },
|
|
24777
24862
|
body: {
|
|
24778
24863
|
workspaceId: client.requireWorkspace(),
|
|
24779
24864
|
scope: options.scope,
|
|
@@ -24789,7 +24874,8 @@ function attachSecretCommands(program) {
|
|
|
24789
24874
|
if (!secrets)
|
|
24790
24875
|
throw new Error("The generated secrets command group is missing");
|
|
24791
24876
|
const redactionSpellings = new Set;
|
|
24792
|
-
|
|
24877
|
+
const [set, connectSet] = apiCommand(secrets, "set", ["setSecret"]);
|
|
24878
|
+
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));
|
|
24793
24879
|
}
|
|
24794
24880
|
|
|
24795
24881
|
// src/telemetry/transport.ts
|
|
@@ -24850,13 +24936,6 @@ var FIRST_RUN_NOTICE = [
|
|
|
24850
24936
|
""
|
|
24851
24937
|
].join(`
|
|
24852
24938
|
`);
|
|
24853
|
-
function commandPath2(command) {
|
|
24854
|
-
const names = [];
|
|
24855
|
-
for (let current = command;current?.parent; current = current.parent) {
|
|
24856
|
-
names.unshift(current.name());
|
|
24857
|
-
}
|
|
24858
|
-
return names;
|
|
24859
|
-
}
|
|
24860
24939
|
function typedFlags(command) {
|
|
24861
24940
|
const flags = new Set;
|
|
24862
24941
|
for (let current = command;current; current = current.parent) {
|
|
@@ -24965,7 +25044,7 @@ function createCommandTelemetry(options = {}) {
|
|
|
24965
25044
|
return {
|
|
24966
25045
|
observe(program) {
|
|
24967
25046
|
program.hook("preAction", (_root, action) => {
|
|
24968
|
-
const path =
|
|
25047
|
+
const path = commandPath(action);
|
|
24969
25048
|
if (path[0] === EXCLUDED_ROOT_COMMAND || !isReportable({}))
|
|
24970
25049
|
return;
|
|
24971
25050
|
const state = loadTelemetryState();
|
|
@@ -25143,7 +25222,7 @@ function explainFailure(error, program) {
|
|
|
25143
25222
|
if (error instanceof SimApiError) {
|
|
25144
25223
|
let output = program.opts().output;
|
|
25145
25224
|
try {
|
|
25146
|
-
output =
|
|
25225
|
+
output = profileFrom(program).output;
|
|
25147
25226
|
} catch {}
|
|
25148
25227
|
if (output === "json" || output === "yaml") {
|
|
25149
25228
|
const payload = {
|