@kokimoki/app 2.0.0 → 2.0.2
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 +3 -0
- package/dist/core/index.js +3 -0
- package/dist/core/kokimoki-client.d.ts +361 -0
- package/dist/core/kokimoki-client.js +819 -0
- package/dist/core/room-subscription-mode.d.ts +5 -0
- package/dist/core/room-subscription-mode.js +6 -0
- package/dist/core/room-subscription.d.ts +15 -0
- package/dist/core/room-subscription.js +53 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.js +4 -7
- package/dist/kokimoki.min.d.ts +55 -59
- package/dist/kokimoki.min.js +3076 -1790
- package/dist/kokimoki.min.js.map +1 -1
- package/dist/llms.txt +75 -67
- package/dist/protocol/ws-message/index.d.ts +3 -0
- package/dist/protocol/ws-message/index.js +3 -0
- package/dist/protocol/ws-message/reader.d.ts +11 -0
- package/dist/protocol/ws-message/reader.js +36 -0
- package/dist/protocol/ws-message/type.d.ts +11 -0
- package/dist/protocol/ws-message/type.js +12 -0
- package/dist/protocol/ws-message/writer.d.ts +9 -0
- package/dist/protocol/ws-message/writer.js +45 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +3 -0
- package/dist/services/kokimoki-ai.d.ts +153 -0
- package/dist/services/kokimoki-ai.js +164 -0
- package/dist/services/kokimoki-leaderboard.d.ts +175 -0
- package/dist/services/kokimoki-leaderboard.js +203 -0
- package/dist/services/kokimoki-storage.d.ts +155 -0
- package/dist/services/kokimoki-storage.js +208 -0
- package/dist/stores/index.d.ts +3 -0
- package/dist/stores/index.js +3 -0
- package/dist/stores/kokimoki-local-store.d.ts +11 -0
- package/dist/stores/kokimoki-local-store.js +40 -0
- package/dist/stores/kokimoki-store.d.ts +22 -0
- package/dist/stores/kokimoki-store.js +117 -0
- package/dist/stores/kokimoki-transaction.d.ts +18 -0
- package/dist/stores/kokimoki-transaction.js +143 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +3 -0
- package/dist/utils/valtio.d.ts +7 -0
- package/dist/utils/valtio.js +6 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -1
- package/package.json +4 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { KokimokiStore } from "../stores";
|
|
2
|
+
import type { KokimokiClient } from "./kokimoki-client";
|
|
3
|
+
export declare class RoomSubscription {
|
|
4
|
+
private kmClient;
|
|
5
|
+
readonly store: KokimokiStore<any>;
|
|
6
|
+
private _joined;
|
|
7
|
+
private _roomHash?;
|
|
8
|
+
private _onDisconnect;
|
|
9
|
+
constructor(kmClient: KokimokiClient, store: KokimokiStore<any>);
|
|
10
|
+
get roomName(): string;
|
|
11
|
+
get roomHash(): number;
|
|
12
|
+
get joined(): boolean;
|
|
13
|
+
applyInitialResponse(roomHash: number, initialUpdate?: Uint8Array): Promise<void>;
|
|
14
|
+
close(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as Y from "yjs";
|
|
2
|
+
import { RoomSubscriptionMode } from "./room-subscription-mode";
|
|
3
|
+
export class RoomSubscription {
|
|
4
|
+
kmClient;
|
|
5
|
+
store;
|
|
6
|
+
_joined = false;
|
|
7
|
+
_roomHash;
|
|
8
|
+
_onDisconnect = () => {
|
|
9
|
+
this._joined = false;
|
|
10
|
+
};
|
|
11
|
+
constructor(kmClient, store) {
|
|
12
|
+
this.kmClient = kmClient;
|
|
13
|
+
this.store = store;
|
|
14
|
+
kmClient.on("disconnected", this._onDisconnect);
|
|
15
|
+
}
|
|
16
|
+
get roomName() {
|
|
17
|
+
return this.store.roomName;
|
|
18
|
+
}
|
|
19
|
+
get roomHash() {
|
|
20
|
+
if (!this._roomHash) {
|
|
21
|
+
throw new Error("Room not joined");
|
|
22
|
+
}
|
|
23
|
+
return this._roomHash;
|
|
24
|
+
}
|
|
25
|
+
get joined() {
|
|
26
|
+
return this._joined;
|
|
27
|
+
}
|
|
28
|
+
async applyInitialResponse(roomHash, initialUpdate) {
|
|
29
|
+
this._roomHash = roomHash;
|
|
30
|
+
// Apply initial state
|
|
31
|
+
if (initialUpdate) {
|
|
32
|
+
Y.applyUpdate(this.store.doc, initialUpdate, this);
|
|
33
|
+
}
|
|
34
|
+
// Set defaults if doc is empty after sync (only possible in ReadWrite mode)
|
|
35
|
+
if (this.store.mode === RoomSubscriptionMode.ReadWrite) {
|
|
36
|
+
await this.kmClient.transact([this.store], ([state]) => {
|
|
37
|
+
if (!("_connections" in state)) {
|
|
38
|
+
state._connections = {};
|
|
39
|
+
}
|
|
40
|
+
for (const key in this.store.defaultValue) {
|
|
41
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
42
|
+
if (!state.hasOwnProperty(key)) {
|
|
43
|
+
state[key] = this.store.defaultValue[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
this._joined = true;
|
|
49
|
+
}
|
|
50
|
+
close() {
|
|
51
|
+
this.kmClient.off("disconnected", this._onDisconnect);
|
|
52
|
+
}
|
|
53
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./kokimoki-store";
|
|
6
|
-
export * from "./room-subscription";
|
|
7
|
-
export * from "./room-subscription-mode";
|
|
1
|
+
export { KokimokiClient } from "./core";
|
|
2
|
+
export { KokimokiStore } from "./stores";
|
|
3
|
+
export type { KokimokiClientEvents, Paginated, Upload } from "./types";
|
|
4
|
+
export * from "./utils/valtio";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./kokimoki-store";
|
|
6
|
-
export * from "./room-subscription";
|
|
7
|
-
export * from "./room-subscription-mode";
|
|
1
|
+
export { KokimokiClient } from "./core";
|
|
2
|
+
export { KokimokiStore } from "./stores";
|
|
3
|
+
// Re-export Valtio utilities
|
|
4
|
+
export * from "./utils/valtio";
|
package/dist/kokimoki.min.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import TypedEmitter from 'typed-emitter';
|
|
2
|
-
import * as Y from 'yjs';
|
|
3
2
|
import { Snapshot } from 'valtio/vanilla';
|
|
3
|
+
import * as Y from 'yjs';
|
|
4
|
+
export { proxy, ref, snapshot, subscribe, useSnapshot } from 'valtio';
|
|
5
|
+
export { derive, underive } from 'derive-valtio';
|
|
6
|
+
export { devtools, subscribeKey, useProxy, watch } from 'valtio/utils';
|
|
4
7
|
|
|
5
8
|
interface Paginated<T> {
|
|
6
9
|
items: T[];
|
|
@@ -25,43 +28,6 @@ interface Upload {
|
|
|
25
28
|
tags: string[];
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
declare enum RoomSubscriptionMode {
|
|
29
|
-
Read = "r",
|
|
30
|
-
Write = "w",
|
|
31
|
-
ReadWrite = "b"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare class KokimokiStore<T extends object> {
|
|
35
|
-
readonly roomName: string;
|
|
36
|
-
readonly defaultValue: T;
|
|
37
|
-
readonly mode: RoomSubscriptionMode;
|
|
38
|
-
readonly doc: Y.Doc;
|
|
39
|
-
readonly proxy: T;
|
|
40
|
-
readonly docRoot: Y.Map<unknown>;
|
|
41
|
-
readonly connections: {
|
|
42
|
-
connectionIds: Set<string>;
|
|
43
|
-
clientIds: Set<string>;
|
|
44
|
-
};
|
|
45
|
-
private _unsubscribeConnectionsHandler;
|
|
46
|
-
constructor(roomName: string, defaultValue: T, mode?: RoomSubscriptionMode);
|
|
47
|
-
get(): Snapshot<T>;
|
|
48
|
-
subscribe(set: (value: Snapshot<T>) => void): () => void;
|
|
49
|
-
onJoin(client: KokimokiClient<any>): Promise<void>;
|
|
50
|
-
onBeforeLeave(client: KokimokiClient): Promise<void>;
|
|
51
|
-
onLeave(client: KokimokiClient): Promise<void>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
declare class KokimokiLocalStore<T extends object> extends KokimokiStore<T> {
|
|
55
|
-
private readonly localRoomName;
|
|
56
|
-
private _stateKey?;
|
|
57
|
-
private get stateKey();
|
|
58
|
-
constructor(localRoomName: string, defaultState: T);
|
|
59
|
-
getInitialUpdate(appId: string, clientId: string): {
|
|
60
|
-
roomHash: number;
|
|
61
|
-
initialUpdate: Uint8Array | undefined;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
31
|
/**
|
|
66
32
|
* Kokimoki AI Integration Service
|
|
67
33
|
*
|
|
@@ -111,7 +77,7 @@ declare class KokimokiLocalStore<T extends object> extends KokimokiStore<T> {
|
|
|
111
77
|
* );
|
|
112
78
|
* ```
|
|
113
79
|
*/
|
|
114
|
-
declare class
|
|
80
|
+
declare class KokimokiAiService {
|
|
115
81
|
private readonly client;
|
|
116
82
|
constructor(client: KokimokiClient);
|
|
117
83
|
/**
|
|
@@ -211,7 +177,7 @@ declare class KokimokiAi {
|
|
|
211
177
|
* @param tags Optional. Tags to associate with the image.
|
|
212
178
|
* @returns A promise that resolves to the modified image upload information.
|
|
213
179
|
*/
|
|
214
|
-
modifyImage(baseImageUrl: string, prompt: string, tags?: string[]): Promise<Upload>;
|
|
180
|
+
modifyImage(baseImageUrl: string, prompt: string, tags?: string[], model?: 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview'): Promise<Upload>;
|
|
215
181
|
}
|
|
216
182
|
|
|
217
183
|
/**
|
|
@@ -261,7 +227,7 @@ declare class KokimokiAi {
|
|
|
261
227
|
* const best = await kmClient.leaderboard.getBestEntry('high-scores', 'desc');
|
|
262
228
|
* ```
|
|
263
229
|
*/
|
|
264
|
-
declare class
|
|
230
|
+
declare class KokimokiLeaderboardService {
|
|
265
231
|
private readonly client;
|
|
266
232
|
constructor(client: KokimokiClient);
|
|
267
233
|
/**
|
|
@@ -426,7 +392,7 @@ declare class KokimokiLeaderboard {
|
|
|
426
392
|
* });
|
|
427
393
|
* ```
|
|
428
394
|
*/
|
|
429
|
-
declare class
|
|
395
|
+
declare class KokimokiStorageService {
|
|
430
396
|
private readonly client;
|
|
431
397
|
constructor(client: KokimokiClient);
|
|
432
398
|
private createUpload;
|
|
@@ -542,11 +508,44 @@ declare class KokimokiStorage {
|
|
|
542
508
|
}>;
|
|
543
509
|
}
|
|
544
510
|
|
|
511
|
+
declare class KokimokiStore<T extends object> {
|
|
512
|
+
readonly roomName: string;
|
|
513
|
+
readonly defaultValue: T;
|
|
514
|
+
readonly mode: RoomSubscriptionMode;
|
|
515
|
+
readonly doc: Y.Doc;
|
|
516
|
+
readonly proxy: T;
|
|
517
|
+
readonly docRoot: Y.Map<unknown>;
|
|
518
|
+
readonly connections: {
|
|
519
|
+
connectionIds: Set<string>;
|
|
520
|
+
clientIds: Set<string>;
|
|
521
|
+
};
|
|
522
|
+
private _unsubscribeConnectionsHandler;
|
|
523
|
+
constructor(roomName: string, defaultValue: T, mode?: RoomSubscriptionMode);
|
|
524
|
+
get(): Snapshot<T>;
|
|
525
|
+
subscribe(set: (value: Snapshot<T>) => void): () => void;
|
|
526
|
+
onJoin(client: KokimokiClient<any>): Promise<void>;
|
|
527
|
+
onBeforeLeave(_client: KokimokiClient): Promise<void>;
|
|
528
|
+
onLeave(_client: KokimokiClient): Promise<void>;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
declare class KokimokiLocalStore<T extends object> extends KokimokiStore<T> {
|
|
532
|
+
private readonly localRoomName;
|
|
533
|
+
private _stateKey?;
|
|
534
|
+
private get stateKey();
|
|
535
|
+
constructor(localRoomName: string, defaultState: T);
|
|
536
|
+
getInitialUpdate(appId: string, clientId: string): {
|
|
537
|
+
roomHash: number;
|
|
538
|
+
initialUpdate: Uint8Array<ArrayBufferLike> | undefined;
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
545
542
|
type Mutable<T> = {
|
|
546
543
|
-readonly [K in keyof T]: T[K] extends object ? Mutable<T[K]> : T[K];
|
|
547
544
|
};
|
|
548
545
|
type StoreValue<S> = S extends KokimokiStore<infer U> ? Mutable<U> : never;
|
|
549
|
-
declare const KokimokiClient_base:
|
|
546
|
+
declare const KokimokiClient_base: {
|
|
547
|
+
new (): TypedEmitter<KokimokiClientEvents>;
|
|
548
|
+
};
|
|
550
549
|
/**
|
|
551
550
|
* Kokimoki Client - Real-time Collaborative Game Development SDK
|
|
552
551
|
*
|
|
@@ -886,29 +885,26 @@ declare class KokimokiClient<ClientContextT = any> extends KokimokiClient_base {
|
|
|
886
885
|
/**
|
|
887
886
|
* Access AI capabilities including text generation, structured JSON output, and image modification.
|
|
888
887
|
*/
|
|
889
|
-
get ai():
|
|
888
|
+
get ai(): KokimokiAiService;
|
|
890
889
|
/**
|
|
891
890
|
* Access file upload and management for media files, images, and user-generated content.
|
|
892
891
|
*/
|
|
893
|
-
get storage():
|
|
892
|
+
get storage(): KokimokiStorageService;
|
|
894
893
|
/**
|
|
895
894
|
* Access player ranking and score tracking with efficient queries and pagination.
|
|
896
895
|
*/
|
|
897
|
-
get leaderboard():
|
|
896
|
+
get leaderboard(): KokimokiLeaderboardService;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
declare enum RoomSubscriptionMode {
|
|
900
|
+
Read = "r",
|
|
901
|
+
Write = "w",
|
|
902
|
+
ReadWrite = "b"
|
|
898
903
|
}
|
|
899
904
|
|
|
900
|
-
declare
|
|
901
|
-
|
|
902
|
-
readonly store: KokimokiStore<any>;
|
|
903
|
-
private _joined;
|
|
904
|
-
private _roomHash?;
|
|
905
|
-
private _onDisconnect;
|
|
906
|
-
constructor(kmClient: KokimokiClient, store: KokimokiStore<any>);
|
|
907
|
-
get roomName(): string;
|
|
908
|
-
get roomHash(): number;
|
|
909
|
-
get joined(): boolean;
|
|
910
|
-
applyInitialResponse(roomHash: number, initialUpdate?: Uint8Array): Promise<void>;
|
|
911
|
-
close(): void;
|
|
905
|
+
declare module "valtio" {
|
|
906
|
+
function useSnapshot<T extends object>(p: T): T;
|
|
912
907
|
}
|
|
913
908
|
|
|
914
|
-
export { KokimokiClient,
|
|
909
|
+
export { KokimokiClient, KokimokiStore };
|
|
910
|
+
export type { KokimokiClientEvents, Paginated, Upload };
|