feat: add quota tracking
This commit is contained in:
+22
-4
@@ -38,7 +38,7 @@ async function host(
|
||||
build.permissions.push({ action: "shell", resource: "git push *", effect: "ask" });
|
||||
agents.set("build", build);
|
||||
const originalBuild = structuredClone(build);
|
||||
const sessionHooks: Record<string, (event: HookEvent) => Promise<void> | void> = {};
|
||||
const sessionHooks: Record<string, ((event: HookEvent) => Promise<void> | void)[]> = {};
|
||||
let before!: (event: { tool: string; agent: string; input: unknown }) => Promise<void> | void;
|
||||
let parent = "build";
|
||||
let child = "fast-lo";
|
||||
@@ -122,6 +122,24 @@ async function host(
|
||||
async set(key: string, value: JsonValue) {
|
||||
storage.set(key, value);
|
||||
},
|
||||
async remove(key: string) {
|
||||
storage.delete(key);
|
||||
},
|
||||
},
|
||||
integration: {
|
||||
connection: {
|
||||
async active() {
|
||||
return undefined;
|
||||
},
|
||||
async resolve() {
|
||||
return undefined;
|
||||
},
|
||||
},
|
||||
},
|
||||
rpc: {
|
||||
async register() {
|
||||
return { ...registration, events: { async emit() {} } };
|
||||
},
|
||||
},
|
||||
mcp: {
|
||||
async transform(callback: typeof mcpTransform) {
|
||||
@@ -165,7 +183,7 @@ async function host(
|
||||
},
|
||||
session: {
|
||||
async hook(name: string, callback: (event: HookEvent) => Promise<void> | void) {
|
||||
sessionHooks[name] = callback;
|
||||
(sessionHooks[name] ??= []).push(callback);
|
||||
return registration;
|
||||
},
|
||||
async get({ sessionID }: { sessionID: string }) {
|
||||
@@ -236,7 +254,7 @@ async function host(
|
||||
async command(caller: string, target: string) {
|
||||
parent = caller;
|
||||
child = target;
|
||||
await sessionHooks.prompt!({ sessionID: "child" });
|
||||
for (const hook of sessionHooks.prompt ?? []) await hook({ sessionID: "child" });
|
||||
},
|
||||
async tools(caller: string) {
|
||||
const event: ModelContext = {
|
||||
@@ -251,7 +269,7 @@ async function host(
|
||||
},
|
||||
},
|
||||
};
|
||||
await sessionHooks.context!(event);
|
||||
for (const hook of sessionHooks.context ?? []) await hook(event);
|
||||
return event.tools;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user