better permissions ux when denying (#1747)
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
|||||||
type LanguageModelUsage,
|
type LanguageModelUsage,
|
||||||
type ProviderMetadata,
|
type ProviderMetadata,
|
||||||
type ModelMessage,
|
type ModelMessage,
|
||||||
stepCountIs,
|
|
||||||
type StreamTextResult,
|
type StreamTextResult,
|
||||||
} from "ai"
|
} from "ai"
|
||||||
|
|
||||||
@@ -41,6 +40,7 @@ import { mergeDeep, pipe, splitWhen } from "remeda"
|
|||||||
import { ToolRegistry } from "../tool/registry"
|
import { ToolRegistry } from "../tool/registry"
|
||||||
import { Plugin } from "../plugin"
|
import { Plugin } from "../plugin"
|
||||||
import { Agent } from "../agent/agent"
|
import { Agent } from "../agent/agent"
|
||||||
|
import { Permission } from "../permission"
|
||||||
|
|
||||||
export namespace Session {
|
export namespace Session {
|
||||||
const log = Log.create({ service: "session" })
|
const log = Log.create({ service: "session" })
|
||||||
@@ -932,7 +932,18 @@ export namespace Session {
|
|||||||
activeTools: Object.keys(tools).filter((x) => x !== "invalid"),
|
activeTools: Object.keys(tools).filter((x) => x !== "invalid"),
|
||||||
maxOutputTokens: outputLimit,
|
maxOutputTokens: outputLimit,
|
||||||
abortSignal: abort.signal,
|
abortSignal: abort.signal,
|
||||||
stopWhen: stepCountIs(1000),
|
stopWhen: async ({ steps }) => {
|
||||||
|
if (steps.length >= 1000) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if processor flagged that we should stop
|
||||||
|
if (processor.getShouldStop()) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
},
|
||||||
providerOptions: {
|
providerOptions: {
|
||||||
[input.providerID]: {
|
[input.providerID]: {
|
||||||
...ProviderTransform.options(input.providerID, input.modelID),
|
...ProviderTransform.options(input.providerID, input.modelID),
|
||||||
@@ -983,10 +994,14 @@ export namespace Session {
|
|||||||
function createProcessor(assistantMsg: MessageV2.Assistant, model: ModelsDev.Model) {
|
function createProcessor(assistantMsg: MessageV2.Assistant, model: ModelsDev.Model) {
|
||||||
const toolcalls: Record<string, MessageV2.ToolPart> = {}
|
const toolcalls: Record<string, MessageV2.ToolPart> = {}
|
||||||
let snapshot: string | undefined
|
let snapshot: string | undefined
|
||||||
|
let shouldStop = false
|
||||||
return {
|
return {
|
||||||
partFromToolCall(toolCallID: string) {
|
partFromToolCall(toolCallID: string) {
|
||||||
return toolcalls[toolCallID]
|
return toolcalls[toolCallID]
|
||||||
},
|
},
|
||||||
|
getShouldStop() {
|
||||||
|
return shouldStop
|
||||||
|
},
|
||||||
async process(stream: StreamTextResult<Record<string, AITool>, never>) {
|
async process(stream: StreamTextResult<Record<string, AITool>, never>) {
|
||||||
try {
|
try {
|
||||||
let currentText: MessageV2.TextPart | undefined
|
let currentText: MessageV2.TextPart | undefined
|
||||||
@@ -1063,6 +1078,9 @@ export namespace Session {
|
|||||||
case "tool-error": {
|
case "tool-error": {
|
||||||
const match = toolcalls[value.toolCallId]
|
const match = toolcalls[value.toolCallId]
|
||||||
if (match && match.state.status === "running") {
|
if (match && match.state.status === "running") {
|
||||||
|
if (value.error instanceof Permission.RejectedError) {
|
||||||
|
shouldStop = true
|
||||||
|
}
|
||||||
await updatePart({
|
await updatePart({
|
||||||
...match,
|
...match,
|
||||||
state: {
|
state: {
|
||||||
@@ -1079,7 +1097,6 @@ export namespace Session {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case "error":
|
case "error":
|
||||||
throw value.error
|
throw value.error
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user