@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.
Files changed (45) hide show
  1. package/dist/core/index.d.ts +3 -0
  2. package/dist/core/index.js +3 -0
  3. package/dist/core/kokimoki-client.d.ts +361 -0
  4. package/dist/core/kokimoki-client.js +819 -0
  5. package/dist/core/room-subscription-mode.d.ts +5 -0
  6. package/dist/core/room-subscription-mode.js +6 -0
  7. package/dist/core/room-subscription.d.ts +15 -0
  8. package/dist/core/room-subscription.js +53 -0
  9. package/dist/index.d.ts +4 -7
  10. package/dist/index.js +4 -7
  11. package/dist/kokimoki.min.d.ts +55 -59
  12. package/dist/kokimoki.min.js +3076 -1790
  13. package/dist/kokimoki.min.js.map +1 -1
  14. package/dist/llms.txt +75 -67
  15. package/dist/protocol/ws-message/index.d.ts +3 -0
  16. package/dist/protocol/ws-message/index.js +3 -0
  17. package/dist/protocol/ws-message/reader.d.ts +11 -0
  18. package/dist/protocol/ws-message/reader.js +36 -0
  19. package/dist/protocol/ws-message/type.d.ts +11 -0
  20. package/dist/protocol/ws-message/type.js +12 -0
  21. package/dist/protocol/ws-message/writer.d.ts +9 -0
  22. package/dist/protocol/ws-message/writer.js +45 -0
  23. package/dist/services/index.d.ts +3 -0
  24. package/dist/services/index.js +3 -0
  25. package/dist/services/kokimoki-ai.d.ts +153 -0
  26. package/dist/services/kokimoki-ai.js +164 -0
  27. package/dist/services/kokimoki-leaderboard.d.ts +175 -0
  28. package/dist/services/kokimoki-leaderboard.js +203 -0
  29. package/dist/services/kokimoki-storage.d.ts +155 -0
  30. package/dist/services/kokimoki-storage.js +208 -0
  31. package/dist/stores/index.d.ts +3 -0
  32. package/dist/stores/index.js +3 -0
  33. package/dist/stores/kokimoki-local-store.d.ts +11 -0
  34. package/dist/stores/kokimoki-local-store.js +40 -0
  35. package/dist/stores/kokimoki-store.d.ts +22 -0
  36. package/dist/stores/kokimoki-store.js +117 -0
  37. package/dist/stores/kokimoki-transaction.d.ts +18 -0
  38. package/dist/stores/kokimoki-transaction.js +143 -0
  39. package/dist/types/index.d.ts +3 -0
  40. package/dist/types/index.js +3 -0
  41. package/dist/utils/valtio.d.ts +7 -0
  42. package/dist/utils/valtio.js +6 -0
  43. package/dist/version.d.ts +1 -1
  44. package/dist/version.js +2 -1
  45. package/package.json +4 -3
@@ -0,0 +1,5 @@
1
+ export declare enum RoomSubscriptionMode {
2
+ Read = "r",
3
+ Write = "w",
4
+ ReadWrite = "b"
5
+ }
@@ -0,0 +1,6 @@
1
+ export var RoomSubscriptionMode;
2
+ (function (RoomSubscriptionMode) {
3
+ RoomSubscriptionMode["Read"] = "r";
4
+ RoomSubscriptionMode["Write"] = "w";
5
+ RoomSubscriptionMode["ReadWrite"] = "b";
6
+ })(RoomSubscriptionMode || (RoomSubscriptionMode = {}));
@@ -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 * from "./types/common";
2
- export * from "./types/events";
3
- export * from "./types/upload";
4
- export * from "./kokimoki-client";
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 * from "./types/common";
2
- export * from "./types/events";
3
- export * from "./types/upload";
4
- export * from "./kokimoki-client";
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";
@@ -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 KokimokiAi {
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 KokimokiLeaderboard {
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 KokimokiStorage {
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: new () => TypedEmitter<KokimokiClientEvents>;
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(): KokimokiAi;
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(): KokimokiStorage;
892
+ get storage(): KokimokiStorageService;
894
893
  /**
895
894
  * Access player ranking and score tracking with efficient queries and pagination.
896
895
  */
897
- get leaderboard(): KokimokiLeaderboard;
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 class RoomSubscription {
901
- private kmClient;
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, type KokimokiClientEvents, KokimokiStore, type Paginated, RoomSubscription, RoomSubscriptionMode, type Upload };
909
+ export { KokimokiClient, KokimokiStore };
910
+ export type { KokimokiClientEvents, Paginated, Upload };