Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | 2213x 2213x 92x 89x 89x 2213x 78x 75x 75x 2213x 56x 56x 56x 2213x 60x 60x 60x 2213x 35x 35x 35x 2213x 7x 7x 7x 2213x 5x 5x 5x 2213x 3x 3x 2213x 8x 8x 2213x 5x 4x | import {
Rule,
RuleCatalogue,
RuleCreate,
RuleScopeTargets,
RuleUpdate,
} from "@/objects/Rule";
import {
GovernanceActivityList,
GovernanceActivityQuery,
} from "@/objects/Governance";
import {
CreateRulesFromConfigRequest,
CreateRulesFromConfigResponse,
GenerateRulesRequest,
RulesGenerationProposal,
} from "@/objects/RuleSetup";
import { Dictionary } from "@/types/ext";
import { AxiosRequestConfig } from "axios";
import { HistoricalAPIRouter } from "../HistoricalApiRouter";
export class RuleRouter extends HistoricalAPIRouter {
constructor(
host: string,
token: string | null = null,
default_config: AxiosRequestConfig | null = null,
headers: Dictionary<string> = {},
) {
super("rules", host, token, default_config, headers);
}
/**
* The rule grammar — condition fields, operators and actions — as the
* engine can actually evaluate it.
*
* Served from svc-core's registries so the builder never offers a field or
* action the backend would skip with a warning. Declared before `get` on
* the backend router too, so `/catalogue` is not parsed as a rule id.
*/
catalogue = async (): Promise<RuleCatalogue | null> => {
const res = await this.api.get<RuleCatalogue>(super.endpoint("catalogue"));
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
/**
* Every resource the current user may pin a rule to, grouped by scope.
*
* One call instead of asking the agent, model, skill, worker, project and
* organisation routers each in turn — and the same payload is what lets a
* rule list show "applies to Support Agent" rather than a UUID.
*
* Unlike `catalogue` this is per-user, so it is not cached indefinitely:
* creating an agent should make it selectable as a rule target.
*/
targets = async (): Promise<RuleScopeTargets | null> => {
const res = await this.api.get<RuleScopeTargets>(super.endpoint("targets"));
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
/**
* What the rules have actually done — one row per rule per invocation.
*
* Filtered, counted and paged on the server: the summary counts every row
* the filters select, not the page in hand, and a log is a backlog. The
* rules that did *nothing* are the reason it exists, so `no_change` and
* `not_matched` are ordinary outcomes here rather than an "other" bucket.
*/
activity = async (
params?: GovernanceActivityQuery,
): Promise<GovernanceActivityList | null> => {
const res = await this.api.get<GovernanceActivityList>(
super.endpoint("activity"),
{ params },
);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
/** `include_system` adds the built-in rules after the user's own — for
* the Rules tab only: a built-in governs nobody, so it must never be
* counted among the rules in force. */
list = async (params?: {
layer?: string;
owner_organisation_id?: string;
owner_project_id?: string;
include_system?: boolean;
}): Promise<Rule[] | null> => {
const res = await this.api.get<Rule[]>(this.prefix, { params });
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
get = async (id: string): Promise<Rule | null> => {
const res = await this.api.get<Rule>(super.endpoint(id));
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
create = async (body: RuleCreate): Promise<Rule | null> => {
const res = await this.api.post<Rule>(this.prefix, body);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
update = async (id: string, body: RuleUpdate): Promise<Rule | null> => {
const res = await this.api.patch<Rule>(super.endpoint(id), body);
Eif (super.validRes(res)) {
return res.data;
}
return null;
};
delete = async (id: string): Promise<boolean> => {
const res = await this.api.delete(super.endpoint(id));
return super.validRes(res);
};
// ── Generative setup ──────────────────────────────────────────────────
//
// Proposes rules from a description of what the user wants governed. The
// vocabulary travels with the request server-side, and anything written
// outside it is dropped there with a reason — so what comes back is
// already a rule this engine can evaluate, not a suggestion to interpret.
generateConfig = async (
body: GenerateRulesRequest,
): Promise<RulesGenerationProposal> => {
// Generation is a single long LLM call (30-90s); spread the default
// config so withCredentials survives the per-request timeout override.
const res = await this.api.post<RulesGenerationProposal>(
super.endpoint("generate"),
body,
{ ...(this.api.default_config ?? {}), timeout: 180000 },
);
return res.data;
};
createFromConfig = async (
body: CreateRulesFromConfigRequest,
): Promise<CreateRulesFromConfigResponse> => {
const res = await this.api.post<CreateRulesFromConfigResponse>(
super.endpoint("create-from-config"),
body,
);
return res.data;
};
}
|