@lark-base-open/base-database-app-sdk 0.3.2 → 0.4.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/CHANGELOG.md +17 -0
- package/README.md +8 -8
- package/capabilities.json +1 -1
- package/dist/{capabilities-56e403e7.d.ts → capabilities-83939715.d.ts} +5 -0
- package/dist/chunk-5U3PWPXP.js +1 -0
- package/dist/codegen.cjs +10 -10
- package/dist/codegen.js +10 -10
- package/dist/components.d.ts +2 -2
- package/dist/components.js +1 -1
- package/dist/{index-a4d31302.d.ts → index-99514181.d.ts} +28 -12
- package/dist/page.d.ts +4 -4
- package/dist/page.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/theme.css +121 -8
- package/docs/compat.md +1 -1
- package/docs/exports.md +2 -2
- package/docs/page.md +48 -0
- package/docs/upgrade.md +1 -1
- package/examples/read-after-write.ts +40 -0
- package/package.json +1 -1
- package/dist/chunk-FJAP37BR.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1 - 2026-10-26
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- 恢复悬浮编辑按钮、隐藏按钮和隐藏提示的样式。
|
|
8
|
+
- 修复悬浮按钮提示框在窄屏和左右定位时超出视口的问题。
|
|
9
|
+
|
|
10
|
+
## 0.4.0 - 2026-10-23
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- 新增 `readYourWrites` 选项和 `DataNotReadyError`。
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- 默认开启写后读,数据未就绪时自动重试,耗尽后抛出异常。
|
|
19
|
+
|
|
3
20
|
## 0.3.2 - 2026-10-19
|
|
4
21
|
|
|
5
22
|
### Added
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
用于开发以飞书多维表格为数据后端的 Base Database 应用,提供页面与服务端运行时、平台组件、版本化能力查询与测试工具。
|
|
4
4
|
|
|
5
|
-
安装:`npm install @lark-base-open/base-database-app-sdk@0.
|
|
5
|
+
安装:`npm install @lark-base-open/base-database-app-sdk@0.4.1`。从旧版本升级前请阅读 [变更记录](CHANGELOG.md)。
|
|
6
6
|
|
|
7
7
|
运行环境需支持 ES2022;页面 API 需要 Base Database 页面宿主,服务端 API 用于 Node.js / FaaS。组件需要 React 与 React DOM 19.2,页面查询能力使用 @tanstack/react-query 5.104.1;npm 会安装声明的依赖与必需 peer。底层通信依赖 base-site-channel 0.1.6。
|
|
8
8
|
|
|
@@ -34,15 +34,15 @@ SDK 文档说明本版本 API、组件、兼容语义与可编译示例。业务
|
|
|
34
34
|
|
|
35
35
|
## npm 发布
|
|
36
36
|
|
|
37
|
-
SDK 0.
|
|
37
|
+
SDK 0.4.1 依赖已发布的 channel 0.1.6,锁文件必须解析到 `registry.npmjs.org` 的制品。AI Function 调用需要后端与宿主支持 `functions/:key/invoke`。
|
|
38
38
|
|
|
39
|
-
本版本拟发布到 `latest
|
|
39
|
+
本版本拟发布到 `latest`,修复悬浮编辑控件样式及提示框视口边界,保持 0.4.0 的 API 与默认行为。0.4.0 默认开启写后读,数据未就绪时自动重试并可能抛出 `DataNotReadyError`;需要按[写后读说明](docs/page.md#写后读)处理新异常,或传入 `{ readYourWrites: false }` 保持普通查询行为。契约生成使用工程安装的 SDK `./codegen` 入口;已安装旧 SDK 的工程不会因为单独升级 CLI 而自动切换到 0.4.0。0.3.0 将批量 Mutation 的 ID、输入和输出绑定到生成契约,收紧公开类型接口;0.2.0 对直接 Function 调用的返回泛型也有不兼容变化,跨版本升级见[升级指引](docs/upgrade.md)。
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
`CHANGELOG.md` 只记录简要版本变化,升级与迁移指导由[升级指引](docs/upgrade.md)及配套 CLI 的建站 Skill 提供。`check:migrations` 检查当前版本、重复编号和已有 Migration 的格式,不强制新增 Migration 章节。
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Changelog 检查不能证明迁移可用。发布者还须按升级指导在旧 SDK 工程中定位受影响代码,验证未授权时保留依赖、授权升级后完成 `contracts generate → check → build`;核对使用目标包内 docs,保留实际 SDK/CLI 制品、修改与验证结果。跨过多个不兼容版本时逐一核对相关指导,不以全新 starter 的构建代替存量迁移。
|
|
44
44
|
|
|
45
|
-
在本 SDK 目录按顺序执行以下发布前检查(`npm test`
|
|
45
|
+
在本 SDK 目录按顺序执行以下发布前检查(`npm test` 包含Changelog 检查、构建、公开文档与包边界检查、类型和组件测试;`prepublishOnly` 也会执行Changelog 检查):
|
|
46
46
|
|
|
47
47
|
- `npm ci --registry=https://registry.npmjs.org/`
|
|
48
48
|
- `npm run check:migrations`
|
|
@@ -59,7 +59,7 @@ SDK 0.3.2 依赖已发布的 channel 0.1.6,锁文件必须解析到 `registry.
|
|
|
59
59
|
|
|
60
60
|
- `npm whoami --registry=https://registry.npmjs.org/`
|
|
61
61
|
- `npm publish --tag latest --registry=https://registry.npmjs.org/`
|
|
62
|
-
- `npm view @lark-base-open/base-database-app-sdk@0.
|
|
62
|
+
- `npm view @lark-base-open/base-database-app-sdk@0.4.1 version dist --json --registry=https://registry.npmjs.org/`
|
|
63
63
|
- `npm view @lark-base-open/base-database-app-sdk dist-tags versions --json --registry=https://registry.npmjs.org/`
|
|
64
64
|
|
|
65
|
-
回读应确认 `latest` 为 `0.
|
|
65
|
+
回读应确认 `latest` 为 `0.4.1`。
|
package/capabilities.json
CHANGED
|
@@ -8,6 +8,11 @@ type SiteRuntimeContext = SiteRuntimeContext$1 & CapabilityContext & {
|
|
|
8
8
|
projectEnv: "preview";
|
|
9
9
|
artifactVersion: string | null;
|
|
10
10
|
};
|
|
11
|
+
/** 写后读重试参数;宿主只在整份合法时下发,SDK 侧另有兜底。 */
|
|
12
|
+
readYourWritesRetry?: {
|
|
13
|
+
maxRetries: number;
|
|
14
|
+
intervalMs: number;
|
|
15
|
+
};
|
|
11
16
|
};
|
|
12
17
|
interface RuntimeContextReader {
|
|
13
18
|
getRuntimeContext(): Promise<SiteRuntimeContext>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as He,b as re,c as ze}from"./chunk-ZKBZAK4L.js";import{a as oe}from"./chunk-3JX3FIBG.js";import{a as $}from"./chunk-OHPYKFCM.js";import{createContext as sn,useContext as ct}from"react";import{createContext as Zt,useContext as Xt,useEffect as en,useSyncExternalStore as tn}from"react";import{capabilityNames as Tt}from"@lark-base-open/base-site-channel/capabilities";import*as I from"@lark-base-open/base-site-channel/runtime";import{SITE_RUNTIME_PROTOCOL_VERSION as qn,SiteRuntimeApi as le,SiteRuntimeEvent as Yn,SiteRuntimeFunction as Gn,SiteRuntimeErrorCode as Kn,readSiteAITextDelta as Jn,isValidSiteFunctionName as Qn}from"@lark-base-open/base-site-channel/runtime-contract";var J=()=>{throw new oe(re.ContextInvalid,"\u5BBF\u4E3B\u80FD\u529B\u5B57\u6BB5\u65E0\u6548")};function ve(e){if(!e||typeof e!="object")return J();if(e.capabilities===void 0)return Object.fromEntries(Object.entries(He).filter(([,o])=>o.baseline).map(([o])=>[o,{version:1}]));let t=e.capabilities;if(!t||typeof t!="object"||Array.isArray(t))return J();let n=Object.entries(t);return n.some(([,o])=>!o||typeof o!="object"||Array.isArray(o)||!Number.isSafeInteger(o.version)||o.version<=0)?J():Object.fromEntries(n.map(([o,r])=>[o,{version:r.version}]))}function It(e,t,n=1){if(!Number.isSafeInteger(n)||n<1)return J();let o=ve(e);return Object.prototype.hasOwnProperty.call(o,t)&&o[t].version>=n}async function kt(e=P){return ve(await e.getRuntimeContext())}var Xn=kt;async function Lt(e,t=1,n=P){let o=await n.getRuntimeContext(),r=ve(o),i=It(o,e,t),a=o.capabilityUnavailable;if(a!==void 0&&(!a||typeof a!="object"||Array.isArray(a)))return J();let s=a&&Object.prototype.hasOwnProperty.call(a,e)?a[e]:void 0;return s!==void 0&&(!s||typeof s!="object"||!["permission-denied","region-unavailable","temporarily-unavailable"].includes(s.reason)||typeof s.retryable!="boolean")?J():{name:e,requiredVersion:t,version:Object.prototype.hasOwnProperty.call(r,e)?r[e].version:null,supported:i,source:o.capabilities===void 0?"host-baseline":"advertised",availability:i?s?.reason??"unknown":"unsupported"}}async function Ve(e,t=1,n=P){let o=await n.getRuntimeContext(),r=await Lt(e,t,{getRuntimeContext:async()=>o});if(!r.supported)throw new ze(e,t);let i={"permission-denied":re.PermissionDenied,"region-unavailable":re.RegionUnavailable,"temporarily-unavailable":re.TemporarilyUnavailable};if(r.availability in i)throw new oe(i[r.availability],"\u5BBF\u4E3B\u660E\u786E\u62D2\u7EDD\u6B64\u80FD\u529B",void 0,o.capabilityUnavailable?.[e]?.retryable)}function qe(e,t){let n,o=!1,r,i=new Promise(a=>{r=a});return e.registerApi($.pairApi,async a=>{if(!a||!/^[A-Za-z0-9_-]{43}$/.test(a.challenge))throw new Error("INVALID_PAIRING_CHALLENGE");n=a.challenge;let s=n;o&&(o=!1,i=new Promise(u=>{r=u}));let c=await t($.endpoint,{method:"POST",credentials:"omit",cache:"no-store",redirect:"error",headers:{"Content-Type":"application/json"},body:JSON.stringify({challenge:s})});if(!c.ok)throw new Error("DEVELOPMENT_PAIRING_FAILED");let d=await c.json();if(!/^[A-Za-z0-9_-]{43}$/.test(d.proof))throw new Error("INVALID_PAIRING_PROOF");return{proof:d.proof}}),e.subscribeEvent($.pairedEvent,a=>{n&&a?.challenge===n&&(o=!0,r())}),{reset:()=>{n=void 0,o&&(o=!1,i=new Promise(a=>{r=a}))},wait:async()=>{let a;do a=i,await a;while(a!==i)}}}var Ye=typeof window<"u"&&window.location.protocol==="http:"&&window.location.hostname===$.host&&Number(window.location.port)>=$.portMin&&Number(window.location.port)<=$.portMax;var Ge=I.siteRuntime,M=Ge.getChannel?.()??Ge.channel,_t=Ye&&typeof window<"u"&&window.parent!==window?qe(M,globalThis.fetch.bind(globalThis)):void 0;function Ke(e,t=async()=>{}){let n=new Map,o=async(r,i)=>{await t();for(let a of Tt(r,i))try{await Ve(a,1,{getRuntimeContext:()=>e.invokeApi(le.RuntimeContext,void 0)})}catch(s){throw s instanceof Error&&"code"in s?Object.assign(new I.SiteRuntimeInvocationError(String(s.code),s.message),s):s}};return{subscribeEvent:(r,i)=>e.subscribeEvent(r,i),emitEvent:async(r,i)=>(await o(r,i),e.emitEvent(r,i)),invokeApi:async(r,i,a)=>{let s=i?.requestId??i?.subscriptionId??i?.uploadId,c=r===le.HttpRequestCancel||r===le.AttachmentUploadCancel||r.endsWith(".close");if(c&&s&&n.has(s)){n.get(s).canceled=!0;return}let d={canceled:!1};!c&&s&&n.set(s,d);try{if(await o(r,i),d.canceled)throw new DOMException("The operation was aborted","AbortError");return s&&n.delete(s),await e.invokeApi(r,i,a)}finally{s&&n.get(s)===d&&n.delete(s)}}}}var Mt={invokeApi:M.invokeApi.bind(M),emitEvent:M.emitEvent.bind(M),subscribeEvent:M.subscribeEvent.bind(M)},Re=Ke(Mt,async()=>{if(typeof window<"u"&&window.parent===window)throw new I.SiteRuntimeInvocationError("CHANNEL_UNAVAILABLE","\u9875\u9762\u672A\u8FDE\u63A5\u5BBF\u4E3B channel");await _t?.wait()});M.invokeApi=Re.invokeApi;M.emitEvent=Re.emitEvent;var Ce=class extends I.SiteRuntimeClient{constructor(t){super(t?Ke(t):Re)}},so=e=>new Ce(e),P=I.siteRuntime,{invokeHttp:ue,invokeApi:co,getCurrentUser:ae,logout:Ee,requestEdit:Dt,uploadAttachment:lo,openLink:de}=P,Ft=(e=P,t)=>I.createSiteRuntimeFetch(e,t),N=Ft();var Ot=ue,Nt=/^\/?(preview\/)?app\/([^/]+)(\/|$)/,Je=/^[A-Za-z0-9_-]+$/,We="/space/api/bitable/site/v1",Bt="/space/api/box/file/temporary_download_url",Q="preview",ie=null;function jt(){let t=(typeof globalThis.location>"u"?void 0:globalThis.location)?.ancestorOrigins?.[0];if(t)return t;let n=typeof globalThis.document>"u"?"":globalThis.document.referrer;if(!n)return"";try{return new URL(n).origin}catch{return""}}function Ue(){let e=typeof globalThis.location>"u"?"":globalThis.location.pathname,t=Nt.exec(e),n=jt();return t?{env:t[1]?Q:"prod",gatewayOrigin:n,token:decodeURIComponent(t[2]??"")}:{env:"prod",gatewayOrigin:n,token:""}}function H(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function $t(e){return e===Q||e==="prod"}function Ht(e){if(!H(e))return{};let t=typeof e.siteToken=="string"?e.siteToken.trim():"";return{...t?{token:t}:{},...$t(e.env)?{env:e.env}:{}}}async function z(){return ie||(ie=(async()=>{let e=Ue(),t={},n;try{n=await P.getRuntimeContext(),t=Ht(n)}catch(r){console.warn("Could not read the host Runtime context; inferring it from the artifact path",r)}pe=Qt(n);let o={env:t.env??e.env,gatewayOrigin:e.gatewayOrigin,token:t.token??e.token};return o.token||console.error("Cannot determine the app token: the host did not provide siteToken and the current path does not match an artifact path"),o})().catch(e=>{throw ie=null,pe={...Pe},e}),ie)}function Se(e){return!!(e.tableId.trim()&&e.fieldId.trim()&&e.recordId.trim()&&e.fileToken.trim())}function Ze(e,t){return JSON.stringify({bitablePerm:{tableId:t.tableId,attachments:{[t.fieldId]:{[t.recordId]:[t.fileToken]}},siteToken:e.token,siteEnv:e.env}})}function Xe(e,t){if(t instanceof Error)return t;let n=H(t)?t.code:void 0,o=typeof n=="string"||typeof n=="number"?String(n):"",r=o==="REQUEST_TIMEOUT"||o==="10005"?`${e} timed out`:`${e} failed`;return Object.assign(new Error(`${r}${o?` (code ${o})`:""}`),{cause:t,...o?{code:o}:{}})}async function et(e,t=360,n={}){if(n.signal?.throwIfAborted(),!Se(e)||!Number.isFinite(t)||t<=0)throw new Error("Attachment location or image size is invalid");let o=await z();if(n.signal?.throwIfAborted(),!o.token)throw new Error("Cannot load the attachment image without an app token");let r=[120,360,720,1280].find(c=>c>=t)??1280,i=new URLSearchParams({extra:Ze(o,e),width:String(r),height:String(r),policy:"allow_up",fallback_source:"1"}),a=await Ot({url:`/space/api/box/stream/download/v2/cover/${encodeURIComponent(e.fileToken)}?${i}`,init:{method:"GET",responseType:"arrayBuffer",timeoutMs:45e3},signal:n.signal}).catch(c=>{throw Xe("Attachment image request",c)});if(!a.ok){let c=a.headers.get("x-tt-logid");throw new Error(`Failed to load attachment image: HTTP ${a.status}${c?`, LogID ${c}`:""}`)}let s=await a.blob();if(!s.size||!s.type.startsWith("image/"))throw new Error("The host did not return a valid image");return s}async function zt(e,t){if(!e.token)throw new Error("Cannot get an attachment download URL without an app token");if(!Se(t))throw new Error("Cannot get an attachment download URL: the attachment location is incomplete");let n=await N(Bt,{body:JSON.stringify({extra:Ze(e,t),file_token:t.fileToken}),headers:{"content-type":"application/json"},method:"POST"}).catch(s=>{throw Xe("Attachment download URL request",s)}),o=n.headers?.get("x-tt-logid")?.trim(),r;try{r=await n.json()}catch{throw new Error(n.ok?`Attachment download URL response is not valid JSON${o?`, LogID ${o}`:""}`:`Failed to get attachment download URL: HTTP ${n.status}${o?`, LogID ${o}`:""}`)}let i=H(r)?r.code:void 0;if(typeof i=="number"&&i!==0||typeof i=="string"&&i.trim()!==""&&i.trim()!=="0"){let s=new Error(`Attachment service could not provide a download URL (code ${String(i)}${o?`, LogID ${o}`:""})`);throw Object.assign(s,{code:String(i),cause:r})}if(!n.ok)throw new Error(`Failed to get attachment download URL: HTTP ${n.status}${o?`, LogID ${o}`:""}`);let a=H(r)&&H(r.data)&&typeof r.data.url=="string"?r.data.url.trim():"";if(!a)throw new Error(`Attachment download URL response is missing data.url${o?`, LogID ${o}`:""}`);return a}function tt(e){let t=new URLSearchParams;e.env===Q&&t.set("env",Q);let n=t.toString(),o=`${We}/${encodeURIComponent(e.token)}/invoke_get`;return n?`${o}?${n}`:o}function nt(e,t){if(!Je.test(t))throw new TypeError(`functionId ${t} does not match the required pattern ${String(Je)}`);let n=`${We}/${encodeURIComponent(e.token)}/functions/${encodeURIComponent(t)}/invoke`;return e.env===Q?`${n}?env=${encodeURIComponent(Q)}`:n}var Vt="x-base-site-session-id",qt="x-base-site-read-your-writes",Yt=800008918,Qe=new Map,Pe={maxRetries:3,intervalMs:300},pe={...Pe},Gt=10,Kt=100,Jt=2e3;function Qt(e){let t=H(e)?e.readYourWritesRetry:void 0;return H(t)&&Number.isInteger(t.maxRetries)&&t.maxRetries>=0&&t.maxRetries<=Gt&&Number.isInteger(t.intervalMs)&&t.intervalMs>=Kt&&t.intervalMs<=Jt?{maxRetries:t.maxRetries,intervalMs:t.intervalMs}:{...Pe}}function Wt(e){let t=Qe.get(e);if(t)return t;let n=`baseSite:session:${e}`,o;try{o=localStorage.getItem(n)||void 0}catch{o=void 0}if(!o){try{o=crypto.randomUUID()}catch{return}try{localStorage.setItem(n,o)}catch{}}return Qe.set(e,o),o}function ot(e){let t=Wt(e);return{"content-type":"application/json",...t?{[Vt]:t}:{}}}var xe=class extends oe{logId;constructor(t={}){super("FUNCTION_INVOKE_FAILED","The write has succeeded but the data is not readable yet. Do not repeat the write; retry the query shortly.","800008918",!0),this.name="DataNotReadyError",this.logId=t.logId}};async function fo(e,t,n){let o=await z();if(!o.token)throw new Error(`Cannot invoke Function ${e} without an app token`);let r=n?.readYourWrites!==!1,i={...ot(o.token),...r?{[qt]:"1"}:{}},a=()=>ue({url:nt(o,e),init:{body:JSON.stringify({params:t}),headers:i,method:"POST"}});for(let s=0;;s++){let c=await a();if(!c.ok)throw new Error(`Function ${e} request failed: HTTP ${c.status}`);let d=await c.json();if(r&&d?.code===Yt){if(s<pe.maxRetries){await new Promise(u=>setTimeout(u,pe.intervalMs));continue}throw new xe({logId:d.data?.log_id})}return d}}async function go(e,t){if(!Array.isArray(t)||t.length<1||t.length>200||t.some(r=>r===null||typeof r!="object"||Array.isArray(r)))throw new TypeError("Mutation batch requires 1 to 200 named parameter objects");let n=await z();if(!n.token)throw new Error("\u5E94\u7528 token \u672A\u786E\u5B9A\uFF0C\u65E0\u6CD5\u8C03\u7528 Mutation");let o=await ue({url:nt(n,e),init:{body:JSON.stringify({batch:t.map(r=>({params:r}))}),headers:ot(n.token),method:"POST"}});if(!o.ok)throw new Error(`Mutation \u8C03\u7528\u5931\u8D25\uFF1AHTTP ${o.status}`);return await o.json()}async function ho(e,t){let n=await zt(e,t);if(!(await de(n)).opened)throw new Error("The host did not open the attachment download link")}function bo(e,t,n=360){if(!e.gatewayOrigin||!e.token||!Se(t))return"";let o=[120,360,720,1280].find(i=>i>=n)??1280,r=new URLSearchParams({extra:JSON.stringify({bitablePerm:{tableId:t.tableId,attachments:{[t.fieldId]:{[t.recordId]:[t.fileToken]}},baseAppToken:e.token}}),width:String(o),height:String(o),policy:"allow_up",fallback_source:"1"});return`${e.gatewayOrigin}/space/api/box/stream/download/v2/cover/${encodeURIComponent(t.fileToken)}?${r.toString()}`}var Le=Zt(void 0),at=[{id:"en",locale:"en-US",match:/^en(?:-|$)/},{id:"zh",locale:"zh-CN",match:/^zh(?:-|$)/},{id:"ja",locale:"ja-JP",match:/^ja(?:-|$)/}],Ie=new Set,it,Ae=null;function ke(e){if(typeof e!="string")return;let t=e.trim().replace(/_/g,"-").toLowerCase();return at.find(({match:n})=>n.test(t))?.id}function nn(){return typeof navigator>"u"?void 0:navigator.language}function on(e,t){return ke(e)??ke(t)??"en"}function V(){return it??on(void 0,nn())}function Te(e=V()){return at.find(({id:t})=>t===e)?.locale??"en-US"}function rn(e){return Ie.add(e),()=>Ie.delete(e)}function rt(e){it=ke(e);let t=V();st(t);for(let n of Ie)n();return t}function st(e){typeof document<"u"&&(document.documentElement.lang=Te(e))}function an(){return Ae||(st(V()),Ae=P.getRuntimeContext().then(e=>rt(e?.locale)).catch(()=>rt(void 0))),Ae}function k(){let e=Xt(Le),t=tn(rn,V,()=>"en");return en(()=>{e||an()},[e]),e??t}import{jsx as _e}from"react/jsx-runtime";var Me=sn(null);function So({children:e,...t}){return _e(Me.Provider,{value:t,children:_e(Le.Provider,{value:t.locale,children:_e("div",{className:"base-app-platform","data-theme":t.theme,children:e})})})}function Po(){let e=ct(Me);if(!e)throw new Error("BASE_APP_PROVIDER_REQUIRED");return e}function me(){return ct(Me)}import{useState as Z,useEffect as gt,useLayoutEffect as hn,useRef as Fe,useId as bn}from"react";import{jsx as D,jsxs as cn}from"react/jsx-runtime";function lt(){return D("svg",{"aria-hidden":"true",focusable:"false",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:D("path",{d:"M17.1956 16.3595C17.6558 16.3595 18.0289 16.7326 18.0289 17.1928C18.0287 17.6529 17.6557 18.0261 17.1956 18.0261H9.48724C9.0273 18.0259 8.65411 17.6527 8.6539 17.1928C8.6539 16.7327 9.02717 16.3597 9.48724 16.3595H17.1956ZM12.5732 2.47195C13.8817 1.28992 15.902 1.32977 17.163 2.59076L17.281 2.71527C18.4249 3.98149 18.4257 5.91435 17.2818 7.18061L17.163 7.3043L9.32366 15.1445C9.12419 15.3439 8.89959 15.5169 8.65716 15.6596L8.40976 15.7923L4.13079 17.8471C2.75554 18.5075 1.31776 17.1336 1.84889 15.7565L1.90667 15.623L3.96152 11.344C4.12431 11.0051 4.34347 10.696 4.60931 10.4301L12.4495 2.59076L12.5732 2.47195ZM5.78769 11.6093C5.65491 11.7421 5.54596 11.8966 5.46461 12.0659L3.40976 16.344L7.68792 14.2892C7.85719 14.2078 8.01164 14.0989 8.14446 13.9661L13.4643 8.64545L11.1075 6.28868L5.78769 11.6093ZM15.9846 3.76915C15.3338 3.11835 14.2788 3.11851 13.6279 3.76915L12.2867 5.11029L14.6435 7.46706L15.9846 6.12592C16.6353 5.47503 16.6354 4.41994 15.9846 3.76915Z",fill:"currentColor"})})}function ut(){return D("svg",{"aria-hidden":"true",focusable:"false",width:"24",height:"6",viewBox:"0 0 24 6",fill:"none",children:D("path",{d:"M8.4383 1.99309L11.2526 5.15916C11.6504 5.60668 12.3496 5.60668 12.7474 5.15916L15.5617 1.99309C16.6886 0.725344 18.3038 0 20 0L12 0L4 0C5.69619 0 7.31142 0.725345 8.4383 1.99309Z",fill:"#1F2329"})})}function dt(){return cn("svg",{"aria-hidden":"true",focusable:"false",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[D("circle",{cx:"8.00008",cy:"8.00033",r:"7.33333",fill:"#1456F0"}),D("path",{d:"M8 5.33333C8.36819 5.33333 8.66667 5.03486 8.66667 4.66667C8.66667 4.29848 8.36819 4 8 4C7.63181 4 7.33333 4.29848 7.33333 4.66667C7.33333 5.03486 7.63181 5.33333 8 5.33333Z",fill:"white"}),D("path",{d:"M7.33333 6C6.96514 6 6.66667 6.29848 6.66667 6.66667C6.66667 7.03486 6.96514 7.33333 7.33333 7.33333V10H6.66667C6.29848 10 6 10.2985 6 10.6667C6 11.0349 6.29848 11.3333 6.66667 11.3333H9.33333C9.70152 11.3333 10 11.0349 10 10.6667C10 10.2985 9.70152 10 9.33333 10H8.66667V6.66667C8.66667 6.29848 8.36819 6 8 6H7.33333Z",fill:"white"})]})}function pt(){return D("svg",{"aria-hidden":"true",focusable:"false",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:D("path",{d:"M13.5043 13.5042C13.7646 13.2439 13.7665 12.8237 13.5062 12.5633L8.94298 8.00013L13.5061 3.43697C13.7665 3.17662 13.7646 2.7564 13.5043 2.49605C13.2439 2.2357 12.8237 2.23382 12.5633 2.49416C12.303 2.75451 8.00017 7.05732 8.00017 7.05732L3.43697 2.49413C3.17662 2.23378 2.7564 2.23566 2.49605 2.49601C2.2357 2.75636 2.23381 3.17658 2.49416 3.43693L7.05736 8.00013L2.49413 12.5634C2.23378 12.8237 2.23566 13.2439 2.49601 13.5043C2.75636 13.7646 3.17659 13.7665 3.43693 13.5062L8.00017 8.94294L12.5634 13.5061C12.8237 13.7665 13.2439 13.7646 13.5043 13.5042Z",fill:"#646A73"})})}import{QueryClient as ln}from"@tanstack/react-query";var De=new ln({defaultOptions:{queries:{retry:!1,staleTime:3e4,gcTime:3e4}}});function fe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ge(e,t){let n=e[t];return typeof n=="string"?n.trim():""}function un(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function q(){return{baseBindings:[],name:"",description:"",isOwner:!1,allowEdit:!1,organization:""}}function dn(){let e=document.querySelector('meta[name="description"]');return e instanceof HTMLMetaElement?e:null}function pn(e){if(e.name&&(document.title=e.name),e.description){let t=dn();t&&(t.content=e.description)}}function mn(e){return Array.isArray(e)?e.reduce((t,n)=>{if(!fe(n))return t;let o=ge(n,"baseToken");return o&&t.push({baseToken:o,tableIds:un(n.tableIds)}),t},[]):[]}function fn(e){if(!fe(e)||e.code!==0)return q();let t=e.data;if(!fe(t))return q();let n=t.site;return fe(n)?{baseBindings:mn(n.baseBindings),description:ge(n,"description"),name:ge(n,"name"),isOwner:t.isOwner===!0,allowEdit:n.allowEdit===void 0?t.isOwner===!0:n.allowEdit===!0,organization:ge(n,"organization")}:q()}async function mt(e){try{let t=await N(tt(e),{method:"GET"});if(!t.ok)return q();let n=await t.json(),o=fn(n);return pn(o),o}catch{return q()}}async function W(){let e=await z();if(!e.token)return q();let t=await ae().catch(()=>null);return t?.userId?De.fetchQuery({queryKey:["project-meta",e.token,e.env,t.userId],queryFn:()=>mt(e)}):mt(e)}var gn="https://feishu.cn/base/site/detail/overview";async function ft(){try{await P.requestEdit();return}catch{let{token:e}=await z(),t=new URL(gn);if(t.searchParams.set("token",e),!(await de(t.toString())).opened)throw new Error("Management page was not opened")}}import{jsx as U,jsxs as he}from"react/jsx-runtime";var yn={en:{openFailed:"Unable to open the management page. Please try again.",editSite:"Edit and manage your apps",hidePanel:"Hide until next visit",hiddenConfirmation:"Edit button hidden until you reopen the app",dismissNotification:"Dismiss notification"},zh:{openFailed:"\u65E0\u6CD5\u6253\u5F00\u7BA1\u7406\u9875\u9762\uFF0C\u8BF7\u91CD\u8BD5",editSite:"\u7F16\u8F91\u4E0E\u7BA1\u7406\u5E94\u7528",hidePanel:"\u9690\u85CF\u9762\u677F",hiddenConfirmation:"\u7F16\u8F91\u6309\u94AE\u5DF2\u9690\u85CF\uFF0C\u76F4\u81F3\u4E0B\u6B21\u91CD\u65B0\u6253\u5F00\u5E94\u7528",dismissNotification:"\u5173\u95ED\u63D0\u793A"},ja:{openFailed:"\u7BA1\u7406\u30DA\u30FC\u30B8\u3092\u958B\u3051\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",editSite:"\u30A2\u30D7\u30EA\u3092\u7DE8\u96C6\u30FB\u7BA1\u7406",hidePanel:"\u6B21\u56DE\u306E\u30A2\u30AF\u30BB\u30B9\u307E\u3067\u975E\u8868\u793A",hiddenConfirmation:"\u7DE8\u96C6\u30DC\u30BF\u30F3\u3092\u975E\u8868\u793A\u306B\u3057\u307E\u3057\u305F\u3002\u30A2\u30D7\u30EA\u3092\u518D\u5EA6\u958B\u304F\u3068\u8868\u793A\u3055\u308C\u307E\u3059",dismissNotification:"\u901A\u77E5\u3092\u9589\u3058\u308B"}};function Yo({position:e="bottom-right",className:t="",slots:n={}}){let o=yn[k()],[r,i]=Z(!1),[a,s]=Z(!1),[c,d]=Z(!1),[u,p]=Z(!1),[m,g]=Z(null),[f,E]=Z(null),x=Fe(null),O=Fe(null),S=Fe(null),_=bn();hn(()=>{if(!m)return;let h=m==="edit"?x.current:O.current,w=S.current;if(!h||!w)return;let v=()=>{let X=h.getBoundingClientRect(),ee=X.left+X.width/2,te=Math.ceil(w.getBoundingClientRect().width),ne=Math.max(8,Math.min(ee-te/2,window.innerWidth-te-8));E({left:ne,top:X.top-w.offsetHeight-14,arrowLeft:ee-ne})};v(),window.addEventListener("resize",v);let K=new ResizeObserver(v);return K.observe(w),()=>{window.removeEventListener("resize",v),K.disconnect()}},[m,o,e,n.tooltip]),gt(()=>{let h=!0;return W().then(w=>{h&&i(w.allowEdit&&Ue().env==="prod")}).catch(()=>{}),()=>{h=!1}},[]),gt(()=>{if(!c)return;let h=setTimeout(()=>d(!1),3e3);return()=>clearTimeout(h)},[c]);let A=n.trigger,y=n.tooltip;return r?a?c?he("div",{className:"base-app-platform base-app-notice",role:"status",children:[U(dt,{}),U("span",{children:o.hiddenConfirmation}),U("button",{type:"button","aria-label":o.dismissNotification,onClick:()=>d(!1),children:U(pt,{})})]}):null:he("div",{className:`base-app-platform base-app-floating ${t}`,"data-position":e,children:[u?U("div",{role:"alert",children:o.openFailed}):null,m?he("div",{ref:S,id:_,role:"tooltip",style:f?{left:f.left,top:f.top}:{visibility:"hidden"},children:[y?U(y,{text:m==="edit"?o.editSite:o.hidePanel}):m==="edit"?o.editSite:o.hidePanel,U("span",{className:"base-app-floating-caret",style:{left:f?.arrowLeft},children:U(ut,{})})]}):null,he("div",{className:"base-app-floating-controls",children:[U("button",{ref:x,type:"button",className:"base-app-floating-edit","aria-describedby":m==="edit"?_:void 0,"aria-label":o.editSite,onFocus:()=>g("edit"),onBlur:()=>g(null),onMouseEnter:()=>g("edit"),onMouseLeave:()=>g(null),onClick:()=>{p(!1),ft().catch(()=>p(!0))},children:A?U(A,{}):U(lt,{})}),U("button",{ref:O,type:"button",className:"base-app-floating-hide","aria-describedby":m==="hide"?_:void 0,"aria-label":o.hidePanel,onFocus:()=>g("hide"),onBlur:()=>g(null),onMouseEnter:()=>g("hide"),onMouseLeave:()=>g(null),onClick:()=>{s(!0),g(null),d(!0)},children:U("span",{"aria-hidden":"true",children:"\xD7"})})]})]}):null}var Oe=new Set;function ht(e){return Oe.add(e),()=>{Oe.delete(e)}}function bt(){for(let e of Oe)e()}import{useEffect as wn,useState as wt}from"react";import*as B from"@radix-ui/react-popover";async function yt(){try{let e=await ae();if(typeof e?.name=="string"&&e.name)return{name:e.name,avatarUrl:typeof e.avatarUrl=="string"?e.avatarUrl:"",tenantName:""}}catch{}try{let e=await N("/space/api/user/",{headers:{accept:"application/json"}});if(!e.ok)return null;let n=(await e.json()).data;return!n||typeof n.name!="string"||!n.name?null:{name:n.name,avatarUrl:typeof n.avatar_url=="string"?n.avatar_url:"",tenantName:typeof n.tenant_name=="string"?n.tenant_name:""}}catch{return null}}import{Fragment as Cn,jsx as L,jsxs as Ne}from"react/jsx-runtime";var vn={en:{account:"Account",logout:"Log out"},zh:{account:"\u8D26\u53F7",logout:"\u9000\u51FA\u767B\u5F55"},ja:{account:"\u30A2\u30AB\u30A6\u30F3\u30C8",logout:"\u30ED\u30B0\u30A2\u30A6\u30C8"}};function ir({audience:e="enterprise",align:t="right",side:n="down",showName:o=!0,className:r="",slots:i={}}){let[a,s]=wt(null),[c,d]=wt(""),u=me(),p=vn[k()];if(wn(()=>{if(e!=="enterprise")return;let f=!0;return Promise.all([yt(),W().catch(()=>null)]).then(([E,x])=>{f&&(s(E),d(E?.tenantName||x?.organization||""))}),()=>{f=!1}},[e]),e!=="enterprise"||!a)return null;let m=i.trigger,g=i.organization;return Ne(B.Root,{children:[L(B.Trigger,{asChild:!0,children:L("button",{className:`base-app-platform base-app-user-menu ${r}`,"aria-label":p.account,children:m?L(m,{user:a}):Ne(Cn,{children:[a.avatarUrl?L("img",{src:a.avatarUrl,alt:"",referrerPolicy:"no-referrer"}):L("span",{children:a.name.slice(0,1)}),o?a.name:null]})})}),L(B.Portal,{children:Ne(B.Content,{"data-theme":u?.theme,className:"base-app-platform base-app-popover",align:t==="right"?"end":"start",side:n==="up"?"top":"bottom",sideOffset:8,collisionPadding:8,children:[L("strong",{children:a.name}),g?L(g,{name:c}):L("p",{children:c}),L("button",{onClick:()=>{bt(),De.clear(),Ee().catch(()=>{for(let f of["base-site-session","session","sl_session"])document.cookie=`${f}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;window.location.reload()})},children:p.logout})]})})]})}import{useEffect as be,useRef as Rt,useState as Y}from"react";import{Command as se}from"cmdk";import{QueryClient as _n,useQuery as Mn}from"@tanstack/react-query";var Rn="/space/api/mention/recommend.v2/",En="8",xn="4",Un="0",Sn=20,vt={en:{businessError:e=>`Could not search members (error code ${e})`,httpError:e=>`Member search request failed: HTTP ${e}`,invalidResponse:"Member search response has an invalid structure",noBoundBase:"Cannot search members: the application is not bound to a Base"},zh:{businessError:e=>`\u641C\u7D22\u6210\u5458\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${e}\uFF09`,httpError:e=>`\u641C\u7D22\u6210\u5458\u8BF7\u6C42\u5931\u8D25\uFF1AHTTP ${e}`,invalidResponse:"\u6210\u5458\u641C\u7D22\u54CD\u5E94\u7ED3\u6784\u65E0\u6548",noBoundBase:"\u65E0\u6CD5\u641C\u7D22\u6210\u5458\uFF1A\u5E94\u7528\u5C1A\u672A\u7ED1\u5B9A\u591A\u7EF4\u8868\u683C"},ja:{businessError:e=>`\u30E1\u30F3\u30D0\u30FC\u3092\u691C\u7D22\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u30A8\u30E9\u30FC\u30B3\u30FC\u30C9 ${e}\uFF09`,httpError:e=>`\u30E1\u30F3\u30D0\u30FC\u691C\u7D22\u306E\u30EA\u30AF\u30A8\u30B9\u30C8\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF1AHTTP ${e}`,invalidResponse:"\u30E1\u30F3\u30D0\u30FC\u691C\u7D22\u306E\u5FDC\u7B54\u5F62\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093",noBoundBase:"\u30E1\u30F3\u30D0\u30FC\u3092\u691C\u7D22\u3067\u304D\u307E\u305B\u3093\uFF1A\u30A2\u30D7\u30EA\u306BBase\u304C\u95A2\u9023\u4ED8\u3051\u3089\u308C\u3066\u3044\u307E\u305B\u3093"}};async function Ct(e,t,n){let o=t??V(),r=vt[o],a=(await W()).baseBindings[0]?.baseToken;if(!a)throw new Error(r.noBoundBase);let s=new URLSearchParams({config_source:"0",obj_type:En,source:xn,token:a,type:Un,user_type:"0",content:e.trim().slice(0,50)}).toString(),c=await N(Rn,{signal:n,body:s,headers:{"content-type":"application/x-www-form-urlencoded"},method:"POST"});if(!c.ok)throw new Error(r.httpError(c.status));let d=await c.json();return{code:0,msg:"ok",data:Pn(d,o)}}function Pn(e,t=V()){let n=Te(t),o=vt[t],r=An(e,o);if(!r)throw new Error(o.invalidResponse);let i=r.entities,a=T(i)?i.users:void 0;if(!T(a)||!Array.isArray(r.result_list))throw new Error(o.invalidResponse);let s=[],c=new Set;for(let d of r.result_list){if(!T(d)||Number(d.type)!==0)continue;let u=b(d.token);if(!u)continue;let p=a[u];if(!T(p))continue;let m=b(p.user_id)||b(p.id)||u,g=In(p,n);if(!m||!g||c.has(m))continue;c.add(m);let f=b(p.avatar_url),E=b(p.open_id);if(s.push({avatar:{avatar_72:f,avatar_240:f,avatar_640:f,avatar_origin:f},department_ids:Tn(p.department_ids),description:kn(p,n),is_external:p.is_external===!0,name:g,user_id:m,...E?{open_id:E}:{}}),s.length>=Sn)break}return{users:s}}function An(e,t){if(T(e)){if(typeof e.code=="number"&&e.code!==0){let n=b(e.msg);throw Object.assign(new Error(n||t.businessError(e.code)),{code:String(e.code),cause:e})}return"entities"in e&&"result_list"in e?e:T(e.data)?e.data:void 0}}function In(e,t){let n=e.display_name;if(typeof n=="string"&&n.trim())return n.trim();let o=t.toLowerCase().replace("-","_"),r=o.split("_")[0],i=T(n)?n:{},a=T(i.i18n_value)?i.i18n_value:i,s=r==="zh"?e.cn_name:r==="en"?e.en_name:void 0;return b(a[o])||b(a[r])||b(s)||b(i.value)||b(e.name)||b(e.en_name)||b(e.cn_name)}function kn(e,t){let n=e.is_external===!0?e.i18n_tenant:e.i18n_department;return Ln(n,t)||b(e.department)}function Ln(e,t){if(typeof e=="string")return e.trim();if(!T(e))return"";let n=t.toLowerCase().replace("-","_"),o=n.split("_")[0]??"",r=T(e.i18n_value)?e.i18n_value:e,i=b(r[n])||b(r[o]);if("i18n_value"in e)return i||b(e.value);let a=o==="zh"?b(r.zh_cn)||b(r.en_us):b(r.en_us)||b(r.zh_cn);return i||b(e.value)||a}function b(e){return typeof e=="string"?e.trim():""}function Tn(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function T(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}import{Fragment as xt,jsx as R,jsxs as Be}from"react/jsx-runtime";var Ut={en:{invalidResponse:"Member search response has an invalid structure",loading:"Loading...",memberList:"Member list",noMatches:"No matching members. Try another search term.",noRecommendations:"No recommended members yet",recordCreator:"Add the person who created this record",searchFailed:"Member search failed",searchFailedCode:e=>`Could not search members (error code ${e})`,searchMembers:"Search members"},zh:{invalidResponse:"\u6210\u5458\u641C\u7D22\u54CD\u5E94\u7ED3\u6784\u65E0\u6548",loading:"\u52A0\u8F7D\u4E2D...",memberList:"\u6210\u5458\u5217\u8868",noMatches:"\u6CA1\u6709\u5339\u914D\u7684\u6210\u5458\uFF0C\u8BF7\u6362\u4E2A\u5173\u952E\u8BCD",noRecommendations:"\u6682\u65E0\u63A8\u8350\u6210\u5458",recordCreator:"\u6DFB\u52A0\u6B64\u8BB0\u5F55\u7684\u4EBA\u5458",searchFailed:"\u641C\u7D22\u6210\u5458\u5931\u8D25",searchFailedCode:e=>`\u641C\u7D22\u6210\u5458\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${e}\uFF09`,searchMembers:"\u641C\u7D22\u6210\u5458"},ja:{invalidResponse:"\u30E1\u30F3\u30D0\u30FC\u691C\u7D22\u306E\u5FDC\u7B54\u5F62\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093",loading:"\u8AAD\u307F\u8FBC\u307F\u4E2D...",memberList:"\u30E1\u30F3\u30D0\u30FC\u4E00\u89A7",noMatches:"\u4E00\u81F4\u3059\u308B\u30E1\u30F3\u30D0\u30FC\u304C\u3044\u307E\u305B\u3093\u3002\u5225\u306E\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22\u3057\u3066\u304F\u3060\u3055\u3044\u3002",noRecommendations:"\u304A\u3059\u3059\u3081\u306E\u30E1\u30F3\u30D0\u30FC\u304C\u3044\u307E\u305B\u3093",recordCreator:"\u3053\u306E\u30EC\u30B3\u30FC\u30C9\u306E\u4F5C\u6210\u8005\u3092\u8FFD\u52A0",searchFailed:"\u30E1\u30F3\u30D0\u30FC\u306E\u691C\u7D22\u306B\u5931\u6557\u3057\u307E\u3057\u305F",searchFailedCode:e=>`\u30E1\u30F3\u30D0\u30FC\u3092\u691C\u7D22\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u30A8\u30E9\u30FC\u30B3\u30FC\u30C9 ${e}\uFF09`,searchMembers:"\u30E1\u30F3\u30D0\u30FC\u3092\u691C\u7D22"}};function ye(e){let[t,n]=Y(!1),[o,r]=Y(!1);be(()=>r(!0),[]);let i=k(),a=Ut[i],[s]=Y(()=>new _n({defaultOptions:{queries:{retry:!1,staleTime:3e4,gcTime:3e4}}}));be(()=>{let l=ht(()=>{n(!0),s.clear()});return()=>{l(),s.clear()}},[s]);let c=Object.prototype.hasOwnProperty.call(e,"value"),d=Rt(c);be(()=>{c!==d.current&&console.warn("UserSelectorPanel controlled mode changed")},[c]);let[u,p]=Y(e.defaultValue),m=c?e.value:u,g=Array.isArray(m)?m:m?[m]:[],[f,E]=Y(""),[x,O]=Y(""),[S,_]=Y(!1),A=Rt(!1);be(()=>{if(S)return;let l=setTimeout(()=>O(f.trim()),f.trim()?400:0);return()=>clearTimeout(l)},[f,S]);let y=Mn({queryKey:["members",i,x],queryFn:async({signal:l})=>{let C=await Ct(x,i,l);return Dn(C,i)},enabled:!t&&o&&!S&&f.trim()===x},s),h=e.loading||y.isFetching||f.trim()!==x,w=!t&&!h&&!y.error&&y.data?[...y.data.users,...g.filter(l=>!y.data.users.some(C=>C.user_id===l.user_id))]:[],v=(l,C)=>{E(l),e.onSearch?.(l,{action:C})},K=()=>{v("","AutoClear"),e.onClose?.()},X=l=>{if(A.current)return;let C=g.some(we=>we.user_id===l.user_id),ce=e.mode==="multiple"?C?g.filter(we=>we.user_id!==l.user_id):[...g,l]:C?void 0:l;c||p(ce),e.onChange?.(ce,{option:l,action:C?"Remove":"Select"}),C||e.onSelect?.(l,{option:l}),e.mode==="multiple"?v("","AutoClear"):K()},ee=e.slots?.empty,te=e.slots?.loading,ne=e.slots?.option,$e=e.slots?.footer;return Be(se,{shouldFilter:!1,loop:!0,className:`base-app-platform base-app-selector ${e.className??""}`,label:a.memberList,children:[R(se.Input,{autoFocus:!0,placeholder:a.searchMembers,"aria-label":a.searchMembers,value:f,onValueChange:l=>v(l,"Input"),onCompositionStart:()=>{A.current=!0,_(!0)},onCompositionEnd:()=>{A.current=!1,_(!1)},onKeyDown:l=>{if(e.onKeyDown?.(l),l.defaultPrevented){l.stopPropagation();return}if(A.current||Fn(l)){l.stopPropagation();return}l.key==="Escape"&&(l.preventDefault(),K())}}),R(se.List,{"aria-label":a.memberList,"aria-multiselectable":e.mode==="multiple"||void 0,children:h?R("div",{role:"status",children:te?R(te,{}):a.loading}):y.error?R("div",{role:"alert",children:a.searchFailed}):Be(xt,{children:[e.onSelectRecordCreator?R(se.Item,{value:"record-creator",onSelect:()=>{e.onSelectRecordCreator?.(),K()},children:a.recordCreator}):null,w.map(l=>{let C=g.some(ce=>ce.user_id===l.user_id);return R(se.Item,{value:l.user_id,onSelect:()=>X(l),"data-checked":C,children:ne?R(ne,{user:l,selected:C}):Be(xt,{children:[R("span",{children:l.name}),R("small",{children:e.getUserDescription?.(l)??l.description}),C?R("span",{"aria-label":"selected",children:"\u2713"}):null]})},l.user_id)}),!w.length&&!e.onSelectRecordCreator?R("div",{role:"status",children:ee?R(ee,{}):f.trim()?a.noMatches:a.noRecommendations}):null]})}),$e?R($e,{}):null]})}function Dn(e,t){let n=Ut[t];if(!Et(e)||typeof e.code!="number")throw new Error(n.invalidResponse);if(e.code!==0){let o=typeof e.msg=="string"?e.msg.trim():"";throw Object.assign(new Error(o||n.searchFailedCode(e.code)),{code:String(e.code),cause:e})}if(!Et(e.data)||!Array.isArray(e.data.users))throw new Error(n.invalidResponse);return{users:e.data.users}}function Et(e){return typeof e=="object"&&e!==null}function Fn(e){return e.nativeEvent?.isComposing===!0||e.keyCode===229}import{useState as On,useRef as Nn}from"react";import*as j from"@radix-ui/react-popover";import{jsx as F,jsxs as St}from"react/jsx-runtime";var Bn={en:{clearSelected:"Clear selected members",removeMember:e=>`Remove member ${e}`,selectMembers:"Select members"},zh:{clearSelected:"\u6E05\u9664\u5DF2\u9009\u6210\u5458",removeMember:e=>`\u79FB\u9664\u6210\u5458 ${e}`,selectMembers:"\u9009\u62E9\u6210\u5458"},ja:{clearSelected:"\u9078\u629E\u3057\u305F\u30E1\u30F3\u30D0\u30FC\u3092\u30AF\u30EA\u30A2",removeMember:e=>`\u30E1\u30F3\u30D0\u30FC ${e} \u3092\u524A\u9664`,selectMembers:"\u30E1\u30F3\u30D0\u30FC\u3092\u9078\u629E"}};function Pt(e){let t=Nn(null),n=me(),o=Bn[k()],[r,i]=On(!1),a=Array.isArray(e.value)?e.value:e.value?[e.value]:[],s=u=>{i(u),u!==r&&e.onDropdownVisibleChange?.(u)},c=e.slots?.trigger,d=e.slots?.chip;return St(j.Root,{open:r,onOpenChange:s,children:[St("div",{ref:t,className:`base-app-platform base-app-editor ${e.className??""}`,onClickCapture:u=>{u.target.closest("[data-base-app-trigger]")&&e.onClick?.(u)},children:[F(j.Trigger,{asChild:!0,children:F("button",{type:"button","data-base-app-trigger":"","aria-label":o.selectMembers,onFocus:e.onFocus,onBlur:e.onBlur,children:c?F(c,{value:e.value}):a.length?a.map(u=>F("span",{children:d?F(d,{user:u}):u.name},u.user_id)):o.selectMembers})}),a.map(u=>F("button",{type:"button","aria-label":e.mode==="multiple"?o.removeMember(u.name):o.clearSelected,onClick:p=>{p.stopPropagation(),e.onChange?.(e.mode==="multiple"?a.filter(m=>m.user_id!==u.user_id):void 0),e.mode==="multiple"?e.onRemove?.(u):e.onClear?.()},children:"\xD7"},u.user_id))]}),F(j.Portal,{container:e.portalContainer??t.current?.closest("dialog")??void 0,children:F(j.Content,{"data-theme":n?.theme,className:"base-app-platform base-app-popover",sideOffset:4,collisionPadding:8,children:F(ye,{...e,slots:void 0,onChange:(u,p)=>{e.onChange?.(u),p.action==="Remove"&&p.option&&e.onRemove?.(p.option)},onClose:()=>s(!1)})})})]})}import{useEffect as At,useRef as jn,useState as je}from"react";import{jsx as G,jsxs as Hn}from"react/jsx-runtime";var $n={en:{decodeFailed:"Image could not be decoded",loadFailed:"Failed to load image",loading:"Loading image",retry:"Retry image"},zh:{decodeFailed:"\u56FE\u7247\u65E0\u6CD5\u89E3\u7801",loadFailed:"\u56FE\u7247\u52A0\u8F7D\u5931\u8D25",loading:"\u56FE\u7247\u52A0\u8F7D\u4E2D",retry:"\u91CD\u8BD5\u56FE\u7247"},ja:{decodeFailed:"\u753B\u50CF\u3092\u8868\u793A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F",loadFailed:"\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F",loading:"\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u307F\u4E2D",retry:"\u753B\u50CF\u3092\u518D\u8AAD\u307F\u8FBC\u307F"}};function Tr({attachment:e,size:t=360,alt:n,className:o,slots:r={}}){let i=k(),a=$n[i],s=jn(null),[c,d]=je(!1),[u,p]=je(0),[m,g]=je({key:"",url:"",error:""}),{tableId:f,fieldId:E,recordId:x,fileToken:O}=e,S=JSON.stringify([f,E,x,O,t,u]);At(()=>{if(typeof IntersectionObserver>"u"){d(!0);return}let h=new IntersectionObserver(w=>{w.some(v=>v.isIntersecting)&&(d(!0),h.disconnect())},{rootMargin:"200px"});return s.current&&h.observe(s.current),()=>h.disconnect()},[]),At(()=>{if(!c)return;let h=new AbortController,w="";return et({tableId:f,fieldId:E,recordId:x,fileToken:O},t,{signal:h.signal}).then(v=>{h.signal.aborted||(w=URL.createObjectURL(v),g({key:S,url:w,error:""}))}).catch(v=>{h.signal.aborted||g({key:S,url:"",error:v instanceof Error?v.message:"",localError:v instanceof Error?void 0:"loadFailed"})}),()=>{h.abort(),w&&URL.revokeObjectURL(w)}},[c,S,f,E,x,O,t]);let _=r.loading,A=r.error,y=m.key===S?m:void 0;return G("span",{ref:s,className:`base-app-platform base-app-attachment ${o??""}`,"aria-busy":!y,children:y?.url?G("img",{src:y.url,alt:n,onError:()=>g({key:S,url:"",error:"",localError:"decodeFailed"})}):y?.error||y?.localError?A?G(A,{code:"ATTACHMENT_LOAD_FAILED",retry:()=>p(h=>h+1)}):Hn("span",{children:[G("span",{role:"status",children:y.localError?a[y.localError]:y.error}),G("button",{type:"button",onClick:()=>p(h=>h+1),children:a.retry})]}):G("span",{role:"status",children:_?G(_,{}):a.loading})})}export{qn as a,le as b,Yn as c,Gn as d,Kn as e,Jn as f,Qn as g,Ke as h,Re as i,Ce as j,so as k,P as l,ue as m,co as n,ae as o,Ee as p,Dt as q,lo as r,de as s,Ft as t,N as u,ve as v,It as w,kt as x,Xn as y,Lt as z,Ve as A,Ue as B,z as C,et as D,zt as E,tt as F,nt as G,xe as H,fo as I,go as J,ho as K,bo as L,Le as M,on as N,V as O,Te as P,an as Q,k as R,So as S,Po as T,me as U,De as V,Yo as W,ir as X,ye as Y,Pt as Z,Tr as _};
|
package/dist/codegen.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
"use strict";var A=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var A=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var D=(n,t)=>{for(var i in t)A(n,i,{get:t[i],enumerable:!0})},E=(n,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of R(t))!x.call(n,e)&&e!==i&&A(n,e,{get:()=>t[e],enumerable:!(r=C(t,e))||r.enumerable});return n};var M=n=>E(A({},"__esModule",{value:!0}),n);var V={};D(V,{CodegenError:()=>m,SUPPORTED_CONTRACT_FORMAT_VERSIONS:()=>U,generateFunctionClients:()=>L,validateContractData:()=>S});module.exports=M(V);var T=require("json-schema-to-typescript");function f(n,t){if(!n||typeof n!="object"||Array.isArray(n))return;let i=n;t(i);for(let e of["properties","patternProperties","$defs","definitions","dependentSchemas"]){let o=i[e];if(o&&typeof o=="object"&&!Array.isArray(o))for(let s of Object.values(o))f(s,t)}for(let e of["items","additionalItems","additionalProperties","unevaluatedProperties","unevaluatedItems","contains","propertyNames","not","if","then","else"]){let o=i[e];Array.isArray(o)?o.forEach(s=>f(s,t)):f(o,t)}for(let e of["allOf","anyOf","oneOf","prefixItems"])Array.isArray(i[e])&&i[e].forEach(o=>f(o,t));let r=i.dependencies;if(r&&typeof r=="object"&&!Array.isArray(r))for(let e of Object.values(r))Array.isArray(e)||f(e,t)}function l(n){if(!n||typeof n!="object"||Array.isArray(n)||Buffer.byteLength(JSON.stringify(n))>32768)throw new Error("CONTRACT_SCHEMA_BUDGET");let t=0,i=(r,e)=>{if(!(!r||typeof r!="object")){if(++t>256||e>16)throw new Error("CONTRACT_SCHEMA_BUDGET");Object.values(r).forEach(o=>i(o,e+1))}};i(n,0),f(n,r=>{if(Object.hasOwn(r,"$ref")&&(typeof r.$ref!="string"||!r.$ref.startsWith("#/")))throw new Error("CONTRACT_EXTERNAL_REF");if(["$id","$dynamicRef","$recursiveRef","tsType","tsEnumNames"].some(e=>Object.hasOwn(r,e)))throw new Error("CONTRACT_EXTERNAL_REF")})}var p="@lark-base-open/base-database-app-sdk/page",b=`/* Generated by base-database-cli. Do not edit. */
|
|
2
2
|
import type { DatabaseFunctionInputMap as GeneratedInputMap } from './database-function-inputs.generated';
|
|
3
|
-
import '${
|
|
4
|
-
declare module '${
|
|
3
|
+
import '${p}';
|
|
4
|
+
declare module '${p}' { interface FunctionInputMap extends GeneratedInputMap {} }
|
|
5
5
|
`,O=`/* Generated by base-database-cli. Map is declared in ../generated/functions. */
|
|
6
6
|
export {};
|
|
7
7
|
`;async function h(n,t){l(n);try{return await(0,T.compile)(j(n,t),t,{bannerComment:"",customName:(i,r)=>i.title===t?t:i.title||r?`${t}_${i.title||r}`:void 0,unknownAny:!0,additionalProperties:!0,$refOptions:{resolve:{http:!1,file:!1}}})}catch{return`// Schema could not be represented; no precision is claimed.
|
|
8
|
-
export type ${t} = unknown;`}}function _(n){if(!n||n.type!=="object")return;let t=n.properties;if(!t||typeof t!="object"||Array.isArray(t))return;let i=t.rows;if(!i||typeof i!="object"||Array.isArray(i))return;let r=i,e=r.items;return r.type==="array"&&e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}async function
|
|
9
|
-
`)}async function
|
|
10
|
-
const response = await invokeDatabaseFunction(${JSON.stringify(s.functionId)}, input);
|
|
8
|
+
export type ${t} = unknown;`}}function _(n){if(!n||n.type!=="object")return;let t=n.properties;if(!t||typeof t!="object"||Array.isArray(t))return;let i=t.rows;if(!i||typeof i!="object"||Array.isArray(i))return;let r=i,e=r.items;return r.type==="array"&&e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}async function $(n,t){let i=new Map(n.map(s=>[s.functionId,s]));for(let s of t)!i.has(s.functionId)&&s.functionType!==void 0&&i.set(s.functionId,{functionId:s.functionId,functionType:s.functionType});let r=[...i.values()],e=["/* Generated by base-database-cli from Function metadata. Do not edit. */",...r.some(s=>s.functionType===1)?[`import type { DatabaseQueryResult } from '${p}';`]:[],...r.some(s=>s.functionType===5&&!s.output)?[`import type { DatabaseMutationResult } from '${p}';`]:[]],o=[];for(let[s,u]of r.sort((a,c)=>a.functionId.localeCompare(c.functionId)).entries()){let a=`Function${s}Output`;if(u.functionType===1){let c=_(u.output);if(c){let g=`Function${s}Row`;e.push(await h(c,g)),e.push(`export type ${a} = DatabaseQueryResult<${g}>;`)}else e.push(`export type ${a} = DatabaseQueryResult<unknown>;`)}else u.functionType===5&&!u.output?e.push(`export type ${a} = DatabaseMutationResult;`):u.output?e.push(await h(u.output,a)):e.push(`export type ${a} = unknown;`);o.push(` ${JSON.stringify(u.functionId)}: ${a};`)}return e.push("export type DatabaseFunctionOutputMap = {",...o,"};",`declare module '${p}' { interface FunctionOutputMap extends DatabaseFunctionOutputMap {} }`,"export type DatabaseMutationFunctionMap = {",...r.filter(s=>s.functionType===5).map(s=>` ${JSON.stringify(s.functionId)}: true;`),"};",`declare module '${p}' { interface MutationFunctionMap extends DatabaseMutationFunctionMap {} }`,""),e.join(`
|
|
9
|
+
`)}async function N(n,t,i="../lib/database-function-inputs.generated"){let r=["/* Generated by base-database-cli. Runtime validation remains authoritative. */",`import { invokeDatabaseFunction } from '${p}';`,`import type { DatabaseFunctionOptions } from '${p}';`,"import { SDKError } from '@lark-base-open/base-database-app-sdk/shared';",`import type { DatabaseFunctionInputMap as GeneratedFunctionInputs } from ${JSON.stringify(i)};`,`import type { DatabaseFunctionOutputMap as GeneratedFunctionOutputs } from ${JSON.stringify(i)};`,`export const contract = ${JSON.stringify({version:1,schemaHash:t,remoteContractMatch:"unknown"})} as const;`],e=[];for(let[o,s]of[...n].sort((u,a)=>u.functionId.localeCompare(a.functionId)).entries()){let u=`Function${o}Input`,a=`Function${o}Output`;r.push(`export type ${u} = GeneratedFunctionInputs[${JSON.stringify(s.functionId)}];`),r.push(`export type ${a} = GeneratedFunctionOutputs[${JSON.stringify(s.functionId)}];`),e.push(` [${JSON.stringify(s.functionId)}]: async (input: ${u}, options?: DatabaseFunctionOptions): Promise<${a}> => {
|
|
10
|
+
const response = await invokeDatabaseFunction(${JSON.stringify(s.functionId)}, input, options);
|
|
11
11
|
if (!response || !Number.isSafeInteger(response.code)) throw new SDKError('FUNCTION_RESPONSE_INVALID', 'Invalid Function response', {outcome:'unknown'});
|
|
12
12
|
if (response.code !== 0) throw new SDKError('FUNCTION_INVOKE_FAILED', 'Function invocation failed', String(response.code));
|
|
13
13
|
return response.data as ${a};
|
|
14
|
-
},`)}return r.push(`declare module '${
|
|
15
|
-
`)}function j(n,t){let i=structuredClone(n);return
|
|
16
|
-
`)}var U=[1],m=class extends Error{constructor(i,r){super(r);this.code=i;this.name="CodegenError"}toJSON(){return{code:this.code,message:this.message}}},k=b.replace("./database-function-inputs.generated","../generated/function-inputs"),I=n=>!!n&&typeof n=="object"&&!Array.isArray(n);function S(n){if(!I(n)||n.contractFormatVersion!==1)throw new m("CONTRACT_FORMAT_UNSUPPORTED","Supported contractFormatVersion: 1");let t=()=>{throw new m("CONTRACT_DATA_INVALID","Invalid contract format 1 data")};(!["workspace","classic"].includes(String(n.layout))||typeof n.schemaHash!="string"||typeof n.client!="boolean"||!["none","compat","client"].includes(String(n.augmentation))||n.previousAugmentation!==void 0&&typeof n.previousAugmentation!="string")&&t();let i;try{i=JSON.stringify(n)}catch{return t()}Buffer.byteLength(i)>4*1024*1024&&t();for(let o of["functions","inputs"]){let s=n[o];if(!Array.isArray(s)||s.length>1e3)return t();let u=new Set;for(let a of s){if(!I(a)||typeof a.functionId!="string"||!/^[A-Za-z0-9_-]{1,64}$/.test(a.functionId)||u.has(a.functionId))return t();u.add(a.functionId),o==="functions"&&(typeof a.functionType!="number"||![1,2,5].includes(a.functionType))&&t(),o==="inputs"&&!I(a.inputSchema)&&t(),o==="inputs"&&a.functionType!==void 0&&(typeof a.functionType!="number"||![1,2,5].includes(a.functionType))&&t();for(let c of o==="inputs"?["inputSchema"]:["input","output"])if(a[c]!==void 0)try{l(a[c])}catch{t()}a.parameterOptions!==void 0&&(!I(a.parameterOptions)||!Object.values(a.parameterOptions).every(Array.isArray))&&t()}}let r=new Set(n.inputs.map(o=>o.functionId));n.functions.some(o=>!r.has(o.functionId))&&t();let e=new Map(n.functions.map(o=>[o.functionId,o.functionType]));n.inputs.some(o=>o.functionType!==void 0&&e.has(o.functionId)&&e.get(o.functionId)!==o.functionType)&&t()}async function L(n){if(S(n),n.previousAugmentation!==void 0&&![b,O,k].includes(n.previousAugmentation))throw new m("CONTRACT_INPUT_MAP_CONFLICT","Unrecognized FunctionInputMap augmentation; review before replacing");let t=[{path:n.layout==="workspace"?"page/src/generated/function-inputs.ts":"page/src/lib/database-function-inputs.generated.ts",content:`${await
|
|
17
|
-
${F(n.inputs)}`}];return n.client&&t.push({path:"page/src/generated/functions.ts",content:await
|
|
14
|
+
},`)}return r.push(`declare module '${p}' { interface FunctionInputMap extends GeneratedFunctionInputs {} }`,"export const functions = {",...e,"};",""),r.join(`
|
|
15
|
+
`)}function j(n,t){let i=structuredClone(n);return f(i,r=>{Array.isArray(r.prefixItems)&&(r.additionalItems=r.items??r.maxItems!==r.prefixItems.length,r.items=r.prefixItems,delete r.prefixItems)}),i.title=t,i}function d(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function w(n){return n===null?"null":typeof n=="string"||typeof n=="boolean"?JSON.stringify(n):typeof n=="number"&&Number.isFinite(n)?Object.is(n,-0)?"-0":String(n):Array.isArray(n)?`[${n.map(w).join(", ")}]`:d(n)?`{ ${Object.entries(n).map(([t,i])=>`${JSON.stringify(t)}: ${w(i)}`).join("; ")} }`:"never"}function P(n,t){switch(t){case"string":return typeof n=="string";case"integer":return typeof n=="number"&&Number.isInteger(n);case"number":return typeof n=="number"&&Number.isFinite(n);case"boolean":return typeof n=="boolean";case"null":return n===null;case"array":return Array.isArray(n);case"object":return d(n);default:return!1}}function G(n){return typeof n.type=="string"?[n.type]:Array.isArray(n.type)?n.type.filter(t=>typeof t=="string"):[]}function J(n,t){switch(t){case"string":return"string";case"integer":case"number":return"number";case"boolean":return"boolean";case"null":return"null";case"array":{let i=n.prefixItems,r=Array.isArray(i),e=r?i.filter(d):[];if(r&&n.minItems===e.length&&n.maxItems===e.length)return`[${e.map(y).join(", ")}]`;let o=d(n.items)?y(n.items):"unknown";return e.length===0?`Array<${o}>`:`[${[...e.map(u=>`${y(u)}?`),`...Array<${o}>`].join(", ")}]`}case"object":{let i=d(n.properties)?n.properties:{},r=new Set(Array.isArray(n.required)?n.required.filter(c=>typeof c=="string"):[]),e=Object.entries(i).filter(c=>d(c[1])),o=new Set(e.map(([c])=>c)),s=[...r].filter(c=>!o.has(c));if(s.length>0&&n.additionalProperties===!1)return"never";let u=e.map(([c,g])=>`${JSON.stringify(c)}${r.has(c)?"":"?"}: ${y(g)}`);u.push(...s.map(c=>`${JSON.stringify(c)}: unknown`));let a=`{ ${u.join("; ")} }`;return n.additionalProperties===!1?u.length===0?"Record<string, never>":a:`${a} & Record<string, unknown>`}default:return"unknown"}}function y(n){let t=["anyOf","oneOf","allOf"].filter(e=>Array.isArray(n[e]));if(t.length){let e={...n};for(let u of t)delete e[u];let o=t.map(u=>{let a=n[u].filter(d).map(y);return a.length?a.map(c=>`(${c})`).join(u==="allOf"?" & ":" | "):"never"}),s=y(e);return s!=="unknown"&&o.unshift(s),o.map(u=>`(${u})`).join(" & ")}if(Object.hasOwn(n,"const"))return w(n.const);let i=G(n);if(Array.isArray(n.enum)&&n.enum.length>0){let e=n.enum.filter(o=>i.length===0||i.some(s=>P(o,s)));return e.length===0?"never":e.map(w).join(" | ")}let r=[...new Set(i.map(e=>J(n,e)))];return r.length===0?"unknown":r.join(" | ")}function F(n){let t=[...n].sort((e,o)=>e.functionId<o.functionId?-1:e.functionId>o.functionId?1:0),i=t.map(e=>` ${JSON.stringify(e.functionId)}: ${y(e.inputSchema)}`),r=t.flatMap(e=>{let o=Object.entries(e.parameterOptions??{});return o.length===0?[]:[` ${JSON.stringify(e.functionId)}: {`,...o.map(([s,u])=>` ${JSON.stringify(s)}: ${JSON.stringify(u)},`)," },"]});return["/* Generated by base-database-cli from Function metadata. Do not edit. */","// prettier-ignore","export type DatabaseFunctionInputMap = {",...i,"}",...r.length?["","/** Fixed options declared as enum, keyed by Function ID and parameter name; the Agent-facing schema uses the same values. */","// prettier-ignore","export const DatabaseFunctionParameterOptions = {",...r,"} as const"]:[],""].join(`
|
|
16
|
+
`)}var U=[1],m=class extends Error{constructor(i,r){super(r);this.code=i;this.name="CodegenError"}toJSON(){return{code:this.code,message:this.message}}},k=b.replace("./database-function-inputs.generated","../generated/function-inputs"),I=n=>!!n&&typeof n=="object"&&!Array.isArray(n);function S(n){if(!I(n)||n.contractFormatVersion!==1)throw new m("CONTRACT_FORMAT_UNSUPPORTED","Supported contractFormatVersion: 1");let t=()=>{throw new m("CONTRACT_DATA_INVALID","Invalid contract format 1 data")};(!["workspace","classic"].includes(String(n.layout))||typeof n.schemaHash!="string"||typeof n.client!="boolean"||!["none","compat","client"].includes(String(n.augmentation))||n.previousAugmentation!==void 0&&typeof n.previousAugmentation!="string")&&t();let i;try{i=JSON.stringify(n)}catch{return t()}Buffer.byteLength(i)>4*1024*1024&&t();for(let o of["functions","inputs"]){let s=n[o];if(!Array.isArray(s)||s.length>1e3)return t();let u=new Set;for(let a of s){if(!I(a)||typeof a.functionId!="string"||!/^[A-Za-z0-9_-]{1,64}$/.test(a.functionId)||u.has(a.functionId))return t();u.add(a.functionId),o==="functions"&&(typeof a.functionType!="number"||![1,2,5].includes(a.functionType))&&t(),o==="inputs"&&!I(a.inputSchema)&&t(),o==="inputs"&&a.functionType!==void 0&&(typeof a.functionType!="number"||![1,2,5].includes(a.functionType))&&t();for(let c of o==="inputs"?["inputSchema"]:["input","output"])if(a[c]!==void 0)try{l(a[c])}catch{t()}a.parameterOptions!==void 0&&(!I(a.parameterOptions)||!Object.values(a.parameterOptions).every(Array.isArray))&&t()}}let r=new Set(n.inputs.map(o=>o.functionId));n.functions.some(o=>!r.has(o.functionId))&&t();let e=new Map(n.functions.map(o=>[o.functionId,o.functionType]));n.inputs.some(o=>o.functionType!==void 0&&e.has(o.functionId)&&e.get(o.functionId)!==o.functionType)&&t()}async function L(n){if(S(n),n.previousAugmentation!==void 0&&![b,O,k].includes(n.previousAugmentation))throw new m("CONTRACT_INPUT_MAP_CONFLICT","Unrecognized FunctionInputMap augmentation; review before replacing");let t=[{path:n.layout==="workspace"?"page/src/generated/function-inputs.ts":"page/src/lib/database-function-inputs.generated.ts",content:`${await $(n.functions,n.inputs)}
|
|
17
|
+
${F(n.inputs)}`}];return n.client&&t.push({path:"page/src/generated/functions.ts",content:await N(n.functions,n.schemaHash,n.layout==="workspace"?"./function-inputs":"../lib/database-function-inputs.generated")}),n.augmentation!=="none"&&t.push({path:"page/src/lib/function-input-map.generated.ts",content:n.augmentation==="compat"?n.layout==="workspace"?k:b:O}),t}0&&(module.exports={CodegenError,SUPPORTED_CONTRACT_FORMAT_VERSIONS,generateFunctionClients,validateContractData});
|
package/dist/codegen.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import{compile as F}from"json-schema-to-typescript";function
|
|
1
|
+
import{compile as F}from"json-schema-to-typescript";function f(n,e){if(!n||typeof n!="object"||Array.isArray(n))return;let i=n;e(i);for(let t of["properties","patternProperties","$defs","definitions","dependentSchemas"]){let o=i[t];if(o&&typeof o=="object"&&!Array.isArray(o))for(let s of Object.values(o))f(s,e)}for(let t of["items","additionalItems","additionalProperties","unevaluatedProperties","unevaluatedItems","contains","propertyNames","not","if","then","else"]){let o=i[t];Array.isArray(o)?o.forEach(s=>f(s,e)):f(o,e)}for(let t of["allOf","anyOf","oneOf","prefixItems"])Array.isArray(i[t])&&i[t].forEach(o=>f(o,e));let r=i.dependencies;if(r&&typeof r=="object"&&!Array.isArray(r))for(let t of Object.values(r))Array.isArray(t)||f(t,e)}function l(n){if(!n||typeof n!="object"||Array.isArray(n)||Buffer.byteLength(JSON.stringify(n))>32768)throw new Error("CONTRACT_SCHEMA_BUDGET");let e=0,i=(r,t)=>{if(!(!r||typeof r!="object")){if(++e>256||t>16)throw new Error("CONTRACT_SCHEMA_BUDGET");Object.values(r).forEach(o=>i(o,t+1))}};i(n,0),f(n,r=>{if(Object.hasOwn(r,"$ref")&&(typeof r.$ref!="string"||!r.$ref.startsWith("#/")))throw new Error("CONTRACT_EXTERNAL_REF");if(["$id","$dynamicRef","$recursiveRef","tsType","tsEnumNames"].some(t=>Object.hasOwn(r,t)))throw new Error("CONTRACT_EXTERNAL_REF")})}var p="@lark-base-open/base-database-app-sdk/page",b=`/* Generated by base-database-cli. Do not edit. */
|
|
2
2
|
import type { DatabaseFunctionInputMap as GeneratedInputMap } from './database-function-inputs.generated';
|
|
3
|
-
import '${
|
|
4
|
-
declare module '${
|
|
3
|
+
import '${p}';
|
|
4
|
+
declare module '${p}' { interface FunctionInputMap extends GeneratedInputMap {} }
|
|
5
5
|
`,A=`/* Generated by base-database-cli. Map is declared in ../generated/functions. */
|
|
6
6
|
export {};
|
|
7
7
|
`;async function O(n,e){l(n);try{return await F(S(n,e),e,{bannerComment:"",customName:(i,r)=>i.title===e?e:i.title||r?`${e}_${i.title||r}`:void 0,unknownAny:!0,additionalProperties:!0,$refOptions:{resolve:{http:!1,file:!1}}})}catch{return`// Schema could not be represented; no precision is claimed.
|
|
8
|
-
export type ${e} = unknown;`}}function k(n){if(!n||n.type!=="object")return;let e=n.properties;if(!e||typeof e!="object"||Array.isArray(e))return;let i=e.rows;if(!i||typeof i!="object"||Array.isArray(i))return;let r=i,t=r.items;return r.type==="array"&&t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}async function h(n,e){let i=new Map(n.map(s=>[s.functionId,s]));for(let s of e)!i.has(s.functionId)&&s.functionType!==void 0&&i.set(s.functionId,{functionId:s.functionId,functionType:s.functionType});let r=[...i.values()],t=["/* Generated by base-database-cli from Function metadata. Do not edit. */",...r.some(s=>s.functionType===1)?[`import type { DatabaseQueryResult } from '${
|
|
9
|
-
`)}async function T(n,e,i="../lib/database-function-inputs.generated"){let r=["/* Generated by base-database-cli. Runtime validation remains authoritative. */",`import { invokeDatabaseFunction } from '${
|
|
10
|
-
const response = await invokeDatabaseFunction(${JSON.stringify(s.functionId)}, input);
|
|
8
|
+
export type ${e} = unknown;`}}function k(n){if(!n||n.type!=="object")return;let e=n.properties;if(!e||typeof e!="object"||Array.isArray(e))return;let i=e.rows;if(!i||typeof i!="object"||Array.isArray(i))return;let r=i,t=r.items;return r.type==="array"&&t&&typeof t=="object"&&!Array.isArray(t)?t:void 0}async function h(n,e){let i=new Map(n.map(s=>[s.functionId,s]));for(let s of e)!i.has(s.functionId)&&s.functionType!==void 0&&i.set(s.functionId,{functionId:s.functionId,functionType:s.functionType});let r=[...i.values()],t=["/* Generated by base-database-cli from Function metadata. Do not edit. */",...r.some(s=>s.functionType===1)?[`import type { DatabaseQueryResult } from '${p}';`]:[],...r.some(s=>s.functionType===5&&!s.output)?[`import type { DatabaseMutationResult } from '${p}';`]:[]],o=[];for(let[s,u]of r.sort((a,c)=>a.functionId.localeCompare(c.functionId)).entries()){let a=`Function${s}Output`;if(u.functionType===1){let c=k(u.output);if(c){let g=`Function${s}Row`;t.push(await O(c,g)),t.push(`export type ${a} = DatabaseQueryResult<${g}>;`)}else t.push(`export type ${a} = DatabaseQueryResult<unknown>;`)}else u.functionType===5&&!u.output?t.push(`export type ${a} = DatabaseMutationResult;`):u.output?t.push(await O(u.output,a)):t.push(`export type ${a} = unknown;`);o.push(` ${JSON.stringify(u.functionId)}: ${a};`)}return t.push("export type DatabaseFunctionOutputMap = {",...o,"};",`declare module '${p}' { interface FunctionOutputMap extends DatabaseFunctionOutputMap {} }`,"export type DatabaseMutationFunctionMap = {",...r.filter(s=>s.functionType===5).map(s=>` ${JSON.stringify(s.functionId)}: true;`),"};",`declare module '${p}' { interface MutationFunctionMap extends DatabaseMutationFunctionMap {} }`,""),t.join(`
|
|
9
|
+
`)}async function T(n,e,i="../lib/database-function-inputs.generated"){let r=["/* Generated by base-database-cli. Runtime validation remains authoritative. */",`import { invokeDatabaseFunction } from '${p}';`,`import type { DatabaseFunctionOptions } from '${p}';`,"import { SDKError } from '@lark-base-open/base-database-app-sdk/shared';",`import type { DatabaseFunctionInputMap as GeneratedFunctionInputs } from ${JSON.stringify(i)};`,`import type { DatabaseFunctionOutputMap as GeneratedFunctionOutputs } from ${JSON.stringify(i)};`,`export const contract = ${JSON.stringify({version:1,schemaHash:e,remoteContractMatch:"unknown"})} as const;`],t=[];for(let[o,s]of[...n].sort((u,a)=>u.functionId.localeCompare(a.functionId)).entries()){let u=`Function${o}Input`,a=`Function${o}Output`;r.push(`export type ${u} = GeneratedFunctionInputs[${JSON.stringify(s.functionId)}];`),r.push(`export type ${a} = GeneratedFunctionOutputs[${JSON.stringify(s.functionId)}];`),t.push(` [${JSON.stringify(s.functionId)}]: async (input: ${u}, options?: DatabaseFunctionOptions): Promise<${a}> => {
|
|
10
|
+
const response = await invokeDatabaseFunction(${JSON.stringify(s.functionId)}, input, options);
|
|
11
11
|
if (!response || !Number.isSafeInteger(response.code)) throw new SDKError('FUNCTION_RESPONSE_INVALID', 'Invalid Function response', {outcome:'unknown'});
|
|
12
12
|
if (response.code !== 0) throw new SDKError('FUNCTION_INVOKE_FAILED', 'Function invocation failed', String(response.code));
|
|
13
13
|
return response.data as ${a};
|
|
14
|
-
},`)}return r.push(`declare module '${
|
|
15
|
-
`)}function S(n,e){let i=structuredClone(n);return
|
|
16
|
-
`)}var L=[1],m=class extends Error{constructor(i,r){super(r);this.code=i;this.name="CodegenError"}toJSON(){return{code:this.code,message:this.message}}}
|
|
17
|
-
${
|
|
14
|
+
},`)}return r.push(`declare module '${p}' { interface FunctionInputMap extends GeneratedFunctionInputs {} }`,"export const functions = {",...t,"};",""),r.join(`
|
|
15
|
+
`)}function S(n,e){let i=structuredClone(n);return f(i,r=>{Array.isArray(r.prefixItems)&&(r.additionalItems=r.items??r.maxItems!==r.prefixItems.length,r.items=r.prefixItems,delete r.prefixItems)}),i.title=e,i}function d(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function w(n){return n===null?"null":typeof n=="string"||typeof n=="boolean"?JSON.stringify(n):typeof n=="number"&&Number.isFinite(n)?Object.is(n,-0)?"-0":String(n):Array.isArray(n)?`[${n.map(w).join(", ")}]`:d(n)?`{ ${Object.entries(n).map(([e,i])=>`${JSON.stringify(e)}: ${w(i)}`).join("; ")} }`:"never"}function C(n,e){switch(e){case"string":return typeof n=="string";case"integer":return typeof n=="number"&&Number.isInteger(n);case"number":return typeof n=="number"&&Number.isFinite(n);case"boolean":return typeof n=="boolean";case"null":return n===null;case"array":return Array.isArray(n);case"object":return d(n);default:return!1}}function R(n){return typeof n.type=="string"?[n.type]:Array.isArray(n.type)?n.type.filter(e=>typeof e=="string"):[]}function x(n,e){switch(e){case"string":return"string";case"integer":case"number":return"number";case"boolean":return"boolean";case"null":return"null";case"array":{let i=n.prefixItems,r=Array.isArray(i),t=r?i.filter(d):[];if(r&&n.minItems===t.length&&n.maxItems===t.length)return`[${t.map(y).join(", ")}]`;let o=d(n.items)?y(n.items):"unknown";return t.length===0?`Array<${o}>`:`[${[...t.map(u=>`${y(u)}?`),`...Array<${o}>`].join(", ")}]`}case"object":{let i=d(n.properties)?n.properties:{},r=new Set(Array.isArray(n.required)?n.required.filter(c=>typeof c=="string"):[]),t=Object.entries(i).filter(c=>d(c[1])),o=new Set(t.map(([c])=>c)),s=[...r].filter(c=>!o.has(c));if(s.length>0&&n.additionalProperties===!1)return"never";let u=t.map(([c,g])=>`${JSON.stringify(c)}${r.has(c)?"":"?"}: ${y(g)}`);u.push(...s.map(c=>`${JSON.stringify(c)}: unknown`));let a=`{ ${u.join("; ")} }`;return n.additionalProperties===!1?u.length===0?"Record<string, never>":a:`${a} & Record<string, unknown>`}default:return"unknown"}}function y(n){let e=["anyOf","oneOf","allOf"].filter(t=>Array.isArray(n[t]));if(e.length){let t={...n};for(let u of e)delete t[u];let o=e.map(u=>{let a=n[u].filter(d).map(y);return a.length?a.map(c=>`(${c})`).join(u==="allOf"?" & ":" | "):"never"}),s=y(t);return s!=="unknown"&&o.unshift(s),o.map(u=>`(${u})`).join(" & ")}if(Object.hasOwn(n,"const"))return w(n.const);let i=R(n);if(Array.isArray(n.enum)&&n.enum.length>0){let t=n.enum.filter(o=>i.length===0||i.some(s=>C(o,s)));return t.length===0?"never":t.map(w).join(" | ")}let r=[...new Set(i.map(t=>x(n,t)))];return r.length===0?"unknown":r.join(" | ")}function $(n){let e=[...n].sort((t,o)=>t.functionId<o.functionId?-1:t.functionId>o.functionId?1:0),i=e.map(t=>` ${JSON.stringify(t.functionId)}: ${y(t.inputSchema)}`),r=e.flatMap(t=>{let o=Object.entries(t.parameterOptions??{});return o.length===0?[]:[` ${JSON.stringify(t.functionId)}: {`,...o.map(([s,u])=>` ${JSON.stringify(s)}: ${JSON.stringify(u)},`)," },"]});return["/* Generated by base-database-cli from Function metadata. Do not edit. */","// prettier-ignore","export type DatabaseFunctionInputMap = {",...i,"}",...r.length?["","/** Fixed options declared as enum, keyed by Function ID and parameter name; the Agent-facing schema uses the same values. */","// prettier-ignore","export const DatabaseFunctionParameterOptions = {",...r,"} as const"]:[],""].join(`
|
|
16
|
+
`)}var L=[1],m=class extends Error{constructor(i,r){super(r);this.code=i;this.name="CodegenError"}toJSON(){return{code:this.code,message:this.message}}},N=b.replace("./database-function-inputs.generated","../generated/function-inputs"),I=n=>!!n&&typeof n=="object"&&!Array.isArray(n);function D(n){if(!I(n)||n.contractFormatVersion!==1)throw new m("CONTRACT_FORMAT_UNSUPPORTED","Supported contractFormatVersion: 1");let e=()=>{throw new m("CONTRACT_DATA_INVALID","Invalid contract format 1 data")};(!["workspace","classic"].includes(String(n.layout))||typeof n.schemaHash!="string"||typeof n.client!="boolean"||!["none","compat","client"].includes(String(n.augmentation))||n.previousAugmentation!==void 0&&typeof n.previousAugmentation!="string")&&e();let i;try{i=JSON.stringify(n)}catch{return e()}Buffer.byteLength(i)>4*1024*1024&&e();for(let o of["functions","inputs"]){let s=n[o];if(!Array.isArray(s)||s.length>1e3)return e();let u=new Set;for(let a of s){if(!I(a)||typeof a.functionId!="string"||!/^[A-Za-z0-9_-]{1,64}$/.test(a.functionId)||u.has(a.functionId))return e();u.add(a.functionId),o==="functions"&&(typeof a.functionType!="number"||![1,2,5].includes(a.functionType))&&e(),o==="inputs"&&!I(a.inputSchema)&&e(),o==="inputs"&&a.functionType!==void 0&&(typeof a.functionType!="number"||![1,2,5].includes(a.functionType))&&e();for(let c of o==="inputs"?["inputSchema"]:["input","output"])if(a[c]!==void 0)try{l(a[c])}catch{e()}a.parameterOptions!==void 0&&(!I(a.parameterOptions)||!Object.values(a.parameterOptions).every(Array.isArray))&&e()}}let r=new Set(n.inputs.map(o=>o.functionId));n.functions.some(o=>!r.has(o.functionId))&&e();let t=new Map(n.functions.map(o=>[o.functionId,o.functionType]));n.inputs.some(o=>o.functionType!==void 0&&t.has(o.functionId)&&t.get(o.functionId)!==o.functionType)&&e()}async function V(n){if(D(n),n.previousAugmentation!==void 0&&![b,A,N].includes(n.previousAugmentation))throw new m("CONTRACT_INPUT_MAP_CONFLICT","Unrecognized FunctionInputMap augmentation; review before replacing");let e=[{path:n.layout==="workspace"?"page/src/generated/function-inputs.ts":"page/src/lib/database-function-inputs.generated.ts",content:`${await h(n.functions,n.inputs)}
|
|
17
|
+
${$(n.inputs)}`}];return n.client&&e.push({path:"page/src/generated/functions.ts",content:await T(n.functions,n.schemaHash,n.layout==="workspace"?"./function-inputs":"../lib/database-function-inputs.generated")}),n.augmentation!=="none"&&e.push({path:"page/src/lib/function-input-map.generated.ts",content:n.augmentation==="compat"?n.layout==="workspace"?N:b:A}),e}export{m as CodegenError,L as SUPPORTED_CONTRACT_FORMAT_VERSIONS,V as generateFunctionClients,D as validateContractData};
|
package/dist/components.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { a3 as AttachmentImage, W as BaseAppContextValue, X as BaseAppProvider, a0 as DatabaseAudience, a2 as DatabaseUserMenu, a1 as DatabaseUserMenuProps, $ as FloatingButton, _ as FloatingButtonProps, U as UiLanguage, a4 as UiLanguageContext, L as User, P as UserSelectorAction, R as UserSelectorEditor, T as UserSelectorEditorProps, V as UserSelectorEditorValue, O as UserSelectorMode, J as UserSelectorPanel, K as UserSelectorPanelProps, Q as UserSelectorSearchAction, N as UserSelectorValue, a6 as getUiLanguage, a7 as getUiLocale, a8 as initializeUiLanguage, a5 as selectUiLanguage, Y as useBaseApp, Z as useOptionalBaseApp, a9 as useUiLanguage } from './index-99514181.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
import '@lark-base-open/base-site-channel/runtime';
|
|
4
|
-
import './capabilities-
|
|
4
|
+
import './capabilities-83939715.js';
|
|
5
5
|
import './shared.js';
|
|
6
6
|
import '@lark-base-open/base-site-channel/capabilities';
|
package/dist/components.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{M as a,N as b,O as c,P as d,Q as e,R as f,S as g,T as h,U as i,W as j,X as k,Y as l,Z as m,_ as n}from"./chunk-5U3PWPXP.js";import"./chunk-ZKBZAK4L.js";import"./chunk-3JX3FIBG.js";import"./chunk-OHPYKFCM.js";export{n as AttachmentImage,g as BaseAppProvider,k as DatabaseUserMenu,j as FloatingButton,a as UiLanguageContext,m as UserSelectorEditor,l as UserSelectorPanel,c as getUiLanguage,d as getUiLocale,e as initializeUiLanguage,b as selectUiLanguage,h as useBaseApp,i as useOptionalBaseApp,f as useUiLanguage};
|
|
@@ -2,8 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import React__default, { KeyboardEventHandler, MouseEventHandler, FocusEventHandler, ComponentType } from 'react';
|
|
3
3
|
import * as channelRuntime from '@lark-base-open/base-site-channel/runtime';
|
|
4
4
|
import { FunctionMap, RuntimeChannel, SiteProjectEnv } from '@lark-base-open/base-site-channel/runtime';
|
|
5
|
-
import { S as SiteRuntimeContext } from './capabilities-
|
|
6
|
-
import { RuntimeDiagnostic } from './shared.js';
|
|
5
|
+
import { S as SiteRuntimeContext } from './capabilities-83939715.js';
|
|
6
|
+
import { SDKError, RuntimeDiagnostic } from './shared.js';
|
|
7
7
|
|
|
8
8
|
declare class SiteRuntimeClient<Map = FunctionMap> extends channelRuntime.SiteRuntimeClient<Map> {
|
|
9
9
|
constructor(channel?: RuntimeChannel);
|
|
@@ -119,6 +119,28 @@ declare function buildDatabaseInvokeGetPath(context: DatabaseContext): string;
|
|
|
119
119
|
* @throws functionId 不满足命名约束时抛出 TypeError。
|
|
120
120
|
*/
|
|
121
121
|
declare function buildDatabaseInvokeFunctionPath(context: DatabaseContext, functionId: string): string;
|
|
122
|
+
type DatabaseFunctionInvocation<Inputs extends object> = [
|
|
123
|
+
Extract<keyof Inputs, string>
|
|
124
|
+
] extends [never] ? [functionId: never, params: never, options?: DatabaseFunctionOptions] : {
|
|
125
|
+
[FunctionId in Extract<keyof Inputs, string>]: [
|
|
126
|
+
functionId: FunctionId,
|
|
127
|
+
params: Inputs[FunctionId],
|
|
128
|
+
options?: DatabaseFunctionOptions
|
|
129
|
+
];
|
|
130
|
+
}[Extract<keyof Inputs, string>];
|
|
131
|
+
/** Function 调用的可选项。 */
|
|
132
|
+
interface DatabaseFunctionOptions {
|
|
133
|
+
/** 写后读,默认 true:读会等到本会话刚写入的数据可读,等不到抛 DataNotReadyError。
|
|
134
|
+
* 传 false 不等——用于轮询、统计面板等可接受旧数据且对时延敏感的读。写调用带上不改变写的行为。 */
|
|
135
|
+
readYourWrites?: boolean;
|
|
136
|
+
}
|
|
137
|
+
/** 数据尚未可读:写入已成功,不要重写,稍后重新查询即可。 */
|
|
138
|
+
declare class DataNotReadyError extends SDKError {
|
|
139
|
+
readonly logId?: string;
|
|
140
|
+
constructor(options?: {
|
|
141
|
+
logId?: string;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
122
144
|
/** 调用应用 Function。
|
|
123
145
|
*
|
|
124
146
|
* 请求经父页面同源代理发往统一网关;整个请求体即 payload,业务参数包在 params 下。
|
|
@@ -127,20 +149,14 @@ declare function buildDatabaseInvokeFunctionPath(context: DatabaseContext, funct
|
|
|
127
149
|
*
|
|
128
150
|
* @param functionId Base Database Function ID。
|
|
129
151
|
* @param params 函数入参:Database Function、Mutation 与 FaaS 使用按声明名称构造的对象。
|
|
152
|
+
* @param options 写后读默认开启(readYourWrites 默认 true):带声明头,数据未就绪时按宿主参数重试,用尽抛 DataNotReadyError;
|
|
153
|
+
* 轮询、统计面板等可接受旧数据且对时延敏感的读传 { readYourWrites: false } 不等。
|
|
130
154
|
* @returns 统一包裹的函数响应。
|
|
131
155
|
*/
|
|
132
|
-
type DatabaseFunctionInvocation<Inputs extends object> = [
|
|
133
|
-
Extract<keyof Inputs, string>
|
|
134
|
-
] extends [never] ? [functionId: never, params: never] : {
|
|
135
|
-
[FunctionId in Extract<keyof Inputs, string>]: [
|
|
136
|
-
functionId: FunctionId,
|
|
137
|
-
params: Inputs[FunctionId]
|
|
138
|
-
];
|
|
139
|
-
}[Extract<keyof Inputs, string>];
|
|
140
156
|
type FunctionId = Extract<keyof DatabaseFunctionInputMap, string>;
|
|
141
157
|
type MappedOutputId = Extract<keyof DatabaseFunctionOutputMap, FunctionId>;
|
|
142
158
|
/** 仅允许同时具有输入和输出契约的 Function;data 按 ID 推断。 */
|
|
143
|
-
declare function invokeDatabaseFunction<Id extends MappedOutputId>(functionId: Id, params: DatabaseFunctionInputMap[Id]): Promise<DatabaseFunctionResponse<DatabaseFunctionOutputMap[Id]>>;
|
|
159
|
+
declare function invokeDatabaseFunction<Id extends MappedOutputId>(functionId: Id, params: DatabaseFunctionInputMap[Id], options?: DatabaseFunctionOptions): Promise<DatabaseFunctionResponse<DatabaseFunctionOutputMap[Id]>>;
|
|
144
160
|
type MutationBatchInvocation<Id extends MutationFunctionId> = {
|
|
145
161
|
[FunctionId in Id]: [
|
|
146
162
|
functionId: FunctionId,
|
|
@@ -337,4 +353,4 @@ declare function AttachmentImage({ attachment, size, alt, className, slots, }: {
|
|
|
337
353
|
className?: string;
|
|
338
354
|
}): React.JSX.Element;
|
|
339
355
|
|
|
340
|
-
export {
|
|
356
|
+
export { FloatingButton as $, DatabaseQueryResult as A, DatabaseMutationResult as B, createSiteRuntimeClient as C, DataNotReadyError as D, createSiteRuntimeFetch as E, FunctionInputMap as F, invokeApi as G, uploadAttachment as H, openLink as I, UserSelectorPanel as J, UserSelectorPanelProps as K, User as L, MutationFunctionMap as M, UserSelectorValue as N, UserSelectorMode as O, UserSelectorAction as P, UserSelectorSearchAction as Q, UserSelectorEditor as R, SiteRuntimeClient as S, UserSelectorEditorProps as T, UiLanguage as U, UserSelectorEditorValue as V, BaseAppContextValue as W, BaseAppProvider as X, useBaseApp as Y, useOptionalBaseApp as Z, FloatingButtonProps as _, getDatabaseContext as a, DatabaseAudience as a0, DatabaseUserMenuProps as a1, DatabaseUserMenu as a2, AttachmentImage as a3, UiLanguageContext as a4, selectUiLanguage as a5, getUiLanguage as a6, getUiLocale as a7, initializeUiLanguage as a8, useUiLanguage as a9, resolveDatabaseContext as b, fetchAttachmentCover as c, buildAttachmentCoverUrl as d, fetchAttachmentDownloadUrl as e, fetch as f, getCurrentUser as g, buildDatabaseInvokeGetPath as h, invokeHttp as i, buildDatabaseInvokeFunctionPath as j, invokeDatabaseFunction as k, logout as l, invokeDatabaseMutationBatch as m, DatabaseContext as n, openAttachmentDownload as o, DatabaseAttachmentRef as p, DatabaseEnv as q, requestEdit as r, siteRuntime as s, DatabaseFunctionResponse as t, DatabaseFunctionInvocation as u, DatabaseFunctionOptions as v, DatabaseFunctionInputMap as w, DatabaseFunctionOutputMap as x, FunctionOutputMap as y, MutationFunctionId as z };
|
package/dist/page.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ export * from '@lark-base-open/base-site-channel/runtime';
|
|
|
4
4
|
export { SiteChatbotStreamError } from '@lark-base-open/base-site-channel/runtime';
|
|
5
5
|
import { RuntimeDiagnostic } from './shared.js';
|
|
6
6
|
export { CapabilityContext, CapabilityDescriptor, CapabilityMap, CapabilityName, CapabilityQueryResult, CapabilityUnavailableError, CapabilityUnavailableReason, DiagnosticCategory, DiagnosticCode, FunctionEnvelope, JsonValue, RuntimeCapabilities, SDKError, SDKErrorOptions, WriteResult, classifyRuntimeError } from './shared.js';
|
|
7
|
-
import { R as RuntimeContextReader } from './capabilities-
|
|
8
|
-
export { S as SiteRuntimeContext, g as getCapabilities, a as getRuntimeCapabilities, h as hasCapability, q as queryCapability, r as readCapabilities, b as requireCapability } from './capabilities-
|
|
7
|
+
import { R as RuntimeContextReader } from './capabilities-83939715.js';
|
|
8
|
+
export { S as SiteRuntimeContext, g as getCapabilities, a as getRuntimeCapabilities, h as hasCapability, q as queryCapability, r as readCapabilities, b as requireCapability } from './capabilities-83939715.js';
|
|
9
9
|
export * from '@lark-base-open/base-site-channel/runtime-contract';
|
|
10
10
|
export { SITE_RUNTIME_PROTOCOL_VERSION, SiteRuntimeApi, SiteRuntimeErrorCode, SiteRuntimeEvent, SiteRuntimeFunction, isValidSiteFunctionName, readSiteAITextDelta } from '@lark-base-open/base-site-channel/runtime-contract';
|
|
11
|
-
import { U as UiLanguage } from './index-
|
|
12
|
-
export {
|
|
11
|
+
import { U as UiLanguage } from './index-99514181.js';
|
|
12
|
+
export { a3 as AttachmentImage, W as BaseAppContextValue, X as BaseAppProvider, D as DataNotReadyError, p as DatabaseAttachmentRef, a0 as DatabaseAudience, n as DatabaseContext, q as DatabaseEnv, w as DatabaseFunctionInputMap, u as DatabaseFunctionInvocation, v as DatabaseFunctionOptions, x as DatabaseFunctionOutputMap, t as DatabaseFunctionResponse, B as DatabaseMutationResult, A as DatabaseQueryResult, a2 as DatabaseUserMenu, a1 as DatabaseUserMenuProps, $ as FloatingButton, _ as FloatingButtonProps, F as FunctionInputMap, y as FunctionOutputMap, z as MutationFunctionId, M as MutationFunctionMap, S as SiteRuntimeClient, a4 as UiLanguageContext, L as User, P as UserSelectorAction, R as UserSelectorEditor, T as UserSelectorEditorProps, V as UserSelectorEditorValue, O as UserSelectorMode, J as UserSelectorPanel, K as UserSelectorPanelProps, Q as UserSelectorSearchAction, N as UserSelectorValue, d as buildAttachmentCoverUrl, j as buildDatabaseInvokeFunctionPath, h as buildDatabaseInvokeGetPath, C as createSiteRuntimeClient, E as createSiteRuntimeFetch, f as fetch, c as fetchAttachmentCover, e as fetchAttachmentDownloadUrl, g as getCurrentUser, a as getDatabaseContext, a6 as getUiLanguage, a7 as getUiLocale, a8 as initializeUiLanguage, G as invokeApi, k as invokeDatabaseFunction, m as invokeDatabaseMutationBatch, i as invokeHttp, l as logout, o as openAttachmentDownload, I as openLink, r as requestEdit, b as resolveDatabaseContext, a5 as selectUiLanguage, s as siteRuntime, H as uploadAttachment, Y as useBaseApp, Z as useOptionalBaseApp, a9 as useUiLanguage } from './index-99514181.js';
|
|
13
13
|
import React__default from 'react';
|
|
14
14
|
export { CAPABILITY_CATALOG } from '@lark-base-open/base-site-channel/capabilities';
|
|
15
15
|
|
package/dist/page.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as
|
|
1
|
+
import{A as Ye,B as le,C as pe,D as fe,E as Se,F as Ae,G as ge,H as Ie,I as ke,J as ye,K as he,L as Re,M as Je,N as L,O as Xe,P as O,Q as Ze,R as $e,S as B,T as et,U as tt,V as U,W as G,X as nt,Y as it,Z as rt,_ as at,a as j,b as Y,c as J,d as X,e as Z,f as $,g as ee,h as x,i as M,j as te,k as ne,l as m,m as ie,n as re,o as ae,p as oe,q as se,r as ce,s as ue,t as de,u as me,v as Ke,w as _,x as We,y as Qe,z as je}from"./chunk-5U3PWPXP.js";import{a as Ve,b as ze,c as v,d as R}from"./chunk-ZKBZAK4L.js";import{a as He}from"./chunk-3JX3FIBG.js";import"./chunk-OHPYKFCM.js";export*from"@lark-base-open/base-site-channel/runtime";import{installLinkGuard as Fe}from"@lark-base-open/base-site-channel/runtime";function D(e={}){let t=!0,n,i=s=>{let c=R(s);e.onDiagnostic?e.onDiagnostic(c):console.warn("[Base Database SDK]",c)},a=e.runtime??m;return Promise.resolve().then(()=>a.getRuntimeContext()).then(s=>{if(t){if(!_(s,"link.open")){i(new v("link.open",1));return}n=Fe(e)}}).catch(s=>{t&&i(s)}),()=>{t=!1,n?.()}}export*from"@lark-base-open/base-site-channel/runtime-contract";import{SiteChatbotStreamError as Lt}from"@lark-base-open/base-site-channel/runtime";import*as u from"@lark-base-open/base-site-channel/runtime";var P=class extends u.SiteChatbotStreamAdapter{constructor(t){super({...t,channel:t.channel?x(t.channel):M})}},F=e=>({...e,channel:e?.channel?x(e.channel):M}),N=(e,t)=>u.callSiteAIFunction(e,F(t)),q=(e,t)=>u.invokeSiteAIFunctionStream(e,F(t)),H=(e,t)=>u.createSiteAIFunctionTask(e,F(t)),V=(e,t,n)=>u.getSiteAIFunctionTask(e,t,F(n));var Te=new Set(["cancelled","failed","queued","running","succeeded"]);async function be(e){let t=await N(e);return e.input&&!e.messages?k(t):t}function Ce(e){return q(e)}function o(e,t){for(let n of t){let i=e[n];if(typeof i=="string"&&i.trim())return i}}function xe(e,t){for(let n of t){let i=e[n];if(typeof i=="number"&&Number.isFinite(i))return i}}function Me(e){let t=o(e,["capabilityType","capability_type","CapabilityType"]);return t==="image"||t==="video"?t:void 0}function De(e){if(Array.isArray(e))return e.filter(b).map(t=>{let n=o(t,["size","Size"]),i=o(t,["token","Token"]),a=o(t,["url","URL"]);return{safetyStatus:o(t,["safetyStatus","safety_status","SafetyStatus"])??"",...n?{size:n}:{},...i?{token:i}:{},...a?{url:a}:{}}})}function Pe(e){if(!b(e))return;let t=e.durationSeconds??e.duration_seconds??e.DurationSeconds,n=o(e,["token","Token"]),i=o(e,["url","URL"]);return{...typeof t=="number"?{durationSeconds:t}:{},...n?{token:n}:{},...i?{url:i}:{}}}function T(e,t="INVALID_AI_FUNCTION_TASK"){let n=new Error(e);return n.name="SiteAIFunctionTaskError",n.code=t,n}function k(e){if(!b(e))throw T("AI Function task response has an invalid structure");let t=Ee(e);if(t)throw T(t.message,t.code);if("data"in e&&e.data!==void 0)return k(e.data);let n=o(e,["type","Type"]),i=o(e,["taskId","task_id","TaskID"]),a=e.status??e.Status;if(n!=="image_task"&&n!=="video_task"||!i||typeof a!="string"||!Te.has(a))throw T("AI Function task response has an invalid structure");let s=De(e.imageAssets??e.image_assets??e.ImageAssets),c=Pe(e.videoAsset??e.video_asset??e.VideoAsset),l=xe(e,["progress","Progress"]),I=Me(e),p=o(e,["errCode","err_code","ErrCode"]),f=o(e,["errMessage","err_message","ErrMessage"]);return{...I?{capabilityType:I}:{},...p?{errCode:p}:{},...f?{errMessage:f}:{},...s?{imageAssets:s}:{},...l!==void 0?{progress:l}:{},...c?{videoAsset:c}:{},requestId:o(e,["requestId","request_id","RequestID"])??"",status:a,taskId:i,type:n}}function Ee(e){let t=e.code??e.Code;if(typeof t=="number"&&t!==0||typeof t=="string"&&t&&t!=="0")return{code:String(t),message:o(e,["msg","message","Message"])??"Failed to create the AI Function task"};let n=e.BaseResp??e.base_resp??e.baseResp;if(!b(n))return;let i=n.StatusCode??n.status_code??n.statusCode;if(typeof i=="number"&&i!==0||typeof i=="string"&&i&&i!=="0")return{code:String(i),message:o(n,["StatusMessage","status_message","statusMessage"])??"Failed to create the AI Function task"}}function we(e){return!!e.taskId.trim()&&(e.status==="queued"||e.status==="running")}async function ve(e){return k(await H(e))}async function _e(e,t){if(!t.trim())throw T("AI Function task ID must not be empty");return k(await V(e,t))}function b(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}import{Component as Le,StrictMode as Oe,useEffect as Be,useState as Ue}from"react";import{createRoot as Ge}from"react-dom/client";import{Fragment as Ne,jsx as d,jsxs as qe}from"react/jsx-runtime";var E=new WeakSet,C=class extends Le{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(t){this.props.failed(t)}render(){let t=this.props.fallback;return this.state.failed?t?d(t,{code:"APP_BOOT_FAILED"}):d("div",{role:"alert",children:"APP_BOOT_FAILED"}):this.props.children}};function bt(e){let t,n,i=new Promise((r,g)=>{t=r,n=g});i.catch(()=>{});let a=!1,s=!1,c=!1,l,I=()=>{},p=()=>{},f=r=>{try{e.onDiagnostic?.(R(r))}catch{}},S=r=>{f(r),!(a||s||c)&&(c=!0,n(r),e.reportLifecycle!==!1&&m.reportLoadFailed("APP_BOOT_FAILED").catch(f))},A;try{A=typeof e.root=="string"?document.querySelector(e.root):e.root??document.querySelector("#root")}catch(r){return S(r),{ready:i,dispose(){a=!0}}}if(!A)return S(new Error("APP_ROOT_NOT_FOUND")),{ready:i,dispose(){a=!0}};if(E.has(A))throw new Error("APP_ALREADY_STARTED");E.add(A);let z=()=>{a||(a=!0,I(),p(),l?.unmount(),E.delete(A),U.clear(),!s&&!c&&n(new Error("APP_DISPOSED")))},K=()=>{queueMicrotask(()=>{a||c||s||(s=!0,e.reportLifecycle===!1?t():m.ready().then(t,r=>{f(r),n(r)}))})};function W({locale:r,theme:g}){let[y,h]=Ue();Be(()=>(p=m.subscribeModeChanged(h),K(),()=>p()),[]);let Q=e.app,w=qe(Ne,{children:[d(Q,{}),e.platformUI===!1?null:d(G,{})]});return d(B,{runtime:m,theme:g,locale:r,mode:y,onDiagnostic:e.onDiagnostic,children:e.providers?e.providers(w):w})}try{l=Ge(A);let r=e.slots?.loading;r&&l.render(d(C,{failed:S,fallback:e.slots?.error,children:d(r,{})})),m.getRuntimeContext().then(g=>{if(a||c)return;let y=e.locale&&e.locale!=="host"?e.locale:L(g.locale,"en");document.documentElement.lang=O(y),e.linkGuard!==!1&&(I=D({onDiagnostic:e.onDiagnostic}));let h=d(C,{failed:S,fallback:e.slots?.error,children:d(W,{locale:y,theme:e.theme&&e.theme!=="host"?e.theme:g.colorScheme==="dark"?"dark":"light"})});l.render(e.strictMode===!1?h:d(Oe,{children:h}))}).catch(S)}catch(r){S(r)}return{ready:i,dispose:z}}export{at as AttachmentImage,B as BaseAppProvider,Ve as CAPABILITY_CATALOG,v as CapabilityUnavailableError,Ie as DataNotReadyError,nt as DatabaseUserMenu,ze as DiagnosticCode,G as FloatingButton,He as SDKError,j as SITE_RUNTIME_PROTOCOL_VERSION,P as SiteChatbotStreamAdapter,Lt as SiteChatbotStreamError,Y as SiteRuntimeApi,te as SiteRuntimeClient,Z as SiteRuntimeErrorCode,J as SiteRuntimeEvent,X as SiteRuntimeFunction,Je as UiLanguageContext,rt as UserSelectorEditor,it as UserSelectorPanel,Re as buildAttachmentCoverUrl,ge as buildDatabaseInvokeFunctionPath,Ae as buildDatabaseInvokeGetPath,be as callSiteAIFunction,R as classifyRuntimeError,ve as createSiteAIFunctionTask,ne as createSiteRuntimeClient,de as createSiteRuntimeFetch,me as fetch,fe as fetchAttachmentCover,Se as fetchAttachmentDownloadUrl,We as getCapabilities,ae as getCurrentUser,le as getDatabaseContext,Qe as getRuntimeCapabilities,_e as getSiteAIFunctionTask,Xe as getUiLanguage,O as getUiLocale,_ as hasCapability,we as hasRunnableMediaTask,Ze as initializeUiLanguage,D as installLinkGuard,re as invokeApi,ke as invokeDatabaseFunction,ye as invokeDatabaseMutationBatch,ie as invokeHttp,Ce as invokeSiteAIFunctionStream,ee as isValidSiteFunctionName,oe as logout,k as normalizeSiteAIMediaTask,he as openAttachmentDownload,ue as openLink,je as queryCapability,Ke as readCapabilities,$ as readSiteAITextDelta,se as requestEdit,Ye as requireCapability,pe as resolveDatabaseContext,L as selectUiLanguage,m as siteRuntime,bt as startBaseApp,ce as uploadAttachment,et as useBaseApp,tt as useOptionalBaseApp,$e as useUiLanguage};
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SiteRuntimeApi } from '@lark-base-open/base-site-channel/runtime-contract';
|
|
2
2
|
import { RuntimeChannel } from '@lark-base-open/base-site-channel/runtime';
|
|
3
|
-
import { S as SiteRuntimeContext } from './capabilities-
|
|
3
|
+
import { S as SiteRuntimeContext } from './capabilities-83939715.js';
|
|
4
4
|
import { RuntimeCapabilities } from './shared.js';
|
|
5
5
|
import { HttpHandler } from 'msw';
|
|
6
6
|
import '@lark-base-open/base-site-channel/capabilities';
|
package/dist/theme.css
CHANGED
|
@@ -114,17 +114,97 @@
|
|
|
114
114
|
}
|
|
115
115
|
.base-app-floating {
|
|
116
116
|
position: fixed;
|
|
117
|
-
bottom:
|
|
117
|
+
bottom: 40px;
|
|
118
118
|
right: 24px;
|
|
119
119
|
z-index: var(--base-app-z-floating);
|
|
120
|
-
display: flex;
|
|
121
|
-
gap: 4px;
|
|
122
120
|
}
|
|
123
121
|
.base-app-floating[data-position="bottom-left"] {
|
|
124
122
|
left: 24px;
|
|
125
123
|
right: auto;
|
|
126
124
|
}
|
|
127
|
-
.base-app-floating
|
|
125
|
+
.base-app-floating-controls {
|
|
126
|
+
position: relative;
|
|
127
|
+
display: flex;
|
|
128
|
+
padding: 2px;
|
|
129
|
+
border-radius: 50%;
|
|
130
|
+
background: #fff;
|
|
131
|
+
box-shadow:
|
|
132
|
+
0 4px 4px rgb(31 35 41 / 6%),
|
|
133
|
+
0 6px 6px rgb(31 35 41 / 4%),
|
|
134
|
+
0 8px 12px rgb(31 35 41 / 4%);
|
|
135
|
+
}
|
|
136
|
+
.base-app-floating .base-app-floating-edit {
|
|
137
|
+
display: flex;
|
|
138
|
+
align-items: center;
|
|
139
|
+
justify-content: center;
|
|
140
|
+
width: 48px;
|
|
141
|
+
height: 48px;
|
|
142
|
+
padding: 0;
|
|
143
|
+
border: 0;
|
|
144
|
+
border-radius: 50%;
|
|
145
|
+
background: transparent;
|
|
146
|
+
color: #2b2f36;
|
|
147
|
+
}
|
|
148
|
+
.base-app-floating-edit:hover,
|
|
149
|
+
.base-app-floating-edit:focus-visible {
|
|
150
|
+
color: #1456f0;
|
|
151
|
+
}
|
|
152
|
+
.base-app-floating .base-app-floating-hide {
|
|
153
|
+
position: absolute;
|
|
154
|
+
top: -4px;
|
|
155
|
+
right: -4px;
|
|
156
|
+
display: flex;
|
|
157
|
+
align-items: center;
|
|
158
|
+
justify-content: center;
|
|
159
|
+
width: 16px;
|
|
160
|
+
height: 16px;
|
|
161
|
+
padding: 0;
|
|
162
|
+
border: 0;
|
|
163
|
+
border-radius: 50%;
|
|
164
|
+
background: #c8c9cc;
|
|
165
|
+
color: #646a73;
|
|
166
|
+
font-size: 14px;
|
|
167
|
+
line-height: 1;
|
|
168
|
+
opacity: 0;
|
|
169
|
+
transition: opacity 150ms;
|
|
170
|
+
}
|
|
171
|
+
.base-app-floating-controls:hover .base-app-floating-hide,
|
|
172
|
+
.base-app-floating-hide:focus-visible {
|
|
173
|
+
opacity: 1;
|
|
174
|
+
}
|
|
175
|
+
.base-app-floating .base-app-floating-hide:hover {
|
|
176
|
+
background: #b7b9bd;
|
|
177
|
+
}
|
|
178
|
+
.base-app-floating [role="tooltip"] {
|
|
179
|
+
pointer-events: none;
|
|
180
|
+
position: fixed;
|
|
181
|
+
z-index: var(--base-app-z-popover);
|
|
182
|
+
box-sizing: border-box;
|
|
183
|
+
width: max-content;
|
|
184
|
+
max-width: calc(100vw - 16px);
|
|
185
|
+
padding: 8px 12px;
|
|
186
|
+
border-radius: 8px;
|
|
187
|
+
background: #1f2329;
|
|
188
|
+
color: #fff;
|
|
189
|
+
font-size: 12px;
|
|
190
|
+
line-height: 20px;
|
|
191
|
+
white-space: normal;
|
|
192
|
+
overflow-wrap: anywhere;
|
|
193
|
+
box-shadow:
|
|
194
|
+
0 8px 24px 8px rgb(31 35 41 / 4%),
|
|
195
|
+
0 6px 12px rgb(31 35 41 / 4%),
|
|
196
|
+
0 4px 8px -8px rgb(31 35 41 / 6%);
|
|
197
|
+
}
|
|
198
|
+
.base-app-floating-caret {
|
|
199
|
+
position: absolute;
|
|
200
|
+
top: 100%;
|
|
201
|
+
width: 24px;
|
|
202
|
+
height: 6px;
|
|
203
|
+
transform: translateX(-50%);
|
|
204
|
+
}
|
|
205
|
+
.base-app-floating-caret svg {
|
|
206
|
+
display: block;
|
|
207
|
+
}
|
|
128
208
|
.base-app-floating [role="alert"] {
|
|
129
209
|
position: absolute;
|
|
130
210
|
bottom: 100%;
|
|
@@ -136,12 +216,45 @@
|
|
|
136
216
|
}
|
|
137
217
|
.base-app-notice {
|
|
138
218
|
position: fixed;
|
|
139
|
-
top:
|
|
219
|
+
top: 32px;
|
|
140
220
|
left: 50%;
|
|
141
221
|
transform: translateX(-50%);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
222
|
+
display: flex;
|
|
223
|
+
align-items: center;
|
|
224
|
+
gap: 8px;
|
|
225
|
+
width: 352px;
|
|
226
|
+
max-width: calc(100vw - 32px);
|
|
227
|
+
min-height: 54px;
|
|
228
|
+
padding: 16px 20px;
|
|
229
|
+
border-radius: 6px;
|
|
230
|
+
background: #f0f4ff;
|
|
231
|
+
color: #1f2329;
|
|
232
|
+
font-size: 14px;
|
|
233
|
+
font-weight: 500;
|
|
234
|
+
line-height: 22px;
|
|
235
|
+
box-shadow:
|
|
236
|
+
inset 0 0 0 1px #1456f0,
|
|
237
|
+
0 8px 24px 8px rgb(31 35 41 / 4%),
|
|
238
|
+
0 6px 12px rgb(31 35 41 / 4%),
|
|
239
|
+
0 4px 8px -8px rgb(31 35 41 / 6%);
|
|
240
|
+
z-index: var(--base-app-z-popover);
|
|
241
|
+
}
|
|
242
|
+
.base-app-notice > svg,
|
|
243
|
+
.base-app-notice button {
|
|
244
|
+
flex-shrink: 0;
|
|
245
|
+
}
|
|
246
|
+
.base-app-notice > span {
|
|
247
|
+
flex: 1;
|
|
248
|
+
min-width: 0;
|
|
249
|
+
padding: 0 8px 0 4px;
|
|
250
|
+
}
|
|
251
|
+
.base-app-notice button {
|
|
252
|
+
display: flex;
|
|
253
|
+
width: 16px;
|
|
254
|
+
height: 16px;
|
|
255
|
+
padding: 0;
|
|
256
|
+
border: 0;
|
|
257
|
+
background: transparent;
|
|
145
258
|
}
|
|
146
259
|
.base-app-user-menu {
|
|
147
260
|
display: inline-flex;
|
package/docs/compat.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
兼容基准为 classic 模板的 `page/src/lib/database-runtime.ts`;源码版本与摘要保存在仓库测试夹具中。page 保留其全部 36 个值/类型导出;测试夹具保存原始文件与 SHA256。兼容长期维护,暂不设截止日期。
|
|
4
4
|
|
|
5
|
-
数据库与附件实现位于 page/database.ts,AI helper 位于 page/ai-compat.ts。替换 import 后,Function 调用仍返回原 envelope
|
|
5
|
+
数据库与附件实现位于 page/database.ts,AI helper 位于 page/ai-compat.ts。替换 import 后,Function 调用仍返回原 envelope;唯一例外是数据未就绪(800008918):Function 调用默认开启写后读,重试用尽后不返回 envelope,改为抛 [`DataNotReadyError`](exports.md#page),传 `{ readYourWrites: false }` 保持原 envelope,见 [页面运行时](page.md) 的「写后读」;HTTP 失败仍抛错;Mutation batch 接受 1–200 个命名参数对象,与统一 Function 路由一致;旧位置数组必须按已发布的冻结声明人工迁移,不能直接替换 import 后发送。[`resolveDatabaseContext`](exports.md#page) 保持宿主优先、路径兜底和原会话缓存语义。媒体任务保留原 helper 的宽容归一化及错误名/码,流式 destroy 仍取消。
|
|
6
6
|
|
|
7
7
|
[`DatabaseFunctionInputMap`](exports.md#page) 可通过模块扩充,[`FunctionInputMap`](exports.md#page) 也可作为生成器的基础扩充接口;两者未提供函数时拒绝任意函数名和参数。不使用 Record<string,unknown> 兜底伪造类型安全。新生成工程用 Function ID 输出映射推断 `data`:SQL 为 `DatabaseQueryResult<Row>`,无列 Schema 时 `Row=unknown`;缺失输出映射时直接调用编译失败,应核对 CLI/SDK 版本并运行 `contracts generate`。批量调用还要求 ID 存在于 codegen 的 Mutation 标记映射中;每组输入和输出均按 ID 推断,移除调用方返回泛型。对自定义过 helper 的工程应先比对差异,不直接覆盖。
|
|
8
8
|
|
package/docs/exports.md
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
## page
|
|
6
6
|
|
|
7
|
-
值:`AttachmentImage`、`BaseAppProvider`、`CAPABILITY_CATALOG`、`CapabilityUnavailableError`、`DatabaseUserMenu`、`DiagnosticCode`、`FloatingButton`、`SDKError`、`SITE_RUNTIME_PROTOCOL_VERSION`、`SiteChatbotStreamAdapter`、`SiteChatbotStreamError`、`SiteRuntimeApi`、`SiteRuntimeClient`、`SiteRuntimeErrorCode`、`SiteRuntimeEvent`、`SiteRuntimeFunction`、`SiteRuntimeInvocationError`、`UiLanguageContext`、`UserSelectorEditor`、`UserSelectorPanel`、`buildAttachmentCoverUrl`、`buildDatabaseInvokeFunctionPath`、`buildDatabaseInvokeGetPath`、`callSiteAIFunction`、`classifyRuntimeError`、`createSiteAIFunctionTask`、`createSiteRuntimeClient`、`createSiteRuntimeFetch`、`fetch`、`fetchAttachmentCover`、`fetchAttachmentDownloadUrl`、`getCapabilities`、`getCurrentUser`、`getDatabaseContext`、`getRuntimeCapabilities`、`getSiteAIFunctionTask`、`getUiLanguage`、`getUiLocale`、`hasCapability`、`hasRunnableMediaTask`、`initializeUiLanguage`、`installLinkGuard`、`invokeApi`、`invokeDatabaseFunction`、`invokeDatabaseMutationBatch`、`invokeHttp`、`invokeSiteAIFunctionStream`、`isValidSiteFunctionName`、`logout`、`normalizeSiteAIMediaTask`、`openAttachmentDownload`、`openLink`、`queryCapability`、`readCapabilities`、`readSiteAITextDelta`、`requestEdit`、`requireCapability`、`resolveDatabaseContext`、`selectUiLanguage`、`siteRuntime`、`startBaseApp`、`uploadAttachment`、`useBaseApp`、`useOptionalBaseApp`、`useUiLanguage`。
|
|
7
|
+
值:`AttachmentImage`、`BaseAppProvider`、`CAPABILITY_CATALOG`、`CapabilityUnavailableError`、`DataNotReadyError`、`DatabaseUserMenu`、`DiagnosticCode`、`FloatingButton`、`SDKError`、`SITE_RUNTIME_PROTOCOL_VERSION`、`SiteChatbotStreamAdapter`、`SiteChatbotStreamError`、`SiteRuntimeApi`、`SiteRuntimeClient`、`SiteRuntimeErrorCode`、`SiteRuntimeEvent`、`SiteRuntimeFunction`、`SiteRuntimeInvocationError`、`UiLanguageContext`、`UserSelectorEditor`、`UserSelectorPanel`、`buildAttachmentCoverUrl`、`buildDatabaseInvokeFunctionPath`、`buildDatabaseInvokeGetPath`、`callSiteAIFunction`、`classifyRuntimeError`、`createSiteAIFunctionTask`、`createSiteRuntimeClient`、`createSiteRuntimeFetch`、`fetch`、`fetchAttachmentCover`、`fetchAttachmentDownloadUrl`、`getCapabilities`、`getCurrentUser`、`getDatabaseContext`、`getRuntimeCapabilities`、`getSiteAIFunctionTask`、`getUiLanguage`、`getUiLocale`、`hasCapability`、`hasRunnableMediaTask`、`initializeUiLanguage`、`installLinkGuard`、`invokeApi`、`invokeDatabaseFunction`、`invokeDatabaseMutationBatch`、`invokeHttp`、`invokeSiteAIFunctionStream`、`isValidSiteFunctionName`、`logout`、`normalizeSiteAIMediaTask`、`openAttachmentDownload`、`openLink`、`queryCapability`、`readCapabilities`、`readSiteAITextDelta`、`requestEdit`、`requireCapability`、`resolveDatabaseContext`、`selectUiLanguage`、`siteRuntime`、`startBaseApp`、`uploadAttachment`、`useBaseApp`、`useOptionalBaseApp`、`useUiLanguage`。
|
|
8
8
|
|
|
9
|
-
类型与值完整清单:`AttachmentImage`、`BaseAppContextValue`、`BaseAppHandle`、`BaseAppProvider`、`CAPABILITY_CATALOG`、`CallSiteAIFunctionParams`、`CapabilityContext`、`CapabilityDescriptor`、`CapabilityMap`、`CapabilityName`、`CapabilityQueryResult`、`CapabilityUnavailableError`、`CapabilityUnavailableReason`、`DatabaseAttachmentRef`、`DatabaseAudience`、`DatabaseContext`、`DatabaseEnv`、`DatabaseFunctionInputMap`、`DatabaseFunctionInvocation`、`DatabaseFunctionOutputMap`、`DatabaseFunctionResponse`、`DatabaseMutationResult`、`DatabaseQueryResult`、`DatabaseUserMenu`、`DatabaseUserMenuProps`、`DevelopmentPairChallenge`、`DevelopmentPairProof`、`DiagnosticCategory`、`DiagnosticCode`、`FloatingButton`、`FloatingButtonProps`、`FunctionEnvelope`、`FunctionInputMap`、`FunctionMap`、`FunctionOutputMap`、`InvokeSiteAIFunctionStreamParams`、`JsonValue`、`LinkGuardOptions`、`MutationFunctionId`、`MutationFunctionMap`、`RuntimeCapabilities`、`RuntimeChannel`、`RuntimeContextReader`、`RuntimeDiagnostic`、`SDKError`、`SDKErrorOptions`、`SITE_RUNTIME_PROTOCOL_VERSION`、`SiteAIAudioContentPart`、`SiteAICapabilityType`、`SiteAIFileContentPart`、`SiteAIFunctionArguments`、`SiteAIFunctionError`、`SiteAIFunctionOptions`、`SiteAIFunctionParams`、`SiteAIFunctionResult`、`SiteAIFunctionStreamCloseRequest`、`SiteAIFunctionStreamDone`、`SiteAIFunctionStreamError`、`SiteAIFunctionStreamHandle`、`SiteAIFunctionStreamMessage`、`SiteAIFunctionStreamOpenRequest`、`SiteAIFunctionVariables`、`SiteAIImageAsset`、`SiteAIImageContentPart`、`SiteAIImageGenerationInput`、`SiteAIImageTask`、`SiteAIMediaTask`、`SiteAIMediaTaskBase`、`SiteAIMessage`、`SiteAIMessageContentPart`、`SiteAIStreamDelta`、`SiteAIStreamMessageParam`、`SiteAITaskStatus`、`SiteAITextContentPart`、`SiteAITextDelta`、`SiteAITextMessageParam`、`SiteAIUserMessageParam`、`SiteAIVideoAsset`、`SiteAIVideoContentPart`、`SiteAIVideoGenerationInput`、`SiteAIVideoTask`、`SiteAttachmentTarget`、`SiteAttachmentUploadCancelRequest`、`SiteAttachmentUploadOptions`、`SiteAttachmentUploadPayload`、`SiteAttachmentUploadProgress`、`SiteAttachmentUploadRequest`、`SiteAttachmentUploadResult`、`SiteChatbotStreamAdapter`、`SiteChatbotStreamCloseRequest`、`SiteChatbotStreamError`、`SiteChatbotStreamMessage`、`SiteChatbotStreamOpenRequest`、`SiteFunctionDefinition`、`SiteFunctionInvokeRequest`、`SiteFunctionValidationIssue`、`SiteHttpCancelRequest`、`SiteHttpMethod`、`SiteHttpRequest`、`SiteHttpRequestInit`、`SiteHttpRequestOptions`、`SiteHttpResponse`、`SiteHttpResponseType`、`SiteOpenLinkRequest`、`SiteOpenLinkResult`、`SiteProjectEnv`、`SiteRuntimeApi`、`SiteRuntimeClient`、`SiteRuntimeContext`、`SiteRuntimeError`、`SiteRuntimeErrorCode`、`SiteRuntimeEvent`、`SiteRuntimeFunction`、`SiteRuntimeInvocationError`、`SiteRuntimeLoadFailedEvent`、`SiteRuntimeModeChangedEvent`、`SiteRuntimeReadyEvent`、`SiteRuntimeUserInfo`、`StartBaseAppOptions`、`UiLanguage`、`UiLanguageContext`、`User`、`UserSelectorAction`、`UserSelectorEditor`、`UserSelectorEditorProps`、`UserSelectorEditorValue`、`UserSelectorMode`、`UserSelectorPanel`、`UserSelectorPanelProps`、`UserSelectorSearchAction`、`UserSelectorValue`、`WriteResult`、`buildAttachmentCoverUrl`、`buildDatabaseInvokeFunctionPath`、`buildDatabaseInvokeGetPath`、`callSiteAIFunction`、`classifyRuntimeError`、`createSiteAIFunctionTask`、`createSiteRuntimeClient`、`createSiteRuntimeFetch`、`fetch`、`fetchAttachmentCover`、`fetchAttachmentDownloadUrl`、`getCapabilities`、`getCurrentUser`、`getDatabaseContext`、`getRuntimeCapabilities`、`getSiteAIFunctionTask`、`getUiLanguage`、`getUiLocale`、`hasCapability`、`hasRunnableMediaTask`、`initializeUiLanguage`、`installLinkGuard`、`invokeApi`、`invokeDatabaseFunction`、`invokeDatabaseMutationBatch`、`invokeHttp`、`invokeSiteAIFunctionStream`、`isValidSiteFunctionName`、`logout`、`normalizeSiteAIMediaTask`、`openAttachmentDownload`、`openLink`、`queryCapability`、`readCapabilities`、`readSiteAITextDelta`、`requestEdit`、`requireCapability`、`resolveDatabaseContext`、`selectUiLanguage`、`siteRuntime`、`startBaseApp`、`uploadAttachment`、`useBaseApp`、`useOptionalBaseApp`、`useUiLanguage`。
|
|
9
|
+
类型与值完整清单:`AttachmentImage`、`BaseAppContextValue`、`BaseAppHandle`、`BaseAppProvider`、`CAPABILITY_CATALOG`、`CallSiteAIFunctionParams`、`CapabilityContext`、`CapabilityDescriptor`、`CapabilityMap`、`CapabilityName`、`CapabilityQueryResult`、`CapabilityUnavailableError`、`CapabilityUnavailableReason`、`DataNotReadyError`、`DatabaseAttachmentRef`、`DatabaseAudience`、`DatabaseContext`、`DatabaseEnv`、`DatabaseFunctionInputMap`、`DatabaseFunctionInvocation`、`DatabaseFunctionOptions`、`DatabaseFunctionOutputMap`、`DatabaseFunctionResponse`、`DatabaseMutationResult`、`DatabaseQueryResult`、`DatabaseUserMenu`、`DatabaseUserMenuProps`、`DevelopmentPairChallenge`、`DevelopmentPairProof`、`DiagnosticCategory`、`DiagnosticCode`、`FloatingButton`、`FloatingButtonProps`、`FunctionEnvelope`、`FunctionInputMap`、`FunctionMap`、`FunctionOutputMap`、`InvokeSiteAIFunctionStreamParams`、`JsonValue`、`LinkGuardOptions`、`MutationFunctionId`、`MutationFunctionMap`、`RuntimeCapabilities`、`RuntimeChannel`、`RuntimeContextReader`、`RuntimeDiagnostic`、`SDKError`、`SDKErrorOptions`、`SITE_RUNTIME_PROTOCOL_VERSION`、`SiteAIAudioContentPart`、`SiteAICapabilityType`、`SiteAIFileContentPart`、`SiteAIFunctionArguments`、`SiteAIFunctionError`、`SiteAIFunctionOptions`、`SiteAIFunctionParams`、`SiteAIFunctionResult`、`SiteAIFunctionStreamCloseRequest`、`SiteAIFunctionStreamDone`、`SiteAIFunctionStreamError`、`SiteAIFunctionStreamHandle`、`SiteAIFunctionStreamMessage`、`SiteAIFunctionStreamOpenRequest`、`SiteAIFunctionVariables`、`SiteAIImageAsset`、`SiteAIImageContentPart`、`SiteAIImageGenerationInput`、`SiteAIImageTask`、`SiteAIMediaTask`、`SiteAIMediaTaskBase`、`SiteAIMessage`、`SiteAIMessageContentPart`、`SiteAIStreamDelta`、`SiteAIStreamMessageParam`、`SiteAITaskStatus`、`SiteAITextContentPart`、`SiteAITextDelta`、`SiteAITextMessageParam`、`SiteAIUserMessageParam`、`SiteAIVideoAsset`、`SiteAIVideoContentPart`、`SiteAIVideoGenerationInput`、`SiteAIVideoTask`、`SiteAttachmentTarget`、`SiteAttachmentUploadCancelRequest`、`SiteAttachmentUploadOptions`、`SiteAttachmentUploadPayload`、`SiteAttachmentUploadProgress`、`SiteAttachmentUploadRequest`、`SiteAttachmentUploadResult`、`SiteChatbotStreamAdapter`、`SiteChatbotStreamCloseRequest`、`SiteChatbotStreamError`、`SiteChatbotStreamMessage`、`SiteChatbotStreamOpenRequest`、`SiteFunctionDefinition`、`SiteFunctionInvokeRequest`、`SiteFunctionValidationIssue`、`SiteHttpCancelRequest`、`SiteHttpMethod`、`SiteHttpRequest`、`SiteHttpRequestInit`、`SiteHttpRequestOptions`、`SiteHttpResponse`、`SiteHttpResponseType`、`SiteOpenLinkRequest`、`SiteOpenLinkResult`、`SiteProjectEnv`、`SiteRuntimeApi`、`SiteRuntimeClient`、`SiteRuntimeContext`、`SiteRuntimeError`、`SiteRuntimeErrorCode`、`SiteRuntimeEvent`、`SiteRuntimeFunction`、`SiteRuntimeInvocationError`、`SiteRuntimeLoadFailedEvent`、`SiteRuntimeModeChangedEvent`、`SiteRuntimeReadyEvent`、`SiteRuntimeUserInfo`、`StartBaseAppOptions`、`UiLanguage`、`UiLanguageContext`、`User`、`UserSelectorAction`、`UserSelectorEditor`、`UserSelectorEditorProps`、`UserSelectorEditorValue`、`UserSelectorMode`、`UserSelectorPanel`、`UserSelectorPanelProps`、`UserSelectorSearchAction`、`UserSelectorValue`、`WriteResult`、`buildAttachmentCoverUrl`、`buildDatabaseInvokeFunctionPath`、`buildDatabaseInvokeGetPath`、`callSiteAIFunction`、`classifyRuntimeError`、`createSiteAIFunctionTask`、`createSiteRuntimeClient`、`createSiteRuntimeFetch`、`fetch`、`fetchAttachmentCover`、`fetchAttachmentDownloadUrl`、`getCapabilities`、`getCurrentUser`、`getDatabaseContext`、`getRuntimeCapabilities`、`getSiteAIFunctionTask`、`getUiLanguage`、`getUiLocale`、`hasCapability`、`hasRunnableMediaTask`、`initializeUiLanguage`、`installLinkGuard`、`invokeApi`、`invokeDatabaseFunction`、`invokeDatabaseMutationBatch`、`invokeHttp`、`invokeSiteAIFunctionStream`、`isValidSiteFunctionName`、`logout`、`normalizeSiteAIMediaTask`、`openAttachmentDownload`、`openLink`、`queryCapability`、`readCapabilities`、`readSiteAITextDelta`、`requestEdit`、`requireCapability`、`resolveDatabaseContext`、`selectUiLanguage`、`siteRuntime`、`startBaseApp`、`uploadAttachment`、`useBaseApp`、`useOptionalBaseApp`、`useUiLanguage`。
|
|
10
10
|
|
|
11
11
|
## server
|
|
12
12
|
|
package/docs/page.md
CHANGED
|
@@ -131,6 +131,54 @@ baseToken/tableId 来自 Catalog,必须成对属于应用绑定;不传 field
|
|
|
131
131
|
进度以回调 total 为分母,100% 不等于完成。首条进度之后连续 120 秒无新进度会报告停滞,未收到首条进度可能仍在排队;超时不是上传未发生的证明。先保留 token 并核对结果,不自动重传。
|
|
132
132
|
上传不会自动挂载到单元格。图片宽高应从原始 File 解码后透传给业务 FaaS;移除附件引用不等于删除云盘文件。展示使用 /page 或 /components 的 [`AttachmentImage`](exports.md#page);[`fetchAttachmentCover`](exports.md#page) 返回 Blob,[`fetchAttachmentDownloadUrl`](exports.md#page) 返回临时链接,参数及完整附件坐标见 [兼容 API](compat.md) 与 [组件](components.md)。写入由业务 FaaS 调用 /server 的 ctx.records,见 [服务端 SDK](server.md);页面不导入 server。附件业务规则见 随 CLI 安装的 lark-base-database Skill 中的「Skill 文件传输」(references/file-transfer.md)。
|
|
133
133
|
|
|
134
|
+
## 写后读
|
|
135
|
+
|
|
136
|
+
[`invokeDatabaseFunction`](exports.md#page) 与 [`invokeDatabaseMutationBatch`](exports.md#page) 自动携带请求头 `x-base-site-session-id`(同站点同浏览器稳定,存于 localStorage,不可用时退回内存),页面无需处理。写入后紧接着查询时,数据可能尚未可读:Function 调用默认开启写后读(`readYourWrites` 默认 `true`),无需传参;SDK 遇到数据未就绪会按宿主下发的重试参数等待并原样重发,重试用尽抛 [`DataNotReadyError`](exports.md#page):写入已成功,不要重写;提示「数据同步中」并给用户重新查询入口。用 `instanceof DataNotReadyError` 识别,它同时是 `SDKError`。轮询、统计面板等可接受旧数据且对时延敏感的读传 `{ readYourWrites: false }` 不等:不带声明头,数据未就绪时原样返回 envelope。单条写调用默认也带声明头,不改变写的行为;批量 Mutation 不带声明头。
|
|
137
|
+
|
|
138
|
+
<!-- example: read-after-write.ts -->
|
|
139
|
+
```ts
|
|
140
|
+
import {
|
|
141
|
+
DataNotReadyError,
|
|
142
|
+
type DatabaseFunctionOptions,
|
|
143
|
+
} from '@lark-base-open/base-database-app-sdk/page';
|
|
144
|
+
|
|
145
|
+
// 生成的函数客户端(page/src/generated/functions.ts)里的每个函数都带同样的可选
|
|
146
|
+
// options;实际工程直接 import 生成的 functions,这里以声明类型代表它保持示例可编译。
|
|
147
|
+
declare const functions: {
|
|
148
|
+
listOrders: (
|
|
149
|
+
input: { status: string },
|
|
150
|
+
options?: DatabaseFunctionOptions,
|
|
151
|
+
) => Promise<unknown>;
|
|
152
|
+
countOrders: (
|
|
153
|
+
input: { status: string },
|
|
154
|
+
options?: DatabaseFunctionOptions,
|
|
155
|
+
) => Promise<unknown>;
|
|
156
|
+
};
|
|
157
|
+
declare function render(orders: unknown): void;
|
|
158
|
+
declare function renderCount(count: unknown): void;
|
|
159
|
+
declare function showSyncing(): void;
|
|
160
|
+
|
|
161
|
+
export async function showOrderList() {
|
|
162
|
+
try {
|
|
163
|
+
// 写后读默认开启,不用传 options:数据未就绪时 SDK 自动等待重试。
|
|
164
|
+
const orders = await functions.listOrders({ status: 'open' });
|
|
165
|
+
render(orders);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (error instanceof DataNotReadyError) {
|
|
168
|
+
// SDK 已重试用尽:提示「数据同步中」,给重新查询入口,不要重写。
|
|
169
|
+
showSyncing();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export async function pollOrderCount() {
|
|
177
|
+
// 轮询、统计面板等可接受旧数据且对时延敏感的读传 false,不等写后读。
|
|
178
|
+
renderCount(await functions.countOrders({ status: 'open' }, { readYourWrites: false }));
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
134
182
|
## 其他兼容导出
|
|
135
183
|
|
|
136
184
|
[`invokeApi`](exports.md#page) 使用 [`FunctionMap`](exports.md#page) 定义的 function 点号路径,不是 Database Function ID。
|
package/docs/upgrade.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 工程迁移与 SDK 升级
|
|
2
2
|
|
|
3
|
-
SDK API
|
|
3
|
+
SDK API 的版本变更见随包 [CHANGELOG](../CHANGELOG.md),升级与迁移指导以配套 CLI 随包安装的建站 Skill 为准;API 细节查阅工程实际安装版本的 SDK 文档。未授权升级时保留现有依赖。
|
|
4
4
|
|
|
5
5
|
存量 classic 的工程迁移由 coding agent 执行;步骤、输入声明与改前/改后示例统一以随 CLI 安装的建站 Skill `references/workspace-migration.md` 为准。CLI 只做配置、契约、类型和构建校验,不改写 helper 或自动搬迁工程。
|
|
6
6
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataNotReadyError,
|
|
3
|
+
type DatabaseFunctionOptions,
|
|
4
|
+
} from '@lark-base-open/base-database-app-sdk/page';
|
|
5
|
+
|
|
6
|
+
// 生成的函数客户端(page/src/generated/functions.ts)里的每个函数都带同样的可选
|
|
7
|
+
// options;实际工程直接 import 生成的 functions,这里以声明类型代表它保持示例可编译。
|
|
8
|
+
declare const functions: {
|
|
9
|
+
listOrders: (
|
|
10
|
+
input: { status: string },
|
|
11
|
+
options?: DatabaseFunctionOptions,
|
|
12
|
+
) => Promise<unknown>;
|
|
13
|
+
countOrders: (
|
|
14
|
+
input: { status: string },
|
|
15
|
+
options?: DatabaseFunctionOptions,
|
|
16
|
+
) => Promise<unknown>;
|
|
17
|
+
};
|
|
18
|
+
declare function render(orders: unknown): void;
|
|
19
|
+
declare function renderCount(count: unknown): void;
|
|
20
|
+
declare function showSyncing(): void;
|
|
21
|
+
|
|
22
|
+
export async function showOrderList() {
|
|
23
|
+
try {
|
|
24
|
+
// 写后读默认开启,不用传 options:数据未就绪时 SDK 自动等待重试。
|
|
25
|
+
const orders = await functions.listOrders({ status: 'open' });
|
|
26
|
+
render(orders);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error instanceof DataNotReadyError) {
|
|
29
|
+
// SDK 已重试用尽:提示「数据同步中」,给重新查询入口,不要重写。
|
|
30
|
+
showSyncing();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function pollOrderCount() {
|
|
38
|
+
// 轮询、统计面板等可接受旧数据且对时延敏感的读传 false,不等写后读。
|
|
39
|
+
renderCount(await functions.countOrders({ status: 'open' }, { readYourWrites: false }));
|
|
40
|
+
}
|
package/package.json
CHANGED
package/dist/chunk-FJAP37BR.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as Le,b as Q,c as Fe}from"./chunk-ZKBZAK4L.js";import{a as pe}from"./chunk-3JX3FIBG.js";import{a as N}from"./chunk-OHPYKFCM.js";import{createContext as $t,useContext as Xe}from"react";import{createContext as Dt,useContext as Mt,useEffect as Lt,useSyncExternalStore as Ft}from"react";import{capabilityNames as Ct}from"@lark-base-open/base-site-channel/capabilities";import*as S from"@lark-base-open/base-site-channel/runtime";import{SITE_RUNTIME_PROTOCOL_VERSION as En,SiteRuntimeApi as ne,SiteRuntimeEvent as Un,SiteRuntimeFunction as Sn,SiteRuntimeErrorCode as Pn,readSiteAITextDelta as xn,isValidSiteFunctionName as kn}from"@lark-base-open/base-site-channel/runtime-contract";var V=()=>{throw new pe(Q.ContextInvalid,"\u5BBF\u4E3B\u80FD\u529B\u5B57\u6BB5\u65E0\u6548")};function me(e){if(!e||typeof e!="object")return V();if(e.capabilities===void 0)return Object.fromEntries(Object.entries(Le).filter(([,o])=>o.baseline).map(([o])=>[o,{version:1}]));let t=e.capabilities;if(!t||typeof t!="object"||Array.isArray(t))return V();let n=Object.entries(t);return n.some(([,o])=>!o||typeof o!="object"||Array.isArray(o)||!Number.isSafeInteger(o.version)||o.version<=0)?V():Object.fromEntries(n.map(([o,r])=>[o,{version:r.version}]))}function yt(e,t,n=1){if(!Number.isSafeInteger(n)||n<1)return V();let o=me(e);return Object.prototype.hasOwnProperty.call(o,t)&&o[t].version>=n}async function wt(e=E){return me(await e.getRuntimeContext())}var In=wt;async function vt(e,t=1,n=E){let o=await n.getRuntimeContext(),r=me(o),i=yt(o,e,t),a=o.capabilityUnavailable;if(a!==void 0&&(!a||typeof a!="object"||Array.isArray(a)))return V();let s=a&&Object.prototype.hasOwnProperty.call(a,e)?a[e]:void 0;return s!==void 0&&(!s||typeof s!="object"||!["permission-denied","region-unavailable","temporarily-unavailable"].includes(s.reason)||typeof s.retryable!="boolean")?V():{name:e,requiredVersion:t,version:Object.prototype.hasOwnProperty.call(r,e)?r[e].version:null,supported:i,source:o.capabilities===void 0?"host-baseline":"advertised",availability:i?s?.reason??"unknown":"unsupported"}}async function Oe(e,t=1,n=E){let o=await n.getRuntimeContext(),r=await vt(e,t,{getRuntimeContext:async()=>o});if(!r.supported)throw new Fe(e,t);let i={"permission-denied":Q.PermissionDenied,"region-unavailable":Q.RegionUnavailable,"temporarily-unavailable":Q.TemporarilyUnavailable};if(r.availability in i)throw new pe(i[r.availability],"\u5BBF\u4E3B\u660E\u786E\u62D2\u7EDD\u6B64\u80FD\u529B",void 0,o.capabilityUnavailable?.[e]?.retryable)}function Ne(e,t){let n,o=!1,r,i=new Promise(a=>{r=a});return e.registerApi(N.pairApi,async a=>{if(!a||!/^[A-Za-z0-9_-]{43}$/.test(a.challenge))throw new Error("INVALID_PAIRING_CHALLENGE");n=a.challenge;let s=n;o&&(o=!1,i=new Promise(u=>{r=u}));let c=await t(N.endpoint,{method:"POST",credentials:"omit",cache:"no-store",redirect:"error",headers:{"Content-Type":"application/json"},body:JSON.stringify({challenge:s})});if(!c.ok)throw new Error("DEVELOPMENT_PAIRING_FAILED");let d=await c.json();if(!/^[A-Za-z0-9_-]{43}$/.test(d.proof))throw new Error("INVALID_PAIRING_PROOF");return{proof:d.proof}}),e.subscribeEvent(N.pairedEvent,a=>{n&&a?.challenge===n&&(o=!0,r())}),{reset:()=>{n=void 0,o&&(o=!1,i=new Promise(a=>{r=a}))},wait:async()=>{let a;do a=i,await a;while(a!==i)}}}var je=typeof window<"u"&&window.location.protocol==="http:"&&window.location.hostname===N.host&&Number(window.location.port)>=N.portMin&&Number(window.location.port)<=N.portMax;var Be=S.siteRuntime,I=Be.getChannel?.()??Be.channel,Rt=je&&typeof window<"u"&&window.parent!==window?Ne(I,globalThis.fetch.bind(globalThis)):void 0;function $e(e,t=async()=>{}){let n=new Map,o=async(r,i)=>{await t();for(let a of Ct(r,i))try{await Oe(a,1,{getRuntimeContext:()=>e.invokeApi(ne.RuntimeContext,void 0)})}catch(s){throw s instanceof Error&&"code"in s?Object.assign(new S.SiteRuntimeInvocationError(String(s.code),s.message),s):s}};return{subscribeEvent:(r,i)=>e.subscribeEvent(r,i),emitEvent:async(r,i)=>(await o(r,i),e.emitEvent(r,i)),invokeApi:async(r,i,a)=>{let s=i?.requestId??i?.subscriptionId??i?.uploadId,c=r===ne.HttpRequestCancel||r===ne.AttachmentUploadCancel||r.endsWith(".close");if(c&&s&&n.has(s)){n.get(s).canceled=!0;return}let d={canceled:!1};!c&&s&&n.set(s,d);try{if(await o(r,i),d.canceled)throw new DOMException("The operation was aborted","AbortError");return s&&n.delete(s),await e.invokeApi(r,i,a)}finally{s&&n.get(s)===d&&n.delete(s)}}}}var Et={invokeApi:I.invokeApi.bind(I),emitEvent:I.emitEvent.bind(I),subscribeEvent:I.subscribeEvent.bind(I)},ge=$e(Et,async()=>{if(typeof window<"u"&&window.parent===window)throw new S.SiteRuntimeInvocationError("CHANNEL_UNAVAILABLE","\u9875\u9762\u672A\u8FDE\u63A5\u5BBF\u4E3B channel");await Rt?.wait()});I.invokeApi=ge.invokeApi;I.emitEvent=ge.emitEvent;var fe=class extends S.SiteRuntimeClient{constructor(t){super(t?$e(t):ge)}},jn=e=>new fe(e),E=S.siteRuntime,{invokeHttp:oe,invokeApi:Bn,getCurrentUser:Y,logout:he,requestEdit:Ut,uploadAttachment:$n,openLink:re}=E,St=(e=E,t)=>S.createSiteRuntimeFetch(e,t),D=St();var Pt=oe,xt=/^\/?(preview\/)?app\/([^/]+)(\/|$)/,He=/^[A-Za-z0-9_-]+$/,ze="/space/api/bitable/site/v1",kt="/space/api/box/file/temporary_download_url",G="preview",W=null;function At(){let t=(typeof globalThis.location>"u"?void 0:globalThis.location)?.ancestorOrigins?.[0];if(t)return t;let n=typeof globalThis.document>"u"?"":globalThis.document.referrer;if(!n)return"";try{return new URL(n).origin}catch{return""}}function be(){let e=typeof globalThis.location>"u"?"":globalThis.location.pathname,t=xt.exec(e),n=At();return t?{env:t[1]?G:"prod",gatewayOrigin:n,token:decodeURIComponent(t[2]??"")}:{env:"prod",gatewayOrigin:n,token:""}}function Z(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Tt(e){return e===G||e==="prod"}function It(e){if(!Z(e))return{};let t=typeof e.siteToken=="string"?e.siteToken.trim():"";return{...t?{token:t}:{},...Tt(e.env)?{env:e.env}:{}}}async function j(){return W||(W=(async()=>{let e=be(),t={};try{t=It(await E.getRuntimeContext())}catch(o){console.warn("Could not read the host Runtime context; inferring it from the artifact path",o)}let n={env:t.env??e.env,gatewayOrigin:e.gatewayOrigin,token:t.token??e.token};return n.token||console.error("Cannot determine the app token: the host did not provide siteToken and the current path does not match an artifact path"),n})().catch(e=>{throw W=null,e}),W)}function ye(e){return!!(e.tableId.trim()&&e.fieldId.trim()&&e.recordId.trim()&&e.fileToken.trim())}function qe(e,t){return JSON.stringify({bitablePerm:{tableId:t.tableId,attachments:{[t.fieldId]:{[t.recordId]:[t.fileToken]}},siteToken:e.token,siteEnv:e.env}})}function Ve(e,t){if(t instanceof Error)return t;let n=Z(t)?t.code:void 0,o=typeof n=="string"||typeof n=="number"?String(n):"",r=o==="REQUEST_TIMEOUT"||o==="10005"?`${e} timed out`:`${e} failed`;return Object.assign(new Error(`${r}${o?` (code ${o})`:""}`),{cause:t,...o?{code:o}:{}})}async function Ge(e,t=360,n={}){if(n.signal?.throwIfAborted(),!ye(e)||!Number.isFinite(t)||t<=0)throw new Error("Attachment location or image size is invalid");let o=await j();if(n.signal?.throwIfAborted(),!o.token)throw new Error("Cannot load the attachment image without an app token");let r=[120,360,720,1280].find(c=>c>=t)??1280,i=new URLSearchParams({extra:qe(o,e),width:String(r),height:String(r),policy:"allow_up",fallback_source:"1"}),a=await Pt({url:`/space/api/box/stream/download/v2/cover/${encodeURIComponent(e.fileToken)}?${i}`,init:{method:"GET",responseType:"arrayBuffer",timeoutMs:45e3},signal:n.signal}).catch(c=>{throw Ve("Attachment image request",c)});if(!a.ok){let c=a.headers.get("x-tt-logid");throw new Error(`Failed to load attachment image: HTTP ${a.status}${c?`, LogID ${c}`:""}`)}let s=await a.blob();if(!s.size||!s.type.startsWith("image/"))throw new Error("The host did not return a valid image");return s}async function _t(e,t){if(!e.token)throw new Error("Cannot get an attachment download URL without an app token");if(!ye(t))throw new Error("Cannot get an attachment download URL: the attachment location is incomplete");let n=await D(kt,{body:JSON.stringify({extra:qe(e,t),file_token:t.fileToken}),headers:{"content-type":"application/json"},method:"POST"}).catch(s=>{throw Ve("Attachment download URL request",s)}),o=n.headers?.get("x-tt-logid")?.trim(),r;try{r=await n.json()}catch{throw new Error(n.ok?`Attachment download URL response is not valid JSON${o?`, LogID ${o}`:""}`:`Failed to get attachment download URL: HTTP ${n.status}${o?`, LogID ${o}`:""}`)}let i=Z(r)?r.code:void 0;if(typeof i=="number"&&i!==0||typeof i=="string"&&i.trim()!==""&&i.trim()!=="0"){let s=new Error(`Attachment service could not provide a download URL (code ${String(i)}${o?`, LogID ${o}`:""})`);throw Object.assign(s,{code:String(i),cause:r})}if(!n.ok)throw new Error(`Failed to get attachment download URL: HTTP ${n.status}${o?`, LogID ${o}`:""}`);let a=Z(r)&&Z(r.data)&&typeof r.data.url=="string"?r.data.url.trim():"";if(!a)throw new Error(`Attachment download URL response is missing data.url${o?`, LogID ${o}`:""}`);return a}function Je(e){let t=new URLSearchParams;e.env===G&&t.set("env",G);let n=t.toString(),o=`${ze}/${encodeURIComponent(e.token)}/invoke_get`;return n?`${o}?${n}`:o}function Ke(e,t){if(!He.test(t))throw new TypeError(`functionId ${t} does not match the required pattern ${String(He)}`);let n=`${ze}/${encodeURIComponent(e.token)}/functions/${encodeURIComponent(t)}/invoke`;return e.env===G?`${n}?env=${encodeURIComponent(G)}`:n}async function qn(e,t){let n=await j();if(!n.token)throw new Error(`Cannot invoke Function ${e} without an app token`);let o=await oe({url:Ke(n,e),init:{body:JSON.stringify({params:t}),headers:{"content-type":"application/json"},method:"POST"}});if(!o.ok)throw new Error(`Function ${e} request failed: HTTP ${o.status}`);return await o.json()}async function Vn(e,t){if(!Array.isArray(t)||t.length<1||t.length>200||t.some(r=>r===null||typeof r!="object"||Array.isArray(r)))throw new TypeError("Mutation batch requires 1 to 200 named parameter objects");let n=await j();if(!n.token)throw new Error("\u5E94\u7528 token \u672A\u786E\u5B9A\uFF0C\u65E0\u6CD5\u8C03\u7528 Mutation");let o=await oe({url:Ke(n,e),init:{body:JSON.stringify({batch:t.map(r=>({params:r}))}),headers:{"content-type":"application/json"},method:"POST"}});if(!o.ok)throw new Error(`Mutation \u8C03\u7528\u5931\u8D25\uFF1AHTTP ${o.status}`);return await o.json()}async function Gn(e,t){let n=await _t(e,t);if(!(await re(n)).opened)throw new Error("The host did not open the attachment download link")}function Jn(e,t,n=360){if(!e.gatewayOrigin||!e.token||!ye(t))return"";let o=[120,360,720,1280].find(i=>i>=n)??1280,r=new URLSearchParams({extra:JSON.stringify({bitablePerm:{tableId:t.tableId,attachments:{[t.fieldId]:{[t.recordId]:[t.fileToken]}},baseAppToken:e.token}}),width:String(o),height:String(o),policy:"allow_up",fallback_source:"1"});return`${e.gatewayOrigin}/space/api/box/stream/download/v2/cover/${encodeURIComponent(t.fileToken)}?${r.toString()}`}var Re=Dt(void 0),Ye=[{id:"en",locale:"en-US",match:/^en(?:-|$)/},{id:"zh",locale:"zh-CN",match:/^zh(?:-|$)/},{id:"ja",locale:"ja-JP",match:/^ja(?:-|$)/}],ve=new Set,We,we=null;function Ce(e){if(typeof e!="string")return;let t=e.trim().replace(/_/g,"-").toLowerCase();return Ye.find(({match:n})=>n.test(t))?.id}function Ot(){return typeof navigator>"u"?void 0:navigator.language}function Nt(e,t){return Ce(e)??Ce(t)??"en"}function B(){return We??Nt(void 0,Ot())}function Ee(e=B()){return Ye.find(({id:t})=>t===e)?.locale??"en-US"}function jt(e){return ve.add(e),()=>ve.delete(e)}function Qe(e){We=Ce(e);let t=B();Ze(t);for(let n of ve)n();return t}function Ze(e){typeof document<"u"&&(document.documentElement.lang=Ee(e))}function Bt(){return we||(Ze(B()),we=E.getRuntimeContext().then(e=>Qe(e?.locale)).catch(()=>Qe(void 0))),we}function P(){let e=Mt(Re),t=Ft(jt,B,()=>"en");return Lt(()=>{e||Bt()},[e]),e??t}import{jsx as Ue}from"react/jsx-runtime";var Se=$t(null);function no({children:e,...t}){return Ue(Se.Provider,{value:t,children:Ue(Re.Provider,{value:t.locale,children:Ue("div",{className:"base-app-platform","data-theme":t.theme,children:e})})})}function oo(){let e=Xe(Se);if(!e)throw new Error("BASE_APP_PROVIDER_REQUIRED");return e}function ae(){return Xe(Se)}import{useState as X,useEffect as nt}from"react";import{QueryClient as Ht}from"@tanstack/react-query";var Pe=new Ht({defaultOptions:{queries:{retry:!1,staleTime:3e4,gcTime:3e4}}});function ie(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function se(e,t){let n=e[t];return typeof n=="string"?n.trim():""}function zt(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function $(){return{baseBindings:[],name:"",description:"",isOwner:!1,allowEdit:!1,organization:""}}function qt(){let e=document.querySelector('meta[name="description"]');return e instanceof HTMLMetaElement?e:null}function Vt(e){if(e.name&&(document.title=e.name),e.description){let t=qt();t&&(t.content=e.description)}}function Gt(e){return Array.isArray(e)?e.reduce((t,n)=>{if(!ie(n))return t;let o=se(n,"baseToken");return o&&t.push({baseToken:o,tableIds:zt(n.tableIds)}),t},[]):[]}function Jt(e){if(!ie(e)||e.code!==0)return $();let t=e.data;if(!ie(t))return $();let n=t.site;return ie(n)?{baseBindings:Gt(n.baseBindings),description:se(n,"description"),name:se(n,"name"),isOwner:t.isOwner===!0,allowEdit:n.allowEdit===void 0?t.isOwner===!0:n.allowEdit===!0,organization:se(n,"organization")}:$()}async function et(e){try{let t=await D(Je(e),{method:"GET"});if(!t.ok)return $();let n=await t.json(),o=Jt(n);return Vt(o),o}catch{return $()}}async function J(){let e=await j();if(!e.token)return $();let t=await Y().catch(()=>null);return t?.userId?Pe.fetchQuery({queryKey:["project-meta",e.token,e.env,t.userId],queryFn:()=>et(e)}):et(e)}var Kt="https://feishu.cn/base/site/detail/overview";async function tt(){try{await E.requestEdit();return}catch{let{token:e}=await j(),t=new URL(Kt);if(t.searchParams.set("token",e),!(await re(t.toString())).opened)throw new Error("Management page was not opened")}}import{jsx as H,jsxs as ot}from"react/jsx-runtime";var Qt={en:{openFailed:"Unable to open the management page. Please try again.",editSite:"Edit and manage your apps",hidePanel:"Hide until next visit",hiddenConfirmation:"Edit button hidden until you reopen the app",dismissNotification:"Dismiss notification"},zh:{openFailed:"\u65E0\u6CD5\u6253\u5F00\u7BA1\u7406\u9875\u9762\uFF0C\u8BF7\u91CD\u8BD5",editSite:"\u7F16\u8F91\u4E0E\u7BA1\u7406\u5E94\u7528",hidePanel:"\u9690\u85CF\u9762\u677F",hiddenConfirmation:"\u7F16\u8F91\u6309\u94AE\u5DF2\u9690\u85CF\uFF0C\u76F4\u81F3\u4E0B\u6B21\u91CD\u65B0\u6253\u5F00\u5E94\u7528",dismissNotification:"\u5173\u95ED\u63D0\u793A"},ja:{openFailed:"\u7BA1\u7406\u30DA\u30FC\u30B8\u3092\u958B\u3051\u307E\u305B\u3093\u3067\u3057\u305F\u3002\u3082\u3046\u4E00\u5EA6\u304A\u8A66\u3057\u304F\u3060\u3055\u3044\u3002",editSite:"\u30A2\u30D7\u30EA\u3092\u7DE8\u96C6\u30FB\u7BA1\u7406",hidePanel:"\u6B21\u56DE\u306E\u30A2\u30AF\u30BB\u30B9\u307E\u3067\u975E\u8868\u793A",hiddenConfirmation:"\u7DE8\u96C6\u30DC\u30BF\u30F3\u3092\u975E\u8868\u793A\u306B\u3057\u307E\u3057\u305F\u3002\u30A2\u30D7\u30EA\u3092\u518D\u5EA6\u958B\u304F\u3068\u8868\u793A\u3055\u308C\u307E\u3059",dismissNotification:"\u901A\u77E5\u3092\u9589\u3058\u308B"}};function vo({position:e="bottom-right",className:t="",slots:n={}}){let o=Qt[P()],[r,i]=X(!1),[a,s]=X(!1),[c,d]=X(!1),[u,p]=X(!1),[h,g]=X(!1);nt(()=>{let b=!0;return J().then(F=>{b&&i(F.allowEdit&&be().env==="prod")}).catch(()=>{}),()=>{b=!1}},[]),nt(()=>{if(!c)return;let b=setTimeout(()=>d(!1),3e3);return()=>clearTimeout(b)},[c]);let m=n.trigger,v=n.tooltip;return r?a?c?ot("div",{className:"base-app-platform base-app-notice",role:"status",children:[o.hiddenConfirmation,H("button",{"aria-label":o.dismissNotification,onClick:()=>d(!1),children:"\xD7"})]}):null:ot("div",{className:`base-app-platform base-app-floating ${t}`,"data-position":e,children:[u?H("div",{role:"alert",children:o.openFailed}):null,h?H("div",{role:"tooltip",children:v?H(v,{text:o.editSite}):o.editSite}):null,H("button",{"aria-label":o.editSite,onFocus:()=>g(!0),onBlur:()=>g(!1),onMouseEnter:()=>g(!0),onMouseLeave:()=>g(!1),onClick:()=>{p(!1),tt().catch(()=>p(!0))},children:m?H(m,{}):"\u270E"}),H("button",{"aria-label":o.hidePanel,onClick:()=>{s(!0),d(!0)},children:"\xD7"})]}):null}var xe=new Set;function rt(e){return xe.add(e),()=>{xe.delete(e)}}function at(){for(let e of xe)e()}import{useEffect as Yt,useState as st}from"react";import*as M from"@radix-ui/react-popover";async function it(){try{let e=await Y();if(typeof e?.name=="string"&&e.name)return{name:e.name,avatarUrl:typeof e.avatarUrl=="string"?e.avatarUrl:"",tenantName:""}}catch{}try{let e=await D("/space/api/user/",{headers:{accept:"application/json"}});if(!e.ok)return null;let n=(await e.json()).data;return!n||typeof n.name!="string"||!n.name?null:{name:n.name,avatarUrl:typeof n.avatar_url=="string"?n.avatar_url:"",tenantName:typeof n.tenant_name=="string"?n.tenant_name:""}}catch{return null}}import{Fragment as Zt,jsx as x,jsxs as ke}from"react/jsx-runtime";var Wt={en:{account:"Account",logout:"Log out"},zh:{account:"\u8D26\u53F7",logout:"\u9000\u51FA\u767B\u5F55"},ja:{account:"\u30A2\u30AB\u30A6\u30F3\u30C8",logout:"\u30ED\u30B0\u30A2\u30A6\u30C8"}};function Mo({audience:e="enterprise",align:t="right",side:n="down",showName:o=!0,className:r="",slots:i={}}){let[a,s]=st(null),[c,d]=st(""),u=ae(),p=Wt[P()];if(Yt(()=>{if(e!=="enterprise")return;let m=!0;return Promise.all([it(),J().catch(()=>null)]).then(([v,b])=>{m&&(s(v),d(v?.tenantName||b?.organization||""))}),()=>{m=!1}},[e]),e!=="enterprise"||!a)return null;let h=i.trigger,g=i.organization;return ke(M.Root,{children:[x(M.Trigger,{asChild:!0,children:x("button",{className:`base-app-platform base-app-user-menu ${r}`,"aria-label":p.account,children:h?x(h,{user:a}):ke(Zt,{children:[a.avatarUrl?x("img",{src:a.avatarUrl,alt:"",referrerPolicy:"no-referrer"}):x("span",{children:a.name.slice(0,1)}),o?a.name:null]})})}),x(M.Portal,{children:ke(M.Content,{"data-theme":u?.theme,className:"base-app-platform base-app-popover",align:t==="right"?"end":"start",side:n==="up"?"top":"bottom",sideOffset:8,collisionPadding:8,children:[x("strong",{children:a.name}),g?x(g,{name:c}):x("p",{children:c}),x("button",{onClick:()=>{at(),Pe.clear(),he().catch(()=>{for(let m of["base-site-session","session","sl_session"])document.cookie=`${m}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;window.location.reload()})},children:p.logout})]})})]})}import{useEffect as ce,useRef as ut,useState as z}from"react";import{Command as ee}from"cmdk";import{QueryClient as dn,useQuery as pn}from"@tanstack/react-query";var Xt="/space/api/mention/recommend.v2/",en="8",tn="4",nn="0",on=20,ct={en:{businessError:e=>`Could not search members (error code ${e})`,httpError:e=>`Member search request failed: HTTP ${e}`,invalidResponse:"Member search response has an invalid structure",noBoundBase:"Cannot search members: the application is not bound to a Base"},zh:{businessError:e=>`\u641C\u7D22\u6210\u5458\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${e}\uFF09`,httpError:e=>`\u641C\u7D22\u6210\u5458\u8BF7\u6C42\u5931\u8D25\uFF1AHTTP ${e}`,invalidResponse:"\u6210\u5458\u641C\u7D22\u54CD\u5E94\u7ED3\u6784\u65E0\u6548",noBoundBase:"\u65E0\u6CD5\u641C\u7D22\u6210\u5458\uFF1A\u5E94\u7528\u5C1A\u672A\u7ED1\u5B9A\u591A\u7EF4\u8868\u683C"},ja:{businessError:e=>`\u30E1\u30F3\u30D0\u30FC\u3092\u691C\u7D22\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u30A8\u30E9\u30FC\u30B3\u30FC\u30C9 ${e}\uFF09`,httpError:e=>`\u30E1\u30F3\u30D0\u30FC\u691C\u7D22\u306E\u30EA\u30AF\u30A8\u30B9\u30C8\u306B\u5931\u6557\u3057\u307E\u3057\u305F\uFF1AHTTP ${e}`,invalidResponse:"\u30E1\u30F3\u30D0\u30FC\u691C\u7D22\u306E\u5FDC\u7B54\u5F62\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093",noBoundBase:"\u30E1\u30F3\u30D0\u30FC\u3092\u691C\u7D22\u3067\u304D\u307E\u305B\u3093\uFF1A\u30A2\u30D7\u30EA\u306BBase\u304C\u95A2\u9023\u4ED8\u3051\u3089\u308C\u3066\u3044\u307E\u305B\u3093"}};async function lt(e,t,n){let o=t??B(),r=ct[o],a=(await J()).baseBindings[0]?.baseToken;if(!a)throw new Error(r.noBoundBase);let s=new URLSearchParams({config_source:"0",obj_type:en,source:tn,token:a,type:nn,user_type:"0",content:e.trim().slice(0,50)}).toString(),c=await D(Xt,{signal:n,body:s,headers:{"content-type":"application/x-www-form-urlencoded"},method:"POST"});if(!c.ok)throw new Error(r.httpError(c.status));let d=await c.json();return{code:0,msg:"ok",data:rn(d,o)}}function rn(e,t=B()){let n=Ee(t),o=ct[t],r=an(e,o);if(!r)throw new Error(o.invalidResponse);let i=r.entities,a=k(i)?i.users:void 0;if(!k(a)||!Array.isArray(r.result_list))throw new Error(o.invalidResponse);let s=[],c=new Set;for(let d of r.result_list){if(!k(d)||Number(d.type)!==0)continue;let u=f(d.token);if(!u)continue;let p=a[u];if(!k(p))continue;let h=f(p.user_id)||f(p.id)||u,g=sn(p,n);if(!h||!g||c.has(h))continue;c.add(h);let m=f(p.avatar_url),v=f(p.open_id);if(s.push({avatar:{avatar_72:m,avatar_240:m,avatar_640:m,avatar_origin:m},department_ids:un(p.department_ids),description:cn(p,n),is_external:p.is_external===!0,name:g,user_id:h,...v?{open_id:v}:{}}),s.length>=on)break}return{users:s}}function an(e,t){if(k(e)){if(typeof e.code=="number"&&e.code!==0){let n=f(e.msg);throw Object.assign(new Error(n||t.businessError(e.code)),{code:String(e.code),cause:e})}return"entities"in e&&"result_list"in e?e:k(e.data)?e.data:void 0}}function sn(e,t){let n=e.display_name;if(typeof n=="string"&&n.trim())return n.trim();let o=t.toLowerCase().replace("-","_"),r=o.split("_")[0],i=k(n)?n:{},a=k(i.i18n_value)?i.i18n_value:i,s=r==="zh"?e.cn_name:r==="en"?e.en_name:void 0;return f(a[o])||f(a[r])||f(s)||f(i.value)||f(e.name)||f(e.en_name)||f(e.cn_name)}function cn(e,t){let n=e.is_external===!0?e.i18n_tenant:e.i18n_department;return ln(n,t)||f(e.department)}function ln(e,t){if(typeof e=="string")return e.trim();if(!k(e))return"";let n=t.toLowerCase().replace("-","_"),o=n.split("_")[0]??"",r=k(e.i18n_value)?e.i18n_value:e,i=f(r[n])||f(r[o]);if("i18n_value"in e)return i||f(e.value);let a=o==="zh"?f(r.zh_cn)||f(r.en_us):f(r.en_us)||f(r.zh_cn);return i||f(e.value)||a}function f(e){return typeof e=="string"?e.trim():""}function un(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function k(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}import{Fragment as pt,jsx as R,jsxs as Ae}from"react/jsx-runtime";var mt={en:{invalidResponse:"Member search response has an invalid structure",loading:"Loading...",memberList:"Member list",noMatches:"No matching members. Try another search term.",noRecommendations:"No recommended members yet",recordCreator:"Add the person who created this record",searchFailed:"Member search failed",searchFailedCode:e=>`Could not search members (error code ${e})`,searchMembers:"Search members"},zh:{invalidResponse:"\u6210\u5458\u641C\u7D22\u54CD\u5E94\u7ED3\u6784\u65E0\u6548",loading:"\u52A0\u8F7D\u4E2D...",memberList:"\u6210\u5458\u5217\u8868",noMatches:"\u6CA1\u6709\u5339\u914D\u7684\u6210\u5458\uFF0C\u8BF7\u6362\u4E2A\u5173\u952E\u8BCD",noRecommendations:"\u6682\u65E0\u63A8\u8350\u6210\u5458",recordCreator:"\u6DFB\u52A0\u6B64\u8BB0\u5F55\u7684\u4EBA\u5458",searchFailed:"\u641C\u7D22\u6210\u5458\u5931\u8D25",searchFailedCode:e=>`\u641C\u7D22\u6210\u5458\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${e}\uFF09`,searchMembers:"\u641C\u7D22\u6210\u5458"},ja:{invalidResponse:"\u30E1\u30F3\u30D0\u30FC\u691C\u7D22\u306E\u5FDC\u7B54\u5F62\u5F0F\u304C\u6B63\u3057\u304F\u3042\u308A\u307E\u305B\u3093",loading:"\u8AAD\u307F\u8FBC\u307F\u4E2D...",memberList:"\u30E1\u30F3\u30D0\u30FC\u4E00\u89A7",noMatches:"\u4E00\u81F4\u3059\u308B\u30E1\u30F3\u30D0\u30FC\u304C\u3044\u307E\u305B\u3093\u3002\u5225\u306E\u30AD\u30FC\u30EF\u30FC\u30C9\u3067\u691C\u7D22\u3057\u3066\u304F\u3060\u3055\u3044\u3002",noRecommendations:"\u304A\u3059\u3059\u3081\u306E\u30E1\u30F3\u30D0\u30FC\u304C\u3044\u307E\u305B\u3093",recordCreator:"\u3053\u306E\u30EC\u30B3\u30FC\u30C9\u306E\u4F5C\u6210\u8005\u3092\u8FFD\u52A0",searchFailed:"\u30E1\u30F3\u30D0\u30FC\u306E\u691C\u7D22\u306B\u5931\u6557\u3057\u307E\u3057\u305F",searchFailedCode:e=>`\u30E1\u30F3\u30D0\u30FC\u3092\u691C\u7D22\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F\uFF08\u30A8\u30E9\u30FC\u30B3\u30FC\u30C9 ${e}\uFF09`,searchMembers:"\u30E1\u30F3\u30D0\u30FC\u3092\u691C\u7D22"}};function le(e){let[t,n]=z(!1),[o,r]=z(!1);ce(()=>r(!0),[]);let i=P(),a=mt[i],[s]=z(()=>new dn({defaultOptions:{queries:{retry:!1,staleTime:3e4,gcTime:3e4}}}));ce(()=>{let l=rt(()=>{n(!0),s.clear()});return()=>{l(),s.clear()}},[s]);let c=Object.prototype.hasOwnProperty.call(e,"value"),d=ut(c);ce(()=>{c!==d.current&&console.warn("UserSelectorPanel controlled mode changed")},[c]);let[u,p]=z(e.defaultValue),h=c?e.value:u,g=Array.isArray(h)?h:h?[h]:[],[m,v]=z(""),[b,F]=z(""),[A,K]=z(!1),O=ut(!1);ce(()=>{if(A)return;let l=setTimeout(()=>F(m.trim()),m.trim()?400:0);return()=>clearTimeout(l)},[m,A]);let y=pn({queryKey:["members",i,b],queryFn:async({signal:l})=>{let C=await lt(b,i,l);return mn(C,i)},enabled:!t&&o&&!A&&m.trim()===b},s),w=e.loading||y.isFetching||m.trim()!==b,T=!t&&!w&&!y.error&&y.data?[...y.data.users,...g.filter(l=>!y.data.users.some(C=>C.user_id===l.user_id))]:[],U=(l,C)=>{v(l),e.onSearch?.(l,{action:C})},ue=()=>{U("","AutoClear"),e.onClose?.()},bt=l=>{if(O.current)return;let C=g.some(de=>de.user_id===l.user_id),te=e.mode==="multiple"?C?g.filter(de=>de.user_id!==l.user_id):[...g,l]:C?void 0:l;c||p(te),e.onChange?.(te,{option:l,action:C?"Remove":"Select"}),C||e.onSelect?.(l,{option:l}),e.mode==="multiple"?U("","AutoClear"):ue()},Ie=e.slots?.empty,_e=e.slots?.loading,De=e.slots?.option,Me=e.slots?.footer;return Ae(ee,{shouldFilter:!1,loop:!0,className:`base-app-platform base-app-selector ${e.className??""}`,label:a.memberList,children:[R(ee.Input,{autoFocus:!0,placeholder:a.searchMembers,"aria-label":a.searchMembers,value:m,onValueChange:l=>U(l,"Input"),onCompositionStart:()=>{O.current=!0,K(!0)},onCompositionEnd:()=>{O.current=!1,K(!1)},onKeyDown:l=>{if(e.onKeyDown?.(l),l.defaultPrevented){l.stopPropagation();return}if(O.current||fn(l)){l.stopPropagation();return}l.key==="Escape"&&(l.preventDefault(),ue())}}),R(ee.List,{"aria-label":a.memberList,"aria-multiselectable":e.mode==="multiple"||void 0,children:w?R("div",{role:"status",children:_e?R(_e,{}):a.loading}):y.error?R("div",{role:"alert",children:a.searchFailed}):Ae(pt,{children:[e.onSelectRecordCreator?R(ee.Item,{value:"record-creator",onSelect:()=>{e.onSelectRecordCreator?.(),ue()},children:a.recordCreator}):null,T.map(l=>{let C=g.some(te=>te.user_id===l.user_id);return R(ee.Item,{value:l.user_id,onSelect:()=>bt(l),"data-checked":C,children:De?R(De,{user:l,selected:C}):Ae(pt,{children:[R("span",{children:l.name}),R("small",{children:e.getUserDescription?.(l)??l.description}),C?R("span",{"aria-label":"selected",children:"\u2713"}):null]})},l.user_id)}),!T.length&&!e.onSelectRecordCreator?R("div",{role:"status",children:Ie?R(Ie,{}):m.trim()?a.noMatches:a.noRecommendations}):null]})}),Me?R(Me,{}):null]})}function mn(e,t){let n=mt[t];if(!dt(e)||typeof e.code!="number")throw new Error(n.invalidResponse);if(e.code!==0){let o=typeof e.msg=="string"?e.msg.trim():"";throw Object.assign(new Error(o||n.searchFailedCode(e.code)),{code:String(e.code),cause:e})}if(!dt(e.data)||!Array.isArray(e.data.users))throw new Error(n.invalidResponse);return{users:e.data.users}}function dt(e){return typeof e=="object"&&e!==null}function fn(e){return e.nativeEvent?.isComposing===!0||e.keyCode===229}import{useState as gn,useRef as hn}from"react";import*as L from"@radix-ui/react-popover";import{jsx as _,jsxs as ft}from"react/jsx-runtime";var bn={en:{clearSelected:"Clear selected members",removeMember:e=>`Remove member ${e}`,selectMembers:"Select members"},zh:{clearSelected:"\u6E05\u9664\u5DF2\u9009\u6210\u5458",removeMember:e=>`\u79FB\u9664\u6210\u5458 ${e}`,selectMembers:"\u9009\u62E9\u6210\u5458"},ja:{clearSelected:"\u9078\u629E\u3057\u305F\u30E1\u30F3\u30D0\u30FC\u3092\u30AF\u30EA\u30A2",removeMember:e=>`\u30E1\u30F3\u30D0\u30FC ${e} \u3092\u524A\u9664`,selectMembers:"\u30E1\u30F3\u30D0\u30FC\u3092\u9078\u629E"}};function gt(e){let t=hn(null),n=ae(),o=bn[P()],[r,i]=gn(!1),a=Array.isArray(e.value)?e.value:e.value?[e.value]:[],s=u=>{i(u),u!==r&&e.onDropdownVisibleChange?.(u)},c=e.slots?.trigger,d=e.slots?.chip;return ft(L.Root,{open:r,onOpenChange:s,children:[ft("div",{ref:t,className:`base-app-platform base-app-editor ${e.className??""}`,onClickCapture:u=>{u.target.closest("[data-base-app-trigger]")&&e.onClick?.(u)},children:[_(L.Trigger,{asChild:!0,children:_("button",{type:"button","data-base-app-trigger":"","aria-label":o.selectMembers,onFocus:e.onFocus,onBlur:e.onBlur,children:c?_(c,{value:e.value}):a.length?a.map(u=>_("span",{children:d?_(d,{user:u}):u.name},u.user_id)):o.selectMembers})}),a.map(u=>_("button",{type:"button","aria-label":e.mode==="multiple"?o.removeMember(u.name):o.clearSelected,onClick:p=>{p.stopPropagation(),e.onChange?.(e.mode==="multiple"?a.filter(h=>h.user_id!==u.user_id):void 0),e.mode==="multiple"?e.onRemove?.(u):e.onClear?.()},children:"\xD7"},u.user_id))]}),_(L.Portal,{container:e.portalContainer??t.current?.closest("dialog")??void 0,children:_(L.Content,{"data-theme":n?.theme,className:"base-app-platform base-app-popover",sideOffset:4,collisionPadding:8,children:_(le,{...e,slots:void 0,onChange:(u,p)=>{e.onChange?.(u),p.action==="Remove"&&p.option&&e.onRemove?.(p.option)},onClose:()=>s(!1)})})})]})}import{useEffect as ht,useRef as yn,useState as Te}from"react";import{jsx as q,jsxs as vn}from"react/jsx-runtime";var wn={en:{decodeFailed:"Image could not be decoded",loadFailed:"Failed to load image",loading:"Loading image",retry:"Retry image"},zh:{decodeFailed:"\u56FE\u7247\u65E0\u6CD5\u89E3\u7801",loadFailed:"\u56FE\u7247\u52A0\u8F7D\u5931\u8D25",loading:"\u56FE\u7247\u52A0\u8F7D\u4E2D",retry:"\u91CD\u8BD5\u56FE\u7247"},ja:{decodeFailed:"\u753B\u50CF\u3092\u8868\u793A\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F",loadFailed:"\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u3081\u307E\u305B\u3093\u3067\u3057\u305F",loading:"\u753B\u50CF\u3092\u8AAD\u307F\u8FBC\u307F\u4E2D",retry:"\u753B\u50CF\u3092\u518D\u8AAD\u307F\u8FBC\u307F"}};function ir({attachment:e,size:t=360,alt:n,className:o,slots:r={}}){let i=P(),a=wn[i],s=yn(null),[c,d]=Te(!1),[u,p]=Te(0),[h,g]=Te({key:"",url:"",error:""}),{tableId:m,fieldId:v,recordId:b,fileToken:F}=e,A=JSON.stringify([m,v,b,F,t,u]);ht(()=>{if(typeof IntersectionObserver>"u"){d(!0);return}let w=new IntersectionObserver(T=>{T.some(U=>U.isIntersecting)&&(d(!0),w.disconnect())},{rootMargin:"200px"});return s.current&&w.observe(s.current),()=>w.disconnect()},[]),ht(()=>{if(!c)return;let w=new AbortController,T="";return Ge({tableId:m,fieldId:v,recordId:b,fileToken:F},t,{signal:w.signal}).then(U=>{w.signal.aborted||(T=URL.createObjectURL(U),g({key:A,url:T,error:""}))}).catch(U=>{w.signal.aborted||g({key:A,url:"",error:U instanceof Error?U.message:"",localError:U instanceof Error?void 0:"loadFailed"})}),()=>{w.abort(),T&&URL.revokeObjectURL(T)}},[c,A,m,v,b,F,t]);let K=r.loading,O=r.error,y=h.key===A?h:void 0;return q("span",{ref:s,className:`base-app-platform base-app-attachment ${o??""}`,"aria-busy":!y,children:y?.url?q("img",{src:y.url,alt:n,onError:()=>g({key:A,url:"",error:"",localError:"decodeFailed"})}):y?.error||y?.localError?O?q(O,{code:"ATTACHMENT_LOAD_FAILED",retry:()=>p(w=>w+1)}):vn("span",{children:[q("span",{role:"status",children:y.localError?a[y.localError]:y.error}),q("button",{type:"button",onClick:()=>p(w=>w+1),children:a.retry})]}):q("span",{role:"status",children:K?q(K,{}):a.loading})})}export{En as a,ne as b,Un as c,Sn as d,Pn as e,xn as f,kn as g,$e as h,ge as i,fe as j,jn as k,E as l,oe as m,Bn as n,Y as o,he as p,Ut as q,$n as r,re as s,St as t,D as u,me as v,yt as w,wt as x,In as y,vt as z,Oe as A,be as B,j as C,Ge as D,_t as E,Je as F,Ke as G,qn as H,Vn as I,Gn as J,Jn as K,Re as L,Nt as M,B as N,Ee as O,Bt as P,P as Q,no as R,oo as S,ae as T,Pe as U,vo as V,Mo as W,le as X,gt as Y,ir as Z};
|