Skip to content

Commit a8176d9

Browse files
committed
updated notification
1 parent ff99661 commit a8176d9

File tree

20 files changed

+4003
-30
lines changed

20 files changed

+4003
-30
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ dist
33
node_modules
44
.codeboltAgents
55
docs
6-
document
6+
document
7+
.kiro

src/core/Codebolt.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { chatSummary } from '../modules/history';
2424
import codeboltTools from '../modules/mcp';
2525
import cbagent from '../modules/agent';
2626
import cbutils from '../modules/utils';
27+
import { notificationFunctions, type NotificationFunctions } from '../notificationfunctions';
2728
import type { UserMessage } from '../types/libFunctionTypes';
2829

2930
/**
@@ -103,6 +104,7 @@ class Codebolt {
103104
mcp = codeboltTools;
104105
agent = cbagent;
105106
utils = cbutils;
107+
notify = notificationFunctions;
106108

107109
/**
108110
* Sets up a listener for incoming messages with a direct handler function.

src/notificationfunctions/agent.ts

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/**
2+
* Agent Notification Functions
3+
*
4+
* This module provides functions for sending agent-related notifications,
5+
* including subagent task operations and completions.
6+
*/
7+
8+
import {
9+
StartSubagentTaskRequestNotification,
10+
StartSubagentTaskResponseNotification,
11+
SubagentTaskCompletedNotification
12+
} from '../types/notifications/agent';
13+
14+
import {
15+
sendNotification,
16+
generateToolUseId,
17+
validateRequiredFields,
18+
createErrorResponse,
19+
createSuccessResponse
20+
} from './utils';
21+
22+
/**
23+
* Interface for agent notification functions
24+
*/
25+
export interface AgentNotifications {
26+
StartSubagentTaskRequestNotify(parentAgentId: string, subagentId: string, task: string, priority?: string, dependencies?: string[], toolUseId?: string): void;
27+
StartSubagentTaskResponseNotify(content: string | any, isError?: boolean, toolUseId?: string): void;
28+
SubagentTaskCompletedNotify(parentAgentId: string, subagentId: string, taskId: string, result: any, status: string, toolUseId?: string): void;
29+
}
30+
31+
/**
32+
* Sends a request to start a subagent task
33+
*
34+
* @param parentAgentId - The parent agent ID
35+
* @param subagentId - The subagent ID
36+
* @param task - The task description
37+
* @param priority - Optional task priority
38+
* @param dependencies - Optional array of dependencies
39+
* @param toolUseId - Optional custom toolUseId, will be generated if not provided
40+
*
41+
* Requirements: 1.1 - WHEN I call `codebolt.notify.agent.StartSubagentTaskRequestNotify()` THEN the system SHALL send a StartSubagentTaskRequestNotification via WebSocket
42+
*/
43+
export function StartSubagentTaskRequestNotify(
44+
parentAgentId: string,
45+
subagentId: string,
46+
task: string,
47+
priority?: string,
48+
dependencies?: string[],
49+
toolUseId?: string
50+
): void {
51+
// Validate required fields
52+
if (!validateRequiredFields({ parentAgentId, subagentId, task }, ['parentAgentId', 'subagentId', 'task'], 'agent.StartSubagentTaskRequestNotify')) {
53+
return;
54+
}
55+
56+
// Create the notification
57+
const notification: StartSubagentTaskRequestNotification = {
58+
toolUseId: toolUseId || generateToolUseId(),
59+
type: "agentnotify",
60+
action: "startSubagentTaskRequest",
61+
data: {
62+
parentAgentId: parentAgentId,
63+
subagentId: subagentId,
64+
task: task,
65+
priority: priority,
66+
dependencies: dependencies
67+
}
68+
};
69+
70+
// Send the notification
71+
sendNotification(notification, 'agent.StartSubagentTaskRequestNotify');
72+
}
73+
74+
/**
75+
* Sends a response to a subagent task request
76+
*
77+
* @param content - The response content (string or any object)
78+
* @param isError - Whether this is an error response (default: false)
79+
* @param toolUseId - Optional custom toolUseId, will be generated if not provided
80+
*
81+
* Requirements: 1.2 - WHEN I call `codebolt.notify.agent.StartSubagentTaskResponseNotify()` THEN the system SHALL send a StartSubagentTaskResponseNotification via WebSocket
82+
*/
83+
export function StartSubagentTaskResponseNotify(
84+
content: string | any,
85+
isError: boolean = false,
86+
toolUseId?: string
87+
): void {
88+
// Validate content is provided
89+
if (content === null || content === undefined) {
90+
console.error('[NotificationFunctions] Content is required for agent.StartSubagentTaskResponseNotify');
91+
return;
92+
}
93+
94+
// Create the notification
95+
const notification: StartSubagentTaskResponseNotification = {
96+
toolUseId: toolUseId || generateToolUseId(),
97+
type: "agentnotify",
98+
action: "startSubagentTaskResult",
99+
content: content,
100+
isError: isError
101+
};
102+
103+
// Send the notification
104+
sendNotification(notification, 'agent.StartSubagentTaskResponseNotify');
105+
}
106+
107+
/**
108+
* Notifies that a subagent task has been completed
109+
*
110+
* @param parentAgentId - The parent agent ID
111+
* @param subagentId - The subagent ID
112+
* @param taskId - The task ID
113+
* @param result - The task result
114+
* @param status - The task status
115+
* @param toolUseId - Optional custom toolUseId, will be generated if not provided
116+
*
117+
* Requirements: 1.3 - WHEN I call `codebolt.notify.agent.SubagentTaskCompletedNotify()` THEN the system SHALL send a SubagentTaskCompletedNotification via WebSocket
118+
*/
119+
export function SubagentTaskCompletedNotify(
120+
parentAgentId: string,
121+
subagentId: string,
122+
taskId: string,
123+
result: any,
124+
status: string,
125+
toolUseId?: string
126+
): void {
127+
// Validate required fields
128+
if (!validateRequiredFields({ parentAgentId, subagentId, taskId, result, status }, ['parentAgentId', 'subagentId', 'taskId', 'result', 'status'], 'agent.SubagentTaskCompletedNotify')) {
129+
return;
130+
}
131+
132+
// Create the notification
133+
const notification: SubagentTaskCompletedNotification = {
134+
toolUseId: toolUseId || generateToolUseId(),
135+
type: "agentnotify",
136+
action: "subagentTaskCompleted",
137+
data: {
138+
parentAgentId: parentAgentId,
139+
subagentId: subagentId,
140+
taskId: taskId,
141+
result: result,
142+
status: status
143+
}
144+
};
145+
146+
// Send the notification
147+
sendNotification(notification, 'agent.SubagentTaskCompletedNotify');
148+
}
149+
150+
/**
151+
* Agent notification functions object
152+
*/
153+
export const agentNotifications: AgentNotifications = {
154+
StartSubagentTaskRequestNotify,
155+
StartSubagentTaskResponseNotify,
156+
SubagentTaskCompletedNotify
157+
};
158+
159+
// Default export
160+
export default agentNotifications;

