@prostgles/prostgles 2.3.6-dev.1786565331 → 2.3.6-dev.1786613371

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 (99) hide show
  1. package/dist/common/DBGeneratedSchema.d.ts +5 -9
  2. package/dist/common/DBGeneratedSchema.d.ts.map +1 -1
  3. package/dist/common/llmUtils.d.ts.map +1 -1
  4. package/dist/server/package.json +3 -2
  5. package/dist/server/src/BackupManager/BackupManager.d.ts +0 -1
  6. package/dist/server/src/BackupManager/BackupManager.d.ts.map +1 -1
  7. package/dist/server/src/ConnectionManager/ConnectionManager.d.ts +1 -2
  8. package/dist/server/src/ConnectionManager/ConnectionManager.d.ts.map +1 -1
  9. package/dist/server/src/ConnectionManager/ConnectionManager.js +9 -5
  10. package/dist/server/src/ConnectionManager/ConnectionManager.js.map +1 -1
  11. package/dist/server/src/ConnectionManager/connectionManagerUtils.d.ts +0 -4
  12. package/dist/server/src/ConnectionManager/connectionManagerUtils.d.ts.map +1 -1
  13. package/dist/server/src/ConnectionManager/connectionManagerUtils.js +1 -8
  14. package/dist/server/src/ConnectionManager/connectionManagerUtils.js.map +1 -1
  15. package/dist/server/src/ConnectionManager/getHotReloadConfigs.d.ts.map +1 -1
  16. package/dist/server/src/ConnectionManager/initConnectionManager.js +1 -1
  17. package/dist/server/src/ConnectionManager/initConnectionManager.js.map +1 -1
  18. package/dist/server/src/ConnectionManager/startConnection.d.ts.map +1 -1
  19. package/dist/server/src/ConnectionManager/startConnection.js +1 -5
  20. package/dist/server/src/ConnectionManager/startConnection.js.map +1 -1
  21. package/dist/server/src/McpHub/DockerSandbox/getDockerRunArgs.d.ts.map +1 -1
  22. package/dist/server/src/McpHub/DockerSandbox/getDockerRunArgs.js +4 -2
  23. package/dist/server/src/McpHub/DockerSandbox/getDockerRunArgs.js.map +1 -1
  24. package/dist/server/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/definitionValidation/validateAgenticWorkflowDefinitions.d.ts.map +1 -1
  25. package/dist/server/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/proxyHandlers/createWorkflowExecutionHandlers.d.ts.map +1 -1
  26. package/dist/server/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/proxyHandlers/getAgentConfigWithDefaults.d.ts.map +1 -1
  27. package/dist/server/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/proxyHandlers/setupOrchestrationToolPermissions.d.ts.map +1 -1
  28. package/dist/server/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/WebDev/tools/getWebDevChatAndConnection.d.ts +0 -1
  29. package/dist/server/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/WebDev/tools/getWebDevChatAndConnection.d.ts.map +1 -1
  30. package/dist/server/src/authConfig/sessionUtils.d.ts.map +1 -1
  31. package/dist/server/src/authConfig/subscribeToAuthSetupChanges.d.ts.map +1 -1
  32. package/dist/server/src/cli/cli.js +2 -1
  33. package/dist/server/src/cli/cli.js.map +1 -1
  34. package/dist/server/src/cli/cliUtils.d.ts +1 -0
  35. package/dist/server/src/cli/cliUtils.d.ts.map +1 -1
  36. package/dist/server/src/cli/cliUtils.js +5 -0
  37. package/dist/server/src/cli/cliUtils.js.map +1 -1
  38. package/dist/server/src/connectionUtils/testDBConnection.d.ts +1 -1
  39. package/dist/server/src/connectionUtils/testDBConnection.d.ts.map +1 -1
  40. package/dist/server/src/connectionUtils/testDBConnection.js +12 -9
  41. package/dist/server/src/connectionUtils/testDBConnection.js.map +1 -1
  42. package/dist/server/src/init/initUsers.d.ts.map +1 -1
  43. package/dist/server/src/init/saveTypescriptFilesForProduction.d.ts.map +1 -1
  44. package/dist/server/src/init/saveTypescriptFilesForProduction.js +3 -1
  45. package/dist/server/src/init/saveTypescriptFilesForProduction.js.map +1 -1
  46. package/dist/server/src/init/startProstgles.d.ts.map +1 -1
  47. package/dist/server/src/init/startProstgles.js +5 -2
  48. package/dist/server/src/init/startProstgles.js.map +1 -1
  49. package/dist/server/src/publish/getPublishLLM.d.ts.map +1 -1
  50. package/dist/server/src/publish/getPublishLlmChats.d.ts.map +1 -1
  51. package/dist/server/src/serverFunctions/adminServerFunctions/getAdminServerFunctions.d.ts +0 -10
  52. package/dist/server/src/serverFunctions/adminServerFunctions/getAdminServerFunctions.d.ts.map +1 -1
  53. package/dist/server/src/serverFunctions/adminServerFunctions/getAdminServerFunctions.js +0 -1
  54. package/dist/server/src/serverFunctions/adminServerFunctions/getAdminServerFunctions.js.map +1 -1
  55. package/dist/server/src/serverFunctions/adminServerFunctions/getAgenticWorkflowFunctions.d.ts.map +1 -1
  56. package/dist/server/src/serverFunctions/adminServerFunctions/getBackupServerFunctions.d.ts.map +1 -1
  57. package/dist/server/src/serverFunctions/adminServerFunctions/getDefineAdminFunction.d.ts.map +1 -1
  58. package/dist/server/src/serverFunctions/adminServerFunctions/getMcpServerFunctions.d.ts.map +1 -1
  59. package/dist/server/src/serverFunctions/adminServerFunctions/getWebAppServerFunctions.d.ts.map +1 -1
  60. package/dist/server/src/serverFunctions/adminServerFunctions/webApp/getTemplatedWebAppConnection.d.ts +0 -1
  61. package/dist/server/src/serverFunctions/adminServerFunctions/webApp/getTemplatedWebAppConnection.d.ts.map +1 -1
  62. package/dist/server/src/serverFunctions/applySampleSchema.d.ts +0 -1
  63. package/dist/server/src/serverFunctions/applySampleSchema.d.ts.map +1 -1
  64. package/dist/server/src/serverFunctions/askLLM/askLLM.d.ts.map +1 -1
  65. package/dist/server/src/serverFunctions/askLLM/getPastMessages.d.ts.map +1 -1
  66. package/dist/server/src/serverFunctions/askLLM/getValidatedAskLLMChatOptions.d.ts.map +1 -1
  67. package/dist/server/src/serverFunctions/askLLM/handleToolUseResultConfirmation.d.ts.map +1 -1
  68. package/dist/server/src/serverFunctions/askLLM/prostglesLLMTools/getMCPServerTools.d.ts.map +1 -1
  69. package/dist/server/src/serverFunctions/askLLM/prostglesLLMTools/getMcpToolsWithDynamicDescription.d.ts.map +1 -1
  70. package/dist/server/src/serverFunctions/deleteConnection.d.ts +0 -1
  71. package/dist/server/src/serverFunctions/deleteConnection.d.ts.map +1 -1
  72. package/dist/server/src/serverFunctions/getConnectionAndDatabaseConfig.d.ts +0 -1
  73. package/dist/server/src/serverFunctions/getConnectionAndDatabaseConfig.d.ts.map +1 -1
  74. package/dist/server/src/serverFunctions/getServerFunctions.d.ts +0 -10
  75. package/dist/server/src/serverFunctions/getServerFunctions.d.ts.map +1 -1
  76. package/dist/server/src/serverFunctions/getServerFunctionsContext.d.ts.map +1 -1
  77. package/dist/server/src/serverFunctions/userServerFunctions/getLLMAccessParams.d.ts.map +1 -1
  78. package/dist/server/src/serverFunctions/userServerFunctions/getUserServerFunctions.d.ts.map +1 -1
  79. package/dist/server/src/tableConfig/tableConfigConnections.d.ts.map +1 -1
  80. package/dist/server/src/tableConfig/tableConfigConnections.js +0 -6
  81. package/dist/server/src/tableConfig/tableConfigConnections.js.map +1 -1
  82. package/dist/server/src/upsertConnection.d.ts +0 -1
  83. package/dist/server/src/upsertConnection.d.ts.map +1 -1
  84. package/package.json +3 -2
  85. package/sample_schemas/crypto/tsconfig.json +4 -0
  86. package/sample_schemas/food_delivery/tsconfig.json +1 -1
  87. package/sample_schemas/property_management/tsconfig.json +1 -1
  88. package/sample_schemas/weather/tsconfig.json +1 -1
  89. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/addInstrumentationToTsLogic.ts +350 -0
  90. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/callWorkflowProxy.ts +99 -0
  91. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/defineAgenticWorkflow.spec.ts +110 -0
  92. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/defineAgenticWorkflow.ts +576 -0
  93. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/defineAgenticWorkflowHandlers.ts +127 -0
  94. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/defineAgenticWorkflowHandlers.types.ts +72 -0
  95. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/definitionHandler.ts +104 -0
  96. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/ensureWorkflowIsExecuted.ts +53 -0
  97. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/getTsLogicSummary.ts +639 -0
  98. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/orchestrationToolHandlers.ts +55 -0
  99. package/src/McpHub/ProstglesMcpHub/ProstglesMCPServers/Prostgles/agenticWorkflow/runtimeSdk/tableHandlers.ts +108 -0
