Import apps/vscode/src/remote.ts

This commit is contained in:
QQ 2026-11-17 08:38:37 +08:00
parent 9b1c5da892
commit f3f4420027
1 changed files with 14 additions and 3 deletions

View File

@ -155,9 +155,20 @@ export class RemoteConnection {
return this.call('session.create', options.workspaceId ? { workspaceId: options.workspaceId } : options.cwd ? { cwd: options.cwd } : {})
}
async prompt(sessionId: string, text: string): Promise<void> {
if (this.alpha !== undefined) return this.alpha.sessionPrompt(sessionId, text)
await this.call('session.prompt', { sessionId, mode: 'queue', content: [{ type: 'text', text }] })
async prompt(sessionId: string, text: string, images: { mediaType: string; data: string; name?: string }[] = []): Promise<void> {
const promptImages = images.filter(image => ['image/png', 'image/jpeg', 'image/webp', 'image/gif'].includes(image.mediaType))
const attachments = images.filter(image => !promptImages.includes(image))
if (this.alpha !== undefined) {
const files: { receiptId: string }[] = []
for (const file of attachments) {
const uploaded = await this.alpha.sessionUploadFile(sessionId, file.data, file.name)
if (typeof uploaded.receiptId !== 'string' || uploaded.receiptId.length === 0) throw new Error('Host returned an invalid file receipt.')
files.push({ receiptId: uploaded.receiptId })
}
return this.alpha.sessionPrompt(sessionId, text, undefined, promptImages, files)
}
if (attachments.length > 0) throw new Error('File attachments require an updated Harness Remote Host.')
await this.call('session.prompt', { sessionId, mode: 'queue', content: [...(text ? [{ type: 'text', text }] : []), ...images.map(image => ({ type: 'image', ...image }))] })
}
async cancelSession(sessionId: string): Promise<void> {