@kya-os/agentshield-nextjs 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-middleware.js +591 -12
- package/dist/create-middleware.js.map +1 -1
- package/dist/create-middleware.mjs +591 -12
- package/dist/create-middleware.mjs.map +1 -1
- package/dist/edge-detector-wrapper.js +251 -12
- package/dist/edge-detector-wrapper.js.map +1 -1
- package/dist/edge-detector-wrapper.mjs +251 -12
- package/dist/edge-detector-wrapper.mjs.map +1 -1
- package/dist/index.js +591 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +591 -12
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.js +587 -8
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +587 -8
- package/dist/middleware.mjs.map +1 -1
- package/dist/signature-verifier.js +220 -0
- package/dist/signature-verifier.js.map +1 -0
- package/dist/signature-verifier.mjs +216 -0
- package/dist/signature-verifier.mjs.map +1 -0
- package/package.json +2 -2
- package/wasm/agentshield_wasm.d.ts +121 -0
- package/wasm/agentshield_wasm.js +576 -0
- package/wasm/agentshield_wasm_bg.wasm +0 -0
- package/dist/create-middleware.d.mts +0 -16
- package/dist/create-middleware.d.ts +0 -16
- package/dist/edge-detector-wrapper.d.mts +0 -42
- package/dist/edge-detector-wrapper.d.ts +0 -42
- package/dist/edge-runtime-loader.d.mts +0 -49
- package/dist/edge-runtime-loader.d.ts +0 -49
- package/dist/edge-wasm-middleware.d.mts +0 -58
- package/dist/edge-wasm-middleware.d.ts +0 -58
- package/dist/index.d.mts +0 -19
- package/dist/index.d.ts +0 -19
- package/dist/middleware.d.mts +0 -20
- package/dist/middleware.d.ts +0 -20
- package/dist/nodejs-wasm-loader.d.mts +0 -25
- package/dist/nodejs-wasm-loader.d.ts +0 -25
- package/dist/session-tracker.d.mts +0 -55
- package/dist/session-tracker.d.ts +0 -55
- package/dist/types-BJTEUa4T.d.mts +0 -88
- package/dist/types-BJTEUa4T.d.ts +0 -88
- package/dist/wasm-middleware.d.mts +0 -62
- package/dist/wasm-middleware.d.ts +0 -62
- package/dist/wasm-setup.d.mts +0 -46
- package/dist/wasm-setup.d.ts +0 -46
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { NextRequest } from 'next/server';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Edge Runtime Compatible WASM Loader for AgentShield
|
|
5
|
-
*
|
|
6
|
-
* This module provides a pre-built solution for loading WASM in Edge Runtime.
|
|
7
|
-
* It requires the WASM file to be manually placed in the project.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
interface WasmModule {
|
|
11
|
-
default: WebAssembly.Module;
|
|
12
|
-
}
|
|
13
|
-
interface DetectionResult {
|
|
14
|
-
isAgent: boolean;
|
|
15
|
-
confidence: number;
|
|
16
|
-
agent?: string;
|
|
17
|
-
verificationMethod: 'cryptographic' | 'pattern';
|
|
18
|
-
riskLevel?: 'low' | 'medium' | 'high' | 'critical';
|
|
19
|
-
timestamp: string;
|
|
20
|
-
}
|
|
21
|
-
interface AgentShieldConfig {
|
|
22
|
-
wasmModule?: WebAssembly.Module;
|
|
23
|
-
enableWasm?: boolean;
|
|
24
|
-
onAgentDetected?: (result: DetectionResult) => void;
|
|
25
|
-
blockAgents?: boolean;
|
|
26
|
-
allowedAgents?: string[];
|
|
27
|
-
debug?: boolean;
|
|
28
|
-
}
|
|
29
|
-
declare class EdgeRuntimeAgentShield {
|
|
30
|
-
private wasmInstance;
|
|
31
|
-
private wasmMemory;
|
|
32
|
-
private config;
|
|
33
|
-
private initialized;
|
|
34
|
-
constructor(config?: AgentShieldConfig);
|
|
35
|
-
init(wasmModule?: WebAssembly.Module): Promise<void>;
|
|
36
|
-
private readString;
|
|
37
|
-
private writeString;
|
|
38
|
-
detect(request: NextRequest): Promise<DetectionResult>;
|
|
39
|
-
private patternDetection;
|
|
40
|
-
isInitialized(): boolean;
|
|
41
|
-
getVerificationMethod(): 'cryptographic' | 'pattern';
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Factory function to create an AgentShield instance for Edge Runtime
|
|
45
|
-
*/
|
|
46
|
-
declare function createEdgeAgentShield(config?: AgentShieldConfig): EdgeRuntimeAgentShield;
|
|
47
|
-
declare function getDefaultAgentShield(config?: AgentShieldConfig): EdgeRuntimeAgentShield;
|
|
48
|
-
|
|
49
|
-
export { type AgentShieldConfig, type DetectionResult, type WasmModule, createEdgeAgentShield, createEdgeAgentShield as default, getDefaultAgentShield };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { NextRequest } from 'next/server';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Edge Runtime Compatible WASM Loader for AgentShield
|
|
5
|
-
*
|
|
6
|
-
* This module provides a pre-built solution for loading WASM in Edge Runtime.
|
|
7
|
-
* It requires the WASM file to be manually placed in the project.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
interface WasmModule {
|
|
11
|
-
default: WebAssembly.Module;
|
|
12
|
-
}
|
|
13
|
-
interface DetectionResult {
|
|
14
|
-
isAgent: boolean;
|
|
15
|
-
confidence: number;
|
|
16
|
-
agent?: string;
|
|
17
|
-
verificationMethod: 'cryptographic' | 'pattern';
|
|
18
|
-
riskLevel?: 'low' | 'medium' | 'high' | 'critical';
|
|
19
|
-
timestamp: string;
|
|
20
|
-
}
|
|
21
|
-
interface AgentShieldConfig {
|
|
22
|
-
wasmModule?: WebAssembly.Module;
|
|
23
|
-
enableWasm?: boolean;
|
|
24
|
-
onAgentDetected?: (result: DetectionResult) => void;
|
|
25
|
-
blockAgents?: boolean;
|
|
26
|
-
allowedAgents?: string[];
|
|
27
|
-
debug?: boolean;
|
|
28
|
-
}
|
|
29
|
-
declare class EdgeRuntimeAgentShield {
|
|
30
|
-
private wasmInstance;
|
|
31
|
-
private wasmMemory;
|
|
32
|
-
private config;
|
|
33
|
-
private initialized;
|
|
34
|
-
constructor(config?: AgentShieldConfig);
|
|
35
|
-
init(wasmModule?: WebAssembly.Module): Promise<void>;
|
|
36
|
-
private readString;
|
|
37
|
-
private writeString;
|
|
38
|
-
detect(request: NextRequest): Promise<DetectionResult>;
|
|
39
|
-
private patternDetection;
|
|
40
|
-
isInitialized(): boolean;
|
|
41
|
-
getVerificationMethod(): 'cryptographic' | 'pattern';
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Factory function to create an AgentShield instance for Edge Runtime
|
|
45
|
-
*/
|
|
46
|
-
declare function createEdgeAgentShield(config?: AgentShieldConfig): EdgeRuntimeAgentShield;
|
|
47
|
-
declare function getDefaultAgentShield(config?: AgentShieldConfig): EdgeRuntimeAgentShield;
|
|
48
|
-
|
|
49
|
-
export { type AgentShieldConfig, type DetectionResult, type WasmModule, createEdgeAgentShield, createEdgeAgentShield as default, getDefaultAgentShield };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Edge Runtime Compatible WASM Middleware for AgentShield
|
|
5
|
-
*
|
|
6
|
-
* This module provides WASM-based AI agent detection with 95-100% confidence
|
|
7
|
-
* in Next.js Edge Runtime and Vercel Edge Functions.
|
|
8
|
-
*
|
|
9
|
-
* IMPORTANT: WebAssembly.instantiate(module) IS supported in Edge Runtime
|
|
10
|
-
* when using a pre-compiled module imported with ?module suffix.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
interface EdgeWasmDetectionResult {
|
|
14
|
-
isAgent: boolean;
|
|
15
|
-
confidence: number;
|
|
16
|
-
agent?: string;
|
|
17
|
-
verificationMethod: 'signature' | 'pattern' | 'wasm';
|
|
18
|
-
riskLevel: 'low' | 'medium' | 'high';
|
|
19
|
-
timestamp: string;
|
|
20
|
-
reasons?: string[];
|
|
21
|
-
}
|
|
22
|
-
interface EdgeAgentShieldConfig {
|
|
23
|
-
onAgentDetected?: (result: EdgeWasmDetectionResult) => void | Promise<void>;
|
|
24
|
-
blockOnHighConfidence?: boolean;
|
|
25
|
-
confidenceThreshold?: number;
|
|
26
|
-
skipPaths?: string[];
|
|
27
|
-
blockedResponse?: {
|
|
28
|
-
status?: number;
|
|
29
|
-
message?: string;
|
|
30
|
-
headers?: Record<string, string>;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Initialize WASM module with proper imports for Edge Runtime
|
|
35
|
-
*/
|
|
36
|
-
declare function initializeEdgeWasm(wasmModule: WebAssembly.Module): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Create Edge Runtime compatible WASM middleware
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* // middleware.ts
|
|
43
|
-
* import wasmModule from '@kya-os/agentshield/wasm?module';
|
|
44
|
-
* import { createEdgeWasmMiddleware } from '@kya-os/agentshield-nextjs/edge-wasm-middleware';
|
|
45
|
-
*
|
|
46
|
-
* export const middleware = createEdgeWasmMiddleware({
|
|
47
|
-
* wasmModule,
|
|
48
|
-
* onAgentDetected: (result) => {
|
|
49
|
-
* console.log(`AI Agent: ${result.agent} (${result.confidence * 100}% confidence)`);
|
|
50
|
-
* }
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
declare function createEdgeWasmMiddleware(config: EdgeAgentShieldConfig & {
|
|
55
|
-
wasmModule: WebAssembly.Module;
|
|
56
|
-
}): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
57
|
-
|
|
58
|
-
export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, createEdgeWasmMiddleware, initializeEdgeWasm };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Edge Runtime Compatible WASM Middleware for AgentShield
|
|
5
|
-
*
|
|
6
|
-
* This module provides WASM-based AI agent detection with 95-100% confidence
|
|
7
|
-
* in Next.js Edge Runtime and Vercel Edge Functions.
|
|
8
|
-
*
|
|
9
|
-
* IMPORTANT: WebAssembly.instantiate(module) IS supported in Edge Runtime
|
|
10
|
-
* when using a pre-compiled module imported with ?module suffix.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
interface EdgeWasmDetectionResult {
|
|
14
|
-
isAgent: boolean;
|
|
15
|
-
confidence: number;
|
|
16
|
-
agent?: string;
|
|
17
|
-
verificationMethod: 'signature' | 'pattern' | 'wasm';
|
|
18
|
-
riskLevel: 'low' | 'medium' | 'high';
|
|
19
|
-
timestamp: string;
|
|
20
|
-
reasons?: string[];
|
|
21
|
-
}
|
|
22
|
-
interface EdgeAgentShieldConfig {
|
|
23
|
-
onAgentDetected?: (result: EdgeWasmDetectionResult) => void | Promise<void>;
|
|
24
|
-
blockOnHighConfidence?: boolean;
|
|
25
|
-
confidenceThreshold?: number;
|
|
26
|
-
skipPaths?: string[];
|
|
27
|
-
blockedResponse?: {
|
|
28
|
-
status?: number;
|
|
29
|
-
message?: string;
|
|
30
|
-
headers?: Record<string, string>;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Initialize WASM module with proper imports for Edge Runtime
|
|
35
|
-
*/
|
|
36
|
-
declare function initializeEdgeWasm(wasmModule: WebAssembly.Module): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Create Edge Runtime compatible WASM middleware
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* // middleware.ts
|
|
43
|
-
* import wasmModule from '@kya-os/agentshield/wasm?module';
|
|
44
|
-
* import { createEdgeWasmMiddleware } from '@kya-os/agentshield-nextjs/edge-wasm-middleware';
|
|
45
|
-
*
|
|
46
|
-
* export const middleware = createEdgeWasmMiddleware({
|
|
47
|
-
* wasmModule,
|
|
48
|
-
* onAgentDetected: (result) => {
|
|
49
|
-
* console.log(`AI Agent: ${result.agent} (${result.confidence * 100}% confidence)`);
|
|
50
|
-
* }
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
declare function createEdgeWasmMiddleware(config: EdgeAgentShieldConfig & {
|
|
55
|
-
wasmModule: WebAssembly.Module;
|
|
56
|
-
}): (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
57
|
-
|
|
58
|
-
export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, createEdgeWasmMiddleware, initializeEdgeWasm };
|
package/dist/index.d.mts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export { createMiddleware as createAgentShieldMiddleware, createMiddleware } from './create-middleware.mjs';
|
|
2
|
-
export { createAgentShieldMiddleware as createAgentShieldMiddlewareBase } from './middleware.mjs';
|
|
3
|
-
export { EdgeSessionTracker, SessionData, SessionTrackingConfig, StatelessSessionChecker } from './session-tracker.mjs';
|
|
4
|
-
export { D as DetectionContext, N as NextJSMiddlewareConfig } from './types-BJTEUa4T.mjs';
|
|
5
|
-
import 'next/server';
|
|
6
|
-
import '@kya-os/agentshield';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @fileoverview AgentShield Next.js Integration
|
|
10
|
-
* @version 0.1.0
|
|
11
|
-
* @license MIT OR Apache-2.0
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Library version
|
|
16
|
-
*/
|
|
17
|
-
declare const VERSION = "0.1.0";
|
|
18
|
-
|
|
19
|
-
export { VERSION };
|
package/dist/index.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export { createMiddleware as createAgentShieldMiddleware, createMiddleware } from './create-middleware.js';
|
|
2
|
-
export { createAgentShieldMiddleware as createAgentShieldMiddlewareBase } from './middleware.js';
|
|
3
|
-
export { EdgeSessionTracker, SessionData, SessionTrackingConfig, StatelessSessionChecker } from './session-tracker.js';
|
|
4
|
-
export { D as DetectionContext, N as NextJSMiddlewareConfig } from './types-BJTEUa4T.js';
|
|
5
|
-
import 'next/server';
|
|
6
|
-
import '@kya-os/agentshield';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @fileoverview AgentShield Next.js Integration
|
|
10
|
-
* @version 0.1.0
|
|
11
|
-
* @license MIT OR Apache-2.0
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Library version
|
|
16
|
-
*/
|
|
17
|
-
declare const VERSION = "0.1.0";
|
|
18
|
-
|
|
19
|
-
export { VERSION };
|
package/dist/middleware.d.mts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { N as NextJSMiddlewareConfig } from './types-BJTEUa4T.mjs';
|
|
3
|
-
import '@kya-os/agentshield';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Next.js middleware for AgentShield
|
|
7
|
-
*
|
|
8
|
-
* Uses edge-safe imports to avoid WASM in Edge Runtime
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Create AgentShield middleware for Next.js
|
|
13
|
-
*/
|
|
14
|
-
declare function createAgentShieldMiddleware(config?: Partial<NextJSMiddlewareConfig>): (request: NextRequest) => Promise<NextResponse>;
|
|
15
|
-
/**
|
|
16
|
-
* Convenience function for basic setup
|
|
17
|
-
*/
|
|
18
|
-
declare function agentShield(config?: Partial<NextJSMiddlewareConfig>): (request: NextRequest) => Promise<NextResponse>;
|
|
19
|
-
|
|
20
|
-
export { agentShield, createAgentShieldMiddleware };
|
package/dist/middleware.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { N as NextJSMiddlewareConfig } from './types-BJTEUa4T.js';
|
|
3
|
-
import '@kya-os/agentshield';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Next.js middleware for AgentShield
|
|
7
|
-
*
|
|
8
|
-
* Uses edge-safe imports to avoid WASM in Edge Runtime
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Create AgentShield middleware for Next.js
|
|
13
|
-
*/
|
|
14
|
-
declare function createAgentShieldMiddleware(config?: Partial<NextJSMiddlewareConfig>): (request: NextRequest) => Promise<NextResponse>;
|
|
15
|
-
/**
|
|
16
|
-
* Convenience function for basic setup
|
|
17
|
-
*/
|
|
18
|
-
declare function agentShield(config?: Partial<NextJSMiddlewareConfig>): (request: NextRequest) => Promise<NextResponse>;
|
|
19
|
-
|
|
20
|
-
export { agentShield, createAgentShieldMiddleware };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js Runtime WASM Loader for AgentShield
|
|
3
|
-
*
|
|
4
|
-
* This loader uses fs.readFileSync to load WASM in Node.js runtime.
|
|
5
|
-
* It provides full cryptographic verification capabilities.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Load WASM module using Node.js fs module
|
|
9
|
-
* This only works in Node.js runtime, not Edge Runtime
|
|
10
|
-
*/
|
|
11
|
-
declare function loadWasmNodejs(): Promise<boolean>;
|
|
12
|
-
/**
|
|
13
|
-
* Check if we're in Node.js runtime
|
|
14
|
-
*/
|
|
15
|
-
declare function isNodejsRuntime(): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Get the loaded WASM module
|
|
18
|
-
*/
|
|
19
|
-
declare function getWasmModule(): WebAssembly.Module | null;
|
|
20
|
-
/**
|
|
21
|
-
* Check if WASM is initialized
|
|
22
|
-
*/
|
|
23
|
-
declare function isWasmInitialized(): boolean;
|
|
24
|
-
|
|
25
|
-
export { getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node.js Runtime WASM Loader for AgentShield
|
|
3
|
-
*
|
|
4
|
-
* This loader uses fs.readFileSync to load WASM in Node.js runtime.
|
|
5
|
-
* It provides full cryptographic verification capabilities.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Load WASM module using Node.js fs module
|
|
9
|
-
* This only works in Node.js runtime, not Edge Runtime
|
|
10
|
-
*/
|
|
11
|
-
declare function loadWasmNodejs(): Promise<boolean>;
|
|
12
|
-
/**
|
|
13
|
-
* Check if we're in Node.js runtime
|
|
14
|
-
*/
|
|
15
|
-
declare function isNodejsRuntime(): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Get the loaded WASM module
|
|
18
|
-
*/
|
|
19
|
-
declare function getWasmModule(): WebAssembly.Module | null;
|
|
20
|
-
/**
|
|
21
|
-
* Check if WASM is initialized
|
|
22
|
-
*/
|
|
23
|
-
declare function isWasmInitialized(): boolean;
|
|
24
|
-
|
|
25
|
-
export { getWasmModule, isNodejsRuntime, isWasmInitialized, loadWasmNodejs };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { DetectionResult } from '@kya-os/agentshield';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Edge-compatible session tracking for AI agents
|
|
6
|
-
* Uses cookie-based storage to work in Edge Runtime
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
interface SessionData {
|
|
10
|
-
id: string;
|
|
11
|
-
agent: string;
|
|
12
|
-
confidence: number;
|
|
13
|
-
detectedAt: number;
|
|
14
|
-
expires: number;
|
|
15
|
-
}
|
|
16
|
-
interface SessionTrackingConfig {
|
|
17
|
-
enabled: boolean;
|
|
18
|
-
cookieName?: string;
|
|
19
|
-
cookieMaxAge?: number;
|
|
20
|
-
encryptionKey?: string;
|
|
21
|
-
}
|
|
22
|
-
declare class EdgeSessionTracker {
|
|
23
|
-
private readonly config;
|
|
24
|
-
constructor(config: SessionTrackingConfig);
|
|
25
|
-
/**
|
|
26
|
-
* Track a new AI agent session
|
|
27
|
-
*/
|
|
28
|
-
track(_request: NextRequest, response: NextResponse, result: DetectionResult): Promise<NextResponse>;
|
|
29
|
-
/**
|
|
30
|
-
* Check for existing AI agent session
|
|
31
|
-
*/
|
|
32
|
-
check(request: NextRequest): Promise<SessionData | null>;
|
|
33
|
-
/**
|
|
34
|
-
* Clear an existing session
|
|
35
|
-
*/
|
|
36
|
-
clear(response: NextResponse): NextResponse;
|
|
37
|
-
/**
|
|
38
|
-
* Simple encryption using Web Crypto API (Edge-compatible)
|
|
39
|
-
*/
|
|
40
|
-
private encrypt;
|
|
41
|
-
/**
|
|
42
|
-
* Simple decryption (Edge-compatible)
|
|
43
|
-
*/
|
|
44
|
-
private decrypt;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Stateless session checker for non-Next.js environments (Express, etc.)
|
|
48
|
-
* Uses a combination of headers to identify continued sessions
|
|
49
|
-
*/
|
|
50
|
-
declare class StatelessSessionChecker {
|
|
51
|
-
static check(headers: Record<string, string>): SessionData | null;
|
|
52
|
-
static setHeaders(response: any, session: SessionData): void;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { EdgeSessionTracker, type SessionData, type SessionTrackingConfig, StatelessSessionChecker };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { DetectionResult } from '@kya-os/agentshield';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Edge-compatible session tracking for AI agents
|
|
6
|
-
* Uses cookie-based storage to work in Edge Runtime
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
interface SessionData {
|
|
10
|
-
id: string;
|
|
11
|
-
agent: string;
|
|
12
|
-
confidence: number;
|
|
13
|
-
detectedAt: number;
|
|
14
|
-
expires: number;
|
|
15
|
-
}
|
|
16
|
-
interface SessionTrackingConfig {
|
|
17
|
-
enabled: boolean;
|
|
18
|
-
cookieName?: string;
|
|
19
|
-
cookieMaxAge?: number;
|
|
20
|
-
encryptionKey?: string;
|
|
21
|
-
}
|
|
22
|
-
declare class EdgeSessionTracker {
|
|
23
|
-
private readonly config;
|
|
24
|
-
constructor(config: SessionTrackingConfig);
|
|
25
|
-
/**
|
|
26
|
-
* Track a new AI agent session
|
|
27
|
-
*/
|
|
28
|
-
track(_request: NextRequest, response: NextResponse, result: DetectionResult): Promise<NextResponse>;
|
|
29
|
-
/**
|
|
30
|
-
* Check for existing AI agent session
|
|
31
|
-
*/
|
|
32
|
-
check(request: NextRequest): Promise<SessionData | null>;
|
|
33
|
-
/**
|
|
34
|
-
* Clear an existing session
|
|
35
|
-
*/
|
|
36
|
-
clear(response: NextResponse): NextResponse;
|
|
37
|
-
/**
|
|
38
|
-
* Simple encryption using Web Crypto API (Edge-compatible)
|
|
39
|
-
*/
|
|
40
|
-
private encrypt;
|
|
41
|
-
/**
|
|
42
|
-
* Simple decryption (Edge-compatible)
|
|
43
|
-
*/
|
|
44
|
-
private decrypt;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Stateless session checker for non-Next.js environments (Express, etc.)
|
|
48
|
-
* Uses a combination of headers to identify continued sessions
|
|
49
|
-
*/
|
|
50
|
-
declare class StatelessSessionChecker {
|
|
51
|
-
static check(headers: Record<string, string>): SessionData | null;
|
|
52
|
-
static setHeaders(response: any, session: SessionData): void;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { EdgeSessionTracker, type SessionData, type SessionTrackingConfig, StatelessSessionChecker };
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { AgentShieldConfig, DetectionResult, AgentShieldEvents } from '@kya-os/agentshield';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Next.js-specific type definitions
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Next.js middleware configuration
|
|
10
|
-
*/
|
|
11
|
-
interface NextJSMiddlewareConfig extends Partial<AgentShieldConfig> {
|
|
12
|
-
/**
|
|
13
|
-
* Action to take when an agent is detected
|
|
14
|
-
*/
|
|
15
|
-
onAgentDetected?: 'block' | 'redirect' | 'rewrite' | 'allow' | 'log';
|
|
16
|
-
/**
|
|
17
|
-
* Custom handler for agent detection
|
|
18
|
-
* @deprecated Use 'events' instead. Will be removed in v1.0.0
|
|
19
|
-
*/
|
|
20
|
-
onDetection?: (req: NextRequest, result: DetectionResult) => NextResponse | Promise<NextResponse> | void | Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Event handlers for detection events
|
|
23
|
-
*/
|
|
24
|
-
events?: Partial<AgentShieldEvents>;
|
|
25
|
-
/**
|
|
26
|
-
* Path patterns to skip detection
|
|
27
|
-
*/
|
|
28
|
-
skipPaths?: string[] | RegExp[];
|
|
29
|
-
/**
|
|
30
|
-
* Response when blocking agents
|
|
31
|
-
*/
|
|
32
|
-
blockedResponse?: {
|
|
33
|
-
status: number;
|
|
34
|
-
message: string;
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Redirect URL when redirecting detected agents
|
|
39
|
-
*/
|
|
40
|
-
redirectUrl?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Rewrite URL when rewriting requests from detected agents
|
|
43
|
-
*/
|
|
44
|
-
rewriteUrl?: string;
|
|
45
|
-
/**
|
|
46
|
-
* Confidence threshold for agent detection
|
|
47
|
-
*/
|
|
48
|
-
confidenceThreshold?: number;
|
|
49
|
-
/**
|
|
50
|
-
* Enable WASM for enhanced detection
|
|
51
|
-
*/
|
|
52
|
-
enableWasm?: boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Session tracking configuration
|
|
55
|
-
*/
|
|
56
|
-
sessionTracking?: {
|
|
57
|
-
/**
|
|
58
|
-
* Enable session tracking
|
|
59
|
-
*/
|
|
60
|
-
enabled: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Cookie name for session storage
|
|
63
|
-
* Default: '__agentshield_session'
|
|
64
|
-
*/
|
|
65
|
-
cookieName?: string;
|
|
66
|
-
/**
|
|
67
|
-
* Cookie max age in seconds
|
|
68
|
-
* Default: 3600 (1 hour)
|
|
69
|
-
*/
|
|
70
|
-
cookieMaxAge?: number;
|
|
71
|
-
/**
|
|
72
|
-
* Encryption key for session data
|
|
73
|
-
* Default: Uses AGENTSHIELD_SECRET env var or default key
|
|
74
|
-
*/
|
|
75
|
-
encryptionKey?: string;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Detection context for hooks
|
|
80
|
-
*/
|
|
81
|
-
interface DetectionContext {
|
|
82
|
-
result: DetectionResult;
|
|
83
|
-
request: NextRequest;
|
|
84
|
-
userAgent?: string;
|
|
85
|
-
ip?: string;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export type { DetectionContext as D, NextJSMiddlewareConfig as N };
|
package/dist/types-BJTEUa4T.d.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { AgentShieldConfig, DetectionResult, AgentShieldEvents } from '@kya-os/agentshield';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Next.js-specific type definitions
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Next.js middleware configuration
|
|
10
|
-
*/
|
|
11
|
-
interface NextJSMiddlewareConfig extends Partial<AgentShieldConfig> {
|
|
12
|
-
/**
|
|
13
|
-
* Action to take when an agent is detected
|
|
14
|
-
*/
|
|
15
|
-
onAgentDetected?: 'block' | 'redirect' | 'rewrite' | 'allow' | 'log';
|
|
16
|
-
/**
|
|
17
|
-
* Custom handler for agent detection
|
|
18
|
-
* @deprecated Use 'events' instead. Will be removed in v1.0.0
|
|
19
|
-
*/
|
|
20
|
-
onDetection?: (req: NextRequest, result: DetectionResult) => NextResponse | Promise<NextResponse> | void | Promise<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Event handlers for detection events
|
|
23
|
-
*/
|
|
24
|
-
events?: Partial<AgentShieldEvents>;
|
|
25
|
-
/**
|
|
26
|
-
* Path patterns to skip detection
|
|
27
|
-
*/
|
|
28
|
-
skipPaths?: string[] | RegExp[];
|
|
29
|
-
/**
|
|
30
|
-
* Response when blocking agents
|
|
31
|
-
*/
|
|
32
|
-
blockedResponse?: {
|
|
33
|
-
status: number;
|
|
34
|
-
message: string;
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Redirect URL when redirecting detected agents
|
|
39
|
-
*/
|
|
40
|
-
redirectUrl?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Rewrite URL when rewriting requests from detected agents
|
|
43
|
-
*/
|
|
44
|
-
rewriteUrl?: string;
|
|
45
|
-
/**
|
|
46
|
-
* Confidence threshold for agent detection
|
|
47
|
-
*/
|
|
48
|
-
confidenceThreshold?: number;
|
|
49
|
-
/**
|
|
50
|
-
* Enable WASM for enhanced detection
|
|
51
|
-
*/
|
|
52
|
-
enableWasm?: boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Session tracking configuration
|
|
55
|
-
*/
|
|
56
|
-
sessionTracking?: {
|
|
57
|
-
/**
|
|
58
|
-
* Enable session tracking
|
|
59
|
-
*/
|
|
60
|
-
enabled: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Cookie name for session storage
|
|
63
|
-
* Default: '__agentshield_session'
|
|
64
|
-
*/
|
|
65
|
-
cookieName?: string;
|
|
66
|
-
/**
|
|
67
|
-
* Cookie max age in seconds
|
|
68
|
-
* Default: 3600 (1 hour)
|
|
69
|
-
*/
|
|
70
|
-
cookieMaxAge?: number;
|
|
71
|
-
/**
|
|
72
|
-
* Encryption key for session data
|
|
73
|
-
* Default: Uses AGENTSHIELD_SECRET env var or default key
|
|
74
|
-
*/
|
|
75
|
-
encryptionKey?: string;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Detection context for hooks
|
|
80
|
-
*/
|
|
81
|
-
interface DetectionContext {
|
|
82
|
-
result: DetectionResult;
|
|
83
|
-
request: NextRequest;
|
|
84
|
-
userAgent?: string;
|
|
85
|
-
ip?: string;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export type { DetectionContext as D, NextJSMiddlewareConfig as N };
|