@lark-base-open/base-database-app-sdk 0.0.0-stage → 0.0.1-alpha.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/LICENSE +6 -0
- package/README.md +42 -2
- package/capabilities.json +114 -0
- package/development-pairing.json +11 -0
- package/dist/capabilities-56e403e7.d.ts +22 -0
- package/dist/chunk-3JX3FIBG.js +1 -0
- package/dist/chunk-5XIFZ4AH.js +1 -0
- package/dist/chunk-OHPYKFCM.js +1 -0
- package/dist/chunk-ZKBZAK4L.js +1 -0
- package/dist/codegen.cjs +15 -0
- package/dist/codegen.d.cts +43 -0
- package/dist/codegen.d.ts +43 -0
- package/dist/codegen.js +15 -0
- package/dist/components.d.ts +6 -0
- package/dist/components.js +1 -0
- package/dist/index-64557073.d.ts +306 -0
- package/dist/page.d.ts +138 -0
- package/dist/page.js +1 -0
- package/dist/server.cjs +1 -0
- package/dist/server.d.cts +79 -0
- package/dist/server.d.ts +79 -0
- package/dist/server.js +1 -0
- package/dist/shared.cjs +1 -0
- package/dist/shared.d.cts +115 -0
- package/dist/shared.d.ts +115 -0
- package/dist/shared.js +1 -0
- package/dist/testing.d.ts +74 -0
- package/dist/testing.js +1 -0
- package/dist/theme.css +168 -0
- package/dist/vite.d.ts +15 -0
- package/dist/vite.js +3 -0
- package/docs/README.md +16 -0
- package/docs/capabilities.md +42 -0
- package/docs/codegen.md +28 -0
- package/docs/compat.md +36 -0
- package/docs/components.md +34 -0
- package/docs/exports.md +45 -0
- package/docs/page.md +101 -0
- package/docs/server.md +92 -0
- package/docs/shared.md +21 -0
- package/docs/start-base-app.md +47 -0
- package/docs/testing.md +57 -0
- package/docs/upgrade.md +44 -0
- package/examples/capabilities.ts +7 -0
- package/examples/codegen.ts +13 -0
- package/examples/compat.ts +21 -0
- package/examples/components.tsx +11 -0
- package/examples/contract-types.ts +41 -0
- package/examples/development-context.ts +17 -0
- package/examples/http.ts +12 -0
- package/examples/link.ts +10 -0
- package/examples/mock.ts +8 -0
- package/examples/msw.ts +5 -0
- package/examples/page.ts +6 -0
- package/examples/server.ts +57 -0
- package/examples/shared.ts +10 -0
- package/examples/start-base-app.tsx +8 -0
- package/examples/upgrade.ts +7 -0
- package/examples/upload.ts +18 -0
- package/examples/vite.ts +2 -0
- package/package.json +119 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
©Lark Technologies Pte. Ltd. All rights reserved. Use is subject to the Legal Agreements outlined here:
|
|
2
|
+
[Feishu User Terms of Service](https://www.feishu.cn/terms)
|
|
3
|
+
[Feishu Privacy Policy](https://www.feishu.cn/privacy)
|
|
4
|
+
[Feishu Open Platform App Service Provider Security Management Specifications](https://open.feishu.cn/document/uAjLw4CM/uMzNwEjLzcDMx4yM3ATM/management-practice/app-service-provider-security-management-specifications)
|
|
5
|
+
[Lark User Terms of Service](https://www.larksuite.com/user-terms-of-service)
|
|
6
|
+
[Lark Privacy Policy](https://www.larksuite.com/privacy-policy)
|
package/README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lark-base-open/base-database-app-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
用于开发以飞书多维表格为数据后端的 Base Database 应用,提供页面与服务端运行时、平台组件、版本化能力查询与测试工具。
|
|
4
|
+
|
|
5
|
+
安装:`npm install @lark-base-open/base-database-app-sdk@0.0.1-alpha.1`。
|
|
6
|
+
|
|
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.5。
|
|
8
|
+
|
|
9
|
+
server/shared 同时提供 ESM 和 CJS;page/components/testing/vite 仅 ESM。
|
|
10
|
+
|
|
11
|
+
公开入口:`page` 页面 API;`server` [`defineFunction`](docs/exports.md#server) 与 records;`shared` 能力及诊断类型/[`SDKError`](docs/exports.md#page);`testing` 测试宿主与 MSW 工厂。另有 components 平台组件、vite 开发插件及 page/styles.css 样式入口。没有根入口,不支持私有源码路径。
|
|
12
|
+
|
|
13
|
+
文档:[完整索引](docs/README.md)、[导出清单](docs/exports.md)、[page](docs/page.md)、[server(defineFunction / ctx.records / 结果语义)](docs/server.md)、[shared](docs/shared.md)、[testing](docs/testing.md)、[components](docs/components.md)、[start-base-app](docs/start-base-app.md)、[capabilities](docs/capabilities.md)、[compat](docs/compat.md)、[upgrade](docs/upgrade.md)。
|
|
14
|
+
所有示例在 examples/,由 npm test 做编译与文档一致性校验。
|
|
15
|
+
|
|
16
|
+
<!-- example: page.ts -->
|
|
17
|
+
```ts
|
|
18
|
+
import { siteRuntime, installLinkGuard, classifyRuntimeError } from '@lark-base-open/base-database-app-sdk/page';
|
|
19
|
+
export function mountPage() {
|
|
20
|
+
const cleanup = installLinkGuard({ onDiagnostic: diagnostic => console.warn(diagnostic) });
|
|
21
|
+
void siteRuntime.ready().catch(error => console.warn(classifyRuntimeError(error)));
|
|
22
|
+
return cleanup;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`page` 不包含 Node、凭据或 testing;`server/shared` 不含 React、DOM 或 channel 的传递依赖。
|
|
27
|
+
测试需要额外安装可选 peer `msw@2.11.6`。生产只导入 page/server/shared 时不需要 MSW。
|
|
28
|
+
|
|
29
|
+
平台启动与组件:见 [startBaseApp](docs/start-base-app.md) 与 [组件](docs/components.md)。
|
|
30
|
+
|
|
31
|
+
SDK 文档说明本版本 API、组件、兼容语义与可编译示例。业务规则、服务端契约、Mutation 结果、CLI 命令与发布流程,请查阅 [@lark-base-open/base-database-cli](https://www.npmjs.com/package/@lark-base-open/base-database-cli) 随包安装的 lark-base-database Skill 及其 references。升级 CLI 时以该版本随包 Skill 为准。
|
|
32
|
+
|
|
33
|
+
页面类型客户端生成使用 [codegen](docs/codegen.md) 入口;CLI 仅提取契约、隔离调用并写入返回文件。
|
|
34
|
+
|
|
35
|
+
## npm 发布
|
|
36
|
+
|
|
37
|
+
SDK 0.0.1-alpha.1 依赖 channel 0.1.6,其 AI Function 调用需要后端与宿主支持 `functions/:key/invoke`。这两个版本均使用 `next` 标签。
|
|
38
|
+
|
|
39
|
+
先发布 channel 0.1.6,再将 SDK 的依赖锁解析到 registry 制品并运行构建、测试和打包检查。在 SDK 目录执行 `npm publish --tag next --registry=https://registry.npmjs.org/`。
|
|
40
|
+
|
|
41
|
+
后端与宿主上线并完成验收后,由用户执行 `npm dist-tag add @lark-base-open/base-site-channel@0.1.6 latest --registry=https://registry.npmjs.org/` 和 `npm dist-tag add @lark-base-open/base-database-app-sdk@0.0.1-alpha.1 latest --registry=https://registry.npmjs.org/`。使用 `npm view <pkg> dist-tags --json --registry=https://registry.npmjs.org/` 回读标签。
|
|
42
|
+
|
|
43
|
+
SDK 提升为 `latest` 之前,workspace 迁移命令不可用,会报 `SDK_CODEGEN_UNAVAILABLE`;迁移命令只读取 `latest`。
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"sdkVersion": "0.0.1-alpha.1",
|
|
4
|
+
"capabilities": {
|
|
5
|
+
"runtime.context": {
|
|
6
|
+
"required": [
|
|
7
|
+
"site.v1.runtime.context"
|
|
8
|
+
],
|
|
9
|
+
"baseline": true
|
|
10
|
+
},
|
|
11
|
+
"http.request": {
|
|
12
|
+
"required": [
|
|
13
|
+
"site.v1.http.request"
|
|
14
|
+
],
|
|
15
|
+
"baseline": true
|
|
16
|
+
},
|
|
17
|
+
"http.binary": {
|
|
18
|
+
"required": [
|
|
19
|
+
"site.v1.http.request"
|
|
20
|
+
],
|
|
21
|
+
"baseline": true
|
|
22
|
+
},
|
|
23
|
+
"http.cancel": {
|
|
24
|
+
"required": [
|
|
25
|
+
"site.v1.http.request.cancel"
|
|
26
|
+
],
|
|
27
|
+
"baseline": true
|
|
28
|
+
},
|
|
29
|
+
"function.invoke": {
|
|
30
|
+
"required": [
|
|
31
|
+
"site.v1.function.invoke"
|
|
32
|
+
],
|
|
33
|
+
"baseline": true
|
|
34
|
+
},
|
|
35
|
+
"runtime.user": {
|
|
36
|
+
"required": [
|
|
37
|
+
"site.v1.function.invoke",
|
|
38
|
+
"function.runtime.getCurrentUser"
|
|
39
|
+
],
|
|
40
|
+
"baseline": true
|
|
41
|
+
},
|
|
42
|
+
"runtime.logout": {
|
|
43
|
+
"required": [
|
|
44
|
+
"site.v1.function.invoke",
|
|
45
|
+
"function.runtime.logout"
|
|
46
|
+
],
|
|
47
|
+
"baseline": true
|
|
48
|
+
},
|
|
49
|
+
"runtime.requestEdit": {
|
|
50
|
+
"required": [
|
|
51
|
+
"site.v1.function.invoke",
|
|
52
|
+
"function.runtime.requestEdit"
|
|
53
|
+
],
|
|
54
|
+
"baseline": true
|
|
55
|
+
},
|
|
56
|
+
"attachment.upload": {
|
|
57
|
+
"required": [
|
|
58
|
+
"site.v1.attachment.upload"
|
|
59
|
+
],
|
|
60
|
+
"baseline": true
|
|
61
|
+
},
|
|
62
|
+
"attachment.cancel": {
|
|
63
|
+
"required": [
|
|
64
|
+
"site.v1.attachment.upload.cancel"
|
|
65
|
+
],
|
|
66
|
+
"baseline": true
|
|
67
|
+
},
|
|
68
|
+
"chatbot.stream": {
|
|
69
|
+
"required": [
|
|
70
|
+
"site.v1.chatbot.stream.open",
|
|
71
|
+
"site.v1.chatbot.stream.close",
|
|
72
|
+
"site.v1.chatbot.stream.message",
|
|
73
|
+
"site.v1.chatbot.stream.error"
|
|
74
|
+
],
|
|
75
|
+
"baseline": true
|
|
76
|
+
},
|
|
77
|
+
"ai.function.stream": {
|
|
78
|
+
"required": [
|
|
79
|
+
"site.v1.ai.function.stream.open",
|
|
80
|
+
"site.v1.ai.function.stream.close",
|
|
81
|
+
"site.v1.ai.function.stream.message",
|
|
82
|
+
"site.v1.ai.function.stream.error",
|
|
83
|
+
"site.v1.ai.function.stream.done"
|
|
84
|
+
],
|
|
85
|
+
"baseline": true
|
|
86
|
+
},
|
|
87
|
+
"runtime.lifecycle": {
|
|
88
|
+
"required": [
|
|
89
|
+
"site.v1.lifecycle.ready",
|
|
90
|
+
"site.v1.lifecycle.load-failed"
|
|
91
|
+
],
|
|
92
|
+
"baseline": true
|
|
93
|
+
},
|
|
94
|
+
"runtime.mode": {
|
|
95
|
+
"required": [
|
|
96
|
+
"site.v1.runtime.mode-changed"
|
|
97
|
+
],
|
|
98
|
+
"baseline": true
|
|
99
|
+
},
|
|
100
|
+
"attachment.progress": {
|
|
101
|
+
"required": [
|
|
102
|
+
"site.v1.attachment.upload",
|
|
103
|
+
"site.v1.attachment.upload.progress"
|
|
104
|
+
],
|
|
105
|
+
"baseline": true
|
|
106
|
+
},
|
|
107
|
+
"link.open": {
|
|
108
|
+
"required": [
|
|
109
|
+
"site.v1.link.open"
|
|
110
|
+
],
|
|
111
|
+
"baseline": true
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tokenEnv": "BASE_APP_DEV_PAIRING_TOKEN",
|
|
3
|
+
"endpoint": "/__base_app/dev-pair",
|
|
4
|
+
"proofPrefix": "base-app-dev-pair.v1",
|
|
5
|
+
"pairApi": "site.v1.development.pair",
|
|
6
|
+
"pairedEvent": "site.v1.development.paired",
|
|
7
|
+
"host": "127.0.0.1",
|
|
8
|
+
"portMin": 43100,
|
|
9
|
+
"portMax": 43109,
|
|
10
|
+
"secretBytes": 32
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SiteRuntimeContext as SiteRuntimeContext$1 } from '@lark-base-open/base-site-channel/runtime';
|
|
2
|
+
import { CapabilityContext, RuntimeCapabilities, CapabilityQueryResult } from './shared.js';
|
|
3
|
+
|
|
4
|
+
/** 仅独立开发入口提供;不含身份凭据或服务端会话。 */
|
|
5
|
+
type SiteRuntimeContext = SiteRuntimeContext$1 & CapabilityContext & {
|
|
6
|
+
development?: {
|
|
7
|
+
localOrigin: string;
|
|
8
|
+
projectEnv: "preview";
|
|
9
|
+
artifactVersion: string | null;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
interface RuntimeContextReader {
|
|
13
|
+
getRuntimeContext(): Promise<SiteRuntimeContext>;
|
|
14
|
+
}
|
|
15
|
+
declare function readCapabilities(context: CapabilityContext): RuntimeCapabilities;
|
|
16
|
+
declare function hasCapability(context: CapabilityContext, name: string, minimumVersion?: number): boolean;
|
|
17
|
+
declare function getCapabilities(runtime?: RuntimeContextReader): Promise<RuntimeCapabilities>;
|
|
18
|
+
declare const getRuntimeCapabilities: typeof getCapabilities;
|
|
19
|
+
declare function queryCapability(name: string, minVersion?: number, runtime?: RuntimeContextReader): Promise<CapabilityQueryResult>;
|
|
20
|
+
declare function requireCapability(name: string, minVersion?: number, runtime?: RuntimeContextReader): Promise<void>;
|
|
21
|
+
|
|
22
|
+
export { RuntimeContextReader as R, SiteRuntimeContext as S, getRuntimeCapabilities as a, requireCapability as b, getCapabilities as g, hasCapability as h, queryCapability as q, readCapabilities as r };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=Symbol.for("@lark-base-open/base-database-app-sdk/SDKError/v1"),t=class extends Error{constructor(e,n,o,s){super(n);this.code=e;this.name="SDKError",this.safeMessage=n;let r=typeof o=="object"?o:{};this.upstreamCode=typeof o=="string"?o:void 0,this.wireCode=Number.isSafeInteger(r.wireCode)&&r.wireCode!==0?r.wireCode:e==="SDK_TIMEOUT"?504:e==="SDK_CANCELLED"?499:e==="SDK_INPUT_INVALID"?400:500,this.retryable=r.retryable??s??!1,this.outcome=r.outcome??"failed",this.paths=r.paths??[]}[a]=!0;static[Symbol.hasInstance](e){return this!==t?Function.prototype[Symbol.hasInstance].call(this,e):e!==null&&typeof e=="object"&&e[a]===!0}wireCode;safeMessage;retryable;outcome;paths;upstreamCode};export{t as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as Me,b as Q,c as Oe}from"./chunk-ZKBZAK4L.js";import{a as pe}from"./chunk-3JX3FIBG.js";import{a as F}from"./chunk-OHPYKFCM.js";import{createContext as Ht,useContext as Xe}from"react";import{createContext as It,useContext as Mt,useEffect as Ot,useSyncExternalStore as Ft}from"react";import{capabilityNames as Rt}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 An}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(Me).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 wt(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 vt(e=E){return me(await e.getRuntimeContext())}var _n=vt;async function Ct(e,t=1,n=E){let o=await n.getRuntimeContext(),r=me(o),s=wt(o,e,t),a=o.capabilityUnavailable;if(a!==void 0&&(!a||typeof a!="object"||Array.isArray(a)))return V();let i=a&&Object.prototype.hasOwnProperty.call(a,e)?a[e]:void 0;return i!==void 0&&(!i||typeof i!="object"||!["permission-denied","region-unavailable","temporarily-unavailable"].includes(i.reason)||typeof i.retryable!="boolean")?V():{name:e,requiredVersion:t,version:Object.prototype.hasOwnProperty.call(r,e)?r[e].version:null,supported:s,source:o.capabilities===void 0?"host-baseline":"advertised",availability:s?i?.reason??"unknown":"unsupported"}}async function Fe(e,t=1,n=E){let o=await n.getRuntimeContext(),r=await Ct(e,t,{getRuntimeContext:async()=>o});if(!r.supported)throw new Oe(e,t);let s={"permission-denied":Q.PermissionDenied,"region-unavailable":Q.RegionUnavailable,"temporarily-unavailable":Q.TemporarilyUnavailable};if(r.availability in s)throw new pe(s[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,s=new Promise(a=>{r=a});return e.registerApi(F.pairApi,async a=>{if(!a||!/^[A-Za-z0-9_-]{43}$/.test(a.challenge))throw new Error("INVALID_PAIRING_CHALLENGE");n=a.challenge;let i=n;o&&(o=!1,s=new Promise(u=>{r=u}));let c=await t(F.endpoint,{method:"POST",credentials:"omit",cache:"no-store",redirect:"error",headers:{"Content-Type":"application/json"},body:JSON.stringify({challenge:i})});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(F.pairedEvent,a=>{n&&a?.challenge===n&&(o=!0,r())}),{reset:()=>{n=void 0,o&&(o=!1,s=new Promise(a=>{r=a}))},wait:async()=>{let a;do a=s,await a;while(a!==s)}}}var je=typeof window<"u"&&window.location.protocol==="http:"&&window.location.hostname===F.host&&Number(window.location.port)>=F.portMin&&Number(window.location.port)<=F.portMax;var $e=S.siteRuntime,T=$e.getChannel?.()??$e.channel,Et=je&&typeof window<"u"&&window.parent!==window?Ne(T,globalThis.fetch.bind(globalThis)):void 0;function Be(e,t=async()=>{}){let n=new Map,o=async(r,s)=>{await t();for(let a of Rt(r,s))try{await Fe(a,1,{getRuntimeContext:()=>e.invokeApi(ne.RuntimeContext,void 0)})}catch(i){throw i instanceof Error&&"code"in i?Object.assign(new S.SiteRuntimeInvocationError(String(i.code),i.message),i):i}};return{subscribeEvent:(r,s)=>e.subscribeEvent(r,s),emitEvent:async(r,s)=>(await o(r,s),e.emitEvent(r,s)),invokeApi:async(r,s,a)=>{let i=s?.requestId??s?.subscriptionId??s?.uploadId,c=r===ne.HttpRequestCancel||r===ne.AttachmentUploadCancel||r.endsWith(".close");if(c&&i&&n.has(i)){n.get(i).canceled=!0;return}let d={canceled:!1};!c&&i&&n.set(i,d);try{if(await o(r,s),d.canceled)throw new DOMException("The operation was aborted","AbortError");return i&&n.delete(i),await e.invokeApi(r,s,a)}finally{i&&n.get(i)===d&&n.delete(i)}}}}var Ut={invokeApi:T.invokeApi.bind(T),emitEvent:T.emitEvent.bind(T),subscribeEvent:T.subscribeEvent.bind(T)},ge=Be(Ut,async()=>{if(typeof window<"u"&&window.parent===window)throw new S.SiteRuntimeInvocationError("CHANNEL_UNAVAILABLE","\u9875\u9762\u672A\u8FDE\u63A5\u5BBF\u4E3B channel");await Et?.wait()});T.invokeApi=ge.invokeApi;T.emitEvent=ge.emitEvent;var fe=class extends S.SiteRuntimeClient{constructor(t){super(t?Be(t):ge)}},jn=e=>new fe(e),E=S.siteRuntime,{invokeHttp:oe,invokeApi:$n,getCurrentUser:Y,logout:he,requestEdit:St,uploadAttachment:Bn,openLink:re}=E,Pt=(e=E,t)=>S.createSiteRuntimeFetch(e,t),L=Pt();var xt=oe,At=/^\/?(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 Tt(){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=At.exec(e),n=Tt();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 _t(e){return e===G||e==="prod"}function Lt(e){if(!Z(e))return{};let t=typeof e.siteToken=="string"?e.siteToken.trim():"";return{...t?{token:t}:{},..._t(e.env)?{env:e.env}:{}}}async function N(){return W||(W=(async()=>{let e=be(),t={};try{t=Lt(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 N();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,s=new URLSearchParams({extra:qe(o,e),width:String(r),height:String(r),policy:"allow_up",fallback_source:"1"}),a=await xt({url:`/space/api/box/stream/download/v2/cover/${encodeURIComponent(e.fileToken)}?${s}`,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 i=await a.blob();if(!i.size||!i.type.startsWith("image/"))throw new Error("The host did not return a valid image");return i}async function Dt(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 L(kt,{body:JSON.stringify({extra:qe(e,t),file_token:t.fileToken}),headers:{"content-type":"application/json"},method:"POST"}).catch(i=>{throw Ve("Attachment download URL request",i)}),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 s=Z(r)?r.code:void 0;if(typeof s=="number"&&s!==0||typeof s=="string"&&s.trim()!==""&&s.trim()!=="0"){let i=new Error(`Attachment service could not provide a download URL (code ${String(s)}${o?`, LogID ${o}`:""})`);throw Object.assign(i,{code:String(s),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 N();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 N();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 Dt(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(s=>s>=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=It(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 Nt(){return typeof navigator>"u"?void 0:navigator.language}function jt(e,t){return Ce(e)??Ce(t)??"en"}function j(){return We??jt(void 0,Nt())}function Ee(e=j()){return Ye.find(({id:t})=>t===e)?.locale??"en-US"}function $t(e){return ve.add(e),()=>ve.delete(e)}function Qe(e){We=Ce(e);let t=j();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(j()),we=E.getRuntimeContext().then(e=>Qe(e?.locale)).catch(()=>Qe(void 0))),we}function P(){let e=Mt(Re),t=Ft($t,j,()=>"en");return Ot(()=>{e||Bt()},[e]),e??t}import{jsx as Ue}from"react/jsx-runtime";var Se=Ht(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 zt}from"@tanstack/react-query";var Pe=new zt({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 qt(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function $(){return{baseBindings:[],name:"",description:"",isOwner:!1,allowEdit:!1,organization:""}}function Vt(){let e=document.querySelector('meta[name="description"]');return e instanceof HTMLMetaElement?e:null}function Gt(e){if(e.name&&(document.title=e.name),e.description){let t=Vt();t&&(t.content=e.description)}}function Jt(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:qt(n.tableIds)}),t},[]):[]}function Kt(e){if(!ie(e)||e.code!==0)return $();let t=e.data;if(!ie(t))return $();let n=t.site;return ie(n)?{baseBindings:Jt(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 L(Je(e),{method:"GET"});if(!t.ok)return $();let n=await t.json(),o=Kt(n);return Gt(o),o}catch{return $()}}async function J(){let e=await N();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 Qt="https://feishu.cn/base/site/detail/overview";async function tt(){try{await E.requestEdit();return}catch{let{token:e}=await N(),t=new URL(Qt);if(t.searchParams.set("token",e),!(await re(t.toString())).opened)throw new Error("Management page was not opened")}}import{jsx as B,jsxs as ot}from"react/jsx-runtime";var Yt={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=Yt[P()],[r,s]=X(!1),[a,i]=X(!1),[c,d]=X(!1),[u,p]=X(!1),[g,f]=X(!1);nt(()=>{let b=!0;return J().then(M=>{b&&s(M.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,B("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?B("div",{role:"alert",children:o.openFailed}):null,g?B("div",{role:"tooltip",children:v?B(v,{text:o.editSite}):o.editSite}):null,B("button",{"aria-label":o.editSite,onFocus:()=>f(!0),onBlur:()=>f(!1),onMouseEnter:()=>f(!0),onMouseLeave:()=>f(!1),onClick:()=>{p(!1),tt().catch(()=>p(!0))},children:m?B(m,{}):"\u270E"}),B("button",{"aria-label":o.hidePanel,onClick:()=>{i(!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 Wt,useState as st}from"react";import*as D 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 L("/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 Xt,jsx as x,jsxs as Ae}from"react/jsx-runtime";var Zt={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 Io({audience:e="enterprise",align:t="right",side:n="down",showName:o=!0,className:r="",slots:s={}}){let[a,i]=st(null),[c,d]=st(""),u=ae(),p=Zt[P()];if(Wt(()=>{if(e!=="enterprise")return;let m=!0;return Promise.all([it(),J().catch(()=>null)]).then(([v,b])=>{m&&(i(v),d(v?.tenantName||b?.organization||""))}),()=>{m=!1}},[e]),e!=="enterprise"||!a)return null;let g=s.trigger,f=s.organization;return Ae(D.Root,{children:[x(D.Trigger,{asChild:!0,children:x("button",{className:`base-app-platform base-app-user-menu ${r}`,"aria-label":p.account,children:g?x(g,{user:a}):Ae(Xt,{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(D.Portal,{children:Ae(D.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}),f?x(f,{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 dt,useState as z}from"react";import{Command as ee}from"cmdk";import{QueryClient as dn,useQuery as pn}from"@tanstack/react-query";var en="/space/api/mention/recommend.v2/",tn="8",nn="4",on="0",rn=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??j(),r=ct[o],a=(await J()).baseBindings[0]?.baseToken;if(!a)throw new Error(r.noBoundBase);let i=new URLSearchParams({config_source:"0",obj_type:tn,source:nn,token:a,type:on,user_type:"0",content:e.trim().slice(0,50)}).toString(),c=await L(en,{signal:n,body:i,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:an(d,o)}}function an(e,t=j()){let n=Ee(t),o=ct[t],r=sn(e,o);if(!r)throw new Error(o.invalidResponse);let s=r.entities,a=H(s)?s.users:void 0;if(!H(a)||!Array.isArray(r.result_list))throw new Error(o.invalidResponse);let i=[],c=new Set;for(let d of r.result_list){if(!H(d)||Number(d.type)!==0)continue;let u=h(d.token);if(!u)continue;let p=a[u];if(!H(p))continue;let g=h(p.user_id)||h(p.id)||u,f=cn(p,n);if(!g||!f||c.has(g))continue;c.add(g);let m=h(p.avatar_url),v=h(p.open_id);if(i.push({avatar:{avatar_72:m,avatar_240:m,avatar_640:m,avatar_origin:m},department_ids:un(p.department_ids),description:ln(p,n),is_external:p.is_external===!0,name:f,user_id:g,...v?{open_id:v}:{}}),i.length>=rn)break}return{users:i}}function sn(e,t){if(H(e)){if(typeof e.code=="number"&&e.code!==0){let n=h(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:H(e.data)?e.data:void 0}}function cn(e,t){return ut(e.display_name,t)||(t.toLowerCase().startsWith("zh")?h(e.cn_name):h(e.en_name))||h(e.name)||h(e.en_name)||h(e.cn_name)}function ln(e,t){let n=e.is_external===!0?e.i18n_tenant:e.i18n_department;return ut(n,t)||h(e.department)}function ut(e,t){if(typeof e=="string")return e.trim();if(!H(e))return"";let n=t.toLowerCase().replace("-","_"),o=n.split("_")[0]??"",r=o==="zh"?h(e.zh_cn)||h(e.en_us):h(e.en_us)||h(e.zh_cn);return h(e[n])||h(e[o])||r}function h(e){return typeof e=="string"?e.trim():""}function un(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}function H(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}import{Fragment as mt,jsx as R,jsxs as ke}from"react/jsx-runtime";var ft={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 s=P(),a=ft[s],[i]=z(()=>new dn({defaultOptions:{queries:{retry:!1,staleTime:3e4,gcTime:3e4}}}));ce(()=>{let l=rt(()=>{n(!0),i.clear()});return()=>{l(),i.clear()}},[i]);let c=Object.prototype.hasOwnProperty.call(e,"value"),d=dt(c);ce(()=>{c!==d.current&&console.warn("UserSelectorPanel controlled mode changed")},[c]);let[u,p]=z(e.defaultValue),g=c?e.value:u,f=Array.isArray(g)?g:g?[g]:[],[m,v]=z(""),[b,M]=z(""),[A,K]=z(!1),O=dt(!1);ce(()=>{if(A)return;let l=setTimeout(()=>M(m.trim()),m.trim()?400:0);return()=>clearTimeout(l)},[m,A]);let y=pn({queryKey:["members",s,b],queryFn:async({signal:l})=>{let C=await lt(b,s,l);return mn(C,s)},enabled:!t&&o&&!A&&m.trim()===b},i),w=e.loading||y.isFetching||m.trim()!==b,k=!t&&!w&&!y.error&&y.data?[...y.data.users,...f.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?.()},yt=l=>{if(O.current)return;let C=f.some(de=>de.user_id===l.user_id),te=e.mode==="multiple"?C?f.filter(de=>de.user_id!==l.user_id):[...f,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()},_e=e.slots?.empty,Le=e.slots?.loading,De=e.slots?.option,Ie=e.slots?.footer;return ke(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:Le?R(Le,{}):a.loading}):y.error?R("div",{role:"alert",children:a.searchFailed}):ke(mt,{children:[e.onSelectRecordCreator?R(ee.Item,{value:"record-creator",onSelect:()=>{e.onSelectRecordCreator?.(),ue()},children:a.recordCreator}):null,k.map(l=>{let C=f.some(te=>te.user_id===l.user_id);return R(ee.Item,{value:l.user_id,onSelect:()=>yt(l),"data-checked":C,children:De?R(De,{user:l,selected:C}):ke(mt,{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)}),!k.length&&!e.onSelectRecordCreator?R("div",{role:"status",children:_e?R(_e,{}):m.trim()?a.noMatches:a.noRecommendations}):null]})}),Ie?R(Ie,{}):null]})}function mn(e,t){let n=ft[t];if(!pt(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(!pt(e.data)||!Array.isArray(e.data.users))throw new Error(n.invalidResponse);return{users:e.data.users}}function pt(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 I from"@radix-ui/react-popover";import{jsx as _,jsxs as gt}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 ht(e){let t=hn(null),n=ae(),o=bn[P()],[r,s]=gn(!1),a=Array.isArray(e.value)?e.value:e.value?[e.value]:[],i=u=>{s(u),u!==r&&e.onDropdownVisibleChange?.(u)},c=e.slots?.trigger,d=e.slots?.chip;return gt(I.Root,{open:r,onOpenChange:i,children:[gt("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:[_(I.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(g=>g.user_id!==u.user_id):void 0),e.mode==="multiple"?e.onRemove?.(u):e.onClear?.()},children:"\xD7"},u.user_id))]}),_(I.Portal,{container:e.portalContainer??t.current?.closest("dialog")??void 0,children:_(I.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:()=>i(!1)})})})]})}import{useEffect as bt,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 s=P(),a=wn[s],i=yn(null),[c,d]=Te(!1),[u,p]=Te(0),[g,f]=Te({key:"",url:"",error:""}),{tableId:m,fieldId:v,recordId:b,fileToken:M}=e,A=JSON.stringify([m,v,b,M,t,u]);bt(()=>{if(typeof IntersectionObserver>"u"){d(!0);return}let w=new IntersectionObserver(k=>{k.some(U=>U.isIntersecting)&&(d(!0),w.disconnect())},{rootMargin:"200px"});return i.current&&w.observe(i.current),()=>w.disconnect()},[]),bt(()=>{if(!c)return;let w=new AbortController,k="";return Ge({tableId:m,fieldId:v,recordId:b,fileToken:M},t,{signal:w.signal}).then(U=>{w.signal.aborted||(k=URL.createObjectURL(U),f({key:A,url:k,error:""}))}).catch(U=>{w.signal.aborted||f({key:A,url:"",error:U instanceof Error?U.message:"",localError:U instanceof Error?void 0:"loadFailed"})}),()=>{w.abort(),k&&URL.revokeObjectURL(k)}},[c,A,m,v,b,M,t]);let K=r.loading,O=r.error,y=g.key===A?g:void 0;return q("span",{ref:i,className:`base-app-platform base-app-attachment ${o??""}`,"aria-busy":!y,children:y?.url?q("img",{src:y.url,alt:n,onError:()=>f({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,An as g,Be as h,ge as i,fe as j,jn as k,E as l,oe as m,$n as n,Y as o,he as p,St as q,Bn as r,re as s,Pt as t,L as u,me as v,wt as w,vt as x,_n as y,Ct as z,Fe as A,be as B,N as C,Ge as D,Dt as E,Je as F,Ke as G,qn as H,Vn as I,Gn as J,Jn as K,Re as L,jt as M,j 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,Io as W,le as X,ht as Y,ir as Z};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i={tokenEnv:"BASE_APP_DEV_PAIRING_TOKEN",endpoint:"/__base_app/dev-pair",proofPrefix:"base-app-dev-pair.v1",pairApi:"site.v1.development.pair",pairedEvent:"site.v1.development.paired",host:"127.0.0.1",portMin:43100,portMax:43109,secretBytes:32};export{i as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r}from"./chunk-3JX3FIBG.js";import{CAPABILITY_CATALOG as u}from"@lark-base-open/base-site-channel/capabilities";var e={HostUnsupported:"CAPABILITY_HOST_UNSUPPORTED",PermissionDenied:"CAPABILITY_PERMISSION_DENIED",RegionUnavailable:"CAPABILITY_REGION_UNAVAILABLE",TemporarilyUnavailable:"CAPABILITY_TEMPORARILY_UNAVAILABLE",ContextInvalid:"CAPABILITY_CONTEXT_INVALID",UnavailableUnknown:"CAPABILITY_UNAVAILABLE_UNKNOWN"},s=class extends r{constructor(o,a){super(e.HostUnsupported,`\u5F53\u524D\u5BBF\u4E3B\u4E0D\u652F\u6301 ${o} v${a}`);this.capability=o;this.minimumVersion=a;this.name="CapabilityUnavailableError"}};function y(t){let i=t&&typeof t=="object"?t:{},o=typeof i.code=="string"||typeof i.code=="number"?String(i.code):"UNKNOWN",a=e.UnavailableUnknown,n="unknown";[e.HostUnsupported,"10004","PROTOCOL_MISMATCH","ATTACHMENT_UNAVAILABLE","HTTP_RESPONSE_TYPE_UNSUPPORTED"].includes(o)?(a=e.HostUnsupported,n="host-unsupported"):[e.PermissionDenied,"403","PERMISSION_DENIED","FORBIDDEN","FUNCTION_NOT_ALLOWED"].includes(o)?(a=e.PermissionDenied,n="permission-denied"):[e.RegionUnavailable,"REGION_UNAVAILABLE","REGION_NOT_SUPPORTED"].includes(o)?(a=e.RegionUnavailable,n="region-unavailable"):[e.TemporarilyUnavailable,"REQUEST_TIMEOUT","10003","10005","HTTP_REQUEST_FAILED","FUNCTION_REQUEST_FAILED","STREAM_DISCONNECTED","STREAM_HEALTH_TIMEOUT","ATTACHMENT_UPLOAD_STALLED"].includes(o)?(a=e.TemporarilyUnavailable,n="temporary"):o===e.ContextInvalid&&(a=e.ContextInvalid,n="protocol");let l={"host-unsupported":"\u5F53\u524D\u5BBF\u4E3B\u4E0D\u652F\u6301\u6B64\u80FD\u529B","permission-denied":"\u5F53\u524D\u8EAB\u4EFD\u6216\u53D1\u5E03\u6E05\u5355\u4E0D\u5141\u8BB8\u6B64\u64CD\u4F5C","region-unavailable":"\u5BBF\u4E3B\u660E\u786E\u5F53\u524D\u533A\u57DF\u4E0D\u53EF\u7528",temporary:"\u8C03\u7528\u6682\u65F6\u5931\u8D25\uFF0C\u8BF7\u6838\u5BF9\u7ED3\u679C\u540E\u51B3\u5B9A\u662F\u5426\u91CD\u8BD5",protocol:"\u5BBF\u4E3B\u80FD\u529B\u5B57\u6BB5\u65E0\u6548",unknown:"\u8C03\u7528\u5931\u8D25\uFF0C\u539F\u56E0\u672A\u660E\u786E"};return{source:"sdk",code:a,upstreamCode:i.upstreamCode??o,category:n,retryable:n==="temporary"&&i.retryable!==!1,message:l[n],redaction:"\u539F\u59CB\u9519\u8BEF\u6D88\u606F\u548C\u4E1A\u52A1\u53C2\u6570\u5DF2\u7701\u7565"}}export{u as a,e as b,s as c,y as d};
|
package/dist/codegen.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";var A=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var R=(n,e)=>{for(var s in e)A(n,s,{get:e[s],enumerable:!0})},E=(n,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of F(e))!$.call(n,t)&&t!==s&&A(n,t,{get:()=>e[t],enumerable:!(i=k(e,t))||i.enumerable});return n};var x=n=>E(A({},"__esModule",{value:!0}),n);var J={};R(J,{CodegenError:()=>d,SUPPORTED_CONTRACT_FORMAT_VERSIONS:()=>M,generateFunctionClients:()=>G,validateContractData:()=>C});module.exports=x(J);var h=require("json-schema-to-typescript");function g(n){if(!n||typeof n!="object"||Array.isArray(n)||Buffer.byteLength(JSON.stringify(n))>32768)throw new Error("CONTRACT_SCHEMA_BUDGET");let e=0,s=(i,t)=>{if(!(!i||typeof i!="object")){if(++e>256||t>16)throw new Error("CONTRACT_SCHEMA_BUDGET");if(Array.isArray(i))i.forEach(r=>s(r,t+1));else for(let[r,a]of Object.entries(i)){if(r==="$ref"&&(typeof a!="string"||!a.startsWith("#/")))throw new Error("CONTRACT_EXTERNAL_REF");if(["$id","$dynamicRef","$recursiveRef","tsType","tsEnumNames"].includes(r))throw new Error("CONTRACT_EXTERNAL_REF");s(a,t+1)}}};s(n,0)}var y="@lark-base-open/base-database-app-sdk/page",l=`/* Generated by base-database-cli. Do not edit. */
|
|
2
|
+
import type { DatabaseFunctionInputMap as GeneratedInputMap } from './database-function-inputs.generated';
|
|
3
|
+
import '${y}';
|
|
4
|
+
declare module '${y}' { interface FunctionInputMap extends GeneratedInputMap {} }
|
|
5
|
+
`,w=`/* Generated by base-database-cli. Map is declared in ../generated/functions. */
|
|
6
|
+
export {};
|
|
7
|
+
`;async function N(n,e,s="../lib/database-function-inputs.generated"){let i=["/* Generated by base-database-cli. Runtime validation remains authoritative. */",`import { invokeDatabaseFunction } from '${y}';`,"import { SDKError } from '@lark-base-open/base-database-app-sdk/shared';",`import type { DatabaseFunctionInputMap as GeneratedFunctionInputs } from ${JSON.stringify(s)};`,`export const contract = ${JSON.stringify({version:1,schemaHash:e,remoteContractMatch:"unknown"})} as const;`],t=[];for(let[r,a]of[...n].sort((o,c)=>o.functionId.localeCompare(c.functionId)).entries()){let o=`Function${r}Input`,c=`Function${r}Output`;i.push(`export type ${o} = GeneratedFunctionInputs[${JSON.stringify(a.functionId)}];`);let u=a.functionType===2?a.output:void 0;if(!u)i.push(`export type ${c} = unknown;`);else{g(u);try{i.push(await(0,h.compile)(_(u,c),c,{bannerComment:"",customName:(m,O)=>m.title===c?c:m.title||O?`${c}_${m.title||O}`:void 0,unknownAny:!0,additionalProperties:!0,$refOptions:{resolve:{http:!1,file:!1}}}))}catch{i.push(`// Schema could not be represented; no precision is claimed.
|
|
8
|
+
export type ${c} = unknown;`)}}t.push(` [${JSON.stringify(a.functionId)}]: async (input: ${o}): Promise<${c}> => {
|
|
9
|
+
const response = await invokeDatabaseFunction<${c}>(${JSON.stringify(a.functionId)}, input);
|
|
10
|
+
if (!response || !Number.isSafeInteger(response.code)) throw new SDKError('FUNCTION_RESPONSE_INVALID', 'Invalid Function response', {outcome:'unknown'});
|
|
11
|
+
if (response.code !== 0) throw new SDKError('FUNCTION_INVOKE_FAILED', 'Function invocation failed', String(response.code));
|
|
12
|
+
return response.data as ${c};
|
|
13
|
+
},`)}return i.push(`declare module '${y}' { interface FunctionInputMap extends GeneratedFunctionInputs {} }`,"export const functions = {",...t,"};",""),i.join(`
|
|
14
|
+
`)}function _(n,e){let s=structuredClone(n),i=t=>{if(!t||typeof t!="object")return;if(Array.isArray(t)){t.forEach(i);return}let r=t;Object.values(r).forEach(i),Array.isArray(r.prefixItems)&&(r.additionalItems=r.items??r.maxItems!==r.prefixItems.length,r.items=r.prefixItems,delete r.prefixItems)};return i(s),s.title=e,s}function p(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function b(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(b).join(", ")}]`:p(n)?`{ ${Object.entries(n).map(([e,s])=>`${JSON.stringify(e)}: ${b(s)}`).join("; ")} }`:"never"}function j(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 p(n);default:return!1}}function D(n){return typeof n.type=="string"?[n.type]:Array.isArray(n.type)?n.type.filter(e=>typeof e=="string"):[]}function P(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 s=n.prefixItems,i=Array.isArray(s),t=i?s.filter(p):[];if(i&&n.minItems===t.length&&n.maxItems===t.length)return`[${t.map(f).join(", ")}]`;let r=p(n.items)?f(n.items):"unknown";return t.length===0?`Array<${r}>`:`[${[...t.map(o=>`${f(o)}?`),`...Array<${r}>`].join(", ")}]`}case"object":{let s=p(n.properties)?n.properties:{},i=new Set(Array.isArray(n.required)?n.required.filter(u=>typeof u=="string"):[]),t=Object.entries(s).filter(u=>p(u[1])),r=new Set(t.map(([u])=>u)),a=[...i].filter(u=>!r.has(u));if(a.length>0&&n.additionalProperties===!1)return"never";let o=t.map(([u,m])=>`${JSON.stringify(u)}${i.has(u)?"":"?"}: ${f(m)}`);o.push(...a.map(u=>`${JSON.stringify(u)}: unknown`));let c=`{ ${o.join("; ")} }`;return n.additionalProperties===!1?o.length===0?"Record<string, never>":c:`${c} & Record<string, unknown>`}default:return"unknown"}}function f(n){let e=["anyOf","oneOf","allOf"].filter(t=>Array.isArray(n[t]));if(e.length){let t={...n};for(let o of e)delete t[o];let r=e.map(o=>{let c=n[o].filter(p).map(f);return c.length?c.map(u=>`(${u})`).join(o==="allOf"?" & ":" | "):"never"}),a=f(t);return a!=="unknown"&&r.unshift(a),r.map(o=>`(${o})`).join(" & ")}if(Object.hasOwn(n,"const"))return b(n.const);let s=D(n);if(Array.isArray(n.enum)&&n.enum.length>0){let t=n.enum.filter(r=>s.length===0||s.some(a=>j(r,a)));return t.length===0?"never":t.map(b).join(" | ")}let i=[...new Set(s.map(t=>P(n,t)))];return i.length===0?"unknown":i.join(" | ")}function T(n){let e=[...n].sort((t,r)=>t.functionId<r.functionId?-1:t.functionId>r.functionId?1:0),s=e.map(t=>` ${JSON.stringify(t.functionId)}: ${f(t.inputSchema)}`),i=e.flatMap(t=>{let r=Object.entries(t.parameterOptions??{});return r.length===0?[]:[` ${JSON.stringify(t.functionId)}: {`,...r.map(([a,o])=>` ${JSON.stringify(a)}: ${JSON.stringify(o)},`)," },"]});return["/* Generated by base-database-cli from Function metadata. Do not edit. */","// prettier-ignore","export type DatabaseFunctionInputMap = {",...s,"}",...i.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 = {",...i,"} as const"]:[],""].join(`
|
|
15
|
+
`)}var M=[1],d=class extends Error{constructor(s,i){super(i);this.code=s;this.name="CodegenError"}toJSON(){return{code:this.code,message:this.message}}},S=l.replace("./database-function-inputs.generated","../generated/function-inputs"),I=n=>!!n&&typeof n=="object"&&!Array.isArray(n);function C(n){if(!I(n)||n.contractFormatVersion!==1)throw new d("CONTRACT_FORMAT_UNSUPPORTED","Supported contractFormatVersion: 1");let e=()=>{throw new d("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 s;try{s=JSON.stringify(n)}catch{return e()}Buffer.byteLength(s)>4*1024*1024&&e();for(let t of["functions","inputs"]){let r=n[t];if(!Array.isArray(r)||r.length>1e3)return e();let a=new Set;for(let o of r){if(!I(o)||typeof o.functionId!="string"||!/^[A-Za-z0-9_-]{1,64}$/.test(o.functionId)||a.has(o.functionId))return e();a.add(o.functionId),t==="functions"&&(typeof o.functionType!="number"||![1,2,5].includes(o.functionType))&&e(),t==="inputs"&&!I(o.inputSchema)&&e();for(let c of t==="inputs"?["inputSchema"]:["input","output"])if(o[c]!==void 0)try{g(o[c])}catch{e()}o.parameterOptions!==void 0&&(!I(o.parameterOptions)||!Object.values(o.parameterOptions).every(Array.isArray))&&e()}}let i=new Set(n.inputs.map(t=>t.functionId));n.functions.some(t=>!i.has(t.functionId))&&e()}async function G(n){if(C(n),n.previousAugmentation!==void 0&&![l,w,S].includes(n.previousAugmentation))throw new d("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:T(n.inputs)}];return n.client&&e.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"&&e.push({path:"page/src/lib/function-input-map.generated.ts",content:n.augmentation==="compat"?n.layout==="workspace"?S:l:w}),e}0&&(module.exports={CodegenError,SUPPORTED_CONTRACT_FORMAT_VERSIONS,generateFunctionClients,validateContractData});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
interface ClientContract {
|
|
2
|
+
functionId: string;
|
|
3
|
+
input?: Record<string, unknown>;
|
|
4
|
+
output?: Record<string, unknown>;
|
|
5
|
+
functionType: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare const SUPPORTED_CONTRACT_FORMAT_VERSIONS: readonly [1];
|
|
9
|
+
interface FunctionInputContract {
|
|
10
|
+
functionId: string;
|
|
11
|
+
inputSchema: Record<string, unknown>;
|
|
12
|
+
parameterOptions?: Record<string, unknown[]>;
|
|
13
|
+
}
|
|
14
|
+
/** Plain extracted data only. No filesystem paths, executable modules or credentials. */
|
|
15
|
+
interface FunctionContractData {
|
|
16
|
+
contractFormatVersion: 1;
|
|
17
|
+
layout: 'workspace' | 'classic';
|
|
18
|
+
schemaHash: string;
|
|
19
|
+
functions: ClientContract[];
|
|
20
|
+
inputs: FunctionInputContract[];
|
|
21
|
+
client: boolean;
|
|
22
|
+
augmentation: 'none' | 'compat' | 'client';
|
|
23
|
+
previousAugmentation?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface GeneratedFile {
|
|
27
|
+
path: string;
|
|
28
|
+
content: string;
|
|
29
|
+
}
|
|
30
|
+
declare class CodegenError extends Error {
|
|
31
|
+
readonly code: string;
|
|
32
|
+
constructor(code: string, message: string);
|
|
33
|
+
toJSON(): {
|
|
34
|
+
code: string;
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Equivalent runtime validation for contract format 1; schema budgets reject external references. */
|
|
39
|
+
declare function validateContractData(value: unknown): asserts value is FunctionContractData;
|
|
40
|
+
/** Pure generation. The caller validates destinations and owns writes/stale checks. */
|
|
41
|
+
declare function generateFunctionClients(value: unknown): Promise<GeneratedFile[]>;
|
|
42
|
+
|
|
43
|
+
export { ClientContract, CodegenError, FunctionContractData, FunctionInputContract, GeneratedFile, SUPPORTED_CONTRACT_FORMAT_VERSIONS, generateFunctionClients, validateContractData };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
interface ClientContract {
|
|
2
|
+
functionId: string;
|
|
3
|
+
input?: Record<string, unknown>;
|
|
4
|
+
output?: Record<string, unknown>;
|
|
5
|
+
functionType: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare const SUPPORTED_CONTRACT_FORMAT_VERSIONS: readonly [1];
|
|
9
|
+
interface FunctionInputContract {
|
|
10
|
+
functionId: string;
|
|
11
|
+
inputSchema: Record<string, unknown>;
|
|
12
|
+
parameterOptions?: Record<string, unknown[]>;
|
|
13
|
+
}
|
|
14
|
+
/** Plain extracted data only. No filesystem paths, executable modules or credentials. */
|
|
15
|
+
interface FunctionContractData {
|
|
16
|
+
contractFormatVersion: 1;
|
|
17
|
+
layout: 'workspace' | 'classic';
|
|
18
|
+
schemaHash: string;
|
|
19
|
+
functions: ClientContract[];
|
|
20
|
+
inputs: FunctionInputContract[];
|
|
21
|
+
client: boolean;
|
|
22
|
+
augmentation: 'none' | 'compat' | 'client';
|
|
23
|
+
previousAugmentation?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface GeneratedFile {
|
|
27
|
+
path: string;
|
|
28
|
+
content: string;
|
|
29
|
+
}
|
|
30
|
+
declare class CodegenError extends Error {
|
|
31
|
+
readonly code: string;
|
|
32
|
+
constructor(code: string, message: string);
|
|
33
|
+
toJSON(): {
|
|
34
|
+
code: string;
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Equivalent runtime validation for contract format 1; schema budgets reject external references. */
|
|
39
|
+
declare function validateContractData(value: unknown): asserts value is FunctionContractData;
|
|
40
|
+
/** Pure generation. The caller validates destinations and owns writes/stale checks. */
|
|
41
|
+
declare function generateFunctionClients(value: unknown): Promise<GeneratedFile[]>;
|
|
42
|
+
|
|
43
|
+
export { ClientContract, CodegenError, FunctionContractData, FunctionInputContract, GeneratedFile, SUPPORTED_CONTRACT_FORMAT_VERSIONS, generateFunctionClients, validateContractData };
|
package/dist/codegen.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import{compile as T}from"json-schema-to-typescript";function g(n){if(!n||typeof n!="object"||Array.isArray(n)||Buffer.byteLength(JSON.stringify(n))>32768)throw new Error("CONTRACT_SCHEMA_BUDGET");let r=0,s=(o,t)=>{if(!(!o||typeof o!="object")){if(++r>256||t>16)throw new Error("CONTRACT_SCHEMA_BUDGET");if(Array.isArray(o))o.forEach(e=>s(e,t+1));else for(let[e,a]of Object.entries(o)){if(e==="$ref"&&(typeof a!="string"||!a.startsWith("#/")))throw new Error("CONTRACT_EXTERNAL_REF");if(["$id","$dynamicRef","$recursiveRef","tsType","tsEnumNames"].includes(e))throw new Error("CONTRACT_EXTERNAL_REF");s(a,t+1)}}};s(n,0)}var y="@lark-base-open/base-database-app-sdk/page",l=`/* Generated by base-database-cli. Do not edit. */
|
|
2
|
+
import type { DatabaseFunctionInputMap as GeneratedInputMap } from './database-function-inputs.generated';
|
|
3
|
+
import '${y}';
|
|
4
|
+
declare module '${y}' { interface FunctionInputMap extends GeneratedInputMap {} }
|
|
5
|
+
`,A=`/* Generated by base-database-cli. Map is declared in ../generated/functions. */
|
|
6
|
+
export {};
|
|
7
|
+
`;async function O(n,r,s="../lib/database-function-inputs.generated"){let o=["/* Generated by base-database-cli. Runtime validation remains authoritative. */",`import { invokeDatabaseFunction } from '${y}';`,"import { SDKError } from '@lark-base-open/base-database-app-sdk/shared';",`import type { DatabaseFunctionInputMap as GeneratedFunctionInputs } from ${JSON.stringify(s)};`,`export const contract = ${JSON.stringify({version:1,schemaHash:r,remoteContractMatch:"unknown"})} as const;`],t=[];for(let[e,a]of[...n].sort((i,c)=>i.functionId.localeCompare(c.functionId)).entries()){let i=`Function${e}Input`,c=`Function${e}Output`;o.push(`export type ${i} = GeneratedFunctionInputs[${JSON.stringify(a.functionId)}];`);let u=a.functionType===2?a.output:void 0;if(!u)o.push(`export type ${c} = unknown;`);else{g(u);try{o.push(await T(S(u,c),c,{bannerComment:"",customName:(d,w)=>d.title===c?c:d.title||w?`${c}_${d.title||w}`:void 0,unknownAny:!0,additionalProperties:!0,$refOptions:{resolve:{http:!1,file:!1}}}))}catch{o.push(`// Schema could not be represented; no precision is claimed.
|
|
8
|
+
export type ${c} = unknown;`)}}t.push(` [${JSON.stringify(a.functionId)}]: async (input: ${i}): Promise<${c}> => {
|
|
9
|
+
const response = await invokeDatabaseFunction<${c}>(${JSON.stringify(a.functionId)}, input);
|
|
10
|
+
if (!response || !Number.isSafeInteger(response.code)) throw new SDKError('FUNCTION_RESPONSE_INVALID', 'Invalid Function response', {outcome:'unknown'});
|
|
11
|
+
if (response.code !== 0) throw new SDKError('FUNCTION_INVOKE_FAILED', 'Function invocation failed', String(response.code));
|
|
12
|
+
return response.data as ${c};
|
|
13
|
+
},`)}return o.push(`declare module '${y}' { interface FunctionInputMap extends GeneratedFunctionInputs {} }`,"export const functions = {",...t,"};",""),o.join(`
|
|
14
|
+
`)}function S(n,r){let s=structuredClone(n),o=t=>{if(!t||typeof t!="object")return;if(Array.isArray(t)){t.forEach(o);return}let e=t;Object.values(e).forEach(o),Array.isArray(e.prefixItems)&&(e.additionalItems=e.items??e.maxItems!==e.prefixItems.length,e.items=e.prefixItems,delete e.prefixItems)};return o(s),s.title=r,s}function p(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)}function b(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(b).join(", ")}]`:p(n)?`{ ${Object.entries(n).map(([r,s])=>`${JSON.stringify(r)}: ${b(s)}`).join("; ")} }`:"never"}function C(n,r){switch(r){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 p(n);default:return!1}}function k(n){return typeof n.type=="string"?[n.type]:Array.isArray(n.type)?n.type.filter(r=>typeof r=="string"):[]}function F(n,r){switch(r){case"string":return"string";case"integer":case"number":return"number";case"boolean":return"boolean";case"null":return"null";case"array":{let s=n.prefixItems,o=Array.isArray(s),t=o?s.filter(p):[];if(o&&n.minItems===t.length&&n.maxItems===t.length)return`[${t.map(f).join(", ")}]`;let e=p(n.items)?f(n.items):"unknown";return t.length===0?`Array<${e}>`:`[${[...t.map(i=>`${f(i)}?`),`...Array<${e}>`].join(", ")}]`}case"object":{let s=p(n.properties)?n.properties:{},o=new Set(Array.isArray(n.required)?n.required.filter(u=>typeof u=="string"):[]),t=Object.entries(s).filter(u=>p(u[1])),e=new Set(t.map(([u])=>u)),a=[...o].filter(u=>!e.has(u));if(a.length>0&&n.additionalProperties===!1)return"never";let i=t.map(([u,d])=>`${JSON.stringify(u)}${o.has(u)?"":"?"}: ${f(d)}`);i.push(...a.map(u=>`${JSON.stringify(u)}: unknown`));let c=`{ ${i.join("; ")} }`;return n.additionalProperties===!1?i.length===0?"Record<string, never>":c:`${c} & Record<string, unknown>`}default:return"unknown"}}function f(n){let r=["anyOf","oneOf","allOf"].filter(t=>Array.isArray(n[t]));if(r.length){let t={...n};for(let i of r)delete t[i];let e=r.map(i=>{let c=n[i].filter(p).map(f);return c.length?c.map(u=>`(${u})`).join(i==="allOf"?" & ":" | "):"never"}),a=f(t);return a!=="unknown"&&e.unshift(a),e.map(i=>`(${i})`).join(" & ")}if(Object.hasOwn(n,"const"))return b(n.const);let s=k(n);if(Array.isArray(n.enum)&&n.enum.length>0){let t=n.enum.filter(e=>s.length===0||s.some(a=>C(e,a)));return t.length===0?"never":t.map(b).join(" | ")}let o=[...new Set(s.map(t=>F(n,t)))];return o.length===0?"unknown":o.join(" | ")}function h(n){let r=[...n].sort((t,e)=>t.functionId<e.functionId?-1:t.functionId>e.functionId?1:0),s=r.map(t=>` ${JSON.stringify(t.functionId)}: ${f(t.inputSchema)}`),o=r.flatMap(t=>{let e=Object.entries(t.parameterOptions??{});return e.length===0?[]:[` ${JSON.stringify(t.functionId)}: {`,...e.map(([a,i])=>` ${JSON.stringify(a)}: ${JSON.stringify(i)},`)," },"]});return["/* Generated by base-database-cli from Function metadata. Do not edit. */","// prettier-ignore","export type DatabaseFunctionInputMap = {",...s,"}",...o.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 = {",...o,"} as const"]:[],""].join(`
|
|
15
|
+
`)}var G=[1],m=class extends Error{constructor(s,o){super(o);this.code=s;this.name="CodegenError"}toJSON(){return{code:this.code,message:this.message}}},N=l.replace("./database-function-inputs.generated","../generated/function-inputs"),I=n=>!!n&&typeof n=="object"&&!Array.isArray(n);function $(n){if(!I(n)||n.contractFormatVersion!==1)throw new m("CONTRACT_FORMAT_UNSUPPORTED","Supported contractFormatVersion: 1");let r=()=>{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")&&r();let s;try{s=JSON.stringify(n)}catch{return r()}Buffer.byteLength(s)>4*1024*1024&&r();for(let t of["functions","inputs"]){let e=n[t];if(!Array.isArray(e)||e.length>1e3)return r();let a=new Set;for(let i of e){if(!I(i)||typeof i.functionId!="string"||!/^[A-Za-z0-9_-]{1,64}$/.test(i.functionId)||a.has(i.functionId))return r();a.add(i.functionId),t==="functions"&&(typeof i.functionType!="number"||![1,2,5].includes(i.functionType))&&r(),t==="inputs"&&!I(i.inputSchema)&&r();for(let c of t==="inputs"?["inputSchema"]:["input","output"])if(i[c]!==void 0)try{g(i[c])}catch{r()}i.parameterOptions!==void 0&&(!I(i.parameterOptions)||!Object.values(i.parameterOptions).every(Array.isArray))&&r()}}let o=new Set(n.inputs.map(t=>t.functionId));n.functions.some(t=>!o.has(t.functionId))&&r()}async function J(n){if($(n),n.previousAugmentation!==void 0&&![l,A,N].includes(n.previousAugmentation))throw new m("CONTRACT_INPUT_MAP_CONFLICT","Unrecognized FunctionInputMap augmentation; review before replacing");let r=[{path:n.layout==="workspace"?"page/src/generated/function-inputs.ts":"page/src/lib/database-function-inputs.generated.ts",content:h(n.inputs)}];return n.client&&r.push({path:"page/src/generated/functions.ts",content:await O(n.functions,n.schemaHash,n.layout==="workspace"?"./function-inputs":"../lib/database-function-inputs.generated")}),n.augmentation!=="none"&&r.push({path:"page/src/lib/function-input-map.generated.ts",content:n.augmentation==="compat"?n.layout==="workspace"?N:l:A}),r}export{m as CodegenError,G as SUPPORTED_CONTRACT_FORMAT_VERSIONS,J as generateFunctionClients,$ as validateContractData};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { X as AttachmentImage, M as BaseAppContextValue, N as BaseAppProvider, T as DatabaseAudience, W as DatabaseUserMenu, V as DatabaseUserMenuProps, R as FloatingButton, Q as FloatingButtonProps, U as UiLanguage, Y as UiLanguageContext, C as User, H as UserSelectorAction, J as UserSelectorEditor, K as UserSelectorEditorProps, L as UserSelectorEditorValue, G as UserSelectorMode, A as UserSelectorPanel, B as UserSelectorPanelProps, I as UserSelectorSearchAction, E as UserSelectorValue, _ as getUiLanguage, $ as getUiLocale, a0 as initializeUiLanguage, Z as selectUiLanguage, O as useBaseApp, P as useOptionalBaseApp, a1 as useUiLanguage } from './index-64557073.js';
|
|
2
|
+
import 'react';
|
|
3
|
+
import '@lark-base-open/base-site-channel/runtime';
|
|
4
|
+
import './capabilities-56e403e7.js';
|
|
5
|
+
import './shared.js';
|
|
6
|
+
import '@lark-base-open/base-site-channel/capabilities';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{L as a,M as b,N as c,O as d,P as e,Q as f,R as g,S as h,T as i,V as j,W as k,X as l,Y as m,Z as n}from"./chunk-5XIFZ4AH.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};
|