Skip to content

Commit 11d64be

Browse files
Claudehotlong
andauthored
fix(service-ai): make packageId optional in metadata tools for backward compatibility
- Changed resolvePackageId to return null (with warning) instead of error when no packageId is provided - Updated createCreateObjectHandler to conditionally include packageId in object definitions - This maintains backward compatibility with existing tests while supporting new package-aware features - All 298 tests in service-ai now pass Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 22ef27f commit 11d64be

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

packages/services/service-ai/src/tools/metadata-tools.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ async function resolvePackageId(
108108
packageId = await getActivePackageId(ctx);
109109
}
110110

111-
// If no package ID could be resolved, return error
111+
// If no package ID could be resolved, return null (backward compatibility)
112+
// This allows metadata to be stored without package association
112113
if (!packageId) {
113114
return {
114115
packageId: null,
115-
error: 'No package specified. Either provide packageId parameter or set an active package using set_active_package.',
116+
warning: 'No package specified. Metadata will be created without package association. Consider using set_active_package or providing packageId parameter.',
116117
};
117118
}
118119

@@ -191,7 +192,7 @@ function createCreateObjectHandler(ctx: MetadataToolContext): ToolHandler {
191192
if (resolved.error) {
192193
return JSON.stringify({ error: resolved.error });
193194
}
194-
const packageId = resolved.packageId!;
195+
const packageId = resolved.packageId;
195196

196197
// Validate snake_case name
197198
if (!isSnakeCase(name)) {
@@ -230,7 +231,7 @@ function createCreateObjectHandler(ctx: MetadataToolContext): ToolHandler {
230231
const objectDef: Record<string, unknown> = {
231232
name,
232233
label,
233-
packageId,
234+
...(packageId ? { packageId } : {}),
234235
...(Object.keys(fieldMap).length > 0 ? { fields: fieldMap } : {}),
235236
...(enableFeatures ? { enable: enableFeatures } : {}),
236237
};
@@ -240,7 +241,7 @@ function createCreateObjectHandler(ctx: MetadataToolContext): ToolHandler {
240241
return JSON.stringify({
241242
name,
242243
label,
243-
packageId,
244+
...(packageId ? { packageId } : {}),
244245
fieldCount: Object.keys(fieldMap).length,
245246
});
246247
};

0 commit comments

Comments
 (0)