@flink-app/flink 0.14.3 → 2.0.0-alpha.100
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/CHANGELOG.md +1051 -0
- package/SCHEMA_EXTRACTION_ANALYSIS.md +494 -0
- package/SIMPLE_AST_FEASIBILITY.md +570 -0
- package/bin/flink.ts +13 -2
- package/cli/build.ts +24 -44
- package/cli/clean.ts +13 -25
- package/cli/cli-utils.ts +190 -17
- package/cli/dev.ts +252 -0
- package/cli/loadEnvFiles.ts +116 -0
- package/cli/run.ts +45 -62
- package/dist/bin/flink.js +61 -2
- package/dist/cli/build.js +20 -25
- package/dist/cli/clean.js +12 -10
- package/dist/cli/cli-utils.d.ts +34 -3
- package/dist/cli/cli-utils.js +193 -12
- package/dist/cli/dev.d.ts +2 -0
- package/dist/cli/dev.js +279 -0
- package/dist/cli/loadEnvFiles.d.ts +30 -0
- package/dist/cli/loadEnvFiles.js +113 -0
- package/dist/cli/run.js +47 -46
- package/dist/src/DependencyTracker.d.ts +44 -0
- package/dist/src/DependencyTracker.js +239 -0
- package/dist/src/FlinkApp.d.ts +163 -10
- package/dist/src/FlinkApp.js +847 -184
- package/dist/src/FlinkContext.d.ts +41 -0
- package/dist/src/FlinkErrors.d.ts +19 -6
- package/dist/src/FlinkErrors.js +36 -42
- package/dist/src/FlinkHttpHandler.d.ts +219 -26
- package/dist/src/FlinkHttpHandler.js +37 -1
- package/dist/src/FlinkJob.d.ts +10 -0
- package/dist/src/FlinkLog.d.ts +82 -18
- package/dist/src/FlinkLog.js +165 -13
- package/dist/src/FlinkLogFactory.d.ts +288 -0
- package/dist/src/FlinkLogFactory.js +619 -0
- package/dist/src/FlinkRepo.d.ts +10 -2
- package/dist/src/FlinkRepo.js +11 -1
- package/dist/src/FlinkRequestContext.d.ts +63 -0
- package/dist/src/FlinkRequestContext.js +74 -0
- package/dist/src/FlinkResponse.d.ts +6 -0
- package/dist/src/FlinkService.d.ts +38 -0
- package/dist/src/FlinkService.js +46 -0
- package/dist/src/LeaderElection.d.ts +45 -0
- package/dist/src/LeaderElection.js +269 -0
- package/dist/src/SchemaCache.d.ts +84 -0
- package/dist/src/SchemaCache.js +289 -0
- package/dist/src/TypeScriptCompiler.d.ts +161 -51
- package/dist/src/TypeScriptCompiler.js +1253 -617
- package/dist/src/TypeScriptUtils.js +4 -0
- package/dist/src/ai/AgentRunner.d.ts +39 -0
- package/dist/src/ai/AgentRunner.js +760 -0
- package/dist/src/ai/ConversationAgent.d.ts +279 -0
- package/dist/src/ai/ConversationAgent.js +404 -0
- package/dist/src/ai/ConversationFlinkAgent.d.ts +278 -0
- package/dist/src/ai/ConversationFlinkAgent.js +404 -0
- package/dist/src/ai/FlinkAgent.d.ts +690 -0
- package/dist/src/ai/FlinkAgent.js +729 -0
- package/dist/src/ai/FlinkTool.d.ts +135 -0
- package/dist/src/ai/FlinkTool.js +2 -0
- package/dist/src/ai/InMemoryConversationAgent.d.ts +121 -0
- package/dist/src/ai/InMemoryConversationAgent.js +209 -0
- package/dist/src/ai/LLMAdapter.d.ts +148 -0
- package/dist/src/ai/LLMAdapter.js +2 -0
- package/dist/src/ai/PersistentFlinkAgent.d.ts +278 -0
- package/dist/src/ai/PersistentFlinkAgent.js +403 -0
- package/dist/src/ai/SubAgentExecutor.d.ts +38 -0
- package/dist/src/ai/SubAgentExecutor.js +223 -0
- package/dist/src/ai/ToolExecutor.d.ts +64 -0
- package/dist/src/ai/ToolExecutor.js +497 -0
- package/dist/src/ai/agentInstructions.d.ts +68 -0
- package/dist/src/ai/agentInstructions.js +286 -0
- package/dist/src/ai/index.d.ts +8 -0
- package/dist/src/ai/index.js +26 -0
- package/dist/src/ai/instructionFileLoader.d.ts +44 -0
- package/dist/src/ai/instructionFileLoader.js +179 -0
- package/dist/src/auth/FlinkAuthPlugin.d.ts +1 -1
- package/dist/src/handlers/StreamWriterFactory.d.ts +20 -0
- package/dist/src/handlers/StreamWriterFactory.js +83 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +17 -0
- package/dist/src/loadPluginSchemas.d.ts +45 -0
- package/dist/src/loadPluginSchemas.js +143 -0
- package/dist/src/schema-extraction/ComplexTypeDetection.d.ts +40 -0
- package/dist/src/schema-extraction/ComplexTypeDetection.js +75 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.d.ts +321 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.js +925 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.spec.d.ts +1 -0
- package/dist/src/schema-extraction/TypeScriptSourceParser.spec.js +233 -0
- package/dist/src/schema-extraction/TypeScriptTokenizer.d.ts +57 -0
- package/dist/src/schema-extraction/TypeScriptTokenizer.js +177 -0
- package/dist/src/schema-extraction/index.d.ts +2 -0
- package/dist/src/schema-extraction/index.js +20 -0
- package/dist/src/schema-extraction/types.d.ts +31 -0
- package/dist/src/schema-extraction/types.js +2 -0
- package/dist/src/utils/loadFlinkConfig.d.ts +53 -0
- package/dist/src/utils/loadFlinkConfig.js +77 -0
- package/dist/src/utils.d.ts +30 -0
- package/dist/src/utils.js +52 -0
- package/dist/src/workers/SchemaGeneratorWorker.d.ts +1 -0
- package/dist/src/workers/SchemaGeneratorWorker.js +49 -0
- package/dist/src/workers/WorkerPool.d.ts +60 -0
- package/dist/src/workers/WorkerPool.js +306 -0
- package/examples/logging-hierarchical-example.ts +125 -0
- package/package.json +29 -4
- package/readme.md +499 -0
- package/spec/AgentDescendantDetection.spec.ts +335 -0
- package/spec/AgentDuplicateDetection.spec.ts +112 -0
- package/spec/AgentObserver.spec.ts +266 -0
- package/spec/AgentRunner.spec.ts +1062 -0
- package/spec/AsyncLocalStorageContext.spec.ts +223 -0
- package/spec/ConversationHooks.spec.ts +257 -0
- package/spec/FlinkAgent.spec.ts +681 -0
- package/spec/FlinkApp.htmlResponse.spec.ts +260 -0
- package/spec/FlinkApp.onError.invocation.spec.ts +151 -0
- package/spec/FlinkApp.onError.spec.ts +1 -2
- package/spec/FlinkApp.query.spec.ts +107 -0
- package/spec/FlinkApp.routeOrdering.spec.ts +61 -0
- package/spec/FlinkApp.undefinedResponse.spec.ts +123 -0
- package/spec/FlinkApp.validationMode.spec.ts +155 -0
- package/spec/FlinkJob.spec.ts +171 -0
- package/spec/FlinkLogFactory.spec.ts +337 -0
- package/spec/FlinkRepo.spec.ts +1 -1
- package/spec/LeaderElection.spec.ts +174 -0
- package/spec/StreamingIntegration.spec.ts +139 -0
- package/spec/ToolExecutor.spec.ts +465 -0
- package/spec/TypeScriptCompiler.spec.ts +1 -1
- package/spec/TypeScriptSourceParser.spec.ts +1215 -0
- package/spec/TypeScriptTokenizer.spec.ts +366 -0
- package/spec/ai/ContextCompaction.spec.ts +405 -0
- package/spec/ai/ConversationAgent.spec.ts +520 -0
- package/spec/ai/InMemoryConversationAgent.spec.ts +144 -0
- package/spec/ai/agentInstructions.spec.ts +358 -0
- package/spec/fixtures/agent-instructions/TestAgent.ts +24 -0
- package/spec/fixtures/agent-instructions/simple.md +3 -0
- package/spec/fixtures/agent-instructions/template.md +18 -0
- package/spec/fixtures/agent-instructions/yaml-format.yaml +9 -0
- package/spec/mock-project/dist/.tsbuildinfo +1 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar.js +56 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar2.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema2.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema3.js +52 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema2.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile2.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler.js +53 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler2.js +55 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchCar.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOnboardingSession.js +75 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOrderWithComplexTypes.js +57 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchProductWithIntersection.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchUserWithUnion.js +58 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostCar.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogin.js +55 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogout.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/handlers/PutCar.js +54 -0
- package/spec/mock-project/dist/spec/mock-project/src/index.js +83 -0
- package/spec/mock-project/dist/spec/mock-project/src/repos/CarRepo.js +26 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/Car.js +2 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/DefaultExportSchema.js +2 -0
- package/spec/mock-project/dist/spec/mock-project/src/schemas/FileWithTwoSchemas.js +2 -0
- package/spec/mock-project/dist/src/FlinkApp.js +1000 -0
- package/spec/mock-project/dist/src/FlinkContext.js +2 -0
- package/spec/mock-project/dist/src/FlinkErrors.js +143 -0
- package/spec/mock-project/dist/src/FlinkHttpHandler.js +47 -0
- package/spec/mock-project/dist/src/FlinkJob.js +2 -0
- package/spec/mock-project/dist/src/FlinkLog.js +119 -0
- package/spec/mock-project/dist/src/FlinkLogFactory.js +617 -0
- package/spec/mock-project/dist/src/FlinkPlugin.js +2 -0
- package/spec/mock-project/dist/src/FlinkRepo.js +224 -0
- package/spec/mock-project/dist/src/FlinkRequestContext.js +74 -0
- package/spec/mock-project/dist/src/FlinkResponse.js +2 -0
- package/spec/mock-project/dist/src/ai/AgentExecutor.js +279 -0
- package/spec/mock-project/dist/src/ai/AgentRunner.js +632 -0
- package/spec/mock-project/dist/src/ai/ConversationAgent.js +402 -0
- package/spec/mock-project/dist/src/ai/ConversationFlinkAgent.js +422 -0
- package/spec/mock-project/dist/src/ai/FlinkAgent.js +699 -0
- package/spec/mock-project/dist/src/ai/FlinkTool.js +2 -0
- package/spec/mock-project/dist/src/ai/InMemoryConversationAgent.js +209 -0
- package/spec/mock-project/dist/src/ai/LLMAdapter.js +2 -0
- package/spec/mock-project/dist/src/ai/SubAgentExecutor.js +223 -0
- package/spec/mock-project/dist/src/ai/ToolExecutor.js +412 -0
- package/spec/mock-project/dist/src/ai/agentInstructions.js +246 -0
- package/spec/mock-project/dist/src/auth/FlinkAuthPlugin.js +2 -0
- package/spec/mock-project/dist/src/auth/FlinkAuthUser.js +2 -0
- package/spec/mock-project/dist/src/handlers/GetCar.js +26 -52
- package/spec/mock-project/dist/src/handlers/GetCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCar2.js +32 -54
- package/spec/mock-project/dist/src/handlers/GetCar2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +26 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +28 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +29 -48
- package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +26 -50
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +28 -50
- package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +27 -53
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +29 -53
- package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +16 -49
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +25 -50
- package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchCar.js +27 -53
- package/spec/mock-project/dist/src/handlers/PatchCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js +44 -70
- package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js +27 -53
- package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js +28 -54
- package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js +28 -54
- package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostCar.js +24 -50
- package/spec/mock-project/dist/src/handlers/PostCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostLogin.js +25 -51
- package/spec/mock-project/dist/src/handlers/PostLogin.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PostLogout.js +24 -50
- package/spec/mock-project/dist/src/handlers/PostLogout.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/PutCar.js +24 -50
- package/spec/mock-project/dist/src/handlers/PutCar.js.map +1 -0
- package/spec/mock-project/dist/src/handlers/StreamWriterFactory.js +83 -0
- package/spec/mock-project/dist/src/index.js +52 -76
- package/spec/mock-project/dist/src/index.js.map +1 -0
- package/spec/mock-project/dist/src/mock-data-generator.js +9 -0
- package/spec/mock-project/dist/src/repos/CarRepo.js +12 -24
- package/spec/mock-project/dist/src/repos/CarRepo.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/Car.js +3 -1
- package/spec/mock-project/dist/src/schemas/Car.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js +3 -1
- package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js.map +1 -0
- package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js +3 -1
- package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js.map +1 -0
- package/spec/mock-project/dist/src/utils.js +290 -0
- package/spec/mock-project/tsconfig.json +6 -1
- package/spec/schema-generation-nested-objects.spec.ts +97 -0
- package/spec/testHelpers.ts +49 -0
- package/spec/utils.caseConversion.spec.ts +78 -0
- package/spec/utils.spec.ts +13 -13
- package/src/DependencyTracker.ts +166 -0
- package/src/FlinkApp.ts +919 -155
- package/src/FlinkContext.ts +43 -0
- package/src/FlinkErrors.ts +32 -12
- package/src/FlinkHttpHandler.ts +246 -28
- package/src/FlinkJob.ts +11 -0
- package/src/FlinkLog.ts +119 -12
- package/src/FlinkLogFactory.ts +699 -0
- package/src/FlinkRepo.ts +10 -3
- package/src/FlinkRequestContext.ts +95 -0
- package/src/FlinkResponse.ts +6 -0
- package/src/FlinkService.ts +49 -0
- package/src/LeaderElection.ts +203 -0
- package/src/SchemaCache.ts +232 -0
- package/src/TypeScriptCompiler.ts +1347 -610
- package/src/TypeScriptUtils.ts +5 -0
- package/src/ai/AgentRunner.ts +646 -0
- package/src/ai/ConversationAgent.ts +413 -0
- package/src/ai/FlinkAgent.ts +1069 -0
- package/src/ai/FlinkTool.ts +165 -0
- package/src/ai/InMemoryConversationAgent.ts +149 -0
- package/src/ai/LLMAdapter.ts +126 -0
- package/src/ai/ToolExecutor.ts +485 -0
- package/src/ai/agentInstructions.ts +245 -0
- package/src/ai/index.ts +8 -0
- package/src/ai/instructionFileLoader.ts +156 -0
- package/src/auth/FlinkAuthPlugin.ts +2 -1
- package/src/handlers/StreamWriterFactory.ts +84 -0
- package/src/index.ts +14 -0
- package/src/loadPluginSchemas.ts +141 -0
- package/src/schema-extraction/TypeScriptSourceParser.ts +1058 -0
- package/src/schema-extraction/TypeScriptTokenizer.ts +205 -0
- package/src/schema-extraction/index.ts +2 -0
- package/src/schema-extraction/types.ts +34 -0
- package/src/utils/loadFlinkConfig.ts +89 -0
- package/src/utils.ts +52 -0
- package/tsconfig.json +6 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.InMemoryConversationAgent = void 0;
|
|
55
|
+
var ConversationAgent_1 = require("./ConversationAgent");
|
|
56
|
+
/**
|
|
57
|
+
* In-memory conversation storage (development/testing only).
|
|
58
|
+
*
|
|
59
|
+
* ⚠️ WARNING: Data is lost when the process restarts.
|
|
60
|
+
* Use MongoDB, Redis, or another persistent backend for production.
|
|
61
|
+
*/
|
|
62
|
+
var conversationStore = new Map();
|
|
63
|
+
/**
|
|
64
|
+
* Opinionated base class for agents with in-memory conversation persistence.
|
|
65
|
+
*
|
|
66
|
+
* Provides ready-to-use Map-based storage for rapid prototyping and testing.
|
|
67
|
+
* Storage methods (loadConversation/saveConversation) are already implemented - just extend and configure!
|
|
68
|
+
*
|
|
69
|
+
* ⚠️ **WARNING**: Data is stored in memory and lost on process restart.
|
|
70
|
+
* Only use for:
|
|
71
|
+
* - Rapid prototyping
|
|
72
|
+
* - Development environments
|
|
73
|
+
* - Integration testing
|
|
74
|
+
* - Demo applications
|
|
75
|
+
*
|
|
76
|
+
* For production, extend `ConversationAgent` with persistent storage (MongoDB, Redis, etc.)
|
|
77
|
+
*
|
|
78
|
+
* @example Basic Usage
|
|
79
|
+
* ```typescript
|
|
80
|
+
* export default class MyAgent extends InMemoryConversationAgent<AppContext> {
|
|
81
|
+
* id = "my-agent";
|
|
82
|
+
* description = "Quick prototype agent";
|
|
83
|
+
* instructions = "You are a helpful assistant...";
|
|
84
|
+
* tools = ["search-knowledge"];
|
|
85
|
+
* // That's it! No loadConversation or saveConversation needed
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example With Custom Behavior
|
|
90
|
+
* ```typescript
|
|
91
|
+
* export default class CustomAgent extends InMemoryConversationAgent<AppContext> {
|
|
92
|
+
* id = "custom-agent";
|
|
93
|
+
* description = "Custom agent with hooks";
|
|
94
|
+
* instructions = "...";
|
|
95
|
+
*
|
|
96
|
+
* protected async afterRun(result, context) {
|
|
97
|
+
* await super.afterRun(result, context); // Still saves to memory
|
|
98
|
+
* // Add custom logic (logging, analytics, etc.)
|
|
99
|
+
* }
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Testing
|
|
104
|
+
* ```typescript
|
|
105
|
+
* beforeEach(() => {
|
|
106
|
+
* InMemoryConversationAgent.clearAll(); // Reset between tests
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* it("should maintain conversation context", async () => {
|
|
110
|
+
* const agent = new MyAgent();
|
|
111
|
+
* await agent.execute({ message: "Hello", conversationId: "test-1" });
|
|
112
|
+
*
|
|
113
|
+
* expect(InMemoryConversationAgent.getConversationCount()).toBe(1);
|
|
114
|
+
* expect(InMemoryConversationAgent.getAllConversationIds()).toContain("test-1");
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @template Context - Application context type extending FlinkContext
|
|
119
|
+
*/
|
|
120
|
+
var InMemoryConversationAgent = /** @class */ (function (_super) {
|
|
121
|
+
__extends(InMemoryConversationAgent, _super);
|
|
122
|
+
function InMemoryConversationAgent() {
|
|
123
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Load conversation from in-memory Map.
|
|
127
|
+
*
|
|
128
|
+
* @internal Implemented by InMemoryConversationAgent - no need to override
|
|
129
|
+
*/
|
|
130
|
+
InMemoryConversationAgent.prototype.loadConversation = function (conversationId) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
ConversationAgent_1.logger.debug("Loading conversation ".concat(conversationId));
|
|
134
|
+
return [2 /*return*/, conversationStore.get(conversationId) || null];
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Save conversation to in-memory Map.
|
|
140
|
+
*
|
|
141
|
+
* @internal Implemented by InMemoryConversationAgent - no need to override
|
|
142
|
+
*/
|
|
143
|
+
InMemoryConversationAgent.prototype.saveConversation = function (conversationId, data, result, context) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
ConversationAgent_1.logger.debug("Saving ".concat(data.messages.length, " messages"));
|
|
147
|
+
conversationStore.set(conversationId, data);
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Clear all stored conversations.
|
|
154
|
+
* Useful for testing and resetting state.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* beforeEach(() => {
|
|
159
|
+
* InMemoryConversationAgent.clearAll();
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
InMemoryConversationAgent.clearAll = function () {
|
|
164
|
+
conversationStore.clear();
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Get the number of stored conversations.
|
|
168
|
+
* Useful for testing and debugging.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* expect(InMemoryConversationAgent.getConversationCount()).toBe(2);
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
InMemoryConversationAgent.getConversationCount = function () {
|
|
176
|
+
return conversationStore.size;
|
|
177
|
+
};
|
|
178
|
+
/**
|
|
179
|
+
* Get a specific conversation by ID.
|
|
180
|
+
* Useful for testing and debugging.
|
|
181
|
+
*
|
|
182
|
+
* @param conversationId - The conversation ID to retrieve
|
|
183
|
+
* @returns Conversation data or undefined if not found
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const conv = InMemoryConversationAgent.getConversation("conv-123");
|
|
188
|
+
* expect(conv?.messages.length).toBe(4);
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
InMemoryConversationAgent.getConversation = function (conversationId) {
|
|
192
|
+
return conversationStore.get(conversationId);
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Get all stored conversation IDs.
|
|
196
|
+
* Useful for testing and debugging.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const ids = InMemoryConversationAgent.getAllConversationIds();
|
|
201
|
+
* expect(ids).toContain("conv-123");
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
InMemoryConversationAgent.getAllConversationIds = function () {
|
|
205
|
+
return Array.from(conversationStore.keys());
|
|
206
|
+
};
|
|
207
|
+
return InMemoryConversationAgent;
|
|
208
|
+
}(ConversationAgent_1.ConversationAgent));
|
|
209
|
+
exports.InMemoryConversationAgent = InMemoryConversationAgent;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.SubAgentExecutor = void 0;
|
|
51
|
+
var zod_1 = require("zod");
|
|
52
|
+
var FlinkLog_1 = require("../FlinkLog");
|
|
53
|
+
var utils_1 = require("../utils");
|
|
54
|
+
var uuid_1 = require("uuid");
|
|
55
|
+
/**
|
|
56
|
+
* Special tool executor that wraps a sub-agent
|
|
57
|
+
* Automatically created for each agent reference in parent agent's `agents` array
|
|
58
|
+
*/
|
|
59
|
+
var SubAgentExecutor = /** @class */ (function () {
|
|
60
|
+
function SubAgentExecutor(subAgentInstanceName, ctx) {
|
|
61
|
+
this.ctx = ctx;
|
|
62
|
+
this.subAgentInstanceName = subAgentInstanceName;
|
|
63
|
+
// Convert instance name to kebab-case for consistency with agent IDs
|
|
64
|
+
this.subAgentId = (0, utils_1.toKebabCase)(subAgentInstanceName);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Execute the sub-agent with the given input
|
|
68
|
+
*/
|
|
69
|
+
SubAgentExecutor.prototype.execute = function (input, overrides, parentContext // Parent agent context for sub-agent delegation
|
|
70
|
+
) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
var user, userPermissions, agents, subAgent, boundAgent, strategy, conversationId, response, result, err_1;
|
|
73
|
+
var _a;
|
|
74
|
+
return __generator(this, function (_b) {
|
|
75
|
+
switch (_b.label) {
|
|
76
|
+
case 0:
|
|
77
|
+
user = overrides === null || overrides === void 0 ? void 0 : overrides.user;
|
|
78
|
+
userPermissions = overrides === null || overrides === void 0 ? void 0 : overrides.permissions;
|
|
79
|
+
_b.label = 1;
|
|
80
|
+
case 1:
|
|
81
|
+
_b.trys.push([1, 3, , 4]);
|
|
82
|
+
agents = this.ctx.agents;
|
|
83
|
+
if (!agents) {
|
|
84
|
+
return [2 /*return*/, {
|
|
85
|
+
success: false,
|
|
86
|
+
error: "Agents not available in context",
|
|
87
|
+
code: "NO_AGENTS",
|
|
88
|
+
}];
|
|
89
|
+
}
|
|
90
|
+
subAgent = agents[this.subAgentInstanceName];
|
|
91
|
+
if (!subAgent) {
|
|
92
|
+
return [2 /*return*/, {
|
|
93
|
+
success: false,
|
|
94
|
+
error: "Sub-agent ".concat(this.subAgentInstanceName, " not found"),
|
|
95
|
+
code: "AGENT_NOT_FOUND",
|
|
96
|
+
}];
|
|
97
|
+
}
|
|
98
|
+
boundAgent = subAgent;
|
|
99
|
+
if (user) {
|
|
100
|
+
boundAgent = boundAgent.withUser(user);
|
|
101
|
+
}
|
|
102
|
+
if (userPermissions) {
|
|
103
|
+
boundAgent = boundAgent.withPermissions(userPermissions);
|
|
104
|
+
}
|
|
105
|
+
strategy = subAgent.conversationStrategy || "inherit";
|
|
106
|
+
conversationId = void 0;
|
|
107
|
+
if (strategy === "inherit") {
|
|
108
|
+
// Use parent's conversation ID
|
|
109
|
+
conversationId = parentContext === null || parentContext === void 0 ? void 0 : parentContext.conversationId;
|
|
110
|
+
}
|
|
111
|
+
else if (strategy === "independent") {
|
|
112
|
+
// Create nested conversation
|
|
113
|
+
conversationId = (parentContext === null || parentContext === void 0 ? void 0 : parentContext.conversationId)
|
|
114
|
+
? "".concat(parentContext.conversationId, ":").concat(this.subAgentInstanceName, ":").concat((0, utils_1.generateShortId)())
|
|
115
|
+
: (0, uuid_1.v4)();
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// strategy === "none"
|
|
119
|
+
conversationId = undefined;
|
|
120
|
+
}
|
|
121
|
+
FlinkLog_1.log.debug("Delegating to sub-agent ".concat(this.subAgentInstanceName, " from parent ").concat((parentContext === null || parentContext === void 0 ? void 0 : parentContext.agentId) || "unknown", ", ") +
|
|
122
|
+
"strategy: \"".concat(strategy, "\", conversationId: ").concat(conversationId || "none"));
|
|
123
|
+
response = boundAgent.run({
|
|
124
|
+
message: input.query || input.message || JSON.stringify(input),
|
|
125
|
+
user: user,
|
|
126
|
+
userPermissions: userPermissions,
|
|
127
|
+
conversationId: conversationId,
|
|
128
|
+
conversationContext: parentContext === null || parentContext === void 0 ? void 0 : parentContext.conversationContext,
|
|
129
|
+
metadata: __assign(__assign({}, input.metadata), { parentConversationId: parentContext === null || parentContext === void 0 ? void 0 : parentContext.conversationId, parentAgentId: parentContext === null || parentContext === void 0 ? void 0 : parentContext.agentId, parentMetadata: parentContext === null || parentContext === void 0 ? void 0 : parentContext.metadata, isSubAgentCall: true, subAgentDepth: ((_a = parentContext === null || parentContext === void 0 ? void 0 : parentContext.subAgentDepth) !== null && _a !== void 0 ? _a : 0) + 1 }),
|
|
130
|
+
});
|
|
131
|
+
return [4 /*yield*/, response.result];
|
|
132
|
+
case 2:
|
|
133
|
+
result = _b.sent();
|
|
134
|
+
FlinkLog_1.log.debug("Sub-agent ".concat(this.subAgentInstanceName, " completed with ").concat(result.stepsUsed, " steps"));
|
|
135
|
+
return [2 /*return*/, {
|
|
136
|
+
success: true,
|
|
137
|
+
data: result,
|
|
138
|
+
}];
|
|
139
|
+
case 3:
|
|
140
|
+
err_1 = _b.sent();
|
|
141
|
+
FlinkLog_1.log.error("Sub-agent ".concat(this.subAgentInstanceName, " execution failed:"), err_1.message);
|
|
142
|
+
return [2 /*return*/, {
|
|
143
|
+
success: false,
|
|
144
|
+
error: "Sub-agent execution failed: ".concat(err_1.message),
|
|
145
|
+
code: "SUB_AGENT_ERROR",
|
|
146
|
+
}];
|
|
147
|
+
case 4: return [2 /*return*/];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Generate tool schema for this sub-agent
|
|
154
|
+
* LLM sees this as a regular tool
|
|
155
|
+
*/
|
|
156
|
+
SubAgentExecutor.prototype.getToolSchema = function () {
|
|
157
|
+
var agents = this.ctx.agents;
|
|
158
|
+
if (!(agents === null || agents === void 0 ? void 0 : agents[this.subAgentInstanceName])) {
|
|
159
|
+
throw new Error("Missing subagent: " + this.subAgentInstanceName);
|
|
160
|
+
}
|
|
161
|
+
var subAgent = agents === null || agents === void 0 ? void 0 : agents[this.subAgentInstanceName];
|
|
162
|
+
var description = subAgent ? "Delegate to ".concat(this.subAgentId, ": ").concat(subAgent.description) : "Delegate to ".concat(this.subAgentId);
|
|
163
|
+
// Simple schema - accepts a query string
|
|
164
|
+
var inputSchema = zod_1.z.object({
|
|
165
|
+
query: zod_1.z.string().describe("The question or task to send to the specialist agent"),
|
|
166
|
+
});
|
|
167
|
+
var toolName = this.subAgentId;
|
|
168
|
+
return {
|
|
169
|
+
name: toolName,
|
|
170
|
+
description: description,
|
|
171
|
+
input_schema: inputSchema.schema
|
|
172
|
+
? inputSchema.schema()
|
|
173
|
+
: {
|
|
174
|
+
type: "object",
|
|
175
|
+
properties: {
|
|
176
|
+
query: { type: "string" },
|
|
177
|
+
},
|
|
178
|
+
required: ["query"],
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Format sub-agent result for AI consumption
|
|
184
|
+
*/
|
|
185
|
+
SubAgentExecutor.prototype.formatResultForAI = function (result) {
|
|
186
|
+
var _a, _b;
|
|
187
|
+
if (result.success) {
|
|
188
|
+
var agentResult = result.data;
|
|
189
|
+
// Return the agent's final message as the tool result
|
|
190
|
+
return JSON.stringify({
|
|
191
|
+
answer: agentResult.message,
|
|
192
|
+
stepsUsed: agentResult.stepsUsed,
|
|
193
|
+
tokensUsed: (((_a = agentResult.usage) === null || _a === void 0 ? void 0 : _a.inputTokens) || 0) + (((_b = agentResult.usage) === null || _b === void 0 ? void 0 : _b.outputTokens) || 0),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return "Error: ".concat(result.error).concat(result.code ? " (".concat(result.code, ")") : "");
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* Check permissions - sub-agents handle their own permissions
|
|
202
|
+
*/
|
|
203
|
+
SubAgentExecutor.prototype.checkPermissions = function (_user, _input, _userPermissions, _conversationContext) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
205
|
+
return __generator(this, function (_a) {
|
|
206
|
+
// Sub-agents manage their own permissions
|
|
207
|
+
// The sub-agent's permissions will be checked when executed
|
|
208
|
+
return [2 /*return*/, true];
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Mark this as a sub-agent executor
|
|
214
|
+
*/
|
|
215
|
+
SubAgentExecutor.prototype.isSubAgentExecutor = function () {
|
|
216
|
+
return true;
|
|
217
|
+
};
|
|
218
|
+
SubAgentExecutor.prototype.getSubAgentId = function () {
|
|
219
|
+
return this.subAgentId;
|
|
220
|
+
};
|
|
221
|
+
return SubAgentExecutor;
|
|
222
|
+
}());
|
|
223
|
+
exports.SubAgentExecutor = SubAgentExecutor;
|