@kokimoki/app 3.1.2 → 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.
- package/README.md +1 -2
- package/dist/core/kokimoki-client.d.ts +4 -4
- package/dist/core/kokimoki-client.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/kokimoki.min.d.ts +3 -321
- package/dist/kokimoki.min.js +763 -2014
- package/dist/kokimoki.min.js.map +1 -1
- package/dist/services/kokimoki-ai.d.ts +15 -53
- package/dist/services/kokimoki-ai.js +11 -82
- package/dist/services/kokimoki-i18n.d.ts +25 -97
- package/dist/services/kokimoki-i18n.js +30 -99
- package/dist/utils/valtio.d.ts +2 -5
- package/dist/utils/valtio.js +4 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/kokimoki-ai.instructions.md +33 -88
- package/docs/kokimoki-dynamic-stores.instructions.md +3 -3
- package/docs/kokimoki-i18n.instructions.md +8 -115
- package/docs/kokimoki-sdk.instructions.md +46 -7
- package/package.json +8 -2
- package/dist/fields.d.ts +0 -110
- package/dist/fields.js +0 -158
- package/dist/kokimoki-ai.d.ts +0 -153
- package/dist/kokimoki-ai.js +0 -164
- package/dist/kokimoki-awareness.d.ts +0 -21
- package/dist/kokimoki-awareness.js +0 -48
- package/dist/kokimoki-client-refactored.d.ts +0 -80
- package/dist/kokimoki-client-refactored.js +0 -400
- package/dist/kokimoki-client.d.ts +0 -362
- package/dist/kokimoki-client.js +0 -823
- package/dist/kokimoki-leaderboard.d.ts +0 -175
- package/dist/kokimoki-leaderboard.js +0 -203
- package/dist/kokimoki-local-store.d.ts +0 -11
- package/dist/kokimoki-local-store.js +0 -40
- package/dist/kokimoki-queue.d.ts +0 -0
- package/dist/kokimoki-queue.js +0 -38
- package/dist/kokimoki-req-res.d.ts +0 -0
- package/dist/kokimoki-req-res.js +0 -198
- package/dist/kokimoki-schema.d.ts +0 -113
- package/dist/kokimoki-schema.js +0 -162
- package/dist/kokimoki-storage.d.ts +0 -156
- package/dist/kokimoki-storage.js +0 -208
- package/dist/kokimoki-store.d.ts +0 -23
- package/dist/kokimoki-store.js +0 -117
- package/dist/kokimoki-transaction.d.ts +0 -18
- package/dist/kokimoki-transaction.js +0 -143
- package/dist/message-queue.d.ts +0 -8
- package/dist/message-queue.js +0 -19
- package/dist/room-subscription-mode.d.ts +0 -5
- package/dist/room-subscription-mode.js +0 -6
- package/dist/room-subscription.d.ts +0 -15
- package/dist/room-subscription.js +0 -52
- package/dist/synced-schema.d.ts +0 -74
- package/dist/synced-schema.js +0 -83
- package/dist/synced-store.d.ts +0 -10
- package/dist/synced-store.js +0 -9
- package/dist/synced-types.d.ts +0 -47
- package/dist/synced-types.js +0 -67
- package/dist/ws-message-reader.d.ts +0 -11
- package/dist/ws-message-reader.js +0 -36
- package/dist/ws-message-type copy.d.ts +0 -6
- package/dist/ws-message-type copy.js +0 -7
- package/dist/ws-message-type.d.ts +0 -11
- package/dist/ws-message-type.js +0 -12
- package/dist/ws-message-writer.d.ts +0 -9
- package/dist/ws-message-writer.js +0 -45
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZodType } from "zod/v4";
|
|
2
2
|
import { KokimokiClient } from "../core";
|
|
3
|
-
import type { PollOptions, Upload } from "../types";
|
|
4
3
|
/** AI job status */
|
|
5
4
|
export type AiJobStatus = "processing" | "queued" | "completed" | "failed";
|
|
6
5
|
/** AI job type */
|
|
7
6
|
export type AiJobType = "text" | "json" | "image";
|
|
8
7
|
/** AI job information */
|
|
9
|
-
export interface AiJob {
|
|
8
|
+
export interface AiJob<T = unknown> {
|
|
10
9
|
jobId: string;
|
|
11
10
|
type: AiJobType;
|
|
12
11
|
status: AiJobStatus;
|
|
13
|
-
result?:
|
|
12
|
+
result?: T;
|
|
14
13
|
error?: {
|
|
15
14
|
message: string;
|
|
16
15
|
code?: string;
|
|
@@ -109,7 +108,7 @@ export declare class KokimokiAiService {
|
|
|
109
108
|
* Generate text content from the AI model.
|
|
110
109
|
*
|
|
111
110
|
* Submits a text generation job and returns immediately with a jobId.
|
|
112
|
-
* Use `
|
|
111
|
+
* Use `getJob()` to poll for the result.
|
|
113
112
|
*
|
|
114
113
|
* @param req The generation request parameters.
|
|
115
114
|
* @returns A promise that resolves to an object containing the jobId.
|
|
@@ -122,7 +121,8 @@ export declare class KokimokiAiService {
|
|
|
122
121
|
* temperature: 0.8
|
|
123
122
|
* });
|
|
124
123
|
*
|
|
125
|
-
* const
|
|
124
|
+
* const job = await kmClient.ai.getJob<string>(jobId);
|
|
125
|
+
* console.log('Generated quest:', job.result);
|
|
126
126
|
* ```
|
|
127
127
|
*/
|
|
128
128
|
generateText(req: TextGenerateRequest): Promise<JobSubmitResponse>;
|
|
@@ -131,7 +131,7 @@ export declare class KokimokiAiService {
|
|
|
131
131
|
*
|
|
132
132
|
* Submits a JSON generation job and returns immediately with a jobId.
|
|
133
133
|
* The Zod schema is converted to JSON Schema and sent to the AI.
|
|
134
|
-
* Use `
|
|
134
|
+
* Use `getJob()` to poll for the result with type inference.
|
|
135
135
|
*
|
|
136
136
|
* @param req The generation request parameters including Zod schema.
|
|
137
137
|
* @returns A promise that resolves to an object containing the jobId.
|
|
@@ -144,13 +144,16 @@ export declare class KokimokiAiService {
|
|
|
144
144
|
* attack: z.number()
|
|
145
145
|
* });
|
|
146
146
|
*
|
|
147
|
+
* type Enemy = z.infer<typeof enemySchema>;
|
|
148
|
+
*
|
|
147
149
|
* const { jobId } = await kmClient.ai.generateJson({
|
|
148
150
|
* schema: enemySchema,
|
|
149
151
|
* prompt: 'Create a level 5 goblin warrior'
|
|
150
152
|
* });
|
|
151
153
|
*
|
|
152
154
|
* // Poll with schema for type inference and validation
|
|
153
|
-
* const
|
|
155
|
+
* const job = await kmClient.ai.getJob<Enemy>(jobId);
|
|
156
|
+
* console.log('Generated enemy:', job.result);
|
|
154
157
|
* ```
|
|
155
158
|
*/
|
|
156
159
|
generateJson<T extends ZodType>(req: JsonGenerateRequest<T>): Promise<JobSubmitResponse>;
|
|
@@ -158,7 +161,7 @@ export declare class KokimokiAiService {
|
|
|
158
161
|
* Generate or modify an image using the AI model.
|
|
159
162
|
*
|
|
160
163
|
* Submits an image generation job and returns immediately with a jobId.
|
|
161
|
-
* Use `
|
|
164
|
+
* Use `getJob()` to poll for the result.
|
|
162
165
|
*
|
|
163
166
|
* @param req The generation request parameters.
|
|
164
167
|
* @returns A promise that resolves to an object containing the jobId.
|
|
@@ -171,7 +174,8 @@ export declare class KokimokiAiService {
|
|
|
171
174
|
* prompt: 'Make it look like pixel art'
|
|
172
175
|
* });
|
|
173
176
|
*
|
|
174
|
-
* const
|
|
177
|
+
* const job = await kmClient.ai.getJob<string>(jobId);
|
|
178
|
+
* console.log('Generated image:', job.result);
|
|
175
179
|
* ```
|
|
176
180
|
*/
|
|
177
181
|
generateImage(req: ImageGenerateRequest): Promise<JobSubmitResponse>;
|
|
@@ -183,48 +187,6 @@ export declare class KokimokiAiService {
|
|
|
183
187
|
* @param jobId The job ID to check.
|
|
184
188
|
* @returns A promise that resolves to the job information.
|
|
185
189
|
*/
|
|
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.
|
|
223
|
-
*/
|
|
224
|
-
pollImage(jobId: string, options?: PollOptions<AiJobStatus>): Promise<Upload>;
|
|
225
|
-
/**
|
|
226
|
-
* Internal polling implementation.
|
|
227
|
-
*/
|
|
228
|
-
private pollJob;
|
|
190
|
+
getJob<T = unknown>(jobId: string): Promise<AiJob<T>>;
|
|
229
191
|
}
|
|
230
192
|
export {};
|
|
@@ -58,7 +58,7 @@ export class KokimokiAiService {
|
|
|
58
58
|
* Generate text content from the AI model.
|
|
59
59
|
*
|
|
60
60
|
* Submits a text generation job and returns immediately with a jobId.
|
|
61
|
-
* Use `
|
|
61
|
+
* Use `getJob()` to poll for the result.
|
|
62
62
|
*
|
|
63
63
|
* @param req The generation request parameters.
|
|
64
64
|
* @returns A promise that resolves to an object containing the jobId.
|
|
@@ -71,7 +71,8 @@ export class KokimokiAiService {
|
|
|
71
71
|
* temperature: 0.8
|
|
72
72
|
* });
|
|
73
73
|
*
|
|
74
|
-
* const
|
|
74
|
+
* const job = await kmClient.ai.getJob<string>(jobId);
|
|
75
|
+
* console.log('Generated quest:', job.result);
|
|
75
76
|
* ```
|
|
76
77
|
*/
|
|
77
78
|
async generateText(req) {
|
|
@@ -93,7 +94,7 @@ export class KokimokiAiService {
|
|
|
93
94
|
*
|
|
94
95
|
* Submits a JSON generation job and returns immediately with a jobId.
|
|
95
96
|
* The Zod schema is converted to JSON Schema and sent to the AI.
|
|
96
|
-
* Use `
|
|
97
|
+
* Use `getJob()` to poll for the result with type inference.
|
|
97
98
|
*
|
|
98
99
|
* @param req The generation request parameters including Zod schema.
|
|
99
100
|
* @returns A promise that resolves to an object containing the jobId.
|
|
@@ -106,13 +107,16 @@ export class KokimokiAiService {
|
|
|
106
107
|
* attack: z.number()
|
|
107
108
|
* });
|
|
108
109
|
*
|
|
110
|
+
* type Enemy = z.infer<typeof enemySchema>;
|
|
111
|
+
*
|
|
109
112
|
* const { jobId } = await kmClient.ai.generateJson({
|
|
110
113
|
* schema: enemySchema,
|
|
111
114
|
* prompt: 'Create a level 5 goblin warrior'
|
|
112
115
|
* });
|
|
113
116
|
*
|
|
114
117
|
* // Poll with schema for type inference and validation
|
|
115
|
-
* const
|
|
118
|
+
* const job = await kmClient.ai.getJob<Enemy>(jobId);
|
|
119
|
+
* console.log('Generated enemy:', job.result);
|
|
116
120
|
* ```
|
|
117
121
|
*/
|
|
118
122
|
async generateJson(req) {
|
|
@@ -136,7 +140,7 @@ export class KokimokiAiService {
|
|
|
136
140
|
* Generate or modify an image using the AI model.
|
|
137
141
|
*
|
|
138
142
|
* Submits an image generation job and returns immediately with a jobId.
|
|
139
|
-
* Use `
|
|
143
|
+
* Use `getJob()` to poll for the result.
|
|
140
144
|
*
|
|
141
145
|
* @param req The generation request parameters.
|
|
142
146
|
* @returns A promise that resolves to an object containing the jobId.
|
|
@@ -149,7 +153,8 @@ export class KokimokiAiService {
|
|
|
149
153
|
* prompt: 'Make it look like pixel art'
|
|
150
154
|
* });
|
|
151
155
|
*
|
|
152
|
-
* const
|
|
156
|
+
* const job = await kmClient.ai.getJob<string>(jobId);
|
|
157
|
+
* console.log('Generated image:', job.result);
|
|
153
158
|
* ```
|
|
154
159
|
*/
|
|
155
160
|
async generateImage(req) {
|
|
@@ -169,9 +174,6 @@ export class KokimokiAiService {
|
|
|
169
174
|
}
|
|
170
175
|
return await res.json();
|
|
171
176
|
}
|
|
172
|
-
// ============================================================
|
|
173
|
-
// Job Status & Polling Methods
|
|
174
|
-
// ============================================================
|
|
175
177
|
/**
|
|
176
178
|
* Get the current status of an AI job.
|
|
177
179
|
*
|
|
@@ -190,77 +192,4 @@ export class KokimokiAiService {
|
|
|
190
192
|
}
|
|
191
193
|
return await res.json();
|
|
192
194
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Poll a text generation job until completion.
|
|
195
|
-
*
|
|
196
|
-
* @param jobId The job ID to poll.
|
|
197
|
-
* @param options Polling options (interval, timeout, progress callback).
|
|
198
|
-
* @returns A promise that resolves to the generated text.
|
|
199
|
-
* @throws If the job fails or times out.
|
|
200
|
-
*/
|
|
201
|
-
async pollText(jobId, options) {
|
|
202
|
-
const result = await this.pollJob(jobId, options);
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Poll a JSON generation job until completion.
|
|
207
|
-
*
|
|
208
|
-
* @param jobId The job ID to poll.
|
|
209
|
-
* @param options Polling options including the Zod schema for validation.
|
|
210
|
-
* @returns A promise that resolves to the parsed and validated JSON.
|
|
211
|
-
* @throws If the job fails, times out, or validation fails.
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* ```typescript
|
|
215
|
-
* const enemy = await kmClient.ai.pollJson(savedJobId, {
|
|
216
|
-
* schema: enemySchema,
|
|
217
|
-
* timeout: 60000,
|
|
218
|
-
* onProgress: (status) => console.log('Status:', status)
|
|
219
|
-
* });
|
|
220
|
-
* ```
|
|
221
|
-
*/
|
|
222
|
-
async pollJson(jobId, options) {
|
|
223
|
-
const { schema, ...pollOptions } = options;
|
|
224
|
-
const result = await this.pollJob(jobId, pollOptions);
|
|
225
|
-
return schema.parse(result);
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Poll an image generation job until completion.
|
|
229
|
-
*
|
|
230
|
-
* @param jobId The job ID to poll.
|
|
231
|
-
* @param options Polling options (interval, timeout, progress callback).
|
|
232
|
-
* @returns A promise that resolves to the upload information.
|
|
233
|
-
* @throws If the job fails or times out.
|
|
234
|
-
*/
|
|
235
|
-
async pollImage(jobId, options) {
|
|
236
|
-
const result = await this.pollJob(jobId, options);
|
|
237
|
-
return result;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Internal polling implementation.
|
|
241
|
-
*/
|
|
242
|
-
async pollJob(jobId, options) {
|
|
243
|
-
const pollInterval = Math.max(1000, options?.pollInterval ?? 2000);
|
|
244
|
-
const timeout = options?.timeout ?? 120000;
|
|
245
|
-
const startTime = Date.now();
|
|
246
|
-
while (true) {
|
|
247
|
-
const job = await this.getJob(jobId);
|
|
248
|
-
// Call progress callback
|
|
249
|
-
options?.onProgress?.(job.status);
|
|
250
|
-
if (job.status === "completed") {
|
|
251
|
-
return job.result;
|
|
252
|
-
}
|
|
253
|
-
if (job.status === "failed") {
|
|
254
|
-
throw new Error(job.error?.message ?? "AI job failed");
|
|
255
|
-
}
|
|
256
|
-
// processing and queued both continue polling
|
|
257
|
-
// queued jobs will be promoted when slots become available
|
|
258
|
-
// Check timeout
|
|
259
|
-
if (Date.now() - startTime > timeout) {
|
|
260
|
-
throw new Error(`AI job timed out after ${timeout}ms`);
|
|
261
|
-
}
|
|
262
|
-
// Wait before next poll
|
|
263
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
195
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import i18next, { type i18n } from "i18next";
|
|
2
2
|
import type { KokimokiClient } from "../core";
|
|
3
|
-
import type { PollOptions } from "../types";
|
|
4
3
|
/**
|
|
5
4
|
* Options for creating an i18n instance.
|
|
6
5
|
*/
|
|
@@ -15,39 +14,7 @@ export interface I18nOptions {
|
|
|
15
14
|
/**
|
|
16
15
|
* Status of a single namespace translation.
|
|
17
16
|
*/
|
|
18
|
-
export type
|
|
19
|
-
/**
|
|
20
|
-
* Aggregated status of a language across all namespaces.
|
|
21
|
-
*/
|
|
22
|
-
export type LanguageStatus = "available" | "processing" | "failed" | "partial";
|
|
23
|
-
/**
|
|
24
|
-
* Translation status for a specific language.
|
|
25
|
-
*/
|
|
26
|
-
export interface TranslationStatus {
|
|
27
|
-
/** Overall status of the language */
|
|
28
|
-
status: "available" | "processing" | "not_available";
|
|
29
|
-
/** Status per namespace */
|
|
30
|
-
namespaces: Record<string, NamespaceStatus>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Status of all languages that have been requested.
|
|
34
|
-
*/
|
|
35
|
-
export interface AllLanguagesStatus {
|
|
36
|
-
/** Array of language statuses */
|
|
37
|
-
languages: {
|
|
38
|
-
lng: string;
|
|
39
|
-
status: LanguageStatus;
|
|
40
|
-
}[];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Result of requesting a translation.
|
|
44
|
-
*/
|
|
45
|
-
export interface RequestTranslationResult {
|
|
46
|
-
/** Language code that was requested */
|
|
47
|
-
lng: string;
|
|
48
|
-
/** Status of the request */
|
|
49
|
-
status: "started" | "already_processing" | "already_available";
|
|
50
|
-
}
|
|
17
|
+
export type TranslationStatus = "available" | "processing" | "failed";
|
|
51
18
|
/**
|
|
52
19
|
* Kokimoki i18n Service
|
|
53
20
|
*
|
|
@@ -61,7 +28,7 @@ export interface RequestTranslationResult {
|
|
|
61
28
|
* - Pre-configured i18next instance creation
|
|
62
29
|
* - Consistent HTTP-based loading in dev and prod
|
|
63
30
|
* - URL resolution for translation namespaces
|
|
64
|
-
* - AI-powered translation requests
|
|
31
|
+
* - AI-powered translation requests and status polling
|
|
65
32
|
*
|
|
66
33
|
* Access via `kmClient.i18n`
|
|
67
34
|
*
|
|
@@ -75,16 +42,20 @@ export interface RequestTranslationResult {
|
|
|
75
42
|
* });
|
|
76
43
|
*
|
|
77
44
|
* // Initialize with primary language
|
|
78
|
-
* await kmClient.i18n.init(
|
|
45
|
+
* await kmClient.i18n.init();
|
|
79
46
|
*
|
|
80
47
|
* // Request AI translation and wait for it
|
|
81
48
|
* await kmClient.i18n.requestTranslation('de');
|
|
82
|
-
* await kmClient.i18n.pollTranslation('de', {
|
|
83
|
-
* onProgress: (status) => console.log('Translation status:', status.status)
|
|
84
|
-
* });
|
|
85
49
|
*
|
|
86
|
-
* //
|
|
87
|
-
*
|
|
50
|
+
* // Poll until ready
|
|
51
|
+
* const checkInterval = setInterval(async () => {
|
|
52
|
+
* const status = await kmClient.i18n.getTranslationStatus('de');
|
|
53
|
+
* if (status.status === 'available') {
|
|
54
|
+
* clearInterval(checkInterval);
|
|
55
|
+
* // Now safe to switch language
|
|
56
|
+
* i18next.changeLanguage('de');
|
|
57
|
+
* }
|
|
58
|
+
* }, 2000);
|
|
88
59
|
* ```
|
|
89
60
|
*/
|
|
90
61
|
export declare class KokimokiI18nService {
|
|
@@ -174,17 +145,25 @@ export declare class KokimokiI18nService {
|
|
|
174
145
|
*/
|
|
175
146
|
getLanguages(): string[];
|
|
176
147
|
/**
|
|
177
|
-
*
|
|
148
|
+
* Request AI translation for a target language.
|
|
149
|
+
*
|
|
150
|
+
* Triggers background AI translation jobs for all namespaces that are not yet available.
|
|
151
|
+
* Uses the build's configured primary language as the source.
|
|
178
152
|
*
|
|
179
|
-
* @
|
|
153
|
+
* @param lng - Target language code (e.g., 'de', 'fr', 'es')
|
|
154
|
+
* @returns Promise with the translation status
|
|
180
155
|
*
|
|
181
156
|
* @example
|
|
182
157
|
* ```typescript
|
|
183
|
-
* const
|
|
184
|
-
*
|
|
158
|
+
* const status = await kmClient.i18n.requestTranslation('de');
|
|
159
|
+
*
|
|
160
|
+
* if (status === 'available') {
|
|
161
|
+
* // Already translated, switch immediately
|
|
162
|
+
* i18next.changeLanguage('de');
|
|
163
|
+
* }
|
|
185
164
|
* ```
|
|
186
165
|
*/
|
|
187
|
-
|
|
166
|
+
requestTranslation(lng: string): Promise<TranslationStatus>;
|
|
188
167
|
/**
|
|
189
168
|
* Get the translation status for a specific language.
|
|
190
169
|
*
|
|
@@ -208,55 +187,4 @@ export declare class KokimokiI18nService {
|
|
|
208
187
|
* ```
|
|
209
188
|
*/
|
|
210
189
|
getTranslationStatus(lng: string): Promise<TranslationStatus>;
|
|
211
|
-
/**
|
|
212
|
-
* Request AI translation for a target language.
|
|
213
|
-
*
|
|
214
|
-
* Triggers background AI translation jobs for all namespaces that are not yet available.
|
|
215
|
-
* Uses the build's configured primary language as the source.
|
|
216
|
-
*
|
|
217
|
-
* @param lng - Target language code (e.g., 'de', 'fr', 'es')
|
|
218
|
-
* @returns Promise with the result of the request
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```typescript
|
|
222
|
-
* const result = await kmClient.i18n.requestTranslation('de');
|
|
223
|
-
*
|
|
224
|
-
* if (result.status === 'already_available') {
|
|
225
|
-
* // Already translated, switch immediately
|
|
226
|
-
* i18next.changeLanguage('de');
|
|
227
|
-
* } else {
|
|
228
|
-
* // Poll until ready
|
|
229
|
-
* await kmClient.i18n.pollTranslation('de', {
|
|
230
|
-
* onProgress: (status) => console.log('Status:', status.status)
|
|
231
|
-
* });
|
|
232
|
-
* i18next.changeLanguage('de');
|
|
233
|
-
* }
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
requestTranslation(lng: string): Promise<RequestTranslationResult>;
|
|
237
|
-
/**
|
|
238
|
-
* Poll a translation request until all namespaces are available.
|
|
239
|
-
*
|
|
240
|
-
* @param lng - The language code to poll for.
|
|
241
|
-
* @param options - Polling options (interval, timeout, progress callback).
|
|
242
|
-
* @returns Promise that resolves when all namespaces are available.
|
|
243
|
-
* @throws If the translation fails or times out.
|
|
244
|
-
*
|
|
245
|
-
* @example
|
|
246
|
-
* ```typescript
|
|
247
|
-
* // Request and poll with progress
|
|
248
|
-
* await kmClient.i18n.requestTranslation('de');
|
|
249
|
-
* await kmClient.i18n.pollTranslation('de', {
|
|
250
|
-
* timeout: 60000,
|
|
251
|
-
* onProgress: (status) => {
|
|
252
|
-
* console.log('Overall:', status.status);
|
|
253
|
-
* console.log('Namespaces:', status.namespaces);
|
|
254
|
-
* }
|
|
255
|
-
* });
|
|
256
|
-
*
|
|
257
|
-
* // Now safe to switch
|
|
258
|
-
* i18next.changeLanguage('de');
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
pollTranslation(lng: string, options?: PollOptions<TranslationStatus>): Promise<void>;
|
|
262
190
|
}
|
|
@@ -14,7 +14,7 @@ import { getKmEnv } from "../utils/kokimoki-env";
|
|
|
14
14
|
* - Pre-configured i18next instance creation
|
|
15
15
|
* - Consistent HTTP-based loading in dev and prod
|
|
16
16
|
* - URL resolution for translation namespaces
|
|
17
|
-
* - AI-powered translation requests
|
|
17
|
+
* - AI-powered translation requests and status polling
|
|
18
18
|
*
|
|
19
19
|
* Access via `kmClient.i18n`
|
|
20
20
|
*
|
|
@@ -28,16 +28,20 @@ import { getKmEnv } from "../utils/kokimoki-env";
|
|
|
28
28
|
* });
|
|
29
29
|
*
|
|
30
30
|
* // Initialize with primary language
|
|
31
|
-
* await kmClient.i18n.init(
|
|
31
|
+
* await kmClient.i18n.init();
|
|
32
32
|
*
|
|
33
33
|
* // Request AI translation and wait for it
|
|
34
34
|
* await kmClient.i18n.requestTranslation('de');
|
|
35
|
-
* await kmClient.i18n.pollTranslation('de', {
|
|
36
|
-
* onProgress: (status) => console.log('Translation status:', status.status)
|
|
37
|
-
* });
|
|
38
35
|
*
|
|
39
|
-
* //
|
|
40
|
-
*
|
|
36
|
+
* // Poll until ready
|
|
37
|
+
* const checkInterval = setInterval(async () => {
|
|
38
|
+
* const status = await kmClient.i18n.getTranslationStatus('de');
|
|
39
|
+
* if (status.status === 'available') {
|
|
40
|
+
* clearInterval(checkInterval);
|
|
41
|
+
* // Now safe to switch language
|
|
42
|
+
* i18next.changeLanguage('de');
|
|
43
|
+
* }
|
|
44
|
+
* }, 2000);
|
|
41
45
|
* ```
|
|
42
46
|
*/
|
|
43
47
|
export class KokimokiI18nService {
|
|
@@ -208,22 +212,31 @@ export class KokimokiI18nService {
|
|
|
208
212
|
return getKmEnv().i18nLanguages ?? [];
|
|
209
213
|
}
|
|
210
214
|
/**
|
|
211
|
-
*
|
|
215
|
+
* Request AI translation for a target language.
|
|
212
216
|
*
|
|
213
|
-
*
|
|
217
|
+
* Triggers background AI translation jobs for all namespaces that are not yet available.
|
|
218
|
+
* Uses the build's configured primary language as the source.
|
|
219
|
+
*
|
|
220
|
+
* @param lng - Target language code (e.g., 'de', 'fr', 'es')
|
|
221
|
+
* @returns Promise with the translation status
|
|
214
222
|
*
|
|
215
223
|
* @example
|
|
216
224
|
* ```typescript
|
|
217
|
-
* const
|
|
218
|
-
*
|
|
225
|
+
* const status = await kmClient.i18n.requestTranslation('de');
|
|
226
|
+
*
|
|
227
|
+
* if (status === 'available') {
|
|
228
|
+
* // Already translated, switch immediately
|
|
229
|
+
* i18next.changeLanguage('de');
|
|
230
|
+
* }
|
|
219
231
|
* ```
|
|
220
232
|
*/
|
|
221
|
-
async
|
|
222
|
-
const res = await fetch(`${this.client.apiUrl}/i18n`, {
|
|
223
|
-
method: "
|
|
233
|
+
async requestTranslation(lng) {
|
|
234
|
+
const res = await fetch(`${this.client.apiUrl}/i18n/${encodeURIComponent(lng)}/translate`, {
|
|
235
|
+
method: "POST",
|
|
224
236
|
headers: this.client.apiHeaders,
|
|
225
237
|
});
|
|
226
|
-
|
|
238
|
+
const { status } = await res.json();
|
|
239
|
+
return status;
|
|
227
240
|
}
|
|
228
241
|
/**
|
|
229
242
|
* Get the translation status for a specific language.
|
|
@@ -252,89 +265,7 @@ export class KokimokiI18nService {
|
|
|
252
265
|
method: "GET",
|
|
253
266
|
headers: this.client.apiHeaders,
|
|
254
267
|
});
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Request AI translation for a target language.
|
|
259
|
-
*
|
|
260
|
-
* Triggers background AI translation jobs for all namespaces that are not yet available.
|
|
261
|
-
* Uses the build's configured primary language as the source.
|
|
262
|
-
*
|
|
263
|
-
* @param lng - Target language code (e.g., 'de', 'fr', 'es')
|
|
264
|
-
* @returns Promise with the result of the request
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* ```typescript
|
|
268
|
-
* const result = await kmClient.i18n.requestTranslation('de');
|
|
269
|
-
*
|
|
270
|
-
* if (result.status === 'already_available') {
|
|
271
|
-
* // Already translated, switch immediately
|
|
272
|
-
* i18next.changeLanguage('de');
|
|
273
|
-
* } else {
|
|
274
|
-
* // Poll until ready
|
|
275
|
-
* await kmClient.i18n.pollTranslation('de', {
|
|
276
|
-
* onProgress: (status) => console.log('Status:', status.status)
|
|
277
|
-
* });
|
|
278
|
-
* i18next.changeLanguage('de');
|
|
279
|
-
* }
|
|
280
|
-
* ```
|
|
281
|
-
*/
|
|
282
|
-
async requestTranslation(lng) {
|
|
283
|
-
const res = await fetch(`${this.client.apiUrl}/i18n/${encodeURIComponent(lng)}/translate`, {
|
|
284
|
-
method: "POST",
|
|
285
|
-
headers: this.client.apiHeaders,
|
|
286
|
-
});
|
|
287
|
-
const data = await res.json();
|
|
288
|
-
return { lng, ...data };
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Poll a translation request until all namespaces are available.
|
|
292
|
-
*
|
|
293
|
-
* @param lng - The language code to poll for.
|
|
294
|
-
* @param options - Polling options (interval, timeout, progress callback).
|
|
295
|
-
* @returns Promise that resolves when all namespaces are available.
|
|
296
|
-
* @throws If the translation fails or times out.
|
|
297
|
-
*
|
|
298
|
-
* @example
|
|
299
|
-
* ```typescript
|
|
300
|
-
* // Request and poll with progress
|
|
301
|
-
* await kmClient.i18n.requestTranslation('de');
|
|
302
|
-
* await kmClient.i18n.pollTranslation('de', {
|
|
303
|
-
* timeout: 60000,
|
|
304
|
-
* onProgress: (status) => {
|
|
305
|
-
* console.log('Overall:', status.status);
|
|
306
|
-
* console.log('Namespaces:', status.namespaces);
|
|
307
|
-
* }
|
|
308
|
-
* });
|
|
309
|
-
*
|
|
310
|
-
* // Now safe to switch
|
|
311
|
-
* i18next.changeLanguage('de');
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
async pollTranslation(lng, options) {
|
|
315
|
-
const pollInterval = Math.max(1000, options?.pollInterval ?? 2000);
|
|
316
|
-
const timeout = options?.timeout ?? 120000;
|
|
317
|
-
const startTime = Date.now();
|
|
318
|
-
while (true) {
|
|
319
|
-
const status = await this.getTranslationStatus(lng);
|
|
320
|
-
// Call progress callback
|
|
321
|
-
options?.onProgress?.(status);
|
|
322
|
-
if (status.status === "available") {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
// Check for failed namespaces
|
|
326
|
-
const failedNamespaces = Object.entries(status.namespaces)
|
|
327
|
-
.filter(([_, ns]) => ns === "failed")
|
|
328
|
-
.map(([name]) => name);
|
|
329
|
-
if (failedNamespaces.length > 0) {
|
|
330
|
-
throw new Error(`Translation failed for namespaces: ${failedNamespaces.join(", ")}`);
|
|
331
|
-
}
|
|
332
|
-
// Check timeout
|
|
333
|
-
if (Date.now() - startTime > timeout) {
|
|
334
|
-
throw new Error(`Translation timed out after ${timeout}ms`);
|
|
335
|
-
}
|
|
336
|
-
// Wait before next poll
|
|
337
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
338
|
-
}
|
|
268
|
+
const { status } = await res.json();
|
|
269
|
+
return status;
|
|
339
270
|
}
|
|
340
271
|
}
|
package/dist/utils/valtio.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
function useSnapshot<T extends object>(p: T): T;
|
|
4
|
-
}
|
|
5
|
-
export { proxy, ref, snapshot, subscribe, useSnapshot } from "valtio";
|
|
1
|
+
export { proxy, ref, snapshot, subscribe } from "valtio";
|
|
2
|
+
export declare const useSnapshot: <T extends object>(p: T) => T;
|
|
6
3
|
export { derive, underive } from "derive-valtio";
|
|
7
4
|
export { devtools, subscribeKey, useProxy, watch } from "valtio/utils";
|
package/dist/utils/valtio.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import "valtio";
|
|
1
|
+
import { useSnapshot as _useSnapshot } from "valtio";
|
|
2
2
|
// Core Valtio exports
|
|
3
|
-
export { proxy, ref, snapshot, subscribe
|
|
3
|
+
export { proxy, ref, snapshot, subscribe } from "valtio";
|
|
4
|
+
// Loosen useSnapshot return type (valtio returns DeepReadonly<T>, which is too strict)
|
|
5
|
+
export const useSnapshot = _useSnapshot;
|
|
4
6
|
// Valtio utilities
|
|
5
7
|
export { derive, underive } from "derive-valtio";
|
|
6
8
|
export { devtools, subscribeKey, useProxy, watch } from "valtio/utils";
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const KOKIMOKI_APP_VERSION = "3.1.
|
|
1
|
+
export declare const KOKIMOKI_APP_VERSION = "3.1.4";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated file. Do not edit manually.
|
|
2
|
-
export const KOKIMOKI_APP_VERSION = '3.1.
|
|
2
|
+
export const KOKIMOKI_APP_VERSION = '3.1.4';
|