chore(chat): support isNewChat payload flag and fix any casts

This commit is contained in:
yiling
2026-07-11 21:05:47 +08:00
parent c5ce4d07e9
commit b57a3e0239
5 changed files with 11 additions and 10 deletions
+7 -7
View File
@@ -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'
@@ -18,10 +18,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 { UpdateAssetMetadataRequest } from '@shumai/dtos'
+1 -2
View File
@@ -135,10 +135,9 @@ export async function createAgentSession(params: CreateAgentSessionParams) {
const agentDir = path.join(process.cwd(), '.pi', 'agents', agentId)
if (!fs.existsSync(agentDir)) fs.mkdirSync(agentDir, { recursive: true })
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const model =
getModelFromDb(params.providers, providerName, modelId) ||
(getModel as any)(providerName, modelId)
(getModel as unknown as (p: string, m: string) => unknown)(providerName, modelId)
const piDir = path.join(process.cwd(), '.pi')
if (!fs.existsSync(piDir)) fs.mkdirSync(piDir, { recursive: true })
+1 -1
View File
@@ -92,7 +92,7 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
const teamId = asset.project.teamId
// 4. Initialize Session if missing
let isNewChat = !payload.agent?.sessionId
let isNewChat = !payload.agent?.sessionId || payload.agent?.isNewChat === true
if (!sessionId) {
if (!userCommentId) {
throw ApplicationFailure.create({
+1
View File
@@ -302,6 +302,7 @@ export class ChatService {
agentId,
sessionId: activeSessionId,
userId: user.id,
isNewChat: !passedSessionId,
},
},
},
+1
View File
@@ -293,6 +293,7 @@ declare global {
imageUrls?: string[]
attachedFiles?: string[]
assetIds?: string[]
isNewChat?: boolean
}
// ----------------------------------------------------------------------