@stndrds/schema 0.1.0-alpha.49 → 0.1.0-alpha.51
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/dist/{chunk-FDWX5X6L.mjs → chunk-EK56IQJ7.mjs} +296 -1
- package/dist/{chunk-LPCQM5VG.js → chunk-IEHBD7WL.js} +440 -145
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/index.mjs +1 -1
- package/dist/{runtime-BbM_jyVU.d.mts → runtime-DRiI1SCJ.d.mts} +440 -7
- package/dist/{runtime-BbM_jyVU.d.ts → runtime-DRiI1SCJ.d.ts} +440 -7
- package/dist/runtime.d.mts +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +2 -2
- package/dist/runtime.mjs +1 -1
- package/package.json +2 -2
|
@@ -3152,6 +3152,10 @@ function createMockFilesRepository(stores) {
|
|
|
3152
3152
|
if (file2?.deletedAt) return Promise.resolve(null);
|
|
3153
3153
|
return Promise.resolve(file2 ?? null);
|
|
3154
3154
|
},
|
|
3155
|
+
findByIds(ids) {
|
|
3156
|
+
const files = ids.map((id) => stores.files.get(id)).filter((f) => f != null && !f.deletedAt);
|
|
3157
|
+
return Promise.resolve(files);
|
|
3158
|
+
},
|
|
3155
3159
|
create(data) {
|
|
3156
3160
|
const tenantId = getTenantId();
|
|
3157
3161
|
const file2 = {
|
|
@@ -4123,6 +4127,284 @@ function createMockWorkflowParticipationsRepository(stores) {
|
|
|
4123
4127
|
}
|
|
4124
4128
|
};
|
|
4125
4129
|
}
|
|
4130
|
+
function requireUserId() {
|
|
4131
|
+
const userId = getUserId();
|
|
4132
|
+
if (!userId) {
|
|
4133
|
+
throw new Error("User context required for AI operations");
|
|
4134
|
+
}
|
|
4135
|
+
return userId;
|
|
4136
|
+
}
|
|
4137
|
+
function createMockAIConversationsRepository(stores) {
|
|
4138
|
+
return {
|
|
4139
|
+
findById(id) {
|
|
4140
|
+
const conversation = stores.aiConversations.get(id);
|
|
4141
|
+
if (!conversation || conversation.deletedAt) return Promise.resolve(null);
|
|
4142
|
+
const tenantId = getTenantId();
|
|
4143
|
+
if (conversation.tenantId !== tenantId) return Promise.resolve(null);
|
|
4144
|
+
return Promise.resolve(conversation);
|
|
4145
|
+
},
|
|
4146
|
+
list(options) {
|
|
4147
|
+
const tenantId = getTenantId();
|
|
4148
|
+
const userId = requireUserId();
|
|
4149
|
+
let results = Array.from(stores.aiConversations.values()).filter((c) => {
|
|
4150
|
+
if (c.tenantId !== tenantId || c.userId !== userId) return false;
|
|
4151
|
+
if (!options?.includeDeleted && c.deletedAt) return false;
|
|
4152
|
+
return true;
|
|
4153
|
+
});
|
|
4154
|
+
results.sort((a, b) => b.updatedAt.getTime() - a.updatedAt.getTime());
|
|
4155
|
+
const total = results.length;
|
|
4156
|
+
if (options?.limit) {
|
|
4157
|
+
results = results.slice(options.offset ?? 0, (options.offset ?? 0) + options.limit);
|
|
4158
|
+
}
|
|
4159
|
+
return Promise.resolve({ conversations: results, total });
|
|
4160
|
+
},
|
|
4161
|
+
create(data) {
|
|
4162
|
+
const tenantId = getTenantId();
|
|
4163
|
+
const userId = requireUserId();
|
|
4164
|
+
const now = /* @__PURE__ */ new Date();
|
|
4165
|
+
const conversation = {
|
|
4166
|
+
id: generateId(),
|
|
4167
|
+
tenantId,
|
|
4168
|
+
userId,
|
|
4169
|
+
title: data.title ?? null,
|
|
4170
|
+
messageCount: 0,
|
|
4171
|
+
totalTokens: 0,
|
|
4172
|
+
totalCost: 0,
|
|
4173
|
+
createdAt: now,
|
|
4174
|
+
updatedAt: now,
|
|
4175
|
+
deletedAt: null
|
|
4176
|
+
};
|
|
4177
|
+
stores.aiConversations.set(conversation.id, conversation);
|
|
4178
|
+
return Promise.resolve(conversation);
|
|
4179
|
+
},
|
|
4180
|
+
updateTitle(id, title) {
|
|
4181
|
+
const conversation = stores.aiConversations.get(id);
|
|
4182
|
+
if (!conversation || conversation.deletedAt) return Promise.resolve(null);
|
|
4183
|
+
const tenantId = getTenantId();
|
|
4184
|
+
if (conversation.tenantId !== tenantId) return Promise.resolve(null);
|
|
4185
|
+
conversation.title = title;
|
|
4186
|
+
conversation.updatedAt = /* @__PURE__ */ new Date();
|
|
4187
|
+
stores.aiConversations.set(id, conversation);
|
|
4188
|
+
return Promise.resolve(conversation);
|
|
4189
|
+
},
|
|
4190
|
+
delete(id) {
|
|
4191
|
+
const conversation = stores.aiConversations.get(id);
|
|
4192
|
+
if (!conversation) return Promise.resolve(false);
|
|
4193
|
+
const tenantId = getTenantId();
|
|
4194
|
+
if (conversation.tenantId !== tenantId) return Promise.resolve(false);
|
|
4195
|
+
conversation.deletedAt = /* @__PURE__ */ new Date();
|
|
4196
|
+
stores.aiConversations.set(id, conversation);
|
|
4197
|
+
return Promise.resolve(true);
|
|
4198
|
+
},
|
|
4199
|
+
addMessage(input) {
|
|
4200
|
+
const now = /* @__PURE__ */ new Date();
|
|
4201
|
+
const message = {
|
|
4202
|
+
id: generateId(),
|
|
4203
|
+
conversationId: input.conversationId,
|
|
4204
|
+
role: input.role,
|
|
4205
|
+
content: input.content,
|
|
4206
|
+
thinkingLevel: input.thinkingLevel ?? null,
|
|
4207
|
+
thinkingSummary: input.thinkingSummary ?? null,
|
|
4208
|
+
toolCalls: input.toolCalls ?? null,
|
|
4209
|
+
inputTokens: input.inputTokens ?? null,
|
|
4210
|
+
outputTokens: input.outputTokens ?? null,
|
|
4211
|
+
cost: input.cost ?? null,
|
|
4212
|
+
provider: input.provider ?? null,
|
|
4213
|
+
model: input.model ?? null,
|
|
4214
|
+
attachmentIds: input.attachmentIds ?? null,
|
|
4215
|
+
createdAt: now
|
|
4216
|
+
};
|
|
4217
|
+
stores.aiMessages.set(message.id, message);
|
|
4218
|
+
const conversation = stores.aiConversations.get(input.conversationId);
|
|
4219
|
+
if (conversation) {
|
|
4220
|
+
conversation.messageCount++;
|
|
4221
|
+
conversation.totalTokens += (input.inputTokens ?? 0) + (input.outputTokens ?? 0);
|
|
4222
|
+
conversation.totalCost += input.cost ?? 0;
|
|
4223
|
+
conversation.updatedAt = now;
|
|
4224
|
+
stores.aiConversations.set(input.conversationId, conversation);
|
|
4225
|
+
}
|
|
4226
|
+
return Promise.resolve(message);
|
|
4227
|
+
},
|
|
4228
|
+
listMessages(conversationId, options) {
|
|
4229
|
+
let results = Array.from(stores.aiMessages.values()).filter((m) => m.conversationId === conversationId).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
4230
|
+
const total = results.length;
|
|
4231
|
+
if (options?.limit) {
|
|
4232
|
+
results = results.slice(options.offset ?? 0, (options.offset ?? 0) + options.limit);
|
|
4233
|
+
}
|
|
4234
|
+
return Promise.resolve({ messages: results, total });
|
|
4235
|
+
},
|
|
4236
|
+
getRecentMessages(conversationId, count = 20) {
|
|
4237
|
+
const results = Array.from(stores.aiMessages.values()).filter((m) => m.conversationId === conversationId).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()).slice(-count);
|
|
4238
|
+
return Promise.resolve(results);
|
|
4239
|
+
}
|
|
4240
|
+
};
|
|
4241
|
+
}
|
|
4242
|
+
function createMockAIUserMemoryRepository(stores) {
|
|
4243
|
+
const getKey = () => {
|
|
4244
|
+
const tenantId = getTenantId();
|
|
4245
|
+
const userId = requireUserId();
|
|
4246
|
+
return `${tenantId}:${userId}`;
|
|
4247
|
+
};
|
|
4248
|
+
return {
|
|
4249
|
+
get() {
|
|
4250
|
+
const key = getKey();
|
|
4251
|
+
return Promise.resolve(stores.aiUserMemory.get(key) ?? null);
|
|
4252
|
+
},
|
|
4253
|
+
upsert(data) {
|
|
4254
|
+
const key = getKey();
|
|
4255
|
+
const tenantId = getTenantId();
|
|
4256
|
+
const userId = requireUserId();
|
|
4257
|
+
const now = /* @__PURE__ */ new Date();
|
|
4258
|
+
const existing = stores.aiUserMemory.get(key);
|
|
4259
|
+
const memory = {
|
|
4260
|
+
id: existing?.id ?? generateId(),
|
|
4261
|
+
tenantId,
|
|
4262
|
+
userId,
|
|
4263
|
+
preferences: data.preferences ?? existing?.preferences ?? {},
|
|
4264
|
+
facts: data.facts ?? existing?.facts ?? [],
|
|
4265
|
+
createdAt: existing?.createdAt ?? now,
|
|
4266
|
+
updatedAt: now
|
|
4267
|
+
};
|
|
4268
|
+
stores.aiUserMemory.set(key, memory);
|
|
4269
|
+
return Promise.resolve(memory);
|
|
4270
|
+
},
|
|
4271
|
+
addFact(fact) {
|
|
4272
|
+
const key = getKey();
|
|
4273
|
+
const tenantId = getTenantId();
|
|
4274
|
+
const userId = requireUserId();
|
|
4275
|
+
const now = /* @__PURE__ */ new Date();
|
|
4276
|
+
const existing = stores.aiUserMemory.get(key);
|
|
4277
|
+
const memory = {
|
|
4278
|
+
id: existing?.id ?? generateId(),
|
|
4279
|
+
tenantId,
|
|
4280
|
+
userId,
|
|
4281
|
+
preferences: existing?.preferences ?? {},
|
|
4282
|
+
facts: [...existing?.facts ?? [], fact],
|
|
4283
|
+
createdAt: existing?.createdAt ?? now,
|
|
4284
|
+
updatedAt: now
|
|
4285
|
+
};
|
|
4286
|
+
stores.aiUserMemory.set(key, memory);
|
|
4287
|
+
return Promise.resolve(memory);
|
|
4288
|
+
},
|
|
4289
|
+
removeFact(fact) {
|
|
4290
|
+
const key = getKey();
|
|
4291
|
+
const tenantId = getTenantId();
|
|
4292
|
+
const userId = requireUserId();
|
|
4293
|
+
const now = /* @__PURE__ */ new Date();
|
|
4294
|
+
const existing = stores.aiUserMemory.get(key);
|
|
4295
|
+
const memory = {
|
|
4296
|
+
id: existing?.id ?? generateId(),
|
|
4297
|
+
tenantId,
|
|
4298
|
+
userId,
|
|
4299
|
+
preferences: existing?.preferences ?? {},
|
|
4300
|
+
facts: (existing?.facts ?? []).filter((f) => f !== fact),
|
|
4301
|
+
createdAt: existing?.createdAt ?? now,
|
|
4302
|
+
updatedAt: now
|
|
4303
|
+
};
|
|
4304
|
+
stores.aiUserMemory.set(key, memory);
|
|
4305
|
+
return Promise.resolve(memory);
|
|
4306
|
+
},
|
|
4307
|
+
setPreference(prefKey, value) {
|
|
4308
|
+
const memoryKey = getKey();
|
|
4309
|
+
const tenantId = getTenantId();
|
|
4310
|
+
const userId = requireUserId();
|
|
4311
|
+
const now = /* @__PURE__ */ new Date();
|
|
4312
|
+
const existing = stores.aiUserMemory.get(memoryKey);
|
|
4313
|
+
const memory = {
|
|
4314
|
+
id: existing?.id ?? generateId(),
|
|
4315
|
+
tenantId,
|
|
4316
|
+
userId,
|
|
4317
|
+
preferences: { ...existing?.preferences ?? {}, [prefKey]: value },
|
|
4318
|
+
facts: existing?.facts ?? [],
|
|
4319
|
+
createdAt: existing?.createdAt ?? now,
|
|
4320
|
+
updatedAt: now
|
|
4321
|
+
};
|
|
4322
|
+
stores.aiUserMemory.set(memoryKey, memory);
|
|
4323
|
+
return Promise.resolve(memory);
|
|
4324
|
+
},
|
|
4325
|
+
clear() {
|
|
4326
|
+
const key = getKey();
|
|
4327
|
+
stores.aiUserMemory.delete(key);
|
|
4328
|
+
return Promise.resolve();
|
|
4329
|
+
}
|
|
4330
|
+
};
|
|
4331
|
+
}
|
|
4332
|
+
function createMockAIUsageMetricsRepository(stores) {
|
|
4333
|
+
const getDateKey = (date2) => {
|
|
4334
|
+
const tenantId = getTenantId();
|
|
4335
|
+
const dateStr = date2.toISOString().split("T")[0];
|
|
4336
|
+
return `${tenantId}:${dateStr}`;
|
|
4337
|
+
};
|
|
4338
|
+
return {
|
|
4339
|
+
recordUsage(data) {
|
|
4340
|
+
const tenantId = getTenantId();
|
|
4341
|
+
const now = /* @__PURE__ */ new Date();
|
|
4342
|
+
const key = getDateKey(now);
|
|
4343
|
+
const existing = stores.aiUsageMetrics.get(key);
|
|
4344
|
+
const providerBreakdown = existing?.providerBreakdown ?? {};
|
|
4345
|
+
if (!providerBreakdown[data.provider]) {
|
|
4346
|
+
providerBreakdown[data.provider] = { requests: 0, tokens: 0, cost: 0 };
|
|
4347
|
+
}
|
|
4348
|
+
providerBreakdown[data.provider].requests++;
|
|
4349
|
+
providerBreakdown[data.provider].tokens += data.tokens;
|
|
4350
|
+
providerBreakdown[data.provider].cost += data.cost;
|
|
4351
|
+
const toolUsage = existing?.toolUsage ?? {};
|
|
4352
|
+
if (data.toolName) {
|
|
4353
|
+
toolUsage[data.toolName] = (toolUsage[data.toolName] ?? 0) + 1;
|
|
4354
|
+
}
|
|
4355
|
+
const metrics = {
|
|
4356
|
+
id: existing?.id ?? generateId(),
|
|
4357
|
+
tenantId,
|
|
4358
|
+
date: new Date(now.toISOString().split("T")[0] ?? now.toISOString()),
|
|
4359
|
+
requestCount: (existing?.requestCount ?? 0) + 1,
|
|
4360
|
+
totalTokens: (existing?.totalTokens ?? 0) + data.tokens,
|
|
4361
|
+
totalCost: (existing?.totalCost ?? 0) + data.cost,
|
|
4362
|
+
providerBreakdown,
|
|
4363
|
+
toolUsage
|
|
4364
|
+
};
|
|
4365
|
+
stores.aiUsageMetrics.set(key, metrics);
|
|
4366
|
+
return Promise.resolve();
|
|
4367
|
+
},
|
|
4368
|
+
getByDateRange(startDate, endDate) {
|
|
4369
|
+
const tenantId = getTenantId();
|
|
4370
|
+
const results = Array.from(stores.aiUsageMetrics.values()).filter((m) => {
|
|
4371
|
+
if (m.tenantId !== tenantId) return false;
|
|
4372
|
+
return m.date >= startDate && m.date <= endDate;
|
|
4373
|
+
});
|
|
4374
|
+
results.sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
4375
|
+
return Promise.resolve(results);
|
|
4376
|
+
},
|
|
4377
|
+
getCurrentMonthUsage() {
|
|
4378
|
+
const tenantId = getTenantId();
|
|
4379
|
+
const now = /* @__PURE__ */ new Date();
|
|
4380
|
+
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
|
4381
|
+
const monthMetrics = Array.from(stores.aiUsageMetrics.values()).filter((m) => {
|
|
4382
|
+
if (m.tenantId !== tenantId) return false;
|
|
4383
|
+
return m.date >= startOfMonth;
|
|
4384
|
+
});
|
|
4385
|
+
const aggregated = {
|
|
4386
|
+
requestCount: 0,
|
|
4387
|
+
totalTokens: 0,
|
|
4388
|
+
totalCost: 0,
|
|
4389
|
+
providerBreakdown: {}
|
|
4390
|
+
};
|
|
4391
|
+
for (const m of monthMetrics) {
|
|
4392
|
+
aggregated.requestCount += m.requestCount;
|
|
4393
|
+
aggregated.totalTokens += m.totalTokens;
|
|
4394
|
+
aggregated.totalCost += m.totalCost;
|
|
4395
|
+
for (const [provider, stats] of Object.entries(m.providerBreakdown)) {
|
|
4396
|
+
if (!aggregated.providerBreakdown[provider]) {
|
|
4397
|
+
aggregated.providerBreakdown[provider] = { requests: 0, tokens: 0, cost: 0 };
|
|
4398
|
+
}
|
|
4399
|
+
aggregated.providerBreakdown[provider].requests += stats.requests;
|
|
4400
|
+
aggregated.providerBreakdown[provider].tokens += stats.tokens;
|
|
4401
|
+
aggregated.providerBreakdown[provider].cost += stats.cost;
|
|
4402
|
+
}
|
|
4403
|
+
}
|
|
4404
|
+
return Promise.resolve(aggregated);
|
|
4405
|
+
}
|
|
4406
|
+
};
|
|
4407
|
+
}
|
|
4126
4408
|
function createMockAdapter() {
|
|
4127
4409
|
const stores = {
|
|
4128
4410
|
objects: /* @__PURE__ */ new Map(),
|
|
@@ -4136,7 +4418,12 @@ function createMockAdapter() {
|
|
|
4136
4418
|
userRoles: /* @__PURE__ */ new Map(),
|
|
4137
4419
|
workflows: /* @__PURE__ */ new Map(),
|
|
4138
4420
|
workflowInstances: /* @__PURE__ */ new Map(),
|
|
4139
|
-
workflowParticipations: /* @__PURE__ */ new Map()
|
|
4421
|
+
workflowParticipations: /* @__PURE__ */ new Map(),
|
|
4422
|
+
// AI stores
|
|
4423
|
+
aiConversations: /* @__PURE__ */ new Map(),
|
|
4424
|
+
aiMessages: /* @__PURE__ */ new Map(),
|
|
4425
|
+
aiUserMemory: /* @__PURE__ */ new Map(),
|
|
4426
|
+
aiUsageMetrics: /* @__PURE__ */ new Map()
|
|
4140
4427
|
};
|
|
4141
4428
|
const adapter = {
|
|
4142
4429
|
objects: createMockObjectsRepository(stores),
|
|
@@ -4149,6 +4436,10 @@ function createMockAdapter() {
|
|
|
4149
4436
|
workflows: createMockWorkflowsRepository(stores),
|
|
4150
4437
|
workflowInstances: createMockWorkflowInstancesRepository(stores),
|
|
4151
4438
|
workflowParticipations: createMockWorkflowParticipationsRepository(stores),
|
|
4439
|
+
// AI repositories
|
|
4440
|
+
aiConversations: createMockAIConversationsRepository(stores),
|
|
4441
|
+
aiUserMemory: createMockAIUserMemoryRepository(stores),
|
|
4442
|
+
aiUsageMetrics: createMockAIUsageMetricsRepository(stores),
|
|
4152
4443
|
async transaction(callback) {
|
|
4153
4444
|
return await callback(adapter);
|
|
4154
4445
|
},
|
|
@@ -4168,6 +4459,10 @@ function createMockAdapter() {
|
|
|
4168
4459
|
stores.workflows.clear();
|
|
4169
4460
|
stores.workflowInstances.clear();
|
|
4170
4461
|
stores.workflowParticipations.clear();
|
|
4462
|
+
stores.aiConversations.clear();
|
|
4463
|
+
stores.aiMessages.clear();
|
|
4464
|
+
stores.aiUserMemory.clear();
|
|
4465
|
+
stores.aiUsageMetrics.clear();
|
|
4171
4466
|
}
|
|
4172
4467
|
};
|
|
4173
4468
|
return adapter;
|