@agents24/cli 0.3.29 → 0.3.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/compatibility.json +7 -7
- package/dist/{chunk-5QY5A5R6.js → chunk-33HRB63R.js} +2 -2
- package/dist/chunk-33HRB63R.js.map +1 -0
- package/dist/cli.js +184 -225
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +1 -1
- package/generated/schemas/resource-package/2.0/agent.schema.json +5 -0
- package/generated/schemas/resource-package/2.0/artifact.schema.json +162 -28
- package/generated/schemas/resource-package/2.0/manifest.schema.json +26 -1
- package/generated/schemas/resource-package/2.0/rag.schema.json +22 -0
- package/generated/schemas/resource-package/2.0/workflow.schema.json +4 -0
- package/package.json +2 -2
- package/dist/chunk-5QY5A5R6.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -12,20 +12,19 @@ import {
|
|
|
12
12
|
replacePackageFiles,
|
|
13
13
|
shouldPromptForDependency,
|
|
14
14
|
validatePackage
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-33HRB63R.js";
|
|
16
16
|
|
|
17
17
|
// src/cli.ts
|
|
18
|
-
import { basename as basename2, dirname, join as
|
|
19
|
-
import { chmod as chmod2, readFile as
|
|
18
|
+
import { basename as basename2, dirname, join as join4, resolve as resolve3 } from "path";
|
|
19
|
+
import { chmod as chmod2, readFile as readFile6, writeFile as writeFile5 } from "fs/promises";
|
|
20
20
|
import { createInterface as createInterface3 } from "readline/promises";
|
|
21
21
|
import { createHash as createHash3 } from "crypto";
|
|
22
|
-
import { spawn } from "child_process";
|
|
23
22
|
import { isCancel, password, select, text } from "@clack/prompts";
|
|
24
23
|
import { parse as parseYaml3 } from "yaml";
|
|
25
24
|
|
|
26
25
|
// src/cli-arguments.ts
|
|
27
26
|
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["json", "remote", "yes", "allow-incomplete", "no-write-env", "prune", "apply", "wait", "replace", "fix-dependencies", "batch"]);
|
|
28
|
-
var LIFECYCLE_COMMANDS = /* @__PURE__ */ new Set(["prepare", "plan", "apply", "pull", "dev", "publish", "setup", "status", "link", "resources", "fork", "artifact", "knowledge"]);
|
|
27
|
+
var LIFECYCLE_COMMANDS = /* @__PURE__ */ new Set(["prepare", "plan", "apply", "pull", "dev", "serve", "publish", "setup", "status", "link", "resources", "fork", "artifact", "knowledge"]);
|
|
29
28
|
function parseArguments(argv) {
|
|
30
29
|
const lifecycle = LIFECYCLE_COMMANDS.has(argv[0]);
|
|
31
30
|
if (!lifecycle && (argv[0] !== "package" || !argv[1])) {
|
|
@@ -353,7 +352,7 @@ async function promptImportMappings(client, preview, current, enabled) {
|
|
|
353
352
|
kind: String(dependency.kind),
|
|
354
353
|
query: String(dependency.source_name || ""),
|
|
355
354
|
modelRequirements: dependency.model_requirements,
|
|
356
|
-
requiredCapability: ["chat", "embedding", "speech_to_text", "rerank"].find((kind) => kind === dependency.required_capability)
|
|
355
|
+
requiredCapability: ["chat", "embedding", "speech_to_text", "rerank", "ocr"].find((kind) => kind === dependency.required_capability)
|
|
357
356
|
});
|
|
358
357
|
const candidates = Array.isArray(response.items) ? response.items : [];
|
|
359
358
|
process.stdout.write(`${dependency.source_name || key}: ${candidates.map((item, index) => `${index + 1}) ${item.name}`).join(" ")}
|
|
@@ -396,13 +395,17 @@ async function promptInstallationRequirementLinks(client, installationId, plan,
|
|
|
396
395
|
}
|
|
397
396
|
}
|
|
398
397
|
|
|
399
|
-
// src/cli-
|
|
400
|
-
import {
|
|
398
|
+
// src/cli-relay.ts
|
|
399
|
+
import { randomUUID } from "crypto";
|
|
401
400
|
import { hostname } from "os";
|
|
401
|
+
import { join as join3 } from "path";
|
|
402
|
+
import { mkdir, readFile as readFile3, writeFile as writeFile3, rename, rm } from "fs/promises";
|
|
403
|
+
import { spawn } from "child_process";
|
|
404
|
+
import { createArtifactRelay } from "@agents24/node/relay";
|
|
405
|
+
|
|
406
|
+
// src/cli-development.ts
|
|
402
407
|
import { resolve as resolve2 } from "path";
|
|
403
408
|
import { parse as parseYaml2 } from "yaml";
|
|
404
|
-
var DEFAULT_API_BASE_URL = "https://api.agents24.dev";
|
|
405
|
-
var MANIFEST_POLL_INTERVAL_MS = 2e3;
|
|
406
409
|
async function developmentArtifacts(input2) {
|
|
407
410
|
const directory = await packageDirectory(input2);
|
|
408
411
|
if (!directory) throw new Error("dev requires a Resource Package directory");
|
|
@@ -429,6 +432,7 @@ async function developmentArtifacts(input2) {
|
|
|
429
432
|
const cwd = resolve2(directory, String(development.cwd || "."));
|
|
430
433
|
if (cwd !== directory && !cwd.startsWith(`${directory}/`)) throw new Error(`Artifact ${resource.key} development.cwd must remain inside the package`);
|
|
431
434
|
result.push({
|
|
435
|
+
productionTransport: source.production?.base_url ? "http" : "relay",
|
|
432
436
|
key: String(resource.key || ""),
|
|
433
437
|
baseUrl: String(development.base_url || ""),
|
|
434
438
|
command: development.command ? String(development.command) : void 0,
|
|
@@ -451,7 +455,7 @@ async function waitForServer(baseUrl, healthPath) {
|
|
|
451
455
|
const target = new URL(String(healthPath || "/.well-known/agents24/artifact/health"), baseUrl);
|
|
452
456
|
for (let attempt = 0; attempt < 60; attempt += 1) {
|
|
453
457
|
try {
|
|
454
|
-
const response = await fetch(target);
|
|
458
|
+
const response = await fetch(target, { signal: AbortSignal.timeout(1e3) });
|
|
455
459
|
if (response.ok) return;
|
|
456
460
|
} catch {
|
|
457
461
|
}
|
|
@@ -459,119 +463,125 @@ async function waitForServer(baseUrl, healthPath) {
|
|
|
459
463
|
}
|
|
460
464
|
throw new Error(`Local Artifact server did not become healthy at ${target}`);
|
|
461
465
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
+
|
|
467
|
+
// src/cli-relay.ts
|
|
468
|
+
async function servePackageRelay(options) {
|
|
469
|
+
const directory = await packageDirectory(options.input);
|
|
470
|
+
if (!directory) throw new Error("Relay serving requires a package directory");
|
|
471
|
+
const artifacts = options.declared.filter((a) => (!options.artifactKey || a.key === options.artifactKey) && (options.target === "draft" || a.productionTransport === "relay"));
|
|
472
|
+
if (!artifacts.length) throw new Error("No local relay Artifact endpoints are configured");
|
|
473
|
+
for (const id of [options.clientId, options.runtimePrincipalId]) {
|
|
474
|
+
if (id && !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(id)) throw new Error("Relay client and principal IDs must be UUIDs");
|
|
475
|
+
}
|
|
476
|
+
const baseUrl = process.env.AGENTS24_BASE_URL || "https://api.agents24.dev";
|
|
477
|
+
await ensureIgnored(directory, [".agents24/"]);
|
|
478
|
+
const stateDir = join3(directory, ".agents24");
|
|
479
|
+
await mkdir(stateDir, { recursive: true, mode: 448 });
|
|
480
|
+
const identityPath = join3(stateDir, `relay-${options.runtimePrincipalId || "developer"}.json`);
|
|
481
|
+
let clientId = options.clientId;
|
|
482
|
+
if (!clientId) {
|
|
483
|
+
try {
|
|
484
|
+
const saved = JSON.parse(await readFile3(identityPath, "utf8"));
|
|
485
|
+
if (saved.base_url === baseUrl && saved.installation_id === options.installation.id) clientId = saved.client_id;
|
|
486
|
+
} catch (error) {
|
|
487
|
+
if (error.code !== "ENOENT") throw error;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
clientId ||= randomUUID();
|
|
491
|
+
const temporaryIdentity = `${identityPath}.${randomUUID()}.tmp`;
|
|
492
|
+
try {
|
|
493
|
+
await writeFile3(temporaryIdentity, JSON.stringify({ client_id: clientId, base_url: baseUrl, installation_id: options.installation.id }), { mode: 384, flag: "wx" });
|
|
494
|
+
await rename(temporaryIdentity, identityPath);
|
|
495
|
+
} finally {
|
|
496
|
+
await rm(temporaryIdentity, { force: true });
|
|
497
|
+
}
|
|
498
|
+
await options.client.relayClients.create({ id: clientId, name: hostname(), runtime_principal_id: options.runtimePrincipalId });
|
|
499
|
+
let localEnv = {};
|
|
500
|
+
try {
|
|
501
|
+
localEnv = parseEnv(await readFile3(join3(directory, ".env.local"), "utf8"));
|
|
502
|
+
} catch (error) {
|
|
503
|
+
if (error.code !== "ENOENT") throw error;
|
|
504
|
+
}
|
|
505
|
+
const relay = createArtifactRelay({
|
|
506
|
+
baseUrl,
|
|
507
|
+
clientId,
|
|
508
|
+
getTicket: ({ registrations, signal }) => options.client.relayClients.createTicket(clientId, { registrations }, { signal }),
|
|
509
|
+
onStatus: (status) => process.stdout.write(`${JSON.stringify({ phase: "relay_status", relay_client_id: clientId, ...status })}
|
|
510
|
+
`)
|
|
466
511
|
});
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const socket = new WebSocket(apiUrl, [
|
|
471
|
-
"agents24-artifact-relay",
|
|
472
|
-
`agents24-credential-${String(admission.relay_token)}`
|
|
473
|
-
]);
|
|
474
|
-
const state = {};
|
|
475
|
-
let manifestHash;
|
|
476
|
-
let pendingHash;
|
|
512
|
+
const children = [];
|
|
513
|
+
const bindings = options.installation.bindings || [];
|
|
514
|
+
let poll;
|
|
477
515
|
let polling = false;
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
516
|
+
const stop = new Promise((resolve4) => {
|
|
517
|
+
process.once("SIGINT", resolve4);
|
|
518
|
+
process.once("SIGTERM", resolve4);
|
|
519
|
+
});
|
|
520
|
+
try {
|
|
521
|
+
for (const artifact of artifacts) {
|
|
522
|
+
const binding = bindings.find((b) => b.kind === "artifact" && (b.resource_key === artifact.key || b.resource_key === `artifact:${artifact.key}`));
|
|
523
|
+
if (!binding?.resource_id) throw new Error(`Apply the package before serving Artifact ${artifact.key}`);
|
|
524
|
+
if (artifact.command) {
|
|
525
|
+
const child = spawn(artifact.command, artifact.args, {
|
|
526
|
+
cwd: artifact.cwd,
|
|
527
|
+
env: { ...process.env, ...localEnv },
|
|
528
|
+
stdio: "inherit",
|
|
529
|
+
shell: false
|
|
530
|
+
});
|
|
531
|
+
child.on("error", () => process.stdout.write(`${JSON.stringify({ phase: "artifact_unavailable", artifact: artifact.key })}
|
|
532
|
+
`));
|
|
533
|
+
children.push(child);
|
|
493
534
|
}
|
|
494
|
-
pendingHash = nextHash;
|
|
495
|
-
socket.send(JSON.stringify({ type: "manifest_changed" }));
|
|
496
|
-
} catch {
|
|
497
|
-
pendingHash = "unavailable";
|
|
498
|
-
socket.send(JSON.stringify({ type: "manifest_changed" }));
|
|
499
|
-
} finally {
|
|
500
|
-
polling = false;
|
|
501
535
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
const requestBody = method === "POST" ? JSON.stringify(message.body || {}) : void 0;
|
|
534
|
-
const headers = method === "POST" ? { "content-type": "application/json" } : {};
|
|
535
|
-
if (method === "POST" && String(artifact.protocol.auth_mode || "hmac_sha256") === "hmac_sha256") {
|
|
536
|
-
const signingSecret = String(
|
|
537
|
-
artifact.signingSecretEnv && (localEnv[artifact.signingSecretEnv] || process.env[artifact.signingSecretEnv]) || ""
|
|
538
|
-
);
|
|
539
|
-
if (!signingSecret) throw new Error(`Artifact ${artifact.key} signing secret is unavailable`);
|
|
540
|
-
const timestamp = String(Date.now());
|
|
541
|
-
const signature = createHmac("sha256", signingSecret).update(`${timestamp}.${requestBody}`).digest("hex");
|
|
542
|
-
headers["x-agents24-timestamp"] = timestamp;
|
|
543
|
-
headers["x-agents24-signature"] = `sha256=${signature}`;
|
|
544
|
-
}
|
|
545
|
-
const response = await fetch(new URL(String(message.path || "/"), artifact.baseUrl), { method, headers, body: requestBody });
|
|
546
|
-
const textBody = await response.text();
|
|
547
|
-
let body = textBody;
|
|
548
|
-
try {
|
|
549
|
-
body = textBody ? JSON.parse(textBody) : null;
|
|
550
|
-
} catch {
|
|
551
|
-
}
|
|
552
|
-
socket.send(JSON.stringify({ type: "response", request_id: message.request_id, status: response.status, body }));
|
|
553
|
-
} catch (error) {
|
|
554
|
-
const cause = error instanceof Error && error.cause && typeof error.cause === "object" ? error.cause : void 0;
|
|
555
|
-
const causeCode = typeof cause?.code === "string" ? ` (${cause.code})` : "";
|
|
556
|
-
const causeMessage = typeof cause?.message === "string" ? `: ${cause.message}` : "";
|
|
557
|
-
const errorMessage = error instanceof Error ? `${error.message}${causeCode}${causeMessage}` : "Unknown local Artifact relay error";
|
|
558
|
-
process.stderr.write(`[agents24 dev] ${artifact.key}: ${errorMessage}
|
|
536
|
+
await Promise.allSettled(artifacts.map(async (artifact) => {
|
|
537
|
+
const binding = bindings.find((b) => b.resource_key === artifact.key || b.resource_key === `artifact:${artifact.key}`);
|
|
538
|
+
await waitForServer(artifact.baseUrl, artifact.protocol.health_path).catch(() => {
|
|
539
|
+
});
|
|
540
|
+
await relay.register({
|
|
541
|
+
artifactId: String(binding.resource_id),
|
|
542
|
+
target: options.target,
|
|
543
|
+
authoring: options.target === "draft",
|
|
544
|
+
installationId: String(options.installation.id),
|
|
545
|
+
resourceKey: artifact.key,
|
|
546
|
+
baseUrl: artifact.baseUrl,
|
|
547
|
+
signingSecret: artifact.signingSecretEnv ? process.env[artifact.signingSecretEnv] || localEnv[artifact.signingSecretEnv] : void 0,
|
|
548
|
+
manifestPath: artifact.protocol.manifest_path,
|
|
549
|
+
healthPath: artifact.protocol.health_path,
|
|
550
|
+
verifyPath: artifact.protocol.verify_path,
|
|
551
|
+
invokePath: artifact.protocol.invoke_path
|
|
552
|
+
});
|
|
553
|
+
}));
|
|
554
|
+
try {
|
|
555
|
+
await relay.connect();
|
|
556
|
+
} catch (error) {
|
|
557
|
+
if (!["connecting", "reconnecting"].includes(relay.status.state)) throw error;
|
|
558
|
+
}
|
|
559
|
+
process.stdout.write(`${JSON.stringify({
|
|
560
|
+
ok: true,
|
|
561
|
+
phase: relay.status.state === "connected" ? "relay_connected" : "relay_connecting",
|
|
562
|
+
target: options.target,
|
|
563
|
+
installation_id: options.installation.id,
|
|
564
|
+
relay_client_id: clientId,
|
|
565
|
+
registrations: relay.status.registrations
|
|
566
|
+
})}
|
|
559
567
|
`);
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
568
|
+
if (options.target === "draft") poll = setInterval(() => {
|
|
569
|
+
if (polling || relay.status.state !== "connected") return;
|
|
570
|
+
polling = true;
|
|
571
|
+
void Promise.allSettled(artifacts.map((artifact) => {
|
|
572
|
+
const binding = bindings.find((b) => b.resource_key === artifact.key || b.resource_key === `artifact:${artifact.key}`);
|
|
573
|
+
return relay.refresh(String(binding?.resource_id), "draft");
|
|
574
|
+
})).finally(() => {
|
|
575
|
+
polling = false;
|
|
576
|
+
});
|
|
577
|
+
}, 2e3);
|
|
578
|
+
await stop;
|
|
579
|
+
return { ok: true, phase: "relay_stopped", relay_client_id: clientId };
|
|
580
|
+
} finally {
|
|
581
|
+
if (poll) clearInterval(poll);
|
|
582
|
+
await relay.close();
|
|
583
|
+
for (const child of children) child.kill("SIGTERM");
|
|
584
|
+
}
|
|
575
585
|
}
|
|
576
586
|
|
|
577
587
|
// src/cli-help.ts
|
|
@@ -585,8 +595,9 @@ var commands = {
|
|
|
585
595
|
status: { args: "<directory>", summary: "Inspect installation, validation, and publication status.", flags: "", example: "agents24 status ./agents24 --json" },
|
|
586
596
|
pull: { args: "<directory>", summary: "Review and pull portable platform changes into the local package.", flags: "--yes", example: "agents24 pull ./agents24" },
|
|
587
597
|
link: { args: "<directory>", summary: "Link an external requirement by its stable key in an installation.", flags: "--resource <stable-key=resource-id> (repeatable)", example: "agents24 link ./agents24 --resource '$tools.search=<tool-id>'" },
|
|
588
|
-
resources: { args: "", summary: "List candidate resources for external requirements.", flags: "--kind <kind> --query <text> --limit <number>", example: "agents24 resources --kind tool --query Search --json" },
|
|
589
|
-
dev: { args: "<directory>", summary: "
|
|
598
|
+
resources: { args: "list", summary: "List candidate resources for external requirements.", flags: "--kind <kind> --query <text> --limit <number> --capability <chat|embedding|speech_to_text|rerank|ocr>", example: "agents24 resources list --kind tool --query Search --json" },
|
|
599
|
+
dev: { args: "<directory>", summary: "Serve package draft Artifacts through one shared relay.", flags: "--artifact <stable-key> --client-id <uuid> --principal <runtime-principal-id> --apply --yes", example: "agents24 dev ./agents24 --apply" },
|
|
600
|
+
serve: { args: "<directory>", summary: "Serve published relay Artifacts from this app profile.", flags: "--artifact <stable-key> --client-id <uuid> --principal <runtime-principal-id>", example: "agents24 serve ./agents24 --principal <runtime-principal-id>" },
|
|
590
601
|
artifact: { args: "<init|pull|status|diff|push|build|test> [directory]", summary: "Author and test Hosted Artifact source; execution stays on Agents24.", flags: "--language <python|javascript> --artifact <key> --id <existing-artifact-id> --into <directory> --bind <key>:<credential-id> --replace --fix-dependencies --export <name> --input <file|-> --config <json-file> --target <draft|published> --wait", example: "agents24 artifact pull --id <artifact-id> --into ./artifact" },
|
|
591
602
|
fork: { args: "<source> <target>", summary: "Copy a package with a new installation identity.", flags: "--name <name>", example: "agents24 fork ./agents24 ./copy --name copy" },
|
|
592
603
|
"package init": { args: "[directory]", summary: "Initialize a package with a unique package_id. Copying keeps identity; fork creates a new one.", flags: "--name <name>", example: "agents24 package init ./agents24 --name research" },
|
|
@@ -626,7 +637,7 @@ Example:
|
|
|
626
637
|
|
|
627
638
|
// src/cli-hosted-artifacts.ts
|
|
628
639
|
import { createHash as createHash2 } from "crypto";
|
|
629
|
-
import { mkdir, readFile as
|
|
640
|
+
import { mkdir as mkdir2, readFile as readFile4, readdir, writeFile as writeFile4 } from "fs/promises";
|
|
630
641
|
import path from "path";
|
|
631
642
|
import { parse, stringify } from "yaml";
|
|
632
643
|
var stateName = "hosted-artifacts.json";
|
|
@@ -723,7 +734,7 @@ async function localArtifact(input2, selected) {
|
|
|
723
734
|
}
|
|
724
735
|
async function stateFile(root) {
|
|
725
736
|
try {
|
|
726
|
-
return object(JSON.parse(await
|
|
737
|
+
return object(JSON.parse(await readFile4(path.join(root, ".agents24", stateName), "utf8")));
|
|
727
738
|
} catch (error) {
|
|
728
739
|
if (error.code === "ENOENT") return {};
|
|
729
740
|
throw error;
|
|
@@ -731,10 +742,10 @@ async function stateFile(root) {
|
|
|
731
742
|
}
|
|
732
743
|
async function saveState(root, key, state) {
|
|
733
744
|
const directory = path.join(root, ".agents24");
|
|
734
|
-
await
|
|
745
|
+
await mkdir2(directory, { recursive: true });
|
|
735
746
|
const current = await stateFile(root);
|
|
736
747
|
current[key] = state;
|
|
737
|
-
await
|
|
748
|
+
await writeFile4(path.join(directory, stateName), JSON.stringify(current, null, 2) + "\n", { mode: 384 });
|
|
738
749
|
}
|
|
739
750
|
async function installationArtifact(client, local) {
|
|
740
751
|
const packageId = String(local.manifest.package_id || "");
|
|
@@ -777,16 +788,16 @@ async function writeNewPackage(directory, name, draft, requestedLanguage) {
|
|
|
777
788
|
capabilities: typeof draft?.capabilities === "string" ? JSON.parse(draft.capabilities || "{}") : object(draft?.capabilities)
|
|
778
789
|
};
|
|
779
790
|
const manifest = { schema: "agents24.package/v2", package_id: createPackageId(), name: key, resources: [{ key, path: `artifacts/${key}/artifact.yaml` }] };
|
|
780
|
-
await
|
|
781
|
-
await
|
|
782
|
-
await
|
|
791
|
+
await mkdir2(path.join(root, "artifacts", key, "src"), { recursive: true });
|
|
792
|
+
await writeFile4(path.join(root, "agents24.yaml"), stringify(manifest), { flag: "wx" });
|
|
793
|
+
await writeFile4(path.join(root, "artifacts", key, "artifact.yaml"), stringify(source), { flag: "wx" });
|
|
783
794
|
const initial = language === "javascript" ? 'import { defineArtifact, tool } from "@agents24/node/artifacts";\nexport default defineArtifact({ tools: { echo: tool({ handler: async (input) => input }) } });\n' : 'from agents24.artifacts import tool\n\n@tool(name="echo")\nasync def echo(input, config, context):\n return input\n';
|
|
784
795
|
for (const item of files.length ? files : [{ path: entry, content: initial }]) {
|
|
785
796
|
const relative = String(item.path || "").replace(/^src\//, "");
|
|
786
797
|
if (!relative || relative.startsWith("/") || relative.split("/").includes("..")) throw new Error("Artifact source has an unsafe path");
|
|
787
798
|
const destination = path.join(root, "artifacts", key, "src", relative);
|
|
788
|
-
await
|
|
789
|
-
await
|
|
799
|
+
await mkdir2(path.dirname(destination), { recursive: true });
|
|
800
|
+
await writeFile4(destination, String(item.content || ""), { flag: "wx" });
|
|
790
801
|
}
|
|
791
802
|
return localArtifact(root, key);
|
|
792
803
|
}
|
|
@@ -829,7 +840,7 @@ async function hostedArtifactCommand(parsed, client) {
|
|
|
829
840
|
if (unresolved.length && flag(parsed, "fix-dependencies") === "true" && unresolved.every((row) => typeof row.suggested_spec === "string" && row.suggested_spec)) {
|
|
830
841
|
const additions = unresolved.map((row) => String(row.suggested_spec));
|
|
831
842
|
const source = { ...local.source, runtime: { ...runtime, dependencies: [...Array.isArray(runtime.dependencies) ? runtime.dependencies : [], ...additions] } };
|
|
832
|
-
await
|
|
843
|
+
await writeFile4(path.join(local.root, local.artifactPath), stringify(source));
|
|
833
844
|
local = await localArtifact(local.root, local.key);
|
|
834
845
|
const repaired = await validatePackage(local.root);
|
|
835
846
|
if (!repaired.valid) throw Object.assign(new Error("Dependency repair produced an invalid Resource Package"), { diagnostics: repaired.diagnostics });
|
|
@@ -906,11 +917,11 @@ async function hostedArtifactCommand(parsed, client) {
|
|
|
906
917
|
const relative = String(item.path || "");
|
|
907
918
|
if (!relative || relative.startsWith("/") || relative.split("/").includes("..")) throw new Error("Remote Artifact source has an unsafe path");
|
|
908
919
|
const destination = path.join(local.root, prefix, relative);
|
|
909
|
-
await
|
|
910
|
-
await
|
|
920
|
+
await mkdir2(path.dirname(destination), { recursive: true });
|
|
921
|
+
await writeFile4(destination, String(item.content || ""));
|
|
911
922
|
}
|
|
912
923
|
const source = { ...local.source, name: raw.display_name, description: raw.description, runtime: { language: raw.language, entry: String(raw.entry_module_path || "main.py").replace(/^src\//, ""), dependencies: Array.isArray(raw.dependencies) ? raw.dependencies : String(raw.dependencies || "").split(",").map((part) => part.trim()).filter(Boolean) }, capabilities: typeof raw.capabilities === "string" ? JSON.parse(raw.capabilities || "{}") : object(raw.capabilities) };
|
|
913
|
-
await
|
|
924
|
+
await writeFile4(path.join(local.root, local.artifactPath), stringify(source));
|
|
914
925
|
const refreshed = await localArtifact(local.root, local.key);
|
|
915
926
|
await saveState(local.root, local.key, { artifact_id: artifactId, draft_version: Number(remote.draft_version), draft_hash: String(remote.draft_hash), local_hash: hash(comparable(snapshot(refreshed, portable.bindings))), credential_bindings: portable.bindings });
|
|
916
927
|
return { ok: true, artifact_id: artifactId, draft_version: remote.draft_version, credential_refs: remote.credential_refs };
|
|
@@ -941,9 +952,9 @@ async function hostedArtifactCommand(parsed, client) {
|
|
|
941
952
|
value += chunk;
|
|
942
953
|
});
|
|
943
954
|
process.stdin.on("end", () => done(value));
|
|
944
|
-
}) : await
|
|
955
|
+
}) : await readFile4(inputPath, "utf8")) : {};
|
|
945
956
|
const configPath = flag(parsed, "config");
|
|
946
|
-
const config = configPath ? JSON.parse(await
|
|
957
|
+
const config = configPath ? JSON.parse(await readFile4(configPath, "utf8")) : {};
|
|
947
958
|
if (!config || typeof config !== "object" || Array.isArray(config)) throw new Error("--config must contain a JSON object");
|
|
948
959
|
const run2 = await client.hostedArtifacts.test(artifactId, { export_name: exportName, input_data: inputData, config, runtime_target: target, ...target === "draft" ? { expected_draft_version: remote.draft_version, expected_draft_hash: remote.draft_hash, expected_runtime_hash: remote.runtime_hash } : {} });
|
|
949
960
|
if (flag(parsed, "wait") !== "true") return { ok: !["failed", "cancelled"].includes(String(run2.status)), artifact_id: artifactId, run_id: run2.run_id, status: run2.status };
|
|
@@ -961,14 +972,14 @@ async function hostedArtifactCommand(parsed, client) {
|
|
|
961
972
|
}
|
|
962
973
|
|
|
963
974
|
// src/cli-knowledge.ts
|
|
964
|
-
import { readFile as
|
|
975
|
+
import { readFile as readFile5 } from "fs/promises";
|
|
965
976
|
async function input(parsed) {
|
|
966
977
|
const path2 = flag(parsed, "input");
|
|
967
978
|
if (!path2) throw new Error("Record operations require --input <json-file|->");
|
|
968
979
|
let data = "";
|
|
969
980
|
if (path2 === "-") {
|
|
970
981
|
for await (const chunk of process.stdin) data += chunk.toString();
|
|
971
|
-
} else data = await
|
|
982
|
+
} else data = await readFile5(path2, "utf8");
|
|
972
983
|
const payload = JSON.parse(data);
|
|
973
984
|
if (!payload || typeof payload !== "object" || Array.isArray(payload)) throw new Error("Input must be a JSON object");
|
|
974
985
|
return payload;
|
|
@@ -1004,7 +1015,7 @@ async function knowledgeCommand(parsed) {
|
|
|
1004
1015
|
}
|
|
1005
1016
|
|
|
1006
1017
|
// src/cli.ts
|
|
1007
|
-
var
|
|
1018
|
+
var DEFAULT_API_BASE_URL = "https://api.agents24.dev";
|
|
1008
1019
|
var DEFAULT_LOCAL_CLIENT_ORIGINS = ["http://localhost:5173", "http://127.0.0.1:5173"];
|
|
1009
1020
|
function mappings(parsed) {
|
|
1010
1021
|
return parseMappings(values(parsed, "map"));
|
|
@@ -1076,9 +1087,9 @@ async function loadPackageLifecycleEnvironment(input2) {
|
|
|
1076
1087
|
if (!input2) return;
|
|
1077
1088
|
const directory = await packageDirectory(input2);
|
|
1078
1089
|
if (!directory) return;
|
|
1079
|
-
for (const path2 of [
|
|
1090
|
+
for (const path2 of [join4(dirname(directory), ".env.local"), join4(directory, ".env.local")]) {
|
|
1080
1091
|
try {
|
|
1081
|
-
const values2 = parseEnv(await
|
|
1092
|
+
const values2 = parseEnv(await readFile6(path2, "utf8"));
|
|
1082
1093
|
for (const [name, value] of Object.entries(values2)) {
|
|
1083
1094
|
if (!process.env[name]) process.env[name] = value;
|
|
1084
1095
|
}
|
|
@@ -1099,7 +1110,7 @@ function publicationProjection(publication) {
|
|
|
1099
1110
|
}
|
|
1100
1111
|
function clientAppBaseUrl(environment = process.env) {
|
|
1101
1112
|
const baseUrl = String(environment.AGENTS24_BASE_URL || "").trim().replace(/\/+$/, "");
|
|
1102
|
-
if (!baseUrl || baseUrl ===
|
|
1113
|
+
if (!baseUrl || baseUrl === DEFAULT_API_BASE_URL) return void 0;
|
|
1103
1114
|
let parsed;
|
|
1104
1115
|
try {
|
|
1105
1116
|
parsed = new URL(baseUrl);
|
|
@@ -1114,7 +1125,7 @@ function clientAppBaseUrl(environment = process.env) {
|
|
|
1114
1125
|
async function appInfoAt(directory, explicit) {
|
|
1115
1126
|
const target = resolve3(directory);
|
|
1116
1127
|
try {
|
|
1117
|
-
const manifest = JSON.parse(await
|
|
1128
|
+
const manifest = JSON.parse(await readFile6(join4(target, "package.json"), "utf8"));
|
|
1118
1129
|
const metadata = manifest.agents24 && typeof manifest.agents24 === "object" ? manifest.agents24 : {};
|
|
1119
1130
|
const integration = String(metadata.integration || "");
|
|
1120
1131
|
if (integration !== "client-deployment" && integration !== "bff") {
|
|
@@ -1180,10 +1191,10 @@ async function clientDeployment(parsed, client, agent, app) {
|
|
|
1180
1191
|
return client.clientDeployments.create(request, { idempotencyKey: `deploy-${createHash3("sha256").update(canonicalJson(request)).digest("hex").slice(0, 40)}` });
|
|
1181
1192
|
}
|
|
1182
1193
|
async function updateEnvFile(app, values2) {
|
|
1183
|
-
const target =
|
|
1194
|
+
const target = join4(app.directory, ".env.local");
|
|
1184
1195
|
let content = "";
|
|
1185
1196
|
try {
|
|
1186
|
-
content = await
|
|
1197
|
+
content = await readFile6(target, "utf8");
|
|
1187
1198
|
} catch (error) {
|
|
1188
1199
|
if (error.code !== "ENOENT") throw error;
|
|
1189
1200
|
}
|
|
@@ -1199,7 +1210,7 @@ async function updateEnvFile(app, values2) {
|
|
|
1199
1210
|
}) : `${next}${next && !next.endsWith("\n") ? "\n" : ""}${line}
|
|
1200
1211
|
`;
|
|
1201
1212
|
}
|
|
1202
|
-
await
|
|
1213
|
+
await writeFile5(target, next, { mode: 384 });
|
|
1203
1214
|
await chmod2(target, 384);
|
|
1204
1215
|
return target;
|
|
1205
1216
|
}
|
|
@@ -1288,7 +1299,10 @@ async function applyDraft(parsed, options = {}) {
|
|
|
1288
1299
|
}
|
|
1289
1300
|
if (plan.can_apply !== true) throw Object.assign(new Error(blockedPlanMessage(plan)), { plan });
|
|
1290
1301
|
if (!options.skipConfirmation) await applyConfirmation(parsed, plan);
|
|
1291
|
-
const
|
|
1302
|
+
const configuredSecrets = await secretValues(input2);
|
|
1303
|
+
const externalRequirements = Array.isArray(plan.external_requirements) ? plan.external_requirements : [];
|
|
1304
|
+
const requiredSecretKeys = new Set(externalRequirements.filter((item) => item.kind === "secret").map((item) => String(item.requirement_key)));
|
|
1305
|
+
const secrets = Object.fromEntries(Object.entries(configuredSecrets).filter(([key]) => requiredSecretKeys.has(key)));
|
|
1292
1306
|
let operation = await client.resourceInstallations.apply(String(plan.operation_id), {
|
|
1293
1307
|
secrets
|
|
1294
1308
|
}, { idempotencyKey: `apply-${String(plan.operation_id)}` });
|
|
@@ -1392,11 +1406,12 @@ async function execute(parsed) {
|
|
|
1392
1406
|
const kind = flag(parsed, "kind");
|
|
1393
1407
|
if (!kind) throw new Error("resources list requires --kind");
|
|
1394
1408
|
const apiKey = await apiKeyForLifecycle(parsed);
|
|
1395
|
-
const
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1409
|
+
const client = await createRemoteClient({ ...process.env, AGENTS24_API_KEY: apiKey });
|
|
1410
|
+
const capability = flag(parsed, "capability");
|
|
1411
|
+
const supported = ["chat", "embedding", "speech_to_text", "rerank", "ocr"];
|
|
1412
|
+
const requiredCapability = supported.find((value) => value === capability);
|
|
1413
|
+
if (capability && (kind !== "model" || !requiredCapability)) throw new Error("--capability requires kind model and a supported model capability");
|
|
1414
|
+
const result = requiredCapability ? await client.resourcePackages.candidates({ kind, query: flag(parsed, "query"), requiredCapability, limit: Number(flag(parsed, "limit") || 100) }) : await client.resourceInstallations.resources({ kind, query: flag(parsed, "query"), limit: Number(flag(parsed, "limit") || 100) });
|
|
1400
1415
|
return { ok: true, ...result };
|
|
1401
1416
|
}
|
|
1402
1417
|
if (parsed.command === "link") {
|
|
@@ -1486,83 +1501,27 @@ async function execute(parsed) {
|
|
|
1486
1501
|
...envFile ? { env_file: envFile } : {}
|
|
1487
1502
|
};
|
|
1488
1503
|
}
|
|
1489
|
-
if (parsed.command === "dev") {
|
|
1504
|
+
if (parsed.command === "dev" || parsed.command === "serve") {
|
|
1490
1505
|
const input2 = parsed.positionals[0];
|
|
1491
|
-
if (!input2) throw new Error(
|
|
1506
|
+
if (!input2) throw new Error(`${parsed.command} requires a Resource Package directory`);
|
|
1492
1507
|
await packageIdentity(input2);
|
|
1493
1508
|
await preparePackage(input2);
|
|
1494
1509
|
const declared = await developmentArtifacts(input2);
|
|
1495
|
-
|
|
1496
|
-
const artifacts = selectedKey ? declared.filter((item) => item.key === selectedKey) : declared;
|
|
1497
|
-
if (!artifacts.length) throw new Error(selectedKey ? `Artifact ${selectedKey} has no development configuration` : "No self-hosted Artifact development configuration was found");
|
|
1510
|
+
if (!declared.length) throw new Error("No self-hosted Artifact development configuration was found");
|
|
1498
1511
|
const apiKey = await apiKeyForLifecycle(parsed);
|
|
1499
1512
|
const client = await createRemoteClient({ ...process.env, AGENTS24_API_KEY: apiKey });
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
if (Object.keys(configuredSecrets).length) await client.resourceInstallations.configureSecrets(id, { secrets: configuredSecrets });
|
|
1513
|
-
const directory = await packageDirectory(input2);
|
|
1514
|
-
const localEnv = directory ? parseEnv(await readFile5(join3(directory, ".env.local"), "utf8")) : {};
|
|
1515
|
-
const children = [];
|
|
1516
|
-
const relays = [];
|
|
1517
|
-
try {
|
|
1518
|
-
for (const artifact of artifacts) {
|
|
1519
|
-
if (artifact.command) children.push(spawn(artifact.command, artifact.args, { cwd: artifact.cwd, env: { ...process.env, ...localEnv }, stdio: "inherit", shell: false }));
|
|
1520
|
-
await waitForServer(artifact.baseUrl, artifact.protocol.health_path);
|
|
1521
|
-
relays.push(await openDevelopmentRelay(client, id, artifact, localEnv));
|
|
1522
|
-
}
|
|
1523
|
-
const developmentSessions = Object.fromEntries(artifacts.map((item, index) => [item.key, relays[index].sessionId]));
|
|
1524
|
-
process.stdout.write(`${JSON.stringify({ ok: true, phase: "development_connected", installation_id: id, development_sessions: developmentSessions, draft_applied: Boolean(applied) }, null, 2)}
|
|
1525
|
-
`);
|
|
1526
|
-
await new Promise((resolveStop) => {
|
|
1527
|
-
let stopping = false;
|
|
1528
|
-
const reconnecting = /* @__PURE__ */ new Set();
|
|
1529
|
-
const stop = () => {
|
|
1530
|
-
stopping = true;
|
|
1531
|
-
resolveStop();
|
|
1532
|
-
};
|
|
1533
|
-
const watch = (relay, index) => {
|
|
1534
|
-
relay.socket.addEventListener("close", async () => {
|
|
1535
|
-
if (stopping) return;
|
|
1536
|
-
if (relay.state.terminalReason || reconnecting.has(index)) {
|
|
1537
|
-
stop();
|
|
1538
|
-
return;
|
|
1539
|
-
}
|
|
1540
|
-
reconnecting.add(index);
|
|
1541
|
-
for (let attempt = 1; attempt <= 3 && !stopping; attempt += 1) {
|
|
1542
|
-
await new Promise((resolveDelay) => setTimeout(resolveDelay, attempt * 500));
|
|
1543
|
-
try {
|
|
1544
|
-
const replacement = await openDevelopmentRelay(client, id, artifacts[index], localEnv);
|
|
1545
|
-
relays[index] = replacement;
|
|
1546
|
-
developmentSessions[artifacts[index].key] = replacement.sessionId;
|
|
1547
|
-
reconnecting.delete(index);
|
|
1548
|
-
watch(replacement, index);
|
|
1549
|
-
return;
|
|
1550
|
-
} catch {
|
|
1551
|
-
}
|
|
1552
|
-
}
|
|
1553
|
-
reconnecting.delete(index);
|
|
1554
|
-
stop();
|
|
1555
|
-
}, { once: true });
|
|
1556
|
-
};
|
|
1557
|
-
process.once("SIGINT", stop);
|
|
1558
|
-
process.once("SIGTERM", stop);
|
|
1559
|
-
relays.forEach(watch);
|
|
1560
|
-
});
|
|
1561
|
-
return { ok: true, phase: "development_stopped", installation_id: id };
|
|
1562
|
-
} finally {
|
|
1563
|
-
for (const relay of relays) relay.socket.close();
|
|
1564
|
-
for (const child of children) child.kill("SIGTERM");
|
|
1565
|
-
}
|
|
1513
|
+
if (parsed.command === "dev" && flag(parsed, "apply") === "true") await applyDraft(parsed, { apiKey, client });
|
|
1514
|
+
const installation = await resolveInstallation(input2, client);
|
|
1515
|
+
return servePackageRelay({
|
|
1516
|
+
input: input2,
|
|
1517
|
+
client,
|
|
1518
|
+
installation,
|
|
1519
|
+
declared,
|
|
1520
|
+
target: parsed.command === "dev" ? "draft" : "published",
|
|
1521
|
+
artifactKey: flag(parsed, "artifact"),
|
|
1522
|
+
clientId: flag(parsed, "client-id"),
|
|
1523
|
+
runtimePrincipalId: flag(parsed, "principal")
|
|
1524
|
+
});
|
|
1566
1525
|
}
|
|
1567
1526
|
if (parsed.command === "init") {
|
|
1568
1527
|
const directory = resolve3(parsed.positionals[0] || ".");
|
|
@@ -1602,7 +1561,7 @@ async function execute(parsed) {
|
|
|
1602
1561
|
if (!input2) throw new Error("pack requires a package directory");
|
|
1603
1562
|
const data = await packPackage(input2);
|
|
1604
1563
|
const output = resolve3(flag(parsed, "output") || `${basename2(resolve3(input2))}.agents24.zip`);
|
|
1605
|
-
await
|
|
1564
|
+
await writeFile5(output, data);
|
|
1606
1565
|
return { ok: true, output, bytes: data.byteLength };
|
|
1607
1566
|
}
|
|
1608
1567
|
if (parsed.command === "export") {
|
|
@@ -1619,7 +1578,7 @@ async function execute(parsed) {
|
|
|
1619
1578
|
const request = { selectors };
|
|
1620
1579
|
const archive = await (await createRemoteClient()).resourcePackages.exportPackage(request);
|
|
1621
1580
|
const output = resolve3(flag(parsed, "output") || archive.filename);
|
|
1622
|
-
await
|
|
1581
|
+
await writeFile5(output, archive.data);
|
|
1623
1582
|
return { ok: true, output, bytes: archive.data.byteLength };
|
|
1624
1583
|
}
|
|
1625
1584
|
if (parsed.command === "preview" || parsed.command === "import") {
|