@slock-ai/daemon 0.54.0 → 0.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- buildFetchDispatcher,
3
+ daemonFetch,
4
4
  executeJsonRequest
5
- } from "./chunk-KNMCE6WB.js";
5
+ } from "./chunk-VOZJ2ELH.js";
6
6
 
7
7
  // src/chat-bridge.ts
8
8
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -47,9 +47,7 @@ var runtimeActionHeaders = {
47
47
  ...launchId ? { "X-Agent-Launch-Id": launchId } : {}
48
48
  };
49
49
  function bridgeFetch(url, init = {}) {
50
- const dispatcher = buildFetchDispatcher(url, process.env);
51
- const requestInit = dispatcher ? { ...init, dispatcher } : init;
52
- return fetch(url, requestInit);
50
+ return daemonFetch(url, init);
53
51
  }
54
52
  var server = new McpServer({
55
53
  name: "chat",
@@ -207,6 +207,15 @@ function buildFetchDispatcher(targetUrl, env) {
207
207
  return dispatcher;
208
208
  }
209
209
 
210
+ // src/daemonFetch.ts
211
+ function withDaemonFetchProxy(input, init = {}, env = process.env) {
212
+ const dispatcher = buildFetchDispatcher(input.toString(), env);
213
+ return dispatcher ? { ...init, dispatcher } : init;
214
+ }
215
+ function daemonFetch(input, init, env = process.env) {
216
+ return fetch(input, withDaemonFetchProxy(input, init, env));
217
+ }
218
+
210
219
  export {
211
220
  subscribeDaemonLogs,
212
221
  logger,
@@ -214,5 +223,5 @@ export {
214
223
  executeJsonRequest,
215
224
  executeResponseRequest,
216
225
  buildWebSocketOptions,
217
- buildFetchDispatcher
226
+ daemonFetch
218
227
  };
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  DEFAULT_CHAT_BRIDGE_TOOL_TIMEOUT_MS,
3
3
  buildWebSocketOptions,
4
+ daemonFetch,
4
5
  executeJsonRequest,
5
6
  executeResponseRequest,
6
7
  logger
7
- } from "./chunk-KNMCE6WB.js";
8
+ } from "./chunk-VOZJ2ELH.js";
8
9
 
9
10
  // src/core.ts
10
11
  import path16 from "path";
@@ -1504,7 +1505,7 @@ async function handleProxyRequest(req, res) {
1504
1505
  headers.set("content-type", "application/json");
1505
1506
  headers.set("content-length", String(Buffer.byteLength(prepared.bodyText)));
1506
1507
  }
1507
- const upstream = await fetch(target, {
1508
+ const upstream = await daemonFetch(target, {
1508
1509
  method,
1509
1510
  headers,
1510
1511
  body,
@@ -1521,15 +1522,12 @@ async function handleProxyRequest(req, res) {
1521
1522
  res.writeHead(upstream.status, responseHeadersForLocalProxy(upstream));
1522
1523
  if (upstream.body) {
1523
1524
  const reader = upstream.body.getReader();
1524
- try {
1525
- while (true) {
1526
- const { done, value } = await reader.read();
1527
- if (done) break;
1528
- res.write(Buffer.from(value));
1529
- }
1530
- } finally {
1531
- res.end();
1525
+ while (true) {
1526
+ const { done, value } = await reader.read();
1527
+ if (done) break;
1528
+ res.write(Buffer.from(value));
1532
1529
  }
1530
+ res.end();
1533
1531
  } else {
1534
1532
  res.end();
1535
1533
  }
@@ -1539,14 +1537,22 @@ async function handleProxyRequest(req, res) {
1539
1537
  `[Agent Credential Proxy] request failed (agent=${registration.agentId}, launch=${registration.launchId ?? "none"}, method=${failure.method}, path=${failure.pathname}, query_keys=${failure.queryKeys.join(",") || "none"}): ${failure.errorName}: ${failure.errorMessage}`
1540
1538
  );
1541
1539
  registration.inboxCoordinator?.recordProxyFailure?.(failure);
1542
- res.writeHead(502, { "content-type": "application/json" });
1543
- res.end(JSON.stringify({
1544
- error: "failed to proxy local agent request",
1545
- code: "agent_proxy_failed",
1546
- detail: failure.errorMessage
1547
- }));
1540
+ writeProxyFailureResponse(res, failure);
1548
1541
  }
1549
1542
  }
1543
+ function writeProxyFailureResponse(res, failure) {
1544
+ if (res.writableEnded) return;
1545
+ if (res.headersSent) {
1546
+ res.destroy();
1547
+ return;
1548
+ }
1549
+ res.writeHead(502, { "content-type": "application/json" });
1550
+ res.end(JSON.stringify({
1551
+ error: "failed to proxy local agent request",
1552
+ code: "agent_proxy_failed",
1553
+ detail: failure.errorMessage
1554
+ }));
1555
+ }
1550
1556
  function proxyFailureForError(method, target, err) {
1551
1557
  const queryKeys = target ? [.../* @__PURE__ */ new Set([...target.searchParams.keys()])].sort() : [];
1552
1558
  return {
@@ -1742,7 +1748,7 @@ async function loadRecentTargetMessages(registration, headers, target) {
1742
1748
  const historyHeaders = new Headers(headers);
1743
1749
  historyHeaders.delete("content-length");
1744
1750
  historyHeaders.delete("content-type");
1745
- const res = await fetch(historyUrl, { method: "GET", headers: historyHeaders });
1751
+ const res = await daemonFetch(historyUrl, { method: "GET", headers: historyHeaders });
1746
1752
  if (!res.ok) return [];
1747
1753
  const parsed = await res.json().catch(() => null);
1748
1754
  return Array.isArray(parsed?.messages) ? normalizeVisibleMessages(parsed.messages, target) : [];
@@ -7068,7 +7074,7 @@ Use ${communicationCommand(driver, "read_history")} to catch up on the channels
7068
7074
  }
7069
7075
  async requestManagedRunnerCredentialOnce(agentId, config) {
7070
7076
  const url = new URL(`/internal/computer/runners/${encodeURIComponent(agentId)}/credentials`, this.serverUrl);
7071
- const res = await fetch(url, {
7077
+ const res = await daemonFetch(url, {
7072
7078
  method: "POST",
7073
7079
  headers: {
7074
7080
  Authorization: `Bearer ${this.daemonApiKey}`,
@@ -7166,7 +7172,7 @@ Use ${communicationCommand(driver, "read_history")} to catch up on the channels
7166
7172
  `/internal/computer/runners/${encodeURIComponent(agentId)}/credentials/${encodeURIComponent(credentialId)}`,
7167
7173
  this.serverUrl
7168
7174
  );
7169
- void fetch(url, {
7175
+ void daemonFetch(url, {
7170
7176
  method: "DELETE",
7171
7177
  headers: {
7172
7178
  Authorization: `Bearer ${this.daemonApiKey}`,
@@ -9631,7 +9637,7 @@ async function requestDaemonScopeAttestation({
9631
9637
  apiKey,
9632
9638
  scope,
9633
9639
  metadata,
9634
- fetchImpl = fetch,
9640
+ fetchImpl = daemonFetch,
9635
9641
  timeoutMs = DEFAULT_CHAT_BRIDGE_TOOL_TIMEOUT_MS
9636
9642
  }) {
9637
9643
  const { response, data } = await executeJsonRequest(
@@ -9664,7 +9670,7 @@ async function createDirectUploadSession({
9664
9670
  createPath = "/api/uploads",
9665
9671
  body,
9666
9672
  attestationMetadata,
9667
- fetchImpl = fetch,
9673
+ fetchImpl = daemonFetch,
9668
9674
  timeoutMs = DEFAULT_CHAT_BRIDGE_TOOL_TIMEOUT_MS
9669
9675
  }) {
9670
9676
  const capability = await requestDaemonScopeAttestation({
@@ -9706,7 +9712,7 @@ async function uploadWithSignedCapability({
9706
9712
  createBody,
9707
9713
  attestationMetadata,
9708
9714
  uploadBody,
9709
- fetchImpl = fetch,
9715
+ fetchImpl = daemonFetch,
9710
9716
  timeoutMs = DEFAULT_CHAT_BRIDGE_TOOL_TIMEOUT_MS
9711
9717
  }) {
9712
9718
  const { capability, response: session } = await createDirectUploadSession({
@@ -10330,7 +10336,7 @@ var DaemonCore = class {
10330
10336
  }
10331
10337
  async requestRunnerCredentialOnce(agentId, config) {
10332
10338
  const url = new URL(`/internal/computer/runners/${encodeURIComponent(agentId)}/credentials`, this.options.serverUrl);
10333
- const res = await fetch(url, {
10339
+ const res = await daemonFetch(url, {
10334
10340
  method: "POST",
10335
10341
  headers: {
10336
10342
  "Authorization": `Bearer ${this.options.apiKey}`,
package/dist/core.js CHANGED
@@ -9,10 +9,10 @@ import {
9
9
  resolveSlockCliPath,
10
10
  resolveWorkspaceDirectoryPath,
11
11
  scanWorkspaceDirectories
12
- } from "./chunk-JXS4CW3D.js";
12
+ } from "./chunk-X366KJGT.js";
13
13
  import {
14
14
  subscribeDaemonLogs
15
- } from "./chunk-KNMCE6WB.js";
15
+ } from "./chunk-VOZJ2ELH.js";
16
16
  export {
17
17
  DAEMON_CLI_USAGE,
18
18
  DaemonCore,
package/dist/index.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  DAEMON_CLI_USAGE,
4
4
  DaemonCore,
5
5
  parseDaemonCliArgs
6
- } from "./chunk-JXS4CW3D.js";
7
- import "./chunk-KNMCE6WB.js";
6
+ } from "./chunk-X366KJGT.js";
7
+ import "./chunk-VOZJ2ELH.js";
8
8
 
9
9
  // src/index.ts
10
10
  var parsedArgs = parseDaemonCliArgs(process.argv.slice(2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slock-ai/daemon",
3
- "version": "0.54.0",
3
+ "version": "0.54.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "slock-daemon": "dist/index.js"