// Force strict mode and setup for ESM
"use strict";
import {
  init_esbuild_shims
} from "./chunk-5O2XNYP6.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/cli/src/serve/channel-worker-env.ts
init_esbuild_shims();
var CHANNEL_DAEMON_WORKER_SENTINEL = "QWEN_CHANNEL_DAEMON_WORKER";
var CHANNEL_WORKER_HEARTBEAT_INTERVAL_MS = 15e3;
var QWEN_DAEMON_TOKEN_ENV = "QWEN_DAEMON_TOKEN";
var QWEN_DAEMON_URL_ENV = "QWEN_DAEMON_URL";
var QWEN_DAEMON_WORKSPACE_ENV = "QWEN_DAEMON_WORKSPACE";
var QWEN_SERVER_TOKEN_ENV = "QWEN_SERVER_TOKEN";

// packages/cli/src/serve/channel-webhook-ipc.ts
init_esbuild_shims();
import { randomUUID } from "node:crypto";
var CHANNEL_WEBHOOK_ENQUEUE_ERROR_CODES = /* @__PURE__ */ new Set([
  "channel_worker_unavailable",
  "channel_webhook_enqueue_timeout",
  "channel_webhook_queue_full",
  "channel_webhook_target_unavailable",
  "channel_webhook_invalid_task",
  "channel_webhook_enqueue_failed"
]);
var ChannelWebhookEnqueueError = class extends Error {
  constructor(code, message) {
    super(message);
    this.code = code;
    this.name = "ChannelWebhookEnqueueError";
  }
  static {
    __name(this, "ChannelWebhookEnqueueError");
  }
};
function isChannelWebhookEnqueueErrorCode(value) {
  return typeof value === "string" && CHANNEL_WEBHOOK_ENQUEUE_ERROR_CODES.has(value);
}
__name(isChannelWebhookEnqueueErrorCode, "isChannelWebhookEnqueueErrorCode");
function isChannelWebhookEnqueueError(value) {
  return value instanceof ChannelWebhookEnqueueError || typeof value === "object" && value !== null && isChannelWebhookEnqueueErrorCode(value.code) && typeof value.message === "string";
}
__name(isChannelWebhookEnqueueError, "isChannelWebhookEnqueueError");
var CHANNEL_WEBHOOK_TASK_IPC_TIMEOUT_MS = 3e4;
function createChannelWebhookTaskMessage(task) {
  return {
    type: "webhook_task",
    id: randomUUID(),
    expiresAt: Date.now() + CHANNEL_WEBHOOK_TASK_IPC_TIMEOUT_MS,
    task
  };
}
__name(createChannelWebhookTaskMessage, "createChannelWebhookTaskMessage");
function isChannelWebhookTaskMessage(value) {
  return typeof value === "object" && value !== null && value.type === "webhook_task" && typeof value.id === "string" && typeof value.expiresAt === "number" && typeof value.task === "object" && value.task !== null;
}
__name(isChannelWebhookTaskMessage, "isChannelWebhookTaskMessage");
function isChannelWebhookTaskResultMessage(value) {
  return typeof value === "object" && value !== null && value.type === "webhook_task_result" && typeof value.id === "string" && typeof value.ok === "boolean";
}
__name(isChannelWebhookTaskResultMessage, "isChannelWebhookTaskResultMessage");

export {
  CHANNEL_DAEMON_WORKER_SENTINEL,
  CHANNEL_WORKER_HEARTBEAT_INTERVAL_MS,
  QWEN_DAEMON_TOKEN_ENV,
  QWEN_DAEMON_URL_ENV,
  QWEN_DAEMON_WORKSPACE_ENV,
  QWEN_SERVER_TOKEN_ENV,
  ChannelWebhookEnqueueError,
  isChannelWebhookEnqueueErrorCode,
  isChannelWebhookEnqueueError,
  CHANNEL_WEBHOOK_TASK_IPC_TIMEOUT_MS,
  createChannelWebhookTaskMessage,
  isChannelWebhookTaskMessage,
  isChannelWebhookTaskResultMessage
};
