openkbs 0.0.52 → 0.0.55

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 (28) hide show
  1. package/README.md +1496 -192
  2. package/package.json +2 -1
  3. package/src/actions.js +407 -13
  4. package/src/index.js +38 -2
  5. package/src/utils.js +1 -1
  6. package/templates/.openkbs/knowledge/examples/ai-copywriter-agent/app/instructions.txt +44 -9
  7. package/templates/.openkbs/knowledge/examples/ai-copywriter-agent/src/Events/actions.js +43 -42
  8. package/templates/.openkbs/knowledge/examples/ai-copywriter-agent/src/Events/handler.js +14 -8
  9. package/templates/.openkbs/knowledge/examples/ai-copywriter-agent/src/Frontend/contentRender.js +95 -12
  10. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/README.md +64 -0
  11. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/app/instructions.txt +160 -0
  12. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/app/settings.json +7 -0
  13. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/actions.js +258 -0
  14. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/onRequest.js +13 -0
  15. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/onRequest.json +3 -0
  16. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/onResponse.js +13 -0
  17. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Events/onResponse.json +3 -0
  18. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Frontend/contentRender.js +170 -0
  19. package/templates/.openkbs/knowledge/examples/ai-marketing-agent/src/Frontend/contentRender.json +3 -0
  20. package/templates/.openkbs/knowledge/metadata.json +1 -1
  21. package/templates/CLAUDE.md +593 -222
  22. package/templates/app/instructions.txt +13 -1
  23. package/templates/app/settings.json +5 -6
  24. package/templates/src/Events/actions.js +43 -9
  25. package/templates/src/Events/handler.js +24 -25
  26. package/templates/webpack.contentRender.config.js +8 -2
  27. package/version.json +3 -3
  28. package/MODIFY.md +0 -132
@@ -1 +1,13 @@
1
- You are an AI assistant, assist users with their inquiries and tasks efficiently.
1
+ You are an AI assistant, assist users with their inquiries and tasks efficiently.
2
+
3
+ LIST OF AVAILABLE COMMANDS:
4
+ To execute a command, output it as text message and wait for system response.
5
+
6
+ <googleSearch>
7
+ {
8
+ "query": "search query"
9
+ }
10
+ </googleSearch>
11
+ Description: """
12
+ Get results from Google Search API.
13
+ """
@@ -1,14 +1,13 @@
1
1
  {
2
- "chatVendor": "anthropic",
2
+ "chatVendor": "google",
3
3
  "kbDescription": "{{{openkbsAppName}}}",
4
4
  "kbTitle": "{{{openkbsAppName}}}",
5
- "model": "claude-sonnet-4-20250514",
5
+ "model": "gemini-3-pro",
6
6
  "inputTools": [
7
- "imageToText",
8
7
  "speechToText"
9
8
  ],
10
- "embeddingModel": "text-embedding-3-small",
11
- "embeddingDimension": 1536,
12
- "searchEngine": "IndexedDB",
9
+ "embeddingModel": "text-embedding-3-large",
10
+ "embeddingDimension": 3072,
11
+ "searchEngine": "VectorDB",
13
12
  "itemTypes": {}
14
13
  }