src/notificationfunctions/browser.ts

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/**
2+
* Browser Notification Functions
3+
*
4+
* This module provides functions for sending browser-related notifications,
5+
* including web fetch and web search operations.
6+
*/
7+
8+
import {
9+
WebFetchRequestNotification,
10+
WebFetchResponseNotification,
11+
WebSearchRequestNotification,
12+
WebSearchResponseNotification
13+
} from '../types/notifications/browser';
14+
15+
import {
16+
sendNotification,
17+
generateToolUseId,
18+
validateRequiredFields
19+
} from './utils';
20+
21+
/**
22+
* Interface for browser notification functions
23+
*/
24+
export interface BrowserNotifications {
25+
WebFetchRequestNotify(url: string, method?: string, headers?: Record<string, string>, body?: any, timeout?: number, toolUseId?: string): void;
26+
WebFetchResponseNotify(content: string | any, isError?: boolean, toolUseId?: string, data?: WebFetchResponseNotification['data']): void;
27+
WebSearchRequestNotify(query: string, maxResults?: number, searchEngine?: string, filters?: any, toolUseId?: string): void;
28+
WebSearchResponseNotify(content: string | any, isError?: boolean, toolUseId?: string, data?: WebSearchResponseNotification['data']): void;
29+
}
30+
31+
/**
32+
* Sends a web fetch request notification
33+
*
34+
* @param url - The URL to fetch
35+
* @param method - Optional HTTP method
36+
* @param headers - Optional headers object
37+
* @param body - Optional request body
38+
* @param timeout - Optional timeout in milliseconds
39+
* @param toolUseId - Optional custom toolUseId, will be generated if not provided
40+
*
41+
* Requirements: 2.1 - WHEN I call `codebolt.notify.browser.WebFetchRequestNotify()` THEN the system SHALL send a WebFetchRequestNotification via WebSocket
42+
*/
43+
export function WebFetchRequestNotify(
44+
url: string,
45+
method?: string,
46+
headers?: Record<string, string>,
47+
body?: any,
48+
timeout?: number,
49+
toolUseId?: string
50+
): void {
51+
// Validate required fields
52+
if (!validateRequiredFields({ url }, ['url'], 'browser.WebFetchRequestNotify')) {
53+
return;
54+
}
55+
56+
// Create the notification
57+
const notification: WebFetchRequestNotification = {
58+
toolUseId: toolUseId || generateToolUseId(),
59+
type: "browsernotify",
60+
action: "webFetchRequest",
61+
data: {
62+
url: url,
63+
method: method,
64+
headers: headers,
65+
body: body,
66+
timeout: timeout
67+
}
68+
};
69+
70+
// Send the notification
71+
sendNotification(notification, 'browser.WebFetchRequestNotify');
72+
}
73+
74+
/**
75+
* Sends a web fetch response notification
76+
*
77+
* @param content - The response content (string or any object)
78+
* @param isError - Whether this is an error response (default: false)
79+
* @param toolUseId - Optional custom toolUseId, will be generated if not provided
80+
* @param data - Optional response data including status, statusText, headers, and url
81+
*
82+
* Requirements: 2.2 - WHEN I call `codebolt.notify.browser.WebFetchResponseNotify()` THEN the system SHALL send a WebFetchResponseNotification via WebSocket
83+
*/
84+
export function WebFetchResponseNotify(
85+
content: string | any,
86+
isError: boolean = false,
87+
toolUseId?: string,
88+
data?: WebFetchResponseNotification['data']
89+
): void {
90+
// Validate content is provided
91+
if (content === null || content === undefined) {
92+
console.error('[NotificationFunctions] Content is required for browser.WebFetchResponseNotify');
93+
return;
94+
}
95+
96+
// Create the notification
97+
const notification: WebFetchResponseNotification = {
98+
toolUseId: toolUseId || generateToolUseId(),
99+
type: "browsernotify",
100+
action: "webFetchResult",
101+
content: content,
102+
isError: isError,
103+
data: data
104+
};
105+
106+
// Send the notification
107+
sendNotification(notification, 'browser.WebFetchResponseNotify');
108+
}
109+
110+
/**
111+
* Sends a web search request notification
112+
*
113+
* @param query - The search query string
114+
* @param maxResults - Optional maximum number of results
115+
* @param searchEngine - Optional search engine to use
116+
* @param filters - Optional search filters
117+
* @param toolUseId - Optional custom toolUseId, will be generated if not provided
118+
*
119+
* Requirements: 2.3 - WHEN I call `codebolt.notify.browser.WebSearchRequestNotify()` THEN the system SHALL send a WebSearchRequestNotification via WebSocket
120+
*/
121+
export function WebSearchRequestNotify(
122+
query: string,
123+
maxResults?: number,
124+
searchEngine?: string,
125+
filters?: any,
126+
toolUseId?: string
127+
): void {
128+
// Validate required fields
129+
if (!validateRequiredFields({ query }, ['query'], 'browser.WebSearchRequestNotify')) {
130+
return;
131+
}
132+
133+
// Create the notification
134+
const notification: WebSearchRequestNotification = {
135+
toolUseId: toolUseId || generateToolUseId(),
136+
type: "browsernotify",
137+
action: "webSearchRequest",
138+
data: {
139+
query: query,
140+
maxResults: maxResults,
141+
searchEngine: searchEngine,
142+
filters: filters
143+
}
144+
};
145+
146+
// Send the notification
147+
sendNotification(notification, 'browser.WebSearchRequestNotify');
148+
}
149+
150+
/**
151+
* Sends a web search response notification
152+
*
153+
* @param content - The response content (string or any object)
154+
* @param isError - Whether this is an error response (default: false)
155+
* @param toolUseId - Optional custom toolUseId, will be generated if not provided
156+
* @param data - Optional response data including results, totalResults, and searchTime
157+
*
158+
* Requirements: 2.4 - WHEN I call `codebolt.notify.browser.WebSearchResponseNotify()` THEN the system SHALL send a WebSearchResponseNotification via WebSocket
159+
*/
160+
export function WebSearchResponseNotify(
161+
content: string | any,
162+
isError: boolean = false,
163+
toolUseId?: string,
164+
data?: WebSearchResponseNotification['data']
165+
): void {
166+
// Validate content is provided
167+
if (content === null || content === undefined) {
168+
console.error('[NotificationFunctions] Content is required for browser.WebSearchResponseNotify');
169+
return;
170+
}
171+
172+
// Create the notification
173+
const notification: WebSearchResponseNotification = {
174+
toolUseId: toolUseId || generateToolUseId(),
175+
type: "browsernotify",
176+
action: "webSearchResult",
177+
content: content,
178+
isError: isError,
179+
data: data
180+
};
181+
182+
// Send the notification
183+
sendNotification(notification, 'browser.WebSearchResponseNotify');
184+
}
185+
186+
/**
187+
* Browser notification functions object
188+
*/
189+
export const browserNotifications: BrowserNotifications = {
190+
WebFetchRequestNotify,
191+
WebFetchResponseNotify,
192+
WebSearchRequestNotify,
193+
WebSearchResponseNotify
194+
};
195+
196+
// Default export
197+
export default browserNotifications;

0 commit comments

Comments
 (0)