@inkeep/agents-run-api 0.0.0-dev-20251022015253 → 0.0.0-dev-20251022171155
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 +196 -7
- package/dist/index.js +196 -7
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2800,9 +2800,11 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2800
2800
|
const component = this.context.artifactComponents?.find((ac) => ac.name === request.type);
|
|
2801
2801
|
let summaryData = {};
|
|
2802
2802
|
let fullData = {};
|
|
2803
|
+
let previewSchema = null;
|
|
2804
|
+
let fullSchema = null;
|
|
2803
2805
|
if (component?.props) {
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
+
previewSchema = extractPreviewFields(component.props);
|
|
2807
|
+
fullSchema = extractFullFields(component.props);
|
|
2806
2808
|
summaryData = this.extractPropsFromSchema(
|
|
2807
2809
|
selectedData,
|
|
2808
2810
|
previewSchema,
|
|
@@ -2825,6 +2827,15 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2825
2827
|
}
|
|
2826
2828
|
const cleanedSummaryData = this.cleanEscapedContent(summaryData);
|
|
2827
2829
|
const cleanedFullData = this.cleanEscapedContent(fullData);
|
|
2830
|
+
const schemaValidation = this.validateExtractedData(
|
|
2831
|
+
request.artifactId,
|
|
2832
|
+
request.type,
|
|
2833
|
+
cleanedSummaryData,
|
|
2834
|
+
cleanedFullData,
|
|
2835
|
+
previewSchema,
|
|
2836
|
+
fullSchema,
|
|
2837
|
+
component?.props
|
|
2838
|
+
);
|
|
2828
2839
|
const artifactData = {
|
|
2829
2840
|
artifactId: request.artifactId,
|
|
2830
2841
|
toolCallId: request.toolCallId,
|
|
@@ -2833,7 +2844,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2833
2844
|
type: request.type,
|
|
2834
2845
|
data: cleanedSummaryData
|
|
2835
2846
|
};
|
|
2836
|
-
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId);
|
|
2847
|
+
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId, schemaValidation);
|
|
2837
2848
|
await this.cacheArtifact(
|
|
2838
2849
|
request.artifactId,
|
|
2839
2850
|
request.toolCallId,
|
|
@@ -2943,32 +2954,183 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2943
2954
|
* Format raw artifact to standardized summary data format
|
|
2944
2955
|
*/
|
|
2945
2956
|
formatArtifactSummaryData(artifact, artifactId, toolCallId) {
|
|
2957
|
+
let data = artifact.parts?.[0]?.data?.summary;
|
|
2958
|
+
let dataSource = "parts[0].data.summary";
|
|
2959
|
+
if (!data || typeof data === "object" && Object.keys(data).length === 0) {
|
|
2960
|
+
data = artifact.parts?.[0]?.data;
|
|
2961
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
2962
|
+
dataSource = "parts[0].data (fallback)";
|
|
2963
|
+
logger7.debug(
|
|
2964
|
+
{ artifactId, toolCallId, dataSource },
|
|
2965
|
+
"Using fallback data source for artifact summary"
|
|
2966
|
+
);
|
|
2967
|
+
} else {
|
|
2968
|
+
data = artifact.data;
|
|
2969
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
2970
|
+
dataSource = "artifact.data (fallback)";
|
|
2971
|
+
logger7.debug(
|
|
2972
|
+
{ artifactId, toolCallId, dataSource },
|
|
2973
|
+
"Using fallback data source for artifact summary"
|
|
2974
|
+
);
|
|
2975
|
+
} else {
|
|
2976
|
+
data = {};
|
|
2977
|
+
dataSource = "empty (no data found)";
|
|
2978
|
+
logger7.warn(
|
|
2979
|
+
{
|
|
2980
|
+
artifactId,
|
|
2981
|
+
toolCallId,
|
|
2982
|
+
artifactStructure: {
|
|
2983
|
+
hasParts: !!artifact.parts,
|
|
2984
|
+
partsLength: artifact.parts?.length,
|
|
2985
|
+
hasPartsData: !!artifact.parts?.[0]?.data,
|
|
2986
|
+
hasPartsSummary: !!artifact.parts?.[0]?.data?.summary,
|
|
2987
|
+
hasArtifactData: !!artifact.data,
|
|
2988
|
+
artifactKeys: Object.keys(artifact || {})
|
|
2989
|
+
}
|
|
2990
|
+
},
|
|
2991
|
+
"No valid data found for artifact summary - using empty object"
|
|
2992
|
+
);
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2946
2996
|
return {
|
|
2947
2997
|
artifactId,
|
|
2948
2998
|
toolCallId,
|
|
2949
2999
|
name: artifact.name || "Processing...",
|
|
2950
3000
|
description: artifact.description || "Name and description being generated...",
|
|
2951
3001
|
type: artifact.metadata?.artifactType || artifact.artifactType,
|
|
2952
|
-
data
|
|
3002
|
+
data
|
|
2953
3003
|
};
|
|
2954
3004
|
}
|
|
2955
3005
|
/**
|
|
2956
3006
|
* Format raw artifact to standardized full data format
|
|
2957
3007
|
*/
|
|
2958
3008
|
formatArtifactFullData(artifact, artifactId, toolCallId) {
|
|
3009
|
+
let data = artifact.parts?.[0]?.data?.full;
|
|
3010
|
+
let dataSource = "parts[0].data.full";
|
|
3011
|
+
if (!data || typeof data === "object" && Object.keys(data).length === 0) {
|
|
3012
|
+
data = artifact.parts?.[0]?.data;
|
|
3013
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
3014
|
+
dataSource = "parts[0].data (fallback)";
|
|
3015
|
+
logger7.debug(
|
|
3016
|
+
{ artifactId, toolCallId, dataSource },
|
|
3017
|
+
"Using fallback data source for artifact full data"
|
|
3018
|
+
);
|
|
3019
|
+
} else {
|
|
3020
|
+
data = artifact.data;
|
|
3021
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
3022
|
+
dataSource = "artifact.data (fallback)";
|
|
3023
|
+
logger7.debug(
|
|
3024
|
+
{ artifactId, toolCallId, dataSource },
|
|
3025
|
+
"Using fallback data source for artifact full data"
|
|
3026
|
+
);
|
|
3027
|
+
} else {
|
|
3028
|
+
data = {};
|
|
3029
|
+
dataSource = "empty (no data found)";
|
|
3030
|
+
logger7.warn(
|
|
3031
|
+
{
|
|
3032
|
+
artifactId,
|
|
3033
|
+
toolCallId,
|
|
3034
|
+
artifactStructure: {
|
|
3035
|
+
hasParts: !!artifact.parts,
|
|
3036
|
+
partsLength: artifact.parts?.length,
|
|
3037
|
+
hasPartsData: !!artifact.parts?.[0]?.data,
|
|
3038
|
+
hasPartsFull: !!artifact.parts?.[0]?.data?.full,
|
|
3039
|
+
hasArtifactData: !!artifact.data,
|
|
3040
|
+
artifactKeys: Object.keys(artifact || {})
|
|
3041
|
+
}
|
|
3042
|
+
},
|
|
3043
|
+
"No valid data found for artifact full data - using empty object"
|
|
3044
|
+
);
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
2959
3048
|
return {
|
|
2960
3049
|
artifactId,
|
|
2961
3050
|
toolCallId,
|
|
2962
3051
|
name: artifact.name || "Processing...",
|
|
2963
3052
|
description: artifact.description || "Name and description being generated...",
|
|
2964
3053
|
type: artifact.metadata?.artifactType || artifact.artifactType,
|
|
2965
|
-
data
|
|
3054
|
+
data
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
/**
|
|
3058
|
+
* Validate extracted data against the schemas used for extraction
|
|
3059
|
+
*/
|
|
3060
|
+
validateExtractedData(artifactId, artifactType, summaryData, fullData, previewSchema, fullSchema, originalProps) {
|
|
3061
|
+
const validateAgainstSchema = (data, schema) => {
|
|
3062
|
+
const actualFields = Object.keys(data || {});
|
|
3063
|
+
const expectedFields = schema?.properties ? Object.keys(schema.properties) : [];
|
|
3064
|
+
const missingFields = expectedFields.filter((field) => !(field in (data || {})));
|
|
3065
|
+
const extraFields = actualFields.filter((field) => !expectedFields.includes(field));
|
|
3066
|
+
const requiredFields = schema?.required || [];
|
|
3067
|
+
const missingRequired = requiredFields.filter((field) => !(field in (data || {})));
|
|
3068
|
+
return {
|
|
3069
|
+
hasExpectedFields: missingFields.length === 0,
|
|
3070
|
+
missingFields,
|
|
3071
|
+
extraFields,
|
|
3072
|
+
expectedFields,
|
|
3073
|
+
actualFields,
|
|
3074
|
+
hasRequiredFields: missingRequired.length === 0,
|
|
3075
|
+
missingRequired
|
|
3076
|
+
};
|
|
3077
|
+
};
|
|
3078
|
+
const summaryValidation = validateAgainstSchema(summaryData, previewSchema);
|
|
3079
|
+
const fullValidation = validateAgainstSchema(fullData, fullSchema);
|
|
3080
|
+
if (!summaryValidation.hasRequiredFields) {
|
|
3081
|
+
const error = new Error(
|
|
3082
|
+
`Cannot save artifact: Missing required fields [${summaryValidation.missingRequired.join(", ")}] for '${artifactType}' schema. Required: [${summaryValidation.missingRequired.join(", ")}]. Found: [${summaryValidation.actualFields.join(", ")}]. Consider using a different artifact component type that matches your data structure.`
|
|
3083
|
+
);
|
|
3084
|
+
logger7.error(
|
|
3085
|
+
{
|
|
3086
|
+
artifactId,
|
|
3087
|
+
artifactType,
|
|
3088
|
+
requiredFields: summaryValidation.missingRequired,
|
|
3089
|
+
actualFields: summaryValidation.actualFields,
|
|
3090
|
+
schemaExpected: previewSchema?.properties ? Object.keys(previewSchema.properties) : []
|
|
3091
|
+
},
|
|
3092
|
+
"Blocking artifact save due to missing required fields"
|
|
3093
|
+
);
|
|
3094
|
+
throw error;
|
|
3095
|
+
}
|
|
3096
|
+
if (!summaryValidation.hasExpectedFields || summaryValidation.extraFields.length > 0) {
|
|
3097
|
+
logger7.warn(
|
|
3098
|
+
{
|
|
3099
|
+
artifactId,
|
|
3100
|
+
artifactType,
|
|
3101
|
+
dataType: "summary",
|
|
3102
|
+
expectedFields: summaryValidation.expectedFields,
|
|
3103
|
+
actualFields: summaryValidation.actualFields,
|
|
3104
|
+
missingFields: summaryValidation.missingFields,
|
|
3105
|
+
extraFields: summaryValidation.extraFields
|
|
3106
|
+
},
|
|
3107
|
+
"Summary data structure does not match preview schema"
|
|
3108
|
+
);
|
|
3109
|
+
}
|
|
3110
|
+
if (!fullValidation.hasExpectedFields || fullValidation.extraFields.length > 0) {
|
|
3111
|
+
logger7.warn(
|
|
3112
|
+
{
|
|
3113
|
+
artifactId,
|
|
3114
|
+
artifactType,
|
|
3115
|
+
dataType: "full",
|
|
3116
|
+
expectedFields: fullValidation.expectedFields,
|
|
3117
|
+
actualFields: fullValidation.actualFields,
|
|
3118
|
+
missingFields: fullValidation.missingFields,
|
|
3119
|
+
extraFields: fullValidation.extraFields
|
|
3120
|
+
},
|
|
3121
|
+
"Full data structure does not match full schema"
|
|
3122
|
+
);
|
|
3123
|
+
}
|
|
3124
|
+
return {
|
|
3125
|
+
summary: summaryValidation,
|
|
3126
|
+
full: fullValidation,
|
|
3127
|
+
schemaFound: !!originalProps
|
|
2966
3128
|
};
|
|
2967
3129
|
}
|
|
2968
3130
|
/**
|
|
2969
3131
|
* Persist artifact to database vian agent session
|
|
2970
3132
|
*/
|
|
2971
|
-
async persistArtifact(request, summaryData, fullData, subAgentId) {
|
|
3133
|
+
async persistArtifact(request, summaryData, fullData, subAgentId, schemaValidation) {
|
|
2972
3134
|
const effectiveAgentId = subAgentId || this.context.subAgentId;
|
|
2973
3135
|
if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
|
|
2974
3136
|
await agentSessionManager.recordEvent(
|
|
@@ -2990,6 +3152,11 @@ var _ArtifactService = class _ArtifactService {
|
|
|
2990
3152
|
sessionId: this.context.sessionId,
|
|
2991
3153
|
artifactType: request.type
|
|
2992
3154
|
},
|
|
3155
|
+
schemaValidation: schemaValidation || {
|
|
3156
|
+
summary: { hasExpectedFields: true, missingFields: [], extraFields: [], expectedFields: [], actualFields: [], hasRequiredFields: true, missingRequired: [] },
|
|
3157
|
+
full: { hasExpectedFields: true, missingFields: [], extraFields: [], expectedFields: [], actualFields: [], hasRequiredFields: true, missingRequired: [] },
|
|
3158
|
+
schemaFound: false
|
|
3159
|
+
},
|
|
2993
3160
|
tenantId: this.context.tenantId,
|
|
2994
3161
|
projectId: this.context.projectId,
|
|
2995
3162
|
contextId: this.context.contextId,
|
|
@@ -4484,7 +4651,29 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
4484
4651
|
has_context_id: !!artifactData.contextId,
|
|
4485
4652
|
has_metadata: !!artifactData.metadata,
|
|
4486
4653
|
tool_call_id: artifactData.metadata?.toolCallId || "missing",
|
|
4487
|
-
pending_generation: !!artifactData.pendingGeneration
|
|
4654
|
+
pending_generation: !!artifactData.pendingGeneration,
|
|
4655
|
+
// Schema validation attributes
|
|
4656
|
+
"schema_validation.schema_found": artifactData.schemaValidation?.schemaFound || false,
|
|
4657
|
+
"schema_validation.summary.has_expected_fields": artifactData.schemaValidation?.summary?.hasExpectedFields || true,
|
|
4658
|
+
"schema_validation.summary.missing_fields_count": artifactData.schemaValidation?.summary?.missingFields?.length || 0,
|
|
4659
|
+
"schema_validation.summary.extra_fields_count": artifactData.schemaValidation?.summary?.extraFields?.length || 0,
|
|
4660
|
+
"schema_validation.summary.expected_fields": JSON.stringify(artifactData.schemaValidation?.summary?.expectedFields || []),
|
|
4661
|
+
"schema_validation.summary.actual_fields": JSON.stringify(artifactData.schemaValidation?.summary?.actualFields || []),
|
|
4662
|
+
"schema_validation.summary.missing_fields": JSON.stringify(artifactData.schemaValidation?.summary?.missingFields || []),
|
|
4663
|
+
"schema_validation.summary.extra_fields": JSON.stringify(artifactData.schemaValidation?.summary?.extraFields || []),
|
|
4664
|
+
"schema_validation.summary.has_required_fields": artifactData.schemaValidation?.summary?.hasRequiredFields || true,
|
|
4665
|
+
"schema_validation.summary.missing_required_count": artifactData.schemaValidation?.summary?.missingRequired?.length || 0,
|
|
4666
|
+
"schema_validation.summary.missing_required": JSON.stringify(artifactData.schemaValidation?.summary?.missingRequired || []),
|
|
4667
|
+
"schema_validation.full.has_expected_fields": artifactData.schemaValidation?.full?.hasExpectedFields || true,
|
|
4668
|
+
"schema_validation.full.missing_fields_count": artifactData.schemaValidation?.full?.missingFields?.length || 0,
|
|
4669
|
+
"schema_validation.full.extra_fields_count": artifactData.schemaValidation?.full?.extraFields?.length || 0,
|
|
4670
|
+
"schema_validation.full.expected_fields": JSON.stringify(artifactData.schemaValidation?.full?.expectedFields || []),
|
|
4671
|
+
"schema_validation.full.actual_fields": JSON.stringify(artifactData.schemaValidation?.full?.actualFields || []),
|
|
4672
|
+
"schema_validation.full.missing_fields": JSON.stringify(artifactData.schemaValidation?.full?.missingFields || []),
|
|
4673
|
+
"schema_validation.full.extra_fields": JSON.stringify(artifactData.schemaValidation?.full?.extraFields || []),
|
|
4674
|
+
"schema_validation.full.has_required_fields": artifactData.schemaValidation?.full?.hasRequiredFields || true,
|
|
4675
|
+
"schema_validation.full.missing_required_count": artifactData.schemaValidation?.full?.missingRequired?.length || 0,
|
|
4676
|
+
"schema_validation.full.missing_required": JSON.stringify(artifactData.schemaValidation?.full?.missingRequired || [])
|
|
4488
4677
|
}
|
|
4489
4678
|
},
|
|
4490
4679
|
async (span) => {
|
package/dist/index.js
CHANGED
|
@@ -1353,9 +1353,11 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1353
1353
|
const component = this.context.artifactComponents?.find((ac) => ac.name === request.type);
|
|
1354
1354
|
let summaryData = {};
|
|
1355
1355
|
let fullData = {};
|
|
1356
|
+
let previewSchema = null;
|
|
1357
|
+
let fullSchema = null;
|
|
1356
1358
|
if (component?.props) {
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
+
previewSchema = extractPreviewFields(component.props);
|
|
1360
|
+
fullSchema = extractFullFields(component.props);
|
|
1359
1361
|
summaryData = this.extractPropsFromSchema(
|
|
1360
1362
|
selectedData,
|
|
1361
1363
|
previewSchema,
|
|
@@ -1378,6 +1380,15 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1378
1380
|
}
|
|
1379
1381
|
const cleanedSummaryData = this.cleanEscapedContent(summaryData);
|
|
1380
1382
|
const cleanedFullData = this.cleanEscapedContent(fullData);
|
|
1383
|
+
const schemaValidation = this.validateExtractedData(
|
|
1384
|
+
request.artifactId,
|
|
1385
|
+
request.type,
|
|
1386
|
+
cleanedSummaryData,
|
|
1387
|
+
cleanedFullData,
|
|
1388
|
+
previewSchema,
|
|
1389
|
+
fullSchema,
|
|
1390
|
+
component?.props
|
|
1391
|
+
);
|
|
1381
1392
|
const artifactData = {
|
|
1382
1393
|
artifactId: request.artifactId,
|
|
1383
1394
|
toolCallId: request.toolCallId,
|
|
@@ -1386,7 +1397,7 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1386
1397
|
type: request.type,
|
|
1387
1398
|
data: cleanedSummaryData
|
|
1388
1399
|
};
|
|
1389
|
-
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId);
|
|
1400
|
+
await this.persistArtifact(request, cleanedSummaryData, cleanedFullData, subAgentId, schemaValidation);
|
|
1390
1401
|
await this.cacheArtifact(
|
|
1391
1402
|
request.artifactId,
|
|
1392
1403
|
request.toolCallId,
|
|
@@ -1496,32 +1507,183 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1496
1507
|
* Format raw artifact to standardized summary data format
|
|
1497
1508
|
*/
|
|
1498
1509
|
formatArtifactSummaryData(artifact, artifactId, toolCallId) {
|
|
1510
|
+
let data = artifact.parts?.[0]?.data?.summary;
|
|
1511
|
+
let dataSource = "parts[0].data.summary";
|
|
1512
|
+
if (!data || typeof data === "object" && Object.keys(data).length === 0) {
|
|
1513
|
+
data = artifact.parts?.[0]?.data;
|
|
1514
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
1515
|
+
dataSource = "parts[0].data (fallback)";
|
|
1516
|
+
logger6.debug(
|
|
1517
|
+
{ artifactId, toolCallId, dataSource },
|
|
1518
|
+
"Using fallback data source for artifact summary"
|
|
1519
|
+
);
|
|
1520
|
+
} else {
|
|
1521
|
+
data = artifact.data;
|
|
1522
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
1523
|
+
dataSource = "artifact.data (fallback)";
|
|
1524
|
+
logger6.debug(
|
|
1525
|
+
{ artifactId, toolCallId, dataSource },
|
|
1526
|
+
"Using fallback data source for artifact summary"
|
|
1527
|
+
);
|
|
1528
|
+
} else {
|
|
1529
|
+
data = {};
|
|
1530
|
+
dataSource = "empty (no data found)";
|
|
1531
|
+
logger6.warn(
|
|
1532
|
+
{
|
|
1533
|
+
artifactId,
|
|
1534
|
+
toolCallId,
|
|
1535
|
+
artifactStructure: {
|
|
1536
|
+
hasParts: !!artifact.parts,
|
|
1537
|
+
partsLength: artifact.parts?.length,
|
|
1538
|
+
hasPartsData: !!artifact.parts?.[0]?.data,
|
|
1539
|
+
hasPartsSummary: !!artifact.parts?.[0]?.data?.summary,
|
|
1540
|
+
hasArtifactData: !!artifact.data,
|
|
1541
|
+
artifactKeys: Object.keys(artifact || {})
|
|
1542
|
+
}
|
|
1543
|
+
},
|
|
1544
|
+
"No valid data found for artifact summary - using empty object"
|
|
1545
|
+
);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1499
1549
|
return {
|
|
1500
1550
|
artifactId,
|
|
1501
1551
|
toolCallId,
|
|
1502
1552
|
name: artifact.name || "Processing...",
|
|
1503
1553
|
description: artifact.description || "Name and description being generated...",
|
|
1504
1554
|
type: artifact.metadata?.artifactType || artifact.artifactType,
|
|
1505
|
-
data
|
|
1555
|
+
data
|
|
1506
1556
|
};
|
|
1507
1557
|
}
|
|
1508
1558
|
/**
|
|
1509
1559
|
* Format raw artifact to standardized full data format
|
|
1510
1560
|
*/
|
|
1511
1561
|
formatArtifactFullData(artifact, artifactId, toolCallId) {
|
|
1562
|
+
let data = artifact.parts?.[0]?.data?.full;
|
|
1563
|
+
let dataSource = "parts[0].data.full";
|
|
1564
|
+
if (!data || typeof data === "object" && Object.keys(data).length === 0) {
|
|
1565
|
+
data = artifact.parts?.[0]?.data;
|
|
1566
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
1567
|
+
dataSource = "parts[0].data (fallback)";
|
|
1568
|
+
logger6.debug(
|
|
1569
|
+
{ artifactId, toolCallId, dataSource },
|
|
1570
|
+
"Using fallback data source for artifact full data"
|
|
1571
|
+
);
|
|
1572
|
+
} else {
|
|
1573
|
+
data = artifact.data;
|
|
1574
|
+
if (data && !(typeof data === "object" && Object.keys(data).length === 0)) {
|
|
1575
|
+
dataSource = "artifact.data (fallback)";
|
|
1576
|
+
logger6.debug(
|
|
1577
|
+
{ artifactId, toolCallId, dataSource },
|
|
1578
|
+
"Using fallback data source for artifact full data"
|
|
1579
|
+
);
|
|
1580
|
+
} else {
|
|
1581
|
+
data = {};
|
|
1582
|
+
dataSource = "empty (no data found)";
|
|
1583
|
+
logger6.warn(
|
|
1584
|
+
{
|
|
1585
|
+
artifactId,
|
|
1586
|
+
toolCallId,
|
|
1587
|
+
artifactStructure: {
|
|
1588
|
+
hasParts: !!artifact.parts,
|
|
1589
|
+
partsLength: artifact.parts?.length,
|
|
1590
|
+
hasPartsData: !!artifact.parts?.[0]?.data,
|
|
1591
|
+
hasPartsFull: !!artifact.parts?.[0]?.data?.full,
|
|
1592
|
+
hasArtifactData: !!artifact.data,
|
|
1593
|
+
artifactKeys: Object.keys(artifact || {})
|
|
1594
|
+
}
|
|
1595
|
+
},
|
|
1596
|
+
"No valid data found for artifact full data - using empty object"
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1512
1601
|
return {
|
|
1513
1602
|
artifactId,
|
|
1514
1603
|
toolCallId,
|
|
1515
1604
|
name: artifact.name || "Processing...",
|
|
1516
1605
|
description: artifact.description || "Name and description being generated...",
|
|
1517
1606
|
type: artifact.metadata?.artifactType || artifact.artifactType,
|
|
1518
|
-
data
|
|
1607
|
+
data
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Validate extracted data against the schemas used for extraction
|
|
1612
|
+
*/
|
|
1613
|
+
validateExtractedData(artifactId, artifactType, summaryData, fullData, previewSchema, fullSchema, originalProps) {
|
|
1614
|
+
const validateAgainstSchema = (data, schema) => {
|
|
1615
|
+
const actualFields = Object.keys(data || {});
|
|
1616
|
+
const expectedFields = schema?.properties ? Object.keys(schema.properties) : [];
|
|
1617
|
+
const missingFields = expectedFields.filter((field) => !(field in (data || {})));
|
|
1618
|
+
const extraFields = actualFields.filter((field) => !expectedFields.includes(field));
|
|
1619
|
+
const requiredFields = schema?.required || [];
|
|
1620
|
+
const missingRequired = requiredFields.filter((field) => !(field in (data || {})));
|
|
1621
|
+
return {
|
|
1622
|
+
hasExpectedFields: missingFields.length === 0,
|
|
1623
|
+
missingFields,
|
|
1624
|
+
extraFields,
|
|
1625
|
+
expectedFields,
|
|
1626
|
+
actualFields,
|
|
1627
|
+
hasRequiredFields: missingRequired.length === 0,
|
|
1628
|
+
missingRequired
|
|
1629
|
+
};
|
|
1630
|
+
};
|
|
1631
|
+
const summaryValidation = validateAgainstSchema(summaryData, previewSchema);
|
|
1632
|
+
const fullValidation = validateAgainstSchema(fullData, fullSchema);
|
|
1633
|
+
if (!summaryValidation.hasRequiredFields) {
|
|
1634
|
+
const error = new Error(
|
|
1635
|
+
`Cannot save artifact: Missing required fields [${summaryValidation.missingRequired.join(", ")}] for '${artifactType}' schema. Required: [${summaryValidation.missingRequired.join(", ")}]. Found: [${summaryValidation.actualFields.join(", ")}]. Consider using a different artifact component type that matches your data structure.`
|
|
1636
|
+
);
|
|
1637
|
+
logger6.error(
|
|
1638
|
+
{
|
|
1639
|
+
artifactId,
|
|
1640
|
+
artifactType,
|
|
1641
|
+
requiredFields: summaryValidation.missingRequired,
|
|
1642
|
+
actualFields: summaryValidation.actualFields,
|
|
1643
|
+
schemaExpected: previewSchema?.properties ? Object.keys(previewSchema.properties) : []
|
|
1644
|
+
},
|
|
1645
|
+
"Blocking artifact save due to missing required fields"
|
|
1646
|
+
);
|
|
1647
|
+
throw error;
|
|
1648
|
+
}
|
|
1649
|
+
if (!summaryValidation.hasExpectedFields || summaryValidation.extraFields.length > 0) {
|
|
1650
|
+
logger6.warn(
|
|
1651
|
+
{
|
|
1652
|
+
artifactId,
|
|
1653
|
+
artifactType,
|
|
1654
|
+
dataType: "summary",
|
|
1655
|
+
expectedFields: summaryValidation.expectedFields,
|
|
1656
|
+
actualFields: summaryValidation.actualFields,
|
|
1657
|
+
missingFields: summaryValidation.missingFields,
|
|
1658
|
+
extraFields: summaryValidation.extraFields
|
|
1659
|
+
},
|
|
1660
|
+
"Summary data structure does not match preview schema"
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
if (!fullValidation.hasExpectedFields || fullValidation.extraFields.length > 0) {
|
|
1664
|
+
logger6.warn(
|
|
1665
|
+
{
|
|
1666
|
+
artifactId,
|
|
1667
|
+
artifactType,
|
|
1668
|
+
dataType: "full",
|
|
1669
|
+
expectedFields: fullValidation.expectedFields,
|
|
1670
|
+
actualFields: fullValidation.actualFields,
|
|
1671
|
+
missingFields: fullValidation.missingFields,
|
|
1672
|
+
extraFields: fullValidation.extraFields
|
|
1673
|
+
},
|
|
1674
|
+
"Full data structure does not match full schema"
|
|
1675
|
+
);
|
|
1676
|
+
}
|
|
1677
|
+
return {
|
|
1678
|
+
summary: summaryValidation,
|
|
1679
|
+
full: fullValidation,
|
|
1680
|
+
schemaFound: !!originalProps
|
|
1519
1681
|
};
|
|
1520
1682
|
}
|
|
1521
1683
|
/**
|
|
1522
1684
|
* Persist artifact to database vian agent session
|
|
1523
1685
|
*/
|
|
1524
|
-
async persistArtifact(request, summaryData, fullData, subAgentId) {
|
|
1686
|
+
async persistArtifact(request, summaryData, fullData, subAgentId, schemaValidation) {
|
|
1525
1687
|
const effectiveAgentId = subAgentId || this.context.subAgentId;
|
|
1526
1688
|
if (this.context.streamRequestId && effectiveAgentId && this.context.taskId) {
|
|
1527
1689
|
await agentSessionManager.recordEvent(
|
|
@@ -1543,6 +1705,11 @@ var _ArtifactService = class _ArtifactService {
|
|
|
1543
1705
|
sessionId: this.context.sessionId,
|
|
1544
1706
|
artifactType: request.type
|
|
1545
1707
|
},
|
|
1708
|
+
schemaValidation: schemaValidation || {
|
|
1709
|
+
summary: { hasExpectedFields: true, missingFields: [], extraFields: [], expectedFields: [], actualFields: [], hasRequiredFields: true, missingRequired: [] },
|
|
1710
|
+
full: { hasExpectedFields: true, missingFields: [], extraFields: [], expectedFields: [], actualFields: [], hasRequiredFields: true, missingRequired: [] },
|
|
1711
|
+
schemaFound: false
|
|
1712
|
+
},
|
|
1546
1713
|
tenantId: this.context.tenantId,
|
|
1547
1714
|
projectId: this.context.projectId,
|
|
1548
1715
|
contextId: this.context.contextId,
|
|
@@ -3037,7 +3204,29 @@ ${this.statusUpdateState?.config.prompt?.trim() || ""}`;
|
|
|
3037
3204
|
has_context_id: !!artifactData.contextId,
|
|
3038
3205
|
has_metadata: !!artifactData.metadata,
|
|
3039
3206
|
tool_call_id: artifactData.metadata?.toolCallId || "missing",
|
|
3040
|
-
pending_generation: !!artifactData.pendingGeneration
|
|
3207
|
+
pending_generation: !!artifactData.pendingGeneration,
|
|
3208
|
+
// Schema validation attributes
|
|
3209
|
+
"schema_validation.schema_found": artifactData.schemaValidation?.schemaFound || false,
|
|
3210
|
+
"schema_validation.summary.has_expected_fields": artifactData.schemaValidation?.summary?.hasExpectedFields || true,
|
|
3211
|
+
"schema_validation.summary.missing_fields_count": artifactData.schemaValidation?.summary?.missingFields?.length || 0,
|
|
3212
|
+
"schema_validation.summary.extra_fields_count": artifactData.schemaValidation?.summary?.extraFields?.length || 0,
|
|
3213
|
+
"schema_validation.summary.expected_fields": JSON.stringify(artifactData.schemaValidation?.summary?.expectedFields || []),
|
|
3214
|
+
"schema_validation.summary.actual_fields": JSON.stringify(artifactData.schemaValidation?.summary?.actualFields || []),
|
|
3215
|
+
"schema_validation.summary.missing_fields": JSON.stringify(artifactData.schemaValidation?.summary?.missingFields || []),
|
|
3216
|
+
"schema_validation.summary.extra_fields": JSON.stringify(artifactData.schemaValidation?.summary?.extraFields || []),
|
|
3217
|
+
"schema_validation.summary.has_required_fields": artifactData.schemaValidation?.summary?.hasRequiredFields || true,
|
|
3218
|
+
"schema_validation.summary.missing_required_count": artifactData.schemaValidation?.summary?.missingRequired?.length || 0,
|
|
3219
|
+
"schema_validation.summary.missing_required": JSON.stringify(artifactData.schemaValidation?.summary?.missingRequired || []),
|
|
3220
|
+
"schema_validation.full.has_expected_fields": artifactData.schemaValidation?.full?.hasExpectedFields || true,
|
|
3221
|
+
"schema_validation.full.missing_fields_count": artifactData.schemaValidation?.full?.missingFields?.length || 0,
|
|
3222
|
+
"schema_validation.full.extra_fields_count": artifactData.schemaValidation?.full?.extraFields?.length || 0,
|
|
3223
|
+
"schema_validation.full.expected_fields": JSON.stringify(artifactData.schemaValidation?.full?.expectedFields || []),
|
|
3224
|
+
"schema_validation.full.actual_fields": JSON.stringify(artifactData.schemaValidation?.full?.actualFields || []),
|
|
3225
|
+
"schema_validation.full.missing_fields": JSON.stringify(artifactData.schemaValidation?.full?.missingFields || []),
|
|
3226
|
+
"schema_validation.full.extra_fields": JSON.stringify(artifactData.schemaValidation?.full?.extraFields || []),
|
|
3227
|
+
"schema_validation.full.has_required_fields": artifactData.schemaValidation?.full?.hasRequiredFields || true,
|
|
3228
|
+
"schema_validation.full.missing_required_count": artifactData.schemaValidation?.full?.missingRequired?.length || 0,
|
|
3229
|
+
"schema_validation.full.missing_required": JSON.stringify(artifactData.schemaValidation?.full?.missingRequired || [])
|
|
3041
3230
|
}
|
|
3042
3231
|
},
|
|
3043
3232
|
async (span) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-run-api",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20251022171155",
|
|
4
4
|
"description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"traverse": "^0.6.11",
|
|
53
53
|
"ts-pattern": "^5.7.1",
|
|
54
54
|
"zod": "^4.1.11",
|
|
55
|
-
"@inkeep/agents-core": "^0.0.0-dev-
|
|
55
|
+
"@inkeep/agents-core": "^0.0.0-dev-20251022171155"
|
|
56
56
|
},
|
|
57
57
|
"optionalDependencies": {
|
|
58
58
|
"keytar": "^7.9.0"
|