@kivacore/cli 0.13.1 → 0.13.3
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/README.md +14 -7
- package/main.js +558 -408
- package/main.js.map +4 -4
- package/package.json +1 -1
- package/resources/pi-agent/prompts/agent-system.md +15 -1
- package/resources/pi-agent/prompts/coder-system.md +2 -1
package/main.js
CHANGED
|
@@ -89093,7 +89093,7 @@ import { createHash as createHash3 } from "node:crypto";
|
|
|
89093
89093
|
import { existsSync as existsSync14 } from "node:fs";
|
|
89094
89094
|
import fs11 from "node:fs/promises";
|
|
89095
89095
|
import path9 from "node:path";
|
|
89096
|
-
function
|
|
89096
|
+
function isRecord8(value2) {
|
|
89097
89097
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
89098
89098
|
}
|
|
89099
89099
|
function isNonEmptyString(value2) {
|
|
@@ -89205,14 +89205,14 @@ function migrateV1ToV2(v1) {
|
|
|
89205
89205
|
return { version: 2, projectVersion: "0.1.0", phases, features, tasks };
|
|
89206
89206
|
}
|
|
89207
89207
|
function parseV1Graph(rawValue) {
|
|
89208
|
-
const sections = Array.isArray(rawValue.sections) ? rawValue.sections.filter((value2) =>
|
|
89208
|
+
const sections = Array.isArray(rawValue.sections) ? rawValue.sections.filter((value2) => isRecord8(value2)).map((value2) => ({
|
|
89209
89209
|
id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
|
|
89210
89210
|
title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
|
|
89211
89211
|
slug: isNonEmptyString(value2.slug) ? value2.slug.trim() : "",
|
|
89212
89212
|
summary: typeof value2.summary === "string" ? value2.summary.trim() : "",
|
|
89213
89213
|
...typeof value2.order === "number" ? { order: value2.order } : {}
|
|
89214
89214
|
})).filter((value2) => value2.id.length > 0) : [];
|
|
89215
|
-
const features = Array.isArray(rawValue.features) ? rawValue.features.filter((value2) =>
|
|
89215
|
+
const features = Array.isArray(rawValue.features) ? rawValue.features.filter((value2) => isRecord8(value2)).map((value2) => ({
|
|
89216
89216
|
id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
|
|
89217
89217
|
title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
|
|
89218
89218
|
slug: isNonEmptyString(value2.slug) ? value2.slug.trim() : "",
|
|
@@ -89220,7 +89220,7 @@ function parseV1Graph(rawValue) {
|
|
|
89220
89220
|
sectionId: isNonEmptyString(value2.sectionId) ? value2.sectionId.trim() : "",
|
|
89221
89221
|
...typeof value2.order === "number" ? { order: value2.order } : {}
|
|
89222
89222
|
})).filter((value2) => value2.id.length > 0) : [];
|
|
89223
|
-
const tasks = Array.isArray(rawValue.tasks) ? rawValue.tasks.filter((value2) =>
|
|
89223
|
+
const tasks = Array.isArray(rawValue.tasks) ? rawValue.tasks.filter((value2) => isRecord8(value2)).map((value2) => ({
|
|
89224
89224
|
id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
|
|
89225
89225
|
title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
|
|
89226
89226
|
summary: typeof value2.summary === "string" ? value2.summary.trim() : "",
|
|
@@ -89236,7 +89236,7 @@ function parseV1Graph(rawValue) {
|
|
|
89236
89236
|
}
|
|
89237
89237
|
function parseV2Graph(rawValue) {
|
|
89238
89238
|
const projectVersion = isNonEmptyString(rawValue.projectVersion) ? rawValue.projectVersion.trim() : "0.1.0";
|
|
89239
|
-
const phases = Array.isArray(rawValue.phases) ? rawValue.phases.filter((value2) =>
|
|
89239
|
+
const phases = Array.isArray(rawValue.phases) ? rawValue.phases.filter((value2) => isRecord8(value2)).map((value2) => ({
|
|
89240
89240
|
id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
|
|
89241
89241
|
title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
|
|
89242
89242
|
slug: isNonEmptyString(value2.slug) ? value2.slug.trim() : "",
|
|
@@ -89244,7 +89244,7 @@ function parseV2Graph(rawValue) {
|
|
|
89244
89244
|
...isNonEmptyString(value2.projectVersion) ? { projectVersion: value2.projectVersion.trim() } : {},
|
|
89245
89245
|
...typeof value2.order === "number" ? { order: value2.order } : {}
|
|
89246
89246
|
})).filter((value2) => value2.id.length > 0) : [];
|
|
89247
|
-
const features = Array.isArray(rawValue.features) ? rawValue.features.filter((value2) =>
|
|
89247
|
+
const features = Array.isArray(rawValue.features) ? rawValue.features.filter((value2) => isRecord8(value2)).map((value2) => ({
|
|
89248
89248
|
id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
|
|
89249
89249
|
title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
|
|
89250
89250
|
slug: isNonEmptyString(value2.slug) ? value2.slug.trim() : "",
|
|
@@ -89254,7 +89254,7 @@ function parseV2Graph(rawValue) {
|
|
|
89254
89254
|
...isNonEmptyString(value2.projectVersion) ? { projectVersion: value2.projectVersion.trim() } : {},
|
|
89255
89255
|
...typeof value2.order === "number" ? { order: value2.order } : {}
|
|
89256
89256
|
})).filter((value2) => value2.id.length > 0) : [];
|
|
89257
|
-
const tasks = Array.isArray(rawValue.tasks) ? rawValue.tasks.filter((value2) =>
|
|
89257
|
+
const tasks = Array.isArray(rawValue.tasks) ? rawValue.tasks.filter((value2) => isRecord8(value2)).map((value2) => ({
|
|
89258
89258
|
id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
|
|
89259
89259
|
title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
|
|
89260
89260
|
summary: typeof value2.summary === "string" ? value2.summary.trim() : "",
|
|
@@ -89269,7 +89269,7 @@ function parseV2Graph(rawValue) {
|
|
|
89269
89269
|
return sortGraph({ version: 2, projectVersion, phases, features, tasks });
|
|
89270
89270
|
}
|
|
89271
89271
|
function parseProjectPlanGraph(rawValue) {
|
|
89272
|
-
if (!
|
|
89272
|
+
if (!isRecord8(rawValue)) {
|
|
89273
89273
|
return createEmptyProjectPlanGraph();
|
|
89274
89274
|
}
|
|
89275
89275
|
if (rawValue.version === 2) {
|
|
@@ -97698,7 +97698,7 @@ function resolveDisplayName(name3, aliases) {
|
|
|
97698
97698
|
// package.json
|
|
97699
97699
|
var package_default = {
|
|
97700
97700
|
name: "@kivacore/cli",
|
|
97701
|
-
version: "0.13.
|
|
97701
|
+
version: "0.13.3",
|
|
97702
97702
|
private: false,
|
|
97703
97703
|
description: "KIVA API CLI",
|
|
97704
97704
|
bin: {
|
|
@@ -100200,8 +100200,36 @@ var StudioResolver = class {
|
|
|
100200
100200
|
if (dataSourceId) {
|
|
100201
100201
|
return dataSourceId;
|
|
100202
100202
|
}
|
|
100203
|
-
|
|
100204
|
-
|
|
100203
|
+
try {
|
|
100204
|
+
const dataSources = await this.getDataSourcesForApp(options.appId);
|
|
100205
|
+
return resolveBySlug("Data source", dataSources, dataSourceSlug);
|
|
100206
|
+
} catch (error62) {
|
|
100207
|
+
const systemAppSlug = lookupSystemAppSlugById(options.appId);
|
|
100208
|
+
if (!systemAppSlug || !(error62 instanceof ApiResponseError) || error62.httpStatusCode !== 404) {
|
|
100209
|
+
throw error62;
|
|
100210
|
+
}
|
|
100211
|
+
return await this.#resolveSystemDataSourceId({ appSlug: systemAppSlug, dataSourceSlug });
|
|
100212
|
+
}
|
|
100213
|
+
}
|
|
100214
|
+
async #resolveSystemDataSourceId(params) {
|
|
100215
|
+
const notFound = new UserInputError(`Data source slug '${params.dataSourceSlug}' was not found in app '${params.appSlug}'.`);
|
|
100216
|
+
try {
|
|
100217
|
+
const response = await this.apiClient.request({
|
|
100218
|
+
method: "GET",
|
|
100219
|
+
path: `/dsql/schema/apps/${encodeURIComponent(params.appSlug)}/data-sources/${encodeURIComponent(params.dataSourceSlug)}`
|
|
100220
|
+
});
|
|
100221
|
+
const payload = isRecord3(response.data) && isRecord3(response.data.data) ? response.data.data : response.data;
|
|
100222
|
+
const id = isRecord3(payload) ? extractString(payload, "id") : void 0;
|
|
100223
|
+
if (!id) {
|
|
100224
|
+
throw notFound;
|
|
100225
|
+
}
|
|
100226
|
+
return id;
|
|
100227
|
+
} catch (error62) {
|
|
100228
|
+
if (error62 instanceof ApiResponseError && error62.httpStatusCode === 404) {
|
|
100229
|
+
throw notFound;
|
|
100230
|
+
}
|
|
100231
|
+
throw error62;
|
|
100232
|
+
}
|
|
100205
100233
|
}
|
|
100206
100234
|
async resolveAppSlug(options) {
|
|
100207
100235
|
const appId = normalizeOptional(options.appId);
|
|
@@ -102568,6 +102596,9 @@ function extractAppRecords(payload) {
|
|
|
102568
102596
|
}
|
|
102569
102597
|
return [];
|
|
102570
102598
|
}
|
|
102599
|
+
function isRecord4(value2) {
|
|
102600
|
+
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
102601
|
+
}
|
|
102571
102602
|
function extractString2(record2, key) {
|
|
102572
102603
|
const value2 = record2[key];
|
|
102573
102604
|
return typeof value2 === "string" && value2.length > 0 ? value2 : void 0;
|
|
@@ -103040,7 +103071,17 @@ async function offerWorkspaceAgentSkills(dir) {
|
|
|
103040
103071
|
promptFn: async (question) => await promptYesNo({ question })
|
|
103041
103072
|
});
|
|
103042
103073
|
}
|
|
103074
|
+
function filterApiClientsByAppSlug(payload, appSlug) {
|
|
103075
|
+
if (!appSlug || !isRecord4(payload) || !Array.isArray(payload.data)) {
|
|
103076
|
+
return payload;
|
|
103077
|
+
}
|
|
103078
|
+
const data = payload.data.filter(
|
|
103079
|
+
(client) => isRecord4(client) && Array.isArray(client.tenant_apps) && client.tenant_apps.some((app) => isRecord4(app) && extractString2(app, "slug") === appSlug)
|
|
103080
|
+
);
|
|
103081
|
+
return { ...payload, data };
|
|
103082
|
+
}
|
|
103043
103083
|
function createAppsCli(dependencies) {
|
|
103084
|
+
const isIncluded = (name3) => !dependencies.excludedCommands?.includes(name3);
|
|
103044
103085
|
const appsCli = Cli_exports.create("apps", {
|
|
103045
103086
|
description: "App commands",
|
|
103046
103087
|
env: EnvSchema
|
|
@@ -103069,6 +103110,22 @@ function createAppsCli(dependencies) {
|
|
|
103069
103110
|
});
|
|
103070
103111
|
}
|
|
103071
103112
|
});
|
|
103113
|
+
appsCli.command("list-api-clients", {
|
|
103114
|
+
description: "List the organization's API (OAuth2) clients: client id, redirect URIs and scopes, the API app each belongs to and the apps each is assigned to",
|
|
103115
|
+
options: external_exports.object({
|
|
103116
|
+
appSlug: external_exports.string().optional().describe("Only the clients assigned to the app with this slug")
|
|
103117
|
+
}),
|
|
103118
|
+
run: async (context) => {
|
|
103119
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103120
|
+
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
103121
|
+
const response = await apiClient.request({ method: "GET", path: "/api/clients" });
|
|
103122
|
+
return await injectContext({
|
|
103123
|
+
apiBaseUrl,
|
|
103124
|
+
authStore: dependencies.authStore,
|
|
103125
|
+
payload: filterApiClientsByAppSlug(response.data, normalizeOptional2(context.options.appSlug))
|
|
103126
|
+
});
|
|
103127
|
+
}
|
|
103128
|
+
});
|
|
103072
103129
|
appsCli.command("update", {
|
|
103073
103130
|
description: "Update an app. Store fields and array/object values must be passed via --data/--from-file.",
|
|
103074
103131
|
options: external_exports.object({
|
|
@@ -103361,39 +103418,41 @@ function createAppsCli(dependencies) {
|
|
|
103361
103418
|
});
|
|
103362
103419
|
}
|
|
103363
103420
|
});
|
|
103364
|
-
|
|
103365
|
-
|
|
103366
|
-
|
|
103367
|
-
|
|
103368
|
-
|
|
103369
|
-
|
|
103370
|
-
|
|
103371
|
-
|
|
103372
|
-
|
|
103373
|
-
|
|
103374
|
-
|
|
103375
|
-
|
|
103376
|
-
|
|
103377
|
-
|
|
103378
|
-
|
|
103379
|
-
|
|
103380
|
-
|
|
103381
|
-
|
|
103382
|
-
|
|
103383
|
-
|
|
103384
|
-
|
|
103385
|
-
|
|
103386
|
-
|
|
103387
|
-
|
|
103388
|
-
|
|
103389
|
-
|
|
103390
|
-
|
|
103391
|
-
|
|
103392
|
-
|
|
103393
|
-
|
|
103394
|
-
|
|
103395
|
-
|
|
103396
|
-
|
|
103421
|
+
if (isIncluded("clone")) {
|
|
103422
|
+
appsCli.command("clone", {
|
|
103423
|
+
description: "Clone an existing app's repo locally and write a .env for development",
|
|
103424
|
+
options: external_exports.object({
|
|
103425
|
+
appId: external_exports.string().optional().describe("App ID (one of --app-id/--app-slug)"),
|
|
103426
|
+
appSlug: external_exports.string().optional().describe("App slug (one of --app-id/--app-slug)"),
|
|
103427
|
+
dir: external_exports.string().optional().describe("Target directory (default ./<repoName>)"),
|
|
103428
|
+
clientId: external_exports.string().optional().describe("Override the OAuth client id written to .env")
|
|
103429
|
+
}),
|
|
103430
|
+
run: async (context) => {
|
|
103431
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103432
|
+
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
103433
|
+
const appId = await resolveAppId({
|
|
103434
|
+
apiClient,
|
|
103435
|
+
appId: context.options.appId,
|
|
103436
|
+
appSlug: context.options.appSlug
|
|
103437
|
+
});
|
|
103438
|
+
const workspace = await setupLocalWorkspace({
|
|
103439
|
+
apiClient,
|
|
103440
|
+
environmentConfigService: dependencies.environmentConfigService,
|
|
103441
|
+
authStore: dependencies.authStore,
|
|
103442
|
+
apiBaseUrl,
|
|
103443
|
+
appId,
|
|
103444
|
+
clientIdOverride: normalizeOptional2(context.options.clientId),
|
|
103445
|
+
targetDir: normalizeOptional2(context.options.dir)
|
|
103446
|
+
});
|
|
103447
|
+
await offerWorkspaceAgentSkills(workspace.path);
|
|
103448
|
+
return await injectContext({
|
|
103449
|
+
apiBaseUrl,
|
|
103450
|
+
authStore: dependencies.authStore,
|
|
103451
|
+
payload: { appId, ...workspace }
|
|
103452
|
+
});
|
|
103453
|
+
}
|
|
103454
|
+
});
|
|
103455
|
+
}
|
|
103397
103456
|
appsCli.command(buildActionsCli(dependencies));
|
|
103398
103457
|
appsCli.command(buildAiToolsCli(dependencies));
|
|
103399
103458
|
return appsCli;
|
|
@@ -103698,60 +103757,104 @@ async function loginWithManualTokens(params) {
|
|
|
103698
103757
|
return profile;
|
|
103699
103758
|
}
|
|
103700
103759
|
function createAuthCli(dependencies) {
|
|
103760
|
+
const isIncluded = (name3) => !dependencies.excludedCommands?.includes(name3);
|
|
103701
103761
|
const authCli = Cli_exports.create("auth", {
|
|
103702
103762
|
description: "Authentication commands",
|
|
103703
103763
|
env: EnvSchema
|
|
103704
103764
|
});
|
|
103705
|
-
|
|
103706
|
-
|
|
103707
|
-
|
|
103708
|
-
|
|
103709
|
-
|
|
103710
|
-
|
|
103711
|
-
|
|
103712
|
-
|
|
103713
|
-
|
|
103714
|
-
|
|
103715
|
-
|
|
103716
|
-
|
|
103717
|
-
|
|
103718
|
-
|
|
103719
|
-
|
|
103720
|
-
|
|
103721
|
-
|
|
103722
|
-
|
|
103723
|
-
|
|
103724
|
-
|
|
103725
|
-
|
|
103726
|
-
|
|
103727
|
-
|
|
103728
|
-
|
|
103729
|
-
|
|
103730
|
-
|
|
103731
|
-
|
|
103765
|
+
if (isIncluded("login")) {
|
|
103766
|
+
authCli.command("login", {
|
|
103767
|
+
description: "Authorize CLI using OAuth2 device flow",
|
|
103768
|
+
options: external_exports.object({
|
|
103769
|
+
clientId: external_exports.string().optional().describe("OAuth2 client id"),
|
|
103770
|
+
scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes"),
|
|
103771
|
+
accessToken: external_exports.string().optional().describe("Manual access token; skips device flow"),
|
|
103772
|
+
refreshToken: external_exports.string().optional().describe("Manual refresh token used with --accessToken")
|
|
103773
|
+
}),
|
|
103774
|
+
run: async (context) => {
|
|
103775
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103776
|
+
const manualAccessToken = context.options.accessToken?.trim();
|
|
103777
|
+
const manualRefreshToken = context.options.refreshToken?.trim();
|
|
103778
|
+
if (manualRefreshToken && !manualAccessToken) {
|
|
103779
|
+
throw new UserInputError("refreshToken requires accessToken. Pass --accessToken when using --refreshToken.");
|
|
103780
|
+
}
|
|
103781
|
+
const resolvedClient = await resolveClientId({
|
|
103782
|
+
requestedClientId: context.options.clientId,
|
|
103783
|
+
env: context.env,
|
|
103784
|
+
environmentConfigService: dependencies.environmentConfigService,
|
|
103785
|
+
globalEnvironmentConfigService: dependencies.globalEnvironmentConfigService,
|
|
103786
|
+
allowManualFallback: Boolean(manualAccessToken)
|
|
103787
|
+
});
|
|
103788
|
+
const clientId = resolvedClient.clientId;
|
|
103789
|
+
if (!clientId) {
|
|
103790
|
+
throw new UserInputError(
|
|
103791
|
+
"Client ID is required. Pass --clientId, set KIVA_API_CLIENT_ID, or login once with --clientId to save it."
|
|
103792
|
+
);
|
|
103793
|
+
}
|
|
103794
|
+
let cleanupOpenInBrowserListener = () => {
|
|
103795
|
+
};
|
|
103796
|
+
try {
|
|
103797
|
+
const profile = manualAccessToken ? await loginWithManualTokens({
|
|
103798
|
+
apiBaseUrl,
|
|
103799
|
+
accessToken: manualAccessToken,
|
|
103800
|
+
refreshToken: manualRefreshToken,
|
|
103801
|
+
clientId: context.options.clientId,
|
|
103802
|
+
scope: context.options.scope,
|
|
103803
|
+
dependencies,
|
|
103804
|
+
env: context.env
|
|
103805
|
+
}) : await dependencies.createAuthSessionService(apiBaseUrl).loginWithDeviceFlow({
|
|
103806
|
+
clientId,
|
|
103807
|
+
scope: context.options.scope,
|
|
103808
|
+
onVerification: (verification) => {
|
|
103809
|
+
logVerificationHint(verification, context.agent, dependencies.onMessage);
|
|
103810
|
+
cleanupOpenInBrowserListener = listenForEnterToOpenBrowser(verification.verificationUriComplete, context.agent);
|
|
103811
|
+
}
|
|
103812
|
+
});
|
|
103813
|
+
if (!manualAccessToken && resolvedClient.resolvedClientId) {
|
|
103814
|
+
await dependencies.environmentConfigService.setDefaultClientId(resolvedClient.resolvedClientId);
|
|
103815
|
+
}
|
|
103816
|
+
return await injectContext({
|
|
103817
|
+
apiBaseUrl,
|
|
103818
|
+
authStore: dependencies.authStore,
|
|
103819
|
+
payload: {
|
|
103820
|
+
authenticated: true,
|
|
103821
|
+
apiBaseUrl,
|
|
103822
|
+
userId: profile.userId,
|
|
103823
|
+
email: profile.email,
|
|
103824
|
+
tenantId: profile.tenantId,
|
|
103825
|
+
tenantName: profile.tenantName,
|
|
103826
|
+
tenantNo: profile.tenantNo,
|
|
103827
|
+
clientId: profile.clientId,
|
|
103828
|
+
scope: profile.scope,
|
|
103829
|
+
expiresAt: profile.expiresAt
|
|
103830
|
+
}
|
|
103831
|
+
});
|
|
103832
|
+
} finally {
|
|
103833
|
+
cleanupOpenInBrowserListener();
|
|
103834
|
+
}
|
|
103732
103835
|
}
|
|
103733
|
-
|
|
103734
|
-
|
|
103735
|
-
|
|
103736
|
-
|
|
103836
|
+
});
|
|
103837
|
+
}
|
|
103838
|
+
if (isIncluded("set-tokens")) {
|
|
103839
|
+
authCli.command("set-tokens", {
|
|
103840
|
+
description: "Set custom access and refresh tokens for the active environment",
|
|
103841
|
+
options: external_exports.object({
|
|
103842
|
+
clientId: external_exports.string().optional().describe("OAuth2 client id"),
|
|
103843
|
+
scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes"),
|
|
103844
|
+
accessToken: external_exports.string().min(1).describe("Custom access token"),
|
|
103845
|
+
refreshToken: external_exports.string().optional().describe("Custom refresh token")
|
|
103846
|
+
}),
|
|
103847
|
+
run: async (context) => {
|
|
103848
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103849
|
+
const profile = await loginWithManualTokens({
|
|
103737
103850
|
apiBaseUrl,
|
|
103738
|
-
accessToken:
|
|
103739
|
-
refreshToken:
|
|
103851
|
+
accessToken: context.options.accessToken,
|
|
103852
|
+
refreshToken: context.options.refreshToken,
|
|
103740
103853
|
clientId: context.options.clientId,
|
|
103741
103854
|
scope: context.options.scope,
|
|
103742
103855
|
dependencies,
|
|
103743
103856
|
env: context.env
|
|
103744
|
-
}) : await dependencies.createAuthSessionService(apiBaseUrl).loginWithDeviceFlow({
|
|
103745
|
-
clientId,
|
|
103746
|
-
scope: context.options.scope,
|
|
103747
|
-
onVerification: (verification) => {
|
|
103748
|
-
logVerificationHint(verification, context.agent, dependencies.onMessage);
|
|
103749
|
-
cleanupOpenInBrowserListener = listenForEnterToOpenBrowser(verification.verificationUriComplete, context.agent);
|
|
103750
|
-
}
|
|
103751
103857
|
});
|
|
103752
|
-
if (!manualAccessToken && resolvedClient.resolvedClientId) {
|
|
103753
|
-
await dependencies.environmentConfigService.setDefaultClientId(resolvedClient.resolvedClientId);
|
|
103754
|
-
}
|
|
103755
103858
|
return await injectContext({
|
|
103756
103859
|
apiBaseUrl,
|
|
103757
103860
|
authStore: dependencies.authStore,
|
|
@@ -103768,48 +103871,9 @@ function createAuthCli(dependencies) {
|
|
|
103768
103871
|
expiresAt: profile.expiresAt
|
|
103769
103872
|
}
|
|
103770
103873
|
});
|
|
103771
|
-
} finally {
|
|
103772
|
-
cleanupOpenInBrowserListener();
|
|
103773
103874
|
}
|
|
103774
|
-
}
|
|
103775
|
-
}
|
|
103776
|
-
authCli.command("set-tokens", {
|
|
103777
|
-
description: "Set custom access and refresh tokens for the active environment",
|
|
103778
|
-
options: external_exports.object({
|
|
103779
|
-
clientId: external_exports.string().optional().describe("OAuth2 client id"),
|
|
103780
|
-
scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes"),
|
|
103781
|
-
accessToken: external_exports.string().min(1).describe("Custom access token"),
|
|
103782
|
-
refreshToken: external_exports.string().optional().describe("Custom refresh token")
|
|
103783
|
-
}),
|
|
103784
|
-
run: async (context) => {
|
|
103785
|
-
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103786
|
-
const profile = await loginWithManualTokens({
|
|
103787
|
-
apiBaseUrl,
|
|
103788
|
-
accessToken: context.options.accessToken,
|
|
103789
|
-
refreshToken: context.options.refreshToken,
|
|
103790
|
-
clientId: context.options.clientId,
|
|
103791
|
-
scope: context.options.scope,
|
|
103792
|
-
dependencies,
|
|
103793
|
-
env: context.env
|
|
103794
|
-
});
|
|
103795
|
-
return await injectContext({
|
|
103796
|
-
apiBaseUrl,
|
|
103797
|
-
authStore: dependencies.authStore,
|
|
103798
|
-
payload: {
|
|
103799
|
-
authenticated: true,
|
|
103800
|
-
apiBaseUrl,
|
|
103801
|
-
userId: profile.userId,
|
|
103802
|
-
email: profile.email,
|
|
103803
|
-
tenantId: profile.tenantId,
|
|
103804
|
-
tenantName: profile.tenantName,
|
|
103805
|
-
tenantNo: profile.tenantNo,
|
|
103806
|
-
clientId: profile.clientId,
|
|
103807
|
-
scope: profile.scope,
|
|
103808
|
-
expiresAt: profile.expiresAt
|
|
103809
|
-
}
|
|
103810
|
-
});
|
|
103811
|
-
}
|
|
103812
|
-
});
|
|
103875
|
+
});
|
|
103876
|
+
}
|
|
103813
103877
|
const accountsCli = Cli_exports.create("accounts", {
|
|
103814
103878
|
description: "Account management",
|
|
103815
103879
|
env: EnvSchema
|
|
@@ -103827,27 +103891,29 @@ function createAuthCli(dependencies) {
|
|
|
103827
103891
|
});
|
|
103828
103892
|
}
|
|
103829
103893
|
});
|
|
103830
|
-
|
|
103831
|
-
|
|
103832
|
-
|
|
103833
|
-
|
|
103834
|
-
|
|
103835
|
-
|
|
103836
|
-
|
|
103837
|
-
|
|
103838
|
-
|
|
103839
|
-
|
|
103840
|
-
|
|
103841
|
-
|
|
103842
|
-
|
|
103843
|
-
|
|
103844
|
-
|
|
103845
|
-
|
|
103846
|
-
|
|
103847
|
-
|
|
103848
|
-
|
|
103849
|
-
|
|
103850
|
-
|
|
103894
|
+
if (isIncluded("accounts use")) {
|
|
103895
|
+
accountsCli.command("use", {
|
|
103896
|
+
description: "Switch active account by user ID",
|
|
103897
|
+
options: external_exports.object({
|
|
103898
|
+
userId: external_exports.string().min(1).describe("User ID to activate")
|
|
103899
|
+
}),
|
|
103900
|
+
run: async (context) => {
|
|
103901
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103902
|
+
const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
|
|
103903
|
+
const switched = await authSessionService.switchAccount({
|
|
103904
|
+
userId: context.options.userId
|
|
103905
|
+
});
|
|
103906
|
+
return await injectContext({
|
|
103907
|
+
apiBaseUrl,
|
|
103908
|
+
authStore: dependencies.authStore,
|
|
103909
|
+
payload: {
|
|
103910
|
+
switched: true,
|
|
103911
|
+
...switched
|
|
103912
|
+
}
|
|
103913
|
+
});
|
|
103914
|
+
}
|
|
103915
|
+
});
|
|
103916
|
+
}
|
|
103851
103917
|
authCli.command(accountsCli);
|
|
103852
103918
|
const tenantsCli = Cli_exports.create("tenants", {
|
|
103853
103919
|
description: "Tenant management",
|
|
@@ -103871,67 +103937,71 @@ function createAuthCli(dependencies) {
|
|
|
103871
103937
|
});
|
|
103872
103938
|
}
|
|
103873
103939
|
});
|
|
103874
|
-
|
|
103875
|
-
|
|
103876
|
-
|
|
103877
|
-
|
|
103878
|
-
|
|
103879
|
-
|
|
103880
|
-
|
|
103881
|
-
|
|
103882
|
-
|
|
103883
|
-
|
|
103884
|
-
|
|
103885
|
-
|
|
103886
|
-
|
|
103887
|
-
|
|
103888
|
-
|
|
103889
|
-
|
|
103890
|
-
|
|
103891
|
-
|
|
103892
|
-
|
|
103893
|
-
|
|
103894
|
-
|
|
103895
|
-
|
|
103896
|
-
|
|
103897
|
-
|
|
103898
|
-
|
|
103899
|
-
|
|
103900
|
-
|
|
103901
|
-
|
|
103940
|
+
if (isIncluded("tenants use")) {
|
|
103941
|
+
tenantsCli.command("use", {
|
|
103942
|
+
description: "Switch active tenant for an account",
|
|
103943
|
+
args: external_exports.object({
|
|
103944
|
+
tenantSelector: external_exports.string().min(1).describe("Tenant selector: tenant no or UUID tenant id")
|
|
103945
|
+
}),
|
|
103946
|
+
options: external_exports.object({
|
|
103947
|
+
userId: external_exports.string().optional().describe("User ID; defaults to active account"),
|
|
103948
|
+
scope: external_exports.string().optional().describe("Scope used only when tenant bootstrap login is required")
|
|
103949
|
+
}),
|
|
103950
|
+
run: async (context) => {
|
|
103951
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103952
|
+
const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
|
|
103953
|
+
const tenantId = await resolveTenantIdSelector({
|
|
103954
|
+
authSessionService,
|
|
103955
|
+
selector: context.args.tenantSelector,
|
|
103956
|
+
userId: context.options.userId
|
|
103957
|
+
});
|
|
103958
|
+
let cleanupOpenInBrowserListener = () => {
|
|
103959
|
+
};
|
|
103960
|
+
try {
|
|
103961
|
+
const switched = await authSessionService.switchTenant({
|
|
103962
|
+
tenantId,
|
|
103963
|
+
userId: context.options.userId,
|
|
103964
|
+
scope: context.options.scope,
|
|
103965
|
+
onVerification: (verification) => {
|
|
103966
|
+
logVerificationHint(verification, context.agent, dependencies.onMessage);
|
|
103967
|
+
cleanupOpenInBrowserListener = listenForEnterToOpenBrowser(verification.verificationUriComplete, context.agent);
|
|
103968
|
+
}
|
|
103969
|
+
});
|
|
103970
|
+
return await injectContext({
|
|
103971
|
+
apiBaseUrl,
|
|
103972
|
+
authStore: dependencies.authStore,
|
|
103973
|
+
payload: {
|
|
103974
|
+
switched: true,
|
|
103975
|
+
...switched
|
|
103976
|
+
}
|
|
103977
|
+
});
|
|
103978
|
+
} finally {
|
|
103979
|
+
cleanupOpenInBrowserListener();
|
|
103980
|
+
}
|
|
103981
|
+
}
|
|
103982
|
+
});
|
|
103983
|
+
}
|
|
103984
|
+
authCli.command(tenantsCli);
|
|
103985
|
+
if (isIncluded("logout")) {
|
|
103986
|
+
authCli.command("logout", {
|
|
103987
|
+
description: "Revoke and clear all tenant sessions for active account",
|
|
103988
|
+
options: external_exports.object({
|
|
103989
|
+
clientId: external_exports.string().optional().describe("OAuth2 client id override")
|
|
103990
|
+
}),
|
|
103991
|
+
run: async (context) => {
|
|
103992
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103993
|
+
const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
|
|
103994
|
+
const result = await authSessionService.logout({
|
|
103995
|
+
clientId: context.options.clientId
|
|
103902
103996
|
});
|
|
103903
103997
|
return await injectContext({
|
|
103904
103998
|
apiBaseUrl,
|
|
103905
103999
|
authStore: dependencies.authStore,
|
|
103906
|
-
payload:
|
|
103907
|
-
switched: true,
|
|
103908
|
-
...switched
|
|
103909
|
-
}
|
|
104000
|
+
payload: result
|
|
103910
104001
|
});
|
|
103911
|
-
} finally {
|
|
103912
|
-
cleanupOpenInBrowserListener();
|
|
103913
104002
|
}
|
|
103914
|
-
}
|
|
103915
|
-
}
|
|
103916
|
-
authCli.command(tenantsCli);
|
|
103917
|
-
authCli.command("logout", {
|
|
103918
|
-
description: "Revoke and clear all tenant sessions for active account",
|
|
103919
|
-
options: external_exports.object({
|
|
103920
|
-
clientId: external_exports.string().optional().describe("OAuth2 client id override")
|
|
103921
|
-
}),
|
|
103922
|
-
run: async (context) => {
|
|
103923
|
-
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
103924
|
-
const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
|
|
103925
|
-
const result = await authSessionService.logout({
|
|
103926
|
-
clientId: context.options.clientId
|
|
103927
|
-
});
|
|
103928
|
-
return await injectContext({
|
|
103929
|
-
apiBaseUrl,
|
|
103930
|
-
authStore: dependencies.authStore,
|
|
103931
|
-
payload: result
|
|
103932
|
-
});
|
|
103933
|
-
}
|
|
103934
|
-
});
|
|
104003
|
+
});
|
|
104004
|
+
}
|
|
103935
104005
|
authCli.command("who", {
|
|
103936
104006
|
description: "Return current authenticated user",
|
|
103937
104007
|
run: async (context) => {
|
|
@@ -103996,103 +104066,109 @@ function createAuthCli(dependencies) {
|
|
|
103996
104066
|
});
|
|
103997
104067
|
}
|
|
103998
104068
|
});
|
|
103999
|
-
|
|
104000
|
-
|
|
104001
|
-
|
|
104002
|
-
|
|
104003
|
-
|
|
104004
|
-
|
|
104005
|
-
|
|
104006
|
-
|
|
104007
|
-
|
|
104008
|
-
|
|
104009
|
-
|
|
104010
|
-
|
|
104011
|
-
|
|
104012
|
-
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
104013
|
-
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
104014
|
-
const response = await apiClient.request({
|
|
104015
|
-
method: "POST",
|
|
104016
|
-
path: `/ai/sandbox/app/${appId}/regenerateGithubToken`
|
|
104017
|
-
});
|
|
104018
|
-
return await injectContext({
|
|
104019
|
-
apiBaseUrl,
|
|
104020
|
-
authStore: dependencies.authStore,
|
|
104021
|
-
payload: response.data
|
|
104022
|
-
});
|
|
104023
|
-
}
|
|
104024
|
-
});
|
|
104025
|
-
authCli.command("git-credential", {
|
|
104026
|
-
description: "Git credential helper: supplies the sandbox gateway capability for the active app",
|
|
104027
|
-
options: external_exports.object({
|
|
104028
|
-
operation: external_exports.enum(["get", "store", "erase"]).describe("Git credential operation (passed by git)"),
|
|
104029
|
-
appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
|
|
104030
|
-
}),
|
|
104031
|
-
// Conforms to the git credential helper protocol, so it writes the raw
|
|
104032
|
-
// `username=`/`password=` lines straight to stdout and returns undefined
|
|
104033
|
-
// (no injectContext envelope — git would not understand it).
|
|
104034
|
-
run: async (context) => {
|
|
104035
|
-
if (context.options.operation !== "get") {
|
|
104036
|
-
return void 0;
|
|
104037
|
-
}
|
|
104038
|
-
const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, SANDBOX_APP_ID_ENV);
|
|
104039
|
-
if (!appId) {
|
|
104040
|
-
throw new UserInputError(`App ID is required. Pass --appId or set the ${SANDBOX_APP_ID_ENV} environment variable.`);
|
|
104041
|
-
}
|
|
104042
|
-
if (!isHostedSandbox2()) {
|
|
104043
|
-
return void 0;
|
|
104044
|
-
}
|
|
104045
|
-
if (!dependencies.settingsRootPath) {
|
|
104046
|
-
return void 0;
|
|
104047
|
-
}
|
|
104048
|
-
const writeStdout = dependencies.writeStdout ?? ((chunk) => process.stdout.write(chunk));
|
|
104049
|
-
const readStdin2 = dependencies.readStdin ?? readAllStdin;
|
|
104050
|
-
try {
|
|
104051
|
-
const request2 = parseGitCredentialRequest(await readStdin2());
|
|
104052
|
-
const gatewayUrl = getOptionalEnvValue(context.env, SANDBOX_GATEWAY_URL_ENV);
|
|
104053
|
-
if (!gatewayUrl || !isGatewayGitCredentialRequest({ request: request2, baseUrl: gatewayUrl, appId })) {
|
|
104054
|
-
return void 0;
|
|
104069
|
+
if (isIncluded("github")) {
|
|
104070
|
+
authCli.command("github", {
|
|
104071
|
+
description: "Rotate the server-side repo-scoped GitHub token for an app",
|
|
104072
|
+
options: external_exports.object({
|
|
104073
|
+
appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
|
|
104074
|
+
}),
|
|
104075
|
+
// Status only. The rotated token is never returned and never reaches a
|
|
104076
|
+
// sandbox: git authenticates through the sandbox gateway with a
|
|
104077
|
+
// short-lived capability, and the GitHub token stays on the control plane.
|
|
104078
|
+
run: async (context) => {
|
|
104079
|
+
const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, SANDBOX_APP_ID_ENV);
|
|
104080
|
+
if (!appId) {
|
|
104081
|
+
throw new UserInputError(`App ID is required. Pass --appId or set the ${SANDBOX_APP_ID_ENV} environment variable.`);
|
|
104055
104082
|
}
|
|
104056
104083
|
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
104057
|
-
const
|
|
104058
|
-
|
|
104059
|
-
|
|
104060
|
-
|
|
104084
|
+
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
104085
|
+
const response = await apiClient.request({
|
|
104086
|
+
method: "POST",
|
|
104087
|
+
path: `/ai/sandbox/app/${appId}/regenerateGithubToken`
|
|
104088
|
+
});
|
|
104089
|
+
return await injectContext({
|
|
104090
|
+
apiBaseUrl,
|
|
104091
|
+
authStore: dependencies.authStore,
|
|
104092
|
+
payload: response.data
|
|
104061
104093
|
});
|
|
104062
|
-
|
|
104063
|
-
|
|
104064
|
-
|
|
104094
|
+
}
|
|
104095
|
+
});
|
|
104096
|
+
}
|
|
104097
|
+
if (isIncluded("git-credential")) {
|
|
104098
|
+
authCli.command("git-credential", {
|
|
104099
|
+
description: "Git credential helper: supplies the sandbox gateway capability for the active app",
|
|
104100
|
+
options: external_exports.object({
|
|
104101
|
+
operation: external_exports.enum(["get", "store", "erase"]).describe("Git credential operation (passed by git)"),
|
|
104102
|
+
appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
|
|
104103
|
+
}),
|
|
104104
|
+
// Conforms to the git credential helper protocol, so it writes the raw
|
|
104105
|
+
// `username=`/`password=` lines straight to stdout and returns undefined
|
|
104106
|
+
// (no injectContext envelope — git would not understand it).
|
|
104107
|
+
run: async (context) => {
|
|
104108
|
+
if (context.options.operation !== "get") {
|
|
104109
|
+
return void 0;
|
|
104110
|
+
}
|
|
104111
|
+
const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, SANDBOX_APP_ID_ENV);
|
|
104112
|
+
if (!appId) {
|
|
104113
|
+
throw new UserInputError(`App ID is required. Pass --appId or set the ${SANDBOX_APP_ID_ENV} environment variable.`);
|
|
104114
|
+
}
|
|
104115
|
+
if (!isHostedSandbox2()) {
|
|
104116
|
+
return void 0;
|
|
104117
|
+
}
|
|
104118
|
+
if (!dependencies.settingsRootPath) {
|
|
104119
|
+
return void 0;
|
|
104120
|
+
}
|
|
104121
|
+
const writeStdout = dependencies.writeStdout ?? ((chunk) => process.stdout.write(chunk));
|
|
104122
|
+
const readStdin2 = dependencies.readStdin ?? readAllStdin;
|
|
104123
|
+
try {
|
|
104124
|
+
const request2 = parseGitCredentialRequest(await readStdin2());
|
|
104125
|
+
const gatewayUrl = getOptionalEnvValue(context.env, SANDBOX_GATEWAY_URL_ENV);
|
|
104126
|
+
if (!gatewayUrl || !isGatewayGitCredentialRequest({ request: request2, baseUrl: gatewayUrl, appId })) {
|
|
104127
|
+
return void 0;
|
|
104128
|
+
}
|
|
104129
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
104130
|
+
const state = await getGatewayCredential({
|
|
104131
|
+
statePath: resolveSandboxGatewayStatePath(dependencies.settingsRootPath),
|
|
104132
|
+
appId,
|
|
104133
|
+
createApiClient: () => dependencies.createApiClient(apiBaseUrl)
|
|
104134
|
+
});
|
|
104135
|
+
const answer = resolveGitCredentialAnswer({ request: request2, state });
|
|
104136
|
+
if (answer) {
|
|
104137
|
+
writeStdout(`username=${answer.username}
|
|
104065
104138
|
password=${answer.password}
|
|
104066
104139
|
`);
|
|
104140
|
+
}
|
|
104141
|
+
} catch {
|
|
104067
104142
|
}
|
|
104068
|
-
|
|
104143
|
+
return void 0;
|
|
104069
104144
|
}
|
|
104070
|
-
|
|
104071
|
-
|
|
104072
|
-
|
|
104073
|
-
|
|
104074
|
-
|
|
104075
|
-
|
|
104076
|
-
|
|
104077
|
-
|
|
104078
|
-
|
|
104079
|
-
|
|
104080
|
-
|
|
104081
|
-
|
|
104145
|
+
});
|
|
104146
|
+
}
|
|
104147
|
+
if (isIncluded("sandbox")) {
|
|
104148
|
+
authCli.command("sandbox", {
|
|
104149
|
+
description: "Refresh and inject fresh authentication tokens into the active sandbox",
|
|
104150
|
+
options: external_exports.object({
|
|
104151
|
+
appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
|
|
104152
|
+
}),
|
|
104153
|
+
run: async (context) => {
|
|
104154
|
+
const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, "KIVA_SANDBOX_APP_ID");
|
|
104155
|
+
if (!appId) {
|
|
104156
|
+
throw new UserInputError("App ID is required. Pass --appId or set the KIVA_SANDBOX_APP_ID environment variable.");
|
|
104157
|
+
}
|
|
104158
|
+
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
104159
|
+
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
104160
|
+
const response = await apiClient.request({
|
|
104161
|
+
method: "POST",
|
|
104162
|
+
path: `/ai/sandbox/app/${appId}/refreshAuth`
|
|
104163
|
+
});
|
|
104164
|
+
return await injectContext({
|
|
104165
|
+
apiBaseUrl,
|
|
104166
|
+
authStore: dependencies.authStore,
|
|
104167
|
+
payload: response.data
|
|
104168
|
+
});
|
|
104082
104169
|
}
|
|
104083
|
-
|
|
104084
|
-
|
|
104085
|
-
const response = await apiClient.request({
|
|
104086
|
-
method: "POST",
|
|
104087
|
-
path: `/ai/sandbox/app/${appId}/refreshAuth`
|
|
104088
|
-
});
|
|
104089
|
-
return await injectContext({
|
|
104090
|
-
apiBaseUrl,
|
|
104091
|
-
authStore: dependencies.authStore,
|
|
104092
|
-
payload: response.data
|
|
104093
|
-
});
|
|
104094
|
-
}
|
|
104095
|
-
});
|
|
104170
|
+
});
|
|
104171
|
+
}
|
|
104096
104172
|
return authCli;
|
|
104097
104173
|
}
|
|
104098
104174
|
|
|
@@ -105549,7 +105625,7 @@ var FILE_EXTENSION_TO_CONTENT_TYPE = {
|
|
|
105549
105625
|
".zip": "application/zip",
|
|
105550
105626
|
".7z": "application/x-7z-compressed"
|
|
105551
105627
|
};
|
|
105552
|
-
function
|
|
105628
|
+
function isRecord5(value2) {
|
|
105553
105629
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
105554
105630
|
}
|
|
105555
105631
|
function normalizeOptionalString2(value2) {
|
|
@@ -105579,7 +105655,7 @@ function toBulkPayload(payload, mode) {
|
|
|
105579
105655
|
const records = [];
|
|
105580
105656
|
for (let index3 = 0; index3 < payload.length; index3 += 1) {
|
|
105581
105657
|
const item = payload[index3];
|
|
105582
|
-
if (!
|
|
105658
|
+
if (!isRecord5(item)) {
|
|
105583
105659
|
throw new UserInputError(`Batch item at index ${index3} must be a JSON object.`);
|
|
105584
105660
|
}
|
|
105585
105661
|
if (mode === "update") {
|
|
@@ -105593,7 +105669,7 @@ function toBulkPayload(payload, mode) {
|
|
|
105593
105669
|
return records;
|
|
105594
105670
|
}
|
|
105595
105671
|
function toSinglePayload(payload) {
|
|
105596
|
-
if (!
|
|
105672
|
+
if (!isRecord5(payload)) {
|
|
105597
105673
|
throw new UserInputError("Expected a JSON object for single-item operation.");
|
|
105598
105674
|
}
|
|
105599
105675
|
return payload;
|
|
@@ -106086,7 +106162,7 @@ function parseIds(raw) {
|
|
|
106086
106162
|
}
|
|
106087
106163
|
return raw.split(",").map((id) => id.trim()).filter((id) => id.length > 0);
|
|
106088
106164
|
}
|
|
106089
|
-
function
|
|
106165
|
+
function isRecord6(value2) {
|
|
106090
106166
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
106091
106167
|
}
|
|
106092
106168
|
function normalizeNonEmptyString(value2) {
|
|
@@ -106101,13 +106177,13 @@ function tryParseJsonObject(text3) {
|
|
|
106101
106177
|
const candidate = (fenceMatch ? fenceMatch[1] : trimmed).trim();
|
|
106102
106178
|
try {
|
|
106103
106179
|
const parsed = JSON.parse(candidate);
|
|
106104
|
-
return
|
|
106180
|
+
return isRecord6(parsed) ? parsed : null;
|
|
106105
106181
|
} catch {
|
|
106106
106182
|
return null;
|
|
106107
106183
|
}
|
|
106108
106184
|
}
|
|
106109
106185
|
function extractGeneratedDsql(result) {
|
|
106110
|
-
const structured = (
|
|
106186
|
+
const structured = (isRecord6(result.data) ? isRecord6(result.data.data) ? result.data.data : result.data : null) ?? tryParseJsonObject(result.text);
|
|
106111
106187
|
const structuredQuery = structured ? normalizeNonEmptyString(structured.query) : void 0;
|
|
106112
106188
|
if (structuredQuery) {
|
|
106113
106189
|
return {
|
|
@@ -106135,6 +106211,10 @@ async function generateDsqlQuery(params) {
|
|
|
106135
106211
|
});
|
|
106136
106212
|
return extractGeneratedDsql(result);
|
|
106137
106213
|
}
|
|
106214
|
+
var EXPAND_ENUMS_DESCRIPTION = "List each enum field's option ids and labels under its column.";
|
|
106215
|
+
function expandEnumsQuery(expandEnums) {
|
|
106216
|
+
return expandEnums ? { expandEnums: "true" } : {};
|
|
106217
|
+
}
|
|
106138
106218
|
function createDsqlCli(dependencies) {
|
|
106139
106219
|
const dsqlCli = Cli_exports.create("dsql", {
|
|
106140
106220
|
description: "Logical SQL query and schema discovery commands",
|
|
@@ -106176,12 +106256,16 @@ function createDsqlCli(dependencies) {
|
|
|
106176
106256
|
args: external_exports.object({
|
|
106177
106257
|
appSlug: external_exports.string().min(1)
|
|
106178
106258
|
}),
|
|
106259
|
+
options: external_exports.object({
|
|
106260
|
+
expandEnums: external_exports.boolean().default(false).describe(EXPAND_ENUMS_DESCRIPTION)
|
|
106261
|
+
}),
|
|
106179
106262
|
run: async (context) => {
|
|
106180
106263
|
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
106181
106264
|
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
106182
106265
|
const response = await apiClient.request({
|
|
106183
106266
|
method: "GET",
|
|
106184
|
-
path: `/dsql/schema/apps/${context.args.appSlug}
|
|
106267
|
+
path: `/dsql/schema/apps/${context.args.appSlug}`,
|
|
106268
|
+
query: expandEnumsQuery(context.options.expandEnums)
|
|
106185
106269
|
});
|
|
106186
106270
|
return await injectContext({
|
|
106187
106271
|
apiBaseUrl,
|
|
@@ -106196,12 +106280,18 @@ function createDsqlCli(dependencies) {
|
|
|
106196
106280
|
appSlug: external_exports.string().min(1),
|
|
106197
106281
|
dataSourceSlug: external_exports.string().min(1)
|
|
106198
106282
|
}),
|
|
106283
|
+
options: external_exports.object({
|
|
106284
|
+
// On by default: a single table is small, and its enum labels are what a
|
|
106285
|
+
// filter such as "open tasks" has to be written against.
|
|
106286
|
+
expandEnums: external_exports.boolean().default(true).describe(`${EXPAND_ENUMS_DESCRIPTION} On by default; pass --no-expand-enums to omit`)
|
|
106287
|
+
}),
|
|
106199
106288
|
run: async (context) => {
|
|
106200
106289
|
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
106201
106290
|
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
106202
106291
|
const response = await apiClient.request({
|
|
106203
106292
|
method: "GET",
|
|
106204
|
-
path: `/dsql/schema/apps/${context.args.appSlug}/data-sources/${context.args.dataSourceSlug}
|
|
106293
|
+
path: `/dsql/schema/apps/${context.args.appSlug}/data-sources/${context.args.dataSourceSlug}`,
|
|
106294
|
+
query: expandEnumsQuery(context.options.expandEnums)
|
|
106205
106295
|
});
|
|
106206
106296
|
return await injectContext({
|
|
106207
106297
|
apiBaseUrl,
|
|
@@ -106213,7 +106303,8 @@ function createDsqlCli(dependencies) {
|
|
|
106213
106303
|
schemaCli.command("data-sources", {
|
|
106214
106304
|
description: "Get the DSQL schema for data sources matching the given ids",
|
|
106215
106305
|
options: external_exports.object({
|
|
106216
|
-
ids: external_exports.string().optional().describe("Comma-separated data source ids")
|
|
106306
|
+
ids: external_exports.string().optional().describe("Comma-separated data source ids"),
|
|
106307
|
+
expandEnums: external_exports.boolean().default(false).describe(EXPAND_ENUMS_DESCRIPTION)
|
|
106217
106308
|
}),
|
|
106218
106309
|
run: async (context) => {
|
|
106219
106310
|
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
@@ -106226,7 +106317,8 @@ function createDsqlCli(dependencies) {
|
|
|
106226
106317
|
method: "GET",
|
|
106227
106318
|
path: "/dsql/schema/data-sources",
|
|
106228
106319
|
query: {
|
|
106229
|
-
ids: ids.join(",")
|
|
106320
|
+
ids: ids.join(","),
|
|
106321
|
+
...expandEnumsQuery(context.options.expandEnums)
|
|
106230
106322
|
}
|
|
106231
106323
|
});
|
|
106232
106324
|
return await injectContext({
|
|
@@ -106305,7 +106397,7 @@ function createDsqlCli(dependencies) {
|
|
|
106305
106397
|
prompt: generated.prompt ?? prompt,
|
|
106306
106398
|
query: generated.query
|
|
106307
106399
|
};
|
|
106308
|
-
const payload =
|
|
106400
|
+
const payload = isRecord6(response.data) ? { ...base, ...response.data } : { ...base, result: response.data };
|
|
106309
106401
|
return await injectContext({
|
|
106310
106402
|
apiBaseUrl,
|
|
106311
106403
|
authStore: dependencies.authStore,
|
|
@@ -106510,7 +106602,7 @@ function createDsqlCli(dependencies) {
|
|
|
106510
106602
|
// src/commands/discoverCommands.ts
|
|
106511
106603
|
import { readFile as readFile10 } from "node:fs/promises";
|
|
106512
106604
|
var SUPPORTED_HTTP_METHODS2 = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "TRACE"];
|
|
106513
|
-
function
|
|
106605
|
+
function isRecord7(value2) {
|
|
106514
106606
|
return typeof value2 === "object" && value2 !== null;
|
|
106515
106607
|
}
|
|
106516
106608
|
function isEnoentError(error62) {
|
|
@@ -106564,15 +106656,15 @@ function parseEndpointSelector(input2) {
|
|
|
106564
106656
|
}
|
|
106565
106657
|
function getPaths(document4) {
|
|
106566
106658
|
const rawPaths = document4.paths;
|
|
106567
|
-
return
|
|
106659
|
+
return isRecord7(rawPaths) ? rawPaths : {};
|
|
106568
106660
|
}
|
|
106569
106661
|
function getEntities(document4) {
|
|
106570
|
-
const components =
|
|
106571
|
-
if (components &&
|
|
106662
|
+
const components = isRecord7(document4.components) ? document4.components : null;
|
|
106663
|
+
if (components && isRecord7(components.schemas)) {
|
|
106572
106664
|
return components.schemas;
|
|
106573
106665
|
}
|
|
106574
106666
|
const definitions = document4.definitions;
|
|
106575
|
-
if (
|
|
106667
|
+
if (isRecord7(definitions)) {
|
|
106576
106668
|
return definitions;
|
|
106577
106669
|
}
|
|
106578
106670
|
return {};
|
|
@@ -106592,19 +106684,19 @@ function extractNamespaces(paths) {
|
|
|
106592
106684
|
return Array.from(namespaces.values()).sort((left, right) => left.localeCompare(right));
|
|
106593
106685
|
}
|
|
106594
106686
|
function getPathOperation(pathItem, method) {
|
|
106595
|
-
if (!
|
|
106687
|
+
if (!isRecord7(pathItem)) {
|
|
106596
106688
|
return null;
|
|
106597
106689
|
}
|
|
106598
106690
|
const normalizedMethod = method.toLowerCase();
|
|
106599
106691
|
const operation = pathItem[normalizedMethod];
|
|
106600
|
-
return
|
|
106692
|
+
return isRecord7(operation) ? operation : null;
|
|
106601
106693
|
}
|
|
106602
106694
|
function toEndpointMethodEntries(paths, pathFilter) {
|
|
106603
106695
|
const entries = [];
|
|
106604
106696
|
const sortedPaths = Object.keys(paths).filter(pathFilter).sort((left, right) => left.localeCompare(right));
|
|
106605
106697
|
for (const path13 of sortedPaths) {
|
|
106606
106698
|
const pathItem = paths[path13];
|
|
106607
|
-
if (!
|
|
106699
|
+
if (!isRecord7(pathItem)) {
|
|
106608
106700
|
continue;
|
|
106609
106701
|
}
|
|
106610
106702
|
for (const method of SUPPORTED_HTTP_METHODS2) {
|
|
@@ -106633,7 +106725,7 @@ function parseOpenApiDocument(raw) {
|
|
|
106633
106725
|
cause: error62
|
|
106634
106726
|
});
|
|
106635
106727
|
}
|
|
106636
|
-
if (!
|
|
106728
|
+
if (!isRecord7(parsed)) {
|
|
106637
106729
|
throw new UserInputError("Stored OpenAPI spec must be a JSON object. Run 'kiva discover api' to re-download.");
|
|
106638
106730
|
}
|
|
106639
106731
|
return parsed;
|
|
@@ -117612,11 +117704,11 @@ function requireNonEmptyObject4(payload, label) {
|
|
|
117612
117704
|
throw new UserInputError(`${label} payload is empty. Provide flags, --data, or --from-file.`);
|
|
117613
117705
|
}
|
|
117614
117706
|
}
|
|
117615
|
-
function
|
|
117707
|
+
function isRecord9(value2) {
|
|
117616
117708
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
117617
117709
|
}
|
|
117618
117710
|
function normalizeBatchUpdateFieldItem(item) {
|
|
117619
|
-
if (!
|
|
117711
|
+
if (!isRecord9(item)) {
|
|
117620
117712
|
return item;
|
|
117621
117713
|
}
|
|
117622
117714
|
const normalized = {
|
|
@@ -117650,7 +117742,7 @@ function normalizeBatchUpdateFieldsPayload(payload) {
|
|
|
117650
117742
|
};
|
|
117651
117743
|
}
|
|
117652
117744
|
function normalizeUpdateEnumItem(item) {
|
|
117653
|
-
if (!
|
|
117745
|
+
if (!isRecord9(item)) {
|
|
117654
117746
|
return item;
|
|
117655
117747
|
}
|
|
117656
117748
|
if (!("enumId" in item) && typeof item.id === "string") {
|
|
@@ -119574,6 +119666,87 @@ function createUpdateCli(dependencies) {
|
|
|
119574
119666
|
});
|
|
119575
119667
|
}
|
|
119576
119668
|
|
|
119669
|
+
// src/rootHelpCommands.ts
|
|
119670
|
+
var ROOT_HELP_COMMANDS = [
|
|
119671
|
+
{ command: "kiva -g <command>", description: "Force use of global ~/.kiva settings for this run" },
|
|
119672
|
+
{ command: "env", description: "Show active environment and list environments" },
|
|
119673
|
+
{ command: "env which", description: "Show the active environment and resolved settings scope for the current folder" },
|
|
119674
|
+
{ command: "env use <id|name>", description: "Switch active environment" },
|
|
119675
|
+
{ command: "auth login", description: "Authenticate with OAuth2 device flow" },
|
|
119676
|
+
{ command: "auth set-tokens --accessToken <token>", description: "Save custom access and refresh tokens" },
|
|
119677
|
+
{ command: "auth accounts list", description: "List saved user accounts" },
|
|
119678
|
+
{ command: "auth tenants use <uuid|tenantNo>", description: "Switch active tenant for selected user" },
|
|
119679
|
+
{ command: '"<prompt>"', description: "Start an agent with a prompt: the Coding Agent for software requests, the Work Agent otherwise" },
|
|
119680
|
+
{ command: "work [prompt]", description: "Launch the Kiva Work Agent" },
|
|
119681
|
+
{ command: "code [prompt]", description: "Launch the Kiva Coding Agent" },
|
|
119682
|
+
{ command: "server", description: "Start HTTP server bridging pi agent to AI SDK useChat" },
|
|
119683
|
+
{ command: "browser start", description: "Start a browser session (local Chrome or remote Cloudflare)" },
|
|
119684
|
+
{ command: "browser nav <url>", description: "Navigate the active browser tab" },
|
|
119685
|
+
{ command: "browser content <url>", description: "Extract readable page content as markdown" },
|
|
119686
|
+
{ command: "discover api", description: "Download active tenant OpenAPI spec" },
|
|
119687
|
+
{ command: "discover namespaces", description: "List namespaces from tenant OpenAPI spec" },
|
|
119688
|
+
{ command: "discover path <prefix>", description: "List endpoint paths by prefix" },
|
|
119689
|
+
{ command: "discover endpoint <path>", description: "Show endpoint object by exact path" },
|
|
119690
|
+
{ command: "discover entity <name>", description: "Show entity object by name" },
|
|
119691
|
+
{ command: "discover search <terms>", description: "Search in endpoint paths and entity names" },
|
|
119692
|
+
{ command: "connect list-connectors", description: "List integration connectors" },
|
|
119693
|
+
{ command: "connect get-connector <slug>", description: "Get connector details with data sources and actions" },
|
|
119694
|
+
{ command: "connect get-action <slug> <key>", description: "Get connector action details" },
|
|
119695
|
+
{ command: "connect list-connections <slug>", description: "Get connector connections" },
|
|
119696
|
+
{ command: "connect curl <slug> <endpoint>", description: "Send request through connector" },
|
|
119697
|
+
{ command: "connect run-action <appSlug> <actionKey>", description: "Run a connector or app action" },
|
|
119698
|
+
{ command: "knowledge search <query>", description: "Semantic search across kiva/knowledge" },
|
|
119699
|
+
{ command: "knowledge section <query>", description: "Show a knowledge section with refs and backlinks" },
|
|
119700
|
+
{ command: "knowledge check", description: "Validate kiva/knowledge links and backlinks" },
|
|
119701
|
+
{ command: "project-plan show", description: "Show the canonical project plan graph and hierarchy" },
|
|
119702
|
+
{ command: "project-plan check", description: "Validate the canonical project plan graph" },
|
|
119703
|
+
{ command: "ds list <appSlug> <dataSourceSlug>", description: "List data source items" },
|
|
119704
|
+
{ command: 'dsql query "<sql>"', description: "Run a read-only logical SQL SELECT query" },
|
|
119705
|
+
{ command: 'dsql generate "<question>"', description: "Generate a DSQL query from natural language" },
|
|
119706
|
+
{ command: 'dsql ask "<question>"', description: "Generate a DSQL query from natural language and run it" },
|
|
119707
|
+
{ command: "dsql schema app <appSlug>", description: "Show DSQL schema for every data source in an app" },
|
|
119708
|
+
{ command: "dsql schema data-source <appSlug> <dataSourceSlug>", description: "Show DSQL schema for a single data source" },
|
|
119709
|
+
{ command: "dsql list-custom-query --appSlug <slug>", description: "List saved custom query records for an app" },
|
|
119710
|
+
{
|
|
119711
|
+
command: "dsql create-custom-query --appSlug <slug> --name <name> --dsqlQuery <sql> --fields <json>",
|
|
119712
|
+
description: "Create a custom query record from DSQL"
|
|
119713
|
+
},
|
|
119714
|
+
{ command: "dsql run-custom-query --queryId <id>", description: "Run a saved custom query (--debug/--simulate to inspect)" },
|
|
119715
|
+
{ command: "apps list", description: "List apps" },
|
|
119716
|
+
{ command: "apps delete --appId <id>", description: "Archive an app" },
|
|
119717
|
+
{
|
|
119718
|
+
command: "apps set-agent-context --appSlug <slug> --value <text>",
|
|
119719
|
+
description: "Set an app's AI agent context (or --from-file/--clear)"
|
|
119720
|
+
},
|
|
119721
|
+
{ command: "apps ai-tools list --appSlug <slug>", description: "List app-scoped AI tools" },
|
|
119722
|
+
{ command: "apps ai-tools create --appSlug <slug> --name <name> --key <key>", description: "Create an app-scoped AI tool" },
|
|
119723
|
+
{ command: "studio list-data-sources --appSlug <slug>", description: "List studio data sources" },
|
|
119724
|
+
{ command: "automation list --appSlug <slug>", description: "List automations for an app" },
|
|
119725
|
+
{ command: "automation create-trigger --automationId <id> --type <type>", description: "Add a typed trigger to an automation" },
|
|
119726
|
+
{ command: "agent list --appSlug <slug>", description: "List custom agents for an app" },
|
|
119727
|
+
{ command: "agent create --appSlug <slug> --name <name>", description: "Create a custom agent" },
|
|
119728
|
+
{ command: "agent tools create --appSlug <slug> --agentId <id> --toolType <type>", description: "Add a tool to an agent" },
|
|
119729
|
+
{ command: "acl roles list", description: "List tenant roles" },
|
|
119730
|
+
{ command: "acl roles create --slug <slug> --name <name>", description: "Create a tenant role" },
|
|
119731
|
+
{ command: "acl role-queries list", description: "List tenant role queries" },
|
|
119732
|
+
{ command: "acl hierarchy-units list", description: "List tenant user hierarchy units" },
|
|
119733
|
+
{ command: "acl hierarchy-units create --name <name>", description: "Create a hierarchy unit" },
|
|
119734
|
+
{ command: "messaging accounts", description: "List tenant email accounts (non-credential info)" },
|
|
119735
|
+
{ command: "messaging email send --accountId <id>", description: "Send an email through a tenant email account" },
|
|
119736
|
+
{ command: "account brands list", description: "List tenant brands" },
|
|
119737
|
+
{ command: "account brands create --name <name>", description: "Create a tenant brand" },
|
|
119738
|
+
{ command: "account brands update --brandId <id>", description: "Update a tenant brand" },
|
|
119739
|
+
{ command: "account user-profile get", description: "Get the current user's profile" },
|
|
119740
|
+
{ command: "account user-profile update --firstname <name>", description: "Update the current user's profile" },
|
|
119741
|
+
{ command: "account tenant-preferences get", description: "Get the tenant's regional preferences" },
|
|
119742
|
+
{ command: "account tenant-preferences update --timeZone <id>", description: "Update the tenant's regional preferences" },
|
|
119743
|
+
{ command: "tui", description: "Launch terminal UI (OpenTUI, requires Bun)" },
|
|
119744
|
+
{ command: "curl <path>", description: "Send arbitrary API requests" },
|
|
119745
|
+
{ command: "agent-skills status", description: "Show whether the Kiva agent skills are installed and current in this folder" },
|
|
119746
|
+
{ command: "agent-skills install", description: "Install or update the Kiva agent skills in this folder" },
|
|
119747
|
+
{ command: "update", description: "Update the kiva CLI to the latest version (--check to only report)" }
|
|
119748
|
+
];
|
|
119749
|
+
|
|
119577
119750
|
// src/services/authStoreMigration.ts
|
|
119578
119751
|
var LEGACY_API_BASE_URLS = /* @__PURE__ */ new Map([
|
|
119579
119752
|
["https://api.docyrus.com/v1", "https://api.kiva.app/v1"],
|
|
@@ -119647,7 +119820,7 @@ function migrateLegacyAuthApiUrls(state) {
|
|
|
119647
119820
|
|
|
119648
119821
|
// src/services/authSession.ts
|
|
119649
119822
|
var DEFAULT_MANUAL_ACCESS_TOKEN_EXPIRY_SECONDS = 3600;
|
|
119650
|
-
function
|
|
119823
|
+
function isRecord10(value2) {
|
|
119651
119824
|
return typeof value2 === "object" && value2 !== null;
|
|
119652
119825
|
}
|
|
119653
119826
|
function extractRecordValue(record2, keys) {
|
|
@@ -119963,11 +120136,11 @@ var AuthSessionService = class {
|
|
|
119963
120136
|
fetchFn: this.params.fetchFn
|
|
119964
120137
|
});
|
|
119965
120138
|
const payload = response.data;
|
|
119966
|
-
const dataCandidate =
|
|
119967
|
-
if (!
|
|
120139
|
+
const dataCandidate = isRecord10(payload) && isRecord10(payload.data) ? payload.data : payload;
|
|
120140
|
+
if (!isRecord10(dataCandidate)) {
|
|
119968
120141
|
throw new AuthSessionError("Unable to parse /users/me response.");
|
|
119969
120142
|
}
|
|
119970
|
-
const tenantCandidate =
|
|
120143
|
+
const tenantCandidate = isRecord10(dataCandidate.tenant) ? dataCandidate.tenant : void 0;
|
|
119971
120144
|
const userId = extractString3(dataCandidate, ["id", "user_id"]);
|
|
119972
120145
|
const email3 = extractString3(dataCandidate, ["email"]);
|
|
119973
120146
|
const tenantId = tenantCandidate ? extractString3(tenantCandidate, ["id"]) : extractString3(dataCandidate, ["tenant_id", "tenantId"]);
|
|
@@ -119993,13 +120166,13 @@ var AuthSessionService = class {
|
|
|
119993
120166
|
fetchFn: this.params.fetchFn
|
|
119994
120167
|
});
|
|
119995
120168
|
const payload = response.data;
|
|
119996
|
-
const listCandidate = Array.isArray(payload) ? payload :
|
|
120169
|
+
const listCandidate = Array.isArray(payload) ? payload : isRecord10(payload) && Array.isArray(payload.data) ? payload.data : null;
|
|
119997
120170
|
if (!listCandidate) {
|
|
119998
120171
|
throw new AuthSessionError("Unable to parse tenant catalog response.");
|
|
119999
120172
|
}
|
|
120000
120173
|
const mapped = [];
|
|
120001
120174
|
for (const item of listCandidate) {
|
|
120002
|
-
if (!
|
|
120175
|
+
if (!isRecord10(item)) {
|
|
120003
120176
|
continue;
|
|
120004
120177
|
}
|
|
120005
120178
|
const tenantId = extractString3(item, ["id", "tenant_id"]);
|
|
@@ -120676,15 +120849,16 @@ var AuthStore = class _AuthStore {
|
|
|
120676
120849
|
};
|
|
120677
120850
|
|
|
120678
120851
|
// src/services/barePrompt.ts
|
|
120852
|
+
var BARE_PROMPT_AGENT_COMMANDS = ["work", "code"];
|
|
120679
120853
|
var BARE_PROMPT_COMMAND = "work";
|
|
120680
120854
|
var SENTENCE_RE = /\S\s+\S/u;
|
|
120681
|
-
function
|
|
120855
|
+
function findBarePrompt(argv) {
|
|
120682
120856
|
for (const [index3, token] of argv.entries()) {
|
|
120683
120857
|
if (token.startsWith("-")) {
|
|
120684
120858
|
continue;
|
|
120685
120859
|
}
|
|
120686
120860
|
if (SENTENCE_RE.test(token)) {
|
|
120687
|
-
return
|
|
120861
|
+
return token;
|
|
120688
120862
|
}
|
|
120689
120863
|
const previous2 = argv[index3 - 1];
|
|
120690
120864
|
if (previous2?.startsWith("-") && !previous2.includes("=")) {
|
|
@@ -120692,7 +120866,46 @@ function rewriteBarePromptArgv(argv) {
|
|
|
120692
120866
|
}
|
|
120693
120867
|
break;
|
|
120694
120868
|
}
|
|
120695
|
-
return
|
|
120869
|
+
return void 0;
|
|
120870
|
+
}
|
|
120871
|
+
function rewriteBarePromptArgv(argv, command2 = BARE_PROMPT_COMMAND) {
|
|
120872
|
+
return findBarePrompt(argv) === void 0 ? [...argv] : [command2, ...argv];
|
|
120873
|
+
}
|
|
120874
|
+
|
|
120875
|
+
// src/services/barePromptAgent.ts
|
|
120876
|
+
var BARE_PROMPT_DECISION_PATH = "/ai/decideCliAgent";
|
|
120877
|
+
var DECISION_TIMEOUT_MS = 3e3;
|
|
120878
|
+
function isAgentCommand(value2) {
|
|
120879
|
+
return BARE_PROMPT_AGENT_COMMANDS.includes(value2);
|
|
120880
|
+
}
|
|
120881
|
+
async function decideBarePromptAgent(params) {
|
|
120882
|
+
if (isHostedSandbox(params.env)) {
|
|
120883
|
+
return BARE_PROMPT_COMMAND;
|
|
120884
|
+
}
|
|
120885
|
+
let timer;
|
|
120886
|
+
try {
|
|
120887
|
+
const apiBaseUrl = normalizeApiBaseUrl(await params.environmentConfigService.getActiveApiBaseUrl());
|
|
120888
|
+
if (!await params.authStore.getActiveProfile(apiBaseUrl)) {
|
|
120889
|
+
return BARE_PROMPT_COMMAND;
|
|
120890
|
+
}
|
|
120891
|
+
const apiClient = params.createApiClient?.(apiBaseUrl) ?? new ApiClient({ apiBaseUrl, authSessionService: new AuthSessionService({ apiBaseUrl, authStore: params.authStore }) });
|
|
120892
|
+
const decision = requestApiData({
|
|
120893
|
+
apiClient,
|
|
120894
|
+
request: { method: "POST", path: BARE_PROMPT_DECISION_PATH, body: { prompt: params.prompt } }
|
|
120895
|
+
}).then((payload) => {
|
|
120896
|
+
const agent = payload?.agent ?? payload?.data?.agent;
|
|
120897
|
+
return isAgentCommand(agent) ? agent : BARE_PROMPT_COMMAND;
|
|
120898
|
+
});
|
|
120899
|
+
decision.catch(() => void 0);
|
|
120900
|
+
const deadline = new Promise((resolve9) => {
|
|
120901
|
+
timer = setTimeout(() => resolve9(BARE_PROMPT_COMMAND), params.timeoutMs ?? DECISION_TIMEOUT_MS);
|
|
120902
|
+
});
|
|
120903
|
+
return await Promise.race([decision, deadline]);
|
|
120904
|
+
} catch {
|
|
120905
|
+
return BARE_PROMPT_COMMAND;
|
|
120906
|
+
} finally {
|
|
120907
|
+
clearTimeout(timer);
|
|
120908
|
+
}
|
|
120696
120909
|
}
|
|
120697
120910
|
|
|
120698
120911
|
// src/services/environmentConfig.ts
|
|
@@ -122464,85 +122677,6 @@ var TenantOpenApiService = class {
|
|
|
122464
122677
|
};
|
|
122465
122678
|
|
|
122466
122679
|
// src/main.ts
|
|
122467
|
-
var ROOT_HELP_COMMANDS = [
|
|
122468
|
-
{ command: "kiva -g <command>", description: "Force use of global ~/.kiva settings for this run" },
|
|
122469
|
-
{ command: "env", description: "Show active environment and list environments" },
|
|
122470
|
-
{ command: "env which", description: "Show the active environment and resolved settings scope for the current folder" },
|
|
122471
|
-
{ command: "env use <id|name>", description: "Switch active environment" },
|
|
122472
|
-
{ command: "auth login", description: "Authenticate with OAuth2 device flow" },
|
|
122473
|
-
{ command: "auth set-tokens --accessToken <token>", description: "Save custom access and refresh tokens" },
|
|
122474
|
-
{ command: "auth accounts list", description: "List saved user accounts" },
|
|
122475
|
-
{ command: "auth tenants use <uuid|tenantNo>", description: "Switch active tenant for selected user" },
|
|
122476
|
-
{ command: '"<prompt>"', description: 'Start the Kiva Work Agent with a prompt (same as: work "<prompt>")' },
|
|
122477
|
-
{ command: "work [prompt]", description: "Launch the Kiva Work Agent" },
|
|
122478
|
-
{ command: "code [prompt]", description: "Launch the Kiva Coding Agent" },
|
|
122479
|
-
{ command: "server", description: "Start HTTP server bridging pi agent to AI SDK useChat" },
|
|
122480
|
-
{ command: "browser start", description: "Start a browser session (local Chrome or remote Cloudflare)" },
|
|
122481
|
-
{ command: "browser nav <url>", description: "Navigate the active browser tab" },
|
|
122482
|
-
{ command: "browser content <url>", description: "Extract readable page content as markdown" },
|
|
122483
|
-
{ command: "discover api", description: "Download active tenant OpenAPI spec" },
|
|
122484
|
-
{ command: "discover namespaces", description: "List namespaces from tenant OpenAPI spec" },
|
|
122485
|
-
{ command: "discover path <prefix>", description: "List endpoint paths by prefix" },
|
|
122486
|
-
{ command: "discover endpoint <path>", description: "Show endpoint object by exact path" },
|
|
122487
|
-
{ command: "discover entity <name>", description: "Show entity object by name" },
|
|
122488
|
-
{ command: "discover search <terms>", description: "Search in endpoint paths and entity names" },
|
|
122489
|
-
{ command: "connect list-connectors", description: "List integration connectors" },
|
|
122490
|
-
{ command: "connect get-connector <slug>", description: "Get connector details with data sources and actions" },
|
|
122491
|
-
{ command: "connect get-action <slug> <key>", description: "Get connector action details" },
|
|
122492
|
-
{ command: "connect list-connections <slug>", description: "Get connector connections" },
|
|
122493
|
-
{ command: "connect curl <slug> <endpoint>", description: "Send request through connector" },
|
|
122494
|
-
{ command: "connect run-action <appSlug> <actionKey>", description: "Run a connector or app action" },
|
|
122495
|
-
{ command: "knowledge search <query>", description: "Semantic search across kiva/knowledge" },
|
|
122496
|
-
{ command: "knowledge section <query>", description: "Show a knowledge section with refs and backlinks" },
|
|
122497
|
-
{ command: "knowledge check", description: "Validate kiva/knowledge links and backlinks" },
|
|
122498
|
-
{ command: "project-plan show", description: "Show the canonical project plan graph and hierarchy" },
|
|
122499
|
-
{ command: "project-plan check", description: "Validate the canonical project plan graph" },
|
|
122500
|
-
{ command: "ds list <appSlug> <dataSourceSlug>", description: "List data source items" },
|
|
122501
|
-
{ command: 'dsql query "<sql>"', description: "Run a read-only logical SQL SELECT query" },
|
|
122502
|
-
{ command: 'dsql generate "<question>"', description: "Generate a DSQL query from natural language" },
|
|
122503
|
-
{ command: 'dsql ask "<question>"', description: "Generate a DSQL query from natural language and run it" },
|
|
122504
|
-
{ command: "dsql schema app <appSlug>", description: "Show DSQL schema for every data source in an app" },
|
|
122505
|
-
{ command: "dsql schema data-source <appSlug> <dataSourceSlug>", description: "Show DSQL schema for a single data source" },
|
|
122506
|
-
{ command: "dsql list-custom-query --appSlug <slug>", description: "List saved custom query records for an app" },
|
|
122507
|
-
{
|
|
122508
|
-
command: "dsql create-custom-query --appSlug <slug> --name <name> --dsqlQuery <sql> --fields <json>",
|
|
122509
|
-
description: "Create a custom query record from DSQL"
|
|
122510
|
-
},
|
|
122511
|
-
{ command: "dsql run-custom-query --queryId <id>", description: "Run a saved custom query (--debug/--simulate to inspect)" },
|
|
122512
|
-
{ command: "apps list", description: "List apps" },
|
|
122513
|
-
{ command: "apps delete --appId <id>", description: "Archive an app" },
|
|
122514
|
-
{
|
|
122515
|
-
command: "apps set-agent-context --appSlug <slug> --value <text>",
|
|
122516
|
-
description: "Set an app's AI agent context (or --from-file/--clear)"
|
|
122517
|
-
},
|
|
122518
|
-
{ command: "apps ai-tools list --appSlug <slug>", description: "List app-scoped AI tools" },
|
|
122519
|
-
{ command: "apps ai-tools create --appSlug <slug> --name <name> --key <key>", description: "Create an app-scoped AI tool" },
|
|
122520
|
-
{ command: "studio list-data-sources --appSlug <slug>", description: "List studio data sources" },
|
|
122521
|
-
{ command: "automation list --appSlug <slug>", description: "List automations for an app" },
|
|
122522
|
-
{ command: "automation create-trigger --automationId <id> --type <type>", description: "Add a typed trigger to an automation" },
|
|
122523
|
-
{ command: "agent list --appSlug <slug>", description: "List custom agents for an app" },
|
|
122524
|
-
{ command: "agent create --appSlug <slug> --name <name>", description: "Create a custom agent" },
|
|
122525
|
-
{ command: "agent tools create --appSlug <slug> --agentId <id> --toolType <type>", description: "Add a tool to an agent" },
|
|
122526
|
-
{ command: "acl roles list", description: "List tenant roles" },
|
|
122527
|
-
{ command: "acl roles create --slug <slug> --name <name>", description: "Create a tenant role" },
|
|
122528
|
-
{ command: "acl role-queries list", description: "List tenant role queries" },
|
|
122529
|
-
{ command: "acl hierarchy-units list", description: "List tenant user hierarchy units" },
|
|
122530
|
-
{ command: "acl hierarchy-units create --name <name>", description: "Create a hierarchy unit" },
|
|
122531
|
-
{ command: "messaging accounts", description: "List tenant email accounts (non-credential info)" },
|
|
122532
|
-
{ command: "messaging email send --accountId <id>", description: "Send an email through a tenant email account" },
|
|
122533
|
-
{ command: "account brands list", description: "List tenant brands" },
|
|
122534
|
-
{ command: "account brands create --name <name>", description: "Create a tenant brand" },
|
|
122535
|
-
{ command: "account brands update --brandId <id>", description: "Update a tenant brand" },
|
|
122536
|
-
{ command: "account user-profile get", description: "Get the current user's profile" },
|
|
122537
|
-
{ command: "account user-profile update --firstname <name>", description: "Update the current user's profile" },
|
|
122538
|
-
{ command: "account tenant-preferences get", description: "Get the tenant's regional preferences" },
|
|
122539
|
-
{ command: "account tenant-preferences update --timeZone <id>", description: "Update the tenant's regional preferences" },
|
|
122540
|
-
{ command: "tui", description: "Launch terminal UI (OpenTUI, requires Bun)" },
|
|
122541
|
-
{ command: "curl <path>", description: "Send arbitrary API requests" },
|
|
122542
|
-
{ command: "agent-skills status", description: "Show whether the Kiva agent skills are installed and current in this folder" },
|
|
122543
|
-
{ command: "agent-skills install", description: "Install or update the Kiva agent skills in this folder" },
|
|
122544
|
-
{ command: "update", description: "Update the kiva CLI to the latest version (--check to only report)" }
|
|
122545
|
-
];
|
|
122546
122680
|
function createKivaCli(params) {
|
|
122547
122681
|
const settingsPaths = resolveKivaSettingsPaths({
|
|
122548
122682
|
forceGlobal: params?.forceGlobalSettings,
|
|
@@ -122772,15 +122906,31 @@ function createKivaCli(params) {
|
|
|
122772
122906
|
}
|
|
122773
122907
|
migrateLegacyBrandDirectories();
|
|
122774
122908
|
var extractedArgs = extractGlobalFlagFromArgv(process.argv.slice(2));
|
|
122775
|
-
var runtimeArgs = { ...extractedArgs, argv: rewriteBarePromptArgv(extractedArgs.argv) };
|
|
122776
122909
|
var cli = createKivaCli({
|
|
122777
|
-
forceGlobalSettings:
|
|
122910
|
+
forceGlobalSettings: extractedArgs.forceGlobal
|
|
122778
122911
|
});
|
|
122912
|
+
async function resolveRuntimeArgv() {
|
|
122913
|
+
const prompt = findBarePrompt(extractedArgs.argv);
|
|
122914
|
+
if (prompt === void 0) {
|
|
122915
|
+
return [...extractedArgs.argv];
|
|
122916
|
+
}
|
|
122917
|
+
const settingsPaths = resolveKivaSettingsPaths({ forceGlobal: extractedArgs.forceGlobal });
|
|
122918
|
+
const agent = await decideBarePromptAgent({
|
|
122919
|
+
prompt,
|
|
122920
|
+
authStore: new AuthStore(settingsPaths.authFilePath),
|
|
122921
|
+
environmentConfigService: new EnvironmentConfigService(settingsPaths.configFilePath)
|
|
122922
|
+
});
|
|
122923
|
+
if (agent === "code") {
|
|
122924
|
+
process.stderr.write('Starting the Kiva Coding Agent for this request. To choose yourself: kiva work "<prompt>"\n');
|
|
122925
|
+
}
|
|
122926
|
+
return rewriteBarePromptArgv(extractedArgs.argv, agent);
|
|
122927
|
+
}
|
|
122779
122928
|
void runWithIncurSkillsOutOfDateWarningSuppressed({
|
|
122780
122929
|
run: async () => {
|
|
122930
|
+
const argv = await resolveRuntimeArgv();
|
|
122781
122931
|
const gate = await enforceLatestCliVersion({
|
|
122782
122932
|
currentVersion: package_default.version,
|
|
122783
|
-
argv
|
|
122933
|
+
argv,
|
|
122784
122934
|
interactive: isInteractiveSession(),
|
|
122785
122935
|
promptFn: async (question) => await promptYesNo({ question })
|
|
122786
122936
|
});
|
|
@@ -122788,7 +122938,7 @@ void runWithIncurSkillsOutOfDateWarningSuppressed({
|
|
|
122788
122938
|
process.exitCode = gate.exitCode;
|
|
122789
122939
|
return;
|
|
122790
122940
|
}
|
|
122791
|
-
await cli.serve(
|
|
122941
|
+
await cli.serve(argv);
|
|
122792
122942
|
}
|
|
122793
122943
|
});
|
|
122794
122944
|
var main_default = cli;
|