@xalia/agent 0.6.10 → 0.6.11
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 +5 -2
- package/.env.development +0 -6
- package/.env.test +0 -7
- package/.prettierrc.json +0 -11
- package/context_system.md +0 -498
- package/eslint.config.mjs +0 -38
- package/scripts/chat_server +0 -8
- package/scripts/git_message +0 -31
- package/scripts/git_wip +0 -21
- package/scripts/pr_message +0 -18
- package/scripts/pr_review +0 -16
- package/scripts/setup_chat +0 -90
- package/scripts/shutdown_chat_server +0 -42
- package/scripts/start_chat_server +0 -24
- package/scripts/sudomcp_import +0 -23
- package/scripts/test_chat +0 -327
- package/src/agent/agent.ts +0 -699
- package/src/agent/agentUtils.ts +0 -286
- package/src/agent/compressingContextManager.ts +0 -129
- package/src/agent/context.ts +0 -265
- package/src/agent/contextWithWorkspace.ts +0 -162
- package/src/agent/documentSummarizer.ts +0 -157
- package/src/agent/dummyLLM.ts +0 -130
- package/src/agent/iAgentEventHandler.ts +0 -64
- package/src/agent/imageGenLLM.ts +0 -101
- package/src/agent/imageGenerator.ts +0 -45
- package/src/agent/iplatform.ts +0 -18
- package/src/agent/llm.ts +0 -74
- package/src/agent/mcpServerManager.ts +0 -541
- package/src/agent/nullAgentEventHandler.ts +0 -26
- package/src/agent/nullPlatform.ts +0 -13
- package/src/agent/openAI.ts +0 -123
- package/src/agent/openAILLM.ts +0 -99
- package/src/agent/openAILLMStreaming.ts +0 -648
- package/src/agent/promptProvider.ts +0 -87
- package/src/agent/repeatLLM.ts +0 -62
- package/src/agent/sudoMcpServerManager.ts +0 -361
- package/src/agent/test_data/harrypotter.txt +0 -6065
- package/src/agent/tokenAuth.ts +0 -50
- package/src/agent/tokenCounter.test.ts +0 -243
- package/src/agent/tokenCounter.ts +0 -483
- package/src/agent/toolSettings.ts +0 -24
- package/src/agent/tools/calculatorTool.ts +0 -50
- package/src/agent/tools/contentExtractors/htmlToText.ts +0 -61
- package/src/agent/tools/contentExtractors/pdfToText.ts +0 -60
- package/src/agent/tools/datetimeTool.ts +0 -41
- package/src/agent/tools/fileManager/fileManagerTool.ts +0 -199
- package/src/agent/tools/fileManager/index.ts +0 -50
- package/src/agent/tools/fileManager/memoryFileManager.ts +0 -120
- package/src/agent/tools/fileManager/mimeTypes.ts +0 -60
- package/src/agent/tools/fileManager/prompt.ts +0 -38
- package/src/agent/tools/fileManager/types.ts +0 -189
- package/src/agent/tools/index.ts +0 -49
- package/src/agent/tools/openUrlTool.ts +0 -62
- package/src/agent/tools/renderTool.ts +0 -92
- package/src/agent/tools/utils.ts +0 -74
- package/src/agent/tools/webSearch.ts +0 -138
- package/src/agent/tools/webSearchTool.ts +0 -44
- package/src/chat/client/chatClient.ts +0 -967
- package/src/chat/client/connection.test.ts +0 -241
- package/src/chat/client/connection.ts +0 -286
- package/src/chat/client/constants.ts +0 -1
- package/src/chat/client/index.ts +0 -21
- package/src/chat/client/interfaces.ts +0 -34
- package/src/chat/client/sessionClient.ts +0 -574
- package/src/chat/client/sessionFiles.ts +0 -142
- package/src/chat/client/teamManager.ts +0 -29
- package/src/chat/constants.ts +0 -6
- package/src/chat/data/apiKeyManager.ts +0 -76
- package/src/chat/data/dataModels.ts +0 -107
- package/src/chat/data/database.ts +0 -997
- package/src/chat/data/dbMcpServerConfigs.ts +0 -59
- package/src/chat/data/dbSessionFiles.ts +0 -107
- package/src/chat/data/dbSessionMessages.ts +0 -102
- package/src/chat/protocol/connectionMessages.ts +0 -49
- package/src/chat/protocol/constants.ts +0 -55
- package/src/chat/protocol/errors.ts +0 -16
- package/src/chat/protocol/messages.ts +0 -899
- package/src/chat/server/README.md +0 -127
- package/src/chat/server/chatContextManager.ts +0 -660
- package/src/chat/server/connectionManager.test.ts +0 -246
- package/src/chat/server/connectionManager.ts +0 -506
- package/src/chat/server/conversation.ts +0 -319
- package/src/chat/server/errorUtils.ts +0 -28
- package/src/chat/server/imageGeneratorTools.ts +0 -179
- package/src/chat/server/openAIRouterLLM.ts +0 -168
- package/src/chat/server/openSession.ts +0 -1945
- package/src/chat/server/openSessionMessageSender.ts +0 -4
- package/src/chat/server/promptRefiner.ts +0 -106
- package/src/chat/server/server.ts +0 -178
- package/src/chat/server/sessionFileManager.ts +0 -151
- package/src/chat/server/sessionRegistry.test.ts +0 -137
- package/src/chat/server/sessionRegistry.ts +0 -1553
- package/src/chat/server/test-utils/mockFactories.ts +0 -422
- package/src/chat/server/titleGenerator.test.ts +0 -103
- package/src/chat/server/titleGenerator.ts +0 -143
- package/src/chat/server/tools.ts +0 -170
- package/src/chat/utils/agentSessionMap.ts +0 -76
- package/src/chat/utils/approvalManager.ts +0 -189
- package/src/chat/utils/asyncLock.ts +0 -43
- package/src/chat/utils/asyncQueue.ts +0 -62
- package/src/chat/utils/multiAsyncQueue.ts +0 -66
- package/src/chat/utils/responseAwaiter.ts +0 -181
- package/src/chat/utils/userResolver.ts +0 -48
- package/src/chat/utils/websocket.ts +0 -16
- package/src/index.ts +0 -0
- package/src/test/agent.test.ts +0 -584
- package/src/test/approvalManager.test.ts +0 -141
- package/src/test/chatContextManager.test.ts +0 -552
- package/src/test/clientServerConnection.test.ts +0 -205
- package/src/test/compressingContextManager.test.ts +0 -77
- package/src/test/context.test.ts +0 -150
- package/src/test/contextTestTools.ts +0 -95
- package/src/test/conversation.test.ts +0 -109
- package/src/test/db.test.ts +0 -363
- package/src/test/dbMcpServerConfigs.test.ts +0 -112
- package/src/test/dbSessionFiles.test.ts +0 -258
- package/src/test/dbSessionMessages.test.ts +0 -85
- package/src/test/dbTestTools.ts +0 -157
- package/src/test/imageLoad.test.ts +0 -15
- package/src/test/mcpServerManager.test.ts +0 -114
- package/src/test/multiAsyncQueue.test.ts +0 -183
- package/src/test/openaiStreaming.test.ts +0 -177
- package/src/test/prompt.test.ts +0 -27
- package/src/test/promptProvider.test.ts +0 -33
- package/src/test/responseAwaiter.test.ts +0 -103
- package/src/test/sudoMcpServerManager.test.ts +0 -63
- package/src/test/testTools.ts +0 -176
- package/src/test/tools.test.ts +0 -64
- package/src/tool/agentChat.ts +0 -203
- package/src/tool/agentMain.ts +0 -180
- package/src/tool/chatMain.ts +0 -621
- package/src/tool/commandPrompt.ts +0 -264
- package/src/tool/files.ts +0 -82
- package/src/tool/main.ts +0 -25
- package/src/tool/nodePlatform.ts +0 -73
- package/src/tool/options.ts +0 -144
- package/src/tool/prompt.ts +0 -101
- package/test_data/background_test_profile.json +0 -6
- package/test_data/background_test_script.json +0 -11
- package/test_data/dummyllm_script_crash.json +0 -32
- package/test_data/dummyllm_script_image_gen.json +0 -19
- package/test_data/dummyllm_script_image_gen_fe.json +0 -29
- package/test_data/dummyllm_script_invoke_image_gen_tool.json +0 -37
- package/test_data/dummyllm_script_render_tool.json +0 -29
- package/test_data/dummyllm_script_simplecalc.json +0 -28
- package/test_data/dummyllm_script_test_auto_approve.json +0 -81
- package/test_data/dummyllm_script_test_simplecalc_addition.json +0 -29
- package/test_data/frog.png +0 -0
- package/test_data/frog.png.b64 +0 -1
- package/test_data/git_message_profile.json +0 -4
- package/test_data/git_wip_system.txt +0 -5
- package/test_data/image_gen_test_profile.json +0 -5
- package/test_data/pr_message_profile.json +0 -4
- package/test_data/pr_review_profile.json +0 -4
- package/test_data/prompt_simplecalc.txt +0 -1
- package/test_data/simplecalc_profile.json +0 -4
- package/test_data/sudomcp_import_profile.json +0 -4
- package/test_data/test_script_profile.json +0 -8
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -39
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "@xalia/xmcp/sdk";
|
|
2
|
-
|
|
3
|
-
const DEFAULT_TIMEOUT_MS: number = 10000;
|
|
4
|
-
|
|
5
|
-
type ServerMsg = { type: string };
|
|
6
|
-
// Messages of type S which also have a message field. The message
|
|
7
|
-
// representing an error should be of this type.
|
|
8
|
-
type ServerErr<S> = Extract<S, { message: string }>;
|
|
9
|
-
|
|
10
|
-
type IdExtractor<S extends ServerMsg> = (msg: S) => string | undefined;
|
|
11
|
-
|
|
12
|
-
type WaitingEntry<ServerMessageT> = {
|
|
13
|
-
resolve: (s: ServerMessageT) => void;
|
|
14
|
-
error: (e: Error) => void;
|
|
15
|
-
timeoutId: NodeJS.Timeout;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const logger = getLogger();
|
|
19
|
-
|
|
20
|
-
function defaultImmediate<T>(x: T): T {
|
|
21
|
-
return x;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* Handles response messages and timeouts for client request messages.
|
|
27
|
-
*
|
|
28
|
-
* Create a ResponseAwaiter for a specific class of queries
|
|
29
|
-
*
|
|
30
|
-
* this.responseHandler = new ResponseAwaiter<SomeRequest, SomeResponse>(
|
|
31
|
-
* (msg: SomeResponse) => msg.client_message_id;
|
|
32
|
-
* )
|
|
33
|
-
*
|
|
34
|
-
* Use as follows:
|
|
35
|
-
*
|
|
36
|
-
* ```
|
|
37
|
-
* someRequest(data: string): Promise<string> {
|
|
38
|
-
* const client_message_id = uuidv4();
|
|
39
|
-
*
|
|
40
|
-
* // Create a request message and send it to the backend
|
|
41
|
-
* const msg = { type: "some_request, client_message_id, ... };
|
|
42
|
-
* this.sendMessage(msg);
|
|
43
|
-
*
|
|
44
|
-
* // Get a Promise representing the response to this message, which
|
|
45
|
-
* // we can await.
|
|
46
|
-
* const response =
|
|
47
|
-
* await this.responseHandler.waitForResponse(client_message_id);
|
|
48
|
-
*
|
|
49
|
-
* // Perform any processing on the response
|
|
50
|
-
* return response.response_data;
|
|
51
|
-
* }
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* ResponseAwaiter must be informed of relevant messages in order to resolve
|
|
55
|
-
* responses:
|
|
56
|
-
*
|
|
57
|
-
* ```
|
|
58
|
-
* onMessage(msg: ServerToClient) {
|
|
59
|
-
* switch (msg.type) {
|
|
60
|
-
* ...
|
|
61
|
-
* case "some_response":
|
|
62
|
-
* this.responseHandler.onMessage(msg); // resolve pending promises
|
|
63
|
-
* break;
|
|
64
|
-
* ...
|
|
65
|
-
* }
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* If some actions need to happen immediately on receipt of the message,
|
|
70
|
-
* instead of when the `Promise.resolve` function is resolved, add an
|
|
71
|
-
* `immediateAction` callback, which can optionally transfrom `ServerMsgT`
|
|
72
|
-
* into `FinalResponseT` to be passed back by `waitForResponse`.
|
|
73
|
-
*/
|
|
74
|
-
export class ResponseAwaiter<
|
|
75
|
-
ServerMsgT extends ServerMsg,
|
|
76
|
-
FinalResponseT = ServerMsgT,
|
|
77
|
-
> {
|
|
78
|
-
readonly waiting: Map<string, WaitingEntry<FinalResponseT>>;
|
|
79
|
-
readonly idExtractor: IdExtractor<ServerMsgT>;
|
|
80
|
-
readonly immediateAction: (x: ServerMsgT) => FinalResponseT;
|
|
81
|
-
readonly timeoutMS: number;
|
|
82
|
-
readonly errorType: ServerErr<ServerMsgT>["type"] | undefined;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* errorType: the type field of the message which represents an error.
|
|
86
|
-
*/
|
|
87
|
-
private constructor(
|
|
88
|
-
// value of the `type` field of an error message type,
|
|
89
|
-
// e.g. "session_error". Compiler should ensure that the `ServerMsgT` with
|
|
90
|
-
// this `type` field at least has a `message` field.
|
|
91
|
-
errorType: undefined | ServerErr<ServerMsgT>["type"],
|
|
92
|
-
idExtractor: IdExtractor<ServerMsgT>,
|
|
93
|
-
immediateAction: (x: ServerMsgT) => FinalResponseT,
|
|
94
|
-
timeoutMS: number = DEFAULT_TIMEOUT_MS
|
|
95
|
-
) {
|
|
96
|
-
this.waiting = new Map();
|
|
97
|
-
this.idExtractor = idExtractor;
|
|
98
|
-
this.immediateAction = immediateAction;
|
|
99
|
-
this.timeoutMS = timeoutMS;
|
|
100
|
-
this.errorType = errorType;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static init<S extends ServerMsg>(
|
|
104
|
-
errorType: undefined | ServerErr<S>["type"],
|
|
105
|
-
idExtractor: IdExtractor<S>,
|
|
106
|
-
timeoutMS: number = DEFAULT_TIMEOUT_MS
|
|
107
|
-
): ResponseAwaiter<S, S> {
|
|
108
|
-
return new ResponseAwaiter(
|
|
109
|
-
errorType,
|
|
110
|
-
idExtractor,
|
|
111
|
-
defaultImmediate,
|
|
112
|
-
timeoutMS
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
static initWithImmediate<S extends ServerMsg, F>(
|
|
117
|
-
errorType: undefined | ServerErr<S>["type"],
|
|
118
|
-
idExtractor: IdExtractor<S>,
|
|
119
|
-
immediateAction: (x: S) => F,
|
|
120
|
-
timeoutMS: number = DEFAULT_TIMEOUT_MS
|
|
121
|
-
): ResponseAwaiter<S, F> {
|
|
122
|
-
return new ResponseAwaiter(
|
|
123
|
-
errorType,
|
|
124
|
-
idExtractor,
|
|
125
|
-
immediateAction,
|
|
126
|
-
timeoutMS
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Given a request message, return a promise representing the corresponding
|
|
132
|
-
* response message from the server.
|
|
133
|
-
*/
|
|
134
|
-
waitForResponse(msgId: string): Promise<FinalResponseT> {
|
|
135
|
-
return new Promise<FinalResponseT>((resolve, error) => {
|
|
136
|
-
const timeoutId = setTimeout(() => {
|
|
137
|
-
const waiting = this.waiting.get(msgId);
|
|
138
|
-
if (!waiting) {
|
|
139
|
-
logger.warn(`[ResponseAwaiter] timeout for ${msgId} with no entry`);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
this.waiting.delete(msgId);
|
|
143
|
-
logger.warn(`[ResponseAwaiter] timeout for client_msg_id ${msgId}`);
|
|
144
|
-
error(new Error(`timeout for client_msg_id ${msgId}`));
|
|
145
|
-
}, this.timeoutMS);
|
|
146
|
-
|
|
147
|
-
this.waiting.set(msgId, { resolve, error, timeoutId });
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
waitingForId(msgId: string): boolean {
|
|
152
|
-
return this.waiting.has(msgId);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Pass response (and error) messages in here. Returns `true` if the
|
|
157
|
-
* message was consumed. Otherwise `false`.
|
|
158
|
-
*/
|
|
159
|
-
onMessage(msg: ServerMsgT): boolean {
|
|
160
|
-
const msgId = this.idExtractor(msg);
|
|
161
|
-
if (!msgId) {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
const waiting = this.waiting.get(msgId);
|
|
165
|
-
if (!waiting) {
|
|
166
|
-
logger.warn(
|
|
167
|
-
`[ResponseAwaiter] resolve for ${msgId} with no entry (timeout?)`
|
|
168
|
-
);
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
clearTimeout(waiting.timeoutId);
|
|
173
|
-
this.waiting.delete(msgId);
|
|
174
|
-
if (this.errorType && msg.type === this.errorType) {
|
|
175
|
-
waiting.error(new Error((msg as ServerErr<ServerMsgT>).message));
|
|
176
|
-
} else {
|
|
177
|
-
waiting.resolve(this.immediateAction(msg));
|
|
178
|
-
}
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { getLogger } from "@xalia/xmcp/sdk";
|
|
2
|
-
import { Database, UserData } from "../data/database";
|
|
3
|
-
|
|
4
|
-
const logger = getLogger();
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Validates and resolves an email or UUID to a valid user UUID.
|
|
8
|
-
* @param db - Database instance for user lookups
|
|
9
|
-
* @param input - Either an email address or UUID string
|
|
10
|
-
* @returns Valid user UUID if found, undefined otherwise
|
|
11
|
-
*/
|
|
12
|
-
export async function resolveUserIdentifier(
|
|
13
|
-
db: Database,
|
|
14
|
-
input: string
|
|
15
|
-
): Promise<UserData | undefined> {
|
|
16
|
-
// Check if input looks like a UUID (basic format check)
|
|
17
|
-
const uuidRegex =
|
|
18
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
19
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
20
|
-
|
|
21
|
-
if (uuidRegex.test(input)) {
|
|
22
|
-
// Input looks like a UUID - verify it exists
|
|
23
|
-
try {
|
|
24
|
-
return await db.getUserFromUuid(input);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
logger.debug(`UUID validation failed for ${input}: ${String(error)}`);
|
|
27
|
-
}
|
|
28
|
-
} else if (input === "chatuser0" || input === "chatuser1") {
|
|
29
|
-
// speicial case for test users
|
|
30
|
-
return {
|
|
31
|
-
uuid: input,
|
|
32
|
-
nickname: input,
|
|
33
|
-
email: `${input}@test.com`,
|
|
34
|
-
timezone: "UTC",
|
|
35
|
-
};
|
|
36
|
-
} else if (emailRegex.test(input)) {
|
|
37
|
-
// Input looks like an email - find corresponding UUID
|
|
38
|
-
try {
|
|
39
|
-
const userData = await db.getUserByEmail(input);
|
|
40
|
-
return userData;
|
|
41
|
-
} catch (error) {
|
|
42
|
-
logger.debug(`Email lookup failed for ${input}: ${String(error)}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Input doesn't match expected formats or user not found
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Browser and Node.js Universal WebSocket wrapper
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
4
|
-
|
|
5
|
-
let WSClass: typeof WebSocket;
|
|
6
|
-
|
|
7
|
-
if (typeof window !== "undefined" && typeof window.WebSocket !== "undefined") {
|
|
8
|
-
// Running in browser
|
|
9
|
-
WSClass = window.WebSocket;
|
|
10
|
-
} else {
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
12
|
-
const ws = require("ws");
|
|
13
|
-
WSClass = ws.WebSocket as unknown as typeof WebSocket;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { WSClass as WebSocket };
|
package/src/index.ts
DELETED
|
File without changes
|