deepline 0.3.207 → 0.3.209
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/bundling-sources/sdk/src/release.ts +1 -1
- package/dist/bundling-sources/shared_libs/play-runtime/run-ledger.ts +21 -0
- package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +70 -3
- package/dist/cli/index.js +240 -101
- package/dist/cli/index.mjs +240 -101
- package/dist/index.js +5 -1
- package/dist/index.mjs +5 -1
- package/dist/release.d.mts +1 -1
- package/dist/release.d.ts +1 -1
- package/dist/release.js +1 -1
- package/dist/release.mjs +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -3051,7 +3051,7 @@ var SDK_RELEASE = {
|
|
|
3051
3051
|
// getters keep their established compatibility behavior.
|
|
3052
3052
|
// 0.3.1 deprecated the legacy `deepline enrich` command in favor of Plays.
|
|
3053
3053
|
// 0.3.90 is the first deliberately versioned SDK release for API v3.
|
|
3054
|
-
version: "0.3.
|
|
3054
|
+
version: "0.3.209",
|
|
3055
3055
|
updateSummary: "Play grep now returns concise results with the matched fields and terms. Automatic CLI updates are enabled by default; use `deepline settings autoupdate off` to opt out, `deepline settings autoupdate on` to re-enable updates, or `deepline settings autoupdate pin <version>` to hold an exact release.",
|
|
3056
3056
|
packageCapabilities: {
|
|
3057
3057
|
updatePreferences: 1
|
|
@@ -5450,6 +5450,8 @@ function createEmptyPlayRunLedgerSnapshot(input2) {
|
|
|
5450
5450
|
runId: input2.runId,
|
|
5451
5451
|
playName: input2.playName ?? null,
|
|
5452
5452
|
status,
|
|
5453
|
+
waitKind: null,
|
|
5454
|
+
waitUntil: null,
|
|
5453
5455
|
error: optionalNullableString(input2.error) ?? null,
|
|
5454
5456
|
createdAt: finiteNumber(input2.createdAt) ?? null,
|
|
5455
5457
|
startedAt,
|
|
@@ -5546,6 +5548,8 @@ function normalizePlayRunLedgerSnapshot(value, fallback) {
|
|
|
5546
5548
|
runId: optionalString(value.runId) ?? fallback.runId,
|
|
5547
5549
|
playName: optionalNullableString(value.playName) ?? fallback.playName ?? null,
|
|
5548
5550
|
status: normalizePlayRunLedgerStatus(value.status ?? fallback.status),
|
|
5551
|
+
waitKind: optionalNullableString(value.waitKind),
|
|
5552
|
+
waitUntil: finiteNumber(value.waitUntil),
|
|
5549
5553
|
error,
|
|
5550
5554
|
createdAt,
|
|
5551
5555
|
startedAt,
|
|
@@ -11645,6 +11649,7 @@ function printCommandEnvelope(envelope, options = {}) {
|
|
|
11645
11649
|
var EXIT_OK = 0;
|
|
11646
11650
|
var EXIT_AUTH = 3;
|
|
11647
11651
|
var EXIT_SERVER = 5;
|
|
11652
|
+
var EXIT_WORKSPACE_MISMATCH = 6;
|
|
11648
11653
|
var AUTH_HTTP_TIMEOUT_MS = 1e4;
|
|
11649
11654
|
var AUTH_REGISTER_HTTP_TIMEOUT_MS = 3e4;
|
|
11650
11655
|
function statusBannerLine(value) {
|
|
@@ -11735,7 +11740,8 @@ function readPendingAuthClaim(baseUrl, scope) {
|
|
|
11735
11740
|
if (!claimToken) return null;
|
|
11736
11741
|
return {
|
|
11737
11742
|
claimToken,
|
|
11738
|
-
claimUrl: typeof parsed.claimUrl === "string" ? parsed.claimUrl.trim() :
|
|
11743
|
+
claimUrl: typeof parsed.claimUrl === "string" && parsed.claimUrl.trim() ? parsed.claimUrl.trim() : `${baseUrl}/api/v2/auth/cli/claim/${encodeURIComponent(claimToken)}`,
|
|
11744
|
+
orgName: typeof parsed.orgName === "string" ? parsed.orgName.trim() : void 0,
|
|
11739
11745
|
// The record's own scope, when it has one. `register` writes this field
|
|
11740
11746
|
// precisely so a resume can learn where the credential belongs; reading
|
|
11741
11747
|
// back the caller's argument instead made it decorative, and a record
|
|
@@ -11756,6 +11762,14 @@ function clearPendingClaim(baseUrl, scope) {
|
|
|
11756
11762
|
} catch {
|
|
11757
11763
|
}
|
|
11758
11764
|
}
|
|
11765
|
+
function clearSatisfiedPendingClaim(baseUrl, scope, connectedWorkspaceName) {
|
|
11766
|
+
const pending = readPendingAuthClaim(baseUrl, scope);
|
|
11767
|
+
if (!pending) return;
|
|
11768
|
+
if (pending.orgName && pending.orgName.toLowerCase() !== connectedWorkspaceName?.trim().toLowerCase()) {
|
|
11769
|
+
return;
|
|
11770
|
+
}
|
|
11771
|
+
clearPendingClaim(baseUrl, scope);
|
|
11772
|
+
}
|
|
11759
11773
|
function parseRegisterWaitMode(args) {
|
|
11760
11774
|
let mode = "auto";
|
|
11761
11775
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -11993,7 +12007,12 @@ async function handleRegister(args) {
|
|
|
11993
12007
|
const claimUrl = String(data.claim_url || "");
|
|
11994
12008
|
const claimToken = String(data.claim_token || "");
|
|
11995
12009
|
if (claimToken) {
|
|
11996
|
-
savePendingClaim(baseUrl, {
|
|
12010
|
+
savePendingClaim(baseUrl, {
|
|
12011
|
+
claimToken,
|
|
12012
|
+
claimUrl,
|
|
12013
|
+
scope: authScope,
|
|
12014
|
+
...orgName ? { orgName } : {}
|
|
12015
|
+
});
|
|
11997
12016
|
saveEnvValues(
|
|
11998
12017
|
{
|
|
11999
12018
|
[HOST_URL_ENV]: baseUrl
|
|
@@ -12039,6 +12058,13 @@ async function handleRegister(args) {
|
|
|
12039
12058
|
return EXIT_SERVER;
|
|
12040
12059
|
}
|
|
12041
12060
|
const state = String(statusData.status || "").toLowerCase();
|
|
12061
|
+
if (statusData.code === "REQUESTED_WORKSPACE_NOT_IN_ACCOUNT") {
|
|
12062
|
+
clearPendingClaim(baseUrl, authScope);
|
|
12063
|
+
console.error(
|
|
12064
|
+
"The requested workspace does not exist in this account. Connect to an existing workspace first; then use `deepline org create` if you need a new one."
|
|
12065
|
+
);
|
|
12066
|
+
return EXIT_WORKSPACE_MISMATCH;
|
|
12067
|
+
}
|
|
12042
12068
|
if (state === "claimed") {
|
|
12043
12069
|
const apiKey = String(statusData.api_key || "");
|
|
12044
12070
|
if (apiKey) {
|
|
@@ -12100,12 +12126,13 @@ async function handleWait(args) {
|
|
|
12100
12126
|
return EXIT_AUTH;
|
|
12101
12127
|
}
|
|
12102
12128
|
const deadline = Date.now() + timeoutSeconds * 1e3;
|
|
12103
|
-
while (Date.now()
|
|
12129
|
+
while (Date.now() < deadline) {
|
|
12104
12130
|
const { status, data } = await httpJson(
|
|
12105
12131
|
"POST",
|
|
12106
12132
|
`${baseUrl}/api/v2/auth/cli/status`,
|
|
12107
12133
|
null,
|
|
12108
|
-
{ claim_token: claimToken, reveal: true }
|
|
12134
|
+
{ claim_token: claimToken, reveal: true },
|
|
12135
|
+
Math.min(AUTH_HTTP_TIMEOUT_MS, Math.max(1, deadline - Date.now()))
|
|
12109
12136
|
);
|
|
12110
12137
|
if (status === 401 || status === 403) {
|
|
12111
12138
|
clearPendingClaim(baseUrl, authScope);
|
|
@@ -12113,7 +12140,7 @@ async function handleWait(args) {
|
|
|
12113
12140
|
return EXIT_AUTH;
|
|
12114
12141
|
}
|
|
12115
12142
|
if (status >= 500 || status === 0 || status === 400) {
|
|
12116
|
-
await sleep4(2e3);
|
|
12143
|
+
await sleep4(Math.min(2e3, Math.max(0, deadline - Date.now())));
|
|
12117
12144
|
continue;
|
|
12118
12145
|
}
|
|
12119
12146
|
if (status >= 400) {
|
|
@@ -12121,6 +12148,13 @@ async function handleWait(args) {
|
|
|
12121
12148
|
return EXIT_SERVER;
|
|
12122
12149
|
}
|
|
12123
12150
|
const state = String(data.status || "").toLowerCase();
|
|
12151
|
+
if (data.code === "REQUESTED_WORKSPACE_NOT_IN_ACCOUNT") {
|
|
12152
|
+
clearPendingClaim(baseUrl, authScope);
|
|
12153
|
+
console.error(
|
|
12154
|
+
"The requested workspace does not exist in this account. Connect to an existing workspace first; then use `deepline org create` if you need a new one."
|
|
12155
|
+
);
|
|
12156
|
+
return EXIT_WORKSPACE_MISMATCH;
|
|
12157
|
+
}
|
|
12124
12158
|
if (state === "claimed") {
|
|
12125
12159
|
const apiKey = String(data.api_key || "");
|
|
12126
12160
|
if (apiKey) {
|
|
@@ -12143,7 +12177,7 @@ async function handleWait(args) {
|
|
|
12143
12177
|
console.error("That approval link expired. Run: deepline auth register");
|
|
12144
12178
|
return EXIT_AUTH;
|
|
12145
12179
|
}
|
|
12146
|
-
await sleep4(2e3);
|
|
12180
|
+
await sleep4(Math.min(2e3, Math.max(0, deadline - Date.now())));
|
|
12147
12181
|
}
|
|
12148
12182
|
console.error(
|
|
12149
12183
|
"Still pending. Approve the browser link, then run: deepline auth wait"
|
|
@@ -12288,7 +12322,11 @@ async function handleStatus(args) {
|
|
|
12288
12322
|
return EXIT_SERVER;
|
|
12289
12323
|
}
|
|
12290
12324
|
const resolvedAuthScope = authScope ?? (getResolvedProjectAuthSource(baseUrl, apiKey) ? "folder" : "global");
|
|
12291
|
-
|
|
12325
|
+
clearSatisfiedPendingClaim(
|
|
12326
|
+
baseUrl,
|
|
12327
|
+
resolvedAuthScope,
|
|
12328
|
+
typeof data.org_name === "string" ? data.org_name : null
|
|
12329
|
+
);
|
|
12292
12330
|
const payload = {
|
|
12293
12331
|
...hostStatusPayload ?? { host: baseUrl },
|
|
12294
12332
|
status: data.status || "(unknown)",
|
|
@@ -12302,6 +12340,7 @@ async function handleStatus(args) {
|
|
|
12302
12340
|
user: {
|
|
12303
12341
|
id: data.user_id ?? null
|
|
12304
12342
|
},
|
|
12343
|
+
businessDomain: typeof data.business_domain === "string" ? data.business_domain : null,
|
|
12305
12344
|
examples: Array.isArray(data.examples) ? data.examples : []
|
|
12306
12345
|
};
|
|
12307
12346
|
let savedApiKeyPath = null;
|
|
@@ -12413,7 +12452,7 @@ Examples:
|
|
|
12413
12452
|
`
|
|
12414
12453
|
).option(
|
|
12415
12454
|
"--org-name <name>",
|
|
12416
|
-
"
|
|
12455
|
+
"Connect to an existing workspace, or name your first workspace"
|
|
12417
12456
|
).option(
|
|
12418
12457
|
"--org-id <id>",
|
|
12419
12458
|
"Bind to this workspace directly, skipping the browser picker"
|
|
@@ -45452,11 +45491,24 @@ function openSetupAuthorization(authorizationUrl, options = {}) {
|
|
|
45452
45491
|
}
|
|
45453
45492
|
function buildPendingAuthorizationOutput(input2) {
|
|
45454
45493
|
const authorizationUrl = input2.authorizationUrl.trim();
|
|
45455
|
-
if (input2.browserOpenStatus === "
|
|
45494
|
+
if (input2.browserOpenStatus === "existing_claim" && authorizationUrl) {
|
|
45456
45495
|
return {
|
|
45457
|
-
authorizationUrl
|
|
45458
|
-
next: `
|
|
45459
|
-
lines: [
|
|
45496
|
+
authorizationUrl,
|
|
45497
|
+
next: `The existing approval is still pending. Use its authorization URL if needed, then run: ${input2.resumeCommand}`,
|
|
45498
|
+
lines: [
|
|
45499
|
+
"Deepline did not open another browser tab. Use the existing approval page or this link:",
|
|
45500
|
+
authorizationUrl
|
|
45501
|
+
]
|
|
45502
|
+
};
|
|
45503
|
+
}
|
|
45504
|
+
if (input2.browserOpenStatus === "timed_out" && authorizationUrl) {
|
|
45505
|
+
return {
|
|
45506
|
+
authorizationUrl,
|
|
45507
|
+
next: `Approval is still pending after five minutes. Use the authorization URL if needed, then run: ${input2.resumeCommand}`,
|
|
45508
|
+
lines: [
|
|
45509
|
+
"Approval is still pending. Use this link if the tab was missed:",
|
|
45510
|
+
authorizationUrl
|
|
45511
|
+
]
|
|
45460
45512
|
};
|
|
45461
45513
|
}
|
|
45462
45514
|
if (authorizationUrl) {
|
|
@@ -45646,15 +45698,16 @@ function rollbackCommand(scope, root) {
|
|
|
45646
45698
|
const allowScriptsFlag = npmSupportsAllowScripts(readNpmVersion(process.env)) ? " --allow-scripts=esbuild" : "";
|
|
45647
45699
|
return `npm install -g${prefix} --no-audit --no-fund --include=optional${allowScriptsFlag} deepline@${SDK_VERSION}`;
|
|
45648
45700
|
}
|
|
45649
|
-
function setupResumeCommand(baseUrl, scope) {
|
|
45701
|
+
function setupResumeCommand(baseUrl, scope, orgName) {
|
|
45650
45702
|
const hostPrefix = baseUrl === "https://code.deepline.com" ? "" : `DEEPLINE_HOST_URL=${JSON.stringify(baseUrl)} `;
|
|
45651
|
-
|
|
45703
|
+
const quotedOrgName = orgName ? process.platform === "win32" ? ` --org-name "${orgName.replace(/"/g, '""')}"` : ` --org-name '${orgName.replace(/'/g, `'\\''`)}'` : "";
|
|
45704
|
+
return `${hostPrefix}deepline setup --scope ${scope}${quotedOrgName} --json`;
|
|
45652
45705
|
}
|
|
45653
45706
|
function setupRetry(input2) {
|
|
45654
45707
|
return {
|
|
45655
45708
|
phase: input2.phase,
|
|
45656
|
-
command: setupResumeCommand(input2.baseUrl, input2.scope),
|
|
45657
|
-
automatic: true
|
|
45709
|
+
command: setupResumeCommand(input2.baseUrl, input2.scope, input2.orgName),
|
|
45710
|
+
automatic: input2.retryAutomatic ?? true
|
|
45658
45711
|
};
|
|
45659
45712
|
}
|
|
45660
45713
|
function reportSetupPhaseFailure(input2) {
|
|
@@ -45710,6 +45763,7 @@ function reportSetupAuthStatusFailure(input2) {
|
|
|
45710
45763
|
scope: input2.scope,
|
|
45711
45764
|
root: input2.root,
|
|
45712
45765
|
phases: input2.phases,
|
|
45766
|
+
orgName: input2.orgName,
|
|
45713
45767
|
phase: "auth",
|
|
45714
45768
|
code: "AUTH_STATUS_FAILED",
|
|
45715
45769
|
exitCode: 4,
|
|
@@ -45832,22 +45886,14 @@ function pendingResult(input2) {
|
|
|
45832
45886
|
status: "authorization_pending",
|
|
45833
45887
|
phases: input2.phases
|
|
45834
45888
|
});
|
|
45835
|
-
let browserOpenStatus = "failed";
|
|
45836
|
-
if (input2.authorizationUrl) {
|
|
45837
|
-
browserOpenStatus = openSetupAuthorization(input2.authorizationUrl);
|
|
45838
|
-
if (browserOpenStatus === "opened") {
|
|
45839
|
-
process.stderr.write(
|
|
45840
|
-
"Opened Deepline authorization in your browser. Complete approval there.\n"
|
|
45841
|
-
);
|
|
45842
|
-
} else if (browserOpenStatus === "failed") {
|
|
45843
|
-
process.stderr.write(`Authorize Deepline: ${input2.authorizationUrl}
|
|
45844
|
-
`);
|
|
45845
|
-
}
|
|
45846
|
-
}
|
|
45847
45889
|
const pendingOutput = buildPendingAuthorizationOutput({
|
|
45848
45890
|
authorizationUrl: input2.authorizationUrl,
|
|
45849
|
-
browserOpenStatus,
|
|
45850
|
-
resumeCommand: setupResumeCommand(
|
|
45891
|
+
browserOpenStatus: input2.browserOpenStatus,
|
|
45892
|
+
resumeCommand: setupResumeCommand(
|
|
45893
|
+
input2.baseUrl,
|
|
45894
|
+
input2.scope,
|
|
45895
|
+
input2.orgName
|
|
45896
|
+
)
|
|
45851
45897
|
});
|
|
45852
45898
|
printCommandEnvelope(
|
|
45853
45899
|
{
|
|
@@ -45856,8 +45902,9 @@ function pendingResult(input2) {
|
|
|
45856
45902
|
complete: false,
|
|
45857
45903
|
scope: input2.scope,
|
|
45858
45904
|
authorizationUrl: pendingOutput.authorizationUrl,
|
|
45859
|
-
browserOpened: browserOpenStatus === "
|
|
45860
|
-
browserOpenStatus,
|
|
45905
|
+
browserOpened: input2.browserOpenStatus === "timed_out",
|
|
45906
|
+
browserOpenStatus: input2.browserOpenStatus,
|
|
45907
|
+
authClaimSource: input2.authClaimSource,
|
|
45861
45908
|
statePath,
|
|
45862
45909
|
phases: input2.phases,
|
|
45863
45910
|
currentPhase: "auth",
|
|
@@ -45865,7 +45912,8 @@ function pendingResult(input2) {
|
|
|
45865
45912
|
retry: setupRetry({
|
|
45866
45913
|
baseUrl: input2.baseUrl,
|
|
45867
45914
|
scope: input2.scope,
|
|
45868
|
-
phase: "auth"
|
|
45915
|
+
phase: "auth",
|
|
45916
|
+
orgName: input2.orgName
|
|
45869
45917
|
}),
|
|
45870
45918
|
next: pendingOutput.next,
|
|
45871
45919
|
render: {
|
|
@@ -45882,6 +45930,20 @@ function pendingResult(input2) {
|
|
|
45882
45930
|
return 0;
|
|
45883
45931
|
}
|
|
45884
45932
|
async function runSetupCommand(options) {
|
|
45933
|
+
let orgName = options.orgName?.trim();
|
|
45934
|
+
if (options.orgName !== void 0 && !orgName) {
|
|
45935
|
+
printCommandEnvelope(
|
|
45936
|
+
{
|
|
45937
|
+
ok: false,
|
|
45938
|
+
status: "failed",
|
|
45939
|
+
code: "INVALID_ORG_NAME",
|
|
45940
|
+
exitCode: 2,
|
|
45941
|
+
message: "Workspace name cannot be empty."
|
|
45942
|
+
},
|
|
45943
|
+
{ json: options.json }
|
|
45944
|
+
);
|
|
45945
|
+
return 2;
|
|
45946
|
+
}
|
|
45885
45947
|
let scope;
|
|
45886
45948
|
let root;
|
|
45887
45949
|
try {
|
|
@@ -45926,6 +45988,7 @@ async function runSetupCommand(options) {
|
|
|
45926
45988
|
exitCode: 7,
|
|
45927
45989
|
message: installedButUnreachable ? `The global Deepline executable is not reachable on PATH: ${globalCli.persistentPath}` : "No persistent global Deepline executable was found.",
|
|
45928
45990
|
json: options.json,
|
|
45991
|
+
orgName,
|
|
45929
45992
|
extra: {
|
|
45930
45993
|
persistentPath: globalCli.persistentPath,
|
|
45931
45994
|
fallback: "https://code.deepline.com/INSTALL.md"
|
|
@@ -45945,6 +46008,7 @@ async function runSetupCommand(options) {
|
|
|
45945
46008
|
exitCode: 7,
|
|
45946
46009
|
message: `An unknown executable named deepline is first on PATH: ${conflict}`,
|
|
45947
46010
|
json: options.json,
|
|
46011
|
+
orgName,
|
|
45948
46012
|
extra: { path: conflict }
|
|
45949
46013
|
});
|
|
45950
46014
|
}
|
|
@@ -45978,7 +46042,8 @@ async function runSetupCommand(options) {
|
|
|
45978
46042
|
code: "LEGACY_CLEANUP_FAILED",
|
|
45979
46043
|
exitCode: 5,
|
|
45980
46044
|
message: error instanceof Error ? error.message : String(error),
|
|
45981
|
-
json: options.json
|
|
46045
|
+
json: options.json,
|
|
46046
|
+
orgName
|
|
45982
46047
|
});
|
|
45983
46048
|
}
|
|
45984
46049
|
}
|
|
@@ -45999,7 +46064,7 @@ async function runSetupCommand(options) {
|
|
|
45999
46064
|
process.stderr.write(
|
|
46000
46065
|
"Global skill setup failed. Trying project-local skills instead.\n"
|
|
46001
46066
|
);
|
|
46002
|
-
return runSetupCommand({ scope: "local", json: options.json });
|
|
46067
|
+
return runSetupCommand({ scope: "local", json: options.json, orgName });
|
|
46003
46068
|
}
|
|
46004
46069
|
return reportSetupPhaseFailure({
|
|
46005
46070
|
baseUrl,
|
|
@@ -46011,7 +46076,8 @@ async function runSetupCommand(options) {
|
|
|
46011
46076
|
exitCode: skills.exitCode,
|
|
46012
46077
|
message: typeof skillsPayload?.message === "string" ? skillsPayload.message : "Deepline skills could not be installed.",
|
|
46013
46078
|
json: options.json,
|
|
46014
|
-
|
|
46079
|
+
orgName,
|
|
46080
|
+
next: `! ${setupResumeCommand(baseUrl, scope, orgName)}`,
|
|
46015
46081
|
extra: { detail: skillsPayload }
|
|
46016
46082
|
});
|
|
46017
46083
|
}
|
|
@@ -46033,6 +46099,13 @@ async function runSetupCommand(options) {
|
|
|
46033
46099
|
);
|
|
46034
46100
|
}
|
|
46035
46101
|
const authScope = authScopeForSetup(scope);
|
|
46102
|
+
const pendingAtStart = readPendingAuthClaim(baseUrl, authScope);
|
|
46103
|
+
const replacingPendingClaim = Boolean(
|
|
46104
|
+
pendingAtStart && orgName && pendingAtStart.orgName?.toLowerCase() !== orgName.toLowerCase()
|
|
46105
|
+
);
|
|
46106
|
+
if (pendingAtStart && !replacingPendingClaim) {
|
|
46107
|
+
if (pendingAtStart.orgName) orgName = pendingAtStart.orgName;
|
|
46108
|
+
}
|
|
46036
46109
|
beginSetupPhase(phases, "auth");
|
|
46037
46110
|
persistSetupProgress({ baseUrl, scope, root, phases });
|
|
46038
46111
|
let auth = await readAuthStatus(authScope);
|
|
@@ -46043,88 +46116,146 @@ async function runSetupCommand(options) {
|
|
|
46043
46116
|
scope,
|
|
46044
46117
|
root,
|
|
46045
46118
|
phases,
|
|
46119
|
+
orgName,
|
|
46046
46120
|
json: options.json
|
|
46047
46121
|
});
|
|
46048
46122
|
if (initialAuthFailure !== null) return initialAuthFailure;
|
|
46049
|
-
|
|
46050
|
-
|
|
46051
|
-
if (
|
|
46052
|
-
|
|
46053
|
-
|
|
46054
|
-
|
|
46055
|
-
|
|
46056
|
-
|
|
46057
|
-
|
|
46058
|
-
|
|
46059
|
-
|
|
46060
|
-
|
|
46061
|
-
|
|
46062
|
-
|
|
46063
|
-
|
|
46064
|
-
|
|
46065
|
-
|
|
46066
|
-
|
|
46067
|
-
|
|
46068
|
-
|
|
46069
|
-
|
|
46070
|
-
|
|
46071
|
-
|
|
46072
|
-
|
|
46073
|
-
|
|
46074
|
-
|
|
46075
|
-
|
|
46076
|
-
|
|
46077
|
-
|
|
46078
|
-
|
|
46079
|
-
|
|
46123
|
+
const connectedToRequestedWorkspace = () => {
|
|
46124
|
+
if (auth.payload?.connected !== true) return false;
|
|
46125
|
+
if (!orgName) return true;
|
|
46126
|
+
const workspace = asRecord3(auth.payload.workspace);
|
|
46127
|
+
return typeof workspace?.name === "string" && workspace.name.trim().toLowerCase() === orgName.toLowerCase();
|
|
46128
|
+
};
|
|
46129
|
+
let pending = replacingPendingClaim ? null : readPendingAuthClaim(baseUrl, authScope);
|
|
46130
|
+
if (replacingPendingClaim && connectedToRequestedWorkspace()) {
|
|
46131
|
+
clearPendingClaim(baseUrl, authScope);
|
|
46132
|
+
}
|
|
46133
|
+
let authClaimSource = "none";
|
|
46134
|
+
if (pending || !connectedToRequestedWorkspace()) {
|
|
46135
|
+
const reusedClaim = Boolean(pending);
|
|
46136
|
+
authClaimSource = reusedClaim ? "existing" : "new";
|
|
46137
|
+
if (!pending) {
|
|
46138
|
+
process.stderr.write("Starting Deepline browser authorization...\n");
|
|
46139
|
+
const registered = await captureStdout2(
|
|
46140
|
+
() => handleRegister([
|
|
46141
|
+
"--wait",
|
|
46142
|
+
"no",
|
|
46143
|
+
"--auth-scope",
|
|
46144
|
+
authScope,
|
|
46145
|
+
...orgName ? ["--org-name", orgName] : []
|
|
46146
|
+
])
|
|
46147
|
+
);
|
|
46148
|
+
if (registered.exitCode !== 0) {
|
|
46149
|
+
return reportSetupPhaseFailure({
|
|
46150
|
+
baseUrl,
|
|
46151
|
+
scope,
|
|
46152
|
+
root,
|
|
46153
|
+
phases,
|
|
46154
|
+
phase: "auth",
|
|
46155
|
+
code: "AUTH_REGISTER_FAILED",
|
|
46156
|
+
exitCode: registered.exitCode,
|
|
46157
|
+
message: "Deepline browser authorization could not be started.",
|
|
46158
|
+
orgName,
|
|
46159
|
+
json: options.json,
|
|
46160
|
+
extra: { detail: parseCapturedJson(registered.stdout), authScope }
|
|
46161
|
+
});
|
|
46080
46162
|
}
|
|
46163
|
+
pending = readPendingAuthClaim(baseUrl, authScope);
|
|
46164
|
+
if (!pending?.claimUrl) {
|
|
46165
|
+
return reportSetupPhaseFailure({
|
|
46166
|
+
baseUrl,
|
|
46167
|
+
scope,
|
|
46168
|
+
root,
|
|
46169
|
+
phases,
|
|
46170
|
+
phase: "auth",
|
|
46171
|
+
code: "AUTH_CLAIM_URL_MISSING",
|
|
46172
|
+
exitCode: 4,
|
|
46173
|
+
message: "Deepline authorization did not return a usable claim URL.",
|
|
46174
|
+
orgName,
|
|
46175
|
+
json: options.json
|
|
46176
|
+
});
|
|
46177
|
+
}
|
|
46178
|
+
const browserOpenStatus = openSetupAuthorization(pending.claimUrl);
|
|
46179
|
+
if (browserOpenStatus === "failed") {
|
|
46180
|
+
return pendingResult({
|
|
46181
|
+
baseUrl,
|
|
46182
|
+
scope,
|
|
46183
|
+
root,
|
|
46184
|
+
phases,
|
|
46185
|
+
authorizationUrl: pending.claimUrl,
|
|
46186
|
+
browserOpenStatus: "failed",
|
|
46187
|
+
authClaimSource,
|
|
46188
|
+
orgName,
|
|
46189
|
+
resumed,
|
|
46190
|
+
json: options.json
|
|
46191
|
+
});
|
|
46192
|
+
}
|
|
46193
|
+
process.stderr.write("Opened Deepline sign-in in the browser.\n");
|
|
46081
46194
|
}
|
|
46082
|
-
|
|
46083
|
-
|
|
46084
|
-
|
|
46085
|
-
const
|
|
46086
|
-
|
|
46087
|
-
const waitMode = options.json || agentLed || !process.stdin.isTTY ? "no" : "auto";
|
|
46088
|
-
const registered = await captureStdout2(
|
|
46089
|
-
() => handleRegister(["--wait", waitMode, "--auth-scope", authScope])
|
|
46195
|
+
process.stderr.write(
|
|
46196
|
+
"Waiting up to five minutes for Deepline approval...\n"
|
|
46197
|
+
);
|
|
46198
|
+
const waited = await captureStdout2(
|
|
46199
|
+
() => handleWait(["--timeout", "300", "--auth-scope", authScope])
|
|
46090
46200
|
);
|
|
46091
|
-
if (registered.exitCode !== 0) {
|
|
46092
|
-
return reportSetupPhaseFailure({
|
|
46093
|
-
baseUrl,
|
|
46094
|
-
scope,
|
|
46095
|
-
root,
|
|
46096
|
-
phases,
|
|
46097
|
-
phase: "auth",
|
|
46098
|
-
code: "AUTH_REGISTER_FAILED",
|
|
46099
|
-
exitCode: registered.exitCode,
|
|
46100
|
-
message: "Deepline browser authorization could not be started.",
|
|
46101
|
-
json: options.json,
|
|
46102
|
-
extra: {
|
|
46103
|
-
detail: parseCapturedJson(registered.stdout),
|
|
46104
|
-
authScope
|
|
46105
|
-
}
|
|
46106
|
-
});
|
|
46107
|
-
}
|
|
46108
46201
|
auth = await readAuthStatus(authScope);
|
|
46109
|
-
const
|
|
46202
|
+
const authFailure = reportSetupAuthStatusFailure({
|
|
46110
46203
|
auth,
|
|
46111
46204
|
baseUrl,
|
|
46112
46205
|
authScope,
|
|
46113
46206
|
scope,
|
|
46114
46207
|
root,
|
|
46115
46208
|
phases,
|
|
46209
|
+
orgName,
|
|
46116
46210
|
json: options.json
|
|
46117
46211
|
});
|
|
46118
|
-
if (
|
|
46119
|
-
if (
|
|
46120
|
-
|
|
46121
|
-
return pendingResult({
|
|
46212
|
+
if (authFailure !== null) return authFailure;
|
|
46213
|
+
if (waited.exitCode === EXIT_WORKSPACE_MISMATCH) {
|
|
46214
|
+
return reportSetupPhaseFailure({
|
|
46122
46215
|
baseUrl,
|
|
46123
46216
|
scope,
|
|
46124
46217
|
root,
|
|
46125
46218
|
phases,
|
|
46126
|
-
|
|
46127
|
-
|
|
46219
|
+
phase: "auth",
|
|
46220
|
+
code: "REQUESTED_WORKSPACE_NOT_IN_ACCOUNT",
|
|
46221
|
+
exitCode: EXIT_WORKSPACE_MISMATCH,
|
|
46222
|
+
message: `The requested workspace${orgName ? ` ${orgName}` : ""} does not exist in this account. Connect to an existing workspace first; then use deepline org create if you need a new one.`,
|
|
46223
|
+
orgName,
|
|
46224
|
+
retryAutomatic: false,
|
|
46225
|
+
next: "Ask the user which existing workspace or account to use. Sign in with an account that can access it, then rerun setup with --org-name set to the confirmed workspace.",
|
|
46226
|
+
json: options.json
|
|
46227
|
+
});
|
|
46228
|
+
}
|
|
46229
|
+
if (!connectedToRequestedWorkspace()) {
|
|
46230
|
+
const stillPending = readPendingAuthClaim(baseUrl, authScope);
|
|
46231
|
+
if (stillPending?.claimUrl) {
|
|
46232
|
+
return pendingResult({
|
|
46233
|
+
baseUrl,
|
|
46234
|
+
scope,
|
|
46235
|
+
root,
|
|
46236
|
+
phases,
|
|
46237
|
+
authorizationUrl: stillPending.claimUrl,
|
|
46238
|
+
browserOpenStatus: reusedClaim ? "existing_claim" : "timed_out",
|
|
46239
|
+
authClaimSource,
|
|
46240
|
+
orgName,
|
|
46241
|
+
resumed,
|
|
46242
|
+
json: options.json
|
|
46243
|
+
});
|
|
46244
|
+
}
|
|
46245
|
+
return reportSetupPhaseFailure({
|
|
46246
|
+
baseUrl,
|
|
46247
|
+
scope,
|
|
46248
|
+
root,
|
|
46249
|
+
phases,
|
|
46250
|
+
phase: "auth",
|
|
46251
|
+
code: orgName && auth.payload?.connected ? "AUTH_WORKSPACE_MISMATCH" : "AUTH_WAIT_FAILED",
|
|
46252
|
+
exitCode: waited.exitCode || 4,
|
|
46253
|
+
message: orgName && auth.payload?.connected ? `Deepline is connected to a different workspace than ${orgName}.` : "Deepline authorization did not complete.",
|
|
46254
|
+
orgName,
|
|
46255
|
+
...orgName && auth.payload?.connected ? {
|
|
46256
|
+
retryAutomatic: false,
|
|
46257
|
+
next: "Ask the user which existing workspace or account to use. Rerun setup with --org-name set to the confirmed workspace."
|
|
46258
|
+
} : {},
|
|
46128
46259
|
json: options.json
|
|
46129
46260
|
});
|
|
46130
46261
|
}
|
|
@@ -46158,6 +46289,7 @@ async function runSetupCommand(options) {
|
|
|
46158
46289
|
code: "DOCTOR_FAILED",
|
|
46159
46290
|
exitCode: 7,
|
|
46160
46291
|
message: "Deepline setup verification found one or more failed checks.",
|
|
46292
|
+
orgName,
|
|
46161
46293
|
json: options.json,
|
|
46162
46294
|
extra: {
|
|
46163
46295
|
doctor: doctorPayload,
|
|
@@ -46198,6 +46330,9 @@ async function runSetupCommand(options) {
|
|
|
46198
46330
|
cliVersion: SDK_VERSION,
|
|
46199
46331
|
agents: installedAgents,
|
|
46200
46332
|
workspace: apiCheck?.workspace ?? null,
|
|
46333
|
+
businessDomain: typeof auth.payload?.businessDomain === "string" ? auth.payload.businessDomain : null,
|
|
46334
|
+
authClaimSource,
|
|
46335
|
+
browserOpened: authClaimSource === "new",
|
|
46201
46336
|
rollbackCommand: rollbackCommand(scope, root),
|
|
46202
46337
|
statePath,
|
|
46203
46338
|
doctor: doctorPayload,
|
|
@@ -46229,7 +46364,10 @@ async function runSetupCommand(options) {
|
|
|
46229
46364
|
return 0;
|
|
46230
46365
|
}
|
|
46231
46366
|
function registerSetupCommands(program) {
|
|
46232
|
-
program.command("setup").description("Install skills, authenticate, and verify Deepline.").option("--scope <scope>", "Setup scope: global or local", "global").option(
|
|
46367
|
+
program.command("setup").description("Install skills, authenticate, and verify Deepline.").option("--scope <scope>", "Setup scope: global or local", "global").option(
|
|
46368
|
+
"--org-name <name>",
|
|
46369
|
+
"Connect to an existing workspace, or name your first workspace"
|
|
46370
|
+
).option("--json", "Emit one final JSON result envelope").addHelpText(
|
|
46233
46371
|
"after",
|
|
46234
46372
|
`
|
|
46235
46373
|
Notes:
|
|
@@ -46239,6 +46377,7 @@ Notes:
|
|
|
46239
46377
|
|
|
46240
46378
|
Examples:
|
|
46241
46379
|
deepline setup --json
|
|
46380
|
+
deepline setup --org-name Acme --json
|
|
46242
46381
|
deepline setup --scope local --json
|
|
46243
46382
|
`
|
|
46244
46383
|
).action(async (options) => {
|