Skip to content

Commit 8906b30

Browse files
authored
Merge pull request #37 from ssdeanx/develop
feat: Implement core services for validation, vector querying, storag…
2 parents e603cbe + 18dbe3b commit 8906b30

18 files changed

Lines changed: 2436 additions & 31 deletions

src/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
logProgress,
77
log,
88
} from '../mastra/config/logger'
9-
import { tierManagementService } from '../mastra/config/tier-management-service'
9+
import { tierManagementService } from '../mastra/services/tier-management-service'
1010
import type { SubscriptionTier } from '../mastra/config/role-hierarchy'
1111
import * as dotenv from 'dotenv'
1212
import * as fs from 'fs/promises'

src/mastra/agents/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export type { EditorRuntimeContext } from "./editorAgent";
22
export type { ResearchRuntimeContext } from "./researchAgent";
33
export type { WeatherRuntimeContext } from "./weather-agent";
4-
export type { SqlAgentRuntimeContext } from "./sql";
54
export type { ReportRuntimeContext } from "./reportAgent";
65
export type { ImageRuntimeContext } from "./image";
76
export type { StockRuntimeContext } from "./stockAnalysisAgent";
@@ -47,7 +46,6 @@ export { reportAgent } from "./reportAgent";
4746
export { researchAgent } from "./researchAgent";
4847
export { researchPaperAgent } from "./researchPaperAgent";
4948
export { scriptWriterAgent } from "./scriptWriterAgent";
50-
export { sqlAgent } from "./sql";
5149
export { stockAnalysisAgent } from "./stockAnalysisAgent";
5250
export { weatherAgent } from "./weather-agent";
5351

