|
| 1 | +# Story 184.1: OpenAI-Compatible Kimi Provider Contract |
| 2 | + |
| 3 | +## Metadata |
| 4 | + |
| 5 | +| Campo | Valor | |
| 6 | +|-------|-------| |
| 7 | +| Story ID | 184.1 | |
| 8 | +| Epic | [184 - Kimi K2.5 Provider Support](./EPIC-184-KIMI-K2-5-PROVIDER.md) | |
| 9 | +| Status | Draft | |
| 10 | +| Executor | @dev | |
| 11 | +| Quality Gate | @architect | |
| 12 | +| quality_gate_tools | npm test focused, npm run lint, npm run typecheck, npm run validate:manifest | |
| 13 | +| Points | 8 | |
| 14 | +| Priority | P4 | |
| 15 | +| Story Order | 1 | |
| 16 | +| Source Issue | #184 | |
| 17 | +| Issue URL | https://github.com/SynkraAI/aiox-core/issues/184 | |
| 18 | +| Implementation Repository | SynkraAI/aiox-core | |
| 19 | +| Start Gate | PO/architect validation must confirm provider scope and no overlap with Kimi IDE sync work. | |
| 20 | + |
| 21 | +## Status |
| 22 | + |
| 23 | +- [x] Draft |
| 24 | +- [ ] PO validated |
| 25 | +- [ ] Ready for implementation |
| 26 | +- [ ] Ready for Review |
| 27 | +- [ ] Done |
| 28 | + |
| 29 | +## Executor Assignment |
| 30 | + |
| 31 | +```yaml |
| 32 | +executor: "@dev" |
| 33 | +quality_gate: "@architect" |
| 34 | +quality_gate_tools: |
| 35 | + - npm test focused |
| 36 | + - npm run lint |
| 37 | + - npm run typecheck |
| 38 | + - npm run validate:manifest |
| 39 | +accountable: "pedro-valerio" |
| 40 | +domain: "*" |
| 41 | +deploy_type: "none" |
| 42 | +``` |
| 43 | +
|
| 44 | +## Community Origin |
| 45 | +
|
| 46 | +**Discussion URL**: https://github.com/SynkraAI/aiox-core/issues/184 |
| 47 | +**Author**: GitHub issue author |
| 48 | +**Approved Date**: 2026-03-11 |
| 49 | +**Approved By**: AIOX triage via `status: confirmed` |
| 50 | + |
| 51 | +## Story |
| 52 | + |
| 53 | +**As a** framework maintainer, |
| 54 | +**I want** Kimi K2.5 to be available through a generic OpenAI-compatible provider in the AIOX provider factory, |
| 55 | +**so that** agents can use Moonshot/OpenRouter-compatible model endpoints without replacing the existing Claude/Gemini provider contract. |
| 56 | + |
| 57 | +## Contexto |
| 58 | + |
| 59 | +Issue #184 asks for native Kimi K2.5 support as an alternative to OpenAI or Claude. The current implementation already has an `AIProvider` base class, `ClaudeProvider`, `GeminiProvider` and a factory that loads `.aiox-ai-config.yaml`, but the factory only knows `claude` and `gemini`. |
| 60 | + |
| 61 | +Official Kimi documentation confirms the API is OpenAI-compatible and uses: |
| 62 | + |
| 63 | +- `base_url`: `https://api.moonshot.ai/v1` |
| 64 | +- chat completions endpoint relative to that base URL: `/chat/completions` |
| 65 | + |
| 66 | +The correct implementation path is a reusable `OpenAICompatibleProvider` plus a Kimi preset/alias. A Kimi-specific hardcoded provider would solve less and create avoidable duplication. |
| 67 | + |
| 68 | +## Acceptance Criteria |
| 69 | + |
| 70 | +- [ ] AC1: A new `OpenAICompatibleProvider` exists under `.aiox-core/infrastructure/integrations/ai-providers/` and extends the existing `AIProvider` contract. |
| 71 | +- [ ] AC2: The provider supports `baseURL`/`baseUrl`, `apiKey`, `apiKeyEnv`, `model`, `timeout`, optional default headers and Chat Completions-compatible request payloads. |
| 72 | +- [ ] AC3: The provider never logs raw API keys and returns the existing `AIResponse` shape with provider/model/duration metadata. |
| 73 | +- [ ] AC4: `ai-provider-factory.js` registers `openai-compatible` and `kimi` aliases without changing the default `claude` primary and `gemini` fallback. |
| 74 | +- [ ] AC5: Kimi default config uses Moonshot's OpenAI-compatible base URL and a Kimi K2.5 model identifier only as a configurable preset, not as a hard dependency. |
| 75 | +- [ ] AC6: `getAvailableProviders()` and `getProvidersStatus()` include configured providers without hardcoding only `claude` and `gemini`. |
| 76 | +- [ ] AC7: Tests mock HTTP/fetch and cover success, API error, missing key, timeout or network failure, JSON response parsing and factory alias registration. |
| 77 | +- [ ] AC8: Documentation shows `.aiox-ai-config.yaml` examples for Moonshot/Kimi and OpenRouter-style overrides without committing secrets. |
| 78 | +- [ ] AC9: Existing Claude/Gemini provider tests continue to pass unchanged in behavior. |
| 79 | +- [ ] AC10: The story does not merge or depend on the stale Kimi IDE sync worktree; IDE sync can become a separate future story if still desired. |
| 80 | + |
| 81 | +## CodeRabbit Integration |
| 82 | + |
| 83 | +### Story Type Analysis |
| 84 | + |
| 85 | +**Primary Type**: Core runtime feature |
| 86 | +**Secondary Type(s)**: Provider abstraction, configuration, documentation |
| 87 | +**Complexity**: Medium-high |
| 88 | + |
| 89 | +### Specialized Agent Assignment |
| 90 | + |
| 91 | +**Primary Agents**: |
| 92 | +- @dev |
| 93 | +- @architect |
| 94 | + |
| 95 | +**Supporting Agents**: |
| 96 | +- @qa |
| 97 | +- @po |
| 98 | +- @devops |
| 99 | + |
| 100 | +### Quality Gate Tasks |
| 101 | + |
| 102 | +- [ ] Pre-Commit (@dev): Run provider factory tests and the new OpenAI-compatible provider tests. |
| 103 | +- [ ] Pre-PR (@devops): Confirm no secrets are committed and manifest updates match package files. |
| 104 | +- [ ] Architecture Review (@architect): Confirm the design is generic OpenAI-compatible provider plus Kimi preset, not a one-off Kimi-only fork. |
| 105 | + |
| 106 | +## Tasks / Subtasks |
| 107 | + |
| 108 | +- [ ] T1: Confirm exact provider file paths and exports from current `ai-providers` module. |
| 109 | +- [ ] T2: Implement `OpenAICompatibleProvider` using native fetch or an existing local HTTP primitive, with graceful fallback for unsupported runtimes if needed. |
| 110 | +- [ ] T3: Add `kimi` and `openai-compatible` factory registration, config merging and provider status discovery. |
| 111 | +- [ ] T4: Add deterministic tests with mocked HTTP responses and no external network calls. |
| 112 | +- [ ] T5: Update docs with Kimi/Moonshot and OpenRouter configuration examples. |
| 113 | +- [ ] T6: Update manifest/entity registry only if required by existing packaging gates. |
| 114 | +- [ ] T7: Run focused tests, lint, typecheck and manifest validation. |
| 115 | + |
| 116 | +## Dev Notes |
| 117 | + |
| 118 | +- Do not add a live Moonshot/OpenRouter integration test in CI. |
| 119 | +- Do not introduce a new SDK dependency unless native fetch is insufficient and the dependency is justified in the PR. |
| 120 | +- Prefer `apiKeyEnv` defaults such as `MOONSHOT_API_KEY` for Kimi and allow explicit override. |
| 121 | +- Treat `baseURL` and `baseUrl` as equivalent input names for compatibility with common OpenAI-style config. |
| 122 | +- Preserve current default provider behavior: `primary: claude`, `fallback: gemini`. |
| 123 | +- The stale `aiox-core-kimi` branch/worktree is scoped to IDE sync and should not be replayed into this story without a separate decision. |
| 124 | + |
| 125 | +## Testing |
| 126 | + |
| 127 | +Required focused validation: |
| 128 | + |
| 129 | +```bash |
| 130 | +npm test -- --runTestsByPath tests/infrastructure/ai-providers/ai-provider-factory.test.js |
| 131 | +npm test -- --runTestsByPath tests/infrastructure/ai-providers/openai-compatible-provider.test.js |
| 132 | +npm run lint |
| 133 | +npm run typecheck |
| 134 | +npm run validate:manifest |
| 135 | +``` |
| 136 | + |
| 137 | +If the provider test lands under a different path, update this section and the File List during implementation. |
| 138 | + |
| 139 | +## Dependencies |
| 140 | + |
| 141 | +- **Blocked by:** PO/architect validation of this draft. |
| 142 | +- **Blocks:** issue #184 closure. |
| 143 | +- **Related:** issue #137; existing LLM routing docs; Kimi IDE sync branch is adjacent but not in scope. |
| 144 | + |
| 145 | +## Definition of Ready |
| 146 | + |
| 147 | +- [ ] PO validation completed with no unresolved blocker. |
| 148 | +- [x] Target provider surfaces confirmed against current code reality. |
| 149 | +- [x] Acceptance criteria are testable without live API calls. |
| 150 | + |
| 151 | +## Definition of Done |
| 152 | + |
| 153 | +- [ ] All ACs complete. |
| 154 | +- [ ] Focused tests pass. |
| 155 | +- [ ] Lint and typecheck pass. |
| 156 | +- [ ] Manifest validation passes if package files are added. |
| 157 | +- [ ] File List and Dev Agent Record are updated. |
| 158 | +- [ ] Issue #184 has implementation evidence and can be closed or explicitly moved to follow-up scope. |
| 159 | + |
| 160 | +## Dev Agent Record |
| 161 | + |
| 162 | +### Debug Log |
| 163 | + |
| 164 | +- Draft created from issue #184 and current repo inspection on 2026-05-08. |
| 165 | +- Confirmed no open PR currently targets Kimi/Moonshot/provider support. |
| 166 | +- Identified stale `aiox-core-kimi` branch/worktree as IDE sync scope, not provider LLM scope. |
| 167 | +- Confirmed current provider factory registers `claude` and `gemini` only. |
| 168 | +- Verified current Kimi API docs: OpenAI-compatible base URL is `https://api.moonshot.ai/v1`, and the chat completions endpoint relative to that base URL is `/chat/completions`. |
| 169 | + |
| 170 | +### Agent Model Used |
| 171 | + |
| 172 | +- GPT-5 Codex |
| 173 | + |
| 174 | +### Completion Notes |
| 175 | + |
| 176 | +- Draft only. No runtime implementation has been made in this story yet. |
| 177 | + |
| 178 | +### File List |
| 179 | + |
| 180 | +| File | Action | |
| 181 | +|------|--------| |
| 182 | +| `docs/stories/epic-184-kimi-provider/EPIC-184-KIMI-K2-5-PROVIDER.md` | Created | |
| 183 | +| `docs/stories/epic-184-kimi-provider/STORY-184.1-OPENAI-COMPATIBLE-KIMI-PROVIDER.md` | Created | |
| 184 | + |
| 185 | +## Change Log |
| 186 | + |
| 187 | +| Data | Agente | Mudança | |
| 188 | +|------|--------|---------| |
| 189 | +| 2026-05-08 | @sm / Codex | Epic/story draft criados a partir do issue #184, leitura do provider factory atual e documentação oficial Kimi API. | |
0 commit comments