@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.
Files changed (280) hide show
  1. package/CHANGELOG.md +1051 -0
  2. package/SCHEMA_EXTRACTION_ANALYSIS.md +494 -0
  3. package/SIMPLE_AST_FEASIBILITY.md +570 -0
  4. package/bin/flink.ts +13 -2
  5. package/cli/build.ts +24 -44
  6. package/cli/clean.ts +13 -25
  7. package/cli/cli-utils.ts +190 -17
  8. package/cli/dev.ts +252 -0
  9. package/cli/loadEnvFiles.ts +116 -0
  10. package/cli/run.ts +45 -62
  11. package/dist/bin/flink.js +61 -2
  12. package/dist/cli/build.js +20 -25
  13. package/dist/cli/clean.js +12 -10
  14. package/dist/cli/cli-utils.d.ts +34 -3
  15. package/dist/cli/cli-utils.js +193 -12
  16. package/dist/cli/dev.d.ts +2 -0
  17. package/dist/cli/dev.js +279 -0
  18. package/dist/cli/loadEnvFiles.d.ts +30 -0
  19. package/dist/cli/loadEnvFiles.js +113 -0
  20. package/dist/cli/run.js +47 -46
  21. package/dist/src/DependencyTracker.d.ts +44 -0
  22. package/dist/src/DependencyTracker.js +239 -0
  23. package/dist/src/FlinkApp.d.ts +163 -10
  24. package/dist/src/FlinkApp.js +847 -184
  25. package/dist/src/FlinkContext.d.ts +41 -0
  26. package/dist/src/FlinkErrors.d.ts +19 -6
  27. package/dist/src/FlinkErrors.js +36 -42
  28. package/dist/src/FlinkHttpHandler.d.ts +219 -26
  29. package/dist/src/FlinkHttpHandler.js +37 -1
  30. package/dist/src/FlinkJob.d.ts +10 -0
  31. package/dist/src/FlinkLog.d.ts +82 -18
  32. package/dist/src/FlinkLog.js +165 -13
  33. package/dist/src/FlinkLogFactory.d.ts +288 -0
  34. package/dist/src/FlinkLogFactory.js +619 -0
  35. package/dist/src/FlinkRepo.d.ts +10 -2
  36. package/dist/src/FlinkRepo.js +11 -1
  37. package/dist/src/FlinkRequestContext.d.ts +63 -0
  38. package/dist/src/FlinkRequestContext.js +74 -0
  39. package/dist/src/FlinkResponse.d.ts +6 -0
  40. package/dist/src/FlinkService.d.ts +38 -0
  41. package/dist/src/FlinkService.js +46 -0
  42. package/dist/src/LeaderElection.d.ts +45 -0
  43. package/dist/src/LeaderElection.js +269 -0
  44. package/dist/src/SchemaCache.d.ts +84 -0
  45. package/dist/src/SchemaCache.js +289 -0
  46. package/dist/src/TypeScriptCompiler.d.ts +161 -51
  47. package/dist/src/TypeScriptCompiler.js +1253 -617
  48. package/dist/src/TypeScriptUtils.js +4 -0
  49. package/dist/src/ai/AgentRunner.d.ts +39 -0
  50. package/dist/src/ai/AgentRunner.js +760 -0
  51. package/dist/src/ai/ConversationAgent.d.ts +279 -0
  52. package/dist/src/ai/ConversationAgent.js +404 -0
  53. package/dist/src/ai/ConversationFlinkAgent.d.ts +278 -0
  54. package/dist/src/ai/ConversationFlinkAgent.js +404 -0
  55. package/dist/src/ai/FlinkAgent.d.ts +690 -0
  56. package/dist/src/ai/FlinkAgent.js +729 -0
  57. package/dist/src/ai/FlinkTool.d.ts +135 -0
  58. package/dist/src/ai/FlinkTool.js +2 -0
  59. package/dist/src/ai/InMemoryConversationAgent.d.ts +121 -0
  60. package/dist/src/ai/InMemoryConversationAgent.js +209 -0
  61. package/dist/src/ai/LLMAdapter.d.ts +148 -0
  62. package/dist/src/ai/LLMAdapter.js +2 -0
  63. package/dist/src/ai/PersistentFlinkAgent.d.ts +278 -0
  64. package/dist/src/ai/PersistentFlinkAgent.js +403 -0
  65. package/dist/src/ai/SubAgentExecutor.d.ts +38 -0
  66. package/dist/src/ai/SubAgentExecutor.js +223 -0
  67. package/dist/src/ai/ToolExecutor.d.ts +64 -0
  68. package/dist/src/ai/ToolExecutor.js +497 -0
  69. package/dist/src/ai/agentInstructions.d.ts +68 -0
  70. package/dist/src/ai/agentInstructions.js +286 -0
  71. package/dist/src/ai/index.d.ts +8 -0
  72. package/dist/src/ai/index.js +26 -0
  73. package/dist/src/ai/instructionFileLoader.d.ts +44 -0
  74. package/dist/src/ai/instructionFileLoader.js +179 -0
  75. package/dist/src/auth/FlinkAuthPlugin.d.ts +1 -1
  76. package/dist/src/handlers/StreamWriterFactory.d.ts +20 -0
  77. package/dist/src/handlers/StreamWriterFactory.js +83 -0
  78. package/dist/src/index.d.ts +14 -0
  79. package/dist/src/index.js +17 -0
  80. package/dist/src/loadPluginSchemas.d.ts +45 -0
  81. package/dist/src/loadPluginSchemas.js +143 -0
  82. package/dist/src/schema-extraction/ComplexTypeDetection.d.ts +40 -0
  83. package/dist/src/schema-extraction/ComplexTypeDetection.js +75 -0
  84. package/dist/src/schema-extraction/TypeScriptSourceParser.d.ts +321 -0
  85. package/dist/src/schema-extraction/TypeScriptSourceParser.js +925 -0
  86. package/dist/src/schema-extraction/TypeScriptSourceParser.spec.d.ts +1 -0
  87. package/dist/src/schema-extraction/TypeScriptSourceParser.spec.js +233 -0
  88. package/dist/src/schema-extraction/TypeScriptTokenizer.d.ts +57 -0
  89. package/dist/src/schema-extraction/TypeScriptTokenizer.js +177 -0
  90. package/dist/src/schema-extraction/index.d.ts +2 -0
  91. package/dist/src/schema-extraction/index.js +20 -0
  92. package/dist/src/schema-extraction/types.d.ts +31 -0
  93. package/dist/src/schema-extraction/types.js +2 -0
  94. package/dist/src/utils/loadFlinkConfig.d.ts +53 -0
  95. package/dist/src/utils/loadFlinkConfig.js +77 -0
  96. package/dist/src/utils.d.ts +30 -0
  97. package/dist/src/utils.js +52 -0
  98. package/dist/src/workers/SchemaGeneratorWorker.d.ts +1 -0
  99. package/dist/src/workers/SchemaGeneratorWorker.js +49 -0
  100. package/dist/src/workers/WorkerPool.d.ts +60 -0
  101. package/dist/src/workers/WorkerPool.js +306 -0
  102. package/examples/logging-hierarchical-example.ts +125 -0
  103. package/package.json +29 -4
  104. package/readme.md +499 -0
  105. package/spec/AgentDescendantDetection.spec.ts +335 -0
  106. package/spec/AgentDuplicateDetection.spec.ts +112 -0
  107. package/spec/AgentObserver.spec.ts +266 -0
  108. package/spec/AgentRunner.spec.ts +1062 -0
  109. package/spec/AsyncLocalStorageContext.spec.ts +223 -0
  110. package/spec/ConversationHooks.spec.ts +257 -0
  111. package/spec/FlinkAgent.spec.ts +681 -0
  112. package/spec/FlinkApp.htmlResponse.spec.ts +260 -0
  113. package/spec/FlinkApp.onError.invocation.spec.ts +151 -0
  114. package/spec/FlinkApp.onError.spec.ts +1 -2
  115. package/spec/FlinkApp.query.spec.ts +107 -0
  116. package/spec/FlinkApp.routeOrdering.spec.ts +61 -0
  117. package/spec/FlinkApp.undefinedResponse.spec.ts +123 -0
  118. package/spec/FlinkApp.validationMode.spec.ts +155 -0
  119. package/spec/FlinkJob.spec.ts +171 -0
  120. package/spec/FlinkLogFactory.spec.ts +337 -0
  121. package/spec/FlinkRepo.spec.ts +1 -1
  122. package/spec/LeaderElection.spec.ts +174 -0
  123. package/spec/StreamingIntegration.spec.ts +139 -0
  124. package/spec/ToolExecutor.spec.ts +465 -0
  125. package/spec/TypeScriptCompiler.spec.ts +1 -1
  126. package/spec/TypeScriptSourceParser.spec.ts +1215 -0
  127. package/spec/TypeScriptTokenizer.spec.ts +366 -0
  128. package/spec/ai/ContextCompaction.spec.ts +405 -0
  129. package/spec/ai/ConversationAgent.spec.ts +520 -0
  130. package/spec/ai/InMemoryConversationAgent.spec.ts +144 -0
  131. package/spec/ai/agentInstructions.spec.ts +358 -0
  132. package/spec/fixtures/agent-instructions/TestAgent.ts +24 -0
  133. package/spec/fixtures/agent-instructions/simple.md +3 -0
  134. package/spec/fixtures/agent-instructions/template.md +18 -0
  135. package/spec/fixtures/agent-instructions/yaml-format.yaml +9 -0
  136. package/spec/mock-project/dist/.tsbuildinfo +1 -0
  137. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar.js +56 -0
  138. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCar2.js +58 -0
  139. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema.js +52 -0
  140. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema2.js +52 -0
  141. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithArraySchema3.js +52 -0
  142. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema.js +54 -0
  143. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithLiteralSchema2.js +54 -0
  144. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile.js +57 -0
  145. package/spec/mock-project/dist/spec/mock-project/src/handlers/GetCarWithSchemaInFile2.js +57 -0
  146. package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler.js +53 -0
  147. package/spec/mock-project/dist/spec/mock-project/src/handlers/ManuallyAddedHandler2.js +55 -0
  148. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchCar.js +57 -0
  149. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOnboardingSession.js +75 -0
  150. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchOrderWithComplexTypes.js +57 -0
  151. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchProductWithIntersection.js +58 -0
  152. package/spec/mock-project/dist/spec/mock-project/src/handlers/PatchUserWithUnion.js +58 -0
  153. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostCar.js +54 -0
  154. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogin.js +55 -0
  155. package/spec/mock-project/dist/spec/mock-project/src/handlers/PostLogout.js +54 -0
  156. package/spec/mock-project/dist/spec/mock-project/src/handlers/PutCar.js +54 -0
  157. package/spec/mock-project/dist/spec/mock-project/src/index.js +83 -0
  158. package/spec/mock-project/dist/spec/mock-project/src/repos/CarRepo.js +26 -0
  159. package/spec/mock-project/dist/spec/mock-project/src/schemas/Car.js +2 -0
  160. package/spec/mock-project/dist/spec/mock-project/src/schemas/DefaultExportSchema.js +2 -0
  161. package/spec/mock-project/dist/spec/mock-project/src/schemas/FileWithTwoSchemas.js +2 -0
  162. package/spec/mock-project/dist/src/FlinkApp.js +1000 -0
  163. package/spec/mock-project/dist/src/FlinkContext.js +2 -0
  164. package/spec/mock-project/dist/src/FlinkErrors.js +143 -0
  165. package/spec/mock-project/dist/src/FlinkHttpHandler.js +47 -0
  166. package/spec/mock-project/dist/src/FlinkJob.js +2 -0
  167. package/spec/mock-project/dist/src/FlinkLog.js +119 -0
  168. package/spec/mock-project/dist/src/FlinkLogFactory.js +617 -0
  169. package/spec/mock-project/dist/src/FlinkPlugin.js +2 -0
  170. package/spec/mock-project/dist/src/FlinkRepo.js +224 -0
  171. package/spec/mock-project/dist/src/FlinkRequestContext.js +74 -0
  172. package/spec/mock-project/dist/src/FlinkResponse.js +2 -0
  173. package/spec/mock-project/dist/src/ai/AgentExecutor.js +279 -0
  174. package/spec/mock-project/dist/src/ai/AgentRunner.js +632 -0
  175. package/spec/mock-project/dist/src/ai/ConversationAgent.js +402 -0
  176. package/spec/mock-project/dist/src/ai/ConversationFlinkAgent.js +422 -0
  177. package/spec/mock-project/dist/src/ai/FlinkAgent.js +699 -0
  178. package/spec/mock-project/dist/src/ai/FlinkTool.js +2 -0
  179. package/spec/mock-project/dist/src/ai/InMemoryConversationAgent.js +209 -0
  180. package/spec/mock-project/dist/src/ai/LLMAdapter.js +2 -0
  181. package/spec/mock-project/dist/src/ai/SubAgentExecutor.js +223 -0
  182. package/spec/mock-project/dist/src/ai/ToolExecutor.js +412 -0
  183. package/spec/mock-project/dist/src/ai/agentInstructions.js +246 -0
  184. package/spec/mock-project/dist/src/auth/FlinkAuthPlugin.js +2 -0
  185. package/spec/mock-project/dist/src/auth/FlinkAuthUser.js +2 -0
  186. package/spec/mock-project/dist/src/handlers/GetCar.js +26 -52
  187. package/spec/mock-project/dist/src/handlers/GetCar.js.map +1 -0
  188. package/spec/mock-project/dist/src/handlers/GetCar2.js +32 -54
  189. package/spec/mock-project/dist/src/handlers/GetCar2.js.map +1 -0
  190. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js +26 -48
  191. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema.js.map +1 -0
  192. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js +28 -48
  193. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema2.js.map +1 -0
  194. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js +29 -48
  195. package/spec/mock-project/dist/src/handlers/GetCarWithArraySchema3.js.map +1 -0
  196. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js +26 -50
  197. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema.js.map +1 -0
  198. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js +28 -50
  199. package/spec/mock-project/dist/src/handlers/GetCarWithLiteralSchema2.js.map +1 -0
  200. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js +27 -53
  201. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile.js.map +1 -0
  202. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js +29 -53
  203. package/spec/mock-project/dist/src/handlers/GetCarWithSchemaInFile2.js.map +1 -0
  204. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js +16 -49
  205. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler.js.map +1 -0
  206. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js +25 -50
  207. package/spec/mock-project/dist/src/handlers/ManuallyAddedHandler2.js.map +1 -0
  208. package/spec/mock-project/dist/src/handlers/PatchCar.js +27 -53
  209. package/spec/mock-project/dist/src/handlers/PatchCar.js.map +1 -0
  210. package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js +44 -70
  211. package/spec/mock-project/dist/src/handlers/PatchOnboardingSession.js.map +1 -0
  212. package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js +27 -53
  213. package/spec/mock-project/dist/src/handlers/PatchOrderWithComplexTypes.js.map +1 -0
  214. package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js +28 -54
  215. package/spec/mock-project/dist/src/handlers/PatchProductWithIntersection.js.map +1 -0
  216. package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js +28 -54
  217. package/spec/mock-project/dist/src/handlers/PatchUserWithUnion.js.map +1 -0
  218. package/spec/mock-project/dist/src/handlers/PostCar.js +24 -50
  219. package/spec/mock-project/dist/src/handlers/PostCar.js.map +1 -0
  220. package/spec/mock-project/dist/src/handlers/PostLogin.js +25 -51
  221. package/spec/mock-project/dist/src/handlers/PostLogin.js.map +1 -0
  222. package/spec/mock-project/dist/src/handlers/PostLogout.js +24 -50
  223. package/spec/mock-project/dist/src/handlers/PostLogout.js.map +1 -0
  224. package/spec/mock-project/dist/src/handlers/PutCar.js +24 -50
  225. package/spec/mock-project/dist/src/handlers/PutCar.js.map +1 -0
  226. package/spec/mock-project/dist/src/handlers/StreamWriterFactory.js +83 -0
  227. package/spec/mock-project/dist/src/index.js +52 -76
  228. package/spec/mock-project/dist/src/index.js.map +1 -0
  229. package/spec/mock-project/dist/src/mock-data-generator.js +9 -0
  230. package/spec/mock-project/dist/src/repos/CarRepo.js +12 -24
  231. package/spec/mock-project/dist/src/repos/CarRepo.js.map +1 -0
  232. package/spec/mock-project/dist/src/schemas/Car.js +3 -1
  233. package/spec/mock-project/dist/src/schemas/Car.js.map +1 -0
  234. package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js +3 -1
  235. package/spec/mock-project/dist/src/schemas/DefaultExportSchema.js.map +1 -0
  236. package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js +3 -1
  237. package/spec/mock-project/dist/src/schemas/FileWithTwoSchemas.js.map +1 -0
  238. package/spec/mock-project/dist/src/utils.js +290 -0
  239. package/spec/mock-project/tsconfig.json +6 -1
  240. package/spec/schema-generation-nested-objects.spec.ts +97 -0
  241. package/spec/testHelpers.ts +49 -0
  242. package/spec/utils.caseConversion.spec.ts +78 -0
  243. package/spec/utils.spec.ts +13 -13
  244. package/src/DependencyTracker.ts +166 -0
  245. package/src/FlinkApp.ts +919 -155
  246. package/src/FlinkContext.ts +43 -0
  247. package/src/FlinkErrors.ts +32 -12
  248. package/src/FlinkHttpHandler.ts +246 -28
  249. package/src/FlinkJob.ts +11 -0
  250. package/src/FlinkLog.ts +119 -12
  251. package/src/FlinkLogFactory.ts +699 -0
  252. package/src/FlinkRepo.ts +10 -3
  253. package/src/FlinkRequestContext.ts +95 -0
  254. package/src/FlinkResponse.ts +6 -0
  255. package/src/FlinkService.ts +49 -0
  256. package/src/LeaderElection.ts +203 -0
  257. package/src/SchemaCache.ts +232 -0
  258. package/src/TypeScriptCompiler.ts +1347 -610
  259. package/src/TypeScriptUtils.ts +5 -0
  260. package/src/ai/AgentRunner.ts +646 -0
  261. package/src/ai/ConversationAgent.ts +413 -0
  262. package/src/ai/FlinkAgent.ts +1069 -0
  263. package/src/ai/FlinkTool.ts +165 -0
  264. package/src/ai/InMemoryConversationAgent.ts +149 -0
  265. package/src/ai/LLMAdapter.ts +126 -0
  266. package/src/ai/ToolExecutor.ts +485 -0
  267. package/src/ai/agentInstructions.ts +245 -0
  268. package/src/ai/index.ts +8 -0
  269. package/src/ai/instructionFileLoader.ts +156 -0
  270. package/src/auth/FlinkAuthPlugin.ts +2 -1
  271. package/src/handlers/StreamWriterFactory.ts +84 -0
  272. package/src/index.ts +14 -0
  273. package/src/loadPluginSchemas.ts +141 -0
  274. package/src/schema-extraction/TypeScriptSourceParser.ts +1058 -0
  275. package/src/schema-extraction/TypeScriptTokenizer.ts +205 -0
  276. package/src/schema-extraction/index.ts +2 -0
  277. package/src/schema-extraction/types.ts +34 -0
  278. package/src/utils/loadFlinkConfig.ts +89 -0
  279. package/src/utils.ts +52 -0
  280. package/tsconfig.json +6 -1
