@bilibili-notify/extension 0.1.0-alpha.1 → 0.1.0-alpha.2

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/DEVELOPMENT.md CHANGED
@@ -156,6 +156,8 @@ export function activate(ctx: ExtensionContext): void {
156
156
 
157
157
  推送适配器通过`ctx.registerPlatformAdapter`登记,并在清单声明`contributes.push`。自己的连接及入站能力由适配器`start`收到的上下文提供;适配器键由宿主填成拓展id。它与订阅来源是两套接口,具体使用`PlatformAdapterDef`及其公开注释。
158
158
 
159
+ 可选实现`createTestPayload(connection, destination, kind, samples)`,让推送目标页测试真实能力。使用宿主提供的图片、SILK语音和文字构造`NotificationPayload`,不在此方法发送;不支持时返回`unsupported`,不能发送纯文本替代品。省略此方法的旧适配器仍可测试普通文本。接收测试由宿主经既有入站入口核对短时测试码,适配器不用另开接口。明确的`audio`和`markdown`载荷不应降级为普通文本。
160
+
159
161
  ## 失败与译文
160
162
 
161
163
  可预期失败返回`fail(code, message)`,成功返回`ok(...)`。`code`使用SDK的标准失败码;上游自己的错误码放`upstreamCode`。超时、限流、凭据失效与确实不存在分别处理;不要把所有错误都变成“找不到”。发送结果不明用`indeterminate`,不能自动重发。
package/build.mjs CHANGED
@@ -70,6 +70,7 @@ function translate(dict, locale, key, values = {}) {
70
70
  const UNBOUND_LAYERS = {
71
71
  "zh-CN": {
72
72
  plain: {
73
+ "internal.settings.imageAllowedCidrs": "请填写有效的 IPv4 或 IPv6 CIDR 地址段,例如 198.18.0.0/16。",
73
74
  "internal.commands.aliasBlank": "别名不能为空或带首尾空格",
74
75
  "internal.commands.prefixBlank": "前缀不能是纯空白",
75
76
  "internal.commands.prefixLeadingSpace": "前缀不能以空白开头",
@@ -859,6 +860,7 @@ const UNBOUND_LAYERS = {
859
860
  },
860
861
  "zh-TW": {
861
862
  plain: {
863
+ "internal.settings.imageAllowedCidrs": "請填寫有效的 IPv4 或 IPv6 CIDR 網段,例如 198.18.0.0/16。",
862
864
  "storage.log.masterReadFailed": "主金鑰讀取失敗(非缺失),保留原檔案並停止載入",
863
865
  "storage.log.masterLoaded": "主金鑰已載入",
864
866
  "storage.log.masterInvalid": "主金鑰檔案格式無效(應為 64 位十六進位),將重新產生;原有憑證將無法解密,需重新登入或設定",
@@ -1647,6 +1649,7 @@ const UNBOUND_LAYERS = {
1647
1649
  }
1648
1650
  },
1649
1651
  en: { plain: {
1652
+ "internal.settings.imageAllowedCidrs": "Enter a valid IPv4 or IPv6 CIDR range, such as 198.18.0.0/16.",
1650
1653
  "storage.log.masterReadFailed": "Cannot read the existing master key; preserving the file and stopping the load",
1651
1654
  "storage.log.masterLoaded": "Master key loaded",
1652
1655
  "storage.log.masterInvalid": "Invalid master key file (expected 64 hexadecimal characters); regenerating it will make existing credentials unreadable and require login or configuration again",
@@ -2352,6 +2355,7 @@ const UNBOUND_LAYERS = {
2352
2355
  } },
2353
2356
  ja: {
2354
2357
  plain: {
2358
+ "internal.settings.imageAllowedCidrs": "198.18.0.0/16 など、有効な IPv4 または IPv6 の CIDR 範囲を入力してください。",
2355
2359
  "storage.log.masterReadFailed": "既存のマスターキーを読み取れません。ファイルを保持して読み込みを中止します",
2356
2360
  "storage.log.masterLoaded": "マスターキーを読み込みました",
2357
2361
  "storage.log.masterInvalid": "マスターキーファイルの形式が無効です(64 桁の16進数が必要)。再生成により既存の認証情報を復号できなくなるため、再ログインまたは再設定が必要です",
@@ -3272,7 +3276,7 @@ const EXTENSION_IMAGE_MAX_CHARS = 32768;
3272
3276
  * ⚠️ 不带 `g`:几处共用这一个对象,带 `g` 的话 `test()` 会在两次调用之间记着 `lastIndex`。
3273
3277
  */
3274
3278
  const EXTENSION_IMAGE_DATA_URL_RE = /^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+=*$/;
3275
- // ../internal/lib/settings-fields-from-schema-CpiuxNUl.mjs
3279
+ // ../internal/lib/settings-fields-from-schema-CU2DEonf.mjs
3276
3280
  const VARIABLE_QUANTIFIER = String.raw`(?:[+*]|\{\d+,\d*\})`;
3277
3281
  const NESTED_QUANTIFIER = new RegExp(String.raw`\((?:\?[:=!][^)]*|[^)]*)${VARIABLE_QUANTIFIER}[^)]*\)\s*(?:[+*]|\{\d+(?:,\d*)?\})`);
3278
3282
  function hasOverlappingAlternationUnderQuantifier(src) {
package/index.d.mts CHANGED
@@ -239,6 +239,10 @@ type DestinationRef = Pick<Extract<PushTarget, {
239
239
  */
240
240
  declare const PUSH_TARGET_SCOPES: readonly ["group", "private", "channel"];
241
241
  type PushTargetScope = (typeof PUSH_TARGET_SCOPES)[number];
242
+ /** 面板逐项测试的词表;`inbound` 需要回传,其他项目各发送一次真实样例。 */
243
+ declare const TARGET_TEST_KINDS: readonly ["text", "atAll", "nativeShare", "image", "imageGroup", "forward", "audio", "markdown", "inbound"];
244
+ type TargetTestKind = (typeof TARGET_TEST_KINDS)[number];
245
+ type SendTestKind = Exclude<TargetTestKind, "inbound">;
242
246
  /**
243
247
  * 图库引用形状 —— `<sha256>.<ext>` 的扩展名和校验正则。
244
248
  *
@@ -855,6 +859,22 @@ interface SettingsFieldMeta {
855
859
  type ProbeResult = Result<{
856
860
  latencyMs: number;
857
861
  }>;
862
+ /** 宿主提供的自包含测试素材。适配器只编载荷;真正发送仍由 TargetDispatcher 调 send。 */
863
+ interface PlatformTestOptions {
864
+ text: string;
865
+ image: {
866
+ buffer: Buffer;
867
+ mime: string;
868
+ };
869
+ secondImage: {
870
+ buffer: Buffer;
871
+ mime: string;
872
+ };
873
+ audio: {
874
+ buffer: Buffer;
875
+ mime: "audio/silk";
876
+ };
877
+ }
858
878
  /**
859
879
  * 一个平台实现 —— 认领哪些连接、怎么建连、报文怎么编、地址怎么解、有什么能力。
860
880
  * 矩阵({@link TargetDispatcher})拿它按连接的 `adapterKey` 找。
@@ -916,12 +936,22 @@ interface PlatformAdapter {
916
936
  isAvailable(connection: Connection, destination: DestinationRef): boolean;
917
937
  /** Deliver `payload` to `destination` over `connection`. 群还是私聊只看 `destination.scope`。 */
918
938
  send(connection: Connection, destination: DestinationRef, payload: NotificationPayload): Promise<DeliveryResult>;
939
+ /** 构造对应能力的真实样例;不支持时拒绝,不用文本替代。没有此成员的旧适配器仍可测试普通文本。 */
940
+ createTestPayload?(connection: Connection, destination: DestinationRef, kind: SendTestKind, samples: PlatformTestOptions): Result<{
941
+ payload: NotificationPayload;
942
+ }>;
919
943
  /**
920
944
  * 这条连接的能力(三态;探测结果读缓存,同步读、不打网络)。内置适配器都实现;没实现的
921
945
  * (老的拓展适配器)各项按「还不知道」算,怎么对待「还不知道」见 internal 的
922
946
  * `shouldSendAtAll` / `canReceiveReply` / `listsForLinkPreview`。
923
947
  */
924
948
  capabilities?(connection: Connection): ConnectionCapabilities;
949
+ /** 宿主只读查询会话内身份与使用记录;暂不向拓展开放。 */
950
+ fetchDestinationStatus?(connection: Connection, destination: DestinationRef, signal: AbortSignal, options?: {
951
+ refresh?: boolean;
952
+ }): Promise<Result<{
953
+ status: DestinationStatus;
954
+ }>>;
925
955
  /** 主动探一次能力,结果进缓存。连上时、健康探测时、用之前都可以叫;零副作用。 */
926
956
  probeCapabilities?(connection: Connection): Promise<ConnectionCapabilities>;
927
957
  /**
@@ -1278,6 +1308,11 @@ interface NativeShare {
1278
1308
  type NotificationPayload = {
1279
1309
  kind: "text";
1280
1310
  text: string;
1311
+ } |
1312
+ /** 明确要求原生 Markdown;不支持的适配器拒绝,不剥成纯文字冒充成功。 */
1313
+ {
1314
+ kind: "markdown";
1315
+ text: string;
1281
1316
  } | {
1282
1317
  kind: "image";
1283
1318
  image: {
@@ -1285,6 +1320,14 @@ type NotificationPayload = {
1285
1320
  mime: string;
1286
1321
  };
1287
1322
  caption?: string;
1323
+ } |
1324
+ /** 单条语音。当前发送实现接收 SILK;格式转换由调用方完成,适配器不降级成文字。 */
1325
+ {
1326
+ kind: "audio";
1327
+ audio: {
1328
+ buffer: Buffer;
1329
+ mime: "audio/silk";
1330
+ };
1288
1331
  } | {
1289
1332
  kind: "composite";
1290
1333
  segments: PayloadSegment[];
@@ -1336,7 +1379,7 @@ type DeliveryResult = Result<{
1336
1379
  * 后者是结论;读它的地方各自决定「还不知道」时怎么办(见 `ConnectionCapabilities` 各格的注释),
1337
1380
  * 面板上两者也要分开显示。
1338
1381
  *
1339
- * - `supported`:确认支持,`checkedAt` 是确认的时刻。
1382
+ * - `supported`:确认支持,`checkedAt` 是确认的时刻,可用 `reason` 说明适用范围。
1340
1383
  * - `unsupported`:确认不支持,`reason` 给人看的一句话,`checkedAt` 是确认的时刻。
1341
1384
  * - `unknown`:还没探出来(没探过、连不上、对面没报),`reason` 可选。
1342
1385
  *
@@ -1345,6 +1388,7 @@ type DeliveryResult = Result<{
1345
1388
  type CapabilitySupport = {
1346
1389
  state: "supported";
1347
1390
  checkedAt: string;
1391
+ reason?: string;
1348
1392
  } | {
1349
1393
  state: "unsupported";
1350
1394
  reason: string;
@@ -1353,8 +1397,32 @@ type CapabilitySupport = {
1353
1397
  state: "unknown";
1354
1398
  reason?: string;
1355
1399
  };
1400
+ /** 机器人在某个会话里的状态,独立于整条连接的能力。 */
1401
+ interface DestinationStatus {
1402
+ role: {
1403
+ state: "known";
1404
+ value: "member" | "admin" | "owner";
1405
+ checkedAt: string;
1406
+ } | {
1407
+ state: "unknown";
1408
+ reason?: string;
1409
+ };
1410
+ /** BN 的当日发送记录,不是平台返回的剩余额度。 */
1411
+ atAllUsage?: {
1412
+ state: "not-recorded" | "used" | "exhausted" | "indeterminate";
1413
+ date: string;
1414
+ timezone: string;
1415
+ source: "bn";
1416
+ };
1417
+ }
1356
1418
  /** 一条连接的能力快照,由这条连接的适配器回答。 */
1357
1419
  interface ConnectionCapabilities {
1420
+ /** 额外展示能力;旧适配器未报告时按未知,不用于推断群内权限。 */
1421
+ image?: CapabilitySupport;
1422
+ imageGroup?: CapabilitySupport;
1423
+ forward?: CapabilitySupport;
1424
+ audio?: CapabilitySupport;
1425
+ markdown?: CapabilitySupport;
1358
1426
  /**
1359
1427
  * 能不能单发 @全体。派发器的 `supportsAtAll` 与订阅抽屉里的 @全体 开关读它;
1360
1428
  * 「还不知道」时**照发**(发错只是多一条消息)。
@@ -1934,7 +2002,7 @@ type ExtensionUpgradeHandler = (upgrade: ExtensionUpgrade) => void;
1934
2002
  *
1935
2003
  * `listAddressCandidates` 与 `connectionAuth` 不对拓展开放(ADR-0024 决策 11),类型里排除,宿主运行时也会摘掉。
1936
2004
  */
1937
- type PlatformAdapterDef = Simplify<Pick<PlatformAdapter, "probe" | "start" | "stop" | "isAvailable" | "send" | "capabilities" | "probeCapabilities" | "settingsSchema" | "listConnectionCandidates">>;
2005
+ type PlatformAdapterDef = Simplify<Pick<PlatformAdapter, "probe" | "start" | "stop" | "isAvailable" | "send" | "createTestPayload" | "capabilities" | "probeCapabilities" | "settingsSchema" | "listConnectionCandidates">>;
1938
2006
  /** 注册完一个平台适配器之后拿到的把手。 */
1939
2007
  interface PlatformAdapterHandle {
1940
2008
  /** 注销适配器;幂等,调用后不再接收消息,也不再发送。 */
@@ -2268,4 +2336,4 @@ interface ExtensionDevtoolsContext extends ExtensionContext {
2268
2336
  */
2269
2337
  mountUrl(): string | undefined;
2270
2338
  }
2271
- export { type AuthState, type CapabilitySupport, type Connection, type ConnectionCandidate, type ConnectionCapabilities, type CreatorCandidate, type CreatorProfileReport, type DeliveryResult, type DestinationRef, type DevInjection, type DevParamField, type DevParamValues, type DevScenarioDef, type DevScenarioDescriptor, type DevScenarioGroup, type DevtoolsProvider, type Disposable, type ExtensionBlock, type ExtensionButton, type ExtensionContext, type ExtensionDevtoolsContext, type ExtensionFetchHandler, type ExtensionI18n, type ExtensionItemView, type ExtensionLinkPreview, type ExtensionLiveDetails, type ExtensionLiveSignalReport, type ExtensionLiveStatusResult, type ExtensionPostReport, type ExtensionRichText, type ExtensionRichTextSegment, type ExtensionSourceContext, type ExtensionTableCell, type ExtensionTableColumn, type ExtensionTone, type ExtensionUpgrade, type ExtensionUpgradeHandler, type ExtensionView, type ExtensionViewSummary, type ExtensionViewText, type ExtensionViewTextSegment, type Failure, type FailureCode, type FeatureKey, type FetchOptions, type Hop, type HopHandler, type HttpClient, type HttpResponse, type Identity, type ImageRef, type InboundGroupMessage, type InboundMeta, type InboundPrivateMessage, type IntegrationContext, type Json, type KeyValueOp, type KeyValueStore, type Logger, type NotificationPayload, type PayloadSegment, type PlatformAdapter, type PlatformAdapterContext, type PlatformAdapterDef, type PlatformAdapterDescriptor, type PlatformAdapterHandle, type PlatformDescriptor, type ProbeResult, type PushTarget, type PushTargetScope, type Result, type SettingsField, type SettingsFieldMeta, type SettingsListField, type SettingsReader, type SettingsScalarField, type SourceAccount, type SourceAuth, type SourceDef, type SourceHandle, type SourceHealth, type SourceSubscriptionView, type SubscriptionCreator, type TextValues, type WebSocketLike, type WebSocketOptions, fail, ok };
2339
+ export { type AuthState, type CapabilitySupport, type Connection, type ConnectionCandidate, type ConnectionCapabilities, type CreatorCandidate, type CreatorProfileReport, type DeliveryResult, type DestinationRef, type DevInjection, type DevParamField, type DevParamValues, type DevScenarioDef, type DevScenarioDescriptor, type DevScenarioGroup, type DevtoolsProvider, type Disposable, type ExtensionBlock, type ExtensionButton, type ExtensionContext, type ExtensionDevtoolsContext, type ExtensionFetchHandler, type ExtensionI18n, type ExtensionItemView, type ExtensionLinkPreview, type ExtensionLiveDetails, type ExtensionLiveSignalReport, type ExtensionLiveStatusResult, type ExtensionPostReport, type ExtensionRichText, type ExtensionRichTextSegment, type ExtensionSourceContext, type ExtensionTableCell, type ExtensionTableColumn, type ExtensionTone, type ExtensionUpgrade, type ExtensionUpgradeHandler, type ExtensionView, type ExtensionViewSummary, type ExtensionViewText, type ExtensionViewTextSegment, type Failure, type FailureCode, type FeatureKey, type FetchOptions, type Hop, type HopHandler, type HttpClient, type HttpResponse, type Identity, type ImageRef, type InboundGroupMessage, type InboundMeta, type InboundPrivateMessage, type IntegrationContext, type Json, type KeyValueOp, type KeyValueStore, type Logger, type NotificationPayload, type PayloadSegment, type PlatformAdapter, type PlatformAdapterContext, type PlatformAdapterDef, type PlatformAdapterDescriptor, type PlatformAdapterHandle, type PlatformDescriptor, type PlatformTestOptions, type ProbeResult, type PushTarget, type PushTargetScope, type Result, type SendTestKind, type SettingsField, type SettingsFieldMeta, type SettingsListField, type SettingsReader, type SettingsScalarField, type SourceAccount, type SourceAuth, type SourceDef, type SourceHandle, type SourceHealth, type SourceSubscriptionView, type SubscriptionCreator, type TextValues, type WebSocketLike, type WebSocketOptions, fail, ok };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bilibili-notify/extension",
3
3
  "description": "Public contract and build helpers for bilibili-notify extensions",
4
- "version": "0.1.0-alpha.1",
4
+ "version": "0.1.0-alpha.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/Akokk0/bilibili-notify"