import * as _linkfox_web_http from '@linkfox-web/http';
import { LinkfoxHttpError } from '@linkfox-web/http';
export { D as DEFAULT_THEME_COLOR, b as FieldDef, F as FilterValues, N as NavGroup, a as NavItem, c as NotebookInfo, S as SmartTable, d as SmartTableConfig, e as SmartTableFieldDef, g as THEME_COLORS, h as THEME_COLOR_ATTRIBUTE, i as THEME_COLOR_MESSAGE_TYPE, j as THEME_COLOR_SCRIPT, k as THEME_COLOR_STORAGE_KEY, l as TableInfo, T as ThemeColor, U as UiFilterSpec, m as WORD_FIELDS, n as WORD_KIND_LABEL, o as WORD_STATUS, p as WordHit, W as WordTableKey, q as activeSmartTable, r as activeWordTables, s as applyThemeColor, t as attachmentUrl, u as buildWordMatcher, v as createSmartTable, w as createWordTables, x as filterKeys, f as findNav, y as firstAttachment, z as flagList, A as isAttachmentList, B as normalizeThemeColor, C as nowIso, E as num, G as postThemeColorToParent, H as setActiveSmartTable, I as splitList, J as str, K as themeColorScript, L as toggleFlag } from '../word-tables-DycgaC-4.js';
export { A as AuthState, a as authIdentity, g as getApiKey, b as getAuthState, h as handleGatewayError, c as hasSeenCreditsNotice, i as initialAuthState, l as loadApiKey, d as login, e as logout, m as markCreditsNoticeSeen, f as maskApiKey, s as startAuth, j as subscribeAuth } from '../auth-BhFFT22n.js';
export { cn } from 'cn';
export { Attachment, FieldInfo, FieldType, FilterCondition, ListRecordsResult as ListRecordsResponse, RecordFilter, SmartRecord } from '@linkfox-web/ai-tools/smart-table';
import 'lucide-react';

/**
 * 模板注入的应用配置。
 *
 * 包内不读 `process.env`：Next 只对应用源码做静态内联，`node_modules` 里的环境变量
 * 在构建后是 `undefined`。模板在自己的 `lib/app-kit.ts` 里读 env 并调用
 * `configureAppKit()`，`NEXT_PUBLIC_*` 留在模板源码里才能被正确替换。
 */
interface AppKitConfig {
    /** 工具网关地址；开启 rewrite 时模板传 `/api/linkfox` */
    gatewayBaseUrl: string;
    /** 第三方 SSO 服务地址 */
    ssoBaseUrl: string;
    /** SSO clientId；为空时只能走固定 API Key 模式 */
    ssoClientId: string;
    /** 是否开启同源 rewrite：决定 API Key 走 Authorization 还是 tool-gateway-api-key */
    rewrite: boolean;
    /** 固定 API Key。必须是函数，每次请求现取，不能缓存字符串 */
    apiKey?: () => string | undefined;
    /** 应用 ID（`apl` 开头）；为空则跳过访问登记，也不显示「编辑应用」入口 */
    applicationId?: string;
    /** LinkFox OS 站点地址，用于拼「编辑应用」跳转链接；默认 `https://os.linkfox.com` */
    osBaseUrl?: string;
    /** 单次接口请求超时（毫秒），默认沿用 SDK 的 30 秒；工作流类慢接口需要的模板自行调大 */
    timeout?: number;
    /** 子路径部署的前缀，用于拼 SSO 回调地址 */
    basePath?: string;
}
declare function configureAppKit(next: AppKitConfig): void;
declare function appKitConfig(): AppKitConfig;
/** 每次调用都重新读取，避免把构建期之外的 Key 变化缓存住 */
declare function getConfiguredApiKey(): string | undefined;

/** LinkFox 充值页（按年付、AI 算力页签） */
declare const CREDITS_RECHARGE_URL = "https://ai.linkfox.com/usercenter/pricing?tab=ai&plan=personalYearly";
/**
 * 查一次当前成员可用算力。失败（网络、401、接口异常）返回 undefined，
 * 调用方据此静默跳过——余额检查不能挡住登录。
 *
 * 登录后算力弹窗和账号菜单会各查一次，同一时刻的并发调用共用一个请求；
 * 不缓存结果，下一次调用仍然拿到当下的余额。
 */
