@uzuhq/code-sdk 0.7.6 → 0.7.7
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/dev-globals.d.ts +12 -27
- package/dist/dev-globals.js +0 -15
- package/dist/dev-hooks-ClWM8HzI.d.ts +682 -0
- package/dist/index.d.ts +152 -66
- package/dist/index.js +1837 -416
- package/package.json +8 -5
- package/dist/action-types.test-d.d.ts +0 -11
- package/dist/action-types.test-d.js +0 -101
- package/dist/dev-hooks.d.ts +0 -241
- package/dist/dev-hooks.js +0 -132
- package/dist/dev-hooks.test.d.ts +0 -1
- package/dist/dev-hooks.test.js +0 -294
- package/dist/dev-prediction-traps.d.ts +0 -32
- package/dist/dev-prediction-traps.js +0 -0
- package/dist/dev-prediction-traps.test.d.ts +0 -1
- package/dist/dev-prediction-traps.test.js +0 -178
- package/dist/dev-state-patch.d.ts +0 -81
- package/dist/dev-state-patch.js +0 -295
- package/dist/dev-state-patch.test.d.ts +0 -1
- package/dist/dev-state-patch.test.js +0 -333
- package/dist/json-patch.d.ts +0 -7
- package/dist/json-patch.js +0 -78
- package/dist/random.d.ts +0 -11
- package/dist/random.js +0 -34
- package/dist/reconnectable-ws.d.ts +0 -60
- package/dist/reconnectable-ws.js +0 -229
- package/dist/room.d.ts +0 -23
- package/dist/room.js +0 -36
- package/dist/roster-params.test.d.ts +0 -1
- package/dist/roster-params.test.js +0 -86
- package/dist/run/local-server-action.d.ts +0 -16
- package/dist/run/local-server-action.js +0 -217
- package/dist/run/local-server-action.test.d.ts +0 -1
- package/dist/run/local-server-action.test.js +0 -242
- package/dist/run/optimistic-action-client.d.ts +0 -68
- package/dist/run/optimistic-action-client.js +0 -209
- package/dist/run/optimistic-action-client.test.d.ts +0 -1
- package/dist/run/optimistic-action-client.test.js +0 -430
- package/dist/run/server-action.d.ts +0 -16
- package/dist/run/server-action.js +0 -181
- package/dist/run/server-action.test.d.ts +0 -1
- package/dist/run/server-action.test.js +0 -105
- package/dist/server-clock.d.ts +0 -29
- package/dist/server-clock.js +0 -40
- package/dist/server-only.d.ts +0 -33
- package/dist/server-only.js +0 -21
- package/dist/sync/local.d.ts +0 -8
- package/dist/sync/local.js +0 -50
- package/dist/sync/online.d.ts +0 -5
- package/dist/sync/online.js +0 -165
- package/dist/types.d.ts +0 -345
- package/dist/types.js +0 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,72 +1,156 @@
|
|
|
1
|
+
import { $ as applyJsonMergePatch, A as DEFAULT_ICON_URLS, B as ServerActionContext, C as SetFn, D as ActionContext, E as ActionArgs, F as GameLogic, G as ServerOnlyActionContext, H as ServerActionMap, I as SERVER_TIME, J as SetupContext, K as ServerOnlyActionHandlerFn, L as Seat, M as DeadlineArgs, N as DeadlineContext, O as ActionHandler, P as Emit, Q as JsonPatchOp, R as SeededRandom, S as SendAction, T as Operation, U as ServerEvent, V as ServerActionHandler, W as ServerOnlyAction, X as UpdateContext, Y as UpdateArgs, Z as JsonMergePatch, _ as PayloadMap, a as attachDevHooks, b as PlayersChangedMessage, c as getPredictionWarnings, d as ConnectionCallbacks, et as applyJsonPatch, f as ConnectionState, g as PatchFn, h as GameConfig, i as UzuDevHooks, j as Deadline, k as ActionMap, l as BridgeChannel, m as EventSubscription, n as RunHandle, o as createDevHooks, p as EventHandler, q as SetupArgs, r as SyncHandle, s as PredictionWarning, t as DevHooksCtx, u as BridgeMessage, v as PlayScreenMessage, w as SyncConfig, x as SeatKind, y as PlayerVoiceState, z as ServerActionArgs } from "./dev-hooks-ClWM8HzI.js";
|
|
2
|
+
//#region ../engine-core/src/random.d.ts
|
|
3
|
+
declare class SeededRandomImpl implements SeededRandom {
|
|
4
|
+
private _state;
|
|
5
|
+
constructor(seed: number);
|
|
6
|
+
get state(): number;
|
|
7
|
+
static fromState(state: number): SeededRandomImpl;
|
|
8
|
+
float(): number;
|
|
9
|
+
int(max: number): number;
|
|
10
|
+
pick<T>(array: T[]): T;
|
|
11
|
+
shuffle<T>(array: T[]): T[];
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region ../engine-core/src/server-only.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated `logic.serverActions` に直接書く。
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* // before
|
|
20
|
+
* actions: { notifyExternal: serverOnly(async (state) => { ... }) }
|
|
21
|
+
* // after
|
|
22
|
+
* serverActions: { notifyExternal: async (state) => { ... } }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare function serverOnly<S>(handler: ServerActionHandler<S>): ServerOnlyAction<S>;
|
|
26
|
+
/**
|
|
27
|
+
* handler が `serverOnly()` で wrap されているか判定する。
|
|
28
|
+
*
|
|
29
|
+
* 移行期の互換用。`serverActions` へ移行済みの logic では常に false になる。
|
|
30
|
+
*/
|
|
31
|
+
declare function isServerOnlyAction<S>(handler: ActionHandler<S> | ServerActionHandler<S> | ServerOnlyAction<S> | undefined): handler is ServerOnlyAction<S>;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/server-clock.d.ts
|
|
1
34
|
/**
|
|
2
|
-
*
|
|
3
|
-
* - SDK仕様: docs/docs/uzu_code/play-screen-sdk.md
|
|
4
|
-
* - ブリッジ仕様: docs/docs/uzu_code/bridge.md
|
|
5
|
-
* - Relay仕様: docs/docs/uzu_code/relay.md
|
|
6
|
-
* - SyncRoom仕様: docs/docs/uzu_code/sync-room.md
|
|
7
|
-
* - ゲーム仕様: docs/docs/uzu_code/games.md
|
|
8
|
-
* - システム全体像: docs/docs/uzu_code/overview.md
|
|
9
|
-
* - AI用APIリファレンス (README): javascript/uzu_code/sdk/README.md
|
|
35
|
+
* サーバー時刻の推定値 (ms)。
|
|
10
36
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* `@uzuhq/code-cli` の `uzu dev` サブコマンドに統合されている。 parent frame で
|
|
14
|
-
* `init()` / `run()` / `sync()` を呼んでも何もしない (= noop)。 harness を立てるには
|
|
15
|
-
* scenario ディレクトリで `uzu dev` を実行するだけで良い。 子 iframe は既存 online mode
|
|
16
|
-
* (`?server=ws://localhost:<port>` 経路) で dev-server に接続する。
|
|
37
|
+
* カウントダウン描画のように毎秒/毎フレーム呼ぶ用途を想定しているので、
|
|
38
|
+
* state の到着とは無関係にいつでも呼べる。
|
|
17
39
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
declare function serverNow(): number;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/room.d.ts
|
|
43
|
+
type RoomMessageHandler = (data: Record<string, unknown>) => void;
|
|
44
|
+
/** WebSocket 互換の send/addEventListener インターフェース */
|
|
45
|
+
interface WebSocketLike {
|
|
46
|
+
send(data: string): void;
|
|
47
|
+
addEventListener(type: 'message', handler: (ev: MessageEvent) => void): void;
|
|
48
|
+
}
|
|
49
|
+
/** Room の公開インターフェース。WebSocket / BroadcastChannel どちらでも実装可能。 */
|
|
50
|
+
interface RoomLike {
|
|
51
|
+
readonly myId: string;
|
|
52
|
+
broadcast(msg: Record<string, unknown>): void;
|
|
53
|
+
send(id: string, msg: Record<string, unknown>): void;
|
|
54
|
+
on(type: string, handler: RoomMessageHandler): void;
|
|
55
|
+
}
|
|
56
|
+
declare class Room implements RoomLike {
|
|
57
|
+
readonly myId: string;
|
|
58
|
+
private ws;
|
|
59
|
+
private handlers;
|
|
60
|
+
constructor(ws: WebSocketLike, myId: string);
|
|
61
|
+
broadcast(msg: Record<string, unknown>): void;
|
|
62
|
+
send(id: string, msg: Record<string, unknown>): void;
|
|
63
|
+
on(type: string, handler: RoomMessageHandler): void;
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/reconnectable-ws.d.ts
|
|
67
|
+
/**
|
|
68
|
+
* 自動再接続 WebSocket ラッパー
|
|
69
|
+
*
|
|
70
|
+
* - Exponential backoff + jitter 付き自動再接続
|
|
71
|
+
* - Heartbeat (__ping / __pong) による接続生存確認
|
|
72
|
+
* - 再接続中のメッセージバッファリング
|
|
73
|
+
*/
|
|
74
|
+
type ConnectionState$1 = 'connecting' | 'connected' | 'reconnecting' | 'disconnected';
|
|
75
|
+
interface ReconnectableWSOptions {
|
|
76
|
+
/** 最大再接続試行回数 (default: 15) */
|
|
77
|
+
maxReconnectAttempts?: number;
|
|
78
|
+
/** Backoff の基準遅延 ms (default: 1000) */
|
|
79
|
+
baseDelay?: number;
|
|
80
|
+
/** Backoff の最大遅延 ms (default: 30000) */
|
|
81
|
+
maxDelay?: number;
|
|
82
|
+
/** Jitter 係数 0〜1 (default: 0.5) */
|
|
83
|
+
jitterFactor?: number;
|
|
84
|
+
/** Heartbeat 送信間隔 ms (default: 25000) */
|
|
85
|
+
heartbeatInterval?: number;
|
|
86
|
+
/** Pong 待ちタイムアウト ms (default: 10000) */
|
|
87
|
+
heartbeatTimeout?: number;
|
|
88
|
+
/** 再接続中のバッファ上限 (default: 50) */
|
|
89
|
+
maxBufferSize?: number;
|
|
90
|
+
/** バッファ対象判定。false を返すとドロップ */
|
|
91
|
+
shouldBuffer?: (data: string) => boolean;
|
|
92
|
+
/** 接続状態変更コールバック */
|
|
93
|
+
onConnectionStateChange?: (state: ConnectionState$1) => void;
|
|
94
|
+
}
|
|
95
|
+
declare class ReconnectableWebSocket {
|
|
96
|
+
private ws;
|
|
97
|
+
private readonly url;
|
|
98
|
+
private readonly opts;
|
|
99
|
+
private _state;
|
|
100
|
+
private reconnectAttempt;
|
|
101
|
+
private messageBuffer;
|
|
102
|
+
private messageHandlers;
|
|
103
|
+
private heartbeatTimer;
|
|
104
|
+
private heartbeatTimeoutTimer;
|
|
105
|
+
private reconnectTimer;
|
|
106
|
+
private disposed;
|
|
107
|
+
constructor(url: string, options?: ReconnectableWSOptions);
|
|
108
|
+
get connectionState(): ConnectionState$1;
|
|
109
|
+
/** WebSocket.readyState 互換 (既存コードとの互換用) */
|
|
110
|
+
get readyState(): number;
|
|
111
|
+
send(data: string): void;
|
|
112
|
+
addEventListener(type: 'message', handler: (ev: MessageEvent) => void): void;
|
|
113
|
+
removeEventListener(type: 'message', handler: (ev: MessageEvent) => void): void;
|
|
114
|
+
/** バッファをクリア(権威的 state 受信時に呼ぶ) */
|
|
115
|
+
clearBuffer(): void;
|
|
116
|
+
/** 全リソース解放 */
|
|
117
|
+
dispose(): void;
|
|
118
|
+
private connect;
|
|
119
|
+
private setState;
|
|
120
|
+
private scheduleReconnect;
|
|
121
|
+
private getReconnectDelay;
|
|
122
|
+
private flushBuffer;
|
|
123
|
+
private startHeartbeat;
|
|
124
|
+
private stopHeartbeat;
|
|
125
|
+
private handlePong;
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/index.d.ts
|
|
35
129
|
type GameMessageHandler = (payload: Record<string, unknown>) => void;
|
|
36
130
|
type PlayersChangedHandler = (players: Record<string, PlayerVoiceState>) => void;
|
|
37
|
-
declare
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export declare function init(opts?: {
|
|
51
|
-
wsEndpoint?: string;
|
|
52
|
-
syncEndpoint?: string;
|
|
53
|
-
playerCount?: number;
|
|
54
|
-
orientation?: 'portrait' | 'landscape';
|
|
55
|
-
/**
|
|
56
|
-
* Dev harness の iframe inner viewport 短辺 (CSS px) の下限。default 360。
|
|
57
|
-
* harness 側で参照される値で、 SDK runtime 本体は使わない。
|
|
58
|
-
*/
|
|
59
|
-
devMinIframeShortEdge?: number;
|
|
131
|
+
declare const isHosted: boolean;
|
|
132
|
+
declare function getRoom(): RoomLike | null;
|
|
133
|
+
declare function onRoom(callback: (room: RoomLike) => void): void;
|
|
134
|
+
declare function init(opts?: {
|
|
135
|
+
wsEndpoint?: string;
|
|
136
|
+
syncEndpoint?: string;
|
|
137
|
+
playerCount?: number;
|
|
138
|
+
orientation?: 'portrait' | 'landscape';
|
|
139
|
+
/**
|
|
140
|
+
* Dev harness の iframe inner viewport 短辺 (CSS px) の下限。default 360。
|
|
141
|
+
* harness 側で参照される値で、 SDK runtime 本体は使わない。
|
|
142
|
+
*/
|
|
143
|
+
devMinIframeShortEdge?: number;
|
|
60
144
|
}): void;
|
|
61
145
|
/** game channel でカスタムメッセージを送信する。 native コマンドには使用不可。 */
|
|
62
|
-
|
|
146
|
+
declare function send(type: string, payload?: Record<string, unknown>): void;
|
|
63
147
|
/** game channel のカスタムメッセージを受信する。 */
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
148
|
+
declare function on(type: string, handler: GameMessageHandler): void;
|
|
149
|
+
declare function playSound(sound: string): void;
|
|
150
|
+
declare function playBgm(sound: string): void;
|
|
151
|
+
declare function stopBgm(): void;
|
|
152
|
+
declare function setMicEnabled(enabled: boolean): void;
|
|
153
|
+
declare function changeRoom(roomId: string | null): void;
|
|
70
154
|
/**
|
|
71
155
|
* splash 描画完了を Flutter ホストに通知する。
|
|
72
156
|
*
|
|
@@ -83,7 +167,7 @@ export declare function changeRoom(roomId: string | null): void;
|
|
|
83
167
|
* requestAnimationFrame(() => firstFrameReady());
|
|
84
168
|
* ```
|
|
85
169
|
*/
|
|
86
|
-
|
|
170
|
+
declare function firstFrameReady(): void;
|
|
87
171
|
/**
|
|
88
172
|
* ユーザー操作受付可能を Flutter ホストに通知する。
|
|
89
173
|
*
|
|
@@ -100,9 +184,9 @@ export declare function firstFrameReady(): void;
|
|
|
100
184
|
* gameReady();
|
|
101
185
|
* ```
|
|
102
186
|
*/
|
|
103
|
-
|
|
187
|
+
declare function gameReady(): void;
|
|
104
188
|
/** Flutter からの playersChanged メッセージを受信するハンドラを登録する。 */
|
|
105
|
-
|
|
189
|
+
declare function onPlayersChanged(handler: PlayersChangedHandler): void;
|
|
106
190
|
/**
|
|
107
191
|
* `A` に既定値が要る。 TypeScript は型引数の部分推論ができないので、 既定が無いと
|
|
108
192
|
* 既存の `run<State>({…})` が「2 つ必要」で落ちる。 既定を置けば型引数を書かない
|
|
@@ -112,5 +196,7 @@ export declare function onPlayersChanged(handler: PlayersChangedHandler): void;
|
|
|
112
196
|
* `keyof (A & SA)` が `string` へ潰れ、action 名の検査が丸ごと消える。
|
|
113
197
|
* `serverActions` を持たない logic でもキーが残るよう空 map を既定にする。
|
|
114
198
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
199
|
+
declare function run<S, A extends ActionMap<S> = ActionMap<S>, SA extends ServerActionMap<S> = Record<never, never>>(config: GameConfig<S, A, SA>): void;
|
|
200
|
+
declare function sync<S>(config: SyncConfig<S>): void;
|
|
201
|
+
//#endregion
|
|
202
|
+
export { type ActionArgs, type ActionContext, type ActionHandler, type ActionMap, type BridgeChannel, type BridgeMessage, type ConnectionCallbacks, type ConnectionState, DEFAULT_ICON_URLS, type Deadline, type DeadlineArgs, type DeadlineContext, type DevHooksCtx, type Emit, type EventHandler, type EventSubscription, type GameConfig, type GameLogic, type JsonMergePatch, type JsonPatchOp, type Operation, type PatchFn, type PayloadMap, type PlayScreenMessage, type PlayerVoiceState, type PlayersChangedMessage, type PredictionWarning, type ReconnectableWSOptions, ReconnectableWebSocket, Room, type RoomLike, type RunHandle, SERVER_TIME, type Seat, type SeatKind, type SeededRandom, SeededRandomImpl, type SendAction, type ServerActionArgs, type ServerActionContext, type ServerActionHandler, type ServerActionMap, type ServerEvent, type ServerOnlyAction, type ServerOnlyActionContext, type ServerOnlyActionHandlerFn, type SetFn, type SetupArgs, type SetupContext, type SyncConfig, type SyncHandle, type UpdateArgs, type UpdateContext, type UzuDevHooks, applyJsonMergePatch, applyJsonPatch, attachDevHooks, changeRoom, createDevHooks, firstFrameReady, gameReady, getPredictionWarnings, getRoom, init, isHosted, isServerOnlyAction, on, onPlayersChanged, onRoom, playBgm, playSound, run, send, serverNow, serverOnly, setMicEnabled, stopBgm, sync };
|