@base44-preview/cli 0.1.15-pr.630.66e368f → 0.1.15-pr.630.68db200
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/cli/index.js +1395 -1309
- package/dist/cli/index.js.map +20 -20
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -269450,1431 +269450,1482 @@ function getAgentsCommand() {
|
|
|
269450
269450
|
return new Command2("agents").description("Manage project agents").addCommand(getAgentsPushCommand()).addCommand(getAgentsPullCommand());
|
|
269451
269451
|
}
|
|
269452
269452
|
|
|
269453
|
-
// src/
|
|
269454
|
-
|
|
269455
|
-
|
|
269456
|
-
|
|
269457
|
-
{
|
|
269458
|
-
|
|
269459
|
-
|
|
269460
|
-
|
|
269461
|
-
|
|
269462
|
-
|
|
269463
|
-
|
|
269464
|
-
|
|
269465
|
-
|
|
269466
|
-
|
|
269467
|
-
|
|
269468
|
-
return byExact;
|
|
269469
|
-
const byContains = MODELS.filter((m) => fold(m.name).includes(key) || m.id && fold(m.id).includes(key));
|
|
269470
|
-
if (byContains.length === 1)
|
|
269471
|
-
return byContains[0];
|
|
269472
|
-
const names = MODELS.map((m) => m.name).join(", ");
|
|
269473
|
-
throw new InvalidInputError(byContains.length > 1 ? `"${input}" is ambiguous — matches ${byContains.map((m) => m.name).join(", ")}.` : `Unknown model "${input}". Choose one of: ${names}.`);
|
|
269474
|
-
}
|
|
269475
|
-
async function getMe() {
|
|
269476
|
-
try {
|
|
269477
|
-
return await base44Client.get("api/auth/me").json();
|
|
269478
|
-
} catch (error) {
|
|
269479
|
-
throw await ApiError.fromHttpError(error, "reading your account");
|
|
269453
|
+
// src/cli/commands/auth/password-login.ts
|
|
269454
|
+
import { dirname as dirname15, join as join21 } from "node:path";
|
|
269455
|
+
async function passwordLoginAction({ log, runTask }, action) {
|
|
269456
|
+
const shouldEnable = action === "enable";
|
|
269457
|
+
const { project } = await readProjectConfig();
|
|
269458
|
+
const configDir = dirname15(project.configPath);
|
|
269459
|
+
const authDir = join21(configDir, project.authDir);
|
|
269460
|
+
const updated = await runTask("Updating local auth config", async () => {
|
|
269461
|
+
const current = await readAuthConfig(authDir) ?? DEFAULT_AUTH_CONFIG;
|
|
269462
|
+
const merged = { ...current, enableUsernamePassword: shouldEnable };
|
|
269463
|
+
await writeAuthConfig(authDir, merged);
|
|
269464
|
+
return merged;
|
|
269465
|
+
});
|
|
269466
|
+
if (!shouldEnable && !hasAnyLoginMethod(updated)) {
|
|
269467
|
+
log.warn("Disabling password auth will leave no login methods enabled. Users will be locked out.");
|
|
269480
269468
|
}
|
|
269469
|
+
const newStatus = shouldEnable ? "enabled" : "disabled";
|
|
269470
|
+
return {
|
|
269471
|
+
outroMessage: `Username & password authentication ${newStatus} in local config. Run \`base44 auth push\` or \`base44 deploy\` to apply.`
|
|
269472
|
+
};
|
|
269481
269473
|
}
|
|
269482
|
-
|
|
269483
|
-
|
|
269484
|
-
|
|
269485
|
-
|
|
269486
|
-
|
|
269487
|
-
|
|
269488
|
-
|
|
269489
|
-
|
|
269490
|
-
|
|
269491
|
-
|
|
269474
|
+
function getPasswordLoginCommand() {
|
|
269475
|
+
return new Base44Command("password-login").description("Enable or disable username & password authentication").addArgument(new Argument2("<action>", "enable or disable password authentication").choices(["enable", "disable"])).action(passwordLoginAction);
|
|
269476
|
+
}
|
|
269477
|
+
|
|
269478
|
+
// src/cli/commands/auth/pull.ts
|
|
269479
|
+
import { dirname as dirname16, join as join22 } from "node:path";
|
|
269480
|
+
async function pullAuthAction({
|
|
269481
|
+
log,
|
|
269482
|
+
runTask
|
|
269483
|
+
}) {
|
|
269484
|
+
const { project } = await readProjectConfig();
|
|
269485
|
+
const configDir = dirname16(project.configPath);
|
|
269486
|
+
const authDir = join22(configDir, project.authDir);
|
|
269487
|
+
const remoteConfig = await runTask("Fetching auth config from Base44", async () => {
|
|
269488
|
+
return await pullAuthConfig();
|
|
269489
|
+
}, {
|
|
269490
|
+
successMessage: "Auth config fetched successfully",
|
|
269491
|
+
errorMessage: "Failed to fetch auth config"
|
|
269492
|
+
});
|
|
269493
|
+
const { written } = await runTask("Syncing auth config file", async () => {
|
|
269494
|
+
return await writeAuthConfig(authDir, remoteConfig);
|
|
269495
|
+
}, {
|
|
269496
|
+
successMessage: "Auth config file synced successfully",
|
|
269497
|
+
errorMessage: "Failed to sync auth config file"
|
|
269498
|
+
});
|
|
269499
|
+
if (written) {
|
|
269500
|
+
log.success("Auth config written to local file");
|
|
269501
|
+
} else {
|
|
269502
|
+
log.info("Auth config is already up to date");
|
|
269492
269503
|
}
|
|
269504
|
+
return {
|
|
269505
|
+
outroMessage: `Pulled auth config to ${authDir} (overwrites local file)`
|
|
269506
|
+
};
|
|
269507
|
+
}
|
|
269508
|
+
function getAuthPullCommand() {
|
|
269509
|
+
return new Base44Command("pull").description("Pull auth config from Base44 to local file").action(pullAuthAction);
|
|
269493
269510
|
}
|
|
269494
|
-
var displayName = (id) => MODELS.find((m) => m.id === id)?.name ?? id ?? "default";
|
|
269495
269511
|
|
|
269496
|
-
// src/cli/commands/
|
|
269497
|
-
async function
|
|
269498
|
-
const
|
|
269499
|
-
|
|
269500
|
-
|
|
269501
|
-
if (jsonMode) {
|
|
269502
|
-
return {
|
|
269503
|
-
stdout: `${JSON.stringify({
|
|
269504
|
-
current,
|
|
269505
|
-
models: MODELS.map((m) => ({ name: m.name, id: m.id }))
|
|
269506
|
-
})}
|
|
269507
|
-
`
|
|
269508
|
-
};
|
|
269509
|
-
}
|
|
269510
|
-
for (const m of MODELS) {
|
|
269511
|
-
const active = (m.id ?? null) === current;
|
|
269512
|
-
const marker = active ? theme.styles.bold("●") : theme.styles.dim("○");
|
|
269513
|
-
const note = m.note ? theme.styles.dim(` (${m.note})`) : "";
|
|
269514
|
-
log.message(`${marker} ${active ? theme.styles.bold(m.name) : m.name}${note}`);
|
|
269515
|
-
}
|
|
269512
|
+
// src/cli/commands/auth/push.ts
|
|
269513
|
+
async function pushAuthAction({ isNonInteractive, log, runTask }, options) {
|
|
269514
|
+
const { authConfig } = await readProjectConfig();
|
|
269515
|
+
if (authConfig.length === 0) {
|
|
269516
|
+
log.info("No local auth config found");
|
|
269516
269517
|
return {
|
|
269517
|
-
outroMessage:
|
|
269518
|
+
outroMessage: "No auth config to push. Run `base44 auth pull` to fetch the remote config first."
|
|
269518
269519
|
};
|
|
269519
269520
|
}
|
|
269520
|
-
|
|
269521
|
-
|
|
269522
|
-
return { outroMessage: `Already on ${theme.styles.bold(pick.name)}.` };
|
|
269521
|
+
if (!hasAnyLoginMethod(authConfig[0])) {
|
|
269522
|
+
log.warn("This config has no login methods enabled. Pushing it will lock out all users.");
|
|
269523
269523
|
}
|
|
269524
|
-
|
|
269525
|
-
|
|
269526
|
-
|
|
269527
|
-
|
|
269524
|
+
if (!options.yes) {
|
|
269525
|
+
if (isNonInteractive) {
|
|
269526
|
+
throw new InvalidInputError("--yes is required in non-interactive mode");
|
|
269527
|
+
}
|
|
269528
|
+
const shouldPush = await Re({
|
|
269529
|
+
message: "Push auth config to Base44?"
|
|
269530
|
+
});
|
|
269531
|
+
if (Ct(shouldPush) || !shouldPush) {
|
|
269532
|
+
return { outroMessage: "Push cancelled" };
|
|
269533
|
+
}
|
|
269534
|
+
}
|
|
269535
|
+
await runTask("Pushing auth config to Base44", async () => {
|
|
269536
|
+
return await pushAuthConfig(authConfig[0] ?? null);
|
|
269537
|
+
}, {
|
|
269538
|
+
successMessage: "Auth config pushed successfully",
|
|
269539
|
+
errorMessage: "Failed to push auth config"
|
|
269540
|
+
});
|
|
269528
269541
|
return {
|
|
269529
|
-
outroMessage:
|
|
269542
|
+
outroMessage: "Auth config pushed to Base44"
|
|
269530
269543
|
};
|
|
269531
269544
|
}
|
|
269532
|
-
function
|
|
269533
|
-
|
|
269534
|
-
command.description("Pick the builder model for your turns (account-wide). No argument lists models and the current pick; `default` clears it").argument("[model]", 'Model name or id, e.g. "Opus 5" or default').action(modelAction);
|
|
269535
|
-
return command;
|
|
269545
|
+
function getAuthPushCommand() {
|
|
269546
|
+
return new Base44Command("push").description("Push local auth config to Base44").option("-y, --yes", "Skip confirmation prompt").action(pushAuthAction);
|
|
269536
269547
|
}
|
|
269537
269548
|
|
|
269538
|
-
// src/cli/commands/
|
|
269539
|
-
import {
|
|
269540
|
-
|
|
269541
|
-
|
|
269542
|
-
|
|
269543
|
-
|
|
269544
|
-
|
|
269545
|
-
read_repo_file: "read",
|
|
269546
|
-
write_repo_file: "write",
|
|
269547
|
-
edit_repo_file: "edit",
|
|
269548
|
-
set_secrets: "secrets",
|
|
269549
|
-
generate_development_secrets: "secrets",
|
|
269550
|
-
create_pull_request: "pr",
|
|
269551
|
-
merge_pull_request: "merge",
|
|
269552
|
-
list_pr_threads: "pr threads",
|
|
269553
|
-
reply_to_pr_thread: "pr reply",
|
|
269554
|
-
comment_on_pr: "pr comment",
|
|
269555
|
-
resolve_pr_thread: "pr resolve",
|
|
269556
|
-
reload_preview: "reload",
|
|
269557
|
-
preview_execute_code: "preview js",
|
|
269558
|
-
preview_screenshot: "screenshot",
|
|
269559
|
-
connect_github_account: "github"
|
|
269549
|
+
// src/cli/commands/auth/social-login.ts
|
|
269550
|
+
import { dirname as dirname17, join as join23, resolve as resolve6 } from "node:path";
|
|
269551
|
+
var PROVIDER_LABELS = {
|
|
269552
|
+
google: "Google",
|
|
269553
|
+
microsoft: "Microsoft",
|
|
269554
|
+
facebook: "Facebook",
|
|
269555
|
+
apple: "Apple"
|
|
269560
269556
|
};
|
|
269561
|
-
var
|
|
269562
|
-
|
|
269563
|
-
|
|
269564
|
-
|
|
269565
|
-
|
|
269566
|
-
var BEL = String.fromCharCode(7);
|
|
269567
|
-
var OSC8_CLOSE = `${ESC_CHAR}]8;;${BEL}`;
|
|
269568
|
-
function terminalLink(label, url) {
|
|
269569
|
-
return `${ESC_CHAR}]8;;${url}${BEL}${source_default.dim.underline(label)}${OSC8_CLOSE}`;
|
|
269570
|
-
}
|
|
269571
|
-
function linkifyUrls(text) {
|
|
269572
|
-
let n = 0;
|
|
269573
|
-
return text.replace(/https?:\/\/[^\s]+/g, (raw) => {
|
|
269574
|
-
const trailing = raw.match(/[.,;:!?)\]}'"]+$/)?.[0] ?? "";
|
|
269575
|
-
const url = trailing ? raw.slice(0, -trailing.length) : raw;
|
|
269576
|
-
const id = `b44-${n++}`;
|
|
269577
|
-
return `${ESC_CHAR}]8;id=${id};${url}${BEL}${url}${OSC8_CLOSE}${trailing}`;
|
|
269578
|
-
});
|
|
269579
|
-
}
|
|
269580
|
-
function hardWrapAnsi(text, width) {
|
|
269581
|
-
const ESC = new RegExp(`^(?:${ESC_CHAR}\\[[0-9;]*m|${ESC_CHAR}\\]8;[^${BEL}]*${BEL})`);
|
|
269582
|
-
const RESET = `${ESC_CHAR}[0m`;
|
|
269583
|
-
const out = [];
|
|
269584
|
-
for (const logical of text.split(`
|
|
269585
|
-
`)) {
|
|
269586
|
-
let line = "";
|
|
269587
|
-
let visible = 0;
|
|
269588
|
-
let active = [];
|
|
269589
|
-
let link = "";
|
|
269590
|
-
let i = 0;
|
|
269591
|
-
while (i < logical.length) {
|
|
269592
|
-
const esc = ESC.exec(logical.slice(i));
|
|
269593
|
-
if (esc) {
|
|
269594
|
-
const seq = esc[0];
|
|
269595
|
-
line += seq;
|
|
269596
|
-
if (seq === RESET)
|
|
269597
|
-
active = [];
|
|
269598
|
-
else if (seq.endsWith("m"))
|
|
269599
|
-
active.push(seq);
|
|
269600
|
-
else if (seq === OSC8_CLOSE)
|
|
269601
|
-
link = "";
|
|
269602
|
-
else
|
|
269603
|
-
link = seq;
|
|
269604
|
-
i += seq.length;
|
|
269605
|
-
continue;
|
|
269606
|
-
}
|
|
269607
|
-
if (visible >= width) {
|
|
269608
|
-
out.push(`${line}${link ? OSC8_CLOSE : ""}${RESET}`);
|
|
269609
|
-
line = active.join("") + link;
|
|
269610
|
-
visible = 0;
|
|
269611
|
-
}
|
|
269612
|
-
line += logical[i];
|
|
269613
|
-
visible++;
|
|
269614
|
-
i++;
|
|
269615
|
-
}
|
|
269616
|
-
out.push(line);
|
|
269557
|
+
var VALID_PROVIDER_NAMES = Object.keys(SOCIAL_PROVIDERS);
|
|
269558
|
+
var PROVIDER_OAUTH_CLI = {
|
|
269559
|
+
google: {
|
|
269560
|
+
envVar: "google_oauth_client_secret",
|
|
269561
|
+
promptMessage: "Enter Google OAuth client secret"
|
|
269617
269562
|
}
|
|
269618
|
-
|
|
269563
|
+
};
|
|
269564
|
+
function hasSecretOptions(options) {
|
|
269565
|
+
return Boolean(options.clientSecret || options.clientSecretStdin || options.envFile);
|
|
269619
269566
|
}
|
|
269620
|
-
function
|
|
269621
|
-
|
|
269622
|
-
if (seconds < 90)
|
|
269623
|
-
return `${seconds}s`;
|
|
269624
|
-
return `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
269567
|
+
function hasCustomOAuthOptions(options) {
|
|
269568
|
+
return Boolean(options.clientId || hasSecretOptions(options));
|
|
269625
269569
|
}
|
|
269626
|
-
function
|
|
269627
|
-
|
|
269628
|
-
|
|
269629
|
-
|
|
269630
|
-
|
|
269631
|
-
|
|
269632
|
-
|
|
269633
|
-
|
|
269634
|
-
|
|
269635
|
-
|
|
269636
|
-
|
|
269637
|
-
|
|
269638
|
-
|
|
269639
|
-
|
|
269640
|
-
|
|
269641
|
-
|
|
269642
|
-
|
|
269643
|
-
|
|
269644
|
-
|
|
269645
|
-
|
|
269646
|
-
const
|
|
269647
|
-
|
|
269648
|
-
|
|
269570
|
+
async function socialLoginAction({ log, isNonInteractive, runTask }, provider, action, options) {
|
|
269571
|
+
const shouldEnable = action === "enable";
|
|
269572
|
+
const providerInfo = SOCIAL_PROVIDERS[provider];
|
|
269573
|
+
const label = PROVIDER_LABELS[provider];
|
|
269574
|
+
const hasOAuthOptions = hasCustomOAuthOptions(options);
|
|
269575
|
+
if (hasOAuthOptions && !providerInfo.customOAuth) {
|
|
269576
|
+
throw new InvalidInputError(`Custom OAuth options are only supported for providers with custom OAuth (e.g., google). Use: base44 auth social-login ${provider} ${action}`);
|
|
269577
|
+
}
|
|
269578
|
+
if (hasOAuthOptions && !shouldEnable) {
|
|
269579
|
+
throw new InvalidInputError(`Custom OAuth options cannot be used with disable. To disable ${label} login: base44 auth social-login ${provider} disable`);
|
|
269580
|
+
}
|
|
269581
|
+
if (hasSecretOptions(options) && !options.clientId) {
|
|
269582
|
+
throw new InvalidInputError(`--client-id is required when providing a client secret. Use: base44 auth social-login ${provider} enable --client-id <id> --client-secret <secret>`);
|
|
269583
|
+
}
|
|
269584
|
+
const oauth = providerInfo.customOAuth;
|
|
269585
|
+
const oauthCli = PROVIDER_OAUTH_CLI[provider];
|
|
269586
|
+
const useCustomOAuth = shouldEnable && hasOAuthOptions && oauth != null;
|
|
269587
|
+
let clientSecret;
|
|
269588
|
+
if (useCustomOAuth && oauth && oauthCli && hasSecretOptions(options)) {
|
|
269589
|
+
if (options.envFile) {
|
|
269590
|
+
const secrets = await parseEnvFile(resolve6(options.envFile));
|
|
269591
|
+
const value = secrets[oauthCli.envVar];
|
|
269592
|
+
if (!value) {
|
|
269593
|
+
throw new InvalidInputError(`Key "${oauthCli.envVar}" not found in ${options.envFile}.`);
|
|
269649
269594
|
}
|
|
269650
|
-
|
|
269651
|
-
|
|
269652
|
-
|
|
269595
|
+
clientSecret = value;
|
|
269596
|
+
} else {
|
|
269597
|
+
clientSecret = await resolveSecret({
|
|
269598
|
+
flagValue: options.clientSecret,
|
|
269599
|
+
fromStdin: options.clientSecretStdin,
|
|
269600
|
+
envVar: oauthCli.envVar,
|
|
269601
|
+
promptMessage: oauthCli.promptMessage,
|
|
269602
|
+
isNonInteractive,
|
|
269603
|
+
name: "client secret",
|
|
269604
|
+
hints: [
|
|
269605
|
+
{
|
|
269606
|
+
message: `Provide via flag: base44 auth social-login ${provider} enable --client-id <id> --client-secret <secret>`,
|
|
269607
|
+
command: `base44 auth social-login ${provider} enable --client-id <id> --client-secret <secret>`
|
|
269608
|
+
},
|
|
269609
|
+
{
|
|
269610
|
+
message: `Provide via stdin: echo <secret> | base44 auth social-login ${provider} enable --client-id <id> --client-secret-stdin`
|
|
269611
|
+
},
|
|
269612
|
+
{
|
|
269613
|
+
message: `Provide via env: ${oauthCli.envVar}=<secret> base44 auth social-login ${provider} enable --client-id <id>`
|
|
269614
|
+
}
|
|
269615
|
+
]
|
|
269616
|
+
});
|
|
269653
269617
|
}
|
|
269654
269618
|
}
|
|
269619
|
+
const { project } = await readProjectConfig();
|
|
269620
|
+
const configDir = dirname17(project.configPath);
|
|
269621
|
+
const authDir = join23(configDir, project.authDir);
|
|
269622
|
+
const { config: updated } = await runTask("Updating local auth config", async () => updateSocialLoginConfig(authDir, provider, shouldEnable, useCustomOAuth && options.clientId ? { clientId: options.clientId } : undefined));
|
|
269623
|
+
if (clientSecret) {
|
|
269624
|
+
await runTask("Saving client secret", async () => pushCustomOAuthSecret(provider, clientSecret));
|
|
269625
|
+
}
|
|
269626
|
+
if (!shouldEnable && !hasAnyLoginMethod(updated)) {
|
|
269627
|
+
log.warn(`Disabling ${label} login will leave no login methods enabled. Users will be locked out.`);
|
|
269628
|
+
}
|
|
269629
|
+
const newStatus = shouldEnable ? "enabled" : "disabled";
|
|
269630
|
+
const oauthNote = useCustomOAuth ? " with custom OAuth" : "";
|
|
269631
|
+
let outroMessage = `${label} login ${newStatus}${oauthNote} in local config. Run \`base44 auth push\` or \`base44 deploy\` to apply.`;
|
|
269632
|
+
if (useCustomOAuth && !clientSecret) {
|
|
269633
|
+
outroMessage += `
|
|
269634
|
+
Remember to push the client secret separately: base44 secrets set --env-file <path>`;
|
|
269635
|
+
}
|
|
269636
|
+
return { outroMessage };
|
|
269655
269637
|
}
|
|
269656
|
-
|
|
269657
|
-
|
|
269658
|
-
|
|
269659
|
-
|
|
269660
|
-
"
|
|
269661
|
-
"Noodling",
|
|
269662
|
-
"Marinating",
|
|
269663
|
-
"Brewing",
|
|
269664
|
-
"Simmering",
|
|
269665
|
-
"Conjuring",
|
|
269666
|
-
"Tinkering",
|
|
269667
|
-
"Scheming",
|
|
269668
|
-
"Pondering",
|
|
269669
|
-
"Mulling",
|
|
269670
|
-
"Whirring",
|
|
269671
|
-
"Crunching",
|
|
269672
|
-
"Weaving",
|
|
269673
|
-
"Sketching",
|
|
269674
|
-
"Hatching",
|
|
269675
|
-
"Riffing",
|
|
269676
|
-
"Cooking",
|
|
269677
|
-
"Composting ideas",
|
|
269678
|
-
"Rummaging",
|
|
269679
|
-
"Vibing responsibly",
|
|
269680
|
-
"Untangling",
|
|
269681
|
-
"Squinting at the repo"
|
|
269682
|
-
];
|
|
269683
|
-
var MUSING_ROTATE_MS = 6000;
|
|
269684
|
-
function idleMusing(seed) {
|
|
269685
|
-
return `${MUSINGS[(seed + Math.floor(Date.now() / MUSING_ROTATE_MS)) % MUSINGS.length]}…`;
|
|
269686
|
-
}
|
|
269687
|
-
function createTurnStream(interactive, write = (text) => process.stdout.write(text), options = {}) {
|
|
269688
|
-
const running = new Map;
|
|
269689
|
-
const footer = options.footer ?? [];
|
|
269690
|
-
let frame = 0;
|
|
269691
|
-
let stopped = false;
|
|
269692
|
-
let drawnLines = 0;
|
|
269693
|
-
const musingSeed = Math.floor(Math.random() * MUSINGS.length);
|
|
269694
|
-
const statusLabel = () => {
|
|
269695
|
-
if (running.size === 0) {
|
|
269696
|
-
if (options.idleLabel)
|
|
269697
|
-
return `${options.idleLabel}…`;
|
|
269698
|
-
const index = (musingSeed + Math.floor(Date.now() / MUSING_ROTATE_MS)) % MUSINGS.length;
|
|
269699
|
-
return `${MUSINGS[index]}…`;
|
|
269700
|
-
}
|
|
269701
|
-
const newest = [...running.values()].at(-1);
|
|
269702
|
-
const elapsed = Math.round((Date.now() - newest.startedAt) / 1000);
|
|
269703
|
-
const others = running.size > 1 ? ` (+${running.size - 1} more)` : "";
|
|
269704
|
-
const what = newest.label || `${newest.alias}${newest.summary ? ` ${newest.summary}` : ""}`;
|
|
269705
|
-
return `${what}${others} · ${elapsed}s`;
|
|
269706
|
-
};
|
|
269707
|
-
const clearBlock = () => {
|
|
269708
|
-
if (!drawnLines)
|
|
269709
|
-
return;
|
|
269710
|
-
write("\r\x1B[2K");
|
|
269711
|
-
for (let i = 1;i < drawnLines; i++)
|
|
269712
|
-
write("\x1B[1A\r\x1B[2K");
|
|
269713
|
-
drawnLines = 0;
|
|
269714
|
-
};
|
|
269715
|
-
const drawBlock = () => {
|
|
269716
|
-
if (!interactive || stopped)
|
|
269717
|
-
return;
|
|
269718
|
-
const lines = [
|
|
269719
|
-
...footer.length ? ["", ...footer] : [],
|
|
269720
|
-
source_default.dim(`${FRAMES[frame]} ${statusLabel()}`)
|
|
269721
|
-
];
|
|
269722
|
-
write(lines.join(`
|
|
269723
|
-
`));
|
|
269724
|
-
drawnLines = lines.length;
|
|
269725
|
-
};
|
|
269726
|
-
const tick = () => {
|
|
269727
|
-
if (!interactive || stopped)
|
|
269728
|
-
return;
|
|
269729
|
-
frame = (frame + 1) % FRAMES.length;
|
|
269730
|
-
clearBlock();
|
|
269731
|
-
drawBlock();
|
|
269732
|
-
};
|
|
269733
|
-
const timer = interactive ? setInterval(tick, 120) : null;
|
|
269734
|
-
if (timer)
|
|
269735
|
-
timer.unref?.();
|
|
269736
|
-
return {
|
|
269737
|
-
onEvent(event) {
|
|
269738
|
-
if (event.kind === "tool_start") {
|
|
269739
|
-
running.set(event.id, {
|
|
269740
|
-
alias: toolAlias(event.name),
|
|
269741
|
-
label: event.label,
|
|
269742
|
-
summary: event.summary,
|
|
269743
|
-
startedAt: Date.now()
|
|
269744
|
-
});
|
|
269745
|
-
if (interactive) {
|
|
269746
|
-
clearBlock();
|
|
269747
|
-
drawBlock();
|
|
269748
|
-
}
|
|
269749
|
-
return;
|
|
269750
|
-
}
|
|
269751
|
-
let elapsedMs;
|
|
269752
|
-
if (event.kind === "tool_end") {
|
|
269753
|
-
const started = running.get(event.id)?.startedAt;
|
|
269754
|
-
if (started != null)
|
|
269755
|
-
elapsedMs = Date.now() - started;
|
|
269756
|
-
running.delete(event.id);
|
|
269757
|
-
}
|
|
269758
|
-
const line = eventLine(event, elapsedMs);
|
|
269759
|
-
if (line == null)
|
|
269760
|
-
return;
|
|
269761
|
-
if (interactive) {
|
|
269762
|
-
clearBlock();
|
|
269763
|
-
write(`${line}
|
|
269764
|
-
`);
|
|
269765
|
-
drawBlock();
|
|
269766
|
-
} else {
|
|
269767
|
-
write(`${line}
|
|
269768
|
-
`);
|
|
269769
|
-
}
|
|
269770
|
-
},
|
|
269771
|
-
stop() {
|
|
269772
|
-
if (interactive) {
|
|
269773
|
-
clearBlock();
|
|
269774
|
-
if (footer.length)
|
|
269775
|
-
write(`
|
|
269776
|
-
${footer.join(`
|
|
269777
|
-
`)}
|
|
269778
|
-
`);
|
|
269779
|
-
}
|
|
269780
|
-
stopped = true;
|
|
269781
|
-
if (timer)
|
|
269782
|
-
clearInterval(timer);
|
|
269783
|
-
}
|
|
269784
|
-
};
|
|
269638
|
+
function getSocialLoginCommand() {
|
|
269639
|
+
return new Base44Command("social-login").description("Enable or disable social login providers (google, microsoft, facebook, apple)").addArgument(new Argument2("<provider>", "social login provider").choices(VALID_PROVIDER_NAMES)).addArgument(new Argument2("<action>", "enable or disable the provider").choices([
|
|
269640
|
+
"enable",
|
|
269641
|
+
"disable"
|
|
269642
|
+
])).option("--client-id <id>", "custom OAuth client ID (Google only)").option("--client-secret <secret>", "custom OAuth client secret (Google only)").option("--client-secret-stdin", "read client secret from stdin (Google only)").option("--env-file <path>", "read client secret from a .env file (Google only)").action(socialLoginAction);
|
|
269785
269643
|
}
|
|
269786
269644
|
|
|
269787
|
-
// src/
|
|
269788
|
-
|
|
269789
|
-
|
|
269790
|
-
|
|
269791
|
-
|
|
269792
|
-
|
|
269793
|
-
|
|
269794
|
-
|
|
269795
|
-
|
|
269796
|
-
|
|
269797
|
-
|
|
269798
|
-
|
|
269799
|
-
|
|
269800
|
-
|
|
269801
|
-
|
|
269802
|
-
status: object({
|
|
269803
|
-
state: string2().nullish(),
|
|
269804
|
-
message: string2().nullish(),
|
|
269805
|
-
error_source: string2().nullish()
|
|
269806
|
-
}).nullish(),
|
|
269807
|
-
conversation: object({
|
|
269808
|
-
messages: array(object({
|
|
269809
|
-
role: string2().nullish(),
|
|
269810
|
-
content: unknown().nullish()
|
|
269811
|
-
})).nullish()
|
|
269812
|
-
}).nullish()
|
|
269813
|
-
});
|
|
269814
|
-
var PreviewUrlSchema = object({
|
|
269815
|
-
preview_url: string2().min(1)
|
|
269816
|
-
});
|
|
269817
|
-
var ConversationMessageSchema = object({
|
|
269818
|
-
id: string2(),
|
|
269819
|
-
role: string2(),
|
|
269820
|
-
hidden: boolean2().nullish(),
|
|
269821
|
-
outcome: unknown().nullish(),
|
|
269822
|
-
content: unknown().nullish(),
|
|
269823
|
-
reasoning: object({ content: string2().nullish() }).nullish(),
|
|
269824
|
-
tool_calls: array(object({
|
|
269825
|
-
id: string2(),
|
|
269826
|
-
name: string2(),
|
|
269827
|
-
arguments_string: string2().nullish(),
|
|
269828
|
-
status: string2().nullish(),
|
|
269829
|
-
results: unknown().nullish()
|
|
269830
|
-
})).nullish()
|
|
269831
|
-
});
|
|
269832
|
-
var FullConversationSchema = object({
|
|
269833
|
-
messages: array(ConversationMessageSchema).default([])
|
|
269645
|
+
// src/cli/commands/auth/sso.ts
|
|
269646
|
+
import { dirname as dirname18, join as join24, resolve as resolve7 } from "node:path";
|
|
269647
|
+
var SSOConfigFileSchema = object({
|
|
269648
|
+
provider: _enum(Object.values(KNOWN_SSO_PROVIDERS)),
|
|
269649
|
+
clientId: string2(),
|
|
269650
|
+
clientSecret: string2(),
|
|
269651
|
+
scope: string2().optional(),
|
|
269652
|
+
discoveryUrl: string2().optional(),
|
|
269653
|
+
tenantId: string2().optional(),
|
|
269654
|
+
oktaDomain: string2().optional(),
|
|
269655
|
+
authEndpoint: string2().optional(),
|
|
269656
|
+
tokenEndpoint: string2().optional(),
|
|
269657
|
+
userinfoEndpoint: string2().optional(),
|
|
269658
|
+
jwksUri: string2().optional(),
|
|
269659
|
+
ssoName: string2().optional()
|
|
269834
269660
|
});
|
|
269835
|
-
|
|
269836
|
-
|
|
269837
|
-
const
|
|
269661
|
+
async function loadSSOConfigFile(filePath) {
|
|
269662
|
+
const resolved = resolve7(filePath);
|
|
269663
|
+
const raw = await readJsonFile(resolved);
|
|
269664
|
+
const result = SSOConfigFileSchema.safeParse(raw);
|
|
269838
269665
|
if (!result.success) {
|
|
269839
|
-
throw new SchemaValidationError(
|
|
269666
|
+
throw new SchemaValidationError("Invalid SSO config file", result.error, filePath);
|
|
269840
269667
|
}
|
|
269841
269668
|
return result.data;
|
|
269842
269669
|
}
|
|
269843
|
-
function
|
|
269844
|
-
return
|
|
269670
|
+
function mergeFileWithFlags(fileConfig, options) {
|
|
269671
|
+
return {
|
|
269672
|
+
provider: options.provider ?? fileConfig.provider,
|
|
269673
|
+
clientId: options.clientId ?? fileConfig.clientId,
|
|
269674
|
+
clientSecret: options.clientSecret ?? fileConfig.clientSecret,
|
|
269675
|
+
clientSecretStdin: options.clientSecretStdin,
|
|
269676
|
+
envFile: options.envFile,
|
|
269677
|
+
scope: options.scope ?? fileConfig.scope,
|
|
269678
|
+
discoveryUrl: options.discoveryUrl ?? fileConfig.discoveryUrl,
|
|
269679
|
+
tenantId: options.tenantId ?? fileConfig.tenantId,
|
|
269680
|
+
oktaDomain: options.oktaDomain ?? fileConfig.oktaDomain,
|
|
269681
|
+
authEndpoint: options.authEndpoint ?? fileConfig.authEndpoint,
|
|
269682
|
+
tokenEndpoint: options.tokenEndpoint ?? fileConfig.tokenEndpoint,
|
|
269683
|
+
userinfoEndpoint: options.userinfoEndpoint ?? fileConfig.userinfoEndpoint,
|
|
269684
|
+
jwksUri: options.jwksUri ?? fileConfig.jwksUri,
|
|
269685
|
+
ssoName: options.ssoName ?? fileConfig.ssoName
|
|
269686
|
+
};
|
|
269845
269687
|
}
|
|
269846
|
-
|
|
269847
|
-
|
|
269848
|
-
|
|
269849
|
-
|
|
269850
|
-
|
|
269851
|
-
|
|
269852
|
-
|
|
269853
|
-
|
|
269854
|
-
|
|
269855
|
-
|
|
269688
|
+
var providerNames = Object.keys(KNOWN_SSO_PROVIDERS);
|
|
269689
|
+
var SECRET_KEY_TO_FLAG = {
|
|
269690
|
+
["sso_name" /* Name */]: "--sso-name",
|
|
269691
|
+
["sso_client_id" /* ClientId */]: "--client-id",
|
|
269692
|
+
["sso_client_secret" /* ClientSecret */]: "--client-secret",
|
|
269693
|
+
["sso_scope" /* Scope */]: "--scope",
|
|
269694
|
+
["sso_discovery_url" /* DiscoveryUrl */]: "--discovery-url",
|
|
269695
|
+
["sso_tenant_id" /* TenantId */]: "--tenant-id",
|
|
269696
|
+
["sso_auth_endpoint" /* AuthEndpoint */]: "--auth-endpoint",
|
|
269697
|
+
["sso_token_endpoint" /* TokenEndpoint */]: "--token-endpoint",
|
|
269698
|
+
["sso_userinfo_endpoint" /* UserinfoEndpoint */]: "--userinfo-endpoint",
|
|
269699
|
+
["sso_okta_domain" /* OktaDomain */]: "--okta-domain",
|
|
269700
|
+
["sso_jwks_uri" /* JwksUri */]: "--jwks-uri"
|
|
269701
|
+
};
|
|
269702
|
+
function secretKeyToFlag(key) {
|
|
269703
|
+
return SECRET_KEY_TO_FLAG[key];
|
|
269704
|
+
}
|
|
269705
|
+
function exampleCommand(provider) {
|
|
269706
|
+
let cmd = `base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`;
|
|
269707
|
+
if (provider === KNOWN_SSO_PROVIDERS.microsoft)
|
|
269708
|
+
cmd += " --tenant-id <id>";
|
|
269709
|
+
if (provider === KNOWN_SSO_PROVIDERS.okta)
|
|
269710
|
+
cmd += " --okta-domain <domain>";
|
|
269711
|
+
if (provider === KNOWN_SSO_PROVIDERS.custom)
|
|
269712
|
+
cmd += " --sso-name <name> --auth-endpoint <url> --token-endpoint <url> --userinfo-endpoint <url> --jwks-uri <url>";
|
|
269713
|
+
return cmd;
|
|
269714
|
+
}
|
|
269715
|
+
function validateProvider(provider) {
|
|
269716
|
+
if (!provider) {
|
|
269717
|
+
throw new InvalidInputError("Missing --provider.", {
|
|
269718
|
+
hints: [
|
|
269719
|
+
{
|
|
269720
|
+
message: `Valid providers: ${providerNames.join(", ")}`,
|
|
269721
|
+
command: "base44 auth sso enable --provider <provider> --client-id <id> --client-secret <secret>"
|
|
269722
|
+
}
|
|
269723
|
+
]
|
|
269856
269724
|
});
|
|
269857
|
-
} catch (error) {
|
|
269858
|
-
throw await ApiError.fromHttpError(error, "creating app");
|
|
269859
269725
|
}
|
|
269860
|
-
return
|
|
269726
|
+
return provider;
|
|
269861
269727
|
}
|
|
269862
|
-
async function
|
|
269863
|
-
|
|
269864
|
-
|
|
269865
|
-
|
|
269866
|
-
|
|
269867
|
-
|
|
269868
|
-
|
|
269869
|
-
|
|
269870
|
-
|
|
269871
|
-
|
|
269872
|
-
|
|
269873
|
-
|
|
269874
|
-
|
|
269875
|
-
|
|
269728
|
+
async function ssoEnableAction({ isNonInteractive, runTask }, options) {
|
|
269729
|
+
if (options.file && options.envFile) {
|
|
269730
|
+
throw new InvalidInputError("--file and --env-file cannot be used together. Provide the client secret either inside --file or via --env-file.");
|
|
269731
|
+
}
|
|
269732
|
+
let merged = options;
|
|
269733
|
+
if (options.file) {
|
|
269734
|
+
const fileConfig = await loadSSOConfigFile(options.file);
|
|
269735
|
+
merged = mergeFileWithFlags(fileConfig, options);
|
|
269736
|
+
}
|
|
269737
|
+
const provider = validateProvider(merged.provider);
|
|
269738
|
+
if (!merged.clientId) {
|
|
269739
|
+
throw new InvalidInputError("Missing --client-id.", {
|
|
269740
|
+
hints: [
|
|
269741
|
+
{
|
|
269742
|
+
message: `Example: base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`,
|
|
269743
|
+
command: `base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`
|
|
269744
|
+
}
|
|
269745
|
+
]
|
|
269876
269746
|
});
|
|
269877
|
-
} catch (error) {
|
|
269878
|
-
throw await ApiError.fromHttpError(error, "importing repository");
|
|
269879
269747
|
}
|
|
269880
|
-
|
|
269881
|
-
|
|
269882
|
-
|
|
269883
|
-
|
|
269884
|
-
|
|
269885
|
-
}
|
|
269886
|
-
|
|
269887
|
-
|
|
269888
|
-
|
|
269889
|
-
|
|
269890
|
-
|
|
269891
|
-
|
|
269892
|
-
|
|
269893
|
-
|
|
269894
|
-
|
|
269748
|
+
let clientSecret;
|
|
269749
|
+
if (merged.envFile && !merged.clientSecret) {
|
|
269750
|
+
const secrets = await parseEnvFile(resolve7(merged.envFile));
|
|
269751
|
+
const value = secrets.sso_client_secret;
|
|
269752
|
+
if (!value) {
|
|
269753
|
+
throw new InvalidInputError(`Key "sso_client_secret" not found in ${merged.envFile}.`);
|
|
269754
|
+
}
|
|
269755
|
+
clientSecret = value;
|
|
269756
|
+
} else {
|
|
269757
|
+
clientSecret = await resolveSecret({
|
|
269758
|
+
flagValue: merged.clientSecret,
|
|
269759
|
+
fromStdin: merged.clientSecretStdin,
|
|
269760
|
+
envVar: "sso_client_secret",
|
|
269761
|
+
promptMessage: "Enter SSO client secret",
|
|
269762
|
+
isNonInteractive,
|
|
269763
|
+
name: "client secret",
|
|
269764
|
+
hints: [
|
|
269765
|
+
{
|
|
269766
|
+
message: `Provide via flag: base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`,
|
|
269767
|
+
command: `base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`
|
|
269768
|
+
},
|
|
269769
|
+
{
|
|
269770
|
+
message: `Provide via stdin: echo <secret> | base44 auth sso enable --provider ${provider} --client-id <id> --client-secret-stdin`
|
|
269771
|
+
},
|
|
269772
|
+
{
|
|
269773
|
+
message: `Provide via env: sso_client_secret=<secret> base44 auth sso enable --provider ${provider} --client-id <id>`
|
|
269774
|
+
}
|
|
269775
|
+
]
|
|
269895
269776
|
});
|
|
269896
|
-
} catch (error) {
|
|
269897
|
-
throw await ApiError.fromHttpError(error, "reading app status");
|
|
269898
269777
|
}
|
|
269899
|
-
|
|
269900
|
-
|
|
269901
|
-
|
|
269902
|
-
|
|
269778
|
+
const secretOptions = {
|
|
269779
|
+
clientId: merged.clientId,
|
|
269780
|
+
clientSecret,
|
|
269781
|
+
scope: merged.scope,
|
|
269782
|
+
discoveryUrl: merged.discoveryUrl,
|
|
269783
|
+
tenantId: merged.tenantId,
|
|
269784
|
+
oktaDomain: merged.oktaDomain,
|
|
269785
|
+
authEndpoint: merged.authEndpoint,
|
|
269786
|
+
tokenEndpoint: merged.tokenEndpoint,
|
|
269787
|
+
userinfoEndpoint: merged.userinfoEndpoint,
|
|
269788
|
+
jwksUri: merged.jwksUri,
|
|
269789
|
+
ssoName: merged.ssoName
|
|
269790
|
+
};
|
|
269791
|
+
let secrets;
|
|
269903
269792
|
try {
|
|
269904
|
-
|
|
269905
|
-
timeout: false,
|
|
269906
|
-
searchParams: {
|
|
269907
|
-
conversation_messages: "current_turn",
|
|
269908
|
-
...branchScope(branchId)
|
|
269909
|
-
},
|
|
269910
|
-
json: { content }
|
|
269911
|
-
});
|
|
269793
|
+
secrets = buildSSOSecrets(provider, secretOptions);
|
|
269912
269794
|
} catch (error) {
|
|
269913
|
-
|
|
269795
|
+
if (error instanceof MissingSSOFieldsError) {
|
|
269796
|
+
const flagNames = error.missingKeys.map(secretKeyToFlag);
|
|
269797
|
+
throw new InvalidInputError(`Missing required fields for ${error.provider}: ${flagNames.join(", ")}`, {
|
|
269798
|
+
hints: [
|
|
269799
|
+
{
|
|
269800
|
+
message: `Example: ${exampleCommand(provider)}`,
|
|
269801
|
+
command: exampleCommand(provider)
|
|
269802
|
+
}
|
|
269803
|
+
]
|
|
269804
|
+
});
|
|
269805
|
+
}
|
|
269806
|
+
throw error;
|
|
269914
269807
|
}
|
|
269915
|
-
|
|
269808
|
+
const { project } = await readProjectConfig();
|
|
269809
|
+
const configDir = dirname18(project.configPath);
|
|
269810
|
+
const authDir = join24(configDir, project.authDir);
|
|
269811
|
+
await runTask("Updating local auth config", async () => updateSSOConfig(authDir, provider, true));
|
|
269812
|
+
await runTask("Saving SSO credentials", async () => pushSSOSecrets(secrets));
|
|
269813
|
+
return {
|
|
269814
|
+
outroMessage: `SSO configured with ${provider} in local config. Run \`base44 auth push\` or \`base44 deploy\` to apply.`
|
|
269815
|
+
};
|
|
269916
269816
|
}
|
|
269917
|
-
|
|
269918
|
-
|
|
269919
|
-
|
|
269920
|
-
|
|
269921
|
-
|
|
269922
|
-
|
|
269923
|
-
|
|
269817
|
+
function hasEnableOnlyOptions(options) {
|
|
269818
|
+
return Boolean(options.provider || options.clientId || options.clientSecret || options.clientSecretStdin || options.envFile || options.file || options.scope || options.discoveryUrl || options.tenantId || options.oktaDomain || options.authEndpoint || options.tokenEndpoint || options.userinfoEndpoint || options.jwksUri || options.ssoName);
|
|
269819
|
+
}
|
|
269820
|
+
async function ssoDisableAction({ log, runTask }, options) {
|
|
269821
|
+
if (hasEnableOnlyOptions(options)) {
|
|
269822
|
+
throw new InvalidInputError("Configuration options cannot be used with disable. To disable SSO: base44 auth sso disable");
|
|
269823
|
+
}
|
|
269824
|
+
const { project } = await readProjectConfig();
|
|
269825
|
+
const configDir = dirname18(project.configPath);
|
|
269826
|
+
const authDir = join24(configDir, project.authDir);
|
|
269827
|
+
const updated = await runTask("Updating local auth config", async () => updateSSOConfig(authDir, null, false));
|
|
269828
|
+
await runTask("Removing SSO credentials", async () => deleteSSOSecrets());
|
|
269829
|
+
if (!hasAnyLoginMethod(updated)) {
|
|
269830
|
+
log.warn("Disabling SSO will leave no login methods enabled. Users will be locked out.");
|
|
269924
269831
|
}
|
|
269832
|
+
return {
|
|
269833
|
+
outroMessage: "SSO disabled in local config and credentials removed. Run `base44 auth push` or `base44 deploy` to apply."
|
|
269834
|
+
};
|
|
269925
269835
|
}
|
|
269926
|
-
async function
|
|
269927
|
-
|
|
269928
|
-
|
|
269929
|
-
response = await getAppClient().get("chat/full-conversation", {
|
|
269930
|
-
timeout: 30000,
|
|
269931
|
-
searchParams: { limit: String(limit), ...branchScope(branchId) }
|
|
269932
|
-
});
|
|
269933
|
-
} catch (error) {
|
|
269934
|
-
throw await ApiError.fromHttpError(error, "reading the conversation");
|
|
269836
|
+
async function ssoAction(context, action, options) {
|
|
269837
|
+
if (action === "disable") {
|
|
269838
|
+
return ssoDisableAction(context, options);
|
|
269935
269839
|
}
|
|
269936
|
-
return
|
|
269840
|
+
return ssoEnableAction(context, options);
|
|
269937
269841
|
}
|
|
269938
|
-
|
|
269939
|
-
|
|
269940
|
-
|
|
269842
|
+
function getSSOCommand() {
|
|
269843
|
+
return new Base44Command("sso").description("Configure SSO identity provider (google, microsoft, github, okta, custom). SSO and social login are mutually exclusive — enabling one disables the other in the local auth config.").addArgument(new Argument2("<action>", "enable or disable SSO").choices([
|
|
269844
|
+
"enable",
|
|
269845
|
+
"disable"
|
|
269846
|
+
])).addOption(new Option2("--provider <provider>", "SSO provider").choices(Object.values(KNOWN_SSO_PROVIDERS))).option("--client-id <id>", "OAuth client ID").option("--client-secret <secret>", "OAuth client secret").option("--client-secret-stdin", "Read client secret from stdin").option("--env-file <path>", "Read client secret from a .env file (key: sso_client_secret)").option("--file <path>", "JSON config file with all SSO settings").option("--scope <scope>", "OAuth scope (defaults per provider)").option("--discovery-url <url>", "OIDC discovery URL").option("--tenant-id <id>", "Microsoft tenant ID (required for microsoft)").option("--okta-domain <domain>", "Okta domain (required for okta)").option("--auth-endpoint <url>", "Authorization endpoint (required for custom)").option("--token-endpoint <url>", "Token endpoint (required for custom)").option("--userinfo-endpoint <url>", "Userinfo endpoint (required for custom)").option("--jwks-uri <url>", "JWKS URI (required for custom)").option("--sso-name <name>", "Provider display name (required for custom)").action(ssoAction);
|
|
269941
269847
|
}
|
|
269942
|
-
|
|
269943
|
-
|
|
269944
|
-
|
|
269945
|
-
|
|
269946
|
-
timeout: false
|
|
269947
|
-
});
|
|
269948
|
-
} catch (error) {
|
|
269949
|
-
throw await ApiError.fromHttpError(error, "fetching preview URL");
|
|
269950
|
-
}
|
|
269951
|
-
const url = parseOrThrow(PreviewUrlSchema, await response.json(), "preview URL").preview_url;
|
|
269952
|
-
return /^https?:\/\//.test(url) ? url : `https://${url}`;
|
|
269848
|
+
|
|
269849
|
+
// src/cli/commands/auth/index.ts
|
|
269850
|
+
function getAuthCommand() {
|
|
269851
|
+
return new Command2("auth").description("Manage app authentication settings").addCommand(getPasswordLoginCommand()).addCommand(getSocialLoginCommand()).addCommand(getSSOCommand()).addCommand(getAuthPullCommand()).addCommand(getAuthPushCommand());
|
|
269953
269852
|
}
|
|
269954
269853
|
|
|
269955
|
-
// src/cli/commands/
|
|
269956
|
-
|
|
269957
|
-
|
|
269958
|
-
|
|
269959
|
-
|
|
269960
|
-
"
|
|
269961
|
-
"tidy-maple",
|
|
269962
|
-
"brisk-panda"
|
|
269963
|
-
];
|
|
269964
|
-
function inventAppName(prompt) {
|
|
269965
|
-
const suffix = Math.random().toString(36).slice(2, 5);
|
|
269966
|
-
const words = (prompt ?? "").toLowerCase().match(/[a-z0-9]+/g)?.filter((w) => w.length > 2 && !NAME_STOPWORDS.has(w)).slice(0, 3) ?? [];
|
|
269967
|
-
const core = words.length ? words.join("-") : FALLBACK_WORDS[Math.floor(Math.random() * FALLBACK_WORDS.length)];
|
|
269968
|
-
return `base44-${core}-${suffix}`.slice(0, 60);
|
|
269854
|
+
// src/cli/commands/auth/login.ts
|
|
269855
|
+
function getLoginCommand() {
|
|
269856
|
+
return new Base44Command("login", {
|
|
269857
|
+
requireAuth: false,
|
|
269858
|
+
requireAppContext: false
|
|
269859
|
+
}).description("Authenticate with Base44").action(login);
|
|
269969
269860
|
}
|
|
269970
|
-
|
|
269971
|
-
|
|
269861
|
+
|
|
269862
|
+
// src/cli/commands/auth/logout.ts
|
|
269863
|
+
async function logout(_ctx) {
|
|
269864
|
+
await deleteAuth();
|
|
269865
|
+
return { outroMessage: "Logged out successfully" };
|
|
269972
269866
|
}
|
|
269973
|
-
|
|
269974
|
-
|
|
269975
|
-
|
|
269976
|
-
|
|
269977
|
-
|
|
269978
|
-
|
|
269979
|
-
|
|
269980
|
-
|
|
269981
|
-
|
|
269867
|
+
function getLogoutCommand() {
|
|
269868
|
+
return new Base44Command("logout", {
|
|
269869
|
+
requireAuth: false,
|
|
269870
|
+
requireAppContext: false
|
|
269871
|
+
}).description("Logout from current device").action(logout);
|
|
269872
|
+
}
|
|
269873
|
+
|
|
269874
|
+
// src/cli/commands/auth/whoami.ts
|
|
269875
|
+
async function whoami(_ctx) {
|
|
269876
|
+
const workspaceApiKey = getWorkspaceApiKeyFromEnv();
|
|
269877
|
+
if (workspaceApiKey && isWorkspaceApiKey(workspaceApiKey)) {
|
|
269878
|
+
return {
|
|
269879
|
+
outroMessage: `Using workspace API key: ${theme.styles.bold(workspaceApiKey.slice(0, 10))}`
|
|
269880
|
+
};
|
|
269982
269881
|
}
|
|
269983
|
-
const
|
|
269984
|
-
|
|
269985
|
-
repoUrl: options.importRepo,
|
|
269986
|
-
sourceMode: options.mode ?? "direct",
|
|
269987
|
-
newRepoName: options.repoName,
|
|
269988
|
-
branch: options.fromBranch,
|
|
269989
|
-
prompt: options.prompt
|
|
269990
|
-
}) : await createApp({ appName: name, prompt: options.prompt });
|
|
269991
|
-
await writeAppConfig(targetDir, created.id);
|
|
269992
|
-
await mkdir3(join21(targetDir, "base44"), { recursive: true });
|
|
269993
|
-
try {
|
|
269994
|
-
await writeFile2(join21(targetDir, "base44", "config.jsonc"), `// Base44 project configuration.
|
|
269995
|
-
{
|
|
269996
|
-
"name": ${JSON.stringify(name)}
|
|
269882
|
+
const auth = await readAuth();
|
|
269883
|
+
return { outroMessage: `Logged in as: ${theme.styles.bold(auth.email)}` };
|
|
269997
269884
|
}
|
|
269998
|
-
|
|
269999
|
-
|
|
270000
|
-
setAppContext({ id: created.id, projectRoot: targetDir });
|
|
270001
|
-
return {
|
|
270002
|
-
id: created.id,
|
|
270003
|
-
editorUrl: `${getBase44ApiUrl()}/apps/${created.id}/editor/preview`,
|
|
270004
|
-
repoUrl: created.imported_repo_url ?? undefined,
|
|
270005
|
-
dirName: name,
|
|
270006
|
-
targetDir
|
|
270007
|
-
};
|
|
269885
|
+
function getWhoamiCommand() {
|
|
269886
|
+
return new Base44Command("whoami", { requireAppContext: false }).description("Display current authenticated user").action(whoami);
|
|
270008
269887
|
}
|
|
270009
|
-
|
|
270010
|
-
|
|
270011
|
-
|
|
270012
|
-
|
|
270013
|
-
|
|
270014
|
-
|
|
270015
|
-
|
|
269888
|
+
|
|
269889
|
+
// src/cli/commands/branches/index.ts
|
|
269890
|
+
async function listBranchesAction({
|
|
269891
|
+
log,
|
|
269892
|
+
runTask,
|
|
269893
|
+
jsonMode
|
|
269894
|
+
}) {
|
|
269895
|
+
const remote = await runTask("Fetching branches", () => listBranches());
|
|
269896
|
+
const branches = [
|
|
269897
|
+
{ name: "main", status: "active" },
|
|
269898
|
+
...remote.map((branch) => ({
|
|
269899
|
+
name: branch.branch_name,
|
|
269900
|
+
status: branch.status
|
|
269901
|
+
}))
|
|
270016
269902
|
];
|
|
269903
|
+
if (jsonMode)
|
|
269904
|
+
return { stdout: `${JSON.stringify({ branches })}
|
|
269905
|
+
` };
|
|
269906
|
+
for (const branch of branches)
|
|
269907
|
+
log.message(`${branch.name} (${branch.status})`);
|
|
269908
|
+
return { outroMessage: `${branches.length} branches` };
|
|
270017
269909
|
}
|
|
270018
|
-
|
|
270019
|
-
return
|
|
270020
|
-
return;
|
|
270021
|
-
});
|
|
269910
|
+
function getBranchesCommand() {
|
|
269911
|
+
return new Command2("branches").description("Discover an app's branches").addCommand(new Base44Command("list").description("List main and active branch names for use with --branch").action(listBranchesAction));
|
|
270022
269912
|
}
|
|
270023
269913
|
|
|
270024
|
-
// src/core/
|
|
270025
|
-
|
|
270026
|
-
|
|
270027
|
-
|
|
270028
|
-
|
|
270029
|
-
|
|
270030
|
-
|
|
270031
|
-
|
|
270032
|
-
|
|
269914
|
+
// src/core/model.ts
|
|
269915
|
+
var MODELS = [
|
|
269916
|
+
{
|
|
269917
|
+
name: "Automatic",
|
|
269918
|
+
id: null,
|
|
269919
|
+
note: "matched with the best model",
|
|
269920
|
+
aliases: ["default", "auto"]
|
|
269921
|
+
},
|
|
269922
|
+
{ name: "Opus 5", id: "claude_opus_5" },
|
|
269923
|
+
{ name: "Sonnet 5", id: "claude-sonnet-5" },
|
|
269924
|
+
{ name: "Fable 5", id: "claude_fable_5", note: "uses more credits" },
|
|
269925
|
+
{ name: "GPT-5.6 Sol", id: "gpt_5_6_sol" },
|
|
269926
|
+
{
|
|
269927
|
+
name: "Gemini 3.8 Flash",
|
|
269928
|
+
id: "gemini_3_8_flash",
|
|
269929
|
+
note: "fast responses for everyday tasks"
|
|
269930
|
+
},
|
|
269931
|
+
{ name: "Base 1", id: "base1" }
|
|
269932
|
+
];
|
|
269933
|
+
var fold = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
269934
|
+
function resolvePick(input) {
|
|
269935
|
+
const key = fold(input);
|
|
269936
|
+
const byExact = MODELS.find((m) => fold(m.name) === key || m.id && fold(m.id) === key || m.aliases?.some((a) => fold(a) === key));
|
|
269937
|
+
if (byExact)
|
|
269938
|
+
return byExact;
|
|
269939
|
+
const byContains = MODELS.filter((m) => fold(m.name).includes(key) || m.id && fold(m.id).includes(key));
|
|
269940
|
+
if (byContains.length === 1)
|
|
269941
|
+
return byContains[0];
|
|
269942
|
+
const names = MODELS.map((m) => m.name).join(", ");
|
|
269943
|
+
throw new InvalidInputError(byContains.length > 1 ? `"${input}" is ambiguous — matches ${byContains.map((m) => m.name).join(", ")}.` : `Unknown model "${input}". Choose one of: ${names}.`);
|
|
270033
269944
|
}
|
|
270034
|
-
|
|
270035
|
-
|
|
270036
|
-
|
|
270037
|
-
|
|
270038
|
-
|
|
270039
|
-
return match[1].replace(/\\(.)/g, "$1");
|
|
269945
|
+
async function getMe() {
|
|
269946
|
+
try {
|
|
269947
|
+
return await base44Client.get("api/auth/me").json();
|
|
269948
|
+
} catch (error) {
|
|
269949
|
+
throw await ApiError.fromHttpError(error, "reading your account");
|
|
270040
269950
|
}
|
|
270041
|
-
return;
|
|
270042
269951
|
}
|
|
270043
|
-
function
|
|
270044
|
-
const raw = argumentsString ?? "";
|
|
270045
|
-
let args = {};
|
|
269952
|
+
async function saveBuilderModel(userId, modelId) {
|
|
270046
269953
|
try {
|
|
270047
|
-
|
|
270048
|
-
|
|
270049
|
-
|
|
269954
|
+
await base44Client.post(`api/auth/${userId}/update-user`, {
|
|
269955
|
+
json: { builder_model: modelId }
|
|
269956
|
+
});
|
|
269957
|
+
} catch (error) {
|
|
269958
|
+
if (error instanceof HTTPError && error.response.status === 400) {
|
|
269959
|
+
throw new InvalidInputError("This account can't pick a builder model yet — enable the PER_USER_BUILDER_MODEL_SELECTION flag for it in PostHog, or the model isn't available in this workspace.");
|
|
269960
|
+
}
|
|
269961
|
+
throw await ApiError.fromHttpError(error, "saving your model choice");
|
|
269962
|
+
}
|
|
269963
|
+
}
|
|
269964
|
+
var displayName = (id) => MODELS.find((m) => m.id === id)?.name ?? id ?? "Automatic";
|
|
269965
|
+
|
|
269966
|
+
// src/cli/commands/builder/model.ts
|
|
269967
|
+
async function modelAction({ log, jsonMode }, input) {
|
|
269968
|
+
const me = await getMe();
|
|
269969
|
+
const current = me.builder_model ?? null;
|
|
269970
|
+
if (!input) {
|
|
269971
|
+
if (jsonMode) {
|
|
269972
|
+
return {
|
|
269973
|
+
stdout: `${JSON.stringify({
|
|
269974
|
+
current,
|
|
269975
|
+
models: MODELS.map((m) => ({ name: m.name, id: m.id }))
|
|
269976
|
+
})}
|
|
269977
|
+
`
|
|
269978
|
+
};
|
|
269979
|
+
}
|
|
269980
|
+
for (const m of MODELS) {
|
|
269981
|
+
const active = (m.id ?? null) === current;
|
|
269982
|
+
const marker = active ? theme.styles.bold("●") : theme.styles.dim("○");
|
|
269983
|
+
const note = m.note ? theme.styles.dim(` (${m.note})`) : "";
|
|
269984
|
+
log.message(`${marker} ${active ? theme.styles.bold(m.name) : m.name}${note}`);
|
|
270050
269985
|
}
|
|
270051
|
-
} catch {
|
|
270052
269986
|
return {
|
|
270053
|
-
|
|
270054
|
-
summary: oneLine(salvageKey(raw, SALIENT_KEYS) ?? raw, 90)
|
|
269987
|
+
outroMessage: `Current: ${theme.styles.bold(displayName(current))}. Set with \`base44 builder model <name>\`.`
|
|
270055
269988
|
};
|
|
270056
269989
|
}
|
|
270057
|
-
const pick = (
|
|
270058
|
-
|
|
270059
|
-
|
|
270060
|
-
|
|
270061
|
-
|
|
270062
|
-
|
|
270063
|
-
|
|
270064
|
-
|
|
270065
|
-
};
|
|
270066
|
-
const summary = salient[name] ?? Object.entries(args).find(([key, v]) => key !== "summary" && typeof v === "string" && v.trim().length > 0)?.[1] ?? "";
|
|
269990
|
+
const pick = resolvePick(input);
|
|
269991
|
+
if ((pick.id ?? null) === current) {
|
|
269992
|
+
return { outroMessage: `Already on ${theme.styles.bold(pick.name)}.` };
|
|
269993
|
+
}
|
|
269994
|
+
await saveBuilderModel(me.id, pick.id);
|
|
269995
|
+
if (jsonMode)
|
|
269996
|
+
return { stdout: `${JSON.stringify({ current: pick.id })}
|
|
269997
|
+
` };
|
|
270067
269998
|
return {
|
|
270068
|
-
|
|
270069
|
-
summary: oneLine(summary, 90)
|
|
269999
|
+
outroMessage: pick.id === null ? "Model reset — Base44 chooses per app again." : `Builder model set to ${theme.styles.bold(pick.name)} for every new turn.`
|
|
270070
270000
|
};
|
|
270071
270001
|
}
|
|
270072
|
-
function
|
|
270073
|
-
const
|
|
270074
|
-
|
|
270075
|
-
|
|
270076
|
-
return tense === "running" ? parts[0] : parts[1];
|
|
270002
|
+
function getModelCommand() {
|
|
270003
|
+
const command = new Base44Command("model", { requireAppContext: false });
|
|
270004
|
+
command.description("Pick the builder model for your turns (account-wide). No argument lists models and the current pick; `default` clears it").argument("[model]", 'Model name or id, e.g. "Opus 5" or default').action(modelAction);
|
|
270005
|
+
return command;
|
|
270077
270006
|
}
|
|
270078
|
-
|
|
270079
|
-
|
|
270080
|
-
|
|
270081
|
-
|
|
270082
|
-
|
|
270083
|
-
|
|
270084
|
-
|
|
270085
|
-
|
|
270086
|
-
|
|
270087
|
-
|
|
270088
|
-
|
|
270089
|
-
|
|
270090
|
-
|
|
270007
|
+
|
|
270008
|
+
// src/cli/commands/builder/shared.ts
|
|
270009
|
+
import { mkdir as mkdir3, writeFile as writeFile2 } from "node:fs/promises";
|
|
270010
|
+
import { basename as basename6, join as join25, relative as relative6, resolve as resolve8 } from "node:path";
|
|
270011
|
+
|
|
270012
|
+
// src/cli/commands/code/render.ts
|
|
270013
|
+
var TOOL_ALIASES = {
|
|
270014
|
+
run_shell_command: "bash",
|
|
270015
|
+
read_repo_file: "read",
|
|
270016
|
+
write_repo_file: "write",
|
|
270017
|
+
edit_repo_file: "edit",
|
|
270018
|
+
set_secrets: "secrets",
|
|
270019
|
+
generate_development_secrets: "secrets",
|
|
270020
|
+
create_pull_request: "pr",
|
|
270021
|
+
merge_pull_request: "merge",
|
|
270022
|
+
list_pr_threads: "pr threads",
|
|
270023
|
+
reply_to_pr_thread: "pr reply",
|
|
270024
|
+
comment_on_pr: "pr comment",
|
|
270025
|
+
resolve_pr_thread: "pr resolve",
|
|
270026
|
+
reload_preview: "reload",
|
|
270027
|
+
preview_execute_code: "preview js",
|
|
270028
|
+
preview_screenshot: "screenshot",
|
|
270029
|
+
connect_github_account: "github"
|
|
270030
|
+
};
|
|
270031
|
+
var QUIET_OK_RESULTS = new Set(["read", "write", "edit", "reload"]);
|
|
270032
|
+
function toolAlias(name) {
|
|
270033
|
+
return TOOL_ALIASES[name] ?? name;
|
|
270091
270034
|
}
|
|
270092
|
-
|
|
270093
|
-
|
|
270094
|
-
|
|
270095
|
-
|
|
270096
|
-
|
|
270097
|
-
|
|
270098
|
-
|
|
270099
|
-
|
|
270100
|
-
|
|
270101
|
-
|
|
270102
|
-
|
|
270103
|
-
|
|
270104
|
-
}
|
|
270105
|
-
|
|
270106
|
-
|
|
270107
|
-
|
|
270108
|
-
|
|
270109
|
-
|
|
270110
|
-
|
|
270111
|
-
|
|
270112
|
-
|
|
270113
|
-
|
|
270114
|
-
|
|
270115
|
-
|
|
270116
|
-
|
|
270117
|
-
|
|
270118
|
-
|
|
270119
|
-
|
|
270120
|
-
|
|
270121
|
-
|
|
270122
|
-
|
|
270123
|
-
|
|
270124
|
-
|
|
270125
|
-
|
|
270126
|
-
|
|
270127
|
-
|
|
270128
|
-
|
|
270129
|
-
|
|
270130
|
-
|
|
270131
|
-
|
|
270132
|
-
|
|
270035
|
+
var ESC_CHAR = String.fromCharCode(27);
|
|
270036
|
+
var BEL = String.fromCharCode(7);
|
|
270037
|
+
var OSC8_CLOSE = `${ESC_CHAR}]8;;${BEL}`;
|
|
270038
|
+
function terminalLink(label, url) {
|
|
270039
|
+
return `${ESC_CHAR}]8;;${url}${BEL}${source_default.dim.underline(label)}${OSC8_CLOSE}`;
|
|
270040
|
+
}
|
|
270041
|
+
function linkifyUrls(text) {
|
|
270042
|
+
let n = 0;
|
|
270043
|
+
return text.replace(/https?:\/\/[^\s]+/g, (raw) => {
|
|
270044
|
+
const trailing = raw.match(/[.,;:!?)\]}'"]+$/)?.[0] ?? "";
|
|
270045
|
+
const url = trailing ? raw.slice(0, -trailing.length) : raw;
|
|
270046
|
+
const id = `b44-${n++}`;
|
|
270047
|
+
return `${ESC_CHAR}]8;id=${id};${url}${BEL}${url}${OSC8_CLOSE}${trailing}`;
|
|
270048
|
+
});
|
|
270049
|
+
}
|
|
270050
|
+
function hardWrapAnsi(text, width) {
|
|
270051
|
+
const ESC = new RegExp(`^(?:${ESC_CHAR}\\[[0-9;]*m|${ESC_CHAR}\\]8;[^${BEL}]*${BEL})`);
|
|
270052
|
+
const RESET = `${ESC_CHAR}[0m`;
|
|
270053
|
+
const out = [];
|
|
270054
|
+
for (const logical of text.split(`
|
|
270055
|
+
`)) {
|
|
270056
|
+
let line = "";
|
|
270057
|
+
let visible = 0;
|
|
270058
|
+
let active = [];
|
|
270059
|
+
let link = "";
|
|
270060
|
+
let i = 0;
|
|
270061
|
+
while (i < logical.length) {
|
|
270062
|
+
const esc = ESC.exec(logical.slice(i));
|
|
270063
|
+
if (esc) {
|
|
270064
|
+
const seq = esc[0];
|
|
270065
|
+
line += seq;
|
|
270066
|
+
if (seq === RESET)
|
|
270067
|
+
active = [];
|
|
270068
|
+
else if (seq.endsWith("m"))
|
|
270069
|
+
active.push(seq);
|
|
270070
|
+
else if (seq === OSC8_CLOSE)
|
|
270071
|
+
link = "";
|
|
270072
|
+
else
|
|
270073
|
+
link = seq;
|
|
270074
|
+
i += seq.length;
|
|
270075
|
+
continue;
|
|
270133
270076
|
}
|
|
270134
|
-
if (
|
|
270135
|
-
|
|
270136
|
-
|
|
270137
|
-
|
|
270138
|
-
kind: "tool_end",
|
|
270139
|
-
id: tool.id,
|
|
270140
|
-
name: tool.name,
|
|
270141
|
-
label: labelTense(meta.label, "done"),
|
|
270142
|
-
summary: meta.summary,
|
|
270143
|
-
ok: status === "success",
|
|
270144
|
-
result: oneLine(tool.results, 110)
|
|
270145
|
-
});
|
|
270077
|
+
if (visible >= width) {
|
|
270078
|
+
out.push(`${line}${link ? OSC8_CLOSE : ""}${RESET}`);
|
|
270079
|
+
line = active.join("") + link;
|
|
270080
|
+
visible = 0;
|
|
270146
270081
|
}
|
|
270082
|
+
line += logical[i];
|
|
270083
|
+
visible++;
|
|
270084
|
+
i++;
|
|
270147
270085
|
}
|
|
270086
|
+
out.push(line);
|
|
270148
270087
|
}
|
|
270149
|
-
return
|
|
270088
|
+
return out;
|
|
270150
270089
|
}
|
|
270151
|
-
function
|
|
270152
|
-
|
|
270090
|
+
function formatDuration2(ms) {
|
|
270091
|
+
const seconds = Math.round(ms / 1000);
|
|
270092
|
+
if (seconds < 90)
|
|
270093
|
+
return `${seconds}s`;
|
|
270094
|
+
return `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
270153
270095
|
}
|
|
270154
|
-
function
|
|
270155
|
-
|
|
270156
|
-
|
|
270157
|
-
|
|
270158
|
-
|
|
270159
|
-
|
|
270160
|
-
|
|
270161
|
-
|
|
270162
|
-
|
|
270163
|
-
|
|
270164
|
-
};
|
|
270096
|
+
function eventLine(event, elapsedMs) {
|
|
270097
|
+
switch (event.kind) {
|
|
270098
|
+
case "thinking":
|
|
270099
|
+
return source_default.dim(`✻ ${event.text}`);
|
|
270100
|
+
case "text":
|
|
270101
|
+
return linkifyUrls(event.text);
|
|
270102
|
+
case "tool_start":
|
|
270103
|
+
return null;
|
|
270104
|
+
case "waiting": {
|
|
270105
|
+
const what = event.label || toolAlias(event.name);
|
|
270106
|
+
return source_default.yellow(`⏸ ${what} — needs your input (answer in the editor)`);
|
|
270165
270107
|
}
|
|
270166
|
-
|
|
270167
|
-
|
|
270168
|
-
|
|
270169
|
-
|
|
270170
|
-
|
|
270171
|
-
|
|
270172
|
-
|
|
270173
|
-
|
|
270174
|
-
const
|
|
270175
|
-
|
|
270176
|
-
|
|
270177
|
-
|
|
270178
|
-
|
|
270179
|
-
return
|
|
270180
|
-
|
|
270181
|
-
return [];
|
|
270108
|
+
case "tool_end": {
|
|
270109
|
+
const alias = toolAlias(event.name);
|
|
270110
|
+
const mark = event.ok ? source_default.green("✓") : source_default.red("✗");
|
|
270111
|
+
const title = source_default.bold(event.label || alias);
|
|
270112
|
+
const took = elapsedMs != null && elapsedMs >= 3000 ? ` ${source_default.dim(`· ${formatDuration2(elapsedMs)}`)}` : "";
|
|
270113
|
+
const inlineDetail = !event.label && event.summary ? ` ${source_default.dim(event.summary)}` : "";
|
|
270114
|
+
const paramsLine = event.label && event.summary ? `
|
|
270115
|
+
${source_default.dim(`${alias}: ${event.summary}`)}` : "";
|
|
270116
|
+
const head = `${mark} ${title}${inlineDetail}${took}${paramsLine}`;
|
|
270117
|
+
if (event.ok && (QUIET_OK_RESULTS.has(alias) || !event.result)) {
|
|
270118
|
+
return head;
|
|
270119
|
+
}
|
|
270120
|
+
const result = event.ok ? source_default.dim(linkifyUrls(event.result)) : source_default.red(linkifyUrls(event.result));
|
|
270121
|
+
return `${head}${event.result ? `
|
|
270122
|
+
${result}` : ""}`;
|
|
270182
270123
|
}
|
|
270183
|
-
};
|
|
270184
|
-
}
|
|
270185
|
-
async function streamConversationDuring(start, onEvent, options = {}) {
|
|
270186
|
-
const intervalMs = options.intervalMs ?? 1000;
|
|
270187
|
-
const poll = makePoller(onEvent, options);
|
|
270188
|
-
await poll(true);
|
|
270189
|
-
const work = start();
|
|
270190
|
-
let pending = true;
|
|
270191
|
-
const settled = work.then(() => {
|
|
270192
|
-
pending = false;
|
|
270193
|
-
}, () => {
|
|
270194
|
-
pending = false;
|
|
270195
|
-
});
|
|
270196
|
-
while (pending) {
|
|
270197
|
-
await Promise.race([sleep3(intervalMs), settled]);
|
|
270198
|
-
if (!pending)
|
|
270199
|
-
break;
|
|
270200
|
-
await poll();
|
|
270201
270124
|
}
|
|
270202
|
-
await poll();
|
|
270203
|
-
return work;
|
|
270204
270125
|
}
|
|
270205
|
-
|
|
270206
|
-
|
|
270207
|
-
|
|
270208
|
-
|
|
270209
|
-
|
|
270210
|
-
|
|
270211
|
-
|
|
270212
|
-
|
|
270213
|
-
|
|
270214
|
-
|
|
270215
|
-
|
|
270126
|
+
var FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
270127
|
+
var MUSINGS = [
|
|
270128
|
+
"Shmoozing",
|
|
270129
|
+
"Shmoogling",
|
|
270130
|
+
"Percolating",
|
|
270131
|
+
"Noodling",
|
|
270132
|
+
"Marinating",
|
|
270133
|
+
"Brewing",
|
|
270134
|
+
"Simmering",
|
|
270135
|
+
"Conjuring",
|
|
270136
|
+
"Tinkering",
|
|
270137
|
+
"Scheming",
|
|
270138
|
+
"Pondering",
|
|
270139
|
+
"Mulling",
|
|
270140
|
+
"Whirring",
|
|
270141
|
+
"Crunching",
|
|
270142
|
+
"Weaving",
|
|
270143
|
+
"Sketching",
|
|
270144
|
+
"Hatching",
|
|
270145
|
+
"Riffing",
|
|
270146
|
+
"Cooking",
|
|
270147
|
+
"Composting ideas",
|
|
270148
|
+
"Rummaging",
|
|
270149
|
+
"Vibing responsibly",
|
|
270150
|
+
"Untangling",
|
|
270151
|
+
"Squinting at the repo"
|
|
270152
|
+
];
|
|
270153
|
+
var MUSING_ROTATE_MS = 6000;
|
|
270154
|
+
function idleMusing(seed) {
|
|
270155
|
+
return `${MUSINGS[(seed + Math.floor(Date.now() / MUSING_ROTATE_MS)) % MUSINGS.length]}…`;
|
|
270216
270156
|
}
|
|
270217
|
-
|
|
270218
|
-
|
|
270219
|
-
|
|
270220
|
-
|
|
270221
|
-
|
|
270222
|
-
|
|
270223
|
-
|
|
270224
|
-
|
|
270225
|
-
|
|
270226
|
-
|
|
270227
|
-
|
|
270228
|
-
|
|
270229
|
-
|
|
270230
|
-
|
|
270231
|
-
|
|
270232
|
-
|
|
270233
|
-
|
|
270234
|
-
|
|
270235
|
-
|
|
270236
|
-
|
|
270237
|
-
|
|
270238
|
-
|
|
270239
|
-
fromBranch: options.fromBranch
|
|
270240
|
-
}));
|
|
270241
|
-
} catch (error) {
|
|
270242
|
-
for (const line of await githubReauthLines(error) ?? [])
|
|
270243
|
-
log.message(line);
|
|
270244
|
-
throw error;
|
|
270245
|
-
}
|
|
270246
|
-
if (!jsonMode) {
|
|
270247
|
-
if (app.repoUrl)
|
|
270248
|
-
log.message(source_default.dim(`repo ${app.repoUrl}`));
|
|
270249
|
-
log.message(source_default.dim(`editor ${app.editorUrl}`));
|
|
270250
|
-
log.message(source_default.dim(`linked ./${app.dirName}`));
|
|
270251
|
-
}
|
|
270252
|
-
let finalState;
|
|
270253
|
-
let previewUrl;
|
|
270254
|
-
const startedAt = Date.now();
|
|
270255
|
-
if (prompt) {
|
|
270256
|
-
const branchId = await resolveActiveBranchId().catch(() => {
|
|
270157
|
+
function createTurnStream(interactive, write = (text) => process.stdout.write(text), options = {}) {
|
|
270158
|
+
const running = new Map;
|
|
270159
|
+
const footer = options.footer ?? [];
|
|
270160
|
+
let frame = 0;
|
|
270161
|
+
let stopped = false;
|
|
270162
|
+
let drawnLines = 0;
|
|
270163
|
+
const musingSeed = Math.floor(Math.random() * MUSINGS.length);
|
|
270164
|
+
const statusLabel = () => {
|
|
270165
|
+
if (running.size === 0) {
|
|
270166
|
+
if (options.idleLabel)
|
|
270167
|
+
return `${options.idleLabel}…`;
|
|
270168
|
+
const index = (musingSeed + Math.floor(Date.now() / MUSING_ROTATE_MS)) % MUSINGS.length;
|
|
270169
|
+
return `${MUSINGS[index]}…`;
|
|
270170
|
+
}
|
|
270171
|
+
const newest = [...running.values()].at(-1);
|
|
270172
|
+
const elapsed = Math.round((Date.now() - newest.startedAt) / 1000);
|
|
270173
|
+
const others = running.size > 1 ? ` (+${running.size - 1} more)` : "";
|
|
270174
|
+
const what = newest.label || `${newest.alias}${newest.summary ? ` ${newest.summary}` : ""}`;
|
|
270175
|
+
return `${what}${others} · ${elapsed}s`;
|
|
270176
|
+
};
|
|
270177
|
+
const clearBlock = () => {
|
|
270178
|
+
if (!drawnLines)
|
|
270257
270179
|
return;
|
|
270258
|
-
|
|
270259
|
-
|
|
270260
|
-
|
|
270261
|
-
|
|
270262
|
-
|
|
270263
|
-
|
|
270264
|
-
|
|
270265
|
-
|
|
270266
|
-
|
|
270267
|
-
|
|
270268
|
-
|
|
270180
|
+
write("\r\x1B[2K");
|
|
270181
|
+
for (let i = 1;i < drawnLines; i++)
|
|
270182
|
+
write("\x1B[1A\r\x1B[2K");
|
|
270183
|
+
drawnLines = 0;
|
|
270184
|
+
};
|
|
270185
|
+
const drawBlock = () => {
|
|
270186
|
+
if (!interactive || stopped)
|
|
270187
|
+
return;
|
|
270188
|
+
const lines = [
|
|
270189
|
+
...footer.length ? ["", ...footer] : [],
|
|
270190
|
+
source_default.dim(`${FRAMES[frame]} ${statusLabel()}`)
|
|
270191
|
+
];
|
|
270192
|
+
write(lines.join(`
|
|
270193
|
+
`));
|
|
270194
|
+
drawnLines = lines.length;
|
|
270195
|
+
};
|
|
270196
|
+
const tick = () => {
|
|
270197
|
+
if (!interactive || stopped)
|
|
270198
|
+
return;
|
|
270199
|
+
frame = (frame + 1) % FRAMES.length;
|
|
270200
|
+
clearBlock();
|
|
270201
|
+
drawBlock();
|
|
270202
|
+
};
|
|
270203
|
+
const timer = interactive ? setInterval(tick, 120) : null;
|
|
270204
|
+
if (timer)
|
|
270205
|
+
timer.unref?.();
|
|
270206
|
+
return {
|
|
270207
|
+
onEvent(event) {
|
|
270208
|
+
if (event.kind === "tool_start") {
|
|
270209
|
+
running.set(event.id, {
|
|
270210
|
+
alias: toolAlias(event.name),
|
|
270211
|
+
label: event.label,
|
|
270212
|
+
summary: event.summary,
|
|
270213
|
+
startedAt: Date.now()
|
|
270269
270214
|
});
|
|
270215
|
+
if (interactive) {
|
|
270216
|
+
clearBlock();
|
|
270217
|
+
drawBlock();
|
|
270218
|
+
}
|
|
270219
|
+
return;
|
|
270270
270220
|
}
|
|
270271
|
-
|
|
270272
|
-
|
|
270221
|
+
let elapsedMs;
|
|
270222
|
+
if (event.kind === "tool_end") {
|
|
270223
|
+
const started = running.get(event.id)?.startedAt;
|
|
270224
|
+
if (started != null)
|
|
270225
|
+
elapsedMs = Date.now() - started;
|
|
270226
|
+
running.delete(event.id);
|
|
270227
|
+
}
|
|
270228
|
+
const line = eventLine(event, elapsedMs);
|
|
270229
|
+
if (line == null)
|
|
270230
|
+
return;
|
|
270231
|
+
if (interactive) {
|
|
270232
|
+
clearBlock();
|
|
270233
|
+
write(`${line}
|
|
270234
|
+
`);
|
|
270235
|
+
drawBlock();
|
|
270236
|
+
} else {
|
|
270237
|
+
write(`${line}
|
|
270238
|
+
`);
|
|
270239
|
+
}
|
|
270240
|
+
},
|
|
270241
|
+
stop() {
|
|
270242
|
+
if (interactive) {
|
|
270243
|
+
clearBlock();
|
|
270244
|
+
if (footer.length)
|
|
270245
|
+
write(`
|
|
270246
|
+
${footer.join(`
|
|
270247
|
+
`)}
|
|
270248
|
+
`);
|
|
270249
|
+
}
|
|
270250
|
+
stopped = true;
|
|
270251
|
+
if (timer)
|
|
270252
|
+
clearInterval(timer);
|
|
270273
270253
|
}
|
|
270254
|
+
};
|
|
270255
|
+
}
|
|
270256
|
+
|
|
270257
|
+
// src/core/resources/apps/api.ts
|
|
270258
|
+
var CreatedAppSchema = object({
|
|
270259
|
+
id: string2().min(1),
|
|
270260
|
+
name: string2().nullish(),
|
|
270261
|
+
imported_repo_url: string2().nullish()
|
|
270262
|
+
});
|
|
270263
|
+
var AppStateSchema = object({
|
|
270264
|
+
id: string2(),
|
|
270265
|
+
app_type: string2().nullish(),
|
|
270266
|
+
is_managed_source_code: boolean2().nullish(),
|
|
270267
|
+
imported_repo_url: string2().nullish(),
|
|
270268
|
+
status: object({
|
|
270269
|
+
state: string2().nullish(),
|
|
270270
|
+
message: string2().nullish()
|
|
270271
|
+
}).nullish()
|
|
270272
|
+
});
|
|
270273
|
+
var ChatTurnSchema = object({
|
|
270274
|
+
queued: boolean2().optional(),
|
|
270275
|
+
status: object({
|
|
270276
|
+
state: string2().nullish(),
|
|
270277
|
+
message: string2().nullish(),
|
|
270278
|
+
error_source: string2().nullish()
|
|
270279
|
+
}).nullish(),
|
|
270280
|
+
conversation: object({
|
|
270281
|
+
messages: array(object({
|
|
270282
|
+
role: string2().nullish(),
|
|
270283
|
+
content: unknown().nullish()
|
|
270284
|
+
})).nullish()
|
|
270285
|
+
}).nullish()
|
|
270286
|
+
});
|
|
270287
|
+
var PreviewUrlSchema = object({
|
|
270288
|
+
preview_url: string2().min(1)
|
|
270289
|
+
});
|
|
270290
|
+
var ConversationMessageSchema = object({
|
|
270291
|
+
id: string2(),
|
|
270292
|
+
role: string2(),
|
|
270293
|
+
hidden: boolean2().nullish(),
|
|
270294
|
+
outcome: unknown().nullish(),
|
|
270295
|
+
content: unknown().nullish(),
|
|
270296
|
+
reasoning: object({ content: string2().nullish() }).nullish(),
|
|
270297
|
+
tool_calls: array(object({
|
|
270298
|
+
id: string2(),
|
|
270299
|
+
name: string2(),
|
|
270300
|
+
arguments_string: string2().nullish(),
|
|
270301
|
+
status: string2().nullish(),
|
|
270302
|
+
results: unknown().nullish()
|
|
270303
|
+
})).nullish()
|
|
270304
|
+
});
|
|
270305
|
+
var FullConversationSchema = object({
|
|
270306
|
+
messages: array(ConversationMessageSchema).default([])
|
|
270307
|
+
});
|
|
270308
|
+
var OAuthInitiateSchema = object({ authorization_url: string2().min(1) });
|
|
270309
|
+
function parseOrThrow(schema, payload, what) {
|
|
270310
|
+
const result = schema.safeParse(payload);
|
|
270311
|
+
if (!result.success) {
|
|
270312
|
+
throw new SchemaValidationError(`Invalid ${what} response from server`, result.error);
|
|
270274
270313
|
}
|
|
270275
|
-
|
|
270276
|
-
|
|
270277
|
-
|
|
270278
|
-
|
|
270279
|
-
|
|
270280
|
-
|
|
270281
|
-
|
|
270282
|
-
|
|
270283
|
-
|
|
270284
|
-
|
|
270285
|
-
|
|
270286
|
-
|
|
270287
|
-
|
|
270288
|
-
|
|
270289
|
-
|
|
270290
|
-
|
|
270291
|
-
|
|
270292
|
-
|
|
270293
|
-
};
|
|
270294
|
-
}
|
|
270295
|
-
if (finalState === "processing") {
|
|
270296
|
-
return {
|
|
270297
|
-
outroMessage: `Still building — follow it with \`base44 app status\`.${cd}`
|
|
270298
|
-
};
|
|
270314
|
+
return result.data;
|
|
270315
|
+
}
|
|
270316
|
+
function branchScope(branchId) {
|
|
270317
|
+
return branchId ? { branch_id: branchId } : {};
|
|
270318
|
+
}
|
|
270319
|
+
async function createApp(options) {
|
|
270320
|
+
let response;
|
|
270321
|
+
try {
|
|
270322
|
+
response = await base44Client.post("api/apps", {
|
|
270323
|
+
timeout: false,
|
|
270324
|
+
json: {
|
|
270325
|
+
...options.appName ? { name: options.appName } : {},
|
|
270326
|
+
...options.organizationId ? { organization_id: options.organizationId } : {},
|
|
270327
|
+
...options.prompt ? { initial_message: { content: options.prompt } } : {}
|
|
270328
|
+
}
|
|
270329
|
+
});
|
|
270330
|
+
} catch (error) {
|
|
270331
|
+
throw await ApiError.fromHttpError(error, "creating app");
|
|
270299
270332
|
}
|
|
270300
|
-
return
|
|
270301
|
-
outroMessage: prompt ? `First build finished · ${formatDuration2(Date.now() - startedAt)}.${cd}` : `App created.${cd}`
|
|
270302
|
-
};
|
|
270333
|
+
return parseOrThrow(CreatedAppSchema, await response.json(), "app");
|
|
270303
270334
|
}
|
|
270304
|
-
function
|
|
270305
|
-
|
|
270306
|
-
|
|
270307
|
-
|
|
270335
|
+
async function createImportedApp(options) {
|
|
270336
|
+
let response;
|
|
270337
|
+
try {
|
|
270338
|
+
response = await base44Client.post("api/apps", {
|
|
270339
|
+
timeout: false,
|
|
270340
|
+
json: {
|
|
270341
|
+
app_type: "imported_app",
|
|
270342
|
+
name: options.appName,
|
|
270343
|
+
imported_source_mode: options.sourceMode,
|
|
270344
|
+
imported_repo_url: options.repoUrl,
|
|
270345
|
+
...options.newRepoName ? { imported_new_repo_name: options.newRepoName } : {},
|
|
270346
|
+
...options.branch ? { imported_branch: options.branch } : {},
|
|
270347
|
+
...options.prompt ? { initial_message: { content: options.prompt } } : {}
|
|
270348
|
+
}
|
|
270349
|
+
});
|
|
270350
|
+
} catch (error) {
|
|
270351
|
+
throw await ApiError.fromHttpError(error, "importing repository");
|
|
270352
|
+
}
|
|
270353
|
+
return parseOrThrow(CreatedAppSchema, await response.json(), "app");
|
|
270308
270354
|
}
|
|
270309
|
-
|
|
270310
|
-
|
|
270311
|
-
|
|
270312
|
-
const url = await ctx.runTask("Resolving preview URL (boots the sandbox if needed)", () => getPreviewUrl());
|
|
270313
|
-
if (ctx.jsonMode)
|
|
270314
|
-
return { stdout: `${JSON.stringify({ preview_url: url })}
|
|
270315
|
-
` };
|
|
270316
|
-
ctx.log.message(url);
|
|
270317
|
-
return { outroMessage: "Preview is live." };
|
|
270355
|
+
async function startGithubReauth() {
|
|
270356
|
+
const response = await base44Client.post("api/github/oauth/initiate?skip_installation=true");
|
|
270357
|
+
return parseOrThrow(OAuthInitiateSchema, await response.json(), "github oauth initiate").authorization_url;
|
|
270318
270358
|
}
|
|
270319
|
-
function
|
|
270320
|
-
const
|
|
270321
|
-
|
|
270322
|
-
return command;
|
|
270359
|
+
function isGithubUserTokenError(error) {
|
|
270360
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
270361
|
+
return /api\.github\.com/i.test(message) && /\b401\b|unauthorized/i.test(message);
|
|
270323
270362
|
}
|
|
270324
|
-
|
|
270325
|
-
|
|
270326
|
-
|
|
270327
|
-
|
|
270328
|
-
|
|
270329
|
-
|
|
270330
|
-
|
|
270331
|
-
|
|
270332
|
-
|
|
270363
|
+
async function getAppState(appId) {
|
|
270364
|
+
let response;
|
|
270365
|
+
try {
|
|
270366
|
+
response = await base44Client.get(`api/apps/${appId}`, {
|
|
270367
|
+
searchParams: {
|
|
270368
|
+
fields: "id,status,app_type,is_managed_source_code,imported_repo_url"
|
|
270369
|
+
}
|
|
270370
|
+
});
|
|
270371
|
+
} catch (error) {
|
|
270372
|
+
throw await ApiError.fromHttpError(error, "reading app status");
|
|
270333
270373
|
}
|
|
270334
|
-
return;
|
|
270374
|
+
return parseOrThrow(AppStateSchema, await response.json(), "app status");
|
|
270335
270375
|
}
|
|
270336
|
-
async function
|
|
270337
|
-
|
|
270338
|
-
if (ctx.jsonMode) {
|
|
270339
|
-
const turn = await ctx.runTask("Agent working (a turn can take minutes)", () => sendTurn(message, branchId));
|
|
270340
|
-
if (turn.queued)
|
|
270341
|
-
return { stdout: `${JSON.stringify({ queued: true })}
|
|
270342
|
-
` };
|
|
270343
|
-
return {
|
|
270344
|
-
stdout: `${JSON.stringify({
|
|
270345
|
-
status: turn.status?.state ?? "ready",
|
|
270346
|
-
error_source: turn.status?.error_source ?? null,
|
|
270347
|
-
reply: lastAssistantReply(turn) ?? null
|
|
270348
|
-
})}
|
|
270349
|
-
`
|
|
270350
|
-
};
|
|
270351
|
-
}
|
|
270352
|
-
const stream = createTurnStream(process.stdout.isTTY === true);
|
|
270353
|
-
let turn;
|
|
270376
|
+
async function sendTurn(content, branchId) {
|
|
270377
|
+
let response;
|
|
270354
270378
|
try {
|
|
270355
|
-
|
|
270356
|
-
|
|
270357
|
-
|
|
270379
|
+
response = await getAppClient().post("chat/message", {
|
|
270380
|
+
timeout: false,
|
|
270381
|
+
searchParams: {
|
|
270382
|
+
conversation_messages: "current_turn",
|
|
270383
|
+
...branchScope(branchId)
|
|
270384
|
+
},
|
|
270385
|
+
json: { content }
|
|
270386
|
+
});
|
|
270387
|
+
} catch (error) {
|
|
270388
|
+
throw await ApiError.fromHttpError(error, "sending message");
|
|
270358
270389
|
}
|
|
270359
|
-
|
|
270360
|
-
|
|
270361
|
-
|
|
270362
|
-
|
|
270390
|
+
return parseOrThrow(ChatTurnSchema, await response.json(), "chat turn");
|
|
270391
|
+
}
|
|
270392
|
+
async function stopTurn(branchId) {
|
|
270393
|
+
try {
|
|
270394
|
+
await getAppClient().post("chat/stop", {
|
|
270395
|
+
searchParams: branchScope(branchId)
|
|
270396
|
+
});
|
|
270397
|
+
} catch (error) {
|
|
270398
|
+
throw await ApiError.fromHttpError(error, "stopping the turn");
|
|
270363
270399
|
}
|
|
270364
|
-
|
|
270365
|
-
|
|
270366
|
-
|
|
270367
|
-
|
|
270400
|
+
}
|
|
270401
|
+
async function getFullConversation(limit, branchId) {
|
|
270402
|
+
let response;
|
|
270403
|
+
try {
|
|
270404
|
+
response = await getAppClient().get("chat/full-conversation", {
|
|
270405
|
+
timeout: 30000,
|
|
270406
|
+
searchParams: { limit: String(limit), ...branchScope(branchId) }
|
|
270407
|
+
});
|
|
270408
|
+
} catch (error) {
|
|
270409
|
+
throw await ApiError.fromHttpError(error, "reading the conversation");
|
|
270368
270410
|
}
|
|
270369
|
-
return
|
|
270411
|
+
return parseOrThrow(FullConversationSchema, await response.json(), "conversation").messages;
|
|
270370
270412
|
}
|
|
270371
|
-
function
|
|
270372
|
-
const
|
|
270373
|
-
|
|
270374
|
-
return command;
|
|
270413
|
+
async function resolveActiveBranchId() {
|
|
270414
|
+
const branches = await listBranches();
|
|
270415
|
+
return branches.length === 1 ? branches[0].id : undefined;
|
|
270375
270416
|
}
|
|
270376
|
-
|
|
270377
|
-
|
|
270378
|
-
|
|
270379
|
-
|
|
270380
|
-
|
|
270381
|
-
|
|
270382
|
-
|
|
270383
|
-
|
|
270384
|
-
stdout: `${JSON.stringify({ id: app.id, state, message: app.status?.message ?? null })}
|
|
270385
|
-
`
|
|
270386
|
-
};
|
|
270417
|
+
async function getPreviewUrl() {
|
|
270418
|
+
let response;
|
|
270419
|
+
try {
|
|
270420
|
+
response = await getAppClient().get("sandbox/preview-url", {
|
|
270421
|
+
timeout: false
|
|
270422
|
+
});
|
|
270423
|
+
} catch (error) {
|
|
270424
|
+
throw await ApiError.fromHttpError(error, "fetching preview URL");
|
|
270387
270425
|
}
|
|
270388
|
-
|
|
270389
|
-
|
|
270390
|
-
ctx.log.message(`Note: ${app.status.message}`);
|
|
270391
|
-
return { outroMessage: "Status read." };
|
|
270392
|
-
}
|
|
270393
|
-
function getStatusCommand() {
|
|
270394
|
-
const command = new Base44Command("status");
|
|
270395
|
-
command.description("Show whether the app is building, ready, or errored").action(statusAction);
|
|
270396
|
-
return command;
|
|
270426
|
+
const url = parseOrThrow(PreviewUrlSchema, await response.json(), "preview URL").preview_url;
|
|
270427
|
+
return /^https?:\/\//.test(url) ? url : `https://${url}`;
|
|
270397
270428
|
}
|
|
270398
270429
|
|
|
270399
|
-
// src/cli/commands/
|
|
270400
|
-
|
|
270401
|
-
|
|
270402
|
-
|
|
270403
|
-
|
|
270404
|
-
|
|
270405
|
-
|
|
270406
|
-
|
|
270430
|
+
// src/cli/commands/builder/shared.ts
|
|
270431
|
+
var APP_NAME_RE = /^[A-Za-z0-9._-]+$/;
|
|
270432
|
+
var NAME_STOPWORDS = new Set("a an the and or of for with to in on that this its it my our your me".split(" "));
|
|
270433
|
+
var FALLBACK_WORDS = [
|
|
270434
|
+
"swift-otter",
|
|
270435
|
+
"sunny-comet",
|
|
270436
|
+
"tidy-maple",
|
|
270437
|
+
"brisk-panda"
|
|
270438
|
+
];
|
|
270439
|
+
function inventAppName(prompt) {
|
|
270440
|
+
const suffix = Math.random().toString(36).slice(2, 5);
|
|
270441
|
+
const words = (prompt ?? "").toLowerCase().match(/[a-z0-9]+/g)?.filter((w) => w.length > 2 && !NAME_STOPWORDS.has(w)).slice(0, 3) ?? [];
|
|
270442
|
+
const core = words.length ? words.join("-") : FALLBACK_WORDS[Math.floor(Math.random() * FALLBACK_WORDS.length)];
|
|
270443
|
+
return `base44-${core}-${suffix}`.slice(0, 60);
|
|
270444
|
+
}
|
|
270445
|
+
function repoBasename(repoUrl) {
|
|
270446
|
+
return repoUrl.replace(/\/+$/, "").replace(/\.git$/, "").split("/").pop() ?? "app";
|
|
270447
|
+
}
|
|
270448
|
+
async function createAndLinkApp(options) {
|
|
270449
|
+
if (options.name && !APP_NAME_RE.test(options.name)) {
|
|
270450
|
+
throw new InvalidInputError("The name becomes a directory — letters, digits, dots, dashes and underscores only.");
|
|
270451
|
+
}
|
|
270452
|
+
const cwd = process.cwd();
|
|
270453
|
+
const fallbackName = () => options.importRepo ? repoBasename(options.importRepo) : inventAppName(options.prompt);
|
|
270454
|
+
const chosenDir = options.path ? resolve8(cwd, options.path) : await isDirEmpty(cwd) ? cwd : undefined;
|
|
270455
|
+
const dirBase = chosenDir ? basename6(chosenDir) : undefined;
|
|
270456
|
+
const name = options.name ?? (dirBase && APP_NAME_RE.test(dirBase) ? dirBase : fallbackName());
|
|
270457
|
+
const targetDir = chosenDir ?? join25(cwd, name);
|
|
270458
|
+
const here = targetDir === cwd;
|
|
270459
|
+
const dirName = here ? "." : relative6(cwd, targetDir) || name;
|
|
270460
|
+
await mkdir3(targetDir, { recursive: true });
|
|
270461
|
+
if (await appConfigExists(targetDir)) {
|
|
270462
|
+
throw new InvalidInputError(here ? "This directory is already linked to a Base44 app. Run `base44 code` here to keep building it, or pass --path for a new one." : `./${dirName} is already linked to a Base44 app. Pick another name or --path.`);
|
|
270463
|
+
}
|
|
270464
|
+
const created = options.importRepo ? await createImportedApp({
|
|
270465
|
+
appName: name,
|
|
270466
|
+
repoUrl: options.importRepo,
|
|
270467
|
+
sourceMode: options.mode ?? "direct",
|
|
270468
|
+
newRepoName: options.repoName,
|
|
270469
|
+
branch: options.fromBranch,
|
|
270470
|
+
prompt: options.prompt
|
|
270471
|
+
}) : await createApp({ appName: name, prompt: options.prompt });
|
|
270472
|
+
await writeAppConfig(targetDir, created.id);
|
|
270473
|
+
await mkdir3(join25(targetDir, "base44"), { recursive: true });
|
|
270474
|
+
try {
|
|
270475
|
+
await writeFile2(join25(targetDir, "base44", "config.jsonc"), `// Base44 project configuration.
|
|
270476
|
+
{
|
|
270477
|
+
"name": ${JSON.stringify(name)}
|
|
270478
|
+
}
|
|
270479
|
+
`, { flag: "wx" });
|
|
270480
|
+
} catch {}
|
|
270481
|
+
setAppContext({ id: created.id, projectRoot: targetDir });
|
|
270482
|
+
return {
|
|
270483
|
+
id: created.id,
|
|
270484
|
+
editorUrl: `${getBase44ApiUrl()}/apps/${created.id}/editor/preview`,
|
|
270485
|
+
repoUrl: created.imported_repo_url ?? undefined,
|
|
270486
|
+
dirName,
|
|
270487
|
+
targetDir,
|
|
270488
|
+
here
|
|
270489
|
+
};
|
|
270490
|
+
}
|
|
270491
|
+
function repoLabel(url) {
|
|
270492
|
+
return url.replace(/^https?:\/\//, "").replace(/\.git$/, "").replace(/\/$/, "");
|
|
270493
|
+
}
|
|
270494
|
+
function appTypeChip(state) {
|
|
270495
|
+
switch (state.app_type ?? "user_app") {
|
|
270496
|
+
case "imported_app":
|
|
270497
|
+
return state.imported_repo_url ? repoLabel(state.imported_repo_url) : "repository app";
|
|
270498
|
+
case "user_game":
|
|
270499
|
+
return "game";
|
|
270500
|
+
case "mobile_app":
|
|
270501
|
+
return "mobile app";
|
|
270502
|
+
case "slide":
|
|
270503
|
+
return "slides";
|
|
270504
|
+
case "user_agent":
|
|
270505
|
+
return "superagent";
|
|
270506
|
+
default:
|
|
270507
|
+
return "web app";
|
|
270508
|
+
}
|
|
270407
270509
|
}
|
|
270408
|
-
function
|
|
270409
|
-
const
|
|
270410
|
-
|
|
270411
|
-
|
|
270510
|
+
async function assertBuilderApp(appId) {
|
|
270511
|
+
const state = await getAppState(appId);
|
|
270512
|
+
if (state.is_managed_source_code === false) {
|
|
270513
|
+
throw new InvalidInputError("This project is code-first (base44 create): you own the source and the builder cannot work on it. Run `base44 builder new` for an agent-built app.");
|
|
270514
|
+
}
|
|
270515
|
+
if (state.app_type === "user_agent") {
|
|
270516
|
+
throw new InvalidInputError("This is a Superagent, not an app the builder works on. Superagent has no CLI surface yet.");
|
|
270517
|
+
}
|
|
270518
|
+
return state;
|
|
270412
270519
|
}
|
|
270413
|
-
|
|
270414
|
-
|
|
270415
|
-
|
|
270416
|
-
|
|
270520
|
+
function nextStepsLines(app) {
|
|
270521
|
+
const cd = app.here ? "" : `cd ${app.dirName} && `;
|
|
270522
|
+
return [
|
|
270523
|
+
"",
|
|
270524
|
+
`${source_default.bold("Your app lives in")} ${app.here ? "./ (this directory)" : `./${app.dirName}`}`,
|
|
270525
|
+
source_default.dim(` ${cd}base44 code # keep building with the agent`),
|
|
270526
|
+
source_default.dim(` ${cd}base44 builder send "…" # one non-interactive turn`),
|
|
270527
|
+
source_default.dim(` files live remotely — ${cd}base44 sandbox ls to look, base44 eject for a copy`)
|
|
270528
|
+
];
|
|
270417
270529
|
}
|
|
270418
|
-
|
|
270419
|
-
|
|
270420
|
-
|
|
270421
|
-
|
|
270422
|
-
|
|
270423
|
-
|
|
270424
|
-
|
|
270425
|
-
|
|
270426
|
-
const updated = await runTask("Updating local auth config", async () => {
|
|
270427
|
-
const current = await readAuthConfig(authDir) ?? DEFAULT_AUTH_CONFIG;
|
|
270428
|
-
const merged = { ...current, enableUsernamePassword: shouldEnable };
|
|
270429
|
-
await writeAuthConfig(authDir, merged);
|
|
270430
|
-
return merged;
|
|
270431
|
-
});
|
|
270432
|
-
if (!shouldEnable && !hasAnyLoginMethod(updated)) {
|
|
270433
|
-
log.warn("Disabling password auth will leave no login methods enabled. Users will be locked out.");
|
|
270434
|
-
}
|
|
270435
|
-
const newStatus = shouldEnable ? "enabled" : "disabled";
|
|
270436
|
-
return {
|
|
270437
|
-
outroMessage: `Username & password authentication ${newStatus} in local config. Run \`base44 auth push\` or \`base44 deploy\` to apply.`
|
|
270438
|
-
};
|
|
270530
|
+
async function githubReauthLines(error) {
|
|
270531
|
+
if (!isGithubUserTokenError(error))
|
|
270532
|
+
return null;
|
|
270533
|
+
const link = await startGithubReauth().catch(() => null);
|
|
270534
|
+
return [
|
|
270535
|
+
"Your GitHub authorization expired. Reconnect, then run this again:",
|
|
270536
|
+
link ? terminalLink("Reconnect GitHub", link) : "Open Base44 → GitHub settings to reconnect your account."
|
|
270537
|
+
];
|
|
270439
270538
|
}
|
|
270440
|
-
function
|
|
270441
|
-
return
|
|
270539
|
+
async function resolveBranchId(ctx) {
|
|
270540
|
+
return ctx.branchId ?? await resolveActiveBranchId().catch(() => {
|
|
270541
|
+
return;
|
|
270542
|
+
});
|
|
270442
270543
|
}
|
|
270443
270544
|
|
|
270444
|
-
// src/
|
|
270445
|
-
|
|
270446
|
-
|
|
270447
|
-
log,
|
|
270448
|
-
runTask
|
|
270449
|
-
}) {
|
|
270450
|
-
const { project } = await readProjectConfig();
|
|
270451
|
-
const configDir = dirname16(project.configPath);
|
|
270452
|
-
const authDir = join23(configDir, project.authDir);
|
|
270453
|
-
const remoteConfig = await runTask("Fetching auth config from Base44", async () => {
|
|
270454
|
-
return await pullAuthConfig();
|
|
270455
|
-
}, {
|
|
270456
|
-
successMessage: "Auth config fetched successfully",
|
|
270457
|
-
errorMessage: "Failed to fetch auth config"
|
|
270458
|
-
});
|
|
270459
|
-
const { written } = await runTask("Syncing auth config file", async () => {
|
|
270460
|
-
return await writeAuthConfig(authDir, remoteConfig);
|
|
270461
|
-
}, {
|
|
270462
|
-
successMessage: "Auth config file synced successfully",
|
|
270463
|
-
errorMessage: "Failed to sync auth config file"
|
|
270464
|
-
});
|
|
270465
|
-
if (written) {
|
|
270466
|
-
log.success("Auth config written to local file");
|
|
270467
|
-
} else {
|
|
270468
|
-
log.info("Auth config is already up to date");
|
|
270469
|
-
}
|
|
270470
|
-
return {
|
|
270471
|
-
outroMessage: `Pulled auth config to ${authDir} (overwrites local file)`
|
|
270472
|
-
};
|
|
270545
|
+
// src/core/resources/apps/stream.ts
|
|
270546
|
+
function newStreamState() {
|
|
270547
|
+
return { perMessage: new Map };
|
|
270473
270548
|
}
|
|
270474
|
-
|
|
270475
|
-
|
|
270549
|
+
var TOOL_SETTLED = new Set(["success", "error", "stopped"]);
|
|
270550
|
+
function oneLine(value, max) {
|
|
270551
|
+
const text = typeof value === "string" ? value : value == null ? "" : JSON.stringify(value);
|
|
270552
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
270553
|
+
return flat.length > max ? `${flat.slice(0, max)}…` : flat;
|
|
270476
270554
|
}
|
|
270477
|
-
|
|
270478
|
-
|
|
270479
|
-
|
|
270480
|
-
|
|
270481
|
-
|
|
270482
|
-
|
|
270483
|
-
return {
|
|
270484
|
-
outroMessage: "No auth config to push. Run `base44 auth pull` to fetch the remote config first."
|
|
270485
|
-
};
|
|
270486
|
-
}
|
|
270487
|
-
if (!hasAnyLoginMethod(authConfig[0])) {
|
|
270488
|
-
log.warn("This config has no login methods enabled. Pushing it will lock out all users.");
|
|
270555
|
+
var SALIENT_KEYS = ["command", "path", "file_path", "title"];
|
|
270556
|
+
function salvageKey(raw, keys) {
|
|
270557
|
+
for (const key of keys) {
|
|
270558
|
+
const match = raw.match(new RegExp(`"${key}"\\s*:\\s*"((?:[^"\\\\]|\\\\.)*)"`));
|
|
270559
|
+
if (match?.[1])
|
|
270560
|
+
return match[1].replace(/\\(.)/g, "$1");
|
|
270489
270561
|
}
|
|
270490
|
-
|
|
270491
|
-
|
|
270492
|
-
|
|
270493
|
-
|
|
270494
|
-
|
|
270495
|
-
|
|
270496
|
-
|
|
270497
|
-
if (
|
|
270498
|
-
|
|
270562
|
+
return;
|
|
270563
|
+
}
|
|
270564
|
+
function toolMeta(name, argumentsString) {
|
|
270565
|
+
const raw = argumentsString ?? "";
|
|
270566
|
+
let args = {};
|
|
270567
|
+
try {
|
|
270568
|
+
const parsed = JSON.parse(raw);
|
|
270569
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
270570
|
+
args = parsed;
|
|
270499
270571
|
}
|
|
270572
|
+
} catch {
|
|
270573
|
+
return {
|
|
270574
|
+
label: oneLine(salvageKey(raw, ["summary"]) ?? "", 90),
|
|
270575
|
+
summary: oneLine(salvageKey(raw, SALIENT_KEYS) ?? raw, 90)
|
|
270576
|
+
};
|
|
270500
270577
|
}
|
|
270501
|
-
|
|
270502
|
-
|
|
270503
|
-
|
|
270504
|
-
|
|
270505
|
-
|
|
270506
|
-
|
|
270578
|
+
const pick = (key) => typeof args[key] === "string" && args[key].trim() ? args[key] : undefined;
|
|
270579
|
+
const salient = {
|
|
270580
|
+
run_shell_command: pick("command"),
|
|
270581
|
+
read_repo_file: pick("path") ?? pick("file_path"),
|
|
270582
|
+
write_repo_file: pick("path") ?? pick("file_path"),
|
|
270583
|
+
edit_repo_file: pick("path") ?? pick("file_path"),
|
|
270584
|
+
create_pull_request: pick("title"),
|
|
270585
|
+
reload_preview: ""
|
|
270586
|
+
};
|
|
270587
|
+
const summary = salient[name] ?? Object.entries(args).find(([key, v]) => key !== "summary" && typeof v === "string" && v.trim().length > 0)?.[1] ?? "";
|
|
270507
270588
|
return {
|
|
270508
|
-
|
|
270589
|
+
label: oneLine(pick("summary") ?? "", 90),
|
|
270590
|
+
summary: oneLine(summary, 90)
|
|
270509
270591
|
};
|
|
270510
270592
|
}
|
|
270511
|
-
function
|
|
270512
|
-
|
|
270593
|
+
function labelTense(label, tense) {
|
|
270594
|
+
const parts = label.split(/\s*\|\s*/);
|
|
270595
|
+
if (parts.length < 2)
|
|
270596
|
+
return label;
|
|
270597
|
+
return tense === "running" ? parts[0] : parts[1];
|
|
270513
270598
|
}
|
|
270514
|
-
|
|
270515
|
-
|
|
270516
|
-
|
|
270517
|
-
|
|
270518
|
-
|
|
270519
|
-
|
|
270520
|
-
|
|
270521
|
-
|
|
270522
|
-
|
|
270523
|
-
|
|
270524
|
-
|
|
270525
|
-
google: {
|
|
270526
|
-
envVar: "google_oauth_client_secret",
|
|
270527
|
-
promptMessage: "Enter Google OAuth client secret"
|
|
270599
|
+
function progressFor(state, id) {
|
|
270600
|
+
let progress = state.perMessage.get(id);
|
|
270601
|
+
if (!progress) {
|
|
270602
|
+
progress = {
|
|
270603
|
+
contentLength: 0,
|
|
270604
|
+
reasoningLength: 0,
|
|
270605
|
+
announcedTools: new Map,
|
|
270606
|
+
settledTools: new Set,
|
|
270607
|
+
waitingNotified: new Set
|
|
270608
|
+
};
|
|
270609
|
+
state.perMessage.set(id, progress);
|
|
270528
270610
|
}
|
|
270529
|
-
|
|
270530
|
-
function hasSecretOptions(options) {
|
|
270531
|
-
return Boolean(options.clientSecret || options.clientSecretStdin || options.envFile);
|
|
270532
|
-
}
|
|
270533
|
-
function hasCustomOAuthOptions(options) {
|
|
270534
|
-
return Boolean(options.clientId || hasSecretOptions(options));
|
|
270611
|
+
return progress;
|
|
270535
270612
|
}
|
|
270536
|
-
|
|
270537
|
-
const
|
|
270538
|
-
const
|
|
270539
|
-
|
|
270540
|
-
|
|
270541
|
-
|
|
270542
|
-
|
|
270543
|
-
|
|
270544
|
-
|
|
270545
|
-
|
|
270546
|
-
|
|
270547
|
-
|
|
270548
|
-
|
|
270549
|
-
|
|
270550
|
-
|
|
270551
|
-
|
|
270552
|
-
|
|
270553
|
-
|
|
270554
|
-
|
|
270555
|
-
|
|
270556
|
-
|
|
270557
|
-
|
|
270558
|
-
|
|
270559
|
-
|
|
270613
|
+
function diffConversation(state, messages) {
|
|
270614
|
+
const events = [];
|
|
270615
|
+
for (const message of messages) {
|
|
270616
|
+
if (message.role !== "assistant" || message.hidden)
|
|
270617
|
+
continue;
|
|
270618
|
+
const progress = progressFor(state, message.id);
|
|
270619
|
+
const reasoning = message.reasoning?.content ?? "";
|
|
270620
|
+
if (reasoning.length > progress.reasoningLength) {
|
|
270621
|
+
const delta = reasoning.slice(progress.reasoningLength).trim();
|
|
270622
|
+
if (delta)
|
|
270623
|
+
events.push({ kind: "thinking", text: oneLine(delta, 300) });
|
|
270624
|
+
progress.reasoningLength = reasoning.length;
|
|
270625
|
+
}
|
|
270626
|
+
if (typeof message.content === "string" && message.content.length > progress.contentLength) {
|
|
270627
|
+
const delta = message.content.slice(progress.contentLength).trim();
|
|
270628
|
+
if (delta)
|
|
270629
|
+
events.push({ kind: "text", text: delta });
|
|
270630
|
+
progress.contentLength = message.content.length;
|
|
270631
|
+
}
|
|
270632
|
+
for (const tool of message.tool_calls ?? []) {
|
|
270633
|
+
if (!progress.announcedTools.has(tool.id)) {
|
|
270634
|
+
progress.announcedTools.set(tool.id, toolMeta(tool.name, tool.arguments_string));
|
|
270635
|
+
const meta = progress.announcedTools.get(tool.id);
|
|
270636
|
+
events.push({
|
|
270637
|
+
kind: "tool_start",
|
|
270638
|
+
id: tool.id,
|
|
270639
|
+
name: tool.name,
|
|
270640
|
+
label: labelTense(meta.label, "running"),
|
|
270641
|
+
summary: meta.summary
|
|
270642
|
+
});
|
|
270643
|
+
}
|
|
270644
|
+
const status = tool.status ?? "running";
|
|
270645
|
+
if (status === "waiting_for_user_input" && !progress.waitingNotified.has(tool.id)) {
|
|
270646
|
+
progress.waitingNotified.add(tool.id);
|
|
270647
|
+
const meta = progress.announcedTools.get(tool.id);
|
|
270648
|
+
events.push({
|
|
270649
|
+
kind: "waiting",
|
|
270650
|
+
id: tool.id,
|
|
270651
|
+
name: tool.name,
|
|
270652
|
+
label: labelTense(meta.label, "running")
|
|
270653
|
+
});
|
|
270654
|
+
}
|
|
270655
|
+
if (TOOL_SETTLED.has(status) && !progress.settledTools.has(tool.id)) {
|
|
270656
|
+
progress.settledTools.add(tool.id);
|
|
270657
|
+
const meta = progress.announcedTools.get(tool.id);
|
|
270658
|
+
events.push({
|
|
270659
|
+
kind: "tool_end",
|
|
270660
|
+
id: tool.id,
|
|
270661
|
+
name: tool.name,
|
|
270662
|
+
label: labelTense(meta.label, "done"),
|
|
270663
|
+
summary: meta.summary,
|
|
270664
|
+
ok: status === "success",
|
|
270665
|
+
result: oneLine(tool.results, 110)
|
|
270666
|
+
});
|
|
270560
270667
|
}
|
|
270561
|
-
clientSecret = value;
|
|
270562
|
-
} else {
|
|
270563
|
-
clientSecret = await resolveSecret({
|
|
270564
|
-
flagValue: options.clientSecret,
|
|
270565
|
-
fromStdin: options.clientSecretStdin,
|
|
270566
|
-
envVar: oauthCli.envVar,
|
|
270567
|
-
promptMessage: oauthCli.promptMessage,
|
|
270568
|
-
isNonInteractive,
|
|
270569
|
-
name: "client secret",
|
|
270570
|
-
hints: [
|
|
270571
|
-
{
|
|
270572
|
-
message: `Provide via flag: base44 auth social-login ${provider} enable --client-id <id> --client-secret <secret>`,
|
|
270573
|
-
command: `base44 auth social-login ${provider} enable --client-id <id> --client-secret <secret>`
|
|
270574
|
-
},
|
|
270575
|
-
{
|
|
270576
|
-
message: `Provide via stdin: echo <secret> | base44 auth social-login ${provider} enable --client-id <id> --client-secret-stdin`
|
|
270577
|
-
},
|
|
270578
|
-
{
|
|
270579
|
-
message: `Provide via env: ${oauthCli.envVar}=<secret> base44 auth social-login ${provider} enable --client-id <id>`
|
|
270580
|
-
}
|
|
270581
|
-
]
|
|
270582
|
-
});
|
|
270583
270668
|
}
|
|
270584
270669
|
}
|
|
270585
|
-
|
|
270586
|
-
const configDir = dirname17(project.configPath);
|
|
270587
|
-
const authDir = join24(configDir, project.authDir);
|
|
270588
|
-
const { config: updated } = await runTask("Updating local auth config", async () => updateSocialLoginConfig(authDir, provider, shouldEnable, useCustomOAuth && options.clientId ? { clientId: options.clientId } : undefined));
|
|
270589
|
-
if (clientSecret) {
|
|
270590
|
-
await runTask("Saving client secret", async () => pushCustomOAuthSecret(provider, clientSecret));
|
|
270591
|
-
}
|
|
270592
|
-
if (!shouldEnable && !hasAnyLoginMethod(updated)) {
|
|
270593
|
-
log.warn(`Disabling ${label} login will leave no login methods enabled. Users will be locked out.`);
|
|
270594
|
-
}
|
|
270595
|
-
const newStatus = shouldEnable ? "enabled" : "disabled";
|
|
270596
|
-
const oauthNote = useCustomOAuth ? " with custom OAuth" : "";
|
|
270597
|
-
let outroMessage = `${label} login ${newStatus}${oauthNote} in local config. Run \`base44 auth push\` or \`base44 deploy\` to apply.`;
|
|
270598
|
-
if (useCustomOAuth && !clientSecret) {
|
|
270599
|
-
outroMessage += `
|
|
270600
|
-
Remember to push the client secret separately: base44 secrets set --env-file <path>`;
|
|
270601
|
-
}
|
|
270602
|
-
return { outroMessage };
|
|
270670
|
+
return events;
|
|
270603
270671
|
}
|
|
270604
|
-
function
|
|
270605
|
-
return
|
|
270606
|
-
"enable",
|
|
270607
|
-
"disable"
|
|
270608
|
-
])).option("--client-id <id>", "custom OAuth client ID (Google only)").option("--client-secret <secret>", "custom OAuth client secret (Google only)").option("--client-secret-stdin", "read client secret from stdin (Google only)").option("--env-file <path>", "read client secret from a .env file (Google only)").action(socialLoginAction);
|
|
270672
|
+
function turnSettled(messages) {
|
|
270673
|
+
return newestUserTurn(messages)?.settled ?? false;
|
|
270609
270674
|
}
|
|
270610
|
-
|
|
270611
|
-
|
|
270612
|
-
|
|
270613
|
-
|
|
270614
|
-
|
|
270615
|
-
|
|
270616
|
-
|
|
270617
|
-
|
|
270618
|
-
|
|
270619
|
-
|
|
270620
|
-
|
|
270621
|
-
|
|
270622
|
-
tokenEndpoint: string2().optional(),
|
|
270623
|
-
userinfoEndpoint: string2().optional(),
|
|
270624
|
-
jwksUri: string2().optional(),
|
|
270625
|
-
ssoName: string2().optional()
|
|
270626
|
-
});
|
|
270627
|
-
async function loadSSOConfigFile(filePath) {
|
|
270628
|
-
const resolved = resolve7(filePath);
|
|
270629
|
-
const raw = await readJsonFile(resolved);
|
|
270630
|
-
const result = SSOConfigFileSchema.safeParse(raw);
|
|
270631
|
-
if (!result.success) {
|
|
270632
|
-
throw new SchemaValidationError("Invalid SSO config file", result.error, filePath);
|
|
270675
|
+
function newestUserTurn(messages) {
|
|
270676
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
270677
|
+
const message = messages[i];
|
|
270678
|
+
if (message.role === "user" && !message.hidden) {
|
|
270679
|
+
const outcome = message.outcome;
|
|
270680
|
+
const backendStatus = outcome && typeof outcome === "object" ? outcome.backend_status : undefined;
|
|
270681
|
+
return {
|
|
270682
|
+
id: message.id,
|
|
270683
|
+
settled: outcome != null && backendStatus !== "pending",
|
|
270684
|
+
backendStatus
|
|
270685
|
+
};
|
|
270686
|
+
}
|
|
270633
270687
|
}
|
|
270634
|
-
return
|
|
270688
|
+
return null;
|
|
270635
270689
|
}
|
|
270636
|
-
|
|
270637
|
-
|
|
270638
|
-
|
|
270639
|
-
|
|
270640
|
-
|
|
270641
|
-
|
|
270642
|
-
|
|
270643
|
-
|
|
270644
|
-
|
|
270645
|
-
|
|
270646
|
-
|
|
270647
|
-
|
|
270648
|
-
|
|
270649
|
-
|
|
270650
|
-
jwksUri: options.jwksUri ?? fileConfig.jwksUri,
|
|
270651
|
-
ssoName: options.ssoName ?? fileConfig.ssoName
|
|
270690
|
+
var sleep3 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
270691
|
+
function makePoller(onEvent, options) {
|
|
270692
|
+
const state = newStreamState();
|
|
270693
|
+
return async (prime = false) => {
|
|
270694
|
+
try {
|
|
270695
|
+
const messages = await getFullConversation(30, options.branchId);
|
|
270696
|
+
const events = diffConversation(state, messages);
|
|
270697
|
+
if (!prime)
|
|
270698
|
+
for (const event of events)
|
|
270699
|
+
onEvent(event);
|
|
270700
|
+
return messages;
|
|
270701
|
+
} catch {
|
|
270702
|
+
return [];
|
|
270703
|
+
}
|
|
270652
270704
|
};
|
|
270653
270705
|
}
|
|
270654
|
-
|
|
270655
|
-
|
|
270656
|
-
|
|
270657
|
-
|
|
270658
|
-
|
|
270659
|
-
|
|
270660
|
-
|
|
270661
|
-
|
|
270662
|
-
|
|
270663
|
-
|
|
270664
|
-
|
|
270665
|
-
|
|
270666
|
-
|
|
270667
|
-
|
|
270668
|
-
|
|
270669
|
-
|
|
270670
|
-
}
|
|
270671
|
-
function exampleCommand(provider) {
|
|
270672
|
-
let cmd = `base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`;
|
|
270673
|
-
if (provider === KNOWN_SSO_PROVIDERS.microsoft)
|
|
270674
|
-
cmd += " --tenant-id <id>";
|
|
270675
|
-
if (provider === KNOWN_SSO_PROVIDERS.okta)
|
|
270676
|
-
cmd += " --okta-domain <domain>";
|
|
270677
|
-
if (provider === KNOWN_SSO_PROVIDERS.custom)
|
|
270678
|
-
cmd += " --sso-name <name> --auth-endpoint <url> --token-endpoint <url> --userinfo-endpoint <url> --jwks-uri <url>";
|
|
270679
|
-
return cmd;
|
|
270680
|
-
}
|
|
270681
|
-
function validateProvider(provider) {
|
|
270682
|
-
if (!provider) {
|
|
270683
|
-
throw new InvalidInputError("Missing --provider.", {
|
|
270684
|
-
hints: [
|
|
270685
|
-
{
|
|
270686
|
-
message: `Valid providers: ${providerNames.join(", ")}`,
|
|
270687
|
-
command: "base44 auth sso enable --provider <provider> --client-id <id> --client-secret <secret>"
|
|
270688
|
-
}
|
|
270689
|
-
]
|
|
270690
|
-
});
|
|
270706
|
+
async function streamConversationDuring(start, onEvent, options = {}) {
|
|
270707
|
+
const intervalMs = options.intervalMs ?? 1000;
|
|
270708
|
+
const poll = makePoller(onEvent, options);
|
|
270709
|
+
await poll(true);
|
|
270710
|
+
const work = start();
|
|
270711
|
+
let pending = true;
|
|
270712
|
+
const settled = work.then(() => {
|
|
270713
|
+
pending = false;
|
|
270714
|
+
}, () => {
|
|
270715
|
+
pending = false;
|
|
270716
|
+
});
|
|
270717
|
+
while (pending) {
|
|
270718
|
+
await Promise.race([sleep3(intervalMs), settled]);
|
|
270719
|
+
if (!pending)
|
|
270720
|
+
break;
|
|
270721
|
+
await poll();
|
|
270691
270722
|
}
|
|
270692
|
-
|
|
270723
|
+
await poll();
|
|
270724
|
+
return work;
|
|
270693
270725
|
}
|
|
270694
|
-
async function
|
|
270695
|
-
|
|
270696
|
-
|
|
270726
|
+
async function streamConversationUntilSettled(onEvent, options = {}) {
|
|
270727
|
+
const intervalMs = options.intervalMs ?? 1000;
|
|
270728
|
+
const deadline = Date.now() + (options.timeoutMs ?? 20 * 60000);
|
|
270729
|
+
const poll = makePoller(onEvent, options);
|
|
270730
|
+
while (Date.now() < deadline) {
|
|
270731
|
+
const messages = await poll();
|
|
270732
|
+
if (messages.length > 0 && turnSettled(messages))
|
|
270733
|
+
return "settled";
|
|
270734
|
+
await sleep3(intervalMs);
|
|
270697
270735
|
}
|
|
270698
|
-
|
|
270699
|
-
|
|
270700
|
-
|
|
270701
|
-
|
|
270736
|
+
return "timeout";
|
|
270737
|
+
}
|
|
270738
|
+
|
|
270739
|
+
// src/cli/commands/builder/new.ts
|
|
270740
|
+
var POLL_TIMEOUT_MS = 20 * 60000;
|
|
270741
|
+
var MODES = ["direct", "fork", "copy"];
|
|
270742
|
+
async function newAction({ log, runTask, jsonMode }, prompt, options) {
|
|
270743
|
+
if (options.mode && !MODES.includes(options.mode)) {
|
|
270744
|
+
throw new InvalidInputError("--mode must be direct, fork, or copy.");
|
|
270702
270745
|
}
|
|
270703
|
-
|
|
270704
|
-
|
|
270705
|
-
throw new InvalidInputError("Missing --client-id.", {
|
|
270706
|
-
hints: [
|
|
270707
|
-
{
|
|
270708
|
-
message: `Example: base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`,
|
|
270709
|
-
command: `base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`
|
|
270710
|
-
}
|
|
270711
|
-
]
|
|
270712
|
-
});
|
|
270746
|
+
if ((options.mode || options.repoName || options.fromBranch) && !options.import) {
|
|
270747
|
+
throw new InvalidInputError("--mode, --repo-name and --from-branch apply only with --import <repo>.");
|
|
270713
270748
|
}
|
|
270714
|
-
|
|
270715
|
-
|
|
270716
|
-
const secrets = await parseEnvFile(resolve7(merged.envFile));
|
|
270717
|
-
const value = secrets.sso_client_secret;
|
|
270718
|
-
if (!value) {
|
|
270719
|
-
throw new InvalidInputError(`Key "sso_client_secret" not found in ${merged.envFile}.`);
|
|
270720
|
-
}
|
|
270721
|
-
clientSecret = value;
|
|
270722
|
-
} else {
|
|
270723
|
-
clientSecret = await resolveSecret({
|
|
270724
|
-
flagValue: merged.clientSecret,
|
|
270725
|
-
fromStdin: merged.clientSecretStdin,
|
|
270726
|
-
envVar: "sso_client_secret",
|
|
270727
|
-
promptMessage: "Enter SSO client secret",
|
|
270728
|
-
isNonInteractive,
|
|
270729
|
-
name: "client secret",
|
|
270730
|
-
hints: [
|
|
270731
|
-
{
|
|
270732
|
-
message: `Provide via flag: base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`,
|
|
270733
|
-
command: `base44 auth sso enable --provider ${provider} --client-id <id> --client-secret <secret>`
|
|
270734
|
-
},
|
|
270735
|
-
{
|
|
270736
|
-
message: `Provide via stdin: echo <secret> | base44 auth sso enable --provider ${provider} --client-id <id> --client-secret-stdin`
|
|
270737
|
-
},
|
|
270738
|
-
{
|
|
270739
|
-
message: `Provide via env: sso_client_secret=<secret> base44 auth sso enable --provider ${provider} --client-id <id>`
|
|
270740
|
-
}
|
|
270741
|
-
]
|
|
270742
|
-
});
|
|
270749
|
+
if (!prompt && !options.import) {
|
|
270750
|
+
throw new InvalidInputError('Describe the app ("<prompt>") or pass --import <repo>.');
|
|
270743
270751
|
}
|
|
270744
|
-
|
|
270745
|
-
clientId: merged.clientId,
|
|
270746
|
-
clientSecret,
|
|
270747
|
-
scope: merged.scope,
|
|
270748
|
-
discoveryUrl: merged.discoveryUrl,
|
|
270749
|
-
tenantId: merged.tenantId,
|
|
270750
|
-
oktaDomain: merged.oktaDomain,
|
|
270751
|
-
authEndpoint: merged.authEndpoint,
|
|
270752
|
-
tokenEndpoint: merged.tokenEndpoint,
|
|
270753
|
-
userinfoEndpoint: merged.userinfoEndpoint,
|
|
270754
|
-
jwksUri: merged.jwksUri,
|
|
270755
|
-
ssoName: merged.ssoName
|
|
270756
|
-
};
|
|
270757
|
-
let secrets;
|
|
270752
|
+
let app;
|
|
270758
270753
|
try {
|
|
270759
|
-
|
|
270754
|
+
app = await runTask(options.import ? "Importing the repository" : "Creating your app", () => createAndLinkApp({
|
|
270755
|
+
prompt,
|
|
270756
|
+
name: options.name,
|
|
270757
|
+
importRepo: options.import,
|
|
270758
|
+
mode: options.mode,
|
|
270759
|
+
repoName: options.repoName,
|
|
270760
|
+
fromBranch: options.fromBranch,
|
|
270761
|
+
path: options.path
|
|
270762
|
+
}));
|
|
270760
270763
|
} catch (error) {
|
|
270761
|
-
|
|
270762
|
-
|
|
270763
|
-
throw new InvalidInputError(`Missing required fields for ${error.provider}: ${flagNames.join(", ")}`, {
|
|
270764
|
-
hints: [
|
|
270765
|
-
{
|
|
270766
|
-
message: `Example: ${exampleCommand(provider)}`,
|
|
270767
|
-
command: exampleCommand(provider)
|
|
270768
|
-
}
|
|
270769
|
-
]
|
|
270770
|
-
});
|
|
270771
|
-
}
|
|
270764
|
+
for (const line of await githubReauthLines(error) ?? [])
|
|
270765
|
+
log.message(line);
|
|
270772
270766
|
throw error;
|
|
270773
270767
|
}
|
|
270774
|
-
|
|
270775
|
-
|
|
270776
|
-
|
|
270777
|
-
|
|
270778
|
-
|
|
270779
|
-
return {
|
|
270780
|
-
outroMessage: `SSO configured with ${provider} in local config. Run \`base44 auth push\` or \`base44 deploy\` to apply.`
|
|
270781
|
-
};
|
|
270782
|
-
}
|
|
270783
|
-
function hasEnableOnlyOptions(options) {
|
|
270784
|
-
return Boolean(options.provider || options.clientId || options.clientSecret || options.clientSecretStdin || options.envFile || options.file || options.scope || options.discoveryUrl || options.tenantId || options.oktaDomain || options.authEndpoint || options.tokenEndpoint || options.userinfoEndpoint || options.jwksUri || options.ssoName);
|
|
270785
|
-
}
|
|
270786
|
-
async function ssoDisableAction({ log, runTask }, options) {
|
|
270787
|
-
if (hasEnableOnlyOptions(options)) {
|
|
270788
|
-
throw new InvalidInputError("Configuration options cannot be used with disable. To disable SSO: base44 auth sso disable");
|
|
270768
|
+
if (!jsonMode) {
|
|
270769
|
+
if (app.repoUrl)
|
|
270770
|
+
log.message(source_default.dim(`repo ${app.repoUrl}`));
|
|
270771
|
+
log.message(source_default.dim(`editor ${app.editorUrl}`));
|
|
270772
|
+
log.message(source_default.dim(`linked ${app.here ? "./ (this directory)" : `./${app.dirName}`}`));
|
|
270789
270773
|
}
|
|
270790
|
-
|
|
270791
|
-
|
|
270792
|
-
const
|
|
270793
|
-
|
|
270794
|
-
|
|
270795
|
-
|
|
270796
|
-
|
|
270774
|
+
let finalState;
|
|
270775
|
+
let previewUrl;
|
|
270776
|
+
const startedAt = Date.now();
|
|
270777
|
+
if (prompt) {
|
|
270778
|
+
const branchId = await resolveActiveBranchId().catch(() => {
|
|
270779
|
+
return;
|
|
270780
|
+
});
|
|
270781
|
+
const stream = createTurnStream(process.stdout.isTTY === true && !jsonMode, undefined, { idleLabel: "provisioning the sandbox and starting the build" });
|
|
270782
|
+
try {
|
|
270783
|
+
const settled = await streamConversationUntilSettled((event) => {
|
|
270784
|
+
if (!jsonMode)
|
|
270785
|
+
stream.onEvent(event);
|
|
270786
|
+
}, { branchId, timeoutMs: POLL_TIMEOUT_MS });
|
|
270787
|
+
finalState = settled === "timeout" ? "processing" : (await getAppState(app.id)).status?.state ?? "ready";
|
|
270788
|
+
if (finalState === "ready") {
|
|
270789
|
+
previewUrl = await getPreviewUrl().catch(() => {
|
|
270790
|
+
return;
|
|
270791
|
+
});
|
|
270792
|
+
}
|
|
270793
|
+
} finally {
|
|
270794
|
+
stream.stop();
|
|
270795
|
+
}
|
|
270796
|
+
}
|
|
270797
|
+
if (jsonMode) {
|
|
270798
|
+
return {
|
|
270799
|
+
stdout: `${JSON.stringify({
|
|
270800
|
+
id: app.id,
|
|
270801
|
+
repo_url: app.repoUrl ?? null,
|
|
270802
|
+
editor_url: app.editorUrl,
|
|
270803
|
+
preview_url: previewUrl ?? null,
|
|
270804
|
+
dir: app.dirName,
|
|
270805
|
+
path: app.targetDir,
|
|
270806
|
+
status: finalState ?? "created"
|
|
270807
|
+
})}
|
|
270808
|
+
`
|
|
270809
|
+
};
|
|
270810
|
+
}
|
|
270811
|
+
if (previewUrl)
|
|
270812
|
+
log.message(`preview ${previewUrl}`);
|
|
270813
|
+
for (const line of nextStepsLines(app))
|
|
270814
|
+
log.message(line);
|
|
270815
|
+
if (finalState === "error") {
|
|
270816
|
+
return {
|
|
270817
|
+
outroMessage: `The first build reported an error — open the editor for details.`
|
|
270818
|
+
};
|
|
270819
|
+
}
|
|
270820
|
+
if (finalState === "processing") {
|
|
270821
|
+
return {
|
|
270822
|
+
outroMessage: `Still building — follow it with \`base44 builder status\`.`
|
|
270823
|
+
};
|
|
270797
270824
|
}
|
|
270798
270825
|
return {
|
|
270799
|
-
outroMessage:
|
|
270826
|
+
outroMessage: prompt ? `First build finished · ${formatDuration2(Date.now() - startedAt)}.` : "App created."
|
|
270800
270827
|
};
|
|
270801
270828
|
}
|
|
270802
|
-
|
|
270803
|
-
|
|
270804
|
-
|
|
270805
|
-
|
|
270806
|
-
return ssoEnableAction(context, options);
|
|
270807
|
-
}
|
|
270808
|
-
function getSSOCommand() {
|
|
270809
|
-
return new Base44Command("sso").description("Configure SSO identity provider (google, microsoft, github, okta, custom). SSO and social login are mutually exclusive — enabling one disables the other in the local auth config.").addArgument(new Argument2("<action>", "enable or disable SSO").choices([
|
|
270810
|
-
"enable",
|
|
270811
|
-
"disable"
|
|
270812
|
-
])).addOption(new Option2("--provider <provider>", "SSO provider").choices(Object.values(KNOWN_SSO_PROVIDERS))).option("--client-id <id>", "OAuth client ID").option("--client-secret <secret>", "OAuth client secret").option("--client-secret-stdin", "Read client secret from stdin").option("--env-file <path>", "Read client secret from a .env file (key: sso_client_secret)").option("--file <path>", "JSON config file with all SSO settings").option("--scope <scope>", "OAuth scope (defaults per provider)").option("--discovery-url <url>", "OIDC discovery URL").option("--tenant-id <id>", "Microsoft tenant ID (required for microsoft)").option("--okta-domain <domain>", "Okta domain (required for okta)").option("--auth-endpoint <url>", "Authorization endpoint (required for custom)").option("--token-endpoint <url>", "Token endpoint (required for custom)").option("--userinfo-endpoint <url>", "Userinfo endpoint (required for custom)").option("--jwks-uri <url>", "JWKS URI (required for custom)").option("--sso-name <name>", "Provider display name (required for custom)").action(ssoAction);
|
|
270813
|
-
}
|
|
270814
|
-
|
|
270815
|
-
// src/cli/commands/auth/index.ts
|
|
270816
|
-
function getAuthCommand() {
|
|
270817
|
-
return new Command2("auth").description("Manage app authentication settings").addCommand(getPasswordLoginCommand()).addCommand(getSocialLoginCommand()).addCommand(getSSOCommand()).addCommand(getAuthPullCommand()).addCommand(getAuthPushCommand());
|
|
270829
|
+
function getNewCommand() {
|
|
270830
|
+
const command = new Base44Command("new", { requireAppContext: false });
|
|
270831
|
+
command.description("Create an app and start building: from a prompt (the Base44 template), or over an existing GitHub repo with --import").argument("[prompt]", "What to build; the first agent turn starts immediately").option("--import <repo>", "Build over an existing GitHub repository instead of the template").option("--mode <mode>", "How to import: direct, fork, or copy (default: direct)").option("--name <name>", "Directory and app name (invented when omitted)").option("--path <dir>", "Directory to link (default: the current directory when empty, else ./<name>)").option("--repo-name <name>", "Name for the new GitHub repo when forking/copying").option("--from-branch <name>", "Import a specific branch of the repo").action(newAction);
|
|
270832
|
+
return command;
|
|
270818
270833
|
}
|
|
270819
270834
|
|
|
270820
|
-
// src/cli/commands/
|
|
270821
|
-
function
|
|
270822
|
-
|
|
270823
|
-
|
|
270824
|
-
|
|
270825
|
-
|
|
270835
|
+
// src/cli/commands/builder/send.ts
|
|
270836
|
+
function lastAssistantReply(turn) {
|
|
270837
|
+
const messages = turn.conversation?.messages ?? [];
|
|
270838
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
270839
|
+
const { role, content } = messages[i];
|
|
270840
|
+
if (role === "assistant" && typeof content === "string" && content.trim()) {
|
|
270841
|
+
return content.trim();
|
|
270842
|
+
}
|
|
270843
|
+
}
|
|
270844
|
+
return;
|
|
270826
270845
|
}
|
|
270827
|
-
|
|
270828
|
-
|
|
270829
|
-
|
|
270830
|
-
await
|
|
270831
|
-
|
|
270846
|
+
async function sendAction(ctx, message) {
|
|
270847
|
+
if (ctx.app)
|
|
270848
|
+
await assertBuilderApp(ctx.app.id);
|
|
270849
|
+
const branchId = await resolveBranchId(ctx);
|
|
270850
|
+
if (ctx.jsonMode) {
|
|
270851
|
+
const turn = await ctx.runTask("Agent working (a turn can take minutes)", () => sendTurn(message, branchId));
|
|
270852
|
+
if (turn.queued)
|
|
270853
|
+
return { stdout: `${JSON.stringify({ queued: true })}
|
|
270854
|
+
` };
|
|
270855
|
+
return {
|
|
270856
|
+
stdout: `${JSON.stringify({
|
|
270857
|
+
status: turn.status?.state ?? "ready",
|
|
270858
|
+
error_source: turn.status?.error_source ?? null,
|
|
270859
|
+
reply: lastAssistantReply(turn) ?? null
|
|
270860
|
+
})}
|
|
270861
|
+
`
|
|
270862
|
+
};
|
|
270863
|
+
}
|
|
270864
|
+
const stream = createTurnStream(process.stdout.isTTY === true);
|
|
270865
|
+
let turn;
|
|
270866
|
+
try {
|
|
270867
|
+
turn = await streamConversationDuring(() => sendTurn(message, branchId), stream.onEvent, { branchId });
|
|
270868
|
+
} finally {
|
|
270869
|
+
stream.stop();
|
|
270870
|
+
}
|
|
270871
|
+
if (turn.queued) {
|
|
270872
|
+
return {
|
|
270873
|
+
outroMessage: "The agent is busy with an earlier message — yours was queued and runs next."
|
|
270874
|
+
};
|
|
270875
|
+
}
|
|
270876
|
+
if (turn.status?.state === "error") {
|
|
270877
|
+
return {
|
|
270878
|
+
outroMessage: `Turn failed (${turn.status.error_source ?? "unknown"}) — see the editor for details.`
|
|
270879
|
+
};
|
|
270880
|
+
}
|
|
270881
|
+
return { outroMessage: "Turn finished." };
|
|
270832
270882
|
}
|
|
270833
|
-
function
|
|
270834
|
-
|
|
270835
|
-
|
|
270836
|
-
|
|
270837
|
-
}).description("Logout from current device").action(logout);
|
|
270883
|
+
function getSendCommand() {
|
|
270884
|
+
const command = new Base44Command("send", { supportsBranch: true });
|
|
270885
|
+
command.description("Send the agent one message and stream the turn until it finishes").argument("<message>", "What you want the agent to do").action(sendAction);
|
|
270886
|
+
return command;
|
|
270838
270887
|
}
|
|
270839
270888
|
|
|
270840
|
-
// src/cli/commands/
|
|
270841
|
-
async function
|
|
270842
|
-
const
|
|
270843
|
-
|
|
270889
|
+
// src/cli/commands/builder/status.ts
|
|
270890
|
+
async function statusAction(ctx) {
|
|
270891
|
+
const id = ctx.app?.id;
|
|
270892
|
+
const app = await ctx.runTask("Reading app status", () => getAppState(id));
|
|
270893
|
+
const state = app.status?.state ?? "ready";
|
|
270894
|
+
if (ctx.jsonMode) {
|
|
270844
270895
|
return {
|
|
270845
|
-
|
|
270896
|
+
stdout: `${JSON.stringify({ id: app.id, state, message: app.status?.message ?? null })}
|
|
270897
|
+
`
|
|
270846
270898
|
};
|
|
270847
270899
|
}
|
|
270848
|
-
|
|
270849
|
-
|
|
270900
|
+
ctx.log.message(`State: ${state}`);
|
|
270901
|
+
if (app.status?.message)
|
|
270902
|
+
ctx.log.message(`Note: ${app.status.message}`);
|
|
270903
|
+
return { outroMessage: "Status read." };
|
|
270850
270904
|
}
|
|
270851
|
-
function
|
|
270852
|
-
|
|
270905
|
+
function getStatusCommand() {
|
|
270906
|
+
const command = new Base44Command("status");
|
|
270907
|
+
command.description("Show whether the app is building, ready, or errored").action(statusAction);
|
|
270908
|
+
return command;
|
|
270853
270909
|
}
|
|
270854
270910
|
|
|
270855
|
-
// src/cli/commands/
|
|
270856
|
-
async function
|
|
270857
|
-
|
|
270858
|
-
runTask,
|
|
270859
|
-
jsonMode
|
|
270860
|
-
})
|
|
270861
|
-
const remote = await runTask("Fetching branches", () => listBranches());
|
|
270862
|
-
const branches = [
|
|
270863
|
-
{ name: "main", status: "active" },
|
|
270864
|
-
...remote.map((branch) => ({
|
|
270865
|
-
name: branch.branch_name,
|
|
270866
|
-
status: branch.status
|
|
270867
|
-
}))
|
|
270868
|
-
];
|
|
270869
|
-
if (jsonMode)
|
|
270870
|
-
return { stdout: `${JSON.stringify({ branches })}
|
|
270911
|
+
// src/cli/commands/builder/stop.ts
|
|
270912
|
+
async function stopAction(ctx) {
|
|
270913
|
+
const branchId = await resolveBranchId(ctx);
|
|
270914
|
+
await ctx.runTask("Stopping the running turn", () => stopTurn(branchId));
|
|
270915
|
+
if (ctx.jsonMode)
|
|
270916
|
+
return { stdout: `${JSON.stringify({ stopped: true })}
|
|
270871
270917
|
` };
|
|
270872
|
-
|
|
270873
|
-
log.message(`${branch.name} (${branch.status})`);
|
|
270874
|
-
return { outroMessage: `${branches.length} branches` };
|
|
270918
|
+
return { outroMessage: "Stopped." };
|
|
270875
270919
|
}
|
|
270876
|
-
function
|
|
270877
|
-
|
|
270920
|
+
function getStopCommand() {
|
|
270921
|
+
const command = new Base44Command("stop", { supportsBranch: true });
|
|
270922
|
+
command.description("Stop the agent's running turn").action(stopAction);
|
|
270923
|
+
return command;
|
|
270924
|
+
}
|
|
270925
|
+
|
|
270926
|
+
// src/cli/commands/builder/index.ts
|
|
270927
|
+
function getBuilderCommand() {
|
|
270928
|
+
return new Command2("builder").description("Build an app with the Base44 builder agent, non-interactively: create it, send turns, read status, stop, pick the model").addCommand(getNewCommand()).addCommand(getSendCommand()).addCommand(getStatusCommand()).addCommand(getStopCommand()).addCommand(getModelCommand());
|
|
270878
270929
|
}
|
|
270879
270930
|
|
|
270880
270931
|
// ../../node_modules/ink/build/render.js
|
|
@@ -276578,19 +276629,21 @@ async function runGenesisSession(options) {
|
|
|
276578
276629
|
|
|
276579
276630
|
// src/cli/commands/code/index.ts
|
|
276580
276631
|
var BRAND_ORANGE2 = "#E86B3C";
|
|
276581
|
-
async function bootstrapApp(prompt, footer, emit, importRepo) {
|
|
276632
|
+
async function bootstrapApp(prompt, footer, emit, onCreated, importRepo, path) {
|
|
276582
276633
|
let app;
|
|
276583
276634
|
try {
|
|
276584
|
-
app = await createAndLinkApp({ prompt, importRepo });
|
|
276635
|
+
app = await createAndLinkApp({ prompt, importRepo, path });
|
|
276585
276636
|
} catch (error) {
|
|
276586
276637
|
for (const line of await githubReauthLines(error) ?? [])
|
|
276587
276638
|
emit(line);
|
|
276588
276639
|
throw error;
|
|
276589
276640
|
}
|
|
276641
|
+
onCreated(app);
|
|
276642
|
+
footer.push(source_default.dim(`dir ${app.here ? "./" : `./${app.dirName}`}`));
|
|
276590
276643
|
if (app.repoUrl)
|
|
276591
276644
|
footer.push(terminalLink("repo", app.repoUrl));
|
|
276592
276645
|
footer.push(terminalLink("editor", app.editorUrl));
|
|
276593
|
-
emit(source_default.dim(`linked ./${app.dirName} (cd ${app.dirName} after the session)`));
|
|
276646
|
+
emit(source_default.dim(app.here ? "linked ./ (this directory)" : `linked ./${app.dirName} (cd ${app.dirName} after the session)`));
|
|
276594
276647
|
const branchId = await resolveActiveBranchId().catch(() => {
|
|
276595
276648
|
return;
|
|
276596
276649
|
});
|
|
@@ -276614,46 +276667,64 @@ async function bootstrapApp(prompt, footer, emit, importRepo) {
|
|
|
276614
276667
|
}
|
|
276615
276668
|
};
|
|
276616
276669
|
}
|
|
276617
|
-
async function codeAction(
|
|
276670
|
+
async function codeAction({ log }, options, appId) {
|
|
276671
|
+
const orange = source_default.hex(BRAND_ORANGE2);
|
|
276672
|
+
const chip = (label) => source_default.dim(`${orange("●")} ${label}`);
|
|
276618
276673
|
if (process.stdout.isTTY !== true) {
|
|
276619
276674
|
throw new InvalidInputError("base44 code is an interactive session and needs a terminal.");
|
|
276620
276675
|
}
|
|
276621
276676
|
let linked = false;
|
|
276622
276677
|
try {
|
|
276623
|
-
await initAppContext();
|
|
276678
|
+
await initAppContext(appId ? { appId } : {});
|
|
276624
276679
|
linked = true;
|
|
276625
276680
|
} catch {}
|
|
276626
276681
|
if (linked) {
|
|
276627
|
-
if (options.import) {
|
|
276628
|
-
throw new InvalidInputError("--import
|
|
276682
|
+
if (options.import || options.path) {
|
|
276683
|
+
throw new InvalidInputError("--import and --path create a new app; run them outside a linked project, without --app-id.");
|
|
276629
276684
|
}
|
|
276685
|
+
const { id, projectRoot } = getAppContext();
|
|
276686
|
+
const state = await assertBuilderApp(id);
|
|
276630
276687
|
const branchId = await resolveActiveBranchId().catch(() => {
|
|
276631
276688
|
return;
|
|
276632
276689
|
});
|
|
276633
276690
|
await runInteractiveSession({
|
|
276634
276691
|
branchId,
|
|
276635
|
-
footer: [],
|
|
276692
|
+
footer: [chip(appTypeChip(state))],
|
|
276636
276693
|
primeFirstPoll: true,
|
|
276637
276694
|
idleHint: "what should the agent do next?"
|
|
276638
276695
|
});
|
|
276639
|
-
|
|
276696
|
+
if (projectRoot) {
|
|
276697
|
+
log.message(source_default.dim(`app dir ${projectRoot}`));
|
|
276698
|
+
return {
|
|
276699
|
+
outroMessage: "Session closed. Run `base44 code` here to resume."
|
|
276700
|
+
};
|
|
276701
|
+
}
|
|
276702
|
+
return {
|
|
276703
|
+
outroMessage: `Session closed. Resume with \`base44 code --app-id ${id}\`.`
|
|
276704
|
+
};
|
|
276640
276705
|
}
|
|
276641
|
-
|
|
276642
|
-
const footer = [
|
|
276643
|
-
source_default.dim(`${orange("●")} ${options.import ? "import" : "builder"}`)
|
|
276644
|
-
];
|
|
276706
|
+
let created;
|
|
276707
|
+
const footer = [chip(options.import ? repoLabel(options.import) : "web app")];
|
|
276645
276708
|
await runGenesisSession({
|
|
276646
|
-
idleHint: options.import ? "describe what to build over the
|
|
276709
|
+
idleHint: options.import ? "describe what to build over the repository" : "describe the app you want to build · have one already? base44 code --app-id <id>, or base44 link",
|
|
276647
276710
|
creatingLabel: options.import ? "importing the repository" : "creating your app",
|
|
276648
|
-
modeLabel: options.import ? `
|
|
276711
|
+
modeLabel: options.import ? `Repository — ${repoLabel(options.import)}` : "Web app — Base44 template + builder agent",
|
|
276649
276712
|
footer,
|
|
276650
|
-
createApp: (prompt, emit) => bootstrapApp(prompt, footer, emit,
|
|
276713
|
+
createApp: (prompt, emit) => bootstrapApp(prompt, footer, emit, (app) => {
|
|
276714
|
+
created = app;
|
|
276715
|
+
}, options.import, options.path)
|
|
276651
276716
|
});
|
|
276652
|
-
|
|
276717
|
+
if (!created) {
|
|
276718
|
+
return { outroMessage: "Session closed. No app was created." };
|
|
276719
|
+
}
|
|
276720
|
+
for (const line of nextStepsLines(created))
|
|
276721
|
+
log.message(line);
|
|
276722
|
+
log.message(source_default.dim(` editor ${created.editorUrl}`));
|
|
276723
|
+
return { outroMessage: "Session closed." };
|
|
276653
276724
|
}
|
|
276654
276725
|
function getCodeCommand() {
|
|
276655
276726
|
const command = new Base44Command("code", { requireAppContext: false });
|
|
276656
|
-
command.description("Open Base44 Code
|
|
276727
|
+
command.description("Open Base44 Code, an interactive builder session. In a linked directory (or with --app-id <id>) it opens that app; anywhere else your first prompt creates one (--import <repo> to build over your own repository). Attach a directory to an existing app with base44 link.").option("--import <repo>", "Build over an existing GitHub repository instead of the Base44 template").option("--path <dir>", "Directory to link the new app to (default: the current directory when empty, else ./<name>)").action((ctx, options) => codeAction(ctx, options, command.optsWithGlobals().appId));
|
|
276657
276728
|
return command;
|
|
276658
276729
|
}
|
|
276659
276730
|
|
|
@@ -277451,10 +277522,10 @@ function getConnectorsListAvailableCommand() {
|
|
|
277451
277522
|
}
|
|
277452
277523
|
|
|
277453
277524
|
// src/cli/commands/connectors/pull.ts
|
|
277454
|
-
import { dirname as dirname19, join as join27, resolve as
|
|
277525
|
+
import { dirname as dirname19, join as join27, resolve as resolve9 } from "node:path";
|
|
277455
277526
|
async function resolveConnectorsDir(options) {
|
|
277456
277527
|
if (!getAppContext().projectRoot) {
|
|
277457
|
-
return
|
|
277528
|
+
return resolve9(options.dir ?? "connectors");
|
|
277458
277529
|
}
|
|
277459
277530
|
const { project } = await readProjectConfig();
|
|
277460
277531
|
return join27(dirname19(project.configPath), project.connectorsDir);
|
|
@@ -277498,10 +277569,10 @@ function getConnectorsPullCommand() {
|
|
|
277498
277569
|
}
|
|
277499
277570
|
|
|
277500
277571
|
// src/cli/commands/connectors/push.ts
|
|
277501
|
-
import { resolve as
|
|
277572
|
+
import { resolve as resolve10 } from "node:path";
|
|
277502
277573
|
async function readConnectorsToPush(options) {
|
|
277503
277574
|
if (!getAppContext().projectRoot) {
|
|
277504
|
-
return readAllConnectors(
|
|
277575
|
+
return readAllConnectors(resolve10(options.dir ?? "connectors"));
|
|
277505
277576
|
}
|
|
277506
277577
|
const { connectors } = await readProjectConfig();
|
|
277507
277578
|
return connectors;
|
|
@@ -277970,7 +278041,7 @@ function getBuildCommand() {
|
|
|
277970
278041
|
}
|
|
277971
278042
|
|
|
277972
278043
|
// src/cli/commands/project/create.ts
|
|
277973
|
-
import { basename as
|
|
278044
|
+
import { basename as basename7, resolve as resolve11 } from "node:path";
|
|
277974
278045
|
var import_kebabCase2 = __toESM(require_kebabCase(), 1);
|
|
277975
278046
|
|
|
277976
278047
|
// src/cli/commands/project/scaffold-shared.ts
|
|
@@ -278135,8 +278206,8 @@ async function createInteractive(options, ctx) {
|
|
|
278135
278206
|
name: () => {
|
|
278136
278207
|
return options.name ? Promise.resolve(options.name) : Ze({
|
|
278137
278208
|
message: "What is the name of your project?",
|
|
278138
|
-
placeholder:
|
|
278139
|
-
initialValue:
|
|
278209
|
+
placeholder: basename7(process.cwd()),
|
|
278210
|
+
initialValue: basename7(process.cwd()),
|
|
278140
278211
|
validate: (value) => {
|
|
278141
278212
|
if (!value || value.trim().length === 0) {
|
|
278142
278213
|
return "Every project deserves a name";
|
|
@@ -278166,7 +278237,7 @@ async function createInteractive(options, ctx) {
|
|
|
278166
278237
|
}, ctx);
|
|
278167
278238
|
}
|
|
278168
278239
|
async function createNonInteractive(options, ctx) {
|
|
278169
|
-
ctx.log.info(`Creating a new project at ${
|
|
278240
|
+
ctx.log.info(`Creating a new project at ${resolve11(options.path)}`);
|
|
278170
278241
|
const template = await getTemplateById(options.template ?? DEFAULT_TEMPLATE_ID);
|
|
278171
278242
|
return await executeCreate({
|
|
278172
278243
|
template,
|
|
@@ -278190,7 +278261,7 @@ async function executeCreate({
|
|
|
278190
278261
|
}, ctx) {
|
|
278191
278262
|
const { log, runTask } = ctx;
|
|
278192
278263
|
const name = rawName.trim();
|
|
278193
|
-
const resolvedPath =
|
|
278264
|
+
const resolvedPath = resolve11(projectPath);
|
|
278194
278265
|
const organizationId = await resolveWorkspaceId(ctx, flagWorkspaceId, isInteractive);
|
|
278195
278266
|
const { projectId } = await runTask("Setting up your project...", async () => {
|
|
278196
278267
|
return await createProjectFiles({
|
|
@@ -278831,7 +278902,7 @@ function getLogsCommand() {
|
|
|
278831
278902
|
}
|
|
278832
278903
|
|
|
278833
278904
|
// src/cli/commands/project/scaffold.ts
|
|
278834
|
-
import { basename as
|
|
278905
|
+
import { basename as basename8, resolve as resolve12 } from "node:path";
|
|
278835
278906
|
function resolveAppId(options) {
|
|
278836
278907
|
const appId = options.appId;
|
|
278837
278908
|
if (!appId) {
|
|
@@ -278847,8 +278918,8 @@ function resolveAppId(options) {
|
|
|
278847
278918
|
async function scaffoldAction(ctx, name, options, command) {
|
|
278848
278919
|
const { log, runTask } = ctx;
|
|
278849
278920
|
const appId = resolveAppId(command.optsWithGlobals());
|
|
278850
|
-
const resolvedPath =
|
|
278851
|
-
const projectName = (name ??
|
|
278921
|
+
const resolvedPath = resolve12("./");
|
|
278922
|
+
const projectName = (name ?? basename8(resolvedPath)).trim();
|
|
278852
278923
|
const template = await getTemplateById("backend-only");
|
|
278853
278924
|
log.info(`Scaffolding project at ${resolvedPath}`);
|
|
278854
278925
|
const { projectId } = await runTask("Setting up your project...", async () => {
|
|
@@ -279165,6 +279236,21 @@ function getSandboxListDirectoryCommand() {
|
|
|
279165
279236
|
return new Base44Command("ls", { supportsBranch: true }).description("List directory entries in an app's remote sandbox").argument("[path]", "Directory relative to the app root (default: app root)").option("--recursive", "List nested entries").option("--max-depth <n>", "Max depth when recursive (1-10, default 3)").option("--include-hidden", "Include dotfiles").action(listDirectoryAction);
|
|
279166
279237
|
}
|
|
279167
279238
|
|
|
279239
|
+
// src/cli/commands/sandbox/preview.ts
|
|
279240
|
+
async function previewAction(ctx) {
|
|
279241
|
+
const url = await ctx.runTask("Resolving preview URL (boots the sandbox if needed)", () => getPreviewUrl());
|
|
279242
|
+
if (ctx.jsonMode)
|
|
279243
|
+
return { stdout: `${JSON.stringify({ preview_url: url })}
|
|
279244
|
+
` };
|
|
279245
|
+
ctx.log.message(url);
|
|
279246
|
+
return { outroMessage: "Preview is live." };
|
|
279247
|
+
}
|
|
279248
|
+
function getSandboxPreviewCommand() {
|
|
279249
|
+
const command = new Base44Command("preview");
|
|
279250
|
+
command.description("Print the app's live preview URL").action(previewAction);
|
|
279251
|
+
return command;
|
|
279252
|
+
}
|
|
279253
|
+
|
|
279168
279254
|
// src/cli/commands/sandbox/read-file.ts
|
|
279169
279255
|
async function readFileAction({ runTask, branchId }, paths, options) {
|
|
279170
279256
|
const { id: appId } = getAppContext();
|
|
@@ -279218,7 +279304,7 @@ Examples:
|
|
|
279218
279304
|
|
|
279219
279305
|
// src/cli/commands/sandbox/index.ts
|
|
279220
279306
|
function getSandboxCommand() {
|
|
279221
|
-
return new Command2("sandbox").description("Develop an app remotely via its server-side sandbox").addCommand(getSandboxListDirectoryCommand()).addCommand(getSandboxReadFileCommand()).addCommand(getSandboxWriteFileCommand()).addCommand(getSandboxEditFileCommand()).addCommand(getSandboxGrepCommand()).addCommand(getSandboxRunCommandCommand()).addCommand(getSandboxCheckpointCommand());
|
|
279307
|
+
return new Command2("sandbox").description("Develop an app remotely via its server-side sandbox").addCommand(getSandboxListDirectoryCommand()).addCommand(getSandboxReadFileCommand()).addCommand(getSandboxWriteFileCommand()).addCommand(getSandboxEditFileCommand()).addCommand(getSandboxGrepCommand()).addCommand(getSandboxRunCommandCommand()).addCommand(getSandboxCheckpointCommand()).addCommand(getSandboxPreviewCommand());
|
|
279222
279308
|
}
|
|
279223
279309
|
|
|
279224
279310
|
// src/cli/commands/secrets/delete.ts
|
|
@@ -279264,7 +279350,7 @@ function getSecretsListCommand() {
|
|
|
279264
279350
|
}
|
|
279265
279351
|
|
|
279266
279352
|
// src/cli/commands/secrets/set.ts
|
|
279267
|
-
import { resolve as
|
|
279353
|
+
import { resolve as resolve13 } from "node:path";
|
|
279268
279354
|
function parseEntries(entries) {
|
|
279269
279355
|
const secrets = {};
|
|
279270
279356
|
for (const entry of entries) {
|
|
@@ -279295,7 +279381,7 @@ async function setSecretsAction({ log, runTask }, entries, options) {
|
|
|
279295
279381
|
validateInput(entries, options);
|
|
279296
279382
|
let secrets;
|
|
279297
279383
|
if (options.envFile) {
|
|
279298
|
-
secrets = await parseEnvFile(
|
|
279384
|
+
secrets = await parseEnvFile(resolve13(options.envFile));
|
|
279299
279385
|
if (Object.keys(secrets).length === 0) {
|
|
279300
279386
|
throw new InvalidInputError("The env file contains no valid KEY=VALUE entries.");
|
|
279301
279387
|
}
|
|
@@ -279324,7 +279410,7 @@ function getSecretsCommand() {
|
|
|
279324
279410
|
}
|
|
279325
279411
|
|
|
279326
279412
|
// src/cli/commands/site/deploy.ts
|
|
279327
|
-
import { resolve as
|
|
279413
|
+
import { resolve as resolve14 } from "node:path";
|
|
279328
279414
|
async function deployAction2(ctx, options) {
|
|
279329
279415
|
const { isNonInteractive } = ctx;
|
|
279330
279416
|
if (isNonInteractive && !options.yes) {
|
|
@@ -279402,7 +279488,7 @@ async function deployTarball({ runTask }, project) {
|
|
|
279402
279488
|
}
|
|
279403
279489
|
function siteOutputDir(project) {
|
|
279404
279490
|
const outputDirectory = project.site?.outputDirectory;
|
|
279405
|
-
return outputDirectory ?
|
|
279491
|
+
return outputDirectory ? resolve14(project.root, outputDirectory) : null;
|
|
279406
279492
|
}
|
|
279407
279493
|
function getSiteDeployCommand() {
|
|
279408
279494
|
const command = new Base44Command("deploy").description("Deploy built site files to Base44 hosting").option("-y, --yes", "Skip confirmation prompt").option("--build", "Build the site before deploying (skips the prompt)").option("--no-build", "Deploy without building (skips the prompt)");
|
|
@@ -281904,7 +281990,7 @@ function createCustomIntegrationRoutes(remoteProxy, logger) {
|
|
|
281904
281990
|
|
|
281905
281991
|
// src/cli/dev/dev-server/watcher.ts
|
|
281906
281992
|
import { EventEmitter as EventEmitter6 } from "node:events";
|
|
281907
|
-
import { relative as
|
|
281993
|
+
import { relative as relative10 } from "node:path";
|
|
281908
281994
|
|
|
281909
281995
|
// ../../node_modules/chokidar/index.js
|
|
281910
281996
|
import { EventEmitter as EventEmitter5 } from "node:events";
|
|
@@ -283589,7 +283675,7 @@ class WatchBase44 extends EventEmitter6 {
|
|
|
283589
283675
|
ignoreInitial: true
|
|
283590
283676
|
});
|
|
283591
283677
|
watcher.on("all", import_debounce4.default(async (_event, path) => {
|
|
283592
|
-
this.emit("change", name,
|
|
283678
|
+
this.emit("change", name, relative10(targetPath, path));
|
|
283593
283679
|
}, WATCH_DEBOUNCE_MS));
|
|
283594
283680
|
watcher.on("error", (err) => {
|
|
283595
283681
|
this.logger.error(`Watch handler failed for ${targetPath}`, err);
|
|
@@ -284099,7 +284185,7 @@ Examples:
|
|
|
284099
284185
|
}
|
|
284100
284186
|
|
|
284101
284187
|
// src/cli/commands/project/eject.ts
|
|
284102
|
-
import { resolve as
|
|
284188
|
+
import { resolve as resolve18 } from "node:path";
|
|
284103
284189
|
var import_kebabCase3 = __toESM(require_kebabCase(), 1);
|
|
284104
284190
|
async function eject(ctx, options, command) {
|
|
284105
284191
|
const { log, runTask, isNonInteractive } = ctx;
|
|
@@ -284163,7 +284249,7 @@ async function eject(ctx, options, command) {
|
|
|
284163
284249
|
Ne("Operation cancelled.");
|
|
284164
284250
|
throw new CLIExitError(0);
|
|
284165
284251
|
}
|
|
284166
|
-
const resolvedPath =
|
|
284252
|
+
const resolvedPath = resolve18(selectedPath);
|
|
284167
284253
|
await runTask("Downloading your project's code...", async (updateMessage) => {
|
|
284168
284254
|
await createProjectFilesForExistingProject({
|
|
284169
284255
|
projectId,
|
|
@@ -284245,7 +284331,7 @@ function createProgram(context) {
|
|
|
284245
284331
|
program.addCommand(getSecretsCommand());
|
|
284246
284332
|
program.addCommand(getSandboxCommand());
|
|
284247
284333
|
program.addCommand(getBranchesCommand());
|
|
284248
|
-
program.addCommand(
|
|
284334
|
+
program.addCommand(getBuilderCommand());
|
|
284249
284335
|
program.addCommand(getCodeCommand());
|
|
284250
284336
|
program.addCommand(getAuthCommand());
|
|
284251
284337
|
program.addCommand(getSiteCommand());
|
|
@@ -288300,4 +288386,4 @@ export {
|
|
|
288300
288386
|
runCLI
|
|
288301
288387
|
};
|
|
288302
288388
|
|
|
288303
|
-
//# debugId=
|
|
288389
|
+
//# debugId=DDB3983E5E326EC264756E2164756E21
|