@ainetwork/adk 0.2.0 → 0.2.2

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 (159) hide show
  1. package/README.md +50 -24
  2. package/dist/cjs/chunk-3ZFV2K7O.cjs +128 -0
  3. package/dist/cjs/chunk-3ZFV2K7O.cjs.map +1 -0
  4. package/dist/cjs/chunk-7PZP7YSA.cjs +40 -0
  5. package/dist/cjs/chunk-7PZP7YSA.cjs.map +1 -0
  6. package/dist/cjs/chunk-A2I7D6JW.cjs +45 -0
  7. package/dist/cjs/chunk-A2I7D6JW.cjs.map +1 -0
  8. package/dist/cjs/{chunk-6YVTJEMQ.cjs → chunk-BBFYVWE2.cjs} +17 -42
  9. package/dist/cjs/chunk-BBFYVWE2.cjs.map +1 -0
  10. package/dist/cjs/{chunk-LRBRG2DS.cjs → chunk-E35E4LQY.cjs} +4 -4
  11. package/dist/cjs/chunk-E35E4LQY.cjs.map +1 -0
  12. package/dist/cjs/{chunk-EAK7MP6X.cjs → chunk-FRWC3FQ4.cjs} +4 -4
  13. package/dist/cjs/chunk-FRWC3FQ4.cjs.map +1 -0
  14. package/dist/cjs/{chunk-ZZK4ACTV.cjs → chunk-KHD7UAFW.cjs} +64 -27
  15. package/dist/cjs/chunk-KHD7UAFW.cjs.map +1 -0
  16. package/dist/cjs/{chunk-JXKLEQD6.cjs → chunk-LMR6B76V.cjs} +5 -5
  17. package/dist/cjs/chunk-LMR6B76V.cjs.map +1 -0
  18. package/dist/cjs/{chunk-55IME4BG.cjs → chunk-OKRBMMK2.cjs} +46 -24
  19. package/dist/cjs/chunk-OKRBMMK2.cjs.map +1 -0
  20. package/dist/cjs/{chunk-DX2JH3FJ.cjs → chunk-QHQLU7BI.cjs} +1 -1
  21. package/dist/cjs/{chunk-DX2JH3FJ.cjs.map → chunk-QHQLU7BI.cjs.map} +1 -1
  22. package/dist/cjs/{chunk-QWASSVCU.cjs → chunk-RIJV7J5Z.cjs} +1 -1
  23. package/dist/cjs/chunk-RIJV7J5Z.cjs.map +1 -0
  24. package/dist/cjs/{chunk-3J3ORQOG.cjs → chunk-VLMHDHXT.cjs} +3 -3
  25. package/dist/cjs/{chunk-3J3ORQOG.cjs.map → chunk-VLMHDHXT.cjs.map} +1 -1
  26. package/dist/cjs/{chunk-344VLDMS.cjs → chunk-W5VM75PL.cjs} +7 -7
  27. package/dist/cjs/{chunk-344VLDMS.cjs.map → chunk-W5VM75PL.cjs.map} +1 -1
  28. package/dist/cjs/{chunk-KE7SL3H6.cjs → chunk-ZPYMLCQZ.cjs} +14 -18
  29. package/dist/cjs/chunk-ZPYMLCQZ.cjs.map +1 -0
  30. package/dist/cjs/controllers/api/threads.api.controller.cjs +7 -0
  31. package/dist/cjs/controllers/api/threads.api.controller.cjs.map +1 -0
  32. package/dist/cjs/controllers/index.cjs +4 -4
  33. package/dist/cjs/controllers/query.controller.cjs +3 -3
  34. package/dist/cjs/index.cjs +67 -28
  35. package/dist/cjs/index.cjs.map +1 -1
  36. package/dist/cjs/middlewares/auth.middleware.cjs +3 -3
  37. package/dist/cjs/modules/a2a/a2a.module.cjs +2 -2
  38. package/dist/cjs/modules/index.cjs +7 -7
  39. package/dist/cjs/modules/index.cjs.map +1 -1
  40. package/dist/cjs/modules/mcp/mcp.module.cjs +2 -2
  41. package/dist/cjs/modules/models/model.module.cjs +2 -2
  42. package/dist/cjs/routes/a2a.routes.cjs +4 -4
  43. package/dist/cjs/routes/api/threads.routes.cjs +9 -0
  44. package/dist/cjs/routes/api/threads.routes.cjs.map +1 -0
  45. package/dist/cjs/routes/api.routes.cjs +5 -5
  46. package/dist/cjs/routes/index.cjs +11 -11
  47. package/dist/cjs/routes/query.routes.cjs +6 -6
  48. package/dist/cjs/services/a2a.service.cjs +2 -2
  49. package/dist/cjs/services/index.cjs +4 -4
  50. package/dist/cjs/services/query-stream.service.cjs +2 -2
  51. package/dist/cjs/services/query.service.cjs +2 -2
  52. package/dist/cjs/types/agent.cjs +2 -2
  53. package/dist/esm/{chunk-7D4SKPIS.js → chunk-4C2TLCWI.js} +2 -2
  54. package/dist/esm/{chunk-PN6NMQBM.js → chunk-5JIXQ6PU.js} +2 -2
  55. package/dist/esm/chunk-5JIXQ6PU.js.map +1 -0
  56. package/dist/esm/{chunk-M4EJC7LZ.js → chunk-7IYLOABV.js} +61 -24
  57. package/dist/esm/chunk-7IYLOABV.js.map +1 -0
  58. package/dist/esm/{chunk-G37LGM6P.js → chunk-AJRQEL5N.js} +6 -6
  59. package/dist/esm/{chunk-KMQX6T56.js → chunk-EUUW7J3S.js} +8 -8
  60. package/dist/esm/chunk-EUUW7J3S.js.map +1 -0
  61. package/dist/esm/{chunk-A65XRRHY.js → chunk-GDA6Z5AL.js} +11 -15
  62. package/dist/esm/chunk-GDA6Z5AL.js.map +1 -0
  63. package/dist/esm/{chunk-LJVVSUF7.js → chunk-MJEPJ62P.js} +15 -40
  64. package/dist/esm/chunk-MJEPJ62P.js.map +1 -0
  65. package/dist/esm/{chunk-2RW77MJB.js → chunk-PUUZRUE6.js} +47 -25
  66. package/dist/esm/chunk-PUUZRUE6.js.map +1 -0
  67. package/dist/esm/chunk-QHWDMU43.js +40 -0
  68. package/dist/esm/chunk-QHWDMU43.js.map +1 -0
  69. package/dist/esm/chunk-RL6SRSSK.js +45 -0
  70. package/dist/esm/chunk-RL6SRSSK.js.map +1 -0
  71. package/dist/esm/chunk-RNA32QWV.js +128 -0
  72. package/dist/esm/chunk-RNA32QWV.js.map +1 -0
  73. package/dist/esm/{chunk-HOFAK5J2.js → chunk-TV2GJAEH.js} +4 -4
  74. package/dist/esm/chunk-TV2GJAEH.js.map +1 -0
  75. package/dist/esm/{chunk-PHKK5NHK.js → chunk-VNQCUGC3.js} +1 -1
  76. package/dist/esm/chunk-VNQCUGC3.js.map +1 -0
  77. package/dist/esm/{chunk-FL3JRQM4.js → chunk-ZBUAT73P.js} +1 -1
  78. package/dist/esm/{chunk-FL3JRQM4.js.map → chunk-ZBUAT73P.js.map} +1 -1
  79. package/dist/esm/controllers/a2a.controller.d.ts +4 -2
  80. package/dist/esm/controllers/api/{thread.api.controller.d.ts → threads.api.controller.d.ts} +2 -0
  81. package/dist/esm/controllers/api/threads.api.controller.js +7 -0
  82. package/dist/esm/controllers/index.d.ts +6 -4
  83. package/dist/esm/controllers/index.js +5 -5
  84. package/dist/esm/controllers/query.controller.d.ts +4 -2
  85. package/dist/esm/controllers/query.controller.js +2 -2
  86. package/dist/esm/index.d.ts +3 -2
  87. package/dist/esm/index.js +66 -27
  88. package/dist/esm/index.js.map +1 -1
  89. package/dist/esm/middlewares/auth.middleware.js +2 -2
  90. package/dist/esm/modules/a2a/a2a.module.d.ts +2 -9
  91. package/dist/esm/modules/a2a/a2a.module.js +1 -1
  92. package/dist/esm/modules/index.d.ts +2 -0
  93. package/dist/esm/modules/index.js +3 -3
  94. package/dist/esm/modules/mcp/mcp.module.d.ts +8 -14
  95. package/dist/esm/modules/mcp/mcp.module.js +1 -1
  96. package/dist/esm/modules/memory/base.memory.d.ts +3 -3
  97. package/dist/esm/modules/models/model.module.d.ts +17 -0
  98. package/dist/esm/modules/models/model.module.js +1 -1
  99. package/dist/esm/routes/a2a.routes.d.ts +2 -0
  100. package/dist/esm/routes/a2a.routes.js +3 -3
  101. package/dist/esm/routes/api/threads.routes.js +9 -0
  102. package/dist/esm/routes/api.routes.d.ts +2 -0
  103. package/dist/esm/routes/api.routes.js +4 -4
  104. package/dist/esm/routes/index.d.ts +3 -1
  105. package/dist/esm/routes/index.js +12 -12
  106. package/dist/esm/routes/query.routes.d.ts +2 -0
  107. package/dist/esm/routes/query.routes.js +5 -5
  108. package/dist/esm/services/a2a.service.d.ts +6 -4
  109. package/dist/esm/services/a2a.service.js +1 -1
  110. package/dist/esm/services/index.d.ts +2 -0
  111. package/dist/esm/services/index.js +7 -7
  112. package/dist/esm/services/query-stream.service.d.ts +15 -10
  113. package/dist/esm/services/query-stream.service.js +1 -1
  114. package/dist/esm/services/query.service.d.ts +9 -4
  115. package/dist/esm/services/query.service.js +1 -1
  116. package/dist/esm/types/agent.d.ts +0 -2
  117. package/dist/esm/types/agent.js +1 -1
  118. package/dist/esm/types/mcp.d.ts +15 -1
  119. package/dist/esm/types/stream.d.ts +2 -0
  120. package/package.json +9 -4
  121. package/dist/cjs/chunk-55IME4BG.cjs.map +0 -1
  122. package/dist/cjs/chunk-6YVTJEMQ.cjs.map +0 -1
  123. package/dist/cjs/chunk-BBCZU5VZ.cjs +0 -17
  124. package/dist/cjs/chunk-BBCZU5VZ.cjs.map +0 -1
  125. package/dist/cjs/chunk-CYW6ICAW.cjs +0 -106
  126. package/dist/cjs/chunk-CYW6ICAW.cjs.map +0 -1
  127. package/dist/cjs/chunk-EAK7MP6X.cjs.map +0 -1
  128. package/dist/cjs/chunk-JXKLEQD6.cjs.map +0 -1
  129. package/dist/cjs/chunk-KE7SL3H6.cjs.map +0 -1
  130. package/dist/cjs/chunk-KRLUWTLN.cjs +0 -35
  131. package/dist/cjs/chunk-KRLUWTLN.cjs.map +0 -1
  132. package/dist/cjs/chunk-LRBRG2DS.cjs.map +0 -1
  133. package/dist/cjs/chunk-QWASSVCU.cjs.map +0 -1
  134. package/dist/cjs/chunk-ZZK4ACTV.cjs.map +0 -1
  135. package/dist/cjs/controllers/api/thread.api.controller.cjs +0 -8
  136. package/dist/cjs/controllers/api/thread.api.controller.cjs.map +0 -1
  137. package/dist/cjs/routes/api/thread.routes.cjs +0 -9
  138. package/dist/cjs/routes/api/thread.routes.cjs.map +0 -1
  139. package/dist/esm/chunk-2RW77MJB.js.map +0 -1
  140. package/dist/esm/chunk-A65XRRHY.js.map +0 -1
  141. package/dist/esm/chunk-ADIAIRNH.js +0 -35
  142. package/dist/esm/chunk-ADIAIRNH.js.map +0 -1
  143. package/dist/esm/chunk-BDMVIJPF.js +0 -106
  144. package/dist/esm/chunk-BDMVIJPF.js.map +0 -1
  145. package/dist/esm/chunk-HOFAK5J2.js.map +0 -1
  146. package/dist/esm/chunk-KMQX6T56.js.map +0 -1
  147. package/dist/esm/chunk-LJVVSUF7.js.map +0 -1
  148. package/dist/esm/chunk-M4EJC7LZ.js.map +0 -1
  149. package/dist/esm/chunk-PHKK5NHK.js.map +0 -1
  150. package/dist/esm/chunk-PN6NMQBM.js.map +0 -1
  151. package/dist/esm/chunk-VA3XOZBV.js +0 -17
  152. package/dist/esm/chunk-VA3XOZBV.js.map +0 -1
  153. package/dist/esm/controllers/api/thread.api.controller.js +0 -8
  154. package/dist/esm/routes/api/thread.routes.js +0 -9
  155. /package/dist/esm/{chunk-7D4SKPIS.js.map → chunk-4C2TLCWI.js.map} +0 -0
  156. /package/dist/esm/{chunk-G37LGM6P.js.map → chunk-AJRQEL5N.js.map} +0 -0
  157. /package/dist/esm/controllers/api/{thread.api.controller.js.map → threads.api.controller.js.map} +0 -0
  158. /package/dist/esm/routes/api/{thread.routes.d.ts → threads.routes.d.ts} +0 -0
  159. /package/dist/esm/routes/api/{thread.routes.js.map → threads.routes.js.map} +0 -0
