@agents24/cli 0.3.14 → 0.3.16
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 +8 -8
- package/dist/{chunk-GFT6T7PO.js → chunk-3MGYJNQL.js} +1 -1
- package/dist/{chunk-GFT6T7PO.js.map → chunk-3MGYJNQL.js.map} +1 -1
- package/dist/cli.js +403 -26
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +15 -0
- package/dist/index.js +1 -1
- package/generated/schemas/resource-package/2.0/agent.schema.json +12 -0
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
assertImportAllowed,
|
|
4
|
+
createPackageId,
|
|
4
5
|
createRemoteClient,
|
|
5
6
|
forkPackage,
|
|
6
7
|
initializePackage,
|
|
@@ -11,23 +12,24 @@ import {
|
|
|
11
12
|
replacePackageFiles,
|
|
12
13
|
shouldPromptForDependency,
|
|
13
14
|
validatePackage
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-3MGYJNQL.js";
|
|
15
16
|
|
|
16
17
|
// src/cli.ts
|
|
17
18
|
import { basename as basename2, dirname, join as join3, resolve as resolve3 } from "path";
|
|
18
|
-
import { chmod as chmod2, readFile as
|
|
19
|
+
import { chmod as chmod2, readFile as readFile4, writeFile as writeFile4 } from "fs/promises";
|
|
19
20
|
import { createInterface as createInterface3 } from "readline/promises";
|
|
20
|
-
import { createHash as
|
|
21
|
+
import { createHash as createHash3 } from "crypto";
|
|
21
22
|
import { spawn } from "child_process";
|
|
22
23
|
import { isCancel, password, select, text } from "@clack/prompts";
|
|
24
|
+
import { parse as parseYaml3 } from "yaml";
|
|
23
25
|
|
|
24
26
|
// src/cli-arguments.ts
|
|
25
|
-
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["json", "remote", "yes", "allow-incomplete", "no-write-env", "prune", "apply"]);
|
|
26
|
-
var LIFECYCLE_COMMANDS = /* @__PURE__ */ new Set(["prepare", "plan", "apply", "pull", "dev", "publish", "setup", "status", "link", "resources", "fork"]);
|
|
27
|
+
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set(["json", "remote", "yes", "allow-incomplete", "no-write-env", "prune", "apply", "wait", "replace", "fix-dependencies"]);
|
|
28
|
+
var LIFECYCLE_COMMANDS = /* @__PURE__ */ new Set(["prepare", "plan", "apply", "pull", "dev", "publish", "setup", "status", "link", "resources", "fork", "artifact"]);
|
|
27
29
|
function parseArguments(argv) {
|
|
28
30
|
const lifecycle = LIFECYCLE_COMMANDS.has(argv[0]);
|
|
29
31
|
if (!lifecycle && (argv[0] !== "package" || !argv[1])) {
|
|
30
|
-
throw new Error("Usage: agents24 <prepare|plan|apply|pull|dev|publish|setup|status|link|resources|fork> | agents24 package <init|validate|pack|export|preview|import>");
|
|
32
|
+
throw new Error("Usage: agents24 <prepare|plan|apply|pull|dev|publish|setup|status|link|resources|fork> | agents24 package <init|validate|pack|export|preview|import> | agents24 artifact <init|pull|status|diff|push|build|test>");
|
|
31
33
|
}
|
|
32
34
|
const flags = /* @__PURE__ */ new Map();
|
|
33
35
|
const positionals = [];
|
|
@@ -114,7 +116,9 @@ function failurePayload(error) {
|
|
|
114
116
|
...typeof record.status === "number" ? { status: record.status } : {},
|
|
115
117
|
...error && typeof error === "object" && "phase" in error ? { phase: error.phase } : {},
|
|
116
118
|
...error && typeof error === "object" && "imported" in error ? { import_result: error.imported } : {},
|
|
117
|
-
...diagnosticList ? { diagnostics: diagnosticList } : {}
|
|
119
|
+
...diagnosticList ? { diagnostics: diagnosticList } : {},
|
|
120
|
+
...code === "WORKING_DRAFT_CONFLICT" && record.current_draft ? { current_draft: record.current_draft } : {},
|
|
121
|
+
...code === "WORKING_DRAFT_CONFLICT" && typeof record.diff === "string" ? { diff: record.diff } : {}
|
|
118
122
|
};
|
|
119
123
|
}
|
|
120
124
|
function writeResult(result, parsed) {
|
|
@@ -408,9 +412,9 @@ async function developmentArtifacts(input) {
|
|
|
408
412
|
const requiredSecrets = requires.secrets && typeof requires.secrets === "object" ? requires.secrets : {};
|
|
409
413
|
const result = [];
|
|
410
414
|
for (const resource of resources) {
|
|
411
|
-
const
|
|
412
|
-
if (!/^artifacts\/[a-z0-9][a-z0-9-]*\/artifact\.yaml$/.test(
|
|
413
|
-
const sourceText = files.get(
|
|
415
|
+
const path2 = String(resource.path || "");
|
|
416
|
+
if (!/^artifacts\/[a-z0-9][a-z0-9-]*\/artifact\.yaml$/.test(path2)) continue;
|
|
417
|
+
const sourceText = files.get(path2);
|
|
414
418
|
if (!sourceText) continue;
|
|
415
419
|
const source = parseYaml2(sourceText);
|
|
416
420
|
if (source.execution_target !== "self_hosted") continue;
|
|
@@ -581,6 +585,7 @@ var commands = {
|
|
|
581
585
|
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>'" },
|
|
582
586
|
resources: { args: "", summary: "List candidate resources for external requirements.", flags: "--kind <kind> --query <text> --limit <number>", example: "agents24 resources --kind tool --query Search --json" },
|
|
583
587
|
dev: { args: "<directory>", summary: "Run the local Remote Artifact development relay.", flags: "--artifact <stable-key> --apply --yes", example: "agents24 dev ./agents24 --artifact workspace --apply" },
|
|
588
|
+
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" },
|
|
584
589
|
fork: { args: "<source> <target>", summary: "Copy a package with a new installation identity.", flags: "--name <name>", example: "agents24 fork ./agents24 ./copy --name copy" },
|
|
585
590
|
"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" },
|
|
586
591
|
"package validate": { args: "<directory|archive.zip>", summary: "Validate authored package source, optionally against the backend.", flags: "--remote", example: "agents24 package validate ./agents24 --json" },
|
|
@@ -617,6 +622,342 @@ Example:
|
|
|
617
622
|
`;
|
|
618
623
|
}
|
|
619
624
|
|
|
625
|
+
// src/cli-hosted-artifacts.ts
|
|
626
|
+
import { createHash as createHash2 } from "crypto";
|
|
627
|
+
import { mkdir, readFile as readFile3, readdir, writeFile as writeFile3 } from "fs/promises";
|
|
628
|
+
import path from "path";
|
|
629
|
+
import { parse, stringify } from "yaml";
|
|
630
|
+
var stateName = "hosted-artifacts.json";
|
|
631
|
+
function slug(value) {
|
|
632
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64) || "artifact";
|
|
633
|
+
}
|
|
634
|
+
function hash(value) {
|
|
635
|
+
return createHash2("sha256").update(JSON.stringify(value)).digest("hex");
|
|
636
|
+
}
|
|
637
|
+
function object(value) {
|
|
638
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
639
|
+
}
|
|
640
|
+
function sourceFiles(local) {
|
|
641
|
+
const prefix = local.artifactPath.replace(/artifact\.yaml$/, "src/");
|
|
642
|
+
return [...local.files].filter(([name]) => name.startsWith(prefix)).map(([name, content]) => ({ path: name.slice(prefix.length), content })).sort((a, b) => a.path.localeCompare(b.path));
|
|
643
|
+
}
|
|
644
|
+
function sourceDiff(local, remote) {
|
|
645
|
+
const localFiles = new Map(sourceFiles(local).map((item) => [item.path, item.content]));
|
|
646
|
+
const raw = object(remote.draft_snapshot);
|
|
647
|
+
const remoteFiles = new Map((Array.isArray(raw.source_files) ? raw.source_files : []).map((item) => {
|
|
648
|
+
const file = object(item);
|
|
649
|
+
return [String(file.path || ""), String(file.content || "")];
|
|
650
|
+
}));
|
|
651
|
+
const lines = [];
|
|
652
|
+
for (const name of [.../* @__PURE__ */ new Set([...localFiles.keys(), ...remoteFiles.keys()])].sort()) {
|
|
653
|
+
const before = remoteFiles.get(name);
|
|
654
|
+
const after = localFiles.get(name);
|
|
655
|
+
if (before === after) continue;
|
|
656
|
+
lines.push(`--- remote/${name}`, `+++ local/${name}`);
|
|
657
|
+
if (before !== void 0) lines.push(...before.split("\n").map((line) => `-${line}`));
|
|
658
|
+
if (after !== void 0) lines.push(...after.split("\n").map((line) => `+${line}`));
|
|
659
|
+
}
|
|
660
|
+
return lines.join("\n");
|
|
661
|
+
}
|
|
662
|
+
function snapshot(local, credentialBindings = {}) {
|
|
663
|
+
const runtime = object(local.source.runtime);
|
|
664
|
+
const entry = String(runtime.entry || "src/main.py").replace(/^src\//, "");
|
|
665
|
+
return {
|
|
666
|
+
display_name: String(local.source.name || local.key),
|
|
667
|
+
description: String(local.source.description || ""),
|
|
668
|
+
language: String(runtime.language || "python"),
|
|
669
|
+
source_files: sourceFiles(local),
|
|
670
|
+
entry_module_path: entry,
|
|
671
|
+
dependencies: (Array.isArray(runtime.dependencies) ? runtime.dependencies : []).join(", "),
|
|
672
|
+
runtime_target: "cloudflare_workers",
|
|
673
|
+
capabilities: JSON.stringify(object(local.source.capabilities)),
|
|
674
|
+
credential_bindings: credentialBindings
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
function comparable(value) {
|
|
678
|
+
const raw = value.draft_snapshot ? object(value.draft_snapshot) : value;
|
|
679
|
+
const dependencies = Array.isArray(raw.dependencies) ? raw.dependencies : String(raw.dependencies || "").split(",").map((part) => part.trim()).filter(Boolean);
|
|
680
|
+
const capabilities = typeof raw.capabilities === "string" ? JSON.parse(raw.capabilities || "{}") : object(raw.capabilities);
|
|
681
|
+
const files = Array.isArray(raw.source_files) ? raw.source_files.map((entry) => object(entry)) : [];
|
|
682
|
+
return {
|
|
683
|
+
display_name: String(raw.display_name || ""),
|
|
684
|
+
description: String(raw.description || ""),
|
|
685
|
+
language: String(raw.language || "python"),
|
|
686
|
+
entry_module_path: String(raw.entry_module_path || "main.py"),
|
|
687
|
+
dependencies,
|
|
688
|
+
runtime_target: String(raw.runtime_target || "cloudflare_workers"),
|
|
689
|
+
capabilities,
|
|
690
|
+
source_files: files.map((entry) => ({ path: String(entry.path || ""), content: String(entry.content || "") })).sort((a, b) => a.path.localeCompare(b.path)),
|
|
691
|
+
credential_bindings: object(raw.credential_bindings)
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
function portableDraft(remote) {
|
|
695
|
+
const raw = object(remote.draft_snapshot);
|
|
696
|
+
const bindings = { ...object(raw.credential_bindings) };
|
|
697
|
+
const legacy = (Array.isArray(remote.legacy_credential_refs) ? remote.legacy_credential_refs : []).map(object);
|
|
698
|
+
const aliases = new Map(legacy.map((item) => [String(item.legacy_credential_id).toLowerCase(), String(item.key)]));
|
|
699
|
+
for (const item of legacy) bindings[String(item.key)] = item.credential_id ? String(item.credential_id) : null;
|
|
700
|
+
const source = (Array.isArray(raw.source_files) ? raw.source_files : []).map((entry) => {
|
|
701
|
+
const file = object(entry);
|
|
702
|
+
return { ...file, content: String(file.content || "").replace(/@\{(?:[^{}|]*\|)?([0-9a-fA-F-]{36})\}/g, (full, id) => aliases.has(id.toLowerCase()) ? `@{credentials.${aliases.get(id.toLowerCase())}}` : full) };
|
|
703
|
+
});
|
|
704
|
+
return { draft: { ...raw, source_files: source }, bindings };
|
|
705
|
+
}
|
|
706
|
+
async function localArtifact(input, selected) {
|
|
707
|
+
const root = path.resolve(input);
|
|
708
|
+
const files = await loadPackageFiles(root);
|
|
709
|
+
const manifest = object(parse(files.get("agents24.yaml") || ""));
|
|
710
|
+
const declarations = Array.isArray(manifest.resources) ? manifest.resources.map(object) : [];
|
|
711
|
+
const candidates = declarations.filter((entry) => {
|
|
712
|
+
const artifactPath2 = String(entry.path || "");
|
|
713
|
+
if (!/^artifacts\/[a-z0-9][a-z0-9-]*\/artifact\.yaml$/.test(artifactPath2)) return false;
|
|
714
|
+
const source = object(parse(files.get(artifactPath2) || ""));
|
|
715
|
+
return source.execution_target === "platform_hosted";
|
|
716
|
+
});
|
|
717
|
+
const chosen = selected ? candidates.find((entry) => entry.key === selected) : candidates.length === 1 ? candidates[0] : void 0;
|
|
718
|
+
if (!chosen) throw new Error(selected ? `Hosted Artifact ${selected} was not found` : "Use --artifact <key> to select one Hosted Artifact");
|
|
719
|
+
const artifactPath = String(chosen.path);
|
|
720
|
+
return { root, files, manifest, key: String(chosen.key), artifactPath, source: object(parse(files.get(artifactPath) || "")) };
|
|
721
|
+
}
|
|
722
|
+
async function stateFile(root) {
|
|
723
|
+
try {
|
|
724
|
+
return object(JSON.parse(await readFile3(path.join(root, ".agents24", stateName), "utf8")));
|
|
725
|
+
} catch (error) {
|
|
726
|
+
if (error.code === "ENOENT") return {};
|
|
727
|
+
throw error;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
async function saveState(root, key, state) {
|
|
731
|
+
const directory = path.join(root, ".agents24");
|
|
732
|
+
await mkdir(directory, { recursive: true });
|
|
733
|
+
const current = await stateFile(root);
|
|
734
|
+
current[key] = state;
|
|
735
|
+
await writeFile3(path.join(directory, stateName), JSON.stringify(current, null, 2) + "\n", { mode: 384 });
|
|
736
|
+
}
|
|
737
|
+
async function installationArtifact(client, local) {
|
|
738
|
+
const packageId = String(local.manifest.package_id || "");
|
|
739
|
+
if (!packageId) return null;
|
|
740
|
+
let installation;
|
|
741
|
+
try {
|
|
742
|
+
installation = await client.resourceInstallations.getByPackageId(packageId);
|
|
743
|
+
} catch (error) {
|
|
744
|
+
if (object(error).status === 404) return null;
|
|
745
|
+
throw error;
|
|
746
|
+
}
|
|
747
|
+
const binding = (Array.isArray(installation.bindings) ? installation.bindings : []).map(object).find((item) => item.resource_key === local.key && item.kind === "artifact");
|
|
748
|
+
return binding ? String(binding.resource_id || "") : null;
|
|
749
|
+
}
|
|
750
|
+
async function bindPackage(client, local, artifactId) {
|
|
751
|
+
const data = await packPackage(local.root);
|
|
752
|
+
const plan = await client.resourceInstallations.plan(packageUpload(data, local.root));
|
|
753
|
+
const packageId = String(local.manifest.package_id || "");
|
|
754
|
+
const packageName = String(local.manifest.name || local.key);
|
|
755
|
+
const installation = plan.installation_id ? await client.resourceInstallations.get(String(plan.installation_id)) : await client.resourceInstallations.create({ package_id: packageId, package_name: packageName, operation_id: String(plan.operation_id) });
|
|
756
|
+
await client.resourceInstallations.link(String(installation.id), { resource_key: local.key, resource_id: artifactId });
|
|
757
|
+
}
|
|
758
|
+
async function writeNewPackage(directory, name, draft, requestedLanguage) {
|
|
759
|
+
const root = path.resolve(directory);
|
|
760
|
+
try {
|
|
761
|
+
if ((await readdir(root)).length) throw new Error("Target directory must be empty");
|
|
762
|
+
} catch (error) {
|
|
763
|
+
if (error.code !== "ENOENT") throw error;
|
|
764
|
+
}
|
|
765
|
+
const key = slug(name);
|
|
766
|
+
const language = String(draft?.language || requestedLanguage || "python");
|
|
767
|
+
if (language !== "python" && language !== "javascript") throw new Error("--language must be python or javascript");
|
|
768
|
+
const files = Array.isArray(draft?.source_files) ? draft.source_files.map(object) : [];
|
|
769
|
+
const entry = String(draft?.entry_module_path || (language === "javascript" ? "main.js" : "main.py")).replace(/^src\//, "");
|
|
770
|
+
const source = {
|
|
771
|
+
schema: "agents24.artifact/v1",
|
|
772
|
+
name,
|
|
773
|
+
execution_target: "platform_hosted",
|
|
774
|
+
runtime: { language, entry, dependencies: Array.isArray(draft?.dependencies) ? draft.dependencies : String(draft?.dependencies || "").split(",").map((part) => part.trim()).filter(Boolean) },
|
|
775
|
+
capabilities: typeof draft?.capabilities === "string" ? JSON.parse(draft.capabilities || "{}") : object(draft?.capabilities)
|
|
776
|
+
};
|
|
777
|
+
const manifest = { schema: "agents24.package/v2", package_id: createPackageId(), name: key, resources: [{ key, path: `artifacts/${key}/artifact.yaml` }] };
|
|
778
|
+
await mkdir(path.join(root, "artifacts", key, "src"), { recursive: true });
|
|
779
|
+
await writeFile3(path.join(root, "agents24.yaml"), stringify(manifest), { flag: "wx" });
|
|
780
|
+
await writeFile3(path.join(root, "artifacts", key, "artifact.yaml"), stringify(source), { flag: "wx" });
|
|
781
|
+
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';
|
|
782
|
+
for (const item of files.length ? files : [{ path: entry, content: initial }]) {
|
|
783
|
+
const relative = String(item.path || "").replace(/^src\//, "");
|
|
784
|
+
if (!relative || relative.startsWith("/") || relative.split("/").includes("..")) throw new Error("Artifact source has an unsafe path");
|
|
785
|
+
const destination = path.join(root, "artifacts", key, "src", relative);
|
|
786
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
787
|
+
await writeFile3(destination, String(item.content || ""), { flag: "wx" });
|
|
788
|
+
}
|
|
789
|
+
return localArtifact(root, key);
|
|
790
|
+
}
|
|
791
|
+
async function remoteDraft(client, id) {
|
|
792
|
+
const artifact = await client.hostedArtifacts.get(id);
|
|
793
|
+
if (artifact.execution_target !== "platform_hosted") throw new Error("This command accepts Hosted Artifacts only; Remote development uses agents24 dev");
|
|
794
|
+
return client.hostedArtifacts.draft(id);
|
|
795
|
+
}
|
|
796
|
+
async function resolvedId(client, local) {
|
|
797
|
+
return (await stateFile(local.root))[local.key]?.artifact_id || await installationArtifact(client, local);
|
|
798
|
+
}
|
|
799
|
+
async function hostedArtifactCommand(parsed, client) {
|
|
800
|
+
const [action, input = "."] = parsed.positionals;
|
|
801
|
+
if (action === "init") {
|
|
802
|
+
const directory = path.resolve(input);
|
|
803
|
+
const local2 = await writeNewPackage(directory, flag(parsed, "name") || path.basename(directory), void 0, flag(parsed, "language"));
|
|
804
|
+
return { ok: true, directory, package_id: local2.manifest.package_id, artifact_key: local2.key };
|
|
805
|
+
}
|
|
806
|
+
if (!client) throw new Error("AGENTS24_API_KEY is required for Hosted Artifact commands");
|
|
807
|
+
if (action === "pull" && flag(parsed, "id")) {
|
|
808
|
+
const id2 = String(flag(parsed, "id"));
|
|
809
|
+
const artifact = await client.hostedArtifacts.get(id2);
|
|
810
|
+
const draft = await remoteDraft(client, id2);
|
|
811
|
+
const portable2 = portableDraft(draft);
|
|
812
|
+
const root = path.resolve(flag(parsed, "into") || input);
|
|
813
|
+
const local2 = await writeNewPackage(root, String(artifact.display_name || "Artifact"), portable2.draft);
|
|
814
|
+
await bindPackage(client, local2, id2);
|
|
815
|
+
await saveState(root, local2.key, { artifact_id: id2, draft_version: Number(draft.draft_version), draft_hash: String(draft.draft_hash), local_hash: hash(comparable(snapshot(local2, portable2.bindings))), credential_bindings: portable2.bindings });
|
|
816
|
+
return { ok: true, directory: root, artifact_id: id2, artifact_key: local2.key, draft_version: draft.draft_version, credential_refs: draft.credential_refs };
|
|
817
|
+
}
|
|
818
|
+
let local = await localArtifact(input, flag(parsed, "artifact"));
|
|
819
|
+
const id = await resolvedId(client, local);
|
|
820
|
+
if (!id && action !== "push") throw new Error("This Hosted Artifact is not linked; run agents24 artifact push first");
|
|
821
|
+
if (action === "push") {
|
|
822
|
+
const validation = await validatePackage(local.root);
|
|
823
|
+
if (!validation.valid) throw Object.assign(new Error("Resource package is invalid"), { diagnostics: validation.diagnostics });
|
|
824
|
+
const runtime = object(local.source.runtime);
|
|
825
|
+
const analysis = await client.hostedArtifacts.analyzeDependencies({ language: runtime.language || "python", source_files: sourceFiles(local), dependencies: Array.isArray(runtime.dependencies) ? runtime.dependencies : [] });
|
|
826
|
+
const unresolved = (Array.isArray(analysis.rows) ? analysis.rows : []).map(object).filter((row) => row.needs_declaration === true);
|
|
827
|
+
if (unresolved.length && flag(parsed, "fix-dependencies") === "true" && unresolved.every((row) => typeof row.suggested_spec === "string" && row.suggested_spec)) {
|
|
828
|
+
const additions = unresolved.map((row) => String(row.suggested_spec));
|
|
829
|
+
const source = { ...local.source, runtime: { ...runtime, dependencies: [...Array.isArray(runtime.dependencies) ? runtime.dependencies : [], ...additions] } };
|
|
830
|
+
await writeFile3(path.join(local.root, local.artifactPath), stringify(source));
|
|
831
|
+
local = await localArtifact(local.root, local.key);
|
|
832
|
+
const repaired = await validatePackage(local.root);
|
|
833
|
+
if (!repaired.valid) throw Object.assign(new Error("Dependency repair produced an invalid Resource Package"), { diagnostics: repaired.diagnostics });
|
|
834
|
+
} else if (unresolved.length) {
|
|
835
|
+
throw Object.assign(new Error("Artifact imports undeclared dependencies; add them to runtime.dependencies before pushing"), {
|
|
836
|
+
code: "ARTIFACT_MISSING_DEPENDENCIES",
|
|
837
|
+
diagnostics: unresolved.map((row) => ({ severity: "error", code: "ARTIFACT_MISSING_DEPENDENCY", path: local.artifactPath, message: row.suggested_spec ? `Import ${String(row.name)} requires ${String(row.suggested_spec)}` : `Import ${String(row.name)} needs an explicit package declaration` }))
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
const savedState = (await stateFile(local.root))[local.key];
|
|
841
|
+
const bindings = { ...savedState?.credential_bindings || {} };
|
|
842
|
+
for (const value of parsed.flags.get("bind") || []) {
|
|
843
|
+
const separator = value.indexOf(":");
|
|
844
|
+
const key = value.slice(0, separator);
|
|
845
|
+
const credentialId = value.slice(separator + 1);
|
|
846
|
+
if (separator < 1 || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(key) || !/^[0-9a-fA-F-]{36}$/.test(credentialId)) throw new Error("Use --bind <symbolic-key>:<credential-uuid>");
|
|
847
|
+
bindings[key] = credentialId;
|
|
848
|
+
}
|
|
849
|
+
const localSnapshot = snapshot(local, bindings);
|
|
850
|
+
let artifactId2 = id;
|
|
851
|
+
if (!artifactId2) {
|
|
852
|
+
const created = await client.hostedArtifacts.create({ display_name: localSnapshot.display_name, description: localSnapshot.description, execution_target: "platform_hosted", runtime: { language: localSnapshot.language, source_files: localSnapshot.source_files, entry_module_path: localSnapshot.entry_module_path, dependencies: String(localSnapshot.dependencies).split(",").map((part) => part.trim()).filter(Boolean), runtime_target: "cloudflare_workers" }, capabilities: object(local.source.capabilities) });
|
|
853
|
+
artifactId2 = String(created.id || "");
|
|
854
|
+
if (!artifactId2) throw new Error("Artifact creation returned no identity");
|
|
855
|
+
await bindPackage(client, local, artifactId2);
|
|
856
|
+
}
|
|
857
|
+
const remote2 = await remoteDraft(client, artifactId2);
|
|
858
|
+
const base = savedState;
|
|
859
|
+
const remotePortable = portableDraft(remote2);
|
|
860
|
+
const diverged = hash(comparable(localSnapshot)) !== hash(comparable({ ...remotePortable.draft, credential_bindings: remotePortable.bindings }));
|
|
861
|
+
if (flag(parsed, "replace") !== "true" && (base && remote2.draft_version !== base.draft_version && hash(comparable({ ...remotePortable.draft, credential_bindings: remotePortable.bindings })) !== base.local_hash || id && !base && diverged)) {
|
|
862
|
+
throw Object.assign(new Error("Hosted draft changed or has no local sync baseline; pull, merge, or explicitly push --replace"), { code: "WORKING_DRAFT_CONFLICT", current_draft: remote2, diff: sourceDiff(local, { draft_snapshot: remotePortable.draft }) });
|
|
863
|
+
}
|
|
864
|
+
let saved = remote2;
|
|
865
|
+
if (hash(comparable(localSnapshot)) !== hash(comparable(remote2))) {
|
|
866
|
+
try {
|
|
867
|
+
saved = await client.hostedArtifacts.saveDraft(artifactId2, localSnapshot, Number(remote2.draft_version));
|
|
868
|
+
} catch (error) {
|
|
869
|
+
if (object(error).status !== 409) throw error;
|
|
870
|
+
const current = await remoteDraft(client, artifactId2);
|
|
871
|
+
throw Object.assign(new Error("Hosted draft changed; pull or compare before pushing"), { code: "WORKING_DRAFT_CONFLICT", current_draft: current, diff: sourceDiff(local, { draft_snapshot: portableDraft(current).draft }) });
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
await saveState(local.root, local.key, { artifact_id: artifactId2, draft_version: Number(saved.draft_version), draft_hash: String(saved.draft_hash), local_hash: hash(comparable(localSnapshot)), credential_bindings: bindings });
|
|
875
|
+
return { ok: true, artifact_id: artifactId2, draft_version: saved.draft_version, draft_hash: saved.draft_hash, credential_refs: saved.credential_refs, built: false };
|
|
876
|
+
}
|
|
877
|
+
const artifactId = String(id);
|
|
878
|
+
const remote = await remoteDraft(client, artifactId);
|
|
879
|
+
const localState = (await stateFile(local.root))[local.key];
|
|
880
|
+
const localHash = hash(comparable(snapshot(local, localState?.credential_bindings || {})));
|
|
881
|
+
const portable = portableDraft(remote);
|
|
882
|
+
const remoteHash = hash(comparable({ ...portable.draft, credential_bindings: portable.bindings }));
|
|
883
|
+
if (action === "status" || action === "diff") {
|
|
884
|
+
const base = localState;
|
|
885
|
+
const localFiles = new Map(sourceFiles(local).map((item) => [item.path, item.content]));
|
|
886
|
+
const remoteFiles = new Map((Array.isArray(portable.draft.source_files) ? portable.draft.source_files : []).map((item) => [String(item.path), String(item.content)]));
|
|
887
|
+
const changes = [.../* @__PURE__ */ new Set([...localFiles.keys(), ...remoteFiles.keys()])].sort().filter((name) => localFiles.get(name) !== remoteFiles.get(name)).map((name) => ({ path: name, change: !remoteFiles.has(name) ? "added" : !localFiles.has(name) ? "removed" : "modified" }));
|
|
888
|
+
if (base && remote.draft_version !== base.draft_version && remoteHash === base.local_hash) {
|
|
889
|
+
await saveState(local.root, local.key, { ...base, draft_version: Number(remote.draft_version), draft_hash: String(remote.draft_hash) });
|
|
890
|
+
}
|
|
891
|
+
return { ok: true, artifact_id: artifactId, artifact_key: local.key, local_changed: localHash !== base?.local_hash, remote_changed: remoteHash !== base?.local_hash, in_sync: localHash === remoteHash, draft_version: remote.draft_version, last_origin: remote.last_origin, credential_refs: remote.credential_refs, changes, ...action === "diff" ? { diff: sourceDiff(local, { draft_snapshot: portable.draft }) } : {} };
|
|
892
|
+
}
|
|
893
|
+
if (action === "pull") {
|
|
894
|
+
const base = (await stateFile(local.root))[local.key];
|
|
895
|
+
if (!base) throw new Error("No local Hosted sync baseline exists; push this package first or adopt into an empty directory with --id and --into");
|
|
896
|
+
if (localHash !== base.local_hash) throw new Error("Local Hosted source changed; commit or merge it before pulling");
|
|
897
|
+
const raw = portable.draft;
|
|
898
|
+
const files = Array.isArray(raw.source_files) ? raw.source_files.map(object) : [];
|
|
899
|
+
const prefix = local.artifactPath.replace(/artifact\.yaml$/, "src/");
|
|
900
|
+
const remotePaths = new Set(files.map((item) => String(item.path)));
|
|
901
|
+
const localPaths = sourceFiles(local).map((item) => item.path);
|
|
902
|
+
if (localPaths.some((name) => !remotePaths.has(name))) throw new Error("Pull would delete local source files; resolve them manually");
|
|
903
|
+
for (const item of files) {
|
|
904
|
+
const relative = String(item.path || "");
|
|
905
|
+
if (!relative || relative.startsWith("/") || relative.split("/").includes("..")) throw new Error("Remote Artifact source has an unsafe path");
|
|
906
|
+
const destination = path.join(local.root, prefix, relative);
|
|
907
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
908
|
+
await writeFile3(destination, String(item.content || ""));
|
|
909
|
+
}
|
|
910
|
+
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) };
|
|
911
|
+
await writeFile3(path.join(local.root, local.artifactPath), stringify(source));
|
|
912
|
+
const refreshed = await localArtifact(local.root, local.key);
|
|
913
|
+
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 });
|
|
914
|
+
return { ok: true, artifact_id: artifactId, draft_version: remote.draft_version, credential_refs: remote.credential_refs };
|
|
915
|
+
}
|
|
916
|
+
if (action === "build") {
|
|
917
|
+
if (localHash !== remoteHash) throw new Error("Local source differs from the managed draft; push before building");
|
|
918
|
+
let build = await client.hostedArtifacts.build(artifactId, { draft_version: Number(remote.draft_version), draft_hash: String(remote.draft_hash), runtime_hash: String(remote.runtime_hash) });
|
|
919
|
+
if (flag(parsed, "wait") === "true") {
|
|
920
|
+
for (let attempt = 0; attempt < 300 && !["ready", "failed"].includes(String(build.status)); attempt += 1) {
|
|
921
|
+
await new Promise((done) => setTimeout(done, 1e3));
|
|
922
|
+
build = await client.hostedArtifacts.buildStatus(artifactId, String(build.id));
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
const timedOut = flag(parsed, "wait") === "true" && !["ready", "failed"].includes(String(build.status));
|
|
926
|
+
return { ok: build.status !== "failed" && !timedOut, artifact_id: artifactId, build, ...timedOut ? { timed_out: true } : {} };
|
|
927
|
+
}
|
|
928
|
+
if (action === "test") {
|
|
929
|
+
const target = flag(parsed, "target") || "draft";
|
|
930
|
+
if (target !== "draft" && target !== "published") throw new Error("--target must be draft or published");
|
|
931
|
+
if (target === "draft" && localHash !== remoteHash) throw new Error("Local source differs from the managed draft; push before testing");
|
|
932
|
+
const exportName = flag(parsed, "export");
|
|
933
|
+
if (!exportName) throw new Error("Managed test requires --export <name>");
|
|
934
|
+
const inputPath = flag(parsed, "input");
|
|
935
|
+
const inputData = inputPath ? JSON.parse(inputPath === "-" ? await new Promise((done) => {
|
|
936
|
+
let value = "";
|
|
937
|
+
process.stdin.setEncoding("utf8");
|
|
938
|
+
process.stdin.on("data", (chunk) => {
|
|
939
|
+
value += chunk;
|
|
940
|
+
});
|
|
941
|
+
process.stdin.on("end", () => done(value));
|
|
942
|
+
}) : await readFile3(inputPath, "utf8")) : {};
|
|
943
|
+
const configPath = flag(parsed, "config");
|
|
944
|
+
const config = configPath ? JSON.parse(await readFile3(configPath, "utf8")) : {};
|
|
945
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) throw new Error("--config must contain a JSON object");
|
|
946
|
+
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 } : {} });
|
|
947
|
+
if (flag(parsed, "wait") !== "true") return { ok: !["failed", "cancelled"].includes(String(run2.status)), artifact_id: artifactId, run_id: run2.run_id, status: run2.status };
|
|
948
|
+
let completed = run2;
|
|
949
|
+
for (let attempt = 0; attempt < 300; attempt += 1) {
|
|
950
|
+
completed = await client.hostedArtifacts.run(String(run2.run_id));
|
|
951
|
+
if (["completed", "failed", "cancelled"].includes(String(completed.status))) break;
|
|
952
|
+
await new Promise((done) => setTimeout(done, 1e3));
|
|
953
|
+
}
|
|
954
|
+
const status = String(completed.status);
|
|
955
|
+
const timedOut = !["completed", "failed", "cancelled"].includes(status);
|
|
956
|
+
return { ok: status === "completed", artifact_id: artifactId, run_id: run2.run_id, status, result: completed.result_payload ?? null, failure: completed.failure ?? null, ...timedOut ? { timed_out: true } : {} };
|
|
957
|
+
}
|
|
958
|
+
throw new Error("Usage: agents24 artifact <init|pull|status|diff|push|build|test>");
|
|
959
|
+
}
|
|
960
|
+
|
|
620
961
|
// src/cli.ts
|
|
621
962
|
var DEFAULT_API_BASE_URL2 = "https://api.agents24.dev";
|
|
622
963
|
var DEFAULT_LOCAL_CLIENT_ORIGINS = ["http://localhost:5173", "http://127.0.0.1:5173"];
|
|
@@ -665,7 +1006,7 @@ async function packedValidatedPackage(parsed) {
|
|
|
665
1006
|
return { data, filename: `${basename2(resolve3(input))}.agents24.zip` };
|
|
666
1007
|
}
|
|
667
1008
|
function importKey(packageHash, map) {
|
|
668
|
-
return `import-${
|
|
1009
|
+
return `import-${createHash3("sha256").update(canonicalJson({ package_hash: packageHash, mappings: map })).digest("hex").slice(0, 40)}`;
|
|
669
1010
|
}
|
|
670
1011
|
function interactive(parsed) {
|
|
671
1012
|
return flag(parsed, "yes") !== "true" && Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
@@ -690,9 +1031,9 @@ async function loadPackageLifecycleEnvironment(input) {
|
|
|
690
1031
|
if (!input) return;
|
|
691
1032
|
const directory = await packageDirectory(input);
|
|
692
1033
|
if (!directory) return;
|
|
693
|
-
for (const
|
|
1034
|
+
for (const path2 of [join3(dirname(directory), ".env.local"), join3(directory, ".env.local")]) {
|
|
694
1035
|
try {
|
|
695
|
-
const values2 = parseEnv(await
|
|
1036
|
+
const values2 = parseEnv(await readFile4(path2, "utf8"));
|
|
696
1037
|
for (const [name, value] of Object.entries(values2)) {
|
|
697
1038
|
if (!process.env[name]) process.env[name] = value;
|
|
698
1039
|
}
|
|
@@ -728,7 +1069,7 @@ function clientAppBaseUrl(environment = process.env) {
|
|
|
728
1069
|
async function appInfoAt(directory, explicit) {
|
|
729
1070
|
const target = resolve3(directory);
|
|
730
1071
|
try {
|
|
731
|
-
const manifest = JSON.parse(await
|
|
1072
|
+
const manifest = JSON.parse(await readFile4(join3(target, "package.json"), "utf8"));
|
|
732
1073
|
const metadata = manifest.agents24 && typeof manifest.agents24 === "object" ? manifest.agents24 : {};
|
|
733
1074
|
const integration = String(metadata.integration || "");
|
|
734
1075
|
if (integration !== "client-deployment" && integration !== "bff") {
|
|
@@ -791,13 +1132,13 @@ async function clientDeployment(parsed, client, agent, app) {
|
|
|
791
1132
|
allowed_origins: origins,
|
|
792
1133
|
...oidcRaw ? { oidc: JSON.parse(oidcRaw) } : {}
|
|
793
1134
|
};
|
|
794
|
-
return client.clientDeployments.create(request, { idempotencyKey: `deploy-${
|
|
1135
|
+
return client.clientDeployments.create(request, { idempotencyKey: `deploy-${createHash3("sha256").update(canonicalJson(request)).digest("hex").slice(0, 40)}` });
|
|
795
1136
|
}
|
|
796
1137
|
async function updateEnvFile(app, values2) {
|
|
797
1138
|
const target = join3(app.directory, ".env.local");
|
|
798
1139
|
let content = "";
|
|
799
1140
|
try {
|
|
800
|
-
content = await
|
|
1141
|
+
content = await readFile4(target, "utf8");
|
|
801
1142
|
} catch (error) {
|
|
802
1143
|
if (error.code !== "ENOENT") throw error;
|
|
803
1144
|
}
|
|
@@ -813,13 +1154,17 @@ async function updateEnvFile(app, values2) {
|
|
|
813
1154
|
}) : `${next}${next && !next.endsWith("\n") ? "\n" : ""}${line}
|
|
814
1155
|
`;
|
|
815
1156
|
}
|
|
816
|
-
await
|
|
1157
|
+
await writeFile4(target, next, { mode: 384 });
|
|
817
1158
|
await chmod2(target, 384);
|
|
818
1159
|
return target;
|
|
819
1160
|
}
|
|
820
|
-
function
|
|
1161
|
+
function optionalPrimaryAgentAlias(applied) {
|
|
821
1162
|
const aliases = Array.isArray(applied.agent.aliases) ? applied.agent.aliases : [];
|
|
822
1163
|
const agentAlias = String(aliases[0] || applied.result.primary_agent_alias || "");
|
|
1164
|
+
return agentAlias || null;
|
|
1165
|
+
}
|
|
1166
|
+
function primaryAgentAlias(applied) {
|
|
1167
|
+
const agentAlias = optionalPrimaryAgentAlias(applied);
|
|
823
1168
|
if (!agentAlias) throw new Error("Apply completed without a primary Agent alias");
|
|
824
1169
|
return agentAlias;
|
|
825
1170
|
}
|
|
@@ -935,6 +1280,12 @@ async function publishDraft(parsed, applied) {
|
|
|
935
1280
|
return { publication, installationId: id };
|
|
936
1281
|
}
|
|
937
1282
|
async function execute(parsed) {
|
|
1283
|
+
if (parsed.command === "artifact") {
|
|
1284
|
+
if (parsed.positionals[0] === "init") return hostedArtifactCommand(parsed);
|
|
1285
|
+
const apiKey = await apiKeyForLifecycle({ ...parsed, positionals: parsed.positionals.slice(1) });
|
|
1286
|
+
const client = await createRemoteClient({ ...process.env, AGENTS24_API_KEY: apiKey });
|
|
1287
|
+
return hostedArtifactCommand(parsed, client);
|
|
1288
|
+
}
|
|
938
1289
|
if (parsed.command === "fork") {
|
|
939
1290
|
const [source, target] = parsed.positionals;
|
|
940
1291
|
if (!source || !target) throw new Error("Usage: agents24 fork <source> <target> [--name <name>]");
|
|
@@ -1019,21 +1370,31 @@ async function execute(parsed) {
|
|
|
1019
1370
|
const resourceKey = assignment.slice(0, separator);
|
|
1020
1371
|
const resourceId = assignment.slice(separator + 1);
|
|
1021
1372
|
linked.push(await client.resourceInstallations.link(id, { resource_key: resourceKey, resource_id: resourceId }, {
|
|
1022
|
-
idempotencyKey: `link-${
|
|
1373
|
+
idempotencyKey: `link-${createHash3("sha256").update(`${id}:${assignment}`).digest("hex").slice(0, 40)}`
|
|
1023
1374
|
}));
|
|
1024
1375
|
}
|
|
1025
1376
|
return { ok: true, installation_id: id, linked };
|
|
1026
1377
|
}
|
|
1027
1378
|
if (parsed.command === "apply") {
|
|
1028
1379
|
const app = await resolveApp(parsed);
|
|
1029
|
-
const
|
|
1380
|
+
const packageInput = parsed.positionals[0];
|
|
1381
|
+
const packageFiles = packageInput ? await loadPackageFiles(packageInput) : void 0;
|
|
1382
|
+
const packageManifest = packageFiles ? parseYaml3(String(packageFiles.get("agents24.yaml") || "")) : void 0;
|
|
1383
|
+
const declarations = Array.isArray(packageManifest?.resources) ? packageManifest.resources : [];
|
|
1384
|
+
const hostedOnly = declarations.length > 0 && declarations.every((item) => {
|
|
1385
|
+
const artifactPath = String(item.path || "");
|
|
1386
|
+
if (!artifactPath.startsWith("artifacts/") || !artifactPath.endsWith("/artifact.yaml")) return false;
|
|
1387
|
+
const source = parseYaml3(String(packageFiles?.get(artifactPath) || ""));
|
|
1388
|
+
return source.execution_target === "platform_hosted";
|
|
1389
|
+
});
|
|
1390
|
+
const integration = hostedOnly && !flag(parsed, "integration") ? "publish-only" : app || flag(parsed, "integration") ? await resolveInstallMode(parsed, app) : "publish-only";
|
|
1030
1391
|
const applied = await applyDraft(parsed, { integrationMode: integration });
|
|
1031
1392
|
const envFile = app && integration === "bff" && flag(parsed, "no-write-env") !== "true" ? await updateEnvFile(app, bffApplicationValues(applied)) : void 0;
|
|
1032
1393
|
return {
|
|
1033
1394
|
ok: true,
|
|
1034
1395
|
phase: "draft_applied",
|
|
1035
1396
|
installation_id: applied.installationId,
|
|
1036
|
-
agent_alias:
|
|
1397
|
+
...optionalPrimaryAgentAlias(applied) ? { agent_alias: optionalPrimaryAgentAlias(applied) } : {},
|
|
1037
1398
|
operation_id: applied.operation.operation_id,
|
|
1038
1399
|
operation_status: applied.operation.status,
|
|
1039
1400
|
...envFile ? { env_file: envFile } : {}
|
|
@@ -1104,7 +1465,7 @@ async function execute(parsed) {
|
|
|
1104
1465
|
const configuredSecrets = await secretValues(input);
|
|
1105
1466
|
if (Object.keys(configuredSecrets).length) await client.resourceInstallations.configureSecrets(id, { secrets: configuredSecrets });
|
|
1106
1467
|
const directory = await packageDirectory(input);
|
|
1107
|
-
const localEnv = directory ? parseEnv(await
|
|
1468
|
+
const localEnv = directory ? parseEnv(await readFile4(join3(directory, ".env.local"), "utf8")) : {};
|
|
1108
1469
|
const children = [];
|
|
1109
1470
|
const relays = [];
|
|
1110
1471
|
try {
|
|
@@ -1168,18 +1529,34 @@ async function execute(parsed) {
|
|
|
1168
1529
|
if (!input) throw new Error("validate requires a package directory or ZIP");
|
|
1169
1530
|
const local = await validatePackage(input);
|
|
1170
1531
|
let remote;
|
|
1532
|
+
const hostedDependencyDiagnostics = [];
|
|
1171
1533
|
if (flag(parsed, "remote") === "true" && local.valid) {
|
|
1534
|
+
const client = await createRemoteClient();
|
|
1172
1535
|
const data = await packPackage(input);
|
|
1173
|
-
remote = await
|
|
1536
|
+
remote = await client.resourcePackages.validatePackage(packageUpload(data, input));
|
|
1537
|
+
const manifest = parseYaml3(String(local.files.get("agents24.yaml") || ""));
|
|
1538
|
+
for (const declaration of Array.isArray(manifest.resources) ? manifest.resources : []) {
|
|
1539
|
+
const artifactPath = String(declaration.path || "");
|
|
1540
|
+
if (!artifactPath.startsWith("artifacts/") || !artifactPath.endsWith("/artifact.yaml")) continue;
|
|
1541
|
+
const source = parseYaml3(String(local.files.get(artifactPath) || ""));
|
|
1542
|
+
if (source.execution_target !== "platform_hosted") continue;
|
|
1543
|
+
const runtime = source.runtime && typeof source.runtime === "object" ? source.runtime : {};
|
|
1544
|
+
const prefix = artifactPath.replace(/artifact\.yaml$/, "src/");
|
|
1545
|
+
const sourceFiles2 = [...local.files].filter(([name]) => name.startsWith(prefix)).map(([name, content]) => ({ path: name.slice(prefix.length), content }));
|
|
1546
|
+
const analysis = await client.hostedArtifacts.analyzeDependencies({ language: runtime.language || "python", source_files: sourceFiles2, dependencies: Array.isArray(runtime.dependencies) ? runtime.dependencies : [] });
|
|
1547
|
+
for (const row of Array.isArray(analysis.rows) ? analysis.rows : []) {
|
|
1548
|
+
if (row.needs_declaration === true) hostedDependencyDiagnostics.push({ resource_key: String(declaration.key || ""), module: String(row.name || ""), suggested_package: typeof row.suggested_spec === "string" ? row.suggested_spec : null });
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1174
1551
|
}
|
|
1175
|
-
return { ok: local.valid && (!remote || remote.valid === true), local: { ...local, files: void 0 }, ...remote ? { remote } : {} };
|
|
1552
|
+
return { ok: local.valid && (!remote || remote.valid === true) && hostedDependencyDiagnostics.length === 0, local: { ...local, files: void 0 }, ...remote ? { remote } : {}, ...flag(parsed, "remote") === "true" ? { hosted_dependency_diagnostics: hostedDependencyDiagnostics } : {} };
|
|
1176
1553
|
}
|
|
1177
1554
|
if (parsed.command === "pack") {
|
|
1178
1555
|
const input = parsed.positionals[0];
|
|
1179
1556
|
if (!input) throw new Error("pack requires a package directory");
|
|
1180
1557
|
const data = await packPackage(input);
|
|
1181
1558
|
const output = resolve3(flag(parsed, "output") || `${basename2(resolve3(input))}.agents24.zip`);
|
|
1182
|
-
await
|
|
1559
|
+
await writeFile4(output, data);
|
|
1183
1560
|
return { ok: true, output, bytes: data.byteLength };
|
|
1184
1561
|
}
|
|
1185
1562
|
if (parsed.command === "export") {
|
|
@@ -1196,7 +1573,7 @@ async function execute(parsed) {
|
|
|
1196
1573
|
const request = { selectors };
|
|
1197
1574
|
const archive = await (await createRemoteClient()).resourcePackages.exportPackage(request);
|
|
1198
1575
|
const output = resolve3(flag(parsed, "output") || archive.filename);
|
|
1199
|
-
await
|
|
1576
|
+
await writeFile4(output, archive.data);
|
|
1200
1577
|
return { ok: true, output, bytes: archive.data.byteLength };
|
|
1201
1578
|
}
|
|
1202
1579
|
if (parsed.command === "preview" || parsed.command === "import") {
|