@moxt-ai/cli 0.12.0 → 0.12.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.
package/dist/index.cjs CHANGED
@@ -9976,7 +9976,7 @@ var init_durable_attempt = __esm({
9976
9976
  });
9977
9977
 
9978
9978
  // ../machine-connector/dist/runtime/local-codex-runtime/event-normalizer.js
9979
- function normalizeAppServerNotification(message, canonicalRoot) {
9979
+ function normalizeAppServerNotification(message, canonicalRoot, remoteImageSourceUrls) {
9980
9980
  const method = message.method;
9981
9981
  if (method === void 0) {
9982
9982
  return {};
@@ -10059,7 +10059,7 @@ function normalizeAppServerNotification(message, canonicalRoot) {
10059
10059
  return event("usage_updated", { tokenUsage: params.tokenUsage }, correlation, canonicalRoot);
10060
10060
  }
10061
10061
  if (method === "item/started" || method === "item/completed") {
10062
- return normalizeItem(recordValue(params.item), method === "item/completed", correlation, canonicalRoot);
10062
+ return normalizeItem(recordValue(params.item), method === "item/completed", correlation, canonicalRoot, remoteImageSourceUrls);
10063
10063
  }
10064
10064
  if (method === "item/mcpToolCall/progress") {
10065
10065
  return event("tool_started", { message: params.message }, correlation, canonicalRoot);
@@ -10072,7 +10072,7 @@ function normalizeAppServerNotification(message, canonicalRoot) {
10072
10072
  function sanitizeAppServerPayload(value, canonicalRoot) {
10073
10073
  return sanitizeRecord(recordValue(value), canonicalRoot);
10074
10074
  }
10075
- function normalizeItem(item, completed, baseCorrelation, canonicalRoot) {
10075
+ function normalizeItem(item, completed, baseCorrelation, canonicalRoot, remoteImageSourceUrls) {
10076
10076
  const itemType = optionalString2(item.type).value;
10077
10077
  const correlation = {
10078
10078
  ...baseCorrelation,
@@ -10085,7 +10085,7 @@ function normalizeItem(item, completed, baseCorrelation, canonicalRoot) {
10085
10085
  }
10086
10086
  return event("user_message", {
10087
10087
  clientMessageId,
10088
- inputItems: userMessageInputItems(item.content)
10088
+ inputItems: userMessageInputItems(item.content, remoteImageSourceUrls)
10089
10089
  }, correlation, canonicalRoot);
10090
10090
  }
10091
10091
  if (itemType === "agentMessage") {
@@ -10115,7 +10115,7 @@ function normalizeItem(item, completed, baseCorrelation, canonicalRoot) {
10115
10115
  }
10116
10116
  return {};
10117
10117
  }
10118
- function userMessageInputItems(value) {
10118
+ function userMessageInputItems(value, remoteImageSourceUrls) {
10119
10119
  if (!Array.isArray(value)) {
10120
10120
  return [];
10121
10121
  }
@@ -10129,9 +10129,14 @@ function userMessageInputItems(value) {
10129
10129
  payload: { text: optionalString2(content3.text).value ?? "" }
10130
10130
  });
10131
10131
  } else if (contentType === "image") {
10132
+ const url = optionalString2(content3.url).value ?? "";
10133
+ const sourceUrl = remoteImageSourceUrls.get(url);
10134
+ if (url.startsWith("data:") && sourceUrl === void 0) {
10135
+ continue;
10136
+ }
10132
10137
  result.push({
10133
10138
  itemType: "image",
10134
- payload: { url: optionalString2(content3.url).value ?? "" }
10139
+ payload: { url: sourceUrl ?? url }
10135
10140
  });
10136
10141
  } else if (contentType === "localImage") {
10137
10142
  result.push({
@@ -10311,6 +10316,7 @@ function createActiveAttempt(claim, durable, workingDirectory) {
10311
10316
  leaseDeadlineMilliseconds: parseLeaseDeadline(claim.leaseExpiresAt),
10312
10317
  nativeThreadId: durable.snapshot().nativeThreadId ?? claim.nativeThreadId,
10313
10318
  processQuarantined: false,
10319
+ remoteImageSourceUrls: /* @__PURE__ */ new Map(),
10314
10320
  spoolQueue: Promise.resolve(),
10315
10321
  subagentThreadIds: /* @__PURE__ */ new Set(),
10316
10322
  terminal,
@@ -10497,36 +10503,42 @@ function requireTurnId2(response) {
10497
10503
  }
10498
10504
  return id;
10499
10505
  }
10500
- async function toCodexInput(items, pairedRoot, relativeWorkingDirectory) {
10506
+ async function toCodexInput(items, pairedRoot, relativeWorkingDirectory, signal, remoteImageSourceUrls) {
10501
10507
  const source = await LocalFileSource.create(pairedRoot, relativeWorkingDirectory);
10502
- return await Promise.all(items.map(async (item) => {
10508
+ const input = [];
10509
+ for (const item of items) {
10503
10510
  const payload = safeRecord2(item.payload);
10504
10511
  if (item.itemType === "text") {
10505
- return {
10512
+ input.push({
10506
10513
  type: "text",
10507
10514
  text: optionalString3(payload.text).value ?? "",
10508
10515
  text_elements: []
10509
- };
10516
+ });
10517
+ continue;
10510
10518
  }
10511
10519
  if (item.itemType === "image") {
10512
10520
  const url = optionalString3(payload.url).value;
10513
- if (url === void 0 || !isSecureImageUrl(url)) {
10514
- throw new Error("Remote image input requires a valid HTTPS URL");
10521
+ if (url === void 0) {
10522
+ throw new Error("Remote image input has no URL");
10515
10523
  }
10516
- return {
10524
+ const dataUrl = await downloadRemoteImageDataUrl(url, signal);
10525
+ remoteImageSourceUrls.set(dataUrl, url);
10526
+ input.push({
10517
10527
  type: "image",
10518
- url
10519
- };
10528
+ url: dataUrl
10529
+ });
10530
+ continue;
10520
10531
  }
10521
10532
  if (item.itemType === "local_image") {
10522
10533
  const path4 = optionalString3(payload.path).value;
10523
10534
  if (path4 === void 0)
10524
10535
  throw new Error("Local image input has no path");
10525
10536
  await source.validateImage(path4);
10526
- return {
10537
+ input.push({
10527
10538
  type: "localImage",
10528
10539
  path: path4
10529
- };
10540
+ });
10541
+ continue;
10530
10542
  }
10531
10543
  if (item.itemType === "local_file") {
10532
10544
  const path4 = optionalString3(payload.path).value;
@@ -10534,21 +10546,69 @@ async function toCodexInput(items, pairedRoot, relativeWorkingDirectory) {
10534
10546
  throw new Error("Local file input has no path");
10535
10547
  const kind = payload.kind === "directory" ? "directory" : "file";
10536
10548
  await source.validate(path4, kind);
10537
- return {
10549
+ input.push({
10538
10550
  type: "text",
10539
10551
  text: `@${path4}${kind === "directory" && !path4.endsWith("/") ? "/" : ""}`,
10540
10552
  text_elements: []
10541
- };
10553
+ });
10554
+ continue;
10542
10555
  }
10543
10556
  throw new Error(`Unsupported Local Codex input ${item.itemType}`);
10544
- }));
10557
+ }
10558
+ return input;
10545
10559
  }
10546
- function isSecureImageUrl(value) {
10560
+ async function downloadRemoteImageDataUrl(value, signal) {
10561
+ const url = trustedRemoteImageUrl(value);
10562
+ const response = await fetch(url, {
10563
+ redirect: "error",
10564
+ signal: AbortSignal.any([signal, AbortSignal.timeout(remoteImageDownloadTimeoutMilliseconds)])
10565
+ });
10566
+ if (!response.ok) {
10567
+ await response.body?.cancel();
10568
+ throw new Error(`Remote image download failed with HTTP ${response.status}`);
10569
+ }
10570
+ const mimeType = response.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
10571
+ if (mimeType === void 0 || !allowedRemoteImageMimeTypes.has(mimeType)) {
10572
+ await response.body?.cancel();
10573
+ throw new Error("Remote image response has an unsupported content type");
10574
+ }
10575
+ const contentLength = Number(response.headers.get("content-length"));
10576
+ if (Number.isFinite(contentLength) && contentLength > maximumRemoteImageBytes) {
10577
+ await response.body?.cancel();
10578
+ throw new Error("Remote image exceeds the 20 MiB limit");
10579
+ }
10580
+ if (response.body === null) {
10581
+ throw new Error("Remote image response has no body");
10582
+ }
10583
+ const reader = response.body.getReader();
10584
+ const chunks = [];
10585
+ let byteLength = 0;
10586
+ while (true) {
10587
+ const result = await reader.read();
10588
+ if (result.done) {
10589
+ break;
10590
+ }
10591
+ byteLength += result.value.byteLength;
10592
+ if (byteLength > maximumRemoteImageBytes) {
10593
+ await reader.cancel();
10594
+ throw new Error("Remote image exceeds the 20 MiB limit");
10595
+ }
10596
+ chunks.push(result.value);
10597
+ }
10598
+ if (byteLength === 0) {
10599
+ throw new Error("Remote image response is empty");
10600
+ }
10601
+ return `data:${mimeType};base64,${Buffer.concat(chunks, byteLength).toString("base64")}`;
10602
+ }
10603
+ function trustedRemoteImageUrl(value) {
10547
10604
  try {
10548
10605
  const url = new URL(value);
10549
- return url.protocol === "https:" && url.username === "" && url.password === "" && url.hostname !== "";
10606
+ if (url.protocol !== "https:" || url.username !== "" || url.password !== "" || url.port !== "" || !allowedRemoteImageHosts.has(url.hostname) || !url.pathname.startsWith("/public/resource/")) {
10607
+ throw new Error("Remote image input requires a trusted Moxt image URL");
10608
+ }
10609
+ return url;
10550
10610
  } catch {
10551
- return false;
10611
+ throw new Error("Remote image input requires a trusted Moxt image URL");
10552
10612
  }
10553
10613
  }
10554
10614
  function localCodexInputItems(value) {
@@ -10784,7 +10844,7 @@ function parseLeaseDeadline(value) {
10784
10844
  function routineLeaseRenewalDelayMilliseconds(remainingLeaseMilliseconds) {
10785
10845
  return Math.min(leaseRenewIntervalMilliseconds, Math.max(1, Math.floor(remainingLeaseMilliseconds / leaseRenewalIntervalsBeforeDeadline)));
10786
10846
  }
10787
- var import_node_child_process4, import_promises13, import_node_os7, import_node_path11, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, maximumDiscoveryDirectories, maximumDiscoveryModels, maximumModelListPages, eventUploadCoalesceMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewalIntervalsBeforeDeadline, defaultNetworkRetryMilliseconds2, maximumNetworkRetryMilliseconds2, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryScanIntervalMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, maximumThreadTitleCharacters, maximumThreadTitleSourceCharacters, threadTitleGenerationTimeoutMilliseconds, interruptedExecutionCleanupTimeoutMilliseconds, threadTitleGenerationInstructions, threadTitleGenerationOutputSchema, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, WorkerStoppedError, LocalCodexRuntimeConnectionWorker;
10847
+ var import_node_child_process4, import_promises13, import_node_os7, import_node_path11, heartbeatIntervalMilliseconds, claimRetryMilliseconds, claimWaitSeconds, maximumDiscoveryDirectories, maximumDiscoveryModels, maximumModelListPages, eventUploadCoalesceMilliseconds, maximumEventUploadCount, preferredEventUploadRequestBytes, leaseRenewIntervalMilliseconds, leaseRenewalIntervalsBeforeDeadline, defaultNetworkRetryMilliseconds2, maximumNetworkRetryMilliseconds2, interactionTimeoutMilliseconds, executableProbeTimeoutMilliseconds, recoveryScanIntervalMilliseconds, initialThreadNameRetryMilliseconds, maximumThreadNameRetryMilliseconds, maximumInitialThreadNameAttempts, maximumThreadTitleCharacters, maximumThreadTitleSourceCharacters, threadTitleGenerationTimeoutMilliseconds, interruptedExecutionCleanupTimeoutMilliseconds, remoteImageDownloadTimeoutMilliseconds, maximumRemoteImageBytes, allowedRemoteImageMimeTypes, allowedRemoteImageHosts, threadTitleGenerationInstructions, threadTitleGenerationOutputSchema, ThreadUnavailableError, LeaseLostError, SpoolPersistenceError, UnknownTurnStartResultError, WorkerStoppedError, LocalCodexRuntimeConnectionWorker;
10788
10848
  var init_runtime_worker = __esm({
10789
10849
  "../machine-connector/dist/runtime/local-codex-runtime/runtime-worker.js"() {
10790
10850
  "use strict";
@@ -10825,6 +10885,18 @@ var init_runtime_worker = __esm({
10825
10885
  maximumThreadTitleSourceCharacters = 4e3;
10826
10886
  threadTitleGenerationTimeoutMilliseconds = 2e4;
10827
10887
  interruptedExecutionCleanupTimeoutMilliseconds = 3e3;
10888
+ remoteImageDownloadTimeoutMilliseconds = 3e4;
10889
+ maximumRemoteImageBytes = 20 * 1024 * 1024;
10890
+ allowedRemoteImageMimeTypes = /* @__PURE__ */ new Set([
10891
+ "image/gif",
10892
+ "image/jpeg",
10893
+ "image/png",
10894
+ "image/webp"
10895
+ ]);
10896
+ allowedRemoteImageHosts = /* @__PURE__ */ new Set([
10897
+ "static-dev.moxtcontent.com",
10898
+ "static.moxtcontent.com"
10899
+ ]);
10828
10900
  threadTitleGenerationInstructions = "Generate a concise semantic UI title for a coding conversation from its opening request. Use the request language. Prefer a specific noun phrase over a sentence, omit filler and incidental identifiers, and do not copy the full request unless it is already concise. Return only the structured result.";
10829
10901
  threadTitleGenerationOutputSchema = {
10830
10902
  additionalProperties: false,
@@ -10979,7 +11051,7 @@ var init_runtime_worker = __esm({
10979
11051
  if (captureThreadTitleGenerationNotification(active, message)) {
10980
11052
  return;
10981
11053
  }
10982
- const normalized = normalizeAppServerNotification(message, active.workingDirectory).value;
11054
+ const normalized = normalizeAppServerNotification(message, active.workingDirectory, active.remoteImageSourceUrls).value;
10983
11055
  if (normalized === void 0) {
10984
11056
  return;
10985
11057
  }
@@ -11440,7 +11512,7 @@ var init_runtime_worker = __esm({
11440
11512
  approvalPolicy: claim.approvalPolicy,
11441
11513
  cwd: active.workingDirectory,
11442
11514
  effort: claim.reasoningEffort,
11443
- input: await toCodexInput(claim.inputItems, this.connection.rootPath, claim.relativeWorkingDirectory),
11515
+ input: await toCodexInput(claim.inputItems, this.connection.rootPath, claim.relativeWorkingDirectory, active.finished.signal, active.remoteImageSourceUrls),
11444
11516
  ...claim.model === void 0 ? {} : { model: claim.model },
11445
11517
  sandboxPolicy: toSandboxPolicy(claim.sandboxPolicy, active.workingDirectory),
11446
11518
  summary: "auto",
@@ -11851,7 +11923,7 @@ var init_runtime_worker = __esm({
11851
11923
  const response = await client.request("turn/steer", {
11852
11924
  clientUserMessageId: clientMessageId,
11853
11925
  expectedTurnId: active.nativeTurnId,
11854
- input: await toCodexInput(inputItems, this.connection.rootPath, active.claim.relativeWorkingDirectory),
11926
+ input: await toCodexInput(inputItems, this.connection.rootPath, active.claim.relativeWorkingDirectory, active.finished.signal, active.remoteImageSourceUrls),
11855
11927
  threadId: active.nativeThreadId
11856
11928
  });
11857
11929
  if (response.turnId !== active.nativeTurnId) {
@@ -16535,7 +16607,7 @@ function getApiKeyOrUndefined() {
16535
16607
 
16536
16608
  // src/utils/http.ts
16537
16609
  function getUserAgent() {
16538
- return `moxt-cli/${"0.12.0"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
16610
+ return `moxt-cli/${"0.12.1"} (${(0, import_os.platform)()}/${(0, import_os.arch)()}) node/${process.versions.node}`;
16539
16611
  }
16540
16612
  async function sendRequest(method, path4, init) {
16541
16613
  return await fetch(`${getApiBaseUrl()}${path4}`, {
@@ -31121,7 +31193,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
31121
31193
  var MAX_BATCH_SIZE = 100;
31122
31194
  function commonLabels() {
31123
31195
  return {
31124
- cli_version: "0.12.0",
31196
+ cli_version: "0.12.1",
31125
31197
  node_version: process.versions.node,
31126
31198
  os: (0, import_node_os11.platform)(),
31127
31199
  arch: (0, import_node_os11.arch)(),
@@ -31167,7 +31239,7 @@ async function flush() {
31167
31239
  }
31168
31240
  const batch = buffer.splice(0, MAX_BATCH_SIZE);
31169
31241
  const payload = {
31170
- release_id: "0.12.0",
31242
+ release_id: "0.12.1",
31171
31243
  client_type: "cli",
31172
31244
  metric_data_list: batch.map((m) => ({
31173
31245
  profile: "cli",
@@ -31550,9 +31622,9 @@ function commandPath3(command) {
31550
31622
  }
31551
31623
 
31552
31624
  // src/index.ts
31553
- var program2 = createProgram("0.12.0");
31554
- installDaemonReconcileHook(program2, "0.12.0");
31555
- installUpdateHook(program2, "0.12.0");
31625
+ var program2 = createProgram("0.12.1");
31626
+ installDaemonReconcileHook(program2, "0.12.1");
31627
+ installUpdateHook(program2, "0.12.1");
31556
31628
  instrumentProgram(program2);
31557
31629
  installExitHandler();
31558
31630
  program2.parseAsync(process.argv).then(async () => {