@vscode/chat-lib 0.0.5-4 → 0.0.5-6
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/dist/src/_internal/extension/xtab/node/xtabProvider.d.ts.map +1 -1
- package/dist/src/_internal/extension/xtab/node/xtabProvider.js +1 -2
- package/dist/src/_internal/extension/xtab/node/xtabProvider.js.map +1 -1
- package/dist/src/_internal/platform/chat/common/commonTypes.d.ts +5 -1
- package/dist/src/_internal/platform/chat/common/commonTypes.d.ts.map +1 -1
- package/dist/src/_internal/platform/chat/common/commonTypes.js +4 -0
- package/dist/src/_internal/platform/chat/common/commonTypes.js.map +1 -1
- package/dist/src/_internal/platform/configuration/common/configurationService.d.ts +0 -1
- package/dist/src/_internal/platform/configuration/common/configurationService.d.ts.map +1 -1
- package/dist/src/_internal/platform/configuration/common/configurationService.js +0 -1
- package/dist/src/_internal/platform/configuration/common/configurationService.js.map +1 -1
- package/dist/src/_internal/platform/endpoint/common/endpointProvider.d.ts +1 -1
- package/dist/src/_internal/platform/endpoint/common/endpointProvider.d.ts.map +1 -1
- package/dist/src/_internal/platform/endpoint/node/responsesApi.d.ts +9 -0
- package/dist/src/_internal/platform/endpoint/node/responsesApi.d.ts.map +1 -1
- package/dist/src/_internal/platform/endpoint/node/responsesApi.js +18 -27
- package/dist/src/_internal/platform/endpoint/node/responsesApi.js.map +1 -1
- package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProviders.d.ts +4 -1
- package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProviders.d.ts.map +1 -1
- package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProviders.js +26 -0
- package/dist/src/_internal/platform/inlineEdits/common/statelessNextEditProviders.js.map +1 -1
- package/dist/src/_internal/platform/networking/common/networking.d.ts +2 -1
- package/dist/src/_internal/platform/networking/common/networking.d.ts.map +1 -1
- package/dist/src/_internal/platform/networking/common/networking.js.map +1 -1
- package/dist/src/_internal/platform/openai/node/fetch.js +2 -0
- package/dist/src/_internal/platform/openai/node/fetch.js.map +1 -1
- package/dist/src/_internal/platform/requestLogger/node/requestLogger.d.ts +5 -42
- package/dist/src/_internal/platform/requestLogger/node/requestLogger.d.ts.map +1 -1
- package/dist/src/_internal/platform/requestLogger/node/requestLogger.js +1 -40
- package/dist/src/_internal/platform/requestLogger/node/requestLogger.js.map +1 -1
- package/dist/src/package.json +9 -13
- package/package.json +1 -1
- package/dist/src/_internal/extension/inlineEdits/common/ghNearbyNesProvider.d.ts +0 -16
- package/dist/src/_internal/extension/inlineEdits/common/ghNearbyNesProvider.d.ts.map +0 -1
- package/dist/src/_internal/extension/inlineEdits/common/ghNearbyNesProvider.js +0 -147
- package/dist/src/_internal/extension/inlineEdits/common/ghNearbyNesProvider.js.map +0 -1
- package/dist/src/_internal/platform/nesFetch/common/completionsAPI.d.ts +0 -69
- package/dist/src/_internal/platform/nesFetch/common/completionsAPI.d.ts.map +0 -1
- package/dist/src/_internal/platform/nesFetch/common/completionsAPI.js +0 -23
- package/dist/src/_internal/platform/nesFetch/common/completionsAPI.js.map +0 -1
- package/dist/src/_internal/platform/nesFetch/common/completionsFetchService.d.ts +0 -80
- package/dist/src/_internal/platform/nesFetch/common/completionsFetchService.d.ts.map +0 -1
- package/dist/src/_internal/platform/nesFetch/common/completionsFetchService.js +0 -77
- package/dist/src/_internal/platform/nesFetch/common/completionsFetchService.js.map +0 -1
- package/dist/src/_internal/platform/nesFetch/common/responseStream.d.ts +0 -26
- package/dist/src/_internal/platform/nesFetch/common/responseStream.d.ts.map +0 -1
- package/dist/src/_internal/platform/nesFetch/common/responseStream.js +0 -125
- package/dist/src/_internal/platform/nesFetch/common/responseStream.js.map +0 -1
- package/dist/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.d.ts +0 -27
- package/dist/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.d.ts.map +0 -1
- package/dist/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.js +0 -222
- package/dist/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.js.map +0 -1
- package/dist/src/_internal/platform/nesFetch/node/streamTransformer.d.ts +0 -10
- package/dist/src/_internal/platform/nesFetch/node/streamTransformer.d.ts.map +0 -1
- package/dist/src/_internal/platform/nesFetch/node/streamTransformer.js +0 -86
- package/dist/src/_internal/platform/nesFetch/node/streamTransformer.js.map +0 -1
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ResponseStream = void 0;
|
|
8
|
-
const result_1 = require("../../../util/common/result");
|
|
9
|
-
const async_1 = require("../../../util/vs/base/common/async");
|
|
10
|
-
const objects_1 = require("../../../util/vs/base/common/objects");
|
|
11
|
-
const types_1 = require("../../../util/vs/base/common/types");
|
|
12
|
-
class ResponseStream {
|
|
13
|
-
constructor(stream) {
|
|
14
|
-
const tokensDeferredPromise = new async_1.DeferredPromise();
|
|
15
|
-
this.aggregatedStream = tokensDeferredPromise.p;
|
|
16
|
-
this.response = this.aggregatedStream.then((completions) => {
|
|
17
|
-
if (completions.isError()) {
|
|
18
|
-
return completions;
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
return result_1.Result.ok(ResponseStream.aggregateCompletionsStream(completions.val));
|
|
22
|
-
}
|
|
23
|
-
catch (err) {
|
|
24
|
-
return result_1.Result.error(err);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
this.stream = new async_1.AsyncIterableObject(async (emitter) => {
|
|
28
|
-
const completions = [];
|
|
29
|
-
let error;
|
|
30
|
-
try {
|
|
31
|
-
for await (const completion of stream) {
|
|
32
|
-
completions.push(completion);
|
|
33
|
-
emitter.emitOne(completion);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (e) {
|
|
37
|
-
if (e instanceof Error) {
|
|
38
|
-
error = e;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
error = new Error((0, objects_1.safeStringify)(e));
|
|
42
|
-
}
|
|
43
|
-
emitter.reject(e);
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
tokensDeferredPromise.complete(error ? result_1.Result.error(error) : result_1.Result.ok(completions));
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
static aggregateCompletionsStream(stream) {
|
|
51
|
-
let text = '';
|
|
52
|
-
let finishReason = null;
|
|
53
|
-
let aggregatedLogsProbs = null;
|
|
54
|
-
let aggregatedUsage = undefined;
|
|
55
|
-
for (const completion of stream) {
|
|
56
|
-
const choice = completion.choices[0]; // TODO@ulugbekna: we only support choice.index=0
|
|
57
|
-
text += choice.text ?? '';
|
|
58
|
-
if (choice.logprobs) {
|
|
59
|
-
if (aggregatedLogsProbs === null) {
|
|
60
|
-
aggregatedLogsProbs = {
|
|
61
|
-
tokens: [...choice.logprobs.tokens],
|
|
62
|
-
token_logprobs: [...choice.logprobs.token_logprobs],
|
|
63
|
-
text_offset: [...choice.logprobs.text_offset],
|
|
64
|
-
top_logprobs: [...choice.logprobs.top_logprobs],
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
aggregatedLogsProbs.tokens.push(...choice.logprobs.tokens);
|
|
69
|
-
aggregatedLogsProbs.token_logprobs.push(...choice.logprobs.token_logprobs);
|
|
70
|
-
aggregatedLogsProbs.text_offset.push(...choice.logprobs.text_offset);
|
|
71
|
-
aggregatedLogsProbs.top_logprobs.push(...choice.logprobs.top_logprobs);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (completion.usage) {
|
|
75
|
-
if (aggregatedUsage === undefined) {
|
|
76
|
-
aggregatedUsage = {
|
|
77
|
-
completion_tokens: completion.usage.completion_tokens,
|
|
78
|
-
prompt_tokens: completion.usage.prompt_tokens,
|
|
79
|
-
total_tokens: completion.usage.total_tokens,
|
|
80
|
-
completion_tokens_details: {
|
|
81
|
-
audio_tokens: completion.usage.completion_tokens_details.audio_tokens,
|
|
82
|
-
reasoning_tokens: completion.usage.completion_tokens_details.reasoning_tokens,
|
|
83
|
-
},
|
|
84
|
-
prompt_tokens_details: {
|
|
85
|
-
audio_tokens: completion.usage.prompt_tokens_details.audio_tokens,
|
|
86
|
-
reasoning_tokens: completion.usage.prompt_tokens_details.reasoning_tokens,
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
aggregatedUsage.completion_tokens += completion.usage.completion_tokens;
|
|
92
|
-
aggregatedUsage.prompt_tokens += completion.usage.prompt_tokens;
|
|
93
|
-
aggregatedUsage.total_tokens += completion.usage.total_tokens;
|
|
94
|
-
aggregatedUsage.completion_tokens_details.audio_tokens += completion.usage.completion_tokens_details.audio_tokens;
|
|
95
|
-
aggregatedUsage.completion_tokens_details.reasoning_tokens += completion.usage.completion_tokens_details.reasoning_tokens;
|
|
96
|
-
aggregatedUsage.prompt_tokens_details.audio_tokens += completion.usage.prompt_tokens_details.audio_tokens;
|
|
97
|
-
aggregatedUsage.prompt_tokens_details.reasoning_tokens += completion.usage.prompt_tokens_details.reasoning_tokens;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (choice.finish_reason) {
|
|
101
|
-
(0, types_1.assertType)(finishReason === null, 'cannot already have finishReason if just seeing choice.finish_reason');
|
|
102
|
-
finishReason = choice.finish_reason;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (stream.length === 0) {
|
|
106
|
-
throw new Error(`Response is empty!`);
|
|
107
|
-
}
|
|
108
|
-
const completion = stream[0];
|
|
109
|
-
const choice = {
|
|
110
|
-
index: 0,
|
|
111
|
-
finish_reason: finishReason,
|
|
112
|
-
logprobs: aggregatedLogsProbs,
|
|
113
|
-
text,
|
|
114
|
-
};
|
|
115
|
-
const aggregatedCompletion = {
|
|
116
|
-
choices: [choice],
|
|
117
|
-
system_fingerprint: completion.system_fingerprint,
|
|
118
|
-
object: completion.object,
|
|
119
|
-
usage: aggregatedUsage,
|
|
120
|
-
};
|
|
121
|
-
return aggregatedCompletion;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.ResponseStream = ResponseStream;
|
|
125
|
-
//# sourceMappingURL=responseStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"responseStream.js","sourceRoot":"","sources":["../../../../../../src/_internal/platform/nesFetch/common/responseStream.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,wDAAqD;AACrD,8DAA0F;AAC1F,kEAAqE;AACrE,8DAAgE;AAGhE,MAAa,cAAc;IAsB1B,YAAY,MAAiC;QAC5C,MAAM,qBAAqB,GAAG,IAAI,uBAAe,EAA+B,CAAC;QACjF,IAAI,CAAC,gBAAgB,GAAG,qBAAqB,CAAC,CAAC,CAAC;QAChD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;YAC1D,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;gBAC3B,OAAO,WAAW,CAAC;YACpB,CAAC;YACD,IAAI,CAAC;gBACJ,OAAO,eAAM,CAAC,EAAE,CAAC,cAAc,CAAC,0BAA0B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9E,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,OAAO,eAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC1B,CAAC;QACF,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,IAAI,2BAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;YACvD,MAAM,WAAW,GAAiB,EAAE,CAAC;YACrC,IAAI,KAAwB,CAAC;YAC7B,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B,kBAAkB,EAAE,UAAU,CAAC,kBAAkB;YACjD,MAAM,EAAE,UAAU,CAAC,MAAM;YACzB,KAAK,EAAE,eAAe;SACtB,CAAC;QAEF,OAAO,oBAAoB,CAAC;IAC7B,CAAC;CACD;AA3ID,wCA2IC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Result } from '../../../util/common/result';
|
|
2
|
-
import { AsyncIterableObject } from '../../../util/vs/base/common/async';
|
|
3
|
-
import { CancellationToken } from '../../../util/vs/base/common/cancellation';
|
|
4
|
-
import { IAuthenticationService } from '../../authentication/common/authentication';
|
|
5
|
-
import { IFetcherService } from '../../networking/common/fetcherService';
|
|
6
|
-
import { CompletionsFetchFailure, FetchOptions, ICompletionsFetchService, ModelParams } from '../common/completionsFetchService';
|
|
7
|
-
import { ResponseStream } from '../common/responseStream';
|
|
8
|
-
export type FetchResponse = {
|
|
9
|
-
status: number;
|
|
10
|
-
statusText: string;
|
|
11
|
-
headers: {
|
|
12
|
-
[name: string]: string;
|
|
13
|
-
};
|
|
14
|
-
body: AsyncIterableObject<string>;
|
|
15
|
-
};
|
|
16
|
-
export interface IFetchRequestParams extends ModelParams {
|
|
17
|
-
}
|
|
18
|
-
export declare class CompletionsFetchService implements ICompletionsFetchService {
|
|
19
|
-
private authService;
|
|
20
|
-
private fetcherService;
|
|
21
|
-
readonly _serviceBrand: undefined;
|
|
22
|
-
constructor(authService: IAuthenticationService, fetcherService: IFetcherService);
|
|
23
|
-
fetch(url: string, secretKey: string, params: IFetchRequestParams, requestId: string, ct: CancellationToken, headerOverrides?: Record<string, string>): Promise<Result<ResponseStream, CompletionsFetchFailure>>;
|
|
24
|
-
protected _fetchFromUrl(url: string, options: FetchOptions, ct: CancellationToken): Promise<Result<FetchResponse, CompletionsFetchFailure>>;
|
|
25
|
-
private getHeaders;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=completionsFetchServiceImpl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"completionsFetchServiceImpl.d.ts","sourceRoot":"","sources":["../../../../../../src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAE9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AACpF,OAAO,EAAE,eAAe,EAAY,MAAM,wCAAwC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AACjI,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,MAAM,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACpC,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,WAAW,mBAAoB,SAAQ,WAAW;CAAI;AAE5D,qBAAa,uBAAwB,YAAW,wBAAwB;IAI9C,OAAO,CAAC,WAAW;IAC1B,OAAO,CAAC,cAAc;IAJxC,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC;gBAGD,WAAW,EAAE,sBAAsB,EAC1C,cAAc,EAAE,eAAe;IAI5C,KAAK,CACjB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,mBAAmB,EAC3B,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,iBAAiB,EACrB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,uBAAuB,CAAC,CAAC;cAgE3C,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC;IAyGjJ,OAAO,CAAC,UAAU;CAgBlB"}
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
23
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
-
};
|
|
28
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
-
var ownKeys = function(o) {
|
|
30
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
-
var ar = [];
|
|
32
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
-
return ar;
|
|
34
|
-
};
|
|
35
|
-
return ownKeys(o);
|
|
36
|
-
};
|
|
37
|
-
return function (mod) {
|
|
38
|
-
if (mod && mod.__esModule) return mod;
|
|
39
|
-
var result = {};
|
|
40
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
-
__setModuleDefault(result, mod);
|
|
42
|
-
return result;
|
|
43
|
-
};
|
|
44
|
-
})();
|
|
45
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
46
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
47
|
-
};
|
|
48
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
-
exports.CompletionsFetchService = void 0;
|
|
50
|
-
const stream_1 = require("stream");
|
|
51
|
-
const stream_consumers = __importStar(require("stream/consumers"));
|
|
52
|
-
const result_1 = require("../../../util/common/result");
|
|
53
|
-
const async_1 = require("../../../util/vs/base/common/async");
|
|
54
|
-
const objects_1 = require("../../../util/vs/base/common/objects");
|
|
55
|
-
const authentication_1 = require("../../authentication/common/authentication");
|
|
56
|
-
const fetcherService_1 = require("../../networking/common/fetcherService");
|
|
57
|
-
const responseStream_1 = require("../common/responseStream");
|
|
58
|
-
const streamTransformer_1 = require("./streamTransformer");
|
|
59
|
-
let CompletionsFetchService = class CompletionsFetchService {
|
|
60
|
-
constructor(authService, fetcherService) {
|
|
61
|
-
this.authService = authService;
|
|
62
|
-
this.fetcherService = fetcherService;
|
|
63
|
-
}
|
|
64
|
-
async fetch(url, secretKey, params, requestId, ct, headerOverrides) {
|
|
65
|
-
if (ct.isCancellationRequested) {
|
|
66
|
-
return result_1.Result.error({ kind: 'cancelled' });
|
|
67
|
-
}
|
|
68
|
-
const options = {
|
|
69
|
-
requestId,
|
|
70
|
-
headers: this.getHeaders(requestId, secretKey, headerOverrides),
|
|
71
|
-
body: {
|
|
72
|
-
...params,
|
|
73
|
-
stream: true,
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const fetchResponse = await this._fetchFromUrl(url, options, ct);
|
|
77
|
-
if (fetchResponse.isError()) {
|
|
78
|
-
return fetchResponse;
|
|
79
|
-
}
|
|
80
|
-
if (fetchResponse.val.status === 200) {
|
|
81
|
-
const jsonlStream = (0, streamTransformer_1.streamToLines)(fetchResponse.val.body);
|
|
82
|
-
const completionsStream = (0, streamTransformer_1.jsonlStreamToCompletions)(jsonlStream);
|
|
83
|
-
const completions = completionsStream.map(completion => {
|
|
84
|
-
return {
|
|
85
|
-
...completion,
|
|
86
|
-
choices: completion.choices.filter(choice => choice.index === 0),
|
|
87
|
-
};
|
|
88
|
-
}).filter(c => {
|
|
89
|
-
return c.choices.length > 0;
|
|
90
|
-
}); // we only support `n=1`, so we only get choice.index = 0
|
|
91
|
-
const response = new responseStream_1.ResponseStream(completions);
|
|
92
|
-
return result_1.Result.ok(response);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const body = await stream_consumers.text(fetchResponse.val.body);
|
|
96
|
-
if (body.match(/This model's maximum context length is /)) {
|
|
97
|
-
return result_1.Result.error({ kind: 'context-window-exceeded', message: body });
|
|
98
|
-
}
|
|
99
|
-
if (body.match(/Access denied due to invalid subscription key or wrong API endpoint/) || fetchResponse.val.status === 401 || fetchResponse.val.status === 403) {
|
|
100
|
-
return result_1.Result.error({ kind: 'invalid-api-key', message: body });
|
|
101
|
-
}
|
|
102
|
-
if (body.match(/exceeded call rate limit/)) {
|
|
103
|
-
return result_1.Result.error({ kind: 'exceeded-rate-limit', message: body });
|
|
104
|
-
}
|
|
105
|
-
const error = {
|
|
106
|
-
kind: 'not-200-status',
|
|
107
|
-
status: fetchResponse.val.status,
|
|
108
|
-
statusText: fetchResponse.val.statusText,
|
|
109
|
-
};
|
|
110
|
-
return result_1.Result.error(error);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async _fetchFromUrl(url, options, ct) {
|
|
114
|
-
const fetchAbortCtl = this.fetcherService.makeAbortController();
|
|
115
|
-
const onCancellationDisposable = ct.onCancellationRequested(() => {
|
|
116
|
-
fetchAbortCtl.abort();
|
|
117
|
-
});
|
|
118
|
-
try {
|
|
119
|
-
const response = await this.fetcherService.fetch(url, {
|
|
120
|
-
headers: options.headers,
|
|
121
|
-
json: options.body,
|
|
122
|
-
signal: fetchAbortCtl.signal,
|
|
123
|
-
method: 'POST',
|
|
124
|
-
});
|
|
125
|
-
if (response.status === 200 && this.authService.copilotToken?.isFreeUser && this.authService.copilotToken?.isChatQuotaExceeded) {
|
|
126
|
-
this.authService.resetCopilotToken();
|
|
127
|
-
}
|
|
128
|
-
if (response.status !== 200) {
|
|
129
|
-
if (response.status === 402) {
|
|
130
|
-
// When we receive a 402, we have exceed the free tier quota
|
|
131
|
-
// This is stored on the token so let's refresh it
|
|
132
|
-
this.authService.resetCopilotToken(response.status);
|
|
133
|
-
return result_1.Result.error({ kind: 'quota-exceeded' });
|
|
134
|
-
}
|
|
135
|
-
const error = {
|
|
136
|
-
kind: 'not-200-status',
|
|
137
|
-
status: response.status,
|
|
138
|
-
statusText: response.statusText,
|
|
139
|
-
};
|
|
140
|
-
return result_1.Result.error(error);
|
|
141
|
-
}
|
|
142
|
-
const responseBody = await response.body();
|
|
143
|
-
const body = (responseBody instanceof stream_1.Readable
|
|
144
|
-
? responseBody
|
|
145
|
-
: (responseBody
|
|
146
|
-
? new stream_1.Readable().wrap(responseBody)
|
|
147
|
-
: new stream_1.Readable()));
|
|
148
|
-
body.setEncoding('utf8');
|
|
149
|
-
const responseStream = new async_1.AsyncIterableObject(async (emitter) => {
|
|
150
|
-
try {
|
|
151
|
-
for await (const str of body) {
|
|
152
|
-
emitter.emitOne(str);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
catch (err) {
|
|
156
|
-
if (!(err instanceof Error)) {
|
|
157
|
-
throw new Error((0, objects_1.safeStringify)(err));
|
|
158
|
-
}
|
|
159
|
-
if (this.fetcherService.isAbortError(err) || err.name === 'AbortError') {
|
|
160
|
-
// stream aborted - ignore
|
|
161
|
-
}
|
|
162
|
-
else if (err.message === 'ERR_HTTP2_STREAM_ERROR' ||
|
|
163
|
-
err.code === 'ERR_HTTP2_STREAM_ERROR') {
|
|
164
|
-
// stream closed - ignore
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
throw err;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
finally {
|
|
171
|
-
onCancellationDisposable.dispose();
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
return result_1.Result.ok({
|
|
175
|
-
status: response.status,
|
|
176
|
-
statusText: response.statusText,
|
|
177
|
-
headers: headersObjectToKv(response.headers),
|
|
178
|
-
body: responseStream,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
catch (reason) { // TODO: replace with unknown with proper error handling
|
|
182
|
-
onCancellationDisposable.dispose();
|
|
183
|
-
if (reason instanceof Error && reason.message === 'This operation was aborted') {
|
|
184
|
-
return result_1.Result.error({ kind: 'cancelled', errorMessage: reason.message });
|
|
185
|
-
}
|
|
186
|
-
if (reason.code === 'ECONNRESET' ||
|
|
187
|
-
reason.code === 'ETIMEDOUT' ||
|
|
188
|
-
reason.code === 'ERR_HTTP2_INVALID_SESSION' ||
|
|
189
|
-
reason.message === 'ERR_HTTP2_GOAWAY_SESSION' ||
|
|
190
|
-
reason.code === '429') {
|
|
191
|
-
return result_1.Result.error({ kind: 'model_overloaded', errorMessage: reason.message });
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
return result_1.Result.error({ kind: 'model_error', errorMessage: reason.message });
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
getHeaders(requestId, secretKey, headerOverrides = {}) {
|
|
199
|
-
const headers = {
|
|
200
|
-
'Content-Type': 'application/json',
|
|
201
|
-
'x-policy-id': 'nil',
|
|
202
|
-
Authorization: 'Bearer ' + secretKey,
|
|
203
|
-
'X-Request-Id': requestId,
|
|
204
|
-
'X-GitHub-Api-Version': '2025-04-01',
|
|
205
|
-
...headerOverrides,
|
|
206
|
-
};
|
|
207
|
-
return headers;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
exports.CompletionsFetchService = CompletionsFetchService;
|
|
211
|
-
exports.CompletionsFetchService = CompletionsFetchService = __decorate([
|
|
212
|
-
__param(0, authentication_1.IAuthenticationService),
|
|
213
|
-
__param(1, fetcherService_1.IFetcherService)
|
|
214
|
-
], CompletionsFetchService);
|
|
215
|
-
function headersObjectToKv(headers) {
|
|
216
|
-
const result = {};
|
|
217
|
-
for (const [name, value] of headers) {
|
|
218
|
-
result[name] = value;
|
|
219
|
-
}
|
|
220
|
-
return result;
|
|
221
|
-
}
|
|
222
|
-
//# sourceMappingURL=completionsFetchServiceImpl.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"completionsFetchServiceImpl.js","sourceRoot":"","sources":["../../../../../../src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEhG,mCAAkC;AAClC,mEAAqD;AACrD,wDAAqD;AACrD,8DAAyE;AAEzE,kEAAqE;AACrE,+EAAoF;AACpF,2EAAmF;AAEnF,6DAA0D;AAC1D,2DAA8E;AAWvE,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAGnC,YACiC,WAAmC,EAC1C,cAA+B;QADxB,gBAA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Y,0DAAuB;kCAAvB,uBAAuB;IAIjC,WAAA,uCAAsB,CAAA;IACtB,WAAA,gCAAe,CAAA;GALL,uBAAuB,CAyMnC;AAED,SAAS,iBAAiB,CAAC,OAAiB;IAC3C,MAAM,MAAM,GAA+B,EAAE,CAAC;IAC9C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACrC,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AsyncIterableObject } from '../../../util/vs/base/common/async';
|
|
2
|
-
import { Completion } from '../common/completionsAPI';
|
|
3
|
-
/**
|
|
4
|
-
* Transforms a stream of strings into a stream of lines.
|
|
5
|
-
*
|
|
6
|
-
* Listener should handle the errors coming from the input stream.
|
|
7
|
-
*/
|
|
8
|
-
export declare function streamToLines(stream: AsyncIterableObject<string>): AsyncIterableObject<string>;
|
|
9
|
-
export declare function jsonlStreamToCompletions(jsonlStream: AsyncIterableObject<string>): AsyncIterableObject<Completion>;
|
|
10
|
-
//# sourceMappingURL=streamTransformer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streamTransformer.d.ts","sourceRoot":"","sources":["../../../../../../src/_internal/platform/nesFetch/node/streamTransformer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAyB9F;AAED,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG,mBAAmB,CAAC,UAAU,CAAC,CA2BlH"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.streamToLines = streamToLines;
|
|
8
|
-
exports.jsonlStreamToCompletions = jsonlStreamToCompletions;
|
|
9
|
-
const async_1 = require("../../../util/vs/base/common/async");
|
|
10
|
-
/**
|
|
11
|
-
* Transforms a stream of strings into a stream of lines.
|
|
12
|
-
*
|
|
13
|
-
* Listener should handle the errors coming from the input stream.
|
|
14
|
-
*/
|
|
15
|
-
function streamToLines(stream) {
|
|
16
|
-
return new async_1.AsyncIterableObject(async (emitter) => {
|
|
17
|
-
let buffer = '';
|
|
18
|
-
for await (const str of stream) {
|
|
19
|
-
buffer += str;
|
|
20
|
-
do {
|
|
21
|
-
const newlineIndex = buffer.indexOf('\n');
|
|
22
|
-
if (newlineIndex === -1) {
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
// take the first line
|
|
26
|
-
const line = buffer.substring(0, newlineIndex);
|
|
27
|
-
buffer = buffer.substring(newlineIndex + 1);
|
|
28
|
-
emitter.emitOne(line);
|
|
29
|
-
} while (true);
|
|
30
|
-
}
|
|
31
|
-
if (buffer.length > 0) {
|
|
32
|
-
// last line which doesn't end with \n
|
|
33
|
-
emitter.emitOne(buffer);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
function jsonlStreamToCompletions(jsonlStream) {
|
|
38
|
-
return new async_1.AsyncIterableObject(async (emitter) => {
|
|
39
|
-
for await (const line of jsonlStream) {
|
|
40
|
-
if (line.trim() === 'data: [DONE]') {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (line.startsWith('data: ')) {
|
|
44
|
-
try {
|
|
45
|
-
const message = JSON.parse(line.substring('data: '.length));
|
|
46
|
-
if (message.error) {
|
|
47
|
-
emitter.reject(new Error(message.error.message));
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
emitter.emitOne(message);
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
emitter.reject(err);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
// function replaceBytes(s: string): string {
|
|
61
|
-
// if (!s.startsWith('bytes:')) {
|
|
62
|
-
// return s;
|
|
63
|
-
// }
|
|
64
|
-
// const bytes: number[] = [];
|
|
65
|
-
// let i = 'bytes:'.length;
|
|
66
|
-
// const textEncoder = new TextEncoder();
|
|
67
|
-
// while (i < s.length) {
|
|
68
|
-
// if (s.slice(i, i + 3) === '\\\\x') {
|
|
69
|
-
// bytes.push(parseInt(s.slice(i + 3, i + 5), 16));
|
|
70
|
-
// i += 5;
|
|
71
|
-
// } else if (s.slice(i, i + 2) === '\\x') {
|
|
72
|
-
// bytes.push(parseInt(s.slice(i + 2, i + 4), 16));
|
|
73
|
-
// i += 4;
|
|
74
|
-
// } else {
|
|
75
|
-
// const encoded = textEncoder.encode(s.slice(i, i + 1));
|
|
76
|
-
// for (const b of encoded) {
|
|
77
|
-
// bytes.push(b);
|
|
78
|
-
// }
|
|
79
|
-
// i += 1;
|
|
80
|
-
// }
|
|
81
|
-
// }
|
|
82
|
-
// return new TextDecoder('utf8', { fatal: false }).decode(
|
|
83
|
-
// new Uint8Array(bytes)
|
|
84
|
-
// );
|
|
85
|
-
// }
|
|
86
|
-
//# sourceMappingURL=streamTransformer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streamTransformer.js","sourceRoot":"","sources":["../../../../../../src/_internal/platform/nesFetch/node/streamTransformer.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;AAUhG,sCAyBC;AAED,4DA2BC;AA9DD,8DAA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