@casual-simulation/aux-records 3.2.1 → 3.2.2-alpha.5685728183
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/AIChatInterface.d.ts +127 -0
- package/AIChatInterface.js +15 -0
- package/AIChatInterface.js.map +1 -0
- package/AIController.d.ts +153 -0
- package/AIController.js +183 -0
- package/AIController.js.map +1 -0
- package/AIGenerateSkyboxInterface.d.ts +63 -0
- package/AIGenerateSkyboxInterface.js +2 -0
- package/AIGenerateSkyboxInterface.js.map +1 -0
- package/AuthController.d.ts +9 -0
- package/AuthController.js +38 -24
- package/AuthController.js.map +1 -1
- package/BlockadeLabsGenerateSkyboxInterface.d.ts +14 -0
- package/BlockadeLabsGenerateSkyboxInterface.js +100 -0
- package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -0
- package/Errors.d.ts +8 -0
- package/OpenAIChatInterface.d.ts +20 -0
- package/OpenAIChatInterface.js +54 -0
- package/OpenAIChatInterface.js.map +1 -0
- package/RecordsHttpServer.d.ts +5 -1
- package/RecordsHttpServer.js +117 -1
- package/RecordsHttpServer.js.map +1 -1
- package/Utils.js +6 -0
- package/Utils.js.map +1 -1
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Defines an interface that is able to send and receive AI chat messages.
|
|
4
|
+
*/
|
|
5
|
+
export interface AIChatInterface {
|
|
6
|
+
/**
|
|
7
|
+
* Sends a chat request to the AI API.
|
|
8
|
+
* @param request The request to send.
|
|
9
|
+
*/
|
|
10
|
+
chat(request: AIChatInterfaceRequest): Promise<AIChatInterfaceResponse>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Defines an interface that represents an AI chat request.
|
|
14
|
+
*/
|
|
15
|
+
export interface AIChatInterfaceRequest {
|
|
16
|
+
/**
|
|
17
|
+
* The model that should be used.
|
|
18
|
+
*/
|
|
19
|
+
model: string;
|
|
20
|
+
/**
|
|
21
|
+
* The messages that should be sent to the AI.
|
|
22
|
+
*/
|
|
23
|
+
messages: AIChatMessage[];
|
|
24
|
+
/**
|
|
25
|
+
* The temperature of the request.
|
|
26
|
+
*/
|
|
27
|
+
temperature: number;
|
|
28
|
+
/**
|
|
29
|
+
* The nucleus sampling probability.
|
|
30
|
+
*/
|
|
31
|
+
topP?: number;
|
|
32
|
+
/**
|
|
33
|
+
* The presence penalty.
|
|
34
|
+
*
|
|
35
|
+
* Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
|
|
36
|
+
*/
|
|
37
|
+
presencePenalty?: number;
|
|
38
|
+
/**
|
|
39
|
+
* The frequency penalty.
|
|
40
|
+
*
|
|
41
|
+
* Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
|
|
42
|
+
*/
|
|
43
|
+
frequencyPenalty?: number;
|
|
44
|
+
/**
|
|
45
|
+
* The list of stop words that should be used.
|
|
46
|
+
*
|
|
47
|
+
* If the AI generates a sequence of tokens that match one of the given words, then it will stop generating tokens.
|
|
48
|
+
*/
|
|
49
|
+
stopWords?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* The ID of the user that is making the request.
|
|
52
|
+
*/
|
|
53
|
+
userId: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Defines an interface that represents an AI chat response.
|
|
57
|
+
*/
|
|
58
|
+
export interface AIChatInterfaceResponse {
|
|
59
|
+
/**
|
|
60
|
+
* The messages that the AI responded with.
|
|
61
|
+
*/
|
|
62
|
+
choices: AIChatMessage[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Defines an interface that represents a single chat message in a conversation with an AI.
|
|
66
|
+
*
|
|
67
|
+
* @dochash types/ai
|
|
68
|
+
* @docname AIChatMessage
|
|
69
|
+
*/
|
|
70
|
+
export interface AIChatMessage {
|
|
71
|
+
/**
|
|
72
|
+
* The role of the message.
|
|
73
|
+
*
|
|
74
|
+
* - `system` means that the message was generated by the system. Useful for telling the AI how to behave while.
|
|
75
|
+
* - `user` means that the message was generated by the user.
|
|
76
|
+
* - `assistant` means that the message was generated by the AI assistant.
|
|
77
|
+
* - `function` means that the message contains the results of a function call.
|
|
78
|
+
*/
|
|
79
|
+
role: 'system' | 'user' | 'assistant' | 'function';
|
|
80
|
+
/**
|
|
81
|
+
* The contents of the message.
|
|
82
|
+
*/
|
|
83
|
+
content: string;
|
|
84
|
+
/**
|
|
85
|
+
* The name of the author of the message.
|
|
86
|
+
*
|
|
87
|
+
* This is required if the role is `function`.
|
|
88
|
+
*/
|
|
89
|
+
author?: string;
|
|
90
|
+
/**
|
|
91
|
+
* The reason why the message was finished.
|
|
92
|
+
*/
|
|
93
|
+
finishReason?: string;
|
|
94
|
+
/**
|
|
95
|
+
* @hidden
|
|
96
|
+
*/
|
|
97
|
+
functionCall?: AIFunctionCall;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Defines a schema that represents an AI chat message.
|
|
101
|
+
*/
|
|
102
|
+
export declare const AI_CHAT_MESSAGE_SCHEMA: z.ZodObject<{
|
|
103
|
+
role: z.ZodUnion<[z.ZodLiteral<"system">, z.ZodLiteral<"user">, z.ZodLiteral<"assistant">, z.ZodLiteral<"function">]>;
|
|
104
|
+
content: z.ZodString;
|
|
105
|
+
author: z.ZodOptional<z.ZodString>;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
role?: "function" | "system" | "user" | "assistant";
|
|
108
|
+
content?: string;
|
|
109
|
+
author?: string;
|
|
110
|
+
}, {
|
|
111
|
+
role?: "function" | "system" | "user" | "assistant";
|
|
112
|
+
content?: string;
|
|
113
|
+
author?: string;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Defines an interface that represents an AI function call.
|
|
117
|
+
*/
|
|
118
|
+
export interface AIFunctionCall {
|
|
119
|
+
name: string;
|
|
120
|
+
/**
|
|
121
|
+
* The arguments that should be passed to the function.
|
|
122
|
+
*/
|
|
123
|
+
arguments: {
|
|
124
|
+
[key: string]: any;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=AIChatInterface.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Defines a schema that represents an AI chat message.
|
|
4
|
+
*/
|
|
5
|
+
export const AI_CHAT_MESSAGE_SCHEMA = z.object({
|
|
6
|
+
role: z.union([
|
|
7
|
+
z.literal('system'),
|
|
8
|
+
z.literal('user'),
|
|
9
|
+
z.literal('assistant'),
|
|
10
|
+
z.literal('function'),
|
|
11
|
+
]),
|
|
12
|
+
content: z.string().nonempty(),
|
|
13
|
+
author: z.string().nonempty().optional(),
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=AIChatInterface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIChatInterface.js","sourceRoot":"","sources":["AIChatInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAkHxB;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC;QACV,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QACnB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;QACjB,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QACtB,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC;KACxB,CAAC;IACF,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CAC3C,CAAC,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { InvalidSubscriptionTierError, NotLoggedInError, NotSubscribedError, NotSupportedError, ServerError } from './Errors';
|
|
2
|
+
import { AIChatInterface, AIChatMessage } from './AIChatInterface';
|
|
3
|
+
import { AIGenerateSkyboxInterface, AIGenerateSkyboxInterfaceBlockadeLabsOptions } from './AIGenerateSkyboxInterface';
|
|
4
|
+
export interface AIConfiguration {
|
|
5
|
+
chat: AIChatConfiguration | null;
|
|
6
|
+
generateSkybox: AIGenerateSkyboxConfiguration | null;
|
|
7
|
+
}
|
|
8
|
+
export interface AIChatConfiguration {
|
|
9
|
+
interface: AIChatInterface;
|
|
10
|
+
options: AIChatOptions;
|
|
11
|
+
}
|
|
12
|
+
export interface AIChatOptions {
|
|
13
|
+
/**
|
|
14
|
+
* The model that should be used when none is specified in a request.
|
|
15
|
+
*/
|
|
16
|
+
defaultModel: string;
|
|
17
|
+
/**
|
|
18
|
+
* The list of allowed models that are allowed to be used for chat.
|
|
19
|
+
*/
|
|
20
|
+
allowedChatModels: string[];
|
|
21
|
+
/**
|
|
22
|
+
* The list of subscription tiers that are allowed to be used for chat.
|
|
23
|
+
*
|
|
24
|
+
* - `true` indicates that all users are allowed, regardless of their subscription tier or if they are even subscribed.
|
|
25
|
+
* - An array of strings indicates that only users with the given subscription tiers are allowed.
|
|
26
|
+
*/
|
|
27
|
+
allowedChatSubscriptionTiers: true | string[];
|
|
28
|
+
}
|
|
29
|
+
export interface AIGenerateSkyboxConfiguration {
|
|
30
|
+
interface: AIGenerateSkyboxInterface;
|
|
31
|
+
options: AIGenerateSkyboxOptions;
|
|
32
|
+
}
|
|
33
|
+
export interface AIGenerateSkyboxOptions {
|
|
34
|
+
/**
|
|
35
|
+
* The list of subscription tiers that are allowed to be used for generate skybox.
|
|
36
|
+
*
|
|
37
|
+
* - `true` indicates that all users are allowed, regardless of their subscription tier or if they are even subscribed.
|
|
38
|
+
* - An array of strings indicates that only users with the given subscription tiers are allowed.
|
|
39
|
+
*/
|
|
40
|
+
allowedSubscriptionTiers: true | string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Defines a class that is able to handle AI requests.
|
|
44
|
+
*/
|
|
45
|
+
export declare class AIController {
|
|
46
|
+
private _chat;
|
|
47
|
+
private _chatOptions;
|
|
48
|
+
private _generateSkybox;
|
|
49
|
+
private _allowedChatModels;
|
|
50
|
+
private _allowedChatSubscriptionTiers;
|
|
51
|
+
private _allowedGenerateSkyboxSubscriptionTiers;
|
|
52
|
+
constructor(configuration: AIConfiguration);
|
|
53
|
+
chat(request: AIChatRequest): Promise<AIChatResponse>;
|
|
54
|
+
generateSkybox(request: AIGenerateSkyboxRequest): Promise<AIGenerateSkyboxResponse>;
|
|
55
|
+
private _matchesSubscriptionTiers;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Defines an AI Chat request.
|
|
59
|
+
*/
|
|
60
|
+
export interface AIChatRequest {
|
|
61
|
+
/**
|
|
62
|
+
* The messages to include in the request.
|
|
63
|
+
*/
|
|
64
|
+
messages: AIChatMessage[];
|
|
65
|
+
/**
|
|
66
|
+
* The model that should be used.
|
|
67
|
+
*/
|
|
68
|
+
model?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The ID of the currently logged in user.
|
|
71
|
+
*/
|
|
72
|
+
userId: string;
|
|
73
|
+
/**
|
|
74
|
+
* The subscription tier of the user.
|
|
75
|
+
* Should be null if the user is not logged in or if they do not have a subscription.
|
|
76
|
+
*/
|
|
77
|
+
userSubscriptionTier: string;
|
|
78
|
+
/**
|
|
79
|
+
* The temperature of the request.
|
|
80
|
+
*/
|
|
81
|
+
temperature?: number;
|
|
82
|
+
/**
|
|
83
|
+
* The nucleus sampling probability.
|
|
84
|
+
*/
|
|
85
|
+
topP?: number;
|
|
86
|
+
/**
|
|
87
|
+
* The presence penalty.
|
|
88
|
+
*
|
|
89
|
+
* Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.
|
|
90
|
+
*/
|
|
91
|
+
presencePenalty?: number;
|
|
92
|
+
/**
|
|
93
|
+
* The frequency penalty.
|
|
94
|
+
*
|
|
95
|
+
* Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
|
|
96
|
+
*/
|
|
97
|
+
frequencyPenalty?: number;
|
|
98
|
+
/**
|
|
99
|
+
* The list of stop words that should be used.
|
|
100
|
+
*
|
|
101
|
+
* If the AI generates a sequence of tokens that match one of the given words, then it will stop generating tokens.
|
|
102
|
+
*/
|
|
103
|
+
stopWords?: string[];
|
|
104
|
+
}
|
|
105
|
+
export type AIChatResponse = AIChatSuccess | AIChatFailure;
|
|
106
|
+
export interface AIChatSuccess {
|
|
107
|
+
success: true;
|
|
108
|
+
choices: AIChatMessage[];
|
|
109
|
+
}
|
|
110
|
+
export interface AIChatFailure {
|
|
111
|
+
success: false;
|
|
112
|
+
errorCode: ServerError | NotLoggedInError | NotSubscribedError | InvalidSubscriptionTierError | NotSupportedError | 'invalid_model';
|
|
113
|
+
errorMessage: string;
|
|
114
|
+
allowedSubscriptionTiers?: string[];
|
|
115
|
+
currentSubscriptionTier?: string;
|
|
116
|
+
}
|
|
117
|
+
export interface AIGenerateSkyboxRequest {
|
|
118
|
+
/**
|
|
119
|
+
* The prompt that should be used to generate the skybox.
|
|
120
|
+
*/
|
|
121
|
+
prompt: string;
|
|
122
|
+
/**
|
|
123
|
+
* The ID of the user that is currently logged in.
|
|
124
|
+
*/
|
|
125
|
+
userId: string;
|
|
126
|
+
/**
|
|
127
|
+
* The subscription tier of the user.
|
|
128
|
+
* Should be null if the user is not logged in or if they do not have a subscription.
|
|
129
|
+
*/
|
|
130
|
+
userSubscriptionTier: string;
|
|
131
|
+
/**
|
|
132
|
+
* The negative prompt for the skybox.
|
|
133
|
+
*/
|
|
134
|
+
negativePrompt?: string;
|
|
135
|
+
/**
|
|
136
|
+
* Options specific to blockade labs.
|
|
137
|
+
*/
|
|
138
|
+
blockadeLabs?: AIGenerateSkyboxInterfaceBlockadeLabsOptions;
|
|
139
|
+
}
|
|
140
|
+
export type AIGenerateSkyboxResponse = AIGenerateSkyboxSuccess | AIGenerateSkyboxFailure;
|
|
141
|
+
export interface AIGenerateSkyboxSuccess {
|
|
142
|
+
success: true;
|
|
143
|
+
fileUrl: string;
|
|
144
|
+
thumbnailUrl: string;
|
|
145
|
+
}
|
|
146
|
+
export interface AIGenerateSkyboxFailure {
|
|
147
|
+
success: false;
|
|
148
|
+
errorCode: ServerError | NotLoggedInError | NotSubscribedError | InvalidSubscriptionTierError | NotSupportedError;
|
|
149
|
+
errorMessage: string;
|
|
150
|
+
allowedSubscriptionTiers?: string[];
|
|
151
|
+
currentSubscriptionTier?: string;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=AIController.d.ts.map
|
package/AIController.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Defines a class that is able to handle AI requests.
|
|
12
|
+
*/
|
|
13
|
+
export class AIController {
|
|
14
|
+
constructor(configuration) {
|
|
15
|
+
if (configuration.chat) {
|
|
16
|
+
const chat = configuration.chat;
|
|
17
|
+
const options = chat.options;
|
|
18
|
+
this._chat = chat.interface;
|
|
19
|
+
this._chatOptions = options;
|
|
20
|
+
this._allowedChatModels = new Set(options.allowedChatModels);
|
|
21
|
+
this._allowedChatSubscriptionTiers =
|
|
22
|
+
typeof options.allowedChatSubscriptionTiers === 'boolean'
|
|
23
|
+
? options.allowedChatSubscriptionTiers
|
|
24
|
+
: new Set(options.allowedChatSubscriptionTiers);
|
|
25
|
+
}
|
|
26
|
+
if (configuration.generateSkybox) {
|
|
27
|
+
this._generateSkybox = configuration.generateSkybox.interface;
|
|
28
|
+
const options = configuration.generateSkybox.options;
|
|
29
|
+
this._allowedGenerateSkyboxSubscriptionTiers =
|
|
30
|
+
typeof options.allowedSubscriptionTiers === 'boolean'
|
|
31
|
+
? options.allowedSubscriptionTiers
|
|
32
|
+
: new Set(options.allowedSubscriptionTiers);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
chat(request) {
|
|
36
|
+
var _a;
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
try {
|
|
39
|
+
if (!this._chat) {
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
errorCode: 'not_supported',
|
|
43
|
+
errorMessage: 'This operation is not supported.',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (!request.userId) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
errorCode: 'not_logged_in',
|
|
50
|
+
errorMessage: 'The user must be logged in. Please provide a sessionKey or a recordKey.',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (!this._matchesSubscriptionTiers(request.userSubscriptionTier, this._allowedChatSubscriptionTiers)) {
|
|
54
|
+
if (!request.userSubscriptionTier) {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
errorCode: 'not_subscribed',
|
|
58
|
+
errorMessage: 'The user must be subscribed in order to use this operation.',
|
|
59
|
+
allowedSubscriptionTiers: [
|
|
60
|
+
...this
|
|
61
|
+
._allowedChatSubscriptionTiers,
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
errorCode: 'invalid_subscription_tier',
|
|
69
|
+
errorMessage: 'This operation is not available to the user at their current subscription tier.',
|
|
70
|
+
allowedSubscriptionTiers: [
|
|
71
|
+
...this
|
|
72
|
+
._allowedChatSubscriptionTiers,
|
|
73
|
+
],
|
|
74
|
+
currentSubscriptionTier: request.userSubscriptionTier,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!!request.model &&
|
|
79
|
+
!this._allowedChatModels.has(request.model)) {
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
errorCode: 'invalid_model',
|
|
83
|
+
errorMessage: `The given model is not allowed for chats.`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const result = yield this._chat.chat({
|
|
87
|
+
messages: request.messages,
|
|
88
|
+
model: (_a = request.model) !== null && _a !== void 0 ? _a : this._chatOptions.defaultModel,
|
|
89
|
+
temperature: request.temperature,
|
|
90
|
+
topP: request.topP,
|
|
91
|
+
frequencyPenalty: request.frequencyPenalty,
|
|
92
|
+
presencePenalty: request.presencePenalty,
|
|
93
|
+
stopWords: request.stopWords,
|
|
94
|
+
userId: request.userId,
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
success: true,
|
|
98
|
+
choices: result.choices,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
console.error('[AIController] Error handling chat request:', err);
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
errorCode: 'server_error',
|
|
106
|
+
errorMessage: 'A server error occurred.',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
generateSkybox(request) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
if (!this._generateSkybox) {
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
errorCode: 'not_supported',
|
|
118
|
+
errorMessage: 'This operation is not supported.',
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (!request.userId) {
|
|
122
|
+
return {
|
|
123
|
+
success: false,
|
|
124
|
+
errorCode: 'not_logged_in',
|
|
125
|
+
errorMessage: 'The user must be logged in. Please provide a sessionKey or a recordKey.',
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (!this._matchesSubscriptionTiers(request.userSubscriptionTier, this._allowedGenerateSkyboxSubscriptionTiers)) {
|
|
129
|
+
if (!request.userSubscriptionTier) {
|
|
130
|
+
return {
|
|
131
|
+
success: false,
|
|
132
|
+
errorCode: 'not_subscribed',
|
|
133
|
+
errorMessage: 'The user must be subscribed in order to use this operation.',
|
|
134
|
+
allowedSubscriptionTiers: [
|
|
135
|
+
...this
|
|
136
|
+
._allowedGenerateSkyboxSubscriptionTiers,
|
|
137
|
+
],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
return {
|
|
142
|
+
success: false,
|
|
143
|
+
errorCode: 'invalid_subscription_tier',
|
|
144
|
+
errorMessage: 'This operation is not available to the user at their current subscription tier.',
|
|
145
|
+
allowedSubscriptionTiers: [
|
|
146
|
+
...this
|
|
147
|
+
._allowedGenerateSkyboxSubscriptionTiers,
|
|
148
|
+
],
|
|
149
|
+
currentSubscriptionTier: request.userSubscriptionTier,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const result = yield this._generateSkybox.generateSkybox({
|
|
154
|
+
prompt: request.prompt,
|
|
155
|
+
negativePrompt: request.negativePrompt,
|
|
156
|
+
blockadeLabs: request.blockadeLabs,
|
|
157
|
+
});
|
|
158
|
+
if (result.success === true) {
|
|
159
|
+
return {
|
|
160
|
+
success: true,
|
|
161
|
+
fileUrl: result.fileUrl,
|
|
162
|
+
thumbnailUrl: result.thumbnailUrl,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
console.error('[AIController] Error handling generate skybox request:', err);
|
|
171
|
+
return {
|
|
172
|
+
success: false,
|
|
173
|
+
errorCode: 'server_error',
|
|
174
|
+
errorMessage: 'A server error occurred.',
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
_matchesSubscriptionTiers(tier, allowedTiers) {
|
|
180
|
+
return allowedTiers === true || allowedTiers.has(tier);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=AIController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIController.js","sourceRoot":"","sources":["AIController.ts"],"names":[],"mappings":";;;;;;;;;AA0DA;;GAEG;AACH,MAAM,OAAO,YAAY;IAWrB,YAAY,aAA8B;QACtC,IAAI,aAAa,CAAC,IAAI,EAAE;YACpB,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;YAChC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC;YAC5B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;YAC5B,IAAI,CAAC,kBAAkB,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;YAC7D,IAAI,CAAC,6BAA6B;gBAC9B,OAAO,OAAO,CAAC,4BAA4B,KAAK,SAAS;oBACrD,CAAC,CAAC,OAAO,CAAC,4BAA4B;oBACtC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC;SAC3D;QAED,IAAI,aAAa,CAAC,cAAc,EAAE;YAC9B,IAAI,CAAC,eAAe,GAAG,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC;YAC9D,MAAM,OAAO,GAAG,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC;YACrD,IAAI,CAAC,uCAAuC;gBACxC,OAAO,OAAO,CA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
|
|
1
|
+
import { ServerError } from './Errors';
|
|
2
|
+
/**
|
|
3
|
+
* Defines an interface that is able to send and receive AI chat messages.
|
|
4
|
+
*/
|
|
5
|
+
export interface AIGenerateSkyboxInterface {
|
|
6
|
+
/**
|
|
7
|
+
* Sends a generate skybox request to the AI API.
|
|
8
|
+
* @param request The request to send.
|
|
9
|
+
*/
|
|
10
|
+
generateSkybox(request: AIGenerateSkyboxInterfaceRequest): Promise<AIGenerateSkyboxInterfaceResponse>;
|
|
11
|
+
}
|
|
12
|
+
export interface AIGenerateSkyboxInterfaceRequest {
|
|
13
|
+
/**
|
|
14
|
+
* The prompt to use.
|
|
15
|
+
*/
|
|
16
|
+
prompt: string;
|
|
17
|
+
/**
|
|
18
|
+
* The negative prompt to use.
|
|
19
|
+
*/
|
|
20
|
+
negativePrompt?: string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Options specific to blockade labs.
|
|
23
|
+
*/
|
|
24
|
+
blockadeLabs?: AIGenerateSkyboxInterfaceBlockadeLabsOptions;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options specific to blockade labs.
|
|
28
|
+
*/
|
|
29
|
+
export interface AIGenerateSkyboxInterfaceBlockadeLabsOptions {
|
|
30
|
+
/**
|
|
31
|
+
* The pre-defined style ID for the skybox.
|
|
32
|
+
*/
|
|
33
|
+
skyboxStyleId?: number;
|
|
34
|
+
/**
|
|
35
|
+
* The ID of a previously generated skybox.
|
|
36
|
+
*/
|
|
37
|
+
remixImagineId?: number;
|
|
38
|
+
/**
|
|
39
|
+
* The random seed to use for generating the skybox.
|
|
40
|
+
*/
|
|
41
|
+
seed?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Defines an interface that represents an generate skybox response.
|
|
45
|
+
*/
|
|
46
|
+
export type AIGenerateSkyboxInterfaceResponse = AIGenerateSkyboxInterfaceResponseSuccess | AIGenerateSkyboxInterfaceResponseFailure;
|
|
47
|
+
export interface AIGenerateSkyboxInterfaceResponseSuccess {
|
|
48
|
+
success: true;
|
|
49
|
+
/**
|
|
50
|
+
* The URL of the file that was generated.
|
|
51
|
+
*/
|
|
52
|
+
fileUrl: string;
|
|
53
|
+
/**
|
|
54
|
+
* The URL of the thumbnail for the file.
|
|
55
|
+
*/
|
|
56
|
+
thumbnailUrl?: string;
|
|
57
|
+
}
|
|
58
|
+
export interface AIGenerateSkyboxInterfaceResponseFailure {
|
|
59
|
+
success: false;
|
|
60
|
+
errorCode: ServerError;
|
|
61
|
+
errorMessage: string;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=AIGenerateSkyboxInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIGenerateSkyboxInterface.js","sourceRoot":"","sources":["AIGenerateSkyboxInterface.ts"],"names":[],"mappings":""}
|
package/AuthController.d.ts
CHANGED
|
@@ -81,6 +81,7 @@ export declare class AuthController {
|
|
|
81
81
|
* @param request The request.
|
|
82
82
|
*/
|
|
83
83
|
getUserInfo(request: GetUserInfoRequest): Promise<GetUserInfoResult>;
|
|
84
|
+
private _getSubscriptionInfo;
|
|
84
85
|
/**
|
|
85
86
|
* Attempts to update a user's metadata.
|
|
86
87
|
* @param request The request for the operation.
|
|
@@ -199,6 +200,14 @@ export interface ValidateSessionKeySuccess {
|
|
|
199
200
|
userId: string;
|
|
200
201
|
sessionId: string;
|
|
201
202
|
allSessionsRevokedTimeMs?: number;
|
|
203
|
+
/**
|
|
204
|
+
* The subscription ID for the user.
|
|
205
|
+
*/
|
|
206
|
+
subscriptionTier?: string;
|
|
207
|
+
/**
|
|
208
|
+
* The ID of the subscription that the user is subscribed to.
|
|
209
|
+
*/
|
|
210
|
+
subscriptionId?: string;
|
|
202
211
|
}
|
|
203
212
|
export interface ValidateSessionKeyFailure {
|
|
204
213
|
success: false;
|
package/AuthController.js
CHANGED
|
@@ -447,11 +447,14 @@ export class AuthController {
|
|
|
447
447
|
};
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
|
+
const { subscriptionId, subscriptionTier } = this._getSubscriptionInfo(userInfo);
|
|
450
451
|
return {
|
|
451
452
|
success: true,
|
|
452
453
|
userId: session.userId,
|
|
453
454
|
sessionId: session.sessionId,
|
|
454
455
|
allSessionsRevokedTimeMs: userInfo.allSessionRevokeTimeMs,
|
|
456
|
+
subscriptionId: subscriptionId !== null && subscriptionId !== void 0 ? subscriptionId : undefined,
|
|
457
|
+
subscriptionTier: subscriptionTier !== null && subscriptionTier !== void 0 ? subscriptionTier : undefined,
|
|
455
458
|
};
|
|
456
459
|
}
|
|
457
460
|
catch (err) {
|
|
@@ -729,7 +732,6 @@ export class AuthController {
|
|
|
729
732
|
* @param request The request.
|
|
730
733
|
*/
|
|
731
734
|
getUserInfo(request) {
|
|
732
|
-
var _a, _b, _c;
|
|
733
735
|
return __awaiter(this, void 0, void 0, function* () {
|
|
734
736
|
if (typeof request.userId !== 'string' || request.userId === '') {
|
|
735
737
|
return {
|
|
@@ -763,28 +765,7 @@ export class AuthController {
|
|
|
763
765
|
if (!result) {
|
|
764
766
|
throw new Error('Unable to find user even though a valid session key was presented!');
|
|
765
767
|
}
|
|
766
|
-
const hasActiveSubscription = this.
|
|
767
|
-
isActiveSubscription(result.subscriptionStatus);
|
|
768
|
-
let sub;
|
|
769
|
-
if (result.subscriptionId) {
|
|
770
|
-
sub = (_a = this._subscriptionConfig) === null || _a === void 0 ? void 0 : _a.subscriptions.find((s) => s.id === result.subscriptionId);
|
|
771
|
-
}
|
|
772
|
-
if (!sub) {
|
|
773
|
-
sub = (_b = this._subscriptionConfig) === null || _b === void 0 ? void 0 : _b.subscriptions.find((s) => s.defaultSubscription);
|
|
774
|
-
if (sub) {
|
|
775
|
-
console.log('[AuthController] [getUserInfo] Using default subscription for user.');
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
if (!sub) {
|
|
779
|
-
sub = (_c = this._subscriptionConfig) === null || _c === void 0 ? void 0 : _c.subscriptions[0];
|
|
780
|
-
if (sub) {
|
|
781
|
-
console.log('[AuthController] [getUserInfo] Using first subscription for user.');
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
let tier = 'beta';
|
|
785
|
-
if (sub && sub.tier) {
|
|
786
|
-
tier = sub.tier;
|
|
787
|
-
}
|
|
768
|
+
const { hasActiveSubscription, subscriptionTier: tier } = this._getSubscriptionInfo(result);
|
|
788
769
|
return {
|
|
789
770
|
success: true,
|
|
790
771
|
userId: result.id,
|
|
@@ -793,7 +774,7 @@ export class AuthController {
|
|
|
793
774
|
phoneNumber: result.phoneNumber,
|
|
794
775
|
avatarPortraitUrl: result.avatarPortraitUrl,
|
|
795
776
|
avatarUrl: result.avatarUrl,
|
|
796
|
-
hasActiveSubscription,
|
|
777
|
+
hasActiveSubscription: hasActiveSubscription,
|
|
797
778
|
subscriptionTier: hasActiveSubscription ? tier : null,
|
|
798
779
|
openAiKey: hasActiveSubscription ? result.openAiKey : null,
|
|
799
780
|
};
|
|
@@ -808,6 +789,39 @@ export class AuthController {
|
|
|
808
789
|
}
|
|
809
790
|
});
|
|
810
791
|
}
|
|
792
|
+
_getSubscriptionInfo(user) {
|
|
793
|
+
var _a, _b, _c;
|
|
794
|
+
const hasActiveSubscription = this._forceAllowSubscriptionFeatures ||
|
|
795
|
+
isActiveSubscription(user.subscriptionStatus);
|
|
796
|
+
let tier = null;
|
|
797
|
+
let sub = null;
|
|
798
|
+
if (hasActiveSubscription) {
|
|
799
|
+
if (user.subscriptionId) {
|
|
800
|
+
sub = (_a = this._subscriptionConfig) === null || _a === void 0 ? void 0 : _a.subscriptions.find((s) => s.id === user.subscriptionId);
|
|
801
|
+
}
|
|
802
|
+
if (!sub) {
|
|
803
|
+
sub = (_b = this._subscriptionConfig) === null || _b === void 0 ? void 0 : _b.subscriptions.find((s) => s.defaultSubscription);
|
|
804
|
+
if (sub) {
|
|
805
|
+
console.log('[AuthController] [getUserInfo] Using default subscription for user.');
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
if (!sub) {
|
|
809
|
+
sub = (_c = this._subscriptionConfig) === null || _c === void 0 ? void 0 : _c.subscriptions[0];
|
|
810
|
+
if (sub) {
|
|
811
|
+
console.log('[AuthController] [getUserInfo] Using first subscription for user.');
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
tier = 'beta';
|
|
815
|
+
if (sub && sub.tier) {
|
|
816
|
+
tier = sub.tier;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return {
|
|
820
|
+
hasActiveSubscription,
|
|
821
|
+
subscriptionId: sub === null || sub === void 0 ? void 0 : sub.id,
|
|
822
|
+
subscriptionTier: tier,
|
|
823
|
+
};
|
|
824
|
+
}
|
|
811
825
|
/**
|
|
812
826
|
* Attempts to update a user's metadata.
|
|
813
827
|
* @param request The request for the operation.
|