@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,205 @@
|
|
|
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
|
+
|
|
15
|
+
export interface Token {
|
|
16
|
+
type: 'string' | 'comment' | 'bracket' | 'char';
|
|
17
|
+
value: string;
|
|
18
|
+
startPos: number;
|
|
19
|
+
endPos: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class TypeScriptTokenizer {
|
|
23
|
+
private text: string;
|
|
24
|
+
private pos: number = 0;
|
|
25
|
+
|
|
26
|
+
constructor(text: string) {
|
|
27
|
+
this.text = text;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Find matching closing bracket from current position.
|
|
32
|
+
* Properly handles strings and comments.
|
|
33
|
+
*
|
|
34
|
+
* @param openChar Opening bracket character
|
|
35
|
+
* @returns Position of matching closing bracket, or -1 if not found
|
|
36
|
+
*/
|
|
37
|
+
findMatchingBracket(openChar: '{' | '<' | '(' | '['): number {
|
|
38
|
+
const closeChar = this.getClosingBracket(openChar);
|
|
39
|
+
let depth = 1;
|
|
40
|
+
let i = this.pos + 1;
|
|
41
|
+
|
|
42
|
+
while (i < this.text.length && depth > 0) {
|
|
43
|
+
const token = this.getNextToken(i);
|
|
44
|
+
|
|
45
|
+
// Only count brackets outside strings and comments
|
|
46
|
+
if (token.type === 'bracket') {
|
|
47
|
+
if (token.value === openChar) {
|
|
48
|
+
depth++;
|
|
49
|
+
} else if (token.value === closeChar) {
|
|
50
|
+
depth--;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
i = token.endPos;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return depth === 0 ? i - 1 : -1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Find matching closing bracket from a specific start position.
|
|
62
|
+
*/
|
|
63
|
+
findMatchingBracketAt(startPos: number, openChar: '{' | '<' | '(' | '['): number {
|
|
64
|
+
this.pos = startPos;
|
|
65
|
+
return this.findMatchingBracket(openChar);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get next meaningful token, properly handling strings and comments.
|
|
70
|
+
* Public for use in other parsing utilities.
|
|
71
|
+
*/
|
|
72
|
+
getNextToken(startPos: number): Token {
|
|
73
|
+
const char = this.text[startPos];
|
|
74
|
+
|
|
75
|
+
// String literal (single, double, or backtick quotes)
|
|
76
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
77
|
+
return this.parseStringLiteral(startPos, char);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Line comment
|
|
81
|
+
if (char === '/' && this.text[startPos + 1] === '/') {
|
|
82
|
+
return this.parseLineComment(startPos);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Block comment
|
|
86
|
+
if (char === '/' && this.text[startPos + 1] === '*') {
|
|
87
|
+
return this.parseBlockComment(startPos);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Bracket characters
|
|
91
|
+
if ('{}<>()[]'.includes(char)) {
|
|
92
|
+
return {
|
|
93
|
+
type: 'bracket',
|
|
94
|
+
value: char,
|
|
95
|
+
startPos,
|
|
96
|
+
endPos: startPos + 1,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Other character (not important for bracket matching)
|
|
101
|
+
return {
|
|
102
|
+
type: 'char',
|
|
103
|
+
value: char,
|
|
104
|
+
startPos,
|
|
105
|
+
endPos: startPos + 1,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Parse string literal, handling escape sequences.
|
|
111
|
+
*/
|
|
112
|
+
private parseStringLiteral(startPos: number, quoteChar: string): Token {
|
|
113
|
+
let i = startPos + 1;
|
|
114
|
+
let escaped = false;
|
|
115
|
+
|
|
116
|
+
while (i < this.text.length) {
|
|
117
|
+
if (escaped) {
|
|
118
|
+
// Skip escaped character
|
|
119
|
+
escaped = false;
|
|
120
|
+
i++;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (this.text[i] === '\\') {
|
|
125
|
+
// Found escape sequence
|
|
126
|
+
escaped = true;
|
|
127
|
+
i++;
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (this.text[i] === quoteChar) {
|
|
132
|
+
// Found closing quote
|
|
133
|
+
return {
|
|
134
|
+
type: 'string',
|
|
135
|
+
value: this.text.slice(startPos, i + 1),
|
|
136
|
+
startPos,
|
|
137
|
+
endPos: i + 1,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
i++;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Unclosed string - return what we have
|
|
145
|
+
// (Let TypeScript compiler handle the error)
|
|
146
|
+
return {
|
|
147
|
+
type: 'string',
|
|
148
|
+
value: this.text.slice(startPos),
|
|
149
|
+
startPos,
|
|
150
|
+
endPos: this.text.length,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Parse line comment (// ... \n).
|
|
156
|
+
*/
|
|
157
|
+
private parseLineComment(startPos: number): Token {
|
|
158
|
+
const newlinePos = this.text.indexOf('\n', startPos);
|
|
159
|
+
const endPos = newlinePos === -1 ? this.text.length : newlinePos + 1;
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
type: 'comment',
|
|
163
|
+
value: this.text.slice(startPos, endPos),
|
|
164
|
+
startPos,
|
|
165
|
+
endPos,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Parse block comment (/* ... *\/).
|
|
171
|
+
*/
|
|
172
|
+
private parseBlockComment(startPos: number): Token {
|
|
173
|
+
const endPos = this.text.indexOf('*/', startPos + 2);
|
|
174
|
+
|
|
175
|
+
if (endPos === -1) {
|
|
176
|
+
// Unclosed block comment - return what we have
|
|
177
|
+
return {
|
|
178
|
+
type: 'comment',
|
|
179
|
+
value: this.text.slice(startPos),
|
|
180
|
+
startPos,
|
|
181
|
+
endPos: this.text.length,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
type: 'comment',
|
|
187
|
+
value: this.text.slice(startPos, endPos + 2),
|
|
188
|
+
startPos,
|
|
189
|
+
endPos: endPos + 2,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Get closing bracket character for an opening bracket.
|
|
195
|
+
*/
|
|
196
|
+
private getClosingBracket(open: string): string {
|
|
197
|
+
const pairs: Record<string, string> = {
|
|
198
|
+
'{': '}',
|
|
199
|
+
'<': '>',
|
|
200
|
+
'(': ')',
|
|
201
|
+
'[': ']',
|
|
202
|
+
};
|
|
203
|
+
return pairs[open];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema type detection result
|
|
3
|
+
*/
|
|
4
|
+
export interface SchemaTypeDetection {
|
|
5
|
+
hasZodSchemas: boolean;
|
|
6
|
+
hasJsonSchemas: boolean;
|
|
7
|
+
shouldSkipTypeScriptExtraction: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* FlinkTool type arguments extracted from source
|
|
12
|
+
*/
|
|
13
|
+
export interface FlinkToolTypeArgs {
|
|
14
|
+
contextType: string;
|
|
15
|
+
inputType: string;
|
|
16
|
+
outputType: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Result of type definition search
|
|
21
|
+
*/
|
|
22
|
+
export interface TypeDefinition {
|
|
23
|
+
name: string;
|
|
24
|
+
definition: string;
|
|
25
|
+
kind: 'interface' | 'type';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Metadata for a single property (parameter or query field)
|
|
30
|
+
*/
|
|
31
|
+
export interface PropertyMetadata {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import { LoggingConfig } from "../FlinkLogFactory";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Compiler plugin descriptor — declared in flink.config.js, consumed by the TypeScript compiler.
|
|
7
|
+
* Plugin packages export a compilerPlugin() factory that returns this shape.
|
|
8
|
+
*/
|
|
9
|
+
export interface FlinkCompilerPlugin {
|
|
10
|
+
/** npm package name, e.g. "@flink-app/inbound-email-plugin" */
|
|
11
|
+
package: string;
|
|
12
|
+
/** Directory to scan for handler files, e.g. "src/email-handlers" */
|
|
13
|
+
scanDir: string;
|
|
14
|
+
/** Base name for the generated .flink/generatedXxx.ts file, e.g. "generatedEmailHandlers" */
|
|
15
|
+
generatedFile: string;
|
|
16
|
+
/** Name of the singleton array exported by the plugin package, e.g. "autoRegisteredEmailHandlers" */
|
|
17
|
+
registrationVar: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional callback to confirm a file should be registered.
|
|
20
|
+
* Receives the raw file content and the absolute file path.
|
|
21
|
+
* Return true to include the file, false to skip it.
|
|
22
|
+
*/
|
|
23
|
+
detectBy?: (fileContent: string, filePath: string) => boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Flink configuration file structure
|
|
28
|
+
*/
|
|
29
|
+
export interface FlinkConfig {
|
|
30
|
+
logging?: LoggingConfig;
|
|
31
|
+
/** Compiler plugins that extend auto-discovery to custom directories */
|
|
32
|
+
compilerPlugins?: FlinkCompilerPlugin[];
|
|
33
|
+
/** Disable auto-discovery of services from src/services/. Default: false */
|
|
34
|
+
disableServices?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Load Flink configuration from flink.config.js in current working directory
|
|
39
|
+
*
|
|
40
|
+
* @returns FlinkConfig object or undefined if not found/invalid
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```javascript
|
|
44
|
+
* // flink.config.js
|
|
45
|
+
* module.exports = {
|
|
46
|
+
* logging: {
|
|
47
|
+
* global: "info",
|
|
48
|
+
* showTimestamps: true,
|
|
49
|
+
* components: {
|
|
50
|
+
* "flink.ai.openai": "trace",
|
|
51
|
+
* "flink.ai.*": "debug",
|
|
52
|
+
* "flink.database.**": "warn"
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* };
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function loadFlinkConfig(cwd?: string): FlinkConfig | undefined {
|
|
59
|
+
try {
|
|
60
|
+
// Look for flink.config.js in current working directory (or provided cwd)
|
|
61
|
+
const configPath = path.join(cwd ?? process.cwd(), "flink.config.js");
|
|
62
|
+
|
|
63
|
+
// Check if file exists
|
|
64
|
+
if (!fs.existsSync(configPath)) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Load config using require (CommonJS)
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
70
|
+
const config = require(configPath);
|
|
71
|
+
|
|
72
|
+
// Validate structure
|
|
73
|
+
if (!config || typeof config !== "object") {
|
|
74
|
+
console.warn(`[flink] Warning: flink.config.js exists but does not export an object`);
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Validate logging config if present
|
|
79
|
+
if (config.logging && typeof config.logging !== "object") {
|
|
80
|
+
console.warn(`[flink] Warning: flink.config.js has invalid logging config (must be object)`);
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return config as FlinkConfig;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.warn(`[flink] Warning: Failed to load flink.config.js:`, error);
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -59,6 +59,45 @@ export function getRepoInstanceName(fn: string) {
|
|
|
59
59
|
return name.charAt(0).toLowerCase() + name.substr(1);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Convert PascalCase or camelCase to kebab-case
|
|
64
|
+
*
|
|
65
|
+
* Examples:
|
|
66
|
+
* - FooBarBaz → foo-bar-baz
|
|
67
|
+
* - CarAgent → car-agent
|
|
68
|
+
* - APIAgent → api-agent
|
|
69
|
+
* - HTMLParser → html-parser
|
|
70
|
+
* - IOManager → io-manager
|
|
71
|
+
*
|
|
72
|
+
* Handles:
|
|
73
|
+
* - Single uppercase followed by lowercase: CarAgent → car-agent
|
|
74
|
+
* - Multiple consecutive uppercase: APIAgent → api-agent
|
|
75
|
+
* - All caps: HTML → html
|
|
76
|
+
*/
|
|
77
|
+
export function toKebabCase(str: string): string {
|
|
78
|
+
return str
|
|
79
|
+
// Insert hyphen before uppercase letters that follow lowercase letters
|
|
80
|
+
// CarAgent → Car-Agent
|
|
81
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
82
|
+
// Insert hyphen before uppercase letter that follows uppercase and precedes lowercase
|
|
83
|
+
// APIAgent → API-Agent
|
|
84
|
+
.replace(/([A-Z])([A-Z][a-z])/g, "$1-$2")
|
|
85
|
+
// Convert to lowercase
|
|
86
|
+
.toLowerCase();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Convert kebab-case to snake_case
|
|
91
|
+
*
|
|
92
|
+
* Examples:
|
|
93
|
+
* - car-agent → car_agent
|
|
94
|
+
* - api-agent → api_agent
|
|
95
|
+
* - html-parser → html_parser
|
|
96
|
+
*/
|
|
97
|
+
export function toSnakeCase(str: string): string {
|
|
98
|
+
return str.replace(/-/g, "_");
|
|
99
|
+
}
|
|
100
|
+
|
|
62
101
|
/**
|
|
63
102
|
* Get http method from props or convention based on file name
|
|
64
103
|
* if it starts with i.e "GetFoo"
|
|
@@ -177,3 +216,16 @@ export function formatValidationErrors(errors: any[] | null | undefined, data: a
|
|
|
177
216
|
|
|
178
217
|
return formatted.join("\n");
|
|
179
218
|
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Generate a short random ID for nested conversations
|
|
222
|
+
* Format: 8 character alphanumeric string (e.g., "a3b7c9d2")
|
|
223
|
+
*/
|
|
224
|
+
export function generateShortId(): string {
|
|
225
|
+
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
226
|
+
let result = "";
|
|
227
|
+
for (let i = 0; i < 8; i++) {
|
|
228
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -16,7 +16,12 @@
|
|
|
16
16
|
"checkJs": false,
|
|
17
17
|
"typeRoots": ["./typings", "./node_modules/@types"],
|
|
18
18
|
"declaration": true,
|
|
19
|
-
"outDir": "dist"
|
|
19
|
+
"outDir": "dist",
|
|
20
|
+
"baseUrl": ".",
|
|
21
|
+
"paths": {
|
|
22
|
+
"@flink-app/flink": ["./src/index.ts"],
|
|
23
|
+
"@flink-app/flink/*": ["./src/*"]
|
|
24
|
+
}
|
|
20
25
|
},
|
|
21
26
|
"include": ["./src/**/*.ts", "./bin/*", "./cli/*", "./spec/**/*.ts"],
|
|
22
27
|
"exclude": ["./node_modules/*", "./spec/mock-project/*"]
|