@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.
Files changed (161) hide show
  1. package/package.json +5 -2
  2. package/.env.development +0 -6
  3. package/.env.test +0 -7
  4. package/.prettierrc.json +0 -11
  5. package/context_system.md +0 -498
  6. package/eslint.config.mjs +0 -38
  7. package/scripts/chat_server +0 -8
  8. package/scripts/git_message +0 -31
  9. package/scripts/git_wip +0 -21
  10. package/scripts/pr_message +0 -18
  11. package/scripts/pr_review +0 -16
  12. package/scripts/setup_chat +0 -90
  13. package/scripts/shutdown_chat_server +0 -42
  14. package/scripts/start_chat_server +0 -24
  15. package/scripts/sudomcp_import +0 -23
  16. package/scripts/test_chat +0 -327
  17. package/src/agent/agent.ts +0 -699
  18. package/src/agent/agentUtils.ts +0 -286
  19. package/src/agent/compressingContextManager.ts +0 -129
  20. package/src/agent/context.ts +0 -265
  21. package/src/agent/contextWithWorkspace.ts +0 -162
  22. package/src/agent/documentSummarizer.ts +0 -157
  23. package/src/agent/dummyLLM.ts +0 -130
  24. package/src/agent/iAgentEventHandler.ts +0 -64
  25. package/src/agent/imageGenLLM.ts +0 -101
  26. package/src/agent/imageGenerator.ts +0 -45
  27. package/src/agent/iplatform.ts +0 -18
  28. package/src/agent/llm.ts +0 -74
  29. package/src/agent/mcpServerManager.ts +0 -541
  30. package/src/agent/nullAgentEventHandler.ts +0 -26
  31. package/src/agent/nullPlatform.ts +0 -13
  32. package/src/agent/openAI.ts +0 -123
  33. package/src/agent/openAILLM.ts +0 -99
  34. package/src/agent/openAILLMStreaming.ts +0 -648
  35. package/src/agent/promptProvider.ts +0 -87
  36. package/src/agent/repeatLLM.ts +0 -62
  37. package/src/agent/sudoMcpServerManager.ts +0 -361
  38. package/src/agent/test_data/harrypotter.txt +0 -6065
  39. package/src/agent/tokenAuth.ts +0 -50
  40. package/src/agent/tokenCounter.test.ts +0 -243
  41. package/src/agent/tokenCounter.ts +0 -483
  42. package/src/agent/toolSettings.ts +0 -24
  43. package/src/agent/tools/calculatorTool.ts +0 -50
  44. package/src/agent/tools/contentExtractors/htmlToText.ts +0 -61
  45. package/src/agent/tools/contentExtractors/pdfToText.ts +0 -60
  46. package/src/agent/tools/datetimeTool.ts +0 -41
  47. package/src/agent/tools/fileManager/fileManagerTool.ts +0 -199
  48. package/src/agent/tools/fileManager/index.ts +0 -50
  49. package/src/agent/tools/fileManager/memoryFileManager.ts +0 -120
  50. package/src/agent/tools/fileManager/mimeTypes.ts +0 -60
  51. package/src/agent/tools/fileManager/prompt.ts +0 -38
  52. package/src/agent/tools/fileManager/types.ts +0 -189
  53. package/src/agent/tools/index.ts +0 -49
  54. package/src/agent/tools/openUrlTool.ts +0 -62
  55. package/src/agent/tools/renderTool.ts +0 -92
  56. package/src/agent/tools/utils.ts +0 -74
  57. package/src/agent/tools/webSearch.ts +0 -138
  58. package/src/agent/tools/webSearchTool.ts +0 -44
  59. package/src/chat/client/chatClient.ts +0 -967
  60. package/src/chat/client/connection.test.ts +0 -241
  61. package/src/chat/client/connection.ts +0 -286
  62. package/src/chat/client/constants.ts +0 -1
  63. package/src/chat/client/index.ts +0 -21
  64. package/src/chat/client/interfaces.ts +0 -34
  65. package/src/chat/client/sessionClient.ts +0 -574
  66. package/src/chat/client/sessionFiles.ts +0 -142
  67. package/src/chat/client/teamManager.ts +0 -29
  68. package/src/chat/constants.ts +0 -6
  69. package/src/chat/data/apiKeyManager.ts +0 -76
  70. package/src/chat/data/dataModels.ts +0 -107
  71. package/src/chat/data/database.ts +0 -997
  72. package/src/chat/data/dbMcpServerConfigs.ts +0 -59
  73. package/src/chat/data/dbSessionFiles.ts +0 -107
  74. package/src/chat/data/dbSessionMessages.ts +0 -102
  75. package/src/chat/protocol/connectionMessages.ts +0 -49
  76. package/src/chat/protocol/constants.ts +0 -55
  77. package/src/chat/protocol/errors.ts +0 -16
  78. package/src/chat/protocol/messages.ts +0 -899
  79. package/src/chat/server/README.md +0 -127
  80. package/src/chat/server/chatContextManager.ts +0 -660
  81. package/src/chat/server/connectionManager.test.ts +0 -246
  82. package/src/chat/server/connectionManager.ts +0 -506
  83. package/src/chat/server/conversation.ts +0 -319
  84. package/src/chat/server/errorUtils.ts +0 -28
  85. package/src/chat/server/imageGeneratorTools.ts +0 -179
  86. package/src/chat/server/openAIRouterLLM.ts +0 -168
  87. package/src/chat/server/openSession.ts +0 -1945
  88. package/src/chat/server/openSessionMessageSender.ts +0 -4
  89. package/src/chat/server/promptRefiner.ts +0 -106
  90. package/src/chat/server/server.ts +0 -178
  91. package/src/chat/server/sessionFileManager.ts +0 -151
  92. package/src/chat/server/sessionRegistry.test.ts +0 -137
  93. package/src/chat/server/sessionRegistry.ts +0 -1553
  94. package/src/chat/server/test-utils/mockFactories.ts +0 -422
  95. package/src/chat/server/titleGenerator.test.ts +0 -103
  96. package/src/chat/server/titleGenerator.ts +0 -143
  97. package/src/chat/server/tools.ts +0 -170
  98. package/src/chat/utils/agentSessionMap.ts +0 -76
  99. package/src/chat/utils/approvalManager.ts +0 -189
  100. package/src/chat/utils/asyncLock.ts +0 -43
  101. package/src/chat/utils/asyncQueue.ts +0 -62
  102. package/src/chat/utils/multiAsyncQueue.ts +0 -66
  103. package/src/chat/utils/responseAwaiter.ts +0 -181
  104. package/src/chat/utils/userResolver.ts +0 -48
  105. package/src/chat/utils/websocket.ts +0 -16
  106. package/src/index.ts +0 -0
  107. package/src/test/agent.test.ts +0 -584
  108. package/src/test/approvalManager.test.ts +0 -141
  109. package/src/test/chatContextManager.test.ts +0 -552
  110. package/src/test/clientServerConnection.test.ts +0 -205
  111. package/src/test/compressingContextManager.test.ts +0 -77
  112. package/src/test/context.test.ts +0 -150
  113. package/src/test/contextTestTools.ts +0 -95
  114. package/src/test/conversation.test.ts +0 -109
  115. package/src/test/db.test.ts +0 -363
  116. package/src/test/dbMcpServerConfigs.test.ts +0 -112
  117. package/src/test/dbSessionFiles.test.ts +0 -258
  118. package/src/test/dbSessionMessages.test.ts +0 -85
  119. package/src/test/dbTestTools.ts +0 -157
  120. package/src/test/imageLoad.test.ts +0 -15
  121. package/src/test/mcpServerManager.test.ts +0 -114
  122. package/src/test/multiAsyncQueue.test.ts +0 -183
  123. package/src/test/openaiStreaming.test.ts +0 -177
  124. package/src/test/prompt.test.ts +0 -27
  125. package/src/test/promptProvider.test.ts +0 -33
  126. package/src/test/responseAwaiter.test.ts +0 -103
  127. package/src/test/sudoMcpServerManager.test.ts +0 -63
  128. package/src/test/testTools.ts +0 -176
  129. package/src/test/tools.test.ts +0 -64
  130. package/src/tool/agentChat.ts +0 -203
  131. package/src/tool/agentMain.ts +0 -180
  132. package/src/tool/chatMain.ts +0 -621
  133. package/src/tool/commandPrompt.ts +0 -264
  134. package/src/tool/files.ts +0 -82
  135. package/src/tool/main.ts +0 -25
  136. package/src/tool/nodePlatform.ts +0 -73
  137. package/src/tool/options.ts +0 -144
  138. package/src/tool/prompt.ts +0 -101
  139. package/test_data/background_test_profile.json +0 -6
  140. package/test_data/background_test_script.json +0 -11
  141. package/test_data/dummyllm_script_crash.json +0 -32
  142. package/test_data/dummyllm_script_image_gen.json +0 -19
  143. package/test_data/dummyllm_script_image_gen_fe.json +0 -29
  144. package/test_data/dummyllm_script_invoke_image_gen_tool.json +0 -37
  145. package/test_data/dummyllm_script_render_tool.json +0 -29
  146. package/test_data/dummyllm_script_simplecalc.json +0 -28
  147. package/test_data/dummyllm_script_test_auto_approve.json +0 -81
  148. package/test_data/dummyllm_script_test_simplecalc_addition.json +0 -29
  149. package/test_data/frog.png +0 -0
  150. package/test_data/frog.png.b64 +0 -1
  151. package/test_data/git_message_profile.json +0 -4
  152. package/test_data/git_wip_system.txt +0 -5
  153. package/test_data/image_gen_test_profile.json +0 -5
  154. package/test_data/pr_message_profile.json +0 -4
  155. package/test_data/pr_review_profile.json +0 -4
  156. package/test_data/prompt_simplecalc.txt +0 -1
  157. package/test_data/simplecalc_profile.json +0 -4
  158. package/test_data/sudomcp_import_profile.json +0 -4
  159. package/test_data/test_script_profile.json +0 -8
  160. package/tsconfig.json +0 -13
  161. 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