@theia/plugin 1.50.1 → 1.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theia/plugin",
3
- "version": "1.50.1",
3
+ "version": "1.51.0",
4
4
  "description": "Theia - Plugin API",
5
5
  "types": "./src/theia.d.ts",
6
6
  "publishConfig": {
@@ -27,10 +27,10 @@
27
27
  "watch": "theiaext watch"
28
28
  },
29
29
  "devDependencies": {
30
- "@theia/ext-scripts": "1.50.1"
30
+ "@theia/ext-scripts": "1.51.0"
31
31
  },
32
32
  "nyc": {
33
33
  "extends": "../../configs/nyc.json"
34
34
  },
35
- "gitHead": "ffefc7ac2c0f6c63256042b7710551304200e5e1"
35
+ "gitHead": "fe70ec5d445d733038564d81357c78aedf5c7e0e"
36
36
  }
@@ -291,6 +291,13 @@ export module '@theia/plugin' {
291
291
  * see - workspace.fs for how to read and write files and folders from an uri.
292
292
  */
293
293
  readonly logUri: Uri;
294
+
295
+ /**
296
+ * An object that keeps information about how this extension can use language models.
297
+ *
298
+ * @see {@link LanguageModelChat.sendRequest}
299
+ */
300
+ readonly languageModelAccessInformation: LanguageModelAccessInformation;
294
301
  }
295
302
 
