@motebit/sdk 0.6.11 → 0.8.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 (74) hide show
  1. package/README.md +15 -110
  2. package/dist/__tests__/appearance-config.test.d.ts +2 -0
  3. package/dist/__tests__/appearance-config.test.d.ts.map +1 -0
  4. package/dist/__tests__/appearance-config.test.js +104 -0
  5. package/dist/__tests__/appearance-config.test.js.map +1 -0
  6. package/dist/__tests__/branded-ids.test.d.ts +2 -0
  7. package/dist/__tests__/branded-ids.test.d.ts.map +1 -0
  8. package/dist/__tests__/branded-ids.test.js +70 -0
  9. package/dist/__tests__/branded-ids.test.js.map +1 -0
  10. package/dist/__tests__/index.test.d.ts +2 -0
  11. package/dist/__tests__/index.test.d.ts.map +1 -0
  12. package/dist/__tests__/index.test.js +194 -0
  13. package/dist/__tests__/index.test.js.map +1 -0
  14. package/dist/__tests__/provider-mode.test.d.ts +2 -0
  15. package/dist/__tests__/provider-mode.test.d.ts.map +1 -0
  16. package/dist/__tests__/provider-mode.test.js +180 -0
  17. package/dist/__tests__/provider-mode.test.js.map +1 -0
  18. package/dist/__tests__/provider-resolver.test.d.ts +2 -0
  19. package/dist/__tests__/provider-resolver.test.d.ts.map +1 -0
  20. package/dist/__tests__/provider-resolver.test.js +353 -0
  21. package/dist/__tests__/provider-resolver.test.js.map +1 -0
  22. package/dist/__tests__/voice-config.test.d.ts +2 -0
  23. package/dist/__tests__/voice-config.test.d.ts.map +1 -0
  24. package/dist/__tests__/voice-config.test.js +98 -0
  25. package/dist/__tests__/voice-config.test.js.map +1 -0
  26. package/dist/appearance-config.d.ts +55 -0
  27. package/dist/appearance-config.d.ts.map +1 -0
  28. package/dist/appearance-config.js +79 -0
  29. package/dist/appearance-config.js.map +1 -0
  30. package/dist/approval-presets.d.ts +16 -0
  31. package/dist/approval-presets.d.ts.map +1 -0
  32. package/dist/approval-presets.js +30 -0
  33. package/dist/approval-presets.js.map +1 -0
  34. package/dist/color-presets.d.ts +14 -0
  35. package/dist/color-presets.d.ts.map +1 -0
  36. package/dist/color-presets.js +17 -0
  37. package/dist/color-presets.js.map +1 -0
  38. package/dist/credential-types-doc.d.ts +73 -0
  39. package/dist/credential-types-doc.d.ts.map +1 -0
  40. package/dist/credential-types-doc.js +2 -0
  41. package/dist/credential-types-doc.js.map +1 -0
  42. package/dist/governance-config.d.ts +19 -0
  43. package/dist/governance-config.d.ts.map +1 -0
  44. package/dist/governance-config.js +15 -0
  45. package/dist/governance-config.js.map +1 -0
  46. package/dist/index.d.ts +97 -1045
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +12 -346
  49. package/dist/index.js.map +1 -1
  50. package/dist/models.d.ts +56 -0
  51. package/dist/models.d.ts.map +1 -0
  52. package/dist/models.js +85 -0
  53. package/dist/models.js.map +1 -0
  54. package/dist/provider-mode.d.ts +109 -0
  55. package/dist/provider-mode.d.ts.map +1 -0
  56. package/dist/provider-mode.js +179 -0
  57. package/dist/provider-mode.js.map +1 -0
  58. package/dist/provider-resolver.d.ts +179 -0
  59. package/dist/provider-resolver.d.ts.map +1 -0
  60. package/dist/provider-resolver.js +224 -0
  61. package/dist/provider-resolver.js.map +1 -0
  62. package/dist/risk-labels.d.ts +22 -0
  63. package/dist/risk-labels.d.ts.map +1 -0
  64. package/dist/risk-labels.js +28 -0
  65. package/dist/risk-labels.js.map +1 -0
  66. package/dist/surface-options.d.ts +34 -0
  67. package/dist/surface-options.d.ts.map +1 -0
  68. package/dist/surface-options.js +36 -0
  69. package/dist/surface-options.js.map +1 -0
  70. package/dist/voice-config.d.ts +52 -0
  71. package/dist/voice-config.d.ts.map +1 -0
  72. package/dist/voice-config.js +61 -0
  73. package/dist/voice-config.js.map +1 -0
  74. package/package.json +9 -6
