@inkeep/agents-run-api 0.0.0-dev-20251008182848 → 0.0.0-dev-20251008200151
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 +910 -573
- package/dist/index.js +775 -442
- package/package.json +2 -2
- package/templates/v1/shared/artifact.xml +1 -0
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var agentsCore = require('@inkeep/agents-core');
|
|
6
|
-
var
|
|
6
|
+
var z6 = require('zod');
|
|
7
7
|
var nanoid = require('nanoid');
|
|
8
8
|
var otel = require('@hono/otel');
|
|
9
9
|
var zodOpenapi = require('@hono/zod-openapi');
|
|
@@ -31,6 +31,7 @@ var google = require('@ai-sdk/google');
|
|
|
31
31
|
var openai = require('@ai-sdk/openai');
|
|
32
32
|
var aiSdkProvider = require('@openrouter/ai-sdk-provider');
|
|
33
33
|
var jmespath = require('jmespath');
|
|
34
|
+
var Ajv = require('ajv');
|
|
34
35
|
var destr = require('destr');
|
|
35
36
|
var traverse = require('traverse');
|
|
36
37
|
var mcp_js = require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
@@ -40,8 +41,9 @@ var fetchToNode = require('fetch-to-node');
|
|
|
40
41
|
|
|
41
42
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
42
43
|
|
|
43
|
-
var
|
|
44
|
+
var z6__default = /*#__PURE__*/_interopDefault(z6);
|
|
44
45
|
var jmespath__default = /*#__PURE__*/_interopDefault(jmespath);
|
|
46
|
+
var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
45
47
|
var destr__default = /*#__PURE__*/_interopDefault(destr);
|
|
46
48
|
var traverse__default = /*#__PURE__*/_interopDefault(traverse);
|
|
47
49
|
|
|
@@ -60,27 +62,27 @@ var envSchema, parseEnv, env;
|
|
|
60
62
|
var init_env = __esm({
|
|
61
63
|
"src/env.ts"() {
|
|
62
64
|
agentsCore.loadEnvironmentFiles();
|
|
63
|
-
envSchema =
|
|
64
|
-
NODE_ENV:
|
|
65
|
-
ENVIRONMENT:
|
|
66
|
-
DB_FILE_NAME:
|
|
67
|
-
TURSO_DATABASE_URL:
|
|
68
|
-
TURSO_AUTH_TOKEN:
|
|
69
|
-
AGENTS_RUN_API_URL:
|
|
70
|
-
LOG_LEVEL:
|
|
71
|
-
NANGO_SECRET_KEY:
|
|
72
|
-
OPENAI_API_KEY:
|
|
73
|
-
ANTHROPIC_API_KEY:
|
|
74
|
-
INKEEP_AGENTS_RUN_API_BYPASS_SECRET:
|
|
75
|
-
OTEL_BSP_SCHEDULE_DELAY:
|
|
76
|
-
OTEL_BSP_MAX_EXPORT_BATCH_SIZE:
|
|
65
|
+
envSchema = z6.z.object({
|
|
66
|
+
NODE_ENV: z6.z.enum(["development", "production", "test"]).optional(),
|
|
67
|
+
ENVIRONMENT: z6.z.enum(["development", "production", "pentest", "test"]).optional().default("development"),
|
|
68
|
+
DB_FILE_NAME: z6.z.string().optional(),
|
|
69
|
+
TURSO_DATABASE_URL: z6.z.string().optional(),
|
|
70
|
+
TURSO_AUTH_TOKEN: z6.z.string().optional(),
|
|
71
|
+
AGENTS_RUN_API_URL: z6.z.string().optional().default("http://localhost:3003"),
|
|
72
|
+
LOG_LEVEL: z6.z.enum(["trace", "debug", "info", "warn", "error"]).optional().default("debug"),
|
|
73
|
+
NANGO_SECRET_KEY: z6.z.string().optional(),
|
|
74
|
+
OPENAI_API_KEY: z6.z.string().optional(),
|
|
75
|
+
ANTHROPIC_API_KEY: z6.z.string(),
|
|
76
|
+
INKEEP_AGENTS_RUN_API_BYPASS_SECRET: z6.z.string().optional(),
|
|
77
|
+
OTEL_BSP_SCHEDULE_DELAY: z6.z.coerce.number().optional().default(500),
|
|
78
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: z6.z.coerce.number().optional().default(64)
|
|
77
79
|
});
|
|
78
80
|
parseEnv = () => {
|
|
79
81
|
try {
|
|
80
82
|
const parsedEnv = envSchema.parse(process.env);
|
|
81
83
|
return parsedEnv;
|
|
82
84
|
} catch (error) {
|
|
83
|
-
if (error instanceof
|
|
85
|
+
if (error instanceof z6.z.ZodError) {
|
|
84
86
|
const missingVars = error.issues.map((issue) => issue.path.join("."));
|
|
85
87
|
throw new Error(
|
|
86
88
|
`\u274C Invalid environment variables: ${missingVars.join(", ")}
|
|
@@ -345,8 +347,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
345
347
|
});
|
|
346
348
|
referenceArtifacts.push(...artifacts);
|
|
347
349
|
}
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
+
const logger27 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
351
|
+
logger27.debug(
|
|
350
352
|
{
|
|
351
353
|
conversationId,
|
|
352
354
|
visibleMessages: visibleMessages.length,
|
|
@@ -358,8 +360,8 @@ async function getConversationScopedArtifacts(params) {
|
|
|
358
360
|
);
|
|
359
361
|
return referenceArtifacts;
|
|
360
362
|
} catch (error) {
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
+
const logger27 = (await Promise.resolve().then(() => (init_logger(), logger_exports))).getLogger("conversations");
|
|
364
|
+
logger27.error(
|
|
363
365
|
{
|
|
364
366
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
365
367
|
conversationId
|
|
@@ -1394,46 +1396,6 @@ async function getRegisteredAgent(executionContext, credentialStoreRegistry) {
|
|
|
1394
1396
|
init_dbClient();
|
|
1395
1397
|
init_logger();
|
|
1396
1398
|
|
|
1397
|
-
// src/utils/model-resolver.ts
|
|
1398
|
-
init_dbClient();
|
|
1399
|
-
async function resolveModelConfig(graphId, agent) {
|
|
1400
|
-
if (agent.models?.base?.model) {
|
|
1401
|
-
return {
|
|
1402
|
-
base: agent.models.base,
|
|
1403
|
-
structuredOutput: agent.models.structuredOutput || agent.models.base,
|
|
1404
|
-
summarizer: agent.models.summarizer || agent.models.base
|
|
1405
|
-
};
|
|
1406
|
-
}
|
|
1407
|
-
const graph = await agentsCore.getAgentGraphById(dbClient_default)({
|
|
1408
|
-
scopes: { tenantId: agent.tenantId, projectId: agent.projectId, graphId }
|
|
1409
|
-
});
|
|
1410
|
-
if (graph?.models?.base?.model) {
|
|
1411
|
-
return {
|
|
1412
|
-
base: graph.models.base,
|
|
1413
|
-
structuredOutput: agent.models?.structuredOutput || graph.models.structuredOutput || graph.models.base,
|
|
1414
|
-
summarizer: agent.models?.summarizer || graph.models.summarizer || graph.models.base
|
|
1415
|
-
};
|
|
1416
|
-
}
|
|
1417
|
-
const project = await agentsCore.getProject(dbClient_default)({
|
|
1418
|
-
scopes: { tenantId: agent.tenantId, projectId: agent.projectId }
|
|
1419
|
-
});
|
|
1420
|
-
if (project?.models?.base?.model) {
|
|
1421
|
-
return {
|
|
1422
|
-
base: project.models.base,
|
|
1423
|
-
structuredOutput: agent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
|
|
1424
|
-
summarizer: agent.models?.summarizer || project.models.summarizer || project.models.base
|
|
1425
|
-
};
|
|
1426
|
-
}
|
|
1427
|
-
throw new Error(
|
|
1428
|
-
"Base model configuration is required. Please configure models at the project level."
|
|
1429
|
-
);
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
// src/agents/Agent.ts
|
|
1433
|
-
init_conversations();
|
|
1434
|
-
init_dbClient();
|
|
1435
|
-
init_logger();
|
|
1436
|
-
|
|
1437
1399
|
// src/agents/ModelFactory.ts
|
|
1438
1400
|
init_logger();
|
|
1439
1401
|
var logger5 = agentsCore.getLogger("ModelFactory");
|
|
@@ -1832,7 +1794,46 @@ var tracer = agentsCore.getTracer("agents-run-api");
|
|
|
1832
1794
|
init_logger();
|
|
1833
1795
|
init_dbClient();
|
|
1834
1796
|
init_logger();
|
|
1835
|
-
|
|
1797
|
+
|
|
1798
|
+
// src/utils/schema-validation.ts
|
|
1799
|
+
init_logger();
|
|
1800
|
+
agentsCore.getLogger("SchemaValidation");
|
|
1801
|
+
new Ajv__default.default({ allErrors: true, strict: false });
|
|
1802
|
+
function extractPreviewFields(schema) {
|
|
1803
|
+
const previewProperties = {};
|
|
1804
|
+
if (schema.properties) {
|
|
1805
|
+
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
1806
|
+
if (prop.inPreview === true) {
|
|
1807
|
+
const cleanProp = { ...prop };
|
|
1808
|
+
delete cleanProp.inPreview;
|
|
1809
|
+
previewProperties[key] = cleanProp;
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
return {
|
|
1814
|
+
type: "object",
|
|
1815
|
+
properties: previewProperties,
|
|
1816
|
+
required: schema.required?.filter((field) => previewProperties[field])
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
function extractFullFields(schema) {
|
|
1820
|
+
const fullProperties = {};
|
|
1821
|
+
if (schema.properties) {
|
|
1822
|
+
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
1823
|
+
const cleanProp = { ...prop };
|
|
1824
|
+
delete cleanProp.inPreview;
|
|
1825
|
+
fullProperties[key] = cleanProp;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
return {
|
|
1829
|
+
type: "object",
|
|
1830
|
+
properties: fullProperties,
|
|
1831
|
+
required: schema.required
|
|
1832
|
+
};
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
// src/services/ArtifactService.ts
|
|
1836
|
+
var logger8 = agentsCore.getLogger("ArtifactService");
|
|
1836
1837
|
var _ArtifactService = class _ArtifactService {
|
|
1837
1838
|
constructor(context) {
|
|
1838
1839
|
this.context = context;
|
|
@@ -1844,6 +1845,12 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1844
1845
|
static clearCaches() {
|
|
1845
1846
|
_ArtifactService.selectorCache.clear();
|
|
1846
1847
|
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Update artifact components in the context
|
|
1850
|
+
*/
|
|
1851
|
+
updateArtifactComponents(artifactComponents) {
|
|
1852
|
+
this.context.artifactComponents = artifactComponents;
|
|
1853
|
+
}
|
|
1847
1854
|
/**
|
|
1848
1855
|
* Get all artifacts for a context from database
|
|
1849
1856
|
*/
|
|
@@ -1858,7 +1865,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1858
1865
|
id: taskId
|
|
1859
1866
|
});
|
|
1860
1867
|
if (!task) {
|
|
1861
|
-
|
|
1868
|
+
logger8.warn({ taskId }, "Task not found when fetching artifacts");
|
|
1862
1869
|
continue;
|
|
1863
1870
|
}
|
|
1864
1871
|
const taskArtifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
@@ -1876,7 +1883,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1876
1883
|
}
|
|
1877
1884
|
}
|
|
1878
1885
|
} catch (error) {
|
|
1879
|
-
|
|
1886
|
+
logger8.error({ error, contextId }, "Error loading context artifacts");
|
|
1880
1887
|
}
|
|
1881
1888
|
return artifacts;
|
|
1882
1889
|
}
|
|
@@ -1885,12 +1892,12 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1885
1892
|
*/
|
|
1886
1893
|
async createArtifact(request, agentId) {
|
|
1887
1894
|
if (!this.context.sessionId) {
|
|
1888
|
-
|
|
1895
|
+
logger8.warn({ request }, "No session ID available for artifact creation");
|
|
1889
1896
|
return null;
|
|
1890
1897
|
}
|
|
1891
1898
|
const toolResult = toolSessionManager.getToolResult(this.context.sessionId, request.toolCallId);
|
|
1892
1899
|
if (!toolResult) {
|
|
1893
|
-
|
|
1900
|
+
logger8.warn(
|
|
1894
1901
|
{ request, sessionId: this.context.sessionId },
|
|
1895
1902
|
"Tool result not found for artifact"
|
|
1896
1903
|
);
|
|
@@ -1906,7 +1913,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1906
1913
|
selectedData = selectedData.length > 0 ? selectedData[0] : {};
|
|
1907
1914
|
}
|
|
1908
1915
|
if (!selectedData) {
|
|
1909
|
-
|
|
1916
|
+
logger8.warn(
|
|
1910
1917
|
{
|
|
1911
1918
|
request,
|
|
1912
1919
|
baseSelector: request.baseSelector
|
|
@@ -1915,8 +1922,26 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1915
1922
|
);
|
|
1916
1923
|
selectedData = {};
|
|
1917
1924
|
}
|
|
1918
|
-
const
|
|
1919
|
-
let
|
|
1925
|
+
const component = this.context.artifactComponents?.find((ac) => ac.name === request.type);
|
|
1926
|
+
let summaryData = {};
|
|
1927
|
+
let fullData = {};
|
|
1928
|
+
if (component?.props) {
|
|
1929
|
+
const previewSchema = extractPreviewFields(component.props);
|
|
1930
|
+
const fullSchema = extractFullFields(component.props);
|
|
1931
|
+
summaryData = this.extractPropsFromSchema(
|
|
1932
|
+
selectedData,
|
|
1933
|
+
previewSchema,
|
|
1934
|
+
request.detailsSelector || {}
|
|
1935
|
+
);
|
|
1936
|
+
fullData = this.extractPropsFromSchema(
|
|
1937
|
+
selectedData,
|
|
1938
|
+
fullSchema,
|
|
1939
|
+
request.detailsSelector || {}
|
|
1940
|
+
);
|
|
1941
|
+
} else {
|
|
1942
|
+
summaryData = selectedData;
|
|
1943
|
+
fullData = selectedData;
|
|
1944
|
+
}
|
|
1920
1945
|
const isFullDataEmpty = !fullData || Object.keys(fullData).length === 0 || Object.values(fullData).every(
|
|
1921
1946
|
(val) => val === null || val === void 0 || val === "" || Array.isArray(val) && val.length === 0 || typeof val === "object" && Object.keys(val).length === 0
|
|
1922
1947
|
);
|
|
@@ -1925,14 +1950,13 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1925
1950
|
}
|
|
1926
1951
|
const cleanedSummaryData = this.cleanEscapedContent(summaryData);
|
|
1927
1952
|
const cleanedFullData = this.cleanEscapedContent(fullData);
|
|
1928
|
-
const component = this.context.artifactComponents?.find((ac) => ac.name === request.type);
|
|
1929
1953
|
const artifactData = {
|
|
1930
1954
|
artifactId: request.artifactId,
|
|
1931
1955
|
toolCallId: request.toolCallId,
|
|
1932
1956
|
name: "Processing...",
|
|
1933
1957
|
description: "Name and description being generated...",
|
|
1934
1958
|
type: request.type,
|
|
1935
|
-
|
|
1959
|
+
data: cleanedSummaryData
|
|
1936
1960
|
};
|
|
1937
1961
|
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, agentId);
|
|
1938
1962
|
await this.cacheArtifact(
|
|
@@ -1943,15 +1967,15 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1943
1967
|
);
|
|
1944
1968
|
return artifactData;
|
|
1945
1969
|
} catch (error) {
|
|
1946
|
-
|
|
1970
|
+
logger8.error({ error, request }, "Failed to create artifact");
|
|
1947
1971
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1948
1972
|
throw new Error(`Artifact creation failed for ${request.artifactId}: ${errorMessage}`);
|
|
1949
1973
|
}
|
|
1950
1974
|
}
|
|
1951
1975
|
/**
|
|
1952
|
-
* Get artifact data by ID and tool call ID
|
|
1976
|
+
* Get artifact summary data by ID and tool call ID
|
|
1953
1977
|
*/
|
|
1954
|
-
async
|
|
1978
|
+
async getArtifactSummary(artifactId, toolCallId, artifactMap) {
|
|
1955
1979
|
const key = `${artifactId}:${toolCallId}`;
|
|
1956
1980
|
if (this.context.streamRequestId) {
|
|
1957
1981
|
const cachedArtifact = await graphSessionManager.getArtifactCache(
|
|
@@ -1959,20 +1983,20 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1959
1983
|
key
|
|
1960
1984
|
);
|
|
1961
1985
|
if (cachedArtifact) {
|
|
1962
|
-
return this.
|
|
1986
|
+
return this.formatArtifactSummaryData(cachedArtifact, artifactId, toolCallId);
|
|
1963
1987
|
}
|
|
1964
1988
|
}
|
|
1965
1989
|
if (this.createdArtifacts.has(key)) {
|
|
1966
1990
|
const cached = this.createdArtifacts.get(key);
|
|
1967
|
-
return this.
|
|
1991
|
+
return this.formatArtifactSummaryData(cached, artifactId, toolCallId);
|
|
1968
1992
|
}
|
|
1969
1993
|
if (artifactMap?.has(key)) {
|
|
1970
1994
|
const artifact = artifactMap.get(key);
|
|
1971
|
-
return this.
|
|
1995
|
+
return this.formatArtifactSummaryData(artifact, artifactId, toolCallId);
|
|
1972
1996
|
}
|
|
1973
1997
|
try {
|
|
1974
1998
|
if (!this.context.projectId || !this.context.taskId) {
|
|
1975
|
-
|
|
1999
|
+
logger8.warn(
|
|
1976
2000
|
{ artifactId, toolCallId },
|
|
1977
2001
|
"No projectId or taskId available for artifact lookup"
|
|
1978
2002
|
);
|
|
@@ -1984,10 +2008,10 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1984
2008
|
taskId: this.context.taskId
|
|
1985
2009
|
});
|
|
1986
2010
|
if (artifacts.length > 0) {
|
|
1987
|
-
return this.
|
|
2011
|
+
return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
|
|
1988
2012
|
}
|
|
1989
2013
|
} catch (error) {
|
|
1990
|
-
|
|
2014
|
+
logger8.warn(
|
|
1991
2015
|
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
1992
2016
|
"Failed to fetch artifact"
|
|
1993
2017
|
);
|
|
@@ -1995,16 +2019,75 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1995
2019
|
return null;
|
|
1996
2020
|
}
|
|
1997
2021
|
/**
|
|
1998
|
-
*
|
|
2022
|
+
* Get artifact full data by ID and tool call ID
|
|
2023
|
+
*/
|
|
2024
|
+
async getArtifactFull(artifactId, toolCallId, artifactMap) {
|
|
2025
|
+
const key = `${artifactId}:${toolCallId}`;
|
|
2026
|
+
if (this.context.streamRequestId) {
|
|
2027
|
+
const cachedArtifact = await graphSessionManager.getArtifactCache(
|
|
2028
|
+
this.context.streamRequestId,
|
|
2029
|
+
key
|
|
2030
|
+
);
|
|
2031
|
+
if (cachedArtifact) {
|
|
2032
|
+
return this.formatArtifactFullData(cachedArtifact, artifactId, toolCallId);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (this.createdArtifacts.has(key)) {
|
|
2036
|
+
const cached = this.createdArtifacts.get(key);
|
|
2037
|
+
return this.formatArtifactFullData(cached, artifactId, toolCallId);
|
|
2038
|
+
}
|
|
2039
|
+
if (artifactMap?.has(key)) {
|
|
2040
|
+
const artifact = artifactMap.get(key);
|
|
2041
|
+
return this.formatArtifactFullData(artifact, artifactId, toolCallId);
|
|
2042
|
+
}
|
|
2043
|
+
try {
|
|
2044
|
+
if (!this.context.projectId || !this.context.taskId) {
|
|
2045
|
+
logger8.warn(
|
|
2046
|
+
{ artifactId, toolCallId },
|
|
2047
|
+
"No projectId or taskId available for artifact lookup"
|
|
2048
|
+
);
|
|
2049
|
+
return null;
|
|
2050
|
+
}
|
|
2051
|
+
const artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
|
|
2052
|
+
scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
|
|
2053
|
+
artifactId,
|
|
2054
|
+
taskId: this.context.taskId
|
|
2055
|
+
});
|
|
2056
|
+
if (artifacts.length > 0) {
|
|
2057
|
+
return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
|
|
2058
|
+
}
|
|
2059
|
+
} catch (error) {
|
|
2060
|
+
logger8.warn(
|
|
2061
|
+
{ artifactId, toolCallId, taskId: this.context.taskId, error },
|
|
2062
|
+
"Failed to fetch artifact"
|
|
2063
|
+
);
|
|
2064
|
+
}
|
|
2065
|
+
return null;
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
* Format raw artifact to standardized summary data format
|
|
2069
|
+
*/
|
|
2070
|
+
formatArtifactSummaryData(artifact, artifactId, toolCallId) {
|
|
2071
|
+
return {
|
|
2072
|
+
artifactId,
|
|
2073
|
+
toolCallId,
|
|
2074
|
+
name: artifact.name || "Processing...",
|
|
2075
|
+
description: artifact.description || "Name and description being generated...",
|
|
2076
|
+
type: artifact.metadata?.artifactType || artifact.artifactType,
|
|
2077
|
+
data: artifact.parts?.[0]?.data?.summary || {}
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
/**
|
|
2081
|
+
* Format raw artifact to standardized full data format
|
|
1999
2082
|
*/
|
|
2000
|
-
|
|
2083
|
+
formatArtifactFullData(artifact, artifactId, toolCallId) {
|
|
2001
2084
|
return {
|
|
2002
2085
|
artifactId,
|
|
2003
2086
|
toolCallId,
|
|
2004
2087
|
name: artifact.name || "Processing...",
|
|
2005
2088
|
description: artifact.description || "Name and description being generated...",
|
|
2006
2089
|
type: artifact.metadata?.artifactType || artifact.artifactType,
|
|
2007
|
-
|
|
2090
|
+
data: artifact.parts?.[0]?.data?.full || {}
|
|
2008
2091
|
};
|
|
2009
2092
|
}
|
|
2010
2093
|
/**
|
|
@@ -2022,14 +2105,13 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2022
2105
|
taskId: this.context.taskId,
|
|
2023
2106
|
toolCallId: request.toolCallId,
|
|
2024
2107
|
artifactType: request.type,
|
|
2025
|
-
|
|
2026
|
-
|
|
2108
|
+
summaryData,
|
|
2109
|
+
data: fullData,
|
|
2027
2110
|
agentId: effectiveAgentId,
|
|
2028
2111
|
metadata: {
|
|
2029
2112
|
toolCallId: request.toolCallId,
|
|
2030
2113
|
baseSelector: request.baseSelector,
|
|
2031
|
-
|
|
2032
|
-
fullProps: request.fullProps,
|
|
2114
|
+
detailsSelector: request.detailsSelector,
|
|
2033
2115
|
sessionId: this.context.sessionId,
|
|
2034
2116
|
artifactType: request.type
|
|
2035
2117
|
},
|
|
@@ -2040,14 +2122,17 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2040
2122
|
}
|
|
2041
2123
|
);
|
|
2042
2124
|
} else {
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2125
|
+
logger8.warn(
|
|
2126
|
+
{
|
|
2127
|
+
artifactId: request.artifactId,
|
|
2128
|
+
hasStreamRequestId: !!this.context.streamRequestId,
|
|
2129
|
+
hasAgentId: !!effectiveAgentId,
|
|
2130
|
+
hasTaskId: !!this.context.taskId,
|
|
2131
|
+
passedAgentId: agentId,
|
|
2132
|
+
contextAgentId: this.context.agentId
|
|
2133
|
+
},
|
|
2134
|
+
"Skipping artifact_saved event - missing required context"
|
|
2135
|
+
);
|
|
2051
2136
|
}
|
|
2052
2137
|
}
|
|
2053
2138
|
/**
|
|
@@ -2057,7 +2142,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2057
2142
|
const cacheKey = `${artifactId}:${toolCallId}`;
|
|
2058
2143
|
const artifactForCache = {
|
|
2059
2144
|
...artifactData,
|
|
2060
|
-
parts: [{ data: { summary: artifactData.
|
|
2145
|
+
parts: [{ data: { summary: artifactData.data, data: fullData } }],
|
|
2061
2146
|
metadata: { artifactType: artifactData.type, toolCallId },
|
|
2062
2147
|
taskId: this.context.taskId
|
|
2063
2148
|
};
|
|
@@ -2098,6 +2183,30 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2098
2183
|
* Used by GraphSession to save artifacts after name/description generation
|
|
2099
2184
|
*/
|
|
2100
2185
|
async saveArtifact(artifact) {
|
|
2186
|
+
let summaryData = artifact.data;
|
|
2187
|
+
let fullData = artifact.data;
|
|
2188
|
+
if (this.context.artifactComponents) {
|
|
2189
|
+
const artifactComponent = this.context.artifactComponents.find(
|
|
2190
|
+
(ac) => ac.name === artifact.type
|
|
2191
|
+
);
|
|
2192
|
+
if (artifactComponent?.props) {
|
|
2193
|
+
try {
|
|
2194
|
+
const schema = artifactComponent.props;
|
|
2195
|
+
const previewSchema = extractPreviewFields(schema);
|
|
2196
|
+
const fullSchema = extractFullFields(schema);
|
|
2197
|
+
summaryData = this.filterBySchema(artifact.data, previewSchema);
|
|
2198
|
+
fullData = this.filterBySchema(artifact.data, fullSchema);
|
|
2199
|
+
} catch (error) {
|
|
2200
|
+
logger8.warn(
|
|
2201
|
+
{
|
|
2202
|
+
artifactType: artifact.type,
|
|
2203
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
2204
|
+
},
|
|
2205
|
+
"Failed to extract preview/full fields from schema, using full data for both"
|
|
2206
|
+
);
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2101
2210
|
const artifactToSave = {
|
|
2102
2211
|
artifactId: artifact.artifactId,
|
|
2103
2212
|
name: artifact.name,
|
|
@@ -2108,8 +2217,8 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2108
2217
|
{
|
|
2109
2218
|
kind: "data",
|
|
2110
2219
|
data: {
|
|
2111
|
-
summary:
|
|
2112
|
-
full:
|
|
2220
|
+
summary: summaryData,
|
|
2221
|
+
full: fullData
|
|
2113
2222
|
}
|
|
2114
2223
|
}
|
|
2115
2224
|
],
|
|
@@ -2122,10 +2231,11 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2122
2231
|
},
|
|
2123
2232
|
contextId: this.context.contextId,
|
|
2124
2233
|
taskId: this.context.taskId,
|
|
2234
|
+
toolCallId: artifact.toolCallId,
|
|
2125
2235
|
artifact: artifactToSave
|
|
2126
2236
|
});
|
|
2127
2237
|
if (!result.created && result.existing) {
|
|
2128
|
-
|
|
2238
|
+
logger8.debug(
|
|
2129
2239
|
{
|
|
2130
2240
|
artifactId: artifact.artifactId,
|
|
2131
2241
|
taskId: this.context.taskId
|
|
@@ -2178,7 +2288,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2178
2288
|
extracted[propName] = this.cleanEscapedContent(rawValue);
|
|
2179
2289
|
}
|
|
2180
2290
|
} catch (error) {
|
|
2181
|
-
|
|
2291
|
+
logger8.warn(
|
|
2182
2292
|
{ propName, selector, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2183
2293
|
"Failed to extract property"
|
|
2184
2294
|
);
|
|
@@ -2190,6 +2300,39 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2190
2300
|
}
|
|
2191
2301
|
return extracted;
|
|
2192
2302
|
}
|
|
2303
|
+
/**
|
|
2304
|
+
* Extract properties from data using schema-defined fields and custom selectors
|
|
2305
|
+
*/
|
|
2306
|
+
extractPropsFromSchema(item, schema, customSelectors) {
|
|
2307
|
+
const extracted = {};
|
|
2308
|
+
if (schema.properties) {
|
|
2309
|
+
for (const fieldName of Object.keys(schema.properties)) {
|
|
2310
|
+
try {
|
|
2311
|
+
const customSelector = customSelectors[fieldName];
|
|
2312
|
+
let rawValue;
|
|
2313
|
+
if (customSelector) {
|
|
2314
|
+
const sanitizedSelector = this.sanitizeJMESPathSelector(customSelector);
|
|
2315
|
+
rawValue = jmespath__default.default.search(item, sanitizedSelector);
|
|
2316
|
+
} else {
|
|
2317
|
+
rawValue = item[fieldName];
|
|
2318
|
+
}
|
|
2319
|
+
if (rawValue !== null && rawValue !== void 0) {
|
|
2320
|
+
extracted[fieldName] = this.cleanEscapedContent(rawValue);
|
|
2321
|
+
}
|
|
2322
|
+
} catch (error) {
|
|
2323
|
+
logger8.warn(
|
|
2324
|
+
{ fieldName, error: error instanceof Error ? error.message : "Unknown error" },
|
|
2325
|
+
"Failed to extract schema field"
|
|
2326
|
+
);
|
|
2327
|
+
const fallbackValue = item[fieldName];
|
|
2328
|
+
if (fallbackValue !== null && fallbackValue !== void 0) {
|
|
2329
|
+
extracted[fieldName] = this.cleanEscapedContent(fallbackValue);
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
return extracted;
|
|
2335
|
+
}
|
|
2193
2336
|
/**
|
|
2194
2337
|
* Filter extracted props based on schema
|
|
2195
2338
|
*/
|
|
@@ -2208,15 +2351,19 @@ __publicField(_ArtifactService, "selectorCache", /* @__PURE__ */ new Map());
|
|
|
2208
2351
|
var ArtifactService = _ArtifactService;
|
|
2209
2352
|
|
|
2210
2353
|
// src/services/ArtifactParser.ts
|
|
2211
|
-
var
|
|
2354
|
+
var logger9 = agentsCore.getLogger("ArtifactParser");
|
|
2212
2355
|
var _ArtifactParser = class _ArtifactParser {
|
|
2213
2356
|
constructor(tenantId, options) {
|
|
2214
2357
|
__publicField(this, "artifactService");
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2358
|
+
if (options?.artifactService) {
|
|
2359
|
+
this.artifactService = options.artifactService;
|
|
2360
|
+
} else {
|
|
2361
|
+
const context = {
|
|
2362
|
+
tenantId,
|
|
2363
|
+
...options
|
|
2364
|
+
};
|
|
2365
|
+
this.artifactService = new ArtifactService(context);
|
|
2366
|
+
}
|
|
2220
2367
|
}
|
|
2221
2368
|
/**
|
|
2222
2369
|
* Check if text contains complete artifact markers (ref or create)
|
|
@@ -2292,7 +2439,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2292
2439
|
attrs[key] = value;
|
|
2293
2440
|
}
|
|
2294
2441
|
if (!attrs.id || !attrs.tool || !attrs.type || !attrs.base) {
|
|
2295
|
-
|
|
2442
|
+
logger9.warn({ attrs, attrString }, "Missing required attributes in artifact annotation");
|
|
2296
2443
|
return null;
|
|
2297
2444
|
}
|
|
2298
2445
|
return {
|
|
@@ -2300,8 +2447,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2300
2447
|
toolCallId: attrs.tool,
|
|
2301
2448
|
type: attrs.type,
|
|
2302
2449
|
baseSelector: attrs.base,
|
|
2303
|
-
|
|
2304
|
-
fullProps: attrs.full || {}
|
|
2450
|
+
detailsSelector: attrs.details || {}
|
|
2305
2451
|
};
|
|
2306
2452
|
}
|
|
2307
2453
|
/**
|
|
@@ -2330,8 +2476,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2330
2476
|
toolCallId: annotation.toolCallId,
|
|
2331
2477
|
type: annotation.type,
|
|
2332
2478
|
baseSelector: annotation.baseSelector,
|
|
2333
|
-
|
|
2334
|
-
fullProps: annotation.fullProps
|
|
2479
|
+
detailsSelector: annotation.detailsSelector
|
|
2335
2480
|
};
|
|
2336
2481
|
return this.artifactService.createArtifact(request, agentId);
|
|
2337
2482
|
}
|
|
@@ -2351,9 +2496,14 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2351
2496
|
if (artifactData && annotation.raw) {
|
|
2352
2497
|
createdArtifactData.set(annotation.raw, artifactData);
|
|
2353
2498
|
} else if (annotation.raw) {
|
|
2354
|
-
failedAnnotations.push(
|
|
2499
|
+
failedAnnotations.push(
|
|
2500
|
+
`Failed to create artifact "${annotation.artifactId}": Missing or invalid data`
|
|
2501
|
+
);
|
|
2355
2502
|
processedText = processedText.replace(annotation.raw, "");
|
|
2356
|
-
|
|
2503
|
+
logger9.warn(
|
|
2504
|
+
{ annotation, artifactData },
|
|
2505
|
+
"Removed failed artifact:create annotation from output"
|
|
2506
|
+
);
|
|
2357
2507
|
}
|
|
2358
2508
|
} catch (error) {
|
|
2359
2509
|
const errorMsg = error instanceof Error ? error.message : "Unknown error";
|
|
@@ -2361,14 +2511,17 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2361
2511
|
if (annotation.raw) {
|
|
2362
2512
|
processedText = processedText.replace(annotation.raw, "");
|
|
2363
2513
|
}
|
|
2364
|
-
|
|
2514
|
+
logger9.error({ annotation, error }, "Failed to extract artifact from create annotation");
|
|
2365
2515
|
}
|
|
2366
2516
|
}
|
|
2367
2517
|
if (failedAnnotations.length > 0) {
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2518
|
+
logger9.warn(
|
|
2519
|
+
{
|
|
2520
|
+
failedCount: failedAnnotations.length,
|
|
2521
|
+
failures: failedAnnotations
|
|
2522
|
+
},
|
|
2523
|
+
"Some artifact creation attempts failed"
|
|
2524
|
+
);
|
|
2372
2525
|
}
|
|
2373
2526
|
const parts = [];
|
|
2374
2527
|
const createRegex = /<artifact:create\s+([^>]+?)(?:\s*\/)?>(?:(.*?)<\/artifact:create>)?/gs;
|
|
@@ -2401,7 +2554,17 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2401
2554
|
artifactData = await this.getArtifactData(artifactId, toolCallId, artifactMap);
|
|
2402
2555
|
}
|
|
2403
2556
|
if (artifactData) {
|
|
2404
|
-
parts.push({
|
|
2557
|
+
parts.push({
|
|
2558
|
+
kind: "data",
|
|
2559
|
+
data: {
|
|
2560
|
+
artifactId: artifactData.artifactId,
|
|
2561
|
+
toolCallId: artifactData.toolCallId,
|
|
2562
|
+
name: artifactData.name,
|
|
2563
|
+
description: artifactData.description,
|
|
2564
|
+
type: artifactData.type,
|
|
2565
|
+
artifactSummary: artifactData.data
|
|
2566
|
+
}
|
|
2567
|
+
});
|
|
2405
2568
|
}
|
|
2406
2569
|
lastIndex = matchStart + fullMatch.length;
|
|
2407
2570
|
}
|
|
@@ -2427,12 +2590,32 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2427
2590
|
artifactMap
|
|
2428
2591
|
);
|
|
2429
2592
|
if (artifactData) {
|
|
2430
|
-
parts.push({
|
|
2593
|
+
parts.push({
|
|
2594
|
+
kind: "data",
|
|
2595
|
+
data: {
|
|
2596
|
+
artifactId: artifactData.artifactId,
|
|
2597
|
+
toolCallId: artifactData.toolCallId,
|
|
2598
|
+
name: artifactData.name,
|
|
2599
|
+
description: artifactData.description,
|
|
2600
|
+
type: artifactData.type,
|
|
2601
|
+
artifactSummary: artifactData.data
|
|
2602
|
+
}
|
|
2603
|
+
});
|
|
2431
2604
|
}
|
|
2432
2605
|
} else if (this.isArtifactCreateComponent(component)) {
|
|
2433
2606
|
const createData = await this.extractFromArtifactCreateComponent(component, agentId);
|
|
2434
2607
|
if (createData) {
|
|
2435
|
-
parts.push({
|
|
2608
|
+
parts.push({
|
|
2609
|
+
kind: "data",
|
|
2610
|
+
data: {
|
|
2611
|
+
artifactId: createData.artifactId,
|
|
2612
|
+
toolCallId: createData.toolCallId,
|
|
2613
|
+
name: createData.name,
|
|
2614
|
+
description: createData.description,
|
|
2615
|
+
type: createData.type,
|
|
2616
|
+
artifactSummary: createData.data
|
|
2617
|
+
}
|
|
2618
|
+
});
|
|
2436
2619
|
}
|
|
2437
2620
|
} else {
|
|
2438
2621
|
parts.push({ kind: "data", data: component });
|
|
@@ -2446,11 +2629,35 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2446
2629
|
obj.props.tool_call_id,
|
|
2447
2630
|
artifactMap
|
|
2448
2631
|
);
|
|
2449
|
-
return artifactData ? [
|
|
2632
|
+
return artifactData ? [
|
|
2633
|
+
{
|
|
2634
|
+
kind: "data",
|
|
2635
|
+
data: {
|
|
2636
|
+
artifactId: artifactData.artifactId,
|
|
2637
|
+
toolCallId: artifactData.toolCallId,
|
|
2638
|
+
name: artifactData.name,
|
|
2639
|
+
description: artifactData.description,
|
|
2640
|
+
type: artifactData.type,
|
|
2641
|
+
artifactSummary: artifactData.data
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
] : [];
|
|
2450
2645
|
}
|
|
2451
2646
|
if (this.isArtifactCreateComponent(obj)) {
|
|
2452
2647
|
const createData = await this.extractFromArtifactCreateComponent(obj, agentId);
|
|
2453
|
-
return createData ? [
|
|
2648
|
+
return createData ? [
|
|
2649
|
+
{
|
|
2650
|
+
kind: "data",
|
|
2651
|
+
data: {
|
|
2652
|
+
artifactId: createData.artifactId,
|
|
2653
|
+
toolCallId: createData.toolCallId,
|
|
2654
|
+
name: createData.name,
|
|
2655
|
+
description: createData.description,
|
|
2656
|
+
type: createData.type,
|
|
2657
|
+
artifactSummary: createData.data
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
] : [];
|
|
2454
2661
|
}
|
|
2455
2662
|
return [{ kind: "data", data: obj }];
|
|
2456
2663
|
}
|
|
@@ -2479,8 +2686,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2479
2686
|
toolCallId: props.tool_call_id,
|
|
2480
2687
|
type: props.type,
|
|
2481
2688
|
baseSelector: props.base_selector,
|
|
2482
|
-
|
|
2483
|
-
fullProps: props.full_props || {}
|
|
2689
|
+
detailsSelector: props.details_selector || {}
|
|
2484
2690
|
};
|
|
2485
2691
|
return await this.extractFromCreateAnnotation(annotation, agentId);
|
|
2486
2692
|
}
|
|
@@ -2488,7 +2694,7 @@ var _ArtifactParser = class _ArtifactParser {
|
|
|
2488
2694
|
* Get artifact data - delegates to service
|
|
2489
2695
|
*/
|
|
2490
2696
|
async getArtifactData(artifactId, toolCallId, artifactMap) {
|
|
2491
|
-
return this.artifactService.
|
|
2697
|
+
return await this.artifactService.getArtifactSummary(artifactId, toolCallId, artifactMap);
|
|
2492
2698
|
}
|
|
2493
2699
|
};
|
|
2494
2700
|
// Shared regex patterns - support both single and double quotes
|
|
@@ -2522,7 +2728,7 @@ __publicField(_ArtifactParser, "INCOMPLETE_CREATE_REGEX", /<artifact:create(?![^
|
|
|
2522
2728
|
var ArtifactParser = _ArtifactParser;
|
|
2523
2729
|
|
|
2524
2730
|
// src/services/GraphSession.ts
|
|
2525
|
-
var
|
|
2731
|
+
var logger10 = agentsCore.getLogger("GraphSession");
|
|
2526
2732
|
var GraphSession = class {
|
|
2527
2733
|
// Whether to send data operations
|
|
2528
2734
|
constructor(sessionId, messageId, graphId, tenantId, projectId, contextId) {
|
|
@@ -2555,7 +2761,7 @@ var GraphSession = class {
|
|
|
2555
2761
|
__publicField(this, "artifactParser");
|
|
2556
2762
|
// Session-scoped ArtifactParser instance
|
|
2557
2763
|
__publicField(this, "isEmitOperations", false);
|
|
2558
|
-
|
|
2764
|
+
logger10.debug({ sessionId, messageId, graphId }, "GraphSession created");
|
|
2559
2765
|
if (tenantId && projectId) {
|
|
2560
2766
|
toolSessionManager.createSessionWithId(
|
|
2561
2767
|
sessionId,
|
|
@@ -2579,7 +2785,9 @@ var GraphSession = class {
|
|
|
2579
2785
|
sessionId,
|
|
2580
2786
|
contextId,
|
|
2581
2787
|
taskId: `task_${contextId}-${messageId}`,
|
|
2582
|
-
streamRequestId: sessionId
|
|
2788
|
+
streamRequestId: sessionId,
|
|
2789
|
+
artifactService: this.artifactService
|
|
2790
|
+
// Pass the shared ArtifactService
|
|
2583
2791
|
});
|
|
2584
2792
|
}
|
|
2585
2793
|
}
|
|
@@ -2588,7 +2796,7 @@ var GraphSession = class {
|
|
|
2588
2796
|
*/
|
|
2589
2797
|
enableEmitOperations() {
|
|
2590
2798
|
this.isEmitOperations = true;
|
|
2591
|
-
|
|
2799
|
+
logger10.info(
|
|
2592
2800
|
{ sessionId: this.sessionId },
|
|
2593
2801
|
"\u{1F50D} DEBUG: Emit operations enabled for GraphSession"
|
|
2594
2802
|
);
|
|
@@ -2612,7 +2820,7 @@ var GraphSession = class {
|
|
|
2612
2820
|
await streamHelper.writeOperation(formattedOperation);
|
|
2613
2821
|
}
|
|
2614
2822
|
} catch (error) {
|
|
2615
|
-
|
|
2823
|
+
logger10.error(
|
|
2616
2824
|
{
|
|
2617
2825
|
sessionId: this.sessionId,
|
|
2618
2826
|
eventType: event.eventType,
|
|
@@ -2675,7 +2883,7 @@ var GraphSession = class {
|
|
|
2675
2883
|
if (this.statusUpdateState.config.timeInSeconds) {
|
|
2676
2884
|
this.statusUpdateTimer = setInterval(async () => {
|
|
2677
2885
|
if (!this.statusUpdateState || this.isEnded) {
|
|
2678
|
-
|
|
2886
|
+
logger10.debug(
|
|
2679
2887
|
{ sessionId: this.sessionId },
|
|
2680
2888
|
"Timer triggered but session already cleaned up or ended"
|
|
2681
2889
|
);
|
|
@@ -2687,7 +2895,7 @@ var GraphSession = class {
|
|
|
2687
2895
|
}
|
|
2688
2896
|
await this.checkAndSendTimeBasedUpdate();
|
|
2689
2897
|
}, this.statusUpdateState.config.timeInSeconds * 1e3);
|
|
2690
|
-
|
|
2898
|
+
logger10.info(
|
|
2691
2899
|
{
|
|
2692
2900
|
sessionId: this.sessionId,
|
|
2693
2901
|
intervalMs: this.statusUpdateState.config.timeInSeconds * 1e3
|
|
@@ -2709,7 +2917,7 @@ var GraphSession = class {
|
|
|
2709
2917
|
});
|
|
2710
2918
|
}
|
|
2711
2919
|
if (this.isEnded) {
|
|
2712
|
-
|
|
2920
|
+
logger10.debug(
|
|
2713
2921
|
{
|
|
2714
2922
|
sessionId: this.sessionId,
|
|
2715
2923
|
eventType,
|
|
@@ -2729,7 +2937,7 @@ var GraphSession = class {
|
|
|
2729
2937
|
if (eventType === "artifact_saved" && data.pendingGeneration) {
|
|
2730
2938
|
const artifactId = data.artifactId;
|
|
2731
2939
|
if (this.pendingArtifacts.size >= this.MAX_PENDING_ARTIFACTS) {
|
|
2732
|
-
|
|
2940
|
+
logger10.warn(
|
|
2733
2941
|
{
|
|
2734
2942
|
sessionId: this.sessionId,
|
|
2735
2943
|
artifactId,
|
|
@@ -2751,7 +2959,7 @@ var GraphSession = class {
|
|
|
2751
2959
|
this.artifactProcessingErrors.set(artifactId, errorCount);
|
|
2752
2960
|
if (errorCount >= this.MAX_ARTIFACT_RETRIES) {
|
|
2753
2961
|
this.pendingArtifacts.delete(artifactId);
|
|
2754
|
-
|
|
2962
|
+
logger10.error(
|
|
2755
2963
|
{
|
|
2756
2964
|
sessionId: this.sessionId,
|
|
2757
2965
|
artifactId,
|
|
@@ -2763,7 +2971,7 @@ var GraphSession = class {
|
|
|
2763
2971
|
"Artifact processing failed after max retries, giving up"
|
|
2764
2972
|
);
|
|
2765
2973
|
} else {
|
|
2766
|
-
|
|
2974
|
+
logger10.warn(
|
|
2767
2975
|
{
|
|
2768
2976
|
sessionId: this.sessionId,
|
|
2769
2977
|
artifactId,
|
|
@@ -2785,14 +2993,14 @@ var GraphSession = class {
|
|
|
2785
2993
|
*/
|
|
2786
2994
|
checkStatusUpdates() {
|
|
2787
2995
|
if (this.isEnded) {
|
|
2788
|
-
|
|
2996
|
+
logger10.debug(
|
|
2789
2997
|
{ sessionId: this.sessionId },
|
|
2790
2998
|
"Session has ended - skipping status update check"
|
|
2791
2999
|
);
|
|
2792
3000
|
return;
|
|
2793
3001
|
}
|
|
2794
3002
|
if (!this.statusUpdateState) {
|
|
2795
|
-
|
|
3003
|
+
logger10.debug({ sessionId: this.sessionId }, "No status update state - skipping check");
|
|
2796
3004
|
return;
|
|
2797
3005
|
}
|
|
2798
3006
|
const statusUpdateState = this.statusUpdateState;
|
|
@@ -2803,11 +3011,11 @@ var GraphSession = class {
|
|
|
2803
3011
|
*/
|
|
2804
3012
|
async checkAndSendTimeBasedUpdate() {
|
|
2805
3013
|
if (this.isEnded) {
|
|
2806
|
-
|
|
3014
|
+
logger10.debug({ sessionId: this.sessionId }, "Session has ended - skipping time-based update");
|
|
2807
3015
|
return;
|
|
2808
3016
|
}
|
|
2809
3017
|
if (!this.statusUpdateState) {
|
|
2810
|
-
|
|
3018
|
+
logger10.debug(
|
|
2811
3019
|
{ sessionId: this.sessionId },
|
|
2812
3020
|
"No status updates configured for time-based check"
|
|
2813
3021
|
);
|
|
@@ -2820,7 +3028,7 @@ var GraphSession = class {
|
|
|
2820
3028
|
try {
|
|
2821
3029
|
await this.generateAndSendUpdate();
|
|
2822
3030
|
} catch (error) {
|
|
2823
|
-
|
|
3031
|
+
logger10.error(
|
|
2824
3032
|
{
|
|
2825
3033
|
sessionId: this.sessionId,
|
|
2826
3034
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -2923,29 +3131,29 @@ var GraphSession = class {
|
|
|
2923
3131
|
*/
|
|
2924
3132
|
async generateAndSendUpdate() {
|
|
2925
3133
|
if (this.isEnded) {
|
|
2926
|
-
|
|
3134
|
+
logger10.debug({ sessionId: this.sessionId }, "Session has ended - not generating update");
|
|
2927
3135
|
return;
|
|
2928
3136
|
}
|
|
2929
3137
|
if (this.isTextStreaming) {
|
|
2930
|
-
|
|
3138
|
+
logger10.debug(
|
|
2931
3139
|
{ sessionId: this.sessionId },
|
|
2932
3140
|
"Text is currently streaming - skipping status update"
|
|
2933
3141
|
);
|
|
2934
3142
|
return;
|
|
2935
3143
|
}
|
|
2936
3144
|
if (this.isGeneratingUpdate) {
|
|
2937
|
-
|
|
3145
|
+
logger10.debug(
|
|
2938
3146
|
{ sessionId: this.sessionId },
|
|
2939
3147
|
"Update already in progress - skipping duplicate generation"
|
|
2940
3148
|
);
|
|
2941
3149
|
return;
|
|
2942
3150
|
}
|
|
2943
3151
|
if (!this.statusUpdateState) {
|
|
2944
|
-
|
|
3152
|
+
logger10.warn({ sessionId: this.sessionId }, "No status update state - cannot generate update");
|
|
2945
3153
|
return;
|
|
2946
3154
|
}
|
|
2947
3155
|
if (!this.graphId) {
|
|
2948
|
-
|
|
3156
|
+
logger10.warn({ sessionId: this.sessionId }, "No graph ID - cannot generate update");
|
|
2949
3157
|
return;
|
|
2950
3158
|
}
|
|
2951
3159
|
const newEventCount = this.events.length - this.statusUpdateState.lastEventCount;
|
|
@@ -2957,7 +3165,7 @@ var GraphSession = class {
|
|
|
2957
3165
|
try {
|
|
2958
3166
|
const streamHelper = getStreamHelper(this.sessionId);
|
|
2959
3167
|
if (!streamHelper) {
|
|
2960
|
-
|
|
3168
|
+
logger10.warn(
|
|
2961
3169
|
{ sessionId: this.sessionId },
|
|
2962
3170
|
"No stream helper found - cannot send status update"
|
|
2963
3171
|
);
|
|
@@ -2977,7 +3185,7 @@ var GraphSession = class {
|
|
|
2977
3185
|
if (result.summaries && result.summaries.length > 0) {
|
|
2978
3186
|
for (const summary of result.summaries) {
|
|
2979
3187
|
if (!summary || !summary.type || !summary.data || !summary.data.label || Object.keys(summary.data).length === 0) {
|
|
2980
|
-
|
|
3188
|
+
logger10.warn(
|
|
2981
3189
|
{
|
|
2982
3190
|
sessionId: this.sessionId,
|
|
2983
3191
|
summary
|
|
@@ -3014,7 +3222,7 @@ var GraphSession = class {
|
|
|
3014
3222
|
this.statusUpdateState.lastEventCount = this.events.length;
|
|
3015
3223
|
}
|
|
3016
3224
|
} catch (error) {
|
|
3017
|
-
|
|
3225
|
+
logger10.error(
|
|
3018
3226
|
{
|
|
3019
3227
|
sessionId: this.sessionId,
|
|
3020
3228
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -3052,7 +3260,7 @@ var GraphSession = class {
|
|
|
3052
3260
|
this.releaseUpdateLock();
|
|
3053
3261
|
}
|
|
3054
3262
|
} catch (error) {
|
|
3055
|
-
|
|
3263
|
+
logger10.error(
|
|
3056
3264
|
{
|
|
3057
3265
|
sessionId: this.sessionId,
|
|
3058
3266
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -3130,7 +3338,7 @@ User's Question/Context:
|
|
|
3130
3338
|
${conversationHistory}
|
|
3131
3339
|
` : "";
|
|
3132
3340
|
} catch (error) {
|
|
3133
|
-
|
|
3341
|
+
logger10.warn(
|
|
3134
3342
|
{ sessionId: this.sessionId, error },
|
|
3135
3343
|
"Failed to fetch conversation history for structured status update"
|
|
3136
3344
|
);
|
|
@@ -3140,13 +3348,13 @@ ${conversationHistory}
|
|
|
3140
3348
|
Previous updates sent to user:
|
|
3141
3349
|
${previousSummaries.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
3142
3350
|
` : "";
|
|
3143
|
-
const selectionSchema =
|
|
3351
|
+
const selectionSchema = z6.z.object(
|
|
3144
3352
|
Object.fromEntries([
|
|
3145
3353
|
// Add no_relevant_updates schema
|
|
3146
3354
|
[
|
|
3147
3355
|
"no_relevant_updates",
|
|
3148
|
-
|
|
3149
|
-
no_updates:
|
|
3356
|
+
z6.z.object({
|
|
3357
|
+
no_updates: z6.z.boolean().default(true)
|
|
3150
3358
|
}).optional().describe(
|
|
3151
3359
|
"Use when nothing substantially new to report. Should only use on its own."
|
|
3152
3360
|
)
|
|
@@ -3264,7 +3472,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3264
3472
|
return { summaries };
|
|
3265
3473
|
} catch (error) {
|
|
3266
3474
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
3267
|
-
|
|
3475
|
+
logger10.error({ error }, "Failed to generate structured update, using fallback");
|
|
3268
3476
|
return { summaries: [] };
|
|
3269
3477
|
} finally {
|
|
3270
3478
|
span.end();
|
|
@@ -3279,8 +3487,8 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3279
3487
|
if (component.detailsSchema && "properties" in component.detailsSchema) {
|
|
3280
3488
|
return this.buildZodSchemaFromJson(component.detailsSchema);
|
|
3281
3489
|
}
|
|
3282
|
-
return
|
|
3283
|
-
label:
|
|
3490
|
+
return z6.z.object({
|
|
3491
|
+
label: z6.z.string().describe(
|
|
3284
3492
|
'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The ACTUAL finding or result, not the action. What specific information was discovered? (e.g., "Slack requires OAuth 2.0 setup", "Found 5 integration methods", "API rate limit is 100/minute"). Include the actual detail or insight, not just that you searched or processed. CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
|
|
3285
3493
|
)
|
|
3286
3494
|
});
|
|
@@ -3290,56 +3498,56 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3290
3498
|
*/
|
|
3291
3499
|
buildZodSchemaFromJson(jsonSchema) {
|
|
3292
3500
|
const properties = {};
|
|
3293
|
-
properties["label"] =
|
|
3501
|
+
properties["label"] = z6.z.string().describe(
|
|
3294
3502
|
'A short 3-5 word phrase, that is a descriptive label for the update component. This Label must be EXTREMELY unique to represent the UNIQUE update we are providing. The SPECIFIC finding, result, or insight discovered (e.g., "Slack bot needs workspace admin role", "Found ingestion requires 3 steps", "Channel history limited to 10k messages"). State the ACTUAL information found, not that you searched. What did you LEARN or DISCOVER? What specific detail is now known? CRITICAL: Only use facts explicitly found in the activities - NEVER invent names, people, organizations, or details that are not present in the actual tool results.'
|
|
3295
3503
|
);
|
|
3296
3504
|
for (const [key, value] of Object.entries(jsonSchema.properties)) {
|
|
3297
3505
|
let zodType;
|
|
3298
3506
|
if (value.enum && Array.isArray(value.enum)) {
|
|
3299
3507
|
if (value.enum.length === 1) {
|
|
3300
|
-
zodType =
|
|
3508
|
+
zodType = z6.z.literal(value.enum[0]);
|
|
3301
3509
|
} else {
|
|
3302
3510
|
const [first, ...rest] = value.enum;
|
|
3303
|
-
zodType =
|
|
3511
|
+
zodType = z6.z.enum([first, ...rest]);
|
|
3304
3512
|
}
|
|
3305
3513
|
} else if (value.type === "string") {
|
|
3306
|
-
zodType =
|
|
3514
|
+
zodType = z6.z.string();
|
|
3307
3515
|
if (value.minLength) zodType = zodType.min(value.minLength);
|
|
3308
3516
|
if (value.maxLength) zodType = zodType.max(value.maxLength);
|
|
3309
3517
|
if (value.format === "email") zodType = zodType.email();
|
|
3310
3518
|
if (value.format === "url" || value.format === "uri")
|
|
3311
3519
|
zodType = zodType.url();
|
|
3312
3520
|
} else if (value.type === "number" || value.type === "integer") {
|
|
3313
|
-
zodType = value.type === "integer" ?
|
|
3521
|
+
zodType = value.type === "integer" ? z6.z.number().int() : z6.z.number();
|
|
3314
3522
|
if (value.minimum !== void 0) zodType = zodType.min(value.minimum);
|
|
3315
3523
|
if (value.maximum !== void 0) zodType = zodType.max(value.maximum);
|
|
3316
3524
|
} else if (value.type === "boolean") {
|
|
3317
|
-
zodType =
|
|
3525
|
+
zodType = z6.z.boolean();
|
|
3318
3526
|
} else if (value.type === "array") {
|
|
3319
3527
|
if (value.items) {
|
|
3320
3528
|
if (value.items.enum && Array.isArray(value.items.enum)) {
|
|
3321
3529
|
const [first, ...rest] = value.items.enum;
|
|
3322
|
-
zodType =
|
|
3530
|
+
zodType = z6.z.array(z6.z.enum([first, ...rest]));
|
|
3323
3531
|
} else if (value.items.type === "string") {
|
|
3324
|
-
zodType =
|
|
3532
|
+
zodType = z6.z.array(z6.z.string());
|
|
3325
3533
|
} else if (value.items.type === "number") {
|
|
3326
|
-
zodType =
|
|
3534
|
+
zodType = z6.z.array(z6.z.number());
|
|
3327
3535
|
} else if (value.items.type === "boolean") {
|
|
3328
|
-
zodType =
|
|
3536
|
+
zodType = z6.z.array(z6.z.boolean());
|
|
3329
3537
|
} else if (value.items.type === "object") {
|
|
3330
|
-
zodType =
|
|
3538
|
+
zodType = z6.z.array(z6.z.record(z6.z.string(), z6.z.any()));
|
|
3331
3539
|
} else {
|
|
3332
|
-
zodType =
|
|
3540
|
+
zodType = z6.z.array(z6.z.any());
|
|
3333
3541
|
}
|
|
3334
3542
|
} else {
|
|
3335
|
-
zodType =
|
|
3543
|
+
zodType = z6.z.array(z6.z.any());
|
|
3336
3544
|
}
|
|
3337
3545
|
if (value.minItems) zodType = zodType.min(value.minItems);
|
|
3338
3546
|
if (value.maxItems) zodType = zodType.max(value.maxItems);
|
|
3339
3547
|
} else if (value.type === "object") {
|
|
3340
|
-
zodType =
|
|
3548
|
+
zodType = z6.z.record(z6.z.string(), z6.z.any());
|
|
3341
3549
|
} else {
|
|
3342
|
-
zodType =
|
|
3550
|
+
zodType = z6.z.any();
|
|
3343
3551
|
}
|
|
3344
3552
|
if (value.description) {
|
|
3345
3553
|
zodType = zodType.describe(value.description);
|
|
@@ -3349,7 +3557,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3349
3557
|
}
|
|
3350
3558
|
properties[key] = zodType;
|
|
3351
3559
|
}
|
|
3352
|
-
return
|
|
3560
|
+
return z6.z.object(properties);
|
|
3353
3561
|
}
|
|
3354
3562
|
/**
|
|
3355
3563
|
* Extract user-visible activities with rich formatting and complete information
|
|
@@ -3409,6 +3617,9 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3409
3617
|
"graph_session.id": this.sessionId,
|
|
3410
3618
|
"artifact.id": artifactData.artifactId,
|
|
3411
3619
|
"artifact.type": artifactData.artifactType || "unknown",
|
|
3620
|
+
"artifact.agent_id": artifactData.agentId || "unknown",
|
|
3621
|
+
"artifact.tool_call_id": artifactData.metadata?.toolCallId || "unknown",
|
|
3622
|
+
"artifact.data": JSON.stringify(artifactData.data, null, 2),
|
|
3412
3623
|
"tenant.id": artifactData.tenantId || "unknown",
|
|
3413
3624
|
"project.id": artifactData.projectId || "unknown",
|
|
3414
3625
|
"context.id": artifactData.contextId || "unknown",
|
|
@@ -3459,8 +3670,7 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3459
3670
|
Tool Context: ${toolContext ? JSON.stringify(toolContext, null, 2) : "No tool context"}
|
|
3460
3671
|
Context: ${conversationHistory?.slice(-200) || "Processing"}
|
|
3461
3672
|
Type: ${artifactData.artifactType || "data"}
|
|
3462
|
-
|
|
3463
|
-
Full: ${JSON.stringify(artifactData.fullProps, null, 2)}
|
|
3673
|
+
Data: ${JSON.stringify(artifactData.data || artifactData.summaryData, null, 2)}
|
|
3464
3674
|
|
|
3465
3675
|
Make it specific and relevant.`;
|
|
3466
3676
|
let modelToUse = this.statusUpdateState?.summarizerModel;
|
|
@@ -3478,7 +3688,7 @@ Make it specific and relevant.`;
|
|
|
3478
3688
|
});
|
|
3479
3689
|
if (agentData && "models" in agentData && agentData.models?.base?.model) {
|
|
3480
3690
|
modelToUse = agentData.models.base;
|
|
3481
|
-
|
|
3691
|
+
logger10.info(
|
|
3482
3692
|
{
|
|
3483
3693
|
sessionId: this.sessionId,
|
|
3484
3694
|
artifactId: artifactData.artifactId,
|
|
@@ -3489,7 +3699,7 @@ Make it specific and relevant.`;
|
|
|
3489
3699
|
);
|
|
3490
3700
|
}
|
|
3491
3701
|
} catch (error) {
|
|
3492
|
-
|
|
3702
|
+
logger10.warn(
|
|
3493
3703
|
{
|
|
3494
3704
|
sessionId: this.sessionId,
|
|
3495
3705
|
artifactId: artifactData.artifactId,
|
|
@@ -3501,7 +3711,7 @@ Make it specific and relevant.`;
|
|
|
3501
3711
|
}
|
|
3502
3712
|
}
|
|
3503
3713
|
if (!modelToUse?.model?.trim()) {
|
|
3504
|
-
|
|
3714
|
+
logger10.warn(
|
|
3505
3715
|
{
|
|
3506
3716
|
sessionId: this.sessionId,
|
|
3507
3717
|
artifactId: artifactData.artifactId
|
|
@@ -3522,9 +3732,9 @@ Make it specific and relevant.`;
|
|
|
3522
3732
|
};
|
|
3523
3733
|
} else {
|
|
3524
3734
|
const model = ModelFactory.createModel(modelToUse);
|
|
3525
|
-
const schema =
|
|
3526
|
-
name:
|
|
3527
|
-
description:
|
|
3735
|
+
const schema = z6.z.object({
|
|
3736
|
+
name: z6.z.string().describe("Concise, descriptive name for the artifact"),
|
|
3737
|
+
description: z6.z.string().describe("Brief description of the artifact's relevance to the user's question")
|
|
3528
3738
|
});
|
|
3529
3739
|
const { object } = await tracer.startActiveSpan(
|
|
3530
3740
|
"graph_session.generate_artifact_metadata",
|
|
@@ -3534,8 +3744,12 @@ Make it specific and relevant.`;
|
|
|
3534
3744
|
"llm.operation": "generate_object",
|
|
3535
3745
|
"artifact.id": artifactData.artifactId,
|
|
3536
3746
|
"artifact.type": artifactData.artifactType,
|
|
3537
|
-
"artifact.summary": JSON.stringify(artifactData.
|
|
3538
|
-
"artifact.full": JSON.stringify(
|
|
3747
|
+
"artifact.summary": JSON.stringify(artifactData.summaryData, null, 2),
|
|
3748
|
+
"artifact.full": JSON.stringify(
|
|
3749
|
+
artifactData.data || artifactData.summaryData,
|
|
3750
|
+
null,
|
|
3751
|
+
2
|
|
3752
|
+
),
|
|
3539
3753
|
"prompt.length": prompt.length
|
|
3540
3754
|
}
|
|
3541
3755
|
},
|
|
@@ -3565,8 +3779,12 @@ Make it specific and relevant.`;
|
|
|
3565
3779
|
"artifact.type": artifactData.artifactType,
|
|
3566
3780
|
"artifact.name": result2.object.name,
|
|
3567
3781
|
"artifact.description": result2.object.description,
|
|
3568
|
-
"artifact.summary": JSON.stringify(artifactData.
|
|
3569
|
-
"artifact.full": JSON.stringify(
|
|
3782
|
+
"artifact.summary": JSON.stringify(artifactData.summaryData, null, 2),
|
|
3783
|
+
"artifact.full": JSON.stringify(
|
|
3784
|
+
artifactData.data || artifactData.summaryData,
|
|
3785
|
+
null,
|
|
3786
|
+
2
|
|
3787
|
+
),
|
|
3570
3788
|
"generation.name_length": result2.object.name.length,
|
|
3571
3789
|
"generation.description_length": result2.object.description.length,
|
|
3572
3790
|
"generation.attempts": attempt
|
|
@@ -3575,7 +3793,7 @@ Make it specific and relevant.`;
|
|
|
3575
3793
|
return result2;
|
|
3576
3794
|
} catch (error) {
|
|
3577
3795
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
3578
|
-
|
|
3796
|
+
logger10.warn(
|
|
3579
3797
|
{
|
|
3580
3798
|
sessionId: this.sessionId,
|
|
3581
3799
|
artifactId: artifactData.artifactId,
|
|
@@ -3615,9 +3833,9 @@ Make it specific and relevant.`;
|
|
|
3615
3833
|
name: result.name,
|
|
3616
3834
|
description: result.description,
|
|
3617
3835
|
type: artifactData.artifactType || "source",
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3836
|
+
data: artifactData.data || {},
|
|
3837
|
+
metadata: artifactData.metadata || {},
|
|
3838
|
+
toolCallId: artifactData.toolCallId
|
|
3621
3839
|
});
|
|
3622
3840
|
mainSaveSucceeded = true;
|
|
3623
3841
|
span.setAttributes({
|
|
@@ -3627,7 +3845,7 @@ Make it specific and relevant.`;
|
|
|
3627
3845
|
});
|
|
3628
3846
|
span.setStatus({ code: api.SpanStatusCode.OK });
|
|
3629
3847
|
} catch (saveError) {
|
|
3630
|
-
|
|
3848
|
+
logger10.error(
|
|
3631
3849
|
{
|
|
3632
3850
|
sessionId: this.sessionId,
|
|
3633
3851
|
artifactId: artifactData.artifactId,
|
|
@@ -3651,11 +3869,11 @@ Make it specific and relevant.`;
|
|
|
3651
3869
|
name: `Artifact ${artifactData.artifactId.substring(0, 8)}`,
|
|
3652
3870
|
description: `${artifactData.artifactType || "Data"} from ${artifactData.metadata?.toolName || "tool results"}`,
|
|
3653
3871
|
type: artifactData.artifactType || "source",
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3872
|
+
data: artifactData.data || {},
|
|
3873
|
+
metadata: artifactData.metadata || {},
|
|
3874
|
+
toolCallId: artifactData.toolCallId
|
|
3657
3875
|
});
|
|
3658
|
-
|
|
3876
|
+
logger10.info(
|
|
3659
3877
|
{
|
|
3660
3878
|
sessionId: this.sessionId,
|
|
3661
3879
|
artifactId: artifactData.artifactId
|
|
@@ -3666,7 +3884,7 @@ Make it specific and relevant.`;
|
|
|
3666
3884
|
} catch (fallbackError) {
|
|
3667
3885
|
const isDuplicateError = fallbackError instanceof Error && (fallbackError.message?.includes("UNIQUE") || fallbackError.message?.includes("duplicate"));
|
|
3668
3886
|
if (isDuplicateError) ; else {
|
|
3669
|
-
|
|
3887
|
+
logger10.error(
|
|
3670
3888
|
{
|
|
3671
3889
|
sessionId: this.sessionId,
|
|
3672
3890
|
artifactId: artifactData.artifactId,
|
|
@@ -3679,7 +3897,7 @@ Make it specific and relevant.`;
|
|
|
3679
3897
|
}
|
|
3680
3898
|
} catch (error) {
|
|
3681
3899
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
3682
|
-
|
|
3900
|
+
logger10.error(
|
|
3683
3901
|
{
|
|
3684
3902
|
sessionId: this.sessionId,
|
|
3685
3903
|
artifactId: artifactData.artifactId,
|
|
@@ -3698,7 +3916,7 @@ Make it specific and relevant.`;
|
|
|
3698
3916
|
*/
|
|
3699
3917
|
setArtifactCache(key, artifact) {
|
|
3700
3918
|
this.artifactCache.set(key, artifact);
|
|
3701
|
-
|
|
3919
|
+
logger10.debug({ sessionId: this.sessionId, key }, "Artifact cached in session");
|
|
3702
3920
|
}
|
|
3703
3921
|
/**
|
|
3704
3922
|
* Get session-scoped ArtifactService instance
|
|
@@ -3717,9 +3935,17 @@ Make it specific and relevant.`;
|
|
|
3717
3935
|
*/
|
|
3718
3936
|
getArtifactCache(key) {
|
|
3719
3937
|
const artifact = this.artifactCache.get(key);
|
|
3720
|
-
|
|
3938
|
+
logger10.debug({ sessionId: this.sessionId, key, found: !!artifact }, "Artifact cache lookup");
|
|
3721
3939
|
return artifact || null;
|
|
3722
3940
|
}
|
|
3941
|
+
/**
|
|
3942
|
+
* Update artifact components in the shared ArtifactService
|
|
3943
|
+
*/
|
|
3944
|
+
updateArtifactComponents(artifactComponents) {
|
|
3945
|
+
if (this.artifactService) {
|
|
3946
|
+
this.artifactService.updateArtifactComponents(artifactComponents);
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3723
3949
|
};
|
|
3724
3950
|
var GraphSessionManager = class {
|
|
3725
3951
|
constructor() {
|
|
@@ -3732,7 +3958,7 @@ var GraphSessionManager = class {
|
|
|
3732
3958
|
const sessionId = messageId;
|
|
3733
3959
|
const session = new GraphSession(sessionId, messageId, graphId, tenantId, projectId, contextId);
|
|
3734
3960
|
this.sessions.set(sessionId, session);
|
|
3735
|
-
|
|
3961
|
+
logger10.info(
|
|
3736
3962
|
{ sessionId, messageId, graphId, tenantId, projectId, contextId },
|
|
3737
3963
|
"GraphSession created"
|
|
3738
3964
|
);
|
|
@@ -3746,7 +3972,7 @@ var GraphSessionManager = class {
|
|
|
3746
3972
|
if (session) {
|
|
3747
3973
|
session.initializeStatusUpdates(config, summarizerModel);
|
|
3748
3974
|
} else {
|
|
3749
|
-
|
|
3975
|
+
logger10.error(
|
|
3750
3976
|
{
|
|
3751
3977
|
sessionId,
|
|
3752
3978
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -3763,7 +3989,7 @@ var GraphSessionManager = class {
|
|
|
3763
3989
|
if (session) {
|
|
3764
3990
|
session.enableEmitOperations();
|
|
3765
3991
|
} else {
|
|
3766
|
-
|
|
3992
|
+
logger10.error(
|
|
3767
3993
|
{
|
|
3768
3994
|
sessionId,
|
|
3769
3995
|
availableSessions: Array.from(this.sessions.keys())
|
|
@@ -3784,7 +4010,7 @@ var GraphSessionManager = class {
|
|
|
3784
4010
|
recordEvent(sessionId, eventType, agentId, data) {
|
|
3785
4011
|
const session = this.sessions.get(sessionId);
|
|
3786
4012
|
if (!session) {
|
|
3787
|
-
|
|
4013
|
+
logger10.warn({ sessionId }, "Attempted to record event in non-existent session");
|
|
3788
4014
|
return;
|
|
3789
4015
|
}
|
|
3790
4016
|
session.recordEvent(eventType, agentId, data);
|
|
@@ -3795,12 +4021,12 @@ var GraphSessionManager = class {
|
|
|
3795
4021
|
endSession(sessionId) {
|
|
3796
4022
|
const session = this.sessions.get(sessionId);
|
|
3797
4023
|
if (!session) {
|
|
3798
|
-
|
|
4024
|
+
logger10.warn({ sessionId }, "Attempted to end non-existent session");
|
|
3799
4025
|
return [];
|
|
3800
4026
|
}
|
|
3801
4027
|
const events = session.getEvents();
|
|
3802
4028
|
const summary = session.getSummary();
|
|
3803
|
-
|
|
4029
|
+
logger10.info({ sessionId, summary }, "GraphSession ended");
|
|
3804
4030
|
session.cleanup();
|
|
3805
4031
|
this.sessions.delete(sessionId);
|
|
3806
4032
|
return events;
|
|
@@ -3854,12 +4080,61 @@ var GraphSessionManager = class {
|
|
|
3854
4080
|
const session = this.sessions.get(sessionId);
|
|
3855
4081
|
return session ? session.getArtifactParser() : null;
|
|
3856
4082
|
}
|
|
4083
|
+
/**
|
|
4084
|
+
* Update artifact components for a session
|
|
4085
|
+
*/
|
|
4086
|
+
updateArtifactComponents(sessionId, artifactComponents) {
|
|
4087
|
+
const session = this.sessions.get(sessionId);
|
|
4088
|
+
if (session) {
|
|
4089
|
+
session.updateArtifactComponents(artifactComponents);
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
3857
4092
|
};
|
|
3858
4093
|
var graphSessionManager = new GraphSessionManager();
|
|
3859
4094
|
|
|
4095
|
+
// src/utils/model-resolver.ts
|
|
4096
|
+
init_dbClient();
|
|
4097
|
+
async function resolveModelConfig(graphId, agent) {
|
|
4098
|
+
if (agent.models?.base?.model) {
|
|
4099
|
+
return {
|
|
4100
|
+
base: agent.models.base,
|
|
4101
|
+
structuredOutput: agent.models.structuredOutput || agent.models.base,
|
|
4102
|
+
summarizer: agent.models.summarizer || agent.models.base
|
|
4103
|
+
};
|
|
4104
|
+
}
|
|
4105
|
+
const graph = await agentsCore.getAgentGraphById(dbClient_default)({
|
|
4106
|
+
scopes: { tenantId: agent.tenantId, projectId: agent.projectId, graphId }
|
|
4107
|
+
});
|
|
4108
|
+
if (graph?.models?.base?.model) {
|
|
4109
|
+
return {
|
|
4110
|
+
base: graph.models.base,
|
|
4111
|
+
structuredOutput: agent.models?.structuredOutput || graph.models.structuredOutput || graph.models.base,
|
|
4112
|
+
summarizer: agent.models?.summarizer || graph.models.summarizer || graph.models.base
|
|
4113
|
+
};
|
|
4114
|
+
}
|
|
4115
|
+
const project = await agentsCore.getProject(dbClient_default)({
|
|
4116
|
+
scopes: { tenantId: agent.tenantId, projectId: agent.projectId }
|
|
4117
|
+
});
|
|
4118
|
+
if (project?.models?.base?.model) {
|
|
4119
|
+
return {
|
|
4120
|
+
base: project.models.base,
|
|
4121
|
+
structuredOutput: agent.models?.structuredOutput || project.models.structuredOutput || project.models.base,
|
|
4122
|
+
summarizer: agent.models?.summarizer || project.models.summarizer || project.models.base
|
|
4123
|
+
};
|
|
4124
|
+
}
|
|
4125
|
+
throw new Error(
|
|
4126
|
+
"Base model configuration is required. Please configure models at the project level."
|
|
4127
|
+
);
|
|
4128
|
+
}
|
|
4129
|
+
|
|
4130
|
+
// src/agents/Agent.ts
|
|
4131
|
+
init_conversations();
|
|
4132
|
+
init_dbClient();
|
|
4133
|
+
init_logger();
|
|
4134
|
+
|
|
3860
4135
|
// src/services/IncrementalStreamParser.ts
|
|
3861
4136
|
init_logger();
|
|
3862
|
-
var
|
|
4137
|
+
var logger11 = agentsCore.getLogger("IncrementalStreamParser");
|
|
3863
4138
|
var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
3864
4139
|
// Max number of collected parts to prevent unbounded growth
|
|
3865
4140
|
constructor(streamHelper, tenantId, contextId, artifactParserOptions) {
|
|
@@ -3888,9 +4163,20 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3888
4163
|
return;
|
|
3889
4164
|
}
|
|
3890
4165
|
}
|
|
4166
|
+
let sharedArtifactService = null;
|
|
4167
|
+
if (artifactParserOptions?.streamRequestId && typeof graphSessionManager.getArtifactService === "function") {
|
|
4168
|
+
try {
|
|
4169
|
+
sharedArtifactService = graphSessionManager.getArtifactService(
|
|
4170
|
+
artifactParserOptions.streamRequestId
|
|
4171
|
+
);
|
|
4172
|
+
} catch (error) {
|
|
4173
|
+
}
|
|
4174
|
+
}
|
|
3891
4175
|
this.artifactParser = new ArtifactParser(tenantId, {
|
|
3892
4176
|
...artifactParserOptions,
|
|
3893
|
-
contextId
|
|
4177
|
+
contextId,
|
|
4178
|
+
artifactService: sharedArtifactService
|
|
4179
|
+
// Use shared ArtifactService if available
|
|
3894
4180
|
});
|
|
3895
4181
|
}
|
|
3896
4182
|
/**
|
|
@@ -3900,7 +4186,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3900
4186
|
async initializeArtifactMap() {
|
|
3901
4187
|
try {
|
|
3902
4188
|
this.artifactMap = await this.artifactParser.getContextArtifacts(this.contextId);
|
|
3903
|
-
|
|
4189
|
+
logger11.debug(
|
|
3904
4190
|
{
|
|
3905
4191
|
contextId: this.contextId,
|
|
3906
4192
|
artifactMapSize: this.artifactMap.size
|
|
@@ -3908,7 +4194,7 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
3908
4194
|
"Initialized artifact map for streaming"
|
|
3909
4195
|
);
|
|
3910
4196
|
} catch (error) {
|
|
3911
|
-
|
|
4197
|
+
logger11.warn({ error, contextId: this.contextId }, "Failed to initialize artifact map");
|
|
3912
4198
|
this.artifactMap = /* @__PURE__ */ new Map();
|
|
3913
4199
|
}
|
|
3914
4200
|
}
|
|
@@ -4005,9 +4291,13 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4005
4291
|
* Note: Text components are handled separately with incremental streaming
|
|
4006
4292
|
*/
|
|
4007
4293
|
async streamComponent(component) {
|
|
4008
|
-
const parts = await this.artifactParser.parseObject(
|
|
4009
|
-
|
|
4010
|
-
|
|
4294
|
+
const parts = await this.artifactParser.parseObject(
|
|
4295
|
+
{
|
|
4296
|
+
dataComponents: [component]
|
|
4297
|
+
},
|
|
4298
|
+
this.artifactMap,
|
|
4299
|
+
this.agentId
|
|
4300
|
+
);
|
|
4011
4301
|
if (!Array.isArray(parts)) {
|
|
4012
4302
|
console.warn("parseObject returned non-array:", parts);
|
|
4013
4303
|
return;
|
|
@@ -4077,9 +4367,13 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4077
4367
|
const componentKey = component.id;
|
|
4078
4368
|
const hasBeenStreamed = this.lastStreamedComponents.has(componentKey);
|
|
4079
4369
|
if (!hasBeenStreamed && this.isComponentComplete(component) && component.name !== "Text") {
|
|
4080
|
-
const parts = await this.artifactParser.parseObject(
|
|
4081
|
-
|
|
4082
|
-
|
|
4370
|
+
const parts = await this.artifactParser.parseObject(
|
|
4371
|
+
{
|
|
4372
|
+
dataComponents: [component]
|
|
4373
|
+
},
|
|
4374
|
+
this.artifactMap,
|
|
4375
|
+
this.agentId
|
|
4376
|
+
);
|
|
4083
4377
|
for (const part of parts) {
|
|
4084
4378
|
await this.streamPart(part);
|
|
4085
4379
|
}
|
|
@@ -4144,7 +4438,11 @@ var _IncrementalStreamParser = class _IncrementalStreamParser {
|
|
|
4144
4438
|
remainingBuffer: workingBuffer
|
|
4145
4439
|
};
|
|
4146
4440
|
}
|
|
4147
|
-
const parts = await this.artifactParser.parseText(
|
|
4441
|
+
const parts = await this.artifactParser.parseText(
|
|
4442
|
+
workingBuffer,
|
|
4443
|
+
this.artifactMap,
|
|
4444
|
+
this.agentId
|
|
4445
|
+
);
|
|
4148
4446
|
if (parts.length > 0 && parts[parts.length - 1].kind === "text") {
|
|
4149
4447
|
const lastPart = parts[parts.length - 1];
|
|
4150
4448
|
const lastText = lastPart.text || "";
|
|
@@ -4217,20 +4515,35 @@ var IncrementalStreamParser = _IncrementalStreamParser;
|
|
|
4217
4515
|
|
|
4218
4516
|
// src/services/ResponseFormatter.ts
|
|
4219
4517
|
init_logger();
|
|
4220
|
-
var
|
|
4518
|
+
var logger12 = agentsCore.getLogger("ResponseFormatter");
|
|
4221
4519
|
var ResponseFormatter = class {
|
|
4222
4520
|
constructor(tenantId, artifactParserOptions) {
|
|
4223
4521
|
__publicField(this, "artifactParser");
|
|
4224
4522
|
__publicField(this, "agentId");
|
|
4225
4523
|
this.agentId = artifactParserOptions?.agentId;
|
|
4226
4524
|
if (artifactParserOptions?.streamRequestId) {
|
|
4227
|
-
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4525
|
+
const sessionParser = graphSessionManager.getArtifactParser(
|
|
4526
|
+
artifactParserOptions.streamRequestId
|
|
4527
|
+
);
|
|
4228
4528
|
if (sessionParser) {
|
|
4229
4529
|
this.artifactParser = sessionParser;
|
|
4230
4530
|
return;
|
|
4231
4531
|
}
|
|
4232
4532
|
}
|
|
4233
|
-
|
|
4533
|
+
let sharedArtifactService = null;
|
|
4534
|
+
if (artifactParserOptions?.streamRequestId && typeof graphSessionManager.getArtifactService === "function") {
|
|
4535
|
+
try {
|
|
4536
|
+
sharedArtifactService = graphSessionManager.getArtifactService(
|
|
4537
|
+
artifactParserOptions.streamRequestId
|
|
4538
|
+
);
|
|
4539
|
+
} catch (error) {
|
|
4540
|
+
}
|
|
4541
|
+
}
|
|
4542
|
+
this.artifactParser = new ArtifactParser(tenantId, {
|
|
4543
|
+
...artifactParserOptions,
|
|
4544
|
+
artifactService: sharedArtifactService
|
|
4545
|
+
// Use shared ArtifactService if available
|
|
4546
|
+
});
|
|
4234
4547
|
}
|
|
4235
4548
|
/**
|
|
4236
4549
|
* Process structured object response and replace artifact markers with actual artifacts
|
|
@@ -4243,7 +4556,11 @@ var ResponseFormatter = class {
|
|
|
4243
4556
|
"response.type": "object",
|
|
4244
4557
|
"response.availableArtifacts": artifactMap.size
|
|
4245
4558
|
});
|
|
4246
|
-
const parts = await this.artifactParser.parseObject(
|
|
4559
|
+
const parts = await this.artifactParser.parseObject(
|
|
4560
|
+
responseObject,
|
|
4561
|
+
artifactMap,
|
|
4562
|
+
this.agentId
|
|
4563
|
+
);
|
|
4247
4564
|
const uniqueArtifacts = this.countUniqueArtifacts(parts);
|
|
4248
4565
|
span.setAttributes({
|
|
4249
4566
|
"response.dataPartsCount": parts.length,
|
|
@@ -4257,7 +4574,7 @@ var ResponseFormatter = class {
|
|
|
4257
4574
|
return { parts };
|
|
4258
4575
|
} catch (error) {
|
|
4259
4576
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4260
|
-
|
|
4577
|
+
logger12.error({ error, responseObject }, "Error formatting object response");
|
|
4261
4578
|
return {
|
|
4262
4579
|
parts: [{ kind: "data", data: responseObject }]
|
|
4263
4580
|
};
|
|
@@ -4309,7 +4626,7 @@ var ResponseFormatter = class {
|
|
|
4309
4626
|
return { parts };
|
|
4310
4627
|
} catch (error) {
|
|
4311
4628
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
4312
|
-
|
|
4629
|
+
logger12.error({ error, responseText }, "Error formatting response");
|
|
4313
4630
|
return { text: responseText };
|
|
4314
4631
|
} finally {
|
|
4315
4632
|
span.end();
|
|
@@ -4391,11 +4708,11 @@ init_logger();
|
|
|
4391
4708
|
|
|
4392
4709
|
// src/utils/data-component-schema.ts
|
|
4393
4710
|
init_logger();
|
|
4394
|
-
var
|
|
4711
|
+
var logger13 = agentsCore.getLogger("DataComponentSchema");
|
|
4395
4712
|
function jsonSchemaToZod(jsonSchema) {
|
|
4396
4713
|
if (!jsonSchema || typeof jsonSchema !== "object") {
|
|
4397
|
-
|
|
4398
|
-
return
|
|
4714
|
+
logger13.warn({ jsonSchema }, "Invalid JSON schema provided, using string fallback");
|
|
4715
|
+
return z6.z.string();
|
|
4399
4716
|
}
|
|
4400
4717
|
switch (jsonSchema.type) {
|
|
4401
4718
|
case "object":
|
|
@@ -4404,31 +4721,31 @@ function jsonSchemaToZod(jsonSchema) {
|
|
|
4404
4721
|
for (const [key, prop] of Object.entries(jsonSchema.properties)) {
|
|
4405
4722
|
shape[key] = jsonSchemaToZod(prop);
|
|
4406
4723
|
}
|
|
4407
|
-
return
|
|
4724
|
+
return z6.z.object(shape);
|
|
4408
4725
|
}
|
|
4409
|
-
return
|
|
4726
|
+
return z6.z.record(z6.z.string(), z6.z.unknown());
|
|
4410
4727
|
case "array": {
|
|
4411
|
-
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) :
|
|
4412
|
-
return
|
|
4728
|
+
const itemSchema = jsonSchema.items ? jsonSchemaToZod(jsonSchema.items) : z6.z.unknown();
|
|
4729
|
+
return z6.z.array(itemSchema);
|
|
4413
4730
|
}
|
|
4414
4731
|
case "string":
|
|
4415
|
-
return
|
|
4732
|
+
return z6.z.string();
|
|
4416
4733
|
case "number":
|
|
4417
4734
|
case "integer":
|
|
4418
|
-
return
|
|
4735
|
+
return z6.z.number();
|
|
4419
4736
|
case "boolean":
|
|
4420
|
-
return
|
|
4737
|
+
return z6.z.boolean();
|
|
4421
4738
|
case "null":
|
|
4422
|
-
return
|
|
4739
|
+
return z6.z.null();
|
|
4423
4740
|
default:
|
|
4424
|
-
|
|
4741
|
+
logger13.warn(
|
|
4425
4742
|
{
|
|
4426
4743
|
unsupportedType: jsonSchema.type,
|
|
4427
4744
|
schema: jsonSchema
|
|
4428
4745
|
},
|
|
4429
4746
|
"Unsupported JSON schema type, using unknown validation"
|
|
4430
4747
|
);
|
|
4431
|
-
return
|
|
4748
|
+
return z6.z.unknown();
|
|
4432
4749
|
}
|
|
4433
4750
|
}
|
|
4434
4751
|
|
|
@@ -4656,9 +4973,9 @@ var _ArtifactReferenceSchema = class _ArtifactReferenceSchema {
|
|
|
4656
4973
|
* Get the standard Zod schema for artifact reference components
|
|
4657
4974
|
*/
|
|
4658
4975
|
static getSchema() {
|
|
4659
|
-
return
|
|
4660
|
-
id:
|
|
4661
|
-
name:
|
|
4976
|
+
return z6.z.object({
|
|
4977
|
+
id: z6.z.string(),
|
|
4978
|
+
name: z6.z.literal("Artifact"),
|
|
4662
4979
|
props: jsonSchemaToZod(_ArtifactReferenceSchema.ARTIFACT_PROPS_SCHEMA)
|
|
4663
4980
|
});
|
|
4664
4981
|
}
|
|
@@ -4700,8 +5017,7 @@ var ArtifactCreateSchema = class {
|
|
|
4700
5017
|
*/
|
|
4701
5018
|
static getSchemas(artifactComponents) {
|
|
4702
5019
|
return artifactComponents.map((component) => {
|
|
4703
|
-
const
|
|
4704
|
-
const enhancedFullProps = SchemaProcessor.enhanceSchemaWithJMESPathGuidance(component.fullProps);
|
|
5020
|
+
const enhancedSchema = component.props ? SchemaProcessor.enhanceSchemaWithJMESPathGuidance(component.props) : { type: "object", properties: {} };
|
|
4705
5021
|
const propsSchema = {
|
|
4706
5022
|
type: "object",
|
|
4707
5023
|
properties: {
|
|
@@ -4720,16 +5036,15 @@ var ArtifactCreateSchema = class {
|
|
|
4720
5036
|
},
|
|
4721
5037
|
base_selector: {
|
|
4722
5038
|
type: "string",
|
|
4723
|
-
description: `JMESPath selector starting with "result." to navigate to ONE specific item.
|
|
5039
|
+
description: `JMESPath selector starting with "result." to navigate to ONE specific item. Details selector will be relative to this selection. Use filtering to avoid arrays (e.g., "result.items[?type=='guide']").`
|
|
4724
5040
|
},
|
|
4725
|
-
|
|
4726
|
-
full_props: enhancedFullProps
|
|
5041
|
+
details_selector: enhancedSchema
|
|
4727
5042
|
},
|
|
4728
5043
|
required: ["id", "tool_call_id", "type", "base_selector"]
|
|
4729
5044
|
};
|
|
4730
|
-
return
|
|
4731
|
-
id:
|
|
4732
|
-
name:
|
|
5045
|
+
return z6.z.object({
|
|
5046
|
+
id: z6.z.string(),
|
|
5047
|
+
name: z6.z.literal(`ArtifactCreate_${component.name}`),
|
|
4733
5048
|
props: jsonSchemaToZod(propsSchema)
|
|
4734
5049
|
});
|
|
4735
5050
|
});
|
|
@@ -4741,8 +5056,7 @@ var ArtifactCreateSchema = class {
|
|
|
4741
5056
|
*/
|
|
4742
5057
|
static getDataComponents(tenantId, projectId = "", artifactComponents) {
|
|
4743
5058
|
return artifactComponents.map((component) => {
|
|
4744
|
-
const
|
|
4745
|
-
const enhancedFullProps = SchemaProcessor.enhanceSchemaWithJMESPathGuidance(component.fullProps);
|
|
5059
|
+
const enhancedSchema = component.props ? SchemaProcessor.enhanceSchemaWithJMESPathGuidance(component.props) : { type: "object", properties: {} };
|
|
4746
5060
|
const propsSchema = {
|
|
4747
5061
|
type: "object",
|
|
4748
5062
|
properties: {
|
|
@@ -4761,10 +5075,9 @@ var ArtifactCreateSchema = class {
|
|
|
4761
5075
|
},
|
|
4762
5076
|
base_selector: {
|
|
4763
5077
|
type: "string",
|
|
4764
|
-
description: `JMESPath selector starting with "result." to navigate to ONE specific item.
|
|
5078
|
+
description: `JMESPath selector starting with "result." to navigate to ONE specific item. Details selector will be relative to this selection. Use filtering to avoid arrays (e.g., "result.items[?type=='guide']").`
|
|
4765
5079
|
},
|
|
4766
|
-
|
|
4767
|
-
full_props: enhancedFullProps
|
|
5080
|
+
details_selector: enhancedSchema
|
|
4768
5081
|
},
|
|
4769
5082
|
required: ["id", "tool_call_id", "type", "base_selector"]
|
|
4770
5083
|
};
|
|
@@ -4792,7 +5105,7 @@ function parseEmbeddedJson(data) {
|
|
|
4792
5105
|
|
|
4793
5106
|
// src/a2a/client.ts
|
|
4794
5107
|
init_logger();
|
|
4795
|
-
var
|
|
5108
|
+
var logger14 = agentsCore.getLogger("a2aClient");
|
|
4796
5109
|
var DEFAULT_BACKOFF = {
|
|
4797
5110
|
initialInterval: 500,
|
|
4798
5111
|
maxInterval: 6e4,
|
|
@@ -4998,7 +5311,7 @@ var A2AClient = class {
|
|
|
4998
5311
|
try {
|
|
4999
5312
|
const res = await fn();
|
|
5000
5313
|
if (attempt > 0) {
|
|
5001
|
-
|
|
5314
|
+
logger14.info(
|
|
5002
5315
|
{
|
|
5003
5316
|
attempts: attempt + 1,
|
|
5004
5317
|
elapsedTime: Date.now() - start
|
|
@@ -5013,7 +5326,7 @@ var A2AClient = class {
|
|
|
5013
5326
|
}
|
|
5014
5327
|
const elapsed = Date.now() - start;
|
|
5015
5328
|
if (elapsed > maxElapsedTime) {
|
|
5016
|
-
|
|
5329
|
+
logger14.warn(
|
|
5017
5330
|
{
|
|
5018
5331
|
attempts: attempt + 1,
|
|
5019
5332
|
elapsedTime: elapsed,
|
|
@@ -5034,7 +5347,7 @@ var A2AClient = class {
|
|
|
5034
5347
|
retryInterval = initialInterval * attempt ** exponent + Math.random() * 1e3;
|
|
5035
5348
|
}
|
|
5036
5349
|
const delayMs = Math.min(retryInterval, maxInterval);
|
|
5037
|
-
|
|
5350
|
+
logger14.info(
|
|
5038
5351
|
{
|
|
5039
5352
|
attempt: attempt + 1,
|
|
5040
5353
|
delayMs,
|
|
@@ -5119,7 +5432,7 @@ var A2AClient = class {
|
|
|
5119
5432
|
}
|
|
5120
5433
|
const rpcResponse = await httpResponse.json();
|
|
5121
5434
|
if (rpcResponse.id !== requestId2) {
|
|
5122
|
-
|
|
5435
|
+
logger14.warn(
|
|
5123
5436
|
{
|
|
5124
5437
|
method,
|
|
5125
5438
|
expectedId: requestId2,
|
|
@@ -5318,7 +5631,7 @@ var A2AClient = class {
|
|
|
5318
5631
|
try {
|
|
5319
5632
|
while (true) {
|
|
5320
5633
|
const { done, value } = await reader.read();
|
|
5321
|
-
|
|
5634
|
+
logger14.info({ done, value }, "parseA2ASseStream");
|
|
5322
5635
|
if (done) {
|
|
5323
5636
|
if (eventDataBuffer.trim()) {
|
|
5324
5637
|
const result = this._processSseEventData(
|
|
@@ -5408,7 +5721,7 @@ var A2AClient = class {
|
|
|
5408
5721
|
init_conversations();
|
|
5409
5722
|
init_dbClient();
|
|
5410
5723
|
init_logger();
|
|
5411
|
-
var
|
|
5724
|
+
var logger15 = agentsCore.getLogger("relationships Tools");
|
|
5412
5725
|
var generateTransferToolDescription = (config) => {
|
|
5413
5726
|
return `Hand off the conversation to agent ${config.id}.
|
|
5414
5727
|
|
|
@@ -5437,7 +5750,7 @@ var createTransferToAgentTool = ({
|
|
|
5437
5750
|
}) => {
|
|
5438
5751
|
return ai.tool({
|
|
5439
5752
|
description: generateTransferToolDescription(transferConfig),
|
|
5440
|
-
inputSchema:
|
|
5753
|
+
inputSchema: z6__default.default.object({}),
|
|
5441
5754
|
execute: async () => {
|
|
5442
5755
|
const activeSpan = api.trace.getActiveSpan();
|
|
5443
5756
|
if (activeSpan) {
|
|
@@ -5446,7 +5759,7 @@ var createTransferToAgentTool = ({
|
|
|
5446
5759
|
"transfer.to_agent_id": transferConfig.id ?? "unknown"
|
|
5447
5760
|
});
|
|
5448
5761
|
}
|
|
5449
|
-
|
|
5762
|
+
logger15.info(
|
|
5450
5763
|
{
|
|
5451
5764
|
transferTo: transferConfig.id ?? "unknown",
|
|
5452
5765
|
fromAgent: callingAgentId
|
|
@@ -5483,7 +5796,7 @@ function createDelegateToAgentTool({
|
|
|
5483
5796
|
}) {
|
|
5484
5797
|
return ai.tool({
|
|
5485
5798
|
description: generateDelegateToolDescription(delegateConfig.config),
|
|
5486
|
-
inputSchema:
|
|
5799
|
+
inputSchema: z6__default.default.object({ message: z6__default.default.string() }),
|
|
5487
5800
|
execute: async (input, context) => {
|
|
5488
5801
|
const delegationId = `del_${nanoid.nanoid()}`;
|
|
5489
5802
|
const activeSpan = api.trace.getActiveSpan();
|
|
@@ -5595,7 +5908,7 @@ function createDelegateToAgentTool({
|
|
|
5595
5908
|
...isInternal ? { fromAgentId: callingAgentId } : { fromExternalAgentId: callingAgentId }
|
|
5596
5909
|
}
|
|
5597
5910
|
};
|
|
5598
|
-
|
|
5911
|
+
logger15.info({ messageToSend }, "messageToSend");
|
|
5599
5912
|
await agentsCore.createMessage(dbClient_default)({
|
|
5600
5913
|
id: nanoid.nanoid(),
|
|
5601
5914
|
tenantId,
|
|
@@ -5658,7 +5971,7 @@ function createDelegateToAgentTool({
|
|
|
5658
5971
|
|
|
5659
5972
|
// src/agents/SystemPromptBuilder.ts
|
|
5660
5973
|
init_logger();
|
|
5661
|
-
var
|
|
5974
|
+
var logger16 = agentsCore.getLogger("SystemPromptBuilder");
|
|
5662
5975
|
var SystemPromptBuilder = class {
|
|
5663
5976
|
constructor(version, versionConfig) {
|
|
5664
5977
|
this.version = version;
|
|
@@ -5674,12 +5987,12 @@ var SystemPromptBuilder = class {
|
|
|
5674
5987
|
this.templates.set(name, content);
|
|
5675
5988
|
}
|
|
5676
5989
|
this.loaded = true;
|
|
5677
|
-
|
|
5990
|
+
logger16.debug(
|
|
5678
5991
|
{ templateCount: this.templates.size, version: this.version },
|
|
5679
5992
|
`Loaded ${this.templates.size} templates for version ${this.version}`
|
|
5680
5993
|
);
|
|
5681
5994
|
} catch (error) {
|
|
5682
|
-
|
|
5995
|
+
logger16.error({ error }, `Failed to load templates for version ${this.version}`);
|
|
5683
5996
|
throw new Error(`Template loading failed: ${error}`);
|
|
5684
5997
|
}
|
|
5685
5998
|
}
|
|
@@ -5704,68 +6017,6 @@ var SystemPromptBuilder = class {
|
|
|
5704
6017
|
}
|
|
5705
6018
|
};
|
|
5706
6019
|
|
|
5707
|
-
// templates/v1/shared/artifact.xml?raw
|
|
5708
|
-
var artifact_default = "<artifact>\n <name>{{ARTIFACT_NAME}}</name>\n <description>{{ARTIFACT_DESCRIPTION}}</description>\n <task_id>{{TASK_ID}}</task_id>\n <artifact_id>{{ARTIFACT_ID}}</artifact_id>\n <tool_call_id>{{TOOL_CALL_ID}}</tool_call_id>\n <summary_data>{{ARTIFACT_SUMMARY}}</summary_data>\n</artifact> ";
|
|
5709
|
-
|
|
5710
|
-
// templates/v1/shared/artifact-retrieval-guidance.xml?raw
|
|
5711
|
-
var artifact_retrieval_guidance_default = `ARTIFACT RETRIEVAL: ACCESSING EXISTING ARTIFACT DATA
|
|
5712
|
-
|
|
5713
|
-
\u{1F6A8} **CRITICAL: ALWAYS CHECK EXISTING ARTIFACTS FIRST** \u{1F6A8}
|
|
5714
|
-
Before creating new artifacts, ALWAYS examine existing artifacts to see if they contain relevant information for the current topic or question.
|
|
5715
|
-
|
|
5716
|
-
You CAN and SHOULD retrieve information from existing artifacts to answer user questions.
|
|
5717
|
-
Available artifacts contain structured data that you can access in two ways:
|
|
5718
|
-
|
|
5719
|
-
1. **SUMMARY DATA**: Read the summary_data directly from available artifacts for basic information
|
|
5720
|
-
2. **FULL DATA**: Use the get_artifact tool to retrieve complete artifact data (both summary_data and full_data) when you need detailed information
|
|
5721
|
-
|
|
5722
|
-
**REUSE EXISTING ARTIFACTS WHEN POSSIBLE:**
|
|
5723
|
-
- Look for artifacts with similar topics, names, or descriptions
|
|
5724
|
-
- Check if existing artifacts can answer the current question
|
|
5725
|
-
- Use existing artifact data instead of creating duplicates
|
|
5726
|
-
- Only create new artifacts if existing ones don't contain the needed information
|
|
5727
|
-
- Prioritize reusing relevant existing artifacts over creating new ones
|
|
5728
|
-
|
|
5729
|
-
HOW TO USE ARTIFACT DATA:
|
|
5730
|
-
- Read summary_data from available artifacts for quick answers
|
|
5731
|
-
- Use get_artifact tool when you need comprehensive details
|
|
5732
|
-
- Extract specific information to answer user questions accurately
|
|
5733
|
-
- Reference artifacts when citing the information source
|
|
5734
|
-
- Combine information from multiple existing artifacts when relevant
|
|
5735
|
-
|
|
5736
|
-
\u{1F6A8} **MANDATORY CITATION POLICY** \u{1F6A8}
|
|
5737
|
-
EVERY piece of information from existing artifacts MUST be properly cited:
|
|
5738
|
-
- When referencing information from existing artifacts = MUST cite with artifact reference
|
|
5739
|
-
- When discussing artifact data = MUST cite the artifact source
|
|
5740
|
-
- When using artifact information = MUST reference the artifact
|
|
5741
|
-
- NO INFORMATION from existing artifacts can be presented without proper citation
|
|
5742
|
-
|
|
5743
|
-
CITATION PLACEMENT RULES:
|
|
5744
|
-
- ALWAYS place artifact citations AFTER complete thoughts and punctuation
|
|
5745
|
-
- Never interrupt a sentence or thought with an artifact citation
|
|
5746
|
-
- Complete your sentence or thought, add punctuation, THEN add the citation
|
|
5747
|
-
- This maintains natural reading flow and professional presentation
|
|
5748
|
-
|
|
5749
|
-
\u2705 CORRECT EXAMPLES:
|
|
5750
|
-
- "The API uses OAuth 2.0 authentication. <artifact:create id='auth-doc' ...> This process involves three main steps..."
|
|
5751
|
-
- "Based on the documentation, there are several authentication methods available. <artifact:create id='auth-methods' ...> The recommended approach is OAuth 2.0."
|
|
5752
|
-
|
|
5753
|
-
\u274C WRONG EXAMPLES:
|
|
5754
|
-
- "The API uses <artifact:create id='auth-doc' ...> OAuth 2.0 authentication which involves..."
|
|
5755
|
-
- "According to <artifact:create id='auth-doc' ...>, the authentication method is OAuth 2.0."
|
|
5756
|
-
|
|
5757
|
-
\u{1F3AF} **KEY PRINCIPLE**: Information from tools \u2192 Complete thought \u2192 Punctuation \u2192 Citation \u2192 Continue
|
|
5758
|
-
|
|
5759
|
-
DELEGATION AND ARTIFACTS:
|
|
5760
|
-
When you use delegation tools, the response may include artifacts in the parts array. These appear as objects with:
|
|
5761
|
-
- kind: "data"
|
|
5762
|
-
- data: { artifactId, toolCallId, name, description, type, artifactSummary }
|
|
5763
|
-
|
|
5764
|
-
These artifacts become immediately available for you to reference using the artifactId and toolCallId from the response.
|
|
5765
|
-
Present delegation results naturally without mentioning the delegation process itself.
|
|
5766
|
-
|
|
5767
|
-
IMPORTANT: All agents can retrieve and use information from existing artifacts when the graph has artifact components, regardless of whether the individual agent can create new artifacts.`;
|
|
5768
|
-
|
|
5769
6020
|
// templates/v1/phase1/system-prompt.xml?raw
|
|
5770
6021
|
var system_prompt_default = `<system_message>
|
|
5771
6022
|
<agent_identity>
|
|
@@ -5882,6 +6133,68 @@ var thinking_preparation_default = `<thinking_preparation_mode>
|
|
|
5882
6133
|
// templates/v1/phase1/tool.xml?raw
|
|
5883
6134
|
var tool_default = "<tool>\n <name>{{TOOL_NAME}}</name>\n <description>{{TOOL_DESCRIPTION}}</description>\n <parameters>\n <schema>\n {{TOOL_PARAMETERS_SCHEMA}}\n </schema>\n </parameters>\n <usage_guidelines>\n {{TOOL_USAGE_GUIDELINES}}\n </usage_guidelines>\n</tool> ";
|
|
5884
6135
|
|
|
6136
|
+
// templates/v1/shared/artifact.xml?raw
|
|
6137
|
+
var artifact_default = "<artifact>\n <name>{{ARTIFACT_NAME}}</name>\n <description>{{ARTIFACT_DESCRIPTION}}</description>\n <task_id>{{TASK_ID}}</task_id>\n <artifact_id>{{ARTIFACT_ID}}</artifact_id>\n <tool_call_id>{{TOOL_CALL_ID}}</tool_call_id>\n <summary_data>{{ARTIFACT_SUMMARY}}</summary_data>\n <!-- NOTE: This shows summary/preview data only. Use get_reference_artifact tool to get complete artifact data if needed. -->\n</artifact> ";
|
|
6138
|
+
|
|
6139
|
+
// templates/v1/shared/artifact-retrieval-guidance.xml?raw
|
|
6140
|
+
var artifact_retrieval_guidance_default = `ARTIFACT RETRIEVAL: ACCESSING EXISTING ARTIFACT DATA
|
|
6141
|
+
|
|
6142
|
+
\u{1F6A8} **CRITICAL: ALWAYS CHECK EXISTING ARTIFACTS FIRST** \u{1F6A8}
|
|
6143
|
+
Before creating new artifacts, ALWAYS examine existing artifacts to see if they contain relevant information for the current topic or question.
|
|
6144
|
+
|
|
6145
|
+
You CAN and SHOULD retrieve information from existing artifacts to answer user questions.
|
|
6146
|
+
Available artifacts contain structured data that you can access in two ways:
|
|
6147
|
+
|
|
6148
|
+
1. **SUMMARY DATA**: Read the summary_data directly from available artifacts for basic information
|
|
6149
|
+
2. **FULL DATA**: Use the get_artifact tool to retrieve complete artifact data (both summary_data and full_data) when you need detailed information
|
|
6150
|
+
|
|
6151
|
+
**REUSE EXISTING ARTIFACTS WHEN POSSIBLE:**
|
|
6152
|
+
- Look for artifacts with similar topics, names, or descriptions
|
|
6153
|
+
- Check if existing artifacts can answer the current question
|
|
6154
|
+
- Use existing artifact data instead of creating duplicates
|
|
6155
|
+
- Only create new artifacts if existing ones don't contain the needed information
|
|
6156
|
+
- Prioritize reusing relevant existing artifacts over creating new ones
|
|
6157
|
+
|
|
6158
|
+
HOW TO USE ARTIFACT DATA:
|
|
6159
|
+
- Read summary_data from available artifacts for quick answers
|
|
6160
|
+
- Use get_artifact tool when you need comprehensive details
|
|
6161
|
+
- Extract specific information to answer user questions accurately
|
|
6162
|
+
- Reference artifacts when citing the information source
|
|
6163
|
+
- Combine information from multiple existing artifacts when relevant
|
|
6164
|
+
|
|
6165
|
+
\u{1F6A8} **MANDATORY CITATION POLICY** \u{1F6A8}
|
|
6166
|
+
EVERY piece of information from existing artifacts MUST be properly cited:
|
|
6167
|
+
- When referencing information from existing artifacts = MUST cite with artifact reference
|
|
6168
|
+
- When discussing artifact data = MUST cite the artifact source
|
|
6169
|
+
- When using artifact information = MUST reference the artifact
|
|
6170
|
+
- NO INFORMATION from existing artifacts can be presented without proper citation
|
|
6171
|
+
|
|
6172
|
+
CITATION PLACEMENT RULES:
|
|
6173
|
+
- ALWAYS place artifact citations AFTER complete thoughts and punctuation
|
|
6174
|
+
- Never interrupt a sentence or thought with an artifact citation
|
|
6175
|
+
- Complete your sentence or thought, add punctuation, THEN add the citation
|
|
6176
|
+
- This maintains natural reading flow and professional presentation
|
|
6177
|
+
|
|
6178
|
+
\u2705 CORRECT EXAMPLES:
|
|
6179
|
+
- "The API uses OAuth 2.0 authentication. <artifact:create id='auth-doc' ...> This process involves three main steps..."
|
|
6180
|
+
- "Based on the documentation, there are several authentication methods available. <artifact:create id='auth-methods' ...> The recommended approach is OAuth 2.0."
|
|
6181
|
+
|
|
6182
|
+
\u274C WRONG EXAMPLES:
|
|
6183
|
+
- "The API uses <artifact:create id='auth-doc' ...> OAuth 2.0 authentication which involves..."
|
|
6184
|
+
- "According to <artifact:create id='auth-doc' ...>, the authentication method is OAuth 2.0."
|
|
6185
|
+
|
|
6186
|
+
\u{1F3AF} **KEY PRINCIPLE**: Information from tools \u2192 Complete thought \u2192 Punctuation \u2192 Citation \u2192 Continue
|
|
6187
|
+
|
|
6188
|
+
DELEGATION AND ARTIFACTS:
|
|
6189
|
+
When you use delegation tools, the response may include artifacts in the parts array. These appear as objects with:
|
|
6190
|
+
- kind: "data"
|
|
6191
|
+
- data: { artifactId, toolCallId, name, description, type, artifactSummary }
|
|
6192
|
+
|
|
6193
|
+
These artifacts become immediately available for you to reference using the artifactId and toolCallId from the response.
|
|
6194
|
+
Present delegation results naturally without mentioning the delegation process itself.
|
|
6195
|
+
|
|
6196
|
+
IMPORTANT: All agents can retrieve and use information from existing artifacts when the graph has artifact components, regardless of whether the individual agent can create new artifacts.`;
|
|
6197
|
+
|
|
5885
6198
|
// src/agents/versions/v1/Phase1Config.ts
|
|
5886
6199
|
init_logger();
|
|
5887
6200
|
agentsCore.getLogger("Phase1Config");
|
|
@@ -6018,8 +6331,8 @@ SELECTOR REQUIREMENTS:
|
|
|
6018
6331
|
|
|
6019
6332
|
CRITICAL: SELECTOR HIERARCHY
|
|
6020
6333
|
- base_selector: Points to ONE specific item in the tool result
|
|
6021
|
-
-
|
|
6022
|
-
- Example: If base="result.documents[?type=='api']" then
|
|
6334
|
+
- details_selector: Contains JMESPath selectors RELATIVE to the base selector
|
|
6335
|
+
- Example: If base="result.documents[?type=='api']" then details_selector uses "title" not "documents[0].title"
|
|
6023
6336
|
|
|
6024
6337
|
COMMON FAILURE POINTS (AVOID THESE):
|
|
6025
6338
|
1. **Array Selection**: result.items (returns array) \u274C
|
|
@@ -6051,24 +6364,22 @@ You will create and reference artifacts using inline annotations in your text re
|
|
|
6051
6364
|
|
|
6052
6365
|
CREATING ARTIFACTS (SERVES AS CITATION):
|
|
6053
6366
|
Use the artifact:create annotation to extract data from tool results. The creation itself serves as a citation.
|
|
6054
|
-
Format: <artifact:create id="unique-id" tool="tool_call_id" type="TypeName" base="selector.path"
|
|
6367
|
+
Format: <artifact:create id="unique-id" tool="tool_call_id" type="TypeName" base="selector.path" details='{"key":"jmespath_selector"}' />
|
|
6055
6368
|
|
|
6056
|
-
\u{1F6A8} CRITICAL:
|
|
6369
|
+
\u{1F6A8} CRITICAL: DETAILS PROPS USE JMESPATH SELECTORS, NOT LITERAL VALUES! \u{1F6A8}
|
|
6057
6370
|
|
|
6058
6371
|
\u274C WRONG - Using literal values:
|
|
6059
|
-
|
|
6060
|
-
full='{"description":"This is a comprehensive guide..."}'
|
|
6372
|
+
details='{"title":"API Documentation","type":"guide"}'
|
|
6061
6373
|
|
|
6062
6374
|
\u2705 CORRECT - Using JMESPath selectors (relative to base selector):
|
|
6063
|
-
|
|
6064
|
-
full='{"description":"content.description","main_text":"content.text","author":"metadata.author"}'
|
|
6375
|
+
details='{"title":"metadata.title","doc_type":"document_type","description":"content.description","main_text":"content.text","author":"metadata.author"}'
|
|
6065
6376
|
|
|
6066
6377
|
The selectors extract actual field values from the data structure selected by your base selector.
|
|
6067
6378
|
|
|
6068
|
-
THE
|
|
6069
|
-
-
|
|
6070
|
-
- full: Contains JMESPath selectors relative to the base selector
|
|
6379
|
+
THE details PROPERTY MUST CONTAIN JMESPATH SELECTORS THAT EXTRACT DATA FROM THE TOOL RESULT!
|
|
6380
|
+
- details: Contains JMESPath selectors relative to the base selector that map to artifact schema fields
|
|
6071
6381
|
- These selectors are evaluated against the tool result to extract the actual values
|
|
6382
|
+
- The system automatically determines which fields are preview vs full based on the artifact schema
|
|
6072
6383
|
- NEVER put literal values like "Inkeep" or "2023" - always use selectors like "metadata.company" or "founded_year"
|
|
6073
6384
|
|
|
6074
6385
|
\u{1F6AB} FORBIDDEN JMESPATH PATTERNS:
|
|
@@ -6128,7 +6439,7 @@ Only use artifact:ref when you need to cite the SAME artifact again for a differ
|
|
|
6128
6439
|
Format: <artifact:ref id="artifact-id" tool="tool_call_id" />
|
|
6129
6440
|
|
|
6130
6441
|
EXAMPLE TEXT RESPONSE:
|
|
6131
|
-
"I found the authentication documentation. <artifact:create id='auth-doc-1' tool='call_xyz789' type='APIDoc' base='result.documents[?type=="auth"]'
|
|
6442
|
+
"I found the authentication documentation. <artifact:create id='auth-doc-1' tool='call_xyz789' type='APIDoc' base='result.documents[?type=="auth"]' details='{"title":"metadata.title","endpoint":"api.endpoint","description":"content.description","parameters":"spec.parameters","examples":"examples.sample_code"}' /> The documentation explains OAuth 2.0 implementation in detail.
|
|
6132
6443
|
|
|
6133
6444
|
The process involves three main steps: registration, token exchange, and API calls. As mentioned in the authentication documentation <artifact:ref id='auth-doc-1' tool='call_xyz789' />, you'll need to register your application first."
|
|
6134
6445
|
|
|
@@ -6184,31 +6495,29 @@ IMPORTANT GUIDELINES:
|
|
|
6184
6495
|
return "";
|
|
6185
6496
|
}
|
|
6186
6497
|
const typeDescriptions = artifactComponents.map((ac) => {
|
|
6187
|
-
let
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
const fullDetails = Object.entries(ac.fullProps.properties).map(([key, value]) => `${key} (${value.description || value.type || "field"})`).join(", ");
|
|
6195
|
-
fullSchema = `Available: ${fullDetails}`;
|
|
6498
|
+
let schemaDescription = "No schema defined";
|
|
6499
|
+
if (ac.props?.properties) {
|
|
6500
|
+
const fieldDetails = Object.entries(ac.props.properties).map(([key, value]) => {
|
|
6501
|
+
const inPreview = value.inPreview ? " [PREVIEW]" : " [FULL]";
|
|
6502
|
+
return `${key} (${value.description || value.type || "field"})${inPreview}`;
|
|
6503
|
+
}).join(", ");
|
|
6504
|
+
schemaDescription = `Fields: ${fieldDetails}`;
|
|
6196
6505
|
}
|
|
6197
6506
|
return ` - "${ac.name}": ${ac.description || "No description available"}
|
|
6198
|
-
|
|
6199
|
-
Full Props: ${fullSchema}`;
|
|
6507
|
+
${schemaDescription}`;
|
|
6200
6508
|
}).join("\n\n");
|
|
6201
6509
|
return `
|
|
6202
6510
|
AVAILABLE ARTIFACT TYPES:
|
|
6203
6511
|
|
|
6204
6512
|
${typeDescriptions}
|
|
6205
6513
|
|
|
6206
|
-
\u{1F6A8} CRITICAL:
|
|
6514
|
+
\u{1F6A8} CRITICAL: DETAILS PROPS MUST MATCH THE ARTIFACT SCHEMA! \u{1F6A8}
|
|
6207
6515
|
- Only use property names that are defined in the artifact component schema above
|
|
6208
6516
|
- Do NOT make up arbitrary property names like "founders", "nick_details", "year"
|
|
6209
|
-
- Each artifact type has specific
|
|
6517
|
+
- Each artifact type has specific fields defined in its schema
|
|
6210
6518
|
- Your JMESPath selectors must extract values for these exact schema-defined properties
|
|
6211
|
-
- Example: If schema defines "title" and "url", use
|
|
6519
|
+
- Example: If schema defines "title" and "url", use details='{"title":"title","url":"url"}' not made-up names
|
|
6520
|
+
- The system will automatically determine which fields are preview vs full based on schema configuration
|
|
6212
6521
|
|
|
6213
6522
|
\u{1F6A8} CRITICAL: USE EXACT ARTIFACT TYPE NAMES IN QUOTES! \u{1F6A8}
|
|
6214
6523
|
- MUST use the exact type name shown in quotes above
|
|
@@ -6219,7 +6528,11 @@ ${typeDescriptions}
|
|
|
6219
6528
|
}
|
|
6220
6529
|
generateArtifactsSection(templates, artifacts, hasArtifactComponents = false, artifactComponents, hasGraphArtifactComponents) {
|
|
6221
6530
|
const shouldShowReferencingRules = hasGraphArtifactComponents || artifacts.length > 0;
|
|
6222
|
-
const rules = this.getArtifactReferencingRules(
|
|
6531
|
+
const rules = this.getArtifactReferencingRules(
|
|
6532
|
+
hasArtifactComponents,
|
|
6533
|
+
templates,
|
|
6534
|
+
shouldShowReferencingRules
|
|
6535
|
+
);
|
|
6223
6536
|
const creationInstructions = this.getArtifactCreationInstructions(
|
|
6224
6537
|
hasArtifactComponents,
|
|
6225
6538
|
artifactComponents
|
|
@@ -6314,6 +6627,12 @@ ${propertiesXml}
|
|
|
6314
6627
|
}
|
|
6315
6628
|
};
|
|
6316
6629
|
|
|
6630
|
+
// templates/v1/phase2/data-component.xml?raw
|
|
6631
|
+
var data_component_default = "<data-component>\n <name>{{COMPONENT_NAME}}</name>\n <description>{{COMPONENT_DESCRIPTION}}</description>\n <props>\n <schema>\n {{COMPONENT_PROPS_SCHEMA}}\n </schema>\n </props>\n</data-component> ";
|
|
6632
|
+
|
|
6633
|
+
// templates/v1/phase2/data-components.xml?raw
|
|
6634
|
+
var data_components_default = '<data_components_section description="These are the data components available for you to use in generating responses. Each component represents a single structured piece of information. You can create multiple instances of the same component type when needed.\n\n***MANDATORY JSON RESPONSE FORMAT - ABSOLUTELY CRITICAL***:\n- WHEN DATA COMPONENTS ARE AVAILABLE, YOU MUST RESPOND IN JSON FORMAT ONLY\n- DO NOT respond with plain text when data components are defined\n- YOUR RESPONSE MUST BE STRUCTURED JSON WITH dataComponents ARRAY\n- THIS IS NON-NEGOTIABLE - JSON FORMAT IS REQUIRED\n\nCRITICAL JSON FORMATTING RULES - MUST FOLLOW EXACTLY:\n1. Each data component must include id, name, and props fields\n2. The id and name should match the exact component definition\n3. The props field contains the actual component data using exact property names from the schema\n4. NEVER omit the id and name fields\n\nCORRECT: [{\\"id\\": \\"component1\\", \\"name\\": \\"Component1\\", \\"props\\": {\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}}, {\\"id\\": \\"component2\\", \\"name\\": \\"Component2\\", \\"props\\": {\\"field3\\": \\"value3\\"}}]\nWRONG: [{\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}, {\\"field3\\": \\"value3\\"}]\n\nAVAILABLE DATA COMPONENTS: {{DATA_COMPONENTS_LIST}}">\n\n{{DATA_COMPONENTS_XML}}\n\n</data_components_section>';
|
|
6635
|
+
|
|
6317
6636
|
// templates/v1/phase2/system-prompt.xml?raw
|
|
6318
6637
|
var system_prompt_default2 = `<phase2_system_message>
|
|
6319
6638
|
<instruction>
|
|
@@ -6353,12 +6672,6 @@ var system_prompt_default2 = `<phase2_system_message>
|
|
|
6353
6672
|
</requirements>
|
|
6354
6673
|
</phase2_system_message>`;
|
|
6355
6674
|
|
|
6356
|
-
// templates/v1/phase2/data-components.xml?raw
|
|
6357
|
-
var data_components_default = '<data_components_section description="These are the data components available for you to use in generating responses. Each component represents a single structured piece of information. You can create multiple instances of the same component type when needed.\n\n***MANDATORY JSON RESPONSE FORMAT - ABSOLUTELY CRITICAL***:\n- WHEN DATA COMPONENTS ARE AVAILABLE, YOU MUST RESPOND IN JSON FORMAT ONLY\n- DO NOT respond with plain text when data components are defined\n- YOUR RESPONSE MUST BE STRUCTURED JSON WITH dataComponents ARRAY\n- THIS IS NON-NEGOTIABLE - JSON FORMAT IS REQUIRED\n\nCRITICAL JSON FORMATTING RULES - MUST FOLLOW EXACTLY:\n1. Each data component must include id, name, and props fields\n2. The id and name should match the exact component definition\n3. The props field contains the actual component data using exact property names from the schema\n4. NEVER omit the id and name fields\n\nCORRECT: [{\\"id\\": \\"component1\\", \\"name\\": \\"Component1\\", \\"props\\": {\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}}, {\\"id\\": \\"component2\\", \\"name\\": \\"Component2\\", \\"props\\": {\\"field3\\": \\"value3\\"}}]\nWRONG: [{\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}, {\\"field3\\": \\"value3\\"}]\n\nAVAILABLE DATA COMPONENTS: {{DATA_COMPONENTS_LIST}}">\n\n{{DATA_COMPONENTS_XML}}\n\n</data_components_section>';
|
|
6358
|
-
|
|
6359
|
-
// templates/v1/phase2/data-component.xml?raw
|
|
6360
|
-
var data_component_default = "<data-component>\n <name>{{COMPONENT_NAME}}</name>\n <description>{{COMPONENT_DESCRIPTION}}</description>\n <props>\n <schema>\n {{COMPONENT_PROPS_SCHEMA}}\n </schema>\n </props>\n</data-component> ";
|
|
6361
|
-
|
|
6362
6675
|
// src/agents/versions/v1/Phase2Config.ts
|
|
6363
6676
|
var Phase2Config = class {
|
|
6364
6677
|
getArtifactCreationGuidance() {
|
|
@@ -6404,17 +6717,15 @@ When the same field names appear at different levels (like 'content', 'title', '
|
|
|
6404
6717
|
|
|
6405
6718
|
CRITICAL: SELECTOR HIERARCHY
|
|
6406
6719
|
- base_selector: Points to ONE specific item in the tool result
|
|
6407
|
-
-
|
|
6408
|
-
- Example: If base="result.documents[?type=='api']" then
|
|
6720
|
+
- details_selector: Contains JMESPath selectors RELATIVE to the base selector
|
|
6721
|
+
- Example: If base="result.documents[?type=='api']" then details_selector uses "title" not "documents[0].title"
|
|
6409
6722
|
|
|
6410
6723
|
\u274C WRONG EXAMPLE:
|
|
6411
6724
|
{
|
|
6412
6725
|
"base_selector": "result.content[?title=='Guide']",
|
|
6413
|
-
"
|
|
6726
|
+
"details_selector": {
|
|
6414
6727
|
"title": "Guide", // \u274C This is a literal value, not a selector!
|
|
6415
|
-
"url": "result.content[?title=='Guide'].url" // \u274C This is absolute, not relative!
|
|
6416
|
-
},
|
|
6417
|
-
"full_props": {
|
|
6728
|
+
"url": "result.content[?title=='Guide'].url", // \u274C This is absolute, not relative!
|
|
6418
6729
|
"description": "A comprehensive guide", // \u274C Literal value instead of selector!
|
|
6419
6730
|
"content": "result.content[?title=='Guide'].content" // \u274C Absolute path instead of relative!
|
|
6420
6731
|
}
|
|
@@ -6423,11 +6734,9 @@ CRITICAL: SELECTOR HIERARCHY
|
|
|
6423
6734
|
\u2705 CORRECT EXAMPLE:
|
|
6424
6735
|
{
|
|
6425
6736
|
"base_selector": "result.content[?title=='Guide']",
|
|
6426
|
-
"
|
|
6737
|
+
"details_selector": {
|
|
6427
6738
|
"title": "title", // \u2705 Relative selector to get title field
|
|
6428
|
-
"url": "url" // \u2705 Relative selector to get url field
|
|
6429
|
-
},
|
|
6430
|
-
"full_props": {
|
|
6739
|
+
"url": "url", // \u2705 Relative selector to get url field
|
|
6431
6740
|
"description": "description", // \u2705 Relative selector
|
|
6432
6741
|
"content": "content", // \u2705 Relative selector
|
|
6433
6742
|
"metadata": "metadata.details" // \u2705 Relative selector with nesting
|
|
@@ -6513,8 +6822,7 @@ EXAMPLE STRUCTURED RESPONSE:
|
|
|
6513
6822
|
"tool_call_id": "call_abc123",
|
|
6514
6823
|
"type": "APIDoc",
|
|
6515
6824
|
"base_selector": "result.documents[?type=='api']",
|
|
6516
|
-
"
|
|
6517
|
-
"full_props": {"description": "content.description", "parameters": "spec.parameters", "examples": "examples.sample_code"}
|
|
6825
|
+
"details_selector": {"title": "metadata.title", "endpoint": "api.endpoint", "description": "content.description", "parameters": "spec.parameters", "examples": "examples.sample_code"}
|
|
6518
6826
|
}
|
|
6519
6827
|
},
|
|
6520
6828
|
{
|
|
@@ -6594,14 +6902,14 @@ IMPORTANT GUIDELINES:
|
|
|
6594
6902
|
return "";
|
|
6595
6903
|
}
|
|
6596
6904
|
const componentDescriptions = artifactComponents.map((ac) => {
|
|
6597
|
-
const
|
|
6598
|
-
|
|
6905
|
+
const schemaProps = ac.props?.properties ? Object.entries(ac.props.properties).map(([key, value]) => {
|
|
6906
|
+
const inPreview = value.inPreview ? " [PREVIEW]" : " [FULL]";
|
|
6907
|
+
return ` - ${key}: ${value.description || "Field from tool result"}${inPreview}`;
|
|
6908
|
+
}).join("\n") : " No properties defined";
|
|
6599
6909
|
return ` ArtifactCreate_${ac.name}:
|
|
6600
6910
|
Description: ${ac.description || "Extract and structure data"}
|
|
6601
|
-
|
|
6602
|
-
${
|
|
6603
|
-
Full Properties:
|
|
6604
|
-
${fullProps}`;
|
|
6911
|
+
Schema Properties:
|
|
6912
|
+
${schemaProps}`;
|
|
6605
6913
|
}).join("\n\n");
|
|
6606
6914
|
return `
|
|
6607
6915
|
AVAILABLE ARTIFACT TYPES:
|
|
@@ -6615,8 +6923,14 @@ ${componentDescriptions}`;
|
|
|
6615
6923
|
const dataComponentsDescription = dataComponents.map((dc) => `${dc.name}: ${dc.description}`).join(", ");
|
|
6616
6924
|
const dataComponentsXml = dataComponents.map((dataComponent) => this.generateDataComponentXml(dataComponent)).join("\n ");
|
|
6617
6925
|
let dataComponentsSection = data_components_default;
|
|
6618
|
-
dataComponentsSection = dataComponentsSection.replace(
|
|
6619
|
-
|
|
6926
|
+
dataComponentsSection = dataComponentsSection.replace(
|
|
6927
|
+
"{{DATA_COMPONENTS_LIST}}",
|
|
6928
|
+
dataComponentsDescription
|
|
6929
|
+
);
|
|
6930
|
+
dataComponentsSection = dataComponentsSection.replace(
|
|
6931
|
+
"{{DATA_COMPONENTS_XML}}",
|
|
6932
|
+
dataComponentsXml
|
|
6933
|
+
);
|
|
6620
6934
|
return dataComponentsSection;
|
|
6621
6935
|
}
|
|
6622
6936
|
generateDataComponentXml(dataComponent) {
|
|
@@ -6688,14 +7002,21 @@ ${artifact_retrieval_guidance_default}
|
|
|
6688
7002
|
* Assemble the complete Phase 2 system prompt for structured output generation
|
|
6689
7003
|
*/
|
|
6690
7004
|
assemblePhase2Prompt(config) {
|
|
6691
|
-
const {
|
|
7005
|
+
const {
|
|
7006
|
+
corePrompt,
|
|
7007
|
+
dataComponents,
|
|
7008
|
+
artifactComponents,
|
|
7009
|
+
hasArtifactComponents,
|
|
7010
|
+
hasGraphArtifactComponents,
|
|
7011
|
+
artifacts = []
|
|
7012
|
+
} = config;
|
|
6692
7013
|
let allDataComponents = [...dataComponents];
|
|
6693
7014
|
if (hasArtifactComponents && artifactComponents) {
|
|
6694
7015
|
const artifactCreateComponents = ArtifactCreateSchema.getDataComponents(
|
|
6695
7016
|
"tenant",
|
|
6696
7017
|
// placeholder - not used in Phase2
|
|
6697
7018
|
"",
|
|
6698
|
-
// placeholder - not used in Phase2
|
|
7019
|
+
// placeholder - not used in Phase2
|
|
6699
7020
|
artifactComponents
|
|
6700
7021
|
);
|
|
6701
7022
|
allDataComponents = [...dataComponents, ...artifactCreateComponents];
|
|
@@ -6703,8 +7024,15 @@ ${artifact_retrieval_guidance_default}
|
|
|
6703
7024
|
const dataComponentsSection = this.generateDataComponentsSection(allDataComponents);
|
|
6704
7025
|
const artifactsSection = this.generateArtifactsSection(artifacts);
|
|
6705
7026
|
const shouldShowReferencingRules = hasGraphArtifactComponents || artifacts.length > 0;
|
|
6706
|
-
const artifactGuidance = this.getStructuredArtifactGuidance(
|
|
6707
|
-
|
|
7027
|
+
const artifactGuidance = this.getStructuredArtifactGuidance(
|
|
7028
|
+
hasArtifactComponents,
|
|
7029
|
+
artifactComponents,
|
|
7030
|
+
shouldShowReferencingRules
|
|
7031
|
+
);
|
|
7032
|
+
const artifactTypes = this.getArtifactCreationInstructions(
|
|
7033
|
+
hasArtifactComponents,
|
|
7034
|
+
artifactComponents
|
|
7035
|
+
);
|
|
6708
7036
|
let phase2Prompt = system_prompt_default2;
|
|
6709
7037
|
phase2Prompt = phase2Prompt.replace("{{CORE_INSTRUCTIONS}}", corePrompt);
|
|
6710
7038
|
phase2Prompt = phase2Prompt.replace("{{DATA_COMPONENTS_SECTION}}", dataComponentsSection);
|
|
@@ -6725,7 +7053,7 @@ function hasToolCallWithPrefix(prefix) {
|
|
|
6725
7053
|
return false;
|
|
6726
7054
|
};
|
|
6727
7055
|
}
|
|
6728
|
-
var
|
|
7056
|
+
var logger18 = agentsCore.getLogger("Agent");
|
|
6729
7057
|
var CONSTANTS = {
|
|
6730
7058
|
MAX_GENERATION_STEPS: 12,
|
|
6731
7059
|
PHASE_1_TIMEOUT_MS: 27e4,
|
|
@@ -7026,14 +7354,14 @@ var Agent = class {
|
|
|
7026
7354
|
for (const toolSet of tools) {
|
|
7027
7355
|
for (const [toolName, originalTool] of Object.entries(toolSet)) {
|
|
7028
7356
|
if (!isValidTool(originalTool)) {
|
|
7029
|
-
|
|
7357
|
+
logger18.error({ toolName }, "Invalid MCP tool structure - missing required properties");
|
|
7030
7358
|
continue;
|
|
7031
7359
|
}
|
|
7032
7360
|
const sessionWrappedTool = ai.tool({
|
|
7033
7361
|
description: originalTool.description,
|
|
7034
7362
|
inputSchema: originalTool.inputSchema,
|
|
7035
7363
|
execute: async (args, { toolCallId }) => {
|
|
7036
|
-
|
|
7364
|
+
logger18.debug({ toolName, toolCallId }, "MCP Tool Called");
|
|
7037
7365
|
try {
|
|
7038
7366
|
const rawResult = await originalTool.execute(args, { toolCallId });
|
|
7039
7367
|
const parsedResult = parseEmbeddedJson(rawResult);
|
|
@@ -7047,7 +7375,7 @@ var Agent = class {
|
|
|
7047
7375
|
});
|
|
7048
7376
|
return { result: enhancedResult, toolCallId };
|
|
7049
7377
|
} catch (error) {
|
|
7050
|
-
|
|
7378
|
+
logger18.error({ toolName, toolCallId, error }, "MCP tool execution failed");
|
|
7051
7379
|
throw error;
|
|
7052
7380
|
}
|
|
7053
7381
|
}
|
|
@@ -7142,7 +7470,7 @@ var Agent = class {
|
|
|
7142
7470
|
headers: agentToolRelationHeaders
|
|
7143
7471
|
};
|
|
7144
7472
|
}
|
|
7145
|
-
|
|
7473
|
+
logger18.info(
|
|
7146
7474
|
{
|
|
7147
7475
|
toolName: tool3.name,
|
|
7148
7476
|
credentialReferenceId,
|
|
@@ -7167,7 +7495,7 @@ var Agent = class {
|
|
|
7167
7495
|
this.mcpClientCache.set(cacheKey, client);
|
|
7168
7496
|
} catch (error) {
|
|
7169
7497
|
this.mcpConnectionLocks.delete(cacheKey);
|
|
7170
|
-
|
|
7498
|
+
logger18.error(
|
|
7171
7499
|
{
|
|
7172
7500
|
toolName: tool3.name,
|
|
7173
7501
|
agentId: this.config.id,
|
|
@@ -7191,7 +7519,7 @@ var Agent = class {
|
|
|
7191
7519
|
await client.connect();
|
|
7192
7520
|
return client;
|
|
7193
7521
|
} catch (error) {
|
|
7194
|
-
|
|
7522
|
+
logger18.error(
|
|
7195
7523
|
{
|
|
7196
7524
|
toolName: tool3.name,
|
|
7197
7525
|
agentId: this.config.id,
|
|
@@ -7208,7 +7536,7 @@ var Agent = class {
|
|
|
7208
7536
|
for (const funcTool of this.config.functionTools) {
|
|
7209
7537
|
const aiTool = ai.tool({
|
|
7210
7538
|
description: funcTool.description,
|
|
7211
|
-
inputSchema: funcTool.schema ||
|
|
7539
|
+
inputSchema: funcTool.schema || z6.z.object({}),
|
|
7212
7540
|
execute: funcTool.execute
|
|
7213
7541
|
});
|
|
7214
7542
|
functionTools[funcTool.name] = this.wrapToolWithStreaming(
|
|
@@ -7226,7 +7554,7 @@ var Agent = class {
|
|
|
7226
7554
|
async getResolvedContext(conversationId, requestContext) {
|
|
7227
7555
|
try {
|
|
7228
7556
|
if (!this.config.contextConfigId) {
|
|
7229
|
-
|
|
7557
|
+
logger18.debug({ graphId: this.config.graphId }, "No context config found for graph");
|
|
7230
7558
|
return null;
|
|
7231
7559
|
}
|
|
7232
7560
|
const contextConfig = await agentsCore.getContextConfigById(dbClient_default)({
|
|
@@ -7238,7 +7566,7 @@ var Agent = class {
|
|
|
7238
7566
|
id: this.config.contextConfigId
|
|
7239
7567
|
});
|
|
7240
7568
|
if (!contextConfig) {
|
|
7241
|
-
|
|
7569
|
+
logger18.warn({ contextConfigId: this.config.contextConfigId }, "Context config not found");
|
|
7242
7570
|
return null;
|
|
7243
7571
|
}
|
|
7244
7572
|
if (!this.contextResolver) {
|
|
@@ -7255,7 +7583,7 @@ var Agent = class {
|
|
|
7255
7583
|
$now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7256
7584
|
$env: process.env
|
|
7257
7585
|
};
|
|
7258
|
-
|
|
7586
|
+
logger18.debug(
|
|
7259
7587
|
{
|
|
7260
7588
|
conversationId,
|
|
7261
7589
|
contextConfigId: contextConfig.id,
|
|
@@ -7269,7 +7597,7 @@ var Agent = class {
|
|
|
7269
7597
|
);
|
|
7270
7598
|
return contextWithBuiltins;
|
|
7271
7599
|
} catch (error) {
|
|
7272
|
-
|
|
7600
|
+
logger18.error(
|
|
7273
7601
|
{
|
|
7274
7602
|
conversationId,
|
|
7275
7603
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7293,7 +7621,7 @@ var Agent = class {
|
|
|
7293
7621
|
});
|
|
7294
7622
|
return graphDefinition?.graphPrompt || void 0;
|
|
7295
7623
|
} catch (error) {
|
|
7296
|
-
|
|
7624
|
+
logger18.warn(
|
|
7297
7625
|
{
|
|
7298
7626
|
graphId: this.config.graphId,
|
|
7299
7627
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7322,7 +7650,7 @@ var Agent = class {
|
|
|
7322
7650
|
(agent) => "artifactComponents" in agent && agent.artifactComponents && agent.artifactComponents.length > 0
|
|
7323
7651
|
);
|
|
7324
7652
|
} catch (error) {
|
|
7325
|
-
|
|
7653
|
+
logger18.warn(
|
|
7326
7654
|
{
|
|
7327
7655
|
graphId: this.config.graphId,
|
|
7328
7656
|
tenantId: this.config.tenantId,
|
|
@@ -7351,7 +7679,7 @@ var Agent = class {
|
|
|
7351
7679
|
preserveUnresolved: false
|
|
7352
7680
|
});
|
|
7353
7681
|
} catch (error) {
|
|
7354
|
-
|
|
7682
|
+
logger18.error(
|
|
7355
7683
|
{
|
|
7356
7684
|
conversationId,
|
|
7357
7685
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7398,7 +7726,7 @@ var Agent = class {
|
|
|
7398
7726
|
preserveUnresolved: false
|
|
7399
7727
|
});
|
|
7400
7728
|
} catch (error) {
|
|
7401
|
-
|
|
7729
|
+
logger18.error(
|
|
7402
7730
|
{
|
|
7403
7731
|
conversationId,
|
|
7404
7732
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7437,7 +7765,7 @@ var Agent = class {
|
|
|
7437
7765
|
preserveUnresolved: false
|
|
7438
7766
|
});
|
|
7439
7767
|
} catch (error) {
|
|
7440
|
-
|
|
7768
|
+
logger18.error(
|
|
7441
7769
|
{
|
|
7442
7770
|
conversationId,
|
|
7443
7771
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -7464,23 +7792,29 @@ var Agent = class {
|
|
|
7464
7792
|
}
|
|
7465
7793
|
getArtifactTools() {
|
|
7466
7794
|
return ai.tool({
|
|
7467
|
-
description: "Call this tool to get the artifact with the given artifactId.
|
|
7468
|
-
inputSchema:
|
|
7469
|
-
artifactId:
|
|
7795
|
+
description: "Call this tool to get the complete artifact data with the given artifactId. This retrieves the full artifact content (not just the summary). Only use this when you need the complete artifact data and the summary shown in your context is insufficient.",
|
|
7796
|
+
inputSchema: z6.z.object({
|
|
7797
|
+
artifactId: z6.z.string().describe("The unique identifier of the artifact to get."),
|
|
7798
|
+
toolCallId: z6.z.string().describe("The tool call ID associated with this artifact.")
|
|
7470
7799
|
}),
|
|
7471
|
-
execute: async ({ artifactId }) => {
|
|
7472
|
-
|
|
7473
|
-
const
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
},
|
|
7478
|
-
artifactId
|
|
7479
|
-
});
|
|
7480
|
-
if (!artifact) {
|
|
7481
|
-
throw new Error(`Artifact ${artifactId} not found`);
|
|
7800
|
+
execute: async ({ artifactId, toolCallId }) => {
|
|
7801
|
+
logger18.info({ artifactId, toolCallId }, "get_artifact_full executed");
|
|
7802
|
+
const streamRequestId = this.getStreamRequestId();
|
|
7803
|
+
const artifactService = graphSessionManager.getArtifactService(streamRequestId);
|
|
7804
|
+
if (!artifactService) {
|
|
7805
|
+
throw new Error(`ArtifactService not found for session ${streamRequestId}`);
|
|
7482
7806
|
}
|
|
7483
|
-
|
|
7807
|
+
const artifactData = await artifactService.getArtifactFull(artifactId, toolCallId);
|
|
7808
|
+
if (!artifactData) {
|
|
7809
|
+
throw new Error(`Artifact ${artifactId} with toolCallId ${toolCallId} not found`);
|
|
7810
|
+
}
|
|
7811
|
+
return {
|
|
7812
|
+
artifactId: artifactData.artifactId,
|
|
7813
|
+
name: artifactData.name,
|
|
7814
|
+
description: artifactData.description,
|
|
7815
|
+
type: artifactData.type,
|
|
7816
|
+
data: artifactData.data
|
|
7817
|
+
};
|
|
7484
7818
|
}
|
|
7485
7819
|
});
|
|
7486
7820
|
}
|
|
@@ -7488,9 +7822,9 @@ var Agent = class {
|
|
|
7488
7822
|
createThinkingCompleteTool() {
|
|
7489
7823
|
return ai.tool({
|
|
7490
7824
|
description: "\u{1F6A8} CRITICAL: Call this tool IMMEDIATELY when you have gathered enough information to answer the user. This is MANDATORY - you CANNOT provide text responses in thinking mode, only tool calls. Call thinking_complete as soon as you have sufficient data to generate a structured response.",
|
|
7491
|
-
inputSchema:
|
|
7492
|
-
complete:
|
|
7493
|
-
summary:
|
|
7825
|
+
inputSchema: z6.z.object({
|
|
7826
|
+
complete: z6.z.boolean().describe("ALWAYS set to true - marks end of research phase"),
|
|
7827
|
+
summary: z6.z.string().describe(
|
|
7494
7828
|
"Brief summary of what information was gathered and why it is sufficient to answer the user"
|
|
7495
7829
|
)
|
|
7496
7830
|
}),
|
|
@@ -7691,8 +8025,7 @@ var Agent = class {
|
|
|
7691
8025
|
artifactGuidance: {
|
|
7692
8026
|
creationFirst: "\u{1F6A8} CRITICAL: Artifacts must be CREATED before they can be referenced. Use ArtifactCreate_[Type] components FIRST, then reference with Artifact components only if citing the SAME artifact again.",
|
|
7693
8027
|
baseSelector: `\u{1F3AF} CRITICAL: Use base_selector to navigate to ONE specific item. For deeply nested structures with repeated keys, use full paths with specific filtering (e.g., "result.data.content.items[?type=='guide' && status=='active']")`,
|
|
7694
|
-
|
|
7695
|
-
fullProps: '\u{1F4D6} Use relative selectors for detailed data (e.g., "content.details", "specifications.data", "attributes")',
|
|
8028
|
+
detailsSelector: '\u{1F4DD} Use relative selectors for specific fields (e.g., "title", "metadata.category", "properties.status", "content.details")',
|
|
7696
8029
|
avoidLiterals: "\u274C NEVER use literal values - always use field selectors to extract from data",
|
|
7697
8030
|
avoidArrays: "\u2728 ALWAYS filter arrays to single items using [?condition] - NEVER use [*] notation which returns arrays",
|
|
7698
8031
|
nestedKeys: "\u{1F511} For structures with repeated keys (like result.content.data.content.items.content), use full paths with filtering at each level",
|
|
@@ -7719,7 +8052,7 @@ var Agent = class {
|
|
|
7719
8052
|
};
|
|
7720
8053
|
return enhanced;
|
|
7721
8054
|
} catch (error) {
|
|
7722
|
-
|
|
8055
|
+
logger18.warn({ error }, "Failed to enhance tool result with structure hints");
|
|
7723
8056
|
return result;
|
|
7724
8057
|
}
|
|
7725
8058
|
}
|
|
@@ -7734,7 +8067,7 @@ var Agent = class {
|
|
|
7734
8067
|
}
|
|
7735
8068
|
});
|
|
7736
8069
|
} catch (error) {
|
|
7737
|
-
|
|
8070
|
+
logger18.error(
|
|
7738
8071
|
{ error, graphId: this.config.graphId },
|
|
7739
8072
|
"Failed to check graph artifact components"
|
|
7740
8073
|
);
|
|
@@ -7835,7 +8168,7 @@ var Agent = class {
|
|
|
7835
8168
|
const configuredTimeout = modelSettings.maxDuration ? Math.min(modelSettings.maxDuration * 1e3, MAX_ALLOWED_TIMEOUT_MS) : shouldStreamPhase1 ? CONSTANTS.PHASE_1_TIMEOUT_MS : CONSTANTS.NON_STREAMING_PHASE_1_TIMEOUT_MS;
|
|
7836
8169
|
const timeoutMs = Math.min(configuredTimeout, MAX_ALLOWED_TIMEOUT_MS);
|
|
7837
8170
|
if (modelSettings.maxDuration && modelSettings.maxDuration * 1e3 > MAX_ALLOWED_TIMEOUT_MS) {
|
|
7838
|
-
|
|
8171
|
+
logger18.warn(
|
|
7839
8172
|
{
|
|
7840
8173
|
requestedTimeout: modelSettings.maxDuration * 1e3,
|
|
7841
8174
|
appliedTimeout: timeoutMs,
|
|
@@ -7877,7 +8210,7 @@ var Agent = class {
|
|
|
7877
8210
|
}
|
|
7878
8211
|
);
|
|
7879
8212
|
} catch (error) {
|
|
7880
|
-
|
|
8213
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
7881
8214
|
}
|
|
7882
8215
|
}
|
|
7883
8216
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -7981,7 +8314,7 @@ var Agent = class {
|
|
|
7981
8314
|
}
|
|
7982
8315
|
);
|
|
7983
8316
|
} catch (error) {
|
|
7984
|
-
|
|
8317
|
+
logger18.debug({ error }, "Failed to track agent reasoning");
|
|
7985
8318
|
}
|
|
7986
8319
|
}
|
|
7987
8320
|
if (last && "toolCalls" in last && last.toolCalls) {
|
|
@@ -8085,9 +8418,9 @@ ${output}${structureHintsFormatted}`;
|
|
|
8085
8418
|
this.config.dataComponents.forEach((dc) => {
|
|
8086
8419
|
const propsSchema = jsonSchemaToZod(dc.props);
|
|
8087
8420
|
componentSchemas.push(
|
|
8088
|
-
|
|
8089
|
-
id:
|
|
8090
|
-
name:
|
|
8421
|
+
z6.z.object({
|
|
8422
|
+
id: z6.z.string(),
|
|
8423
|
+
name: z6.z.literal(dc.name),
|
|
8091
8424
|
props: propsSchema
|
|
8092
8425
|
})
|
|
8093
8426
|
);
|
|
@@ -8104,7 +8437,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8104
8437
|
if (componentSchemas.length === 1) {
|
|
8105
8438
|
dataComponentsSchema = componentSchemas[0];
|
|
8106
8439
|
} else {
|
|
8107
|
-
dataComponentsSchema =
|
|
8440
|
+
dataComponentsSchema = z6.z.union(
|
|
8108
8441
|
componentSchemas
|
|
8109
8442
|
);
|
|
8110
8443
|
}
|
|
@@ -8128,8 +8461,8 @@ ${output}${structureHintsFormatted}`;
|
|
|
8128
8461
|
const streamResult = ai.streamObject({
|
|
8129
8462
|
...structuredModelSettings,
|
|
8130
8463
|
messages: phase2Messages,
|
|
8131
|
-
schema:
|
|
8132
|
-
dataComponents:
|
|
8464
|
+
schema: z6.z.object({
|
|
8465
|
+
dataComponents: z6.z.array(dataComponentsSchema)
|
|
8133
8466
|
}),
|
|
8134
8467
|
experimental_telemetry: {
|
|
8135
8468
|
isEnabled: true,
|
|
@@ -8197,8 +8530,8 @@ ${output}${structureHintsFormatted}`;
|
|
|
8197
8530
|
withJsonPostProcessing2({
|
|
8198
8531
|
...structuredModelSettings,
|
|
8199
8532
|
messages: phase2Messages,
|
|
8200
|
-
schema:
|
|
8201
|
-
dataComponents:
|
|
8533
|
+
schema: z6.z.object({
|
|
8534
|
+
dataComponents: z6.z.array(dataComponentsSchema)
|
|
8202
8535
|
}),
|
|
8203
8536
|
experimental_telemetry: {
|
|
8204
8537
|
isEnabled: true,
|
|
@@ -8273,7 +8606,7 @@ ${output}${structureHintsFormatted}`;
|
|
|
8273
8606
|
};
|
|
8274
8607
|
|
|
8275
8608
|
// src/agents/generateTaskHandler.ts
|
|
8276
|
-
var
|
|
8609
|
+
var logger19 = agentsCore.getLogger("generateTaskHandler");
|
|
8277
8610
|
var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
8278
8611
|
return async (task) => {
|
|
8279
8612
|
try {
|
|
@@ -8326,7 +8659,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8326
8659
|
}
|
|
8327
8660
|
})
|
|
8328
8661
|
]);
|
|
8329
|
-
|
|
8662
|
+
logger19.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
8330
8663
|
const enhancedInternalRelations = await Promise.all(
|
|
8331
8664
|
internalRelations.map(async (relation) => {
|
|
8332
8665
|
try {
|
|
@@ -8355,7 +8688,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8355
8688
|
return { ...relation, description: enhancedDescription };
|
|
8356
8689
|
}
|
|
8357
8690
|
} catch (error) {
|
|
8358
|
-
|
|
8691
|
+
logger19.warn({ agentId: relation.id, error }, "Failed to enhance agent description");
|
|
8359
8692
|
}
|
|
8360
8693
|
return relation;
|
|
8361
8694
|
})
|
|
@@ -8450,12 +8783,16 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8450
8783
|
},
|
|
8451
8784
|
credentialStoreRegistry
|
|
8452
8785
|
);
|
|
8786
|
+
const artifactStreamRequestId = task.context?.metadata?.streamRequestId;
|
|
8787
|
+
if (artifactStreamRequestId && artifactComponents.length > 0) {
|
|
8788
|
+
graphSessionManager.updateArtifactComponents(artifactStreamRequestId, artifactComponents);
|
|
8789
|
+
}
|
|
8453
8790
|
let contextId = task.context?.conversationId;
|
|
8454
8791
|
if (!contextId || contextId === "default" || contextId === "") {
|
|
8455
8792
|
const taskIdMatch = task.id.match(/^task_([^-]+-[^-]+-\d+)-/);
|
|
8456
8793
|
if (taskIdMatch) {
|
|
8457
8794
|
contextId = taskIdMatch[1];
|
|
8458
|
-
|
|
8795
|
+
logger19.info(
|
|
8459
8796
|
{
|
|
8460
8797
|
taskId: task.id,
|
|
8461
8798
|
extractedContextId: contextId,
|
|
@@ -8471,7 +8808,7 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8471
8808
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
8472
8809
|
agent.setDelegationStatus(isDelegation);
|
|
8473
8810
|
if (isDelegation) {
|
|
8474
|
-
|
|
8811
|
+
logger19.info(
|
|
8475
8812
|
{ agentId: config.agentId, taskId: task.id },
|
|
8476
8813
|
"Delegated agent - streaming disabled"
|
|
8477
8814
|
);
|
|
@@ -8696,7 +9033,7 @@ async function getRegisteredGraph(executionContext) {
|
|
|
8696
9033
|
init_dbClient();
|
|
8697
9034
|
init_logger();
|
|
8698
9035
|
var app = new zodOpenapi.OpenAPIHono();
|
|
8699
|
-
var
|
|
9036
|
+
var logger20 = agentsCore.getLogger("agents");
|
|
8700
9037
|
app.openapi(
|
|
8701
9038
|
zodOpenapi.createRoute({
|
|
8702
9039
|
method: "get",
|
|
@@ -8711,14 +9048,14 @@ app.openapi(
|
|
|
8711
9048
|
description: "Agent Card for A2A discovery",
|
|
8712
9049
|
content: {
|
|
8713
9050
|
"application/json": {
|
|
8714
|
-
schema:
|
|
8715
|
-
name:
|
|
8716
|
-
description:
|
|
8717
|
-
url:
|
|
8718
|
-
version:
|
|
8719
|
-
defaultInputModes:
|
|
8720
|
-
defaultOutputModes:
|
|
8721
|
-
skills:
|
|
9051
|
+
schema: z6.z.object({
|
|
9052
|
+
name: z6.z.string(),
|
|
9053
|
+
description: z6.z.string().optional(),
|
|
9054
|
+
url: z6.z.string(),
|
|
9055
|
+
version: z6.z.string(),
|
|
9056
|
+
defaultInputModes: z6.z.array(z6.z.string()),
|
|
9057
|
+
defaultOutputModes: z6.z.array(z6.z.string()),
|
|
9058
|
+
skills: z6.z.array(z6.z.any())
|
|
8722
9059
|
})
|
|
8723
9060
|
}
|
|
8724
9061
|
}
|
|
@@ -8734,7 +9071,7 @@ app.openapi(
|
|
|
8734
9071
|
tracestate: c.req.header("tracestate"),
|
|
8735
9072
|
baggage: c.req.header("baggage")
|
|
8736
9073
|
};
|
|
8737
|
-
|
|
9074
|
+
logger20.info(
|
|
8738
9075
|
{
|
|
8739
9076
|
otelHeaders,
|
|
8740
9077
|
path: c.req.path,
|
|
@@ -8746,7 +9083,7 @@ app.openapi(
|
|
|
8746
9083
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
8747
9084
|
console.dir("executionContext", executionContext);
|
|
8748
9085
|
if (agentId) {
|
|
8749
|
-
|
|
9086
|
+
logger20.info(
|
|
8750
9087
|
{
|
|
8751
9088
|
message: "getRegisteredAgent (agent-level)",
|
|
8752
9089
|
tenantId,
|
|
@@ -8758,7 +9095,7 @@ app.openapi(
|
|
|
8758
9095
|
);
|
|
8759
9096
|
const credentialStores = c.get("credentialStores");
|
|
8760
9097
|
const agent = await getRegisteredAgent(executionContext, credentialStores);
|
|
8761
|
-
|
|
9098
|
+
logger20.info({ agent }, "agent registered: well-known agent.json");
|
|
8762
9099
|
if (!agent) {
|
|
8763
9100
|
throw agentsCore.createApiError({
|
|
8764
9101
|
code: "not_found",
|
|
@@ -8767,7 +9104,7 @@ app.openapi(
|
|
|
8767
9104
|
}
|
|
8768
9105
|
return c.json(agent.agentCard);
|
|
8769
9106
|
} else {
|
|
8770
|
-
|
|
9107
|
+
logger20.info(
|
|
8771
9108
|
{
|
|
8772
9109
|
message: "getRegisteredGraph (graph-level)",
|
|
8773
9110
|
tenantId,
|
|
@@ -8793,7 +9130,7 @@ app.post("/a2a", async (c) => {
|
|
|
8793
9130
|
tracestate: c.req.header("tracestate"),
|
|
8794
9131
|
baggage: c.req.header("baggage")
|
|
8795
9132
|
};
|
|
8796
|
-
|
|
9133
|
+
logger20.info(
|
|
8797
9134
|
{
|
|
8798
9135
|
otelHeaders,
|
|
8799
9136
|
path: c.req.path,
|
|
@@ -8804,7 +9141,7 @@ app.post("/a2a", async (c) => {
|
|
|
8804
9141
|
const executionContext = agentsCore.getRequestExecutionContext(c);
|
|
8805
9142
|
const { tenantId, projectId, graphId, agentId } = executionContext;
|
|
8806
9143
|
if (agentId) {
|
|
8807
|
-
|
|
9144
|
+
logger20.info(
|
|
8808
9145
|
{
|
|
8809
9146
|
message: "a2a (agent-level)",
|
|
8810
9147
|
tenantId,
|
|
@@ -8828,7 +9165,7 @@ app.post("/a2a", async (c) => {
|
|
|
8828
9165
|
}
|
|
8829
9166
|
return a2aHandler(c, agent);
|
|
8830
9167
|
} else {
|
|
8831
|
-
|
|
9168
|
+
logger20.info(
|
|
8832
9169
|
{
|
|
8833
9170
|
message: "a2a (graph-level)",
|
|
8834
9171
|
tenantId,
|
|
@@ -8884,14 +9221,14 @@ init_dbClient();
|
|
|
8884
9221
|
// src/a2a/transfer.ts
|
|
8885
9222
|
init_dbClient();
|
|
8886
9223
|
init_logger();
|
|
8887
|
-
var
|
|
9224
|
+
var logger21 = agentsCore.getLogger("Transfer");
|
|
8888
9225
|
async function executeTransfer({
|
|
8889
9226
|
tenantId,
|
|
8890
9227
|
threadId,
|
|
8891
9228
|
projectId,
|
|
8892
9229
|
targetAgentId
|
|
8893
9230
|
}) {
|
|
8894
|
-
|
|
9231
|
+
logger21.info({ targetAgent: targetAgentId }, "Executing transfer to agent");
|
|
8895
9232
|
await agentsCore.setActiveAgentForThread(dbClient_default)({
|
|
8896
9233
|
scopes: { tenantId, projectId },
|
|
8897
9234
|
threadId,
|
|
@@ -9477,7 +9814,7 @@ function createMCPStreamHelper() {
|
|
|
9477
9814
|
}
|
|
9478
9815
|
|
|
9479
9816
|
// src/handlers/executionHandler.ts
|
|
9480
|
-
var
|
|
9817
|
+
var logger22 = agentsCore.getLogger("ExecutionHandler");
|
|
9481
9818
|
var ExecutionHandler = class {
|
|
9482
9819
|
constructor() {
|
|
9483
9820
|
// Hardcoded error limit - separate from configurable stopWhen
|
|
@@ -9513,7 +9850,7 @@ var ExecutionHandler = class {
|
|
|
9513
9850
|
if (emitOperations) {
|
|
9514
9851
|
graphSessionManager.enableEmitOperations(requestId2);
|
|
9515
9852
|
}
|
|
9516
|
-
|
|
9853
|
+
logger22.info(
|
|
9517
9854
|
{ sessionId: requestId2, graphId, conversationId, emitOperations },
|
|
9518
9855
|
"Created GraphSession for message execution"
|
|
9519
9856
|
);
|
|
@@ -9528,7 +9865,7 @@ var ExecutionHandler = class {
|
|
|
9528
9865
|
);
|
|
9529
9866
|
}
|
|
9530
9867
|
} catch (error) {
|
|
9531
|
-
|
|
9868
|
+
logger22.error(
|
|
9532
9869
|
{
|
|
9533
9870
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
9534
9871
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -9544,7 +9881,7 @@ var ExecutionHandler = class {
|
|
|
9544
9881
|
try {
|
|
9545
9882
|
await sseHelper.writeOperation(agentInitializingOp(requestId2, graphId));
|
|
9546
9883
|
const taskId = `task_${conversationId}-${requestId2}`;
|
|
9547
|
-
|
|
9884
|
+
logger22.info(
|
|
9548
9885
|
{ taskId, currentAgentId, conversationId, requestId: requestId2 },
|
|
9549
9886
|
"Attempting to create or reuse existing task"
|
|
9550
9887
|
);
|
|
@@ -9568,7 +9905,7 @@ var ExecutionHandler = class {
|
|
|
9568
9905
|
agent_id: currentAgentId
|
|
9569
9906
|
}
|
|
9570
9907
|
});
|
|
9571
|
-
|
|
9908
|
+
logger22.info(
|
|
9572
9909
|
{
|
|
9573
9910
|
taskId,
|
|
9574
9911
|
createdTaskMetadata: Array.isArray(task) ? task[0]?.metadata : task?.metadata
|
|
@@ -9577,27 +9914,27 @@ var ExecutionHandler = class {
|
|
|
9577
9914
|
);
|
|
9578
9915
|
} catch (error) {
|
|
9579
9916
|
if (error?.message?.includes("UNIQUE constraint failed") || error?.message?.includes("PRIMARY KEY constraint failed") || error?.code === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
9580
|
-
|
|
9917
|
+
logger22.info(
|
|
9581
9918
|
{ taskId, error: error.message },
|
|
9582
9919
|
"Task already exists, fetching existing task"
|
|
9583
9920
|
);
|
|
9584
9921
|
const existingTask = await agentsCore.getTask(dbClient_default)({ id: taskId });
|
|
9585
9922
|
if (existingTask) {
|
|
9586
9923
|
task = existingTask;
|
|
9587
|
-
|
|
9924
|
+
logger22.info(
|
|
9588
9925
|
{ taskId, existingTask },
|
|
9589
9926
|
"Successfully reused existing task from race condition"
|
|
9590
9927
|
);
|
|
9591
9928
|
} else {
|
|
9592
|
-
|
|
9929
|
+
logger22.error({ taskId, error }, "Task constraint failed but task not found");
|
|
9593
9930
|
throw error;
|
|
9594
9931
|
}
|
|
9595
9932
|
} else {
|
|
9596
|
-
|
|
9933
|
+
logger22.error({ taskId, error }, "Failed to create task due to non-constraint error");
|
|
9597
9934
|
throw error;
|
|
9598
9935
|
}
|
|
9599
9936
|
}
|
|
9600
|
-
|
|
9937
|
+
logger22.debug(
|
|
9601
9938
|
{
|
|
9602
9939
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9603
9940
|
executionType: "create_initial_task",
|
|
@@ -9615,7 +9952,7 @@ var ExecutionHandler = class {
|
|
|
9615
9952
|
const maxTransfers = graphConfig?.stopWhen?.transferCountIs ?? 10;
|
|
9616
9953
|
while (iterations < maxTransfers) {
|
|
9617
9954
|
iterations++;
|
|
9618
|
-
|
|
9955
|
+
logger22.info(
|
|
9619
9956
|
{ iterations, currentAgentId, graphId, conversationId, fromAgentId },
|
|
9620
9957
|
`Execution loop iteration ${iterations} with agent ${currentAgentId}, transfer from: ${fromAgentId || "none"}`
|
|
9621
9958
|
);
|
|
@@ -9623,10 +9960,10 @@ var ExecutionHandler = class {
|
|
|
9623
9960
|
scopes: { tenantId, projectId },
|
|
9624
9961
|
conversationId
|
|
9625
9962
|
});
|
|
9626
|
-
|
|
9963
|
+
logger22.info({ activeAgent }, "activeAgent");
|
|
9627
9964
|
if (activeAgent && activeAgent.activeAgentId !== currentAgentId) {
|
|
9628
9965
|
currentAgentId = activeAgent.activeAgentId;
|
|
9629
|
-
|
|
9966
|
+
logger22.info({ currentAgentId }, `Updated current agent to: ${currentAgentId}`);
|
|
9630
9967
|
}
|
|
9631
9968
|
const agentBaseUrl = `${baseUrl}/agents`;
|
|
9632
9969
|
const a2aClient = new A2AClient(agentBaseUrl, {
|
|
@@ -9667,13 +10004,13 @@ var ExecutionHandler = class {
|
|
|
9667
10004
|
});
|
|
9668
10005
|
if (!messageResponse?.result) {
|
|
9669
10006
|
errorCount++;
|
|
9670
|
-
|
|
10007
|
+
logger22.error(
|
|
9671
10008
|
{ currentAgentId, iterations, errorCount },
|
|
9672
10009
|
`No response from agent ${currentAgentId} on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
9673
10010
|
);
|
|
9674
10011
|
if (errorCount >= this.MAX_ERRORS) {
|
|
9675
10012
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
9676
|
-
|
|
10013
|
+
logger22.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
9677
10014
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
9678
10015
|
if (task) {
|
|
9679
10016
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9698,7 +10035,7 @@ var ExecutionHandler = class {
|
|
|
9698
10035
|
const transferResponse = messageResponse.result;
|
|
9699
10036
|
const targetAgentId = transferResponse.artifacts?.[0]?.parts?.[0]?.data?.targetAgentId;
|
|
9700
10037
|
const transferReason = transferResponse.artifacts?.[0]?.parts?.[1]?.text;
|
|
9701
|
-
|
|
10038
|
+
logger22.info({ targetAgentId, transferReason }, "transfer response");
|
|
9702
10039
|
currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
|
|
9703
10040
|
const { success, targetAgentId: newAgentId } = await executeTransfer({
|
|
9704
10041
|
projectId,
|
|
@@ -9709,7 +10046,7 @@ var ExecutionHandler = class {
|
|
|
9709
10046
|
if (success) {
|
|
9710
10047
|
fromAgentId = currentAgentId;
|
|
9711
10048
|
currentAgentId = newAgentId;
|
|
9712
|
-
|
|
10049
|
+
logger22.info(
|
|
9713
10050
|
{
|
|
9714
10051
|
transferFrom: fromAgentId,
|
|
9715
10052
|
transferTo: currentAgentId,
|
|
@@ -9727,7 +10064,7 @@ var ExecutionHandler = class {
|
|
|
9727
10064
|
const graphSessionData = graphSessionManager.getSession(requestId2);
|
|
9728
10065
|
if (graphSessionData) {
|
|
9729
10066
|
const sessionSummary = graphSessionData.getSummary();
|
|
9730
|
-
|
|
10067
|
+
logger22.info(sessionSummary, "GraphSession data after completion");
|
|
9731
10068
|
}
|
|
9732
10069
|
let textContent = "";
|
|
9733
10070
|
for (const part of responseParts) {
|
|
@@ -9781,22 +10118,22 @@ var ExecutionHandler = class {
|
|
|
9781
10118
|
}
|
|
9782
10119
|
});
|
|
9783
10120
|
const updateTaskEnd = Date.now();
|
|
9784
|
-
|
|
10121
|
+
logger22.info(
|
|
9785
10122
|
{ duration: updateTaskEnd - updateTaskStart },
|
|
9786
10123
|
"Completed updateTask operation"
|
|
9787
10124
|
);
|
|
9788
10125
|
await sseHelper.writeOperation(completionOp(currentAgentId, iterations));
|
|
9789
10126
|
await sseHelper.complete();
|
|
9790
|
-
|
|
10127
|
+
logger22.info({}, "Ending GraphSession and cleaning up");
|
|
9791
10128
|
graphSessionManager.endSession(requestId2);
|
|
9792
|
-
|
|
10129
|
+
logger22.info({}, "Cleaning up streamHelper");
|
|
9793
10130
|
unregisterStreamHelper(requestId2);
|
|
9794
10131
|
let response;
|
|
9795
10132
|
if (sseHelper instanceof MCPStreamHelper) {
|
|
9796
10133
|
const captured = sseHelper.getCapturedResponse();
|
|
9797
10134
|
response = captured.text || "No response content";
|
|
9798
10135
|
}
|
|
9799
|
-
|
|
10136
|
+
logger22.info({}, "ExecutionHandler returning success");
|
|
9800
10137
|
return { success: true, iterations, response };
|
|
9801
10138
|
} catch (error) {
|
|
9802
10139
|
agentsCore.setSpanWithError(span, error instanceof Error ? error : new Error(String(error)));
|
|
@@ -9807,13 +10144,13 @@ var ExecutionHandler = class {
|
|
|
9807
10144
|
});
|
|
9808
10145
|
}
|
|
9809
10146
|
errorCount++;
|
|
9810
|
-
|
|
10147
|
+
logger22.warn(
|
|
9811
10148
|
{ iterations, errorCount },
|
|
9812
10149
|
`No valid response or transfer on iteration ${iterations} (error ${errorCount}/${this.MAX_ERRORS})`
|
|
9813
10150
|
);
|
|
9814
10151
|
if (errorCount >= this.MAX_ERRORS) {
|
|
9815
10152
|
const errorMessage2 = `Maximum error limit (${this.MAX_ERRORS}) reached`;
|
|
9816
|
-
|
|
10153
|
+
logger22.error({ maxErrors: this.MAX_ERRORS, errorCount }, errorMessage2);
|
|
9817
10154
|
await sseHelper.writeOperation(errorOp(errorMessage2, currentAgentId || "system"));
|
|
9818
10155
|
if (task) {
|
|
9819
10156
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9834,7 +10171,7 @@ var ExecutionHandler = class {
|
|
|
9834
10171
|
}
|
|
9835
10172
|
}
|
|
9836
10173
|
const errorMessage = `Maximum transfer limit (${maxTransfers}) reached without completion`;
|
|
9837
|
-
|
|
10174
|
+
logger22.error({ maxTransfers, iterations }, errorMessage);
|
|
9838
10175
|
await sseHelper.writeOperation(errorOp(errorMessage, currentAgentId || "system"));
|
|
9839
10176
|
if (task) {
|
|
9840
10177
|
await agentsCore.updateTask(dbClient_default)({
|
|
@@ -9853,7 +10190,7 @@ var ExecutionHandler = class {
|
|
|
9853
10190
|
unregisterStreamHelper(requestId2);
|
|
9854
10191
|
return { success: false, error: errorMessage, iterations };
|
|
9855
10192
|
} catch (error) {
|
|
9856
|
-
|
|
10193
|
+
logger22.error({ error }, "Error in execution handler");
|
|
9857
10194
|
const errorMessage = error instanceof Error ? error.message : "Unknown execution error";
|
|
9858
10195
|
await sseHelper.writeOperation(
|
|
9859
10196
|
errorOp(`Execution error: ${errorMessage}`, currentAgentId || "system")
|
|
@@ -9881,7 +10218,7 @@ var ExecutionHandler = class {
|
|
|
9881
10218
|
// src/routes/chat.ts
|
|
9882
10219
|
init_logger();
|
|
9883
10220
|
var app2 = new zodOpenapi.OpenAPIHono();
|
|
9884
|
-
var
|
|
10221
|
+
var logger23 = agentsCore.getLogger("completionsHandler");
|
|
9885
10222
|
var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
9886
10223
|
method: "post",
|
|
9887
10224
|
path: "/completions",
|
|
@@ -9893,36 +10230,36 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
9893
10230
|
body: {
|
|
9894
10231
|
content: {
|
|
9895
10232
|
"application/json": {
|
|
9896
|
-
schema:
|
|
9897
|
-
model:
|
|
9898
|
-
messages:
|
|
9899
|
-
|
|
9900
|
-
role:
|
|
9901
|
-
content:
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
type:
|
|
9906
|
-
text:
|
|
10233
|
+
schema: z6.z.object({
|
|
10234
|
+
model: z6.z.string().describe("The model to use for the completion"),
|
|
10235
|
+
messages: z6.z.array(
|
|
10236
|
+
z6.z.object({
|
|
10237
|
+
role: z6.z.enum(["system", "user", "assistant", "function", "tool"]).describe("The role of the message"),
|
|
10238
|
+
content: z6.z.union([
|
|
10239
|
+
z6.z.string(),
|
|
10240
|
+
z6.z.array(
|
|
10241
|
+
z6.z.strictObject({
|
|
10242
|
+
type: z6.z.string(),
|
|
10243
|
+
text: z6.z.string().optional()
|
|
9907
10244
|
})
|
|
9908
10245
|
)
|
|
9909
10246
|
]).describe("The message content"),
|
|
9910
|
-
name:
|
|
10247
|
+
name: z6.z.string().optional().describe("The name of the message sender")
|
|
9911
10248
|
})
|
|
9912
10249
|
).describe("The conversation messages"),
|
|
9913
|
-
temperature:
|
|
9914
|
-
top_p:
|
|
9915
|
-
n:
|
|
9916
|
-
stream:
|
|
9917
|
-
max_tokens:
|
|
9918
|
-
presence_penalty:
|
|
9919
|
-
frequency_penalty:
|
|
9920
|
-
logit_bias:
|
|
9921
|
-
user:
|
|
9922
|
-
conversationId:
|
|
9923
|
-
tools:
|
|
9924
|
-
runConfig:
|
|
9925
|
-
requestContext:
|
|
10250
|
+
temperature: z6.z.number().optional().describe("Controls randomness (0-1)"),
|
|
10251
|
+
top_p: z6.z.number().optional().describe("Controls nucleus sampling"),
|
|
10252
|
+
n: z6.z.number().optional().describe("Number of completions to generate"),
|
|
10253
|
+
stream: z6.z.boolean().optional().describe("Whether to stream the response"),
|
|
10254
|
+
max_tokens: z6.z.number().optional().describe("Maximum tokens to generate"),
|
|
10255
|
+
presence_penalty: z6.z.number().optional().describe("Presence penalty (-2 to 2)"),
|
|
10256
|
+
frequency_penalty: z6.z.number().optional().describe("Frequency penalty (-2 to 2)"),
|
|
10257
|
+
logit_bias: z6.z.record(z6.z.string(), z6.z.number()).optional().describe("Token logit bias"),
|
|
10258
|
+
user: z6.z.string().optional().describe("User identifier"),
|
|
10259
|
+
conversationId: z6.z.string().optional().describe("Conversation ID for multi-turn chat"),
|
|
10260
|
+
tools: z6.z.array(z6.z.string()).optional().describe("Available tools"),
|
|
10261
|
+
runConfig: z6.z.record(z6.z.string(), z6.z.unknown()).optional().describe("Run configuration"),
|
|
10262
|
+
requestContext: z6.z.record(z6.z.string(), z6.z.unknown()).optional().describe(
|
|
9926
10263
|
"Context data for template processing (validated against context config schema)"
|
|
9927
10264
|
)
|
|
9928
10265
|
})
|
|
@@ -9933,14 +10270,14 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
9933
10270
|
responses: {
|
|
9934
10271
|
200: {
|
|
9935
10272
|
description: "Streaming chat completion response in Server-Sent Events format",
|
|
9936
|
-
headers:
|
|
9937
|
-
"Content-Type":
|
|
9938
|
-
"Cache-Control":
|
|
9939
|
-
Connection:
|
|
10273
|
+
headers: z6.z.object({
|
|
10274
|
+
"Content-Type": z6.z.string().default("text/event-stream"),
|
|
10275
|
+
"Cache-Control": z6.z.string().default("no-cache"),
|
|
10276
|
+
Connection: z6.z.string().default("keep-alive")
|
|
9940
10277
|
}),
|
|
9941
10278
|
content: {
|
|
9942
10279
|
"text/event-stream": {
|
|
9943
|
-
schema:
|
|
10280
|
+
schema: z6.z.string().describe("Server-Sent Events stream with chat completion chunks")
|
|
9944
10281
|
}
|
|
9945
10282
|
}
|
|
9946
10283
|
},
|
|
@@ -9948,13 +10285,13 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
9948
10285
|
description: "Invalid request context or parameters",
|
|
9949
10286
|
content: {
|
|
9950
10287
|
"application/json": {
|
|
9951
|
-
schema:
|
|
9952
|
-
error:
|
|
9953
|
-
details:
|
|
9954
|
-
|
|
9955
|
-
field:
|
|
9956
|
-
message:
|
|
9957
|
-
value:
|
|
10288
|
+
schema: z6.z.object({
|
|
10289
|
+
error: z6.z.string(),
|
|
10290
|
+
details: z6.z.array(
|
|
10291
|
+
z6.z.object({
|
|
10292
|
+
field: z6.z.string(),
|
|
10293
|
+
message: z6.z.string(),
|
|
10294
|
+
value: z6.z.unknown().optional()
|
|
9958
10295
|
})
|
|
9959
10296
|
).optional()
|
|
9960
10297
|
})
|
|
@@ -9965,8 +10302,8 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
9965
10302
|
description: "Agent graph or agent not found",
|
|
9966
10303
|
content: {
|
|
9967
10304
|
"application/json": {
|
|
9968
|
-
schema:
|
|
9969
|
-
error:
|
|
10305
|
+
schema: z6.z.object({
|
|
10306
|
+
error: z6.z.string()
|
|
9970
10307
|
})
|
|
9971
10308
|
}
|
|
9972
10309
|
}
|
|
@@ -9975,9 +10312,9 @@ var chatCompletionsRoute = zodOpenapi.createRoute({
|
|
|
9975
10312
|
description: "Internal server error",
|
|
9976
10313
|
content: {
|
|
9977
10314
|
"application/json": {
|
|
9978
|
-
schema:
|
|
9979
|
-
error:
|
|
9980
|
-
message:
|
|
10315
|
+
schema: z6.z.object({
|
|
10316
|
+
error: z6.z.string(),
|
|
10317
|
+
message: z6.z.string()
|
|
9981
10318
|
})
|
|
9982
10319
|
}
|
|
9983
10320
|
}
|
|
@@ -9999,7 +10336,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
9999
10336
|
tracestate: c.req.header("tracestate"),
|
|
10000
10337
|
baggage: c.req.header("baggage")
|
|
10001
10338
|
};
|
|
10002
|
-
|
|
10339
|
+
logger23.info(
|
|
10003
10340
|
{
|
|
10004
10341
|
otelHeaders,
|
|
10005
10342
|
path: c.req.path,
|
|
@@ -10092,7 +10429,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10092
10429
|
dbClient: dbClient_default,
|
|
10093
10430
|
credentialStores
|
|
10094
10431
|
});
|
|
10095
|
-
|
|
10432
|
+
logger23.info(
|
|
10096
10433
|
{
|
|
10097
10434
|
tenantId,
|
|
10098
10435
|
projectId,
|
|
@@ -10140,7 +10477,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10140
10477
|
try {
|
|
10141
10478
|
const sseHelper = createSSEStreamHelper(stream2, requestId2, timestamp);
|
|
10142
10479
|
await sseHelper.writeRole();
|
|
10143
|
-
|
|
10480
|
+
logger23.info({ agentId }, "Starting execution");
|
|
10144
10481
|
const emitOperationsHeader = c.req.header("x-emit-operations");
|
|
10145
10482
|
const emitOperations = emitOperationsHeader === "true";
|
|
10146
10483
|
const executionHandler = new ExecutionHandler();
|
|
@@ -10153,7 +10490,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10153
10490
|
sseHelper,
|
|
10154
10491
|
emitOperations
|
|
10155
10492
|
});
|
|
10156
|
-
|
|
10493
|
+
logger23.info(
|
|
10157
10494
|
{ result },
|
|
10158
10495
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10159
10496
|
);
|
|
@@ -10167,7 +10504,7 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10167
10504
|
}
|
|
10168
10505
|
await sseHelper.complete();
|
|
10169
10506
|
} catch (error) {
|
|
10170
|
-
|
|
10507
|
+
logger23.error(
|
|
10171
10508
|
{
|
|
10172
10509
|
error: error instanceof Error ? error.message : error,
|
|
10173
10510
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10184,12 +10521,12 @@ app2.openapi(chatCompletionsRoute, async (c) => {
|
|
|
10184
10521
|
);
|
|
10185
10522
|
await sseHelper.complete();
|
|
10186
10523
|
} catch (streamError) {
|
|
10187
|
-
|
|
10524
|
+
logger23.error({ streamError }, "Failed to write error to stream");
|
|
10188
10525
|
}
|
|
10189
10526
|
}
|
|
10190
10527
|
});
|
|
10191
10528
|
} catch (error) {
|
|
10192
|
-
|
|
10529
|
+
logger23.error(
|
|
10193
10530
|
{
|
|
10194
10531
|
error: error instanceof Error ? error.message : error,
|
|
10195
10532
|
stack: error instanceof Error ? error.stack : void 0
|
|
@@ -10217,7 +10554,7 @@ var chat_default = app2;
|
|
|
10217
10554
|
init_dbClient();
|
|
10218
10555
|
init_logger();
|
|
10219
10556
|
var app3 = new zodOpenapi.OpenAPIHono();
|
|
10220
|
-
var
|
|
10557
|
+
var logger24 = agentsCore.getLogger("chatDataStream");
|
|
10221
10558
|
var chatDataStreamRoute = zodOpenapi.createRoute({
|
|
10222
10559
|
method: "post",
|
|
10223
10560
|
path: "/chat",
|
|
@@ -10334,7 +10671,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10334
10671
|
});
|
|
10335
10672
|
const lastUserMessage = body.messages.filter((m) => m.role === "user").slice(-1)[0];
|
|
10336
10673
|
const userText = typeof lastUserMessage?.content === "string" ? lastUserMessage.content : lastUserMessage?.parts?.map((p) => p.text).join("") || "";
|
|
10337
|
-
|
|
10674
|
+
logger24.info({ userText, lastUserMessage }, "userText");
|
|
10338
10675
|
const messageSpan = api.trace.getActiveSpan();
|
|
10339
10676
|
if (messageSpan) {
|
|
10340
10677
|
messageSpan.setAttributes({
|
|
@@ -10379,7 +10716,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10379
10716
|
await streamHelper.writeOperation(errorOp("Unable to process request", "system"));
|
|
10380
10717
|
}
|
|
10381
10718
|
} catch (err) {
|
|
10382
|
-
|
|
10719
|
+
logger24.error({ err }, "Streaming error");
|
|
10383
10720
|
await streamHelper.writeOperation(errorOp("Internal server error", "system"));
|
|
10384
10721
|
} finally {
|
|
10385
10722
|
if ("cleanup" in streamHelper && typeof streamHelper.cleanup === "function") {
|
|
@@ -10400,7 +10737,7 @@ app3.openapi(chatDataStreamRoute, async (c) => {
|
|
|
10400
10737
|
)
|
|
10401
10738
|
);
|
|
10402
10739
|
} catch (error) {
|
|
10403
|
-
|
|
10740
|
+
logger24.error({ error }, "chatDataStream error");
|
|
10404
10741
|
throw agentsCore.createApiError({
|
|
10405
10742
|
code: "internal_server_error",
|
|
10406
10743
|
message: "Failed to process chat completion"
|
|
@@ -10415,7 +10752,7 @@ init_logger();
|
|
|
10415
10752
|
function createMCPSchema(schema) {
|
|
10416
10753
|
return schema;
|
|
10417
10754
|
}
|
|
10418
|
-
var
|
|
10755
|
+
var logger25 = agentsCore.getLogger("mcp");
|
|
10419
10756
|
var _MockResponseSingleton = class _MockResponseSingleton {
|
|
10420
10757
|
constructor() {
|
|
10421
10758
|
__publicField(this, "mockRes");
|
|
@@ -10470,21 +10807,21 @@ var createSpoofInitMessage = (mcpProtocolVersion) => ({
|
|
|
10470
10807
|
id: 0
|
|
10471
10808
|
});
|
|
10472
10809
|
var spoofTransportInitialization = async (transport, req, sessionId, mcpProtocolVersion) => {
|
|
10473
|
-
|
|
10810
|
+
logger25.info({ sessionId }, "Spoofing initialization message to set transport state");
|
|
10474
10811
|
const spoofInitMessage = createSpoofInitMessage(mcpProtocolVersion);
|
|
10475
10812
|
const mockRes = MockResponseSingleton.getInstance().getMockResponse();
|
|
10476
10813
|
try {
|
|
10477
10814
|
await transport.handleRequest(req, mockRes, spoofInitMessage);
|
|
10478
|
-
|
|
10815
|
+
logger25.info({ sessionId }, "Successfully spoofed initialization");
|
|
10479
10816
|
} catch (spoofError) {
|
|
10480
|
-
|
|
10817
|
+
logger25.warn({ sessionId, error: spoofError }, "Spoof initialization failed, continuing anyway");
|
|
10481
10818
|
}
|
|
10482
10819
|
};
|
|
10483
10820
|
var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
10484
10821
|
const sessionId = req.headers["mcp-session-id"];
|
|
10485
|
-
|
|
10822
|
+
logger25.info({ sessionId }, "Received MCP session ID");
|
|
10486
10823
|
if (!sessionId) {
|
|
10487
|
-
|
|
10824
|
+
logger25.info({ body }, "Missing session ID");
|
|
10488
10825
|
res.writeHead(400).end(
|
|
10489
10826
|
JSON.stringify({
|
|
10490
10827
|
jsonrpc: "2.0",
|
|
@@ -10510,7 +10847,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10510
10847
|
scopes: { tenantId, projectId },
|
|
10511
10848
|
conversationId: sessionId
|
|
10512
10849
|
});
|
|
10513
|
-
|
|
10850
|
+
logger25.info(
|
|
10514
10851
|
{
|
|
10515
10852
|
sessionId,
|
|
10516
10853
|
conversationFound: !!conversation,
|
|
@@ -10521,7 +10858,7 @@ var validateSession = async (req, res, body, tenantId, projectId, graphId) => {
|
|
|
10521
10858
|
"Conversation lookup result"
|
|
10522
10859
|
);
|
|
10523
10860
|
if (!conversation || conversation.metadata?.sessionData?.sessionType !== "mcp" || conversation.metadata?.sessionData?.graphId !== graphId) {
|
|
10524
|
-
|
|
10861
|
+
logger25.info(
|
|
10525
10862
|
{ sessionId, conversationId: conversation?.id },
|
|
10526
10863
|
"MCP session not found or invalid"
|
|
10527
10864
|
);
|
|
@@ -10582,7 +10919,7 @@ var executeAgentQuery = async (executionContext, conversationId, query, defaultA
|
|
|
10582
10919
|
requestId: requestId2,
|
|
10583
10920
|
sseHelper: mcpStreamHelper
|
|
10584
10921
|
});
|
|
10585
|
-
|
|
10922
|
+
logger25.info(
|
|
10586
10923
|
{ result },
|
|
10587
10924
|
`Execution completed: ${result.success ? "success" : "failed"} after ${result.iterations} iterations`
|
|
10588
10925
|
);
|
|
@@ -10666,7 +11003,7 @@ var getServer = async (requestContext, executionContext, conversationId, credent
|
|
|
10666
11003
|
dbClient: dbClient_default,
|
|
10667
11004
|
credentialStores
|
|
10668
11005
|
});
|
|
10669
|
-
|
|
11006
|
+
logger25.info(
|
|
10670
11007
|
{
|
|
10671
11008
|
tenantId,
|
|
10672
11009
|
projectId,
|
|
@@ -10728,7 +11065,7 @@ var validateRequestParameters = (c) => {
|
|
|
10728
11065
|
};
|
|
10729
11066
|
var handleInitializationRequest = async (body, executionContext, validatedContext, req, res, c, credentialStores) => {
|
|
10730
11067
|
const { tenantId, projectId, graphId } = executionContext;
|
|
10731
|
-
|
|
11068
|
+
logger25.info({ body }, "Received initialization request");
|
|
10732
11069
|
const sessionId = agentsCore.getConversationId();
|
|
10733
11070
|
const agentGraph = await agentsCore.getAgentGraphWithDefaultAgent(dbClient_default)({
|
|
10734
11071
|
scopes: { tenantId, projectId, graphId }
|
|
@@ -10768,7 +11105,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10768
11105
|
}
|
|
10769
11106
|
}
|
|
10770
11107
|
});
|
|
10771
|
-
|
|
11108
|
+
logger25.info(
|
|
10772
11109
|
{ sessionId, conversationId: conversation.id },
|
|
10773
11110
|
"Created MCP session as conversation"
|
|
10774
11111
|
);
|
|
@@ -10777,9 +11114,9 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10777
11114
|
});
|
|
10778
11115
|
const server = await getServer(validatedContext, executionContext, sessionId, credentialStores);
|
|
10779
11116
|
await server.connect(transport);
|
|
10780
|
-
|
|
11117
|
+
logger25.info({ sessionId }, "Server connected for initialization");
|
|
10781
11118
|
res.setHeader("Mcp-Session-Id", sessionId);
|
|
10782
|
-
|
|
11119
|
+
logger25.info(
|
|
10783
11120
|
{
|
|
10784
11121
|
sessionId,
|
|
10785
11122
|
bodyMethod: body?.method,
|
|
@@ -10788,7 +11125,7 @@ var handleInitializationRequest = async (body, executionContext, validatedContex
|
|
|
10788
11125
|
"About to handle initialization request"
|
|
10789
11126
|
);
|
|
10790
11127
|
await transport.handleRequest(req, res, body);
|
|
10791
|
-
|
|
11128
|
+
logger25.info({ sessionId }, "Successfully handled initialization request");
|
|
10792
11129
|
return fetchToNode.toFetchResponse(res);
|
|
10793
11130
|
};
|
|
10794
11131
|
var handleExistingSessionRequest = async (body, executionContext, validatedContext, req, res, credentialStores) => {
|
|
@@ -10816,8 +11153,8 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
10816
11153
|
sessionId,
|
|
10817
11154
|
conversation.metadata?.session_data?.mcpProtocolVersion
|
|
10818
11155
|
);
|
|
10819
|
-
|
|
10820
|
-
|
|
11156
|
+
logger25.info({ sessionId }, "Server connected and transport initialized");
|
|
11157
|
+
logger25.info(
|
|
10821
11158
|
{
|
|
10822
11159
|
sessionId,
|
|
10823
11160
|
bodyKeys: Object.keys(body || {}),
|
|
@@ -10831,9 +11168,9 @@ var handleExistingSessionRequest = async (body, executionContext, validatedConte
|
|
|
10831
11168
|
);
|
|
10832
11169
|
try {
|
|
10833
11170
|
await transport.handleRequest(req, res, body);
|
|
10834
|
-
|
|
11171
|
+
logger25.info({ sessionId }, "Successfully handled MCP request");
|
|
10835
11172
|
} catch (transportError) {
|
|
10836
|
-
|
|
11173
|
+
logger25.error(
|
|
10837
11174
|
{
|
|
10838
11175
|
sessionId,
|
|
10839
11176
|
error: transportError,
|
|
@@ -10884,13 +11221,13 @@ app4.openapi(
|
|
|
10884
11221
|
}
|
|
10885
11222
|
const { executionContext } = paramValidation;
|
|
10886
11223
|
const body = c.get("requestBody") || {};
|
|
10887
|
-
|
|
11224
|
+
logger25.info({ body, bodyKeys: Object.keys(body || {}) }, "Parsed request body");
|
|
10888
11225
|
const isInitRequest = body.method === "initialize";
|
|
10889
11226
|
const { req, res } = fetchToNode.toReqRes(c.req.raw);
|
|
10890
11227
|
const validatedContext = c.get("validatedContext") || {};
|
|
10891
11228
|
const credentialStores = c.get("credentialStores");
|
|
10892
|
-
|
|
10893
|
-
|
|
11229
|
+
logger25.info({ validatedContext }, "Validated context");
|
|
11230
|
+
logger25.info({ req }, "request");
|
|
10894
11231
|
if (isInitRequest) {
|
|
10895
11232
|
return await handleInitializationRequest(
|
|
10896
11233
|
body,
|
|
@@ -10912,7 +11249,7 @@ app4.openapi(
|
|
|
10912
11249
|
);
|
|
10913
11250
|
}
|
|
10914
11251
|
} catch (e) {
|
|
10915
|
-
|
|
11252
|
+
logger25.error(
|
|
10916
11253
|
{
|
|
10917
11254
|
error: e instanceof Error ? e.message : e,
|
|
10918
11255
|
stack: e instanceof Error ? e.stack : void 0
|
|
@@ -10924,7 +11261,7 @@ app4.openapi(
|
|
|
10924
11261
|
}
|
|
10925
11262
|
);
|
|
10926
11263
|
app4.get("/", async (c) => {
|
|
10927
|
-
|
|
11264
|
+
logger25.info({}, "Received GET MCP request");
|
|
10928
11265
|
return c.json(
|
|
10929
11266
|
{
|
|
10930
11267
|
jsonrpc: "2.0",
|
|
@@ -10938,7 +11275,7 @@ app4.get("/", async (c) => {
|
|
|
10938
11275
|
);
|
|
10939
11276
|
});
|
|
10940
11277
|
app4.delete("/", async (c) => {
|
|
10941
|
-
|
|
11278
|
+
logger25.info({}, "Received DELETE MCP request");
|
|
10942
11279
|
return c.json(
|
|
10943
11280
|
{
|
|
10944
11281
|
jsonrpc: "2.0",
|
|
@@ -10951,7 +11288,7 @@ app4.delete("/", async (c) => {
|
|
|
10951
11288
|
var mcp_default = app4;
|
|
10952
11289
|
|
|
10953
11290
|
// src/app.ts
|
|
10954
|
-
var
|
|
11291
|
+
var logger26 = agentsCore.getLogger("agents-run-api");
|
|
10955
11292
|
function createExecutionHono(serverConfig, credentialStores) {
|
|
10956
11293
|
const app6 = new zodOpenapi.OpenAPIHono();
|
|
10957
11294
|
app6.use("*", otel.otel());
|
|
@@ -10967,7 +11304,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
10967
11304
|
const body = await c.req.json();
|
|
10968
11305
|
c.set("requestBody", body);
|
|
10969
11306
|
} catch (error) {
|
|
10970
|
-
|
|
11307
|
+
logger26.debug({ error }, "Failed to parse JSON body, continuing without parsed body");
|
|
10971
11308
|
}
|
|
10972
11309
|
}
|
|
10973
11310
|
return next();
|
|
@@ -11018,8 +11355,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11018
11355
|
if (!isExpectedError) {
|
|
11019
11356
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
11020
11357
|
const errorStack = err instanceof Error ? err.stack : void 0;
|
|
11021
|
-
if (
|
|
11022
|
-
|
|
11358
|
+
if (logger26) {
|
|
11359
|
+
logger26.error(
|
|
11023
11360
|
{
|
|
11024
11361
|
error: err,
|
|
11025
11362
|
message: errorMessage,
|
|
@@ -11031,8 +11368,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11031
11368
|
);
|
|
11032
11369
|
}
|
|
11033
11370
|
} else {
|
|
11034
|
-
if (
|
|
11035
|
-
|
|
11371
|
+
if (logger26) {
|
|
11372
|
+
logger26.error(
|
|
11036
11373
|
{
|
|
11037
11374
|
error: err,
|
|
11038
11375
|
path: c.req.path,
|
|
@@ -11049,8 +11386,8 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11049
11386
|
const response = err.getResponse();
|
|
11050
11387
|
return response;
|
|
11051
11388
|
} catch (responseError) {
|
|
11052
|
-
if (
|
|
11053
|
-
|
|
11389
|
+
if (logger26) {
|
|
11390
|
+
logger26.error({ error: responseError }, "Error while handling HTTPException response");
|
|
11054
11391
|
}
|
|
11055
11392
|
}
|
|
11056
11393
|
}
|
|
@@ -11084,7 +11421,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11084
11421
|
app6.use("*", async (c, next) => {
|
|
11085
11422
|
const executionContext = c.get("executionContext");
|
|
11086
11423
|
if (!executionContext) {
|
|
11087
|
-
|
|
11424
|
+
logger26.debug({}, "Empty execution context");
|
|
11088
11425
|
return next();
|
|
11089
11426
|
}
|
|
11090
11427
|
const { tenantId, projectId, graphId } = executionContext;
|
|
@@ -11093,7 +11430,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11093
11430
|
if (requestBody) {
|
|
11094
11431
|
conversationId = requestBody.conversationId;
|
|
11095
11432
|
if (!conversationId) {
|
|
11096
|
-
|
|
11433
|
+
logger26.debug({ requestBody }, "No conversation ID found in request body");
|
|
11097
11434
|
}
|
|
11098
11435
|
}
|
|
11099
11436
|
const entries = Object.fromEntries(
|
|
@@ -11108,7 +11445,7 @@ function createExecutionHono(serverConfig, credentialStores) {
|
|
|
11108
11445
|
})
|
|
11109
11446
|
);
|
|
11110
11447
|
if (!Object.keys(entries).length) {
|
|
11111
|
-
|
|
11448
|
+
logger26.debug({}, "Empty entries for baggage");
|
|
11112
11449
|
return next();
|
|
11113
11450
|
}
|
|
11114
11451
|
const bag = Object.entries(entries).reduce(
|