Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/components/ConfigDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default function ConfigDrawer({
...tools,
{
type: 'file_search' as const,
vector_store_ids: [''],
knowledge_base_ids: [''],
max_num_results: 20,
},
];
Expand All @@ -216,7 +216,7 @@ export default function ConfigDrawer({

const updateTool = (index: number, field: keyof Tool, value: any) => {
const newTools = [...tools];
if (field === 'vector_store_ids') {
if (field === 'knowledge_base_ids') {
newTools[index][field] = [value];
} else {
(newTools[index] as any)[field] = value;
Expand Down Expand Up @@ -639,8 +639,8 @@ export default function ConfigDrawer({
</label>
<input
type="text"
value={tool.vector_store_ids[0] || ''}
onChange={(e) => updateTool(index, 'vector_store_ids', e.target.value)}
value={tool.knowledge_base_ids[0] || ''}
onChange={(e) => updateTool(index, 'knowledge_base_ids', e.target.value)}
placeholder="vs_abc123"
style={{
width: '100%',
Expand Down
12 changes: 6 additions & 6 deletions app/components/ConfigModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export default function ConfigModal({ isOpen, onClose, job, assistantConfig }: C
))}
</div>
{configVersionInfo.tools.map((tool, idx) => (
Array.isArray(tool.vector_store_ids) && tool.vector_store_ids.length > 0 && (
Array.isArray(tool.knowledge_base_ids) && tool.knowledge_base_ids.length > 0 && (
<div key={`vs-${idx}`} className="mb-4">
<div className="text-xs uppercase font-semibold mb-2" style={{ color: '#737373' }}>
Vector Store IDs ({tool.type})
Expand All @@ -269,7 +269,7 @@ export default function ConfigModal({ isOpen, onClose, job, assistantConfig }: C
borderColor: '#e5e5e5',
color: '#171717'
}}>
{tool.vector_store_ids.join(', ')}
{tool.knowledge_base_ids.join(', ')}
</div>
</div>
)
Expand Down Expand Up @@ -297,7 +297,7 @@ export default function ConfigModal({ isOpen, onClose, job, assistantConfig }: C
))}
</div>
{job.config.tools.map((tool, idx) => (
Array.isArray(tool.vector_store_ids) && tool.vector_store_ids.length > 0 && (
Array.isArray(tool.knowledge_base_ids) && tool.knowledge_base_ids.length > 0 && (
<div key={`vs-${idx}`} className="mb-4">
<div className="text-xs uppercase font-semibold mb-2" style={{ color: '#737373' }}>
Vector Store IDs ({tool.type})
Expand All @@ -307,23 +307,23 @@ export default function ConfigModal({ isOpen, onClose, job, assistantConfig }: C
borderColor: '#e5e5e5',
color: '#171717'
}}>
{tool.vector_store_ids.join(', ')}
{tool.knowledge_base_ids.join(', ')}
</div>
</div>
)
))}
</div>
)}

{Array.isArray(assistantConfig?.vector_store_ids) && assistantConfig.vector_store_ids.length > 0 && (
{Array.isArray(assistantConfig?.knowledge_base_ids) && assistantConfig.knowledge_base_ids.length > 0 && (
<div>
<div className="text-xs uppercase font-semibold mb-2" style={{ color: '#737373' }}>Vector Store IDs</div>
<div className="text-sm font-mono p-3 rounded-md border" style={{
backgroundColor: '#fafafa',
borderColor: '#e5e5e5',
color: '#171717'
}}>
{assistantConfig.vector_store_ids.join(', ')}
{assistantConfig.knowledge_base_ids.join(', ')}
</div>
</div>
)}
Expand Down
63 changes: 55 additions & 8 deletions app/components/ConfigSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ export default function ConfigSelector({
</span>
</div>
<div className="text-xs mt-0.5" style={{ color: colors.text.secondary }}>
{version.provider}/{version.modelName} • {formatRelativeTime(version.timestamp)}
{version.provider}/{version.modelName} • T:{version.temperature.toFixed(2)}
{version.tools && version.tools.length > 0 && (
<> • {version.tools.map(t => t.knowledge_base_ids).flat().length} KB</>
)}
{' • '}{formatRelativeTime(version.timestamp)}
</div>
</div>
{selectedConfig?.id === version.id && (
Expand All @@ -316,14 +320,57 @@ export default function ConfigSelector({
className="mt-4 rounded-md p-4"
style={{ backgroundColor: colors.bg.secondary }}
>
<div className="text-xs font-medium mb-2" style={{ color: colors.text.secondary }}>
Prompt Preview
{/* Configuration Details */}
<div className="grid grid-cols-2 gap-4 mb-4">
<div>
<div className="text-xs font-medium mb-1" style={{ color: colors.text.secondary }}>
Provider & Model
</div>
<div className="text-sm font-mono" style={{ color: colors.text.primary }}>
{selectedConfig.provider}/{selectedConfig.modelName}
</div>
</div>
<div>
<div className="text-xs font-medium mb-1" style={{ color: colors.text.secondary }}>
Temperature
</div>
<div className="text-sm font-mono" style={{ color: colors.text.primary }}>
{selectedConfig.temperature.toFixed(2)}
</div>
</div>
{selectedConfig.tools && selectedConfig.tools.length > 0 && (
<>
<div>
<div className="text-xs font-medium mb-1" style={{ color: colors.text.secondary }}>
Knowledge Base IDs
</div>
<div className="text-xs font-mono" style={{ color: colors.text.primary }}>
{selectedConfig.tools.map(tool => tool.knowledge_base_ids).flat().join(', ') || 'None'}
</div>
</div>
<div>
<div className="text-xs font-medium mb-1" style={{ color: colors.text.secondary }}>
Max Results
</div>
<div className="text-sm font-mono" style={{ color: colors.text.primary }}>
{selectedConfig.tools[0].max_num_results}
</div>
</div>
</>
)}
</div>
<div
className="text-xs font-mono line-clamp-3"
style={{ color: colors.text.primary }}
>
{selectedConfig.instructions || 'No instructions set'}

{/* Prompt Preview */}
<div className="border-t pt-3" style={{ borderColor: colors.border }}>
<div className="text-xs font-medium mb-2" style={{ color: colors.text.secondary }}>
Prompt Preview
</div>
<div
className="text-xs font-mono line-clamp-3"
style={{ color: colors.text.primary }}
>
{selectedConfig.instructions || 'No instructions set'}
</div>
</div>
</div>
)}
Expand Down
40 changes: 37 additions & 3 deletions app/components/SimplifiedConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ export default function SimplifiedConfigEditor({
const blob = version.config_blob;
const params = blob.completion.params;

// Backend sends flattened fields (knowledge_base_ids, max_num_results) directly on params
// Convert to tools array for frontend UI compatibility
const tools: Tool[] = params.tools || [];

// If no tools array but has flattened fields, create tools array from them
// Each knowledge_base_id becomes a separate tool for UI display
if (tools.length === 0 && params.knowledge_base_ids && params.knowledge_base_ids.length > 0) {
params.knowledge_base_ids.forEach((kbId: string) => {
tools.push({
type: 'file_search',
knowledge_base_ids: [kbId], // Each tool gets one ID for UI
max_num_results: params.max_num_results || 20,
});
});
}

return {
id: version.id,
config_id: config.id,
Expand All @@ -113,8 +129,8 @@ export default function SimplifiedConfigEditor({
modelName: params.model || '',
provider: blob.completion.provider,
temperature: params.temperature || 0.7,
vectorStoreIds: params.tools?.[0]?.vector_store_ids?.[0] || '',
tools: params.tools || [],
vectorStoreIds: tools[0]?.knowledge_base_ids?.[0] || '',
tools: tools,
commit_message: version.commit_message,
};
};
Expand Down Expand Up @@ -228,14 +244,32 @@ export default function SimplifiedConfigEditor({

try {
// Build config blob
// Extract tools array and flatten to direct params fields for backend compatibility
// Collect ALL knowledge_base_ids from ALL tools into a single array
const allKnowledgeBaseIds: string[] = [];
let maxNumResults = 20; // default

tools.forEach((tool) => {
// Add all knowledge_base_ids from this tool
allKnowledgeBaseIds.push(...tool.knowledge_base_ids);
// Use max_num_results from first tool (could be made configurable)
if (allKnowledgeBaseIds.length === tool.knowledge_base_ids.length) {
maxNumResults = tool.max_num_results;
}
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think iska easy way vo sakta hai no need of iteration and all.

const maxNumResults = tools[0].max_num_results || 20 // since u are just considering the from the first tool .. idk what configurable u can do while performing iteration but this one line is enough

const allKnwledgebaseids. = tools.flatMap(tool => tool.knoweldge_base_ids)

aisa karenge toh let maxNumResults = 20 ki phi jarurat nhi padeghi


This suggestion is for just code readability .. u can ignore it if it doesn't make sense

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are correct but abhi lets merge it and refactor at a later time. Its possible all these code will be deleted entirely in 2 months.


const configBlob: ConfigBlob = {
completion: {
provider: provider as 'openai', // | 'anthropic' | 'google', // Only OpenAI supported for now
params: {
model: modelName,
instructions: instructions,
temperature: temperature,
...(tools.length > 0 && { tools }),
// Flatten tools array to direct fields for backend - support multiple knowledge bases
...(allKnowledgeBaseIds.length > 0 && {
knowledge_base_ids: allKnowledgeBaseIds,
max_num_results: maxNumResults,
}),
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion app/components/prompt-editor/ConfigDiffPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function ConfigDiffPane({
if (value.length === 0) return '[]';
return value.map((tool, idx) => {
if (tool.type === 'file_search') {
return `File Search (${tool.vector_store_ids?.[0] || 'no store'})`;
return `File Search (${tool.knowledge_base_ids?.[0] || 'no store'})`;
}
return JSON.stringify(tool);
}).join(', ');
Expand Down
8 changes: 4 additions & 4 deletions app/components/prompt-editor/ConfigEditorPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default function ConfigEditorPane({
...tools,
{
type: 'file_search' as const,
vector_store_ids: [''],
knowledge_base_ids: [''],
max_num_results: 20,
},
];
Expand All @@ -157,7 +157,7 @@ export default function ConfigEditorPane({

const handleUpdateTool = (index: number, field: keyof Tool, value: any) => {
const newTools = [...tools];
if (field === 'vector_store_ids') {
if (field === 'knowledge_base_ids') {
newTools[index][field] = [value];
} else {
(newTools[index] as any)[field] = value;
Expand Down Expand Up @@ -574,9 +574,9 @@ export default function ConfigEditorPane({
</label>
<input
type="text"
value={tool.vector_store_ids[0] || ''}
value={tool.knowledge_base_ids[0] || ''}
onChange={(e) =>
handleUpdateTool(index, 'vector_store_ids', e.target.value)
handleUpdateTool(index, 'knowledge_base_ids', e.target.value)
}
placeholder="vs_abc123"
className="w-full px-2 py-1 rounded text-xs focus:outline-none"
Expand Down
8 changes: 4 additions & 4 deletions app/components/prompt-editor/CurrentConfigTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function CurrentConfigTab({
...tools,
{
type: 'file_search',
vector_store_ids: [''],
knowledge_base_ids: [''],
max_num_results: 20,
},
]);
Expand All @@ -64,7 +64,7 @@ export default function CurrentConfigTab({

const updateTool = (index: number, field: keyof Tool, value: any) => {
const newTools = [...tools];
if (field === 'vector_store_ids') {
if (field === 'knowledge_base_ids') {
newTools[index][field] = [value];
} else {
(newTools[index] as any)[field] = value;
Expand Down Expand Up @@ -397,8 +397,8 @@ export default function CurrentConfigTab({
</label>
<input
type="text"
value={tool.vector_store_ids[0] || ''}
onChange={(e) => updateTool(index, 'vector_store_ids', e.target.value)}
value={tool.knowledge_base_ids[0] || ''}
onChange={(e) => updateTool(index, 'knowledge_base_ids', e.target.value)}
placeholder="vs_abc123"
style={{
width: '100%',
Expand Down
4 changes: 2 additions & 2 deletions app/components/prompt-editor/DiffView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ export default function DiffView({
{selectedCommit.tools.map((tool, idx) => (
<div key={idx} className="p-2 rounded" style={{ backgroundColor: colors.bg.secondary }}>
<div className="text-xs font-semibold">{tool.type}</div>
{tool.vector_store_ids && (
{tool.knowledge_base_ids && (
<div className="text-xs mt-1" style={{ color: colors.text.secondary }}>
Vector Store: {tool.vector_store_ids[0]}
Vector Store: {tool.knowledge_base_ids[0]}
</div>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type ScoreObject = NewScoreObjectV2 | NewScoreObject | LegacyScoreObject;
export interface AssistantConfig {
name: string;
model: string;
vector_store_ids: string[];
knowledge_base_ids: string[];
project_id: number;
organization_id: number;
updated_at: string;
Expand Down
29 changes: 25 additions & 4 deletions app/configurations/prompt-editor/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,40 @@ function PromptEditorContent() {

try {
// Build config blob (store prompt in instructions field)
// Extract tools array and flatten to direct params fields for backend compatibility
const tools = currentConfigBlob.completion.params.tools || [];

// Collect ALL knowledge_base_ids from ALL tools into a single array
const allKnowledgeBaseIds: string[] = [];
let maxNumResults = 20; // default

tools.forEach((tool) => {
// Add all knowledge_base_ids from this tool
allKnowledgeBaseIds.push(...tool.knowledge_base_ids);
// Use max_num_results from first tool (could be made configurable)
if (allKnowledgeBaseIds.length === tool.knowledge_base_ids.length) {
maxNumResults = tool.max_num_results;
}
});

const configBlob: ConfigBlob = {
completion: {
// provider: provider as 'openai' | 'anthropic' | 'google',
provider:provider as 'openai',
provider: currentConfigBlob.completion.provider,
params: {
model: currentConfigBlob.completion.params.model,
instructions: currentContent, // Store prompt as instructions
temperature: temperature,
...(tools.length > 0 && { tools }),
temperature: currentConfigBlob.completion.params.temperature,
// Flatten tools array to direct fields for backend - support multiple knowledge bases
...(allKnowledgeBaseIds.length > 0 && {
knowledge_base_ids: allKnowledgeBaseIds,
max_num_results: maxNumResults,
}),
},
},
};

console.log('[DEBUG] Config blob being sent:', JSON.stringify(configBlob, null, 2));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Drop or gate the debug config blob log.

Line 247 logs the full config blob (including instructions) to the console. Consider removing or gating to non-production builds.

🧹 Suggested guard
-      console.log('[DEBUG] Config blob being sent:', JSON.stringify(configBlob, null, 2));
+      if (process.env.NODE_ENV !== 'production') {
+        console.log('[DEBUG] Config blob being sent:', JSON.stringify(configBlob, null, 2));
+      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log('[DEBUG] Config blob being sent:', JSON.stringify(configBlob, null, 2));
if (process.env.NODE_ENV !== 'production') {
console.log('[DEBUG] Config blob being sent:', JSON.stringify(configBlob, null, 2));
}
🤖 Prompt for AI Agents
In `@app/configurations/prompt-editor/page.tsx` at line 247, The debug console.log
that prints the entire configBlob (console.log('[DEBUG] Config blob being
sent:', JSON.stringify(configBlob, null, 2))) should be removed or gated to
non-production; update the code around where configBlob is prepared to either
delete the debug log or wrap it in a runtime check (e.g., only run when
process.env.NODE_ENV !== 'production' or when a specific DEBUG flag is enabled)
so the full instructions/config are not exposed in production logs.


// Check if updating existing config (same name exists)
const existingConfig = savedConfigs.find(c => c.name === currentConfigName.trim());

Expand Down
8 changes: 6 additions & 2 deletions app/configurations/prompt-editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface DiffStats {

export interface Tool {
type: 'file_search';
vector_store_ids: string[];
knowledge_base_ids: string[];
max_num_results: number;
}

Expand All @@ -36,7 +36,11 @@ export interface ConfigBlob {
model: string;
instructions: string;
temperature: number;
tools: Tool[];
// Frontend uses tools array for UI
tools?: Tool[];
// Backend expects these as direct fields (flattened from tools array)
knowledge_base_ids?: string[];
max_num_results?: number;
};
};
}
Expand Down
Loading