eggi-ai-db-schema-2 0.1.1

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.
Files changed (188) hide show
  1. package/CHANGELOG.md +750 -0
  2. package/README.md +660 -0
  3. package/dist/config/database.d.ts +28 -0
  4. package/dist/config/database.d.ts.map +1 -0
  5. package/dist/config/database.js +72 -0
  6. package/dist/config/database.js.map +1 -0
  7. package/dist/index.d.ts +28 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +199 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/lib/database-service.d.ts +714 -0
  12. package/dist/lib/database-service.d.ts.map +1 -0
  13. package/dist/lib/database-service.js +1394 -0
  14. package/dist/lib/database-service.js.map +1 -0
  15. package/dist/lib/db-types.d.ts +167 -0
  16. package/dist/lib/db-types.d.ts.map +1 -0
  17. package/dist/lib/db-types.js +28 -0
  18. package/dist/lib/db-types.js.map +1 -0
  19. package/dist/lib/db.d.ts +58 -0
  20. package/dist/lib/db.d.ts.map +1 -0
  21. package/dist/lib/db.js +292 -0
  22. package/dist/lib/db.js.map +1 -0
  23. package/dist/lib/index.d.ts +11 -0
  24. package/dist/lib/index.d.ts.map +1 -0
  25. package/dist/lib/index.js +26 -0
  26. package/dist/lib/index.js.map +1 -0
  27. package/dist/lib/pg-client.d.ts +50 -0
  28. package/dist/lib/pg-client.d.ts.map +1 -0
  29. package/dist/lib/pg-client.js +106 -0
  30. package/dist/lib/pg-client.js.map +1 -0
  31. package/dist/lib/schema.d.ts +298 -0
  32. package/dist/lib/schema.d.ts.map +1 -0
  33. package/dist/lib/schema.js +12 -0
  34. package/dist/lib/schema.js.map +1 -0
  35. package/dist/migration-manager.d.ts +49 -0
  36. package/dist/migration-manager.d.ts.map +1 -0
  37. package/dist/migration-manager.js +282 -0
  38. package/dist/migration-manager.js.map +1 -0
  39. package/dist/queries/minimal-connections.d.ts +31 -0
  40. package/dist/queries/minimal-connections.d.ts.map +1 -0
  41. package/dist/queries/minimal-connections.js +143 -0
  42. package/dist/queries/minimal-connections.js.map +1 -0
  43. package/dist/schema.ts +340 -0
  44. package/dist/seed.d.ts +8 -0
  45. package/dist/seed.d.ts.map +1 -0
  46. package/dist/seed.js +40 -0
  47. package/dist/seed.js.map +1 -0
  48. package/dist/types/index.d.ts +7 -0
  49. package/dist/types/index.d.ts.map +1 -0
  50. package/dist/types/index.js +23 -0
  51. package/dist/types/index.js.map +1 -0
  52. package/dist/types/types.d.ts +77 -0
  53. package/dist/types/types.d.ts.map +1 -0
  54. package/dist/types/types.js +3 -0
  55. package/dist/types/types.js.map +1 -0
  56. package/dist/utils/authenticated-user-operations.d.ts +110 -0
  57. package/dist/utils/authenticated-user-operations.d.ts.map +1 -0
  58. package/dist/utils/authenticated-user-operations.js +292 -0
  59. package/dist/utils/authenticated-user-operations.js.map +1 -0
  60. package/dist/utils/authentication-operations.d.ts +48 -0
  61. package/dist/utils/authentication-operations.d.ts.map +1 -0
  62. package/dist/utils/authentication-operations.js +172 -0
  63. package/dist/utils/authentication-operations.js.map +1 -0
  64. package/dist/utils/company-mapping-job-operations.d.ts +103 -0
  65. package/dist/utils/company-mapping-job-operations.d.ts.map +1 -0
  66. package/dist/utils/company-mapping-job-operations.js +413 -0
  67. package/dist/utils/company-mapping-job-operations.js.map +1 -0
  68. package/dist/utils/company-sheet-upload-operations.d.ts +53 -0
  69. package/dist/utils/company-sheet-upload-operations.d.ts.map +1 -0
  70. package/dist/utils/company-sheet-upload-operations.js +135 -0
  71. package/dist/utils/company-sheet-upload-operations.js.map +1 -0
  72. package/dist/utils/contact-operations.d.ts +70 -0
  73. package/dist/utils/contact-operations.d.ts.map +1 -0
  74. package/dist/utils/contact-operations.js +294 -0
  75. package/dist/utils/contact-operations.js.map +1 -0
  76. package/dist/utils/forager-linkedin-operations.d.ts +74 -0
  77. package/dist/utils/forager-linkedin-operations.d.ts.map +1 -0
  78. package/dist/utils/forager-linkedin-operations.js +778 -0
  79. package/dist/utils/forager-linkedin-operations.js.map +1 -0
  80. package/dist/utils/ghost-genius-linkedin-operations.d.ts +23 -0
  81. package/dist/utils/ghost-genius-linkedin-operations.d.ts.map +1 -0
  82. package/dist/utils/ghost-genius-linkedin-operations.js +282 -0
  83. package/dist/utils/ghost-genius-linkedin-operations.js.map +1 -0
  84. package/dist/utils/index.d.ts +29 -0
  85. package/dist/utils/index.d.ts.map +1 -0
  86. package/dist/utils/index.js +77 -0
  87. package/dist/utils/index.js.map +1 -0
  88. package/dist/utils/introduction-request-operations.d.ts +160 -0
  89. package/dist/utils/introduction-request-operations.d.ts.map +1 -0
  90. package/dist/utils/introduction-request-operations.js +492 -0
  91. package/dist/utils/introduction-request-operations.js.map +1 -0
  92. package/dist/utils/invitation-operations.d.ts +141 -0
  93. package/dist/utils/invitation-operations.d.ts.map +1 -0
  94. package/dist/utils/invitation-operations.js +749 -0
  95. package/dist/utils/invitation-operations.js.map +1 -0
  96. package/dist/utils/linkedin-account-operations.d.ts +45 -0
  97. package/dist/utils/linkedin-account-operations.d.ts.map +1 -0
  98. package/dist/utils/linkedin-account-operations.js +279 -0
  99. package/dist/utils/linkedin-account-operations.js.map +1 -0
  100. package/dist/utils/linkedin-account-relationship-operations.d.ts +77 -0
  101. package/dist/utils/linkedin-account-relationship-operations.d.ts.map +1 -0
  102. package/dist/utils/linkedin-account-relationship-operations.js +274 -0
  103. package/dist/utils/linkedin-account-relationship-operations.js.map +1 -0
  104. package/dist/utils/linkedin-data-operations.d.ts +102 -0
  105. package/dist/utils/linkedin-data-operations.d.ts.map +1 -0
  106. package/dist/utils/linkedin-data-operations.js +613 -0
  107. package/dist/utils/linkedin-data-operations.js.map +1 -0
  108. package/dist/utils/linkedin-identifier-utils.d.ts +31 -0
  109. package/dist/utils/linkedin-identifier-utils.d.ts.map +1 -0
  110. package/dist/utils/linkedin-identifier-utils.js +63 -0
  111. package/dist/utils/linkedin-identifier-utils.js.map +1 -0
  112. package/dist/utils/linkedin-profile-cache.d.ts +131 -0
  113. package/dist/utils/linkedin-profile-cache.d.ts.map +1 -0
  114. package/dist/utils/linkedin-profile-cache.js +418 -0
  115. package/dist/utils/linkedin-profile-cache.js.map +1 -0
  116. package/dist/utils/llm-inference-job-operations.d.ts +116 -0
  117. package/dist/utils/llm-inference-job-operations.d.ts.map +1 -0
  118. package/dist/utils/llm-inference-job-operations.js +267 -0
  119. package/dist/utils/llm-inference-job-operations.js.map +1 -0
  120. package/dist/utils/mapping-job-operations.d.ts +272 -0
  121. package/dist/utils/mapping-job-operations.d.ts.map +1 -0
  122. package/dist/utils/mapping-job-operations.js +833 -0
  123. package/dist/utils/mapping-job-operations.js.map +1 -0
  124. package/dist/utils/mapping-operations.d.ts +80 -0
  125. package/dist/utils/mapping-operations.d.ts.map +1 -0
  126. package/dist/utils/mapping-operations.js +318 -0
  127. package/dist/utils/mapping-operations.js.map +1 -0
  128. package/dist/utils/on-demand-mapping-operations.d.ts +199 -0
  129. package/dist/utils/on-demand-mapping-operations.d.ts.map +1 -0
  130. package/dist/utils/on-demand-mapping-operations.js +728 -0
  131. package/dist/utils/on-demand-mapping-operations.js.map +1 -0
  132. package/dist/utils/onboarding-operations.d.ts +53 -0
  133. package/dist/utils/onboarding-operations.d.ts.map +1 -0
  134. package/dist/utils/onboarding-operations.js +223 -0
  135. package/dist/utils/onboarding-operations.js.map +1 -0
  136. package/dist/utils/organization-assignment-job-operations.d.ts +258 -0
  137. package/dist/utils/organization-assignment-job-operations.d.ts.map +1 -0
  138. package/dist/utils/organization-assignment-job-operations.js +881 -0
  139. package/dist/utils/organization-assignment-job-operations.js.map +1 -0
  140. package/dist/utils/organization-assignment-operations.d.ts +59 -0
  141. package/dist/utils/organization-assignment-operations.d.ts.map +1 -0
  142. package/dist/utils/organization-assignment-operations.js +130 -0
  143. package/dist/utils/organization-assignment-operations.js.map +1 -0
  144. package/dist/utils/organization-operations.d.ts +284 -0
  145. package/dist/utils/organization-operations.d.ts.map +1 -0
  146. package/dist/utils/organization-operations.js +1030 -0
  147. package/dist/utils/organization-operations.js.map +1 -0
  148. package/dist/utils/organization-relationship-operations.d.ts +79 -0
  149. package/dist/utils/organization-relationship-operations.d.ts.map +1 -0
  150. package/dist/utils/organization-relationship-operations.js +294 -0
  151. package/dist/utils/organization-relationship-operations.js.map +1 -0
  152. package/dist/utils/quota-operations.d.ts +107 -0
  153. package/dist/utils/quota-operations.d.ts.map +1 -0
  154. package/dist/utils/quota-operations.js +692 -0
  155. package/dist/utils/quota-operations.js.map +1 -0
  156. package/dist/utils/recursive-mapping-job-operations.d.ts +42 -0
  157. package/dist/utils/recursive-mapping-job-operations.d.ts.map +1 -0
  158. package/dist/utils/recursive-mapping-job-operations.js +169 -0
  159. package/dist/utils/recursive-mapping-job-operations.js.map +1 -0
  160. package/dist/utils/relationship-operations.d.ts +130 -0
  161. package/dist/utils/relationship-operations.d.ts.map +1 -0
  162. package/dist/utils/relationship-operations.js +329 -0
  163. package/dist/utils/relationship-operations.js.map +1 -0
  164. package/dist/utils/sales-pipeline-operations.d.ts +163 -0
  165. package/dist/utils/sales-pipeline-operations.d.ts.map +1 -0
  166. package/dist/utils/sales-pipeline-operations.js +725 -0
  167. package/dist/utils/sales-pipeline-operations.js.map +1 -0
  168. package/dist/utils/skills-operations.d.ts +117 -0
  169. package/dist/utils/skills-operations.d.ts.map +1 -0
  170. package/dist/utils/skills-operations.js +487 -0
  171. package/dist/utils/skills-operations.js.map +1 -0
  172. package/dist/utils/subscription-operations.d.ts +123 -0
  173. package/dist/utils/subscription-operations.d.ts.map +1 -0
  174. package/dist/utils/subscription-operations.js +391 -0
  175. package/dist/utils/subscription-operations.js.map +1 -0
  176. package/dist/utils/unipile-account-operations.d.ts +96 -0
  177. package/dist/utils/unipile-account-operations.d.ts.map +1 -0
  178. package/dist/utils/unipile-account-operations.js +255 -0
  179. package/dist/utils/unipile-account-operations.js.map +1 -0
  180. package/dist/utils/user-industry-operations.d.ts +80 -0
  181. package/dist/utils/user-industry-operations.d.ts.map +1 -0
  182. package/dist/utils/user-industry-operations.js +237 -0
  183. package/dist/utils/user-industry-operations.js.map +1 -0
  184. package/dist/utils/user-operations.d.ts +87 -0
  185. package/dist/utils/user-operations.d.ts.map +1 -0
  186. package/dist/utils/user-operations.js +212 -0
  187. package/dist/utils/user-operations.js.map +1 -0
  188. package/package.json +98 -0
