@kokimoki/app 2.1.0 → 3.0.0
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/README.md +72 -0
- package/dist/core/kokimoki-client.d.ts +75 -15
- package/dist/core/kokimoki-client.js +137 -22
- package/dist/index.d.ts +6 -1
- package/dist/index.js +4 -0
- package/dist/kokimoki.min.d.ts +322 -2
- package/dist/kokimoki.min.js +1884 -72
- package/dist/kokimoki.min.js.map +1 -1
- package/dist/llms.txt +6 -0
- package/dist/protocol/ws-message/reader.d.ts +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/kokimoki-ai.d.ts +185 -122
- package/dist/services/kokimoki-ai.js +201 -109
- package/dist/services/kokimoki-i18n.d.ts +259 -0
- package/dist/services/kokimoki-i18n.js +325 -0
- package/dist/stores/kokimoki-local-store.d.ts +1 -1
- package/dist/types/common.d.ts +9 -0
- package/dist/types/env.d.ts +36 -0
- package/dist/types/env.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/kokimoki-client.d.ts +31 -0
- package/dist/utils/kokimoki-client.js +38 -0
- package/dist/utils/kokimoki-dev.d.ts +30 -0
- package/dist/utils/kokimoki-dev.js +75 -0
- package/dist/utils/kokimoki-env.d.ts +20 -0
- package/dist/utils/kokimoki-env.js +30 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/kokimoki-ai.instructions.md +316 -0
- package/docs/kokimoki-dynamic-stores.instructions.md +439 -0
- package/docs/kokimoki-i18n.instructions.md +285 -0
- package/docs/kokimoki-leaderboard.instructions.md +189 -0
- package/docs/kokimoki-sdk.instructions.md +221 -0
- package/docs/kokimoki-storage.instructions.md +162 -0
- package/llms.txt +43 -0
- package/package.json +9 -13
package/dist/llms.txt
CHANGED
|
@@ -308,10 +308,13 @@ Used to generate text response with AI
|
|
|
308
308
|
- `gpt-5-nano`: Smallest GPT-5 variant for lightweight tasks
|
|
309
309
|
- `gemini-2.5-flash-lite`: Google Gemini lite variant
|
|
310
310
|
- `gemini-2.5-flash`: Google Gemini fast variant
|
|
311
|
+
- `gemini-3-flash-preview`: Google Gemini 3 Flash preview
|
|
312
|
+
- `gemini-3-pro-preview`: Google Gemini 3 Pro preview
|
|
311
313
|
- **req.systemPrompt**: `string` AI role/behavior (optional)
|
|
312
314
|
- **req.userPrompt**: `string` User message (optional)
|
|
313
315
|
- **req.temperature**: `number` Creativity level from 0.0 = factual to 2.0 = creative (optional)
|
|
314
316
|
- **req.maxTokens**: `number` Response length limit (optional)
|
|
317
|
+
- **req.imageUrls**: `string[]` Image URLs to include with the user prompt (Gemini models only) (optional)
|
|
315
318
|
|
|
316
319
|
**Examples:**
|
|
317
320
|
|
|
@@ -342,10 +345,13 @@ Used to generate structured JSON output with AI. Automatically ensures the respo
|
|
|
342
345
|
- `gpt-5-nano`: Smallest GPT-5 variant for lightweight tasks
|
|
343
346
|
- `gemini-2.5-flash-lite`: Google Gemini lite variant
|
|
344
347
|
- `gemini-2.5-flash`: Google Gemini fast variant
|
|
348
|
+
- `gemini-3-flash-preview`: Google Gemini 3 Flash preview
|
|
349
|
+
- `gemini-3-pro-preview`: Google Gemini 3 Pro preview
|
|
345
350
|
- **req.systemPrompt**: `string` AI role/behavior (optional)
|
|
346
351
|
- **req.userPrompt**: `string` User message (optional)
|
|
347
352
|
- **req.temperature**: `number` Creativity level from 0.0 = factual to 2.0 = creative (optional)
|
|
348
353
|
- **req.maxTokens**: `number` Response length limit (optional)
|
|
354
|
+
- **req.imageUrls**: `string[]` Image URLs to include with the user prompt (Gemini models only) (optional)
|
|
349
355
|
|
|
350
356
|
**Returns:** Promise resolving to parsed JSON object of type T
|
|
351
357
|
|
package/dist/services/index.d.ts
CHANGED
package/dist/services/index.js
CHANGED
|
@@ -1,17 +1,74 @@
|
|
|
1
|
+
import { z, ZodType } from "zod/v4";
|
|
1
2
|
import { KokimokiClient } from "../core";
|
|
2
|
-
import type { Upload } from "../types";
|
|
3
|
+
import type { PollOptions, Upload } from "../types";
|
|
4
|
+
/** AI job status */
|
|
5
|
+
export type AiJobStatus = "processing" | "queued" | "completed" | "failed";
|
|
6
|
+
/** AI job type */
|
|
7
|
+
export type AiJobType = "text" | "json" | "image";
|
|
8
|
+
/** AI job information */
|
|
9
|
+
export interface AiJob {
|
|
10
|
+
jobId: string;
|
|
11
|
+
type: AiJobType;
|
|
12
|
+
status: AiJobStatus;
|
|
13
|
+
result?: unknown;
|
|
14
|
+
error?: {
|
|
15
|
+
message: string;
|
|
16
|
+
code?: string;
|
|
17
|
+
};
|
|
18
|
+
createdAt: number;
|
|
19
|
+
}
|
|
20
|
+
/** AI model options */
|
|
21
|
+
type AiModel = "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gemini-2.5-flash-lite" | "gemini-2.5-flash" | "gemini-3-flash-preview" | "gemini-3-pro-preview";
|
|
22
|
+
/** Image generation model options */
|
|
23
|
+
type ImageModel = "gemini-2.5-flash-image" | "gemini-3-pro-image-preview";
|
|
24
|
+
/** Common request options for text generation */
|
|
25
|
+
interface TextGenerateRequest {
|
|
26
|
+
model?: AiModel;
|
|
27
|
+
/** System prompt that sets the behavior and context for the AI */
|
|
28
|
+
systemPrompt?: string;
|
|
29
|
+
/** The user's message or question to send to the AI */
|
|
30
|
+
prompt: string;
|
|
31
|
+
/** Controls randomness in the response (0.0 to 1.0) */
|
|
32
|
+
temperature?: number;
|
|
33
|
+
/** Image URLs to include with the prompt (Gemini models only) */
|
|
34
|
+
imageUrls?: string[];
|
|
35
|
+
}
|
|
36
|
+
/** Request options for JSON generation */
|
|
37
|
+
interface JsonGenerateRequest<T extends ZodType> extends Omit<TextGenerateRequest, "prompt"> {
|
|
38
|
+
/** Zod schema that defines the expected JSON structure */
|
|
39
|
+
schema: T;
|
|
40
|
+
/** The user's message or question to send to the AI */
|
|
41
|
+
prompt: string;
|
|
42
|
+
}
|
|
43
|
+
/** Request options for image generation */
|
|
44
|
+
interface ImageGenerateRequest {
|
|
45
|
+
model?: ImageModel;
|
|
46
|
+
/** The prompt describing the image modification */
|
|
47
|
+
prompt: string;
|
|
48
|
+
/** Image URLs to include in the generation */
|
|
49
|
+
imageUrls?: string[];
|
|
50
|
+
/** Tags to associate with the generated image */
|
|
51
|
+
tags?: string[];
|
|
52
|
+
}
|
|
53
|
+
/** Job submission response */
|
|
54
|
+
interface JobSubmitResponse {
|
|
55
|
+
jobId: string;
|
|
56
|
+
status: AiJobStatus;
|
|
57
|
+
}
|
|
3
58
|
/**
|
|
4
59
|
* Kokimoki AI Integration Service
|
|
5
60
|
*
|
|
6
61
|
* Provides built-in AI capabilities for game applications without requiring API keys or setup.
|
|
7
|
-
*
|
|
62
|
+
* All generation methods are async job-based - they submit a job and return immediately with a jobId.
|
|
63
|
+
* Use the corresponding poll method to wait for the result.
|
|
8
64
|
*
|
|
9
65
|
* **Key Features:**
|
|
10
66
|
* - Multiple AI models (GPT-4, GPT-5, Gemini variants)
|
|
11
67
|
* - Text generation with configurable creativity (temperature)
|
|
12
|
-
* - Structured JSON output
|
|
13
|
-
* - AI-powered image
|
|
14
|
-
* -
|
|
68
|
+
* - Structured JSON output with Zod schema validation
|
|
69
|
+
* - AI-powered image generation and modification
|
|
70
|
+
* - Job-based async processing with polling support
|
|
71
|
+
* - Resumable after page reload (persist jobId)
|
|
15
72
|
*
|
|
16
73
|
* **Common Use Cases:**
|
|
17
74
|
* - Generate dynamic game content (quests, dialogues, stories)
|
|
@@ -25,143 +82,149 @@ import type { Upload } from "../types";
|
|
|
25
82
|
*
|
|
26
83
|
* @example
|
|
27
84
|
* ```typescript
|
|
28
|
-
* // Generate
|
|
29
|
-
* const
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
85
|
+
* // Generate structured game data
|
|
86
|
+
* const enemySchema = z.object({
|
|
87
|
+
* name: z.string(),
|
|
88
|
+
* health: z.number(),
|
|
89
|
+
* attack: z.number()
|
|
33
90
|
* });
|
|
34
91
|
*
|
|
35
|
-
* //
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* attack: number;
|
|
40
|
-
* }
|
|
41
|
-
* const enemy = await kmClient.ai.generateJson<Enemy>({
|
|
42
|
-
* userPrompt: 'Create a level 5 goblin warrior'
|
|
92
|
+
* // Submit job
|
|
93
|
+
* const { jobId } = await kmClient.ai.generateJson({
|
|
94
|
+
* schema: enemySchema,
|
|
95
|
+
* prompt: 'Create a level 5 goblin warrior'
|
|
43
96
|
* });
|
|
44
97
|
*
|
|
45
|
-
* //
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* );
|
|
98
|
+
* // Save jobId to store for persistence across reloads
|
|
99
|
+
* await saveJobId(jobId);
|
|
100
|
+
*
|
|
101
|
+
* // Poll for result (can resume after reload)
|
|
102
|
+
* const enemy = await kmClient.ai.pollJson(jobId, { schema: enemySchema });
|
|
50
103
|
* ```
|
|
51
104
|
*/
|
|
52
105
|
export declare class KokimokiAiService {
|
|
53
106
|
private readonly client;
|
|
54
107
|
constructor(client: KokimokiClient);
|
|
55
108
|
/**
|
|
56
|
-
* Generate
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @
|
|
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
|
-
* - `gemini-3-flash-preview`: Google Gemini 3 Flash preview
|
|
73
|
-
* - `gemini-3-pro-preview`: Google Gemini 3 Pro preview
|
|
74
|
-
* @param req.systemPrompt Optional. The system message that sets the behavior and context for the AI.
|
|
75
|
-
* This helps define the AI's role, personality, and constraints.
|
|
76
|
-
* @param req.userPrompt The user's message or question to send to the AI.
|
|
77
|
-
* @param req.temperature Optional. Controls randomness in the response (0.0 to 1.0).
|
|
78
|
-
* Lower values make output more focused and deterministic,
|
|
79
|
-
* higher values make it more creative and varied.
|
|
80
|
-
* @param req.maxTokens Optional. The maximum number of tokens to generate in the response.
|
|
81
|
-
* Controls the length of the AI's output.
|
|
82
|
-
*
|
|
83
|
-
* @returns A promise that resolves to an object containing the AI-generated response.
|
|
84
|
-
* @returns {string} content The text content of the AI's response.
|
|
85
|
-
*
|
|
86
|
-
* @throws An error object if the API request fails.
|
|
109
|
+
* Generate text content from the AI model.
|
|
110
|
+
*
|
|
111
|
+
* Submits a text generation job and returns immediately with a jobId.
|
|
112
|
+
* Use `pollText()` to wait for the result.
|
|
113
|
+
*
|
|
114
|
+
* @param req The generation request parameters.
|
|
115
|
+
* @returns A promise that resolves to an object containing the jobId.
|
|
87
116
|
*
|
|
88
117
|
* @example
|
|
89
118
|
* ```typescript
|
|
90
|
-
* const
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* temperature: 0.7,
|
|
95
|
-
* maxTokens: 100
|
|
119
|
+
* const { jobId } = await kmClient.ai.generateText({
|
|
120
|
+
* systemPrompt: 'You are a fantasy story writer',
|
|
121
|
+
* prompt: 'Write a short quest description',
|
|
122
|
+
* temperature: 0.8
|
|
96
123
|
* });
|
|
97
|
-
*
|
|
124
|
+
*
|
|
125
|
+
* const text = await kmClient.ai.pollText(jobId);
|
|
98
126
|
* ```
|
|
99
127
|
*/
|
|
100
|
-
|
|
101
|
-
model?: "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gemini-2.5-flash-lite" | "gemini-2.5-flash" | "gemini-3-flash-preview" | "gemini-3-pro-preview";
|
|
102
|
-
systemPrompt?: string;
|
|
103
|
-
userPrompt: string;
|
|
104
|
-
temperature?: number;
|
|
105
|
-
maxTokens?: number;
|
|
106
|
-
responseMimeType?: string;
|
|
107
|
-
/** Image URLs to include with the user prompt (Gemini models only) */
|
|
108
|
-
imageUrls?: string[];
|
|
109
|
-
}): Promise<{
|
|
110
|
-
content: string;
|
|
111
|
-
}>;
|
|
128
|
+
generateText(req: TextGenerateRequest): Promise<JobSubmitResponse>;
|
|
112
129
|
/**
|
|
113
130
|
* Generate structured JSON output from the AI model.
|
|
114
131
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @
|
|
147
|
-
*
|
|
148
|
-
*
|
|
132
|
+
* Submits a JSON generation job and returns immediately with a jobId.
|
|
133
|
+
* The Zod schema is converted to JSON Schema and sent to the AI.
|
|
134
|
+
* Use `pollJson()` to wait for the result with type inference.
|
|
135
|
+
*
|
|
136
|
+
* @param req The generation request parameters including Zod schema.
|
|
137
|
+
* @returns A promise that resolves to an object containing the jobId.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const enemySchema = z.object({
|
|
142
|
+
* name: z.string(),
|
|
143
|
+
* health: z.number(),
|
|
144
|
+
* attack: z.number()
|
|
145
|
+
* });
|
|
146
|
+
*
|
|
147
|
+
* const { jobId } = await kmClient.ai.generateJson({
|
|
148
|
+
* schema: enemySchema,
|
|
149
|
+
* prompt: 'Create a level 5 goblin warrior'
|
|
150
|
+
* });
|
|
151
|
+
*
|
|
152
|
+
* // Poll with schema for type inference and validation
|
|
153
|
+
* const enemy = await kmClient.ai.pollJson(jobId, { schema: enemySchema });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
generateJson<T extends ZodType>(req: JsonGenerateRequest<T>): Promise<JobSubmitResponse>;
|
|
157
|
+
/**
|
|
158
|
+
* Generate or modify an image using the AI model.
|
|
159
|
+
*
|
|
160
|
+
* Submits an image generation job and returns immediately with a jobId.
|
|
161
|
+
* Use `pollImage()` to wait for the result.
|
|
162
|
+
*
|
|
163
|
+
* @param req The generation request parameters.
|
|
164
|
+
* @returns A promise that resolves to an object containing the jobId.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // Modify existing image
|
|
169
|
+
* const { jobId } = await kmClient.ai.generateImage({
|
|
170
|
+
* imageUrls: [imageUrl],
|
|
171
|
+
* prompt: 'Make it look like pixel art'
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* const image = await kmClient.ai.pollImage(jobId);
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
generateImage(req: ImageGenerateRequest): Promise<JobSubmitResponse>;
|
|
178
|
+
/**
|
|
179
|
+
* Get the current status of an AI job.
|
|
180
|
+
*
|
|
181
|
+
* One-shot status check without polling.
|
|
182
|
+
*
|
|
183
|
+
* @param jobId The job ID to check.
|
|
184
|
+
* @returns A promise that resolves to the job information.
|
|
185
|
+
*/
|
|
186
|
+
getJob(jobId: string): Promise<AiJob>;
|
|
187
|
+
/**
|
|
188
|
+
* Poll a text generation job until completion.
|
|
189
|
+
*
|
|
190
|
+
* @param jobId The job ID to poll.
|
|
191
|
+
* @param options Polling options (interval, timeout, progress callback).
|
|
192
|
+
* @returns A promise that resolves to the generated text.
|
|
193
|
+
* @throws If the job fails or times out.
|
|
194
|
+
*/
|
|
195
|
+
pollText(jobId: string, options?: PollOptions<AiJobStatus>): Promise<string>;
|
|
196
|
+
/**
|
|
197
|
+
* Poll a JSON generation job until completion.
|
|
198
|
+
*
|
|
199
|
+
* @param jobId The job ID to poll.
|
|
200
|
+
* @param options Polling options including the Zod schema for validation.
|
|
201
|
+
* @returns A promise that resolves to the parsed and validated JSON.
|
|
202
|
+
* @throws If the job fails, times out, or validation fails.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const enemy = await kmClient.ai.pollJson(savedJobId, {
|
|
207
|
+
* schema: enemySchema,
|
|
208
|
+
* timeout: 60000,
|
|
209
|
+
* onProgress: (status) => console.log('Status:', status)
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
pollJson<T extends ZodType>(jobId: string, options: PollOptions<AiJobStatus> & {
|
|
214
|
+
schema: T;
|
|
215
|
+
}): Promise<z.infer<T>>;
|
|
216
|
+
/**
|
|
217
|
+
* Poll an image generation job until completion.
|
|
218
|
+
*
|
|
219
|
+
* @param jobId The job ID to poll.
|
|
220
|
+
* @param options Polling options (interval, timeout, progress callback).
|
|
221
|
+
* @returns A promise that resolves to the upload information.
|
|
222
|
+
* @throws If the job fails or times out.
|
|
149
223
|
*/
|
|
150
|
-
|
|
151
|
-
model?: "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gemini-2.5-flash-lite" | "gemini-2.5-flash" | "gemini-3-flash-preview" | "gemini-3-pro-preview";
|
|
152
|
-
systemPrompt?: string;
|
|
153
|
-
userPrompt: string;
|
|
154
|
-
temperature?: number;
|
|
155
|
-
maxTokens?: number;
|
|
156
|
-
/** Image URLs to include with the user prompt (Gemini models only) */
|
|
157
|
-
imageUrls?: string[];
|
|
158
|
-
}): Promise<T>;
|
|
224
|
+
pollImage(jobId: string, options?: PollOptions<AiJobStatus>): Promise<Upload>;
|
|
159
225
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @param baseImageUrl The URL of the base image to modify.
|
|
162
|
-
* @param prompt The modification prompt to apply to the image.
|
|
163
|
-
* @param tags Optional. Tags to associate with the image.
|
|
164
|
-
* @returns A promise that resolves to the modified image upload information.
|
|
226
|
+
* Internal polling implementation.
|
|
165
227
|
*/
|
|
166
|
-
|
|
228
|
+
private pollJob;
|
|
167
229
|
}
|
|
230
|
+
export {};
|