Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/crates/assembly/core/src/service/filesystem/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub async fn workspace_file_upload(
request.remote_connection_id.as_deref(),
)
.await?;
if request.action == "begin" && is_runtime_attachment_uri(&request.path) {
ensure_runtime_attachment_parent(&target).await?;
}
let scope = TransferScope {
account_id,
target_id,
Expand Down Expand Up @@ -118,6 +121,49 @@ pub async fn workspace_file_upload(
result.map_err(|error| error.to_string())
}

/// Top-level runtime directory that holds controller-supplied attachments.
const RUNTIME_ATTACHMENTS_DIR: &str = "attachments";

/// Whether `path` names a file below `openbitfun://runtime/<workspace>/attachments/`.
///
/// A controller that does not share this host's filesystem (Peer Device Mode)
/// stages its local files there; agent tools resolve the same URI on this host.
fn is_runtime_attachment_uri(path: &str) -> bool {
use crate::agentic::tools::workspace_paths::{
is_openbitfun_runtime_uri, parse_openbitfun_runtime_uri,
};
if !is_openbitfun_runtime_uri(path) {
return false;
}
parse_openbitfun_runtime_uri(path).is_ok_and(|parsed| {
let mut segments = parsed.relative_path.split('/');
segments.next() == Some(RUNTIME_ATTACHMENTS_DIR) && segments.count() >= 2
})
}

/// Create the runtime-owned parent of an attachment upload.
///
/// Workspace uploads deliberately require an existing parent. Attachment
/// directories are unique per upload and owned by this runtime, so they are
/// created here, confined to the resolved runtime root.
async fn ensure_runtime_attachment_parent(
target: &openbitfun_services_integrations::remote_connect::file_projection::SessionFileTarget,
) -> Result<(), String> {
if target.remote {
return Err("Runtime attachments must resolve to the executing host".into());
}
let root = std::path::Path::new(&target.root);
let parent = std::path::Path::new(&target.path)
.parent()
.ok_or("Upload destination has no parent")?;
if !parent.starts_with(root) || parent == root {
return Err("Runtime attachment is outside its runtime root".into());
}
tokio::fs::create_dir_all(parent)
.await
.map_err(|error| format!("Failed to create runtime attachment directory: {error}"))
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -135,6 +181,25 @@ mod tests {
assert!(error.contains("workspace identity is required"), "{error}");
}

#[test]
fn runtime_attachment_uri_requires_an_attachments_file() {
assert!(is_runtime_attachment_uri(
"openbitfun://runtime/ws-1/attachments/abc/report.pdf"
));
assert!(!is_runtime_attachment_uri(
"openbitfun://runtime/ws-1/attachments/report.pdf"
));
assert!(!is_runtime_attachment_uri(
"openbitfun://runtime/ws-1/plans/abc/plan.md"
));
assert!(!is_runtime_attachment_uri(
"openbitfun://runtime/ws-1/attachments/../plans/x.md"
));
assert!(!is_runtime_attachment_uri(
"/tmp/attachments/abc/report.pdf"
));
}

#[tokio::test]
async fn upload_stays_bound_to_explicit_local_workspace() {
let directory = tempfile::tempdir().unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"schemaVersion": 1,
"digest": "fnv1a64:f622fe54e98d2ae1",
"digest": "fnv1a64:416c934dda520065",
"retiredCommandPrefixes": [
{
"prefix": "lsp_",
Expand All @@ -16,6 +16,7 @@
"dialog_queue_v1",
"idempotent_dialog_submit",
"inline_image_attachments_v1",
"runtime_attachment_upload_v1",
"btw_initial_model_selection_v1",
"btw_model_pool_selection_v1",
"control_conversation_v1",
Expand Down Expand Up @@ -64,6 +65,7 @@
"dialog_queue_v1",
"idempotent_dialog_submit",
"inline_image_attachments_v1",
"runtime_attachment_upload_v1",
"btw_initial_model_selection_v1",
"btw_model_pool_selection_v1",
"control_conversation_v1",
Expand Down Expand Up @@ -112,6 +114,7 @@
"control_conversation_reset_v1",
"idempotent_dialog_submit",
"inline_image_attachments_v1",
"runtime_attachment_upload_v1",
"btw_initial_model_selection_v1",
"btw_model_pool_selection_v1",
"targeted_session_rollback",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub enum PeerHostCapability {
IdempotentDialogSubmit,
/// Inline imageContexts are durably prepared by the receiving Runtime.
InlineImageAttachmentsV1,
/// `workspace_file_upload` accepts `openbitfun://runtime/<workspace>/attachments/...`
/// targets and creates their runtime-owned parents, so a controller can
/// attach its own local files to a session executing on this host.
RuntimeAttachmentUploadV1,
/// `btw_ask_stream` applies initial model and reasoning selection before the first turn.
BtwInitialModelSelectionV1,
/// BTW accepts typed initial model/pool choices and retains inherited bindings.
Expand Down Expand Up @@ -129,6 +133,7 @@ impl PeerHostCapability {
Self::DialogQueueV1,
Self::IdempotentDialogSubmit,
Self::InlineImageAttachmentsV1,
Self::RuntimeAttachmentUploadV1,
Self::BtwInitialModelSelectionV1,
Self::BtwModelPoolSelectionV1,
Self::ControlConversationV1,
Expand Down Expand Up @@ -180,6 +185,7 @@ impl PeerHostCapability {
Self::DialogQueueV1 => "dialog_queue_v1",
Self::IdempotentDialogSubmit => "idempotent_dialog_submit",
Self::InlineImageAttachmentsV1 => "inline_image_attachments_v1",
Self::RuntimeAttachmentUploadV1 => "runtime_attachment_upload_v1",
Self::ControlConversationV1 => "control_conversation_v1",
Self::ControlConversationResetV1 => "control_conversation_reset_v1",
Self::BtwInitialModelSelectionV1 => "btw_initial_model_selection_v1",
Expand Down Expand Up @@ -238,6 +244,7 @@ const DESKTOP_CAPABILITIES: &[PeerHostCapability] = &[
PeerHostCapability::DialogQueueV1,
PeerHostCapability::IdempotentDialogSubmit,
PeerHostCapability::InlineImageAttachmentsV1,
PeerHostCapability::RuntimeAttachmentUploadV1,
PeerHostCapability::BtwInitialModelSelectionV1,
PeerHostCapability::BtwModelPoolSelectionV1,
PeerHostCapability::ControlConversationV1,
Expand Down Expand Up @@ -289,6 +296,7 @@ const CLI_CAPABILITIES: &[PeerHostCapability] = &[
PeerHostCapability::ControlConversationResetV1,
PeerHostCapability::IdempotentDialogSubmit,
PeerHostCapability::InlineImageAttachmentsV1,
PeerHostCapability::RuntimeAttachmentUploadV1,
PeerHostCapability::BtwInitialModelSelectionV1,
PeerHostCapability::BtwModelPoolSelectionV1,
PeerHostCapability::TargetedSessionRollback,
Expand Down
20 changes: 18 additions & 2 deletions src/web-ui/src/app/components/panels/FilesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
pasteClipboardFilesToWorkspaceDirectory,
resolvePasteTargetDirectory,
type TransferProgressState,
type WorkspaceTransferResult,
} from '@/tools/file-system/services/workspaceFileTransfer';
import { useWorkspaceFileDrop } from '@/tools/file-system/hooks/useWorkspaceFileDrop';
import { useShortcut } from '@/infrastructure/hooks/useShortcut';
Expand Down Expand Up @@ -909,13 +910,28 @@ const FilesPanel: React.FC<FilesPanelProps> = ({
setFileDropHighlight(overPanel);
}, []);

const handleFileDropComplete = useCallback((targetDirectory: string) => {
const handleFileDropComplete = useCallback((
targetDirectory: string,
_transferId: string,
result: WorkspaceTransferResult,
) => {
setFileDropHighlight(false);
void loadFileTree(workspacePath || '', true);
if (workspacePath && !pathsEquivalentFs(targetDirectory, workspacePath)) {
expandFolder(targetDirectory, true);
}
}, [workspacePath, loadFileTree, expandFolder]);
// Items that were refused or failed must not disappear silently.
if (result.failedFiles.length > 0) {
const failedNames = result.failedFiles.map((entry) => {
const name = entry.path.split(/[/\\]/).pop() || entry.path;
return `${name}: ${entry.error}`;
}).join('\n');
notification.error(
t('notifications.pasteFailed', { count: result.failedFiles.length }) + `:\n${failedNames}`,
{ duration: 5000 },
);
}
}, [workspacePath, loadFileTree, expandFolder, notification, t]);

const handleFileDropError = useCallback((
error: unknown,
Expand Down
11 changes: 11 additions & 0 deletions src/web-ui/src/app/scenes/miniapps/views/MiniAppGalleryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { useCurrentWorkspace } from '@/infrastructure/contexts/WorkspaceContext'
import { useMiniAppStore } from '../miniAppStore';
import { useMiniAppCreation } from '../hooks/useMiniAppCreation';
import { useI18n } from '@/infrastructure/i18n';
import { isPeerDeviceModeActive } from '@/infrastructure/peer-device/peerModeFlag';
import { useGallerySceneAutoRefresh } from '@/app/hooks/useGallerySceneAutoRefresh';
import { useNotification } from '@/shared/notification-system';
import { getAppearanceOverlayHost } from '@/infrastructure/appearance/runtime/AppearanceOverlayHost';
Expand Down Expand Up @@ -274,6 +275,12 @@ const MiniAppGalleryView: React.FC<MiniAppGalleryViewProps> = ({ tabs }) => {

const preparePackageImport = useCallback(async (path: string) => {
if (!path.toLowerCase().endsWith('.bfminiapp')) return;
// The package path belongs to this controller; a rendered peer would
// resolve it against its own filesystem.
if (isPeerDeviceModeActive()) {
notification.warning(t('market.import.peerUnsupported'));
return;
}
try {
const inspection = await miniAppMarketAPI.inspectPackage(path);
setPendingPackage({ path, inspection });
Expand All @@ -284,6 +291,10 @@ const MiniAppGalleryView: React.FC<MiniAppGalleryViewProps> = ({ tabs }) => {
}, [notification, t]);

const handleAddPackage = async () => {
if (isPeerDeviceModeActive()) {
notification.warning(t('market.import.peerUnsupported'));
return;
}
const selected = await open({
directory: false,
multiple: false,
Expand Down
11 changes: 11 additions & 0 deletions src/web-ui/src/app/scenes/miniapps/views/MiniAppLibraryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { systemAPI } from '@/infrastructure/api/service-api/SystemAPI';
import { getAppearanceOverlayHost } from '@/infrastructure/appearance/runtime/AppearanceOverlayHost';
import { useCurrentWorkspace } from '@/infrastructure/contexts/WorkspaceContext';
import { useI18n } from '@/infrastructure/i18n';
import { isPeerDeviceModeActive } from '@/infrastructure/peer-device/peerModeFlag';
import { useAccountIdentity } from '@/infrastructure/account-identity';
import { useNotification } from '@/shared/notification-system';
import { isRemoteWorkspace } from '@/shared/types';
Expand Down Expand Up @@ -429,6 +430,12 @@ const MiniAppLibraryContent: React.FC<MiniAppLibraryViewProps> = ({

const preparePackageImport = useCallback(async (path: string) => {
if (!path.toLowerCase().endsWith('.bfminiapp')) return;
// The package path belongs to this controller; a rendered peer would
// resolve it against its own filesystem.
if (isPeerDeviceModeActive()) {
notification.warning(t('market.import.peerUnsupported'));
return;
}
try {
const inspection = await miniAppMarketAPI.inspectPackage(path);
setPendingPackage({ path, inspection });
Expand All @@ -439,6 +446,10 @@ const MiniAppLibraryContent: React.FC<MiniAppLibraryViewProps> = ({
}, [notification, t]);

const handleAddPackage = async () => {
if (isPeerDeviceModeActive()) {
notification.warning(t('market.import.peerUnsupported'));
return;
}
const selected = await open({
directory: false,
multiple: false,
Expand Down
Loading
Loading