@moxxy/sdk 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 (211) hide show
  1. package/dist/agent.d.ts +39 -0
  2. package/dist/agent.d.ts.map +1 -0
  3. package/dist/agent.js +2 -0
  4. package/dist/agent.js.map +1 -0
  5. package/dist/cache-strategy.d.ts +35 -0
  6. package/dist/cache-strategy.d.ts.map +1 -0
  7. package/dist/cache-strategy.js +2 -0
  8. package/dist/cache-strategy.js.map +1 -0
  9. package/dist/channel.d.ts +146 -0
  10. package/dist/channel.d.ts.map +1 -0
  11. package/dist/channel.js +2 -0
  12. package/dist/channel.js.map +1 -0
  13. package/dist/client-session.d.ts +83 -0
  14. package/dist/client-session.d.ts.map +1 -0
  15. package/dist/client-session.js +2 -0
  16. package/dist/client-session.js.map +1 -0
  17. package/dist/command.d.ts +90 -0
  18. package/dist/command.d.ts.map +1 -0
  19. package/dist/command.js +15 -0
  20. package/dist/command.js.map +1 -0
  21. package/dist/compactor-helpers.d.ts +34 -0
  22. package/dist/compactor-helpers.d.ts.map +1 -0
  23. package/dist/compactor-helpers.js +156 -0
  24. package/dist/compactor-helpers.js.map +1 -0
  25. package/dist/compactor.d.ts +20 -0
  26. package/dist/compactor.d.ts.map +1 -0
  27. package/dist/compactor.js +2 -0
  28. package/dist/compactor.js.map +1 -0
  29. package/dist/define.d.ts +51 -0
  30. package/dist/define.d.ts.map +1 -0
  31. package/dist/define.js +71 -0
  32. package/dist/define.js.map +1 -0
  33. package/dist/elision-helpers.d.ts +27 -0
  34. package/dist/elision-helpers.d.ts.map +1 -0
  35. package/dist/elision-helpers.js +109 -0
  36. package/dist/elision-helpers.js.map +1 -0
  37. package/dist/elision-state.d.ts +49 -0
  38. package/dist/elision-state.d.ts.map +1 -0
  39. package/dist/elision-state.js +144 -0
  40. package/dist/elision-state.js.map +1 -0
  41. package/dist/embedding-cache.d.ts +32 -0
  42. package/dist/embedding-cache.d.ts.map +1 -0
  43. package/dist/embedding-cache.js +0 -0
  44. package/dist/embedding-cache.js.map +1 -0
  45. package/dist/embedding.d.ts +21 -0
  46. package/dist/embedding.d.ts.map +1 -0
  47. package/dist/embedding.js +2 -0
  48. package/dist/embedding.js.map +1 -0
  49. package/dist/errors.d.ts +81 -0
  50. package/dist/errors.d.ts.map +1 -0
  51. package/dist/errors.js +241 -0
  52. package/dist/errors.js.map +1 -0
  53. package/dist/events.d.ts +193 -0
  54. package/dist/events.d.ts.map +1 -0
  55. package/dist/events.js +2 -0
  56. package/dist/events.js.map +1 -0
  57. package/dist/hooks.d.ts +52 -0
  58. package/dist/hooks.d.ts.map +1 -0
  59. package/dist/hooks.js +2 -0
  60. package/dist/hooks.js.map +1 -0
  61. package/dist/ids.d.ts +18 -0
  62. package/dist/ids.d.ts.map +1 -0
  63. package/dist/ids.js +7 -0
  64. package/dist/ids.js.map +1 -0
  65. package/dist/index.d.ts +45 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +18 -0
  68. package/dist/index.js.map +1 -0
  69. package/dist/install-hints.d.ts +26 -0
  70. package/dist/install-hints.d.ts.map +1 -0
  71. package/dist/install-hints.js +15 -0
  72. package/dist/install-hints.js.map +1 -0
  73. package/dist/isolation.d.ts +125 -0
  74. package/dist/isolation.d.ts.map +1 -0
  75. package/dist/isolation.js +11 -0
  76. package/dist/isolation.js.map +1 -0
  77. package/dist/log.d.ts +11 -0
  78. package/dist/log.d.ts.map +1 -0
  79. package/dist/log.js +2 -0
  80. package/dist/log.js.map +1 -0
  81. package/dist/mode-helpers.d.ts +99 -0
  82. package/dist/mode-helpers.d.ts.map +1 -0
  83. package/dist/mode-helpers.js +368 -0
  84. package/dist/mode-helpers.js.map +1 -0
  85. package/dist/mode.d.ts +133 -0
  86. package/dist/mode.d.ts.map +1 -0
  87. package/dist/mode.js +2 -0
  88. package/dist/mode.js.map +1 -0
  89. package/dist/permission.d.ts +35 -0
  90. package/dist/permission.d.ts.map +1 -0
  91. package/dist/permission.js +2 -0
  92. package/dist/permission.js.map +1 -0
  93. package/dist/plugin.d.ts +88 -0
  94. package/dist/plugin.d.ts.map +1 -0
  95. package/dist/plugin.js +2 -0
  96. package/dist/plugin.js.map +1 -0
  97. package/dist/provider-utils.d.ts +40 -0
  98. package/dist/provider-utils.d.ts.map +1 -0
  99. package/dist/provider-utils.js +163 -0
  100. package/dist/provider-utils.js.map +1 -0
  101. package/dist/provider.d.ts +219 -0
  102. package/dist/provider.d.ts.map +1 -0
  103. package/dist/provider.js +2 -0
  104. package/dist/provider.js.map +1 -0
  105. package/dist/requirements.d.ts +22 -0
  106. package/dist/requirements.d.ts.map +1 -0
  107. package/dist/requirements.js +2 -0
  108. package/dist/requirements.js.map +1 -0
  109. package/dist/schemas.d.ts +228 -0
  110. package/dist/schemas.d.ts.map +1 -0
  111. package/dist/schemas.js +88 -0
  112. package/dist/schemas.js.map +1 -0
  113. package/dist/session-like.d.ts +111 -0
  114. package/dist/session-like.d.ts.map +1 -0
  115. package/dist/session-like.js +2 -0
  116. package/dist/session-like.js.map +1 -0
  117. package/dist/skill.d.ts +30 -0
  118. package/dist/skill.d.ts.map +1 -0
  119. package/dist/skill.js +2 -0
  120. package/dist/skill.js.map +1 -0
  121. package/dist/subagent.d.ts +45 -0
  122. package/dist/subagent.d.ts.map +1 -0
  123. package/dist/subagent.js +11 -0
  124. package/dist/subagent.js.map +1 -0
  125. package/dist/token-accounting.d.ts +73 -0
  126. package/dist/token-accounting.d.ts.map +1 -0
  127. package/dist/token-accounting.js +129 -0
  128. package/dist/token-accounting.js.map +1 -0
  129. package/dist/tool-dispatch.d.ts +19 -0
  130. package/dist/tool-dispatch.d.ts.map +1 -0
  131. package/dist/tool-dispatch.js +118 -0
  132. package/dist/tool-dispatch.js.map +1 -0
  133. package/dist/tool-gating.d.ts +32 -0
  134. package/dist/tool-gating.d.ts.map +1 -0
  135. package/dist/tool-gating.js +83 -0
  136. package/dist/tool-gating.js.map +1 -0
  137. package/dist/tool.d.ts +166 -0
  138. package/dist/tool.d.ts.map +1 -0
  139. package/dist/tool.js +2 -0
  140. package/dist/tool.js.map +1 -0
  141. package/dist/transcriber.d.ts +64 -0
  142. package/dist/transcriber.d.ts.map +1 -0
  143. package/dist/transcriber.js +21 -0
  144. package/dist/transcriber.js.map +1 -0
  145. package/dist/tunnel.d.ts +25 -0
  146. package/dist/tunnel.d.ts.map +1 -0
  147. package/dist/tunnel.js +2 -0
  148. package/dist/tunnel.js.map +1 -0
  149. package/dist/type-contracts.d.ts +2 -0
  150. package/dist/type-contracts.d.ts.map +1 -0
  151. package/dist/type-contracts.js +4 -0
  152. package/dist/type-contracts.js.map +1 -0
  153. package/dist/types.test-d.d.ts +2 -0
  154. package/dist/types.test-d.d.ts.map +1 -0
  155. package/dist/types.test-d.js +22 -0
  156. package/dist/types.test-d.js.map +1 -0
  157. package/dist/view-renderer.d.ts +97 -0
  158. package/dist/view-renderer.d.ts.map +1 -0
  159. package/dist/view-renderer.js +72 -0
  160. package/dist/view-renderer.js.map +1 -0
  161. package/package.json +38 -0
  162. package/src/agent.ts +38 -0
  163. package/src/cache-strategy.ts +39 -0
  164. package/src/channel.ts +158 -0
  165. package/src/client-session.ts +88 -0
  166. package/src/command.ts +86 -0
  167. package/src/compactor-helpers.test.ts +206 -0
  168. package/src/compactor-helpers.ts +163 -0
  169. package/src/compactor.ts +20 -0
  170. package/src/define.test.ts +76 -0
  171. package/src/define.ts +113 -0
  172. package/src/elision-helpers.ts +143 -0
  173. package/src/elision-state.ts +170 -0
  174. package/src/embedding-cache.ts +0 -0
  175. package/src/embedding.ts +22 -0
  176. package/src/errors.test.ts +176 -0
  177. package/src/errors.ts +308 -0
  178. package/src/events.ts +250 -0
  179. package/src/hooks.ts +54 -0
  180. package/src/ids.ts +16 -0
  181. package/src/index.ts +304 -0
  182. package/src/install-hints.ts +43 -0
  183. package/src/isolation.ts +148 -0
  184. package/src/log.ts +11 -0
  185. package/src/loop-helpers.test.ts +78 -0
  186. package/src/mode-helpers.ts +483 -0
  187. package/src/mode.ts +139 -0
  188. package/src/package-root.test.ts +40 -0
  189. package/src/permission.ts +37 -0
  190. package/src/plugin.ts +92 -0
  191. package/src/provider-utils.test.ts +84 -0
  192. package/src/provider-utils.ts +171 -0
  193. package/src/provider.ts +195 -0
  194. package/src/requirements.ts +35 -0
  195. package/src/schemas.test.ts +106 -0
  196. package/src/schemas.ts +97 -0
  197. package/src/session-like.ts +118 -0
  198. package/src/skill.ts +34 -0
  199. package/src/subagent.ts +46 -0
  200. package/src/token-accounting.test.ts +93 -0
  201. package/src/token-accounting.ts +202 -0
  202. package/src/token-efficiency.test.ts +459 -0
  203. package/src/tool-dispatch.ts +137 -0
  204. package/src/tool-gating.ts +107 -0
  205. package/src/tool.ts +175 -0
  206. package/src/transcriber.ts +71 -0
  207. package/src/tunnel.ts +26 -0
  208. package/src/type-contracts.ts +4 -0
  209. package/src/types.test-d.ts +29 -0
  210. package/src/view-renderer.test.ts +90 -0
  211. package/src/view-renderer.ts +156 -0
