541
);
542
}
544
>
545
>
export class ToolSetForModel {
546
>
public get id() {
547
>
return this._toolSet.id;
548
>
}
549
>
550
>
public get referenceName() {
551
return this._toolSet.referenceName;
552
}
554
>
public get icon() {
555
return this._toolSet.icon;
556
}
558
>
public get source() {
559
return this._toolSet.source;
560
}
562
>
public get description() {
563
return this._toolSet.description;
564
}
566
>
public get detail() {
567
return this._toolSet.detail;
568
}
570
>
public get legacyFullNames() {
571
return this._toolSet.legacyFullNames;
572
}
574
>
public get deprecated() {
575
return this._toolSet.deprecated;
576
}
578
>
public get hiddenInToolsPicker() {
579
return this._toolSet.hiddenInToolsPicker;
580
}
582
>
constructor(
583
private readonly _toolSet: IToolSet,
584
private readonly model: ILanguageModelChatMetadata | undefined,
585
private readonly toolFilter?: (toolData: IToolData) => boolean,
586
) { }
588
>
public getTools(r?: IReader): Iterable<IToolData> {
589
return Iterable.filter(this._toolSet.getTools(r), toolData => toolMatchesModel(toolData, this.model) && (!this.toolFilter || this.toolFilter(toolData)));
590
}
592
>
593
>
594
>
export interface IBeginToolCallOptions {
595
>
toolCallId: string;
596
>
toolId: string;
597
>
chatRequestId?: string;
598
>
sessionResource?: URI;
599
>
subagentInvocationId?: string;
600
>
/**
601
>
* Create the streaming invocation even when the tool does not
602
>
* implement `handleToolStream`. Used by callers that need a
603
>
* `ChatToolInvocation` handle to observe state transitions (e.g.
604
>
* confirmation) before invoking the tool.
605
>
*/
606
>
force?: boolean;
607
>
}
608
>
609
>
export interface IToolInvokedEvent {
610
>
readonly toolId: string;
611
>
readonly sessionResource: URI | undefined;
612
>
readonly requestId: string | undefined;
613
>
readonly subagentInvocationId: string | undefined;
614
>
}
615
>
616
>
export const ILanguageModelToolsService = createDecorator<ILanguageModelToolsService>('ILanguageModelToolsService');
617
>
618
>
export type CountTokensCallback = (input: string, token: CancellationToken) => Promise<number>;
619
>
620
>
export interface ILanguageModelToolsService {
621
>
_serviceBrand: undefined;
622
>
readonly vscodeToolSet: ToolSet;
623
>
readonly executeToolSet: ToolSet;
624
>
readonly readToolSet: ToolSet;
625
>
readonly agentToolSet: ToolSet;
626
>
readonly onDidChangeTools: Event<void>;
627
>
readonly onDidPrepareToolCallBecomeUnresponsive: Event<{ readonly sessionResource: URI; readonly toolData: IToolData }>;
628
>
readonly onDidInvokeTool: Event<IToolInvokedEvent>;
629
>
registerToolData(toolData: IToolData): IDisposable;
630
>
registerToolImplementation(id: string, tool: IToolImpl): IDisposable;
631
>
registerTool(toolData: IToolData, tool: IToolImpl): IDisposable;
632
>
633
>
/**
634
>
* Get all tools currently enabled (matching `when` clauses and model).
635
>
* @param model The language model metadata to filter tools by. If undefined, model-specific filtering is skipped.
636
>
*/
637
>
getTools(model: ILanguageModelChatMetadata | undefined): Iterable<IToolData>;
638
>
639
>
/**
640
>
* Creats an observable of enabled tools in the context. Note the observable
641
>
* should be created and reused, not created per reader, for example:
642
>
*
643
>
* ```
644
>
* const toolsObs = toolsService.observeTools(model);
645
>
* autorun(reader => {
646
>
* const tools = toolsObs.read(reader);
647
>
* ...
648
>
* });
649
>
* ```
650
>
* @param model The language model metadata to filter tools by. If undefined, model-specific filtering is skipped.
651
>
*/
652
>
observeTools(model: ILanguageModelChatMetadata | undefined): IObservable<readonly IToolData[]>;
653
>
654
>
/**
655
>
* Get all registered tools regardless of enablement state.
656
>
* Use this for configuration UIs, completions, etc. where all tools should be visible.
657
>
*/
658
>
getAllToolsIncludingDisabled(): Iterable<IToolData>;
659
>
660
>
/**
661
>
* Get a tool by its ID. Does not check when clauses.
662
>
*/
663
>
getTool(id: string): IToolData | undefined;
664
>
665
>
/**
666
>
* Get a tool by its reference name. Does not check when clauses.
667
>
*/
668
>
getToolByName(name: string): IToolData | undefined;
669
>
670
>
/**
671
>
* Begin a tool call in the streaming phase.
672
>
* Creates a ChatToolInvocation in the Streaming state and appends it to the chat.
673
>
* Returns the invocation so it can be looked up later when invokeTool is called.
674
>
*/
675
>
beginToolCall(options: IBeginToolCallOptions): IChatToolInvocation | undefined;
676
>
677
>
/**
678
>
* Update the streaming state of a pending tool call.
679
>
* Calls the tool's handleToolStream method to get a custom invocation message.
680
>
*/
681
>
updateToolStream(toolCallId: string, partialInput: unknown, token: CancellationToken): Promise<void>;
682
>
683
>
invokeTool(invocation: IToolInvocation, countTokens: CountTokensCallback, token: CancellationToken): Promise<IToolResult>;
684
>
cancelToolCallsForRequest(requestId: string): void;
685
>
/** Flush any pending tool updates to the extension hosts. */
686
>
flushToolUpdates(): void;
687
>
688
>
readonly toolSets: IObservable<Iterable<IToolSet>>;
689
>
getToolSetsForModel(model: ILanguageModelChatMetadata | undefined, reader?: IReader): Iterable<IToolSet>;
690
>
getToolSet(id: string): IToolSet | undefined;
691
>
getToolSetByName(name: string): IToolSet | undefined;
692
>
createToolSet(source: ToolDataSource, id: string, referenceName: string, options?: { icon?: ThemeIcon; description?: string; detail?: string; legacyFullNames?: string[]; deprecated?: boolean; hiddenInToolsPicker?: boolean }): ToolSet & IDisposable;
693
>
694
>
// tool names in prompt and agent files ('full reference names')
695
>
getFullReferenceNames(): Iterable<string>;
696
>
getFullReferenceName(tool: IToolData | IToolSet, toolSet?: IToolSet): string;
697
>
getFullReferenceNameMap(): Map<IToolData | IToolSet, string>;
698
>
getToolByFullReferenceName(fullReferenceName: string): IToolData | IToolSet | undefined;
699
>
getDeprecatedFullReferenceNames(): Map<string, Set<string>>;
700
>
701
>
/**
702
>
* Gets the enablement maps based on the given set of references.
703
>
* @param fullReferenceNames The full reference names of the tools and tool sets to enable.
704
>
* @param model Optional language model metadata to filter tools by.
705
>
* If undefined is passed, all tools will be returned, even if normally disabled.
706
>
*/
707
>
toToolAndToolSetEnablementMap(fullReferenceNames: readonly string[], model: ILanguageModelChatMetadata | undefined): ToolAndToolSetEnablementMap;
708
>
709
>
toFullReferenceNames(map: ToolAndToolSetEnablementMap): string[];
710
>
toToolReferences(variableReferences: readonly IVariableReference[]): ChatRequestToolReferenceEntry[];
711
>
}
712
>
713
>
714
>
export function createToolInputUri(toolCallId: string): URI {
715
return URI.from({ scheme: Schemas.inMemory, path: `/lm/tool/${toolCallId}/tool_input.json` });
716
}
718
>
export function createToolSchemaUri(toolOrId: IToolData | string): URI {
719
if (typeof toolOrId !== 'string') {
720
toolOrId = toolOrId.id;