mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 18:24:21 +01:00
support agent options
This commit is contained in:
@@ -14,6 +14,7 @@ export namespace Agent {
|
|||||||
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]),
|
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]),
|
||||||
topP: z.number().optional(),
|
topP: z.number().optional(),
|
||||||
temperature: z.number().optional(),
|
temperature: z.number().optional(),
|
||||||
|
options: z.record(z.any()),
|
||||||
model: z
|
model: z
|
||||||
.object({
|
.object({
|
||||||
modelID: z.string(),
|
modelID: z.string(),
|
||||||
@@ -39,15 +40,18 @@ export namespace Agent {
|
|||||||
todoread: false,
|
todoread: false,
|
||||||
todowrite: false,
|
todowrite: false,
|
||||||
},
|
},
|
||||||
|
options: {},
|
||||||
mode: "subagent",
|
mode: "subagent",
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
name: "build",
|
name: "build",
|
||||||
tools: {},
|
tools: {},
|
||||||
|
options: {},
|
||||||
mode: "primary",
|
mode: "primary",
|
||||||
},
|
},
|
||||||
plan: {
|
plan: {
|
||||||
name: "plan",
|
name: "plan",
|
||||||
|
options: {},
|
||||||
tools: {
|
tools: {
|
||||||
write: false,
|
write: false,
|
||||||
edit: false,
|
edit: false,
|
||||||
@@ -66,6 +70,7 @@ export namespace Agent {
|
|||||||
item = result[key] = {
|
item = result[key] = {
|
||||||
name: key,
|
name: key,
|
||||||
mode: "all",
|
mode: "all",
|
||||||
|
options: {},
|
||||||
tools: {},
|
tools: {},
|
||||||
}
|
}
|
||||||
if (value.model) item.model = Provider.parseModel(value.model)
|
if (value.model) item.model = Provider.parseModel(value.model)
|
||||||
@@ -79,6 +84,11 @@ export namespace Agent {
|
|||||||
if (value.temperature != undefined) item.temperature = value.temperature
|
if (value.temperature != undefined) item.temperature = value.temperature
|
||||||
if (value.top_p != undefined) item.topP = value.top_p
|
if (value.top_p != undefined) item.topP = value.top_p
|
||||||
if (value.mode) item.mode = value.mode
|
if (value.mode) item.mode = value.mode
|
||||||
|
if (value.options)
|
||||||
|
item.options = {
|
||||||
|
...item.options,
|
||||||
|
...value.options,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ export namespace Config {
|
|||||||
tools: z.record(z.string(), z.boolean()).optional(),
|
tools: z.record(z.string(), z.boolean()).optional(),
|
||||||
disable: z.boolean().optional(),
|
disable: z.boolean().optional(),
|
||||||
description: z.string().optional().describe("Description of when to use the agent"),
|
description: z.string().optional().describe("Description of when to use the agent"),
|
||||||
|
options: z.record(z.string(), z.any()).optional().describe("Additional model options passed through to provider"),
|
||||||
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]).optional(),
|
mode: z.union([z.literal("subagent"), z.literal("primary"), z.literal("all")]).optional(),
|
||||||
})
|
})
|
||||||
.openapi({
|
.openapi({
|
||||||
|
|||||||
@@ -852,20 +852,24 @@ export namespace Session {
|
|||||||
tools[key] = item
|
tools[key] = item
|
||||||
}
|
}
|
||||||
|
|
||||||
const params = {
|
const params = await Plugin.trigger(
|
||||||
temperature: model.info.temperature
|
|
||||||
? (agent.temperature ?? ProviderTransform.temperature(input.providerID, input.modelID))
|
|
||||||
: undefined,
|
|
||||||
topP: agent.topP ?? ProviderTransform.topP(input.providerID, input.modelID),
|
|
||||||
}
|
|
||||||
await Plugin.trigger(
|
|
||||||
"chat.params",
|
"chat.params",
|
||||||
{
|
{
|
||||||
model: model.info,
|
model: model.info,
|
||||||
provider: await Provider.getProvider(input.providerID),
|
provider: await Provider.getProvider(input.providerID),
|
||||||
message: userMsg,
|
message: userMsg,
|
||||||
},
|
},
|
||||||
params,
|
{
|
||||||
|
temperature: model.info.temperature
|
||||||
|
? (agent.temperature ?? ProviderTransform.temperature(input.providerID, input.modelID))
|
||||||
|
: undefined,
|
||||||
|
topP: agent.topP ?? ProviderTransform.topP(input.providerID, input.modelID),
|
||||||
|
options: {
|
||||||
|
...ProviderTransform.options(input.providerID, input.modelID),
|
||||||
|
...model.info.options,
|
||||||
|
...agent.options,
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
const stream = streamText({
|
const stream = streamText({
|
||||||
onError(e) {
|
onError(e) {
|
||||||
@@ -946,10 +950,7 @@ export namespace Session {
|
|||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
providerOptions: {
|
providerOptions: {
|
||||||
[input.providerID]: {
|
[input.providerID]: params.options,
|
||||||
...ProviderTransform.options(input.providerID, input.modelID),
|
|
||||||
...model.info.options,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
temperature: params.temperature,
|
temperature: params.temperature,
|
||||||
topP: params.topP,
|
topP: params.topP,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export interface Hooks {
|
|||||||
*/
|
*/
|
||||||
"chat.params"?: (
|
"chat.params"?: (
|
||||||
input: { model: Model; provider: Provider; message: UserMessage },
|
input: { model: Model; provider: Provider; message: UserMessage },
|
||||||
output: { temperature: number; topP: number },
|
output: { temperature: number; topP: number; options: Record<string, any> },
|
||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
"permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
|
"permission.ask"?: (input: Permission, output: { status: "ask" | "deny" | "allow" }) => Promise<void>
|
||||||
"tool.execute.before"?: (
|
"tool.execute.before"?: (
|
||||||
|
|||||||
Reference in New Issue
Block a user