@forinda/kickjs-ai 2.3.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Felix Orinda
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,87 @@
1
+ # @forinda/kickjs-ai
2
+
3
+ AI runtime for KickJS. Provides a provider abstraction, an `@AiTool` decorator for turning controller endpoints into LLM tool calls, streaming response helpers, RAG primitives, and an agent loop executor — all built on the framework's existing DI container and Zod validation.
4
+
5
+ ## Status
6
+
7
+ **v0 — skeleton.** The provider interface, DI token, adapter skeleton, and `@AiTool` decorator exist and compile. Built-in providers (OpenAI, Anthropic, Google, Ollama), streaming, RAG, and the agent loop are scheduled for subsequent phases of Workstream 2 in the v3 AI plan.
8
+
9
+ ### Roadmap
10
+
11
+ - **Phase A** — Provider interface + OpenAI and Anthropic implementations (`chat`, `stream`, `embed`)
12
+ - **Phase B** — `@AiTool` decorator with runtime dispatch via the Express pipeline
13
+ - **Phase C** — RAG primitives + pgvector/Qdrant/Pinecone vector stores
14
+ - **Phase D** — Agent loop executor with request-scoped memory + prompt templates
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pnpm add @forinda/kickjs-ai
20
+ ```
21
+
22
+ Zod is a peer dependency (already installed in every KickJS project).
23
+
24
+ ## Usage (planned — phase A)
25
+
26
+ ```ts
27
+ import { bootstrap } from '@forinda/kickjs'
28
+ import { AiAdapter } from '@forinda/kickjs-ai'
29
+ import { OpenAIProvider } from '@forinda/kickjs-ai/providers/openai'
30
+ import { modules } from './modules'
31
+
32
+ export const app = await bootstrap({
33
+ modules,
34
+ adapters: [
35
+ new AiAdapter({
36
+ provider: new OpenAIProvider({ apiKey: process.env.OPENAI_API_KEY! }),
37
+ }),
38
+ ],
39
+ })
40
+ ```
41
+
42
+ Inject the provider in any service:
43
+
44
+ ```ts
45
+ import { Service, Inject } from '@forinda/kickjs'
46
+ import { AI_PROVIDER, type AiProvider } from '@forinda/kickjs-ai'
47
+
48
+ @Service()
49
+ export class SummarizeService {
50
+ constructor(@Inject(AI_PROVIDER) private readonly ai: AiProvider) {}
51
+
52
+ async summarize(text: string): Promise<string> {
53
+ const res = await this.ai.chat({
54
+ messages: [
55
+ { role: 'system', content: 'Summarize the following in 2 sentences.' },
56
+ { role: 'user', content: text },
57
+ ],
58
+ })
59
+ return res.content
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## `@AiTool` — endpoints as tool calls (planned — phase B)
65
+
66
+ The feature that makes this package unique. Because Zod schemas already power route validation, they also power tool definitions — no duplicated type declarations:
67
+
68
+ ```ts
69
+ import { Controller, Post, type Ctx } from '@forinda/kickjs'
70
+ import { AiTool } from '@forinda/kickjs-ai'
71
+ import { createTaskSchema } from './dtos/create-task.dto'
72
+
73
+ @Controller('/tasks')
74
+ export class TaskController {
75
+ @Post('/', { body: createTaskSchema, name: 'CreateTask' })
76
+ @AiTool({ description: 'Create a new task with title, priority, and optional assignee' })
77
+ create(ctx: Ctx<KickRoutes.TaskController['create']>) {
78
+ return this.createTaskUseCase.execute(ctx.body)
79
+ }
80
+ }
81
+ ```
82
+
83
+ At runtime, `ai.chat({ tools: 'auto' })` exposes every `@AiTool`-decorated method to the model. Tool calls route back through the normal Express pipeline, so auth, validation, and logging all still apply.
84
+
85
+ ## License
86
+
87
+ MIT