@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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var TypeScriptSourceParser_1 = require("./TypeScriptSourceParser");
|
|
4
|
+
describe("TypeScriptSourceParser", function () {
|
|
5
|
+
describe("detectSchemaType", function () {
|
|
6
|
+
it("should detect Zod schemas", function () {
|
|
7
|
+
var source = "\n export const Tool: FlinkToolProps = {\n inputSchema: z.object({ name: z.string() })\n }\n ";
|
|
8
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.detectSchemaType(source);
|
|
9
|
+
expect(result.hasZodSchemas).toBe(true);
|
|
10
|
+
expect(result.shouldSkipTypeScriptExtraction).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it("should detect JSON schemas", function () {
|
|
13
|
+
var source = "\n export const Tool: FlinkToolProps = {\n inputJsonSchema: { type: \"object\" }\n }\n ";
|
|
14
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.detectSchemaType(source);
|
|
15
|
+
expect(result.hasJsonSchemas).toBe(true);
|
|
16
|
+
expect(result.shouldSkipTypeScriptExtraction).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it("should detect neither for TypeScript-only tools", function () {
|
|
19
|
+
var source = "\n const handler: FlinkTool<Ctx, Input, Output> = async () => {};\n ";
|
|
20
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.detectSchemaType(source);
|
|
21
|
+
expect(result.hasZodSchemas).toBe(false);
|
|
22
|
+
expect(result.hasJsonSchemas).toBe(false);
|
|
23
|
+
expect(result.shouldSkipTypeScriptExtraction).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe("parseFlinkToolTypeArgs", function () {
|
|
27
|
+
it("should extract type arguments from FlinkTool declaration", function () {
|
|
28
|
+
var source = "const handler: FlinkTool<Ctx, CreateDocInput, ToolResult<DocOutput>> = async () => {};";
|
|
29
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.parseFlinkToolTypeArgs(source);
|
|
30
|
+
expect(result).toEqual({
|
|
31
|
+
contextType: "Ctx",
|
|
32
|
+
inputType: "CreateDocInput",
|
|
33
|
+
outputType: "ToolResult<DocOutput>",
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it("should handle inline object types", function () {
|
|
37
|
+
var source = "const handler: FlinkTool<Ctx, { foo: string }, ToolResult<Output>> = async () => {};";
|
|
38
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.parseFlinkToolTypeArgs(source);
|
|
39
|
+
expect(result === null || result === void 0 ? void 0 : result.inputType).toBe("{ foo: string }");
|
|
40
|
+
});
|
|
41
|
+
it("should handle empty object input", function () {
|
|
42
|
+
var source = "const handler: FlinkTool<Ctx, {}, ToolResult<Output>> = async () => {};";
|
|
43
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.parseFlinkToolTypeArgs(source);
|
|
44
|
+
expect(result === null || result === void 0 ? void 0 : result.inputType).toBe("{}");
|
|
45
|
+
});
|
|
46
|
+
it("should return null if no FlinkTool found", function () {
|
|
47
|
+
var source = "const handler = async () => {};";
|
|
48
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.parseFlinkToolTypeArgs(source);
|
|
49
|
+
expect(result).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
it("should handle whitespace variations", function () {
|
|
52
|
+
var source = "const handler: FlinkTool<Ctx,Input,Output> = async () => {};";
|
|
53
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.parseFlinkToolTypeArgs(source);
|
|
54
|
+
expect(result).toEqual({
|
|
55
|
+
contextType: "Ctx",
|
|
56
|
+
inputType: "Input",
|
|
57
|
+
outputType: "Output",
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe("shouldGenerateSchema", function () {
|
|
62
|
+
it("should return false for 'any'", function () {
|
|
63
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.shouldGenerateSchema("any")).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
it("should return false for primitives", function () {
|
|
66
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.shouldGenerateSchema("string")).toBe(false);
|
|
67
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.shouldGenerateSchema("number")).toBe(false);
|
|
68
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.shouldGenerateSchema("boolean")).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
it("should return true for inline objects", function () {
|
|
71
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.shouldGenerateSchema("{}")).toBe(true);
|
|
72
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.shouldGenerateSchema("{ foo: string }")).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
it("should return true for named types", function () {
|
|
75
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.shouldGenerateSchema("User")).toBe(true);
|
|
76
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.shouldGenerateSchema("CreateDocInput")).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe("unwrapToolResultType", function () {
|
|
80
|
+
it("should extract type from ToolResult<T>", function () {
|
|
81
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.unwrapToolResultType("ToolResult<DocOutput>")).toBe("DocOutput");
|
|
82
|
+
});
|
|
83
|
+
it("should handle complex generic types", function () {
|
|
84
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.unwrapToolResultType("ToolResult<Array<Doc>>")).toBe("Array<Doc>");
|
|
85
|
+
});
|
|
86
|
+
it("should return as-is if not ToolResult", function () {
|
|
87
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.unwrapToolResultType("DocOutput")).toBe("DocOutput");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe("convertInlineObjectToInterface", function () {
|
|
91
|
+
it("should convert empty object", function () {
|
|
92
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.convertInlineObjectToInterface("{}", "MyInput");
|
|
93
|
+
expect(result).toBe("export interface MyInput {}");
|
|
94
|
+
});
|
|
95
|
+
it("should convert single property", function () {
|
|
96
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.convertInlineObjectToInterface("{ foo: string }", "MyInput");
|
|
97
|
+
expect(result).toContain("export interface MyInput");
|
|
98
|
+
expect(result).toContain("foo: string;");
|
|
99
|
+
});
|
|
100
|
+
it("should convert multiple properties", function () {
|
|
101
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.convertInlineObjectToInterface("{ foo: string; bar: number }", "MyInput");
|
|
102
|
+
expect(result).toContain("export interface MyInput");
|
|
103
|
+
expect(result).toContain("foo: string;");
|
|
104
|
+
expect(result).toContain("bar: number;");
|
|
105
|
+
});
|
|
106
|
+
it("should handle properties with commas", function () {
|
|
107
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.convertInlineObjectToInterface("{ foo: string, bar: number }", "MyInput");
|
|
108
|
+
expect(result).toContain("foo: string");
|
|
109
|
+
expect(result).toContain("bar: number");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe("findTypeDefinition", function () {
|
|
113
|
+
it("should find interface definitions", function () {
|
|
114
|
+
var source = "\n interface User {\n name: string;\n age: number;\n }\n ";
|
|
115
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.findTypeDefinition(source, "User");
|
|
116
|
+
expect(result).not.toBeNull();
|
|
117
|
+
expect(result === null || result === void 0 ? void 0 : result.kind).toBe("interface");
|
|
118
|
+
expect(result === null || result === void 0 ? void 0 : result.name).toBe("User");
|
|
119
|
+
expect(result === null || result === void 0 ? void 0 : result.definition).toContain("interface User");
|
|
120
|
+
});
|
|
121
|
+
it("should find type alias definitions", function () {
|
|
122
|
+
var source = "\n type UserId = string;\n ";
|
|
123
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.findTypeDefinition(source, "UserId");
|
|
124
|
+
expect(result).not.toBeNull();
|
|
125
|
+
expect(result === null || result === void 0 ? void 0 : result.kind).toBe("type");
|
|
126
|
+
expect(result === null || result === void 0 ? void 0 : result.name).toBe("UserId");
|
|
127
|
+
});
|
|
128
|
+
it("should find interfaces with JSDoc", function () {
|
|
129
|
+
var source = "\n /**\n * User model\n */\n interface User {\n name: string;\n }\n ";
|
|
130
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.findTypeDefinition(source, "User");
|
|
131
|
+
expect(result).not.toBeNull();
|
|
132
|
+
expect(result === null || result === void 0 ? void 0 : result.definition).toContain("/**");
|
|
133
|
+
});
|
|
134
|
+
it("should return null for non-existent types", function () {
|
|
135
|
+
var source = "interface User { name: string; }";
|
|
136
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.findTypeDefinition(source, "NonExistent");
|
|
137
|
+
expect(result).toBeNull();
|
|
138
|
+
});
|
|
139
|
+
it("should handle interfaces with generics", function () {
|
|
140
|
+
var source = "\n interface List<T> {\n items: T[];\n }\n ";
|
|
141
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.findTypeDefinition(source, "List");
|
|
142
|
+
expect(result).not.toBeNull();
|
|
143
|
+
expect(result === null || result === void 0 ? void 0 : result.definition).toContain("interface List<T>");
|
|
144
|
+
});
|
|
145
|
+
it("should handle interfaces with extends", function () {
|
|
146
|
+
var source = "\n interface Admin extends User {\n role: string;\n }\n ";
|
|
147
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.findTypeDefinition(source, "Admin");
|
|
148
|
+
expect(result).not.toBeNull();
|
|
149
|
+
expect(result === null || result === void 0 ? void 0 : result.definition).toContain("extends User");
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe("renameTypeDefinition", function () {
|
|
153
|
+
it("should rename interface", function () {
|
|
154
|
+
var def = "interface User { name: string; }";
|
|
155
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.renameTypeDefinition(def, "User", "Person");
|
|
156
|
+
expect(result).toBe("export interface Person { name: string; }");
|
|
157
|
+
});
|
|
158
|
+
it("should rename type alias", function () {
|
|
159
|
+
var def = "type UserId = string;";
|
|
160
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.renameTypeDefinition(def, "UserId", "PersonId");
|
|
161
|
+
expect(result).toBe("export type PersonId = string;");
|
|
162
|
+
});
|
|
163
|
+
it("should not export if exportIt is false", function () {
|
|
164
|
+
var def = "interface User { name: string; }";
|
|
165
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.renameTypeDefinition(def, "User", "Person", false);
|
|
166
|
+
expect(result).toBe("interface Person { name: string; }");
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe("extractReferencedTypes", function () {
|
|
170
|
+
it("should extract type references from interface", function () {
|
|
171
|
+
var def = "\n interface Document {\n author: User;\n tags: Tag[];\n metadata: Metadata;\n }\n ";
|
|
172
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.extractReferencedTypes(def);
|
|
173
|
+
expect(result).toContain("User");
|
|
174
|
+
expect(result).toContain("Tag");
|
|
175
|
+
expect(result).toContain("Metadata");
|
|
176
|
+
});
|
|
177
|
+
it("should not extract built-in types", function () {
|
|
178
|
+
var def = "\n interface Doc {\n title: string;\n count: number;\n date: Date;\n }\n ";
|
|
179
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.extractReferencedTypes(def);
|
|
180
|
+
expect(result).not.toContain("Date");
|
|
181
|
+
expect(result.length).toBe(0);
|
|
182
|
+
});
|
|
183
|
+
it("should not extract types from JSDoc comments", function () {
|
|
184
|
+
var def = "\n /**\n * Title for the document\n * Optional user info\n */\n interface Doc {\n title: string;\n }\n ";
|
|
185
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.extractReferencedTypes(def);
|
|
186
|
+
expect(result).not.toContain("Title");
|
|
187
|
+
expect(result).not.toContain("Optional");
|
|
188
|
+
});
|
|
189
|
+
it("should handle union types", function () {
|
|
190
|
+
var def = "\n interface Result {\n data: Success | Error;\n }\n ";
|
|
191
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.extractReferencedTypes(def);
|
|
192
|
+
expect(result).toContain("Success");
|
|
193
|
+
expect(result).toContain("Error");
|
|
194
|
+
});
|
|
195
|
+
it("should handle intersection types", function () {
|
|
196
|
+
var def = "\n interface Combined {\n data: Base & Extra;\n }\n ";
|
|
197
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.extractReferencedTypes(def);
|
|
198
|
+
expect(result).toContain("Base");
|
|
199
|
+
expect(result).toContain("Extra");
|
|
200
|
+
});
|
|
201
|
+
it("should handle Array generics", function () {
|
|
202
|
+
var def = "\n interface List {\n items: Array<Item>;\n }\n ";
|
|
203
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.extractReferencedTypes(def);
|
|
204
|
+
expect(result).toContain("Item");
|
|
205
|
+
});
|
|
206
|
+
it("should not include duplicates", function () {
|
|
207
|
+
var def = "\n interface Doc {\n author: User;\n editor: User;\n }\n ";
|
|
208
|
+
var result = TypeScriptSourceParser_1.TypeScriptSourceParser.extractReferencedTypes(def);
|
|
209
|
+
expect(result.filter(function (t) { return t === "User"; }).length).toBe(1);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe("isInlineObjectType", function () {
|
|
213
|
+
it("should return true for inline objects", function () {
|
|
214
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isInlineObjectType("{}")).toBe(true);
|
|
215
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isInlineObjectType("{ foo: string }")).toBe(true);
|
|
216
|
+
});
|
|
217
|
+
it("should return false for named types", function () {
|
|
218
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isInlineObjectType("User")).toBe(false);
|
|
219
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isInlineObjectType("CreateDocInput")).toBe(false);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
describe("isBuiltInType", function () {
|
|
223
|
+
it("should return true for built-in types", function () {
|
|
224
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isBuiltInType("String")).toBe(true);
|
|
225
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isBuiltInType("Array")).toBe(true);
|
|
226
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isBuiltInType("Promise")).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
it("should return false for custom types", function () {
|
|
229
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isBuiltInType("User")).toBe(false);
|
|
230
|
+
expect(TypeScriptSourceParser_1.TypeScriptSourceParser.isBuiltInType("CustomType")).toBe(false);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple TypeScript tokenizer for robust bracket matching.
|
|
3
|
+
*
|
|
4
|
+
* Properly handles:
|
|
5
|
+
* - String literals with all quote types
|
|
6
|
+
* - Escape sequences in strings
|
|
7
|
+
* - Line comments
|
|
8
|
+
* - Block comments
|
|
9
|
+
* - Nested brackets
|
|
10
|
+
*
|
|
11
|
+
* This prevents bracket counting errors when special characters
|
|
12
|
+
* appear inside strings or comments.
|
|
13
|
+
*/
|
|
14
|
+
export interface Token {
|
|
15
|
+
type: 'string' | 'comment' | 'bracket' | 'char';
|
|
16
|
+
value: string;
|
|
17
|
+
startPos: number;
|
|
18
|
+
endPos: number;
|
|
19
|
+
}
|
|
20
|
+
export declare class TypeScriptTokenizer {
|
|
21
|
+
private text;
|
|
22
|
+
private pos;
|
|
23
|
+
constructor(text: string);
|
|
24
|
+
/**
|
|
25
|
+
* Find matching closing bracket from current position.
|
|
26
|
+
* Properly handles strings and comments.
|
|
27
|
+
*
|
|
28
|
+
* @param openChar Opening bracket character
|
|
29
|
+
* @returns Position of matching closing bracket, or -1 if not found
|
|
30
|
+
*/
|
|
31
|
+
findMatchingBracket(openChar: '{' | '<' | '(' | '['): number;
|
|
32
|
+
/**
|
|
33
|
+
* Find matching closing bracket from a specific start position.
|
|
34
|
+
*/
|
|
35
|
+
findMatchingBracketAt(startPos: number, openChar: '{' | '<' | '(' | '['): number;
|
|
36
|
+
/**
|
|
37
|
+
* Get next meaningful token, properly handling strings and comments.
|
|
38
|
+
* Public for use in other parsing utilities.
|
|
39
|
+
*/
|
|
40
|
+
getNextToken(startPos: number): Token;
|
|
41
|
+
/**
|
|
42
|
+
* Parse string literal, handling escape sequences.
|
|
43
|
+
*/
|
|
44
|
+
private parseStringLiteral;
|
|
45
|
+
/**
|
|
46
|
+
* Parse line comment (// ... \n).
|
|
47
|
+
*/
|
|
48
|
+
private parseLineComment;
|
|
49
|
+
/**
|
|
50
|
+
* Parse block comment (/* ... *\/).
|
|
51
|
+
*/
|
|
52
|
+
private parseBlockComment;
|
|
53
|
+
/**
|
|
54
|
+
* Get closing bracket character for an opening bracket.
|
|
55
|
+
*/
|
|
56
|
+
private getClosingBracket;
|
|
57
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Simple TypeScript tokenizer for robust bracket matching.
|
|
4
|
+
*
|
|
5
|
+
* Properly handles:
|
|
6
|
+
* - String literals with all quote types
|
|
7
|
+
* - Escape sequences in strings
|
|
8
|
+
* - Line comments
|
|
9
|
+
* - Block comments
|
|
10
|
+
* - Nested brackets
|
|
11
|
+
*
|
|
12
|
+
* This prevents bracket counting errors when special characters
|
|
13
|
+
* appear inside strings or comments.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.TypeScriptTokenizer = void 0;
|
|
17
|
+
var TypeScriptTokenizer = /** @class */ (function () {
|
|
18
|
+
function TypeScriptTokenizer(text) {
|
|
19
|
+
this.pos = 0;
|
|
20
|
+
this.text = text;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Find matching closing bracket from current position.
|
|
24
|
+
* Properly handles strings and comments.
|
|
25
|
+
*
|
|
26
|
+
* @param openChar Opening bracket character
|
|
27
|
+
* @returns Position of matching closing bracket, or -1 if not found
|
|
28
|
+
*/
|
|
29
|
+
TypeScriptTokenizer.prototype.findMatchingBracket = function (openChar) {
|
|
30
|
+
var closeChar = this.getClosingBracket(openChar);
|
|
31
|
+
var depth = 1;
|
|
32
|
+
var i = this.pos + 1;
|
|
33
|
+
while (i < this.text.length && depth > 0) {
|
|
34
|
+
var token = this.getNextToken(i);
|
|
35
|
+
// Only count brackets outside strings and comments
|
|
36
|
+
if (token.type === 'bracket') {
|
|
37
|
+
if (token.value === openChar) {
|
|
38
|
+
depth++;
|
|
39
|
+
}
|
|
40
|
+
else if (token.value === closeChar) {
|
|
41
|
+
depth--;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
i = token.endPos;
|
|
45
|
+
}
|
|
46
|
+
return depth === 0 ? i - 1 : -1;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Find matching closing bracket from a specific start position.
|
|
50
|
+
*/
|
|
51
|
+
TypeScriptTokenizer.prototype.findMatchingBracketAt = function (startPos, openChar) {
|
|
52
|
+
this.pos = startPos;
|
|
53
|
+
return this.findMatchingBracket(openChar);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Get next meaningful token, properly handling strings and comments.
|
|
57
|
+
* Public for use in other parsing utilities.
|
|
58
|
+
*/
|
|
59
|
+
TypeScriptTokenizer.prototype.getNextToken = function (startPos) {
|
|
60
|
+
var char = this.text[startPos];
|
|
61
|
+
// String literal (single, double, or backtick quotes)
|
|
62
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
63
|
+
return this.parseStringLiteral(startPos, char);
|
|
64
|
+
}
|
|
65
|
+
// Line comment
|
|
66
|
+
if (char === '/' && this.text[startPos + 1] === '/') {
|
|
67
|
+
return this.parseLineComment(startPos);
|
|
68
|
+
}
|
|
69
|
+
// Block comment
|
|
70
|
+
if (char === '/' && this.text[startPos + 1] === '*') {
|
|
71
|
+
return this.parseBlockComment(startPos);
|
|
72
|
+
}
|
|
73
|
+
// Bracket characters
|
|
74
|
+
if ('{}<>()[]'.includes(char)) {
|
|
75
|
+
return {
|
|
76
|
+
type: 'bracket',
|
|
77
|
+
value: char,
|
|
78
|
+
startPos: startPos,
|
|
79
|
+
endPos: startPos + 1,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
// Other character (not important for bracket matching)
|
|
83
|
+
return {
|
|
84
|
+
type: 'char',
|
|
85
|
+
value: char,
|
|
86
|
+
startPos: startPos,
|
|
87
|
+
endPos: startPos + 1,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Parse string literal, handling escape sequences.
|
|
92
|
+
*/
|
|
93
|
+
TypeScriptTokenizer.prototype.parseStringLiteral = function (startPos, quoteChar) {
|
|
94
|
+
var i = startPos + 1;
|
|
95
|
+
var escaped = false;
|
|
96
|
+
while (i < this.text.length) {
|
|
97
|
+
if (escaped) {
|
|
98
|
+
// Skip escaped character
|
|
99
|
+
escaped = false;
|
|
100
|
+
i++;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (this.text[i] === '\\') {
|
|
104
|
+
// Found escape sequence
|
|
105
|
+
escaped = true;
|
|
106
|
+
i++;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (this.text[i] === quoteChar) {
|
|
110
|
+
// Found closing quote
|
|
111
|
+
return {
|
|
112
|
+
type: 'string',
|
|
113
|
+
value: this.text.slice(startPos, i + 1),
|
|
114
|
+
startPos: startPos,
|
|
115
|
+
endPos: i + 1,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
i++;
|
|
119
|
+
}
|
|
120
|
+
// Unclosed string - return what we have
|
|
121
|
+
// (Let TypeScript compiler handle the error)
|
|
122
|
+
return {
|
|
123
|
+
type: 'string',
|
|
124
|
+
value: this.text.slice(startPos),
|
|
125
|
+
startPos: startPos,
|
|
126
|
+
endPos: this.text.length,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Parse line comment (// ... \n).
|
|
131
|
+
*/
|
|
132
|
+
TypeScriptTokenizer.prototype.parseLineComment = function (startPos) {
|
|
133
|
+
var newlinePos = this.text.indexOf('\n', startPos);
|
|
134
|
+
var endPos = newlinePos === -1 ? this.text.length : newlinePos + 1;
|
|
135
|
+
return {
|
|
136
|
+
type: 'comment',
|
|
137
|
+
value: this.text.slice(startPos, endPos),
|
|
138
|
+
startPos: startPos,
|
|
139
|
+
endPos: endPos,
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Parse block comment (/* ... *\/).
|
|
144
|
+
*/
|
|
145
|
+
TypeScriptTokenizer.prototype.parseBlockComment = function (startPos) {
|
|
146
|
+
var endPos = this.text.indexOf('*/', startPos + 2);
|
|
147
|
+
if (endPos === -1) {
|
|
148
|
+
// Unclosed block comment - return what we have
|
|
149
|
+
return {
|
|
150
|
+
type: 'comment',
|
|
151
|
+
value: this.text.slice(startPos),
|
|
152
|
+
startPos: startPos,
|
|
153
|
+
endPos: this.text.length,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
type: 'comment',
|
|
158
|
+
value: this.text.slice(startPos, endPos + 2),
|
|
159
|
+
startPos: startPos,
|
|
160
|
+
endPos: endPos + 2,
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Get closing bracket character for an opening bracket.
|
|
165
|
+
*/
|
|
166
|
+
TypeScriptTokenizer.prototype.getClosingBracket = function (open) {
|
|
167
|
+
var pairs = {
|
|
168
|
+
'{': '}',
|
|
169
|
+
'<': '>',
|
|
170
|
+
'(': ')',
|
|
171
|
+
'[': ']',
|
|
172
|
+
};
|
|
173
|
+
return pairs[open];
|
|
174
|
+
};
|
|
175
|
+
return TypeScriptTokenizer;
|
|
176
|
+
}());
|
|
177
|
+
exports.TypeScriptTokenizer = TypeScriptTokenizer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.TypeScriptSourceParser = void 0;
|
|
18
|
+
var TypeScriptSourceParser_1 = require("./TypeScriptSourceParser");
|
|
19
|
+
Object.defineProperty(exports, "TypeScriptSourceParser", { enumerable: true, get: function () { return TypeScriptSourceParser_1.TypeScriptSourceParser; } });
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema type detection result
|
|
3
|
+
*/
|
|
4
|
+
export interface SchemaTypeDetection {
|
|
5
|
+
hasZodSchemas: boolean;
|
|
6
|
+
hasJsonSchemas: boolean;
|
|
7
|
+
shouldSkipTypeScriptExtraction: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* FlinkTool type arguments extracted from source
|
|
11
|
+
*/
|
|
12
|
+
export interface FlinkToolTypeArgs {
|
|
13
|
+
contextType: string;
|
|
14
|
+
inputType: string;
|
|
15
|
+
outputType: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Result of type definition search
|
|
19
|
+
*/
|
|
20
|
+
export interface TypeDefinition {
|
|
21
|
+
name: string;
|
|
22
|
+
definition: string;
|
|
23
|
+
kind: 'interface' | 'type';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Metadata for a single property (parameter or query field)
|
|
27
|
+
*/
|
|
28
|
+
export interface PropertyMetadata {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { LoggingConfig } from "../FlinkLogFactory";
|
|
2
|
+
/**
|
|
3
|
+
* Compiler plugin descriptor — declared in flink.config.js, consumed by the TypeScript compiler.
|
|
4
|
+
* Plugin packages export a compilerPlugin() factory that returns this shape.
|
|
5
|
+
*/
|
|
6
|
+
export interface FlinkCompilerPlugin {
|
|
7
|
+
/** npm package name, e.g. "@flink-app/inbound-email-plugin" */
|
|
8
|
+
package: string;
|
|
9
|
+
/** Directory to scan for handler files, e.g. "src/email-handlers" */
|
|
10
|
+
scanDir: string;
|
|
11
|
+
/** Base name for the generated .flink/generatedXxx.ts file, e.g. "generatedEmailHandlers" */
|
|
12
|
+
generatedFile: string;
|
|
13
|
+
/** Name of the singleton array exported by the plugin package, e.g. "autoRegisteredEmailHandlers" */
|
|
14
|
+
registrationVar: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional callback to confirm a file should be registered.
|
|
17
|
+
* Receives the raw file content and the absolute file path.
|
|
18
|
+
* Return true to include the file, false to skip it.
|
|
19
|
+
*/
|
|
20
|
+
detectBy?: (fileContent: string, filePath: string) => boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Flink configuration file structure
|
|
24
|
+
*/
|
|
25
|
+
export interface FlinkConfig {
|
|
26
|
+
logging?: LoggingConfig;
|
|
27
|
+
/** Compiler plugins that extend auto-discovery to custom directories */
|
|
28
|
+
compilerPlugins?: FlinkCompilerPlugin[];
|
|
29
|
+
/** Disable auto-discovery of services from src/services/. Default: false */
|
|
30
|
+
disableServices?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Load Flink configuration from flink.config.js in current working directory
|
|
34
|
+
*
|
|
35
|
+
* @returns FlinkConfig object or undefined if not found/invalid
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```javascript
|
|
39
|
+
* // flink.config.js
|
|
40
|
+
* module.exports = {
|
|
41
|
+
* logging: {
|
|
42
|
+
* global: "info",
|
|
43
|
+
* showTimestamps: true,
|
|
44
|
+
* components: {
|
|
45
|
+
* "flink.ai.openai": "trace",
|
|
46
|
+
* "flink.ai.*": "debug",
|
|
47
|
+
* "flink.database.**": "warn"
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
* };
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadFlinkConfig(cwd?: string): FlinkConfig | undefined;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.loadFlinkConfig = loadFlinkConfig;
|
|
27
|
+
var path = __importStar(require("path"));
|
|
28
|
+
var fs = __importStar(require("fs"));
|
|
29
|
+
/**
|
|
30
|
+
* Load Flink configuration from flink.config.js in current working directory
|
|
31
|
+
*
|
|
32
|
+
* @returns FlinkConfig object or undefined if not found/invalid
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```javascript
|
|
36
|
+
* // flink.config.js
|
|
37
|
+
* module.exports = {
|
|
38
|
+
* logging: {
|
|
39
|
+
* global: "info",
|
|
40
|
+
* showTimestamps: true,
|
|
41
|
+
* components: {
|
|
42
|
+
* "flink.ai.openai": "trace",
|
|
43
|
+
* "flink.ai.*": "debug",
|
|
44
|
+
* "flink.database.**": "warn"
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function loadFlinkConfig(cwd) {
|
|
51
|
+
try {
|
|
52
|
+
// Look for flink.config.js in current working directory (or provided cwd)
|
|
53
|
+
var configPath = path.join(cwd !== null && cwd !== void 0 ? cwd : process.cwd(), "flink.config.js");
|
|
54
|
+
// Check if file exists
|
|
55
|
+
if (!fs.existsSync(configPath)) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
// Load config using require (CommonJS)
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
60
|
+
var config = require(configPath);
|
|
61
|
+
// Validate structure
|
|
62
|
+
if (!config || typeof config !== "object") {
|
|
63
|
+
console.warn("[flink] Warning: flink.config.js exists but does not export an object");
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
// Validate logging config if present
|
|
67
|
+
if (config.logging && typeof config.logging !== "object") {
|
|
68
|
+
console.warn("[flink] Warning: flink.config.js has invalid logging config (must be object)");
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.warn("[flink] Warning: Failed to load flink.config.js:", error);
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|