@moxxy/sdk 0.7.0 → 0.8.1

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 (48) hide show
  1. package/README.md +32 -11
  2. package/dist/cache-strategy.d.ts +9 -0
  3. package/dist/cache-strategy.d.ts.map +1 -1
  4. package/dist/channel-auth.d.ts +43 -5
  5. package/dist/channel-auth.d.ts.map +1 -1
  6. package/dist/channel-auth.js +112 -17
  7. package/dist/channel-auth.js.map +1 -1
  8. package/dist/compactor-helpers.d.ts.map +1 -1
  9. package/dist/compactor-helpers.js +5 -0
  10. package/dist/compactor-helpers.js.map +1 -1
  11. package/dist/compactor.d.ts +10 -0
  12. package/dist/compactor.d.ts.map +1 -1
  13. package/dist/index.d.ts +2 -3
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -3
  16. package/dist/index.js.map +1 -1
  17. package/dist/mode-helpers.d.ts +9 -0
  18. package/dist/mode-helpers.d.ts.map +1 -1
  19. package/dist/mode-helpers.js +19 -1
  20. package/dist/mode-helpers.js.map +1 -1
  21. package/dist/permission.d.ts +13 -0
  22. package/dist/permission.d.ts.map +1 -1
  23. package/dist/provider.d.ts +10 -0
  24. package/dist/provider.d.ts.map +1 -1
  25. package/dist/session-like.d.ts +13 -0
  26. package/dist/session-like.d.ts.map +1 -1
  27. package/dist/view-renderer.d.ts +15 -0
  28. package/dist/view-renderer.d.ts.map +1 -1
  29. package/dist/view-renderer.js +24 -0
  30. package/dist/view-renderer.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/cache-strategy.ts +9 -0
  33. package/src/channel-auth.test.ts +122 -0
  34. package/src/channel-auth.ts +129 -16
  35. package/src/compactor-helpers.ts +5 -0
  36. package/src/compactor.ts +10 -0
  37. package/src/index.ts +6 -7
  38. package/src/loop-helpers.test.ts +101 -0
  39. package/src/mode-helpers.ts +28 -1
  40. package/src/permission.ts +13 -0
  41. package/src/provider.ts +10 -0
  42. package/src/session-like.ts +14 -0
  43. package/src/view-renderer.ts +22 -0
  44. package/dist/voice.d.ts +0 -36
  45. package/dist/voice.d.ts.map +0 -1
  46. package/dist/voice.js +0 -82
  47. package/dist/voice.js.map +0 -1
  48. package/src/voice.ts +0 -103
package/src/voice.ts DELETED
@@ -1,103 +0,0 @@
1
- /**
2
- * Voice / transcription helpers shared across surfaces.
3
- *
4
- * The TUI's voice-input infrastructure used to inline the same logic
5
- * with a `Codex`-specific name baked in. Pulled out here as
6
- * *agnostic* helpers that take a transcriber name as input, so the
7
- * desktop, TUI, and any future channel can mirror the same flow:
8
- *
9
- * - Is the session ready to transcribe? Check via the requirements
10
- * API for a named transcriber. (`checkTranscriberReady`)
11
- * - Activate any registered transcriber lazily. Returns the active
12
- * transcriber instance. (`resolveTranscriber`)
13
- * - "Just give me whatever works" — try a list of candidates in
14
- * order, or fall back to the first registered one. (`pickFirstAvailableTranscriber`)
15
- */
16
-
17
- import type { ClientSession } from './client-session.js';
18
- import type {
19
- MoxxyRequirement,
20
- RequirementCheck,
21
- RequirementIssue,
22
- } from './requirements.js';
23
- import type { Transcriber } from './transcriber.js';
24
-
25
- /** Probe whether a *named* transcriber is ready: registered, with any
26
- * declared upstream requirements satisfied. The optional `requires`
27
- * list lets channels gate on additional provider / auth runtimes
28
- * (the Codex transcriber e.g. depends on the `openai-codex` provider
29
- * + its OAuth runtime). */
30
- export function checkTranscriberReady(
31
- session: ClientSession,
32
- transcriberName: string,
33
- requires: ReadonlyArray<MoxxyRequirement> = [],
34
- ): RequirementCheck {
35
- const baseline: ReadonlyArray<MoxxyRequirement> = [
36
- { kind: 'transcriber', name: transcriberName },
37
- ...requires,
38
- ];
39
- const check = session.requirements.check(baseline);
40
- const activeName = session.transcribers.getActiveName();
41
- if (!activeName || activeName === transcriberName) return check;
42
-
43
- const conflict: RequirementIssue = {
44
- requirement: {
45
- kind: 'transcriber',
46
- name: transcriberName,
47
- state: 'active',
48
- hint: `Switch active transcriber to ${transcriberName}.`,
49
- },
50
- code: 'inactive',
51
- message: `Required active transcriber ${transcriberName}; active is ${activeName}`,
52
- hint: `Switch active transcriber to ${transcriberName}.`,
53
- };
54
- return { ready: false, issues: [conflict, ...check.issues] };
55
- }
56
-
57
- /** Activate a transcriber by name, lazily. Returns the active instance
58
- * ready to `.transcribe(...)`. Throws if no such transcriber is
59
- * registered, or a *different* one is already active. */
60
- export function resolveTranscriber(
61
- session: ClientSession,
62
- transcriberName: string,
63
- ): Transcriber {
64
- const activeName = session.transcribers.getActiveName();
65
- if (activeName && activeName !== transcriberName) {
66
- throw new Error(
67
- `Another transcriber is already active: ${activeName}.`,
68
- );
69
- }
70
- if (activeName === transcriberName) return session.transcribers.getActive();
71
- if (session.transcribers.has(transcriberName)) {
72
- return session.transcribers.setActive(transcriberName);
73
- }
74
- throw new Error(
75
- `No transcriber registered as ${transcriberName}. Configure one via your moxxy plugins.`,
76
- );
77
- }
78
-
79
- /** "Just pick a transcriber that works."
80
- *
81
- * Tries each name in `candidates` in order — first one that can be
82
- * activated wins. Returns null if none can be activated, so callers
83
- * can degrade gracefully (hide their mic button, show a "no voice
84
- * configured" tip, …) instead of throwing. */
85
- export function pickFirstAvailableTranscriber(
86
- session: ClientSession,
87
- candidates: ReadonlyArray<string>,
88
- ): Transcriber | null {
89
- // If something's already active, just hand that back — never fight
90
- // a user-chosen activation.
91
- const existing = session.transcribers.tryGetActive();
92
- if (existing) return existing;
93
- for (const name of candidates) {
94
- try {
95
- return resolveTranscriber(session, name);
96
- } catch {
97
- // Wrong-active errors don't apply here (we just returned early),
98
- // so any throw is "this candidate isn't registered" — keep
99
- // trying.
100
- }
101
- }
102
- return null;
103
- }