Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
'List all configured scheduled automations and their stable IDs, editable fields, targets, and timing metadata. Use this before configureAutomation, runAutomation, or deleteAutomation when acting on an existing automation. This tool never changes automation state.'
,
:
.
,
:
,
:
false
,
:
{
:
'object'
,
:
{
}
,
:
false
,
}
,
}
;
}
async
prepareToolInvocation
(
:
,
:
)
:
Promise
<
>
{
return
{
:
localize
(
'automation.tool.list.invocationMessage'
,
"Reading automations"
)
,
:
localize
(
'automation.tool.list.pastTenseMessage'
,
"Read automations"
)
,
}
;
}
async
invoke
(
:
,
:
,
:
,
:
)
:
Promise
<
>
{
if
(
!
isAutomationsEnabled
(
this
.
)
)
{
return
automationToolError
(
'Automations are disabled.'
)
;
}
const
=
this
.
.
.
get
(
)
.
map
(
)
;
const
=
automationToolResult
(
JSON
.
stringify
(
{
}
,
undefined
,
2
)
)
;
.
=
.
===
1
?
localize
(
'automation.tool.list.result.singular'
,
"Listed 1 automation"
)
:
localize
(
'automation.tool.list.result.plural'
,
"Listed {0} automations"
,
.
)
;
return
;
}
}
export
class
RunAutomationTool
implements
IToolImpl
{
constructor
(
@IAutomationService
private
readonly
:
,
@IAutomationRunner
private
readonly
:
,
@IConfigurationService
private
readonly
:
,
)
{
}
getToolData
(
)
:
{
return
{
:
,
:
'runAutomation'
,
:
false
,
:
.
,
:
localize
(
'automation.tool.run.displayName'
,
"Run Automation"
)
,
:
localize
(
'automation.tool.run.userDescription'
,
"Run a configured agent automation now"
)
,
:
'Run a configured automation immediately by stable ID. Call listAutomations first to obtain the current ID. This starts a fresh agent session in the background using the saved prompt, target, model, mode, and permission level, even when scheduled runs are disabled. The tool returns after session dispatch commits; do not run it again unless the user asks.'
,
:
.
,
:
,
:
false
,
:
{
:
'object'
,
:
false
,
:
{
:
{
:
'string'
,
:
'Stable automation ID from listAutomations.'
,
}
,
}
,
:
[
'automationId'
]
,
}
,
}
;
}
async
prepareToolInvocation
(
:
,
:
)
:
Promise
<
>
{
if
(
!
isAutomationsEnabled
(
this
.
)
)
{
throw
new
AutomationToolInputError
(
'Automations are disabled.'
)
;
}
const
=
resolveAutomationInput
(
this
.
,
.
,
'runAutomation'
)
;
const
=
this
.
.
getActiveRunFor
(
.
)
;
if
(
)
{
return
{
:
localize
(
'automation.tool.run.alreadyRunning'
,
"Automation {0} is already running"
,
.
)
,
:
localize
(
'automation.tool.run.wasAlreadyRunning'
,
"Automation {0} was already running"
,
.
)
,
}
;
}
return
{
:
localize
(
'automation.tool.run.invocationMessage'
,
"Running automation {0}"
,
.
)
,
:
localize
(
'automation.tool.run.pastTenseMessage'
,
"Started automation {0}"
,
.
)
,
:
{
:
localize
(
'automation.tool.run.confirmationTitle'
,
"Run Automation?"
)
,
:
new
MarkdownString
(
localize
(
'automation.tool.run.confirmationMessage'
,
"Run **{0}** (`{1}`) now? This starts a new agent session using the automation's configured prompt and permissions."
,
.
,
.
,
)
)
,
}
,
}
;
}
async
invoke
(
:
,
:
,
:
,
:
)
:
Promise
<
>
{
if
(
!
isAutomationsEnabled
(
this
.
)
)
{
return
automationToolError
(
'Automations are disabled.'
)
;
}
if
(
.
)
{
return
automationRunCancelled
(
)
;
}
let
:
;
try
{
=
resolveAutomationInput
(
this
.
,
.
,
'runAutomation'
)
;
}
catch
(
)
{
if
(
instanceof
AutomationToolInputError
)
{
return
automationToolError
(
.
)
;
}
throw
;
}
const
=
new
CancellationTokenSource
(
)
;
const
=
this
.
.
runOnce
(
,
'manual'
,
,
.
)
;
let
:
;
try
{
=
await
.
;
}
finally
{
.
dispose
(
)
;
}
if
(
.
===
'alreadyRunning'
)
{
return
automationAlreadyRunning
(
,
.
)
;
}
if
(
.
===
'notStarted'
)
{
return
automationNotStarted
(
,
)
;
}
const
=
automationToolResult
(
JSON
.
stringify
(
{
:
'started'
,
:
{
:
.
,
:
.
}
,
:
{
:
.
.
,
:
.
.
,
:
.
.
toString
(
)
,
}
,
}
,
undefined
,
2
)
)
;
.
=
localize
(
'automation.tool.run.started'
,
"Started automation {0}"
,
.
)
;
return
;
}
}
export
class
DeleteAutomationTool
implements
IToolImpl
{
constructor
(
@IAutomationService
private
readonly
:
,
@IConfigurationService
private
readonly
:
,
)
{
}
getToolData
(
)
:
{
return
{
:
,
:
'deleteAutomation'
,
:
false
,
:
.
,
:
localize
(
'automation.tool.delete.displayName'
,
"Delete Automation"
)
,
:
localize
(
'automation.tool.delete.userDescription'
,
"Delete a scheduled agent automation"
)
,
:
'Delete an automation by stable ID. Call listAutomations first to obtain the current ID. The current approval policy may approve the action automatically; otherwise the user is shown a Delete/Cancel confirmation.'
,
:
.
,
:
,
:
false
,
:
{
:
'object'
,
:
false
,
:
{
:
{
:
'string'
,
:
'Stable automation ID from listAutomations.'
,
}
,
}
,
:
[
'automationId'
]
,
}
,
}
;
}
async
prepareToolInvocation
(
:
,
:
)
:
Promise
<
>
{
if
(
!
isAutomationsEnabled
(
this
.
)
)
{
throw
new
AutomationToolInputError
(
'Automations are disabled.'
)
;
}
const
=
resolveAutomationInput
(
this
.
,
.
,
'deleteAutomation'
)
;
return
{
:
localize
(
'automation.tool.delete.invocationMessage'
,
"Deleting automation {0}"
,
.
)
,
:
localize
(
'automation.tool.delete.pastTenseMessage'
,
"Deleted automation {0}"
,
.
)
,
:
{
:
localize
(
'automation.tool.delete.confirmationTitle'
,
"Delete Automation?"
)
,
:
new
MarkdownString
(
localize
(
'automation.tool.delete.confirmationMessage'
,
"Delete **{0}** (`{1}`)? Its saved configuration and run history will be permanently removed. Runs already in flight will continue."
,
.
,
.
,
)
)
,
:
[
{
:
,
:
localize
(
'automation.tool.delete.confirm'
,
"Delete"
)
,
:
.
}
,
{
:
'cancel'
,
:
localize
(
'automation.tool.delete.cancel'
,
"Cancel"
)
,
:
.
}
,
]
,
}
,
}
;
}
async
invoke
(
:
,
:
,
:
,
:
)
:
Promise
<
>
{
if
(
!
isAutomationsEnabled
(
this
.
)
)
{
return
automationToolError
(
'Automations are disabled.'
)
;
}
if
(
.
)
{
return
automationDeleteCancelled
(
)
;
}
let
:
;
try
{
=
resolveAutomationInput
(
this
.
,
.
,
'deleteAutomation'
)
;
}
catch
(
)
{
if
(
instanceof
AutomationToolInputError
)
{
return
automationToolError
(
.
)
;
}
throw
;
}
if
(
.
!==
undefined
&&
.
!==
)
{
return
automationDeleteCancelled
(
)
;
}
try
{
await
this
.
.
deleteAutomation
(
.
,
this
.
createMutationGuard
(
)
)
;
}
catch
(
)
{
if
(
instanceof
AutomationToolMutationBlockedError
)
{
return
.
;
}
throw
;
}
const
=
automationToolResult
(
JSON
.
stringify
(
{
:
'deleted'
,
:
{
:
.
,
:
.
}
,
}
)
)
;
.
=
localize
(
'automation.tool.delete.deleted'
,
"Deleted automation {0}"
,
.
)
;
return
;
}
private
createMutationGuard
(
:
)
:
{
return
(
)
=>
{
if
(
!
isAutomationsEnabled
(
this
.
)
)
{
throw
new
AutomationToolMutationBlockedError
(
automationToolError
(
'Automations are disabled.'
)
)
;
}
if
(
.
)
{
throw
new
AutomationToolMutationBlockedError
(
automationDeleteCancelled
(
)
)
;
}
}
;
}
}
export
class
ConfigureAutomationTool
implements
IToolImpl
{
constructor
(
@IAutomationService
private
readonly
:
,
@ISessionsManagementService
private
readonly
:
,
@IConfigurationService
private
readonly
:
,
)
{
}
getToolData
(
)
:
{
return
{
:
,
:
,
:
false
,
:
.
,
:
localize
(
'automation.tool.configure.displayName'
,
"Configure Automation"
)
,
:
localize
(
'automation.tool.configure.userDescription'
,
"Create or update an automation"
)
,
:
`Create or update a persistent scheduled automation.
Create a new automation only when the user explicitly asks for an automation, or for a prompt to run on a recurring schedule. Do not infer that intent from requests merely to monitor, watch, follow, or keep something (such as a pull request) green.
Omit "automationId" to create an automation; "name", "prompt", and "schedule.interval" are then required. If "target" is omitted, the automation targets the current Agents window session. Include "automationId" to update an existing automation, and only provide fields that should change. Call listAutomations first to obtain the stable ID and current values.
The change uses the current tool-approval policy. When approval is required, the user sees a normal tool confirmation. If the user cancels or denies the request, do not retry unless they ask you to.`
,
:
.
,
:
,
:
false
,
:
{
:
'object'
,
:
false
,
:
{
:
{
:
'string'
,
:
'Stable automation ID from listAutomations. Omit to create a new automation.'
,
}
,
:
{
:
'string'
,
:
'Automation name. Required when creating.'
,
}
,
:
{
:
'string'
,
:
'Prompt sent when the automation runs. Required when creating.'
,
}
,
:
{
:
'object'
,
:
false
,
:
'Schedule proposal. Required when creating. Omitted fields preserve existing values when updating; create defaults are 09:00 Monday.'
,
:
{
:
{
:
'string'
,
enum
:
[
...
]
,
:
'manual, hourly, daily, or weekly.'
,
}
,
:
{
:
'integer'
,
:
0
,
:
23
,
:
'Local hour, used for daily and weekly schedules.'
,
}
,
:
{
:
'integer'
,
:
0
,
:
59
,
:
'Local minute, used for daily and weekly schedules.'
,
}
,
:
{
:
'integer'
,
:
0
,
:
6
,
:
'Day of week for weekly schedules: 0 is Sunday and 6 is Saturday.'
,
}
,
}
,
}
,
:
{
:
'object'
,
:
false
,
:
'Run target. Omit when creating to use the current session, or omit when updating to preserve the existing target.'
,
:
{
:
{
:
'string'
,
enum
:
[
'currentSession'
,
'workspace'
,
'quickChat'
]
,
}
,
:
{
:
'string'
,
:
'Full workspace URI for a workspace target.'
,
}
,
:
{
:
'string'
,
:
'Sessions provider ID.'
,
}
,
:
{
:
'string'
,
:
'Sessions provider session-type ID.'
,
}
,
:
{
:
'string'
,
enum
:
[
...
]
,
:
'Workspace isolation: default, folder, or worktree.'
,
}
,
:
{
:
'string'
,
:
'Base branch, required for worktree isolation.'
,
}
,
}
,
:
[
'kind'
]
,
}
,
:
{
:
[
'string'
,
'null'
]
,
:
'Language model ID, or null to use the provider default.'
,
}
,
:
{
enum
:
[
...
,
null
]
,
:
'Chat mode, or null to use the provider default.'
,
}
,
:
{
enum
:
[
...
,
null
]
,
:
'Permission level, or null to use the provider default.'
,
}
,
:
{
:
'boolean'
,
:
'Whether scheduled runs are enabled. Defaults to true when creating.'
`Automation "${proposal.existing.id}" changed before the update was applied. Call listAutomations to refresh it before proposing new changes. No changes were made.`
)
;
}
return
await
this
.
applyUpdate
(
.
,
,
)
;
}
catch
(
)
{
if
(
instanceof
AutomationToolMutationBlockedError
)
{
return
.
;
}
if
(
instanceof
AutomationToolInputError
)
{
return
automationToolError
(
.
)
;
}
throw
;
}
}
private
async
applyCreate
(
:
,
:
)
:
Promise
<
>
{
const
=
this
.
getMutationBlockedResult
(
)
;
if
(
)
{
return
;
}
const
=
await
this
.
.
createAutomation
(
,
this
.
createMutationGuard
(
)
)
;
const
=
automationToolResult
(
JSON
.
stringify
(
{
:
'created'
,
:
toAutomationToolOutput
(
)
}
,
undefined
,
2
)
)
;
.
=
toAutomationConfiguredData
(
,
'created'
)
;
.
=
localize
(
'automation.tool.configure.created'
,
"Created automation {0}"
,
.
)
;
return
;
}
private
async
applyUpdate
(
:
,
:
,
:
)
:
Promise
<
>
{
const
=
this
.
getMutationBlockedResult
(
)
;
if
(
)
{
return
;
}
const
=
await
this
.
.
updateAutomationIfUnchanged
(
.
,
,
,
this
.
createMutationGuard
(
)
)
;
if
(
.
===
'conflict'
&&
!
.
)
{
return
automationToolError
(
`Automation "${existing.id}" was deleted before the update was applied. No changes were made.`
)
;
}
if
(
.
===
'conflict'
)
{
return
automationToolError
(
`Automation "${existing.id}" changed before the update was applied. Call listAutomations to refresh it before proposing new changes. No changes were made.`
)
;
}
const
=
.
;
const
=
automationToolResult
(
JSON
.
stringify
(
{
:
'updated'
,
:
toAutomationToolOutput
(
)
}
,
undefined
,
2
)
)
;
.
=
toAutomationConfiguredData
(
,
'updated'
)
;
.
=
localize
(
'automation.tool.configure.updated'
,
"Updated automation {0}"
,
.
)
;
return
;
}
private
createMutationGuard
(
:
)
:
{
return
(
)
=>
{
const
=
this
.
getMutationBlockedResult
(
)
;
if
(
)
{
throw
new
AutomationToolMutationBlockedError
(
)
;
}
}
;
}
private
getMutationBlockedResult
(
:
)
:
|
undefined
{
if
(
!
isAutomationsEnabled
(
this
.
)
)
{
return
automationToolError
(
'Automations are disabled.'
)
;
}
if
(
.
)
{
return
automationToolCancelled
(
)
;
}
return
undefined
;
}
private
resolveAvailableTarget
(
:
)
:
{
const
=
.
===
'quickChat'
?
this
.
.
getQuickChatSessionTypes
(
)
:
this
.
.
getSessionTypesForFolder
(
.
)
;
const
=
findSessionType
(
,
.
,
.
)
;
if
(
!
)
{
throw
new
AutomationToolInputError
(
.
===
'quickChat'
?
`The quick-chat target "${target.providerId}/${target.sessionTypeId}" is not available.`
:
'The proposed workspace target is not available for the selected provider and session type.'
)
;
}
if
(
.
===
'workspace'
&&
.
.
===
'worktree'
&&
!
.
.
)
{
throw
new
AutomationToolInputError
(
`Session type "${candidate.sessionType.id}" does not support worktree isolation.`
)
;
}
return
{
...
,
:
.
,
:
.
.
,
}
;
}
private
parseProposal
(
:
unknown
,
:
URI
|
undefined
)
:
{
const
=
;
if
(
!
isRecord
(
)
)
{
throw
new
AutomationToolInputError
(
'configureAutomation input must be an object.'
)
;
}
const
=
;
assertKnownProperties
(
,
[
'automationId'
,
'name'
,
'prompt'
,
'schedule'
,
'target'
,
'modelId'
,
'mode'
,
'permissionLevel'
,
'enabled'
]
,
'configureAutomation input'
)
;
const
=
readOptionalNonEmptyString
(
,
'automationId'
)
;
const
=
?
this
.
.
getAutomation
(
)
:
undefined
;
if
(
&&
!
)
{
throw
new
AutomationToolInputError
(
`Automation "${automationId}" does not exist. Call listAutomations to refresh the available IDs.`
)
;
}
const
=
readOptionalRequiredText
(
,
'name'
)
;
const
=
readOptionalRequiredText
(
,
'prompt'
)
;
if
(
!
&&
===
undefined
)
{
throw
new
AutomationToolInputError
(
'"name" is required when creating an automation.'
)
;
}
if
(
!
&&
===
undefined
)
{
throw
new
AutomationToolInputError
(
'"prompt" is required when creating an automation.'
)
;
}
const
=
parseSchedule
(
,
?.
,
!
)
;
const
=
this
.
getCurrentSessionTarget
(
)
;
const
=
parseTarget
(
,
,
)
;
const
=
readOptionalNullableNonEmptyString
(
,
'modelId'
)
;
const
=
readOptionalNullableEnum
(
,
'mode'
,
)
;
const
=
readOptionalNullableEnum
(
,
'permissionLevel'
,
)
;
const
=
readOptionalBoolean
(
,
'enabled'
)
;
const
:
=
{
...
(
!==
undefined
?
{
}
:
{
}
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
...
(
?
{
}
:
{
}
)
,
...
(
?
{
}
:
{
}
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
}
;
const
=
.
!==
undefined
&&
!
(
isRecord
(
.
)
&&
.
.
===
'currentSession'
)
;
if
(
)
{
return
{
:
'update'
,
,
:
,
}
;
}
if
(
!
)
{
throw
new
AutomationToolInputError
(
'"schedule" is required when creating an automation.'
)
;
}
if
(
!
)
{
throw
new
AutomationToolInputError
(
'A target could not be derived from the current session. Provide an explicit "target".'
)
;
}
if
(
===
undefined
||
===
undefined
)
{
throw
new
Error
(
'Automation create proposal is missing required values.'
)
;
}
return
{
:
'create'
,
:
undefined
,
:
{
,
,
,
,
...
(
?
{
}
:
{
}
)
,
...
(
?
{
}
:
{
}
)
,
...
(
?
{
}
:
{
}
)
,
...
(
!==
undefined
?
{
}
:
{
}
)
,
}
,
,
}
;
}
private
getCurrentSessionTarget
(
:
URI
|
undefined
)
:
|
undefined
{
if
(
!
)
{
return
undefined
;
}
const
=
this
.
.
getSession
(
)
??
this
.
.
getSessionForChatResource
(
)
?.
;
return
?
automationTargetFromSession
(
)
:
undefined
;
}
}
export
class
AutomationToolsContribution
extends
Disposable
implements
IWorkbenchContribution
{
static
readonly
ID
=
'sessions.contrib.automationTools'
;
constructor
(
@ILanguageModelToolsService
:
,
@IInstantiationService
:
,
)
{
super
(
)
;
const
=
.
createInstance
(
)
;
const
=
.
createInstance
(
)
;
const
=
.
createInstance
(
)
;
const
=
.
createInstance
(
)
;
this
.
_register
(
.
registerTool
(
.
getToolData
(
)
,
)
)
;
this
.
_register
(
.
registerTool
(
.
getToolData
(
)
,
)
)
;
this
.
_register
(
.
registerTool
(
.
getToolData
(
)
,
)
)
;
this
.
_register
(
.
registerTool
(
.
getToolData
(
)
,
)
)
;
}
}
function
isAutomationsEnabled
(
:
)
:
boolean
{
return
.
getValue<boolean>
(
CHAT_AUTOMATIONS_ENABLED_SETTING
)
===
true
;
}
function
findSessionType
(
:
readonly
[
]
,
:
string
|
undefined
,
:
string
|
undefined
)
:
|
undefined
{
return
.
find
(
=>
(
===
undefined
||
.
===
)
&&
(
===
undefined
||
.
.
===
)
)
;
}
function
automationTargetFromSession
(
:
)
:
|
undefined
{
if
(
.
?.
get
(
)
===
true
)
{
return
{
:
'quickChat'
,
:
.
,
:
.
,
}
;
}
const
=
.
.
get
(
)
;
return
?
{
:
'workspace'
,
:
.
,
:
.
,
:
.
,
:
{
:
'default'
}
,
}
:
undefined
;
}
function
parseSchedule
(
:
<
string
,
unknown
>
,
:
|
undefined
,
:
boolean
)
:
|
undefined
{
const
=
readOptionalObject
(
,
'schedule'
)
;
if
(
!
)
{
if
(
)
{
throw
new
AutomationToolInputError
(
'"schedule" is required when creating an automation.'
)
;
}
return
undefined
;
}
assertKnownProperties
(
,
[
'interval'
,
'scheduleHour'
,
'scheduleMinute'
,
'scheduleDay'
]
,
'"schedule"'
)
;
const
=
readOptionalEnum
(
,
'interval'
,
)
??
?.
;
if
(
!
)
{
throw
new
AutomationToolInputError
(
'"schedule.interval" is required when creating an automation.'
)
;
}
const
=
readOptionalInteger
(
,
'scheduleHour'
,
0
,
23
)
??
?.
??
9
;
const
=
readOptionalInteger
(
,
'scheduleMinute'
,
0
,
59
)
??
?.
??
0
;
const
=
readOptionalInteger
(
,
'scheduleDay'
,
0
,
6
)
??
?.
??
1
;
return
{
,
,
,
}
;
}
function
parseTarget
(
:
<
string
,
unknown
>
,
:
|
undefined
,
:
|
undefined
)
:
|
undefined
{
const
=
readOptionalObject
(
,
'target'
)
;
if
(
!
)
{
return
?
undefined
:
;
}
assertKnownProperties
(
,
[
'kind'
,
'folderUri'
,
'providerId'
,
'sessionTypeId'
,
'isolation'
,
'branch'
]
,
'"target"'
)
;
const
=
readRequiredEnum
(
,
'kind'
,
[
'currentSession'
,
'workspace'
,
'quickChat'
]
as
const
)
;
if
(
===
'currentSession'
)
{
assertPropertiesAbsent
(
,
[
'folderUri'
,
'providerId'
,
'sessionTypeId'
,
'isolation'
,
'branch'
]
,
'A currentSession target'
)
;
if
(
!
)
{
throw
new
AutomationToolInputError
(
'The current session does not have a resolved automation target.'
)
;
}
return
;
}
if
(
===
'quickChat'
)
{
assertPropertiesAbsent
(
,
[
'folderUri'
,
'isolation'
,
'branch'
]
,
'A quickChat target'
)
;
const
=
?.
.
===
'quickChat'
?
.
:
undefined
;
const
=
readOptionalNonEmptyString
(
,
'providerId'
)
??
?.
??
?.
;
const
=
readOptionalNonEmptyString
(
,
'sessionTypeId'
)
??
?.
??
?.
;
if
(
!
||
!
)
{
throw
new
AutomationToolInputError
(
'A quickChat target requires "providerId" and "sessionTypeId".'
)
;
}
return
{
:
'quickChat'
,
,
}
;
}
const
=
?.
.
===
'workspace'
?
.
:
undefined
;
const
=
?.
===
'workspace'
?
:
undefined
;
const
=
??
;
const
=
readOptionalNonEmptyString
(
,
'folderUri'
)
;
const
=
?
parseUri
(
,
'target.folderUri'
)
:
?.
;
if
(
!
)
{
throw
new
AutomationToolInputError
(
'A workspace target requires "folderUri".'
)
;
}
const
=
readOptionalNonEmptyString
(
,
'providerId'
)
??
?.
;
const
=
readOptionalNonEmptyString
(
,
'sessionTypeId'
)
??
?.
;
const
=
readOptionalEnum
(
,
'isolation'
,
)
??
?.
.
??
'default'
;
const
=
readOptionalNonEmptyString
(
,
'branch'
)
??
(
?.
.
===
'worktree'
?
.
.
:
undefined
)
;
if
(
!==
'worktree'
&&
readOptionalNonEmptyString
(
,
'branch'
)
!==
undefined
)
{
throw
new
AutomationToolInputError
(
'"target.branch" is only valid with worktree isolation.'
)
;
}
let
:
;
if
(
===
'worktree'
)
{
if
(
!
)
{
throw
new
AutomationToolInputError
(
'A workspace target with worktree isolation requires "branch".'
)
;
}
=
{
:
'worktree'
,
}
;
}
else
{
=
{
:
}
;
}
return
{
:
'workspace'
,
,
,
,
}
;
}
function
parseUri
(
:
string
,
:
string
)
:
URI
{
try
{
const
=
URI
.
parse
(
,
true
)
;
if
(
!
.
)
{
throw
new
Error
(
'URI has no scheme.'
)
;
}
return
;
}
catch
{
throw
new
AutomationToolInputError
(
`"${field}" must be a valid absolute URI.`
)
;
}
}
function
toAutomationToolOutput
(
:
)
:
{
const
:
[
'target'
]
=
.
.
===
'workspace'
?
{
:
'workspace'
,
:
.
.
.
toString
(
)
,
:
.
.
??
null
,
:
.
.
??
null
,
:
.
.
,
}
:
{
:
'quickChat'
,
:
.
.
,
:
.
.
,
}
;
return
{
:
.
,
:
.
,
:
.
,
:
.
,
,
:
.
??
null
,
:
.
??
null
,
:
.
??
null
,
:
.
,
:
.
,
:
.
,
:
.
??
null
,
:
.
??
null
,
}
;
}
function
toAutomationConfiguredData
(
:
,
:
[
'operation'
]
)
:
{
return
{
:
'automationConfigured'
,
:
.
,
:
.
,
,
}
;
}
function
automationToolResult
(
:
string
)
:
{
return
{
:
[
{
:
'text'
,
}
]
}
;
}
function
automationToolError
(
:
string
)
:
{
return
{
:
[
{
:
'text'
,
:
}
]
,
:
,
:
localize
(
'automation.tool.error'
,
"Automation request failed"
)
,
}
;
}
function
automationToolCancelled
(
)
:
{
const
=
automationToolResult
(
JSON
.
stringify
(
{
:
'cancelled'
,
:
'The automation change was cancelled. No changes were made.'
,
}
)
)
;
.
=
localize
(
'automation.tool.cancelled'
,
"Automation change cancelled"
)
;
return
;
}
function
automationDeleteCancelled
(
)
:
{
const
=
automationToolResult
(
JSON
.
stringify
(
{
:
'cancelled'
,
:
'The automation was not deleted.'
,
}
)
)
;
.
=
localize
(
'automation.tool.delete.cancelled'
,
"Automation deletion cancelled"
)
;
return
;
}
function
automationRunCancelled
(
)
:
{
const
=
automationToolResult
(
JSON
.
stringify
(
{
:
'cancelled'
,
:
'The automation was not started.'
,
}
)
)
;
.
=
localize
(
'automation.tool.run.cancelled'
,
"Automation run cancelled"
)
;
return
;
}
function
automationAlreadyRunning
(
:
,
:
)
:
{
const
=
automationToolResult
(
JSON
.
stringify
(
{
:
'already_running'
,
:
{
:
.
,
:
.
}
,
:
{
:
.
,
:
.
,
:
.
?.
toString
(
)
??
null
,
}
,
}
,
undefined
,
2
)
)
;
.
=
localize
(
'automation.tool.run.alreadyRunningResult'
,
"Automation {0} is already running"
,
.
)
;
return
;
}
/** Turns a dispatch that never produced a session into an actionable agent-facing message. */
function
automationNotStarted
(
:
,
:
&
{
:
'notStarted'
}
)
:
{
if
(
.
===
'cancelled'
)
{
return
automationRunCancelled
(
)
;
}
if
(
.
===
'deleted'
)
{
return
automationToolError
(
`Automation "${automation.id}" no longer exists.`
)
;
}
if
(
.
===
'targetUnavailable'
)
{
return
automationToolError
(
`Automation "${automation.id}" did not start. Its configured agent is unavailable.`
)
;
}
return
automationToolError
(
.
?.
?
`Automation "${automation.id}" failed to start: ${dispatch.run.errorMessage}`
:
`Automation "${automation.id}" failed to start.`
)
;
}
function
resolveAutomationInput
(
:
,
:
unknown
,
:
'runAutomation'
|
'deleteAutomation'
)
:
{
if
(
!
isRecord
(
)
)
{
throw
new
AutomationToolInputError
(
`${toolName} input must be an object.`
)
;
}
assertKnownProperties
(
,
[
'automationId'
]
,
`${toolName} input`
)
;
const
=
readOptionalNonEmptyString
(
,
'automationId'
)
;
if
(
!
)
{
throw
new
AutomationToolInputError
(
'"automationId" is required.'
)
;
}
const
=
.
getAutomation
(
)
;
if
(
!
)
{
throw
new
AutomationToolInputError
(
`Automation "${automationId}" does not exist. Call listAutomations to refresh the available IDs.`
)
;
}
return
;
}
function
assertKnownProperties
(
:
<
string
,
unknown
>
,
:
readonly
string
[
]
,
:
string
)
:
void
{
const
=
new
Set
(
)
;
const
=
.
keys
(
)
.
find
(
=>
!
.
has
(
)
)
;
if
(
)
{
throw
new
AutomationToolInputError
(
`${field} has an unsupported "${unexpected}" property.`
)
;
}
}
function
assertPropertiesAbsent
(
:
<
string
,
unknown
>
,
:
readonly
string
[
]
,
:
string
)
:
void
{
const
=
.
find
(
=>
[
]
!==
undefined
)
;
if
(
)
{
throw
new
AutomationToolInputError
(
`${field} cannot include "${present}".`
)
;
}
}
function
readOptionalObject
(
:
<
string
,
unknown
>
,
:
string
)
:
<
string
,
unknown
>
|
undefined
{
const
=
[
]
;
if
(
===
undefined
)
{
return
undefined
;
}
if
(
!
isRecord
(
)
)
{
throw
new
AutomationToolInputError
(
`"${property}" must be an object.`
)
;
}
return
;
}
function
readOptionalRequiredText
(
:
<
string
,
unknown
>
,
:
string
)
:
string
|
undefined
{
const
=
[
]
;
if
(
===
undefined
)
{
return
undefined
;
}
if
(
typeof
!==
'string'
||
.
trim
(
)
===
''
)
{
throw
new
AutomationToolInputError
(
`"${property}" must be a non-empty string.`
)
;
}
return
;
}
function
readOptionalNonEmptyString
(
:
<
string
,
unknown
>
,
:
string
)
:
string
|
undefined
{
const
=
readOptionalRequiredText
(
,
)
;
return
?.
trim
(
)
;
}
function
readOptionalNullableNonEmptyString
(
:
<
string
,
unknown
>
,
:
string
)
:
string
|
null
|
undefined
{
const
=
[
]
;
if
(
===
undefined
||
===
null
)
{
return
;
}
if
(
typeof
!==
'string'
||
.
trim
(
)
===
''
)
{
throw
new
AutomationToolInputError
(
`"${property}" must be a non-empty string or null.`
)
;
}
return
.
trim
(
)
;
}
function
readOptionalBoolean
(
:
<
string
,
unknown
>
,
:
string
)
:
boolean
|
undefined
{
const
=
[
]
;
if
(
===
undefined
)
{
return
undefined
;
}
if
(
typeof
!==
'boolean'
)
{
throw
new
AutomationToolInputError
(
`"${property}" must be a boolean.`
)
;
}
return
;
}
function
readOptionalInteger
(
:
<
string
,
unknown
>
,
:
string
,
:
number
,
:
number
)
:
number
|
undefined
{
const
=
[
]
;
if
(
===
undefined
)
{
return
undefined
;
}
if
(
typeof
!==
'number'
||
!
.
isInteger
(
)
||
<
||
>
)
{
throw
new
AutomationToolInputError
(
`"${property}" must be an integer from ${minimum} through ${maximum}.`
)
;
}
return
;
}
function
readRequiredEnum<constTextendsstring>
(
:
<
string
,
unknown
>
,
:
string
,
:
readonly
T
[
]
)
:
T
{
const
=
readOptionalEnum
(
,
,
)
;
if
(
===
undefined
)
{
throw
new
AutomationToolInputError
(
`"${property}" is required.`
)
;
}
return
;
}
function
readOptionalEnum<constTextendsstring>
(
:
<
string
,
unknown
>
,
:
string
,
:
readonly
T
[
]
)
:
T
|
undefined
{
const
=
[
]
;
if
(
===
undefined
)
{
return
undefined
;
}
if
(
!
isAllowedString
(
,
)
)
{
throw
new
AutomationToolInputError
(
`"${property}" must be one of: ${allowed.join(', ')}.`
)
;
}
return
;
}
function
readOptionalNullableEnum<constTextendsstring>
(
:
<
string
,
unknown
>
,
:
string
,
:
readonly
T
[
]
)
:
T
|
null
|
undefined
{
const
=
[
]
;
if
(
===
undefined
||
===
null
)
{
return
;
}
if
(
!
isAllowedString
(
,
)
)
{
throw
new
AutomationToolInputError
(
`"${property}" must be null or one of: ${allowed.join(', ')}.`