@@ -0,0 +1,224 @@
1
+ // === Provider Resolver — pure dispatch logic, shared across all surfaces ===
2
+ //
3
+ // The four surfaces (web, mobile, desktop, cli) used to each maintain their
4
+ // own copy of "given a UnifiedProviderConfig, build a concrete @motebit/ai-core
5
+ // provider instance." Four implementations of the same decision tree, with
6
+ // only one (web) actually containing the Ollama-vs-OpenAI-compat dispatch
7
+ // heuristic. Adding a vendor meant editing four files. Fixing a bug meant
8
+ // fixing it four times — and historically, only the surface where the bug
9
+ // was reported actually got the fix.
10
+ //
11
+ // This module extracts the decision tree as a pure function. It takes a
12
+ // `UnifiedProviderConfig` and a surface-supplied `ResolverEnv` (which captures
13
+ // the only legitimately-divergent concerns: platform URL routing, available
14
+ // on-device backends, motebit-cloud session state). It returns a `ProviderSpec`
15
+ // — a normalized data shape describing what kind of provider to instantiate
16
+ // with what config. The surface still constructs the concrete class itself
17
+ // (because @motebit/sdk is Layer 0 and can't import @motebit/ai-core's
18
+ // provider classes), but the construction shrinks to a 15-line transport
19
+ // switch with no decision logic.
20
+ //
21
+ // Adding a new vendor: extend ByokVendor, add a case to resolveProviderSpec.
22
+ // Fixing a dispatch bug: fix it once here. Tested in one place.
23
+ //
24
+ // What stays per-surface (and rightly so):
25
+ // - Constructing the actual @motebit/ai-core provider classes
26
+ // - Async init flows (WebLLM model download, native module loading)
27
+ // - API key storage (keyring vs SecureStore vs env vars)
28
+ // - URL substitution that depends on platform (Vite proxy paths, Tauri vs dev)
29
+ //
30
+ // What moves here (the duplication):
31
+ // - The mode → vendor → transport decision tree
32
+ // - The Ollama-vs-OpenAI-compat endpoint heuristic
33
+ // - The Google "uses OpenAI-compat" fact
34
+ // - Default model fallback per vendor
35
+ // - The supported-backends gate
36
+ import { DEFAULT_ANTHROPIC_MODEL, DEFAULT_OPENAI_MODEL, DEFAULT_GOOGLE_MODEL, DEFAULT_OLLAMA_MODEL, DEFAULT_PROXY_MODEL, } from "./models.js";
37
+ // === Constants ===
38
+ /**
39
+ * Google's OpenAI-compatible chat completions endpoint. Used when the user
40
+ * picks Google as a BYOK vendor — Google is dispatched as OpenAI-compat
41
+ * because every cloud client (web, mobile, desktop, cli) already understands
42
+ * the OpenAI wire protocol. Single source of truth.
43
+ */
44
+ export const GOOGLE_OPENAI_COMPAT_URL = "https://generativelanguage.googleapis.com/v1beta/openai";
45
+ /** Canonical Anthropic API base URL. */
46
+ export const ANTHROPIC_CANONICAL_URL = "https://api.anthropic.com";
47
+ /** Canonical OpenAI API base URL. */
48
+ export const OPENAI_CANONICAL_URL = "https://api.openai.com/v1";
49
+ /** Default Motebit Cloud relay URL. Surfaces may override via env. */
50
+ export const DEFAULT_MOTEBIT_CLOUD_URL = "https://api.motebit.com";
51
+ /** Default WebLLM model when none specified — small enough to fit on most devices. */
52
+ export const DEFAULT_WEBLLM_MODEL = "Llama-3.2-3B-Instruct-q4f16_1-MLC";
53
+ // === Helpers ===
54
+ /**
55
+ * Normalize a local-inference server URL so that it points at the
56
+ * OpenAI-compatible chat completions base path. Auto-appends `/v1` if
57
+ * the URL doesn't already contain it. Idempotent.
58
+ *
59
+ * Every supported local server (Ollama via its OpenAI shim, LM Studio,
60
+ * llama.cpp, Jan, vLLM, text-generation-webui) exposes
61
+ * `{base}/v1/chat/completions`. Users typically type just the host
62
+ * (`http://localhost:11434`) — this helper completes the path so the
63
+ * client can call `{normalized}/chat/completions` directly.
64
+ *
65
+ * Examples:
66
+ * "http://localhost:11434" → "http://localhost:11434/v1"
67
+ * "http://localhost:11434/v1" → "http://localhost:11434/v1"
68
+ * "http://localhost:1234/" → "http://localhost:1234/v1"
69
+ * "http://192.168.1.42:11434" → "http://192.168.1.42:11434/v1"
70
+ * "/api/ollama" → "/api/ollama/v1" (dev proxy path)
71
+ */
72
+ export function normalizeLocalServerEndpoint(url) {
73
+ const stripped = url.replace(/\/+$/, "");
74
+ // Already contains a /v1 path segment? Leave it alone.
75
+ if (/\/v1(\/|$)/.test(stripped))
76
+ return stripped;
77
+ return `${stripped}/v1`;
78
+ }
79
+ /** Default chat model for a BYOK vendor. */
80
+ export function defaultModelForVendor(vendor) {
81
+ switch (vendor) {
82
+ case "anthropic":
83
+ return DEFAULT_ANTHROPIC_MODEL;
84
+ case "openai":
85
+ return DEFAULT_OPENAI_MODEL;
86
+ case "google":
87
+ return DEFAULT_GOOGLE_MODEL;
88
+ }
89
+ }
90
+ /**
91
+ * Canonical (vendor-published) base URL for a BYOK vendor. Surfaces that
92
+ * need to substitute a CORS proxy or dev-mode path receive this canonical
93
+ * URL via the resolver and may rewrite it.
94
+ */
95
+ export function canonicalVendorBaseUrl(vendor) {
96
+ switch (vendor) {
97
+ case "anthropic":
98
+ return ANTHROPIC_CANONICAL_URL;
99
+ case "openai":
100
+ return OPENAI_CANONICAL_URL;
101
+ case "google":
102
+ return GOOGLE_OPENAI_COMPAT_URL;
103
+ }
104
+ }
105
+ // === Errors ===
106
+ /**
107
+ * Thrown when the user picks an on-device backend that the current surface
108
+ * doesn't physically support (e.g., apple-fm on web). Surfaces should
109
+ * present a graceful error rather than letting it propagate.
110
+ */
111
+ export class UnsupportedBackendError extends Error {
112
+ backend;
113
+ constructor(backend) {
114
+ super(`On-device backend "${backend}" is not supported on this surface`);
115
+ this.backend = backend;
116
+ this.name = "UnsupportedBackendError";
117
+ }
118
+ }
119
+ // === The resolver ===
120
+ /**
121
+ * Resolve a `UnifiedProviderConfig` (the user's choice) against a surface's
122
+ * `ResolverEnv` (its physical capabilities) to produce a normalized
123
+ * `ProviderSpec` (what the surface should instantiate).
124
+ *
125
+ * Pure function. No I/O. No side effects. Tested once, used everywhere.
126
+ *
127
+ * @throws {UnsupportedBackendError} if the chosen on-device backend isn't
128
+ * in `env.supportedBackends`. Surfaces should catch and present a
129
+ * user-facing message.
130
+ */
131
+ export function resolveProviderSpec(config, env) {
132
+ switch (config.mode) {
133
+ case "motebit-cloud": {
134
+ // Motebit Cloud speaks the Anthropic wire protocol via the relay.
135
+ // The relay injects the real key server-side, so the spec carries
136
+ // an empty apiKey — every cloud client knows to handle that case.
137
+ const baseUrl = config.baseUrl ?? env.motebitCloudBaseUrl ?? DEFAULT_MOTEBIT_CLOUD_URL;
138
+ const extraHeaders = config.proxyToken !== undefined
139
+ ? { "x-proxy-token": config.proxyToken, ...(env.motebitCloudHeaders ?? {}) }
140
+ : env.motebitCloudHeaders;
141
+ return {
142
+ kind: "cloud",
143
+ wireProtocol: "anthropic",
144
+ apiKey: "",
145
+ model: config.model ?? env.motebitCloudDefaultModel ?? DEFAULT_PROXY_MODEL,
146
+ baseUrl,
147
+ maxTokens: config.maxTokens,
148
+ temperature: config.temperature,
149
+ extraHeaders,
150
+ };
151
+ }
152
+ case "byok": {
153
+ // Google is dispatched as OpenAI-compat — its public API is OpenAI-
154
+ // compatible at the canonical Google URL. Anthropic and OpenAI use
155
+ // their own canonical wire protocols.
156
+ const wireProtocol = config.vendor === "anthropic" ? "anthropic" : "openai";
157
+ const canonical = config.baseUrl ?? canonicalVendorBaseUrl(config.vendor);
158
+ return {
159
+ kind: "cloud",
160
+ wireProtocol,
161
+ apiKey: config.apiKey,
162
+ model: config.model ?? defaultModelForVendor(config.vendor),
163
+ baseUrl: env.cloudBaseUrl(wireProtocol, canonical),
164
+ maxTokens: config.maxTokens,
165
+ temperature: config.temperature,
166
+ };
167
+ }
168
+ case "on-device": {
169
+ if (!env.supportedBackends.has(config.backend)) {
170
+ throw new UnsupportedBackendError(config.backend);
171
+ }
172
+ switch (config.backend) {
173
+ case "webllm":
174
+ return {
175
+ kind: "webllm",
176
+ model: config.model ?? DEFAULT_WEBLLM_MODEL,
177
+ maxTokens: config.maxTokens,
178
+ temperature: config.temperature,
179
+ };
180
+ case "apple-fm":
181
+ return {
182
+ kind: "apple-fm",
183
+ model: config.model,
184
+ maxTokens: config.maxTokens,
185
+ };
186
+ case "mlx":
187
+ return {
188
+ kind: "mlx",
189
+ model: config.model,
190
+ maxTokens: config.maxTokens,
191
+ };
192
+ case "local-server": {
193
+ // Every supported local inference server (Ollama, LM Studio,
194
+ // llama.cpp, Jan, vLLM, text-generation-webui, …) exposes an
195
+ // OpenAI-compatible chat completions endpoint at /v1. We dispatch
196
+ // them all through the OpenAI wire protocol with a single client
197
+ // (`OpenAIProvider`). The previous Ollama-vs-OpenAI port heuristic
198
+ // is gone — there's only one code path now.
199
+ //
200
+ // `normalizeLocalServerEndpoint` auto-appends `/v1` so users who
201
+ // type the bare host (`http://localhost:11434`) still work. Users
202
+ // who type the full path (`http://localhost:11434/v1`) are
203
+ // unaffected. Surfaces may further substitute the URL via
204
+ // `localServerBaseUrl` (e.g. desktop dev mode → `/api/ollama`).
205
+ const logicalEndpoint = config.endpoint ?? env.defaultLocalServerUrl;
206
+ const surfaceTransformed = env.localServerBaseUrl?.(logicalEndpoint) ?? logicalEndpoint;
207
+ const actualEndpoint = normalizeLocalServerEndpoint(surfaceTransformed);
208
+ return {
209
+ kind: "cloud",
210
+ wireProtocol: "openai",
211
+ // Local OpenAI-compat servers don't validate the API key, but
212
+ // most clients require a non-empty string. Use a sentinel.
213
+ apiKey: "local",
214
+ model: config.model ?? DEFAULT_OLLAMA_MODEL,
215
+ baseUrl: actualEndpoint,
216
+ maxTokens: config.maxTokens,
217
+ temperature: config.temperature,
218
+ };
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+ //# sourceMappingURL=provider-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-resolver.js","sourceRoot":"","sources":["../src/provider-resolver.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,EAAE;AACF,4EAA4E;AAC5E,gFAAgF;AAChF,2EAA2E;AAC3E,0EAA0E;AAC1E,0EAA0E;AAC1E,0EAA0E;AAC1E,qCAAqC;AACrC,EAAE;AACF,wEAAwE;AACxE,+EAA+E;AAC/E,4EAA4E;AAC5E,gFAAgF;AAChF,4EAA4E;AAC5E,2EAA2E;AAC3E,uEAAuE;AACvE,yEAAyE;AACzE,iCAAiC;AACjC,EAAE;AACF,6EAA6E;AAC7E,gEAAgE;AAChE,EAAE;AACF,2CAA2C;AAC3C,gEAAgE;AAChE,sEAAsE;AACtE,2DAA2D;AAC3D,iFAAiF;AACjF,EAAE;AACF,qCAAqC;AACrC,kDAAkD;AAClD,qDAAqD;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AC;gBACJ,KAAK,cAAc,CAAC,CAAC,CAAC;oBACpB,6DAA6D;oBAC7D,6DAA6D;oBAC7D,kEAAkE;oBAClE,iEAAiE;oBACjE,mEAAmE;oBACnE,4CAA4C;oBAC5C,EAAE;oBACF,iEAAiE;oBACjE,kEAAkE;oBAClE,2DAA2D;oBAC3D,0DAA0D;oBAC1D,gEAAgE;oBAChE,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC,qBAAqB,CAAC;oBACrE,MAAM,kBAAkB,GAAG,GAAG,CAAC,kBAAkB,EAAE,CAAC,eAAe,CAAC,IAAI,eAAe,CAAC;oBACxF,MAAM,cAAc,GAAG,4BAA4B,CAAC,kBAAkB,CAAC,CAAC;oBACxE,OAAO;wBACL,IAAI,EAAE,OAAO;wBACb,YAAY,EAAE,QAAQ;wBACtB,8DAA8D;wBAC9D,2DAA2D;wBAC3D,MAAM,EAAE,OAAO;wBACf,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,oBAAoB;wBAC3C,OAAO,EAAE,cAAc;wBACvB,SAAS,EAAE,MAAM,CAAC,SAAS;wBAC3B,WAAW,EAAE,MAAM,CAAC,WAAW;qBAChC,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Canonical risk level labels for tool governance.
3
+ *
4
+ * The five risk levels are the same across every surface and every
5
+ * storage system — they're the axes the `PolicyGate` scores tools
6
+ * against, and they're what the user picks a preset threshold for.
7
+ * The label strings ("R0 Read", "R1 Draft", …) were drifting across
8
+ * four different files with four different presentation shapes
9
+ * (Record<number, string>, { label, cls }, { label, color, bg }).
10
+ * This module is the authoritative source for the semantic labels.
11
+ *
12
+ * Surfaces still own their own presentation — the CSS class in
13
+ * desktop's chat badge, the color swatches in the mobile approval
14
+ * card — but the label string comes from here.
15
+ *
16
+ * The order is the same as `PolicyGate`'s risk scoring: 0 is
17
+ * read-only, 4 is "touches money." A tool classified above its
18
+ * surface's `requireApprovalAbove` gets a modal; above `denyAbove`
19
+ * gets rejected.
20
+ */
21
+ export declare const RISK_LABELS: Record<number, string>;
22
+ //# sourceMappingURL=risk-labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"risk-labels.d.ts","sourceRoot":"","sources":["../src/risk-labels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAM9C,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Canonical risk level labels for tool governance.
3
+ *
4
+ * The five risk levels are the same across every surface and every
5
+ * storage system — they're the axes the `PolicyGate` scores tools
6
+ * against, and they're what the user picks a preset threshold for.
7
+ * The label strings ("R0 Read", "R1 Draft", …) were drifting across
8
+ * four different files with four different presentation shapes
9
+ * (Record<number, string>, { label, cls }, { label, color, bg }).
10
+ * This module is the authoritative source for the semantic labels.
11
+ *
12
+ * Surfaces still own their own presentation — the CSS class in
13
+ * desktop's chat badge, the color swatches in the mobile approval
14
+ * card — but the label string comes from here.
15
+ *
16
+ * The order is the same as `PolicyGate`'s risk scoring: 0 is
17
+ * read-only, 4 is "touches money." A tool classified above its
18
+ * surface's `requireApprovalAbove` gets a modal; above `denyAbove`
19
+ * gets rejected.
20
+ */
21
+ export const RISK_LABELS = {
22
+ 0: "R0 Read",
23
+ 1: "R1 Draft",
24
+ 2: "R2 Write",
25
+ 3: "R3 Execute",
26
+ 4: "R4 Money",
27
+ };
28
+ //# sourceMappingURL=risk-labels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"risk-labels.js","sourceRoot":"","sources":["../src/risk-labels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,CAAC,MAAM,WAAW,GAA2B;IACjD,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,UAAU;IACb,CAAC,EAAE,YAAY;IACf,CAAC,EAAE,UAAU;CACd,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Shared option lists for surface settings UIs.
3
+ *
4
+ * These are the dropdown / radio / chip options every surface needs
5
+ * to render the same choices the same way: the six OpenAI TTS voices,
6
+ * and the three theme preferences.
7
+ *
8
+ * Previously each surface redeclared these inline. Now there's one
9
+ * source — a new TTS voice added here shows up in every settings tab.
10
+ *
11
+ * The shapes are intentionally presentation-neutral: a key + label
12
+ * pair. Each surface layers its own visual styling (chip vs radio vs
13
+ * dropdown) on top. The key is what gets persisted; the label is what
14
+ * the user sees.
15
+ */
16
+ export interface TtsVoiceOption {
17
+ key: string;
18
+ label: string;
19
+ }
20
+ /**
21
+ * OpenAI TTS voices. Reference: https://platform.openai.com/docs/guides/text-to-speech/voice-options
22
+ *
23
+ * These map 1:1 onto the `VoiceConfig.ttsVoice` field. Surfaces with
24
+ * non-OpenAI TTS providers can supplement this list with their own
25
+ * voice options, but the default catalogue lives here.
26
+ */
27
+ export declare const TTS_VOICE_OPTIONS: TtsVoiceOption[];
28
+ export type ThemePreference = "light" | "dark" | "system";
29
+ export interface ThemeOption {
30
+ key: ThemePreference;
31
+ label: string;
32
+ }
33
+ export declare const THEME_OPTIONS: ThemeOption[];
34
+ //# sourceMappingURL=surface-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"surface-options.d.ts","sourceRoot":"","sources":["../src/surface-options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,cAAc,EAO7C,CAAC;AAIF,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE1D,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,eAAe,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,aAAa,EAAE,WAAW,EAItC,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Shared option lists for surface settings UIs.
3
+ *
4
+ * These are the dropdown / radio / chip options every surface needs
5
+ * to render the same choices the same way: the six OpenAI TTS voices,
6
+ * and the three theme preferences.
7
+ *
8
+ * Previously each surface redeclared these inline. Now there's one
9
+ * source — a new TTS voice added here shows up in every settings tab.
10
+ *
11
+ * The shapes are intentionally presentation-neutral: a key + label
12
+ * pair. Each surface layers its own visual styling (chip vs radio vs
13
+ * dropdown) on top. The key is what gets persisted; the label is what
14
+ * the user sees.
15
+ */
16
+ /**
17
+ * OpenAI TTS voices. Reference: https://platform.openai.com/docs/guides/text-to-speech/voice-options
18
+ *
19
+ * These map 1:1 onto the `VoiceConfig.ttsVoice` field. Surfaces with
20
+ * non-OpenAI TTS providers can supplement this list with their own
21
+ * voice options, but the default catalogue lives here.
22
+ */
23
+ export const TTS_VOICE_OPTIONS = [
24
+ { key: "alloy", label: "Alloy" },
25
+ { key: "echo", label: "Echo" },
26
+ { key: "fable", label: "Fable" },
27
+ { key: "onyx", label: "Onyx" },
28
+ { key: "nova", label: "Nova" },
29
+ { key: "shimmer", label: "Shimmer" },
30
+ ];
31
+ export const THEME_OPTIONS = [
32
+ { key: "light", label: "Light" },
33
+ { key: "dark", label: "Dark" },
34
+ { key: "system", label: "System" },
35
+ ];
36
+ //# sourceMappingURL=surface-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"surface-options.js","sourceRoot":"","sources":["../src/surface-options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAqB;IACjD,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IAChC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAC9B,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IAChC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAC9B,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAC9B,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;CACrC,CAAC;AAWF,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;IAChC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAC9B,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;CACnC,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Canonical voice configuration shape.
3
+ *
4
+ * Every surface (web, mobile, desktop, spatial) has historically carried its
5
+ * own voice config — with drifted field names (`voiceResponse` vs
6
+ * `voiceResponseEnabled` vs `speakResponses`, `autoSend` vs `voiceAutoSend`)
7
+ * and different subsets of the feature set. This module is the authoritative
8
+ * vocabulary. Surfaces may keep UI-internal state in their own shapes, but
9
+ * anything crossing the SDK boundary — sync, import/export, cross-surface
10
+ * helpers — speaks `VoiceConfig`.
11
+ *
12
+ * Migration helpers are provided for the legacy shapes so each surface can
13
+ * normalize on load without inventing its own migration one-offs.
14
+ */
15
+ /**
16
+ * The canonical voice configuration. Narrow, descriptive, surface-agnostic.
17
+ *
18
+ * - `enabled`: master on/off for the voice pipeline (VAD + STT + TTS).
19
+ * - `autoSend`: after a transcription lands, auto-submit without a manual
20
+ * press. Off means the user edits/approves the transcript first.
21
+ * - `speakResponses`: read agent replies aloud via the TTS backend.
22
+ * - `ttsVoice`: opaque voice identifier — the specific string space depends
23
+ * on the TTS provider (OpenAI voices, platform voices, …).
24
+ * - `neuralVad`: opt into ML-based VAD where the platform supports it
25
+ * (currently iOS via Silero). Absent/false uses the default RMS VAD.
26
+ */
27
+ export interface VoiceConfig {
28
+ enabled: boolean;
29
+ autoSend: boolean;
30
+ speakResponses: boolean;
31
+ ttsVoice: string;
32
+ neuralVad?: boolean;
33
+ }
34
+ /** Default voice config — voice off, sensible behavior when it's turned on. */
35
+ export declare const DEFAULT_VOICE_CONFIG: VoiceConfig;
36
+ /**
37
+ * Normalize any of the historical surface-specific voice shapes onto the
38
+ * canonical `VoiceConfig`. Unknown fields are ignored. Missing fields fall
39
+ * back to `DEFAULT_VOICE_CONFIG`.
40
+ *
41
+ * Accepted legacy keys:
42
+ * - web: `{ttsVoice, autoSend, voiceResponse}`
43
+ * - mobile: `{voiceEnabled, voiceAutoSend, voiceResponseEnabled, neuralVadEnabled, ttsVoice}`
44
+ * - desktop: `{ttsVoice, voiceAutoSend, voiceResponseEnabled}`
45
+ * - spatial: `{voiceEnabled, ttsVoice}`
46
+ *
47
+ * The function is intentionally defensive — it operates on `unknown` because
48
+ * the typical caller is reading from `localStorage` / `AsyncStorage` / a
49
+ * Tauri JSON config, all of which return untyped blobs.
50
+ */
51
+ export declare function migrateVoiceConfig(raw: unknown): VoiceConfig;
52
+ //# sourceMappingURL=voice-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice-config.d.ts","sourceRoot":"","sources":["../src/voice-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,+EAA+E;AAC/E,eAAO,MAAM,oBAAoB,EAAE,WAMlC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,WAAW,CAuB5D"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Canonical voice configuration shape.
3
+ *
4
+ * Every surface (web, mobile, desktop, spatial) has historically carried its
5
+ * own voice config — with drifted field names (`voiceResponse` vs
6
+ * `voiceResponseEnabled` vs `speakResponses`, `autoSend` vs `voiceAutoSend`)
7
+ * and different subsets of the feature set. This module is the authoritative
8
+ * vocabulary. Surfaces may keep UI-internal state in their own shapes, but
9
+ * anything crossing the SDK boundary — sync, import/export, cross-surface
10
+ * helpers — speaks `VoiceConfig`.
11
+ *
12
+ * Migration helpers are provided for the legacy shapes so each surface can
13
+ * normalize on load without inventing its own migration one-offs.
14
+ */
15
+ /** Default voice config — voice off, sensible behavior when it's turned on. */
16
+ export const DEFAULT_VOICE_CONFIG = {
17
+ enabled: false,
18
+ autoSend: true,
19
+ speakResponses: true,
20
+ ttsVoice: "alloy",
21
+ neuralVad: true,
22
+ };
23
+ /**
24
+ * Normalize any of the historical surface-specific voice shapes onto the
25
+ * canonical `VoiceConfig`. Unknown fields are ignored. Missing fields fall
26
+ * back to `DEFAULT_VOICE_CONFIG`.
27
+ *
28
+ * Accepted legacy keys:
29
+ * - web: `{ttsVoice, autoSend, voiceResponse}`
30
+ * - mobile: `{voiceEnabled, voiceAutoSend, voiceResponseEnabled, neuralVadEnabled, ttsVoice}`
31
+ * - desktop: `{ttsVoice, voiceAutoSend, voiceResponseEnabled}`
32
+ * - spatial: `{voiceEnabled, ttsVoice}`
33
+ *
34
+ * The function is intentionally defensive — it operates on `unknown` because
35
+ * the typical caller is reading from `localStorage` / `AsyncStorage` / a
36
+ * Tauri JSON config, all of which return untyped blobs.
37
+ */
38
+ export function migrateVoiceConfig(raw) {
39
+ if (raw == null || typeof raw !== "object")
40
+ return { ...DEFAULT_VOICE_CONFIG };
41
+ const obj = raw;
42
+ const pick = (keys, isType) => {
43
+ for (const key of keys) {
44
+ const v = obj[key];
45
+ if (isType(v))
46
+ return v;
47
+ }
48
+ return undefined;
49
+ };
50
+ const isBool = (v) => typeof v === "boolean";
51
+ const isStr = (v) => typeof v === "string";
52
+ return {
53
+ enabled: pick(["enabled", "voiceEnabled"], isBool) ?? DEFAULT_VOICE_CONFIG.enabled,
54
+ autoSend: pick(["autoSend", "voiceAutoSend"], isBool) ?? DEFAULT_VOICE_CONFIG.autoSend,
55
+ speakResponses: pick(["speakResponses", "voiceResponse", "voiceResponseEnabled"], isBool) ??
56
+ DEFAULT_VOICE_CONFIG.speakResponses,
57
+ ttsVoice: pick(["ttsVoice"], isStr) ?? DEFAULT_VOICE_CONFIG.ttsVoice,
58
+ neuralVad: pick(["neuralVad", "neuralVadEnabled"], isBool),
59
+ };
60
+ }
61
+ //# sourceMappingURL=voice-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice-config.js","sourceRoot":"","sources":["../src/voice-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAsBH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,IAAI;IACd,cAAc,EAAE,IAAI;IACpB,QAAQ,EAAE,OAAO;IACjB,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,IAAI,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,EAAE,GAAG,oBAAoB,EAAE,CAAC;IAC/E,MAAM,GAAG,GAAG,GAA8B,CAAC;IAE3C,MAAM,IAAI,GAAG,CAAI,IAAc,EAAE,MAA8B,EAAiB,EAAE;QAChF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACnB,IAAI,MAAM,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAC;QAC1B,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IACF,MAAM,MAAM,GAAG,CAAC,CAAU,EAAgB,EAAE,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;IACpE,MAAM,KAAK,GAAG,CAAC,CAAU,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC;IAEjE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,IAAI,oBAAoB,CAAC,OAAO;QAClF,QAAQ,EAAE,IAAI,CAAC,CAAC,UAAU,EAAE,eAAe,CAAC,EAAE,MAAM,CAAC,IAAI,oBAAoB,CAAC,QAAQ;QACtF,cAAc,EACZ,IAAI,CAAC,CAAC,gBAAgB,EAAE,eAAe,EAAE,sBAAsB,CAAC,EAAE,MAAM,CAAC;YACzE,oBAAoB,CAAC,cAAc;QACrC,QAAQ,EAAE,IAAI,CAAC,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,IAAI,oBAAoB,CAAC,QAAQ;QACpE,SAAS,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC3D,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@motebit/sdk",
3
- "version": "0.6.11",
4
- "description": "Core types for the motebit protocol state vectors, identity, memory, policy, tools, and agent delegation",
3
+ "version": "0.8.0",
4
+ "description": "Motebit product development kitshared types, config schemas, normalization, and adapters for Motebit surfaces. Re-exports @motebit/protocol.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -12,10 +12,10 @@
12
12
  }
13
13
  },
14
14
  "files": [
15
- "dist/index.js",
16
- "dist/index.js.map",
17
- "dist/index.d.ts",
18
- "dist/index.d.ts.map",
15
+ "dist/**/*.js",
16
+ "dist/**/*.js.map",
17
+ "dist/**/*.d.ts",
18
+ "dist/**/*.d.ts.map",
19
19
  "LICENSE",
20
20
  "README.md"
21
21
  ],
@@ -45,6 +45,9 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
+ "dependencies": {
49
+ "@motebit/protocol": "0.8.0"
50
+ },
48
51
  "devDependencies": {
49
52
  "@types/node": "^22.0.0",
50
53
  "typescript": "^5.6.0",