@inkeep/agents-run-api 0.29.2 → 0.29.4
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/dist/index.cjs +174 -345
- package/dist/index.js +169 -338
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { dbClient_default } from './chunk-TRNLEUK2.js';
|
|
|
4
4
|
import { env } from './chunk-Z4TYO3W3.js';
|
|
5
5
|
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
6
6
|
import { __publicField } from './chunk-PKBMQBKP.js';
|
|
7
|
-
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory,
|
|
7
|
+
import { getTracer, HeadersScopeSchema, getRequestExecutionContext, createApiError, getAgentWithDefaultSubAgent, contextValidationMiddleware, getConversationId, getFullAgent, createOrGetConversation, getActiveAgentForConversation, setActiveAgentForConversation, getSubAgentById, handleContextResolution, createMessage, generateId, commonGetErrorResponses, loggerFactory, createDefaultCredentialStores, CredentialStoreRegistry, listTaskIdsByContextId, getTask, getLedgerArtifacts, upsertLedgerArtifact, createTask, updateTask, setSpanWithError, updateConversation, handleApiError, TaskState, setActiveAgentForThread, getConversation, getAgentById, getRelatedAgentsForAgent, getExternalAgentsForSubAgent, getTeamAgentsForSubAgent, getToolsForAgent, getDataComponentsForAgent, getArtifactComponentsForAgent, dbResultToMcpTool, validateAndGetApiKey, verifyServiceToken, validateTargetAgent, getProject, ContextResolver, CredentialStuffer, MCPServerType, getCredentialReference, McpClient, getFunctionToolsForSubAgent, getFunction, getContextConfigById, getFullAgentDefinition, TemplateEngine, agentHasArtifactComponents, MCPTransportType, SPAN_KEYS, headers, generateServiceToken } from '@inkeep/agents-core';
|
|
8
8
|
import { otel } from '@hono/otel';
|
|
9
9
|
import { OpenAPIHono, createRoute, z as z$1 } from '@hono/zod-openapi';
|
|
10
10
|
import { trace, propagation, context, SpanStatusCode } from '@opentelemetry/api';
|
|
@@ -16,7 +16,7 @@ import { createMiddleware } from 'hono/factory';
|
|
|
16
16
|
import { swaggerUI } from '@hono/swagger-ui';
|
|
17
17
|
import z5, { z } from 'zod';
|
|
18
18
|
import { streamSSE, stream } from 'hono/streaming';
|
|
19
|
-
import { createUIMessageStream, JsonToSseTransformStream,
|
|
19
|
+
import { createUIMessageStream, JsonToSseTransformStream, parsePartialJson, generateObject, tool, streamText, generateText, streamObject } from 'ai';
|
|
20
20
|
import { createAnthropic, anthropic } from '@ai-sdk/anthropic';
|
|
21
21
|
import { createGateway, gateway } from '@ai-sdk/gateway';
|
|
22
22
|
import { createGoogleGenerativeAI, google } from '@ai-sdk/google';
|
|
@@ -289,10 +289,10 @@ var extractContextFromTeamAgentToken = async (token, baseUrl, expectedSubAgentId
|
|
|
289
289
|
}
|
|
290
290
|
});
|
|
291
291
|
};
|
|
292
|
-
function setupOpenAPIRoutes(
|
|
293
|
-
|
|
292
|
+
function setupOpenAPIRoutes(app6) {
|
|
293
|
+
app6.get("/openapi.json", (c) => {
|
|
294
294
|
try {
|
|
295
|
-
const document =
|
|
295
|
+
const document = app6.getOpenAPIDocument({
|
|
296
296
|
openapi: "3.0.0",
|
|
297
297
|
info: {
|
|
298
298
|
title: "Inkeep Agents Run API",
|
|
@@ -313,7 +313,7 @@ function setupOpenAPIRoutes(app7) {
|
|
|
313
313
|
return c.json({ error: "Failed to generate OpenAPI document", details: errorDetails }, 500);
|
|
314
314
|
}
|
|
315
315
|
});
|
|
316
|
-
|
|
316
|
+
app6.get(
|
|
317
317
|
"/docs",
|
|
318
318
|
swaggerUI({
|
|
319
319
|
url: "/openapi.json",
|
|
@@ -664,7 +664,7 @@ async function handleMessageStream(c, agent, request) {
|
|
|
664
664
|
}
|
|
665
665
|
}
|
|
666
666
|
};
|
|
667
|
-
return streamSSE(c, async (
|
|
667
|
+
return streamSSE(c, async (stream2) => {
|
|
668
668
|
try {
|
|
669
669
|
const initialTask = {
|
|
670
670
|
id: task.id,
|
|
@@ -676,7 +676,7 @@ async function handleMessageStream(c, agent, request) {
|
|
|
676
676
|
artifacts: [],
|
|
677
677
|
kind: "task"
|
|
678
678
|
};
|
|
679
|
-
await
|
|
679
|
+
await stream2.writeSSE({
|
|
680
680
|
data: JSON.stringify({
|
|
681
681
|
jsonrpc: "2.0",
|
|
682
682
|
result: initialTask,
|
|
@@ -694,7 +694,7 @@ async function handleMessageStream(c, agent, request) {
|
|
|
694
694
|
(part) => part.kind === "data" && part.data && typeof part.data === "object" && part.data.type === "transfer"
|
|
695
695
|
);
|
|
696
696
|
if (transferPart && transferPart.kind === "data" && transferPart.data) {
|
|
697
|
-
await
|
|
697
|
+
await stream2.writeSSE({
|
|
698
698
|
data: JSON.stringify({
|
|
699
699
|
jsonrpc: "2.0",
|
|
700
700
|
result: {
|
|
@@ -728,7 +728,7 @@ async function handleMessageStream(c, agent, request) {
|
|
|
728
728
|
contextId: params.message.contextId,
|
|
729
729
|
kind: "message"
|
|
730
730
|
};
|
|
731
|
-
await
|
|
731
|
+
await stream2.writeSSE({
|
|
732
732
|
data: JSON.stringify({
|
|
733
733
|
jsonrpc: "2.0",
|
|
734
734
|
result: messageResponse,
|
|
@@ -743,7 +743,7 @@ async function handleMessageStream(c, agent, request) {
|
|
|
743
743
|
},
|
|
744
744
|
artifacts: result.artifacts
|
|
745
745
|
};
|
|
746
|
-
await
|
|
746
|
+
await stream2.writeSSE({
|
|
747
747
|
data: JSON.stringify({
|
|
748
748
|
jsonrpc: "2.0",
|
|
749
749
|
result: completedTask,
|
|
@@ -752,7 +752,7 @@ async function handleMessageStream(c, agent, request) {
|
|
|
752
752
|
});
|
|
753
753
|
} catch (error) {
|
|
754
754
|
console.error("Error in stream execution:", error);
|
|
755
|
-
await
|
|
755
|
+
await stream2.writeSSE({
|
|
756
756
|
data: JSON.stringify({
|
|
757
757
|
jsonrpc: "2.0",
|
|
758
758
|
error: {
|
|
@@ -884,7 +884,7 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
884
884
|
id: request.id
|
|
885
885
|
});
|
|
886
886
|
}
|
|
887
|
-
return streamSSE(c, async (
|
|
887
|
+
return streamSSE(c, async (stream2) => {
|
|
888
888
|
try {
|
|
889
889
|
const task = {
|
|
890
890
|
id: params.taskId,
|
|
@@ -896,7 +896,7 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
896
896
|
artifacts: [],
|
|
897
897
|
kind: "task"
|
|
898
898
|
};
|
|
899
|
-
await
|
|
899
|
+
await stream2.writeSSE({
|
|
900
900
|
data: JSON.stringify({
|
|
901
901
|
jsonrpc: "2.0",
|
|
902
902
|
result: task,
|
|
@@ -905,7 +905,7 @@ async function handleTasksResubscribe(c, agent, request) {
|
|
|
905
905
|
});
|
|
906
906
|
} catch (error) {
|
|
907
907
|
console.error("Error in task resubscription:", error);
|
|
908
|
-
await
|
|
908
|
+
await stream2.writeSSE({
|
|
909
909
|
data: JSON.stringify({
|
|
910
910
|
jsonrpc: "2.0",
|
|
911
911
|
error: {
|
|
@@ -8650,10 +8650,19 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8650
8650
|
subAgentId: relation.id
|
|
8651
8651
|
}
|
|
8652
8652
|
});
|
|
8653
|
-
const
|
|
8653
|
+
const relatedAgentTeamAgentRelations = await getTeamAgentsForSubAgent(dbClient_default)({
|
|
8654
|
+
scopes: {
|
|
8655
|
+
tenantId: config.tenantId,
|
|
8656
|
+
projectId: config.projectId,
|
|
8657
|
+
agentId: config.agentId,
|
|
8658
|
+
subAgentId: relation.id
|
|
8659
|
+
}
|
|
8660
|
+
});
|
|
8661
|
+
const enhancedDescription = generateDescriptionWithRelationData(
|
|
8654
8662
|
relation.description || "",
|
|
8655
8663
|
relatedAgentRelations.data,
|
|
8656
|
-
relatedAgentExternalAgentRelations.data
|
|
8664
|
+
relatedAgentExternalAgentRelations.data,
|
|
8665
|
+
relatedAgentTeamAgentRelations.data
|
|
8657
8666
|
);
|
|
8658
8667
|
return { ...relation, description: enhancedDescription };
|
|
8659
8668
|
}
|
|
@@ -8663,6 +8672,67 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8663
8672
|
return relation;
|
|
8664
8673
|
})
|
|
8665
8674
|
);
|
|
8675
|
+
const enhancedTeamRelations = await Promise.all(
|
|
8676
|
+
teamRelations.data.map(async (relation) => {
|
|
8677
|
+
try {
|
|
8678
|
+
const teamAgentWithDefault = await getAgentWithDefaultSubAgent(dbClient_default)({
|
|
8679
|
+
scopes: {
|
|
8680
|
+
tenantId: config.tenantId,
|
|
8681
|
+
projectId: config.projectId,
|
|
8682
|
+
agentId: relation.targetAgentId
|
|
8683
|
+
}
|
|
8684
|
+
});
|
|
8685
|
+
if (teamAgentWithDefault?.defaultSubAgent) {
|
|
8686
|
+
const defaultSubAgent = teamAgentWithDefault.defaultSubAgent;
|
|
8687
|
+
const relatedAgentRelations = await getRelatedAgentsForAgent(dbClient_default)({
|
|
8688
|
+
scopes: {
|
|
8689
|
+
tenantId: config.tenantId,
|
|
8690
|
+
projectId: config.projectId,
|
|
8691
|
+
agentId: relation.targetAgentId
|
|
8692
|
+
},
|
|
8693
|
+
subAgentId: defaultSubAgent.id
|
|
8694
|
+
});
|
|
8695
|
+
const relatedAgentExternalAgentRelations = await getExternalAgentsForSubAgent(
|
|
8696
|
+
dbClient_default
|
|
8697
|
+
)({
|
|
8698
|
+
scopes: {
|
|
8699
|
+
tenantId: config.tenantId,
|
|
8700
|
+
projectId: config.projectId,
|
|
8701
|
+
agentId: relation.targetAgentId,
|
|
8702
|
+
subAgentId: defaultSubAgent.id
|
|
8703
|
+
}
|
|
8704
|
+
});
|
|
8705
|
+
const relatedAgentTeamAgentRelations = await getTeamAgentsForSubAgent(dbClient_default)({
|
|
8706
|
+
scopes: {
|
|
8707
|
+
tenantId: config.tenantId,
|
|
8708
|
+
projectId: config.projectId,
|
|
8709
|
+
agentId: relation.targetAgentId,
|
|
8710
|
+
subAgentId: defaultSubAgent.id
|
|
8711
|
+
}
|
|
8712
|
+
});
|
|
8713
|
+
const enhancedDescription = generateDescriptionWithRelationData(
|
|
8714
|
+
teamAgentWithDefault.description || "",
|
|
8715
|
+
relatedAgentRelations.data,
|
|
8716
|
+
relatedAgentExternalAgentRelations.data,
|
|
8717
|
+
relatedAgentTeamAgentRelations.data
|
|
8718
|
+
);
|
|
8719
|
+
return {
|
|
8720
|
+
...relation,
|
|
8721
|
+
targetAgent: {
|
|
8722
|
+
...relation.targetAgent,
|
|
8723
|
+
description: enhancedDescription
|
|
8724
|
+
}
|
|
8725
|
+
};
|
|
8726
|
+
}
|
|
8727
|
+
} catch (error) {
|
|
8728
|
+
logger16.warn(
|
|
8729
|
+
{ targetAgentId: relation.targetAgentId, error },
|
|
8730
|
+
"Failed to enhance team agent description"
|
|
8731
|
+
);
|
|
8732
|
+
}
|
|
8733
|
+
return relation;
|
|
8734
|
+
})
|
|
8735
|
+
);
|
|
8666
8736
|
const prompt = "prompt" in config.agentSchema ? config.agentSchema.prompt : "";
|
|
8667
8737
|
const models = "models" in config.agentSchema ? config.agentSchema.models : void 0;
|
|
8668
8738
|
const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
|
|
@@ -8743,7 +8813,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8743
8813
|
relationType: "delegate"
|
|
8744
8814
|
}
|
|
8745
8815
|
})),
|
|
8746
|
-
...
|
|
8816
|
+
...enhancedTeamRelations.map((relation) => ({
|
|
8747
8817
|
type: "team",
|
|
8748
8818
|
config: {
|
|
8749
8819
|
id: relation.targetAgent.id,
|
|
@@ -9003,11 +9073,12 @@ function createAgentCard({
|
|
|
9003
9073
|
}
|
|
9004
9074
|
};
|
|
9005
9075
|
}
|
|
9006
|
-
function
|
|
9076
|
+
function generateDescriptionWithRelationData(baseDescription, internalRelations, externalRelations, teamRelations) {
|
|
9007
9077
|
const transfers = [...internalRelations.filter((rel) => rel.relationType === "transfer")];
|
|
9008
9078
|
const delegates = [
|
|
9009
9079
|
...internalRelations.filter((rel) => rel.relationType === "delegate"),
|
|
9010
|
-
...externalRelations.map((data) => data.externalAgent)
|
|
9080
|
+
...externalRelations.map((data) => data.externalAgent),
|
|
9081
|
+
...teamRelations.map((data) => data.targetAgent)
|
|
9011
9082
|
];
|
|
9012
9083
|
if (transfers.length === 0 && delegates.length === 0) {
|
|
9013
9084
|
return baseDescription;
|
|
@@ -9373,8 +9444,8 @@ async function executeTransfer({
|
|
|
9373
9444
|
return { success: true, targetSubAgentId };
|
|
9374
9445
|
}
|
|
9375
9446
|
var SSEStreamHelper = class {
|
|
9376
|
-
constructor(
|
|
9377
|
-
this.stream =
|
|
9447
|
+
constructor(stream2, requestId2, timestamp) {
|
|
9448
|
+
this.stream = stream2;
|
|
9378
9449
|
this.requestId = requestId2;
|
|
9379
9450
|
this.timestamp = timestamp;
|
|
9380
9451
|
__publicField(this, "isTextStreaming", false);
|
|
@@ -9540,8 +9611,8 @@ ${errorMessage}`);
|
|
|
9540
9611
|
await this.writeDone();
|
|
9541
9612
|
}
|
|
9542
9613
|
};
|
|
9543
|
-
function createSSEStreamHelper(
|
|
9544
|
-
return new SSEStreamHelper(
|
|
9614
|
+
function createSSEStreamHelper(stream2, requestId2, timestamp) {
|
|
9615
|
+
return new SSEStreamHelper(stream2, requestId2, timestamp);
|
|
9545
9616
|
}
|
|
9546
9617
|
var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
9547
9618
|
// 10 minutes max lifetime
|
|
@@ -9688,12 +9759,12 @@ var _VercelDataStreamHelper = class _VercelDataStreamHelper {
|
|
|
9688
9759
|
async streamData(data) {
|
|
9689
9760
|
await this.writeContent(JSON.stringify(data));
|
|
9690
9761
|
}
|
|
9691
|
-
async mergeStream(
|
|
9762
|
+
async mergeStream(stream2) {
|
|
9692
9763
|
if (this.isCompleted) {
|
|
9693
9764
|
console.warn("Attempted to merge stream to completed stream");
|
|
9694
9765
|
return;
|
|
9695
9766
|
}
|
|
9696
|
-
this.writer.merge(
|
|
9767
|
+
this.writer.merge(stream2);
|
|
9697
9768
|
}
|
|
9698
9769
|
/**
|
|
9699
9770
|
* Clean up all memory allocations
|
|
@@ -10631,9 +10702,9 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10631
10702
|
"database.operation": "insert"
|
|
10632
10703
|
});
|
|
10633
10704
|
}
|
|
10634
|
-
return streamSSE(c, async (
|
|
10705
|
+
return streamSSE(c, async (stream2) => {
|
|
10635
10706
|
try {
|
|
10636
|
-
const sseHelper = createSSEStreamHelper(
|
|
10707
|
+
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
10637
10708
|
await sseHelper.writeRole();
|
|
10638
10709
|
logger21.info({ subAgentId }, "Starting execution");
|
|
10639
10710
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
@@ -10670,7 +10741,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10670
10741
|
"Error during streaming execution"
|
|
10671
10742
|
);
|
|
10672
10743
|
try {
|
|
10673
|
-
const sseHelper = createSSEStreamHelper(
|
|
10744
|
+
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
10674
10745
|
await sseHelper.writeOperation(
|
|
10675
10746
|
errorOp(
|
|
10676
10747
|
"Sorry, I was unable to process your request at this time. Please try again.",
|
|
@@ -10894,7 +10965,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10894
10965
|
c.header("x-accel-buffering", "no");
|
|
10895
10966
|
return stream(
|
|
10896
10967
|
c,
|
|
10897
|
-
(
|
|
10968
|
+
(stream2) => stream2.pipe(
|
|
10898
10969
|
dataStream.pipeThrough(new JsonToSseTransformStream()).pipeThrough(new TextEncoderStream())
|
|
10899
10970
|
)
|
|
10900
10971
|
);
|
|
@@ -10908,249 +10979,10 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10908
10979
|
}
|
|
10909
10980
|
});
|
|
10910
10981
|
var chatDataStream_default = app3;
|
|
10911
|
-
var logger23 = getLogger("dataComponentPreview");
|
|
10912
|
-
var app4 = new OpenAPIHono();
|
|
10913
|
-
var generatePreviewRoute = createRoute({
|
|
10914
|
-
method: "post",
|
|
10915
|
-
path: "/:tenantId/projects/:projectId/data-components/:id/generate-render",
|
|
10916
|
-
tags: ["Data Component Preview"],
|
|
10917
|
-
summary: "Generate Component Render",
|
|
10918
|
-
description: "Generate a React/Tailwind component render using AI based on the data component schema",
|
|
10919
|
-
request: {
|
|
10920
|
-
params: z.object({
|
|
10921
|
-
tenantId: z.string(),
|
|
10922
|
-
projectId: z.string(),
|
|
10923
|
-
id: z.string()
|
|
10924
|
-
}),
|
|
10925
|
-
body: {
|
|
10926
|
-
content: {
|
|
10927
|
-
"application/json": {
|
|
10928
|
-
schema: z.object({
|
|
10929
|
-
instructions: z.string().optional().describe("Custom instructions for modifying the component"),
|
|
10930
|
-
existingCode: z.string().optional().describe("Existing component code to modify")
|
|
10931
|
-
})
|
|
10932
|
-
}
|
|
10933
|
-
}
|
|
10934
|
-
}
|
|
10935
|
-
},
|
|
10936
|
-
responses: {
|
|
10937
|
-
200: {
|
|
10938
|
-
description: "Streaming component code generation",
|
|
10939
|
-
headers: z.object({
|
|
10940
|
-
"Content-Type": z.string().default("text/plain; charset=utf-8"),
|
|
10941
|
-
"Cache-Control": z.string().default("no-cache"),
|
|
10942
|
-
Connection: z.string().default("keep-alive")
|
|
10943
|
-
}),
|
|
10944
|
-
content: {
|
|
10945
|
-
"text/plain": {
|
|
10946
|
-
schema: z.string().describe("Streaming generated component code")
|
|
10947
|
-
}
|
|
10948
|
-
}
|
|
10949
|
-
},
|
|
10950
|
-
...commonGetErrorResponses
|
|
10951
|
-
}
|
|
10952
|
-
});
|
|
10953
|
-
app4.openapi(generatePreviewRoute, async (c) => {
|
|
10954
|
-
const { tenantId, projectId, id } = c.req.valid("param");
|
|
10955
|
-
const body = c.req.valid("json");
|
|
10956
|
-
const { instructions, existingCode } = body;
|
|
10957
|
-
logger23.info(
|
|
10958
|
-
{
|
|
10959
|
-
tenantId,
|
|
10960
|
-
projectId,
|
|
10961
|
-
dataComponentId: id,
|
|
10962
|
-
hasInstructions: !!instructions,
|
|
10963
|
-
hasExistingCode: !!existingCode
|
|
10964
|
-
},
|
|
10965
|
-
"Generating component preview"
|
|
10966
|
-
);
|
|
10967
|
-
const dataComponent = await getDataComponent(dbClient_default)({
|
|
10968
|
-
scopes: { tenantId, projectId },
|
|
10969
|
-
dataComponentId: id
|
|
10970
|
-
});
|
|
10971
|
-
if (!dataComponent) {
|
|
10972
|
-
throw createApiError({
|
|
10973
|
-
code: "not_found",
|
|
10974
|
-
message: "Data component not found"
|
|
10975
|
-
});
|
|
10976
|
-
}
|
|
10977
|
-
const project = await getProject(dbClient_default)({
|
|
10978
|
-
scopes: { tenantId, projectId }
|
|
10979
|
-
});
|
|
10980
|
-
if (!project?.models?.base) {
|
|
10981
|
-
throw createApiError({
|
|
10982
|
-
code: "bad_request",
|
|
10983
|
-
message: "Project base model configuration is required"
|
|
10984
|
-
});
|
|
10985
|
-
}
|
|
10986
|
-
const prompt = buildGenerationPrompt(dataComponent, instructions, existingCode);
|
|
10987
|
-
try {
|
|
10988
|
-
const modelConfig = ModelFactory.prepareGenerationConfig(project.models.base);
|
|
10989
|
-
const renderSchema = z.object({
|
|
10990
|
-
component: z.string().describe("The React component code"),
|
|
10991
|
-
mockData: z.any().describe("Sample data matching the props schema")
|
|
10992
|
-
});
|
|
10993
|
-
const result = streamObject({
|
|
10994
|
-
...modelConfig,
|
|
10995
|
-
prompt,
|
|
10996
|
-
schema: renderSchema,
|
|
10997
|
-
temperature: 0.7
|
|
10998
|
-
});
|
|
10999
|
-
c.header("Content-Type", "text/plain; charset=utf-8");
|
|
11000
|
-
c.header("Cache-Control", "no-cache");
|
|
11001
|
-
c.header("Connection", "keep-alive");
|
|
11002
|
-
const existingData = existingCode && dataComponent.render && typeof dataComponent.render === "object" && "mockData" in dataComponent.render ? dataComponent.render.mockData : null;
|
|
11003
|
-
return stream(c, async (stream3) => {
|
|
11004
|
-
try {
|
|
11005
|
-
for await (const partialObject of result.partialObjectStream) {
|
|
11006
|
-
const outputObject = instructions && existingData ? { ...partialObject, mockData: existingData } : partialObject;
|
|
11007
|
-
await stream3.write(JSON.stringify(outputObject) + "\n");
|
|
11008
|
-
}
|
|
11009
|
-
} catch (error) {
|
|
11010
|
-
logger23.error(
|
|
11011
|
-
{ error, tenantId, projectId, dataComponentId: id },
|
|
11012
|
-
"Error streaming preview generation"
|
|
11013
|
-
);
|
|
11014
|
-
await stream3.write(
|
|
11015
|
-
JSON.stringify({ component: "// Error generating component preview", mockData: {} }) + "\n"
|
|
11016
|
-
);
|
|
11017
|
-
}
|
|
11018
|
-
});
|
|
11019
|
-
} catch (error) {
|
|
11020
|
-
logger23.error(
|
|
11021
|
-
{ error, tenantId, projectId, dataComponentId: id },
|
|
11022
|
-
"Error generating component preview"
|
|
11023
|
-
);
|
|
11024
|
-
throw createApiError({
|
|
11025
|
-
code: "internal_server_error",
|
|
11026
|
-
message: "Failed to generate component preview"
|
|
11027
|
-
});
|
|
11028
|
-
}
|
|
11029
|
-
});
|
|
11030
|
-
function buildGenerationPrompt(dataComponent, instructions, existingCode) {
|
|
11031
|
-
const propsSchema = dataComponent.props || {};
|
|
11032
|
-
const propsJson = JSON.stringify(propsSchema, null, 2);
|
|
11033
|
-
const componentName = sanitizeComponentName(dataComponent.name);
|
|
11034
|
-
if (instructions && existingCode) {
|
|
11035
|
-
return `You are an expert React and Tailwind CSS developer. You need to modify an existing React component based on specific instructions.
|
|
11036
|
-
|
|
11037
|
-
COMPONENT DETAILS:
|
|
11038
|
-
- Original Name: ${dataComponent.name}
|
|
11039
|
-
- Component Function Name: ${componentName}
|
|
11040
|
-
- Description: ${dataComponent.description}
|
|
11041
|
-
- Props Schema (JSON Schema): ${propsJson}
|
|
11042
|
-
|
|
11043
|
-
EXISTING COMPONENT CODE:
|
|
11044
|
-
\`\`\`jsx
|
|
11045
|
-
${existingCode}
|
|
11046
|
-
\`\`\`
|
|
11047
|
-
|
|
11048
|
-
MODIFICATION INSTRUCTIONS:
|
|
11049
|
-
${instructions}
|
|
11050
|
-
|
|
11051
|
-
REQUIREMENTS:
|
|
11052
|
-
1. Modify the existing component code according to the instructions
|
|
11053
|
-
2. Keep using Tailwind CSS SEMANTIC COLOR CLASSES (bg-background, text-foreground, etc.)
|
|
11054
|
-
3. Maintain the balanced spacing and design principles from the original
|
|
11055
|
-
4. Keep using lucide-react icons where appropriate
|
|
11056
|
-
5. DO NOT include export statements - just the imports and function
|
|
11057
|
-
6. DO NOT include TypeScript type annotations
|
|
11058
|
-
7. Component name should remain: ${componentName}
|
|
11059
|
-
8. DO NOT regenerate sample data - keep the same data structure
|
|
11060
|
-
|
|
11061
|
-
OUTPUT FORMAT:
|
|
11062
|
-
You need to generate only one thing:
|
|
11063
|
-
1. "component": The modified React component code as a string
|
|
11064
|
-
|
|
11065
|
-
Return ONLY the component field, the mockData field will be reused from the existing render.
|
|
11066
|
-
|
|
11067
|
-
EXAMPLE OUTPUT:
|
|
11068
|
-
{
|
|
11069
|
-
"component": "import { Mail, User } from 'lucide-react';\\n\\nfunction ${componentName}(props) {\\n // Modified component code here\\n}"
|
|
11070
|
-
}
|
|
11071
|
-
|
|
11072
|
-
Focus on making the requested changes while maintaining the component's quality and design principles.`;
|
|
11073
|
-
}
|
|
11074
|
-
return `You are an expert React and Tailwind CSS developer. Generate a beautiful, modern React component for displaying data and sample data to preview it.
|
|
11075
|
-
|
|
11076
|
-
COMPONENT DETAILS:
|
|
11077
|
-
- Original Name: ${dataComponent.name}
|
|
11078
|
-
- Component Function Name: ${componentName}
|
|
11079
|
-
- Description: ${dataComponent.description}
|
|
11080
|
-
- Props Schema (JSON Schema): ${propsJson}
|
|
11081
|
-
|
|
11082
|
-
REQUIREMENTS:
|
|
11083
|
-
1. Create a React functional component (JSX, not TypeScript)
|
|
11084
|
-
2. Use Tailwind CSS SEMANTIC COLOR CLASSES (these automatically adapt to light/dark mode):
|
|
11085
|
-
- Background: bg-background, bg-card, bg-muted, bg-muted/40, bg-accent, bg-primary
|
|
11086
|
-
- Text: text-foreground, text-muted-foreground, text-card-foreground, text-primary-foreground
|
|
11087
|
-
- Borders: border-border, border-input, border-muted
|
|
11088
|
-
- DO NOT use direct colors like bg-white, bg-gray-800, text-gray-900, etc.
|
|
11089
|
-
- DO NOT use dark: prefix - semantic classes handle dark mode automatically
|
|
11090
|
-
3. Make it balanced - comfortable but efficient:
|
|
11091
|
-
- Use moderate padding: p-4, px-4 py-3 (balanced, not cramped or excessive)
|
|
11092
|
-
- Use appropriate text sizes: text-sm for body, text-base for headings, text-xs for captions
|
|
11093
|
-
- Use balanced spacing: gap-2.5, gap-3, space-y-2, mt-2, mb-3
|
|
11094
|
-
- Aim for a clean, professional look with good readability
|
|
11095
|
-
4. Design for embedding - this component blends into existing content:
|
|
11096
|
-
- DO NOT add redundant titles or headers unless they're part of the actual data schema
|
|
11097
|
-
- Focus on displaying the data directly and elegantly
|
|
11098
|
-
- Assume the component is part of a larger conversation or content flow
|
|
11099
|
-
- If the schema has a "title" or "name" property, display it as data, not as a wrapper heading
|
|
11100
|
-
5. Use LUCIDE-REACT ICONS to enhance UI aesthetics:
|
|
11101
|
-
- Import icons from lucide-react: import { User, Mail, Clock } from 'lucide-react'
|
|
11102
|
-
- Use icons with size-4 or size-5 classes for balanced visibility
|
|
11103
|
-
- Place icons inline with text or as visual indicators
|
|
11104
|
-
- Example: <User className="size-4" /> or <Mail className="size-4 text-muted-foreground" />
|
|
11105
|
-
- Common useful icons: User, Mail, Calendar, Clock, Check, X, Star, Heart, Settings, Search, etc.
|
|
11106
|
-
6. The component should accept props that match the JSON Schema properties
|
|
11107
|
-
7. Make it visually appealing and professional - clean with good whitespace
|
|
11108
|
-
8. Use semantic HTML elements
|
|
11109
|
-
9. Make it responsive and accessible
|
|
11110
|
-
10. You can import icons from 'lucide-react' at the top
|
|
11111
|
-
11. DO NOT include export statements - just the imports and function
|
|
11112
|
-
12. DO NOT include TypeScript type annotations
|
|
11113
|
-
13. Component name should be exactly: ${componentName}
|
|
11114
|
-
|
|
11115
|
-
AVAILABLE SEMANTIC COLOR CLASSES:
|
|
11116
|
-
- Backgrounds: bg-background, bg-foreground, bg-card, bg-popover, bg-primary, bg-secondary, bg-muted, bg-accent, bg-destructive
|
|
11117
|
-
- Text: text-foreground, text-background, text-card-foreground, text-popover-foreground, text-primary-foreground, text-secondary-foreground, text-muted-foreground, text-accent-foreground, text-destructive
|
|
11118
|
-
- Borders: border-border, border-input, border-ring
|
|
11119
|
-
- You can use opacity modifiers: bg-muted/40, bg-accent/10, etc.
|
|
11120
|
-
|
|
11121
|
-
OUTPUT FORMAT:
|
|
11122
|
-
You need to generate two things:
|
|
11123
|
-
1. "component": The complete React component code as a string
|
|
11124
|
-
2. "mockData": Realistic sample data that matches the props schema (as a JSON object)
|
|
11125
|
-
|
|
11126
|
-
EXAMPLE OUTPUT (for a user profile schema with name, email, role):
|
|
11127
|
-
{
|
|
11128
|
-
"component": "import { Mail, User } from 'lucide-react';\\n\\nfunction ${componentName}(props) {\\n return (\\n <div className=\\"p-4 rounded-lg border border-border bg-card\\">\\n <div className=\\"flex items-center gap-2.5 mb-2\\">\\n <User className=\\"size-4 text-muted-foreground\\" />\\n <span className=\\"text-base font-medium text-foreground\\">{props.name}</span>\\n </div>\\n <div className=\\"flex items-center gap-2 text-sm text-muted-foreground\\">\\n <Mail className=\\"size-4\\" />\\n <span>{props.email}</span>\\n </div>\\n <div className=\\"text-xs text-muted-foreground mt-2\\">Role: {props.role}</div>\\n </div>\\n );\\n}",
|
|
11129
|
-
"mockData": {
|
|
11130
|
-
"name": "Sarah Chen",
|
|
11131
|
-
"email": "sarah.chen@example.com",
|
|
11132
|
-
"role": "Product Manager"
|
|
11133
|
-
}
|
|
11134
|
-
}
|
|
11135
|
-
|
|
11136
|
-
REMEMBER:
|
|
11137
|
-
- ONLY use semantic color classes (bg-card, text-foreground, etc.)
|
|
11138
|
-
- NO direct colors (bg-white, text-gray-900, etc.)
|
|
11139
|
-
- NO dark: prefix needed - semantic classes adapt automatically
|
|
11140
|
-
- Use balanced spacing (p-4, gap-2.5/gap-3, text-sm for body, text-base for headings)
|
|
11141
|
-
- Use lucide-react icons where appropriate for better UI
|
|
11142
|
-
- NO redundant titles - just display the actual data from props
|
|
11143
|
-
- Design for embedding - this blends into existing content, not a standalone card
|
|
11144
|
-
- Make the sample data realistic and useful for previewing the component`;
|
|
11145
|
-
}
|
|
11146
|
-
function sanitizeComponentName(name) {
|
|
11147
|
-
return name.split(/\s+/).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
11148
|
-
}
|
|
11149
|
-
var dataComponentPreview_default = app4;
|
|
11150
10982
|
function createMCPSchema(schema) {
|
|
11151
10983
|
return schema;
|
|
11152
10984
|
}
|
|
11153
|
-
var
|
|
10985
|
+
var logger23 = getLogger("mcp");
|
|
11154
10986
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
11155
10987
|
constructor() {
|
|
11156
10988
|
__publicField(this, "mockRes");
|
|
@@ -11205,21 +11037,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
11205
11037
|
id: 0
|
|
11206
11038
|
});
|
|
11207
11039
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
11208
|
-
|
|
11040
|
+
logger23.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
11209
11041
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
11210
11042
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
11211
11043
|
try {
|
|
11212
11044
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
11213
|
-
|
|
11045
|
+
logger23.info({ sessionId }, "Successfully spoofed initialization");
|
|
11214
11046
|
} catch (spoofError) {
|
|
11215
|
-
|
|
11047
|
+
logger23.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
11216
11048
|
}
|
|
11217
11049
|
};
|
|
11218
11050
|
var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
11219
11051
|
const sessionId = req.headers["mcp-session-id"];
|
|
11220
|
-
|
|
11052
|
+
logger23.info({ sessionId }, "Received MCP session ID");
|
|
11221
11053
|
if (!sessionId) {
|
|
11222
|
-
|
|
11054
|
+
logger23.info({ body }, "Missing session ID");
|
|
11223
11055
|
res.writeHead(400).end(
|
|
11224
11056
|
JSON.stringify({
|
|
11225
11057
|
jsonrpc: "2.0",
|
|
@@ -11245,7 +11077,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
|
11245
11077
|
scopes: { tenantId, projectId },
|
|
11246
11078
|
conversationId: sessionId
|
|
11247
11079
|
});
|
|
11248
|
-
|
|
11080
|
+
logger23.info(
|
|
11249
11081
|
{
|
|
11250
11082
|
sessionId,
|
|
11251
11083
|
conversationFound: !!conversation,
|
|
@@ -11256,7 +11088,7 @@ var validateSession = async (req, res, body, tenantId, projectId, agentId) => {
|
|
|
11256
11088
|
"Conversation lookup result"
|
|
11257
11089
|
);
|
|
11258
11090
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.agentId !== agentId) {
|
|
11259
|
-
|
|
11091
|
+
logger23.info(
|
|
11260
11092
|
{ sessionId, conversationId: conversation?.id },
|
|
11261
11093
|
"MCP session not found or invalid"
|
|
11262
11094
|
);
|
|
@@ -11317,7 +11149,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultS
|
|
|
11317
11149
|
requestId: requestId2,
|
|
11318
11150
|
sseHelper: mcpStreamHelper
|
|
11319
11151
|
});
|
|
11320
|
-
|
|
11152
|
+
logger23.info(
|
|
11321
11153
|
{ result },
|
|
11322
11154
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
11323
11155
|
);
|
|
@@ -11401,7 +11233,7 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
|
|
|
11401
11233
|
dbClient: dbClient_default,
|
|
11402
11234
|
credentialStores
|
|
11403
11235
|
});
|
|
11404
|
-
|
|
11236
|
+
logger23.info(
|
|
11405
11237
|
{
|
|
11406
11238
|
tenantId,
|
|
11407
11239
|
projectId,
|
|
@@ -11430,8 +11262,8 @@ var getServer = async (headers2, executionContext, conversationId, credentialSto
|
|
|
11430
11262
|
);
|
|
11431
11263
|
return server;
|
|
11432
11264
|
};
|
|
11433
|
-
var
|
|
11434
|
-
|
|
11265
|
+
var app4 = new OpenAPIHono();
|
|
11266
|
+
app4.use("/", async (c, next) => {
|
|
11435
11267
|
if (c.req.method === "POST") {
|
|
11436
11268
|
return contextValidationMiddleware(dbClient_default)(c, next);
|
|
11437
11269
|
}
|
|
@@ -11463,7 +11295,7 @@ var validateRequestParameters = (c) => {
|
|
|
11463
11295
|
};
|
|
11464
11296
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
11465
11297
|
const { tenantId, projectId, agentId } = executionContext;
|
|
11466
|
-
|
|
11298
|
+
logger23.info({ body }, "Received initialization request");
|
|
11467
11299
|
const sessionId = getConversationId();
|
|
11468
11300
|
const activeSpan = trace.getActiveSpan();
|
|
11469
11301
|
if (activeSpan) {
|
|
@@ -11519,7 +11351,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11519
11351
|
}
|
|
11520
11352
|
}
|
|
11521
11353
|
});
|
|
11522
|
-
|
|
11354
|
+
logger23.info(
|
|
11523
11355
|
{ sessionId, conversationId: conversation.id },
|
|
11524
11356
|
"Created MCP session as conversation"
|
|
11525
11357
|
);
|
|
@@ -11528,9 +11360,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11528
11360
|
});
|
|
11529
11361
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
11530
11362
|
await server.connect(transport);
|
|
11531
|
-
|
|
11363
|
+
logger23.info({ sessionId }, "Server connected for initialization");
|
|
11532
11364
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
11533
|
-
|
|
11365
|
+
logger23.info(
|
|
11534
11366
|
{
|
|
11535
11367
|
sessionId,
|
|
11536
11368
|
bodyMethod: body?.method,
|
|
@@ -11539,7 +11371,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
11539
11371
|
"About to handle initialization request"
|
|
11540
11372
|
);
|
|
11541
11373
|
await transport.handleRequest(req, res, body);
|
|
11542
|
-
|
|
11374
|
+
logger23.info({ sessionId }, "Successfully handled initialization request");
|
|
11543
11375
|
return toFetchResponse(res);
|
|
11544
11376
|
});
|
|
11545
11377
|
};
|
|
@@ -11566,8 +11398,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11566
11398
|
sessionId,
|
|
11567
11399
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
11568
11400
|
);
|
|
11569
|
-
|
|
11570
|
-
|
|
11401
|
+
logger23.info({ sessionId }, "Server connected and transport initialized");
|
|
11402
|
+
logger23.info(
|
|
11571
11403
|
{
|
|
11572
11404
|
sessionId,
|
|
11573
11405
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -11581,9 +11413,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
11581
11413
|
);
|
|
11582
11414
|
try {
|
|
11583
11415
|
await transport.handleRequest(req, res, body);
|
|
11584
|
-
|
|
11416
|
+
logger23.info({ sessionId }, "Successfully handled MCP request");
|
|
11585
11417
|
} catch (transportError) {
|
|
11586
|
-
|
|
11418
|
+
logger23.error(
|
|
11587
11419
|
{
|
|
11588
11420
|
sessionId,
|
|
11589
11421
|
error: transportError,
|
|
@@ -11600,7 +11432,7 @@ var createErrorResponse = (code, message, id = null) => ({
|
|
|
11600
11432
|
error: { code, message },
|
|
11601
11433
|
id
|
|
11602
11434
|
});
|
|
11603
|
-
|
|
11435
|
+
app4.openapi(
|
|
11604
11436
|
createRoute({
|
|
11605
11437
|
method: "post",
|
|
11606
11438
|
path: "/",
|
|
@@ -11634,13 +11466,13 @@ app5.openapi(
|
|
|
11634
11466
|
}
|
|
11635
11467
|
const { executionContext } = paramValidation;
|
|
11636
11468
|
const body = c.get("requestBody") || {};
|
|
11637
|
-
|
|
11469
|
+
logger23.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
11638
11470
|
const isInitRequest = body.method === "initialize";
|
|
11639
11471
|
const { req, res } = toReqRes(c.req.raw);
|
|
11640
11472
|
const validatedContext = c.get("validatedContext") || {};
|
|
11641
11473
|
const credentialStores = c.get("credentialStores");
|
|
11642
|
-
|
|
11643
|
-
|
|
11474
|
+
logger23.info({ validatedContext }, "Validated context");
|
|
11475
|
+
logger23.info({ req }, "request");
|
|
11644
11476
|
if (isInitRequest) {
|
|
11645
11477
|
return await handleInitializationRequest(
|
|
11646
11478
|
body,
|
|
@@ -11662,7 +11494,7 @@ app5.openapi(
|
|
|
11662
11494
|
);
|
|
11663
11495
|
}
|
|
11664
11496
|
} catch (e) {
|
|
11665
|
-
|
|
11497
|
+
logger23.error(
|
|
11666
11498
|
{
|
|
11667
11499
|
error: e instanceof Error ? e.message : e,
|
|
11668
11500
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -11673,8 +11505,8 @@ app5.openapi(
|
|
|
11673
11505
|
}
|
|
11674
11506
|
}
|
|
11675
11507
|
);
|
|
11676
|
-
|
|
11677
|
-
|
|
11508
|
+
app4.get("/", async (c) => {
|
|
11509
|
+
logger23.info({}, "Received GET MCP request");
|
|
11678
11510
|
return c.json(
|
|
11679
11511
|
{
|
|
11680
11512
|
jsonrpc: "2.0",
|
|
@@ -11687,8 +11519,8 @@ app5.get("/", async (c) => {
|
|
|
11687
11519
|
{ status: 405 }
|
|
11688
11520
|
);
|
|
11689
11521
|
});
|
|
11690
|
-
|
|
11691
|
-
|
|
11522
|
+
app4.delete("/", async (c) => {
|
|
11523
|
+
logger23.info({}, "Received DELETE MCP request");
|
|
11692
11524
|
return c.json(
|
|
11693
11525
|
{
|
|
11694
11526
|
jsonrpc: "2.0",
|
|
@@ -11698,15 +11530,15 @@ app5.delete("/", async (c) => {
|
|
|
11698
11530
|
{ status: 405 }
|
|
11699
11531
|
);
|
|
11700
11532
|
});
|
|
11701
|
-
var mcp_default =
|
|
11533
|
+
var mcp_default = app4;
|
|
11702
11534
|
|
|
11703
11535
|
// src/app.ts
|
|
11704
|
-
var
|
|
11536
|
+
var logger24 = getLogger("agents-run-api");
|
|
11705
11537
|
function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
11706
|
-
const
|
|
11707
|
-
|
|
11708
|
-
|
|
11709
|
-
|
|
11538
|
+
const app6 = new OpenAPIHono();
|
|
11539
|
+
app6.use("*", otel());
|
|
11540
|
+
app6.use("*", requestId());
|
|
11541
|
+
app6.use("*", async (c, next) => {
|
|
11710
11542
|
c.set("serverConfig", serverConfig);
|
|
11711
11543
|
c.set("credentialStores", credentialStores);
|
|
11712
11544
|
if (sandboxConfig) {
|
|
@@ -11714,18 +11546,18 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11714
11546
|
}
|
|
11715
11547
|
return next();
|
|
11716
11548
|
});
|
|
11717
|
-
|
|
11549
|
+
app6.use("*", async (c, next) => {
|
|
11718
11550
|
if (c.req.header("content-type")?.includes("application/json")) {
|
|
11719
11551
|
try {
|
|
11720
11552
|
const body = await c.req.json();
|
|
11721
11553
|
c.set("requestBody", body);
|
|
11722
11554
|
} catch (error) {
|
|
11723
|
-
|
|
11555
|
+
logger24.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
11724
11556
|
}
|
|
11725
11557
|
}
|
|
11726
11558
|
return next();
|
|
11727
11559
|
});
|
|
11728
|
-
|
|
11560
|
+
app6.use("*", async (c, next) => {
|
|
11729
11561
|
const reqId = c.get("requestId");
|
|
11730
11562
|
let bag = propagation.getBaggage(context.active());
|
|
11731
11563
|
if (!bag) {
|
|
@@ -11738,7 +11570,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11738
11570
|
}
|
|
11739
11571
|
return next();
|
|
11740
11572
|
});
|
|
11741
|
-
|
|
11573
|
+
app6.onError(async (err, c) => {
|
|
11742
11574
|
const isExpectedError = err instanceof HTTPException;
|
|
11743
11575
|
const status = isExpectedError ? err.status : 500;
|
|
11744
11576
|
const requestId2 = c.get("requestId") || "unknown";
|
|
@@ -11771,8 +11603,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11771
11603
|
if (!isExpectedError) {
|
|
11772
11604
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
11773
11605
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
11774
|
-
if (
|
|
11775
|
-
|
|
11606
|
+
if (logger24) {
|
|
11607
|
+
logger24.error(
|
|
11776
11608
|
{
|
|
11777
11609
|
error: err,
|
|
11778
11610
|
message: errorMessage,
|
|
@@ -11784,8 +11616,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11784
11616
|
);
|
|
11785
11617
|
}
|
|
11786
11618
|
} else {
|
|
11787
|
-
if (
|
|
11788
|
-
|
|
11619
|
+
if (logger24) {
|
|
11620
|
+
logger24.error(
|
|
11789
11621
|
{
|
|
11790
11622
|
error: err,
|
|
11791
11623
|
path: c.req.path,
|
|
@@ -11802,8 +11634,8 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11802
11634
|
const response = err.getResponse();
|
|
11803
11635
|
return response;
|
|
11804
11636
|
} catch (responseError) {
|
|
11805
|
-
if (
|
|
11806
|
-
|
|
11637
|
+
if (logger24) {
|
|
11638
|
+
logger24.error({ error: responseError }, "Error while handling HTTPException response");
|
|
11807
11639
|
}
|
|
11808
11640
|
}
|
|
11809
11641
|
}
|
|
@@ -11819,7 +11651,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11819
11651
|
...instance && { instance }
|
|
11820
11652
|
});
|
|
11821
11653
|
});
|
|
11822
|
-
|
|
11654
|
+
app6.use(
|
|
11823
11655
|
"*",
|
|
11824
11656
|
cors({
|
|
11825
11657
|
origin: "*",
|
|
@@ -11830,14 +11662,14 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11830
11662
|
maxAge: 86400
|
|
11831
11663
|
})
|
|
11832
11664
|
);
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
|
|
11837
|
-
|
|
11665
|
+
app6.use("/tenants/*", apiKeyAuth());
|
|
11666
|
+
app6.use("/agents/*", apiKeyAuth());
|
|
11667
|
+
app6.use("/v1/*", apiKeyAuth());
|
|
11668
|
+
app6.use("/api/*", apiKeyAuth());
|
|
11669
|
+
app6.use("*", async (c, next) => {
|
|
11838
11670
|
const executionContext = c.get("executionContext");
|
|
11839
11671
|
if (!executionContext) {
|
|
11840
|
-
|
|
11672
|
+
logger24.debug({}, "Empty execution context");
|
|
11841
11673
|
return next();
|
|
11842
11674
|
}
|
|
11843
11675
|
const { tenantId, projectId, agentId } = executionContext;
|
|
@@ -11846,7 +11678,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11846
11678
|
if (requestBody) {
|
|
11847
11679
|
conversationId = requestBody.conversationId;
|
|
11848
11680
|
if (!conversationId) {
|
|
11849
|
-
|
|
11681
|
+
logger24.debug({ requestBody }, "No conversation ID found in request body");
|
|
11850
11682
|
}
|
|
11851
11683
|
}
|
|
11852
11684
|
const entries = Object.fromEntries(
|
|
@@ -11861,7 +11693,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11861
11693
|
})
|
|
11862
11694
|
);
|
|
11863
11695
|
if (!Object.keys(entries).length) {
|
|
11864
|
-
|
|
11696
|
+
logger24.debug({}, "Empty entries for baggage");
|
|
11865
11697
|
return next();
|
|
11866
11698
|
}
|
|
11867
11699
|
const bag = Object.entries(entries).reduce(
|
|
@@ -11871,7 +11703,7 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11871
11703
|
const ctxWithBag = propagation.setBaggage(context.active(), bag);
|
|
11872
11704
|
return await context.with(ctxWithBag, async () => await next());
|
|
11873
11705
|
});
|
|
11874
|
-
|
|
11706
|
+
app6.openapi(
|
|
11875
11707
|
createRoute({
|
|
11876
11708
|
method: "get",
|
|
11877
11709
|
path: "/health",
|
|
@@ -11888,30 +11720,29 @@ function createExecutionHono(serverConfig, credentialStores, sandboxConfig) {
|
|
|
11888
11720
|
return c.body(null, 204);
|
|
11889
11721
|
}
|
|
11890
11722
|
);
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
app7.use("/tenants/*", async (_c, next) => {
|
|
11723
|
+
app6.route("/v1/chat", chat_default);
|
|
11724
|
+
app6.route("/api", chatDataStream_default);
|
|
11725
|
+
app6.route("/v1/mcp", mcp_default);
|
|
11726
|
+
app6.route("/agents", agents_default);
|
|
11727
|
+
setupOpenAPIRoutes(app6);
|
|
11728
|
+
app6.use("/tenants/*", async (_c, next) => {
|
|
11898
11729
|
await next();
|
|
11899
11730
|
await flushBatchProcessor();
|
|
11900
11731
|
});
|
|
11901
|
-
|
|
11732
|
+
app6.use("/agents/*", async (_c, next) => {
|
|
11902
11733
|
await next();
|
|
11903
11734
|
await flushBatchProcessor();
|
|
11904
11735
|
});
|
|
11905
|
-
|
|
11736
|
+
app6.use("/v1/*", async (_c, next) => {
|
|
11906
11737
|
await next();
|
|
11907
11738
|
await flushBatchProcessor();
|
|
11908
11739
|
});
|
|
11909
|
-
|
|
11740
|
+
app6.use("/api/*", async (_c, next) => {
|
|
11910
11741
|
await next();
|
|
11911
11742
|
await flushBatchProcessor();
|
|
11912
11743
|
});
|
|
11913
11744
|
const baseApp = new Hono();
|
|
11914
|
-
baseApp.route("/",
|
|
11745
|
+
baseApp.route("/", app6);
|
|
11915
11746
|
return baseApp;
|
|
11916
11747
|
}
|
|
11917
11748
|
|
|
@@ -11927,8 +11758,8 @@ var defaultConfig = {
|
|
|
11927
11758
|
};
|
|
11928
11759
|
var defaultStores = createDefaultCredentialStores();
|
|
11929
11760
|
var defaultRegistry = new CredentialStoreRegistry(defaultStores);
|
|
11930
|
-
var
|
|
11931
|
-
var index_default =
|
|
11761
|
+
var app5 = createExecutionHono(defaultConfig, defaultRegistry);
|
|
11762
|
+
var index_default = app5;
|
|
11932
11763
|
function createExecutionApp(config) {
|
|
11933
11764
|
const serverConfig = config?.serverConfig ?? defaultConfig;
|
|
11934
11765
|
const stores = config?.credentialStores ?? defaultStores;
|