codeblog-app 2.1.0 → 2.1.1
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/package.json +8 -71
- package/drizzle/0000_init.sql +0 -34
- package/drizzle/meta/_journal.json +0 -13
- package/drizzle.config.ts +0 -10
- package/src/ai/__tests__/chat.test.ts +0 -110
- package/src/ai/__tests__/provider.test.ts +0 -184
- package/src/ai/__tests__/tools.test.ts +0 -90
- package/src/ai/chat.ts +0 -169
- package/src/ai/configure.ts +0 -134
- package/src/ai/provider.ts +0 -238
- package/src/ai/tools.ts +0 -336
- package/src/auth/index.ts +0 -47
- package/src/auth/oauth.ts +0 -94
- package/src/cli/__tests__/commands.test.ts +0 -225
- package/src/cli/cmd/agent.ts +0 -102
- package/src/cli/cmd/chat.ts +0 -190
- package/src/cli/cmd/comment.ts +0 -70
- package/src/cli/cmd/config.ts +0 -153
- package/src/cli/cmd/feed.ts +0 -57
- package/src/cli/cmd/forum.ts +0 -123
- package/src/cli/cmd/login.ts +0 -45
- package/src/cli/cmd/logout.ts +0 -12
- package/src/cli/cmd/me.ts +0 -202
- package/src/cli/cmd/post.ts +0 -29
- package/src/cli/cmd/publish.ts +0 -70
- package/src/cli/cmd/scan.ts +0 -80
- package/src/cli/cmd/search.ts +0 -40
- package/src/cli/cmd/setup.ts +0 -273
- package/src/cli/cmd/tui.ts +0 -20
- package/src/cli/cmd/update.ts +0 -78
- package/src/cli/cmd/vote.ts +0 -50
- package/src/cli/cmd/whoami.ts +0 -21
- package/src/cli/ui.ts +0 -195
- package/src/config/index.ts +0 -54
- package/src/flag/index.ts +0 -23
- package/src/global/index.ts +0 -38
- package/src/id/index.ts +0 -20
- package/src/index.ts +0 -197
- package/src/mcp/__tests__/client.test.ts +0 -149
- package/src/mcp/__tests__/e2e.ts +0 -327
- package/src/mcp/__tests__/integration.ts +0 -148
- package/src/mcp/client.ts +0 -148
- package/src/server/index.ts +0 -48
- package/src/storage/chat.ts +0 -92
- package/src/storage/db.ts +0 -85
- package/src/storage/schema.sql.ts +0 -39
- package/src/storage/schema.ts +0 -1
- package/src/tui/app.tsx +0 -163
- package/src/tui/commands.ts +0 -187
- package/src/tui/context/exit.tsx +0 -15
- package/src/tui/context/helper.tsx +0 -25
- package/src/tui/context/route.tsx +0 -24
- package/src/tui/context/theme.tsx +0 -470
- package/src/tui/routes/home.tsx +0 -508
- package/src/tui/routes/model.tsx +0 -209
- package/src/tui/routes/notifications.tsx +0 -85
- package/src/tui/routes/post.tsx +0 -108
- package/src/tui/routes/search.tsx +0 -104
- package/src/tui/routes/setup.tsx +0 -255
- package/src/tui/routes/trending.tsx +0 -107
- package/src/util/__tests__/context.test.ts +0 -31
- package/src/util/__tests__/lazy.test.ts +0 -37
- package/src/util/context.ts +0 -23
- package/src/util/error.ts +0 -46
- package/src/util/lazy.ts +0 -18
- package/src/util/log.ts +0 -142
- package/tsconfig.json +0 -11
package/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/package.json",
|
|
3
2
|
"name": "codeblog-app",
|
|
4
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
5
4
|
"description": "CLI client for CodeBlog — the forum where AI writes the posts",
|
|
6
|
-
"type": "module",
|
|
7
5
|
"license": "MIT",
|
|
8
6
|
"author": "CodeBlog-ai",
|
|
9
7
|
"homepage": "https://github.com/CodeBlog-ai/codeblog-app",
|
|
@@ -11,75 +9,14 @@
|
|
|
11
9
|
"type": "git",
|
|
12
10
|
"url": "https://github.com/CodeBlog-ai/codeblog-app"
|
|
13
11
|
},
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/CodeBlog-ai/codeblog-app/issues"
|
|
16
|
-
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"codeblog",
|
|
19
|
-
"cli",
|
|
20
|
-
"ai",
|
|
21
|
-
"coding",
|
|
22
|
-
"forum",
|
|
23
|
-
"ide",
|
|
24
|
-
"scanner",
|
|
25
|
-
"claude",
|
|
26
|
-
"cursor",
|
|
27
|
-
"windsurf",
|
|
28
|
-
"codex",
|
|
29
|
-
"copilot"
|
|
30
|
-
],
|
|
31
|
-
"scripts": {
|
|
32
|
-
"typecheck": "tsc --noEmit",
|
|
33
|
-
"test": "bun test --timeout 30000",
|
|
34
|
-
"dev": "bun run --watch ./src/index.ts"
|
|
35
|
-
},
|
|
36
12
|
"bin": {
|
|
37
|
-
"codeblog": "
|
|
38
|
-
},
|
|
39
|
-
"files": [
|
|
40
|
-
"bin",
|
|
41
|
-
"src",
|
|
42
|
-
"drizzle",
|
|
43
|
-
"drizzle.config.ts",
|
|
44
|
-
"tsconfig.json",
|
|
45
|
-
"package.json",
|
|
46
|
-
"README.md"
|
|
47
|
-
],
|
|
48
|
-
"exports": {
|
|
49
|
-
"./*": "./src/*.ts"
|
|
50
|
-
},
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"@tsconfig/bun": "1.0.9",
|
|
53
|
-
"@types/bun": "1.3.9",
|
|
54
|
-
"@types/yargs": "17.0.33",
|
|
55
|
-
"drizzle-kit": "1.0.0-beta.12-a5629fb",
|
|
56
|
-
"typescript": "5.8.2"
|
|
13
|
+
"codeblog": "bin/codeblog"
|
|
57
14
|
},
|
|
58
15
|
"optionalDependencies": {
|
|
59
|
-
"codeblog-app-darwin-arm64": "2.1.
|
|
60
|
-
"codeblog-app-darwin-x64": "2.1.
|
|
61
|
-
"codeblog-app-linux-arm64": "2.1.
|
|
62
|
-
"codeblog-app-linux-x64": "2.1.
|
|
63
|
-
"codeblog-app-windows-x64": "2.1.
|
|
64
|
-
},
|
|
65
|
-
"dependencies": {
|
|
66
|
-
"@ai-sdk/anthropic": "^3.0.44",
|
|
67
|
-
"@ai-sdk/google": "^3.0.29",
|
|
68
|
-
"@ai-sdk/openai": "^3.0.29",
|
|
69
|
-
"@ai-sdk/openai-compatible": "^2.0.30",
|
|
70
|
-
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
71
|
-
"@opentui/core": "^0.1.79",
|
|
72
|
-
"@opentui/solid": "^0.1.79",
|
|
73
|
-
"ai": "^6.0.86",
|
|
74
|
-
"codeblog-mcp": "^1.7.0",
|
|
75
|
-
"drizzle-orm": "1.0.0-beta.12-a5629fb",
|
|
76
|
-
"fuzzysort": "^3.1.0",
|
|
77
|
-
"hono": "4.10.7",
|
|
78
|
-
"open": "10.1.2",
|
|
79
|
-
"remeda": "^2.33.6",
|
|
80
|
-
"solid-js": "^1.9.11",
|
|
81
|
-
"xdg-basedir": "5.1.0",
|
|
82
|
-
"yargs": "18.0.0",
|
|
83
|
-
"zod": "4.1.8"
|
|
16
|
+
"codeblog-app-darwin-arm64": "2.1.1",
|
|
17
|
+
"codeblog-app-darwin-x64": "2.1.1",
|
|
18
|
+
"codeblog-app-linux-arm64": "2.1.1",
|
|
19
|
+
"codeblog-app-linux-x64": "2.1.1",
|
|
20
|
+
"codeblog-app-windows-x64": "2.1.1"
|
|
84
21
|
}
|
|
85
|
-
}
|
|
22
|
+
}
|
package/drizzle/0000_init.sql
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
CREATE TABLE IF NOT EXISTS `published_sessions` (
|
|
2
|
-
`id` text PRIMARY KEY NOT NULL,
|
|
3
|
-
`session_id` text NOT NULL,
|
|
4
|
-
`source` text NOT NULL,
|
|
5
|
-
`post_id` text NOT NULL,
|
|
6
|
-
`file_path` text NOT NULL,
|
|
7
|
-
`published_at` integer DEFAULT (unixepoch()) NOT NULL
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
CREATE TABLE IF NOT EXISTS `cached_posts` (
|
|
11
|
-
`id` text PRIMARY KEY NOT NULL,
|
|
12
|
-
`title` text NOT NULL,
|
|
13
|
-
`content` text NOT NULL,
|
|
14
|
-
`summary` text,
|
|
15
|
-
`tags` text DEFAULT '[]' NOT NULL,
|
|
16
|
-
`upvotes` integer DEFAULT 0 NOT NULL,
|
|
17
|
-
`downvotes` integer DEFAULT 0 NOT NULL,
|
|
18
|
-
`author_name` text NOT NULL,
|
|
19
|
-
`fetched_at` integer DEFAULT (unixepoch()) NOT NULL
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
CREATE TABLE IF NOT EXISTS `notifications_cache` (
|
|
23
|
-
`id` text PRIMARY KEY NOT NULL,
|
|
24
|
-
`type` text NOT NULL,
|
|
25
|
-
`message` text NOT NULL,
|
|
26
|
-
`read` integer DEFAULT 0 NOT NULL,
|
|
27
|
-
`post_id` text,
|
|
28
|
-
`created_at` integer DEFAULT (unixepoch()) NOT NULL
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
CREATE INDEX IF NOT EXISTS `idx_published_sessions_source` ON `published_sessions` (`source`);
|
|
32
|
-
CREATE INDEX IF NOT EXISTS `idx_published_sessions_session_id` ON `published_sessions` (`session_id`);
|
|
33
|
-
CREATE INDEX IF NOT EXISTS `idx_cached_posts_fetched_at` ON `cached_posts` (`fetched_at`);
|
|
34
|
-
CREATE INDEX IF NOT EXISTS `idx_notifications_read` ON `notifications_cache` (`read`);
|
package/drizzle.config.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, mock, beforeEach } from "bun:test"
|
|
2
|
-
|
|
3
|
-
// Mock the MCP bridge for chat tests
|
|
4
|
-
const mockCallToolJSON = mock((name: string, args: Record<string, unknown>) =>
|
|
5
|
-
Promise.resolve({ ok: true, tool: name }),
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
mock.module("../../mcp/client", () => ({
|
|
9
|
-
McpBridge: {
|
|
10
|
-
callTool: mock((name: string, args: Record<string, unknown>) =>
|
|
11
|
-
Promise.resolve(JSON.stringify({ ok: true, tool: name })),
|
|
12
|
-
),
|
|
13
|
-
callToolJSON: mockCallToolJSON,
|
|
14
|
-
disconnect: mock(() => Promise.resolve()),
|
|
15
|
-
},
|
|
16
|
-
}))
|
|
17
|
-
|
|
18
|
-
// Each call to streamText must return a FRESH async generator
|
|
19
|
-
function makeStreamResult() {
|
|
20
|
-
return {
|
|
21
|
-
fullStream: (async function* () {
|
|
22
|
-
yield { type: "text-delta", textDelta: "Hello " }
|
|
23
|
-
yield { type: "text-delta", textDelta: "World" }
|
|
24
|
-
})(),
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
mock.module("ai", () => ({
|
|
29
|
-
streamText: () => makeStreamResult(),
|
|
30
|
-
ModelMessage: class {},
|
|
31
|
-
tool: (config: any) => config,
|
|
32
|
-
}))
|
|
33
|
-
|
|
34
|
-
mock.module("../provider", () => ({
|
|
35
|
-
AIProvider: {
|
|
36
|
-
getModel: mock(() => Promise.resolve({ id: "test-model" })),
|
|
37
|
-
DEFAULT_MODEL: "test-model",
|
|
38
|
-
},
|
|
39
|
-
}))
|
|
40
|
-
|
|
41
|
-
const { AIChat } = await import("../chat")
|
|
42
|
-
|
|
43
|
-
describe("AIChat", () => {
|
|
44
|
-
beforeEach(() => {
|
|
45
|
-
mockCallToolJSON.mockClear()
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
// ---------------------------------------------------------------------------
|
|
49
|
-
// Message interface
|
|
50
|
-
// ---------------------------------------------------------------------------
|
|
51
|
-
|
|
52
|
-
test("Message type accepts user, assistant, system roles", () => {
|
|
53
|
-
const messages: AIChat.Message[] = [
|
|
54
|
-
{ role: "user", content: "hello" },
|
|
55
|
-
{ role: "assistant", content: "hi" },
|
|
56
|
-
{ role: "system", content: "you are a bot" },
|
|
57
|
-
]
|
|
58
|
-
expect(messages).toHaveLength(3)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// ---------------------------------------------------------------------------
|
|
62
|
-
// stream()
|
|
63
|
-
// ---------------------------------------------------------------------------
|
|
64
|
-
|
|
65
|
-
test("stream calls onToken for each text delta", async () => {
|
|
66
|
-
const tokens: string[] = []
|
|
67
|
-
const result = await AIChat.stream(
|
|
68
|
-
[{ role: "user", content: "test" }],
|
|
69
|
-
{
|
|
70
|
-
onToken: (t) => tokens.push(t),
|
|
71
|
-
onFinish: () => {},
|
|
72
|
-
},
|
|
73
|
-
)
|
|
74
|
-
expect(tokens).toEqual(["Hello ", "World"])
|
|
75
|
-
expect(result).toBe("Hello World")
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test("stream calls onFinish with full text", async () => {
|
|
79
|
-
let finished = ""
|
|
80
|
-
await AIChat.stream(
|
|
81
|
-
[{ role: "user", content: "test" }],
|
|
82
|
-
{
|
|
83
|
-
onFinish: (text) => { finished = text },
|
|
84
|
-
},
|
|
85
|
-
)
|
|
86
|
-
expect(finished).toBe("Hello World")
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
test("stream filters out system messages from history", async () => {
|
|
90
|
-
await AIChat.stream(
|
|
91
|
-
[
|
|
92
|
-
{ role: "system", content: "ignored" },
|
|
93
|
-
{ role: "user", content: "hello" },
|
|
94
|
-
{ role: "assistant", content: "hi" },
|
|
95
|
-
{ role: "user", content: "bye" },
|
|
96
|
-
],
|
|
97
|
-
{ onFinish: () => {} },
|
|
98
|
-
)
|
|
99
|
-
// Should not throw — system messages are filtered
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
// generate()
|
|
104
|
-
// ---------------------------------------------------------------------------
|
|
105
|
-
|
|
106
|
-
test("generate returns the full response text", async () => {
|
|
107
|
-
const result = await AIChat.generate("test prompt")
|
|
108
|
-
expect(result).toBe("Hello World")
|
|
109
|
-
})
|
|
110
|
-
})
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, beforeEach, afterEach } from "bun:test"
|
|
2
|
-
import { AIProvider } from "../provider"
|
|
3
|
-
|
|
4
|
-
describe("AIProvider", () => {
|
|
5
|
-
const originalEnv = { ...process.env }
|
|
6
|
-
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
// Clean up env vars before each test
|
|
9
|
-
delete process.env.ANTHROPIC_API_KEY
|
|
10
|
-
delete process.env.ANTHROPIC_AUTH_TOKEN
|
|
11
|
-
delete process.env.OPENAI_API_KEY
|
|
12
|
-
delete process.env.GOOGLE_GENERATIVE_AI_API_KEY
|
|
13
|
-
delete process.env.GOOGLE_API_KEY
|
|
14
|
-
delete process.env.OPENAI_COMPATIBLE_API_KEY
|
|
15
|
-
delete process.env.ANTHROPIC_BASE_URL
|
|
16
|
-
delete process.env.OPENAI_BASE_URL
|
|
17
|
-
delete process.env.OPENAI_API_BASE
|
|
18
|
-
delete process.env.GOOGLE_API_BASE_URL
|
|
19
|
-
delete process.env.OPENAI_COMPATIBLE_BASE_URL
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
// Restore original env
|
|
24
|
-
for (const key of Object.keys(process.env)) {
|
|
25
|
-
if (!(key in originalEnv)) delete process.env[key]
|
|
26
|
-
}
|
|
27
|
-
for (const [key, val] of Object.entries(originalEnv)) {
|
|
28
|
-
if (val !== undefined) process.env[key] = val
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
// BUILTIN_MODELS
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
|
|
36
|
-
test("BUILTIN_MODELS has 7 models", () => {
|
|
37
|
-
expect(Object.keys(AIProvider.BUILTIN_MODELS)).toHaveLength(7)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
test("each model has required fields", () => {
|
|
41
|
-
for (const [id, model] of Object.entries(AIProvider.BUILTIN_MODELS)) {
|
|
42
|
-
expect(model.id).toBe(id)
|
|
43
|
-
expect(model.providerID).toBeTruthy()
|
|
44
|
-
expect(model.name).toBeTruthy()
|
|
45
|
-
expect(model.contextWindow).toBeGreaterThan(0)
|
|
46
|
-
expect(model.outputTokens).toBeGreaterThan(0)
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test("DEFAULT_MODEL is a valid builtin model", () => {
|
|
51
|
-
expect(AIProvider.BUILTIN_MODELS[AIProvider.DEFAULT_MODEL]).toBeDefined()
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
test("all providers are covered: anthropic, openai, google", () => {
|
|
55
|
-
const providerIDs = new Set(Object.values(AIProvider.BUILTIN_MODELS).map((m) => m.providerID))
|
|
56
|
-
expect(providerIDs.has("anthropic")).toBe(true)
|
|
57
|
-
expect(providerIDs.has("openai")).toBe(true)
|
|
58
|
-
expect(providerIDs.has("google")).toBe(true)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// ---------------------------------------------------------------------------
|
|
62
|
-
// getApiKey
|
|
63
|
-
// ---------------------------------------------------------------------------
|
|
64
|
-
|
|
65
|
-
test("getApiKey returns env var when set", async () => {
|
|
66
|
-
process.env.ANTHROPIC_API_KEY = "sk-ant-test123"
|
|
67
|
-
const key = await AIProvider.getApiKey("anthropic")
|
|
68
|
-
expect(key).toBe("sk-ant-test123")
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test("getApiKey checks secondary env var", async () => {
|
|
72
|
-
process.env.ANTHROPIC_AUTH_TOKEN = "token-test"
|
|
73
|
-
const key = await AIProvider.getApiKey("anthropic")
|
|
74
|
-
expect(key).toBe("token-test")
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
test("getApiKey returns undefined when no key set", async () => {
|
|
78
|
-
const key = await AIProvider.getApiKey("anthropic")
|
|
79
|
-
// May return undefined or a config value — just check it doesn't crash
|
|
80
|
-
expect(key === undefined || typeof key === "string").toBe(true)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
test("getApiKey works for openai", async () => {
|
|
84
|
-
process.env.OPENAI_API_KEY = "sk-openai-test"
|
|
85
|
-
const key = await AIProvider.getApiKey("openai")
|
|
86
|
-
expect(key).toBe("sk-openai-test")
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
test("getApiKey works for google", async () => {
|
|
90
|
-
process.env.GOOGLE_GENERATIVE_AI_API_KEY = "aiza-test"
|
|
91
|
-
const key = await AIProvider.getApiKey("google")
|
|
92
|
-
expect(key).toBe("aiza-test")
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
// ---------------------------------------------------------------------------
|
|
96
|
-
// getBaseUrl
|
|
97
|
-
// ---------------------------------------------------------------------------
|
|
98
|
-
|
|
99
|
-
test("getBaseUrl returns env var when set", async () => {
|
|
100
|
-
process.env.ANTHROPIC_BASE_URL = "https://custom.api.com"
|
|
101
|
-
const url = await AIProvider.getBaseUrl("anthropic")
|
|
102
|
-
expect(url).toBe("https://custom.api.com")
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
test("getBaseUrl returns undefined when no env var set", async () => {
|
|
106
|
-
const url = await AIProvider.getBaseUrl("anthropic")
|
|
107
|
-
expect(url === undefined || typeof url === "string").toBe(true)
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
// ---------------------------------------------------------------------------
|
|
111
|
-
// hasAnyKey
|
|
112
|
-
// ---------------------------------------------------------------------------
|
|
113
|
-
|
|
114
|
-
test("hasAnyKey returns true when any key is set", async () => {
|
|
115
|
-
process.env.OPENAI_API_KEY = "sk-test"
|
|
116
|
-
const has = await AIProvider.hasAnyKey()
|
|
117
|
-
expect(has).toBe(true)
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
// ---------------------------------------------------------------------------
|
|
121
|
-
// parseModel
|
|
122
|
-
// ---------------------------------------------------------------------------
|
|
123
|
-
|
|
124
|
-
test("parseModel splits provider/model", () => {
|
|
125
|
-
const result = AIProvider.parseModel("anthropic/claude-sonnet-4-20250514")
|
|
126
|
-
expect(result.providerID).toBe("anthropic")
|
|
127
|
-
expect(result.modelID).toBe("claude-sonnet-4-20250514")
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
test("parseModel handles nested slashes", () => {
|
|
131
|
-
const result = AIProvider.parseModel("openai/gpt-4o/latest")
|
|
132
|
-
expect(result.providerID).toBe("openai")
|
|
133
|
-
expect(result.modelID).toBe("gpt-4o/latest")
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
test("parseModel handles no slash", () => {
|
|
137
|
-
const result = AIProvider.parseModel("gpt-4o")
|
|
138
|
-
expect(result.providerID).toBe("gpt-4o")
|
|
139
|
-
expect(result.modelID).toBe("")
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
// ---------------------------------------------------------------------------
|
|
143
|
-
// available
|
|
144
|
-
// ---------------------------------------------------------------------------
|
|
145
|
-
|
|
146
|
-
test("available returns all builtin models with hasKey status", async () => {
|
|
147
|
-
const models = await AIProvider.available()
|
|
148
|
-
expect(models).toHaveLength(7)
|
|
149
|
-
for (const entry of models) {
|
|
150
|
-
expect(entry.model).toBeDefined()
|
|
151
|
-
expect(typeof entry.hasKey).toBe("boolean")
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
// ---------------------------------------------------------------------------
|
|
156
|
-
// getModel
|
|
157
|
-
// ---------------------------------------------------------------------------
|
|
158
|
-
|
|
159
|
-
test("getModel throws when no API key for builtin model", async () => {
|
|
160
|
-
expect(AIProvider.getModel("gpt-4o")).rejects.toThrow("No API key for openai")
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
test("getModel falls back to provider with base_url for unknown model", async () => {
|
|
164
|
-
// When a provider with base_url is configured, unknown models get sent there
|
|
165
|
-
// instead of throwing. This test verifies the fallback behavior.
|
|
166
|
-
// If no provider has a base_url, it would throw.
|
|
167
|
-
const result = AIProvider.getModel("nonexistent-model-xyz")
|
|
168
|
-
// Either resolves (provider with base_url available) or rejects
|
|
169
|
-
const settled = await Promise.allSettled([result])
|
|
170
|
-
expect(settled[0]!.status).toBeDefined()
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
// ---------------------------------------------------------------------------
|
|
174
|
-
// listProviders
|
|
175
|
-
// ---------------------------------------------------------------------------
|
|
176
|
-
|
|
177
|
-
test("listProviders returns provider info", async () => {
|
|
178
|
-
process.env.OPENAI_API_KEY = "sk-test"
|
|
179
|
-
const providers = await AIProvider.listProviders()
|
|
180
|
-
expect(providers.openai).toBeDefined()
|
|
181
|
-
expect(providers.openai!.hasKey).toBe(true)
|
|
182
|
-
expect(providers.openai!.models.length).toBeGreaterThan(0)
|
|
183
|
-
})
|
|
184
|
-
})
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from "bun:test"
|
|
2
|
-
import { chatTools, TOOL_LABELS } from "../tools"
|
|
3
|
-
|
|
4
|
-
describe("AI Tools", () => {
|
|
5
|
-
// ---------------------------------------------------------------------------
|
|
6
|
-
// Structural tests — verify all tools are properly exported and configured
|
|
7
|
-
// ---------------------------------------------------------------------------
|
|
8
|
-
|
|
9
|
-
const expectedTools = [
|
|
10
|
-
"scan_sessions", "read_session", "analyze_session",
|
|
11
|
-
"post_to_codeblog", "auto_post", "weekly_digest",
|
|
12
|
-
"browse_posts", "search_posts", "read_post",
|
|
13
|
-
"comment_on_post", "vote_on_post", "edit_post", "delete_post", "bookmark_post",
|
|
14
|
-
"browse_by_tag", "trending_topics", "explore_and_engage", "join_debate",
|
|
15
|
-
"my_notifications",
|
|
16
|
-
"manage_agents", "my_posts", "my_dashboard", "follow_user",
|
|
17
|
-
"codeblog_setup", "codeblog_status",
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
test("exports all 25 tools", () => {
|
|
21
|
-
const toolNames = Object.keys(chatTools)
|
|
22
|
-
expect(toolNames).toHaveLength(25)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
test("each expected tool is present in chatTools", () => {
|
|
26
|
-
for (const name of expectedTools) {
|
|
27
|
-
expect(chatTools).toHaveProperty(name)
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
test("each tool has parameters and execute", () => {
|
|
32
|
-
for (const [name, tool] of Object.entries(chatTools)) {
|
|
33
|
-
const t = tool as any
|
|
34
|
-
expect(t.parameters).toBeDefined()
|
|
35
|
-
expect(t.execute).toBeDefined()
|
|
36
|
-
expect(typeof t.execute).toBe("function")
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
test("each tool has a description", () => {
|
|
41
|
-
for (const [name, tool] of Object.entries(chatTools)) {
|
|
42
|
-
const t = tool as any
|
|
43
|
-
expect(t.description).toBeDefined()
|
|
44
|
-
expect(typeof t.description).toBe("string")
|
|
45
|
-
expect(t.description.length).toBeGreaterThan(10)
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// TOOL_LABELS tests
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
test("TOOL_LABELS has an entry for every chatTool", () => {
|
|
54
|
-
for (const name of Object.keys(chatTools)) {
|
|
55
|
-
expect(TOOL_LABELS).toHaveProperty(name)
|
|
56
|
-
expect(typeof TOOL_LABELS[name]).toBe("string")
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
test("TOOL_LABELS values are non-empty strings", () => {
|
|
61
|
-
for (const [key, label] of Object.entries(TOOL_LABELS)) {
|
|
62
|
-
expect(label.length).toBeGreaterThan(0)
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
// ---------------------------------------------------------------------------
|
|
67
|
-
// Parameter schema spot-checks
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
|
|
70
|
-
test("scan_sessions has optional limit and source parameters", () => {
|
|
71
|
-
const params = (chatTools.scan_sessions as any).parameters
|
|
72
|
-
// Zod schema should exist
|
|
73
|
-
expect(params).toBeDefined()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
test("post_to_codeblog requires title, content, source_session", () => {
|
|
77
|
-
const params = (chatTools.post_to_codeblog as any).parameters
|
|
78
|
-
expect(params).toBeDefined()
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
test("vote_on_post requires post_id and value", () => {
|
|
82
|
-
const params = (chatTools.vote_on_post as any).parameters
|
|
83
|
-
expect(params).toBeDefined()
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
test("delete_post requires post_id and confirm", () => {
|
|
87
|
-
const params = (chatTools.delete_post as any).parameters
|
|
88
|
-
expect(params).toBeDefined()
|
|
89
|
-
})
|
|
90
|
-
})
|