import { LinkfoxHttpError } from '@linkfox-web/http';
export { b as FieldDef, F as FilterValues, N as NavGroup, a as NavItem, c as NotebookInfo, S as SmartTable, d as SmartTableConfig, e as SmartTableFieldDef, T as TableInfo, U as UiFilterSpec, g as WORD_FIELDS, h as WORD_KIND_LABEL, i as WORD_STATUS, j as WordHit, W as WordTableKey, k as activeSmartTable, l as activeWordTables, m as attachmentUrl, n as buildWordMatcher, o as createSmartTable, p as createWordTables, q as filterKeys, f as findNav, r as firstAttachment, s as flagList, t as isAttachmentList, u as nowIso, v as num, w as setActiveSmartTable, x as splitList, y as str, z as toggleFlag } from '../word-tables-B3Zc1OiL.js';
export { A as AuthState, a as authIdentity, g as getApiKey, b as getAuthState, h as handleGatewayError, i as initialAuthState, l as loadApiKey, c as login, d as logout, m as maskApiKey, s as startAuth, e as subscribeAuth } from '../auth-RGVm8hmz.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;
    /** 子路径部署的前缀，用于拼 SSO 回调地址 */
    basePath?: string;
}
declare function configureAppKit(next: AppKitConfig): void;
declare function appKitConfig(): AppKitConfig;
/** 每次调用都重新读取，避免把构建期之外的 Key 变化缓存住 */
declare function getConfiguredApiKey(): string | 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;
/** 工具网关返回 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;

/**
 * 网关调用包装：错误统一交给 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 IClaimableFlow, type IRegisteredWorkflow, type IWorkflowClaim, LinkfoxError, SESSION_EXPIRED_MESSAGE, type TaskFile, type TaskStep, type TaskView, appKitConfig, cancelTask, claimWorkflows, configureAppKit, currentNotebookId, errorMessage, gateway, getApplicationId, getConfiguredApiKey, getShareUrl, initLinkfoxSdk, isAbortError, isApiKeyInvalid, isBalanceError, isSessionExpired, isTriggerLinked, keyOf, listRegisteredWorkflows, recordVisit, runTask, sleep, withWorkflowKey };
