agent-world 0.11.1 → 0.12.0

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 (267) hide show
  1. package/README.md +17 -7
  2. package/dist/cli/commands.d.ts +109 -0
  3. package/dist/cli/commands.js +2024 -0
  4. package/dist/cli/display.d.ts +124 -0
  5. package/dist/cli/display.js +381 -0
  6. package/dist/cli/hitl.d.ts +33 -0
  7. package/dist/cli/hitl.js +81 -0
  8. package/dist/cli/index.d.ts +2 -0
  9. package/dist/cli/stream.d.ts +41 -0
  10. package/dist/cli/stream.js +222 -0
  11. package/dist/core/activity-tracker.d.ts +16 -0
  12. package/dist/core/activity-tracker.d.ts.map +1 -0
  13. package/dist/core/activity-tracker.js +91 -0
  14. package/dist/core/activity-tracker.js.map +1 -0
  15. package/dist/core/ai-commands.d.ts +16 -0
  16. package/dist/core/ai-commands.d.ts.map +1 -0
  17. package/dist/core/ai-commands.js +24 -0
  18. package/dist/core/ai-commands.js.map +1 -0
  19. package/dist/core/ai-sdk-patch.d.ts +24 -0
  20. package/dist/core/ai-sdk-patch.d.ts.map +1 -0
  21. package/dist/core/ai-sdk-patch.js +169 -0
  22. package/dist/core/ai-sdk-patch.js.map +1 -0
  23. package/dist/core/anthropic-direct.d.ts +52 -0
  24. package/dist/core/anthropic-direct.d.ts.map +1 -0
  25. package/dist/core/anthropic-direct.js +301 -0
  26. package/dist/core/anthropic-direct.js.map +1 -0
  27. package/dist/core/approval-cache.d.ts +104 -0
  28. package/dist/core/approval-cache.d.ts.map +1 -0
  29. package/dist/core/approval-cache.js +150 -0
  30. package/dist/core/approval-cache.js.map +1 -0
  31. package/dist/core/chat-constants.d.ts +20 -0
  32. package/dist/core/chat-constants.d.ts.map +1 -0
  33. package/dist/core/chat-constants.js +22 -0
  34. package/dist/core/chat-constants.js.map +1 -0
  35. package/dist/core/create-agent-tool.d.ts +66 -0
  36. package/dist/core/create-agent-tool.d.ts.map +1 -0
  37. package/dist/core/create-agent-tool.js +212 -0
  38. package/dist/core/create-agent-tool.js.map +1 -0
  39. package/dist/core/events/approval-checker.d.ts +61 -0
  40. package/dist/core/events/approval-checker.d.ts.map +1 -0
  41. package/dist/core/events/approval-checker.js +226 -0
  42. package/dist/core/events/approval-checker.js.map +1 -0
  43. package/dist/core/events/index.d.ts +25 -0
  44. package/dist/core/events/index.d.ts.map +1 -0
  45. package/dist/core/events/index.js +30 -0
  46. package/dist/core/events/index.js.map +1 -0
  47. package/dist/core/events/memory-manager.d.ts +73 -0
  48. package/dist/core/events/memory-manager.d.ts.map +1 -0
  49. package/dist/core/events/memory-manager.js +1218 -0
  50. package/dist/core/events/memory-manager.js.map +1 -0
  51. package/dist/core/events/mention-logic.d.ts +39 -0
  52. package/dist/core/events/mention-logic.d.ts.map +1 -0
  53. package/dist/core/events/mention-logic.js +163 -0
  54. package/dist/core/events/mention-logic.js.map +1 -0
  55. package/dist/core/events/orchestrator.d.ts +69 -0
  56. package/dist/core/events/orchestrator.d.ts.map +1 -0
  57. package/dist/core/events/orchestrator.js +883 -0
  58. package/dist/core/events/orchestrator.js.map +1 -0
  59. package/dist/core/events/persistence.d.ts +41 -0
  60. package/dist/core/events/persistence.d.ts.map +1 -0
  61. package/dist/core/events/persistence.js +296 -0
  62. package/dist/core/events/persistence.js.map +1 -0
  63. package/dist/core/events/publishers.d.ts +81 -0
  64. package/dist/core/events/publishers.d.ts.map +1 -0
  65. package/dist/core/events/publishers.js +272 -0
  66. package/dist/core/events/publishers.js.map +1 -0
  67. package/dist/core/events/subscribers.d.ts +45 -0
  68. package/dist/core/events/subscribers.d.ts.map +1 -0
  69. package/dist/core/events/subscribers.js +288 -0
  70. package/dist/core/events/subscribers.js.map +1 -0
  71. package/dist/core/events/tool-bridge-logging.d.ts +28 -0
  72. package/dist/core/events/tool-bridge-logging.d.ts.map +1 -0
  73. package/dist/core/events/tool-bridge-logging.js +94 -0
  74. package/dist/core/events/tool-bridge-logging.js.map +1 -0
  75. package/dist/core/events-metadata.d.ts +72 -0
  76. package/dist/core/events-metadata.d.ts.map +1 -0
  77. package/dist/core/events-metadata.js +167 -0
  78. package/dist/core/events-metadata.js.map +1 -0
  79. package/dist/core/events.d.ts +186 -0
  80. package/dist/core/events.d.ts.map +1 -0
  81. package/dist/core/events.js +1248 -0
  82. package/dist/core/events.js.map +1 -0
  83. package/dist/core/export.d.ts +106 -0
  84. package/dist/core/export.d.ts.map +1 -0
  85. package/dist/core/export.js +705 -0
  86. package/dist/core/export.js.map +1 -0
  87. package/dist/core/file-tools.d.ts +114 -0
  88. package/dist/core/file-tools.d.ts.map +1 -0
  89. package/dist/core/file-tools.js +370 -0
  90. package/dist/core/file-tools.js.map +1 -0
  91. package/dist/core/google-direct.d.ts +58 -0
  92. package/dist/core/google-direct.d.ts.map +1 -0
  93. package/dist/core/google-direct.js +298 -0
  94. package/dist/core/google-direct.js.map +1 -0
  95. package/dist/core/hitl.d.ts +54 -0
  96. package/dist/core/hitl.d.ts.map +1 -0
  97. package/dist/core/hitl.js +153 -0
  98. package/dist/core/hitl.js.map +1 -0
  99. package/dist/core/index.d.ts +59 -0
  100. package/dist/core/index.d.ts.map +1 -0
  101. package/dist/core/index.js +70 -0
  102. package/dist/core/index.js.map +1 -0
  103. package/dist/core/llm-config.d.ts +128 -0
  104. package/dist/core/llm-config.d.ts.map +1 -0
  105. package/dist/core/llm-config.js +164 -0
  106. package/dist/core/llm-config.js.map +1 -0
  107. package/dist/core/llm-manager.d.ts +163 -0
  108. package/dist/core/llm-manager.d.ts.map +1 -0
  109. package/dist/core/llm-manager.js +669 -0
  110. package/dist/core/llm-manager.js.map +1 -0
  111. package/dist/core/load-skill-tool.d.ts +55 -0
  112. package/dist/core/load-skill-tool.d.ts.map +1 -0
  113. package/dist/core/load-skill-tool.js +468 -0
  114. package/dist/core/load-skill-tool.js.map +1 -0
  115. package/dist/core/logger.d.ts +88 -0
  116. package/dist/core/logger.d.ts.map +1 -0
  117. package/dist/core/logger.js +358 -0
  118. package/dist/core/logger.js.map +1 -0
  119. package/dist/core/managers.d.ts +131 -0
  120. package/dist/core/managers.d.ts.map +1 -0
  121. package/dist/core/managers.js +1223 -0
  122. package/dist/core/managers.js.map +1 -0
  123. package/dist/core/mcp-server-registry.d.ts +304 -0
  124. package/dist/core/mcp-server-registry.d.ts.map +1 -0
  125. package/dist/core/mcp-server-registry.js +1769 -0
  126. package/dist/core/mcp-server-registry.js.map +1 -0
  127. package/dist/core/mcp-tools.d.ts +56 -0
  128. package/dist/core/mcp-tools.d.ts.map +1 -0
  129. package/dist/core/mcp-tools.js +186 -0
  130. package/dist/core/mcp-tools.js.map +1 -0
  131. package/dist/core/message-prep.d.ts +81 -0
  132. package/dist/core/message-prep.d.ts.map +1 -0
  133. package/dist/core/message-prep.js +223 -0
  134. package/dist/core/message-prep.js.map +1 -0
  135. package/dist/core/message-processing-control.d.ts +54 -0
  136. package/dist/core/message-processing-control.d.ts.map +1 -0
  137. package/dist/core/message-processing-control.js +139 -0
  138. package/dist/core/message-processing-control.js.map +1 -0
  139. package/dist/core/openai-direct.d.ts +80 -0
  140. package/dist/core/openai-direct.d.ts.map +1 -0
  141. package/dist/core/openai-direct.js +374 -0
  142. package/dist/core/openai-direct.js.map +1 -0
  143. package/dist/core/shell-cmd-tool.d.ts +235 -0
  144. package/dist/core/shell-cmd-tool.d.ts.map +1 -0
  145. package/dist/core/shell-cmd-tool.js +1157 -0
  146. package/dist/core/shell-cmd-tool.js.map +1 -0
  147. package/dist/core/shell-process-registry.d.ts +88 -0
  148. package/dist/core/shell-process-registry.d.ts.map +1 -0
  149. package/dist/core/shell-process-registry.js +309 -0
  150. package/dist/core/shell-process-registry.js.map +1 -0
  151. package/dist/core/skill-registry.d.ts +75 -0
  152. package/dist/core/skill-registry.d.ts.map +1 -0
  153. package/dist/core/skill-registry.js +369 -0
  154. package/dist/core/skill-registry.js.map +1 -0
  155. package/dist/core/skill-script-runner.d.ts +89 -0
  156. package/dist/core/skill-script-runner.d.ts.map +1 -0
  157. package/dist/core/skill-script-runner.js +274 -0
  158. package/dist/core/skill-script-runner.js.map +1 -0
  159. package/dist/core/skill-selector.d.ts +65 -0
  160. package/dist/core/skill-selector.d.ts.map +1 -0
  161. package/dist/core/skill-selector.js +190 -0
  162. package/dist/core/skill-selector.js.map +1 -0
  163. package/dist/core/skill-settings.d.ts +20 -0
  164. package/dist/core/skill-settings.d.ts.map +1 -0
  165. package/dist/core/skill-settings.js +40 -0
  166. package/dist/core/skill-settings.js.map +1 -0
  167. package/dist/core/storage/agent-storage.d.ts +134 -0
  168. package/dist/core/storage/agent-storage.d.ts.map +1 -0
  169. package/dist/core/storage/agent-storage.js +498 -0
  170. package/dist/core/storage/agent-storage.js.map +1 -0
  171. package/dist/core/storage/eventStorage/fileEventStorage.d.ts +100 -0
  172. package/dist/core/storage/eventStorage/fileEventStorage.d.ts.map +1 -0
  173. package/dist/core/storage/eventStorage/fileEventStorage.js +494 -0
  174. package/dist/core/storage/eventStorage/fileEventStorage.js.map +1 -0
  175. package/dist/core/storage/eventStorage/index.d.ts +31 -0
  176. package/dist/core/storage/eventStorage/index.d.ts.map +1 -0
  177. package/dist/core/storage/eventStorage/index.js +31 -0
  178. package/dist/core/storage/eventStorage/index.js.map +1 -0
  179. package/dist/core/storage/eventStorage/memoryEventStorage.d.ts +87 -0
  180. package/dist/core/storage/eventStorage/memoryEventStorage.d.ts.map +1 -0
  181. package/dist/core/storage/eventStorage/memoryEventStorage.js +244 -0
  182. package/dist/core/storage/eventStorage/memoryEventStorage.js.map +1 -0
  183. package/dist/core/storage/eventStorage/sqliteEventStorage.d.ts +45 -0
  184. package/dist/core/storage/eventStorage/sqliteEventStorage.d.ts.map +1 -0
  185. package/dist/core/storage/eventStorage/sqliteEventStorage.js +301 -0
  186. package/dist/core/storage/eventStorage/sqliteEventStorage.js.map +1 -0
  187. package/dist/core/storage/eventStorage/types.d.ts +142 -0
  188. package/dist/core/storage/eventStorage/types.d.ts.map +1 -0
  189. package/dist/core/storage/eventStorage/types.js +43 -0
  190. package/dist/core/storage/eventStorage/types.js.map +1 -0
  191. package/dist/core/storage/eventStorage/validation.d.ts +30 -0
  192. package/dist/core/storage/eventStorage/validation.d.ts.map +1 -0
  193. package/dist/core/storage/eventStorage/validation.js +68 -0
  194. package/dist/core/storage/eventStorage/validation.js.map +1 -0
  195. package/dist/core/storage/legacy-migrations.d.ts +45 -0
  196. package/dist/core/storage/legacy-migrations.d.ts.map +1 -0
  197. package/dist/core/storage/legacy-migrations.js +295 -0
  198. package/dist/core/storage/legacy-migrations.js.map +1 -0
  199. package/dist/core/storage/memory-storage.d.ts +105 -0
  200. package/dist/core/storage/memory-storage.d.ts.map +1 -0
  201. package/dist/core/storage/memory-storage.js +415 -0
  202. package/dist/core/storage/memory-storage.js.map +1 -0
  203. package/dist/core/storage/migration-runner.d.ts +96 -0
  204. package/dist/core/storage/migration-runner.d.ts.map +1 -0
  205. package/dist/core/storage/migration-runner.js +306 -0
  206. package/dist/core/storage/migration-runner.js.map +1 -0
  207. package/dist/core/storage/queue-storage.d.ts +147 -0
  208. package/dist/core/storage/queue-storage.d.ts.map +1 -0
  209. package/dist/core/storage/queue-storage.js +290 -0
  210. package/dist/core/storage/queue-storage.js.map +1 -0
  211. package/dist/core/storage/skill-storage.d.ts +136 -0
  212. package/dist/core/storage/skill-storage.d.ts.map +1 -0
  213. package/dist/core/storage/skill-storage.js +474 -0
  214. package/dist/core/storage/skill-storage.js.map +1 -0
  215. package/dist/core/storage/sqlite-schema.d.ts +95 -0
  216. package/dist/core/storage/sqlite-schema.d.ts.map +1 -0
  217. package/dist/core/storage/sqlite-schema.js +156 -0
  218. package/dist/core/storage/sqlite-schema.js.map +1 -0
  219. package/dist/core/storage/sqlite-storage.d.ts +146 -0
  220. package/dist/core/storage/sqlite-storage.d.ts.map +1 -0
  221. package/dist/core/storage/sqlite-storage.js +709 -0
  222. package/dist/core/storage/sqlite-storage.js.map +1 -0
  223. package/dist/core/storage/storage-factory.d.ts +61 -0
  224. package/dist/core/storage/storage-factory.d.ts.map +1 -0
  225. package/dist/core/storage/storage-factory.js +794 -0
  226. package/dist/core/storage/storage-factory.js.map +1 -0
  227. package/dist/core/storage/validation.d.ts +36 -0
  228. package/dist/core/storage/validation.d.ts.map +1 -0
  229. package/dist/core/storage/validation.js +79 -0
  230. package/dist/core/storage/validation.js.map +1 -0
  231. package/dist/core/storage/world-storage.d.ts +114 -0
  232. package/dist/core/storage/world-storage.d.ts.map +1 -0
  233. package/dist/core/storage/world-storage.js +378 -0
  234. package/dist/core/storage/world-storage.js.map +1 -0
  235. package/dist/core/subscription.d.ts +43 -0
  236. package/dist/core/subscription.d.ts.map +1 -0
  237. package/dist/core/subscription.js +227 -0
  238. package/dist/core/subscription.js.map +1 -0
  239. package/dist/core/tool-utils.d.ts +80 -0
  240. package/dist/core/tool-utils.d.ts.map +1 -0
  241. package/dist/core/tool-utils.js +273 -0
  242. package/dist/core/tool-utils.js.map +1 -0
  243. package/dist/core/types.d.ts +595 -0
  244. package/dist/core/types.d.ts.map +1 -0
  245. package/dist/core/types.js +158 -0
  246. package/dist/core/types.js.map +1 -0
  247. package/dist/core/utils.d.ts +138 -0
  248. package/dist/core/utils.d.ts.map +1 -0
  249. package/dist/core/utils.js +478 -0
  250. package/dist/core/utils.js.map +1 -0
  251. package/dist/core/world-class.d.ts +43 -0
  252. package/dist/core/world-class.d.ts.map +1 -0
  253. package/dist/core/world-class.js +90 -0
  254. package/dist/core/world-class.js.map +1 -0
  255. package/dist/index.d.ts +18 -0
  256. package/dist/public/assets/agent-sprites-DJFgj-zP.png +0 -0
  257. package/dist/public/assets/border-KHK37r8y.svg +83 -0
  258. package/dist/public/assets/index-C9kPXL6G.css +1 -0
  259. package/dist/public/assets/index-DOQEHGWt.js +96 -0
  260. package/dist/public/index.html +21 -0
  261. package/dist/server/api.d.ts +2 -0
  262. package/dist/server/api.js +1124 -0
  263. package/dist/server/index.d.ts +29 -0
  264. package/dist/server/sse-handler.d.ts +62 -0
  265. package/dist/server/sse-handler.js +234 -0
  266. package/package.json +15 -3
  267. package/scripts/launch-electron.js +0 -58
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Core Module - Curated Public API
3
+ *
4
+ * Features:
5
+ * - Essential world/agent/chat management functions for client applications
6
+ * - Event-driven messaging with clean subscription interface
7
+ * - Category-based logging system
8
+ * - Core types and utility functions
9
+ *
10
+ * Architecture:
11
+ * - Public API limited to client-facing functionality (~25 exports vs previous 60+)
12
+ * - Internal implementation details kept private
13
+ * - Clear separation between public and private interfaces
14
+ * - Tests can import from internal modules directly
15
+ *
16
+ * Public API Categories:
17
+ * - World Management: createWorld, getWorld, updateWorld, deleteWorld, listWorlds, getWorldConfig, exportWorldToMarkdown
18
+ * - Agent Management: getAgent, updateAgent, deleteAgent, listAgents, clearAgentMemory
19
+ * - Chat Management: createChatData, getChatData, restoreWorldChat
20
+ * - Event System: publishMessage, enableStreaming, disableStreaming
21
+ * - Core Types: World, Agent, AgentMessage, WorldChat, ChatData, WorldInfo, LLMProvider, LoggerConfig, LogLevel
22
+ * - Utilities: logger, createCategoryLogger, loggers, generateId, toKebabCase
23
+ * - Subscription System: subscribeWorld, ClientConnection (for server API)
24
+ *
25
+ * Private APIs (not exported):
26
+ * - Internal agent functions: createAgent (via world instance), updateAgentMemory, loadAgentsIntoWorld, syncWorldAgents, etc.
27
+ * - Internal chat functions: createChat, getChat, createWorldChat
28
+ * - Internal event functions: subscribeAgentToMessages, processAgentMessage, SSE functions
29
+ * - Parameter types: CreateAgentParams, UpdateAgentParams, etc.
30
+ * - Storage implementation: StorageAPI, storage factory functions
31
+ * - Internal utilities: initializeLogger, getCategoryLogLevel
32
+ *
33
+ * Recent Changes:
34
+ * - 2026-02-14: Exported generic HITL option request/response APIs for world-scoped user approval flows.
35
+ * - 2026-02-14: Exported `waitForInitialSkillSync` to allow callers to await startup skill-registry auto-sync completion.
36
+ * - 2026-02-13: Exported chat-scoped stop-message processing controls for Electron IPC stop action.
37
+ * - 2026-02-08: Exported LLM provider configuration helpers for npm core library consumers
38
+ *
39
+ * Version: 3.1.0
40
+ */
41
+ // === WORLD MANAGEMENT ===
42
+ export { createWorld, getWorld, updateWorld, setWorldVariablesText, getWorldVariablesText, getWorldEnvMap, getWorldEnvValue, deleteWorld, listWorlds, getMemory, migrateMessageIds, removeMessagesFrom, editUserMessage, logEditError, getEditErrors } from './managers.js';
43
+ export { exportWorldToMarkdown, exportChatToMarkdown, } from './export.js';
44
+ // === AGENT MANAGEMENT ===
45
+ export { createAgent, getAgent, updateAgent, deleteAgent, listAgents, clearAgentMemory, } from './managers.js';
46
+ // === MCP MANAGEMENT ===
47
+ export { clearToolsCache } from './mcp-server-registry.js';
48
+ export { skillRegistry, syncSkills, waitForInitialSkillSync, getSkills, getSkillsForSystemPrompt, getSkill, getSkillSourceScope, clearSkillsForTests, } from './skill-registry.js';
49
+ export { requestWorldOption, submitWorldOptionResponse, clearHitlStateForTests, } from './hitl.js';
50
+ // === SHELL COMMAND TOOL ===
51
+ export { executeShellCommand, getExecutionHistory, clearExecutionHistory, stopShellCommandsForChat, getProcessExecution, listProcessExecutions, cancelProcessExecution, deleteProcessExecution, subscribeProcessExecutionStatus, clearProcessExecutionStateForTests } from './shell-cmd-tool.js';
52
+ export { stopMessageProcessing } from './message-processing-control.js';
53
+ // === CHAT MANAGEMENT ===
54
+ export { newChat, branchChatFromMessage, listChats, updateChat, deleteChat, restoreChat } from './managers.js';
55
+ // === EVENT SYSTEM ===
56
+ export { enableStreaming, disableStreaming, publishMessage, publishMessageWithId, } from './events/index.js';
57
+ export { beginWorldActivity, trackWorldActivity, } from './activity-tracker.js';
58
+ // LLM Provider enum (needed for agent configuration)
59
+ export { LLMProvider, EventType } from './types.js';
60
+ // === LLM PROVIDER CONFIGURATION ===
61
+ export { configureLLMProvider, validateProviderConfig, isProviderConfigured, getConfiguredProviders, clearAllConfiguration, getConfigurationStatus, } from './llm-config.js';
62
+ // === LOGGER ===
63
+ export { logger, createCategoryLogger, loggers, addLogStreamCallback } from './logger.js';
64
+ // === SUBSCRIPTION SYSTEM ===
65
+ export { subscribeWorld } from './subscription.js';
66
+ export { getDefaultRootPath } from './storage/storage-factory.js';
67
+ // === MIGRATION SYSTEM (for advanced usage) ===
68
+ export { runMigrations, getMigrationStatus, needsMigration } from './storage/migration-runner.js';
69
+ export const VERSION = '0.5.0';
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,2BAA2B;AAC3B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,aAAa,EACd,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB,2BAA2B;AAC3B,OAAO,EACL,WAAW,EACX,QAAQ,EACR,WAAW,EACX,WAAW,EACX,UAAU,EACV,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,yBAAyB;AACzB,OAAO,EACL,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EACb,UAAU,EACV,uBAAuB,EACvB,SAAS,EACT,wBAAwB,EACxB,QAAQ,EACR,mBAAmB,EACnB,mBAAmB,GAMpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,GAIvB,MAAM,WAAW,CAAC;AAEnB,6BAA6B;AAC7B,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,+BAA+B,EAC/B,kCAAkC,EAEnC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,qBAAqB,EAEtB,MAAM,iCAAiC,CAAC;AAEzC,0BAA0B;AAC1B,OAAO,EACL,OAAO,EACP,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACZ,MAAM,eAAe,CAAC;AAEvB,uBAAuB;AACvB,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,kBAAkB,EAClB,kBAAkB,GAGnB,MAAM,uBAAuB,CAAC;AAE/B,qDAAqD;AACrD,OAAO,EAA+F,WAAW,EAAE,SAAS,EAAoB,MAAM,YAAY,CAAC;AAEnK,qCAAqC;AACrC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,GAWvB,MAAM,iBAAiB,CAAC;AAEzB,iBAAiB;AACjB,OAAO,EAAoC,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE5H,8BAA8B;AAC9B,OAAO,EAAyB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,gDAAgD;AAChD,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,cAAc,EAGf,MAAM,+BAA+B,CAAC;AAEvC,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * LLM Configuration Module - Browser-Safe Provider Configuration Management
3
+ *
4
+ * Features:
5
+ * - Browser-safe configuration storage for all LLM providers
6
+ * - Type-safe configuration interfaces for each provider
7
+ * - Configuration injection and validation functions
8
+ * - Clear error messages for missing configuration
9
+ * - Zero Node.js dependencies for browser compatibility
10
+ *
11
+ * Provider Configuration Support:
12
+ * - OpenAI: API key configuration
13
+ * - Anthropic: API key configuration
14
+ * - Google: API key configuration
15
+ * - Azure: API key, resource name, and deployment configuration (API version optional)
16
+ * - XAI: API key configuration
17
+ * - OpenAI-Compatible: API key and base URL configuration
18
+ * - Ollama: Base URL configuration
19
+ *
20
+ * Usage:
21
+ * - configureLLMProvider: Set configuration for a specific provider
22
+ * - getLLMProviderConfig: Get configuration for a specific provider
23
+ * - validateProviderConfig: Validate that required configuration is present
24
+ * - clearAllConfiguration: Clear all provider configurations (for testing)
25
+ *
26
+ * Implementation Details:
27
+ * - Global configuration store with provider-specific sections
28
+ * - Type-safe interfaces prevent configuration errors
29
+ * - Validation functions ensure required settings are present
30
+ * - No external dependencies for maximum browser compatibility
31
+ * - Clear error messages guide users to correct configuration issues
32
+ *
33
+ * Recent Changes:
34
+ * - Initial implementation with all provider configuration interfaces
35
+ * - Added configuration injection and validation functions
36
+ * - Implemented browser-safe global configuration store
37
+ * - Added comprehensive error handling and validation
38
+ */
39
+ import { LLMProvider } from './types.js';
40
+ /**
41
+ * Provider-specific configuration interfaces - Enhanced with TypeScript Utility Types
42
+ */
43
+ /**
44
+ * Base configuration interface for all providers
45
+ */
46
+ export interface BaseLLMConfig {
47
+ apiKey?: string;
48
+ baseUrl?: string;
49
+ endpoint?: string;
50
+ deployment?: string;
51
+ apiVersion?: string;
52
+ }
53
+ /**
54
+ * OpenAI configuration - requires only API key
55
+ */
56
+ export type OpenAIConfig = Required<Pick<BaseLLMConfig, 'apiKey'>>;
57
+ /**
58
+ * Anthropic configuration - requires only API key
59
+ */
60
+ export type AnthropicConfig = Required<Pick<BaseLLMConfig, 'apiKey'>>;
61
+ /**
62
+ * Google configuration - requires only API key
63
+ */
64
+ export type GoogleConfig = Required<Pick<BaseLLMConfig, 'apiKey'>>;
65
+ /**
66
+ * Azure configuration - requires API key, resource name, and deployment; optionally API version
67
+ */
68
+ export type AzureConfig = Required<Pick<BaseLLMConfig, 'apiKey' | 'deployment'>> & {
69
+ resourceName: string;
70
+ apiVersion?: string;
71
+ };
72
+ /**
73
+ * XAI configuration - requires only API key
74
+ */
75
+ export type XAIConfig = Required<Pick<BaseLLMConfig, 'apiKey'>>;
76
+ /**
77
+ * OpenAI-Compatible configuration - requires API key and base URL
78
+ */
79
+ export type OpenAICompatibleConfig = Required<Pick<BaseLLMConfig, 'apiKey' | 'baseUrl'>>;
80
+ /**
81
+ * Ollama configuration - requires only base URL
82
+ */
83
+ export type OllamaConfig = Required<Pick<BaseLLMConfig, 'baseUrl'>>;
84
+ /**
85
+ * Provider configuration mapping for type-safe access
86
+ */
87
+ export type ProviderConfigMap = {
88
+ [LLMProvider.OPENAI]: OpenAIConfig;
89
+ [LLMProvider.ANTHROPIC]: AnthropicConfig;
90
+ [LLMProvider.GOOGLE]: GoogleConfig;
91
+ [LLMProvider.AZURE]: AzureConfig;
92
+ [LLMProvider.XAI]: XAIConfig;
93
+ [LLMProvider.OPENAI_COMPATIBLE]: OpenAICompatibleConfig;
94
+ [LLMProvider.OLLAMA]: OllamaConfig;
95
+ };
96
+ /**
97
+ * Union type for all provider configurations
98
+ */
99
+ export type ProviderConfig = ProviderConfigMap[keyof ProviderConfigMap];
100
+ /**
101
+ * Configure a specific LLM provider with type-safe configuration
102
+ */
103
+ export declare function configureLLMProvider<T extends LLMProvider>(provider: T, config: ProviderConfigMap[T]): void;
104
+ /**
105
+ * Get configuration for a specific provider
106
+ */
107
+ export declare function getLLMProviderConfig<T extends LLMProvider>(provider: T): ProviderConfigMap[T];
108
+ /**
109
+ * Validate provider configuration
110
+ */
111
+ export declare function validateProviderConfig(provider: LLMProvider, config: any): void;
112
+ /**
113
+ * Check if a provider is configured
114
+ */
115
+ export declare function isProviderConfigured(provider: LLMProvider): boolean;
116
+ /**
117
+ * Get list of all configured providers
118
+ */
119
+ export declare function getConfiguredProviders(): LLMProvider[];
120
+ /**
121
+ * Clear all provider configurations (useful for testing)
122
+ */
123
+ export declare function clearAllConfiguration(): void;
124
+ /**
125
+ * Get configuration status for debugging
126
+ */
127
+ export declare function getConfigurationStatus(): Record<LLMProvider, boolean>;
128
+ //# sourceMappingURL=llm-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-config.d.ts","sourceRoot":"","sources":["../../core/llm-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,YAAY,CAAC,CAAC,GAAG;IACjF,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,GAA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G;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAUrE"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * LLM Configuration Module - Browser-Safe Provider Configuration Management
3
+ *
4
+ * Features:
5
+ * - Browser-safe configuration storage for all LLM providers
6
+ * - Type-safe configuration interfaces for each provider
7
+ * - Configuration injection and validation functions
8
+ * - Clear error messages for missing configuration
9
+ * - Zero Node.js dependencies for browser compatibility
10
+ *
11
+ * Provider Configuration Support:
12
+ * - OpenAI: API key configuration
13
+ * - Anthropic: API key configuration
14
+ * - Google: API key configuration
15
+ * - Azure: API key, resource name, and deployment configuration (API version optional)
16
+ * - XAI: API key configuration
17
+ * - OpenAI-Compatible: API key and base URL configuration
18
+ * - Ollama: Base URL configuration
19
+ *
20
+ * Usage:
21
+ * - configureLLMProvider: Set configuration for a specific provider
22
+ * - getLLMProviderConfig: Get configuration for a specific provider
23
+ * - validateProviderConfig: Validate that required configuration is present
24
+ * - clearAllConfiguration: Clear all provider configurations (for testing)
25
+ *
26
+ * Implementation Details:
27
+ * - Global configuration store with provider-specific sections
28
+ * - Type-safe interfaces prevent configuration errors
29
+ * - Validation functions ensure required settings are present
30
+ * - No external dependencies for maximum browser compatibility
31
+ * - Clear error messages guide users to correct configuration issues
32
+ *
33
+ * Recent Changes:
34
+ * - Initial implementation with all provider configuration interfaces
35
+ * - Added configuration injection and validation functions
36
+ * - Implemented browser-safe global configuration store
37
+ * - Added comprehensive error handling and validation
38
+ */
39
+ import { LLMProvider } from './types.js';
40
+ /**
41
+ * Global configuration store instance
42
+ */
43
+ let providerConfigs = {};
44
+ /**
45
+ * Initialize default configuration - configure Ollama with default URL if no providers configured
46
+ */
47
+ function initializeDefaultConfiguration() {
48
+ // Only initialize if no providers are configured yet
49
+ if (Object.keys(providerConfigs).length === 0) {
50
+ // Configure Ollama with default URL as fallback (OpenAI-compatible endpoint)
51
+ configureLLMProvider(LLMProvider.OLLAMA, {
52
+ baseUrl: 'http://localhost:11434/v1'
53
+ });
54
+ }
55
+ }
56
+ // Initialize default configuration on module load
57
+ initializeDefaultConfiguration();
58
+ /**
59
+ * Configure a specific LLM provider with type-safe configuration
60
+ */
61
+ export function configureLLMProvider(provider, config) {
62
+ // Validate configuration before storing
63
+ validateProviderConfig(provider, config);
64
+ // Store configuration
65
+ providerConfigs[provider] = config;
66
+ }
67
+ /**
68
+ * Get configuration for a specific provider
69
+ */
70
+ export function getLLMProviderConfig(provider) {
71
+ const config = providerConfigs[provider];
72
+ if (!config) {
73
+ throw new Error(`No configuration found for ${provider} provider. ` +
74
+ `Please ensure the provider is configured before making LLM calls. ` +
75
+ `Configuration should be set via configureLLMProvider() function.`);
76
+ }
77
+ return config;
78
+ }
79
+ /**
80
+ * Validate provider configuration
81
+ */
82
+ export function validateProviderConfig(provider, config) {
83
+ switch (provider) {
84
+ case LLMProvider.OPENAI:
85
+ if (!config.apiKey || typeof config.apiKey !== 'string') {
86
+ throw new Error('OpenAI provider requires apiKey (string)');
87
+ }
88
+ break;
89
+ case LLMProvider.ANTHROPIC:
90
+ if (!config.apiKey || typeof config.apiKey !== 'string') {
91
+ throw new Error('Anthropic provider requires apiKey (string)');
92
+ }
93
+ break;
94
+ case LLMProvider.GOOGLE:
95
+ if (!config.apiKey || typeof config.apiKey !== 'string') {
96
+ throw new Error('Google provider requires apiKey (string)');
97
+ }
98
+ break;
99
+ case LLMProvider.AZURE:
100
+ if (!config.apiKey || typeof config.apiKey !== 'string') {
101
+ throw new Error('Azure provider requires apiKey (string)');
102
+ }
103
+ if (!config.resourceName || typeof config.resourceName !== 'string') {
104
+ throw new Error('Azure provider requires resourceName (string)');
105
+ }
106
+ if (!config.deployment || typeof config.deployment !== 'string') {
107
+ throw new Error('Azure provider requires deployment (string)');
108
+ }
109
+ break;
110
+ case LLMProvider.XAI:
111
+ if (!config.apiKey || typeof config.apiKey !== 'string') {
112
+ throw new Error('XAI provider requires apiKey (string)');
113
+ }
114
+ break;
115
+ case LLMProvider.OPENAI_COMPATIBLE:
116
+ if (!config.apiKey || typeof config.apiKey !== 'string') {
117
+ throw new Error('OpenAI-Compatible provider requires apiKey (string)');
118
+ }
119
+ if (!config.baseUrl || typeof config.baseUrl !== 'string') {
120
+ throw new Error('OpenAI-Compatible provider requires baseUrl (string)');
121
+ }
122
+ break;
123
+ case LLMProvider.OLLAMA:
124
+ if (!config.baseUrl || typeof config.baseUrl !== 'string') {
125
+ throw new Error('Ollama provider requires baseUrl (string)');
126
+ }
127
+ break;
128
+ default:
129
+ throw new Error(`Unsupported provider: ${provider}`);
130
+ }
131
+ }
132
+ /**
133
+ * Check if a provider is configured
134
+ */
135
+ export function isProviderConfigured(provider) {
136
+ return !!providerConfigs[provider];
137
+ }
138
+ /**
139
+ * Get list of all configured providers
140
+ */
141
+ export function getConfiguredProviders() {
142
+ return Object.keys(providerConfigs);
143
+ }
144
+ /**
145
+ * Clear all provider configurations (useful for testing)
146
+ */
147
+ export function clearAllConfiguration() {
148
+ providerConfigs = {};
149
+ }
150
+ /**
151
+ * Get configuration status for debugging
152
+ */
153
+ export function getConfigurationStatus() {
154
+ return {
155
+ [LLMProvider.OPENAI]: isProviderConfigured(LLMProvider.OPENAI),
156
+ [LLMProvider.ANTHROPIC]: isProviderConfigured(LLMProvider.ANTHROPIC),
157
+ [LLMProvider.GOOGLE]: isProviderConfigured(LLMProvider.GOOGLE),
158
+ [LLMProvider.AZURE]: isProviderConfigured(LLMProvider.AZURE),
159
+ [LLMProvider.XAI]: isProviderConfigured(LLMProvider.XAI),
160
+ [LLMProvider.OPENAI_COMPATIBLE]: isProviderConfigured(LLMProvider.OPENAI_COMPATIBLE),
161
+ [LLMProvider.OLLAMA]: isProviderConfigured(LLMProvider.OLLAMA),
162
+ };
163
+ }
164
+ //# sourceMappingURL=llm-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-config.js","sourceRoot":"","sources":["../../core/llm-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;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AG,CAAC;QACxD,CAAC,WAAW,CAAC,iBAAiB,CAAC,EAAE,oBAAoB,CAAC,WAAW,CAAC,iBAAiB,CAAC;QACpF,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,WAAW,CAAC,MAAM,CAAC;KAC/D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * LLM Manager Module - Pure Orchestration Layer (LLM Provider Refactoring Phase 5)
3
+ *
4
+ * Features:
5
+ * - Browser-safe LLM integration using direct provider SDKs (OpenAI, Anthropic, Google)
6
+ * - Streaming responses with SSE events via World.eventEmitter specifically
7
+ * - Support for all major LLM providers (OpenAI, Anthropic, Google, Azure, XAI, OpenAI-Compatible, Ollama)
8
+ * - Agent activity tracking and token usage monitoring with automatic state persistence
9
+ * - Error handling with SSE error events via world's eventEmitter and timeout management
10
+ * - World-aware event publishing using world.eventEmitter for proper event isolation
11
+ * - Conversation history support with message preparation and context management
12
+ * - Global LLM call queue to ensure serialized execution (one LLM call at a time)
13
+ * - Configuration injection from external sources (CLI/server) for browser compatibility
14
+ * - Automatic MCP tool integration for worlds with mcpConfig
15
+ * - All providers return LLMResponse with unified structure
16
+ * - Granular function-based logging for detailed debugging control
17
+ *
18
+ * Core Functions:
19
+ * - streamAgentResponse: Streaming LLM calls with SSE events via world.eventEmitter (queued)
20
+ * - generateAgentResponse: Non-streaming LLM calls with automatic state management (queued)
21
+ * - loadLLMProvider: Provider loading logic using injected configuration
22
+ * - getLLMQueueStatus: Monitor queue status for debugging and administration
23
+ * - clearLLMQueue: Emergency queue clearing for administrative purposes
24
+ *
25
+ * Provider Support:
26
+ * - OpenAI: Direct OpenAI package integration (bypasses AI SDK bug)
27
+ * - Azure: Direct OpenAI package integration with Azure endpoints (bypasses AI SDK bug)
28
+ * - OpenAI-Compatible: Direct OpenAI package integration (bypasses AI SDK bug)
29
+ * - XAI: Direct OpenAI package integration with XAI endpoints (bypasses AI SDK bug)
30
+ * - Ollama: Direct OpenAI package integration with OpenAI-compatible endpoint (better function calling)
31
+ * - Anthropic: Direct Anthropic SDK integration (improved tool calling support)
32
+ * - Google: Direct Google Generative AI SDK integration (improved tool calling support)
33
+ *
34
+ * Granular Logging Categories:
35
+ * - llm.queue: Queue operations (add, process, complete, errors)
36
+ * - llm.streaming: Streaming response operations (start, chunks, finish, errors)
37
+ * - llm.generation: Non-streaming response operations (start, finish, errors)
38
+ * - llm.provider: Provider loading, configuration, and validation
39
+ * - llm.mcp: Comprehensive MCP tool integration and execution tracking
40
+ * - llm.util: Utility functions and helper operations
41
+ *
42
+ * Environment Variable Control:
43
+ * - LOG_LLM_QUEUE=debug: Enable queue operation debugging
44
+ * - LOG_LLM_STREAMING=debug: Enable streaming operation debugging
45
+ * - LOG_LLM_GENERATION=debug: Enable generation operation debugging
46
+ * - LOG_LLM_PROVIDER=debug: Enable provider operation debugging
47
+ * - LOG_LLM_MCP=debug: Enable comprehensive MCP tool debugging (consolidates all MCP logging)
48
+ * - LOG_LLM_UTIL=debug: Enable utility function debugging
49
+ *
50
+ * MCP Tool Logging Features (LOG_LLM_MCP=debug):
51
+ * - Tool call sequence tracking with unique sequence IDs
52
+ * - Tool execution performance metrics (duration in milliseconds)
53
+ * - Tool result content analysis (size, type, preview)
54
+ * - Tool call success/failure status with detailed error information
55
+ * - Tool call dependencies and parent-child relationships
56
+ * - Tool argument validation and presence checking
57
+ * - Streaming vs non-streaming execution path differentiation
58
+ * - Complete tool call lifecycle from start to completion
59
+ * - Server-side tool execution via direct MCP server registry calls
60
+ * - AI SDK tool conversion execution tracking
61
+ * - Tool result processing and content type identification
62
+ *
63
+ * LLM Queue Implementation:
64
+ * - Global singleton queue prevents concurrent LLM calls across all agents and worlds
65
+ * - FIFO (First In, First Out) processing ensures fair agent response ordering
66
+ * - Maximum queue size of 100 items prevents memory overflow issues
67
+ * - 15-minute timeout per LLM call supports long-running tool executions (configurable)
68
+ * - Warning logs at 50% timeout threshold for debugging long-running operations
69
+ * - Queue status monitoring available for debugging and performance analysis
70
+ * - Emergency clear function allows administrative queue reset when needed
71
+ * - Proper error handling with promise rejection for failed calls
72
+ * - Automatic queue processing with safety measures for edge cases
73
+ * - Timeout cleanup on promise resolution prevents resource leaks and Jest hanging
74
+ * - Configurable timeout via setProcessingTimeout() for different use cases
75
+ *
76
+ * Browser Safety Implementation:
77
+ * - Zero process.env dependencies for browser compatibility
78
+ * - Configuration injection via llm-config module
79
+ * - All provider settings supplied externally by CLI/server components
80
+ * - Type-safe configuration interfaces prevent runtime errors
81
+ * - Clear error messages when configuration is missing
82
+ *
83
+ * Implementation Details:
84
+ * - Uses direct OpenAI package for OpenAI providers to avoid AI SDK schema corruption bug
85
+ * - Uses direct Anthropic SDK for Anthropic provider to fix tool calling issues
86
+ * - Uses direct Google Generative AI SDK for Google provider to fix tool calling issues
87
+ * - Publishes SSE events via world.eventEmitter.emit('sse', event) for proper isolation
88
+ * - Updates agent activity metrics and LLM call counts automatically
89
+ * - Zero dependencies on Node.js environment variables or legacy event systems
90
+ * - Complete provider support with externally injected configuration
91
+ * - All events scoped to specific world instance preventing cross-world interference
92
+ * - Full LLM provider support with configuration validation and error handling
93
+ * - Timeout handling with configurable limits and proper error recovery
94
+ * - Queue-based serialization prevents API rate limits and resource conflicts
95
+ *
96
+ * Recent Changes:
97
+ * - 2026-02-13: Reclassified stop-triggered aborts as cancellation/info logs (not errors) in queue and non-streaming paths.
98
+ * - 2026-02-13: Added merged external+queue abort-signal support so chat stop requests can cancel follow-up continuation calls.
99
+ * - 2026-02-13: Added chat-scoped LLM cancellation controls so Electron stop requests can abort active and queued calls by `worldId` + `chatId`.
100
+ * - 2026-02-08: Removed stale manual tool-intervention terminology from internal comments
101
+ * - 2025-11-09: Phase 5 - Updated to expect LLMResponse from all providers
102
+ * - Removed old manual tool decision return type handling
103
+ * - All providers now return unified LLMResponse interface with type discriminator
104
+ * - Updated logging to handle LLMResponse structure (type, content, tool_calls)
105
+ * - Providers are now pure clients - no tool execution, only API calls
106
+ * - NO type checking for string vs object - always LLMResponse
107
+ * - Tool orchestration will be handled by events.ts (Phase 6)
108
+ * - Simplified tool usage guidance: minimal system prompt patch for tool availability
109
+ * - Increased LLM queue timeout from 2 minutes to 15 minutes for long-running tool executions
110
+ * - Replaced AI SDK with direct OpenAI, Anthropic, and Google integrations
111
+ * - Implemented granular function-based logging for detailed debugging control
112
+ * - Tool-specific guidance moved to individual tool descriptions (proper separation)
113
+ */
114
+ import { World, Agent, AgentMessage, LLMProvider, WorldSSEEvent, LLMResponse } from './types.js';
115
+ /**
116
+ * LLM configuration interface
117
+ */
118
+ export interface LLMConfig {
119
+ provider: LLMProvider;
120
+ model: string;
121
+ apiKey?: string;
122
+ baseUrl?: string;
123
+ temperature?: number;
124
+ maxTokens?: number;
125
+ ollamaBaseUrl?: string;
126
+ }
127
+ /**
128
+ * Streaming agent response with SSE events via world's eventEmitter (queued)
129
+ */
130
+ export declare function streamAgentResponse(world: World, agent: Agent, messages: AgentMessage[], publishSSE: (world: World, data: Partial<WorldSSEEvent>) => void, chatId?: string | null, abortSignal?: AbortSignal): Promise<{
131
+ response: LLMResponse;
132
+ messageId: string;
133
+ }>;
134
+ /**
135
+ * Non-streaming LLM call (queued)
136
+ */
137
+ export declare function generateAgentResponse(world: World, agent: Agent, messages: AgentMessage[], _publishSSE?: (world: World, data: Partial<WorldSSEEvent>) => void, skipTools?: boolean, chatId?: string | null, abortSignal?: AbortSignal): Promise<{
138
+ response: LLMResponse;
139
+ messageId: string;
140
+ }>;
141
+ /**
142
+ * Get current LLM queue status for monitoring and debugging
143
+ */
144
+ export declare function getLLMQueueStatus(): {
145
+ queueLength: number;
146
+ processing: boolean;
147
+ nextAgent?: string;
148
+ nextWorld?: string;
149
+ maxQueueSize: number;
150
+ };
151
+ /**
152
+ * Emergency function to clear the LLM queue (for debugging/admin use)
153
+ * Returns the number of items that were cleared
154
+ */
155
+ export declare function clearLLMQueue(): number;
156
+ /**
157
+ * Cancel active and pending LLM calls for a specific world/chat session.
158
+ */
159
+ export declare function cancelLLMCallsForChat(worldId: string, chatId: string | null): {
160
+ canceledPending: number;
161
+ abortedActive: number;
162
+ };
163
+ //# sourceMappingURL=llm-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-manager.d.ts","sourceRoot":"","sources":["../../core/llm-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHG;AAEH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAe,WAAW,EAAE,MAAM,YAAY,CAAC;AA8S9G;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA8CD;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,YAAY,EAAE,EACxB,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,KAAK,IAAI,EAChE,MAAM,GAAE,MAAM,GAAG,IAAW,EAC5B,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAiBvD;AAmJD;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,QAAQ,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