@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
package/dist/src/utils.d.ts
CHANGED
|
@@ -12,6 +12,31 @@ export declare function getHandlerFiles(appRoot: string): Promise<string[]>;
|
|
|
12
12
|
export declare function getSchemaFiles(appRoot: string): Promise<string[]>;
|
|
13
13
|
export declare function getCollectionNameForRepo(repoFilename: string): string;
|
|
14
14
|
export declare function getRepoInstanceName(fn: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Convert PascalCase or camelCase to kebab-case
|
|
17
|
+
*
|
|
18
|
+
* Examples:
|
|
19
|
+
* - FooBarBaz ā foo-bar-baz
|
|
20
|
+
* - CarAgent ā car-agent
|
|
21
|
+
* - APIAgent ā api-agent
|
|
22
|
+
* - HTMLParser ā html-parser
|
|
23
|
+
* - IOManager ā io-manager
|
|
24
|
+
*
|
|
25
|
+
* Handles:
|
|
26
|
+
* - Single uppercase followed by lowercase: CarAgent ā car-agent
|
|
27
|
+
* - Multiple consecutive uppercase: APIAgent ā api-agent
|
|
28
|
+
* - All caps: HTML ā html
|
|
29
|
+
*/
|
|
30
|
+
export declare function toKebabCase(str: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Convert kebab-case to snake_case
|
|
33
|
+
*
|
|
34
|
+
* Examples:
|
|
35
|
+
* - car-agent ā car_agent
|
|
36
|
+
* - api-agent ā api_agent
|
|
37
|
+
* - html-parser ā html_parser
|
|
38
|
+
*/
|
|
39
|
+
export declare function toSnakeCase(str: string): string;
|
|
15
40
|
/**
|
|
16
41
|
* Get http method from props or convention based on file name
|
|
17
42
|
* if it starts with i.e "GetFoo"
|
|
@@ -37,3 +62,8 @@ export declare function getDataAtPath(data: any, instancePath: string): any;
|
|
|
37
62
|
* @param maxDataLength Maximum length of data to show (default 500)
|
|
38
63
|
*/
|
|
39
64
|
export declare function formatValidationErrors(errors: any[] | null | undefined, data: any, maxDataLength?: number): string;
|
|
65
|
+
/**
|
|
66
|
+
* Generate a short random ID for nested conversations
|
|
67
|
+
* Format: 8 character alphanumeric string (e.g., "a3b7c9d2")
|
|
68
|
+
*/
|
|
69
|
+
export declare function generateShortId(): string;
|
package/dist/src/utils.js
CHANGED
|
@@ -47,11 +47,14 @@ exports.getHandlerFiles = getHandlerFiles;
|
|
|
47
47
|
exports.getSchemaFiles = getSchemaFiles;
|
|
48
48
|
exports.getCollectionNameForRepo = getCollectionNameForRepo;
|
|
49
49
|
exports.getRepoInstanceName = getRepoInstanceName;
|
|
50
|
+
exports.toKebabCase = toKebabCase;
|
|
51
|
+
exports.toSnakeCase = toSnakeCase;
|
|
50
52
|
exports.getHttpMethodFromHandlerName = getHttpMethodFromHandlerName;
|
|
51
53
|
exports.getJsDocComment = getJsDocComment;
|
|
52
54
|
exports.getPathParams = getPathParams;
|
|
53
55
|
exports.getDataAtPath = getDataAtPath;
|
|
54
56
|
exports.formatValidationErrors = formatValidationErrors;
|
|
57
|
+
exports.generateShortId = generateShortId;
|
|
55
58
|
var path_1 = require("path");
|
|
56
59
|
var tiny_glob_1 = __importDefault(require("tiny-glob"));
|
|
57
60
|
var FlinkHttpHandler_1 = require("./FlinkHttpHandler");
|
|
@@ -122,6 +125,43 @@ function getRepoInstanceName(fn) {
|
|
|
122
125
|
var name = fn.split(".ts")[0];
|
|
123
126
|
return name.charAt(0).toLowerCase() + name.substr(1);
|
|
124
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Convert PascalCase or camelCase to kebab-case
|
|
130
|
+
*
|
|
131
|
+
* Examples:
|
|
132
|
+
* - FooBarBaz ā foo-bar-baz
|
|
133
|
+
* - CarAgent ā car-agent
|
|
134
|
+
* - APIAgent ā api-agent
|
|
135
|
+
* - HTMLParser ā html-parser
|
|
136
|
+
* - IOManager ā io-manager
|
|
137
|
+
*
|
|
138
|
+
* Handles:
|
|
139
|
+
* - Single uppercase followed by lowercase: CarAgent ā car-agent
|
|
140
|
+
* - Multiple consecutive uppercase: APIAgent ā api-agent
|
|
141
|
+
* - All caps: HTML ā html
|
|
142
|
+
*/
|
|
143
|
+
function toKebabCase(str) {
|
|
144
|
+
return str
|
|
145
|
+
// Insert hyphen before uppercase letters that follow lowercase letters
|
|
146
|
+
// CarAgent ā Car-Agent
|
|
147
|
+
.replace(/([a-z])([A-Z])/g, "$1-$2")
|
|
148
|
+
// Insert hyphen before uppercase letter that follows uppercase and precedes lowercase
|
|
149
|
+
// APIAgent ā API-Agent
|
|
150
|
+
.replace(/([A-Z])([A-Z][a-z])/g, "$1-$2")
|
|
151
|
+
// Convert to lowercase
|
|
152
|
+
.toLowerCase();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Convert kebab-case to snake_case
|
|
156
|
+
*
|
|
157
|
+
* Examples:
|
|
158
|
+
* - car-agent ā car_agent
|
|
159
|
+
* - api-agent ā api_agent
|
|
160
|
+
* - html-parser ā html_parser
|
|
161
|
+
*/
|
|
162
|
+
function toSnakeCase(str) {
|
|
163
|
+
return str.replace(/-/g, "_");
|
|
164
|
+
}
|
|
125
165
|
/**
|
|
126
166
|
* Get http method from props or convention based on file name
|
|
127
167
|
* if it starts with i.e "GetFoo"
|
|
@@ -236,3 +276,15 @@ function formatValidationErrors(errors, data, maxDataLength) {
|
|
|
236
276
|
});
|
|
237
277
|
return formatted.join("\n");
|
|
238
278
|
}
|
|
279
|
+
/**
|
|
280
|
+
* Generate a short random ID for nested conversations
|
|
281
|
+
* Format: 8 character alphanumeric string (e.g., "a3b7c9d2")
|
|
282
|
+
*/
|
|
283
|
+
function generateShortId() {
|
|
284
|
+
var chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
285
|
+
var result = "";
|
|
286
|
+
for (var i = 0; i < 8; i++) {
|
|
287
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var worker_threads_1 = require("worker_threads");
|
|
4
|
+
var ts_json_schema_generator_1 = require("ts-json-schema-generator");
|
|
5
|
+
if (!worker_threads_1.parentPort) {
|
|
6
|
+
throw new Error("This script must be run as a worker thread");
|
|
7
|
+
}
|
|
8
|
+
worker_threads_1.parentPort.on("message", function (input) {
|
|
9
|
+
try {
|
|
10
|
+
// Configure schema generator - match the config from TypeScriptCompiler
|
|
11
|
+
var config = {
|
|
12
|
+
path: input.schemaFilePath,
|
|
13
|
+
expose: "export",
|
|
14
|
+
topRef: false,
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
jsDoc: "basic",
|
|
17
|
+
sortProps: false,
|
|
18
|
+
strictTuples: false,
|
|
19
|
+
minify: false,
|
|
20
|
+
markdownDescription: false,
|
|
21
|
+
skipTypeCheck: true,
|
|
22
|
+
encodeRefs: false,
|
|
23
|
+
extraTags: [],
|
|
24
|
+
functions: "fail",
|
|
25
|
+
discriminatorType: "json-schema",
|
|
26
|
+
tsconfig: input.tsconfigPath,
|
|
27
|
+
};
|
|
28
|
+
// Create TypeScript program and schema generator
|
|
29
|
+
var program = (0, ts_json_schema_generator_1.createProgram)(config);
|
|
30
|
+
var parser = (0, ts_json_schema_generator_1.createParser)(program, config);
|
|
31
|
+
var formatter = (0, ts_json_schema_generator_1.createFormatter)(config);
|
|
32
|
+
var generator = new ts_json_schema_generator_1.SchemaGenerator(program, parser, formatter, config);
|
|
33
|
+
// Generate schema for the type
|
|
34
|
+
var schema = generator.createSchema(input.typeName);
|
|
35
|
+
// Send result back to main thread
|
|
36
|
+
worker_threads_1.parentPort.postMessage({
|
|
37
|
+
typeName: input.typeName,
|
|
38
|
+
schema: schema,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
// Send error back to main thread
|
|
43
|
+
worker_threads_1.parentPort.postMessage({
|
|
44
|
+
typeName: input.typeName,
|
|
45
|
+
schema: {},
|
|
46
|
+
error: error.message || String(error),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare class WorkerPool<TInput, TOutput> {
|
|
2
|
+
private workerScriptPath;
|
|
3
|
+
private taskTimeout;
|
|
4
|
+
private workers;
|
|
5
|
+
private availableWorkers;
|
|
6
|
+
private taskQueue;
|
|
7
|
+
private workerTasks;
|
|
8
|
+
private poolSize;
|
|
9
|
+
private initialized;
|
|
10
|
+
constructor(workerScriptPath: string, poolSize?: number, taskTimeout?: number);
|
|
11
|
+
/**
|
|
12
|
+
* Calculate optimal pool size based on CPU count and memory
|
|
13
|
+
*/
|
|
14
|
+
private calculateOptimalPoolSize;
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the worker pool
|
|
17
|
+
*/
|
|
18
|
+
initialize(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Execute a task using an available worker
|
|
21
|
+
*/
|
|
22
|
+
execute(input: TInput): Promise<TOutput>;
|
|
23
|
+
/**
|
|
24
|
+
* Assign a task to an available worker
|
|
25
|
+
*/
|
|
26
|
+
private assignTaskToWorker;
|
|
27
|
+
/**
|
|
28
|
+
* Handle message received from worker
|
|
29
|
+
*/
|
|
30
|
+
private handleWorkerMessage;
|
|
31
|
+
/**
|
|
32
|
+
* Handle worker error
|
|
33
|
+
*/
|
|
34
|
+
private handleWorkerError;
|
|
35
|
+
/**
|
|
36
|
+
* Handle worker exit
|
|
37
|
+
*/
|
|
38
|
+
private handleWorkerExit;
|
|
39
|
+
/**
|
|
40
|
+
* Handle task timeout
|
|
41
|
+
*/
|
|
42
|
+
private handleTaskTimeout;
|
|
43
|
+
/**
|
|
44
|
+
* Process next task from queue
|
|
45
|
+
*/
|
|
46
|
+
private processNextTask;
|
|
47
|
+
/**
|
|
48
|
+
* Terminate all workers and clean up
|
|
49
|
+
*/
|
|
50
|
+
terminate(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get pool statistics
|
|
53
|
+
*/
|
|
54
|
+
getStats(): {
|
|
55
|
+
poolSize: number;
|
|
56
|
+
availableWorkers: number;
|
|
57
|
+
activeTasks: number;
|
|
58
|
+
queuedTasks: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.WorkerPool = void 0;
|
|
43
|
+
var worker_threads_1 = require("worker_threads");
|
|
44
|
+
var os_1 = __importDefault(require("os"));
|
|
45
|
+
var WorkerPool = /** @class */ (function () {
|
|
46
|
+
function WorkerPool(workerScriptPath, poolSize, taskTimeout) {
|
|
47
|
+
if (taskTimeout === void 0) { taskTimeout = 30000; }
|
|
48
|
+
this.workerScriptPath = workerScriptPath;
|
|
49
|
+
this.taskTimeout = taskTimeout;
|
|
50
|
+
this.workers = [];
|
|
51
|
+
this.availableWorkers = [];
|
|
52
|
+
this.taskQueue = [];
|
|
53
|
+
this.workerTasks = new Map();
|
|
54
|
+
this.initialized = false;
|
|
55
|
+
this.poolSize = poolSize || this.calculateOptimalPoolSize();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Calculate optimal pool size based on CPU count and memory
|
|
59
|
+
*/
|
|
60
|
+
WorkerPool.prototype.calculateOptimalPoolSize = function () {
|
|
61
|
+
var cpuCount = os_1.default.cpus().length;
|
|
62
|
+
var availableMemoryGB = os_1.default.totalmem() / (Math.pow(1024, 3));
|
|
63
|
+
// Memory constraint: 20MB per worker, use max 30% of RAM
|
|
64
|
+
var maxByMemory = Math.floor((availableMemoryGB * 0.3) / 0.02);
|
|
65
|
+
// CPU constraint: Leave 2 cores for main thread + OS
|
|
66
|
+
var maxByCPU = Math.max(1, cpuCount - 2);
|
|
67
|
+
// Cap at 8 for diminishing returns
|
|
68
|
+
return Math.min(8, maxByMemory, maxByCPU);
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Initialize the worker pool
|
|
72
|
+
*/
|
|
73
|
+
WorkerPool.prototype.initialize = function () {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
75
|
+
var _loop_1, this_1, i;
|
|
76
|
+
var _this = this;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
if (this.initialized) {
|
|
79
|
+
return [2 /*return*/];
|
|
80
|
+
}
|
|
81
|
+
_loop_1 = function (i) {
|
|
82
|
+
var worker = new worker_threads_1.Worker(this_1.workerScriptPath);
|
|
83
|
+
this_1.workers.push(worker);
|
|
84
|
+
this_1.availableWorkers.push(worker);
|
|
85
|
+
worker.on("message", function (message) {
|
|
86
|
+
_this.handleWorkerMessage(worker, message);
|
|
87
|
+
});
|
|
88
|
+
worker.on("error", function (error) {
|
|
89
|
+
_this.handleWorkerError(worker, error);
|
|
90
|
+
});
|
|
91
|
+
worker.on("exit", function (code) {
|
|
92
|
+
_this.handleWorkerExit(worker, code);
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
this_1 = this;
|
|
96
|
+
for (i = 0; i < this.poolSize; i++) {
|
|
97
|
+
_loop_1(i);
|
|
98
|
+
}
|
|
99
|
+
this.initialized = true;
|
|
100
|
+
return [2 /*return*/];
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Execute a task using an available worker
|
|
106
|
+
*/
|
|
107
|
+
WorkerPool.prototype.execute = function (input) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
var _this = this;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
if (!this.initialized) {
|
|
112
|
+
throw new Error("Worker pool not initialized. Call initialize() first.");
|
|
113
|
+
}
|
|
114
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
115
|
+
var task = { input: input, resolve: resolve, reject: reject };
|
|
116
|
+
if (_this.availableWorkers.length > 0) {
|
|
117
|
+
_this.assignTaskToWorker(task);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
_this.taskQueue.push(task);
|
|
121
|
+
}
|
|
122
|
+
})];
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Assign a task to an available worker
|
|
128
|
+
*/
|
|
129
|
+
WorkerPool.prototype.assignTaskToWorker = function (task) {
|
|
130
|
+
var _this = this;
|
|
131
|
+
var worker = this.availableWorkers.shift();
|
|
132
|
+
if (!worker) {
|
|
133
|
+
this.taskQueue.push(task);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
this.workerTasks.set(worker, task);
|
|
137
|
+
// Set timeout for task
|
|
138
|
+
task.timeout = setTimeout(function () {
|
|
139
|
+
_this.handleTaskTimeout(worker);
|
|
140
|
+
}, this.taskTimeout);
|
|
141
|
+
worker.postMessage(task.input);
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Handle message received from worker
|
|
145
|
+
*/
|
|
146
|
+
WorkerPool.prototype.handleWorkerMessage = function (worker, message) {
|
|
147
|
+
var task = this.workerTasks.get(worker);
|
|
148
|
+
if (!task) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
// Clear timeout
|
|
152
|
+
if (task.timeout) {
|
|
153
|
+
clearTimeout(task.timeout);
|
|
154
|
+
}
|
|
155
|
+
// Remove task from active tasks
|
|
156
|
+
this.workerTasks.delete(worker);
|
|
157
|
+
// Resolve the task
|
|
158
|
+
task.resolve(message);
|
|
159
|
+
// Make worker available again
|
|
160
|
+
this.availableWorkers.push(worker);
|
|
161
|
+
// Process next task in queue
|
|
162
|
+
this.processNextTask();
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Handle worker error
|
|
166
|
+
*/
|
|
167
|
+
WorkerPool.prototype.handleWorkerError = function (worker, error) {
|
|
168
|
+
var task = this.workerTasks.get(worker);
|
|
169
|
+
if (task) {
|
|
170
|
+
// Clear timeout
|
|
171
|
+
if (task.timeout) {
|
|
172
|
+
clearTimeout(task.timeout);
|
|
173
|
+
}
|
|
174
|
+
// Remove task and reject
|
|
175
|
+
this.workerTasks.delete(worker);
|
|
176
|
+
task.reject(error);
|
|
177
|
+
// Make worker available again (it might still be usable)
|
|
178
|
+
this.availableWorkers.push(worker);
|
|
179
|
+
// Process next task
|
|
180
|
+
this.processNextTask();
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Handle worker exit
|
|
185
|
+
*/
|
|
186
|
+
WorkerPool.prototype.handleWorkerExit = function (worker, code) {
|
|
187
|
+
var task = this.workerTasks.get(worker);
|
|
188
|
+
if (task) {
|
|
189
|
+
// Clear timeout
|
|
190
|
+
if (task.timeout) {
|
|
191
|
+
clearTimeout(task.timeout);
|
|
192
|
+
}
|
|
193
|
+
// Remove task and reject
|
|
194
|
+
this.workerTasks.delete(worker);
|
|
195
|
+
task.reject(new Error("Worker exited with code ".concat(code)));
|
|
196
|
+
}
|
|
197
|
+
// Remove worker from all lists
|
|
198
|
+
var workerIndex = this.workers.indexOf(worker);
|
|
199
|
+
if (workerIndex !== -1) {
|
|
200
|
+
this.workers.splice(workerIndex, 1);
|
|
201
|
+
}
|
|
202
|
+
var availableIndex = this.availableWorkers.indexOf(worker);
|
|
203
|
+
if (availableIndex !== -1) {
|
|
204
|
+
this.availableWorkers.splice(availableIndex, 1);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Handle task timeout
|
|
209
|
+
*/
|
|
210
|
+
WorkerPool.prototype.handleTaskTimeout = function (worker) {
|
|
211
|
+
var _this = this;
|
|
212
|
+
var task = this.workerTasks.get(worker);
|
|
213
|
+
if (!task) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// Remove task and reject
|
|
217
|
+
this.workerTasks.delete(worker);
|
|
218
|
+
task.reject(new Error("Task timeout exceeded"));
|
|
219
|
+
// Terminate the worker and create a new one
|
|
220
|
+
worker.terminate();
|
|
221
|
+
// Remove from available workers
|
|
222
|
+
var availableIndex = this.availableWorkers.indexOf(worker);
|
|
223
|
+
if (availableIndex !== -1) {
|
|
224
|
+
this.availableWorkers.splice(availableIndex, 1);
|
|
225
|
+
}
|
|
226
|
+
// Create a new worker to replace it
|
|
227
|
+
var newWorker = new worker_threads_1.Worker(this.workerScriptPath);
|
|
228
|
+
this.workers.push(newWorker);
|
|
229
|
+
this.availableWorkers.push(newWorker);
|
|
230
|
+
newWorker.on("message", function (message) {
|
|
231
|
+
_this.handleWorkerMessage(newWorker, message);
|
|
232
|
+
});
|
|
233
|
+
newWorker.on("error", function (error) {
|
|
234
|
+
_this.handleWorkerError(newWorker, error);
|
|
235
|
+
});
|
|
236
|
+
newWorker.on("exit", function (code) {
|
|
237
|
+
_this.handleWorkerExit(newWorker, code);
|
|
238
|
+
});
|
|
239
|
+
// Process next task
|
|
240
|
+
this.processNextTask();
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Process next task from queue
|
|
244
|
+
*/
|
|
245
|
+
WorkerPool.prototype.processNextTask = function () {
|
|
246
|
+
if (this.taskQueue.length > 0 && this.availableWorkers.length > 0) {
|
|
247
|
+
var task = this.taskQueue.shift();
|
|
248
|
+
if (task) {
|
|
249
|
+
this.assignTaskToWorker(task);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Terminate all workers and clean up
|
|
255
|
+
*/
|
|
256
|
+
WorkerPool.prototype.terminate = function () {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
258
|
+
var tasks, _i, tasks_1, task, _a, tasks_2, task, _b, _c, task;
|
|
259
|
+
return __generator(this, function (_d) {
|
|
260
|
+
switch (_d.label) {
|
|
261
|
+
case 0:
|
|
262
|
+
tasks = Array.from(this.workerTasks.values());
|
|
263
|
+
for (_i = 0, tasks_1 = tasks; _i < tasks_1.length; _i++) {
|
|
264
|
+
task = tasks_1[_i];
|
|
265
|
+
if (task.timeout) {
|
|
266
|
+
clearTimeout(task.timeout);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Reject all pending tasks
|
|
270
|
+
for (_a = 0, tasks_2 = tasks; _a < tasks_2.length; _a++) {
|
|
271
|
+
task = tasks_2[_a];
|
|
272
|
+
task.reject(new Error("Worker pool terminated"));
|
|
273
|
+
}
|
|
274
|
+
for (_b = 0, _c = this.taskQueue; _b < _c.length; _b++) {
|
|
275
|
+
task = _c[_b];
|
|
276
|
+
task.reject(new Error("Worker pool terminated"));
|
|
277
|
+
}
|
|
278
|
+
// Terminate all workers
|
|
279
|
+
return [4 /*yield*/, Promise.all(this.workers.map(function (worker) { return worker.terminate(); }))];
|
|
280
|
+
case 1:
|
|
281
|
+
// Terminate all workers
|
|
282
|
+
_d.sent();
|
|
283
|
+
this.workers = [];
|
|
284
|
+
this.availableWorkers = [];
|
|
285
|
+
this.taskQueue = [];
|
|
286
|
+
this.workerTasks.clear();
|
|
287
|
+
this.initialized = false;
|
|
288
|
+
return [2 /*return*/];
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* Get pool statistics
|
|
295
|
+
*/
|
|
296
|
+
WorkerPool.prototype.getStats = function () {
|
|
297
|
+
return {
|
|
298
|
+
poolSize: this.poolSize,
|
|
299
|
+
availableWorkers: this.availableWorkers.length,
|
|
300
|
+
activeTasks: this.workerTasks.size,
|
|
301
|
+
queuedTasks: this.taskQueue.length,
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
return WorkerPool;
|
|
305
|
+
}());
|
|
306
|
+
exports.WorkerPool = WorkerPool;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* Example: Java-Style Hierarchical Logging in Flink
|
|
4
|
+
*
|
|
5
|
+
* This example demonstrates the hierarchical prefix matching feature
|
|
6
|
+
* inspired by Java logging frameworks (Log4j, Logback).
|
|
7
|
+
*
|
|
8
|
+
* Run with:
|
|
9
|
+
* npx tsx packages/flink/examples/logging-hierarchical-example.ts
|
|
10
|
+
*
|
|
11
|
+
* Or with environment variables:
|
|
12
|
+
* LOG_LEVELS=flink.ai:debug npx tsx packages/flink/examples/logging-hierarchical-example.ts
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { FlinkLogFactory } from "../src";
|
|
16
|
+
|
|
17
|
+
console.log("=== Java-Style Hierarchical Logging Example ===\n");
|
|
18
|
+
|
|
19
|
+
// Configure hierarchical logging (Java-style)
|
|
20
|
+
console.log("š Configuration:");
|
|
21
|
+
console.log(" - Global level: warn");
|
|
22
|
+
console.log(" - flink.ai.* ā debug (hierarchical prefix)");
|
|
23
|
+
console.log(" - flink.ai.openai ā trace (exact match - more specific)\n");
|
|
24
|
+
|
|
25
|
+
FlinkLogFactory.setGlobalLevel("warn");
|
|
26
|
+
FlinkLogFactory.setHierarchicalLevel("flink.ai", "debug");
|
|
27
|
+
FlinkLogFactory.setComponentLevel("flink.ai.openai", "trace");
|
|
28
|
+
|
|
29
|
+
// Create loggers (lowercase recommended)
|
|
30
|
+
const openaiLog = FlinkLogFactory.createLogger("flink.ai.openai");
|
|
31
|
+
const anthropicLog = FlinkLogFactory.createLogger("flink.ai.anthropic");
|
|
32
|
+
const claudeLog = FlinkLogFactory.createLogger("flink.ai.claude.v4");
|
|
33
|
+
const dbLog = FlinkLogFactory.createLogger("flink.database.mongodb");
|
|
34
|
+
const cacheLog = FlinkLogFactory.createLogger("flink.cache.redis");
|
|
35
|
+
|
|
36
|
+
// Test case insensitivity
|
|
37
|
+
const openaiLog2 = FlinkLogFactory.createLogger("Flink.AI.OpenAI");
|
|
38
|
+
console.log("ā
Case insensitivity check:");
|
|
39
|
+
console.log(` flink.ai.openai === Flink.AI.OpenAI: ${openaiLog === openaiLog2}\n`);
|
|
40
|
+
|
|
41
|
+
// Display effective levels
|
|
42
|
+
console.log("š Effective Log Levels:");
|
|
43
|
+
console.log(` flink.ai.openai: ${FlinkLogFactory.getEffectiveLevel("flink.ai.openai")} (exact match)`);
|
|
44
|
+
console.log(
|
|
45
|
+
` flink.ai.anthropic: ${FlinkLogFactory.getEffectiveLevel("flink.ai.anthropic")} (prefix: flink.ai.)`
|
|
46
|
+
);
|
|
47
|
+
console.log(
|
|
48
|
+
` flink.ai.claude.v4: ${FlinkLogFactory.getEffectiveLevel("flink.ai.claude.v4")} (prefix: flink.ai.)`
|
|
49
|
+
);
|
|
50
|
+
console.log(
|
|
51
|
+
` flink.database.mongodb: ${
|
|
52
|
+
FlinkLogFactory.getEffectiveLevel("flink.database.mongodb") || "warn (global)"
|
|
53
|
+
}`
|
|
54
|
+
);
|
|
55
|
+
console.log(
|
|
56
|
+
` flink.cache.redis: ${FlinkLogFactory.getEffectiveLevel("flink.cache.redis") || "warn (global)"}\n`
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// Test logging at different levels
|
|
60
|
+
console.log("š Testing Log Output:\n");
|
|
61
|
+
|
|
62
|
+
console.log("--- flink.ai.openai (level: trace) ---");
|
|
63
|
+
openaiLog.trace("This is a TRACE message (visible)");
|
|
64
|
+
openaiLog.debug("This is a DEBUG message (visible)");
|
|
65
|
+
openaiLog.info("This is an INFO message (visible)");
|
|
66
|
+
openaiLog.warn("This is a WARN message (visible)");
|
|
67
|
+
|
|
68
|
+
console.log("\n--- flink.ai.anthropic (level: debug via prefix) ---");
|
|
69
|
+
anthropicLog.debug("This is a DEBUG message (visible)");
|
|
70
|
+
anthropicLog.info("This is an INFO message (visible)");
|
|
71
|
+
console.log("[TRACE message would be hidden]\n");
|
|
72
|
+
|
|
73
|
+
console.log("--- flink.ai.claude.v4 (level: debug via prefix) ---");
|
|
74
|
+
claudeLog.debug("Multi-level prefix matching works!");
|
|
75
|
+
claudeLog.info("Claude v4 logger inherits from flink.ai prefix");
|
|
76
|
+
|
|
77
|
+
console.log("\n--- flink.database.mongodb (level: warn via global) ---");
|
|
78
|
+
dbLog.warn("This is a WARN message (visible)");
|
|
79
|
+
console.log("[INFO and DEBUG messages would be hidden]\n");
|
|
80
|
+
|
|
81
|
+
console.log("--- flink.cache.redis (level: warn via global) ---");
|
|
82
|
+
cacheLog.warn("This is a WARN message (visible)");
|
|
83
|
+
console.log("[INFO and DEBUG messages would be hidden]\n");
|
|
84
|
+
|
|
85
|
+
// Demonstrate wildcard patterns
|
|
86
|
+
console.log("\n=== Wildcard Pattern Example ===\n");
|
|
87
|
+
FlinkLogFactory.setWildcardLevel("flink.database.*", "debug");
|
|
88
|
+
|
|
89
|
+
const mongoLog = FlinkLogFactory.createLogger("flink.database.mongodb");
|
|
90
|
+
const redisLog = FlinkLogFactory.createLogger("flink.database.redis");
|
|
91
|
+
|
|
92
|
+
console.log("š Configuration:");
|
|
93
|
+
console.log(" - flink.database.* ā debug (single-level wildcard)\n");
|
|
94
|
+
|
|
95
|
+
console.log("š Effective Levels:");
|
|
96
|
+
console.log(
|
|
97
|
+
` flink.database.mongodb: ${FlinkLogFactory.getEffectiveLevel("flink.database.mongodb")} (wildcard: flink.database.*)`
|
|
98
|
+
);
|
|
99
|
+
console.log(
|
|
100
|
+
` flink.database.redis: ${FlinkLogFactory.getEffectiveLevel("flink.database.redis")} (wildcard: flink.database.*)\n`
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
console.log("--- flink.database.mongodb (level: debug via wildcard) ---");
|
|
104
|
+
mongoLog.debug("MongoDB debug message (now visible)");
|
|
105
|
+
|
|
106
|
+
console.log("\n--- flink.database.redis (level: debug via wildcard) ---");
|
|
107
|
+
redisLog.debug("Redis debug message (now visible)");
|
|
108
|
+
|
|
109
|
+
// Demonstrate runtime level changes
|
|
110
|
+
console.log("\n\n=== Runtime Level Changes ===\n");
|
|
111
|
+
console.log("Changing flink.ai.openai from trace ā info");
|
|
112
|
+
FlinkLogFactory.setComponentLevel("flink.ai.openai", "info");
|
|
113
|
+
|
|
114
|
+
console.log("\n--- flink.ai.openai (level: info after change) ---");
|
|
115
|
+
openaiLog.info("This INFO message is visible");
|
|
116
|
+
console.log("[DEBUG and TRACE messages would now be hidden]\n");
|
|
117
|
+
|
|
118
|
+
// Reset to original
|
|
119
|
+
console.log("Resetting flink.ai.openai back to trace");
|
|
120
|
+
FlinkLogFactory.setComponentLevel("flink.ai.openai", "trace");
|
|
121
|
+
|
|
122
|
+
console.log("\nā
Example complete! Try running with different LOG_LEVELS:");
|
|
123
|
+
console.log(" LOG_LEVELS=flink.ai:trace npm run example");
|
|
124
|
+
console.log(" LOG_LEVELS=flink.ai:debug,flink.database:info npm run example");
|
|
125
|
+
console.log(" LOG_LEVELS=flink.ai.*:debug,flink.database.**:warn npm run example");
|