@chatcops/core 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +129 -0
  3. package/package.json +15 -10
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CoderCops
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,129 @@
1
+ # @chatcops/core
2
+
3
+ Core AI provider abstraction, tools, knowledge base, conversation management, analytics, and i18n for ChatCops.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @chatcops/core
9
+ ```
10
+
11
+ ## Providers
12
+
13
+ Unified interface for Claude, OpenAI, and Gemini. Supports streaming (AsyncGenerator) and sync modes.
14
+
15
+ ```typescript
16
+ import { createProvider } from '@chatcops/core';
17
+
18
+ const provider = await createProvider({
19
+ type: 'claude', // 'claude' | 'openai' | 'gemini'
20
+ apiKey: process.env.ANTHROPIC_API_KEY,
21
+ model: 'claude-haiku-4-5-20251001', // optional
22
+ });
23
+
24
+ // Streaming
25
+ for await (const chunk of provider.chat({
26
+ messages: [{ id: '1', role: 'user', content: 'Hello', timestamp: Date.now() }],
27
+ systemPrompt: 'You are a helpful assistant.',
28
+ })) {
29
+ process.stdout.write(chunk);
30
+ }
31
+
32
+ // Sync
33
+ const response = await provider.chatSync({
34
+ messages: [{ id: '1', role: 'user', content: 'Hello', timestamp: Date.now() }],
35
+ systemPrompt: 'You are a helpful assistant.',
36
+ });
37
+ ```
38
+
39
+ Default models: `claude-haiku-4-5-20251001` (Claude), `gpt-4o-mini` (OpenAI), `gemini-2.0-flash` (Gemini).
40
+
41
+ ## Tools
42
+
43
+ Define tools the AI can call. Built-in `LeadCaptureTool` for collecting contact info.
44
+
45
+ ```typescript
46
+ import { LeadCaptureTool } from '@chatcops/core';
47
+
48
+ const leadTool = new LeadCaptureTool((lead) => {
49
+ console.log('Lead captured:', lead.name, lead.email);
50
+ });
51
+ ```
52
+
53
+ Custom tools implement the `ChatTool` interface:
54
+
55
+ ```typescript
56
+ import type { ChatTool, ToolResult } from '@chatcops/core';
57
+
58
+ const myTool: ChatTool = {
59
+ name: 'lookup_order',
60
+ description: 'Look up an order by ID',
61
+ parameters: {
62
+ orderId: { type: 'string', description: 'The order ID' },
63
+ },
64
+ required: ['orderId'],
65
+ async execute(input): Promise<ToolResult> {
66
+ return { success: true, data: { status: 'shipped' } };
67
+ },
68
+ };
69
+ ```
70
+
71
+ ## Knowledge Base
72
+
73
+ Feed context to the AI with text chunks or FAQ pairs.
74
+
75
+ ```typescript
76
+ import { TextKnowledgeSource, FAQKnowledgeSource } from '@chatcops/core';
77
+
78
+ const text = new TextKnowledgeSource([
79
+ 'ChatCops supports Claude, OpenAI, and Gemini.',
80
+ 'The widget is zero-dependency and uses Shadow DOM.',
81
+ ]);
82
+
83
+ const faq = new FAQKnowledgeSource([
84
+ { question: 'What is ChatCops?', answer: 'An embeddable AI chat widget.' },
85
+ { question: 'Is it free?', answer: 'Yes, MIT licensed.' },
86
+ ]);
87
+
88
+ const context = await faq.getContext('is chatcops free');
89
+ ```
90
+
91
+ ## Conversation Management
92
+
93
+ ```typescript
94
+ import { ConversationManager } from '@chatcops/core';
95
+
96
+ const manager = new ConversationManager({ maxMessages: 100 });
97
+ const conversation = await manager.getOrCreate('conv-123');
98
+ await manager.addMessage('conv-123', {
99
+ id: '1', role: 'user', content: 'Hello', timestamp: Date.now(),
100
+ });
101
+ ```
102
+
103
+ Plug in your own store by implementing `ConversationStore`.
104
+
105
+ ## Analytics
106
+
107
+ ```typescript
108
+ import { AnalyticsCollector } from '@chatcops/core';
109
+
110
+ const analytics = new AnalyticsCollector();
111
+ analytics.track('message:sent', { conversationId: 'conv-123' });
112
+ const stats = analytics.getStats();
113
+ ```
114
+
115
+ ## i18n
116
+
117
+ 8 built-in locales: `en`, `es`, `hi`, `fr`, `de`, `ja`, `zh`, `ar`.
118
+
119
+ ```typescript
120
+ import { getLocale, getAvailableLocales } from '@chatcops/core';
121
+
122
+ const strings = getLocale('es');
123
+ console.log(strings.welcomeMessage); // "Hola! Como puedo ayudarte hoy?"
124
+ console.log(getAvailableLocales()); // ['en', 'es', 'hi', 'fr', 'de', 'ja', 'zh', 'ar']
125
+ ```
126
+
127
+ ## License
128
+
129
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatcops/core",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Core AI provider abstraction, tools, and knowledge base for ChatCops",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,13 +14,6 @@
14
14
  "files": [
15
15
  "dist"
16
16
  ],
17
- "scripts": {
18
- "build": "tsc",
19
- "typecheck": "tsc --noEmit",
20
- "test": "vitest run",
21
- "test:watch": "vitest",
22
- "clean": "rm -rf dist *.tsbuildinfo"
23
- },
24
17
  "dependencies": {
25
18
  "@anthropic-ai/sdk": "^0.39.0",
26
19
  "openai": "^4.80.0",
@@ -31,8 +24,20 @@
31
24
  "typescript": "^5.7.0",
32
25
  "vitest": "^3.0.0"
33
26
  },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/codercops/chatcops",
30
+ "directory": "packages/core"
31
+ },
34
32
  "publishConfig": {
35
33
  "access": "public"
36
34
  },
37
- "license": "MIT"
38
- }
35
+ "license": "MIT",
36
+ "scripts": {
37
+ "build": "tsc",
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "vitest run",
40
+ "test:watch": "vitest",
41
+ "clean": "rm -rf dist *.tsbuildinfo"
42
+ }
43
+ }