@blade-hq/agent-client 2612.0.0-beta.82 → 2612.0.0-beta.83
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/README.md +20 -0
- package/dist/blade-client.d.ts +4 -0
- package/dist/{chunk-FNFGLHK7.js → chunk-J5HK3PPV.js} +124 -2
- package/dist/chunk-J5HK3PPV.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/internal.js +5 -1
- package/dist/internal.js.map +1 -1
- package/dist/resources/capabilities.d.ts +14 -0
- package/dist/resources/feishu-bots.d.ts +273 -0
- package/package.json +1 -1
- package/public-api.md +308 -1
- package/dist/chunk-FNFGLHK7.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { BladeApplicationClient } from "./application-client";
|
|
2
2
|
export { BladeClient } from "./blade-client";
|
|
3
3
|
export { ConnectorsResource } from "./resources/connectors";
|
|
4
|
+
export * from "./resources/feishu-bots";
|
|
4
5
|
export type { ConnectorRuleValue, ConnectorRuleGroup, ConnectorRules, ConnectorPushSettingsResult, ConnectorPushSettings, ConnectorPushSetting, ConnectorArtifact, ConnectorApprovalStatus, ConnectorDomain, ConnectorAuthorization, ConnectorAuthorizationAction, ConnectorAuthorizationOptions, ConnectorAuthorizationPlan, ConnectorCapability, ConnectorPermission, ConnectorAuthorizationFailure, ConnectorAuthorizationStep, ConnectorDiagnostics, ConnectorRuntimeDiagnostics, ConnectorAuditEvent, AccountConnector, ConnectorDraft, ConnectorConnection, ConnectorConnectionView } from "./resources/connectors";
|
|
5
6
|
export type { BladeClientOptions, UploadProgress } from "./blade-client";
|
|
6
7
|
export { BladeApiError } from "./rest";
|
|
@@ -51,3 +52,5 @@ export { PackRecordsResource } from "./resources/pack-records";
|
|
|
51
52
|
export type { PackRecord, PackRecordQuery } from "./resources/pack-records";
|
|
52
53
|
export { attachPackPageBridge } from "./pack-page-bridge";
|
|
53
54
|
export type { PackProfile, ProfileComponent, PackManifest, PackLayoutOperation, InstalledPack } from "./resources/profile";
|
|
55
|
+
export { CapabilitiesResource } from "./resources/capabilities";
|
|
56
|
+
export type { CapabilitySnapshot } from "./resources/capabilities";
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,10 @@ import {
|
|
|
4
4
|
BladeApiError,
|
|
5
5
|
BladeApplicationClient,
|
|
6
6
|
BladeClient,
|
|
7
|
+
CapabilitiesResource,
|
|
7
8
|
ConnectorsResource,
|
|
8
9
|
DEFAULT_REPLAY_SPEED,
|
|
10
|
+
FeishuBotsResource,
|
|
9
11
|
PackRecordsResource,
|
|
10
12
|
PacksResource,
|
|
11
13
|
ProfileResource,
|
|
@@ -30,15 +32,17 @@ import {
|
|
|
30
32
|
parseAskUserQuestion,
|
|
31
33
|
transformSlashCommand,
|
|
32
34
|
userFacingErrorText
|
|
33
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-J5HK3PPV.js";
|
|
34
36
|
export {
|
|
35
37
|
AgentSession,
|
|
36
38
|
AgentSessionError,
|
|
37
39
|
BladeApiError,
|
|
38
40
|
BladeApplicationClient,
|
|
39
41
|
BladeClient,
|
|
42
|
+
CapabilitiesResource,
|
|
40
43
|
ConnectorsResource,
|
|
41
44
|
DEFAULT_REPLAY_SPEED,
|
|
45
|
+
FeishuBotsResource,
|
|
42
46
|
PackRecordsResource,
|
|
43
47
|
PacksResource,
|
|
44
48
|
ProfileResource,
|
package/dist/internal.js
CHANGED
|
@@ -5,12 +5,14 @@ import {
|
|
|
5
5
|
BladeApiError,
|
|
6
6
|
BladeApplicationClient,
|
|
7
7
|
BladeClient,
|
|
8
|
+
CapabilitiesResource,
|
|
8
9
|
ChatGroupsResource,
|
|
9
10
|
ClientProjectionBuilder,
|
|
10
11
|
ComputersResource,
|
|
11
12
|
ConnectorsResource,
|
|
12
13
|
DEFAULT_REPLAY_SPEED,
|
|
13
14
|
EMPTY_SESSION_QUEUE,
|
|
15
|
+
FeishuBotsResource,
|
|
14
16
|
ModelsResource,
|
|
15
17
|
OOM_MESSAGE,
|
|
16
18
|
PackRecordsResource,
|
|
@@ -100,7 +102,7 @@ import {
|
|
|
100
102
|
withTurns,
|
|
101
103
|
workflowEntriesFromOutput,
|
|
102
104
|
workflowNameFromArguments
|
|
103
|
-
} from "./chunk-
|
|
105
|
+
} from "./chunk-J5HK3PPV.js";
|
|
104
106
|
|
|
105
107
|
// src/polling-backoff.ts
|
|
106
108
|
var MAX_BACKOFF_MS = 6e4;
|
|
@@ -272,6 +274,7 @@ export {
|
|
|
272
274
|
BladeApiError,
|
|
273
275
|
BladeApplicationClient,
|
|
274
276
|
BladeClient,
|
|
277
|
+
CapabilitiesResource,
|
|
275
278
|
ChatGroupsResource,
|
|
276
279
|
ClientProjectionBuilder,
|
|
277
280
|
ComputersResource,
|
|
@@ -279,6 +282,7 @@ export {
|
|
|
279
282
|
DEFAULT_REPLAY_SPEED,
|
|
280
283
|
EMPTY_PLATFORM_ENDPOINTS,
|
|
281
284
|
EMPTY_SESSION_QUEUE,
|
|
285
|
+
FeishuBotsResource,
|
|
282
286
|
LayoutType,
|
|
283
287
|
ModelsResource,
|
|
284
288
|
OOM_MESSAGE,
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/polling-backoff.ts","../src/platform-endpoints.ts","../src/commands/protocol.ts","../src/schemas/projection-utils.ts","../src/schemas/solution.ts","../src/schemas/task.ts"],"sourcesContent":["import { BladeApiError } from \"./rest\"\n\nconst MAX_BACKOFF_MS = 60_000\nconst MAX_TIMER_MS = 2_147_483_647\n\n/** Scheduling policy for read-only polling; never sends or replays a request. */\nexport class PollingBackoff {\n private failures = 0\n private nextAt: number | false = 0\n\n constructor(private readonly intervalMs: number) {\n if (!Number.isFinite(intervalMs) || intervalMs <= 0 || intervalMs > MAX_BACKOFF_MS) {\n throw new RangeError(\"Polling interval must be between 0 and 60000 ms\")\n }\n }\n\n reset(): void {\n this.failures = 0\n this.nextAt = 0\n }\n\n failed(error: unknown): void {\n if (\n (error instanceof Error && error.name === \"AbortError\") ||\n (error instanceof BladeApiError && error.status < 500 &&\n error.status !== 408 && error.status !== 429)\n ) {\n this.nextAt = false\n return\n }\n this.failures = Math.min(this.failures + 1, 10)\n const ceiling = Math.min(MAX_BACKOFF_MS, this.intervalMs * 2 ** this.failures)\n const backoff = Math.max(this.intervalMs, ceiling * (0.5 + Math.random() * 0.5))\n const header = error instanceof BladeApiError\n ? error.response.headers.get(\"Retry-After\")?.trim()\n : undefined\n const retryAfter = header\n ? /^\\d+$/.test(header) ? Number(header) * 1000 : Date.parse(header) - Date.now()\n : 0\n const delay = Math.max(backoff, Number.isNaN(retryAfter) ? 0 : retryAfter)\n // Oversized server delays must not overflow browser timers into a hot loop.\n this.nextAt = delay > MAX_TIMER_MS ? false : Date.now() + delay\n }\n\n /** Zero means ready, false means stop, otherwise wait at least this many ms. */\n waitMs(): number | false {\n return this.nextAt === false ? false : Math.max(0, this.nextAt - Date.now())\n }\n}\n","import { isRecord } from \"./shared/type-guards\"\n\nexport const PLATFORM_SERVICE_NAMES = [\n \"os\",\n \"hub\",\n \"agent\",\n \"oauth\",\n \"llmGateway\",\n \"gitea\",\n \"tile\",\n] as const\n\nexport type PlatformServiceName = (typeof PLATFORM_SERVICE_NAMES)[number]\n\nexport interface PlatformEndpoints {\n services: Partial<Record<PlatformServiceName, string>>\n}\n\nexport const EMPTY_PLATFORM_ENDPOINTS: PlatformEndpoints = Object.freeze({\n services: Object.freeze({}),\n})\n\nexport interface LoadPlatformEndpointsOptions {\n baseUrl?: string\n fetchImpl?: typeof fetch\n timeoutMs?: number\n}\n\nfunction defaultDocumentBaseUrl(): string | undefined {\n if (typeof document === \"undefined\") return undefined\n if (document.querySelector(\"base[href]\")) return document.baseURI\n if (typeof location !== \"undefined\" && location.origin) return `${location.origin}/`\n return document.baseURI\n}\n\nfunction normalizeServiceUrl(value: unknown): string | null {\n if (typeof value !== \"string\" || !value.trim()) return null\n if (value.includes(\"?\") || value.includes(\"#\")) return null\n try {\n const url = new URL(value.trim())\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") return null\n if (url.username || url.password || url.search || url.hash) return null\n return url.toString().replace(/\\/$/, \"\")\n } catch {\n return null\n }\n}\n\nexport function parsePlatformEndpoints(value: unknown): PlatformEndpoints | null {\n if (!isRecord(value) || !isRecord(value.services)) return null\n\n const services: Partial<Record<PlatformServiceName, string>> = {}\n for (const name of PLATFORM_SERVICE_NAMES) {\n if (!(name in value.services)) continue\n const url = normalizeServiceUrl(value.services[name])\n if (!url) return null\n if (name === \"agent\" && new URL(url).pathname !== \"/\") return null\n services[name] = url\n }\n\n return { services }\n}\n\nexport async function loadPlatformEndpoints(\n options: LoadPlatformEndpointsOptions = {},\n): Promise<PlatformEndpoints> {\n const fetchImpl = options.fetchImpl ?? globalThis.fetch\n const baseUrl = options.baseUrl ?? defaultDocumentBaseUrl()\n if (!fetchImpl || !baseUrl) return EMPTY_PLATFORM_ENDPOINTS\n\n const controller = new AbortController()\n const timeout = globalThis.setTimeout(() => controller.abort(), options.timeoutMs ?? 3_000)\n try {\n const response = await fetchImpl(new URL(\"config.json\", baseUrl), {\n cache: \"no-store\",\n credentials: \"same-origin\",\n headers: { Accept: \"application/json\" },\n signal: controller.signal,\n })\n if (!response.ok) return EMPTY_PLATFORM_ENDPOINTS\n return parsePlatformEndpoints(await response.json()) ?? EMPTY_PLATFORM_ENDPOINTS\n } catch {\n return EMPTY_PLATFORM_ENDPOINTS\n } finally {\n globalThis.clearTimeout(timeout)\n }\n}\n\nexport function resolveServiceUrl(\n endpoints: PlatformEndpoints,\n name: PlatformServiceName,\n path = \"\",\n): string | null {\n const baseUrl = endpoints.services[name]\n if (!baseUrl) return null\n if (!path) return baseUrl\n const pathReference = path.trimStart()\n if (\n path.includes(\"\\\\\") ||\n pathReference.startsWith(\"//\") ||\n /^[a-z][a-z0-9+.-]*:/i.test(pathReference)\n ) {\n return null\n }\n const base = new URL(`${baseUrl}/`)\n const target = new URL(path.replace(/^\\/+/, \"\"), base)\n if (target.origin !== base.origin || !target.pathname.startsWith(base.pathname)) {\n return null\n }\n return target.toString()\n}\n","/**\n * 页面协作协议(对应后端 `_meta.bridge` 通道,见 docs/specs/260417-embed-bridge)。\n *\n * ## action 从哪里来\n *\n * 智能体 → 宿主方向的每一条指令,都源自**技能作者写的工具代码**:工具返回值\n * JSON 里带 `_meta.bridge: { action, payload }`,后端在持久化前把它剥离成独立\n * 事件送达前端(LLM 的对话历史里读不到它)。因此:\n *\n * - action 字符串(如 \"map.highlight\")是**技能作者与宿主页面开发者之间的业务\n * 契约**,LLM 不参与协议、SDK 不做枚举校验;\n * - 宿主页面用 `session.onCommand(\"map.highlight\", fn)` 消费;\n * - 未注册 handler 的 action 会进入有限缓冲等待注册,超限后丢弃并 console 告警。\n *\n * 宿主 → 智能体方向只有三个白名单动作:attach(附件入输入框)/ insertText\n * (追加输入文本)/ send(直接发消息),对应协议层的 addContext / appendInput /\n * sendMessage。\n */\n\nexport interface CommandEnvelope {\n __bladeBridge: true\n direction: \"agent-to-host\"\n action: string\n payload: unknown\n meta: {\n sessionId: string\n toolCallId?: string\n timestamp: number\n }\n}\n\nexport type InboundAction = \"addContext\" | \"appendInput\" | \"sendMessage\"\n\nexport interface InboundEnvelope {\n __bladeBridge: true\n direction: \"host-to-agent\"\n action: InboundAction\n payload: unknown\n}\n\nexport function isCommandEnvelope(value: unknown): value is CommandEnvelope {\n if (typeof value !== \"object\" || value === null) return false\n const record = value as Record<string, unknown>\n return (\n record.__bladeBridge === true &&\n record.direction === \"agent-to-host\" &&\n typeof record.action === \"string\"\n )\n}\n\nexport function isInboundEnvelope(value: unknown): value is InboundEnvelope {\n if (typeof value !== \"object\" || value === null) return false\n const record = value as Record<string, unknown>\n return (\n record.__bladeBridge === true &&\n record.direction === \"host-to-agent\" &&\n (record.action === \"addContext\" || record.action === \"appendInput\" || record.action === \"sendMessage\")\n )\n}\n","import type { PostChatFollowup, TurnProjection } from \"./projection\"\n\n/** 返回最新根会话轮次的小结;新用户消息到达后旧小结立即失效。 */\nexport function latestPostChatFollowup(turns: TurnProjection[]): PostChatFollowup | null {\n for (let index = turns.length - 1; index >= 0; index -= 1) {\n const turn = turns[index]\n if (\n turn.loop_id === \"root\" &&\n (turn.role === \"user\" || turn.role === \"assistant\") &&\n (turn.kind ?? \"message\") === \"message\" &&\n !turn.blocks.some((block) =>\n [\"mode_change\", \"plan_status\", \"ask_user_answer\"].includes(block.type),\n )\n ) {\n return turn.role === \"assistant\" ? (turn.post_chat_followup ?? null) : null\n }\n }\n return null\n}\n","export enum LayoutType {\n Default = \"default\",\n SkillEditor = \"skill-editor\",\n SolutionEditor = \"solution-editor\",\n SolutionApp = \"solution-app\",\n Custom = \"custom\",\n}\n\nexport interface Solution {\n id: string\n name: string\n version: string\n description?: string | null\n source?: \"builtin\" | \"personal\" | string | null\n layout_type: LayoutType | string\n initial_mode?: \"planning\" | \"executing\" | string | null\n initial_message?: string | null\n preview?: { url: string; title?: string | null } | null\n layout?: {\n available?: boolean\n source_dir?: string\n entry?: string\n export?: string\n } | null\n roles?: BizRole[] | null\n data?: Record<string, unknown> | null\n ui_config?: SolutionAppUiConfig | null\n}\n\nexport interface SolutionAppUiConfig {\n branding: {\n name: string\n subtitle?: string\n icon_text: string\n icon_gradient?: string\n }\n list: {\n title: string\n create_button: string\n card?: {\n subtitle?: string\n stats?: Array<{\n label: string\n value: string\n color?: string\n }>\n }\n }\n create: {\n title: string\n description?: string\n submit_button: string\n sections: Array<{\n id: string\n title: string\n description?: string\n fields: Array<SolutionAppField>\n }>\n }\n}\n\nexport type SolutionAppField =\n | {\n id: string\n kind: \"textarea\"\n label: string\n placeholder?: string\n }\n | {\n id: string\n kind: \"file-upload\"\n accept?: string[]\n categories?: Array<{\n label: string\n description: string\n color: string\n }>\n }\n\nexport interface SolutionAppState {\n pipeline: Array<{\n id: string\n label: string\n status: \"done\" | \"active\" | \"pending\" | \"error\"\n }>\n meta: Record<\n string,\n {\n label: string\n value: string\n color?: string\n }\n >\n}\n\nexport interface BizRole {\n id: string\n name: string\n description?: string | null\n preview?: { url: string; title?: string | null } | null\n}\n","import { type } from \"arktype\"\n\nexport const TaskStatus = type(\"'pending' | 'in_progress' | 'done' | 'failed' | 'skipped'\")\nexport type TaskStatus = typeof TaskStatus.infer\n\nexport const Task = type({\n id: \"string\",\n goal: \"string\",\n skills: \"string[]\",\n depends_on: \"string[]\",\n status: TaskStatus,\n result_summary: \"string\",\n number: \"string\",\n})\nexport type Task = typeof Task.infer\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,iBAAiB;AACvB,IAAM,eAAe;AAGd,IAAM,iBAAN,MAAqB;AAAA,EAI1B,YAA6B,YAAoB;AAApB;AAC3B,QAAI,CAAC,OAAO,SAAS,UAAU,KAAK,cAAc,KAAK,aAAa,gBAAgB;AAClF,YAAM,IAAI,WAAW,iDAAiD;AAAA,IACxE;AAAA,EACF;AAAA,EAJ6B;AAAA,EAHrB,WAAW;AAAA,EACX,SAAyB;AAAA,EAQjC,QAAc;AACZ,SAAK,WAAW;AAChB,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,OAAO,OAAsB;AAC3B,QACG,iBAAiB,SAAS,MAAM,SAAS,gBACzC,iBAAiB,iBAAiB,MAAM,SAAS,OAChD,MAAM,WAAW,OAAO,MAAM,WAAW,KAC3C;AACA,WAAK,SAAS;AACd;AAAA,IACF;AACA,SAAK,WAAW,KAAK,IAAI,KAAK,WAAW,GAAG,EAAE;AAC9C,UAAM,UAAU,KAAK,IAAI,gBAAgB,KAAK,aAAa,KAAK,KAAK,QAAQ;AAC7E,UAAM,UAAU,KAAK,IAAI,KAAK,YAAY,WAAW,MAAM,KAAK,OAAO,IAAI,IAAI;AAC/E,UAAM,SA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ACV,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,oBAAiB;AACjB,EAAAA,YAAA,iBAAc;AACd,EAAAA,YAAA,YAAS;AALC,SAAAA;AAAA,GAAA;;;ACAZ,SAAS,YAAY;AAEd,IAAM,aAAa,KAAK,2DAA2D;AAGnF,IAAM,OAAO,KAAK;AAAA,EACvB,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,gBAAgB;AAAA,EAChB,QAAQ;AACV,CAAC;","names":["LayoutType"]}
|
|
1
|
+
{"version":3,"sources":["../src/polling-backoff.ts","../src/platform-endpoints.ts","../src/commands/protocol.ts","../src/schemas/projection-utils.ts","../src/schemas/solution.ts","../src/schemas/task.ts"],"sourcesContent":["import { BladeApiError } from \"./rest\"\n\nconst MAX_BACKOFF_MS = 60_000\nconst MAX_TIMER_MS = 2_147_483_647\n\n/** Scheduling policy for read-only polling; never sends or replays a request. */\nexport class PollingBackoff {\n private failures = 0\n private nextAt: number | false = 0\n\n constructor(private readonly intervalMs: number) {\n if (!Number.isFinite(intervalMs) || intervalMs <= 0 || intervalMs > MAX_BACKOFF_MS) {\n throw new RangeError(\"Polling interval must be between 0 and 60000 ms\")\n }\n }\n\n reset(): void {\n this.failures = 0\n this.nextAt = 0\n }\n\n failed(error: unknown): void {\n if (\n (error instanceof Error && error.name === \"AbortError\") ||\n (error instanceof BladeApiError && error.status < 500 &&\n error.status !== 408 && error.status !== 429)\n ) {\n this.nextAt = false\n return\n }\n this.failures = Math.min(this.failures + 1, 10)\n const ceiling = Math.min(MAX_BACKOFF_MS, this.intervalMs * 2 ** this.failures)\n const backoff = Math.max(this.intervalMs, ceiling * (0.5 + Math.random() * 0.5))\n const header = error instanceof BladeApiError\n ? error.response.headers.get(\"Retry-After\")?.trim()\n : undefined\n const retryAfter = header\n ? /^\\d+$/.test(header) ? Number(header) * 1000 : Date.parse(header) - Date.now()\n : 0\n const delay = Math.max(backoff, Number.isNaN(retryAfter) ? 0 : retryAfter)\n // Oversized server delays must not overflow browser timers into a hot loop.\n this.nextAt = delay > MAX_TIMER_MS ? false : Date.now() + delay\n }\n\n /** Zero means ready, false means stop, otherwise wait at least this many ms. */\n waitMs(): number | false {\n return this.nextAt === false ? false : Math.max(0, this.nextAt - Date.now())\n }\n}\n","import { isRecord } from \"./shared/type-guards\"\n\nexport const PLATFORM_SERVICE_NAMES = [\n \"os\",\n \"hub\",\n \"agent\",\n \"oauth\",\n \"llmGateway\",\n \"gitea\",\n \"tile\",\n] as const\n\nexport type PlatformServiceName = (typeof PLATFORM_SERVICE_NAMES)[number]\n\nexport interface PlatformEndpoints {\n services: Partial<Record<PlatformServiceName, string>>\n}\n\nexport const EMPTY_PLATFORM_ENDPOINTS: PlatformEndpoints = Object.freeze({\n services: Object.freeze({}),\n})\n\nexport interface LoadPlatformEndpointsOptions {\n baseUrl?: string\n fetchImpl?: typeof fetch\n timeoutMs?: number\n}\n\nfunction defaultDocumentBaseUrl(): string | undefined {\n if (typeof document === \"undefined\") return undefined\n if (document.querySelector(\"base[href]\")) return document.baseURI\n if (typeof location !== \"undefined\" && location.origin) return `${location.origin}/`\n return document.baseURI\n}\n\nfunction normalizeServiceUrl(value: unknown): string | null {\n if (typeof value !== \"string\" || !value.trim()) return null\n if (value.includes(\"?\") || value.includes(\"#\")) return null\n try {\n const url = new URL(value.trim())\n if (url.protocol !== \"http:\" && url.protocol !== \"https:\") return null\n if (url.username || url.password || url.search || url.hash) return null\n return url.toString().replace(/\\/$/, \"\")\n } catch {\n return null\n }\n}\n\nexport function parsePlatformEndpoints(value: unknown): PlatformEndpoints | null {\n if (!isRecord(value) || !isRecord(value.services)) return null\n\n const services: Partial<Record<PlatformServiceName, string>> = {}\n for (const name of PLATFORM_SERVICE_NAMES) {\n if (!(name in value.services)) continue\n const url = normalizeServiceUrl(value.services[name])\n if (!url) return null\n if (name === \"agent\" && new URL(url).pathname !== \"/\") return null\n services[name] = url\n }\n\n return { services }\n}\n\nexport async function loadPlatformEndpoints(\n options: LoadPlatformEndpointsOptions = {},\n): Promise<PlatformEndpoints> {\n const fetchImpl = options.fetchImpl ?? globalThis.fetch\n const baseUrl = options.baseUrl ?? defaultDocumentBaseUrl()\n if (!fetchImpl || !baseUrl) return EMPTY_PLATFORM_ENDPOINTS\n\n const controller = new AbortController()\n const timeout = globalThis.setTimeout(() => controller.abort(), options.timeoutMs ?? 3_000)\n try {\n const response = await fetchImpl(new URL(\"config.json\", baseUrl), {\n cache: \"no-store\",\n credentials: \"same-origin\",\n headers: { Accept: \"application/json\" },\n signal: controller.signal,\n })\n if (!response.ok) return EMPTY_PLATFORM_ENDPOINTS\n return parsePlatformEndpoints(await response.json()) ?? EMPTY_PLATFORM_ENDPOINTS\n } catch {\n return EMPTY_PLATFORM_ENDPOINTS\n } finally {\n globalThis.clearTimeout(timeout)\n }\n}\n\nexport function resolveServiceUrl(\n endpoints: PlatformEndpoints,\n name: PlatformServiceName,\n path = \"\",\n): string | null {\n const baseUrl = endpoints.services[name]\n if (!baseUrl) return null\n if (!path) return baseUrl\n const pathReference = path.trimStart()\n if (\n path.includes(\"\\\\\") ||\n pathReference.startsWith(\"//\") ||\n /^[a-z][a-z0-9+.-]*:/i.test(pathReference)\n ) {\n return null\n }\n const base = new URL(`${baseUrl}/`)\n const target = new URL(path.replace(/^\\/+/, \"\"), base)\n if (target.origin !== base.origin || !target.pathname.startsWith(base.pathname)) {\n return null\n }\n return target.toString()\n}\n","/**\n * 页面协作协议(对应后端 `_meta.bridge` 通道,见 docs/specs/260417-embed-bridge)。\n *\n * ## action 从哪里来\n *\n * 智能体 → 宿主方向的每一条指令,都源自**技能作者写的工具代码**:工具返回值\n * JSON 里带 `_meta.bridge: { action, payload }`,后端在持久化前把它剥离成独立\n * 事件送达前端(LLM 的对话历史里读不到它)。因此:\n *\n * - action 字符串(如 \"map.highlight\")是**技能作者与宿主页面开发者之间的业务\n * 契约**,LLM 不参与协议、SDK 不做枚举校验;\n * - 宿主页面用 `session.onCommand(\"map.highlight\", fn)` 消费;\n * - 未注册 handler 的 action 会进入有限缓冲等待注册,超限后丢弃并 console 告警。\n *\n * 宿主 → 智能体方向只有三个白名单动作:attach(附件入输入框)/ insertText\n * (追加输入文本)/ send(直接发消息),对应协议层的 addContext / appendInput /\n * sendMessage。\n */\n\nexport interface CommandEnvelope {\n __bladeBridge: true\n direction: \"agent-to-host\"\n action: string\n payload: unknown\n meta: {\n sessionId: string\n toolCallId?: string\n timestamp: number\n }\n}\n\nexport type InboundAction = \"addContext\" | \"appendInput\" | \"sendMessage\"\n\nexport interface InboundEnvelope {\n __bladeBridge: true\n direction: \"host-to-agent\"\n action: InboundAction\n payload: unknown\n}\n\nexport function isCommandEnvelope(value: unknown): value is CommandEnvelope {\n if (typeof value !== \"object\" || value === null) return false\n const record = value as Record<string, unknown>\n return (\n record.__bladeBridge === true &&\n record.direction === \"agent-to-host\" &&\n typeof record.action === \"string\"\n )\n}\n\nexport function isInboundEnvelope(value: unknown): value is InboundEnvelope {\n if (typeof value !== \"object\" || value === null) return false\n const record = value as Record<string, unknown>\n return (\n record.__bladeBridge === true &&\n record.direction === \"host-to-agent\" &&\n (record.action === \"addContext\" || record.action === \"appendInput\" || record.action === \"sendMessage\")\n )\n}\n","import type { PostChatFollowup, TurnProjection } from \"./projection\"\n\n/** 返回最新根会话轮次的小结;新用户消息到达后旧小结立即失效。 */\nexport function latestPostChatFollowup(turns: TurnProjection[]): PostChatFollowup | null {\n for (let index = turns.length - 1; index >= 0; index -= 1) {\n const turn = turns[index]\n if (\n turn.loop_id === \"root\" &&\n (turn.role === \"user\" || turn.role === \"assistant\") &&\n (turn.kind ?? \"message\") === \"message\" &&\n !turn.blocks.some((block) =>\n [\"mode_change\", \"plan_status\", \"ask_user_answer\"].includes(block.type),\n )\n ) {\n return turn.role === \"assistant\" ? (turn.post_chat_followup ?? null) : null\n }\n }\n return null\n}\n","export enum LayoutType {\n Default = \"default\",\n SkillEditor = \"skill-editor\",\n SolutionEditor = \"solution-editor\",\n SolutionApp = \"solution-app\",\n Custom = \"custom\",\n}\n\nexport interface Solution {\n id: string\n name: string\n version: string\n description?: string | null\n source?: \"builtin\" | \"personal\" | string | null\n layout_type: LayoutType | string\n initial_mode?: \"planning\" | \"executing\" | string | null\n initial_message?: string | null\n preview?: { url: string; title?: string | null } | null\n layout?: {\n available?: boolean\n source_dir?: string\n entry?: string\n export?: string\n } | null\n roles?: BizRole[] | null\n data?: Record<string, unknown> | null\n ui_config?: SolutionAppUiConfig | null\n}\n\nexport interface SolutionAppUiConfig {\n branding: {\n name: string\n subtitle?: string\n icon_text: string\n icon_gradient?: string\n }\n list: {\n title: string\n create_button: string\n card?: {\n subtitle?: string\n stats?: Array<{\n label: string\n value: string\n color?: string\n }>\n }\n }\n create: {\n title: string\n description?: string\n submit_button: string\n sections: Array<{\n id: string\n title: string\n description?: string\n fields: Array<SolutionAppField>\n }>\n }\n}\n\nexport type SolutionAppField =\n | {\n id: string\n kind: \"textarea\"\n label: string\n placeholder?: string\n }\n | {\n id: string\n kind: \"file-upload\"\n accept?: string[]\n categories?: Array<{\n label: string\n description: string\n color: string\n }>\n }\n\nexport interface SolutionAppState {\n pipeline: Array<{\n id: string\n label: string\n status: \"done\" | \"active\" | \"pending\" | \"error\"\n }>\n meta: Record<\n string,\n {\n label: string\n value: string\n color?: string\n }\n >\n}\n\nexport interface BizRole {\n id: string\n name: string\n description?: string | null\n preview?: { url: string; title?: string | null } | null\n}\n","import { type } from \"arktype\"\n\nexport const TaskStatus = type(\"'pending' | 'in_progress' | 'done' | 'failed' | 'skipped'\")\nexport type TaskStatus = typeof TaskStatus.infer\n\nexport const Task = type({\n id: \"string\",\n goal: \"string\",\n skills: \"string[]\",\n depends_on: \"string[]\",\n status: TaskStatus,\n result_summary: \"string\",\n number: \"string\",\n})\nexport type Task = typeof Task.infer\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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** Display snapshot only. Resource services enforce each actual operation. */
|
|
3
|
+
export interface CapabilitySnapshot {
|
|
4
|
+
status: "known" | "unknown";
|
|
5
|
+
capabilities: string[];
|
|
6
|
+
expires_at: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class CapabilitiesResource {
|
|
9
|
+
private client;
|
|
10
|
+
constructor(client: BladeClient);
|
|
11
|
+
get(options?: {
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}): Promise<CapabilitySnapshot>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { BladeClient } from "../blade-client";
|
|
2
|
+
import type { ConnectorArtifact, ConnectorAuthorization, ConnectorAuthorizationFailure } from "./connectors";
|
|
3
|
+
export interface FeishuBotReferenceScope {
|
|
4
|
+
connection_id: string;
|
|
5
|
+
app_id: string;
|
|
6
|
+
}
|
|
7
|
+
export interface FeishuBotConnection extends Omit<ConnectorAuthorization, "provider" | "connection_id" | "reference_scope"> {
|
|
8
|
+
provider: "feishu";
|
|
9
|
+
purpose: "bot";
|
|
10
|
+
connection_id: string;
|
|
11
|
+
reference_scope: {
|
|
12
|
+
connection_id: string;
|
|
13
|
+
app_id?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export type FeishuBotAuthorizationAction = "app" | "poll" | "cancel" | "check" | "finish" | "permissions" | "authorize";
|
|
17
|
+
export interface FeishuBotAuthorizationOptions {
|
|
18
|
+
attempt_id?: string;
|
|
19
|
+
capabilities?: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface FeishuBotArtifact extends ConnectorArtifact {
|
|
22
|
+
reference_scope: FeishuBotReferenceScope;
|
|
23
|
+
}
|
|
24
|
+
export interface FeishuBotScopedRequest {
|
|
25
|
+
reference_scope: FeishuBotReferenceScope;
|
|
26
|
+
}
|
|
27
|
+
export interface FeishuBotOperationResult<T> {
|
|
28
|
+
ok: boolean;
|
|
29
|
+
outcome: "success" | "partial" | "unknown" | "failed";
|
|
30
|
+
data?: T;
|
|
31
|
+
error?: ConnectorAuthorizationFailure;
|
|
32
|
+
warning?: ConnectorAuthorizationFailure;
|
|
33
|
+
reference_scope: FeishuBotReferenceScope;
|
|
34
|
+
trace_id: string;
|
|
35
|
+
}
|
|
36
|
+
export interface FeishuBotReceipt<T = FeishuBotRawMessage> {
|
|
37
|
+
operation_id: string;
|
|
38
|
+
status: "succeeded" | "unknown" | "rejected" | "retryable_rejected";
|
|
39
|
+
message_id?: string;
|
|
40
|
+
chat_id?: string;
|
|
41
|
+
identity?: "bot";
|
|
42
|
+
record_status?: "stored" | "failed" | "unavailable";
|
|
43
|
+
record_reason?: string;
|
|
44
|
+
error?: ConnectorAuthorizationFailure;
|
|
45
|
+
result?: FeishuBotPlatformResult<T>;
|
|
46
|
+
}
|
|
47
|
+
export interface FeishuBotPlatformResult<T> {
|
|
48
|
+
code: number;
|
|
49
|
+
msg?: string;
|
|
50
|
+
data: T;
|
|
51
|
+
}
|
|
52
|
+
export interface FeishuBotRawMessage {
|
|
53
|
+
message_id: string;
|
|
54
|
+
chat_id?: string;
|
|
55
|
+
msg_type?: string;
|
|
56
|
+
create_time?: string;
|
|
57
|
+
update_time?: string;
|
|
58
|
+
root_id?: string;
|
|
59
|
+
parent_id?: string;
|
|
60
|
+
upper_message_id?: string;
|
|
61
|
+
thread_id?: string;
|
|
62
|
+
body?: {
|
|
63
|
+
content: string;
|
|
64
|
+
};
|
|
65
|
+
sender?: {
|
|
66
|
+
id: string;
|
|
67
|
+
id_type: string;
|
|
68
|
+
sender_type: string;
|
|
69
|
+
tenant_key?: string;
|
|
70
|
+
};
|
|
71
|
+
mentions?: Array<{
|
|
72
|
+
key: string;
|
|
73
|
+
id: string;
|
|
74
|
+
id_type: string;
|
|
75
|
+
name: string;
|
|
76
|
+
tenant_key?: string;
|
|
77
|
+
}>;
|
|
78
|
+
deleted?: boolean;
|
|
79
|
+
updated?: boolean;
|
|
80
|
+
}
|
|
81
|
+
export interface FeishuBotMessagePage {
|
|
82
|
+
items: FeishuBotRawMessage[];
|
|
83
|
+
has_more?: boolean;
|
|
84
|
+
page_token?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface FeishuBotHistoryRequest extends FeishuBotScopedRequest {
|
|
87
|
+
chat_id: string;
|
|
88
|
+
chat_type: "p2p" | "group";
|
|
89
|
+
page_token?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface FeishuBotMessageRequest extends Omit<FeishuBotHistoryRequest, "page_token"> {
|
|
92
|
+
message_id: string;
|
|
93
|
+
}
|
|
94
|
+
export interface FeishuBotNames {
|
|
95
|
+
senders: Record<string, string>;
|
|
96
|
+
chats: Record<string, string>;
|
|
97
|
+
}
|
|
98
|
+
export interface FeishuBotResourceRequest extends FeishuBotScopedRequest {
|
|
99
|
+
message_id: string;
|
|
100
|
+
file_key: string;
|
|
101
|
+
type: "image" | "file";
|
|
102
|
+
chat_id?: string;
|
|
103
|
+
chat_type?: "p2p" | "group";
|
|
104
|
+
}
|
|
105
|
+
export interface FeishuBotSendRequest extends FeishuBotScopedRequest {
|
|
106
|
+
chat_id: string;
|
|
107
|
+
text: string;
|
|
108
|
+
idempotency_key: string;
|
|
109
|
+
}
|
|
110
|
+
export interface FeishuBotReplyRequest extends FeishuBotScopedRequest {
|
|
111
|
+
message_id: string;
|
|
112
|
+
text: string;
|
|
113
|
+
idempotency_key: string;
|
|
114
|
+
}
|
|
115
|
+
export interface FeishuBotUploadFileRequest extends FeishuBotScopedRequest {
|
|
116
|
+
request_id: string;
|
|
117
|
+
data: {
|
|
118
|
+
artifact_id: string;
|
|
119
|
+
file_type: "opus" | "mp4" | "pdf" | "doc" | "xls" | "ppt" | "stream";
|
|
120
|
+
duration?: number;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export interface FeishuBotCreateMessageRequest extends FeishuBotScopedRequest {
|
|
124
|
+
request_id: string;
|
|
125
|
+
params: {
|
|
126
|
+
receive_id_type: "open_id" | "chat_id";
|
|
127
|
+
};
|
|
128
|
+
data: {
|
|
129
|
+
receive_id: string;
|
|
130
|
+
msg_type: "text" | "post" | "image" | "file" | "audio" | "media" | "interactive" | "share_chat" | "share_user" | "sticker";
|
|
131
|
+
content: string;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export interface FeishuBotMember {
|
|
135
|
+
member_id: string;
|
|
136
|
+
member_id_type?: string;
|
|
137
|
+
name?: string;
|
|
138
|
+
}
|
|
139
|
+
export interface FeishuBotReplyTypedMessageRequest extends FeishuBotScopedRequest {
|
|
140
|
+
request_id: string;
|
|
141
|
+
params: {
|
|
142
|
+
message_id: string;
|
|
143
|
+
};
|
|
144
|
+
data: Pick<FeishuBotCreateMessageRequest["data"], "msg_type" | "content"> & {
|
|
145
|
+
reply_in_thread?: boolean;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export type FeishuBotReceiptQuery = FeishuBotScopedRequest & ({
|
|
149
|
+
operation_id: string;
|
|
150
|
+
idempotency_key?: never;
|
|
151
|
+
request_id?: never;
|
|
152
|
+
} | {
|
|
153
|
+
operation_id?: never;
|
|
154
|
+
idempotency_key: string;
|
|
155
|
+
request_id?: never;
|
|
156
|
+
} | {
|
|
157
|
+
operation_id?: never;
|
|
158
|
+
idempotency_key?: never;
|
|
159
|
+
request_id: string;
|
|
160
|
+
});
|
|
161
|
+
export interface FeishuBotUser {
|
|
162
|
+
user_id?: string;
|
|
163
|
+
open_id?: string;
|
|
164
|
+
union_id?: string;
|
|
165
|
+
name?: string;
|
|
166
|
+
en_name?: string;
|
|
167
|
+
}
|
|
168
|
+
export type FeishuDocumentType = "doc" | "docx" | "sheet" | "bitable" | "file" | "slides" | "mindnote" | "wiki";
|
|
169
|
+
export interface FeishuDocumentMetadata {
|
|
170
|
+
metas?: Array<{
|
|
171
|
+
doc_token: string;
|
|
172
|
+
doc_type: string;
|
|
173
|
+
title: string;
|
|
174
|
+
}>;
|
|
175
|
+
failed_list?: Array<{
|
|
176
|
+
token: string;
|
|
177
|
+
code: number;
|
|
178
|
+
}>;
|
|
179
|
+
node?: {
|
|
180
|
+
node_token: string;
|
|
181
|
+
obj_token: string;
|
|
182
|
+
obj_type: string;
|
|
183
|
+
title: string;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
export declare class FeishuBotsResource {
|
|
187
|
+
private readonly client;
|
|
188
|
+
constructor(client: BladeClient);
|
|
189
|
+
private path;
|
|
190
|
+
private operation;
|
|
191
|
+
list(init?: RequestInit): Promise<{
|
|
192
|
+
items: FeishuBotConnection[];
|
|
193
|
+
}>;
|
|
194
|
+
create(requestId: string, init?: RequestInit): Promise<FeishuBotConnection>;
|
|
195
|
+
get(id: string, init?: RequestInit): Promise<FeishuBotConnection>;
|
|
196
|
+
authorize(id: string, action: FeishuBotAuthorizationAction, options?: FeishuBotAuthorizationOptions, init?: RequestInit): Promise<FeishuBotConnection>;
|
|
197
|
+
bind(id: string, pushUrl: string, init?: RequestInit): Promise<FeishuBotConnection>;
|
|
198
|
+
pause(id: string, init?: RequestInit): Promise<FeishuBotConnection>;
|
|
199
|
+
resume(id: string, init?: RequestInit): Promise<FeishuBotConnection>;
|
|
200
|
+
private subscription;
|
|
201
|
+
disconnect(id: string, init?: RequestInit): Promise<{
|
|
202
|
+
disconnected: boolean;
|
|
203
|
+
}>;
|
|
204
|
+
getMessage(id: string, request: FeishuBotMessageRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<FeishuBotMessagePage>>>;
|
|
205
|
+
getHistory(id: string, request: FeishuBotHistoryRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<FeishuBotMessagePage>>>;
|
|
206
|
+
getForwardedMessages(id: string, request: FeishuBotMessageRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<FeishuBotMessagePage>>>;
|
|
207
|
+
getUserInfo(id: string, request: FeishuBotScopedRequest & {
|
|
208
|
+
user_id: string;
|
|
209
|
+
}, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<{
|
|
210
|
+
user: FeishuBotUser;
|
|
211
|
+
}>>>;
|
|
212
|
+
resolveNames(id: string, request: FeishuBotScopedRequest & {
|
|
213
|
+
message_ids: string[];
|
|
214
|
+
chat_ids: string[];
|
|
215
|
+
}, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotNames>>;
|
|
216
|
+
downloadResource(id: string, request: FeishuBotResourceRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotArtifact>>;
|
|
217
|
+
sendMessage(id: string, request: FeishuBotSendRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotReceipt>>;
|
|
218
|
+
replyMessage(id: string, request: FeishuBotReplyRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotReceipt>>;
|
|
219
|
+
getReceipt<T = FeishuBotRawMessage>(id: string, request: FeishuBotReceiptQuery, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotReceipt<T>>>;
|
|
220
|
+
getDocumentMetadata(id: string, request: FeishuBotScopedRequest & {
|
|
221
|
+
type: FeishuDocumentType;
|
|
222
|
+
token: string;
|
|
223
|
+
}, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<FeishuDocumentMetadata>>>;
|
|
224
|
+
getDocument(id: string, request: FeishuBotScopedRequest & {
|
|
225
|
+
document_id: string;
|
|
226
|
+
}, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<{
|
|
227
|
+
document: {
|
|
228
|
+
document_id: string;
|
|
229
|
+
title: string;
|
|
230
|
+
revision_id?: number;
|
|
231
|
+
};
|
|
232
|
+
}>>>;
|
|
233
|
+
getChatInfo(id: string, request: FeishuBotScopedRequest & {
|
|
234
|
+
chat_id: string;
|
|
235
|
+
}, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<{
|
|
236
|
+
chat_id?: string;
|
|
237
|
+
name?: string;
|
|
238
|
+
description?: string;
|
|
239
|
+
}>>>;
|
|
240
|
+
listChatMembers(id: string, request: FeishuBotScopedRequest & {
|
|
241
|
+
chat_id: string;
|
|
242
|
+
page_token?: string;
|
|
243
|
+
page_size?: number;
|
|
244
|
+
}, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<{
|
|
245
|
+
items: FeishuBotMember[];
|
|
246
|
+
has_more?: boolean;
|
|
247
|
+
page_token?: string;
|
|
248
|
+
}>>>;
|
|
249
|
+
listChatBots(id: string, request: FeishuBotScopedRequest & {
|
|
250
|
+
chat_id: string;
|
|
251
|
+
}, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotPlatformResult<{
|
|
252
|
+
items?: Array<{
|
|
253
|
+
app_id: string;
|
|
254
|
+
name?: string;
|
|
255
|
+
}>;
|
|
256
|
+
}>>>;
|
|
257
|
+
uploadFile(id: string, request: FeishuBotUploadFileRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotReceipt<{
|
|
258
|
+
file_key: string;
|
|
259
|
+
}>>>;
|
|
260
|
+
uploadImage(id: string, request: FeishuBotScopedRequest & {
|
|
261
|
+
request_id: string;
|
|
262
|
+
data: {
|
|
263
|
+
artifact_id: string;
|
|
264
|
+
image_type: "message";
|
|
265
|
+
};
|
|
266
|
+
}, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotReceipt<{
|
|
267
|
+
image_key: string;
|
|
268
|
+
}>>>;
|
|
269
|
+
createMessage(id: string, request: FeishuBotCreateMessageRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotReceipt>>;
|
|
270
|
+
replyTypedMessage(id: string, request: FeishuBotReplyTypedMessageRequest, init?: RequestInit): Promise<FeishuBotOperationResult<FeishuBotReceipt>>;
|
|
271
|
+
uploadArtifact(id: string, file: Blob, filename: string, requestId: string, init?: RequestInit): Promise<FeishuBotArtifact>;
|
|
272
|
+
downloadArtifact(id: string, artifactId: string, init?: RequestInit): Promise<Response>;
|
|
273
|
+
}
|