@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,7 +1,4 @@
1
- import "valtio";
2
- declare module "valtio" {
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";
@@ -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, useSnapshot } from "valtio";
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.3";
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.3';
2
+ export const KOKIMOKI_APP_VERSION = '3.1.4';
@@ -86,7 +86,7 @@ Submits a JSON generation job with Zod schema validation. Use `getJob<T>()` to w
86
86
  **Example:**
87
87
 
88
88
  ```typescript
89
- import { z } from "zod/v4";
89
+ import { z } from "@kokimoki/app";
90
90
 
91
91
  // Define schema with Zod
92
92
  const enemySchema = z.object({
@@ -205,6 +205,8 @@ if (job.status === "completed") {
205
205
  ### Example: Persist Jobs Across Page Reloads
206
206
 
207
207
  ```typescript
208
+ import { snapshot } from "@kokimoki/app";
209
+
208
210
  // Store jobId in local store for persistence
209
211
  const { jobId } = await kmClient.ai.generateJson({
210
212
  schema: questSchema,
@@ -216,7 +218,7 @@ await kmClient.transact([localStore], ([state]) => {
216
218
  });
217
219
 
218
220
  // On page load, resume polling if job is pending
219
- const pendingJobId = localStore.proxy.pendingQuestJobId;
221
+ const pendingJobId = snapshot(localStore.proxy).pendingQuestJobId;
220
222
  if (pendingJobId) {
221
223
  const quest = await kmClient.ai.pollJson(pendingJobId, {
222
224
  schema: questSchema,
@@ -133,7 +133,7 @@ export function useDynamicStore<T extends object>(
133
133
  ## Basic Usage
134
134
 
135
135
  ```tsx
136
- import { useSnapshot } from "valtio";
136
+ import { useSnapshot } from "@kokimoki/app";
137
137
  import { useDynamicStore } from "@/hooks/useDynamicStore";
138
138
 
139
139
  interface RoomState {
@@ -350,7 +350,7 @@ const BreakoutRoom = ({ roomId }: { roomId: string }) => {
350
350
 
351
351
  ## File Organization
352
352
 
353
- **ALWAYS** organize dynamic store code using the standard store/actions pattern:
353
+ **ALWAYS** organize dynamic store code using the standard state/actions pattern:
354
354
 
355
355
  **State definition** (`src/state/chat-store.ts`):
356
356
 
@@ -408,7 +408,7 @@ export const chatActions = {
408
408
  **Usage in component** (`src/views/chat-view.tsx`):
409
409
 
410
410
  ```tsx
411
- import { useSnapshot } from "valtio";
411
+ import { useSnapshot } from "@kokimoki/app";
412
412
  import { useDynamicStore } from "@/hooks/useDynamicStore";
413
413
  import { createChatState, type ChatState } from "@/state/chat-store";
414
414
  import { chatActions } from "@/state/actions/chat-actions";
@@ -141,7 +141,7 @@ type TranslationStatus = "available" | "processing" | "failed";
141
141
  ```typescript
142
142
  const status = await kmClient.i18n.requestTranslation("de");
143
143
 
144
- if (status === "already_available") {
144
+ if (status === "available") {
145
145
  // Already translated, switch immediately
146
146
  i18next.changeLanguage("de");
147
147
  } else {
@@ -16,7 +16,9 @@ The Kokimoki SDK is a comprehensive development toolkit for building real-time c
16
16
  - Use `kmClient.transact` for atomic state updates across single store or multiple stores
17
17
  - Use `kmClient.storage.upload` and related API methods to handle file uploads (media, JSON, etc.) in application
18
18
  - Use `kmClient.serverTimestamp()` for time-related matters as this will be synced among players
19
- - Use `useSnapshot` hook from `valtio` to get reactive state inside React components
19
+ - Use `useSnapshot` hook to get reactive state inside React components — import from `@kokimoki/app` (re-exports valtio)
20
+ - Use `snapshot` function to read immutable state outside React components (in actions, event handlers, etc.) — import from `@kokimoki/app` — **NEVER** read directly from `store.proxy.field`
21
+ - Use `z` and `ZodType` from `@kokimoki/app` for schema definitions (re-exports zod)
20
22
  - Use AI integration API methods: `kmClient.ai.generateText`, `kmClient.ai.generateJson`, and `kmClient.ai.generateImage` with corresponding poll methods for AI capabilities
21
23
  - Use i18n API methods: `kmClient.i18n.createI18n`, `kmClient.i18n.init`, and `kmClient.i18n.requestTranslation` for internationalization with AI-powered translations
22
24
  - Use leaderboard API methods: `kmClient.leaderboard.insertEntry`, `kmClient.leaderboard.upsertEntry`, `kmClient.leaderboard.listEntries`, and `kmClient.leaderboard.getBestEntry` to add leaderboard capabilities to application
@@ -118,13 +120,13 @@ await kmClient.transact([store1, store2], ([state1, state2]) => {
118
120
 
119
121
  ### Reactive State in Components
120
122
 
121
- - Use `useSnapshot` hook from `valtio` to get reactive state inside React components
123
+ - Use `useSnapshot` hook to get reactive state inside React components (import from `@kokimoki/app`)
122
124
  - The component will re-render when the store state changes
123
125
 
124
126
  **Example: Using State in Components**
125
127
 
126
128
  ```tsx
127
- import { useSnapshot } from "valtio";
129
+ import { useSnapshot } from "@kokimoki/app";
128
130
  import { store } from "../store";
129
131
 
130
132
  const Component = () => {
@@ -140,6 +142,44 @@ const Component = () => {
140
142
  };
141
143
  ```
142
144
 
145
+ ### Reading State Outside Components
146
+
147
+ When reading state **outside React components** (in store actions, event handlers, initialization logic), use `snapshot()` from `@kokimoki/app` to get an immutable copy.
148
+ **NEVER** read directly from `store.proxy` — the proxy is mutable and values can change between read and use.
149
+
150
+ ```typescript
151
+ import { snapshot } from "@kokimoki/app";
152
+
153
+ // WRONG — mutable proxy, value can change unexpectedly
154
+ const value = store.proxy.someField;
155
+
156
+ // CORRECT — immutable snapshot, safe to use
157
+ const value = snapshot(store.proxy).someField;
158
+ ```
159
+
160
+ **Example: Reading state in an store actions**
161
+
162
+ ```typescript
163
+ import { snapshot } from "@kokimoki/app";
164
+
165
+ // Action function that reads state and updates it based on conditions
166
+ async function doSomething() {
167
+ const { count, completed } = snapshot(store.proxy);
168
+
169
+ if (count > 10 && !completed) {
170
+ await kmClient.transact([store], ([state]) => {
171
+ state.completed = true;
172
+ });
173
+ }
174
+ }
175
+ ```
176
+
177
+ ### Common Patterns
178
+
179
+ - **Inside React components** → `useSnapshot(store.proxy)` (reactive, triggers re-renders)
180
+ - **Outside React components** → `snapshot(store.proxy)` (immutable, read-only)
181
+ - **Writing state** → Always use `kmClient.transact()` (never assign to proxy directly)
182
+
143
183
  ## Dynamic Stores
144
184
 
145
185
  For room-based state isolation (teams, chat rooms, breakout rooms), see [Dynamic Stores](./kokimoki-dynamic-stores.instructions.md).
@@ -166,7 +206,7 @@ Each Kokimoki store has a `connections` property that provides real-time presenc
166
206
  ### Example: Track Online Players
167
207
 
168
208
  ```tsx
169
- import { useSnapshot } from "valtio";
209
+ import { useSnapshot } from "@kokimoki/app";
170
210
  import { globalStore } from "@/state/stores/global-store";
171
211
 
172
212
  const Component = () => {
@@ -186,7 +226,7 @@ const Component = () => {
186
226
  ### Example: Display Player List with Online Status
187
227
 
188
228
  ```tsx
189
- import { useSnapshot } from "valtio";
229
+ import { useSnapshot } from "@kokimoki/app";
190
230
  import { globalStore } from "@/state/stores/global-store";
191
231
 
192
232
  const PlayerList = () => {
@@ -231,8 +271,7 @@ Store names with the `__km/` prefix are reserved for SDK internal use. Do not cr
231
271
  ### Using App Meta
232
272
 
233
273
  ```tsx
234
- import { getKmClient } from "@kokimoki/app";
235
- import { useSnapshot } from "valtio";
274
+ import { useSnapshot, getKmClient } from "@kokimoki/app";
236
275
 
237
276
  const kmClient = getKmClient();
238
277
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokimoki/app",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "type": "module",
5
5
  "description": "Kokimoki app",
6
6
  "main": "dist/index.js",
@@ -19,17 +19,23 @@
19
19
  "prebuild": "node scripts/generate-version.js",
20
20
  "build": "tsc",
21
21
  "dev": "tsc -w",
22
- "docs": "typedoc src/index.ts"
22
+ "docs": "typedoc src/index.ts",
23
+ "lint": "eslint .",
24
+ "typecheck": "tsc --noEmit"
23
25
  },
24
26
  "author": "Loquiz OÜ",
25
27
  "license": "Apache-2.0",
26
28
  "devDependencies": {
29
+ "eslint-config": "*",
27
30
  "@types/chai": "^4",
28
31
  "@types/mocha": "^10",
29
32
  "@types/node": "^18",
30
33
  "@types/ws": "^8.5.5",
31
34
  "bson-objectid": "^2.0.4",
32
35
  "chai": "^4",
36
+ "eslint": "^9.39.1",
37
+ "eslint-plugin-chai-friendly": "^1.1.0",
38
+ "eslint-plugin-valtio": "^0.8.0",
33
39
  "mocha": "^10",
34
40
  "ts-node": "^10",
35
41
  "tsx": "^4",
package/dist/fields.d.ts DELETED
@@ -1,110 +0,0 @@
1
- export interface FieldOptions {
2
- label?: string;
3
- }
4
- export declare abstract class Field<T> {
5
- readonly options: FieldOptions;
6
- constructor(options: FieldOptions);
7
- abstract get value(): T;
8
- abstract get schema(): any;
9
- }
10
- export declare class BooleanField extends Field<boolean> {
11
- value: boolean;
12
- constructor(value: boolean, options?: FieldOptions);
13
- get schema(): {
14
- type: string;
15
- default: boolean;
16
- };
17
- }
18
- export declare class ConstField<T extends string> extends Field<
19
- string extends T ? never : T
20
- > {
21
- value: string extends T ? never : T;
22
- constructor(value: string extends T ? never : T, options?: FieldOptions);
23
- get schema(): {
24
- const: string extends T ? never : T;
25
- };
26
- }
27
- export declare class ImageField extends Field<string> {
28
- value: string;
29
- constructor(value: string, options?: FieldOptions);
30
- get schema(): {
31
- type: string;
32
- default: string;
33
- };
34
- }
35
- export declare class TextField extends Field<string> {
36
- value: string;
37
- constructor(value: string, options?: FieldOptions);
38
- get schema(): {
39
- type: string;
40
- default: string;
41
- };
42
- }
43
- export declare class EnumField<T extends Record<string, string>> extends Field<
44
- keyof T
45
- > {
46
- enumValues: T;
47
- value: keyof T;
48
- constructor(enumValues: T, value: keyof T, options?: FieldOptions);
49
- get schema(): {
50
- enum: string[];
51
- };
52
- }
53
- export declare class IntegerField extends Field<number> {
54
- value: number;
55
- constructor(value: number, options?: FieldOptions);
56
- get schema(): {
57
- type: string;
58
- default: number;
59
- };
60
- }
61
- export declare class FloatField extends Field<number> {
62
- value: number;
63
- constructor(value: number, options?: FieldOptions);
64
- get schema(): {
65
- type: string;
66
- default: number;
67
- };
68
- }
69
- export declare class FormGroup<
70
- T extends Record<string, Field<any>>,
71
- O extends Record<string, Field<any>>,
72
- > extends Field<
73
- {
74
- [key in keyof T]: T[key]["value"];
75
- } & Partial<{
76
- [key in keyof O]: O[key]["value"];
77
- }>
78
- > {
79
- requiredFields: T;
80
- optionalFields: O;
81
- constructor(requiredFields: T, optionalFields?: O, options?: FieldOptions);
82
- get value(): {
83
- [key in keyof T]: T[key]["value"];
84
- } & Partial<{
85
- [key in keyof O]: O[key]["value"];
86
- }>;
87
- get schema(): {
88
- type: string;
89
- properties: any;
90
- required: string[];
91
- };
92
- }
93
- export declare class FormArray<T> extends Field<T[]> {
94
- private factory;
95
- value: Field<T>["value"][];
96
- constructor(
97
- factory: () => Field<T>,
98
- value: Field<T>["value"][],
99
- options?: FieldOptions,
100
- );
101
- get schema(): {
102
- type: string;
103
- items: any;
104
- default: T[];
105
- };
106
- }
107
- export declare class Form<
108
- R extends Record<string, Field<any>>,
109
- O extends Record<string, Field<any>>,
110
- > extends FormGroup<R, O> {}
package/dist/fields.js DELETED
@@ -1,158 +0,0 @@
1
- const defaultFieldOptions = {};
2
- export class Field {
3
- options;
4
- constructor(options) {
5
- this.options = options;
6
- }
7
- }
8
- export class BooleanField extends Field {
9
- value;
10
- constructor(value, options = defaultFieldOptions) {
11
- super(options);
12
- this.value = value;
13
- }
14
- get schema() {
15
- return {
16
- type: "boolean",
17
- default: this.value,
18
- };
19
- }
20
- }
21
- export class ConstField extends Field {
22
- value;
23
- constructor(value, options = defaultFieldOptions) {
24
- super(options);
25
- this.value = value;
26
- }
27
- get schema() {
28
- return {
29
- const: this.value,
30
- };
31
- }
32
- }
33
- export class ImageField extends Field {
34
- value;
35
- constructor(value, options = defaultFieldOptions) {
36
- super(options);
37
- this.value = value;
38
- }
39
- get schema() {
40
- return {
41
- type: "string",
42
- default: this.value,
43
- };
44
- }
45
- }
46
- export class TextField extends Field {
47
- value;
48
- constructor(value, options = defaultFieldOptions) {
49
- super(options);
50
- this.value = value;
51
- }
52
- get schema() {
53
- return {
54
- type: "string",
55
- default: this.value,
56
- };
57
- }
58
- }
59
- export class EnumField extends Field {
60
- enumValues;
61
- value;
62
- constructor(enumValues, value, options = defaultFieldOptions) {
63
- super(options);
64
- this.enumValues = enumValues;
65
- this.value = value;
66
- }
67
- get schema() {
68
- return {
69
- enum: Object.keys(this.enumValues),
70
- };
71
- }
72
- }
73
- export class IntegerField extends Field {
74
- value;
75
- constructor(value, options = defaultFieldOptions) {
76
- super(options);
77
- this.value = value;
78
- }
79
- get schema() {
80
- return {
81
- type: "integer",
82
- default: this.value,
83
- };
84
- }
85
- }
86
- export class FloatField extends Field {
87
- value;
88
- constructor(value, options = defaultFieldOptions) {
89
- super(options);
90
- this.value = value;
91
- }
92
- get schema() {
93
- return {
94
- type: "number",
95
- default: this.value,
96
- };
97
- }
98
- }
99
- export class FormGroup extends Field {
100
- requiredFields;
101
- optionalFields;
102
- constructor(
103
- requiredFields,
104
- optionalFields = {},
105
- options = defaultFieldOptions,
106
- ) {
107
- super(options);
108
- this.requiredFields = requiredFields;
109
- this.optionalFields = optionalFields;
110
- }
111
- get value() {
112
- const value = Object.entries(this.requiredFields).reduce(
113
- (acc, [key, field]) => {
114
- acc[key] = field.value;
115
- return acc;
116
- },
117
- {},
118
- );
119
- Object.entries(this.optionalFields).forEach(([key, field]) => {
120
- if (field.value !== undefined) {
121
- value[key] = field.value;
122
- }
123
- });
124
- return value;
125
- }
126
- get schema() {
127
- const properties = {};
128
- Object.entries(this.requiredFields).forEach(([key, field]) => {
129
- properties[key] = field.schema;
130
- });
131
- Object.entries(this.optionalFields).forEach(([key, field]) => {
132
- properties[key] = field.schema;
133
- });
134
- return {
135
- type: "object",
136
- properties,
137
- required: Object.keys(this.requiredFields),
138
- };
139
- }
140
- }
141
- export class FormArray extends Field {
142
- factory;
143
- value;
144
- constructor(factory, value, options = defaultFieldOptions) {
145
- super(options);
146
- this.factory = factory;
147
- this.value = value;
148
- }
149
- get schema() {
150
- const field = this.factory();
151
- return {
152
- type: "array",
153
- items: field.schema,
154
- default: this.value,
155
- };
156
- }
157
- }
158
- export class Form extends FormGroup {}
@@ -1,153 +0,0 @@
1
- import type { Upload } from "./types/upload";
2
- import { KokimokiClient } from "./kokimoki-client";
3
- /**
4
- * Kokimoki AI Integration Service
5
- *
6
- * Provides built-in AI capabilities for game applications without requiring API keys or setup.
7
- * Includes text generation, structured JSON output, and image modification.
8
- *
9
- * **Key Features:**
10
- * - Multiple AI models (GPT-4, GPT-5, Gemini variants)
11
- * - Text generation with configurable creativity (temperature)
12
- * - Structured JSON output for game data
13
- * - AI-powered image modifications
14
- * - No API keys or configuration required
15
- *
16
- * **Common Use Cases:**
17
- * - Generate dynamic game content (quests, dialogues, stories)
18
- * - Create AI opponents or NPCs with personalities
19
- * - Generate quiz questions or trivia
20
- * - Create game assets (character stats, item descriptions)
21
- * - Transform user-uploaded images
22
- * - Generate procedural content
23
- *
24
- * Access via `kmClient.ai`
25
- *
26
- * @example
27
- * ```typescript
28
- * // Generate story text
29
- * const story = await kmClient.ai.chat({
30
- * systemPrompt: 'You are a fantasy story writer',
31
- * userPrompt: 'Write a short quest description',
32
- * temperature: 0.8
33
- * });
34
- *
35
- * // Generate structured game data
36
- * interface Enemy {
37
- * name: string;
38
- * health: number;
39
- * attack: number;
40
- * }
41
- * const enemy = await kmClient.ai.generateJson<Enemy>({
42
- * userPrompt: 'Create a level 5 goblin warrior'
43
- * });
44
- *
45
- * // Transform image
46
- * const modified = await kmClient.ai.modifyImage(
47
- * imageUrl,
48
- * 'Make it look like pixel art'
49
- * );
50
- * ```
51
- */
52
- export declare class KokimokiAi {
53
- private readonly client;
54
- constructor(client: KokimokiClient);
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
- chat(req: {
99
- model?: "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gemini-2.5-flash-lite" | "gemini-2.5-flash";
100
- systemPrompt?: string;
101
- userPrompt: string;
102
- temperature?: number;
103
- maxTokens?: number;
104
- responseMimeType?: string;
105
- }): Promise<{
106
- content: string;
107
- }>;
108
- /**
109
- * Generate structured JSON output from the AI model.
110
- *
111
- * Sends a chat request to the AI service with the expectation of receiving
112
- * a JSON-formatted response. This is useful for scenarios where the output
113
- * needs to be parsed or processed programmatically.
114
- *
115
- * @param req The chat request parameters.
116
- * @param req.model Optional. The AI model to use. Defaults to server-side default if not specified.
117
- * Available models:
118
- * - `gpt-4o`: OpenAI GPT-4 Optimized
119
- * - `gpt-4o-mini`: Smaller, faster GPT-4 variant
120
- * - `gpt-5`: OpenAI GPT-5 (latest)
121
- * - `gpt-5-mini`: Smaller GPT-5 variant
122
- * - `gpt-5-nano`: Smallest GPT-5 variant for lightweight tasks
123
- * - `gemini-2.5-flash-lite`: Google Gemini lite variant
124
- * - `gemini-2.5-flash`: Google Gemini fast variant
125
- * @param req.systemPrompt Optional. The system message that sets the behavior and context for the AI.
126
- * This helps define the AI's role, personality, and constraints.
127
- * @param req.userPrompt The user's message or question to send to the AI.
128
- * @param req.temperature Optional. Controls randomness in the response (0.0 to 1.0).
129
- * Lower values make output more focused and deterministic,
130
- * higher values make it more creative and varied.
131
- * @param req.maxTokens Optional. The maximum number of tokens to generate in the response.
132
- * Controls the length of the AI's output.
133
- *
134
- * @returns A promise that resolves to the parsed JSON object generated by the AI.
135
- *
136
- * @throws An error object if the API request fails or if the response is not valid JSON.
137
- */
138
- generateJson<T extends object>(req: {
139
- model?: "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "gemini-2.5-flash-lite" | "gemini-2.5-flash";
140
- systemPrompt?: string;
141
- userPrompt: string;
142
- temperature?: number;
143
- maxTokens?: number;
144
- }): Promise<T>;
145
- /**
146
- * Modify an image using the AI service.
147
- * @param baseImageUrl The URL of the base image to modify.
148
- * @param prompt The modification prompt to apply to the image.
149
- * @param tags Optional. Tags to associate with the image.
150
- * @returns A promise that resolves to the modified image upload information.
151
- */
152
- modifyImage(baseImageUrl: string, prompt: string, tags?: string[]): Promise<Upload>;
153
- }