@77-zhike/app-sdk 0.2.0-d7b1.10

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.
Files changed (87) hide show
  1. package/README.md +251 -0
  2. package/package.json +71 -0
  3. package/src/bin.js +15 -0
  4. package/src/cli/api-client.js +249 -0
  5. package/src/cli/browser-auth.js +212 -0
  6. package/src/cli/credential-store.js +101 -0
  7. package/src/cli/development-app.js +77 -0
  8. package/src/cli/development-logs.js +183 -0
  9. package/src/cli/development-watch.js +205 -0
  10. package/src/cli/index.js +256 -0
  11. package/src/cli/local-commands.js +80 -0
  12. package/src/cli/logs.js +56 -0
  13. package/src/cli/project-init.js +259 -0
  14. package/src/cli/upload-bundle.js +73 -0
  15. package/src/client/analysis.d.ts +4 -0
  16. package/src/client/analysis.js +12 -0
  17. package/src/client/destinations.d.ts +25 -0
  18. package/src/client/destinations.js +70 -0
  19. package/src/client/external-url.js +9 -0
  20. package/src/client/index.d.ts +249 -0
  21. package/src/client/index.js +72 -0
  22. package/src/client/interactions.d.ts +23 -0
  23. package/src/client/interactions.js +62 -0
  24. package/src/client/points.generated.js +67 -0
  25. package/src/config.js +68 -0
  26. package/src/development-workspace.js +154 -0
  27. package/src/errors.js +20 -0
  28. package/src/forms/array-contract.d.ts +32 -0
  29. package/src/forms/array-contract.js +138 -0
  30. package/src/forms/components.generated.js +4 -0
  31. package/src/forms/factory.js +41 -0
  32. package/src/forms/field-array.d.ts +16 -0
  33. package/src/forms/field-array.js +52 -0
  34. package/src/forms/index.d.ts +118 -0
  35. package/src/forms/index.js +5 -0
  36. package/src/forms/normalize-options.js +19 -0
  37. package/src/forms/options.d.ts +30 -0
  38. package/src/forms/options.js +55 -0
  39. package/src/forms/record-options.d.ts +28 -0
  40. package/src/forms/record-options.js +92 -0
  41. package/src/forms/schema.d.ts +82 -0
  42. package/src/forms/schema.js +128 -0
  43. package/src/forms/state.d.ts +30 -0
  44. package/src/forms/state.js +82 -0
  45. package/src/forms/validation.d.ts +9 -0
  46. package/src/forms/validation.js +81 -0
  47. package/src/forms/values.d.ts +5 -0
  48. package/src/forms/values.js +38 -0
  49. package/src/index.d.ts +13 -0
  50. package/src/index.js +2 -0
  51. package/src/jsx-dev-runtime.d.ts +2 -0
  52. package/src/jsx-dev-runtime.js +1 -0
  53. package/src/jsx-runtime.d.ts +2 -0
  54. package/src/jsx-runtime.js +1 -0
  55. package/src/project-binding.js +84 -0
  56. package/src/server/index.d.ts +318 -0
  57. package/src/server/index.js +242 -0
  58. package/src/server/steps/index.d.ts +71 -0
  59. package/src/server/steps/index.js +15 -0
  60. package/src/server/triggers/index.d.ts +68 -0
  61. package/src/server/triggers/index.js +27 -0
  62. package/src/server/workflow-blocks/index.d.ts +72 -0
  63. package/src/server/workflow-blocks/index.js +32 -0
  64. package/src/toolchain/allowed-packages.json +7 -0
  65. package/src/toolchain/canonical-json.js +17 -0
  66. package/src/toolchain/dependency-policy.js +181 -0
  67. package/src/toolchain/index.js +15 -0
  68. package/src/toolchain/real-build.js +459 -0
  69. package/src/toolchain/source-discovery.js +919 -0
  70. package/src/toolchain/transport-tar.js +168 -0
  71. package/src/toolchain/webhook-response.js +50 -0
  72. package/src/toolchain/workflow-blocks/discovery.js +133 -0
  73. package/src/toolchain/workflow-steps/manifest.js +99 -0
  74. package/src/toolchain/workflow-triggers/manifest.js +47 -0
  75. package/src/ui/components.generated.js +5 -0
  76. package/src/ui/events.d.ts +10 -0
  77. package/src/ui/factory.js +70 -0
  78. package/src/ui/icons.generated.js +2 -0
  79. package/src/ui/index.d.ts +343 -0
  80. package/src/ui/index.js +4 -0
  81. package/src/ui/jsx.generated.d.ts +359 -0
  82. package/src/ui/native-dom.d.ts +49 -0
  83. package/src/ui/native-dom.js +44 -0
  84. package/src/ui/style.d.ts +5 -0
  85. package/src/ui/style.generated.js +2 -0
  86. package/src/ui/style.js +15 -0
  87. package/src/ui/validation.js +86 -0
