> = {
openai: {
title: "OpenAI",
provider: "openai",
- description: "Use gpt-4, gpt-3.5-turbo, or any other OpenAI model",
+ description: "Use gpt-5, gpt-4, or any other OpenAI model",
longDescription:
- "Use gpt-4, gpt-3.5-turbo, or any other OpenAI model. See [here](https://openai.com/product#made-for-developers) to obtain an API key.",
+ "Use gpt-5, gpt-4, or any other OpenAI model. See [here](https://openai.com/product#made-for-developers) to obtain an API key.",
icon: "openai.png",
tags: [ModelProviderTags.RequiresApiKey],
packages: [
+ models.gpt5,
models.gpt4o,
models.gpt4omini,
models.gpt4turbo,
diff --git a/gui/src/pages/gui/ToolCallDiv/index.tsx b/gui/src/pages/gui/ToolCallDiv/index.tsx
index ae2839926..ca99d8fdd 100644
--- a/gui/src/pages/gui/ToolCallDiv/index.tsx
+++ b/gui/src/pages/gui/ToolCallDiv/index.tsx
@@ -80,7 +80,7 @@ export function ToolCallDiv({
if (shouldShowGroupedUI) {
return (
-
+
(
-
+
{renderToolCall(toolCallState)}
));
diff --git a/gui/src/redux/thunks/callToolById.ts b/gui/src/redux/thunks/callToolById.ts
index 468838ec6..32898f30e 100644
--- a/gui/src/redux/thunks/callToolById.ts
+++ b/gui/src/redux/thunks/callToolById.ts
@@ -14,6 +14,7 @@ import {
import { ThunkApiType } from "../store";
import { findToolCallById, logToolUsage } from "../util";
import { streamResponseAfterToolCall } from "./streamResponseAfterToolCall";
+import { DEFAULT_TOOL_SETTING } from "../slices/uiSlice";
export const callToolById = createAsyncThunk<
void,
@@ -36,9 +37,11 @@ export const callToolById = createAsyncThunk<
// Check if this is an auto-approved tool
const toolSettings = state.ui.toolSettings;
- const isAutoApproved =
- toolSettings[toolCallState.toolCall.function.name] ===
- "allowedWithoutPermission";
+ const toolPolicy =
+ toolSettings[toolCallState.toolCall.function.name] ??
+ toolCallState.tool?.defaultToolPolicy ??
+ DEFAULT_TOOL_SETTING;
+ const isAutoApproved = toolPolicy === "allowedWithoutPermission";
posthog.capture("gui_tool_call_decision", {
decision: isAutoApproved ? "auto_accept" : "accept",
diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts
index 6e3939a5b..e2f645858 100644
--- a/gui/src/redux/thunks/streamNormalInput.ts
+++ b/gui/src/redux/thunks/streamNormalInput.ts
@@ -25,9 +25,11 @@ import { constructMessages } from "../util/constructMessages";
import { modelSupportsNativeTools } from "core/llm/toolSupport";
import { addSystemMessageToolsToSystemMessage } from "core/tools/systemMessageTools/buildToolsSystemMessage";
import { interceptSystemToolCalls } from "core/tools/systemMessageTools/interceptSystemToolCalls";
+import { SystemMessageToolCodeblocksFramework } from "core/tools/systemMessageTools/toolCodeblocks";
import { selectCurrentToolCalls } from "../selectors/selectToolCalls";
import { getBaseSystemMessage } from "../util/getBaseSystemMessage";
import { callToolById } from "./callToolById";
+import { DEFAULT_TOOL_SETTING } from "../slices/uiSlice";
/**
* Handles the execution of tool calls that may be automatically accepted.
* Sets all tools as generated first, then executes auto-approved tool calls.
@@ -35,6 +37,7 @@ import { callToolById } from "./callToolById";
async function handleToolCallExecution(
dispatch: AppThunkDispatch,
getState: () => RootState,
+ activeTools: Tool[],
): Promise
{
const newState = getState();
const toolSettings = newState.ui.toolSettings;
@@ -51,11 +54,15 @@ async function handleToolCallExecution(
}
// Check if ALL tool calls are auto-approved - if not, wait for user approval
- const allAutoApproved = toolCallStates.every(
- (toolCallState) =>
- toolSettings[toolCallState.toolCall.function.name] ===
- "allowedWithoutPermission",
- );
+ const allAutoApproved = toolCallStates.every((toolCallState) => {
+ const toolPolicy =
+ toolSettings[toolCallState.toolCall.function.name] ??
+ activeTools.find(
+ (tool) => tool.function.name === toolCallState.toolCall.function.name,
+ )?.defaultToolPolicy ??
+ DEFAULT_TOOL_SETTING;
+ return toolPolicy == "allowedWithoutPermission";
+ });
// Set all tools as generated first
toolCallStates.forEach((toolCallState) => {
@@ -147,6 +154,9 @@ export const streamNormalInput = createAsyncThunk<
// Use the centralized selector to determine if system message tools should be used
const useSystemTools = selectUseSystemMessageTools(state);
const useNativeTools = !useSystemTools && supportsNativeTools;
+ const systemToolsFramework = useSystemTools
+ ? new SystemMessageToolCodeblocksFramework()
+ : undefined;
// Construct completion options
let completionOptions: LLMFullCompletionOptions = {};
@@ -169,10 +179,15 @@ export const streamNormalInput = createAsyncThunk<
const baseSystemMessage = getBaseSystemMessage(
state.session.mode,
selectedChatModel,
+ activeTools,
);
- const systemMessage = useSystemTools
- ? addSystemMessageToolsToSystemMessage(baseSystemMessage, activeTools)
+ const systemMessage = systemToolsFramework
+ ? addSystemMessageToolsToSystemMessage(
+ systemToolsFramework,
+ baseSystemMessage,
+ activeTools,
+ )
: baseSystemMessage;
const withoutMessageIds = state.session.history.map((item) => {
@@ -185,7 +200,7 @@ export const streamNormalInput = createAsyncThunk<
systemMessage,
state.config.config.rules,
state.ui.ruleSettings,
- !useNativeTools,
+ systemToolsFramework,
);
// TODO parallel tool calls will cause issues with this
@@ -233,8 +248,8 @@ export const streamNormalInput = createAsyncThunk<
},
streamAborter.signal,
);
- if (!useNativeTools && activeTools.length > 0) {
- gen = interceptSystemToolCalls(gen, streamAborter);
+ if (systemToolsFramework && activeTools.length > 0) {
+ gen = interceptSystemToolCalls(gen, streamAborter, systemToolsFramework);
}
let next = await gen.next();
@@ -289,11 +304,16 @@ export const streamNormalInput = createAsyncThunk<
// Check if ALL generating tool calls are auto-approved
const allAutoApproved =
generatingToolCalls.length > 0 &&
- generatingToolCalls.every(
- (toolCallState) =>
- toolSettings[toolCallState.toolCall.function.name] ===
- "allowedWithoutPermission",
- );
+ generatingToolCalls.every((toolCallState) => {
+ const toolPolicy =
+ toolSettings[toolCallState.toolCall.function.name] ??
+ activeTools.find(
+ (tool) =>
+ tool.function.name === toolCallState.toolCall.function.name,
+ )?.defaultToolPolicy ??
+ DEFAULT_TOOL_SETTING;
+ return toolPolicy == "allowedWithoutPermission";
+ });
// Only set inactive if:
// 1. There are no tool calls, OR
@@ -303,6 +323,6 @@ export const streamNormalInput = createAsyncThunk<
dispatch(setInactive());
}
- await handleToolCallExecution(dispatch, getState);
+ await handleToolCallExecution(dispatch, getState, activeTools);
},
);
diff --git a/gui/src/redux/util/constructMessages.ts b/gui/src/redux/util/constructMessages.ts
index ac70bdafa..f75eb8b49 100644
--- a/gui/src/redux/util/constructMessages.ts
+++ b/gui/src/redux/util/constructMessages.ts
@@ -15,6 +15,7 @@ import {
NO_TOOL_CALL_OUTPUT_MESSAGE,
} from "core/tools/constants";
import { convertToolCallStatesToSystemCallsAndOutput } from "core/tools/systemMessageTools/convertSystemTools";
+import { SystemMessageToolsFramework } from "core/tools/systemMessageTools/types";
import { findLast, findLastIndex } from "core/util/findLast";
import {
normalizeToMessageParts,
@@ -30,7 +31,7 @@ export function constructMessages(
baseSystemMessage: string | undefined,
availableRules: RuleWithSource[],
rulePolicies: RulePolicies,
- useSystemMessageTools?: boolean,
+ useSystemToolsFramework?: SystemMessageToolsFramework,
): {
messages: ChatMessage[];
appliedRules: RuleWithSource[];
@@ -95,11 +96,12 @@ export function constructMessages(
});
} else if (item.message.role === "assistant") {
// When using system message tools, convert tool calls/states to text content
- if (item.toolCallStates?.length && useSystemMessageTools) {
+ if (item.toolCallStates?.length && useSystemToolsFramework) {
const { userMessage, assistantMessage } =
convertToolCallStatesToSystemCallsAndOutput(
item.message,
item.toolCallStates ?? [],
+ useSystemToolsFramework,
);
msgs.push({
message: assistantMessage,
diff --git a/gui/src/redux/util/getBaseSystemMessage.test.ts b/gui/src/redux/util/getBaseSystemMessage.test.ts
index ef2eef559..ed069693a 100644
--- a/gui/src/redux/util/getBaseSystemMessage.test.ts
+++ b/gui/src/redux/util/getBaseSystemMessage.test.ts
@@ -1,10 +1,10 @@
-import { ModelDescription } from "core";
+import { ModelDescription, Tool } from "core";
import {
DEFAULT_AGENT_SYSTEM_MESSAGE,
DEFAULT_CHAT_SYSTEM_MESSAGE,
DEFAULT_PLAN_SYSTEM_MESSAGE,
} from "core/llm/defaultSystemMessages";
-import { getBaseSystemMessage } from "./getBaseSystemMessage";
+import { getBaseSystemMessage, NO_TOOL_WARNING } from "./getBaseSystemMessage";
test("getBaseSystemMessage should return the correct system message based on mode", () => {
const mockModel = {
@@ -13,33 +13,74 @@ test("getBaseSystemMessage should return the correct system message based on mod
baseAgentSystemMessage: "Custom Agent System Message",
} as ModelDescription;
- // Test agent mode with custom message
- expect(getBaseSystemMessage("agent", mockModel)).toBe(
+ const mockTool = {
+ function: {
+ name: "testTool",
+ description: "Test tool",
+ parameters: {},
+ },
+ } as Tool;
+
+ // Test agent mode with custom message and tools
+ expect(getBaseSystemMessage("agent", mockModel, [mockTool])).toBe(
"Custom Agent System Message",
);
- // Test plan mode with custom message
- expect(getBaseSystemMessage("plan", mockModel)).toBe(
+ // Test plan mode with custom message and tools
+ expect(getBaseSystemMessage("plan", mockModel, [mockTool])).toBe(
"Custom Plan System Message",
);
- // Test chat mode with custom message
- expect(getBaseSystemMessage("chat", mockModel)).toBe(
+ // Test chat mode with custom message and tools
+ expect(getBaseSystemMessage("chat", mockModel, [mockTool])).toBe(
"Custom Chat System Message",
);
- // Test agent mode with default message
- expect(getBaseSystemMessage("agent", {} as ModelDescription)).toBe(
- DEFAULT_AGENT_SYSTEM_MESSAGE,
- );
+ // Test agent mode with default message and tools
+ expect(
+ getBaseSystemMessage("agent", {} as ModelDescription, [mockTool]),
+ ).toBe(DEFAULT_AGENT_SYSTEM_MESSAGE);
- // Test plan mode with default message
- expect(getBaseSystemMessage("plan", {} as ModelDescription)).toBe(
+ // Test plan mode with default message and tools
+ expect(getBaseSystemMessage("plan", {} as ModelDescription, [mockTool])).toBe(
DEFAULT_PLAN_SYSTEM_MESSAGE,
);
- // Test chat mode with default message
- expect(getBaseSystemMessage("chat", {} as ModelDescription)).toBe(
+ // Test chat mode with default message and tools
+ expect(getBaseSystemMessage("chat", {} as ModelDescription, [mockTool])).toBe(
DEFAULT_CHAT_SYSTEM_MESSAGE,
);
});
+
+test("getBaseSystemMessage should append no-tools warning for agent/plan modes without tools", () => {
+ const mockModel = {
+ baseChatSystemMessage: "Custom Chat System Message",
+ basePlanSystemMessage: "Custom Plan System Message",
+ baseAgentSystemMessage: "Custom Agent System Message",
+ } as ModelDescription;
+
+ // Test agent mode without tools
+ expect(getBaseSystemMessage("agent", mockModel, [])).toBe(
+ "Custom Agent System Message" + NO_TOOL_WARNING,
+ );
+
+ // Test plan mode without tools
+ expect(getBaseSystemMessage("plan", mockModel, [])).toBe(
+ "Custom Plan System Message" + NO_TOOL_WARNING,
+ );
+
+ // Test chat mode without tools (should not append warning)
+ expect(getBaseSystemMessage("chat", mockModel, [])).toBe(
+ "Custom Chat System Message",
+ );
+
+ // Test agent mode with undefined tools
+ expect(getBaseSystemMessage("agent", mockModel)).toBe(
+ "Custom Agent System Message" + NO_TOOL_WARNING,
+ );
+
+ // Test plan mode with undefined tools
+ expect(getBaseSystemMessage("plan", mockModel)).toBe(
+ "Custom Plan System Message" + NO_TOOL_WARNING,
+ );
+});
diff --git a/gui/src/redux/util/getBaseSystemMessage.ts b/gui/src/redux/util/getBaseSystemMessage.ts
index b27d38ff7..c03493b15 100644
--- a/gui/src/redux/util/getBaseSystemMessage.ts
+++ b/gui/src/redux/util/getBaseSystemMessage.ts
@@ -1,19 +1,32 @@
-import { ModelDescription } from "core";
+import { ModelDescription, Tool } from "core";
import {
DEFAULT_AGENT_SYSTEM_MESSAGE,
DEFAULT_CHAT_SYSTEM_MESSAGE,
DEFAULT_PLAN_SYSTEM_MESSAGE,
} from "core/llm/defaultSystemMessages";
+export const NO_TOOL_WARNING =
+ "\n\nTHE USER HAS NOT PROVIDED ANY TOOLS, DO NOT ATTEMPT TO USE ANY TOOLS. STOP AND LET THE USER KNOW THAT THERE ARE NO TOOLS AVAILABLE. The user can provide tools by enabling them in the Tool Policies section of the notch (wrench icon)";
+
export function getBaseSystemMessage(
messageMode: string,
model: ModelDescription,
+ activeTools?: Tool[],
): string {
+ let baseMessage: string;
+
if (messageMode === "agent") {
- return model.baseAgentSystemMessage ?? DEFAULT_AGENT_SYSTEM_MESSAGE;
+ baseMessage = model.baseAgentSystemMessage ?? DEFAULT_AGENT_SYSTEM_MESSAGE;
} else if (messageMode === "plan") {
- return model.basePlanSystemMessage ?? DEFAULT_PLAN_SYSTEM_MESSAGE;
+ baseMessage = model.basePlanSystemMessage ?? DEFAULT_PLAN_SYSTEM_MESSAGE;
} else {
- return model.baseChatSystemMessage ?? DEFAULT_CHAT_SYSTEM_MESSAGE;
+ baseMessage = model.baseChatSystemMessage ?? DEFAULT_CHAT_SYSTEM_MESSAGE;
}
+
+ // Add no-tools warning for agent/plan modes when no tools are available
+ if (messageMode !== "chat" && (!activeTools || activeTools.length === 0)) {
+ baseMessage += NO_TOOL_WARNING;
+ }
+
+ return baseMessage;
}
diff --git a/packages/config-yaml/src/__tests__/index.test.ts b/packages/config-yaml/src/__tests__/index.test.ts
index af11cf0c4..5e0a3cdb9 100644
--- a/packages/config-yaml/src/__tests__/index.test.ts
+++ b/packages/config-yaml/src/__tests__/index.test.ts
@@ -93,9 +93,11 @@ describe("E2E Scenarios", () => {
const registry: Registry = {
getContent: async function (id: PackageIdentifier): Promise {
const slug = packageIdentifierToShorthandSlug(id);
- return fs
- .readFileSync(`./src/__tests__/packages/${slug}.yaml`)
- .toString();
+ const filePath =
+ id.uriType === "slug"
+ ? `./src/__tests__/packages/${slug}.yaml`
+ : id.filePath;
+ return fs.readFileSync(filePath).toString();
},
};
@@ -230,7 +232,7 @@ describe("E2E Scenarios", () => {
orgScopeId: "test-org",
currentUserSlug: "test-user",
onPremProxyUrl: null,
- // Add an injected block
+ // Add injected blocks
injectBlocks: [
{
uriType: "slug",
@@ -240,11 +242,16 @@ describe("E2E Scenarios", () => {
versionSlug: "latest",
},
},
+ {
+ uriType: "file",
+ filePath: "./src/__tests__/local-files/rules.yaml",
+ },
],
},
);
const config = unrolledConfig.config;
+ const errors = unrolledConfig.errors;
// The original rules array should have two items
expect(config?.rules?.length).toBe(3); // Now 3 with the injected block
@@ -255,7 +262,72 @@ describe("E2E Scenarios", () => {
);
// Check the injected doc block was added
- expect(config?.rules?.[2]).toBe("Be kind");
+ expect(
+ typeof config?.rules?.[2] !== "string" &&
+ config?.rules?.[2]?.rule === "Be humble",
+ );
+
+ // Check if we receive one error that is caused by duplicate rules
+ expect(errors?.length).toBe(1);
+ expect(errors?.[0].message.includes("Duplicate rules detected"));
+ });
+
+ it("duplicate detection should happen in the assistant config first and then the intected blocks", async () => {
+ const unrolledConfig = await unrollAssistant(
+ {
+ uriType: "file",
+ filePath: "./src/__tests__/local-files/duplicate-test-assistant.yaml",
+ },
+ registry,
+ {
+ renderSecrets: true,
+ platformClient,
+ orgScopeId: "test-org",
+ currentUserSlug: "test-user",
+ onPremProxyUrl: null,
+ // Add injected blocks
+ injectBlocks: [
+ {
+ uriType: "file",
+ filePath: "./src/__tests__/local-files/rules.yaml",
+ },
+ {
+ uriType: "file",
+ filePath: "./src/__tests__/local-files/mcpServer.yaml",
+ },
+ {
+ uriType: "file",
+ filePath: "./src/__tests__/local-files/prompt.yaml",
+ },
+ ],
+ },
+ );
+
+ const config = unrolledConfig.config;
+ const errors = unrolledConfig.errors;
+
+ // Check if all the duplicate blocks get removed
+ expect(config?.models?.length).toBe(1);
+ expect(config?.context?.length).toBe(1);
+ expect(config?.mcpServers?.length).toBe(1);
+ expect(config?.rules?.length).toBe(1);
+ expect(config?.prompts?.length).toBe(1);
+ expect(config?.docs?.length).toBe(1);
+
+ // Check if there are 8 duplication detected
+ expect(errors?.length).toBe(8);
+
+ // Beginning of the assistant config duplication check
+ expect(
+ errors?.[0].message.includes("Duplicate models named gpt-5 detected"),
+ ).toBe(true);
+ // Beginning of the injected blocks duplication check
+ expect(errors?.[4].message.includes("Duplicate rules detected")).toBe(true);
+ expect(
+ errors?.[6].message.includes(
+ "Duplicate mcpServers named Browser search detected",
+ ),
+ ).toBe(true);
});
it.skip("should prioritize org over user / package secrets", () => {});
diff --git a/packages/config-yaml/src/__tests__/local-files/duplicate-test-assistant.yaml b/packages/config-yaml/src/__tests__/local-files/duplicate-test-assistant.yaml
new file mode 100644
index 000000000..7f5eca13a
--- /dev/null
+++ b/packages/config-yaml/src/__tests__/local-files/duplicate-test-assistant.yaml
@@ -0,0 +1,39 @@
+name: Duplicate Test Assistant
+version: 0.0.1
+schema: v1
+
+docs:
+ - name: React
+ startUrl: https://react.dev
+ - name: React
+ startUrl: https://react.dev
+
+rules:
+ - Be humble
+ - uses: ./src/__tests__/local-files/rules.yaml
+
+models:
+ - name: gpt-5
+ provider: openai
+ model: gpt-5
+ apiKey: ${{ secrets.OPENAI_API_KEY }}
+ roles:
+ - chat
+
+ - name: gpt-5
+ provider: openai
+ model: gpt-5
+ apiKey: ${{ secrets.OPENAI_API_KEY }}
+ roles:
+ - chat
+
+mcpServers:
+ - uses: ./src/__tests__/local-files/mcpServer.yaml
+
+prompts:
+ - uses: ./src/__tests__/local-files/prompt.yaml
+ - uses: ./src/__tests__/local-files/prompt.yaml
+
+context:
+ - provider: doc
+ - provider: doc
diff --git a/packages/config-yaml/src/__tests__/local-files/mcpServer.yaml b/packages/config-yaml/src/__tests__/local-files/mcpServer.yaml
new file mode 100644
index 000000000..b6be73016
--- /dev/null
+++ b/packages/config-yaml/src/__tests__/local-files/mcpServer.yaml
@@ -0,0 +1,8 @@
+name: Local MCP Server
+version: 0.0.1
+schema: v1
+mcpServers:
+ - name: Browser search
+ command: npx
+ args:
+ - "@playwright/mcp@latest"
diff --git a/packages/config-yaml/src/__tests__/local-files/prompt.yaml b/packages/config-yaml/src/__tests__/local-files/prompt.yaml
new file mode 100644
index 000000000..7ea2c2707
--- /dev/null
+++ b/packages/config-yaml/src/__tests__/local-files/prompt.yaml
@@ -0,0 +1,7 @@
+name: Local prompt
+version: 0.0.1
+schema: v1
+prompts:
+ - name: duplication test
+ description: test purpose
+ prompt: Please check that this prompt should only appear once
diff --git a/packages/config-yaml/src/__tests__/local-files/rules.yaml b/packages/config-yaml/src/__tests__/local-files/rules.yaml
new file mode 100644
index 000000000..6bfca2423
--- /dev/null
+++ b/packages/config-yaml/src/__tests__/local-files/rules.yaml
@@ -0,0 +1,6 @@
+name: Rules
+version: 0.0.1
+schema: v1
+
+rules:
+ - Be humble
diff --git a/packages/config-yaml/src/load/blockDuplicationDetector.ts b/packages/config-yaml/src/load/blockDuplicationDetector.ts
new file mode 100644
index 000000000..78e5ce980
--- /dev/null
+++ b/packages/config-yaml/src/load/blockDuplicationDetector.ts
@@ -0,0 +1,76 @@
+import { BLOCK_TYPES, BlockType } from "./getBlockType.js";
+
+export class BlockDuplicationDetector {
+ private records: Map>;
+
+ constructor() {
+ this.records = new Map();
+ for (const blockType of BLOCK_TYPES) {
+ this.records.set(blockType, new Set());
+ }
+ }
+
+ private isRuleDuplicated(rule: any): boolean {
+ if (typeof rule === "string") {
+ return this.check(rule, "rules");
+ } else {
+ return this.check(rule.name, "rules");
+ }
+ }
+
+ private isContextDuplicated(context: any): boolean {
+ return this.check(context.provider, "context");
+ }
+
+ private isCommonBlockDuplicated(block: any, blockType: BlockType): boolean {
+ return this.check(block.name, blockType);
+ }
+
+ private check(identifier: string, blockType: BlockType): boolean {
+ if (this.records.get(blockType)!.has(identifier)) {
+ return true;
+ } else {
+ this.records.get(blockType)!.add(identifier);
+ return false;
+ }
+ }
+
+ // Check if the name is duplicated within the same blockType
+ isDuplicated(
+ block: any,
+ blockType: BlockType,
+ injectError?: (errorMsg: string) => void,
+ ): boolean {
+ // Not checking any null or undefined object
+ if (block === null || block === undefined) {
+ return false;
+ }
+
+ switch (blockType) {
+ case "rules":
+ if (this.isRuleDuplicated(block)) {
+ injectError?.(
+ `Duplicate rules${typeof block === "string" ? "" : ` named ${block.name}`} detected. The duplicate one has been deleted for preventing unexpected behavior.`,
+ );
+ return true;
+ }
+ return false;
+ case "context":
+ if (this.isContextDuplicated(block)) {
+ injectError?.(
+ `Duplicate ${block.provider} context providers detected. The duplicate one has been deleted for preventing unexpected behavior.`,
+ );
+ return true;
+ }
+ return false;
+ default:
+ if (this.isCommonBlockDuplicated(block, blockType)) {
+ injectError?.(
+ `Duplicate ${blockType} named ${block.name} detected. The duplicate one has been deleted for preventing unexpected behavior.`,
+ );
+ return true;
+ }
+ return false;
+ }
+ }
+}
diff --git a/packages/config-yaml/src/load/unroll.ts b/packages/config-yaml/src/load/unroll.ts
index adbe45324..5225f79aa 100644
--- a/packages/config-yaml/src/load/unroll.ts
+++ b/packages/config-yaml/src/load/unroll.ts
@@ -20,6 +20,7 @@ import {
Rule,
} from "../schemas/index.js";
import { ConfigResult, ConfigValidationError } from "../validation.js";
+import { BlockDuplicationDetector } from "./blockDuplicationDetector.js";
import {
packageIdentifierToShorthandSlug,
useProxyForUnrenderedSecrets,
@@ -306,6 +307,13 @@ export async function unrollBlocks(
): Promise> {
const errors: ConfigValidationError[] = [];
+ function injectDuplicationError(errorMsg: string) {
+ errors.push({
+ fatal: false,
+ message: errorMsg,
+ });
+ }
+
const unrolledAssistant: AssistantUnrolled = {
name: assistant.name,
version: assistant.version,
@@ -484,7 +492,7 @@ export async function unrollBlocks(
const injectedResults = await Promise.all(injectedBlockPromises);
const injectedErrors: ConfigValidationError[] = [];
const injectedBlocks: {
- blockType: string;
+ blockType: BlockType;
resolvedBlock: any;
source?: string;
}[] = [];
@@ -521,16 +529,27 @@ export async function unrollBlocks(
errors.push(...rulesResult.errors);
errors.push(...injectedResult.errors);
+ const detector = new BlockDuplicationDetector();
+
// Assign section results
for (const sectionResult of sectionResults) {
if (sectionResult.blocks) {
- unrolledAssistant[sectionResult.section] = sectionResult.blocks;
+ unrolledAssistant[sectionResult.section] = sectionResult.blocks.filter(
+ (block) =>
+ !detector.isDuplicated(
+ block,
+ sectionResult.section,
+ injectDuplicationError,
+ ),
+ );
}
}
// Assign rules result
if (rulesResult.rules) {
- unrolledAssistant.rules = rulesResult.rules;
+ unrolledAssistant.rules = rulesResult.rules.filter(
+ (rule) => !detector.isDuplicated(rule, "rules", injectDuplicationError),
+ );
}
// Add injected blocks
@@ -539,16 +558,20 @@ export async function unrollBlocks(
resolvedBlock,
source,
} of injectedResult.injectedBlocks) {
- const key = blockType as BlockType;
+ const key = blockType;
if (!unrolledAssistant[key]) {
unrolledAssistant[key] = [];
}
- const blocksWithSourceFiles = injectLocalSourceFile(
+
+ const filteredBlocks = injectLocalSourceFile(
key,
resolvedBlock,
source,
+ ).filter(
+ (block: any) =>
+ !detector.isDuplicated(block, blockType, injectDuplicationError),
);
- unrolledAssistant[key]?.push(...blocksWithSourceFiles);
+ unrolledAssistant[key]?.push(...filteredBlocks);
}
const configResult: ConfigResult = {
diff --git a/packages/config-yaml/src/schemas/models.ts b/packages/config-yaml/src/schemas/models.ts
index 283ec6781..0693675a2 100644
--- a/packages/config-yaml/src/schemas/models.ts
+++ b/packages/config-yaml/src/schemas/models.ts
@@ -36,6 +36,7 @@ export type ModelRole = z.infer;
export const modelCapabilitySchema = z.union([
z.literal("tool_use"),
z.literal("image_input"),
+ z.literal("next_edit"),
]);
export type ModelCapability = z.infer;
diff --git a/packages/llm-info/src/providers/openai.ts b/packages/llm-info/src/providers/openai.ts
index a15dd3089..820559308 100644
--- a/packages/llm-info/src/providers/openai.ts
+++ b/packages/llm-info/src/providers/openai.ts
@@ -75,6 +75,15 @@ export const OpenAi: ModelProvider = {
contextLength: 128000,
maxCompletionTokens: 4096,
},
+ // gpt-5
+ {
+ model: "gpt-5",
+ displayName: "GPT-5",
+ contextLength: 400000,
+ maxCompletionTokens: 128000,
+ regex: /gpt-5/,
+ recommendedFor: ["chat"],
+ },
// gpt-4o
{
model: "gpt-4o",
diff --git a/packages/openai-adapters/src/apis/OpenAI.ts b/packages/openai-adapters/src/apis/OpenAI.ts
index c1e356fa5..714ce67fd 100644
--- a/packages/openai-adapters/src/apis/OpenAI.ts
+++ b/packages/openai-adapters/src/apis/OpenAI.ts
@@ -38,7 +38,7 @@ export class OpenAIApi implements BaseLlmApi {
// o-series models - only apply for official OpenAI API
const isOfficialOpenAIAPI = this.apiBase === "https://api.openai.com/v1/";
if (isOfficialOpenAIAPI) {
- if (body.model.startsWith("o")) {
+ if (body.model.startsWith("o") || body.model.includes("gpt-5")) {
// a) use max_completion_tokens instead of max_tokens
body.max_completion_tokens = body.max_tokens;
body.max_tokens = undefined;