新增 Expo 与 Tauri 原生宿主壳

新增 HostBridge 原生宿主契约和 H5 native_app transport

新增 Expo React Native 移动壳并收紧 WebView 外链边界

新增 Tauri 桌面壳并用 capability 收口受控命令

更新宿主壳方案、文档索引和共享记忆
This commit is contained in:
2026-06-17 21:39:34 +08:00
parent f92e791464
commit 9b7da18879
35 changed files with 16229 additions and 308 deletions

View File

@@ -0,0 +1,106 @@
export const HOST_BRIDGE_PROTOCOL = 'GenarrativeHostBridge';
export const HOST_BRIDGE_VERSION = 1;
export type HostShellKind = 'browser' | 'wechat_mini_program' | 'native_app';
export type NativeHostShell = 'expo_mobile' | 'tauri_desktop';
export type NativeHostPlatform =
| 'ios'
| 'android'
| 'macos'
| 'windows'
| 'linux'
| 'unknown';
export type HostBridgeMethod =
| 'host.getRuntime'
| 'auth.requestLogin'
| 'payment.request'
| 'share.setTarget'
| 'share.open'
| 'navigation.openNativePage'
| 'app.openExternalUrl'
| 'clipboard.writeText'
| 'haptics.impact';
export type HostBridgeCapability =
| HostBridgeMethod
| 'host.events'
| 'navigation.canGoBack';
export type HostBridgeRuntimeResult = {
shell: NativeHostShell;
platform: NativeHostPlatform;
hostVersion: string | null;
bridgeVersion: number;
capabilities: HostBridgeCapability[];
};
export type HostBridgeRequest<Payload = unknown> = {
bridge: typeof HOST_BRIDGE_PROTOCOL;
version: typeof HOST_BRIDGE_VERSION;
id: string;
method: HostBridgeMethod;
payload?: Payload;
timeoutMs?: number;
};
export type HostBridgeError = {
code:
| 'invalid_request'
| 'unsupported_method'
| 'unsupported_capability'
| 'timeout'
| 'cancelled'
| 'host_error';
message: string;
};
export type HostBridgeResponse<Result = unknown> = {
bridge: typeof HOST_BRIDGE_PROTOCOL;
version: typeof HOST_BRIDGE_VERSION;
id: string;
} & (
| {
ok: true;
result?: Result;
}
| {
ok: false;
error: HostBridgeError;
}
);
export type HostBridgeEvent<Payload = unknown> = {
bridge: typeof HOST_BRIDGE_PROTOCOL;
version: typeof HOST_BRIDGE_VERSION;
event: string;
payload?: Payload;
};
export type NavigateNativePagePayload = {
url: string;
};
export type OpenExternalUrlPayload = {
url: string;
};
export type ClipboardWriteTextPayload = {
text: string;
};
export type HapticsImpactPayload = {
style?: 'light' | 'medium' | 'heavy';
};
export type ShareSetTargetPayload = {
target: unknown;
};
export type ShareOpenPayload = {
title?: string;
message?: string;
url?: string;
};