declare function fetchRemainingCredits(): Promise<number | undefined>;
/** 当前是否已因余额不足停止发起计费请求 */
declare function creditsExhausted(): boolean;
/** 触发熔断的错误（用于区分「团队没额度」和「成员限额」） */
declare function creditsError(): _linkfox_web_http.LinkfoxHttpError | undefined;
/** 订阅新的熔断事件；已熔断时不补发 */
declare function subscribeCreditsExhausted(listener: () => void): () => void;
/**
 * 充值后重新检查：查到 > 0 就解除熔断并返回余额；
 * 仍为 0 或查询失败返回原值/undefined，熔断保持不变。
 */
declare function recheckCredits(): Promise<number | undefined>;

declare const SESSION_EXPIRED_MESSAGE = "\u4F1A\u8BDD\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55";
/** 会话过期：上游 invalid_token（token 失效 / 过期 / 被吊销），或网关直接回 401 */
declare function isSessionExpired(e: unknown): boolean;
/** 前端自己判定的业务错误（生成超时、结果无法解析等），与 SDK 错误同一类型，errorMessage 统一处理 */
declare class LinkfoxError extends LinkfoxHttpError {
    constructor(code: number, message: string);
}
declare function isAbortError(e: unknown): boolean;
/** 算力 / 余额不足：重试无意义，轮询时直接抛出 */
declare function isBalanceError(e: unknown): boolean;
/**
 * 成员达到团队设置的算力限额（余额没耗尽，是管理员给这个成员封了顶）。
 * 与「团队余额为 0」的后续动作不同：前者要找管理员提额度，后者充值即可。
 */
declare function isMemberLimitError(e: unknown): boolean;
/** 工具网关返回 401：配了固定 Key 时是 Key 失效，否则是登录态失效 */
declare function isApiKeyInvalid(e: unknown): boolean;
declare function errorMessage(e: unknown): string;
declare const sleep: (ms: number, signal?: AbortSignal) => Promise<void>;

/** 应用 ID 只来自配置；没配（或还是占位符）就整个功能跳过，不发任何请求 */
declare function getApplicationId(): string | undefined;
/**
 * 登录后登记一次「打开应用」，刷新用户的最近访问列表。
 *
 * 服务端 30 秒内重复上报只记一条流水，所以不用自己防抖，拿到会话时调一次即可。
 * 匿名、应用不存在或在回收站时返回 recorded:false；网络失败会 reject——
 * 两种都吞掉：登记失败不该把用户挡在门外。
 *
 * 直接调 SDK 而不经 gateway()：那里会把 401 交给 handleGatewayError，
 * 一个配错的应用 ID 就会把用户登出。
 */
declare function recordVisit(): void;

interface ApplicationEditEntry {
    applicationId: string;
    /** 应用所在团队 base（`bse` 开头） */
    baseId: string;
    /** 应用编辑页地址 */
    url: string;
}
/** 应用编辑页：`<os>/table/<baseId>/application/<applicationId>` */
declare function applicationEditUrl(baseId: string, applicationId: string): string;
/**
 * 当前登录者是不是应用创建者；是的话给出编辑页地址，否则 `undefined`（入口不显示）。
 *
 * 没配应用 id、不是创建者、接口 404（应用不存在 / 别的团队）或网络失败都返回 `undefined`，
 * 不抛错——这个入口是锦上添花，不能因为它把页面挡住。
 * 直接调 SDK 而不经 `gateway()`：这里不处理 401，一个配错的应用 id 不该把用户登出
 * （与 `recordVisit` 同一取舍）。只读判定，同一账号一次加载内结果不变，缓存一次。
 */
declare function getApplicationEditEntry(): Promise<ApplicationEditEntry | undefined>;

/**
 * 当前页面是否被嵌在 iframe 中打开（外层页面可能是任意 origin）。
 *
 * 只比较 window.self 与 window.parent 的引用，不读取外层属性，跨域也安全（与 SSO 判断一致）；
 * 某些沙箱环境访问 window.parent 会抛错，此时按「已嵌入」处理——宁可少显示装饰性入口。
 * SSR 阶段没有 window，返回 false。
 */
declare function isEmbeddedInIframe(): boolean;