@@ -0,0 +1,350 @@
1
+ import * as ts from "typescript";
2
+
3
+ // ─── Types ────────────────────────────────────────────────────────────────────
4
+
5
+ export type StepKind = "await" | "await-assign" | "if" | "loop" | "fn-enter";
6
+
7
+ export interface StepMeta {
8
+ line?: number;
9
+ kind?: StepKind;
10
+ }
11
+
12
+ /**
13
+ * The signature your runtime `__step` function must match.
14
+ * Receives a human-readable label and optional metadata.
15
+ */
16
+ export type StepFn = (label: string, meta?: StepMeta) => Promise<void>;
17
+
18
+ export interface InstrumentOptions {
19
+ /**
20
+ * Name of the step function injected into the workflow.
21
+ * Defaults to `"__step"`. Must be in scope when the instrumented file runs.
22
+ */
23
+ stepFnName?: string;
24
+ /**
25
+ * Optional source code to prepend to the instrumented file.
26
+ * Use this to inject a `__step` implementation directly, e.g. a console logger.
27
+ *
28
+ * @example
29
+ * preamble: `const __step: StepFn = async (label, meta) => { console.log("[step]", label, meta); };`
30
+ */
31
+ preamble?: string;
32
+ }
33
+
34
+ // ─── Helpers ──────────────────────────────────────────────────────────────────
35
+
36
+ const truncate = (s: string, max = 50): string =>
37
+ s.length > max ? s.slice(0, max - 1) + "..." : s;
38
+
39
+ const shortExpr = (node: ts.Node): string => {
40
+ if (ts.isStringLiteral(node)) return JSON.stringify(node.text);
41
+ if (ts.isNumericLiteral(node)) return node.text;
42
+ if (ts.isIdentifier(node)) return node.text;
43
+ if (ts.isPropertyAccessExpression(node))
44
+ return `${shortExpr(node.expression)}.${node.name.text}`;
45
+ if (ts.isCallExpression(node)) return `${shortExpr(node.expression)}(...)`;
46
+ if (ts.isAwaitExpression(node)) return shortExpr(node.expression);
47
+ if (ts.isObjectLiteralExpression(node)) {
48
+ const keys = node.properties
49
+ .slice(0, 2)
50
+ .map((p) => (ts.isPropertyAssignment(p) ? shortExpr(p.name) : "..."))
51
+ .join(", ");
52
+ return `{ ${keys}${node.properties.length > 2 ? ", ..." : ""} }`;
53
+ }
54
+ if (ts.isArrayLiteralExpression(node))
55
+ return `[${node.elements.length} item${node.elements.length !== 1 ? "s" : ""}]`;
56
+ if (ts.isBinaryExpression(node))
57
+ return `${shortExpr(node.left)} ${ts.tokenToString(node.operatorToken.kind)} ${shortExpr(node.right)}`;
58
+ if (ts.isTemplateExpression(node) || ts.isNoSubstitutionTemplateLiteral(node))
59
+ return "`...`";
60
+ return "...";
61
+ };
62
+
63
+ // ─── AST factory helpers ──────────────────────────────────────────────────────
64
+
65
+ const { factory } = ts;
66
+
67
+ const makeStepCall = (
68
+ label: string,
69
+ stepFnName: string,
70
+ meta?: StepMeta,
71
+ ): ts.ExpressionStatement => {
72
+ const metaProps: ts.ObjectLiteralElementLike[] = [];
73
+ if (meta?.line != null)
74
+ metaProps.push(
75
+ factory.createPropertyAssignment(
76
+ "line",
77
+ factory.createNumericLiteral(meta.line),
78
+ ),
79
+ );
80
+ if (meta?.kind != null)
81
+ metaProps.push(
82
+ factory.createPropertyAssignment(
83
+ "kind",
84
+ factory.createStringLiteral(meta.kind),
85
+ ),
86
+ );
87
+
88
+ const args: ts.Expression[] = [factory.createStringLiteral(truncate(label))];
89
+ if (metaProps.length > 0)
90
+ args.push(factory.createObjectLiteralExpression(metaProps));
91
+
92
+ return factory.createExpressionStatement(
93
+ factory.createAwaitExpression(
94
+ factory.createCallExpression(
95
+ factory.createIdentifier(stepFnName),
96
+ undefined,
97
+ args,
98
+ ),
99
+ ),
100
+ );
101
+ };
102
+
103
+ // ─── Transformer: inject __step before key statements ─────────────────────────
104
+
105
+ const makeInstrumentTransformer =
106
+ (
107
+ sf: ts.SourceFile,
108
+ stepFnName: string,
109
+ ): ts.TransformerFactory<ts.SourceFile> =>
110
+ (context) =>
111
+ (rootNode) => {
112
+ let insideAsync = 0;
113
+
114
+ const getLine = (node: ts.Node): number =>
115
+ sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
116
+
117
+ const instrumentBlock = (block: ts.Block): ts.Block => {
118
+ const newStmts: ts.Statement[] = [];
119
+
120
+ for (const stmt of block.statements) {
121
+ // const x = await callee(...)
122
+ if (ts.isVariableStatement(stmt)) {
123
+ const decl = stmt.declarationList.declarations[0];
124
+ if (decl?.initializer && ts.isAwaitExpression(decl.initializer)) {
125
+ const name = ts.isIdentifier(decl.name) ? decl.name.text : "...";
126
+ const callee = shortExpr(decl.initializer.expression);
127
+ newStmts.push(
128
+ makeStepCall(`${name} = await ${callee}`, stepFnName, {
129
+ line: getLine(stmt),
130
+ kind: "await-assign",
131
+ }),
132
+ );
133
+ }
134
+ }
135
+
136
+ // await callee(...) standalone
137
+ if (
138
+ ts.isExpressionStatement(stmt) &&
139
+ ts.isAwaitExpression(stmt.expression)
140
+ ) {
141
+ const callee = shortExpr(stmt.expression.expression);
142
+ newStmts.push(
143
+ makeStepCall(`await ${callee}`, stepFnName, {
144
+ line: getLine(stmt),
145
+ kind: "await",
146
+ }),
147
+ );
148
+ }
149
+
150
+ // if (condition)
151
+ if (ts.isIfStatement(stmt)) {
152
+ newStmts.push(
153
+ makeStepCall(
154
+ `if (${truncate(shortExpr(stmt.expression), 40)})`,
155
+ stepFnName,
156
+ { line: getLine(stmt), kind: "if" },
157
+ ),
158
+ );
159
+ }
160
+
161
+ // for...of / for...in
162
+ if (ts.isForOfStatement(stmt) || ts.isForInStatement(stmt)) {
163
+ newStmts.push(
164
+ makeStepCall(
165
+ `forEach ${truncate(shortExpr(stmt.expression), 40)}`,
166
+ stepFnName,
167
+ { line: getLine(stmt), kind: "loop" },
168
+ ),
169
+ );
170
+ }
171
+
172
+ newStmts.push(ts.visitEachChild(stmt, visit, context));
173
+ }
174
+
175
+ return factory.updateBlock(block, newStmts);
176
+ };
177
+
178
+ const visit = (node: ts.Node): ts.Node => {
179
+ const isAsyncFn =
180
+ (ts.isArrowFunction(node) ||
181
+ ts.isFunctionExpression(node) ||
182
+ ts.isFunctionDeclaration(node)) &&
183
+ (node as ts.FunctionLikeDeclaration).modifiers?.some(
184
+ (m) => m.kind === ts.SyntaxKind.AsyncKeyword,
185
+ );
186
+
187
+ if (isAsyncFn) {
188
+ insideAsync++;
189
+ const updated = ts.visitEachChild(node, visit, context);
190
+ insideAsync--;
191
+ return updated;
192
+ }
193
+
194
+ if (ts.isBlock(node) && insideAsync > 0) {
195
+ return instrumentBlock(node);
196
+ }
197
+
198
+ return ts.visitEachChild(node, visit, context);
199
+ };
200
+
201
+ return ts.visitNode(rootNode, visit) as ts.SourceFile;
202
+ };
203
+
204
+ // ─── Transformer: inject "enter <fnName>" at top of named async arrow fns ────
205
+
206
+ const makeEnterFnTransformer =
207
+ (stepFnName: string): ts.TransformerFactory<ts.SourceFile> =>
208
+ (context) =>
209
+ (rootNode) => {
210
+ const visit = (node: ts.Node): ts.Node => {
211
+ if (ts.isVariableStatement(node)) {
212
+ const decl = node.declarationList.declarations[0];
213
+ if (
214
+ decl &&
215
+ ts.isIdentifier(decl.name) &&
216
+ decl.initializer &&
217
+ (ts.isArrowFunction(decl.initializer) ||
218
+ ts.isFunctionExpression(decl.initializer)) &&
219
+ ts.isBlock(decl.initializer.body) &&
220
+ decl.initializer.modifiers?.some(
221
+ (m) => m.kind === ts.SyntaxKind.AsyncKeyword,
222
+ )
223
+ ) {
224
+ const fnName = decl.name.text;
225
+ const enterStmt = makeStepCall(`enter ${fnName}`, stepFnName, {
226
+ kind: "fn-enter",
227
+ });
228
+ const oldBody = decl.initializer.body;
229
+ const newBody = factory.updateBlock(oldBody, [
230
+ enterStmt,
231
+ ...oldBody.statements,
232
+ ]);
233
+
234
+ const newInit =
235
+ ts.isArrowFunction(decl.initializer) ?
236
+ factory.updateArrowFunction(
237
+ decl.initializer,
238
+ decl.initializer.modifiers,
239
+ decl.initializer.typeParameters,
240
+ decl.initializer.parameters,
241
+ decl.initializer.type,
242
+ decl.initializer.equalsGreaterThanToken,
243
+ newBody,
244
+ )
245
+ : factory.updateFunctionExpression(
246
+ decl.initializer,
247
+ decl.initializer.modifiers,
248
+ decl.initializer.asteriskToken,
249
+ decl.initializer.name,
250
+ decl.initializer.typeParameters,
251
+ decl.initializer.parameters,
252
+ decl.initializer.type,
253
+ newBody,
254
+ );
255
+
256
+ const newDecl = factory.updateVariableDeclaration(
257
+ decl,
258
+ decl.name,
259
+ decl.exclamationToken,
260
+ decl.type,
261
+ newInit,
262
+ );
263
+
264
+ return factory.updateVariableStatement(
265
+ node,
266
+ node.modifiers,
267
+ factory.updateVariableDeclarationList(node.declarationList, [
268
+ newDecl,
269
+ ]),
270
+ );
271
+ }
272
+ }
273
+
274
+ return ts.visitEachChild(node, visit, context);
275
+ };
276
+
277
+ return ts.visitNode(rootNode, visit) as ts.SourceFile;
278
+ };
279
+
280
+ // ─── Public API ───────────────────────────────────────────────────────────────
281
+
282
+ /**
283
+ * Instruments a full workflow TypeScript file by injecting `await __step(label, meta)`
284
+ * calls before every meaningful step in the workflow function body.
285
+ *
286
+ * Instrumented points:
287
+ * - `const x = await callee(...)` → logged before the await
288
+ * - `await callee(...)` (standalone) → logged before the await
289
+ * - `if (condition)` → logged before the branch
290
+ * - `for...of` / `forEach` loops → logged before iteration
291
+ * - Entry of named async sub-functions (`const doX = async () => {...}`)
292
+ *
293
+ * The `stepFnName` function must be in scope when the instrumented file runs.
294
+ * Use the `preamble` option to inject an implementation, or set it as a global
295
+ * before executing (e.g. `globalThis.__step = myLogger`).
296
+ *
297
+ * @example — inject a console logger
298
+ * ```ts
299
+ * const instrumented = instrumentWorkflowFile(source, {
300
+ * preamble: `const __step = async (label, meta) => {
301
+ * console.log(\`[step:\${meta?.kind}] \${label}\`, meta?.line ? \`(line \${meta.line})\` : "");
302
+ * };`,
303
+ * });
304
+ * ```
305
+ *
306
+ * @example — send steps to a websocket for real-time UI updates
307
+ * ```ts
308
+ * const instrumented = instrumentWorkflowFile(source, {
309
+ * preamble: `const __step = async (label, meta) => {
310
+ * await fetch("/api/workflow-step", {
311
+ * method: "POST",
312
+ * body: JSON.stringify({ label, ...meta }),
313
+ * });
314
+ * };`,
315
+ * });
316
+ * ```
317
+ */
318
+ export const instrumentWorkflowFile = (
319
+ fileSource: string,
320
+ options: InstrumentOptions = {},
321
+ ): string => {
322
+ const { stepFnName = "__step", preamble } = options;
323
+
324
+ const sf = ts.createSourceFile(
325
+ "workflow.ts",
326
+ fileSource,
327
+ ts.ScriptTarget.Latest,
328
+ true,
329
+ ts.ScriptKind.TS,
330
+ );
331
+
332
+ const result = ts.transform(sf, [
333
+ makeInstrumentTransformer(sf, stepFnName),
334
+ makeEnterFnTransformer(stepFnName),
335
+ ]);
336
+
337
+ const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
338
+ const instrumented = printer.printFile(result.transformed[0]!);
339
+
340
+ return preamble ? `${preamble}\n\n${instrumented}` : instrumented;
341
+ };
342
+
343
+ /**
344
+ * Convenience: returns a default console-logging preamble you can pass directly.
345
+ */
346
+ export const consoleStepLogger = (stepFnName = "__step"): string =>
347
+ `const ${stepFnName} = async (label: string, meta?: { line?: number; kind?: string }) => {
348
+ const loc = meta?.line ? \` (line \${meta.line})\` : "";
349
+ console.log(\`[workflow:\${meta?.kind ?? "step"}]\${loc} \${label}\`);
350
+ };`;
@@ -0,0 +1,99 @@
1
+ import {
2
+ WORKFLOW_ENV_VARS,
3
+ type ProxyCallData,
4
+ } from "./defineAgenticWorkflowHandlers.types";
5
+ const { DOCKER_MCP_ENDPOINT } = WORKFLOW_ENV_VARS;
6
+
7
+ const startTime = Date.now();
8
+ export const callWorkflowProxy = async (args: ProxyCallData) => {
9
+ const logData: [string, ...any] = (() => {
10
+ if (
11
+ args.type === "db/execute_sql" ||
12
+ args.type === "db/execute_readonly_sql"
13
+ ) {
14
+ return ["db.runSQL", args.type];
15
+ }
16
+ if (args.type === "agent") {
17
+ return ["agent." + args.agentName, truncateString(args.input)];
18
+ }
19
+ if (args.type === "tool") {
20
+ return [
21
+ args.serverName,
22
+ args.toolName,
23
+ args.input && shortenJsonData(args.input),
24
+ ];
25
+ }
26
+ if (args.type === "progress") {
27
+ const { percent, message } = args;
28
+ return [
29
+ "progress",
30
+ typeof percent === "number" ? percent.toFixed(1) + "%" : percent,
31
+ message,
32
+ ];
33
+ }
34
+
35
+ if (args.type === "definitions") {
36
+ return [args.type, args.definitions.name];
37
+ }
38
+
39
+ const command = args.type.split("/")[1];
40
+ return [
41
+ `db.${(args as Extract<ProxyCallData, { tableName: string }>).tableName}.${command}`,
42
+ ];
43
+ })();
44
+
45
+ const { type, ...argsWithoutType } = args;
46
+ const route =
47
+ args.type === "tool" ?
48
+ [args.serverName, args.toolName].join("/")
49
+ : args.type;
50
+ const result = await fetch(`${DOCKER_MCP_ENDPOINT}/${route}`, {
51
+ method: "POST",
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ },
55
+ body: JSON.stringify(
56
+ args.type.startsWith("db/") ? argsWithoutType
57
+ : args.type === "tool" ? args.input
58
+ : args,
59
+ ),
60
+ });
61
+
62
+ const elapsed = `T+ ${Date.now() - startTime}ms`;
63
+ if (!result.ok) {
64
+ console.error(elapsed, ...logData, "\n");
65
+ } else {
66
+ console.log(elapsed, ...logData, "\n");
67
+ }
68
+ const resCopy = result.clone();
69
+ const data = await result.json().catch(() => resCopy.text());
70
+
71
+ if (!result.ok) {
72
+ console.error(`${logData[0]} failed`, data);
73
+ return Promise.reject(data);
74
+ }
75
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
76
+ return data as any;
77
+ };
78
+
79
+ const truncateString = (str: string, maxLength = 100): string => {
80
+ if (str.length <= maxLength) {
81
+ return str;
82
+ }
83
+ return str.slice(0, maxLength) + "... [truncated]";
84
+ };
85
+
86
+ const shortenJsonData = (
87
+ data: Record<string, unknown>,
88
+ ): Record<string, unknown> => {
89
+ const shortenedData: Record<string, unknown> = {};
90
+ for (const key in data) {
91
+ const value = data[key];
92
+ if (typeof value === "string") {
93
+ shortenedData[key] = truncateString(value);
94
+ } else {
95
+ shortenedData[key] = value;
96
+ }
97
+ }
98
+ return shortenedData;
99
+ };
@@ -0,0 +1,110 @@
1
+ import { describe, test } from "node:test";
2
+ import { defineAgenticWorkflow } from "./defineAgenticWorkflow";
3
+
4
+ void describe("defineAgenticWorkflow", async () => {
5
+ await test("defineAgenticWorkflow type tests", () => {
6
+ () => {
7
+ void defineAgenticWorkflow(
8
+ {
9
+ name: "Test Workflow",
10
+ containerConfiguration: { timeout: 60_000 },
11
+ databaseAccessDefinitions: {
12
+ mode: "custom",
13
+ tablePermissions: {
14
+ tbl1: {
15
+ select: true,
16
+ insert: true,
17
+ },
18
+ },
19
+ },
20
+ agentDefinitions: {
21
+ researcher: {
22
+ prompt: "You are a research assistant.",
23
+ tools: { fetch: { fetch_webpage: 1 } },
24
+ outputSchema: {
25
+ summary: { type: "string" },
26
+ references: { type: "string[]" },
27
+ },
28
+ },
29
+ },
30
+ orchestrationTools: {
31
+ web: {
32
+ search: 1,
33
+ get_snapshot: 1,
34
+ },
35
+ },
36
+ userInput: {
37
+ test_input: {
38
+ title: "Test Input",
39
+ type: "table-filter",
40
+ tableName: "users",
41
+ },
42
+ enum_input: {
43
+ title: "Enum Input",
44
+ type: "enum",
45
+ values: ["option1", "option2", "option3"] as const,
46
+ },
47
+ text_input: {
48
+ title: "Text Input",
49
+ type: "custom",
50
+ dataType: "string",
51
+ },
52
+ date_input: {
53
+ title: "Date Input",
54
+ type: "custom",
55
+ dataType: "Date",
56
+ },
57
+ number_input: {
58
+ title: "Number Input",
59
+ type: "custom",
60
+ dataType: "number",
61
+ },
62
+ },
63
+ },
64
+ async ({
65
+ agentHandlers: {
66
+ researcher,
67
+ //@ts-expect-error
68
+ invalid,
69
+ },
70
+ tableHandlers,
71
+ runSQL,
72
+ orchestratorToolHandlers,
73
+ userInputValues: {
74
+ test_input,
75
+ enum_input,
76
+ text_input,
77
+ date_input,
78
+ number_input,
79
+ },
80
+ }) => {
81
+ void tableHandlers.tbl1?.insert({ col1: "value1", col2: 123 });
82
+ // @ts-expect-error
83
+ void runSQL("SELECT * FROM tbl1");
84
+ const result = await researcher("Prostgles");
85
+ result.summary satisfies string;
86
+
87
+ void orchestratorToolHandlers.web.search({ q: "Prostgles" });
88
+ void orchestratorToolHandlers.web.get_snapshot({
89
+ url: "https://www.example.com",
90
+ });
91
+
92
+ // @ts-expect-error
93
+ result.invalid;
94
+
95
+ const result2 = await researcher(test_input.tableName);
96
+
97
+ if (enum_input === "option1") {
98
+ //@ts-expect-error
99
+ } else if (enum_input === "option233") {
100
+ }
101
+
102
+ text_input.trim();
103
+
104
+ date_input.getDate();
105
+ number_input.toFixed(2);
106
+ },
107
+ );
108
+ };
109
+ });
110
+ });