@talkpilot/core-db 1.2.0 → 1.2.2

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 (168) hide show
  1. package/README.md +95 -116
  2. package/README_OLD.md +160 -0
  3. package/dist/talkpilot/calls/calls.dashboard.d.ts +3 -0
  4. package/dist/talkpilot/calls/calls.dashboard.d.ts.map +1 -0
  5. package/dist/talkpilot/calls/calls.dashboard.js +191 -0
  6. package/dist/talkpilot/calls/calls.dashboard.js.map +1 -0
  7. package/dist/talkpilot/calls/calls.getters.d.ts +3 -3
  8. package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
  9. package/dist/talkpilot/calls/calls.getters.js +1 -178
  10. package/dist/talkpilot/calls/calls.getters.js.map +1 -1
  11. package/dist/talkpilot/calls/calls.types.d.ts +3 -55
  12. package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
  13. package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts +36 -0
  14. package/dist/talkpilot/calls/dashboard/calls.dashboard.d.ts.map +1 -0
  15. package/dist/talkpilot/calls/dashboard/calls.dashboard.js +208 -0
  16. package/dist/talkpilot/calls/dashboard/calls.dashboard.js.map +1 -0
  17. package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts +66 -0
  18. package/dist/talkpilot/calls/dashboard/calls.dashboard.types.d.ts.map +1 -0
  19. package/dist/talkpilot/calls/dashboard/calls.dashboard.types.js +3 -0
  20. package/dist/talkpilot/calls/dashboard/calls.dashboard.types.js.map +1 -0
  21. package/dist/talkpilot/calls/index.d.ts +1 -0
  22. package/dist/talkpilot/calls/index.d.ts.map +1 -1
  23. package/dist/talkpilot/calls/index.js +1 -0
  24. package/dist/talkpilot/calls/index.js.map +1 -1
  25. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +2 -2
  26. package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
  27. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +11 -10
  28. package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
  29. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +20 -9
  30. package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
  31. package/dist/talkpilot/clientsConfig/clientsConfig.types.js +6 -0
  32. package/dist/talkpilot/clientsConfig/clientsConfig.types.js.map +1 -1
  33. package/dist/talkpilot/flows/flows.schema.js +1 -1
  34. package/dist/talkpilot/phone_numbers/index.d.ts +2 -2
  35. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +1 -1
  36. package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
  37. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +5 -3
  38. package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
  39. package/dist/talkpilot/phone_numbers/phone_numbers.schema.js +12 -12
  40. package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +4 -4
  41. package/dist/talkpilot/results/results.getter.d.ts.map +1 -1
  42. package/dist/talkpilot/results/results.getter.js.map +1 -1
  43. package/dist/talkpilot/retry_analyze/retryAnalyze.getters.d.ts.map +1 -1
  44. package/dist/talkpilot/retry_analyze/retryAnalyze.getters.js.map +1 -1
  45. package/dist/utils/shared.types.d.ts +5 -0
  46. package/dist/utils/shared.types.d.ts.map +1 -0
  47. package/dist/utils/shared.types.js +3 -0
  48. package/dist/utils/shared.types.js.map +1 -0
  49. package/package.json +2 -1
  50. package/src/__tests__/setup.ts +20 -20
  51. package/src/connection.ts +42 -42
  52. package/src/index.ts +16 -16
  53. package/src/municipal/__tests__/validation.spec.ts +62 -62
  54. package/src/municipal/cities/cities.getters.ts +50 -50
  55. package/src/municipal/cities/cities.types.ts +11 -11
  56. package/src/municipal/cities/index.ts +2 -2
  57. package/src/municipal/departmentsSubjects/departmentsSubjects.getters.ts +282 -282
  58. package/src/municipal/departmentsSubjects/departmentsSubjects.types.ts +72 -72
  59. package/src/municipal/departmentsSubjects/index.ts +9 -9
  60. package/src/municipal/index.ts +21 -21
  61. package/src/municipal/mongodb-client.ts +61 -61
  62. package/src/municipal/streets/index.ts +2 -2
  63. package/src/municipal/streets/streets.getters.ts +125 -125
  64. package/src/municipal/streets/streets.types.ts +18 -18
  65. package/src/municipal/systemInstructions/__tests__/getters.spec.ts +113 -113
  66. package/src/municipal/systemInstructions/__tests__/setters.spec.ts +274 -274
  67. package/src/municipal/systemInstructions/index.ts +7 -7
  68. package/src/municipal/systemInstructions/instructions.getters.ts +57 -57
  69. package/src/municipal/systemInstructions/instructions.setters.ts +119 -119
  70. package/src/municipal/systemInstructions/instructions.types.ts +30 -30
  71. package/src/municipal/tickets/__tests__/tickets.getters.spec.ts +66 -66
  72. package/src/municipal/tickets/index.ts +2 -2
  73. package/src/municipal/tickets/tickets.getters.ts +261 -261
  74. package/src/municipal/tickets/tickets.types.ts +43 -43
  75. package/src/municipal/utils/types.ts +11 -11
  76. package/src/talkpilot/__tests__/db.spec.ts +38 -38
  77. package/src/talkpilot/__tests__/mongodb-client.spec.ts +18 -18
  78. package/src/talkpilot/__tests__/validation.spec.ts +68 -68
  79. package/src/talkpilot/agents/__tests__/agents.getters.spec.ts +29 -29
  80. package/src/talkpilot/agents/agents.getters.ts +34 -34
  81. package/src/talkpilot/agents/agents.types.ts +14 -14
  82. package/src/talkpilot/agents/index.ts +2 -2
  83. package/src/talkpilot/backgroundToolResults/__tests__/backgroundToolResults.getters.spec.ts +147 -147
  84. package/src/talkpilot/backgroundToolResults/backgroundToolResults.getters.ts +65 -65
  85. package/src/talkpilot/backgroundToolResults/backgroundToolResults.types.ts +23 -23
  86. package/src/talkpilot/backgroundToolResults/index.ts +2 -2
  87. package/src/talkpilot/calls/__tests__/callStats.utils.spec.ts +128 -128
  88. package/src/talkpilot/calls/__tests__/calls.dashboard.spec.ts +46 -0
  89. package/src/talkpilot/calls/__tests__/calls.spec.ts +270 -252
  90. package/src/talkpilot/calls/calls.getters.ts +248 -446
  91. package/src/talkpilot/calls/calls.types.ts +113 -171
  92. package/src/talkpilot/calls/dashboard/calls.dashboard.ts +243 -0
  93. package/src/talkpilot/calls/dashboard/calls.dashboard.types.ts +70 -0
  94. package/src/talkpilot/calls/index.ts +3 -2
  95. package/src/talkpilot/clientAudioBuffers/__tests__/clientAudioBuffer.getters.spec.ts +160 -160
  96. package/src/talkpilot/clientAudioBuffers/clientAudioBuffer.getters.ts +117 -117
  97. package/src/talkpilot/clientAudioBuffers/clientsAudioBuffers.types.ts +25 -25
  98. package/src/talkpilot/clientAudioBuffers/index.ts +2 -2
  99. package/src/talkpilot/clients/clients.getters.ts +16 -16
  100. package/src/talkpilot/clients/clients.types.ts +14 -14
  101. package/src/talkpilot/clients/index.ts +2 -2
  102. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.getters.spec.ts +53 -0
  103. package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +197 -106
  104. package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +55 -44
  105. package/src/talkpilot/clientsConfig/clientsConfig.types.ts +127 -94
  106. package/src/talkpilot/clientsConfig/index.ts +2 -2
  107. package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +71 -67
  108. package/src/talkpilot/flows/flows.getter.ts +14 -14
  109. package/src/talkpilot/flows/flows.schema.ts +153 -153
  110. package/src/talkpilot/flows/flows.types.ts +184 -184
  111. package/src/talkpilot/flows/index.ts +2 -2
  112. package/src/talkpilot/groups/__tests__/groups.spec.ts +90 -90
  113. package/src/talkpilot/groups/__tests__/phone.utils.spec.ts +32 -32
  114. package/src/talkpilot/groups/groups.getters.ts +30 -30
  115. package/src/talkpilot/groups/groups.types.ts +29 -29
  116. package/src/talkpilot/groups/index.ts +3 -3
  117. package/src/talkpilot/groups/phone.utils.ts +46 -46
  118. package/src/talkpilot/index.ts +29 -29
  119. package/src/talkpilot/leads/index.ts +2 -2
  120. package/src/talkpilot/leads/leads.getter.ts +6 -6
  121. package/src/talkpilot/leads/leads.schema.ts +33 -33
  122. package/src/talkpilot/leads/leads.types.ts +20 -20
  123. package/src/talkpilot/mongodb-client.ts +78 -78
  124. package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +252 -247
  125. package/src/talkpilot/phone_numbers/index.ts +2 -2
  126. package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +158 -154
  127. package/src/talkpilot/phone_numbers/phone_numbers.schema.ts +17 -17
  128. package/src/talkpilot/phone_numbers/phone_numbers.types.ts +30 -30
  129. package/src/talkpilot/plans/__tests__/plans.spec.ts +70 -70
  130. package/src/talkpilot/plans/index.ts +2 -2
  131. package/src/talkpilot/plans/plans.getters.ts +132 -132
  132. package/src/talkpilot/plans/plans.types.ts +89 -89
  133. package/src/talkpilot/results/index.ts +7 -7
  134. package/src/talkpilot/results/results.getter.ts +39 -35
  135. package/src/talkpilot/results/results.schema.ts +25 -25
  136. package/src/talkpilot/results/results.types.ts +34 -34
  137. package/src/talkpilot/retry_analyze/__tests__/retryAnalyze.getters.spec.ts +156 -156
  138. package/src/talkpilot/retry_analyze/index.ts +2 -2
  139. package/src/talkpilot/retry_analyze/retryAnalyze.getters.ts +84 -75
  140. package/src/talkpilot/retry_analyze/retryAnalyze.types.ts +13 -13
  141. package/src/talkpilot/sessions/__tests__/sessions.spec.ts +147 -147
  142. package/src/talkpilot/sessions/index.ts +2 -2
  143. package/src/talkpilot/sessions/sessions.getter.ts +92 -92
  144. package/src/talkpilot/sessions/sessions.schema.ts +34 -34
  145. package/src/talkpilot/sessions/sessions.types.ts +30 -30
  146. package/src/talkpilot/subscriptions/__tests__/subscriptions.getters.utils.spec.ts +45 -45
  147. package/src/talkpilot/subscriptions/index.ts +3 -3
  148. package/src/talkpilot/subscriptions/subscriptions.getters.ts +146 -146
  149. package/src/talkpilot/subscriptions/subscriptions.getters.utils.ts +33 -33
  150. package/src/talkpilot/subscriptions/subscriptions.types.ts +66 -66
  151. package/src/talkpilot/utils/__tests__/query.utils.spec.ts +49 -49
  152. package/src/talkpilot/utils/query.utils.ts +21 -21
  153. package/src/test-utils/db-utils.ts +24 -24
  154. package/src/test-utils/factories/index.ts +12 -12
  155. package/src/test-utils/factories/municipal/cities.ts +16 -16
  156. package/src/test-utils/factories/municipal/departmentsSubjects.ts +37 -37
  157. package/src/test-utils/factories/municipal/streets.ts +22 -22
  158. package/src/test-utils/factories/municipal/tickets.ts +39 -39
  159. package/src/test-utils/factories/talkpilot/agents.ts +19 -19
  160. package/src/test-utils/factories/talkpilot/calls.ts +37 -37
  161. package/src/test-utils/factories/talkpilot/clientAudioBuffers.ts +20 -20
  162. package/src/test-utils/factories/talkpilot/clientsConfig.ts +18 -18
  163. package/src/test-utils/factories/talkpilot/flows.ts +33 -33
  164. package/src/test-utils/factories/talkpilot/groups.ts +33 -33
  165. package/src/test-utils/factories/talkpilot/phone_numbers.ts +22 -22
  166. package/src/test-utils/factories/talkpilot/sessions.ts +35 -35
  167. package/src/utils/shared.types.ts +4 -0
  168. package/src/utils/validation.ts +23 -23
