@sagentlab/navarch-runtime 0.1.71 → 0.1.72

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.
@@ -96,40 +96,55 @@ async function startBrowserEvidence(options) {
96
96
  throw new Error("Screenshot exceeds 25 MiB.");
97
97
  assertActive();
98
98
  const fileName = `${args.evidence_role}-${viewport}-${(0, node_crypto_1.randomUUID)()}.png`;
99
- const registration = await fetchImpl(`${options.apiBase.replace(/\/+$/, "")}/api/mcp`, {
100
- method: "POST",
101
- signal: AbortSignal.timeout(30_000),
102
- headers: {
103
- authorization: `Bearer ${options.machineToken}`,
104
- "x-navarch-lease-id": options.leaseId,
105
- "content-type": "application/json",
106
- accept: "application/json, text/event-stream",
107
- "mcp-protocol-version": "2025-06-18",
108
- },
109
- body: JSON.stringify({ jsonrpc: "2.0", id: (0, node_crypto_1.randomUUID)(), method: "tools/call", params: {
110
- name: "register_artifact", arguments: {
111
- file_name: fileName, mime_type: "image/png", size_bytes: bytes.length,
112
- checksum_sha256: (0, node_crypto_1.createHash)("sha256").update(bytes).digest("hex"),
113
- source_commit_sha: args.source_commit_sha, evidence_role: args.evidence_role,
114
- },
115
- } }),
99
+ const callTool = async (name, toolArgs) => {
100
+ const response = await fetchImpl(`${options.apiBase.replace(/\/+$/, "")}/api/mcp`, {
101
+ method: "POST",
102
+ signal: AbortSignal.timeout(30_000),
103
+ headers: {
104
+ authorization: `Bearer ${options.machineToken}`,
105
+ "x-navarch-lease-id": options.leaseId,
106
+ "content-type": "application/json",
107
+ accept: "application/json, text/event-stream",
108
+ "mcp-protocol-version": "2025-06-18",
109
+ },
110
+ body: JSON.stringify({ jsonrpc: "2.0", id: (0, node_crypto_1.randomUUID)(), method: "tools/call", params: {
111
+ name, arguments: toolArgs,
112
+ } }),
113
+ });
114
+ if (!response.ok)
115
+ throw new Error(`Artifact ${name} returned HTTP ${response.status}.`);
116
+ const result = await response.json();
117
+ if (result.error || result.result?.isError || !result.result?.structuredContent) {
118
+ throw new Error(`Artifact ${name} was rejected.`);
119
+ }
120
+ return result.result.structuredContent;
121
+ };
122
+ const registered = await callTool("register_artifact", {
123
+ file_name: fileName, mime_type: "image/png", size_bytes: bytes.length,
124
+ checksum_sha256: (0, node_crypto_1.createHash)("sha256").update(bytes).digest("hex"),
125
+ source_commit_sha: args.source_commit_sha, evidence_role: args.evidence_role,
116
126
  });
117
- if (!registration.ok)
118
- throw new Error(`Artifact registration returned HTTP ${registration.status}.`);
119
- const result = await registration.json();
120
- const destination = result.result?.structuredContent;
121
- if (result.error || result.result?.isError || !destination?.upload_url || !destination.public_url
122
- || new URL(destination.upload_url).protocol !== "https:" || new URL(destination.public_url).protocol !== "https:") {
123
- throw new Error("Artifact registration did not provide secure upload and public URLs.");
127
+ const { upload_url: uploadUrl, artifact_version_id: versionId } = registered;
128
+ if (typeof uploadUrl !== "string" || typeof versionId !== "string" || new URL(uploadUrl).protocol !== "https:") {
129
+ throw new Error("Artifact registration did not provide a secure upload URL.");
124
130
  }
125
131
  assertActive();
126
- const upload = await fetchImpl(destination.upload_url, {
127
- method: "PUT", headers: { "content-type": "image/png" },
132
+ // The signed URL is creation-only: Content-Type and If-None-Match are
133
+ // signed headers, so the PUT must send both or storage returns 403.
134
+ const upload = await fetchImpl(uploadUrl, {
135
+ method: "PUT", headers: { "content-type": "image/png", "if-none-match": "*" },
128
136
  body: new Uint8Array(bytes), signal: AbortSignal.timeout(30_000),
129
137
  });
130
138
  if (!upload.ok)
131
139
  throw new Error(`Screenshot upload returned HTTP ${upload.status}.`);
132
- const item = { fileName, publicUrl: destination.public_url,
140
+ assertActive();
141
+ // The artifact is not published (or completion-eligible) until finalized.
142
+ const finalized = await callTool("finalize_artifact", { artifact_version_id: versionId });
143
+ const publicUrl = finalized.public_url;
144
+ if (finalized.artifact_version_id !== versionId || typeof publicUrl !== "string" || new URL(publicUrl).protocol !== "https:") {
145
+ throw new Error("Artifact finalization did not provide a secure public URL.");
146
+ }
147
+ const item = { fileName, publicUrl,
133
148
  sourceCommitSha: args.source_commit_sha, role: args.evidence_role, viewport };
134
149
  evidence.push(item);
135
150
  captured.push(item);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sagentlab/navarch-runtime",
3
- "version": "0.1.71",
3
+ "version": "0.1.72",
4
4
  "description": "Navarch machine-side session manager: claims delivery tasks and runs them through local coding agents.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",