@m5kdev/backend 0.8.5 → 0.8.6
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/src/modules/ai/ai.service.d.mts +13 -1
- package/dist/src/modules/ai/ai.service.mjs +61 -18
- package/dist/src/modules/ai/ai.service.mjs.map +1 -1
- package/dist/src/modules/auth/auth.dto.d.mts +2 -2
- package/dist/src/modules/auth/auth.lib.d.mts +1 -1
- package/dist/src/modules/auth/auth.trpc.d.mts +7 -7
- package/dist/src/modules/billing/billing.repository.d.mts +11 -11
- package/dist/src/modules/billing/billing.service.d.mts +7 -7
- package/dist/src/modules/connect/connect.dto.d.mts +2 -2
- package/dist/src/modules/connect/connect.repository.d.mts +1 -1
- package/dist/src/modules/connect/connect.service.d.mts +2 -2
- package/dist/src/modules/file/file.service.mjs +2 -2
- package/dist/src/modules/recurrence/recurrence.service.d.mts +4 -4
- package/dist/src/modules/recurrence/recurrence.trpc.d.mts +3 -3
- package/dist/src/modules/tag/tag.trpc.d.mts +2 -2
- package/dist/src/modules/video/video.service.mjs +1 -1
- package/package.json +3 -3
|
@@ -35,6 +35,8 @@ type AIServiceGenerateTextParams = Omit<GenerateTextParams, "model" | "prompt" |
|
|
|
35
35
|
model: string;
|
|
36
36
|
removeMDash?: boolean;
|
|
37
37
|
ctx?: AIServiceActorContext;
|
|
38
|
+
retryAttempts?: number;
|
|
39
|
+
retryModels?: string[];
|
|
38
40
|
};
|
|
39
41
|
type AIServiceGenerateObjectParams<T extends ZodType> = Omit<GenerateTextParams, "model" | "prompt" | "messages" | "output"> & GenerateTextInput & {
|
|
40
42
|
model: string;
|
|
@@ -42,6 +44,15 @@ type AIServiceGenerateObjectParams<T extends ZodType> = Omit<GenerateTextParams,
|
|
|
42
44
|
repairAttempts?: number;
|
|
43
45
|
repairModel?: string;
|
|
44
46
|
ctx?: AIServiceActorContext;
|
|
47
|
+
retryAttempts?: number;
|
|
48
|
+
retryModels?: string[];
|
|
49
|
+
};
|
|
50
|
+
type AIServiceOptions = {
|
|
51
|
+
retryAttempts?: number;
|
|
52
|
+
retryModels?: string[];
|
|
53
|
+
repairAttempts?: number;
|
|
54
|
+
repairModel?: string;
|
|
55
|
+
removeMDash?: boolean;
|
|
45
56
|
};
|
|
46
57
|
declare class AIService<MastraInstance extends Mastra> extends BaseService<{
|
|
47
58
|
aiUsage?: AiUsageRepository;
|
|
@@ -54,6 +65,7 @@ declare class AIService<MastraInstance extends Mastra> extends BaseService<{
|
|
|
54
65
|
mastra?: MastraInstance;
|
|
55
66
|
openrouter?: OpenRouterProvider;
|
|
56
67
|
replicate?: Replicate;
|
|
68
|
+
options?: AIServiceOptions;
|
|
57
69
|
constructor(repositories: {
|
|
58
70
|
aiUsage?: AiUsageRepository;
|
|
59
71
|
}, services: {
|
|
@@ -62,7 +74,7 @@ declare class AIService<MastraInstance extends Mastra> extends BaseService<{
|
|
|
62
74
|
mastra?: MastraInstance;
|
|
63
75
|
openrouter?: OpenRouterProvider;
|
|
64
76
|
replicate?: Replicate;
|
|
65
|
-
});
|
|
77
|
+
}, options?: AIServiceOptions);
|
|
66
78
|
getMastra(): MastraInstance;
|
|
67
79
|
prepareModel(model: string): ReturnType<OpenRouterProvider["chat"]>;
|
|
68
80
|
prepareEmbeddingModel(model: string): ReturnType<OpenRouterProvider["textEmbeddingModel"]>;
|
|
@@ -13,11 +13,13 @@ var AIService = class extends BaseService {
|
|
|
13
13
|
mastra;
|
|
14
14
|
openrouter;
|
|
15
15
|
replicate;
|
|
16
|
-
|
|
16
|
+
options;
|
|
17
|
+
constructor(repositories, services, libs, options) {
|
|
17
18
|
super(repositories, services);
|
|
18
19
|
this.mastra = libs.mastra;
|
|
19
20
|
this.openrouter = libs.openrouter;
|
|
20
21
|
this.replicate = libs.replicate;
|
|
22
|
+
this.options = options;
|
|
21
23
|
}
|
|
22
24
|
getMastra() {
|
|
23
25
|
if (!this.mastra) throw new Error("Mastra is not available");
|
|
@@ -134,8 +136,8 @@ var AIService = class extends BaseService {
|
|
|
134
136
|
}
|
|
135
137
|
async generateText(params) {
|
|
136
138
|
return this.throwableAsync(async () => {
|
|
137
|
-
const { removeMDash = true, model, prompt, messages, ctx, ...rest } = params;
|
|
138
|
-
const
|
|
139
|
+
const { removeMDash = this.options?.removeMDash ?? true, model, prompt, messages, ctx, retryAttempts = this.options?.retryAttempts ?? 0, retryModels = this.options?.retryModels ?? [], ...rest } = params;
|
|
140
|
+
const request = messages ? {
|
|
139
141
|
...rest,
|
|
140
142
|
model: this.prepareModel(model),
|
|
141
143
|
messages
|
|
@@ -143,26 +145,48 @@ var AIService = class extends BaseService {
|
|
|
143
145
|
...rest,
|
|
144
146
|
model: this.prepareModel(model),
|
|
145
147
|
prompt
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
148
|
+
};
|
|
149
|
+
try {
|
|
150
|
+
const result = await generateText(request);
|
|
151
|
+
if (this.repository.aiUsage) {
|
|
152
|
+
const createUsageResult = await this.repository.aiUsage.create({
|
|
153
|
+
userId: ctx?.actor?.userId,
|
|
154
|
+
model,
|
|
155
|
+
provider: "openrouter",
|
|
156
|
+
feature: "generateText",
|
|
157
|
+
traceId: result.providerMetadata?.openrouter?.traceId?.toString(),
|
|
158
|
+
inputTokens: result.usage.inputTokens,
|
|
159
|
+
outputTokens: result.usage.outputTokens,
|
|
160
|
+
totalTokens: result.usage.totalTokens,
|
|
161
|
+
cost: (result?.providerMetadata?.openrouter?.usage)?.cost ?? 0
|
|
162
|
+
});
|
|
163
|
+
if (createUsageResult.isErr()) return err(createUsageResult.error);
|
|
164
|
+
}
|
|
165
|
+
return ok(removeMDash ? result.text.replace(/\u2013|\u2014/g, "-") : result.text);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (retryAttempts <= 0) throw error;
|
|
168
|
+
this.logger.warn(`generateText failed, retrying (${retryAttempts} attempts left)`, {
|
|
150
169
|
model,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
170
|
+
error
|
|
171
|
+
});
|
|
172
|
+
const delay = Math.min(1e3 * 2 ** ((this.options?.retryAttempts ?? 3) - retryAttempts), 1e4);
|
|
173
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
174
|
+
const nextModel = retryModels?.[0] ?? model;
|
|
175
|
+
const nextRetryModels = retryModels ? [...retryModels.slice(1), model] : void 0;
|
|
176
|
+
return this.generateText({
|
|
177
|
+
...rest,
|
|
178
|
+
...messages ? { messages } : { prompt },
|
|
179
|
+
model: nextModel,
|
|
180
|
+
removeMDash,
|
|
181
|
+
ctx,
|
|
182
|
+
retryAttempts: retryAttempts - 1,
|
|
183
|
+
retryModels: nextRetryModels
|
|
158
184
|
});
|
|
159
|
-
if (createUsageResult.isErr()) return err(createUsageResult.error);
|
|
160
185
|
}
|
|
161
|
-
return ok(removeMDash ? result.text.replace(/\u2013|\u2014/g, "-") : result.text);
|
|
162
186
|
});
|
|
163
187
|
}
|
|
164
188
|
async generateObject(params) {
|
|
165
|
-
const { model, schema, prompt, messages, repairAttempts = 0, repairModel, ctx, ...rest } = params;
|
|
189
|
+
const { model, schema, prompt, messages, repairAttempts = this.options?.repairAttempts ?? 0, repairModel = this.options?.repairModel ?? model, ctx, retryAttempts = this.options?.retryAttempts ?? 0, retryModels = this.options?.retryModels ?? [], ...rest } = params;
|
|
166
190
|
const request = messages ? {
|
|
167
191
|
...rest,
|
|
168
192
|
model: this.prepareModel(model),
|
|
@@ -226,7 +250,26 @@ var AIService = class extends BaseService {
|
|
|
226
250
|
}
|
|
227
251
|
return this.error("PARSE_ERROR", "AI: Agent object failed without text", { cause: error });
|
|
228
252
|
}
|
|
229
|
-
return this.error("BAD_REQUEST", "AI:
|
|
253
|
+
if (retryAttempts <= 0) return this.error("BAD_REQUEST", "AI: Provider failed to generate object", { cause: error });
|
|
254
|
+
this.logger.warn(`generateObject failed, retrying (${retryAttempts} attempts left)`, {
|
|
255
|
+
model,
|
|
256
|
+
error
|
|
257
|
+
});
|
|
258
|
+
const delay = Math.min(1e3 * 2 ** ((this.options?.retryAttempts ?? 3) - retryAttempts), 1e4);
|
|
259
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
260
|
+
const nextModel = retryModels?.[0] ?? model;
|
|
261
|
+
const nextRetryModels = retryModels ? [...retryModels.slice(1), model] : void 0;
|
|
262
|
+
return this.generateObject({
|
|
263
|
+
...rest,
|
|
264
|
+
...messages ? { messages } : { prompt },
|
|
265
|
+
model: nextModel,
|
|
266
|
+
schema,
|
|
267
|
+
repairAttempts,
|
|
268
|
+
repairModel,
|
|
269
|
+
ctx,
|
|
270
|
+
retryAttempts: retryAttempts - 1,
|
|
271
|
+
retryModels: nextRetryModels
|
|
272
|
+
});
|
|
230
273
|
}
|
|
231
274
|
}
|
|
232
275
|
async generateReplicate(model, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.service.mjs","names":[],"sources":["../../../../src/modules/ai/ai.service.ts"],"sourcesContent":["import { OPENAI_TEXT_EMBEDDING_3_SMALL } from \"@m5kdev/commons/modules/ai/ai.constants\";\r\nimport { arrayToPseudoXML } from \"@m5kdev/commons/modules/ai/ai.utils\";\r\nimport type { Mastra } from \"@mastra/core\";\r\nimport { RequestContext } from \"@mastra/core/request-context\";\r\nimport type { FullOutput, MastraModelOutput } from \"@mastra/core/stream\";\r\nimport { MDocument } from \"@mastra/rag\";\r\nimport type { OpenRouterProvider } from \"@openrouter/ai-sdk-provider\";\r\nimport {\r\n embed,\r\n embedMany,\r\n generateText,\r\n type ModelMessage,\r\n NoObjectGeneratedError,\r\n Output,\r\n} from \"ai\";\r\nimport { jsonrepair } from \"jsonrepair\";\r\nimport { err, ok } from \"neverthrow\";\r\nimport type Replicate from \"replicate\";\r\nimport type { ZodType, z } from \"zod\";\r\nimport type { RequiredServiceActor } from \"../base/base.actor\";\r\nimport type { ServerResultAsync } from \"../base/base.dto\";\r\nimport { BaseService } from \"../base/base.service\";\r\nimport { repairJsonPrompt } from \"./ai.prompts\";\r\nimport type { AiUsageRepository, AiUsageRow } from \"./ai.repository\";\r\nimport type { IdeogramV3GenerateInput, IdeogramV3GenerateOutput } from \"./ideogram/ideogram.dto\";\r\nimport type { IdeogramService } from \"./ideogram/ideogram.service\";\r\n\r\ntype MastraAgent = ReturnType<Mastra[\"getAgent\"]>;\r\ntype MastraAgentGenerateOptions = Parameters<MastraAgent[\"generate\"]>[1];\r\ntype MessageListInput = { role: \"user\" | \"assistant\" | \"system\"; content: string }[];\r\ntype GenerateTextParams = Parameters<typeof generateText>[0];\r\ntype GenerateTextInput =\r\n | { prompt: string | ModelMessage[]; messages?: never }\r\n | { messages: ModelMessage[]; prompt?: never };\r\ntype AIServiceActorContext = { actor: RequiredServiceActor<\"user\"> };\r\ntype AIServiceGenerateTextParams = Omit<GenerateTextParams, \"model\" | \"prompt\" | \"messages\"> &\r\n GenerateTextInput & {\r\n model: string;\r\n removeMDash?: boolean;\r\n ctx?: AIServiceActorContext;\r\n };\r\ntype AIServiceGenerateObjectParams<T extends ZodType> = Omit<\r\n GenerateTextParams,\r\n \"model\" | \"prompt\" | \"messages\" | \"output\"\r\n> &\r\n GenerateTextInput & {\r\n model: string;\r\n schema: T;\r\n repairAttempts?: number;\r\n repairModel?: string;\r\n ctx?: AIServiceActorContext;\r\n };\r\n\r\nexport class AIService<MastraInstance extends Mastra> extends BaseService<\r\n { aiUsage?: AiUsageRepository },\r\n { ideogram?: IdeogramService }\r\n> {\r\n helpers = {\r\n arrayToPseudoXML,\r\n };\r\n\r\n mastra?: MastraInstance;\r\n openrouter?: OpenRouterProvider;\r\n replicate?: Replicate;\r\n\r\n constructor(\r\n repositories: { aiUsage?: AiUsageRepository },\r\n services: { ideogram?: IdeogramService },\r\n libs: { mastra?: MastraInstance; openrouter?: OpenRouterProvider; replicate?: Replicate }\r\n ) {\r\n super(repositories, services);\r\n this.mastra = libs.mastra;\r\n this.openrouter = libs.openrouter;\r\n this.replicate = libs.replicate;\r\n }\r\n\r\n getMastra(): MastraInstance {\r\n if (!this.mastra) {\r\n throw new Error(\"Mastra is not available\");\r\n }\r\n return this.mastra;\r\n }\r\n\r\n prepareModel(model: string): ReturnType<OpenRouterProvider[\"chat\"]> {\r\n if (!this.openrouter) {\r\n throw new Error(\"OpenRouter is not configured\");\r\n }\r\n return this.openrouter.chat(model, {\r\n usage: {\r\n include: true,\r\n },\r\n });\r\n }\r\n\r\n prepareEmbeddingModel(model: string): ReturnType<OpenRouterProvider[\"textEmbeddingModel\"]> {\r\n if (!this.openrouter) {\r\n throw new Error(\"OpenRouter is not configured\");\r\n }\r\n const openrouter = this.openrouter as OpenRouterProvider & {\r\n embeddingModel?: (modelId: string) => unknown;\r\n };\r\n return (openrouter.embeddingModel?.(model) ??\r\n openrouter.textEmbeddingModel(model)) as ReturnType<OpenRouterProvider[\"textEmbeddingModel\"]>;\r\n }\r\n\r\n async agentUse(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & { prompt?: string; messages?: MessageListInput },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<Awaited<ReturnType<MastraModelOutput<any>[\"getFullOutput\"]>>> {\r\n return this.throwableAsync(async () => {\r\n this.logger.info(\"AGENT USE\");\r\n const { prompt, messages, ...rest } = options;\r\n const payload = messages || prompt;\r\n if (!payload) return this.error(\"BAD_REQUEST\", \"No prompt or messages provided\");\r\n const requestContext = options.requestContext ?? new RequestContext();\r\n\r\n if (ctx?.actor) {\r\n requestContext.set(\"userId\", ctx.actor.userId);\r\n }\r\n if (ctx?.model) {\r\n requestContext.set(\"model\", ctx.model);\r\n }\r\n const mAgent = this.getMastra().getAgent(agent);\r\n\r\n const result = await mAgent.generate(payload as any, {\r\n ...rest,\r\n requestContext: rest.requestContext ?? requestContext,\r\n });\r\n this.logger.info(\"AGENT USE DONE\");\r\n if (this.repository.aiUsage) {\r\n const createUsageResult = await this.repository.aiUsage.create({\r\n userId: ctx?.actor?.userId,\r\n model: ctx?.model ?? \"unknown\",\r\n provider: \"openrouter\",\r\n feature: agent,\r\n traceId: result.traceId,\r\n inputTokens: result.usage.inputTokens,\r\n outputTokens: result.usage.outputTokens,\r\n totalTokens: result.usage.totalTokens,\r\n cost: (result?.providerMetadata?.openrouter?.usage as any)?.cost ?? 0,\r\n });\r\n if (createUsageResult.isErr()) return err(createUsageResult.error);\r\n }\r\n this.logger.info(\"AGENT USE CREATED USAGE\");\r\n return ok(result);\r\n });\r\n }\r\n\r\n async agentText(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & { prompt?: string; messages?: MessageListInput },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<string> {\r\n const result = await this.agentUse(agent, options, ctx);\r\n if (result.isErr())\r\n return this.error(\"SERVICE_UNAVAILABLE\", \"AI: Agent text failed\", { cause: result.error });\r\n return ok(result.value.text);\r\n }\r\n\r\n async agentTextResult(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & { prompt?: string; messages?: MessageListInput },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<FullOutput<any>> {\r\n const result = await this.agentUse(agent, options, ctx);\r\n if (result.isErr()) return err(result.error);\r\n return ok(result.value);\r\n }\r\n\r\n async agentObject<T extends ZodType<any>>(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & {\r\n schema: T;\r\n prompt?: string;\r\n messages?: MessageListInput;\r\n },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<z.infer<T>> {\r\n const { schema, ...rest } = options;\r\n const result = await this.agentUse(agent, { ...rest, structuredOutput: { schema } }, ctx);\r\n if (result.isErr())\r\n return this.error(\"SERVICE_UNAVAILABLE\", \"AI: Agent object failed\", { cause: result.error });\r\n return ok(result.value.object as z.infer<T>);\r\n }\r\n\r\n async agentObjectResult<T extends ZodType<any>>(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & {\r\n schema: T;\r\n prompt?: string;\r\n messages?: MessageListInput;\r\n },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<FullOutput<any> & { object: z.infer<T> }> {\r\n this.logger.info(\"AGENT OBJECT RESULT\");\r\n const { schema, ...rest } = options;\r\n const result = await this.agentUse(agent, { ...rest, structuredOutput: { schema } }, ctx);\r\n if (result.isErr()) return err(result.error);\r\n this.logger.info(\"AGENT OBJECT RESULT DONE\");\r\n return ok({ ...result.value, object: result.value.object as z.infer<T> });\r\n }\r\n\r\n async embedDocument(\r\n value: string,\r\n options?: Parameters<ReturnType<typeof MDocument.fromText>[\"chunk\"]>[0],\r\n type: \"text\" | \"markdown\" | \"html\" | \"json\" = \"text\",\r\n model: string = OPENAI_TEXT_EMBEDDING_3_SMALL\r\n ): ServerResultAsync<{ embeddings: number[][]; chunks: { text: string }[] }> {\r\n return this.throwableAsync(async () => {\r\n if (type === \"text\") {\r\n const doc = MDocument.fromText(value);\r\n const chunks = await doc.chunk(\r\n options ?? {\r\n strategy: \"recursive\",\r\n maxSize: 512,\r\n overlap: 50,\r\n separators: [\"\\n\"],\r\n }\r\n );\r\n const embeddings = await this.embedMany(chunks, model);\r\n if (embeddings.isErr()) return err(embeddings.error);\r\n return ok({ embeddings: embeddings.value.embeddings, chunks });\r\n }\r\n return this.error(\"BAD_REQUEST\", \"Unsupported document type\");\r\n });\r\n }\r\n\r\n async embed(\r\n text: string,\r\n model: string = OPENAI_TEXT_EMBEDDING_3_SMALL\r\n ): ServerResultAsync<{ embedding: number[] }> {\r\n return this.throwableAsync(async () => {\r\n const result = await embed({\r\n model: this.prepareEmbeddingModel(model),\r\n value: text,\r\n });\r\n return ok(result);\r\n });\r\n }\r\n\r\n async embedMany(\r\n chunks: { text: string }[],\r\n model: string = OPENAI_TEXT_EMBEDDING_3_SMALL\r\n ): ServerResultAsync<{ embeddings: number[][] }> {\r\n return this.throwableAsync(async () => {\r\n const result = await embedMany({\r\n model: this.prepareEmbeddingModel(model),\r\n values: chunks.map((chunk) => chunk.text),\r\n });\r\n return ok(result);\r\n });\r\n }\r\n\r\n async generateText(params: AIServiceGenerateTextParams): ServerResultAsync<string> {\r\n return this.throwableAsync(async () => {\r\n const { removeMDash = true, model, prompt, messages, ctx, ...rest } = params;\r\n const request = messages\r\n ? { ...rest, model: this.prepareModel(model), messages }\r\n : { ...rest, model: this.prepareModel(model), prompt };\r\n const result = await generateText(request);\r\n if (this.repository.aiUsage) {\r\n const createUsageResult = await this.repository.aiUsage.create({\r\n userId: ctx?.actor?.userId,\r\n model,\r\n provider: \"openrouter\",\r\n feature: \"generateText\",\r\n traceId: result.providerMetadata?.openrouter?.traceId?.toString(),\r\n inputTokens: result.usage.inputTokens,\r\n outputTokens: result.usage.outputTokens,\r\n totalTokens: result.usage.totalTokens,\r\n cost: (result?.providerMetadata?.openrouter?.usage as any)?.cost ?? 0,\r\n });\r\n if (createUsageResult.isErr()) return err(createUsageResult.error);\r\n }\r\n return ok(removeMDash ? result.text.replace(/\\u2013|\\u2014/g, \"-\") : result.text);\r\n });\r\n }\r\n\r\n async generateObject<T extends ZodType>(\r\n params: AIServiceGenerateObjectParams<T>\r\n ): ServerResultAsync<z.infer<T>> {\r\n const {\r\n model,\r\n schema,\r\n prompt,\r\n messages,\r\n repairAttempts = 0,\r\n repairModel,\r\n ctx,\r\n ...rest\r\n } = params;\r\n const request = messages\r\n ? {\r\n ...rest,\r\n model: this.prepareModel(model),\r\n messages,\r\n output: Output.object({ schema }),\r\n }\r\n : {\r\n ...rest,\r\n model: this.prepareModel(model),\r\n prompt,\r\n output: Output.object({ schema }),\r\n };\r\n try {\r\n const result = await generateText(request);\r\n if (this.repository.aiUsage) {\r\n const createUsageResult = await this.repository.aiUsage.create({\r\n userId: ctx?.actor?.userId,\r\n model,\r\n provider: \"openrouter\",\r\n feature: \"generateObject\",\r\n traceId: result.providerMetadata?.openrouter?.traceId?.toString(),\r\n inputTokens: result.usage.inputTokens,\r\n outputTokens: result.usage.outputTokens,\r\n totalTokens: result.usage.totalTokens,\r\n cost: (result?.providerMetadata?.openrouter?.usage as any)?.cost ?? 0,\r\n });\r\n if (createUsageResult.isErr()) return err(createUsageResult.error);\r\n }\r\n return ok(result.output as z.infer<T>);\r\n } catch (error) {\r\n if (NoObjectGeneratedError.isInstance(error)) {\r\n if (this.repository.aiUsage) {\r\n const createUsageResult = await this.repository.aiUsage.create({\r\n userId: ctx?.actor?.userId,\r\n model,\r\n provider: \"openrouter\",\r\n feature: \"generateObject\",\r\n traceId: null,\r\n inputTokens: error?.usage?.inputTokens,\r\n outputTokens: error?.usage?.outputTokens,\r\n totalTokens: error?.usage?.totalTokens,\r\n cost: 0,\r\n });\r\n if (createUsageResult.isErr()) return err(createUsageResult.error);\r\n }\r\n if (error.text) {\r\n const repairedText = jsonrepair(error.text);\r\n const parsed = schema.safeParse(repairedText);\r\n if (parsed.success) return ok(parsed.data);\r\n\r\n if (repairAttempts === 0)\r\n return this.error(\"PARSE_ERROR\", \"AI: Agent object failed\", { cause: error });\r\n\r\n return this.generateObject({\r\n ...rest,\r\n prompt: repairJsonPrompt.compile({\r\n text: error.text,\r\n error: JSON.stringify(error.cause ?? \"Unknown error\"),\r\n }),\r\n repairAttempts: repairAttempts - 1,\r\n model: repairModel ?? model,\r\n schema,\r\n ctx,\r\n });\r\n }\r\n return this.error(\"PARSE_ERROR\", \"AI: Agent object failed without text\", {\r\n cause: error,\r\n });\r\n }\r\n return this.error(\"BAD_REQUEST\", \"AI: Provided failed to generate object\", { cause: error });\r\n }\r\n }\r\n\r\n async generateReplicate(\r\n model: Parameters<Replicate[\"run\"]>[0],\r\n options: Parameters<Replicate[\"run\"]>[1]\r\n ): ServerResultAsync<object> {\r\n return this.throwableAsync(async () => {\r\n if (!this.replicate) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Replicate is not configured\");\r\n }\r\n try {\r\n return ok(await this.replicate.run(model, options));\r\n } catch (error) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", undefined, { cause: error });\r\n }\r\n });\r\n }\r\n\r\n async generateTranscript(\r\n file_url: string\r\n ): ServerResultAsync<{ text: string; metadata: unknown }> {\r\n const output = await this.generateReplicate(\r\n \"thomasmol/whisper-diarization:1495a9cddc83b2203b0d8d3516e38b80fd1572ebc4bc5700ac1da56a9b3ed886\",\r\n {\r\n input: {\r\n file_url,\r\n },\r\n }\r\n );\r\n\r\n if (output.isErr()) return err(output.error);\r\n\r\n try {\r\n const { segments } = output.value as { segments: { text: string }[] };\r\n return ok({ text: segments.map((segment) => segment.text).join(\"\"), metadata: segments });\r\n } catch (error) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", undefined, { cause: error });\r\n }\r\n }\r\n\r\n async generateIdeogram(\r\n input: IdeogramV3GenerateInput\r\n ): ServerResultAsync<IdeogramV3GenerateOutput> {\r\n if (!this.service.ideogram) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Ideogram service is not available\");\r\n }\r\n return this.service.ideogram.generate(input);\r\n }\r\n\r\n async getUsage(\r\n userId: string\r\n ): ServerResultAsync<Pick<AiUsageRow, \"inputTokens\" | \"outputTokens\" | \"totalTokens\" | \"cost\">> {\r\n if (!this.repository.aiUsage) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"AI usage repository is not available\");\r\n }\r\n return this.repository.aiUsage.getUsage(userId);\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;AAqDA,IAAa,YAAb,cAA8D,YAG5D;CACA,UAAU,EACR,kBACD;CAED;CACA;CACA;CAEA,YACE,cACA,UACA,MACA;AACA,QAAM,cAAc,SAAS;AAC7B,OAAK,SAAS,KAAK;AACnB,OAAK,aAAa,KAAK;AACvB,OAAK,YAAY,KAAK;;CAGxB,YAA4B;AAC1B,MAAI,CAAC,KAAK,OACR,OAAM,IAAI,MAAM,0BAA0B;AAE5C,SAAO,KAAK;;CAGd,aAAa,OAAuD;AAClE,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,+BAA+B;AAEjD,SAAO,KAAK,WAAW,KAAK,OAAO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K,MAAM,yBAAyB,KAAA,GAAW,EAAE,OAAO,OAAO,CAAC;;;CAI3E,MAAM,iBACJ,OAC6C;AAC7C,MAAI,CAAC,KAAK,QAAQ,SAChB,QAAO,KAAK,MAAM,yBAAyB,oCAAoC;AAEjF,SAAO,KAAK,QAAQ,SAAS,SAAS,MAAM;;CAG9C,MAAM,SACJ,QAC8F;AAC9F,MAAI,CAAC,KAAK,WAAW,QACnB,QAAO,KAAK,MAAM,yBAAyB,uCAAuC;AAEpF,SAAO,KAAK,WAAW,QAAQ,SAAS,OAAO"}
|
|
1
|
+
{"version":3,"file":"ai.service.mjs","names":[],"sources":["../../../../src/modules/ai/ai.service.ts"],"sourcesContent":["import { OPENAI_TEXT_EMBEDDING_3_SMALL } from \"@m5kdev/commons/modules/ai/ai.constants\";\r\nimport { arrayToPseudoXML } from \"@m5kdev/commons/modules/ai/ai.utils\";\r\nimport type { Mastra } from \"@mastra/core\";\r\nimport { RequestContext } from \"@mastra/core/request-context\";\r\nimport type { FullOutput, MastraModelOutput } from \"@mastra/core/stream\";\r\nimport { MDocument } from \"@mastra/rag\";\r\nimport type { OpenRouterProvider } from \"@openrouter/ai-sdk-provider\";\r\nimport {\r\n embed,\r\n embedMany,\r\n generateText,\r\n type ModelMessage,\r\n NoObjectGeneratedError,\r\n Output,\r\n} from \"ai\";\r\nimport { jsonrepair } from \"jsonrepair\";\r\nimport { err, ok } from \"neverthrow\";\r\nimport type Replicate from \"replicate\";\r\nimport type { ZodType, z } from \"zod\";\r\nimport type { RequiredServiceActor } from \"../base/base.actor\";\r\nimport type { ServerResultAsync } from \"../base/base.dto\";\r\nimport { BaseService } from \"../base/base.service\";\r\nimport { repairJsonPrompt } from \"./ai.prompts\";\r\nimport type { AiUsageRepository, AiUsageRow } from \"./ai.repository\";\r\nimport type { IdeogramV3GenerateInput, IdeogramV3GenerateOutput } from \"./ideogram/ideogram.dto\";\r\nimport type { IdeogramService } from \"./ideogram/ideogram.service\";\r\n\r\ntype MastraAgent = ReturnType<Mastra[\"getAgent\"]>;\r\ntype MastraAgentGenerateOptions = Parameters<MastraAgent[\"generate\"]>[1];\r\ntype MessageListInput = { role: \"user\" | \"assistant\" | \"system\"; content: string }[];\r\ntype GenerateTextParams = Parameters<typeof generateText>[0];\r\ntype GenerateTextInput =\r\n | { prompt: string | ModelMessage[]; messages?: never }\r\n | { messages: ModelMessage[]; prompt?: never };\r\ntype AIServiceActorContext = { actor: RequiredServiceActor<\"user\"> };\r\ntype AIServiceGenerateTextParams = Omit<GenerateTextParams, \"model\" | \"prompt\" | \"messages\"> &\r\n GenerateTextInput & {\r\n model: string;\r\n removeMDash?: boolean;\r\n ctx?: AIServiceActorContext;\r\n retryAttempts?: number;\r\n retryModels?: string[];\r\n };\r\ntype AIServiceGenerateObjectParams<T extends ZodType> = Omit<\r\n GenerateTextParams,\r\n \"model\" | \"prompt\" | \"messages\" | \"output\"\r\n> &\r\n GenerateTextInput & {\r\n model: string;\r\n schema: T;\r\n repairAttempts?: number;\r\n repairModel?: string;\r\n ctx?: AIServiceActorContext;\r\n retryAttempts?: number;\r\n retryModels?: string[];\r\n };\r\n\r\ntype AIServiceOptions = {\r\n retryAttempts?: number;\r\n retryModels?: string[];\r\n repairAttempts?: number;\r\n repairModel?: string;\r\n removeMDash?: boolean;\r\n};\r\n\r\nexport class AIService<MastraInstance extends Mastra> extends BaseService<\r\n { aiUsage?: AiUsageRepository },\r\n { ideogram?: IdeogramService }\r\n> {\r\n helpers = {\r\n arrayToPseudoXML,\r\n };\r\n\r\n mastra?: MastraInstance;\r\n openrouter?: OpenRouterProvider;\r\n replicate?: Replicate;\r\n options?: AIServiceOptions;\r\n\r\n constructor(\r\n repositories: { aiUsage?: AiUsageRepository },\r\n services: { ideogram?: IdeogramService },\r\n libs: { mastra?: MastraInstance; openrouter?: OpenRouterProvider; replicate?: Replicate },\r\n options?: AIServiceOptions\r\n ) {\r\n super(repositories, services);\r\n this.mastra = libs.mastra;\r\n this.openrouter = libs.openrouter;\r\n this.replicate = libs.replicate;\r\n this.options = options;\r\n }\r\n\r\n getMastra(): MastraInstance {\r\n if (!this.mastra) {\r\n throw new Error(\"Mastra is not available\");\r\n }\r\n return this.mastra;\r\n }\r\n\r\n prepareModel(model: string): ReturnType<OpenRouterProvider[\"chat\"]> {\r\n if (!this.openrouter) {\r\n throw new Error(\"OpenRouter is not configured\");\r\n }\r\n return this.openrouter.chat(model, {\r\n usage: {\r\n include: true,\r\n },\r\n });\r\n }\r\n\r\n prepareEmbeddingModel(model: string): ReturnType<OpenRouterProvider[\"textEmbeddingModel\"]> {\r\n if (!this.openrouter) {\r\n throw new Error(\"OpenRouter is not configured\");\r\n }\r\n const openrouter = this.openrouter as OpenRouterProvider & {\r\n embeddingModel?: (modelId: string) => unknown;\r\n };\r\n return (openrouter.embeddingModel?.(model) ??\r\n openrouter.textEmbeddingModel(model)) as ReturnType<OpenRouterProvider[\"textEmbeddingModel\"]>;\r\n }\r\n\r\n async agentUse(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & { prompt?: string; messages?: MessageListInput },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<Awaited<ReturnType<MastraModelOutput<any>[\"getFullOutput\"]>>> {\r\n return this.throwableAsync(async () => {\r\n this.logger.info(\"AGENT USE\");\r\n const { prompt, messages, ...rest } = options;\r\n const payload = messages || prompt;\r\n if (!payload) return this.error(\"BAD_REQUEST\", \"No prompt or messages provided\");\r\n const requestContext = options.requestContext ?? new RequestContext();\r\n\r\n if (ctx?.actor) {\r\n requestContext.set(\"userId\", ctx.actor.userId);\r\n }\r\n if (ctx?.model) {\r\n requestContext.set(\"model\", ctx.model);\r\n }\r\n const mAgent = this.getMastra().getAgent(agent);\r\n\r\n const result = await mAgent.generate(payload as any, {\r\n ...rest,\r\n requestContext: rest.requestContext ?? requestContext,\r\n });\r\n this.logger.info(\"AGENT USE DONE\");\r\n if (this.repository.aiUsage) {\r\n const createUsageResult = await this.repository.aiUsage.create({\r\n userId: ctx?.actor?.userId,\r\n model: ctx?.model ?? \"unknown\",\r\n provider: \"openrouter\",\r\n feature: agent,\r\n traceId: result.traceId,\r\n inputTokens: result.usage.inputTokens,\r\n outputTokens: result.usage.outputTokens,\r\n totalTokens: result.usage.totalTokens,\r\n cost: (result?.providerMetadata?.openrouter?.usage as any)?.cost ?? 0,\r\n });\r\n if (createUsageResult.isErr()) return err(createUsageResult.error);\r\n }\r\n this.logger.info(\"AGENT USE CREATED USAGE\");\r\n return ok(result);\r\n });\r\n }\r\n\r\n async agentText(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & { prompt?: string; messages?: MessageListInput },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<string> {\r\n const result = await this.agentUse(agent, options, ctx);\r\n if (result.isErr())\r\n return this.error(\"SERVICE_UNAVAILABLE\", \"AI: Agent text failed\", { cause: result.error });\r\n return ok(result.value.text);\r\n }\r\n\r\n async agentTextResult(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & { prompt?: string; messages?: MessageListInput },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<FullOutput<any>> {\r\n const result = await this.agentUse(agent, options, ctx);\r\n if (result.isErr()) return err(result.error);\r\n return ok(result.value);\r\n }\r\n\r\n async agentObject<T extends ZodType<any>>(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & {\r\n schema: T;\r\n prompt?: string;\r\n messages?: MessageListInput;\r\n },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<z.infer<T>> {\r\n const { schema, ...rest } = options;\r\n const result = await this.agentUse(agent, { ...rest, structuredOutput: { schema } }, ctx);\r\n if (result.isErr())\r\n return this.error(\"SERVICE_UNAVAILABLE\", \"AI: Agent object failed\", { cause: result.error });\r\n return ok(result.value.object as z.infer<T>);\r\n }\r\n\r\n async agentObjectResult<T extends ZodType<any>>(\r\n agent: string,\r\n options: MastraAgentGenerateOptions & {\r\n schema: T;\r\n prompt?: string;\r\n messages?: MessageListInput;\r\n },\r\n ctx?: AIServiceActorContext & { model?: string }\r\n ): ServerResultAsync<FullOutput<any> & { object: z.infer<T> }> {\r\n this.logger.info(\"AGENT OBJECT RESULT\");\r\n const { schema, ...rest } = options;\r\n const result = await this.agentUse(agent, { ...rest, structuredOutput: { schema } }, ctx);\r\n if (result.isErr()) return err(result.error);\r\n this.logger.info(\"AGENT OBJECT RESULT DONE\");\r\n return ok({ ...result.value, object: result.value.object as z.infer<T> });\r\n }\r\n\r\n async embedDocument(\r\n value: string,\r\n options?: Parameters<ReturnType<typeof MDocument.fromText>[\"chunk\"]>[0],\r\n type: \"text\" | \"markdown\" | \"html\" | \"json\" = \"text\",\r\n model: string = OPENAI_TEXT_EMBEDDING_3_SMALL\r\n ): ServerResultAsync<{ embeddings: number[][]; chunks: { text: string }[] }> {\r\n return this.throwableAsync(async () => {\r\n if (type === \"text\") {\r\n const doc = MDocument.fromText(value);\r\n const chunks = await doc.chunk(\r\n options ?? {\r\n strategy: \"recursive\",\r\n maxSize: 512,\r\n overlap: 50,\r\n separators: [\"\\n\"],\r\n }\r\n );\r\n const embeddings = await this.embedMany(chunks, model);\r\n if (embeddings.isErr()) return err(embeddings.error);\r\n return ok({ embeddings: embeddings.value.embeddings, chunks });\r\n }\r\n return this.error(\"BAD_REQUEST\", \"Unsupported document type\");\r\n });\r\n }\r\n\r\n async embed(\r\n text: string,\r\n model: string = OPENAI_TEXT_EMBEDDING_3_SMALL\r\n ): ServerResultAsync<{ embedding: number[] }> {\r\n return this.throwableAsync(async () => {\r\n const result = await embed({\r\n model: this.prepareEmbeddingModel(model),\r\n value: text,\r\n });\r\n return ok(result);\r\n });\r\n }\r\n\r\n async embedMany(\r\n chunks: { text: string }[],\r\n model: string = OPENAI_TEXT_EMBEDDING_3_SMALL\r\n ): ServerResultAsync<{ embeddings: number[][] }> {\r\n return this.throwableAsync(async () => {\r\n const result = await embedMany({\r\n model: this.prepareEmbeddingModel(model),\r\n values: chunks.map((chunk) => chunk.text),\r\n });\r\n return ok(result);\r\n });\r\n }\r\n\r\n async generateText(params: AIServiceGenerateTextParams): ServerResultAsync<string> {\r\n return this.throwableAsync(async () => {\r\n const {\r\n removeMDash = this.options?.removeMDash ?? true,\r\n model,\r\n prompt,\r\n messages,\r\n ctx,\r\n retryAttempts = this.options?.retryAttempts ?? 0,\r\n retryModels = this.options?.retryModels ?? [],\r\n ...rest\r\n } = params;\r\n const request = messages\r\n ? { ...rest, model: this.prepareModel(model), messages }\r\n : { ...rest, model: this.prepareModel(model), prompt };\r\n try {\r\n const result = await generateText(request);\r\n if (this.repository.aiUsage) {\r\n const createUsageResult = await this.repository.aiUsage.create({\r\n userId: ctx?.actor?.userId,\r\n model,\r\n provider: \"openrouter\",\r\n feature: \"generateText\",\r\n traceId: result.providerMetadata?.openrouter?.traceId?.toString(),\r\n inputTokens: result.usage.inputTokens,\r\n outputTokens: result.usage.outputTokens,\r\n totalTokens: result.usage.totalTokens,\r\n cost: (result?.providerMetadata?.openrouter?.usage as any)?.cost ?? 0,\r\n });\r\n if (createUsageResult.isErr()) return err(createUsageResult.error);\r\n }\r\n return ok(removeMDash ? result.text.replace(/\\u2013|\\u2014/g, \"-\") : result.text);\r\n } catch (error) {\r\n if (retryAttempts <= 0) throw error;\r\n this.logger.warn(`generateText failed, retrying (${retryAttempts} attempts left)`, {\r\n model,\r\n error,\r\n });\r\n // Exponential backoff: wait before retrying\r\n const delay = Math.min(\r\n 1000 * 2 ** ((this.options?.retryAttempts ?? 3) - retryAttempts),\r\n 10000\r\n );\r\n await new Promise<void>((resolve) => setTimeout(resolve, delay));\r\n const nextModel = retryModels?.[0] ?? model;\r\n const nextRetryModels = retryModels ? [...retryModels.slice(1), model] : undefined;\r\n return this.generateText({\r\n ...rest,\r\n ...(messages ? { messages } : { prompt: prompt! }),\r\n model: nextModel,\r\n removeMDash,\r\n ctx,\r\n retryAttempts: retryAttempts - 1,\r\n retryModels: nextRetryModels,\r\n } as AIServiceGenerateTextParams);\r\n }\r\n });\r\n }\r\n\r\n async generateObject<T extends ZodType>(\r\n params: AIServiceGenerateObjectParams<T>\r\n ): ServerResultAsync<z.infer<T>> {\r\n const {\r\n model,\r\n schema,\r\n prompt,\r\n messages,\r\n repairAttempts = this.options?.repairAttempts ?? 0,\r\n repairModel = this.options?.repairModel ?? model,\r\n ctx,\r\n retryAttempts = this.options?.retryAttempts ?? 0,\r\n retryModels = this.options?.retryModels ?? [],\r\n ...rest\r\n } = params;\r\n const request = messages\r\n ? {\r\n ...rest,\r\n model: this.prepareModel(model),\r\n messages,\r\n output: Output.object({ schema }),\r\n }\r\n : {\r\n ...rest,\r\n model: this.prepareModel(model),\r\n prompt,\r\n output: Output.object({ schema }),\r\n };\r\n try {\r\n const result = await generateText(request);\r\n if (this.repository.aiUsage) {\r\n const createUsageResult = await this.repository.aiUsage.create({\r\n userId: ctx?.actor?.userId,\r\n model,\r\n provider: \"openrouter\",\r\n feature: \"generateObject\",\r\n traceId: result.providerMetadata?.openrouter?.traceId?.toString(),\r\n inputTokens: result.usage.inputTokens,\r\n outputTokens: result.usage.outputTokens,\r\n totalTokens: result.usage.totalTokens,\r\n cost: (result?.providerMetadata?.openrouter?.usage as any)?.cost ?? 0,\r\n });\r\n if (createUsageResult.isErr()) return err(createUsageResult.error);\r\n }\r\n return ok(result.output as z.infer<T>);\r\n } catch (error) {\r\n if (NoObjectGeneratedError.isInstance(error)) {\r\n if (this.repository.aiUsage) {\r\n const createUsageResult = await this.repository.aiUsage.create({\r\n userId: ctx?.actor?.userId,\r\n model,\r\n provider: \"openrouter\",\r\n feature: \"generateObject\",\r\n traceId: null,\r\n inputTokens: error?.usage?.inputTokens,\r\n outputTokens: error?.usage?.outputTokens,\r\n totalTokens: error?.usage?.totalTokens,\r\n cost: 0,\r\n });\r\n if (createUsageResult.isErr()) return err(createUsageResult.error);\r\n }\r\n if (error.text) {\r\n const repairedText = jsonrepair(error.text);\r\n const parsed = schema.safeParse(repairedText);\r\n if (parsed.success) return ok(parsed.data);\r\n\r\n if (repairAttempts === 0)\r\n return this.error(\"PARSE_ERROR\", \"AI: Agent object failed\", { cause: error });\r\n\r\n return this.generateObject({\r\n ...rest,\r\n prompt: repairJsonPrompt.compile({\r\n text: error.text,\r\n error: JSON.stringify(error.cause ?? \"Unknown error\"),\r\n }),\r\n repairAttempts: repairAttempts - 1,\r\n model: repairModel ?? model,\r\n schema,\r\n ctx,\r\n });\r\n }\r\n return this.error(\"PARSE_ERROR\", \"AI: Agent object failed without text\", {\r\n cause: error,\r\n });\r\n }\r\n if (retryAttempts <= 0)\r\n return this.error(\"BAD_REQUEST\", \"AI: Provider failed to generate object\", {\r\n cause: error,\r\n });\r\n this.logger.warn(`generateObject failed, retrying (${retryAttempts} attempts left)`, {\r\n model,\r\n error,\r\n });\r\n // Exponential backoff: wait before retrying\r\n const delay = Math.min(\r\n 1000 * 2 ** ((this.options?.retryAttempts ?? 3) - retryAttempts),\r\n 10000\r\n );\r\n await new Promise<void>((resolve) => setTimeout(resolve, delay));\r\n const nextModel = retryModels?.[0] ?? model;\r\n const nextRetryModels = retryModels ? [...retryModels.slice(1), model] : undefined;\r\n return this.generateObject({\r\n ...rest,\r\n ...(messages ? { messages } : { prompt: prompt! }),\r\n model: nextModel,\r\n schema,\r\n repairAttempts,\r\n repairModel,\r\n ctx,\r\n retryAttempts: retryAttempts - 1,\r\n retryModels: nextRetryModels,\r\n } as AIServiceGenerateObjectParams<T>);\r\n }\r\n }\r\n\r\n async generateReplicate(\r\n model: Parameters<Replicate[\"run\"]>[0],\r\n options: Parameters<Replicate[\"run\"]>[1]\r\n ): ServerResultAsync<object> {\r\n return this.throwableAsync(async () => {\r\n if (!this.replicate) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Replicate is not configured\");\r\n }\r\n try {\r\n return ok(await this.replicate.run(model, options));\r\n } catch (error) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", undefined, { cause: error });\r\n }\r\n });\r\n }\r\n\r\n async generateTranscript(\r\n file_url: string\r\n ): ServerResultAsync<{ text: string; metadata: unknown }> {\r\n const output = await this.generateReplicate(\r\n \"thomasmol/whisper-diarization:1495a9cddc83b2203b0d8d3516e38b80fd1572ebc4bc5700ac1da56a9b3ed886\",\r\n {\r\n input: {\r\n file_url,\r\n },\r\n }\r\n );\r\n\r\n if (output.isErr()) return err(output.error);\r\n\r\n try {\r\n const { segments } = output.value as { segments: { text: string }[] };\r\n return ok({ text: segments.map((segment) => segment.text).join(\"\"), metadata: segments });\r\n } catch (error) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", undefined, { cause: error });\r\n }\r\n }\r\n\r\n async generateIdeogram(\r\n input: IdeogramV3GenerateInput\r\n ): ServerResultAsync<IdeogramV3GenerateOutput> {\r\n if (!this.service.ideogram) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"Ideogram service is not available\");\r\n }\r\n return this.service.ideogram.generate(input);\r\n }\r\n\r\n async getUsage(\r\n userId: string\r\n ): ServerResultAsync<Pick<AiUsageRow, \"inputTokens\" | \"outputTokens\" | \"totalTokens\" | \"cost\">> {\r\n if (!this.repository.aiUsage) {\r\n return this.error(\"INTERNAL_SERVER_ERROR\", \"AI usage repository is not available\");\r\n }\r\n return this.repository.aiUsage.getUsage(userId);\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;AAiEA,IAAa,YAAb,cAA8D,YAG5D;CACA,UAAU,EACR,kBACD;CAED;CACA;CACA;CACA;CAEA,YACE,cACA,UACA,MACA,SACA;AACA,QAAM,cAAc,SAAS;AAC7B,OAAK,SAAS,KAAK;AACnB,OAAK,aAAa,KAAK;AACvB,OAAK,YAAY,KAAK;AACtB,OAAK,UAAU;;CAGjB,YAA4B;AAC1B,MAAI,CAAC,KAAK,OACR,OAAM,IAAI,MAAM,0BAA0B;AAE5C,SAAO,KAAK;;CAGd,aAAa,OAAuD;AAClE,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MAAM,+BAA+B;AAEjD,SAAO,KAAK,WAAW,KAAK,OAAO,EACjC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AAK,MAAM,yBAAyB,KAAA,GAAW,EAAE,OAAO,OAAO,CAAC;;;CAI3E,MAAM,iBACJ,OAC6C;AAC7C,MAAI,CAAC,KAAK,QAAQ,SAChB,QAAO,KAAK,MAAM,yBAAyB,oCAAoC;AAEjF,SAAO,KAAK,QAAQ,SAAS,SAAS,MAAM;;CAG9C,MAAM,SACJ,QAC8F;AAC9F,MAAI,CAAC,KAAK,WAAW,QACnB,QAAO,KAAK,MAAM,yBAAyB,uCAAuC;AAEpF,SAAO,KAAK,WAAW,QAAQ,SAAS,OAAO"}
|
|
@@ -12,8 +12,8 @@ declare const waitlistSchema: z.ZodObject<{
|
|
|
12
12
|
expiresAt: z.ZodNullable<z.ZodDate>;
|
|
13
13
|
}, z.core.$strip>;
|
|
14
14
|
declare const waitlistOutputSchema: z.ZodObject<{
|
|
15
|
-
id: z.ZodString;
|
|
16
15
|
name: z.ZodNullable<z.ZodString>;
|
|
16
|
+
id: z.ZodString;
|
|
17
17
|
email: z.ZodNullable<z.ZodString>;
|
|
18
18
|
createdAt: z.ZodDate;
|
|
19
19
|
updatedAt: z.ZodNullable<z.ZodDate>;
|
|
@@ -58,8 +58,8 @@ declare const accountClaimMagicLinkOutputSchema: z.ZodObject<{
|
|
|
58
58
|
id: z.ZodString;
|
|
59
59
|
email: z.ZodString;
|
|
60
60
|
createdAt: z.ZodDate;
|
|
61
|
-
userId: z.ZodString;
|
|
62
61
|
expiresAt: z.ZodNullable<z.ZodDate>;
|
|
62
|
+
userId: z.ZodString;
|
|
63
63
|
claimId: z.ZodString;
|
|
64
64
|
url: z.ZodString;
|
|
65
65
|
}, z.core.$strip>;
|
|
@@ -4830,7 +4830,7 @@ declare function createBetterAuth<O extends Orm, S extends Schema, E extends Ema
|
|
|
4830
4830
|
} | undefined;
|
|
4831
4831
|
verification?: {
|
|
4832
4832
|
modelName?: string;
|
|
4833
|
-
fields?: Partial<Record<"createdAt" | "updatedAt" | "expiresAt" | "
|
|
4833
|
+
fields?: Partial<Record<"createdAt" | "updatedAt" | "expiresAt" | "value" | "identifier", string>>;
|
|
4834
4834
|
additionalFields?: {
|
|
4835
4835
|
[key: string]: _$better_auth0.DBFieldAttribute;
|
|
4836
4836
|
};
|
|
@@ -76,8 +76,8 @@ declare function createAuthTRPC({
|
|
|
76
76
|
id: string;
|
|
77
77
|
email: string;
|
|
78
78
|
createdAt: Date;
|
|
79
|
-
userId: string;
|
|
80
79
|
expiresAt: Date | null;
|
|
80
|
+
userId: string;
|
|
81
81
|
claimId: string;
|
|
82
82
|
url: string;
|
|
83
83
|
};
|
|
@@ -91,8 +91,8 @@ declare function createAuthTRPC({
|
|
|
91
91
|
id: string;
|
|
92
92
|
email: string;
|
|
93
93
|
createdAt: Date;
|
|
94
|
-
userId: string;
|
|
95
94
|
expiresAt: Date | null;
|
|
95
|
+
userId: string;
|
|
96
96
|
claimId: string;
|
|
97
97
|
url: string;
|
|
98
98
|
}[];
|
|
@@ -146,8 +146,8 @@ declare function createAuthTRPC({
|
|
|
146
146
|
listAdminWaitlist: _$_trpc_server0.TRPCQueryProcedure<{
|
|
147
147
|
input: void;
|
|
148
148
|
output: {
|
|
149
|
-
id: string;
|
|
150
149
|
name: string | null;
|
|
150
|
+
id: string;
|
|
151
151
|
email: string | null;
|
|
152
152
|
createdAt: Date;
|
|
153
153
|
updatedAt: Date | null;
|
|
@@ -160,8 +160,8 @@ declare function createAuthTRPC({
|
|
|
160
160
|
email: string;
|
|
161
161
|
};
|
|
162
162
|
output: {
|
|
163
|
-
id: string;
|
|
164
163
|
name: string | null;
|
|
164
|
+
id: string;
|
|
165
165
|
email: string | null;
|
|
166
166
|
createdAt: Date;
|
|
167
167
|
updatedAt: Date | null;
|
|
@@ -191,8 +191,8 @@ declare function createAuthTRPC({
|
|
|
191
191
|
id: string;
|
|
192
192
|
};
|
|
193
193
|
output: {
|
|
194
|
-
id: string;
|
|
195
194
|
name: string | null;
|
|
195
|
+
id: string;
|
|
196
196
|
email: string | null;
|
|
197
197
|
createdAt: Date;
|
|
198
198
|
updatedAt: Date | null;
|
|
@@ -205,8 +205,8 @@ declare function createAuthTRPC({
|
|
|
205
205
|
id: string;
|
|
206
206
|
};
|
|
207
207
|
output: {
|
|
208
|
-
id: string;
|
|
209
208
|
name: string | null;
|
|
209
|
+
id: string;
|
|
210
210
|
email: string | null;
|
|
211
211
|
createdAt: Date;
|
|
212
212
|
updatedAt: Date | null;
|
|
@@ -219,8 +219,8 @@ declare function createAuthTRPC({
|
|
|
219
219
|
email: string;
|
|
220
220
|
};
|
|
221
221
|
output: {
|
|
222
|
-
id: string;
|
|
223
222
|
name: string | null;
|
|
223
|
+
id: string;
|
|
224
224
|
email: string | null;
|
|
225
225
|
createdAt: Date;
|
|
226
226
|
updatedAt: Date | null;
|
|
@@ -4,7 +4,7 @@ import { BillingSchema } from "@m5kdev/commons/modules/billing/billing.schema";
|
|
|
4
4
|
import { InferSelectModel } from "drizzle-orm";
|
|
5
5
|
import * as _$drizzle_orm_sqlite_core0 from "drizzle-orm/sqlite-core";
|
|
6
6
|
import { LibSQLDatabase } from "drizzle-orm/libsql";
|
|
7
|
-
import { Stripe } from "stripe";
|
|
7
|
+
import { Stripe as Stripe$1 } from "stripe";
|
|
8
8
|
import { StripePlan } from "@m5kdev/commons/modules/billing/billing.types";
|
|
9
9
|
|
|
10
10
|
//#region src/modules/billing/billing.repository.d.ts
|
|
@@ -2713,7 +2713,7 @@ declare const schema: {
|
|
|
2713
2713
|
type Schema = typeof schema;
|
|
2714
2714
|
type Orm = LibSQLDatabase<Schema>;
|
|
2715
2715
|
declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<string, never>, Schema["subscriptions"]> {
|
|
2716
|
-
stripe: Stripe;
|
|
2716
|
+
stripe: Stripe$1;
|
|
2717
2717
|
plans: StripePlan[];
|
|
2718
2718
|
trial?: StripePlan;
|
|
2719
2719
|
constructor(options: {
|
|
@@ -2721,7 +2721,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2721
2721
|
schema: Schema;
|
|
2722
2722
|
table: Schema["subscriptions"];
|
|
2723
2723
|
libs: {
|
|
2724
|
-
stripe: Stripe;
|
|
2724
|
+
stripe: Stripe$1;
|
|
2725
2725
|
};
|
|
2726
2726
|
config: {
|
|
2727
2727
|
trial?: StripePlan;
|
|
@@ -2730,7 +2730,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2730
2730
|
});
|
|
2731
2731
|
hasTrial(): boolean;
|
|
2732
2732
|
getPlanByPriceId(priceId: string): StripePlan | undefined;
|
|
2733
|
-
getCustomerByEmail(email: string): ServerResultAsync<Stripe.Customer | null>;
|
|
2733
|
+
getCustomerByEmail(email: string): ServerResultAsync<Stripe$1.Customer | null>;
|
|
2734
2734
|
getUserByCustomerId(customerId: string): ServerResultAsync<InferSelectModel<Schema["users"]> | null>;
|
|
2735
2735
|
createCustomer({
|
|
2736
2736
|
email,
|
|
@@ -2740,8 +2740,8 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2740
2740
|
email: string;
|
|
2741
2741
|
name?: string;
|
|
2742
2742
|
userId: string;
|
|
2743
|
-
}): ServerResultAsync<Stripe.Customer>;
|
|
2744
|
-
createTrialSubscription(customerId: string): ServerResultAsync<Stripe.Subscription>;
|
|
2743
|
+
}): ServerResultAsync<Stripe$1.Customer>;
|
|
2744
|
+
createTrialSubscription(customerId: string): ServerResultAsync<Stripe$1.Subscription>;
|
|
2745
2745
|
createSubscription({
|
|
2746
2746
|
customerId,
|
|
2747
2747
|
priceId,
|
|
@@ -2752,7 +2752,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2752
2752
|
priceId: string;
|
|
2753
2753
|
quantity?: number;
|
|
2754
2754
|
trialDays?: number;
|
|
2755
|
-
}): ServerResultAsync<Stripe.Subscription>;
|
|
2755
|
+
}): ServerResultAsync<Stripe$1.Subscription>;
|
|
2756
2756
|
updateUserCustomerId({
|
|
2757
2757
|
userId,
|
|
2758
2758
|
customerId
|
|
@@ -2762,7 +2762,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2762
2762
|
}): ServerResultAsync<InferSelectModel<Schema["users"]>>;
|
|
2763
2763
|
getLatestSubscription(referenceId: string): ServerResultAsync<BillingSchema | null>;
|
|
2764
2764
|
getActiveSubscription(referenceId: string): ServerResultAsync<BillingSchema | null>;
|
|
2765
|
-
listInvoices(customerId: string): ServerResultAsync<Stripe.Invoice[]>;
|
|
2765
|
+
listInvoices(customerId: string): ServerResultAsync<Stripe$1.Invoice[]>;
|
|
2766
2766
|
createCheckoutSession({
|
|
2767
2767
|
customerId,
|
|
2768
2768
|
priceId,
|
|
@@ -2771,8 +2771,8 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2771
2771
|
customerId: string;
|
|
2772
2772
|
priceId: string;
|
|
2773
2773
|
userId: string;
|
|
2774
|
-
}): ServerResultAsync<Stripe.Checkout.Session>;
|
|
2775
|
-
createBillingPortalSession(customerId: string): ServerResultAsync<Stripe.BillingPortal.Session>;
|
|
2774
|
+
}): ServerResultAsync<Stripe$1.Checkout.Session>;
|
|
2775
|
+
createBillingPortalSession(customerId: string): ServerResultAsync<Stripe$1.BillingPortal.Session>;
|
|
2776
2776
|
syncStripeData({
|
|
2777
2777
|
customerId,
|
|
2778
2778
|
userId
|
|
@@ -2780,7 +2780,7 @@ declare class BillingRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
2780
2780
|
customerId: string;
|
|
2781
2781
|
userId: string;
|
|
2782
2782
|
}): ServerResultAsync<boolean>;
|
|
2783
|
-
constructEvent(body: Buffer | string, signature: string, secret: string): ServerResult<Stripe.Event>;
|
|
2783
|
+
constructEvent(body: Buffer | string, signature: string, secret: string): ServerResult<Stripe$1.Event>;
|
|
2784
2784
|
}
|
|
2785
2785
|
//#endregion
|
|
2786
2786
|
export { BillingRepository };
|
|
@@ -4,7 +4,7 @@ import { BillingRepository } from "./billing.repository.mjs";
|
|
|
4
4
|
import { User } from "../auth/auth.lib.mjs";
|
|
5
5
|
import { BaseService } from "../base/base.service.mjs";
|
|
6
6
|
import { BillingSchema } from "@m5kdev/commons/modules/billing/billing.schema";
|
|
7
|
-
import Stripe
|
|
7
|
+
import Stripe from "stripe";
|
|
8
8
|
|
|
9
9
|
//#region src/modules/billing/billing.service.d.ts
|
|
10
10
|
declare class BillingService extends BaseService<{
|
|
@@ -18,7 +18,7 @@ declare class BillingService extends BaseService<{
|
|
|
18
18
|
email: string;
|
|
19
19
|
name?: string;
|
|
20
20
|
};
|
|
21
|
-
}): ServerResultAsync<Stripe
|
|
21
|
+
}): ServerResultAsync<Stripe.Customer>;
|
|
22
22
|
createUserHook({
|
|
23
23
|
user
|
|
24
24
|
}: {
|
|
@@ -29,7 +29,7 @@ declare class BillingService extends BaseService<{
|
|
|
29
29
|
};
|
|
30
30
|
}): ServerResultAsync<boolean>;
|
|
31
31
|
getActiveSubscription(ctx: Context): ServerResultAsync<BillingSchema | null>;
|
|
32
|
-
listInvoices(ctx: Context): ServerResultAsync<Stripe
|
|
32
|
+
listInvoices(ctx: Context): ServerResultAsync<Stripe.Invoice[]>;
|
|
33
33
|
createCheckoutSession({
|
|
34
34
|
priceId
|
|
35
35
|
}: {
|
|
@@ -38,15 +38,15 @@ declare class BillingService extends BaseService<{
|
|
|
38
38
|
user
|
|
39
39
|
}: {
|
|
40
40
|
user: User;
|
|
41
|
-
}): ServerResultAsync<Stripe
|
|
41
|
+
}): ServerResultAsync<Stripe.Checkout.Session>;
|
|
42
42
|
createBillingPortalSession({
|
|
43
43
|
user
|
|
44
44
|
}: {
|
|
45
45
|
user: User;
|
|
46
|
-
}): ServerResultAsync<Stripe
|
|
47
|
-
constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe
|
|
46
|
+
}): ServerResultAsync<Stripe.BillingPortal.Session>;
|
|
47
|
+
constructEvent(body: Buffer | string, signature: string): ServerResult<Stripe.Event>;
|
|
48
48
|
syncStripeData(customerId: string, eventType?: string): ServerResultAsync<boolean>;
|
|
49
|
-
processEvent(event: Stripe
|
|
49
|
+
processEvent(event: Stripe.Event): ServerResultAsync<boolean>;
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
|
52
52
|
export { BillingService };
|
|
@@ -27,9 +27,9 @@ declare const connectSelectOutputSchema: z.ZodObject<{
|
|
|
27
27
|
id: z.ZodString;
|
|
28
28
|
createdAt: z.ZodDate;
|
|
29
29
|
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
30
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
30
31
|
userId: z.ZodString;
|
|
31
32
|
provider: z.ZodString;
|
|
32
|
-
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
33
33
|
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
34
34
|
accountType: z.ZodString;
|
|
35
35
|
providerAccountId: z.ZodString;
|
|
@@ -51,9 +51,9 @@ declare const connectListOutputSchema: z.ZodArray<z.ZodObject<{
|
|
|
51
51
|
id: z.ZodString;
|
|
52
52
|
createdAt: z.ZodDate;
|
|
53
53
|
updatedAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
54
|
+
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
54
55
|
userId: z.ZodString;
|
|
55
56
|
provider: z.ZodString;
|
|
56
|
-
expiresAt: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
|
|
57
57
|
scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
58
58
|
accountType: z.ZodString;
|
|
59
59
|
providerAccountId: z.ZodString;
|
|
@@ -396,9 +396,9 @@ declare class ConnectRepository extends BaseTableRepository<Orm, Schema, Record<
|
|
|
396
396
|
id: string;
|
|
397
397
|
createdAt: Date;
|
|
398
398
|
updatedAt: Date | null;
|
|
399
|
+
expiresAt: Date | null;
|
|
399
400
|
userId: string;
|
|
400
401
|
provider: string;
|
|
401
|
-
expiresAt: Date | null;
|
|
402
402
|
accessToken: string;
|
|
403
403
|
refreshToken: string | null;
|
|
404
404
|
scope: string | null;
|
|
@@ -22,9 +22,9 @@ declare class ConnectService extends BaseService<{
|
|
|
22
22
|
id: string;
|
|
23
23
|
createdAt: Date;
|
|
24
24
|
updatedAt: Date | null;
|
|
25
|
+
expiresAt: Date | null;
|
|
25
26
|
userId: string;
|
|
26
27
|
provider: string;
|
|
27
|
-
expiresAt: Date | null;
|
|
28
28
|
accessToken: string;
|
|
29
29
|
refreshToken: string | null;
|
|
30
30
|
scope: string | null;
|
|
@@ -43,9 +43,9 @@ declare class ConnectService extends BaseService<{
|
|
|
43
43
|
id: string;
|
|
44
44
|
createdAt: Date;
|
|
45
45
|
updatedAt: Date | null;
|
|
46
|
+
expiresAt: Date | null;
|
|
46
47
|
userId: string;
|
|
47
48
|
provider: string;
|
|
48
|
-
expiresAt: Date | null;
|
|
49
49
|
accessToken: string;
|
|
50
50
|
refreshToken: string | null;
|
|
51
51
|
scope: string | null;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BaseService } from "../base/base.service.mjs";
|
|
2
2
|
import { err, ok } from "neverthrow";
|
|
3
3
|
import { v4 } from "uuid";
|
|
4
|
-
import { createWriteStream } from "node:fs";
|
|
5
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
4
|
import path, { dirname } from "node:path";
|
|
7
5
|
import { fileTypes } from "@m5kdev/commons/modules/file/file.constants";
|
|
6
|
+
import { createWriteStream } from "node:fs";
|
|
7
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
8
8
|
import { tmpdir } from "node:os";
|
|
9
9
|
import { Readable } from "node:stream";
|
|
10
10
|
import { pipeline } from "node:stream/promises";
|
|
@@ -18,7 +18,7 @@ declare class RecurrenceService extends BaseService<{
|
|
|
18
18
|
filters?: {
|
|
19
19
|
columnId: string;
|
|
20
20
|
type: "string" | "number" | "boolean" | "date" | "enum";
|
|
21
|
-
method: "contains" | "
|
|
21
|
+
method: "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
|
|
22
22
|
value: string | number | boolean | string[];
|
|
23
23
|
valueTo?: string | undefined;
|
|
24
24
|
endColumnId?: string | undefined;
|
|
@@ -29,12 +29,12 @@ declare class RecurrenceService extends BaseService<{
|
|
|
29
29
|
actor: UserActor;
|
|
30
30
|
}, {
|
|
31
31
|
rows: {
|
|
32
|
-
id: string;
|
|
33
32
|
name: string | null;
|
|
33
|
+
id: string;
|
|
34
34
|
createdAt: Date;
|
|
35
35
|
updatedAt: Date;
|
|
36
|
-
metadata: Record<string, any> | null;
|
|
37
36
|
userId: string | null;
|
|
37
|
+
metadata: Record<string, any> | null;
|
|
38
38
|
organizationId: string | null;
|
|
39
39
|
teamId: string | null;
|
|
40
40
|
enabled: boolean;
|
|
@@ -47,8 +47,8 @@ declare class RecurrenceService extends BaseService<{
|
|
|
47
47
|
kind: string;
|
|
48
48
|
enabled: boolean;
|
|
49
49
|
recurrenceRules: {
|
|
50
|
-
freq: number;
|
|
51
50
|
interval: number;
|
|
51
|
+
freq: number;
|
|
52
52
|
bysetpos?: number | number[] | null | undefined;
|
|
53
53
|
bymonth?: number | number[] | null | undefined;
|
|
54
54
|
bymonthday?: number | number[] | null | undefined;
|
|
@@ -21,7 +21,7 @@ declare function createRecurrenceTRPC({
|
|
|
21
21
|
filters?: {
|
|
22
22
|
columnId: string;
|
|
23
23
|
type: "string" | "number" | "boolean" | "date" | "enum";
|
|
24
|
-
method: "contains" | "
|
|
24
|
+
method: "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
|
|
25
25
|
value: string | number | boolean | string[];
|
|
26
26
|
valueTo?: string | undefined;
|
|
27
27
|
endColumnId?: string | undefined;
|
|
@@ -50,8 +50,8 @@ declare function createRecurrenceTRPC({
|
|
|
50
50
|
kind: string;
|
|
51
51
|
enabled: boolean;
|
|
52
52
|
recurrenceRules: {
|
|
53
|
-
freq: number;
|
|
54
53
|
interval: number;
|
|
54
|
+
freq: number;
|
|
55
55
|
bysetpos?: number | number[] | null | undefined;
|
|
56
56
|
bymonth?: number | number[] | null | undefined;
|
|
57
57
|
bymonthday?: number | number[] | null | undefined;
|
|
@@ -150,8 +150,8 @@ declare function createRecurrenceTRPC({
|
|
|
150
150
|
updateRule: _$_trpc_server0.TRPCMutationProcedure<{
|
|
151
151
|
input: {
|
|
152
152
|
id: string;
|
|
153
|
-
freq: number;
|
|
154
153
|
interval: number;
|
|
154
|
+
freq: number;
|
|
155
155
|
bysetpos?: number | number[] | null | undefined;
|
|
156
156
|
bymonth?: number | number[] | null | undefined;
|
|
157
157
|
bymonthday?: number | number[] | null | undefined;
|
|
@@ -21,7 +21,7 @@ declare function createTagTRPC({
|
|
|
21
21
|
filters?: {
|
|
22
22
|
columnId: string;
|
|
23
23
|
type: "string" | "number" | "boolean" | "date" | "enum";
|
|
24
|
-
method: "contains" | "
|
|
24
|
+
method: "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
|
|
25
25
|
value: string | number | boolean | string[];
|
|
26
26
|
valueTo?: string | undefined;
|
|
27
27
|
endColumnId?: string | undefined;
|
|
@@ -54,7 +54,7 @@ declare function createTagTRPC({
|
|
|
54
54
|
resourceIds?: {
|
|
55
55
|
columnId: string;
|
|
56
56
|
type: "string" | "number" | "boolean" | "date" | "enum";
|
|
57
|
-
method: "contains" | "
|
|
57
|
+
method: "contains" | "equals" | "starts_with" | "ends_with" | "greater_than" | "less_than" | "on" | "between" | "before" | "after" | "oneOf" | "intersect" | "isEmpty" | "isNotEmpty" | "is_null" | "is_not_null";
|
|
58
58
|
value: string | number | boolean | string[];
|
|
59
59
|
valueTo?: string | undefined;
|
|
60
60
|
endColumnId?: string | undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseService } from "../base/base.service.mjs";
|
|
2
2
|
import { err, ok } from "neverthrow";
|
|
3
3
|
import { v4 } from "uuid";
|
|
4
|
-
import { closeSync, existsSync, mkdirSync, openSync } from "node:fs";
|
|
5
4
|
import path from "node:path";
|
|
5
|
+
import { closeSync, existsSync, mkdirSync, openSync } from "node:fs";
|
|
6
6
|
import ffbin from "ffmpeg-ffprobe-static";
|
|
7
7
|
import ffmpeg from "fluent-ffmpeg";
|
|
8
8
|
//#region src/modules/video/video.service.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m5kdev/backend",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.6",
|
|
4
4
|
"description": "Composable Express server stack with Drizzle ORM and tRPC.",
|
|
5
5
|
"license": "GPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"trpc-to-openapi": "2.3.0",
|
|
60
60
|
"uuid": "11.0.5",
|
|
61
61
|
"zod": "4.2.1",
|
|
62
|
-
"@m5kdev/commons": "0.8.
|
|
63
|
-
"@m5kdev/config": "0.8.
|
|
62
|
+
"@m5kdev/commons": "0.8.6",
|
|
63
|
+
"@m5kdev/config": "0.8.6"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@jest/globals": "30.2.0",
|