@dexto/core 1.16.5 → 1.17.0-beta.5

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.
Files changed (126) hide show
  1. package/dist/agent/DextoAgent.cjs +2 -1
  2. package/dist/agent/DextoAgent.d.ts.map +1 -1
  3. package/dist/agent/DextoAgent.js +2 -1
  4. package/dist/agent/schemas.d.ts +2 -2
  5. package/dist/approval/index.cjs +4 -0
  6. package/dist/approval/index.d.ts +1 -1
  7. package/dist/approval/index.d.ts.map +1 -1
  8. package/dist/approval/index.js +4 -0
  9. package/dist/events/index.cjs +2 -3
  10. package/dist/events/index.d.ts +6 -23
  11. package/dist/events/index.d.ts.map +1 -1
  12. package/dist/events/index.js +2 -3
  13. package/dist/llm/auth/index.d.ts +1 -1
  14. package/dist/llm/auth/index.d.ts.map +1 -1
  15. package/dist/llm/auth/types.d.ts +14 -0
  16. package/dist/llm/auth/types.d.ts.map +1 -1
  17. package/dist/llm/error-codes.cjs +3 -0
  18. package/dist/llm/error-codes.d.ts +3 -0
  19. package/dist/llm/error-codes.d.ts.map +1 -1
  20. package/dist/llm/error-codes.js +3 -0
  21. package/dist/llm/errors.cjs +27 -0
  22. package/dist/llm/errors.d.ts +9 -0
  23. package/dist/llm/errors.d.ts.map +1 -1
  24. package/dist/llm/errors.js +27 -0
  25. package/dist/llm/executor/provider-error.cjs +14 -0
  26. package/dist/llm/executor/provider-error.d.ts.map +1 -1
  27. package/dist/llm/executor/provider-error.js +14 -0
  28. package/dist/llm/executor/tool-output-spill.cjs +46 -14
  29. package/dist/llm/executor/tool-output-spill.d.ts.map +1 -1
  30. package/dist/llm/executor/tool-output-spill.js +46 -14
  31. package/dist/llm/executor/turn-executor.cjs +4 -0
  32. package/dist/llm/executor/turn-executor.d.ts +5 -5
  33. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  34. package/dist/llm/executor/turn-executor.js +4 -0
  35. package/dist/llm/index.cjs +6 -0
  36. package/dist/llm/index.d.ts +3 -1
  37. package/dist/llm/index.d.ts.map +1 -1
  38. package/dist/llm/index.js +4 -0
  39. package/dist/llm/private-address.cjs +88 -0
  40. package/dist/llm/private-address.d.ts +3 -0
  41. package/dist/llm/private-address.d.ts.map +1 -0
  42. package/dist/llm/private-address.js +65 -0
  43. package/dist/llm/providers/codex-app-server.cjs +3 -3
  44. package/dist/llm/providers/codex-app-server.js +3 -3
  45. package/dist/llm/providers/local/errors.cjs +4 -4
  46. package/dist/llm/providers/local/errors.js +4 -4
  47. package/dist/llm/safe-download.cjs +159 -0
  48. package/dist/llm/safe-download.d.ts +21 -0
  49. package/dist/llm/safe-download.d.ts.map +1 -0
  50. package/dist/llm/safe-download.js +126 -0
  51. package/dist/llm/services/factory.cjs +204 -14
  52. package/dist/llm/services/factory.d.ts +1 -1
  53. package/dist/llm/services/factory.d.ts.map +1 -1
  54. package/dist/llm/services/factory.js +204 -14
  55. package/dist/logger/logger.cjs +12 -9
  56. package/dist/logger/logger.d.ts.map +1 -1
  57. package/dist/logger/logger.js +12 -9
  58. package/dist/logger/v2/dexto-logger.cjs +3 -2
  59. package/dist/logger/v2/dexto-logger.d.ts.map +1 -1
  60. package/dist/logger/v2/dexto-logger.js +3 -2
  61. package/dist/mcp/mcp-client.cjs +17 -8
  62. package/dist/mcp/mcp-client.d.ts +4 -2
  63. package/dist/mcp/mcp-client.d.ts.map +1 -1
  64. package/dist/mcp/mcp-client.js +17 -8
  65. package/dist/mcp/schemas.cjs +3 -0
  66. package/dist/mcp/schemas.d.ts +3 -0
  67. package/dist/mcp/schemas.d.ts.map +1 -1
  68. package/dist/mcp/schemas.js +3 -0
  69. package/dist/resources/handlers/filesystem-handler.cjs +7 -6
  70. package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
  71. package/dist/resources/handlers/filesystem-handler.js +7 -6
  72. package/dist/session/session-manager.cjs +2 -0
  73. package/dist/session/session-manager.d.ts.map +1 -1
  74. package/dist/session/session-manager.js +2 -0
  75. package/dist/systemPrompt/schemas.d.ts +3 -3
  76. package/dist/telemetry/decorators.cjs +2 -2
  77. package/dist/telemetry/decorators.js +2 -2
  78. package/dist/tools/activity.cjs +0 -16
  79. package/dist/tools/activity.d.ts +0 -2
  80. package/dist/tools/activity.d.ts.map +1 -1
  81. package/dist/tools/activity.js +0 -16
  82. package/dist/tools/tool-call-metadata.cjs +0 -12
  83. package/dist/tools/tool-call-metadata.d.ts +0 -3
  84. package/dist/tools/tool-call-metadata.d.ts.map +1 -1
  85. package/dist/tools/tool-call-metadata.js +0 -12
  86. package/dist/tools/tool-manager.cjs +10 -93
  87. package/dist/tools/tool-manager.d.ts.map +1 -1
  88. package/dist/tools/tool-manager.js +10 -93
  89. package/dist/tools/tool-output-read.cjs +4 -3
  90. package/dist/tools/tool-output-read.d.ts.map +1 -1
  91. package/dist/tools/tool-output-read.js +4 -3
  92. package/dist/utils/env.cjs +0 -5
  93. package/dist/utils/env.d.ts +0 -1
  94. package/dist/utils/env.d.ts.map +1 -1
  95. package/dist/utils/env.js +0 -4
  96. package/dist/utils/index.cjs +3 -1
  97. package/dist/utils/index.d.ts +1 -0
  98. package/dist/utils/index.d.ts.map +1 -1
  99. package/dist/utils/index.js +1 -0
  100. package/dist/utils/metadata-address.cjs +138 -0
  101. package/dist/utils/metadata-address.d.ts +24 -0
  102. package/dist/utils/metadata-address.d.ts.map +1 -0
  103. package/dist/utils/metadata-address.js +113 -0
  104. package/dist/utils/path.cjs +0 -15
  105. package/dist/utils/path.d.ts +0 -6
  106. package/dist/utils/path.d.ts.map +1 -1
  107. package/dist/utils/path.js +0 -14
  108. package/dist/utils/redactor.cjs +242 -34
  109. package/dist/utils/redactor.d.ts +15 -0
  110. package/dist/utils/redactor.d.ts.map +1 -1
  111. package/dist/utils/redactor.js +238 -34
  112. package/dist/utils/text-boundary.cjs +32 -0
  113. package/dist/utils/text-boundary.d.ts +3 -0
  114. package/dist/utils/text-boundary.d.ts.map +1 -0
  115. package/dist/utils/text-boundary.js +9 -0
  116. package/dist/workspace/index.cjs +7 -2
  117. package/dist/workspace/index.d.ts +1 -0
  118. package/dist/workspace/index.d.ts.map +1 -1
  119. package/dist/workspace/index.js +4 -1
  120. package/dist/workspace/shell-environment.cjs +96 -0
  121. package/dist/workspace/shell-environment.d.ts +18 -0
  122. package/dist/workspace/shell-environment.d.ts.map +1 -0
  123. package/dist/workspace/shell-environment.js +72 -0
  124. package/dist/workspace/types.d.ts +9 -0
  125. package/dist/workspace/types.d.ts.map +1 -1
  126. package/package.json +3 -3
