@motrix/mdxp 0.1.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.
Files changed (103) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +103 -0
  3. package/dist/browser.d.ts +3 -0
  4. package/dist/browser.d.ts.map +1 -0
  5. package/dist/browser.js +14 -0
  6. package/dist/browser.js.map +1 -0
  7. package/dist/connection.d.ts +50 -0
  8. package/dist/connection.d.ts.map +1 -0
  9. package/dist/connection.js +38 -0
  10. package/dist/connection.js.map +1 -0
  11. package/dist/errors.d.ts +33 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +34 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +10 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/methods.d.ts +28 -0
  20. package/dist/methods.d.ts.map +1 -0
  21. package/dist/methods.js +32 -0
  22. package/dist/methods.js.map +1 -0
  23. package/dist/node.d.ts +3 -0
  24. package/dist/node.d.ts.map +1 -0
  25. package/dist/node.js +15 -0
  26. package/dist/node.js.map +1 -0
  27. package/dist/schemas/download-add.d.ts +72 -0
  28. package/dist/schemas/download-add.d.ts.map +1 -0
  29. package/dist/schemas/download-add.js +49 -0
  30. package/dist/schemas/download-add.js.map +1 -0
  31. package/dist/schemas/download.d.ts +156 -0
  32. package/dist/schemas/download.d.ts.map +1 -0
  33. package/dist/schemas/download.js +34 -0
  34. package/dist/schemas/download.js.map +1 -0
  35. package/dist/schemas/engine.d.ts +41 -0
  36. package/dist/schemas/engine.d.ts.map +1 -0
  37. package/dist/schemas/engine.js +24 -0
  38. package/dist/schemas/engine.js.map +1 -0
  39. package/dist/schemas/events.d.ts +36 -0
  40. package/dist/schemas/events.d.ts.map +1 -0
  41. package/dist/schemas/events.js +26 -0
  42. package/dist/schemas/events.js.map +1 -0
  43. package/dist/schemas/index.d.ts +12 -0
  44. package/dist/schemas/index.d.ts.map +1 -0
  45. package/dist/schemas/index.js +12 -0
  46. package/dist/schemas/index.js.map +1 -0
  47. package/dist/schemas/initialize.d.ts +70 -0
  48. package/dist/schemas/initialize.d.ts.map +1 -0
  49. package/dist/schemas/initialize.js +72 -0
  50. package/dist/schemas/initialize.js.map +1 -0
  51. package/dist/schemas/resource.d.ts +39 -0
  52. package/dist/schemas/resource.d.ts.map +1 -0
  53. package/dist/schemas/resource.js +21 -0
  54. package/dist/schemas/resource.js.map +1 -0
  55. package/dist/schemas/selection.d.ts +129 -0
  56. package/dist/schemas/selection.d.ts.map +1 -0
  57. package/dist/schemas/selection.js +30 -0
  58. package/dist/schemas/selection.js.map +1 -0
  59. package/dist/schemas/stats.d.ts +18 -0
  60. package/dist/schemas/stats.d.ts.map +1 -0
  61. package/dist/schemas/stats.js +14 -0
  62. package/dist/schemas/stats.js.map +1 -0
  63. package/dist/schemas/system.d.ts +11 -0
  64. package/dist/schemas/system.d.ts.map +1 -0
  65. package/dist/schemas/system.js +9 -0
  66. package/dist/schemas/system.js.map +1 -0
  67. package/dist/schemas/task.d.ts +202 -0
  68. package/dist/schemas/task.d.ts.map +1 -0
  69. package/dist/schemas/task.js +90 -0
  70. package/dist/schemas/task.js.map +1 -0
  71. package/dist/schemas/url.d.ts +162 -0
  72. package/dist/schemas/url.d.ts.map +1 -0
  73. package/dist/schemas/url.js +73 -0
  74. package/dist/schemas/url.js.map +1 -0
  75. package/dist/tools.d.ts +35 -0
  76. package/dist/tools.d.ts.map +1 -0
  77. package/dist/tools.js +124 -0
  78. package/dist/tools.js.map +1 -0
  79. package/dist/types.d.ts +12 -0
  80. package/dist/types.d.ts.map +1 -0
  81. package/dist/types.js +2 -0
  82. package/dist/types.js.map +1 -0
  83. package/package.json +73 -0
  84. package/src/browser.ts +14 -0
  85. package/src/connection.ts +162 -0
  86. package/src/errors.ts +60 -0
  87. package/src/index.ts +31 -0
  88. package/src/methods.ts +36 -0
  89. package/src/node.ts +15 -0
  90. package/src/schemas/download-add.ts +55 -0
  91. package/src/schemas/download.ts +42 -0
  92. package/src/schemas/engine.ts +32 -0
  93. package/src/schemas/events.ts +36 -0
  94. package/src/schemas/index.ts +11 -0
  95. package/src/schemas/initialize.ts +88 -0
  96. package/src/schemas/resource.ts +26 -0
  97. package/src/schemas/selection.ts +32 -0
  98. package/src/schemas/stats.ts +20 -0
  99. package/src/schemas/system.ts +13 -0
  100. package/src/schemas/task.ts +113 -0
  101. package/src/schemas/url.ts +86 -0
  102. package/src/tools.ts +175 -0
  103. package/src/types.ts +63 -0
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2018-present Dr_rOot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @motrix/mdxp
2
+
3
+ Motrix Download eXchange Protocol (MDXP) v1.0 — JSON-RPC 2.0 wire types, Zod schemas, and bidirectional connection helpers shared between the Motrix desktop app and the Motrix browser extension. Both live under the [motrixapp](https://github.com/motrixapp) organization.
4
+
5
+ 完整协议规范见 `motrix-extension` 仓库的 `docs/01-protocol-mdxp.md`。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add @motrix/mdxp
11
+ ```
12
+
13
+ ## 用法
14
+
15
+ ### 创建一个连接
16
+
17
+ ```ts
18
+ import { createMdxpConnection } from '@motrix/mdxp'
19
+ import { StreamMessageReader, StreamMessageWriter } from 'vscode-jsonrpc/node'
20
+
21
+ const conn = createMdxpConnection(
22
+ new StreamMessageReader(process.stdin),
23
+ new StreamMessageWriter(process.stdout)
24
+ )
25
+
26
+ // 注册 handlers BEFORE listen
27
+ conn.onRequest('url/resolve', async (params) => {
28
+ // ... 返回 typed UrlResolveResult
29
+ })
30
+
31
+ conn.onNotification('$/task/progress', (params) => {
32
+ // ...
33
+ })
34
+
35
+ conn.listen()
36
+ ```
37
+
38
+ ### 发送 request
39
+
40
+ ```ts
41
+ const result = await conn.sendRequest('url/resolve', {
42
+ url: 'https://www.youtube.com/watch?v=...',
43
+ preferences: { maxQuality: '1080p' },
44
+ })
45
+ // result 类型自动推断为 UrlResolveResult
46
+ ```
47
+
48
+ ### 发送 notification
49
+
50
+ ```ts
51
+ conn.sendNotification('$/task/progress', {
52
+ taskId: 't1',
53
+ bytesDone: 1024,
54
+ bytesTotal: 10240,
55
+ speedBps: 512,
56
+ etaSec: 18,
57
+ phase: 'downloading',
58
+ })
59
+ ```
60
+
61
+ ### Schema 运行时校验
62
+
63
+ ```ts
64
+ import { UrlResolveParamsSchema } from '@motrix/mdxp'
65
+
66
+ const validated = UrlResolveParamsSchema.parse(rawData)
67
+ // 失败抛 ZodError;用 safeParse() 取 success 字段判断
68
+ ```
69
+
70
+ ### Error 模型
71
+
72
+ ```ts
73
+ import { ErrorCodes, makeMdxpError } from '@motrix/mdxp'
74
+
75
+ throw makeMdxpError(ErrorCodes.AdapterError, 'YouTube extraction failed', {
76
+ appCode: 'youtube.video_unavailable',
77
+ retryable: false,
78
+ context: { videoId: 'abc' },
79
+ })
80
+ ```
81
+
82
+ ## 公共 API
83
+
84
+ | Export | 作用 |
85
+ |---|---|
86
+ | `Methods.*` | 方法名常量 (`motrix/initialize` 等) |
87
+ | `Notifications.*` | 通知名常量 (`$/task/progress` 等) |
88
+ | `ErrorCodes.*` | JSON-RPC + Motrix-defined error codes |
89
+ | `isProtocolError(code)`, `isMotrixError(code)` | error 分类 helpers |
90
+ | `makeMdxpError(code, msg, data?)` | error 构造 helper |
91
+ | `createMdxpConnection(reader, writer)` | 主入口,返回 `MdxpConnection` |
92
+ | `*Schema` | 全部 Zod schemas(运行时校验) |
93
+ | `MdxpRequestMap`, `MdxpNotificationMap` | 类型表(method → [params, result]) |
94
+
95
+ ## 设计原则
96
+
97
+ - **transport-agnostic**:本包不绑死特定 transport;任何符合 `MessageReader`/`MessageWriter` 接口的双工流都可用
98
+ - **schema-first**:所有 wire 形态先用 Zod 定义,TypeScript 类型从 schema 推断
99
+ - **forward-compat**:未知 method/字段忽略而非 reject
100
+
101
+ ## License
102
+
103
+ MIT
@@ -0,0 +1,3 @@
1
+ import 'vscode-jsonrpc/browser';
2
+ export * from './index.js';
3
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAWA,OAAO,wBAAwB,CAAA;AAE/B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,14 @@
1
+ // Browser platform entry.
2
+ //
3
+ // vscode-jsonrpc v9 split the runtime abstraction layer (RAL) out of the bare
4
+ // `vscode-jsonrpc` entry: creating/listening on a `MessageConnection` now
5
+ // requires a platform RAL to be installed first. Importing this module installs
6
+ // the browser RAL into the SAME `vscode-jsonrpc` instance that this package's
7
+ // `createMdxpConnection` resolves.
8
+ //
9
+ // A browser host (e.g. the Motrix extension background script) imports
10
+ // `@motrix/mdxp/browser` once at startup. The full public API is re-exported, so
11
+ // `import { createMdxpConnection } from '@motrix/mdxp/browser'` also works.
12
+ import 'vscode-jsonrpc/browser';
13
+ export * from './index.js';
14
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,gFAAgF;AAChF,8EAA8E;AAC9E,mCAAmC;AACnC,EAAE;AACF,uEAAuE;AACvE,iFAAiF;AACjF,4EAA4E;AAC5E,OAAO,wBAAwB,CAAA;AAE/B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,50 @@
1
+ import type { CancellationToken, MessageConnection, MessageReader, MessageWriter } from 'vscode-jsonrpc';
2
+ import type { CancelRequestParams, DownloadAddParams, DownloadAddResult, DownloadCancelParams, DownloadCancelResult, DownloadSubmitParams, DownloadSubmitResult, EngineStatusParams, EngineStatusResult, InitializeParams, InitializeResult, PairRevokedParams, StatsGetParams, StatsResult, StatsUpdateParams, SystemPingParams, SystemPingResult, TaskCompletedParams, TaskErrorParams, TaskGetParams, TaskGetResult, TaskListParams, TaskListResult, TaskPauseParams, TaskPauseResult, TaskProgressParams, TaskRemoveParams, TaskRemoveResult, TaskResumeParams, TaskResumeResult, UrlProbeParams, UrlProbeResult, UrlResolveParams, UrlResolveResult } from './types.js';
3
+ export interface MdxpRequestMap {
4
+ 'motrix/initialize': [InitializeParams, InitializeResult];
5
+ 'download/submit': [DownloadSubmitParams, DownloadSubmitResult];
6
+ 'download/cancel': [DownloadCancelParams, DownloadCancelResult];
7
+ 'url/probe': [UrlProbeParams, UrlProbeResult];
8
+ 'url/resolve': [UrlResolveParams, UrlResolveResult];
9
+ 'system/ping': [SystemPingParams, SystemPingResult];
10
+ 'download/add': [DownloadAddParams, DownloadAddResult];
11
+ 'task/list': [TaskListParams, TaskListResult];
12
+ 'task/get': [TaskGetParams, TaskGetResult];
13
+ 'task/pause': [TaskPauseParams, TaskPauseResult];
14
+ 'task/resume': [TaskResumeParams, TaskResumeResult];
15
+ 'task/remove': [TaskRemoveParams, TaskRemoveResult];
16
+ 'stats/get': [StatsGetParams, StatsResult];
17
+ 'engine/status': [EngineStatusParams, EngineStatusResult];
18
+ }
19
+ export interface MdxpNotificationMap {
20
+ 'motrix/initialized': undefined;
21
+ '$/task/progress': TaskProgressParams;
22
+ '$/task/completed': TaskCompletedParams;
23
+ '$/task/error': TaskErrorParams;
24
+ '$/pair/revoked': PairRevokedParams;
25
+ '$/cancelRequest': CancelRequestParams;
26
+ '$/stats': StatsUpdateParams;
27
+ }
28
+ export interface MdxpConnection {
29
+ /** Begin processing incoming messages. Call AFTER attaching handlers. */
30
+ listen(): void;
31
+ /**
32
+ * Send a request. Optionally pass a `CancellationToken` so the caller can
33
+ * abort an in-flight request — vscode-jsonrpc emits `$/cancelRequest`
34
+ * automatically per spec §9.
35
+ */
36
+ sendRequest<M extends keyof MdxpRequestMap>(method: M, params: MdxpRequestMap[M][0], token?: CancellationToken): Promise<MdxpRequestMap[M][1]>;
37
+ /**
38
+ * Handler can accept an optional `CancellationToken`. vscode-jsonrpc wires
39
+ * it to the underlying `$/cancelRequest` notification — the handler MUST
40
+ * observe `token.isCancellationRequested` for cooperative cancellation.
41
+ */
42
+ onRequest<M extends keyof MdxpRequestMap>(method: M, handler: (params: MdxpRequestMap[M][0], token: CancellationToken) => MdxpRequestMap[M][1] | Promise<MdxpRequestMap[M][1]>): void;
43
+ sendNotification<N extends keyof MdxpNotificationMap>(name: N, params: MdxpNotificationMap[N]): void;
44
+ onNotification<N extends keyof MdxpNotificationMap>(name: N, handler: (params: MdxpNotificationMap[N]) => void): void;
45
+ dispose(): void;
46
+ /** Escape hatch: access the underlying vscode-jsonrpc connection. */
47
+ readonly raw: MessageConnection;
48
+ }
49
+ export declare function createMdxpConnection(reader: MessageReader, writer: MessageWriter): MdxpConnection;
50
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names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,GAC7B,IAAI,CAAA;IAEP,cAAc,CAAC,CAAC,SAAS,MAAM,mBAAmB,EAChD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,IAAI,GAChD,IAAI,CAAA;IAEP,OAAO,IAAI,IAAI,CAAA;IAEf,qEAAqE;IACrE,QAAQ,CAAC,GAAG,EAAE,iBAAiB,CAAA;CAChC;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,aAAa,GACpB,cAAc,CAwChB"}
@@ -0,0 +1,38 @@
1
+ import { createMessageConnection } from 'vscode-jsonrpc';
2
+ export function createMdxpConnection(reader, writer) {
3
+ const raw = createMessageConnection(reader, writer);
4
+ return {
5
+ listen: () => raw.listen(),
6
+ // Promise<never> is assignable to all Promise<X>, satisfying the generic
7
+ // constraint for all M simultaneously at the implementation site.
8
+ sendRequest: (method, params, token) =>
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ (token === undefined
11
+ ? raw.sendRequest(method, params)
12
+ : raw.sendRequest(method, params, token)),
13
+ onRequest: (method, handler) => {
14
+ // vscode-jsonrpc v9 tightened GenericRequestHandler/HandlerResult, so a
15
+ // generically-typed handler is no longer directly assignable. The runtime
16
+ // function is correct for every M; cast the whole handler via `never`
17
+ // (matching the `as never` escape hatches used elsewhere in this file).
18
+ raw.onRequest(method, ((params, token) => handler(params, token)));
19
+ },
20
+ sendNotification: (name, params) => {
21
+ if (params === undefined) {
22
+ raw.sendNotification(name);
23
+ }
24
+ else {
25
+ raw.sendNotification(name, params);
26
+ }
27
+ },
28
+ onNotification: (name, handler) => {
29
+ raw.onNotification(name, (params) =>
30
+ // Cast via `never`: handler accepts the concrete notification params
31
+ // type for N, but raw.onNotification gives us `unknown`.
32
+ handler(params));
33
+ },
34
+ dispose: () => raw.dispose(),
35
+ raw,
36
+ };
37
+ }
38
+ //# sourceMappingURL=connection.js.map
@@ -0,0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AC,IAAc,EAAE,CAAC,MAAe,EAAE,EAAE;YACrD,qEAAqE;YACrE,yDAAyD;YACzD,OAAO,CAAC,MAAe,CAAC,CACzB,CAAA;QACH,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE;QAC5B,GAAG;KACJ,CAAA;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ export declare const ErrorCodes: Readonly<{
2
+ readonly ParseError: -32700;
3
+ readonly InvalidRequest: -32600;
4
+ readonly MethodNotFound: -32601;
5
+ readonly InvalidParams: -32602;
6
+ readonly InternalError: -32603;
7
+ readonly RequestCancelled: -32800;
8
+ readonly AdapterError: -32001;
9
+ readonly ResourceUnavailable: -32002;
10
+ readonly PermissionDenied: -32003;
11
+ readonly RateLimited: -32004;
12
+ readonly CapabilityNotSupported: -32005;
13
+ readonly PairRevoked: -32006;
14
+ }>;
15
+ export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
16
+ /** True for JSON-RPC 2.0 reserved codes (parse/invalid/method/internal/cancel) */
17
+ export declare function isProtocolError(code: number): boolean;
18
+ /** True for codes in Motrix's -32000..-32099 reserved range */
19
+ export declare function isMotrixError(code: number): boolean;
20
+ export interface MdxpErrorData {
21
+ appCode?: string;
22
+ localizedMessage?: string;
23
+ retryable?: boolean;
24
+ retryAfterSec?: number;
25
+ context?: Record<string, unknown>;
26
+ }
27
+ export interface MdxpError {
28
+ code: number;
29
+ message: string;
30
+ data?: MdxpErrorData;
31
+ }
32
+ export declare function makeMdxpError(code: number, message: string, data?: MdxpErrorData): MdxpError;
33
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU;;;;;;;;;;;;;EAgBZ,CAAA;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAA;AAEpE,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CASrD;AAED,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,aAAa,CAAA;CACrB;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,aAAa,GACnB,SAAS,CAEX"}
package/dist/errors.js ADDED
@@ -0,0 +1,34 @@
1
+ // MDXP error code model — see docs/01-protocol-mdxp.md §8
2
+ export const ErrorCodes = Object.freeze({
3
+ // JSON-RPC 2.0 reserved (-32768 to -32000)
4
+ ParseError: -32700,
5
+ InvalidRequest: -32600,
6
+ MethodNotFound: -32601,
7
+ InvalidParams: -32602,
8
+ InternalError: -32603,
9
+ RequestCancelled: -32800, // LSP extension
10
+ // Motrix-defined (-32000 to -32099, JSON-RPC server-implementation reserved)
11
+ AdapterError: -32001,
12
+ ResourceUnavailable: -32002,
13
+ PermissionDenied: -32003,
14
+ RateLimited: -32004,
15
+ CapabilityNotSupported: -32005,
16
+ PairRevoked: -32006,
17
+ });
18
+ /** True for JSON-RPC 2.0 reserved codes (parse/invalid/method/internal/cancel) */
19
+ export function isProtocolError(code) {
20
+ return (code === ErrorCodes.ParseError ||
21
+ code === ErrorCodes.InvalidRequest ||
22
+ code === ErrorCodes.MethodNotFound ||
23
+ code === ErrorCodes.InvalidParams ||
24
+ code === ErrorCodes.InternalError ||
25
+ code === ErrorCodes.RequestCancelled);
26
+ }
27
+ /** True for codes in Motrix's -32000..-32099 reserved range */
28
+ export function isMotrixError(code) {
29
+ return code <= -32000 && code >= -32099;
30
+ }
31
+ export function makeMdxpError(code, message, data) {
32
+ return data === undefined ? { code, message } : { code, message, data };
33
+ }
34
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAE1D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;IACtC,2CAA2C;IAC3C,UAAU,EAAE,CAAC,KAAK;IAClB,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;IACtB,aAAa,EAAE,CAAC,KAAK;IACrB,aAAa,EAAE,CAAC,KAAK;IACrB,gBAAgB,EAAE,CAAC,KAAK,EAAE,gBAAgB;IAE1C,6EAA6E;IAC7E,YAAY,EAAE,CAAC,KAAK;IACpB,mBAAmB,EAAE,CAAC,KAAK;IAC3B,gBAAgB,EAAE,CAAC,KAAK;IACxB,WAAW,EAAE,CAAC,KAAK;IACnB,sBAAsB,EAAE,CAAC,KAAK;IAC9B,WAAW,EAAE,CAAC,KAAK;CACX,CAAC,CAAA;AAIX,kFAAkF;AAClF,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,CACL,IAAI,KAAK,UAAU,CAAC,UAAU;QAC9B,IAAI,KAAK,UAAU,CAAC,cAAc;QAClC,IAAI,KAAK,UAAU,CAAC,cAAc;QAClC,IAAI,KAAK,UAAU,CAAC,aAAa;QACjC,IAAI,KAAK,UAAU,CAAC,aAAa;QACjC,IAAI,KAAK,UAAU,CAAC,gBAAgB,CACrC,CAAA;AACH,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAA;AACzC,CAAC;AAgBD,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,OAAe,EACf,IAAoB;IAEpB,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AACzE,CAAC"}
@@ -0,0 +1,11 @@
1
+ export type { MdxpConnection, MdxpNotificationMap, MdxpRequestMap, } from './connection.js';
2
+ export { createMdxpConnection } from './connection.js';
3
+ export type { ErrorCode, MdxpError, MdxpErrorData } from './errors.js';
4
+ export { ErrorCodes, isMotrixError, isProtocolError, makeMdxpError, } from './errors.js';
5
+ export type { Method, Notification } from './methods.js';
6
+ export { Methods, Notifications } from './methods.js';
7
+ export * from './schemas/index.js';
8
+ export type { AgentTool, MdxpToolDef } from './tools.js';
9
+ export { SERVER_INITIATED_METHODS, Tools, toAgentToolCatalog, } from './tools.js';
10
+ export type * from './types.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,cAAc,GACf,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EACL,UAAU,EACV,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAGrD,cAAc,oBAAoB,CAAA;AAClC,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAGxD,OAAO,EACL,wBAAwB,EACxB,KAAK,EACL,kBAAkB,GACnB,MAAM,YAAY,CAAA;AAEnB,mBAAmB,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // MDXP — Motrix Download eXchange Protocol
2
+ // Public API surface for both Motrix desktop and the browser extension.
3
+ export { createMdxpConnection } from './connection.js';
4
+ export { ErrorCodes, isMotrixError, isProtocolError, makeMdxpError, } from './errors.js';
5
+ export { Methods, Notifications } from './methods.js';
6
+ // Schemas (for callers that want runtime validation)
7
+ export * from './schemas/index.js';
8
+ // Tool registry / AI-agent tool catalog
9
+ export { SERVER_INITIATED_METHODS, Tools, toAgentToolCatalog, } from './tools.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,wEAAwE;AAOxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD,OAAO,EACL,UAAU,EACV,aAAa,EACb,eAAe,EACf,aAAa,GACd,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAErD,qDAAqD;AACrD,cAAc,oBAAoB,CAAA;AAGlC,wCAAwC;AACxC,OAAO,EACL,wBAAwB,EACxB,KAAK,EACL,kBAAkB,GACnB,MAAM,YAAY,CAAA"}
@@ -0,0 +1,28 @@
1
+ export declare const Methods: Readonly<{
2
+ readonly MotrixInitialize: "motrix/initialize";
3
+ readonly DownloadSubmit: "download/submit";
4
+ readonly DownloadCancel: "download/cancel";
5
+ readonly UrlProbe: "url/probe";
6
+ readonly UrlResolve: "url/resolve";
7
+ readonly SystemPing: "system/ping";
8
+ readonly DownloadAdd: "download/add";
9
+ readonly TaskList: "task/list";
10
+ readonly TaskGet: "task/get";
11
+ readonly TaskPause: "task/pause";
12
+ readonly TaskResume: "task/resume";
13
+ readonly TaskRemove: "task/remove";
14
+ readonly StatsGet: "stats/get";
15
+ readonly EngineStatus: "engine/status";
16
+ }>;
17
+ export type Method = (typeof Methods)[keyof typeof Methods];
18
+ export declare const Notifications: Readonly<{
19
+ readonly MotrixInitialized: "motrix/initialized";
20
+ readonly TaskProgress: "$/task/progress";
21
+ readonly TaskCompleted: "$/task/completed";
22
+ readonly TaskError: "$/task/error";
23
+ readonly PairRevoked: "$/pair/revoked";
24
+ readonly CancelRequest: "$/cancelRequest";
25
+ readonly StatsUpdate: "$/stats";
26
+ }>;
27
+ export type Notification = (typeof Notifications)[keyof typeof Notifications];
28
+ //# sourceMappingURL=methods.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.d.ts","sourceRoot":"","sources":["../src/methods.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;EAgBT,CAAA;AAEX,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,OAAO,OAAO,CAAC,CAAA;AAK3D,eAAO,MAAM,aAAa;;;;;;;;EASf,CAAA;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAA"}
@@ -0,0 +1,32 @@
1
+ // MDXP method names (request/response) — see docs/01-protocol-mdxp.md §6
2
+ export const Methods = Object.freeze({
3
+ MotrixInitialize: 'motrix/initialize',
4
+ DownloadSubmit: 'download/submit',
5
+ DownloadCancel: 'download/cancel',
6
+ UrlProbe: 'url/probe',
7
+ UrlResolve: 'url/resolve',
8
+ SystemPing: 'system/ping',
9
+ // v1 control-plane (Spec 2)
10
+ DownloadAdd: 'download/add',
11
+ TaskList: 'task/list',
12
+ TaskGet: 'task/get',
13
+ TaskPause: 'task/pause',
14
+ TaskResume: 'task/resume',
15
+ TaskRemove: 'task/remove',
16
+ StatsGet: 'stats/get',
17
+ EngineStatus: 'engine/status',
18
+ });
19
+ // MDXP notification names — see docs/01-protocol-mdxp.md §7.
20
+ // `motrix/initialized` follows LSP convention (no $/ prefix because it's
21
+ // a one-way handshake, not a protocol meta-event).
22
+ export const Notifications = Object.freeze({
23
+ MotrixInitialized: 'motrix/initialized',
24
+ TaskProgress: '$/task/progress',
25
+ TaskCompleted: '$/task/completed',
26
+ TaskError: '$/task/error',
27
+ PairRevoked: '$/pair/revoked',
28
+ CancelRequest: '$/cancelRequest',
29
+ // v1 control-plane (Spec 2): periodic aggregate stats push.
30
+ StatsUpdate: '$/stats',
31
+ });
32
+ //# sourceMappingURL=methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"methods.js","sourceRoot":"","sources":["../src/methods.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,gBAAgB,EAAE,mBAAmB;IACrC,cAAc,EAAE,iBAAiB;IACjC,cAAc,EAAE,iBAAiB;IACjC,QAAQ,EAAE,WAAW;IACrB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,aAAa;IACzB,4BAA4B;IAC5B,WAAW,EAAE,cAAc;IAC3B,QAAQ,EAAE,WAAW;IACrB,OAAO,EAAE,UAAU;IACnB,SAAS,EAAE,YAAY;IACvB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,aAAa;IACzB,QAAQ,EAAE,WAAW;IACrB,YAAY,EAAE,eAAe;CACrB,CAAC,CAAA;AAIX,6DAA6D;AAC7D,yEAAyE;AACzE,mDAAmD;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,iBAAiB,EAAE,oBAAoB;IACvC,YAAY,EAAE,iBAAiB;IAC/B,aAAa,EAAE,kBAAkB;IACjC,SAAS,EAAE,cAAc;IACzB,WAAW,EAAE,gBAAgB;IAC7B,aAAa,EAAE,iBAAiB;IAChC,4DAA4D;IAC5D,WAAW,EAAE,SAAS;CACd,CAAC,CAAA"}
package/dist/node.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import 'vscode-jsonrpc/node';
2
+ export * from './index.js';
3
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAYA,OAAO,qBAAqB,CAAA;AAE5B,cAAc,YAAY,CAAA"}
package/dist/node.js ADDED
@@ -0,0 +1,15 @@
1
+ // Node platform entry.
2
+ //
3
+ // vscode-jsonrpc v9 split the runtime abstraction layer (RAL) out of the bare
4
+ // `vscode-jsonrpc` entry: creating/listening on a `MessageConnection` now
5
+ // requires a platform RAL to be installed first. Importing this module installs
6
+ // the Node RAL into the SAME `vscode-jsonrpc` instance that this package's
7
+ // `createMdxpConnection` resolves, so it is immune to duplicate-instance issues
8
+ // across linked workspaces.
9
+ //
10
+ // A Node host (e.g. Motrix Turbo's bridge) only needs `import '@motrix/mdxp/node'`
11
+ // once at bootstrap. The full public API is re-exported for convenience, so
12
+ // `import { createMdxpConnection } from '@motrix/mdxp/node'` also works.
13
+ import 'vscode-jsonrpc/node';
14
+ export * from './index.js';
15
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,gFAAgF;AAChF,2EAA2E;AAC3E,gFAAgF;AAChF,4BAA4B;AAC5B,EAAE;AACF,mFAAmF;AACnF,4EAA4E;AAC5E,yEAAyE;AACzE,OAAO,qBAAqB,CAAA;AAE5B,cAAc,YAAY,CAAA"}
@@ -0,0 +1,72 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * URL-shaped public "add a download" params — distinct from the browser-page
4
+ * `download/submit`. Discriminated on `kind`; strict variants so an agent's
5
+ * typo is loudly rejected rather than silently dropped. The host maps this onto
6
+ * its native taskCreateRequest in Spec 4.
7
+ */
8
+ export declare const DownloadAddParamsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
9
+ kind: z.ZodLiteral<"url">;
10
+ saveDir: z.ZodString;
11
+ uris: z.ZodArray<z.ZodString>;
12
+ filename: z.ZodOptional<z.ZodString>;
13
+ headers: z.ZodOptional<z.ZodArray<z.ZodObject<{
14
+ name: z.ZodString;
15
+ value: z.ZodString;
16
+ }, z.core.$strip>>>;
17
+ connections: z.ZodOptional<z.ZodNumber>;
18
+ proxy: z.ZodOptional<z.ZodString>;
19
+ }, z.core.$strict>, z.ZodObject<{
20
+ kind: z.ZodLiteral<"magnet">;
21
+ saveDir: z.ZodString;
22
+ uri: z.ZodString;
23
+ selectedFiles: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
24
+ }, z.core.$strict>, z.ZodObject<{
25
+ kind: z.ZodLiteral<"torrent">;
26
+ saveDir: z.ZodString;
27
+ base64: z.ZodString;
28
+ selectedFiles: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
29
+ displayName: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$strict>], "kind">;
31
+ /** Result is the created task snapshot so callers render without polling. */
32
+ export declare const DownloadAddResultSchema: z.ZodObject<{
33
+ id: z.ZodString;
34
+ type: z.ZodEnum<{
35
+ magnet: "magnet";
36
+ http: "http";
37
+ ftp: "ftp";
38
+ bt: "bt";
39
+ metalink: "metalink";
40
+ }>;
41
+ name: z.ZodString;
42
+ status: z.ZodEnum<{
43
+ error: "error";
44
+ queued: "queued";
45
+ fetching_metadata: "fetching_metadata";
46
+ downloading: "downloading";
47
+ paused: "paused";
48
+ seeding: "seeding";
49
+ finalizing: "finalizing";
50
+ completed: "completed";
51
+ }>;
52
+ progress: z.ZodNumber;
53
+ bytesDone: z.ZodNumber;
54
+ bytesTotal: z.ZodNullable<z.ZodNumber>;
55
+ speedBps: z.ZodNumber;
56
+ etaSec: z.ZodNullable<z.ZodNumber>;
57
+ saveDir: z.ZodString;
58
+ error: z.ZodNullable<z.ZodString>;
59
+ createdAt: z.ZodNumber;
60
+ finishedAt: z.ZodNullable<z.ZodNumber>;
61
+ finalPath: z.ZodNullable<z.ZodString>;
62
+ infoHash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
63
+ bt: z.ZodOptional<z.ZodObject<{
64
+ peers: z.ZodNumber;
65
+ seeds: z.ZodNumber;
66
+ ratio: z.ZodNumber;
67
+ trackers: z.ZodArray<z.ZodString>;
68
+ }, z.core.$strip>>;
69
+ }, z.core.$strip>;
70
+ export type DownloadAddParams = z.infer<typeof DownloadAddParamsSchema>;
71
+ export type DownloadAddResult = z.infer<typeof DownloadAddResultSchema>;
72
+ //# sourceMappingURL=download-add.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-add.d.ts","sourceRoot":"","sources":["../../src/schemas/download-add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAmBvB;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;4BAuBlC,CAAA;AAEF,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAiB,CAAA;AAErD,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AACvE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { z } from 'zod';
2
+ import { MdxpTaskSchema } from './task.js';
3
+ const HttpHeaderSchema = z.object({ name: z.string(), value: z.string() });
4
+ /**
5
+ * Network download schemes allowed on the public, agent-facing `download/add`
6
+ * surface. Pinned at the contract boundary so an LLM-callable tool can never
7
+ * be coerced into `file://` (local file read / path traversal), `javascript:`,
8
+ * `data:`, etc. — independent of whatever the host handler does later.
9
+ */
10
+ const SAFE_DOWNLOAD_URL = /^(https?|ftps?|sftp):\/\//i;
11
+ const safeDownloadUrl = z
12
+ .string()
13
+ .url()
14
+ .refine((u) => SAFE_DOWNLOAD_URL.test(u), {
15
+ message: 'unsupported URL scheme (allowed: http, https, ftp, ftps, sftp)',
16
+ });
17
+ /**
18
+ * URL-shaped public "add a download" params — distinct from the browser-page
19
+ * `download/submit`. Discriminated on `kind`; strict variants so an agent's
20
+ * typo is loudly rejected rather than silently dropped. The host maps this onto
21
+ * its native taskCreateRequest in Spec 4.
22
+ */
23
+ export const DownloadAddParamsSchema = z.discriminatedUnion('kind', [
24
+ z.strictObject({
25
+ kind: z.literal('url'),
26
+ saveDir: z.string().min(1),
27
+ uris: z.array(safeDownloadUrl).min(1),
28
+ filename: z.string().optional(),
29
+ headers: z.array(HttpHeaderSchema).optional(),
30
+ connections: z.number().int().min(1).max(128).optional(),
31
+ proxy: z.string().optional(),
32
+ }),
33
+ z.strictObject({
34
+ kind: z.literal('magnet'),
35
+ saveDir: z.string().min(1),
36
+ uri: z.string().startsWith('magnet:?'),
37
+ selectedFiles: z.array(z.number().int().nonnegative()).optional(),
38
+ }),
39
+ z.strictObject({
40
+ kind: z.literal('torrent'),
41
+ saveDir: z.string().min(1),
42
+ base64: z.string().min(1),
43
+ selectedFiles: z.array(z.number().int().nonnegative()).optional(),
44
+ displayName: z.string().optional(),
45
+ }),
46
+ ]);
47
+ /** Result is the created task snapshot so callers render without polling. */
48
+ export const DownloadAddResultSchema = MdxpTaskSchema;
49
+ //# sourceMappingURL=download-add.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-add.js","sourceRoot":"","sources":["../../src/schemas/download-add.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,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