@@ -0,0 +1,497 @@
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.ToolExecutor = void 0;
43
+ var ajv_1 = __importDefault(require("ajv"));
44
+ var ajv_formats_1 = __importDefault(require("ajv-formats"));
45
+ var FlinkErrors_1 = require("../FlinkErrors");
46
+ var FlinkLogFactory_1 = require("../FlinkLogFactory");
47
+ var FlinkRequestContext_1 = require("../FlinkRequestContext");
48
+ var toolLog = FlinkLogFactory_1.FlinkLogFactory.createLogger("flink.ai.tool");
49
+ var ToolExecutor = /** @class */ (function () {
50
+ function ToolExecutor(toolProps, toolFn, ctx, autoSchemas, allSchemas) {
51
+ this.toolProps = toolProps;
52
+ this.toolFn = toolFn;
53
+ this.ctx = ctx;
54
+ this.autoSchemas = autoSchemas;
55
+ this.allSchemas = allSchemas;
56
+ this.ajv = new ajv_1.default({ allErrors: true });
57
+ (0, ajv_formats_1.default)(this.ajv);
58
+ // Pre-populate AJV with all schemas so $ref references resolve across schema boundaries
59
+ if (allSchemas) {
60
+ for (var _i = 0, _a = Object.values(allSchemas); _i < _a.length; _i++) {
61
+ var schema = _a[_i];
62
+ if (schema && schema.$id) {
63
+ try {
64
+ this.ajv.addSchema(schema);
65
+ }
66
+ catch (_b) {
67
+ // Ignore duplicate schema errors (schema may already be added)
68
+ }
69
+ }
70
+ }
71
+ }
72
+ // Pre-compile validators once at construction time (not per invocation)
73
+ if (toolProps.inputJsonSchema) {
74
+ this.compiledInputValidator = this.ajv.compile(toolProps.inputJsonSchema);
75
+ }
76
+ else if (autoSchemas === null || autoSchemas === void 0 ? void 0 : autoSchemas.inputSchema) {
77
+ this.compiledInputValidator = this.ajv.compile(autoSchemas.inputSchema);
78
+ }
79
+ if (toolProps.outputJsonSchema) {
80
+ this.compiledOutputValidator = this.ajv.compile(toolProps.outputJsonSchema);
81
+ }
82
+ else if (autoSchemas === null || autoSchemas === void 0 ? void 0 : autoSchemas.outputSchema) {
83
+ this.compiledOutputValidator = this.ajv.compile(autoSchemas.outputSchema);
84
+ }
85
+ // Log when using auto-schemas
86
+ if ((autoSchemas === null || autoSchemas === void 0 ? void 0 : autoSchemas.inputSchema) && !toolProps.inputSchema && !toolProps.inputJsonSchema) {
87
+ toolLog.debug("Tool ".concat(toolProps.id, ": Using auto-generated schemas from type parameters"));
88
+ }
89
+ // Log when no schema is provided (valid for void/any input types)
90
+ var hasInputSchema = toolProps.inputSchema || toolProps.inputJsonSchema || (autoSchemas === null || autoSchemas === void 0 ? void 0 : autoSchemas.inputSchema);
91
+ if (!hasInputSchema) {
92
+ toolLog.debug("Tool ".concat(toolProps.id, ": No input schema provided (input type is void or any)"));
93
+ }
94
+ // Warn if both manual and auto provided (manual takes precedence)
95
+ if ((toolProps.inputSchema || toolProps.inputJsonSchema) && (autoSchemas === null || autoSchemas === void 0 ? void 0 : autoSchemas.inputSchema)) {
96
+ toolLog.debug("Tool ".concat(toolProps.id, ": Manual schemas take precedence over auto-generated schemas"));
97
+ }
98
+ // Log warning if both manual Zod and JSON schemas are provided
99
+ if (toolProps.inputSchema && toolProps.inputJsonSchema) {
100
+ toolLog.warn("Tool ".concat(toolProps.id, ": Both 'inputSchema' (Zod) and 'inputJsonSchema' are provided. ") + "Using 'inputSchema' for validation.");
101
+ }
102
+ if (toolProps.outputSchema && toolProps.outputJsonSchema) {
103
+ toolLog.warn("Tool ".concat(toolProps.id, ": Both 'outputSchema' (Zod) and 'outputJsonSchema' are provided. ") + "Using 'outputSchema' for validation.");
104
+ }
105
+ }
106
+ /**
107
+ * Execute the tool with input
108
+ * @param input - Tool input data
109
+ * @param overrides - Optional overrides for user/permissions/conversationContext (for testing)
110
+ */
111
+ ToolExecutor.prototype.execute = function (input, overrides) {
112
+ return __awaiter(this, void 0, void 0, function () {
113
+ var user, userPermissions, conversationContext, hasPermission, validatedInput, valid, errorDetails, errorDetails, result, err_1, validatedData, valid, errorDetails;
114
+ var _a, _b, _c;
115
+ return __generator(this, function (_d) {
116
+ switch (_d.label) {
117
+ case 0:
118
+ user = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.user) !== null && _a !== void 0 ? _a : (0, FlinkRequestContext_1.getRequestUser)();
119
+ userPermissions = (_b = overrides === null || overrides === void 0 ? void 0 : overrides.permissions) !== null && _b !== void 0 ? _b : (_c = (0, FlinkRequestContext_1.getRequestContext)()) === null || _c === void 0 ? void 0 : _c.userPermissions;
120
+ conversationContext = overrides === null || overrides === void 0 ? void 0 : overrides.conversationContext;
121
+ if (!this.toolProps.permissions) return [3 /*break*/, 2];
122
+ return [4 /*yield*/, this.checkPermissionsInternal(input, user, userPermissions)];
123
+ case 1:
124
+ hasPermission = _d.sent();
125
+ if (!hasPermission) {
126
+ toolLog.debug("Tool invocator is missing required permission(s)", this.toolProps.permissions, "user has", userPermissions);
127
+ throw (0, FlinkErrors_1.forbidden)("Permission denied for tool ".concat(this.toolProps.id), "PERMISSION_DENIED");
128
+ }
129
+ _d.label = 2;
130
+ case 2:
131
+ try {
132
+ if (this.toolProps.inputSchema) {
133
+ // Priority 1: Use Zod validation
134
+ validatedInput = this.toolProps.inputSchema.parse(input);
135
+ }
136
+ else if (this.compiledInputValidator) {
137
+ valid = this.compiledInputValidator(input);
138
+ if (!valid) {
139
+ errorDetails = this.formatAjvErrors(this.compiledInputValidator.errors || [], input);
140
+ toolLog.warn("Tool ".concat(this.toolProps.id, " input validation failed:"), errorDetails);
141
+ return [2 /*return*/, {
142
+ success: false,
143
+ error: "Invalid input for tool '".concat(this.toolProps.id, "': ").concat(errorDetails),
144
+ code: "VALIDATION_ERROR",
145
+ }];
146
+ }
147
+ validatedInput = input;
148
+ }
149
+ else {
150
+ // No schema available - skip validation
151
+ validatedInput = input;
152
+ }
153
+ }
154
+ catch (err) {
155
+ toolLog.warn("Tool ".concat(this.toolProps.id, " input validation failed:"), err.message);
156
+ errorDetails = this.formatZodError(err, input);
157
+ return [2 /*return*/, {
158
+ success: false,
159
+ error: "Invalid input for tool '".concat(this.toolProps.id, "': ").concat(errorDetails),
160
+ code: "VALIDATION_ERROR",
161
+ }];
162
+ }
163
+ // 3. Execute tool
164
+ toolLog.debug("Executing tool ".concat(this.toolProps.id));
165
+ _d.label = 3;
166
+ case 3:
167
+ _d.trys.push([3, 5, , 6]);
168
+ toolLog.trace(this.toolFn.name + " input:", validatedInput);
169
+ return [4 /*yield*/, this.toolFn({
170
+ input: validatedInput,
171
+ ctx: this.ctx,
172
+ user: user,
173
+ permissions: userPermissions,
174
+ conversationCtx: conversationContext,
175
+ })];
176
+ case 4:
177
+ result = _d.sent();
178
+ return [3 /*break*/, 6];
179
+ case 5:
180
+ err_1 = _d.sent();
181
+ toolLog.error("Tool ".concat(this.toolProps.id, " threw error:"), err_1.message);
182
+ return [2 /*return*/, {
183
+ success: false,
184
+ error: "Tool execution failed: ".concat(err_1.message),
185
+ code: "EXECUTION_ERROR",
186
+ }];
187
+ case 6:
188
+ // 4. Handle error results
189
+ if (!result.success) {
190
+ toolLog.warn("Tool ".concat(this.toolProps.id, " returned error:"), result.error);
191
+ return [2 /*return*/, result]; // Return error result as-is
192
+ }
193
+ // 5. Output validation (priority: Zod > JSON Schema > Auto-generated)
194
+ if (this.toolProps.outputSchema) {
195
+ // Priority 1: Use Zod validation
196
+ try {
197
+ validatedData = this.toolProps.outputSchema.parse(result.data);
198
+ return [2 /*return*/, { success: true, data: validatedData }];
199
+ }
200
+ catch (err) {
201
+ toolLog.error("Tool ".concat(this.toolProps.id, " output validation failed:"), err.message);
202
+ return [2 /*return*/, {
203
+ success: false,
204
+ error: "Invalid output from tool ".concat(this.toolProps.id, ": ").concat(err.message),
205
+ code: "OUTPUT_VALIDATION_ERROR",
206
+ }];
207
+ }
208
+ }
209
+ else if (this.compiledOutputValidator) {
210
+ // Priority 2 & 3: Use pre-compiled JSON Schema validator (manual or auto-generated)
211
+ try {
212
+ valid = this.compiledOutputValidator(result.data);
213
+ if (!valid) {
214
+ errorDetails = this.formatAjvErrors(this.compiledOutputValidator.errors || []);
215
+ toolLog.error("Tool ".concat(this.toolProps.id, " output validation failed:"), errorDetails);
216
+ return [2 /*return*/, {
217
+ success: false,
218
+ error: "Invalid output from tool ".concat(this.toolProps.id, ": ").concat(errorDetails),
219
+ code: "OUTPUT_VALIDATION_ERROR",
220
+ }];
221
+ }
222
+ return [2 /*return*/, { success: true, data: result.data }];
223
+ }
224
+ catch (err) {
225
+ toolLog.error("Tool ".concat(this.toolProps.id, " output validation failed:"), err.message);
226
+ return [2 /*return*/, {
227
+ success: false,
228
+ error: "Invalid output from tool ".concat(this.toolProps.id, ": ").concat(err.message),
229
+ code: "OUTPUT_VALIDATION_ERROR",
230
+ }];
231
+ }
232
+ }
233
+ // No output validation - return result as-is
234
+ return [2 /*return*/, result];
235
+ }
236
+ });
237
+ });
238
+ };
239
+ ToolExecutor.prototype.getToolSchema = function () {
240
+ // Priority order: inputJsonSchema > inputSchema (Zod 4.x) > autoSchemas
241
+ var _a, _b;
242
+ // Priority 1: Manual JSON schema
243
+ if (this.toolProps.inputJsonSchema) {
244
+ return {
245
+ name: this.toolProps.id,
246
+ description: this.toolProps.description,
247
+ inputSchema: this.toolProps.inputJsonSchema,
248
+ };
249
+ }
250
+ // Priority 2: Zod schema (convert to JSON Schema using Zod 4.x)
251
+ if (this.toolProps.inputSchema) {
252
+ var z = require("zod");
253
+ if (!z.toJSONSchema) {
254
+ throw new Error("Tool ".concat(this.toolProps.id, ": Zod 4.x is required for automatic schema generation. ") +
255
+ "Either upgrade to Zod 4.x or provide 'inputJsonSchema' in your tool definition, " +
256
+ "or use TypeScript type parameters for auto-generation.");
257
+ }
258
+ return {
259
+ name: this.toolProps.id,
260
+ description: this.toolProps.description,
261
+ inputSchema: z.toJSONSchema(this.toolProps.inputSchema),
262
+ };
263
+ }
264
+ // Priority 3: Auto-generated schema from type parameters
265
+ if ((_a = this.autoSchemas) === null || _a === void 0 ? void 0 : _a.inputSchema) {
266
+ return {
267
+ name: this.toolProps.id,
268
+ description: this.toolProps.description,
269
+ inputSchema: this.resolveSchemaRefs(this.autoSchemas.inputSchema),
270
+ };
271
+ }
272
+ // No schema provided - return schema based on type hint
273
+ var typeHint = (_b = this.autoSchemas) === null || _b === void 0 ? void 0 : _b.inputTypeHint;
274
+ if (typeHint === 'void') {
275
+ // void: Tool takes no input - reject any properties
276
+ return {
277
+ name: this.toolProps.id,
278
+ description: this.toolProps.description,
279
+ inputSchema: {
280
+ type: "object",
281
+ properties: {},
282
+ additionalProperties: false,
283
+ },
284
+ };
285
+ }
286
+ else if (typeHint === 'any') {
287
+ // any: Tool accepts any input - allow any properties
288
+ return {
289
+ name: this.toolProps.id,
290
+ description: this.toolProps.description,
291
+ inputSchema: {
292
+ type: "object",
293
+ additionalProperties: true,
294
+ },
295
+ };
296
+ }
297
+ else {
298
+ // No type hint - default to void behavior (no input expected)
299
+ return {
300
+ name: this.toolProps.id,
301
+ description: this.toolProps.description,
302
+ inputSchema: {
303
+ type: "object",
304
+ properties: {},
305
+ additionalProperties: false,
306
+ },
307
+ };
308
+ }
309
+ };
310
+ /**
311
+ * Resolve cross-schema $ref values into $defs so the schema is self-contained.
312
+ *
313
+ * Flink's schema manifest stores schemas as separate documents with IDs like
314
+ * "Canvas.ElementInput". These are valid for AJV (which uses a schema registry),
315
+ * but LLM providers like OpenAI require a single self-contained schema where all
316
+ * $ref values point to #/$defs/... entries at the top level.
317
+ */
318
+ ToolExecutor.prototype.resolveSchemaRefs = function (schema) {
319
+ var _this = this;
320
+ if (!this.allSchemas)
321
+ return schema;
322
+ var defs = {};
323
+ var collectRefs = function (node, visited) {
324
+ if (!node || typeof node !== "object")
325
+ return;
326
+ if (node.$ref && typeof node.$ref === "string" && !node.$ref.startsWith("#")) {
327
+ var refId = node.$ref;
328
+ if (!visited.has(refId) && _this.allSchemas[refId]) {
329
+ visited.add(refId);
330
+ // Clone and strip top-level JSON Schema meta fields not valid inside $defs
331
+ var def = JSON.parse(JSON.stringify(_this.allSchemas[refId]));
332
+ delete def.$id;
333
+ delete def.$schema;
334
+ defs[refId] = def;
335
+ // Recurse into the referenced schema to collect its deps
336
+ collectRefs(def, visited);
337
+ }
338
+ }
339
+ for (var _i = 0, _a = Object.values(node); _i < _a.length; _i++) {
340
+ var value = _a[_i];
341
+ collectRefs(value, visited);
342
+ }
343
+ };
344
+ var visited = new Set();
345
+ collectRefs(schema, visited);
346
+ if (Object.keys(defs).length === 0)
347
+ return schema;
348
+ // Deep clone and rewrite all non-standard $ref values to #/$defs/<id>
349
+ var resolved = JSON.parse(JSON.stringify(schema));
350
+ delete resolved.$id;
351
+ delete resolved.$schema;
352
+ var rewriteRefs = function (node) {
353
+ if (!node || typeof node !== "object")
354
+ return;
355
+ if (node.$ref && typeof node.$ref === "string" && !node.$ref.startsWith("#")) {
356
+ node.$ref = "#/$defs/".concat(node.$ref);
357
+ }
358
+ for (var _i = 0, _a = Object.values(node); _i < _a.length; _i++) {
359
+ var value = _a[_i];
360
+ rewriteRefs(value);
361
+ }
362
+ };
363
+ rewriteRefs(resolved);
364
+ // Also rewrite refs inside the collected defs
365
+ for (var _i = 0, _a = Object.values(defs); _i < _a.length; _i++) {
366
+ var def = _a[_i];
367
+ rewriteRefs(def);
368
+ }
369
+ resolved.$defs = defs;
370
+ return resolved;
371
+ };
372
+ /**
373
+ * Get tool result for AI consumption
374
+ * Formats ToolResult into string for AI context
375
+ */
376
+ ToolExecutor.prototype.formatResultForAI = function (result) {
377
+ if (result.success) {
378
+ return JSON.stringify(result.data);
379
+ }
380
+ else {
381
+ return "Error: ".concat(result.error).concat(result.code ? " (".concat(result.code, ")") : "");
382
+ }
383
+ };
384
+ /**
385
+ * Check if user has permission to use this tool
386
+ * Used by AgentRunner to filter tools before showing to LLM
387
+ *
388
+ * @param user - User object
389
+ * @param input - Tool input (for function-based permissions)
390
+ * @param userPermissions - Optional resolved permissions from auth plugin (preferred)
391
+ * @param conversationContext - Optional conversation context
392
+ */
393
+ ToolExecutor.prototype.checkPermissions = function (user, input, userPermissions, conversationContext) {
394
+ return __awaiter(this, void 0, void 0, function () {
395
+ var perms, effectivePerms, requiredPerms;
396
+ return __generator(this, function (_a) {
397
+ switch (_a.label) {
398
+ case 0:
399
+ perms = this.toolProps.permissions;
400
+ if (!perms)
401
+ return [2 /*return*/, true];
402
+ if (!(typeof perms === "function")) return [3 /*break*/, 2];
403
+ return [4 /*yield*/, perms(input !== null && input !== void 0 ? input : {}, user)];
404
+ case 1: return [2 /*return*/, _a.sent()];
405
+ case 2:
406
+ effectivePerms = userPermissions || (user === null || user === void 0 ? void 0 : user.permissions) || [];
407
+ // If no user and no explicit permissions, deny access
408
+ if (!user && !userPermissions)
409
+ return [2 /*return*/, false];
410
+ requiredPerms = Array.isArray(perms) ? perms : [perms];
411
+ return [2 /*return*/, requiredPerms.every(function (p) { return effectivePerms.includes(p); })];
412
+ }
413
+ });
414
+ });
415
+ };
416
+ ToolExecutor.prototype.checkPermissionsInternal = function (input, user, userPermissions, conversationContext) {
417
+ return __awaiter(this, void 0, void 0, function () {
418
+ return __generator(this, function (_a) {
419
+ return [2 /*return*/, this.checkPermissions(user, input, userPermissions, conversationContext)];
420
+ });
421
+ });
422
+ };
423
+ /**
424
+ * Format Zod validation errors into LLM-friendly error messages
425
+ * Provides specific guidance on what's missing or incorrect
426
+ */
427
+ ToolExecutor.prototype.formatZodError = function (err, receivedInput) {
428
+ // Check if it's a Zod error with issues array
429
+ if (err.issues && Array.isArray(err.issues)) {
430
+ var issues = err.issues.map(function (issue) {
431
+ var path = issue.path.join(".");
432
+ var field = path || "input";
433
+ if (issue.code === "invalid_type") {
434
+ if (issue.received === "undefined") {
435
+ return "Missing required field '".concat(field, "' (expected ").concat(issue.expected, ")");
436
+ }
437
+ return "Field '".concat(field, "' has wrong type: expected ").concat(issue.expected, ", got ").concat(issue.received);
438
+ }
439
+ if (issue.code === "too_small") {
440
+ if (issue.type === "string") {
441
+ return "Field '".concat(field, "' is too short (minimum ").concat(issue.minimum, " characters)");
442
+ }
443
+ return "Field '".concat(field, "' is too small (minimum ").concat(issue.minimum, ")");
444
+ }
445
+ if (issue.code === "too_big") {
446
+ if (issue.type === "string") {
447
+ return "Field '".concat(field, "' is too long (maximum ").concat(issue.maximum, " characters)");
448
+ }
449
+ return "Field '".concat(field, "' is too large (maximum ").concat(issue.maximum, ")");
450
+ }
451
+ // Generic fallback
452
+ return "".concat(field, ": ").concat(issue.message);
453
+ });
454
+ if (receivedInput) {
455
+ var inputInfo = Object.keys(receivedInput || {}).length === 0 ? "You provided an empty object {}." : "You provided: ".concat(JSON.stringify(receivedInput));
456
+ return "".concat(issues.join("; "), ". ").concat(inputInfo);
457
+ }
458
+ return issues.join("; ");
459
+ }
460
+ // Fallback for non-Zod errors
461
+ return err.message || "Unknown validation error";
462
+ };
463
+ /**
464
+ * Format AJV validation errors into LLM-friendly error messages
465
+ */
466
+ ToolExecutor.prototype.formatAjvErrors = function (errors, receivedInput) {
467
+ var issues = errors.map(function (error) {
468
+ var field = error.instancePath ? error.instancePath.substring(1).replace(/\//g, ".") : "input";
469
+ if (error.keyword === "required") {
470
+ return "Missing required field '".concat(error.params.missingProperty, "'");
471
+ }
472
+ if (error.keyword === "type") {
473
+ return "Field '".concat(field, "' has wrong type: expected ").concat(error.params.type);
474
+ }
475
+ if (error.keyword === "minLength") {
476
+ return "Field '".concat(field, "' is too short (minimum ").concat(error.params.limit, " characters)");
477
+ }
478
+ if (error.keyword === "maxLength") {
479
+ return "Field '".concat(field, "' is too long (maximum ").concat(error.params.limit, " characters)");
480
+ }
481
+ if (error.keyword === "minimum") {
482
+ return "Field '".concat(field, "' is too small (minimum ").concat(error.params.limit, ")");
483
+ }
484
+ if (error.keyword === "maximum") {
485
+ return "Field '".concat(field, "' is too large (maximum ").concat(error.params.limit, ")");
486
+ }
487
+ return "".concat(field, ": ").concat(error.message);
488
+ });
489
+ if (receivedInput) {
490
+ var inputInfo = Object.keys(receivedInput || {}).length === 0 ? "You provided an empty object {}." : "You provided: ".concat(JSON.stringify(receivedInput));
491
+ return "".concat(issues.join("; "), ". ").concat(inputInfo);
492
+ }
493
+ return issues.join("; ");
494
+ };
495
+ return ToolExecutor;
496
+ }());
497
+ exports.ToolExecutor = ToolExecutor;
@@ -0,0 +1,68 @@
1
+ import { FlinkContext } from "../FlinkContext";
2
+ import { InstructionsCallback, AgentExecuteContext } from "./FlinkAgent";
3
+ /**
4
+ * Load agent instructions from external files with template variable support
5
+ *
6
+ * Supports multiple file types: .md, .yaml, .txt, etc. (loaded as plain text)
7
+ *
8
+ * ## Path Resolution
9
+ *
10
+ * - `./` or `../` prefix: Agent-relative path (based on caller's file location)
11
+ * - Otherwise: Project root-relative path
12
+ *
13
+ * ## Template Variables
14
+ *
15
+ * Uses Handlebars templating with automatic context helpers:
16
+ * - `ctx`: Full FlinkContext
17
+ * - `agentContext`: AgentExecuteContext
18
+ * - `user`: Shortcut to agentContext.user
19
+ * - Custom variables from static object or callback
20
+ *
21
+ * ## Caching
22
+ *
23
+ * Files are cached in-memory and reloaded only when modification time changes
24
+ *
25
+ * @example Agent-relative path with static variables
26
+ * ```typescript
27
+ * export default class CarAgent extends FlinkAgent<AppCtx> {
28
+ * id = "car-agent";
29
+ * instructions = agentInstructions("./instructions/car-agent.md");
30
+ * tools = [SearchCarsTool];
31
+ * }
32
+ * ```
33
+ *
34
+ * @example Dynamic variables with callback
35
+ * ```typescript
36
+ * export default class SupportAgent extends FlinkAgent<AppCtx> {
37
+ * id = "support-agent";
38
+ * instructions = agentInstructions(
39
+ * "./instructions/support-agent.md",
40
+ * (ctx, agentContext) => ({
41
+ * isBusinessHours: new Date().getHours() >= 9 && new Date().getHours() < 17,
42
+ * customerTier: agentContext.user?.tier || "standard",
43
+ * })
44
+ * );
45
+ * tools = [CreateTicketTool];
46
+ * }
47
+ * ```
48
+ *
49
+ * @example Template file (instructions/support-agent.md)
50
+ * ```markdown
51
+ * You are a customer support agent.
52
+ *
53
+ * Customer: {{user.name}} ({{customerTier}})
54
+ * {{#if user.isPremium}}
55
+ * ⭐ VIP CUSTOMER - Provide white-glove service!
56
+ * {{/if}}
57
+ *
58
+ * {{#unless isBusinessHours}}
59
+ * NOTE: Outside business hours. Suggest emergency contact.
60
+ * {{/unless}}
61
+ * ```
62
+ *
63
+ * @param filePath - Path to instructions file (./ for agent-relative, otherwise project root)
64
+ * @param variables - Static object or callback returning template variables
65
+ * @returns InstructionsCallback compatible with FlinkAgent.instructions property
66
+ */
67
+ export declare function agentInstructions<Ctx extends FlinkContext = FlinkContext>(filePath: string, variables?: Record<string, any> | ((ctx: Ctx, agentContext: AgentExecuteContext) => Record<string, any> | Promise<Record<string, any>>)): InstructionsCallback<Ctx>;
68
+ export type { InstructionsCallback, AgentExecuteContext, InstructionsReturn } from "./FlinkAgent";