@tool-bridge/server 0.23.0 → 0.25.0
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/dist/admin.js +164 -5
- package/dist/{airtable-VMQVXLHK.js → airtable-4HFPBKO2.js} +6 -6
- package/dist/{alt_text_generator_ai-FTWY4RU4.js → alt_text_generator_ai-TBGJCAWO.js} +5 -5
- package/dist/{amap-OK5VBHYC.js → amap-V2WZ4GP4.js} +5 -5
- package/dist/{anthropic-S67AZFZ3.js → anthropic-HVNDGFRH.js} +6 -6
- package/dist/{apify-ZE6MYQI3.js → apify-TI5DOAUG.js} +6 -6
- package/dist/{brave_search-TG2M2KOD.js → brave_search-7GFBVUIH.js} +6 -6
- package/dist/{chunk-BADVCN6K.js → chunk-3VF7MQJX.js} +40 -3
- package/dist/{chunk-TDAWLMDE.js → chunk-CXRQCZBS.js} +3 -3
- package/dist/{chunk-VWRUGUSU.js → chunk-G6GI7EMV.js} +3 -3
- package/dist/{chunk-7CTWGTDU.js → chunk-KVLI7ZFI.js} +2 -2
- package/dist/{chunk-2JNAI4OC.js → chunk-N7ZFZWGA.js} +1 -1
- package/dist/{chunk-5ICRY3VU.js → chunk-TF2N67HN.js} +1755 -1349
- package/dist/{chunk-4XJPN3DY.js → chunk-UKITQ6LN.js} +3792 -2881
- package/dist/{chunk-WJHG6OK7.js → chunk-UVG4PNWV.js} +2 -2
- package/dist/{circleci-3L3WJVSK.js → circleci-75NMIPKV.js} +6 -6
- package/dist/{clerk-EZPF2V7T.js → clerk-PB2SJAMC.js} +6 -6
- package/dist/{cohere-U27DPO64.js → cohere-UBIMGBOU.js} +6 -6
- package/dist/{confluence-G2KL6ERH.js → confluence-5436ZQBW.js} +6 -6
- package/dist/{convertapi-L4CLJ2M3.js → convertapi-CZILNAZL.js} +4 -4
- package/dist/{currencyapi-YPYXG7YY.js → currencyapi-IPUUA4ZC.js} +6 -6
- package/dist/{deepseek-6HT6WF3M.js → deepseek-F2JV4HEE.js} +6 -6
- package/dist/{docker_hub-LPE3PCVB.js → docker_hub-TRH7EULS.js} +5 -5
- package/dist/{dropbox-V56ABHTA.js → dropbox-4DCC6FQ7.js} +6 -6
- package/dist/{dub-6OKQ7MHT.js → dub-RSI5NDXK.js} +6 -6
- package/dist/{e2b-JS2U2QFU.js → e2b-KM4FJOXS.js} +6 -6
- package/dist/{exa-DPWVYXSP.js → exa-MF26RJSD.js} +6 -6
- package/dist/{fal_ai-DK6Y27ZF.js → fal_ai-4I4QJKBZ.js} +6 -6
- package/dist/{feishu-K7EGSRF3.js → feishu-KEBTN5OD.js} +3 -3
- package/dist/{feishu_custom_bot-2JUGFYNG.js → feishu_custom_bot-KJTIB3PG.js} +4 -4
- package/dist/{figma-FT5I7ITD.js → figma-OFW54Q54.js} +6 -6
- package/dist/{firehydrant-EIKLKHX2.js → firehydrant-RU3B7DXC.js} +6 -6
- package/dist/{fixer-U5QXIAKD.js → fixer-QZ4WCQN3.js} +5 -5
- package/dist/{fly-T3JYFZ2M.js → fly-ZPUXZ5Y7.js} +6 -6
- package/dist/{front-D72MGVOR.js → front-SCMVKIEA.js} +6 -6
- package/dist/{geocodio-BOTD5TI5.js → geocodio-N3QYPBRC.js} +5 -5
- package/dist/{ghost-KYP7SZGB.js → ghost-VMSBR3TP.js} +5 -5
- package/dist/{github-AGMZT3VY.js → github-XOML5UVH.js} +6 -6
- package/dist/github_events-5FCIB5E3.js +78 -0
- package/dist/{gmail-BLJNJOBG.js → gmail-FX3TTLAE.js} +6 -6
- package/dist/{googlecalendar-GTHWNCF6.js → googlecalendar-LWMUNEF5.js} +6 -6
- package/dist/{googledocs-6EEDMEBQ.js → googledocs-ZGVN66MU.js} +4 -4
- package/dist/{grafana-GMW6EKSQ.js → grafana-NKZPJG5L.js} +6 -6
- package/dist/{graphhopper-6OLGBDGB.js → graphhopper-XCRPVZNX.js} +5 -5
- package/dist/index.d.ts +315 -5
- package/dist/index.js +7 -5
- package/dist/{ip2proxy-4QN42E6T.js → ip2proxy-RDDJFPLQ.js} +5 -5
- package/dist/{ipgeolocation_io-SK4XKDA2.js → ipgeolocation_io-RTUJKI3Z.js} +5 -5
- package/dist/{ipqualityscore-6ANBPXKT.js → ipqualityscore-5NG5KR33.js} +5 -5
- package/dist/{jina_ai-IHPSVRM5.js → jina_ai-VG5X5JBE.js} +6 -6
- package/dist/{jira-46KKM4LC.js → jira-LS6ITOSL.js} +6 -6
- package/dist/{langsmith-JZA345I5.js → langsmith-TT26W3A4.js} +6 -6
- package/dist/{lemlist-43IV7DK6.js → lemlist-25WLR36L.js} +6 -6
- package/dist/{linear-5LFH7XNL.js → linear-JLE2CHI3.js} +4 -4
- package/dist/{logsnag-5RMYAHIL.js → logsnag-OI67GLMG.js} +6 -6
- package/dist/main.js +6 -5
- package/dist/{mattermost-XFL6SHGG.js → mattermost-AYJAUGNG.js} +6 -6
- package/dist/{mem0-NYO4DTP6.js → mem0-ZGEAZPCF.js} +6 -6
- package/dist/{memos-37MPQOLV.js → memos-PS2QHWZX.js} +6 -6
- package/dist/{metabase-KYBKZFMG.js → metabase-6F5P4YNZ.js} +6 -6
- package/dist/{mistral_ai-6PL3K4PM.js → mistral_ai-GKF6H3PY.js} +6 -6
- package/dist/{mother_duck-2NH7W5M5.js → mother_duck-C7KWG5OB.js} +6 -6
- package/dist/{ngrok-UO6CDYCA.js → ngrok-UZQYPMSO.js} +6 -6
- package/dist/{notes-I3P32WP4.js → notes-DO7GGFTP.js} +2 -2
- package/dist/{notion-BEAJFUOE.js → notion-JSLD5P5J.js} +6 -6
- package/dist/{open_exchange_rates-CMF62JB4.js → open_exchange_rates-NZYN73GB.js} +5 -5
- package/dist/{openai-IHOMKVND.js → openai-KOXCZZVV.js} +6 -6
- package/dist/{opengraph_io-ZQ2FGLHX.js → opengraph_io-DVAV6AK6.js} +5 -5
- package/dist/{openrouter-HXLW3NR5.js → openrouter-MPMSFAEY.js} +6 -6
- package/dist/{outline-ELCP4NEU.js → outline-E2SNFTFE.js} +6 -6
- package/dist/{paddle-O77LALVN.js → paddle-QOZOMZ6T.js} +6 -6
- package/dist/{perplexity-JCU654QV.js → perplexity-VRWYDYRW.js} +6 -6
- package/dist/{pinecone-W5W4LRKL.js → pinecone-LDU3YSBJ.js} +6 -6
- package/dist/{pipedrive-ITMJLLPZ.js → pipedrive-ZN6NDUPL.js} +6 -6
- package/dist/{polar-R33XU4L3.js → polar-H5GK75YP.js} +6 -6
- package/dist/{posthog-JVNTOLTV.js → posthog-XVJMSCPA.js} +6 -6
- package/dist/{postmark-6SBG7HWV.js → postmark-IVXNOXFI.js} +6 -6
- package/dist/{prerender-GPNKTNFC.js → prerender-FH4SBVJY.js} +5 -5
- package/dist/{pubmed-UP6ZEEIH.js → pubmed-TM7LBALS.js} +4 -4
- package/dist/{railway-KWEWXHTY.js → railway-FJ4XQ2NF.js} +4 -4
- package/dist/{readwise-BLATSMC3.js → readwise-4VQNTOLQ.js} +6 -6
- package/dist/{render-QYRVIXII.js → render-CX7AWO6F.js} +6 -6
- package/dist/{replicate-JYTWH4NF.js → replicate-U6T7GYMR.js} +6 -6
- package/dist/{resend-L5N75SZM.js → resend-RDQXZGY6.js} +6 -6
- package/dist/{rootly-MHCPEQ26.js → rootly-AWTSRSIZ.js} +6 -6
- package/dist/{scrapfly-PTPGYSJM.js → scrapfly-UWX6TBH7.js} +5 -5
- package/dist/{scrapingbee-JN6UH5PY.js → scrapingbee-BKCOLELF.js} +5 -5
- package/dist/{screenshot_fyi-4QRVSV55.js → screenshot_fyi-3OYHV6ZZ.js} +5 -5
- package/dist/{semantic_scholar-LRSWA2GE.js → semantic_scholar-EV2HDKRA.js} +6 -6
- package/dist/{sentry-2G6PF5W6.js → sentry-BPEKPIFX.js} +6 -6
- package/dist/{shodan-WKKPP5C6.js → shodan-RYTNBHVJ.js} +5 -5
- package/dist/{shopify-64YDK5T2.js → shopify-JGWZFCNO.js} +6 -6
- package/dist/{stripe-QAIGGOTF.js → stripe-RBWCW52X.js} +4 -4
- package/dist/{supabase-WHTGR6ND.js → supabase-TX5J2UBD.js} +6 -6
- package/dist/{tavily-QIXCDDWO.js → tavily-33ZRT2RT.js} +6 -6
- package/dist/{telegram-E6G7CWI6.js → telegram-HX3UKW3Y.js} +5 -5
- package/dist/{telnyx-ZDVVS7PK.js → telnyx-5J74OO5R.js} +6 -6
- package/dist/{todoist-DMYF3G7J.js → todoist-6CUCDWTH.js} +6 -6
- package/dist/{trello-HY2RYIRP.js → trello-FTFDRPZ7.js} +5 -5
- package/dist/{turso-HAQWMGRP.js → turso-33T4OAJR.js} +6 -6
- package/dist/{twilio-MLXYPHJE.js → twilio-ZBX6EHFG.js} +4 -4
- package/dist/{umami-DZHBLPVG.js → umami-QCVTF7WS.js} +6 -6
- package/dist/{unsplash-GS2OPXKE.js → unsplash-M6XCQKQE.js} +6 -6
- package/dist/{upstash_redis-XMXWTNAJ.js → upstash_redis-57JQ3XMB.js} +6 -6
- package/dist/{uptimerobot-TF5WRZ4G.js → uptimerobot-KDS5YBKZ.js} +4 -4
- package/dist/{v2ex-2BVXAPDF.js → v2ex-5YPZ6BIT.js} +6 -6
- package/dist/{vercel-YMJGQYJE.js → vercel-6VWZHALZ.js} +6 -6
- package/dist/{wolfram_alpha_api-I56SXWFZ.js → wolfram_alpha_api-4YNRTVTQ.js} +5 -5
- package/dist/{wordpress-R7TDFZ2P.js → wordpress-LKN2EV4B.js} +6 -6
- package/dist/{workos-HDNHWVMS.js → workos-DTPEULYR.js} +6 -6
- package/dist/{zhihu-LX6AGGDS.js → zhihu-LFQRTQS7.js} +6 -6
- package/package.json +5 -5
|
@@ -241,10 +241,10 @@ var AnnotationStore = class {
|
|
|
241
241
|
async list(prefix) {
|
|
242
242
|
const normPrefix = prefix === void 0 ? "" : normalizeAnnotationPath(prefix);
|
|
243
243
|
const out = [];
|
|
244
|
-
let
|
|
244
|
+
let cursor2;
|
|
245
245
|
do {
|
|
246
246
|
const page = await this.store.list(KEY_ANNOTATION, {
|
|
247
|
-
...
|
|
247
|
+
...cursor2 !== void 0 ? { cursor: cursor2 } : {}
|
|
248
248
|
});
|
|
249
249
|
for (const { key, value } of page.items) {
|
|
250
250
|
const path = key.slice(KEY_ANNOTATION.length);
|
|
@@ -259,8 +259,8 @@ var AnnotationStore = class {
|
|
|
259
259
|
updatedBy: typeof a.updatedBy === "string" ? a.updatedBy : ""
|
|
260
260
|
});
|
|
261
261
|
}
|
|
262
|
-
|
|
263
|
-
} while (
|
|
262
|
+
cursor2 = page.cursor;
|
|
263
|
+
} while (cursor2);
|
|
264
264
|
return out.sort((a, b) => a.path.localeCompare(b.path));
|
|
265
265
|
}
|
|
266
266
|
};
|
|
@@ -318,6 +318,7 @@ var LIST_LIMIT_DEFAULT = 50;
|
|
|
318
318
|
var LIST_LIMIT_MAX = 200;
|
|
319
319
|
var ACTIONS = ["read", "write", "call", "register", "admin"];
|
|
320
320
|
var NODE_KINDS = [
|
|
321
|
+
"topic",
|
|
321
322
|
"directory",
|
|
322
323
|
"mcp",
|
|
323
324
|
"http",
|
|
@@ -838,7 +839,8 @@ function cmdPath(nodePath) {
|
|
|
838
839
|
var DESCRIPTION = "Built-in integration catalog (read-only; mount one via system/registry)";
|
|
839
840
|
var NODE_KIND_BY_PROFILE = {
|
|
840
841
|
"tools/v1": "tool",
|
|
841
|
-
"context/v1": "context"
|
|
842
|
+
"context/v1": "context",
|
|
843
|
+
"events/v1": "topic"
|
|
842
844
|
};
|
|
843
845
|
function projectExportAuth(exported) {
|
|
844
846
|
if (exported.oauth !== void 0) return { kind: "oauth" };
|
|
@@ -871,6 +873,7 @@ function projectListItem(entry) {
|
|
|
871
873
|
id: e.id,
|
|
872
874
|
kind,
|
|
873
875
|
auth: projectExportAuth(e),
|
|
876
|
+
...e.eventSource ? { eventSource: e.eventSource } : {},
|
|
874
877
|
...e.description !== void 0 ? { description: e.description } : {},
|
|
875
878
|
...e.mountConfigFields !== void 0 ? { mountConfigFields: e.mountConfigFields } : {}
|
|
876
879
|
};
|
|
@@ -946,22 +949,45 @@ function createCatalogModule(deps) {
|
|
|
946
949
|
}
|
|
947
950
|
|
|
948
951
|
// ../core/src/builtin/plugin.ts
|
|
949
|
-
import { z as
|
|
952
|
+
import { z as z12 } from "zod/v4";
|
|
953
|
+
|
|
954
|
+
// ../core/src/builtin/pluginDistribution.ts
|
|
955
|
+
import { z as z11 } from "zod/v4";
|
|
956
|
+
|
|
957
|
+
// ../core/src/plugin/release.ts
|
|
958
|
+
import { z as z10 } from "zod/v4";
|
|
950
959
|
|
|
951
960
|
// ../core/src/plugin/contract.ts
|
|
952
|
-
import { z as
|
|
961
|
+
import { z as z8 } from "zod";
|
|
962
|
+
|
|
963
|
+
// ../core/src/plugin/eventSource.ts
|
|
964
|
+
import { z as z5 } from "zod/v4";
|
|
965
|
+
var eventBindingSchema = z5.strictObject({
|
|
966
|
+
kind: z5.literal("topic"),
|
|
967
|
+
provider: z5.string().min(1).max(128),
|
|
968
|
+
export: z5.string().min(1).max(128),
|
|
969
|
+
authRef: z5.string().min(1).max(128)
|
|
970
|
+
});
|
|
971
|
+
var eventSourceSchema = z5.strictObject({
|
|
972
|
+
headers: z5.array(z5.string().max(80).regex(/^x-(?!tb-|forwarded-)[a-z0-9-]+$/)).max(12),
|
|
973
|
+
types: z5.array(z5.strictObject({
|
|
974
|
+
type: z5.string().min(1).max(128),
|
|
975
|
+
version: z5.number().int().positive(),
|
|
976
|
+
dataSchema: z5.record(z5.string(), z5.unknown())
|
|
977
|
+
})).min(1).max(64)
|
|
978
|
+
});
|
|
953
979
|
|
|
954
980
|
// ../core/src/plugin/oauth.ts
|
|
955
|
-
import { z as
|
|
981
|
+
import { z as z6 } from "zod";
|
|
956
982
|
var OAUTH_CLIENT_AUTH_METHODS = ["client_secret_basic", "client_secret_post", "none"];
|
|
957
|
-
var httpsUrl =
|
|
983
|
+
var httpsUrl = z6.string().url().refine(
|
|
958
984
|
(value) => {
|
|
959
985
|
const url = new URL2(value);
|
|
960
986
|
return url.protocol === "https:" && !url.hash && !url.username && !url.password;
|
|
961
987
|
},
|
|
962
988
|
"OAuth \u7AEF\u70B9\u5FC5\u987B\u662F HTTPS\uFF0C\u4E14\u4E0D\u80FD\u542B fragment \u6216 URL \u51ED\u8BC1"
|
|
963
989
|
);
|
|
964
|
-
var pluginOAuthSchema =
|
|
990
|
+
var pluginOAuthSchema = z6.object({
|
|
965
991
|
/** 浏览器跳转的授权端点。 */
|
|
966
992
|
authorizationUrl: httpsUrl,
|
|
967
993
|
/** 兑换 code / 刷新令牌的端点。 */
|
|
@@ -969,23 +995,23 @@ var pluginOAuthSchema = z5.object({
|
|
|
969
995
|
/** 刷新端点(缺省同 tokenUrl;个别 provider 分开)。 */
|
|
970
996
|
refreshUrl: httpsUrl.optional(),
|
|
971
997
|
/** 申请的 scope 列表。 */
|
|
972
|
-
scopes:
|
|
998
|
+
scopes: z6.array(z6.string().min(1)).optional(),
|
|
973
999
|
/** scope 分隔符(缺省空格;个别 provider 用逗号)。 */
|
|
974
|
-
scopeSeparator:
|
|
1000
|
+
scopeSeparator: z6.enum([" ", ","]).optional(),
|
|
975
1001
|
/** 客户端认证方式(缺省 client_secret_post)。 */
|
|
976
|
-
clientAuth:
|
|
1002
|
+
clientAuth: z6.enum(OAUTH_CLIENT_AUTH_METHODS).optional(),
|
|
977
1003
|
/**
|
|
978
1004
|
* 授权 URL 的额外静态参数(如 Google 的 `access_type=offline`、
|
|
979
1005
|
* 飞书的 `state` 之外的自定义项)。不得覆盖协议参数。
|
|
980
1006
|
*/
|
|
981
|
-
authorizationParams:
|
|
1007
|
+
authorizationParams: z6.record(z6.string(), z6.string()).optional(),
|
|
982
1008
|
/**
|
|
983
1009
|
* 令牌响应被包了一层信封时的取值路径(如飞书 v2 的 `{code,msg,data:{...}}` → `'data'`)。
|
|
984
1010
|
* 缺省表示响应根就是令牌对象。
|
|
985
1011
|
*/
|
|
986
|
-
responseEnvelope:
|
|
1012
|
+
responseEnvelope: z6.string().min(1).optional(),
|
|
987
1013
|
/** PKCE:缺省启用(S256)。个别老 provider 不支持,置 false。 */
|
|
988
|
-
pkce:
|
|
1014
|
+
pkce: z6.boolean().optional()
|
|
989
1015
|
});
|
|
990
1016
|
var OAUTH_CLIENT_FIELDS = [
|
|
991
1017
|
{
|
|
@@ -1077,16 +1103,16 @@ function buildTokenRequest(opts) {
|
|
|
1077
1103
|
return { body: encodeForm(form), headers };
|
|
1078
1104
|
}
|
|
1079
1105
|
function parseTokenResponse(payload, config, now) {
|
|
1080
|
-
let
|
|
1106
|
+
let source2 = payload;
|
|
1081
1107
|
if (config.responseEnvelope !== void 0) {
|
|
1082
1108
|
const outer = asRecord(payload);
|
|
1083
1109
|
const inner = outer?.[config.responseEnvelope];
|
|
1084
1110
|
if (inner === void 0) {
|
|
1085
1111
|
throw new TBError("invalid_argument", tokenErrorMessage(outer) ?? "\u4EE4\u724C\u54CD\u5E94\u7F3A\u5C11\u4EE4\u724C\u6570\u636E");
|
|
1086
1112
|
}
|
|
1087
|
-
|
|
1113
|
+
source2 = inner;
|
|
1088
1114
|
}
|
|
1089
|
-
const record = asRecord(
|
|
1115
|
+
const record = asRecord(source2);
|
|
1090
1116
|
const accessToken = typeof record?.access_token === "string" ? record.access_token : void 0;
|
|
1091
1117
|
if (accessToken === void 0 || accessToken === "") {
|
|
1092
1118
|
throw new TBError("invalid_argument", tokenErrorMessage(asRecord(payload)) ?? "\u4EE4\u724C\u54CD\u5E94\u7F3A\u5C11 access_token");
|
|
@@ -1104,34 +1130,34 @@ function parseTokenResponse(payload, config, now) {
|
|
|
1104
1130
|
}
|
|
1105
1131
|
|
|
1106
1132
|
// ../core/src/context/commands.ts
|
|
1107
|
-
import { z as
|
|
1108
|
-
var metadataSchema =
|
|
1133
|
+
import { z as z7 } from "zod/v4";
|
|
1134
|
+
var metadataSchema = z7.record(z7.string(), z7.string()).optional().describe(
|
|
1109
1135
|
"string-to-string metadata map"
|
|
1110
1136
|
);
|
|
1111
|
-
var entrySchema =
|
|
1112
|
-
contentType:
|
|
1137
|
+
var entrySchema = z7.strictObject({
|
|
1138
|
+
contentType: z7.string().optional().describe(
|
|
1113
1139
|
"required when content is a string; defaults to application/json for non-string content"
|
|
1114
1140
|
),
|
|
1115
|
-
content:
|
|
1141
|
+
content: z7.unknown().describe("entry body: string, or any JSON value"),
|
|
1116
1142
|
metadata: metadataSchema,
|
|
1117
|
-
ifVersion:
|
|
1143
|
+
ifVersion: z7.string().optional().describe("optimistic concurrency: expected current version")
|
|
1118
1144
|
});
|
|
1119
|
-
var patchSchema =
|
|
1120
|
-
content:
|
|
1145
|
+
var patchSchema = z7.strictObject({
|
|
1146
|
+
content: z7.unknown().optional().describe("replacement content"),
|
|
1121
1147
|
metadata: metadataSchema,
|
|
1122
|
-
ifVersion:
|
|
1148
|
+
ifVersion: z7.string().optional().describe("optimistic concurrency: expected current version")
|
|
1123
1149
|
}).describe("partial update; omitted fields keep their current value");
|
|
1124
|
-
var searchOptionsSchema =
|
|
1125
|
-
cursor:
|
|
1126
|
-
limit:
|
|
1127
|
-
mode:
|
|
1150
|
+
var searchOptionsSchema = z7.strictObject({
|
|
1151
|
+
cursor: z7.string().optional().describe("opaque cursor returned by the previous page"),
|
|
1152
|
+
limit: z7.number().optional().describe("page size (default 50, max 200)"),
|
|
1153
|
+
mode: z7.enum(["keyword", "semantic"]).optional().describe('default "keyword"')
|
|
1128
1154
|
}).describe("pagination + search mode");
|
|
1129
1155
|
var contextCommands = new HtbpCommandRegistry().register(
|
|
1130
1156
|
"list",
|
|
1131
1157
|
{
|
|
1132
1158
|
h: "list entries directly under a path (shallow, paginated)",
|
|
1133
|
-
inputSchema:
|
|
1134
|
-
path:
|
|
1159
|
+
inputSchema: z7.strictObject({
|
|
1160
|
+
path: z7.string().optional().describe("entry path prefix inside the namespace"),
|
|
1135
1161
|
opts: HTBP_LIST_OPTIONS_SCHEMA.optional()
|
|
1136
1162
|
}),
|
|
1137
1163
|
returns: "Page<ContextEntryMeta>",
|
|
@@ -1143,8 +1169,8 @@ var contextCommands = new HtbpCommandRegistry().register(
|
|
|
1143
1169
|
"get",
|
|
1144
1170
|
{
|
|
1145
1171
|
h: "read one entry with content (oversized content comes back as { $ref: <download URL> })",
|
|
1146
|
-
inputSchema:
|
|
1147
|
-
path:
|
|
1172
|
+
inputSchema: z7.strictObject({
|
|
1173
|
+
path: z7.string().describe("entry path inside the namespace")
|
|
1148
1174
|
}),
|
|
1149
1175
|
returns: "ContextEntry",
|
|
1150
1176
|
scope: "read",
|
|
@@ -1155,8 +1181,8 @@ var contextCommands = new HtbpCommandRegistry().register(
|
|
|
1155
1181
|
"write",
|
|
1156
1182
|
{
|
|
1157
1183
|
h: "create or fully replace an entry (idempotent upsert)",
|
|
1158
|
-
inputSchema:
|
|
1159
|
-
path:
|
|
1184
|
+
inputSchema: z7.strictObject({
|
|
1185
|
+
path: z7.string().describe("entry path inside the namespace"),
|
|
1160
1186
|
entry: entrySchema
|
|
1161
1187
|
}),
|
|
1162
1188
|
returns: "ContextEntryMeta",
|
|
@@ -1168,8 +1194,8 @@ var contextCommands = new HtbpCommandRegistry().register(
|
|
|
1168
1194
|
"update",
|
|
1169
1195
|
{
|
|
1170
1196
|
h: "partially update content and/or metadata (shallow merge); not_found if the entry does not exist",
|
|
1171
|
-
inputSchema:
|
|
1172
|
-
path:
|
|
1197
|
+
inputSchema: z7.strictObject({
|
|
1198
|
+
path: z7.string().describe("entry path inside the namespace"),
|
|
1173
1199
|
patch: patchSchema
|
|
1174
1200
|
}),
|
|
1175
1201
|
returns: "ContextEntryMeta",
|
|
@@ -1181,8 +1207,8 @@ var contextCommands = new HtbpCommandRegistry().register(
|
|
|
1181
1207
|
"delete",
|
|
1182
1208
|
{
|
|
1183
1209
|
h: "delete an entry (idempotent)",
|
|
1184
|
-
inputSchema:
|
|
1185
|
-
path:
|
|
1210
|
+
inputSchema: z7.strictObject({
|
|
1211
|
+
path: z7.string().describe("entry path inside the namespace")
|
|
1186
1212
|
}),
|
|
1187
1213
|
scope: "write",
|
|
1188
1214
|
effect: "destructive"
|
|
@@ -1192,8 +1218,8 @@ var contextCommands = new HtbpCommandRegistry().register(
|
|
|
1192
1218
|
"search",
|
|
1193
1219
|
{
|
|
1194
1220
|
h: "keyword search: substring match on entry paths and metadata values",
|
|
1195
|
-
inputSchema:
|
|
1196
|
-
query:
|
|
1221
|
+
inputSchema: z7.strictObject({
|
|
1222
|
+
query: z7.string().describe("substring to match"),
|
|
1197
1223
|
opts: searchOptionsSchema.optional()
|
|
1198
1224
|
}),
|
|
1199
1225
|
returns: "Page<ContextEntryMeta>",
|
|
@@ -1207,10 +1233,10 @@ var contextCommands = new HtbpCommandRegistry().register(
|
|
|
1207
1233
|
h: "create a short-lived, path-scoped direct-upload grant; persist the returned uri, not url",
|
|
1208
1234
|
// 宿主专属扩展:仅在底层具备直传签名能力时由宿主装配,不进基础动词表。
|
|
1209
1235
|
hostOnly: true,
|
|
1210
|
-
inputSchema:
|
|
1211
|
-
path:
|
|
1212
|
-
contentType:
|
|
1213
|
-
overwrite:
|
|
1236
|
+
inputSchema: z7.strictObject({
|
|
1237
|
+
path: z7.string().describe("target entry path inside the namespace"),
|
|
1238
|
+
contentType: z7.string().describe("media type signed into the PUT request"),
|
|
1239
|
+
overwrite: z7.boolean().optional().describe(
|
|
1214
1240
|
"allow replacing an existing object; default false"
|
|
1215
1241
|
)
|
|
1216
1242
|
}),
|
|
@@ -1279,10 +1305,11 @@ function contextCapabilitiesOf(provider) {
|
|
|
1279
1305
|
}
|
|
1280
1306
|
|
|
1281
1307
|
// ../core/src/plugin/contract.ts
|
|
1282
|
-
var PLUGIN_PROFILES = ["tools/v1", "context/v1"];
|
|
1308
|
+
var PLUGIN_PROFILES = ["tools/v1", "context/v1", "events/v1"];
|
|
1283
1309
|
var NODE_KIND_BY_PROFILE2 = {
|
|
1284
1310
|
"tools/v1": "tool",
|
|
1285
|
-
"context/v1": "context"
|
|
1311
|
+
"context/v1": "context",
|
|
1312
|
+
"events/v1": "topic"
|
|
1286
1313
|
};
|
|
1287
1314
|
var OPTIONAL_METHOD_BY_CAPABILITY = {
|
|
1288
1315
|
search: "search",
|
|
@@ -1298,29 +1325,30 @@ function optionalMethodsForCapabilities(capabilities) {
|
|
|
1298
1325
|
return methods;
|
|
1299
1326
|
}
|
|
1300
1327
|
var EXPORT_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
1301
|
-
var exportAuthSchema =
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
kind:
|
|
1305
|
-
description:
|
|
1306
|
-
label:
|
|
1307
|
-
required:
|
|
1328
|
+
var exportAuthSchema = z8.discriminatedUnion("kind", [
|
|
1329
|
+
z8.object({ kind: z8.literal("none") }),
|
|
1330
|
+
z8.object({
|
|
1331
|
+
kind: z8.literal("single"),
|
|
1332
|
+
description: z8.string().optional(),
|
|
1333
|
+
label: z8.string().optional(),
|
|
1334
|
+
required: z8.boolean().optional()
|
|
1308
1335
|
})
|
|
1309
1336
|
]);
|
|
1310
|
-
var exportSchema =
|
|
1311
|
-
id:
|
|
1312
|
-
profile:
|
|
1313
|
-
|
|
1337
|
+
var exportSchema = z8.object({
|
|
1338
|
+
id: z8.string().regex(EXPORT_ID_RE, "export id \u987B\u4E3A [A-Za-z0-9._-] \u4E14\u4E0D\u4EE5\u6807\u70B9\u5F00\u5934"),
|
|
1339
|
+
profile: z8.enum(PLUGIN_PROFILES),
|
|
1340
|
+
eventSource: eventSourceSchema.optional(),
|
|
1341
|
+
description: z8.string().optional(),
|
|
1314
1342
|
/** context/v1:实际提供的动词;tools/v1 由运行时 List 发现,可省。 */
|
|
1315
|
-
methods:
|
|
1316
|
-
capabilities:
|
|
1343
|
+
methods: z8.array(z8.string()).optional(),
|
|
1344
|
+
capabilities: z8.array(z8.string()).optional(),
|
|
1317
1345
|
/** export 的单值/无凭证声明;多字段与 OAuth 继续由各自字段表达。 */
|
|
1318
1346
|
auth: exportAuthSchema.optional(),
|
|
1319
1347
|
/**
|
|
1320
1348
|
* tools/v1 可选:一个**只读、零副作用、无必填入参**的工具名,平台在挂载时拿它做一次
|
|
1321
1349
|
* 真实调用来验证 `authRef` 指向的凭证可用(见 `credentialProbe` 的类型注释)。
|
|
1322
1350
|
*/
|
|
1323
|
-
credentialProbe:
|
|
1351
|
+
credentialProbe: z8.string().optional(),
|
|
1324
1352
|
/**
|
|
1325
1353
|
* 多字段凭证的字段声明(tools/v1)。声明了它,平台就知道该 secret 存的是一个 JSON
|
|
1326
1354
|
* 对象而非单值,并在挂载时校验字段齐全 —— 见 `credentialFields` 的类型注释。
|
|
@@ -1330,29 +1358,29 @@ var exportSchema = z7.object({
|
|
|
1330
1358
|
* `POST /<path>/~authorize` 发起、回调兑换、调用时自动刷新,插件只拿到 access token。
|
|
1331
1359
|
*/
|
|
1332
1360
|
oauth: pluginOAuthSchema.optional(),
|
|
1333
|
-
credentialFields:
|
|
1334
|
-
key:
|
|
1335
|
-
label:
|
|
1336
|
-
description:
|
|
1337
|
-
required:
|
|
1361
|
+
credentialFields: z8.array(z8.object({
|
|
1362
|
+
key: z8.string().regex(/^[A-Za-z_][\w]*$/, "\u5B57\u6BB5\u540D\u987B\u4E3A\u5408\u6CD5\u6807\u8BC6\u7B26"),
|
|
1363
|
+
label: z8.string().optional(),
|
|
1364
|
+
description: z8.string().optional(),
|
|
1365
|
+
required: z8.boolean().optional(),
|
|
1338
1366
|
/** 敏感字段:管理面不回显、日志不打印。缺省按敏感处理(fail safe)。 */
|
|
1339
|
-
secret:
|
|
1367
|
+
secret: z8.boolean().optional()
|
|
1340
1368
|
})).min(1).optional(),
|
|
1341
1369
|
/**
|
|
1342
1370
|
* 非凭证的挂载配置字段(如 baseUrl / instanceUrl / region)。声明了它,平台就知道
|
|
1343
1371
|
* 该 export 挂载时还需要哪些 `providerConfig`,管理面据此渲染带标签的输入框而不是让
|
|
1344
1372
|
* 用户对着一个自由 k=v 框猜 —— 见 `mountConfigFields` 的类型注释。
|
|
1345
1373
|
*/
|
|
1346
|
-
mountConfigFields:
|
|
1347
|
-
key:
|
|
1348
|
-
label:
|
|
1349
|
-
description:
|
|
1350
|
-
required:
|
|
1374
|
+
mountConfigFields: z8.array(z8.object({
|
|
1375
|
+
key: z8.string().regex(/^[A-Za-z_][\w]*$/, "\u5B57\u6BB5\u540D\u987B\u4E3A\u5408\u6CD5\u6807\u8BC6\u7B26"),
|
|
1376
|
+
label: z8.string().optional(),
|
|
1377
|
+
description: z8.string().optional(),
|
|
1378
|
+
required: z8.boolean().optional()
|
|
1351
1379
|
})).min(1).optional()
|
|
1352
1380
|
});
|
|
1353
|
-
var describeSchema =
|
|
1354
|
-
protocolVersion:
|
|
1355
|
-
exports:
|
|
1381
|
+
var describeSchema = z8.object({
|
|
1382
|
+
protocolVersion: z8.string().min(1),
|
|
1383
|
+
exports: z8.array(exportSchema).min(1, "\u81F3\u5C11\u58F0\u660E\u4E00\u4E2A export")
|
|
1356
1384
|
});
|
|
1357
1385
|
function validatePluginContract(input) {
|
|
1358
1386
|
const { manifest } = input;
|
|
@@ -1453,6 +1481,15 @@ function validatePluginContract(input) {
|
|
|
1453
1481
|
keys.add(field.key);
|
|
1454
1482
|
}
|
|
1455
1483
|
}
|
|
1484
|
+
if (exported.profile === "events/v1") {
|
|
1485
|
+
if (!exported.eventSource || exported.auth?.kind !== "single" || !exported.auth.required) {
|
|
1486
|
+
throw new TBError("invalid_argument", "event sources require a verifier credential and declared event types");
|
|
1487
|
+
}
|
|
1488
|
+
const names = exported.eventSource.types.map((item) => item.type);
|
|
1489
|
+
if (new Set(names).size !== names.length) throw new TBError("invalid_argument", "duplicate event type");
|
|
1490
|
+
} else if (exported.eventSource) {
|
|
1491
|
+
throw new TBError("invalid_argument", "eventSource requires events/v1");
|
|
1492
|
+
}
|
|
1456
1493
|
if (exported.profile === "context/v1") {
|
|
1457
1494
|
const known = new Set(CONTEXT_METHODS);
|
|
1458
1495
|
const unknown = (exported.methods ?? []).filter((m) => !known.has(m));
|
|
@@ -1511,7 +1548,7 @@ function resolvePluginExport(describe, opts) {
|
|
|
1511
1548
|
}
|
|
1512
1549
|
|
|
1513
1550
|
// ../core/src/plugin/manifest.ts
|
|
1514
|
-
import { z as
|
|
1551
|
+
import { z as z9 } from "zod";
|
|
1515
1552
|
|
|
1516
1553
|
// ../core/src/tool/upstreamError.ts
|
|
1517
1554
|
function normalizeUpstreamError(e) {
|
|
@@ -1546,19 +1583,19 @@ function assertSecureUrl(url, allowInsecure) {
|
|
|
1546
1583
|
var PLUGIN_PROTOCOL_VERSION = "plugin/v2";
|
|
1547
1584
|
var ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
1548
1585
|
var BINDING_RE = /^binding:[A-Za-z0-9_-]+$/;
|
|
1549
|
-
var authSchema =
|
|
1550
|
-
|
|
1551
|
-
|
|
1586
|
+
var authSchema = z9.discriminatedUnion("kind", [
|
|
1587
|
+
z9.object({ kind: z9.literal("platform-token") }),
|
|
1588
|
+
z9.object({ kind: z9.literal("bearer"), secretRef: z9.string().min(1) })
|
|
1552
1589
|
]);
|
|
1553
|
-
var manifestSchema =
|
|
1554
|
-
id:
|
|
1555
|
-
protocolVersion:
|
|
1590
|
+
var manifestSchema = z9.object({
|
|
1591
|
+
id: z9.string().regex(ID_RE, "id \u987B\u4E3A path-segment \u5B89\u5168\u5B57\u7B26([A-Za-z0-9._-],\u4E0D\u4EE5\u6807\u70B9\u5F00\u5934)"),
|
|
1592
|
+
protocolVersion: z9.string().refine((v) => v === PLUGIN_PROTOCOL_VERSION, {
|
|
1556
1593
|
error: `protocolVersion \u987B\u4E3A '${PLUGIN_PROTOCOL_VERSION}'`
|
|
1557
1594
|
}),
|
|
1558
|
-
endpoint:
|
|
1595
|
+
endpoint: z9.string().min(1),
|
|
1559
1596
|
auth: authSchema,
|
|
1560
|
-
healthPath:
|
|
1561
|
-
enabled:
|
|
1597
|
+
healthPath: z9.string().regex(/^\//, "healthPath \u987B\u4EE5 '/' \u5F00\u5934"),
|
|
1598
|
+
enabled: z9.boolean()
|
|
1562
1599
|
}).strict();
|
|
1563
1600
|
function parsePluginManifest(value, opts = {}) {
|
|
1564
1601
|
const parsed = manifestSchema.safeParse(value);
|
|
@@ -1580,169 +1617,798 @@ function parsePluginManifest(value, opts = {}) {
|
|
|
1580
1617
|
return manifest;
|
|
1581
1618
|
}
|
|
1582
1619
|
|
|
1583
|
-
// ../core/src/
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1620
|
+
// ../core/src/plugin/catalog.ts
|
|
1621
|
+
function canonicalCatalogJson(value) {
|
|
1622
|
+
const normalize = (input) => {
|
|
1623
|
+
if (Array.isArray(input)) return input.map(normalize);
|
|
1624
|
+
if (input === null || typeof input !== "object") return input;
|
|
1625
|
+
const source2 = input;
|
|
1626
|
+
const out = {};
|
|
1627
|
+
for (const key of Object.keys(source2).sort()) {
|
|
1628
|
+
if (source2[key] !== void 0) out[key] = normalize(source2[key]);
|
|
1629
|
+
}
|
|
1630
|
+
return out;
|
|
1631
|
+
};
|
|
1632
|
+
return JSON.stringify(normalize(value));
|
|
1587
1633
|
}
|
|
1588
|
-
function
|
|
1589
|
-
|
|
1634
|
+
async function catalogDigest(value) {
|
|
1635
|
+
const bytes2 = new TextEncoder().encode(canonicalCatalogJson(value));
|
|
1636
|
+
const hash = await crypto.subtle.digest("SHA-256", bytes2);
|
|
1637
|
+
return [...new Uint8Array(hash)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1590
1638
|
}
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1639
|
+
async function catalogSetDigest(catalog) {
|
|
1640
|
+
const pairs = Object.keys(catalog).sort().map((id) => ({ id, digest: catalog[id].digest }));
|
|
1641
|
+
return await catalogDigest(pairs);
|
|
1642
|
+
}
|
|
1643
|
+
function builtinManifestOf(id) {
|
|
1644
|
+
return {
|
|
1645
|
+
id,
|
|
1646
|
+
protocolVersion: "plugin/v2",
|
|
1647
|
+
endpoint: `binding:${id}`,
|
|
1648
|
+
auth: { kind: "platform-token" },
|
|
1649
|
+
healthPath: "/healthz",
|
|
1650
|
+
enabled: true
|
|
1651
|
+
};
|
|
1652
|
+
}
|
|
1653
|
+
function resolveBuiltinExport(catalog, id, nodeKind, what, exportId) {
|
|
1654
|
+
const entry = catalog[id];
|
|
1655
|
+
if (entry === void 0) {
|
|
1656
|
+
throw new TBError("invalid_argument", `\u672A\u77E5 ${what} provider:'${id}'`);
|
|
1657
|
+
}
|
|
1658
|
+
const chosen = resolvePluginExport(entry.describe, {
|
|
1659
|
+
nodeKind,
|
|
1660
|
+
pluginId: id,
|
|
1661
|
+
...exportId !== void 0 ? { exportId } : {}
|
|
1662
|
+
});
|
|
1663
|
+
return { manifest: builtinManifestOf(id), export: chosen, source: "builtin" };
|
|
1664
|
+
}
|
|
1665
|
+
async function resolveExternalExport(store, id, nodeKind, what, exportId) {
|
|
1666
|
+
const manifest = await store.get(KEY_PLUGIN + id);
|
|
1667
|
+
if (manifest === null) {
|
|
1668
|
+
throw new TBError("invalid_argument", `\u672A\u77E5 ${what} provider:'${id}'`);
|
|
1669
|
+
}
|
|
1670
|
+
if (manifest.enabled !== true) {
|
|
1671
|
+
throw new TBError("invalid_argument", `plugin '${id}' \u5DF2\u7981\u7528`);
|
|
1672
|
+
}
|
|
1673
|
+
const describe = manifest.describe ?? await store.get(KEY_PLUGIN_META + id);
|
|
1674
|
+
if (describe === null) {
|
|
1675
|
+
throw new TBError("invalid_argument", `plugin '${id}' \u7F3A\u5C11 ~describe \u7F13\u5B58,\u8BF7\u91CD\u65B0\u6CE8\u518C`);
|
|
1676
|
+
}
|
|
1677
|
+
const chosen = resolvePluginExport(describe, {
|
|
1678
|
+
nodeKind,
|
|
1679
|
+
pluginId: id,
|
|
1680
|
+
...exportId !== void 0 ? { exportId } : {}
|
|
1681
|
+
});
|
|
1682
|
+
return { manifest, export: chosen, source: "external" };
|
|
1683
|
+
}
|
|
1684
|
+
async function resolveIntegration(store, catalog, id, nodeKind, what, exportId) {
|
|
1685
|
+
const manifest = await store.get(KEY_PLUGIN + id);
|
|
1686
|
+
if (manifest !== null) {
|
|
1687
|
+
return await resolveExternalExport(store, id, nodeKind, what, exportId);
|
|
1688
|
+
}
|
|
1689
|
+
return resolveBuiltinExport(catalog, id, nodeKind, what, exportId);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// ../core/src/plugin/release.ts
|
|
1693
|
+
var pluginImageSchema = z10.string().max(512).regex(
|
|
1694
|
+
/^[a-z0-9]+(?:[.-][a-z0-9]+)*(?::[0-9]+)?\/(?:[a-z0-9]+(?:[._-][a-z0-9]+)*\/)*[a-z0-9]+(?:[._-][a-z0-9]+)*@sha256:[a-f0-9]{64}$/,
|
|
1695
|
+
"expected registry/repository@sha256:<digest>"
|
|
1596
1696
|
);
|
|
1597
|
-
var
|
|
1598
|
-
var
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
)
|
|
1603
|
-
endpoint: z9.string().min(1).describe("https base URL of the plugin service"),
|
|
1604
|
-
auth: pluginAuthSchema,
|
|
1605
|
-
healthPath: z9.string().min(1).describe('GET probe path, e.g. "/healthz"'),
|
|
1606
|
-
enabled: z9.boolean()
|
|
1697
|
+
var pluginVersionPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[\da-zA-Z-]*[a-zA-Z-][\da-zA-Z-]*)(?:\.(?:0|[1-9]\d*|[\da-zA-Z-]*[a-zA-Z-][\da-zA-Z-]*))*)?(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/;
|
|
1698
|
+
var fields = {
|
|
1699
|
+
schemaVersion: z10.literal("tb-plugin-release/v1"),
|
|
1700
|
+
id: z10.string().max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/),
|
|
1701
|
+
version: z10.string().max(128).regex(pluginVersionPattern),
|
|
1702
|
+
healthPath: z10.string().max(256).regex(/^\/[a-zA-Z0-9_./~-]*$/).default("/healthz")
|
|
1607
1703
|
};
|
|
1608
|
-
var
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
"list",
|
|
1619
|
-
{
|
|
1620
|
-
h: "list registered plugins (pluginToken never returned)",
|
|
1621
|
-
inputSchema: z9.strictObject({ opts: HTBP_LIST_OPTIONS_SCHEMA.optional() }),
|
|
1622
|
-
returns: "Page<PluginView> \u2014 manifest + the exports declared by its /~describe",
|
|
1623
|
-
scope: "admin"
|
|
1624
|
-
},
|
|
1625
|
-
({ opts }, { deps }) => deps.list(opts)
|
|
1626
|
-
).register(
|
|
1627
|
-
"get",
|
|
1628
|
-
{
|
|
1629
|
-
h: "fetch one plugin manifest by id",
|
|
1630
|
-
inputSchema: z9.strictObject({ id: pluginIdSchema }),
|
|
1631
|
-
returns: "PluginView \u2014 manifest + the exports declared by its /~describe",
|
|
1632
|
-
scope: "admin"
|
|
1633
|
-
},
|
|
1634
|
-
({ id }, { deps }) => deps.get(id)
|
|
1635
|
-
).register(
|
|
1636
|
-
"write",
|
|
1637
|
-
{
|
|
1638
|
-
h: "register a plugin: probes health and validates its /~describe exports before accepting; then mount an export via system/registry (config.provider = plugin id, config.export = export id)",
|
|
1639
|
-
inputSchema: pluginWriteSchema,
|
|
1640
|
-
returns: "PluginView + pluginToken shown once (platform-token only)",
|
|
1641
|
-
scope: "admin"
|
|
1642
|
-
},
|
|
1643
|
-
(input, { deps }) => deps.write(input)
|
|
1644
|
-
).register(
|
|
1645
|
-
"update",
|
|
1646
|
-
{
|
|
1647
|
-
h: "patch a registration; endpoint changes re-probe and re-validate the exports before applying",
|
|
1648
|
-
inputSchema: z9.strictObject({
|
|
1649
|
-
id: pluginIdSchema,
|
|
1650
|
-
patch: pluginPatchSchema
|
|
1651
|
-
}),
|
|
1652
|
-
returns: "PluginView \u2014 pluginToken shown once if auth switched to platform-token",
|
|
1653
|
-
scope: "admin"
|
|
1654
|
-
},
|
|
1655
|
-
({ id, patch }, { deps }) => deps.update(id, patch)
|
|
1656
|
-
).register(
|
|
1657
|
-
"delete",
|
|
1658
|
-
{
|
|
1659
|
-
h: "unregister a plugin and revoke its platform token; mounted nodes referencing it stop working",
|
|
1660
|
-
inputSchema: z9.strictObject({ id: pluginIdSchema }),
|
|
1661
|
-
returns: "void",
|
|
1662
|
-
scope: "admin"
|
|
1663
|
-
},
|
|
1664
|
-
async ({ id }, { deps }) => {
|
|
1665
|
-
await deps.remove(id);
|
|
1666
|
-
return VOID_ACK;
|
|
1704
|
+
var releaseSchema = z10.union([
|
|
1705
|
+
z10.strictObject({ ...fields, endpoint: z10.string().max(2048) }),
|
|
1706
|
+
z10.strictObject({ ...fields, image: pluginImageSchema })
|
|
1707
|
+
]);
|
|
1708
|
+
function httpsReleaseUrl(value) {
|
|
1709
|
+
try {
|
|
1710
|
+
const url = new URL2(value);
|
|
1711
|
+
if (value.startsWith("https://") && url.protocol === "https:" && !url.username && !url.password && !/[?#\\\s]/.test(value))
|
|
1712
|
+
return url.toString();
|
|
1713
|
+
} catch {
|
|
1667
1714
|
}
|
|
1668
|
-
)
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1715
|
+
throw new TBError("invalid_argument", "expected a credential-free HTTPS URL without query or fragment");
|
|
1716
|
+
}
|
|
1717
|
+
function parsePluginRelease(input) {
|
|
1718
|
+
const result = releaseSchema.safeParse(input);
|
|
1719
|
+
if (!result.success) throw new TBError("invalid_argument", "invalid tb-plugin-release/v1 manifest");
|
|
1720
|
+
if ("endpoint" in result.data) result.data.endpoint = httpsReleaseUrl(result.data.endpoint).replace(/\/+$/, "");
|
|
1721
|
+
return result.data;
|
|
1722
|
+
}
|
|
1723
|
+
async function releaseReceipt(source2, { release, resolvedSource }, approvedBy) {
|
|
1724
|
+
return {
|
|
1725
|
+
source: source2,
|
|
1726
|
+
resolvedSource,
|
|
1727
|
+
approvedBy,
|
|
1728
|
+
version: release.version,
|
|
1729
|
+
digest: "sha256:" + await sha256Hex(canonicalCatalogJson(release)),
|
|
1730
|
+
..."image" in release ? { image: release.image } : {}
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
// ../core/src/tree/registry.ts
|
|
1678
1735
|
function clampLimit2(limit) {
|
|
1679
1736
|
if (limit === void 0 || limit < 1) return LIST_LIMIT_DEFAULT;
|
|
1680
1737
|
return limit > LIST_LIMIT_MAX ? LIST_LIMIT_MAX : limit;
|
|
1681
1738
|
}
|
|
1682
|
-
function
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1739
|
+
function assertKindConfig(node) {
|
|
1740
|
+
if (node.config === void 0) return;
|
|
1741
|
+
if (node.config.kind !== node.kind) {
|
|
1742
|
+
throw new TBError(
|
|
1743
|
+
"invalid_argument",
|
|
1744
|
+
`kind='${node.kind}' \u4E0E config.kind='${node.config.kind}' \u4E0D\u4E00\u81F4`
|
|
1745
|
+
);
|
|
1686
1746
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1747
|
+
}
|
|
1748
|
+
function byPath(a, b) {
|
|
1749
|
+
return a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
|
1750
|
+
}
|
|
1751
|
+
var NodeRegistryStore = class {
|
|
1752
|
+
store;
|
|
1753
|
+
constructor(store) {
|
|
1754
|
+
this.store = store;
|
|
1691
1755
|
}
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
if (describe === null) {
|
|
1695
|
-
throw new TBError(
|
|
1696
|
-
"unavailable",
|
|
1697
|
-
`plugin '${record.id}' \u7F3A\u5C11 ~describe \u7F13\u5B58,\u8BF7\u91CD\u65B0\u6CE8\u518C`,
|
|
1698
|
-
{ retryable: false }
|
|
1699
|
-
);
|
|
1700
|
-
}
|
|
1701
|
-
return { ...projectManifest(record), exports: describe.exports };
|
|
1756
|
+
keyOf(path) {
|
|
1757
|
+
return KEY_NODE + path;
|
|
1702
1758
|
}
|
|
1703
|
-
async
|
|
1704
|
-
|
|
1705
|
-
try {
|
|
1706
|
-
await secrets.delete(pluginTokenSecretName(record.id));
|
|
1707
|
-
} catch {
|
|
1708
|
-
}
|
|
1759
|
+
async read(path) {
|
|
1760
|
+
return await this.store.get(this.keyOf(path));
|
|
1709
1761
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
const record = {
|
|
1714
|
-
healthy: result.healthy,
|
|
1715
|
-
checkedAt: now(),
|
|
1716
|
-
consecutiveFailures: result.healthy ? 0 : (prev?.consecutiveFailures ?? 0) + 1
|
|
1717
|
-
};
|
|
1718
|
-
await store.put(KEY_PLUGIN_HEALTH + manifest.id, record);
|
|
1719
|
-
return record;
|
|
1762
|
+
/** 翻页取尽 node:* 全量。 */
|
|
1763
|
+
async scanAll() {
|
|
1764
|
+
return this.scanPrefix(KEY_NODE);
|
|
1720
1765
|
}
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1766
|
+
/**
|
|
1767
|
+
* 翻页扫描给定 KV 键前缀下的所有 TreeNode。
|
|
1768
|
+
*
|
|
1769
|
+
* 只扫子树(前缀限定),不再对全树做内存过滤——避免 children/hasChildren/subtree 的
|
|
1770
|
+
* O(N²)(每层各扫全树)。`opts.limit` 传给底层 `store.list` 以小步取(hasChildren 短路用)。
|
|
1771
|
+
*
|
|
1772
|
+
* **Workers 查询预算约束**:D1StateStore.list 是单条 SQL 直接带值返回(ADR-001 迁 D1 后
|
|
1773
|
+
* 不再逐键 get),每页只花一次 D1 查询;但 Workers 单请求仍有查询/子请求预算,深翻页的
|
|
1774
|
+
* 页数应远小于预算——当前树规模小(节点数十级)可接受。
|
|
1775
|
+
*/
|
|
1776
|
+
async scanPrefix(keyPrefix, opts) {
|
|
1777
|
+
const out = [];
|
|
1778
|
+
let cursor2;
|
|
1779
|
+
do {
|
|
1780
|
+
const limit = opts?.maxNodes === void 0 ? opts?.limit ?? LIST_LIMIT_MAX : Math.min(
|
|
1781
|
+
opts.limit ?? LIST_LIMIT_MAX,
|
|
1782
|
+
opts.maxNodes - out.length + (opts.truncate === true ? 0 : 1)
|
|
1731
1783
|
);
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1784
|
+
if (limit < 1) return out;
|
|
1785
|
+
const page = await this.store.list(keyPrefix, {
|
|
1786
|
+
limit,
|
|
1787
|
+
...cursor2 !== void 0 ? { cursor: cursor2 } : {}
|
|
1788
|
+
});
|
|
1789
|
+
for (const { value } of page.items) out.push(value);
|
|
1790
|
+
if (opts?.truncate === true && out.length >= (opts.maxNodes ?? Number.POSITIVE_INFINITY)) {
|
|
1791
|
+
return out;
|
|
1792
|
+
}
|
|
1793
|
+
if (opts?.maxNodes !== void 0 && out.length > opts.maxNodes) {
|
|
1794
|
+
throw new TBError(
|
|
1795
|
+
"rate_limited",
|
|
1796
|
+
`registry scan \u6700\u591A\u8BFB\u53D6 ${opts.maxNodes} \u4E2A\u8282\u70B9`
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
cursor2 = page.cursor;
|
|
1800
|
+
} while (cursor2);
|
|
1801
|
+
return out;
|
|
1802
|
+
}
|
|
1803
|
+
/** KV 前缀:某路径的子树(含中间 directory)= `node:<path>/`;根('')= `node:`。 */
|
|
1804
|
+
subtreePrefix(norm) {
|
|
1805
|
+
return norm === "" ? KEY_NODE : `${KEY_NODE}${norm}/`;
|
|
1806
|
+
}
|
|
1807
|
+
async hasChildren(path) {
|
|
1808
|
+
const norm = normalizePath(path);
|
|
1809
|
+
const page = await this.store.list(this.subtreePrefix(norm), { limit: 1 });
|
|
1810
|
+
return page.items.length > 0;
|
|
1811
|
+
}
|
|
1812
|
+
/** 取单个;不存在 → not_found。路径大小写不敏感(规范化为小写后查)。 */
|
|
1813
|
+
async get(path) {
|
|
1814
|
+
const norm = canonicalizePath(path);
|
|
1815
|
+
const node = await this.read(norm);
|
|
1816
|
+
if (!node) throw new TBError("not_found", `\u8282\u70B9\u4E0D\u5B58\u5728:'${norm}'`);
|
|
1817
|
+
return node;
|
|
1818
|
+
}
|
|
1819
|
+
/** 批量取节点;路径先规范化(小写)去重,不存在的节点不进入返回 Map。 */
|
|
1820
|
+
async getMany(paths) {
|
|
1821
|
+
const canonical = [...new Set(paths.map((path) => canonicalizePath(path)))];
|
|
1822
|
+
const values = await this.store.getMany(canonical.map((path) => this.keyOf(path)));
|
|
1823
|
+
const out = /* @__PURE__ */ new Map();
|
|
1824
|
+
for (const path of canonical) {
|
|
1825
|
+
const value = values.get(this.keyOf(path));
|
|
1826
|
+
if (value !== void 0) out.set(path, value);
|
|
1827
|
+
}
|
|
1828
|
+
return out;
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* 枚举 `prefix` 之下(含 prefix 自身,按段前缀匹配)的节点,分页。
|
|
1832
|
+
* 无 prefix = 全树。cursor 为上一页末节点的 path。
|
|
1833
|
+
*/
|
|
1834
|
+
async list(prefix, opts) {
|
|
1835
|
+
const normPrefix = prefix === void 0 ? "" : canonicalizePath(prefix);
|
|
1836
|
+
const limit = clampLimit2(opts?.limit);
|
|
1837
|
+
const all = (await this.scanAll()).filter((n) => isPrefixOf(normPrefix, n.path)).sort(byPath);
|
|
1838
|
+
const cursor2 = opts?.cursor;
|
|
1839
|
+
const start = cursor2 ? all.findIndex((n) => n.path === cursor2) + 1 : 0;
|
|
1840
|
+
const items = all.slice(start, start + limit);
|
|
1841
|
+
const hasMore = start + limit < all.length;
|
|
1842
|
+
return {
|
|
1843
|
+
items,
|
|
1844
|
+
cursor: hasMore ? items[items.length - 1]?.path : void 0
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
/** 直接子节点(段深恰好 +1);~help 列子节点用。只扫子树前缀,不扫全树。 */
|
|
1848
|
+
async children(path) {
|
|
1849
|
+
const norm = canonicalizePath(path);
|
|
1850
|
+
const depth = segments(norm).length;
|
|
1851
|
+
const sub = await this.scanPrefix(this.subtreePrefix(norm));
|
|
1852
|
+
return sub.filter((n) => segments(n.path).length === depth + 1).sort(byPath);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* 一次性取整棵子树的节点数组(含 `path` 自身 + 全部后代),按 path 排序。
|
|
1856
|
+
* 供 `~tree` 建树一次读入内存(而非每层递归各扫一遍)。根('')= 全树。
|
|
1857
|
+
* 不存在的根返回空数组(调用方自行判 not_found)。
|
|
1858
|
+
*/
|
|
1859
|
+
async subtree(path, opts) {
|
|
1860
|
+
const norm = canonicalizePath(path);
|
|
1861
|
+
if (opts?.maxNodes !== void 0 && (!Number.isInteger(opts.maxNodes) || opts.maxNodes < 1)) {
|
|
1862
|
+
throw new TBError("invalid_argument", "maxNodes \u5FC5\u987B\u662F\u6B63\u6574\u6570");
|
|
1863
|
+
}
|
|
1864
|
+
const descendants = await this.scanPrefix(this.subtreePrefix(norm), opts);
|
|
1865
|
+
if (norm === "") return descendants.sort(byPath);
|
|
1866
|
+
const self = await this.read(norm);
|
|
1867
|
+
const all = self ? [self, ...descendants] : descendants;
|
|
1868
|
+
if (opts?.maxNodes !== void 0 && all.length > opts.maxNodes) {
|
|
1869
|
+
throw new TBError(
|
|
1870
|
+
"rate_limited",
|
|
1871
|
+
`registry scan \u6700\u591A\u8BFB\u53D6 ${opts.maxNodes} \u4E2A\u8282\u70B9`
|
|
1872
|
+
);
|
|
1873
|
+
}
|
|
1874
|
+
return all.sort(byPath);
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* 取按 key 确定排序的有界根快照,并显式报告是否截断。派生索引用 truncated
|
|
1878
|
+
* 选择保留 last-known-good,不把 canonical registry 的规模限制反向施加到主数据面。
|
|
1879
|
+
*/
|
|
1880
|
+
async rootSnapshot(maxNodes) {
|
|
1881
|
+
if (!Number.isInteger(maxNodes) || maxNodes < 1) {
|
|
1882
|
+
throw new TBError("invalid_argument", "maxNodes \u5FC5\u987B\u662F\u6B63\u6574\u6570");
|
|
1883
|
+
}
|
|
1884
|
+
const items = await this.scanPrefix(KEY_NODE, { maxNodes: maxNodes + 1, truncate: true });
|
|
1885
|
+
return {
|
|
1886
|
+
items: items.slice(0, maxNodes).sort(byPath),
|
|
1887
|
+
truncated: items.length > maxNodes
|
|
1888
|
+
};
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* 幂等 upsert:
|
|
1892
|
+
* - 校验路径(空/空段/保留段)与 kind↔config 一致性;
|
|
1893
|
+
* - 自动物化 parentPaths 中缺失的中间 directory(registeredBy=system:auto,description='');
|
|
1894
|
+
* 已存在的祖先(无论显式或自动)一律不动;
|
|
1895
|
+
* - createdAt 保留原值(存在时)否则取 now;updatedAt 始终刷新为 now;
|
|
1896
|
+
* - registeredBy 由调用方注入(device 节点由 Gateway 代写)。
|
|
1897
|
+
*
|
|
1898
|
+
* conflict(覆盖他人节点)判定在网关注册路径层,不在此——本层是幂等 upsert。
|
|
1899
|
+
*/
|
|
1900
|
+
async write(node, registeredBy, now, opts = {}) {
|
|
1901
|
+
const invalid2 = validatePath(node.path);
|
|
1902
|
+
if (invalid2) throw invalid2;
|
|
1903
|
+
const path = canonicalizePath(node.path);
|
|
1904
|
+
assertKindConfig(node);
|
|
1905
|
+
for (const parent of parentPaths(path)) {
|
|
1906
|
+
if (!await this.read(parent)) {
|
|
1907
|
+
const dir = {
|
|
1908
|
+
path: parent,
|
|
1909
|
+
kind: "directory",
|
|
1910
|
+
description: "",
|
|
1911
|
+
registeredBy: SYSTEM_AUTO,
|
|
1912
|
+
createdAt: now,
|
|
1913
|
+
updatedAt: now
|
|
1914
|
+
};
|
|
1915
|
+
if (this.store.putIfAbsent) await this.store.putIfAbsent(this.keyOf(parent), dir);
|
|
1916
|
+
else await this.store.put(this.keyOf(parent), dir);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
const existing = await this.read(path);
|
|
1920
|
+
const full = {
|
|
1921
|
+
path,
|
|
1922
|
+
kind: node.kind,
|
|
1923
|
+
description: node.description,
|
|
1924
|
+
...node.config !== void 0 ? { config: node.config } : {},
|
|
1925
|
+
...node.virtualize !== void 0 ? { virtualize: node.virtualize } : {},
|
|
1926
|
+
...opts.deviceId !== void 0 ? { deviceId: opts.deviceId } : {},
|
|
1927
|
+
...opts.deviceEnvironment !== void 0 ? { deviceEnvironment: opts.deviceEnvironment } : {},
|
|
1928
|
+
...opts.deviceReportedAt !== void 0 ? { deviceReportedAt: opts.deviceReportedAt } : {},
|
|
1929
|
+
...opts.online !== void 0 ? { online: opts.online } : {},
|
|
1930
|
+
...opts.lastSeenAt !== void 0 ? { lastSeenAt: opts.lastSeenAt } : {},
|
|
1931
|
+
registeredBy,
|
|
1932
|
+
createdAt: existing?.createdAt ?? now,
|
|
1933
|
+
updatedAt: now
|
|
1934
|
+
};
|
|
1935
|
+
await this.store.put(this.keyOf(path), full);
|
|
1936
|
+
return full;
|
|
1937
|
+
}
|
|
1938
|
+
async editExisting(path, edit) {
|
|
1939
|
+
const key = this.keyOf(path);
|
|
1940
|
+
if (this.store.updateNode) return this.store.updateNode(key, edit);
|
|
1941
|
+
const node = await this.read(path);
|
|
1942
|
+
if (!node) return null;
|
|
1943
|
+
const next = edit(node);
|
|
1944
|
+
await this.store.put(key, next);
|
|
1945
|
+
return next;
|
|
1946
|
+
}
|
|
1947
|
+
/** Apply partial configuration edits to the same row that carries device presence. */
|
|
1948
|
+
async update(path, patch, now) {
|
|
1949
|
+
const norm = canonicalizePath(path);
|
|
1950
|
+
if (patch.path !== void 0 && canonicalizePath(patch.path) !== norm) {
|
|
1951
|
+
throw new TBError("invalid_argument", "path \u4E0D\u53EF\u901A\u8FC7 Update \u53D8\u66F4");
|
|
1952
|
+
}
|
|
1953
|
+
const updated = await this.editExisting(norm, (current) => {
|
|
1954
|
+
const next = {
|
|
1955
|
+
...current,
|
|
1956
|
+
...patch.kind !== void 0 ? { kind: patch.kind } : {},
|
|
1957
|
+
...patch.description !== void 0 ? { description: patch.description } : {},
|
|
1958
|
+
...patch.config !== void 0 ? { config: patch.config } : {},
|
|
1959
|
+
...patch.virtualize !== void 0 ? { virtualize: patch.virtualize } : {},
|
|
1960
|
+
updatedAt: now
|
|
1961
|
+
};
|
|
1962
|
+
assertKindConfig(next);
|
|
1963
|
+
return next;
|
|
1964
|
+
});
|
|
1965
|
+
if (!updated) throw new TBError("not_found", `\u8282\u70B9\u4E0D\u5B58\u5728:'${norm}'`);
|
|
1966
|
+
return updated;
|
|
1967
|
+
}
|
|
1968
|
+
async setOnline(path, online, now) {
|
|
1969
|
+
const norm = canonicalizePath(path);
|
|
1970
|
+
const updated = await this.editExisting(norm, (current) => ({
|
|
1971
|
+
...current,
|
|
1972
|
+
online,
|
|
1973
|
+
updatedAt: now,
|
|
1974
|
+
...online ? { lastSeenAt: now } : {}
|
|
1975
|
+
}));
|
|
1976
|
+
if (!updated) throw new TBError("not_found", `\u8282\u70B9\u4E0D\u5B58\u5728:'${norm}'`);
|
|
1977
|
+
return updated;
|
|
1978
|
+
}
|
|
1979
|
+
async touchSeen(path, now) {
|
|
1980
|
+
await this.editExisting(canonicalizePath(path), (current) => ({
|
|
1981
|
+
...current,
|
|
1982
|
+
lastSeenAt: current.lastSeenAt && current.lastSeenAt > now ? current.lastSeenAt : now
|
|
1983
|
+
}));
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* 卸载;不存在 → not_found。删除后自底向上级联回收:
|
|
1987
|
+
* 仅回收 registeredBy=system:auto 且再无子节点的 directory,遇显式节点/仍有子节点即停。
|
|
1988
|
+
*
|
|
1989
|
+
* 实现决策(待回写 docs):被删节点若仍有后代 → conflict
|
|
1990
|
+
* (不允许删除非空子树;显式 directory 同理)。
|
|
1991
|
+
*/
|
|
1992
|
+
async delete(path) {
|
|
1993
|
+
const norm = canonicalizePath(path);
|
|
1994
|
+
const existing = await this.read(norm);
|
|
1995
|
+
if (!existing) throw new TBError("not_found", `\u8282\u70B9\u4E0D\u5B58\u5728:'${norm}'`);
|
|
1996
|
+
if (await this.hasChildren(norm)) {
|
|
1997
|
+
throw new TBError("conflict", `\u8282\u70B9 '${norm}' \u4ECD\u6709\u5B50\u8282\u70B9,\u4E0D\u5141\u8BB8\u5220\u9664\u975E\u7A7A\u5B50\u6811`);
|
|
1998
|
+
}
|
|
1999
|
+
await this.store.delete(this.keyOf(norm));
|
|
2000
|
+
for (const parent of [...parentPaths(norm)].reverse()) {
|
|
2001
|
+
const p = await this.read(parent);
|
|
2002
|
+
if (!p || p.registeredBy !== SYSTEM_AUTO || p.kind !== "directory") break;
|
|
2003
|
+
if (await this.hasChildren(parent)) break;
|
|
2004
|
+
await this.store.delete(this.keyOf(parent));
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
/**
|
|
2008
|
+
* 设备回收专用:删除一个已知子树(含根与全部后代),再按普通 delete 规则回收自动目录。
|
|
2009
|
+
* 普通管理面仍使用 delete(),不允许误删非空子树。
|
|
2010
|
+
*/
|
|
2011
|
+
async deleteSubtree(path) {
|
|
2012
|
+
const norm = canonicalizePath(path);
|
|
2013
|
+
const existing = await this.read(norm);
|
|
2014
|
+
if (!existing) throw new TBError("not_found", `\u8282\u70B9\u4E0D\u5B58\u5728:'${norm}'`);
|
|
2015
|
+
const descendants = await this.scanPrefix(this.subtreePrefix(norm));
|
|
2016
|
+
descendants.sort((a, b) => segments(b.path).length - segments(a.path).length || byPath(b, a));
|
|
2017
|
+
for (const n of descendants) await this.store.delete(this.keyOf(n.path));
|
|
2018
|
+
await this.store.delete(this.keyOf(norm));
|
|
2019
|
+
for (const parent of [...parentPaths(norm)].reverse()) {
|
|
2020
|
+
const p = await this.read(parent);
|
|
2021
|
+
if (!p || p.registeredBy !== SYSTEM_AUTO || p.kind !== "directory") break;
|
|
2022
|
+
if (await this.hasChildren(parent)) break;
|
|
2023
|
+
await this.store.delete(this.keyOf(parent));
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* 最长前缀匹配:返回命中节点与剩余段('/' 连接)。
|
|
2028
|
+
* 完全匹配 → rest=''。无任何匹配 → not_found。
|
|
2029
|
+
*/
|
|
2030
|
+
async resolve(path) {
|
|
2031
|
+
const norm = canonicalizePath(path);
|
|
2032
|
+
const candidates = [norm, ...parentPaths(norm).reverse()];
|
|
2033
|
+
for (const cand of candidates) {
|
|
2034
|
+
const node = await this.read(cand);
|
|
2035
|
+
if (node) {
|
|
2036
|
+
const rest = segments(norm).slice(segments(cand).length).join("/");
|
|
2037
|
+
return { node, rest };
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
throw new TBError("not_found", `\u65E0\u5339\u914D\u8282\u70B9:'${norm}'`);
|
|
2041
|
+
}
|
|
2042
|
+
};
|
|
2043
|
+
|
|
2044
|
+
// ../core/src/builtin/pluginDistribution.ts
|
|
2045
|
+
var source = z11.string().min(1).max(2048);
|
|
2046
|
+
var installInput = z11.strictObject({
|
|
2047
|
+
source,
|
|
2048
|
+
secretRef: z11.string().min(1).max(128).regex(/^[^:\s]+$/),
|
|
2049
|
+
origin: z11.string().max(2048).optional()
|
|
2050
|
+
});
|
|
2051
|
+
var previewInput = z11.strictObject({ id: z11.string().min(1), source: source.optional() });
|
|
2052
|
+
var upgradeInput = previewInput.extend({ candidateDigest: z11.string().regex(/^sha256:[0-9a-f]{64}$/).optional() });
|
|
2053
|
+
function approvedOrigin(url) {
|
|
2054
|
+
return new URL2(httpsReleaseUrl(url)).origin;
|
|
2055
|
+
}
|
|
2056
|
+
function manifestOf(record) {
|
|
2057
|
+
const { id, protocolVersion, enabled, endpoint, healthPath, auth } = record;
|
|
2058
|
+
return { id, protocolVersion, enabled, endpoint, healthPath, auth };
|
|
2059
|
+
}
|
|
2060
|
+
function createDistribution(deps) {
|
|
2061
|
+
async function load(source2) {
|
|
2062
|
+
if (!deps.resolveRelease || !deps.store.compareAndSwap)
|
|
2063
|
+
throw new TBError("unavailable", "this host does not support plugin distribution");
|
|
2064
|
+
return deps.resolveRelease(source2);
|
|
2065
|
+
}
|
|
2066
|
+
async function resolveCandidate(receipt, release, origin) {
|
|
2067
|
+
let endpoint;
|
|
2068
|
+
if ("image" in release) {
|
|
2069
|
+
if (!deps.prepareImage) throw new TBError("unavailable", "an administrator must configure the isolated plugin runner");
|
|
2070
|
+
endpoint = httpsReleaseUrl(await deps.prepareImage(release.id, release.image)).replace(/\/+$/, "");
|
|
2071
|
+
} else {
|
|
2072
|
+
endpoint = release.endpoint;
|
|
2073
|
+
const trusted = origin ?? (receipt.resolvedSource.startsWith("https://") ? receipt.resolvedSource : void 0);
|
|
2074
|
+
if (!trusted || approvedOrigin(trusted) !== approvedOrigin(endpoint))
|
|
2075
|
+
throw new TBError("invalid_argument", "hosted endpoint must match the approved HTTPS origin");
|
|
2076
|
+
}
|
|
2077
|
+
return { ...receipt, endpoint, healthPath: release.healthPath };
|
|
2078
|
+
}
|
|
2079
|
+
async function inspect(manifest, distribution) {
|
|
2080
|
+
if (!distribution.active.image && approvedOrigin(distribution.active.endpoint) !== distribution.origin)
|
|
2081
|
+
throw new TBError("conflict", "candidate endpoint does not match the installation origin");
|
|
2082
|
+
const candidate = { ...manifest, distribution, endpoint: distribution.active.endpoint, healthPath: distribution.active.healthPath };
|
|
2083
|
+
const probed = await deps.probe(candidate);
|
|
2084
|
+
if (!probed.healthy) throw new TBError("unavailable", "candidate plugin failed its health check", { retryable: true });
|
|
2085
|
+
const { describe: raw } = await deps.fetchContract(candidate);
|
|
2086
|
+
const describe = validatePluginContract({ manifest: candidate, describe: raw });
|
|
2087
|
+
return { ...candidate, describe };
|
|
2088
|
+
}
|
|
2089
|
+
async function verifyAuth(candidate) {
|
|
2090
|
+
if (!deps.verifyReleaseAuth) throw new TBError("unavailable", "plugin bearer verifier unavailable");
|
|
2091
|
+
await deps.verifyReleaseAuth(candidate);
|
|
2092
|
+
}
|
|
2093
|
+
async function activate(candidate, prior) {
|
|
2094
|
+
await verifyAuth(candidate);
|
|
2095
|
+
const revision2 = prior ? prior.revision + 1 : Number.parseInt(crypto.randomUUID().replace(/-/g, "").slice(0, 12), 16);
|
|
2096
|
+
const record = { ...candidate, revision: revision2 };
|
|
2097
|
+
if (!await deps.store.compareAndSwap?.(KEY_PLUGIN + candidate.id, prior?.revision ?? null, record))
|
|
2098
|
+
throw new TBError("conflict", "plugin registration changed; reload before retrying");
|
|
2099
|
+
return { ...manifestOf(candidate), distribution: candidate.distribution, exports: candidate.describe.exports };
|
|
2100
|
+
}
|
|
2101
|
+
async function managed(id, scopes) {
|
|
2102
|
+
const record = await deps.store.get(KEY_PLUGIN + id);
|
|
2103
|
+
if (!record) throw new TBError("not_found", "plugin not installed");
|
|
2104
|
+
if (!record.distribution) throw new TBError("conflict", "plugin was registered manually; use plugin update");
|
|
2105
|
+
if (record.auth.kind !== "bearer") throw new TBError("conflict", "missing installation bearer reference");
|
|
2106
|
+
assertSecretRefUse(scopes, { authRef: record.auth.secretRef });
|
|
2107
|
+
return record;
|
|
2108
|
+
}
|
|
2109
|
+
async function prepareUpgrade(record, input, actor) {
|
|
2110
|
+
const { active } = record.distribution;
|
|
2111
|
+
const source2 = input.source ?? active.source;
|
|
2112
|
+
const resolved = await load(source2);
|
|
2113
|
+
const { release } = resolved;
|
|
2114
|
+
if (release.id !== input.id || "image" in release !== (active.image !== void 0))
|
|
2115
|
+
throw new TBError("invalid_argument", "plugin identity or hosting mode changed");
|
|
2116
|
+
const receipt = await releaseReceipt(source2, resolved, actor);
|
|
2117
|
+
for (const known of [active, record.distribution.previous, record.distribution.rolledBackFrom]) {
|
|
2118
|
+
if (known?.version === receipt.version && known.digest !== receipt.digest)
|
|
2119
|
+
throw new TBError("conflict", "a known version cannot be replaced with a different manifest");
|
|
2120
|
+
}
|
|
2121
|
+
const next = await resolveCandidate(receipt, release, record.distribution.origin);
|
|
2122
|
+
if (active.digest === next.digest && active.endpoint !== next.endpoint)
|
|
2123
|
+
throw new TBError("conflict", "an existing release cannot change endpoints");
|
|
2124
|
+
if (active.digest !== next.digest && active.endpoint === next.endpoint)
|
|
2125
|
+
throw new TBError("conflict", "a new release needs its own endpoint so rollback remains possible");
|
|
2126
|
+
const distribution = active.digest === next.digest ? { ...record.distribution, active: next } : { origin: record.distribution.origin, active: next, previous: active };
|
|
2127
|
+
return inspect(manifestOf(record), distribution);
|
|
2128
|
+
}
|
|
2129
|
+
async function confirmationDigest(record, candidate) {
|
|
2130
|
+
const { digest, resolvedSource } = candidate.distribution.active;
|
|
2131
|
+
return "sha256:" + await catalogDigest({
|
|
2132
|
+
id: record.id,
|
|
2133
|
+
revision: record.revision,
|
|
2134
|
+
resolvedSource,
|
|
2135
|
+
digest,
|
|
2136
|
+
endpoint: candidate.endpoint,
|
|
2137
|
+
describe: candidate.describe
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
return {
|
|
2141
|
+
async install(input, actor) {
|
|
2142
|
+
const resolved = await load(input.source);
|
|
2143
|
+
const { release } = resolved;
|
|
2144
|
+
if (await deps.store.get(KEY_PLUGIN + release.id)) throw new TBError("conflict", "plugin is already registered");
|
|
2145
|
+
if (!await deps.secrets.resolve(input.secretRef)) throw new TBError("invalid_argument", "plugin bearer secret is unavailable");
|
|
2146
|
+
const receipt = await releaseReceipt(input.source, resolved, actor);
|
|
2147
|
+
const active = await resolveCandidate(receipt, release, input.origin);
|
|
2148
|
+
return activate(await inspect({
|
|
2149
|
+
id: release.id,
|
|
2150
|
+
protocolVersion: "plugin/v2",
|
|
2151
|
+
enabled: true,
|
|
2152
|
+
auth: { kind: "bearer", secretRef: input.secretRef },
|
|
2153
|
+
endpoint: active.endpoint,
|
|
2154
|
+
healthPath: active.healthPath
|
|
2155
|
+
}, { active, ...!active.image ? { origin: approvedOrigin(active.endpoint) } : {} }));
|
|
2156
|
+
},
|
|
2157
|
+
async preview(input, scopes, actor) {
|
|
2158
|
+
const record = await managed(input.id, scopes);
|
|
2159
|
+
const candidate = await prepareUpgrade(record, input, actor);
|
|
2160
|
+
await verifyAuth(candidate);
|
|
2161
|
+
const before = new Map(record.describe.exports.map((e) => [e.id, e]));
|
|
2162
|
+
const after = new Map(candidate.describe.exports.map((e) => [e.id, e]));
|
|
2163
|
+
const addedExports = [...after.keys()].filter((id) => !before.has(id)).sort();
|
|
2164
|
+
const removedExports = [...before.keys()].filter((id) => !after.has(id)).sort();
|
|
2165
|
+
const changedExports = [...after.keys()].filter(
|
|
2166
|
+
(id) => before.has(id) && canonicalCatalogJson(before.get(id)) !== canonicalCatalogJson(after.get(id))
|
|
2167
|
+
).sort();
|
|
2168
|
+
const affectedMounts = [];
|
|
2169
|
+
const incompatibleMounts = [];
|
|
2170
|
+
const kinds = Object.values(NODE_KIND_BY_PROFILE2);
|
|
2171
|
+
for (const node of await new NodeRegistryStore(deps.store).subtree("")) {
|
|
2172
|
+
const cfg = node.config;
|
|
2173
|
+
if (!cfg || !("provider" in cfg) || cfg.provider !== record.id || cfg.kind !== node.kind) continue;
|
|
2174
|
+
const nodeKind = kinds.find((kind) => kind === cfg.kind);
|
|
2175
|
+
if (!nodeKind || !checkScopes(scopes, node.path, "read")) continue;
|
|
2176
|
+
if (nodeKind === "context" && ["storage", "s3", "device-fs"].includes(cfg.provider)) continue;
|
|
2177
|
+
const pc = "providerConfig" in cfg ? cfg.providerConfig : void 0;
|
|
2178
|
+
if (typeof pc?.deviceId === "string" && typeof pc.mountPath === "string") continue;
|
|
2179
|
+
affectedMounts.push(node.path);
|
|
2180
|
+
try {
|
|
2181
|
+
resolvePluginExport(candidate.describe, {
|
|
2182
|
+
pluginId: record.id,
|
|
2183
|
+
nodeKind,
|
|
2184
|
+
exportId: "export" in cfg ? cfg.export : void 0
|
|
2185
|
+
});
|
|
2186
|
+
} catch (err) {
|
|
2187
|
+
if (!isTBError(err) || err.code !== "invalid_argument") throw err;
|
|
2188
|
+
incompatibleMounts.push(node.path);
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
return {
|
|
2192
|
+
id: record.id,
|
|
2193
|
+
currentVersion: record.distribution.active.version,
|
|
2194
|
+
candidateVersion: candidate.distribution.active.version,
|
|
2195
|
+
candidateDigest: await confirmationDigest(record, candidate),
|
|
2196
|
+
addedExports,
|
|
2197
|
+
removedExports,
|
|
2198
|
+
changedExports,
|
|
2199
|
+
affectedMounts,
|
|
2200
|
+
incompatibleMounts,
|
|
2201
|
+
requiresRunner: candidate.distribution.active.image !== void 0
|
|
2202
|
+
};
|
|
2203
|
+
},
|
|
2204
|
+
async upgrade(input, scopes, actor) {
|
|
2205
|
+
const record = await managed(input.id, scopes);
|
|
2206
|
+
const candidate = await prepareUpgrade(record, input, actor);
|
|
2207
|
+
if (input.candidateDigest && input.candidateDigest !== await confirmationDigest(record, candidate))
|
|
2208
|
+
throw new TBError("conflict", "candidate or active registration changed; preview again");
|
|
2209
|
+
return activate(candidate, record);
|
|
2210
|
+
},
|
|
2211
|
+
async rollback(id, scopes, digest) {
|
|
2212
|
+
const record = await managed(id, scopes);
|
|
2213
|
+
const { active, previous } = record.distribution;
|
|
2214
|
+
if (digest === active.digest || !digest && !previous && record.distribution.rolledBackFrom)
|
|
2215
|
+
return { ...manifestOf(record), distribution: record.distribution, exports: record.describe.exports };
|
|
2216
|
+
if (!previous || digest && digest !== previous.digest)
|
|
2217
|
+
throw new TBError("conflict", "requested rollback target is unavailable");
|
|
2218
|
+
if (previous.image) {
|
|
2219
|
+
if (!deps.prepareImage) throw new TBError("unavailable", "isolated plugin runner unavailable");
|
|
2220
|
+
const endpoint = httpsReleaseUrl(await deps.prepareImage(id, previous.image)).replace(/\/+$/, "");
|
|
2221
|
+
if (endpoint !== previous.endpoint) throw new TBError("conflict", "previous runner endpoint changed");
|
|
2222
|
+
}
|
|
2223
|
+
return activate(await inspect(manifestOf(record), { origin: record.distribution.origin, active: previous, rolledBackFrom: active }), record);
|
|
2224
|
+
}
|
|
2225
|
+
};
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
// ../core/src/builtin/plugin.ts
|
|
2229
|
+
var DESCRIPTION2 = "Plugin registry: register / probe external tool & context providers, then mount them via system/registry (admin only)";
|
|
2230
|
+
function pluginTokenSecretName(id) {
|
|
2231
|
+
return `plugin-token:${id}`;
|
|
2232
|
+
}
|
|
2233
|
+
var pluginAuthSchema = z12.discriminatedUnion("kind", [
|
|
2234
|
+
z12.strictObject({ kind: z12.literal("platform-token") }),
|
|
2235
|
+
z12.strictObject({ kind: z12.literal("bearer"), secretRef: z12.string().min(1) })
|
|
2236
|
+
]).describe(
|
|
2237
|
+
'{ kind: "platform-token" } \u2014 gateway mints the token (shown once in the response); or { kind: "bearer", secretRef }'
|
|
2238
|
+
);
|
|
2239
|
+
var pluginIdSchema = z12.string().min(1).describe("plugin id");
|
|
2240
|
+
var manifestFields = {
|
|
2241
|
+
id: z12.string().min(1).describe("unique plugin id"),
|
|
2242
|
+
protocolVersion: z12.literal("plugin/v2").describe(
|
|
2243
|
+
"transport protocol version; what the plugin provides is declared by its /~describe exports"
|
|
2244
|
+
),
|
|
2245
|
+
endpoint: z12.string().min(1).describe("https base URL of the plugin service"),
|
|
2246
|
+
auth: pluginAuthSchema,
|
|
2247
|
+
healthPath: z12.string().min(1).describe('GET probe path, e.g. "/healthz"'),
|
|
2248
|
+
enabled: z12.boolean()
|
|
2249
|
+
};
|
|
2250
|
+
var pluginWriteSchema = z12.strictObject(manifestFields);
|
|
2251
|
+
var pluginPatchSchema = z12.strictObject({
|
|
2252
|
+
id: manifestFields.id.optional(),
|
|
2253
|
+
protocolVersion: manifestFields.protocolVersion.optional(),
|
|
2254
|
+
endpoint: manifestFields.endpoint.optional(),
|
|
2255
|
+
auth: manifestFields.auth.optional(),
|
|
2256
|
+
healthPath: manifestFields.healthPath.optional(),
|
|
2257
|
+
enabled: manifestFields.enabled.optional()
|
|
2258
|
+
}).describe("fields to change; same shape as write, all optional");
|
|
2259
|
+
var COMMANDS2 = new BuiltinCommandRegistry("plugin", DESCRIPTION2).register("install", {
|
|
2260
|
+
h: "Install a hosted or digest-pinned release after validating its candidate",
|
|
2261
|
+
scope: "admin",
|
|
2262
|
+
inputSchema: installInput,
|
|
2263
|
+
returns: "PluginView"
|
|
2264
|
+
}, (input, { deps, call }) => {
|
|
2265
|
+
assertSecretRefUse(call.scopes, { authRef: input.secretRef });
|
|
2266
|
+
return deps.install(input, call.keyId);
|
|
2267
|
+
}).register("preview", {
|
|
2268
|
+
h: "Preview export changes and readable mounts without switching traffic; a pinned OCI candidate is started or reused",
|
|
2269
|
+
scope: "admin",
|
|
2270
|
+
inputSchema: previewInput,
|
|
2271
|
+
returns: "PluginUpgradePreview"
|
|
2272
|
+
}, (input, { deps, call }) => deps.preview(input, call.scopes, call.keyId)).register("upgrade", {
|
|
2273
|
+
h: "Validate and switch to a new release, or refresh the current release",
|
|
2274
|
+
scope: "admin",
|
|
2275
|
+
inputSchema: upgradeInput,
|
|
2276
|
+
returns: "PluginView"
|
|
2277
|
+
}, (input, { deps, call }) => deps.upgrade(input, call.scopes, call.keyId)).register("rollback", {
|
|
2278
|
+
h: "Check and restore the previous installed release",
|
|
2279
|
+
scope: "admin",
|
|
2280
|
+
inputSchema: z12.strictObject({ id: pluginIdSchema, digest: z12.string().regex(/^sha256:[0-9a-f]{64}$/).optional() }),
|
|
2281
|
+
returns: "PluginView"
|
|
2282
|
+
}, ({ id, digest }, { deps, call }) => deps.rollback(id, call.scopes, digest)).register(
|
|
2283
|
+
"list",
|
|
2284
|
+
{
|
|
2285
|
+
h: "list registered plugins (pluginToken never returned)",
|
|
2286
|
+
inputSchema: z12.strictObject({ opts: HTBP_LIST_OPTIONS_SCHEMA.optional() }),
|
|
2287
|
+
returns: "Page<PluginView> \u2014 manifest + the exports declared by its /~describe",
|
|
2288
|
+
scope: "admin"
|
|
2289
|
+
},
|
|
2290
|
+
({ opts }, { deps }) => deps.list(opts)
|
|
2291
|
+
).register(
|
|
2292
|
+
"get",
|
|
2293
|
+
{
|
|
2294
|
+
h: "fetch one plugin manifest by id",
|
|
2295
|
+
inputSchema: z12.strictObject({ id: pluginIdSchema }),
|
|
2296
|
+
returns: "PluginView \u2014 manifest + the exports declared by its /~describe",
|
|
2297
|
+
scope: "admin"
|
|
2298
|
+
},
|
|
2299
|
+
({ id }, { deps }) => deps.get(id)
|
|
2300
|
+
).register(
|
|
2301
|
+
"write",
|
|
2302
|
+
{
|
|
2303
|
+
h: "register a plugin: probes health and validates its /~describe exports before accepting; then mount an export via system/registry (config.provider = plugin id, config.export = export id)",
|
|
2304
|
+
inputSchema: pluginWriteSchema,
|
|
2305
|
+
returns: "PluginView + pluginToken shown once (platform-token only)",
|
|
2306
|
+
scope: "admin"
|
|
2307
|
+
},
|
|
2308
|
+
(input, { deps }) => deps.write(input)
|
|
2309
|
+
).register(
|
|
2310
|
+
"update",
|
|
2311
|
+
{
|
|
2312
|
+
h: "patch a registration; endpoint changes re-probe and re-validate the exports before applying",
|
|
2313
|
+
inputSchema: z12.strictObject({
|
|
2314
|
+
id: pluginIdSchema,
|
|
2315
|
+
patch: pluginPatchSchema
|
|
2316
|
+
}),
|
|
2317
|
+
returns: "PluginView \u2014 pluginToken shown once if auth switched to platform-token",
|
|
2318
|
+
scope: "admin"
|
|
2319
|
+
},
|
|
2320
|
+
({ id, patch }, { deps }) => deps.update(id, patch)
|
|
2321
|
+
).register(
|
|
2322
|
+
"delete",
|
|
2323
|
+
{
|
|
2324
|
+
h: "unregister a plugin and revoke its platform token; mounted nodes referencing it stop working",
|
|
2325
|
+
inputSchema: z12.strictObject({ id: pluginIdSchema }),
|
|
2326
|
+
returns: "void",
|
|
2327
|
+
scope: "admin"
|
|
2328
|
+
},
|
|
2329
|
+
async ({ id }, { deps }) => {
|
|
2330
|
+
await deps.remove(id);
|
|
2331
|
+
return VOID_ACK;
|
|
2332
|
+
}
|
|
2333
|
+
).register(
|
|
2334
|
+
"health",
|
|
2335
|
+
{
|
|
2336
|
+
h: "probe the plugin health endpoint now",
|
|
2337
|
+
inputSchema: z12.strictObject({ id: pluginIdSchema }),
|
|
2338
|
+
returns: "{ id, healthy, checkedAt }",
|
|
2339
|
+
scope: "admin"
|
|
2340
|
+
},
|
|
2341
|
+
({ id }, { deps }) => deps.health(id)
|
|
2342
|
+
);
|
|
2343
|
+
function clampLimit3(limit) {
|
|
2344
|
+
if (limit === void 0 || limit < 1) return LIST_LIMIT_DEFAULT;
|
|
2345
|
+
return limit > LIST_LIMIT_MAX ? LIST_LIMIT_MAX : limit;
|
|
2346
|
+
}
|
|
2347
|
+
function createPluginModule(deps) {
|
|
2348
|
+
const { store, sk, secrets, now } = deps;
|
|
2349
|
+
async function read(id) {
|
|
2350
|
+
return await store.get(KEY_PLUGIN + id);
|
|
2351
|
+
}
|
|
2352
|
+
async function require2(id) {
|
|
2353
|
+
const record = await read(id);
|
|
2354
|
+
if (!record) throw new TBError("not_found", `plugin '${id}' not found`);
|
|
2355
|
+
return record;
|
|
2356
|
+
}
|
|
2357
|
+
async function view(record) {
|
|
2358
|
+
const describe = record.describe ?? await store.get(KEY_PLUGIN_META + record.id);
|
|
2359
|
+
if (describe === null) {
|
|
2360
|
+
throw new TBError(
|
|
2361
|
+
"unavailable",
|
|
2362
|
+
`plugin '${record.id}' \u7F3A\u5C11 ~describe \u7F13\u5B58,\u8BF7\u91CD\u65B0\u6CE8\u518C`,
|
|
2363
|
+
{ retryable: false }
|
|
2364
|
+
);
|
|
2365
|
+
}
|
|
2366
|
+
return { ...manifestOf(record), exports: describe.exports, ...record.distribution ? { distribution: record.distribution } : {} };
|
|
2367
|
+
}
|
|
2368
|
+
async function revokeToken(record) {
|
|
2369
|
+
if (record.tokenSkId !== void 0) await sk.delete(record.tokenSkId);
|
|
2370
|
+
try {
|
|
2371
|
+
await secrets.delete(pluginTokenSecretName(record.id));
|
|
2372
|
+
} catch {
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
async function probeAndRecord(manifest) {
|
|
2376
|
+
const result = await deps.probe(manifest);
|
|
2377
|
+
const prev = await store.get(KEY_PLUGIN_HEALTH + manifest.id);
|
|
2378
|
+
const record = {
|
|
2379
|
+
healthy: result.healthy,
|
|
2380
|
+
checkedAt: now(),
|
|
2381
|
+
consecutiveFailures: result.healthy ? 0 : (prev?.consecutiveFailures ?? 0) + 1
|
|
2382
|
+
};
|
|
2383
|
+
await store.put(KEY_PLUGIN_HEALTH + manifest.id, record);
|
|
2384
|
+
return record;
|
|
2385
|
+
}
|
|
2386
|
+
async function write(args) {
|
|
2387
|
+
const manifest = parsePluginManifest(args, {
|
|
2388
|
+
allowInsecureHttp: deps.allowInsecureHttp ?? false
|
|
2389
|
+
});
|
|
2390
|
+
const probed = await deps.probe(manifest);
|
|
2391
|
+
if (!probed.healthy) {
|
|
2392
|
+
throw new TBError(
|
|
2393
|
+
"unavailable",
|
|
2394
|
+
`plugin '${manifest.id}' \u63A2\u6D3B\u5931\u8D25,\u62D2\u7EDD\u6CE8\u518C${probed.detail !== void 0 ? `:${probed.detail}` : ""}`,
|
|
2395
|
+
{ retryable: true }
|
|
2396
|
+
);
|
|
2397
|
+
}
|
|
2398
|
+
const contract = await deps.fetchContract(manifest);
|
|
2399
|
+
const describe = validatePluginContract({ manifest, describe: contract.describe });
|
|
2400
|
+
const existing = await read(manifest.id);
|
|
2401
|
+
if (existing?.distribution) throw new TBError("conflict", "use plugin upgrade for an installed release");
|
|
2402
|
+
if (existing) await revokeToken(existing);
|
|
2403
|
+
let pluginToken;
|
|
2404
|
+
let tokenSkId;
|
|
2405
|
+
if (manifest.auth.kind === "platform-token") {
|
|
2406
|
+
const minted = await sk.write({ owner: `plugin:${manifest.id}`, scopes: [] }, now());
|
|
2407
|
+
await secrets.set(pluginTokenSecretName(manifest.id), minted.secret, now());
|
|
2408
|
+
pluginToken = minted.secret;
|
|
2409
|
+
tokenSkId = minted.key.id;
|
|
2410
|
+
}
|
|
2411
|
+
await store.put(KEY_PLUGIN_META + manifest.id, describe);
|
|
1746
2412
|
await store.put(KEY_PLUGIN_HEALTH + manifest.id, {
|
|
1747
2413
|
healthy: true,
|
|
1748
2414
|
checkedAt: now(),
|
|
@@ -1752,7 +2418,11 @@ function createPluginModule(deps) {
|
|
|
1752
2418
|
...manifest,
|
|
1753
2419
|
...tokenSkId !== void 0 ? { tokenSkId } : {}
|
|
1754
2420
|
};
|
|
1755
|
-
|
|
2421
|
+
if (!existing && store.putIfAbsent) {
|
|
2422
|
+
if (!await store.putIfAbsent(KEY_PLUGIN + manifest.id, record)) throw new TBError("conflict", "plugin registered concurrently");
|
|
2423
|
+
} else {
|
|
2424
|
+
await store.put(KEY_PLUGIN + manifest.id, record);
|
|
2425
|
+
}
|
|
1756
2426
|
return {
|
|
1757
2427
|
...manifest,
|
|
1758
2428
|
exports: describe.exports,
|
|
@@ -1764,7 +2434,14 @@ function createPluginModule(deps) {
|
|
|
1764
2434
|
if (patch.id !== void 0 && patch.id !== id) {
|
|
1765
2435
|
throw new TBError("invalid_argument", "id \u4E0D\u53EF\u901A\u8FC7 update \u53D8\u66F4");
|
|
1766
2436
|
}
|
|
1767
|
-
|
|
2437
|
+
if (existing.distribution) {
|
|
2438
|
+
if (Object.keys(patch).some((k) => k !== "enabled"))
|
|
2439
|
+
throw new TBError("invalid_argument", "use plugin upgrade to change an installed release");
|
|
2440
|
+
const record2 = { ...existing, enabled: typeof patch.enabled === "boolean" ? patch.enabled : existing.enabled, revision: existing.revision + 1 };
|
|
2441
|
+
if (!await store.compareAndSwap?.(KEY_PLUGIN + id, existing.revision, record2)) throw new TBError("conflict", "plugin changed");
|
|
2442
|
+
return view(record2);
|
|
2443
|
+
}
|
|
2444
|
+
const prev = manifestOf(existing);
|
|
1768
2445
|
const merged = parsePluginManifest(
|
|
1769
2446
|
{ ...prev, ...patch },
|
|
1770
2447
|
{ allowInsecureHttp: deps.allowInsecureHttp ?? false }
|
|
@@ -1815,14 +2492,19 @@ function createPluginModule(deps) {
|
|
|
1815
2492
|
async function remove(id) {
|
|
1816
2493
|
const existing = await read(id);
|
|
1817
2494
|
if (!existing) return;
|
|
2495
|
+
if (existing.distribution) {
|
|
2496
|
+
if (!await store.compareAndSwap?.(KEY_PLUGIN + id, existing.revision, null)) throw new TBError("conflict", "plugin changed");
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
1818
2499
|
await revokeToken(existing);
|
|
1819
2500
|
await store.delete(KEY_PLUGIN + id);
|
|
1820
2501
|
await store.delete(KEY_PLUGIN_HEALTH + id);
|
|
1821
2502
|
await store.delete(KEY_PLUGIN_META + id);
|
|
1822
2503
|
}
|
|
1823
2504
|
return COMMANDS2.module({
|
|
2505
|
+
...createDistribution(deps),
|
|
1824
2506
|
async list(opts) {
|
|
1825
|
-
const listOpts = { limit:
|
|
2507
|
+
const listOpts = { limit: clampLimit3(opts?.limit) };
|
|
1826
2508
|
if (opts?.cursor !== void 0) listOpts.cursor = opts.cursor;
|
|
1827
2509
|
const page = await store.list(KEY_PLUGIN, listOpts);
|
|
1828
2510
|
const items = await Promise.all(
|
|
@@ -1837,7 +2519,12 @@ function createPluginModule(deps) {
|
|
|
1837
2519
|
update,
|
|
1838
2520
|
remove,
|
|
1839
2521
|
async health(id) {
|
|
1840
|
-
const
|
|
2522
|
+
const installed = await require2(id);
|
|
2523
|
+
if (installed.distribution) {
|
|
2524
|
+
const { healthy } = await deps.probe(installed);
|
|
2525
|
+
return { id, healthy, checkedAt: now() };
|
|
2526
|
+
}
|
|
2527
|
+
const manifest = manifestOf(installed);
|
|
1841
2528
|
const record = await probeAndRecord(manifest);
|
|
1842
2529
|
return { id, healthy: record.healthy, checkedAt: record.checkedAt };
|
|
1843
2530
|
}
|
|
@@ -1845,27 +2532,27 @@ function createPluginModule(deps) {
|
|
|
1845
2532
|
}
|
|
1846
2533
|
|
|
1847
2534
|
// ../core/src/builtin/store.ts
|
|
1848
|
-
import { z as
|
|
2535
|
+
import { z as z13 } from "zod/v4";
|
|
1849
2536
|
var DESCRIPTION3 = "Deployment-level private object Store for uploads, reads and short-lived sharing";
|
|
1850
|
-
var contentTypeSchema =
|
|
1851
|
-
var filenameSchema =
|
|
2537
|
+
var contentTypeSchema = z13.string().min(1).describe("object MIME type");
|
|
2538
|
+
var filenameSchema = z13.string().optional().describe(
|
|
1852
2539
|
"display-only filename; never used as a storage key"
|
|
1853
2540
|
);
|
|
1854
|
-
var checksumSchema =
|
|
1855
|
-
algorithm:
|
|
1856
|
-
value:
|
|
2541
|
+
var checksumSchema = z13.strictObject({
|
|
2542
|
+
algorithm: z13.literal("sha256"),
|
|
2543
|
+
value: z13.string()
|
|
1857
2544
|
}).optional().describe("optional sha256 checksum declaration");
|
|
1858
|
-
var uriSchema =
|
|
2545
|
+
var uriSchema = z13.string().describe("store://default/<objectId>");
|
|
1859
2546
|
var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
1860
2547
|
"create_upload",
|
|
1861
2548
|
{
|
|
1862
2549
|
h: "create a new opaque Store object and bounded upload session",
|
|
1863
|
-
inputSchema:
|
|
2550
|
+
inputSchema: z13.strictObject({
|
|
1864
2551
|
contentType: contentTypeSchema,
|
|
1865
2552
|
filename: filenameSchema,
|
|
1866
|
-
size:
|
|
2553
|
+
size: z13.number().optional().describe("expected byte size"),
|
|
1867
2554
|
checksum: checksumSchema,
|
|
1868
|
-
idempotencyKey:
|
|
2555
|
+
idempotencyKey: z13.string().optional().describe("owner-scoped create retry key")
|
|
1869
2556
|
}),
|
|
1870
2557
|
returns: "StoreUploadGrant",
|
|
1871
2558
|
scope: "write"
|
|
@@ -1888,7 +2575,7 @@ var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
|
1888
2575
|
"complete_upload",
|
|
1889
2576
|
{
|
|
1890
2577
|
h: "verify a direct upload and atomically mark its object ready; idempotent",
|
|
1891
|
-
inputSchema:
|
|
2578
|
+
inputSchema: z13.strictObject({ uploadId: z13.string().min(1) }),
|
|
1892
2579
|
returns: "StoreObject",
|
|
1893
2580
|
scope: "write"
|
|
1894
2581
|
},
|
|
@@ -1897,7 +2584,7 @@ var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
|
1897
2584
|
"abort_upload",
|
|
1898
2585
|
{
|
|
1899
2586
|
h: "abandon an unfinished upload; idempotent until the object is ready",
|
|
1900
|
-
inputSchema:
|
|
2587
|
+
inputSchema: z13.strictObject({ uploadId: z13.string().min(1) }),
|
|
1901
2588
|
returns: "void",
|
|
1902
2589
|
scope: "write"
|
|
1903
2590
|
},
|
|
@@ -1906,7 +2593,7 @@ var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
|
1906
2593
|
"stat",
|
|
1907
2594
|
{
|
|
1908
2595
|
h: "return metadata for a ready object owned by the current principal",
|
|
1909
|
-
inputSchema:
|
|
2596
|
+
inputSchema: z13.strictObject({ uri: uriSchema }),
|
|
1910
2597
|
returns: "StoreObject",
|
|
1911
2598
|
scope: "read"
|
|
1912
2599
|
},
|
|
@@ -1915,7 +2602,7 @@ var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
|
1915
2602
|
"read",
|
|
1916
2603
|
{
|
|
1917
2604
|
h: "authorize an object read and return a short-lived $ref",
|
|
1918
|
-
inputSchema:
|
|
2605
|
+
inputSchema: z13.strictObject({ uri: uriSchema }),
|
|
1919
2606
|
returns: "{ $ref, contentType, size, expiresAt }",
|
|
1920
2607
|
scope: "read"
|
|
1921
2608
|
},
|
|
@@ -1927,9 +2614,9 @@ var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
|
1927
2614
|
"share",
|
|
1928
2615
|
{
|
|
1929
2616
|
h: "create a short-lived, revocable read share for an owned object",
|
|
1930
|
-
inputSchema:
|
|
2617
|
+
inputSchema: z13.strictObject({
|
|
1931
2618
|
uri: uriSchema,
|
|
1932
|
-
ttlSec:
|
|
2619
|
+
ttlSec: z13.number().int().positive().optional()
|
|
1933
2620
|
}),
|
|
1934
2621
|
returns: "StoreShare",
|
|
1935
2622
|
scope: "write"
|
|
@@ -1942,7 +2629,7 @@ var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
|
1942
2629
|
"revoke_share",
|
|
1943
2630
|
{
|
|
1944
2631
|
h: "revoke a Store share grant",
|
|
1945
|
-
inputSchema:
|
|
2632
|
+
inputSchema: z13.strictObject({ shareId: z13.string().min(1) }),
|
|
1946
2633
|
returns: "void",
|
|
1947
2634
|
scope: "write"
|
|
1948
2635
|
},
|
|
@@ -1951,7 +2638,7 @@ var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
|
1951
2638
|
"delete",
|
|
1952
2639
|
{
|
|
1953
2640
|
h: "make an owned Store object immediately unreadable and delete its bytes",
|
|
1954
|
-
inputSchema:
|
|
2641
|
+
inputSchema: z13.strictObject({ uri: uriSchema }),
|
|
1955
2642
|
returns: "void",
|
|
1956
2643
|
scope: "write"
|
|
1957
2644
|
},
|
|
@@ -1960,7 +2647,7 @@ var COMMANDS3 = new BuiltinCommandRegistry("store", DESCRIPTION3).register(
|
|
|
1960
2647
|
"list",
|
|
1961
2648
|
{
|
|
1962
2649
|
h: "list ready Store objects owned by the current principal",
|
|
1963
|
-
inputSchema:
|
|
2650
|
+
inputSchema: z13.strictObject({ opts: HTBP_LIST_OPTIONS_SCHEMA.optional() }),
|
|
1964
2651
|
returns: "Page<StoreObject>",
|
|
1965
2652
|
scope: "read"
|
|
1966
2653
|
},
|
|
@@ -1971,18 +2658,18 @@ function createStoreModule(deps) {
|
|
|
1971
2658
|
}
|
|
1972
2659
|
|
|
1973
2660
|
// ../core/src/builtin/annotation.ts
|
|
1974
|
-
import { z as
|
|
2661
|
+
import { z as z14 } from "zod/v4";
|
|
1975
2662
|
var DESCRIPTION4 = "Path annotations: admin-curated notes shown in ~help of the annotated path (set / get / remove / list)";
|
|
1976
|
-
var rootablePathSchema =
|
|
2663
|
+
var rootablePathSchema = z14.string().describe('tree path; "" = tree-wide notice');
|
|
1977
2664
|
var COMMANDS4 = new BuiltinCommandRegistry("annotation", DESCRIPTION4).register(
|
|
1978
2665
|
"set",
|
|
1979
2666
|
{
|
|
1980
2667
|
h: "upsert the note shown in ~help of <path>; empty path = tree-wide notice",
|
|
1981
|
-
inputSchema:
|
|
1982
|
-
path:
|
|
2668
|
+
inputSchema: z14.strictObject({
|
|
2669
|
+
path: z14.string().describe(
|
|
1983
2670
|
'tree path (tool sub-paths like "feishu/create-doc" work); "" = tree-wide'
|
|
1984
2671
|
),
|
|
1985
|
-
text:
|
|
2672
|
+
text: z14.string().min(1).max(ANNOTATION_TEXT_MAX).describe("the note (max 2000 chars)")
|
|
1986
2673
|
}),
|
|
1987
2674
|
returns: "{ path, text, updatedAt, updatedBy }",
|
|
1988
2675
|
scope: "admin"
|
|
@@ -1995,7 +2682,7 @@ var COMMANDS4 = new BuiltinCommandRegistry("annotation", DESCRIPTION4).register(
|
|
|
1995
2682
|
"get",
|
|
1996
2683
|
{
|
|
1997
2684
|
h: "read the note of one path (not_found if none)",
|
|
1998
|
-
inputSchema:
|
|
2685
|
+
inputSchema: z14.strictObject({ path: rootablePathSchema }),
|
|
1999
2686
|
returns: "{ path, text, updatedAt, updatedBy }",
|
|
2000
2687
|
scope: "read"
|
|
2001
2688
|
},
|
|
@@ -2010,7 +2697,7 @@ var COMMANDS4 = new BuiltinCommandRegistry("annotation", DESCRIPTION4).register(
|
|
|
2010
2697
|
"remove",
|
|
2011
2698
|
{
|
|
2012
2699
|
h: "remove the note of a path (idempotent)",
|
|
2013
|
-
inputSchema:
|
|
2700
|
+
inputSchema: z14.strictObject({ path: rootablePathSchema }),
|
|
2014
2701
|
returns: "void",
|
|
2015
2702
|
scope: "admin"
|
|
2016
2703
|
},
|
|
@@ -2022,8 +2709,8 @@ var COMMANDS4 = new BuiltinCommandRegistry("annotation", DESCRIPTION4).register(
|
|
|
2022
2709
|
"list",
|
|
2023
2710
|
{
|
|
2024
2711
|
h: "all annotated paths (optionally under a prefix)",
|
|
2025
|
-
inputSchema:
|
|
2026
|
-
prefix:
|
|
2712
|
+
inputSchema: z14.strictObject({
|
|
2713
|
+
prefix: z14.string().optional().describe("only paths under this prefix")
|
|
2027
2714
|
}),
|
|
2028
2715
|
returns: "{ items: Array<{ path, text, updatedAt, updatedBy }> }",
|
|
2029
2716
|
scope: "read"
|
|
@@ -2035,7 +2722,7 @@ function createAnnotationModule(deps) {
|
|
|
2035
2722
|
}
|
|
2036
2723
|
|
|
2037
2724
|
// ../core/src/builtin/federation.ts
|
|
2038
|
-
import { z as
|
|
2725
|
+
import { z as z15 } from "zod/v4";
|
|
2039
2726
|
|
|
2040
2727
|
// ../core/src/tool/allowlist.ts
|
|
2041
2728
|
function normalizeAllowHost(raw) {
|
|
@@ -2119,7 +2806,7 @@ var COMMANDS5 = new BuiltinCommandRegistry("federation", DESCRIPTION5).register(
|
|
|
2119
2806
|
"list",
|
|
2120
2807
|
{
|
|
2121
2808
|
h: "merged allowlist view: env baseline entries (removable=false) plus runtime entries",
|
|
2122
|
-
inputSchema:
|
|
2809
|
+
inputSchema: z15.strictObject({}),
|
|
2123
2810
|
returns: 'Page<{ host, source: "env"|"store", removable, updatedAt? }>',
|
|
2124
2811
|
scope: "admin"
|
|
2125
2812
|
},
|
|
@@ -2128,8 +2815,8 @@ var COMMANDS5 = new BuiltinCommandRegistry("federation", DESCRIPTION5).register(
|
|
|
2128
2815
|
"add",
|
|
2129
2816
|
{
|
|
2130
2817
|
h: "allow a host (suffix match covers subdomains); takes effect immediately",
|
|
2131
|
-
inputSchema:
|
|
2132
|
-
host:
|
|
2818
|
+
inputSchema: z15.strictObject({
|
|
2819
|
+
host: z15.string().min(1).describe(
|
|
2133
2820
|
'bare host suffix, e.g. "example.com" \u2014 no scheme/port/path'
|
|
2134
2821
|
)
|
|
2135
2822
|
}),
|
|
@@ -2147,8 +2834,8 @@ var COMMANDS5 = new BuiltinCommandRegistry("federation", DESCRIPTION5).register(
|
|
|
2147
2834
|
"remove",
|
|
2148
2835
|
{
|
|
2149
2836
|
h: "remove a runtime-added host; env baseline entries cannot be removed here",
|
|
2150
|
-
inputSchema:
|
|
2151
|
-
host:
|
|
2837
|
+
inputSchema: z15.strictObject({
|
|
2838
|
+
host: z15.string().min(1).describe("bare host suffix as listed")
|
|
2152
2839
|
}),
|
|
2153
2840
|
returns: "void \u2014 env baseline entries are not removable",
|
|
2154
2841
|
scope: "admin"
|
|
@@ -2170,10 +2857,10 @@ function createFederationModule(deps) {
|
|
|
2170
2857
|
}
|
|
2171
2858
|
|
|
2172
2859
|
// ../core/src/builtin/registry.ts
|
|
2173
|
-
import { z as
|
|
2860
|
+
import { z as z19 } from "zod/v4";
|
|
2174
2861
|
|
|
2175
2862
|
// ../core/src/protocol/wire.ts
|
|
2176
|
-
import { z as
|
|
2863
|
+
import { z as z18 } from "zod";
|
|
2177
2864
|
|
|
2178
2865
|
// ../core/src/secret/keyring.ts
|
|
2179
2866
|
function validateEncryptionKeyring(input) {
|
|
@@ -2240,7 +2927,7 @@ function positiveInteger(value, fallback, field) {
|
|
|
2240
2927
|
}
|
|
2241
2928
|
return actual;
|
|
2242
2929
|
}
|
|
2243
|
-
function
|
|
2930
|
+
function clampLimit4(value) {
|
|
2244
2931
|
if (value === void 0) return LIST_LIMIT_DEFAULT2;
|
|
2245
2932
|
if (!Number.isSafeInteger(value) || value < 1) {
|
|
2246
2933
|
throw new TBError("invalid_argument", "limit must be a positive integer");
|
|
@@ -2587,7 +3274,7 @@ var DeviceMailboxService = class {
|
|
|
2587
3274
|
return await this.detail(await this.expireRecord(key, record));
|
|
2588
3275
|
}
|
|
2589
3276
|
async list(input) {
|
|
2590
|
-
const limit =
|
|
3277
|
+
const limit = clampLimit4(input.limit);
|
|
2591
3278
|
const states = input.states === void 0 ? void 0 : new Set(input.states);
|
|
2592
3279
|
if (states !== void 0 && [...states].some((state) => !isState(state))) {
|
|
2593
3280
|
throw new TBError("invalid_argument", "states contains an invalid operation state");
|
|
@@ -2613,7 +3300,7 @@ var DeviceMailboxService = class {
|
|
|
2613
3300
|
deviceId: input.deviceId,
|
|
2614
3301
|
claimableBy: input.deviceKeyId,
|
|
2615
3302
|
now: serverNow,
|
|
2616
|
-
limit:
|
|
3303
|
+
limit: clampLimit4(input.limit),
|
|
2617
3304
|
...input.cursor === void 0 ? {} : { cursor: input.cursor }
|
|
2618
3305
|
});
|
|
2619
3306
|
for (const item of page.items) {
|
|
@@ -2785,7 +3472,7 @@ var DeviceMailboxService = class {
|
|
|
2785
3472
|
}
|
|
2786
3473
|
/** Re-encrypt only unchanged ledger revisions; concurrent lease/terminal transitions retain authority. */
|
|
2787
3474
|
async reencryptPage(opts = {}) {
|
|
2788
|
-
const page = await this.repository.list({ ...opts, limit:
|
|
3475
|
+
const page = await this.repository.list({ ...opts, limit: clampLimit4(opts.limit) });
|
|
2789
3476
|
let changed = 0;
|
|
2790
3477
|
for (const item of page.items) {
|
|
2791
3478
|
const record = parseRecord(item.value);
|
|
@@ -2805,7 +3492,7 @@ var DeviceMailboxService = class {
|
|
|
2805
3492
|
}
|
|
2806
3493
|
async cleanup(opts = {}) {
|
|
2807
3494
|
const page = await this.repository.list({
|
|
2808
|
-
limit:
|
|
3495
|
+
limit: clampLimit4(opts.limit),
|
|
2809
3496
|
...opts.cursor === void 0 ? {} : { cursor: opts.cursor }
|
|
2810
3497
|
});
|
|
2811
3498
|
let deleted = 0;
|
|
@@ -2833,320 +3520,339 @@ var DeviceMailboxService = class {
|
|
|
2833
3520
|
}
|
|
2834
3521
|
};
|
|
2835
3522
|
|
|
3523
|
+
// ../core/src/device/environment.ts
|
|
3524
|
+
import { z as z16 } from "zod";
|
|
3525
|
+
var deviceEnvironmentSchema = z16.strictObject({
|
|
3526
|
+
platform: z16.enum(["darwin", "linux", "win32", "android", "ios", "other"]),
|
|
3527
|
+
arch: z16.string().min(1).max(32).regex(/^[a-zA-Z0-9._-]+$/).optional(),
|
|
3528
|
+
runtime: z16.enum(["node", "bun", "react-native", "other"]).optional(),
|
|
3529
|
+
runtimeVersion: z16.string().min(1).max(64).regex(/^[a-zA-Z0-9.+_-]+$/).optional(),
|
|
3530
|
+
runtimeId: z16.string().min(1).max(128).regex(/^[a-zA-Z0-9._-]+$/).optional()
|
|
3531
|
+
});
|
|
3532
|
+
|
|
2836
3533
|
// ../core/src/protocol/errorWire.ts
|
|
2837
|
-
import { z as
|
|
2838
|
-
var tbErrorCodeSchema =
|
|
2839
|
-
var tbErrorBodySchema =
|
|
3534
|
+
import { z as z17 } from "zod";
|
|
3535
|
+
var tbErrorCodeSchema = z17.enum(TB_ERROR_CODES);
|
|
3536
|
+
var tbErrorBodySchema = z17.object({
|
|
2840
3537
|
code: tbErrorCodeSchema,
|
|
2841
|
-
message:
|
|
2842
|
-
retryable:
|
|
3538
|
+
message: z17.string(),
|
|
3539
|
+
retryable: z17.boolean()
|
|
2843
3540
|
});
|
|
2844
3541
|
|
|
2845
3542
|
// ../core/src/protocol/wire.ts
|
|
2846
|
-
var actionSchema =
|
|
2847
|
-
var nodeKindSchema =
|
|
2848
|
-
var nodeInputConfigSchema =
|
|
3543
|
+
var actionSchema = z18.enum(ACTIONS);
|
|
3544
|
+
var nodeKindSchema = z18.enum(NODE_KINDS);
|
|
3545
|
+
var nodeInputConfigSchema = z18.record(z18.string(), z18.unknown()).optional().describe(
|
|
2849
3546
|
"kind-specific config, e.g. mcp: { url, auth?, authRef?, oauthClient?: { clientId, clientSecretRef? } } / http: { endpoint, tools } / context: { provider, bucket, \u2026 } / remote: { baseUrl, skRef }; credentials go by SecretStore reference name, never inline"
|
|
2850
3547
|
);
|
|
2851
|
-
var nodeInputVirtualizeSchema =
|
|
2852
|
-
prefix:
|
|
2853
|
-
rename:
|
|
2854
|
-
hide:
|
|
2855
|
-
describe:
|
|
3548
|
+
var nodeInputVirtualizeSchema = z18.strictObject({
|
|
3549
|
+
prefix: z18.string().optional(),
|
|
3550
|
+
rename: z18.record(z18.string(), z18.string()).optional(),
|
|
3551
|
+
hide: z18.array(z18.string()).optional(),
|
|
3552
|
+
describe: z18.record(z18.string(), z18.string()).optional()
|
|
2856
3553
|
}).optional().describe(
|
|
2857
3554
|
"optional tool virtualization: { prefix?, rename?: {from:to}, hide?: [name], describe?: {name:text} }"
|
|
2858
3555
|
);
|
|
2859
|
-
var nodeInputSchema =
|
|
2860
|
-
path:
|
|
3556
|
+
var nodeInputSchema = z18.strictObject({
|
|
3557
|
+
path: z18.string().min(1).describe('tree path to mount at, e.g. "docs/context7"'),
|
|
2861
3558
|
kind: nodeKindSchema.describe("node kind; determines the config shape"),
|
|
2862
|
-
description:
|
|
3559
|
+
description: z18.string().min(1).describe("one-line description shown in parent ~help"),
|
|
2863
3560
|
config: nodeInputConfigSchema,
|
|
2864
3561
|
virtualize: nodeInputVirtualizeSchema
|
|
2865
3562
|
});
|
|
2866
|
-
var presenceStateSchema =
|
|
2867
|
-
var presenceSchema =
|
|
2868
|
-
lastSeenAt:
|
|
3563
|
+
var presenceStateSchema = z18.enum(["online", "stale", "offline"]);
|
|
3564
|
+
var presenceSchema = z18.object({
|
|
3565
|
+
lastSeenAt: z18.string().optional(),
|
|
2869
3566
|
state: presenceStateSchema
|
|
2870
3567
|
});
|
|
2871
|
-
var helpFeedbackItemSchema =
|
|
2872
|
-
id:
|
|
2873
|
-
score:
|
|
2874
|
-
title:
|
|
3568
|
+
var helpFeedbackItemSchema = z18.object({
|
|
3569
|
+
id: z18.string(),
|
|
3570
|
+
score: z18.number(),
|
|
3571
|
+
title: z18.string()
|
|
2875
3572
|
});
|
|
2876
|
-
var helpChildSchema =
|
|
2877
|
-
description:
|
|
3573
|
+
var helpChildSchema = z18.object({
|
|
3574
|
+
description: z18.string(),
|
|
2878
3575
|
kind: nodeKindSchema,
|
|
2879
|
-
path:
|
|
3576
|
+
path: z18.string()
|
|
2880
3577
|
});
|
|
2881
|
-
var helpCommandSchema =
|
|
2882
|
-
confirm:
|
|
2883
|
-
delivery:
|
|
2884
|
-
effect:
|
|
2885
|
-
h:
|
|
2886
|
-
inputSchema:
|
|
2887
|
-
method:
|
|
2888
|
-
name:
|
|
2889
|
-
outputSchema:
|
|
2890
|
-
path:
|
|
2891
|
-
returns:
|
|
3578
|
+
var helpCommandSchema = z18.object({
|
|
3579
|
+
confirm: z18.boolean().optional(),
|
|
3580
|
+
delivery: z18.enum(["realtime", "mailbox", "both"]).optional(),
|
|
3581
|
+
effect: z18.string().optional(),
|
|
3582
|
+
h: z18.string().optional(),
|
|
3583
|
+
inputSchema: z18.unknown().optional(),
|
|
3584
|
+
method: z18.literal("POST"),
|
|
3585
|
+
name: z18.string(),
|
|
3586
|
+
outputSchema: z18.unknown().optional(),
|
|
3587
|
+
path: z18.string(),
|
|
3588
|
+
returns: z18.string().optional(),
|
|
2892
3589
|
scope: actionSchema
|
|
2893
3590
|
});
|
|
2894
|
-
var
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
3591
|
+
var deviceContextSchema = z18.strictObject({
|
|
3592
|
+
environment: deviceEnvironmentSchema,
|
|
3593
|
+
reportedAt: z18.iso.datetime({ offset: true }),
|
|
3594
|
+
presence: presenceSchema.optional()
|
|
3595
|
+
});
|
|
3596
|
+
var helpJsonSchema = z18.object({
|
|
3597
|
+
children: z18.array(helpChildSchema).optional(),
|
|
3598
|
+
cmds: z18.array(helpCommandSchema),
|
|
3599
|
+
deviceContext: deviceContextSchema.optional(),
|
|
3600
|
+
feedback: z18.array(helpFeedbackItemSchema).optional(),
|
|
3601
|
+
hint: z18.string().optional(),
|
|
3602
|
+
htbp: z18.string(),
|
|
3603
|
+
node: z18.object({
|
|
3604
|
+
description: z18.string(),
|
|
2902
3605
|
kind: nodeKindSchema,
|
|
2903
|
-
path:
|
|
3606
|
+
path: z18.string()
|
|
2904
3607
|
}),
|
|
2905
|
-
note:
|
|
3608
|
+
note: z18.string().optional()
|
|
2906
3609
|
});
|
|
2907
|
-
var treeJsonSchema =
|
|
2908
|
-
children:
|
|
2909
|
-
description:
|
|
3610
|
+
var treeJsonSchema = z18.lazy(() => z18.object({
|
|
3611
|
+
children: z18.array(treeJsonSchema).optional(),
|
|
3612
|
+
description: z18.string(),
|
|
2910
3613
|
kind: nodeKindSchema,
|
|
2911
|
-
path:
|
|
3614
|
+
path: z18.string(),
|
|
2912
3615
|
presence: presenceSchema.optional(),
|
|
2913
|
-
truncated:
|
|
3616
|
+
truncated: z18.boolean().optional()
|
|
2914
3617
|
}));
|
|
2915
|
-
var toolSpecSchema =
|
|
2916
|
-
confirm:
|
|
2917
|
-
delivery:
|
|
2918
|
-
description:
|
|
2919
|
-
effect:
|
|
2920
|
-
inputSchema:
|
|
2921
|
-
name:
|
|
2922
|
-
outputSchema:
|
|
3618
|
+
var toolSpecSchema = z18.object({
|
|
3619
|
+
confirm: z18.boolean().optional(),
|
|
3620
|
+
delivery: z18.enum(["realtime", "mailbox", "both"]).optional(),
|
|
3621
|
+
description: z18.string().optional(),
|
|
3622
|
+
effect: z18.string().optional(),
|
|
3623
|
+
inputSchema: z18.unknown().optional(),
|
|
3624
|
+
name: z18.string(),
|
|
3625
|
+
outputSchema: z18.unknown().optional()
|
|
2923
3626
|
});
|
|
2924
|
-
var toolSearchRelevanceSchema =
|
|
2925
|
-
coverage:
|
|
2926
|
-
matchedTermCount:
|
|
2927
|
-
rankingVersion:
|
|
2928
|
-
totalTermCount:
|
|
3627
|
+
var toolSearchRelevanceSchema = z18.strictObject({
|
|
3628
|
+
coverage: z18.number().min(0).max(1),
|
|
3629
|
+
matchedTermCount: z18.number().int().nonnegative(),
|
|
3630
|
+
rankingVersion: z18.literal("keyword-v2"),
|
|
3631
|
+
totalTermCount: z18.number().int().positive()
|
|
2929
3632
|
}).refine(
|
|
2930
3633
|
(value) => value.matchedTermCount <= value.totalTermCount && value.coverage === value.matchedTermCount / value.totalTermCount,
|
|
2931
3634
|
{ message: "coverage must equal matchedTermCount / totalTermCount" }
|
|
2932
3635
|
);
|
|
2933
|
-
var toolSearchSourceSchema =
|
|
2934
|
-
path:
|
|
3636
|
+
var toolSearchSourceSchema = z18.strictObject({
|
|
3637
|
+
path: z18.string()
|
|
2935
3638
|
});
|
|
2936
|
-
var toolSearchSourceResultSchema =
|
|
2937
|
-
path:
|
|
2938
|
-
status:
|
|
3639
|
+
var toolSearchSourceResultSchema = z18.strictObject({
|
|
3640
|
+
path: z18.string(),
|
|
3641
|
+
status: z18.enum([
|
|
2939
3642
|
"ok",
|
|
2940
3643
|
"unsupported",
|
|
2941
3644
|
"timed_out",
|
|
2942
3645
|
"unavailable",
|
|
2943
3646
|
"cycle",
|
|
2944
3647
|
"hop_limit",
|
|
3648
|
+
"index_capacity",
|
|
2945
3649
|
"budget_exhausted",
|
|
2946
3650
|
"invalid_response"
|
|
2947
3651
|
])
|
|
2948
3652
|
});
|
|
2949
|
-
var toolSearchItemSchema =
|
|
2950
|
-
path:
|
|
3653
|
+
var toolSearchItemSchema = z18.strictObject({
|
|
3654
|
+
path: z18.string(),
|
|
2951
3655
|
relevance: toolSearchRelevanceSchema,
|
|
2952
3656
|
source: toolSearchSourceSchema.optional(),
|
|
2953
3657
|
tool: toolSpecSchema
|
|
2954
3658
|
});
|
|
2955
3659
|
function pageSchema(itemSchema) {
|
|
2956
|
-
return
|
|
2957
|
-
cursor:
|
|
2958
|
-
items:
|
|
3660
|
+
return z18.object({
|
|
3661
|
+
cursor: z18.string().optional(),
|
|
3662
|
+
items: z18.array(itemSchema)
|
|
2959
3663
|
});
|
|
2960
3664
|
}
|
|
2961
|
-
var toolSearchPageSchema =
|
|
2962
|
-
cursor:
|
|
2963
|
-
items:
|
|
2964
|
-
partial:
|
|
2965
|
-
snapshot:
|
|
2966
|
-
sources:
|
|
3665
|
+
var toolSearchPageSchema = z18.strictObject({
|
|
3666
|
+
cursor: z18.string().optional(),
|
|
3667
|
+
items: z18.array(toolSearchItemSchema),
|
|
3668
|
+
partial: z18.boolean().optional(),
|
|
3669
|
+
snapshot: z18.string().optional(),
|
|
3670
|
+
sources: z18.array(toolSearchSourceResultSchema).optional()
|
|
2967
3671
|
});
|
|
2968
|
-
var toolSearchOptionsSchema =
|
|
2969
|
-
cursor:
|
|
2970
|
-
detail:
|
|
2971
|
-
effects:
|
|
2972
|
-
federation:
|
|
2973
|
-
limit:
|
|
2974
|
-
matching:
|
|
2975
|
-
minCoverage:
|
|
2976
|
-
mode:
|
|
2977
|
-
pathPrefix:
|
|
3672
|
+
var toolSearchOptionsSchema = z18.strictObject({
|
|
3673
|
+
cursor: z18.string().optional(),
|
|
3674
|
+
detail: z18.enum(["compact", "full"]).optional(),
|
|
3675
|
+
effects: z18.array(z18.enum(["read", "write", "destructive", "unknown"])).min(1).optional(),
|
|
3676
|
+
federation: z18.enum(["local", "recursive"]).optional(),
|
|
3677
|
+
limit: z18.number().int().optional(),
|
|
3678
|
+
matching: z18.enum(["best", "all"]).optional(),
|
|
3679
|
+
minCoverage: z18.number().gt(0).max(1).optional(),
|
|
3680
|
+
mode: z18.enum(["keyword"]).optional(),
|
|
3681
|
+
pathPrefix: z18.string().optional()
|
|
2978
3682
|
});
|
|
2979
|
-
var toolSearchRequestSchema =
|
|
3683
|
+
var toolSearchRequestSchema = z18.strictObject({
|
|
2980
3684
|
opts: toolSearchOptionsSchema.optional(),
|
|
2981
|
-
query:
|
|
3685
|
+
query: z18.string().trim().min(1)
|
|
2982
3686
|
});
|
|
2983
|
-
var deviceOperationStateSchema =
|
|
3687
|
+
var deviceOperationStateSchema = z18.enum(
|
|
2984
3688
|
DEVICE_OPERATION_STATES
|
|
2985
3689
|
);
|
|
2986
|
-
var deviceOperationCallerSchema =
|
|
2987
|
-
keyId:
|
|
2988
|
-
owner:
|
|
3690
|
+
var deviceOperationCallerSchema = z18.object({
|
|
3691
|
+
keyId: z18.string().min(1),
|
|
3692
|
+
owner: z18.string().min(1)
|
|
2989
3693
|
});
|
|
2990
3694
|
var deviceOperationSummaryShape = {
|
|
2991
|
-
attempt:
|
|
3695
|
+
attempt: z18.number().int().nonnegative(),
|
|
2992
3696
|
caller: deviceOperationCallerSchema,
|
|
2993
|
-
cancelRequestedAt:
|
|
2994
|
-
createdAt:
|
|
2995
|
-
deviceId:
|
|
2996
|
-
executionMayHaveOccurred:
|
|
2997
|
-
expiresAt:
|
|
2998
|
-
leaseUntil:
|
|
2999
|
-
mountPath:
|
|
3000
|
-
operationId:
|
|
3697
|
+
cancelRequestedAt: z18.iso.datetime({ offset: true }).optional(),
|
|
3698
|
+
createdAt: z18.iso.datetime({ offset: true }),
|
|
3699
|
+
deviceId: z18.string().min(1),
|
|
3700
|
+
executionMayHaveOccurred: z18.boolean(),
|
|
3701
|
+
expiresAt: z18.iso.datetime({ offset: true }),
|
|
3702
|
+
leaseUntil: z18.iso.datetime({ offset: true }).optional(),
|
|
3703
|
+
mountPath: z18.string().min(1),
|
|
3704
|
+
operationId: z18.string().min(1),
|
|
3001
3705
|
state: deviceOperationStateSchema,
|
|
3002
|
-
targetPath:
|
|
3003
|
-
terminalAt:
|
|
3004
|
-
traceId:
|
|
3005
|
-
updatedAt:
|
|
3706
|
+
targetPath: z18.string().min(1),
|
|
3707
|
+
terminalAt: z18.iso.datetime({ offset: true }).optional(),
|
|
3708
|
+
traceId: z18.string().min(1),
|
|
3709
|
+
updatedAt: z18.iso.datetime({ offset: true })
|
|
3006
3710
|
};
|
|
3007
|
-
var deviceOperationSummarySchema =
|
|
3711
|
+
var deviceOperationSummarySchema = z18.object(
|
|
3008
3712
|
deviceOperationSummaryShape
|
|
3009
3713
|
);
|
|
3010
|
-
var deviceOperationDetailSchema =
|
|
3714
|
+
var deviceOperationDetailSchema = z18.object({
|
|
3011
3715
|
...deviceOperationSummaryShape,
|
|
3012
3716
|
error: tbErrorBodySchema.optional(),
|
|
3013
|
-
result:
|
|
3717
|
+
result: z18.json().optional()
|
|
3014
3718
|
});
|
|
3015
|
-
var deviceOperationListRequestSchema =
|
|
3016
|
-
deviceId:
|
|
3017
|
-
opts:
|
|
3018
|
-
cursor:
|
|
3019
|
-
limit:
|
|
3020
|
-
states:
|
|
3719
|
+
var deviceOperationListRequestSchema = z18.strictObject({
|
|
3720
|
+
deviceId: z18.string().min(1),
|
|
3721
|
+
opts: z18.strictObject({
|
|
3722
|
+
cursor: z18.string().min(1).optional(),
|
|
3723
|
+
limit: z18.number().int().positive().optional(),
|
|
3724
|
+
states: z18.array(deviceOperationStateSchema).min(1).optional()
|
|
3021
3725
|
}).optional()
|
|
3022
3726
|
});
|
|
3023
3727
|
var deviceOperationListResponseSchema = pageSchema(deviceOperationSummarySchema);
|
|
3024
|
-
var deviceOperationIdentityRequestSchema =
|
|
3025
|
-
deviceId:
|
|
3026
|
-
operationId:
|
|
3728
|
+
var deviceOperationIdentityRequestSchema = z18.strictObject({
|
|
3729
|
+
deviceId: z18.string().min(1),
|
|
3730
|
+
operationId: z18.string().min(1)
|
|
3027
3731
|
});
|
|
3028
|
-
var deviceOperationClaimRequestSchema =
|
|
3029
|
-
cursor:
|
|
3030
|
-
deviceId:
|
|
3031
|
-
limit:
|
|
3732
|
+
var deviceOperationClaimRequestSchema = z18.strictObject({
|
|
3733
|
+
cursor: z18.string().min(1).optional(),
|
|
3734
|
+
deviceId: z18.string().min(1),
|
|
3735
|
+
limit: z18.number().int().positive().optional()
|
|
3032
3736
|
});
|
|
3033
|
-
var deviceOperationClaimSchema =
|
|
3034
|
-
arguments:
|
|
3035
|
-
attempt:
|
|
3737
|
+
var deviceOperationClaimSchema = z18.object({
|
|
3738
|
+
arguments: z18.record(z18.string(), z18.json()),
|
|
3739
|
+
attempt: z18.number().int().positive(),
|
|
3036
3740
|
caller: deviceOperationCallerSchema,
|
|
3037
|
-
cancelRequestedAt:
|
|
3038
|
-
createdAt:
|
|
3039
|
-
expiresAt:
|
|
3040
|
-
leaseId:
|
|
3041
|
-
leaseUntil:
|
|
3042
|
-
operationId:
|
|
3043
|
-
path:
|
|
3044
|
-
targetPath:
|
|
3045
|
-
traceId:
|
|
3741
|
+
cancelRequestedAt: z18.iso.datetime({ offset: true }).optional(),
|
|
3742
|
+
createdAt: z18.iso.datetime({ offset: true }),
|
|
3743
|
+
expiresAt: z18.iso.datetime({ offset: true }),
|
|
3744
|
+
leaseId: z18.string().min(1),
|
|
3745
|
+
leaseUntil: z18.iso.datetime({ offset: true }),
|
|
3746
|
+
operationId: z18.string().min(1),
|
|
3747
|
+
path: z18.string().min(1),
|
|
3748
|
+
targetPath: z18.string().min(1),
|
|
3749
|
+
traceId: z18.string().min(1)
|
|
3046
3750
|
});
|
|
3047
|
-
var deviceOperationClaimResponseSchema =
|
|
3048
|
-
cursor:
|
|
3751
|
+
var deviceOperationClaimResponseSchema = z18.object({
|
|
3752
|
+
cursor: z18.string().optional(),
|
|
3049
3753
|
operation: deviceOperationClaimSchema.optional(),
|
|
3050
|
-
serverNow:
|
|
3754
|
+
serverNow: z18.iso.datetime({ offset: true })
|
|
3051
3755
|
});
|
|
3052
3756
|
var deviceOperationLeaseShape = {
|
|
3053
|
-
deviceId:
|
|
3054
|
-
leaseId:
|
|
3055
|
-
operationId:
|
|
3757
|
+
deviceId: z18.string().min(1),
|
|
3758
|
+
leaseId: z18.string().min(1),
|
|
3759
|
+
operationId: z18.string().min(1)
|
|
3056
3760
|
};
|
|
3057
|
-
var deviceOperationRenewRequestSchema =
|
|
3058
|
-
var deviceOperationRenewResponseSchema =
|
|
3059
|
-
cancelRequestedAt:
|
|
3060
|
-
leaseUntil:
|
|
3061
|
-
serverNow:
|
|
3761
|
+
var deviceOperationRenewRequestSchema = z18.strictObject(deviceOperationLeaseShape);
|
|
3762
|
+
var deviceOperationRenewResponseSchema = z18.object({
|
|
3763
|
+
cancelRequestedAt: z18.iso.datetime({ offset: true }).optional(),
|
|
3764
|
+
leaseUntil: z18.iso.datetime({ offset: true }),
|
|
3765
|
+
serverNow: z18.iso.datetime({ offset: true })
|
|
3062
3766
|
});
|
|
3063
|
-
var deviceOperationCompleteRequestSchema =
|
|
3064
|
-
|
|
3767
|
+
var deviceOperationCompleteRequestSchema = z18.discriminatedUnion("outcome", [
|
|
3768
|
+
z18.strictObject({
|
|
3065
3769
|
...deviceOperationLeaseShape,
|
|
3066
|
-
outcome:
|
|
3067
|
-
result:
|
|
3770
|
+
outcome: z18.literal("succeeded"),
|
|
3771
|
+
result: z18.json()
|
|
3068
3772
|
}),
|
|
3069
|
-
|
|
3773
|
+
z18.strictObject({
|
|
3070
3774
|
...deviceOperationLeaseShape,
|
|
3071
3775
|
error: tbErrorBodySchema,
|
|
3072
|
-
outcome:
|
|
3776
|
+
outcome: z18.literal("rejected")
|
|
3073
3777
|
}),
|
|
3074
|
-
|
|
3778
|
+
z18.strictObject({
|
|
3075
3779
|
...deviceOperationLeaseShape,
|
|
3076
3780
|
error: tbErrorBodySchema,
|
|
3077
|
-
outcome:
|
|
3781
|
+
outcome: z18.literal("failed")
|
|
3078
3782
|
}),
|
|
3079
|
-
|
|
3783
|
+
z18.strictObject({
|
|
3080
3784
|
...deviceOperationLeaseShape,
|
|
3081
3785
|
error: tbErrorBodySchema.optional(),
|
|
3082
|
-
outcome:
|
|
3786
|
+
outcome: z18.literal("result_unknown")
|
|
3083
3787
|
})
|
|
3084
3788
|
]);
|
|
3085
|
-
var registryNodeSchema =
|
|
3086
|
-
config:
|
|
3087
|
-
createdAt:
|
|
3088
|
-
description:
|
|
3089
|
-
deviceId:
|
|
3789
|
+
var registryNodeSchema = z18.object({
|
|
3790
|
+
config: z18.record(z18.string(), z18.unknown()).optional(),
|
|
3791
|
+
createdAt: z18.string().optional(),
|
|
3792
|
+
description: z18.string(),
|
|
3793
|
+
deviceId: z18.string().optional(),
|
|
3794
|
+
deviceEnvironment: deviceEnvironmentSchema.optional(),
|
|
3795
|
+
deviceReportedAt: z18.iso.datetime({ offset: true }).optional(),
|
|
3090
3796
|
kind: nodeKindSchema,
|
|
3091
|
-
lastSeenAt:
|
|
3092
|
-
online:
|
|
3093
|
-
path:
|
|
3094
|
-
registeredBy:
|
|
3095
|
-
updatedAt:
|
|
3096
|
-
virtualize:
|
|
3797
|
+
lastSeenAt: z18.string().optional(),
|
|
3798
|
+
online: z18.boolean().optional(),
|
|
3799
|
+
path: z18.string(),
|
|
3800
|
+
registeredBy: z18.string().optional(),
|
|
3801
|
+
updatedAt: z18.string().optional(),
|
|
3802
|
+
virtualize: z18.record(z18.string(), z18.unknown()).optional()
|
|
3097
3803
|
});
|
|
3098
3804
|
var feedbackViewShape = {
|
|
3099
|
-
at:
|
|
3100
|
-
by:
|
|
3101
|
-
down:
|
|
3102
|
-
id:
|
|
3103
|
-
score:
|
|
3104
|
-
title:
|
|
3105
|
-
up:
|
|
3805
|
+
at: z18.string(),
|
|
3806
|
+
by: z18.string(),
|
|
3807
|
+
down: z18.number().int().nonnegative(),
|
|
3808
|
+
id: z18.string(),
|
|
3809
|
+
score: z18.number().int(),
|
|
3810
|
+
title: z18.string(),
|
|
3811
|
+
up: z18.number().int().nonnegative()
|
|
3106
3812
|
};
|
|
3107
|
-
var feedbackViewSchema =
|
|
3108
|
-
var feedbackDetailSchema =
|
|
3813
|
+
var feedbackViewSchema = z18.object(feedbackViewShape);
|
|
3814
|
+
var feedbackDetailSchema = z18.object({
|
|
3109
3815
|
...feedbackViewShape,
|
|
3110
|
-
detail:
|
|
3111
|
-
path:
|
|
3816
|
+
detail: z18.string(),
|
|
3817
|
+
path: z18.string()
|
|
3112
3818
|
});
|
|
3113
|
-
var feedbackListSchema =
|
|
3114
|
-
var feedbackSubmitRequestSchema =
|
|
3115
|
-
detail:
|
|
3116
|
-
title:
|
|
3819
|
+
var feedbackListSchema = z18.object({ items: z18.array(feedbackViewSchema) });
|
|
3820
|
+
var feedbackSubmitRequestSchema = z18.strictObject({
|
|
3821
|
+
detail: z18.string(),
|
|
3822
|
+
title: z18.string()
|
|
3117
3823
|
});
|
|
3118
|
-
var feedbackSubmitResponseSchema =
|
|
3119
|
-
at:
|
|
3120
|
-
id:
|
|
3121
|
-
path:
|
|
3122
|
-
title:
|
|
3824
|
+
var feedbackSubmitResponseSchema = z18.object({
|
|
3825
|
+
at: z18.string().optional(),
|
|
3826
|
+
id: z18.string(),
|
|
3827
|
+
path: z18.string(),
|
|
3828
|
+
title: z18.string()
|
|
3123
3829
|
});
|
|
3124
|
-
var feedbackVoteRequestSchema =
|
|
3125
|
-
vote:
|
|
3830
|
+
var feedbackVoteRequestSchema = z18.strictObject({
|
|
3831
|
+
vote: z18.enum(["up", "down", "clear"])
|
|
3126
3832
|
});
|
|
3127
|
-
var feedbackRemoveResponseSchema =
|
|
3128
|
-
var oauthAuthorizeRequestSchema =
|
|
3129
|
-
redirectUri:
|
|
3833
|
+
var feedbackRemoveResponseSchema = z18.object({ ok: z18.literal(true) });
|
|
3834
|
+
var oauthAuthorizeRequestSchema = z18.strictObject({
|
|
3835
|
+
redirectUri: z18.string().optional()
|
|
3130
3836
|
});
|
|
3131
|
-
var oauthAuthorizeResponseSchema =
|
|
3132
|
-
|
|
3133
|
-
|
|
3837
|
+
var oauthAuthorizeResponseSchema = z18.discriminatedUnion("status", [
|
|
3838
|
+
z18.object({ status: z18.literal("authorized") }),
|
|
3839
|
+
z18.object({ authorizationUrl: z18.url(), status: z18.literal("redirect") })
|
|
3134
3840
|
]);
|
|
3135
|
-
var healthResponseSchema =
|
|
3136
|
-
catalog:
|
|
3137
|
-
count:
|
|
3138
|
-
digest:
|
|
3841
|
+
var healthResponseSchema = z18.object({
|
|
3842
|
+
catalog: z18.object({
|
|
3843
|
+
count: z18.number().int().nonnegative(),
|
|
3844
|
+
digest: z18.string()
|
|
3139
3845
|
}).optional(),
|
|
3140
|
-
healthy:
|
|
3141
|
-
version:
|
|
3846
|
+
healthy: z18.boolean(),
|
|
3847
|
+
version: z18.string()
|
|
3142
3848
|
});
|
|
3143
|
-
var livenessResponseSchema =
|
|
3144
|
-
var readinessResponseSchema =
|
|
3145
|
-
checks:
|
|
3146
|
-
detail:
|
|
3147
|
-
ok:
|
|
3849
|
+
var livenessResponseSchema = z18.object({ live: z18.boolean() });
|
|
3850
|
+
var readinessResponseSchema = z18.object({
|
|
3851
|
+
checks: z18.record(z18.string(), z18.object({
|
|
3852
|
+
detail: z18.string().optional(),
|
|
3853
|
+
ok: z18.boolean()
|
|
3148
3854
|
})),
|
|
3149
|
-
ready:
|
|
3855
|
+
ready: z18.boolean()
|
|
3150
3856
|
});
|
|
3151
3857
|
|
|
3152
3858
|
// ../core/src/builtin/registry.ts
|
|
@@ -3169,8 +3875,8 @@ var COMMANDS6 = new BuiltinCommandRegistry("registry", DESCRIPTION6).register(
|
|
|
3169
3875
|
"list",
|
|
3170
3876
|
{
|
|
3171
3877
|
h: "list registered nodes, optionally under a path prefix",
|
|
3172
|
-
inputSchema:
|
|
3173
|
-
prefix:
|
|
3878
|
+
inputSchema: z19.strictObject({
|
|
3879
|
+
prefix: z19.string().optional().describe("only nodes under this path prefix"),
|
|
3174
3880
|
opts: HTBP_LIST_OPTIONS_SCHEMA.optional()
|
|
3175
3881
|
}),
|
|
3176
3882
|
returns: "Page<Node>",
|
|
@@ -3186,8 +3892,8 @@ var COMMANDS6 = new BuiltinCommandRegistry("registry", DESCRIPTION6).register(
|
|
|
3186
3892
|
"get",
|
|
3187
3893
|
{
|
|
3188
3894
|
h: "fetch one node registration (kind, description, config) by path",
|
|
3189
|
-
inputSchema:
|
|
3190
|
-
path:
|
|
3895
|
+
inputSchema: z19.strictObject({
|
|
3896
|
+
path: z19.string().min(1).describe("exact tree path")
|
|
3191
3897
|
}),
|
|
3192
3898
|
returns: "Node",
|
|
3193
3899
|
scope: "read"
|
|
@@ -3211,8 +3917,8 @@ var COMMANDS6 = new BuiltinCommandRegistry("registry", DESCRIPTION6).register(
|
|
|
3211
3917
|
"update",
|
|
3212
3918
|
{
|
|
3213
3919
|
h: "patch fields of a mounted node (description, config, virtualize, \u2026) without remounting",
|
|
3214
|
-
inputSchema:
|
|
3215
|
-
path:
|
|
3920
|
+
inputSchema: z19.strictObject({
|
|
3921
|
+
path: z19.string().min(1).describe("exact tree path"),
|
|
3216
3922
|
patch: nodePatchSchema
|
|
3217
3923
|
}),
|
|
3218
3924
|
returns: "Node",
|
|
@@ -3223,8 +3929,8 @@ var COMMANDS6 = new BuiltinCommandRegistry("registry", DESCRIPTION6).register(
|
|
|
3223
3929
|
"delete",
|
|
3224
3930
|
{
|
|
3225
3931
|
h: "unmount a node (and reclaim empty auto-created parents); a node registered by another key can only be removed by its registrar or by a key holding the 'admin' scope on that path",
|
|
3226
|
-
inputSchema:
|
|
3227
|
-
path:
|
|
3932
|
+
inputSchema: z19.strictObject({
|
|
3933
|
+
path: z19.string().min(1).describe("exact tree path")
|
|
3228
3934
|
}),
|
|
3229
3935
|
returns: "void",
|
|
3230
3936
|
scope: "register"
|
|
@@ -3239,7 +3945,7 @@ function createRegistryModule(store, now, visibility) {
|
|
|
3239
3945
|
}
|
|
3240
3946
|
|
|
3241
3947
|
// ../core/src/builtin/secret.ts
|
|
3242
|
-
import { z as
|
|
3948
|
+
import { z as z20 } from "zod/v4";
|
|
3243
3949
|
var DESCRIPTION7 = "Upstream credential vault: write-only; mounts reference entries by name (authRef), values can never be read back (admin only)";
|
|
3244
3950
|
function assertUserSecretName(name) {
|
|
3245
3951
|
if (name.includes(":")) {
|
|
@@ -3253,11 +3959,11 @@ var COMMANDS7 = new BuiltinCommandRegistry("secret", DESCRIPTION7).register(
|
|
|
3253
3959
|
"set",
|
|
3254
3960
|
{
|
|
3255
3961
|
h: "store or rotate a credential under a name; mount configs reference it as authRef",
|
|
3256
|
-
inputSchema:
|
|
3257
|
-
name:
|
|
3962
|
+
inputSchema: z20.strictObject({
|
|
3963
|
+
name: z20.string().min(1).describe(
|
|
3258
3964
|
'reference name used as authRef in mount configs (":" is reserved)'
|
|
3259
3965
|
),
|
|
3260
|
-
value:
|
|
3966
|
+
value: z20.string().min(1).describe(
|
|
3261
3967
|
"the credential (token / key / JSON); encrypted at rest, never echoed"
|
|
3262
3968
|
)
|
|
3263
3969
|
}),
|
|
@@ -3273,7 +3979,7 @@ var COMMANDS7 = new BuiltinCommandRegistry("secret", DESCRIPTION7).register(
|
|
|
3273
3979
|
"list",
|
|
3274
3980
|
{
|
|
3275
3981
|
h: "list stored credential names (names and timestamps only, never values)",
|
|
3276
|
-
inputSchema:
|
|
3982
|
+
inputSchema: z20.strictObject({ opts: HTBP_LIST_OPTIONS_SCHEMA.optional() }),
|
|
3277
3983
|
returns: "Page<{ name, updatedAt }>",
|
|
3278
3984
|
scope: "admin"
|
|
3279
3985
|
},
|
|
@@ -3282,8 +3988,8 @@ var COMMANDS7 = new BuiltinCommandRegistry("secret", DESCRIPTION7).register(
|
|
|
3282
3988
|
"delete",
|
|
3283
3989
|
{
|
|
3284
3990
|
h: "delete a credential; mounts still referencing it will fail to resolve",
|
|
3285
|
-
inputSchema:
|
|
3286
|
-
name:
|
|
3991
|
+
inputSchema: z20.strictObject({
|
|
3992
|
+
name: z20.string().min(1).describe("reference name")
|
|
3287
3993
|
}),
|
|
3288
3994
|
returns: "void",
|
|
3289
3995
|
scope: "admin"
|
|
@@ -3299,13 +4005,13 @@ function createSecretModule(store, now) {
|
|
|
3299
4005
|
}
|
|
3300
4006
|
|
|
3301
4007
|
// ../core/src/builtin/status.ts
|
|
3302
|
-
import { z as
|
|
4008
|
+
import { z as z21 } from "zod/v4";
|
|
3303
4009
|
var DESCRIPTION8 = "Gateway health and summary (readable without admin)";
|
|
3304
4010
|
var COMMANDS8 = new BuiltinCommandRegistry("status", DESCRIPTION8).register(
|
|
3305
4011
|
"get",
|
|
3306
4012
|
{
|
|
3307
4013
|
h: "health summary: gateway version and node count; no arguments",
|
|
3308
|
-
inputSchema:
|
|
4014
|
+
inputSchema: z21.strictObject({}),
|
|
3309
4015
|
returns: "{ healthy, version, nodeCount }",
|
|
3310
4016
|
scope: "read"
|
|
3311
4017
|
},
|
|
@@ -3323,41 +4029,41 @@ function createStatusModule(deps) {
|
|
|
3323
4029
|
}
|
|
3324
4030
|
|
|
3325
4031
|
// ../core/src/builtin/sk.ts
|
|
3326
|
-
import { z as
|
|
4032
|
+
import { z as z22 } from "zod/v4";
|
|
3327
4033
|
var DESCRIPTION9 = "Secret Key registry: issue / list / update / revoke access keys (the only credential form; admin only)";
|
|
3328
|
-
var actionSchema2 =
|
|
3329
|
-
var scopeSchema =
|
|
3330
|
-
pattern:
|
|
3331
|
-
actions:
|
|
3332
|
-
effect:
|
|
4034
|
+
var actionSchema2 = z22.enum(["read", "write", "call", "register", "admin"]);
|
|
4035
|
+
var scopeSchema = z22.strictObject({
|
|
4036
|
+
pattern: z22.string().describe('tree path glob, e.g. "**" (everything) or "docs/**"'),
|
|
4037
|
+
actions: z22.array(actionSchema2),
|
|
4038
|
+
effect: z22.enum(["allow", "deny"]).optional().describe('default "allow"')
|
|
3333
4039
|
});
|
|
3334
|
-
var ownerSchema =
|
|
4040
|
+
var ownerSchema = z22.string().min(1).describe(
|
|
3335
4041
|
'owner ref: "user:<name>" | "agent:<name>" | "device:<id>"'
|
|
3336
4042
|
);
|
|
3337
|
-
var descriptionSchema =
|
|
3338
|
-
var scopesSchema =
|
|
4043
|
+
var descriptionSchema = z22.string().optional().describe("what this key is for (shown in list)");
|
|
4044
|
+
var scopesSchema = z22.array(scopeSchema).describe(
|
|
3339
4045
|
"permission grants; deny wins over allow, no match = denied"
|
|
3340
4046
|
);
|
|
3341
|
-
var registerPathsSchema =
|
|
4047
|
+
var registerPathsSchema = z22.array(z22.string()).optional().describe(
|
|
3342
4048
|
"path prefixes this key may self-register nodes under (via ~register)"
|
|
3343
4049
|
);
|
|
3344
|
-
var expiresAtSchema =
|
|
4050
|
+
var expiresAtSchema = z22.string().optional().describe(
|
|
3345
4051
|
"expiry, ISO 8601 timestamp with timezone; omit = never"
|
|
3346
4052
|
);
|
|
3347
|
-
var writeSchema =
|
|
4053
|
+
var writeSchema = z22.strictObject({
|
|
3348
4054
|
owner: ownerSchema,
|
|
3349
4055
|
description: descriptionSchema,
|
|
3350
4056
|
scopes: scopesSchema,
|
|
3351
4057
|
registerPaths: registerPathsSchema,
|
|
3352
4058
|
expiresAt: expiresAtSchema
|
|
3353
4059
|
});
|
|
3354
|
-
var patchSchema2 =
|
|
4060
|
+
var patchSchema2 = z22.strictObject({
|
|
3355
4061
|
owner: ownerSchema.optional(),
|
|
3356
4062
|
description: descriptionSchema,
|
|
3357
4063
|
scopes: scopesSchema.optional(),
|
|
3358
4064
|
registerPaths: registerPathsSchema,
|
|
3359
4065
|
expiresAt: expiresAtSchema,
|
|
3360
|
-
disabled:
|
|
4066
|
+
disabled: z22.boolean().optional().describe("true = key rejected until re-enabled")
|
|
3361
4067
|
}).describe("fields to change; same shape as write (all optional) plus disabled");
|
|
3362
4068
|
function toSecretKeyInput(input) {
|
|
3363
4069
|
return {
|
|
@@ -3382,7 +4088,7 @@ var COMMANDS9 = new BuiltinCommandRegistry("sk", DESCRIPTION9).register(
|
|
|
3382
4088
|
"list",
|
|
3383
4089
|
{
|
|
3384
4090
|
h: "list issued keys (id, owner, scopes; the secret itself is never returned)",
|
|
3385
|
-
inputSchema:
|
|
4091
|
+
inputSchema: z22.strictObject({ opts: HTBP_LIST_OPTIONS_SCHEMA.optional() }),
|
|
3386
4092
|
returns: "Page<SecretKey without hash>",
|
|
3387
4093
|
scope: "admin"
|
|
3388
4094
|
},
|
|
@@ -3391,8 +4097,8 @@ var COMMANDS9 = new BuiltinCommandRegistry("sk", DESCRIPTION9).register(
|
|
|
3391
4097
|
"get",
|
|
3392
4098
|
{
|
|
3393
4099
|
h: "fetch one key by id",
|
|
3394
|
-
inputSchema:
|
|
3395
|
-
id:
|
|
4100
|
+
inputSchema: z22.strictObject({
|
|
4101
|
+
id: z22.string().min(1).describe("key id (from list or the issue response)")
|
|
3396
4102
|
}),
|
|
3397
4103
|
returns: "SecretKey without hash",
|
|
3398
4104
|
scope: "admin"
|
|
@@ -3411,8 +4117,8 @@ var COMMANDS9 = new BuiltinCommandRegistry("sk", DESCRIPTION9).register(
|
|
|
3411
4117
|
"update",
|
|
3412
4118
|
{
|
|
3413
4119
|
h: "patch fields of an issued key (scopes, expiresAt, disabled, \u2026); takes effect immediately",
|
|
3414
|
-
inputSchema:
|
|
3415
|
-
id:
|
|
4120
|
+
inputSchema: z22.strictObject({
|
|
4121
|
+
id: z22.string().min(1).describe("key id"),
|
|
3416
4122
|
patch: patchSchema2
|
|
3417
4123
|
}),
|
|
3418
4124
|
returns: "SecretKey without hash",
|
|
@@ -3423,7 +4129,7 @@ var COMMANDS9 = new BuiltinCommandRegistry("sk", DESCRIPTION9).register(
|
|
|
3423
4129
|
"delete",
|
|
3424
4130
|
{
|
|
3425
4131
|
h: "revoke a key permanently; takes effect immediately",
|
|
3426
|
-
inputSchema:
|
|
4132
|
+
inputSchema: z22.strictObject({ id: z22.string().min(1).describe("key id") }),
|
|
3427
4133
|
returns: "void",
|
|
3428
4134
|
scope: "admin"
|
|
3429
4135
|
},
|
|
@@ -3437,24 +4143,24 @@ function createSkModule(store, now) {
|
|
|
3437
4143
|
}
|
|
3438
4144
|
|
|
3439
4145
|
// ../core/src/builtin/keys.ts
|
|
3440
|
-
import { z as
|
|
4146
|
+
import { z as z24 } from "zod";
|
|
3441
4147
|
|
|
3442
4148
|
// ../core/src/keyManagement.ts
|
|
3443
|
-
import { z as
|
|
3444
|
-
var keyRotateSchema =
|
|
3445
|
-
expectedRevision:
|
|
3446
|
-
target:
|
|
3447
|
-
revokeExisting:
|
|
4149
|
+
import { z as z23 } from "zod";
|
|
4150
|
+
var keyRotateSchema = z23.strictObject({
|
|
4151
|
+
expectedRevision: z23.number().int().nonnegative(),
|
|
4152
|
+
target: z23.enum(["encryption", "signing"]),
|
|
4153
|
+
revokeExisting: z23.boolean().optional()
|
|
3448
4154
|
});
|
|
3449
|
-
var keyRetireSchema =
|
|
3450
|
-
expectedRevision:
|
|
3451
|
-
keyId:
|
|
3452
|
-
target:
|
|
4155
|
+
var keyRetireSchema = z23.strictObject({
|
|
4156
|
+
expectedRevision: z23.number().int().nonnegative(),
|
|
4157
|
+
keyId: z23.string().regex(/^[A-Za-z0-9_-]{1,64}$/),
|
|
4158
|
+
target: z23.enum(["encryption", "signing"])
|
|
3453
4159
|
});
|
|
3454
|
-
var keyResumeSchema =
|
|
4160
|
+
var keyResumeSchema = z23.strictObject({ jobId: z23.string().min(1).max(128) });
|
|
3455
4161
|
|
|
3456
4162
|
// ../core/src/builtin/keys.ts
|
|
3457
|
-
var commands = new BuiltinCommandRegistry("keys", "\u52A0\u5BC6\u6839\u3001\u7B7E\u540D\u5BC6\u94A5\u4E0E\u53EF\u6062\u590D\u8F6E\u6362\uFF08\u7BA1\u7406\u5458\uFF09").register("status", { inputSchema:
|
|
4163
|
+
var commands = new BuiltinCommandRegistry("keys", "\u52A0\u5BC6\u6839\u3001\u7B7E\u540D\u5BC6\u94A5\u4E0E\u53EF\u6062\u590D\u8F6E\u6362\uFF08\u7BA1\u7406\u5458\uFF09").register("status", { inputSchema: z24.strictObject({}), scope: "admin", h: "\u67E5\u770B\u5BC6\u94A5\u7248\u672C\u3001\u5F15\u7528\u548C\u8F6E\u6362\u8FDB\u5EA6\uFF0C\u4E0D\u542B\u6839\u6750\u6599", returns: "KeyStatus" }, async (_, { deps }) => deps.status()).register("rotate", { inputSchema: keyRotateSchema, scope: "admin", h: "\u7EF4\u62A4\u7A97\u53E3\u5185\u751F\u6210\u65B0\u6839\uFF1B\u65E7\u6839\u9ED8\u8BA4\u4FDD\u7559\uFF0C\u91CD\u52A0\u5BC6\u53EF\u6062\u590D", returns: "KeyStatus" }, async (input, { deps }) => deps.rotate(input)).register("resume", { inputSchema: keyResumeSchema, scope: "admin", h: "\u7EE7\u7EED\u4E00\u6279\u91CD\u52A0\u5BC6\u4EFB\u52A1\uFF0C\u5B8C\u6210\u540E\u68C0\u67E5\u65E7\u5BC6\u6587\u5F15\u7528", returns: "KeyStatus" }, async (input, { deps }) => deps.resume(input)).register("retire", { inputSchema: keyRetireSchema, scope: "admin", h: "\u4EC5\u5728\u65E0\u5F15\u7528\u4E14\u7B7E\u540D\u5B89\u5168\u7A97\u53E3\u5DF2\u8FC7\u540E\u5220\u9664\u65E7\u6839", returns: "KeyStatus" }, async (input, { deps }) => deps.retire(input)).register("backup", { inputSchema: z24.strictObject({}), scope: "admin", h: "\u663E\u5F0F\u5BFC\u51FA\u5305\u542B\u5BC6\u94A5\u7684\u5B9E\u4F8B\u6062\u590D\u6587\u4EF6\uFF1B\u8BF7\u5B89\u5168\u4FDD\u5B58", returns: "KeyBackup" }, async (_, { deps }) => deps.backup());
|
|
3458
4164
|
var createKeysModule = (deps) => commands.module(deps);
|
|
3459
4165
|
|
|
3460
4166
|
// ../core/src/builtin/index.ts
|
|
@@ -3499,47 +4205,47 @@ function createBuiltins(deps) {
|
|
|
3499
4205
|
}
|
|
3500
4206
|
|
|
3501
4207
|
// ../core/src/builtin/deployment.ts
|
|
3502
|
-
import { z as
|
|
4208
|
+
import { z as z26 } from "zod";
|
|
3503
4209
|
|
|
3504
4210
|
// ../core/src/deployment.ts
|
|
3505
|
-
import { z as
|
|
3506
|
-
var directory =
|
|
3507
|
-
var deploymentSettingsSchema =
|
|
3508
|
-
image:
|
|
3509
|
-
hostPort:
|
|
3510
|
-
bindAddress:
|
|
4211
|
+
import { z as z25 } from "zod";
|
|
4212
|
+
var directory = z25.string().min(2).startsWith("/").refine((value) => !/(?:^|\/)\.\.(?:\/|$)/.test(value) && !/^\/(?:etc|proc|sys|dev|var\/run)(?:\/|$)/.test(value), "\u8BF7\u9009\u62E9\u90E8\u7F72\u76EE\u5F55\u5185\u7684\u7EDD\u5BF9\u8DEF\u5F84");
|
|
4213
|
+
var deploymentSettingsSchema = z25.strictObject({
|
|
4214
|
+
image: z25.string().min(1).max(512).regex(/^[a-zA-Z0-9][a-zA-Z0-9._:/@-]*$/).describe("\u5E94\u7528\u955C\u50CF"),
|
|
4215
|
+
hostPort: z25.number().int().min(1).max(65535).describe("\u5BBF\u4E3B\u8BBF\u95EE\u7AEF\u53E3"),
|
|
4216
|
+
bindAddress: z25.enum(["127.0.0.1", "0.0.0.0"]).describe("\u76D1\u542C\u8303\u56F4"),
|
|
3511
4217
|
stateDirectory: directory.optional().describe("\u5BBF\u4E3B\u6570\u636E\u76EE\u5F55\uFF08\u53EF\u9009\uFF09"),
|
|
3512
4218
|
uiDirectory: directory.optional().describe("\u5BBF\u4E3B\u7BA1\u7406\u754C\u9762\u76EE\u5F55\uFF08\u53EF\u9009\uFF09")
|
|
3513
4219
|
});
|
|
3514
|
-
var deploymentUpdateSchema =
|
|
3515
|
-
var deploymentClaimSchema =
|
|
3516
|
-
var deploymentCompleteSchema =
|
|
4220
|
+
var deploymentUpdateSchema = z25.strictObject({ expectedRevision: z25.number().int().nonnegative(), settings: deploymentSettingsSchema });
|
|
4221
|
+
var deploymentClaimSchema = z25.strictObject({ agentId: z25.string().min(1).max(128), instanceId: z25.string().min(1), observed: deploymentSettingsSchema });
|
|
4222
|
+
var deploymentCompleteSchema = z25.strictObject({ jobId: z25.string().min(1), leaseToken: z25.string().min(1), ok: z25.boolean(), error: z25.enum(["preflight_failed", "apply_failed", "health_failed", "rollback_failed"]).optional() });
|
|
3517
4223
|
|
|
3518
4224
|
// ../core/src/builtin/deployment.ts
|
|
3519
|
-
var commands2 = new BuiltinCommandRegistry("deployment", "\u90E8\u7F72\u6267\u884C\u5668\u3001\u671F\u671B\u914D\u7F6E\u4E0E\u5B9E\u9645\u751F\u6548\u72B6\u6001\uFF08\u7BA1\u7406\u5458\uFF09").register("schema", { inputSchema:
|
|
4225
|
+
var commands2 = new BuiltinCommandRegistry("deployment", "\u90E8\u7F72\u6267\u884C\u5668\u3001\u671F\u671B\u914D\u7F6E\u4E0E\u5B9E\u9645\u751F\u6548\u72B6\u6001\uFF08\u7BA1\u7406\u5458\uFF09").register("schema", { inputSchema: z26.strictObject({}), scope: "admin", h: "\u67E5\u8BE2\u90E8\u7F72\u8BBE\u7F6E\u5B57\u6BB5", returns: "JSON Schema" }, async () => z26.toJSONSchema(deploymentSettingsSchema)).register("get", { inputSchema: z26.strictObject({}), scope: "admin", h: "\u8BFB\u53D6\u90E8\u7F72\u914D\u7F6E\u4E0E\u6267\u884C\u5668\u72B6\u6001", returns: "DeploymentStatus" }, async (_, { deps }) => deps.get()).register("status", { inputSchema: z26.strictObject({}), scope: "admin", h: "\u6838\u5BF9\u90E8\u7F72\u4EFB\u52A1\u4E0E\u5DF2\u5E94\u7528\u7248\u672C", returns: "DeploymentStatus" }, async (_, { deps }) => deps.get()).register("update", { inputSchema: deploymentUpdateSchema, scope: "admin", h: "\u4FDD\u5B58\u914D\u7F6E\u5E76\u521B\u5EFA\u767D\u540D\u5355\u90E8\u7F72\u4EFB\u52A1", returns: "DeploymentStatus" }, async (input, { deps }) => deps.update(input)).register("claim", { inputSchema: deploymentClaimSchema, scope: "admin", h: "\u672C\u673A\u6267\u884C\u5668\u72EC\u5360\u9886\u53D6\u56FA\u5B9A\u90E8\u7F72\u4EFB\u52A1", returns: "{job:DeploymentClaim|null}" }, async (input, { deps }) => deps.claim(input)).register("complete", { inputSchema: deploymentCompleteSchema, scope: "admin", h: "\u63D0\u4EA4\u5B9E\u4F8B\u68C0\u67E5\u6216\u6062\u590D\u7ED3\u679C", returns: "DeploymentStatus" }, async (input, { deps }) => deps.complete(input));
|
|
3520
4226
|
var createDeploymentModule = (deps) => commands2.module(deps);
|
|
3521
4227
|
|
|
3522
4228
|
// ../core/src/builtin/maintenance.ts
|
|
3523
|
-
import { z as
|
|
4229
|
+
import { z as z28 } from "zod";
|
|
3524
4230
|
|
|
3525
4231
|
// ../core/src/maintenance.ts
|
|
3526
|
-
import { z as
|
|
3527
|
-
var revision =
|
|
3528
|
-
var databaseUrl =
|
|
3529
|
-
var databaseMigrationSchema =
|
|
4232
|
+
import { z as z27 } from "zod";
|
|
4233
|
+
var revision = z27.number().int().nonnegative();
|
|
4234
|
+
var databaseUrl = z27.string().min(1).max(8192);
|
|
4235
|
+
var databaseMigrationSchema = z27.strictObject({
|
|
3530
4236
|
expectedRevision: revision,
|
|
3531
|
-
expectedInstanceId:
|
|
4237
|
+
expectedInstanceId: z27.string().min(1),
|
|
3532
4238
|
databaseUrl
|
|
3533
4239
|
});
|
|
3534
|
-
var databaseCredentialRotationSchema =
|
|
4240
|
+
var databaseCredentialRotationSchema = z27.strictObject({
|
|
3535
4241
|
databaseAdminUrl: databaseUrl.optional(),
|
|
3536
4242
|
expectedRevision: revision,
|
|
3537
|
-
expectedInstanceId:
|
|
3538
|
-
password:
|
|
4243
|
+
expectedInstanceId: z27.string().min(1),
|
|
4244
|
+
password: z27.string().min(24).max(4096)
|
|
3539
4245
|
});
|
|
3540
|
-
var redisMaintenanceSchema =
|
|
4246
|
+
var redisMaintenanceSchema = z27.strictObject({
|
|
3541
4247
|
expectedRevision: revision,
|
|
3542
|
-
redisUrl:
|
|
4248
|
+
redisUrl: z27.string().min(1).max(8192).nullable()
|
|
3543
4249
|
});
|
|
3544
4250
|
|
|
3545
4251
|
// ../core/src/builtin/maintenance.ts
|
|
@@ -3549,7 +4255,7 @@ var commands3 = new BuiltinCommandRegistry(
|
|
|
3549
4255
|
).register(
|
|
3550
4256
|
"status",
|
|
3551
4257
|
{
|
|
3552
|
-
inputSchema:
|
|
4258
|
+
inputSchema: z28.strictObject({}),
|
|
3553
4259
|
scope: "admin",
|
|
3554
4260
|
h: "\u7EF4\u62A4\u9636\u6BB5\u53CA\u5DF2\u8131\u654F\u7684\u8FDE\u63A5\u72B6\u6001",
|
|
3555
4261
|
returns: "MaintenanceStatus"
|
|
@@ -3586,20 +4292,20 @@ var commands3 = new BuiltinCommandRegistry(
|
|
|
3586
4292
|
var createMaintenanceModule = (deps) => commands3.module(deps);
|
|
3587
4293
|
|
|
3588
4294
|
// ../core/src/builtin/management.ts
|
|
3589
|
-
import { z as
|
|
4295
|
+
import { z as z30 } from "zod";
|
|
3590
4296
|
|
|
3591
4297
|
// ../core/src/managedConfig.ts
|
|
3592
|
-
import { z as
|
|
4298
|
+
import { z as z29 } from "zod";
|
|
3593
4299
|
|
|
3594
4300
|
// ../core/src/runtimeConfig.ts
|
|
3595
4301
|
var DEFAULT_MAX_HOPS = 4;
|
|
3596
4302
|
|
|
3597
4303
|
// ../core/src/managedConfig.ts
|
|
3598
|
-
var positive =
|
|
4304
|
+
var positive = z29.number().int().positive().max(Number.MAX_SAFE_INTEGER);
|
|
3599
4305
|
var ttl = positive.max(604800);
|
|
3600
|
-
var runtimeConfigSchema =
|
|
3601
|
-
canonicalOrigin:
|
|
3602
|
-
remoteAllowlist:
|
|
4306
|
+
var runtimeConfigSchema = z29.strictObject({
|
|
4307
|
+
canonicalOrigin: z29.union([z29.literal(""), z29.url({ protocol: /^https?$/ })]).default("").describe("\u516C\u5F00\u8BBF\u95EE\u5730\u5740"),
|
|
4308
|
+
remoteAllowlist: z29.array(z29.string().min(1)).default([]).describe("\u5141\u8BB8\u8054\u90A6\u8FDE\u63A5\u7684\u4E3B\u673A"),
|
|
3603
4309
|
maxHops: positive.max(16).default(DEFAULT_MAX_HOPS).describe("\u8054\u90A6\u6700\u5927\u8DF3\u6570"),
|
|
3604
4310
|
deviceReclaimSec: positive.max(2147483).default(86400).describe("\u79BB\u7EBF\u8BBE\u5907\u56DE\u6536\u7B49\u5F85\uFF08\u79D2\uFF09"),
|
|
3605
4311
|
toolCacheTtlSec: positive.default(300).describe("\u5DE5\u5177\u7F13\u5B58\u6709\u6548\u671F\uFF08\u79D2\uFF09"),
|
|
@@ -3611,7 +4317,7 @@ var runtimeConfigSchema = z25.strictObject({
|
|
|
3611
4317
|
storeCallMaxBytes: positive.default(536870912).describe("\u5355\u6B21\u8C03\u7528\u7D2F\u8BA1\u4E0A\u4F20\u5927\u5C0F\uFF08\u5B57\u8282\uFF09"),
|
|
3612
4318
|
storeCallMaxObjectBytes: positive.max(1073741824).default(268435456).describe("\u8C03\u7528\u5185\u5355\u4E2A\u5BF9\u8C61\u6700\u5927\u5927\u5C0F\uFF08\u5B57\u8282\uFF09"),
|
|
3613
4319
|
storeCallMaxObjects: positive.default(4).describe("\u5355\u6B21\u8C03\u7528\u6700\u591A\u5BF9\u8C61\u6570"),
|
|
3614
|
-
storeCallAllowedContentTypes:
|
|
4320
|
+
storeCallAllowedContentTypes: z29.array(z29.string().min(1)).min(1).default(["*/*"]).describe("\u8C03\u7528\u4E0A\u4F20\u5141\u8BB8\u7684 MIME \u7C7B\u578B"),
|
|
3615
4321
|
storeUploadTtlSec: ttl.default(900).describe("\u4E0A\u4F20\u4F1A\u8BDD\u6709\u6548\u671F\uFF08\u79D2\uFF09"),
|
|
3616
4322
|
storeShareTtlSec: ttl.default(900).describe("\u5206\u4EAB\u6709\u6548\u671F\uFF08\u79D2\uFF09"),
|
|
3617
4323
|
storeReadTtlSec: ttl.default(900).describe("\u4E0B\u8F7D\u5F15\u7528\u6709\u6548\u671F\uFF08\u79D2\uFF09"),
|
|
@@ -3623,37 +4329,37 @@ var runtimeConfigSchema = z25.strictObject({
|
|
|
3623
4329
|
searchMinChildWorkMs: positive.default(200).describe("\u5B50\u641C\u7D22\u6700\u5C11\u5DE5\u4F5C\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09"),
|
|
3624
4330
|
searchReturnReserveMs: positive.default(100).describe("\u641C\u7D22\u8FD4\u56DE\u9884\u7559\u65F6\u95F4\uFF08\u6BEB\u79D2\uFF09"),
|
|
3625
4331
|
searchSessionTtlSec: positive.default(300).describe("\u641C\u7D22\u5FEB\u7167\u6709\u6548\u671F\uFF08\u79D2\uFF09"),
|
|
3626
|
-
shutdownDrainSec:
|
|
4332
|
+
shutdownDrainSec: z29.number().int().min(0).max(300).default(0).describe("\u5173\u505C\u6392\u7A7A\u7B49\u5F85\uFF08\u79D2\uFF09")
|
|
3627
4333
|
});
|
|
3628
|
-
var configUpdateSchema =
|
|
3629
|
-
expectedRevision:
|
|
4334
|
+
var configUpdateSchema = z29.strictObject({
|
|
4335
|
+
expectedRevision: z29.number().int().nonnegative(),
|
|
3630
4336
|
settings: runtimeConfigSchema
|
|
3631
4337
|
});
|
|
3632
|
-
var revisionSchema =
|
|
3633
|
-
var s3ConnectionSchema =
|
|
3634
|
-
endpoint:
|
|
3635
|
-
bucket:
|
|
3636
|
-
region:
|
|
3637
|
-
accessKeyId:
|
|
3638
|
-
secretAccessKey:
|
|
4338
|
+
var revisionSchema = z29.strictObject({ expectedRevision: z29.number().int().nonnegative() });
|
|
4339
|
+
var s3ConnectionSchema = z29.strictObject({
|
|
4340
|
+
endpoint: z29.url(),
|
|
4341
|
+
bucket: z29.string().min(1).max(255),
|
|
4342
|
+
region: z29.string().min(1).default("us-east-1"),
|
|
4343
|
+
accessKeyId: z29.string().min(1).max(4096),
|
|
4344
|
+
secretAccessKey: z29.string().min(1).max(4096)
|
|
3639
4345
|
});
|
|
3640
|
-
var storageWriteSchema =
|
|
3641
|
-
name:
|
|
4346
|
+
var storageWriteSchema = z29.strictObject({
|
|
4347
|
+
name: z29.string().min(1).max(120),
|
|
3642
4348
|
connection: s3ConnectionSchema
|
|
3643
4349
|
});
|
|
3644
|
-
var storageIdSchema =
|
|
4350
|
+
var storageIdSchema = z29.strictObject({ id: z29.string().min(1).max(128) });
|
|
3645
4351
|
var storageRevisionSchema = storageIdSchema.extend({
|
|
3646
|
-
expectedRevision:
|
|
4352
|
+
expectedRevision: z29.number().int().nonnegative()
|
|
3647
4353
|
});
|
|
3648
4354
|
var storageActivateSchema = storageRevisionSchema.extend({
|
|
3649
|
-
expectedActiveRevision:
|
|
4355
|
+
expectedActiveRevision: z29.number().int().nonnegative()
|
|
3650
4356
|
});
|
|
3651
4357
|
var storageRotateSchema = storageRevisionSchema.extend({
|
|
3652
|
-
accessKeyId:
|
|
3653
|
-
secretAccessKey:
|
|
4358
|
+
accessKeyId: z29.string().min(1),
|
|
4359
|
+
secretAccessKey: z29.string().min(1)
|
|
3654
4360
|
});
|
|
3655
|
-
var setupInputSchema =
|
|
3656
|
-
databaseUrl:
|
|
4361
|
+
var setupInputSchema = z29.strictObject({
|
|
4362
|
+
databaseUrl: z29.string().min(1).refine((value) => {
|
|
3657
4363
|
try {
|
|
3658
4364
|
return ["postgres:", "postgresql:"].includes(new URL(value).protocol);
|
|
3659
4365
|
} catch {
|
|
@@ -3661,47 +4367,47 @@ var setupInputSchema = z25.strictObject({
|
|
|
3661
4367
|
}
|
|
3662
4368
|
}, "\u9700\u8981 PostgreSQL \u8FDE\u63A5\u5730\u5740").optional(),
|
|
3663
4369
|
storage: s3ConnectionSchema.optional(),
|
|
3664
|
-
redisUrl:
|
|
4370
|
+
redisUrl: z29.string().optional(),
|
|
3665
4371
|
settings: runtimeConfigSchema.default(() => runtimeConfigSchema.parse({}))
|
|
3666
4372
|
});
|
|
3667
|
-
var setupStatusSchema =
|
|
3668
|
-
state:
|
|
3669
|
-
instanceId:
|
|
3670
|
-
pairingRequired:
|
|
4373
|
+
var setupStatusSchema = z29.object({
|
|
4374
|
+
state: z29.enum(["setup", "installing", "ready", "recovery"]),
|
|
4375
|
+
instanceId: z29.string().min(1),
|
|
4376
|
+
pairingRequired: z29.boolean()
|
|
3671
4377
|
});
|
|
3672
|
-
var setupDefaultsSchema =
|
|
3673
|
-
databaseConfigured:
|
|
3674
|
-
databaseHost:
|
|
3675
|
-
redisConfigured:
|
|
3676
|
-
storageConfigured:
|
|
3677
|
-
storage:
|
|
4378
|
+
var setupDefaultsSchema = z29.object({
|
|
4379
|
+
databaseConfigured: z29.boolean(),
|
|
4380
|
+
databaseHost: z29.string().optional(),
|
|
4381
|
+
redisConfigured: z29.boolean(),
|
|
4382
|
+
storageConfigured: z29.boolean(),
|
|
4383
|
+
storage: z29.object({ endpoint: z29.string(), bucket: z29.string(), region: z29.string() }).optional()
|
|
3678
4384
|
});
|
|
3679
|
-
var setupResultSchema =
|
|
3680
|
-
state:
|
|
3681
|
-
adminSk:
|
|
3682
|
-
baseUrl:
|
|
4385
|
+
var setupResultSchema = z29.object({
|
|
4386
|
+
state: z29.literal("ready"),
|
|
4387
|
+
adminSk: z29.string().min(1),
|
|
4388
|
+
baseUrl: z29.string()
|
|
3683
4389
|
});
|
|
3684
|
-
var backupKeyringSchema =
|
|
4390
|
+
var backupKeyringSchema = z29.strictObject({ activeKeyId: z29.string().min(1), keys: z29.record(z29.string(), z29.string()) });
|
|
3685
4391
|
var recoveryInputSchema = setupInputSchema.extend({
|
|
3686
|
-
backup:
|
|
3687
|
-
version:
|
|
3688
|
-
instanceId:
|
|
3689
|
-
exportedAt:
|
|
4392
|
+
backup: z29.strictObject({
|
|
4393
|
+
version: z29.literal(1),
|
|
4394
|
+
instanceId: z29.string().min(1),
|
|
4395
|
+
exportedAt: z29.string().min(1),
|
|
3690
4396
|
keyring: backupKeyringSchema,
|
|
3691
4397
|
storeTokenKeyring: backupKeyringSchema,
|
|
3692
|
-
oauthKey:
|
|
3693
|
-
signingRetireAfter:
|
|
4398
|
+
oauthKey: z29.string().min(1),
|
|
4399
|
+
signingRetireAfter: z29.record(z29.string(), z29.string()).optional()
|
|
3694
4400
|
}).optional()
|
|
3695
4401
|
});
|
|
3696
|
-
var recoveryResultSchema =
|
|
3697
|
-
state:
|
|
3698
|
-
baseUrl:
|
|
3699
|
-
adminSk:
|
|
4402
|
+
var recoveryResultSchema = z29.object({
|
|
4403
|
+
state: z29.literal("ready"),
|
|
4404
|
+
baseUrl: z29.string(),
|
|
4405
|
+
adminSk: z29.string().min(1).optional()
|
|
3700
4406
|
});
|
|
3701
4407
|
|
|
3702
4408
|
// ../core/src/builtin/management.ts
|
|
3703
|
-
var configCommands = new BuiltinCommandRegistry("config", "\u5B9E\u4F8B\u914D\u7F6E\u4E0E\u751F\u6548\u72B6\u6001\uFF08\u7BA1\u7406\u5458\uFF09").register("schema", { inputSchema:
|
|
3704
|
-
var storageCommands = new BuiltinCommandRegistry("storage", "\u5BF9\u8C61\u5B58\u50A8\u540E\u7AEF\u3001\u9A8C\u8BC1\u548C\u9ED8\u8BA4\u4E0A\u4F20\u76EE\u6807\uFF08\u7BA1\u7406\u5458\uFF09").register("list", { inputSchema:
|
|
4409
|
+
var configCommands = new BuiltinCommandRegistry("config", "\u5B9E\u4F8B\u914D\u7F6E\u4E0E\u751F\u6548\u72B6\u6001\uFF08\u7BA1\u7406\u5458\uFF09").register("schema", { inputSchema: z30.strictObject({}), scope: "admin", h: "\u914D\u7F6E\u76EE\u5F55\u3001\u5B57\u6BB5\u8BF4\u660E\u4E0E\u9ED8\u8BA4\u503C", returns: "JSON Schema" }, async () => z30.toJSONSchema(runtimeConfigSchema)).register("get", { inputSchema: z30.strictObject({}), scope: "admin", h: "\u8BFB\u53D6\u671F\u671B\u503C\u3001\u5B9E\u9645\u503C\u548C revision", returns: "ConfigStatus" }, async (_, { deps }) => deps.get()).register("status", { inputSchema: z30.strictObject({}), scope: "admin", h: "\u68C0\u67E5\u914D\u7F6E\u5E94\u7528\u72B6\u6001", returns: "ConfigStatus" }, async (_, { deps }) => deps.get()).register("validate", { inputSchema: runtimeConfigSchema, scope: "admin", h: "\u6821\u9A8C\u5B8C\u6574\u5019\u9009\u914D\u7F6E", returns: "RuntimeConfig" }, async (input) => input).register("update", { inputSchema: configUpdateSchema, scope: "admin", h: "\u6309 revision \u4FDD\u5B58\u914D\u7F6E\uFF1B\u5C1A\u672A\u5E94\u7528", returns: "ConfigStatus" }, async (input, { deps }) => deps.update(input)).register("apply", { inputSchema: revisionSchema, scope: "admin", h: "\u5E94\u7528\u6307\u5B9A revision \u5E76\u68C0\u67E5\u5B9E\u9645\u72B6\u6001", returns: "ConfigStatus" }, async (input, { deps }) => deps.apply(input));
|
|
4410
|
+
var storageCommands = new BuiltinCommandRegistry("storage", "\u5BF9\u8C61\u5B58\u50A8\u540E\u7AEF\u3001\u9A8C\u8BC1\u548C\u9ED8\u8BA4\u4E0A\u4F20\u76EE\u6807\uFF08\u7BA1\u7406\u5458\uFF09").register("list", { inputSchema: z30.strictObject({}), scope: "admin", h: "\u5217\u51FA\u9ED8\u8BA4\u4E0E\u5386\u53F2\u5B58\u50A8\u540E\u7AEF", returns: "Page<StorageBackendView>" }, async (_, { deps }) => deps.list()).register("get", { inputSchema: storageIdSchema, scope: "admin", h: "\u8BFB\u53D6\u540E\u7AEF\u72B6\u6001\uFF0C\u4E0D\u56DE\u663E\u51ED\u8BC1", returns: "StorageBackendView" }, async (input, { deps }) => deps.get(input)).register("write", { inputSchema: storageWriteSchema, scope: "admin", h: "\u521B\u5EFA\u672A\u542F\u7528\u7684\u540E\u7AEF\uFF0C\u51ED\u8BC1\u53EA\u5199\u5165\u52A0\u5BC6\u4FDD\u7BA1\u5E93", returns: "StorageBackendView" }, async (input, { deps }) => deps.write(input)).register("test", { inputSchema: storageRevisionSchema, scope: "admin", h: "\u9A8C\u8BC1\u5B9E\u9645\u8BFB\u5199\u548C\u6761\u4EF6\u5199\u80FD\u529B", returns: "StorageBackendView" }, async (input, { deps }) => deps.test(input)).register("activate", { inputSchema: storageActivateSchema, scope: "admin", h: "\u8BBE\u4E3A\u65B0\u4E0A\u4F20\u9ED8\u8BA4\u503C\uFF1B\u65E7\u5BF9\u8C61\u4FDD\u7559\u539F\u540E\u7AEF", returns: "StorageBackendView" }, async (input, { deps }) => deps.activate(input)).register("update", { inputSchema: storageRotateSchema, scope: "admin", h: "\u9A8C\u8BC1\u5E76\u8F6E\u6362\u51ED\u8BC1\uFF0C\u4F4D\u7F6E\u4E0D\u53D8", returns: "StorageBackendView" }, async (input, { deps }) => deps.update(input)).register("delete", { inputSchema: storageRevisionSchema, scope: "admin", h: "\u5220\u9664\u6CA1\u6709\u5BF9\u8C61\u6216 Context \u5F15\u7528\u7684\u975E\u9ED8\u8BA4\u540E\u7AEF", returns: "{ok:true}" }, async (input, { deps }) => deps.delete(input));
|
|
3705
4411
|
var createConfigModule = (deps) => configCommands.module(deps);
|
|
3706
4412
|
var createStorageModule = (deps) => storageCommands.module(deps);
|
|
3707
4413
|
|
|
@@ -3867,7 +4573,7 @@ async function createObjectContextUploadGrant(store, opts, input) {
|
|
|
3867
4573
|
expiresAt
|
|
3868
4574
|
};
|
|
3869
4575
|
}
|
|
3870
|
-
function
|
|
4576
|
+
function clampLimit5(limit) {
|
|
3871
4577
|
if (limit === void 0) return LIST_LIMIT_DEFAULT;
|
|
3872
4578
|
if (!Number.isInteger(limit) || limit < 1) {
|
|
3873
4579
|
throw new TBError("invalid_argument", `limit \u975E\u6CD5:${limit}`);
|
|
@@ -3941,7 +4647,7 @@ function createObjectContextProvider(store, opts) {
|
|
|
3941
4647
|
return {
|
|
3942
4648
|
async list(path, listOpts) {
|
|
3943
4649
|
rejectFilter(listOpts);
|
|
3944
|
-
const limit =
|
|
4650
|
+
const limit = clampLimit5(listOpts?.limit);
|
|
3945
4651
|
const rel = path === "" ? "" : `${normalizeEntryPath(path)}/`;
|
|
3946
4652
|
const full = keyPrefix + rel;
|
|
3947
4653
|
assertContextKeyAllowed(full.slice(0, -1), path, false);
|
|
@@ -4051,7 +4757,7 @@ function createObjectContextProvider(store, opts) {
|
|
|
4051
4757
|
throw new TBError("invalid_argument", "query \u4E0D\u80FD\u4E3A\u7A7A");
|
|
4052
4758
|
}
|
|
4053
4759
|
rejectFilter(searchOpts);
|
|
4054
|
-
const limit =
|
|
4760
|
+
const limit = clampLimit5(searchOpts?.limit);
|
|
4055
4761
|
const q = query.toLowerCase();
|
|
4056
4762
|
const after = searchOpts?.cursor;
|
|
4057
4763
|
const items = [];
|
|
@@ -4106,78 +4812,79 @@ function isContextExpired(createdAt, ttlSec, now) {
|
|
|
4106
4812
|
}
|
|
4107
4813
|
|
|
4108
4814
|
// ../core/src/device/frames.ts
|
|
4109
|
-
import { z as
|
|
4110
|
-
var deviceNodeCmdSchema =
|
|
4111
|
-
name:
|
|
4112
|
-
delivery:
|
|
4113
|
-
description:
|
|
4114
|
-
inputSchema:
|
|
4115
|
-
outputSchema:
|
|
4116
|
-
effect:
|
|
4117
|
-
confirm:
|
|
4815
|
+
import { z as z31 } from "zod";
|
|
4816
|
+
var deviceNodeCmdSchema = z31.object({
|
|
4817
|
+
name: z31.string().min(1),
|
|
4818
|
+
delivery: z31.enum(["realtime", "mailbox", "both"]).optional(),
|
|
4819
|
+
description: z31.string().optional(),
|
|
4820
|
+
inputSchema: z31.unknown().optional(),
|
|
4821
|
+
outputSchema: z31.unknown().optional(),
|
|
4822
|
+
effect: z31.string().optional(),
|
|
4823
|
+
confirm: z31.boolean().optional()
|
|
4118
4824
|
}).passthrough();
|
|
4119
|
-
var nodeInputSchema2 =
|
|
4120
|
-
path:
|
|
4121
|
-
kind:
|
|
4122
|
-
description:
|
|
4123
|
-
cmds:
|
|
4825
|
+
var nodeInputSchema2 = z31.object({
|
|
4826
|
+
path: z31.string().min(1),
|
|
4827
|
+
kind: z31.enum(NODE_KINDS),
|
|
4828
|
+
description: z31.string(),
|
|
4829
|
+
cmds: z31.array(deviceNodeCmdSchema).optional()
|
|
4124
4830
|
}).passthrough();
|
|
4125
|
-
var deviceExposeSchema =
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4831
|
+
var deviceExposeSchema = z31.object({
|
|
4832
|
+
environment: deviceEnvironmentSchema.optional(),
|
|
4833
|
+
shell: z31.object({
|
|
4834
|
+
description: z31.string().optional(),
|
|
4835
|
+
allow: z31.array(z31.string()).optional()
|
|
4129
4836
|
}).optional(),
|
|
4130
|
-
fs:
|
|
4131
|
-
roots:
|
|
4132
|
-
readOnly:
|
|
4837
|
+
fs: z31.object({
|
|
4838
|
+
roots: z31.array(z31.string().min(1)).min(1),
|
|
4839
|
+
readOnly: z31.boolean().optional()
|
|
4133
4840
|
}).optional(),
|
|
4134
|
-
nodes:
|
|
4841
|
+
nodes: z31.array(nodeInputSchema2).optional()
|
|
4135
4842
|
});
|
|
4136
|
-
var idSchema =
|
|
4137
|
-
var deviceCallContextSchema =
|
|
4138
|
-
caller:
|
|
4139
|
-
keyId:
|
|
4140
|
-
owner:
|
|
4141
|
-
displayName:
|
|
4843
|
+
var idSchema = z31.string().min(1);
|
|
4844
|
+
var deviceCallContextSchema = z31.object({
|
|
4845
|
+
caller: z31.object({
|
|
4846
|
+
keyId: z31.string().min(1),
|
|
4847
|
+
owner: z31.string().min(1),
|
|
4848
|
+
displayName: z31.string().optional()
|
|
4142
4849
|
}).passthrough(),
|
|
4143
|
-
traceId:
|
|
4144
|
-
createdAt:
|
|
4145
|
-
expiresAt:
|
|
4146
|
-
upload:
|
|
4147
|
-
token:
|
|
4148
|
-
expiresAt:
|
|
4149
|
-
maxBytes:
|
|
4150
|
-
maxObjects:
|
|
4850
|
+
traceId: z31.string().min(1),
|
|
4851
|
+
createdAt: z31.string().min(1),
|
|
4852
|
+
expiresAt: z31.string().min(1),
|
|
4853
|
+
upload: z31.object({
|
|
4854
|
+
token: z31.string().min(1),
|
|
4855
|
+
expiresAt: z31.iso.datetime({ offset: true }),
|
|
4856
|
+
maxBytes: z31.number().int().positive(),
|
|
4857
|
+
maxObjects: z31.number().int().positive()
|
|
4151
4858
|
}).strict().optional()
|
|
4152
4859
|
}).passthrough();
|
|
4153
4860
|
var schemaByType = {
|
|
4154
|
-
hello:
|
|
4155
|
-
type:
|
|
4156
|
-
deviceId:
|
|
4157
|
-
mountPath:
|
|
4861
|
+
hello: z31.object({
|
|
4862
|
+
type: z31.literal("hello"),
|
|
4863
|
+
deviceId: z31.string().min(1),
|
|
4864
|
+
mountPath: z31.string().min(1).optional(),
|
|
4158
4865
|
expose: deviceExposeSchema
|
|
4159
4866
|
}),
|
|
4160
|
-
ready:
|
|
4161
|
-
error:
|
|
4162
|
-
call:
|
|
4163
|
-
type:
|
|
4867
|
+
ready: z31.object({ type: z31.literal("ready"), mountPath: z31.string().min(1) }),
|
|
4868
|
+
error: z31.object({ type: z31.literal("error"), error: tbErrorBodySchema }),
|
|
4869
|
+
call: z31.object({
|
|
4870
|
+
type: z31.literal("call"),
|
|
4164
4871
|
id: idSchema,
|
|
4165
|
-
path:
|
|
4166
|
-
arguments:
|
|
4872
|
+
path: z31.string().min(1),
|
|
4873
|
+
arguments: z31.record(z31.string(), z31.unknown()),
|
|
4167
4874
|
context: deviceCallContextSchema.optional()
|
|
4168
4875
|
}),
|
|
4169
|
-
result:
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
type:
|
|
4876
|
+
result: z31.discriminatedUnion("ok", [
|
|
4877
|
+
z31.object({ type: z31.literal("result"), id: idSchema, ok: z31.literal(true), value: z31.unknown() }),
|
|
4878
|
+
z31.object({
|
|
4879
|
+
type: z31.literal("result"),
|
|
4173
4880
|
id: idSchema,
|
|
4174
|
-
ok:
|
|
4881
|
+
ok: z31.literal(false),
|
|
4175
4882
|
error: tbErrorBodySchema
|
|
4176
4883
|
})
|
|
4177
4884
|
]),
|
|
4178
|
-
ping:
|
|
4179
|
-
pong:
|
|
4180
|
-
cancel:
|
|
4885
|
+
ping: z31.object({ type: z31.literal("ping") }),
|
|
4886
|
+
pong: z31.object({ type: z31.literal("pong") }),
|
|
4887
|
+
cancel: z31.object({ type: z31.literal("cancel"), id: idSchema })
|
|
4181
4888
|
};
|
|
4182
4889
|
var PING_FRAME_JSON = '{"type":"ping"}';
|
|
4183
4890
|
var PONG_FRAME_JSON = '{"type":"pong"}';
|
|
@@ -4194,14 +4901,14 @@ function decodeDeviceFrame(text) {
|
|
|
4194
4901
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
4195
4902
|
throw invalidFrame("\u5FC5\u987B\u662F JSON \u5BF9\u8C61");
|
|
4196
4903
|
}
|
|
4197
|
-
const
|
|
4198
|
-
if (typeof
|
|
4199
|
-
throw invalidFrame(`\u672A\u77E5 type:${JSON.stringify(
|
|
4904
|
+
const type2 = raw.type;
|
|
4905
|
+
if (typeof type2 !== "string" || !(type2 in schemaByType)) {
|
|
4906
|
+
throw invalidFrame(`\u672A\u77E5 type:${JSON.stringify(type2)}`);
|
|
4200
4907
|
}
|
|
4201
|
-
const parsed = schemaByType[
|
|
4908
|
+
const parsed = schemaByType[type2].safeParse(raw);
|
|
4202
4909
|
if (!parsed.success) {
|
|
4203
4910
|
const issue = parsed.error.issues[0];
|
|
4204
|
-
throw invalidFrame(`${
|
|
4911
|
+
throw invalidFrame(`${type2} \u5E27\u5B57\u6BB5\u975E\u6CD5:${issue?.path.join(".") ?? ""} ${issue?.message ?? ""}`);
|
|
4205
4912
|
}
|
|
4206
4913
|
return parsed.data;
|
|
4207
4914
|
}
|
|
@@ -4264,7 +4971,11 @@ function deviceDirectoryHelpModel(node, children = []) {
|
|
|
4264
4971
|
description: `${node.description} (${node.presence.state})`
|
|
4265
4972
|
},
|
|
4266
4973
|
cmds: [],
|
|
4267
|
-
children
|
|
4974
|
+
children,
|
|
4975
|
+
...node.environment === void 0 || node.reportedAt === void 0 ? {} : {
|
|
4976
|
+
deviceContext: { environment: node.environment, reportedAt: node.reportedAt, presence: node.presence },
|
|
4977
|
+
hint: `Environment is the last hello report (${node.presence.state}); inspect authorized child ~help for commands, execution limits and session recovery rules.`
|
|
4978
|
+
}
|
|
4268
4979
|
};
|
|
4269
4980
|
}
|
|
4270
4981
|
|
|
@@ -4464,6 +5175,63 @@ var DeviceGatewaySession = class {
|
|
|
4464
5175
|
}
|
|
4465
5176
|
};
|
|
4466
5177
|
|
|
5178
|
+
// ../core/src/events.ts
|
|
5179
|
+
import { z as z33 } from "zod/v4";
|
|
5180
|
+
|
|
5181
|
+
// ../core/src/protocol/eventWire.ts
|
|
5182
|
+
import { z as z32 } from "zod/v4";
|
|
5183
|
+
var EVENT_MAX_WAIT_MS = 3e4;
|
|
5184
|
+
var EVENT_MAX_BYTES = 16384;
|
|
5185
|
+
var type = z32.string().min(1).max(128);
|
|
5186
|
+
var cursor = z32.string().min(1).max(2048);
|
|
5187
|
+
var schemaVersion = z32.number().int().min(1).max(2147483647);
|
|
5188
|
+
var subject = z32.string().min(1).max(512).optional();
|
|
5189
|
+
var eventPublishSchema = z32.strictObject({
|
|
5190
|
+
type,
|
|
5191
|
+
schemaVersion: schemaVersion.optional(),
|
|
5192
|
+
subject,
|
|
5193
|
+
data: z32.json(),
|
|
5194
|
+
idempotencyKey: z32.string().min(1).max(256).optional()
|
|
5195
|
+
});
|
|
5196
|
+
var eventReadSchema = z32.strictObject({
|
|
5197
|
+
after: cursor.optional(),
|
|
5198
|
+
type: type.optional(),
|
|
5199
|
+
limit: z32.number().int().min(1).max(100).optional(),
|
|
5200
|
+
waitMs: z32.number().int().min(0).max(EVENT_MAX_WAIT_MS).optional()
|
|
5201
|
+
});
|
|
5202
|
+
var eventReceiptSchema = z32.object({ id: z32.uuid(), cursor });
|
|
5203
|
+
var eventEnvelopeSchema = eventReceiptSchema.extend({
|
|
5204
|
+
type,
|
|
5205
|
+
schemaVersion,
|
|
5206
|
+
source: z32.string(),
|
|
5207
|
+
recordedAt: z32.iso.datetime(),
|
|
5208
|
+
subject,
|
|
5209
|
+
data: z32.json()
|
|
5210
|
+
});
|
|
5211
|
+
var eventReadResultSchema = z32.object({
|
|
5212
|
+
events: z32.array(eventEnvelopeSchema),
|
|
5213
|
+
nextCursor: cursor,
|
|
5214
|
+
timedOut: z32.boolean(),
|
|
5215
|
+
gap: z32.object({ reason: z32.enum(["retention", "generation"]), earliestCursor: cursor }).optional()
|
|
5216
|
+
});
|
|
5217
|
+
|
|
5218
|
+
// ../core/src/events.ts
|
|
5219
|
+
var eventCommands = new HtbpCommandRegistry().register("publish", {
|
|
5220
|
+
h: "Append an event. Idempotency keys retain their first receipt for 24 hours.",
|
|
5221
|
+
inputSchema: eventPublishSchema,
|
|
5222
|
+
outputSchema: z33.toJSONSchema(eventReceiptSchema),
|
|
5223
|
+
returns: "EventReceipt",
|
|
5224
|
+
scope: "write",
|
|
5225
|
+
effect: "write"
|
|
5226
|
+
}, (input, ctx) => ctx.publish(input)).register("read", {
|
|
5227
|
+
h: "Read after a cursor, or from the current tail when omitted. Stop on a retention or generation gap.",
|
|
5228
|
+
inputSchema: eventReadSchema,
|
|
5229
|
+
outputSchema: z33.toJSONSchema(eventReadResultSchema),
|
|
5230
|
+
returns: "EventReadResult",
|
|
5231
|
+
scope: "read",
|
|
5232
|
+
effect: "read"
|
|
5233
|
+
}, (input, ctx) => ctx.read(input));
|
|
5234
|
+
|
|
4467
5235
|
// ../core/src/feedback/store.ts
|
|
4468
5236
|
var FEEDBACK_TITLE_MAX = 80;
|
|
4469
5237
|
var FEEDBACK_DETAIL_MAX = 500;
|
|
@@ -4671,6 +5439,7 @@ function attrLines(key, value) {
|
|
|
4671
5439
|
function renderHelpDsl(model) {
|
|
4672
5440
|
const lines = [HTBP_HELP_HEADER];
|
|
4673
5441
|
lines.push(nodeLine(model.node.path, model.node.kind, model.node.description));
|
|
5442
|
+
if (model.deviceContext !== void 0) lines.push(`deviceContext ${JSON.stringify(model.deviceContext)}`);
|
|
4674
5443
|
if (model.hint !== void 0) lines.push(`hint ${collapseToOneLine(model.hint)}`);
|
|
4675
5444
|
if (model.note !== void 0) lines.push(`note "${collapseToOneLine(model.note)}"`);
|
|
4676
5445
|
for (const cmd of model.cmds) {
|
|
@@ -4725,6 +5494,7 @@ function renderHelpJson(model) {
|
|
|
4725
5494
|
node: { path: model.node.path, kind: model.node.kind, description: model.node.description },
|
|
4726
5495
|
cmds
|
|
4727
5496
|
};
|
|
5497
|
+
if (model.deviceContext !== void 0) json.deviceContext = model.deviceContext;
|
|
4728
5498
|
if (model.hint !== void 0) json.hint = model.hint;
|
|
4729
5499
|
if (model.note !== void 0) json.note = model.note;
|
|
4730
5500
|
if (model.feedback !== void 0 && model.feedback.length > 0) {
|
|
@@ -4790,6 +5560,11 @@ function renderHelpMarkdown(model) {
|
|
|
4790
5560
|
if (model.node.description.trim() !== "") {
|
|
4791
5561
|
out.push(model.node.description.trim(), "");
|
|
4792
5562
|
}
|
|
5563
|
+
if (model.deviceContext !== void 0) {
|
|
5564
|
+
out.push("## Device context", "");
|
|
5565
|
+
out.push("Last reported environment (self-reported; presence does not refresh this snapshot):", "");
|
|
5566
|
+
out.push("```json", JSON.stringify(model.deviceContext, null, 2), "```", "");
|
|
5567
|
+
}
|
|
4793
5568
|
if (model.hint !== void 0) {
|
|
4794
5569
|
out.push(`> **Next step**: ${collapseToOneLine(model.hint)}`, "");
|
|
4795
5570
|
}
|
|
@@ -4949,9 +5724,9 @@ function reserveUploadQuota(input, capability) {
|
|
|
4949
5724
|
if (capability.status !== "active" || capability.reservations.length >= capability.maxObjects) {
|
|
4950
5725
|
throw new TBError("rate_limited", "call upload object \u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650");
|
|
4951
5726
|
}
|
|
4952
|
-
const
|
|
4953
|
-
if (!capability.allowedContentTypes.some((allowed) => allowed === "*/*" || allowed ===
|
|
4954
|
-
throw new TBError("permission_denied", `call \u4E0D\u5141\u8BB8\u4E0A\u4F20 ${
|
|
5727
|
+
const type2 = input.object.contentType;
|
|
5728
|
+
if (!capability.allowedContentTypes.some((allowed) => allowed === "*/*" || allowed === type2 || allowed.endsWith("/*") && type2.startsWith(allowed.slice(0, -1)))) {
|
|
5729
|
+
throw new TBError("permission_denied", `call \u4E0D\u5141\u8BB8\u4E0A\u4F20 ${type2}`);
|
|
4955
5730
|
}
|
|
4956
5731
|
const maxBytes = Math.min(
|
|
4957
5732
|
input.session.maxBytes,
|
|
@@ -4981,7 +5756,7 @@ function assertUploadBinding(existing, requested, now) {
|
|
|
4981
5756
|
}
|
|
4982
5757
|
|
|
4983
5758
|
// ../core/src/objectStoreService/service.ts
|
|
4984
|
-
import { z as
|
|
5759
|
+
import { z as z34 } from "zod/v4";
|
|
4985
5760
|
|
|
4986
5761
|
// ../core/src/objectStoreService/uri.ts
|
|
4987
5762
|
var STORE_OBJECT_ID_RE = /^[A-Za-z0-9_-]{22,64}$/;
|
|
@@ -5020,18 +5795,18 @@ var TOKEN_PREFIX = {
|
|
|
5020
5795
|
function stateCorrupt(kind) {
|
|
5021
5796
|
return new TBError("internal", `Store ${kind} \u72B6\u6001\u635F\u574F`, { retryable: false });
|
|
5022
5797
|
}
|
|
5023
|
-
var persistedId =
|
|
5024
|
-
var persistedOwner =
|
|
5025
|
-
var persistedTimestamp =
|
|
5026
|
-
var persistedNonNegativeInt =
|
|
5798
|
+
var persistedId = z34.string().min(1);
|
|
5799
|
+
var persistedOwner = z34.string().min(1).refine((value) => !/[\r\n\0]/.test(value));
|
|
5800
|
+
var persistedTimestamp = z34.string().refine((value) => Number.isFinite(Date.parse(value)));
|
|
5801
|
+
var persistedNonNegativeInt = z34.number().int().nonnegative().refine(Number.isSafeInteger);
|
|
5027
5802
|
var persistedPositiveInt = persistedNonNegativeInt.refine((value) => value > 0);
|
|
5028
|
-
var persistedHash =
|
|
5029
|
-
var persistedChecksum =
|
|
5030
|
-
algorithm:
|
|
5031
|
-
value:
|
|
5803
|
+
var persistedHash = z34.string().regex(/^[0-9a-f]{64}$/);
|
|
5804
|
+
var persistedChecksum = z34.looseObject({
|
|
5805
|
+
algorithm: z34.literal("sha256"),
|
|
5806
|
+
value: z34.string().min(1)
|
|
5032
5807
|
});
|
|
5033
5808
|
function stateParser(kind, shape) {
|
|
5034
|
-
const schema =
|
|
5809
|
+
const schema = z34.looseObject({ revision: persistedPositiveInt, ...shape });
|
|
5035
5810
|
return (value) => {
|
|
5036
5811
|
const parsed = schema.safeParse(value);
|
|
5037
5812
|
if (!parsed.success) throw stateCorrupt(kind);
|
|
@@ -5042,22 +5817,22 @@ var parseObject = stateParser("object", {
|
|
|
5042
5817
|
backendId: persistedId,
|
|
5043
5818
|
bytesDeletedAt: persistedTimestamp.optional(),
|
|
5044
5819
|
checksum: persistedChecksum.optional(),
|
|
5045
|
-
contentType:
|
|
5820
|
+
contentType: z34.string().min(1),
|
|
5046
5821
|
createdAt: persistedTimestamp,
|
|
5047
5822
|
driverKey: persistedId,
|
|
5048
|
-
etag:
|
|
5823
|
+
etag: z34.string().optional(),
|
|
5049
5824
|
expectedChecksum: persistedChecksum.optional(),
|
|
5050
5825
|
expectedSize: persistedNonNegativeInt.optional(),
|
|
5051
5826
|
expiresAt: persistedTimestamp.optional(),
|
|
5052
|
-
filename:
|
|
5827
|
+
filename: z34.string().optional(),
|
|
5053
5828
|
id: persistedId,
|
|
5054
5829
|
originCallId: persistedId.optional(),
|
|
5055
5830
|
owner: persistedOwner,
|
|
5056
5831
|
producer: persistedOwner.optional(),
|
|
5057
5832
|
readyAt: persistedTimestamp.optional(),
|
|
5058
5833
|
size: persistedNonNegativeInt.optional(),
|
|
5059
|
-
status:
|
|
5060
|
-
store:
|
|
5834
|
+
status: z34.enum(["pending", "ready", "failed", "abandoned", "deleted"]),
|
|
5835
|
+
store: z34.literal(DEFAULT_STORE_NAME),
|
|
5061
5836
|
updatedAt: persistedTimestamp,
|
|
5062
5837
|
uploadId: persistedId
|
|
5063
5838
|
});
|
|
@@ -5067,7 +5842,7 @@ var parseSessionRecord = stateParser("upload session", {
|
|
|
5067
5842
|
backendId: persistedId,
|
|
5068
5843
|
capabilityHash: persistedHash,
|
|
5069
5844
|
completedAt: persistedTimestamp.optional(),
|
|
5070
|
-
contentType:
|
|
5845
|
+
contentType: z34.string().min(1),
|
|
5071
5846
|
createdAt: persistedTimestamp,
|
|
5072
5847
|
expectedChecksum: persistedChecksum.optional(),
|
|
5073
5848
|
expectedSize: persistedNonNegativeInt.optional(),
|
|
@@ -5075,13 +5850,13 @@ var parseSessionRecord = stateParser("upload session", {
|
|
|
5075
5850
|
id: persistedId,
|
|
5076
5851
|
maxBytes: persistedPositiveInt,
|
|
5077
5852
|
objectId: persistedId,
|
|
5078
|
-
status:
|
|
5853
|
+
status: z34.enum(["created", "completed", "aborted", "expired", "failed"]),
|
|
5079
5854
|
terminalAt: persistedTimestamp.optional(),
|
|
5080
|
-
transport:
|
|
5855
|
+
transport: z34.enum(["relay", "presigned-put"])
|
|
5081
5856
|
});
|
|
5082
5857
|
var parseCallCapabilityRecord = stateParser("call capability", {
|
|
5083
5858
|
signingKeyId: persistedId,
|
|
5084
|
-
allowedContentTypes:
|
|
5859
|
+
allowedContentTypes: z34.array(z34.string().min(1)).min(1),
|
|
5085
5860
|
callId: persistedId,
|
|
5086
5861
|
createdAt: persistedTimestamp,
|
|
5087
5862
|
expiresAt: persistedTimestamp,
|
|
@@ -5091,12 +5866,12 @@ var parseCallCapabilityRecord = stateParser("call capability", {
|
|
|
5091
5866
|
maxObjects: persistedPositiveInt,
|
|
5092
5867
|
owner: persistedOwner,
|
|
5093
5868
|
producer: persistedOwner,
|
|
5094
|
-
reservations:
|
|
5869
|
+
reservations: z34.array(z34.looseObject({
|
|
5095
5870
|
maxBytes: persistedPositiveInt,
|
|
5096
5871
|
objectId: persistedId
|
|
5097
5872
|
})),
|
|
5098
5873
|
reservedBytes: persistedNonNegativeInt,
|
|
5099
|
-
status:
|
|
5874
|
+
status: z34.enum(["active", "exhausted", "revoked", "expired"]),
|
|
5100
5875
|
terminalAt: persistedTimestamp.optional(),
|
|
5101
5876
|
tokenHash: persistedHash
|
|
5102
5877
|
});
|
|
@@ -5107,13 +5882,13 @@ var parseShare = stateParser("share grant", {
|
|
|
5107
5882
|
expiresAt: persistedTimestamp,
|
|
5108
5883
|
id: persistedId,
|
|
5109
5884
|
objectId: persistedId,
|
|
5110
|
-
status:
|
|
5885
|
+
status: z34.enum(["active", "revoked", "expired"]),
|
|
5111
5886
|
terminalAt: persistedTimestamp.optional(),
|
|
5112
5887
|
tokenHash: persistedHash
|
|
5113
5888
|
});
|
|
5114
5889
|
var parseIdempotencyBinding = stateParser("idempotency binding", {
|
|
5115
5890
|
createdAt: persistedTimestamp,
|
|
5116
|
-
domain:
|
|
5891
|
+
domain: z34.enum(["owner", "call"]),
|
|
5117
5892
|
expiresAt: persistedTimestamp,
|
|
5118
5893
|
fingerprint: persistedHash,
|
|
5119
5894
|
objectId: persistedId,
|
|
@@ -5751,7 +6526,7 @@ var StoreService = class {
|
|
|
5751
6526
|
idempotencyBindings: idempotencyBindings.cursor ?? null,
|
|
5752
6527
|
objects: objectRecords.cursor ?? null
|
|
5753
6528
|
};
|
|
5754
|
-
return Object.values(cursors).some((
|
|
6529
|
+
return Object.values(cursors).some((cursor2) => cursor2 !== null) ? { ...result, cursors } : result;
|
|
5755
6530
|
}
|
|
5756
6531
|
async beginNormalized(input, identity) {
|
|
5757
6532
|
const now = this.nowIso();
|
|
@@ -6002,13 +6777,13 @@ var StoreService = class {
|
|
|
6002
6777
|
}
|
|
6003
6778
|
return body;
|
|
6004
6779
|
}
|
|
6005
|
-
const
|
|
6780
|
+
const source2 = body;
|
|
6006
6781
|
const bounded = {
|
|
6007
6782
|
async cancel(reason) {
|
|
6008
|
-
await
|
|
6783
|
+
await source2.cancel?.(reason);
|
|
6009
6784
|
},
|
|
6010
6785
|
getReader() {
|
|
6011
|
-
const reader =
|
|
6786
|
+
const reader = source2.getReader();
|
|
6012
6787
|
let consumed = 0;
|
|
6013
6788
|
return {
|
|
6014
6789
|
async read() {
|
|
@@ -6018,7 +6793,7 @@ var StoreService = class {
|
|
|
6018
6793
|
if (consumed > maxBytes) {
|
|
6019
6794
|
try {
|
|
6020
6795
|
if (reader.cancel !== void 0) await reader.cancel("Store upload size limit");
|
|
6021
|
-
else await
|
|
6796
|
+
else await source2.cancel?.("Store upload size limit");
|
|
6022
6797
|
} catch {
|
|
6023
6798
|
}
|
|
6024
6799
|
throw new TBError("rate_limited", `\u4E0A\u4F20\u5BF9\u8C61\u8D85\u8FC7 ${maxBytes} bytes`);
|
|
@@ -6031,7 +6806,7 @@ var StoreService = class {
|
|
|
6031
6806
|
},
|
|
6032
6807
|
async cancel(reason) {
|
|
6033
6808
|
if (reader.cancel !== void 0) await reader.cancel(reason);
|
|
6034
|
-
else await
|
|
6809
|
+
else await source2.cancel?.(reason);
|
|
6035
6810
|
}
|
|
6036
6811
|
};
|
|
6037
6812
|
}
|
|
@@ -6173,97 +6948,25 @@ var StoreService = class {
|
|
|
6173
6948
|
}
|
|
6174
6949
|
};
|
|
6175
6950
|
|
|
6176
|
-
// ../core/src/plugin/catalog.ts
|
|
6177
|
-
function canonicalCatalogJson(value) {
|
|
6178
|
-
const normalize = (input) => {
|
|
6179
|
-
if (Array.isArray(input)) return input.map(normalize);
|
|
6180
|
-
if (input === null || typeof input !== "object") return input;
|
|
6181
|
-
const source = input;
|
|
6182
|
-
const out = {};
|
|
6183
|
-
for (const key of Object.keys(source).sort()) {
|
|
6184
|
-
if (source[key] !== void 0) out[key] = normalize(source[key]);
|
|
6185
|
-
}
|
|
6186
|
-
return out;
|
|
6187
|
-
};
|
|
6188
|
-
return JSON.stringify(normalize(value));
|
|
6189
|
-
}
|
|
6190
|
-
async function catalogDigest(value) {
|
|
6191
|
-
const bytes2 = new TextEncoder().encode(canonicalCatalogJson(value));
|
|
6192
|
-
const hash = await crypto.subtle.digest("SHA-256", bytes2);
|
|
6193
|
-
return [...new Uint8Array(hash)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
6194
|
-
}
|
|
6195
|
-
async function catalogSetDigest(catalog) {
|
|
6196
|
-
const pairs = Object.keys(catalog).sort().map((id) => ({ id, digest: catalog[id].digest }));
|
|
6197
|
-
return await catalogDigest(pairs);
|
|
6198
|
-
}
|
|
6199
|
-
function builtinManifestOf(id) {
|
|
6200
|
-
return {
|
|
6201
|
-
id,
|
|
6202
|
-
protocolVersion: "plugin/v2",
|
|
6203
|
-
endpoint: `binding:${id}`,
|
|
6204
|
-
auth: { kind: "platform-token" },
|
|
6205
|
-
healthPath: "/healthz",
|
|
6206
|
-
enabled: true
|
|
6207
|
-
};
|
|
6208
|
-
}
|
|
6209
|
-
function resolveBuiltinExport(catalog, id, nodeKind, what, exportId) {
|
|
6210
|
-
const entry = catalog[id];
|
|
6211
|
-
if (entry === void 0) {
|
|
6212
|
-
throw new TBError("invalid_argument", `\u672A\u77E5 ${what} provider:'${id}'`);
|
|
6213
|
-
}
|
|
6214
|
-
const chosen = resolvePluginExport(entry.describe, {
|
|
6215
|
-
nodeKind,
|
|
6216
|
-
pluginId: id,
|
|
6217
|
-
...exportId !== void 0 ? { exportId } : {}
|
|
6218
|
-
});
|
|
6219
|
-
return { manifest: builtinManifestOf(id), export: chosen, source: "builtin" };
|
|
6220
|
-
}
|
|
6221
|
-
async function resolveExternalExport(store, id, nodeKind, what, exportId) {
|
|
6222
|
-
const manifest = await store.get(KEY_PLUGIN + id);
|
|
6223
|
-
if (manifest === null) {
|
|
6224
|
-
throw new TBError("invalid_argument", `\u672A\u77E5 ${what} provider:'${id}'`);
|
|
6225
|
-
}
|
|
6226
|
-
if (manifest.enabled !== true) {
|
|
6227
|
-
throw new TBError("invalid_argument", `plugin '${id}' \u5DF2\u7981\u7528`);
|
|
6228
|
-
}
|
|
6229
|
-
const describe = await store.get(KEY_PLUGIN_META + id);
|
|
6230
|
-
if (describe === null) {
|
|
6231
|
-
throw new TBError("invalid_argument", `plugin '${id}' \u7F3A\u5C11 ~describe \u7F13\u5B58,\u8BF7\u91CD\u65B0\u6CE8\u518C`);
|
|
6232
|
-
}
|
|
6233
|
-
const chosen = resolvePluginExport(describe, {
|
|
6234
|
-
nodeKind,
|
|
6235
|
-
pluginId: id,
|
|
6236
|
-
...exportId !== void 0 ? { exportId } : {}
|
|
6237
|
-
});
|
|
6238
|
-
return { manifest, export: chosen, source: "external" };
|
|
6239
|
-
}
|
|
6240
|
-
async function resolveIntegration(store, catalog, id, nodeKind, what, exportId) {
|
|
6241
|
-
const manifest = await store.get(KEY_PLUGIN + id);
|
|
6242
|
-
if (manifest !== null) {
|
|
6243
|
-
return await resolveExternalExport(store, id, nodeKind, what, exportId);
|
|
6244
|
-
}
|
|
6245
|
-
return resolveBuiltinExport(catalog, id, nodeKind, what, exportId);
|
|
6246
|
-
}
|
|
6247
|
-
|
|
6248
6951
|
// ../core/src/plugin/credential.ts
|
|
6249
|
-
function parseCredentialValues(raw,
|
|
6952
|
+
function parseCredentialValues(raw, fields2) {
|
|
6250
6953
|
let parsed;
|
|
6251
6954
|
try {
|
|
6252
6955
|
parsed = JSON.parse(raw);
|
|
6253
6956
|
} catch {
|
|
6254
6957
|
throw new TBError(
|
|
6255
6958
|
"invalid_argument",
|
|
6256
|
-
`\u8BE5 plugin \u9700\u8981\u591A\u5B57\u6BB5\u51ED\u8BC1(${
|
|
6959
|
+
`\u8BE5 plugin \u9700\u8981\u591A\u5B57\u6BB5\u51ED\u8BC1(${fields2.map((f) => f.key).join("\u3001")}),\u4F46 secret \u5B58\u7684\u4E0D\u662F JSON \u5BF9\u8C61\u3002\u7528 \`tb secret set <name> --field k=v\` \u5199\u5165`
|
|
6257
6960
|
);
|
|
6258
6961
|
}
|
|
6259
6962
|
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
6260
6963
|
throw new TBError("invalid_argument", "\u591A\u5B57\u6BB5\u51ED\u8BC1\u7684 secret \u5FC5\u987B\u662F\u4E00\u4E2A JSON \u5BF9\u8C61");
|
|
6261
6964
|
}
|
|
6262
|
-
const
|
|
6965
|
+
const source2 = parsed;
|
|
6263
6966
|
const values = {};
|
|
6264
6967
|
const missing = [];
|
|
6265
|
-
for (const field of
|
|
6266
|
-
const value =
|
|
6968
|
+
for (const field of fields2) {
|
|
6969
|
+
const value = source2[field.key];
|
|
6267
6970
|
if (typeof value === "string" && value !== "") {
|
|
6268
6971
|
values[field.key] = value;
|
|
6269
6972
|
continue;
|
|
@@ -6320,24 +7023,24 @@ var RequestDedupe = class {
|
|
|
6320
7023
|
};
|
|
6321
7024
|
|
|
6322
7025
|
// ../core/src/plugin/envelope.ts
|
|
6323
|
-
import { z as
|
|
7026
|
+
import { z as z35 } from "zod";
|
|
6324
7027
|
var HEADER_TB_CONTEXT = "X-TB-Context";
|
|
6325
7028
|
var HEADER_TB_REQUEST_ID = "X-TB-Request-Id";
|
|
6326
7029
|
var HEADER_TB_UPSTREAM_AUTH = "X-TB-Upstream-Auth";
|
|
6327
7030
|
var PLUGIN_PAYLOAD_MAX_BYTES = 1024 * 1024;
|
|
6328
|
-
var callContextSchema =
|
|
6329
|
-
keyId:
|
|
6330
|
-
owner:
|
|
6331
|
-
scopes:
|
|
6332
|
-
|
|
6333
|
-
pattern:
|
|
6334
|
-
actions:
|
|
6335
|
-
effect:
|
|
7031
|
+
var callContextSchema = z35.object({
|
|
7032
|
+
keyId: z35.string().min(1),
|
|
7033
|
+
owner: z35.string().min(1),
|
|
7034
|
+
scopes: z35.array(
|
|
7035
|
+
z35.object({
|
|
7036
|
+
pattern: z35.string().min(1),
|
|
7037
|
+
actions: z35.array(z35.enum(ACTIONS)),
|
|
7038
|
+
effect: z35.enum(["allow", "deny"]).optional()
|
|
6336
7039
|
})
|
|
6337
7040
|
),
|
|
6338
|
-
registerPaths:
|
|
6339
|
-
traceId:
|
|
6340
|
-
mountPath:
|
|
7041
|
+
registerPaths: z35.array(z35.string()).optional(),
|
|
7042
|
+
traceId: z35.string().min(1),
|
|
7043
|
+
mountPath: z35.string().min(1).optional(),
|
|
6341
7044
|
/**
|
|
6342
7045
|
* 挂载节点的 `providerConfig`。**只发给该节点对应的那个 plugin**(随本次调用的信封),
|
|
6343
7046
|
* 插件之间不共享 —— 同一 plugin 部署的不同挂载各自收到自己那份。
|
|
@@ -6349,9 +7052,9 @@ var callContextSchema = z29.object({
|
|
|
6349
7052
|
*
|
|
6350
7053
|
* 放这里的应当是:region / baseUrl override / 功能开关 / workspace 归属之类的**非敏感**配置。
|
|
6351
7054
|
*/
|
|
6352
|
-
mountConfig:
|
|
7055
|
+
mountConfig: z35.record(z35.string(), z35.unknown()).optional(),
|
|
6353
7056
|
/** v2 多 export 路由:本次调用命中 plugin 的哪个 export。 */
|
|
6354
|
-
exportId:
|
|
7057
|
+
exportId: z35.string().min(1).optional()
|
|
6355
7058
|
});
|
|
6356
7059
|
function encodeCallContext(ctx) {
|
|
6357
7060
|
return base64urlEncode(new TextEncoder().encode(JSON.stringify(ctx)));
|
|
@@ -6379,9 +7082,9 @@ function decodeCallContext(header) {
|
|
|
6379
7082
|
}
|
|
6380
7083
|
return parsed.data;
|
|
6381
7084
|
}
|
|
6382
|
-
var pluginCallSchema =
|
|
6383
|
-
tool:
|
|
6384
|
-
arguments:
|
|
7085
|
+
var pluginCallSchema = z35.object({
|
|
7086
|
+
tool: z35.string().min(1),
|
|
7087
|
+
arguments: z35.record(z35.string(), z35.unknown())
|
|
6385
7088
|
});
|
|
6386
7089
|
function assertPluginPayloadSize(payload) {
|
|
6387
7090
|
const bytes2 = new TextEncoder().encode(payload).length;
|
|
@@ -6819,11 +7522,11 @@ async function encodeToolSearchCursor(query, mode, revision2, offset, secret, op
|
|
|
6819
7522
|
toolSearchOptionsFingerprint(opts)
|
|
6820
7523
|
);
|
|
6821
7524
|
}
|
|
6822
|
-
async function decodeToolSearchCursor(
|
|
6823
|
-
if (
|
|
7525
|
+
async function decodeToolSearchCursor(cursor2, query, mode, revision2, secret, opts) {
|
|
7526
|
+
if (cursor2 === void 0) return 0;
|
|
6824
7527
|
let value;
|
|
6825
7528
|
try {
|
|
6826
|
-
const sealed = cursorBase64UrlDecode(
|
|
7529
|
+
const sealed = cursorBase64UrlDecode(cursor2);
|
|
6827
7530
|
if (sealed.length <= 12) throw new Error("truncated cursor");
|
|
6828
7531
|
const plaintext = await crypto.subtle.decrypt(
|
|
6829
7532
|
{ iv: sealed.slice(0, 12), name: "AES-GCM" },
|
|
@@ -7306,13 +8009,13 @@ var SecretStoreImpl = class {
|
|
|
7306
8009
|
*/
|
|
7307
8010
|
async list(opts) {
|
|
7308
8011
|
const limit = Math.min(opts?.limit ?? LIST_LIMIT_DEFAULT, LIST_LIMIT_MAX);
|
|
7309
|
-
const { items, cursor } = await this.store.list(KEY_SECRET, { cursor: opts?.cursor, limit });
|
|
8012
|
+
const { items, cursor: cursor2 } = await this.store.list(KEY_SECRET, { cursor: opts?.cursor, limit });
|
|
7310
8013
|
return {
|
|
7311
8014
|
items: items.map(({ key, value }) => ({
|
|
7312
8015
|
name: key.slice(KEY_SECRET.length),
|
|
7313
8016
|
updatedAt: isStoredSecret(value) ? value.updatedAt : ""
|
|
7314
8017
|
})),
|
|
7315
|
-
cursor
|
|
8018
|
+
cursor: cursor2
|
|
7316
8019
|
};
|
|
7317
8020
|
}
|
|
7318
8021
|
/** 删除 secret;不存在 → not_found。 */
|
|
@@ -7395,19 +8098,19 @@ function parseFrontmatter(text) {
|
|
|
7395
8098
|
}
|
|
7396
8099
|
|
|
7397
8100
|
// ../core/src/skillhub/commands.ts
|
|
7398
|
-
import { z as
|
|
7399
|
-
var publishFileSchema =
|
|
7400
|
-
path:
|
|
8101
|
+
import { z as z36 } from "zod/v4";
|
|
8102
|
+
var publishFileSchema = z36.strictObject({
|
|
8103
|
+
path: z36.string().describe(
|
|
7401
8104
|
"file path relative to the skill root, e.g. 'SKILL.md', 'scripts/run.sh'"
|
|
7402
8105
|
),
|
|
7403
|
-
content:
|
|
7404
|
-
contentType:
|
|
8106
|
+
content: z36.string().describe("UTF-8 text content"),
|
|
8107
|
+
contentType: z36.string().optional().describe("optional; inferred from extension when omitted")
|
|
7405
8108
|
});
|
|
7406
8109
|
var skillhubCommands = new HtbpCommandRegistry().register(
|
|
7407
8110
|
"list",
|
|
7408
8111
|
{
|
|
7409
8112
|
h: "list published skills (id / name / description from SKILL.md frontmatter, paginated)",
|
|
7410
|
-
inputSchema:
|
|
8113
|
+
inputSchema: z36.strictObject({ opts: HTBP_LIST_OPTIONS_SCHEMA.optional() }),
|
|
7411
8114
|
returns: "Page<SkillSummary>",
|
|
7412
8115
|
scope: "read"
|
|
7413
8116
|
},
|
|
@@ -7416,9 +8119,9 @@ var skillhubCommands = new HtbpCommandRegistry().register(
|
|
|
7416
8119
|
"get",
|
|
7417
8120
|
{
|
|
7418
8121
|
h: "read a skill: SKILL.md body + file manifest; pass 'file' to fetch one bundled file (oversized/binary as { $ref })",
|
|
7419
|
-
inputSchema:
|
|
7420
|
-
id:
|
|
7421
|
-
file:
|
|
8122
|
+
inputSchema: z36.strictObject({
|
|
8123
|
+
id: z36.string().describe("skill id"),
|
|
8124
|
+
file: z36.string().optional().describe(
|
|
7422
8125
|
"optional: path of one bundled file to fetch instead of the manifest"
|
|
7423
8126
|
)
|
|
7424
8127
|
}),
|
|
@@ -7430,8 +8133,8 @@ var skillhubCommands = new HtbpCommandRegistry().register(
|
|
|
7430
8133
|
"search",
|
|
7431
8134
|
{
|
|
7432
8135
|
h: "keyword search over skill id / name / description",
|
|
7433
|
-
inputSchema:
|
|
7434
|
-
query:
|
|
8136
|
+
inputSchema: z36.strictObject({
|
|
8137
|
+
query: z36.string().describe("substring to match"),
|
|
7435
8138
|
opts: HTBP_LIST_OPTIONS_SCHEMA.optional()
|
|
7436
8139
|
}),
|
|
7437
8140
|
returns: "Page<SkillSummary>",
|
|
@@ -7442,11 +8145,11 @@ var skillhubCommands = new HtbpCommandRegistry().register(
|
|
|
7442
8145
|
"publish",
|
|
7443
8146
|
{
|
|
7444
8147
|
h: "publish/replace a skill from a set of text files (must include SKILL.md with name+description frontmatter)",
|
|
7445
|
-
inputSchema:
|
|
7446
|
-
id:
|
|
8148
|
+
inputSchema: z36.strictObject({
|
|
8149
|
+
id: z36.string().optional().describe(
|
|
7447
8150
|
"skill id; defaults to a slug derived from the frontmatter name"
|
|
7448
8151
|
),
|
|
7449
|
-
files:
|
|
8152
|
+
files: z36.array(publishFileSchema).describe(
|
|
7450
8153
|
"the skill files; whole-skill replace (files not listed are removed)"
|
|
7451
8154
|
)
|
|
7452
8155
|
}),
|
|
@@ -7464,7 +8167,7 @@ var skillhubCommands = new HtbpCommandRegistry().register(
|
|
|
7464
8167
|
"remove",
|
|
7465
8168
|
{
|
|
7466
8169
|
h: "delete a skill and all its files (not_found if it does not exist)",
|
|
7467
|
-
inputSchema:
|
|
8170
|
+
inputSchema: z36.strictObject({ id: z36.string().describe("skill id") }),
|
|
7468
8171
|
scope: "write",
|
|
7469
8172
|
effect: "destructive"
|
|
7470
8173
|
},
|
|
@@ -7517,7 +8220,7 @@ function guessContentType(path) {
|
|
|
7517
8220
|
if (dot < 0) return "text/plain";
|
|
7518
8221
|
return CONTENT_TYPE_BY_EXT[path.slice(dot + 1).toLowerCase()] ?? "text/plain";
|
|
7519
8222
|
}
|
|
7520
|
-
function
|
|
8223
|
+
function clampLimit6(limit) {
|
|
7521
8224
|
if (limit === void 0) return LIST_LIMIT_DEFAULT;
|
|
7522
8225
|
if (!Number.isInteger(limit) || limit < 1) {
|
|
7523
8226
|
throw new TBError("invalid_argument", `limit \u975E\u6CD5:${limit}`);
|
|
@@ -7572,7 +8275,7 @@ function createSkillhubProvider(store, opts) {
|
|
|
7572
8275
|
};
|
|
7573
8276
|
return {
|
|
7574
8277
|
async list(listOpts) {
|
|
7575
|
-
const limit =
|
|
8278
|
+
const limit = clampLimit6(listOpts?.limit);
|
|
7576
8279
|
const res = await store.list(keyPrefix, {
|
|
7577
8280
|
delimiter: "/",
|
|
7578
8281
|
cursor: listOpts?.cursor,
|
|
@@ -7597,9 +8300,9 @@ function createSkillhubProvider(store, opts) {
|
|
|
7597
8300
|
const summary = summaryOf(id, text, meta);
|
|
7598
8301
|
const files = [];
|
|
7599
8302
|
const prefix = skillPrefix(id);
|
|
7600
|
-
let
|
|
8303
|
+
let cursor2;
|
|
7601
8304
|
do {
|
|
7602
|
-
const page = await store.list(prefix, { cursor, limit: LIST_LIMIT_MAX });
|
|
8305
|
+
const page = await store.list(prefix, { cursor: cursor2, limit: LIST_LIMIT_MAX });
|
|
7603
8306
|
for (const it of page.items) {
|
|
7604
8307
|
if ("prefix" in it) continue;
|
|
7605
8308
|
files.push({
|
|
@@ -7609,8 +8312,8 @@ function createSkillhubProvider(store, opts) {
|
|
|
7609
8312
|
version: it.etag
|
|
7610
8313
|
});
|
|
7611
8314
|
}
|
|
7612
|
-
|
|
7613
|
-
} while (
|
|
8315
|
+
cursor2 = page.cursor;
|
|
8316
|
+
} while (cursor2 !== void 0);
|
|
7614
8317
|
return { ...summary, content: text, files };
|
|
7615
8318
|
},
|
|
7616
8319
|
async get_file(idRaw, file) {
|
|
@@ -7632,7 +8335,7 @@ function createSkillhubProvider(store, opts) {
|
|
|
7632
8335
|
if (typeof query !== "string" || query === "") {
|
|
7633
8336
|
throw new TBError("invalid_argument", "query \u4E0D\u80FD\u4E3A\u7A7A");
|
|
7634
8337
|
}
|
|
7635
|
-
const limit =
|
|
8338
|
+
const limit = clampLimit6(searchOpts?.limit);
|
|
7636
8339
|
const q = query.toLowerCase();
|
|
7637
8340
|
const after = searchOpts?.cursor;
|
|
7638
8341
|
const items = [];
|
|
@@ -7708,544 +8411,235 @@ ${summary.description}`.toLowerCase();
|
|
|
7708
8411
|
const id = assertSkillId(input.id ?? slugify(fm.name));
|
|
7709
8412
|
const prefix = skillPrefix(id);
|
|
7710
8413
|
const keep = new Set(files.map((f) => `${prefix}${f.rel}`));
|
|
7711
|
-
let
|
|
8414
|
+
let cursor2;
|
|
7712
8415
|
do {
|
|
7713
|
-
const page = await store.list(prefix, { cursor, limit: LIST_LIMIT_MAX });
|
|
8416
|
+
const page = await store.list(prefix, { cursor: cursor2, limit: LIST_LIMIT_MAX });
|
|
7714
8417
|
for (const it of page.items) {
|
|
7715
8418
|
if ("prefix" in it) continue;
|
|
7716
8419
|
if (!keep.has(it.key)) await store.delete(it.key);
|
|
7717
|
-
}
|
|
7718
|
-
|
|
7719
|
-
} while (
|
|
7720
|
-
for (const f of files) {
|
|
7721
|
-
await store.put(`${prefix}${f.rel}`, f.content, {
|
|
7722
|
-
contentType: f.contentType || guessContentType(f.rel)
|
|
7723
|
-
});
|
|
7724
|
-
}
|
|
7725
|
-
return { id, name: fm.name, description: fm.description, fileCount: files.length };
|
|
7726
|
-
},
|
|
7727
|
-
async remove(idRaw) {
|
|
7728
|
-
assertWritable("remove");
|
|
7729
|
-
const id = assertSkillId(idRaw);
|
|
7730
|
-
const prefix = skillPrefix(id);
|
|
7731
|
-
let
|
|
7732
|
-
let removed = 0;
|
|
7733
|
-
do {
|
|
7734
|
-
const page = await store.list(prefix, { cursor, limit: LIST_LIMIT_MAX });
|
|
7735
|
-
for (const it of page.items) {
|
|
7736
|
-
if ("prefix" in it) continue;
|
|
7737
|
-
await store.delete(it.key);
|
|
7738
|
-
removed++;
|
|
7739
|
-
}
|
|
7740
|
-
|
|
7741
|
-
} while (
|
|
7742
|
-
if (removed === 0) throw TBError.notFound(`skill \u4E0D\u5B58\u5728:'${id}'`);
|
|
7743
|
-
}
|
|
7744
|
-
};
|
|
7745
|
-
}
|
|
7746
|
-
|
|
7747
|
-
// ../core/src/tool/httpTool.ts
|
|
7748
|
-
var PARAM_RE = /\{([^{}]+)\}/g;
|
|
7749
|
-
function buildQuery(params) {
|
|
7750
|
-
const parts = [];
|
|
7751
|
-
for (const [k, v] of Object.entries(params)) {
|
|
7752
|
-
if (v === void 0) continue;
|
|
7753
|
-
parts.push(`${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`);
|
|
7754
|
-
}
|
|
7755
|
-
return parts.join("&");
|
|
7756
|
-
}
|
|
7757
|
-
function buildHttpRequest(def, endpoint, args) {
|
|
7758
|
-
const consumed = /* @__PURE__ */ new Set();
|
|
7759
|
-
const path = def.pathTemplate.replace(PARAM_RE, (_match, name) => {
|
|
7760
|
-
const value = args[name];
|
|
7761
|
-
if (value === void 0) {
|
|
7762
|
-
throw new TBError(
|
|
7763
|
-
"invalid_argument",
|
|
7764
|
-
`\u7F3A\u5C11\u8DEF\u5F84\u53C2\u6570 '${name}'(pathTemplate '${def.pathTemplate}')`
|
|
7765
|
-
);
|
|
7766
|
-
}
|
|
7767
|
-
consumed.add(name);
|
|
7768
|
-
return encodeURIComponent(String(value));
|
|
7769
|
-
});
|
|
7770
|
-
const remaining = {};
|
|
7771
|
-
for (const [k, v] of Object.entries(args)) {
|
|
7772
|
-
if (!consumed.has(k)) remaining[k] = v;
|
|
7773
|
-
}
|
|
7774
|
-
const base = endpoint.replace(/\/+$/, "");
|
|
7775
|
-
const rel = path.startsWith("/") ? path : `/${path}`;
|
|
7776
|
-
let url = `${base}${rel}`;
|
|
7777
|
-
const headers = {};
|
|
7778
|
-
let body;
|
|
7779
|
-
if (def.method === "GET" || def.method === "DELETE") {
|
|
7780
|
-
const qs = buildQuery(remaining);
|
|
7781
|
-
if (qs) url += `?${qs}`;
|
|
7782
|
-
} else {
|
|
7783
|
-
body = JSON.stringify(remaining);
|
|
7784
|
-
headers["content-type"] = "application/json";
|
|
7785
|
-
}
|
|
7786
|
-
return { url, method: def.method, body, headers };
|
|
7787
|
-
}
|
|
7788
|
-
function effectFor(def) {
|
|
7789
|
-
if (def.effect !== void 0) return def.effect;
|
|
7790
|
-
return def.method === "GET" ? "read" : "write";
|
|
7791
|
-
}
|
|
7792
|
-
function authHeaderFor(config, secret) {
|
|
7793
|
-
const name = config.authHeader ?? "Authorization";
|
|
7794
|
-
const scheme = config.authScheme;
|
|
7795
|
-
const value = scheme === void 0 ? `Bearer ${secret}` : scheme === "" ? secret : `${scheme} ${secret}`;
|
|
7796
|
-
return [name, value];
|
|
7797
|
-
}
|
|
7798
|
-
|
|
7799
|
-
// ../core/src/tool/mcpSchema.ts
|
|
7800
|
-
function toolToCmd(nodePath, tool, index) {
|
|
7801
|
-
const cmd = {
|
|
7802
|
-
name: tool.name,
|
|
7803
|
-
method: "POST",
|
|
7804
|
-
path: `/${nodePath}/${tool.name}`,
|
|
7805
|
-
scope: "call"
|
|
7806
|
-
};
|
|
7807
|
-
if (tool.description !== void 0) {
|
|
7808
|
-
cmd.h = index ? summarizeOneLine(tool.description) : tool.description;
|
|
7809
|
-
}
|
|
7810
|
-
if (tool.delivery !== void 0) cmd.delivery = tool.delivery;
|
|
7811
|
-
if (!index && tool.inputSchema !== void 0) cmd.inputSchema = tool.inputSchema;
|
|
7812
|
-
if (!index && tool.outputSchema !== void 0) cmd.outputSchema = tool.outputSchema;
|
|
7813
|
-
if (tool.effect !== void 0) cmd.effect = tool.effect;
|
|
7814
|
-
const confirm = tool.confirm ?? (tool.effect === "destructive" ? true : void 0);
|
|
7815
|
-
if (confirm) cmd.confirm = confirm;
|
|
7816
|
-
return cmd;
|
|
7817
|
-
}
|
|
7818
|
-
function toolsToHelpModel(nodePath, node, tools, opts = {}) {
|
|
7819
|
-
const index = opts.index === true;
|
|
7820
|
-
const model = {
|
|
7821
|
-
node: { path: nodePath, kind: node.kind, description: node.description },
|
|
7822
|
-
cmds: tools.map((tool) => toolToCmd(nodePath, tool, index))
|
|
7823
|
-
};
|
|
7824
|
-
if (index) {
|
|
7825
|
-
model.index = true;
|
|
7826
|
-
model.hint = `this is an index (descriptions summarized, input schemas omitted); GET /${nodePath}/<tool>/~help returns one tool's full spec`;
|
|
7827
|
-
}
|
|
7828
|
-
return model;
|
|
7829
|
-
}
|
|
7830
|
-
function toolHelpModel(nodePath, node, tool) {
|
|
7831
|
-
return {
|
|
7832
|
-
node: {
|
|
7833
|
-
path: `${nodePath}/${tool.name}`,
|
|
7834
|
-
kind: node.kind,
|
|
7835
|
-
description: summarizeOneLine(tool.description ?? node.description)
|
|
7836
|
-
},
|
|
7837
|
-
cmds: [toolToCmd(nodePath, tool, false)]
|
|
7838
|
-
};
|
|
7839
|
-
}
|
|
7840
|
-
|
|
7841
|
-
// ../core/src/tool/remote.ts
|
|
7842
|
-
function rewriteRemotePath(nodePath, requestPath, baseUrl) {
|
|
7843
|
-
const base = baseUrl.replace(/\/+$/, "");
|
|
7844
|
-
const rawSegs = requestPath.replace(/^\/+|\/+$/g, "").split("/").filter((s) => s.length > 0);
|
|
7845
|
-
const reserved = rawSegs.length > 0 && rawSegs[rawSegs.length - 1]?.startsWith("~") ? rawSegs.pop() : void 0;
|
|
7846
|
-
const nodeSegs = segments(nodePath);
|
|
7847
|
-
const pathSegs = rawSegs;
|
|
7848
|
-
let relSegs;
|
|
7849
|
-
const isPrefix = nodeSegs.length <= pathSegs.length && nodeSegs.every((s, i) => s === pathSegs[i]);
|
|
7850
|
-
if (isPrefix) {
|
|
7851
|
-
relSegs = pathSegs.slice(nodeSegs.length);
|
|
7852
|
-
} else {
|
|
7853
|
-
relSegs = pathSegs;
|
|
7854
|
-
}
|
|
7855
|
-
const tail = reserved !== void 0 ? [...relSegs, reserved] : relSegs;
|
|
7856
|
-
const rel = tail.join("/");
|
|
7857
|
-
return rel === "" ? base : `${base}/${rel}`;
|
|
7858
|
-
}
|
|
7859
|
-
function hostOf(url) {
|
|
7860
|
-
const m = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/([^/?#\\]*)/.exec(url);
|
|
7861
|
-
if (m === null) return void 0;
|
|
7862
|
-
let authority = m[1] ?? "";
|
|
7863
|
-
const at = authority.lastIndexOf("@");
|
|
7864
|
-
if (at >= 0) authority = authority.slice(at + 1);
|
|
7865
|
-
if (authority.startsWith("[")) {
|
|
7866
|
-
const close = authority.indexOf("]");
|
|
7867
|
-
if (close >= 0) return authority.slice(0, close + 1).toLowerCase();
|
|
7868
|
-
}
|
|
7869
|
-
const colon = authority.indexOf(":");
|
|
7870
|
-
const host = colon >= 0 ? authority.slice(0, colon) : authority;
|
|
7871
|
-
return host.toLowerCase();
|
|
7872
|
-
}
|
|
7873
|
-
function checkAllowlist(baseUrl, allowlist) {
|
|
7874
|
-
if (allowlist.length === 0) return false;
|
|
7875
|
-
const host = hostOf(baseUrl);
|
|
7876
|
-
if (host === void 0 || host === "") return false;
|
|
7877
|
-
return allowlist.some((entry) => {
|
|
7878
|
-
const suffix = entry.trim().toLowerCase();
|
|
7879
|
-
if (suffix === "") return false;
|
|
7880
|
-
return host === suffix || host.endsWith(`.${suffix}`);
|
|
7881
|
-
});
|
|
8420
|
+
}
|
|
8421
|
+
cursor2 = page.cursor;
|
|
8422
|
+
} while (cursor2 !== void 0);
|
|
8423
|
+
for (const f of files) {
|
|
8424
|
+
await store.put(`${prefix}${f.rel}`, f.content, {
|
|
8425
|
+
contentType: f.contentType || guessContentType(f.rel)
|
|
8426
|
+
});
|
|
8427
|
+
}
|
|
8428
|
+
return { id, name: fm.name, description: fm.description, fileCount: files.length };
|
|
8429
|
+
},
|
|
8430
|
+
async remove(idRaw) {
|
|
8431
|
+
assertWritable("remove");
|
|
8432
|
+
const id = assertSkillId(idRaw);
|
|
8433
|
+
const prefix = skillPrefix(id);
|
|
8434
|
+
let cursor2;
|
|
8435
|
+
let removed = 0;
|
|
8436
|
+
do {
|
|
8437
|
+
const page = await store.list(prefix, { cursor: cursor2, limit: LIST_LIMIT_MAX });
|
|
8438
|
+
for (const it of page.items) {
|
|
8439
|
+
if ("prefix" in it) continue;
|
|
8440
|
+
await store.delete(it.key);
|
|
8441
|
+
removed++;
|
|
8442
|
+
}
|
|
8443
|
+
cursor2 = page.cursor;
|
|
8444
|
+
} while (cursor2 !== void 0);
|
|
8445
|
+
if (removed === 0) throw TBError.notFound(`skill \u4E0D\u5B58\u5728:'${id}'`);
|
|
8446
|
+
}
|
|
8447
|
+
};
|
|
7882
8448
|
}
|
|
7883
8449
|
|
|
7884
|
-
// ../core/src/tool/
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
return new TBError("unavailable", `\u68C0\u6D4B\u5230\u900F\u4F20\u73AF:'${selfId}' \u5DF2\u5728 X-TB-Via \u94FE\u4E2D`, {
|
|
7892
|
-
retryable: false
|
|
7893
|
-
});
|
|
7894
|
-
}
|
|
7895
|
-
if (chain.length >= maxHops) {
|
|
7896
|
-
return new TBError("unavailable", `\u900F\u4F20\u8DF3\u6570\u8D85\u9650:\u94FE\u957F ${chain.length} \u2265 maxHops ${maxHops}`, {
|
|
7897
|
-
retryable: false
|
|
7898
|
-
});
|
|
8450
|
+
// ../core/src/tool/httpTool.ts
|
|
8451
|
+
var PARAM_RE = /\{([^{}]+)\}/g;
|
|
8452
|
+
function buildQuery(params) {
|
|
8453
|
+
const parts = [];
|
|
8454
|
+
for (const [k, v] of Object.entries(params)) {
|
|
8455
|
+
if (v === void 0) continue;
|
|
8456
|
+
parts.push(`${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`);
|
|
7899
8457
|
}
|
|
7900
|
-
return
|
|
7901
|
-
}
|
|
7902
|
-
function appendVia(chain, selfId) {
|
|
7903
|
-
return [...chain, selfId].join(", ");
|
|
7904
|
-
}
|
|
7905
|
-
|
|
7906
|
-
// ../core/src/tool/virtualize.ts
|
|
7907
|
-
function virtualName(v, upstreamName) {
|
|
7908
|
-
const renamed = v.rename?.[upstreamName] ?? upstreamName;
|
|
7909
|
-
return v.prefix !== void 0 ? `${v.prefix}${renamed}` : renamed;
|
|
8458
|
+
return parts.join("&");
|
|
7910
8459
|
}
|
|
7911
|
-
function
|
|
7912
|
-
const
|
|
7913
|
-
const
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
if (hidden.has(tool.name)) continue;
|
|
7917
|
-
const projectedName = v ? virtualName(v, tool.name) : tool.name;
|
|
7918
|
-
const name = canonicalizeSegment(projectedName);
|
|
7919
|
-
const previous = reverse.get(name);
|
|
7920
|
-
if (previous !== void 0) {
|
|
8460
|
+
function buildHttpRequest(def, endpoint, args) {
|
|
8461
|
+
const consumed = /* @__PURE__ */ new Set();
|
|
8462
|
+
const path = def.pathTemplate.replace(PARAM_RE, (_match, name) => {
|
|
8463
|
+
const value = args[name];
|
|
8464
|
+
if (value === void 0) {
|
|
7921
8465
|
throw new TBError(
|
|
7922
8466
|
"invalid_argument",
|
|
7923
|
-
`\
|
|
8467
|
+
`\u7F3A\u5C11\u8DEF\u5F84\u53C2\u6570 '${name}'(pathTemplate '${def.pathTemplate}')`
|
|
7924
8468
|
);
|
|
7925
8469
|
}
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
8470
|
+
consumed.add(name);
|
|
8471
|
+
return encodeURIComponent(String(value));
|
|
8472
|
+
});
|
|
8473
|
+
const remaining = {};
|
|
8474
|
+
for (const [k, v] of Object.entries(args)) {
|
|
8475
|
+
if (!consumed.has(k)) remaining[k] = v;
|
|
7929
8476
|
}
|
|
7930
|
-
|
|
7931
|
-
}
|
|
7932
|
-
|
|
7933
|
-
const
|
|
7934
|
-
|
|
7935
|
-
if (
|
|
7936
|
-
|
|
8477
|
+
const base = endpoint.replace(/\/+$/, "");
|
|
8478
|
+
const rel = path.startsWith("/") ? path : `/${path}`;
|
|
8479
|
+
let url = `${base}${rel}`;
|
|
8480
|
+
const headers = {};
|
|
8481
|
+
let body;
|
|
8482
|
+
if (def.method === "GET" || def.method === "DELETE") {
|
|
8483
|
+
const qs = buildQuery(remaining);
|
|
8484
|
+
if (qs) url += `?${qs}`;
|
|
8485
|
+
} else {
|
|
8486
|
+
body = JSON.stringify(remaining);
|
|
8487
|
+
headers["content-type"] = "application/json";
|
|
7937
8488
|
}
|
|
7938
|
-
return
|
|
7939
|
-
}
|
|
7940
|
-
|
|
7941
|
-
// ../core/src/tree/registry.ts
|
|
7942
|
-
function clampLimit6(limit) {
|
|
7943
|
-
if (limit === void 0 || limit < 1) return LIST_LIMIT_DEFAULT;
|
|
7944
|
-
return limit > LIST_LIMIT_MAX ? LIST_LIMIT_MAX : limit;
|
|
8489
|
+
return { url, method: def.method, body, headers };
|
|
7945
8490
|
}
|
|
7946
|
-
function
|
|
7947
|
-
if (
|
|
7948
|
-
|
|
7949
|
-
throw new TBError(
|
|
7950
|
-
"invalid_argument",
|
|
7951
|
-
`kind='${node.kind}' \u4E0E config.kind='${node.config.kind}' \u4E0D\u4E00\u81F4`
|
|
7952
|
-
);
|
|
7953
|
-
}
|
|
8491
|
+
function effectFor(def) {
|
|
8492
|
+
if (def.effect !== void 0) return def.effect;
|
|
8493
|
+
return def.method === "GET" ? "read" : "write";
|
|
7954
8494
|
}
|
|
7955
|
-
function
|
|
7956
|
-
|
|
8495
|
+
function authHeaderFor(config, secret) {
|
|
8496
|
+
const name = config.authHeader ?? "Authorization";
|
|
8497
|
+
const scheme = config.authScheme;
|
|
8498
|
+
const value = scheme === void 0 ? `Bearer ${secret}` : scheme === "" ? secret : `${scheme} ${secret}`;
|
|
8499
|
+
return [name, value];
|
|
7957
8500
|
}
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
|
|
7962
|
-
|
|
7963
|
-
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
/** 翻页取尽 node:* 全量。 */
|
|
7970
|
-
async scanAll() {
|
|
7971
|
-
return this.scanPrefix(KEY_NODE);
|
|
7972
|
-
}
|
|
7973
|
-
/**
|
|
7974
|
-
* 翻页扫描给定 KV 键前缀下的所有 TreeNode。
|
|
7975
|
-
*
|
|
7976
|
-
* 只扫子树(前缀限定),不再对全树做内存过滤——避免 children/hasChildren/subtree 的
|
|
7977
|
-
* O(N²)(每层各扫全树)。`opts.limit` 传给底层 `store.list` 以小步取(hasChildren 短路用)。
|
|
7978
|
-
*
|
|
7979
|
-
* **Workers 查询预算约束**:D1StateStore.list 是单条 SQL 直接带值返回(ADR-001 迁 D1 后
|
|
7980
|
-
* 不再逐键 get),每页只花一次 D1 查询;但 Workers 单请求仍有查询/子请求预算,深翻页的
|
|
7981
|
-
* 页数应远小于预算——当前树规模小(节点数十级)可接受。
|
|
7982
|
-
*/
|
|
7983
|
-
async scanPrefix(keyPrefix, opts) {
|
|
7984
|
-
const out = [];
|
|
7985
|
-
let cursor;
|
|
7986
|
-
do {
|
|
7987
|
-
const limit = opts?.maxNodes === void 0 ? opts?.limit ?? LIST_LIMIT_MAX : Math.min(
|
|
7988
|
-
opts.limit ?? LIST_LIMIT_MAX,
|
|
7989
|
-
opts.maxNodes - out.length + (opts.truncate === true ? 0 : 1)
|
|
7990
|
-
);
|
|
7991
|
-
if (limit < 1) return out;
|
|
7992
|
-
const page = await this.store.list(keyPrefix, {
|
|
7993
|
-
limit,
|
|
7994
|
-
...cursor !== void 0 ? { cursor } : {}
|
|
7995
|
-
});
|
|
7996
|
-
for (const { value } of page.items) out.push(value);
|
|
7997
|
-
if (opts?.truncate === true && out.length >= (opts.maxNodes ?? Number.POSITIVE_INFINITY)) {
|
|
7998
|
-
return out;
|
|
7999
|
-
}
|
|
8000
|
-
if (opts?.maxNodes !== void 0 && out.length > opts.maxNodes) {
|
|
8001
|
-
throw new TBError(
|
|
8002
|
-
"rate_limited",
|
|
8003
|
-
`registry scan \u6700\u591A\u8BFB\u53D6 ${opts.maxNodes} \u4E2A\u8282\u70B9`
|
|
8004
|
-
);
|
|
8005
|
-
}
|
|
8006
|
-
cursor = page.cursor;
|
|
8007
|
-
} while (cursor);
|
|
8008
|
-
return out;
|
|
8009
|
-
}
|
|
8010
|
-
/** KV 前缀:某路径的子树(含中间 directory)= `node:<path>/`;根('')= `node:`。 */
|
|
8011
|
-
subtreePrefix(norm) {
|
|
8012
|
-
return norm === "" ? KEY_NODE : `${KEY_NODE}${norm}/`;
|
|
8013
|
-
}
|
|
8014
|
-
async hasChildren(path) {
|
|
8015
|
-
const norm = normalizePath(path);
|
|
8016
|
-
const page = await this.store.list(this.subtreePrefix(norm), { limit: 1 });
|
|
8017
|
-
return page.items.length > 0;
|
|
8018
|
-
}
|
|
8019
|
-
/** 取单个;不存在 → not_found。路径大小写不敏感(规范化为小写后查)。 */
|
|
8020
|
-
async get(path) {
|
|
8021
|
-
const norm = canonicalizePath(path);
|
|
8022
|
-
const node = await this.read(norm);
|
|
8023
|
-
if (!node) throw new TBError("not_found", `\u8282\u70B9\u4E0D\u5B58\u5728:'${norm}'`);
|
|
8024
|
-
return node;
|
|
8025
|
-
}
|
|
8026
|
-
/** 批量取节点;路径先规范化(小写)去重,不存在的节点不进入返回 Map。 */
|
|
8027
|
-
async getMany(paths) {
|
|
8028
|
-
const canonical = [...new Set(paths.map((path) => canonicalizePath(path)))];
|
|
8029
|
-
const values = await this.store.getMany(canonical.map((path) => this.keyOf(path)));
|
|
8030
|
-
const out = /* @__PURE__ */ new Map();
|
|
8031
|
-
for (const path of canonical) {
|
|
8032
|
-
const value = values.get(this.keyOf(path));
|
|
8033
|
-
if (value !== void 0) out.set(path, value);
|
|
8034
|
-
}
|
|
8035
|
-
return out;
|
|
8036
|
-
}
|
|
8037
|
-
/**
|
|
8038
|
-
* 枚举 `prefix` 之下(含 prefix 自身,按段前缀匹配)的节点,分页。
|
|
8039
|
-
* 无 prefix = 全树。cursor 为上一页末节点的 path。
|
|
8040
|
-
*/
|
|
8041
|
-
async list(prefix, opts) {
|
|
8042
|
-
const normPrefix = prefix === void 0 ? "" : canonicalizePath(prefix);
|
|
8043
|
-
const limit = clampLimit6(opts?.limit);
|
|
8044
|
-
const all = (await this.scanAll()).filter((n) => isPrefixOf(normPrefix, n.path)).sort(byPath);
|
|
8045
|
-
const cursor = opts?.cursor;
|
|
8046
|
-
const start = cursor ? all.findIndex((n) => n.path === cursor) + 1 : 0;
|
|
8047
|
-
const items = all.slice(start, start + limit);
|
|
8048
|
-
const hasMore = start + limit < all.length;
|
|
8049
|
-
return {
|
|
8050
|
-
items,
|
|
8051
|
-
cursor: hasMore ? items[items.length - 1]?.path : void 0
|
|
8052
|
-
};
|
|
8053
|
-
}
|
|
8054
|
-
/** 直接子节点(段深恰好 +1);~help 列子节点用。只扫子树前缀,不扫全树。 */
|
|
8055
|
-
async children(path) {
|
|
8056
|
-
const norm = canonicalizePath(path);
|
|
8057
|
-
const depth = segments(norm).length;
|
|
8058
|
-
const sub = await this.scanPrefix(this.subtreePrefix(norm));
|
|
8059
|
-
return sub.filter((n) => segments(n.path).length === depth + 1).sort(byPath);
|
|
8060
|
-
}
|
|
8061
|
-
/**
|
|
8062
|
-
* 一次性取整棵子树的节点数组(含 `path` 自身 + 全部后代),按 path 排序。
|
|
8063
|
-
* 供 `~tree` 建树一次读入内存(而非每层递归各扫一遍)。根('')= 全树。
|
|
8064
|
-
* 不存在的根返回空数组(调用方自行判 not_found)。
|
|
8065
|
-
*/
|
|
8066
|
-
async subtree(path, opts) {
|
|
8067
|
-
const norm = canonicalizePath(path);
|
|
8068
|
-
if (opts?.maxNodes !== void 0 && (!Number.isInteger(opts.maxNodes) || opts.maxNodes < 1)) {
|
|
8069
|
-
throw new TBError("invalid_argument", "maxNodes \u5FC5\u987B\u662F\u6B63\u6574\u6570");
|
|
8070
|
-
}
|
|
8071
|
-
const descendants = await this.scanPrefix(this.subtreePrefix(norm), opts);
|
|
8072
|
-
if (norm === "") return descendants.sort(byPath);
|
|
8073
|
-
const self = await this.read(norm);
|
|
8074
|
-
const all = self ? [self, ...descendants] : descendants;
|
|
8075
|
-
if (opts?.maxNodes !== void 0 && all.length > opts.maxNodes) {
|
|
8076
|
-
throw new TBError(
|
|
8077
|
-
"rate_limited",
|
|
8078
|
-
`registry scan \u6700\u591A\u8BFB\u53D6 ${opts.maxNodes} \u4E2A\u8282\u70B9`
|
|
8079
|
-
);
|
|
8080
|
-
}
|
|
8081
|
-
return all.sort(byPath);
|
|
8082
|
-
}
|
|
8083
|
-
/**
|
|
8084
|
-
* 取按 key 确定排序的有界根快照,并显式报告是否截断。派生索引用 truncated
|
|
8085
|
-
* 选择保留 last-known-good,不把 canonical registry 的规模限制反向施加到主数据面。
|
|
8086
|
-
*/
|
|
8087
|
-
async rootSnapshot(maxNodes) {
|
|
8088
|
-
if (!Number.isInteger(maxNodes) || maxNodes < 1) {
|
|
8089
|
-
throw new TBError("invalid_argument", "maxNodes \u5FC5\u987B\u662F\u6B63\u6574\u6570");
|
|
8090
|
-
}
|
|
8091
|
-
const items = await this.scanPrefix(KEY_NODE, { maxNodes: maxNodes + 1, truncate: true });
|
|
8092
|
-
return {
|
|
8093
|
-
items: items.slice(0, maxNodes).sort(byPath),
|
|
8094
|
-
truncated: items.length > maxNodes
|
|
8095
|
-
};
|
|
8501
|
+
|
|
8502
|
+
// ../core/src/tool/mcpSchema.ts
|
|
8503
|
+
function toolToCmd(nodePath, tool, index) {
|
|
8504
|
+
const cmd = {
|
|
8505
|
+
name: tool.name,
|
|
8506
|
+
method: "POST",
|
|
8507
|
+
path: `/${nodePath}/${tool.name}`,
|
|
8508
|
+
scope: "call"
|
|
8509
|
+
};
|
|
8510
|
+
if (tool.description !== void 0) {
|
|
8511
|
+
cmd.h = index ? summarizeOneLine(tool.description) : tool.description;
|
|
8096
8512
|
}
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
const dir = {
|
|
8115
|
-
path: parent,
|
|
8116
|
-
kind: "directory",
|
|
8117
|
-
description: "",
|
|
8118
|
-
registeredBy: SYSTEM_AUTO,
|
|
8119
|
-
createdAt: now,
|
|
8120
|
-
updatedAt: now
|
|
8121
|
-
};
|
|
8122
|
-
await this.store.put(this.keyOf(parent), dir);
|
|
8123
|
-
}
|
|
8124
|
-
}
|
|
8125
|
-
const existing = await this.read(path);
|
|
8126
|
-
const full = {
|
|
8127
|
-
path,
|
|
8128
|
-
kind: node.kind,
|
|
8129
|
-
description: node.description,
|
|
8130
|
-
...node.config !== void 0 ? { config: node.config } : {},
|
|
8131
|
-
...node.virtualize !== void 0 ? { virtualize: node.virtualize } : {},
|
|
8132
|
-
...opts.deviceId !== void 0 ? { deviceId: opts.deviceId } : {},
|
|
8133
|
-
...opts.online !== void 0 ? { online: opts.online } : {},
|
|
8134
|
-
...opts.lastSeenAt !== void 0 ? { lastSeenAt: opts.lastSeenAt } : {},
|
|
8135
|
-
registeredBy,
|
|
8136
|
-
createdAt: existing?.createdAt ?? now,
|
|
8137
|
-
updatedAt: now
|
|
8138
|
-
};
|
|
8139
|
-
await this.store.put(this.keyOf(path), full);
|
|
8140
|
-
return full;
|
|
8513
|
+
if (tool.delivery !== void 0) cmd.delivery = tool.delivery;
|
|
8514
|
+
if (!index && tool.inputSchema !== void 0) cmd.inputSchema = tool.inputSchema;
|
|
8515
|
+
if (!index && tool.outputSchema !== void 0) cmd.outputSchema = tool.outputSchema;
|
|
8516
|
+
if (tool.effect !== void 0) cmd.effect = tool.effect;
|
|
8517
|
+
const confirm = tool.confirm ?? (tool.effect === "destructive" ? true : void 0);
|
|
8518
|
+
if (confirm) cmd.confirm = confirm;
|
|
8519
|
+
return cmd;
|
|
8520
|
+
}
|
|
8521
|
+
function toolsToHelpModel(nodePath, node, tools, opts = {}) {
|
|
8522
|
+
const index = opts.index === true;
|
|
8523
|
+
const model = {
|
|
8524
|
+
node: { path: nodePath, kind: node.kind, description: node.description },
|
|
8525
|
+
cmds: tools.map((tool) => toolToCmd(nodePath, tool, index))
|
|
8526
|
+
};
|
|
8527
|
+
if (index) {
|
|
8528
|
+
model.index = true;
|
|
8529
|
+
model.hint = `this is an index (descriptions summarized, input schemas omitted); GET /${nodePath}/<tool>/~help returns one tool's full spec`;
|
|
8141
8530
|
}
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8153
|
-
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8531
|
+
return model;
|
|
8532
|
+
}
|
|
8533
|
+
function toolHelpModel(nodePath, node, tool) {
|
|
8534
|
+
return {
|
|
8535
|
+
node: {
|
|
8536
|
+
path: `${nodePath}/${tool.name}`,
|
|
8537
|
+
kind: node.kind,
|
|
8538
|
+
description: summarizeOneLine(tool.description ?? node.description)
|
|
8539
|
+
},
|
|
8540
|
+
cmds: [toolToCmd(nodePath, tool, false)]
|
|
8541
|
+
};
|
|
8542
|
+
}
|
|
8543
|
+
|
|
8544
|
+
// ../core/src/tool/remote.ts
|
|
8545
|
+
function rewriteRemotePath(nodePath, requestPath, baseUrl) {
|
|
8546
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
8547
|
+
const rawSegs = requestPath.replace(/^\/+|\/+$/g, "").split("/").filter((s) => s.length > 0);
|
|
8548
|
+
const reserved = rawSegs.length > 0 && rawSegs[rawSegs.length - 1]?.startsWith("~") ? rawSegs.pop() : void 0;
|
|
8549
|
+
const nodeSegs = segments(nodePath);
|
|
8550
|
+
const pathSegs = rawSegs;
|
|
8551
|
+
let relSegs;
|
|
8552
|
+
const isPrefix = nodeSegs.length <= pathSegs.length && nodeSegs.every((s, i) => s === pathSegs[i]);
|
|
8553
|
+
if (isPrefix) {
|
|
8554
|
+
relSegs = pathSegs.slice(nodeSegs.length);
|
|
8555
|
+
} else {
|
|
8556
|
+
relSegs = pathSegs;
|
|
8162
8557
|
}
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
updatedAt: now
|
|
8177
|
-
};
|
|
8178
|
-
await this.store.put(this.keyOf(norm), updated);
|
|
8179
|
-
return updated;
|
|
8558
|
+
const tail = reserved !== void 0 ? [...relSegs, reserved] : relSegs;
|
|
8559
|
+
const rel = tail.join("/");
|
|
8560
|
+
return rel === "" ? base : `${base}/${rel}`;
|
|
8561
|
+
}
|
|
8562
|
+
function hostOf(url) {
|
|
8563
|
+
const m = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/([^/?#\\]*)/.exec(url);
|
|
8564
|
+
if (m === null) return void 0;
|
|
8565
|
+
let authority = m[1] ?? "";
|
|
8566
|
+
const at = authority.lastIndexOf("@");
|
|
8567
|
+
if (at >= 0) authority = authority.slice(at + 1);
|
|
8568
|
+
if (authority.startsWith("[")) {
|
|
8569
|
+
const close = authority.indexOf("]");
|
|
8570
|
+
if (close >= 0) return authority.slice(0, close + 1).toLowerCase();
|
|
8180
8571
|
}
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8572
|
+
const colon = authority.indexOf(":");
|
|
8573
|
+
const host = colon >= 0 ? authority.slice(0, colon) : authority;
|
|
8574
|
+
return host.toLowerCase();
|
|
8575
|
+
}
|
|
8576
|
+
function checkAllowlist(baseUrl, allowlist) {
|
|
8577
|
+
if (allowlist.length === 0) return false;
|
|
8578
|
+
const host = hostOf(baseUrl);
|
|
8579
|
+
if (host === void 0 || host === "") return false;
|
|
8580
|
+
return allowlist.some((entry) => {
|
|
8581
|
+
const suffix = entry.trim().toLowerCase();
|
|
8582
|
+
if (suffix === "") return false;
|
|
8583
|
+
return host === suffix || host.endsWith(`.${suffix}`);
|
|
8584
|
+
});
|
|
8585
|
+
}
|
|
8586
|
+
|
|
8587
|
+
// ../core/src/tool/via.ts
|
|
8588
|
+
function parseVia(header) {
|
|
8589
|
+
if (header === void 0) return [];
|
|
8590
|
+
return header.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
8591
|
+
}
|
|
8592
|
+
function checkVia(chain, selfId, maxHops) {
|
|
8593
|
+
if (chain.includes(selfId)) {
|
|
8594
|
+
return new TBError("unavailable", `\u68C0\u6D4B\u5230\u900F\u4F20\u73AF:'${selfId}' \u5DF2\u5728 X-TB-Via \u94FE\u4E2D`, {
|
|
8595
|
+
retryable: false
|
|
8596
|
+
});
|
|
8190
8597
|
}
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
* 实现决策(待回写 docs):被删节点若仍有后代 → conflict
|
|
8196
|
-
* (不允许删除非空子树;显式 directory 同理)。
|
|
8197
|
-
*/
|
|
8198
|
-
async delete(path) {
|
|
8199
|
-
const norm = canonicalizePath(path);
|
|
8200
|
-
const existing = await this.read(norm);
|
|
8201
|
-
if (!existing) throw new TBError("not_found", `\u8282\u70B9\u4E0D\u5B58\u5728:'${norm}'`);
|
|
8202
|
-
if (await this.hasChildren(norm)) {
|
|
8203
|
-
throw new TBError("conflict", `\u8282\u70B9 '${norm}' \u4ECD\u6709\u5B50\u8282\u70B9,\u4E0D\u5141\u8BB8\u5220\u9664\u975E\u7A7A\u5B50\u6811`);
|
|
8204
|
-
}
|
|
8205
|
-
await this.store.delete(this.keyOf(norm));
|
|
8206
|
-
for (const parent of [...parentPaths(norm)].reverse()) {
|
|
8207
|
-
const p = await this.read(parent);
|
|
8208
|
-
if (!p || p.registeredBy !== SYSTEM_AUTO || p.kind !== "directory") break;
|
|
8209
|
-
if (await this.hasChildren(parent)) break;
|
|
8210
|
-
await this.store.delete(this.keyOf(parent));
|
|
8211
|
-
}
|
|
8598
|
+
if (chain.length >= maxHops) {
|
|
8599
|
+
return new TBError("unavailable", `\u900F\u4F20\u8DF3\u6570\u8D85\u9650:\u94FE\u957F ${chain.length} \u2265 maxHops ${maxHops}`, {
|
|
8600
|
+
retryable: false
|
|
8601
|
+
});
|
|
8212
8602
|
}
|
|
8213
|
-
|
|
8214
|
-
|
|
8215
|
-
|
|
8216
|
-
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
|
|
8603
|
+
return null;
|
|
8604
|
+
}
|
|
8605
|
+
function appendVia(chain, selfId) {
|
|
8606
|
+
return [...chain, selfId].join(", ");
|
|
8607
|
+
}
|
|
8608
|
+
|
|
8609
|
+
// ../core/src/tool/virtualize.ts
|
|
8610
|
+
function virtualName(v, upstreamName) {
|
|
8611
|
+
const renamed = v.rename?.[upstreamName] ?? upstreamName;
|
|
8612
|
+
return v.prefix !== void 0 ? `${v.prefix}${renamed}` : renamed;
|
|
8613
|
+
}
|
|
8614
|
+
function virtualizeTools(v, upstream) {
|
|
8615
|
+
const exposed = [];
|
|
8616
|
+
const reverse = /* @__PURE__ */ new Map();
|
|
8617
|
+
const hidden = new Set(v?.hide ?? []);
|
|
8618
|
+
for (const tool of upstream) {
|
|
8619
|
+
if (hidden.has(tool.name)) continue;
|
|
8620
|
+
const projectedName = v ? virtualName(v, tool.name) : tool.name;
|
|
8621
|
+
const name = canonicalizeSegment(projectedName);
|
|
8622
|
+
const previous = reverse.get(name);
|
|
8623
|
+
if (previous !== void 0) {
|
|
8624
|
+
throw new TBError(
|
|
8625
|
+
"invalid_argument",
|
|
8626
|
+
`\u5DE5\u5177\u540D '${previous}' \u4E0E '${tool.name}' \u89C4\u8303\u5316\u540E\u51B2\u7A81:'${name}',\u8BF7\u663E\u5F0F rename`
|
|
8627
|
+
);
|
|
8230
8628
|
}
|
|
8629
|
+
const description = v?.describe?.[tool.name] ?? tool.description;
|
|
8630
|
+
exposed.push({ ...tool, name, description });
|
|
8631
|
+
reverse.set(name, tool.name);
|
|
8231
8632
|
}
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
for (const cand of candidates) {
|
|
8240
|
-
const node = await this.read(cand);
|
|
8241
|
-
if (node) {
|
|
8242
|
-
const rest = segments(norm).slice(segments(cand).length).join("/");
|
|
8243
|
-
return { node, rest };
|
|
8244
|
-
}
|
|
8245
|
-
}
|
|
8246
|
-
throw new TBError("not_found", `\u65E0\u5339\u914D\u8282\u70B9:'${norm}'`);
|
|
8633
|
+
return { exposed, reverse };
|
|
8634
|
+
}
|
|
8635
|
+
function resolveUpstreamTool(v, source2, virtualName2) {
|
|
8636
|
+
const reverse = source2 instanceof Map ? source2 : virtualizeTools(v, source2).reverse;
|
|
8637
|
+
const upstream = reverse.get(virtualName2);
|
|
8638
|
+
if (upstream === void 0) {
|
|
8639
|
+
throw TBError.notFound(`\u672A\u77E5\u5DE5\u5177:'${virtualName2}'`);
|
|
8247
8640
|
}
|
|
8248
|
-
|
|
8641
|
+
return upstream;
|
|
8642
|
+
}
|
|
8249
8643
|
|
|
8250
8644
|
export {
|
|
8251
8645
|
TB_ERROR_CODES,
|
|
@@ -8258,6 +8652,7 @@ export {
|
|
|
8258
8652
|
validatePath,
|
|
8259
8653
|
KEY_SK_HASH,
|
|
8260
8654
|
KEY_SK_ID,
|
|
8655
|
+
KEY_NODE,
|
|
8261
8656
|
KEY_PLUGIN,
|
|
8262
8657
|
KEY_BOOTSTRAPPED,
|
|
8263
8658
|
KEY_FEEDBACK,
|
|
@@ -8276,6 +8671,7 @@ export {
|
|
|
8276
8671
|
identify,
|
|
8277
8672
|
toToolResult,
|
|
8278
8673
|
OperationRegistry,
|
|
8674
|
+
eventBindingSchema,
|
|
8279
8675
|
OAUTH_CLIENT_FIELDS,
|
|
8280
8676
|
shouldRefresh,
|
|
8281
8677
|
buildAuthorizationUrl,
|
|
@@ -8291,6 +8687,14 @@ export {
|
|
|
8291
8687
|
optionalMethodsForCapabilities,
|
|
8292
8688
|
normalizeUpstreamError,
|
|
8293
8689
|
assertSecureUrl,
|
|
8690
|
+
canonicalCatalogJson,
|
|
8691
|
+
catalogSetDigest,
|
|
8692
|
+
resolveIntegration,
|
|
8693
|
+
pluginImageSchema,
|
|
8694
|
+
pluginVersionPattern,
|
|
8695
|
+
httpsReleaseUrl,
|
|
8696
|
+
parsePluginRelease,
|
|
8697
|
+
NodeRegistryStore,
|
|
8294
8698
|
pluginTokenSecretName,
|
|
8295
8699
|
createStoreModule,
|
|
8296
8700
|
RemoteAllowlistStore,
|
|
@@ -8298,6 +8702,7 @@ export {
|
|
|
8298
8702
|
createEncryptionKeyring,
|
|
8299
8703
|
validateStoreTokenKeyring,
|
|
8300
8704
|
DeviceMailboxService,
|
|
8705
|
+
deviceEnvironmentSchema,
|
|
8301
8706
|
tbErrorBodySchema,
|
|
8302
8707
|
nodeInputSchema,
|
|
8303
8708
|
helpJsonSchema,
|
|
@@ -8361,6 +8766,10 @@ export {
|
|
|
8361
8766
|
derivePresence,
|
|
8362
8767
|
DEVICE_CALL_TIMEOUT_MS,
|
|
8363
8768
|
DeviceGatewaySession,
|
|
8769
|
+
EVENT_MAX_BYTES,
|
|
8770
|
+
eventPublishSchema,
|
|
8771
|
+
eventReadSchema,
|
|
8772
|
+
eventCommands,
|
|
8364
8773
|
FEEDBACK_HIDE_SCORE,
|
|
8365
8774
|
selectFeedbackSearchText,
|
|
8366
8775
|
parseFeedbackEntries,
|
|
@@ -8377,8 +8786,6 @@ export {
|
|
|
8377
8786
|
assertUploadBinding,
|
|
8378
8787
|
storeUri,
|
|
8379
8788
|
StoreService,
|
|
8380
|
-
catalogSetDigest,
|
|
8381
|
-
resolveIntegration,
|
|
8382
8789
|
parseCredentialValues,
|
|
8383
8790
|
RequestDedupe,
|
|
8384
8791
|
HEADER_TB_CONTEXT,
|
|
@@ -8427,6 +8834,5 @@ export {
|
|
|
8427
8834
|
checkVia,
|
|
8428
8835
|
appendVia,
|
|
8429
8836
|
virtualizeTools,
|
|
8430
|
-
resolveUpstreamTool
|
|
8431
|
-
NodeRegistryStore
|
|
8837
|
+
resolveUpstreamTool
|
|
8432
8838
|
};
|