@rlynjb/aptkit-core 0.1.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/README.md +19 -0
- package/dist/src/index.d.ts +12 -0
- package/dist/src/index.js +9 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/README.md +13 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/categories.d.ts +11 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/categories.js +100 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/fixture-provider.d.ts +10 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/fixture-provider.js +18 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/index.d.ts +6 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/index.js +6 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/monitoring-agent.d.ts +32 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/monitoring-agent.js +88 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/schema-summary.d.ts +2 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/schema-summary.js +7 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/types.d.ts +32 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/types.js +1 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/validate.d.ts +9 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/dist/src/validate.js +34 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/fixtures/promoted/sp-revenue-monitoring-fixture-promoted-2026-06-18-18-37-26.json +229 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/fixtures/sp-revenue-monitoring.json +136 -0
- package/node_modules/@aptkit/agent-anomaly-monitoring/package.json +33 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/README.md +11 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/diagnostic-agent.d.ts +27 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/diagnostic-agent.js +95 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/fixture-provider.d.ts +10 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/fixture-provider.js +18 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/index.d.ts +5 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/index.js +5 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/schema-summary.d.ts +1 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/schema-summary.js +1 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/types.d.ts +37 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/types.js +1 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/validate.d.ts +10 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/dist/src/validate.js +49 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/fixtures/promoted/sp-revenue-diagnostic-fixture-promoted-2026-06-18-19-04-28.json +230 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/fixtures/sp-revenue-diagnostic.json +148 -0
- package/node_modules/@aptkit/agent-diagnostic-investigation/package.json +33 -0
- package/node_modules/@aptkit/agent-query/README.md +11 -0
- package/node_modules/@aptkit/agent-query/dist/src/fixture-provider.d.ts +10 -0
- package/node_modules/@aptkit/agent-query/dist/src/fixture-provider.js +18 -0
- package/node_modules/@aptkit/agent-query/dist/src/index.d.ts +6 -0
- package/node_modules/@aptkit/agent-query/dist/src/index.js +6 -0
- package/node_modules/@aptkit/agent-query/dist/src/intent.d.ts +6 -0
- package/node_modules/@aptkit/agent-query/dist/src/intent.js +23 -0
- package/node_modules/@aptkit/agent-query/dist/src/query-agent.d.ts +27 -0
- package/node_modules/@aptkit/agent-query/dist/src/query-agent.js +81 -0
- package/node_modules/@aptkit/agent-query/dist/src/schema-summary.d.ts +1 -0
- package/node_modules/@aptkit/agent-query/dist/src/schema-summary.js +1 -0
- package/node_modules/@aptkit/agent-query/dist/src/types.d.ts +5 -0
- package/node_modules/@aptkit/agent-query/dist/src/types.js +1 -0
- package/node_modules/@aptkit/agent-query/dist/src/validate.d.ts +7 -0
- package/node_modules/@aptkit/agent-query/dist/src/validate.js +9 -0
- package/node_modules/@aptkit/agent-query/fixtures/promoted/revenue-by-state-query-fixture-promoted-2026-06-18-19-29-11.json +138 -0
- package/node_modules/@aptkit/agent-query/fixtures/revenue-by-state-query.json +79 -0
- package/node_modules/@aptkit/agent-query/package.json +33 -0
- package/node_modules/@aptkit/agent-recommendation/README.md +109 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/fixture-provider.d.ts +10 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/fixture-provider.js +18 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/index.d.ts +4 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/index.js +4 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/recommendation-agent.d.ts +30 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/recommendation-agent.js +85 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/schema-summary.d.ts +1 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/schema-summary.js +1 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/types.d.ts +68 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/types.js +3 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/validate.d.ts +3 -0
- package/node_modules/@aptkit/agent-recommendation/dist/src/validate.js +54 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/electronics-spike.json +84 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/promoted/voucher-dropoff-w10-on-openai-promoted-2026-06-18-16-53-02.json +166 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/promoted/voucher-dropoff-w10-on-openai-promoted-2026-06-18-17-20-55.json +157 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/sp-revenue-drop.json +83 -0
- package/node_modules/@aptkit/agent-recommendation/fixtures/voucher-dropoff.json +84 -0
- package/node_modules/@aptkit/agent-recommendation/package.json +34 -0
- package/node_modules/@aptkit/context/README.md +15 -0
- package/node_modules/@aptkit/context/dist/src/index.d.ts +2 -0
- package/node_modules/@aptkit/context/dist/src/index.js +2 -0
- package/node_modules/@aptkit/context/dist/src/workspace-descriptor.d.ts +25 -0
- package/node_modules/@aptkit/context/dist/src/workspace-descriptor.js +1 -0
- package/node_modules/@aptkit/context/dist/src/workspace-summary.d.ts +9 -0
- package/node_modules/@aptkit/context/dist/src/workspace-summary.js +38 -0
- package/node_modules/@aptkit/context/package.json +24 -0
- package/node_modules/@aptkit/evals/dist/src/assertions.d.ts +13 -0
- package/node_modules/@aptkit/evals/dist/src/assertions.js +351 -0
- package/node_modules/@aptkit/evals/dist/src/detection-scorer.d.ts +25 -0
- package/node_modules/@aptkit/evals/dist/src/detection-scorer.js +72 -0
- package/node_modules/@aptkit/evals/dist/src/index.d.ts +3 -0
- package/node_modules/@aptkit/evals/dist/src/index.js +3 -0
- package/node_modules/@aptkit/evals/dist/src/replay-runner.d.ts +29 -0
- package/node_modules/@aptkit/evals/dist/src/replay-runner.js +72 -0
- package/node_modules/@aptkit/evals/dist/src/structural-diff.d.ts +50 -0
- package/node_modules/@aptkit/evals/dist/src/structural-diff.js +143 -0
- package/node_modules/@aptkit/evals/package.json +27 -0
- package/node_modules/@aptkit/prompts/README.md +7 -0
- package/node_modules/@aptkit/prompts/dist/src/diagnostic.d.ts +3 -0
- package/node_modules/@aptkit/prompts/dist/src/diagnostic.js +85 -0
- package/node_modules/@aptkit/prompts/dist/src/index.d.ts +5 -0
- package/node_modules/@aptkit/prompts/dist/src/index.js +5 -0
- package/node_modules/@aptkit/prompts/dist/src/monitoring.d.ts +3 -0
- package/node_modules/@aptkit/prompts/dist/src/monitoring.js +57 -0
- package/node_modules/@aptkit/prompts/dist/src/query.d.ts +3 -0
- package/node_modules/@aptkit/prompts/dist/src/query.js +86 -0
- package/node_modules/@aptkit/prompts/dist/src/recommendation.d.ts +3 -0
- package/node_modules/@aptkit/prompts/dist/src/recommendation.js +110 -0
- package/node_modules/@aptkit/prompts/dist/src/types.d.ts +21 -0
- package/node_modules/@aptkit/prompts/dist/src/types.js +6 -0
- package/node_modules/@aptkit/prompts/package.json +24 -0
- package/node_modules/@aptkit/runtime/dist/src/events.d.ts +44 -0
- package/node_modules/@aptkit/runtime/dist/src/events.js +3 -0
- package/node_modules/@aptkit/runtime/dist/src/index.d.ts +6 -0
- package/node_modules/@aptkit/runtime/dist/src/index.js +6 -0
- package/node_modules/@aptkit/runtime/dist/src/json-output.d.ts +10 -0
- package/node_modules/@aptkit/runtime/dist/src/json-output.js +32 -0
- package/node_modules/@aptkit/runtime/dist/src/model-provider.d.ts +49 -0
- package/node_modules/@aptkit/runtime/dist/src/model-provider.js +1 -0
- package/node_modules/@aptkit/runtime/dist/src/ndjson-stream.d.ts +43 -0
- package/node_modules/@aptkit/runtime/dist/src/ndjson-stream.js +128 -0
- package/node_modules/@aptkit/runtime/dist/src/run-agent-loop.d.ts +42 -0
- package/node_modules/@aptkit/runtime/dist/src/run-agent-loop.js +138 -0
- package/node_modules/@aptkit/runtime/dist/src/usage-ledger.d.ts +29 -0
- package/node_modules/@aptkit/runtime/dist/src/usage-ledger.js +61 -0
- package/node_modules/@aptkit/runtime/package.json +23 -0
- package/node_modules/@aptkit/tools/dist/src/coverage-gate.d.ts +32 -0
- package/node_modules/@aptkit/tools/dist/src/coverage-gate.js +43 -0
- package/node_modules/@aptkit/tools/dist/src/index.d.ts +3 -0
- package/node_modules/@aptkit/tools/dist/src/index.js +3 -0
- package/node_modules/@aptkit/tools/dist/src/tool-policy.d.ts +9 -0
- package/node_modules/@aptkit/tools/dist/src/tool-policy.js +11 -0
- package/node_modules/@aptkit/tools/dist/src/tool-registry.d.ts +27 -0
- package/node_modules/@aptkit/tools/dist/src/tool-registry.js +25 -0
- package/node_modules/@aptkit/tools/package.json +26 -0
- package/package.json +53 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CapabilityEvent } from './events.js';
|
|
2
|
+
export type TokenUsageSummary = {
|
|
3
|
+
inputTokens: number;
|
|
4
|
+
outputTokens: number;
|
|
5
|
+
totalTokens: number;
|
|
6
|
+
modelName?: string;
|
|
7
|
+
turns: number;
|
|
8
|
+
estimated: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type CostEstimate = {
|
|
11
|
+
currency: 'USD';
|
|
12
|
+
inputCost: number;
|
|
13
|
+
outputCost: number;
|
|
14
|
+
totalCost: number;
|
|
15
|
+
inputUsdPerMillion: number;
|
|
16
|
+
outputUsdPerMillion: number;
|
|
17
|
+
estimated: true;
|
|
18
|
+
};
|
|
19
|
+
export type UsagePricing = Pick<CostEstimate, 'inputUsdPerMillion' | 'outputUsdPerMillion'>;
|
|
20
|
+
/** Sums model usage trace events into one provider-neutral usage ledger row. */
|
|
21
|
+
export declare function summarizeUsage(trace: readonly CapabilityEvent[]): TokenUsageSummary;
|
|
22
|
+
/** Counts model turns from a trace without requiring token fields to be present. */
|
|
23
|
+
export declare function modelTurnCount(trace: readonly CapabilityEvent[]): number;
|
|
24
|
+
/** Estimates USD cost from usage and known provider/model pricing. */
|
|
25
|
+
export declare function estimateCost(provider: string, usage: Pick<TokenUsageSummary, 'inputTokens' | 'outputTokens'>, modelName: string): CostEstimate | undefined;
|
|
26
|
+
/** Returns the currently configured per-million-token pricing for known model families. */
|
|
27
|
+
export declare function pricingForModel(provider: string, modelName: string): UsagePricing | undefined;
|
|
28
|
+
/** Formats estimated costs for compact Studio and replay-summary displays. */
|
|
29
|
+
export declare function formatCost(costEstimate: CostEstimate | undefined): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Sums model usage trace events into one provider-neutral usage ledger row. */
|
|
2
|
+
export function summarizeUsage(trace) {
|
|
3
|
+
return trace.reduce((summary, event) => {
|
|
4
|
+
if (event.type !== 'model_usage')
|
|
5
|
+
return summary;
|
|
6
|
+
const inputTokens = event.inputTokens ?? 0;
|
|
7
|
+
const outputTokens = event.outputTokens ?? 0;
|
|
8
|
+
return {
|
|
9
|
+
inputTokens: summary.inputTokens + inputTokens,
|
|
10
|
+
outputTokens: summary.outputTokens + outputTokens,
|
|
11
|
+
totalTokens: summary.totalTokens + inputTokens + outputTokens,
|
|
12
|
+
modelName: event.model || summary.modelName,
|
|
13
|
+
turns: summary.turns + 1,
|
|
14
|
+
estimated: summary.estimated || event.estimated === true,
|
|
15
|
+
};
|
|
16
|
+
}, { inputTokens: 0, outputTokens: 0, totalTokens: 0, modelName: '', turns: 0, estimated: false });
|
|
17
|
+
}
|
|
18
|
+
/** Counts model turns from a trace without requiring token fields to be present. */
|
|
19
|
+
export function modelTurnCount(trace) {
|
|
20
|
+
return trace.filter((event) => event.type === 'model_usage').length;
|
|
21
|
+
}
|
|
22
|
+
/** Estimates USD cost from usage and known provider/model pricing. */
|
|
23
|
+
export function estimateCost(provider, usage, modelName) {
|
|
24
|
+
const pricing = pricingForModel(provider, modelName);
|
|
25
|
+
if (!pricing)
|
|
26
|
+
return undefined;
|
|
27
|
+
const inputCost = (usage.inputTokens / 1_000_000) * pricing.inputUsdPerMillion;
|
|
28
|
+
const outputCost = (usage.outputTokens / 1_000_000) * pricing.outputUsdPerMillion;
|
|
29
|
+
return {
|
|
30
|
+
currency: 'USD',
|
|
31
|
+
inputCost,
|
|
32
|
+
outputCost,
|
|
33
|
+
totalCost: inputCost + outputCost,
|
|
34
|
+
inputUsdPerMillion: pricing.inputUsdPerMillion,
|
|
35
|
+
outputUsdPerMillion: pricing.outputUsdPerMillion,
|
|
36
|
+
estimated: true,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Returns the currently configured per-million-token pricing for known model families. */
|
|
40
|
+
export function pricingForModel(provider, modelName) {
|
|
41
|
+
if (provider !== 'openai')
|
|
42
|
+
return undefined;
|
|
43
|
+
const normalized = modelName.toLowerCase();
|
|
44
|
+
if (normalized.startsWith('gpt-4.1-nano'))
|
|
45
|
+
return { inputUsdPerMillion: 0.1, outputUsdPerMillion: 0.4 };
|
|
46
|
+
if (normalized.startsWith('gpt-4.1-mini'))
|
|
47
|
+
return { inputUsdPerMillion: 0.4, outputUsdPerMillion: 1.6 };
|
|
48
|
+
if (normalized.startsWith('gpt-4.1'))
|
|
49
|
+
return { inputUsdPerMillion: 2, outputUsdPerMillion: 8 };
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/** Formats estimated costs for compact Studio and replay-summary displays. */
|
|
53
|
+
export function formatCost(costEstimate) {
|
|
54
|
+
if (!costEstimate)
|
|
55
|
+
return 'n/a';
|
|
56
|
+
if (costEstimate.totalCost === 0)
|
|
57
|
+
return '$0.00';
|
|
58
|
+
if (costEstimate.totalCost < 0.01)
|
|
59
|
+
return `$${costEstimate.totalCost.toFixed(4)}`;
|
|
60
|
+
return `$${costEstimate.totalCost.toFixed(2)}`;
|
|
61
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aptkit/runtime",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/src/index.js",
|
|
6
|
+
"types": "./dist/src/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/src"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/src/index.d.ts",
|
|
13
|
+
"import": "./dist/src/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"test": "npm run build && node --test dist/test/*.test.js"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^20.0.0"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type CapabilityDescriptorSource = {
|
|
2
|
+
events?: readonly {
|
|
3
|
+
name: string;
|
|
4
|
+
properties?: readonly string[];
|
|
5
|
+
}[];
|
|
6
|
+
catalogs?: readonly {
|
|
7
|
+
name: string;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
export type CoverageLevel = 'full' | 'limited' | 'unavailable';
|
|
11
|
+
export type CoverageRequirement = {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
requires: readonly string[];
|
|
15
|
+
enriches?: readonly string[];
|
|
16
|
+
};
|
|
17
|
+
export type CoverageReportItem = {
|
|
18
|
+
category: string;
|
|
19
|
+
label: string;
|
|
20
|
+
coverage: CoverageLevel;
|
|
21
|
+
missing?: string[];
|
|
22
|
+
};
|
|
23
|
+
/** Builds capability tokens such as event names, event properties, and catalogs from a workspace-like descriptor. */
|
|
24
|
+
export declare function schemaCapabilities(source: CapabilityDescriptorSource): Set<string>;
|
|
25
|
+
/** Classifies whether a task can run completely, partially, or not at all from the available capabilities. */
|
|
26
|
+
export declare function requirementCoverage(requirement: CoverageRequirement, capabilities: ReadonlySet<string>): CoverageLevel;
|
|
27
|
+
/** Lists required or enriching capabilities that are absent for a task. */
|
|
28
|
+
export declare function missingCapabilities(requirement: CoverageRequirement, capabilities: ReadonlySet<string>): string[];
|
|
29
|
+
/** Produces an inspectable coverage report for Studio previews and pre-model gating. */
|
|
30
|
+
export declare function coverageReport(requirements: readonly CoverageRequirement[], capabilities: ReadonlySet<string>): CoverageReportItem[];
|
|
31
|
+
/** Filters out tasks that cannot run before the agent spends model tokens on them. */
|
|
32
|
+
export declare function runnableRequirements<T extends CoverageRequirement>(requirements: readonly T[], capabilities: ReadonlySet<string>): T[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Builds capability tokens such as event names, event properties, and catalogs from a workspace-like descriptor. */
|
|
2
|
+
export function schemaCapabilities(source) {
|
|
3
|
+
const capabilities = new Set();
|
|
4
|
+
for (const event of source.events ?? []) {
|
|
5
|
+
capabilities.add(event.name);
|
|
6
|
+
for (const property of event.properties ?? []) {
|
|
7
|
+
capabilities.add(`${event.name}.${property}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
for (const catalog of source.catalogs ?? []) {
|
|
11
|
+
capabilities.add(`catalog:${catalog.name}`);
|
|
12
|
+
}
|
|
13
|
+
return capabilities;
|
|
14
|
+
}
|
|
15
|
+
/** Classifies whether a task can run completely, partially, or not at all from the available capabilities. */
|
|
16
|
+
export function requirementCoverage(requirement, capabilities) {
|
|
17
|
+
if (!requirement.requires.every((dependency) => capabilities.has(dependency)))
|
|
18
|
+
return 'unavailable';
|
|
19
|
+
if (requirement.enriches?.length && !requirement.enriches.every((dependency) => capabilities.has(dependency)))
|
|
20
|
+
return 'limited';
|
|
21
|
+
return 'full';
|
|
22
|
+
}
|
|
23
|
+
/** Lists required or enriching capabilities that are absent for a task. */
|
|
24
|
+
export function missingCapabilities(requirement, capabilities) {
|
|
25
|
+
return [...requirement.requires, ...(requirement.enriches ?? [])].filter((dependency) => !capabilities.has(dependency));
|
|
26
|
+
}
|
|
27
|
+
/** Produces an inspectable coverage report for Studio previews and pre-model gating. */
|
|
28
|
+
export function coverageReport(requirements, capabilities) {
|
|
29
|
+
return requirements.map((requirement) => {
|
|
30
|
+
const coverage = requirementCoverage(requirement, capabilities);
|
|
31
|
+
const missing = missingCapabilities(requirement, capabilities);
|
|
32
|
+
return {
|
|
33
|
+
category: requirement.id,
|
|
34
|
+
label: requirement.label,
|
|
35
|
+
coverage,
|
|
36
|
+
...(coverage !== 'full' && missing.length ? { missing } : {}),
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Filters out tasks that cannot run before the agent spends model tokens on them. */
|
|
41
|
+
export function runnableRequirements(requirements, capabilities) {
|
|
42
|
+
return requirements.filter((requirement) => requirementCoverage(requirement, capabilities) !== 'unavailable');
|
|
43
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ModelTool } from '@aptkit/runtime';
|
|
2
|
+
import type { ToolDefinition } from './tool-registry.js';
|
|
3
|
+
/** Capability-scoped allowlist that keeps agents from seeing tools outside their role. */
|
|
4
|
+
export type ToolPolicy = {
|
|
5
|
+
capabilityId: string;
|
|
6
|
+
allowedTools: readonly string[];
|
|
7
|
+
};
|
|
8
|
+
/** Filters a registry catalog down to the provider-neutral tool schemas a model may call. */
|
|
9
|
+
export declare function filterToolsForPolicy(allTools: readonly ToolDefinition[], policy: ToolPolicy): ModelTool[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Filters a registry catalog down to the provider-neutral tool schemas a model may call. */
|
|
2
|
+
export function filterToolsForPolicy(allTools, policy) {
|
|
3
|
+
const allowed = new Set(policy.allowedTools);
|
|
4
|
+
return allTools
|
|
5
|
+
.filter((tool) => allowed.has(tool.name))
|
|
6
|
+
.map((tool) => ({
|
|
7
|
+
name: tool.name,
|
|
8
|
+
description: tool.description ?? '',
|
|
9
|
+
inputSchema: tool.inputSchema,
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ModelTool } from '@aptkit/runtime';
|
|
2
|
+
export type ToolDefinition = ModelTool;
|
|
3
|
+
/** Per-call controls passed from an agent loop into a tool implementation. */
|
|
4
|
+
export type ToolCallOptions = {
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
};
|
|
7
|
+
/** Normalized result envelope for any model-callable tool. */
|
|
8
|
+
export type ToolCallResult = {
|
|
9
|
+
result: unknown;
|
|
10
|
+
durationMs: number;
|
|
11
|
+
};
|
|
12
|
+
/** Provider-neutral registry that lists callable tools and executes them by name. */
|
|
13
|
+
export type ToolRegistry = {
|
|
14
|
+
listTools(): Promise<ToolDefinition[]> | ToolDefinition[];
|
|
15
|
+
callTool(name: string, args: Record<string, unknown>, options?: ToolCallOptions): Promise<ToolCallResult>;
|
|
16
|
+
};
|
|
17
|
+
/** Function backing one tool in an in-memory or adapter-backed registry. */
|
|
18
|
+
export type ToolHandler = (args: Record<string, unknown>, options?: ToolCallOptions) => Promise<unknown> | unknown;
|
|
19
|
+
/** Test/demo registry that serves fixed tool definitions with injected handlers. */
|
|
20
|
+
export declare class InMemoryToolRegistry implements ToolRegistry {
|
|
21
|
+
private readonly definitions;
|
|
22
|
+
private readonly handlers;
|
|
23
|
+
constructor(definitions: ToolDefinition[], handlers: Record<string, ToolHandler>);
|
|
24
|
+
listTools(): ToolDefinition[];
|
|
25
|
+
/** Executes a named handler and records wall-clock duration for traces. */
|
|
26
|
+
callTool(name: string, args: Record<string, unknown>, options?: ToolCallOptions): Promise<ToolCallResult>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Test/demo registry that serves fixed tool definitions with injected handlers. */
|
|
2
|
+
export class InMemoryToolRegistry {
|
|
3
|
+
definitions;
|
|
4
|
+
handlers = new Map();
|
|
5
|
+
constructor(definitions, handlers) {
|
|
6
|
+
this.definitions = definitions;
|
|
7
|
+
for (const [name, handler] of Object.entries(handlers)) {
|
|
8
|
+
this.handlers.set(name, handler);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
listTools() {
|
|
12
|
+
return this.definitions;
|
|
13
|
+
}
|
|
14
|
+
/** Executes a named handler and records wall-clock duration for traces. */
|
|
15
|
+
async callTool(name, args, options) {
|
|
16
|
+
options?.signal?.throwIfAborted();
|
|
17
|
+
const handler = this.handlers.get(name);
|
|
18
|
+
if (!handler) {
|
|
19
|
+
throw new Error(`tool not found: ${name}`);
|
|
20
|
+
}
|
|
21
|
+
const start = performance.now();
|
|
22
|
+
const result = await handler(args, options);
|
|
23
|
+
return { result, durationMs: Math.round(performance.now() - start) };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aptkit/tools",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/src/index.js",
|
|
6
|
+
"types": "./dist/src/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/src"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/src/index.d.ts",
|
|
13
|
+
"import": "./dist/src/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.json",
|
|
18
|
+
"test": "npm run build && node --test dist/test/*.test.js"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@aptkit/runtime": "0.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "^20.0.0"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rlynjb/aptkit-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Standalone AptKit core bundle for extracted agent capabilities.",
|
|
6
|
+
"main": "./dist/src/index.js",
|
|
7
|
+
"types": "./dist/src/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/rlynjb/aptkit.git",
|
|
11
|
+
"directory": "packages/core"
|
|
12
|
+
},
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public",
|
|
15
|
+
"registry": "https://registry.npmjs.org/"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"README.md",
|
|
19
|
+
"dist/src"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/src/index.d.ts",
|
|
24
|
+
"import": "./dist/src/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json",
|
|
29
|
+
"test": "npm run build && node --test dist/test/*.test.js"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@aptkit/agent-anomaly-monitoring": "0.0.0",
|
|
33
|
+
"@aptkit/agent-diagnostic-investigation": "0.0.0",
|
|
34
|
+
"@aptkit/agent-query": "0.0.0",
|
|
35
|
+
"@aptkit/agent-recommendation": "0.0.0",
|
|
36
|
+
"@aptkit/context": "0.0.0",
|
|
37
|
+
"@aptkit/evals": "0.0.0",
|
|
38
|
+
"@aptkit/prompts": "0.0.0",
|
|
39
|
+
"@aptkit/runtime": "0.0.0",
|
|
40
|
+
"@aptkit/tools": "0.0.0"
|
|
41
|
+
},
|
|
42
|
+
"bundledDependencies": [
|
|
43
|
+
"@aptkit/agent-anomaly-monitoring",
|
|
44
|
+
"@aptkit/agent-diagnostic-investigation",
|
|
45
|
+
"@aptkit/agent-query",
|
|
46
|
+
"@aptkit/agent-recommendation",
|
|
47
|
+
"@aptkit/context",
|
|
48
|
+
"@aptkit/evals",
|
|
49
|
+
"@aptkit/prompts",
|
|
50
|
+
"@aptkit/runtime",
|
|
51
|
+
"@aptkit/tools"
|
|
52
|
+
]
|
|
53
|
+
}
|