1- type UnknownObject = Record < string , unknown > ;
2-
3- export type WidgetState = UnknownObject ;
4-
5- export type SetWidgetState = ( state : WidgetState ) => Promise < void > ;
6-
7- export type Theme = "light" | "dark" ;
8-
9- export type SafeAreaInsets = {
10- top : number ;
11- bottom : number ;
12- left : number ;
13- right : number ;
14- } ;
15-
16- export type SafeArea = {
17- insets : SafeAreaInsets ;
18- } ;
19-
20- export type UserAgent = {
21- //
22- } ;
23-
24- export type WebplusGlobals = {
1+ export type OpenAiGlobals <
2+ ToolInput = UnknownObject ,
3+ ToolOutput = UnknownObject ,
4+ ToolResponseMetadata = UnknownObject ,
5+ WidgetState = UnknownObject
6+ > = {
257 // visuals
268 theme : Theme ;
279
2810 userAgent : UserAgent ;
11+ locale : string ;
2912
3013 // layout
3114 maxHeight : number ;
3215 displayMode : DisplayMode ;
3316 safeArea : SafeArea ;
3417
3518 // state
36- toolInput : UnknownObject ;
37- toolOutput : UnknownObject ;
38- widgetState : UnknownObject | null ;
39- setWidgetState : SetWidgetState ;
19+ toolInput : ToolInput ;
20+ toolOutput : ToolOutput | null ;
21+ toolResponseMetadata : ToolResponseMetadata | null ;
22+ widgetState : WidgetState | null ;
23+ setWidgetState : ( state : WidgetState ) => Promise < void > ;
4024} ;
4125
4226// currently copied from types.ts in chatgpt/web-sandbox.
4327// Will eventually use a public package.
4428type API = {
45- // Calling APIs
46- streamCompletion : StreamCompletion ;
47- callCompletion : CallCompletion ;
4829 callTool : CallTool ;
49- sendFollowUpMessage : SendFollowUpMessage ;
30+ sendFollowUpMessage : ( args : { prompt : string } ) => Promise < void > ;
31+ openExternal ( payload : { href : string } ) : void ;
5032
5133 // Layout controls
5234 requestDisplayMode : RequestDisplayMode ;
5335} ;
5436
37+ export type UnknownObject = Record < string , unknown > ;
38+
39+ export type Theme = "light" | "dark" ;
40+
41+ export type SafeAreaInsets = {
42+ top : number ;
43+ bottom : number ;
44+ left : number ;
45+ right : number ;
46+ } ;
47+
48+ export type SafeArea = {
49+ insets : SafeAreaInsets ;
50+ } ;
51+
52+ export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown" ;
53+
54+ export type UserAgent = {
55+ device : { type : DeviceType } ;
56+ capabilities : {
57+ hover : boolean ;
58+ touch : boolean ;
59+ } ;
60+ } ;
61+
5562/** Display mode */
5663export type DisplayMode = "pip" | "inline" | "fullscreen" ;
5764export type RequestDisplayMode = ( args : { mode : DisplayMode } ) => Promise < {
@@ -72,106 +79,23 @@ export type CallTool = (
7279 args : Record < string , unknown >
7380) => Promise < CallToolResponse > ;
7481
75- // Subest of the the params for sampling/createMessage
76- export type ModelHintName = "thinking-none" | "thinking-low" | "thinking-high" ;
77-
78- export type CompletionStreamOptions = {
79- systemPrompt ?: string | null ;
80- modelType ?: ModelHintName ;
81- } ;
82-
83- export type Annotations = {
84- audience ?: ( "user" | "assistant" ) [ ] | null ;
85- priority ?: number | null ;
86- } ;
87-
88- export type TextContent = {
89- type : "text" ;
90- text : string ;
91- annotations ?: Annotations | null ;
92- _meta ?: Record < string , never > | null ;
93- } ;
94-
95- export type ImageContent = {
96- type : "image" ;
97- data : string ;
98- mimeType : string ;
99- annotations ?: Annotations | null ;
100- _meta ?: Record < string , never > | null ;
101- } ;
102-
103- export type AudioContent = {
104- type : "audio" ;
105- data : string ;
106- mimeType : string ;
107- annotations ?: Annotations | null ;
108- _meta ?: Record < string , never > | null ;
109- } ;
110-
111- export type SamplingMessage = {
112- role : "user" | "assistant" ;
113- content : TextContent | ImageContent | AudioContent ;
114- } ;
115-
116- export type ModelHint = {
117- name : ModelHintName ;
118- } ;
119-
120- export type ModelPreferences = {
121- hints : ModelHint [ ] ;
122- } ;
123-
124- export type CreateMessageRequestParams = {
125- messages : SamplingMessage [ ] ;
126- modelPreferences : ModelPreferences ;
127- systemPrompt ?: string | null ;
128- metadata ?: Record < string , string > | null ;
129- } ;
130-
131- export type CreateMessageResponse = {
132- content : TextContent | ImageContent | AudioContent ;
133- model : string ;
134- role : "assistant" ;
135- stopReason ?: string ;
136- } ;
137-
138- // this is the MCP sample stream
139- export type StreamCompletion = (
140- request : CreateMessageRequestParams
141- ) => AsyncIterable < CreateMessageResponse > ;
142-
143- export type CallCompletion = (
144- request : CreateMessageRequestParams
145- ) => Promise < CreateMessageResponse > ;
146-
147- export type SendFollowUpMessage = ( args : { prompt : string } ) => Promise < void > ;
148-
14982/** Extra events */
150- export const SET_GLOBALS_EVENT_TYPE = "webplus :set_globals" ;
83+ export const SET_GLOBALS_EVENT_TYPE = "openai :set_globals" ;
15184export class SetGlobalsEvent extends CustomEvent < {
152- globals : Partial < WebplusGlobals > ;
85+ globals : Partial < OpenAiGlobals > ;
15386} > {
15487 readonly type = SET_GLOBALS_EVENT_TYPE ;
15588}
15689
157- export const TOOL_RESPONSE_EVENT_TYPE = "webplus:tool_response" ;
158- export class ToolResponseEvent extends CustomEvent < {
159- tool : { name : string ; args : UnknownObject } ;
160- } > {
161- readonly type = TOOL_RESPONSE_EVENT_TYPE ;
162- }
163-
16490/**
16591 * Global oai object injected by the web sandbox for communicating with chatgpt host page.
16692 */
16793declare global {
16894 interface Window {
169- webplus : API & WebplusGlobals ;
170- openai : API & WebplusGlobals ;
95+ openai : API & OpenAiGlobals ;
17196 }
17297
17398 interface WindowEventMap {
17499 [ SET_GLOBALS_EVENT_TYPE ] : SetGlobalsEvent ;
175- [ TOOL_RESPONSE_EVENT_TYPE ] : ToolResponseEvent ;
176100 }
177101}
0 commit comments