/**
 * 网关调用包装：错误统一交给 handleGatewayError 处理（会话过期 / Key 失效时提示并回到登录页）。
 * 「200 + {error:{code,message}}」信封由 ai-tools 0.3.9 的 SDK 自己抛错，这里不再重复解析。
 */
declare function gateway<T>(p: Promise<T>): Promise<T>;

declare const AGENT_MODELS: readonly [{
    readonly id: "default";
    readonly name: "通用助手";
}, {
    readonly id: "linkfox-product-selection-agent";
    readonly name: "选品 Agent";
}, {
    readonly id: "linkfox-market-analysis-agent";
    readonly name: "市场分析 Agent";
}, {
    readonly id: "linkfox-listing-agent";
    readonly name: "Listing Agent";
}, {
    readonly id: "linkfox-image-agent";
    readonly name: "图片 Agent";
}, {
    readonly id: "linkfox-video-agent";
    readonly name: "视频 Agent";
}];
interface TaskStep {
    id: string;
    title: string;
    status: "running" | "done" | "failed";
}
interface TaskFile {
    name: string;
    uri: string;
}
interface TaskView {
    messageId: string;
    /** 服务端会话 ID：下一轮追问时传回即可在同一会话内续接（技能 §6.3） */
    sessionId: string;
    steps: TaskStep[];
    text: string;
    files: TaskFile[];
    /** 非空即结束：end_turn 为正常完成 */
    stopReason: string;
}
declare function cancelTask(messageId: string): Promise<unknown>;
/** 任务结束后换取公开的完整过程链接（失败返回 undefined） */
declare function getShareUrl(messageId: string): Promise<string | undefined>;
/**
 * 提交任务并轮询到结束；onUpdate 推送进行中的步骤与文本。
 *
 * 多轮对话：首轮不传 sessionId，服务端新建会话并在 create 响应里返回；
 * 后续追问带上这个 sessionId，服务端在原会话内继续，Agent 保有前几轮上下文。
 * 续接必须沿用同一个 modelId（会话属于发起它的专家），换专家要开新会话。
 */
declare function runTask(prompt: string, modelId: string, { signal, onUpdate, sessionId, }: {
    signal?: AbortSignal;
    onUpdate: (view: TaskView) => void;
    /** 上一轮返回的 sessionId；首轮不传 */
    sessionId?: string;
}): Promise<TaskView>;

/**
 * 工作流身份判定：**不靠名字**认「这条流是不是我这条模板流」。
 *
 * ## 为什么不能只按名字
 *
 * 复制多维表时工作流会跟着复制，而对方**保持原名**（缺陷 #5051 的产品结论），
 * 于是一条从 `nbkA` 复制到 `nbkB` 的流仍叫 `Ozon选品-自动上架 (nbkA)`。
 * 模板按自己的容器 id 算出 `(nbkB)`，`findByName` 必然落空 ⇒ 再建一整套。
 * 线上实测副本容器里因此出现两套流、同表双触发。
 *
 * ## 三级判据
 *
 * 1. **硬判据：本容器已登记**。`listWorkflows({ notebookId })` 返回的就是侧栏那份关联数据；
 *    「复制来的流」靠它进候选池，别的多维表下的同名流则进不来。
 *    ⚠️ 候选池 = 登记行 **∪ 精确名字**：**手动流不产生订阅、不登记**，只留登记行会让它们
 *    每次打开页面都被判成「没部署」而无限新建。
 * 2. **次判据：`description` 里的 `key=<模板key>`**。部署时由 `renderFlow` 写入，随复制一起走
 *    （复制只改 flowData 里的表引用，不动 description），所以副本流上它也在。
 * 3. **兜底：名字**。复制来的流名字带的是**源**容器 id，所以放宽成「以 `<模板名> (` 开头」——
 *    **该放宽只在登记集合可用时生效**（否则等于回到今天那种会误认的匹配）。
 *
 * ## 什么时候降级
 *
 * - 没配 `NEXT_PUBLIC_NOTE_BOOK_ID`（自建部署）：拿不到容器 id，整体退回**精确名字**匹配。
 * - `listWorkflows` 查询失败：同上，退回精确名字匹配，不放松到前缀匹配。
 *
 * 两种情况都只是「回到改动前」，不会更糟。
 */
