scoutline 0.1.0 → 0.2.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 (206) hide show
  1. package/README.md +170 -5
  2. package/bin/scoutline.js +36 -15
  3. package/dist/capabilities/diagnostics.d.ts +97 -0
  4. package/dist/capabilities/diagnostics.d.ts.map +1 -0
  5. package/dist/capabilities/diagnostics.js +88 -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/search.d.ts +110 -0
  12. package/dist/capabilities/search.d.ts.map +1 -0
  13. package/dist/capabilities/search.js +21 -0
  14. package/dist/capabilities/search.js.map +1 -0
  15. package/dist/capabilities/vision.d.ts +156 -0
  16. package/dist/capabilities/vision.d.ts.map +1 -0
  17. package/dist/capabilities/vision.js +111 -0
  18. package/dist/capabilities/vision.js.map +1 -0
  19. package/dist/command-invocation.d.ts +58 -0
  20. package/dist/command-invocation.d.ts.map +1 -0
  21. package/dist/command-invocation.js +95 -0
  22. package/dist/command-invocation.js.map +1 -0
  23. package/dist/commands/code.d.ts +11 -4
  24. package/dist/commands/code.d.ts.map +1 -1
  25. package/dist/commands/code.js +16 -42
  26. package/dist/commands/code.js.map +1 -1
  27. package/dist/commands/doctor.d.ts +58 -3
  28. package/dist/commands/doctor.d.ts.map +1 -1
  29. package/dist/commands/doctor.js +154 -52
  30. package/dist/commands/doctor.js.map +1 -1
  31. package/dist/commands/quota.d.ts +45 -3
  32. package/dist/commands/quota.d.ts.map +1 -1
  33. package/dist/commands/quota.js +116 -60
  34. package/dist/commands/quota.js.map +1 -1
  35. package/dist/commands/read.d.ts +15 -1
  36. package/dist/commands/read.d.ts.map +1 -1
  37. package/dist/commands/read.js +53 -54
  38. package/dist/commands/read.js.map +1 -1
  39. package/dist/commands/repo.d.ts +8 -3
  40. package/dist/commands/repo.d.ts.map +1 -1
  41. package/dist/commands/repo.js +40 -78
  42. package/dist/commands/repo.js.map +1 -1
  43. package/dist/commands/search.d.ts +27 -2
  44. package/dist/commands/search.d.ts.map +1 -1
  45. package/dist/commands/search.js +95 -103
  46. package/dist/commands/search.js.map +1 -1
  47. package/dist/commands/tools.d.ts +9 -3
  48. package/dist/commands/tools.d.ts.map +1 -1
  49. package/dist/commands/tools.js +29 -59
  50. package/dist/commands/tools.js.map +1 -1
  51. package/dist/commands/vision.d.ts +35 -9
  52. package/dist/commands/vision.d.ts.map +1 -1
  53. package/dist/commands/vision.js +184 -131
  54. package/dist/commands/vision.js.map +1 -1
  55. package/dist/index.d.ts +42 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +389 -207
  58. package/dist/index.js.map +1 -1
  59. package/dist/lib/cache.d.ts +61 -0
  60. package/dist/lib/cache.d.ts.map +1 -1
  61. package/dist/lib/cache.js +74 -11
  62. package/dist/lib/cache.js.map +1 -1
  63. package/dist/lib/code-mode.d.ts +13 -0
  64. package/dist/lib/code-mode.d.ts.map +1 -1
  65. package/dist/lib/code-mode.js +26 -6
  66. package/dist/lib/code-mode.js.map +1 -1
  67. package/dist/lib/config.d.ts.map +1 -1
  68. package/dist/lib/config.js +15 -18
  69. package/dist/lib/config.js.map +1 -1
  70. package/dist/lib/errors.d.ts +65 -10
  71. package/dist/lib/errors.d.ts.map +1 -1
  72. package/dist/lib/errors.js +135 -19
  73. package/dist/lib/errors.js.map +1 -1
  74. package/dist/lib/execution.d.ts +76 -0
  75. package/dist/lib/execution.d.ts.map +1 -0
  76. package/dist/lib/execution.js +177 -0
  77. package/dist/lib/execution.js.map +1 -0
  78. package/dist/lib/index.d.ts +10 -2
  79. package/dist/lib/index.d.ts.map +1 -1
  80. package/dist/lib/index.js +10 -2
  81. package/dist/lib/index.js.map +1 -1
  82. package/dist/lib/mcp-client.d.ts +46 -11
  83. package/dist/lib/mcp-client.d.ts.map +1 -1
  84. package/dist/lib/mcp-client.js +92 -27
  85. package/dist/lib/mcp-client.js.map +1 -1
  86. package/dist/lib/mcp-config.d.ts +17 -0
  87. package/dist/lib/mcp-config.d.ts.map +1 -1
  88. package/dist/lib/mcp-config.js +29 -0
  89. package/dist/lib/mcp-config.js.map +1 -1
  90. package/dist/lib/monitor-client.d.ts +17 -3
  91. package/dist/lib/monitor-client.d.ts.map +1 -1
  92. package/dist/lib/monitor-client.js +23 -69
  93. package/dist/lib/monitor-client.js.map +1 -1
  94. package/dist/lib/output.d.ts +53 -7
  95. package/dist/lib/output.d.ts.map +1 -1
  96. package/dist/lib/output.js +126 -39
  97. package/dist/lib/output.js.map +1 -1
  98. package/dist/lib/redact.d.ts +62 -3
  99. package/dist/lib/redact.d.ts.map +1 -1
  100. package/dist/lib/redact.js +165 -31
  101. package/dist/lib/redact.js.map +1 -1
  102. package/dist/lib/tty.d.ts +7 -20
  103. package/dist/lib/tty.d.ts.map +1 -1
  104. package/dist/lib/tty.js +51 -30
  105. package/dist/lib/tty.js.map +1 -1
  106. package/dist/node-command-invocation-adapter.d.ts +28 -0
  107. package/dist/node-command-invocation-adapter.d.ts.map +1 -0
  108. package/dist/node-command-invocation-adapter.js +88 -0
  109. package/dist/node-command-invocation-adapter.js.map +1 -0
  110. package/dist/providers/minimax/adapter.d.ts +47 -0
  111. package/dist/providers/minimax/adapter.d.ts.map +1 -0
  112. package/dist/providers/minimax/adapter.js +443 -0
  113. package/dist/providers/minimax/adapter.js.map +1 -0
  114. package/dist/providers/minimax/config.d.ts +32 -0
  115. package/dist/providers/minimax/config.d.ts.map +1 -0
  116. package/dist/providers/minimax/config.js +84 -0
  117. package/dist/providers/minimax/config.js.map +1 -0
  118. package/dist/providers/minimax/media.d.ts +34 -0
  119. package/dist/providers/minimax/media.d.ts.map +1 -0
  120. package/dist/providers/minimax/media.js +92 -0
  121. package/dist/providers/minimax/media.js.map +1 -0
  122. package/dist/providers/minimax/quota-client.d.ts +37 -0
  123. package/dist/providers/minimax/quota-client.d.ts.map +1 -0
  124. package/dist/providers/minimax/quota-client.js +78 -0
  125. package/dist/providers/minimax/quota-client.js.map +1 -0
  126. package/dist/providers/minimax/quota.d.ts +48 -0
  127. package/dist/providers/minimax/quota.d.ts.map +1 -0
  128. package/dist/providers/minimax/quota.js +120 -0
  129. package/dist/providers/minimax/quota.js.map +1 -0
  130. package/dist/providers/minimax/sdk-client.d.ts +29 -0
  131. package/dist/providers/minimax/sdk-client.d.ts.map +1 -0
  132. package/dist/providers/minimax/sdk-client.js +50 -0
  133. package/dist/providers/minimax/sdk-client.js.map +1 -0
  134. package/dist/providers/minimax/vision-attestations.d.ts +29 -0
  135. package/dist/providers/minimax/vision-attestations.d.ts.map +1 -0
  136. package/dist/providers/minimax/vision-attestations.js +54 -0
  137. package/dist/providers/minimax/vision-attestations.js.map +1 -0
  138. package/dist/providers/minimax/vision-conformance.d.ts +184 -0
  139. package/dist/providers/minimax/vision-conformance.d.ts.map +1 -0
  140. package/dist/providers/minimax/vision-conformance.js +369 -0
  141. package/dist/providers/minimax/vision-conformance.js.map +1 -0
  142. package/dist/providers/minimax/vision-mappings/chart.d.ts +35 -0
  143. package/dist/providers/minimax/vision-mappings/chart.d.ts.map +1 -0
  144. package/dist/providers/minimax/vision-mappings/chart.js +55 -0
  145. package/dist/providers/minimax/vision-mappings/chart.js.map +1 -0
  146. package/dist/providers/minimax/vision-mappings/common.d.ts +60 -0
  147. package/dist/providers/minimax/vision-mappings/common.d.ts.map +1 -0
  148. package/dist/providers/minimax/vision-mappings/common.js +75 -0
  149. package/dist/providers/minimax/vision-mappings/common.js.map +1 -0
  150. package/dist/providers/minimax/vision-mappings/diagnose-error.d.ts +35 -0
  151. package/dist/providers/minimax/vision-mappings/diagnose-error.d.ts.map +1 -0
  152. package/dist/providers/minimax/vision-mappings/diagnose-error.js +55 -0
  153. package/dist/providers/minimax/vision-mappings/diagnose-error.js.map +1 -0
  154. package/dist/providers/minimax/vision-mappings/diagram.d.ts +35 -0
  155. package/dist/providers/minimax/vision-mappings/diagram.d.ts.map +1 -0
  156. package/dist/providers/minimax/vision-mappings/diagram.js +55 -0
  157. package/dist/providers/minimax/vision-mappings/diagram.js.map +1 -0
  158. package/dist/providers/minimax/vision-mappings/extract-text.d.ts +35 -0
  159. package/dist/providers/minimax/vision-mappings/extract-text.d.ts.map +1 -0
  160. package/dist/providers/minimax/vision-mappings/extract-text.js +55 -0
  161. package/dist/providers/minimax/vision-mappings/extract-text.js.map +1 -0
  162. package/dist/providers/minimax/vision-mappings/ui-artifact.d.ts +35 -0
  163. package/dist/providers/minimax/vision-mappings/ui-artifact.d.ts.map +1 -0
  164. package/dist/providers/minimax/vision-mappings/ui-artifact.js +69 -0
  165. package/dist/providers/minimax/vision-mappings/ui-artifact.js.map +1 -0
  166. package/dist/providers/minimax/vision-mappings.generated.d.ts +29 -0
  167. package/dist/providers/minimax/vision-mappings.generated.d.ts.map +1 -0
  168. package/dist/providers/minimax/vision-mappings.generated.js +29 -0
  169. package/dist/providers/minimax/vision-mappings.generated.js.map +1 -0
  170. package/dist/providers/minimax/vision-revisions.d.ts +22 -0
  171. package/dist/providers/minimax/vision-revisions.d.ts.map +1 -0
  172. package/dist/providers/minimax/vision-revisions.js +27 -0
  173. package/dist/providers/minimax/vision-revisions.js.map +1 -0
  174. package/dist/providers/registry.d.ts +36 -0
  175. package/dist/providers/registry.d.ts.map +1 -0
  176. package/dist/providers/registry.js +45 -0
  177. package/dist/providers/registry.js.map +1 -0
  178. package/dist/providers/selection.d.ts +44 -0
  179. package/dist/providers/selection.d.ts.map +1 -0
  180. package/dist/providers/selection.js +85 -0
  181. package/dist/providers/selection.js.map +1 -0
  182. package/dist/providers/types.d.ts +247 -0
  183. package/dist/providers/types.d.ts.map +1 -0
  184. package/dist/providers/types.js +127 -0
  185. package/dist/providers/types.js.map +1 -0
  186. package/dist/providers/zai/adapter.d.ts +35 -0
  187. package/dist/providers/zai/adapter.d.ts.map +1 -0
  188. package/dist/providers/zai/adapter.js +619 -0
  189. package/dist/providers/zai/adapter.js.map +1 -0
  190. package/dist/providers/zai/credentials.d.ts +38 -0
  191. package/dist/providers/zai/credentials.d.ts.map +1 -0
  192. package/dist/providers/zai/credentials.js +60 -0
  193. package/dist/providers/zai/credentials.js.map +1 -0
  194. package/dist/providers/zai/media.d.ts +38 -0
  195. package/dist/providers/zai/media.d.ts.map +1 -0
  196. package/dist/providers/zai/media.js +107 -0
  197. package/dist/providers/zai/media.js.map +1 -0
  198. package/dist/providers/zai/monitor-client.d.ts +53 -0
  199. package/dist/providers/zai/monitor-client.d.ts.map +1 -0
  200. package/dist/providers/zai/monitor-client.js +117 -0
  201. package/dist/providers/zai/monitor-client.js.map +1 -0
  202. package/dist/providers/zai/quota.d.ts +47 -0
  203. package/dist/providers/zai/quota.d.ts.map +1 -0
  204. package/dist/providers/zai/quota.js +127 -0
  205. package/dist/providers/zai/quota.js.map +1 -0
  206. package/package.json +10 -5
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Quota Capability Contract (DESIGN.md §13, ADR-0001).
3
+ *
4
+ * Defines the normalized Provider-quota Interface shared by every
5
+ * Provider that reports plan usage. Each Adapter maps its Provider
6
+ * response shape into named quota categories with current and optional
7
+ * weekly windows, optional counts, a remaining percentage, and a reset
8
+ * time so callers do not need Provider-specific knowledge.
9
+ *
10
+ * Normalization rules (DESIGN.md §13):
11
+ * - Percentages are REMAINING percentages clamped to 0..100.
12
+ * - A valid explicit remaining percentage wins; otherwise derive
13
+ * `(remaining / limit) * 100` from finite nonnegative counts where
14
+ * used is not greater than limit.
15
+ * - Invalid optional counts are omitted together (not set to zero).
16
+ * - A category that has neither a valid percentage nor valid counts
17
+ * is rejected with `QUOTA_ERROR`.
18
+ * - Nonempty names, finite values, and ISO dates are mandatory.
19
+ *
20
+ * This module imports only Provider identity types and shared errors;
21
+ * it imports no Provider transport and no Provider Adapter.
22
+ */
23
+ import { ScoutlineError } from "../lib/errors.js";
24
+ function isFiniteNonnegative(value) {
25
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
26
+ }
27
+ function isFinitePositive(value) {
28
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
29
+ }
30
+ function clampPercent(value) {
31
+ if (value < 0)
32
+ return 0;
33
+ if (value > 100)
34
+ return 100;
35
+ return value;
36
+ }
37
+ /**
38
+ * Validate a count set: both `used` and `limit` must be finite,
39
+ * nonnegative, with `used` not greater than `limit`. Returns the pair
40
+ * or `null` so an invalid set can be omitted together.
41
+ */
42
+ function validCountSet(used, limit) {
43
+ if (!isFiniteNonnegative(used) || !isFiniteNonnegative(limit))
44
+ return null;
45
+ if (used > limit)
46
+ return null;
47
+ return { used: used, limit: limit };
48
+ }
49
+ /**
50
+ * Derive a remaining percentage from finite nonnegative counts where
51
+ * used is not greater than limit and limit is positive. Returns `null`
52
+ * when the counts cannot yield a percentage.
53
+ */
54
+ function derivePercentFromCounts(used, limit) {
55
+ const counts = validCountSet(used, limit);
56
+ if (counts === null)
57
+ return null;
58
+ if (counts.limit <= 0)
59
+ return null;
60
+ return ((counts.limit - counts.used) / counts.limit) * 100;
61
+ }
62
+ function epochMsToIso(epochMs) {
63
+ if (!isFinitePositive(epochMs))
64
+ return undefined;
65
+ return new Date(epochMs).toISOString();
66
+ }
67
+ /**
68
+ * Build a normalized {@link QuotaWindow} from Provider inputs.
69
+ *
70
+ * Resolution order for `remainingPercent`:
71
+ * 1. A finite explicit remaining percentage wins (then clamped).
72
+ * 2. Otherwise derive from valid counts.
73
+ * 3. Otherwise throw `QUOTA_ERROR` — the category is unrecoverable.
74
+ *
75
+ * Invalid optional counts are omitted together; valid counts populate
76
+ * `used`, `limit`, and a derived `remaining`. `durationSeconds` and
77
+ * `resetsAt` are included only when finite/ISO-valid.
78
+ */
79
+ export function buildQuotaWindow(inputs) {
80
+ let remainingPercent;
81
+ if (Number.isFinite(inputs.explicitRemainingPercent)) {
82
+ remainingPercent = inputs.explicitRemainingPercent;
83
+ }
84
+ else {
85
+ const derived = derivePercentFromCounts(inputs.used, inputs.limit);
86
+ if (derived !== null)
87
+ remainingPercent = derived;
88
+ }
89
+ if (remainingPercent === undefined) {
90
+ throw new ScoutlineError("quota category has neither a valid remaining percentage nor valid counts", "QUOTA_ERROR", { exitCode: 1 });
91
+ }
92
+ const window = { remainingPercent: clampPercent(remainingPercent) };
93
+ const counts = validCountSet(inputs.used, inputs.limit);
94
+ if (counts !== null) {
95
+ window.used = counts.used;
96
+ window.limit = counts.limit;
97
+ window.remaining = counts.limit - counts.used;
98
+ }
99
+ if (isFinitePositive(inputs.durationSeconds)) {
100
+ window.durationSeconds = inputs.durationSeconds;
101
+ }
102
+ const iso = epochMsToIso(inputs.resetsAtEpochMs);
103
+ if (iso !== undefined) {
104
+ window.resetsAt = iso;
105
+ }
106
+ return window;
107
+ }
108
+ // ---------------------------------------------------------------------------
109
+ // Failure normalization
110
+ // ---------------------------------------------------------------------------
111
+ /**
112
+ * Map a thrown error into a normalized {@link ProviderQuotaFailure}. The
113
+ * caller is responsible for recursive redaction before the failure
114
+ * crosses an outward boundary (all-provider quota does this in P4-03).
115
+ */
116
+ export function quotaFailureFromError(provider, error) {
117
+ const code = error instanceof ScoutlineError ? error.code : "UNKNOWN_ERROR";
118
+ const message = error instanceof Error ? error.message : String(error);
119
+ const failure = {
120
+ provider,
121
+ status: "error",
122
+ error: { code, message },
123
+ };
124
+ if (error instanceof ScoutlineError && error.help) {
125
+ failure.error.help = error.help;
126
+ }
127
+ return failure;
128
+ }
129
+ //# sourceMappingURL=quota.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quota.js","sourceRoot":"","sources":["../../src/capabilities/quota.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAAE,cAAc,EAA2B,MAAM,kBAAkB,CAAC;AAoE3E,SAAS,mBAAmB,CAAC,KAAc;IACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,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B,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC;IACxB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAoB,EAAE,KAAc;IACxE,MAAM,IAAI,GACR,KAAK,YAAY,cAAc,CAAC,CAAC,CAAE,KAAK,CAAC,IAA2B,CAAC,CAAC,CAAC,eAAe,CAAC;IACzF,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,MAAM,OAAO,GAAyB;QACpC,QAAQ;QACR,MAAM,EAAE,OAAO;QACf,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;KACzB,CAAC;IACF,IAAI,KAAK,YAAY,cAAc,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QAClD,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IAClC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Search Capability Contract (DESIGN.md §7, PRD FR-010 through FR-016).
3
+ *
4
+ * Defines the normalized meaning shared by every Search Provider.
5
+ * Commands consume the Capability through `SearchCapability.invoke`,
6
+ * which returns `SearchSource[]` in the Provider-agnostic shape. All
7
+ * Provider-specific fields (rank, occurrence count, count, summary
8
+ * truncation, field projection, presentation) remain command meaning.
9
+ *
10
+ * The Cache Identity contract (`SearchCacheIdentity`,
11
+ * `LegacySearchCacheCandidate`) is declared here so P2-02 can wire
12
+ * Provider-partitioned cache keys without further type changes.
13
+ *
14
+ * Phase 2 implements only this contract. The Z.AI and MiniMax Search
15
+ * Adapters arrive in P2-03 and P2-04; the production registry arrives
16
+ * in P2-05. The Provider descriptors advertised in P2-01 already
17
+ * declare the search Capability, so command wiring can begin once the
18
+ * Adapters exist.
19
+ */
20
+ import type { ProviderId } from "../providers/types.js";
21
+ /** Recency filter accepted by Z.AI; MiniMax rejects it. */
22
+ export type SearchRecency = "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | "noLimit";
23
+ /**
24
+ * Provider controls accepted by the Search Capability. Every field is
25
+ * optional. MiniMax rejects `domain`, `recency`, `contentSize`, and
26
+ * `location` with `UNSUPPORTED_OPTION` before any SDK access.
27
+ */
28
+ export interface SearchControls {
29
+ domain?: string;
30
+ recency?: SearchRecency;
31
+ contentSize?: "medium" | "high";
32
+ location?: "cn" | "us";
33
+ }
34
+ /**
35
+ * A Search request. `query` must contain at least one non-whitespace
36
+ * character; the Capability's `validate` enforces this and throws
37
+ * `ValidationError` otherwise.
38
+ */
39
+ export interface SearchRequest {
40
+ query: string;
41
+ controls?: Readonly<SearchControls>;
42
+ }
43
+ /**
44
+ * Normalized Search result. Adapters populate this from their Provider
45
+ * response shape; commands merge, deduplicate, project, truncate, and
46
+ * rank downstream. Provider-only fields are discarded.
47
+ */
48
+ export interface SearchSource {
49
+ title: string;
50
+ url: string;
51
+ summary: string;
52
+ source?: string;
53
+ date?: string;
54
+ }
55
+ /**
56
+ * Provider-owned legacy cache candidate. Old Z.AI keys encode raw
57
+ * `WebSearchResult[]`; the Adapter supplies the decoder so shared cache
58
+ * code never inspects Provider response shapes. Invalid decode is a
59
+ * cache miss.
60
+ */
61
+ export interface LegacySearchCacheCandidate {
62
+ readonly key: string;
63
+ decode(value: unknown): readonly SearchSource[] | null;
64
+ }
65
+ /**
66
+ * Identity used to read and write a Provider-partitioned cache entry.
67
+ * `credentialFingerprint` is the full lowercase SHA-256 hex digest of
68
+ * the active credential and is never hashed a second time by cache
69
+ * code. Request identity uses recursively key-sorted JSON of only
70
+ * `query` and Provider controls.
71
+ */
72
+ export interface SearchCacheIdentity {
73
+ readonly provider: ProviderId;
74
+ readonly capability: "search";
75
+ readonly credentialFingerprint: string;
76
+ readonly request: Readonly<SearchRequest>;
77
+ readonly legacyCandidates?: readonly LegacySearchCacheCandidate[];
78
+ }
79
+ /**
80
+ * Search Capability contract. Every Adapter that supports Search
81
+ * implements this interface and is consumed by shared execution. The
82
+ * Adapter owns Provider field mapping; commands call only these three
83
+ * methods.
84
+ */
85
+ export interface SearchCapability {
86
+ /**
87
+ * Validate a request before any Provider access. Throws
88
+ * `ValidationError` for an empty or whitespace-only query, and
89
+ * `UnsupportedOptionError` for Provider-specific options the Adapter
90
+ * does not accept. Validation must occur before credential resolution
91
+ * or transport construction.
92
+ */
93
+ validate(request: SearchRequest): void;
94
+ /**
95
+ * Build the cache identity for a request. Called only after
96
+ * `validate` succeeds. `compatibility.legacyCount` is the optional
97
+ * command count; it may enter only `legacyCandidates` and never the
98
+ * new request identity.
99
+ */
100
+ cacheIdentity(request: SearchRequest, compatibility?: {
101
+ readonly legacyCount?: number;
102
+ }): SearchCacheIdentity;
103
+ /**
104
+ * Invoke the Provider and return normalized sources. The Adapter
105
+ * closes its transport and never retries inside this method; shared
106
+ * execution owns retry policy.
107
+ */
108
+ invoke(request: SearchRequest): Promise<readonly SearchSource[]>;
109
+ }
110
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/capabilities/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAMxD,2DAA2D;AAC3D,MAAM,MAAM,aAAa,GACrB,QAAQ,GACR,SAAS,GACT,UAAU,GACV,SAAS,GACT,SAAS,CAAC;AAEd;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,WAAW,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAChC,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,C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
2
+ * Search Capability Contract (DESIGN.md §7, PRD FR-010 through FR-016).
3
+ *
4
+ * Defines the normalized meaning shared by every Search Provider.
5
+ * Commands consume the Capability through `SearchCapability.invoke`,
6
+ * which returns `SearchSource[]` in the Provider-agnostic shape. All
7
+ * Provider-specific fields (rank, occurrence count, count, summary
8
+ * truncation, field projection, presentation) remain command meaning.
9
+ *
10
+ * The Cache Identity contract (`SearchCacheIdentity`,
11
+ * `LegacySearchCacheCandidate`) is declared here so P2-02 can wire
12
+ * Provider-partitioned cache keys without further type changes.
13
+ *
14
+ * Phase 2 implements only this contract. The Z.AI and MiniMax Search
15
+ * Adapters arrive in P2-03 and P2-04; the production registry arrives
16
+ * in P2-05. The Provider descriptors advertised in P2-01 already
17
+ * declare the search Capability, so command wiring can begin once the
18
+ * Adapters exist.
19
+ */
20
+ export {};
21
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/capabilities/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Provider Vision Capability (DESIGN.md §8, PRD FR-020, FR-022 to FR-026,
3
+ * FR-050, NFR-004, NFR-006).
4
+ *
5
+ * Defines the normalized Vision Capability shared by every Provider that
6
+ * supports single-image interpretation. Commands pass a `VisionRequest`
7
+ * (a discriminated union over the eight operation shapes) and the
8
+ * shared `invokeVision` helper:
9
+ *
10
+ * 1. Maps the operation to a stable `vision.<operation>` Capability id.
11
+ * 2. Reads descriptor-level capability metadata (pure; no Adapter
12
+ * construction). If the descriptor does not advertise the
13
+ * Capability, throws `UnsupportedCapabilityError(provider, ...)`
14
+ * BEFORE `descriptor.create()` is called. No credentials, no media,
15
+ * no transport, no cache, no fallback Adapter are observed.
16
+ * 3. Calls `descriptor.create(context)` and defensively double-checks
17
+ * the Adapter's `supports(operation)`. If the Adapter says no,
18
+ * throws the same error before `invoke` runs.
19
+ * 4. Calls `adapter.vision.invoke(request)` and returns the normalized
20
+ * text. Vision never uses the response cache and never falls back
21
+ * to another Provider.
22
+ *
23
+ * This module imports no Provider transport and no Provider Adapter.
24
+ * The error class import below is from `lib/errors.ts` (a shared error
25
+ * contract, not Provider transport), which is the existing boundary
26
+ * pattern for the Search Capability Module. The retry wrapper lives
27
+ * above `invokeVision` and passes a `() => Promise<string>` closure so
28
+ * Vision can be invoked through `executeProviderOperation("vision",
29
+ * ...)` (DESIGN.md §10) without coupling this file to that contract.
30
+ *
31
+ * P3-01 introduces only the contract + the early-fail ordering proof.
32
+ * Real Z.AI and MiniMax `vision` Adapters arrive in P3-03; the
33
+ * built-in descriptor factories in `providers/types.ts` advertise
34
+ * `vision.<operation>` Capability metadata now so the support check is
35
+ * wired through descriptor metadata from the start.
36
+ */
37
+ /**
38
+ * A Provider-neutral Vision request. Commands construct one of these
39
+ * shapes from their semantic arguments; Adapters map them to the
40
+ * Provider's transport shape. Adding a new operation requires extending
41
+ * this union, the `ProviderCapability` union in `providers/types.ts`,
42
+ * and the `ALL_VISION_OPERATIONS` set below.
43
+ */
44
+ export type VisionRequest = {
45
+ operation: "interpret-image";
46
+ source: string;
47
+ instruction: string;
48
+ } | {
49
+ operation: "ui-artifact";
50
+ source: string;
51
+ instruction: string;
52
+ outputType: "code" | "prompt" | "spec" | "description";
53
+ } | {
54
+ operation: "extract-text";
55
+ source: string;
56
+ instruction: string;
57
+ programmingLanguage?: string;
58
+ } | {
59
+ operation: "diagnose-error";
60
+ source: string;
61
+ instruction: string;
62
+ context?: string;
63
+ } | {
64
+ operation: "diagram";
65
+ source: string;
66
+ instruction: string;
67
+ diagramType?: string;
68
+ } | {
69
+ operation: "chart";
70
+ source: string;
71
+ instruction: string;
72
+ focus?: string;
73
+ } | {
74
+ operation: "diff";
75
+ expectedSource: string;
76
+ actualSource: string;
77
+ instruction: string;
78
+ } | {
79
+ operation: "video";
80
+ source: string;
81
+ instruction: string;
82
+ };
83
+ /** Convenience: the set of every supported operation. */
84
+ export type VisionOperation = VisionRequest["operation"];
85
+ /** Every operation that exists in the discriminated union. */
86
+ export declare const ALL_VISION_OPERATIONS: ReadonlySet<VisionOperation>;
87
+ /**
88
+ * Stable Capability id for a Vision operation. Each id matches a member
89
+ * of the `ProviderCapability` union declared in `providers/types.ts`.
90
+ * This mapping is the single source of truth: Adapters advertise the id;
91
+ * `invokeVision` reads it; commands never branch on the id directly.
92
+ */
93
+ export declare function visionOperationToCapability(operation: VisionOperation): "vision.interpret-image" | "vision.ui-artifact" | "vision.extract-text" | "vision.diagnose-error" | "vision.diagram" | "vision.chart" | "vision.diff" | "vision.video";
94
+ /**
95
+ * Vision Capability contract. Every Adapter that supports a Vision
96
+ * operation implements this interface and exposes it as `adapter.vision`.
97
+ * The Adapter owns Provider field mapping, transport, and credentials;
98
+ * commands call only these two methods.
99
+ *
100
+ * `supports` is a pure metadata check. It MUST NOT construct a
101
+ * transport, read a credential, inspect a source, or perform I/O. The
102
+ * shared `invokeVision` helper uses descriptor metadata first and
103
+ * `supports` only as a defensive double-check after `create()`.
104
+ */
105
+ export interface VisionCapability {
106
+ /**
107
+ * Report whether the Adapter can perform `operation` against the
108
+ * current environment. Pure metadata; no construction.
109
+ */
110
+ supports(operation: VisionOperation): boolean;
111
+ /**
112
+ * Invoke the Provider and return the normalized text result. The
113
+ * Adapter owns credentials, transport lifecycle, Provider field
114
+ * mapping, and failure normalization. The Adapter closes its
115
+ * transport and never retries inside this method.
116
+ */
117
+ invoke(request: VisionRequest): Promise<string>;
118
+ }
119
+ /**
120
+ * Minimal Adapter shape `invokeVision` needs. Defined here (instead of
121
+ * importing from `providers/types.ts`) so this file remains free of
122
+ * any Provider imports — the Boundary rule for Capability Modules
123
+ * (ARCHITECTURE.md §2).
124
+ *
125
+ * The descriptor's `create(context)` returns a `ProviderAdapter`; the
126
+ * shared helper accepts anything that exposes `id` and an optional
127
+ * `vision` VisionCapability, matching the Phase 3 ProviderAdapter
128
+ * shape defined in DESIGN.md §5.
129
+ */
130
+ export interface VisionInvocationDescriptor {
131
+ readonly id: string;
132
+ capabilities(): ReadonlySet<string>;
133
+ create(context: {
134
+ readonly env: NodeJS.ProcessEnv;
135
+ }): {
136
+ readonly id: string;
137
+ readonly vision?: VisionCapability;
138
+ };
139
+ }
140
+ /**
141
+ * Invoke a Vision request through a Provider descriptor. The support
142
+ * check happens BEFORE `descriptor.create()` (using descriptor
143
+ * metadata) and is then double-checked against the Adapter's
144
+ * `supports` after construction. Failures throw
145
+ * `UnsupportedCapabilityError` and never touch credentials, media,
146
+ * transport, cache, or a fallback Adapter.
147
+ *
148
+ * Phase 3 P3-01 introduces the contract and the early-fail ordering
149
+ * proof; Phase 3 P3-03 supplies the real Adapter implementations.
150
+ * Until then the built-in descriptors advertise metadata so the
151
+ * ordering is provable today.
152
+ */
153
+ export declare function invokeVision(descriptor: VisionInvocationDescriptor, request: VisionRequest, context: {
154
+ readonly env: NodeJS.ProcessEnv;
155
+ }): Promise<string>;
156
+ //# sourceMappingURL=vision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision.d.ts","sourceRoot":"","sources":["../../src/capabilities/vision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAQH;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GACrB;IACE,SAAS,EAAE,iBAAiB,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IACE,SAAS,EAAE,aAAa,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,aAAa,CAAC;CACxD,GACD;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,GAC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;IACzC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,YAAY,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;KAAE,GAAG;QACpD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;KACpC,CAAC;CACH;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,0BAA0B,EACtC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;CAAE,GAC3C,OAAO,CAAC,MAAM,CAAC,CAuBjB"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Provider Vision Capability (DESIGN.md §8, PRD FR-020, FR-022 to FR-026,
3
+ * FR-050, NFR-004, NFR-006).
4
+ *
5
+ * Defines the normalized Vision Capability shared by every Provider that
6
+ * supports single-image interpretation. Commands pass a `VisionRequest`
7
+ * (a discriminated union over the eight operation shapes) and the
8
+ * shared `invokeVision` helper:
9
+ *
10
+ * 1. Maps the operation to a stable `vision.<operation>` Capability id.
11
+ * 2. Reads descriptor-level capability metadata (pure; no Adapter
12
+ * construction). If the descriptor does not advertise the
13
+ * Capability, throws `UnsupportedCapabilityError(provider, ...)`
14
+ * BEFORE `descriptor.create()` is called. No credentials, no media,
15
+ * no transport, no cache, no fallback Adapter are observed.
16
+ * 3. Calls `descriptor.create(context)` and defensively double-checks
17
+ * the Adapter's `supports(operation)`. If the Adapter says no,
18
+ * throws the same error before `invoke` runs.
19
+ * 4. Calls `adapter.vision.invoke(request)` and returns the normalized
20
+ * text. Vision never uses the response cache and never falls back
21
+ * to another Provider.
22
+ *
23
+ * This module imports no Provider transport and no Provider Adapter.
24
+ * The error class import below is from `lib/errors.ts` (a shared error
25
+ * contract, not Provider transport), which is the existing boundary
26
+ * pattern for the Search Capability Module. The retry wrapper lives
27
+ * above `invokeVision` and passes a `() => Promise<string>` closure so
28
+ * Vision can be invoked through `executeProviderOperation("vision",
29
+ * ...)` (DESIGN.md §10) without coupling this file to that contract.
30
+ *
31
+ * P3-01 introduces only the contract + the early-fail ordering proof.
32
+ * Real Z.AI and MiniMax `vision` Adapters arrive in P3-03; the
33
+ * built-in descriptor factories in `providers/types.ts` advertise
34
+ * `vision.<operation>` Capability metadata now so the support check is
35
+ * wired through descriptor metadata from the start.
36
+ */
37
+ import { UnsupportedCapabilityError } from "../lib/errors.js";
38
+ /** Every operation that exists in the discriminated union. */
39
+ export const ALL_VISION_OPERATIONS = new Set([
40
+ "interpret-image",
41
+ "ui-artifact",
42
+ "extract-text",
43
+ "diagnose-error",
44
+ "diagram",
45
+ "chart",
46
+ "diff",
47
+ "video",
48
+ ]);
49
+ // ---------------------------------------------------------------------------
50
+ // Operation → Capability id mapping (no Provider imports)
51
+ // ---------------------------------------------------------------------------
52
+ /**
53
+ * Stable Capability id for a Vision operation. Each id matches a member
54
+ * of the `ProviderCapability` union declared in `providers/types.ts`.
55
+ * This mapping is the single source of truth: Adapters advertise the id;
56
+ * `invokeVision` reads it; commands never branch on the id directly.
57
+ */
58
+ export function visionOperationToCapability(operation) {
59
+ switch (operation) {
60
+ case "interpret-image":
61
+ return "vision.interpret-image";
62
+ case "ui-artifact":
63
+ return "vision.ui-artifact";
64
+ case "extract-text":
65
+ return "vision.extract-text";
66
+ case "diagnose-error":
67
+ return "vision.diagnose-error";
68
+ case "diagram":
69
+ return "vision.diagram";
70
+ case "chart":
71
+ return "vision.chart";
72
+ case "diff":
73
+ return "vision.diff";
74
+ case "video":
75
+ return "vision.video";
76
+ }
77
+ }
78
+ /**
79
+ * Invoke a Vision request through a Provider descriptor. The support
80
+ * check happens BEFORE `descriptor.create()` (using descriptor
81
+ * metadata) and is then double-checked against the Adapter's
82
+ * `supports` after construction. Failures throw
83
+ * `UnsupportedCapabilityError` and never touch credentials, media,
84
+ * transport, cache, or a fallback Adapter.
85
+ *
86
+ * Phase 3 P3-01 introduces the contract and the early-fail ordering
87
+ * proof; Phase 3 P3-03 supplies the real Adapter implementations.
88
+ * Until then the built-in descriptors advertise metadata so the
89
+ * ordering is provable today.
90
+ */
91
+ export async function invokeVision(descriptor, request, context) {
92
+ const capabilityId = visionOperationToCapability(request.operation);
93
+ // Step 1: descriptor-level metadata. NO create(), NO construction.
94
+ if (!descriptor.capabilities().has(capabilityId)) {
95
+ throw new UnsupportedCapabilityError(descriptor.id, capabilityId);
96
+ }
97
+ // Step 2: create() is allowed now — it is side-effect-free, only
98
+ // captures the injected env. Credentials, transport, and SDK are
99
+ // built lazily inside Capability invocation.
100
+ const adapter = descriptor.create(context);
101
+ // Step 3: defensive double-check against the Adapter's own metadata.
102
+ // If the Adapter says no, fail closed before invoke runs.
103
+ const vision = adapter.vision;
104
+ if (!vision || !vision.supports(request.operation)) {
105
+ throw new UnsupportedCapabilityError(descriptor.id, capabilityId);
106
+ }
107
+ // Step 4: invoke. No cache lookup, no fallback Adapter. Retries live
108
+ // above this call in `executeProviderOperation("vision", ...)`.
109
+ return vision.invoke(request);
110
+ }
111
+ //# sourceMappingURL=vision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision.js","sourceRoot":"","sources":["../../src/capabilities/vision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAgE9D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAAiC,IAAI,GAAG,CAAC;IACzE,iBAAiB;IACjB,aAAa;IACb,cAAc;IACd,gBAAgB;IAChB,SAAS;IACT,OAAO;IACP,MAAM;IACN,OAAO;CACR,CAAC,CAAC;AAEH,8EAA8E;AAC9E,0DAA0D;AAC1D,8EAA8E;AAE9E;;;;;GAKG;AACH,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,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Command Invocation Seam (DESIGN.md §2).
3
+ *
4
+ * This Module defines the pure invocation contract that separates
5
+ * command behaviour from process effects. `invokeCommand` owns
6
+ * invocation-local presentation, notice storage, and error conversion.
7
+ * The Node Adapter is the only Module that touches process streams,
8
+ * TTY state, and `process.exitCode`.
9
+ *
10
+ * Requirements: NFR-002, NFR-003, NFR-007.
11
+ */
12
+ import type { OutputMode } from "./lib/output.js";
13
+ export type TextOutputMode = "compact" | "markdown" | "refs" | "tty";
14
+ export type CommandPresentations = Readonly<Partial<Record<TextOutputMode, string>>>;
15
+ export interface DataCommandResult<T = unknown> {
16
+ readonly kind: "data";
17
+ readonly data: T;
18
+ readonly presentations?: CommandPresentations;
19
+ readonly exitCode?: number;
20
+ }
21
+ export interface TextCommandResult {
22
+ readonly kind: "text";
23
+ readonly text: string;
24
+ readonly exitCode?: number;
25
+ }
26
+ export type CommandResult<T = unknown> = DataCommandResult<T> | TextCommandResult;
27
+ export interface CommandContext {
28
+ readonly stdinIsTTY: boolean;
29
+ readStdin(): Promise<string>;
30
+ notice(message: string): void;
31
+ }
32
+ export interface CommandInvocationAdapter {
33
+ readonly stdoutIsTTY: boolean;
34
+ readonly stdinIsTTY: boolean;
35
+ readonly environmentOutputMode?: string;
36
+ readStdin(): Promise<string>;
37
+ writeStdout(value: string): void;
38
+ writeStderr(value: string): void;
39
+ runQuietly<T>(operation: () => Promise<T>): Promise<T>;
40
+ setExitCode(value: number): void;
41
+ }
42
+ /**
43
+ * Run command behaviour through the invocation seam.
44
+ *
45
+ * 1. Create invocation-local context and notice storage.
46
+ * 2. Run command behaviour through `runQuietly`.
47
+ * 3. `runQuietly` restores dependency logging before returning.
48
+ * 4. Flush notices to stderr in encounter order.
49
+ * 5. Select a presentation override or the base data.
50
+ * 6. Write one final successful value to stdout.
51
+ * 7. Convert a thrown error into one structured stderr value.
52
+ * 8. Return an exit status without terminating the process.
53
+ *
54
+ * The trailing newline is appended at the Node Adapter boundary, not
55
+ * here, so `invokeCommand` itself is process-effect-free.
56
+ */
57
+ export declare function invokeCommand(adapter: CommandInvocationAdapter, behavior: (context: CommandContext) => Promise<CommandResult>, outputMode: OutputMode, now?: () => number, secrets?: string[]): Promise<number>;
58
+ //# sourceMappingURL=command-invocation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-invocation.d.ts","sourceRoot":"","sources":["../src/command-invocation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKlD,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,MAAM,GAAG,KAAK,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAErF,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,OAAO;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,aAAa,CAAC,EAAE,oBAAoB,CAAC;IAC9C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,CAAC;AAElF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IA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