Native File Tasks and AI Response UI
Use SwiftBiu's native session interfaces when a background action needs continuous progress, structured errors, or streaming AI output. Do not replace these workflows with repeated notifications or another custom floating window.
Native File Task Progress Panel
Use this for organizers, exporters, renamers, movers, compressors, and other actions that modify local files.
Background script.js can call:
SwiftBiu.beginFileTask(options): creates a native file-processing session and returnssessionID.SwiftBiu.updateFileTask(sessionID, options): updates progress, logs, and structured state.SwiftBiu.finishFileTask(sessionID, options): marks the task as completed.SwiftBiu.failFileTask(sessionID, options): marks the task as failed.
Common options
- Core progress:
headlineText,detailText,totalCount,completedCount,skippedCount,progress,batchItems - Rich logs:
activityEntrieswith{ message, category, isPinned } - Plan preview:
summaryChipswith{ title, count, tone } - Grouped failures:
failureGroupswith{ identifier, title, count, items, detailText } - Section labels:
sectionTitleswithplanTitle,logTitle,fileTitle,failureTitle,actionTitle - Completion actions:
actionButtons, currently supportingrevealTargetsandundoMoves - Action payloads:
targetDirectoryPathsandundoOperations
Recommended Workflow
- Show the category plan before the first write.
- Ask for native folder authorization as soon as access is missing; stop when the user cancels.
- Stream milestones such as folder creation, move start, conflict skip, and category completion.
- Group name conflicts and permission failures separately.
- Show “open target folder” or “undo this run” only when the required paths and rollback data exist.
function performAction(context) {
const sessionID = SwiftBiu.beginFileTask({
headlineText: "Organize Files",
totalCount: context.selectedFiles.length,
completedCount: 0
});
try {
context.selectedFiles.forEach((file, index) => {
// ... process file ...
SwiftBiu.updateFileTask(sessionID, {
completedCount: index + 1,
detailText: file.fileName,
progress: (index + 1) / context.selectedFiles.length
});
});
SwiftBiu.finishFileTask(sessionID, {
headlineText: "Completed"
});
} catch (error) {
SwiftBiu.failFileTask(sessionID, {
headlineText: "Failed",
detailText: String(error)
});
}
}
Native AI Response Bubble
Use this for OpenAI, Gemini, Doubao, and similar plugins that generate text and let the user preview, regenerate, replace, or append it. These APIs run in background script.js and require the ui permission.
SwiftBiu.showAIResponseBubble(options, onEvent): displays the bubble and returnssessionID.SwiftBiu.updateAIResponseBubble(sessionID, options): updates state, status copy, generated text, and button availability.SwiftBiu.failAIResponseBubble(sessionID, message): moves the bubble into a failed state.SwiftBiu.closeAIResponseBubble(sessionID): closes the session.
Common Events
configChanged: the user changedmode,systemPrompt,userPrompt, or editor visibility.submit: the user confirmed the result. The event containstext,mode,systemPrompt, anduserPrompt.regenerate: the user requested a new generation.previewPoster/sharePoster: poster preview and sharing.
Recommended Workflow
- Call
showAIResponseBubble(...)with only the fields the plugin needs, usuallytitle,mode, andonEvent. - Use
SwiftBiu.fetch(...)for one-shot requests and update the bubble once. - Use
SwiftBiu.fetchStream(...)for real streaming, parse SSE or chunks, and write the cumulative full text throughupdateAIResponseBubble(...). - Persist changes from
configChangedwithSwiftBiu.setConfig(...). - Cancel the previous stream with
cancelFetchStream(...)before regenerating. - On
submit, let the background script choose replace or append and apply the text withpasteText(...).
Defaults
- Omit
systemPromptwhen the native layer should resolve it from configuration. Current fallback:responseSystemPrompt→ manifest default. - Omit
promptVisibleanduserPromptVisiblewhen both editors should start hidden. - Omit
submitLabel,replaceLabel, andappendLabelto use native localization. - Pass
stateorstatusonly for custom transitions or wording.
function performAction(context) {
let streamID = null;
let output = "";
const sessionID = SwiftBiu.showAIResponseBubble({
title: "AI Assistant",
mode: "replace"
}, function (event) {
if (event.type === "regenerate" && streamID) {
SwiftBiu.cancelFetchStream(streamID);
startRequest();
}
if (event.type === "submit") {
SwiftBiu.pasteText(event.text || output);
SwiftBiu.closeAIResponseBubble(sessionID);
}
});
function startRequest() {
output = "";
streamID = SwiftBiu.fetchStream(
"https://example.com/stream",
{ method: "POST" },
function (event) {
// Parse event and append to output.
SwiftBiu.updateAIResponseBubble(sessionID, {
text: output,
state: "streaming"
});
},
function (error) {
SwiftBiu.failAIResponseBubble(sessionID, String(error));
}
);
}
startRequest();
}
Choosing a Native Interface
| Scenario | Recommended interface |
|---|---|
| Batch modification of local files | File task panel |
| Streaming text that requires confirmation | AI response bubble |
| One short success message | System notification |
| Image preview or regeneration | Interactive image session |
| Complex form or complete application UI | Web App UI |