@ainetwork/adk 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chunk-2E6X6IDL.cjs +37 -0
- package/dist/cjs/chunk-2E6X6IDL.cjs.map +1 -0
- package/dist/cjs/chunk-2G7V7SC5.cjs +18 -0
- package/dist/cjs/chunk-2G7V7SC5.cjs.map +1 -0
- package/dist/cjs/chunk-3JKRJYJ6.cjs +111 -0
- package/dist/cjs/chunk-3JKRJYJ6.cjs.map +1 -0
- package/dist/cjs/chunk-466ED5WN.cjs +41 -0
- package/dist/cjs/chunk-466ED5WN.cjs.map +1 -0
- package/dist/cjs/chunk-4ESGHH2M.cjs +20 -0
- package/dist/cjs/chunk-4ESGHH2M.cjs.map +1 -0
- package/dist/cjs/chunk-4HY26I2C.cjs +168 -0
- package/dist/cjs/chunk-4HY26I2C.cjs.map +1 -0
- package/dist/cjs/chunk-5OWM5IH4.cjs +20 -0
- package/dist/cjs/chunk-5OWM5IH4.cjs.map +1 -0
- package/dist/cjs/chunk-6S6GEY3D.cjs +37 -0
- package/dist/cjs/chunk-6S6GEY3D.cjs.map +1 -0
- package/dist/cjs/chunk-CYW6ICAW.cjs +106 -0
- package/dist/cjs/chunk-CYW6ICAW.cjs.map +1 -0
- package/dist/cjs/chunk-DQP6RGIR.cjs +162 -0
- package/dist/cjs/chunk-DQP6RGIR.cjs.map +1 -0
- package/dist/cjs/chunk-FWFEVDEY.cjs +172 -0
- package/dist/cjs/chunk-FWFEVDEY.cjs.map +1 -0
- package/dist/cjs/chunk-GEQMVWSK.cjs +275 -0
- package/dist/cjs/chunk-GEQMVWSK.cjs.map +1 -0
- package/dist/cjs/chunk-HKIUAJ45.cjs +37 -0
- package/dist/cjs/chunk-HKIUAJ45.cjs.map +1 -0
- package/dist/cjs/chunk-ICFTUZP5.cjs +111 -0
- package/dist/cjs/chunk-ICFTUZP5.cjs.map +1 -0
- package/dist/cjs/chunk-MIXAV5OD.cjs +43 -0
- package/dist/cjs/chunk-MIXAV5OD.cjs.map +1 -0
- package/dist/cjs/chunk-MMWEU2MO.cjs +100 -0
- package/dist/cjs/chunk-MMWEU2MO.cjs.map +1 -0
- package/dist/cjs/chunk-NYYEZ4ER.cjs +22 -0
- package/dist/cjs/chunk-NYYEZ4ER.cjs.map +1 -0
- package/dist/cjs/chunk-OBUCVZNU.cjs +37 -0
- package/dist/cjs/chunk-OBUCVZNU.cjs.map +1 -0
- package/dist/cjs/chunk-RMRFCEP4.cjs +8 -0
- package/dist/cjs/chunk-RMRFCEP4.cjs.map +1 -0
- package/dist/cjs/chunk-RPMERDHU.cjs +44 -0
- package/dist/cjs/chunk-RPMERDHU.cjs.map +1 -0
- package/dist/cjs/chunk-RWQDV2XY.cjs +166 -0
- package/dist/cjs/chunk-RWQDV2XY.cjs.map +1 -0
- package/dist/cjs/chunk-TNLJ6AVP.cjs +22 -0
- package/dist/cjs/chunk-TNLJ6AVP.cjs.map +1 -0
- package/dist/cjs/chunk-TRT5ABOM.cjs +43 -0
- package/dist/cjs/chunk-TRT5ABOM.cjs.map +1 -0
- package/dist/cjs/chunk-UQ72NNHV.cjs +225 -0
- package/dist/cjs/chunk-UQ72NNHV.cjs.map +1 -0
- package/dist/cjs/chunk-XZAKXJYO.cjs +20 -0
- package/dist/cjs/chunk-XZAKXJYO.cjs.map +1 -0
- package/dist/cjs/chunk-YE52UBF3.cjs +66 -0
- package/dist/cjs/chunk-YE52UBF3.cjs.map +1 -0
- package/dist/cjs/chunk-ZAZ3KYP5.cjs +43 -0
- package/dist/cjs/chunk-ZAZ3KYP5.cjs.map +1 -0
- package/dist/cjs/chunk-ZSEBMINV.cjs +44 -0
- package/dist/cjs/chunk-ZSEBMINV.cjs.map +1 -0
- package/dist/cjs/controllers/a2a.controller.cjs +3 -3
- package/dist/cjs/controllers/index.cjs +4 -4
- package/dist/cjs/controllers/query.controller.cjs +2 -2
- package/dist/cjs/index.cjs +17 -16
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/middlewares/error.middleware.cjs +3 -3
- package/dist/cjs/modules/a2a/a2a.module.cjs +3 -3
- package/dist/cjs/modules/index.cjs +9 -9
- package/dist/cjs/modules/index.cjs.map +1 -1
- package/dist/cjs/modules/mcp/mcp.module.cjs +3 -3
- package/dist/cjs/modules/models/base.model.cjs +2 -2
- package/dist/cjs/routes/a2a.routes.cjs +7 -7
- package/dist/cjs/routes/index.cjs +10 -9
- package/dist/cjs/routes/index.cjs.map +1 -1
- package/dist/cjs/routes/query.routes.cjs +7 -6
- package/dist/cjs/routes/query.routes.cjs.map +1 -1
- package/dist/cjs/services/a2a.service.cjs +3 -3
- package/dist/cjs/services/index.cjs +10 -6
- package/dist/cjs/services/index.cjs.map +1 -1
- package/dist/cjs/services/query-stream.service.cjs +10 -0
- package/dist/cjs/services/query-stream.service.cjs.map +1 -0
- package/dist/cjs/services/query.service.cjs +4 -4
- package/dist/cjs/types/memory.cjs +2 -2
- package/dist/cjs/types/stream.cjs +1 -0
- package/dist/cjs/types/stream.cjs.map +1 -0
- package/dist/cjs/utils/logger.cjs +2 -2
- package/dist/esm/{chunk-GZFRRFOE.js → chunk-2BITOA2R.js} +1 -1
- package/dist/esm/chunk-2BITOA2R.js.map +1 -0
- package/dist/esm/{chunk-BTZVK3EA.js → chunk-BDMVIJPF.js} +18 -12
- package/dist/esm/{chunk-BTZVK3EA.js.map → chunk-BDMVIJPF.js.map} +1 -1
- package/dist/esm/{chunk-SQWZXP4P.js → chunk-C6SGV7JV.js} +7 -3
- package/dist/esm/{chunk-SQWZXP4P.js.map → chunk-C6SGV7JV.js.map} +1 -1
- package/dist/esm/{chunk-N6T2JOGC.js → chunk-DRUCJYPJ.js} +4 -8
- package/dist/esm/chunk-DRUCJYPJ.js.map +1 -0
- package/dist/esm/chunk-F3YHV3TK.js +43 -0
- package/dist/esm/chunk-F3YHV3TK.js.map +1 -0
- package/dist/esm/{chunk-EODMRV4H.js → chunk-HAE333YO.js} +2 -2
- package/dist/esm/{chunk-U2Y64SAC.js → chunk-JOE4VYJJ.js} +4 -4
- package/dist/esm/{chunk-ILFWNK3W.js → chunk-MAU2MAK2.js} +2 -2
- package/dist/esm/{chunk-64GEXWSE.js → chunk-N7VYM2R5.js} +2 -1
- package/dist/esm/chunk-N7VYM2R5.js.map +1 -0
- package/dist/esm/chunk-OWL56P6L.js +275 -0
- package/dist/esm/chunk-OWL56P6L.js.map +1 -0
- package/dist/esm/chunk-RN3S44OH.js +44 -0
- package/dist/esm/chunk-RN3S44OH.js.map +1 -0
- package/dist/esm/{chunk-F727XG4N.js → chunk-VAZWF5IK.js} +1 -1
- package/dist/esm/{chunk-F727XG4N.js.map → chunk-VAZWF5IK.js.map} +1 -1
- package/dist/esm/{chunk-AQ5YZERE.js → chunk-Y6E73I7I.js} +2 -2
- package/dist/esm/{chunk-7QSZHJU5.js → chunk-YT6PD6UF.js} +4 -4
- package/dist/esm/controllers/a2a.controller.d.ts +1 -0
- package/dist/esm/controllers/a2a.controller.js +2 -2
- package/dist/esm/controllers/api/model.api.controller.d.ts +1 -0
- package/dist/esm/controllers/index.d.ts +2 -0
- package/dist/esm/controllers/index.js +7 -7
- package/dist/esm/controllers/query.controller.d.ts +5 -1
- package/dist/esm/controllers/query.controller.js +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +22 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/middlewares/error.middleware.js +2 -2
- package/dist/esm/modules/a2a/a2a.module.d.ts +1 -1
- package/dist/esm/modules/a2a/a2a.module.js +2 -2
- package/dist/esm/modules/index.d.ts +1 -0
- package/dist/esm/modules/index.js +10 -10
- package/dist/esm/modules/mcp/mcp.module.d.ts +1 -1
- package/dist/esm/modules/mcp/mcp.module.js +2 -2
- package/dist/esm/modules/memory/base.memory.d.ts +3 -3
- package/dist/esm/modules/models/base.model.d.ts +13 -0
- package/dist/esm/modules/models/base.model.js +1 -1
- package/dist/esm/modules/models/model.module.d.ts +1 -0
- package/dist/esm/routes/a2a.routes.d.ts +1 -0
- package/dist/esm/routes/a2a.routes.js +6 -6
- package/dist/esm/routes/api/models.routes.d.ts +1 -0
- package/dist/esm/routes/api.routes.d.ts +1 -0
- package/dist/esm/routes/api.routes.js +2 -2
- package/dist/esm/routes/index.d.ts +1 -0
- package/dist/esm/routes/index.js +17 -16
- package/dist/esm/routes/query.routes.d.ts +2 -1
- package/dist/esm/routes/query.routes.js +6 -5
- package/dist/esm/services/a2a.service.d.ts +1 -0
- package/dist/esm/services/a2a.service.js +2 -2
- package/dist/esm/services/index.d.ts +3 -0
- package/dist/esm/services/index.js +9 -5
- package/dist/esm/services/query-stream.service.d.ts +81 -0
- package/dist/esm/services/query-stream.service.js +10 -0
- package/dist/esm/services/query-stream.service.js.map +1 -0
- package/dist/esm/services/query.service.d.ts +1 -0
- package/dist/esm/services/query.service.js +3 -3
- package/dist/esm/types/memory.d.ts +9 -1
- package/dist/esm/types/memory.js +1 -1
- package/dist/esm/types/stream.d.ts +45 -0
- package/dist/esm/types/stream.js +1 -0
- package/dist/esm/types/stream.js.map +1 -0
- package/dist/esm/utils/logger.d.ts +1 -0
- package/dist/esm/utils/logger.js +1 -1
- package/package.json +1 -1
- package/dist/esm/chunk-64GEXWSE.js.map +0 -1
- package/dist/esm/chunk-GZFRRFOE.js.map +0 -1
- package/dist/esm/chunk-N6T2JOGC.js.map +0 -1
- package/dist/esm/chunk-NH7BYWQV.js +0 -27
- package/dist/esm/chunk-NH7BYWQV.js.map +0 -1
- package/dist/esm/chunk-WIJDRP2A.js +0 -26
- package/dist/esm/chunk-WIJDRP2A.js.map +0 -1
- /package/dist/esm/{chunk-EODMRV4H.js.map → chunk-HAE333YO.js.map} +0 -0
- /package/dist/esm/{chunk-U2Y64SAC.js.map → chunk-JOE4VYJJ.js.map} +0 -0
- /package/dist/esm/{chunk-ILFWNK3W.js.map → chunk-MAU2MAK2.js.map} +0 -0
- /package/dist/esm/{chunk-AQ5YZERE.js.map → chunk-Y6E73I7I.js.map} +0 -0
- /package/dist/esm/{chunk-7QSZHJU5.js.map → chunk-YT6PD6UF.js.map} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk466ED5WNcjs = require('./chunk-466ED5WN.cjs');
|
|
4
|
+
|
|
5
|
+
// src/middlewares/error.middleware.ts
|
|
6
|
+
var errorMiddleware = (error, req, res, next) => {
|
|
7
|
+
try {
|
|
8
|
+
const status = error.status || 500;
|
|
9
|
+
const message = error.message || "Something went wrong";
|
|
10
|
+
_chunk466ED5WNcjs.logger.error(
|
|
11
|
+
`[${req.method}] ${req.path} >> StatusCode:: ${status}, Message:: ${message}`
|
|
12
|
+
);
|
|
13
|
+
res.status(status).json({ message });
|
|
14
|
+
} catch (error2) {
|
|
15
|
+
next(error2);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.errorMiddleware = errorMiddleware;
|
|
22
|
+
//# sourceMappingURL=chunk-NYYEZ4ER.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-NYYEZ4ER.cjs","../../src/middlewares/error.middleware.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACAO,IAAM,gBAAA,EAAkB,CAC9B,KAAA,EACA,GAAA,EACA,GAAA,EACA,IAAA,EAAA,GACU;AACV,EAAA,IAAI;AACH,IAAA,MAAM,OAAA,EAAiB,KAAA,CAAM,OAAA,GAAU,GAAA;AACvC,IAAA,MAAM,QAAA,EAAkB,KAAA,CAAM,QAAA,GAAW,sBAAA;AAEzC,IAAA,wBAAA,CAAO,KAAA;AAAA,MACN,CAAA,CAAA,EAAI,GAAA,CAAI,MAAM,CAAA,EAAA,EAAK,GAAA,CAAI,IAAI,CAAA,iBAAA,EAAoB,MAAM,CAAA,YAAA,EAAe,OAAO,CAAA;AAAA,IAAA;AAE5E,IAAA;AAAmC,EAAA;AAEnC,IAAA;AAAU,EAAA;AAEZ;ADJA;AACA;AACA;AACA","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-NYYEZ4ER.cjs","sourcesContent":[null,"import type { NextFunction, Request, Response } from \"express\";\nimport type { AinHttpError } from \"@/types/agent\";\nimport { logger } from \"@/utils/logger\";\n\nexport const errorMiddleware = (\n\terror: AinHttpError,\n\treq: Request,\n\tres: Response,\n\tnext: NextFunction,\n): void => {\n\ttry {\n\t\tconst status: number = error.status || 500;\n\t\tconst message: string = error.message || \"Something went wrong\";\n\n\t\tlogger.error(\n\t\t\t`[${req.method}] ${req.path} >> StatusCode:: ${status}, Message:: ${message}`,\n\t\t);\n\t\tres.status(status).json({ message });\n\t} catch (error) {\n\t\tnext(error);\n\t}\n};\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkQUWZWKSZcjs = require('./chunk-QUWZWKSZ.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkILGIEJCXcjs = require('./chunk-ILGIEJCX.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk7BZO57TGcjs = require('./chunk-7BZO57TG.cjs');
|
|
10
|
+
|
|
11
|
+
// src/routes/a2a.routes.ts
|
|
12
|
+
var _server = require('@a2a-js/sdk/server');
|
|
13
|
+
var _express = require('express');
|
|
14
|
+
var createA2ARouter = (agent) => {
|
|
15
|
+
const router = _express.Router.call(void 0, );
|
|
16
|
+
const taskStore = new (0, _server.InMemoryTaskStore)();
|
|
17
|
+
const queryService = new (0, _chunkQUWZWKSZcjs.QueryService)(
|
|
18
|
+
agent.modelModule,
|
|
19
|
+
agent.a2aModule,
|
|
20
|
+
agent.mcpModule,
|
|
21
|
+
agent.memoryModule,
|
|
22
|
+
agent.manifest.prompts
|
|
23
|
+
);
|
|
24
|
+
const a2aService = new (0, _chunk7BZO57TGcjs.A2AService)(queryService);
|
|
25
|
+
const a2aController = new (0, _chunkILGIEJCXcjs.A2AController)(
|
|
26
|
+
a2aService,
|
|
27
|
+
taskStore,
|
|
28
|
+
agent.generateAgentCard
|
|
29
|
+
);
|
|
30
|
+
router.post("/a2a", a2aController.handleA2ARequest);
|
|
31
|
+
return router;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
exports.createA2ARouter = createA2ARouter;
|
|
37
|
+
//# sourceMappingURL=chunk-OBUCVZNU.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-OBUCVZNU.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,MAAA,EAAQ,aAAA,CAAc,gBAAgB,CAAA;AAElD,EAAA,OAAO,MAAA;AACR,CAAA;ADNA;AACA;AACE;AACF,0CAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-OBUCVZNU.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(\"/a2a\", a2aController.handleA2ARequest);\n\n\treturn router;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-RMRFCEP4.cjs","../../src/modules/models/base.model.ts"],"names":[],"mappings":"AAAA;ACcO,IAAe,UAAA,EAAf,MAAoD;AAkE3D,CAAA;AD7EA;AACA;AACE;AACF,8BAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-RMRFCEP4.cjs","sourcesContent":[null,"import type { SessionObject } from \"@/types/memory.js\";\nimport type { LLMStream } from \"@/types/stream.js\";\nimport type { FetchResponse, IAgentTool } from \"@/types/tool.js\";\n\n/**\n * Abstract base class for AI model implementations.\n *\n * Provides a common interface for different AI model providers (OpenAI, Gemini, etc.)\n * to integrate with the AIN-ADK framework. Each model implementation must handle\n * message formatting, tool conversion, and API communication.\n *\n * @typeParam MessageType - The message format used by the specific model API\n * @typeParam FunctionType - The function/tool format used by the specific model API\n */\nexport abstract class BaseModel<MessageType, FunctionType> {\n\t/**\n\t * Generates an array of messages from session history and current query.\n\t *\n\t * @param sessionHistory - Previous conversation history\n\t * @param query - Current user query\n\t * @param systemPrompt - Optional system prompt to set context\n\t * @returns Array of messages formatted for the specific model API\n\t */\n\tabstract generateMessages(params: {\n\t\tquery: string;\n\t\tsessionHistory?: SessionObject;\n\t\tsystemPrompt?: string;\n\t}): MessageType[];\n\n\t/**\n\t * Appends a new message to the existing message array.\n\t *\n\t * @param messages - Existing message array to expand\n\t * @param message - New message content to append\n\t */\n\tabstract appendMessages(messages: MessageType[], message: string): void;\n\n\t/**\n\t * Converts protocol-agnostic tools to model-specific function format.\n\t *\n\t * @param tools - Array of agent tools from MCP or A2A sources\n\t * @returns Array of functions in the format required by the model API\n\t */\n\tabstract convertToolsToFunctions(tools: IAgentTool[]): FunctionType[];\n\n\t/**\n\t * Fetches a response from the model API without tool support.\n\t *\n\t * @param messages - Array of messages to send to the model\n\t * @returns Promise resolving to the model's response\n\t */\n\tabstract fetch(messages: MessageType[]): Promise<FetchResponse>;\n\n\t/**\n\t * Fetches a response from the model API with tool/function support.\n\t *\n\t * @param messages - Array of messages to send to the model\n\t * @param functions - Array of available functions/tools the model can call\n\t * @returns Promise resolving to the model's response, possibly including tool calls\n\t */\n\tabstract fetchWithContextMessage(\n\t\tmessages: MessageType[],\n\t\tfunctions: FunctionType[],\n\t): Promise<FetchResponse>;\n\n\t/**\n\t * Fetches a streaming response from the model API with tool/function support.\n\t *\n\t * Returns a standardized LLMStream that can be used consistently across\n\t * different AI model providers. Each implementation should convert their\n\t * provider-specific stream format to the common StreamChunk interface.\n\t *\n\t * @param messages - Array of messages to send to the model\n\t * @param functions - Array of available functions/tools the model can call\n\t * @returns Promise resolving to an LLMStream for consistent iteration\n\t */\n\tabstract fetchStreamWithContextMessage(\n\t\tmessages: MessageType[],\n\t\tfunctions: FunctionType[],\n\t): Promise<LLMStream>;\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _class;// src/controllers/query.controller.ts
|
|
2
|
+
var QueryController = (_class = class {
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
constructor(queryService, queryStreamService) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);
|
|
6
|
+
this.queryService = queryService;
|
|
7
|
+
this.queryStreamService = queryStreamService;
|
|
8
|
+
}
|
|
9
|
+
__init() {this.handleQueryRequest = async (req, res, next) => {
|
|
10
|
+
try {
|
|
11
|
+
const { message, sessionId } = req.body;
|
|
12
|
+
const userId = res.locals.userId;
|
|
13
|
+
const result = await this.queryService.handleQuery(
|
|
14
|
+
message,
|
|
15
|
+
sessionId,
|
|
16
|
+
userId
|
|
17
|
+
);
|
|
18
|
+
res.status(200).json(result);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
next(error);
|
|
21
|
+
}
|
|
22
|
+
}}
|
|
23
|
+
__init2() {this.handleQueryStreamRequest = async (req, res, next) => {
|
|
24
|
+
const { message, sessionId, userId } = req.body;
|
|
25
|
+
if (!this.queryStreamService) {
|
|
26
|
+
throw new Error("This Agent does not support stream query");
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
await this.queryStreamService.handleQueryStream(
|
|
30
|
+
message,
|
|
31
|
+
sessionId,
|
|
32
|
+
res,
|
|
33
|
+
userId
|
|
34
|
+
);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
next(error);
|
|
37
|
+
}
|
|
38
|
+
}}
|
|
39
|
+
}, _class);
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
exports.QueryController = QueryController;
|
|
44
|
+
//# sourceMappingURL=chunk-RPMERDHU.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-RPMERDHU.cjs","../../src/controllers/query.controller.ts"],"names":[],"mappings":"AAAA;ACGO,IAAM,gBAAA,YAAN,MAAsB;AAAA,EACpB;AAAA,EACA;AAAA,EAER,WAAA,CACC,YAAA,EACA,kBAAA,EACC;AACD,IAAA,IAAA,CAAK,aAAA,EAAe,YAAA;AACpB,IAAA,IAAA,CAAK,mBAAA,EAAqB,kBAAA;AAAA,EAC3B;AAAA,iBAEO,mBAAA,EAAqB,MAAA,CAC3B,GAAA,EACA,GAAA,EACA,IAAA,EAAA,GACI;AACJ,IAAA,IAAI;AACH,MAAA,MAAM,EAAE,OAAA,EAAS,UAAU,EAAA,EAAI,GAAA,CAAI,IAAA;AACnC,MAAA,MAAM,OAAA,EAAS,GAAA,CAAI,MAAA,CAAO,MAAA;AAE1B,MAAA,MAAM,OAAA,EAAS,MAAM,IAAA,CAAK,YAAA,CAAa,WAAA;AAAA,QACtC,OAAA;AAAA,QACA,SAAA;AAAA,QACA;AAAA,MACD,CAAA;AAEA,MAAA,GAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,MAAM,CAAA;AAAA,IAC5B,EAAA,MAAA,CAAS,KAAA,EAAO;AACf,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA,IACX;AAAA,EACD,EAAA;AAAA,kBAEO,yBAAA,EAA2B,MAAA,CACjC,GAAA,EACA,GAAA,EACA,IAAA,EAAA,GACI;AACJ,IAAA,MAAM,EAAE,OAAA,EAAS,SAAA,EAAW,OAAO,EAAA,EAAI,GAAA,CAAI,IAAA;AAE3C,IAAA,GAAA,CAAI,CAAC,IAAA,CAAK,kBAAA,EAAoB;AAC7B,MAAA,MAAM,IAAI,KAAA,CAAM,0CAA0C,CAAA;AAAA,IAC3D;AACA,IAAA,IAAI;AACH,MAAA,MAAM,IAAA,CAAK,kBAAA,CAAmB,iBAAA;AAAA,QAC7B,OAAA;AAAA,QACA,SAAA;AAAA,QACA,GAAA;AAAA,QACA;AAAA,MACD,CAAA;AAAA,IACD,EAAA,MAAA,CAAS,KAAA,EAAO;AACf,MAAA,IAAA,CAAK,KAAK,CAAA;AAAA,IACX;AAAA,EACD,EAAA;AACD,UAAA;ADlBA;AACA;AACE;AACF,0CAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-RPMERDHU.cjs","sourcesContent":[null,"import type { NextFunction, Request, Response } from \"express\";\nimport type { QueryService, QueryStreamService } from \"@/services\";\n\nexport class QueryController {\n\tprivate queryService;\n\tprivate queryStreamService;\n\n\tconstructor(\n\t\tqueryService: QueryService,\n\t\tqueryStreamService?: QueryStreamService,\n\t) {\n\t\tthis.queryService = queryService;\n\t\tthis.queryStreamService = queryStreamService;\n\t}\n\n\tpublic handleQueryRequest = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst { message, sessionId } = req.body;\n\t\t\tconst userId = res.locals.userId;\n\n\t\t\tconst result = await this.queryService.handleQuery(\n\t\t\t\tmessage,\n\t\t\t\tsessionId,\n\t\t\t\tuserId,\n\t\t\t);\n\n\t\t\tres.status(200).json(result);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n\n\tpublic handleQueryStreamRequest = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\tconst { message, sessionId, userId } = req.body;\n\n\t\tif (!this.queryStreamService) {\n\t\t\tthrow new Error(\"This Agent does not support stream query\");\n\t\t}\n\t\ttry {\n\t\t\tawait this.queryStreamService.handleQueryStream(\n\t\t\t\tmessage,\n\t\t\t\tsessionId,\n\t\t\t\tres,\n\t\t\t\tuserId,\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n}\n"]}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunk466ED5WNcjs = require('./chunk-466ED5WN.cjs');
|
|
4
|
+
|
|
5
|
+
// src/services/query.service.ts
|
|
6
|
+
var QueryService = class {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
constructor(modelModule, a2aModule, mcpModule, memoryModule, prompts) {
|
|
13
|
+
this.modelModule = modelModule;
|
|
14
|
+
this.a2aModule = a2aModule;
|
|
15
|
+
this.mcpModule = mcpModule;
|
|
16
|
+
this.memoryModule = memoryModule;
|
|
17
|
+
this.prompts = prompts;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detects the intent from a user query.
|
|
21
|
+
*
|
|
22
|
+
* @param query - The user's input query
|
|
23
|
+
* @returns The detected intent (currently returns the query as-is)
|
|
24
|
+
* @todo Implement actual intent detection logic
|
|
25
|
+
*/
|
|
26
|
+
async intentTriggering(query) {
|
|
27
|
+
return query;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Fulfills the detected intent by generating a response.
|
|
31
|
+
*
|
|
32
|
+
* Manages the complete inference loop including:
|
|
33
|
+
* - Loading prompts and conversation history
|
|
34
|
+
* - Collecting available tools from modules
|
|
35
|
+
* - Executing model inference with tool support
|
|
36
|
+
* - Processing tool calls iteratively until completion
|
|
37
|
+
*
|
|
38
|
+
* @param query - The user's input query
|
|
39
|
+
* @param sessionId - Session identifier for context
|
|
40
|
+
* @param sessionHistory - Previous conversation history
|
|
41
|
+
* @returns Object containing process steps and final response
|
|
42
|
+
*/
|
|
43
|
+
async intentFulfilling(query, sessionId, sessionHistory) {
|
|
44
|
+
const systemPrompt = `
|
|
45
|
+
Today is ${(/* @__PURE__ */ new Date()).toLocaleDateString()}.
|
|
46
|
+
|
|
47
|
+
${_optionalChain([this, 'access', _ => _.prompts, 'optionalAccess', _2 => _2.agent]) || ""}
|
|
48
|
+
|
|
49
|
+
${_optionalChain([this, 'access', _3 => _3.prompts, 'optionalAccess', _4 => _4.system]) || ""}
|
|
50
|
+
`;
|
|
51
|
+
const modelInstance = this.modelModule.getModel();
|
|
52
|
+
const messages = modelInstance.generateMessages({
|
|
53
|
+
query,
|
|
54
|
+
sessionHistory,
|
|
55
|
+
systemPrompt: systemPrompt.trim()
|
|
56
|
+
});
|
|
57
|
+
const tools = [];
|
|
58
|
+
if (this.mcpModule) {
|
|
59
|
+
tools.push(...this.mcpModule.getTools());
|
|
60
|
+
}
|
|
61
|
+
if (this.a2aModule) {
|
|
62
|
+
tools.push(...await this.a2aModule.getTools());
|
|
63
|
+
}
|
|
64
|
+
const functions = modelInstance.convertToolsToFunctions(tools);
|
|
65
|
+
const processList = [];
|
|
66
|
+
let finalMessage = "";
|
|
67
|
+
let didCallTool = false;
|
|
68
|
+
while (true) {
|
|
69
|
+
const response = await modelInstance.fetchWithContextMessage(
|
|
70
|
+
messages,
|
|
71
|
+
functions
|
|
72
|
+
);
|
|
73
|
+
didCallTool = false;
|
|
74
|
+
_chunk466ED5WNcjs.loggers.intent.debug("messages", { messages });
|
|
75
|
+
const { content, toolCalls } = response;
|
|
76
|
+
_chunk466ED5WNcjs.loggers.intent.debug("content", { content });
|
|
77
|
+
_chunk466ED5WNcjs.loggers.intent.debug("tool_calls", { ...toolCalls });
|
|
78
|
+
if (toolCalls) {
|
|
79
|
+
const messagePayload = _optionalChain([this, 'access', _5 => _5.a2aModule, 'optionalAccess', _6 => _6.getMessagePayload, 'call', _7 => _7(
|
|
80
|
+
query,
|
|
81
|
+
sessionId
|
|
82
|
+
)]);
|
|
83
|
+
for (const toolCall of toolCalls) {
|
|
84
|
+
const toolName = toolCall.name;
|
|
85
|
+
didCallTool = true;
|
|
86
|
+
const selectedTool = tools.filter((tool) => tool.id === toolName)[0];
|
|
87
|
+
let toolResult = "";
|
|
88
|
+
if (this.mcpModule && selectedTool.protocol === "MCP" /* MCP */) {
|
|
89
|
+
const toolArgs = toolCall.arguments;
|
|
90
|
+
_chunk466ED5WNcjs.loggers.intent.debug("MCP tool call", { toolName, toolArgs });
|
|
91
|
+
const result = await this.mcpModule.useTool(
|
|
92
|
+
selectedTool,
|
|
93
|
+
toolArgs
|
|
94
|
+
);
|
|
95
|
+
toolResult = `[Bot Called MCP Tool ${toolName} with args ${JSON.stringify(toolArgs)}]
|
|
96
|
+
` + JSON.stringify(result.content, null, 2);
|
|
97
|
+
} else if (this.a2aModule && selectedTool.protocol === "A2A" /* A2A */) {
|
|
98
|
+
const result = await this.a2aModule.useTool(
|
|
99
|
+
selectedTool,
|
|
100
|
+
messagePayload,
|
|
101
|
+
sessionId
|
|
102
|
+
);
|
|
103
|
+
toolResult = `[Bot Called A2A Tool ${toolName}]
|
|
104
|
+
${result.join("\n")}`;
|
|
105
|
+
} else {
|
|
106
|
+
_chunk466ED5WNcjs.loggers.intent.warn(
|
|
107
|
+
`Unrecognized tool type: ${selectedTool.protocol}`
|
|
108
|
+
);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
_chunk466ED5WNcjs.loggers.intent.debug("toolResult", { toolResult });
|
|
112
|
+
processList.push(toolResult);
|
|
113
|
+
modelInstance.appendMessages(messages, toolResult);
|
|
114
|
+
}
|
|
115
|
+
} else if (content) {
|
|
116
|
+
processList.push(content);
|
|
117
|
+
finalMessage = content;
|
|
118
|
+
}
|
|
119
|
+
if (!didCallTool) break;
|
|
120
|
+
}
|
|
121
|
+
const botResponse = {
|
|
122
|
+
process: processList.join("\n"),
|
|
123
|
+
response: finalMessage
|
|
124
|
+
};
|
|
125
|
+
return botResponse;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Main entry point for processing user queries.
|
|
129
|
+
*
|
|
130
|
+
* Handles the complete query lifecycle:
|
|
131
|
+
* 1. Loads session history from memory
|
|
132
|
+
* 2. Detects intent from the query
|
|
133
|
+
* 3. Fulfills the intent with AI response
|
|
134
|
+
* 4. Updates conversation history
|
|
135
|
+
*
|
|
136
|
+
* @param query - The user's input query
|
|
137
|
+
* @param sessionId - Unique session identifier
|
|
138
|
+
* @param userId - Unique user identifier
|
|
139
|
+
* @returns Object containing the AI-generated response
|
|
140
|
+
*/
|
|
141
|
+
async handleQuery(query, sessionId, userId) {
|
|
142
|
+
const queryStartAt = Date.now();
|
|
143
|
+
const sessionMemory = _optionalChain([this, 'access', _8 => _8.memoryModule, 'optionalAccess', _9 => _9.getSessionMemory, 'call', _10 => _10()]);
|
|
144
|
+
const session = !userId ? void 0 : await _optionalChain([sessionMemory, 'optionalAccess', _11 => _11.getSession, 'call', _12 => _12(userId, sessionId)]);
|
|
145
|
+
const intent = this.intentTriggering(query);
|
|
146
|
+
const result = await this.intentFulfilling(query, sessionId, session);
|
|
147
|
+
if (userId) {
|
|
148
|
+
await _optionalChain([sessionMemory, 'optionalAccess', _13 => _13.addChatToSession, 'call', _14 => _14(userId, sessionId, {
|
|
149
|
+
role: "USER" /* USER */,
|
|
150
|
+
timestamp: queryStartAt,
|
|
151
|
+
content: { type: "text", parts: [query] }
|
|
152
|
+
})]);
|
|
153
|
+
await _optionalChain([sessionMemory, 'optionalAccess', _15 => _15.addChatToSession, 'call', _16 => _16(userId, sessionId, {
|
|
154
|
+
role: "MODEL" /* MODEL */,
|
|
155
|
+
timestamp: Date.now(),
|
|
156
|
+
content: { type: "text", parts: [result.response] }
|
|
157
|
+
})]);
|
|
158
|
+
}
|
|
159
|
+
return { content: result.response };
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
exports.QueryService = QueryService;
|
|
166
|
+
//# sourceMappingURL=chunk-RWQDV2XY.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-RWQDV2XY.cjs","../../src/services/query.service.ts"],"names":[],"mappings":"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","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-RWQDV2XY.cjs","sourcesContent":[null,"import type {\n\tA2AModule,\n\tMCPModule,\n\tMemoryModule,\n\tModelModule,\n} from \"@/modules/index.js\";\nimport type { AinAgentPrompts } from \"@/types/agent.js\";\nimport { ChatRole, type SessionObject } 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 a user query.\n\t *\n\t * @param query - The user's input query\n\t * @returns The detected intent (currently returns the query as-is)\n\t * @todo Implement actual intent detection logic\n\t */\n\tprivate async intentTriggering(query: string) {\n\t\t/* TODO */\n\t\treturn query;\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 sessionId - Session identifier for context\n\t * @param sessionHistory - 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\tsessionId: string,\n\t\tsessionHistory: SessionObject | undefined,\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\n\t\tconst modelInstance = this.modelModule.getModel();\n\t\tconst messages = modelInstance.generateMessages({\n\t\t\tquery,\n\t\t\tsessionHistory,\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\tsessionId,\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\tconst result = 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\ttoolResult =\n\t\t\t\t\t\t\t`[Bot Called MCP Tool ${toolName} with args ${JSON.stringify(toolArgs)}]\\n` +\n\t\t\t\t\t\t\tJSON.stringify(result.content, null, 2);\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\tconst result = 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\tsessionId,\n\t\t\t\t\t\t);\n\t\t\t\t\t\ttoolResult = `[Bot Called A2A Tool ${toolName}]\\n${result.join(\"\\n\")}`;\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 * Main entry point for processing user queries.\n\t *\n\t * Handles the complete query lifecycle:\n\t * 1. Loads session 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 query - The user's input query\n\t * @param sessionId - Unique session identifier\n\t * @param userId - Unique user identifier\n\t * @returns Object containing the AI-generated response\n\t */\n\tpublic async handleQuery(query: string, sessionId: string, userId?: string) {\n\t\t// 1. Load session history with sessionId\n\t\tconst queryStartAt = Date.now();\n\t\tconst sessionMemory = this.memoryModule?.getSessionMemory();\n\t\tconst session = !userId\n\t\t\t? undefined\n\t\t\t: await sessionMemory?.getSession(userId, sessionId);\n\n\t\t// 2. intent triggering\n\t\tconst intent = this.intentTriggering(query);\n\n\t\t// 3. intent fulfillment\n\t\tconst result = await this.intentFulfilling(query, sessionId, session);\n\t\tif (userId) {\n\t\t\tawait sessionMemory?.addChatToSession(userId, sessionId, {\n\t\t\t\trole: ChatRole.USER,\n\t\t\t\ttimestamp: queryStartAt,\n\t\t\t\tcontent: { type: \"text\", parts: [query] },\n\t\t\t});\n\t\t\tawait sessionMemory?.addChatToSession(userId, sessionId, {\n\t\t\t\trole: ChatRole.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"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkN7NGEMKLcjs = require('./chunk-N7NGEMKL.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk2G7V7SC5cjs = require('./chunk-2G7V7SC5.cjs');
|
|
7
|
+
|
|
8
|
+
// src/routes/api.routes.ts
|
|
9
|
+
var _express = require('express');
|
|
10
|
+
var createApiRouter = (agent) => {
|
|
11
|
+
const router = _express.Router.call(void 0, );
|
|
12
|
+
router.use("/api/models", _chunkN7NGEMKLcjs.createModelApiRouter.call(void 0, agent.modelModule));
|
|
13
|
+
if (agent.memoryModule) {
|
|
14
|
+
router.use("/api/sessions", _chunk2G7V7SC5cjs.createSessionApiRouter.call(void 0, agent.memoryModule));
|
|
15
|
+
}
|
|
16
|
+
return router;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.createApiRouter = createApiRouter;
|
|
22
|
+
//# sourceMappingURL=chunk-TNLJ6AVP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-TNLJ6AVP.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,aAAA,EAAe,oDAAA,KAAqB,CAAM,WAAW,CAAC,CAAA;AACjE,EAAA,GAAA,CAAI,KAAA,CAAM,YAAA,EAAc;AACvB,IAAA,MAAA,CAAO,GAAA,CAAI,eAAA,EAAiB,sDAAA,KAAuB,CAAM,YAAY,CAAC,CAAA;AAAA,EACvE;AAEA,EAAA,OAAO,MAAA;AACR,CAAA;ADEA;AACA;AACE;AACF,0CAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-TNLJ6AVP.cjs","sourcesContent":[null,"import { Router } from \"express\";\nimport type { AINAgent } from \"@/index.js\";\n\nimport { createModelApiRouter } from \"./api/models.routes.js\";\nimport { createSessionApiRouter } from \"./api/sessions.routes.js\";\n\nexport const createApiRouter = (agent: AINAgent): Router => {\n\tconst router = Router();\n\n\trouter.use(\"/api/models\", createModelApiRouter(agent.modelModule));\n\tif (agent.memoryModule) {\n\t\trouter.use(\"/api/sessions\", createSessionApiRouter(agent.memoryModule));\n\t}\n\n\treturn router;\n};\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkUQ72NNHVcjs = require('./chunk-UQ72NNHV.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkRPMERDHUcjs = require('./chunk-RPMERDHU.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkRWQDV2XYcjs = require('./chunk-RWQDV2XY.cjs');
|
|
10
|
+
|
|
11
|
+
// src/routes/query.routes.ts
|
|
12
|
+
var _express = require('express');
|
|
13
|
+
var createQueryRouter = (agent, allowStream = false) => {
|
|
14
|
+
const router = _express.Router.call(void 0, );
|
|
15
|
+
const queryService = new (0, _chunkRWQDV2XYcjs.QueryService)(
|
|
16
|
+
agent.modelModule,
|
|
17
|
+
agent.a2aModule,
|
|
18
|
+
agent.mcpModule,
|
|
19
|
+
agent.memoryModule,
|
|
20
|
+
agent.manifest.prompts
|
|
21
|
+
);
|
|
22
|
+
let queryStreamService;
|
|
23
|
+
if (allowStream) {
|
|
24
|
+
queryStreamService = new (0, _chunkUQ72NNHVcjs.QueryStreamService)(
|
|
25
|
+
agent.modelModule,
|
|
26
|
+
agent.a2aModule,
|
|
27
|
+
agent.mcpModule,
|
|
28
|
+
agent.memoryModule,
|
|
29
|
+
agent.manifest.prompts
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const queryController = new (0, _chunkRPMERDHUcjs.QueryController)(queryService, queryStreamService);
|
|
33
|
+
router.post("/query", queryController.handleQueryRequest);
|
|
34
|
+
if (allowStream) {
|
|
35
|
+
router.post("/query-stream", queryController.handleQueryStreamRequest);
|
|
36
|
+
}
|
|
37
|
+
return router;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
exports.createQueryRouter = createQueryRouter;
|
|
43
|
+
//# sourceMappingURL=chunk-TRT5ABOM.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-TRT5ABOM.cjs","../../src/routes/query.routes.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACVA,kCAAuB;AAMhB,IAAM,kBAAA,EAAoB,CAChC,KAAA,EACA,YAAA,EAAc,KAAA,EAAA,GACF;AACZ,EAAA,MAAM,OAAA,EAAS,6BAAA,CAAO;AAEtB,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;AAEA,EAAA,IAAI,kBAAA;AAEJ,EAAA,GAAA,CAAI,WAAA,EAAa;AAChB,IAAA,mBAAA,EAAqB,IAAI,yCAAA;AAAA,MACxB,KAAA,CAAM,WAAA;AAAA,MACN,KAAA,CAAM,SAAA;AAAA,MACN,KAAA,CAAM,SAAA;AAAA,MACN,KAAA,CAAM,YAAA;AAAA,MACN,KAAA,CAAM,QAAA,CAAS;AAAA,IAChB,CAAA;AAAA,EACD;AAEA,EAAA,MAAM,gBAAA,EAAkB,IAAI,sCAAA,CAAgB,YAAA,EAAc,kBAAkB,CAAA;AAC5E,EAAA,MAAA,CAAO,IAAA,CAAK,QAAA,EAAU,eAAA,CAAgB,kBAAkB,CAAA;AAExD,EAAA,GAAA,CAAI,WAAA,EAAa;AAChB,IAAA,MAAA,CAAO,IAAA,CAAK,eAAA,EAAiB,eAAA,CAAgB,wBAAwB,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,MAAA;AACR,CAAA;ADFA;AACA;AACE;AACF,8CAAC","file":"/Users/shyun/comcom/ain-agent/ain-adk/dist/cjs/chunk-TRT5ABOM.cjs","sourcesContent":[null,"import { Router } from \"express\";\nimport { QueryController } from \"@/controllers/query.controller.js\";\nimport type { AINAgent } from \"@/index.js\";\nimport { QueryService } from \"@/services/query.service.js\";\nimport { QueryStreamService } from \"@/services/query-stream.service.js\";\n\nexport const createQueryRouter = (\n\tagent: AINAgent,\n\tallowStream = false,\n): Router => {\n\tconst router = Router();\n\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\n\tlet queryStreamService: QueryStreamService | undefined;\n\n\tif (allowStream) {\n\t\tqueryStreamService = new QueryStreamService(\n\t\t\tagent.modelModule,\n\t\t\tagent.a2aModule,\n\t\t\tagent.mcpModule,\n\t\t\tagent.memoryModule,\n\t\t\tagent.manifest.prompts,\n\t\t);\n\t}\n\n\tconst queryController = new QueryController(queryService, queryStreamService);\n\trouter.post(\"/query\", queryController.handleQueryRequest);\n\n\tif (allowStream) {\n\t\trouter.post(\"/query-stream\", queryController.handleQueryStreamRequest);\n\t}\n\n\treturn router;\n};\n"]}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunk466ED5WNcjs = require('./chunk-466ED5WN.cjs');
|
|
4
|
+
|
|
5
|
+
// src/services/query-stream.service.ts
|
|
6
|
+
var QueryStreamService = class {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
constructor(modelModule, a2aModule, mcpModule, memoryModule, prompts) {
|
|
13
|
+
this.modelModule = modelModule;
|
|
14
|
+
this.a2aModule = a2aModule;
|
|
15
|
+
this.mcpModule = mcpModule;
|
|
16
|
+
this.memoryModule = memoryModule;
|
|
17
|
+
this.prompts = prompts;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Detects the intent from a user query.
|
|
21
|
+
*
|
|
22
|
+
* @param query - The user's input query
|
|
23
|
+
* @returns The detected intent (currently returns the query as-is)
|
|
24
|
+
* @todo Implement actual intent detection logic
|
|
25
|
+
*/
|
|
26
|
+
async intentTriggering(query) {
|
|
27
|
+
return query;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Fulfills the detected intent by generating a response.
|
|
31
|
+
*
|
|
32
|
+
* Manages the complete inference loop including:
|
|
33
|
+
* - Loading prompts and conversation history
|
|
34
|
+
* - Collecting available tools from modules
|
|
35
|
+
* - Executing model inference with tool support
|
|
36
|
+
* - Processing tool calls iteratively until completion
|
|
37
|
+
*
|
|
38
|
+
* @param query - The user's input query
|
|
39
|
+
* @param sessionId - Session identifier for context
|
|
40
|
+
* @param sessionHistory - Previous conversation history
|
|
41
|
+
* @returns Object containing process steps and final response
|
|
42
|
+
*/
|
|
43
|
+
async *intentFulfilling(query, sessionId, sessionHistory) {
|
|
44
|
+
try {
|
|
45
|
+
const systemPrompt = `
|
|
46
|
+
Today is ${(/* @__PURE__ */ new Date()).toLocaleDateString()}.
|
|
47
|
+
|
|
48
|
+
${_optionalChain([this, 'access', _ => _.prompts, 'optionalAccess', _2 => _2.agent]) || ""}
|
|
49
|
+
|
|
50
|
+
${_optionalChain([this, 'access', _3 => _3.prompts, 'optionalAccess', _4 => _4.system]) || ""}
|
|
51
|
+
`;
|
|
52
|
+
const modelInstance = this.modelModule.getModel();
|
|
53
|
+
const messages = modelInstance.generateMessages({
|
|
54
|
+
query,
|
|
55
|
+
sessionHistory,
|
|
56
|
+
systemPrompt: systemPrompt.trim()
|
|
57
|
+
});
|
|
58
|
+
const tools = [];
|
|
59
|
+
if (this.mcpModule) {
|
|
60
|
+
tools.push(...this.mcpModule.getTools());
|
|
61
|
+
}
|
|
62
|
+
if (this.a2aModule) {
|
|
63
|
+
tools.push(...await this.a2aModule.getTools());
|
|
64
|
+
}
|
|
65
|
+
const functions = modelInstance.convertToolsToFunctions(tools);
|
|
66
|
+
const processList = [];
|
|
67
|
+
const finalMessage = "";
|
|
68
|
+
let didCallTool = false;
|
|
69
|
+
while (true) {
|
|
70
|
+
const responseStream = await modelInstance.fetchStreamWithContextMessage(
|
|
71
|
+
messages,
|
|
72
|
+
functions
|
|
73
|
+
);
|
|
74
|
+
didCallTool = false;
|
|
75
|
+
const assembledToolCalls = [];
|
|
76
|
+
_chunk466ED5WNcjs.loggers.intentStream.debug("messages", { messages });
|
|
77
|
+
for await (const chunk of responseStream) {
|
|
78
|
+
const delta = chunk.delta;
|
|
79
|
+
if (_optionalChain([delta, 'optionalAccess', _5 => _5.tool_calls])) {
|
|
80
|
+
didCallTool = true;
|
|
81
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
82
|
+
const index = toolCallDelta.index;
|
|
83
|
+
if (!assembledToolCalls[index]) {
|
|
84
|
+
assembledToolCalls[index] = {
|
|
85
|
+
id: "",
|
|
86
|
+
type: "function",
|
|
87
|
+
function: { name: "", arguments: "" }
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (toolCallDelta.id) {
|
|
91
|
+
assembledToolCalls[index].id = toolCallDelta.id;
|
|
92
|
+
}
|
|
93
|
+
if (_optionalChain([toolCallDelta, 'access', _6 => _6.function, 'optionalAccess', _7 => _7.name])) {
|
|
94
|
+
assembledToolCalls[index].function.name = toolCallDelta.function.name;
|
|
95
|
+
}
|
|
96
|
+
if (_optionalChain([toolCallDelta, 'access', _8 => _8.function, 'optionalAccess', _9 => _9.arguments])) {
|
|
97
|
+
assembledToolCalls[index].function.arguments += toolCallDelta.function.arguments;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} else if (_optionalChain([chunk, 'access', _10 => _10.delta, 'optionalAccess', _11 => _11.content])) {
|
|
101
|
+
yield {
|
|
102
|
+
event: "text_chunk",
|
|
103
|
+
data: { delta: chunk.delta.content }
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_chunk466ED5WNcjs.loggers.intentStream.debug("assembledToolCalls", {
|
|
108
|
+
assembledToolCalls
|
|
109
|
+
});
|
|
110
|
+
if (didCallTool && assembledToolCalls.length > 0) {
|
|
111
|
+
const messagePayload = _optionalChain([this, 'access', _12 => _12.a2aModule, 'optionalAccess', _13 => _13.getMessagePayload, 'call', _14 => _14(
|
|
112
|
+
query,
|
|
113
|
+
sessionId
|
|
114
|
+
)]);
|
|
115
|
+
for (const toolCall of assembledToolCalls) {
|
|
116
|
+
const toolName = toolCall.function.name;
|
|
117
|
+
const toolArgs = JSON.parse(toolCall.function.arguments);
|
|
118
|
+
const selectedTool = tools.filter(
|
|
119
|
+
(tool) => tool.id === toolName
|
|
120
|
+
)[0];
|
|
121
|
+
yield { event: "tool_start", data: { toolName, toolArgs } };
|
|
122
|
+
let toolResult = "";
|
|
123
|
+
if (this.mcpModule && selectedTool.protocol === "MCP" /* MCP */) {
|
|
124
|
+
const toolArgs2 = JSON.parse(toolCall.function.arguments);
|
|
125
|
+
_chunk466ED5WNcjs.loggers.intent.debug("MCP tool call", { toolName, toolArgs: toolArgs2 });
|
|
126
|
+
const result = await this.mcpModule.useTool(
|
|
127
|
+
selectedTool,
|
|
128
|
+
toolArgs2
|
|
129
|
+
);
|
|
130
|
+
toolResult = `[Bot Called MCP Tool ${toolName} with args ${JSON.stringify(toolArgs2)}]
|
|
131
|
+
` + JSON.stringify(result.content, null, 2);
|
|
132
|
+
} else if (this.a2aModule && selectedTool.protocol === "A2A" /* A2A */) {
|
|
133
|
+
const result = await this.a2aModule.useTool(
|
|
134
|
+
selectedTool,
|
|
135
|
+
messagePayload,
|
|
136
|
+
sessionId
|
|
137
|
+
);
|
|
138
|
+
toolResult = `[Bot Called A2A Tool ${toolName}]
|
|
139
|
+
${result.join("\n")}`;
|
|
140
|
+
} else {
|
|
141
|
+
_chunk466ED5WNcjs.loggers.intent.warn(
|
|
142
|
+
`Unrecognized tool type: ${selectedTool.protocol}`
|
|
143
|
+
);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
yield {
|
|
147
|
+
event: "tool_output",
|
|
148
|
+
data: { toolName, result: toolResult }
|
|
149
|
+
};
|
|
150
|
+
_chunk466ED5WNcjs.loggers.intent.debug("toolResult", { toolResult });
|
|
151
|
+
processList.push(toolResult);
|
|
152
|
+
modelInstance.appendMessages(messages, toolResult);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (!didCallTool) break;
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
_chunk466ED5WNcjs.loggers.intent.error("Error in intentFulfilling generator", { error });
|
|
159
|
+
if (error instanceof Error) {
|
|
160
|
+
yield {
|
|
161
|
+
event: "error",
|
|
162
|
+
data: { message: error.message || "An unknown error occurred." }
|
|
163
|
+
};
|
|
164
|
+
} else {
|
|
165
|
+
yield {
|
|
166
|
+
event: "error",
|
|
167
|
+
data: { message: "An unknown error occurred." }
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Main entry point for processing user queries.
|
|
174
|
+
*
|
|
175
|
+
* Handles the complete query lifecycle:
|
|
176
|
+
* 1. Loads session history from memory
|
|
177
|
+
* 2. Detects intent from the query
|
|
178
|
+
* 3. Fulfills the intent with AI response
|
|
179
|
+
* 4. Updates conversation history
|
|
180
|
+
*
|
|
181
|
+
* @param query - The user's input query
|
|
182
|
+
* @param sessionId - Unique session identifier
|
|
183
|
+
* @returns Object containing the AI-generated response
|
|
184
|
+
*/
|
|
185
|
+
async handleQueryStream(query, sessionId, res, userId) {
|
|
186
|
+
const queryStartAt = Date.now();
|
|
187
|
+
const sessionMemory = _optionalChain([this, 'access', _15 => _15.memoryModule, 'optionalAccess', _16 => _16.getSessionMemory, 'call', _17 => _17()]);
|
|
188
|
+
const session = !userId ? void 0 : await _optionalChain([sessionMemory, 'optionalAccess', _18 => _18.getSession, 'call', _19 => _19(sessionId, userId)]);
|
|
189
|
+
const intent = this.intentTriggering(query);
|
|
190
|
+
try {
|
|
191
|
+
const stream = await this.intentFulfilling(
|
|
192
|
+
query,
|
|
193
|
+
sessionId,
|
|
194
|
+
session || { chats: {} }
|
|
195
|
+
);
|
|
196
|
+
let finalResponseText = "";
|
|
197
|
+
for await (const event of stream) {
|
|
198
|
+
if (event.event === "text_chunk" && event.data.delta) {
|
|
199
|
+
_chunk466ED5WNcjs.loggers.intentStream.debug("text_chunk", { event });
|
|
200
|
+
finalResponseText += event.data.delta;
|
|
201
|
+
}
|
|
202
|
+
const sseFormattedEvent = `event: ${event.event}
|
|
203
|
+
data: ${JSON.stringify(event.data)}
|
|
204
|
+
|
|
205
|
+
`;
|
|
206
|
+
res.write(sseFormattedEvent);
|
|
207
|
+
}
|
|
208
|
+
} catch (error) {
|
|
209
|
+
_chunk466ED5WNcjs.loggers.intent.error("Error in handleQuery", { error });
|
|
210
|
+
res.write(
|
|
211
|
+
`event: error
|
|
212
|
+
data: ${JSON.stringify({ message: "Stream failed" })}
|
|
213
|
+
|
|
214
|
+
`
|
|
215
|
+
);
|
|
216
|
+
} finally {
|
|
217
|
+
res.end();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
exports.QueryStreamService = QueryStreamService;
|
|
225
|
+
//# sourceMappingURL=chunk-UQ72NNHV.cjs.map
|