Context variables (#214)

* move prompts panel to variables

* variable shows both name and value

* added modal to add variables

* removed warning on edits

* adding or updating variables only uses the modal

* append variable context to agent instructions

* add dummy value to the variable values when downloading json

* fixed @variable mentions in the instruction editor

* change placeholder text for variables when json is imported
This commit is contained in:
arkml 2025-08-21 17:29:27 +05:30 committed by GitHub
parent 981cff3b3f
commit ab014f788c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 358 additions and 23 deletions

View file

@ -55,11 +55,15 @@ export function createAtMentions({ agents, prompts, tools, pipelines = [], curre
// Add prompts (always allowed)
for (const prompt of prompts) {
const id = `prompt:${prompt.name}`;
// Use 'variable' for base_prompt types, 'prompt' for others
const isVariable = prompt.type === 'base_prompt';
const type = isVariable ? 'variable' : 'prompt';
const label = isVariable ? 'Variable' : 'Prompt';
const id = `${type}:${prompt.name}`;
atMentions.push({
id,
value: id,
label: `Prompt: ${prompt.name}`,
label: `${label}: ${prompt.name}`,
denotationChar: "@",
link: id,
target: "_self"

View file

@ -15,6 +15,6 @@ export const USE_VOICE_FEATURE = false;
export const USE_TRANSFER_CONTROL_OPTIONS = false;
export const USE_PRODUCT_TOUR = false;
export const SHOW_COPILOT_MARQUEE = false;
export const SHOW_PROMPTS_SECTION = false;
export const SHOW_PROMPTS_SECTION = true;
export const SHOW_DARK_MODE_TOGGLE = false;
export const SHOW_VISUALIZATION = false

View file

@ -129,8 +129,8 @@ export function sanitizeTextWithMentions(
sanitized: string;
entities: z.infer<typeof ConnectedEntity>[];
} {
// Regex to match [@type:name](#type:something) pattern where type is tool/prompt/agent/pipeline
const mentionRegex = /\[@(tool|prompt|agent|pipeline):([^\]]+)\]\(#mention\)/g;
// Regex to match [@type:name](#type:something) pattern where type is tool/prompt/agent/pipeline/variable
const mentionRegex = /\[@(tool|prompt|agent|pipeline|variable):([^\]]+)\]\(#mention\)/g;
const seen = new Set<string>();
// collect entities
@ -144,8 +144,10 @@ export function sanitizeTextWithMentions(
return true;
})
.map(match => {
// Treat @variable: as @prompt: internally
const type = match[1] === 'variable' ? 'prompt' : match[1];
return {
type: match[1] as 'tool' | 'prompt' | 'agent' | 'pipeline',
type: type as 'tool' | 'prompt' | 'agent' | 'pipeline',
name: match[2],
};
})
@ -176,6 +178,12 @@ export function sanitizeTextWithMentions(
const id = `${entity.type}:${entity.name}`;
const textToReplace = `[@${id}](#mention)`;
text = text.replace(textToReplace, `[@${id}]`);
// Also handle @variable: mentions for prompts
if (entity.type === 'prompt') {
const variableTextToReplace = `[@variable:${entity.name}](#mention)`;
text = text.replace(variableTextToReplace, `[@variable:${entity.name}]`);
}
}
return {