scoutline 0.1.0 → 0.6.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 (242) hide show
  1. package/README.md +394 -7
  2. package/bin/scoutline.js +36 -15
  3. package/dist/capabilities/diagnostics.d.ts +135 -0
  4. package/dist/capabilities/diagnostics.d.ts.map +1 -0
  5. package/dist/capabilities/diagnostics.js +139 -0
  6. package/dist/capabilities/diagnostics.js.map +1 -0
  7. package/dist/capabilities/quota.d.ts +99 -0
  8. package/dist/capabilities/quota.d.ts.map +1 -0
  9. package/dist/capabilities/quota.js +129 -0
  10. package/dist/capabilities/quota.js.map +1 -0
  11. package/dist/capabilities/reader.d.ts +227 -0
  12. package/dist/capabilities/reader.d.ts.map +1 -0
  13. package/dist/capabilities/reader.js +100 -0
  14. package/dist/capabilities/reader.js.map +1 -0
  15. package/dist/capabilities/repository.d.ts +221 -0
  16. package/dist/capabilities/repository.d.ts.map +1 -0
  17. package/dist/capabilities/repository.js +172 -0
  18. package/dist/capabilities/repository.js.map +1 -0
  19. package/dist/capabilities/search.d.ts +110 -0
  20. package/dist/capabilities/search.d.ts.map +1 -0
  21. package/dist/capabilities/search.js +21 -0
  22. package/dist/capabilities/search.js.map +1 -0
  23. package/dist/capabilities/vision.d.ts +156 -0
  24. package/dist/capabilities/vision.d.ts.map +1 -0
  25. package/dist/capabilities/vision.js +111 -0
  26. package/dist/capabilities/vision.js.map +1 -0
  27. package/dist/command-invocation.d.ts +58 -0
  28. package/dist/command-invocation.d.ts.map +1 -0
  29. package/dist/command-invocation.js +95 -0
  30. package/dist/command-invocation.js.map +1 -0
  31. package/dist/commands/cache.d.ts +106 -0
  32. package/dist/commands/cache.d.ts.map +1 -0
  33. package/dist/commands/cache.js +203 -0
  34. package/dist/commands/cache.js.map +1 -0
  35. package/dist/commands/code.d.ts +11 -4
  36. package/dist/commands/code.d.ts.map +1 -1
  37. package/dist/commands/code.js +16 -42
  38. package/dist/commands/code.js.map +1 -1
  39. package/dist/commands/doctor.d.ts +69 -3
  40. package/dist/commands/doctor.d.ts.map +1 -1
  41. package/dist/commands/doctor.js +179 -52
  42. package/dist/commands/doctor.js.map +1 -1
  43. package/dist/commands/quota.d.ts +45 -3
  44. package/dist/commands/quota.d.ts.map +1 -1
  45. package/dist/commands/quota.js +116 -60
  46. package/dist/commands/quota.js.map +1 -1
  47. package/dist/commands/read.d.ts +76 -2
  48. package/dist/commands/read.d.ts.map +1 -1
  49. package/dist/commands/read.js +260 -121
  50. package/dist/commands/read.js.map +1 -1
  51. package/dist/commands/repo.d.ts +55 -4
  52. package/dist/commands/repo.d.ts.map +1 -1
  53. package/dist/commands/repo.js +115 -172
  54. package/dist/commands/repo.js.map +1 -1
  55. package/dist/commands/repository-explorer.d.ts +147 -0
  56. package/dist/commands/repository-explorer.d.ts.map +1 -0
  57. package/dist/commands/repository-explorer.js +550 -0
  58. package/dist/commands/repository-explorer.js.map +1 -0
  59. package/dist/commands/search.d.ts +27 -2
  60. package/dist/commands/search.d.ts.map +1 -1
  61. package/dist/commands/search.js +95 -103
  62. package/dist/commands/search.js.map +1 -1
  63. package/dist/commands/tools.d.ts +9 -3
  64. package/dist/commands/tools.d.ts.map +1 -1
  65. package/dist/commands/tools.js +29 -59
  66. package/dist/commands/tools.js.map +1 -1
  67. package/dist/commands/vision.d.ts +35 -9
  68. package/dist/commands/vision.d.ts.map +1 -1
  69. package/dist/commands/vision.js +184 -131
  70. package/dist/commands/vision.js.map +1 -1
  71. package/dist/index.d.ts +62 -1
  72. package/dist/index.d.ts.map +1 -1
  73. package/dist/index.js +580 -223
  74. package/dist/index.js.map +1 -1
  75. package/dist/lib/cache.d.ts +178 -12
  76. package/dist/lib/cache.d.ts.map +1 -1
  77. package/dist/lib/cache.js +377 -39
  78. package/dist/lib/cache.js.map +1 -1
  79. package/dist/lib/code-mode.d.ts +13 -0
  80. package/dist/lib/code-mode.d.ts.map +1 -1
  81. package/dist/lib/code-mode.js +26 -6
  82. package/dist/lib/code-mode.js.map +1 -1
  83. package/dist/lib/config.d.ts.map +1 -1
  84. package/dist/lib/config.js +15 -18
  85. package/dist/lib/config.js.map +1 -1
  86. package/dist/lib/errors.d.ts +89 -11
  87. package/dist/lib/errors.d.ts.map +1 -1
  88. package/dist/lib/errors.js +168 -21
  89. package/dist/lib/errors.js.map +1 -1
  90. package/dist/lib/execution.d.ts +190 -0
  91. package/dist/lib/execution.d.ts.map +1 -0
  92. package/dist/lib/execution.js +383 -0
  93. package/dist/lib/execution.js.map +1 -0
  94. package/dist/lib/index.d.ts +10 -2
  95. package/dist/lib/index.d.ts.map +1 -1
  96. package/dist/lib/index.js +10 -2
  97. package/dist/lib/index.js.map +1 -1
  98. package/dist/lib/mcp-client.d.ts +75 -16
  99. package/dist/lib/mcp-client.d.ts.map +1 -1
  100. package/dist/lib/mcp-client.js +173 -108
  101. package/dist/lib/mcp-client.js.map +1 -1
  102. package/dist/lib/mcp-config.d.ts +17 -0
  103. package/dist/lib/mcp-config.d.ts.map +1 -1
  104. package/dist/lib/mcp-config.js +29 -0
  105. package/dist/lib/mcp-config.js.map +1 -1
  106. package/dist/lib/monitor-client.d.ts +17 -3
  107. package/dist/lib/monitor-client.d.ts.map +1 -1
  108. package/dist/lib/monitor-client.js +23 -69
  109. package/dist/lib/monitor-client.js.map +1 -1
  110. package/dist/lib/output.d.ts +53 -7
  111. package/dist/lib/output.d.ts.map +1 -1
  112. package/dist/lib/output.js +126 -39
  113. package/dist/lib/output.js.map +1 -1
  114. package/dist/lib/redact.d.ts +62 -3
  115. package/dist/lib/redact.d.ts.map +1 -1
  116. package/dist/lib/redact.js +165 -31
  117. package/dist/lib/redact.js.map +1 -1
  118. package/dist/lib/tool-cache.d.ts +86 -0
  119. package/dist/lib/tool-cache.d.ts.map +1 -0
  120. package/dist/lib/tool-cache.js +123 -0
  121. package/dist/lib/tool-cache.js.map +1 -0
  122. package/dist/lib/tty.d.ts +7 -20
  123. package/dist/lib/tty.d.ts.map +1 -1
  124. package/dist/lib/tty.js +51 -30
  125. package/dist/lib/tty.js.map +1 -1
  126. package/dist/node-command-invocation-adapter.d.ts +28 -0
  127. package/dist/node-command-invocation-adapter.d.ts.map +1 -0
  128. package/dist/node-command-invocation-adapter.js +88 -0
  129. package/dist/node-command-invocation-adapter.js.map +1 -0
  130. package/dist/providers/minimax/adapter.d.ts +49 -0
  131. package/dist/providers/minimax/adapter.d.ts.map +1 -0
  132. package/dist/providers/minimax/adapter.js +450 -0
  133. package/dist/providers/minimax/adapter.js.map +1 -0
  134. package/dist/providers/minimax/coding-plan-client.d.ts +60 -0
  135. package/dist/providers/minimax/coding-plan-client.d.ts.map +1 -0
  136. package/dist/providers/minimax/coding-plan-client.js +204 -0
  137. package/dist/providers/minimax/coding-plan-client.js.map +1 -0
  138. package/dist/providers/minimax/config.d.ts +32 -0
  139. package/dist/providers/minimax/config.d.ts.map +1 -0
  140. package/dist/providers/minimax/config.js +84 -0
  141. package/dist/providers/minimax/config.js.map +1 -0
  142. package/dist/providers/minimax/media.d.ts +88 -0
  143. package/dist/providers/minimax/media.d.ts.map +1 -0
  144. package/dist/providers/minimax/media.js +232 -0
  145. package/dist/providers/minimax/media.js.map +1 -0
  146. package/dist/providers/minimax/quota-client.d.ts +44 -0
  147. package/dist/providers/minimax/quota-client.d.ts.map +1 -0
  148. package/dist/providers/minimax/quota-client.js +83 -0
  149. package/dist/providers/minimax/quota-client.js.map +1 -0
  150. package/dist/providers/minimax/quota.d.ts +48 -0
  151. package/dist/providers/minimax/quota.d.ts.map +1 -0
  152. package/dist/providers/minimax/quota.js +120 -0
  153. package/dist/providers/minimax/quota.js.map +1 -0
  154. package/dist/providers/minimax/sdk-client.d.ts +29 -0
  155. package/dist/providers/minimax/sdk-client.d.ts.map +1 -0
  156. package/dist/providers/minimax/sdk-client.js +50 -0
  157. package/dist/providers/minimax/sdk-client.js.map +1 -0
  158. package/dist/providers/minimax/vision-attestations.d.ts +52 -0
  159. package/dist/providers/minimax/vision-attestations.d.ts.map +1 -0
  160. package/dist/providers/minimax/vision-attestations.js +79 -0
  161. package/dist/providers/minimax/vision-attestations.js.map +1 -0
  162. package/dist/providers/minimax/vision-conformance.d.ts +186 -0
  163. package/dist/providers/minimax/vision-conformance.d.ts.map +1 -0
  164. package/dist/providers/minimax/vision-conformance.js +371 -0
  165. package/dist/providers/minimax/vision-conformance.js.map +1 -0
  166. package/dist/providers/minimax/vision-mappings/chart.d.ts +35 -0
  167. package/dist/providers/minimax/vision-mappings/chart.d.ts.map +1 -0
  168. package/dist/providers/minimax/vision-mappings/chart.js +55 -0
  169. package/dist/providers/minimax/vision-mappings/chart.js.map +1 -0
  170. package/dist/providers/minimax/vision-mappings/common.d.ts +60 -0
  171. package/dist/providers/minimax/vision-mappings/common.d.ts.map +1 -0
  172. package/dist/providers/minimax/vision-mappings/common.js +75 -0
  173. package/dist/providers/minimax/vision-mappings/common.js.map +1 -0
  174. package/dist/providers/minimax/vision-mappings/diagnose-error.d.ts +35 -0
  175. package/dist/providers/minimax/vision-mappings/diagnose-error.d.ts.map +1 -0
  176. package/dist/providers/minimax/vision-mappings/diagnose-error.js +55 -0
  177. package/dist/providers/minimax/vision-mappings/diagnose-error.js.map +1 -0
  178. package/dist/providers/minimax/vision-mappings/diagram.d.ts +35 -0
  179. package/dist/providers/minimax/vision-mappings/diagram.d.ts.map +1 -0
  180. package/dist/providers/minimax/vision-mappings/diagram.js +55 -0
  181. package/dist/providers/minimax/vision-mappings/diagram.js.map +1 -0
  182. package/dist/providers/minimax/vision-mappings/extract-text.d.ts +35 -0
  183. package/dist/providers/minimax/vision-mappings/extract-text.d.ts.map +1 -0
  184. package/dist/providers/minimax/vision-mappings/extract-text.js +55 -0
  185. package/dist/providers/minimax/vision-mappings/extract-text.js.map +1 -0
  186. package/dist/providers/minimax/vision-mappings/ui-artifact.d.ts +35 -0
  187. package/dist/providers/minimax/vision-mappings/ui-artifact.d.ts.map +1 -0
  188. package/dist/providers/minimax/vision-mappings/ui-artifact.js +69 -0
  189. package/dist/providers/minimax/vision-mappings/ui-artifact.js.map +1 -0
  190. package/dist/providers/minimax/vision-mappings.generated.d.ts +29 -0
  191. package/dist/providers/minimax/vision-mappings.generated.d.ts.map +1 -0
  192. package/dist/providers/minimax/vision-mappings.generated.js +29 -0
  193. package/dist/providers/minimax/vision-mappings.generated.js.map +1 -0
  194. package/dist/providers/minimax/vision-revisions.d.ts +29 -0
  195. package/dist/providers/minimax/vision-revisions.d.ts.map +1 -0
  196. package/dist/providers/minimax/vision-revisions.js +34 -0
  197. package/dist/providers/minimax/vision-revisions.js.map +1 -0
  198. package/dist/providers/registry.d.ts +36 -0
  199. package/dist/providers/registry.d.ts.map +1 -0
  200. package/dist/providers/registry.js +45 -0
  201. package/dist/providers/registry.js.map +1 -0
  202. package/dist/providers/selection.d.ts +44 -0
  203. package/dist/providers/selection.d.ts.map +1 -0
  204. package/dist/providers/selection.js +85 -0
  205. package/dist/providers/selection.js.map +1 -0
  206. package/dist/providers/types.d.ts +281 -0
  207. package/dist/providers/types.d.ts.map +1 -0
  208. package/dist/providers/types.js +127 -0
  209. package/dist/providers/types.js.map +1 -0
  210. package/dist/providers/zai/adapter.d.ts +35 -0
  211. package/dist/providers/zai/adapter.d.ts.map +1 -0
  212. package/dist/providers/zai/adapter.js +685 -0
  213. package/dist/providers/zai/adapter.js.map +1 -0
  214. package/dist/providers/zai/credentials.d.ts +38 -0
  215. package/dist/providers/zai/credentials.d.ts.map +1 -0
  216. package/dist/providers/zai/credentials.js +60 -0
  217. package/dist/providers/zai/credentials.js.map +1 -0
  218. package/dist/providers/zai/encoded-error.d.ts +90 -0
  219. package/dist/providers/zai/encoded-error.d.ts.map +1 -0
  220. package/dist/providers/zai/encoded-error.js +169 -0
  221. package/dist/providers/zai/encoded-error.js.map +1 -0
  222. package/dist/providers/zai/media.d.ts +38 -0
  223. package/dist/providers/zai/media.d.ts.map +1 -0
  224. package/dist/providers/zai/media.js +107 -0
  225. package/dist/providers/zai/media.js.map +1 -0
  226. package/dist/providers/zai/monitor-client.d.ts +53 -0
  227. package/dist/providers/zai/monitor-client.d.ts.map +1 -0
  228. package/dist/providers/zai/monitor-client.js +117 -0
  229. package/dist/providers/zai/monitor-client.js.map +1 -0
  230. package/dist/providers/zai/quota.d.ts +47 -0
  231. package/dist/providers/zai/quota.d.ts.map +1 -0
  232. package/dist/providers/zai/quota.js +127 -0
  233. package/dist/providers/zai/quota.js.map +1 -0
  234. package/dist/providers/zai/reader.d.ts +82 -0
  235. package/dist/providers/zai/reader.d.ts.map +1 -0
  236. package/dist/providers/zai/reader.js +490 -0
  237. package/dist/providers/zai/reader.js.map +1 -0
  238. package/dist/providers/zai/repository.d.ts +76 -0
  239. package/dist/providers/zai/repository.d.ts.map +1 -0
  240. package/dist/providers/zai/repository.js +715 -0
  241. package/dist/providers/zai/repository.js.map +1 -0
  242. package/package.json +11 -6