/** 认领只依赖这几个字段；模板自己的 `ChatflowSummary` 结构兼容即可（不要求索引签名）。 */
interface IClaimableFlow {
    id: string;
    name: string;
    description?: string;
    flowData?: string;
}
/** `listWorkflows` 里我们关心的部分。 */
interface IRegisteredWorkflow {
    flowId: string;
    /** null = 没绑触发表（手动 / 定时启动），不会被记录变化触发 */
    tableId: string | null;
}
interface IWorkflowClaim<T extends IClaimableFlow> {
    key: string;
    flow?: T;
    /** 命中依据，排查用：`key` / `name` / 无（未认领） */
    matchedBy?: "key" | "name";
    /** 同一个 key 还命中了别的流（历史重复流）。不自动删 —— 可能带用户手工修改 */
    duplicates: T[];
}
/** 从流上取逻辑 key：先看 `description`，再看 `flowData` 里的 description。 */
declare function keyOf(flow: IClaimableFlow): string | undefined;
/**
 * 把 `key=<key>` 补进 description。已经带了就不重复追加（幂等）。
 *
 * 部署时由 `renderFlow` 调用；「模板版本 <hash>」那段的格式不动，版本判定照旧。
 */
declare function withWorkflowKey(description: string, key: string): string;
/** 本多维表下的容器 id；没配（或尚未注册客户端）就是 undefined。 */
declare function currentNotebookId(): string | undefined;
/**
 * 读本容器已登记的关联。**永不抛**：失败返回 `null`，调用方据此退回精确名字匹配。
 */
declare function listRegisteredWorkflows(notebookId: string | undefined): Promise<IRegisteredWorkflow[] | null>;
/**
 * 按上面的三级判据，为每个模板 key 挑出对应的流。
 *
 * @param names    模板 key → 展示名（`workflowNames`）
 * @param flows    账号全量流（`listChatflows()` 的结果）
 * @param links    本容器登记行；`null` = 查不到 / 未配容器 id ⇒ 退回精确名字匹配
 */
declare function claimWorkflows<T extends IClaimableFlow>(params: {
    notebookId: string | undefined;
    names: Record<string, string>;
    flows: T[];
    links: IRegisteredWorkflow[] | null;
}): Record<string, IWorkflowClaim<T>>;
/**
 * 这条流的触发器是否**已关联到多维表**（侧栏能看到它、记录变更能触发它或定时任务挂在它下面）。
 *
 * 判据是「有没有登记行」，**不看 `tableId` 是否为 null**：定时流按设计只挂容器，
 * 登记行的 `tableId` 就是 null（studio `14ca607` 起如此），拿它当「未生效」会把正常的定时流
 * 全标成未关联。记录触发的流若确实没绑上表，由 studio 的 `tableSync` 那一侧报，
 * 这里不重复猜。
 *
 * `links === null`（查询失败 / 未配容器 id）时返回 `undefined`（未知），不要猜。
 */
declare function isTriggerLinked(links: IRegisteredWorkflow[] | null, flowId: string | undefined): boolean | undefined;

/**
 * 浏览器直接调用服务，兼容静态导出。SSO token 存进 http 会话，由 SDK 自动放进
 * ai-tools 请求的 Authorization；api-user-center 按 clientId 存进独立 localStorage 键，
 * 同域多个应用互不覆盖，也不覆盖主站 LINKFOX_AI_TOKEN。
 */
declare function initLinkfoxSdk(): void;

export { AGENT_MODELS, type AppKitConfig, type ApplicationEditEntry, CREDITS_RECHARGE_URL, type IClaimableFlow, type IRegisteredWorkflow, type IWorkflowClaim, LinkfoxError, SESSION_EXPIRED_MESSAGE, type TaskFile, type TaskStep, type TaskView, appKitConfig, applicationEditUrl, cancelTask, claimWorkflows, configureAppKit, creditsError, creditsExhausted, currentNotebookId, errorMessage, fetchRemainingCredits, gateway, getApplicationEditEntry, getApplicationId, getConfiguredApiKey, getShareUrl, initLinkfoxSdk, isAbortError, isApiKeyInvalid, isBalanceError, isEmbeddedInIframe, isMemberLimitError, isSessionExpired, isTriggerLinked, keyOf, listRegisteredWorkflows, recheckCredits, recordVisit, runTask, sleep, subscribeCreditsExhausted, withWorkflowKey };
