mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-11 14:10:15 -07:00
AIX: Anthropic: Download Files (AIX hosted resource support)
This commit is contained in:
@@ -347,6 +347,12 @@ export class ChatGenerateTransmitter implements IParticleTransmitter {
|
||||
this._queueParticleS();
|
||||
}
|
||||
|
||||
/** Appends a hosted resource (e.g. Anthropic container file) - inline content between text fragments */
|
||||
appendHostedResource(hres: Extract<AixWire_Particles.PartParticleOp, { p: 'hres' }>) {
|
||||
this.endMessagePart();
|
||||
this.transmissionQueue.push(hres);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Undocumented, internal, as the IPartTransmitter callers will call setDialectTerminatingIssue instead
|
||||
|
||||
@@ -45,6 +45,9 @@ export interface IParticleTransmitter {
|
||||
/** Appends an image generated by the model */
|
||||
appendImageInline(mimeType: string, base64Data: string, label: string, generator: string, prompt: string, hintSkipResize?: boolean): void;
|
||||
|
||||
/** Appends a hosted resource (e.g. Anthropic container file) - inline content between text fragments */
|
||||
appendHostedResource(hres: Extract<AixWire_Particles.PartParticleOp, { p: 'hres' }>): void;
|
||||
|
||||
/**
|
||||
* Creates a FC part, flushing the previous one if needed, and starts adding data to it
|
||||
* @param id if null [Gemini], a new id will be generated to keep it linked to future tool responses
|
||||
@@ -66,6 +69,7 @@ export interface IParticleTransmitter {
|
||||
/** Adds a URL citation part */
|
||||
appendUrlCitation(title: string, url: string, citationNumber?: number, startIndex?: number, endIndex?: number, textSnippet?: string, pubTs?: number): void;
|
||||
|
||||
|
||||
// Special //
|
||||
|
||||
/** Sends control particles right away, such as aix-info/aix-retry-reset/... control particles */
|
||||
|
||||
@@ -887,14 +887,11 @@ function _handleCBS_CodeExecutionToolResult(pt: IParticleTransmitter, block: Ext
|
||||
const codeExecFailed = block.content.return_code !== 0;
|
||||
pt.sendOperationState('code-exec', codeExecFailed ? `Code executed` /* was: failed */ : 'Code executed', { opId, state: codeExecFailed ? 'error' : 'done', ...oTexts.length ? { oTexts } : undefined });
|
||||
|
||||
// add text if there are generated files in content array (e.g. generated from a skill)
|
||||
const fileIds: string[] = [];
|
||||
// emit structured hosted resource references for generated files (e.g. from a skill)
|
||||
if (Array.isArray(block.content?.content))
|
||||
for (const ob of block.content.content)
|
||||
if (ob.type === 'code_execution_output' && ob.file_id)
|
||||
fileIds.push(ob.file_id);
|
||||
if (fileIds.length > 0)
|
||||
pt.appendText(`\n\n⚡ Code executed by Skill\n${fileIds.map(id => `\n📎 File: \`${id}\``).join('')}\n`);
|
||||
pt.appendHostedResource({ p: 'hres', kind: 'vnd.ant.file', fileId: ob.file_id });
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -922,14 +919,11 @@ function _handleCBS_BashCodeExecutionToolResult(pt: IParticleTransmitter, block:
|
||||
const bashFailed = block.content.return_code !== 0;
|
||||
pt.sendOperationState('code-exec', bashFailed ? `Bash executed` /* was: failed */ : 'Bash executed', { opId, state: bashFailed ? 'error' : 'done', ...oTexts.length ? { oTexts } : undefined });
|
||||
|
||||
// add text if there are generated files in content array
|
||||
const fileIds: string[] = [];
|
||||
// emit structured hosted resource references for generated files
|
||||
if (Array.isArray(block.content.content))
|
||||
for (const ob of block.content.content)
|
||||
if (ob.type === 'bash_code_execution_output' && ob.file_id)
|
||||
fileIds.push(ob.file_id);
|
||||
if (fileIds.length > 0)
|
||||
pt.appendText(`\n\n⚡ Bash executed by Skill\n${fileIds.map(id => `\n📎 File: \`${id}\``).join('')}\n`);
|
||||
pt.appendHostedResource({ p: 'hres', kind: 'vnd.ant.file', fileId: ob.file_id });
|
||||
break;
|
||||
|
||||
case 'bash_code_execution_tool_result_error':
|
||||
@@ -972,9 +966,8 @@ function _handleCBS_TextEditorCodeExecutionToolResult(pt: IParticleTransmitter,
|
||||
}
|
||||
|
||||
function _handleCBS_ContainerUpload(pt: IParticleTransmitter, block: Extract<_ContentBlock, { type: 'container_upload' }>, containerId: string | undefined): void {
|
||||
// Container upload - this is when a Skill has generated a file - file_id can be used with the Files API to download the file
|
||||
pt.appendText(`\n\n⚡ File uploaded to container (${containerId || 'none'})\n\n📎 File: \`${block.file_id}\`\n\n`);
|
||||
// TODO: Future enhancement - could trigger automatic file download here using the Files API with content_block.file_id, or offer an UI way to do so through a dedicated part/block?
|
||||
// Container upload - Skill has generated a file, emit as a downloadable hosted resource
|
||||
pt.appendHostedResource({ p: 'hres', kind: 'vnd.ant.file', fileId: block.file_id, ...(containerId ? { containerId } : {}) });
|
||||
}
|
||||
|
||||
function _handleCBS_ToolSearchToolResult(pt: IParticleTransmitter, block: Extract<_ContentBlock, { type: 'tool_search_tool_result' }>): void {
|
||||
|
||||
Reference in New Issue
Block a user