@@ -0,0 +1,232 @@
1
+ /**
2
+ * MiniMax Provider Media Module (DESIGN.md §9 — P3-02).
3
+ *
4
+ * Owns MiniMax-local image media facts: accepted extensions, size limit,
5
+ * existence check, and absolute-path resolution. Commands pass raw
6
+ * path-or-URL strings; this module is the single owner of every
7
+ * Provider-specific media decision for MiniMax images.
8
+ *
9
+ * Boundary rules (ARCHITECTURE.md §2):
10
+ * - May import normalized errors from `lib/errors.ts` and the shared
11
+ * `ProviderQuotaFetch` port from `providers/types.ts` (HTTP-source
12
+ * image fetch only).
13
+ * - Content reads happen here, in the Adapter-local media Module,
14
+ * since the SDK no longer performs data-URI conversion. The Module
15
+ * owns every MiniMax image fact: accepted extensions, size limit,
16
+ * existence check, absolute-path resolution, MIME detection, and
17
+ * base64 conversion.
18
+ *
19
+ * Media rules (DESIGN.md §9 MiniMax Transitional SDK):
20
+ * - Local image: JPG, JPEG, PNG, WebP (case-insensitive), at most 50 MiB.
21
+ * - HTTP(S) source is accepted.
22
+ * - Local source becomes an absolute path after validation.
23
+ * - `convertToDataUri` performs data-URI conversion for HTTP sources
24
+ * (fetched bytes) and local paths (read bytes); `data:` URIs pass
25
+ * through unchanged.
26
+ * - No MiniMax video media module exists in this scope.
27
+ * - Missing local file rejects with `FILE_ERROR`.
28
+ * - Non-HTTP URL-like strings and unsupported extensions reject with
29
+ * `VALIDATION_ERROR` and Provider-specific supported-format help.
30
+ */
31
+ import * as fs from "node:fs";
32
+ import { readFile } from "node:fs/promises";
33
+ import * as path from "node:path";
34
+ import { ApiError, FileError, NetworkError, TimeoutError, ValidationError, } from "../../lib/errors.js";
35
+ // ---------------------------------------------------------------------------
36
+ // MiniMax media limits (DESIGN.md §9)
37
+ // ---------------------------------------------------------------------------
38
+ const MINIMAX_IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png", ".webp"];
39
+ const MINIMAX_MAX_IMAGE_BYTES = 50 * 1024 * 1024; // 50 MiB
40
+ const MINIMAX_IMAGE_FORMAT_HELP = "Supported MiniMax image formats: JPG, JPEG, PNG, WebP (max 50 MiB)";
41
+ /**
42
+ * HTTP image-fetch timeout in milliseconds (DESIGN.md §9, critique G2).
43
+ * Matches the SDK's effective default (`config.timeout * 1000`,
44
+ * `config.timeout = 300` → 30 s). Local files are NOT bound by this
45
+ * timeout — already validated synchronously by `resolveImageSource`
46
+ * via `fs.statSync`, so a slow disk read is not a real risk here.
47
+ */
48
+ export const MINIMAX_IMAGE_FETCH_TIMEOUT_MS = 30000;
49
+ /**
50
+ * Local-file extension → MIME mapping for `convertToDataUri` (critique
51
+ * G1). Mirrors the SDK's `IMAGE_MIME_TYPES` table at
52
+ * `mmx-cli/dist/sdk.mjs:1581-1586` exactly. The extension has already
53
+ * been validated against `MINIMAX_IMAGE_EXTENSIONS` by
54
+ * `resolveImageSource`, so a missing entry is not expected at this
55
+ * layer (we still fall back to `image/jpeg` defensively, matching SDK).
56
+ */
57
+ export const MINIMAX_IMAGE_MIME_BY_EXTENSION = {
58
+ ".jpg": "image/jpeg",
59
+ ".jpeg": "image/jpeg",
60
+ ".png": "image/png",
61
+ ".webp": "image/webp",
62
+ };
63
+ // ---------------------------------------------------------------------------
64
+ // Source classification
65
+ // ---------------------------------------------------------------------------
66
+ /**
67
+ * A leading `<scheme>://` that is NOT `http(s)://` (e.g. `ftp://`, `file://`)
68
+ * is a URL-like string MiniMax cannot consume. It is rejected up front with
69
+ * `VALIDATION_ERROR` rather than falling through to a misleading local-file
70
+ * `FILE_ERROR`.
71
+ */
72
+ const URL_SCHEME_PATTERN = /^[a-z][a-z0-9+.-]*:\/\//i;
73
+ function classifySource(source) {
74
+ if (source.startsWith("http://") || source.startsWith("https://")) {
75
+ return "http";
76
+ }
77
+ if (URL_SCHEME_PATTERN.test(source)) {
78
+ return "unsupported-url";
79
+ }
80
+ return "local";
81
+ }
82
+ // ---------------------------------------------------------------------------
83
+ // Local media validation (existence + size + extension; never reads content)
84
+ // ---------------------------------------------------------------------------
85
+ function validateLocalImage(source) {
86
+ const resolved = path.resolve(source);
87
+ if (!fs.existsSync(resolved)) {
88
+ throw new FileError(`File not found: ${source}`, "Check the file path is correct");
89
+ }
90
+ const stats = fs.statSync(resolved);
91
+ if (stats.size > MINIMAX_MAX_IMAGE_BYTES) {
92
+ throw new ValidationError(`File exceeds the ${(MINIMAX_MAX_IMAGE_BYTES / 1024 / 1024).toFixed(0)} MiB limit ` +
93
+ `(${(stats.size / 1024 / 1024).toFixed(2)} MiB)`, MINIMAX_IMAGE_FORMAT_HELP);
94
+ }
95
+ const ext = path.extname(resolved).toLowerCase();
96
+ if (!MINIMAX_IMAGE_EXTENSIONS.includes(ext)) {
97
+ throw new ValidationError(`Unsupported media format: ${ext || "(no extension)"}`, MINIMAX_IMAGE_FORMAT_HELP);
98
+ }
99
+ return resolved;
100
+ }
101
+ // ---------------------------------------------------------------------------
102
+ // Public resolver
103
+ // ---------------------------------------------------------------------------
104
+ /**
105
+ * Resolve a MiniMax image source into the value the MiniMax SDK consumes.
106
+ * For a local file, validates existence, size (≤ 50 MiB), and extension
107
+ * (JPG/JPEG/PNG/WebP) and returns the absolute path (the SDK performs
108
+ * data-URI conversion from this path). For an HTTP(S) URL, returns the URL
109
+ * unchanged without touching the local filesystem.
110
+ */
111
+ export function resolveImageSource(source) {
112
+ const kind = classifySource(source);
113
+ if (kind === "http")
114
+ return source;
115
+ if (kind === "unsupported-url") {
116
+ throw new ValidationError(`Unsupported source scheme for MiniMax vision`, "Use an HTTP(S) URL or a local file path");
117
+ }
118
+ return validateLocalImage(source);
119
+ }
120
+ // ---------------------------------------------------------------------------
121
+ // MIME detection from HTTP Content-Type (critique G1)
122
+ // ---------------------------------------------------------------------------
123
+ /**
124
+ * Map an HTTP `Content-Type` header to a MiniMax image MIME.
125
+ *
126
+ * Rules (mirror SDK behaviour at `sdk.mjs:1601-1602`, critique G1):
127
+ * - Missing/null → `image/jpeg` (SDK default).
128
+ * - Strip `;`-introduced parameters, then trim and lowercase.
129
+ * - Match `image/jpeg` or `image/jpg` → `image/jpeg`.
130
+ * - Match `image/png` → `image/png`.
131
+ * - Match `image/webp` → `image/webp`.
132
+ * - Anything else (e.g. `application/octet-stream`, an unrecognised
133
+ * vendor type) → `image/jpeg` (SDK default).
134
+ */
135
+ function detectMimeFromContentType(contentType) {
136
+ if (!contentType)
137
+ return "image/jpeg";
138
+ const base = contentType.split(";")[0].trim().toLowerCase();
139
+ if (base === "image/jpeg" || base === "image/jpg")
140
+ return "image/jpeg";
141
+ if (base === "image/png")
142
+ return "image/png";
143
+ if (base === "image/webp")
144
+ return "image/webp";
145
+ return "image/jpeg";
146
+ }
147
+ /**
148
+ * Convert a MiniMax image source into the `data:<mime>;base64,...` form
149
+ * the MiniMax VLM endpoint consumes. Three branches:
150
+ *
151
+ * 1. `data:` prefix → returned unchanged.
152
+ * 2. `http(s)://` → bytes fetched via injected `fetch` with an
153
+ * `AbortController` timed out by `MINIMAX_IMAGE_FETCH_TIMEOUT_MS`,
154
+ * MIME detected via `detectMimeFromContentType`, base64-encoded.
155
+ * The 50 MiB cap (`MINIMAX_MAX_IMAGE_BYTES`) is enforced on the
156
+ * fetched byte length.
157
+ * 3. Local path → bytes read via `node:fs/promises`, MIME from
158
+ * `MINIMAX_IMAGE_MIME_BY_EXTENSION`. The path has already been
159
+ * validated (existence, size, extension) by `resolveImageSource`,
160
+ * so this branch trusts the prior validation.
161
+ *
162
+ * The HTTP branch mirrors the abort/timeout + injected-fetch +
163
+ * injected-setTimeout pattern from `quota-client.ts` so the same test
164
+ * fixtures drive both transports.
165
+ */
166
+ export async function convertToDataUri(source, deps = {}) {
167
+ // 1. data: passthrough.
168
+ if (source.startsWith("data:")) {
169
+ return source;
170
+ }
171
+ // 2. http(s):// fetch.
172
+ if (source.startsWith("http://") || source.startsWith("https://")) {
173
+ return await fetchHttpImageAsDataUri(source, deps);
174
+ }
175
+ // 3. Local path — extension already validated by resolveImageSource.
176
+ return await readLocalImageAsDataUri(source);
177
+ }
178
+ async function fetchHttpImageAsDataUri(source, deps) {
179
+ const f = deps.fetch ?? fetch;
180
+ const setT = deps.setTimeout ?? setTimeout;
181
+ const clearT = deps.clearTimeout ?? clearTimeout;
182
+ const timeoutMs = MINIMAX_IMAGE_FETCH_TIMEOUT_MS;
183
+ const controller = new AbortController();
184
+ const timeoutId = setT(() => controller.abort(), timeoutMs);
185
+ try {
186
+ const res = await f(source, {
187
+ method: "GET",
188
+ signal: controller.signal,
189
+ });
190
+ clearT(timeoutId);
191
+ if (!res.ok) {
192
+ await res.text().catch(() => { });
193
+ throw new ApiError(`Failed to download image: HTTP ${res.status}`, res.status);
194
+ }
195
+ const contentType = res.headers.get("content-type");
196
+ const mime = detectMimeFromContentType(contentType);
197
+ const buf = await res.arrayBuffer();
198
+ if (buf.byteLength > MINIMAX_MAX_IMAGE_BYTES) {
199
+ throw new ValidationError(`Image too large (${(buf.byteLength / 1024 / 1024).toFixed(2)} MiB). ` +
200
+ `Maximum is ${(MINIMAX_MAX_IMAGE_BYTES / 1024 / 1024).toFixed(0)} MiB.`, MINIMAX_IMAGE_FORMAT_HELP);
201
+ }
202
+ return `data:${mime};base64,${Buffer.from(buf).toString("base64")}`;
203
+ }
204
+ catch (err) {
205
+ clearT(timeoutId);
206
+ if (err instanceof ValidationError || err instanceof ApiError)
207
+ throw err;
208
+ if (err instanceof Error) {
209
+ if (err.name === "AbortError") {
210
+ throw new TimeoutError(timeoutMs);
211
+ }
212
+ const lower = err.message.toLowerCase();
213
+ if (lower.includes("fetch") ||
214
+ lower.includes("econnrefused") ||
215
+ lower.includes("econnreset") ||
216
+ lower.includes("enotfound") ||
217
+ lower.includes("network")) {
218
+ throw new NetworkError("MiniMax image fetch network error");
219
+ }
220
+ }
221
+ throw err;
222
+ }
223
+ }
224
+ async function readLocalImageAsDataUri(source) {
225
+ const ext = path.extname(source).toLowerCase();
226
+ // Extension was validated by resolveImageSource; the fallback matches
227
+ // SDK behaviour if an unknown extension ever reaches this branch.
228
+ const mime = MINIMAX_IMAGE_MIME_BY_EXTENSION[ext] ?? "image/jpeg";
229
+ const data = await readFile(source);
230
+ return `data:${mime};base64,${data.toString("base64")}`;
231
+ }
232
+ //# sourceMappingURL=media.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.js","sourceRoot":"","sources":["../../../src/providers/minimax/media.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAG7B,8EAA8E;AAC9E,sCAAsC;AACtC,8EAA8E;AAE9E,MAAM,wBAAwB,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpE,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,SAAS;AAE3D,MAAM,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CAAC,OAAO,CAAC;gBACvB,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAC9B,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC;gBAC5B,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC;gBAC3B,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EACzB,CAAC;gBACD,MAAM,IAAI,YAAY,CAAC,mCAAmC,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,uBAAuB,CAAC,MAAc;IACnD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/C,sEAAsE;IACtE,kEAAkE;IAClE,MAAM,IAAI,GAAG,+BAA+B,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC;IAClE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpC,OAAO,QAAQ,IAAI,WAAW,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * MiniMax Quota Client — Adapter-local direct transport (DESIGN.md §12, P4-02).
3
+ *
4
+ * The pinned `mmx-cli/sdk` 1.0.16 does not preserve an arbitrary
5
+ * configured host for quota. This Module performs ONE direct GET against
6
+ * `<baseUrl>/v1/api/openplatform/coding_plan/remains` with an
7
+ * `Authorization: Bearer <apiKey>` header so `MINIMAX_BASE_URL` is
8
+ * authoritative for quota. There is NO internal retry — shared execution
9
+ * owns retry policy. Fetch and timer are injectable for tests.
10
+ *
11
+ * Phase A (A2): the previously named `MiniMaxQuotaClientDeps` is now an
12
+ * alias for the unified `MiniMaxTransportDeps` declared in
13
+ * `./coding-plan-client.ts`. Same four fields — rename, not superset —
14
+ * so existing imports and call sites keep working unchanged.
15
+ *
16
+ * Boundary rules (ARCHITECTURE.md §2):
17
+ * - May import Adapter-local config and normalized errors.
18
+ * - Must NOT import `mmx-cli/sdk`, command presentation, or another
19
+ * Provider's Adapter.
20
+ */
21
+ import type { MiniMaxConfig } from "./config.js";
22
+ import type { ProviderQuotaFetch } from "../types.js";
23
+ import type { MiniMaxTransportDeps } from "./coding-plan-client.js";
24
+ /** Injectable fetch signature (shared duck-typed port). */
25
+ export type MiniMaxQuotaFetch = ProviderQuotaFetch;
26
+ /** Fetch response shape this transport consumes. */
27
+ export type MiniMaxQuotaFetchResponse = Awaited<ReturnType<MiniMaxQuotaFetch>>;
28
+ /**
29
+ * Renamed alias for {@link MiniMaxTransportDeps} (Phase A — A2). The
30
+ * two type names describe the same shape; the unified name wins at
31
+ * the new `coding-plan-client.ts`, this name is preserved here so
32
+ * existing imports keep resolving.
33
+ */
34
+ export type MiniMaxQuotaClientDeps = MiniMaxTransportDeps;
35
+ /** Raw MiniMax quota response shape (remains endpoint). */
36
+ export interface MiniMaxRawQuotaResponse {
37
+ model_remains?: unknown[];
38
+ }
39
+ /**
40
+ * Perform ONE GET against the MiniMax remains endpoint. No retry; no
41
+ * response body in public errors. Returns the parsed JSON body.
42
+ */
43
+ export declare function fetchMiniMaxQuota(config: MiniMaxConfig, deps?: MiniMaxQuotaClientDeps): Promise<MiniMaxRawQuotaResponse>;
44
+ //# sourceMappingURL=quota-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota-client.d.ts","sourceRoot":"","sources":["../../../src/providers/minimax/quota-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAKpE,2DAA2D;AAC3D,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAEnD,oDAAoD;AACpD,MAAM,MAAM,yBAAyB,GAAG,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAE1D,2DAA2D;AAC3D,MAAM,WAAW,uBAAuB;IACtC,aAAa,CAAC,EAAE,OAAO,EAAE,CAAC;CAC3B;AAkCD;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,aAAa,EACrB,IAAI,GAAE,sBAA2B,GAChC,OAAO,CAAC,uBAAuB,CAAC,CA0BlC"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * MiniMax Quota Client — Adapter-local direct transport (DESIGN.md §12, P4-02).
3
+ *
4
+ * The pinned `mmx-cli/sdk` 1.0.16 does not preserve an arbitrary
5
+ * configured host for quota. This Module performs ONE direct GET against
6
+ * `<baseUrl>/v1/api/openplatform/coding_plan/remains` with an
7
+ * `Authorization: Bearer <apiKey>` header so `MINIMAX_BASE_URL` is
8
+ * authoritative for quota. There is NO internal retry — shared execution
9
+ * owns retry policy. Fetch and timer are injectable for tests.
10
+ *
11
+ * Phase A (A2): the previously named `MiniMaxQuotaClientDeps` is now an
12
+ * alias for the unified `MiniMaxTransportDeps` declared in
13
+ * `./coding-plan-client.ts`. Same four fields — rename, not superset —
14
+ * so existing imports and call sites keep working unchanged.
15
+ *
16
+ * Boundary rules (ARCHITECTURE.md §2):
17
+ * - May import Adapter-local config and normalized errors.
18
+ * - Must NOT import `mmx-cli/sdk`, command presentation, or another
19
+ * Provider's Adapter.
20
+ */
21
+ import { ApiError, AuthError, NetworkError, TimeoutError } from "../../lib/errors.js";
22
+ const QUOTA_PATH = "/v1/api/openplatform/coding_plan/remains";
23
+ const DEFAULT_TIMEOUT_MS = 30000;
24
+ function resolveTimeoutMs(env) {
25
+ const raw = parseInt(env.MINIMAX_TIMEOUT || String(DEFAULT_TIMEOUT_MS), 10);
26
+ return Number.isFinite(raw) && raw > 0 ? raw : DEFAULT_TIMEOUT_MS;
27
+ }
28
+ function mapStatusError(status) {
29
+ if (status === 401 || status === 403) {
30
+ return new AuthError("MiniMax quota API authentication failed");
31
+ }
32
+ return new ApiError("MiniMax quota API request failed", status);
33
+ }
34
+ function normalizeTransportError(err, timeoutMs) {
35
+ if (err instanceof AuthError || err instanceof ApiError)
36
+ return err;
37
+ if (err instanceof Error) {
38
+ if (err.name === "AbortError") {
39
+ return new TimeoutError(timeoutMs);
40
+ }
41
+ const lower = err.message.toLowerCase();
42
+ if (lower.includes("fetch") ||
43
+ lower.includes("econnrefused") ||
44
+ lower.includes("econnreset") ||
45
+ lower.includes("enotfound") ||
46
+ lower.includes("network")) {
47
+ return new NetworkError("MiniMax quota network error");
48
+ }
49
+ }
50
+ return new ApiError("MiniMax quota request failed", 500);
51
+ }
52
+ /**
53
+ * Perform ONE GET against the MiniMax remains endpoint. No retry; no
54
+ * response body in public errors. Returns the parsed JSON body.
55
+ */
56
+ export async function fetchMiniMaxQuota(config, deps = {}) {
57
+ const f = deps.fetch ?? fetch;
58
+ const setT = deps.setTimeout ?? setTimeout;
59
+ const clearT = deps.clearTimeout ?? clearTimeout;
60
+ const env = deps.env ?? process.env;
61
+ const timeoutMs = resolveTimeoutMs(env);
62
+ const url = `${config.baseUrl}${QUOTA_PATH}`;
63
+ const controller = new AbortController();
64
+ const timeoutId = setT(() => controller.abort(), timeoutMs);
65
+ try {
66
+ const res = await f(url, {
67
+ method: "GET",
68
+ headers: { Authorization: `Bearer ${config.apiKey}` },
69
+ signal: controller.signal,
70
+ });
71
+ clearT(timeoutId);
72
+ if (!res.ok) {
73
+ await res.text().catch(() => { });
74
+ throw mapStatusError(res.status);
75
+ }
76
+ return (await res.json());
77
+ }
78
+ catch (err) {
79
+ clearT(timeoutId);
80
+ throw normalizeTransportError(err, timeoutMs);
81
+ }
82
+ }
83
+ //# sourceMappingURL=quota-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota-client.js","sourceRoot":"","sources":["../../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AC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YACjC,MAAM,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAA4B,CAAC;IACvD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,SAAS,CAAC,CAAC;QAClB,MAAM,uBAAuB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IAChD,CAAC;AACH,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * MiniMax Quota Capability (DESIGN.md §12, §13, P4-02).
3
+ *
4
+ * Maps the MiniMax remains-endpoint response into the normalized
5
+ * Provider-quota Interface. The normalizer is pure; the capability
6
+ * factory owns configuration resolution, the single direct transport
7
+ * attempt, and failure normalization. Shared execution owns retry.
8
+ *
9
+ * MiniMax mapping (DESIGN.md §13):
10
+ * - Each `model_remains` entry -> one category named by nonempty
11
+ * `model_name`, unit `requests`, sorted ascending by name.
12
+ * - Current counts + remaining percent; optional weekly counts +
13
+ * remaining percent.
14
+ * - `end_time` / `weekly_end_time` (epoch ms) -> ISO `resetsAt`.
15
+ * - Only characterized 1.0.16 fields are read: model name, counts,
16
+ * remaining percentages, reset timestamps. Status and boost fields
17
+ * are not interpreted.
18
+ *
19
+ * Boundary rules (ARCHITECTURE.md §2):
20
+ * - May import the quota capability contract, Adapter-local config,
21
+ * Adapter-local quota client, and normalized errors.
22
+ * - Must NOT import `mmx-cli/sdk`, command presentation, or another
23
+ * Provider's Adapter.
24
+ */
25
+ import type { ProviderQuotaSuccess, QuotaCapability } from "../../capabilities/quota.js";
26
+ import { type MiniMaxQuotaClientDeps } from "./quota-client.js";
27
+ /**
28
+ * Normalize a raw MiniMax remains payload into the shared Interface.
29
+ * Throws `QUOTA_ERROR` (via {@link buildQuotaWindow}) when an entry has
30
+ * neither a valid percentage nor valid counts.
31
+ */
32
+ export declare function normalizeMiniMaxQuota(raw: unknown): ProviderQuotaSuccess;
33
+ /**
34
+ * Options for the MiniMax QuotaCapability. Configuration is loaded from
35
+ * `env`; transport dependencies (`fetch`, timer) are injectable for
36
+ * deterministic tests.
37
+ */
38
+ export interface MiniMaxQuotaCapabilityOptions extends MiniMaxQuotaClientDeps {
39
+ readonly env: NodeJS.ProcessEnv;
40
+ }
41
+ /**
42
+ * Build the MiniMax QuotaCapability. `invoke` loads Adapter-local
43
+ * config, performs one direct remains-endpoint attempt, and normalizes
44
+ * the response. Shared execution wraps this in the retry policy; quota
45
+ * never uses the response cache and never routes through the SDK.
46
+ */
47
+ export declare function createMiniMaxQuotaCapability(options: MiniMaxQuotaCapabilityOptions): QuotaCapability;
48
+ //# sourceMappingURL=quota.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota.d.ts","sourceRoot":"","sources":["../../../src/providers/minimax/quota.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EAEhB,MAAM,6BAA6B,CAAC;AAUrC,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,mBAAmB,CAAC;AAiC3B;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,oBAAoB,CAkDxE;AAmBD;;;;GAIG;AACH,MAAM,WAAW,6BAA8B,SAAQ,sBAAsB;IAC3E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,6BAA6B,GACrC,eAAe,CAajB"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * MiniMax Quota Capability (DESIGN.md §12, §13, P4-02).
3
+ *
4
+ * Maps the MiniMax remains-endpoint response into the normalized
5
+ * Provider-quota Interface. The normalizer is pure; the capability
6
+ * factory owns configuration resolution, the single direct transport
7
+ * attempt, and failure normalization. Shared execution owns retry.
8
+ *
9
+ * MiniMax mapping (DESIGN.md §13):
10
+ * - Each `model_remains` entry -> one category named by nonempty
11
+ * `model_name`, unit `requests`, sorted ascending by name.
12
+ * - Current counts + remaining percent; optional weekly counts +
13
+ * remaining percent.
14
+ * - `end_time` / `weekly_end_time` (epoch ms) -> ISO `resetsAt`.
15
+ * - Only characterized 1.0.16 fields are read: model name, counts,
16
+ * remaining percentages, reset timestamps. Status and boost fields
17
+ * are not interpreted.
18
+ *
19
+ * Boundary rules (ARCHITECTURE.md §2):
20
+ * - May import the quota capability contract, Adapter-local config,
21
+ * Adapter-local quota client, and normalized errors.
22
+ * - Must NOT import `mmx-cli/sdk`, command presentation, or another
23
+ * Provider's Adapter.
24
+ */
25
+ import { buildQuotaWindow } from "../../capabilities/quota.js";
26
+ import { ApiError, AuthError, ConfigurationError, NetworkError, TimeoutError, } from "../../lib/errors.js";
27
+ import { loadMiniMaxConfig } from "./config.js";
28
+ import { fetchMiniMaxQuota, } from "./quota-client.js";
29
+ function readNumber(value) {
30
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
31
+ }
32
+ function readNonemptyString(value) {
33
+ return typeof value === "string" && value.trim().length > 0 ? value : undefined;
34
+ }
35
+ // ---------------------------------------------------------------------------
36
+ // Normalizer
37
+ // ---------------------------------------------------------------------------
38
+ /**
39
+ * Normalize a raw MiniMax remains payload into the shared Interface.
40
+ * Throws `QUOTA_ERROR` (via {@link buildQuotaWindow}) when an entry has
41
+ * neither a valid percentage nor valid counts.
42
+ */
43
+ export function normalizeMiniMaxQuota(raw) {
44
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
45
+ throw new ApiError("MiniMax quota returned a malformed response", 500);
46
+ }
47
+ const response = raw;
48
+ const entries = response.model_remains;
49
+ if (!Array.isArray(entries)) {
50
+ throw new ApiError("MiniMax quota returned a malformed response", 500);
51
+ }
52
+ const categories = [];
53
+ for (const entry of entries) {
54
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
55
+ throw new ApiError("MiniMax quota returned a malformed response", 500);
56
+ }
57
+ const record = entry;
58
+ const name = readNonemptyString(record.model_name);
59
+ if (!name) {
60
+ throw new ApiError("MiniMax quota returned a malformed response", 500);
61
+ }
62
+ const current = buildQuotaWindow({
63
+ used: readNumber(record.current_interval_usage_count),
64
+ limit: readNumber(record.current_interval_total_count),
65
+ explicitRemainingPercent: readNumber(record.current_interval_remaining_percent),
66
+ resetsAtEpochMs: readNumber(record.end_time),
67
+ });
68
+ const category = { name, unit: "requests", current };
69
+ const hasWeekly = readNumber(record.current_weekly_usage_count) !== undefined ||
70
+ readNumber(record.current_weekly_total_count) !== undefined ||
71
+ readNumber(record.current_weekly_remaining_percent) !== undefined ||
72
+ readNumber(record.weekly_end_time) !== undefined;
73
+ if (hasWeekly) {
74
+ category.weekly = buildQuotaWindow({
75
+ used: readNumber(record.current_weekly_usage_count),
76
+ limit: readNumber(record.current_weekly_total_count),
77
+ explicitRemainingPercent: readNumber(record.current_weekly_remaining_percent),
78
+ resetsAtEpochMs: readNumber(record.weekly_end_time),
79
+ });
80
+ }
81
+ categories.push(category);
82
+ }
83
+ categories.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
84
+ return { provider: "minimax", status: "ok", categories };
85
+ }
86
+ // ---------------------------------------------------------------------------
87
+ // Capability factory
88
+ // ---------------------------------------------------------------------------
89
+ function normalizeMiniMaxQuotaError(error) {
90
+ if (error instanceof AuthError ||
91
+ error instanceof ApiError ||
92
+ error instanceof NetworkError ||
93
+ error instanceof TimeoutError ||
94
+ error instanceof ConfigurationError) {
95
+ return error;
96
+ }
97
+ return new ApiError("MiniMax quota request failed", 500);
98
+ }
99
+ /**
100
+ * Build the MiniMax QuotaCapability. `invoke` loads Adapter-local
101
+ * config, performs one direct remains-endpoint attempt, and normalizes
102
+ * the response. Shared execution wraps this in the retry policy; quota
103
+ * never uses the response cache and never routes through the SDK.
104
+ */
105
+ export function createMiniMaxQuotaCapability(options) {
106
+ const { env, ...transportDeps } = options;
107
+ return {
108
+ async invoke() {
109
+ const config = loadMiniMaxConfig(env);
110
+ try {
111
+ const raw = await fetchMiniMaxQuota(config, transportDeps);
112
+ return normalizeMiniMaxQuota(raw);
113
+ }
114
+ catch (error) {
115
+ throw normalizeMiniMaxQuotaError(error);
116
+ }
117
+ },
118
+ };
119
+ }
120
+ //# sourceMappingURL=quota.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota.js","sourceRoot":"","sources":["../../../src/providers/minimax/quota.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EACL,QAAQ,EACR,SAAS,EACT,kBAAkB,EAClB,YAAY,EACZ,YAAY,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAsB,MAAM,aAAa,CAAC;AACpE,OAAO,EACL,iBAAiB,GAGlB,MAAM,mBAAmB,CAAC;AAqB3B,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACjF,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAClF,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAY;IAChD,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,QAAQ,CAAC,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AAC,CAAC;AAC3D,CAAC;AAWD;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,OAAsC;IAEtC,MAAM,EAAE,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,OAAO,CAAC;IAC1C,OAAO;QACL,KAAK,CAAC,MAAM;YACV,MAAM,MAAM,GAAkB,iBAAiB,CAAC,GAAG,CAAC,CAAC;YACrD,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;gBAC3D,OAAO,qBAAqB,CAAC,GAAG,CAAC,CAAC;YACpC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,0BAA0B,CAAC,KAAK,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * MiniMax SDK client factory (DESIGN.md §12 — P2-04).
3
+ *
4
+ * This is the ONLY module that imports `mmx-cli/sdk`. The Adapter and
5
+ * registry consume {@link createMiniMaxSdk} plus the injectable
6
+ * {@link MiniMaxSdkConstructor} / {@link MiniMaxSdkPort} types declared
7
+ * in `providers/types.ts`, so the transitional SDK never leaks past
8
+ * this boundary.
9
+ *
10
+ * The characterized SDK reads its own config directory during
11
+ * construction (it calls `getConfigDir()`, which honours
12
+ * `MMX_CONFIG_DIR`). To prevent the SDK from touching the user's real
13
+ * `~/.mmx` state, the factory temporarily points `MMX_CONFIG_DIR` at a
14
+ * unique nonexistent path for the synchronous construction call only,
15
+ * then restores the prior value in `finally`. The temporary directory
16
+ * is NEVER created on disk.
17
+ */
18
+ import type { MiniMaxSdkConstructor, MiniMaxSdkPort } from "../types.js";
19
+ /**
20
+ * Construct a MiniMax SDK port. The optional `constructor` lets tests
21
+ * inject a fake; production omits it and uses the pinned `mmx-cli/sdk`
22
+ * implementation.
23
+ */
24
+ export declare function createMiniMaxSdk(options: {
25
+ apiKey: string;
26
+ region: "global" | "cn";
27
+ baseUrl: string;
28
+ }, constructor?: MiniMaxSdkConstructor): MiniMaxSdkPort;
29
+ //# sourceMappingURL=sdk-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-client.d.ts","sourceRoot":"","sources":["../../../src/providers/minimax/sdk-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAOH,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIzE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EACrE,WAAW,CAAC,EAAE,qBAAqB,GAClC,cAAc,CAoBhB"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * MiniMax SDK client factory (DESIGN.md §12 — P2-04).
3
+ *
4
+ * This is the ONLY module that imports `mmx-cli/sdk`. The Adapter and
5
+ * registry consume {@link createMiniMaxSdk} plus the injectable
6
+ * {@link MiniMaxSdkConstructor} / {@link MiniMaxSdkPort} types declared
7
+ * in `providers/types.ts`, so the transitional SDK never leaks past
8
+ * this boundary.
9
+ *
10
+ * The characterized SDK reads its own config directory during
11
+ * construction (it calls `getConfigDir()`, which honours
12
+ * `MMX_CONFIG_DIR`). To prevent the SDK from touching the user's real
13
+ * `~/.mmx` state, the factory temporarily points `MMX_CONFIG_DIR` at a
14
+ * unique nonexistent path for the synchronous construction call only,
15
+ * then restores the prior value in `finally`. The temporary directory
16
+ * is NEVER created on disk.
17
+ */
18
+ import { randomUUID } from "node:crypto";
19
+ import { tmpdir } from "node:os";
20
+ import path from "node:path";
21
+ import { MiniMaxSDK } from "mmx-cli/sdk";
22
+ const MMX_CONFIG_DIR = "MMX_CONFIG_DIR";
23
+ /**
24
+ * Construct a MiniMax SDK port. The optional `constructor` lets tests
25
+ * inject a fake; production omits it and uses the pinned `mmx-cli/sdk`
26
+ * implementation.
27
+ */
28
+ export function createMiniMaxSdk(options, constructor) {
29
+ const Ctor = constructor ?? MiniMaxSDK;
30
+ const hadPrev = Object.prototype.hasOwnProperty.call(process.env, MMX_CONFIG_DIR);
31
+ const prev = process.env[MMX_CONFIG_DIR];
32
+ // A unique nonexistent path. It is deliberately never created.
33
+ const temporaryDir = path.join(tmpdir(), `scoutline-minimax-${randomUUID()}`);
34
+ process.env[MMX_CONFIG_DIR] = temporaryDir;
35
+ try {
36
+ // Construction is synchronous and reads MMX_CONFIG_DIR via the
37
+ // SDK's getConfigDir(). The async search/vision calls happen
38
+ // after this block, with the original env already restored.
39
+ return new Ctor(options);
40
+ }
41
+ finally {
42
+ if (hadPrev) {
43
+ process.env[MMX_CONFIG_DIR] = prev;
44
+ }
45
+ else {
46
+ delete process.env[MMX_CONFIG_DIR];
47
+ }
48
+ }
49
+ }
50
+ //# sourceMappingURL=sdk-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdk-client.js","sourceRoot":"","sources":["../../../src/providers/minimax/sdk-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAExC;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAAqE,EACrE,WAAmC;IAEnC,MAAM,IAAI,GAAG,WAAW,IAAK,UAA+C,CAAC;IAE7E,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAClF,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACzC,+DAA+D;IAC/D,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,qBAAqB,UAAU,EAAE,EAAE,CAAC,CAAC;IAC9E,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,YAAY,CAAC;IAC3C,IAAI,CAAC;QACH,+DAA+D;QAC/D,6DAA6D;QAC7D,4DAA4D;QAC5D,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;YAAS,CAAC;QACT,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;AACH,CAAC"}