@creature-ai/sdk 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.d.ts +299 -72
- package/dist/core/index.js +235 -267
- package/dist/core/index.js.map +1 -1
- package/dist/react/index.d.ts +47 -51
- package/dist/react/index.js +249 -311
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.d.ts +187 -218
- package/dist/server/index.js +583 -524
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/types-JBEuUzEi.d.ts +0 -186
package/package.json
CHANGED
package/dist/types-JBEuUzEi.d.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core types for the MCP SDK.
|
|
3
|
-
* These are framework-agnostic and shared between vanilla JS and React.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Environment types for host detection.
|
|
7
|
-
*/
|
|
8
|
-
type Environment = "chatgpt" | "mcp-apps" | "standalone";
|
|
9
|
-
/**
|
|
10
|
-
* Display modes for UI resources.
|
|
11
|
-
* - "inline": Embedded within the conversation flow
|
|
12
|
-
* - "pip": Picture-in-picture floating panel
|
|
13
|
-
* - "fullscreen": Full-screen overlay
|
|
14
|
-
*/
|
|
15
|
-
type DisplayMode = "inline" | "pip" | "fullscreen";
|
|
16
|
-
/**
|
|
17
|
-
* Log severity levels matching MCP protocol LoggingLevel.
|
|
18
|
-
* These are displayed in the host's DevConsole with appropriate colors.
|
|
19
|
-
*/
|
|
20
|
-
type LogLevel = "debug" | "info" | "notice" | "warning" | "error";
|
|
21
|
-
/**
|
|
22
|
-
* Structured widget state format (ChatGPT-compatible).
|
|
23
|
-
* Allows separating model-visible content from private UI state.
|
|
24
|
-
*/
|
|
25
|
-
interface StructuredWidgetState {
|
|
26
|
-
/** Content visible to the AI model on follow-up turns */
|
|
27
|
-
modelContent?: string | Record<string, unknown> | null;
|
|
28
|
-
/** UI-only state, hidden from model */
|
|
29
|
-
privateContent?: Record<string, unknown> | null;
|
|
30
|
-
/** File IDs for images the model can see */
|
|
31
|
-
imageIds?: string[];
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Widget state can be structured (with modelContent/privateContent)
|
|
35
|
-
* or a simple key-value object.
|
|
36
|
-
*/
|
|
37
|
-
type WidgetState = StructuredWidgetState | Record<string, unknown>;
|
|
38
|
-
/**
|
|
39
|
-
* Unified state shape for AppSession.
|
|
40
|
-
* Provides a consistent state model across MCP Apps and ChatGPT Apps.
|
|
41
|
-
*
|
|
42
|
-
* - `internal`: Private to AppSession implementation (not synced anywhere)
|
|
43
|
-
* - `backend`: Available in the backend server (not mirrored to UI)
|
|
44
|
-
* - `ui`: Maps to widgetState on the frontend (synced via host binding)
|
|
45
|
-
*/
|
|
46
|
-
interface AppSessionState<TInternal extends Record<string, unknown> = Record<string, unknown>, TBackend extends Record<string, unknown> = Record<string, unknown>, TUi extends WidgetState | null = WidgetState | null> {
|
|
47
|
-
internal: TInternal;
|
|
48
|
-
backend: TBackend;
|
|
49
|
-
ui: TUi;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Options for creating an AppSession.
|
|
53
|
-
*/
|
|
54
|
-
interface AppSessionOptions {
|
|
55
|
-
/** Optional AppSession ID (auto-generated if not provided) */
|
|
56
|
-
id?: string;
|
|
57
|
-
/** Enable WebSocket channel for this AppSession (server-side only) */
|
|
58
|
-
websockets?: boolean;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Listener for AppSession state changes.
|
|
62
|
-
*/
|
|
63
|
-
type AppSessionListener<TState extends AppSessionState = AppSessionState> = (state: TState, prevState: TState) => void;
|
|
64
|
-
/**
|
|
65
|
-
* Tool call result structure.
|
|
66
|
-
*/
|
|
67
|
-
interface ToolResult<T = Record<string, unknown>> {
|
|
68
|
-
content?: Array<{
|
|
69
|
-
type: string;
|
|
70
|
-
text: string;
|
|
71
|
-
}>;
|
|
72
|
-
structuredContent?: T;
|
|
73
|
-
isError?: boolean;
|
|
74
|
-
source?: "agent" | "ui";
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Host context sent from MCP Apps host.
|
|
78
|
-
* Follows MCP Apps spec with Creature extensions via [key: string]: unknown.
|
|
79
|
-
*/
|
|
80
|
-
interface HostContext {
|
|
81
|
-
theme?: "light" | "dark";
|
|
82
|
-
styles?: {
|
|
83
|
-
variables?: Record<string, string>;
|
|
84
|
-
};
|
|
85
|
-
displayMode?: DisplayMode;
|
|
86
|
-
availableDisplayModes?: DisplayMode[];
|
|
87
|
-
viewport?: {
|
|
88
|
-
width: number;
|
|
89
|
-
height: number;
|
|
90
|
-
};
|
|
91
|
-
platform?: string;
|
|
92
|
-
/**
|
|
93
|
-
* Widget state restored from previous widget instance.
|
|
94
|
-
* Creature extension - passed via hostContext on ui/initialize.
|
|
95
|
-
*/
|
|
96
|
-
widgetState?: WidgetState;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Configuration for creating a host client.
|
|
100
|
-
*/
|
|
101
|
-
interface HostClientConfig {
|
|
102
|
-
/** Name of the client (for protocol handshake) */
|
|
103
|
-
name: string;
|
|
104
|
-
/** Version of the client */
|
|
105
|
-
version: string;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* State managed by the host client.
|
|
109
|
-
*/
|
|
110
|
-
interface HostClientState {
|
|
111
|
-
/** Whether the host connection is ready */
|
|
112
|
-
isReady: boolean;
|
|
113
|
-
/** The detected environment */
|
|
114
|
-
environment: Environment;
|
|
115
|
-
/** Current widget state */
|
|
116
|
-
widgetState: WidgetState | null;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Event handlers that can be registered on the host client.
|
|
120
|
-
*/
|
|
121
|
-
interface HostClientEvents {
|
|
122
|
-
/** Called when tool input is received (before execution) */
|
|
123
|
-
"tool-input": (args: Record<string, unknown>) => void;
|
|
124
|
-
/** Called when tool result is received */
|
|
125
|
-
"tool-result": (result: ToolResult) => void;
|
|
126
|
-
/** Called when theme changes (MCP Apps only) */
|
|
127
|
-
"theme-change": (theme: "light" | "dark") => void;
|
|
128
|
-
/** Called when host requests teardown (MCP Apps only) */
|
|
129
|
-
teardown: () => Promise<void> | void;
|
|
130
|
-
/** Called when widget state changes (restored or updated) */
|
|
131
|
-
"widget-state-change": (widgetState: WidgetState | null) => void;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Listener for state changes.
|
|
135
|
-
*/
|
|
136
|
-
type StateListener = (state: HostClientState, prevState: HostClientState) => void;
|
|
137
|
-
/**
|
|
138
|
-
* Host client interface.
|
|
139
|
-
* Implemented by McpHostClient and ChatGPTHostClient.
|
|
140
|
-
*/
|
|
141
|
-
interface HostClient {
|
|
142
|
-
/** Get current state */
|
|
143
|
-
getState(): HostClientState;
|
|
144
|
-
/** Subscribe to state changes. Returns unsubscribe function. */
|
|
145
|
-
subscribe(listener: StateListener): () => void;
|
|
146
|
-
/** Call a tool on the MCP server */
|
|
147
|
-
callTool<T = Record<string, unknown>>(toolName: string, args: Record<string, unknown>): Promise<ToolResult<T>>;
|
|
148
|
-
/** Send a notification to the host (MCP Apps only, no-op on ChatGPT) */
|
|
149
|
-
sendNotification(method: string, params: unknown): void;
|
|
150
|
-
/** Set widget state */
|
|
151
|
-
setWidgetState(state: WidgetState | null): void;
|
|
152
|
-
/**
|
|
153
|
-
* Request a display mode change from the host.
|
|
154
|
-
*
|
|
155
|
-
* The host may refuse or coerce the request (e.g., "pip" → "fullscreen" on mobile).
|
|
156
|
-
* Always check `availableDisplayModes` in host context before calling, and handle
|
|
157
|
-
* the returned mode differing from the requested mode.
|
|
158
|
-
*
|
|
159
|
-
* @param params - Object containing the requested display mode
|
|
160
|
-
* @returns Promise resolving to the actual display mode granted by the host
|
|
161
|
-
*/
|
|
162
|
-
requestDisplayMode(params: {
|
|
163
|
-
mode: DisplayMode;
|
|
164
|
-
}): Promise<{
|
|
165
|
-
mode: DisplayMode;
|
|
166
|
-
}>;
|
|
167
|
-
/**
|
|
168
|
-
* Send a log message to the host's DevConsole.
|
|
169
|
-
*
|
|
170
|
-
* Logs are sent via the MCP protocol's `notifications/message` notification
|
|
171
|
-
* and displayed in the host's unified log viewer alongside server logs.
|
|
172
|
-
*
|
|
173
|
-
* @param level - Log severity level
|
|
174
|
-
* @param message - Log message
|
|
175
|
-
* @param data - Optional structured data to include
|
|
176
|
-
*/
|
|
177
|
-
log(level: LogLevel, message: string, data?: Record<string, unknown>): void;
|
|
178
|
-
/** Register an event handler. Returns unsubscribe function. */
|
|
179
|
-
on<K extends keyof HostClientEvents>(event: K, handler: HostClientEvents[K]): () => void;
|
|
180
|
-
/** Start listening for host messages */
|
|
181
|
-
connect(): void;
|
|
182
|
-
/** Stop listening for host messages */
|
|
183
|
-
disconnect(): void;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export type { AppSessionOptions as A, DisplayMode as D, Environment as E, HostClient as H, LogLevel as L, StructuredWidgetState as S, ToolResult as T, WidgetState as W, AppSessionState as a, AppSessionListener as b, HostContext as c, HostClientConfig as d, HostClientState as e, HostClientEvents as f, StateListener as g };
|