@@ -0,0 +1,35 @@
1
+ import type { ToolCallRequestedEvent } from './events.js';
2
+ export type PermissionMode = 'allow' | 'allow_session' | 'allow_always' | 'deny';
3
+ export interface PermissionDecision {
4
+ readonly mode: PermissionMode;
5
+ readonly reason?: string;
6
+ }
7
+ export interface PermissionRule {
8
+ readonly action: 'allow' | 'deny' | 'prompt';
9
+ readonly pattern?: {
10
+ name?: string | RegExp;
11
+ inputMatches?: Record<string, string | RegExp>;
12
+ };
13
+ readonly reason?: string;
14
+ }
15
+ export interface PendingToolCall {
16
+ readonly callId: ToolCallRequestedEvent['callId'];
17
+ readonly name: string;
18
+ readonly input: unknown;
19
+ /**
20
+ * Sequence number of the `tool_call_requested` event in the EventLog.
21
+ * Optional because permission resolvers may construct PendingToolCalls
22
+ * for evaluations that aren't yet on the log (e.g., hook rewrites).
23
+ */
24
+ readonly requestedAtSeq?: number;
25
+ }
26
+ export interface PermissionContext {
27
+ readonly toolDescription?: string;
28
+ readonly skillContext?: string;
29
+ readonly sessionId: string;
30
+ }
31
+ export interface PermissionResolver {
32
+ readonly name: string;
33
+ check(call: PendingToolCall, ctx: PermissionContext): Promise<PermissionDecision>;
34
+ }
35
+ //# sourceMappingURL=permission.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,eAAe,GAAG,cAAc,GAAG,MAAM,CAAC;AAEjF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC7C,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;KAAE,CAAC;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACnF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=permission.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission.js","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":""}
@@ -0,0 +1,88 @@
1
+ import type { AgentDef } from './agent.js';
2
+ import type { CacheStrategyDef } from './cache-strategy.js';
3
+ import type { ChannelDef } from './channel.js';
4
+ import type { CommandDef } from './command.js';
5
+ import type { CompactorDef } from './compactor.js';
6
+ import type { LifecycleHooks } from './hooks.js';
7
+ import type { ModeDef } from './mode.js';
8
+ import type { ProviderDef } from './provider.js';
9
+ import type { MoxxyRequirement } from './requirements.js';
10
+ import type { ToolDef } from './tool.js';
11
+ import type { TranscriberDef } from './transcriber.js';
12
+ import type { ViewRendererDef } from './view-renderer.js';
13
+ import type { TunnelProviderDef } from './tunnel.js';
14
+ export type PluginKind = 'tools' | 'provider' | 'mode' | 'compactor' | 'cache-strategy' | 'view-renderer' | 'tunnel-provider' | 'mcp' | 'cli' | 'channel' | 'hooks' | 'agent' | 'command' | 'transcriber';
15
+ export interface PluginSpec {
16
+ readonly name: string;
17
+ readonly version?: string;
18
+ readonly tools?: ReadonlyArray<ToolDef>;
19
+ readonly providers?: ReadonlyArray<ProviderDef>;
20
+ readonly modes?: ReadonlyArray<ModeDef>;
21
+ readonly compactors?: ReadonlyArray<CompactorDef>;
22
+ /**
23
+ * Prompt-caching strategies contributed by the plugin. One is active per
24
+ * session (selected via `session.cacheStrategies.setActive(name)`); the
25
+ * active strategy decides where cache breakpoints go for each provider call.
26
+ */
27
+ readonly cacheStrategies?: ReadonlyArray<CacheStrategyDef>;
28
+ /**
29
+ * View-spec renderers contributed by the plugin. One is active per session
30
+ * (selected via `session.viewRenderers.setActive(name)`); the active renderer
31
+ * parses the agent's view-spec into a validated AST for `present_view`. A
32
+ * default renderer ships with core, so this is only for replacing it.
33
+ */
34
+ readonly viewRenderers?: ReadonlyArray<ViewRendererDef>;
35
+ /**
36
+ * Tunnel providers that expose the local web surface publicly (e.g.
37
+ * cloudflared). One active per session; core seeds a `localhost` no-op.
38
+ */
39
+ readonly tunnelProviders?: ReadonlyArray<TunnelProviderDef>;
40
+ readonly channels?: ReadonlyArray<ChannelDef>;
41
+ /**
42
+ * Speech-to-text backends contributed by the plugin. Selected by name via
43
+ * `session.transcribers.setActive(name)`; channels with audio input use
44
+ * `session.transcribers.getActive()` to convert bytes → transcript when
45
+ * the active provider does not advertise `supportsAudio`.
46
+ */
47
+ readonly transcribers?: ReadonlyArray<TranscriberDef>;
48
+ /**
49
+ * Typed subagent kinds the plugin contributes. Each becomes
50
+ * dispatchable as `dispatch_agent({ agentType: <name>, ... })`.
51
+ * When NO plugin registers any agents (and no plugin registers the
52
+ * dispatch tool itself), the model has no subagent capability and
53
+ * the system degrades to the normal single-loop flow.
54
+ */
55
+ readonly agents?: ReadonlyArray<AgentDef>;
56
+ /**
57
+ * Slash commands contributed to every channel — the TUI's slash
58
+ * menu, the Telegram bot's command list, and any future channel
59
+ * that consumes `session.commands`. Use this for actions that make
60
+ * sense regardless of UI (`/info`, `/clear`, custom domain commands
61
+ * like `/deploy`); leave channel-specific UI commands (overlay
62
+ * pickers, raw-mode toggles) inside the channel itself.
63
+ */
64
+ readonly commands?: ReadonlyArray<CommandDef>;
65
+ readonly hooks?: LifecycleHooks;
66
+ readonly skillsDir?: string;
67
+ }
68
+ export interface Plugin extends PluginSpec {
69
+ readonly __moxxy: 'plugin';
70
+ readonly version: string;
71
+ }
72
+ export interface PluginManifest {
73
+ readonly entry: string;
74
+ readonly kind?: PluginKind | ReadonlyArray<PluginKind>;
75
+ readonly skills?: string;
76
+ }
77
+ export interface ResolvedPluginManifest extends PluginManifest {
78
+ readonly packageName: string;
79
+ readonly packageVersion: string;
80
+ readonly packagePath: string;
81
+ /**
82
+ * Requirements declared at `package.json#moxxy.requirements`. Statically
83
+ * authored — never derived from code. Drives plugin toposort and the
84
+ * pre-load readiness gate.
85
+ */
86
+ readonly requirements?: ReadonlyArray<MoxxyRequirement>;
87
+ }
88
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,gBAAgB,GAAG,eAAe,GAAG,iBAAiB,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,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AM,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IACvD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;CACzD"}
package/dist/plugin.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Small helpers that provider plugins share. Lives in the SDK because plugins
3
+ * are only allowed to depend on @moxxy/sdk, not core.
4
+ */
5
+ /** Canonical stop reasons emitted on `message_end` events. */
6
+ export type StopReason = 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence' | 'error';
7
+ /**
8
+ * Heuristic: should a provider request retry on this error? Used by stream
9
+ * modes to attach a `retryable: boolean` flag to the `error` event so callers
10
+ * (or the loop strategy) can decide whether to back off and try again.
11
+ *
12
+ * Identical implementation across plugin-provider-anthropic and -openai;
13
+ * hoisted here so a new provider plugin can stay consistent.
14
+ */
15
+ export declare function isRetryableError(err: unknown): boolean;
16
+ /**
17
+ * Build a friendly error event for `ProviderEvent` streams. Tries to classify
18
+ * the cause as a network failure (turning Node's "fetch failed" into something
19
+ * actionable) before falling back to the raw message. Providers' catch blocks
20
+ * yield the result via:
21
+ * yield { type: 'error', ...toFriendlyError(err, { provider: this.name }) };
22
+ */
23
+ export declare function toFriendlyError(err: unknown, ctx?: {
24
+ readonly url?: string;
25
+ readonly provider?: string;
26
+ }): {
27
+ message: string;
28
+ retryable: boolean;
29
+ };
30
+ /**
31
+ * Best-effort zod → JSON-schema conversion for provider tool definitions.
32
+ * Most callers want the basic object/string/number/boolean/array coverage;
33
+ * for richer schemas, plugins can layer `zod-to-json-schema`.
34
+ *
35
+ * The `as unknown as { ... }` casts below probe zod's `_def` internals
36
+ * (`shape`, `type`) which aren't part of zod's public typed surface but are
37
+ * stable enough across versions to rely on for this best-effort path.
38
+ */
39
+ export declare function zodToJsonSchema(schema: unknown): unknown;
40
+ //# sourceMappingURL=provider-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-utils.d.ts","sourceRoot":"","sources":["../src/provider-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,8DAA8D;AAC9D,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,eAAe,GAAG,OAAO,CAAC;AAE5F;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAYtD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,EACZ,GAAG,GAAE;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9D;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAYzC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAyGxD"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Small helpers that provider plugins share. Lives in the SDK because plugins
3
+ * are only allowed to depend on @moxxy/sdk, not core.
4
+ */
5
+ import { classifyNetworkError } from './errors.js';
6
+ /**
7
+ * Heuristic: should a provider request retry on this error? Used by stream
8
+ * modes to attach a `retryable: boolean` flag to the `error` event so callers
9
+ * (or the loop strategy) can decide whether to back off and try again.
10
+ *
11
+ * Identical implementation across plugin-provider-anthropic and -openai;
12
+ * hoisted here so a new provider plugin can stay consistent.
13
+ */
14
+ export function isRetryableError(err) {
15
+ if (!(err instanceof Error))
16
+ return false;
17
+ // MoxxyError-classified ones carry the verdict in the code.
18
+ const code = err.code;
19
+ if (typeof code === 'string') {
20
+ if (code === 'PROVIDER_RATE_LIMITED' || code === 'PROVIDER_SERVER_ERROR')
21
+ return true;
22
+ if (code === 'NETWORK_TIMEOUT' || code === 'NETWORK_UNREACHABLE')
23
+ return true;
24
+ }
25
+ const msg = err.message.toLowerCase();
26
+ if (msg.includes('rate_limit') || msg.includes('429') || msg.includes('overloaded'))
27
+ return true;
28
+ if (msg.includes('econnreset') || msg.includes('etimedout') || msg.includes('network'))
29
+ return true;
30
+ return false;
31
+ }
32
+ /**
33
+ * Build a friendly error event for `ProviderEvent` streams. Tries to classify
34
+ * the cause as a network failure (turning Node's "fetch failed" into something
35
+ * actionable) before falling back to the raw message. Providers' catch blocks
36
+ * yield the result via:
37
+ * yield { type: 'error', ...toFriendlyError(err, { provider: this.name }) };
38
+ */
39
+ export function toFriendlyError(err, ctx = {}) {
40
+ const classified = classifyNetworkError(err, ctx);
41
+ if (classified) {
42
+ return {
43
+ message: classified.message + (classified.hint ? ` — ${classified.hint}` : ''),
44
+ retryable: isRetryableError(classified),
45
+ };
46
+ }
47
+ return {
48
+ message: err instanceof Error ? err.message : String(err),
49
+ retryable: isRetryableError(err),
50
+ };
51
+ }
52
+ /**
53
+ * Best-effort zod → JSON-schema conversion for provider tool definitions.
54
+ * Most callers want the basic object/string/number/boolean/array coverage;
55
+ * for richer schemas, plugins can layer `zod-to-json-schema`.
56
+ *
57
+ * The `as unknown as { ... }` casts below probe zod's `_def` internals
58
+ * (`shape`, `type`) which aren't part of zod's public typed surface but are
59
+ * stable enough across versions to rely on for this best-effort path.
60
+ */
61
+ export function zodToJsonSchema(schema) {
62
+ const s = schema;
63
+ // Only honor a pre-serialized schema's `toJSON` for NON-zod objects (a plain
64
+ // JSON-schema object passed through). A real zod schema (has `_def`) MUST go
65
+ // through the unwrap below — short-circuiting on a zod `toJSON` (some versions
66
+ // add one) skips the ZodEffects/intersection handling and yields a
67
+ // properties-less object schema that providers like Codex reject.
68
+ if (!s._def && typeof s.toJSON === 'function')
69
+ return s.toJSON();
70
+ const def = s._def;
71
+ const typeName = def?.typeName;
72
+ // ZodEffects (`.refine`, `.transform`, `.superRefine`) is a wrapper —
73
+ // the inner `schema` field holds the real type. Skipping the unwrap
74
+ // leaves us with a properties-less object schema, which providers like
75
+ // Codex's /responses validator reject ("object schema missing properties").
76
+ if (typeName === 'ZodEffects') {
77
+ const inner = def.schema;
78
+ return zodToJsonSchema(inner);
79
+ }
80
+ // ZodOptional / ZodNullable / ZodDefault / ZodBranded / ZodReadonly all
81
+ // wrap an inner schema we want to unwrap for JSON-schema purposes.
82
+ if (typeName === 'ZodOptional' ||
83
+ typeName === 'ZodNullable' ||
84
+ typeName === 'ZodDefault' ||
85
+ typeName === 'ZodBranded' ||
86
+ typeName === 'ZodReadonly') {
87
+ const inner = def.innerType;
88
+ return zodToJsonSchema(inner);
89
+ }
90
+ // `.and(other)` produces a ZodIntersection. The standard JSON-schema
91
+ // representation is `allOf`, but strict validators (Codex again) want
92
+ // each branch to be a complete object schema. Easiest path that satisfies
93
+ // them: when both branches reduce to object schemas, merge properties
94
+ // and required lists into one object. Fall back to `allOf` otherwise.
95
+ if (typeName === 'ZodIntersection') {
96
+ const intersection = def;
97
+ const left = zodToJsonSchema(intersection.left);
98
+ const right = zodToJsonSchema(intersection.right);
99
+ if (left &&
100
+ right &&
101
+ left.type === 'object' &&
102
+ right.type === 'object' &&
103
+ left.properties &&
104
+ right.properties) {
105
+ return {
106
+ type: 'object',
107
+ properties: { ...left.properties, ...right.properties },
108
+ required: Array.from(new Set([
109
+ ...(left.required ?? []),
110
+ ...(right.required ?? []),
111
+ ])),
112
+ };
113
+ }
114
+ return { allOf: [left, right] };
115
+ }
116
+ if (typeName === 'ZodObject') {
117
+ // zod's ZodObject._def has a `shape()` thunk returning the field map.
118
+ const shape = def.shape();
119
+ const properties = {};
120
+ const required = [];
121
+ for (const [key, value] of Object.entries(shape)) {
122
+ properties[key] = zodToJsonSchema(value);
123
+ const isOptional = value.isOptional?.();
124
+ if (!isOptional)
125
+ required.push(key);
126
+ }
127
+ return { type: 'object', properties, required };
128
+ }
129
+ if (typeName === 'ZodString')
130
+ return { type: 'string' };
131
+ if (typeName === 'ZodNumber')
132
+ return { type: 'number' };
133
+ if (typeName === 'ZodBoolean')
134
+ return { type: 'boolean' };
135
+ if (typeName === 'ZodEnum') {
136
+ const values = def.values;
137
+ return { type: 'string', enum: [...values] };
138
+ }
139
+ if (typeName === 'ZodNativeEnum') {
140
+ const values = Object.values(def.values);
141
+ const allString = values.every((v) => typeof v === 'string');
142
+ return { type: allString ? 'string' : 'number', enum: values };
143
+ }
144
+ if (typeName === 'ZodLiteral') {
145
+ const value = def.value;
146
+ const t = value === null ? 'null' : typeof value;
147
+ return { type: t, enum: [value] };
148
+ }
149
+ if (typeName === 'ZodUnion' || typeName === 'ZodDiscriminatedUnion') {
150
+ const options = def.options;
151
+ return { anyOf: options.map((o) => zodToJsonSchema(o)) };
152
+ }
153
+ if (typeName === 'ZodArray') {
154
+ // ZodArray._def.type is the element schema.
155
+ const items = zodToJsonSchema(def.type);
156
+ return { type: 'array', items };
157
+ }
158
+ // Truly unknown — fall back to a permissive "any object" but spell out
159
+ // `properties: {}` and `additionalProperties: true` so strict validators
160
+ // accept the schema instead of bailing on a missing `properties` field.
161
+ return { type: 'object', properties: {}, additionalProperties: true };
162
+ }
163
+ //# sourceMappingURL=provider-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-utils.js","sourceRoot":"","sources":["../src/provider-utils.ts"],"names":[],"mapp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AAE,CAAC;IACpC,CAAC;IACD,IAAI,QAAQ,KAAK,UAAU,IAAI,QAAQ,KAAK,uBAAuB,EAAE,CAAC;QACpE,MAAM,OAAO,GAAI,GAAsD,CAAC,OAAO,CAAC;QAChF,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3D,CAAC;IACD,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;QAC5B,4CAA4C;QAC5C,MAAM,KAAK,GAAG,eAAe,CAAE,GAAoC,CAAC,IAAI,CAAC,CAAC;QAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAClC,CAAC;IACD,uEAAuE;IACvE,yEAAyE;IACzE,wEAAwE;IACxE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;AACxE,CAAC"}
@@ -0,0 +1,219 @@
1
+ import type { ToolDef } from './tool.js';
2
+ export interface ProviderMessage {
3
+ readonly role: 'system' | 'user' | 'assistant' | 'tool_result';
4
+ readonly content: ReadonlyArray<ContentBlock>;
5
+ }
6
+ export type ContentBlock = {
7
+ readonly type: 'text';
8
+ readonly text: string;
9
+ } | {
10
+ readonly type: 'tool_use';
11
+ readonly id: string;
12
+ readonly name: string;
13
+ readonly input: unknown;
14
+ } | {
15
+ readonly type: 'tool_result';
16
+ readonly toolUseId: string;
17
+ readonly content: string;
18
+ readonly isError?: boolean;
19
+ } | {
20
+ readonly type: 'image';
21
+ readonly mediaType: string;
22
+ readonly data: string;
23
+ } | {
24
+ readonly type: 'audio';
25
+ readonly mediaType: string;
26
+ readonly data: string;
27
+ };
28
+ /**
29
+ * Provider-neutral instruction for where a prompt-cache breakpoint should be
30
+ * placed. A {@link CacheStrategyDef} emits these; providers that support
31
+ * caching (e.g. Anthropic via `cache_control`) translate them into their
32
+ * native marker, and providers that don't simply ignore them.
33
+ *
34
+ * `tools` / `system` mark the end of those (session-stable) regions;
35
+ * `{ messageIndex }` marks the end of the message at that index in the
36
+ * request's `messages` array (used for the rolling prefix breakpoint).
37
+ * Anthropic honors at most 4 breakpoints per request.
38
+ */
39
+ export interface CacheHint {
40
+ readonly target: 'tools' | 'system' | {
41
+ readonly messageIndex: number;
42
+ };
43
+ }
44
+ export interface ProviderRequest {
45
+ readonly model: string;
46
+ readonly system?: string;
47
+ readonly messages: ReadonlyArray<ProviderMessage>;
48
+ readonly tools?: ReadonlyArray<ToolDef>;
49
+ readonly maxTokens?: number;
50
+ readonly temperature?: number;
51
+ readonly signal?: AbortSignal;
52
+ /** Where to place prompt-cache breakpoints. Set by the active CacheStrategy. */
53
+ readonly cacheHints?: ReadonlyArray<CacheHint>;
54
+ }
55
+ export type ProviderEvent = {
56
+ readonly type: 'message_start';
57
+ readonly model: string;
58
+ } | {
59
+ readonly type: 'text_delta';
60
+ readonly delta: string;
61
+ } | {
62
+ readonly type: 'tool_use_start';
63
+ readonly id: string;
64
+ readonly name: string;
65
+ } | {
66
+ readonly type: 'tool_use_delta';
67
+ readonly id: string;
68
+ readonly partialInput: string;
69
+ } | {
70
+ readonly type: 'tool_use_end';
71
+ readonly id: string;
72
+ readonly input: unknown;
73
+ } | {
74
+ readonly type: 'message_end';
75
+ readonly stopReason: 'end_turn' | 'tool_use' | 'max_tokens' | 'stop_sequence' | 'error';
76
+ readonly usage?: TokenUsage;
77
+ } | {
78
+ readonly type: 'error';
79
+ readonly message: string;
80
+ readonly retryable: boolean;
81
+ };
82
+ export interface TokenUsage {
83
+ readonly inputTokens: number;
84
+ readonly outputTokens: number;
85
+ readonly cacheReadTokens?: number;
86
+ readonly cacheCreationTokens?: number;
87
+ }
88
+ export interface ModelDescriptor {
89
+ readonly id: string;
90
+ readonly contextWindow: number;
91
+ readonly maxOutputTokens?: number;
92
+ readonly supportsTools: boolean;
93
+ readonly supportsStreaming: boolean;
94
+ /**
95
+ * Whether this model accepts `image` ContentBlocks in user messages.
96
+ * Channels gate image attachments on this flag — if a user drops an
97
+ * image while a non-vision model is active, the channel either
98
+ * refuses or warns instead of silently dropping the bytes.
99
+ */
100
+ readonly supportsImages?: boolean;
101
+ /**
102
+ * Whether this model accepts `audio` ContentBlocks in user messages
103
+ * (GPT-4o, Gemini-Live-class models). When false, channels with audio
104
+ * input route through the session's active `Transcriber` and forward
105
+ * the transcript as text instead.
106
+ */
107
+ readonly supportsAudio?: boolean;
108
+ }
109
+ export interface LLMProvider {
110
+ readonly name: string;
111
+ readonly models: ReadonlyArray<ModelDescriptor>;
112
+ stream(req: ProviderRequest): AsyncIterable<ProviderEvent>;
113
+ countTokens(req: Pick<ProviderRequest, 'model' | 'messages' | 'system' | 'tools'>): Promise<number>;
114
+ }
115
+ export type ProviderKeyValidation = {
116
+ readonly ok: true;
117
+ } | {
118
+ readonly ok: false;
119
+ readonly message: string;
120
+ };
121
+ /**
122
+ * Minimal vault interface exposed to provider auth flows. Implementations
123
+ * (typically `@moxxy/plugin-vault`) supply encrypted storage; the auth
124
+ * descriptor doesn't need anything richer, so we keep the contract small
125
+ * and SDK-Node-free.
126
+ */
127
+ export interface ProviderVault {
128
+ get(key: string): Promise<string | null>;
129
+ set(key: string, value: string, tags?: ReadonlyArray<string>): Promise<void>;
130
+ delete?(key: string): Promise<boolean>;
131
+ }
132
+ /**
133
+ * Runtime supplied to a provider's OAuth `login(ctx)` callback. The host
134
+ * (e.g. `moxxy init`, `moxxy login <provider>`) constructs this and hands
135
+ * it off; the provider plugin runs the flow end-to-end and persists
136
+ * credentials via `ctx.vault`.
137
+ */
138
+ export interface ProviderAuthContext {
139
+ readonly vault: ProviderVault;
140
+ /**
141
+ * True when there is no usable browser or interactive TTY. OAuth flows
142
+ * should fall back to device-code (or equivalent) in this mode rather
143
+ * than spawning a local callback server / opening a browser.
144
+ */
145
+ readonly headless: boolean;
146
+ /**
147
+ * Progress-message sink. The host wires this to its preferred renderer
148
+ * (clack `log.*`, plain stdout, …) so providers don't have to know
149
+ * whether they're running inside a wizard or a one-shot command.
150
+ */
151
+ readonly write: (chunk: string) => void;
152
+ }
153
+ export interface ProviderOAuthResult {
154
+ /** Human-readable account identifier shown in the success message. */
155
+ readonly accountId?: string | null;
156
+ /** UNIX-ms expiry of the persisted credential; surfaced to users. */
157
+ readonly expiresAt?: number;
158
+ }
159
+ /**
160
+ * Self-describing auth metadata a provider plugin attaches to its
161
+ * `ProviderDef`. Lets the CLI's setup wizard and `moxxy login` operate
162
+ * generically over any installed provider — no CLI-side branch table.
163
+ *
164
+ * `apiKey` : the host prompts for a key and calls `validateKey` (if any).
165
+ * `oauth` : the host hands the provider a `ProviderAuthContext`; the
166
+ * provider drives the full OAuth dance, including any local
167
+ * callback server, and persists tokens to `ctx.vault`.
168
+ */
169
+ export type ProviderAuthDescriptor = {
170
+ readonly kind: 'apiKey';
171
+ /** Canonical env-var name (e.g. `ANTHROPIC_API_KEY`). Inferred when omitted. */
172
+ readonly envVar?: string;
173
+ /** Short hint shown next to the prompt (e.g. "starts with `sk-ant-`"). */
174
+ readonly hint?: string;
175
+ } | {
176
+ readonly kind: 'oauth';
177
+ /** Human-readable name of the upstream service (e.g. "ChatGPT Pro/Plus"). */
178
+ readonly serviceName?: string;
179
+ /**
180
+ * Drive the OAuth flow and persist credentials. Throws on failure /
181
+ * user cancellation; the host typically offers a retry prompt.
182
+ */
183
+ login(ctx: ProviderAuthContext): Promise<ProviderOAuthResult>;
184
+ /**
185
+ * Optional logout — remove persisted credentials from the vault.
186
+ * Returns true if anything was removed, false if there was nothing
187
+ * stored. Used by `moxxy login logout <provider>`.
188
+ */
189
+ logout?(ctx: ProviderAuthContext): Promise<boolean>;
190
+ /**
191
+ * Optional status probe — returns a brief description of the stored
192
+ * credential, or null if none. Used by `moxxy login status`.
193
+ */
194
+ status?(ctx: ProviderAuthContext): Promise<ProviderOAuthStatus | null>;
195
+ };
196
+ export interface ProviderOAuthStatus {
197
+ readonly accountId?: string | null;
198
+ readonly expiresAt?: number;
199
+ /** Vault key the credentials are stored under (informational). */
200
+ readonly vaultKey?: string;
201
+ }
202
+ export interface ProviderDef {
203
+ readonly name: string;
204
+ readonly models: ReadonlyArray<ModelDescriptor>;
205
+ createClient(config: Record<string, unknown>): LLMProvider;
206
+ /**
207
+ * Optional check that the given key is actually accepted by the vendor.
208
+ * Implementations should be cheap (a free metadata call or a 1-token
209
+ * completion). Used by `moxxy init` to verify keys before persisting.
210
+ */
211
+ validateKey?(apiKey: string): Promise<ProviderKeyValidation>;
212
+ /**
213
+ * Optional auth descriptor. When omitted, the host treats the provider
214
+ * as `{ kind: 'apiKey' }` — i.e. prompt for a key, call `validateKey`
215
+ * if defined, store under the canonical vault entry.
216
+ */
217
+ readonly auth?: ProviderAuthDescriptor;
218
+ }
219
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,aAAa,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;CAC/C;AAED,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAClG;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,C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,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAChD,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC;IAC3D;;;;OAIG;IACH,WAAW,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC7D;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,sBAAsB,CAAC;CACxC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ export type RequirementKind = 'plugin' | 'provider' | 'tool' | 'transcriber' | 'mode' | 'compactor' | 'channel' | 'agent' | 'command' | 'runtime';
2
+ export type RequirementState = 'registered' | 'active' | 'ready';
3
+ export interface MoxxyRequirement {
4
+ readonly kind: RequirementKind;
5
+ readonly name: string;
6
+ readonly state?: RequirementState;
7
+ readonly version?: string;
8
+ readonly optional?: boolean;
9
+ readonly reason?: string;
10
+ readonly hint?: string;
11
+ }
12
+ export interface RequirementIssue {
13
+ readonly requirement: MoxxyRequirement;
14
+ readonly code: 'missing' | 'inactive' | 'not_ready' | 'version_mismatch';
15
+ readonly message: string;
16
+ readonly hint?: string;
17
+ }
18
+ export interface RequirementCheck {
19
+ readonly ready: boolean;
20
+ readonly issues: ReadonlyArray<RequirementIssue>;
21
+ }
22
+ //# sourceMappingURL=requirements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requirements.d.ts","sourceRoot":"","sources":["../src/requirements.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,UAAU,GACV,MAAM,GACN,aAAa,GACb,MAAM,GACN,WAAW,GACX,SAAS,GACT,OAAO,GACP,SAAS,GACT,SAAS,CAAC;AAEd,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEjE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,kBAAkB,CAAC;IACzE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;CAClD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=requirements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requirements.js","sourceRoot":"","sources":["../src/requirements.ts"],"names":[],"mappings":""}