@mimikkai/opencode-mimikkai-connect 1.0.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +128 -0
  3. package/dist/index.js +2017 -0
  4. package/package.json +39 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shatyuka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # MimikkAi Connect for OpenCode
2
+
3
+ OpenCode plugin for MimikkAi — device authorization flow + LiteLLM gateway integration.
4
+
5
+ ## Prerequisites
6
+
7
+ - [OpenCode](https://opencode.ai) installed
8
+ - [Bun](https://bun.sh) for building
9
+ - A MimikkAi account (register at [panel.mimikkai.ru](https://panel.mimikkai.ru))
10
+
11
+ ## Installation
12
+
13
+ ```shell
14
+ bun install
15
+ bun run build
16
+ ```
17
+
18
+ ## Configuration
19
+
20
+ Add the plugin to your `opencode.json`:
21
+
22
+ ```json
23
+ {
24
+ "plugin": ["opencode-mimikkai-connect"]
25
+ }
26
+ ```
27
+
28
+ ## Authentication Flow
29
+
30
+ ```
31
+ User runs `opencode auth login`
32
+
33
+
34
+ ┌─────────────────────────────┐
35
+ │ Device Authorization │
36
+ │ POST /api/auth/device/ │
37
+ │ authorize │
38
+ └────────────┬────────────────┘
39
+
40
+
41
+ Browser opens:
42
+ panel.mimikkai.ru/device?code=AB12-CD34
43
+
44
+
45
+ ┌─────────────────────────────┐
46
+ │ Poll for token │
47
+ │ POST /api/auth/device/ │
48
+ │ token (every 5s) │
49
+ │ 202 → pending │
50
+ │ 200 → { token, user } │
51
+ └────────────┬────────────────┘
52
+
53
+
54
+ ┌─────────────────────────────┐
55
+ │ Fetch LiteLLM virtual key │
56
+ │ GraphQL → userViewer │
57
+ │ → litellmVirtualKey (sk-) │
58
+ └────────────┬────────────────┘
59
+
60
+
61
+ ┌─────────────────────────────┐
62
+ │ Save to storage │
63
+ │ ~/.config/opencode/ │
64
+ │ mimikkai.json │
65
+ └────────────┬────────────────┘
66
+
67
+
68
+ ┌─────────────────────────────┐
69
+ │ Register provider + models │
70
+ │ @ai-sdk/openai-compatible │
71
+ │ → litellm.mimikkai.ru/v1 │
72
+ │ → /model/info │
73
+ └─────────────────────────────┘
74
+ ```
75
+
76
+ ## Usage
77
+
78
+ 1. Run `opencode auth login` and select **Device Authorization**
79
+ 2. A browser opens — confirm the displayed code
80
+ 3. The plugin fetches your LiteLLM virtual key and syncs available models
81
+ 4. Select a MimikkAi model in OpenCode's model picker
82
+
83
+ ## Architecture
84
+
85
+ ```
86
+ src/
87
+ ├── constants.ts ← Mimikkai endpoints (service, panel, litellm)
88
+ ├── mimikkai.ts ← API client (device auth, GraphQL, /model/info)
89
+ ├── storage.ts ← Token storage (~/.config/opencode/mimikkai.json)
90
+ ├── logger.ts ← Configurable structured logging (LOG_LEVEL env)
91
+ ├── index.ts ← Plugin entry (auth hook + config hook + dispose)
92
+ └── test/
93
+ ├── mimikkai.test.ts ← API client tests (24 tests)
94
+ └── storage.test.ts ← Storage tests (8 tests)
95
+ ```
96
+
97
+ ### Key Design Decisions
98
+
99
+ - **Sanctum token → LiteLLM key exchange**: The Sanctum token (`1|abc...`) from auth is exchanged for a LiteLLM virtual key (`sk-...`) via GraphQL. Only the `sk-` key is used for API requests.
100
+ - **Key refresh on every config hook**: The `config` hook re-fetches the LiteLLM key on each invocation using the stored Sanctum token, falling back to the cached key if the refresh fails.
101
+ - **Token validation on startup**: The `loader` validates the Sanctum token via `userViewer` GraphQL query before using the stored LiteLLM key.
102
+ - **Far-future expiry**: The OAuth callback returns a 1-year expiry since Sanctum tokens don't have a known short TTL.
103
+
104
+ ## Troubleshooting
105
+
106
+ ### "LiteLLM virtual key is missing or masked"
107
+
108
+ The backend returned a masked key (containing `...`). This happens when the key hasn't been fully provisioned. Try logging out and back in:
109
+
110
+ ```shell
111
+ rm ~/.config/opencode/mimikkai.json
112
+ opencode auth login
113
+ ```
114
+
115
+ ### No models appear
116
+
117
+ The plugin couldn't fetch models from `litellm.mimikkai.ru/model/info`. Check:
118
+ 1. Your LiteLLM key is valid (`sk-` prefix)
119
+ 2. Network connectivity to `litellm.mimikkai.ru`
120
+ 3. Set `LOG_LEVEL=debug` for verbose logging
121
+
122
+ ### Token expired
123
+
124
+ If the Sanctum token expires, the `loader` will detect it and return empty, forcing re-authentication. Run `opencode auth login` again.
125
+
126
+ ## License
127
+
128
+ MIT License.