@diafunc/cli 0.1.1 → 0.2.0
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.
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Command } from "commander";
|
|
3
3
|
|
|
4
|
+
// package.json
|
|
5
|
+
var package_default = {
|
|
6
|
+
name: "@diafunc/cli",
|
|
7
|
+
version: "0.2.0",
|
|
8
|
+
description: "Diafunc CLI \u2014 command-line interface for the Diafunc platform",
|
|
9
|
+
type: "module",
|
|
10
|
+
bin: {
|
|
11
|
+
diafunc: "./dist/bin/diafunc.js"
|
|
12
|
+
},
|
|
13
|
+
homepage: "https://diafunc.com",
|
|
14
|
+
repository: {
|
|
15
|
+
type: "git",
|
|
16
|
+
url: "git+https://gitlab.com/diafunc/cli.git"
|
|
17
|
+
},
|
|
18
|
+
bugs: {
|
|
19
|
+
url: "https://gitlab.com/diafunc/cli/-/issues"
|
|
20
|
+
},
|
|
21
|
+
author: "Markus Pollak <markus.pollak@diafunc.com>",
|
|
22
|
+
scripts: {
|
|
23
|
+
build: `tsup && node -e "const fs=require('fs');const f='dist/bin/diafunc.js';fs.writeFileSync(f,'#!/usr/bin/env node\\n'+fs.readFileSync(f,'utf8'))"`,
|
|
24
|
+
dev: "tsup --watch",
|
|
25
|
+
test: "vitest run",
|
|
26
|
+
"test:watch": "vitest",
|
|
27
|
+
lint: "tsc --noEmit",
|
|
28
|
+
start: "node dist/bin/diafunc.js",
|
|
29
|
+
prepublishOnly: "npm run lint && npm test && npm run build"
|
|
30
|
+
},
|
|
31
|
+
files: [
|
|
32
|
+
"dist",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"README.md"
|
|
35
|
+
],
|
|
36
|
+
keywords: [
|
|
37
|
+
"diafunc",
|
|
38
|
+
"cli",
|
|
39
|
+
"data-science",
|
|
40
|
+
"symbolic-regression"
|
|
41
|
+
],
|
|
42
|
+
license: "Apache-2.0",
|
|
43
|
+
publishConfig: {
|
|
44
|
+
access: "public",
|
|
45
|
+
registry: "https://registry.npmjs.org/"
|
|
46
|
+
},
|
|
47
|
+
engines: {
|
|
48
|
+
node: ">=20.0.0"
|
|
49
|
+
},
|
|
50
|
+
dependencies: {
|
|
51
|
+
"@inquirer/prompts": "^7.0.0",
|
|
52
|
+
chalk: "^5.4.0",
|
|
53
|
+
"cli-table3": "^0.6.5",
|
|
54
|
+
commander: "^12.1.0",
|
|
55
|
+
ora: "^8.1.0"
|
|
56
|
+
},
|
|
57
|
+
devDependencies: {
|
|
58
|
+
"@types/node": "^22.0.0",
|
|
59
|
+
tsup: "^8.3.0",
|
|
60
|
+
typescript: "^5.6.0",
|
|
61
|
+
vitest: "^2.1.0"
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
4
65
|
// src/commands/auth/login.ts
|
|
5
66
|
import chalk2 from "chalk";
|
|
6
67
|
|
|
@@ -88,8 +149,8 @@ var NetworkError = class extends Error {
|
|
|
88
149
|
};
|
|
89
150
|
|
|
90
151
|
// src/client/http.ts
|
|
91
|
-
function buildUrl(endpoint, service,
|
|
92
|
-
const base = `${endpoint}/api/v1/${service}${
|
|
152
|
+
function buildUrl(endpoint, service, path7, query) {
|
|
153
|
+
const base = `${endpoint}/api/v1/${service}${path7}`;
|
|
93
154
|
const params = new URLSearchParams();
|
|
94
155
|
if (query) {
|
|
95
156
|
for (const [key, value] of Object.entries(query)) {
|
|
@@ -106,14 +167,27 @@ function getAuthHeader(auth) {
|
|
|
106
167
|
if (auth.type === "api-token") {
|
|
107
168
|
return `Bearer ${auth.token}`;
|
|
108
169
|
}
|
|
109
|
-
if (auth.type === "session") {
|
|
170
|
+
if (auth.type === "session" || auth.type === "device-code") {
|
|
110
171
|
return `Bearer ${auth.accessToken}`;
|
|
111
172
|
}
|
|
112
173
|
return void 0;
|
|
113
174
|
}
|
|
114
175
|
function isTokenExpired(auth) {
|
|
115
|
-
if (!auth
|
|
116
|
-
|
|
176
|
+
if (!auth) return false;
|
|
177
|
+
if (auth.type === "session" || auth.type === "device-code") {
|
|
178
|
+
return Date.now() >= auth.accessTokenExpiry - 3e4;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
function deriveAuthUrl(endpoint) {
|
|
183
|
+
const trimmed = endpoint.replace(/\/+$/, "");
|
|
184
|
+
if (trimmed.includes("://auth.")) {
|
|
185
|
+
return trimmed;
|
|
186
|
+
}
|
|
187
|
+
const url = new URL(trimmed);
|
|
188
|
+
url.hostname = `auth.${url.hostname}`;
|
|
189
|
+
url.pathname = "";
|
|
190
|
+
return url.toString().replace(/\/+$/, "");
|
|
117
191
|
}
|
|
118
192
|
async function refreshSession(endpoint, refreshToken) {
|
|
119
193
|
const url = `${endpoint}/api/v1/admin/sessions/`;
|
|
@@ -131,18 +205,51 @@ async function refreshSession(endpoint, refreshToken) {
|
|
|
131
205
|
accessTokenExpiry: session.accessToken.expiry
|
|
132
206
|
};
|
|
133
207
|
}
|
|
208
|
+
async function refreshOAuthTokens(endpoint, clientId, refreshToken) {
|
|
209
|
+
const authUrl = deriveAuthUrl(endpoint);
|
|
210
|
+
const response = await fetch(`${authUrl}/token`, {
|
|
211
|
+
method: "POST",
|
|
212
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
213
|
+
body: new URLSearchParams({
|
|
214
|
+
grant_type: "refresh_token",
|
|
215
|
+
refresh_token: refreshToken,
|
|
216
|
+
client_id: clientId
|
|
217
|
+
}).toString()
|
|
218
|
+
});
|
|
219
|
+
if (!response.ok) {
|
|
220
|
+
throw new ApiError(response.status, "OAuth token refresh failed. Please run `diafunc auth login` again.");
|
|
221
|
+
}
|
|
222
|
+
const body = await response.json();
|
|
223
|
+
return {
|
|
224
|
+
accessToken: body.access_token,
|
|
225
|
+
refreshToken: body.refresh_token,
|
|
226
|
+
accessTokenExpiry: Date.now() + body.expires_in * 1e3
|
|
227
|
+
};
|
|
228
|
+
}
|
|
134
229
|
async function ensureValidAuth(config, profileOverride) {
|
|
135
230
|
const profileName = profileOverride ?? config.currentProfile;
|
|
136
231
|
const profile = config.profiles[profileName];
|
|
137
232
|
if (!profile?.auth) return void 0;
|
|
138
|
-
if (isTokenExpired(profile.auth)) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
233
|
+
if (!isTokenExpired(profile.auth)) {
|
|
234
|
+
return profile.auth;
|
|
235
|
+
}
|
|
236
|
+
const endpoint = resolveEndpoint(config, profileOverride);
|
|
237
|
+
if (profile.auth.type === "session") {
|
|
238
|
+
const refreshed = await refreshSession(endpoint, profile.auth.refreshToken);
|
|
142
239
|
profile.auth = {
|
|
143
240
|
type: "session",
|
|
144
241
|
accessToken: refreshed.accessToken,
|
|
145
|
-
refreshToken: auth.refreshToken,
|
|
242
|
+
refreshToken: profile.auth.refreshToken,
|
|
243
|
+
accessTokenExpiry: refreshed.accessTokenExpiry
|
|
244
|
+
};
|
|
245
|
+
saveConfig(config);
|
|
246
|
+
} else if (profile.auth.type === "device-code") {
|
|
247
|
+
const refreshed = await refreshOAuthTokens(endpoint, profile.auth.clientId, profile.auth.refreshToken);
|
|
248
|
+
profile.auth = {
|
|
249
|
+
type: "device-code",
|
|
250
|
+
clientId: profile.auth.clientId,
|
|
251
|
+
accessToken: refreshed.accessToken,
|
|
252
|
+
refreshToken: refreshed.refreshToken,
|
|
146
253
|
accessTokenExpiry: refreshed.accessTokenExpiry
|
|
147
254
|
};
|
|
148
255
|
saveConfig(config);
|
|
@@ -434,6 +541,14 @@ function createAdminService(client) {
|
|
|
434
541
|
body: group
|
|
435
542
|
});
|
|
436
543
|
},
|
|
544
|
+
async updateGroup(group) {
|
|
545
|
+
return client.request({
|
|
546
|
+
method: "PUT",
|
|
547
|
+
service: SERVICE,
|
|
548
|
+
path: "/groups/",
|
|
549
|
+
body: group
|
|
550
|
+
});
|
|
551
|
+
},
|
|
437
552
|
async deleteGroup(groupId) {
|
|
438
553
|
return client.request({
|
|
439
554
|
method: "DELETE",
|
|
@@ -507,22 +622,44 @@ function createAdminService(client) {
|
|
|
507
622
|
path: "/subscriptions/current"
|
|
508
623
|
});
|
|
509
624
|
},
|
|
510
|
-
|
|
511
|
-
async createShortTermProjectBackup(body) {
|
|
625
|
+
async getNextSubscription() {
|
|
512
626
|
return client.request({
|
|
513
|
-
method: "
|
|
627
|
+
method: "GET",
|
|
514
628
|
service: SERVICE,
|
|
515
|
-
path: "/
|
|
516
|
-
body
|
|
629
|
+
path: "/subscriptions/next"
|
|
517
630
|
});
|
|
518
631
|
},
|
|
519
|
-
async
|
|
632
|
+
async getSubscriptionPlans(subscriptionToken) {
|
|
520
633
|
return client.request({
|
|
521
|
-
method: "
|
|
634
|
+
method: "GET",
|
|
522
635
|
service: SERVICE,
|
|
523
|
-
path:
|
|
636
|
+
path: `/subscription-plans/${encodeURIComponent(subscriptionToken)}`
|
|
637
|
+
});
|
|
638
|
+
},
|
|
639
|
+
// Invoices
|
|
640
|
+
async hasInvoices() {
|
|
641
|
+
return client.request({
|
|
642
|
+
method: "GET",
|
|
643
|
+
service: SERVICE,
|
|
644
|
+
path: "/invoices/any"
|
|
645
|
+
});
|
|
646
|
+
},
|
|
647
|
+
async getInvoices() {
|
|
648
|
+
return client.request({
|
|
649
|
+
method: "GET",
|
|
650
|
+
service: SERVICE,
|
|
651
|
+
path: "/invoices/"
|
|
652
|
+
});
|
|
653
|
+
},
|
|
654
|
+
async downloadInvoice(invoiceNumber, fileName) {
|
|
655
|
+
return client.requestRaw({
|
|
656
|
+
method: "GET",
|
|
657
|
+
service: SERVICE,
|
|
658
|
+
path: `/invoices/${encodeURIComponent(invoiceNumber)}/documents/${encodeURIComponent(fileName)}`
|
|
524
659
|
});
|
|
525
660
|
},
|
|
661
|
+
// (Backup methods moved to storage service — see src/client/services/storage.ts.
|
|
662
|
+
// Backup endpoints live under @RestApi("storage") on the platform.)
|
|
526
663
|
// Analyses
|
|
527
664
|
async getLastAnalysis() {
|
|
528
665
|
return client.request({
|
|
@@ -531,6 +668,14 @@ function createAdminService(client) {
|
|
|
531
668
|
path: "/analyses/last"
|
|
532
669
|
});
|
|
533
670
|
},
|
|
671
|
+
async getRecentAnalyses(count = 20) {
|
|
672
|
+
return client.request({
|
|
673
|
+
method: "GET",
|
|
674
|
+
service: SERVICE,
|
|
675
|
+
path: "/analyses/recent",
|
|
676
|
+
query: { count }
|
|
677
|
+
});
|
|
678
|
+
},
|
|
534
679
|
async getAnalysis(analysisId) {
|
|
535
680
|
return client.request({
|
|
536
681
|
method: "GET",
|
|
@@ -545,6 +690,29 @@ function createAdminService(client) {
|
|
|
545
690
|
path: "/analyses/",
|
|
546
691
|
body: analysis
|
|
547
692
|
});
|
|
693
|
+
},
|
|
694
|
+
// Utilization
|
|
695
|
+
async getActualUtilization() {
|
|
696
|
+
return client.request({
|
|
697
|
+
method: "GET",
|
|
698
|
+
service: SERVICE,
|
|
699
|
+
path: "/utilization/actual"
|
|
700
|
+
});
|
|
701
|
+
},
|
|
702
|
+
async getUtilizationHistory() {
|
|
703
|
+
return client.request({
|
|
704
|
+
method: "GET",
|
|
705
|
+
service: SERVICE,
|
|
706
|
+
path: "/utilization/history"
|
|
707
|
+
});
|
|
708
|
+
},
|
|
709
|
+
// Recent projects
|
|
710
|
+
async getRecentProjects() {
|
|
711
|
+
return client.request({
|
|
712
|
+
method: "GET",
|
|
713
|
+
service: SERVICE,
|
|
714
|
+
path: "/recent-projects/"
|
|
715
|
+
});
|
|
548
716
|
}
|
|
549
717
|
};
|
|
550
718
|
}
|
|
@@ -569,8 +737,21 @@ function handleError(error) {
|
|
|
569
737
|
}
|
|
570
738
|
|
|
571
739
|
// src/commands/auth/login.ts
|
|
740
|
+
var DEVICE_CLIENT_ID = "diafunc-cli";
|
|
741
|
+
var DEVICE_SCOPE = "openid profile email user";
|
|
742
|
+
var ACCESS_TOKEN_LIFETIME_SECONDS = 15 * 60;
|
|
743
|
+
function deriveAuthUrl2(endpoint) {
|
|
744
|
+
const trimmed = endpoint.replace(/\/+$/, "");
|
|
745
|
+
if (trimmed.includes("://auth.")) {
|
|
746
|
+
return trimmed;
|
|
747
|
+
}
|
|
748
|
+
const url = new URL(trimmed);
|
|
749
|
+
url.hostname = `auth.${url.hostname}`;
|
|
750
|
+
url.pathname = "";
|
|
751
|
+
return url.toString().replace(/\/+$/, "");
|
|
752
|
+
}
|
|
572
753
|
function registerLoginCommand(parent) {
|
|
573
|
-
parent.command("login").description("Authenticate with the Diafunc platform").option("--token <token>", "API token (dfat_...) for token-based auth").option("--endpoint <url>", "Override the endpoint URL for this login").action(async (options) => {
|
|
754
|
+
parent.command("login").description("Authenticate with the Diafunc platform").option("--token <token>", "API token (dfat_...) for non-interactive token-based auth").option("--endpoint <url>", "Override the endpoint URL for this login").option("--password", "Use legacy username/password login instead of OIDC device code").action(async (options) => {
|
|
574
755
|
try {
|
|
575
756
|
const config = loadConfig();
|
|
576
757
|
const profile = config.profiles[config.currentProfile];
|
|
@@ -582,10 +763,7 @@ function registerLoginCommand(parent) {
|
|
|
582
763
|
profile.endpoint = options.endpoint;
|
|
583
764
|
}
|
|
584
765
|
if (options.token) {
|
|
585
|
-
profile.auth = {
|
|
586
|
-
type: "api-token",
|
|
587
|
-
token: options.token
|
|
588
|
-
};
|
|
766
|
+
profile.auth = { type: "api-token", token: options.token };
|
|
589
767
|
saveConfig(config);
|
|
590
768
|
const client = createHttpClient();
|
|
591
769
|
const admin = createAdminService(client);
|
|
@@ -595,55 +773,141 @@ function registerLoginCommand(parent) {
|
|
|
595
773
|
console.log(` Email: ${user.email}`);
|
|
596
774
|
console.log(` Profile: ${config.currentProfile}`);
|
|
597
775
|
console.log(` Endpoint: ${profile.endpoint}`);
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
const pwd = await password({
|
|
604
|
-
message: "Password:"
|
|
605
|
-
});
|
|
606
|
-
const endpoint = profile.endpoint.replace(/\/+$/, "");
|
|
607
|
-
const response = await fetch(`${endpoint}/api/v1/admin/sessions/`, {
|
|
608
|
-
method: "POST",
|
|
609
|
-
headers: { "Content-Type": "application/json" },
|
|
610
|
-
body: JSON.stringify({
|
|
611
|
-
userNameOrEmail: username,
|
|
612
|
-
password: pwd
|
|
613
|
-
})
|
|
614
|
-
});
|
|
615
|
-
if (!response.ok) {
|
|
616
|
-
const text = await response.text();
|
|
617
|
-
console.error(chalk2.red("Login failed:"), text || response.statusText);
|
|
618
|
-
process.exit(1);
|
|
619
|
-
}
|
|
620
|
-
const session = await response.json();
|
|
621
|
-
profile.auth = {
|
|
622
|
-
type: "session",
|
|
623
|
-
accessToken: session.accessToken.raw,
|
|
624
|
-
refreshToken: session.refreshToken.raw,
|
|
625
|
-
accessTokenExpiry: session.accessToken.expiry
|
|
626
|
-
};
|
|
627
|
-
saveConfig(config);
|
|
628
|
-
const client = createHttpClient();
|
|
629
|
-
const admin = createAdminService(client);
|
|
630
|
-
const user = await admin.getMyUser();
|
|
631
|
-
console.log(chalk2.green("Logged in successfully."));
|
|
632
|
-
console.log(` User: ${chalk2.bold(user.name)}`);
|
|
633
|
-
console.log(` Email: ${user.email}`);
|
|
634
|
-
console.log(` Profile: ${config.currentProfile}`);
|
|
635
|
-
console.log(` Endpoint: ${profile.endpoint}`);
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
if (options.password) {
|
|
779
|
+
await legacyPasswordLogin(config, profile);
|
|
780
|
+
return;
|
|
636
781
|
}
|
|
782
|
+
await deviceCodeLogin(config, profile);
|
|
637
783
|
} catch (error) {
|
|
638
784
|
handleError(error);
|
|
639
785
|
}
|
|
640
786
|
});
|
|
641
787
|
}
|
|
788
|
+
async function deviceCodeLogin(config, profile) {
|
|
789
|
+
const authUrl = deriveAuthUrl2(profile.endpoint);
|
|
790
|
+
const deviceResponse = await fetch(`${authUrl}/device_authorization`, {
|
|
791
|
+
method: "POST",
|
|
792
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
793
|
+
body: new URLSearchParams({ client_id: DEVICE_CLIENT_ID, scope: DEVICE_SCOPE }).toString()
|
|
794
|
+
});
|
|
795
|
+
if (!deviceResponse.ok) {
|
|
796
|
+
const text = await deviceResponse.text();
|
|
797
|
+
console.error(chalk2.red("Failed to start device-code flow:"), text || deviceResponse.statusText);
|
|
798
|
+
process.exit(1);
|
|
799
|
+
}
|
|
800
|
+
const device = await deviceResponse.json();
|
|
801
|
+
console.log("");
|
|
802
|
+
console.log(`Open this URL in a browser: ${chalk2.cyan(device.verification_uri)}`);
|
|
803
|
+
console.log(`Enter the code: ${chalk2.bold.yellow(device.user_code)}`);
|
|
804
|
+
console.log("");
|
|
805
|
+
console.log(chalk2.dim("Or open the full URL to pre-fill:"));
|
|
806
|
+
console.log(chalk2.dim(` ${device.verification_uri_complete}`));
|
|
807
|
+
console.log("");
|
|
808
|
+
console.log(chalk2.dim(`Waiting for approval (expires in ${Math.floor(device.expires_in / 60)} min)...`));
|
|
809
|
+
const deadline = Date.now() + device.expires_in * 1e3;
|
|
810
|
+
let interval = Math.max(1, device.interval || 5);
|
|
811
|
+
while (Date.now() < deadline) {
|
|
812
|
+
await sleep(interval * 1e3);
|
|
813
|
+
const pollResponse = await fetch(`${authUrl}/token`, {
|
|
814
|
+
method: "POST",
|
|
815
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
816
|
+
body: new URLSearchParams({
|
|
817
|
+
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
818
|
+
device_code: device.device_code,
|
|
819
|
+
client_id: DEVICE_CLIENT_ID
|
|
820
|
+
}).toString()
|
|
821
|
+
});
|
|
822
|
+
if (pollResponse.ok) {
|
|
823
|
+
const tokens = await pollResponse.json();
|
|
824
|
+
profile.auth = {
|
|
825
|
+
type: "device-code",
|
|
826
|
+
clientId: DEVICE_CLIENT_ID,
|
|
827
|
+
accessToken: tokens.access_token,
|
|
828
|
+
refreshToken: tokens.refresh_token,
|
|
829
|
+
accessTokenExpiry: Date.now() + (tokens.expires_in || ACCESS_TOKEN_LIFETIME_SECONDS) * 1e3
|
|
830
|
+
};
|
|
831
|
+
saveConfig(config);
|
|
832
|
+
const client = createHttpClient();
|
|
833
|
+
const admin = createAdminService(client);
|
|
834
|
+
const user = await admin.getMyUser();
|
|
835
|
+
console.log(chalk2.green("\nLogged in successfully."));
|
|
836
|
+
console.log(` User: ${chalk2.bold(user.name)}`);
|
|
837
|
+
console.log(` Email: ${user.email}`);
|
|
838
|
+
console.log(` Profile: ${config.currentProfile}`);
|
|
839
|
+
console.log(` Endpoint: ${profile.endpoint}`);
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const errorBody = await pollResponse.json().catch(() => ({ error: "unknown" }));
|
|
843
|
+
if (errorBody.error === "authorization_pending") {
|
|
844
|
+
continue;
|
|
845
|
+
}
|
|
846
|
+
if (errorBody.error === "slow_down") {
|
|
847
|
+
interval += 5;
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
if (errorBody.error === "expired_token") {
|
|
851
|
+
console.error(chalk2.red("\nCode expired before approval. Run `diafunc auth login` again."));
|
|
852
|
+
process.exit(1);
|
|
853
|
+
}
|
|
854
|
+
console.error(chalk2.red(`
|
|
855
|
+
Device-code flow failed: ${errorBody.error}${errorBody.error_description ? " \u2014 " + errorBody.error_description : ""}`));
|
|
856
|
+
process.exit(1);
|
|
857
|
+
}
|
|
858
|
+
console.error(chalk2.red("\nTimed out waiting for approval."));
|
|
859
|
+
process.exit(1);
|
|
860
|
+
}
|
|
861
|
+
async function legacyPasswordLogin(config, profile) {
|
|
862
|
+
const { input, password } = await import("@inquirer/prompts");
|
|
863
|
+
const username = await input({ message: "Username or email:" });
|
|
864
|
+
const pwd = await password({ message: "Password:" });
|
|
865
|
+
const endpoint = profile.endpoint.replace(/\/+$/, "");
|
|
866
|
+
const response = await fetch(`${endpoint}/api/v1/admin/sessions/`, {
|
|
867
|
+
method: "POST",
|
|
868
|
+
headers: { "Content-Type": "application/json" },
|
|
869
|
+
body: JSON.stringify({ userNameOrEmail: username, password: pwd })
|
|
870
|
+
});
|
|
871
|
+
if (!response.ok) {
|
|
872
|
+
const text = await response.text();
|
|
873
|
+
console.error(chalk2.red("Login failed:"), text || response.statusText);
|
|
874
|
+
process.exit(1);
|
|
875
|
+
}
|
|
876
|
+
const session = await response.json();
|
|
877
|
+
profile.auth = {
|
|
878
|
+
type: "session",
|
|
879
|
+
accessToken: session.accessToken.raw,
|
|
880
|
+
refreshToken: session.refreshToken.raw,
|
|
881
|
+
accessTokenExpiry: session.accessToken.expiry
|
|
882
|
+
};
|
|
883
|
+
saveConfig(config);
|
|
884
|
+
const client = createHttpClient();
|
|
885
|
+
const admin = createAdminService(client);
|
|
886
|
+
const user = await admin.getMyUser();
|
|
887
|
+
console.log(chalk2.green("Logged in successfully (legacy password path)."));
|
|
888
|
+
console.log(` User: ${chalk2.bold(user.name)}`);
|
|
889
|
+
console.log(` Email: ${user.email}`);
|
|
890
|
+
console.log(` Profile: ${config.currentProfile}`);
|
|
891
|
+
console.log(` Endpoint: ${profile.endpoint}`);
|
|
892
|
+
}
|
|
893
|
+
function sleep(ms) {
|
|
894
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
895
|
+
}
|
|
642
896
|
|
|
643
897
|
// src/commands/auth/logout.ts
|
|
644
898
|
import chalk3 from "chalk";
|
|
899
|
+
function deriveAuthUrl3(endpoint) {
|
|
900
|
+
const trimmed = endpoint.replace(/\/+$/, "");
|
|
901
|
+
if (trimmed.includes("://auth.")) {
|
|
902
|
+
return trimmed;
|
|
903
|
+
}
|
|
904
|
+
const url = new URL(trimmed);
|
|
905
|
+
url.hostname = `auth.${url.hostname}`;
|
|
906
|
+
url.pathname = "";
|
|
907
|
+
return url.toString().replace(/\/+$/, "");
|
|
908
|
+
}
|
|
645
909
|
function registerLogoutCommand(parent) {
|
|
646
|
-
parent.command("logout").description("Remove stored credentials for the active profile").action(() => {
|
|
910
|
+
parent.command("logout").description("Remove stored credentials for the active profile and revoke refresh token if possible").action(async () => {
|
|
647
911
|
const config = loadConfig();
|
|
648
912
|
const profile = config.profiles[config.currentProfile];
|
|
649
913
|
if (!profile) {
|
|
@@ -654,6 +918,26 @@ function registerLogoutCommand(parent) {
|
|
|
654
918
|
console.log(chalk3.dim("No credentials stored for this profile."));
|
|
655
919
|
return;
|
|
656
920
|
}
|
|
921
|
+
if (profile.auth.type === "device-code") {
|
|
922
|
+
try {
|
|
923
|
+
const authUrl = deriveAuthUrl3(profile.endpoint);
|
|
924
|
+
await fetch(`${authUrl}/revoke`, {
|
|
925
|
+
method: "POST",
|
|
926
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
927
|
+
body: new URLSearchParams({
|
|
928
|
+
token: profile.auth.refreshToken,
|
|
929
|
+
token_type_hint: "refresh_token"
|
|
930
|
+
}).toString()
|
|
931
|
+
});
|
|
932
|
+
} catch {
|
|
933
|
+
}
|
|
934
|
+
} else if (profile.auth.type === "session") {
|
|
935
|
+
try {
|
|
936
|
+
const endpoint = profile.endpoint.replace(/\/+$/, "");
|
|
937
|
+
await fetch(`${endpoint}/api/v1/admin/sessions/`, { method: "DELETE" });
|
|
938
|
+
} catch {
|
|
939
|
+
}
|
|
940
|
+
}
|
|
657
941
|
delete profile.auth;
|
|
658
942
|
saveConfig(config);
|
|
659
943
|
console.log(chalk3.green(`Logged out from profile "${config.currentProfile}".`));
|
|
@@ -934,14 +1218,14 @@ function createStorageService(client) {
|
|
|
934
1218
|
});
|
|
935
1219
|
},
|
|
936
1220
|
async deleteLink(projectId, projectBranch, sourceEntityId, sourceEntityBranch, linkId, targetEntityId, targetEntityBranch) {
|
|
937
|
-
let
|
|
1221
|
+
let path7 = `/links/actual/${enc(projectId)}/${enc(projectBranch)}/${enc(sourceEntityId)}/${enc(sourceEntityBranch)}/${enc(linkId)}`;
|
|
938
1222
|
if (targetEntityId && targetEntityBranch) {
|
|
939
|
-
|
|
1223
|
+
path7 += `/${enc(targetEntityId)}/${enc(targetEntityBranch)}`;
|
|
940
1224
|
}
|
|
941
1225
|
return client.request({
|
|
942
1226
|
method: "DELETE",
|
|
943
1227
|
service: SERVICE2,
|
|
944
|
-
path:
|
|
1228
|
+
path: path7
|
|
945
1229
|
});
|
|
946
1230
|
},
|
|
947
1231
|
// --- Events ---
|
|
@@ -1135,7 +1419,54 @@ function createStorageService(client) {
|
|
|
1135
1419
|
path: `/project-searches/${enc(projectId)}/${enc(projectBranch)}`,
|
|
1136
1420
|
body
|
|
1137
1421
|
});
|
|
1422
|
+
},
|
|
1423
|
+
// --- Backups ---
|
|
1424
|
+
async createShortTermProjectBackup() {
|
|
1425
|
+
return client.request({
|
|
1426
|
+
method: "POST",
|
|
1427
|
+
service: SERVICE2,
|
|
1428
|
+
path: "/backups/project/short-term/create"
|
|
1429
|
+
});
|
|
1430
|
+
},
|
|
1431
|
+
async createLongTermProjectBackup() {
|
|
1432
|
+
return client.request({
|
|
1433
|
+
method: "POST",
|
|
1434
|
+
service: SERVICE2,
|
|
1435
|
+
path: "/backups/project/long-term/create"
|
|
1436
|
+
});
|
|
1437
|
+
},
|
|
1438
|
+
async restoreProjectBackup(request) {
|
|
1439
|
+
return client.request({
|
|
1440
|
+
method: "POST",
|
|
1441
|
+
service: SERVICE2,
|
|
1442
|
+
path: "/backups/project/restore",
|
|
1443
|
+
body: request
|
|
1444
|
+
});
|
|
1445
|
+
},
|
|
1446
|
+
async createShortTermFullBackup() {
|
|
1447
|
+
return client.request({
|
|
1448
|
+
method: "POST",
|
|
1449
|
+
service: SERVICE2,
|
|
1450
|
+
path: "/backups/full/short-term/create"
|
|
1451
|
+
});
|
|
1452
|
+
},
|
|
1453
|
+
async createLongTermFullBackup() {
|
|
1454
|
+
return client.request({
|
|
1455
|
+
method: "POST",
|
|
1456
|
+
service: SERVICE2,
|
|
1457
|
+
path: "/backups/full/long-term/create"
|
|
1458
|
+
});
|
|
1459
|
+
},
|
|
1460
|
+
async restoreFullBackup(request) {
|
|
1461
|
+
return client.request({
|
|
1462
|
+
method: "POST",
|
|
1463
|
+
service: SERVICE2,
|
|
1464
|
+
path: "/backups/full/restore",
|
|
1465
|
+
body: request
|
|
1466
|
+
});
|
|
1138
1467
|
}
|
|
1468
|
+
// --- Event write ops (moved from read-only block) ---
|
|
1469
|
+
// NOTE: createEvents / consumeEvents already exist above in the Events section.
|
|
1139
1470
|
};
|
|
1140
1471
|
}
|
|
1141
1472
|
|
|
@@ -1255,6 +1586,9 @@ function createEvaluationService(client) {
|
|
|
1255
1586
|
|
|
1256
1587
|
// src/client/services/scheduler.ts
|
|
1257
1588
|
var SERVICE4 = "scheduler";
|
|
1589
|
+
function enc3(s) {
|
|
1590
|
+
return encodeURIComponent(s);
|
|
1591
|
+
}
|
|
1258
1592
|
function createSchedulerService(client) {
|
|
1259
1593
|
return {
|
|
1260
1594
|
async scheduleCall(request) {
|
|
@@ -1264,13 +1598,20 @@ function createSchedulerService(client) {
|
|
|
1264
1598
|
path: "/calls/",
|
|
1265
1599
|
body: request
|
|
1266
1600
|
});
|
|
1601
|
+
},
|
|
1602
|
+
async stopScheduled(projectId, projectBranch, functionId, functionBranch, year, month, day, hour, evaluationId) {
|
|
1603
|
+
return client.request({
|
|
1604
|
+
method: "POST",
|
|
1605
|
+
service: SERVICE4,
|
|
1606
|
+
path: `/stop/${enc3(projectId)}/${enc3(projectBranch)}/${enc3(functionId)}/${enc3(functionBranch)}/${year}/${month}/${day}/${hour}/${enc3(evaluationId)}`
|
|
1607
|
+
});
|
|
1267
1608
|
}
|
|
1268
1609
|
};
|
|
1269
1610
|
}
|
|
1270
1611
|
|
|
1271
1612
|
// src/client/services/language.ts
|
|
1272
1613
|
var SERVICE5 = "language";
|
|
1273
|
-
function
|
|
1614
|
+
function enc4(s) {
|
|
1274
1615
|
return encodeURIComponent(s);
|
|
1275
1616
|
}
|
|
1276
1617
|
function createLanguageService(client) {
|
|
@@ -1322,28 +1663,28 @@ function createLanguageService(client) {
|
|
|
1322
1663
|
return client.request({
|
|
1323
1664
|
method: "GET",
|
|
1324
1665
|
service: SERVICE5,
|
|
1325
|
-
path: `/sessions/${
|
|
1666
|
+
path: `/sessions/${enc4(sessionId)}`
|
|
1326
1667
|
});
|
|
1327
1668
|
},
|
|
1328
1669
|
async deleteSession(sessionId) {
|
|
1329
1670
|
return client.request({
|
|
1330
1671
|
method: "DELETE",
|
|
1331
1672
|
service: SERVICE5,
|
|
1332
|
-
path: `/sessions/${
|
|
1673
|
+
path: `/sessions/${enc4(sessionId)}`
|
|
1333
1674
|
});
|
|
1334
1675
|
},
|
|
1335
1676
|
async getSessionMessages(sessionId) {
|
|
1336
1677
|
return client.request({
|
|
1337
1678
|
method: "GET",
|
|
1338
1679
|
service: SERVICE5,
|
|
1339
|
-
path: `/sessions/${
|
|
1680
|
+
path: `/sessions/${enc4(sessionId)}/messages`
|
|
1340
1681
|
});
|
|
1341
1682
|
},
|
|
1342
1683
|
async renameSession(sessionId, title) {
|
|
1343
1684
|
return client.request({
|
|
1344
1685
|
method: "PUT",
|
|
1345
1686
|
service: SERVICE5,
|
|
1346
|
-
path: `/sessions/${
|
|
1687
|
+
path: `/sessions/${enc4(sessionId)}/title`,
|
|
1347
1688
|
rawBody: title,
|
|
1348
1689
|
contentType: "text/plain"
|
|
1349
1690
|
});
|
|
@@ -1353,7 +1694,7 @@ function createLanguageService(client) {
|
|
|
1353
1694
|
|
|
1354
1695
|
// src/client/services/index-search.ts
|
|
1355
1696
|
var SERVICE6 = "index";
|
|
1356
|
-
function
|
|
1697
|
+
function enc5(s) {
|
|
1357
1698
|
return encodeURIComponent(s);
|
|
1358
1699
|
}
|
|
1359
1700
|
function createIndexService(client) {
|
|
@@ -1369,7 +1710,7 @@ function createIndexService(client) {
|
|
|
1369
1710
|
return client.request({
|
|
1370
1711
|
method: "POST",
|
|
1371
1712
|
service: SERVICE6,
|
|
1372
|
-
path: `/indexes/rebuild/${
|
|
1713
|
+
path: `/indexes/rebuild/${enc5(projectId)}`
|
|
1373
1714
|
});
|
|
1374
1715
|
}
|
|
1375
1716
|
};
|
|
@@ -1572,8 +1913,8 @@ function registerConfigCommands(program) {
|
|
|
1572
1913
|
console.log(chalk7.green(`Profile "${name}" removed.`));
|
|
1573
1914
|
});
|
|
1574
1915
|
}
|
|
1575
|
-
function setNestedValue(obj,
|
|
1576
|
-
const keys =
|
|
1916
|
+
function setNestedValue(obj, path7, value) {
|
|
1917
|
+
const keys = path7.split(".");
|
|
1577
1918
|
let current = obj;
|
|
1578
1919
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
1579
1920
|
const key = keys[i];
|
|
@@ -1584,8 +1925,8 @@ function setNestedValue(obj, path5, value) {
|
|
|
1584
1925
|
}
|
|
1585
1926
|
current[keys[keys.length - 1]] = value;
|
|
1586
1927
|
}
|
|
1587
|
-
function getNestedValue(obj,
|
|
1588
|
-
const keys =
|
|
1928
|
+
function getNestedValue(obj, path7) {
|
|
1929
|
+
const keys = path7.split(".");
|
|
1589
1930
|
let current = obj;
|
|
1590
1931
|
for (const key of keys) {
|
|
1591
1932
|
if (current === null || current === void 0 || typeof current !== "object") {
|
|
@@ -1649,6 +1990,36 @@ function registerProjectCommands(program) {
|
|
|
1649
1990
|
handleError(error);
|
|
1650
1991
|
}
|
|
1651
1992
|
});
|
|
1993
|
+
project.command("update").description("Update a project").argument("<projectId>", "Project ID").option("--visibility <visibility>", "PRIVATE or PUBLIC").option("--language <language>", "Project language").option("--group <groupId>", "Group ID (empty string to unset)").option("--active <bool>", "Whether the project is active (true/false)").action(async (projectId, options) => {
|
|
1994
|
+
try {
|
|
1995
|
+
const api = createApiClient();
|
|
1996
|
+
const current = await api.admin.getProject(projectId);
|
|
1997
|
+
const updated = {
|
|
1998
|
+
...current,
|
|
1999
|
+
...options.visibility ? { visibility: options.visibility.toUpperCase() } : {},
|
|
2000
|
+
...options.language ? { language: options.language } : {},
|
|
2001
|
+
...options.group !== void 0 ? { groupId: options.group || null } : {},
|
|
2002
|
+
...options.active !== void 0 ? { active: options.active === "true" } : {}
|
|
2003
|
+
};
|
|
2004
|
+
await api.admin.updateProject(updated);
|
|
2005
|
+
console.log(chalk8.green(`Project "${projectId}" updated.`));
|
|
2006
|
+
} catch (error) {
|
|
2007
|
+
handleError(error);
|
|
2008
|
+
}
|
|
2009
|
+
});
|
|
2010
|
+
project.command("recent").description("List recently accessed projects").action(async (_options, cmd) => {
|
|
2011
|
+
try {
|
|
2012
|
+
const outputFormat = getOutputFormat(cmd);
|
|
2013
|
+
const api = createApiClient();
|
|
2014
|
+
const recent = await api.admin.getRecentProjects();
|
|
2015
|
+
format(recent, {
|
|
2016
|
+
format: outputFormat,
|
|
2017
|
+
columns: ["projectId", "projectBranch", "lastAccessed"]
|
|
2018
|
+
});
|
|
2019
|
+
} catch (error) {
|
|
2020
|
+
handleError(error);
|
|
2021
|
+
}
|
|
2022
|
+
});
|
|
1652
2023
|
project.command("delete").description("Delete a project").argument("<projectId>", "Project ID").action(async (projectId) => {
|
|
1653
2024
|
try {
|
|
1654
2025
|
const api = createApiClient();
|
|
@@ -2103,6 +2474,43 @@ function registerEventCommands(program) {
|
|
|
2103
2474
|
handleError(error);
|
|
2104
2475
|
}
|
|
2105
2476
|
});
|
|
2477
|
+
event.command("create").description("Create one or more events (body from JSON file or stdin)").argument("[file]", "JSON file containing a BareEvent array; defaults to stdin").action(async (file) => {
|
|
2478
|
+
try {
|
|
2479
|
+
const fs9 = await import("fs");
|
|
2480
|
+
const body = file ? fs9.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
2481
|
+
let data = "";
|
|
2482
|
+
process.stdin.setEncoding("utf-8");
|
|
2483
|
+
process.stdin.on("data", (chunk) => {
|
|
2484
|
+
data += chunk;
|
|
2485
|
+
});
|
|
2486
|
+
process.stdin.on("end", () => resolve(data));
|
|
2487
|
+
process.stdin.on("error", reject);
|
|
2488
|
+
});
|
|
2489
|
+
const events = JSON.parse(body);
|
|
2490
|
+
const api = createApiClient();
|
|
2491
|
+
const arr = Array.isArray(events) ? events : [events];
|
|
2492
|
+
await api.storage.createEvents(arr);
|
|
2493
|
+
console.log(chalk11.green(`${arr.length} event(s) created.`));
|
|
2494
|
+
} catch (error) {
|
|
2495
|
+
handleError(error);
|
|
2496
|
+
}
|
|
2497
|
+
});
|
|
2498
|
+
event.command("consume").description("Consume events for a given project and consumer").argument("<projectRef>", "Project reference (projectId or projectId/branch)").requiredOption("--consumer-type <type>", "Consumer type").requiredOption("--consumer-id <id>", "Consumer ID").option("--events <json>", "Event references as JSON array", "[]").action(async (projectRef, options) => {
|
|
2499
|
+
try {
|
|
2500
|
+
const [projectId, projectBranch = "main"] = projectRef.split("/");
|
|
2501
|
+
const api = createApiClient();
|
|
2502
|
+
const events = await api.storage.consumeEvents({
|
|
2503
|
+
projectId,
|
|
2504
|
+
projectBranch,
|
|
2505
|
+
eventReferences: JSON.parse(options.events),
|
|
2506
|
+
consumerType: options.consumerType,
|
|
2507
|
+
consumerId: options.consumerId
|
|
2508
|
+
});
|
|
2509
|
+
console.log(JSON.stringify(events, null, 2));
|
|
2510
|
+
} catch (error) {
|
|
2511
|
+
handleError(error);
|
|
2512
|
+
}
|
|
2513
|
+
});
|
|
2106
2514
|
event.command("delete").description("Delete an event").argument("<ref>", "Entity reference").argument("<eventId>", "Event ID").argument("<occurrenceId>", "Occurrence ID").action(async (ref, eventId, occurrenceId, _options, cmd) => {
|
|
2107
2515
|
try {
|
|
2108
2516
|
const overrides = getOverrides3(cmd);
|
|
@@ -2428,7 +2836,61 @@ function registerTableCommands(program) {
|
|
|
2428
2836
|
|
|
2429
2837
|
// src/commands/function/index.ts
|
|
2430
2838
|
import chalk14 from "chalk";
|
|
2839
|
+
import * as fs4 from "fs";
|
|
2840
|
+
import * as os2 from "os";
|
|
2841
|
+
import * as path3 from "path";
|
|
2842
|
+
import { spawn } from "child_process";
|
|
2431
2843
|
import { randomUUID } from "crypto";
|
|
2844
|
+
|
|
2845
|
+
// src/util/function-content.ts
|
|
2846
|
+
function decodeFunctionSource(entity) {
|
|
2847
|
+
if (!entity.content) return "";
|
|
2848
|
+
const json = Buffer.from(entity.content, "base64").toString("utf-8");
|
|
2849
|
+
try {
|
|
2850
|
+
const parsed = JSON.parse(json);
|
|
2851
|
+
return parsed.sourceCode ?? "";
|
|
2852
|
+
} catch {
|
|
2853
|
+
return json;
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
function encodeFunctionSource(sourceCode) {
|
|
2857
|
+
return Buffer.from(JSON.stringify({ sourceCode })).toString("base64");
|
|
2858
|
+
}
|
|
2859
|
+
function buildFunctionEntity(args) {
|
|
2860
|
+
const now = Date.now();
|
|
2861
|
+
const attributes = { language: args.language };
|
|
2862
|
+
const attributeTypes = { language: "text" };
|
|
2863
|
+
if (args.name !== null && args.name !== void 0) {
|
|
2864
|
+
attributes.name = args.name;
|
|
2865
|
+
attributeTypes.name = "text";
|
|
2866
|
+
}
|
|
2867
|
+
return {
|
|
2868
|
+
projectId: args.projectId,
|
|
2869
|
+
projectBranch: args.projectBranch,
|
|
2870
|
+
entityId: args.entityId,
|
|
2871
|
+
entityBranch: args.entityBranch,
|
|
2872
|
+
head: true,
|
|
2873
|
+
version: 1,
|
|
2874
|
+
type: "function",
|
|
2875
|
+
attributes,
|
|
2876
|
+
attributeTypes,
|
|
2877
|
+
metaAttributes: {},
|
|
2878
|
+
metaAttributeTypes: {},
|
|
2879
|
+
tags: [],
|
|
2880
|
+
modified: now,
|
|
2881
|
+
created: now,
|
|
2882
|
+
versioned: false,
|
|
2883
|
+
versionTtl: null,
|
|
2884
|
+
retain: false,
|
|
2885
|
+
contentAvailable: true,
|
|
2886
|
+
contentLoaded: true,
|
|
2887
|
+
contentType: "application/script",
|
|
2888
|
+
contentSize: null,
|
|
2889
|
+
content: encodeFunctionSource(args.sourceCode)
|
|
2890
|
+
};
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
// src/commands/function/index.ts
|
|
2432
2894
|
function getOutputFormat7(cmd) {
|
|
2433
2895
|
const config = loadConfig();
|
|
2434
2896
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -2641,25 +3103,140 @@ function registerFunctionCommands(program) {
|
|
|
2641
3103
|
handleError(error);
|
|
2642
3104
|
}
|
|
2643
3105
|
});
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
// src/commands/trigger/index.ts
|
|
2647
|
-
import chalk15 from "chalk";
|
|
2648
|
-
function getOutputFormat8(cmd) {
|
|
2649
|
-
const config = loadConfig();
|
|
2650
|
-
const globalOpts = cmd.optsWithGlobals();
|
|
2651
|
-
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2652
|
-
}
|
|
2653
|
-
function getOverrides7(cmd) {
|
|
2654
|
-
const opts = cmd.optsWithGlobals();
|
|
2655
|
-
return { project: opts.project, branch: opts.branch };
|
|
2656
|
-
}
|
|
2657
|
-
function registerTriggerCommands(program) {
|
|
2658
|
-
const trigger = program.command("trigger").description("Manage function triggers");
|
|
2659
|
-
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3106
|
+
fn.command("last-evaluation").description("Show the most recent evaluation of a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
2660
3107
|
try {
|
|
2661
|
-
const outputFormat =
|
|
2662
|
-
const overrides =
|
|
3108
|
+
const outputFormat = getOutputFormat7(cmd);
|
|
3109
|
+
const overrides = getOverrides6(cmd);
|
|
3110
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3111
|
+
const api = createApiClient();
|
|
3112
|
+
const evaluation = await api.evaluation.getLastEvaluation(
|
|
3113
|
+
resolved.projectId,
|
|
3114
|
+
resolved.projectBranch,
|
|
3115
|
+
resolved.entityId,
|
|
3116
|
+
resolved.entityBranch
|
|
3117
|
+
);
|
|
3118
|
+
format(evaluation, { format: outputFormat });
|
|
3119
|
+
} catch (error) {
|
|
3120
|
+
handleError(error);
|
|
3121
|
+
}
|
|
3122
|
+
});
|
|
3123
|
+
fn.command("create").description("Create a new function entity").argument("<ref>", "Function entity reference").option("--language <lang>", "Function language (Java, JavaScript, Kotlin, Python, Scala)", "Java").option("--source <file>", "Initial source code file").option("--name <name>", "Display name (defaults to entityId)").action(async (ref, options, cmd) => {
|
|
3124
|
+
try {
|
|
3125
|
+
const overrides = getOverrides6(cmd);
|
|
3126
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3127
|
+
const api = createApiClient();
|
|
3128
|
+
const sourceCode = options.source ? fs4.readFileSync(options.source, "utf-8") : "";
|
|
3129
|
+
const entity = buildFunctionEntity({
|
|
3130
|
+
projectId: resolved.projectId,
|
|
3131
|
+
projectBranch: resolved.projectBranch,
|
|
3132
|
+
entityId: resolved.entityId,
|
|
3133
|
+
entityBranch: resolved.entityBranch,
|
|
3134
|
+
name: options.name ?? resolved.entityId,
|
|
3135
|
+
language: options.language,
|
|
3136
|
+
sourceCode
|
|
3137
|
+
});
|
|
3138
|
+
await api.storage.saveEntities([entity]);
|
|
3139
|
+
console.log(chalk14.green(`Function "${resolved.entityId}" created (${options.language}).`));
|
|
3140
|
+
} catch (error) {
|
|
3141
|
+
handleError(error);
|
|
3142
|
+
}
|
|
3143
|
+
});
|
|
3144
|
+
const source = fn.command("source").description("Get or set function source code");
|
|
3145
|
+
source.command("get").description("Print the function source code").argument("<ref>", "Function entity reference").option("--out <file>", "Write source to this file instead of stdout").action(async (ref, options, cmd) => {
|
|
3146
|
+
try {
|
|
3147
|
+
const overrides = getOverrides6(cmd);
|
|
3148
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3149
|
+
const api = createApiClient();
|
|
3150
|
+
const entity = await api.storage.getEntity(resolved, true);
|
|
3151
|
+
const sourceCode = decodeFunctionSource(entity);
|
|
3152
|
+
if (options.out) {
|
|
3153
|
+
fs4.writeFileSync(options.out, sourceCode);
|
|
3154
|
+
console.log(chalk14.green(`Source written to ${options.out}`));
|
|
3155
|
+
} else {
|
|
3156
|
+
process.stdout.write(sourceCode);
|
|
3157
|
+
if (!sourceCode.endsWith("\n")) process.stdout.write("\n");
|
|
3158
|
+
}
|
|
3159
|
+
} catch (error) {
|
|
3160
|
+
handleError(error);
|
|
3161
|
+
}
|
|
3162
|
+
});
|
|
3163
|
+
source.command("set").description("Replace the function source code from a file or stdin").argument("<ref>", "Function entity reference").argument("[file]", "Source file; defaults to stdin").action(async (ref, file, _options, cmd) => {
|
|
3164
|
+
try {
|
|
3165
|
+
const overrides = getOverrides6(cmd);
|
|
3166
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3167
|
+
const api = createApiClient();
|
|
3168
|
+
const sourceCode = file ? fs4.readFileSync(file, "utf-8") : await new Promise((resolve, reject) => {
|
|
3169
|
+
let data = "";
|
|
3170
|
+
process.stdin.setEncoding("utf-8");
|
|
3171
|
+
process.stdin.on("data", (chunk) => {
|
|
3172
|
+
data += chunk;
|
|
3173
|
+
});
|
|
3174
|
+
process.stdin.on("end", () => resolve(data));
|
|
3175
|
+
process.stdin.on("error", reject);
|
|
3176
|
+
});
|
|
3177
|
+
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(sourceCode));
|
|
3178
|
+
console.log(chalk14.green(`Source updated for "${resolved.entityId}".`));
|
|
3179
|
+
} catch (error) {
|
|
3180
|
+
handleError(error);
|
|
3181
|
+
}
|
|
3182
|
+
});
|
|
3183
|
+
fn.command("edit").description("Open the function source in $EDITOR and save on exit").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3184
|
+
try {
|
|
3185
|
+
const overrides = getOverrides6(cmd);
|
|
3186
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3187
|
+
const api = createApiClient();
|
|
3188
|
+
const entity = await api.storage.getEntity(resolved, true);
|
|
3189
|
+
const currentSource = decodeFunctionSource(entity);
|
|
3190
|
+
const language = entity.attributes?.["language"] ?? "txt";
|
|
3191
|
+
const ext = extensionFor(language);
|
|
3192
|
+
const tmpFile = path3.join(os2.tmpdir(), `diafunc-${resolved.entityId}-${randomUUID()}.${ext}`);
|
|
3193
|
+
fs4.writeFileSync(tmpFile, currentSource);
|
|
3194
|
+
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
3195
|
+
await new Promise((resolve, reject) => {
|
|
3196
|
+
const child = spawn(editor, [tmpFile], { stdio: "inherit" });
|
|
3197
|
+
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with code ${code}`)));
|
|
3198
|
+
child.on("error", reject);
|
|
3199
|
+
});
|
|
3200
|
+
const newSource = fs4.readFileSync(tmpFile, "utf-8");
|
|
3201
|
+
fs4.unlinkSync(tmpFile);
|
|
3202
|
+
if (newSource === currentSource) {
|
|
3203
|
+
console.log(chalk14.dim("No changes."));
|
|
3204
|
+
return;
|
|
3205
|
+
}
|
|
3206
|
+
await api.storage.saveEntityContentBase64(resolved, encodeFunctionSource(newSource));
|
|
3207
|
+
console.log(chalk14.green(`Source updated for "${resolved.entityId}".`));
|
|
3208
|
+
} catch (error) {
|
|
3209
|
+
handleError(error);
|
|
3210
|
+
}
|
|
3211
|
+
});
|
|
3212
|
+
}
|
|
3213
|
+
function extensionFor(language) {
|
|
3214
|
+
const l = language.toLowerCase();
|
|
3215
|
+
if (l === "java") return "java";
|
|
3216
|
+
if (l === "javascript" || l === "js") return "js";
|
|
3217
|
+
if (l === "kotlin") return "kt";
|
|
3218
|
+
if (l === "python") return "py";
|
|
3219
|
+
if (l === "scala") return "scala";
|
|
3220
|
+
return "txt";
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
// src/commands/trigger/index.ts
|
|
3224
|
+
import chalk15 from "chalk";
|
|
3225
|
+
function getOutputFormat8(cmd) {
|
|
3226
|
+
const config = loadConfig();
|
|
3227
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
3228
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
3229
|
+
}
|
|
3230
|
+
function getOverrides7(cmd) {
|
|
3231
|
+
const opts = cmd.optsWithGlobals();
|
|
3232
|
+
return { project: opts.project, branch: opts.branch };
|
|
3233
|
+
}
|
|
3234
|
+
function registerTriggerCommands(program) {
|
|
3235
|
+
const trigger = program.command("trigger").description("Manage function triggers");
|
|
3236
|
+
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3237
|
+
try {
|
|
3238
|
+
const outputFormat = getOutputFormat8(cmd);
|
|
3239
|
+
const overrides = getOverrides7(cmd);
|
|
2663
3240
|
const resolved = parseEntityReference(ref, overrides);
|
|
2664
3241
|
const api = createApiClient();
|
|
2665
3242
|
const triggers = await api.evaluation.getTriggers(
|
|
@@ -2719,6 +3296,54 @@ function registerTriggerCommands(program) {
|
|
|
2719
3296
|
handleError(error);
|
|
2720
3297
|
}
|
|
2721
3298
|
});
|
|
3299
|
+
trigger.command("create").description("Create or update a trigger on a function").argument("<ref>", "Function entity reference").requiredOption("--type <type>", "Trigger type (SCHEDULE, EVENT, LINK, MANUAL)").option("--trigger-id <id>", "Trigger ID (auto-generated if omitted)").option("--expression <expr>", "Cron expression (for SCHEDULE) or event pattern").option("--origin <ref>", "Origin entity reference (for LINK/EVENT)").option("--persistent", "Persistent trigger (survives after first fire)").option("--inactive", "Create the trigger inactive").option("--max <n>", "Maximum fire count (0 = unlimited)", "0").option("--args <json>", "Arguments passed on fire (JSON object)").action(async (ref, options, cmd) => {
|
|
3300
|
+
try {
|
|
3301
|
+
const overrides = getOverrides7(cmd);
|
|
3302
|
+
const fn = parseEntityReference(ref, overrides);
|
|
3303
|
+
const api = createApiClient();
|
|
3304
|
+
const args = options.args ? JSON.parse(options.args) : null;
|
|
3305
|
+
const types = args ? Object.fromEntries(
|
|
3306
|
+
Object.entries(args).map(([k, v]) => [k, typeof v === "number" ? "number" : typeof v === "boolean" ? "bool" : "string"])
|
|
3307
|
+
) : null;
|
|
3308
|
+
let originEntityId = null;
|
|
3309
|
+
let originEntityBranch = null;
|
|
3310
|
+
if (options.origin) {
|
|
3311
|
+
const o = parseEntityReference(options.origin, overrides);
|
|
3312
|
+
originEntityId = o.entityId;
|
|
3313
|
+
originEntityBranch = o.entityBranch;
|
|
3314
|
+
}
|
|
3315
|
+
await api.evaluation.saveTrigger({
|
|
3316
|
+
projectId: fn.projectId,
|
|
3317
|
+
projectBranch: fn.projectBranch,
|
|
3318
|
+
functionId: fn.entityId,
|
|
3319
|
+
functionBranch: fn.entityBranch,
|
|
3320
|
+
triggerId: options.triggerId ?? null,
|
|
3321
|
+
bucketId: null,
|
|
3322
|
+
type: options.type.toUpperCase(),
|
|
3323
|
+
expression: options.expression ?? null,
|
|
3324
|
+
conditions: null,
|
|
3325
|
+
conditionTypes: null,
|
|
3326
|
+
originEntityId,
|
|
3327
|
+
originEntityBranch,
|
|
3328
|
+
active: !options.inactive,
|
|
3329
|
+
quantity: 0,
|
|
3330
|
+
fired: 0,
|
|
3331
|
+
maximum: options.max ? parseInt(options.max, 10) || null : null,
|
|
3332
|
+
evaluationIds: null,
|
|
3333
|
+
arguments: args,
|
|
3334
|
+
types,
|
|
3335
|
+
persistent: !!options.persistent,
|
|
3336
|
+
removeFunction: false,
|
|
3337
|
+
modified: null,
|
|
3338
|
+
created: null,
|
|
3339
|
+
scheduler: null,
|
|
3340
|
+
heartbeat: null
|
|
3341
|
+
});
|
|
3342
|
+
console.log(chalk15.green("Trigger saved."));
|
|
3343
|
+
} catch (error) {
|
|
3344
|
+
handleError(error);
|
|
3345
|
+
}
|
|
3346
|
+
});
|
|
2722
3347
|
}
|
|
2723
3348
|
|
|
2724
3349
|
// src/commands/schedule/index.ts
|
|
@@ -2782,19 +3407,182 @@ function registerScheduleCommands(program) {
|
|
|
2782
3407
|
handleError(error);
|
|
2783
3408
|
}
|
|
2784
3409
|
});
|
|
3410
|
+
schedule.command("stop").description("Stop a scheduled function evaluation").argument("<ref>", "Function entity reference").argument("<evaluationId>", "Evaluation ID to stop").requiredOption("--date <date>", "Evaluation date/hour (YYYY-MM-DD-HH in UTC)").action(async (ref, evaluationId, options, cmd) => {
|
|
3411
|
+
try {
|
|
3412
|
+
const overrides = getOverrides8(cmd);
|
|
3413
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3414
|
+
const api = createApiClient();
|
|
3415
|
+
const [year, month, day, hour] = options.date.split("-").map(Number);
|
|
3416
|
+
await api.scheduler.stopScheduled(
|
|
3417
|
+
resolved.projectId,
|
|
3418
|
+
resolved.projectBranch,
|
|
3419
|
+
resolved.entityId,
|
|
3420
|
+
resolved.entityBranch,
|
|
3421
|
+
year,
|
|
3422
|
+
month,
|
|
3423
|
+
day,
|
|
3424
|
+
hour,
|
|
3425
|
+
evaluationId
|
|
3426
|
+
);
|
|
3427
|
+
console.log(chalk16.green(`Scheduled evaluation ${evaluationId} stopped.`));
|
|
3428
|
+
} catch (error) {
|
|
3429
|
+
handleError(error);
|
|
3430
|
+
}
|
|
3431
|
+
});
|
|
3432
|
+
schedule.command("list").description("List persistent triggers (scheduled functions are modeled as triggers)").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
3433
|
+
try {
|
|
3434
|
+
const outputFormat = getOutputFormat9(cmd);
|
|
3435
|
+
const overrides = getOverrides8(cmd);
|
|
3436
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
3437
|
+
const api = createApiClient();
|
|
3438
|
+
const triggers = await api.evaluation.getTriggers(
|
|
3439
|
+
resolved.projectId,
|
|
3440
|
+
resolved.projectBranch,
|
|
3441
|
+
resolved.entityId,
|
|
3442
|
+
resolved.entityBranch
|
|
3443
|
+
);
|
|
3444
|
+
const scheduled = triggers.filter((t) => t.type === "SCHEDULE");
|
|
3445
|
+
const rows = scheduled.map((t) => ({
|
|
3446
|
+
triggerId: t.triggerId,
|
|
3447
|
+
expression: t.expression,
|
|
3448
|
+
active: t.active,
|
|
3449
|
+
fired: t.fired,
|
|
3450
|
+
maximum: t.maximum,
|
|
3451
|
+
persistent: t.persistent
|
|
3452
|
+
}));
|
|
3453
|
+
format(rows, {
|
|
3454
|
+
format: outputFormat,
|
|
3455
|
+
columns: ["triggerId", "expression", "active", "fired", "maximum", "persistent"]
|
|
3456
|
+
});
|
|
3457
|
+
} catch (error) {
|
|
3458
|
+
handleError(error);
|
|
3459
|
+
}
|
|
3460
|
+
});
|
|
2785
3461
|
}
|
|
2786
3462
|
|
|
2787
3463
|
// src/commands/chat/index.ts
|
|
2788
3464
|
import chalk17 from "chalk";
|
|
2789
|
-
import * as
|
|
2790
|
-
import * as
|
|
3465
|
+
import * as fs5 from "fs";
|
|
3466
|
+
import * as path4 from "path";
|
|
2791
3467
|
function getOutputFormat10(cmd) {
|
|
2792
3468
|
const config = loadConfig();
|
|
2793
3469
|
const globalOpts = cmd.optsWithGlobals();
|
|
2794
3470
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
2795
3471
|
}
|
|
3472
|
+
async function streamOneTurn(message, sessionId, projectId, branch) {
|
|
3473
|
+
const api = createApiClient();
|
|
3474
|
+
const response = await api.language.chatStream({
|
|
3475
|
+
message,
|
|
3476
|
+
sessionId,
|
|
3477
|
+
projectId,
|
|
3478
|
+
projectBranch: projectId ? branch : void 0
|
|
3479
|
+
});
|
|
3480
|
+
const reader = response.body.getReader();
|
|
3481
|
+
const decoder = new TextDecoder();
|
|
3482
|
+
let buffer = "";
|
|
3483
|
+
let finalSession = sessionId ?? "";
|
|
3484
|
+
let input = 0;
|
|
3485
|
+
let output = 0;
|
|
3486
|
+
while (true) {
|
|
3487
|
+
const { done, value } = await reader.read();
|
|
3488
|
+
if (done) break;
|
|
3489
|
+
buffer += decoder.decode(value, { stream: true });
|
|
3490
|
+
const lines = buffer.split("\n");
|
|
3491
|
+
buffer = lines.pop() ?? "";
|
|
3492
|
+
for (const line of lines) {
|
|
3493
|
+
if (!line.startsWith("data:")) continue;
|
|
3494
|
+
const data = line.slice(5).trim();
|
|
3495
|
+
if (!data) continue;
|
|
3496
|
+
try {
|
|
3497
|
+
const event = JSON.parse(data);
|
|
3498
|
+
if (event.type === "token" && event.content) {
|
|
3499
|
+
process.stdout.write(event.content);
|
|
3500
|
+
} else if (event.type === "done") {
|
|
3501
|
+
finalSession = event.sessionId ?? finalSession;
|
|
3502
|
+
input = event.inputTokens;
|
|
3503
|
+
output = event.outputTokens;
|
|
3504
|
+
} else if (event.type === "error") {
|
|
3505
|
+
console.error(chalk17.red(`
|
|
3506
|
+
Error: ${event.content}`));
|
|
3507
|
+
}
|
|
3508
|
+
} catch {
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
return { sessionId: finalSession, input, output };
|
|
3513
|
+
}
|
|
3514
|
+
async function runChatRepl(options) {
|
|
3515
|
+
const { input: promptInput } = await import("@inquirer/prompts");
|
|
3516
|
+
let sessionId = options.session;
|
|
3517
|
+
console.log(chalk17.bold("Diafunc chat") + chalk17.dim(" \xB7 /help for commands, /quit to exit"));
|
|
3518
|
+
if (sessionId) {
|
|
3519
|
+
console.log(chalk17.dim(`Continuing session ${sessionId}`));
|
|
3520
|
+
}
|
|
3521
|
+
console.log();
|
|
3522
|
+
for (; ; ) {
|
|
3523
|
+
let line;
|
|
3524
|
+
try {
|
|
3525
|
+
line = await promptInput({ message: chalk17.cyan.bold("you >") });
|
|
3526
|
+
} catch {
|
|
3527
|
+
console.log();
|
|
3528
|
+
return;
|
|
3529
|
+
}
|
|
3530
|
+
const trimmed = line.trim();
|
|
3531
|
+
if (!trimmed) continue;
|
|
3532
|
+
if (trimmed.startsWith("/")) {
|
|
3533
|
+
const [cmd, ...rest] = trimmed.slice(1).split(/\s+/);
|
|
3534
|
+
const arg = rest.join(" ");
|
|
3535
|
+
switch (cmd) {
|
|
3536
|
+
case "quit":
|
|
3537
|
+
case "exit":
|
|
3538
|
+
case "q":
|
|
3539
|
+
return;
|
|
3540
|
+
case "new":
|
|
3541
|
+
sessionId = void 0;
|
|
3542
|
+
console.log(chalk17.dim("Started a new session."));
|
|
3543
|
+
continue;
|
|
3544
|
+
case "session":
|
|
3545
|
+
if (!arg) {
|
|
3546
|
+
console.log(chalk17.dim(`Current session: ${sessionId ?? "(new)"}`));
|
|
3547
|
+
} else {
|
|
3548
|
+
sessionId = arg;
|
|
3549
|
+
console.log(chalk17.dim(`Switched to session ${sessionId}`));
|
|
3550
|
+
}
|
|
3551
|
+
continue;
|
|
3552
|
+
case "help":
|
|
3553
|
+
case "h":
|
|
3554
|
+
case "?":
|
|
3555
|
+
console.log(chalk17.dim(" /new start a new session"));
|
|
3556
|
+
console.log(chalk17.dim(" /session [id] switch to a session (no id = show current)"));
|
|
3557
|
+
console.log(chalk17.dim(" /quit exit the REPL"));
|
|
3558
|
+
continue;
|
|
3559
|
+
default:
|
|
3560
|
+
console.log(chalk17.dim(`Unknown command: /${cmd}. Try /help.`));
|
|
3561
|
+
continue;
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
process.stdout.write(chalk17.magenta.bold("diafunc > "));
|
|
3565
|
+
try {
|
|
3566
|
+
const result = await streamOneTurn(trimmed, sessionId, options.project, options.branch);
|
|
3567
|
+
sessionId = result.sessionId || sessionId;
|
|
3568
|
+
console.log();
|
|
3569
|
+
console.log(chalk17.dim(`[session ${sessionId} \xB7 ${result.input} in / ${result.output} out]`));
|
|
3570
|
+
console.log();
|
|
3571
|
+
} catch (error) {
|
|
3572
|
+
console.error(chalk17.red(`
|
|
3573
|
+
Request failed: ${error.message}`));
|
|
3574
|
+
}
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
2796
3577
|
function registerChatCommands(program) {
|
|
2797
3578
|
const chat = program.command("chat").description("AI chat");
|
|
3579
|
+
chat.option("--session <id>", "Continue an existing session").option("--project <id>", "Project context").option("--branch <branch>", "Project branch", "main").action(async (options) => {
|
|
3580
|
+
try {
|
|
3581
|
+
await runChatRepl(options);
|
|
3582
|
+
} catch (error) {
|
|
3583
|
+
handleError(error);
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
2798
3586
|
chat.command("send").description("Send a chat message (blocking)").argument("<message>", "Message to send").option("--project <id>", "Project context").option("--branch <branch>", "Project branch", "main").option("--session <id>", "Session ID to continue").action(async (message, options, cmd) => {
|
|
2799
3587
|
try {
|
|
2800
3588
|
const outputFormat = getOutputFormat10(cmd);
|
|
@@ -2890,15 +3678,15 @@ Error: ${event.content}`));
|
|
|
2890
3678
|
});
|
|
2891
3679
|
chat.command("upload").description("Upload a file for chat context").argument("<file>", "File to upload").action(async (file) => {
|
|
2892
3680
|
try {
|
|
2893
|
-
if (!
|
|
3681
|
+
if (!fs5.existsSync(file)) {
|
|
2894
3682
|
console.error(chalk17.red(`File not found: ${file}`));
|
|
2895
3683
|
process.exit(1);
|
|
2896
3684
|
}
|
|
2897
3685
|
const api = createApiClient();
|
|
2898
|
-
const fileBuffer =
|
|
3686
|
+
const fileBuffer = fs5.readFileSync(file);
|
|
2899
3687
|
const blob = new Blob([fileBuffer]);
|
|
2900
3688
|
const formData = new FormData();
|
|
2901
|
-
formData.append("file", blob,
|
|
3689
|
+
formData.append("file", blob, path4.basename(file));
|
|
2902
3690
|
const result = await api.language.upload(formData);
|
|
2903
3691
|
console.log(chalk17.green(`File uploaded: ${result}`));
|
|
2904
3692
|
} catch (error) {
|
|
@@ -2928,6 +3716,36 @@ Error: ${event.content}`));
|
|
|
2928
3716
|
handleError(error);
|
|
2929
3717
|
}
|
|
2930
3718
|
});
|
|
3719
|
+
session.command("show").description("Show the message history of a chat session").argument("<sessionId>", "Session ID").action(async (sessionId, _options, cmd) => {
|
|
3720
|
+
try {
|
|
3721
|
+
const outputFormat = getOutputFormat10(cmd);
|
|
3722
|
+
const api = createApiClient();
|
|
3723
|
+
const detail = await api.language.getSession(sessionId);
|
|
3724
|
+
if (outputFormat === "human") {
|
|
3725
|
+
console.log(chalk17.bold(detail.title) + chalk17.dim(` (${detail.sessionId})`));
|
|
3726
|
+
console.log();
|
|
3727
|
+
for (const msg of detail.messages) {
|
|
3728
|
+
const role = msg.role === "user" ? chalk17.cyan.bold("You") : chalk17.magenta.bold("Diafunc");
|
|
3729
|
+
console.log(`${role} ${chalk17.dim(msg.created)}`);
|
|
3730
|
+
console.log(msg.content);
|
|
3731
|
+
console.log();
|
|
3732
|
+
}
|
|
3733
|
+
} else {
|
|
3734
|
+
format(detail, { format: outputFormat });
|
|
3735
|
+
}
|
|
3736
|
+
} catch (error) {
|
|
3737
|
+
handleError(error);
|
|
3738
|
+
}
|
|
3739
|
+
});
|
|
3740
|
+
session.command("rename").description("Rename a chat session").argument("<sessionId>", "Session ID").argument("<title>", "New title").action(async (sessionId, title) => {
|
|
3741
|
+
try {
|
|
3742
|
+
const api = createApiClient();
|
|
3743
|
+
await api.language.renameSession(sessionId, title);
|
|
3744
|
+
console.log(chalk17.green(`Session "${sessionId}" renamed to "${title}".`));
|
|
3745
|
+
} catch (error) {
|
|
3746
|
+
handleError(error);
|
|
3747
|
+
}
|
|
3748
|
+
});
|
|
2931
3749
|
chat.command("usage").description("Show token usage").action(async (_options, cmd) => {
|
|
2932
3750
|
try {
|
|
2933
3751
|
const outputFormat = getOutputFormat10(cmd);
|
|
@@ -3017,6 +3835,15 @@ function registerGroupCommands(program) {
|
|
|
3017
3835
|
handleError(error);
|
|
3018
3836
|
}
|
|
3019
3837
|
});
|
|
3838
|
+
group.command("update").description("Update a group").argument("<groupId>", "Group ID").requiredOption("--name <name>", "New group name").action(async (groupId, options) => {
|
|
3839
|
+
try {
|
|
3840
|
+
const api = createApiClient();
|
|
3841
|
+
await api.admin.updateGroup({ groupId, name: options.name });
|
|
3842
|
+
console.log(chalk18.green(`Group "${groupId}" updated.`));
|
|
3843
|
+
} catch (error) {
|
|
3844
|
+
handleError(error);
|
|
3845
|
+
}
|
|
3846
|
+
});
|
|
3020
3847
|
group.command("delete").description("Delete a group").argument("<groupId>", "Group ID").action(async (groupId) => {
|
|
3021
3848
|
try {
|
|
3022
3849
|
const api = createApiClient();
|
|
@@ -3157,20 +3984,72 @@ function registerAdminCommands(program) {
|
|
|
3157
3984
|
}
|
|
3158
3985
|
});
|
|
3159
3986
|
const backup = admin.command("backup").description("Manage backups");
|
|
3160
|
-
backup.command("create-full").description("Create a full system backup").action(async () => {
|
|
3987
|
+
backup.command("create-full").description("Create a full system short-term backup").option("--long-term", "Create a long-term backup instead").action(async (options) => {
|
|
3988
|
+
try {
|
|
3989
|
+
const api = createApiClient();
|
|
3990
|
+
if (options.longTerm) {
|
|
3991
|
+
await api.storage.createLongTermFullBackup();
|
|
3992
|
+
console.log(chalk19.green("Full long-term backup initiated."));
|
|
3993
|
+
} else {
|
|
3994
|
+
await api.storage.createShortTermFullBackup();
|
|
3995
|
+
console.log(chalk19.green("Full short-term backup initiated."));
|
|
3996
|
+
}
|
|
3997
|
+
} catch (error) {
|
|
3998
|
+
handleError(error);
|
|
3999
|
+
}
|
|
4000
|
+
});
|
|
4001
|
+
backup.command("project").description("Create a project short-term backup (use --long-term for long-term)").option("--long-term", "Create a long-term backup instead").action(async (options) => {
|
|
4002
|
+
try {
|
|
4003
|
+
const api = createApiClient();
|
|
4004
|
+
if (options.longTerm) {
|
|
4005
|
+
await api.storage.createLongTermProjectBackup();
|
|
4006
|
+
console.log(chalk19.green("Project long-term backup initiated."));
|
|
4007
|
+
} else {
|
|
4008
|
+
await api.storage.createShortTermProjectBackup();
|
|
4009
|
+
console.log(chalk19.green("Project short-term backup initiated."));
|
|
4010
|
+
}
|
|
4011
|
+
} catch (error) {
|
|
4012
|
+
handleError(error);
|
|
4013
|
+
}
|
|
4014
|
+
});
|
|
4015
|
+
backup.command("restore-project").description("Restore a project from a backup bucket+object").argument("<projectId>", "Project ID").argument("<projectBranch>", "Project branch").argument("<bucketName>", "Backup bucket name").argument("<objectName>", "Backup object name").action(async (projectId, projectBranch, bucketName, objectName) => {
|
|
4016
|
+
try {
|
|
4017
|
+
const api = createApiClient();
|
|
4018
|
+
await api.storage.restoreProjectBackup({ projectId, projectBranch, bucketName, objectName });
|
|
4019
|
+
console.log(chalk19.green(`Restore initiated for ${projectId}/${projectBranch} from ${bucketName}/${objectName}.`));
|
|
4020
|
+
} catch (error) {
|
|
4021
|
+
handleError(error);
|
|
4022
|
+
}
|
|
4023
|
+
});
|
|
4024
|
+
backup.command("restore-full").description("Restore a full system backup from a bucket+object").argument("<bucketName>", "Backup bucket name").argument("<objectName>", "Backup object name").action(async (bucketName, objectName) => {
|
|
3161
4025
|
try {
|
|
3162
4026
|
const api = createApiClient();
|
|
3163
|
-
await api.
|
|
3164
|
-
console.log(chalk19.green(
|
|
4027
|
+
await api.storage.restoreFullBackup({ bucketName, objectName });
|
|
4028
|
+
console.log(chalk19.green(`Full restore initiated from ${bucketName}/${objectName}.`));
|
|
4029
|
+
} catch (error) {
|
|
4030
|
+
handleError(error);
|
|
4031
|
+
}
|
|
4032
|
+
});
|
|
4033
|
+
admin.command("index-rebuild").description("Rebuild all search indexes (or a specific project with --project)").option("--project <id>", "Project ID to rebuild").action(async (options) => {
|
|
4034
|
+
try {
|
|
4035
|
+
const api = createApiClient();
|
|
4036
|
+
if (options.project) {
|
|
4037
|
+
await api.index.rebuildProject(options.project);
|
|
4038
|
+
console.log(chalk19.green(`Index rebuild initiated for project "${options.project}".`));
|
|
4039
|
+
} else {
|
|
4040
|
+
await api.index.rebuildAll();
|
|
4041
|
+
console.log(chalk19.green("Index rebuild initiated for all projects."));
|
|
4042
|
+
}
|
|
3165
4043
|
} catch (error) {
|
|
3166
4044
|
handleError(error);
|
|
3167
4045
|
}
|
|
3168
4046
|
});
|
|
3169
|
-
|
|
4047
|
+
admin.command("permissions").description("Show your permissions on a project").argument("<projectId>", "Project ID").action(async (projectId, _options, cmd) => {
|
|
3170
4048
|
try {
|
|
4049
|
+
const outputFormat = getOutputFormat13(cmd);
|
|
3171
4050
|
const api = createApiClient();
|
|
3172
|
-
await api.admin.
|
|
3173
|
-
|
|
4051
|
+
const perm = await api.admin.getPermissions(projectId);
|
|
4052
|
+
format(perm, { format: outputFormat });
|
|
3174
4053
|
} catch (error) {
|
|
3175
4054
|
handleError(error);
|
|
3176
4055
|
}
|
|
@@ -3184,8 +4063,8 @@ import chalk20 from "chalk";
|
|
|
3184
4063
|
function createStatusService() {
|
|
3185
4064
|
const config = loadConfig();
|
|
3186
4065
|
const endpoint = resolveEndpoint(config);
|
|
3187
|
-
async function fetchJson(
|
|
3188
|
-
const url = `${endpoint}/status/v1${
|
|
4066
|
+
async function fetchJson(path7) {
|
|
4067
|
+
const url = `${endpoint}/status/v1${path7}`;
|
|
3189
4068
|
const response = await fetch(url, {
|
|
3190
4069
|
headers: { "Accept": "application/json" }
|
|
3191
4070
|
});
|
|
@@ -3368,8 +4247,9 @@ function registerStatusCommands(program) {
|
|
|
3368
4247
|
|
|
3369
4248
|
// src/commands/analyze/index.ts
|
|
3370
4249
|
import chalk23 from "chalk";
|
|
3371
|
-
import * as
|
|
3372
|
-
import * as
|
|
4250
|
+
import * as fs6 from "fs";
|
|
4251
|
+
import * as path5 from "path";
|
|
4252
|
+
import { spawn as spawn2 } from "child_process";
|
|
3373
4253
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
3374
4254
|
function createEntity(projectId, entityId, entityType, name, description, attributes, tags, contentType, content) {
|
|
3375
4255
|
const now = Date.now();
|
|
@@ -3432,61 +4312,68 @@ return diafunc
|
|
|
3432
4312
|
function stringToBinary(str) {
|
|
3433
4313
|
return Buffer.from(str).toString("base64");
|
|
3434
4314
|
}
|
|
3435
|
-
function
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
});
|
|
4315
|
+
function formatDuration(ms) {
|
|
4316
|
+
const seconds = Math.floor(ms / 1e3);
|
|
4317
|
+
const minutes = Math.floor(seconds / 60);
|
|
4318
|
+
const hours = Math.floor(minutes / 60);
|
|
4319
|
+
if (hours > 0) return `${hours}h ${minutes % 60}m`;
|
|
4320
|
+
if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
|
|
4321
|
+
return `${seconds}s`;
|
|
4322
|
+
}
|
|
4323
|
+
function analysisUrl(analysis, endpoint) {
|
|
4324
|
+
return `${endpoint}/lab/${analysis.projectId}/main/entities/${analysis.notebookId}/main`;
|
|
4325
|
+
}
|
|
4326
|
+
function openUrl(url) {
|
|
4327
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
4328
|
+
const args = process.platform === "win32" ? ["/c", "start", '""', url] : [url];
|
|
4329
|
+
spawn2(cmd, args, { detached: true, stdio: "ignore" }).unref();
|
|
4330
|
+
}
|
|
4331
|
+
function getOutputFormat14(cmd) {
|
|
4332
|
+
const config = loadConfig();
|
|
4333
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
4334
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
4335
|
+
}
|
|
4336
|
+
async function runAnalysis(file, options, cmd) {
|
|
4337
|
+
if (!fs6.existsSync(file)) {
|
|
4338
|
+
console.error(chalk23.red(`File not found: ${file}`));
|
|
4339
|
+
process.exit(1);
|
|
4340
|
+
}
|
|
4341
|
+
const api = createApiClient();
|
|
4342
|
+
const projectName = options.name ?? path5.basename(file, path5.extname(file));
|
|
4343
|
+
const visibility = options.visibility.toUpperCase();
|
|
4344
|
+
const analysis = {
|
|
4345
|
+
userId: null,
|
|
4346
|
+
analysisId: randomUUID3(),
|
|
4347
|
+
phase: "PREPARATION",
|
|
4348
|
+
step: "CREATE_PROJECT",
|
|
4349
|
+
projectName,
|
|
4350
|
+
projectDescription: options.description,
|
|
4351
|
+
visibility,
|
|
4352
|
+
time: options.time,
|
|
4353
|
+
budget: options.budget,
|
|
4354
|
+
projectId: null,
|
|
4355
|
+
notebookId: null,
|
|
4356
|
+
rawDataTableId: null,
|
|
4357
|
+
analysisFunctionId: null,
|
|
4358
|
+
analysisChapterId: null,
|
|
4359
|
+
year: null,
|
|
4360
|
+
month: null,
|
|
4361
|
+
day: null,
|
|
4362
|
+
hour: null,
|
|
4363
|
+
evaluationId: null,
|
|
4364
|
+
started: null
|
|
4365
|
+
};
|
|
4366
|
+
process.stdout.write(`Creating project "${projectName}" ...`);
|
|
4367
|
+
await createProjectStructure(api, analysis);
|
|
4368
|
+
console.log(chalk23.green(" done"));
|
|
4369
|
+
process.stdout.write(`Importing ${path5.basename(file)} ...`);
|
|
4370
|
+
await importData(api, analysis, file);
|
|
4371
|
+
console.log(chalk23.green(" done"));
|
|
4372
|
+
process.stdout.write("Launching analysis ...");
|
|
4373
|
+
await launchAnalysis(api, analysis);
|
|
4374
|
+
console.log(chalk23.green(" done"));
|
|
4375
|
+
console.log();
|
|
4376
|
+
await monitorAnalysis(api, analysis, cmd);
|
|
3490
4377
|
}
|
|
3491
4378
|
async function createProjectStructure(api, analysis) {
|
|
3492
4379
|
const project = await api.admin.createProject({
|
|
@@ -3593,18 +4480,16 @@ async function importData(api, analysis, file) {
|
|
|
3593
4480
|
entityId: analysis.rawDataTableId,
|
|
3594
4481
|
entityBranch: "main"
|
|
3595
4482
|
};
|
|
3596
|
-
const fileBuffer =
|
|
4483
|
+
const fileBuffer = fs6.readFileSync(file);
|
|
3597
4484
|
const blob = new Blob([fileBuffer]);
|
|
3598
4485
|
const formData = new FormData();
|
|
3599
|
-
formData.append("content", blob,
|
|
4486
|
+
formData.append("content", blob, path5.basename(file));
|
|
3600
4487
|
const importId = await api.storage.importTable(ref, formData, true);
|
|
3601
4488
|
for (let i = 0; i < 300; i++) {
|
|
3602
4489
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
3603
4490
|
const imp = await api.storage.getImport(ref, importId);
|
|
3604
4491
|
if (imp.finished !== null) {
|
|
3605
|
-
if (!imp.succeeded) {
|
|
3606
|
-
throw new Error(`Import failed: ${imp.error}`);
|
|
3607
|
-
}
|
|
4492
|
+
if (!imp.succeeded) throw new Error(`Import failed: ${imp.error}`);
|
|
3608
4493
|
break;
|
|
3609
4494
|
}
|
|
3610
4495
|
}
|
|
@@ -3647,8 +4532,7 @@ async function launchAnalysis(api, analysis) {
|
|
|
3647
4532
|
}
|
|
3648
4533
|
async function monitorAnalysis(api, analysis, cmd) {
|
|
3649
4534
|
const config = loadConfig();
|
|
3650
|
-
const
|
|
3651
|
-
const outputFormat = globalOpts.output ?? config.defaults.output ?? "human";
|
|
4535
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
3652
4536
|
const computationMs = parseFloat(analysis.time) * 60 * 60 * 1e3;
|
|
3653
4537
|
const seenOutputIds = /* @__PURE__ */ new Set();
|
|
3654
4538
|
for (let i = 0; ; i++) {
|
|
@@ -3675,11 +4559,9 @@ async function monitorAnalysis(api, analysis, cmd) {
|
|
|
3675
4559
|
const durationStr = formatDuration(duration);
|
|
3676
4560
|
if (outputFormat === "human") {
|
|
3677
4561
|
console.log(chalk23.green(`Analysis complete! (${durationStr})`));
|
|
3678
|
-
if (evaluation.result) {
|
|
3679
|
-
console.log(` Result: ${evaluation.result}`);
|
|
3680
|
-
}
|
|
4562
|
+
if (evaluation.result) console.log(` Result: ${evaluation.result}`);
|
|
3681
4563
|
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
3682
|
-
console.log(` Project: ${endpoint}
|
|
4564
|
+
console.log(` Project: ${analysisUrl(analysis, endpoint)}`);
|
|
3683
4565
|
} else {
|
|
3684
4566
|
format({
|
|
3685
4567
|
status: "completed",
|
|
@@ -3710,9 +4592,7 @@ async function monitorAnalysis(api, analysis, cmd) {
|
|
|
3710
4592
|
for (const out of outputs) {
|
|
3711
4593
|
if (!seenOutputIds.has(out.outputId)) {
|
|
3712
4594
|
seenOutputIds.add(out.outputId);
|
|
3713
|
-
if (outputFormat === "human") {
|
|
3714
|
-
console.log(` ${chalk23.dim("Output:")} ${out.output}`);
|
|
3715
|
-
}
|
|
4595
|
+
if (outputFormat === "human") console.log(` ${chalk23.dim("Output:")} ${out.output}`);
|
|
3716
4596
|
}
|
|
3717
4597
|
}
|
|
3718
4598
|
} catch {
|
|
@@ -3726,36 +4606,112 @@ async function monitorAnalysis(api, analysis, cmd) {
|
|
|
3726
4606
|
}
|
|
3727
4607
|
}
|
|
3728
4608
|
}
|
|
3729
|
-
async function
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
4609
|
+
async function listAnalyses(limit, cmd) {
|
|
4610
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4611
|
+
const api = createApiClient();
|
|
4612
|
+
const analyses = await api.admin.getRecentAnalyses(limit);
|
|
4613
|
+
const rows = analyses.map((a) => ({
|
|
4614
|
+
analysisId: a.analysisId ?? "\u2014",
|
|
4615
|
+
projectName: a.projectName ?? "\u2014",
|
|
4616
|
+
projectId: a.projectId ?? "\u2014",
|
|
4617
|
+
phase: a.phase,
|
|
4618
|
+
step: a.step,
|
|
4619
|
+
started: a.started ? new Date(a.started).toISOString() : "\u2014"
|
|
4620
|
+
}));
|
|
4621
|
+
format(rows, {
|
|
4622
|
+
format: outputFormat,
|
|
4623
|
+
columns: ["analysisId", "projectName", "phase", "step", "started"]
|
|
4624
|
+
});
|
|
4625
|
+
}
|
|
4626
|
+
async function getAnalysisDetails(analysisId, cmd) {
|
|
4627
|
+
const outputFormat = getOutputFormat14(cmd);
|
|
4628
|
+
const api = createApiClient();
|
|
4629
|
+
const result = analysisId ? await api.admin.getAnalysis(analysisId) : await api.admin.getLastAnalysis();
|
|
4630
|
+
if (!result.analysis) {
|
|
4631
|
+
console.log(chalk23.dim("No analysis found."));
|
|
4632
|
+
return;
|
|
3740
4633
|
}
|
|
4634
|
+
format(result.analysis, { format: outputFormat });
|
|
4635
|
+
}
|
|
4636
|
+
async function watchAnalysis(analysisId, cmd) {
|
|
4637
|
+
const api = createApiClient();
|
|
4638
|
+
const result = analysisId ? await api.admin.getAnalysis(analysisId) : await api.admin.getLastAnalysis();
|
|
4639
|
+
if (!result.analysis) {
|
|
4640
|
+
console.log(chalk23.dim("No analysis found."));
|
|
4641
|
+
return;
|
|
4642
|
+
}
|
|
4643
|
+
const analysis = result.analysis;
|
|
3741
4644
|
if (analysis.phase === "COMPLETION") {
|
|
3742
|
-
console.log(chalk23.
|
|
4645
|
+
console.log(chalk23.green("Analysis already completed."));
|
|
4646
|
+
console.log(` Analysis ID: ${analysis.analysisId}`);
|
|
4647
|
+
if (analysis.projectId) {
|
|
4648
|
+
const config = loadConfig();
|
|
4649
|
+
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
4650
|
+
console.log(` Project: ${analysisUrl(analysis, endpoint)}`);
|
|
4651
|
+
}
|
|
3743
4652
|
return;
|
|
3744
4653
|
}
|
|
3745
4654
|
if (analysis.phase === "ANALYSIS") {
|
|
3746
|
-
console.log(`
|
|
4655
|
+
console.log(`Watching analysis for project "${analysis.projectId}" ...`);
|
|
3747
4656
|
await monitorAnalysis(api, analysis, cmd);
|
|
3748
|
-
|
|
3749
|
-
console.log(`Analysis in preparation phase (step: ${analysis.step}). Cannot resume \u2014 start a new analysis.`);
|
|
4657
|
+
return;
|
|
3750
4658
|
}
|
|
4659
|
+
console.log(chalk23.yellow(`Analysis in preparation (step: ${analysis.step}); not yet running.`));
|
|
3751
4660
|
}
|
|
3752
|
-
function
|
|
3753
|
-
const
|
|
3754
|
-
const
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
4661
|
+
async function openAnalysis(analysisId) {
|
|
4662
|
+
const api = createApiClient();
|
|
4663
|
+
const result = analysisId ? await api.admin.getAnalysis(analysisId) : await api.admin.getLastAnalysis();
|
|
4664
|
+
if (!result.analysis?.projectId) {
|
|
4665
|
+
console.log(chalk23.dim("No analysis found (or analysis has no project yet)."));
|
|
4666
|
+
return;
|
|
4667
|
+
}
|
|
4668
|
+
const config = loadConfig();
|
|
4669
|
+
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
4670
|
+
const url = analysisUrl(result.analysis, endpoint);
|
|
4671
|
+
console.log(`Opening ${url} ...`);
|
|
4672
|
+
openUrl(url);
|
|
4673
|
+
}
|
|
4674
|
+
function registerAnalyzeCommand(program) {
|
|
4675
|
+
const analyze = program.command("analyze").description("Run and manage automatic analyses");
|
|
4676
|
+
analyze.argument("[file]", "CSV or Excel file to analyze").option("--name <name>", "Project name (derived from filename if omitted)").option("--description <text>", "Project description", "").option("--visibility <vis>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--time <hours>", "Computation time in hours", "4").option("--budget <credits>", "Credit budget", "400").action(async (file, options, cmd) => {
|
|
4677
|
+
try {
|
|
4678
|
+
if (!file) {
|
|
4679
|
+
analyze.help();
|
|
4680
|
+
return;
|
|
4681
|
+
}
|
|
4682
|
+
await runAnalysis(file, options, cmd);
|
|
4683
|
+
} catch (error) {
|
|
4684
|
+
handleError(error);
|
|
4685
|
+
}
|
|
4686
|
+
});
|
|
4687
|
+
analyze.command("list").description("List recent analyses").option("--limit <n>", "Number of analyses to list", "20").action(async (options, cmd) => {
|
|
4688
|
+
try {
|
|
4689
|
+
await listAnalyses(parseInt(options.limit, 10), cmd);
|
|
4690
|
+
} catch (error) {
|
|
4691
|
+
handleError(error);
|
|
4692
|
+
}
|
|
4693
|
+
});
|
|
4694
|
+
analyze.command("get").description("Show details of an analysis").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id, _options, cmd) => {
|
|
4695
|
+
try {
|
|
4696
|
+
await getAnalysisDetails(id, cmd);
|
|
4697
|
+
} catch (error) {
|
|
4698
|
+
handleError(error);
|
|
4699
|
+
}
|
|
4700
|
+
});
|
|
4701
|
+
analyze.command("watch").description("Live-monitor a running analysis with progress bar and streaming outputs").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id, _options, cmd) => {
|
|
4702
|
+
try {
|
|
4703
|
+
await watchAnalysis(id, cmd);
|
|
4704
|
+
} catch (error) {
|
|
4705
|
+
handleError(error);
|
|
4706
|
+
}
|
|
4707
|
+
});
|
|
4708
|
+
analyze.command("open").description("Open an analysis project in your browser").argument("[id]", "Analysis ID (defaults to the most recent)").action(async (id) => {
|
|
4709
|
+
try {
|
|
4710
|
+
await openAnalysis(id);
|
|
4711
|
+
} catch (error) {
|
|
4712
|
+
handleError(error);
|
|
4713
|
+
}
|
|
4714
|
+
});
|
|
3759
4715
|
}
|
|
3760
4716
|
|
|
3761
4717
|
// src/commands/completion/index.ts
|
|
@@ -4011,10 +4967,406 @@ function registerCompletionCommand(program) {
|
|
|
4011
4967
|
});
|
|
4012
4968
|
}
|
|
4013
4969
|
|
|
4970
|
+
// src/commands/whoami/index.ts
|
|
4971
|
+
import chalk24 from "chalk";
|
|
4972
|
+
function registerWhoamiCommand(program) {
|
|
4973
|
+
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
4974
|
+
try {
|
|
4975
|
+
const config = loadConfig();
|
|
4976
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
4977
|
+
const outputFormat = globalOpts.output ?? config.defaults.output ?? "human";
|
|
4978
|
+
const api = createApiClient();
|
|
4979
|
+
const user = await api.admin.getMyUser();
|
|
4980
|
+
if (outputFormat === "human") {
|
|
4981
|
+
console.log(chalk24.bold(user.name) + chalk24.dim(` <${user.email}>`));
|
|
4982
|
+
console.log(chalk24.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
4983
|
+
} else {
|
|
4984
|
+
format(user, { format: outputFormat });
|
|
4985
|
+
}
|
|
4986
|
+
} catch (error) {
|
|
4987
|
+
handleError(error);
|
|
4988
|
+
}
|
|
4989
|
+
});
|
|
4990
|
+
}
|
|
4991
|
+
|
|
4992
|
+
// src/commands/utilization/index.ts
|
|
4993
|
+
import chalk25 from "chalk";
|
|
4994
|
+
function getOutputFormat15(cmd) {
|
|
4995
|
+
const config = loadConfig();
|
|
4996
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
4997
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
4998
|
+
}
|
|
4999
|
+
function printUtilizationHuman(u, label) {
|
|
5000
|
+
const when = u.day !== null && u.day !== void 0 ? `${u.year}-${String(u.month).padStart(2, "0")}-${String(u.day).padStart(2, "0")}` : `${u.year}-${String(u.month).padStart(2, "0")}`;
|
|
5001
|
+
if (label) {
|
|
5002
|
+
console.log(chalk25.bold(label) + " " + chalk25.dim(when));
|
|
5003
|
+
} else {
|
|
5004
|
+
console.log(chalk25.bold(when));
|
|
5005
|
+
}
|
|
5006
|
+
if (u.types.length === 0) {
|
|
5007
|
+
console.log(chalk25.dim(" (no usage)"));
|
|
5008
|
+
return;
|
|
5009
|
+
}
|
|
5010
|
+
for (const t of u.types) {
|
|
5011
|
+
console.log(
|
|
5012
|
+
` ${t.type.padEnd(24)} ${chalk25.cyan(String(t.quantity).padStart(10))} ${chalk25.dim("credits:")} ${t.credits.toFixed(2)}`
|
|
5013
|
+
);
|
|
5014
|
+
}
|
|
5015
|
+
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
5016
|
+
console.log(chalk25.bold(` Total credits: ${total.toFixed(2)}`));
|
|
5017
|
+
}
|
|
5018
|
+
function registerUtilizationCommand(program) {
|
|
5019
|
+
const util = program.command("utilization").description("Show credit utilization");
|
|
5020
|
+
util.command("actual", { isDefault: true }).description("Show current utilization (default subcommand)").action(async (_options, cmd) => {
|
|
5021
|
+
try {
|
|
5022
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
5023
|
+
const api = createApiClient();
|
|
5024
|
+
const utilization = await api.admin.getActualUtilization();
|
|
5025
|
+
if (outputFormat === "human") {
|
|
5026
|
+
printUtilizationHuman(utilization, "Current utilization");
|
|
5027
|
+
} else {
|
|
5028
|
+
format(utilization, { format: outputFormat });
|
|
5029
|
+
}
|
|
5030
|
+
} catch (error) {
|
|
5031
|
+
handleError(error);
|
|
5032
|
+
}
|
|
5033
|
+
});
|
|
5034
|
+
util.command("history").description("Show utilization history").action(async (_options, cmd) => {
|
|
5035
|
+
try {
|
|
5036
|
+
const outputFormat = getOutputFormat15(cmd);
|
|
5037
|
+
const api = createApiClient();
|
|
5038
|
+
const history = await api.admin.getUtilizationHistory();
|
|
5039
|
+
if (outputFormat === "human") {
|
|
5040
|
+
if (history.length === 0) {
|
|
5041
|
+
console.log(chalk25.dim("No usage recorded."));
|
|
5042
|
+
return;
|
|
5043
|
+
}
|
|
5044
|
+
for (const u of history) {
|
|
5045
|
+
printUtilizationHuman(u);
|
|
5046
|
+
console.log();
|
|
5047
|
+
}
|
|
5048
|
+
} else {
|
|
5049
|
+
format(history, { format: outputFormat });
|
|
5050
|
+
}
|
|
5051
|
+
} catch (error) {
|
|
5052
|
+
handleError(error);
|
|
5053
|
+
}
|
|
5054
|
+
});
|
|
5055
|
+
}
|
|
5056
|
+
|
|
5057
|
+
// src/commands/entity-branch/index.ts
|
|
5058
|
+
import chalk26 from "chalk";
|
|
5059
|
+
function getOutputFormat16(cmd) {
|
|
5060
|
+
const config = loadConfig();
|
|
5061
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
5062
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
5063
|
+
}
|
|
5064
|
+
function getOverrides9(cmd) {
|
|
5065
|
+
const opts = cmd.optsWithGlobals();
|
|
5066
|
+
return { project: opts.project, branch: opts.branch };
|
|
5067
|
+
}
|
|
5068
|
+
function registerEntityBranchCommands(program) {
|
|
5069
|
+
const eb = program.command("entity-branch").description("Manage entity branches (parallel versions of a single entity)");
|
|
5070
|
+
eb.command("list").description("List branches of an entity").argument("<ref>", "Entity reference (projectId/branch/entityId)").action(async (ref, _options, cmd) => {
|
|
5071
|
+
try {
|
|
5072
|
+
const outputFormat = getOutputFormat16(cmd);
|
|
5073
|
+
const overrides = getOverrides9(cmd);
|
|
5074
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
5075
|
+
const api = createApiClient();
|
|
5076
|
+
const branches = await api.storage.getEntityBranches(
|
|
5077
|
+
resolved.projectId,
|
|
5078
|
+
resolved.projectBranch,
|
|
5079
|
+
resolved.entityId
|
|
5080
|
+
);
|
|
5081
|
+
if (outputFormat === "json") {
|
|
5082
|
+
format(branches, { format: outputFormat });
|
|
5083
|
+
} else {
|
|
5084
|
+
for (const b of branches) console.log(b);
|
|
5085
|
+
}
|
|
5086
|
+
} catch (error) {
|
|
5087
|
+
handleError(error);
|
|
5088
|
+
}
|
|
5089
|
+
});
|
|
5090
|
+
eb.command("create").description("Create a new branch of an entity from an existing branch").argument("<ref>", "Source entity reference (projectId/branch/entityId/sourceBranch)").argument("<targetBranch>", "New branch name").action(async (ref, targetBranch, _options, cmd) => {
|
|
5091
|
+
try {
|
|
5092
|
+
const overrides = getOverrides9(cmd);
|
|
5093
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
5094
|
+
const api = createApiClient();
|
|
5095
|
+
await api.storage.createEntityBranch({
|
|
5096
|
+
projectId: resolved.projectId,
|
|
5097
|
+
projectBranch: resolved.projectBranch,
|
|
5098
|
+
entityId: resolved.entityId,
|
|
5099
|
+
sourceEntityBranch: resolved.entityBranch,
|
|
5100
|
+
targetEntityBranch: targetBranch
|
|
5101
|
+
});
|
|
5102
|
+
console.log(chalk26.green(`Entity branch "${targetBranch}" created from "${resolved.entityBranch}".`));
|
|
5103
|
+
} catch (error) {
|
|
5104
|
+
handleError(error);
|
|
5105
|
+
}
|
|
5106
|
+
});
|
|
5107
|
+
}
|
|
5108
|
+
|
|
5109
|
+
// src/commands/subscription/index.ts
|
|
5110
|
+
function getOutputFormat17(cmd) {
|
|
5111
|
+
const config = loadConfig();
|
|
5112
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
5113
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
5114
|
+
}
|
|
5115
|
+
function registerSubscriptionCommand(program) {
|
|
5116
|
+
const sub = program.command("subscription").description("View subscription info");
|
|
5117
|
+
sub.command("current", { isDefault: true }).description("Show the current subscription").action(async (_options, cmd) => {
|
|
5118
|
+
try {
|
|
5119
|
+
const api = createApiClient();
|
|
5120
|
+
const s = await api.admin.getCurrentSubscription();
|
|
5121
|
+
format(s, { format: getOutputFormat17(cmd) });
|
|
5122
|
+
} catch (error) {
|
|
5123
|
+
handleError(error);
|
|
5124
|
+
}
|
|
5125
|
+
});
|
|
5126
|
+
sub.command("next").description("Show the next (upcoming) subscription").action(async (_options, cmd) => {
|
|
5127
|
+
try {
|
|
5128
|
+
const api = createApiClient();
|
|
5129
|
+
const s = await api.admin.getNextSubscription();
|
|
5130
|
+
format(s, { format: getOutputFormat17(cmd) });
|
|
5131
|
+
} catch (error) {
|
|
5132
|
+
handleError(error);
|
|
5133
|
+
}
|
|
5134
|
+
});
|
|
5135
|
+
sub.command("plans").description("Show subscription plans").argument("<subscriptionToken>", "Subscription token").action(async (subscriptionToken, _options, cmd) => {
|
|
5136
|
+
try {
|
|
5137
|
+
const api = createApiClient();
|
|
5138
|
+
const plans = await api.admin.getSubscriptionPlans(subscriptionToken);
|
|
5139
|
+
format(plans, { format: getOutputFormat17(cmd) });
|
|
5140
|
+
} catch (error) {
|
|
5141
|
+
handleError(error);
|
|
5142
|
+
}
|
|
5143
|
+
});
|
|
5144
|
+
}
|
|
5145
|
+
|
|
5146
|
+
// src/commands/invoice/index.ts
|
|
5147
|
+
import chalk27 from "chalk";
|
|
5148
|
+
import * as fs7 from "fs";
|
|
5149
|
+
function getOutputFormat18(cmd) {
|
|
5150
|
+
const config = loadConfig();
|
|
5151
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
5152
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
5153
|
+
}
|
|
5154
|
+
function registerInvoiceCommand(program) {
|
|
5155
|
+
const invoice = program.command("invoice").description("View and download invoices");
|
|
5156
|
+
invoice.command("list").description("List your invoices").action(async (_options, cmd) => {
|
|
5157
|
+
try {
|
|
5158
|
+
const api = createApiClient();
|
|
5159
|
+
const invoices = await api.admin.getInvoices();
|
|
5160
|
+
format(invoices, {
|
|
5161
|
+
format: getOutputFormat18(cmd),
|
|
5162
|
+
columns: ["invoiceNumber", "issued", "periodFrom", "periodTo", "total", "status"]
|
|
5163
|
+
});
|
|
5164
|
+
} catch (error) {
|
|
5165
|
+
handleError(error);
|
|
5166
|
+
}
|
|
5167
|
+
});
|
|
5168
|
+
invoice.command("download").description("Download an invoice document").argument("<invoiceNumber>", "Invoice number").argument("<fileName>", "File name of the document").option("--out <path>", "Output file path (defaults to <fileName>)").action(async (invoiceNumber, fileName, options) => {
|
|
5169
|
+
try {
|
|
5170
|
+
const api = createApiClient();
|
|
5171
|
+
const response = await api.admin.downloadInvoice(invoiceNumber, fileName);
|
|
5172
|
+
const buffer = Buffer.from(await response.arrayBuffer());
|
|
5173
|
+
const outPath = options.out ?? fileName;
|
|
5174
|
+
fs7.writeFileSync(outPath, buffer);
|
|
5175
|
+
console.log(chalk27.green(`Invoice saved to ${outPath}`));
|
|
5176
|
+
} catch (error) {
|
|
5177
|
+
handleError(error);
|
|
5178
|
+
}
|
|
5179
|
+
});
|
|
5180
|
+
}
|
|
5181
|
+
|
|
5182
|
+
// src/commands/shell/index.ts
|
|
5183
|
+
import chalk28 from "chalk";
|
|
5184
|
+
import * as fs8 from "fs";
|
|
5185
|
+
import * as os3 from "os";
|
|
5186
|
+
import * as path6 from "path";
|
|
5187
|
+
import { spawn as spawn3 } from "child_process";
|
|
5188
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
5189
|
+
function extensionFor2(language) {
|
|
5190
|
+
const l = language.toLowerCase();
|
|
5191
|
+
if (l === "java") return "java";
|
|
5192
|
+
if (l === "javascript" || l === "js") return "js";
|
|
5193
|
+
if (l === "kotlin") return "kt";
|
|
5194
|
+
if (l === "python") return "py";
|
|
5195
|
+
if (l === "scala") return "scala";
|
|
5196
|
+
return "txt";
|
|
5197
|
+
}
|
|
5198
|
+
async function openInEditor(initial, ext) {
|
|
5199
|
+
const tmpFile = path6.join(os3.tmpdir(), `diafunc-shell-${randomUUID4()}.${ext}`);
|
|
5200
|
+
fs8.writeFileSync(tmpFile, initial);
|
|
5201
|
+
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
5202
|
+
await new Promise((resolve, reject) => {
|
|
5203
|
+
const child = spawn3(editor, [tmpFile], { stdio: "inherit" });
|
|
5204
|
+
child.on("exit", (code) => code === 0 ? resolve() : reject(new Error(`Editor exited with ${code}`)));
|
|
5205
|
+
child.on("error", reject);
|
|
5206
|
+
});
|
|
5207
|
+
const content = fs8.readFileSync(tmpFile, "utf-8");
|
|
5208
|
+
fs8.unlinkSync(tmpFile);
|
|
5209
|
+
return content;
|
|
5210
|
+
}
|
|
5211
|
+
function utcNowParts() {
|
|
5212
|
+
const d = /* @__PURE__ */ new Date();
|
|
5213
|
+
return {
|
|
5214
|
+
year: d.getUTCFullYear(),
|
|
5215
|
+
month: d.getUTCMonth() + 1,
|
|
5216
|
+
day: d.getUTCDate(),
|
|
5217
|
+
hour: d.getUTCHours()
|
|
5218
|
+
};
|
|
5219
|
+
}
|
|
5220
|
+
async function evaluate(api, fnRef, language, sourceCode) {
|
|
5221
|
+
const entity = buildFunctionEntity({
|
|
5222
|
+
projectId: fnRef.projectId,
|
|
5223
|
+
projectBranch: fnRef.projectBranch,
|
|
5224
|
+
entityId: fnRef.entityId,
|
|
5225
|
+
entityBranch: fnRef.entityBranch,
|
|
5226
|
+
name: fnRef.entityId,
|
|
5227
|
+
language,
|
|
5228
|
+
sourceCode
|
|
5229
|
+
});
|
|
5230
|
+
await api.storage.saveEntities([entity]);
|
|
5231
|
+
const evaluationId = randomUUID4();
|
|
5232
|
+
const nowParts = utcNowParts();
|
|
5233
|
+
const result = await api.evaluation.call({
|
|
5234
|
+
evaluationId,
|
|
5235
|
+
projectId: fnRef.projectId,
|
|
5236
|
+
projectBranch: fnRef.projectBranch,
|
|
5237
|
+
functionId: fnRef.entityId,
|
|
5238
|
+
functionBranch: fnRef.entityBranch,
|
|
5239
|
+
targetEntityId: null,
|
|
5240
|
+
targetEntityBranch: null,
|
|
5241
|
+
arguments: null,
|
|
5242
|
+
types: null,
|
|
5243
|
+
requested: Date.now(),
|
|
5244
|
+
provideOutputs: true,
|
|
5245
|
+
removeFunction: true
|
|
5246
|
+
}, false);
|
|
5247
|
+
if (result.outputs?.length) {
|
|
5248
|
+
for (const out of result.outputs) {
|
|
5249
|
+
console.log(chalk28.dim(` [${out.type}]`) + " " + out.output);
|
|
5250
|
+
}
|
|
5251
|
+
}
|
|
5252
|
+
if (result.successful) {
|
|
5253
|
+
if (result.result) {
|
|
5254
|
+
console.log(chalk28.green("=> ") + result.result);
|
|
5255
|
+
} else {
|
|
5256
|
+
console.log(chalk28.dim("=> (no value)"));
|
|
5257
|
+
}
|
|
5258
|
+
const duration = result.completed - result.started;
|
|
5259
|
+
console.log(chalk28.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
5260
|
+
} else {
|
|
5261
|
+
console.log(chalk28.red("error: ") + result.error);
|
|
5262
|
+
if (result.lineNumber > 0) {
|
|
5263
|
+
console.log(chalk28.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
5264
|
+
}
|
|
5265
|
+
}
|
|
5266
|
+
}
|
|
5267
|
+
function registerShellCommand(program) {
|
|
5268
|
+
program.command("shell").description("Interactive REPL for function code evaluation").option("--function <ref>", "Function entity reference to use as scratch (required)").option("--language <lang>", "Source language", "JavaScript").action(async (options, cmd) => {
|
|
5269
|
+
try {
|
|
5270
|
+
if (!options.function) {
|
|
5271
|
+
console.error(chalk28.red("Missing --function <ref>."));
|
|
5272
|
+
console.error(chalk28.dim("Pass an existing or new function entity reference to use as the shell target."));
|
|
5273
|
+
console.error(chalk28.dim("Example: diafunc shell --function my-project/main/scratch/main --language JavaScript"));
|
|
5274
|
+
process.exit(1);
|
|
5275
|
+
}
|
|
5276
|
+
const config = loadConfig();
|
|
5277
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
5278
|
+
const fnRef = parseEntityReference(options.function, {
|
|
5279
|
+
project: globalOpts.project,
|
|
5280
|
+
branch: globalOpts.branch
|
|
5281
|
+
});
|
|
5282
|
+
const api = createApiClient();
|
|
5283
|
+
const { input: promptInput } = await import("@inquirer/prompts");
|
|
5284
|
+
console.log(chalk28.bold("Diafunc shell") + chalk28.dim(` \xB7 function ${fnRef.entityId} \xB7 ${options.language}`));
|
|
5285
|
+
console.log(chalk28.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
5286
|
+
console.log(chalk28.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
5287
|
+
console.log();
|
|
5288
|
+
let language = options.language;
|
|
5289
|
+
for (; ; ) {
|
|
5290
|
+
let line;
|
|
5291
|
+
try {
|
|
5292
|
+
line = await promptInput({ message: chalk28.cyan.bold(`${language} >`) });
|
|
5293
|
+
} catch {
|
|
5294
|
+
console.log();
|
|
5295
|
+
return;
|
|
5296
|
+
}
|
|
5297
|
+
const trimmed = line.trim();
|
|
5298
|
+
if (!trimmed) continue;
|
|
5299
|
+
if (trimmed.startsWith("/")) {
|
|
5300
|
+
const [cmd2, ...rest] = trimmed.slice(1).split(/\s+/);
|
|
5301
|
+
const arg = rest.join(" ");
|
|
5302
|
+
switch (cmd2) {
|
|
5303
|
+
case "quit":
|
|
5304
|
+
case "exit":
|
|
5305
|
+
case "q":
|
|
5306
|
+
return;
|
|
5307
|
+
case "help":
|
|
5308
|
+
case "h":
|
|
5309
|
+
case "?":
|
|
5310
|
+
console.log(chalk28.dim(" /edit open $EDITOR for multi-line code"));
|
|
5311
|
+
console.log(chalk28.dim(" /file <path> evaluate the contents of a file"));
|
|
5312
|
+
console.log(chalk28.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
5313
|
+
console.log(chalk28.dim(" /quit exit the shell"));
|
|
5314
|
+
continue;
|
|
5315
|
+
case "lang":
|
|
5316
|
+
if (arg) language = arg;
|
|
5317
|
+
console.log(chalk28.dim(`Language: ${language}`));
|
|
5318
|
+
continue;
|
|
5319
|
+
case "edit": {
|
|
5320
|
+
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
5321
|
+
if (!sourceCode.trim()) {
|
|
5322
|
+
console.log(chalk28.dim("(empty \u2014 not evaluated)"));
|
|
5323
|
+
continue;
|
|
5324
|
+
}
|
|
5325
|
+
try {
|
|
5326
|
+
await evaluate(api, fnRef, language, sourceCode);
|
|
5327
|
+
} catch (e) {
|
|
5328
|
+
console.error(chalk28.red(e.message));
|
|
5329
|
+
}
|
|
5330
|
+
continue;
|
|
5331
|
+
}
|
|
5332
|
+
case "file": {
|
|
5333
|
+
if (!arg) {
|
|
5334
|
+
console.log(chalk28.dim("usage: /file <path>"));
|
|
5335
|
+
continue;
|
|
5336
|
+
}
|
|
5337
|
+
if (!fs8.existsSync(arg)) {
|
|
5338
|
+
console.log(chalk28.red(`file not found: ${arg}`));
|
|
5339
|
+
continue;
|
|
5340
|
+
}
|
|
5341
|
+
const sourceCode = fs8.readFileSync(arg, "utf-8");
|
|
5342
|
+
try {
|
|
5343
|
+
await evaluate(api, fnRef, language, sourceCode);
|
|
5344
|
+
} catch (e) {
|
|
5345
|
+
console.error(chalk28.red(e.message));
|
|
5346
|
+
}
|
|
5347
|
+
continue;
|
|
5348
|
+
}
|
|
5349
|
+
default:
|
|
5350
|
+
console.log(chalk28.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
5351
|
+
continue;
|
|
5352
|
+
}
|
|
5353
|
+
}
|
|
5354
|
+
try {
|
|
5355
|
+
await evaluate(api, fnRef, language, trimmed);
|
|
5356
|
+
} catch (e) {
|
|
5357
|
+
console.error(chalk28.red(e.message));
|
|
5358
|
+
}
|
|
5359
|
+
}
|
|
5360
|
+
} catch (error) {
|
|
5361
|
+
handleError(error);
|
|
5362
|
+
}
|
|
5363
|
+
});
|
|
5364
|
+
}
|
|
5365
|
+
|
|
4014
5366
|
// src/index.ts
|
|
4015
5367
|
function createProgram() {
|
|
4016
5368
|
const program = new Command();
|
|
4017
|
-
program.name("diafunc").description("Diafunc CLI \u2014 command-line interface for the Diafunc platform").version(
|
|
5369
|
+
program.name("diafunc").description("Diafunc CLI \u2014 command-line interface for the Diafunc platform").version(package_default.version).option("-p, --profile <name>", "Profile to use").option("-o, --output <format>", "Output format: human, json, table").option("--project <id>", "Default project ID override").option("--branch <name>", "Default branch override").option("--dry-run", "Preview mutating operations without executing them").hook("preAction", (thisCommand) => {
|
|
4018
5370
|
const opts = thisCommand.optsWithGlobals();
|
|
4019
5371
|
if (opts.dryRun) {
|
|
4020
5372
|
setDryRun(true);
|
|
@@ -4038,10 +5390,17 @@ function createProgram() {
|
|
|
4038
5390
|
registerStatusCommands(program);
|
|
4039
5391
|
registerAnalyzeCommand(program);
|
|
4040
5392
|
registerCompletionCommand(program);
|
|
5393
|
+
registerWhoamiCommand(program);
|
|
5394
|
+
registerUtilizationCommand(program);
|
|
5395
|
+
registerEntityBranchCommands(program);
|
|
5396
|
+
registerSubscriptionCommand(program);
|
|
5397
|
+
registerInvoiceCommand(program);
|
|
5398
|
+
registerShellCommand(program);
|
|
4041
5399
|
return program;
|
|
4042
5400
|
}
|
|
4043
5401
|
|
|
4044
5402
|
export {
|
|
5403
|
+
package_default,
|
|
4045
5404
|
createProgram
|
|
4046
5405
|
};
|
|
4047
|
-
//# sourceMappingURL=chunk-
|
|
5406
|
+
//# sourceMappingURL=chunk-YNIZ5WGU.js.map
|