@kokimoki/app 3.1.3 → 3.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.
Files changed (61) hide show
  1. package/README.md +1 -2
  2. package/dist/core/kokimoki-client.d.ts +4 -4
  3. package/dist/core/kokimoki-client.js +4 -4
  4. package/dist/kokimoki.min.d.ts +3 -321
  5. package/dist/kokimoki.min.js +763 -2014
  6. package/dist/kokimoki.min.js.map +1 -1
  7. package/dist/utils/valtio.d.ts +2 -5
  8. package/dist/utils/valtio.js +4 -2
  9. package/dist/version.d.ts +1 -1
  10. package/dist/version.js +1 -1
  11. package/docs/kokimoki-ai.instructions.md +4 -2
  12. package/docs/kokimoki-dynamic-stores.instructions.md +3 -3
  13. package/docs/kokimoki-i18n.instructions.md +1 -1
  14. package/docs/kokimoki-sdk.instructions.md +46 -7
  15. package/package.json +8 -2
  16. package/dist/fields.d.ts +0 -110
  17. package/dist/fields.js +0 -158
  18. package/dist/kokimoki-ai.d.ts +0 -153
  19. package/dist/kokimoki-ai.js +0 -164
  20. package/dist/kokimoki-awareness.d.ts +0 -21
  21. package/dist/kokimoki-awareness.js +0 -48
  22. package/dist/kokimoki-client-refactored.d.ts +0 -80
  23. package/dist/kokimoki-client-refactored.js +0 -400
  24. package/dist/kokimoki-client.d.ts +0 -362
  25. package/dist/kokimoki-client.js +0 -823
  26. package/dist/kokimoki-leaderboard.d.ts +0 -175
  27. package/dist/kokimoki-leaderboard.js +0 -203
  28. package/dist/kokimoki-local-store.d.ts +0 -11
  29. package/dist/kokimoki-local-store.js +0 -40
  30. package/dist/kokimoki-queue.d.ts +0 -0
  31. package/dist/kokimoki-queue.js +0 -38
  32. package/dist/kokimoki-req-res.d.ts +0 -0
  33. package/dist/kokimoki-req-res.js +0 -198
  34. package/dist/kokimoki-schema.d.ts +0 -113
  35. package/dist/kokimoki-schema.js +0 -162
  36. package/dist/kokimoki-storage.d.ts +0 -156
  37. package/dist/kokimoki-storage.js +0 -208
  38. package/dist/kokimoki-store.d.ts +0 -23
  39. package/dist/kokimoki-store.js +0 -117
  40. package/dist/kokimoki-transaction.d.ts +0 -18
  41. package/dist/kokimoki-transaction.js +0 -143
  42. package/dist/message-queue.d.ts +0 -8
  43. package/dist/message-queue.js +0 -19
  44. package/dist/room-subscription-mode.d.ts +0 -5
  45. package/dist/room-subscription-mode.js +0 -6
  46. package/dist/room-subscription.d.ts +0 -15
  47. package/dist/room-subscription.js +0 -52
  48. package/dist/synced-schema.d.ts +0 -74
  49. package/dist/synced-schema.js +0 -83
  50. package/dist/synced-store.d.ts +0 -10
  51. package/dist/synced-store.js +0 -9
  52. package/dist/synced-types.d.ts +0 -47
  53. package/dist/synced-types.js +0 -67
  54. package/dist/ws-message-reader.d.ts +0 -11
  55. package/dist/ws-message-reader.js +0 -36
  56. package/dist/ws-message-type copy.d.ts +0 -6
  57. package/dist/ws-message-type copy.js +0 -7
  58. package/dist/ws-message-type.d.ts +0 -11
  59. package/dist/ws-message-type.js +0 -12
  60. package/dist/ws-message-writer.d.ts +0 -9
  61. package/dist/ws-message-writer.js +0 -45
