@casual-simulation/aux-records 3.3.6 → 3.3.7-alpha.9747723960
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/AIController.d.ts +126 -0
- package/AIController.js +177 -7
- package/AIController.js.map +1 -1
- package/AISloydInterface.d.ts +154 -0
- package/AISloydInterface.js +2 -0
- package/AISloydInterface.js.map +1 -0
- package/AuthController.js +165 -0
- package/AuthController.js.map +1 -1
- package/BlockadeLabsGenerateSkyboxInterface.js +28 -0
- package/BlockadeLabsGenerateSkyboxInterface.js.map +1 -1
- package/DataRecordsController.js +39 -0
- package/DataRecordsController.js.map +1 -1
- package/EventRecordsController.js +33 -0
- package/EventRecordsController.js.map +1 -1
- package/FileRecordsController.js +54 -0
- package/FileRecordsController.js.map +1 -1
- package/GoogleAIChatInterface.js +28 -0
- package/GoogleAIChatInterface.js.map +1 -1
- package/LivekitController.js +15 -0
- package/LivekitController.js.map +1 -1
- package/LoomController.js +15 -0
- package/LoomController.js.map +1 -1
- package/MemoryStore.d.ts +6 -1
- package/MemoryStore.js +41 -0
- package/MemoryStore.js.map +1 -1
- package/MetricsStore.d.ts +65 -0
- package/ModerationController.js +15 -0
- package/ModerationController.js.map +1 -1
- package/OpenAIChatInterface.js +25 -0
- package/OpenAIChatInterface.js.map +1 -1
- package/OpenAIImageInterface.js +19 -0
- package/OpenAIImageInterface.js.map +1 -1
- package/PolicyController.d.ts +26 -1
- package/PolicyController.js +126 -0
- package/PolicyController.js.map +1 -1
- package/PrivoClient.js +40 -0
- package/PrivoClient.js.map +1 -1
- package/RateLimitController.js +15 -0
- package/RateLimitController.js.map +1 -1
- package/RecordsController.js +114 -0
- package/RecordsController.js.map +1 -1
- package/RecordsServer.d.ts +49 -10
- package/RecordsServer.js +152 -4
- package/RecordsServer.js.map +1 -1
- package/SloydInterface.d.ts +16 -0
- package/SloydInterface.js +109 -0
- package/SloydInterface.js.map +1 -0
- package/StabilityAIImageInterface.js +11 -0
- package/StabilityAIImageInterface.js.map +1 -1
- package/SubscriptionConfiguration.d.ts +304 -0
- package/SubscriptionConfiguration.js +33 -0
- package/SubscriptionConfiguration.js.map +1 -1
- package/SubscriptionController.js +35 -0
- package/SubscriptionController.js.map +1 -1
- package/package.json +7 -4
- package/tracing/TracingDecorators.d.ts +18 -0
- package/tracing/TracingDecorators.js +138 -0
- package/tracing/TracingDecorators.js.map +1 -0
- package/websockets/WebsocketController.js +83 -0
- package/websockets/WebsocketController.js.map +1 -1
package/RecordsServer.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
1
7
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
8
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
9
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -42,6 +48,9 @@ import { WebsocketEventTypes, websocketEventSchema, websocketRequestMessageSchem
|
|
|
42
48
|
import { DEFAULT_BRANCH_NAME } from '@casual-simulation/aux-common';
|
|
43
49
|
import { getStatusCode, } from '@casual-simulation/aux-common';
|
|
44
50
|
import { COM_ID_CONFIG_SCHEMA, COM_ID_PLAYER_CONFIG } from './ComIdConfig';
|
|
51
|
+
import { SpanKind, trace } from '@opentelemetry/api';
|
|
52
|
+
import { traceHttpResponse, traced } from './tracing/TracingDecorators';
|
|
53
|
+
import { SEMATTRS_ENDUSER_ID, SEMATTRS_HTTP_CLIENT_IP, SEMATTRS_HTTP_HOST, SEMATTRS_HTTP_METHOD, SEMATTRS_HTTP_TARGET, SEMATTRS_HTTP_URL, SEMATTRS_HTTP_USER_AGENT, } from '@opentelemetry/semantic-conventions';
|
|
45
54
|
export const NOT_LOGGED_IN_RESULT = {
|
|
46
55
|
success: false,
|
|
47
56
|
errorCode: 'not_logged_in',
|
|
@@ -362,6 +371,7 @@ export class RecordsServer {
|
|
|
362
371
|
this._websocketController = websocketController;
|
|
363
372
|
this._moderationController = moderationController;
|
|
364
373
|
this._loomController = loomController;
|
|
374
|
+
this._tracer = trace.getTracer('RecordsServer', typeof GIT_TAG === 'undefined' ? undefined : GIT_TAG);
|
|
365
375
|
this._procedures = this._createProcedures();
|
|
366
376
|
this._setupRoutes();
|
|
367
377
|
}
|
|
@@ -1583,6 +1593,48 @@ export class RecordsServer {
|
|
|
1583
1593
|
});
|
|
1584
1594
|
return result;
|
|
1585
1595
|
})),
|
|
1596
|
+
createSloydModel: procedure()
|
|
1597
|
+
.origins('api')
|
|
1598
|
+
.http('POST', '/api/v2/ai/sloyd/model')
|
|
1599
|
+
.inputs(z.object({
|
|
1600
|
+
recordName: RECORD_NAME_VALIDATION.optional(),
|
|
1601
|
+
outputMimeType: z
|
|
1602
|
+
.enum(['model/gltf+json', 'model/gltf-binary'])
|
|
1603
|
+
.default('model/gltf+json'),
|
|
1604
|
+
prompt: z.string().min(1),
|
|
1605
|
+
levelOfDetail: z.number().min(0.01).max(1).optional(),
|
|
1606
|
+
baseModelId: z.string().optional(),
|
|
1607
|
+
thumbnail: z
|
|
1608
|
+
.object({
|
|
1609
|
+
type: z.literal('image/png'),
|
|
1610
|
+
width: z.number().int().min(1),
|
|
1611
|
+
height: z.number().int().min(1),
|
|
1612
|
+
})
|
|
1613
|
+
.optional(),
|
|
1614
|
+
}))
|
|
1615
|
+
.handler(({ recordName, outputMimeType, prompt, levelOfDetail, baseModelId, thumbnail, }, context) => __awaiter(this, void 0, void 0, function* () {
|
|
1616
|
+
if (!this._aiController) {
|
|
1617
|
+
return AI_NOT_SUPPORTED_RESULT;
|
|
1618
|
+
}
|
|
1619
|
+
const sessionKeyValidation = yield this._validateSessionKey(context.sessionKey);
|
|
1620
|
+
if (sessionKeyValidation.success === false) {
|
|
1621
|
+
if (sessionKeyValidation.errorCode ===
|
|
1622
|
+
'no_session_key') {
|
|
1623
|
+
return NOT_LOGGED_IN_RESULT;
|
|
1624
|
+
}
|
|
1625
|
+
return sessionKeyValidation;
|
|
1626
|
+
}
|
|
1627
|
+
const result = yield this._aiController.sloydGenerateModel({
|
|
1628
|
+
userId: sessionKeyValidation.userId,
|
|
1629
|
+
recordName: recordName !== null && recordName !== void 0 ? recordName : sessionKeyValidation.userId,
|
|
1630
|
+
outputMimeType,
|
|
1631
|
+
prompt,
|
|
1632
|
+
levelOfDetail,
|
|
1633
|
+
baseModelId,
|
|
1634
|
+
thumbnail: thumbnail,
|
|
1635
|
+
});
|
|
1636
|
+
return result;
|
|
1637
|
+
})),
|
|
1586
1638
|
getLoomAccessToken: procedure()
|
|
1587
1639
|
.origins('api')
|
|
1588
1640
|
.http('GET', '/api/v2/loom/token')
|
|
@@ -2169,7 +2221,7 @@ export class RecordsServer {
|
|
|
2169
2221
|
if (procs.hasOwnProperty(procedureName)) {
|
|
2170
2222
|
const procedure = procs[procedureName];
|
|
2171
2223
|
if (procedure.http) {
|
|
2172
|
-
this._addProcedureRoute(procedure);
|
|
2224
|
+
this._addProcedureRoute(procedure, procedureName);
|
|
2173
2225
|
}
|
|
2174
2226
|
}
|
|
2175
2227
|
}
|
|
@@ -2190,6 +2242,11 @@ export class RecordsServer {
|
|
|
2190
2242
|
errorMessage: `Unable to find procedure: ${procedure}`,
|
|
2191
2243
|
});
|
|
2192
2244
|
}
|
|
2245
|
+
const span = trace.getActiveSpan();
|
|
2246
|
+
if (span) {
|
|
2247
|
+
span.updateName(`http:${procedure}`);
|
|
2248
|
+
span.setAttribute('request.procedure', procedure);
|
|
2249
|
+
}
|
|
2193
2250
|
const origins = proc.allowedOrigins === 'account'
|
|
2194
2251
|
? this._allowedAccountOrigins
|
|
2195
2252
|
: proc.allowedOrigins === 'api'
|
|
@@ -2221,6 +2278,7 @@ export class RecordsServer {
|
|
|
2221
2278
|
this.addRoute({
|
|
2222
2279
|
method: 'POST',
|
|
2223
2280
|
path: '/api/stripeWebhook',
|
|
2281
|
+
name: 'stripeWebhook',
|
|
2224
2282
|
allowedOrigins: true,
|
|
2225
2283
|
handler: (request) => this._stripeWebhook(request),
|
|
2226
2284
|
});
|
|
@@ -2236,7 +2294,7 @@ export class RecordsServer {
|
|
|
2236
2294
|
}
|
|
2237
2295
|
this._procedures[name] = procedure;
|
|
2238
2296
|
if (procedure.http) {
|
|
2239
|
-
this._addProcedureRoute(procedure);
|
|
2297
|
+
this._addProcedureRoute(procedure, name);
|
|
2240
2298
|
}
|
|
2241
2299
|
}
|
|
2242
2300
|
/**
|
|
@@ -2252,7 +2310,7 @@ export class RecordsServer {
|
|
|
2252
2310
|
* Adds the given procedural route to the server.
|
|
2253
2311
|
* @param route The route that should be added.
|
|
2254
2312
|
*/
|
|
2255
|
-
_addProcedureRoute(procedure) {
|
|
2313
|
+
_addProcedureRoute(procedure, name) {
|
|
2256
2314
|
if (!procedure.http) {
|
|
2257
2315
|
throw new Error('Procedure must have an http route defined.');
|
|
2258
2316
|
}
|
|
@@ -2261,6 +2319,7 @@ export class RecordsServer {
|
|
|
2261
2319
|
method: route.method,
|
|
2262
2320
|
path: route.path,
|
|
2263
2321
|
schema: procedure.schema,
|
|
2322
|
+
name: name,
|
|
2264
2323
|
handler: (request, data) => __awaiter(this, void 0, void 0, function* () {
|
|
2265
2324
|
var _a;
|
|
2266
2325
|
const context = {
|
|
@@ -2301,6 +2360,19 @@ export class RecordsServer {
|
|
|
2301
2360
|
handleHttpRequest(request) {
|
|
2302
2361
|
var _a;
|
|
2303
2362
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2363
|
+
const span = trace.getActiveSpan();
|
|
2364
|
+
if (span) {
|
|
2365
|
+
const url = new URL(request.path, `http://${request.headers.host}`);
|
|
2366
|
+
span.setAttributes({
|
|
2367
|
+
[SEMATTRS_HTTP_METHOD]: request.method,
|
|
2368
|
+
[SEMATTRS_HTTP_URL]: url.href,
|
|
2369
|
+
[SEMATTRS_HTTP_TARGET]: request.path,
|
|
2370
|
+
[SEMATTRS_HTTP_CLIENT_IP]: request.ipAddress,
|
|
2371
|
+
[SEMATTRS_HTTP_HOST]: request.headers.host,
|
|
2372
|
+
[SEMATTRS_HTTP_USER_AGENT]: request.headers['user-agent'],
|
|
2373
|
+
['http.origin']: request.headers.origin,
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2304
2376
|
let skipRateLimitCheck = false;
|
|
2305
2377
|
if (!this._rateLimit) {
|
|
2306
2378
|
skipRateLimitCheck = true;
|
|
@@ -2309,6 +2381,9 @@ export class RecordsServer {
|
|
|
2309
2381
|
request.path === '/api/stripeWebhook') {
|
|
2310
2382
|
skipRateLimitCheck = true;
|
|
2311
2383
|
}
|
|
2384
|
+
if (skipRateLimitCheck && span) {
|
|
2385
|
+
span.setAttribute('request.rateLimitCheck', 'skipped');
|
|
2386
|
+
}
|
|
2312
2387
|
if (!skipRateLimitCheck) {
|
|
2313
2388
|
const response = yield this._rateLimit.checkRateLimit({
|
|
2314
2389
|
ipAddress: request.ipAddress,
|
|
@@ -2355,6 +2430,9 @@ export class RecordsServer {
|
|
|
2355
2430
|
}
|
|
2356
2431
|
const route = this._routes.get(`${request.method}:${request.path}`);
|
|
2357
2432
|
if (route) {
|
|
2433
|
+
if (span && route.name) {
|
|
2434
|
+
span.updateName(`http:${route.name}`);
|
|
2435
|
+
}
|
|
2358
2436
|
const origins = route.allowedOrigins === 'account'
|
|
2359
2437
|
? this._allowedAccountOrigins
|
|
2360
2438
|
: route.allowedOrigins === 'api'
|
|
@@ -2423,6 +2501,15 @@ export class RecordsServer {
|
|
|
2423
2501
|
if (!this._websocketController) {
|
|
2424
2502
|
return;
|
|
2425
2503
|
}
|
|
2504
|
+
const span = trace.getActiveSpan();
|
|
2505
|
+
if (span) {
|
|
2506
|
+
span.setAttributes({
|
|
2507
|
+
[SEMATTRS_HTTP_CLIENT_IP]: request.ipAddress,
|
|
2508
|
+
['http.origin']: request.origin,
|
|
2509
|
+
['websocket.type']: request.type,
|
|
2510
|
+
['request.connectionId']: request.connectionId,
|
|
2511
|
+
});
|
|
2512
|
+
}
|
|
2426
2513
|
let skipRateLimitCheck = false;
|
|
2427
2514
|
if (!this._websocketRateLimit) {
|
|
2428
2515
|
skipRateLimitCheck = true;
|
|
@@ -2444,6 +2531,9 @@ export class RecordsServer {
|
|
|
2444
2531
|
}
|
|
2445
2532
|
}
|
|
2446
2533
|
}
|
|
2534
|
+
if (skipRateLimitCheck && span) {
|
|
2535
|
+
span.setAttribute('request.rateLimitCheck', 'skipped');
|
|
2536
|
+
}
|
|
2447
2537
|
if (request.type === 'connect') {
|
|
2448
2538
|
console.log(`[RecordsServer] Connection recieved: `, request.connectionId);
|
|
2449
2539
|
}
|
|
@@ -2496,12 +2586,15 @@ export class RecordsServer {
|
|
|
2496
2586
|
}
|
|
2497
2587
|
_processWebsocketMessage(request, requestId, message) {
|
|
2498
2588
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2589
|
+
const span = trace.getActiveSpan();
|
|
2499
2590
|
const messageResult = websocketRequestMessageSchema.safeParse(message);
|
|
2500
2591
|
if (messageResult.success === false) {
|
|
2592
|
+
span === null || span === void 0 ? void 0 : span.setAttribute('request.messageType', 'invalid');
|
|
2501
2593
|
yield this._sendWebsocketZodError(request.connectionId, requestId, messageResult.error);
|
|
2502
2594
|
return;
|
|
2503
2595
|
}
|
|
2504
2596
|
const data = messageResult.data;
|
|
2597
|
+
span === null || span === void 0 ? void 0 : span.setAttribute('request.messageType', data.type);
|
|
2505
2598
|
if (data.type === 'login') {
|
|
2506
2599
|
yield this._websocketController.login(request.connectionId, requestId, data);
|
|
2507
2600
|
}
|
|
@@ -5124,17 +5217,72 @@ export class RecordsServer {
|
|
|
5124
5217
|
errorMessage: 'A session key was not provided, but it is required for this operation.',
|
|
5125
5218
|
};
|
|
5126
5219
|
}
|
|
5127
|
-
|
|
5220
|
+
const result = yield this._auth.validateSessionKey(sessionKey);
|
|
5221
|
+
if (result.success === true) {
|
|
5222
|
+
const span = trace.getActiveSpan();
|
|
5223
|
+
if (span) {
|
|
5224
|
+
span.setAttributes({
|
|
5225
|
+
[SEMATTRS_ENDUSER_ID]: result.userId,
|
|
5226
|
+
['request.userId']: result.userId,
|
|
5227
|
+
['request.userRole']: result.role,
|
|
5228
|
+
['request.sessionId']: result.sessionId,
|
|
5229
|
+
['request.subscriptionId']: result.subscriptionId,
|
|
5230
|
+
['request.subscriptionTier']: result.subscriptionTier,
|
|
5231
|
+
});
|
|
5232
|
+
}
|
|
5233
|
+
}
|
|
5234
|
+
return result;
|
|
5128
5235
|
});
|
|
5129
5236
|
}
|
|
5130
5237
|
}
|
|
5238
|
+
__decorate([
|
|
5239
|
+
traced('RecordsServer', {
|
|
5240
|
+
kind: SpanKind.SERVER,
|
|
5241
|
+
root: true,
|
|
5242
|
+
}),
|
|
5243
|
+
traceHttpResponse()
|
|
5244
|
+
], RecordsServer.prototype, "handleHttpRequest", null);
|
|
5245
|
+
__decorate([
|
|
5246
|
+
traced('RecordsServer', {
|
|
5247
|
+
kind: SpanKind.SERVER,
|
|
5248
|
+
})
|
|
5249
|
+
], RecordsServer.prototype, "handleWebsocketRequest", null);
|
|
5250
|
+
__decorate([
|
|
5251
|
+
traced('RecordsServer')
|
|
5252
|
+
], RecordsServer.prototype, "_processWebsocketMessage", null);
|
|
5253
|
+
__decorate([
|
|
5254
|
+
traced('RecordsServer')
|
|
5255
|
+
], RecordsServer.prototype, "_processWebsocketDownload", null);
|
|
5256
|
+
__decorate([
|
|
5257
|
+
traced('RecordsServer')
|
|
5258
|
+
], RecordsServer.prototype, "_processWebsocketUploadRequest", null);
|
|
5131
5259
|
export function returnResult(result) {
|
|
5260
|
+
const span = trace.getActiveSpan();
|
|
5261
|
+
if (span) {
|
|
5262
|
+
if (result.success === false) {
|
|
5263
|
+
span.setAttributes({
|
|
5264
|
+
['result.errorCode']: result.errorCode,
|
|
5265
|
+
['result.errorMessage']: result.errorMessage,
|
|
5266
|
+
});
|
|
5267
|
+
if (result.reason) {
|
|
5268
|
+
for (let prop in result.reason) {
|
|
5269
|
+
span.setAttribute(`result.reason.${prop}`, result.reason[prop]);
|
|
5270
|
+
}
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5273
|
+
}
|
|
5132
5274
|
return {
|
|
5133
5275
|
statusCode: getStatusCode(result),
|
|
5134
5276
|
body: JSON.stringify(result),
|
|
5135
5277
|
};
|
|
5136
5278
|
}
|
|
5137
5279
|
export function returnProcedureOutputStream(result) {
|
|
5280
|
+
const span = trace.getActiveSpan();
|
|
5281
|
+
if (span) {
|
|
5282
|
+
span.setAttributes({
|
|
5283
|
+
['result.stream']: true,
|
|
5284
|
+
});
|
|
5285
|
+
}
|
|
5138
5286
|
function generateBody() {
|
|
5139
5287
|
return __asyncGenerator(this, arguments, function* generateBody_1() {
|
|
5140
5288
|
while (true) {
|