skillprint-js-sdk 1.1.0-beta.1

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.
@@ -0,0 +1,456 @@
1
+ /**
2
+ * Skillprint API environments
3
+ */
4
+ declare enum ApiEnvironment {
5
+ PRODUCTION = "production",
6
+ STAGING = "staging"
7
+ }
8
+ /**
9
+ * Supported game parameter types
10
+ */
11
+ declare enum ParameterType {
12
+ FLOAT = "Float",
13
+ INTEGER = "Integer",
14
+ BOOLEAN = "Boolean"
15
+ }
16
+ /**
17
+ * Skillprint target mood optimization categories
18
+ */
19
+ declare enum Mood {
20
+ RELAX = "relax",
21
+ FOCUS = "focus",
22
+ CREATIVITY = "creativity",
23
+ COLLABORATE = "collaborate",
24
+ GRIT = "grit",
25
+ JOY = "joy",
26
+ CURIOSITY = "curiosity",
27
+ EMPATHY = "empathy",
28
+ AWE = "awe"
29
+ }
30
+ /**
31
+ * SDK Logger log severity levels
32
+ */
33
+ declare enum LogLevel {
34
+ INFO = "info",
35
+ WARNING = "warning",
36
+ ERROR = "error"
37
+ }
38
+
39
+ /**
40
+ * Options for configuring SkillprintConfig
41
+ */
42
+ interface SkillprintConfigOptions {
43
+ /** Unique game identifier slug registered in Skillprint */
44
+ gameName?: string;
45
+ /** Environment target: production or staging */
46
+ targetEnvironment?: ApiEnvironment | string;
47
+ /** API key for production environment */
48
+ productionPartnerApiKey?: string;
49
+ /** Base URL for production API */
50
+ productionApiBaseUrl?: string;
51
+ /** API key for staging environment */
52
+ stagingPartnerApiKey?: string;
53
+ /** Base URL for staging API */
54
+ stagingApiBaseUrl?: string;
55
+ /** List of initial game parameter definitions */
56
+ gameParameters?: ParameterDefinitionOptions[];
57
+ /** Interval in seconds between screenshot captures */
58
+ screenshotIntervalSeconds?: number;
59
+ /** Interval in seconds between posting screenshot batches */
60
+ screenshotPostIntervalSeconds?: number;
61
+ /** Interval in seconds between polling API parameter results */
62
+ pollResultsIntervalSeconds?: number;
63
+ /** Enable console log outputs for SDK operation */
64
+ enableDebugLogging?: boolean;
65
+ }
66
+ /**
67
+ * Options for defining a game parameter
68
+ */
69
+ interface ParameterDefinitionOptions {
70
+ /** Unique name of the parameter */
71
+ parameterName?: string;
72
+ /** Description of what this parameter controls */
73
+ description?: string;
74
+ /** Explanation of how Skillprint modifies this parameter */
75
+ howSDKChangesIt?: string;
76
+ /** Parameter data type: FLOAT, INTEGER, or BOOLEAN */
77
+ type?: ParameterType | string;
78
+ /** Minimum allowed numerical value */
79
+ minValue?: number;
80
+ /** Maximum allowed numerical value */
81
+ maxValue?: number;
82
+ /** Default value of the parameter */
83
+ defaultValue?: string | number | boolean;
84
+ }
85
+ /**
86
+ * Function type for canvas provider callback
87
+ */
88
+ type CanvasProvider = () => HTMLCanvasElement | null | undefined;
89
+ /**
90
+ * Function type for parameter update modifier action
91
+ */
92
+ type ParameterModifierAction = (value: number | boolean | string) => void;
93
+ /**
94
+ * Options for capturing screenshots
95
+ */
96
+ interface ScreenshotOptions {
97
+ /** Image MIME type format ('image/jpeg' or 'image/png') */
98
+ format?: string;
99
+ /** Image compression quality (0.0 to 1.0) */
100
+ quality?: number;
101
+ /** Maximum width to downscale image */
102
+ maxWidth?: number | null;
103
+ /** Maximum height to downscale image */
104
+ maxHeight?: number | null;
105
+ }
106
+ /**
107
+ * Response payload structure from parameter polling API
108
+ */
109
+ interface RawParameterUpdateData {
110
+ parameterName?: string;
111
+ newValue?: number | boolean | string;
112
+ [key: string]: unknown;
113
+ }
114
+ /**
115
+ * Response payload structure from polling endpoint
116
+ */
117
+ interface RawPollResultsData {
118
+ gameplayTips?: string;
119
+ state?: string;
120
+ parameterUpdates?: RawParameterUpdateData[];
121
+ }
122
+ /**
123
+ * Logger callback function signature
124
+ */
125
+ type SDKLogger = (message: string, level?: LogLevel) => void;
126
+ /**
127
+ * Extracted URL parameter values
128
+ */
129
+ interface UrlParametersInfo {
130
+ targetMood: Mood | string | null;
131
+ playerId: string | null;
132
+ }
133
+
134
+ /**
135
+ * Configuration options for initializing the Skillprint SDK.
136
+ */
137
+ declare class SkillprintConfig {
138
+ gameName: string;
139
+ targetEnvironment: ApiEnvironment | string;
140
+ productionPartnerApiKey: string;
141
+ productionApiBaseUrl: string;
142
+ stagingPartnerApiKey: string;
143
+ stagingApiBaseUrl: string;
144
+ gameParameters: ParameterDefinitionOptions[];
145
+ screenshotIntervalSeconds: number;
146
+ screenshotPostIntervalSeconds: number;
147
+ pollResultsIntervalSeconds: number;
148
+ enableDebugLogging: boolean;
149
+ constructor(options?: SkillprintConfigOptions);
150
+ /**
151
+ * Resolves the active partner API key based on current targetEnvironment.
152
+ */
153
+ get activePartnerApiKey(): string;
154
+ /**
155
+ * Resolves the active API base URL based on current targetEnvironment.
156
+ */
157
+ get activeApiBaseUrl(): string;
158
+ }
159
+
160
+ /**
161
+ * Defines a game parameter that Skillprint's AI model can modify.
162
+ */
163
+ declare class ParameterDefinition {
164
+ parameterName: string;
165
+ description: string;
166
+ howSDKChangesIt: string;
167
+ type: ParameterType | string;
168
+ minValue: number;
169
+ maxValue: number;
170
+ defaultValue: string | number | boolean;
171
+ updateAction: ParameterModifierAction | null;
172
+ constructor(options?: ParameterDefinitionOptions);
173
+ /**
174
+ * Checks if a converted value is valid for this parameter type and range.
175
+ * @param value The value to validate
176
+ */
177
+ isValid(value: unknown): boolean;
178
+ /**
179
+ * Converts a raw API value into the defined type for this parameter.
180
+ * @param rawValue Raw incoming value from API
181
+ */
182
+ convertValue(rawValue: unknown): number | boolean | string | null;
183
+ }
184
+
185
+ /**
186
+ * Request payload structure for starting a game session.
187
+ */
188
+ declare class StartSessionRequest {
189
+ sessionId: string;
190
+ game: string;
191
+ targetMood: string;
192
+ constructor(sessionId: string, game: string, targetMood: string);
193
+ }
194
+ /**
195
+ * Parameter info sent to Skillprint during session start.
196
+ */
197
+ declare class ParameterInfo {
198
+ name: string;
199
+ type: string;
200
+ description: string;
201
+ minValue: string | null;
202
+ maxValue: string | null;
203
+ constructor(name: string, type: string, description: string, minValue?: string | null, maxValue?: string | null);
204
+ }
205
+ /**
206
+ * Result model representing a single parameter update from Skillprint API.
207
+ */
208
+ declare class ParameterUpdateResult {
209
+ parameterName: string;
210
+ newValue: unknown;
211
+ _rawJson: string;
212
+ [key: string]: unknown;
213
+ constructor(data?: RawParameterUpdateData);
214
+ /**
215
+ * Extracts parsed new value from response payload.
216
+ */
217
+ getParsedValue(): unknown;
218
+ /**
219
+ * Converts value to target primitive type.
220
+ * @param targetType Target primitive type string ('number', 'integer', 'boolean', 'string')
221
+ */
222
+ convertToType(targetType: string): number | boolean | string | null;
223
+ /**
224
+ * Converts value based on parameter definition type and applies range clamping if necessary.
225
+ * @param paramDef Parameter definition object
226
+ */
227
+ convertToParameterType(paramDef: ParameterDefinition): number | boolean | string | null;
228
+ }
229
+ /**
230
+ * Poll results API response object.
231
+ */
232
+ declare class PollResultsResponse {
233
+ gameplayTips: string;
234
+ state: string;
235
+ parameterUpdates: ParameterUpdateResult[];
236
+ constructor(data?: RawPollResultsData);
237
+ }
238
+
239
+ interface ApiCallResult<T> {
240
+ success: boolean;
241
+ data: T;
242
+ }
243
+ declare class SkillprintAPIClient {
244
+ baseUrl: string;
245
+ partnerApiKey: string;
246
+ private logger?;
247
+ readonly START_SESSION_ENDPOINT = "/games/api/sessions/";
248
+ readonly UPLOAD_SCREENSHOTS_ENDPOINT = "/games/api/record-session/{sessionId}/";
249
+ readonly POLL_RESULTS_ENDPOINT = "/games/api/sessions/{sessionId}/";
250
+ readonly CREATE_USER_ENDPOINT = "/partners/api/users/add/";
251
+ readonly GET_USER_TOKEN_ENDPOINT = "/partners/api/users/auth/token/";
252
+ constructor(baseUrl: string, partnerApiKey: string, logger?: SDKLogger);
253
+ /**
254
+ * Starts a new Skillprint session.
255
+ */
256
+ startSession(sessionId: string, targetMood: Mood | string, customPlayerId?: string | null, gameName?: string, _gameParameters?: ParameterInfo[]): Promise<ApiCallResult<string>>;
257
+ /**
258
+ * Uploads a batch of captured screenshots for an active session.
259
+ */
260
+ postScreenshots(sessionId: string, screenshots: (Blob | null)[], isLastChunk?: boolean): Promise<ApiCallResult<string>>;
261
+ /**
262
+ * Polls API for updated parameter values for the active session.
263
+ */
264
+ pollParameterResults(sessionId: string): Promise<ApiCallResult<ParameterUpdateResult[]>>;
265
+ /**
266
+ * Creates or fetches user auth token for custom player ID.
267
+ */
268
+ createOrGetUserToken(customPlayerId: string): Promise<string>;
269
+ /**
270
+ * Registers a new user with Skillprint API.
271
+ */
272
+ createUser(internalId: string): Promise<string>;
273
+ /**
274
+ * Obtains auth token for existing user internalId.
275
+ */
276
+ getUserToken(internalId: string): Promise<string>;
277
+ }
278
+
279
+ /**
280
+ * Utility for capturing screenshots from HTML Canvas and WebGL contexts.
281
+ */
282
+ declare class ScreenshotUtility {
283
+ private logger?;
284
+ constructor(logger?: SDKLogger);
285
+ /**
286
+ * Captures a screenshot from a standard HTML canvas element as a Blob.
287
+ * @param canvas Target HTML Canvas element
288
+ * @param options Screenshot options (format, quality, max dimensions)
289
+ */
290
+ captureScreenshot(canvas: HTMLCanvasElement | null | undefined, options?: ScreenshotOptions): Promise<Blob | null>;
291
+ /**
292
+ * Alternative method for WebGL contexts that don't preserve drawing buffer.
293
+ * Reads pixel data directly from WebGL rendering context and flips vertically.
294
+ * @param gl WebGL rendering context (WebGLRenderingContext | WebGL2RenderingContext)
295
+ * @param canvas Target HTML Canvas element
296
+ * @param options Screenshot options
297
+ */
298
+ captureScreenshotWebGL(gl: WebGLRenderingContext | WebGL2RenderingContext, canvas: HTMLCanvasElement, options?: ScreenshotOptions): Promise<Blob | null>;
299
+ }
300
+
301
+ declare class WebGLUrlParameterExtractor {
302
+ /**
303
+ * Retrieves a URL query parameter by key.
304
+ * @param parameterName Name of the URL query parameter
305
+ */
306
+ static getUrlParameter(parameterName: string): string | null;
307
+ /**
308
+ * Gets current window URL string.
309
+ */
310
+ static getCurrentUrl(): string | null;
311
+ /**
312
+ * Extracts targetMood and playerId from URL query parameters.
313
+ */
314
+ static getSkillprintUrlParameters(): UrlParametersInfo;
315
+ /**
316
+ * Returns true if running in browser context with URL access.
317
+ */
318
+ static isUrlParameterSupported(): boolean;
319
+ }
320
+ /**
321
+ * Interface defining minimum required SkillprintManager methods for session helper
322
+ */
323
+ interface ISkillprintManagerSessionTarget {
324
+ log(message: string, level?: LogLevel): void;
325
+ startGameSession(targetMood: Mood | string, playerId?: string | null): Promise<void>;
326
+ }
327
+ declare class SkillprintSessionHelper {
328
+ /**
329
+ * Starts a Skillprint session, attempting to auto-extract parameters from URL.
330
+ * @param manager SkillprintManager instance
331
+ * @param fallbackMood Mood to use if not found in URL
332
+ * @param fallbackPlayerId Player ID to use if not found in URL
333
+ * @param overrideMood Forced mood override
334
+ * @param overridePlayerId Forced player ID override
335
+ */
336
+ static startSessionWithUrlParams(manager: ISkillprintManagerSessionTarget | null | undefined, fallbackMood?: Mood | string, fallbackPlayerId?: string | null, overrideMood?: Mood | string | null, overridePlayerId?: string | null): void;
337
+ }
338
+
339
+ declare class SkillprintManager {
340
+ static instance: SkillprintManager | null;
341
+ config: SkillprintConfig;
342
+ canvasProvider?: CanvasProvider;
343
+ currentSessionId: string | null;
344
+ isSessionActive: boolean;
345
+ apiClient: SkillprintAPIClient | null;
346
+ screenshotUtility: ScreenshotUtility | null;
347
+ screenshotQueue: (Blob | null)[];
348
+ registeredParameters: Map<string, ParameterDefinition>;
349
+ private screenshotCaptureTimer;
350
+ private screenshotPostTimer;
351
+ private pollResultsTimer;
352
+ constructor(config: SkillprintConfig, canvasProvider?: CanvasProvider);
353
+ static getInstance(): SkillprintManager | null;
354
+ initializeSDK(): void;
355
+ /**
356
+ * Registers a modifier callback action for a named parameter.
357
+ * @param parameterName Unique parameter identifier
358
+ * @param updateAction Callback invoked when Skillprint modifies this parameter
359
+ * @param expectedType Optional type check string ('number', 'integer', 'boolean')
360
+ */
361
+ registerParameterModifier(parameterName: string, updateAction: ParameterModifierAction, expectedType?: string | null): void;
362
+ /**
363
+ * Starts a new Skillprint AI gameplay session.
364
+ * @param targetMood Target optimization mood category
365
+ * @param customPlayerId Optional external player identifier
366
+ */
367
+ startGameSession(targetMood: Mood | string, customPlayerId?: string | null): Promise<void>;
368
+ /**
369
+ * Stops the active Skillprint session and clears all loop timers.
370
+ */
371
+ stopGameSession(): void;
372
+ private startScreenshotCaptureLoop;
373
+ private startScreenshotPostLoop;
374
+ private startPollResultsLoop;
375
+ applyParameterUpdates(updates: ParameterUpdateResult[]): void;
376
+ generateSessionId(): string;
377
+ log(message: string, level?: LogLevel): void;
378
+ getCurrentSessionId(): string | null;
379
+ getConfig(): SkillprintConfig;
380
+ startGameSessionFromUrl(fallbackMood?: Mood | string, fallbackPlayerId?: string | null): void;
381
+ startGameSessionWithOverrides(fallbackMood?: Mood | string, fallbackPlayerId?: string | null, overrideMood?: Mood | string | null, overridePlayerId?: string | null): void;
382
+ getUrlParametersInfo(): string;
383
+ }
384
+
385
+ /** Minimal interface representing Phaser Scene & Game */
386
+ interface PhaserSceneLike {
387
+ game: {
388
+ canvas: HTMLCanvasElement;
389
+ };
390
+ }
391
+ declare class PhaserSkillprintAdapter {
392
+ scene: PhaserSceneLike;
393
+ config: SkillprintConfig;
394
+ manager: SkillprintManager;
395
+ constructor(scene: PhaserSceneLike, config: SkillprintConfig);
396
+ static create(scene: PhaserSceneLike, config: SkillprintConfig): PhaserSkillprintAdapter;
397
+ startSession(targetMood: Mood | string, customPlayerId?: string | null): Promise<void>;
398
+ stopSession(): void;
399
+ registerParameter(parameterName: string, updateAction: ParameterModifierAction, expectedType?: string | null): void;
400
+ /**
401
+ * Phaser-specific helper to register sprite property updates directly.
402
+ */
403
+ registerSpriteProperty(parameterName: string, sprite: Record<string, unknown>, propertyName: string): void;
404
+ }
405
+
406
+ /** Minimal interface representing Three.js WebGLRenderer */
407
+ interface ThreeRendererLike {
408
+ domElement: HTMLCanvasElement;
409
+ }
410
+ declare class ThreeSkillprintAdapter {
411
+ renderer: ThreeRendererLike;
412
+ config: SkillprintConfig;
413
+ manager: SkillprintManager;
414
+ constructor(renderer: ThreeRendererLike, config: SkillprintConfig);
415
+ static create(renderer: ThreeRendererLike, config: SkillprintConfig): ThreeSkillprintAdapter;
416
+ startSession(targetMood: Mood | string, customPlayerId?: string | null): Promise<void>;
417
+ stopSession(): void;
418
+ registerParameter(parameterName: string, updateAction: ParameterModifierAction, expectedType?: string | null): void;
419
+ /**
420
+ * Three.js-specific helper to register object or nested material property updates.
421
+ */
422
+ registerObjectProperty(parameterName: string, object: Record<string, any>, propertyName: string): void;
423
+ }
424
+
425
+ /** Minimal interface representing PixiJS Application */
426
+ interface PixiApplicationLike {
427
+ view?: HTMLCanvasElement;
428
+ canvas?: HTMLCanvasElement;
429
+ }
430
+ declare class PixiSkillprintAdapter {
431
+ app: PixiApplicationLike;
432
+ config: SkillprintConfig;
433
+ manager: SkillprintManager;
434
+ constructor(app: PixiApplicationLike, config: SkillprintConfig);
435
+ static create(app: PixiApplicationLike, config: SkillprintConfig): PixiSkillprintAdapter;
436
+ startSession(targetMood: Mood | string, customPlayerId?: string | null): Promise<void>;
437
+ stopSession(): void;
438
+ registerParameter(parameterName: string, updateAction: ParameterModifierAction, expectedType?: string | null): void;
439
+ /**
440
+ * PixiJS-specific helper to register display object property updates.
441
+ */
442
+ registerDisplayObjectProperty(parameterName: string, displayObject: Record<string, any>, propertyName: string): void;
443
+ }
444
+
445
+ declare class GenericCanvasSkillprintAdapter {
446
+ canvas: HTMLCanvasElement;
447
+ config: SkillprintConfig;
448
+ manager: SkillprintManager;
449
+ constructor(canvas: HTMLCanvasElement, config: SkillprintConfig);
450
+ static create(canvas: HTMLCanvasElement, config: SkillprintConfig): GenericCanvasSkillprintAdapter;
451
+ startSession(targetMood: Mood | string, customPlayerId?: string | null): Promise<void>;
452
+ stopSession(): void;
453
+ registerParameter(parameterName: string, updateAction: ParameterModifierAction, expectedType?: string | null): void;
454
+ }
455
+
456
+ export { ApiEnvironment, type CanvasProvider, GenericCanvasSkillprintAdapter, LogLevel, Mood, ParameterDefinition, type ParameterDefinitionOptions, ParameterInfo, type ParameterModifierAction, ParameterType, ParameterUpdateResult, PhaserSkillprintAdapter, PixiSkillprintAdapter, PollResultsResponse, type RawParameterUpdateData, type RawPollResultsData, type SDKLogger, type ScreenshotOptions, ScreenshotUtility, SkillprintAPIClient, SkillprintConfig, type SkillprintConfigOptions, SkillprintManager, SkillprintSessionHelper, StartSessionRequest, ThreeSkillprintAdapter, type UrlParametersInfo, WebGLUrlParameterExtractor };