@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,224 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
+
t[p] = s[p];
|
|
53
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
+
t[p[i]] = s[p[i]];
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
};
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
exports.FlinkRepo = void 0;
|
|
62
|
+
var mongodb_1 = require("mongodb");
|
|
63
|
+
var FlinkRepo = /** @class */ (function () {
|
|
64
|
+
function FlinkRepo(collectionName, db, client) {
|
|
65
|
+
this.collectionName = collectionName;
|
|
66
|
+
this.db = db;
|
|
67
|
+
this.client = client;
|
|
68
|
+
this.collection = db.collection(this.collectionName);
|
|
69
|
+
}
|
|
70
|
+
Object.defineProperty(FlinkRepo.prototype, "ctx", {
|
|
71
|
+
get: function () {
|
|
72
|
+
if (!this._ctx)
|
|
73
|
+
throw new Error("Missing FlinkContext");
|
|
74
|
+
return this._ctx;
|
|
75
|
+
},
|
|
76
|
+
set: function (ctx) {
|
|
77
|
+
this._ctx = ctx;
|
|
78
|
+
},
|
|
79
|
+
enumerable: false,
|
|
80
|
+
configurable: true
|
|
81
|
+
});
|
|
82
|
+
FlinkRepo.prototype.findAll = function () {
|
|
83
|
+
return __awaiter(this, arguments, void 0, function (query) {
|
|
84
|
+
var res;
|
|
85
|
+
if (query === void 0) { query = {}; }
|
|
86
|
+
return __generator(this, function (_a) {
|
|
87
|
+
switch (_a.label) {
|
|
88
|
+
case 0: return [4 /*yield*/, this.collection.find(query).toArray()];
|
|
89
|
+
case 1:
|
|
90
|
+
res = _a.sent();
|
|
91
|
+
return [2 /*return*/, res.map(this.objectIdToString)];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
FlinkRepo.prototype.getById = function (id) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var res;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0: return [4 /*yield*/, this.collection.findOne({ _id: this.buildId(id) })];
|
|
102
|
+
case 1:
|
|
103
|
+
res = _a.sent();
|
|
104
|
+
if (res) {
|
|
105
|
+
return [2 /*return*/, this.objectIdToString(res)];
|
|
106
|
+
}
|
|
107
|
+
return [2 /*return*/, null];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
FlinkRepo.prototype.getOne = function () {
|
|
113
|
+
return __awaiter(this, arguments, void 0, function (query) {
|
|
114
|
+
var res;
|
|
115
|
+
if (query === void 0) { query = {}; }
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0: return [4 /*yield*/, this.collection.findOne(query)];
|
|
119
|
+
case 1:
|
|
120
|
+
res = _a.sent();
|
|
121
|
+
if (res) {
|
|
122
|
+
return [2 /*return*/, this.objectIdToString(res)];
|
|
123
|
+
}
|
|
124
|
+
return [2 /*return*/, null];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
FlinkRepo.prototype.create = function (model) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
131
|
+
var result;
|
|
132
|
+
return __generator(this, function (_a) {
|
|
133
|
+
switch (_a.label) {
|
|
134
|
+
case 0: return [4 /*yield*/, this.collection.insertOne(model)];
|
|
135
|
+
case 1:
|
|
136
|
+
result = _a.sent();
|
|
137
|
+
return [2 /*return*/, __assign(__assign({}, model), { _id: result.insertedId.toString() })];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
FlinkRepo.prototype.updateOne = function (id, model) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
+
var oid, _id, modelWithoutId, res;
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
switch (_a.label) {
|
|
147
|
+
case 0:
|
|
148
|
+
oid = this.buildId(id);
|
|
149
|
+
_id = model._id, modelWithoutId = __rest(model, ["_id"]);
|
|
150
|
+
return [4 /*yield*/, this.collection.updateOne({ _id: oid }, { $set: modelWithoutId })];
|
|
151
|
+
case 1:
|
|
152
|
+
_a.sent();
|
|
153
|
+
return [4 /*yield*/, this.collection.findOne({ _id: oid })];
|
|
154
|
+
case 2:
|
|
155
|
+
res = _a.sent();
|
|
156
|
+
if (res) {
|
|
157
|
+
return [2 /*return*/, this.objectIdToString(res)];
|
|
158
|
+
}
|
|
159
|
+
return [2 /*return*/, null];
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
FlinkRepo.prototype.updateMany = function (query, model) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
166
|
+
var _a, _id, modelWithoutId, modifiedCount;
|
|
167
|
+
return __generator(this, function (_b) {
|
|
168
|
+
switch (_b.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
_a = model, _id = _a._id, modelWithoutId = __rest(_a, ["_id"]);
|
|
171
|
+
return [4 /*yield*/, this.collection.updateMany(query, {
|
|
172
|
+
$set: modelWithoutId,
|
|
173
|
+
})];
|
|
174
|
+
case 1:
|
|
175
|
+
modifiedCount = (_b.sent()).modifiedCount;
|
|
176
|
+
return [2 /*return*/, modifiedCount];
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
FlinkRepo.prototype.deleteById = function (id) {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
183
|
+
var deletedCount;
|
|
184
|
+
return __generator(this, function (_a) {
|
|
185
|
+
switch (_a.label) {
|
|
186
|
+
case 0: return [4 /*yield*/, this.collection.deleteOne({
|
|
187
|
+
_id: this.buildId(id),
|
|
188
|
+
})];
|
|
189
|
+
case 1:
|
|
190
|
+
deletedCount = (_a.sent()).deletedCount;
|
|
191
|
+
return [2 /*return*/, deletedCount || 0];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Helper to ensure the id is always an ObjectId.
|
|
198
|
+
* If a string is passed, it will be converted to an ObjectId.
|
|
199
|
+
* If an ObjectId is passed, it will be returned as is.
|
|
200
|
+
* @param id
|
|
201
|
+
* @returns
|
|
202
|
+
*/
|
|
203
|
+
FlinkRepo.prototype.buildId = function (id) {
|
|
204
|
+
var oid;
|
|
205
|
+
if (typeof id === "string") {
|
|
206
|
+
oid = new mongodb_1.ObjectId(id);
|
|
207
|
+
}
|
|
208
|
+
else if (id instanceof mongodb_1.ObjectId) {
|
|
209
|
+
oid = id;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
throw new Error("Invalid id type");
|
|
213
|
+
}
|
|
214
|
+
return oid;
|
|
215
|
+
};
|
|
216
|
+
FlinkRepo.prototype.objectIdToString = function (doc) {
|
|
217
|
+
if (doc && doc._id) {
|
|
218
|
+
doc._id = doc._id.toString();
|
|
219
|
+
}
|
|
220
|
+
return doc;
|
|
221
|
+
};
|
|
222
|
+
return FlinkRepo;
|
|
223
|
+
}());
|
|
224
|
+
exports.FlinkRepo = FlinkRepo;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requestContext = void 0;
|
|
4
|
+
exports.getRequestContext = getRequestContext;
|
|
5
|
+
exports.getRequestUser = getRequestUser;
|
|
6
|
+
exports.getRequestPermissions = getRequestPermissions;
|
|
7
|
+
exports.getReqId = getReqId;
|
|
8
|
+
exports.hasPermission = hasPermission;
|
|
9
|
+
exports.hasAllPermissions = hasAllPermissions;
|
|
10
|
+
exports.hasAnyPermission = hasAnyPermission;
|
|
11
|
+
var async_hooks_1 = require("async_hooks");
|
|
12
|
+
/**
|
|
13
|
+
* AsyncLocalStorage instance for request-scoped context
|
|
14
|
+
* Available throughout the entire request lifecycle including async operations
|
|
15
|
+
*/
|
|
16
|
+
exports.requestContext = new async_hooks_1.AsyncLocalStorage();
|
|
17
|
+
/**
|
|
18
|
+
* Get the current request context
|
|
19
|
+
* Returns undefined if called outside of a request context
|
|
20
|
+
*/
|
|
21
|
+
function getRequestContext() {
|
|
22
|
+
return exports.requestContext.getStore();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the authenticated user from request context
|
|
26
|
+
* Returns undefined if no user is authenticated or outside request context
|
|
27
|
+
*/
|
|
28
|
+
function getRequestUser() {
|
|
29
|
+
var _a;
|
|
30
|
+
return (_a = exports.requestContext.getStore()) === null || _a === void 0 ? void 0 : _a.user;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get user permissions from request context
|
|
34
|
+
* Returns empty array if no permissions available
|
|
35
|
+
*/
|
|
36
|
+
function getRequestPermissions() {
|
|
37
|
+
var _a;
|
|
38
|
+
return ((_a = exports.requestContext.getStore()) === null || _a === void 0 ? void 0 : _a.userPermissions) || [];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get request ID from context
|
|
42
|
+
* Returns undefined if called outside of request context
|
|
43
|
+
*/
|
|
44
|
+
function getReqId() {
|
|
45
|
+
var _a;
|
|
46
|
+
return (_a = exports.requestContext.getStore()) === null || _a === void 0 ? void 0 : _a.reqId;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if current user has a specific permission
|
|
50
|
+
* @param permission - Permission string to check
|
|
51
|
+
* @returns true if user has the permission, false otherwise
|
|
52
|
+
*/
|
|
53
|
+
function hasPermission(permission) {
|
|
54
|
+
var permissions = getRequestPermissions();
|
|
55
|
+
return permissions.includes(permission);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if current user has all of the specified permissions (AND logic)
|
|
59
|
+
* @param requiredPermissions - Array of permission strings (all required)
|
|
60
|
+
* @returns true if user has all permissions, false otherwise
|
|
61
|
+
*/
|
|
62
|
+
function hasAllPermissions(requiredPermissions) {
|
|
63
|
+
var permissions = getRequestPermissions();
|
|
64
|
+
return requiredPermissions.every(function (p) { return permissions.includes(p); });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Check if current user has any of the specified permissions (OR logic)
|
|
68
|
+
* @param requiredPermissions - Array of permission strings (any required)
|
|
69
|
+
* @returns true if user has at least one permission, false otherwise
|
|
70
|
+
*/
|
|
71
|
+
function hasAnyPermission(requiredPermissions) {
|
|
72
|
+
var permissions = getRequestPermissions();
|
|
73
|
+
return requiredPermissions.some(function (p) { return permissions.includes(p); });
|
|
74
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
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);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
39
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
40
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
41
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
42
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
43
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
44
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
45
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
46
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
47
|
+
function fulfill(value) { resume("next", value); }
|
|
48
|
+
function reject(value) { resume("throw", value); }
|
|
49
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
50
|
+
};
|
|
51
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
52
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
53
|
+
var m = o[Symbol.asyncIterator], i;
|
|
54
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
55
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
56
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
57
|
+
};
|
|
58
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
59
|
+
exports.AgentExecutor = void 0;
|
|
60
|
+
var AgentRunner_1 = require("./AgentRunner");
|
|
61
|
+
var FlinkLog_1 = require("../FlinkLog");
|
|
62
|
+
var AgentExecutor = /** @class */ (function () {
|
|
63
|
+
function AgentExecutor(agentProps, tools, ctx, llmAdapters, agentName) {
|
|
64
|
+
this.agentProps = agentProps;
|
|
65
|
+
this.tools = tools;
|
|
66
|
+
this.ctx = ctx;
|
|
67
|
+
this.llmAdapters = llmAdapters;
|
|
68
|
+
this.agentName = agentName;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Unified execution method - supports both awaiting and streaming
|
|
72
|
+
*
|
|
73
|
+
* Uses lazy generator pattern (similar to Vercel AI SDK) to allow
|
|
74
|
+
* multiple consumption without re-execution.
|
|
75
|
+
*
|
|
76
|
+
* Examples:
|
|
77
|
+
* const response = agent.run({ message: "Hello" });
|
|
78
|
+
* const result = await response.result; // Await final result
|
|
79
|
+
* for await (const text of response.textStream) { ... } // Stream text
|
|
80
|
+
* for await (const chunk of response.fullStream) { ... } // Stream all events
|
|
81
|
+
*/
|
|
82
|
+
AgentExecutor.prototype.run = function (input) {
|
|
83
|
+
// Permission check
|
|
84
|
+
if (this.agentProps.permissions) {
|
|
85
|
+
this.checkPermissionsSync(input.user);
|
|
86
|
+
}
|
|
87
|
+
var runner = this.getRunner();
|
|
88
|
+
FlinkLog_1.log.debug("Running agent ".concat(this.agentName || "unknown"));
|
|
89
|
+
// Lazy evaluation - generator only starts when first consumed
|
|
90
|
+
var baseGenerator = null;
|
|
91
|
+
var buffer = [];
|
|
92
|
+
var done = false;
|
|
93
|
+
var getBaseGenerator = function () {
|
|
94
|
+
if (!baseGenerator) {
|
|
95
|
+
baseGenerator = runner.streamGenerator(input);
|
|
96
|
+
}
|
|
97
|
+
return baseGenerator;
|
|
98
|
+
};
|
|
99
|
+
// Create independent iterators that share buffered chunks
|
|
100
|
+
var createIterator = function () {
|
|
101
|
+
var index = 0;
|
|
102
|
+
return (function () {
|
|
103
|
+
return __asyncGenerator(this, arguments, function () {
|
|
104
|
+
var gen, _a, value, isDone;
|
|
105
|
+
return __generator(this, function (_b) {
|
|
106
|
+
switch (_b.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
if (!true) return [3 /*break*/, 7];
|
|
109
|
+
if (!(index < buffer.length)) return [3 /*break*/, 3];
|
|
110
|
+
return [4 /*yield*/, __await(buffer[index++])];
|
|
111
|
+
case 1: return [4 /*yield*/, _b.sent()];
|
|
112
|
+
case 2:
|
|
113
|
+
_b.sent();
|
|
114
|
+
return [3 /*break*/, 0];
|
|
115
|
+
case 3:
|
|
116
|
+
// If already done, exit
|
|
117
|
+
if (done) {
|
|
118
|
+
return [3 /*break*/, 7];
|
|
119
|
+
}
|
|
120
|
+
gen = getBaseGenerator();
|
|
121
|
+
return [4 /*yield*/, __await(gen.next())];
|
|
122
|
+
case 4:
|
|
123
|
+
_a = _b.sent(), value = _a.value, isDone = _a.done;
|
|
124
|
+
if (isDone) {
|
|
125
|
+
done = true;
|
|
126
|
+
return [3 /*break*/, 7];
|
|
127
|
+
}
|
|
128
|
+
// Buffer and yield
|
|
129
|
+
buffer.push(value);
|
|
130
|
+
return [4 /*yield*/, __await(value)];
|
|
131
|
+
case 5: return [4 /*yield*/, _b.sent()];
|
|
132
|
+
case 6:
|
|
133
|
+
_b.sent();
|
|
134
|
+
index++;
|
|
135
|
+
return [3 /*break*/, 0];
|
|
136
|
+
case 7: return [2 /*return*/];
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
})();
|
|
141
|
+
};
|
|
142
|
+
return {
|
|
143
|
+
result: this.consumeAsResult(createIterator()),
|
|
144
|
+
textStream: this.consumeAsTextStream(createIterator()),
|
|
145
|
+
fullStream: createIterator(),
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Consume stream as final result (for await pattern)
|
|
150
|
+
*/
|
|
151
|
+
AgentExecutor.prototype.consumeAsResult = function (stream) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
+
var result, chunk, e_1_1;
|
|
154
|
+
var _a, stream_1, stream_1_1;
|
|
155
|
+
var _b, e_1, _c, _d;
|
|
156
|
+
return __generator(this, function (_e) {
|
|
157
|
+
switch (_e.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
_e.trys.push([0, 5, 6, 11]);
|
|
160
|
+
_a = true, stream_1 = __asyncValues(stream);
|
|
161
|
+
_e.label = 1;
|
|
162
|
+
case 1: return [4 /*yield*/, stream_1.next()];
|
|
163
|
+
case 2:
|
|
164
|
+
if (!(stream_1_1 = _e.sent(), _b = stream_1_1.done, !_b)) return [3 /*break*/, 4];
|
|
165
|
+
_d = stream_1_1.value;
|
|
166
|
+
_a = false;
|
|
167
|
+
chunk = _d;
|
|
168
|
+
if (chunk.type === "complete") {
|
|
169
|
+
result = chunk.result;
|
|
170
|
+
}
|
|
171
|
+
_e.label = 3;
|
|
172
|
+
case 3:
|
|
173
|
+
_a = true;
|
|
174
|
+
return [3 /*break*/, 1];
|
|
175
|
+
case 4: return [3 /*break*/, 11];
|
|
176
|
+
case 5:
|
|
177
|
+
e_1_1 = _e.sent();
|
|
178
|
+
e_1 = { error: e_1_1 };
|
|
179
|
+
return [3 /*break*/, 11];
|
|
180
|
+
case 6:
|
|
181
|
+
_e.trys.push([6, , 9, 10]);
|
|
182
|
+
if (!(!_a && !_b && (_c = stream_1.return))) return [3 /*break*/, 8];
|
|
183
|
+
return [4 /*yield*/, _c.call(stream_1)];
|
|
184
|
+
case 7:
|
|
185
|
+
_e.sent();
|
|
186
|
+
_e.label = 8;
|
|
187
|
+
case 8: return [3 /*break*/, 10];
|
|
188
|
+
case 9:
|
|
189
|
+
if (e_1) throw e_1.error;
|
|
190
|
+
return [7 /*endfinally*/];
|
|
191
|
+
case 10: return [7 /*endfinally*/];
|
|
192
|
+
case 11:
|
|
193
|
+
if (!result) {
|
|
194
|
+
throw new Error("Agent execution did not complete");
|
|
195
|
+
}
|
|
196
|
+
return [2 /*return*/, result];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Consume stream as text-only stream (for simple streaming UX)
|
|
203
|
+
*/
|
|
204
|
+
AgentExecutor.prototype.consumeAsTextStream = function (stream) {
|
|
205
|
+
return __asyncGenerator(this, arguments, function consumeAsTextStream_1() {
|
|
206
|
+
var _a, stream_2, stream_2_1, chunk, e_2_1;
|
|
207
|
+
var _b, e_2, _c, _d;
|
|
208
|
+
return __generator(this, function (_e) {
|
|
209
|
+
switch (_e.label) {
|
|
210
|
+
case 0:
|
|
211
|
+
_e.trys.push([0, 7, 8, 13]);
|
|
212
|
+
_a = true, stream_2 = __asyncValues(stream);
|
|
213
|
+
_e.label = 1;
|
|
214
|
+
case 1: return [4 /*yield*/, __await(stream_2.next())];
|
|
215
|
+
case 2:
|
|
216
|
+
if (!(stream_2_1 = _e.sent(), _b = stream_2_1.done, !_b)) return [3 /*break*/, 6];
|
|
217
|
+
_d = stream_2_1.value;
|
|
218
|
+
_a = false;
|
|
219
|
+
chunk = _d;
|
|
220
|
+
if (!(chunk.type === "text_delta")) return [3 /*break*/, 5];
|
|
221
|
+
return [4 /*yield*/, __await(chunk.delta)];
|
|
222
|
+
case 3: return [4 /*yield*/, _e.sent()];
|
|
223
|
+
case 4:
|
|
224
|
+
_e.sent();
|
|
225
|
+
_e.label = 5;
|
|
226
|
+
case 5:
|
|
227
|
+
_a = true;
|
|
228
|
+
return [3 /*break*/, 1];
|
|
229
|
+
case 6: return [3 /*break*/, 13];
|
|
230
|
+
case 7:
|
|
231
|
+
e_2_1 = _e.sent();
|
|
232
|
+
e_2 = { error: e_2_1 };
|
|
233
|
+
return [3 /*break*/, 13];
|
|
234
|
+
case 8:
|
|
235
|
+
_e.trys.push([8, , 11, 12]);
|
|
236
|
+
if (!(!_a && !_b && (_c = stream_2.return))) return [3 /*break*/, 10];
|
|
237
|
+
return [4 /*yield*/, __await(_c.call(stream_2))];
|
|
238
|
+
case 9:
|
|
239
|
+
_e.sent();
|
|
240
|
+
_e.label = 10;
|
|
241
|
+
case 10: return [3 /*break*/, 12];
|
|
242
|
+
case 11:
|
|
243
|
+
if (e_2) throw e_2.error;
|
|
244
|
+
return [7 /*endfinally*/];
|
|
245
|
+
case 12: return [7 /*endfinally*/];
|
|
246
|
+
case 13: return [2 /*return*/];
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
AgentExecutor.prototype.getRunner = function () {
|
|
252
|
+
if (!this.runner) {
|
|
253
|
+
this.runner = new AgentRunner_1.AgentRunner(this.agentProps, this.tools, this.llmAdapters, this.agentName);
|
|
254
|
+
}
|
|
255
|
+
return this.runner;
|
|
256
|
+
};
|
|
257
|
+
AgentExecutor.prototype.checkPermissionsSync = function (user) {
|
|
258
|
+
var perms = this.agentProps.permissions;
|
|
259
|
+
if (!perms)
|
|
260
|
+
return;
|
|
261
|
+
if (typeof perms === "function") {
|
|
262
|
+
var hasPermission = perms(user);
|
|
263
|
+
if (!hasPermission) {
|
|
264
|
+
throw new Error("Permission denied for agent ".concat(this.agentName || "unknown"));
|
|
265
|
+
}
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
if (!user) {
|
|
269
|
+
throw new Error("Permission denied for agent ".concat(this.agentName || "unknown"));
|
|
270
|
+
}
|
|
271
|
+
var requiredPerms = Array.isArray(perms) ? perms : [perms];
|
|
272
|
+
var userPerms = user.permissions || [];
|
|
273
|
+
if (!requiredPerms.every(function (p) { return userPerms.includes(p); })) {
|
|
274
|
+
throw new Error("Permission denied for agent ".concat(this.agentName || "unknown"));
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
return AgentExecutor;
|
|
278
|
+
}());
|
|
279
|
+
exports.AgentExecutor = AgentExecutor;
|