@moraya/core 0.2.0 → 0.4.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 (54) hide show
  1. package/README.md +215 -41
  2. package/dist/ai/drivers/claude.d.ts +6 -0
  3. package/dist/ai/drivers/claude.js +229 -0
  4. package/dist/ai/drivers/claude.js.map +1 -0
  5. package/dist/ai/drivers/gemini.d.ts +6 -0
  6. package/dist/ai/drivers/gemini.js +212 -0
  7. package/dist/ai/drivers/gemini.js.map +1 -0
  8. package/dist/ai/drivers/index.d.ts +14 -0
  9. package/dist/ai/drivers/index.js +617 -0
  10. package/dist/ai/drivers/index.js.map +1 -0
  11. package/dist/ai/drivers/ollama.d.ts +8 -0
  12. package/dist/ai/drivers/ollama.js +158 -0
  13. package/dist/ai/drivers/ollama.js.map +1 -0
  14. package/dist/ai/drivers/openai.d.ts +7 -0
  15. package/dist/ai/drivers/openai.js +225 -0
  16. package/dist/ai/drivers/openai.js.map +1 -0
  17. package/dist/ai/drivers/tool-bridge.d.ts +37 -0
  18. package/dist/ai/drivers/tool-bridge.js +138 -0
  19. package/dist/ai/drivers/tool-bridge.js.map +1 -0
  20. package/dist/ai/drivers/types.d.ts +2 -0
  21. package/dist/ai/drivers/types.js +1 -0
  22. package/dist/ai/drivers/types.js.map +1 -0
  23. package/dist/ai/drivers/util.d.ts +13 -0
  24. package/dist/ai/drivers/util.js +40 -0
  25. package/dist/ai/drivers/util.js.map +1 -0
  26. package/dist/ai/image.d.ts +37 -0
  27. package/dist/ai/image.js +36 -0
  28. package/dist/ai/image.js.map +1 -0
  29. package/dist/ai/index.d.ts +37 -0
  30. package/dist/ai/index.js +826 -0
  31. package/dist/ai/index.js.map +1 -0
  32. package/dist/ai/types.d.ts +92 -0
  33. package/dist/ai/types.js +1 -0
  34. package/dist/ai/types.js.map +1 -0
  35. package/dist/ai/voice.d.ts +42 -0
  36. package/dist/ai/voice.js +34 -0
  37. package/dist/ai/voice.js.map +1 -0
  38. package/dist/chat-markdown/index.d.ts +82 -0
  39. package/dist/chat-markdown/index.js +165 -0
  40. package/dist/chat-markdown/index.js.map +1 -0
  41. package/dist/i18n/locales/ar.json +806 -732
  42. package/dist/i18n/locales/de.json +912 -838
  43. package/dist/i18n/locales/en.json +34 -5
  44. package/dist/i18n/locales/es.json +952 -876
  45. package/dist/i18n/locales/fr.json +1784 -1708
  46. package/dist/i18n/locales/hi.json +1808 -1734
  47. package/dist/i18n/locales/ja.json +839 -765
  48. package/dist/i18n/locales/ko.json +1783 -1709
  49. package/dist/i18n/locales/pt.json +894 -820
  50. package/dist/i18n/locales/ru.json +812 -738
  51. package/dist/i18n/locales/zh-CN.json +34 -5
  52. package/dist/i18n/locales/zh-Hant.json +1039 -965
  53. package/dist/types-CwM77g7u.d.ts +88 -0
  54. package/package.json +26 -2
