@nextsparkjs/plugin-ai 0.1.0-beta.49 → 0.1.0-beta.51

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.
@@ -10,6 +10,7 @@
10
10
  import { NextRequest, NextResponse } from 'next/server'
11
11
  import { auth } from '@nextsparkjs/core/lib/auth'
12
12
  import { AIHistoryService } from '@/plugins/ai/lib/ai-history-service'
13
+ import { withRateLimitTier } from '@nextsparkjs/core/lib/api/rate-limit'
13
14
 
14
15
  interface RouteParams {
15
16
  params: Promise<{
@@ -21,10 +22,10 @@ interface RouteParams {
21
22
  * PATCH /api/v1/plugin/ai/ai-history/:id
22
23
  * Update related entity information for an AI history record
23
24
  */
24
- export async function PATCH(
25
+ const patchHandler = async (
25
26
  request: NextRequest,
26
27
  { params }: RouteParams
27
- ): Promise<NextResponse> {
28
+ ): Promise<NextResponse> => {
28
29
  try {
29
30
  // Authenticate user
30
31
  const session = await auth.api.getSession({
@@ -110,3 +111,5 @@ export async function PATCH(
110
111
  )
111
112
  }
112
113
  }
114
+
115
+ export const PATCH = withRateLimitTier(patchHandler, 'write')
@@ -9,6 +9,7 @@ import { NextRequest, NextResponse } from 'next/server'
9
9
  import { validatePlugin, handleAIError } from '../../lib/core-utils'
10
10
  import { getServerPluginConfig } from '../../lib/server-env'
11
11
  import { authenticateRequest } from '@nextsparkjs/core/lib/api/auth/dual-auth'
12
+ import { withRateLimitTier } from '@nextsparkjs/core/lib/api/rate-limit'
12
13
  import { embed } from 'ai'
13
14
  import { openai } from '@ai-sdk/openai'
14
15
  import { z } from 'zod'
@@ -18,7 +19,7 @@ const EmbeddingRequestSchema = z.object({
18
19
  text: z.string().min(1, 'Text cannot be empty').max(50000, 'Text too long')
19
20
  })
20
21
 
21
- export async function POST(request: NextRequest) {
22
+ const postHandler = async (request: NextRequest) => {
22
23
  try {
23
24
  // 1. Authentication
24
25
  const authResult = await authenticateRequest(request)
@@ -80,10 +81,12 @@ export async function POST(request: NextRequest) {
80
81
  }
81
82
  }
82
83
 
84
+ export const POST = withRateLimitTier(postHandler, 'write')
85
+
83
86
  /**
84
87
  * Get endpoint info
85
88
  */
86
- export async function GET(): Promise<NextResponse> {
89
+ const getHandler = async (): Promise<NextResponse> => {
87
90
  return NextResponse.json({
88
91
  endpoint: '/api/v1/plugin/ai/embeddings',
89
92
  description: 'Generate text embeddings using OpenAI',
@@ -127,3 +130,5 @@ export async function GET(): Promise<NextResponse> {
127
130
  }
128
131
  })
129
132
  }
133
+
134
+ export const GET = withRateLimitTier(getHandler, 'read')
@@ -9,6 +9,7 @@ import { NextRequest, NextResponse } from 'next/server'
9
9
  import { selectModel, calculateCost, validatePlugin, extractTokens, handleAIError } from '../../lib/core-utils'
10
10
  import { getServerPluginConfig } from '../../lib/server-env'
11
11
  import { authenticateRequest } from '@nextsparkjs/core/lib/api/auth/dual-auth'
12
+ import { withRateLimitTier } from '@nextsparkjs/core/lib/api/rate-limit'
12
13
  import { generateText } from 'ai'
13
14
  import { saveExampleSafely } from '../../lib/save-example'
14
15
  import { z } from 'zod'
@@ -25,7 +26,7 @@ const GenerateRequestSchema = z.object({
25
26
  saveExample: z.boolean().optional().default(false)
26
27
  })
27
28
 
28
- export async function POST(request: NextRequest) {
29
+ const postHandler = async (request: NextRequest) => {
29
30
  try {
30
31
  // 1. Authentication
31
32
  const authResult = await authenticateRequest(request)
@@ -119,10 +120,12 @@ export async function POST(request: NextRequest) {
119
120
  }
120
121
  }
121
122
 
123
+ export const POST = withRateLimitTier(postHandler, 'write')
124
+
122
125
  /**
123
126
  * Get endpoint info
124
127
  */
125
- export async function GET(): Promise<NextResponse> {
128
+ const getHandler = async (): Promise<NextResponse> => {
126
129
  const config = await getServerPluginConfig()
127
130
 
128
131
  return NextResponse.json({
@@ -157,4 +160,6 @@ export async function GET(): Promise<NextResponse> {
157
160
  anthropic: 'Add ANTHROPIC_API_KEY to contents/plugins/ai/.env'
158
161
  }
159
162
  })
160
- }
163
+ }
164
+
165
+ export const GET = withRateLimitTier(getHandler, 'read')
@@ -57,46 +57,7 @@ export const aiHistoryEntityConfig: EntityConfig = {
57
57
  },
58
58
 
59
59
  // ==========================================
60
- // 4. PERMISSIONS SYSTEM
61
- // ==========================================
62
- permissions: {
63
- actions: [
64
- {
65
- action: 'create',
66
- label: 'Create AI history',
67
- description: 'Can create AI history entries (typically via API)',
68
- roles: ['owner', 'admin', 'member'],
69
- },
70
- {
71
- action: 'read',
72
- label: 'View AI history',
73
- description: 'Can view AI history entries (users see their own via API filtering)',
74
- roles: ['owner', 'admin', 'member'],
75
- },
76
- {
77
- action: 'list',
78
- label: 'List AI history',
79
- description: 'Can list AI history entries',
80
- roles: ['owner', 'admin', 'member'],
81
- },
82
- {
83
- action: 'update',
84
- label: 'Edit AI history',
85
- description: 'Can modify AI history entries (immutable for most users)',
86
- roles: ['owner', 'admin'],
87
- },
88
- {
89
- action: 'delete',
90
- label: 'Delete AI history',
91
- description: 'Can delete AI history entries (users can delete their own)',
92
- roles: ['owner', 'admin', 'member'],
93
- dangerous: true,
94
- },
95
- ],
96
- },
97
-
98
- // ==========================================
99
- // 5. INTERNATIONALIZATION
60
+ // 4. INTERNATIONALIZATION
100
61
  // ==========================================
101
62
  i18n: {
102
63
  fallbackLocale: 'en',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextsparkjs/plugin-ai",
3
- "version": "0.1.0-beta.49",
3
+ "version": "0.1.0-beta.51",
4
4
  "private": false,
5
5
  "main": "./plugin.config.ts",
6
6
  "requiredPlugins": [],
@@ -18,7 +18,7 @@
18
18
  "react": "^19.0.0",
19
19
  "react-dom": "^19.0.0",
20
20
  "zod": "^4.0.0",
21
- "@nextsparkjs/core": "0.1.0-beta.49"
21
+ "@nextsparkjs/core": "0.1.0-beta.51"
22
22
  },
23
23
  "nextspark": {
24
24
  "type": "plugin",