@@ -1,16 +1,50 @@
1
- // This boilerplate code is a starting point for development.
2
- export const getActions = () => [
3
- [/\/?googleSearch\("(.*?)"\)/, async (match) => {
4
- const q = match[1];
1
+ export const getActions = (meta, event) => [
2
+ // Google Search with JSON
3
+ // Usage: <googleSearch>{"query": "search terms"}</googleSearch>
4
+ [/<googleSearch>([\s\S]*?)<\/googleSearch>/s, async (match) => {
5
5
  try {
6
- const response = await openkbs.googleSearch(q, {});
7
- const data = response?.map(({ title, link, snippet, pagemap }) => ({
8
- title, link, snippet, image: pagemap?.metatags?.[0]?.["og:image"]
6
+ const data = JSON.parse(match[1].trim());
7
+ const response = await openkbs.googleSearch(data.query);
8
+ const results = response?.map(({ title, link, snippet, pagemap }) => ({
9
+ title,
10
+ link,
11
+ snippet,
12
+ image: pagemap?.metatags?.[0]?.["og:image"]
9
13
  }));
10
- return { data };
14
+ return { data: results, ...meta };
11
15
  } catch (e) {
12
- return { error: e.message };
16
+ return { error: e.message, ...meta };
13
17
  }
14
18
  }],
19
+
20
+ // MCP (Model Context Protocol) Tool Handler
21
+ // Automatically handles all MCP tool calls: <mcp_{server}_{toolName}>{params}</mcp_{server}_{toolName}>
22
+ // Configure MCP servers in settings.json: { "options": { "mcpServers": { "github": {} } } }
23
+ // Add required secrets (e.g., GITHUB_PERSONAL_ACCESS_TOKEN) in KB secrets
24
+ [/<mcp_([a-z0-9-]+)_([a-z0-9_]+)>([\s\S]*?)<\/mcp_\1_\2>/s, async (match) => {
25
+ try {
26
+ const server = match[1];
27
+ const toolName = match[2];
28
+ const args = match[3].trim() ? JSON.parse(match[3].trim()) : {};
29
+
30
+ const result = await openkbs.mcp.callTool(server, toolName, args);
31
+ return {
32
+ type: 'MCP_RESULT',
33
+ server,
34
+ tool: toolName,
35
+ data: result?.content || [],
36
+ ...meta,
37
+ _meta_actions: ['REQUEST_CHAT_MODEL']
38
+ };
39
+ } catch (e) {
40
+ return {
41
+ type: 'MCP_ERROR',
42
+ error: e.message,
43
+ ...meta,
44
+ _meta_actions: ['REQUEST_CHAT_MODEL']
45
+ };
46
+ }
47
+ }],
48
+
15
49
  // add more actions here
16
50
  ];
@@ -1,46 +1,45 @@
1
- import {getActions} from './actions.js';
1
+ import { getActions } from './actions.js';
2
2
 
3
3
  export const backendHandler = async (event) => {
4
- const maxSelfInvokeMessagesCount = 60;
4
+ const meta = { _meta_actions: ["REQUEST_CHAT_MODEL"] };
5
5
  const lastMessage = event.payload.messages[event.payload.messages.length - 1];
6
- const actions = getActions();
6
+ const actions = getActions(meta, event);
7
7
 
8
- const matchingActions = actions.reduce((acc, [regex, action]) => {
9
- const matches = [...lastMessage.content.matchAll(new RegExp(regex, 'g'))];
8
+ const matchingActions = [];
9
+ actions.forEach(([regex, action]) => {
10
+ const matches = [...(lastMessage.content || '').matchAll(new RegExp(regex, 'g'))];
10
11
  matches.forEach(match => {
11
- acc.push(action(match, event));
12
+ matchingActions.push(action(match, event));
12
13
  });
13
- return acc;
14
- }, []);
15
-
16
- // IMPORTANT: Actions returning JOB_COMPLETED or JOB_FAILED stop agent execution and return final result
17
- const isJobFinished = /"JOB_COMPLETED"|"JOB_FAILED"/.test(lastMessage.content);
18
-
19
- const meta = {
20
- _meta_actions:
21
- (
22
- event?.payload?.messages?.length > maxSelfInvokeMessagesCount ||
23
- isJobFinished && lastMessage.role === 'system'
24
- )
25
- ? []
26
- : ["REQUEST_CHAT_MODEL"]
27
- }
14
+ });
28
15
 
29
16
  if (matchingActions.length > 0) {
30
17
  try {
31
18
  const results = await Promise.all(matchingActions);
32
19
 
33
- if (results?.[0]?.data?.some?.(o => o?.type === 'image_url')) {
20
+ // Check if any result needs LLM callback
21
+ const needsChatModel = results.some(r =>
22
+ r?._meta_actions?.includes('REQUEST_CHAT_MODEL')
23
+ );
24
+
25
+ // Handle image data for LLM vision
26
+ if (results.some(r => r?.data?.some?.(item => item?.type === 'image_url'))) {
34
27
  return {
35
28
  ...results[0],
36
- ...meta
29
+ _meta_actions: needsChatModel ? ["REQUEST_CHAT_MODEL"] : []
37
30
  };
38
31
  }
39
32
 
33
+ // Single result - return as is
34
+ if (results.length === 1) {
35
+ return results[0];
36
+ }
37
+
38
+ // Multiple results
40
39
  return {
41
- type: 'RESPONSE',
40
+ type: 'MULTI_RESPONSE',
42
41
  data: results,
43
- ...meta
42
+ _meta_actions: needsChatModel ? ["REQUEST_CHAT_MODEL"] : []
44
43
  };
45
44
  } catch (error) {
46
45
  return {
@@ -22,7 +22,7 @@ module.exports = {
22
22
  loader: 'babel-loader',
23
23
  options: {
24
24
  presets: ['@babel/preset-env', '@babel/preset-react'],
25
- cacheDirectory: true, // Enable caching for faster rebuilds
25
+ cacheDirectory: true,
26
26
  },
27
27
  },
28
28
  },
@@ -42,7 +42,13 @@ module.exports = {
42
42
  },
43
43
  compress: true,
44
44
  port: 38592,
45
- hot: true, // Enable Hot Module Replacement
45
+ hot: true,
46
+ headers: {
47
+ 'Access-Control-Allow-Origin': '*',
48
+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
49
+ 'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
50
+ },
51
+ allowedHosts: 'all',
46
52
  },
47
53
  plugins: [
48
54
  new webpack.HotModuleReplacementPlugin(), // Enable HMR globally
package/version.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.52",
3
- "releaseDate": "2025-08-27",
4
- "releaseNotes": "OpenKBS CLI version 0.0.52"
2
+ "version": "0.0.55",
3
+ "releaseDate": "2025-12-28",
4
+ "releaseNotes": "OpenKBS CLI version 0.0.55"
5
5
  }
package/MODIFY.md DELETED
@@ -1,132 +0,0 @@
1
- #### USER-DEFINED REQUIREMENTS
2
-
3
- Define any additional features, integrations, or behavior modifications
4
-
5
- #### USER-DEFINED REQUIREMENTS END
6
-
7
- # OpenKBS Framework Technical Guide (For AI Coding Agents)
8
-
9
- OpenKBS is claud AI platform designed to build, deploy and integrate AI agents and applications.
10
- This guide provides a brief overview of developing backend and frontend logic for your OpenKBS app/agent.
11
-
12
- ## Project Structure Overview
13
-
14
- A typical OpenKBS project has the following key directories:
15
-
16
- * **`src/`**: Contains your custom source code.
17
- * **`Events/`**: Houses backend LLM event handlers.
18
- * `actions.js`: Example file commonly used for shared backend logic/tools definitions.
19
- * `onRequest.js`: Handles incoming user messages before LLM processing.
20
- * `onRequest.json`: NPM dependencies for `onRequest.js`.
21
- * `onResponse.js`: Handles LLM responses before sending to the user.
22
- * `onResponse.json`: NPM dependencies for `onResponse.js`.
23
- * `onPublicAPIRequest.js`: Handles unauthenticated public API calls.
24
- * `onPublicAPIRequest.json`: Dependencies for `onPublicAPIRequest.js`.
25
- * `onAddMessages.js`: Handles messages added via the `chatAddMessages` API.
26
- * `onAddMessages.json`: Dependencies for `onAddMessages.js`.
27
- * **`Frontend/`**: Contains frontend customization logic.
28
- * `contentRender.js`: Custom UI rendering for chat messages, headers, etc.
29
- * `contentRender.json`: NPM dependencies for `contentRender.js`.
30
- * **`app/`**: Application-level configuration.
31
- * `settings.json`: Core application settings (model, vendor, etc.).
32
- * `instructions.txt`: Instructions for the LLM.
33
- * `icon.png`: Application icon.
34
-
35
- #### Backend Handlers
36
- - Files with names starting with "on" (like onRequest.js) are called handler
37
- - Each handler functions as NodeJS execution entry point executed by the platform upon certain events.
38
- - use ES6, user import, do not use require()
39
-
40
- #### onRequest and onResponse Handlers
41
-
42
- The core of the OpenKBS backend framework revolves around the `onRequest` and `onResponse` Node.js backend event handlers.
43
- These handlers act as middleware, intercepting user messages and messages generated by the LLM.
44
-
45
- - onRequest handler is invoked every time a user sends a message to the chat. It provides an opportunity to process the user's input, extract commands and perform actions based on the user's message.
46
- - onResponse handler is invoked after the LLM generates a response. It allows processing of the LLM's output, execution of commands based on the LLM's message.
47
-
48
- #### NPM Dependencies for Backend Handlers
49
-
50
- 1. If a file imports an NPM dependency and is then imported by a handler, this dependency must be defined in the handler's corresponding json file
51
- 2. Example: If actions.js imports got and onRequest.js imports actions.js, then got must be in onRequest.json
52
-
53
-
54
- ## Backend Dependencies
55
-
56
- To use external NPM packages in your backend event handlers, you must declare them in the corresponding `.json` file.
57
-
58
- **Example: Using https module with an API key**
59
-
60
- 1. **Declare dependencies** in both `src/Events/onRequest.json` and `src/Events/onResponse.json` (as each handler have separate Node.js build):
61
- ```json
62
- {
63
- "dependencies": {
64
- "got": "^11.8.5"
65
- }
66
- }
67
- ```
68
-
69
- 2. **Implement in any JavaScript file** (actions.js is just an example name):
70
-
71
- ```javascript
72
- import got from 'got';
73
- export const getActions = (meta) => {
74
- return [
75
- [/\/?getNews\("(.*)"\)/, async (match) => {
76
- const { body } = await got(`https://newsapi.org/v2/everything?q=${match[1]}&apiKey={{secrets.news_api_key}}`,
77
- { responseType: 'json' });
78
-
79
- return { result: body.articles, ...meta };
80
- }],
81
- // ... other actions
82
- ];
83
- };
84
- ```
85
-
86
- ## Secrets Management
87
- OpenKBS provides a secure way to handle sensitive information using the `{{secrets.your_secret_name}}` syntax.
88
- Never hardcode secrets in the code, if any secrets are provided by the user replace them with placeholders syntax above.
89
- The user will later insert the secrets using the secrets manager
90
-
91
- #### LLM Instructions
92
- `app/instructions.txt`
93
- This file contains the instructions for the agent
94
-
95
- **Example Instructions:**
96
-
97
- ```
98
- You are an AI assistant.
99
-
100
- You can execute the following commands:
101
-
102
- /getNews("query")
103
- Description: """
104
- Get the latest news
105
- """
106
- ```
107
-
108
- #### Important Coding guidelines
109
- - Organize new features across multiple files (like Events/utils.js) rather than adding everything to actions.js
110
- - Similar for Frontend: keep newly implemented React components outside contentRender.js for maintainability.
111
- - Keep in mind onRenderChatMessage is not a React component but simple JS function
112
-
113
-
114
- #### onRenderChatMessage injected functions
115
- These functions are automatically injected by the framework to onRenderChatMessage, providing access to system features
116
- ```
117
- // Where functions are injected
118
- const onRenderChatMessage = async (params) => {
119
- const { APIResponseComponent, theme, setBlockingLoading, setSystemAlert, RequestChatAPI,
120
- kbUserData, generateMsgId, messages, msgIndex } = params;
121
- ...
122
- }
123
- ```
124
-
125
- ```
126
- // Shows toast notifications in top-right corner
127
- setSystemAlert({
128
- msg: 'Payment successful',
129
- type: 'success', //'error'|'success'|'info'
130
- duration: 5000
131
- });
132
- ```