@@ -0,0 +1,88 @@
1
+ import { AIProvider, AIProviderConfig, AIRequest, AIResponse, ToolCallRequest, AIUsage } from './ai/types.js';
2
+
3
+ /**
4
+ * Transport adapter — the platform seam. Core builds requests and parses
5
+ * responses; the consumer executes them:
6
+ * - desktop: Tauri `ai_proxy_*` commands (key injected by Rust from Keychain)
7
+ * - web/mobile: direct `fetch()` + SSE (key applied per AuthDescriptor)
8
+ *
9
+ * Mirrors the existing `MediaResolver`/`LinkOpener` DI pattern in core.
10
+ */
11
+
12
+ /** Declarative auth: tells a web transport HOW to attach the secret. The Tauri
13
+ * transport ignores it (Rust already encodes the same rules per `provider`). */
14
+ interface AuthDescriptor {
15
+ scheme: 'bearer' | 'header' | 'query' | 'none';
16
+ /** for scheme:'header' (e.g. 'x-api-key') */
17
+ headerName?: string;
18
+ /** for scheme:'query' (e.g. 'key') */
19
+ queryParam?: string;
20
+ }
21
+ /** A fully-built provider request EXCEPT the secret. Produced by a driver. */
22
+ interface TransportRequest {
23
+ /** Proxy-provider key passed to the Tauri proxy ('claude'|'openai'|'gemini'|'deepseek'|'ollama'). */
24
+ provider: AIProvider | 'openai' | 'claude' | 'gemini' | 'deepseek' | 'ollama';
25
+ /** configId for Keychain lookup on desktop. */
26
+ configId: string;
27
+ /** Keychain key prefix (default 'ai-key:'). */
28
+ keyPrefix?: string;
29
+ method: 'POST' | 'GET';
30
+ url: string;
31
+ /** Headers WITHOUT the auth secret. */
32
+ headers: Record<string, string>;
33
+ /** JSON-stringified request body. */
34
+ body: string;
35
+ auth: AuthDescriptor;
36
+ /** Web transport fills this from its key store; Tauri transport ignores it
37
+ * (Rust holds the key). Drivers never set it. */
38
+ apiKey?: string;
39
+ }
40
+ interface TransportResponse {
41
+ status: number;
42
+ /** Raw response text (a driver's parseResponse parses it). */
43
+ body: string;
44
+ }
45
+ interface StreamCallbacks {
46
+ signal?: AbortSignal;
47
+ /** A plain text delta (desktop: Rust pre-extracted text chunk). */
48
+ onText: (delta: string) => void;
49
+ /** A raw provider SSE envelope JSON string (web: every `data:` payload;
50
+ * desktop: the `\x02`-tagged non-text events). Driver folds parse it. */
51
+ onEnvelope: (rawJson: string) => void;
52
+ }
53
+ interface AITransport {
54
+ fetch(req: TransportRequest, signal?: AbortSignal): Promise<TransportResponse>;
55
+ stream(req: TransportRequest, cb: StreamCallbacks): Promise<void>;
56
+ /** Optional per-provider streaming capability. Defaults to true when absent.
57
+ * Desktop returns false for gemini/ollama (the Rust proxy has no SSE path
58
+ * for them) so the orchestrator one-shots them; web returns true for gemini. */
59
+ canStream?(provider: AIProvider): boolean;
60
+ }
61
+
62
+ /** Per-provider driver contract. Drivers are PURE: build a request (no secret)
63
+ * and parse responses/streams. */
64
+
65
+ /** Stateful streaming accumulator. The SAME parser runs on desktop chunks and
66
+ * web SSE envelopes. */
67
+ interface StreamFold {
68
+ /** Feed a raw provider SSE envelope JSON; return any text delta to surface. */
69
+ pushEnvelope(rawJson: string): string | undefined;
70
+ /** Finalize after the stream ends. */
71
+ finish(): {
72
+ toolCalls?: ToolCallRequest[];
73
+ stopReason: string;
74
+ usage?: AIUsage;
75
+ };
76
+ }
77
+ interface AIDriver {
78
+ /** Build the wire request WITHOUT the secret. */
79
+ buildChatRequest(config: AIProviderConfig, request: AIRequest, stream: boolean): TransportRequest;
80
+ /** Parse a non-streaming JSON response (already JSON.parsed). */
81
+ parseResponse(json: Record<string, unknown>, config: AIProviderConfig): AIResponse;
82
+ /** Create a streaming folder. */
83
+ createStreamFold(): StreamFold;
84
+ /** Whether this provider can stream at all (gated further by transport.canStream). */
85
+ readonly supportsStreaming: boolean;
86
+ }
87
+
88
+ export type { AIDriver as A, StreamFold as S, TransportRequest as T, AITransport as a, AuthDescriptor as b, StreamCallbacks as c, TransportResponse as d };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moraya/core",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Shared markdown editor core for Moraya desktop and Moraya Web. ProseMirror schema, markdown-it parser, prosemirror-markdown serializer, plugins, and editor lifecycle factories. Pure ESM, host-agnostic, dependency-injected.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,7 +43,31 @@
43
43
  "import": "./dist/i18n/index.js",
44
44
  "types": "./dist/i18n/index.d.ts"
45
45
  },
46
- "./i18n/locales/*.json": "./dist/i18n/locales/*.json"
46
+ "./i18n/locales/*.json": "./dist/i18n/locales/*.json",
47
+ "./ai": {
48
+ "import": "./dist/ai/index.js",
49
+ "types": "./dist/ai/index.d.ts"
50
+ },
51
+ "./ai/types": {
52
+ "import": "./dist/ai/types.js",
53
+ "types": "./dist/ai/types.d.ts"
54
+ },
55
+ "./ai/image": {
56
+ "import": "./dist/ai/image.js",
57
+ "types": "./dist/ai/image.d.ts"
58
+ },
59
+ "./ai/voice": {
60
+ "import": "./dist/ai/voice.js",
61
+ "types": "./dist/ai/voice.d.ts"
62
+ },
63
+ "./ai/drivers/*": {
64
+ "import": "./dist/ai/drivers/*.js",
65
+ "types": "./dist/ai/drivers/*.d.ts"
66
+ },
67
+ "./chat-markdown": {
68
+ "import": "./dist/chat-markdown/index.js",
69
+ "types": "./dist/chat-markdown/index.d.ts"
70
+ }
47
71
  },
48
72
  "files": [
49
73
  "dist",