substrai-agentdeploy 0.4.0
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/agent.d.ts +13 -0
- package/dist/agent.js +6 -0
- package/dist/cost.d.ts +15 -0
- package/dist/cost.js +33 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +17 -0
- package/dist/session.d.ts +22 -0
- package/dist/session.js +38 -0
- package/dist/tenants.d.ts +16 -0
- package/dist/tenants.js +16 -0
- package/dist/tools.d.ts +16 -0
- package/dist/tools.js +37 -0
- package/dist/versioning.d.ts +17 -0
- package/dist/versioning.js +64 -0
- package/package.json +16 -0
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface AgentConfig {
|
|
2
|
+
name: string;
|
|
3
|
+
model: string;
|
|
4
|
+
systemPrompt: string;
|
|
5
|
+
tools: string[];
|
|
6
|
+
maxIterations: number;
|
|
7
|
+
timeoutSeconds: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function agent(config: Partial<AgentConfig>): (fn: (msg: string) => string) => {
|
|
10
|
+
config: Partial<AgentConfig>;
|
|
11
|
+
fn: (msg: string) => string;
|
|
12
|
+
invoke: (msg: string) => string;
|
|
13
|
+
};
|
package/dist/agent.js
ADDED
package/dist/cost.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class CostEnforcer {
|
|
2
|
+
private sessionCosts;
|
|
3
|
+
private dailyCost;
|
|
4
|
+
private dailyLimit;
|
|
5
|
+
private sessionLimit;
|
|
6
|
+
private requestLimit;
|
|
7
|
+
constructor(dailyLimit?: number, sessionLimit?: number, requestLimit?: number);
|
|
8
|
+
checkBudget(sessionId: string, estimatedCost: number): {
|
|
9
|
+
allowed: boolean;
|
|
10
|
+
reason?: string;
|
|
11
|
+
};
|
|
12
|
+
recordCost(sessionId: string, cost: number): void;
|
|
13
|
+
getDailyCost(): number;
|
|
14
|
+
getSessionCost(id: string): number;
|
|
15
|
+
}
|
package/dist/cost.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CostEnforcer = void 0;
|
|
4
|
+
class CostEnforcer {
|
|
5
|
+
constructor(dailyLimit = 100, sessionLimit = 5, requestLimit = 0.5) {
|
|
6
|
+
this.sessionCosts = new Map();
|
|
7
|
+
this.dailyCost = 0;
|
|
8
|
+
this.dailyLimit = dailyLimit;
|
|
9
|
+
this.sessionLimit = sessionLimit;
|
|
10
|
+
this.requestLimit = requestLimit;
|
|
11
|
+
}
|
|
12
|
+
checkBudget(sessionId, estimatedCost) {
|
|
13
|
+
if (estimatedCost > this.requestLimit) {
|
|
14
|
+
return { allowed: false, reason: `Request cost $${estimatedCost} exceeds limit $${this.requestLimit}` };
|
|
15
|
+
}
|
|
16
|
+
const sessionCost = this.sessionCosts.get(sessionId) ?? 0;
|
|
17
|
+
if (sessionCost + estimatedCost > this.sessionLimit) {
|
|
18
|
+
return { allowed: false, reason: `Session budget exceeded` };
|
|
19
|
+
}
|
|
20
|
+
if (this.dailyCost + estimatedCost > this.dailyLimit) {
|
|
21
|
+
return { allowed: false, reason: `Daily budget exceeded` };
|
|
22
|
+
}
|
|
23
|
+
return { allowed: true };
|
|
24
|
+
}
|
|
25
|
+
recordCost(sessionId, cost) {
|
|
26
|
+
this.dailyCost += cost;
|
|
27
|
+
const current = this.sessionCosts.get(sessionId) ?? 0;
|
|
28
|
+
this.sessionCosts.set(sessionId, current + cost);
|
|
29
|
+
}
|
|
30
|
+
getDailyCost() { return this.dailyCost; }
|
|
31
|
+
getSessionCost(id) { return this.sessionCosts.get(id) ?? 0; }
|
|
32
|
+
}
|
|
33
|
+
exports.CostEnforcer = CostEnforcer;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AgentConfig, agent } from "./agent";
|
|
2
|
+
export { Session, SessionManager } from "./session";
|
|
3
|
+
export { ToolRegistry, ToolPermission } from "./tools";
|
|
4
|
+
export { CostEnforcer } from "./cost";
|
|
5
|
+
export { TenantManager } from "./tenants";
|
|
6
|
+
export { VersionManager } from "./versioning";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VersionManager = exports.TenantManager = exports.CostEnforcer = exports.ToolPermission = exports.ToolRegistry = exports.SessionManager = exports.Session = exports.agent = void 0;
|
|
4
|
+
var agent_1 = require("./agent");
|
|
5
|
+
Object.defineProperty(exports, "agent", { enumerable: true, get: function () { return agent_1.agent; } });
|
|
6
|
+
var session_1 = require("./session");
|
|
7
|
+
Object.defineProperty(exports, "Session", { enumerable: true, get: function () { return session_1.Session; } });
|
|
8
|
+
Object.defineProperty(exports, "SessionManager", { enumerable: true, get: function () { return session_1.SessionManager; } });
|
|
9
|
+
var tools_1 = require("./tools");
|
|
10
|
+
Object.defineProperty(exports, "ToolRegistry", { enumerable: true, get: function () { return tools_1.ToolRegistry; } });
|
|
11
|
+
Object.defineProperty(exports, "ToolPermission", { enumerable: true, get: function () { return tools_1.ToolPermission; } });
|
|
12
|
+
var cost_1 = require("./cost");
|
|
13
|
+
Object.defineProperty(exports, "CostEnforcer", { enumerable: true, get: function () { return cost_1.CostEnforcer; } });
|
|
14
|
+
var tenants_1 = require("./tenants");
|
|
15
|
+
Object.defineProperty(exports, "TenantManager", { enumerable: true, get: function () { return tenants_1.TenantManager; } });
|
|
16
|
+
var versioning_1 = require("./versioning");
|
|
17
|
+
Object.defineProperty(exports, "VersionManager", { enumerable: true, get: function () { return versioning_1.VersionManager; } });
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare class Session {
|
|
2
|
+
sessionId: string;
|
|
3
|
+
agentName: string;
|
|
4
|
+
messages: Array<{
|
|
5
|
+
role: string;
|
|
6
|
+
content: string;
|
|
7
|
+
}>;
|
|
8
|
+
turnCount: number;
|
|
9
|
+
constructor(sessionId: string, agentName: string);
|
|
10
|
+
addMessage(role: string, content: string): void;
|
|
11
|
+
getHistory(n?: number): Array<{
|
|
12
|
+
role: string;
|
|
13
|
+
content: string;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare class SessionManager {
|
|
17
|
+
private sessions;
|
|
18
|
+
getOrCreate(id: string, agentName: string): Session;
|
|
19
|
+
get(id: string): Session | undefined;
|
|
20
|
+
delete(id: string): void;
|
|
21
|
+
get count(): number;
|
|
22
|
+
}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionManager = exports.Session = void 0;
|
|
4
|
+
class Session {
|
|
5
|
+
constructor(sessionId, agentName) {
|
|
6
|
+
this.messages = [];
|
|
7
|
+
this.turnCount = 0;
|
|
8
|
+
this.sessionId = sessionId;
|
|
9
|
+
this.agentName = agentName;
|
|
10
|
+
}
|
|
11
|
+
addMessage(role, content) {
|
|
12
|
+
this.messages.push({ role, content });
|
|
13
|
+
this.turnCount++;
|
|
14
|
+
}
|
|
15
|
+
getHistory(n = 20) {
|
|
16
|
+
return this.messages.slice(-n);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.Session = Session;
|
|
20
|
+
class SessionManager {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.sessions = new Map();
|
|
23
|
+
}
|
|
24
|
+
getOrCreate(id, agentName) {
|
|
25
|
+
if (!this.sessions.has(id)) {
|
|
26
|
+
this.sessions.set(id, new Session(id, agentName));
|
|
27
|
+
}
|
|
28
|
+
return this.sessions.get(id);
|
|
29
|
+
}
|
|
30
|
+
get(id) {
|
|
31
|
+
return this.sessions.get(id);
|
|
32
|
+
}
|
|
33
|
+
delete(id) {
|
|
34
|
+
this.sessions.delete(id);
|
|
35
|
+
}
|
|
36
|
+
get count() { return this.sessions.size; }
|
|
37
|
+
}
|
|
38
|
+
exports.SessionManager = SessionManager;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface TenantConfig {
|
|
2
|
+
tenantId: string;
|
|
3
|
+
rateLimit: number;
|
|
4
|
+
budgetDaily: number;
|
|
5
|
+
toolsAllowed: string[];
|
|
6
|
+
toolsDenied: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare class TenantManager {
|
|
9
|
+
private tenants;
|
|
10
|
+
constructor();
|
|
11
|
+
create(config: TenantConfig): void;
|
|
12
|
+
get(id: string): TenantConfig | undefined;
|
|
13
|
+
delete(id: string): boolean;
|
|
14
|
+
list(): TenantConfig[];
|
|
15
|
+
get count(): number;
|
|
16
|
+
}
|
package/dist/tenants.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TenantManager = void 0;
|
|
4
|
+
class TenantManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.tenants = new Map();
|
|
7
|
+
this.tenants.set("default", { tenantId: "default", rateLimit: 100, budgetDaily: 50, toolsAllowed: ["all"], toolsDenied: [] });
|
|
8
|
+
}
|
|
9
|
+
create(config) { this.tenants.set(config.tenantId, config); }
|
|
10
|
+
get(id) { return this.tenants.get(id); }
|
|
11
|
+
delete(id) { if (id === "default")
|
|
12
|
+
return false; return this.tenants.delete(id); }
|
|
13
|
+
list() { return Array.from(this.tenants.values()); }
|
|
14
|
+
get count() { return this.tenants.size; }
|
|
15
|
+
}
|
|
16
|
+
exports.TenantManager = TenantManager;
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare enum ToolPermission {
|
|
2
|
+
READ = "read",
|
|
3
|
+
WRITE = "write",
|
|
4
|
+
ADMIN = "admin"
|
|
5
|
+
}
|
|
6
|
+
export declare class ToolRegistry {
|
|
7
|
+
private tools;
|
|
8
|
+
register(name: string, fn: Function): void;
|
|
9
|
+
execute(name: string, ...args: any[]): {
|
|
10
|
+
success: boolean;
|
|
11
|
+
output?: any;
|
|
12
|
+
error?: string;
|
|
13
|
+
};
|
|
14
|
+
isAllowed(name: string, allowed: string[], denied: string[]): boolean;
|
|
15
|
+
get count(): number;
|
|
16
|
+
}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolRegistry = exports.ToolPermission = void 0;
|
|
4
|
+
var ToolPermission;
|
|
5
|
+
(function (ToolPermission) {
|
|
6
|
+
ToolPermission["READ"] = "read";
|
|
7
|
+
ToolPermission["WRITE"] = "write";
|
|
8
|
+
ToolPermission["ADMIN"] = "admin";
|
|
9
|
+
})(ToolPermission || (exports.ToolPermission = ToolPermission = {}));
|
|
10
|
+
class ToolRegistry {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.tools = new Map();
|
|
13
|
+
}
|
|
14
|
+
register(name, fn) {
|
|
15
|
+
this.tools.set(name, fn);
|
|
16
|
+
}
|
|
17
|
+
execute(name, ...args) {
|
|
18
|
+
const fn = this.tools.get(name);
|
|
19
|
+
if (!fn)
|
|
20
|
+
return { success: false, error: "Not found" };
|
|
21
|
+
try {
|
|
22
|
+
return { success: true, output: fn(...args) };
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
return { success: false, error: e.message };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
isAllowed(name, allowed, denied) {
|
|
29
|
+
if (denied.includes(name))
|
|
30
|
+
return false;
|
|
31
|
+
if (allowed.includes("all"))
|
|
32
|
+
return true;
|
|
33
|
+
return allowed.includes(name);
|
|
34
|
+
}
|
|
35
|
+
get count() { return this.tools.size; }
|
|
36
|
+
}
|
|
37
|
+
exports.ToolRegistry = ToolRegistry;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface AgentVersion {
|
|
2
|
+
id: string;
|
|
3
|
+
status: "active" | "canary" | "retired" | "rolled_back";
|
|
4
|
+
traffic: number;
|
|
5
|
+
deployedAt: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class VersionManager {
|
|
8
|
+
private versions;
|
|
9
|
+
private activeId;
|
|
10
|
+
private canaryId;
|
|
11
|
+
deploy(id: string, traffic?: number): void;
|
|
12
|
+
startCanary(id: string, traffic?: number): void;
|
|
13
|
+
promoteCanary(): boolean;
|
|
14
|
+
rollback(): string | null;
|
|
15
|
+
getActiveId(): string | null;
|
|
16
|
+
getCanaryId(): string | null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VersionManager = void 0;
|
|
4
|
+
class VersionManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.versions = [];
|
|
7
|
+
this.activeId = null;
|
|
8
|
+
this.canaryId = null;
|
|
9
|
+
}
|
|
10
|
+
deploy(id, traffic = 100) {
|
|
11
|
+
if (this.activeId) {
|
|
12
|
+
const current = this.versions.find(v => v.id === this.activeId);
|
|
13
|
+
if (current) {
|
|
14
|
+
current.status = "retired";
|
|
15
|
+
current.traffic = 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
this.versions.push({ id, status: "active", traffic, deployedAt: new Date().toISOString() });
|
|
19
|
+
this.activeId = id;
|
|
20
|
+
}
|
|
21
|
+
startCanary(id, traffic = 10) {
|
|
22
|
+
const active = this.versions.find(v => v.id === this.activeId);
|
|
23
|
+
if (active) {
|
|
24
|
+
active.traffic = 100 - traffic;
|
|
25
|
+
}
|
|
26
|
+
this.versions.push({ id, status: "canary", traffic, deployedAt: new Date().toISOString() });
|
|
27
|
+
this.canaryId = id;
|
|
28
|
+
}
|
|
29
|
+
promoteCanary() {
|
|
30
|
+
if (!this.canaryId)
|
|
31
|
+
return false;
|
|
32
|
+
const active = this.versions.find(v => v.id === this.activeId);
|
|
33
|
+
if (active) {
|
|
34
|
+
active.status = "retired";
|
|
35
|
+
active.traffic = 0;
|
|
36
|
+
}
|
|
37
|
+
const canary = this.versions.find(v => v.id === this.canaryId);
|
|
38
|
+
if (canary) {
|
|
39
|
+
canary.status = "active";
|
|
40
|
+
canary.traffic = 100;
|
|
41
|
+
}
|
|
42
|
+
this.activeId = this.canaryId;
|
|
43
|
+
this.canaryId = null;
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
rollback() {
|
|
47
|
+
const retired = this.versions.filter(v => v.status === "retired");
|
|
48
|
+
if (!retired.length)
|
|
49
|
+
return null;
|
|
50
|
+
const prev = retired[retired.length - 1];
|
|
51
|
+
const curr = this.versions.find(v => v.id === this.activeId);
|
|
52
|
+
if (curr) {
|
|
53
|
+
curr.status = "rolled_back";
|
|
54
|
+
curr.traffic = 0;
|
|
55
|
+
}
|
|
56
|
+
prev.status = "active";
|
|
57
|
+
prev.traffic = 100;
|
|
58
|
+
this.activeId = prev.id;
|
|
59
|
+
return prev.id;
|
|
60
|
+
}
|
|
61
|
+
getActiveId() { return this.activeId; }
|
|
62
|
+
getCanaryId() { return this.canaryId; }
|
|
63
|
+
}
|
|
64
|
+
exports.VersionManager = VersionManager;
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "substrai-agentdeploy",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Zero-to-production AI agent deployment framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist/**/*"],
|
|
8
|
+
"scripts": { "build": "tsc", "prepublishOnly": "npm run build" },
|
|
9
|
+
"keywords": ["ai-agent", "deployment", "serverless", "lambda", "llm", "multi-tenancy", "production"],
|
|
10
|
+
"author": "Gaurav Kumar Sinha <gaurav@substrai.dev>",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": { "type": "git", "url": "https://github.com/substrai/agentdeploy" },
|
|
13
|
+
"homepage": "https://github.com/substrai/agentdeploy",
|
|
14
|
+
"engines": { "node": ">=16.0.0" },
|
|
15
|
+
"devDependencies": { "typescript": "^5.0.0" }
|
|
16
|
+
}
|