@@ -0,0 +1,116 @@
1
+ /**
2
+ * =============================================================================
3
+ * LLM INFERENCE JOB OPERATIONS - PREPARATION HANDLER ONLY
4
+ * =============================================================================
5
+ * Minimal operations for LLM inference job creation by the preparation handler
6
+ *
7
+ * The Python LLM service writes its own SQL queries for:
8
+ * - Getting job details with context
9
+ * - Updating started_at and completed_at timestamps
10
+ * - Querying job status
11
+ *
12
+ * This file only provides what the Lambda preparation handler needs:
13
+ * - createLlmInferenceJob() - Creates job record after mapping completes
14
+ *
15
+ * USAGE (Preparation Handler):
16
+ * ```typescript
17
+ * import { createLlmInferenceJob } from 'eggi-ai-db-schema-2';
18
+ *
19
+ * // After validating mapping job completion
20
+ * const { llmInferenceJob } = await createLlmInferenceJob(db, {
21
+ * mappingJobId: 12345,
22
+ * jobMetadata: {
23
+ * organization_id: 8,
24
+ * linkedin_identifier: "ACoA...",
25
+ * strategy: "fresh"
26
+ * }
27
+ * });
28
+ *
29
+ * // Publish llmInferenceJob.id to SNS topic
30
+ * await sns.publish({
31
+ * Message: JSON.stringify({
32
+ * llm_inference_job_id: llmInferenceJob.id,
33
+ * metadata: { source: "profile_analysis_completed" }
34
+ * })
35
+ * });
36
+ * ```
37
+ */
38
+ import { Pool, PoolClient } from "pg";
39
+ import type { DatabaseOrTransaction } from "../lib/db";
40
+ import { type LlmInferenceJob } from "../lib/schema";
41
+ /**
42
+ * Creates a new LLM inference job for a completed mapping job
43
+ *
44
+ * @param db - Database connection
45
+ * @param params - Job creation parameters
46
+ * @param params.mappingJobId - The completed mapping job ID
47
+ * @param params.jobMetadata - Optional metadata to store (organization_id, linkedin_identifier, etc.)
48
+ * @returns Created LLM inference job
49
+ *
50
+ * Note: Caller (preparation handler) should validate mapping job exists and is completed
51
+ */
52
+ export declare function createLlmInferenceJob(db: DatabaseOrTransaction | Pool | PoolClient, params: {
53
+ mappingJobId: number;
54
+ jobMetadata?: Record<string, any>;
55
+ }): Promise<{
56
+ llmInferenceJob: LlmInferenceJob;
57
+ }>;
58
+ /**
59
+ * Check LLM inference job status for a mapping job
60
+ *
61
+ * Checks if there's a pending or completed LLM inference job for a given mapping job.
62
+ *
63
+ * @param db - Database connection
64
+ * @param mappingJobId - Mapping job ID to check
65
+ * @returns LLM inference job status or null if no job found
66
+ */
67
+ export declare function getLlmInferenceJobStatusForMappingJob(db: DatabaseOrTransaction | Pool | PoolClient, mappingJobId: number): Promise<{
68
+ status: "pending" | "completed" | "not_found";
69
+ llmInferenceJobId: number | null;
70
+ mappingJobId: number | null;
71
+ createdAt: Date | null;
72
+ startedAt: Date | null;
73
+ completedAt: Date | null;
74
+ } | null>;
75
+ /**
76
+ * Check LLM inference job status for a contributor in an organization
77
+ *
78
+ * Uses organization assignment job to find the mapping job, then checks
79
+ * for LLM inference job status.
80
+ *
81
+ * @param db - Database connection
82
+ * @param params - Query parameters
83
+ * @param params.userId - User ID of the contributor
84
+ * @param params.organizationId - Organization ID
85
+ * @returns LLM inference job status or null if no job found
86
+ */
87
+ export declare function getLlmInferenceJobStatusForContributor(db: DatabaseOrTransaction | Pool | PoolClient, params: {
88
+ userId: number;
89
+ organizationId: number;
90
+ }): Promise<{
91
+ status: "pending" | "completed" | "not_found";
92
+ llmInferenceJobId: number | null;
93
+ mappingJobId: number | null;
94
+ createdAt: Date | null;
95
+ startedAt: Date | null;
96
+ completedAt: Date | null;
97
+ } | null>;
98
+ /**
99
+ * Get LLM inference job statuses for all contributors in an organization
100
+ *
101
+ * Returns a map of user_id -> LLM inference job status for all contributors
102
+ * in the organization. This is more efficient than individual queries.
103
+ *
104
+ * @param db - Database connection
105
+ * @param organizationId - Organization ID
106
+ * @returns Map of user_id to LLM inference job status
107
+ */
108
+ export declare function getAllLlmInferenceJobStatusesForOrganization(db: DatabaseOrTransaction | Pool | PoolClient, organizationId: number): Promise<Record<number, {
109
+ status: "pending" | "completed" | "not_found";
110
+ llmInferenceJobId: number | null;
111
+ mappingJobId: number | null;
112
+ createdAt: Date | null;
113
+ startedAt: Date | null;
114
+ completedAt: Date | null;
115
+ }>>;
116
+ //# sourceMappingURL=llm-inference-job-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-inference-job-operations.d.ts","sourceRoot":"","sources":["../../src/utils/llm-inference-job-operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEtC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAIrD;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CACzC,EAAE,EAAE,qBAAqB,GAAG,IAAI,GAAG,UAAU,EAC7C,MAAM,EAAE;IACN,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACnC,GACA,OAAO,CAAC;IAAE,eAAe,EAAE,eAAe,CAAA;CAAE,CAAC,CAqC/C;AAED;;;;;;;;GAQG;AACH,wBAAsB,qCAAqC,CACzD,EAAE,EAAE,qBAAqB,GAAG,IAAI,GAAG,UAAU,EAC7C,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;IACT,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;IAC9C,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;CAC1B,GAAG,IAAI,CAAC,CA2DR;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,sCAAsC,CAC1D,EAAE,EAAE,qBAAqB,GAAG,IAAI,GAAG,UAAU,EAC7C,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;CACxB,GACA,OAAO,CAAC;IACT,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;IAC9C,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;CAC1B,GAAG,IAAI,CAAC,CAwCR;AAED;;;;;;;;;GASG;AACH,wBAAsB,4CAA4C,CAChE,EAAE,EAAE,qBAAqB,GAAG,IAAI,GAAG,UAAU,EAC7C,cAAc,EAAE,MAAM,GACrB,OAAO,CACR,MAAM,CACJ,MAAM,EACN;IACE,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;IAC9C,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;CAC1B,CACF,CACF,CAgGA"}
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ /**
3
+ * =============================================================================
4
+ * LLM INFERENCE JOB OPERATIONS - PREPARATION HANDLER ONLY
5
+ * =============================================================================
6
+ * Minimal operations for LLM inference job creation by the preparation handler
7
+ *
8
+ * The Python LLM service writes its own SQL queries for:
9
+ * - Getting job details with context
10
+ * - Updating started_at and completed_at timestamps
11
+ * - Querying job status
12
+ *
13
+ * This file only provides what the Lambda preparation handler needs:
14
+ * - createLlmInferenceJob() - Creates job record after mapping completes
15
+ *
16
+ * USAGE (Preparation Handler):
17
+ * ```typescript
18
+ * import { createLlmInferenceJob } from 'eggi-ai-db-schema-2';
19
+ *
20
+ * // After validating mapping job completion
21
+ * const { llmInferenceJob } = await createLlmInferenceJob(db, {
22
+ * mappingJobId: 12345,
23
+ * jobMetadata: {
24
+ * organization_id: 8,
25
+ * linkedin_identifier: "ACoA...",
26
+ * strategy: "fresh"
27
+ * }
28
+ * });
29
+ *
30
+ * // Publish llmInferenceJob.id to SNS topic
31
+ * await sns.publish({
32
+ * Message: JSON.stringify({
33
+ * llm_inference_job_id: llmInferenceJob.id,
34
+ * metadata: { source: "profile_analysis_completed" }
35
+ * })
36
+ * });
37
+ * ```
38
+ */
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.createLlmInferenceJob = createLlmInferenceJob;
41
+ exports.getLlmInferenceJobStatusForMappingJob = getLlmInferenceJobStatusForMappingJob;
42
+ exports.getLlmInferenceJobStatusForContributor = getLlmInferenceJobStatusForContributor;
43
+ exports.getAllLlmInferenceJobStatusesForOrganization = getAllLlmInferenceJobStatusesForOrganization;
44
+ const pg_client_1 = require("../lib/pg-client");
45
+ const db_1 = require("../lib/db");
46
+ const organization_assignment_job_operations_1 = require("./organization-assignment-job-operations");
47
+ /**
48
+ * Creates a new LLM inference job for a completed mapping job
49
+ *
50
+ * @param db - Database connection
51
+ * @param params - Job creation parameters
52
+ * @param params.mappingJobId - The completed mapping job ID
53
+ * @param params.jobMetadata - Optional metadata to store (organization_id, linkedin_identifier, etc.)
54
+ * @returns Created LLM inference job
55
+ *
56
+ * Note: Caller (preparation handler) should validate mapping job exists and is completed
57
+ */
58
+ async function createLlmInferenceJob(db, params) {
59
+ const { mappingJobId, jobMetadata = {} } = params;
60
+ (0, db_1.debugLogDbOperation)("insert", "monitoring.llm_inference_jobs", { mappingJobId, jobMetadata }, undefined, {
61
+ operation: "createLlmInferenceJob",
62
+ mappingJobId,
63
+ });
64
+ const sql = `
65
+ INSERT INTO monitoring.llm_inference_jobs (mapping_job_id, metadata, created_at, queued_at)
66
+ VALUES ($1, $2, NOW(), NOW())
67
+ RETURNING
68
+ id,
69
+ mapping_job_id,
70
+ metadata,
71
+ created_at,
72
+ queued_at,
73
+ started_at,
74
+ completed_at
75
+ `;
76
+ const llmInferenceJob = await (0, pg_client_1.queryOne)(db, sql, [
77
+ mappingJobId,
78
+ JSON.stringify(jobMetadata),
79
+ ]);
80
+ if (!llmInferenceJob) {
81
+ throw new Error("Failed to create LLM inference job");
82
+ }
83
+ return { llmInferenceJob };
84
+ }
85
+ /**
86
+ * Check LLM inference job status for a mapping job
87
+ *
88
+ * Checks if there's a pending or completed LLM inference job for a given mapping job.
89
+ *
90
+ * @param db - Database connection
91
+ * @param mappingJobId - Mapping job ID to check
92
+ * @returns LLM inference job status or null if no job found
93
+ */
94
+ async function getLlmInferenceJobStatusForMappingJob(db, mappingJobId) {
95
+ (0, db_1.debugLogDbOperation)("select", "monitoring.llm_inference_jobs", { mappingJobId }, undefined, {
96
+ operation: "getLlmInferenceJobStatusForMappingJob",
97
+ mappingJobId,
98
+ });
99
+ try {
100
+ // Build query to find LLM inference job for this mapping job
101
+ const sql = `
102
+ SELECT
103
+ id,
104
+ mapping_job_id,
105
+ created_at,
106
+ queued_at,
107
+ started_at,
108
+ completed_at,
109
+ metadata
110
+ FROM monitoring.llm_inference_jobs
111
+ WHERE mapping_job_id = $1
112
+ ORDER BY created_at DESC
113
+ LIMIT 1
114
+ `;
115
+ const llmJob = await (0, pg_client_1.queryOne)(db, sql, [mappingJobId]);
116
+ if (!llmJob) {
117
+ return {
118
+ status: "not_found",
119
+ llmInferenceJobId: null,
120
+ mappingJobId: mappingJobId,
121
+ createdAt: null,
122
+ startedAt: null,
123
+ completedAt: null,
124
+ };
125
+ }
126
+ // Determine status based on completion
127
+ const status = llmJob.completed_at ? "completed" : "pending";
128
+ return {
129
+ status,
130
+ llmInferenceJobId: llmJob.id,
131
+ mappingJobId: llmJob.mapping_job_id,
132
+ createdAt: llmJob.created_at,
133
+ startedAt: llmJob.started_at,
134
+ completedAt: llmJob.completed_at,
135
+ };
136
+ }
137
+ catch (error) {
138
+ console.error("Error getting LLM inference job status:", error);
139
+ return null;
140
+ }
141
+ }
142
+ /**
143
+ * Check LLM inference job status for a contributor in an organization
144
+ *
145
+ * Uses organization assignment job to find the mapping job, then checks
146
+ * for LLM inference job status.
147
+ *
148
+ * @param db - Database connection
149
+ * @param params - Query parameters
150
+ * @param params.userId - User ID of the contributor
151
+ * @param params.organizationId - Organization ID
152
+ * @returns LLM inference job status or null if no job found
153
+ */
154
+ async function getLlmInferenceJobStatusForContributor(db, params) {
155
+ const { userId, organizationId } = params;
156
+ (0, db_1.debugLogDbOperation)("select", "monitoring.llm_inference_jobs", { userId, organizationId }, undefined, {
157
+ operation: "getLlmInferenceJobStatusForContributor",
158
+ userId,
159
+ organizationId,
160
+ });
161
+ try {
162
+ // Get the organization assignment job for this user
163
+ const orgAssignmentJob = await (0, organization_assignment_job_operations_1.getLatestOrganizationAssignmentJobForUser)(db, userId, organizationId);
164
+ if (!orgAssignmentJob) {
165
+ return {
166
+ status: "not_found",
167
+ llmInferenceJobId: null,
168
+ mappingJobId: null,
169
+ createdAt: null,
170
+ startedAt: null,
171
+ completedAt: null,
172
+ };
173
+ }
174
+ // Use the mapping job ID from the organization assignment job
175
+ return await getLlmInferenceJobStatusForMappingJob(db, orgAssignmentJob.mappingJobId);
176
+ }
177
+ catch (error) {
178
+ console.error("Error getting LLM inference job status for contributor:", error);
179
+ return null;
180
+ }
181
+ }
182
+ /**
183
+ * Get LLM inference job statuses for all contributors in an organization
184
+ *
185
+ * Returns a map of user_id -> LLM inference job status for all contributors
186
+ * in the organization. This is more efficient than individual queries.
187
+ *
188
+ * @param db - Database connection
189
+ * @param organizationId - Organization ID
190
+ * @returns Map of user_id to LLM inference job status
191
+ */
192
+ async function getAllLlmInferenceJobStatusesForOrganization(db, organizationId) {
193
+ (0, db_1.debugLogDbOperation)("select", "monitoring.llm_inference_jobs", { organizationId }, undefined, {
194
+ operation: "getAllLlmInferenceJobStatusesForOrganization",
195
+ organizationId,
196
+ });
197
+ try {
198
+ // Single query to get all LLM inference job statuses for all contributors in the organization
199
+ // This joins organization_members (CONTRIBUTOR only) -> organization_assignment_jobs -> mapping_jobs -> llm_inference_jobs
200
+ const sql = `
201
+ WITH latest_org_assignment_jobs AS (
202
+ -- Get the latest organization assignment job for each CONTRIBUTOR in the organization
203
+ SELECT DISTINCT ON (om.user_id)
204
+ om.user_id,
205
+ oaj.mapping_job_id,
206
+ oaj.created_at as org_assignment_created_at
207
+ FROM public.organization_members om
208
+ INNER JOIN monitoring.organization_assignment_jobs oaj
209
+ ON oaj.organization_id = om.organization_id
210
+ INNER JOIN monitoring.mapping_jobs mj
211
+ ON mj.id = oaj.mapping_job_id
212
+ INNER JOIN linkedin.accounts la
213
+ ON la.id = mj.linkedin_account_id
214
+ WHERE om.organization_id = $1
215
+ AND om.contribution_role = 'CONTRIBUTOR'
216
+ AND la.user_id = om.user_id
217
+ ORDER BY om.user_id, oaj.created_at DESC
218
+ ),
219
+ llm_jobs AS (
220
+ -- Get the latest LLM inference job for each mapping job
221
+ SELECT DISTINCT ON (loaj.mapping_job_id)
222
+ loaj.user_id,
223
+ loaj.mapping_job_id,
224
+ lij.id as llm_inference_job_id,
225
+ lij.created_at,
226
+ lij.started_at,
227
+ lij.completed_at
228
+ FROM latest_org_assignment_jobs loaj
229
+ LEFT JOIN monitoring.llm_inference_jobs lij
230
+ ON lij.mapping_job_id = loaj.mapping_job_id
231
+ ORDER BY loaj.mapping_job_id, lij.created_at DESC NULLS LAST
232
+ )
233
+ SELECT
234
+ lj.user_id,
235
+ lj.mapping_job_id,
236
+ lj.llm_inference_job_id,
237
+ lj.created_at,
238
+ lj.started_at,
239
+ lj.completed_at,
240
+ CASE
241
+ WHEN lj.llm_inference_job_id IS NULL THEN 'not_found'
242
+ WHEN lj.completed_at IS NOT NULL THEN 'completed'
243
+ ELSE 'pending'
244
+ END as status
245
+ FROM llm_jobs lj
246
+ `;
247
+ const results = await (0, pg_client_1.query)(db, sql, [organizationId]);
248
+ // Convert to map: user_id -> status object
249
+ const statusMap = {};
250
+ for (const row of results) {
251
+ statusMap[row.user_id] = {
252
+ status: row.status,
253
+ llmInferenceJobId: row.llm_inference_job_id,
254
+ mappingJobId: row.mapping_job_id,
255
+ createdAt: row.created_at,
256
+ startedAt: row.started_at,
257
+ completedAt: row.completed_at,
258
+ };
259
+ }
260
+ return statusMap;
261
+ }
262
+ catch (error) {
263
+ console.error("Error getting all LLM inference job statuses for organization:", error);
264
+ return {};
265
+ }
266
+ }
267
+ //# sourceMappingURL=llm-inference-job-operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-inference-job-operations.js","sourceRoot":"","sources":["../../src/utils/llm-inference-job-operations.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;;AAqBH,sDA2CC;AAWD,sFAqEC;AAcD,wFAqDC;AAYD,oGA+GC;AA3UD,gDAAmD;AAEnD,kCAAgD;AAGhD,qGAAqG;AAErG;;;;;;;;;;GAUG;AACI,KAAK,UAAU,qBAAqB,CACzC,EAA6C,EAC7C,MAGC;IAED,MAAM,EAAE,YAAY,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IAElD,IAAA,wBAAmB,EACjB,QAAQ,EACR,+BAA+B,EAC/B,EAAE,YAAY,EAAE,WAAW,EAAE,EAC7B,SAAS,EACT;QACE,SAAS,EAAE,uBAAuB;QAClC,YAAY;KACb,CACF,CAAC;IAEF,MAAM,GAAG,GAAG;;;;;;;;;;;GAWX,CAAC;IAEF,MAAM,eAAe,GAAG,MAAM,IAAA,oBAAQ,EAAkB,EAAuB,EAAE,GAAG,EA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AAC;QACH,8FAA8F;QAC9F,2HAA2H;QAC3H,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8CX,CAAC;QAEF,MAAM,OAAO,GAAG,MAAM,IAAA,iBAAK,EAQxB,EAAuB,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;QAEnD,2CAA2C;QAC3C,MAAM,SAAS,GAUX,EAAE,CAAC;QAEP,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;YAC1B,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG;gBACvB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,iBAAiB,EAAE,GAAG,CAAC,oBAAoB;gBAC3C,YAAY,EAAE,GAAG,CAAC,cAAc;gBAChC,SAAS,EAAE,GAAG,CAAC,UAAU;gBACzB,SAAS,EAAE,GAAG,CAAC,UAAU;gBACzB,WAAW,EAAE,GAAG,CAAC,YAAY;aAC9B,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,gEAAgE,EAAE,KAAK,CAAC,CAAC;QACvF,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,272 @@
1
+ /**
2
+ * =============================================================================
3
+ * MAPPING JOB OPERATIONS UTILITIES - CONSOLIDATED SCHEMA
4
+ * =============================================================================
5
+ * Utility functions for creating and managing mapping jobs with direct LinkedIn account references
6
+ *
7
+ * USAGE EXAMPLES:
8
+ *
9
+ * 1. SINGLE LINKEDIN ACCOUNT MAPPING JOB:
10
+ * ```typescript
11
+ * const result = await createMappingJobForLinkedInAccount({
12
+ * linkedinAccountId: 123,
13
+ * jobMetadata: {
14
+ * service: "feed_analyzer",
15
+ * triggered_by: "preparation_handler",
16
+ * linkedin_identifier: "ACoAABCDEFG"
17
+ * }
18
+ * });
19
+ * // Creates: 1 job with direct linkedin_account_id reference
20
+ * ```
21
+ *
22
+ * 2. BATCH PROCESSING (Multiple Jobs):
23
+ * ```typescript
24
+ * const results = await createMappingJobsForLinkedInAccounts([
25
+ * { linkedinAccountId: 123, metadata: { priority: "high" } },
26
+ * { linkedinAccountId: 456, metadata: { priority: "normal" } },
27
+ * { linkedinAccountId: 789, metadata: { priority: "low" } }
28
+ * ]);
29
+ * // Creates: 3 separate jobs, each with direct linkedin_account_id reference
30
+ * ```
31
+ *
32
+ * 3. PROCESSING LIFECYCLE:
33
+ * ```typescript
34
+ * // When processing starts
35
+ * await startMappingJob(jobId, {
36
+ * service_version: "v2.1.0",
37
+ * model_version: "gpt-4-turbo",
38
+ * started_by: "mapping_service_lambda"
39
+ * });
40
+ *
41
+ * // When processing completes
42
+ * await completeMappingJob(jobId, {
43
+ * completion_status: "success",
44
+ * processed_items: 150,
45
+ * completion_reason: "all_items_processed"
46
+ * });
47
+ * ```
48
+ */
49
+ import { Pool, PoolClient } from "pg";
50
+ import type { Database, DatabaseOrTransaction } from "../lib/db";
51
+ import { getDb } from "../lib/db";
52
+ import { type MappingJob } from "../lib/schema";
53
+ /**
54
+ * Creates a new mapping job for a single LinkedIn account
55
+ */
56
+ export declare function createMappingJobForLinkedInAccount(db: DatabaseOrTransaction | Pool | PoolClient, params: {
57
+ linkedinAccountId: number;
58
+ jobMetadata?: Record<string, any>;
59
+ companyMappingJobId?: number | null;
60
+ recursiveMappingJobId?: number | null;
61
+ }): Promise<{
62
+ mappingJob: MappingJob;
63
+ }>;
64
+ /**
65
+ * Creates mapping jobs for multiple LinkedIn accounts
66
+ */
67
+ export declare function createMappingJobsForLinkedInAccounts(db: DatabaseOrTransaction | Pool | PoolClient, accountsData: Array<{
68
+ linkedinAccountId: number;
69
+ metadata?: Record<string, any>;
70
+ }>): Promise<{
71
+ mappingJobs: MappingJob[];
72
+ }>;
73
+ /**
74
+ * Start a mapping job (mark as started)
75
+ */
76
+ export declare function startMappingJob(db: DatabaseOrTransaction | Pool | PoolClient, mappingJobId: number, startMetadata?: Record<string, any>): Promise<MappingJob>;
77
+ /**
78
+ * Complete a mapping job (mark as completed)
79
+ */
80
+ export declare function completeMappingJob(db: DatabaseOrTransaction | Pool | PoolClient, mappingJobId: number, completionMetadata?: Record<string, any>): Promise<MappingJob>;
81
+ /**
82
+ * Validate that a mapping job exists and has been completed
83
+ */
84
+ export declare function validateMappingJobCompletion(db: DatabaseOrTransaction | Pool | PoolClient, mappingJobId: number): Promise<{
85
+ isValid: boolean;
86
+ mappingJob?: MappingJob;
87
+ error?: string;
88
+ }>;
89
+ /**
90
+ * Get mapping job by ID
91
+ * Returns basic mapping job information including completion status
92
+ *
93
+ * @param db - Database instance
94
+ * @param mappingJobId - Mapping job ID
95
+ * @returns Mapping job or null if not found
96
+ */
97
+ export declare function getMappingJobById(db: DatabaseOrTransaction | Pool | PoolClient, mappingJobId: number): Promise<{
98
+ id: number;
99
+ linkedin_account_id: number;
100
+ completed_at: Date | null;
101
+ } | null>;
102
+ /**
103
+ * Get mapping job with LinkedIn account details
104
+ */
105
+ export declare function getMappingJobWithLinkedInAccount(db: Database | Pool | PoolClient, mappingJobId: number): Promise<{
106
+ mappingJob: MappingJob;
107
+ linkedinAccount: {
108
+ id: number;
109
+ user_id: number | null;
110
+ linkedin_identifier_acoa: string | null;
111
+ public_identifier: string | null;
112
+ forager_id: number;
113
+ first_name: string | null;
114
+ last_name: string | null;
115
+ headline: string | null;
116
+ summary: string | null;
117
+ location: string | null;
118
+ profile_picture_url: string | null;
119
+ profile_image_cloudfront_url: string | null;
120
+ follower_count: number | null;
121
+ connections_count: number | null;
122
+ profiles_updated_at: Date | null;
123
+ created_at: Date;
124
+ };
125
+ user?: {
126
+ id: number;
127
+ given_name: string | null;
128
+ family_name: string | null;
129
+ summary: string | null;
130
+ embedding_summary: string | null;
131
+ embedding: any;
132
+ created_at: Date;
133
+ } | undefined;
134
+ } | null>;
135
+ /**
136
+ * Get all mapping jobs for a LinkedIn account
137
+ */
138
+ export declare function getMappingJobsForLinkedInAccount(db: Database | Pool | PoolClient, linkedinAccountId: number, options?: {
139
+ limit?: number;
140
+ includeCompleted?: boolean;
141
+ }): Promise<MappingJob[]>;
142
+ /**
143
+ * Get pending mapping jobs (not started yet)
144
+ */
145
+ export declare function getPendingMappingJobs(db: Database | Pool | PoolClient, options?: {
146
+ limit?: number;
147
+ linkedinAccountId?: number;
148
+ }): Promise<MappingJob[]>;
149
+ /**
150
+ * Get running mapping jobs (started but not completed)
151
+ */
152
+ export declare function getRunningMappingJobs(db: Database | Pool | PoolClient, options?: {
153
+ limit?: number;
154
+ linkedinAccountId?: number;
155
+ }): Promise<MappingJob[]>;
156
+ /**
157
+ * Get completed mapping jobs
158
+ */
159
+ export declare function getCompletedMappingJobs(db: Database | Pool | PoolClient, options?: {
160
+ limit?: number;
161
+ linkedinAccountId?: number;
162
+ since?: Date;
163
+ }): Promise<MappingJob[]>;
164
+ /**
165
+ * Get relationship scores for a mapping job
166
+ */
167
+ export declare function getRelationshipScoresForMappingJob(db: Database | Pool | PoolClient, mappingJobId: number, options?: {
168
+ limit?: number;
169
+ minScore?: number;
170
+ }): Promise<Array<{
171
+ id: number;
172
+ linkedin_account_id_a: number;
173
+ linkedin_account_id_b: number;
174
+ score: number;
175
+ model_version: string;
176
+ analysis_type: string;
177
+ mapping_job_id: number;
178
+ metadata: Record<string, any>;
179
+ created_at: Date;
180
+ }>>;
181
+ /**
182
+ * Gets enriched relationship scores for a specific mapping job with LinkedIn account details
183
+ * This function properly filters by mapping job ID at the database level (avoiding the bug
184
+ * where getRelationshipScoresForAccount followed by client-side filtering would miss records)
185
+ *
186
+ * @param db - Database instance
187
+ * @param mappingJobId - The mapping job ID to filter by
188
+ * @param mainLinkedinAccountId - The main LinkedIn account ID (to determine which is the "other" account)
189
+ * @param options - Query options
190
+ * @returns Promise resolving to array of enriched relationship scores
191
+ */
192
+ export declare function getEnrichedRelationshipScoresForMappingJob(db: Database | Pool | PoolClient, mappingJobId: number, mainLinkedinAccountId: number, options?: {
193
+ limit?: number;
194
+ minScore?: number;
195
+ sortOrder?: "asc" | "desc";
196
+ }): Promise<Array<{
197
+ score: number;
198
+ modelVersion: string;
199
+ analysisType: string;
200
+ mappingJobId: number;
201
+ metadata: Record<string, any>;
202
+ createdAt: Date;
203
+ otherAccount: {
204
+ id: number;
205
+ linkedinIdentifierAcoa: string | null;
206
+ publicIdentifier: string | null;
207
+ firstName: string | null;
208
+ lastName: string | null;
209
+ headline: string | null;
210
+ profilePictureUrl: string | null;
211
+ };
212
+ }>>;
213
+ /**
214
+ * Delete a mapping job and all related data
215
+ */
216
+ export declare function deleteMappingJob(db: DatabaseOrTransaction | Pool | PoolClient, mappingJobId: number): Promise<boolean>;
217
+ /**
218
+ * @deprecated Use createMappingJobForLinkedInAccount instead
219
+ * This function is kept for backward compatibility but will be removed
220
+ */
221
+ export declare function createMappingJobWithSingleLinkedInAccount(db: DatabaseOrTransaction | Pool | PoolClient, params: {
222
+ linkedinAccountId: number;
223
+ jobMetadata?: Record<string, any>;
224
+ linkedinAccountMetadata?: Record<string, any>;
225
+ }): Promise<{
226
+ mappingJob: MappingJob;
227
+ }>;
228
+ /**
229
+ * @deprecated Use createMappingJobsForLinkedInAccounts instead
230
+ */
231
+ export declare function createMappingJobWithLinkedInAccounts(db: DatabaseOrTransaction | Pool | PoolClient, params: {
232
+ linkedinAccounts: Array<{
233
+ linkedinAccountId: number;
234
+ metadata?: Record<string, any>;
235
+ }>;
236
+ jobMetadata?: Record<string, any>;
237
+ }): Promise<{
238
+ mappingJobs: MappingJob[];
239
+ }>;
240
+ /**
241
+ * =============================================================================
242
+ * CHECK MAPPING AVAILABILITY
243
+ * =============================================================================
244
+ * Check if a LinkedIn profile has been mapped before by looking at both:
245
+ * 1. On-demand mapping jobs (by internal_identifier_acoa)
246
+ * 2. Regular mapping jobs (by target LinkedIn account's linkedin_identifier_acoa)
247
+ */
248
+ export interface MappingAvailabilityResult {
249
+ /** Whether the target is available for mapping (true only if target exists AND no existing mapping) */
250
+ isAvailable: boolean;
251
+ /** Whether the target LinkedIn account exists in our system */
252
+ targetExists: boolean;
253
+ /** Whether there's already an existing mapping for this target */
254
+ hasExistingMapping: boolean;
255
+ /** Details about the existing mapping (if any) */
256
+ mappingDetails?: {
257
+ source: "on_demand" | "regular";
258
+ jobId: number;
259
+ createdAt: Date;
260
+ completedAt?: Date | null;
261
+ } | undefined;
262
+ }
263
+ /**
264
+ * Check if a target LinkedIn profile has been mapped before
265
+ * Uses UNION query to check both on-demand and regular mapping jobs
266
+ *
267
+ * @param db - Database connection
268
+ * @param targetLinkedInIdentifier - LinkedIn identifier (ACoA format) to check
269
+ * @returns Promise<MappingAvailabilityResult> - Availability information
270
+ */
271
+ export declare function checkMappingAvailability(db: Awaited<ReturnType<typeof getDb>> | Pool | PoolClient, targetLinkedInIdentifier: string): Promise<MappingAvailabilityResult>;
272
+ //# sourceMappingURL=mapping-job-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapping-job-operations.d.ts","sourceRoot":"","sources":["../../src/utils/mapping-job-operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEtC,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAuB,KAAK,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;GAEG;AACH,wBAAsB,kCAAkC,CACtD,EAAE,EAAE,qBAAqB,GAAG,IAAI,GAAG,UAAU,EAC7C,MAAM,EAAE;IACN,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,mBAAmB,CAAC,EAAE,M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