@@ -1,106 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
-
3
- var _chunkE433ONENcjs = require('./chunk-E433ONEN.cjs');
4
-
5
-
6
- var _chunk466ED5WNcjs = require('./chunk-466ED5WN.cjs');
7
-
8
- // src/modules/mcp/mcp.module.ts
9
- var _indexjs = require('@modelcontextprotocol/sdk/client/index.js');
10
- var _stdiojs = require('@modelcontextprotocol/sdk/client/stdio.js');
11
- var MCPModule = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this); }
12
- /** Map of MCP server names to their client instances */
13
- __init() {this.mcpMap = /* @__PURE__ */ new Map()}
14
- /** Map of MCP server names to their transport instances */
15
- __init2() {this.transportMap = /* @__PURE__ */ new Map()}
16
- /** Array of all discovered tools from connected MCP servers */
17
- __init3() {this.tools = []}
18
- /**
19
- * Connects to MCP servers based on the provided configuration.
20
- *
21
- * For each server in the config, establishes a connection, discovers
22
- * available tools, and adds them to the module's tool collection.
23
- * Skips servers that are already connected.
24
- *
25
- * @param mcpConfig - Configuration object mapping server names to connection details
26
- * @throws Error if connection to any MCP server fails
27
- */
28
- async addMCPConfig(mcpConfig) {
29
- try {
30
- for (const [name, conf] of Object.entries(mcpConfig)) {
31
- if (this.mcpMap.get(name) && this.transportMap.get(name)) continue;
32
- const transport = new (0, _stdiojs.StdioClientTransport)(conf);
33
- this.transportMap.set(name, transport);
34
- const mcp = new (0, _indexjs.Client)({ name: "mcp-client-cli", version: "1.0.0" });
35
- await mcp.connect(transport);
36
- this.mcpMap.set(name, mcp);
37
- const toolsResult = await mcp.listTools();
38
- this.tools.push(
39
- ...toolsResult.tools.map((tool) => {
40
- return new (0, _chunkE433ONENcjs.MCPTool)(name, tool);
41
- })
42
- );
43
- }
44
- _chunk466ED5WNcjs.loggers.mcp.info("Connected to MCP server with tools:", {
45
- tools: this.tools.map((tool) => tool.id)
46
- });
47
- } catch (error) {
48
- _chunk466ED5WNcjs.loggers.mcp.error("Failed to connect to MCP server:", { error });
49
- throw error;
50
- }
51
- }
52
- /**
53
- * Returns all available tools from connected MCP servers.
54
- *
55
- * @returns Array of MCPTool instances representing available tools
56
- */
57
- getTools() {
58
- return this.tools;
59
- }
60
- /**
61
- * Executes a tool on its corresponding MCP server.
62
- *
63
- * @param tool - The MCPTool instance to execute
64
- * @param _args - Arguments to pass to the tool
65
- * @returns Promise resolving to the tool's execution result
66
- * @throws Error if the MCP server for the tool is not found
67
- */
68
- async useTool(tool, _args) {
69
- const { serverName, mcpTool } = tool;
70
- const toolName = mcpTool.name;
71
- const mcp = this.mcpMap.get(serverName);
72
- try {
73
- if (!mcp) {
74
- throw new Error(`Invalid MCP Tool ${serverName}-${mcpTool.name}`);
75
- }
76
- const result = await mcp.callTool({
77
- name: toolName,
78
- arguments: _args
79
- });
80
- const toolResult = `[Bot Called Tool ${toolName} with args ${JSON.stringify(_args)}]
81
- ` + JSON.stringify(result.content, null, 2);
82
- return toolResult;
83
- } catch (error) {
84
- _chunk466ED5WNcjs.loggers.mcp.error("Failed to call tool", { error });
85
- const toolResult = `[Bot Called Tool ${toolName} with args ${JSON.stringify(_args)}]
86
- ${typeof error === "string" ? error : JSON.stringify(error, null, 2)}`;
87
- return toolResult;
88
- }
89
- }
90
- /**
91
- * Closes all MCP client connections.
92
- *
93
- * Should be called when shutting down the application to ensure
94
- * all MCP connections are properly closed.
95
- */
96
- async cleanup() {
97
- this.mcpMap.forEach((mcp) => {
98
- mcp.close();
99
- });
100
- }
101
- }, _class);
102
-
103
-
104
-
105
- exports.MCPModule = MCPModule;
106
- //# sourceMappingURL=chunk-CYW6ICAW.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-CYW6ICAW.cjs","../../src/modules/mcp/mcp.module.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACPA,oEAAuB;AACvB,oEAAqC;AA0B9B,IAAM,UAAA,YAAN,MAAgB;AAAA;AAAA,iBAEd,OAAA,kBAA8B,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA,kBAEtC,aAAA,kBAAkD,IAAI,GAAA,CAAI,EAAA;AAAA;AAAA,kBAE1D,MAAA,EAAmB,CAAC,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAY5B,MAAM,YAAA,CAAa,SAAA,EAAsB;AACxC,IAAA,IAAI;AACH,MAAA,IAAA,CAAA,MAAW,CAAC,IAAA,EAAM,IAAI,EAAA,GAAK,MAAA,CAAO,OAAA,CAAQ,SAAS,CAAA,EAAG;AAErD,QAAA,GAAA,CAAI,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,IAAI,EAAA,GAAK,IAAA,CAAK,YAAA,CAAa,GAAA,CAAI,IAAI,CAAA,EAAG,QAAA;AAE1D,QAAA,MAAM,UAAA,EAAY,IA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,MAAM,EAAE,UAAA,EAAY,QAAQ,EAAA,EAAI,IAAA;AAChC,IAAA,MAAM,SAAA,EAAW,OAAA,CAAQ,IAAA;AACzB,IAAA,MAAM,IAAA,EAAM,IAAA,CAAK,MAAA,CAAO,GAAA,CAAI,UAAU,CAAA;AAEtC,IAAA,IAAI;AACH,MAAA,GAAA,CAAI,CAAC,GAAA,EAAK;AACT,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,iBAAA,EAAoB,UAAU,CAAA,CAAA,EAAI,OAAA,CAAQ,IAAI,CAAA,CAAA;AAC/D,MAAA;AAEkC,MAAA;AAC3B,QAAA;AACK,QAAA;AACX,MAAA;AAE0C,MAAA;AACJ;AAChC,MAAA;AACQ,IAAA;AACmC,MAAA;AACW,MAAA;AAA6F;AACnJ,MAAA;AACR,IAAA;AACD,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQgB,EAAA;AACsB,IAAA;AAC1B,MAAA;AACV,IAAA;AACF,EAAA;AACD;ADzBuE;AACA;AACA;AACA","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-CYW6ICAW.cjs","sourcesContent":[null,"import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StdioClientTransport } from \"@modelcontextprotocol/sdk/client/stdio.js\";\nimport type { MCPConfig } from \"@/types/mcp.js\";\nimport { loggers } from \"@/utils/logger.js\";\nimport { MCPTool } from \"./mcp.tool.js\";\n\n/**\n * Module for managing Model Context Protocol (MCP) server connections.\n *\n * This module handles the lifecycle of MCP client connections, discovers\n * available tools from connected servers, and provides an interface for\n * executing those tools. Multiple MCP servers can be connected simultaneously.\n *\n * @example\n * ```typescript\n * const mcpModule = new MCPModule();\n * await mcpModule.addMCPConfig({\n * \"filesystem\": {\n * command: \"npx\",\n * args: [\"@modelcontextprotocol/server-filesystem\", \"/path/to/files\"]\n * }\n * });\n *\n * const tools = mcpModule.getTools();\n * const result = await mcpModule.useTool(tools[0], { path: \"/example.txt\" });\n * ```\n */\nexport class MCPModule {\n\t/** Map of MCP server names to their client instances */\n\tprivate mcpMap: Map<string, Client> = new Map();\n\t/** Map of MCP server names to their transport instances */\n\tprivate transportMap: Map<string, StdioClientTransport> = new Map();\n\t/** Array of all discovered tools from connected MCP servers */\n\tprivate tools: MCPTool[] = [];\n\n\t/**\n\t * Connects to MCP servers based on the provided configuration.\n\t *\n\t * For each server in the config, establishes a connection, discovers\n\t * available tools, and adds them to the module's tool collection.\n\t * Skips servers that are already connected.\n\t *\n\t * @param mcpConfig - Configuration object mapping server names to connection details\n\t * @throws Error if connection to any MCP server fails\n\t */\n\tasync addMCPConfig(mcpConfig: MCPConfig) {\n\t\ttry {\n\t\t\tfor (const [name, conf] of Object.entries(mcpConfig)) {\n\t\t\t\t// FIXME(yoojin): Need strict duplication check.\n\t\t\t\tif (this.mcpMap.get(name) && this.transportMap.get(name)) continue; // Duplicated mcp: skip\n\n\t\t\t\tconst transport = new StdioClientTransport(conf);\n\t\t\t\tthis.transportMap.set(name, transport);\n\t\t\t\tconst mcp = new Client({ name: \"mcp-client-cli\", version: \"1.0.0\" });\n\t\t\t\tawait mcp.connect(transport);\n\t\t\t\tthis.mcpMap.set(name, mcp);\n\n\t\t\t\tconst toolsResult = await mcp.listTools();\n\t\t\t\tthis.tools.push(\n\t\t\t\t\t...toolsResult.tools.map((tool) => {\n\t\t\t\t\t\treturn new MCPTool(name, tool);\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tloggers.mcp.info(\"Connected to MCP server with tools:\", {\n\t\t\t\ttools: this.tools.map((tool) => tool.id),\n\t\t\t});\n\t\t} catch (error: unknown) {\n\t\t\tloggers.mcp.error(\"Failed to connect to MCP server:\", { error });\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Returns all available tools from connected MCP servers.\n\t *\n\t * @returns Array of MCPTool instances representing available tools\n\t */\n\tgetTools() {\n\t\treturn this.tools;\n\t}\n\n\t/**\n\t * Executes a tool on its corresponding MCP server.\n\t *\n\t * @param tool - The MCPTool instance to execute\n\t * @param _args - Arguments to pass to the tool\n\t * @returns Promise resolving to the tool's execution result\n\t * @throws Error if the MCP server for the tool is not found\n\t */\n\tasync useTool(tool: MCPTool, _args?: any): Promise<string> {\n\t\tconst { serverName, mcpTool } = tool;\n\t\tconst toolName = mcpTool.name;\n\t\tconst mcp = this.mcpMap.get(serverName);\n\n\t\ttry {\n\t\t\tif (!mcp) {\n\t\t\t\tthrow new Error(`Invalid MCP Tool ${serverName}-${mcpTool.name}`);\n\t\t\t}\n\n\t\t\tconst result = await mcp.callTool({\n\t\t\t\tname: toolName,\n\t\t\t\targuments: _args,\n\t\t\t});\n\t\t\tconst toolResult =\n\t\t\t\t`[Bot Called Tool ${toolName} with args ${JSON.stringify(_args)}]\\n` +\n\t\t\t\tJSON.stringify(result.content, null, 2);\n\t\t\treturn toolResult;\n\t\t} catch (error) {\n\t\t\tloggers.mcp.error(\"Failed to call tool\", { error });\n\t\t\tconst toolResult = `[Bot Called Tool ${toolName} with args ${JSON.stringify(_args)}]\\n${typeof error === \"string\" ? error : JSON.stringify(error, null, 2)}`;\n\t\t\treturn toolResult;\n\t\t}\n\t}\n\n\t/**\n\t * Closes all MCP client connections.\n\t *\n\t * Should be called when shutting down the application to ensure\n\t * all MCP connections are properly closed.\n\t */\n\tasync cleanup() {\n\t\tthis.mcpMap.forEach((mcp: Client) => {\n\t\t\tmcp.close();\n\t\t});\n\t}\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-EAK7MP6X.cjs","../../src/routes/api.routes.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACPA,kCAAuB;AAMhB,IAAM,gBAAA,EAAkB,CAAC,KAAA,EAAA,GAA4B;AAC3D,EAAA,MAAM,OAAA,EAAS,6BAAA,CAAO;AAEtB,EAAA,MAAA,CAAO,GAAA,CAAI,YAAA,EAAc,oDAAA,KAAqB,CAAM,WAAW,CAAC,CAAA;AAChE,EAAA,GAAA,CAAI,KAAA,CAAM,YAAA,EAAc;AACvB,IAAA,MAAA,CAAO,GAAA,CAAI,aAAA,EAAe,qDAAA,KAAsB,CAAM,YAAY,CAAC,CAAA;AAAA,EACpE;AAEA,EAAA,OAAO,MAAA;AACR,CAAA;ADEA;AACA;AACE;AACF,0CAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-EAK7MP6X.cjs","sourcesContent":[null,"import { Router } from \"express\";\nimport type { AINAgent } from \"@/index.js\";\n\nimport { createModelApiRouter } from \"./api/model.routes.js\";\nimport { createThreadApiRouter } from \"./api/thread.routes.js\";\n\nexport const createApiRouter = (agent: AINAgent): Router => {\n\tconst router = Router();\n\n\trouter.use(\"/api/model\", createModelApiRouter(agent.modelModule));\n\tif (agent.memoryModule) {\n\t\trouter.use(\"/api/thread\", createThreadApiRouter(agent.memoryModule));\n\t}\n\n\treturn router;\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-JXKLEQD6.cjs","../../src/routes/a2a.routes.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACVA,4CAAkC;AAClC,kCAAuB;AAchB,IAAM,gBAAA,EAAkB,CAAC,KAAA,EAAA,GAA4B;AAC3D,EAAA,MAAM,OAAA,EAAS,6BAAA,CAAO;AAGtB,EAAA,MAAM,UAAA,EAAY,IAAI,8BAAA,CAAkB,CAAA;AACxC,EAAA,MAAM,aAAA,EAAe,IAAI,mCAAA;AAAA,IACxB,KAAA,CAAM,WAAA;AAAA,IACN,KAAA,CAAM,SAAA;AAAA,IACN,KAAA,CAAM,SAAA;AAAA,IACN,KAAA,CAAM,YAAA;AAAA,IACN,KAAA,CAAM,QAAA,CAAS;AAAA,EAChB,CAAA;AACA,EAAA,MAAM,WAAA,EAAa,IAAI,iCAAA,CAAW,YAAY,CAAA;AAC9C,EAAA,MAAM,cAAA,EAAgB,IAAI,oCAAA;AAAA,IACzB,UAAA;AAAA,IACA,SAAA;AAAA,IACA,KAAA,CAAM;AAAA,EACP,CAAA;AAGA,EAAA,MAAA,CAAO,IAAA,CAAK,GAAA,EAAK,aAAA,CAAc,gBAAgB,CAAA;AAE/C,EAAA,OAAO,MAAA;AACR,CAAA;ADNA;AACA;AACE;AACF,0CAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-JXKLEQD6.cjs","sourcesContent":[null,"import { InMemoryTaskStore } from \"@a2a-js/sdk/server\";\nimport { Router } from \"express\";\nimport type { AINAgent } from \"@/index.js\";\nimport { QueryService } from \"@/services/query.service.js\";\nimport { A2AController } from \"../controllers/a2a.controller.js\";\nimport { A2AService } from \"../services/a2a.service.js\";\n\n/**\n * Creates and configures the A2A router.\n * This function is a \"composition root\" for the A2A feature,\n * creating and injecting all necessary dependencies.\n * @param intentAnalyzer The core intent analyzer.\n * @param agentCard The agent's card.\n * @returns An Express Router instance.\n */\nexport const createA2ARouter = (agent: AINAgent): Router => {\n\tconst router = Router();\n\n\t// 1. Create dependencies for the A2A feature\n\tconst taskStore = new InMemoryTaskStore();\n\tconst queryService = new QueryService(\n\t\tagent.modelModule,\n\t\tagent.a2aModule,\n\t\tagent.mcpModule,\n\t\tagent.memoryModule,\n\t\tagent.manifest.prompts,\n\t);\n\tconst a2aService = new A2AService(queryService);\n\tconst a2aController = new A2AController(\n\t\ta2aService,\n\t\ttaskStore,\n\t\tagent.generateAgentCard,\n\t);\n\n\t// 2. Define the route\n\trouter.post(\"/\", a2aController.handleA2ARequest);\n\n\treturn router;\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-KE7SL3H6.cjs","../../src/services/query.service.ts"],"names":["intent"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AA;AAChB,MAAA;AAEkB,MAAA;AACnB,IAAA;AAEoB,IAAA;AACW,MAAA;AACpB,MAAA;AACX,IAAA;AAEO,IAAA;AACR,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAS4D,EAAA;AACrC,IAAA;AAClB,IAAA;AAC6C,MAAA;AACA,MAAA;AAC/C,QAAA;AACc,QAAA;AAAA;AAAA;AAAA,oFAAA;AAId,MAAA;AACkD,MAAA;AACxB,MAAA;AACZ,IAAA;AACgC,MAAA;AAC9C,QAAA;AACA,QAAA;AACA,MAAA;AACM,MAAA;AACR,IAAA;AACD,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBE,EAAA;AAEwB,IAAA;AACK,IAAA;AAC0B,IAAA;AAE1B,IAAA;AAC1B,IAAA;AAEU,IAAA;AACgD,MAAA;AACvD,IAAA;AACgB,MAAA;AACsB,MAAA;AAI1C,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACoB,QAAA;AACrB,MAAA;AACoD,MAAA;AACtD,IAAA;AAGwD,IAAA;AAGkB,IAAA;AAChB,IAAA;AACzD,MAAA;AACC,QAAA;AACW,QAAA;AAC6B,QAAA;AACzC,MAAA;AACA,MAAA;AACC,QAAA;AACoB,QAAA;AAC8B,QAAA;AACnD,MAAA;AACA,IAAA;AAEiC,IAAA;AACnC,EAAA;AACD;ADhH0F;AACA;AACA;AACA","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-KE7SL3H6.cjs","sourcesContent":[null,"import { randomUUID } from \"node:crypto\";\nimport type {\n\tA2AModule,\n\tMCPModule,\n\tMemoryModule,\n\tModelModule,\n} from \"@/modules/index.js\";\nimport type { AinAgentPrompts } from \"@/types/agent.js\";\nimport {\n\ttype Intent,\n\tMessageRole,\n\ttype ThreadMetadata,\n\ttype ThreadObject,\n\ttype ThreadType,\n} from \"@/types/memory.js\";\nimport {\n\ttype IA2ATool,\n\ttype IAgentTool,\n\ttype IMCPTool,\n\tTOOL_PROTOCOL_TYPE,\n} from \"@/types/tool.js\";\nimport { loggers } from \"@/utils/logger.js\";\n\n/**\n * Service for processing user queries through the agent's AI pipeline.\n *\n * Orchestrates the query processing workflow including intent detection,\n * model inference, tool execution, and response generation. Manages\n * conversation context and coordinates between different modules.\n */\nexport class QueryService {\n\tprivate modelModule: ModelModule;\n\tprivate a2aModule?: A2AModule;\n\tprivate mcpModule?: MCPModule;\n\tprivate memoryModule?: MemoryModule;\n\tprivate prompts?: AinAgentPrompts;\n\n\tconstructor(\n\t\tmodelModule: ModelModule,\n\t\ta2aModule?: A2AModule,\n\t\tmcpModule?: MCPModule,\n\t\tmemoryModule?: MemoryModule,\n\t\tprompts?: AinAgentPrompts,\n\t) {\n\t\tthis.modelModule = modelModule;\n\t\tthis.a2aModule = a2aModule;\n\t\tthis.mcpModule = mcpModule;\n\t\tthis.memoryModule = memoryModule;\n\t\tthis.prompts = prompts;\n\t}\n\n\t/**\n\t * Detects the intent from context.\n\t *\n\t * @param query - The user's input query\n\t * @param thread - The thread history\n\t * @returns The detected intent\n\t */\n\tprivate async intentTriggering(\n\t\tquery: string,\n\t\tthread: ThreadObject | undefined,\n\t): Promise<Intent | undefined> {\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst intentMemory = this.memoryModule?.getIntentMemory();\n\t\tif (!intentMemory) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// 인텐트 목록 가져오기\n\t\tconst intents = await intentMemory.listIntents();\n\n\t\tif (intents.length === 0) {\n\t\t\tloggers.intent.warn(\"No intent found\");\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst intentList = intents\n\t\t\t.map((intent) => `- ${intent.name}: ${intent.description}`)\n\t\t\t.join(\"\\n\");\n\n\t\t// Convert session history to a string\n\t\tconst historyMessages = !thread\n\t\t\t? \"\"\n\t\t\t: Object.entries(thread.messages)\n\t\t\t\t\t.sort(([, a], [, b]) => a.timestamp - b.timestamp)\n\t\t\t\t\t.map(([chatId, chat]) => {\n\t\t\t\t\t\tconst role =\n\t\t\t\t\t\t\tchat.role === \"USER\"\n\t\t\t\t\t\t\t\t? \"User\"\n\t\t\t\t\t\t\t\t: chat.role === \"MODEL\"\n\t\t\t\t\t\t\t\t\t? \"Assistant\"\n\t\t\t\t\t\t\t\t\t: \"System\";\n\t\t\t\t\t\tconst content = Array.isArray(chat.content.parts)\n\t\t\t\t\t\t\t? chat.content.parts.join(\" \")\n\t\t\t\t\t\t\t: String(chat.content.parts);\n\t\t\t\t\t\treturn `${role}: \"\"\"${content}\"\"\"`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\");\n\n\t\tconst systemPrompt = `You are an expert in accurately identifying user intentions.\n\nAvailable intent list:\n${intentList}\n\nPlease select and answer only from the above intent list. \nPlease return only the exact intent name without any additional explanations or text.`;\n\n\t\tconst userMessage = `The following is the conversation history with the user:\n\n${historyMessages}\n\nLast user question: \"${query}\"\n\nBased on the above conversation history, please determine what the intention of the last user question is. \nPlease select and answer the most appropriate intent name from the available intent list.`;\n\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery: userMessage,\n\t\t\tsystemPrompt,\n\t\t});\n\n\t\tconst response = await modelInstance.fetch(messages);\n\t\tif (!response.content) {\n\t\t\tthrow new Error(\"No intent detected\");\n\t\t}\n\t\tconst intentName = response.content.trim();\n\t\tconst intent = await intentMemory.getIntentByName(intentName);\n\t\tif (!intent) {\n\t\t\tthrow new Error(`No intent found: ${intentName}`);\n\t\t}\n\t\treturn intent;\n\t}\n\n\t/**\n\t * Fulfills the detected intent by generating a response.\n\t *\n\t * Manages the complete inference loop including:\n\t * - Loading prompts and conversation history\n\t * - Collecting available tools from modules\n\t * - Executing model inference with tool support\n\t * - Processing tool calls iteratively until completion\n\t *\n\t * @param query - The user's input query\n\t * @param threadId - Thread identifier for context\n\t * @param thread - Previous conversation history\n\t * @returns Object containing process steps and final response\n\t */\n\tprivate async intentFulfilling(\n\t\tquery: string,\n\t\tthreadId: string,\n\t\tthread?: ThreadObject,\n\t\tintent?: Intent,\n\t) {\n\t\t// 1. Load agent / system prompt from memory\n\t\tconst systemPrompt = `\nToday is ${new Date().toLocaleDateString()}.\n\n${this.prompts?.agent || \"\"}\n\n${this.prompts?.system || \"\"}\n\n${intent?.prompt || \"\"}\n `;\n\t\t// NOTE(haechan@comcom.ai):\n\t\t// When the `intent.llm` is guaranteed to be consistent, it will be used as a parameter for getModel\n\t\t// const model_name = intent?.llm || \"gpt-4o\";\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery,\n\t\t\tthread,\n\t\t\tsystemPrompt: systemPrompt.trim(),\n\t\t});\n\n\t\tconst tools: IAgentTool[] = [];\n\t\tif (this.mcpModule) {\n\t\t\ttools.push(...this.mcpModule.getTools());\n\t\t}\n\t\tif (this.a2aModule) {\n\t\t\ttools.push(...(await this.a2aModule.getTools()));\n\t\t}\n\t\tconst functions = modelInstance.convertToolsToFunctions(tools);\n\n\t\tconst processList: string[] = [];\n\t\tlet finalMessage = \"\";\n\t\tlet didCallTool = false;\n\n\t\twhile (true) {\n\t\t\tconst response = await modelInstance.fetchWithContextMessage(\n\t\t\t\tmessages,\n\t\t\t\tfunctions,\n\t\t\t);\n\t\t\tdidCallTool = false;\n\n\t\t\tloggers.intent.debug(\"messages\", { messages });\n\n\t\t\tconst { content, toolCalls } = response;\n\n\t\t\tloggers.intent.debug(\"content\", { content });\n\t\t\tloggers.intent.debug(\"tool_calls\", { ...toolCalls });\n\n\t\t\tif (toolCalls) {\n\t\t\t\tconst messagePayload = this.a2aModule?.getMessagePayload(\n\t\t\t\t\tquery,\n\t\t\t\t\tthreadId,\n\t\t\t\t);\n\n\t\t\t\tfor (const toolCall of toolCalls) {\n\t\t\t\t\tconst toolName = toolCall.name;\n\t\t\t\t\tdidCallTool = true;\n\t\t\t\t\tconst selectedTool = tools.filter((tool) => tool.id === toolName)[0];\n\n\t\t\t\t\tlet toolResult = \"\";\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.mcpModule &&\n\t\t\t\t\t\tselectedTool.protocol === TOOL_PROTOCOL_TYPE.MCP\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst toolArgs = toolCall.arguments as\n\t\t\t\t\t\t\t| { [x: string]: unknown }\n\t\t\t\t\t\t\t| undefined;\n\t\t\t\t\t\tloggers.intent.debug(\"MCP tool call\", { toolName, toolArgs });\n\t\t\t\t\t\ttoolResult = await this.mcpModule.useTool(\n\t\t\t\t\t\t\tselectedTool as IMCPTool,\n\t\t\t\t\t\t\ttoolArgs,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tthis.a2aModule &&\n\t\t\t\t\t\tselectedTool.protocol === TOOL_PROTOCOL_TYPE.A2A\n\t\t\t\t\t) {\n\t\t\t\t\t\ttoolResult = await this.a2aModule.useTool(\n\t\t\t\t\t\t\tselectedTool as IA2ATool,\n\t\t\t\t\t\t\tmessagePayload!,\n\t\t\t\t\t\t\tthreadId,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Unrecognized tool type. It cannot be happened...\n\t\t\t\t\t\tloggers.intent.warn(\n\t\t\t\t\t\t\t`Unrecognized tool type: ${selectedTool.protocol}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tloggers.intent.debug(\"toolResult\", { toolResult });\n\n\t\t\t\t\tprocessList.push(toolResult);\n\t\t\t\t\tmodelInstance.appendMessages(messages, toolResult);\n\t\t\t\t}\n\t\t\t} else if (content) {\n\t\t\t\tprocessList.push(content);\n\t\t\t\tfinalMessage = content;\n\t\t\t}\n\n\t\t\tif (!didCallTool) break;\n\t\t}\n\n\t\tconst botResponse = {\n\t\t\tprocess: processList.join(\"\\n\"),\n\t\t\tresponse: finalMessage,\n\t\t};\n\n\t\treturn botResponse;\n\t}\n\n\t/**\n\t * Generates a title for the conversation based on the query.\n\t *\n\t * @param query - The user's input query\n\t * @returns Promise resolving to a generated title\n\t */\n\n\tprivate async generateTitle(query: string): Promise<string> {\n\t\tconst DEFAULT_TITLE = \"New Chat\";\n\t\ttry {\n\t\t\tconst modelInstance = this.modelModule.getModel();\n\t\t\tconst messages = modelInstance.generateMessages({\n\t\t\t\tquery,\n\t\t\t\tsystemPrompt: `You are a helpful assistant that generates titles for conversations.\n Please analyze the user's query and create a concise title that accurately reflects the conversation's core topic.\n The title must be no more than 5 words long.\n Respond with only the title. Do not include any punctuation or extra explanations.`,\n\t\t\t});\n\t\t\tconst response = await modelInstance.fetch(messages);\n\t\t\treturn response.content || DEFAULT_TITLE;\n\t\t} catch (error) {\n\t\t\tloggers.intent.error(\"Error generating title\", {\n\t\t\t\terror,\n\t\t\t\tquery,\n\t\t\t});\n\t\t\treturn DEFAULT_TITLE;\n\t\t}\n\t}\n\n\t/**\n\t * Main entry point for processing user queries.\n\t *\n\t * Handles the complete query lifecycle:\n\t * 1. Loads thread history from memory\n\t * 2. Detects intent from the query\n\t * 3. Fulfills the intent with AI response\n\t * 4. Updates conversation history\n\t *\n\t * @param type - The type of thread (e.g., chat, workflow)\n\t * @param userId - The user's unique identifier\n\t * @param threadId - Unique thread identifier\n\t * @param query - The user's input query\n\t */\n\tpublic async handleQuery(\n\t\tthreadMetadata: {\n\t\t\ttype: ThreadType;\n\t\t\tuserId: string;\n\t\t\tthreadId?: string;\n\t\t},\n\t\tquery: string,\n\t) {\n\t\t// 1. Load thread with threadId\n\t\tconst { type, userId } = threadMetadata;\n\t\tconst queryStartAt = Date.now();\n\t\tconst threadMemory = this.memoryModule?.getThreadMemory();\n\n\t\tlet threadId = threadMetadata.threadId;\n\t\tlet thread: ThreadObject | undefined;\n\n\t\tif (threadId) {\n\t\t\tthread = await threadMemory?.getThread(type, userId, threadId);\n\t\t} else {\n\t\t\tthreadId = randomUUID();\n\t\t\tconst title = await this.generateTitle(query);\n\n\t\t\tconst metadata =\n\t\t\t\t(await threadMemory?.createThread(type, userId, threadId, title)) ||\n\t\t\t\t({\n\t\t\t\t\ttype,\n\t\t\t\t\tthreadId,\n\t\t\t\t\ttitle,\n\t\t\t\t\tupdatedAt: Date.now(),\n\t\t\t\t} as ThreadMetadata);\n\t\t\tloggers.intent.info(\"Create new thread\", { metadata });\n\t\t}\n\n\t\t// 2. intent triggering\n\t\tconst intent = await this.intentTriggering(query, thread);\n\n\t\t// 3. intent fulfillment\n\t\tconst result = await this.intentFulfilling(query, threadId, thread, intent);\n\t\tawait threadMemory?.addMessagesToThread(userId, threadId, [\n\t\t\t{\n\t\t\t\trole: MessageRole.USER,\n\t\t\t\ttimestamp: queryStartAt,\n\t\t\t\tcontent: { type: \"text\", parts: [query] },\n\t\t\t},\n\t\t\t{\n\t\t\t\trole: MessageRole.MODEL,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\tcontent: { type: \"text\", parts: [result.response] },\n\t\t\t},\n\t\t]);\n\n\t\treturn { content: result.response };\n\t}\n}\n"]}
@@ -1,35 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;
2
-
3
- var _chunkDX2JH3FJcjs = require('./chunk-DX2JH3FJ.cjs');
4
-
5
- // src/controllers/api/thread.api.controller.ts
6
- var _httpstatuscodes = require('http-status-codes');
7
- var ThreadApiController = (_class = class {
8
-
9
- constructor(memoryModule) {;_class.prototype.__init.call(this);
10
- this.memoryModule = memoryModule;
11
- }
12
- __init() {this.handleGetThread = async (req, res, next) => {
13
- try {
14
- const { id: threadId, type } = req.params;
15
- const userId = res.locals.userId || "";
16
- const threadMemory = this.memoryModule.getThreadMemory();
17
- if (!threadMemory) {
18
- const error = new (0, _chunkDX2JH3FJcjs.AinHttpError)(
19
- _httpstatuscodes.StatusCodes.SERVICE_UNAVAILABLE,
20
- "Memory module is not initialized"
21
- );
22
- throw error;
23
- }
24
- const thread = await threadMemory.getThread(type, userId, threadId);
25
- res.json(thread);
26
- } catch (error) {
27
- next(error);
28
- }
29
- }}
30
- }, _class);
31
-
32
-
33
-
34
- exports.ThreadApiController = ThreadApiController;
35
- //# sourceMappingURL=chunk-KRLUWTLN.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-KRLUWTLN.cjs","../../src/controllers/api/thread.api.controller.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACHA,oDAA4B;AAKrB,IAAM,oBAAA,YAAN,MAA0B;AAAA,EACxB;AAAA,EAER,WAAA,CAAY,YAAA,EAA4B;AACvC,IAAA,IAAA,CAAK,aAAA,EAAe,YAAA;AAAA,EACrB;AAAA,iBAEO,gBAAA,EAAkB,MAAA,CACxB,GAAA,EACA,GAAA,EACA,IAAA,EAAA,GACI;AACJ,IAAA,IAAI;AACH,MAAA,MAAM,EAAE,EAAA,EAAI,QAAA,EAAU,KAAK,EAAA,EAAI,GAAA,CAAI,MAAA;AAInC,MAAA,MAAM,OAAA,EAAS,GAAA,CAAI,MAAA,CAAO,OAAA,GAAU,EAAA;AACpC,MAAA,MAAM,aAAA,EAAe,IAAA,CAAK,YAAA,CAAa,eAAA,CAAgB,CAAA;AACvD,MAAA,GAAA,CAAI,CAAC,YAAA,EAAc;AAClB,QAAA,MAAM,MAAA,EAAQ,IAAI,mCAAA;AAAA,UACjB,4BAAA,CAAY,mBAAA;AAAA,UACZ;AAAA,QACD,CAAA;AACA,QAAA,MAAM,KAAA;AAAA,MACP;AACA,MAAA,MAAM,OAAA,EAAS,MAAM,YAAA,CAAa,SAAA,CAAU,IAAA,EAAM,MAAA,EAAQ,QAAQ,CAAA;AAClE,MAAA,GAAA,CAAI,IAAA,CAAK,MAAM,CAAA;AAAA,IAChB,EAAA,MAAA,CAAS,KAAA,EAAO;AACf,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA,IACX;AAAA,EACD,EAAA;AACD,UAAA;ADRA;AACA;AACE;AACF,kDAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-KRLUWTLN.cjs","sourcesContent":[null,"import type { NextFunction, Request, Response } from \"express\";\nimport { StatusCodes } from \"http-status-codes\";\nimport type { MemoryModule } from \"@/modules/index.js\";\nimport { AinHttpError } from \"@/types/agent.js\";\nimport type { ThreadType } from \"@/types/memory\";\n\nexport class ThreadApiController {\n\tprivate memoryModule: MemoryModule;\n\n\tconstructor(memoryModule: MemoryModule) {\n\t\tthis.memoryModule = memoryModule;\n\t}\n\n\tpublic handleGetThread = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst { id: threadId, type } = req.params as {\n\t\t\t\tid: string;\n\t\t\t\ttype: ThreadType;\n\t\t\t};\n\t\t\tconst userId = res.locals.userId || \"\";\n\t\t\tconst threadMemory = this.memoryModule.getThreadMemory();\n\t\t\tif (!threadMemory) {\n\t\t\t\tconst error = new AinHttpError(\n\t\t\t\t\tStatusCodes.SERVICE_UNAVAILABLE,\n\t\t\t\t\t\"Memory module is not initialized\",\n\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst thread = await threadMemory.getThread(type, userId, threadId);\n\t\t\tres.json(thread);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-LRBRG2DS.cjs","../../src/middlewares/auth.middleware.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACHA,oDAA4B;AAMrB,IAAM,eAAA,EAAN,MAAqB;AAAA,EACnB;AAAA,EACR,WAAA,CAAY,IAAA,EAAgB;AAC3B,IAAA,IAAA,CAAK,KAAA,EAAO,IAAA;AAAA,EACb;AAAA,EAEO,UAAA,CAAA,EAA6B;AACnC,IAAA,OAAO,MAAA,CAAO,GAAA,EAAc,GAAA,EAAe,IAAA,EAAA,GAAuB;AACjE,MAAA,IAAI;AACH,QAAA,MAAM,QAAA,EAAwB,MAAM,IAAA,CAAK,IAAA,CAAK,YAAA,CAAa,GAAA,EAAK,GAAG,CAAA;AACnE,QAAA,GAAA,CAAI,OAAA,CAAQ,eAAA,EAAiB;AAC5B,UAAA,GAAA,CAAI,MAAA,CAAO,OAAA,EAAS,OAAA,CAAQ,MAAA;AAC5B,UAAA,IAAA,CAAK,CAAA;AAAA,QACN,EAAA,KAAO;AACN,UAAA,MAAM,MAAA,EAAsB,IAAI,mCAAA;AAAA,YAC/B,4BAAA,CAAY,YAAA;AAAA,YACZ;AAAA,UACD,CAAA;AACA,UAAA,MAAM,KAAA;AAAA,QACP;AAAA,MACD,EAAA,MAAA,CAAS,CAAA,EAAQ;AAChB,QAAA,GAAA,CAAI,CAAC,CAAA,CAAE,MAAA,EAAQ;AACd,UAAA,MAAM,MAAA,EAAsB,IAAI,mCAAA;AAAA,YAC/B,4BAAA,CAAY,qBAAA;AAAA,YACZ,CAAA,sBAAA,EAAyB,IAAA,CAAK,SAAA,CAAU,CAAC,CAAC,CAAA;AAAA,UAAA;AAE3C,UAAA;AAAM,QAAA;AAEP,QAAA;AAAM,MAAA;AACP,IAAA;AACD,EAAA;AAEF;ADDA;AACA;AACA;AACA","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-LRBRG2DS.cjs","sourcesContent":[null,"import type { NextFunction, Request, RequestHandler, Response } from \"express\";\nimport { StatusCodes } from \"http-status-codes\";\nimport type { BaseAuth } from \"@/modules/auth/base.auth\";\nimport { AinHttpError } from \"@/types/agent\";\nimport type { AuthResponse } from \"@/types/auth\";\nimport { loggers } from \"@/utils/logger\";\n\nexport class AuthMiddleware {\n\tprivate auth: BaseAuth;\n\tconstructor(auth: BaseAuth) {\n\t\tthis.auth = auth;\n\t}\n\n\tpublic middleware(): RequestHandler {\n\t\treturn async (req: Request, res: Response, next: NextFunction) => {\n\t\t\ttry {\n\t\t\t\tconst authRes: AuthResponse = await this.auth.authenticate(req, res);\n\t\t\t\tif (authRes.isAuthenticated) {\n\t\t\t\t\tres.locals.userId = authRes.userId;\n\t\t\t\t\tnext();\n\t\t\t\t} else {\n\t\t\t\t\tconst error: AinHttpError = new AinHttpError(\n\t\t\t\t\t\tStatusCodes.UNAUTHORIZED,\n\t\t\t\t\t\t\"Unauthorized\",\n\t\t\t\t\t);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t} catch (e: any) {\n\t\t\t\tif (!e.status) {\n\t\t\t\t\tconst error: AinHttpError = new AinHttpError(\n\t\t\t\t\t\tStatusCodes.INTERNAL_SERVER_ERROR,\n\t\t\t\t\t\t`Authentication error: ${JSON.stringify(e)}`,\n\t\t\t\t\t);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t};\n\t}\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-QWASSVCU.cjs","../../src/modules/models/model.module.ts"],"names":[],"mappings":"AAAA;ACkBO,IAAM,YAAA,YAAN,MAAkB;AAAA;AAAA,iBAEhB,OAAA,EAA0D,CAAC,EAAA;AAAA;AAAA,EAE3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASD,QAAA,CACN,IAAA,EACA,KAAA,EACA,SAAA,EACC;AACD,IAAA,IAAA,CAAK,MAAA,CAAO,IAAI,EAAA,EAAI,KAAA;AACpB,IAAA,GAAA,CAAI,UAAA,GAAa,CAAC,IAAA,CAAK,gBAAA,EAAkB;AACxC,MAAA,IAAA,CAAK,iBAAA,EAAmB,IAAA;AAAA,IACzB;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,QAAA,CAAS,IAAA,EAA4C;AAC3D,IAAA,GAAA,CAAI,CAAC,IAAA,CAAK,gBAAA,EAAkB;AAC3B,MAAA,MAAM,KAAA,CAAM,kBAAkB,CAAA;AAAA,IAC/B;AAEA,IAAA,GAAA,CAAI,CAAC,KAAA,GAAQ,CAAC,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA,EAAG;AAChC,MAAA,OAAO,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,gBAAgB,CAAA;AAAA,IACzC;AACA,IAAA,OAAO,IAAA,CAAK,MAAA,CAAO,IAAI,CAAA;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,YAAA,CAAA,EAAe;AACrB,IAAA,OAAO;AAAA,MACN,MAAA,EAAQ,MAAA,CAAO,IAAA,CAAK,IAAA,CAAK,MAAM,CAAA;AAAA,MAC/B,gBAAA,EAAkB,IAAA,CAAK;AAAA,IACxB,CAAA;AAAA,EACD;AACD,UAAA;ADxBA;AACA;AACE;AACF,kCAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-QWASSVCU.cjs","sourcesContent":[null,"import type { BaseModel } from \"./base.model.js\";\n\n/*\n * Module for managing multiple AI model implementations.\n *\n * Allows registration of multiple models and provides a unified interface\n * for accessing them. Supports setting a default model for convenience.\n *\n * @example\n * ```typescript\n * const modelModule = new ModelModule();\n * modelModule.addModel(\"gpt-4\", new OpenAIModel(\"gpt-4\"), true);\n * modelModule.addModel(\"gemini\", new GeminiModel(\"gemini-pro\"));\n *\n * const defaultModel = modelModule.getModel();\n * const specificModel = modelModule.getModel(\"gemini\");\n * ```\n */\nexport class ModelModule {\n\t/** Registry of available models indexed by name */\n\tprivate models: { [name: string]: BaseModel<unknown, unknown> } = {};\n\t/** Name of the default model to use when none specified */\n\tprivate defaultModelName?: string;\n\n\t/**\n\t * Registers a new model with the module.\n\t *\n\t * @param name - Unique identifier for the model\n\t * @param model - Model instance implementing BaseModel\n\t * @param isDefault - Whether to set this as the default model\n\t */\n\tpublic addModel(\n\t\tname: string,\n\t\tmodel: BaseModel<unknown, unknown>,\n\t\tisDefault?: boolean,\n\t) {\n\t\tthis.models[name] = model;\n\t\tif (isDefault || !this.defaultModelName) {\n\t\t\tthis.defaultModelName = name;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves a model by name or returns the default model.\n\t *\n\t * @param name - Optional model name to retrieve\n\t * @returns The requested model or default model if name not provided\n\t * @throws Error if no default model is set and name is not provided\n\t */\n\tpublic getModel(name?: string): BaseModel<unknown, unknown> {\n\t\tif (!this.defaultModelName) {\n\t\t\tthrow Error(\"No default model\");\n\t\t}\n\n\t\tif (!name || !this.models[name]) {\n\t\t\treturn this.models[this.defaultModelName];\n\t\t}\n\t\treturn this.models[name];\n\t}\n\n\t/**\n\t * Returns information about all registered models.\n\t *\n\t * @returns Object containing all models and the default model name\n\t */\n\tpublic getModelList() {\n\t\treturn {\n\t\t\tmodels: Object.keys(this.models),\n\t\t\tdefaultModelName: this.defaultModelName,\n\t\t};\n\t}\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-ZZK4ACTV.cjs","../../src/services/query-stream.service.ts"],"names":["intent"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,gCAA2B;AA+BpB,IAAM,mBAAA,EAAN,MAAyB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,WAAA,CACC,WAAA,EACA,SAAA,EACA,SAAA,EACA,YAAA,EACA,OAAA,EACC;AACD,IAAA,IAAA,CAAK,YAAA,EAAc,WAAA;AACnB,IAAA,IAAA,CAAK,UAAA,EAAY,SAAA;AACjB,IAAA,IAAA,CAAK,UAAA,EAAY,SAAA;AACjB,IAAA,IAAA,CAAK,aAAA,EAAe,YAAA;AACpB,IAAA,IAAA,CAAK,QAAA,EAAU,OAAA;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAc,gBAAA,CACb,KAAA,EACA,MAAA,EAC8B;AAC9B,IAAA,MA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ACc,QAAA;AAAA;AAAA;AAAA,oFAAA;AAId,MAAA;AACkD,MAAA;AACxB,MAAA;AACZ,IAAA;AACsC,MAAA;AACpD,QAAA;AACA,QAAA;AACA,MAAA;AACM,MAAA;AACR,IAAA;AACD,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwB+B,EAAA;AACL,IAAA;AACK,IAAA;AAC0B,IAAA;AAE1B,IAAA;AAC1B,IAAA;AAEU,IAAA;AACgD,MAAA;AACvD,IAAA;AACgB,MAAA;AACsB,MAAA;AAI1C,MAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACoB,QAAA;AACrB,MAAA;AAC0D,MAAA;AAChB,MAAA;AAC5C,IAAA;AAGwD,IAAA;AAGY,IAAA;AAE5C,IAAA;AACU,IAAA;AACqB,MAAA;AACH,QAAA;AAClB,QAAA;AACjC,MAAA;AACM,MAAA;AACP,IAAA;AAE0D,IAAA;AACzD,MAAA;AACC,QAAA;AACW,QAAA;AAC6B,QAAA;AACzC,MAAA;AACA,MAAA;AACC,QAAA;AACoB,QAAA;AACgC,QAAA;AACrD,MAAA;AACA,IAAA;AACF,EAAA;AACD;ADhH0F;AACA;AACA;AACA","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-ZZK4ACTV.cjs","sourcesContent":[null,"import { randomUUID } from \"node:crypto\";\nimport type {\n\tA2AModule,\n\tMCPModule,\n\tMemoryModule,\n\tModelModule,\n} from \"@/modules/index.js\";\nimport type { AinAgentPrompts } from \"@/types/agent.js\";\nimport {\n\ttype Intent,\n\tMessageRole,\n\ttype ThreadMetadata,\n\ttype ThreadObject,\n\ttype ThreadType,\n} from \"@/types/memory.js\";\nimport type { StreamEvent } from \"@/types/stream\";\nimport {\n\ttype IA2ATool,\n\ttype IAgentTool,\n\ttype IMCPTool,\n\tTOOL_PROTOCOL_TYPE,\n} from \"@/types/tool.js\";\nimport { loggers } from \"@/utils/logger.js\";\n\n/**\n * Service for processing user queries through the agent's AI pipeline.\n *\n * Orchestrates the query processing workflow including intent detection,\n * model inference, tool execution, and response generation. Manages\n * conversation context and coordinates between different modules.\n */\nexport class QueryStreamService {\n\tprivate modelModule: ModelModule;\n\tprivate a2aModule?: A2AModule;\n\tprivate mcpModule?: MCPModule;\n\tprivate memoryModule?: MemoryModule;\n\tprivate prompts?: AinAgentPrompts;\n\n\tconstructor(\n\t\tmodelModule: ModelModule,\n\t\ta2aModule?: A2AModule,\n\t\tmcpModule?: MCPModule,\n\t\tmemoryModule?: MemoryModule,\n\t\tprompts?: AinAgentPrompts,\n\t) {\n\t\tthis.modelModule = modelModule;\n\t\tthis.a2aModule = a2aModule;\n\t\tthis.mcpModule = mcpModule;\n\t\tthis.memoryModule = memoryModule;\n\t\tthis.prompts = prompts;\n\t}\n\n\t/**\n\t * Detects the intent from context.\n\t *\n\t * @param query - The user's input query\n\t * @param thread - The thread history\n\t * @returns The detected intent\n\t */\n\tprivate async intentTriggering(\n\t\tquery: string,\n\t\tthread: ThreadObject | undefined,\n\t): Promise<Intent | undefined> {\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst intentMemory = this.memoryModule?.getIntentMemory();\n\t\tif (!intentMemory) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// 인텐트 목록 가져오기\n\t\tconst intents = await intentMemory.listIntents();\n\n\t\tif (intents.length === 0) {\n\t\t\tloggers.intentStream.warn(\"No intent found\");\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst intentList = intents\n\t\t\t.map((intent) => `- ${intent.name}: ${intent.description}`)\n\t\t\t.join(\"\\n\");\n\n\t\t// Convert session history to a string\n\t\tconst historyMessages = !thread\n\t\t\t? \"\"\n\t\t\t: Object.entries(thread.messages)\n\t\t\t\t\t.sort(([, a], [, b]) => a.timestamp - b.timestamp)\n\t\t\t\t\t.map(([_chatId, chat]) => {\n\t\t\t\t\t\tconst role =\n\t\t\t\t\t\t\tchat.role === \"USER\"\n\t\t\t\t\t\t\t\t? \"User\"\n\t\t\t\t\t\t\t\t: chat.role === \"MODEL\"\n\t\t\t\t\t\t\t\t\t? \"Assistant\"\n\t\t\t\t\t\t\t\t\t: \"System\";\n\t\t\t\t\t\tconst content = Array.isArray(chat.content.parts)\n\t\t\t\t\t\t\t? chat.content.parts.join(\" \")\n\t\t\t\t\t\t\t: String(chat.content.parts);\n\t\t\t\t\t\treturn `${role}: \"\"\"${content}\"\"\"`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\");\n\n\t\tconst systemPrompt = `You are an expert in accurately identifying user intentions.\n\nAvailable intent list:\n${intentList}\n\nPlease select and answer only from the above intent list. \nPlease return only the exact intent name without any additional explanations or text.`;\n\n\t\tconst userMessage = `The following is the conversation history with the user:\n\n${historyMessages}\n\nLast user question: \"${query}\"\n\nBased on the above conversation history, please determine what the intention of the last user question is. \nPlease select and answer the most appropriate intent name from the available intent list.`;\n\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery: userMessage,\n\t\t\tsystemPrompt,\n\t\t});\n\n\t\tconst response = await modelInstance.fetch(messages);\n\t\tif (!response.content) {\n\t\t\tthrow new Error(\"No intent detected\");\n\t\t}\n\t\tconst intentName = response.content.trim();\n\t\tconst intent = await intentMemory.getIntentByName(intentName);\n\t\tif (!intent) {\n\t\t\tthrow new Error(`No intent found: ${intentName}`);\n\t\t}\n\t\treturn intent;\n\t}\n\n\t/**\n\t * Fulfills the detected intent by generating a response.\n\t *\n\t * Manages the complete inference loop including:\n\t * - Loading prompts and conversation history\n\t * - Collecting available tools from modules\n\t * - Executing model inference with tool support\n\t * - Processing tool calls iteratively until completion\n\t *\n\t * @param query - The user's input query\n\t * @param threadId - Thread identifier for context\n\t * @param thread - Previous conversation history\n\t * @returns Object containing process steps and final response\n\t */\n\tpublic async *intentFulfilling(\n\t\tquery: string,\n\t\tthreadId: string,\n\t\tthread?: ThreadObject,\n\t\tintent?: Intent,\n\t): AsyncGenerator<StreamEvent> {\n\t\tconst systemPrompt = `\nToday is ${new Date().toLocaleDateString()}.\n\n${this.prompts?.agent || \"\"}\n\n${this.prompts?.system || \"\"}\n\n${intent?.prompt || \"\"}\n\t`.trim();\n\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery,\n\t\t\tthread,\n\t\t\tsystemPrompt: systemPrompt.trim(),\n\t\t});\n\n\t\tconst tools: IAgentTool[] = [];\n\t\tthis.mcpModule && tools.push(...this.mcpModule.getTools());\n\t\tthis.a2aModule && tools.push(...(await this.a2aModule.getTools()));\n\n\t\tconst functions = modelInstance.convertToolsToFunctions(tools);\n\n\t\tconst processList: string[] = [];\n\n\t\twhile (true) {\n\t\t\tconst responseStream = await modelInstance.fetchStreamWithContextMessage(\n\t\t\t\tmessages,\n\t\t\t\tfunctions,\n\t\t\t);\n\n\t\t\tconst assembledToolCalls: {\n\t\t\t\tid: string;\n\t\t\t\ttype: \"function\";\n\t\t\t\tfunction: { name: string; arguments: string };\n\t\t\t}[] = [];\n\n\t\t\tloggers.intentStream.debug(\"messages\", { messages });\n\n\t\t\tfor await (const chunk of responseStream) {\n\t\t\t\tconst delta = chunk.delta;\n\t\t\t\tif (delta?.tool_calls) {\n\t\t\t\t\tfor (const { index, id, function: func } of delta.tool_calls) {\n\t\t\t\t\t\tassembledToolCalls[index] ??= {\n\t\t\t\t\t\t\tid: \"\",\n\t\t\t\t\t\t\ttype: \"function\",\n\t\t\t\t\t\t\tfunction: { name: \"\", arguments: \"\" },\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tif (id) assembledToolCalls[index].id = id;\n\t\t\t\t\t\tif (func?.name) assembledToolCalls[index].function.name = func.name;\n\t\t\t\t\t\tif (func?.arguments)\n\t\t\t\t\t\t\tassembledToolCalls[index].function.arguments += func.arguments;\n\t\t\t\t\t}\n\t\t\t\t} else if (chunk.delta?.content) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\tevent: \"text_chunk\",\n\t\t\t\t\t\tdata: { delta: chunk.delta.content },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tloggers.intentStream.debug(\"assembledToolCalls\", {\n\t\t\t\tassembledToolCalls,\n\t\t\t});\n\n\t\t\tif (assembledToolCalls.length > 0) {\n\t\t\t\tconst messagePayload = this.a2aModule?.getMessagePayload(\n\t\t\t\t\tquery,\n\t\t\t\t\tthreadId,\n\t\t\t\t);\n\t\t\t\tfor (const toolCall of assembledToolCalls) {\n\t\t\t\t\tconst toolName = toolCall.function.name;\n\t\t\t\t\tconst selectedTool = tools.filter((tool) => tool.id === toolName)[0];\n\n\t\t\t\t\tlet toolResult = \"\";\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.mcpModule &&\n\t\t\t\t\t\tselectedTool.protocol === TOOL_PROTOCOL_TYPE.MCP\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst toolArgs = JSON.parse(toolCall.function.arguments) as\n\t\t\t\t\t\t\t| { [x: string]: unknown }\n\t\t\t\t\t\t\t| undefined;\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\tevent: \"tool_start\",\n\t\t\t\t\t\t\tdata: { protocol: TOOL_PROTOCOL_TYPE.MCP, toolName, toolArgs },\n\t\t\t\t\t\t};\n\t\t\t\t\t\tloggers.intent.debug(\"MCP tool call\", { toolName, toolArgs });\n\t\t\t\t\t\ttoolResult = await this.mcpModule.useTool(\n\t\t\t\t\t\t\tselectedTool as IMCPTool,\n\t\t\t\t\t\t\ttoolArgs,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tthis.a2aModule &&\n\t\t\t\t\t\tselectedTool.protocol === TOOL_PROTOCOL_TYPE.A2A\n\t\t\t\t\t) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\tevent: \"tool_start\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tprotocol: TOOL_PROTOCOL_TYPE.A2A,\n\t\t\t\t\t\t\t\ttoolName,\n\t\t\t\t\t\t\t\ttoolArgs: null,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t\tloggers.intent.debug(\"A2A tool call\", { toolName });\n\t\t\t\t\t\ttoolResult = await this.a2aModule.useTool(\n\t\t\t\t\t\t\tselectedTool as IA2ATool,\n\t\t\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: <a2aModule is guaranteed to be defined>\n\t\t\t\t\t\t\tmessagePayload!,\n\t\t\t\t\t\t\tthreadId,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Unrecognized tool type. It cannot be happened...\n\t\t\t\t\t\tloggers.intent.warn(\n\t\t\t\t\t\t\t`Unrecognized tool type: ${selectedTool.protocol}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tyield {\n\t\t\t\t\t\tevent: \"tool_output\",\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tprotocol: selectedTool.protocol,\n\t\t\t\t\t\t\ttoolName,\n\t\t\t\t\t\t\tresult: toolResult,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tloggers.intent.debug(\"toolResult\", { toolResult });\n\n\t\t\t\t\tprocessList.push(toolResult);\n\t\t\t\t\tmodelInstance.appendMessages(messages, toolResult);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Generates a title for the conversation based on the query.\n\t *\n\t * @param query - The user's input query\n\t * @returns Promise resolving to a generated title\n\t */\n\n\tprivate async generateTitle(query: string): Promise<string> {\n\t\tconst DEFAULT_TITLE = \"New Chat\";\n\t\ttry {\n\t\t\tconst modelInstance = this.modelModule.getModel();\n\t\t\tconst messages = modelInstance.generateMessages({\n\t\t\t\tquery,\n\t\t\t\tsystemPrompt: `You are a helpful assistant that generates titles for conversations.\n Please analyze the user's query and create a concise title that accurately reflects the conversation's core topic.\n The title must be no more than 5 words long.\n Respond with only the title. Do not include any punctuation or extra explanations.`,\n\t\t\t});\n\t\t\tconst response = await modelInstance.fetch(messages);\n\t\t\treturn response.content || DEFAULT_TITLE;\n\t\t} catch (error) {\n\t\t\tloggers.intentStream.error(\"Error generating title\", {\n\t\t\t\terror,\n\t\t\t\tquery,\n\t\t\t});\n\t\t\treturn DEFAULT_TITLE;\n\t\t}\n\t}\n\n\t/**\n\t * Main entry point for processing user queries.\n\t *\n\t * Handles the complete query lifecycle:\n\t * 1. Loads thread from memory\n\t * 2. Detects intent from the query\n\t * 3. Fulfills the intent with AI response\n\t * 4. Updates conversation history\n\t *\n\t * @param type - The type of thread (e.g., chat, workflow)\n\t * @param userId - The user's unique identifier\n\t * @param threadId - Unique thread identifier\n\t * @param query - The user's input query\n\t * @returns Object containing the AI-generated response\n\t */\n\tpublic async *handleQueryStream(\n\t\tthreadMetadata: {\n\t\t\ttype: ThreadType;\n\t\t\tuserId: string;\n\t\t\tthreadId?: string;\n\t\t},\n\t\tquery: string,\n\t): AsyncGenerator<StreamEvent> {\n\t\tconst { type, userId } = threadMetadata;\n\t\tconst queryStartAt = Date.now();\n\t\tconst threadMemory = this.memoryModule?.getThreadMemory();\n\n\t\tlet threadId = threadMetadata.threadId;\n\t\tlet thread: ThreadObject | undefined;\n\n\t\tif (threadId) {\n\t\t\tthread = await threadMemory?.getThread(type, userId, threadId);\n\t\t} else {\n\t\t\tthreadId = randomUUID();\n\t\t\tconst title = await this.generateTitle(query);\n\n\t\t\tconst metadata =\n\t\t\t\t(await threadMemory?.createThread(type, userId, threadId, title)) ||\n\t\t\t\t({\n\t\t\t\t\ttype,\n\t\t\t\t\tthreadId,\n\t\t\t\t\ttitle,\n\t\t\t\t\tupdatedAt: Date.now(),\n\t\t\t\t} as ThreadMetadata);\n\t\t\tloggers.intentStream.info(\"Create new thread\", { metadata });\n\t\t\tyield { event: \"thread_id\", data: metadata };\n\t\t}\n\n\t\t// 2. intent triggering\n\t\tconst intent = await this.intentTriggering(query, thread);\n\n\t\t// 3. intent fulfillment\n\t\tconst stream = this.intentFulfilling(query, threadId, thread, intent);\n\n\t\tlet finalResponseText = \"\";\n\t\tfor await (const event of stream) {\n\t\t\tif (event.event === \"text_chunk\" && event.data.delta) {\n\t\t\t\tloggers.intentStream.debug(\"text_chunk\", { event });\n\t\t\t\tfinalResponseText += event.data.delta;\n\t\t\t}\n\t\t\tyield event;\n\t\t}\n\n\t\tawait threadMemory?.addMessagesToThread(userId, threadId, [\n\t\t\t{\n\t\t\t\trole: MessageRole.USER,\n\t\t\t\ttimestamp: queryStartAt,\n\t\t\t\tcontent: { type: \"text\", parts: [query] },\n\t\t\t},\n\t\t\t{\n\t\t\t\trole: MessageRole.MODEL,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\tcontent: { type: \"text\", parts: [finalResponseText] },\n\t\t\t},\n\t\t]);\n\t}\n}\n"]}
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkKRLUWTLNcjs = require('../../chunk-KRLUWTLN.cjs');
4
- require('../../chunk-DX2JH3FJ.cjs');
5
-
6
-
7
- exports.ThreadApiController = _chunkKRLUWTLNcjs.ThreadApiController;
8
- //# sourceMappingURL=thread.api.controller.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/controllers/api/thread.api.controller.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,4DAAiC;AACjC,oCAAiC;AACjC;AACE;AACF,oEAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/controllers/api/thread.api.controller.cjs"}
@@ -1,9 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkBBCZU5VZcjs = require('../../chunk-BBCZU5VZ.cjs');
4
- require('../../chunk-KRLUWTLN.cjs');
5
- require('../../chunk-DX2JH3FJ.cjs');
6
-
7
-
8
- exports.createThreadApiRouter = _chunkBBCZU5VZcjs.createThreadApiRouter;
9
- //# sourceMappingURL=thread.routes.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/routes/api/thread.routes.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,4DAAiC;AACjC,oCAAiC;AACjC,oCAAiC;AACjC;AACE;AACF,wEAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/routes/api/thread.routes.cjs"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/services/a2a.service.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { Task, TaskStatusUpdateEvent } from \"@a2a-js/sdk\";\nimport type {\n\tAgentExecutor,\n\tExecutionEventBus,\n\tRequestContext,\n} from \"@a2a-js/sdk/server\";\nimport type { ThreadType } from \"@/types/memory.js\";\nimport { loggers } from \"@/utils/logger.js\";\nimport type { QueryService } from \"./query.service.js\";\n\n/**\n * Implements the AgentExecutor interface from the a2a-js-sdk.\n * This service is responsible for the core business logic of executing an A2A task.\n */\nexport class A2AService implements AgentExecutor {\n\tprivate queryService: QueryService;\n\tprivate canceledTasks: Set<string> = new Set<string>();\n\n\tconstructor(queryService: QueryService) {\n\t\tthis.queryService = queryService;\n\t}\n\n\tpublic cancelTask = async (\n\t\ttaskId: string,\n\t\t_eventBus: ExecutionEventBus,\n\t): Promise<void> => {\n\t\tthis.canceledTasks.add(taskId);\n\t};\n\n\tprivate createTaskStatusUpdateEvent = (\n\t\ttaskId: string,\n\t\tcontextId: string,\n\t\tstate: \"working\" | \"failed\" | \"canceled\" | \"completed\",\n\t\tmessage?: string,\n\t): TaskStatusUpdateEvent => {\n\t\treturn {\n\t\t\tkind: \"status-update\",\n\t\t\ttaskId: taskId,\n\t\t\tcontextId: contextId,\n\t\t\tstatus: {\n\t\t\t\tstate: state,\n\t\t\t\tmessage: message\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tkind: \"message\",\n\t\t\t\t\t\t\trole: \"agent\",\n\t\t\t\t\t\t\tmessageId: randomUUID(),\n\t\t\t\t\t\t\tparts: [{ kind: \"text\", text: message }],\n\t\t\t\t\t\t\ttaskId: taskId,\n\t\t\t\t\t\t\tcontextId: contextId,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t},\n\t\t\tfinal: state !== \"working\",\n\t\t};\n\t};\n\n\tasync execute(\n\t\trequestContext: RequestContext,\n\t\teventBus: ExecutionEventBus,\n\t): Promise<void> {\n\t\tconst userMessage = requestContext.userMessage;\n\t\tconst { agentId, type, threadId } = userMessage.metadata as {\n\t\t\tagentId: string;\n\t\t\ttype: ThreadType;\n\t\t\tthreadId: string;\n\t\t};\n\t\tconst existingTask = requestContext.task;\n\n\t\tconst taskId = existingTask?.id || randomUUID();\n\t\tconst contextId =\n\t\t\tuserMessage.contextId || existingTask?.contextId || randomUUID();\n\n\t\tif (!existingTask) {\n\t\t\tconst initialTask: Task = {\n\t\t\t\tkind: \"task\",\n\t\t\t\tid: taskId,\n\t\t\t\tcontextId: contextId,\n\t\t\t\tstatus: {\n\t\t\t\t\tstate: \"submitted\",\n\t\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\t},\n\t\t\t\thistory: [userMessage],\n\t\t\t\tmetadata: userMessage.metadata,\n\t\t\t\tartifacts: [],\n\t\t\t};\n\t\t\teventBus.publish(initialTask);\n\t\t}\n\n\t\tconst workingStatusUpdate = this.createTaskStatusUpdateEvent(\n\t\t\ttaskId,\n\t\t\tcontextId,\n\t\t\t\"working\",\n\t\t);\n\t\teventBus.publish(workingStatusUpdate);\n\n\t\tconst message: string = userMessage.parts\n\t\t\t.filter((part) => part.kind === \"text\")\n\t\t\t.map((part) => part.text)\n\t\t\t.join(\"\\n\");\n\t\tif (message.length === 0) {\n\t\t\tloggers.server.warn(`Empty message received for task ${taskId}.`);\n\t\t\tconst failureUpdate = this.createTaskStatusUpdateEvent(\n\t\t\t\ttaskId,\n\t\t\t\tcontextId,\n\t\t\t\t\"failed\",\n\t\t\t\t\"No message found to process.\",\n\t\t\t);\n\t\t\teventBus.publish(failureUpdate);\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst response = await this.queryService.handleQuery(\n\t\t\t\t{ userId: agentId, type, threadId },\n\t\t\t\tmessage,\n\t\t\t);\n\n\t\t\tif (this.canceledTasks.has(taskId)) {\n\t\t\t\tloggers.server.info(`Task ${taskId} was canceled.`);\n\t\t\t\tconst canceledUpdate = this.createTaskStatusUpdateEvent(\n\t\t\t\t\ttaskId,\n\t\t\t\t\tcontextId,\n\t\t\t\t\t\"canceled\",\n\t\t\t\t);\n\t\t\t\teventBus.publish(canceledUpdate);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst finalUpdate = this.createTaskStatusUpdateEvent(\n\t\t\t\ttaskId,\n\t\t\t\tcontextId,\n\t\t\t\t\"completed\",\n\t\t\t\tresponse.content,\n\t\t\t);\n\t\t\teventBus.publish(finalUpdate);\n\t\t\tloggers.server.info(`Task ${taskId} completed successfully.`);\n\t\t} catch (error: any) {\n\t\t\tloggers.server.error(`Error processing task ${taskId}:`, error);\n\t\t\tconst errorUpdate = this.createTaskStatusUpdateEvent(\n\t\t\t\ttaskId,\n\t\t\t\tcontextId,\n\t\t\t\t\"failed\",\n\t\t\t\t`Agent error: ${error.message}`,\n\t\t\t);\n\t\t\teventBus.publish(errorUpdate);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;AAAA,SAAS,kBAAkB;AAepB,IAAM,aAAN,MAA0C;AAAA,EACxC;AAAA,EACA,gBAA6B,oBAAI,IAAY;AAAA,EAErD,YAAY,cAA4B;AACvC,SAAK,eAAe;AAAA,EACrB;AAAA,EAEO,aAAa,OACnB,QACA,cACmB;AACnB,SAAK,cAAc,IAAI,MAAM;AAAA,EAC9B;AAAA,EAEQ,8BAA8B,CACrC,QACA,WACA,OACA,YAC2B;AAC3B,WAAO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A,QACA;AAAA,MACD;AACA,eAAS,QAAQ,aAAa;AAC9B;AAAA,IACD;AAEA,QAAI;AACH,YAAM,WAAW,MAAM,KAAK,aAAa;AAAA,QACxC,EAAE,QAAQ,SAAS,MAAM,SAAS;AAAA,QAClC;AAAA,MACD;AAEA,UAAI,KAAK,cAAc,IAAI,MAAM,GAAG;AACnC,gBAAQ,OAAO,KAAK,QAAQ,MAAM,gBAAgB;AAClD,cAAM,iBAAiB,KAAK;AAAA,UAC3B;AAAA,UACA;AAAA,UACA;AAAA,QACD;AACA,iBAAS,QAAQ,cAAc;AAC/B;AAAA,MACD;AAEA,YAAM,cAAc,KAAK;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS;AAAA,MACV;AACA,eAAS,QAAQ,WAAW;AAC5B,cAAQ,OAAO,KAAK,QAAQ,MAAM,0BAA0B;AAAA,IAC7D,SAAS,OAAY;AACpB,cAAQ,OAAO,MAAM,yBAAyB,MAAM,KAAK,KAAK;AAC9D,YAAM,cAAc,KAAK;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAgB,MAAM,OAAO;AAAA,MAC9B;AACA,eAAS,QAAQ,WAAW;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/services/query.service.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type {\n\tA2AModule,\n\tMCPModule,\n\tMemoryModule,\n\tModelModule,\n} from \"@/modules/index.js\";\nimport type { AinAgentPrompts } from \"@/types/agent.js\";\nimport {\n\ttype Intent,\n\tMessageRole,\n\ttype ThreadMetadata,\n\ttype ThreadObject,\n\ttype ThreadType,\n} from \"@/types/memory.js\";\nimport {\n\ttype IA2ATool,\n\ttype IAgentTool,\n\ttype IMCPTool,\n\tTOOL_PROTOCOL_TYPE,\n} from \"@/types/tool.js\";\nimport { loggers } from \"@/utils/logger.js\";\n\n/**\n * Service for processing user queries through the agent's AI pipeline.\n *\n * Orchestrates the query processing workflow including intent detection,\n * model inference, tool execution, and response generation. Manages\n * conversation context and coordinates between different modules.\n */\nexport class QueryService {\n\tprivate modelModule: ModelModule;\n\tprivate a2aModule?: A2AModule;\n\tprivate mcpModule?: MCPModule;\n\tprivate memoryModule?: MemoryModule;\n\tprivate prompts?: AinAgentPrompts;\n\n\tconstructor(\n\t\tmodelModule: ModelModule,\n\t\ta2aModule?: A2AModule,\n\t\tmcpModule?: MCPModule,\n\t\tmemoryModule?: MemoryModule,\n\t\tprompts?: AinAgentPrompts,\n\t) {\n\t\tthis.modelModule = modelModule;\n\t\tthis.a2aModule = a2aModule;\n\t\tthis.mcpModule = mcpModule;\n\t\tthis.memoryModule = memoryModule;\n\t\tthis.prompts = prompts;\n\t}\n\n\t/**\n\t * Detects the intent from context.\n\t *\n\t * @param query - The user's input query\n\t * @param thread - The thread history\n\t * @returns The detected intent\n\t */\n\tprivate async intentTriggering(\n\t\tquery: string,\n\t\tthread: ThreadObject | undefined,\n\t): Promise<Intent | undefined> {\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst intentMemory = this.memoryModule?.getIntentMemory();\n\t\tif (!intentMemory) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// 인텐트 목록 가져오기\n\t\tconst intents = await intentMemory.listIntents();\n\n\t\tif (intents.length === 0) {\n\t\t\tloggers.intent.warn(\"No intent found\");\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst intentList = intents\n\t\t\t.map((intent) => `- ${intent.name}: ${intent.description}`)\n\t\t\t.join(\"\\n\");\n\n\t\t// Convert session history to a string\n\t\tconst historyMessages = !thread\n\t\t\t? \"\"\n\t\t\t: Object.entries(thread.messages)\n\t\t\t\t\t.sort(([, a], [, b]) => a.timestamp - b.timestamp)\n\t\t\t\t\t.map(([chatId, chat]) => {\n\t\t\t\t\t\tconst role =\n\t\t\t\t\t\t\tchat.role === \"USER\"\n\t\t\t\t\t\t\t\t? \"User\"\n\t\t\t\t\t\t\t\t: chat.role === \"MODEL\"\n\t\t\t\t\t\t\t\t\t? \"Assistant\"\n\t\t\t\t\t\t\t\t\t: \"System\";\n\t\t\t\t\t\tconst content = Array.isArray(chat.content.parts)\n\t\t\t\t\t\t\t? chat.content.parts.join(\" \")\n\t\t\t\t\t\t\t: String(chat.content.parts);\n\t\t\t\t\t\treturn `${role}: \"\"\"${content}\"\"\"`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\");\n\n\t\tconst systemPrompt = `You are an expert in accurately identifying user intentions.\n\nAvailable intent list:\n${intentList}\n\nPlease select and answer only from the above intent list. \nPlease return only the exact intent name without any additional explanations or text.`;\n\n\t\tconst userMessage = `The following is the conversation history with the user:\n\n${historyMessages}\n\nLast user question: \"${query}\"\n\nBased on the above conversation history, please determine what the intention of the last user question is. \nPlease select and answer the most appropriate intent name from the available intent list.`;\n\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery: userMessage,\n\t\t\tsystemPrompt,\n\t\t});\n\n\t\tconst response = await modelInstance.fetch(messages);\n\t\tif (!response.content) {\n\t\t\tthrow new Error(\"No intent detected\");\n\t\t}\n\t\tconst intentName = response.content.trim();\n\t\tconst intent = await intentMemory.getIntentByName(intentName);\n\t\tif (!intent) {\n\t\t\tthrow new Error(`No intent found: ${intentName}`);\n\t\t}\n\t\treturn intent;\n\t}\n\n\t/**\n\t * Fulfills the detected intent by generating a response.\n\t *\n\t * Manages the complete inference loop including:\n\t * - Loading prompts and conversation history\n\t * - Collecting available tools from modules\n\t * - Executing model inference with tool support\n\t * - Processing tool calls iteratively until completion\n\t *\n\t * @param query - The user's input query\n\t * @param threadId - Thread identifier for context\n\t * @param thread - Previous conversation history\n\t * @returns Object containing process steps and final response\n\t */\n\tprivate async intentFulfilling(\n\t\tquery: string,\n\t\tthreadId: string,\n\t\tthread?: ThreadObject,\n\t\tintent?: Intent,\n\t) {\n\t\t// 1. Load agent / system prompt from memory\n\t\tconst systemPrompt = `\nToday is ${new Date().toLocaleDateString()}.\n\n${this.prompts?.agent || \"\"}\n\n${this.prompts?.system || \"\"}\n\n${intent?.prompt || \"\"}\n `;\n\t\t// NOTE(haechan@comcom.ai):\n\t\t// When the `intent.llm` is guaranteed to be consistent, it will be used as a parameter for getModel\n\t\t// const model_name = intent?.llm || \"gpt-4o\";\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery,\n\t\t\tthread,\n\t\t\tsystemPrompt: systemPrompt.trim(),\n\t\t});\n\n\t\tconst tools: IAgentTool[] = [];\n\t\tif (this.mcpModule) {\n\t\t\ttools.push(...this.mcpModule.getTools());\n\t\t}\n\t\tif (this.a2aModule) {\n\t\t\ttools.push(...(await this.a2aModule.getTools()));\n\t\t}\n\t\tconst functions = modelInstance.convertToolsToFunctions(tools);\n\n\t\tconst processList: string[] = [];\n\t\tlet finalMessage = \"\";\n\t\tlet didCallTool = false;\n\n\t\twhile (true) {\n\t\t\tconst response = await modelInstance.fetchWithContextMessage(\n\t\t\t\tmessages,\n\t\t\t\tfunctions,\n\t\t\t);\n\t\t\tdidCallTool = false;\n\n\t\t\tloggers.intent.debug(\"messages\", { messages });\n\n\t\t\tconst { content, toolCalls } = response;\n\n\t\t\tloggers.intent.debug(\"content\", { content });\n\t\t\tloggers.intent.debug(\"tool_calls\", { ...toolCalls });\n\n\t\t\tif (toolCalls) {\n\t\t\t\tconst messagePayload = this.a2aModule?.getMessagePayload(\n\t\t\t\t\tquery,\n\t\t\t\t\tthreadId,\n\t\t\t\t);\n\n\t\t\t\tfor (const toolCall of toolCalls) {\n\t\t\t\t\tconst toolName = toolCall.name;\n\t\t\t\t\tdidCallTool = true;\n\t\t\t\t\tconst selectedTool = tools.filter((tool) => tool.id === toolName)[0];\n\n\t\t\t\t\tlet toolResult = \"\";\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.mcpModule &&\n\t\t\t\t\t\tselectedTool.protocol === TOOL_PROTOCOL_TYPE.MCP\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst toolArgs = toolCall.arguments as\n\t\t\t\t\t\t\t| { [x: string]: unknown }\n\t\t\t\t\t\t\t| undefined;\n\t\t\t\t\t\tloggers.intent.debug(\"MCP tool call\", { toolName, toolArgs });\n\t\t\t\t\t\ttoolResult = await this.mcpModule.useTool(\n\t\t\t\t\t\t\tselectedTool as IMCPTool,\n\t\t\t\t\t\t\ttoolArgs,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tthis.a2aModule &&\n\t\t\t\t\t\tselectedTool.protocol === TOOL_PROTOCOL_TYPE.A2A\n\t\t\t\t\t) {\n\t\t\t\t\t\ttoolResult = await this.a2aModule.useTool(\n\t\t\t\t\t\t\tselectedTool as IA2ATool,\n\t\t\t\t\t\t\tmessagePayload!,\n\t\t\t\t\t\t\tthreadId,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Unrecognized tool type. It cannot be happened...\n\t\t\t\t\t\tloggers.intent.warn(\n\t\t\t\t\t\t\t`Unrecognized tool type: ${selectedTool.protocol}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tloggers.intent.debug(\"toolResult\", { toolResult });\n\n\t\t\t\t\tprocessList.push(toolResult);\n\t\t\t\t\tmodelInstance.appendMessages(messages, toolResult);\n\t\t\t\t}\n\t\t\t} else if (content) {\n\t\t\t\tprocessList.push(content);\n\t\t\t\tfinalMessage = content;\n\t\t\t}\n\n\t\t\tif (!didCallTool) break;\n\t\t}\n\n\t\tconst botResponse = {\n\t\t\tprocess: processList.join(\"\\n\"),\n\t\t\tresponse: finalMessage,\n\t\t};\n\n\t\treturn botResponse;\n\t}\n\n\t/**\n\t * Generates a title for the conversation based on the query.\n\t *\n\t * @param query - The user's input query\n\t * @returns Promise resolving to a generated title\n\t */\n\n\tprivate async generateTitle(query: string): Promise<string> {\n\t\tconst DEFAULT_TITLE = \"New Chat\";\n\t\ttry {\n\t\t\tconst modelInstance = this.modelModule.getModel();\n\t\t\tconst messages = modelInstance.generateMessages({\n\t\t\t\tquery,\n\t\t\t\tsystemPrompt: `You are a helpful assistant that generates titles for conversations.\n Please analyze the user's query and create a concise title that accurately reflects the conversation's core topic.\n The title must be no more than 5 words long.\n Respond with only the title. Do not include any punctuation or extra explanations.`,\n\t\t\t});\n\t\t\tconst response = await modelInstance.fetch(messages);\n\t\t\treturn response.content || DEFAULT_TITLE;\n\t\t} catch (error) {\n\t\t\tloggers.intent.error(\"Error generating title\", {\n\t\t\t\terror,\n\t\t\t\tquery,\n\t\t\t});\n\t\t\treturn DEFAULT_TITLE;\n\t\t}\n\t}\n\n\t/**\n\t * Main entry point for processing user queries.\n\t *\n\t * Handles the complete query lifecycle:\n\t * 1. Loads thread history from memory\n\t * 2. Detects intent from the query\n\t * 3. Fulfills the intent with AI response\n\t * 4. Updates conversation history\n\t *\n\t * @param type - The type of thread (e.g., chat, workflow)\n\t * @param userId - The user's unique identifier\n\t * @param threadId - Unique thread identifier\n\t * @param query - The user's input query\n\t */\n\tpublic async handleQuery(\n\t\tthreadMetadata: {\n\t\t\ttype: ThreadType;\n\t\t\tuserId: string;\n\t\t\tthreadId?: string;\n\t\t},\n\t\tquery: string,\n\t) {\n\t\t// 1. Load thread with threadId\n\t\tconst { type, userId } = threadMetadata;\n\t\tconst queryStartAt = Date.now();\n\t\tconst threadMemory = this.memoryModule?.getThreadMemory();\n\n\t\tlet threadId = threadMetadata.threadId;\n\t\tlet thread: ThreadObject | undefined;\n\n\t\tif (threadId) {\n\t\t\tthread = await threadMemory?.getThread(type, userId, threadId);\n\t\t} else {\n\t\t\tthreadId = randomUUID();\n\t\t\tconst title = await this.generateTitle(query);\n\n\t\t\tconst metadata =\n\t\t\t\t(await threadMemory?.createThread(type, userId, threadId, title)) ||\n\t\t\t\t({\n\t\t\t\t\ttype,\n\t\t\t\t\tthreadId,\n\t\t\t\t\ttitle,\n\t\t\t\t\tupdatedAt: Date.now(),\n\t\t\t\t} as ThreadMetadata);\n\t\t\tloggers.intent.info(\"Create new thread\", { metadata });\n\t\t}\n\n\t\t// 2. intent triggering\n\t\tconst intent = await this.intentTriggering(query, thread);\n\n\t\t// 3. intent fulfillment\n\t\tconst result = await this.intentFulfilling(query, threadId, thread, intent);\n\t\tawait threadMemory?.addMessagesToThread(userId, threadId, [\n\t\t\t{\n\t\t\t\trole: MessageRole.USER,\n\t\t\t\ttimestamp: queryStartAt,\n\t\t\t\tcontent: { type: \"text\", parts: [query] },\n\t\t\t},\n\t\t\t{\n\t\t\t\trole: MessageRole.MODEL,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\tcontent: { type: \"text\", parts: [result.response] },\n\t\t\t},\n\t\t]);\n\n\t\treturn { content: result.response };\n\t}\n}\n"],"mappings":";;;;;AAAA,SAAS,kBAAkB;AA8BpB,IAAM,eAAN,MAAmB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YACC,aACA,WACA,WACA,cACA,SACC;AACD,SAAK,cAAc;AACnB,SAAK,YAAY;AACjB,SAAK,YAAY;AACjB,SAAK,eAAe;AACpB,SAAK,UAAU;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAc,iBACb,OACA,QAC8B;AAC9B,UAAM,gBAAgB,KAAK,YAAY,SAAS;AAChD,UAAM,eAAe,KAAK,cAAc,gBAAgB;AACxD,QAAI,CAAC,cAAc;AAClB,aAAO;AAAA,IACR;AAGA,UAAM,UAAU,MAAM,aAAa,YAAY;AAE/C,QAAI,QAAQ,WAAW,GAAG;AACzB,cAAQ,OAAO,KAAK,iBAAiB;AACrC,aAAO;AAAA,IACR;AAEA,UAAM,aAAa,QACjB,IAAI,CAACA,YAAW,KAAKA,QAAO,IAAI,KAAKA,QAAO,WAAW,EAAE,EACzD,KAAK,IAAI;AAGX,UAAM,kBAAkB,CAAC,SACtB,KACA,OAAO,QAAQ,OAAO,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cAAc,UAAU,MAAM,QAAQ,QAAQ;AAAA,IAC9D,OAAO;AACN,iBAAW,WAAW;AACtB,YAAM,QAAQ,MAAM,KAAK,cAAc,KAAK;AAE5C,YAAM,WACJ,MAAM,cAAc,aAAa,MAAM,QAAQ,UAAU,KAAK,KAC9D;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW,KAAK,IAAI;AAAA,MACrB;AACD,cAAQ,OAAO,KAAK,qBAAqB,EAAE,SAAS,CAAC;AAAA,IACtD;AAGA,UAAM,SAAS,MAAM,KAAK,iBAAiB,OAAO,MAAM;AAGxD,UAAM,SAAS,MAAM,KAAK,iBAAiB,OAAO,UAAU,QAAQ,MAAM;AAC1E,UAAM,cAAc,oBAAoB,QAAQ,UAAU;AAAA,MACzD;AAAA,QACC;AAAA,QACA,WAAW;AAAA,QACX,SAAS,EAAE,MAAM,QAAQ,OAAO,CAAC,KAAK,EAAE;AAAA,MACzC;AAAA,MACA;AAAA,QACC;AAAA,QACA,WAAW,KAAK,IAAI;AAAA,QACpB,SAAS,EAAE,MAAM,QAAQ,OAAO,CAAC,OAAO,QAAQ,EAAE;AAAA,MACnD;AAAA,IACD,CAAC;AAED,WAAO,EAAE,SAAS,OAAO,SAAS;AAAA,EACnC;AACD;","names":["intent"]}
@@ -1,35 +0,0 @@
1
- import {
2
- AinHttpError
3
- } from "./chunk-FL3JRQM4.js";
4
-
5
- // src/controllers/api/thread.api.controller.ts
6
- import { StatusCodes } from "http-status-codes";
7
- var ThreadApiController = class {
8
- memoryModule;
9
- constructor(memoryModule) {
10
- this.memoryModule = memoryModule;
11
- }
12
- handleGetThread = async (req, res, next) => {
13
- try {
14
- const { id: threadId, type } = req.params;
15
- const userId = res.locals.userId || "";
16
- const threadMemory = this.memoryModule.getThreadMemory();
17
- if (!threadMemory) {
18
- const error = new AinHttpError(
19
- StatusCodes.SERVICE_UNAVAILABLE,
20
- "Memory module is not initialized"
21
- );
22
- throw error;
23
- }
24
- const thread = await threadMemory.getThread(type, userId, threadId);
25
- res.json(thread);
26
- } catch (error) {
27
- next(error);
28
- }
29
- };
30
- };
31
-
32
- export {
33
- ThreadApiController
34
- };
35
- //# sourceMappingURL=chunk-ADIAIRNH.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/controllers/api/thread.api.controller.ts"],"sourcesContent":["import type { NextFunction, Request, Response } from \"express\";\nimport { StatusCodes } from \"http-status-codes\";\nimport type { MemoryModule } from \"@/modules/index.js\";\nimport { AinHttpError } from \"@/types/agent.js\";\nimport type { ThreadType } from \"@/types/memory\";\n\nexport class ThreadApiController {\n\tprivate memoryModule: MemoryModule;\n\n\tconstructor(memoryModule: MemoryModule) {\n\t\tthis.memoryModule = memoryModule;\n\t}\n\n\tpublic handleGetThread = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst { id: threadId, type } = req.params as {\n\t\t\t\tid: string;\n\t\t\t\ttype: ThreadType;\n\t\t\t};\n\t\t\tconst userId = res.locals.userId || \"\";\n\t\t\tconst threadMemory = this.memoryModule.getThreadMemory();\n\t\t\tif (!threadMemory) {\n\t\t\t\tconst error = new AinHttpError(\n\t\t\t\t\tStatusCodes.SERVICE_UNAVAILABLE,\n\t\t\t\t\t\"Memory module is not initialized\",\n\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst thread = await threadMemory.getThread(type, userId, threadId);\n\t\t\tres.json(thread);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n}\n"],"mappings":";;;;;AACA,SAAS,mBAAmB;AAKrB,IAAM,sBAAN,MAA0B;AAAA,EACxB;AAAA,EAER,YAAY,cAA4B;AACvC,SAAK,eAAe;AAAA,EACrB;AAAA,EAEO,kBAAkB,OACxB,KACA,KACA,SACI;AACJ,QAAI;AACH,YAAM,EAAE,IAAI,UAAU,KAAK,IAAI,IAAI;AAInC,YAAM,SAAS,IAAI,OAAO,UAAU;AACpC,YAAM,eAAe,KAAK,aAAa,gBAAgB;AACvD,UAAI,CAAC,cAAc;AAClB,cAAM,QAAQ,IAAI;AAAA,UACjB,YAAY;AAAA,UACZ;AAAA,QACD;AACA,cAAM;AAAA,MACP;AACA,YAAM,SAAS,MAAM,aAAa,UAAU,MAAM,QAAQ,QAAQ;AAClE,UAAI,KAAK,MAAM;AAAA,IAChB,SAAS,OAAO;AACf,WAAK,KAAK;AAAA,IACX;AAAA,EACD;AACD;","names":[]}
@@ -1,106 +0,0 @@
1
- import {
2
- MCPTool
3
- } from "./chunk-3LLHEUY2.js";
4
- import {
5
- loggers
6
- } from "./chunk-N7VYM2R5.js";
7
-
8
- // src/modules/mcp/mcp.module.ts
9
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
10
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
11
- var MCPModule = class {
12
- /** Map of MCP server names to their client instances */
13
- mcpMap = /* @__PURE__ */ new Map();
14
- /** Map of MCP server names to their transport instances */
15
- transportMap = /* @__PURE__ */ new Map();
16
- /** Array of all discovered tools from connected MCP servers */
17
- tools = [];
18
- /**
19
- * Connects to MCP servers based on the provided configuration.
20
- *
21
- * For each server in the config, establishes a connection, discovers
22
- * available tools, and adds them to the module's tool collection.
23
- * Skips servers that are already connected.
24
- *
25
- * @param mcpConfig - Configuration object mapping server names to connection details
26
- * @throws Error if connection to any MCP server fails
27
- */
28
- async addMCPConfig(mcpConfig) {
29
- try {
30
- for (const [name, conf] of Object.entries(mcpConfig)) {
31
- if (this.mcpMap.get(name) && this.transportMap.get(name)) continue;
32
- const transport = new StdioClientTransport(conf);
33
- this.transportMap.set(name, transport);
34
- const mcp = new Client({ name: "mcp-client-cli", version: "1.0.0" });
35
- await mcp.connect(transport);
36
- this.mcpMap.set(name, mcp);
37
- const toolsResult = await mcp.listTools();
38
- this.tools.push(
39
- ...toolsResult.tools.map((tool) => {
40
- return new MCPTool(name, tool);
41
- })
42
- );
43
- }
44
- loggers.mcp.info("Connected to MCP server with tools:", {
45
- tools: this.tools.map((tool) => tool.id)
46
- });
47
- } catch (error) {
48
- loggers.mcp.error("Failed to connect to MCP server:", { error });
49
- throw error;
50
- }
51
- }
52
- /**
53
- * Returns all available tools from connected MCP servers.
54
- *
55
- * @returns Array of MCPTool instances representing available tools
56
- */
57
- getTools() {
58
- return this.tools;
59
- }
60
- /**
61
- * Executes a tool on its corresponding MCP server.
62
- *
63
- * @param tool - The MCPTool instance to execute
64
- * @param _args - Arguments to pass to the tool
65
- * @returns Promise resolving to the tool's execution result
66
- * @throws Error if the MCP server for the tool is not found
67
- */
68
- async useTool(tool, _args) {
69
- const { serverName, mcpTool } = tool;
70
- const toolName = mcpTool.name;
71
- const mcp = this.mcpMap.get(serverName);
72
- try {
73
- if (!mcp) {
74
- throw new Error(`Invalid MCP Tool ${serverName}-${mcpTool.name}`);
75
- }
76
- const result = await mcp.callTool({
77
- name: toolName,
78
- arguments: _args
79
- });
80
- const toolResult = `[Bot Called Tool ${toolName} with args ${JSON.stringify(_args)}]
81
- ` + JSON.stringify(result.content, null, 2);
82
- return toolResult;
83
- } catch (error) {
84
- loggers.mcp.error("Failed to call tool", { error });
85
- const toolResult = `[Bot Called Tool ${toolName} with args ${JSON.stringify(_args)}]
86
- ${typeof error === "string" ? error : JSON.stringify(error, null, 2)}`;
87
- return toolResult;
88
- }
89
- }
90
- /**
91
- * Closes all MCP client connections.
92
- *
93
- * Should be called when shutting down the application to ensure
94
- * all MCP connections are properly closed.
95
- */
96
- async cleanup() {
97
- this.mcpMap.forEach((mcp) => {
98
- mcp.close();
99
- });
100
- }
101
- };
102
-
103
- export {
104
- MCPModule
105
- };
106
- //# sourceMappingURL=chunk-BDMVIJPF.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/modules/mcp/mcp.module.ts"],"sourcesContent":["import { Client } from \"@modelcontextprotocol/sdk/client/index.js\";\nimport { StdioClientTransport } from \"@modelcontextprotocol/sdk/client/stdio.js\";\nimport type { MCPConfig } from \"@/types/mcp.js\";\nimport { loggers } from \"@/utils/logger.js\";\nimport { MCPTool } from \"./mcp.tool.js\";\n\n/**\n * Module for managing Model Context Protocol (MCP) server connections.\n *\n * This module handles the lifecycle of MCP client connections, discovers\n * available tools from connected servers, and provides an interface for\n * executing those tools. Multiple MCP servers can be connected simultaneously.\n *\n * @example\n * ```typescript\n * const mcpModule = new MCPModule();\n * await mcpModule.addMCPConfig({\n * \"filesystem\": {\n * command: \"npx\",\n * args: [\"@modelcontextprotocol/server-filesystem\", \"/path/to/files\"]\n * }\n * });\n *\n * const tools = mcpModule.getTools();\n * const result = await mcpModule.useTool(tools[0], { path: \"/example.txt\" });\n * ```\n */\nexport class MCPModule {\n\t/** Map of MCP server names to their client instances */\n\tprivate mcpMap: Map<string, Client> = new Map();\n\t/** Map of MCP server names to their transport instances */\n\tprivate transportMap: Map<string, StdioClientTransport> = new Map();\n\t/** Array of all discovered tools from connected MCP servers */\n\tprivate tools: MCPTool[] = [];\n\n\t/**\n\t * Connects to MCP servers based on the provided configuration.\n\t *\n\t * For each server in the config, establishes a connection, discovers\n\t * available tools, and adds them to the module's tool collection.\n\t * Skips servers that are already connected.\n\t *\n\t * @param mcpConfig - Configuration object mapping server names to connection details\n\t * @throws Error if connection to any MCP server fails\n\t */\n\tasync addMCPConfig(mcpConfig: MCPConfig) {\n\t\ttry {\n\t\t\tfor (const [name, conf] of Object.entries(mcpConfig)) {\n\t\t\t\t// FIXME(yoojin): Need strict duplication check.\n\t\t\t\tif (this.mcpMap.get(name) && this.transportMap.get(name)) continue; // Duplicated mcp: skip\n\n\t\t\t\tconst transport = new StdioClientTransport(conf);\n\t\t\t\tthis.transportMap.set(name, transport);\n\t\t\t\tconst mcp = new Client({ name: \"mcp-client-cli\", version: \"1.0.0\" });\n\t\t\t\tawait mcp.connect(transport);\n\t\t\t\tthis.mcpMap.set(name, mcp);\n\n\t\t\t\tconst toolsResult = await mcp.listTools();\n\t\t\t\tthis.tools.push(\n\t\t\t\t\t...toolsResult.tools.map((tool) => {\n\t\t\t\t\t\treturn new MCPTool(name, tool);\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tloggers.mcp.info(\"Connected to MCP server with tools:\", {\n\t\t\t\ttools: this.tools.map((tool) => tool.id),\n\t\t\t});\n\t\t} catch (error: unknown) {\n\t\t\tloggers.mcp.error(\"Failed to connect to MCP server:\", { error });\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/**\n\t * Returns all available tools from connected MCP servers.\n\t *\n\t * @returns Array of MCPTool instances representing available tools\n\t */\n\tgetTools() {\n\t\treturn this.tools;\n\t}\n\n\t/**\n\t * Executes a tool on its corresponding MCP server.\n\t *\n\t * @param tool - The MCPTool instance to execute\n\t * @param _args - Arguments to pass to the tool\n\t * @returns Promise resolving to the tool's execution result\n\t * @throws Error if the MCP server for the tool is not found\n\t */\n\tasync useTool(tool: MCPTool, _args?: any): Promise<string> {\n\t\tconst { serverName, mcpTool } = tool;\n\t\tconst toolName = mcpTool.name;\n\t\tconst mcp = this.mcpMap.get(serverName);\n\n\t\ttry {\n\t\t\tif (!mcp) {\n\t\t\t\tthrow new Error(`Invalid MCP Tool ${serverName}-${mcpTool.name}`);\n\t\t\t}\n\n\t\t\tconst result = await mcp.callTool({\n\t\t\t\tname: toolName,\n\t\t\t\targuments: _args,\n\t\t\t});\n\t\t\tconst toolResult =\n\t\t\t\t`[Bot Called Tool ${toolName} with args ${JSON.stringify(_args)}]\\n` +\n\t\t\t\tJSON.stringify(result.content, null, 2);\n\t\t\treturn toolResult;\n\t\t} catch (error) {\n\t\t\tloggers.mcp.error(\"Failed to call tool\", { error });\n\t\t\tconst toolResult = `[Bot Called Tool ${toolName} with args ${JSON.stringify(_args)}]\\n${typeof error === \"string\" ? error : JSON.stringify(error, null, 2)}`;\n\t\t\treturn toolResult;\n\t\t}\n\t}\n\n\t/**\n\t * Closes all MCP client connections.\n\t *\n\t * Should be called when shutting down the application to ensure\n\t * all MCP connections are properly closed.\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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAM,QAAQ,MAAe,OAA8B;AAC1D,UAAM,EAAE,YAAY,QAAQ,IAAI;AAChC,UAAM,WAAW,QAAQ;AACzB,UAAM,MAAM,KAAK,OAAO,IAAI,UAAU;AAEtC,QAAI;AACH,UAAI,CAAC,KAAK;AACT,cAAM,IAAI,MAAM,oBAAoB,UAAU,IAAI,QAAQ,IAAI,EAAE;AAAA,MACjE;AAEA,YAAM,SAAS,MAAM,IAAI,SAAS;AAAA,QACjC,MAAM;AAAA,QACN,WAAW;AAAA,MACZ,CAAC;AACD,YAAM,aACL,oBAAoB,QAAQ,cAAc,KAAK,UAAU,KAAK,CAAC;AAAA,IAC/D,KAAK,UAAU,OAAO,SAAS,MAAM,CAAC;AACvC,aAAO;AAAA,IACR,SAAS,OAAO;AACf,cAAQ,IAAI,MAAM,uBAAuB,EAAE,MAAM,CAAC;AAClD,YAAM,aAAa,oBAAoB,QAAQ,cAAc,KAAK,UAAU,KAAK,CAAC;AAAA,EAAM,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAC1J,aAAO;AAAA,IACR;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,UAAU;AACf,SAAK,OAAO,QAAQ,CAAC,QAAgB;AACpC,UAAI,MAAM;AAAA,IACX,CAAC;AAAA,EACF;AACD;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/routes/api.routes.ts"],"sourcesContent":["import { Router } from \"express\";\nimport type { AINAgent } from \"@/index.js\";\n\nimport { createModelApiRouter } from \"./api/model.routes.js\";\nimport { createThreadApiRouter } from \"./api/thread.routes.js\";\n\nexport const createApiRouter = (agent: AINAgent): Router => {\n\tconst router = Router();\n\n\trouter.use(\"/api/model\", createModelApiRouter(agent.modelModule));\n\tif (agent.memoryModule) {\n\t\trouter.use(\"/api/thread\", createThreadApiRouter(agent.memoryModule));\n\t}\n\n\treturn router;\n};\n"],"mappings":";;;;;;;;AAAA,SAAS,cAAc;AAMhB,IAAM,kBAAkB,CAAC,UAA4B;AAC3D,QAAM,SAAS,OAAO;AAEtB,SAAO,IAAI,cAAc,qBAAqB,MAAM,WAAW,CAAC;AAChE,MAAI,MAAM,cAAc;AACvB,WAAO,IAAI,eAAe,sBAAsB,MAAM,YAAY,CAAC;AAAA,EACpE;AAEA,SAAO;AACR;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/routes/a2a.routes.ts"],"sourcesContent":["import { InMemoryTaskStore } from \"@a2a-js/sdk/server\";\nimport { Router } from \"express\";\nimport type { AINAgent } from \"@/index.js\";\nimport { QueryService } from \"@/services/query.service.js\";\nimport { A2AController } from \"../controllers/a2a.controller.js\";\nimport { A2AService } from \"../services/a2a.service.js\";\n\n/**\n * Creates and configures the A2A router.\n * This function is a \"composition root\" for the A2A feature,\n * creating and injecting all necessary dependencies.\n * @param intentAnalyzer The core intent analyzer.\n * @param agentCard The agent's card.\n * @returns An Express Router instance.\n */\nexport const createA2ARouter = (agent: AINAgent): Router => {\n\tconst router = Router();\n\n\t// 1. Create dependencies for the A2A feature\n\tconst taskStore = new InMemoryTaskStore();\n\tconst queryService = new QueryService(\n\t\tagent.modelModule,\n\t\tagent.a2aModule,\n\t\tagent.mcpModule,\n\t\tagent.memoryModule,\n\t\tagent.manifest.prompts,\n\t);\n\tconst a2aService = new A2AService(queryService);\n\tconst a2aController = new A2AController(\n\t\ta2aService,\n\t\ttaskStore,\n\t\tagent.generateAgentCard,\n\t);\n\n\t// 2. Define the route\n\trouter.post(\"/\", a2aController.handleA2ARequest);\n\n\treturn router;\n};\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,yBAAyB;AAClC,SAAS,cAAc;AAchB,IAAM,kBAAkB,CAAC,UAA4B;AAC3D,QAAM,SAAS,OAAO;AAGtB,QAAM,YAAY,IAAI,kBAAkB;AACxC,QAAM,eAAe,IAAI;AAAA,IACxB,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM,SAAS;AAAA,EAChB;AACA,QAAM,aAAa,IAAI,WAAW,YAAY;AAC9C,QAAM,gBAAgB,IAAI;AAAA,IACzB;AAAA,IACA;AAAA,IACA,MAAM;AAAA,EACP;AAGA,SAAO,KAAK,KAAK,cAAc,gBAAgB;AAE/C,SAAO;AACR;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/modules/a2a/a2a.module.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type {\n\tAgentCard,\n\tMessage,\n\tMessageSendParams,\n\tTask,\n\tTaskStatusUpdateEvent,\n\tTextPart,\n} from \"@a2a-js/sdk\";\nimport { A2AClient } from \"@a2a-js/sdk/client\";\nimport { ThreadType } from \"@/types/memory.js\";\nimport { loggers } from \"@/utils/logger.js\";\nimport { A2ATool } from \"./a2a.tool.js\";\n\n/**\n * Represents an active A2A communication session.\n */\ninterface A2ASession {\n\t/** Current task ID for multi-turn conversations */\n\ttaskId: string | undefined;\n\t/** Context ID for maintaining conversation state */\n\tcontextId: string | undefined;\n}\n\n/**\n * Module for managing Agent-to-Agent (A2A) protocol connections.\n *\n * This module handles connections to other A2A-compatible agents, manages\n * conversation sessions, and provides an interface for inter-agent communication.\n * Supports multi-turn conversations with task and context tracking.\n */\nexport class A2AModule {\n\t/** Map of A2A server URLs to their corresponding tool instances */\n\tprivate a2aPeerServers: Map<string, A2ATool | null> = new Map();\n\t/** Map of session IDs to their A2A session state */\n\tprivate a2aSessions: Map<string, A2ASession> = new Map();\n\tprivate agentId: string = randomUUID(); /* FIXME */\n\n\t/**\n\t * Registers a new A2A peer server URL for connection.\n\t *\n\t * @param url - The URL of the A2A-compatible agent to connect to\n\t */\n\tpublic async addA2APeerServer(url: string): Promise<void> {\n\t\tthis.a2aPeerServers.set(url, null);\n\t}\n\n\t/**\n\t * Retrieves tools from all registered A2A peer servers.\n\t *\n\t * Attempts to connect to each registered server, fetch their agent cards,\n\t * and create tool instances. Disables tools for unreachable servers.\n\t *\n\t * @returns Promise resolving to array of available A2A tools\n\t */\n\tpublic async getTools(): Promise<A2ATool[]> {\n\t\tconst tools: A2ATool[] = [];\n\t\tfor (const url of [...this.a2aPeerServers.keys()]) {\n\t\t\tconst tool = this.a2aPeerServers.get(url);\n\t\t\tif (!tool || !tool.enabled) {\n\t\t\t\ttry {\n\t\t\t\t\tconst client = new A2AClient(url);\n\t\t\t\t\tconst card: AgentCard = await client.getAgentCard();\n\t\t\t\t\tconst toolName = card.name.replaceAll(\" \", \"-\");\n\t\t\t\t\tconst a2aTool = new A2ATool(toolName, client, card);\n\n\t\t\t\t\ttools.push(a2aTool);\n\t\t\t\t} catch (_error: any) {\n\t\t\t\t\t// Agent not responded\n\t\t\t\t\tif (tool) {\n\t\t\t\t\t\ttool.disable();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\ttools.push(tool);\n\t\t\t}\n\t\t}\n\t\treturn tools;\n\t}\n\n\t/**\n\t * Gets or creates an A2A session for the given session ID.\n\t *\n\t * @param threadId - The session identifier\n\t * @returns A2ASession object with task and context IDs\n\t */\n\tprivate getA2ASessionWithId = (threadId: string): A2ASession => {\n\t\tconst a2aSession = this.a2aSessions.get(threadId) ?? {\n\t\t\ttaskId: undefined,\n\t\t\tcontextId: undefined,\n\t\t};\n\t\tif (!this.a2aSessions.has(threadId)) {\n\t\t\tthis.a2aSessions.set(threadId, a2aSession);\n\t\t}\n\n\t\treturn a2aSession;\n\t};\n\n\t/**\n\t * Constructs a message payload for A2A communication.\n\t *\n\t * Includes session context (task ID and context ID) if available\n\t * for maintaining conversation continuity.\n\t *\n\t * @param query - The message content to send\n\t * @param threadId - The session identifier\n\t * @returns Formatted Message object for A2A protocol\n\t */\n\tpublic getMessagePayload(query: string, threadId: string): Message {\n\t\tconst messagePayload: Message = {\n\t\t\tmessageId: randomUUID(),\n\t\t\tkind: \"message\",\n\t\t\trole: \"user\", // FIXME: it could be 'agent'\n\t\t\tmetadata: {\n\t\t\t\tagentId: this.agentId,\n\t\t\t\ttype: ThreadType.CHAT,\n\t\t\t\tthreadId,\n\t\t\t},\n\t\t\tparts: [\n\t\t\t\t{\n\t\t\t\t\tkind: \"text\",\n\t\t\t\t\ttext: query,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\n\t\tconst a2aSession = this.getA2ASessionWithId(threadId);\n\t\tif (a2aSession.taskId) {\n\t\t\tmessagePayload.taskId = a2aSession.taskId;\n\t\t}\n\t\tif (a2aSession.contextId) {\n\t\t\tmessagePayload.contextId = a2aSession.contextId;\n\t\t}\n\n\t\treturn messagePayload;\n\t}\n\n\t/**\n\t * Executes an A2A tool by sending a message to the remote agent.\n\t *\n\t * Handles streaming responses, maintains session state, and extracts\n\t * text content from various event types in the response stream.\n\t *\n\t * @param tool - The A2ATool instance to use\n\t * @param messagePayload - The message to send to the agent\n\t * @param threadId - The session identifier for context tracking\n\t * @returns Promise resolving to array of text responses from the agent\n\t */\n\tpublic async useTool(\n\t\ttool: A2ATool,\n\t\tmessagePayload: Message,\n\t\tthreadId: string,\n\t): Promise<string> {\n\t\tconst finalText: string[] = [];\n\t\tconst client = tool.client;\n\t\tconst params: MessageSendParams = {\n\t\t\tmessage: messagePayload,\n\t\t};\n\t\tconst a2aSession = this.getA2ASessionWithId(threadId);\n\n\t\ttry {\n\t\t\tconst stream = client.sendMessageStream(params);\n\t\t\tfor await (const event of stream) {\n\t\t\t\tif (event.kind === \"status-update\") {\n\t\t\t\t\tconst typedEvent = event as TaskStatusUpdateEvent;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypedEvent.final &&\n\t\t\t\t\t\ttypedEvent.status.state !== \"input-required\"\n\t\t\t\t\t) {\n\t\t\t\t\t\ta2aSession.taskId = undefined;\n\t\t\t\t\t}\n\t\t\t\t\t// TODO: handle 'file', 'data' parts\n\t\t\t\t\tconst texts = typedEvent.status.message?.parts\n\t\t\t\t\t\t.filter((part) => part.kind === \"text\")\n\t\t\t\t\t\t.map((part: TextPart) => part.text)\n\t\t\t\t\t\t.join(\"\\n\");\n\t\t\t\t\tif (texts) {\n\t\t\t\t\t\tfinalText.push(texts);\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"message\") {\n\t\t\t\t\t// FIXME: handling text in 'message'?\n\t\t\t\t\tconst msg = event as Message;\n\t\t\t\t\tif (msg.taskId && msg.taskId !== a2aSession.taskId) {\n\t\t\t\t\t\ta2aSession.taskId = msg.taskId;\n\t\t\t\t\t}\n\t\t\t\t\tif (msg.contextId && msg.contextId !== a2aSession.contextId) {\n\t\t\t\t\t\ta2aSession.contextId = msg.contextId;\n\t\t\t\t\t}\n\t\t\t\t} else if (event.kind === \"task\") {\n\t\t\t\t\t// FIXME: handling text in 'task'?\n\t\t\t\t\tconst task = event as Task;\n\t\t\t\t\tif (task.id !== a2aSession.taskId) {\n\t\t\t\t\t\ta2aSession.taskId = task.id;\n\t\t\t\t\t}\n\t\t\t\t\tif (task.contextId && task.contextId !== a2aSession.contextId) {\n\t\t\t\t\t\ta2aSession.contextId = task.contextId;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tloggers.a2a.warn(\"Received unknown event structure from stream:\", {\n\t\t\t\t\t\tevent,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tloggers.a2a.error(\"Error communicating with agent:\", { error });\n\t\t\ttool.disable();\n\t\t\tconst toolResult = `[Bot Called A2A Tool ${tool.card.name}]\\n${typeof error === \"string\" ? error : JSON.stringify(error, null, 2)}`;\n\t\t\treturn toolResult;\n\t\t}\n\n\t\treturn `[Bot Called A2A Tool ${tool.card.name}]\\n${finalText.join(\"\\n\")}`;\n\t}\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,kBAAkB;AAS3B,SAAS,iBAAiB;AAsBnB,IAAM,YAAN,MAAgB;AAAA;AAAA,EAEd,iBAA8C,oBAAI,IA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,WAAW;AAC5D,uBAAW,YAAY,IAAI;AAAA,UAC5B;AAAA,QACD,WAAW,MAAM,SAAS,QAAQ;AAEjC,gBAAM,OAAO;AACb,cAAI,KAAK,OAAO,WAAW,QAAQ;AAClC,uBAAW,SAAS,KAAK;AAAA,UAC1B;AACA,cAAI,KAAK,aAAa,KAAK,cAAc,WAAW,WAAW;AAC9D,uBAAW,YAAY,KAAK;AAAA,UAC7B;AAAA,QACD,OAAO;AACN,kBAAQ,IAAI,KAAK,iDAAiD;AAAA,YACjE;AAAA,UACD,CAAC;AAAA,QACF;AAAA,MACD;AAAA,IACD,SAAS,OAAO;AACf,cAAQ,IAAI,MAAM,mCAAmC,EAAE,MAAM,CAAC;AAC9D,WAAK,QAAQ;AACb,YAAM,aAAa,wBAAwB,KAAK,KAAK,IAAI;AAAA,EAAM,OAAO,UAAU,WAAW,QAAQ,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AACjI,aAAO;AAAA,IACR;AAEA,WAAO,wBAAwB,KAAK,KAAK,IAAI;AAAA,EAAM,UAAU,KAAK,IAAI,CAAC;AAAA,EACxE;AACD;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/services/query-stream.service.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type {\n\tA2AModule,\n\tMCPModule,\n\tMemoryModule,\n\tModelModule,\n} from \"@/modules/index.js\";\nimport type { AinAgentPrompts } from \"@/types/agent.js\";\nimport {\n\ttype Intent,\n\tMessageRole,\n\ttype ThreadMetadata,\n\ttype ThreadObject,\n\ttype ThreadType,\n} from \"@/types/memory.js\";\nimport type { StreamEvent } from \"@/types/stream\";\nimport {\n\ttype IA2ATool,\n\ttype IAgentTool,\n\ttype IMCPTool,\n\tTOOL_PROTOCOL_TYPE,\n} from \"@/types/tool.js\";\nimport { loggers } from \"@/utils/logger.js\";\n\n/**\n * Service for processing user queries through the agent's AI pipeline.\n *\n * Orchestrates the query processing workflow including intent detection,\n * model inference, tool execution, and response generation. Manages\n * conversation context and coordinates between different modules.\n */\nexport class QueryStreamService {\n\tprivate modelModule: ModelModule;\n\tprivate a2aModule?: A2AModule;\n\tprivate mcpModule?: MCPModule;\n\tprivate memoryModule?: MemoryModule;\n\tprivate prompts?: AinAgentPrompts;\n\n\tconstructor(\n\t\tmodelModule: ModelModule,\n\t\ta2aModule?: A2AModule,\n\t\tmcpModule?: MCPModule,\n\t\tmemoryModule?: MemoryModule,\n\t\tprompts?: AinAgentPrompts,\n\t) {\n\t\tthis.modelModule = modelModule;\n\t\tthis.a2aModule = a2aModule;\n\t\tthis.mcpModule = mcpModule;\n\t\tthis.memoryModule = memoryModule;\n\t\tthis.prompts = prompts;\n\t}\n\n\t/**\n\t * Detects the intent from context.\n\t *\n\t * @param query - The user's input query\n\t * @param thread - The thread history\n\t * @returns The detected intent\n\t */\n\tprivate async intentTriggering(\n\t\tquery: string,\n\t\tthread: ThreadObject | undefined,\n\t): Promise<Intent | undefined> {\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst intentMemory = this.memoryModule?.getIntentMemory();\n\t\tif (!intentMemory) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// 인텐트 목록 가져오기\n\t\tconst intents = await intentMemory.listIntents();\n\n\t\tif (intents.length === 0) {\n\t\t\tloggers.intentStream.warn(\"No intent found\");\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst intentList = intents\n\t\t\t.map((intent) => `- ${intent.name}: ${intent.description}`)\n\t\t\t.join(\"\\n\");\n\n\t\t// Convert session history to a string\n\t\tconst historyMessages = !thread\n\t\t\t? \"\"\n\t\t\t: Object.entries(thread.messages)\n\t\t\t\t\t.sort(([, a], [, b]) => a.timestamp - b.timestamp)\n\t\t\t\t\t.map(([_chatId, chat]) => {\n\t\t\t\t\t\tconst role =\n\t\t\t\t\t\t\tchat.role === \"USER\"\n\t\t\t\t\t\t\t\t? \"User\"\n\t\t\t\t\t\t\t\t: chat.role === \"MODEL\"\n\t\t\t\t\t\t\t\t\t? \"Assistant\"\n\t\t\t\t\t\t\t\t\t: \"System\";\n\t\t\t\t\t\tconst content = Array.isArray(chat.content.parts)\n\t\t\t\t\t\t\t? chat.content.parts.join(\" \")\n\t\t\t\t\t\t\t: String(chat.content.parts);\n\t\t\t\t\t\treturn `${role}: \"\"\"${content}\"\"\"`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\");\n\n\t\tconst systemPrompt = `You are an expert in accurately identifying user intentions.\n\nAvailable intent list:\n${intentList}\n\nPlease select and answer only from the above intent list. \nPlease return only the exact intent name without any additional explanations or text.`;\n\n\t\tconst userMessage = `The following is the conversation history with the user:\n\n${historyMessages}\n\nLast user question: \"${query}\"\n\nBased on the above conversation history, please determine what the intention of the last user question is. \nPlease select and answer the most appropriate intent name from the available intent list.`;\n\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery: userMessage,\n\t\t\tsystemPrompt,\n\t\t});\n\n\t\tconst response = await modelInstance.fetch(messages);\n\t\tif (!response.content) {\n\t\t\tthrow new Error(\"No intent detected\");\n\t\t}\n\t\tconst intentName = response.content.trim();\n\t\tconst intent = await intentMemory.getIntentByName(intentName);\n\t\tif (!intent) {\n\t\t\tthrow new Error(`No intent found: ${intentName}`);\n\t\t}\n\t\treturn intent;\n\t}\n\n\t/**\n\t * Fulfills the detected intent by generating a response.\n\t *\n\t * Manages the complete inference loop including:\n\t * - Loading prompts and conversation history\n\t * - Collecting available tools from modules\n\t * - Executing model inference with tool support\n\t * - Processing tool calls iteratively until completion\n\t *\n\t * @param query - The user's input query\n\t * @param threadId - Thread identifier for context\n\t * @param thread - Previous conversation history\n\t * @returns Object containing process steps and final response\n\t */\n\tpublic async *intentFulfilling(\n\t\tquery: string,\n\t\tthreadId: string,\n\t\tthread?: ThreadObject,\n\t\tintent?: Intent,\n\t): AsyncGenerator<StreamEvent> {\n\t\tconst systemPrompt = `\nToday is ${new Date().toLocaleDateString()}.\n\n${this.prompts?.agent || \"\"}\n\n${this.prompts?.system || \"\"}\n\n${intent?.prompt || \"\"}\n\t`.trim();\n\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery,\n\t\t\tthread,\n\t\t\tsystemPrompt: systemPrompt.trim(),\n\t\t});\n\n\t\tconst tools: IAgentTool[] = [];\n\t\tthis.mcpModule && tools.push(...this.mcpModule.getTools());\n\t\tthis.a2aModule && tools.push(...(await this.a2aModule.getTools()));\n\n\t\tconst functions = modelInstance.convertToolsToFunctions(tools);\n\n\t\tconst processList: string[] = [];\n\n\t\twhile (true) {\n\t\t\tconst responseStream = await modelInstance.fetchStreamWithContextMessage(\n\t\t\t\tmessages,\n\t\t\t\tfunctions,\n\t\t\t);\n\n\t\t\tconst assembledToolCalls: {\n\t\t\t\tid: string;\n\t\t\t\ttype: \"function\";\n\t\t\t\tfunction: { name: string; arguments: string };\n\t\t\t}[] = [];\n\n\t\t\tloggers.intentStream.debug(\"messages\", { messages });\n\n\t\t\tfor await (const chunk of responseStream) {\n\t\t\t\tconst delta = chunk.delta;\n\t\t\t\tif (delta?.tool_calls) {\n\t\t\t\t\tfor (const { index, id, function: func } of delta.tool_calls) {\n\t\t\t\t\t\tassembledToolCalls[index] ??= {\n\t\t\t\t\t\t\tid: \"\",\n\t\t\t\t\t\t\ttype: \"function\",\n\t\t\t\t\t\t\tfunction: { name: \"\", arguments: \"\" },\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tif (id) assembledToolCalls[index].id = id;\n\t\t\t\t\t\tif (func?.name) assembledToolCalls[index].function.name = func.name;\n\t\t\t\t\t\tif (func?.arguments)\n\t\t\t\t\t\t\tassembledToolCalls[index].function.arguments += func.arguments;\n\t\t\t\t\t}\n\t\t\t\t} else if (chunk.delta?.content) {\n\t\t\t\t\tyield {\n\t\t\t\t\t\tevent: \"text_chunk\",\n\t\t\t\t\t\tdata: { delta: chunk.delta.content },\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tloggers.intentStream.debug(\"assembledToolCalls\", {\n\t\t\t\tassembledToolCalls,\n\t\t\t});\n\n\t\t\tif (assembledToolCalls.length > 0) {\n\t\t\t\tconst messagePayload = this.a2aModule?.getMessagePayload(\n\t\t\t\t\tquery,\n\t\t\t\t\tthreadId,\n\t\t\t\t);\n\t\t\t\tfor (const toolCall of assembledToolCalls) {\n\t\t\t\t\tconst toolName = toolCall.function.name;\n\t\t\t\t\tconst selectedTool = tools.filter((tool) => tool.id === toolName)[0];\n\n\t\t\t\t\tlet toolResult = \"\";\n\t\t\t\t\tif (\n\t\t\t\t\t\tthis.mcpModule &&\n\t\t\t\t\t\tselectedTool.protocol === TOOL_PROTOCOL_TYPE.MCP\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst toolArgs = JSON.parse(toolCall.function.arguments) as\n\t\t\t\t\t\t\t| { [x: string]: unknown }\n\t\t\t\t\t\t\t| undefined;\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\tevent: \"tool_start\",\n\t\t\t\t\t\t\tdata: { protocol: TOOL_PROTOCOL_TYPE.MCP, toolName, toolArgs },\n\t\t\t\t\t\t};\n\t\t\t\t\t\tloggers.intent.debug(\"MCP tool call\", { toolName, toolArgs });\n\t\t\t\t\t\ttoolResult = await this.mcpModule.useTool(\n\t\t\t\t\t\t\tselectedTool as IMCPTool,\n\t\t\t\t\t\t\ttoolArgs,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tthis.a2aModule &&\n\t\t\t\t\t\tselectedTool.protocol === TOOL_PROTOCOL_TYPE.A2A\n\t\t\t\t\t) {\n\t\t\t\t\t\tyield {\n\t\t\t\t\t\t\tevent: \"tool_start\",\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tprotocol: TOOL_PROTOCOL_TYPE.A2A,\n\t\t\t\t\t\t\t\ttoolName,\n\t\t\t\t\t\t\t\ttoolArgs: null,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t\tloggers.intent.debug(\"A2A tool call\", { toolName });\n\t\t\t\t\t\ttoolResult = await this.a2aModule.useTool(\n\t\t\t\t\t\t\tselectedTool as IA2ATool,\n\t\t\t\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: <a2aModule is guaranteed to be defined>\n\t\t\t\t\t\t\tmessagePayload!,\n\t\t\t\t\t\t\tthreadId,\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Unrecognized tool type. It cannot be happened...\n\t\t\t\t\t\tloggers.intent.warn(\n\t\t\t\t\t\t\t`Unrecognized tool type: ${selectedTool.protocol}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tyield {\n\t\t\t\t\t\tevent: \"tool_output\",\n\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\tprotocol: selectedTool.protocol,\n\t\t\t\t\t\t\ttoolName,\n\t\t\t\t\t\t\tresult: toolResult,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tloggers.intent.debug(\"toolResult\", { toolResult });\n\n\t\t\t\t\tprocessList.push(toolResult);\n\t\t\t\t\tmodelInstance.appendMessages(messages, toolResult);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Generates a title for the conversation based on the query.\n\t *\n\t * @param query - The user's input query\n\t * @returns Promise resolving to a generated title\n\t */\n\n\tprivate async generateTitle(query: string): Promise<string> {\n\t\tconst DEFAULT_TITLE = \"New Chat\";\n\t\ttry {\n\t\t\tconst modelInstance = this.modelModule.getModel();\n\t\t\tconst messages = modelInstance.generateMessages({\n\t\t\t\tquery,\n\t\t\t\tsystemPrompt: `You are a helpful assistant that generates titles for conversations.\n Please analyze the user's query and create a concise title that accurately reflects the conversation's core topic.\n The title must be no more than 5 words long.\n Respond with only the title. Do not include any punctuation or extra explanations.`,\n\t\t\t});\n\t\t\tconst response = await modelInstance.fetch(messages);\n\t\t\treturn response.content || DEFAULT_TITLE;\n\t\t} catch (error) {\n\t\t\tloggers.intentStream.error(\"Error generating title\", {\n\t\t\t\terror,\n\t\t\t\tquery,\n\t\t\t});\n\t\t\treturn DEFAULT_TITLE;\n\t\t}\n\t}\n\n\t/**\n\t * Main entry point for processing user queries.\n\t *\n\t * Handles the complete query lifecycle:\n\t * 1. Loads thread from memory\n\t * 2. Detects intent from the query\n\t * 3. Fulfills the intent with AI response\n\t * 4. Updates conversation history\n\t *\n\t * @param type - The type of thread (e.g., chat, workflow)\n\t * @param userId - The user's unique identifier\n\t * @param threadId - Unique thread identifier\n\t * @param query - The user's input query\n\t * @returns Object containing the AI-generated response\n\t */\n\tpublic async *handleQueryStream(\n\t\tthreadMetadata: {\n\t\t\ttype: ThreadType;\n\t\t\tuserId: string;\n\t\t\tthreadId?: string;\n\t\t},\n\t\tquery: string,\n\t): AsyncGenerator<StreamEvent> {\n\t\tconst { type, userId } = threadMetadata;\n\t\tconst queryStartAt = Date.now();\n\t\tconst threadMemory = this.memoryModule?.getThreadMemory();\n\n\t\tlet threadId = threadMetadata.threadId;\n\t\tlet thread: ThreadObject | undefined;\n\n\t\tif (threadId) {\n\t\t\tthread = await threadMemory?.getThread(type, userId, threadId);\n\t\t} else {\n\t\t\tthreadId = randomUUID();\n\t\t\tconst title = await this.generateTitle(query);\n\n\t\t\tconst metadata =\n\t\t\t\t(await threadMemory?.createThread(type, userId, threadId, title)) ||\n\t\t\t\t({\n\t\t\t\t\ttype,\n\t\t\t\t\tthreadId,\n\t\t\t\t\ttitle,\n\t\t\t\t\tupdatedAt: Date.now(),\n\t\t\t\t} as ThreadMetadata);\n\t\t\tloggers.intentStream.info(\"Create new thread\", { metadata });\n\t\t\tyield { event: \"thread_id\", data: metadata };\n\t\t}\n\n\t\t// 2. intent triggering\n\t\tconst intent = await this.intentTriggering(query, thread);\n\n\t\t// 3. intent fulfillment\n\t\tconst stream = this.intentFulfilling(query, threadId, thread, intent);\n\n\t\tlet finalResponseText = \"\";\n\t\tfor await (const event of stream) {\n\t\t\tif (event.event === \"text_chunk\" && event.data.delta) {\n\t\t\t\tloggers.intentStream.debug(\"text_chunk\", { event });\n\t\t\t\tfinalResponseText += event.data.delta;\n\t\t\t}\n\t\t\tyield event;\n\t\t}\n\n\t\tawait threadMemory?.addMessagesToThread(userId, threadId, [\n\t\t\t{\n\t\t\t\trole: MessageRole.USER,\n\t\t\t\ttimestamp: queryStartAt,\n\t\t\t\tcontent: { type: \"text\", parts: [query] },\n\t\t\t},\n\t\t\t{\n\t\t\t\trole: MessageRole.MODEL,\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\tcontent: { type: \"text\", parts: [finalResponseText] },\n\t\t\t},\n\t\t]);\n\t}\n}\n"],"mappings":";;;;;AAAA,SAAS,kBAAkB;AA+BpB,IAAM,qBAAN,MAAyB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YACC,aACA,WACA,WACA,cACA,SACC;AACD,SAAK,cAAc;AACnB,SAAK,YAAY;AACjB,SAAK,YAAY;AACjB,SAAK,eAAe;AACpB,SAAK,UAAU;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAc,iBACb,OACA,QAC8B;AAC9B,UAAM,gBAAgB,KAAK,YAAY,SAAS;AAChD,UAAM,eAAe,KAAK,cAAc,gBAAgB;AACxD,QAAI,CAAC,cAAc;AAClB,aAAO;AAAA,IACR;AAGA,UAAM,UAAU,MAAM,aAAa,YAAY;AAE/C,QAAI,QAAQ,WAAW,GAAG;AACzB,cAAQ,aAAa,KAAK,iBAAiB;AAC3C,aAAO;AAAA,IACR;AAEA,UAAM,aAAa,QACjB,IAAI,CAACA,YAAW,KAAKA,QAAO,IAAI,KAAKA,QAAO,WAAW,EAAE,EACzD,KAAK,IAAI;AAGX,UAAM,kBAAkB,CAAC,SACtB,KACA,OAAO,QAAQ,OAAO,QAAQ,EAC7B,KAAK,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