296
303
  export namespace commands {
package/src/theia.d.ts CHANGED
@@ -4028,6 +4028,14 @@ export module '@theia/plugin' {
4028
4028
  * The current `Extension` instance.
4029
4029
  */
4030
4030
  readonly extension: Extension<any>;
4031
+
4032
+ /**
4033
+ * An object that keeps information about how this extension can use language models.
4034
+ *
4035
+ * @see {@link LanguageModelChat.sendRequest}
4036
+ * @stubbed
4037
+ */
4038
+ readonly languageModelAccessInformation: LanguageModelAccessInformation;
4031
4039
  }
4032
4040
 
4033
4041
  /**
@@ -7734,6 +7742,9 @@ export module '@theia/plugin' {
7734
7742
 
7735
7743
  /**
7736
7744
  * The application root folder from which the editor is running.
7745
+ *
7746
+ * *Note* that the value is the empty string when running in an
7747
+ * environment that has no representation of an application root folder.
7737
7748
  */
7738
7749
  export const appRoot: string;
7739
7750
 
@@ -12437,6 +12448,50 @@ export module '@theia/plugin' {
12437
12448
  Dynamic = 2
12438
12449
  }
12439
12450
 
12451
+ /**
12452
+ * Represents a thread in a debug session.
12453
+ */
12454
+ export class DebugThread {
12455
+ /**
12456
+ * Debug session for thread.
12457
+ */
12458
+ readonly session: DebugSession;
12459
+
12460
+ /**
12461
+ * ID of the associated thread in the debug protocol.
12462
+ */
12463
+ readonly threadId: number;
12464
+
12465
+ /**
12466
+ * @hidden
12467
+ */
12468
+ private constructor(session: DebugSession, threadId: number);
12469
+ }
12470
+
12471
+ /**
12472
+ * Represents a stack frame in a debug session.
12473
+ */
12474
+ export class DebugStackFrame {
12475
+ /**
12476
+ * Debug session for thread.
12477
+ */
12478
+ readonly session: DebugSession;
12479
+
12480
+ /**
12481
+ * ID of the associated thread in the debug protocol.
12482
+ */
12483
+ readonly threadId: number;
12484
+ /**
12485
+ * ID of the stack frame in the debug protocol.
12486
+ */
12487
+ readonly frameId: number;
12488
+
12489
+ /**
12490
+ * @hidden
12491
+ */
12492
+ private constructor(session: DebugSession, threadId: number, frameId: number);
12493
+ }
12494
+
12440
12495
  /**
12441
12496
  * Namespace for debug functionality.
12442
12497
  */
@@ -12486,6 +12541,21 @@ export module '@theia/plugin' {
12486
12541
  */
12487
12542
  export const onDidChangeBreakpoints: Event<BreakpointsChangeEvent>;
12488
12543
 
12544
+ /**
12545
+ * The currently focused thread or stack frame, or `undefined` if no
12546
+ * thread or stack is focused. A thread can be focused any time there is
12547
+ * an active debug session, while a stack frame can only be focused when
12548
+ * a session is paused and the call stack has been retrieved.
12549
+ * @stubbed
12550
+ */
12551
+ export const activeStackItem: DebugThread | DebugStackFrame | undefined;
12552
+
12553
+ /**
12554
+ * An event which fires when the {@link debug.activeStackItem} has changed.
12555
+ * @stubbed
12556
+ */
12557
+ export const onDidChangeActiveStackItem: Event<DebugThread | DebugStackFrame | undefined>;
12558
+
12489
12559
  /**
12490
12560
  * Register a {@link DebugAdapterDescriptorFactory debug adapter descriptor factory} for a specific debug type.
12491
12561
  * An extension is only allowed to register a DebugAdapterDescriptorFactory for the debug type(s) defined by the extension. Otherwise an error is thrown.
@@ -16242,13 +16312,22 @@ export module '@theia/plugin' {
16242
16312
  */
16243
16313
  readonly continuous?: boolean;
16244
16314
 
16315
+ /**
16316
+ * Controls how test Test Results view is focused. If true, the editor
16317
+ * will keep the maintain the user's focus. If false, the editor will
16318
+ * prefer to move focus into the Test Results view, although
16319
+ * this may be configured by users.
16320
+ */
16321
+ readonly preserveFocus: boolean;
16322
+
16245
16323
  /**
16246
16324
  * @param include Array of specific tests to run, or undefined to run all tests
16247
16325
  * @param exclude An array of tests to exclude from the run.
16248
16326
  * @param profile The run profile used for this request.
16249
16327
  * @param continuous Whether to run tests continuously as source changes.
16328
+ * @param preserveFocus Whether to preserve the user's focus when the run is started
16250
16329
  */
16251
- constructor(include?: readonly TestItem[], exclude?: readonly TestItem[], profile?: TestRunProfile, continuous?: boolean);
16330
+ constructor(include?: readonly TestItem[], exclude?: readonly TestItem[], profile?: TestRunProfile, continuous?: boolean, preserveFocus?: boolean);
16252
16331
  }
16253
16332
 
16254
16333
  /**
@@ -16729,6 +16808,857 @@ export module '@theia/plugin' {
16729
16808
  */
16730
16809
  export type FileCoverageDetail = StatementCoverage | DeclarationCoverage;
16731
16810
 
16811
+ /**
16812
+ * Represents a user request in chat history.
16813
+ */
16814
+ export class ChatRequestTurn {
16815
+ /**
16816
+ * The prompt as entered by the user.
16817
+ *
16818
+ * Information about references used in this request is stored in {@link ChatRequestTurn.references}.
16819
+ *
16820
+ * *Note* that the {@link ChatParticipant.name name} of the participant and the {@link ChatCommand.name command}
16821
+ * are not part of the prompt.
16822
+ */
16823
+ readonly prompt: string;
16824
+
16825
+ /**
16826
+ * The id of the chat participant to which this request was directed.
16827
+ */
16828
+ readonly participant: string;
16829
+
16830
+ /**
16831
+ * The name of the {@link ChatCommand command} that was selected for this request.
16832
+ */
16833
+ readonly command?: string;
16834
+
16835
+ /**
16836
+ * The references that were used in this message.
16837
+ */
16838
+ readonly references: ChatPromptReference[];
16839
+
16840
+ /**
16841
+ * @hidden
16842
+ */
16843
+ private constructor(prompt: string, command: string | undefined, references: ChatPromptReference[], participant: string);
16844
+ }
16845
+
16846
+ /**
16847
+ * Represents a chat participant's response in chat history.
16848
+ */
16849
+ export class ChatResponseTurn {
16850
+ /**
16851
+ * The content that was received from the chat participant. Only the stream parts that represent actual content (not metadata) are represented.
16852
+ */
16853
+ readonly response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>;
16854
+
16855
+ /**
16856
+ * The result that was received from the chat participant.
16857
+ */
16858
+ readonly result: ChatResult;
16859
+
16860
+ /**
16861
+ * The id of the chat participant that this response came from.
16862
+ */
16863
+ readonly participant: string;
16864
+
16865
+ /**
16866
+ * The name of the command that this response came from.
16867
+ */
16868
+ readonly command?: string;
16869
+
16870
+ /**
16871
+ * @hidden
16872
+ */
16873
+ private constructor(response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>, result: ChatResult, participant: string);
16874
+ }
16875
+
16876
+ /**
16877
+ * Extra context passed to a participant.
16878
+ */
16879
+ export interface ChatContext {
16880
+ /**
16881
+ * All of the chat messages so far in the current chat session. Currently, only chat messages for the current participant are included.
16882
+ */
16883
+ readonly history: ReadonlyArray<ChatRequestTurn | ChatResponseTurn>;
16884
+ }
16885
+
16886
+ /**
16887
+ * Represents an error result from a chat request.
16888
+ */
16889
+ export interface ChatErrorDetails {
16890
+ /**
16891
+ * An error message that is shown to the user.
16892
+ */
16893
+ message: string;
16894
+
16895
+ /**
16896
+ * If set to true, the response will be partly blurred out.
16897
+ */
16898
+ responseIsFiltered?: boolean;
16899
+ }
16900
+
16901
+ /**
16902
+ * The result of a chat request.
16903
+ */
16904
+ export interface ChatResult {
16905
+ /**
16906
+ * If the request resulted in an error, this property defines the error details.
16907
+ */
16908
+ errorDetails?: ChatErrorDetails;
16909
+
16910
+ /**
16911
+ * Arbitrary metadata for this result. Can be anything, but must be JSON-stringifyable.
16912
+ */
16913
+ readonly metadata?: { readonly [key: string]: any };
16914
+ }
16915
+
16916
+ /**
16917
+ * Represents the type of user feedback received.
16918
+ */
16919
+ export enum ChatResultFeedbackKind {
16920
+ /**
16921
+ * The user marked the result as unhelpful.
16922
+ */
16923
+ Unhelpful = 0,
16924
+
16925
+ /**
16926
+ * The user marked the result as helpful.
16927
+ */
16928
+ Helpful = 1,
16929
+ }
16930
+
16931
+ /**
16932
+ * Represents user feedback for a result.
16933
+ */
16934
+ export interface ChatResultFeedback {
16935
+ /**
16936
+ * The ChatResult for which the user is providing feedback.
16937
+ * This object has the same properties as the result returned from the participant callback, including `metadata`, but is not the same instance.
16938
+ */
16939
+ readonly result: ChatResult;
16940
+
16941
+ /**
16942
+ * The kind of feedback that was received.
16943
+ */
16944
+ readonly kind: ChatResultFeedbackKind;
16945
+ }
16946
+
16947
+ /**
16948
+ * A followup question suggested by the participant.
16949
+ */
16950
+ export interface ChatFollowup {
16951
+ /**
16952
+ * The message to send to the chat.
16953
+ */
16954
+ prompt: string;
16955
+
16956
+ /**
16957
+ * A title to show the user. The prompt will be shown by default, when this is unspecified.
16958
+ */
16959
+ label?: string;
16960
+
16961
+ /**
16962
+ * By default, the followup goes to the same participant/command. But this property can be set to invoke a different participant by ID.
16963
+ * Followups can only invoke a participant that was contributed by the same extension.
16964
+ */
16965
+ participant?: string;
16966
+
16967
+ /**
16968
+ * By default, the followup goes to the same participant/command. But this property can be set to invoke a different command.
16969
+ */
16970
+ command?: string;
16971
+ }
16972
+
16973
+ /**
16974
+ * Will be invoked once after each request to get suggested followup questions to show the user. The user can click the followup to send it to the chat.
16975
+ */
16976
+ export interface ChatFollowupProvider {
16977
+ /**
16978
+ * Provide followups for the given result.
16979
+ * @param result This object has the same properties as the result returned from the participant callback, including `metadata`, but is not the same instance.
16980
+ * @param token A cancellation token.
16981
+ */
16982
+ provideFollowups(result: ChatResult, context: ChatContext, token: CancellationToken): ProviderResult<ChatFollowup[]>;
16983
+ }
16984
+
16985
+ /**
16986
+ * A chat request handler is a callback that will be invoked when a request is made to a chat participant.
16987
+ */
16988
+ export type ChatRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult<ChatResult | void>;
16989
+
16990
+ /**
16991
+ * A chat participant can be invoked by the user in a chat session, using the `@` prefix. When it is invoked, it handles the chat request and is solely
16992
+ * responsible for providing a response to the user. A ChatParticipant is created using {@link chat.createChatParticipant}.
16993
+ */
16994
+ export interface ChatParticipant {
16995
+ /**
16996
+ * A unique ID for this participant.
16997
+ */
16998
+ readonly id: string;
16999
+
17000
+ /**
17001
+ * An icon for the participant shown in UI.
17002
+ */
17003
+ iconPath?: Uri | {
17004
+ /**
17005
+ * The icon path for the light theme.
17006
+ */
17007
+ light: Uri;
17008
+ /**
17009
+ * The icon path for the dark theme.
17010
+ */
17011
+ dark: Uri;
17012
+ } | ThemeIcon;
17013
+
17014
+ /**
17015
+ * The handler for requests to this participant.
17016
+ */
17017
+ requestHandler: ChatRequestHandler;
17018
+
17019
+ /**
17020
+ * This provider will be called once after each request to retrieve suggested followup questions.
17021
+ */
17022
+ followupProvider?: ChatFollowupProvider;
17023
+
17024
+ /**
17025
+ * An event that fires whenever feedback for a result is received, e.g. when a user up- or down-votes
17026
+ * a result.
17027
+ *
17028
+ * The passed {@link ChatResultFeedback.result result} is guaranteed to be the same instance that was
17029
+ * previously returned from this chat participant.
17030
+ */
17031
+ onDidReceiveFeedback: Event<ChatResultFeedback>;
17032
+
17033
+ /**
17034
+ * Dispose this participant and free resources.
17035
+ */
17036
+ dispose(): void;
17037
+ }
17038
+
17039
+ /**
17040
+ * A reference to a value that the user added to their chat request.
17041
+ */
17042
+ export interface ChatPromptReference {
17043
+ /**
17044
+ * A unique identifier for this kind of reference.
17045
+ */
17046
+ readonly id: string;
17047
+
17048
+ /**
17049
+ * The start and end index of the reference in the {@link ChatRequest.prompt prompt}. When undefined, the reference was not part of the prompt text.
17050
+ *
17051
+ * *Note* that the indices take the leading `#`-character into account which means they can
17052
+ * used to modify the prompt as-is.
17053
+ */
17054
+ readonly range?: [start: number, end: number];
17055
+
17056
+ /**
17057
+ * A description of this value that could be used in an LLM prompt.
17058
+ */
17059
+ readonly modelDescription?: string;
17060
+
17061
+ /**
17062
+ * The value of this reference. The `string | Uri | Location` types are used today, but this could expand in the future.
17063
+ */
17064
+ readonly value: string | Uri | Location | unknown;
17065
+ }
17066
+
17067
+ /**
17068
+ * A request to a chat participant.
17069
+ */
17070
+ export interface ChatRequest {
17071
+ /**
17072
+ * The prompt as entered by the user.
17073
+ *
17074
+ * Information about references used in this request is stored in {@link ChatRequest.references}.
17075
+ *
17076
+ * *Note* that the {@link ChatParticipant.name name} of the participant and the {@link ChatCommand.name command}
17077
+ * are not part of the prompt.
17078
+ */
17079
+ readonly prompt: string;
17080
+
17081
+ /**
17082
+ * The name of the {@link ChatCommand command} that was selected for this request.
17083
+ */
17084
+ readonly command: string | undefined;
17085
+
17086
+ /**
17087
+ * The list of references and their values that are referenced in the prompt.
17088
+ *
17089
+ * *Note* that the prompt contains references as authored and that it is up to the participant
17090
+ * to further modify the prompt, for instance by inlining reference values or creating links to
17091
+ * headings which contain the resolved values. References are sorted in reverse by their range
17092
+ * in the prompt. That means the last reference in the prompt is the first in this list. This simplifies
17093
+ * string-manipulation of the prompt.
17094
+ */
17095
+ readonly references: readonly ChatPromptReference[];
17096
+ }
17097
+
17098
+ /**
17099
+ * The ChatResponseStream is how a participant is able to return content to the chat view. It provides several methods for streaming different types of content
17100
+ * which will be rendered in an appropriate way in the chat view. A participant can use the helper method for the type of content it wants to return, or it
17101
+ * can instantiate a {@link ChatResponsePart} and use the generic {@link ChatResponseStream.push} method to return it.
17102
+ */
17103
+ export interface ChatResponseStream {
17104
+ /**
17105
+ * Push a markdown part to this stream. Short-hand for
17106
+ * `push(new ChatResponseMarkdownPart(value))`.
17107
+ *
17108
+ * @see {@link ChatResponseStream.push}
17109
+ * @param value A markdown string or a string that should be interpreted as markdown. The boolean form of {@link MarkdownString.isTrusted} is NOT supported.
17110
+ */
17111
+ markdown(value: string | MarkdownString): void;
17112
+
17113
+ /**
17114
+ * Push an anchor part to this stream. Short-hand for
17115
+ * `push(new ChatResponseAnchorPart(value, title))`.
17116
+ * An anchor is an inline reference to some type of resource.
17117
+ *
17118
+ * @param value A uri, location, or symbol information.
17119
+ * @param title An optional title that is rendered with value.
17120
+ */
17121
+ anchor(value: Uri | Location, title?: string): void;
17122
+
17123
+ /**
17124
+ * Push a command button part to this stream. Short-hand for
17125
+ * `push(new ChatResponseCommandButtonPart(value, title))`.
17126
+ *
17127
+ * @param command A Command that will be executed when the button is clicked.
17128
+ */
17129
+ button(command: Command): void;
17130
+
17131
+ /**
17132
+ * Push a filetree part to this stream. Short-hand for
17133
+ * `push(new ChatResponseFileTreePart(value))`.
17134
+ *
17135
+ * @param value File tree data.
17136
+ * @param baseUri The base uri to which this file tree is relative.
17137
+ */
17138
+ filetree(value: ChatResponseFileTree[], baseUri: Uri): void;
17139
+
17140
+ /**
17141
+ * Push a progress part to this stream. Short-hand for
17142
+ * `push(new ChatResponseProgressPart(value))`.
17143
+ *
17144
+ * @param value A progress message
17145
+ */
17146
+ progress(value: string): void;
17147
+
17148
+ /**
17149
+ * Push a reference to this stream. Short-hand for
17150
+ * `push(new ChatResponseReferencePart(value))`.
17151
+ *
17152
+ * *Note* that the reference is not rendered inline with the response.
17153
+ *
17154
+ * @param value A uri or location
17155
+ * @param iconPath Icon for the reference shown in UI
17156
+ */
17157
+ reference(value: Uri | Location, iconPath?: Uri | ThemeIcon | {
17158
+ /**
17159
+ * The icon path for the light theme.
17160
+ */
17161
+ light: Uri;
17162
+ /**
17163
+ * The icon path for the dark theme.
17164
+ */
17165
+ dark: Uri;
17166
+ }): void;
17167
+
17168
+ /**
17169
+ * Pushes a part to this stream.
17170
+ *
17171
+ * @param part A response part, rendered or metadata
17172
+ */
17173
+ push(part: ChatResponsePart): void;
17174
+ }
17175
+
17176
+ /**
17177
+ * Represents a part of a chat response that is formatted as Markdown.
17178
+ */
17179
+ export class ChatResponseMarkdownPart {
17180
+ /**
17181
+ * A markdown string or a string that should be interpreted as markdown.
17182
+ */
17183
+ value: MarkdownString;
17184
+
17185
+ /**
17186
+ * Create a new ChatResponseMarkdownPart.
17187
+ *
17188
+ * @param value A markdown string or a string that should be interpreted as markdown. The boolean form of {@link MarkdownString.isTrusted} is NOT supported.
17189
+ */
17190
+ constructor(value: string | MarkdownString);
17191
+ }
17192
+
17193
+ /**
17194
+ * Represents a file tree structure in a chat response.
17195
+ */
17196
+ export interface ChatResponseFileTree {
17197
+ /**
17198
+ * The name of the file or directory.
17199
+ */
17200
+ name: string;
17201
+
17202
+ /**
17203
+ * An array of child file trees, if the current file tree is a directory.
17204
+ */
17205
+ children?: ChatResponseFileTree[];
17206
+ }
17207
+
17208
+ /**
17209
+ * Represents a part of a chat response that is a file tree.
17210
+ */
17211
+ export class ChatResponseFileTreePart {
17212
+ /**
17213
+ * File tree data.
17214
+ */
17215
+ value: ChatResponseFileTree[];
17216
+
17217
+ /**
17218
+ * The base uri to which this file tree is relative
17219
+ */
17220
+ baseUri: Uri;
17221
+
17222
+ /**
17223
+ * Create a new ChatResponseFileTreePart.
17224
+ * @param value File tree data.
17225
+ * @param baseUri The base uri to which this file tree is relative.
17226
+ */
17227
+ constructor(value: ChatResponseFileTree[], baseUri: Uri);
17228
+ }
17229
+
17230
+ /**
17231
+ * Represents a part of a chat response that is an anchor, that is rendered as a link to a target.
17232
+ */
17233
+ export class ChatResponseAnchorPart {
17234
+ /**
17235
+ * The target of this anchor.
17236
+ */
17237
+ value: Uri | Location;
17238
+
17239
+ /**
17240
+ * An optional title that is rendered with value.
17241
+ */
17242
+ title?: string;
17243
+
17244
+ /**
17245
+ * Create a new ChatResponseAnchorPart.
17246
+ * @param value A uri or location.
17247
+ * @param title An optional title that is rendered with value.
17248
+ */
17249
+ constructor(value: Uri | Location, title?: string);
17250
+ }
17251
+
17252
+ /**
17253
+ * Represents a part of a chat response that is a progress message.
17254
+ */
17255
+ export class ChatResponseProgressPart {
17256
+ /**
17257
+ * The progress message
17258
+ */
17259
+ value: string;
17260
+
17261
+ /**
17262
+ * Create a new ChatResponseProgressPart.
17263
+ * @param value A progress message
17264
+ */
17265
+ constructor(value: string);
17266
+ }
17267
+
17268
+ /**
17269
+ * Represents a part of a chat response that is a reference, rendered separately from the content.
17270
+ */
17271
+ export class ChatResponseReferencePart {
17272
+ /**
17273
+ * The reference target.
17274
+ */
17275
+ value: Uri | Location;
17276
+
17277
+ /**
17278
+ * The icon for the reference.
17279
+ */
17280
+ iconPath?: Uri | ThemeIcon | {
17281
+ /**
17282
+ * The icon path for the light theme.
17283
+ */
17284
+ light: Uri;
17285
+ /**
17286
+ * The icon path for the dark theme.
17287
+ */
17288
+ dark: Uri;
17289
+ };
17290
+
17291
+ /**
17292
+ * Create a new ChatResponseReferencePart.
17293
+ * @param value A uri or location
17294
+ * @param iconPath Icon for the reference shown in UI
17295
+ */
17296
+ constructor(value: Uri | Location, iconPath?: Uri | ThemeIcon | {
17297
+ /**
17298
+ * The icon path for the light theme.
17299
+ */
17300
+ light: Uri;
17301
+ /**
17302
+ * The icon path for the dark theme.
17303
+ */
17304
+ dark: Uri;
17305
+ });
17306
+ }
17307
+
17308
+ /**
17309
+ * Represents a part of a chat response that is a button that executes a command.
17310
+ */
17311
+ export class ChatResponseCommandButtonPart {
17312
+ /**
17313
+ * The command that will be executed when the button is clicked.
17314
+ */
17315
+ value: Command;
17316
+
17317
+ /**
17318
+ * Create a new ChatResponseCommandButtonPart.
17319
+ * @param value A Command that will be executed when the button is clicked.
17320
+ */
17321
+ constructor(value: Command);
17322
+ }
17323
+
17324
+ /**
17325
+ * Represents the different chat response types.
17326
+ */
17327
+ export type ChatResponsePart = ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart
17328
+ | ChatResponseProgressPart | ChatResponseReferencePart | ChatResponseCommandButtonPart;
17329
+
17330
+ /**
17331
+ * Namespace for chat functionality. Users interact with chat participants by sending messages
17332
+ * to them in the chat view. Chat participants can respond with markdown or other types of content
17333
+ * via the {@link ChatResponseStream}.
17334
+ */
17335
+ export namespace chat {
17336
+ /**
17337
+ * Create a new {@link ChatParticipant chat participant} instance.
17338
+ *
17339
+ * @param id A unique identifier for the participant.
17340
+ * @param handler A request handler for the participant.
17341
+ * @returns A new chat participant
17342
+ * @stubbed
17343
+ */
17344
+ export function createChatParticipant(id: string, handler: ChatRequestHandler): ChatParticipant;
17345
+ }
17346
+
17347
+ /**
17348
+ * Represents the role of a chat message. This is either the user or the assistant.
17349
+ */
17350
+ export enum LanguageModelChatMessageRole {
17351
+ /**
17352
+ * The user role, e.g the human interacting with a language model.
17353
+ */
17354
+ User = 1,
17355
+
17356
+ /**
17357
+ * The assistant role, e.g. the language model generating responses.
17358
+ */
17359
+ Assistant = 2
17360
+ }
17361
+
17362
+ /**
17363
+ * Represents a message in a chat. Can assume different roles, like user or assistant.
17364
+ */
17365
+ export class LanguageModelChatMessage {
17366
+
17367
+ /**
17368
+ * Utility to create a new user message.
17369
+ *
17370
+ * @param content The content of the message.
17371
+ * @param name The optional name of a user for the message.
17372
+ */
17373
+ static User(content: string, name?: string): LanguageModelChatMessage;
17374
+
17375
+ /**
17376
+ * Utility to create a new assistant message.
17377
+ *
17378
+ * @param content The content of the message.
17379
+ * @param name The optional name of a user for the message.
17380
+ */
17381
+ static Assistant(content: string, name?: string): LanguageModelChatMessage;
17382
+
17383
+ /**
17384
+ * The role of this message.
17385
+ */
17386
+ role: LanguageModelChatMessageRole;
17387
+
17388
+ /**
17389
+ * The content of this message.
17390
+ */
17391
+ content: string;
17392
+
17393
+ /**
17394
+ * The optional name of a user for this message.
17395
+ */
17396
+ name: string | undefined;
17397
+
17398
+ /**
17399
+ * Create a new user message.
17400
+ *
17401
+ * @param role The role of the message.
17402
+ * @param content The content of the message.
17403
+ * @param name The optional name of a user for the message.
17404
+ */
17405
+ constructor(role: LanguageModelChatMessageRole, content: string, name?: string);
17406
+ }
17407
+
17408
+ /**
17409
+ * Represents a language model response.
17410
+ *
17411
+ * @see {@link LanguageModelAccess.chatRequest}
17412
+ */
17413
+ export interface LanguageModelChatResponse {
17414
+
17415
+ /**
17416
+ * An async iterable that is a stream of text chunks forming the overall response.
17417
+ *
17418
+ * *Note* that this stream will error when during data receiving an error occurs. Consumers of
17419
+ * the stream should handle the errors accordingly.
17420
+ *
17421
+ * To cancel the stream, the consumer can {@link CancellationTokenSource.cancel cancel} the token that was used to make the request
17422
+ * or break from the for-loop.
17423
+ *
17424
+ * @example
17425
+ * ```ts
17426
+ * try {
17427
+ * // consume stream
17428
+ * for await (const chunk of response.text) {
17429
+ * console.log(chunk);
17430
+ * }
17431
+ *
17432
+ * } catch(e) {
17433
+ * // stream ended with an error
17434
+ * console.error(e);
17435
+ * }
17436
+ * ```
17437
+ */
17438
+ text: AsyncIterable<string>;
17439
+ }
17440
+
17441
+ /**
17442
+ * Represents a language model for making chat requests.
17443
+ *
17444
+ * @see {@link lm.selectChatModels}
17445
+ */
17446
+ export interface LanguageModelChat {
17447
+
17448
+ /**
17449
+ * Human-readable name of the language model.
17450
+ */
17451
+ readonly name: string;
17452
+
17453
+ /**
17454
+ * Opaque identifier of the language model.
17455
+ */
17456
+ readonly id: string;
17457
+
17458
+ /**
17459
+ * A well-known identifier of the vendor of the language model. An example is `copilot`, but
17460
+ * values are defined by extensions contributing chat models and need to be looked up with them.
17461
+ */
17462
+ readonly vendor: string;
17463
+
17464
+ /**
17465
+ * Opaque family-name of the language model. Values might be `gpt-3.5-turbo`, `gpt4`, `phi2`, or `llama`
17466
+ * but they are defined by extensions contributing languages and subject to change.
17467
+ */
17468
+ readonly family: string;
17469
+
17470
+ /**
17471
+ * Opaque version string of the model. This is defined by the extension contributing the language model
17472
+ * and subject to change.
17473
+ */
17474
+ readonly version: string;
17475
+
17476
+ /**
17477
+ * The maximum number of tokens that can be sent to the model in a single request.
17478
+ */
17479
+ readonly maxInputTokens: number;
17480
+
17481
+ /**
17482
+ * Make a chat request using a language model.
17483
+ *
17484
+ * *Note* that language model use may be subject to access restrictions and user consent. Calling this function
17485
+ * for the first time (for a extension) will show a consent dialog to the user and because of that this function
17486
+ * must _only be called in response to a user action!_ Extension can use {@link LanguageModelAccessInformation.canSendRequest}
17487
+ * to check if they have the necessary permissions to make a request.
17488
+ *
17489
+ * This function will return a rejected promise if making a request to the language model is not
17490
+ * possible. Reasons for this can be:
17491
+ *
17492
+ * - user consent not given, see {@link LanguageModelError.NoPermissions `NoPermissions`}
17493
+ * - model does not exist anymore, see {@link LanguageModelError.NotFound `NotFound`}
17494
+ * - quota limits exceeded, see {@link LanguageModelError.Blocked `Blocked`}
17495
+ * - other issues in which case extension must check {@link LanguageModelError.cause `LanguageModelError.cause`}
17496
+ *
17497
+ * @param messages An array of message instances.
17498
+ * @param options Options that control the request.
17499
+ * @param token A cancellation token which controls the request. See {@link CancellationTokenSource} for how to create one.
17500
+ * @returns A thenable that resolves to a {@link LanguageModelChatResponse}. The promise will reject when the request couldn't be made.
17501
+ */
17502
+ sendRequest(messages: LanguageModelChatMessage[], options?: LanguageModelChatRequestOptions, token?: CancellationToken): Thenable<LanguageModelChatResponse>;
17503
+
17504
+ /**
17505
+ * Count the number of tokens in a message using the model specific tokenizer-logic.
17506
+ * @param text A string or a message instance.
17507
+ * @param token Optional cancellation token. See {@link CancellationTokenSource} for how to create one.
17508
+ * @returns A thenable that resolves to the number of tokens.
17509
+ */
17510
+ countTokens(text: string | LanguageModelChatMessage, token?: CancellationToken): Thenable<number>;
17511
+ }
17512
+
17513
+ /**
17514
+ * Describes how to select language models for chat requests.
17515
+ *
17516
+ * @see {@link lm.selectChatModels}
17517
+ */
17518
+ export interface LanguageModelChatSelector {
17519
+
17520
+ /**
17521
+ * A vendor of language models.
17522
+ * @see {@link LanguageModelChat.vendor}
17523
+ */
17524
+ vendor?: string;
17525
+
17526
+ /**
17527
+ * A family of language models.
17528
+ * @see {@link LanguageModelChat.family}
17529
+ */
17530
+ family?: string;
17531
+
17532
+ /**
17533
+ * The version of a language model.
17534
+ * @see {@link LanguageModelChat.version}
17535
+ */
17536
+ version?: string;
17537
+
17538
+ /**
17539
+ * The identifier of a language model.
17540
+ * @see {@link LanguageModelChat.id}
17541
+ */
17542
+ id?: string;
17543
+ }
17544
+
17545
+ /**
17546
+ * An error type for language model specific errors.
17547
+ *
17548
+ * Consumers of language models should check the code property to determine specific
17549
+ * failure causes, like `if(someError.code === vscode.LanguageModelError.NotFound.name) {...}`
17550
+ * for the case of referring to an unknown language model. For unspecified errors the `cause`-property
17551
+ * will contain the actual error.
17552
+ */
17553
+ export class LanguageModelError extends Error {
17554
+
17555
+ /**
17556
+ * The requestor does not have permissions to use this
17557
+ * language model
17558
+ */
17559
+ static NoPermissions(message?: string): LanguageModelError;
17560
+
17561
+ /**
17562
+ * The requestor is blocked from using this language model.
17563
+ */
17564
+ static Blocked(message?: string): LanguageModelError;
17565
+
17566
+ /**
17567
+ * The language model does not exist.
17568
+ */
17569
+ static NotFound(message?: string): LanguageModelError;
17570
+
17571
+ /**
17572
+ * A code that identifies this error.
17573
+ *
17574
+ * Possible values are names of errors, like {@linkcode LanguageModelError.NotFound NotFound},
17575
+ * or `Unknown` for unspecified errors from the language model itself. In the latter case the
17576
+ * `cause`-property will contain the actual error.
17577
+ */
17578
+ readonly code: string;
17579
+ }
17580
+
17581
+ /**
17582
+ * Options for making a chat request using a language model.
17583
+ *
17584
+ * @see {@link LanguageModelChat.sendRequest}
17585
+ */
17586
+ export interface LanguageModelChatRequestOptions {
17587
+
17588
+ /**
17589
+ * A human-readable message that explains why access to a language model is needed and what feature is enabled by it.
17590
+ */
17591
+ justification?: string;
17592
+
17593
+ /**
17594
+ * A set of options that control the behavior of the language model. These options are specific to the language model
17595
+ * and need to be lookup in the respective documentation.
17596
+ */
17597
+ modelOptions?: { [name: string]: any };
17598
+ }
17599
+
17600
+ /**
17601
+ * Namespace for language model related functionality.
17602
+ */
17603
+ export namespace lm {
17604
+
17605
+ /**
17606
+ * An event that is fired when the set of available chat models changes.
17607
+ * @stubbed
17608
+ */
17609
+ export const onDidChangeChatModels: Event<void>;
17610
+
17611
+ /**
17612
+ * Select chat models by a {@link LanguageModelChatSelector selector}. This can yield multiple or no chat models and
17613
+ * extensions must handle these cases, esp. when no chat model exists, gracefully.
17614
+ *
17615
+ * ```ts
17616
+ * const models = await vscode.lm.selectChatModels({ family: 'gpt-3.5-turbo' });
17617
+ * if (models.length > 0) {
17618
+ * const [first] = models;
17619
+ * const response = await first.sendRequest(...)
17620
+ * // ...
17621
+ * } else {
17622
+ * // NO chat models available
17623
+ * }
17624
+ * ```
17625
+ *
17626
+ * A selector can be written to broadly match all models of a given vendor or family, or it can narrowly select one model by ID.
17627
+ * Keep in mind that the available set of models will change over time, but also that prompts may perform differently in
17628
+ * different models.
17629
+ *
17630
+ * *Note* that extensions can hold on to the results returned by this function and use them later. However, when the
17631
+ * {@link onDidChangeChatModels}-event is fired the list of chat models might have changed and extensions should re-query.
17632
+ *
17633
+ * @param selector A chat model selector. When omitted all chat models are returned.
17634
+ * @returns An array of chat models, can be empty!
17635
+ * @stubbed
17636
+ */
17637
+ export function selectChatModels(selector?: LanguageModelChatSelector): Thenable<LanguageModelChat[]>;
17638
+ }
17639
+
17640
+ /**
17641
+ * Represents extension specific information about the access to language models.
17642
+ */
17643
+ export interface LanguageModelAccessInformation {
17644
+
17645
+ /**
17646
+ * An event that fires when access information changes.
17647
+ */
17648
+ onDidChange: Event<void>;
17649
+
17650
+ /**
17651
+ * Checks if a request can be made to a language model.
17652
+ *
17653
+ * *Note* that calling this function will not trigger a consent UI but just checks for a persisted state.
17654
+ *
17655
+ * @param chat A language model chat object.
17656
+ * @return `true` if a request can be made, `false` if not, `undefined` if the language
17657
+ * model does not exist or consent hasn't been asked for.
17658
+ */
17659
+ canSendRequest(chat: LanguageModelChat): boolean | undefined;
17660
+ }
17661
+
16732
17662
  /**
16733
17663
  * Thenable is a common denominator between ES6 promises, Q, jquery.Deferred, WinJS.Promise,
16734
17664
  * and others. This API makes no assumption about what promise library is being used which