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 163 164 | 104x 80x 80x 56x 56x 38x 38x 38x 320x 136x 51x 16x 16x 1x | import { encodeResourceId } from "@/components/detail";
import { ActivityResourceType } from "@/objects/Activity";
import { APP_ROUTES, ROUTE_PARAMS } from "@/routes/const";
import { MCP_AVAILABLE } from "@/util/mcp";
/**
* Where a resource of a given type lives, by id.
*
* Two surfaces need this and neither owns it: the Activity feed links a change
* event to the thing it changed, and a generative invocation lists what it
* produced. Both are given a `(resource_type, resource_id)` pair off the
* version trail — which is deliberately a soft reference, so the type is a
* string and the route has to be looked up.
*
* Ids are base64-encoded in this app's routes, matching `useResourceId`.
*/
const ROUTES: Partial<Record<ActivityResourceType, [string, string]>> = {
agent: [APP_ROUTES.USER.INFERENCE.AGENTS.id, ROUTE_PARAMS.AGENT.id],
skill: [APP_ROUTES.USER.INFERENCE.SKILLS.id, ROUTE_PARAMS.SKILL.id],
skillset: [APP_ROUTES.USER.INFERENCE.SKILLSETS.id, ROUTE_PARAMS.SKILLSET.id],
swarm: [APP_ROUTES.USER.INFERENCE.SWARMS.id, ROUTE_PARAMS.SWARM.id],
// A toolkit bundles MCP servers, which are not available in this release
// (util/mcp.ts), so its page is not served and there is nothing to open.
...(MCP_AVAILABLE
? {
toolkit: [APP_ROUTES.USER.INFERENCE.TOOLKITS.id, ROUTE_PARAMS.TOOLKIT.id],
}
: {}),
rule: [APP_ROUTES.USER.GOVERNANCE.RULES.id, ROUTE_PARAMS.RULE.id],
knowledge: [APP_ROUTES.USER.KNOWLEDGE.id, ROUTE_PARAMS.KNOWLEDGE.id],
knowledge_repository: [
APP_ROUTES.USER.KNOWLEDGE.REPOSITORIES.id,
ROUTE_PARAMS.REPOSITORY.id,
],
dashboard: [APP_ROUTES.USER.DASHBOARDS.id, ROUTE_PARAMS.DASHBOARD.id],
// Keyed by the *backend's* resource type — `experiment` and `test_suite`
// are what the version trail records, whatever the product calls them now.
experiment: [
APP_ROUTES.USER.GOVERNANCE.EVALUATION.EXPERIMENTS.id,
ROUTE_PARAMS.EXPERIMENT.id,
],
test_suite: [
APP_ROUTES.USER.GOVERNANCE.EVALUATION.DATASETS.id,
ROUTE_PARAMS.DATASET.id,
],
simulation_world: [
APP_ROUTES.USER.INFERENCE.SIMULATIONS.WORLDS.id,
ROUTE_PARAMS.WORLD.id,
],
project: [APP_ROUTES.USER.PROJECTS.id, ROUTE_PARAMS.PROJECT.id],
organisation: [
APP_ROUTES.USER.ORGANISATIONS.id,
ROUTE_PARAMS.ORGANISATION.id,
],
// mcp_server has no detail route of its own — it is edited inline on the
// Inference page — so it is deliberately absent rather than mapped to a
// page that would 404. custom_worker is absent for the same reason: a worker
// is configured on the graph node that uses it, so there is no page to open.
// tool is absent because the resource itself is gone — built-ins belong to
// the platform, and a history row naming one outlives the code that wrote it.
};
/**
* The detail route for one resource, or null when there is nowhere to go.
*
* Null for a type with no detail page, and for an unrecognised type: the
* version trail outlives the code that wrote it, so a type this build has
* never heard of is a normal thing to be handed. A missing link is a better
* answer than a 404.
*/
export function resourceHref(
type: ActivityResourceType | string,
id: string,
): string | null {
const route = ROUTES[type as ActivityResourceType];
return route ? route[0].replace(route[1], encodeResourceId(id)) : null;
}
/**
* A deep link to one message inside one chat.
*
* Both activity surfaces hand a reader a *record of something that happened* —
* a run on the Activity page, a rule evaluation on Governance → Rules →
* Activity — and the next question is always "show me the message". Linking to
* the agent's chat alone answers it with whatever conversation happens to be
* open, which for an agent with fifty turns is not an answer.
*
* The conversation and message ids travel as query params rather than route
* params: they select a *view* of the chat page, not a different page, and
* both chat pages read them (`?conversation=`, `?message=`). Plain uuids —
* unlike a route id there is nothing to decode, and a link a person can read
* is worth more here than symmetry with `encodeResourceId`.
*
* Null when there is nothing to open: no agent or model to host the chat, or
* no conversation, which is the honest answer for a turn that never persisted.
*/
export function chatMessageHref(target: {
agentId?: string | null;
modelId?: string | null;
conversationId?: string | null;
messageId?: string | null;
}): string | null {
const base = target.agentId
? APP_ROUTES.USER.INFERENCE.AGENTS.chat.replace(
ROUTE_PARAMS.AGENT.id,
encodeResourceId(target.agentId),
)
: target.modelId
? APP_ROUTES.USER.INFERENCE.MODELS.chat.replace(
ROUTE_PARAMS.MODEL.id,
encodeResourceId(target.modelId),
)
: null;
if (!base || !target.conversationId) return null;
const params = new URLSearchParams({ conversation: target.conversationId });
// A conversation with no message still opens the right thread; the ring
// simply has nothing to land on.
if (target.messageId) params.set("message", target.messageId);
return `${base}?${params.toString()}`;
}
export default resourceHref;
/**
* One governed turn's decision record — an answer's or a skill run's, by
* its `invocation_id`. What "Why did it do this?" opens. Null without an id:
* a turn from before turns had ids has no record to open.
*/
export function decisionHref(invocationId?: string | null): string | null {
if (!invocationId) return null;
return APP_ROUTES.USER.GOVERNANCE.DECISIONS.id.replace(
ROUTE_PARAMS.DECISION.id,
encodeResourceId(invocationId),
);
}
/** A swarm's page. */
export function swarmHref(swarmId: string): string {
return APP_ROUTES.USER.INFERENCE.SWARMS.id.replace(
ROUTE_PARAMS.SWARM.id,
encodeResourceId(swarmId),
);
}
/** One run of a swarm — its own page, where the inbox's notices land —
* opened on one of its tasks by handle, when `task` is given. */
export function swarmRunHref(runId: string, task?: string): string {
const page = APP_ROUTES.USER.INFERENCE.SWARMS.run.replace(
ROUTE_PARAMS.SWARM.run,
encodeResourceId(runId),
);
return task ? `${page}?task=${encodeURIComponent(task)}` : page;
}
/**
* One run of a skill. The Activity feed links a skill run's LLM call here,
* and the skill page links each row of its run list.
*/
export function skillRunHref(skillId: string, runId: string): string {
return APP_ROUTES.USER.INFERENCE.SKILLS.run
.replace(ROUTE_PARAMS.SKILL.id, encodeResourceId(skillId))
.replace(ROUTE_PARAMS.SKILL.run, encodeResourceId(runId));
}
|