@kognitivedev/adapter-chat-self-hosted 0.2.29
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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-test.log +11 -0
- package/CHANGELOG.md +11 -0
- package/README.md +5 -0
- package/dist/__tests__/self-hosted-backend.test.d.ts +1 -0
- package/dist/__tests__/self-hosted-backend.test.js +49 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +13 -0
- package/package.json +38 -0
- package/src/__tests__/self-hosted-backend.test.ts +55 -0
- package/src/index.ts +16 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
$ vitest run
|
|
2
|
+
|
|
3
|
+
RUN v3.2.4 /Users/vserifsaglam/work/memory-experiment/packages/adapter-chat-self-hosted
|
|
4
|
+
|
|
5
|
+
✓ src/__tests__/self-hosted-backend.test.ts (2 tests) 13ms
|
|
6
|
+
|
|
7
|
+
Test Files 1 passed (1)
|
|
8
|
+
Tests 2 passed (2)
|
|
9
|
+
Start at 17:30:05
|
|
10
|
+
Duration 505ms (transform 43ms, setup 0ms, collect 58ms, tests 13ms, environment 0ms, prepare 127ms)
|
|
11
|
+
|
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
(0, vitest_1.describe)("createSelfHostedKognitiveChatBackend", () => {
|
|
6
|
+
(0, vitest_1.it)("targets the provided self-hosted base url", async () => {
|
|
7
|
+
const fetchMock = vitest_1.vi.fn()
|
|
8
|
+
.mockResolvedValueOnce(new Response("", {
|
|
9
|
+
status: 200,
|
|
10
|
+
headers: { "Content-Type": "text/event-stream" },
|
|
11
|
+
}))
|
|
12
|
+
.mockResolvedValueOnce(new Response(JSON.stringify({
|
|
13
|
+
threads: [],
|
|
14
|
+
total: 0,
|
|
15
|
+
}), {
|
|
16
|
+
status: 200,
|
|
17
|
+
headers: { "Content-Type": "application/json" },
|
|
18
|
+
}));
|
|
19
|
+
const backend = (0, index_1.createSelfHostedKognitiveChatBackend)({
|
|
20
|
+
baseUrl: "https://self-hosted.example.com",
|
|
21
|
+
fetch: fetchMock,
|
|
22
|
+
});
|
|
23
|
+
await backend.createExecutionClient({ agentName: "assistant" }).stream({
|
|
24
|
+
messages: [{ id: "u1", role: "user", parts: [{ type: "text", text: "Hello" }] }],
|
|
25
|
+
onEvent: async () => { },
|
|
26
|
+
});
|
|
27
|
+
await backend.createThreadClient({ agentName: "assistant" }).list();
|
|
28
|
+
(0, vitest_1.expect)(fetchMock.mock.calls[0]?.[0]).toBe("https://self-hosted.example.com/api/kognitive/agents/assistant/stream");
|
|
29
|
+
(0, vitest_1.expect)(fetchMock.mock.calls[1]?.[0]).toBe("https://self-hosted.example.com/api/kognitive/threads/agents/assistant");
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.it)("passes through auth headers", async () => {
|
|
32
|
+
const fetchMock = vitest_1.vi.fn().mockResolvedValue(new Response("", {
|
|
33
|
+
status: 200,
|
|
34
|
+
headers: { "Content-Type": "text/event-stream" },
|
|
35
|
+
}));
|
|
36
|
+
const backend = (0, index_1.createSelfHostedKognitiveChatBackend)({
|
|
37
|
+
baseUrl: "https://self-hosted.example.com",
|
|
38
|
+
headers: { Authorization: "Bearer token" },
|
|
39
|
+
fetch: fetchMock,
|
|
40
|
+
});
|
|
41
|
+
await backend.createExecutionClient({ agentName: "assistant" }).stream({
|
|
42
|
+
messages: [{ id: "u1", role: "user", parts: [{ type: "text", text: "Hello" }] }],
|
|
43
|
+
onEvent: async () => { },
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.expect)(fetchMock.mock.calls[0]?.[1]).toMatchObject({
|
|
46
|
+
headers: vitest_1.expect.objectContaining({ Authorization: "Bearer token" }),
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type KognitiveUIChatBackendOptions } from "@kognitivedev/adapter-chat-kognitive";
|
|
2
|
+
import type { ChatBackendAdapter } from "@kognitivedev/ui";
|
|
3
|
+
export interface SelfHostedKognitiveUIChatBackendOptions extends Omit<KognitiveUIChatBackendOptions, "serverUrl"> {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function createSelfHostedKognitiveChatBackend(options: SelfHostedKognitiveUIChatBackendOptions): ChatBackendAdapter;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSelfHostedKognitiveChatBackend = createSelfHostedKognitiveChatBackend;
|
|
4
|
+
const adapter_chat_kognitive_1 = require("@kognitivedev/adapter-chat-kognitive");
|
|
5
|
+
function createSelfHostedKognitiveChatBackend(options) {
|
|
6
|
+
return (0, adapter_chat_kognitive_1.createKognitiveUIChatBackend)({
|
|
7
|
+
serverUrl: options.baseUrl,
|
|
8
|
+
streamPath: options.streamPath,
|
|
9
|
+
threadBasePath: options.threadBasePath,
|
|
10
|
+
headers: options.headers,
|
|
11
|
+
fetch: options.fetch,
|
|
12
|
+
});
|
|
13
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kognitivedev/adapter-chat-self-hosted",
|
|
3
|
+
"version": "0.2.29",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"dev": "tsc -w --noCheck",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"test": "vitest run"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@kognitivedev/adapter-chat-kognitive": "^0.2.29",
|
|
17
|
+
"@kognitivedev/ui": "^0.2.29"
|
|
18
|
+
},
|
|
19
|
+
"description": "Self-hosted Kognitive-compatible chat adapter for @kognitivedev/ui",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"kognitive",
|
|
22
|
+
"chat",
|
|
23
|
+
"self-hosted",
|
|
24
|
+
"adapter"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/kognitivedev/kognitive",
|
|
30
|
+
"directory": "packages/adapter-chat-self-hosted"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://kognitive.dev",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^20.0.0",
|
|
35
|
+
"typescript": "^5.0.0",
|
|
36
|
+
"vitest": "^3.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createSelfHostedKognitiveChatBackend } from "../index";
|
|
3
|
+
|
|
4
|
+
describe("createSelfHostedKognitiveChatBackend", () => {
|
|
5
|
+
it("targets the provided self-hosted base url", async () => {
|
|
6
|
+
const fetchMock = vi.fn()
|
|
7
|
+
.mockResolvedValueOnce(new Response("", {
|
|
8
|
+
status: 200,
|
|
9
|
+
headers: { "Content-Type": "text/event-stream" },
|
|
10
|
+
}))
|
|
11
|
+
.mockResolvedValueOnce(new Response(JSON.stringify({
|
|
12
|
+
threads: [],
|
|
13
|
+
total: 0,
|
|
14
|
+
}), {
|
|
15
|
+
status: 200,
|
|
16
|
+
headers: { "Content-Type": "application/json" },
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const backend = createSelfHostedKognitiveChatBackend({
|
|
20
|
+
baseUrl: "https://self-hosted.example.com",
|
|
21
|
+
fetch: fetchMock as unknown as typeof fetch,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await backend.createExecutionClient({ agentName: "assistant" }).stream({
|
|
25
|
+
messages: [{ id: "u1", role: "user", parts: [{ type: "text", text: "Hello" }] }],
|
|
26
|
+
onEvent: async () => {},
|
|
27
|
+
});
|
|
28
|
+
await backend.createThreadClient!({ agentName: "assistant" })!.list();
|
|
29
|
+
|
|
30
|
+
expect(fetchMock.mock.calls[0]?.[0]).toBe("https://self-hosted.example.com/api/kognitive/agents/assistant/stream");
|
|
31
|
+
expect(fetchMock.mock.calls[1]?.[0]).toBe("https://self-hosted.example.com/api/kognitive/threads/agents/assistant");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("passes through auth headers", async () => {
|
|
35
|
+
const fetchMock = vi.fn().mockResolvedValue(new Response("", {
|
|
36
|
+
status: 200,
|
|
37
|
+
headers: { "Content-Type": "text/event-stream" },
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
const backend = createSelfHostedKognitiveChatBackend({
|
|
41
|
+
baseUrl: "https://self-hosted.example.com",
|
|
42
|
+
headers: { Authorization: "Bearer token" },
|
|
43
|
+
fetch: fetchMock as unknown as typeof fetch,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await backend.createExecutionClient({ agentName: "assistant" }).stream({
|
|
47
|
+
messages: [{ id: "u1", role: "user", parts: [{ type: "text", text: "Hello" }] }],
|
|
48
|
+
onEvent: async () => {},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(fetchMock.mock.calls[0]?.[1]).toMatchObject({
|
|
52
|
+
headers: expect.objectContaining({ Authorization: "Bearer token" }),
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createKognitiveUIChatBackend, type KognitiveUIChatBackendOptions } from "@kognitivedev/adapter-chat-kognitive";
|
|
2
|
+
import type { ChatBackendAdapter } from "@kognitivedev/ui";
|
|
3
|
+
|
|
4
|
+
export interface SelfHostedKognitiveUIChatBackendOptions extends Omit<KognitiveUIChatBackendOptions, "serverUrl"> {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function createSelfHostedKognitiveChatBackend(options: SelfHostedKognitiveUIChatBackendOptions): ChatBackendAdapter {
|
|
9
|
+
return createKognitiveUIChatBackend({
|
|
10
|
+
serverUrl: options.baseUrl,
|
|
11
|
+
streamPath: options.streamPath,
|
|
12
|
+
threadBasePath: options.threadBasePath,
|
|
13
|
+
headers: options.headers,
|
|
14
|
+
fetch: options.fetch,
|
|
15
|
+
});
|
|
16
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"jsx": "react-jsx",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|