@a5c-ai/agent-runtime 5.0.1-staging.016f0b0e8119
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/README.md +23 -0
- package/dist/apiResult.d.ts +19 -0
- package/dist/apiResult.d.ts.map +1 -0
- package/dist/apiResult.js +16 -0
- package/dist/background/state.d.ts +14 -0
- package/dist/background/state.d.ts.map +1 -0
- package/dist/background/state.js +25 -0
- package/dist/backgroundProcessRegistry.d.ts +66 -0
- package/dist/backgroundProcessRegistry.d.ts.map +1 -0
- package/dist/backgroundProcessRegistry.js +202 -0
- package/dist/cost/claudeCodeParser.d.ts +81 -0
- package/dist/cost/claudeCodeParser.d.ts.map +1 -0
- package/dist/cost/claudeCodeParser.js +232 -0
- package/dist/cost/collector.d.ts +42 -0
- package/dist/cost/collector.d.ts.map +1 -0
- package/dist/cost/collector.js +105 -0
- package/dist/cost/effectCost.d.ts +23 -0
- package/dist/cost/effectCost.d.ts.map +1 -0
- package/dist/cost/effectCost.js +26 -0
- package/dist/cost/index.d.ts +19 -0
- package/dist/cost/index.d.ts.map +1 -0
- package/dist/cost/index.js +39 -0
- package/dist/cost/journal.d.ts +40 -0
- package/dist/cost/journal.d.ts.map +1 -0
- package/dist/cost/journal.js +137 -0
- package/dist/cost/types.d.ts +164 -0
- package/dist/cost/types.d.ts.map +1 -0
- package/dist/cost/types.js +228 -0
- package/dist/daemon/automationExecutor.d.ts +16 -0
- package/dist/daemon/automationExecutor.d.ts.map +1 -0
- package/dist/daemon/automationExecutor.js +222 -0
- package/dist/daemon/config.d.ts +8 -0
- package/dist/daemon/config.d.ts.map +1 -0
- package/dist/daemon/config.js +209 -0
- package/dist/daemon/daemonLog.d.ts +13 -0
- package/dist/daemon/daemonLog.d.ts.map +1 -0
- package/dist/daemon/daemonLog.js +64 -0
- package/dist/daemon/fileWatcher.d.ts +9 -0
- package/dist/daemon/fileWatcher.d.ts.map +1 -0
- package/dist/daemon/fileWatcher.js +141 -0
- package/dist/daemon/index.d.ts +13 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +22 -0
- package/dist/daemon/lifecycle.d.ts +12 -0
- package/dist/daemon/lifecycle.d.ts.map +1 -0
- package/dist/daemon/lifecycle.js +257 -0
- package/dist/daemon/loop.d.ts +21 -0
- package/dist/daemon/loop.d.ts.map +1 -0
- package/dist/daemon/loop.js +196 -0
- package/dist/daemon/timerScheduler.d.ts +13 -0
- package/dist/daemon/timerScheduler.d.ts.map +1 -0
- package/dist/daemon/timerScheduler.js +122 -0
- package/dist/daemon/types.d.ts +93 -0
- package/dist/daemon/types.d.ts.map +1 -0
- package/dist/daemon/types.js +25 -0
- package/dist/daemon/webhookListener.d.ts +6 -0
- package/dist/daemon/webhookListener.d.ts.map +1 -0
- package/dist/daemon/webhookListener.js +110 -0
- package/dist/execution/index.d.ts +8 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +12 -0
- package/dist/execution/modes/docker.d.ts +21 -0
- package/dist/execution/modes/docker.d.ts.map +1 -0
- package/dist/execution/modes/docker.js +125 -0
- package/dist/execution/modes/index.d.ts +10 -0
- package/dist/execution/modes/index.d.ts.map +1 -0
- package/dist/execution/modes/index.js +14 -0
- package/dist/execution/modes/kubernetes.d.ts +29 -0
- package/dist/execution/modes/kubernetes.d.ts.map +1 -0
- package/dist/execution/modes/kubernetes.js +121 -0
- package/dist/execution/modes/local.d.ts +23 -0
- package/dist/execution/modes/local.d.ts.map +1 -0
- package/dist/execution/modes/local.js +102 -0
- package/dist/execution/modes/ssh.d.ts +23 -0
- package/dist/execution/modes/ssh.d.ts.map +1 -0
- package/dist/execution/modes/ssh.js +134 -0
- package/dist/execution/provider.d.ts +32 -0
- package/dist/execution/provider.d.ts.map +1 -0
- package/dist/execution/provider.js +90 -0
- package/dist/execution/types.d.ts +105 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +9 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/observability/health.d.ts +19 -0
- package/dist/observability/health.d.ts.map +1 -0
- package/dist/observability/health.js +129 -0
- package/dist/observability/index.d.ts +6 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +20 -0
- package/dist/observability/runStatus.d.ts +44 -0
- package/dist/observability/runStatus.d.ts.map +1 -0
- package/dist/observability/runStatus.js +169 -0
- package/dist/observability/timeline.d.ts +11 -0
- package/dist/observability/timeline.d.ts.map +1 -0
- package/dist/observability/timeline.js +176 -0
- package/dist/observability/types.d.ts +62 -0
- package/dist/observability/types.d.ts.map +1 -0
- package/dist/observability/types.js +8 -0
- package/dist/observability/webhooks.d.ts +68 -0
- package/dist/observability/webhooks.d.ts.map +1 -0
- package/dist/observability/webhooks.js +132 -0
- package/dist/resources/budget-tracker.d.ts +56 -0
- package/dist/resources/budget-tracker.d.ts.map +1 -0
- package/dist/resources/budget-tracker.js +131 -0
- package/dist/resources/concurrency-guard.d.ts +55 -0
- package/dist/resources/concurrency-guard.d.ts.map +1 -0
- package/dist/resources/concurrency-guard.js +132 -0
- package/dist/resources/index.d.ts +12 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +20 -0
- package/dist/resources/manager.d.ts +49 -0
- package/dist/resources/manager.d.ts.map +1 -0
- package/dist/resources/manager.js +111 -0
- package/dist/resources/timeout-cascade.d.ts +56 -0
- package/dist/resources/timeout-cascade.d.ts.map +1 -0
- package/dist/resources/timeout-cascade.js +145 -0
- package/dist/resources/types.d.ts +108 -0
- package/dist/resources/types.d.ts.map +1 -0
- package/dist/resources/types.js +9 -0
- package/dist/session/context.d.ts +22 -0
- package/dist/session/context.d.ts.map +1 -0
- package/dist/session/context.js +113 -0
- package/dist/session/continuityState.d.ts +39 -0
- package/dist/session/continuityState.d.ts.map +1 -0
- package/dist/session/continuityState.js +164 -0
- package/dist/session/cost.d.ts +63 -0
- package/dist/session/cost.d.ts.map +1 -0
- package/dist/session/cost.js +194 -0
- package/dist/session/discovery.d.ts +22 -0
- package/dist/session/discovery.d.ts.map +1 -0
- package/dist/session/discovery.js +35 -0
- package/dist/session/history.d.ts +30 -0
- package/dist/session/history.d.ts.map +1 -0
- package/dist/session/history.js +143 -0
- package/dist/session/index.d.ts +20 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +78 -0
- package/dist/session/memoryExtraction.d.ts +65 -0
- package/dist/session/memoryExtraction.d.ts.map +1 -0
- package/dist/session/memoryExtraction.js +201 -0
- package/dist/session/parse.d.ts +45 -0
- package/dist/session/parse.d.ts.map +1 -0
- package/dist/session/parse.js +170 -0
- package/dist/session/persistence.d.ts +46 -0
- package/dist/session/persistence.d.ts.map +1 -0
- package/dist/session/persistence.js +180 -0
- package/dist/session/types.d.ts +267 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +45 -0
- package/dist/session/write.d.ts +61 -0
- package/dist/session/write.d.ts.map +1 -0
- package/dist/session/write.js +213 -0
- package/dist/telemetry/audit-log.d.ts +56 -0
- package/dist/telemetry/audit-log.d.ts.map +1 -0
- package/dist/telemetry/audit-log.js +59 -0
- package/dist/telemetry/index.d.ts +9 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +15 -0
- package/dist/telemetry/provider.d.ts +39 -0
- package/dist/telemetry/provider.d.ts.map +1 -0
- package/dist/telemetry/provider.js +91 -0
- package/dist/telemetry/span-tree.d.ts +46 -0
- package/dist/telemetry/span-tree.d.ts.map +1 -0
- package/dist/telemetry/span-tree.js +93 -0
- package/dist/telemetry/types.d.ts +85 -0
- package/dist/telemetry/types.d.ts.map +1 -0
- package/dist/telemetry/types.js +21 -0
- package/package.json +90 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GAP-OBS-NEW-001: Dashboard Webhook and Alert System.
|
|
3
|
+
*
|
|
4
|
+
* Webhook registration, event filtering, and alert evaluation
|
|
5
|
+
* for run health changes. Pure functions for registry management
|
|
6
|
+
* and alert level computation.
|
|
7
|
+
*/
|
|
8
|
+
import type { RunHealthSnapshot } from "./types";
|
|
9
|
+
export type AlertLevel = "info" | "warn" | "critical";
|
|
10
|
+
export type WebhookEventType = "run.health_changed" | "run.completed" | "run.failed" | "run.stuck" | "effect.pending_timeout";
|
|
11
|
+
export interface WebhookRegistration {
|
|
12
|
+
id: string;
|
|
13
|
+
url: string;
|
|
14
|
+
events: WebhookEventType[];
|
|
15
|
+
runId?: string;
|
|
16
|
+
alertLevels?: AlertLevel[];
|
|
17
|
+
secret?: string;
|
|
18
|
+
createdAt: string;
|
|
19
|
+
enabled: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface WebhookEvent {
|
|
22
|
+
id: string;
|
|
23
|
+
type: WebhookEventType;
|
|
24
|
+
runId: string;
|
|
25
|
+
alertLevel: AlertLevel;
|
|
26
|
+
payload: Record<string, unknown>;
|
|
27
|
+
occurredAt: string;
|
|
28
|
+
}
|
|
29
|
+
export interface WebhookDeliveryResult {
|
|
30
|
+
webhookId: string;
|
|
31
|
+
success: boolean;
|
|
32
|
+
statusCode?: number;
|
|
33
|
+
error?: string;
|
|
34
|
+
deliveredAt: string;
|
|
35
|
+
}
|
|
36
|
+
export interface WebhookRegistry {
|
|
37
|
+
schemaVersion: string;
|
|
38
|
+
registrations: WebhookRegistration[];
|
|
39
|
+
}
|
|
40
|
+
export type WebhookRegistrationInput = Omit<WebhookRegistration, "id" | "createdAt">;
|
|
41
|
+
export declare const WEBHOOK_SCHEMA_VERSION = "2026.01.webhooks-v1";
|
|
42
|
+
/**
|
|
43
|
+
* Register a new webhook in the registry.
|
|
44
|
+
* Mutates the registry and returns the created registration.
|
|
45
|
+
*/
|
|
46
|
+
export declare function registerWebhook(registry: WebhookRegistry, input: WebhookRegistrationInput): WebhookRegistration;
|
|
47
|
+
/**
|
|
48
|
+
* Remove a webhook by id. Throws if not found.
|
|
49
|
+
*/
|
|
50
|
+
export declare function unregisterWebhook(registry: WebhookRegistry, id: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* List webhooks, optionally filtered by runId.
|
|
53
|
+
*/
|
|
54
|
+
export declare function listWebhooks(registry: WebhookRegistry, runId?: string): WebhookRegistration[];
|
|
55
|
+
/**
|
|
56
|
+
* Build a webhook event from a health snapshot.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildWebhookEvent(type: WebhookEventType, runId: string, snapshot: RunHealthSnapshot): WebhookEvent;
|
|
59
|
+
/**
|
|
60
|
+
* Evaluate whether a health transition warrants an alert.
|
|
61
|
+
* Returns the alert level, or null if no alert is needed.
|
|
62
|
+
*/
|
|
63
|
+
export declare function evaluateAlertLevel(prev: RunHealthSnapshot | null, next: RunHealthSnapshot): AlertLevel | null;
|
|
64
|
+
/**
|
|
65
|
+
* Filter registrations for a given event type and optional alert level.
|
|
66
|
+
*/
|
|
67
|
+
export declare function filterRegistrations(registrations: WebhookRegistration[], eventType: WebhookEventType, alertLevel?: AlertLevel): WebhookRegistration[];
|
|
68
|
+
//# sourceMappingURL=webhooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/observability/webhooks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,SAAS,CAAC;AAMlE,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAEtD,MAAM,MAAM,gBAAgB,GACxB,oBAAoB,GACpB,eAAe,GACf,YAAY,GACZ,WAAW,GACX,wBAAwB,CAAC;AAE7B,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,mBAAmB,EAAE,CAAC;CACtC;AAED,MAAM,MAAM,wBAAwB,GAAG,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,WAAW,CAAC,CAAC;AAMrF,eAAO,MAAM,sBAAsB,wBAAwB,CAAC;AA0B5D;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE,wBAAwB,GAC9B,mBAAmB,CAQrB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,eAAe,EACzB,EAAE,EAAE,MAAM,GACT,IAAI,CAMN;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,eAAe,EACzB,KAAK,CAAC,EAAE,MAAM,GACb,mBAAmB,EAAE,CAGvB;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,iBAAiB,GAC1B,YAAY,CAad;AAMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,iBAAiB,GAAG,IAAI,EAC9B,IAAI,EAAE,iBAAiB,GACtB,UAAU,GAAG,IAAI,CAgBnB;AAMD;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,mBAAmB,EAAE,EACpC,SAAS,EAAE,gBAAgB,EAC3B,UAAU,CAAC,EAAE,UAAU,GACtB,mBAAmB,EAAE,CASvB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* GAP-OBS-NEW-001: Dashboard Webhook and Alert System.
|
|
4
|
+
*
|
|
5
|
+
* Webhook registration, event filtering, and alert evaluation
|
|
6
|
+
* for run health changes. Pure functions for registry management
|
|
7
|
+
* and alert level computation.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.WEBHOOK_SCHEMA_VERSION = void 0;
|
|
11
|
+
exports.registerWebhook = registerWebhook;
|
|
12
|
+
exports.unregisterWebhook = unregisterWebhook;
|
|
13
|
+
exports.listWebhooks = listWebhooks;
|
|
14
|
+
exports.buildWebhookEvent = buildWebhookEvent;
|
|
15
|
+
exports.evaluateAlertLevel = evaluateAlertLevel;
|
|
16
|
+
exports.filterRegistrations = filterRegistrations;
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Constants
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
exports.WEBHOOK_SCHEMA_VERSION = "2026.01.webhooks-v1";
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// ID generation
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
function generateId() {
|
|
25
|
+
// Use crypto.randomUUID for test isolation (no shared mutable counter)
|
|
26
|
+
return `wh-${crypto.randomUUID()}`;
|
|
27
|
+
}
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Alert level mapping
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
const STATUS_ALERT_MAP = {
|
|
32
|
+
healthy: "info",
|
|
33
|
+
degraded: "warn",
|
|
34
|
+
stuck: "critical",
|
|
35
|
+
failed: "critical",
|
|
36
|
+
};
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// Registry management (pure, operates on mutable registry)
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
/**
|
|
41
|
+
* Register a new webhook in the registry.
|
|
42
|
+
* Mutates the registry and returns the created registration.
|
|
43
|
+
*/
|
|
44
|
+
function registerWebhook(registry, input) {
|
|
45
|
+
const registration = {
|
|
46
|
+
...input,
|
|
47
|
+
id: generateId(),
|
|
48
|
+
createdAt: new Date().toISOString(),
|
|
49
|
+
};
|
|
50
|
+
registry.registrations.push(registration);
|
|
51
|
+
return registration;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Remove a webhook by id. Throws if not found.
|
|
55
|
+
*/
|
|
56
|
+
function unregisterWebhook(registry, id) {
|
|
57
|
+
const index = registry.registrations.findIndex((r) => r.id === id);
|
|
58
|
+
if (index === -1) {
|
|
59
|
+
throw new Error(`Webhook not found: ${id}`);
|
|
60
|
+
}
|
|
61
|
+
registry.registrations.splice(index, 1);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* List webhooks, optionally filtered by runId.
|
|
65
|
+
*/
|
|
66
|
+
function listWebhooks(registry, runId) {
|
|
67
|
+
if (!runId)
|
|
68
|
+
return [...registry.registrations];
|
|
69
|
+
return registry.registrations.filter((r) => r.runId === runId);
|
|
70
|
+
}
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Event building
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
/**
|
|
75
|
+
* Build a webhook event from a health snapshot.
|
|
76
|
+
*/
|
|
77
|
+
function buildWebhookEvent(type, runId, snapshot) {
|
|
78
|
+
return {
|
|
79
|
+
id: generateId(),
|
|
80
|
+
type,
|
|
81
|
+
runId,
|
|
82
|
+
alertLevel: STATUS_ALERT_MAP[snapshot.status],
|
|
83
|
+
payload: {
|
|
84
|
+
status: snapshot.status,
|
|
85
|
+
metrics: snapshot.metrics,
|
|
86
|
+
issues: snapshot.issues,
|
|
87
|
+
},
|
|
88
|
+
occurredAt: new Date().toISOString(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
// Alert level evaluation (pure)
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
/**
|
|
95
|
+
* Evaluate whether a health transition warrants an alert.
|
|
96
|
+
* Returns the alert level, or null if no alert is needed.
|
|
97
|
+
*/
|
|
98
|
+
function evaluateAlertLevel(prev, next) {
|
|
99
|
+
const prevStatus = prev?.status ?? "healthy";
|
|
100
|
+
const nextStatus = next.status;
|
|
101
|
+
if (prevStatus === nextStatus)
|
|
102
|
+
return null;
|
|
103
|
+
// Recovery: anything → healthy
|
|
104
|
+
if (nextStatus === "healthy")
|
|
105
|
+
return "info";
|
|
106
|
+
// Degradation
|
|
107
|
+
if (nextStatus === "degraded")
|
|
108
|
+
return "warn";
|
|
109
|
+
// Critical states
|
|
110
|
+
if (nextStatus === "stuck" || nextStatus === "failed")
|
|
111
|
+
return "critical";
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
// ---------------------------------------------------------------------------
|
|
115
|
+
// Registration filtering
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
/**
|
|
118
|
+
* Filter registrations for a given event type and optional alert level.
|
|
119
|
+
*/
|
|
120
|
+
function filterRegistrations(registrations, eventType, alertLevel) {
|
|
121
|
+
return registrations.filter((r) => {
|
|
122
|
+
if (!r.enabled)
|
|
123
|
+
return false;
|
|
124
|
+
if (!r.events.includes(eventType))
|
|
125
|
+
return false;
|
|
126
|
+
if (alertLevel && r.alertLevels && r.alertLevels.length > 0) {
|
|
127
|
+
if (!r.alertLevels.includes(alertLevel))
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic budget tracker for token and cost budgets.
|
|
3
|
+
*
|
|
4
|
+
* Tracks consumption against a configured limit and fires callbacks
|
|
5
|
+
* when usage crosses registered threshold percentages.
|
|
6
|
+
*/
|
|
7
|
+
/** Thrown when a `consume` call would exceed the budget limit. */
|
|
8
|
+
export declare class BudgetExceededError extends Error {
|
|
9
|
+
readonly limit: number;
|
|
10
|
+
readonly used: number;
|
|
11
|
+
readonly requested: number;
|
|
12
|
+
constructor(limit: number, used: number, requested: number);
|
|
13
|
+
}
|
|
14
|
+
/** Result of a `check()` call describing current budget health. */
|
|
15
|
+
export interface BudgetCheck {
|
|
16
|
+
/** Whether further consumption is allowed. */
|
|
17
|
+
readonly allowed: boolean;
|
|
18
|
+
/** Units remaining before the limit is reached. */
|
|
19
|
+
readonly remaining: number;
|
|
20
|
+
/** Percentage of the budget consumed (0–100). */
|
|
21
|
+
readonly percentUsed: number;
|
|
22
|
+
}
|
|
23
|
+
export declare class BudgetTracker {
|
|
24
|
+
private _limit;
|
|
25
|
+
private _used;
|
|
26
|
+
private readonly _thresholds;
|
|
27
|
+
constructor(limit: number);
|
|
28
|
+
get limit(): number;
|
|
29
|
+
get used(): number;
|
|
30
|
+
get remaining(): number;
|
|
31
|
+
/**
|
|
32
|
+
* Consume `amount` units from the budget.
|
|
33
|
+
*
|
|
34
|
+
* @throws {BudgetExceededError} if `amount` exceeds `remaining`.
|
|
35
|
+
*/
|
|
36
|
+
consume(amount: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* Release previously consumed units back into the budget.
|
|
39
|
+
*
|
|
40
|
+
* The released amount is capped so that `used` never goes below zero.
|
|
41
|
+
*/
|
|
42
|
+
release(amount: number): void;
|
|
43
|
+
/** Check the current budget state without mutating it. */
|
|
44
|
+
check(): BudgetCheck;
|
|
45
|
+
/**
|
|
46
|
+
* Register a callback that fires when usage crosses `percent`%.
|
|
47
|
+
*
|
|
48
|
+
* @param percent - Threshold percentage (0–100).
|
|
49
|
+
* @param callback - Function invoked once when the threshold is crossed.
|
|
50
|
+
*/
|
|
51
|
+
onThreshold(percent: number, callback: () => void): void;
|
|
52
|
+
/** Reset all usage to zero and re-arm all thresholds. */
|
|
53
|
+
reset(): void;
|
|
54
|
+
private _evaluateThresholds;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=budget-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget-tracker.d.ts","sourceRoot":"","sources":["../../src/resources/budget-tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,kEAAkE;AAClE,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAS3D;AAMD,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,iDAAiD;IACjD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAkBD,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwB;gBAExC,KAAK,EAAE,MAAM;IAUzB,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,SAAS,IAAI,MAAM,CAEtB;IAID;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAW7B;;;;OAIG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAe7B,0DAA0D;IAC1D,KAAK,IAAI,WAAW;IAUpB;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAgBxD,yDAAyD;IACzD,KAAK,IAAI,IAAI;IASb,OAAO,CAAC,mBAAmB;CAU5B"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Generic budget tracker for token and cost budgets.
|
|
4
|
+
*
|
|
5
|
+
* Tracks consumption against a configured limit and fires callbacks
|
|
6
|
+
* when usage crosses registered threshold percentages.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.BudgetTracker = exports.BudgetExceededError = void 0;
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Error
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
/** Thrown when a `consume` call would exceed the budget limit. */
|
|
14
|
+
class BudgetExceededError extends Error {
|
|
15
|
+
limit;
|
|
16
|
+
used;
|
|
17
|
+
requested;
|
|
18
|
+
constructor(limit, used, requested) {
|
|
19
|
+
super(`Budget exceeded: requested ${requested} but only ${limit - used} remaining (limit=${limit}, used=${used})`);
|
|
20
|
+
this.name = "BudgetExceededError";
|
|
21
|
+
this.limit = limit;
|
|
22
|
+
this.used = used;
|
|
23
|
+
this.requested = requested;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.BudgetExceededError = BudgetExceededError;
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// BudgetTracker
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
class BudgetTracker {
|
|
31
|
+
_limit;
|
|
32
|
+
_used;
|
|
33
|
+
_thresholds = [];
|
|
34
|
+
constructor(limit) {
|
|
35
|
+
if (limit < 0) {
|
|
36
|
+
throw new RangeError("Budget limit must be non-negative");
|
|
37
|
+
}
|
|
38
|
+
this._limit = limit;
|
|
39
|
+
this._used = 0;
|
|
40
|
+
}
|
|
41
|
+
// -- Getters --------------------------------------------------------------
|
|
42
|
+
get limit() {
|
|
43
|
+
return this._limit;
|
|
44
|
+
}
|
|
45
|
+
get used() {
|
|
46
|
+
return this._used;
|
|
47
|
+
}
|
|
48
|
+
get remaining() {
|
|
49
|
+
return Math.max(0, this._limit - this._used);
|
|
50
|
+
}
|
|
51
|
+
// -- Core API -------------------------------------------------------------
|
|
52
|
+
/**
|
|
53
|
+
* Consume `amount` units from the budget.
|
|
54
|
+
*
|
|
55
|
+
* @throws {BudgetExceededError} if `amount` exceeds `remaining`.
|
|
56
|
+
*/
|
|
57
|
+
consume(amount) {
|
|
58
|
+
if (amount < 0) {
|
|
59
|
+
throw new RangeError("Consume amount must be non-negative");
|
|
60
|
+
}
|
|
61
|
+
if (amount > this.remaining) {
|
|
62
|
+
throw new BudgetExceededError(this._limit, this._used, amount);
|
|
63
|
+
}
|
|
64
|
+
this._used += amount;
|
|
65
|
+
this._evaluateThresholds();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Release previously consumed units back into the budget.
|
|
69
|
+
*
|
|
70
|
+
* The released amount is capped so that `used` never goes below zero.
|
|
71
|
+
*/
|
|
72
|
+
release(amount) {
|
|
73
|
+
if (amount < 0) {
|
|
74
|
+
throw new RangeError("Release amount must be non-negative");
|
|
75
|
+
}
|
|
76
|
+
this._used = Math.max(0, this._used - amount);
|
|
77
|
+
// Re-arm any thresholds that are now above current usage.
|
|
78
|
+
for (const entry of this._thresholds) {
|
|
79
|
+
const currentPercent = this._limit === 0 ? 100 : (this._used / this._limit) * 100;
|
|
80
|
+
if (currentPercent < entry.percent) {
|
|
81
|
+
entry.fired = false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Check the current budget state without mutating it. */
|
|
86
|
+
check() {
|
|
87
|
+
const percentUsed = this._limit === 0 ? 100 : (this._used / this._limit) * 100;
|
|
88
|
+
return {
|
|
89
|
+
allowed: this.remaining > 0,
|
|
90
|
+
remaining: this.remaining,
|
|
91
|
+
percentUsed: Math.min(100, percentUsed),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Register a callback that fires when usage crosses `percent`%.
|
|
96
|
+
*
|
|
97
|
+
* @param percent - Threshold percentage (0–100).
|
|
98
|
+
* @param callback - Function invoked once when the threshold is crossed.
|
|
99
|
+
*/
|
|
100
|
+
onThreshold(percent, callback) {
|
|
101
|
+
if (percent < 0 || percent > 100) {
|
|
102
|
+
throw new RangeError("Threshold percent must be between 0 and 100");
|
|
103
|
+
}
|
|
104
|
+
const entry = { percent, callback, fired: false };
|
|
105
|
+
this._thresholds.push(entry);
|
|
106
|
+
// Fire immediately if already past threshold.
|
|
107
|
+
const currentPercent = this._limit === 0 ? 100 : (this._used / this._limit) * 100;
|
|
108
|
+
if (currentPercent >= percent) {
|
|
109
|
+
entry.fired = true;
|
|
110
|
+
callback();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Reset all usage to zero and re-arm all thresholds. */
|
|
114
|
+
reset() {
|
|
115
|
+
this._used = 0;
|
|
116
|
+
for (const entry of this._thresholds) {
|
|
117
|
+
entry.fired = false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// -- Internals ------------------------------------------------------------
|
|
121
|
+
_evaluateThresholds() {
|
|
122
|
+
const currentPercent = this._limit === 0 ? 100 : (this._used / this._limit) * 100;
|
|
123
|
+
for (const entry of this._thresholds) {
|
|
124
|
+
if (!entry.fired && currentPercent >= entry.percent) {
|
|
125
|
+
entry.fired = true;
|
|
126
|
+
entry.callback();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.BudgetTracker = BudgetTracker;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concurrency guard that limits the number of parallel slots in use.
|
|
3
|
+
*
|
|
4
|
+
* Provides both throwing (`acquire`) and non-throwing (`tryAcquire`)
|
|
5
|
+
* acquisition, as well as an async `waitForSlot` that resolves when a
|
|
6
|
+
* slot becomes available.
|
|
7
|
+
*/
|
|
8
|
+
/** Thrown when `acquire()` is called with no available slots. */
|
|
9
|
+
export declare class ConcurrencyLimitError extends Error {
|
|
10
|
+
readonly limit: number;
|
|
11
|
+
readonly active: number;
|
|
12
|
+
constructor(limit: number, active: number);
|
|
13
|
+
}
|
|
14
|
+
export declare class ConcurrencyGuard {
|
|
15
|
+
private readonly _limit;
|
|
16
|
+
private _active;
|
|
17
|
+
/** Pending waiters, each resolved when a slot is freed. */
|
|
18
|
+
private readonly _waiters;
|
|
19
|
+
constructor(limit: number);
|
|
20
|
+
/** Number of slots currently in use. */
|
|
21
|
+
get active(): number;
|
|
22
|
+
/** Number of slots available for acquisition. */
|
|
23
|
+
get available(): number;
|
|
24
|
+
/** Maximum number of parallel slots. */
|
|
25
|
+
get limit(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Acquire a concurrency slot.
|
|
28
|
+
*
|
|
29
|
+
* @throws {ConcurrencyLimitError} if no slots are available.
|
|
30
|
+
*/
|
|
31
|
+
acquire(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Try to acquire a concurrency slot without throwing.
|
|
34
|
+
*
|
|
35
|
+
* @returns `true` if a slot was acquired, `false` otherwise.
|
|
36
|
+
*/
|
|
37
|
+
tryAcquire(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Release a concurrency slot, waking the oldest waiter if any.
|
|
40
|
+
*
|
|
41
|
+
* No-ops if no slots are currently active (defensive).
|
|
42
|
+
*/
|
|
43
|
+
release(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Wait asynchronously until a slot becomes available, then acquire it.
|
|
46
|
+
*
|
|
47
|
+
* If a slot is already available, the returned promise resolves
|
|
48
|
+
* immediately (on the microtask queue).
|
|
49
|
+
*
|
|
50
|
+
* @param timeoutMs - Optional timeout in milliseconds. Rejects with a
|
|
51
|
+
* `ConcurrencyLimitError` if no slot is freed within this duration.
|
|
52
|
+
*/
|
|
53
|
+
waitForSlot(timeoutMs?: number): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=concurrency-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"concurrency-guard.d.ts","sourceRoot":"","sources":["../../src/resources/concurrency-guard.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,iEAAiE;AACjE,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAQ1C;AAMD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,OAAO,CAAS;IACxB,2DAA2D;IAC3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;gBAEtC,KAAK,EAAE,MAAM;IAUzB,wCAAwC;IACxC,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,iDAAiD;IACjD,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,wCAAwC;IACxC,IAAI,KAAK,IAAI,MAAM,CAElB;IAID;;;;OAIG;IACH,OAAO,IAAI,IAAI;IAOf;;;;OAIG;IACH,UAAU,IAAI,OAAO;IAQrB;;;;OAIG;IACH,OAAO,IAAI,IAAI;IAYf;;;;;;;;OAQG;IACG,WAAW,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAkCrD"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Concurrency guard that limits the number of parallel slots in use.
|
|
4
|
+
*
|
|
5
|
+
* Provides both throwing (`acquire`) and non-throwing (`tryAcquire`)
|
|
6
|
+
* acquisition, as well as an async `waitForSlot` that resolves when a
|
|
7
|
+
* slot becomes available.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ConcurrencyGuard = exports.ConcurrencyLimitError = void 0;
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Error
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
/** Thrown when `acquire()` is called with no available slots. */
|
|
15
|
+
class ConcurrencyLimitError extends Error {
|
|
16
|
+
limit;
|
|
17
|
+
active;
|
|
18
|
+
constructor(limit, active) {
|
|
19
|
+
super(`Concurrency limit reached: ${active}/${limit} slots in use`);
|
|
20
|
+
this.name = "ConcurrencyLimitError";
|
|
21
|
+
this.limit = limit;
|
|
22
|
+
this.active = active;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ConcurrencyLimitError = ConcurrencyLimitError;
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// ConcurrencyGuard
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
class ConcurrencyGuard {
|
|
30
|
+
_limit;
|
|
31
|
+
_active;
|
|
32
|
+
/** Pending waiters, each resolved when a slot is freed. */
|
|
33
|
+
_waiters = [];
|
|
34
|
+
constructor(limit) {
|
|
35
|
+
if (limit < 1) {
|
|
36
|
+
throw new RangeError("Concurrency limit must be at least 1");
|
|
37
|
+
}
|
|
38
|
+
this._limit = limit;
|
|
39
|
+
this._active = 0;
|
|
40
|
+
}
|
|
41
|
+
// -- Getters --------------------------------------------------------------
|
|
42
|
+
/** Number of slots currently in use. */
|
|
43
|
+
get active() {
|
|
44
|
+
return this._active;
|
|
45
|
+
}
|
|
46
|
+
/** Number of slots available for acquisition. */
|
|
47
|
+
get available() {
|
|
48
|
+
return this._limit - this._active;
|
|
49
|
+
}
|
|
50
|
+
/** Maximum number of parallel slots. */
|
|
51
|
+
get limit() {
|
|
52
|
+
return this._limit;
|
|
53
|
+
}
|
|
54
|
+
// -- Acquisition ----------------------------------------------------------
|
|
55
|
+
/**
|
|
56
|
+
* Acquire a concurrency slot.
|
|
57
|
+
*
|
|
58
|
+
* @throws {ConcurrencyLimitError} if no slots are available.
|
|
59
|
+
*/
|
|
60
|
+
acquire() {
|
|
61
|
+
if (this._active >= this._limit) {
|
|
62
|
+
throw new ConcurrencyLimitError(this._limit, this._active);
|
|
63
|
+
}
|
|
64
|
+
this._active++;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Try to acquire a concurrency slot without throwing.
|
|
68
|
+
*
|
|
69
|
+
* @returns `true` if a slot was acquired, `false` otherwise.
|
|
70
|
+
*/
|
|
71
|
+
tryAcquire() {
|
|
72
|
+
if (this._active >= this._limit) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
this._active++;
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Release a concurrency slot, waking the oldest waiter if any.
|
|
80
|
+
*
|
|
81
|
+
* No-ops if no slots are currently active (defensive).
|
|
82
|
+
*/
|
|
83
|
+
release() {
|
|
84
|
+
if (this._active <= 0) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this._active--;
|
|
88
|
+
// Wake the first waiter in line.
|
|
89
|
+
const waiter = this._waiters.shift();
|
|
90
|
+
if (waiter) {
|
|
91
|
+
waiter();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Wait asynchronously until a slot becomes available, then acquire it.
|
|
96
|
+
*
|
|
97
|
+
* If a slot is already available, the returned promise resolves
|
|
98
|
+
* immediately (on the microtask queue).
|
|
99
|
+
*
|
|
100
|
+
* @param timeoutMs - Optional timeout in milliseconds. Rejects with a
|
|
101
|
+
* `ConcurrencyLimitError` if no slot is freed within this duration.
|
|
102
|
+
*/
|
|
103
|
+
async waitForSlot(timeoutMs) {
|
|
104
|
+
// Fast path: slot available right now.
|
|
105
|
+
if (this._active < this._limit) {
|
|
106
|
+
this._active++;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
let timer;
|
|
111
|
+
const onSlot = () => {
|
|
112
|
+
if (timer !== undefined) {
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
}
|
|
115
|
+
this._active++;
|
|
116
|
+
resolve();
|
|
117
|
+
};
|
|
118
|
+
this._waiters.push(onSlot);
|
|
119
|
+
if (timeoutMs !== undefined && timeoutMs >= 0) {
|
|
120
|
+
timer = setTimeout(() => {
|
|
121
|
+
// Remove this waiter from the queue.
|
|
122
|
+
const idx = this._waiters.indexOf(onSlot);
|
|
123
|
+
if (idx !== -1) {
|
|
124
|
+
this._waiters.splice(idx, 1);
|
|
125
|
+
}
|
|
126
|
+
reject(new ConcurrencyLimitError(this._limit, this._active));
|
|
127
|
+
}, timeoutMs);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.ConcurrencyGuard = ConcurrencyGuard;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resources module — budget, concurrency, and timeout management.
|
|
3
|
+
*/
|
|
4
|
+
export type { TokenBudget, CostBudget, ConcurrencyLimits, TimeoutConfig, ResourceSnapshot, BudgetKind, ResourceWarning, ResourceWarningCallback, ResourceManager, } from "./types";
|
|
5
|
+
export { BudgetTracker, BudgetExceededError } from "./budget-tracker";
|
|
6
|
+
export type { BudgetCheck } from "./budget-tracker";
|
|
7
|
+
export { ConcurrencyGuard, ConcurrencyLimitError } from "./concurrency-guard";
|
|
8
|
+
export { TimeoutCascade } from "./timeout-cascade";
|
|
9
|
+
export type { TimeoutHandle } from "./timeout-cascade";
|
|
10
|
+
export { ResourceManagerImpl } from "./manager";
|
|
11
|
+
export type { ResourceManagerOptions } from "./manager";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,uBAAuB,EACvB,eAAe,GAChB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACtE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG9E,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,YAAY,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Resources module — budget, concurrency, and timeout management.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ResourceManagerImpl = exports.TimeoutCascade = exports.ConcurrencyLimitError = exports.ConcurrencyGuard = exports.BudgetExceededError = exports.BudgetTracker = void 0;
|
|
7
|
+
// Budget tracking
|
|
8
|
+
var budget_tracker_1 = require("./budget-tracker");
|
|
9
|
+
Object.defineProperty(exports, "BudgetTracker", { enumerable: true, get: function () { return budget_tracker_1.BudgetTracker; } });
|
|
10
|
+
Object.defineProperty(exports, "BudgetExceededError", { enumerable: true, get: function () { return budget_tracker_1.BudgetExceededError; } });
|
|
11
|
+
// Concurrency
|
|
12
|
+
var concurrency_guard_1 = require("./concurrency-guard");
|
|
13
|
+
Object.defineProperty(exports, "ConcurrencyGuard", { enumerable: true, get: function () { return concurrency_guard_1.ConcurrencyGuard; } });
|
|
14
|
+
Object.defineProperty(exports, "ConcurrencyLimitError", { enumerable: true, get: function () { return concurrency_guard_1.ConcurrencyLimitError; } });
|
|
15
|
+
// Timeout cascade
|
|
16
|
+
var timeout_cascade_1 = require("./timeout-cascade");
|
|
17
|
+
Object.defineProperty(exports, "TimeoutCascade", { enumerable: true, get: function () { return timeout_cascade_1.TimeoutCascade; } });
|
|
18
|
+
// Unified manager
|
|
19
|
+
var manager_1 = require("./manager");
|
|
20
|
+
Object.defineProperty(exports, "ResourceManagerImpl", { enumerable: true, get: function () { return manager_1.ResourceManagerImpl; } });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified resource manager that composes budget trackers, a concurrency
|
|
3
|
+
* guard, and a timeout cascade into the `ResourceManager` interface.
|
|
4
|
+
*/
|
|
5
|
+
import type { BudgetKind, CostBudget, ResourceManager, ResourceSnapshot, ResourceWarningCallback, TokenBudget } from "./types";
|
|
6
|
+
import { ConcurrencyGuard } from "./concurrency-guard";
|
|
7
|
+
import { TimeoutCascade } from "./timeout-cascade";
|
|
8
|
+
/** Options for constructing a `ResourceManagerImpl`. */
|
|
9
|
+
export interface ResourceManagerOptions {
|
|
10
|
+
/** Token budget limit. */
|
|
11
|
+
tokenLimit: number;
|
|
12
|
+
/** Cost budget limit. */
|
|
13
|
+
costLimit: number;
|
|
14
|
+
/** ISO 4217 currency code for cost budget. Defaults to "USD". */
|
|
15
|
+
costCurrency?: string;
|
|
16
|
+
/** Warning threshold percentage (0–100) for both budgets. */
|
|
17
|
+
warningThresholdPercent?: number;
|
|
18
|
+
/** Concurrency limits. */
|
|
19
|
+
concurrency?: {
|
|
20
|
+
maxParallelEffects?: number;
|
|
21
|
+
maxParallelRuns?: number;
|
|
22
|
+
maxParallelSessions?: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare class ResourceManagerImpl implements ResourceManager {
|
|
26
|
+
private readonly _tokenBudget;
|
|
27
|
+
private readonly _costBudget;
|
|
28
|
+
private readonly _costCurrency;
|
|
29
|
+
private readonly _warningThresholdPercent;
|
|
30
|
+
/** Concurrency guard for parallel effects. */
|
|
31
|
+
readonly effects: ConcurrencyGuard;
|
|
32
|
+
/** Concurrency guard for parallel runs. */
|
|
33
|
+
readonly runs: ConcurrencyGuard;
|
|
34
|
+
/** Concurrency guard for parallel sessions. */
|
|
35
|
+
readonly sessions: ConcurrencyGuard;
|
|
36
|
+
/** Timeout cascade for run / iteration / effect timeouts. */
|
|
37
|
+
readonly timeouts: TimeoutCascade;
|
|
38
|
+
private readonly _warningCallbacks;
|
|
39
|
+
constructor(options: ResourceManagerOptions);
|
|
40
|
+
checkBudget(kind: BudgetKind): TokenBudget | CostBudget;
|
|
41
|
+
consume(kind: BudgetKind, amount: number): void;
|
|
42
|
+
release(kind: BudgetKind, amount: number): void;
|
|
43
|
+
getSnapshot(): ResourceSnapshot;
|
|
44
|
+
onWarning(callback: ResourceWarningCallback): void;
|
|
45
|
+
private _trackerFor;
|
|
46
|
+
private _snapshot;
|
|
47
|
+
private _fireWarning;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=manager.d.ts.map
|