Add runtime networking APIs

This commit is contained in:
gem
2026-06-09 16:09:19 +08:00
parent 4f36d68b74
commit 7b3c5cb0f5
20 changed files with 936 additions and 6 deletions

View File

@@ -64,6 +64,11 @@
---| 'animation_done'
---| 'resize'
---| 'scroll'
---| 'network_http'
---| 'network_ws_open'
---| 'network_ws_message'
---| 'network_ws_error'
---| 'network_ws_close'
---@alias RuntimeScaleMode
---| 'fit'
@@ -580,9 +585,26 @@
---@field cancel_group fun(group: string): RuntimeCommand
---@field cancel_scope fun(scope: string): RuntimeCommand
---@class RuntimeHttpRequestOptions
---@field id? string
---@field method? string HTTP method. Defaults to GET.
---@field url string http/https URL.
---@field headers? table<string, string>
---@field body? string
---@field timeout? number Timeout in seconds. Defaults to 15.
---@class RuntimeWsConnectOptions
---@field id? string
---@field url string ws/wss URL.
---@field protocols? string[]
---@class RuntimeImportApi
---@field import fun(moduleName: string): table
---@field log fun(...: any)
---@field http_request fun(options: RuntimeHttpRequestOptions): string Starts an async HTTP request and returns request id. Result event type: network_http.
---@field ws_connect fun(options: RuntimeWsConnectOptions): string Opens a WebSocket and returns connection id. Event types: network_ws_open/network_ws_message/network_ws_error/network_ws_close.
---@field ws_send fun(id: string, message: string): boolean
---@field ws_close fun(id: string): boolean
---@type RuntimeImportApi
runtime = runtime

View File

@@ -64,6 +64,11 @@
---| 'animation_done'
---| 'resize'
---| 'scroll'
---| 'network_http'
---| 'network_ws_open'
---| 'network_ws_message'
---| 'network_ws_error'
---| 'network_ws_close'
---@alias RuntimeScaleMode
---| 'fit'
@@ -580,9 +585,26 @@
---@field cancel_group fun(group: string): RuntimeCommand
---@field cancel_scope fun(scope: string): RuntimeCommand
---@class RuntimeHttpRequestOptions
---@field id? string
---@field method? string HTTP method. Defaults to GET.
---@field url string http/https URL.
---@field headers? table<string, string>
---@field body? string
---@field timeout? number Timeout in seconds. Defaults to 15.
---@class RuntimeWsConnectOptions
---@field id? string
---@field url string ws/wss URL.
---@field protocols? string[]
---@class RuntimeImportApi
---@field import fun(moduleName: string): table
---@field log fun(...: any)
---@field http_request fun(options: RuntimeHttpRequestOptions): string Starts an async HTTP request and returns request id. Result event type: network_http.
---@field ws_connect fun(options: RuntimeWsConnectOptions): string Opens a WebSocket and returns connection id. Event types: network_ws_open/network_ws_message/network_ws_error/network_ws_close.
---@field ws_send fun(id: string, message: string): boolean
---@field ws_close fun(id: string): boolean
---@type RuntimeImportApi
runtime = runtime

View File

@@ -64,6 +64,11 @@
---| 'animation_done'
---| 'resize'
---| 'scroll'
---| 'network_http'
---| 'network_ws_open'
---| 'network_ws_message'
---| 'network_ws_error'
---| 'network_ws_close'
---@alias RuntimeScaleMode
---| 'fit'
@@ -580,9 +585,26 @@
---@field cancel_group fun(group: string): RuntimeCommand
---@field cancel_scope fun(scope: string): RuntimeCommand
---@class RuntimeHttpRequestOptions
---@field id? string
---@field method? string HTTP method. Defaults to GET.
---@field url string http/https URL.
---@field headers? table<string, string>
---@field body? string
---@field timeout? number Timeout in seconds. Defaults to 15.
---@class RuntimeWsConnectOptions
---@field id? string
---@field url string ws/wss URL.
---@field protocols? string[]
---@class RuntimeImportApi
---@field import fun(moduleName: string): table
---@field log fun(...: any)
---@field http_request fun(options: RuntimeHttpRequestOptions): string Starts an async HTTP request and returns request id. Result event type: network_http.
---@field ws_connect fun(options: RuntimeWsConnectOptions): string Opens a WebSocket and returns connection id. Event types: network_ws_open/network_ws_message/network_ws_error/network_ws_close.
---@field ws_send fun(id: string, message: string): boolean
---@field ws_close fun(id: string): boolean
---@type RuntimeImportApi
runtime = runtime

View File

@@ -64,6 +64,11 @@
---| 'animation_done'
---| 'resize'
---| 'scroll'
---| 'network_http'
---| 'network_ws_open'
---| 'network_ws_message'
---| 'network_ws_error'
---| 'network_ws_close'
---@alias RuntimeScaleMode
---| 'fit'
@@ -580,9 +585,26 @@
---@field cancel_group fun(group: string): RuntimeCommand
---@field cancel_scope fun(scope: string): RuntimeCommand
---@class RuntimeHttpRequestOptions
---@field id? string
---@field method? string HTTP method. Defaults to GET.
---@field url string http/https URL.
---@field headers? table<string, string>
---@field body? string
---@field timeout? number Timeout in seconds. Defaults to 15.
---@class RuntimeWsConnectOptions
---@field id? string
---@field url string ws/wss URL.
---@field protocols? string[]
---@class RuntimeImportApi
---@field import fun(moduleName: string): table
---@field log fun(...: any)
---@field http_request fun(options: RuntimeHttpRequestOptions): string Starts an async HTTP request and returns request id. Result event type: network_http.
---@field ws_connect fun(options: RuntimeWsConnectOptions): string Opens a WebSocket and returns connection id. Event types: network_ws_open/network_ws_message/network_ws_error/network_ws_close.
---@field ws_send fun(id: string, message: string): boolean
---@field ws_close fun(id: string): boolean
---@type RuntimeImportApi
runtime = runtime