From b806b0e2baa3da31db881a1572bcdf527e7c3072 Mon Sep 17 00:00:00 2001 From: yiling Date: Wed, 5 Aug 2026 10:53:19 +0800 Subject: [PATCH] refactor(agent): drop field/option ids from list_autofill_fields results --- packages/agent/src/activities/agent.test.ts | 11 ++++----- packages/agent/src/activities/agent.ts | 23 +++++++++++-------- .../src/tools/list-autofill-fields.test.ts | 4 ++-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/packages/agent/src/activities/agent.test.ts b/packages/agent/src/activities/agent.test.ts index f9f66191..0da29dce 100644 --- a/packages/agent/src/activities/agent.test.ts +++ b/packages/agent/src/activities/agent.test.ts @@ -1726,15 +1726,14 @@ describe('Agent Database Activities Integration', () => { }) expect(res.fields).toHaveLength(2) - const source = res.fields.find((f: { id: string }) => f.id === 'source') + const source = res.fields.find((f: { name: string }) => f.name === 'Source') expect(source?.name).toBe('Source') expect(source?.type).toBe('select') expect(source?.description).toBe('Generation source') - expect(source?.options).toEqual([ - { id: 'gemini', displayName: 'Gemini', color: '#ffffff' }, - { id: 'seedance', displayName: 'Seedance', color: '#ffffff' }, - ]) - expect(res.fields.find((f: { id: string }) => f.id === 'manual_notes')).toBeUndefined() + expect(source?.options).toEqual([{ displayName: 'Gemini' }, { displayName: 'Seedance' }]) + expect( + res.fields.find((f: { name: string }) => f.name === 'Manual Notes'), + ).toBeUndefined() }) it('should resolve the project through the ancestor chain', async () => { diff --git a/packages/agent/src/activities/agent.ts b/packages/agent/src/activities/agent.ts index f2ff9509..ea9701a9 100644 --- a/packages/agent/src/activities/agent.ts +++ b/packages/agent/src/activities/agent.ts @@ -1,7 +1,7 @@ import { - type AgentMessage, - type AgentTool, - type SessionTreeEntry, + type AgentMessage, + type AgentTool, + type SessionTreeEntry, } from '@earendil-works/pi-agent-core' import { type ImageContent } from '@earendil-works/pi-ai' import { assetService } from '@shumai/core/src/asset/asset' @@ -19,10 +19,10 @@ import { generateKeyBetween } from 'jittered-fractional-indexing' import { ulid } from 'ulid' import { DatabaseSessionStorage } from '../database-session-storage' import { - createAgentSession, - fieldsToTypeBoxSchema, - type AutofillField, - type DbProviderInfo, + createAgentSession, + fieldsToTypeBoxSchema, + type AutofillField, + type DbProviderInfo, } from '../index' import { aiUsageService } from '@shumai/core/src/ai-usage/ai-usage' @@ -96,7 +96,7 @@ shumai has its own cloud file system. If a user asks you to perform file system If you need to create files in the local filesystem (for example, a temporary file for uploading), only the '.pi' folder in the current directory has write permissions. Do NOT attempt to create files in any other directories. -Before creating a file or version, use 'list_autofill_fields' to check the project's AI-autofillable metadata fields. If relevant, pass a short, simple context (max 50 words) about the file's source or how it was generated via the 'context' parameter of 'create_file' or 'create_version'.` +When creating a file or version, first use 'list_autofill_fields' to inspect the project's AI-autofillable metadata fields. If relevant metadata depends on information unavailable from the file content (for example, the AI model or tool used to generate it), include a brief context hint (maximum 50 words) in the 'context' parameter.` if (agent.soul) { systemPrompt = `${systemPrompt}\n\nAgent Personality and Core Instructions:\n${agent.soul}` @@ -1457,11 +1457,14 @@ export async function executeAgentToolActivity(params: ExecuteAgentToolParams): const autofillFields = fields .filter((f) => f.field.aiAutofill) .map((f) => ({ - id: f.field.key, name: f.field.config?.name, type: f.field.config?.type, description: f.field.description, - options: f.field.config?.select?.options ?? f.field.config?.selectMulti?.options ?? [], + options: ( + f.field.config?.select?.options ?? + f.field.config?.selectMulti?.options ?? + [] + ).map((o) => ({ displayName: o.displayName })), })) return { fields: autofillFields } diff --git a/packages/agent/src/tools/list-autofill-fields.test.ts b/packages/agent/src/tools/list-autofill-fields.test.ts index 28e32c02..5e0f9231 100644 --- a/packages/agent/src/tools/list-autofill-fields.test.ts +++ b/packages/agent/src/tools/list-autofill-fields.test.ts @@ -4,7 +4,7 @@ import { executeAgentToolWorkflow } from './utils' vi.mock('./utils', () => ({ executeAgentToolWorkflow: vi.fn().mockResolvedValue({ - fields: [{ id: 'source', name: 'Source', type: 'select', options: [] }], + fields: [{ name: 'Source', type: 'select', options: [{ displayName: 'Gemini' }] }], }), })) @@ -25,7 +25,7 @@ describe('createListAutofillFieldsTool', () => { }) expect(result.details).toEqual({ - fields: [{ id: 'source', name: 'Source', type: 'select', options: [] }], + fields: [{ name: 'Source', type: 'select', options: [{ displayName: 'Gemini' }] }], }) }) })