feat(metadata): replace aiAutofill boolean with autofillSource enum (#302)

* feat(metadata): replace aiAutofill boolean with autofillSource enum

* fix(agent): validate creation-context metadata and make writes transactional

Address code review feedback on the autofillSource migration:

- Update the agent system prompt to reference the 'metadata' parameter of
  create_file/create_version instead of the removed 'context' parameter,
  which was being silently discarded by the activity
- Write metadata inside the caller's transaction via the new
  metadataService.updateAssetMetadataInTx, keeping metadata rows atomic
  with asset creation instead of opening a separate non-atomic transaction
- Reject metadata keys that are not defined CREATION_CONTEXT fields of the
  project with a non-retryable ApplicationFailure before creating the asset
- Remove dead agentContext handling from autofillAiActivity and its tests,
  and drop the unused ai_autofill i18n keys (paraglide recompiled)
- Derive the DTO autofillSource enum from the AutofillSource const instead
  of a hardcoded z.enum to prevent drift
This commit is contained in:
Yiling-J
2026-08-13 13:41:46 +08:00
committed by GitHub
parent 96493a5493
commit 41b73feeab
57 changed files with 1118 additions and 663 deletions
+5 -7
View File
@@ -17,13 +17,11 @@ const createVersionSchema = Type.Object({
description:
'The absolute or relative local path to the file on disk. This parameter is required.',
}),
context: Type.Optional(
Type.String({
metadata: Type.Optional(
Type.Record(Type.String(), Type.Any(), {
description:
'Optional context passed to the AI metadata autofill workflow for fields that cannot be inferred from file content alone ' +
'(e.g. the model or prompt used to generate the asset). ' +
'Use list_autofill_fields first to check which fields can be autofilled. ' +
'Keep the context short and only include information relevant to those fields.',
'Key-value map of CREATION_CONTEXT metadata field keys and their values (e.g. prompt, model, provider). ' +
'Use list_autofill_fields first to inspect available CREATION_CONTEXT fields.',
}),
),
})
@@ -55,7 +53,7 @@ export function createCreateVersionTool(userId: string): AgentTool<typeof create
name: path.basename(absolutePath),
size: fileSize,
contentType: mimeType,
...(params.context ? { context: params.context } : {}),
...(params.metadata ? { metadata: params.metadata } : {}),
},
userId,
assetId: params.parent,