UNPKG

opencoder

Version:
1,674 lines (1,658 loc) 6.17 MB
import { __commonJS, __esm, __export, __require, __toCommonJS, __toESM } from "./chunk-BlwiYZwt.js"; import "./source-map-support-BDjyShzz.js"; import "./register-DzYslTyX.js"; import { createStorage, fs_lite_default } from "./fs-lite-Dv4pJOKv.js"; import { import_react, import_react$1, require_react, z } from "./react-CmaS1f3l.js"; import { InvalidArgumentError, JSONParseError, TypeValidationError, dedent_default, import_jsx_runtime as import_jsx_runtime$1, import_jsx_runtime$1 as import_jsx_runtime } from "./jsx-runtime-DieFuC91.js"; import { createRequire } from "node:module"; import fs, { readFile, writeFile } from "node:fs/promises"; import * as os$5 from "os"; import * as os2 from "os"; import * as os4 from "os"; import * as os6 from "os"; import os3, { EOL, platform, release, tmpdir, uptime } from "os"; import path, { basename, dirname, extname, isAbsolute, join, relative, resolve } from "path"; import * as fs$11 from "node:fs"; import fs$1, { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import path$1, { dirname as dirname$1, extname as extname$1, isAbsolute as isAbsolute$1, join as join$1, relative as relative$1, resolve as resolve$1 } from "node:path"; import * as fs5 from "fs"; import * as fs$10 from "fs"; import * as fs2 from "fs"; import * as fs3 from "fs"; import * as fs4 from "fs"; import * as fs7 from "fs"; import * as fs9 from "fs"; import * as fs10 from "fs"; import * as fs12 from "fs"; import * as fs14 from "fs"; import * as fs15 from "fs"; import * as fs17 from "fs"; import * as fs19 from "fs"; import * as fs20 from "fs"; import * as fs22 from "fs"; import * as fs24 from "fs"; import * as fs25 from "fs"; import * as fs26 from "fs"; import * as fs28 from "fs"; import * as fs30 from "fs"; import * as fs32 from "fs"; import fs34, { constants, existsSync as existsSync$1, fdatasync, fdatasyncSync, fstatSync, fsync, fsyncSync, ftruncate, ftruncateSync, lstatSync, mkdirSync as mkdirSync$1, mkdtempSync, open, openSync, read, readFileSync as readFileSync$1, readdirSync, writeFileSync as writeFileSync$1 } from "fs"; import { anthropic } from "@ai-sdk/anthropic"; import { appendResponseMessages, createDataStreamResponse, createIdGenerator, embed, simulateStreamingMiddleware, streamText, wrapLanguageModel } from "ai"; import childProcess, { spawnSync } from "child_process"; import url, { fileURLToPath, pathToFileURL } from "url"; import * as stream$1 from "stream"; import stream2 from "stream"; import * as util$2 from "util"; import { promisify } from "util"; import { PassThrough, Readable, Stream, Writable } from "node:stream"; import process$1, { cwd, env } from "node:process"; import { once } from "events"; import cliBoxes from "cli-boxes"; import os from "node:os"; import tty from "node:tty"; import { EventEmitter, on, once as once$1 } from "node:events"; import { Buffer as Buffer$1 } from "node:buffer"; import * as fs6 from "fs/promises"; import * as fs8 from "fs/promises"; import * as fs11 from "fs/promises"; import * as fs13 from "fs/promises"; import * as fs16 from "fs/promises"; import * as fs18 from "fs/promises"; import * as fs21 from "fs/promises"; import * as fs23 from "fs/promises"; import * as fs29 from "fs/promises"; import * as fs31 from "fs/promises"; import * as fs33 from "fs/promises"; import { mkdir as mkdir$1, mkdtemp, opendir, readFile as readFile$1, rename, rm, rmdir, stat, watch } from "fs/promises"; import tty$1, { isatty } from "tty"; import ps from "process"; import { Socket, createConnection, createServer } from "net"; import { connect, createServer as createServer$1 } from "tls"; import dns from "dns"; import { ReadableStream as ReadableStream$1, TextDecoderStream as TextDecoderStream$1, TransformStream as TransformStream$1, WritableStream as WritableStream$1 } from "node:stream/web"; import * as cp from "node:child_process"; import { execFile } from "node:child_process"; import { fileURLToPath as fileURLToPath$1 } from "node:url"; import assert from "node:assert"; import { inspect, promisify as promisify$1 } from "node:util"; import lancedb from "@lancedb/lancedb"; import { finished } from "node:stream/promises"; import { rgPath } from "@vscode/ripgrep"; import { AsyncLocalStorage } from "async_hooks"; //#region node_modules/@tanstack/query-core/build/modern/subscribable.js var Subscribable = class { constructor() { this.listeners = /* @__PURE__ */ new Set(); this.subscribe = this.subscribe.bind(this); } subscribe(listener) { this.listeners.add(listener); this.onSubscribe(); return () => { this.listeners.delete(listener); this.onUnsubscribe(); }; } hasListeners() { return this.listeners.size > 0; } onSubscribe() {} onUnsubscribe() {} }; //#endregion //#region node_modules/@tanstack/query-core/build/modern/utils.js var isServer = typeof window === "undefined" || "Deno" in globalThis; function noop$6() {} function functionalUpdate(updater, input) { return typeof updater === "function" ? updater(input) : updater; } function isValidTimeout(value$1) { return typeof value$1 === "number" && value$1 >= 0 && value$1 !== Infinity; } function timeUntilStale(updatedAt, staleTime) { return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0); } function resolveStaleTime(staleTime, query) { return typeof staleTime === "function" ? staleTime(query) : staleTime; } function resolveEnabled(enabled$1, query) { return typeof enabled$1 === "function" ? enabled$1(query) : enabled$1; } function matchQuery(filters, query) { const { type: type$1 = "all", exact, fetchStatus, predicate, queryKey, stale } = filters; if (queryKey) { if (exact) { if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) return false; } else if (!partialMatchKey(query.queryKey, queryKey)) return false; } if (type$1 !== "all") { const isActive = query.isActive(); if (type$1 === "active" && !isActive) return false; if (type$1 === "inactive" && isActive) return false; } if (typeof stale === "boolean" && query.isStale() !== stale) return false; if (fetchStatus && fetchStatus !== query.state.fetchStatus) return false; if (predicate && !predicate(query)) return false; return true; } function matchMutation(filters, mutation) { const { exact, status, predicate, mutationKey } = filters; if (mutationKey) { if (!mutation.options.mutationKey) return false; if (exact) { if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) return false; } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) return false; } if (status && mutation.state.status !== status) return false; if (predicate && !predicate(mutation)) return false; return true; } function hashQueryKeyByOptions(queryKey, options$1) { const hashFn = options$1?.queryKeyHashFn || hashKey; return hashFn(queryKey); } function hashKey(queryKey) { return JSON.stringify(queryKey, (_$1, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => { result[key] = val[key]; return result; }, {}) : val); } function partialMatchKey(a$1, b$1) { if (a$1 === b$1) return true; if (typeof a$1 != typeof b$1) return false; if (a$1 && b$1 && typeof a$1 === "object" && typeof b$1 === "object") return Object.keys(b$1).every((key) => partialMatchKey(a$1[key], b$1[key])); return false; } function replaceEqualDeep(a$1, b$1) { if (a$1 === b$1) return a$1; const array$1 = isPlainArray(a$1) && isPlainArray(b$1); if (array$1 || isPlainObject(a$1) && isPlainObject(b$1)) { const aItems = array$1 ? a$1 : Object.keys(a$1); const aSize = aItems.length; const bItems = array$1 ? b$1 : Object.keys(b$1); const bSize = bItems.length; const copy$2 = array$1 ? [] : {}; let equalItems = 0; for (let i$1 = 0; i$1 < bSize; i$1++) { const key = array$1 ? i$1 : bItems[i$1]; if ((!array$1 && aItems.includes(key) || array$1) && a$1[key] === void 0 && b$1[key] === void 0) { copy$2[key] = void 0; equalItems++; } else { copy$2[key] = replaceEqualDeep(a$1[key], b$1[key]); if (copy$2[key] === a$1[key] && a$1[key] !== void 0) equalItems++; } } return aSize === bSize && equalItems === aSize ? a$1 : copy$2; } return b$1; } function shallowEqualObjects(a$1, b$1) { if (!b$1 || Object.keys(a$1).length !== Object.keys(b$1).length) return false; for (const key in a$1) if (a$1[key] !== b$1[key]) return false; return true; } function isPlainArray(value$1) { return Array.isArray(value$1) && value$1.length === Object.keys(value$1).length; } function isPlainObject(o$1) { if (!hasObjectPrototype(o$1)) return false; const ctor = o$1.constructor; if (ctor === void 0) return true; const prot = ctor.prototype; if (!hasObjectPrototype(prot)) return false; if (!prot.hasOwnProperty("isPrototypeOf")) return false; if (Object.getPrototypeOf(o$1) !== Object.prototype) return false; return true; } function hasObjectPrototype(o$1) { return Object.prototype.toString.call(o$1) === "[object Object]"; } function sleep$1(timeout) { return new Promise((resolve$3) => { setTimeout(resolve$3, timeout); }); } function replaceData(prevData, data, options$1) { if (typeof options$1.structuralSharing === "function") return options$1.structuralSharing(prevData, data); else if (options$1.structuralSharing !== false) return replaceEqualDeep(prevData, data); return data; } function addToEnd(items, item, max = 0) { const newItems = [...items, item]; return max && newItems.length > max ? newItems.slice(1) : newItems; } function addToStart(items, item, max = 0) { const newItems = [item, ...items]; return max && newItems.length > max ? newItems.slice(0, -1) : newItems; } var skipToken = Symbol(); function ensureQueryFn(options$1, fetchOptions) { if (!options$1.queryFn && fetchOptions?.initialPromise) return () => fetchOptions.initialPromise; if (!options$1.queryFn || options$1.queryFn === skipToken) return () => Promise.reject(new Error(`Missing queryFn: '${options$1.queryHash}'`)); return options$1.queryFn; } //#endregion //#region node_modules/@tanstack/query-core/build/modern/focusManager.js var FocusManager = class extends Subscribable { #focused; #cleanup; #setup; constructor() { super(); this.#setup = (onFocus) => { if (!isServer && window.addEventListener) { const listener = () => onFocus(); window.addEventListener("visibilitychange", listener, false); return () => { window.removeEventListener("visibilitychange", listener); }; } return; }; } onSubscribe() { if (!this.#cleanup) this.setEventListener(this.#setup); } onUnsubscribe() { if (!this.hasListeners()) { this.#cleanup?.(); this.#cleanup = void 0; } } setEventListener(setup) { this.#setup = setup; this.#cleanup?.(); this.#cleanup = setup((focused) => { if (typeof focused === "boolean") this.setFocused(focused); else this.onFocus(); }); } setFocused(focused) { const changed = this.#focused !== focused; if (changed) { this.#focused = focused; this.onFocus(); } } onFocus() { const isFocused = this.isFocused(); this.listeners.forEach((listener) => { listener(isFocused); }); } isFocused() { if (typeof this.#focused === "boolean") return this.#focused; return globalThis.document?.visibilityState !== "hidden"; } }; var focusManager = new FocusManager(); //#endregion //#region node_modules/@tanstack/query-core/build/modern/onlineManager.js var OnlineManager = class extends Subscribable { #online = true; #cleanup; #setup; constructor() { super(); this.#setup = (onOnline) => { if (!isServer && window.addEventListener) { const onlineListener = () => onOnline(true); const offlineListener = () => onOnline(false); window.addEventListener("online", onlineListener, false); window.addEventListener("offline", offlineListener, false); return () => { window.removeEventListener("online", onlineListener); window.removeEventListener("offline", offlineListener); }; } return; }; } onSubscribe() { if (!this.#cleanup) this.setEventListener(this.#setup); } onUnsubscribe() { if (!this.hasListeners()) { this.#cleanup?.(); this.#cleanup = void 0; } } setEventListener(setup) { this.#setup = setup; this.#cleanup?.(); this.#cleanup = setup(this.setOnline.bind(this)); } setOnline(online$1) { const changed = this.#online !== online$1; if (changed) { this.#online = online$1; this.listeners.forEach((listener) => { listener(online$1); }); } } isOnline() { return this.#online; } }; var onlineManager = new OnlineManager(); //#endregion //#region node_modules/@tanstack/query-core/build/modern/thenable.js function pendingThenable() { let resolve$3; let reject; const thenable = new Promise((_resolve, _reject) => { resolve$3 = _resolve; reject = _reject; }); thenable.status = "pending"; thenable.catch(() => {}); function finalize(data) { Object.assign(thenable, data); delete thenable.resolve; delete thenable.reject; } thenable.resolve = (value$1) => { finalize({ status: "fulfilled", value: value$1 }); resolve$3(value$1); }; thenable.reject = (reason) => { finalize({ status: "rejected", reason }); reject(reason); }; return thenable; } //#endregion //#region node_modules/@tanstack/query-core/build/modern/retryer.js function defaultRetryDelay(failureCount) { return Math.min(1e3 * 2 ** failureCount, 3e4); } function canFetch(networkMode) { return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true; } var CancelledError = class extends Error { constructor(options$1) { super("CancelledError"); this.revert = options$1?.revert; this.silent = options$1?.silent; } }; function isCancelledError(value$1) { return value$1 instanceof CancelledError; } function createRetryer(config$2) { let isRetryCancelled = false; let failureCount = 0; let isResolved = false; let continueFn; const thenable = pendingThenable(); const cancel = (cancelOptions) => { if (!isResolved) { reject(new CancelledError(cancelOptions)); config$2.abort?.(); } }; const cancelRetry = () => { isRetryCancelled = true; }; const continueRetry = () => { isRetryCancelled = false; }; const canContinue = () => focusManager.isFocused() && (config$2.networkMode === "always" || onlineManager.isOnline()) && config$2.canRun(); const canStart = () => canFetch(config$2.networkMode) && config$2.canRun(); const resolve$3 = (value$1) => { if (!isResolved) { isResolved = true; config$2.onSuccess?.(value$1); continueFn?.(); thenable.resolve(value$1); } }; const reject = (value$1) => { if (!isResolved) { isResolved = true; config$2.onError?.(value$1); continueFn?.(); thenable.reject(value$1); } }; const pause = () => { return new Promise((continueResolve) => { continueFn = (value$1) => { if (isResolved || canContinue()) continueResolve(value$1); }; config$2.onPause?.(); }).then(() => { continueFn = void 0; if (!isResolved) config$2.onContinue?.(); }); }; const run$2 = () => { if (isResolved) return; let promiseOrValue; const initialPromise = failureCount === 0 ? config$2.initialPromise : void 0; try { promiseOrValue = initialPromise ?? config$2.fn(); } catch (error$1) { promiseOrValue = Promise.reject(error$1); } Promise.resolve(promiseOrValue).then(resolve$3).catch((error$1) => { if (isResolved) return; const retry = config$2.retry ?? (isServer ? 0 : 3); const retryDelay = config$2.retryDelay ?? defaultRetryDelay; const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error$1) : retryDelay; const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error$1); if (isRetryCancelled || !shouldRetry) { reject(error$1); return; } failureCount++; config$2.onFail?.(failureCount, error$1); sleep$1(delay).then(() => { return canContinue() ? void 0 : pause(); }).then(() => { if (isRetryCancelled) reject(error$1); else run$2(); }); }); }; return { promise: thenable, cancel, continue: () => { continueFn?.(); return thenable; }, cancelRetry, continueRetry, canStart, start: () => { if (canStart()) run$2(); else pause().then(run$2); return thenable; } }; } //#endregion //#region node_modules/@tanstack/query-core/build/modern/notifyManager.js var defaultScheduler = (cb) => setTimeout(cb, 0); function createNotifyManager() { let queue = []; let transactions = 0; let notifyFn = (callback) => { callback(); }; let batchNotifyFn = (callback) => { callback(); }; let scheduleFn = defaultScheduler; const schedule = (callback) => { if (transactions) queue.push(callback); else scheduleFn(() => { notifyFn(callback); }); }; const flush = () => { const originalQueue = queue; queue = []; if (originalQueue.length) scheduleFn(() => { batchNotifyFn(() => { originalQueue.forEach((callback) => { notifyFn(callback); }); }); }); }; return { batch: (callback) => { let result; transactions++; try { result = callback(); } finally { transactions--; if (!transactions) flush(); } return result; }, batchCalls: (callback) => { return (...args$1) => { schedule(() => { callback(...args$1); }); }; }, schedule, setNotifyFunction: (fn) => { notifyFn = fn; }, setBatchNotifyFunction: (fn) => { batchNotifyFn = fn; }, setScheduler: (fn) => { scheduleFn = fn; } }; } var notifyManager = createNotifyManager(); //#endregion //#region node_modules/@tanstack/query-core/build/modern/removable.js var Removable = class { #gcTimeout; destroy() { this.clearGcTimeout(); } scheduleGc() { this.clearGcTimeout(); if (isValidTimeout(this.gcTime)) this.#gcTimeout = setTimeout(() => { this.optionalRemove(); }, this.gcTime); } updateGcTime(newGcTime) { this.gcTime = Math.max(this.gcTime || 0, newGcTime ?? (isServer ? Infinity : 5 * 60 * 1e3)); } clearGcTimeout() { if (this.#gcTimeout) { clearTimeout(this.#gcTimeout); this.#gcTimeout = void 0; } } }; //#endregion //#region node_modules/@tanstack/query-core/build/modern/query.js var Query = class extends Removable { #initialState; #revertState; #cache; #client; #retryer; #defaultOptions; #abortSignalConsumed; constructor(config$2) { super(); this.#abortSignalConsumed = false; this.#defaultOptions = config$2.defaultOptions; this.setOptions(config$2.options); this.observers = []; this.#client = config$2.client; this.#cache = this.#client.getQueryCache(); this.queryKey = config$2.queryKey; this.queryHash = config$2.queryHash; this.#initialState = getDefaultState$1(this.options); this.state = config$2.state ?? this.#initialState; this.scheduleGc(); } get meta() { return this.options.meta; } get promise() { return this.#retryer?.promise; } setOptions(options$1) { this.options = { ...this.#defaultOptions, ...options$1 }; this.updateGcTime(this.options.gcTime); } optionalRemove() { if (!this.observers.length && this.state.fetchStatus === "idle") this.#cache.remove(this); } setData(newData, options$1) { const data = replaceData(this.state.data, newData, this.options); this.#dispatch({ data, type: "success", dataUpdatedAt: options$1?.updatedAt, manual: options$1?.manual }); return data; } setState(state, setStateOptions) { this.#dispatch({ type: "setState", state, setStateOptions }); } cancel(options$1) { const promise$1 = this.#retryer?.promise; this.#retryer?.cancel(options$1); return promise$1 ? promise$1.then(noop$6).catch(noop$6) : Promise.resolve(); } destroy() { super.destroy(); this.cancel({ silent: true }); } reset() { this.destroy(); this.setState(this.#initialState); } isActive() { return this.observers.some((observer) => resolveEnabled(observer.options.enabled, this) !== false); } isDisabled() { if (this.getObserversCount() > 0) return !this.isActive(); return this.options.queryFn === skipToken || this.state.dataUpdateCount + this.state.errorUpdateCount === 0; } isStale() { if (this.state.isInvalidated) return true; if (this.getObserversCount() > 0) return this.observers.some((observer) => observer.getCurrentResult().isStale); return this.state.data === void 0; } isStaleByTime(staleTime = 0) { return this.state.isInvalidated || this.state.data === void 0 || !timeUntilStale(this.state.dataUpdatedAt, staleTime); } onFocus() { const observer = this.observers.find((x$1) => x$1.shouldFetchOnWindowFocus()); observer?.refetch({ cancelRefetch: false }); this.#retryer?.continue(); } onOnline() { const observer = this.observers.find((x$1) => x$1.shouldFetchOnReconnect()); observer?.refetch({ cancelRefetch: false }); this.#retryer?.continue(); } addObserver(observer) { if (!this.observers.includes(observer)) { this.observers.push(observer); this.clearGcTimeout(); this.#cache.notify({ type: "observerAdded", query: this, observer }); } } removeObserver(observer) { if (this.observers.includes(observer)) { this.observers = this.observers.filter((x$1) => x$1 !== observer); if (!this.observers.length) { if (this.#retryer) if (this.#abortSignalConsumed) this.#retryer.cancel({ revert: true }); else this.#retryer.cancelRetry(); this.scheduleGc(); } this.#cache.notify({ type: "observerRemoved", query: this, observer }); } } getObserversCount() { return this.observers.length; } invalidate() { if (!this.state.isInvalidated) this.#dispatch({ type: "invalidate" }); } fetch(options$1, fetchOptions) { if (this.state.fetchStatus !== "idle") { if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) this.cancel({ silent: true }); else if (this.#retryer) { this.#retryer.continueRetry(); return this.#retryer.promise; } } if (options$1) this.setOptions(options$1); if (!this.options.queryFn) { const observer = this.observers.find((x$1) => x$1.options.queryFn); if (observer) this.setOptions(observer.options); } const abortController = new AbortController(); const addSignalProperty = (object) => { Object.defineProperty(object, "signal", { enumerable: true, get: () => { this.#abortSignalConsumed = true; return abortController.signal; } }); }; const fetchFn = () => { const queryFn = ensureQueryFn(this.options, fetchOptions); const queryFnContext = { client: this.#client, queryKey: this.queryKey, meta: this.meta }; addSignalProperty(queryFnContext); this.#abortSignalConsumed = false; if (this.options.persister) return this.options.persister(queryFn, queryFnContext, this); return queryFn(queryFnContext); }; const context = { fetchOptions, options: this.options, queryKey: this.queryKey, client: this.#client, state: this.state, fetchFn }; addSignalProperty(context); this.options.behavior?.onFetch(context, this); this.#revertState = this.state; if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) this.#dispatch({ type: "fetch", meta: context.fetchOptions?.meta }); const onError$1 = (error$1) => { if (!(isCancelledError(error$1) && error$1.silent)) this.#dispatch({ type: "error", error: error$1 }); if (!isCancelledError(error$1)) { this.#cache.config.onError?.(error$1, this); this.#cache.config.onSettled?.(this.state.data, error$1, this); } this.scheduleGc(); }; this.#retryer = createRetryer({ initialPromise: fetchOptions?.initialPromise, fn: context.fetchFn, abort: abortController.abort.bind(abortController), onSuccess: (data) => { if (data === void 0) { onError$1(new Error(`${this.queryHash} data is undefined`)); return; } try { this.setData(data); } catch (error$1) { onError$1(error$1); return; } this.#cache.config.onSuccess?.(data, this); this.#cache.config.onSettled?.(data, this.state.error, this); this.scheduleGc(); }, onError: onError$1, onFail: (failureCount, error$1) => { this.#dispatch({ type: "failed", failureCount, error: error$1 }); }, onPause: () => { this.#dispatch({ type: "pause" }); }, onContinue: () => { this.#dispatch({ type: "continue" }); }, retry: context.options.retry, retryDelay: context.options.retryDelay, networkMode: context.options.networkMode, canRun: () => true }); return this.#retryer.start(); } #dispatch(action) { const reducer = (state) => { switch (action.type) { case "failed": return { ...state, fetchFailureCount: action.failureCount, fetchFailureReason: action.error }; case "pause": return { ...state, fetchStatus: "paused" }; case "continue": return { ...state, fetchStatus: "fetching" }; case "fetch": return { ...state, ...fetchState(state.data, this.options), fetchMeta: action.meta ?? null }; case "success": return { ...state, data: action.data, dataUpdateCount: state.dataUpdateCount + 1, dataUpdatedAt: action.dataUpdatedAt ?? Date.now(), error: null, isInvalidated: false, status: "success", ...!action.manual && { fetchStatus: "idle", fetchFailureCount: 0, fetchFailureReason: null } }; case "error": const error$1 = action.error; if (isCancelledError(error$1) && error$1.revert && this.#revertState) return { ...this.#revertState, fetchStatus: "idle" }; return { ...state, error: error$1, errorUpdateCount: state.errorUpdateCount + 1, errorUpdatedAt: Date.now(), fetchFailureCount: state.fetchFailureCount + 1, fetchFailureReason: error$1, fetchStatus: "idle", status: "error" }; case "invalidate": return { ...state, isInvalidated: true }; case "setState": return { ...state, ...action.state }; } }; this.state = reducer(this.state); notifyManager.batch(() => { this.observers.forEach((observer) => { observer.onQueryUpdate(); }); this.#cache.notify({ query: this, type: "updated", action }); }); } }; function fetchState(data, options$1) { return { fetchFailureCount: 0, fetchFailureReason: null, fetchStatus: canFetch(options$1.networkMode) ? "fetching" : "paused", ...data === void 0 && { error: null, status: "pending" } }; } function getDefaultState$1(options$1) { const data = typeof options$1.initialData === "function" ? options$1.initialData() : options$1.initialData; const hasData = data !== void 0; const initialDataUpdatedAt = hasData ? typeof options$1.initialDataUpdatedAt === "function" ? options$1.initialDataUpdatedAt() : options$1.initialDataUpdatedAt : 0; return { data, dataUpdateCount: 0, dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0, error: null, errorUpdateCount: 0, errorUpdatedAt: 0, fetchFailureCount: 0, fetchFailureReason: null, fetchMeta: null, isInvalidated: false, status: hasData ? "success" : "pending", fetchStatus: "idle" }; } //#endregion //#region node_modules/@tanstack/query-core/build/modern/queryCache.js var QueryCache = class extends Subscribable { constructor(config$2 = {}) { super(); this.config = config$2; this.#queries = /* @__PURE__ */ new Map(); } #queries; build(client, options$1, state) { const queryKey = options$1.queryKey; const queryHash = options$1.queryHash ?? hashQueryKeyByOptions(queryKey, options$1); let query = this.get(queryHash); if (!query) { query = new Query({ client, queryKey, queryHash, options: client.defaultQueryOptions(options$1), state, defaultOptions: client.getQueryDefaults(queryKey) }); this.add(query); } return query; } add(query) { if (!this.#queries.has(query.queryHash)) { this.#queries.set(query.queryHash, query); this.notify({ type: "added", query }); } } remove(query) { const queryInMap = this.#queries.get(query.queryHash); if (queryInMap) { query.destroy(); if (queryInMap === query) this.#queries.delete(query.queryHash); this.notify({ type: "removed", query }); } } clear() { notifyManager.batch(() => { this.getAll().forEach((query) => { this.remove(query); }); }); } get(queryHash) { return this.#queries.get(queryHash); } getAll() { return [...this.#queries.values()]; } find(filters) { const defaultedFilters = { exact: true, ...filters }; return this.getAll().find((query) => matchQuery(defaultedFilters, query)); } findAll(filters = {}) { const queries = this.getAll(); return Object.keys(filters).length > 0 ? queries.filter((query) => matchQuery(filters, query)) : queries; } notify(event) { notifyManager.batch(() => { this.listeners.forEach((listener) => { listener(event); }); }); } onFocus() { notifyManager.batch(() => { this.getAll().forEach((query) => { query.onFocus(); }); }); } onOnline() { notifyManager.batch(() => { this.getAll().forEach((query) => { query.onOnline(); }); }); } }; //#endregion //#region node_modules/@tanstack/query-core/build/modern/mutation.js var Mutation = class extends Removable { #observers; #mutationCache; #retryer; constructor(config$2) { super(); this.mutationId = config$2.mutationId; this.#mutationCache = config$2.mutationCache; this.#observers = []; this.state = config$2.state || getDefaultState(); this.setOptions(config$2.options); this.scheduleGc(); } setOptions(options$1) { this.options = options$1; this.updateGcTime(this.options.gcTime); } get meta() { return this.options.meta; } addObserver(observer) { if (!this.#observers.includes(observer)) { this.#observers.push(observer); this.clearGcTimeout(); this.#mutationCache.notify({ type: "observerAdded", mutation: this, observer }); } } removeObserver(observer) { this.#observers = this.#observers.filter((x$1) => x$1 !== observer); this.scheduleGc(); this.#mutationCache.notify({ type: "observerRemoved", mutation: this, observer }); } optionalRemove() { if (!this.#observers.length) if (this.state.status === "pending") this.scheduleGc(); else this.#mutationCache.remove(this); } continue() { return this.#retryer?.continue() ?? this.execute(this.state.variables); } async execute(variables) { const onContinue = () => { this.#dispatch({ type: "continue" }); }; this.#retryer = createRetryer({ fn: () => { if (!this.options.mutationFn) return Promise.reject(new Error("No mutationFn found")); return this.options.mutationFn(variables); }, onFail: (failureCount, error$1) => { this.#dispatch({ type: "failed", failureCount, error: error$1 }); }, onPause: () => { this.#dispatch({ type: "pause" }); }, onContinue, retry: this.options.retry ?? 0, retryDelay: this.options.retryDelay, networkMode: this.options.networkMode, canRun: () => this.#mutationCache.canRun(this) }); const restored = this.state.status === "pending"; const isPaused = !this.#retryer.canStart(); try { if (restored) onContinue(); else { this.#dispatch({ type: "pending", variables, isPaused }); await this.#mutationCache.config.onMutate?.(variables, this); const context = await this.options.onMutate?.(variables); if (context !== this.state.context) this.#dispatch({ type: "pending", context, variables, isPaused }); } const data = await this.#retryer.start(); await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this); await this.options.onSuccess?.(data, variables, this.state.context); await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this); await this.options.onSettled?.(data, null, variables, this.state.context); this.#dispatch({ type: "success", data }); return data; } catch (error$1) { try { await this.#mutationCache.config.onError?.(error$1, variables, this.state.context, this); await this.options.onError?.(error$1, variables, this.state.context); await this.#mutationCache.config.onSettled?.(void 0, error$1, this.state.variables, this.state.context, this); await this.options.onSettled?.(void 0, error$1, variables, this.state.context); throw error$1; } finally { this.#dispatch({ type: "error", error: error$1 }); } } finally { this.#mutationCache.runNext(this); } } #dispatch(action) { const reducer = (state) => { switch (action.type) { case "failed": return { ...state, failureCount: action.failureCount, failureReason: action.error }; case "pause": return { ...state, isPaused: true }; case "continue": return { ...state, isPaused: false }; case "pending": return { ...state, context: action.context, data: void 0, failureCount: 0, failureReason: null, error: null, isPaused: action.isPaused, status: "pending", variables: action.variables, submittedAt: Date.now() }; case "success": return { ...state, data: action.data, failureCount: 0, failureReason: null, error: null, status: "success", isPaused: false }; case "error": return { ...state, data: void 0, error: action.error, failureCount: state.failureCount + 1, failureReason: action.error, isPaused: false, status: "error" }; } }; this.state = reducer(this.state); notifyManager.batch(() => { this.#observers.forEach((observer) => { observer.onMutationUpdate(action); }); this.#mutationCache.notify({ mutation: this, type: "updated", action }); }); } }; function getDefaultState() { return { context: void 0, data: void 0, error: null, failureCount: 0, failureReason: null, isPaused: false, status: "idle", variables: void 0, submittedAt: 0 }; } //#endregion //#region node_modules/@tanstack/query-core/build/modern/mutationCache.js var MutationCache = class extends Subscribable { constructor(config$2 = {}) { super(); this.config = config$2; this.#mutations = /* @__PURE__ */ new Set(); this.#scopes = /* @__PURE__ */ new Map(); this.#mutationId = 0; } #mutations; #scopes; #mutationId; build(client, options$1, state) { const mutation = new Mutation({ mutationCache: this, mutationId: ++this.#mutationId, options: client.defaultMutationOptions(options$1), state }); this.add(mutation); return mutation; } add(mutation) { this.#mutations.add(mutation); const scope = scopeFor(mutation); if (typeof scope === "string") { const scopedMutations = this.#scopes.get(scope); if (scopedMutations) scopedMutations.push(mutation); else this.#scopes.set(scope, [mutation]); } this.notify({ type: "added", mutation }); } remove(mutation) { if (this.#mutations.delete(mutation)) { const scope = scopeFor(mutation); if (typeof scope === "string") { const scopedMutations = this.#scopes.get(scope); if (scopedMutations) { if (scopedMutations.length > 1) { const index = scopedMutations.indexOf(mutation); if (index !== -1) scopedMutations.splice(index, 1); } else if (scopedMutations[0] === mutation) this.#scopes.delete(scope); } } } this.notify({ type: "removed", mutation }); } canRun(mutation) { const scope = scopeFor(mutation); if (typeof scope === "string") { const mutationsWithSameScope = this.#scopes.get(scope); const firstPendingMutation = mutationsWithSameScope?.find((m$1) => m$1.state.status === "pending"); return !firstPendingMutation || firstPendingMutation === mutation; } else return true; } runNext(mutation) { const scope = scopeFor(mutation); if (typeof scope === "string") { const foundMutation = this.#scopes.get(scope)?.find((m$1) => m$1 !== mutation && m$1.state.isPaused); return foundMutation?.continue() ?? Promise.resolve(); } else return Promise.resolve(); } clear() { notifyManager.batch(() => { this.#mutations.forEach((mutation) => { this.notify({ type: "removed", mutation }); }); this.#mutations.clear(); this.#scopes.clear(); }); } getAll() { return Array.from(this.#mutations); } find(filters) { const defaultedFilters = { exact: true, ...filters }; return this.getAll().find((mutation) => matchMutation(defaultedFilters, mutation)); } findAll(filters = {}) { return this.getAll().filter((mutation) => matchMutation(filters, mutation)); } notify(event) { notifyManager.batch(() => { this.listeners.forEach((listener) => { listener(event); }); }); } resumePausedMutations() { const pausedMutations = this.getAll().filter((x$1) => x$1.state.isPaused); return notifyManager.batch(() => Promise.all(pausedMutations.map((mutation) => mutation.continue().catch(noop$6)))); } }; function scopeFor(mutation) { return mutation.options.scope?.id; } //#endregion //#region node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js function infiniteQueryBehavior(pages) { return { onFetch: (context, query) => { const options$1 = context.options; const direction = context.fetchOptions?.meta?.fetchMore?.direction; const oldPages = context.state.data?.pages || []; const oldPageParams = context.state.data?.pageParams || []; let result = { pages: [], pageParams: [] }; let currentPage = 0; const fetchFn = async () => { let cancelled = false; const addSignalProperty = (object) => { Object.defineProperty(object, "signal", { enumerable: true, get: () => { if (context.signal.aborted) cancelled = true; else context.signal.addEventListener("abort", () => { cancelled = true; }); return context.signal; } }); }; const queryFn = ensureQueryFn(context.options, context.fetchOptions); const fetchPage = async (data, param, previous) => { if (cancelled) return Promise.reject(); if (param == null && data.pages.length) return Promise.resolve(data); const queryFnContext = { client: context.client, queryKey: context.queryKey, pageParam: param, direction: previous ? "backward" : "forward", meta: context.options.meta }; addSignalProperty(queryFnContext); const page = await queryFn(queryFnContext); const { maxPages } = context.options; const addTo = previous ? addToStart : addToEnd; return { pages: addTo(data.pages, page, maxPages), pageParams: addTo(data.pageParams, param, maxPages) }; }; if (direction && oldPages.length) { const previous = direction === "backward"; const pageParamFn = previous ? getPreviousPageParam : getNextPageParam; const oldData = { pages: oldPages, pageParams: oldPageParams }; const param = pageParamFn(options$1, oldData); result = await fetchPage(oldData, param, previous); } else { const remainingPages = pages ?? oldPages.length; do { const param = currentPage === 0 ? oldPageParams[0] ?? options$1.initialPageParam : getNextPageParam(options$1, result); if (currentPage > 0 && param == null) break; result = await fetchPage(result, param); currentPage++; } while (currentPage < remainingPages); } return result; }; if (context.options.persister) context.fetchFn = () => { return context.options.persister?.(fetchFn, { client: context.client, queryKey: context.queryKey, meta: context.options.meta, signal: context.signal }, query); }; else context.fetchFn = fetchFn; } }; } function getNextPageParam(options$1, { pages, pageParams }) { const lastIndex = pages.length - 1; return pages.length > 0 ? options$1.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams) : void 0; } function getPreviousPageParam(options$1, { pages, pageParams }) { return pages.length > 0 ? options$1.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams) : void 0; } //#endregion //#region node_modules/@tanstack/query-core/build/modern/queryClient.js var QueryClient = class { #queryCache; #mutationCache; #defaultOptions; #queryDefaults; #mutationDefaults; #mountCount; #unsubscribeFocus; #unsubscribeOnline; constructor(config$2 = {}) { this.#queryCache = config$2.queryCache || new QueryCache(); this.#mutationCache = config$2.mutationCache || new MutationCache(); this.#defaultOptions = config$2.defaultOptions || {}; this.#queryDefaults = /* @__PURE__ */ new Map(); this.#mutationDefaults = /* @__PURE__ */ new Map(); this.#mountCount = 0; } mount() { this.#mountCount++; if (this.#mountCount !== 1) return; this.#unsubscribeFocus = focusManager.subscribe(async (focused) => { if (focused) { await this.resumePausedMutations(); this.#queryCache.onFocus(); } }); this.#unsubscribeOnline = onlineManager.subscribe(async (online$1) => { if (online$1) { await this.resumePausedMutations(); this.#queryCache.onOnline(); } }); } unmount() { this.#mountCount--; if (this.#mountCount !== 0) return; this.#unsubscribeFocus?.(); this.#unsubscribeFocus = void 0; this.#unsubscribeOnline?.(); this.#unsubscribeOnline = void 0; } isFetching(filters) { return this.#queryCache.findAll({ ...filters, fetchStatus: "fetching" }).length; } isMutating(filters) { return this.#mutationCache.findAll({ ...filters, status: "pending" }).length; } /** * Imperative (non-reactive) way to retrieve data for a QueryKey. * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates. * * Hint: Do not use this function inside a component, because it won't receive updates. * Use `useQuery` to create a `QueryObserver` that subscribes to changes. */ getQueryData(queryKey) { const options$1 = this.defaultQueryOptions({ queryKey }); return this.#queryCache.get(options$1.queryHash)?.state.data; } ensureQueryData(options$1) { const defaultedOptions = this.defaultQueryOptions(options$1); const query = this.#queryCache.build(this, defaultedOptions); const cachedData = query.state.data; if (cachedData === void 0) return this.fetchQuery(options$1); if (options$1.revalidateIfStale && query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query))) this.prefetchQuery(defaultedOptions); return Promise.resolve(cachedData); } getQueriesData(filters) { return this.#queryCache.findAll(filters).map(({ queryKey, state }) => { const data = state.data; return [queryKey, data]; }); } setQueryData(queryKey, updater, options$1) { const defaultedOptions = this.defaultQueryOptions({ queryKey }); const query = this.#queryCache.get(defaultedOptions.queryHash); const prevData = query?.state.data; const data = functionalUpdate(updater, prevData); if (data === void 0) return void 0; return this.#queryCache.build(this, defaultedOptions).setData(data, { ...options$1, manual: true }); } setQueriesData(filters, updater, options$1) { return notifyManager.batch(() => this.#queryCache.findAll(filters).map(({ queryKey }) => [queryKey, this.setQueryData(queryKey, updater, options$1)])); } getQueryState(queryKey) { const options$1 = this.defaultQueryOptions({ queryKey }); return this.#queryCache.get(options$1.queryHash)?.state; } removeQueries(filters) { const queryCache = this.#queryCache; notifyManager.batch(() => { queryCache.findAll(filters).forEach((query) => { queryCache.remove(query); }); }); } resetQueries(filters, options$1) { const queryCache = this.#queryCache; return notifyManager.batch(() => { queryCache.findAll(filters).forEach((query) => { query.reset(); }); return this.refetchQueries({ type: "active", ...filters }, options$1); }); } cancelQueries(filters, cancelOptions = {}) { const defaultedCancelOptions = { revert: true, ...cancelOptions }; const promises$1 = notifyManager.batch(() => this.#queryCache.findAll(filters).map((query) => query.cancel(defaultedCancelOptions))); return Promise.all(promises$1).then(noop$6).catch(noop$6); } invalidateQueries(filters, options$1 = {}) { return notifyManager.batch(() => { this.#queryCache.findAll(filters).forEach((query) => { query.invalidate(); }); if (filters?.refetchType === "none") return Promise.resolve(); return this.refetchQueries({ ...filters, type: filters?.refetchType ?? filters?.type ?? "active" }, options$1); }); } refetchQueries(filters, options$1 = {}) { const fetchOptions = { ...options$1, cancelRefetch: options$1.cancelRefetch ?? true }; const promises$1 = notifyManager.batch(() => this.#queryCache.findAll(filters).filter((query) => !query.isDisabled()).map((query) => { let promise$1 = query.fetch(void 0, fetchOptions); if (!fetchOptions.throwOnError) promise$1 = promise$1.catch(noop$6); return query.state.fetchStatus === "paused" ? Promise.resolve() : promise$1; })); return Promise.all(promises$1).then(noop$6); } fetchQuery(options$1) { const defaultedOptions = this.defaultQueryOptions(options$1); if (defaultedOptions.retry === void 0) defaultedOptions.retry = false; const query = this.#queryCache.build(this, defaultedOptions); return query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query)) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data); } prefetchQuery(options$1) { return this.fetchQuery(options$1).then(noop$6).catch(noop$6); } fetchInfiniteQuery(options$1) { options$1.behavior = infiniteQueryBehavior(options$1.pages); return this.fetchQuery(options$1); } prefetchInfiniteQuery(options$1) { return this.fetchInfiniteQuery(options$1).then(noop$6).catch(noop$6); } ensureInfiniteQueryData(options$1) { options$1.behavior = infiniteQueryBehavior(options$1.pages); return this.ensureQueryData(options$1); } resumePausedMutations() { if (onlineManager.isOnline()) return this.#mutationCache.resumePausedMutations(); return Promise.resolve(); } getQueryCache() { return this.#queryCache; } getMutationCache() { return this.#mutationCache; } getDefaultOptions() { return this.#defaultOptions; } setDefaultOptions(options$1) { this.#defaultOptions = options$1; } setQueryDefaults(queryKey, options$1) { this.#queryDefaults.set(hashKey(queryKey), { queryKey, defaultOptions: options$1 }); } getQueryDefaults(queryKey) { const defaults = [...this.#queryDefaults.values()]; const result = {}; defaults.forEach((queryDefault) => { if (partialMatchKey(queryKey, queryDefault.queryKey)) Object.assign(result, queryDefault.defaultOptions); }); return result; } setMutationDefaults(mutationKey, options$1) { this.#mutationDefaults.set(hashKey(mutationKey), { mutationKey, defaultOptions: options$1 }); } getMutationDefaults(mutationKey) { const defaults = [...this.#mutationDefaults.values()]; const result = {}; defaults.forEach((queryDefault) => { if (partialMatchKey(mutationKey, queryDefault.mutationKey)) Object.assign(result, queryDefault.defaultOptions); }); return result; } defaultQueryOptions(options$1) { if (options$1._defaulted) return options$1; const defaultedOptions = { ...this.#defaultOptions.queries, ...this.getQueryDefaults(options$1.queryKey), ...options$1, _defaulted: true }; if (!defaultedOptions.queryHash) defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions); if (defaultedOptions.refetchOnReconnect === void 0) defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== "always"; if (defaultedOptions.throwOnError === void 0) defaultedOptions.throwOnError = !!defaultedOptions.suspense; if (!defaultedOptions.networkMode && defaultedOptions.persister) defaultedOptions.networkMode = "offlineFirst"; if (defaultedOptions.queryFn === skipToken) defaultedOptions.enabled = false; return defaultedOptions; } defaultMutationOptions(options$1) { if (options$1?._defaulted) return options$1; return { ...this.#defaultOptions.mutations, ...options$1?.mutationKey && this.getMutationDefaults(options$1.mutationKey), ...options$1, _defaulted: true }; } clear() { this.#queryCache.clear(); this.#mutationCache.clear(); } }; //#endregion //#region node_modules/@tanstack/query-core/build/modern/queryObserver.js var QueryObserver = class extends Subscribable { constructor(client, options$1) { super(); this.options = options$1; this.#client = client; this.#selectError = null; this.#currentThenable = pendingThenable(); if (!this.options.experimental_prefetchInRender) this.#currentThenable.reject(new Error("experimental_prefetchInRender feature flag is not enabled")); this.bindMethods(); this.setOptions(options$1); } #client; #currentQuery = void 0; #currentQueryInitialState = void 0; #currentResult = void 0; #currentResultState; #currentResultOptions; #currentThenable; #selectError; #selectFn; #selectResult; #lastQueryWithDefinedData; #staleTimeoutId; #refetchIntervalId; #currentRefetchInterval; #trackedProps = /* @__PURE__ */ new Set(); bindMethods() { this.refetch = this.refetch.bind(this); } onSubscribe() { if (this.listeners.size === 1) { this.#currentQuery.addObserver(this); if (shouldFetchOnMount(this.#currentQuery, this.options)) this.#executeFetch();