Skip to content

Let's consider to use a concrete type for toolInvocationToken #231937

@jrieken

Description

@jrieken

I have seen @isidorn pass a cancellation token as toolInvocationToken when calling invoke. I guess this is because of "looks like a token must be a token" thinking. We could rename the field or (my favourite) use a concrete type (class with private ctor) for this so that using a cancellation token or anything else yields a compile error

Activity

added this to the October 2024 milestone on Oct 22, 2024
added a commit that references this issue on Oct 23, 2024
roblourens

roblourens commented on Oct 24, 2024

@roblourens
Member

Have runtime validation and never for now. Could explore a shape using unique symbol later but I don't know that it makes the usage any clearer.

jrieken

jrieken commented on Oct 25, 2024

@jrieken
MemberAuthor

Could explore a shape using unique symbol later but I don't know that it makes the usage any clearer.

I like unique symbol but I couldn't get TS happy when I would use it in type Foo = typeof unique symbol; @connor4312 do you know what I am doing wrong?

connor4312

connor4312 commented on Oct 25, 2024

@connor4312
Member

Unique symbols are pretty special. In for case I think they need to be contained in an interface, like interface MyOpaqueType { readonly _opaque: unique symbol }. With this MyOpaqueType will be type that a consumer cannot construct and is irreplacable (except with any).

added a commit that references this issue on Nov 13, 2024

3 remaining items

c-claeys

c-claeys commented on Jan 21, 2025

@c-claeys
Contributor

Thanks for confirming!

added a commit that references this issue on Jan 21, 2025
removed this from the March 2025 milestone on Mar 24, 2025
roblourens

roblourens commented on May 6, 2025

@roblourens
Member

Was looking at this again because I had more questions similar to the above. Is this too confusing to explain in our API?

/**
 * A token that can be passed to {@link lm.invokeTool} when invoking a tool inside the context of handling a chat request.
 */
export type ChatParticipantToolToken = {
	/**
	 * A unique symbol to prevent accidental construction of this type (see proper usage note on {@link LanguageModelToolInvocationOptions.toolInvocationToken}).
	 */
	readonly sym: unique symbol;
};

The other option I have in mind: change the prop in the token from today's sessionId to something like __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED and I kinda prefer it

added this to the May 2025 milestone on May 8, 2025
added a commit that references this issue on May 8, 2025
a771825
roblourens

roblourens commented on May 9, 2025

@roblourens
Member

Here's my suggestion, I think it's nicer than passing a never around #248452

modified the milestones: May 2025, June 2025 on Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @roblourens@jrieken@connor4312@c-claeys

    Issue actions

      Let's consider to use a concrete type for `toolInvocationToken` · Issue #231937 · microsoft/vscode