refactor(api): extract assistant blueprint rate-card slice
This commit is contained in:
@@ -121,6 +121,10 @@ import {
|
||||
resourceMutationToolDefinitions,
|
||||
resourceReadToolDefinitions,
|
||||
} from "./assistant-tools/resources.js";
|
||||
import {
|
||||
blueprintsRateCardsToolDefinitions,
|
||||
createBlueprintsRateCardsExecutors,
|
||||
} from "./assistant-tools/blueprints-rate-cards.js";
|
||||
import {
|
||||
withToolAccess,
|
||||
type ToolAccessRequirements,
|
||||
@@ -408,16 +412,6 @@ const LEGACY_MONOLITHIC_TOOL_ACCESS: Partial<Record<string, ToolAccessRequiremen
|
||||
get_pending_vacation_approvals: { allowedSystemRoles: [...MANAGER_ASSISTANT_ROLES] },
|
||||
get_entitlement_summary: { allowedSystemRoles: [...MANAGER_ASSISTANT_ROLES] },
|
||||
set_entitlement: { allowedSystemRoles: [...MANAGER_ASSISTANT_ROLES] },
|
||||
list_blueprints: { requiresPlanningRead: true },
|
||||
get_blueprint: { requiresPlanningRead: true },
|
||||
list_rate_cards: {
|
||||
allowedSystemRoles: [...CONTROLLER_ASSISTANT_ROLES],
|
||||
requiresCostView: true,
|
||||
},
|
||||
resolve_rate: {
|
||||
allowedSystemRoles: [...CONTROLLER_ASSISTANT_ROLES],
|
||||
requiresCostView: true,
|
||||
},
|
||||
get_country: { requiresResourceOverview: true },
|
||||
get_dashboard_detail: { allowedSystemRoles: [...CONTROLLER_ASSISTANT_ROLES] },
|
||||
delete_project: { requiredPermissions: [PermissionKey.MANAGE_PROJECTS] },
|
||||
@@ -2275,59 +2269,7 @@ export const TOOL_DEFINITIONS: ToolDef[] = withToolAccess([
|
||||
...staffingDemandMutationToolDefinitions,
|
||||
|
||||
// ── BLUEPRINT ──
|
||||
{
|
||||
type: "function",
|
||||
function: {
|
||||
name: "list_blueprints",
|
||||
description: "List available project blueprints with their field definitions.",
|
||||
parameters: { type: "object", properties: {} },
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "function",
|
||||
function: {
|
||||
name: "get_blueprint",
|
||||
description: "Get detailed blueprint with all field definitions and role presets.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
identifier: { type: "string", description: "Blueprint ID or name (partial match)" },
|
||||
},
|
||||
required: ["identifier"],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
// ── RATE CARDS ──
|
||||
{
|
||||
type: "function",
|
||||
function: {
|
||||
name: "list_rate_cards",
|
||||
description: "List rate cards with their effective dates and line items.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
query: { type: "string", description: "Search by name" },
|
||||
limit: { type: "integer", description: "Max results. Default: 20" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "function",
|
||||
function: {
|
||||
name: "resolve_rate",
|
||||
description: "Look up the applicable rate for a resource, role, or management level from rate cards.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
resourceId: { type: "string", description: "Resource ID or name" },
|
||||
roleName: { type: "string", description: "Role name" },
|
||||
date: { type: "string", description: "Date to check rate for (YYYY-MM-DD). Default: today" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
...blueprintsRateCardsToolDefinitions,
|
||||
|
||||
// ── ESTIMATES ──
|
||||
...estimateReadToolDefinitions,
|
||||
@@ -3020,6 +2962,15 @@ const executors = {
|
||||
resolveResourceIdentifier,
|
||||
resolveProjectIdentifier,
|
||||
}),
|
||||
...createBlueprintsRateCardsExecutors({
|
||||
createBlueprintCaller,
|
||||
createRateCardCaller,
|
||||
createScopedCallerContext,
|
||||
resolveResourceIdentifier,
|
||||
resolveEntityOrAssistantError,
|
||||
parseOptionalIsoDate,
|
||||
fmtDate,
|
||||
}),
|
||||
|
||||
async search_estimates(params: {
|
||||
projectCode?: string; query?: string; status?: string; limit?: number;
|
||||
@@ -3388,72 +3339,6 @@ const executors = {
|
||||
};
|
||||
},
|
||||
|
||||
// ── BLUEPRINT ──
|
||||
|
||||
async list_blueprints(_params: Record<string, never>, ctx: ToolContext) {
|
||||
const caller = createBlueprintCaller(createScopedCallerContext(ctx));
|
||||
const blueprints = await caller.listSummaries();
|
||||
return blueprints.map((b) => ({
|
||||
id: b.id,
|
||||
name: b.name,
|
||||
projectCount: b._count.projects,
|
||||
}));
|
||||
},
|
||||
|
||||
async get_blueprint(params: { identifier: string }, ctx: ToolContext) {
|
||||
const caller = createBlueprintCaller(createScopedCallerContext(ctx));
|
||||
const bp = await resolveEntityOrAssistantError(
|
||||
() => caller.getByIdentifier({ identifier: params.identifier }),
|
||||
`Blueprint not found: ${params.identifier}`,
|
||||
);
|
||||
if ("error" in bp) {
|
||||
return bp;
|
||||
}
|
||||
return {
|
||||
id: bp.id,
|
||||
name: bp.name,
|
||||
fieldDefs: bp.fieldDefs,
|
||||
rolePresets: bp.rolePresets,
|
||||
};
|
||||
},
|
||||
|
||||
// ── RATE CARDS ──
|
||||
|
||||
async list_rate_cards(params: { query?: string; limit?: number }, ctx: ToolContext) {
|
||||
const caller = createRateCardCaller(createScopedCallerContext(ctx));
|
||||
const cards = await caller.list({
|
||||
isActive: true,
|
||||
...(params.query ? { search: params.query } : {}),
|
||||
});
|
||||
return cards.map((c) => ({
|
||||
id: c.id,
|
||||
name: c.name,
|
||||
effectiveFrom: fmtDate(c.effectiveFrom),
|
||||
effectiveTo: fmtDate(c.effectiveTo),
|
||||
lineCount: c._count.lines,
|
||||
})).slice(0, Math.min(params.limit ?? 20, 50));
|
||||
},
|
||||
|
||||
async resolve_rate(params: { resourceId?: string; roleName?: string; date?: string }, ctx: ToolContext) {
|
||||
const caller = createRateCardCaller(createScopedCallerContext(ctx));
|
||||
const date = parseOptionalIsoDate(params.date, "date");
|
||||
if (params.resourceId) {
|
||||
const resource = await resolveResourceIdentifier(ctx, params.resourceId);
|
||||
if ("error" in resource) {
|
||||
return resource;
|
||||
}
|
||||
return caller.resolveBestRate({
|
||||
resourceId: resource.id,
|
||||
...(date ? { date } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
return caller.resolveBestRate({
|
||||
...(params.roleName ? { roleName: params.roleName } : {}),
|
||||
...(date ? { date } : {}),
|
||||
});
|
||||
},
|
||||
|
||||
// ── ESTIMATES ──
|
||||
...createEstimateExecutors({
|
||||
assertPermission,
|
||||
|
||||
Reference in New Issue
Block a user