src/mastra/config/role-hierarchy.ts

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,60 @@ export function getInheritorRoles(targetRole: string): string[] {
116116
* Supabase-compatible tier configuration
117117
*/
118118
export interface TierConfig {
119-
maxRequests: number
119+
// Backwards-compatible: maxRequests remains for legacy callers
120+
maxRequests?: number
121+
// Explicit quotas used throughout services
122+
maxDocuments: number
123+
maxApiRequestsPerDay: number
124+
maxUsersPerTenant: number
120125
features: string[]
121126
rlsPolicy: string
127+
supportLevel?: 'community' | 'email' | 'priority' | 'phone_24x7'
128+
customIntegrations?: boolean
129+
advancedAnalytics?: boolean
130+
whiteLabel?: boolean
131+
onPremise?: boolean
122132
}
123133

124134
export const TIER_CONFIGS: Record<SubscriptionTier, TierConfig> = {
125135
free: {
126136
maxRequests: 100,
137+
maxDocuments: 250,
138+
maxApiRequestsPerDay: 100,
139+
maxUsersPerTenant: 1,
127140
features: ['basic-chat', 'public-docs'],
128141
rlsPolicy: RLS_POLICIES.publicRead,
142+
supportLevel: 'community',
143+
customIntegrations: false,
144+
advancedAnalytics: false,
145+
whiteLabel: false,
146+
onPremise: false,
129147
},
130148
pro: {
131149
maxRequests: 10000,
150+
maxDocuments: 10000,
151+
maxApiRequestsPerDay: 10000,
152+
maxUsersPerTenant: 100,
132153
features: ['advanced-chat', 'private-docs', 'api-access'],
133154
rlsPolicy: RLS_POLICIES.proFeatures,
155+
supportLevel: 'email',
156+
customIntegrations: true,
157+
advancedAnalytics: true,
158+
whiteLabel: false,
159+
onPremise: false,
134160
},
135161
enterprise: {
136162
maxRequests: -1, // unlimited
163+
maxDocuments: -1,
164+
maxApiRequestsPerDay: -1,
165+
maxUsersPerTenant: -1,
137166
features: ['unlimited-chat', 'all-docs', 'custom-models', 'admin-panel'],
138167
rlsPolicy: RLS_POLICIES.enterpriseFeatures,
168+
supportLevel: 'priority',
169+
customIntegrations: true,
170+
advancedAnalytics: true,
171+
whiteLabel: true,
172+
onPremise: true,
139173
},
140174
}
141175

@@ -146,13 +180,40 @@ export function getTierConfig(tier: SubscriptionTier): TierConfig {
146180
return TIER_CONFIGS[tier]
147181
}
148182

183+
/**
184+
* Backwards-compatible tier quota accessor used by services
185+
*/
186+
export function getTierQuota(tier: SubscriptionTier): {
187+
maxDocuments: number
188+
maxApiRequestsPerDay: number
189+
maxUsersPerTenant: number
190+
features: string[]
191+
rlsPolicy: string
192+
} {
193+
const cfg = getTierConfig(tier)
194+
return {
195+
maxDocuments: cfg.maxDocuments,
196+
maxApiRequestsPerDay: cfg.maxApiRequestsPerDay,
197+
maxUsersPerTenant: cfg.maxUsersPerTenant,
198+
features: cfg.features,
199+
rlsPolicy: cfg.rlsPolicy,
200+
}
201+
}
202+
149203
/**
150204
* Check if a feature is available in a tier
151205
*/
152206
export function hasFeature(tier: SubscriptionTier, feature: string): boolean {
153207
return TIER_CONFIGS[tier].features.includes(feature)
154208
}
155209

210+
/**
211+
* Backwards-compatible feature check
212+
*/
213+
export function isTierFeatureEnabled(tier: SubscriptionTier, feature: string) {
214+
return hasFeature(tier, feature)
215+
}
216+
156217
/**
157218
* Get the minimum tier required for a role
158219
*/
@@ -169,6 +230,24 @@ export function getTierForRole(role: string): SubscriptionTier {
169230
return 'free'
170231
}
171232

233+
/**
234+
* Minimum tier required for a given classification level
235+
*/
236+
export function getMinimumTierForClassification(
237+
classification: 'public' | 'internal' | 'confidential'
238+
): SubscriptionTier {
239+
switch (classification) {
240+
case 'public':
241+
return 'free'
242+
case 'internal':
243+
return 'pro'
244+
case 'confidential':
245+
return 'enterprise'
246+
default:
247+
return 'free'
248+
}
249+
}
250+
172251
/**
173252
* Supabase RLS Policy Generator
174253
* Returns the appropriate policy for a given role

src/mastra/experiments/agent-experiments.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createScorer, runEvals } from '@mastra/core/evals';
22
import { contentStrategistAgent } from '../agents/contentStrategistAgent'
3-
import { sqlAgent } from '../agents/sql'
43
import { copywriterAgent } from '../agents/copywriterAgent'
54
import { scriptWriterAgent } from '../agents/scriptWriterAgent'
65
import { stockAnalysisAgent } from '../agents/stockAnalysisAgent'
@@ -45,27 +44,6 @@ export async function runContentStrategistExperiment() {
4544
return results
4645
}
4746

48-
export async function runSqlAgentExperiment() {
49-
console.log('Running SQL Agent Experiment...')
50-
const results = await runEvals({
51-
target: sqlAgent,
52-
data: [
53-
{
54-
input: 'What are the top 5 most populous cities in Europe?',
55-
},
56-
{
57-
input: 'List all cities in France with a population over 1 million.',
58-
},
59-
{
60-
input: 'Show me the average population of cities in Asia.',
61-
}
62-
],
63-
scorers: [sqlValidityScorer, responseQualityScorer]
64-
})
65-
console.log('SQL Agent Experiment Results:', JSON.stringify(results, null, 2))
66-
return results
67-
}
68-
6947
export async function runCopywriterExperiment() {
7048
console.log('Running Copywriter Experiment...')
7149
const results = await runEvals({
@@ -221,7 +199,6 @@ export async function runWeatherAgentExperiment() {
221199

222200
export async function runAllExperiments(p0: unknown) {
223201
await runContentStrategistExperiment()
224-
await runSqlAgentExperiment()
225202
await runCopywriterExperiment()
226203
await runScriptWriterExperiment()
227204
await runStockAnalysisExperiment()

src/mastra/services/AGENTS.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!-- AGENTS-META {"title":"Mastra Services","version":"1.2.0","last_updated":"2025-10-15T17:01:00Z","applies_to":"/src/mastra/services","tags":["layer:backend","domain:rag","type:services","status":"stable"],"status":"stable"} -->
2+
3+
# Services Directory (`/src/mastra/services`)
4+
5+
## Persona
6+
7+
**Name:** Senior Backend Engineer
8+
**Role Objective:** Encapsulate stateless, reusable domain and infrastructure logic consumed by tools and workflow steps.
9+
10+
## Purpose
11+
12+
Provide single-responsibility functional units (auth, role expansion, vector retrieval, document processing, embedding, storage, validation) enabling higher-level orchestration layers to remain thin and declarative.
13+
14+
## Key Files
15+
16+
| File | Responsibility | Notes |
17+
| ----------------------------- | -------------------------------------- | ------------------------------------- |
18+
| `AuthenticationService.ts` | JWT verification & policy seed | Coordinate with jwt-auth.tool |
19+
| `RoleService.ts` | Role expansion & hierarchy logic | Aligns with `role-hierarchy.ts` |
20+
| `VectorQueryService.ts` | Secure filtered vector search assembly | Applies classification & role filters |
21+
| `DocumentProcessorService.ts` | High-level indexing orchestration | Calls chunk, embed, store services |
22+
| `DocumentIndexingService.ts` | Document indexing coordination | Orchestrates the indexing pipeline |
23+
| `ChunkingService.ts` | Strategy-based text segmentation | Tune chunk sizes & overlap |
24+
| `EmbeddingService.ts` | Embedding generation & batching | Retry & backoff logic |
25+
| `VectorStorageService.ts` | Persistence into PostgreSQL with PgVector | Attaches security tags |
26+
| `RateLimitingService.ts` | Request rate limiting & throttling | Prevents abuse and ensures fair usage |
27+
| `TierManagementService.ts` | User tier management & upgrades | Handles subscription and feature access|
28+
| `ValidationService.ts` | Common validation helpers | Env & structural guards |
29+
| `WorkflowDecorators.ts` | Step wrapper utilities | Logging, timing, error wrapping |
30+
31+
## Change Log
32+
33+
| Version | Date (UTC) | Change |
34+
| ------- | ---------- | ------------------------------------------------------- |
35+
| 1.2.0 | 2025-10-15 | Added missing DocumentIndexingService.ts, RateLimitingService.ts, and TierManagementService.ts to documentation |
36+
| 1.1.0 | 2025-10-08 | Verified content accuracy and updated metadata. |
37+
| 1.0.0 | 2025-09-24 | Standardized template applied; legacy content preserved |

src/mastra/config/AuthenticationService.ts renamed to src/mastra/services/AuthenticationService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { jwtVerify } from 'jose'
22

33
import { ValidationService } from './ValidationService'
4-
import { RoleService } from './role-service'
4+
import { RoleService } from './RoleService'
55
import { log } from '../config/logger'
66

77
export interface JWTClaims {

0 commit comments

Comments
 (0)