@@ -26,7 +26,6 @@ import {
26
26
  extractToolCallMeta,
27
27
  wrapToolParametersSchema
28
28
  } from "./tool-call-metadata.js";
29
- import { isBackgroundTasksEnabled } from "../utils/env.js";
30
29
  function isRecord(value) {
31
30
  return typeof value === "object" && value !== null && !Array.isArray(value);
32
31
  }
@@ -1218,10 +1217,6 @@ let _ToolManager = class _ToolManager {
1218
1217
  });
1219
1218
  }
1220
1219
  async replayExistingDirectToolExecution(call, invocation) {
1221
- const { sessionId } = this.resolveToolExecutionInvocation(invocation);
1222
- if (isBackgroundTasksEnabled() && call.meta?.runInBackground === true && sessionId !== void 0) {
1223
- return void 0;
1224
- }
1225
1220
  const identity = this.resolveToolExecutionIdentity(
1226
1221
  invocation ?? {},
1227
1222
  call.toolCallId,
@@ -1358,14 +1353,11 @@ let _ToolManager = class _ToolManager {
1358
1353
  }
1359
1354
  async executePreparedToolCall(call, invocation, options) {
1360
1355
  const { sessionId, abortSignal, runContext, hostRuntime } = this.resolveToolExecutionInvocation(invocation);
1361
- const durableIdentity = this.resolveToolExecutionIdentity(
1356
+ const executionIdentity = this.resolveToolExecutionIdentity(
1362
1357
  invocation ?? {},
1363
1358
  call.toolCallId,
1364
1359
  call.parentToolCallId
1365
1360
  );
1366
- const backgroundTasksEnabled = isBackgroundTasksEnabled();
1367
- const willRunInBackground = backgroundTasksEnabled && call.meta?.runInBackground === true && sessionId !== void 0;
1368
- const executionIdentity = willRunInBackground ? void 0 : durableIdentity;
1369
1361
  const executionId = executionIdentity === void 0 ? void 0 : createToolExecutionId(executionIdentity);
1370
1362
  let toolArgs = call.input;
1371
1363
  this.logger.debug(
@@ -1467,16 +1459,6 @@ let _ToolManager = class _ToolManager {
1467
1459
  }
1468
1460
  }
1469
1461
  let result;
1470
- const registerBackgroundTask = (promise, description) => {
1471
- return {
1472
- result: {
1473
- taskId: call.toolCallId,
1474
- status: "running",
1475
- description
1476
- },
1477
- promise
1478
- };
1479
- };
1480
1462
  if (call.identity.type === "mcp") {
1481
1463
  const actualToolName = call.toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
1482
1464
  if (actualToolName.length === 0) {
@@ -1491,81 +1473,16 @@ let _ToolManager = class _ToolManager {
1491
1473
  sessionId,
1492
1474
  runContext
1493
1475
  );
1494
- if (call.meta?.runInBackground === true && !backgroundTasksEnabled) {
1495
- this.logger.debug(
1496
- "Background tool execution disabled; running synchronously instead.",
1497
- { toolName: call.toolName }
1498
- );
1499
- }
1500
- if (willRunInBackground) {
1501
- const backgroundSessionId = sessionId;
1502
- const { result: backgroundResult, promise } = registerBackgroundTask(
1503
- executeMcpTool(),
1504
- `MCP tool ${actualToolName}`
1505
- );
1506
- this.agentEventBus.emit("tool:background", {
1507
- toolName: call.toolName,
1508
- toolCallId: backgroundResult.taskId,
1509
- sessionId: backgroundSessionId,
1510
- description: backgroundResult.description,
1511
- promise,
1512
- ...hostRuntime !== void 0 && { hostRuntime },
1513
- ...call.meta?.timeoutMs !== void 0 && {
1514
- timeoutMs: call.meta.timeoutMs
1515
- },
1516
- ...call.meta?.notifyOnComplete !== void 0 && {
1517
- notifyOnComplete: call.meta.notifyOnComplete
1518
- }
1519
- });
1520
- result = backgroundResult;
1521
- } else {
1522
- result = await executeMcpTool();
1523
- }
1476
+ result = await executeMcpTool();
1524
1477
  } else {
1525
- if (call.meta?.runInBackground === true && !backgroundTasksEnabled) {
1526
- this.logger.debug(
1527
- "Background tool execution disabled; running synchronously instead.",
1528
- { toolName: call.toolName }
1529
- );
1530
- }
1531
- if (willRunInBackground) {
1532
- const backgroundSessionId = sessionId;
1533
- const { result: backgroundResult, promise } = registerBackgroundTask(
1534
- this.executeLocalTool(call.toolName, toolArgs, {
1535
- sessionId: backgroundSessionId,
1536
- abortSignal,
1537
- executionIdentity,
1538
- toolCallId: call.toolCallId,
1539
- parentToolCallId: call.parentToolCallId,
1540
- runContext
1541
- }),
1542
- `Tool ${call.toolName}`
1543
- );
1544
- this.agentEventBus.emit("tool:background", {
1545
- toolName: call.toolName,
1546
- toolCallId: backgroundResult.taskId,
1547
- sessionId: backgroundSessionId,
1548
- description: backgroundResult.description,
1549
- promise,
1550
- ...hostRuntime !== void 0 && { hostRuntime },
1551
- ...call.meta?.timeoutMs !== void 0 && {
1552
- timeoutMs: call.meta.timeoutMs
1553
- },
1554
- ...call.meta?.notifyOnComplete !== void 0 && {
1555
- notifyOnComplete: call.meta.notifyOnComplete
1556
- }
1557
- });
1558
- result = backgroundResult;
1559
- } else {
1560
- result = await this.executeLocalTool(call.toolName, toolArgs, {
1561
- sessionId,
1562
- abortSignal,
1563
- executionIdentity,
1564
- toolCallId: call.toolCallId,
1565
- parentToolCallId: call.parentToolCallId,
1566
- runContext
1567
- });
1568
- }
1478
+ result = await this.executeLocalTool(call.toolName, toolArgs, {
1479
+ sessionId,
1480
+ abortSignal,
1481
+ executionIdentity,
1482
+ toolCallId: call.toolCallId,
1483
+ parentToolCallId: call.parentToolCallId,
1484
+ runContext
1485
+ });
1569
1486
  }
1570
1487
  const duration = Date.now() - startTime;
1571
1488
  this.logger.debug(
@@ -22,6 +22,7 @@ __export(tool_output_read_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(tool_output_read_exports);
24
24
  var import_zod = require("zod");
25
+ var import_text_boundary = require("../utils/text-boundary.js");
25
26
  var import_tool_output_spill = require("../llm/executor/tool-output-spill.js");
26
27
  var import_activity = require("./activity.js");
27
28
  var import_errors = require("./errors.js");
@@ -91,8 +92,8 @@ function readLines(text, input) {
91
92
  const room = MAX_READ_CHARS - chars - prefix.length;
92
93
  if (room <= 0) break;
93
94
  const full = lines[line - 1] ?? "";
94
- const from = line === start ? Math.min(input.charOffset ?? 0, full.length) : 0;
95
- const piece = full.slice(from, from + room);
95
+ const from = line === start ? (0, import_text_boundary.safeTextBoundary)(full, Math.min(input.charOffset ?? 0, full.length)) : 0;
96
+ const piece = full.slice(from, (0, import_text_boundary.safeTextBoundary)(full, Math.min(from + room, full.length)));
96
97
  selected.push(`${prefix}${piece}`);
97
98
  chars += prefix.length + piece.length + 1;
98
99
  if (from + piece.length < full.length) {
@@ -119,7 +120,7 @@ function searchLines(text, pattern, maxMatches) {
119
120
  if (!line.toLowerCase().includes(needle)) return;
120
121
  total += 1;
121
122
  if (outOfRoom || found.length >= maxMatches) return;
122
- const match = `${index + 1}: ${line.slice(0, MAX_MATCH_LINE_CHARS)}`;
123
+ const match = `${index + 1}: ${line.slice(0, (0, import_text_boundary.safeTextBoundary)(line, MAX_MATCH_LINE_CHARS))}`;
123
124
  if (chars + match.length > MAX_READ_CHARS) {
124
125
  outOfRoom = true;
125
126
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"tool-output-read.d.ts","sourceRoot":"","sources":["../../src/tools/tool-output-read.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAMxE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAYvC,QAAA,MAAM,yBAAyB;;;;;;;kBA0ClB,CAAC;AAId,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC7C,YAAY,EAAE,iBAAiB,CAAC;IAChC,WAAW,EAAE,eAAe,CAAC;CAChC,GAAG,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAkCzC"}
1
+ {"version":3,"file":"tool-output-read.d.ts","sourceRoot":"","sources":["../../src/tools/tool-output-read.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAMxE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAYvC,QAAA,MAAM,yBAAyB;;;;;;;kBA0ClB,CAAC;AAId,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC7C,YAAY,EAAE,iBAAiB,CAAC;IAChC,WAAW,EAAE,eAAe,CAAC;CAChC,GAAG,IAAI,CAAC,OAAO,yBAAyB,CAAC,CAkCzC"}
@@ -1,5 +1,6 @@
1
1
  import "../chunk-C6A6W6XS.js";
2
2
  import { z } from "zod";
3
+ import { safeTextBoundary } from "../utils/text-boundary.js";
3
4
  import { TOOL_OUTPUT_READ_TOOL_NAME } from "../llm/executor/tool-output-spill.js";
4
5
  import { TOOL_ACTIVITY } from "./activity.js";
5
6
  import { ToolError } from "./errors.js";
@@ -69,8 +70,8 @@ function readLines(text, input) {
69
70
  const room = MAX_READ_CHARS - chars - prefix.length;
70
71
  if (room <= 0) break;
71
72
  const full = lines[line - 1] ?? "";
72
- const from = line === start ? Math.min(input.charOffset ?? 0, full.length) : 0;
73
- const piece = full.slice(from, from + room);
73
+ const from = line === start ? safeTextBoundary(full, Math.min(input.charOffset ?? 0, full.length)) : 0;
74
+ const piece = full.slice(from, safeTextBoundary(full, Math.min(from + room, full.length)));
74
75
  selected.push(`${prefix}${piece}`);
75
76
  chars += prefix.length + piece.length + 1;
76
77
  if (from + piece.length < full.length) {
@@ -97,7 +98,7 @@ function searchLines(text, pattern, maxMatches) {
97
98
  if (!line.toLowerCase().includes(needle)) return;
98
99
  total += 1;
99
100
  if (outOfRoom || found.length >= maxMatches) return;
100
- const match = `${index + 1}: ${line.slice(0, MAX_MATCH_LINE_CHARS)}`;
101
+ const match = `${index + 1}: ${line.slice(0, safeTextBoundary(line, MAX_MATCH_LINE_CHARS))}`;
101
102
  if (chars + match.length > MAX_READ_CHARS) {
102
103
  outOfRoom = true;
103
104
  return;
@@ -18,7 +18,6 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var env_exports = {};
20
20
  __export(env_exports, {
21
- isBackgroundTasksEnabled: () => isBackgroundTasksEnabled,
22
21
  isTruthyEnv: () => isTruthyEnv,
23
22
  readBooleanEnv: () => readBooleanEnv
24
23
  });
@@ -38,12 +37,8 @@ function readBooleanEnv(name, defaultValue) {
38
37
  if (FALSE_VALUES.has(normalized)) return false;
39
38
  return defaultValue;
40
39
  }
41
- function isBackgroundTasksEnabled() {
42
- return readBooleanEnv("DEXTO_BACKGROUND_TASKS_ENABLED", false);
43
- }
44
40
  // Annotate the CommonJS export names for ESM import in node:
45
41
  0 && (module.exports = {
46
- isBackgroundTasksEnabled,
47
42
  isTruthyEnv,
48
43
  readBooleanEnv
49
44
  });
@@ -1,4 +1,3 @@
1
1
  export declare function isTruthyEnv(name: string): boolean;
2
2
  export declare function readBooleanEnv(name: string, defaultValue: boolean): boolean;
3
- export declare function isBackgroundTasksEnabled(): boolean;
4
3
  //# sourceMappingURL=env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/utils/env.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIjD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAO3E;AAED,wBAAgB,wBAAwB,IAAI,OAAO,CAElD"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/utils/env.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIjD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAO3E"}
package/dist/utils/env.js CHANGED
@@ -14,11 +14,7 @@ function readBooleanEnv(name, defaultValue) {
14
14
  if (FALSE_VALUES.has(normalized)) return false;
15
15
  return defaultValue;
16
16
  }
17
- function isBackgroundTasksEnabled() {
18
- return readBooleanEnv("DEXTO_BACKGROUND_TASKS_ENABLED", false);
19
- }
20
17
  export {
21
- isBackgroundTasksEnabled,
22
18
  isTruthyEnv,
23
19
  readBooleanEnv
24
20
  };
@@ -29,6 +29,7 @@ __reExport(utils_exports, require("./api-key-resolver.js"), module.exports);
29
29
  __reExport(utils_exports, require("./defer.js"), module.exports);
30
30
  __reExport(utils_exports, require("./async-context.js"), module.exports);
31
31
  __reExport(utils_exports, require("./env.js"), module.exports);
32
+ __reExport(utils_exports, require("./metadata-address.js"), module.exports);
32
33
  // Annotate the CommonJS export names for ESM import in node:
33
34
  0 && (module.exports = {
34
35
  ...require("./path.js"),
@@ -44,5 +45,6 @@ __reExport(utils_exports, require("./env.js"), module.exports);
44
45
  ...require("./api-key-resolver.js"),
45
46
  ...require("./defer.js"),
46
47
  ...require("./async-context.js"),
47
- ...require("./env.js")
48
+ ...require("./env.js"),
49
+ ...require("./metadata-address.js")
48
50
  });
@@ -12,4 +12,5 @@ export * from './api-key-resolver.js';
12
12
  export * from './defer.js';
13
13
  export * from './async-context.js';
14
14
  export * from './env.js';
15
+ export * from './metadata-address.js';
15
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAKA,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAKA,cAAc,WAAW,CAAC;AAC1B,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AASzB,cAAc,uBAAuB,CAAC"}
@@ -12,3 +12,4 @@ export * from "./api-key-resolver.js";
12
12
  export * from "./defer.js";
13
13
  export * from "./async-context.js";
14
14
  export * from "./env.js";
15
+ export * from "./metadata-address.js";
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var metadata_address_exports = {};
20
+ __export(metadata_address_exports, {
21
+ createMetadataCheckedLookup: () => createMetadataCheckedLookup,
22
+ isMetadataHost: () => isMetadataHost,
23
+ isMetadataTarget: () => isMetadataTarget
24
+ });
25
+ module.exports = __toCommonJS(metadata_address_exports);
26
+ var import_node_dns = require("node:dns");
27
+ var import_node_net = require("node:net");
28
+ const METADATA_HOSTNAMES = /* @__PURE__ */ new Set([
29
+ "metadata.google.internal",
30
+ "metadata.goog",
31
+ "instance-data",
32
+ "instance-data.ec2.internal"
33
+ ]);
34
+ async function resolveAllAddresses(hostname) {
35
+ const records = await import_node_dns.promises.lookup(hostname, { all: true, verbatim: true });
36
+ return records.map((record) => record.address);
37
+ }
38
+ const METADATA_IPV4 = ["100.100.100.200", "192.0.0.192", "168.63.129.16"];
39
+ function isMetadataIpv4(a, b, c, d) {
40
+ return a === 169 && b === 254 || METADATA_IPV4.includes(`${a}.${b}.${c}.${d}`);
41
+ }
42
+ function ipv6Groups(address) {
43
+ const [head = "", tail] = address.split("::");
44
+ const headGroups = head === "" ? [] : head.split(":");
45
+ const tailGroups = tail === void 0 || tail === "" ? [] : tail.split(":");
46
+ const missing = tail === void 0 ? 0 : 8 - headGroups.length - tailGroups.length;
47
+ const groups = [...headGroups, ...Array(missing).fill("0"), ...tailGroups];
48
+ return groups.map((group) => Number.parseInt(group, 16));
49
+ }
50
+ function isMetadataIpv6(address) {
51
+ const normalized = new URL(`http://[${address.split("%")[0]}]/`).hostname.slice(1, -1);
52
+ const g = ipv6Groups(normalized);
53
+ const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, g4 = 0, g5 = 0, g6 = 0, g7 = 0] = g;
54
+ if ((g0 & 65472) === 65152) return true;
55
+ const isMetadataUniqueLocal = g0 === 64768 && g1 === 3778 || g0 === 64800 && g1 === 206;
56
+ if (isMetadataUniqueLocal && g2 + g3 + g4 + g5 + g6 === 0 && g7 === 596) {
57
+ return true;
58
+ }
59
+ const v4 = (high, low) => isMetadataIpv4(high >> 8, high & 255, low >> 8, low & 255);
60
+ const upperZero = g0 + g1 + g2 + g3 === 0;
61
+ if (upperZero && g4 === 0 && g5 === 65535) return v4(g6, g7);
62
+ if (upperZero && g4 === 65535 && g5 === 0) return v4(g6, g7);
63
+ if (upperZero && g4 === 0 && g5 === 0) return v4(g6, g7);
64
+ if (g0 === 100 && g1 === 65435 && g2 + g3 + g4 + g5 === 0) return v4(g6, g7);
65
+ if (g0 === 8194) return v4(g1, g2);
66
+ return false;
67
+ }
68
+ function isMetadataAddress(address) {
69
+ const version = (0, import_node_net.isIP)(address.split("%")[0] ?? address);
70
+ if (version === 4) {
71
+ const [a = 0, b = 0, c = 0, d = 0] = address.split(".").map(Number);
72
+ return isMetadataIpv4(a, b, c, d);
73
+ }
74
+ if (version === 6) return isMetadataIpv6(address);
75
+ return false;
76
+ }
77
+ function normalizeHostname(hostname) {
78
+ const bare = hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
79
+ let host = bare.toLowerCase();
80
+ while (host.endsWith(".")) host = host.slice(0, -1);
81
+ return host;
82
+ }
83
+ function isMetadataHost(hostname) {
84
+ const host = normalizeHostname(hostname);
85
+ return METADATA_HOSTNAMES.has(host) || isMetadataAddress(host);
86
+ }
87
+ async function isMetadataTarget(hostname, resolve = resolveAllAddresses) {
88
+ if (isMetadataHost(hostname)) return true;
89
+ const host = normalizeHostname(hostname);
90
+ if ((0, import_node_net.isIP)(host) !== 0) return false;
91
+ let addresses;
92
+ try {
93
+ addresses = await resolve(host);
94
+ } catch {
95
+ return false;
96
+ }
97
+ return addresses.some(isMetadataAddress);
98
+ }
99
+ function createMetadataCheckedLookup(resolve = resolveAllAddresses) {
100
+ return (hostname, options, callback) => {
101
+ const fail = (error) => {
102
+ const errno = Object.assign(error, { code: "EMETADATA" });
103
+ if (options.all) callback(errno, []);
104
+ else callback(errno, "", 0);
105
+ };
106
+ if (isMetadataHost(hostname)) {
107
+ fail(new Error(`Blocked request to metadata host: ${hostname}`));
108
+ return;
109
+ }
110
+ resolve(hostname).then(
111
+ (addresses) => {
112
+ const blocked = addresses.find(isMetadataAddress);
113
+ if (blocked !== void 0) {
114
+ fail(new Error(`${hostname} resolves to metadata address ${blocked}`));
115
+ return;
116
+ }
117
+ const records = addresses.map((address) => ({
118
+ address,
119
+ family: (0, import_node_net.isIP)(address) === 6 ? 6 : 4
120
+ }));
121
+ const [first] = records;
122
+ if (first === void 0) {
123
+ fail(new Error(`Failed to resolve ${hostname}`));
124
+ return;
125
+ }
126
+ if (options.all) callback(null, records);
127
+ else callback(null, first.address, first.family);
128
+ },
129
+ (error) => fail(error instanceof Error ? error : new Error(String(error)))
130
+ );
131
+ };
132
+ }
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ createMetadataCheckedLookup,
136
+ isMetadataHost,
137
+ isMetadataTarget
138
+ });
@@ -0,0 +1,24 @@
1
+ import { type LookupAddress, type LookupOptions } from 'node:dns';
2
+ type Resolve = (hostname: string) => Promise<string[]>;
3
+ /**
4
+ * True when a hostname names a metadata target without any DNS lookup: a metadata host name or
5
+ * an IP literal. Pass `URL.hostname`, which already normalises decimal, octal and hex IPv4.
6
+ */
7
+ export declare function isMetadataHost(hostname: string): boolean;
8
+ /**
9
+ * True when a hostname is a metadata target, or is a name that resolves to one. Resolves at call
10
+ * time and checks every answer. A name that does not resolve is not a metadata target; the
11
+ * request itself will fail.
12
+ */
13
+ export declare function isMetadataTarget(hostname: string, resolve?: Resolve): Promise<boolean>;
14
+ type LookupCallback = (error: NodeJS.ErrnoException | null, address: string | LookupAddress[], family?: number) => void;
15
+ /**
16
+ * A `lookup` for a connection (for example an undici `connect.lookup`) that resolves the host
17
+ * itself, refuses metadata answers and hands the connection the addresses it checked. A name
18
+ * that answers differently to a later lookup (DNS rebinding) therefore cannot redirect the
19
+ * connection, because there is no later lookup. IP literals never reach a lookup, so check those
20
+ * with {@link isMetadataHost} first.
21
+ */
22
+ export declare function createMetadataCheckedLookup(resolve?: Resolve): (hostname: string, options: LookupOptions, callback: LookupCallback) => void;
23
+ export {};
24
+ //# sourceMappingURL=metadata-address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata-address.d.ts","sourceRoot":"","sources":["../../src/utils/metadata-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAmBnF,KAAK,OAAO,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAkEvD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAA6B,GACvC,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED,KAAK,cAAc,GAAG,CAClB,KAAK,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,EACnC,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,EACjC,MAAM,CAAC,EAAE,MAAM,KACd,IAAI,CAAC;AAEV;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACvC,OAAO,GAAE,OAA6B,GACvC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,KAAK,IAAI,CAiC9E"}
@@ -0,0 +1,113 @@
1
+ import "../chunk-C6A6W6XS.js";
2
+ import { promises as dns } from "node:dns";
3
+ import { isIP } from "node:net";
4
+ const METADATA_HOSTNAMES = /* @__PURE__ */ new Set([
5
+ "metadata.google.internal",
6
+ "metadata.goog",
7
+ "instance-data",
8
+ "instance-data.ec2.internal"
9
+ ]);
10
+ async function resolveAllAddresses(hostname) {
11
+ const records = await dns.lookup(hostname, { all: true, verbatim: true });
12
+ return records.map((record) => record.address);
13
+ }
14
+ const METADATA_IPV4 = ["100.100.100.200", "192.0.0.192", "168.63.129.16"];
15
+ function isMetadataIpv4(a, b, c, d) {
16
+ return a === 169 && b === 254 || METADATA_IPV4.includes(`${a}.${b}.${c}.${d}`);
17
+ }
18
+ function ipv6Groups(address) {
19
+ const [head = "", tail] = address.split("::");
20
+ const headGroups = head === "" ? [] : head.split(":");
21
+ const tailGroups = tail === void 0 || tail === "" ? [] : tail.split(":");
22
+ const missing = tail === void 0 ? 0 : 8 - headGroups.length - tailGroups.length;
23
+ const groups = [...headGroups, ...Array(missing).fill("0"), ...tailGroups];
24
+ return groups.map((group) => Number.parseInt(group, 16));
25
+ }
26
+ function isMetadataIpv6(address) {
27
+ const normalized = new URL(`http://[${address.split("%")[0]}]/`).hostname.slice(1, -1);
28
+ const g = ipv6Groups(normalized);
29
+ const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, g4 = 0, g5 = 0, g6 = 0, g7 = 0] = g;
30
+ if ((g0 & 65472) === 65152) return true;
31
+ const isMetadataUniqueLocal = g0 === 64768 && g1 === 3778 || g0 === 64800 && g1 === 206;
32
+ if (isMetadataUniqueLocal && g2 + g3 + g4 + g5 + g6 === 0 && g7 === 596) {
33
+ return true;
34
+ }
35
+ const v4 = (high, low) => isMetadataIpv4(high >> 8, high & 255, low >> 8, low & 255);
36
+ const upperZero = g0 + g1 + g2 + g3 === 0;
37
+ if (upperZero && g4 === 0 && g5 === 65535) return v4(g6, g7);
38
+ if (upperZero && g4 === 65535 && g5 === 0) return v4(g6, g7);
39
+ if (upperZero && g4 === 0 && g5 === 0) return v4(g6, g7);
40
+ if (g0 === 100 && g1 === 65435 && g2 + g3 + g4 + g5 === 0) return v4(g6, g7);
41
+ if (g0 === 8194) return v4(g1, g2);
42
+ return false;
43
+ }
44
+ function isMetadataAddress(address) {
45
+ const version = isIP(address.split("%")[0] ?? address);
46
+ if (version === 4) {
47
+ const [a = 0, b = 0, c = 0, d = 0] = address.split(".").map(Number);
48
+ return isMetadataIpv4(a, b, c, d);
49
+ }
50
+ if (version === 6) return isMetadataIpv6(address);
51
+ return false;
52
+ }
53
+ function normalizeHostname(hostname) {
54
+ const bare = hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
55
+ let host = bare.toLowerCase();
56
+ while (host.endsWith(".")) host = host.slice(0, -1);
57
+ return host;
58
+ }
59
+ function isMetadataHost(hostname) {
60
+ const host = normalizeHostname(hostname);
61
+ return METADATA_HOSTNAMES.has(host) || isMetadataAddress(host);
62
+ }
63
+ async function isMetadataTarget(hostname, resolve = resolveAllAddresses) {
64
+ if (isMetadataHost(hostname)) return true;
65
+ const host = normalizeHostname(hostname);
66
+ if (isIP(host) !== 0) return false;
67
+ let addresses;
68
+ try {
69
+ addresses = await resolve(host);
70
+ } catch {
71
+ return false;
72
+ }
73
+ return addresses.some(isMetadataAddress);
74
+ }
75
+ function createMetadataCheckedLookup(resolve = resolveAllAddresses) {
76
+ return (hostname, options, callback) => {
77
+ const fail = (error) => {
78
+ const errno = Object.assign(error, { code: "EMETADATA" });
79
+ if (options.all) callback(errno, []);
80
+ else callback(errno, "", 0);
81
+ };
82
+ if (isMetadataHost(hostname)) {
83
+ fail(new Error(`Blocked request to metadata host: ${hostname}`));
84
+ return;
85
+ }
86
+ resolve(hostname).then(
87
+ (addresses) => {
88
+ const blocked = addresses.find(isMetadataAddress);
89
+ if (blocked !== void 0) {
90
+ fail(new Error(`${hostname} resolves to metadata address ${blocked}`));
91
+ return;
92
+ }
93
+ const records = addresses.map((address) => ({
94
+ address,
95
+ family: isIP(address) === 6 ? 6 : 4
96
+ }));
97
+ const [first] = records;
98
+ if (first === void 0) {
99
+ fail(new Error(`Failed to resolve ${hostname}`));
100
+ return;
101
+ }
102
+ if (options.all) callback(null, records);
103
+ else callback(null, first.address, first.family);
104
+ },
105
+ (error) => fail(error instanceof Error ? error : new Error(String(error)))
106
+ );
107
+ };
108
+ }
109
+ export {
110
+ createMetadataCheckedLookup,
111
+ isMetadataHost,
112
+ isMetadataTarget
113
+ };
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var path_exports = {};
30
30
  __export(path_exports, {
31
- copyDirectory: () => copyDirectory,
32
31
  ensureDextoGlobalDirectory: () => ensureDextoGlobalDirectory,
33
32
  findPackageRoot: () => findPackageRoot,
34
33
  getDextoEnvPath: () => getDextoEnvPath,
@@ -91,19 +90,6 @@ function getDextoGlobalPath(type, filename) {
91
90
  const basePath = path.join((0, import_os.homedir)(), ".dexto", type);
92
91
  return filename ? path.join(basePath, filename) : basePath;
93
92
  }
94
- async function copyDirectory(src, dest) {
95
- await import_fs2.promises.mkdir(dest, { recursive: true });
96
- const entries = await import_fs2.promises.readdir(src, { withFileTypes: true });
97
- for (const entry of entries) {
98
- const srcPath = path.join(src, entry.name);
99
- const destPath = path.join(dest, entry.name);
100
- if (entry.isDirectory()) {
101
- await copyDirectory(srcPath, destPath);
102
- } else {
103
- await import_fs2.promises.copyFile(srcPath, destPath);
104
- }
105
- }
106
- }
107
93
  function isPath(str) {
108
94
  if (path.isAbsolute(str)) return true;
109
95
  if (/[\\/]/.test(str)) return true;
@@ -161,7 +147,6 @@ function getDextoEnvPath(startPath = process.cwd(), logger) {
161
147
  }
162
148
  // Annotate the CommonJS export names for ESM import in node:
163
149
  0 && (module.exports = {
164
- copyDirectory,
165
150
  ensureDextoGlobalDirectory,
166
151
  findPackageRoot,
167
152
  getDextoEnvPath,
@@ -23,12 +23,6 @@ export declare function getDextoPath(type: string, filename?: string, startPath?
23
23
  * @returns Absolute path to the global location (~/.dexto/...)
24
24
  */
25
25
  export declare function getDextoGlobalPath(type: string, filename?: string): string;
26
- /**
27
- * Copy entire directory recursively
28
- * @param src Source directory path
29
- * @param dest Destination directory path
30
- */
31
- export declare function copyDirectory(src: string, dest: string): Promise<void>;
32
26
  /**
33
27
  * Check if string looks like a file path vs registry name
34
28
  * @param str String to check
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAuCxF;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAc1E;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAe5E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAW3C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAKhF;AAMD;;GAEG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAUhE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAkC1F"}
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAuCxF;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAc1E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAW3C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAKhF;AAMD;;GAEG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAUhE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAkC1F"}
@@ -57,19 +57,6 @@ function getDextoGlobalPath(type, filename) {
57
57
  const basePath = path.join(homedir(), ".dexto", type);
58
58
  return filename ? path.join(basePath, filename) : basePath;
59
59
  }
60
- async function copyDirectory(src, dest) {
61
- await fs.mkdir(dest, { recursive: true });
62
- const entries = await fs.readdir(src, { withFileTypes: true });
63
- for (const entry of entries) {
64
- const srcPath = path.join(src, entry.name);
65
- const destPath = path.join(dest, entry.name);
66
- if (entry.isDirectory()) {
67
- await copyDirectory(srcPath, destPath);
68
- } else {
69
- await fs.copyFile(srcPath, destPath);
70
- }
71
- }
72
- }
73
60
  function isPath(str) {
74
61
  if (path.isAbsolute(str)) return true;
75
62
  if (/[\\/]/.test(str)) return true;
@@ -126,7 +113,6 @@ function getDextoEnvPath(startPath = process.cwd(), logger) {
126
113
  return envPath;
127
114
  }
128
115
  export {
129
- copyDirectory,
130
116
  ensureDextoGlobalDirectory,
131
117
  findPackageRoot,
132
118
  getDextoEnvPath,