joye-backend-utility 8.1.9 → 8.2.0

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/database.js CHANGED
@@ -56,6 +56,7 @@ class database {
56
56
  con.model('User_Profile', schema_1.UserProfileSchema);
57
57
  con.model('AI_Responses_Tracking', schema_1.AIResponsesTrackingSchema);
58
58
  con.model('User_Analytic', schema_1.UserAnalyticSchema);
59
+ con.model('Llm_Batch_Job', schema_1.LlmBatchJobSchema);
59
60
  con.model('AI_Prompts', schema_1.AIPromptsSchema);
60
61
  con.model('Page_View', schema_1.PageViewSchema);
61
62
  con.model('Error_Log', schema_1.ErrorLogSchema);
package/dist/index.d.ts CHANGED
@@ -5,3 +5,5 @@ export { createToken, jwtVerify } from './jwt';
5
5
  export { getPreviousWorkday, get2ndLastPreviousWorkday, addDays, addMinutes, addYears, getCurrentDateTime, getCurrentUtcTime, newDate, getDatesBetweenRange, getMoment, getCurrentEpoch, } from './dateTime';
6
6
  export { RedisClient } from './redisClient';
7
7
  export { hasDailySuggestionFlag } from './userAnalytic';
8
+ export { LlmBatchJobSchema, LLM_BATCH_IN_PROGRESS_ITEM_STATUSES } from './schema/llm_batch_job';
9
+ export type { LlmBatchItemStatus, LlmBatchJobStatus, LlmBatchProvider } from './schema/llm_batch_job';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasDailySuggestionFlag = exports.RedisClient = exports.getCurrentEpoch = exports.getMoment = exports.getDatesBetweenRange = exports.newDate = exports.getCurrentUtcTime = exports.getCurrentDateTime = exports.addYears = exports.addMinutes = exports.addDays = exports.get2ndLastPreviousWorkday = exports.getPreviousWorkday = exports.jwtVerify = exports.createToken = exports.createUuid = exports.createHashPassword = void 0;
3
+ exports.LLM_BATCH_IN_PROGRESS_ITEM_STATUSES = exports.LlmBatchJobSchema = exports.hasDailySuggestionFlag = exports.RedisClient = exports.getCurrentEpoch = exports.getMoment = exports.getDatesBetweenRange = exports.newDate = exports.getCurrentUtcTime = exports.getCurrentDateTime = exports.addYears = exports.addMinutes = exports.addDays = exports.get2ndLastPreviousWorkday = exports.getPreviousWorkday = exports.jwtVerify = exports.createToken = exports.createUuid = exports.createHashPassword = void 0;
4
4
  const database_1 = require("./database");
5
5
  exports.default = database_1.default;
6
6
  var util_1 = require("./util");
@@ -26,3 +26,6 @@ var redisClient_1 = require("./redisClient");
26
26
  Object.defineProperty(exports, "RedisClient", { enumerable: true, get: function () { return redisClient_1.RedisClient; } });
27
27
  var userAnalytic_1 = require("./userAnalytic");
28
28
  Object.defineProperty(exports, "hasDailySuggestionFlag", { enumerable: true, get: function () { return userAnalytic_1.hasDailySuggestionFlag; } });
29
+ var llm_batch_job_1 = require("./schema/llm_batch_job");
30
+ Object.defineProperty(exports, "LlmBatchJobSchema", { enumerable: true, get: function () { return llm_batch_job_1.LlmBatchJobSchema; } });
31
+ Object.defineProperty(exports, "LLM_BATCH_IN_PROGRESS_ITEM_STATUSES", { enumerable: true, get: function () { return llm_batch_job_1.LLM_BATCH_IN_PROGRESS_ITEM_STATUSES; } });
@@ -47,6 +47,7 @@ export { UserChatSessionSchema } from './userChatSession';
47
47
  export { UserProfileSchema } from './userProfile';
48
48
  export { AIResponsesTrackingSchema } from './ai_responses_tracking';
49
49
  export { UserAnalyticSchema } from './user_analytic';
50
+ export { LlmBatchJobSchema } from './llm_batch_job';
50
51
  export { AIPromptsSchema } from './ai_prompts';
51
52
  export { PageViewSchema } from './pageView';
52
53
  export { ErrorLogSchema } from './errorLog';
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AIPromptsSchema = exports.UserAnalyticSchema = exports.AIResponsesTrackingSchema = exports.UserProfileSchema = exports.UserChatSessionSchema = exports.FeatureFeedbackSchema = exports.UserWeekActivitySchema = exports.UserTrainingRemindersSchema = exports.UserTrainingDailyDataSchema = exports.MasterTrainingDaysSchema = exports.UserTrainingWeekDataSchema = exports.UserTrainingDataSchema = exports.MasterTrainingWeekSchema = exports.MasterTrainingSchema = exports.userJoyLevelQaSchema = exports.userGoalSchema = exports.OrganizationUserAttrPermissionSchema = exports.TimezoneSchema = exports.UserVideoSchema = exports.UserFeedbackSchema = exports.UserReminderSchema = exports.MasterLinkCardSchema = exports.UserRecommendationSchema = exports.MasterSuggestionsParameterSchema = exports.MasterSuggestionsMessageSchema = exports.MasterBlessingsDataSchema = exports.MasterVideoSchema = exports.DatabaseInfoSchema = exports.UserSchema = exports.UserNotificationLogSchema = exports.UserMessageLogSchema = exports.UserMessageSchema = exports.UserMeetingSchema = exports.UserLogSchema = exports.PlatformSchema = exports.OrganizationAnalyticsSchema = exports.OrganizationSchema = exports.MasterThemeMessageSchema = exports.MasterThemeDataSchema = exports.MasterPredictionEmotionsMessageMappingSchema = exports.MasterPredictionEmotionMessageSchema = exports.MasterPredictionEmotionSchema = exports.MasterPodcastSchema = exports.MasterEmotionMessageTypeThemeMappingSchema = exports.MasterEmotionsMessageMappingSchemaV2 = exports.MasterEmotionsMessageMappingSchema = exports.MasterEmotionsSchema = exports.MasterDataSchema = exports.MasterAppSettingSchema = exports.BrewSchema = void 0;
4
- exports.UserEmotionalHealthDetailSchema = exports.UserEmotionalHealthSchema = exports.UserWellbeingDataSchema = exports.UserSuperPowerDataSchema = exports.MasterSuperPowerRuleSchema = exports.MasterSuperPowerDataSchema = exports.MasterEmotionalHealthSchema = exports.MasterEmotionalDriverSchema = exports.MasterEmotionsSchemaV2 = exports.ErrorLogSchema = exports.PageViewSchema = void 0;
3
+ exports.LlmBatchJobSchema = exports.UserAnalyticSchema = exports.AIResponsesTrackingSchema = exports.UserProfileSchema = exports.UserChatSessionSchema = exports.FeatureFeedbackSchema = exports.UserWeekActivitySchema = exports.UserTrainingRemindersSchema = exports.UserTrainingDailyDataSchema = exports.MasterTrainingDaysSchema = exports.UserTrainingWeekDataSchema = exports.UserTrainingDataSchema = exports.MasterTrainingWeekSchema = exports.MasterTrainingSchema = exports.userJoyLevelQaSchema = exports.userGoalSchema = exports.OrganizationUserAttrPermissionSchema = exports.TimezoneSchema = exports.UserVideoSchema = exports.UserFeedbackSchema = exports.UserReminderSchema = exports.MasterLinkCardSchema = exports.UserRecommendationSchema = exports.MasterSuggestionsParameterSchema = exports.MasterSuggestionsMessageSchema = exports.MasterBlessingsDataSchema = exports.MasterVideoSchema = exports.DatabaseInfoSchema = exports.UserSchema = exports.UserNotificationLogSchema = exports.UserMessageLogSchema = exports.UserMessageSchema = exports.UserMeetingSchema = exports.UserLogSchema = exports.PlatformSchema = exports.OrganizationAnalyticsSchema = exports.OrganizationSchema = exports.MasterThemeMessageSchema = exports.MasterThemeDataSchema = exports.MasterPredictionEmotionsMessageMappingSchema = exports.MasterPredictionEmotionMessageSchema = exports.MasterPredictionEmotionSchema = exports.MasterPodcastSchema = exports.MasterEmotionMessageTypeThemeMappingSchema = exports.MasterEmotionsMessageMappingSchemaV2 = exports.MasterEmotionsMessageMappingSchema = exports.MasterEmotionsSchema = exports.MasterDataSchema = exports.MasterAppSettingSchema = exports.BrewSchema = void 0;
4
+ exports.UserEmotionalHealthDetailSchema = exports.UserEmotionalHealthSchema = exports.UserWellbeingDataSchema = exports.UserSuperPowerDataSchema = exports.MasterSuperPowerRuleSchema = exports.MasterSuperPowerDataSchema = exports.MasterEmotionalHealthSchema = exports.MasterEmotionalDriverSchema = exports.MasterEmotionsSchemaV2 = exports.ErrorLogSchema = exports.PageViewSchema = exports.AIPromptsSchema = void 0;
5
5
  var brew_1 = require("./brew");
6
6
  Object.defineProperty(exports, "BrewSchema", { enumerable: true, get: function () { return brew_1.BrewSchema; } });
7
7
  var masterAppSetting_1 = require("./masterAppSetting");
@@ -100,6 +100,8 @@ var ai_responses_tracking_1 = require("./ai_responses_tracking");
100
100
  Object.defineProperty(exports, "AIResponsesTrackingSchema", { enumerable: true, get: function () { return ai_responses_tracking_1.AIResponsesTrackingSchema; } });
101
101
  var user_analytic_1 = require("./user_analytic");
102
102
  Object.defineProperty(exports, "UserAnalyticSchema", { enumerable: true, get: function () { return user_analytic_1.UserAnalyticSchema; } });
103
+ var llm_batch_job_1 = require("./llm_batch_job");
104
+ Object.defineProperty(exports, "LlmBatchJobSchema", { enumerable: true, get: function () { return llm_batch_job_1.LlmBatchJobSchema; } });
103
105
  var ai_prompts_1 = require("./ai_prompts");
104
106
  Object.defineProperty(exports, "AIPromptsSchema", { enumerable: true, get: function () { return ai_prompts_1.AIPromptsSchema; } });
105
107
  var pageView_1 = require("./pageView");
@@ -0,0 +1,13 @@
1
+ import { Schema } from 'mongoose';
2
+ /**
3
+ * Provider-neutral LLM batch job store (Gemini Batch today; Claude Message Batches later).
4
+ * Collection / model name: `Llm_Batch_Job`
5
+ */
6
+ /** Item-level statuses for one request inside an LLM batch job. */
7
+ export declare type LlmBatchItemStatus = 'queued' | 'submitted' | 'succeeded' | 'failed' | 'timed_out' | 'fallback_sync' | 'fallback_local';
8
+ /** Job-level statuses on `Llm_Batch_Job`. */
9
+ export declare type LlmBatchJobStatus = 'open' | 'submitted' | 'succeeded' | 'failed' | 'timed_out' | 'cancelled';
10
+ /** LLM vendor for this batch — keep jobs isolated across providers. */
11
+ export declare type LlmBatchProvider = 'gemini' | 'claude';
12
+ export declare const LLM_BATCH_IN_PROGRESS_ITEM_STATUSES: LlmBatchItemStatus[];
13
+ export declare const LlmBatchJobSchema: Schema<import("mongoose").Document<any, any, any>, import("mongoose").Model<import("mongoose").Document<any, any, any>, any, any>, undefined, {}>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LlmBatchJobSchema = exports.LLM_BATCH_IN_PROGRESS_ITEM_STATUSES = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ exports.LLM_BATCH_IN_PROGRESS_ITEM_STATUSES = ['queued', 'submitted'];
6
+ const LlmBatchJobItemSchema = new mongoose_1.Schema({
7
+ key: { type: String, required: true },
8
+ analyticsId: { type: String, required: true, index: true },
9
+ employeeId: { type: String, required: true },
10
+ period: { type: String, required: true },
11
+ date: { type: String, required: true },
12
+ bucket: { type: Number, required: false },
13
+ status: { type: String, required: true, default: 'queued' },
14
+ error: { type: String, required: false },
15
+ /** Provider-specific request payload (GenerateContent / Messages batch body). */
16
+ request: { type: mongoose_1.Schema.Types.Mixed, required: true },
17
+ }, { _id: false });
18
+ exports.LlmBatchJobSchema = new mongoose_1.Schema({
19
+ /** `gemini` | `claude` — required so providers never share an open job. */
20
+ provider: {
21
+ type: String,
22
+ required: true,
23
+ index: true,
24
+ },
25
+ /** Optional feature/purpose tag, e.g. `databricks-analytics`. */
26
+ purpose: {
27
+ type: String,
28
+ required: false,
29
+ index: true,
30
+ },
31
+ /** Remote provider job id/name (e.g. Gemini `batches/...`). */
32
+ batchName: { type: String, required: false, index: true },
33
+ displayName: { type: String, required: true },
34
+ state: { type: String, required: true, default: 'open', index: true },
35
+ /** Model id used for the batch (e.g. gemini-3.5-flash-lite / claude-sonnet-4-6). */
36
+ model: { type: String, required: false },
37
+ createdAt: { type: Number, required: true },
38
+ submittedAt: { type: Number, required: false },
39
+ completedAt: { type: Number, required: false },
40
+ lastPolledAt: { type: Number, required: false },
41
+ requestCount: { type: Number, required: false, default: 0 },
42
+ items: { type: [LlmBatchJobItemSchema], default: [] },
43
+ });
44
+ exports.LlmBatchJobSchema.index({ 'items.analyticsId': 1, 'items.status': 1 });
45
+ exports.LlmBatchJobSchema.index({ provider: 1, state: 1, createdAt: -1 });
46
+ exports.LlmBatchJobSchema.index({ provider: 1, purpose: 1, state: 1 });
@@ -142,11 +142,29 @@ const UserAnalytic = new mongoose_1.Schema({
142
142
  type: Boolean,
143
143
  required: false,
144
144
  },
145
- /** Claude model used for weekly insights generation (Databricks cron). */
145
+ /** Claude/Gemini model used for weekly insights generation (Databricks cron). */
146
146
  model: {
147
147
  type: String,
148
148
  required: false,
149
149
  },
150
+ /** How AI insights were produced: batch | sync | fallback-local */
151
+ aiInsightsSource: {
152
+ type: String,
153
+ required: false,
154
+ },
155
+ /** Set when batch path failed/timed out and sync/fallback was used. */
156
+ aiInsightsBatchError: {
157
+ type: String,
158
+ required: false,
159
+ },
160
+ aiInsightsBatchKey: {
161
+ type: String,
162
+ required: false,
163
+ },
164
+ aiInsightsBatchName: {
165
+ type: String,
166
+ required: false,
167
+ },
150
168
  inputToken: {
151
169
  type: Number,
152
170
  required: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joye-backend-utility",
3
- "version": "8.1.9",
3
+ "version": "8.2.0",
4
4
  "description": "Joye backend utility for db functions and common functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",