@@ -0,0 +1,38 @@
1
+ /** 平台值格式,不包含业务字段规则或缺省时区。 */
2
+ export function isPlainDate(value) {
3
+ if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
4
+ const [year, month, day] = value.split('-').map(Number);
5
+ const date = new Date(0);
6
+ date.setUTCFullYear(year, month - 1, day);
7
+ return year > 0 && date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
8
+ }
9
+ export function isDateTime(value) {
10
+ if (typeof value !== 'string') return false;
11
+ const match = /^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2})$/.exec(value);
12
+ return Boolean(match && isPlainDate(match[1]) && +match[2] < 24 && +match[3] < 60 && +(match[4] ?? 0) < 60 && Number.isFinite(Date.parse(value)));
13
+ }
14
+ export function parseNumberDraft(value) {
15
+ if (value === null || value === '') return { value: null };
16
+ if (typeof value === 'number') return Number.isFinite(value) ? { value } : { value: null, error: '请输入有效数字' };
17
+ if (typeof value !== 'string' || value.length > 512 || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(value)) return { value: null, error: '请输入有效数字' };
18
+ const number = Number(value);
19
+ return Number.isFinite(number) ? { value: number } : { value: null, error: '请输入有效数字' };
20
+ }
21
+ const pad = value => String(value).padStart(2, '0');
22
+ export function instantToLocal(value) {
23
+ if (!value) return '';
24
+ if (!isDateTime(value)) return value;
25
+ const date = new Date(value);
26
+ return `${String(date.getFullYear()).padStart(4, '0')}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
27
+ }
28
+ export function localToInstant(value) {
29
+ if (!value) return { value: null };
30
+ const match = /^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2})$/.exec(value);
31
+ if (!match || !isPlainDate(match[1]) || +match[2] > 23 || +match[3] > 59) return { value: null, error: '请输入有效日期时间' };
32
+ const wall = new Date(value);
33
+ const utc = new Date(value + ':00.000Z').getTime();
34
+ const offsets = new Set([-36, 0, 36].map(hours => new Date(wall.getTime() + hours * 3600000).getTimezoneOffset()));
35
+ const candidates = [...offsets].map(offset => new Date(utc + offset * 60000).toISOString()).filter(instant => instantToLocal(instant) === value);
36
+ if (candidates.length !== 1) return { value: null, error: '该本地时间不存在或有歧义,请选择其他时间' };
37
+ return { value: candidates[0] };
38
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /** App SDK 支持的严格 JSON 值。 */
2
+ export type JsonValue =
3
+ | null
4
+ | boolean
5
+ | number
6
+ | string
7
+ | JsonValue[]
8
+ | { [key: string]: JsonValue };
9
+
10
+ /** 当前 App Bundle 代码 Manifest schema。 */
11
+ export const APP_MANIFEST_SCHEMA_VERSION: "zhike.app-manifest.v1";
12
+ /** 当前 Host SDK ABI 版本。 */
13
+ export const SDK_ABI_VERSION: "2";
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export const APP_MANIFEST_SCHEMA_VERSION = "zhike.app-manifest.v1";
2
+ export const SDK_ABI_VERSION = "2";
@@ -0,0 +1,2 @@
1
+ export { jsxDEV, Fragment } from "react/jsx-dev-runtime";
2
+ export { JSX } from "./ui/jsx.generated.js";
@@ -0,0 +1 @@
1
+ export { jsxDEV, Fragment } from "react/jsx-dev-runtime";
@@ -0,0 +1,2 @@
1
+ export { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ export { JSX } from "./ui/jsx.generated.js";
@@ -0,0 +1 @@
1
+ export { jsx, jsxs, Fragment } from "react/jsx-runtime";
@@ -0,0 +1,84 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+
4
+ import { normalizeOrigin } from "./config.js";
5
+ import { ZhikeCliError } from "./errors.js";
6
+
7
+ export const PROJECT_BINDING_PATH = ".zhike/project.json";
8
+ const BINDING_KEYS = [
9
+ "appId",
10
+ "appSlug",
11
+ "organizationId",
12
+ "platformEnvironment",
13
+ "schemaVersion",
14
+ ];
15
+
16
+ export function parseProjectBinding(value, expectedEnvironment = null) {
17
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
18
+ throw _bindingError();
19
+ }
20
+ const keys = Object.keys(value).sort();
21
+ if (
22
+ keys.length !== BINDING_KEYS.length ||
23
+ keys.some((key, index) => key !== BINDING_KEYS[index])
24
+ ) {
25
+ throw _bindingError();
26
+ }
27
+ const environment = normalizeOrigin(
28
+ value.platformEnvironment,
29
+ "platformEnvironment",
30
+ );
31
+ if (
32
+ value.schemaVersion !== 1 ||
33
+ !/^[0-9A-HJKMNP-TV-Z]{26}$/.test(value.appId) ||
34
+ !/^[0-9A-HJKMNP-TV-Z]{26}$/.test(value.organizationId) ||
35
+ !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value.appSlug) ||
36
+ environment !== value.platformEnvironment
37
+ ) {
38
+ throw _bindingError();
39
+ }
40
+ if (
41
+ expectedEnvironment &&
42
+ environment !== normalizeOrigin(expectedEnvironment, "Developer API URL")
43
+ ) {
44
+ throw new ZhikeCliError(
45
+ "zhike_project_environment_mismatch",
46
+ "当前项目绑定的 Developer 环境与 CLI 目标环境不一致",
47
+ );
48
+ }
49
+ return Object.freeze({ ...value });
50
+ }
51
+
52
+ export async function readProjectBinding(projectDirectory, expectedEnvironment) {
53
+ let content;
54
+ try {
55
+ content = await readFile(resolve(projectDirectory, PROJECT_BINDING_PATH), "utf8");
56
+ } catch (error) {
57
+ throw new ZhikeCliError(
58
+ "zhike_project_binding_missing",
59
+ `当前目录缺少 ${PROJECT_BINDING_PATH}`,
60
+ { cause: error },
61
+ );
62
+ }
63
+ try {
64
+ return parseProjectBinding(JSON.parse(content), expectedEnvironment);
65
+ } catch (error) {
66
+ if (error instanceof ZhikeCliError) {
67
+ throw error;
68
+ }
69
+ throw _bindingError(error);
70
+ }
71
+ }
72
+
73
+ export function serializeProjectBinding(binding) {
74
+ const validated = parseProjectBinding(binding);
75
+ return `${JSON.stringify(validated, null, 2)}\n`;
76
+ }
77
+
78
+ function _bindingError(cause) {
79
+ return new ZhikeCliError(
80
+ "zhike_project_binding_invalid",
81
+ `${PROJECT_BINDING_PATH} 不是受支持的严格 Project Binding`,
82
+ { cause },
83
+ );
84
+ }
@@ -0,0 +1,318 @@
1
+ import type { JsonValue } from "../index.js";
2
+ export { defineWorkflowStep, defineWorkflowStepExecute } from "./steps/index.js";
3
+ export type { WorkflowObjectSchema, WorkflowScalarSchema, WorkflowStepDefinition, WorkflowStepOutcome, WorkflowStepResult, WorkflowSchemaValue } from "./steps/index.js";
4
+ export { defineWorkflowTrigger, defineWorkflowTriggerActivate, defineWorkflowTriggerOnEvent, defineWorkflowTriggerDeactivate } from "./triggers/index.js";
5
+ export type { WorkflowTriggerDefinition, WorkflowTriggerOutcome, WorkflowTriggerEventResult } from "./triggers/index.js";
6
+ export {
7
+ defineWorkflowBlock,
8
+ defineWorkflowBlockExecute,
9
+ defineWorkflowBlockActivate,
10
+ defineWorkflowBlockTrigger,
11
+ defineWorkflowBlockDeactivate,
12
+ } from "./workflow-blocks/index.js";
13
+ export type {
14
+ WorkflowBlockDefinition,
15
+ WorkflowStepBlockDefinition,
16
+ WorkflowTriggerBlockDefinition,
17
+ } from "./workflow-blocks/index.js";
18
+
19
+ /** 当前执行的 App API Token;由可信 Runtime Module 在服务端模块求值前注入。 */
20
+ export const ZHIKE_API_TOKEN: string;
21
+
22
+ /** 由调用方选择稳定操作身份;SDK 不生成 Key 或自动重试。 */
23
+ export interface IdempotencyOptions { idempotencyKey?: string }
24
+
25
+ /** App Settings 条件写入要求使用刚读取到的 revision。 */
26
+ export interface VersionCondition extends IdempotencyOptions { expectedRevision: number }
27
+
28
+ /** 当前 App 的单个持久化配置。 */
29
+ export interface AppSetting { key: string; value: JsonValue; revision: number }
30
+
31
+ /** 只列出当前 App 的有效配置,不含清空元数据。 */
32
+ export function getSettings(): Promise<Readonly<{ items: AppSetting[] }>>;
33
+
34
+ /** 不存在时返回 null/revision=0,清空后的 null 保留正 revision。 */
35
+ export function getSetting(key: string): Promise<Readonly<AppSetting>>;
36
+
37
+ /** null 清空;容量、大小和深度限制由平台原子校验。 */
38
+ export function setSetting(key: string, value: JsonValue, options: VersionCondition): Promise<Readonly<AppSetting>>;
39
+
40
+ /** 当前 App Installation 隔离的字符串 KV。 */
41
+ export interface AppKv {
42
+ /** 读取字符串;不存在或已过期时返回 null。 */
43
+ get(key: string): Promise<string | null>;
44
+ /** 原子覆盖字符串,可选正整数 TTL 秒数。 */
45
+ set(key: string, value: string, options?: { ttlInSeconds?: number }): Promise<void>;
46
+ /** 幂等删除字符串。 */
47
+ delete(key: string): Promise<void>;
48
+ }
49
+
50
+ /** 当前执行可用的 Installation 级 KV。 */
51
+ export const kv: AppKv;
52
+
53
+ /** 当前 Installation 已激活的稳定 Webhook Handler。 */
54
+ export interface WebhookHandler {
55
+ /** 平台生成的稳定 Handler ID。 */
56
+ id: string;
57
+ /** 与源码文件对应的稳定名称。 */
58
+ fileName: string;
59
+ /** 可注册到外部系统或 Workspace Webhook 的平台回调地址。 */
60
+ url: string;
61
+ }
62
+
63
+ /** 幂等激活当前 Manifest 已声明的稳定 Webhook Handler。 */
64
+ export function createWebhookHandler(input: {
65
+ /** `src/app/webhooks/<fileName>.webhook.ts` 中的 fileName。 */
66
+ fileName: string;
67
+ }): Promise<Readonly<WebhookHandler>>;
68
+
69
+ /** 列出当前 Installation 已激活的 Webhook Handlers。 */
70
+ export function listWebhookHandlers(): Promise<readonly Readonly<WebhookHandler>[]>;
71
+
72
+ /** 幂等停用当前 Installation 自己的 Webhook Handler。 */
73
+ export function deleteWebhookHandler(id: string): Promise<void>;
74
+
75
+ /** Workspace Webhook 当前公开的 Record 事件目录。 */
76
+ export type WorkspaceWebhookRecordEventType =
77
+ | "record.created"
78
+ | "record.updated"
79
+ | "record.deleted"
80
+ | "record.archived"
81
+ | "record.restored";
82
+
83
+ /** Workspace Webhook 当前公开的 Task 事件目录。 */
84
+ export type WorkspaceWebhookTaskEventType =
85
+ | "task.created"
86
+ | "task.updated"
87
+ | "task.deleted";
88
+
89
+ /** Workspace Webhook 当前公开的 Note 事件目录。 */
90
+ export type WorkspaceWebhookNoteEventType =
91
+ | "note.created"
92
+ | "note.updated"
93
+ | "note.deleted";
94
+
95
+ /** Workspace Webhook 当前公开的 Activity 事件目录。 */
96
+ export type WorkspaceWebhookActivityEventType =
97
+ | "activity.created"
98
+ | "activity.updated"
99
+ | "activity.deleted";
100
+
101
+ /** Workspace Webhook 当前公开的 Worklist Entry 事件目录。 */
102
+ export type WorkspaceWebhookListEntryEventType =
103
+ | "list-entry.created"
104
+ | "list-entry.updated"
105
+ | "list-entry.deleted";
106
+
107
+ /** Webhook 通知中的可信操作者引用。 */
108
+ export interface WorkspaceWebhookActorReference {
109
+ /** 操作者类型。 */
110
+ type: "human" | "agent" | "automation" | "integration" | "system";
111
+ /** 稳定主体 ID;无具体主体的 system 操作可以为空。 */
112
+ id: string | null;
113
+ }
114
+
115
+ /** Webhook 通知中的 Record 与可选字段 Slug。 */
116
+ export interface WorkspaceWebhookRecordIdentity {
117
+ /** 当前 Workspace ID。 */
118
+ workspaceId: string;
119
+ /** 当前公开对象 Slug。 */
120
+ objectSlug: string;
121
+ /** Record 实例 ID。 */
122
+ recordId: string;
123
+ /** 仅 `record.updated` 存在的当前公开字段 Slug。 */
124
+ fieldSlug?: string;
125
+ }
126
+
127
+ /** 最小 Record Webhook Event;业务值需要通过 Record API 查询。 */
128
+ export interface WorkspaceWebhookRecordEvent {
129
+ /** Record 事件类型。 */
130
+ eventType: WorkspaceWebhookRecordEventType;
131
+ /** 事件涉及的资源 identity。 */
132
+ id: WorkspaceWebhookRecordIdentity;
133
+ /** source fact 无可信 actor 时为空。 */
134
+ actor: WorkspaceWebhookActorReference | null;
135
+ }
136
+
137
+ /** Webhook 通知中的 Task identity。 */
138
+ export interface WorkspaceWebhookTaskIdentity {
139
+ /** 当前 Workspace ID。 */
140
+ workspaceId: string;
141
+ /** Task 实例 ID。 */
142
+ taskId: string;
143
+ }
144
+
145
+ /** 最小 Task Webhook Event;业务值需要通过 Task API 查询。 */
146
+ export interface WorkspaceWebhookTaskEvent {
147
+ /** Task 事件类型。 */
148
+ eventType: WorkspaceWebhookTaskEventType;
149
+ /** 事件涉及的 Task identity。 */
150
+ id: WorkspaceWebhookTaskIdentity;
151
+ /** source fact 无可信 actor 时为空。 */
152
+ actor: WorkspaceWebhookActorReference | null;
153
+ }
154
+
155
+ /** Webhook 通知中的 Note identity。 */
156
+ export interface WorkspaceWebhookNoteIdentity {
157
+ /** 当前 Workspace ID。 */
158
+ workspaceId: string;
159
+ /** Note 实例 ID。 */
160
+ noteId: string;
161
+ }
162
+
163
+ /** 最小 Note Webhook Event;正文和其他业务值需要通过 Note API 查询。 */
164
+ export interface WorkspaceWebhookNoteEvent {
165
+ /** Note 事件类型。 */
166
+ eventType: WorkspaceWebhookNoteEventType;
167
+ /** 事件涉及的 Note identity。 */
168
+ id: WorkspaceWebhookNoteIdentity;
169
+ /** source fact 无可信 actor 时为空。 */
170
+ actor: WorkspaceWebhookActorReference | null;
171
+ }
172
+
173
+ /** Webhook 通知中的 Activity identity。 */
174
+ export interface WorkspaceWebhookActivityIdentity {
175
+ /** 当前 Workspace ID。 */
176
+ workspaceId: string;
177
+ /** Activity 实例 ID。 */
178
+ activityId: string;
179
+ }
180
+
181
+ /** 最小 Activity Webhook Event;业务值需要通过 Activity API 查询。 */
182
+ export interface WorkspaceWebhookActivityEvent {
183
+ /** Activity 事件类型。 */
184
+ eventType: WorkspaceWebhookActivityEventType;
185
+ /** 事件涉及的 Activity identity。 */
186
+ id: WorkspaceWebhookActivityIdentity;
187
+ /** source fact 无可信 actor 时为空。 */
188
+ actor: WorkspaceWebhookActorReference | null;
189
+ }
190
+
191
+ /** Webhook 通知中的 Worklist Entry identity。 */
192
+ export interface WorkspaceWebhookListEntryIdentity {
193
+ workspaceId: string;
194
+ listId: string;
195
+ entryId: string;
196
+ objectSlug: string;
197
+ recordId: string;
198
+ /** 仅 `list-entry.updated` 存在。 */
199
+ fieldSlug?: string;
200
+ }
201
+
202
+ /** 最小 Worklist Entry Webhook Event;业务值需要通过 Entry API 回查。 */
203
+ export interface WorkspaceWebhookListEntryEvent {
204
+ eventType: WorkspaceWebhookListEntryEventType;
205
+ id: WorkspaceWebhookListEntryIdentity;
206
+ actor: WorkspaceWebhookActorReference | null;
207
+ }
208
+
209
+ /** Workspace Webhook 当前公开的封闭事件联合。 */
210
+ export type WorkspaceWebhookEvent =
211
+ | WorkspaceWebhookRecordEvent
212
+ | WorkspaceWebhookTaskEvent
213
+ | WorkspaceWebhookNoteEvent
214
+ | WorkspaceWebhookActivityEvent
215
+ | WorkspaceWebhookListEntryEvent;
216
+
217
+ /** Workspace Webhook HTTP 请求体。 */
218
+ export interface WorkspaceWebhookBody {
219
+ /** 当前 Webhook ID。 */
220
+ webhookId: string;
221
+ /** 本次投递携带的事件;接收方不得假设永久只有一条。 */
222
+ events: WorkspaceWebhookEvent[];
223
+ }
224
+
225
+ interface WorkspaceConnectionBase {
226
+ /** 当前 Workspace Connection 的稳定 ID。 */
227
+ id: string;
228
+ /** 当前 Connect/Reconnect generation 的非敏感稳定表示。 */
229
+ generation: string;
230
+ /** Secret 或当前 OAuth/OIDC access token,仅存在于本次服务端执行内存。 */
231
+ value: string;
232
+ }
233
+
234
+ /** 当前服务端执行可使用的 Workspace 外部系统连接。 */
235
+ export type WorkspaceConnection = WorkspaceConnectionBase & (
236
+ | {
237
+ type: "secret";
238
+ protocol: "secret";
239
+ }
240
+ | {
241
+ type: "oauth2";
242
+ protocol: "oauth2";
243
+ /** OAuth 2.0 access token;等同 value。 */
244
+ accessToken: string;
245
+ }
246
+ | {
247
+ type: "oauth2";
248
+ protocol: "oidc";
249
+ /** OIDC access token;等同 value。 */
250
+ accessToken: string;
251
+ /** OIDC ID token;仅存在于当前服务端执行内存。 */
252
+ idToken: string;
253
+ }
254
+ );
255
+
256
+ /** 同步读取当前执行的连接快照;未连接或暂不可用时抛出安全错误,不在 getter 内刷新。 */
257
+ export function getWorkspaceConnection(): Readonly<WorkspaceConnection>;
258
+
259
+ /** 当前 Server Function 调用者在当前 Workspace 内的成员快照。 */
260
+ export interface CurrentUser {
261
+ /** Workspace 成员 ID;不是平台全局 User ID。 */
262
+ workspaceMemberId: string;
263
+ /** 当前 Workspace 中的显示名称。 */
264
+ displayName: string;
265
+ /** 当前 Workspace 中的主邮箱。 */
266
+ primaryEmailAddress: string | null;
267
+ /** 当前平台用户头像;未绑定平台用户时为空。 */
268
+ avatarUrl: string | null;
269
+ }
270
+
271
+ /** 同步读取当前调用者;Lifecycle、Webhook 等无人触发入口会抛出 current_user_unavailable。 */
272
+ export function getCurrentUser(): Readonly<CurrentUser>;
273
+
274
+ /** Server Function 的一期函数合同。 */
275
+ export type ServerFunction<TArgs extends JsonValue[] = JsonValue[], TResult extends JsonValue = JsonValue> =
276
+ (...args: TArgs) => Promise<TResult>;
277
+
278
+ /** App 安装通知处理器取得的可信参数。 */
279
+ export interface AppInstalledParams {
280
+ /** 当前 Installation 的稳定 ID。 */
281
+ installationId: string;
282
+ /** 当前 Workspace 的稳定 ID。 */
283
+ workspaceId: string;
284
+ }
285
+
286
+ /** App 卸载通知处理器取得的可信参数。 */
287
+ export interface AppUninstalledParams {
288
+ /** 当前 Installation 的稳定 ID。 */
289
+ installationId: string;
290
+ /** 当前 Workspace 的稳定 ID。 */
291
+ workspaceId: string;
292
+ }
293
+
294
+ /** Connection 建立前 interceptor 取得的可信参数。 */
295
+ export interface ConnectionAddedParams {
296
+ /** 本次候选 Connection,只在当前 interceptor 执行内可用。 */
297
+ connection: Readonly<WorkspaceConnection>;
298
+ }
299
+
300
+ /** Connection 移除前 interceptor 取得的可信参数。 */
301
+ export interface ConnectionRemovedParams {
302
+ /** 本次待移除 Connection,只在当前 interceptor 执行内可用。 */
303
+ connection: Readonly<WorkspaceConnection>;
304
+ }
305
+
306
+
307
+ /** 在前端调用的服务端函数中,写入前按当前可信调用者重新校验管理员权限;不接受前端自报角色。 */
308
+ export function requireWorkspaceAdmin(): Promise<void>;
309
+
310
+ /** 平台注入的单次 Webhook 执行上下文,不能由入站请求覆盖。 */
311
+ export interface WebhookContext {
312
+ /** 本次入站请求的可信执行 ID;不是业务幂等保证。 */
313
+ readonly invocationId: string;
314
+ /** 每次实际执行的独立记录 ID。 */
315
+ readonly attemptId: string;
316
+ /** 从 1 开始的业务尝试序号。 */
317
+ readonly attemptNumber: number;
318
+ }