@alook/cli 0.0.107 → 0.0.109
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +95 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __export = (target, all) => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// src/index.ts
|
|
18
|
-
import { Command as
|
|
18
|
+
import { Command as Command14 } from "commander";
|
|
19
19
|
|
|
20
20
|
// commands/register.ts
|
|
21
21
|
import { Command } from "commander";
|
|
@@ -22653,8 +22653,100 @@ function syncCommand() {
|
|
|
22653
22653
|
return cmd;
|
|
22654
22654
|
}
|
|
22655
22655
|
|
|
22656
|
+
// commands/workspace.ts
|
|
22657
|
+
import { Command as Command13 } from "commander";
|
|
22658
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
22659
|
+
function slugify2(name) {
|
|
22660
|
+
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60);
|
|
22661
|
+
}
|
|
22662
|
+
function workspaceCommand() {
|
|
22663
|
+
const cmd = new Command13("workspace").description("Manage workspaces");
|
|
22664
|
+
cmd.command("init").description("Initialize a workspace from a JSON configuration file").requiredOption("--json-file <path>", "Path to the JSON configuration file").option("--name <name>", "Workspace name (overrides JSON)").option("--json", "Output as JSON").action(async (opts, command) => {
|
|
22665
|
+
const { serverUrl, token, workspaceId } = resolveClientOpts(command);
|
|
22666
|
+
const client = new APIClient(serverUrl, token, workspaceId);
|
|
22667
|
+
let configJson;
|
|
22668
|
+
try {
|
|
22669
|
+
configJson = readFileSync14(opts.jsonFile, "utf-8");
|
|
22670
|
+
} catch (err) {
|
|
22671
|
+
console.error(`Error: cannot read file '${opts.jsonFile}': ${err instanceof Error ? err.message : err}`);
|
|
22672
|
+
process.exit(1);
|
|
22673
|
+
}
|
|
22674
|
+
let config2;
|
|
22675
|
+
try {
|
|
22676
|
+
config2 = JSON.parse(configJson);
|
|
22677
|
+
} catch {
|
|
22678
|
+
console.error("Error: invalid JSON in configuration file");
|
|
22679
|
+
process.exit(1);
|
|
22680
|
+
}
|
|
22681
|
+
if (!config2.members || !Array.isArray(config2.members) || config2.members.length === 0) {
|
|
22682
|
+
console.error("Error: JSON must contain a 'members' array with at least one member");
|
|
22683
|
+
process.exit(1);
|
|
22684
|
+
}
|
|
22685
|
+
let runtimes;
|
|
22686
|
+
try {
|
|
22687
|
+
runtimes = await client.getJSON("/api/runtimes");
|
|
22688
|
+
} catch (err) {
|
|
22689
|
+
console.error(`Error: failed to fetch runtimes: ${err instanceof Error ? err.message : err}`);
|
|
22690
|
+
process.exit(1);
|
|
22691
|
+
}
|
|
22692
|
+
if (runtimes.length === 0) {
|
|
22693
|
+
console.error("Error: No daemon registered. Run 'npx @alook/cli daemon start' first.");
|
|
22694
|
+
process.exit(1);
|
|
22695
|
+
}
|
|
22696
|
+
const OFFLINE_THRESHOLD_MS2 = 5 * 60 * 1000;
|
|
22697
|
+
const now = Date.now();
|
|
22698
|
+
const onlineRuntime = runtimes.find((r) => {
|
|
22699
|
+
if (!r.machineLastSeenAt)
|
|
22700
|
+
return false;
|
|
22701
|
+
const lastSeen = new Date(r.machineLastSeenAt.includes("Z") ? r.machineLastSeenAt : r.machineLastSeenAt + "Z").getTime();
|
|
22702
|
+
return now - lastSeen < OFFLINE_THRESHOLD_MS2;
|
|
22703
|
+
});
|
|
22704
|
+
const runtime = onlineRuntime || runtimes[0];
|
|
22705
|
+
let targetWorkspaceId = workspaceId;
|
|
22706
|
+
let targetClient = client;
|
|
22707
|
+
try {
|
|
22708
|
+
const agents = await client.getJSON(`/api/agents?workspace_id=${workspaceId}`);
|
|
22709
|
+
if (agents.length > 0) {
|
|
22710
|
+
console.log("Current workspace has existing agents. Creating a new workspace...");
|
|
22711
|
+
const wsName = opts.name || config2.name || "New Workspace";
|
|
22712
|
+
const newWs = await client.postJSON("/api/workspaces", { name: wsName, slug: slugify2(wsName) });
|
|
22713
|
+
targetWorkspaceId = newWs.id;
|
|
22714
|
+
targetClient = new APIClient(serverUrl, token, targetWorkspaceId);
|
|
22715
|
+
console.log(`Created workspace: ${newWs.name} (${newWs.id})`);
|
|
22716
|
+
}
|
|
22717
|
+
} catch (err) {
|
|
22718
|
+
console.warn(`Warning: could not check existing agents: ${err instanceof Error ? err.message : err}`);
|
|
22719
|
+
}
|
|
22720
|
+
const members = config2.members.map((m) => ({
|
|
22721
|
+
...m,
|
|
22722
|
+
runtime_id: runtime.id
|
|
22723
|
+
}));
|
|
22724
|
+
const payload = {
|
|
22725
|
+
name: opts.name || config2.name,
|
|
22726
|
+
scenario: config2.scenario,
|
|
22727
|
+
members
|
|
22728
|
+
};
|
|
22729
|
+
try {
|
|
22730
|
+
const res = await targetClient.postJSON("/api/studios", payload);
|
|
22731
|
+
if (opts.json)
|
|
22732
|
+
return printJSON(res);
|
|
22733
|
+
console.log(`
|
|
22734
|
+
Workspace initialized: ${res.studio.name || res.workspace.name}`);
|
|
22735
|
+
console.log("Agents created:");
|
|
22736
|
+
for (const agent2 of res.agents) {
|
|
22737
|
+
const email3 = agent2.email_handle ? `${agent2.email_handle}@alook.ai` : "no email";
|
|
22738
|
+
console.log(` - ${agent2.name} (${email3})`);
|
|
22739
|
+
}
|
|
22740
|
+
} catch (err) {
|
|
22741
|
+
console.error(`Error: failed to create workspace: ${err instanceof Error ? err.message : err}`);
|
|
22742
|
+
process.exit(1);
|
|
22743
|
+
}
|
|
22744
|
+
});
|
|
22745
|
+
return cmd;
|
|
22746
|
+
}
|
|
22747
|
+
|
|
22656
22748
|
// src/index.ts
|
|
22657
|
-
var program = new
|
|
22749
|
+
var program = new Command14;
|
|
22658
22750
|
program.name("alook").description("Alook CLI").option("--server <url>", "Server URL").option("--profile <name>", "Profile name");
|
|
22659
22751
|
program.addCommand(registerCommand());
|
|
22660
22752
|
program.addCommand(loginCommand());
|
|
@@ -22668,4 +22760,5 @@ program.addCommand(configCommand());
|
|
|
22668
22760
|
program.addCommand(versionCommand());
|
|
22669
22761
|
program.addCommand(updateCommand());
|
|
22670
22762
|
program.addCommand(syncCommand());
|
|
22763
|
+
program.addCommand(workspaceCommand());
|
|
22671
22764
|
program.parse();
|