package/README.md CHANGED
@@ -1,160 +1,139 @@
1
- # @talkpilot/core-db
1
+ L1:# @talkpilot/core-db
2
2
 
3
- [NPM Version](https://www.npmjs.com/package/@talkpilot/core-db)
3
+ `@talkpilot/core-db` is the shared TypeScript database package that wires TalkPilot APIs, municipal CRM integrations, and internal tools to a single, type-safe MongoDB surface. Every repo (MIS, CIS, TalkPilot Server, etc.) imports this package to avoid re-implementing connections, collections, or validation helpers.
4
4
 
5
- A TypeScript-based core database management package designed to provide centralized database connections, ORM integrations, and client utilities for other projects. This package manages connections to both **TalkPilot** and **Municipal** MongoDB databases.
5
+ ## Purpose
6
6
 
7
- ## Features
7
+ - Provide a reliable, multi-domain MongoDB layer for TalkPilot and municipal data.
8
+ - Export typed getters, vector search helpers, and document factories so services can focus on behavior instead of schema wiring.
9
+ - Manage connection lifecycles, environment configuration, and test helpers from one place so every repo reuses the same plumbing.
8
10
 
9
- - 🚀 **Multi-Domain Database Management**: Centralized handlers for both TalkPilot and Municipal Data domains.
10
- - 📦 **Reusable Getters**: Standardized functions for fetching data from various collections (calls, agents, leads, cities, etc.).
11
- - 🏗️ **Type-safe**: Built with TypeScript for full type safety across all your database interactions.
12
- - 🛠️ **Environment Aware**: Configurable via environment variables or explicit parameters.
11
+ ## Main Concepts
13
12
 
14
- ## Installation
13
+ - **Multi-domain clients** – `src/connection.ts` exposes `mongodbClient` (TalkPilot) and `municipalDataMongodbClient`, each of which resolves `MONGO_URI`, DB overrides, and default names.
14
+ - **Domain-specific getters** – `src/talkpilot/` and `src/municipal/` host typed getters (agents, calls, streets, tickets, etc.), vector-search helpers, and service-friendly adapters that keep caller code DRY.
15
+ - **Product-specific clients (future)** – While the package currently exposes the shared TalkPilot + municipal clients, we expect each product (CIS, MIS, TalkPilot Server) to eventually get its own domain-specific client helpers or wrappers so the shared core can remain stable while new consumers add targeted extensions.
16
+ - **Test helpers** – `src/test-utils/` plus `src/__tests__/` reuse `MongoMemoryServer` and shared factories so tests start with clean data regardless of the consuming repo.
17
+ - **Utility layers** – `src/utils/` contains shared validation, pagination, and environment helpers that complement the getters.
18
+ - **Environment awareness** – Defaults, fallbacks, and `process.env` lookups ensure local, CI, and Cloud Run clients all connect using the right URI/DB names.
15
19
 
16
- This package is intended to be used as a dependency in other projects. If you're working locally, you can install it using a file path:
20
+ ## Key Components
17
21
 
18
- ```bash
19
- # In your other project:
20
- npm install /path/to/core-db
21
- # or if published to a registry:
22
- npm install @talkpilot/core-db
23
- # or via GitHub
24
- npm install github:talkpilot/core-db
25
- ```
26
-
27
- ## Quick Start
28
-
29
- ### 1. Initialize Database Connections
22
+ - `src/connection.ts` – Central connection logic that resolves URIs/DB names from env vars (`MONGO_URI`, `MONGODB_URI`, `TALKPILOT_DB_NAME`, `MUNICIPAL_DB_NAME`) and reuses a single `MongoClient`.
23
+ - `src/talkpilot/` Call history, agents, flows, sessions, leads, subscriptions, and support helpers exposed as getters plus helper enums/types for each collection.
24
+ - `src/municipal/` – Municipal-specific collections (`cities`, `streets`, `departmentsSubjects`, `tickets`, etc.) plus vector search helpers and Ash Bina helpers used by MIS.
25
+ - `src/utils/` Shared helpers such as `resolveConnection`, pagination utilities, and schema validation helper functions.
26
+ - `src/test-utils/` and `src/__tests__/` – Utilities that bootstrap `MongoMemoryServer`, expose factories, and make sure Jest environments can stub database calls predictably.
27
+ - `dist/` Compiled output consumed by downstream repos (CJS + ESM + type defs).
30
28
 
31
- You must initialize the database clients before using any of the getters.
29
+ ## Domain APIs
32
30
 
33
- ```typescript
34
- import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
31
+ - **TalkPilot domain** – Imports like `findAgents`, `getFlows`, `findCalls`, and `vectorSearchCalls` live in `src/talkpilot`. These functions are the canonical access pattern for call history, session metadata, and provider configs.
32
+ - **Municipal domain** – Helpers such as `findStreets`, `getMunicipalCities`, `findDepartmentSubjects`, and `createTicket` live under `src/municipal` and feed MIS workflows (street hints, subject matching, Ash Bina tickets).
35
33
 
36
- async function bootstrap() {
37
- // Initialize TalkPilot DB
38
- await mongodbClient.connect(process.env.TALKPILOT_MONGO_URI);
34
+ ## Environment variables
39
35
 
40
- // Initialize Municipal Data DB (optional)
41
- await municipalDataMongodbClient.connect(process.env.MUNICIPAL_MONGO_URI);
42
- }
36
+ | Variable | Purpose | Required |
37
+ |---------------------------|--------------------------------------------------------------------------------------|----------|
38
+ | `MONGO_URI` | Primary MongoDB connection string for every domain (overridden by `MONGODB_URI`). | ✅ |
39
+ | `MONGODB_URI` | Alternate connection string used when Mongo needs a second URI parameter. | ✅ |
40
+ | `TALKPILOT_DB_NAME` | Optional override for the TalkPilot database name (defaults from URI path). | ❌ |
41
+ | `MUNICIPAL_DB_NAME` | Optional override for the municipal database name (defaults to `municipal-data`). | ❌ |
42
+ | `ENV` | Free-form label used in logs/validators (defaults to `unknown`). | ❌ |
43
43
 
44
- bootstrap().catch(console.error);
45
- ```
46
-
47
- ### 2. Using Getters
44
+ If you pass a `uri` directly to `mongodbClient.connect()` or `municipalDataMongodbClient.connect()`, the client will prefer that value over the env vars.
48
45
 
49
- Once initialized, you can import and use any of the exported database getters.
46
+ ## Getting Started
50
47
 
51
- ```typescript
52
- import { findAgents, findCities } from '@talkpilot/core-db';
48
+ ### Prerequisites
53
49
 
54
- async function getSummary() {
55
- // Get all agents from TalkPilot DB
56
- const agents = await findAgents();
57
- console.log('Total Agents:', agents.length);
50
+ - Node.js 22.x+ (aligns with downstream services).
51
+ - npm 11+ or Yarn.
52
+ - MongoDB accessible from your environment or a `MongoMemoryServer` for tests.
58
53
 
59
- // Get all cities from Municipal Data DB
60
- const cities = await findCities();
61
- console.log('Total Cities:', cities.length);
62
- }
63
- ```
64
-
65
- ## Available Domains
66
-
67
- The package exports two main sets of tools:
68
-
69
- ### TalkPilot Domain
70
-
71
- Includes access to:
54
+ ### Setup
72
55
 
73
- - `agents`, `calls`, `clients`, `flows`, `leads`, `phone_numbers`, `plans`, `results`, `sessions`, `subscriptions`, etc.
74
- - Exported as root level functions or via `mongodbClient`.
56
+ 1. Clone the repo and install dependencies:
75
57
 
76
- ### Municipal Domain
58
+ ```bash
59
+ git clone https://github.com/talkpilot/core-db.git
60
+ cd core-db
61
+ npm install
62
+ ```
77
63
 
78
- Includes access to:
64
+ 2. Build the package before using it locally:
79
65
 
80
- - `cities`, `streets`, `departmentsSubjects`, `tickets`.
81
- - Functions are prefixed where necessary or accessible via `getMunicipalDataDb`.
66
+ ```bash
67
+ npm run build
68
+ ```
82
69
 
83
- ## Environment Variables
70
+ 3. Import `@talkpilot/core-db` from another project by pointing `package.json` at the local path during development or installing the published release.
84
71
 
85
- The clients will automatically attempt to use the following environment variables if no URI is provided to the `connect()` method:
72
+ ## Sample `.env`
86
73
 
87
- - `MONGO_URI` or `MONGODB_URI`: Primary MongoDB connection string.
88
- - `MONGODB_DB_NAME`: Database name (defaults to 'municipal-data' for the municipal client if not specified).
74
+ ```
75
+ MONGO_URI=mongodb://localhost:27017
76
+ TALKPILOT_DB_NAME=talkpilot-dev
77
+ MUNICIPAL_DB_NAME=municipal-dev
78
+ ENV=development
79
+ ```
89
80
 
90
- ## Development
81
+ Adjust `MONGO_URI` to match the running Mongo instance and configure `talkpilot`/`municipal` DB names if you want to keep them separate.
91
82
 
92
- ### Setup
83
+ ## Local development
93
84
 
94
- 1. Clone the repository and install dependencies:
95
- ```bash
96
- git clone https://github.com/talkpilot/core-db.git
97
- cd core-db
98
- npm install
99
- ```
100
- 2. Build the project:
101
- ```bash
102
- npm run build
103
- ```
85
+ 1. Run `npm install`.
86
+ 2. Build the compiled output: `npm run build`.
87
+ 3. Execute tests: `npm run test`.
88
+ 4. Use `npm link` or `npm pack` to consume the freshly built package from other repos (`CIS`, `MIS`, `TalkPilot Server`).
104
89
 
105
- This will generate the `dist/` directory with the compiled JavaScript and type definitions.
90
+ ## Development guide
106
91
 
107
- ### Publishing New Versions
92
+ `DEVELOPMENT.md` contains the tactical steps for contributors. At a glance:
108
93
 
109
- To publish a new version of the package:
94
+ - Node 18+/TypeScript is required (aligns with downstream services).
95
+ - Run `npm install` → `npm run build` after cloning.
96
+ - Use `npm link`/`npm link @talkpilot/core-db` to test the package locally before publishing.
97
+ - When adding getters, define types, implement the function, export it through the domain `index.ts`, and add a corresponding test under the domain’s `__tests__` folder.
98
+ - Always rely on the provided test factories (`src/test-utils/factories`) to seed data so tests remain consistent.
99
+ - Jest with `mongodb-memory-server` is the only execution path we have to verify this core utility—unit tests are the safety net for every change.
110
100
 
111
- 1. **Test your changes**:
112
- ```bash
113
- npm test
114
- ```
115
- 2. **Update the version**:
116
- ```bash
117
- # Bumps patch version (0.1.0 -> 0.1.1)
118
- npm version patch
119
- # Or for minor changes (0.1.0 -> 0.2.0)
120
- # npm version minor
121
- # Or for major changes (0.1.0 -> 1.0.0)
122
- # npm version major
123
- ```
124
- 3. **Publish to npm**:
125
- Ensure you have the shared team token in your `~/.npmrc` (see [Development Guide](./DEVELOPMENT.md#team-access--authentication)).
126
- 4. **Update in other repos**:
127
- ```bash
128
- npm update @talkpilot/core-db
129
- ```
101
+ Refer to `DEVELOPMENT.md` for the full walkthrough, token instructions, and factory samples.
130
102
 
131
- ## License
103
+ ## 🧪 Testing
132
104
 
133
- MIT
105
+ - `npm run test` – Jest suite (factories, utils, integration mocks) powered by `mongodb-memory-server`.
106
+ - Tests rely on `src/__tests__/setup.ts` to bootstrap the in-memory Mongo instances and wire shared factories/helpers before each run.
107
+ - When adding getters, helpers, or domain logic, create focused coverage inside the consuming domain’s `__tests__/` folder and use the provided factories to keep fixtures consistent.
134
108
 
135
- ---
109
+ `@talkpilot/core-db` does not run in a product UI or feature branch—unit tests are the *only* reliable execution path to ensure your changes work. Every change must ship with a unit test so downstream repos can upgrade without surprises; treat the test suite as the canonical safety net for this core utility package.
136
110
 
137
- **Interested in contributing?** Check out our [Development Guide](./DEVELOPMENT.md) for standards and setup instructions.
111
+ ## 🧹 Lint & build verification
138
112
 
139
- ## Release Notes
113
+ - `npm run lint` – Run ESLint over `src/**/*.{ts,tsx}`.
114
+ - `npm run format` – Format the source files with Prettier.
115
+ - `npm run build` – Compile TypeScript and emit `dist/` (used by downstream consumers).
140
116
 
141
- ### 1.1.9
117
+ ## ✅ Pre-push checklist
142
118
 
143
- - `getPhoneNumbersForFlows(clientId)` lists each phone number linked to a flow for that client (newest first), with `flowId`, `phoneNumber`, and `isPrimary`.
144
- ### 1.1.5
119
+ 1. `npm run build`.
120
+ 2. `npm run test`.
121
+ 3. `npm run format`.
145
122
 
146
- - `createPurchasedPhoneNumber` for API-bought numbers (Twilio/Telnyx metadata); optional `flowId` until linked to a flow. Types/schema updated accordingly.
123
+ ## Publishing & release notes
147
124
 
148
- ### 1.0.16
125
+ - Releases are handled by `npm version <patch|minor|major>` followed by `npm publish`. The package is a **private `@talkpilot` dependency**, so every contributor must install the shared npm automation token into their global `~/.npmrc` before running publish or `npm install`.
126
+ - The shared token is rotated periodically—if you see authentication failures, request the refreshed token, update your `~/.npmrc`, and retry. Never commit credentials to source control.
127
+ - After publishing, downstream repos (`CIS`, `MIS`, `TalkPilot Server`, etc.) should run `npm update @talkpilot/core-db` so they receive the latest helpers/bug fixes.
128
+ - Cloud Build & Cloud Run jobs that depend on this package pick up the new version the next time they rebuild their container; the services pull the compiled `dist/` output and type definitions when installing the dependency.
149
129
 
150
- - Fixed critical issues present in version 1.0.15.
151
- - **Warning**: Version 1.0.15 is bugged and should not be used. Please use at least version 1.0.16.
130
+ ## 🛠 CI/CD & deployment
152
131
 
153
- ### 1.0.20
132
+ - This package is consumed by Cloud Build-based services (TalkPilot Server, MIS, CIS) as a dependency when Docker images are built. Keep `dist/` in sync with your builds because the compiled artifact is what downstream services install.
133
+ - Releases require the shared npm token documented in `DEVELOPMENT.md`; consult that guide for contribution, linking, and token rotation procedures.
154
134
 
155
- - Added to Moked106Config this param: withNeedAttentionCalls
156
- - withNeedAttentionCalls?: boolean
135
+ ## Resources
157
136
 
158
- ### 1.0.27
159
- - Added an optional `language` field to `ClientConfig` (e.g. Hebrew/English/Russian/French/Spanish) and updated tests.
137
+ - [DEVELOPMENT.md](./DEVELOPMENT.md) (setup, tooling, publishing, token management)
138
+ - [src/test-utils](src/test-utils) and the `__tests__` folder for examples of `MongoMemoryServer` wiring.
160
139
 
package/README_OLD.md ADDED
@@ -0,0 +1,160 @@
1
+ # @talkpilot/core-db
2
+
3
+ [NPM Version](https://www.npmjs.com/package/@talkpilot/core-db)
4
+
5
+ A TypeScript-based core database management package designed to provide centralized database connections, ORM integrations, and client utilities for other projects. This package manages connections to both **TalkPilot** and **Municipal** MongoDB databases.
6
+
7
+ ## Features
8
+
9
+ - 🚀 **Multi-Domain Database Management**: Centralized handlers for both TalkPilot and Municipal Data domains.
10
+ - 📦 **Reusable Getters**: Standardized functions for fetching data from various collections (calls, agents, leads, cities, etc.).
11
+ - 🏗️ **Type-safe**: Built with TypeScript for full type safety across all your database interactions.
12
+ - 🛠️ **Environment Aware**: Configurable via environment variables or explicit parameters.
13
+
14
+ ## Installation
15
+
16
+ This package is intended to be used as a dependency in other projects. If you're working locally, you can install it using a file path:
17
+
18
+ ```bash
19
+ # In your other project:
20
+ npm install /path/to/core-db
21
+ # or if published to a registry:
22
+ npm install @talkpilot/core-db
23
+ # or via GitHub
24
+ npm install github:talkpilot/core-db
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### 1. Initialize Database Connections
30
+
31
+ You must initialize the database clients before using any of the getters.
32
+
33
+ ```typescript
34
+ import { mongodbClient, municipalDataMongodbClient } from '@talkpilot/core-db';
35
+
36
+ async function bootstrap() {
37
+ // Initialize TalkPilot DB
38
+ await mongodbClient.connect(process.env.TALKPILOT_MONGO_URI);
39
+
40
+ // Initialize Municipal Data DB (optional)
41
+ await municipalDataMongodbClient.connect(process.env.MUNICIPAL_MONGO_URI);
42
+ }
43
+
44
+ bootstrap().catch(console.error);
45
+ ```
46
+
47
+ ### 2. Using Getters
48
+
49
+ Once initialized, you can import and use any of the exported database getters.
50
+
51
+ ```typescript
52
+ import { findAgents, findCities } from '@talkpilot/core-db';
53
+
54
+ async function getSummary() {
55
+ // Get all agents from TalkPilot DB
56
+ const agents = await findAgents();
57
+ console.log('Total Agents:', agents.length);
58
+
59
+ // Get all cities from Municipal Data DB
60
+ const cities = await findCities();
61
+ console.log('Total Cities:', cities.length);
62
+ }
63
+ ```
64
+
65
+ ## Available Domains
66
+
67
+ The package exports two main sets of tools:
68
+
69
+ ### TalkPilot Domain
70
+
71
+ Includes access to:
72
+
73
+ - `agents`, `calls`, `clients`, `flows`, `leads`, `phone_numbers`, `plans`, `results`, `sessions`, `subscriptions`, etc.
74
+ - Exported as root level functions or via `mongodbClient`.
75
+
76
+ ### Municipal Domain
77
+
78
+ Includes access to:
79
+
80
+ - `cities`, `streets`, `departmentsSubjects`, `tickets`.
81
+ - Functions are prefixed where necessary or accessible via `getMunicipalDataDb`.
82
+
83
+ ## Environment Variables
84
+
85
+ The clients will automatically attempt to use the following environment variables if no URI is provided to the `connect()` method:
86
+
87
+ - `MONGO_URI` or `MONGODB_URI`: Primary MongoDB connection string.
88
+ - `MONGODB_DB_NAME`: Database name (defaults to 'municipal-data' for the municipal client if not specified).
89
+
90
+ ## Development
91
+
92
+ ### Setup
93
+
94
+ 1. Clone the repository and install dependencies:
95
+ ```bash
96
+ git clone https://github.com/talkpilot/core-db.git
97
+ cd core-db
98
+ npm install
99
+ ```
100
+ 2. Build the project:
101
+ ```bash
102
+ npm run build
103
+ ```
104
+
105
+ This will generate the `dist/` directory with the compiled JavaScript and type definitions.
106
+
107
+ ### Publishing New Versions
108
+
109
+ To publish a new version of the package:
110
+
111
+ 1. **Test your changes**:
112
+ ```bash
113
+ npm test
114
+ ```
115
+ 2. **Update the version**:
116
+ ```bash
117
+ # Bumps patch version (0.1.0 -> 0.1.1)
118
+ npm version patch
119
+ # Or for minor changes (0.1.0 -> 0.2.0)
120
+ # npm version minor
121
+ # Or for major changes (0.1.0 -> 1.0.0)
122
+ # npm version major
123
+ ```
124
+ 3. **Publish to npm**:
125
+ Ensure you have the shared team token in your `~/.npmrc` (see [Development Guide](./DEVELOPMENT.md#team-access--authentication)).
126
+ 4. **Update in other repos**:
127
+ ```bash
128
+ npm update @talkpilot/core-db
129
+ ```
130
+
131
+ ## License
132
+
133
+ MIT
134
+
135
+ ---
136
+
137
+ **Interested in contributing?** Check out our [Development Guide](./DEVELOPMENT.md) for standards and setup instructions.
138
+
139
+ ## Release Notes
140
+
141
+ ### 1.1.9
142
+
143
+ - `getPhoneNumbersForFlows(clientId)` — lists each phone number linked to a flow for that client (newest first), with `flowId`, `phoneNumber`, and `isPrimary`.
144
+ ### 1.1.5
145
+
146
+ - `createPurchasedPhoneNumber` for API-bought numbers (Twilio/Telnyx metadata); optional `flowId` until linked to a flow. Types/schema updated accordingly.
147
+
148
+ ### 1.0.16
149
+
150
+ - Fixed critical issues present in version 1.0.15.
151
+ - **Warning**: Version 1.0.15 is bugged and should not be used. Please use at least version 1.0.16.
152
+
153
+ ### 1.0.20
154
+
155
+ - Added to Moked106Config this param: withNeedAttentionCalls
156
+ - withNeedAttentionCalls?: boolean
157
+
158
+ ### 1.0.27
159
+ - Added an optional `language` field to `ClientConfig` (e.g. Hebrew/English/Russian/French/Spanish) and updated tests.
160
+
@@ -0,0 +1,3 @@
1
+ import { DashboardStatsParams, DashboardStatsResult } from "./calls.types";
2
+ export declare function getDashboardStats(params: DashboardStatsParams): Promise<DashboardStatsResult>;
3
+ //# sourceMappingURL=calls.dashboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calls.dashboard.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.dashboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAA8B,oBAAoB,EAAE,oBAAoB,EAAiD,MAAM,eAAe,CAAC;AAmGtJ,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CAuG/B"}
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getDashboardStats = getDashboardStats;
7
+ const dayjs_1 = __importDefault(require("dayjs"));
8
+ const calls_getters_1 = require("./calls.getters");
9
+ const clientsConfig_1 = require("../clientsConfig");
10
+ const utc_1 = __importDefault(require("dayjs/plugin/utc"));
11
+ const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
12
+ dayjs_1.default.extend(utc_1.default);
13
+ dayjs_1.default.extend(timezone_1.default);
14
+ function buildKpisPipeline() {
15
+ return [
16
+ {
17
+ $group: {
18
+ _id: null,
19
+ totalCalls: { $sum: 1 },
20
+ totalDuration: { $sum: "$callLength" },
21
+ completedCount: {
22
+ $sum: { $cond: [{ $eq: ["$status", "completed"] }, 1, 0] },
23
+ },
24
+ failedCount: {
25
+ $sum: { $cond: [{ $eq: ["$status", "failed"] }, 1, 0] },
26
+ },
27
+ noAnswerCount: {
28
+ $sum: { $cond: [{ $eq: ["$status", "no-answer"] }, 1, 0] },
29
+ },
30
+ busyCount: {
31
+ $sum: { $cond: [{ $eq: ["$status", "busy"] }, 1, 0] },
32
+ },
33
+ },
34
+ },
35
+ ];
36
+ }
37
+ function buildDailyDataPipeline(timezone) {
38
+ return [
39
+ {
40
+ $group: {
41
+ _id: {
42
+ $dateToString: {
43
+ format: "%Y-%m-%d",
44
+ date: "$createdAt",
45
+ timezone: timezone,
46
+ },
47
+ },
48
+ count: { $sum: 1 },
49
+ completed: {
50
+ $sum: { $cond: [{ $eq: ["$status", "completed"] }, 1, 0] },
51
+ },
52
+ },
53
+ },
54
+ { $sort: { _id: 1 } },
55
+ ];
56
+ }
57
+ function buildHourlyDataPipeline(timezone) {
58
+ return [
59
+ {
60
+ $group: {
61
+ _id: {
62
+ day: {
63
+ $dateToString: {
64
+ format: "%Y-%m-%d",
65
+ date: "$createdAt",
66
+ timezone: timezone,
67
+ },
68
+ },
69
+ hour: { $hour: { date: "$createdAt", timezone: timezone } },
70
+ },
71
+ count: { $sum: 1 },
72
+ },
73
+ },
74
+ ];
75
+ }
76
+ function buildCallLengthBucketsPipeline() {
77
+ return [
78
+ {
79
+ $group: {
80
+ _id: null,
81
+ short: { $sum: { $cond: [{ $lt: ["$callLength", 60] }, 1, 0] } },
82
+ medium: {
83
+ $sum: {
84
+ $cond: [
85
+ {
86
+ $and: [
87
+ { $gte: ["$callLength", 60] },
88
+ { $lte: ["$callLength", 180] },
89
+ ],
90
+ },
91
+ 1,
92
+ 0,
93
+ ],
94
+ },
95
+ },
96
+ long: { $sum: { $cond: [{ $gt: ["$callLength", 180] }, 1, 0] } },
97
+ },
98
+ },
99
+ ];
100
+ }
101
+ async function getDashboardStats(params) {
102
+ const { clientId, startDate, endDate } = params;
103
+ const clientConfig = await (0, clientsConfig_1.getClientConfig)(clientId);
104
+ const timezone = clientConfig?.timezone ?? "UTC";
105
+ const startDateObj = dayjs_1.default.tz(startDate, timezone).startOf("day").toDate();
106
+ const endDateObj = dayjs_1.default.tz(endDate, timezone).endOf("day").toDate();
107
+ const pipeline = [
108
+ {
109
+ $match: {
110
+ clientId,
111
+ createdAt: { $gte: startDateObj, $lte: endDateObj },
112
+ },
113
+ },
114
+ {
115
+ $facet: {
116
+ kpis: buildKpisPipeline(),
117
+ dailyData: buildDailyDataPipeline(timezone),
118
+ hourlyData: buildHourlyDataPipeline(timezone),
119
+ callLengthBuckets: buildCallLengthBucketsPipeline(),
120
+ },
121
+ },
122
+ ];
123
+ const callsCollection = (0, calls_getters_1.getCallsCollection)();
124
+ const [aggregatedResult] = await callsCollection
125
+ .aggregate(pipeline)
126
+ .toArray();
127
+ const kpiData = aggregatedResult?.kpis?.[0] ?? {
128
+ totalCalls: 0,
129
+ totalDuration: 0,
130
+ completedCount: 0,
131
+ failedCount: 0,
132
+ noAnswerCount: 0,
133
+ busyCount: 0,
134
+ };
135
+ const dailyDataRaw = aggregatedResult?.dailyData ?? [];
136
+ const hourlyDataRaw = aggregatedResult?.hourlyData ?? [];
137
+ const callLengthRaw = aggregatedResult?.callLengthBuckets?.[0] ?? {
138
+ short: 0,
139
+ medium: 0,
140
+ long: 0,
141
+ };
142
+ const count = kpiData.totalCalls;
143
+ const totalLen = kpiData.totalDuration;
144
+ const completed = kpiData.completedCount;
145
+ const kpis = {
146
+ totalCalls: count,
147
+ avgDurationSeconds: count > 0 ? Math.round(totalLen / count) : 0,
148
+ timeSavedMinutes: Math.round(totalLen / 60),
149
+ successRate: count > 0 ? Math.round((completed / count) * 1000) / 10 : 0,
150
+ completedCount: completed,
151
+ failedCount: kpiData.failedCount,
152
+ noAnswerCount: kpiData.noAnswerCount,
153
+ busyCount: kpiData.busyCount,
154
+ };
155
+ const volumeData = dailyDataRaw.map((d) => ({
156
+ date: d._id,
157
+ count: d.count,
158
+ completed: d.completed,
159
+ }));
160
+ const heatmapMap = new Map();
161
+ for (const bucket of hourlyDataRaw) {
162
+ const dayKey = bucket._id.day;
163
+ const hour = bucket._id.hour;
164
+ if (!heatmapMap.has(dayKey))
165
+ heatmapMap.set(dayKey, new Map());
166
+ heatmapMap.get(dayKey).set(hour, bucket.count);
167
+ }
168
+ const toSortedBuckets = (map) => Array.from(map.entries())
169
+ .sort(([a], [b]) => a - b)
170
+ .map(([h, c]) => ({
171
+ hour: `${String(h).padStart(2, "0")}:00`,
172
+ calls: c,
173
+ }));
174
+ const heatmap = {};
175
+ for (const [day, hourMap] of Array.from(heatmapMap.entries()).sort()) {
176
+ heatmap[day] = toSortedBuckets(hourMap);
177
+ }
178
+ return {
179
+ kpis,
180
+ charts: {
181
+ volumeData,
182
+ heatmap,
183
+ callLengthBuckets: {
184
+ short: callLengthRaw.short,
185
+ medium: callLengthRaw.medium,
186
+ long: callLengthRaw.long,
187
+ },
188
+ },
189
+ };
190
+ }
191
+ //# sourceMappingURL=calls.dashboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calls.dashboard.js","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.dashboard.ts"],"names":[],"mappings":";;;;;AAqGA,8CAyGC;AA9MD,kDAA0B;AAC1B,mDAAqD;AAErD,oDAAmD;AACnD,2DAAmC;AACnC,qEAAmD;AAEnD,eAAK,CAAC,MAAM,CAAC,aAAG,CAAC,CAAC;AAClB,eAAK,CAAC,MAAM,CAAC,kBAAc,CAAC,CAAC;AAC7B,SAAS,iBAAiB;IACxB,OAAO;QACL;YACE,MAAM,EAAE;gBACN,GAAG,EAAE,IAAI;gBACT,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE;gBACvB,aAAa,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;gBACtC,cAAc,EAAE;oBACd,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE;iBAC3D;gBACD,WAAW,EAAE;oBACX,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,E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MAAM,eAAe,GAAG,CAAC,GAAwB,EAAkB,EAAE,CACnE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;SACtB,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChB,IAAI,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK;QACxC,KAAK,EAAE,CAAC;KACT,CAAC,CAAC,CAAC;IAER,MAAM,OAAO,GAAmC,EAAE,CAAC;IACnD,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACrE,OAAO,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO;QACL,IAAI;QACJ,MAAM,EAAE;YACN,UAAU;YACV,OAAO;YACP,iBAAiB,EAAE;gBACjB,KAAK,EAAE,aAAa,CAAC,KAAK;gBAC1B,MAAM,EAAE,aAAa,CAAC,MAAM;gBAC5B,IAAI,EAAE,aAAa,CAAC,IAAI;aACzB;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { Call, CallDoc, CallQueryOptions, CallUpdateParams } from "../index";
2
- import type { CallsByHour, CountOpts, DateRange, ToolExecution, DashboardStatsResult, DashboardStatsParams } from "./calls.types";
2
+ import type { CountOpts, DateRange, ToolExecution } from "./calls.types";
3
3
  import { Filter, ObjectId } from "mongodb";
4
+ import { DashboardHeatmapMetric } from "./dashboard/calls.dashboard.types";
4
5
  export declare const getCallsCollection: () => import("mongodb").Collection<Call>;
5
6
  export declare const getCallByCallSid: (callSid: string) => Promise<import("mongodb").WithId<Call> | null>;
6
7
  export declare const getCallsByPhoneNumber: (phoneNumber: string) => Promise<import("mongodb").WithId<Call>[]>;
@@ -34,6 +35,5 @@ export declare function getCallsStatsForDateRange(clientId: string, startStr: st
34
35
  /**
35
36
  * Aggregate calls by hour for a given date (createdAt converted to given timezone). Hour format "HH:mm".
36
37
  */
37
- export declare function getCallsHourlyAggregation(clientId: string, dateStr: string, timezone: string): Promise<CallsByHour[]>;
38
- export declare function getDashboardStats(params: DashboardStatsParams): Promise<DashboardStatsResult>;
38
+ export declare function getCallsHourlyAggregation(clientId: string, dateStr: string, timezone: string): Promise<DashboardHeatmapMetric[]>;
39
39
  //# sourceMappingURL=calls.getters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"calls.getters.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/calls/calls.getters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,OAAO,EACP,gBAAgB,EAChB,gBAAgB,EAEjB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAqF,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrN,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAM3C,eAAO,MAAM,kBAAkB,0CAE9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,SAAS,MAAM,mDAE/C,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,aAAa,MAAM,8CAIxD,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,UAAU,MAAM,8CAEhD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,QAAQ,8CAE9C,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,MAAM,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,KAAK,CAAC,qDAQpD,CAAC;AAEF,eA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