@@ -1,164 +0,0 @@
1
- /**
2
- * Kokimoki AI Integration Service
3
- *
4
- * Provides built-in AI capabilities for game applications without requiring API keys or setup.
5
- * Includes text generation, structured JSON output, and image modification.
6
- *
7
- * **Key Features:**
8
- * - Multiple AI models (GPT-4, GPT-5, Gemini variants)
9
- * - Text generation with configurable creativity (temperature)
10
- * - Structured JSON output for game data
11
- * - AI-powered image modifications
12
- * - No API keys or configuration required
13
- *
14
- * **Common Use Cases:**
15
- * - Generate dynamic game content (quests, dialogues, stories)
16
- * - Create AI opponents or NPCs with personalities
17
- * - Generate quiz questions or trivia
18
- * - Create game assets (character stats, item descriptions)
19
- * - Transform user-uploaded images
20
- * - Generate procedural content
21
- *
22
- * Access via `kmClient.ai`
23
- *
24
- * @example
25
- * ```typescript
26
- * // Generate story text
27
- * const story = await kmClient.ai.chat({
28
- * systemPrompt: 'You are a fantasy story writer',
29
- * userPrompt: 'Write a short quest description',
30
- * temperature: 0.8
31
- * });
32
- *
33
- * // Generate structured game data
34
- * interface Enemy {
35
- * name: string;
36
- * health: number;
37
- * attack: number;
38
- * }
39
- * const enemy = await kmClient.ai.generateJson<Enemy>({
40
- * userPrompt: 'Create a level 5 goblin warrior'
41
- * });
42
- *
43
- * // Transform image
44
- * const modified = await kmClient.ai.modifyImage(
45
- * imageUrl,
46
- * 'Make it look like pixel art'
47
- * );
48
- * ```
49
- */
50
- export class KokimokiAi {
51
- client;
52
- constructor(client) {
53
- this.client = client;
54
- }
55
- /**
56
- * Generate a chat response from the AI model.
57
- *
58
- * Sends a chat request to the AI service and returns the generated response.
59
- * Supports multiple AI models including GPT and Gemini variants with configurable
60
- * parameters for fine-tuning the response behavior.
61
- *
62
- * @param req The chat request parameters.
63
- * @param req.model Optional. The AI model to use. Defaults to server-side default if not specified.
64
- * Available models:
65
- * - `gpt-4o`: OpenAI GPT-4 Optimized
66
- * - `gpt-4o-mini`: Smaller, faster GPT-4 variant
67
- * - `gpt-5`: OpenAI GPT-5 (latest)
68
- * - `gpt-5-mini`: Smaller GPT-5 variant
69
- * - `gpt-5-nano`: Smallest GPT-5 variant for lightweight tasks
70
- * - `gemini-2.5-flash-lite`: Google Gemini lite variant
71
- * - `gemini-2.5-flash`: Google Gemini fast variant
72
- * @param req.systemPrompt Optional. The system message that sets the behavior and context for the AI.
73
- * This helps define the AI's role, personality, and constraints.
74
- * @param req.userPrompt The user's message or question to send to the AI.
75
- * @param req.temperature Optional. Controls randomness in the response (0.0 to 1.0).
76
- * Lower values make output more focused and deterministic,
77
- * higher values make it more creative and varied.
78
- * @param req.maxTokens Optional. The maximum number of tokens to generate in the response.
79
- * Controls the length of the AI's output.
80
- *
81
- * @returns A promise that resolves to an object containing the AI-generated response.
82
- * @returns {string} content The text content of the AI's response.
83
- *
84
- * @throws An error object if the API request fails.
85
- *
86
- * @example
87
- * ```typescript
88
- * const response = await client.ai.chat({
89
- * model: "gpt-4o",
90
- * systemPrompt: "You are a helpful coding assistant.",
91
- * userPrompt: "Explain what TypeScript is in one sentence.",
92
- * temperature: 0.7,
93
- * maxTokens: 100
94
- * });
95
- * console.log(response.content);
96
- * ```
97
- */
98
- async chat(req) {
99
- const res = await fetch(`${this.client.apiUrl}/ai/chat`, {
100
- method: "POST",
101
- headers: this.client.apiHeaders,
102
- body: JSON.stringify(req),
103
- });
104
- if (!res.ok) {
105
- throw await res.json();
106
- }
107
- return await res.json();
108
- }
109
- /**
110
- * Generate structured JSON output from the AI model.
111
- *
112
- * Sends a chat request to the AI service with the expectation of receiving
113
- * a JSON-formatted response. This is useful for scenarios where the output
114
- * needs to be parsed or processed programmatically.
115
- *
116
- * @param req The chat request parameters.
117
- * @param req.model Optional. The AI model to use. Defaults to server-side default if not specified.
118
- * Available models:
119
- * - `gpt-4o`: OpenAI GPT-4 Optimized
120
- * - `gpt-4o-mini`: Smaller, faster GPT-4 variant
121
- * - `gpt-5`: OpenAI GPT-5 (latest)
122
- * - `gpt-5-mini`: Smaller GPT-5 variant
123
- * - `gpt-5-nano`: Smallest GPT-5 variant for lightweight tasks
124
- * - `gemini-2.5-flash-lite`: Google Gemini lite variant
125
- * - `gemini-2.5-flash`: Google Gemini fast variant
126
- * @param req.systemPrompt Optional. The system message that sets the behavior and context for the AI.
127
- * This helps define the AI's role, personality, and constraints.
128
- * @param req.userPrompt The user's message or question to send to the AI.
129
- * @param req.temperature Optional. Controls randomness in the response (0.0 to 1.0).
130
- * Lower values make output more focused and deterministic,
131
- * higher values make it more creative and varied.
132
- * @param req.maxTokens Optional. The maximum number of tokens to generate in the response.
133
- * Controls the length of the AI's output.
134
- *
135
- * @returns A promise that resolves to the parsed JSON object generated by the AI.
136
- *
137
- * @throws An error object if the API request fails or if the response is not valid JSON.
138
- */
139
- async generateJson(req) {
140
- const { content } = await this.chat({
141
- ...req,
142
- responseMimeType: "application/json",
143
- });
144
- return JSON.parse(content);
145
- }
146
- /**
147
- * Modify an image using the AI service.
148
- * @param baseImageUrl The URL of the base image to modify.
149
- * @param prompt The modification prompt to apply to the image.
150
- * @param tags Optional. Tags to associate with the image.
151
- * @returns A promise that resolves to the modified image upload information.
152
- */
153
- async modifyImage(baseImageUrl, prompt, tags = []) {
154
- const res = await fetch(`${this.client.apiUrl}/ai/modify-image`, {
155
- method: "POST",
156
- headers: this.client.apiHeaders,
157
- body: JSON.stringify({ baseImageUrl, prompt, tags }),
158
- });
159
- if (!res.ok) {
160
- throw await res.json();
161
- }
162
- return await res.json();
163
- }
164
- }
@@ -1,21 +0,0 @@
1
- import { KokimokiStore } from "./kokimoki-store";
2
- import { RoomSubscriptionMode } from "./room-subscription-mode";
3
- import type { KokimokiClient } from "./kokimoki-client";
4
- import type { Snapshot } from "valtio/vanilla";
5
- export declare class KokimokiAwareness<DataT> extends KokimokiStore<{
6
- [connectionId: string]: {
7
- clientId: string;
8
- data: DataT;
9
- };
10
- }> {
11
- private _data;
12
- private _kmClients;
13
- constructor(roomName: string, _data: DataT, mode?: RoomSubscriptionMode);
14
- onJoin(client: KokimokiClient<any>): Promise<void>;
15
- onBeforeLeave(client: KokimokiClient): Promise<void>;
16
- onLeave(client: KokimokiClient<any>): Promise<void>;
17
- getClients(): {
18
- [clientId: string]: Snapshot<DataT>;
19
- };
20
- setData(data: DataT): Promise<void>;
21
- }
@@ -1,48 +0,0 @@
1
- import { KokimokiStore } from "./kokimoki-store";
2
- import { RoomSubscriptionMode } from "./room-subscription-mode";
3
- export class KokimokiAwareness extends KokimokiStore {
4
- _data;
5
- _kmClients = new Set();
6
- constructor(roomName, _data, mode = RoomSubscriptionMode.ReadWrite) {
7
- super(`/a/${roomName}`, {}, mode);
8
- this._data = _data;
9
- }
10
- async onJoin(client) {
11
- this._kmClients.add(client);
12
- await client.transact([this], ([state]) => {
13
- state[client.connectionId] = {
14
- clientId: client.id,
15
- data: this._data,
16
- };
17
- });
18
- }
19
- async onBeforeLeave(client) {
20
- console.log("Awareness: onBeforeLeave", client.connectionId);
21
- await client.transact([this], ([state]) => {
22
- delete state[client.connectionId];
23
- });
24
- }
25
- async onLeave(client) {
26
- this._kmClients.delete(client);
27
- }
28
- getClients() {
29
- const clients = {};
30
- const connections = this.get();
31
- for (const connectionId in connections) {
32
- clients[connections[connectionId].clientId] =
33
- connections[connectionId].data;
34
- }
35
- return clients;
36
- }
37
- async setData(data) {
38
- this._data = data;
39
- const kmClients = Array.from(this._kmClients);
40
- await Promise.all(
41
- kmClients.map(async (client) => {
42
- await client.transact([this], ([state]) => {
43
- state[client.connectionId].data = this._data;
44
- });
45
- }),
46
- );
47
- }
48
- }
@@ -1,80 +0,0 @@
1
- import type TypedEmitter from "typed-emitter";
2
- import type { KokimokiClientEventsRefactored } from "./types/events";
3
- import type { Upload } from "./types/upload";
4
- import type { Paginated } from "./types/common";
5
- import { KokimokiTransaction } from "./kokimoki-transaction";
6
- import type { KokimokiStore } from "./kokimoki-store";
7
- import type { SyncedGeneric } from "./synced-schema";
8
- import { RoomSubscriptionMode } from "./room-subscription-mode";
9
- declare const KokimokiClientRefactored_base: new () => TypedEmitter<KokimokiClientEventsRefactored>;
10
- export declare class KokimokiClientRefactored<
11
- ClientContextT = any,
12
- > extends KokimokiClientRefactored_base {
13
- readonly host: string;
14
- readonly appId: string;
15
- readonly code: string;
16
- private _wsUrl;
17
- private _apiUrl;
18
- private _id?;
19
- private _token?;
20
- private _apiHeaders?;
21
- private _serverTimeOffset;
22
- private _clientContext?;
23
- private _ws?;
24
- private _subscriptions;
25
- private _stores;
26
- private _reqPromises;
27
- private _transactionResolves;
28
- private _roomHashes;
29
- private _roomHashToDoc;
30
- private _connected;
31
- private _connectPromise?;
32
- private _messageId;
33
- constructor(host: string, appId: string, code?: string);
34
- get id(): string;
35
- get token(): string;
36
- get apiUrl(): string;
37
- get apiHeaders(): Headers;
38
- get clientContext(): ClientContextT & ({} | null);
39
- get connected(): boolean;
40
- get ws(): WebSocket;
41
- connect(): Promise<void>;
42
- private handleInitMessage;
43
- private handleBinaryMessage;
44
- private handleErrorMessage;
45
- private handleSubscribeResMessage;
46
- private handleRoomUpdateMessage;
47
- serverTimestamp(): number;
48
- patchRoomState(room: string, update: Uint8Array): Promise<any>;
49
- private createUpload;
50
- private uploadChunks;
51
- private completeUpload;
52
- upload(name: string, blob: Blob, tags?: string[]): Promise<Upload>;
53
- updateUpload(
54
- id: string,
55
- update: {
56
- tags?: string[];
57
- },
58
- ): Promise<Upload>;
59
- listUploads(
60
- filter?: {
61
- clientId?: string;
62
- mimeTypes?: string[];
63
- tags?: string[];
64
- },
65
- skip?: number,
66
- limit?: number,
67
- ): Promise<Paginated<Upload>>;
68
- deleteUpload(id: string): Promise<{
69
- acknowledged: boolean;
70
- deletedCount: number;
71
- }>;
72
- exposeScriptingContext(context: any): Promise<void>;
73
- private sendSubscriptionReq;
74
- join<T extends SyncedGeneric<unknown>>(
75
- store: KokimokiStore<T>,
76
- mode?: RoomSubscriptionMode,
77
- ): Promise<void>;
78
- transact(handler: (t: KokimokiTransaction) => void): Promise<void>;
79
- }
80
- export {};