@kuckit/ai-module 2.0.3 → 2.0.5
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/dist/index.d.ts +6 -1
- package/dist/index.js +18 -9
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import * as _kuckit_sdk0 from "@kuckit/sdk";
|
|
2
2
|
|
|
3
3
|
//#region src/server/module.d.ts
|
|
4
|
-
|
|
4
|
+
interface AIModuleConfig {
|
|
5
|
+
/** Optional API key override. Falls back to GOOGLE_GENERATIVE_AI_API_KEY env var */
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
/** Model ID to use. Defaults to 'gemini-2.5-flash' */
|
|
8
|
+
model?: string;
|
|
9
|
+
}
|
|
5
10
|
declare const kuckitModule: _kuckit_sdk0.KuckitModuleDefinition<AIModuleConfig>;
|
|
6
11
|
//#endregion
|
|
7
12
|
export { type AIModuleConfig, kuckitModule };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { asFunction, defineKuckitModule } from "@kuckit/sdk";
|
|
2
3
|
import { convertToModelMessages, streamText } from "ai";
|
|
3
4
|
import { Router } from "express";
|
|
4
5
|
import { z } from "zod";
|
|
5
6
|
|
|
7
|
+
//#region rolldown:runtime
|
|
8
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
6
11
|
//#region src/server/use-cases/stream-chat.ts
|
|
7
12
|
const makeStreamChat = ({ aiProvider, logger }) => {
|
|
8
13
|
return async (input) => {
|
|
@@ -46,10 +51,7 @@ const createAiRouter = () => {
|
|
|
46
51
|
const router = Router();
|
|
47
52
|
router.post("/chat", async (req, res) => {
|
|
48
53
|
const scope = req.scope;
|
|
49
|
-
if (!scope) {
|
|
50
|
-
res.status(500).json({ error: "Internal server error" });
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
54
|
+
if (!scope) return res.status(500).json({ error: "Internal server error" });
|
|
53
55
|
const { session, requestLogger: logger, streamChat } = scope.cradle;
|
|
54
56
|
if (!session?.user?.id) {
|
|
55
57
|
logger.warn("Unauthenticated AI chat request");
|
|
@@ -87,11 +89,18 @@ const kuckitModule = defineKuckitModule({
|
|
|
87
89
|
version: "0.1.0",
|
|
88
90
|
capabilities: ["nav.item", "api.public"],
|
|
89
91
|
async register(ctx) {
|
|
90
|
-
const { container } = ctx;
|
|
91
|
-
container.register({
|
|
92
|
-
aiProvider
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
const { container, config: moduleConfig } = ctx;
|
|
93
|
+
container.register({
|
|
94
|
+
aiProvider: asFunction(() => {
|
|
95
|
+
if (!(moduleConfig?.apiKey ?? process.env.GOOGLE_GENERATIVE_AI_API_KEY)) throw new Error("AI module requires GOOGLE_GENERATIVE_AI_API_KEY environment variable or apiKey in module config");
|
|
96
|
+
const { google } = __require("@ai-sdk/google");
|
|
97
|
+
return google(moduleConfig?.model ?? "gemini-2.5-flash");
|
|
98
|
+
}).singleton(),
|
|
99
|
+
streamChat: asFunction(({ aiProvider, logger }) => makeStreamChat({
|
|
100
|
+
aiProvider,
|
|
101
|
+
logger
|
|
102
|
+
})).scoped()
|
|
103
|
+
});
|
|
95
104
|
},
|
|
96
105
|
registerApi(ctx) {
|
|
97
106
|
const aiRouter = createAiRouter();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kuckit/ai-module",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "AI chat streaming module for Kuckit applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/server/module.js",
|
|
@@ -28,14 +28,16 @@
|
|
|
28
28
|
"prepublishOnly": "npm run build && node ../../scripts/resolve-workspace-protocols.cjs && node ../../scripts/check-no-workspace-protocol.cjs"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@kuckit/domain": "^2.0.
|
|
32
|
-
"@kuckit/sdk": "^2.0.
|
|
33
|
-
"@kuckit/sdk-react": "^2.0.
|
|
31
|
+
"@kuckit/domain": "^2.0.5",
|
|
32
|
+
"@kuckit/sdk": "^2.0.5",
|
|
33
|
+
"@kuckit/sdk-react": "^2.0.5",
|
|
34
34
|
"react": "^18 || ^19",
|
|
35
35
|
"typescript": "^5",
|
|
36
36
|
"express": "^4 || ^5"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@ai-sdk/provider-utils": "^2.0.0",
|
|
40
|
+
"@ai-sdk/google": "^2.0.0",
|
|
39
41
|
"@ai-sdk/react": "^2.0.39",
|
|
40
42
|
"ai": "^5.0.49",
|
|
41
43
|
"zod": "^4.1.11",
|