@inkeep/agents-api 0.0.0-dev-20260122085034 → 0.0.0-dev-20260122090358

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.
@@ -1,16 +1,5 @@
1
1
  {
2
2
  "steps": {
3
- "node_modules/.pnpm/workflow@4.0.1-beta.33_@aws-sdk+client-sts@3.970.0_@opentelemetry+api@1.9.0_@types+reac_5c488396978166b4f12e99cb3aa4a769/node_modules/workflow/dist/internal/builtins.js": {
4
- "__builtin_response_array_buffer": {
5
- "stepId": "__builtin_response_array_buffer"
6
- },
7
- "__builtin_response_json": {
8
- "stepId": "__builtin_response_json"
9
- },
10
- "__builtin_response_text": {
11
- "stepId": "__builtin_response_text"
12
- }
13
- },
14
3
  "src/domains/evals/workflow/functions/runDatasetItem.ts": {
15
4
  "callChatApiStep": {
16
5
  "stepId": "step//src/domains/evals/workflow/functions/runDatasetItem.ts//callChatApiStep"
@@ -25,6 +14,17 @@
25
14
  "stepId": "step//src/domains/evals/workflow/functions/runDatasetItem.ts//logStep"
26
15
  }
27
16
  },
17
+ "node_modules/.pnpm/workflow@4.0.1-beta.33_@aws-sdk+client-sts@3.970.0_@opentelemetry+api@1.9.0_@types+reac_5c488396978166b4f12e99cb3aa4a769/node_modules/workflow/dist/internal/builtins.js": {
18
+ "__builtin_response_array_buffer": {
19
+ "stepId": "__builtin_response_array_buffer"
20
+ },
21
+ "__builtin_response_json": {
22
+ "stepId": "__builtin_response_json"
23
+ },
24
+ "__builtin_response_text": {
25
+ "stepId": "__builtin_response_text"
26
+ }
27
+ },
28
28
  "src/domains/evals/workflow/functions/evaluateConversation.ts": {
29
29
  "executeEvaluatorStep": {
30
30
  "stepId": "step//src/domains/evals/workflow/functions/evaluateConversation.ts//executeEvaluatorStep"
@@ -1,7 +1,7 @@
1
1
  import { OpenAPIHono } from "@hono/zod-openapi";
2
- import * as hono10 from "hono";
2
+ import * as hono15 from "hono";
3
3
 
4
4
  //#region src/domains/evals/routes/datasetTriggers.d.ts
5
- declare const app: OpenAPIHono<hono10.Env, {}, "/">;
5
+ declare const app: OpenAPIHono<hono15.Env, {}, "/">;
6
6
  //#endregion
7
7
  export { app as default };
@@ -1,7 +1,7 @@
1
1
  import { OpenAPIHono } from "@hono/zod-openapi";
2
- import * as hono14 from "hono";
2
+ import * as hono16 from "hono";
3
3
 
4
4
  //#region src/domains/evals/routes/index.d.ts
5
- declare const app: OpenAPIHono<hono14.Env, {}, "/">;
5
+ declare const app: OpenAPIHono<hono16.Env, {}, "/">;
6
6
  //#endregion
7
7
  export { app as default };
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types7 from "hono/types";
2
+ import * as hono_types5 from "hono/types";
3
3
 
4
4
  //#region src/domains/evals/workflow/routes.d.ts
5
- declare const workflowRoutes: Hono<hono_types7.BlankEnv, hono_types7.BlankSchema, "/">;
5
+ declare const workflowRoutes: Hono<hono_types5.BlankEnv, hono_types5.BlankSchema, "/">;
6
6
  //#endregion
7
7
  export { workflowRoutes };
@@ -11,8 +11,9 @@ import { createVercelWorld } from "@workflow/world-vercel";
11
11
  * Vercel's NFT can't trace dynamic imports in bundled code.
12
12
  *
13
13
  * Set WORKFLOW_TARGET_WORLD to: 'local' | 'vercel' | '@workflow/world-postgres'
14
+ * Defaults to 'local' for development if not set.
14
15
  */
15
- const targetWorld = env.WORKFLOW_TARGET_WORLD;
16
+ const targetWorld = env.WORKFLOW_TARGET_WORLD || "local";
16
17
  let world;
17
18
  if (targetWorld === "vercel") {
18
19
  const token = process.env.WORKFLOW_VERCEL_AUTH_TOKEN;
@@ -30,7 +31,7 @@ if (targetWorld === "vercel") {
30
31
  jobPrefix: env.WORKFLOW_POSTGRES_JOB_PREFIX,
31
32
  queueConcurrency: Number(env.WORKFLOW_POSTGRES_WORKER_CONCURRENCY) || 10
32
33
  });
33
- else if (targetWorld === "local") world = createLocalWorld();
34
+ else world = createLocalWorld();
34
35
 
35
36
  //#endregion
36
37
  export { world };
@@ -1,7 +1,7 @@
1
1
  import { OpenAPIHono } from "@hono/zod-openapi";
2
- import * as hono15 from "hono";
2
+ import * as hono3 from "hono";
3
3
 
4
4
  //#region src/domains/manage/routes/conversations.d.ts
5
- declare const app: OpenAPIHono<hono15.Env, {}, "/">;
5
+ declare const app: OpenAPIHono<hono3.Env, {}, "/">;
6
6
  //#endregion
7
7
  export { app as default };
@@ -1,7 +1,7 @@
1
1
  import { OpenAPIHono } from "@hono/zod-openapi";
2
- import * as hono18 from "hono";
2
+ import * as hono17 from "hono";
3
3
 
4
4
  //#region src/domains/manage/routes/evals/evaluationResults.d.ts
5
- declare const app: OpenAPIHono<hono18.Env, {}, "/">;
5
+ declare const app: OpenAPIHono<hono17.Env, {}, "/">;
6
6
  //#endregion
7
7
  export { app as default };
@@ -1,7 +1,7 @@
1
1
  import { OpenAPIHono } from "@hono/zod-openapi";
2
- import * as hono17 from "hono";
2
+ import * as hono18 from "hono";
3
3
 
4
4
  //#region src/domains/manage/routes/index.d.ts
5
- declare const app: OpenAPIHono<hono17.Env, {}, "/">;
5
+ declare const app: OpenAPIHono<hono18.Env, {}, "/">;
6
6
  //#endregion
7
7
  export { app as default };
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
- import * as hono_types5 from "hono/types";
2
+ import * as hono_types7 from "hono/types";
3
3
 
4
4
  //#region src/domains/manage/routes/mcp.d.ts
5
- declare const app: Hono<hono_types5.BlankEnv, hono_types5.BlankSchema, "/">;
5
+ declare const app: Hono<hono_types7.BlankEnv, hono_types7.BlankSchema, "/">;
6
6
  //#endregion
7
7
  export { app as default };
@@ -1,18 +1,10 @@
1
- import { getLogger as getLogger$1 } from "../../../logger.js";
2
- import { env } from "../../../env.js";
3
- import manageDbPool_default from "../../../data/db/manageDbPool.js";
4
- import runDbClient_default from "../../../data/db/runDbClient.js";
5
- import { createSSEStreamHelper } from "../utils/stream-helpers.js";
6
- import { ExecutionHandler } from "../handlers/executionHandler.js";
1
+ import { getLogger } from "../../../logger.js";
2
+ import { processWebhook } from "../services/TriggerService.js";
7
3
  import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
8
- import { JsonTransformer, createApiError, createMessage, createOrGetConversation, createTriggerInvocation, generateId, getConversationId, getFullProjectWithRelationIds, getTriggerById, interpolateTemplate, setActiveAgentForConversation, updateTriggerInvocationStatus, verifySigningSecret, verifyTriggerAuth, withRef } from "@inkeep/agents-core";
9
- import { ROOT_CONTEXT, context, propagation, trace } from "@opentelemetry/api";
10
- import Ajv from "ajv";
11
4
 
12
5
  //#region src/domains/run/routes/webhooks.ts
13
6
  const app = new OpenAPIHono();
14
- const logger = getLogger$1("webhooks");
15
- const ajv = new Ajv({ allErrors: true });
7
+ const logger = getLogger("webhooks");
16
8
  /**
17
9
  * Webhook endpoint for trigger invocation
18
10
  * POST /tenants/{tenantId}/projects/{projectId}/agents/{agentId}/triggers/{triggerId}
@@ -37,7 +29,8 @@ const triggerWebhookRoute = createRoute({
37
29
  description: "Webhook accepted and trigger invoked",
38
30
  content: { "application/json": { schema: z.object({
39
31
  success: z.boolean(),
40
- invocationId: z.string()
32
+ invocationId: z.string(),
33
+ conversationId: z.string()
41
34
  }) } }
42
35
  },
43
36
  400: {
@@ -74,336 +67,36 @@ app.openapi(triggerWebhookRoute, async (c) => {
74
67
  agentId,
75
68
  triggerId
76
69
  }, "Processing trigger webhook");
77
- try {
78
- const trigger = await withRef(manageDbPool_default, resolvedRef, (db) => getTriggerById(db)({
79
- scopes: {
80
- tenantId,
81
- projectId,
82
- agentId
83
- },
84
- triggerId
85
- }));
86
- if (!trigger) throw createApiError({
87
- code: "not_found",
88
- message: `Trigger ${triggerId} not found`
89
- });
90
- if (!trigger.enabled) throw createApiError({
91
- code: "not_found",
92
- message: "Trigger is disabled"
93
- });
94
- const bodyText = await c.req.text();
95
- const payload = bodyText ? JSON.parse(bodyText) : {};
96
- if (trigger.authentication) {
97
- const authResult = await verifyTriggerAuth(c, trigger.authentication);
98
- if (!authResult.success) {
99
- if (authResult.status === 401) return c.json({ error: authResult.message || "Unauthorized" }, 401);
100
- return c.json({ error: authResult.message || "Forbidden" }, 403);
101
- }
102
- }
103
- if (trigger.signingSecret) {
104
- const signatureResult = verifySigningSecret(c, trigger.signingSecret, bodyText);
105
- if (!signatureResult.success) return c.json({ error: signatureResult.message || "Invalid signature" }, 403);
106
- }
107
- if (trigger.inputSchema) {
108
- const validate = ajv.compile(trigger.inputSchema);
109
- if (!validate(payload)) {
110
- const errors = validate.errors?.map((err) => `${err.instancePath} ${err.message}`);
111
- return c.json({
112
- error: "Payload validation failed",
113
- validationErrors: errors
114
- }, 400);
115
- }
116
- }
117
- let transformedPayload = payload;
118
- if (trigger.outputTransform) try {
119
- transformedPayload = await JsonTransformer.transformWithConfig(payload, trigger.outputTransform);
120
- logger.debug({
121
- triggerId,
122
- tenantId,
123
- projectId
124
- }, "Payload transformation successful");
125
- } catch (error) {
126
- const errorMessage = error instanceof Error ? error.message : String(error);
127
- logger.error({
128
- triggerId,
129
- tenantId,
130
- projectId,
131
- error: errorMessage
132
- }, "Payload transformation failed");
133
- return c.json({ error: `Payload transformation failed: ${errorMessage}` }, 422);
134
- }
135
- const messageParts = [];
136
- if (trigger.messageTemplate) {
137
- const interpolatedMessage = interpolateTemplate(trigger.messageTemplate, transformedPayload);
138
- messageParts.push({
139
- kind: "text",
140
- text: interpolatedMessage
141
- });
142
- }
143
- if (transformedPayload != null) messageParts.push({
144
- kind: "data",
145
- data: transformedPayload,
146
- metadata: {
147
- source: "trigger",
148
- triggerId
149
- }
150
- });
151
- const userMessageText = trigger.messageTemplate ? interpolateTemplate(trigger.messageTemplate, transformedPayload) : JSON.stringify(transformedPayload);
152
- const conversationId = getConversationId();
153
- const invocationId = generateId();
154
- await createTriggerInvocation(runDbClient_default)({
155
- id: invocationId,
156
- triggerId,
157
- tenantId,
158
- projectId,
159
- agentId,
160
- conversationId,
161
- status: "pending",
162
- requestPayload: payload,
163
- transformedPayload
164
- });
165
- logger.info({
166
- tenantId,
167
- projectId,
168
- agentId,
169
- triggerId,
170
- invocationId,
171
- conversationId
172
- }, "Trigger invocation created");
173
- invokeAgentAsync({
174
- tenantId,
175
- projectId,
176
- agentId,
177
- triggerId,
178
- invocationId,
179
- conversationId,
180
- userMessage: userMessageText,
181
- messageParts,
182
- resolvedRef
183
- }).catch((error) => {
184
- logger.error({
185
- error,
186
- tenantId,
187
- projectId,
188
- agentId,
189
- triggerId,
190
- invocationId
191
- }, "Async agent invocation failed");
192
- });
193
- logger.info({
194
- tenantId,
195
- projectId,
196
- agentId,
197
- triggerId,
198
- invocationId,
199
- conversationId
200
- }, "Trigger webhook accepted, agent invocation initiated");
201
- return c.json({
202
- success: true,
203
- invocationId
204
- }, 202);
205
- } catch (error) {
206
- logger.error({
207
- error,
208
- tenantId,
209
- projectId,
210
- agentId,
211
- triggerId
212
- }, "Webhook processing failed");
213
- throw error;
70
+ const result = await processWebhook({
71
+ tenantId,
72
+ projectId,
73
+ agentId,
74
+ triggerId,
75
+ resolvedRef,
76
+ rawBody: await c.req.text(),
77
+ honoContext: c
78
+ });
79
+ if (!result.success) {
80
+ if (result.validationErrors) return c.json({
81
+ error: result.error,
82
+ validationErrors: result.validationErrors
83
+ }, result.status);
84
+ return c.json({ error: result.error }, result.status);
214
85
  }
86
+ logger.info({
87
+ tenantId,
88
+ projectId,
89
+ agentId,
90
+ triggerId,
91
+ invocationId: result.invocationId,
92
+ conversationId: result.conversationId
93
+ }, "Trigger webhook accepted, workflow dispatched");
94
+ return c.json({
95
+ success: true,
96
+ invocationId: result.invocationId,
97
+ conversationId: result.conversationId
98
+ }, 202);
215
99
  });
216
- /**
217
- * Invokes an agent asynchronously for a trigger invocation.
218
- * This function creates a conversation, stores the user message,
219
- * and executes the agent using ExecutionHandler.
220
- * It updates the trigger invocation status based on success/failure.
221
- */
222
- async function invokeAgentAsync(params) {
223
- const { tenantId, projectId, agentId, triggerId, invocationId, conversationId, userMessage, messageParts, resolvedRef } = params;
224
- return await trace.getTracer("trigger-invocation").startActiveSpan("trigger.invocation", { attributes: {
225
- "conversation.id": conversationId,
226
- "tenant.id": tenantId,
227
- "project.id": projectId,
228
- "agent.id": agentId,
229
- "invocation.type": "trigger",
230
- "trigger.id": triggerId,
231
- "trigger.invocation.id": invocationId,
232
- "message.content": userMessage,
233
- "message.parts": JSON.stringify(messageParts),
234
- "message.timestamp": (/* @__PURE__ */ new Date()).toISOString()
235
- } }, ROOT_CONTEXT, async (span) => {
236
- const spanCtx = trace.setSpan(ROOT_CONTEXT, span);
237
- let bag = propagation.getBaggage(spanCtx) ?? propagation.createBaggage();
238
- bag = bag.setEntry("conversation.id", { value: conversationId }).setEntry("tenant.id", { value: tenantId }).setEntry("project.id", { value: projectId }).setEntry("agent.id", { value: agentId }).setEntry("invocation.type", { value: "trigger" }).setEntry("trigger.id", { value: triggerId }).setEntry("trigger.invocation.id", { value: invocationId });
239
- const ctx = propagation.setBaggage(spanCtx, bag);
240
- return await context.with(ctx, async () => {
241
- try {
242
- logger.info({
243
- tenantId,
244
- projectId,
245
- agentId,
246
- triggerId,
247
- invocationId,
248
- conversationId
249
- }, "Starting async agent invocation");
250
- const project = await withRef(manageDbPool_default, resolvedRef, async (db) => {
251
- return await getFullProjectWithRelationIds(db)({ scopes: {
252
- tenantId,
253
- projectId
254
- } });
255
- });
256
- if (!project) throw createApiError({
257
- code: "not_found",
258
- message: `Project ${projectId} not found`
259
- });
260
- const fullAgent = project.agents[agentId];
261
- if (!fullAgent) throw createApiError({
262
- code: "not_found",
263
- message: `Agent ${agentId} not found`
264
- });
265
- span.setAttribute("agent.name", fullAgent.name || "");
266
- logger.debug({
267
- tenantId,
268
- projectId,
269
- agentId,
270
- defaultSubAgentId: fullAgent.defaultSubAgentId,
271
- subAgentKeys: Object.keys(fullAgent.subAgents || {}),
272
- subAgentsCount: Object.keys(fullAgent.subAgents || {}).length
273
- }, "Debug: Agent and sub-agent info");
274
- const agentKeys = Object.keys(fullAgent.subAgents || {});
275
- const firstAgentId = agentKeys.length > 0 ? agentKeys[0] : "";
276
- const defaultSubAgentId = fullAgent.defaultSubAgentId || firstAgentId;
277
- if (!defaultSubAgentId) throw createApiError({
278
- code: "not_found",
279
- message: "No default sub-agent found"
280
- });
281
- const executionContext = {
282
- tenantId,
283
- projectId,
284
- agentId,
285
- baseUrl: env.INKEEP_AGENTS_API_URL || "http://localhost:3002",
286
- apiKey: env.INKEEP_AGENTS_RUN_API_BYPASS_SECRET || "",
287
- apiKeyId: "trigger-invocation",
288
- resolvedRef,
289
- project,
290
- metadata: { initiatedBy: {
291
- type: "api_key",
292
- id: triggerId
293
- } }
294
- };
295
- await createOrGetConversation(runDbClient_default)({
296
- tenantId,
297
- projectId,
298
- id: conversationId,
299
- agentId,
300
- activeSubAgentId: defaultSubAgentId,
301
- ref: executionContext.resolvedRef
302
- });
303
- await setActiveAgentForConversation(runDbClient_default)({
304
- scopes: {
305
- tenantId,
306
- projectId
307
- },
308
- conversationId,
309
- agentId,
310
- subAgentId: defaultSubAgentId,
311
- ref: executionContext.resolvedRef
312
- });
313
- logger.info({
314
- conversationId,
315
- agentId,
316
- defaultSubAgentId
317
- }, "Conversation created and agent set");
318
- await createMessage(runDbClient_default)({
319
- id: generateId(),
320
- tenantId,
321
- projectId,
322
- conversationId,
323
- role: "user",
324
- content: { parts: messageParts },
325
- visibility: "user-facing",
326
- messageType: "chat"
327
- });
328
- logger.info({
329
- conversationId,
330
- invocationId
331
- }, "User message created");
332
- const requestId = `trigger-${invocationId}`;
333
- const noOpStreamHelper = createSSEStreamHelper({
334
- writeSSE: async () => {},
335
- sleep: async () => {}
336
- }, requestId, Math.floor(Date.now() / 1e3));
337
- await new ExecutionHandler().execute({
338
- executionContext,
339
- conversationId,
340
- userMessage,
341
- messageParts,
342
- initialAgentId: agentId,
343
- requestId,
344
- sseHelper: noOpStreamHelper,
345
- emitOperations: false
346
- });
347
- await updateTriggerInvocationStatus(runDbClient_default)({
348
- scopes: {
349
- tenantId,
350
- projectId,
351
- agentId
352
- },
353
- triggerId,
354
- invocationId,
355
- data: { status: "success" }
356
- });
357
- logger.info({
358
- tenantId,
359
- projectId,
360
- agentId,
361
- triggerId,
362
- invocationId,
363
- conversationId
364
- }, "Agent invocation completed successfully");
365
- span.end();
366
- } catch (error) {
367
- const errorMessage = error instanceof Error ? error.message : String(error);
368
- logger.error({
369
- error,
370
- tenantId,
371
- projectId,
372
- agentId,
373
- triggerId,
374
- invocationId
375
- }, "Agent invocation failed");
376
- span.recordException(error instanceof Error ? error : new Error(errorMessage));
377
- span.setStatus({
378
- code: 2,
379
- message: errorMessage
380
- });
381
- try {
382
- await updateTriggerInvocationStatus(runDbClient_default)({
383
- scopes: {
384
- tenantId,
385
- projectId,
386
- agentId
387
- },
388
- triggerId,
389
- invocationId,
390
- data: {
391
- status: "failed",
392
- errorMessage
393
- }
394
- });
395
- } catch (updateError) {
396
- logger.error({
397
- updateError,
398
- invocationId
399
- }, "Failed to update trigger invocation status to failed");
400
- }
401
- span.end();
402
- throw error;
403
- }
404
- });
405
- });
406
- }
407
100
  var webhooks_default = app;
408
101
 
409
102
  //#endregion
@@ -0,0 +1,31 @@
1
+ import { Context } from "hono";
2
+ import { ResolvedRef } from "@inkeep/agents-core";
3
+
4
+ //#region src/domains/run/services/TriggerService.d.ts
5
+
6
+ type TriggerWebhookParams = {
7
+ tenantId: string;
8
+ projectId: string;
9
+ agentId: string;
10
+ triggerId: string;
11
+ resolvedRef: ResolvedRef;
12
+ rawBody: string;
13
+ honoContext: Context;
14
+ };
15
+ type TriggerWebhookResult = {
16
+ success: true;
17
+ invocationId: string;
18
+ conversationId: string;
19
+ } | {
20
+ success: false;
21
+ error: string;
22
+ status: 400 | 401 | 403 | 404 | 422;
23
+ validationErrors?: string[];
24
+ };
25
+ /**
26
+ * Process a trigger webhook request.
27
+ * Handles validation, transformation, and dispatches async execution.
28
+ */
29
+ declare function processWebhook(params: TriggerWebhookParams): Promise<TriggerWebhookResult>;
30
+ //#endregion
31
+ export { TriggerWebhookParams, TriggerWebhookResult, processWebhook };