/** * 加速度数据变化事件。 * * @public */ export declare interface AccelerometerChangeEvent { /** X 轴加速度,单位 m/s²。 */ x: number; /** Y 轴加速度,单位 m/s²。 */ y: number; /** Z 轴加速度,单位 m/s²。 */ z: number; /** 数据采集时间戳,单位纳秒。 */ timestamp: number; } /** * 加速度数据变化事件监听函数。 * * @public */ export declare type AccelerometerChangeListener = (event: AccelerometerChangeEvent) => void; /** * {@link FileSystemManager.access} 的参数。 * * @public */ export declare interface AccessParams { /** * 要判断是否存在的文件或目录路径。 */ path: string; } /** * 用户动作指令类型。 * * @public */ export declare enum ActionDirectiveType { /** 按钮点击 */ BUTTON_CLICK = "button_click", /** 选择(下拉列表场景) */ OPTION_SELECT = "option_select", /** 表单提交(复杂的信息提交场景) */ FORM_SUBMIT = "form_submit" } /** * 向系统日历添加事件。 * * @example * ```typescript * import { addPhoneCalendar } from '@doubao-apps/framework/api'; * * const startTime = Math.floor(Date.now() / 1000) + 3600; * * await addPhoneCalendar({ * title: '项目评审', * startTime, * endTime: startTime + 1800, * alarm: true, * alarmOffset: 300 * }); * ``` * * @public */ export declare const addPhoneCalendar: (params: AddPhoneCalendarParams) => Promise; /** * 添加系统日历事件的请求参数。 * * @public */ export declare interface AddPhoneCalendarParams { /** 日历事件标题。 */ title: string; /** 开始时间的 Unix 秒级时间戳。 */ startTime: number; /** 是否为全天事件。 */ allDay?: boolean; /** 事件描述。 */ description?: string; /** 事件位置。 */ location?: string; /** 结束时间的 Unix 秒级时间戳。 */ endTime?: number; /** 是否提醒。 */ alarm?: boolean; /** 提前提醒时间,单位秒。 */ alarmOffset?: number; } /** * 添加手机联系人。 * * @example * ```typescript * import { addPhoneContact } from '@doubao-apps/framework/api'; * * await addPhoneContact({ * firstName: 'Tom', * mobilePhoneNumber: '13800000000', * organization: 'Doubao' * }); * ``` * * @public */ export declare const addPhoneContact: (params: AddPhoneContactParams) => Promise; /** * 添加手机联系人的请求参数。 * * @public */ export declare interface AddPhoneContactParams { /** 名字。 */ firstName: string; /** 头像文件路径。 */ photoFilePath?: string; /** 昵称。 */ nickName?: string; /** 中间名。 */ middleName?: string; /** 姓。 */ lastName?: string; /** 备注。 */ remark?: string; /** 手机号。 */ mobilePhoneNumber?: string; /** 微信号。 */ weChatNumber?: string; /** 家庭地址国家。 */ addressCountry?: string; /** 家庭地址省份。 */ addressState?: string; /** 家庭地址城市。 */ addressCity?: string; /** 家庭地址街道。 */ addressStreet?: string; /** 家庭地址邮编。 */ addressPostalCode?: string; /** 公司。 */ organization?: string; /** 职位。 */ title?: string; /** 工作传真。 */ workFaxNumber?: string; /** 工作电话。 */ workPhoneNumber?: string; /** 公司电话。 */ hostNumber?: string; /** 电子邮件。 */ email?: string; /** 个人网站。 */ url?: string; /** 工作地址国家。 */ workAddressCountry?: string; /** 工作地址省份。 */ workAddressState?: string; /** 工作地址城市。 */ workAddressCity?: string; /** 工作地址街道。 */ workAddressStreet?: string; /** 工作地址邮编。 */ workAddressPostalCode?: string; /** 家庭传真。 */ homeFaxNumber?: string; /** 家庭电话。 */ homePhoneNumber?: string; /** 家庭地址国家。 */ homeAddressCountry?: string; /** 家庭地址省份。 */ homeAddressState?: string; /** 家庭地址城市。 */ homeAddressCity?: string; /** 家庭地址街道。 */ homeAddressStreet?: string; /** 家庭地址邮编。 */ homeAddressPostalCode?: string; } /** * 向系统日历添加重复事件。 * * @example * ```typescript * import { addPhoneRepeatCalendar } from '@doubao-apps/framework/api'; * * const startTime = Math.floor(Date.now() / 1000) + 3600; * * await addPhoneRepeatCalendar({ * title: '每周例会', * startTime, * endTime: startTime + 1800, * repeatInterval: 'week' * }); * ``` * * @public */ export declare const addPhoneRepeatCalendar: (params: AddPhoneRepeatCalendarParams) => Promise; /** * 添加重复日历事件的请求参数。 * * @public */ export declare interface AddPhoneRepeatCalendarParams extends AddPhoneCalendarParams { /** 重复周期。 */ repeatInterval?: CalendarRepeatInterval; /** 重复结束时间的 Unix 秒级时间戳。 */ repeatEndTime?: number; } /** @public */ export declare interface AppBaseInfoHost { /** 宿主 app 对应的 appId */ appId: string; } /** * {@link FileSystemManager.appendFile} 的参数。 * * @remarks * - 如果文件不存在会自动创建。 * - 与 {@link WriteFileParams} 不同,追加写入不会覆盖文件已有内容,而是在末尾追加。 * * @public */ export declare interface AppendFileParams { /** * 要追加内容的文件路径(本地路径)。 */ filePath: string; /** * 要追加的内容。 * * - 当 `encoding` 为 `'utf-8'` 时,直接追加该字符串; * - 当 `encoding` 为 `'base64'` 时,将该字符串先进行 Base64 解码再追加到文件末尾。 */ data: string; /** * 指定写入文件的字符编码。 * * @default 'utf-8' */ encoding?: 'utf-8' | 'base64'; } /** * 应用主题。 * * @public */ export declare type AppTheme = 'light' | 'dark'; /** * 初始化授权 * * @param params - 授权参数 * @param params.scope - 授权范围 * @returns Promise 对象,授权成功时会返回授权结果 * @remarks * 按 scope 申请授权。 * @example * ```typescript * import { authorize } from '@doubao-apps/framework/api'; * * await authorize({ scope: 'scope.userLocation' }); * ``` * * @public */ export declare const authorize: (params: AuthorizeRequest) => Promise; /** @public */ export declare interface AuthorizeRequest { /** 授权范围 */ scope: Scope; } /** @public */ export declare type AuthSetting = Record; /** * 背景音频错误信息。 * * @public */ export declare interface BackgroundAudioError { errCode?: number; errMsg: string; } /** * 全局唯一背景音频管理器。 * * @public */ export declare interface BackgroundAudioManager { src: string; title: string; epname: string; singer: string; coverImgUrl: string; webUrl: string; startTime: number; readonly currentTime: number; readonly duration: number; readonly paused: boolean; readonly buffered: number; playbackRate: number; play(): void; pause(): void; stop(): void; seek(position: number): void; onCanplay(callback: BackgroundAudioManagerEventCallback): void; offCanplay(callback?: BackgroundAudioManagerEventCallback): void; onPlay(callback: BackgroundAudioManagerEventCallback): void; offPlay(callback?: BackgroundAudioManagerEventCallback): void; onPause(callback: BackgroundAudioManagerEventCallback): void; offPause(callback?: BackgroundAudioManagerEventCallback): void; onStop(callback: BackgroundAudioManagerEventCallback): void; offStop(callback?: BackgroundAudioManagerEventCallback): void; onEnded(callback: BackgroundAudioManagerEventCallback): void; offEnded(callback?: BackgroundAudioManagerEventCallback): void; onTimeUpdate(callback: BackgroundAudioManagerEventCallback): void; offTimeUpdate(callback?: BackgroundAudioManagerEventCallback): void; onError(callback: BackgroundAudioManagerErrorCallback): void; offError(callback?: BackgroundAudioManagerErrorCallback): void; onWaiting(callback: BackgroundAudioManagerEventCallback): void; offWaiting(callback?: BackgroundAudioManagerEventCallback): void; onSeeking(callback: BackgroundAudioManagerEventCallback): void; offSeeking(callback?: BackgroundAudioManagerEventCallback): void; onSeeked(callback: BackgroundAudioManagerEventCallback): void; offSeeked(callback?: BackgroundAudioManagerEventCallback): void; onPrev(callback: BackgroundAudioManagerEventCallback): void; offPrev(callback?: BackgroundAudioManagerEventCallback): void; onNext(callback: BackgroundAudioManagerEventCallback): void; offNext(callback?: BackgroundAudioManagerEventCallback): void; } /** * 背景音频错误事件回调。 * * @public */ export declare type BackgroundAudioManagerErrorCallback = (error: BackgroundAudioError) => void; /** * 背景音频普通事件回调。 * * @public */ export declare type BackgroundAudioManagerEventCallback = () => void; /** * 背景音频状态。 * * @public */ export declare interface BackgroundAudioState { src?: string; title?: string; epname?: string; singer?: string; coverImgUrl?: string; webUrl?: string; startTime?: number; currentTime?: number; duration?: number; paused?: boolean; buffered?: number; playbackRate?: number; } /** * 电池信息变化事件。 * * @public */ export declare interface BatteryInfoChangeEvent { /** 是否处于省电模式。 */ isLowPowerModeEnabled: boolean; } /** * 电池信息变化事件监听函数。 * * @public */ export declare type BatteryInfoChangeListener = (event: BatteryInfoChangeEvent) => void; /** * iBeacon 设备信息。 * * @public */ export declare interface BeaconInfo { /** Beacon UUID。 */ uuid: string; /** 主 ID。 */ major: number; /** 次 ID。 */ minor: number; /** 距离等级。 */ proximity: BeaconProximity; /** 距离,单位米。 */ accuracy: number; /** RSSI 信号强度,单位 dBm。 */ rssi: number; } /** * iBeacon 距离等级。 * * @public */ export declare type BeaconProximity = 0 | 1 | 2 | 3; /** * BLE 特征值变化事件。 * * @public */ export declare interface BLECharacteristicValueChangeEvent { /** 蓝牙设备 ID。 */ deviceId: string; /** 服务 ID。 */ serviceId: string; /** 特征值 ID。 */ characteristicId: string; /** 特征值最新的二进制值。 */ value?: ArrayBuffer; } /** @public */ export declare type BLECharacteristicValueChangeListener = (event: BLECharacteristicValueChangeEvent) => void; /** * BLE 连接状态变化事件。 * * @public */ export declare interface BLEConnectionStateChangeEvent { /** 蓝牙设备 ID。 */ deviceId: string; /** 是否已连接。 */ connected: boolean; } /** @public */ export declare type BLEConnectionStateChangeListener = (event: BLEConnectionStateChangeEvent) => void; /** * 蓝牙适配器状态变化事件。 * * @public */ export declare type BluetoothAdapterStateChangeEvent = GetBluetoothAdapterStateResult; /** @public */ export declare type BluetoothAdapterStateChangeListener = (event: BluetoothAdapterStateChangeEvent) => void; /** * 蓝牙广播二进制字段。 * * @public */ export declare type BluetoothBinaryField = Record; /** * 蓝牙特征值信息。 * * @public */ export declare interface BluetoothCharacteristic { /** 特征值 UUID。 */ uuid: string; /** 特征值能力。 */ properties: BluetoothCharacteristicProperties; } /** * 蓝牙特征值支持的能力。 * * @public */ export declare interface BluetoothCharacteristicProperties { /** 是否支持 indicate。 */ indicate: boolean; /** 是否支持 notify。 */ notify: boolean; /** 是否支持 read。 */ read: boolean; /** 是否支持 write。 */ write: boolean; /** 是否支持无响应写入。 */ writeNoResponse: boolean; /** 是否支持带响应写入。 */ writeDefault: boolean; } /** * 蓝牙设备信息。 * * @public */ export declare interface BluetoothDevice { /** 设备 ID。 */ deviceId: string; /** 设备名称。 */ name: string; /** 广播中的本地名称。 */ localName?: string; /** RSSI 信号强度,单位 dBm。 */ RSSI: number; /** 广播二进制数据。 */ advertisData?: ArrayBuffer; /** 广播中的服务 UUID 列表。 */ advertisServiceUUIDs?: string[]; /** 广播中的服务数据。 */ serviceData?: BluetoothBinaryField; /** 是否可连接。 */ connectable?: boolean; } /** * 蓝牙设备发现事件中的设备信息。 * * @public */ export declare interface BluetoothDeviceFoundDevice { /** 设备 ID。 */ deviceId: string; /** 设备名称。 */ name: string; /** 广播中的本地名称。 */ localName?: string; /** RSSI 信号强度,单位 dBm。 */ RSSI: number; /** 广播二进制数据。 */ advertisData?: ArrayBuffer; /** 广播中的服务 UUID 列表。 */ advertisServiceUUIDs?: string[]; /** 广播中的服务数据。 */ serviceData?: BluetoothBinaryField; /** 是否可连接。 */ connectable?: boolean; } /** * 蓝牙设备发现事件。 * * @public */ export declare interface BluetoothDeviceFoundEvent { /** 本次扫描上报的新发现设备列表。 */ devices: BluetoothDeviceFoundDevice[]; } /** @public */ export declare type BluetoothDeviceFoundListener = (event: BluetoothDeviceFoundEvent) => void; /** * 蓝牙特征值订阅类型。 * * @public */ export declare type BluetoothNotifyType = 'notification' | 'indication'; /** * 蓝牙扫描功耗等级。 * * @public */ export declare type BluetoothPowerLevel = 'low' | 'medium' | 'high'; /** * 蓝牙服务信息。 * * @public */ export declare interface BluetoothService { /** 服务 UUID。 */ uuid: string; /** 是否为主服务。 */ isPrimary: boolean; } /** * 蓝牙写入模式。 * * @public */ export declare type BluetoothWriteType = 'write' | 'writeNoResponse'; /** * 底部弹窗行为配置。 * * @public */ export declare interface BottomSheetBehavior { /** 是否允许点击蒙层关闭弹窗,默认 `true`。 */ dismissOnMaskTap?: boolean; } /** * 底部弹窗按钮配置。 * * @public */ export declare interface BottomSheetButton { /** 按钮语义。 */ role: BottomSheetButtonRole; /** 按钮展示文案。 */ text: string; } /** * 底部弹窗点击按钮的返回结果。 * * @public */ export declare interface BottomSheetButtonClickResult { /** 弹窗结束动作。 */ action: 'buttonClick'; /** 被点击按钮的语义。 */ role: BottomSheetButtonRole; } /** * 底部弹窗按钮语义。 * * @public */ export declare type BottomSheetButtonRole = 'agreeMain' | 'agreeSub' | 'reject'; /** * 底部弹窗按钮配置,支持 1-3 个按钮。 * * @public */ export declare type BottomSheetButtons = [BottomSheetButton] | [BottomSheetButton, BottomSheetButton] | [BottomSheetButton, BottomSheetButton, BottomSheetButton]; /** * 底部弹窗取消关闭的返回结果。 * * @public */ export declare interface BottomSheetCancelResult { /** 弹窗结束动作。 */ action: 'cancel'; /** 取消来源。 */ source: BottomSheetCancelSource; } /** * 底部弹窗取消来源。 * * @public */ export declare type BottomSheetCancelSource = 'mask' | 'gesture' | 'hostUnavailable' | 'unknown'; /** * 日历重复周期。 * * @public */ export declare type CalendarRepeatInterval = 'day' | 'week' | 'month' | 'year'; /** * 检测当前宿主是否支持指定 API 或能力。 * * @remarks * 用于兼容性判断。 * @example * ```typescript * import { canIUse } from '@doubao-apps/framework/api'; * * const { result } = await canIUse({ schema: 'doubao.getLocation' }); * * console.log(result); * ``` * * @public */ export declare const canIUse: (params: CanIUseParams) => Promise; /** @public */ export declare interface CanIUseParams { schema: string; } /** @public */ export declare interface CanIUseResult { result: boolean; } /** * 录屏或截屏时的视觉表现。 * * @public */ export declare type CaptureVisualEffect = 'none' | 'hidden'; /** * 检测无障碍能力是否开启。 * * @example * ```typescript * import { checkIsOpenAccessibility } from '@doubao-apps/framework/api'; * * const { open } = await checkIsOpenAccessibility(); * * console.log(open); * ``` * * @public */ export declare const checkIsOpenAccessibility: (params?: {} | undefined) => Promise; /** * 无障碍能力检测结果。 * * @public */ export declare interface CheckIsOpenAccessibilityResult { /** 是否开启视觉无障碍能力。 */ open: boolean; } /** * 选择手机联系人。 * * @example * ```typescript * import { chooseContact } from '@doubao-apps/framework/api'; * * const { displayName, phoneNumber } = await chooseContact(); * * console.log(displayName, phoneNumber); * ``` * * @public */ export declare const chooseContact: (params?: {} | undefined) => Promise; /** * 选取联系人后的返回结果。 * * @public */ export declare interface ChooseContactResult { /** 选中的手机号。 */ phoneNumber: string; /** 联系人名称。 */ displayName: string; /** 联系人所有手机号。 */ phoneNumberList: string[]; } /** * 选择图片。 * * @example * ```typescript * import { chooseImage } from '@doubao-apps/framework/api'; * * const { tempFilePaths } = await chooseImage({ * count: 1, * sourceType: ['album'] * }); * * console.log(tempFilePaths); * ``` * * @public */ export declare const chooseImage: (params?: ChooseImageParams | undefined) => Promise; /** * 选择图片返回的单个文件信息。 * * @public */ export declare interface ChooseImageFile { /** 本地临时文件路径。 */ path: string; /** 文件大小,单位 B。 */ size: number; /** 文件 MIME 类型。 */ type?: string; /** 原始浏览器 File 对象。 */ originalFileObj?: File; } /** * 选择图片的请求参数。 * * @public */ export declare interface ChooseImageParams { /** 最多可选图片张数。 */ count?: number; /** 允许返回的图片尺寸类型。 */ sizeType?: ChooseImageSizeType[]; /** 允许选择的图片来源。 */ sourceType?: ChooseImageSourceType[]; /** H5 场景下可复用的 input 元素 ID。 */ imageId?: string; } /** * 选择图片结果。 * * @public */ export declare interface ChooseImageResult { /** 图片临时文件路径列表。 */ tempFilePaths: string[]; /** 图片临时文件信息列表。 */ tempFiles: ChooseImageFile[]; } /** * 可选的图片尺寸类型。 * * @public */ export declare type ChooseImageSizeType = 'original' | 'compressed'; /** * 可选的图片来源类型。 * * @public */ export declare type ChooseImageSourceType = 'album' | 'camera' | 'user' | 'environment'; /** * 打开地图选择位置。 * * @example * ```typescript * import { chooseLocation } from '@doubao-apps/framework/api'; * * const { name, latitude, longitude } = await chooseLocation(); * * console.log(name, latitude, longitude); * ``` * * @public */ export declare const chooseLocation: (params?: ChooseLocationParams | undefined) => Promise; /** @public */ export declare interface ChooseLocationParams { /** * 目标地纬度 */ latitude?: number; /** * 目标地经度 */ longitude?: number; } /** @public */ export declare interface ChooseLocationResponse { /** * 纬度,GCJ-02 坐标系 */ latitude: number; /** * 经度,GCJ-02 坐标系 */ longitude: number; /** * 位置名称 */ name?: string; /** * 地址详情 */ address?: string; } /** * 选择消息文件返回的单个文件信息。 * * @public */ export declare interface ChooseMessageFile { /** 文件名称。 */ name: string; /** 本地临时文件路径。 */ path: string; /** 文件大小,单位 B。 */ size: number; /** 会话发送时间,Unix 时间戳。 */ time: number; /** 文件类型。 */ type: SelectedMessageFileType; } /** * 选择消息文件的请求参数。 * * @public */ export declare interface ChooseMessageFileParams { /** 最多可选文件个数。 */ count: number; /** 基于文件扩展名的过滤条件,仅在 `type` 为 `file` 时生效。 */ extension?: string[]; /** 允许选择的文件类型。 */ type?: ChooseMessageFileType; } /** * 选择消息文件结果。 * * @public */ export declare interface ChooseMessageFileResult { /** 本地临时文件对象数组。 */ tempFiles: ChooseMessageFile[]; } /** * 选择消息文件的文件类型。 * * @public */ export declare type ChooseMessageFileType = 'all' | 'video' | 'image' | 'file'; /** * 清空本地缓存。 * * @returns 返回一个 Promise,清空完成后 resolve。 * @example * ```typescript * import { clearStorage } from '@doubao-apps/framework/api'; * * await clearStorage(); * ``` * * @public */ export declare const clearStorage: (params?: object | undefined) => Promise; /** * 清空本地缓存。 * * @returns 同步清空完成后返回。 * @example * ```typescript * import { clearStorageSync } from '@doubao-apps/framework/api'; * * clearStorageSync(); * ``` * * @public */ export declare const clearStorageSync: (params?: object | undefined) => object; /** * Unified client event registry signature * @internal */ declare type ClientEventRegistry = (handler: (params: Params) => void) => () => void; /** * 关闭栈顶页面。 * * @returns 返回一个 Promise,在关闭操作成功发起时解析 * @deprecated 使用 {@link navigateBack} 返回上一页。 * @example * ```typescript * import { close } from '@doubao-apps/framework/api'; * * async function closeTopPage() { * try { * await close(); * } catch (e) { * console.error('关闭页面失败', e); * } * } * * closeTopPage(); * ``` * @public */ declare const close_2: (params?: CloseParams | undefined) => Promise; export { close_2 as close } /** * 关闭 BLE 连接。 * * @example * ```typescript * import { closeBLEConnection } from '@doubao-apps/framework/api'; * * await closeBLEConnection({ deviceId: 'device-id' }); * ``` * * @public */ export declare const closeBLEConnection: (params: CloseBLEConnectionParams) => Promise; /** * 关闭 BLE 连接的请求参数。 * * @public */ export declare interface CloseBLEConnectionParams { /** 蓝牙设备 ID。 */ deviceId: string; } /** * 关闭蓝牙适配器。 * * @remarks * 会关闭蓝牙模块。 * @example * ```typescript * import { closeBluetoothAdapter } from '@doubao-apps/framework/api'; * * await closeBluetoothAdapter(); * ``` * * @public */ export declare const closeBluetoothAdapter: (params?: {} | undefined) => Promise; /** @public */ export declare interface CloseParams { /** 指定一个要关闭的页面 */ containerID?: string; } /** * 罗盘数据变化事件。 * * @public */ export declare interface CompassChangeEvent { /** 面对的方向度数,范围 0 到 360。 */ direction: number; } /** * 罗盘数据变化事件监听函数。 * * @public */ export declare type CompassChangeListener = (event: CompassChangeEvent) => void; /** * 压缩图片。 * * @example * ```typescript * import { compressImage } from '@doubao-apps/framework/api'; * * const { tempFilePath } = await compressImage({ * src: '/tmp/image.png', * quality: 80 * }); * * console.log(tempFilePath); * ``` * * @public */ export declare const compressImage: (params: CompressImageParams) => Promise; /** * 压缩图片的请求参数。 * * @public */ export declare interface CompressImageParams { /** 图片路径。 */ src: string; /** 压缩质量,范围 0 - 100,仅对 jpg 生效。 */ quality?: number; /** 压缩后图片宽度,单位 px。 */ compressedWidth?: number; /** 压缩后图片高度,单位 px。 */ compressedHeight?: number; } /** * 压缩图片结果。 * * @public */ export declare interface CompressImageResult { /** 压缩后图片的临时文件路径。 */ tempFilePath: string; } /** * 已连接蓝牙设备信息。 * * @public */ export declare interface ConnectedBluetoothDevice { /** 设备 ID。 */ deviceId: string; /** 设备名称。 */ name: string; } /** * 创建一个 WebSocket 连接,并返回可操作该连接的 {@link SocketTask}。 * * 该 API 会同步返回 `SocketTask`,但连接创建本身是异步过程。调用方应先在返回的 * `SocketTask` 上注册事件回调,再等待 `onOpen` 表示连接可用。后续发送消息使用 * `SocketTask.send`,关闭连接使用 `SocketTask.close`。 * * @summary 创建 WebSocket 连接。 * @param params 创建连接所需参数,字段见 {@link ConnectSocketParams}。 * @returns 当前 WebSocket 连接对应的 {@link SocketTask}。 * * @remarks * - 返回 `SocketTask` 不代表连接已经成功,连接成功以 `onOpen` 为准。 * - `send` 必须接收对象参数,并把要发送的内容放在 `data` 字段中。 * - 如果 `protocols` 非空,需要服务端支持并返回匹配的子协议。 * - 多次调用会创建多条连接,旧连接不会自动关闭;不再使用时应主动调用 `close`。 * - 连接失败、发送失败或关闭失败会通过 `SocketTask.onError` 通知。 * * @example * ```typescript * import { connectSocket } from '@doubao-apps/framework/api'; * * const socketTask = connectSocket({ * url: 'wss://example.com/socket', * header: { authorization: 'Bearer token' }, * protocols: ['chat.v1'] * }); * * socketTask.onOpen(() => { * socketTask.send({ data: 'hello' }); * }); * * socketTask.onMessage((event) => { * console.log(event.data); * }); * * socketTask.onClose((event) => { * console.log(event.code, event.reason); * }); * * socketTask.onError((event) => { * console.error(event.errMsg); * }); * ``` * * @public */ export declare function connectSocket(params: ConnectSocketParams): SocketTask; /** * 创建 WebSocket 连接的参数。 * * `connectSocket` 会把这些参数透传给宿主侧创建连接。连接创建请求发出后, * 调用方会立即拿到一个 {@link SocketTask},后续连接成功、失败、收到消息和关闭状态 * 都通过 `SocketTask` 上注册的事件回调通知。 * * @remarks * - `url` 应填写完整的 WebSocket 地址。线上环境通常要求使用 `wss://` 协议,并由宿主侧按当前应用配置校验合法域名和证书。 * - `header` 用于补充握手请求头,`referer` 等由宿主管控的字段不会被业务代码覆盖。 * - `protocols` 非空时,服务端需要在握手响应中选择并返回匹配的子协议,否则连接可能失败。 * - 同一个页面多次调用会创建多个独立连接,已创建的旧连接不会因为新连接自动关闭。 * * @public */ export declare interface ConnectSocketParams { /** * WebSocket 连接地址。 * * 需要包含协议、域名、路径和可选 query,例如 `wss://example.com/socket?room=1`。 * 如果地址为空或不是字符串,本 API 会返回 `readyState` 为 `undefined` 的 {@link SocketTask}, * 并异步触发 `onError`。 */ url: string; /** * WebSocket 握手阶段携带的 HTTP Header。 * * 适合放置业务自定义 Header,例如鉴权 token、trace id、客户端能力标识等。 * `referer` 由宿主侧统一生成和管理,不应依赖该字段被业务传入值覆盖。 */ header?: Record; /** * WebSocket 子协议数组。 * * 会作为握手请求中的 `Sec-WebSocket-Protocol` 候选值传给服务端。 * 如果传入非空数组,服务端需要选择其中一个协议并在握手响应中返回; * 服务端不支持或不返回匹配协议时,连接可能被宿主判定为创建失败。 */ protocols?: string[]; } /** * 连接指定 Wi-Fi。 * * @remarks * 通常先调用 startWifi。 * @example * ```typescript * import { connectWifi, startWifi } from '@doubao-apps/framework/api'; * * await startWifi(); * await connectWifi({ ssid: 'Office-WiFi', password: 'password' }); * ``` * * @public */ export declare const connectWifi: (params: ConnectWifiParams) => Promise; /** * 连接 Wi-Fi 的请求参数。 * * @public */ export declare interface ConnectWifiParams { /** Wi-Fi SSID。 */ ssid: string; /** Wi-Fi 密码。 */ password: string; /** Wi-Fi BSSID。 */ bssid?: string; /** 是否跳转到系统设置页连接。 */ manual?: boolean; /** 是否仅返回部分 Wi-Fi 信息。 */ partialInfo?: boolean; } /** * 后续消息内容。 * * @public */ export declare type Content = { /** 文本消息。 */ type: 'text'; /** 后续消息的文本内容。 */ text: string; } | { /** API 调用消息。 */ type: 'api/call'; /** 要调用的 API 及其参数。 */ data: { /** API 名称。 */ name: string; /** API 调用参数。 */ arguments: object; }; }; /** * {@link FileSystemManager.copyFile} 的参数。 * * @remarks * - 不支持复制目录,仅支持复制文件。 * - 如果目标路径已存在同名文件,会被覆盖。 * * @public */ export declare interface CopyFileParams { /** * 源文件路径(被复制的文件)。 */ srcPath: string; /** * 目标文件路径(复制后生成的文件)。 */ destPath: string; } /** * 创建 BLE 连接。 * * @remarks * 需要传入 deviceId。 * @example * ```typescript * import { createBLEConnection } from '@doubao-apps/framework/api'; * * await createBLEConnection({ * deviceId: 'device-id', * timeout: 10000 * }); * ``` * * @public */ export declare const createBLEConnection: (params: CreateBLEConnectionParams) => Promise; /** * 创建 BLE 连接的请求参数。 * * @public */ export declare interface CreateBLEConnectionParams { /** 蓝牙设备 ID。 */ deviceId: string; /** 超时时间,单位毫秒。 */ timeout?: number; } /** * A factory to generate a custom event API pair (for both the caller and the callee) * * @param name event name * @param options Extra options when generating the event API * @returns A custom event API pair * @category Custom API * @example * interface TestEventParams { * input: string; * } * * const [emitEvent, onReceiveEvent] = createCustomEvent('testEvent'); * * // For receiver * const unregister = onReceiveEvent((params) => console.log(params)); * * // For sender * function emitEventToOtherView() { * emitEvent({ input: 'test' }); * } */ export declare function createCustomEvent(name: string, options?: CustomEventOptions): [CustomEventCaller, CustomEventHandlerRegistry]; /** * 创建一个内部音频上下文。 * * @remarks * 返回的对象拥有独立的 `audioId`、状态和事件监听;播放状态以 native 事件为准。 * * @public */ export declare function createInnerAudioContext(): InnerAudioContext; /** * 创建三方纯签约流程所需的签约单。 * * @param params - 业务服务端返回的签约订单参数和签名。 * @returns 返回签约单创建结果;创建成功不代表用户已经签约成功。 * @remarks * 这是纯签约流程的第一步。创建成功后,将返回的 `authOrderId` 传给 `sign` 拉起用户签约页面。 * 此流程与支付按钮组件使用的豆包平台免密签约状态不是同一类签约关系。 * * `data` 和 `dbAuthorization` 必须由业务服务端生成,不能在前端自行构造。 * 用户的最终签约状态必须以业务服务端查询签约单详情或收到的签约结果回调为准。 * @example * ```typescript * import { * createSignOrder, * type CreateSignOrderParams * } from '@doubao-apps/framework/api'; * * // 业务方自行实现:从业务服务端获取签约订单参数和签名;该函数不是 SDK API。 * declare function getSignOrderParamsFromBusinessServer(): * Promise; * * const orderParams = await getSignOrderParamsFromBusinessServer(); * const result = await createSignOrder(orderParams); * * console.log(result); * ``` * * @public */ export declare const createSignOrder: (params: CreateSignOrderParams) => Promise; /** @public */ export declare interface CreateSignOrderFailResult { /** 错误码。 */ errNo: string; /** 错误信息。 */ errMsg: string; /** 用于服务端排查问题的错误日志 ID。 */ errLogId?: string; } /** @public */ export declare interface CreateSignOrderParams { /** * 三方纯签约的签约单请求数据。 * * 该字段必须由业务服务端按签约能力的接入协议生成并返回,前端应原样透传。 */ data: string; /** * `data` 对应的请求签名。 * * 该字段必须由业务服务端生成并返回,前端应原样透传。 */ dbAuthorization: string; } /** @public */ export declare type CreateSignOrderResult = CreateSignOrderSuccessResult | CreateSignOrderFailResult; /** @public */ export declare interface CreateSignOrderSuccessResult { /** * 平台返回的签约单号,用于调用 `sign` 拉起签约页面。 * * 该字段不是用户签约成功后产生的签约 ID。 */ authOrderId: string; /** 用于服务端排查问题的日志 ID。 */ logId: string; } /** * 创建任务。 * * @param params - 任务创建参数。 * @returns 返回创建后的任务 ID、远端任务 token 和过期时间。 * @remarks * 创建任务时需要传入开发者侧唯一任务标识、任务模板、任务详情和任务类型。开发者侧唯一任务标识 * 可用于幂等创建和后续业务关联。远端任务创建成功后,返回的 taskId 可用于查询或更新任务。 * * @example * ```typescript * import { createTask } from '@doubao-apps/framework/api'; * * const result = await createTask({ * outTaskId: 'order-20260529-001', * taskTemplate: 'remote_normal_v1', * taskType: 'remote', * taskDetail: { * expire_in_sec: 3600, * display_data: { * title: '订单处理中', * sub_title: '正在为你处理订单,请稍候' * } * } * }); * * console.log(result.taskId, result.token, result.expiresIn); * ``` * * @public */ export declare const createTask: (params: CreateTaskParams) => Promise; /** * 创建任务的请求参数。 * * @public */ export declare interface CreateTaskParams { /** 开发者侧任务唯一标识,用于幂等和关联 */ outTaskId: string; /** 任务样式模板,当前仅支持 remote_normal_v1 */ taskTemplate: TaskTemplate; /** 模板对应的数据,传入对象时会在调用 native 前自动 JSON.stringify */ taskDetail: TaskDetail; /** 任务类型,当前支持 local 和 remote */ taskType: TaskType; } /** * 创建任务的返回结果。 * * @public */ export declare interface CreateTaskResult { /** 任务 ID,后续可以使用这个 ID 更新任务 */ taskId: string; /** 远端任务 token,后续使用 token 通过 OpenAPI 更新远端任务 */ token?: string; /** 任务超时过期时间 */ expiresIn?: number; } /** * The caller part of an event API pair * * Used to send an event registered at foreign entity. */ export declare type CustomEventCaller = (params: Params) => void; /** * The callee part of an event API pair * * Used to register custom event handler. */ export declare type CustomEventHandlerRegistry = (handler: (params: Params) => void) => () => void; /** * Extra options for custom event factory */ export declare interface CustomEventOptions { /** * Applied after the target runtime receives the event message and before passing it to the handler. Will skip the * event silently when type guard failed. */ paramsTypeGuard?: TypeGuard; } /** * 设备方向变化事件。 * * @public */ export declare interface DeviceMotionChangeEvent { /** * 当手机坐标 X/Y 和地球坐标 X/Y 重合时,绕 Z 轴转动的夹角。 * 范围为 [0, 2π),逆时针转动为正。 */ alpha: number; /** * 当手机坐标 Y/Z 和地球坐标 Y/Z 重合时,绕 X 轴转动的夹角。 * 范围为 [-π, π)。 */ beta: number; /** * 当手机坐标 X/Z 和地球坐标 X/Z 重合时,绕 Y 轴转动的夹角。 * 范围为 [-π/2, π/2)。 */ gamma: number; } /** * 设备方向变化事件监听函数。 * * @public */ export declare type DeviceMotionChangeListener = (event: DeviceMotionChangeEvent) => void; /** @public */ export declare type DeviceOrientation = 'portrait' | 'landscape'; /** * 关闭页面返回前提醒。 * * @example * ```typescript * import { disableAlertBeforeUnload } from '@doubao-apps/framework/api'; * * await disableAlertBeforeUnload(); * ``` * * @public */ export declare const disableAlertBeforeUnload: (params?: Record | undefined) => Promise; /** * 禁止用户录屏。 * * @example * ```typescript * import { disableUserScreenRecord } from '@doubao-apps/framework/api'; * * await disableUserScreenRecord(); * ``` * * @public */ export declare const disableUserScreenRecord: (params?: {} | undefined) => Promise; /** * 描述用户行为,约束模型行为并指定后续执行路径。 * * @param params - 动作描述、预期行为及工具调用约束参数。 * @returns 返回一个 Promise,在动作指令成功下发时解析。 * @remarks * 适用于卡片交互后向模型补充结构化动作上下文,例如按钮点击、选项选择或表单提交。 * `getWidgetInstanceId` 仅在卡片环境中有效,在小程序页面中会返回 `undefined`。如果需要在页面中调用, * 请在 `navigateTo` 时通过参数传递卡片实例 ID。 * * @example * ```typescript * import { ActionDirectiveType, dispatchActionDirective } from '@doubao-apps/framework/api'; * import { getWidgetInstanceId } from '@doubao-apps/framework'; * * await dispatchActionDirective({ * widgetInstanceId: getWidgetInstanceId(), * actionType: ActionDirectiveType.BUTTON_CLICK, * actionDescribe: '用户点击支付按钮并完成话费支付', * expectedAction: '调用话费账单查询工具,基于工具返回回复用户' * }); * ``` * * @public */ export declare const dispatchActionDirective: (params: DispatchActionDirectiveParams) => Promise; /** * 下发动作指令的请求参数。 * * @public */ export declare interface DispatchActionDirectiveParams { /** * 会话消息关联的卡片实例 ID。 * * 在卡片环境可通过 `getWidgetInstanceId` 获取;在小程序页面等非卡片环境需要通过传参或通信传递。 */ widgetInstanceId: string; /** 动作类型,参见 {@link ActionDirectiveType} */ actionType: ActionDirectiveType; /** 自然语言描述,例如:用户点击支付按钮并完成话费支付 */ actionDescribe: string; /** 自然语言描述,例如:调用话费账单查询工具,基于工具返回回复用户。如果有卡片需要引用卡片 */ expectedAction: string; /** mcp名称,如果expectedAction里预期要调用工具,需要在这里写明调用工具的mcp name */ toolName?: string; /** mcp入参,如果expectedAction里预期要调用工具,需要在这里写明调用工具的入参 */ toolParams?: Record; /** 自然语言描述,例如:严格参照提供的工具入参来调用工具,不要调用除bill_check以外的其他工具,只能严格基于bill_check工具返回结果进行回复 */ responseHint?: string; } /** * 豆包 App 账号信息。 * * @public */ export declare interface DoubaoAppAccountInfo { /** 豆包 App appId */ appId: string; /** * 豆包 App 运行环境。 * * - develop: 开发版 * - trial: 体验版 * - release: 正式版 */ envVersion: 'develop' | 'trial' | 'release'; /** * 线上豆包 App 版本号。 * */ version: string; } /** * 开启页面返回前提醒。 * 当用户在小程序非最底层页面点击左上角返回按钮、左上角首页按钮或 Android 系统 back 键时,弹起询问弹窗 * * 返回询问对话框只会对调用的当前页面生效,通过手势滑动返回时不会弹起询问对话框 * * @summary 开启页面返回前提醒。 * @remarks * 配合 disableAlertBeforeUnload 使用。 * @example * ```typescript * import { enableAlertBeforeUnload } from '@doubao-apps/framework/api'; * * await enableAlertBeforeUnload({ message: '确定离开当前页面吗?' }); * ``` * * @public */ export declare const enableAlertBeforeUnload: (params: EnableAlertBeforeUnloadParams) => Promise; /** * 开启返回前提醒的参数。 * * @public */ export declare interface EnableAlertBeforeUnloadParams { /** 返回前确认弹窗的文案。 */ message: string; } /** * 允许用户录屏。 * * @example * ```typescript * import { enableUserScreenRecord } from '@doubao-apps/framework/api'; * * await enableUserScreenRecord(); * ``` * * @public */ export declare const enableUserScreenRecord: (params?: {} | undefined) => Promise; /** * 退出当前所有页面。 * * @remarks * 会退出当前所有页面。当当前页面已经是页面栈中的最后一个页面、`navigateBack` 无法继续返回时, * 使用 `exitApp` 退出小程序。 * @example * ```typescript * import { exitApp } from '@doubao-apps/framework/api'; * * await exitApp(); * ``` * * @public */ export declare const exitApp: () => Promise; /** * 更新过期的 widget 为固定卡片。 * * @remarks * 用于将状态已经过期的 widget 实例转换为固定卡片,用户点击后可跳转到指定页面。 * * `getWidgetInstanceId` 仅在卡片环境中有效,在小程序页面中会返回 `undefined`。如果需要在页面中调用, * 请在 `navigateTo` 时通过参数传递卡片实例 ID。 * * @example * ```ts * import { expiredWidget } from '@doubao-apps/framework/api'; * import { getWidgetInstanceId } from '@doubao-apps/framework'; * * expiredWidget({ * widgetInstanceId: getWidgetInstanceId(), * url: '/pages/detail/index?key=value' * }); * ``` * * @public */ export declare const expiredWidget: ({ widgetInstanceId, url, schema, title, detailText }: ExpiredWidgetParams) => Promise; /** * 将过期卡片转换为固定卡片的请求参数。 * * @public */ export declare interface ExpiredWidgetParams { /** * 卡片实例 ID。 * * 在卡片环境可通过 `getWidgetInstanceId` 获取;在小程序页面等非卡片环境需要通过传参或通信传递。 */ widgetInstanceId: string; /** 点击失效卡要跳转的页面 URL 或 sslocal schema。小程序页面 URL 格式与 navigateTo 的 url 参数一致 */ url?: string; /** * 点击失效卡要跳转的页面 schema,格式与 navigateTo 的 url 参数一致。 * * @deprecated 使用 url 字段替代 schema 字段,后续版本将移除 schema 字段,请尽快迁移到 url 字段 */ schema?: string; /** 点击失效卡要跳转的页面 title */ title?: string; /** 点击失效卡要跳转的页面 detailText */ detailText?: string; } /** * 文件系统管理器,提供对本地文件系统的完整读写能力。 * * 通过 {@link getFileSystemManager} 获取实例后,可使用该接口上的方法执行文件和目录操作。 * 大多数方法同时提供异步(返回 `Promise`)和同步(`Sync` 后缀)两种调用方式。 * * @remarks * - 所有路径参数均为本地文件路径,不支持网络路径。 * - 同步方法会阻塞当前 JS 线程直到操作完成;对于大文件操作建议使用异步方法以避免卡顿。 * - 文件操作失败时(如路径不存在、权限不足),Promise 会被 reject 或同步方法会抛出异常。 * * @public */ export declare interface FileSystemManager { /** * 读取文件内容(异步)。 * * @param params - 读取参数,参见 {@link ReadFileParams}。 * @returns 返回一个 Promise,解析为 {@link ReadFileResult}。 */ readFile(params: ReadFileParams): Promise; /** * 读取文件内容(同步)。 * * @param params - 读取参数,参见 {@link ReadFileParams}。 * @returns 返回 {@link ReadFileResult}。 */ readFileSync(params: ReadFileParams): ReadFileResult; /** * 写入文件内容(异步)。如果文件不存在则创建,已存在则覆盖。 * * @param params - 写入参数,参见 {@link WriteFileParams}。 */ writeFile(params: WriteFileParams): Promise; /** * 写入文件内容(同步)。如果文件不存在则创建,已存在则覆盖。 * * @param params - 写入参数,参见 {@link WriteFileParams}。 */ writeFileSync(params: WriteFileParams): void; /** * 在文件末尾追加内容(异步)。如果文件不存在则创建。 * * @param params - 追加参数,参见 {@link AppendFileParams}。 */ appendFile(params: AppendFileParams): Promise; /** * 在文件末尾追加内容(同步)。如果文件不存在则创建。 * * @param params - 追加参数,参见 {@link AppendFileParams}。 */ appendFileSync(params: AppendFileParams): void; /** * 判断文件或目录是否存在(异步)。 * * 路径存在时 Promise resolve;路径不存在时 Promise reject。 * * @param params - 参见 {@link AccessParams}。 */ access(params: AccessParams): Promise; /** * 判断文件或目录是否存在(同步)。 * * 路径不存在时会抛出异常。 * * @param params - 参见 {@link AccessParams}。 */ accessSync(params: AccessParams): void; /** * 创建目录(异步)。 * * @param params - 参见 {@link MkdirParams}。 */ mkdir(params: MkdirParams): Promise; /** * 创建目录(同步)。 * * @param params - 参见 {@link MkdirParams}。 */ mkdirSync(params: MkdirParams): void; /** * 删除目录(异步)。 * * @param params - 参见 {@link RmdirParams}。 */ rmdir(params: RmdirParams): Promise; /** * 删除目录(同步)。 * * @param params - 参见 {@link RmdirParams}。 */ rmdirSync(params: RmdirParams): void; /** * 读取目录下的文件和子目录列表(异步)。 * * @param params - 参见 {@link ReaddirParams}。 * @returns 返回一个 Promise,解析为 {@link ReaddirResult}。 */ readdir(params: ReaddirParams): Promise; /** * 读取目录下的文件和子目录列表(同步)。 * * @param params - 参见 {@link ReaddirParams}。 * @returns 返回 {@link ReaddirResult}。 */ readdirSync(params: ReaddirParams): ReaddirResult; /** * 删除文件(异步)。不能用于删除目录。 * * @param params - 参见 {@link UnlinkParams}。 */ unlink(params: UnlinkParams): Promise; /** * 删除文件(同步)。不能用于删除目录。 * * @param params - 参见 {@link UnlinkParams}。 */ unlinkSync(params: UnlinkParams): void; /** * 获取文件或目录的状态信息(异步)。 * * @param params - 参见 {@link StatParams}。 * @returns 返回一个 Promise,解析为 {@link StatResult}。 */ stat(params: StatParams): Promise; /** * 获取文件或目录的状态信息(同步)。 * * @param params - 参见 {@link StatParams}。 * @returns 返回 {@link StatResult}。 */ statSync(params: StatParams): StatResult; /** * 复制文件(异步)。不支持复制目录。 * * @param params - 参见 {@link CopyFileParams}。 */ copyFile(params: CopyFileParams): Promise; /** * 复制文件(同步)。不支持复制目录。 * * @param params - 参见 {@link CopyFileParams}。 */ copyFileSync(params: CopyFileParams): void; /** * 重命名或移动文件(异步)。 * * @param params - 参见 {@link RenameParams}。 */ rename(params: RenameParams): Promise; /** * 重命名或移动文件(同步)。 * * @param params - 参见 {@link RenameParams}。 */ renameSync(params: RenameParams): void; /** * 截断文件到指定长度(异步)。 * * @param params - 参见 {@link TruncateParams}。 */ truncate(params: TruncateParams): Promise; /** * 截断文件到指定长度(同步)。 * * @param params - 参见 {@link TruncateParams}。 */ truncateSync(params: TruncateParams): void; /** * 获取文件信息,可选计算文件摘要(异步)。 * * @param params - 参见 {@link GetFileInfoParams}。 * @returns 返回一个 Promise,解析为 {@link GetFileInfoResult}。 */ getFileInfo(params: GetFileInfoParams): Promise; /** * 将临时文件保存到本地持久化存储(异步)。 * * @param params - 参见 {@link SaveFileParams}。 * @returns 返回一个 Promise,解析为 {@link SaveFileResult}。 */ saveFile(params: SaveFileParams): Promise; /** * 将临时文件保存到本地持久化存储(同步)。 * * @param params - 参见 {@link SaveFileParams}。 * @returns 返回 {@link SaveFileResult}。 */ saveFileSync(params: SaveFileParams): SaveFileResult; /** * 获取已保存的本地文件列表(异步)。 * * @returns 返回一个 Promise,解析为 {@link GetSavedFileListResult}。 */ getSavedFileList(): Promise; /** * 删除通过 {@link FileSystemManager.saveFile} 保存的本地文件(异步)。 * * @param params - 参见 {@link RemoveSavedFileParams}。 */ removeSavedFile(params: RemoveSavedFileParams): Promise; /** * 解压 zip 文件到指定目录(异步)。 * * @param params - 参见 {@link UnzipParams}。 */ unzip(params: UnzipParams): Promise; } /** * 异步获取账号信息。 * * @example * ```typescript * import { getAccountInfo } from '@doubao-apps/framework/api'; * * const result = await getAccountInfo(); * console.log(result.miniProgram.appId); * ``` * * @public */ export declare function getAccountInfo(params?: {}): Promise; /** * 获取当前账号信息。 * * @public */ export declare interface GetAccountInfoResult { /** 豆包 App账号信息 */ miniProgram: DoubaoAppAccountInfo; /** 插件账号信息(仅在插件中调用时包含) */ plugin?: PluginAccountInfo; } /** * 同步获取账号信息。 * * @example * ```typescript * import { getAccountInfoSync } from '@doubao-apps/framework/api'; * * const result = getAccountInfoSync(); * console.log(result.miniProgram.appId, result.miniProgram.envVersion, result.miniProgram.version); * ``` * * @public */ export declare function getAccountInfoSync(params?: {}): GetAccountInfoResult; /** * 获取应用基础信息。 * * @returns 返回 SDK 版本、调试开关、宿主信息、语言和主题等字段,见 {@link GetAppBaseInfoResult}。 * @example * ```typescript * import { getAppBaseInfo } from '@doubao-apps/framework/api'; * * const result = await getAppBaseInfo(); * * console.log(result.language, result.SDKVersion, result.theme); * console.log(result.host?.appId, result.enableDebug); * ``` * * @public */ export declare const getAppBaseInfo: (params?: {}) => Promise; /** @public */ export declare interface GetAppBaseInfoResult { /** 客户端基础库版本 */ SDKVersion?: string; /** 是否已打开调试 */ enableDebug?: boolean; /** 当前豆包 App运行的宿主环境 */ host?: AppBaseInfoHost; /** 当前语言 */ language: string; /** 宿主版本号 */ version?: string; /** 当前主题 */ theme?: 'light' | 'dark'; } /** * 获取应用基础信息。 * * @returns 返回 SDK 版本、调试开关、宿主信息、语言和主题等字段,见 {@link GetAppBaseInfoResult}。 * @example * ```typescript * import { getAppBaseInfoSync } from '@doubao-apps/framework/api'; * * const result = getAppBaseInfoSync(); * * console.log(result.language, result.SDKVersion, result.theme); * console.log(result.host?.appId, result.enableDebug); * ``` * * @public */ export declare const getAppBaseInfoSync: (_params?: {}) => GetAppBaseInfoResult; /** * 获取全局唯一的背景音频管理器。 * * @public */ export declare function getBackgroundAudioManager(): BackgroundAudioManager; /** * 获取电池信息。 * * @example * ```typescript * import { getBatteryInfo } from '@doubao-apps/framework/api'; * * const { isCharging, level } = await getBatteryInfo(); * * console.log(isCharging, level); * ``` * * @public */ export declare const getBatteryInfo: (params?: {} | undefined) => Promise; /** * 电池信息。 * * @public */ export declare interface GetBatteryInfoResult { /** 是否正在充电。 */ isCharging: boolean; /** 当前电量,范围 1 - 100。 */ level: number; } /** * 获取已搜索到的 iBeacon 列表。 * * @example * ```typescript * import { getBeacons } from '@doubao-apps/framework/api'; * * const { beacons } = await getBeacons(); * * console.log(beacons); * ``` * * @public */ export declare const getBeacons: (params?: {} | undefined) => Promise; /** * 获取 iBeacon 列表的返回结果。 * * @public */ export declare interface GetBeaconsResult { /** 当前搜到的 iBeacon 列表。 */ beacons: BeaconInfo[]; } /** * 获取 BLE 特征值列表。 * * @remarks * 通常先获取 BLE 服务列表。 * @example * ```typescript * import { getBLEDeviceCharacteristics } from '@doubao-apps/framework/api'; * * const { characteristics } = await getBLEDeviceCharacteristics({ * deviceId: 'device-id', * serviceId: 'service-id' * }); * * console.log(characteristics); * ``` * * @public */ export declare const getBLEDeviceCharacteristics: (params: GetBLEDeviceCharacteristicsParams) => Promise; /** * 获取 BLE 特征值列表的请求参数。 * * @public */ export declare interface GetBLEDeviceCharacteristicsParams { /** 蓝牙设备 ID。 */ deviceId: string; /** 服务 ID。 */ serviceId: string; } /** * 获取 BLE 特征值列表的返回结果。 * * @public */ export declare interface GetBLEDeviceCharacteristicsResult { /** 特征值列表。 */ characteristics: BluetoothCharacteristic[]; } /** * 获取 BLE 设备 RSSI。 * * @example * ```typescript * import { getBLEDeviceRSSI } from '@doubao-apps/framework/api'; * * const { RSSI } = await getBLEDeviceRSSI({ deviceId: 'device-id' }); * * console.log(RSSI); * ``` * * @public */ export declare const getBLEDeviceRSSI: (params: GetBLEDeviceRSSIParams) => Promise; /** * 获取 BLE RSSI 的请求参数。 * * @public */ export declare interface GetBLEDeviceRSSIParams { /** 蓝牙设备 ID。 */ deviceId: string; } /** * 获取 BLE RSSI 的返回结果。 * * @public */ export declare interface GetBLEDeviceRSSIResult { /** RSSI 信号强度,单位 dBm。 */ RSSI: number; } /** * 获取 BLE 服务列表。 * * @remarks * 通常先调用 createBLEConnection。 * @example * ```typescript * import { getBLEDeviceServices } from '@doubao-apps/framework/api'; * * const { services } = await getBLEDeviceServices({ deviceId: 'device-id' }); * * console.log(services); * ``` * * @public */ export declare const getBLEDeviceServices: (params: GetBLEDeviceServicesParams) => Promise; /** * 获取 BLE 服务列表的请求参数。 * * @public */ export declare interface GetBLEDeviceServicesParams { /** 蓝牙设备 ID。 */ deviceId: string; } /** * 获取 BLE 服务列表的返回结果。 * * @public */ export declare interface GetBLEDeviceServicesResult { /** 设备服务列表。 */ services: BluetoothService[]; } /** * 获取 BLE MTU。 * * @example * ```typescript * import { getBLEMTU } from '@doubao-apps/framework/api'; * * const { mtu } = await getBLEMTU({ deviceId: 'device-id' }); * * console.log(mtu); * ``` * * @public */ export declare const getBLEMTU: (params: GetBLEMTUParams) => Promise; /** * 获取 BLE MTU 的请求参数。 * * @public */ export declare interface GetBLEMTUParams { /** 蓝牙设备 ID。 */ deviceId: string; /** 写入模式。 */ writeType?: BluetoothWriteType; } /** * 获取 BLE MTU 的返回结果。 * * @public */ export declare interface GetBLEMTUResult { /** 当前 MTU。 */ mtu: number; } /** * 获取蓝牙适配器状态。 * * @example * ```typescript * import { getBluetoothAdapterState } from '@doubao-apps/framework/api'; * * const { available, discovering } = await getBluetoothAdapterState(); * * console.log(available, discovering); * ``` * * @public */ export declare const getBluetoothAdapterState: (params?: {} | undefined) => Promise; /** * 蓝牙适配器状态。 * * @public */ export declare interface GetBluetoothAdapterStateResult { /** 蓝牙适配器是否可用。 */ available: boolean; /** 是否正在搜索蓝牙设备。 */ discovering: boolean; } /** * 获取当前蓝牙模块发现的设备列表。 * * @remarks * 通常先调用 startBluetoothDevicesDiscovery。 * @example * ```typescript * import { getBluetoothDevices } from '@doubao-apps/framework/api'; * * const { devices } = await getBluetoothDevices(); * * console.log(devices.map((device) => device.name)); * ``` * * @public */ export declare function getBluetoothDevices(params?: {}): Promise; /** * 获取蓝牙设备列表的返回结果。 * * @public */ export declare interface GetBluetoothDevicesResult { /** 当前蓝牙模块已发现的设备列表。 */ devices: BluetoothDevice[]; } /** * 获取剪贴板内容。 * * @example * ```typescript * import { getClipboardData } from '@doubao-apps/framework/api'; * * const { data } = await getClipboardData(); * * console.log(data); * ``` * * @public */ export declare const getClipboardData: (params?: {} | undefined) => Promise; /** * 剪贴板读取结果。 * * @public */ export declare interface GetClipboardDataResult { /** 当前剪贴板内容。 */ data: string; } /** * 获取已连接的蓝牙设备列表。 * * @example * ```typescript * import { getConnectedBluetoothDevices } from '@doubao-apps/framework/api'; * * const { devices } = await getConnectedBluetoothDevices({ * services: ['0000180D-0000-1000-8000-00805F9B34FB'] * }); * * console.log(devices); * ``` * * @public */ export declare const getConnectedBluetoothDevices: (params: GetConnectedBluetoothDevicesParams) => Promise; /** * 获取已连接蓝牙设备的请求参数。 * * @public */ export declare interface GetConnectedBluetoothDevicesParams { /** 蓝牙主服务 UUID 列表。 */ services: string[]; } /** * 获取已连接蓝牙设备的返回结果。 * * @public */ export declare interface GetConnectedBluetoothDevicesResult { /** 已连接设备列表。 */ devices: ConnectedBluetoothDevice[]; } /** * 获取当前已连接 Wi-Fi 信息。 * * @example * ```typescript * import { getConnectedWifi } from '@doubao-apps/framework/api'; * * const { wifi } = await getConnectedWifi({ partialInfo: true }); * * console.log(wifi.ssid); * ``` * * @public */ export declare const getConnectedWifi: (params?: GetConnectedWifiParams | undefined) => Promise; /** * 获取当前已连接 Wi-Fi 的请求参数。 * * @public */ export declare interface GetConnectedWifiParams { /** 是否只返回部分 Wi-Fi 信息。 */ partialInfo?: boolean; } /** * 获取当前已连接 Wi-Fi 的返回结果。 * * @public */ export declare interface GetConnectedWifiResult { /** 当前连接的 Wi-Fi 信息。 */ wifi: WifiInfo; } /** * 获取设备基础信息。 * * @returns 返回设备品牌、型号、系统、内存和性能等级等字段,见 {@link GetDeviceInfoResult}。 * @example * ```typescript * import { getDeviceInfo } from '@doubao-apps/framework/api'; * * const result = await getDeviceInfo(); * * console.log(result.brand, result.model, result.system); * console.log(result.platform, result.benchmarkLevel); * ``` * * @public */ export declare const getDeviceInfo: (params?: {} | undefined) => Promise; /** * 设备基础信息。 * * @public */ export declare interface GetDeviceInfoResult { /** 宿主 App 二进制接口类型,仅 Android 支持。 */ abi?: string; /** 设备二进制接口类型,仅 Android 支持。 */ deviceAbi?: string; /** 设备性能等级,值越高性能越好;-1 表示未知。 */ benchmarkLevel: number; /** 设备品牌。 */ brand: string; /** 设备型号。 */ model: string; /** 操作系统及版本。 */ system: string; /** 客户端平台。 */ platform: string; /** 设备 CPU 型号,仅 Android 支持。 */ cpuType?: string; /** 设备内存大小,单位 MB。 */ memorySize: string; } /** * 同步获取设备基础信息。 * * @returns 返回设备品牌、型号、系统、内存和性能等级等字段,见 {@link GetDeviceInfoResult}。 * @example * ```typescript * import { getDeviceInfoSync } from '@doubao-apps/framework/api'; * * const result = getDeviceInfoSync(); * * console.log(result.brand, result.model, result.system); * console.log(result.platform, result.benchmarkLevel); * ``` * * @public */ export declare const getDeviceInfoSync: (params?: {} | undefined) => GetDeviceInfoResult; /** * {@link FileSystemManager.getFileInfo} 的参数。 * * @public */ export declare interface GetFileInfoParams { /** * 要获取信息的文件路径。 */ filePath: string; /** * 用于计算文件摘要的哈希算法。 * * - `'md5'`:使用 MD5 算法计算文件摘要。 * - `'sha1'`:使用 SHA-1 算法计算文件摘要。 * * 不传时不计算摘要,返回结果中 {@link GetFileInfoResult.digest} 为 `undefined`。 */ digestAlgorithm?: 'md5' | 'sha1'; } /** * {@link FileSystemManager.getFileInfo} 的返回结果。 * * @public */ export declare interface GetFileInfoResult { /** * 文件大小,单位为字节(Byte)。 */ size: number; /** * 按照 {@link GetFileInfoParams.digestAlgorithm} 计算得到的文件摘要(十六进制字符串)。 * * 仅当请求时指定了 `digestAlgorithm` 才会返回。 */ digest?: string; } /** * 获取文件系统管理器。 * * @example * ```typescript * import { getFileSystemManager } from '@doubao-apps/framework/api'; * * const fs = getFileSystemManager(); * const { data } = await fs.readFile({ * filePath: '/tmp/profile.json', * encoding: 'utf-8' * }); * * console.log(data); * ``` */ export declare function getFileSystemManager(): FileSystemManager; /** * 获取图片信息。 * * @example * ```typescript * import { getImageInfo } from '@doubao-apps/framework/api'; * * const { width, height, path } = await getImageInfo({ * src: '/tmp/image.png' * }); * * console.log(width, height, path); * ``` * * @public */ export declare const getImageInfo: (params: GetImageInfoParams) => Promise; /** * 获取图片信息的请求参数。 * * @public */ export declare interface GetImageInfoParams { /** 图片路径,可以是相对路径、临时文件路径、存储文件路径或网络图片路径。 */ src: string; } /** * 图片信息结果。 * * @public */ export declare interface GetImageInfoResult { /** 图片原始高度,单位 px,不考虑旋转。 */ height: number; /** 图片方向。 */ orientation: ImageOrientation_2; /** 图片的本地路径。 */ path: string; /** 图片格式。 */ type: string; /** 图片原始宽度,单位 px,不考虑旋转。 */ width: number; } /** * 获取局域网 IP 地址。 * * @example * ```typescript * import { getLocalIPAddress } from '@doubao-apps/framework/api'; * * const { localIp, netmask } = await getLocalIPAddress(); * * console.log(localIp, netmask); * ``` * * @public */ export declare const getLocalIPAddress: (params?: {} | undefined) => Promise; /** * 获取局域网 IP 的返回结果。 * * @public */ export declare interface GetLocalIPAddressResult { /** 本机局域网 IP 地址。 */ localIp: string; /** 子网掩码。 */ netmask?: string; } /** * 获取设备当前的地理位置信息。 * * @returns 返回一个 Promise,成功时解析为包含地理位置信息的对象,包含: * - `latitude`: number - 纬度。 * - `longitude`: number - 经度。 * - `timestamp`: string - 时间戳。 * - `speed`: number - 行进速度,单位:米/秒。 * - `accuracy`: number - 定位精度,单位:米。 * 参考 {@link GetLocationResponse}。 * @throws {APICallFailedError} 如果调用失败(例如,用户拒绝权限、定位服务关闭等),则抛出此错误。 * @remarks * 可能涉及定位授权。 * @example * ```typescript * import { getLocation } from '@doubao-apps/framework/api'; * * async function fetchLocation() { * try { * const locationData = await getLocation(); * console.log('纬度:', locationData.latitude); * console.log('经度:', locationData.longitude); * console.log('时间戳:', locationData.timestamp); * console.log('行进速度:', locationData.speed); * console.log('定位精度:', locationData.accuracy); * } catch (error) { * console.error('获取位置失败:', error); * // 处理错误,例如提示用户开启定位权限 * } * } * * fetchLocation(); * ``` * * @public */ export declare const getLocation: (params?: GetLocationParams | undefined) => Promise; /** @public */ export declare interface GetLocationParams { /** * 调用业务方 */ source?: string; /** * 定位模式 * 0:低功耗 * 1:仅设备 * 2:高精度(默认) */ mode?: number; /** * 超时时间,单位毫秒,默认 30000 */ timeoutMs?: number; /** * 缓存时间,单位毫秒,默认为0 */ maxCacheMs?: number; } /** @public */ export declare interface GetLocationResponse { /** * 纬度 */ latitude: number; /** * 经度 */ longitude: number; /** * 时间戳 */ timestamp: string; /** * 行进速度,单位:米/秒 */ speed: number; /** * 定位精度,单位:米 */ accuracy: number; } /** * 获取菜单按钮的布局位置信息。 * * @returns 返回菜单按钮相对屏幕左上角的坐标和尺寸,字段见 {@link MenuButtonBoundingClientRect}。 * @example * ```ts * import { getMenuButtonBoundingClientRect } from '@doubao-apps/framework/api'; * * const rect = getMenuButtonBoundingClientRect(); * * console.log(rect.width, rect.height); * console.log(rect.top, rect.right, rect.bottom, rect.left); * ``` * * @public */ export declare const getMenuButtonBoundingClientRect: (params?: {} | undefined) => MenuButtonBoundingClientRect; /** * 获取当前网络类型。 * * @returns 返回一个 Promise,解析为 {@link GetNetworkTypeResult}。 * * @example * ```ts * import { getNetworkType } from '@doubao-apps/framework/api'; * * const result = await getNetworkType(); * console.log(result.networkType); * ``` * * @public */ export declare const getNetworkType: (params?: GetNetworkTypeParams | undefined) => Promise; /** * 获取网络类型的请求参数。 * * 当前无需传入任何字段,预留扩展位。 * * @public */ export declare interface GetNetworkTypeParams { } /** * 获取网络类型的返回结果。 * * @public */ export declare interface GetNetworkTypeResult { /** 当前网络类型。 */ networkType: NetworkType; /** 信号强弱,单位 dBm。 */ signalStrength?: number; /** 设备是否使用了系统代理。 */ hasSystemProxy?: boolean; /** 是否处于弱网环境。 */ weakNet?: boolean; } /** * 使用预下单返回的平台交易订单号拉起用户收银台。 * * @param params - 拉起收银台所需的平台交易订单号。 * @returns 收银台流程正常返回时,返回订单号和日志 ID。 * @remarks * 直接调用此 API 时,业务只传入 `orderId`,用于普通支付收银台流程。 * 豆包平台免密支付应使用 `DoubaoPaymentButton`,由组件查询当前用户的免密可用状态, * 并在用户选择免密支付时携带平台返回的免密支付方式参数;业务不能自行构造该参数。 * 当账号未绑定、发生换绑或平台判断免密不可用时,应以组件展示的普通支付路径为准。 * * 此 API 成功仅表示收银台已正常拉起并完成前端交互,不代表订单支付成功。 * 最终支付状态必须以业务服务端查询订单详情的结果或业务服务端收到的支付结果回调为准。 * @example * ```typescript * import { * getOrderPayment, * requestOrder, * type RequestOrderParams * } from '@doubao-apps/framework/api'; * * // 业务方自行实现:从业务服务端获取预下单参数和签名;该函数不是 SDK API。 * declare function getOrderParamsFromBusinessServer(): Promise; * // 业务方自行实现:通过业务服务端确认并刷新最终支付状态;该函数不是 SDK API。 * declare function refreshOrderStatusFromBusinessServer(orderId: string): Promise; * * const orderParams = await getOrderParamsFromBusinessServer(); * const { orderId } = await requestOrder(orderParams); * const { logId } = await getOrderPayment({ orderId }); * * console.log(orderId, logId); * await refreshOrderStatusFromBusinessServer(orderId); * ``` * * @public */ export declare const getOrderPayment: (params: GetOrderPaymentParams) => Promise; /** @public */ export declare interface GetOrderPaymentParams { /** * 平台交易订单号,长度不超过 64 字节。 * * 传入 `requestOrder` 预下单成功后返回的 `orderId`,不要使用业务侧订单号或自行构造的值。 */ orderId: string; } /** @public */ export declare interface GetOrderPaymentResult { /** 本次拉起收银台所使用的平台交易订单号。 */ orderId: string; /** 用于服务端排查问题的日志 ID。 */ logId: string; } /** * 使用预下单号和签约参数拉起支付并签约收银台。 * * @param params - 预下单号,以及业务服务端返回的签约参数和请求签名。 * @returns 收银台流程正常返回时,返回订单号和日志 ID;同步结果中不包含签约 ID。 * @remarks * 此 API 属于三方支付并签约流程,与支付按钮组件根据平台签约状态发起的豆包平台免密支付不是同一流程。 * * 支付是主流程,签约是附带流程。如果签约参数无效,收银台会降级为仅支付。 * * `signData` 和 `signDbAuthorization` 必须由业务服务端生成,不能在前端自行构造。 * 此 API 成功不代表支付或签约成功,最终状态必须由业务服务端分别通过查询接口或结果回调确认。 * @example * ```typescript * import { * getOrderPaymentWithSign, * type GetOrderPaymentWithSignParams * } from '@doubao-apps/framework/api'; * * // 业务方自行实现:从业务服务端获取支付并签约参数;该函数不是 SDK API。 * declare function getPaymentAndSignParamsFromBusinessServer(): * Promise; * // 业务方自行实现:通过业务服务端分别确认支付与签约状态;该函数不是 SDK API。 * declare function refreshPaymentAndSignStatusFromBusinessServer(orderId: string): Promise; * * const paymentParams = await getPaymentAndSignParamsFromBusinessServer(); * const result = await getOrderPaymentWithSign(paymentParams); * console.log(result.orderId); * await refreshPaymentAndSignStatusFromBusinessServer(result.orderId); * ``` * * @public */ export declare const getOrderPaymentWithSign: (params: GetOrderPaymentWithSignParams) => Promise; /** @public */ export declare interface GetOrderPaymentWithSignParams { /** * 平台交易订单号。 * * 应使用 `requestOrder` 返回的真实预下单结果,不要传入业务侧订单号或自行构造的值。 */ orderId: string; /** * 支付并签约所需的签约参数。 * * 该字段必须由业务服务端按支付并签约接入协议生成并返回,前端应原样透传。 */ signData: string; /** * `signData` 对应的请求签名。 * * 该字段必须由业务服务端生成并与 `signData` 一并返回,前端应原样透传。 */ signDbAuthorization: string; } /** * 获取当前 package 信息。 * * @returns 返回当前 package 的 appId、展示名称和展示图标地址,见 {@link GetPackageInfoResult}。 * @example * ```typescript * import { getPackageInfo } from '@doubao-apps/framework/api'; * * const result = await getPackageInfo(); * * console.log(result.appId, result.name, result.iconSrc); * ``` * * @public */ export declare const getPackageInfo: (params?: {} | undefined) => Promise; /** * 当前 package 信息。 * * @public */ export declare interface GetPackageInfoResult { /** 当前 package 的 appId。 */ appId: string; /** 当前 package 的展示名称。 */ name: string; /** 当前 package 的展示图标地址。 */ iconSrc?: string; } /** * 同步获取当前 package 信息。 * * @returns 返回当前 package 的 appId、展示名称和展示图标地址,见 {@link GetPackageInfoResult}。 * @example * ```typescript * import { getPackageInfoSync } from '@doubao-apps/framework/api'; * * const result = getPackageInfoSync(); * * console.log(result.appId, result.name, result.iconSrc); * ``` * * @public */ export declare const getPackageInfoSync: () => GetPackageInfoResult; /** * 获取隐私设置状态。 * * @returns 返回隐私设置状态。 * @example * ```typescript * import { getPrivacySetting } from '@doubao-apps/framework/api'; * * const { needAuthorization } = await getPrivacySetting(); * * console.log(needAuthorization); * ``` * * @public */ export declare const getPrivacySetting: (params?: {} | undefined) => Promise; /** * 获取安全随机数。 * * @example * ```typescript * import { getRandomValues } from '@doubao-apps/framework/api'; * * const { randomValues } = await getRandomValues({ length: 16 }); * const bytes = new Uint8Array(randomValues); * * console.log(bytes); * ``` * * @public */ export declare function getRandomValues(params: GetRandomValuesParams): Promise; /** * 获取安全随机数的请求参数。 * * @public */ export declare interface GetRandomValuesParams { /** 需要生成的字节数。 */ length: number; } /** * 获取安全随机数的返回结果。 * * @public */ export declare interface GetRandomValuesResult { /** 生成的随机字节。 */ randomValues: ArrayBuffer; } /** * 获取全局唯一的录音管理器。 * * @example * ```ts * import { getRecorderManager } from '@doubao-apps/framework/api'; * * const rm = getRecorderManager(); * rm.onStop((res) => console.log('录音完成', res.tempFilePath)); * rm.start({ duration: 10000, format: 'aac' }); * ``` * * @public */ export declare function getRecorderManager(): RecorderManager; /** * {@link FileSystemManager.getSavedFileList} 的返回结果。 * * @public */ export declare interface GetSavedFileListResult { /** * 已保存的本地文件列表,每项包含文件路径、大小和创建时间。 */ fileList: Array<{ /** 文件的本地路径。 */ filePath: string; /** 文件大小,单位为字节(Byte)。 */ size: number; /** 文件保存时的时间戳,单位为毫秒。 */ createTime: number; }>; } /** * 获取屏幕亮度。 * * @example * ```typescript * import { getScreenBrightness } from '@doubao-apps/framework/api'; * * const { value } = await getScreenBrightness(); * * console.log(value); * ``` * * @public */ export declare const getScreenBrightness: (params?: {} | undefined) => Promise; /** @public */ export declare interface GetScreenBrightnessResult { /** 屏幕亮度值,范围 0 ~ 1,0 最暗,1 最亮 */ value: number; } /** * 获取当前输入框的选区范围。 * * @example * ```typescript * import { getSelectedTextRange } from '@doubao-apps/framework/api'; * * const { start, end } = await getSelectedTextRange(); * * console.log(start, end); * ``` * * @public */ export declare const getSelectedTextRange: (params?: {} | undefined) => Promise; /** * 获取输入框选区范围的返回结果。 * * @public */ export declare interface GetSelectedTextRangeResult { /** 选区起始位置。 */ start: number; /** 选区结束位置。 */ end: number; } /** * 获取用户当前授权设置 * * @param params - 查询参数 * @param params.withSubscriptions - 是否同时获取用户订阅消息的订阅状态 * @returns Promise 对象,成功时返回授权设置 * @remarks * `authSetting` 只包含已向用户请求过且状态明确的权限。 * 注意:当前宿主暂不支持订阅模板,传入 `withSubscriptions: true` 时会由宿主返回失败,错误信息为 `subscription templates are not supported yet`。 * @example * ```typescript * import { getSetting } from '@doubao-apps/framework/api'; * * const result = await getSetting(); * console.log(result.authSetting['scope.userLocation']); * ``` * * @public */ export declare const getSetting: (params?: GetSettingParams | undefined) => Promise; /** @public */ export declare interface GetSettingParams { /** * 是否同时获取用户订阅消息的订阅状态,默认不获取。 */ withSubscriptions?: boolean; } /** @public */ export declare interface GetSettingResult { /** 用户授权结果,key 为权限 scope,value 表示是否已授权 */ authSetting: AuthSetting; /** 用户订阅消息设置,withSubscriptions 为 true 时才会返回 */ subscriptionsSetting?: SubscriptionsSetting; } /** * 从本地缓存读取数据。 * * @param params 查询参数,字段见 {@link GetStorageParams}。 * @returns 返回一个 Promise,解析为 {@link GetStorageResult}。 * @remarks * @example * ```typescript * import { getStorage } from '@doubao-apps/framework/api'; * * const result = await getStorage<{ name: string; age: number }>({ * key: 'profile', * }); * * console.log(result.data.name, result.data.age); * ``` * * @public */ export declare function getStorage(params: GetStorageParams): Promise>; /** * 获取本地缓存信息。 * * @returns 返回一个 Promise,解析为 {@link GetStorageInfoResult}。 * @example * ```typescript * import { getStorageInfo } from '@doubao-apps/framework/api'; * * const result = await getStorageInfo(); * * console.log(result.keys, result.currentSize, result.limitSize); * ``` * * @public */ export declare const getStorageInfo: (params?: {} | undefined) => Promise; /** @public */ export declare interface GetStorageInfoResult { /** 当前 storage 中所有的 key */ keys: string[]; /** 当前占用的空间大小,单位 KB */ currentSize: number; /** 限制的空间大小,单位 KB */ limitSize: number; } /** * 同步获取本地缓存信息。 * * @returns 返回 {@link GetStorageInfoResult}。 * @example * ```typescript * import { getStorageInfoSync } from '@doubao-apps/framework/api'; * * const result = getStorageInfoSync(); * * console.log(result.keys, result.currentSize, result.limitSize); * ``` * * @public */ export declare const getStorageInfoSync: (params?: {} | undefined) => GetStorageInfoResult; /** @public */ export declare interface GetStorageParams { /** 本地缓存键名 */ key: string; } /** @public */ export declare interface GetStorageResult { /** key 对应的数据 */ data: TData; } /** * 从本地缓存同步读取数据。 * * @param params 查询参数,字段见 {@link GetStorageParams}。 * @returns 返回 {@link GetStorageResult}。 * @remarks * @example * ```typescript * import { getStorageSync } from '@doubao-apps/framework/api'; * * const result = getStorageSync<{ name: string; age: number }>({ * key: 'profile', * }); * * console.log(result.data.name, result.data.age); * ``` * * @public */ export declare function getStorageSync(params: GetStorageParams): GetStorageResult; /** * 获取系统信息。 * * @returns 返回设备品牌、型号、屏幕尺寸、宿主信息和安全区域等字段,见 {@link GetSystemInfoResult}。 * @example * ```typescript * import { getSystemInfo } from '@doubao-apps/framework/api'; * * const result = await getSystemInfo(); * * console.log(result.brand, result.model, result.system); * console.log(result.screenWidth, result.screenHeight); * ``` * * @public */ export declare const getSystemInfo: (params?: {} | undefined) => Promise; /** @public */ export declare interface GetSystemInfoResult { /** 设备品牌 */ brand: string; /** 设备型号 */ model: string; /** 设备像素比,物理像素 = 逻辑像素 × pixelRatio */ pixelRatio: number; /** 屏幕宽度,单位为逻辑像素 */ screenWidth: number; /** 屏幕高度,单位为逻辑像素 */ screenHeight: number; /** 可使用窗口宽度,单位为逻辑像素 */ windowWidth: number; /** 可使用窗口高度,单位为逻辑像素 */ windowHeight: number; /** 状态栏高度,单位为逻辑像素 */ statusBarHeight: number; /** 系统语言,格式为 language_region,如 zh_CN、en_US */ language: string; /** 宿主版本号 */ version?: string; /** 操作系统及版本,如 "Android 14"、"iOS 17.5" */ system: string; /** 客户端平台,取值为 "ios" 或 "android" */ platform: string; /** 客户端基础库版本 */ SDKVersion?: string; /** 系统当前主题 */ theme?: 'light' | 'dark'; /** 设备性能等级,-1 表示未知 */ benchmarkLevel?: number; /** 在竖屏正方向下的安全区域,单位为逻辑像素 */ safeArea?: SystemInfoSafeArea; /** 是否已打开调试 */ enableDebug?: boolean; /** 设备方向 */ deviceOrientation?: 'portrait' | 'landscape'; /** 宿主 App 二进制接口类型(如 arm64-v8a),仅 Android 返回 */ abi?: string; } /** * 同步获取系统信息。 * * @returns 返回设备品牌、型号、屏幕尺寸、宿主信息和安全区域等字段,见 {@link GetSystemInfoResult}。 * @example * ```typescript * import { getSystemInfoSync } from '@doubao-apps/framework/api'; * * const result = getSystemInfoSync(); * * console.log(result.brand, result.model, result.system); * console.log(result.screenWidth, result.screenHeight); * ``` * * @public */ export declare const getSystemInfoSync: (params?: {} | undefined) => GetSystemInfoResult; /** * 获取设备设置。 * * @returns 返回蓝牙、定位、Wi-Fi 系统开关和设备方向等字段,见 {@link GetSystemSettingResult}。 * @example * ```typescript * import { getSystemSetting } from '@doubao-apps/framework/api'; * * const result = getSystemSetting(); * * console.log(result.bluetoothEnabled, result.locationEnabled); * console.log(result.wifiEnabled, result.deviceOrientation); * ``` * * @public */ export declare const getSystemSetting: (params?: {} | undefined) => GetSystemSettingResult; /** @public */ export declare interface GetSystemSettingResult { /** 蓝牙的系统开关 */ bluetoothEnabled: boolean; /** 地理位置的系统开关 */ locationEnabled: boolean; /** Wi-Fi 的系统开关 */ wifiEnabled: boolean; /** 设备方向 */ deviceOrientation: DeviceOrientation; } /** * 查询任务。 * * @param params - 任务查询参数。 * @returns 返回任务详情、状态、类型和 token 信息。 * @remarks * 根据任务 ID 查询任务的模板、详情、状态和类型。若返回 token,可在后续远端任务更新中继续使用。 * * @example * ```typescript * import { getTask } from '@doubao-apps/framework/api'; * * const task = await getTask({ taskId: 'task_123' }); * * if (task.taskStatus === 'running') { * console.log('任务仍在运行', task.taskDetail); * } * ``` * * @public */ export declare const getTask: (params: GetTaskParams) => Promise; /** * 查询任务的请求参数。 * * @public */ export declare interface GetTaskParams { /** 任务 ID */ taskId: string; } /** * 查询任务的返回结果。 * * @public */ export declare interface GetTaskResult { /** 任务 ID */ taskId: string; /** 任务样式模板,当前仅支持 remote_normal_v1 */ taskTemplate: TaskTemplate; /** 模板对应的数据的 JSON 字符串 */ taskDetail: string; /** 每次更新后旧的 token 失效,必须使用新返回的 token */ token?: string; /** 任务超时过期时间 */ expiresIn?: number; /** 任务状态,运行中或已完成 */ taskStatus: TaskStatus; /** 任务类型,local 或 remote */ taskType: TaskType; } /** * 获取 Wi-Fi 列表。 * * @remarks * 通常先调用 startWifi。 * @example * ```typescript * import { getWifiList, startWifi } from '@doubao-apps/framework/api'; * * await startWifi(); * const { wifiList } = await getWifiList(); * * console.log(wifiList.map((wifi) => wifi.ssid)); * ``` * * @public */ export declare const getWifiList: (params?: {} | undefined) => Promise; /** * 获取 Wi-Fi 列表的返回结果。 * * @public */ export declare interface GetWifiListResult { /** 当前获取到的 Wi-Fi 列表。 */ wifiList: WifiInfo[]; } /** * 获取窗口信息。 * * @returns 返回窗口尺寸、状态栏高度和安全区域等信息,字段见 {@link GetWindowInfoResult}。 * @example * ```typescript * import { getWindowInfo } from '@doubao-apps/framework/api'; * * const result = await getWindowInfo(); * * console.log(result.windowWidth, result.windowHeight); * console.log(result.safeArea?.top, result.screenTop); * ``` * * @public */ export declare const getWindowInfo: (_params?: {}) => Promise; /** @public */ export declare interface GetWindowInfoResult { /** 设备像素比 */ pixelRatio: number; /** 屏幕宽度 */ screenWidth: number; /** 屏幕高度 */ screenHeight: number; /** 可使用窗口宽度 */ windowWidth: number; /** 可使用窗口高度 */ windowHeight: number; /** 状态栏高度 */ statusBarHeight: number; /** 安全区域 */ safeArea?: WindowSafeArea; /** 窗口上边缘的 y 值 */ screenTop: number; } /** * 获取窗口信息。 * * @returns 返回窗口尺寸、状态栏高度和安全区域等信息,字段见 {@link GetWindowInfoResult}。 * @example * ```typescript * import { getWindowInfoSync } from '@doubao-apps/framework/api'; * * const result = getWindowInfoSync(); * * console.log(result.windowWidth, result.windowHeight); * console.log(result.safeArea?.top, result.screenTop); * ``` * * @public */ export declare const getWindowInfoSync: (_param?: {}) => GetWindowInfoResult; /** * 陀螺仪数据变化事件。 * * @public */ export declare interface GyroscopeChangeEvent { /** 绕 X 轴旋转的角速度,单位 rad/s。 */ x: number; /** 绕 Y 轴旋转的角速度,单位 rad/s。 */ y: number; /** 绕 Z 轴旋转的角速度,单位 rad/s。 */ z: number; /** 数据采集时间戳,单位纳秒。 */ timestamp: number; } /** * 陀螺仪数据变化事件监听函数。 * * @public */ export declare type GyroscopeChangeListener = (event: GyroscopeChangeEvent) => void; /** * 隐藏交互提示框的公共参数。 * * @public */ export declare interface HideInteractionParams { } /** * 收起当前键盘。 * * @example * ```typescript * import { hideKeyboard } from '@doubao-apps/framework/api'; * * await hideKeyboard({}); * ``` * @public */ export declare const hideKeyboard: (params?: HideKeyboardParam | undefined) => Promise; /** @public */ export declare interface HideKeyboardParam { } /** * 隐藏当前 loading。 * * @example * ```typescript * import { hideLoading } from '@doubao-apps/framework/api'; * * await hideLoading(); * ``` * * @public */ export declare const hideLoading: (params?: HideInteractionParams | undefined) => Promise; /** * 隐藏当前 Toast。 * * @example * ```typescript * import { hideToast } from '@doubao-apps/framework/api'; * * await hideToast(); * ``` * * @public */ export declare const hideToast: (params?: HideInteractionParams | undefined) => Promise; /** * 图片方向枚举。 * * @public */ declare type ImageOrientation_2 = 'up' | 'up-mirrored' | 'down' | 'down-mirrored' | 'left-mirrored' | 'right' | 'right-mirrored' | 'left'; export { ImageOrientation_2 as ImageOrientation } /** * 内部音频上下文。 * * @remarks * 每次调用 `createInnerAudioContext()` 都会创建一个独立实例。首版支持多实例、 * 基础播控、基础事件和播放失败 `onError`;内部音频默认不接入宿主媒体任务、 * 锁屏信息或通知栏,这些长音频能力请使用 `getBackgroundAudioManager()`。 * * @public */ export declare interface InnerAudioContext { src: string; startTime: number; autoplay: boolean; loop: boolean; volume: number; playbackRate: number; readonly currentTime: number; readonly duration: number; readonly paused: boolean; readonly buffered: number; play(): void; pause(): void; stop(): void; seek(position: number): void; destroy(): void; onCanplay(callback: InnerAudioContextEventCallback): void; offCanplay(callback?: InnerAudioContextEventCallback): void; onPlay(callback: InnerAudioContextEventCallback): void; offPlay(callback?: InnerAudioContextEventCallback): void; onPause(callback: InnerAudioContextEventCallback): void; offPause(callback?: InnerAudioContextEventCallback): void; onStop(callback: InnerAudioContextEventCallback): void; offStop(callback?: InnerAudioContextEventCallback): void; onEnded(callback: InnerAudioContextEventCallback): void; offEnded(callback?: InnerAudioContextEventCallback): void; onTimeUpdate(callback: InnerAudioContextEventCallback): void; offTimeUpdate(callback?: InnerAudioContextEventCallback): void; onError(callback: InnerAudioContextErrorCallback): void; offError(callback?: InnerAudioContextErrorCallback): void; onWaiting(callback: InnerAudioContextEventCallback): void; offWaiting(callback?: InnerAudioContextEventCallback): void; onSeeking(callback: InnerAudioContextEventCallback): void; offSeeking(callback?: InnerAudioContextEventCallback): void; onSeeked(callback: InnerAudioContextEventCallback): void; offSeeked(callback?: InnerAudioContextEventCallback): void; } /** * 内部音频错误事件回调。 * * @public */ export declare type InnerAudioContextErrorCallback = (error: InnerAudioError) => void; /** * 内部音频普通事件回调。 * * @public */ export declare type InnerAudioContextEventCallback = () => void; /** * 内部音频错误信息。 * * @public */ export declare interface InnerAudioError { errCode?: number; errMsg: string; } /** * 查询蓝牙设备是否已经配对。 * * @example * ```typescript * import { isBluetoothDevicePaired } from '@doubao-apps/framework/api'; * * await isBluetoothDevicePaired({ deviceId: 'device-id' }); * ``` * * @public */ export declare const isBluetoothDevicePaired: (params: IsBluetoothDevicePairedParams) => Promise; /** * 查询蓝牙设备配对状态的请求参数。 * * @public */ export declare interface IsBluetoothDevicePairedParams { /** 蓝牙设备 ID。 */ deviceId: string; } /** * 点击任务跳转的页面参数。 * * @public */ export declare interface JumpSchemaData { /** 跳转页面 */ path?: string; /** 页面参数,小程序内消费时会自动 base64 url encode,需要 decode */ query?: string; } /** @public */ export declare interface KeyboardHeightChangeEvent { /** 键盘高度,单位 px。*/ height: number; } /** @public */ export declare type KeyboardHeightChangeListener = (event: KeyboardHeightChangeEvent) => void; /** @public */ export declare interface LocationChangeErrorEvent { /** * 错误信息 */ errMsg: string; /** * 错误码 */ errCode?: number; } /** @public */ export declare type LocationChangeErrorListener = (event: LocationChangeErrorEvent) => void; /** @public */ export declare interface LocationChangeEvent { /** * 纬度 */ latitude: number; /** * 经度 */ longitude: number; /** * 速度,单位 m/s */ speed?: number; /** * 位置精确度,单位 m */ accuracy?: number; /** * 高度,单位 m */ altitude?: number; /** * 垂直精度,单位 m。Android 无法获取时返回 0。 */ verticalAccuracy?: number; /** * 水平精度,单位 m。Android 无法获取时返回 0。 */ horizontalAccuracy?: number; /** * 城市信息 */ city?: string; } /** @public */ export declare type LocationChangeListener = (event: LocationChangeEvent) => void; /** * 获取当前豆包用户的一次性登录凭证。 * * @param params - 登录超时配置。 * @returns 返回包含豆包一次性 `login_code` 的结果。 * @remarks * 前端获取 `code` 后应立即发送给业务服务端,由业务服务端使用应用凭证调用豆包 OpenAPI * 换取 OpenID,并完成业务账号登录或绑定。不要在前端保存长期 Token,也不要把应用密钥下发到前端。 * * 此 `code` 不是业务登录态、MCP AccessToken,也不是传给 `postLoginResult` 的三方短期兑换 code。 * 小程序内的自定义登录态及其与 OpenID 的绑定关系需要由业务方维护,平台不存储三方登录态。 * 用户拒绝登录、登录失败或调用超时时,Promise 将被拒绝。 * @example * ```typescript * import { login } from '@doubao-apps/framework/api'; * * // 业务方自行实现:将一次性 login_code 发送到业务服务端完成登录;该函数不是 SDK API。 * declare function loginOnBusinessServer(loginCode: string): Promise; * * const { code } = await login({ timeout: 30000 }); * await loginOnBusinessServer(code); * ``` * * @public */ export declare const login: (params?: LoginRequest | undefined) => Promise; /** @public */ export declare interface LoginRequest { /** 登录调用的超时时间,单位为毫秒。 */ timeout?: number; } /** @public */ export declare interface LoginResult { /** * 豆包一次性登录凭证 `login_code`。 * * 该凭证用于业务服务端调用豆包 OpenAPI 换取当前用户的 OpenID。 * 凭证有效期为 5 分钟,使用一次或过期后失效。 */ code: string; } /** * Widget 中需要拉起的平台交互类型。 * * - `0`: 仅隐私协议授权 * - `1`: 仅登录交互 * - `2`: 先登录再进行隐私协议授权,两次独立交互 * - `3`: 登录和隐私协议授权合并为一次交互 * * @public */ export declare type LoginType = 0 | 1 | 2 | 3; /** @public */ export declare const LoginType: { /** * 仅拉起隐私协议授权。 */ Privacy: number; /** * 仅拉起登录交互。 */ Login: number; /** * 先登录再进行隐私协议授权,两次独立交互。 */ LoginThenPrivacy: number; /** * 将登录和隐私协议授权合并为一次交互。 */ LoginWithPrivacy: number; }; /** * 在 Widget 中拉起平台登录和隐私协议授权交互。 * * @param params - 需要拉起的登录和隐私协议授权组合。 * @returns 返回所选平台交互是否成功完成。 * @remarks * 此 API 只处理 `loginType` 对应的平台交互,不会返回 `login()` 的一次性 `login_code`, * 也不会替业务方创建小程序登录态或完成 MCP Token 交换。 * * 业务方仍需按实际场景完成服务端账号登录;MCP 授权登录还需在业务服务端生成三方短期兑换 code, * 并通过 `postLoginResult` 回传最终登录结果。 * @example * ```typescript * import { LoginType, loginWithDoubaoWidget } from '@doubao-apps/framework/api'; * * const { result } = await loginWithDoubaoWidget({ * loginType: LoginType.LoginWithPrivacy * }); * * if (!result) { * // 用户未完成登录或隐私协议授权,停止后续登录流程。 * } * ``` * * @public */ export declare const loginWithDoubaoWidget: (params: LoginWithWidgetRequest) => Promise; /** @public */ export declare interface LoginWithWidgetRequest { /** Widget 中需要拉起的平台登录和隐私协议授权组合。 */ loginType: LoginType; } /** @public */ export declare interface LoginWithWidgetResult { /** * 所选平台交互是否成功完成。 * * `true` 仅表示 `loginType` 指定的登录或隐私协议授权交互已完成, * 不代表三方业务账号登录或 MCP 授权已经完成。 */ result: boolean; } /** * 发起蓝牙配对。 * * @example * ```typescript * import { makeBluetoothPair } from '@doubao-apps/framework/api'; * * await makeBluetoothPair({ * deviceId: 'device-id', * pin: '000000', * timeout: 10000 * }); * ``` * * @public */ export declare const makeBluetoothPair: (params: MakeBluetoothPairParams) => Promise; /** * 蓝牙配对请求参数。 * * @public */ export declare interface MakeBluetoothPairParams { /** 蓝牙设备 ID。 */ deviceId: string; /** 配对 PIN 码。 */ pin: string; /** 超时时间,单位毫秒。 */ timeout?: number; } /** * 拨打电话。 * * @example * ```typescript * import { makePhoneCall } from '@doubao-apps/framework/api'; * * await makePhoneCall({ phoneNumber: '13800000000' }); * ``` * * @public */ export declare const makePhoneCall: (params: MakePhoneCallParams) => Promise; /** @public */ export declare interface MakePhoneCallParams { /** 需要拨打的电话号码 */ phoneNumber: string; } /** * 菜单按钮的布局位置信息。 * * @public */ export declare interface MenuButtonBoundingClientRect { /** 宽度,单位 px。 */ width: number; /** 高度,单位 px。 */ height: number; /** 上边界坐标,单位 px。 */ top: number; /** 右边界坐标,单位 px。 */ right: number; /** 下边界坐标,单位 px。 */ bottom: number; /** 左边界坐标,单位 px。 */ left: number; } /** * {@link FileSystemManager.mkdir} 的参数。 * * @public */ export declare interface MkdirParams { /** * 要创建的目录路径。 */ dirPath: string; /** * 是否递归创建该目录的上级目录。 * * 设为 `true` 时,即使中间路径不存在也会一并创建(类似 `mkdir -p`)。 * * @default false */ recursive?: boolean; } /** * 广播多媒体播放或暂停控制。 * * @internal */ export declare const multiMediaBroadcast: (params: MultiMediaBroadcastParams) => Promise; /** @internal */ export declare interface MultiMediaBroadcastParams { /** 多媒体控制动作。 */ action: 'play' | 'pause'; /** 可选媒体元素 ID。 */ mediaId?: string; } /** * 关闭当前页面,返回上一页面或多级页面。 * * @remarks * `navigateBack` 只能在页面栈内返回。若当前页面已经是页面栈中的最后一个页面,则无法继续返回; * 需要退出小程序时请调用 {@link exitApp}。 * * @example * ```typescript * import { navigateBack } from '@doubao-apps/framework/api'; * * await navigateBack({ delta: 1 }); * ``` * * @public */ export declare const navigateBack: (params?: NavigateBackParams) => Promise; /** @public */ export declare interface NavigateBackParams { /** 返回的页面数,如果 delta 大于现有页面数,则返回到页面栈中只剩一个页面为止。 */ delta?: number; } /** * 保留当前页面,跳转到应用内的某个页面。 * * @example * ```typescript * import { navigateTo } from '@doubao-apps/framework/api'; * * await navigateTo({ url: '/pages/detail/index?id=1' }); * ``` * * @public */ export declare const navigateTo: (params: NavigateToParams) => Promise; /** @public */ export declare interface NavigateToParams { /** 跳转的页面的路径,如 'path?key=value&key2=value2' */ url: string; } /** * 网络状态变化事件。 * * @public */ export declare interface NetworkStatusChangeEvent { /** 当前是否有可用网络连接。 */ isConnected: boolean; /** 当前网络类型。 */ networkType: NetworkType; } /** * 网络状态变化事件监听函数。 * * @public */ export declare type NetworkStatusChangeListener = (event: NetworkStatusChangeEvent) => void; /** * 网络类型。 * * - `wifi` - Wi-Fi 网络 * - `2g` - 2G 网络 * - `3g` - 3G 网络 * - `4g` - 4G 网络 * - `5g` - 5G 网络 * - `unknown` - Android 下不常见的网络类型 * - `none` - 无网络 * * @public */ export declare type NetworkType = 'wifi' | '2g' | '3g' | '4g' | '5g' | 'unknown' | 'none'; /** * 订阅 BLE 特征值变化。 * * @remarks * 订阅指定特征值变化。 * @example * ```typescript * import { notifyBLECharacteristicValueChange } from '@doubao-apps/framework/api'; * * await notifyBLECharacteristicValueChange({ * deviceId: 'device-id', * serviceId: 'service-id', * characteristicId: 'characteristic-id', * state: true * }); * ``` * * @public */ export declare const notifyBLECharacteristicValueChange: (params: NotifyBLECharacteristicValueChangeParams) => Promise; /** * 订阅 BLE 特征值变化的请求参数。 * * @public */ export declare interface NotifyBLECharacteristicValueChangeParams { /** 蓝牙设备 ID。 */ deviceId: string; /** 服务 ID。 */ serviceId: string; /** 特征值 ID。 */ characteristicId: string; /** 是否启用订阅。 */ state: boolean; /** 订阅类型。 */ type?: BluetoothNotifyType; } /** * 取消注册地理位置变化回调。 * * @example * ```typescript * import { offLocationChange } from '@doubao-apps/framework/api'; * * offLocationChange(); * ``` * * @public */ export declare function offLocationChange(callback?: LocationChangeListener): void; /** * 取消注册位置更新异常回调。 * * @example * ```typescript * import { offLocationChangeError } from '@doubao-apps/framework/api'; * * offLocationChangeError(); * ``` * * @public */ export declare function offLocationChangeError(callback?: LocationChangeErrorListener): void; /** * 监听加速度数据变化事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onAccelerometerChange } from '@doubao-apps/framework/api'; * * const off = onAccelerometerChange(({ x, y, z, timestamp }) => { * console.log(x, y, z, timestamp); * }); * * off(); * ``` * * @public */ export declare const onAccelerometerChange: ClientEventRegistry; /** * 监听电池信息变化事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onBatteryInfoChange } from '@doubao-apps/framework/api'; * * const off = onBatteryInfoChange(({ isLowPowerModeEnabled }) => { * console.log(isLowPowerModeEnabled); * }); * * off(); * ``` * * @public */ export declare const onBatteryInfoChange: ClientEventRegistry; /** * 注册 BLE 特征值变化回调。 * * @remarks * `readBLECharacteristicValue` 读到的数据和 `notifyBLECharacteristicValueChange` 开启后的通知都会从此事件回传。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```typescript * import { onBLECharacteristicValueChange } from '@doubao-apps/framework/api'; * * const off = onBLECharacteristicValueChange(({ deviceId, value }) => { * console.log(deviceId, value?.byteLength ?? 0); * }); * * off(); * ``` * * @public */ export declare function onBLECharacteristicValueChange(callback: BLECharacteristicValueChangeListener): () => void; /** * 注册 BLE 连接状态变化回调。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```typescript * import { onBLEConnectionStateChange } from '@doubao-apps/framework/api'; * * const off = onBLEConnectionStateChange(({ deviceId, connected }) => { * console.log(deviceId, connected); * }); * * off(); * ``` * * @public */ export declare const onBLEConnectionStateChange: ClientEventRegistry; /** * 注册蓝牙适配器状态变化回调。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```typescript * import { onBluetoothAdapterStateChange } from '@doubao-apps/framework/api'; * * const off = onBluetoothAdapterStateChange(({ available, discovering }) => { * console.log(available, discovering); * }); * * off(); * ``` * * @public */ export declare const onBluetoothAdapterStateChange: ClientEventRegistry; /** * 注册发现蓝牙设备回调。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```typescript * import { onBluetoothDeviceFound } from '@doubao-apps/framework/api'; * * const off = onBluetoothDeviceFound(({ devices }) => { * console.log(devices); * }); * * off(); * ``` * * @public */ export declare function onBluetoothDeviceFound(callback: BluetoothDeviceFoundListener): () => void; /** * 监听罗盘数据变化事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onCompassChange } from '@doubao-apps/framework/api'; * * const off = onCompassChange(({ direction }) => { * console.log(direction); * }); * * off(); * ``` * * @public */ export declare const onCompassChange: ClientEventRegistry; /** * 监听设备方向变化事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onDeviceMotionChange } from '@doubao-apps/framework/api'; * * const off = onDeviceMotionChange(({ alpha, beta, gamma }) => { * console.log(alpha, beta, gamma); * }); * * off(); * ``` * * @public */ export declare const onDeviceMotionChange: ClientEventRegistry; /** * 监听陀螺仪数据变化事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onGyroscopeChange } from '@doubao-apps/framework/api'; * * const off = onGyroscopeChange(({ x, y, z, timestamp }) => { * console.log(x, y, z, timestamp); * }); * * off(); * ``` * * @public */ export declare const onGyroscopeChange: ClientEventRegistry; /** * 监听键盘高度变化事件。 * * @example * ```typescript * import { onKeyboardHeightChange } from '@doubao-apps/framework/api'; * * const unsubscribe = onKeyboardHeightChange(({ height }) => { * console.log('Keyboard height change event:', { height }); * }); * ``` * @public */ export declare const onKeyboardHeightChange: ClientEventRegistry; /** * 注册地理位置变化回调。 * * @example * ```typescript * import { onLocationChange } from '@doubao-apps/framework/api'; * * onLocationChange(({ latitude, longitude }) => { * console.log(latitude, longitude); * }); * ``` * * @public */ export declare function onLocationChange(callback: LocationChangeListener): void; /** * 注册位置更新异常回调。 * * @example * ```typescript * import { onLocationChangeError } from '@doubao-apps/framework/api'; * * onLocationChangeError(({ errMsg, errCode }) => { * console.log(errMsg, errCode); * }); * ``` * * @public */ export declare function onLocationChangeError(callback: LocationChangeErrorListener): void; /** * 监听网络状态变化事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onNetworkStatusChange } from '@doubao-apps/framework/api'; * * const off = onNetworkStatusChange(({ isConnected, networkType }) => { * console.log(isConnected, networkType); * }); * * off(); * ``` * * @public */ export declare const onNetworkStatusChange: ClientEventRegistry; /** * 监听应用主题变化。 * * 当用户在系统设置或宿主内切换浅色、深色主题时触发。回调参数中的 `theme` 表示切换后的主题,可与 * {@link getAppBaseInfo} 返回的 `theme` 字段配合使用。 * * @summary 监听应用主题变化。 * @returns 返回取消当前监听函数的函数。 * @example * ```typescript * import { onThemeChange } from '@doubao-apps/framework/api'; * * const offThemeChange = onThemeChange(({ theme }) => { * console.log('当前主题:', theme); * }); * * offThemeChange(); * ``` * * @public */ export declare function onThemeChange(callback: ThemeChangeListener): () => void; /** * 监听用户主动截屏事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onUserCaptureScreen } from '@doubao-apps/framework/api'; * * const off = onUserCaptureScreen(() => { * console.log('用户截屏了'); * }); * * off(); * ``` * * @public */ export declare const onUserCaptureScreen: ClientEventRegistry; /** * 监听用户录屏事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onUserScreenRecord } from '@doubao-apps/framework/api'; * * const off = onUserScreenRecord(({ state }) => { * console.log(state); * }); * * off(); * ``` * * @public */ export declare const onUserScreenRecord: ClientEventRegistry; /** * 监听连接上 Wi-Fi 的事件。 * * @returns 返回取消当前监听函数的函数。 * * @example * ```ts * import { onWifiConnected } from '@doubao-apps/framework/api'; * * const off = onWifiConnected(({ wifi }) => { * console.log(wifi.ssid); * }); * * off(); * ``` * * @public */ export declare const onWifiConnected: ClientEventRegistry; /** * 通过 deep link 等方式打开外部应用。 * * @param params - 外部应用打开参数。 * @returns 返回外部应用打开结果。 * @example * ```typescript * import { openApp } from '@doubao-apps/framework/api'; * * const { status } = await openApp({ * uri: 'demo://detail?id=1', * fallbackUrl: 'https://example.com/download' * }); * * console.log(status); * ``` * * @public */ export declare const openApp: (params: OpenAppRequest) => Promise; /** @public */ export declare interface OpenAppRequest { /** Target URI to open, e.g. scheme://path?query */ uri: string; /** Optional target package name for Android */ targetPackage?: string; /** Optional fallback URL when deep link fails */ fallbackUrl?: string; } /** @public */ export declare interface OpenAppResult { /** Execution status from client */ status: OpenAppStatus; } /** @public */ export declare type OpenAppStatus = 'deep_link' | 'market' | 'browser'; /** * 打开蓝牙适配器。 * * @remarks * 蓝牙流程入口。 * @example * ```typescript * import { openBluetoothAdapter } from '@doubao-apps/framework/api'; * * await openBluetoothAdapter(); * ``` * * @public */ export declare const openBluetoothAdapter: (params?: {} | undefined) => Promise; /** * 使用地图查看位置。 * * @example * ```typescript * import { openLocation } from '@doubao-apps/framework/api'; * * await openLocation({ * latitude: 39.908823, * longitude: 116.39747, * name: '目的地', * scale: 15 * }); * ``` * * @public */ export declare const openLocation: (params: OpenLocationParams) => Promise; /** @public */ export declare interface OpenLocationParams { /** * 位置名称 */ name?: string; /** * 地址详情 */ address?: string; /** * 缩放比例,范围 5 ~ 18 */ scale?: number; /** * 经度 */ longitude: number; /** * 纬度 */ latitude: number; } /** * 插件账号信息(仅在插件中调用时包含)。 * * @public */ export declare interface PluginAccountInfo { /** 插件 appId */ appId: string; /** 插件版本号,'a.b.c' 形式 */ version: string; } /** * 向豆包回传三方 MCP 授权登录结果。 * * @param params - 三方登录结果,以及登录成功时由业务服务端生成的短期兑换 code。 * @returns 登录结果和凭证回传完成后解析。 * @remarks * 仅在 MCP 授权登录流程中调用此 API。业务服务端应先使用 `login()` 返回的一次性 `login_code` * 换取 OpenID、完成业务账号登录或绑定,再生成用于 OAuth Token 交换的三方短期 code。 * * `result` 为 `true` 时必须传入 `code`。豆包使用该 code 完成 Token 交换后会自动关闭 MCP 登录页。 * 用户拒绝登录或登录失败时,传入 `{ result: false }`,不要继续请求用户数据。 * * MCP AccessToken、RefreshToken 及其生命周期由业务服务端维护,不应下发到前端。 * @example * ```typescript * import { * postLoginResult, * type PostLoginResultRequest * } from '@doubao-apps/framework/api'; * * // 业务方自行实现:完成业务登录并生成三方短期兑换 code;该函数不是 SDK API。 * declare function getMcpLoginResultFromBusinessServer(): Promise; * * const loginResult = await getMcpLoginResultFromBusinessServer(); * await postLoginResult(loginResult); * ``` * * @public */ export declare const postLoginResult: (params: PostLoginResultRequest) => Promise; /** @public */ export declare interface PostLoginResultRequest { /** * 三方登录是否成功。 * * `true` 表示三方已完成业务账号登录,并提供了可供豆包兑换 MCP Token 的短期 code; * `false` 表示用户拒绝登录或登录失败。 */ result: boolean; /** * 三方短期兑换 code,仅在 `result` 为 `true` 时有效且必填。 * * 该字段必须由业务服务端生成。豆包服务端会使用它调用业务方配置的 OAuth Token endpoint, * 换取三方颁发的 MCP AccessToken 和 RefreshToken。 * * 不要传入 `login()` 返回的豆包 `login_code`,也不要直接传入 AccessToken 或 RefreshToken。 */ code?: string; } /** * 预览图片。 * * @example * ```typescript * import { previewImage } from '@doubao-apps/framework/api'; * * await previewImage({ * urls: ['https://example.com/a.png', 'https://example.com/b.png'], * current: 0 * }); * ``` * * @public */ export declare const previewImage: (params: PreviewImageParams) => Promise; /** * 预览图片的请求参数。 * * @public */ export declare interface PreviewImageParams { /** 需要预览的图片链接列表。 */ urls: string[]; /** 当前显示图片的链接,或当前显示图片的下标,不填则默认为 urls 中的第一张 */ current?: string | number; /** 是否显示长按菜单,菜单支持保存图片至本地相册 */ showmenu?: boolean; /** 预览页使用的 Referrer 策略。 */ referrerPolicy?: string; } /** * 预览图片和视频的请求参数。 * * @public */ export declare interface PreviewMediaParams { /** 需要预览的资源列表。 */ sources: PreviewMediaSource[]; /** 当前显示资源的下标。 */ current?: number; /** 是否显示长按菜单。 */ showmenu?: boolean; /** 预览页使用的 Referrer 策略。 */ referrerPolicy?: string; } /** * 预览媒体资源项。 * * @public */ export declare interface PreviewMediaSource { /** 图片或视频的地址。 */ url: string; /** 资源类型。 */ type?: 'image' | 'video'; /** 视频封面图地址。 */ poster?: string; } /** @public */ export declare interface PrivacySettingResult { /** Whether user authorization for privacy agreement is required */ needAuthorization: boolean; } /** * 读取 BLE 特征值。 * * @remarks * 需要传入 serviceId 和 characteristicId。 * @example * ```typescript * import { readBLECharacteristicValue } from '@doubao-apps/framework/api'; * * await readBLECharacteristicValue({ * deviceId: 'device-id', * serviceId: 'service-id', * characteristicId: 'characteristic-id' * }); * ``` * * @public */ export declare const readBLECharacteristicValue: (params: ReadBLECharacteristicValueParams) => Promise; /** * 读取 BLE 特征值的请求参数。 * * @public */ export declare interface ReadBLECharacteristicValueParams { /** 蓝牙设备 ID。 */ deviceId: string; /** 服务 ID。 */ serviceId: string; /** 特征值 ID。 */ characteristicId: string; } /** * {@link FileSystemManager.readdir} 的参数。 * * @public */ export declare interface ReaddirParams { /** * 要读取的目录路径。 */ dirPath: string; } /** * {@link FileSystemManager.readdir} 的返回结果。 * * @public */ export declare interface ReaddirResult { /** * 目录下的文件和子目录名称列表(不含 `.` 和 `..`)。 */ files: string[]; } /** * {@link FileSystemManager.readFile} 的参数。 * * @public */ export declare interface ReadFileParams { /** * 要读取的文件路径(本地路径)。 */ filePath: string; /** * 指定读取文件的字符编码。 * * - `'utf-8'`:以 UTF-8 字符串形式返回文件内容。 * - `'base64'`:以 Base64 编码字符串形式返回文件内容,适用于二进制文件。 * * @default 'utf-8' */ encoding?: 'utf-8' | 'base64'; } /** * {@link FileSystemManager.readFile} 的返回结果。 * * @public */ export declare interface ReadFileResult { /** * 文件内容。 * * 具体格式由 {@link ReadFileParams.encoding} 决定: * - 编码为 `'utf-8'` 时返回 UTF-8 字符串; * - 编码为 `'base64'` 时返回 Base64 编码后的字符串。 */ data: string; } /** * 录音格式。 * @public */ export declare type RecorderFormat = 'aac' | 'pcm' | 'wav'; /** * 全局唯一的录音管理器。通过 {@link getRecorderManager} 获取实例。 * @public */ export declare interface RecorderManager { /** 开始录音。 */ start(options?: RecorderManagerStartOptions): void; /** 暂停录音。 */ pause(): void; /** 恢复录音。 */ resume(): void; /** 停止录音。 */ stop(): void; /** 监听录音开始事件。 */ onStart(callback: RecorderManagerStateCallback): void; /** 取消监听录音开始事件。 */ offStart(callback?: RecorderManagerStateCallback): void; /** 监听录音暂停事件。 */ onPause(callback: RecorderManagerStateCallback): void; /** 取消监听录音暂停事件。 */ offPause(callback?: RecorderManagerStateCallback): void; /** 监听录音恢复事件。 */ onResume(callback: RecorderManagerStateCallback): void; /** 取消监听录音恢复事件。 */ offResume(callback?: RecorderManagerStateCallback): void; /** 监听录音停止事件,停止后可获取临时文件路径。 */ onStop(callback: RecorderManagerStopCallback): void; /** 取消监听录音停止事件。 */ offStop(callback?: RecorderManagerStopCallback): void; /** 监听录音错误事件。 */ onError(callback: RecorderManagerErrorCallback): void; /** 取消监听录音错误事件。 */ offError(callback?: RecorderManagerErrorCallback): void; /** 监听已录制完指定帧大小的文件事件(需在 start 时设置 frameSize)。 */ onFrameRecorded(callback: RecorderManagerFrameRecordedCallback): void; /** 取消监听录音分片事件。 */ offFrameRecorded(callback?: RecorderManagerFrameRecordedCallback): void; } export declare type RecorderManagerErrorCallback = (event: RecorderManagerErrorEvent) => void; /** * 录音错误事件数据。 * @public */ export declare interface RecorderManagerErrorEvent { /** 错误信息。 */ errMsg: string; } export declare type RecorderManagerFrameRecordedCallback = (event: RecorderManagerFrameRecordedEvent) => void; /** * 录音分片事件数据。 * @public */ export declare interface RecorderManagerFrameRecordedEvent { /** 当前帧数据,ArrayBuffer 类型。 */ frameBuffer: ArrayBuffer; /** 是否为最后一帧。 */ isLastFrame: boolean; } /** * 开始录音的配置参数。 * @public */ export declare interface RecorderManagerStartOptions { /** 录音时长,单位 ms,最大值 600000,默认 60000。 */ duration?: number; /** 录音格式,默认 aac。 */ format?: RecorderFormat; /** 采样率,默认 44100。 */ sampleRate?: RecorderSampleRate; /** 录音通道数,默认 2。 */ numberOfChannels?: RecorderNumberOfChannels; /** 编码码率,单位 bps,默认 128000。 */ encodeBitRate?: number; /** 帧大小,单位 KB。设置后通过 onFrameRecorded 回调分片内容。 */ frameSize?: number; } export declare type RecorderManagerStateCallback = () => void; export declare type RecorderManagerStopCallback = (event: RecorderManagerStopEvent) => void; /** * 录音停止事件数据。 * @public */ export declare interface RecorderManagerStopEvent { /** 录音文件的临时路径。 */ tempFilePath: string; /** 录音时长,单位 ms。 */ duration: number; /** 录音文件大小,单位 B。 */ fileSize: number; } /** * 录音通道数。 * @public */ export declare type RecorderNumberOfChannels = 1 | 2; /** * 录音采样率。 * @public */ export declare type RecorderSampleRate = 8000 | 11025 | 12000 | 16000 | 22050 | 24000 | 32000 | 44100 | 48000; /** * 关闭当前页面,跳转到应用内的某个页面。 * * @example * ```typescript * import { redirectTo } from '@doubao-apps/framework/api'; * * await redirectTo({ url: '/pages/result/index' }); * ``` * * @public */ export declare const redirectTo: (params: NavigateToParams) => Promise; /** * 关闭所有页面并跳转到应用内页面。 * * @example * ```typescript * import { reLaunch } from '@doubao-apps/framework/api'; * * await reLaunch({ url: '/pages/home/index' }); * ``` * * @public */ export declare const reLaunch: (params: NavigateToParams) => Promise; /** * remote_normal_v1 模板对应的数据。 * * @public */ export declare interface RemoteNormalV1Detail { /** 任务过期时间,单位:秒。任务创建后经过该时间将自动过期 */ expire_in_sec: number; /** 任务展示数据 */ display_data: TaskDisplayData; /** 点击任务跳转的页面参数 */ jump_page_data?: JumpSchemaData; /** 移除任务时的操作参数 */ remove_data?: TaskActionParams; /** 任务进度数据 */ progress_data?: TaskProgressData; } /** * {@link FileSystemManager.removeSavedFile} 的参数。 * * @remarks * - 该接口用于删除通过 {@link FileSystemManager.saveFile} 保存的本地文件。 * - 对非已保存文件调用该接口可能会失败。 * * @public */ export declare interface RemoveSavedFileParams { /** * 需要删除的已保存文件路径(应为 {@link SaveFileResult.savedFilePath} 返回的路径)。 */ filePath: string; } /** * 删除本地缓存中指定 key 的数据。 * * @param params 删除参数,字段见 {@link RemoveStorageParams}。 * @returns 返回一个 Promise,删除完成后 resolve。 * @example * ```typescript * import { removeStorage } from '@doubao-apps/framework/api'; * * await removeStorage({ key: 'profile' }); * ``` * * @public */ export declare const removeStorage: (params: RemoveStorageParams) => Promise; /** @public */ export declare interface RemoveStorageParams { /** 本地缓存键名 */ key: string; } /** * 删除本地缓存中指定 key 的数据。 * * @param params 删除参数,字段见 {@link RemoveStorageParams}。 * @returns 同步删除完成后返回。 * @example * ```typescript * import { removeStorageSync } from '@doubao-apps/framework/api'; * * removeStorageSync({ key: 'profile' }); * ``` * * @public */ export declare const removeStorageSync: (params?: RemoveStorageParams | undefined) => object; /** * {@link FileSystemManager.rename} 的参数。 * * @remarks * - 可用于重命名文件或将文件移动到同一文件系统中的其他路径。 * - 如果目标路径已存在同名文件,行为取决于宿主实现(通常会覆盖)。 * * @public */ export declare interface RenameParams { /** * 源文件路径(即当前文件路径)。 */ oldPath: string; /** * 新文件路径(即重命名或移动后的目标路径)。 */ newPath: string; } /** * 上报数据分析事件。 * * @param params - 数据分析事件上报参数。 * @returns 返回一个 Promise,在事件上报请求成功发起时解析。 * @example * ```typescript * import { reportEvent } from '@doubao-apps/framework/api'; * * await reportEvent({ * eventName: 'page_view', * data: { * pageName: 'home', * source: 'feed' * } * }); * ``` * * @public */ export declare const reportEvent: (params: ReportEventParams) => Promise; /** * 上报数据分析事件的请求参数。 * * @public */ export declare interface ReportEventParams { /** 事件名称。 */ eventName: string; /** 事件参数,会作为事件属性一并上报。 */ data: Record; } /** * 发起网络请求。 * * `request` 本身不接受泛型参数;如需业务数据类型,请读取 `result.data` 后再做类型收窄或断言。 * * @summary 发起网络请求。 * @param params 请求参数,字段见 {@link RequestParams}。 * @returns 返回一个 Promise,解析为 {@link RequestResponse}。 * @remarks * 返回 statusCode、header 和 data。 * @example * ```typescript * import { request } from '@doubao-apps/framework/api'; * * const result = await request({ * url: 'https://postman-echo.com/post', * method: 'POST', * dataType: 'json', * header: { 'content-type': 'application/json' }, * data: { hello: 'world' } * }); * * console.log(result.statusCode, result.data); * ``` * * @public */ export declare const request: (params: RequestParams) => Promise; /** * 请求创建合单订单。 * * @param params - 业务服务端返回的合单预下单参数和签名。 * @returns 返回一个 Promise,解析为合单订单结果。 * @remarks * `data` 的结构和签名方式以合单能力对应的服务端接入协议为准。 * 这些参数必须由业务服务端生成,不能直接复用普通预下单参数,也不能在前端自行构造。 * @example * ```typescript * import { * requestCombineOrder, * type RequestCombineOrderParams * } from '@doubao-apps/framework/api'; * * // 业务方自行实现:从业务服务端获取合单预下单参数和签名;该函数不是 SDK API。 * declare function getCombineOrderParamsFromBusinessServer(): * Promise; * * const orderParams = await getCombineOrderParamsFromBusinessServer(); * const result = await requestCombineOrder(orderParams); * * console.log(result); * ``` * * @public */ export declare const requestCombineOrder: (params: RequestCombineOrderParams) => Promise; /** @public */ export declare interface RequestCombineOrderFailResult { /** 错误码。 */ errNo: string; /** 错误信息。 */ errMsg: string; /** 用于服务端排查问题的错误日志 ID。 */ errLogId?: string; } /** @public */ export declare interface RequestCombineOrderParams { /** * 合单预下单请求数据。 * * 该字段必须由业务服务端按合单接入协议生成并返回,前端应原样透传。 * 不要参照普通预下单的 `data` 结构在客户端自行拼装。 */ data: string; /** * `data` 对应的请求签名。 * * 该字段必须由业务服务端生成并返回,前端应原样透传。 */ dbAuthorization: string; } /** @public */ export declare type RequestCombineOrderResult = RequestCombineOrderSuccessResult | RequestCombineOrderFailResult; /** @public */ export declare interface RequestCombineOrderSuccessResult { /** 平台返回的合单订单号。 */ combineOrderId: string; /** 用于服务端排查问题的日志 ID。 */ logId: string; } /** @public */ export declare type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'CONNECT'; /** * 交易预下单,获取拉起收银台所需的平台交易订单号。 * * @param params - 业务服务端返回的预下单参数和签名。 * @returns 返回交易预下单结果。 * @remarks * 调用前,前端应先请求业务服务端,由业务服务端构造下单参数并完成签名。 * 不要在前端生成 `data` 或 `dbAuthorization`,也不要把证书或私钥下发到前端。 * * 使用 `DoubaoPaymentButton` 时,应在组件请求订单号的回调中获取或创建预下单, * 再将本 API 返回的 `orderId` 交给组件继续普通支付或平台免密支付流程。 * @example * ```typescript * import { * requestOrder, * type RequestOrderParams * } from '@doubao-apps/framework/api'; * * // 业务方自行实现:从业务服务端获取预下单参数和签名;该函数不是 SDK API。 * declare function getOrderParamsFromBusinessServer(): Promise; * * const orderParams = await getOrderParamsFromBusinessServer(); * const { orderId, logId } = await requestOrder(orderParams); * * console.log(orderId, logId); * ``` * * @public */ export declare const requestOrder: (params: RequestOrderParams) => Promise; /** @public */ export declare interface RequestOrderParams { /** * 下单参数 JSON 字符串。 * * 该字段必须由业务服务端按支付接入协议构造并返回,前端应原样透传,不要在客户端自行拼装。 * JSON 必填字段包括 `skuList`、`outOrderNo`、`merchantUid`、`totalAmount`、`orderName` 和 * `orderDesc`;可选字段包括 `currency`、`payExpireSeconds` 和 `payNotifyUrl`。 * * `skuList` 每项必填 `skuId`、`price`、`quantity`、`title` 和 `totalAmount`。 * 金额单位由 `currency` 决定;当前 `CNY` 使用分。`outOrderNo` 不超过 64 字节, * `quantity` 取值范围为 1 到 100,`title` 不超过 256 字节。 * `payExpireSeconds` 不传或传 0 时使用 300 秒,最长不超过 48 小时; * `payNotifyUrl` 必须是 HTTPS 地址。 */ data: string; /** * `data` 对应的请求签名。 * * 该字段必须由业务服务端使用已配置的证书生成并返回,前端应原样透传。 */ dbAuthorization: string; } /** @public */ export declare interface RequestOrderResult { /** 平台交易订单号,用于调用 `getOrderPayment` 拉起收银台。 */ orderId: string; /** 用于服务端排查问题的日志 ID。 */ logId: string; } /** * 网络请求参数。 * * @public */ export declare interface RequestParams { /** * 请求地址,需为完整的 **HTTPS** URL。 */ url: string; /** * 请求 Header。 * * @default {"content-type": "application/json"} */ header?: Record; /** * 请求方法。 * * @default "GET" */ method?: RequestMethod; /** * 请求体数据。 * * 传给服务器的数据最终会是 `String` 或 `ArrayBuffer`: * - 若 `data` 是 `string` 或 `ArrayBuffer`,直接使用; * - 若 `header['content-type']` 是 `application/x-www-form-urlencoded`,会被编码为 query string,例如:`encodeURIComponent(k)=encodeURIComponent(v)`; * - 若 `header['content-type']` 是 `application/json`,会执行 JSON 序列化; * - 若 `data` 是普通对象且未命中上述类型,也会执行 JSON 序列化; * - 其他类型会调用 `toString()` */ data?: Record | string | ArrayBuffer; /** * 期望返回的数据格式。 * - `json`: 尝试按 JSON 解析; * - `string`: 按字符串返回。 * - `arraybuffer`: 按二进制数据返回。 * * @default "json" */ dataType?: 'json' | 'string' | 'arraybuffer'; } /** * 网络请求返回结果。 * * @public */ export declare interface RequestResponse { /** HTTP 状态码。 */ statusCode: number; /** HTTP 响应头。 */ header: Record; /** 响应数据,类型由 `dataType` 决定。 */ data?: string | ArrayBuffer | Record; } /** * {@link FileSystemManager.rmdir} 的参数。 * * @public */ export declare interface RmdirParams { /** * 要删除的目录路径。 */ dirPath: string; /** * 是否递归删除目录下的所有子文件和子目录。 * * 设为 `false` 时,仅当目录为空才能删除成功;设为 `true` 时会递归删除所有内容。 * * @default false */ recursive?: boolean; } /** * {@link FileSystemManager.saveFile} 的参数。 * * @remarks * - 该接口用于将临时文件保存到本地持久化存储。临时文件在应用退出后可能被系统清理, * 通过 `saveFile` 保存后的文件将不会被自动清理。 * - 保存成功后原临时文件会被移除。 * * @public */ export declare interface SaveFileParams { /** * 临时文件路径(需先通过下载或其他方式获得的临时文件路径)。 */ tempFilePath: string; /** * 保存到的目标文件路径。 * * 若不指定,则由宿主决定存储位置并通过 {@link SaveFileResult.savedFilePath} 返回。 */ filePath?: string; } /** * {@link FileSystemManager.saveFile} 的返回结果。 * * @public */ export declare interface SaveFileResult { /** * 文件保存后的实际存储路径。 */ savedFilePath: string; } /** * 保存图片到系统相册。 * * 需要先确保应用已具备写入系统相册的权限。 * * @summary 保存图片到系统相册。 * @example * ```typescript * import { saveImageToPhotosAlbum } from '@doubao-apps/framework/api'; * * await saveImageToPhotosAlbum({ * filePath: '/path/to/image.png' * }); * ``` * * @public */ export declare const saveImageToPhotosAlbum: (params: SaveImageToPhotosAlbumParams) => Promise; /** * 保存图片到系统相册的请求参数。 * * @public */ export declare interface SaveImageToPhotosAlbumParams { /** 需要保存的图片文件路径。支持临时文件路径或持久文件路径,不支持网络图片路径。 */ filePath: string; } /** * 调起扫码能力。 * * @example * ```typescript * import { scanCode } from '@doubao-apps/framework/api'; * * const { result, scanType } = await scanCode({ * onlyFromCamera: true, * scanType: ['qrCode'] * }); * * console.log(result, scanType); * ``` * * @public */ export declare const scanCode: (params?: ScanCodeParams | undefined) => Promise; /** * 扫码请求参数。 * * @public */ export declare interface ScanCodeParams { /** 是否仅允许从相机扫码。 */ onlyFromCamera?: boolean; /** 允许的扫码类型。 */ scanType?: ScanCodeType[]; } /** * 扫码返回结果。 * * @public */ export declare interface ScanCodeResult { /** 字符集。 */ characterSet: string; /** 当前宿主可识别的页面路径。 */ path: string; /** 原始数据,通常为 Base64 字符串。 */ rawData: string; /** 扫码结果文本。 */ result: string; /** 扫码结果类型。 */ scanType: ScanResultType; } /** * 扫码类型。 * * @public */ export declare type ScanCodeType = 'barCode' | 'qrCode' | 'datamatrix' | 'pdf417'; /** * 扫码结果类型。 * * @public */ export declare type ScanResultType = 'QR_CODE' | 'AZTEC' | 'CODABAR' | 'CODE_39' | 'CODE_93' | 'CODE_128' | 'DATA_MATRIX' | 'EAN_8' | 'EAN_13' | 'ITF' | 'MAXICODE' | 'PDF_417' | 'RSS_14' | 'RSS_EXPANDED' | 'UPC_A' | 'UPC_E' | 'UPC_EAN_EXTENSION' | 'WX_CODE' | 'CODE_25'; /** @public */ export declare type Scope = 'scope.userLocation' | 'scope.userFuzzyLocation' | 'scope.userLocationBackground' | 'scope.payment' | 'scope.record' | 'scope.bluetooth' | 'scope.camera' | 'scope.addPhoneContact' | 'scope.addPhoneCalendar'; /** * 选择消息文件后返回的文件类型。 * * @public */ export declare type SelectedMessageFileType = 'video' | 'image' | 'file'; /** * 以用户身份发送后续消息,触发新一轮对话或 API 调用。 * * @param params - 要发送的后续消息内容。 * @returns 返回一个 Promise,在消息发送成功时解析。 * @remarks * 可在 Widget、小程序页面或 Worker 中调用。宿主会根据调用上下文关联会话:Widget 使用其所在 * 会话,从 Widget 打开的页面沿用该会话,其他页面和 Worker 使用主会话。 * * @example * ```typescript * import { sendFollowUpMessage } from '@doubao-apps/framework/api'; * * await sendFollowUpMessage({ * content: [ * { type: 'text', text: '选择拿铁' }, * { * type: 'api/call', * data: { * name: 'selectDrink', * arguments: { drinkId: 'latte_001' } * } * } * ] * }); * ``` * * @public */ export declare const sendFollowUpMessage: (params: SendFollowUpMessageParams) => Promise; /** * 发送后续消息的请求参数。 * * @public */ export declare interface SendFollowUpMessageParams { /** 消息内容。 */ content: Content[]; } /** * 以用户身份发送一条消息 * * 由于会自动获取页面上下文来确定向哪个 bot 发送消息,因此只能在卡片或页面中调用 * * @deprecated 使用 {@link dispatchActionDirective} 描述用户行为并约束模型后续动作。 * @summary 以用户身份发送消息。 * @example * ```typescript * import { sendQueryMessage } from '@doubao-apps/framework/api'; * * await sendQueryMessage({ * type: 'text', * content: '继续完成订阅流程' * }); * ``` * * @public */ export declare const sendQueryMessage: (params: SendQueryMessageParams) => Promise; /** @public */ export declare interface SendQueryMessageParams { /** 要发送的消息。根据类型不同,序列化方式可能不同 */ content: string; /** 消息类型,目前仅支持 text */ type: 'text'; } /** * 拉起系统短信发送面板。 * * @returns 返回一个 Promise,在成功拉起短信发送面板时解析。 * @example * ```typescript * import { sendSms } from '@doubao-apps/framework/api'; * * await sendSms({ * phoneNumber: '10086', * message: '查询话费' * }); * ``` * * @public */ export declare const sendSms: (params?: SendSmsParams | undefined) => Promise; /** * 拉起系统短信发送面板的请求参数。 * * @public */ export declare interface SendSmsParams { /** 预填到发送短信面板的手机号。 */ phoneNumber?: string; /** 预填到发送短信面板的内容。 */ message?: string; } /** * 传感器监听频率。 * * @public */ export declare type SensorInterval = 'game' | 'ui' | 'normal'; /** * 设置全局上下文供大模型理解 * * @deprecated 使用 {@link updateModelContext} 捐赠模型上下文。 * @remarks * 该 API 仅保留兼容旧业务。新业务请使用 `updateModelContext`,按任务或实体维度补充上下文。 * @example * ```typescript * import { setAdditionalContext } from '@doubao-apps/framework/api'; * * await setAdditionalContext({ * additionalContext: '用户正在查看订单详情页', * botId: 'bot-id' * }); * ``` * @public */ export declare const setAdditionalContext: (params: SetAdditionalContextParams) => Promise; /** @public */ export declare interface SetAdditionalContextParams { /** 上下文内容 */ additionalContext: string; /** 指定 bot id */ botId?: string; } /** * 设置 BLE MTU。 * * @example * ```typescript * import { setBLEMTU } from '@doubao-apps/framework/api'; * * const { mtu } = await setBLEMTU({ * deviceId: 'device-id', * mtu: 512 * }); * * console.log(mtu); * ``` * * @public */ export declare const setBLEMTU: (params: SetBLEMTUParams) => Promise; /** * 设置 BLE MTU 的请求参数。 * * @public */ export declare interface SetBLEMTUParams { /** 蓝牙设备 ID。 */ deviceId: string; /** 目标 MTU。 */ mtu: number; } /** * 设置 BLE MTU 的返回结果。 * * @public */ export declare interface SetBLEMTUResult { /** 最终协商得到的 MTU。 */ mtu: number; } /** * 设置系统剪贴板内容。 * * @example * ```typescript * import { setClipboardData } from '@doubao-apps/framework/api'; * * await setClipboardData({ data: '复制内容' }); * ``` * * @public */ export declare const setClipboardData: (params: SetClipboardDataParams) => Promise; /** @public */ export declare interface SetClipboardDataParams { /** 需要设置的剪贴板内容 */ data: string; } /** * 设置屏幕常亮状态。 * * @example * ```typescript * import { setKeepScreenOn } from '@doubao-apps/framework/api'; * * await setKeepScreenOn({ keepScreenOn: true }); * ``` * * @public */ export declare const setKeepScreenOn: (params: SetKeepScreenOnParams) => Promise; /** * 设置屏幕常亮的请求参数。 * * @public */ export declare interface SetKeepScreenOnParams { /** 是否保持屏幕常亮。 */ keepScreenOn: boolean; } /** * 设置屏幕亮度。 * * @example * ```typescript * import { setScreenBrightness } from '@doubao-apps/framework/api'; * * await setScreenBrightness({ value: 0.8 }); * ``` * * @public */ export declare const setScreenBrightness: (params: SetScreenBrightnessParams) => Promise; /** * 设置屏幕亮度的请求参数。 * * @public */ export declare interface SetScreenBrightnessParams { /** 屏幕亮度值,范围 0 ~ 1。 */ value: number; } /** * 将数据写入本地缓存。 * * @param params 存储参数,字段见 {@link SetStorageParams}。 * @returns 返回一个 Promise,写入完成后 resolve。 * @remarks * @example * ```typescript * import { setStorage } from '@doubao-apps/framework/api'; * * await setStorage({ * key: 'profile', * data: { name: 'Tom', age: 18 }, * }); * ``` * * @public */ export declare function setStorage(params: SetStorageParams): Promise; /** @public */ export declare interface SetStorageParams { /** 本地缓存键名 */ key: string; /** 待存储的数据 */ data: TData; } /** * 将数据写入本地缓存。 * * @param params 存储参数,字段见 {@link SetStorageParams}。 * @returns 同步写入完成后返回。 * @remarks * @example * ```typescript * import { setStorageSync } from '@doubao-apps/framework/api'; * * setStorageSync({ * key: 'profile', * data: { name: 'Tom', age: 18 }, * }); * ``` * * @public */ export declare function setStorageSync(params: SetStorageParams): object; /** * 设置截屏或录屏时的视觉表现。 * * @remarks * 控制截屏或录屏时的视觉效果。 * @example * ```typescript * import { setVisualEffectOnCapture } from '@doubao-apps/framework/api'; * * await setVisualEffectOnCapture({ visualEffect: 'hidden' }); * ``` * * @public */ export declare const setVisualEffectOnCapture: (params?: SetVisualEffectOnCaptureParams | undefined) => Promise; /** * 设置截屏或录屏视觉效果的请求参数。 * * @public */ export declare interface SetVisualEffectOnCaptureParams { /** 截屏或录屏时的视觉表现。 */ visualEffect?: CaptureVisualEffect; } /** * 设置 Wi-Fi 预设列表(iOS 特有)。 * * @remarks * 该接口为 iOS 特有,用于预设 Wi-Fi 列表。 * @example * ```typescript * import { setWifiList } from '@doubao-apps/framework/api'; * * await setWifiList({ * wifiList: [{ ssid: 'Office-WiFi', password: 'password' }] * }); * ``` * * @public */ export declare const setWifiList: (params: SetWifiListParams) => Promise; /** * 设置 Wi-Fi 预设列表的请求参数(iOS 特有)。 * * @public */ export declare interface SetWifiListParams { /** 预设的 Wi-Fi 列表。 */ wifiList: WifiListItem[]; } /** * 显示操作菜单。 * * @example * ```ts * import { showActionSheet } from '@doubao-apps/framework/api'; * * const result = await showActionSheet({ * itemList: ['编辑', '删除'] * }); * * console.log(result.tapIndex); * ``` * * @public */ export declare const showActionSheet: (params: ShowActionSheetParams) => Promise; /** * 显示操作菜单的参数。 * * @public */ export declare interface ShowActionSheetParams { /** 标题 */ title?: string; /** 按钮文字数组。 */ itemList: string[]; /** 按钮文字颜色。 */ itemColor?: string; } /** * 显示操作菜单的返回结果。 * * @public */ export declare interface ShowActionSheetResult { /** 用户点击的按钮序号,从 0 开始。 */ tapIndex: number; } /** * 显示 Native 底部弹窗。 * * @remarks * `content` 接收受限 HTML 字符串,当前支持段落、加粗和链接,Native 会拦截危险标签、事件属性和危险链接协议。 * 链接点击由 Native 打开 H5,不会关闭弹窗。 * Promise 在用户点击按钮或点击蒙层关闭后 resolve。 * * @example * ```ts * import { showBottomSheet } from '@doubao-apps/framework/api'; * * const result = await showBottomSheet({ * title: '隐私协议提示', * content: * '

感谢您使用当前小程序。

详情请见《小程序服务条款》

', * buttons: [ * { role: 'agreeMain', text: '同意并继续' }, * { role: 'reject', text: '暂不同意' } * ] * }); * * if (result.action === 'buttonClick') { * console.log(result.role); * } * ``` * * @public */ export declare const showBottomSheet: (params: ShowBottomSheetParams) => Promise; /** * 显示底部弹窗的参数。 * * @public */ export declare interface ShowBottomSheetParams { /** 弹窗标题。 */ title: string; /** 受限 HTML 字符串,支持段落、加粗和链接。 */ content: string; /** 按钮配置,支持 1-3 个,展示顺序与数组顺序一致,按钮语义不可重复。 */ buttons: BottomSheetButtons; /** 弹窗行为配置。 */ behavior?: BottomSheetBehavior; } /** * 显示底部弹窗的返回结果。 * * @public */ export declare type ShowBottomSheetResult = BottomSheetButtonClickResult | BottomSheetCancelResult; /** * 显示 loading 提示框。 * * @remarks * 需调用 hideLoading 关闭。 * @example * ```typescript * import { hideLoading, showLoading } from '@doubao-apps/framework/api'; * * await showLoading(); * await hideLoading(); * ``` * * @public */ export declare const showLoading: (params?: ShowLoadingParams | undefined) => Promise; /** * 显示 loading 提示框的参数。 * * @public */ export declare interface ShowLoadingParams { } /** * 显示模态对话框。 * * @example * ```ts * import { showModal } from '@doubao-apps/framework/api'; * * const result = await showModal({ * title: '提示', * content: '确认删除这条记录吗?', * confirmText: '删除', * cancelText: '取消' * }); * * if (result.action === 'confirm') { * console.log('用户确认删除'); * } * ``` * * @public */ export declare const showModal: (params: ShowModalParams) => Promise; /** * 显示模态对话框的参数。 * * @public */ export declare interface ShowModalParams { /** 模态对话框的标题。 */ title?: string; /** 模态对话框的内容。 */ content: string; /** 是否显示取消按钮,默认 `true`。 */ showCancel?: boolean; /** 取消按钮的文字。 */ cancelText?: string; /** 确认按钮的文字。 */ confirmText?: string; /** 是否允许点击蒙层关闭对话框,默认 `false`。 */ tapMaskToDismiss?: boolean; } /** * 显示模态对话框的返回结果。 * * @public */ export declare interface ShowModalResult { /** 用户点击的动作。 */ action: 'confirm' | 'cancel' | 'mask'; } /** * 显示 Toast 提示。 * * 参数 `options` 包含以下字段: * - `message`: 提示的内容。 * - `type`: Toast 的类型,可选值为 'default'、'success'、'error' 或 'warning'。 * - `duration`: 提示的延迟时间,单位毫秒,默认为 2000。 * - `icon`: 图标,可选值为 'success', 'error', 'warn'。 * - `customIcon`: 自定义图标的 URL 或 base64 字符串。 * * @summary 显示 Toast 提示。 * @returns 返回一个 Promise,在 Toast 显示结束时 resolve。 * @remarks * duration 和 icon 可控制提示表现。 * @example * ```typescript * import { showToast } from '@doubao-apps/framework/api'; * * // 显示一个成功的 Toast * showToast({ * message: '操作成功', * type: 'success', * icon: 'success', * duration: 1500 * }).then(() => { * console.log('Toast 显示完毕'); * }); * * // 显示一个错误的 Toast * showToast({ * message: '网络错误', * type: 'error', * icon: 'error' * }); * ``` * * @public * */ export declare const showToast: (params: ShowToastParams) => Promise; /** @public */ export declare interface ShowToastParams { message: string; type?: 'default' | 'success' | 'error' | 'warning'; duration?: number; icon?: 'success' | 'error' | 'warn'; customIcon?: string; } /** * 使用三方纯签约的签约单号拉起用户签约页面。 * * @param params - `createSignOrder` 返回的平台签约订单号。 * @returns 签约页面流程正常返回时解析为空对象;该结果不代表签约成功。 * @remarks * 如果用户尚未绑定抖音账号,宿主可能先拉起账号绑定流程,再继续展示签约页面。 * * 用户的最终签约状态必须以业务服务端查询签约单详情或收到的签约结果回调为准。 * 业务服务端还需要维护业务用户与签约 ID 的对应关系。 * @example * ```typescript * import { * createSignOrder, * sign, * type CreateSignOrderParams * } from '@doubao-apps/framework/api'; * * // 业务方自行实现:从业务服务端获取签约订单参数和签名;该函数不是 SDK API。 * declare function getSignOrderParamsFromBusinessServer(): * Promise; * // 业务方自行实现:通过业务服务端确认最终签约状态;该函数不是 SDK API。 * declare function refreshSignStatusFromBusinessServer(authOrderId: string): Promise; * * const orderParams = await getSignOrderParamsFromBusinessServer(); * const orderResult = await createSignOrder(orderParams); * * if ('authOrderId' in orderResult) { * await sign({ orderId: orderResult.authOrderId }); * await refreshSignStatusFromBusinessServer(orderResult.authOrderId); * } * ``` * * @public */ export declare const sign: (params: SignParams) => Promise; /** @public */ export declare interface SignFailResult { /** 错误码。 */ code: number; /** 错误编号。 */ errNo: string; /** 错误信息。 */ errMsg: string; /** 用于服务端排查问题的错误日志 ID。 */ errLogId?: string; } /** @public */ export declare interface SignParams { /** * 平台签约订单号。 * * 传入 `createSignOrder` 成功后返回的 `authOrderId`,不要使用业务侧订单号或自行构造的值。 */ orderId: string; } /** @public */ export declare type SignResult = SignSuccessResult | SignFailResult; /** * 签约页面流程正常返回时无业务字段。 * * 该结果不代表用户已经签约成功,最终签约状态必须由业务服务端确认。 * * @public */ export declare type SignSuccessResult = Record; /** * 通过 {@link connectSocket} 获取的 WebSocket 任务实例。 * * `SocketTask` 表示单条 WebSocket 连接的控制对象。它负责发送数据、关闭连接, * 并通过事件回调接收连接状态、服务端消息和错误通知。`connectSocket` 返回时连接 * 仍可能处于创建中,调用方应先注册 `onOpen`、`onError`、`onClose`、`onMessage` * 等回调,再根据 `onOpen` 事件发送业务数据。 * * @public */ export declare interface SocketTask { /** * 表示 Socket 正在连接。 * * `connectSocket` 刚返回且宿主尚未完成握手时通常处于该状态。 */ readonly CONNECTING: 0; /** * 表示 Socket 连接已经打开。 * * 进入该状态后可以调用 {@link SocketTask.send} 发送数据。 */ readonly OPEN: 1; /** * 表示 Socket 连接关闭中。 * * 调用 {@link SocketTask.close} 后、本地等待宿主侧完成关闭流程时通常处于该状态。 */ readonly CLOSING: 2; /** * 表示 Socket 连接已关闭。 * * 进入该状态后,该任务不会再收到新的消息,也不应继续调用 `send`。 */ readonly CLOSED: 3; /** * 当前 Socket 连接状态 code。 * * 可与 `CONNECTING`、`OPEN`、`CLOSING`、`CLOSED` 常量比较。 * 如果因为参数错误等原因导致连接请求没有被宿主成功创建,则为 `undefined`。 */ readonly readyState: number | undefined; /** * 通过 WebSocket 连接发送数据。 * * 该方法只发起发送动作,不返回发送结果。建议在 `readyState === SocketTask.OPEN` * 或收到 `onOpen` 事件后调用;如果连接未就绪、数据编码失败或宿主侧发送失败, * 会触发 `onError`。 */ send(params: SocketTaskSendParams): void; /** * 关闭 WebSocket 连接。 * * 调用后会尝试向宿主侧发起关闭动作,并把 `readyState` 置为 `SocketTask.CLOSING`。 * 最终关闭完成时触发 `onClose`;关闭动作失败时触发 `onError`。 */ close(params?: SocketTaskCloseParams): void; /** * 监听 WebSocket 连接服务器成功的事件。 * * 可以注册多个回调。连接成功后触发回调,并携带握手响应 Header、协议类型等信息。 * 通常应在该回调中或之后调用 {@link SocketTask.send}。 */ onOpen(callback: (event: SocketTaskOpenEvent) => void): void; /** * 监听 WebSocket 与服务器连接断开的事件。 * * 主动关闭、服务端关闭、宿主侧回收连接都可能触发该回调。 * 回调触发后当前任务会从内部连接表移除。 */ onClose(callback: (event: SocketTaskCloseEvent) => void): void; /** * 监听 WebSocket 接收到服务器发送信息的事件。 * * 服务端每下发一条消息都会触发一次回调。消息内容通过 `event.data` 返回, * 类型可能是 `string` 或 `ArrayBuffer`。 */ onMessage(callback: (event: SocketTaskMessageEvent) => void): void; /** * 监听 WebSocket 发生错误的事件。 * * 连接创建、发送、关闭或底层通道出现异常时触发。 * 该回调只表示发生错误,不等同于连接一定已经关闭;是否关闭应结合 `readyState` * 或后续 `onClose` 事件判断。 */ onError(callback: (event: SocketTaskErrorEvent) => void): void; } /** * WebSocket 关闭事件。 * * 当前连接被主动关闭、服务端关闭或宿主侧因异常回收连接时触发。 * 触发后 `readyState` 会变为 `SocketTask.CLOSED`,该 `SocketTask` 不应再继续发送数据。 * * @public */ export declare interface SocketTaskCloseEvent { /** * 关闭状态码。 * * 可能来自调用 {@link SocketTask.close} 时传入的 `code`,也可能来自服务端或宿主侧。 */ code?: number; /** * 关闭原因。 * * 可能来自调用 {@link SocketTask.close} 时传入的 `reason`,也可能来自服务端或宿主侧。 */ reason?: string; /** * 错误信息。 * * 非正常关闭时宿主侧可能通过该字段补充失败原因;正常关闭时通常为空。 */ errMsg?: string; /** * 当前连接使用的网络传输层协议。 * * 该字段由宿主侧返回,部分运行环境可能不提供。 */ protocolType?: string; /** * 宿主侧使用的 WebSocket 实现类型。 * * 该字段由宿主侧返回,部分运行环境可能不提供。 */ socketType?: string; } /** * {@link SocketTask.close} 的参数。 * * `close` 用于主动关闭当前 WebSocket 连接。调用后 `readyState` 会先进入 * `SocketTask.CLOSING`,最终关闭结果通过 `onClose` 或 `onError` 回调通知。 * * @public */ export declare interface SocketTaskCloseParams { /** * 关闭连接状态码。 * * 不传时由宿主侧按正常关闭处理,通常等价于 `1000`。 * 常见值包括: * - `1000`: 正常关闭; * - `1001`: 因页面进入后台、宿主回收连接等原因关闭。 */ code?: number; /** * 连接被关闭的原因。 * * 该字段会随关闭帧传递给服务端,是否被服务端记录或回传取决于服务端实现。 */ reason?: string; } /** * WebSocket 错误事件。 * * 连接创建失败、发送失败、主动关闭失败、底层通道异常等错误都会通过该事件通知。 * 如果错误发生在连接创建阶段,`readyState` 会变为 `undefined` 或 `SocketTask.CLOSED`。 * * @public */ export declare interface SocketTaskErrorEvent { /** * 错误信息。 * * 由前端参数校验、编码过程或宿主侧返回的失败原因组成,可直接用于日志上报。 */ errMsg: string; } /** * WebSocket 收到服务端消息事件。 * * 服务端通过当前连接下发消息时触发。文本消息会以 `string` 形式返回; * 二进制消息会尽量还原为 `ArrayBuffer`。 * * @public */ export declare interface SocketTaskMessageEvent { /** * 收到的服务端消息。 * * - 文本消息返回 `string`; * - 二进制消息返回 `ArrayBuffer`。 * * 如果运行环境不支持二进制解码能力,底层传回的内容可能仍保持字符串形式。 */ data: string | ArrayBuffer; /** * 当前消息所属连接使用的协议。 * * 该字段由宿主侧返回,部分运行环境可能不提供。 */ protocolType?: string; /** * 宿主侧使用的 WebSocket 实现类型。 * * 该字段由宿主侧返回,部分运行环境可能不提供。 */ socketType?: string; } /** * WebSocket 连接成功事件。 * * 当宿主侧完成 WebSocket 握手并进入 open 状态后触发。 * 收到该事件后,调用方可以开始通过 {@link SocketTask.send} 发送数据。 * * @public */ export declare interface SocketTaskOpenEvent { /** * WebSocket 握手响应中的 Response Header。 * * 不同平台对 Header key 的大小写处理可能不同,读取时建议按业务需要做兼容。 */ header: Record; /** * 当前连接使用的网络传输层协议。 * * 该字段由宿主侧返回,部分运行环境可能不提供。 */ protocolType?: string; /** * 宿主侧使用的 WebSocket 实现类型。 * * 可能的值由宿主实现决定,例如传统 WebSocket 实现或宿主网络库实现; * 部分运行环境可能不提供。 */ socketType?: string; } /** * {@link SocketTask.send} 的参数。 * * `send` 只负责向已打开的 WebSocket 连接写入一条消息,不返回 Promise。 * 发送失败、连接未就绪或底层通道异常时,会通过同一个 `SocketTask` 的 `onError` 回调通知。 * * @public */ export declare interface SocketTaskSendParams { /** * 需要发送给服务端的数据。 * * - 传入 `string` 时按文本消息发送; * - 传入 `ArrayBuffer` 时按二进制消息发送,内部会编码后交给宿主侧处理。 * * 建议只在 `onOpen` 回调触发后调用 `send`,此时 `readyState` 通常为 `SocketTask.OPEN`。 */ data: string | ArrayBuffer; } /** * 开始监听加速度。 * * @remarks * 需配对调用 stopAccelerometer。 * @example * ```typescript * import { startAccelerometer } from '@doubao-apps/framework/api'; * * await startAccelerometer({ interval: 'normal' }); * ``` * * @public */ export declare const startAccelerometer: (params?: StartAccelerometerParams | undefined) => Promise; /** * 开始监听加速度的请求参数。 * * @public */ export declare interface StartAccelerometerParams { /** 监听频率。 */ interval?: SensorInterval; } /** * 开始搜索附近的 iBeacon。 * * @remarks * 需配对调用 stopBeaconDiscovery。 * @example * ```typescript * import { startBeaconDiscovery } from '@doubao-apps/framework/api'; * * await startBeaconDiscovery({ uuids: ['FDA50693-A4E2-4FB1-AFCF-C6EB07647825'] }); * ``` * * @public */ export declare const startBeaconDiscovery: (params: StartBeaconDiscoveryParams) => Promise; /** * 开始搜索 iBeacon 的请求参数。 * * @public */ export declare interface StartBeaconDiscoveryParams { /** 要搜索的 iBeacon UUID 列表。 */ uuids: string[]; /** iOS 下是否忽略蓝牙可用性校验。 */ ignoreBluetoothAvailable?: boolean; } /** * 开始搜索附近的蓝牙设备。 * * @remarks * 通常先调用 openBluetoothAdapter。 * @example * ```typescript * import { openBluetoothAdapter, startBluetoothDevicesDiscovery } from '@doubao-apps/framework/api'; * * await openBluetoothAdapter(); * await startBluetoothDevicesDiscovery({ allowDuplicatesKey: false }); * ``` * * @public */ export declare const startBluetoothDevicesDiscovery: (params?: StartBluetoothDevicesDiscoveryParams | undefined) => Promise; /** * 开始搜索蓝牙设备的请求参数。 * * @public */ export declare interface StartBluetoothDevicesDiscoveryParams { /** 是否允许重复上报同一设备。 */ allowDuplicatesKey?: boolean; /** 上报设备的间隔,单位毫秒。 */ interval?: number; /** 按主服务 UUID 过滤搜索范围。 */ services?: string[]; /** 扫描功耗等级。 */ powerLevel?: BluetoothPowerLevel; } /** * 开始监听罗盘。 * * @remarks * 需配对调用 stopCompass。 * @example * ```typescript * import { startCompass } from '@doubao-apps/framework/api'; * * await startCompass(); * ``` * * @public */ export declare const startCompass: (params?: {} | undefined) => Promise; /** * 开始监听设备方向变化。 * * @remarks * 需配对调用 stopDeviceMotionListening。 * @example * ```typescript * import { startDeviceMotionListening } from '@doubao-apps/framework/api'; * * await startDeviceMotionListening({ interval: 'normal' }); * ``` * * @public */ export declare const startDeviceMotionListening: (params?: StartDeviceMotionListeningParams | undefined) => Promise; /** * 开始监听设备方向变化的请求参数。 * * @public */ export declare interface StartDeviceMotionListeningParams { /** 监听频率。 */ interval?: SensorInterval; } /** * 开始监听陀螺仪。 * * @remarks * 需配对调用 stopGyroscope。 * @example * ```typescript * import { startGyroscope } from '@doubao-apps/framework/api'; * * await startGyroscope({ interval: 'normal' }); * ``` * * @public */ export declare const startGyroscope: (params?: StartGyroscopeParams | undefined) => Promise; /** * 开始监听陀螺仪的请求参数。 * * @public */ export declare interface StartGyroscopeParams { /** 监听频率。 */ interval?: SensorInterval; } /** * 开始接收位置更新。 * * @remarks * 需配对调用 stopLocationUpdate。 * @example * ```typescript * import { startLocationUpdate } from '@doubao-apps/framework/api'; * * await startLocationUpdate({ type: 'gcj02' }); * ``` * * @public */ export declare const startLocationUpdate: (params?: StartLocationUpdateParams | undefined) => Promise; /** @public */ export declare interface StartLocationUpdateParams { /** * 坐标系类型,支持 wgs84 或 gcj02 */ type?: 'wgs84' | 'gcj02'; } /** * 初始化 Wi-Fi 模块。 * * @remarks * Wi-Fi 流程入口。 * @example * ```typescript * import { startWifi } from '@doubao-apps/framework/api'; * * await startWifi(); * ``` * * @public */ export declare const startWifi: (params?: {} | undefined) => Promise; /** * {@link FileSystemManager.stat} 的参数。 * * @public */ export declare interface StatParams { /** * 要获取状态信息的文件或目录路径。 */ path: string; } /** * {@link FileSystemManager.stat} 的返回结果。 * * @public */ export declare interface StatResult { /** * 文件大小,单位为字节(Byte)。 */ size: number; /** * 文件最近一次被修改的时间戳,单位为毫秒。 */ lastModifiedTime: number; /** * 判断当前路径是否是一个目录。 */ isDirectory: boolean; } /** * 停止监听加速度。 * * @example * ```typescript * import { stopAccelerometer } from '@doubao-apps/framework/api'; * * await stopAccelerometer(); * ``` * * @public */ export declare const stopAccelerometer: (params?: {} | undefined) => Promise; /** * 停止搜索附近的 iBeacon。 * * @example * ```typescript * import { stopBeaconDiscovery } from '@doubao-apps/framework/api'; * * await stopBeaconDiscovery(); * ``` * * @public */ export declare const stopBeaconDiscovery: (params?: {} | undefined) => Promise; /** * 停止搜索附近的蓝牙设备。 * * @example * ```typescript * import { stopBluetoothDevicesDiscovery } from '@doubao-apps/framework/api'; * * await stopBluetoothDevicesDiscovery(); * ``` * * @public */ export declare const stopBluetoothDevicesDiscovery: (params?: {} | undefined) => Promise; /** * 停止监听罗盘。 * * @example * ```typescript * import { stopCompass } from '@doubao-apps/framework/api'; * * await stopCompass(); * ``` * * @public */ export declare const stopCompass: (params?: {} | undefined) => Promise; /** * 停止监听设备方向变化。 * * @example * ```typescript * import { stopDeviceMotionListening } from '@doubao-apps/framework/api'; * * await stopDeviceMotionListening(); * ``` * * @public */ export declare const stopDeviceMotionListening: (params?: {} | undefined) => Promise; /** * 停止监听陀螺仪。 * * @example * ```typescript * import { stopGyroscope } from '@doubao-apps/framework/api'; * * await stopGyroscope(); * ``` * * @public */ export declare const stopGyroscope: (params?: {} | undefined) => Promise; /** * 停止接收位置更新。 * * @example * ```typescript * import { stopLocationUpdate } from '@doubao-apps/framework/api'; * * await stopLocationUpdate(); * ``` * * @public */ export declare const stopLocationUpdate: (params?: {} | undefined) => Promise; /** * 关闭 Wi-Fi 模块。 * * @example * ```typescript * import { stopWifi } from '@doubao-apps/framework/api'; * * await stopWifi(); * ``` * * @public */ export declare const stopWifi: (params?: {} | undefined) => Promise; /** @public */ export declare type SubscriptionReminderStatus = 'accept' | 'reject'; /** @public */ export declare type SubscriptionReminderType = 'message_notice' | 'feed' | 'push'; /** @public */ export declare interface SubscriptionReminderWay { /** 提醒方式 */ reminderType: SubscriptionReminderType; /** 提醒授权结果 */ reminderStatus: SubscriptionReminderStatus; } /** @public */ export declare type SubscriptionSettingStatus = 'accept' | 'reject' | 'ban' | 'filter'; /** @public */ export declare interface SubscriptionsSetting { /** 设置页订阅消息总开关 */ mainSwitch: boolean; /** 一次性订阅消息模板的订阅状态 */ itemSettings?: Record; /** 模板订阅状态 */ templateSettings?: Record; } /** @public */ export declare interface SubscriptionTemplateSetting { /** 订阅结果 */ status: SubscriptionSettingStatus; /** 是否为长期订阅状态 */ alwaysSubscribe?: boolean; /** 模板支持的提醒方式对应的用户授权结果 */ allowReminderWay?: SubscriptionReminderWay[]; } /** @public */ export declare interface SystemInfoSafeArea { /** 安全区域左上角横坐标 */ left: number; /** 安全区域右下角横坐标 */ right: number; /** 安全区域左上角纵坐标 */ top: number; /** 安全区域右下角纵坐标 */ bottom: number; /** 安全区域宽度 */ width: number; /** 安全区域高度 */ height: number; } /** * 任务操作参数。 * * @public */ export declare interface TaskActionParams { /** 操作标识 */ action_key?: string; /** 页面参数 */ page_param?: string; } /** * 任务详情。传入对象时会在调用 native 前自动 JSON.stringify。 * * @public */ export declare type TaskDetail = string | RemoteNormalV1Detail; /** * 任务展示数据。 * * @public */ export declare interface TaskDisplayData { /** 任务标题 */ title: string; /** 任务副标题 */ sub_title?: string; } /** * 任务进度数据。 * * @public */ export declare interface TaskProgressData { /** 任务进度值,如百分比 0-100 */ progress: number; /** 进度描述文本,如"正在处理中" */ progress_text?: string; /** 预估剩余时间,单位:秒 */ remaining_seconds?: number; } /** * 任务状态。 * * running 表示任务运行中,completed 表示任务已完成。 * * @public */ export declare type TaskStatus = 'running' | 'completed'; /** * 任务样式模板。 * * 当前仅支持 remote_normal_v1。 * * @public */ export declare type TaskTemplate = 'remote_normal_v1'; /** * 任务类型。 * * local 表示本地任务,remote 表示远端任务。 * * @public */ export declare type TaskType = 'local' | 'remote'; /** @public */ export declare interface ThemeChangeEvent { /** 切换后的应用主题 */ theme: AppTheme; } /** * 应用主题变化事件监听函数。 * * @public */ export declare type ThemeChangeListener = (event: ThemeChangeEvent) => void; /** * 直接触发指定的 MCP Tool。 * * @internal */ export declare const toolCall: (params: ToolCallParams) => Promise; /** @internal */ export declare interface ToolCallParams { /** MCP Tool 名称。 */ toolName: string; /** MCP Tool 入参。 */ params?: Record; /** MCP Server ID。 */ serverId?: string; /** 调用超时时间,单位 ms。 */ timeoutMs?: number; } /** @internal */ export declare interface ToolCallResult { status: 'succeeded' | 'failed' | 'timeout' | 'cancelled' | 'rejected'; result?: Record; error?: Record; raw_result_text?: string; raw_mcp_result_json?: string; miniapp?: Record; debug?: Record; } /** * {@link FileSystemManager.truncate} 的参数。 * * @public */ export declare interface TruncateParams { /** * 要截断的文件路径。 */ filePath: string; /** * 截断后的文件字节长度。 * * - 若 `length` 小于文件原始长度,文件将被截取到指定长度,多余部分丢弃。 * - 若 `length` 大于文件原始长度,文件将被扩展到指定长度,扩展部分用 `\0` 填充。 * * @default 0 */ length?: number; } declare type TypeGuard = (from: From) => from is To; /** * {@link FileSystemManager.unlink} 的参数。 * * @public */ export declare interface UnlinkParams { /** * 要删除的文件路径。 * * 该接口只能删除文件,不能删除目录;删除目录应使用 {@link FileSystemManager.rmdir}。 */ filePath: string; } /** * {@link FileSystemManager.unzip} 的参数。 * * @public */ export declare interface UnzipParams { /** * 要解压的 zip 文件路径。 */ zipFilePath: string; /** * 解压后的目标目录路径。 * * 目标目录须已存在,否则解压会失败。 */ targetPath: string; } /** * 向 Agent 捐赠上下文。 * * @param params - 上下文内容及可选的任务、实体标识。 * @returns 返回一个 Promise,在上下文成功捐赠时解析。 * @remarks * `taskId` 可以为空,此时客户端会尝试使用 `entityId` 填充;`entityId` 可以为空, * 此时如果处于卡片环境,客户端会尝试使用卡片的 `entityId` 填充。 * * @example * ```typescript * import { updateModelContext } from '@doubao-apps/framework/api'; * * await updateModelContext({ * taskId: 'task-id', * entityId: 'entity-id', * content: '用户选择了标准配送' * }); * ``` * * @public */ export declare const updateModelContext: (params: UpdateModelContextParams) => Promise; /** * 向 Agent 捐赠上下文的请求参数。 * * @public */ export declare interface UpdateModelContextParams { /** 上下文所属任务 ID,业务侧定义。为空时客户端会尝试使用 entityId 填充 */ taskId?: string; /** 上下文所属的 entityId,业务侧管理。为空且处于卡片环境时,客户端会尝试使用卡片的 entityId 填充 */ entityId?: string; /** 上下文内容,格式无约束,可以与 MCP 服务下发的上下文格式保持一致 */ content: string; } /** * 更新任务状态或任务详情。 * * @param params - 任务更新参数,taskStatus 与 taskDetail 二选一。 * @returns 返回任务 ID、新 token 和过期时间。 * @remarks * 更新任务时至少传入 taskStatus 或 taskDetail 中的一个。更新远端任务成功后,旧 token 会失效, * 如返回 nextToken,后续需要使用新的 token 继续更新远端任务。 * * @example * ```typescript * import { updateTask } from '@doubao-apps/framework/api'; * * const result = await updateTask({ * taskId: 'task_123', * taskStatus: 'completed', * taskDetail: { * expire_in_sec: 3600, * display_data: { * title: '订单已完成', * sub_title: '订单处理完成' * } * } * }); * * console.log(result.taskId, result.nextToken, result.expiresIn); * ``` * * @public */ export declare const updateTask: (params: UpdateTaskParams) => Promise; /** * 更新任务的请求参数。 * * @public */ export declare interface UpdateTaskParams { /** 任务 ID */ taskId: string; /** 任务状态,与 taskDetail 二选一 */ taskStatus?: TaskStatus; /** 模板对应的数据,传入对象时会在调用 native 前自动 JSON.stringify,与 taskStatus 二选一 */ taskDetail?: TaskDetail; } /** * 更新任务的返回结果。 * * @public */ export declare interface UpdateTaskResult { /** 任务 ID,更新后任务 ID 不变 */ taskId: string; /** 每次更新后旧的 token 失效,必须使用新返回的 token */ nextToken?: string; /** 任务超时过期时间 */ expiresIn?: number; } /** * 更新指定 Widget 卡片实例的渲染数据。 * * 用于卡片内操作后刷新卡片展示、把服务端最新结果写回卡片,或由 Page 根据传入的 * `widgetInstanceId` 更新原卡片;需要替换卡片类型时可同时传入新的 `widgetId`。 * * @example * ```typescript * import { updateWidget } from '@doubao-apps/framework/api'; * import { getWidgetInstanceId } from '@doubao-apps/framework'; * * await updateWidget({ * widgetInstanceId: getWidgetInstanceId(), * widgetData: JSON.stringify({ title: '更新后的标题', status: 'done' }) * }); * ``` * * @public */ export declare const updateWidget: (params: UpdateWidgetParams) => Promise; /** @public */ export declare interface UpdateWidgetParams { /** * 需要更新的 Widget 实例 ID。 * * 卡片内可通过 `getWidgetInstanceId()` 获取;页面中需要由路由参数或业务数据传入。 */ widgetInstanceId: string; /** 可选的新 widgetId。传入后会把当前实例切换成另一个已注册的 Widget */ widgetId?: string; /** 新的卡片渲染数据,通常传入 `JSON.stringify(viewData)` */ widgetData: string; } /** * 用户主动截屏事件。 * * @public */ export declare interface UserCaptureScreenEvent { } /** * 用户主动截屏事件监听函数。 * * @public */ export declare type UserCaptureScreenListener = (event: UserCaptureScreenEvent) => void; /** * 用户录屏事件。 * * @public */ export declare interface UserScreenRecordEvent { /** 录屏状态,start 表示开始录屏,stop 表示停止录屏。 */ state: UserScreenRecordState; } /** * 用户录屏事件监听函数。 * * @public */ export declare type UserScreenRecordListener = (event: UserScreenRecordEvent) => void; /** * 用户录屏状态。 * * @public */ export declare type UserScreenRecordState = 'start' | 'stop'; /** * 触发长震动。 * * @example * ```typescript * import { vibrateLong } from '@doubao-apps/framework/api'; * * await vibrateLong(); * ``` * * @public */ export declare const vibrateLong: (params?: {} | undefined) => Promise; /** * 触发短震动。 * * @example * ```typescript * import { vibrateShort } from '@doubao-apps/framework/api'; * * await vibrateShort({ type: 'medium' }); * ``` * * @public */ export declare const vibrateShort: (params?: VibrateShortParams | undefined) => Promise; /** * 短震动请求参数。 * * @public */ export declare interface VibrateShortParams { /** 震动强度类型。 */ type?: VibrateShortType; } /** * 短震动类型。 * * @public */ export declare type VibrateShortType = 'heavy' | 'medium' | 'light'; /** * Wi-Fi 连接事件。 * * @public */ export declare interface WifiConnectedEvent { /** 已连接的 Wi-Fi 信息。 */ wifi: WifiInfo; } /** * Wi-Fi 连接事件监听函数。 * * @public */ export declare type WifiConnectedListener = (event: WifiConnectedEvent) => void; /** * Wi-Fi 信息。 * * @public */ export declare interface WifiInfo { /** Wi-Fi SSID。 */ ssid: string; /** Wi-Fi BSSID。 */ bssid?: string; /** Wi-Fi 是否安全。 */ secure?: boolean; /** 信号强度。 */ signalStrength?: number; /** 频段,单位 MHz。 */ frequency?: number; } /** * 预设 Wi-Fi 条目。 * * @public */ export declare interface WifiListItem { /** Wi-Fi SSID。 */ ssid?: string; /** Wi-Fi BSSID。 */ bssid?: string; /** Wi-Fi 密码。 */ password?: string; } /** @public */ export declare interface WindowSafeArea { /** 安全区域左上角横坐标 */ left: number; /** 安全区域右下角横坐标 */ right: number; /** 安全区域左上角纵坐标 */ top: number; /** 安全区域右下角纵坐标 */ bottom: number; /** 安全区域宽度 */ width: number; /** 安全区域高度 */ height: number; } /** * 写入 BLE 特征值。 * * @remarks * value 需要是 ArrayBuffer。 * @example * ```typescript * import { writeBLECharacteristicValue } from '@doubao-apps/framework/api'; * * await writeBLECharacteristicValue({ * deviceId: 'device-id', * serviceId: 'service-id', * characteristicId: 'characteristic-id', * value: new Uint8Array([1, 2, 3]).buffer * }); * ``` * * @public */ export declare const writeBLECharacteristicValue: (params: WriteBLECharacteristicValueParams) => Promise; /** * 写入 BLE 特征值的请求参数。 * * @public */ export declare interface WriteBLECharacteristicValueParams { /** 蓝牙设备 ID。 */ deviceId: string; /** 服务 ID。 */ serviceId: string; /** 特征值 ID。 */ characteristicId: string; /** 要写入的二进制数据。 */ value: ArrayBuffer; /** 写入模式。 */ writeType?: BluetoothWriteType; } /** * {@link FileSystemManager.writeFile} 的参数。 * * @remarks * - 如果文件不存在会自动创建;如果文件已存在则会覆盖原有内容。 * - 父目录不存在时写入会失败,需先通过 {@link FileSystemManager.mkdir} 创建目录。 * * @public */ export declare interface WriteFileParams { /** * 要写入的文件路径(本地路径)。 */ filePath: string; /** * 要写入的内容。 * * - 当 `encoding` 为 `'utf-8'` 时,直接写入该字符串; * - 当 `encoding` 为 `'base64'` 时,将该字符串先进行 Base64 解码再写入文件。 */ data: string; /** * 指定写入文件的字符编码。 * * @default 'utf-8' */ encoding?: 'utf-8' | 'base64'; } export { }