feat: Agent update backend FIM completion api. (#218)
parent
1aaf29c968
commit
c82cc38e9d
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -35,39 +35,23 @@ declare class CancelablePromise<T> implements Promise<T> {
|
||||||
get isCancelled(): boolean;
|
get isCancelled(): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* An enumeration.
|
|
||||||
*/
|
|
||||||
declare enum EventType {
|
|
||||||
COMPLETION = "completion",
|
|
||||||
VIEW = "view",
|
|
||||||
SELECT = "select"
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChoiceEvent = {
|
|
||||||
type: EventType;
|
|
||||||
completion_id: string;
|
|
||||||
choice_index: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Choice = {
|
type Choice = {
|
||||||
index: number;
|
index: number;
|
||||||
text: string;
|
text: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type CompletionEvent = {
|
type CompletionResponse$1 = {
|
||||||
type: EventType;
|
|
||||||
id: string;
|
id: string;
|
||||||
language: string;
|
|
||||||
prompt: string;
|
|
||||||
created: number;
|
|
||||||
choices: Array<Choice>;
|
choices: Array<Choice>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type CompletionResponse$1 = {
|
type LogEventRequest$1 = {
|
||||||
id: string;
|
/**
|
||||||
created: number;
|
* Event type, should be `view` or `select`.
|
||||||
choices: Array<Choice>;
|
*/
|
||||||
|
type: string;
|
||||||
|
completion_id: string;
|
||||||
|
choice_index: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ApiResult = {
|
type ApiResult = {
|
||||||
|
|
@ -87,16 +71,6 @@ declare class ApiError extends Error {
|
||||||
constructor(request: ApiRequestOptions, response: ApiResult, message: string);
|
constructor(request: ApiRequestOptions, response: ApiResult, message: string);
|
||||||
}
|
}
|
||||||
|
|
||||||
type ValidationError = {
|
|
||||||
loc: Array<(string | number)>;
|
|
||||||
msg: string;
|
|
||||||
type: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type HTTPValidationError = {
|
|
||||||
detail?: Array<ValidationError>;
|
|
||||||
};
|
|
||||||
|
|
||||||
type AgentConfig = {
|
type AgentConfig = {
|
||||||
server?: {
|
server?: {
|
||||||
endpoint?: string;
|
endpoint?: string;
|
||||||
|
|
@ -120,13 +94,14 @@ type CompletionRequest = {
|
||||||
position: number;
|
position: number;
|
||||||
};
|
};
|
||||||
type CompletionResponse = CompletionResponse$1;
|
type CompletionResponse = CompletionResponse$1;
|
||||||
|
type LogEventRequest = LogEventRequest$1;
|
||||||
interface AgentFunction {
|
interface AgentFunction {
|
||||||
initialize(options?: AgentInitOptions): boolean;
|
initialize(options?: AgentInitOptions): boolean;
|
||||||
updateConfig(config: AgentConfig): boolean;
|
updateConfig(config: AgentConfig): boolean;
|
||||||
getConfig(): AgentConfig;
|
getConfig(): AgentConfig;
|
||||||
getStatus(): "connecting" | "ready" | "disconnected";
|
getStatus(): "connecting" | "ready" | "disconnected";
|
||||||
getCompletions(request: CompletionRequest): CancelablePromise<CompletionResponse>;
|
getCompletions(request: CompletionRequest): CancelablePromise<CompletionResponse>;
|
||||||
postEvent(event: ChoiceEvent | CompletionEvent): CancelablePromise<boolean>;
|
postEvent(event: LogEventRequest): CancelablePromise<boolean>;
|
||||||
}
|
}
|
||||||
type StatusChangedEvent = {
|
type StatusChangedEvent = {
|
||||||
event: "statusChanged";
|
event: "statusChanged";
|
||||||
|
|
@ -154,13 +129,13 @@ declare class TabbyAgent extends EventEmitter implements Agent {
|
||||||
private changeStatus;
|
private changeStatus;
|
||||||
private ping;
|
private ping;
|
||||||
private callApi;
|
private callApi;
|
||||||
private createPrompt;
|
private createSegments;
|
||||||
initialize(params: AgentInitOptions): boolean;
|
initialize(params: AgentInitOptions): boolean;
|
||||||
updateConfig(config: AgentConfig): boolean;
|
updateConfig(config: AgentConfig): boolean;
|
||||||
getConfig(): AgentConfig;
|
getConfig(): AgentConfig;
|
||||||
getStatus(): "connecting" | "ready" | "disconnected";
|
getStatus(): "connecting" | "ready" | "disconnected";
|
||||||
getCompletions(request: CompletionRequest): CancelablePromise<CompletionResponse>;
|
getCompletions(request: CompletionRequest): CancelablePromise<CompletionResponse>;
|
||||||
postEvent(request: ChoiceEvent | CompletionEvent): CancelablePromise<boolean>;
|
postEvent(request: LogEventRequest): CancelablePromise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Agent, AgentConfig, AgentEvent, AgentFunction, ApiError, CancelError, CancelablePromise, Choice, ChoiceEvent, CompletionEvent, CompletionRequest, CompletionResponse, EventType, HTTPValidationError, StatusChangedEvent, TabbyAgent, ValidationError, agentEventNames };
|
export { Agent, AgentConfig, AgentEvent, AgentFunction, ApiError, CancelError, CancelablePromise, Choice, CompletionRequest, CompletionResponse, StatusChangedEvent, TabbyAgent, agentEventNames };
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -50,7 +50,6 @@ __export(src_exports, {
|
||||||
ApiError: () => ApiError,
|
ApiError: () => ApiError,
|
||||||
CancelError: () => CancelError,
|
CancelError: () => CancelError,
|
||||||
CancelablePromise: () => CancelablePromise,
|
CancelablePromise: () => CancelablePromise,
|
||||||
EventType: () => EventType,
|
|
||||||
TabbyAgent: () => TabbyAgent,
|
TabbyAgent: () => TabbyAgent,
|
||||||
agentEventNames: () => agentEventNames
|
agentEventNames: () => agentEventNames
|
||||||
});
|
});
|
||||||
|
|
@ -425,42 +424,40 @@ var AxiosHttpRequest = class extends BaseHttpRequest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// src/generated/services/DefaultService.ts
|
// src/generated/services/V1Service.ts
|
||||||
var DefaultService = class {
|
var V1Service = class {
|
||||||
constructor(httpRequest) {
|
constructor(httpRequest) {
|
||||||
this.httpRequest = httpRequest;
|
this.httpRequest = httpRequest;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Completions
|
|
||||||
* @param requestBody
|
* @param requestBody
|
||||||
* @returns CompletionResponse Successful Response
|
* @returns CompletionResponse Success
|
||||||
* @throws ApiError
|
* @throws ApiError
|
||||||
*/
|
*/
|
||||||
completionsV1CompletionsPost(requestBody) {
|
completion(requestBody) {
|
||||||
return this.httpRequest.request({
|
return this.httpRequest.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/v1/completions",
|
url: "/v1/completions",
|
||||||
body: requestBody,
|
body: requestBody,
|
||||||
mediaType: "application/json",
|
mediaType: "application/json",
|
||||||
errors: {
|
errors: {
|
||||||
422: `Validation Error`
|
400: `Bad Request`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Events
|
|
||||||
* @param requestBody
|
* @param requestBody
|
||||||
* @returns any Successful Response
|
* @returns any Success
|
||||||
* @throws ApiError
|
* @throws ApiError
|
||||||
*/
|
*/
|
||||||
eventsV1EventsPost(requestBody) {
|
event(requestBody) {
|
||||||
return this.httpRequest.request({
|
return this.httpRequest.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/v1/events",
|
url: "/v1/events",
|
||||||
body: requestBody,
|
body: requestBody,
|
||||||
mediaType: "application/json",
|
mediaType: "application/json",
|
||||||
errors: {
|
errors: {
|
||||||
422: `Validation Error`
|
400: `Bad Request`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -470,7 +467,7 @@ var DefaultService = class {
|
||||||
var TabbyApi = class {
|
var TabbyApi = class {
|
||||||
constructor(config, HttpRequest = AxiosHttpRequest) {
|
constructor(config, HttpRequest = AxiosHttpRequest) {
|
||||||
this.request = new HttpRequest({
|
this.request = new HttpRequest({
|
||||||
BASE: config?.BASE ?? "",
|
BASE: config?.BASE ?? "https://app.tabbyml.com/api/workspace/tabbyml/tabby",
|
||||||
VERSION: config?.VERSION ?? "0.1.0",
|
VERSION: config?.VERSION ?? "0.1.0",
|
||||||
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
|
WITH_CREDENTIALS: config?.WITH_CREDENTIALS ?? false,
|
||||||
CREDENTIALS: config?.CREDENTIALS ?? "include",
|
CREDENTIALS: config?.CREDENTIALS ?? "include",
|
||||||
|
|
@ -480,18 +477,10 @@ var TabbyApi = class {
|
||||||
HEADERS: config?.HEADERS,
|
HEADERS: config?.HEADERS,
|
||||||
ENCODE_PATH: config?.ENCODE_PATH
|
ENCODE_PATH: config?.ENCODE_PATH
|
||||||
});
|
});
|
||||||
this.default = new DefaultService(this.request);
|
this.v1 = new V1Service(this.request);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// src/generated/models/EventType.ts
|
|
||||||
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
||||||
EventType2["COMPLETION"] = "completion";
|
|
||||||
EventType2["VIEW"] = "view";
|
|
||||||
EventType2["SELECT"] = "select";
|
|
||||||
return EventType2;
|
|
||||||
})(EventType || {});
|
|
||||||
|
|
||||||
// src/utils.ts
|
// src/utils.ts
|
||||||
function sleep(milliseconds) {
|
function sleep(milliseconds) {
|
||||||
return new Promise((r) => setTimeout(r, milliseconds));
|
return new Promise((r) => setTimeout(r, milliseconds));
|
||||||
|
|
@ -711,12 +700,15 @@ var TabbyAgent = class extends import_events.EventEmitter {
|
||||||
}
|
}
|
||||||
callApi(api, request2) {
|
callApi(api, request2) {
|
||||||
this.logger.debug({ api: api.name, request: request2 }, "API request");
|
this.logger.debug({ api: api.name, request: request2 }, "API request");
|
||||||
const promise = api.call(this.api.default, request2);
|
const promise = api.call(this.api.v1, request2);
|
||||||
return cancelable(
|
return cancelable(
|
||||||
promise.then((response) => {
|
promise.then((response) => {
|
||||||
this.logger.debug({ api: api.name, response }, "API response");
|
this.logger.debug({ api: api.name, response }, "API response");
|
||||||
this.changeStatus("ready");
|
this.changeStatus("ready");
|
||||||
return response;
|
return response;
|
||||||
|
}).catch((error) => {
|
||||||
|
this.logger.debug({ api: api.name }, "API request canceled");
|
||||||
|
throw error;
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.logger.error({ api: api.name, error }, "API error");
|
this.logger.error({ api: api.name, error }, "API error");
|
||||||
this.changeStatus("disconnected");
|
this.changeStatus("disconnected");
|
||||||
|
|
@ -727,13 +719,16 @@ var TabbyAgent = class extends import_events.EventEmitter {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
createPrompt(request2) {
|
createSegments(request2) {
|
||||||
const maxLines = 20;
|
const maxLines = 20;
|
||||||
const prefix = request2.text.slice(0, request2.position);
|
const prefix = request2.text.slice(0, request2.position);
|
||||||
const lines = splitLines(prefix);
|
const prefixLines = splitLines(prefix);
|
||||||
const cutoff = Math.max(lines.length - maxLines, 0);
|
const suffix = request2.text.slice(request2.position);
|
||||||
const prompt = lines.slice(cutoff).join("");
|
const suffixLines = splitLines(suffix);
|
||||||
return prompt;
|
return {
|
||||||
|
prefix: prefixLines.slice(Math.max(prefixLines.length - maxLines, 0)).join(""),
|
||||||
|
suffix: suffixLines.slice(0, maxLines).join("")
|
||||||
|
};
|
||||||
}
|
}
|
||||||
initialize(params) {
|
initialize(params) {
|
||||||
if (params.config) {
|
if (params.config) {
|
||||||
|
|
@ -769,20 +764,19 @@ var TabbyAgent = class extends import_events.EventEmitter {
|
||||||
resolve2(this.completionCache.get(request2));
|
resolve2(this.completionCache.get(request2));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const prompt = this.createPrompt(request2);
|
const segments = this.createSegments(request2);
|
||||||
if (isBlank(prompt)) {
|
if (isBlank(segments.prefix)) {
|
||||||
this.logger.debug("Prompt is blank, returning empty completion response");
|
this.logger.debug("Segment prefix is blank, returning empty completion response");
|
||||||
return new CancelablePromise((resolve2) => {
|
return new CancelablePromise((resolve2) => {
|
||||||
resolve2({
|
resolve2({
|
||||||
id: "agent-" + (0, import_uuid.v4)(),
|
id: "agent-" + (0, import_uuid.v4)(),
|
||||||
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
||||||
choices: []
|
choices: []
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const promise = this.callApi(this.api.default.completionsV1CompletionsPost, {
|
const promise = this.callApi(this.api.v1.completion, {
|
||||||
prompt,
|
language: request2.language,
|
||||||
language: request2.language
|
segments
|
||||||
});
|
});
|
||||||
return cancelable(
|
return cancelable(
|
||||||
promise.then((response) => {
|
promise.then((response) => {
|
||||||
|
|
@ -795,7 +789,7 @@ var TabbyAgent = class extends import_events.EventEmitter {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
postEvent(request2) {
|
postEvent(request2) {
|
||||||
return this.callApi(this.api.default.eventsV1EventsPost, request2);
|
return this.callApi(this.api.v1.event, request2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -806,7 +800,6 @@ var agentEventNames = ["statusChanged", "configUpdated"];
|
||||||
ApiError,
|
ApiError,
|
||||||
CancelError,
|
CancelError,
|
||||||
CancelablePromise,
|
CancelablePromise,
|
||||||
EventType,
|
|
||||||
TabbyAgent,
|
TabbyAgent,
|
||||||
agentEventNames
|
agentEventNames
|
||||||
});
|
});
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -12629,47 +12629,45 @@ var AxiosHttpRequest = class extends BaseHttpRequest {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// src/generated/services/DefaultService.ts
|
// src/generated/services/V1Service.ts
|
||||||
init_global();
|
init_global();
|
||||||
init_dirname();
|
init_dirname();
|
||||||
init_filename();
|
init_filename();
|
||||||
init_buffer2();
|
init_buffer2();
|
||||||
init_process2();
|
init_process2();
|
||||||
var DefaultService = class {
|
var V1Service = class {
|
||||||
constructor(httpRequest) {
|
constructor(httpRequest) {
|
||||||
this.httpRequest = httpRequest;
|
this.httpRequest = httpRequest;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Completions
|
|
||||||
* @param requestBody
|
* @param requestBody
|
||||||
* @returns CompletionResponse Successful Response
|
* @returns CompletionResponse Success
|
||||||
* @throws ApiError
|
* @throws ApiError
|
||||||
*/
|
*/
|
||||||
completionsV1CompletionsPost(requestBody) {
|
completion(requestBody) {
|
||||||
return this.httpRequest.request({
|
return this.httpRequest.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/v1/completions",
|
url: "/v1/completions",
|
||||||
body: requestBody,
|
body: requestBody,
|
||||||
mediaType: "application/json",
|
mediaType: "application/json",
|
||||||
errors: {
|
errors: {
|
||||||
422: `Validation Error`
|
400: `Bad Request`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Events
|
|
||||||
* @param requestBody
|
* @param requestBody
|
||||||
* @returns any Successful Response
|
* @returns any Success
|
||||||
* @throws ApiError
|
* @throws ApiError
|
||||||
*/
|
*/
|
||||||
eventsV1EventsPost(requestBody) {
|
event(requestBody) {
|
||||||
return this.httpRequest.request({
|
return this.httpRequest.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/v1/events",
|
url: "/v1/events",
|
||||||
body: requestBody,
|
body: requestBody,
|
||||||
mediaType: "application/json",
|
mediaType: "application/json",
|
||||||
errors: {
|
errors: {
|
||||||
422: `Validation Error`
|
400: `Bad Request`
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -12679,7 +12677,7 @@ var DefaultService = class {
|
||||||
var TabbyApi = class {
|
var TabbyApi = class {
|
||||||
constructor(config2, HttpRequest = AxiosHttpRequest) {
|
constructor(config2, HttpRequest = AxiosHttpRequest) {
|
||||||
this.request = new HttpRequest({
|
this.request = new HttpRequest({
|
||||||
BASE: config2?.BASE ?? "",
|
BASE: config2?.BASE ?? "https://app.tabbyml.com/api/workspace/tabbyml/tabby",
|
||||||
VERSION: config2?.VERSION ?? "0.1.0",
|
VERSION: config2?.VERSION ?? "0.1.0",
|
||||||
WITH_CREDENTIALS: config2?.WITH_CREDENTIALS ?? false,
|
WITH_CREDENTIALS: config2?.WITH_CREDENTIALS ?? false,
|
||||||
CREDENTIALS: config2?.CREDENTIALS ?? "include",
|
CREDENTIALS: config2?.CREDENTIALS ?? "include",
|
||||||
|
|
@ -12689,7 +12687,7 @@ var TabbyApi = class {
|
||||||
HEADERS: config2?.HEADERS,
|
HEADERS: config2?.HEADERS,
|
||||||
ENCODE_PATH: config2?.ENCODE_PATH
|
ENCODE_PATH: config2?.ENCODE_PATH
|
||||||
});
|
});
|
||||||
this.default = new DefaultService(this.request);
|
this.v1 = new V1Service(this.request);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -12700,19 +12698,6 @@ init_filename();
|
||||||
init_buffer2();
|
init_buffer2();
|
||||||
init_process2();
|
init_process2();
|
||||||
|
|
||||||
// src/generated/models/EventType.ts
|
|
||||||
init_global();
|
|
||||||
init_dirname();
|
|
||||||
init_filename();
|
|
||||||
init_buffer2();
|
|
||||||
init_process2();
|
|
||||||
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
||||||
EventType2["COMPLETION"] = "completion";
|
|
||||||
EventType2["VIEW"] = "view";
|
|
||||||
EventType2["SELECT"] = "select";
|
|
||||||
return EventType2;
|
|
||||||
})(EventType || {});
|
|
||||||
|
|
||||||
// src/utils.ts
|
// src/utils.ts
|
||||||
init_global();
|
init_global();
|
||||||
init_dirname();
|
init_dirname();
|
||||||
|
|
@ -32383,12 +32368,15 @@ var TabbyAgent = class extends EventEmitter {
|
||||||
}
|
}
|
||||||
callApi(api, request2) {
|
callApi(api, request2) {
|
||||||
this.logger.debug({ api: api.name, request: request2 }, "API request");
|
this.logger.debug({ api: api.name, request: request2 }, "API request");
|
||||||
const promise = api.call(this.api.default, request2);
|
const promise = api.call(this.api.v1, request2);
|
||||||
return cancelable(
|
return cancelable(
|
||||||
promise.then((response) => {
|
promise.then((response) => {
|
||||||
this.logger.debug({ api: api.name, response }, "API response");
|
this.logger.debug({ api: api.name, response }, "API response");
|
||||||
this.changeStatus("ready");
|
this.changeStatus("ready");
|
||||||
return response;
|
return response;
|
||||||
|
}).catch((error) => {
|
||||||
|
this.logger.debug({ api: api.name }, "API request canceled");
|
||||||
|
throw error;
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.logger.error({ api: api.name, error }, "API error");
|
this.logger.error({ api: api.name, error }, "API error");
|
||||||
this.changeStatus("disconnected");
|
this.changeStatus("disconnected");
|
||||||
|
|
@ -32399,13 +32387,16 @@ var TabbyAgent = class extends EventEmitter {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
createPrompt(request2) {
|
createSegments(request2) {
|
||||||
const maxLines = 20;
|
const maxLines = 20;
|
||||||
const prefix = request2.text.slice(0, request2.position);
|
const prefix = request2.text.slice(0, request2.position);
|
||||||
const lines = splitLines(prefix);
|
const prefixLines = splitLines(prefix);
|
||||||
const cutoff = Math.max(lines.length - maxLines, 0);
|
const suffix = request2.text.slice(request2.position);
|
||||||
const prompt = lines.slice(cutoff).join("");
|
const suffixLines = splitLines(suffix);
|
||||||
return prompt;
|
return {
|
||||||
|
prefix: prefixLines.slice(Math.max(prefixLines.length - maxLines, 0)).join(""),
|
||||||
|
suffix: suffixLines.slice(0, maxLines).join("")
|
||||||
|
};
|
||||||
}
|
}
|
||||||
initialize(params) {
|
initialize(params) {
|
||||||
if (params.config) {
|
if (params.config) {
|
||||||
|
|
@ -32441,20 +32432,19 @@ var TabbyAgent = class extends EventEmitter {
|
||||||
resolve4(this.completionCache.get(request2));
|
resolve4(this.completionCache.get(request2));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const prompt = this.createPrompt(request2);
|
const segments = this.createSegments(request2);
|
||||||
if (isBlank(prompt)) {
|
if (isBlank(segments.prefix)) {
|
||||||
this.logger.debug("Prompt is blank, returning empty completion response");
|
this.logger.debug("Segment prefix is blank, returning empty completion response");
|
||||||
return new CancelablePromise((resolve4) => {
|
return new CancelablePromise((resolve4) => {
|
||||||
resolve4({
|
resolve4({
|
||||||
id: "agent-" + v4_default(),
|
id: "agent-" + v4_default(),
|
||||||
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
||||||
choices: []
|
choices: []
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const promise = this.callApi(this.api.default.completionsV1CompletionsPost, {
|
const promise = this.callApi(this.api.v1.completion, {
|
||||||
prompt,
|
language: request2.language,
|
||||||
language: request2.language
|
segments
|
||||||
});
|
});
|
||||||
return cancelable(
|
return cancelable(
|
||||||
promise.then((response) => {
|
promise.then((response) => {
|
||||||
|
|
@ -32467,7 +32457,7 @@ var TabbyAgent = class extends EventEmitter {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
postEvent(request2) {
|
postEvent(request2) {
|
||||||
return this.callApi(this.api.default.eventsV1EventsPost, request2);
|
return this.callApi(this.api.v1.event, request2);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -32482,7 +32472,6 @@ export {
|
||||||
ApiError,
|
ApiError,
|
||||||
CancelError,
|
CancelError,
|
||||||
CancelablePromise,
|
CancelablePromise,
|
||||||
EventType,
|
|
||||||
TabbyAgent,
|
TabbyAgent,
|
||||||
agentEventNames
|
agentEventNames
|
||||||
};
|
};
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -10,7 +10,7 @@
|
||||||
"browser": "./dist/index.mjs",
|
"browser": "./dist/index.mjs",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"openapi-codegen": "rimraf ./src/generated && openapi --input ../../docs/openapi.json --output ./src/generated --client axios --name TabbyApi --indent 2",
|
"openapi-codegen": "rimraf ./src/generated && openapi --input ../../website/static/openapi.json --output ./src/generated --client axios --name TabbyApi --indent 2",
|
||||||
"dev": "tsup --watch",
|
"dev": "tsup --watch",
|
||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import {
|
import {
|
||||||
CancelablePromise,
|
CancelablePromise,
|
||||||
ChoiceEvent,
|
LogEventRequest as ApiLogEventRequest,
|
||||||
CompletionEvent,
|
|
||||||
CompletionResponse as ApiCompletionResponse,
|
CompletionResponse as ApiCompletionResponse,
|
||||||
} from "./generated";
|
} from "./generated";
|
||||||
|
|
||||||
|
|
@ -21,13 +20,15 @@ export type CompletionRequest = {
|
||||||
|
|
||||||
export type CompletionResponse = ApiCompletionResponse;
|
export type CompletionResponse = ApiCompletionResponse;
|
||||||
|
|
||||||
|
export type LogEventRequest = ApiLogEventRequest;
|
||||||
|
|
||||||
export interface AgentFunction {
|
export interface AgentFunction {
|
||||||
initialize(options?: AgentInitOptions): boolean;
|
initialize(options?: AgentInitOptions): boolean;
|
||||||
updateConfig(config: AgentConfig): boolean;
|
updateConfig(config: AgentConfig): boolean;
|
||||||
getConfig(): AgentConfig;
|
getConfig(): AgentConfig;
|
||||||
getStatus(): "connecting" | "ready" | "disconnected";
|
getStatus(): "connecting" | "ready" | "disconnected";
|
||||||
getCompletions(request: CompletionRequest): CancelablePromise<CompletionResponse>;
|
getCompletions(request: CompletionRequest): CancelablePromise<CompletionResponse>;
|
||||||
postEvent(event: ChoiceEvent | CompletionEvent): CancelablePromise<boolean>;
|
postEvent(event: LogEventRequest): CancelablePromise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StatusChangedEvent = {
|
export type StatusChangedEvent = {
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@ import { EventEmitter } from "events";
|
||||||
import { v4 as uuid } from "uuid";
|
import { v4 as uuid } from "uuid";
|
||||||
import deepEqual from "deep-equal";
|
import deepEqual from "deep-equal";
|
||||||
import deepMerge from "deepmerge";
|
import deepMerge from "deepmerge";
|
||||||
import { TabbyApi, CancelablePromise, ApiError, ChoiceEvent, CompletionEvent } from "./generated";
|
import { TabbyApi, CancelablePromise, ApiError, CancelError } from "./generated";
|
||||||
import { sleep, cancelable, splitLines, isBlank } from "./utils";
|
import { sleep, cancelable, splitLines, isBlank } from "./utils";
|
||||||
import { Agent, AgentEvent, AgentInitOptions, CompletionRequest, CompletionResponse } from "./Agent";
|
import { Agent, AgentEvent, AgentInitOptions, CompletionRequest, CompletionResponse, LogEventRequest } from "./Agent";
|
||||||
import { AgentConfig, defaultAgentConfig } from "./AgentConfig";
|
import { AgentConfig, defaultAgentConfig } from "./AgentConfig";
|
||||||
import { CompletionCache } from "./CompletionCache";
|
import { CompletionCache } from "./CompletionCache";
|
||||||
import { rootLogger, allLoggers } from "./logger";
|
import { rootLogger, allLoggers } from "./logger";
|
||||||
|
|
@ -59,7 +59,7 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
||||||
request: Request
|
request: Request
|
||||||
): CancelablePromise<Response> {
|
): CancelablePromise<Response> {
|
||||||
this.logger.debug({ api: api.name, request }, "API request");
|
this.logger.debug({ api: api.name, request }, "API request");
|
||||||
const promise = api.call(this.api.default, request);
|
const promise = api.call(this.api.v1, request);
|
||||||
return cancelable(
|
return cancelable(
|
||||||
promise
|
promise
|
||||||
.then((response: Response) => {
|
.then((response: Response) => {
|
||||||
|
|
@ -67,6 +67,10 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
||||||
this.changeStatus("ready");
|
this.changeStatus("ready");
|
||||||
return response;
|
return response;
|
||||||
})
|
})
|
||||||
|
.catch((error: CancelError) => {
|
||||||
|
this.logger.debug({ api: api.name }, "API request canceled");
|
||||||
|
throw error;
|
||||||
|
})
|
||||||
.catch((error: ApiError) => {
|
.catch((error: ApiError) => {
|
||||||
this.logger.error({ api: api.name, error }, "API error");
|
this.logger.error({ api: api.name, error }, "API error");
|
||||||
this.changeStatus("disconnected");
|
this.changeStatus("disconnected");
|
||||||
|
|
@ -78,13 +82,17 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private createPrompt(request: CompletionRequest): string {
|
private createSegments(request: CompletionRequest): { prefix: string; suffix: string } {
|
||||||
|
// max to 20 lines in prefix and max to 20 lines in suffix
|
||||||
const maxLines = 20;
|
const maxLines = 20;
|
||||||
const prefix = request.text.slice(0, request.position);
|
const prefix = request.text.slice(0, request.position);
|
||||||
const lines = splitLines(prefix);
|
const prefixLines = splitLines(prefix);
|
||||||
const cutoff = Math.max(lines.length - maxLines, 0);
|
const suffix = request.text.slice(request.position);
|
||||||
const prompt = lines.slice(cutoff).join("");
|
const suffixLines = splitLines(suffix);
|
||||||
return prompt;
|
return {
|
||||||
|
prefix: prefixLines.slice(Math.max(prefixLines.length - maxLines, 0)).join(""),
|
||||||
|
suffix: suffixLines.slice(0, maxLines).join(""),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public initialize(params: AgentInitOptions): boolean {
|
public initialize(params: AgentInitOptions): boolean {
|
||||||
|
|
@ -127,20 +135,19 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
||||||
resolve(this.completionCache.get(request));
|
resolve(this.completionCache.get(request));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const prompt = this.createPrompt(request);
|
const segments = this.createSegments(request);
|
||||||
if (isBlank(prompt)) {
|
if (isBlank(segments.prefix)) {
|
||||||
this.logger.debug("Prompt is blank, returning empty completion response");
|
this.logger.debug("Segment prefix is blank, returning empty completion response");
|
||||||
return new CancelablePromise((resolve) => {
|
return new CancelablePromise((resolve) => {
|
||||||
resolve({
|
resolve({
|
||||||
id: "agent-" + uuid(),
|
id: "agent-" + uuid(),
|
||||||
created: new Date().getTime(),
|
|
||||||
choices: [],
|
choices: [],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const promise = this.callApi(this.api.default.completionsV1CompletionsPost, {
|
const promise = this.callApi(this.api.v1.completion, {
|
||||||
prompt,
|
|
||||||
language: request.language,
|
language: request.language,
|
||||||
|
segments,
|
||||||
});
|
});
|
||||||
return cancelable(
|
return cancelable(
|
||||||
promise.then((response: CompletionResponse) => {
|
promise.then((response: CompletionResponse) => {
|
||||||
|
|
@ -153,7 +160,7 @@ export class TabbyAgent extends EventEmitter implements Agent {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public postEvent(request: ChoiceEvent | CompletionEvent): CancelablePromise<boolean> {
|
public postEvent(request: LogEventRequest): CancelablePromise<boolean> {
|
||||||
return this.callApi(this.api.default.eventsV1EventsPost, request);
|
return this.callApi(this.api.v1.event, request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,5 @@ export {
|
||||||
CancelablePromise,
|
CancelablePromise,
|
||||||
CancelError,
|
CancelError,
|
||||||
ApiError,
|
ApiError,
|
||||||
HTTPValidationError,
|
|
||||||
ValidationError,
|
|
||||||
Choice,
|
Choice,
|
||||||
ChoiceEvent,
|
|
||||||
CompletionEvent,
|
|
||||||
EventType,
|
|
||||||
} from "./generated";
|
} from "./generated";
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import {
|
||||||
} from "vscode";
|
} from "vscode";
|
||||||
import { strict as assert } from "assert";
|
import { strict as assert } from "assert";
|
||||||
import { Duration } from "@sapphire/duration";
|
import { Duration } from "@sapphire/duration";
|
||||||
import { ChoiceEvent } from "tabby-agent";
|
|
||||||
import { Agent } from "./Agent";
|
import { Agent } from "./Agent";
|
||||||
|
|
||||||
const target = ConfigurationTarget.Global;
|
const target = ConfigurationTarget.Global;
|
||||||
|
|
@ -131,7 +130,7 @@ const openSettings: Command = {
|
||||||
const agent = Agent.getInstance();
|
const agent = Agent.getInstance();
|
||||||
const emitEvent: Command = {
|
const emitEvent: Command = {
|
||||||
command: "tabby.emitEvent",
|
command: "tabby.emitEvent",
|
||||||
callback: (event: ChoiceEvent) => {
|
callback: (event) => {
|
||||||
console.debug("Emit Event: ", event);
|
console.debug("Emit Event: ", event);
|
||||||
agent.postEvent(event);
|
agent.postEvent(event);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
TextDocument,
|
TextDocument,
|
||||||
workspace,
|
workspace,
|
||||||
} from "vscode";
|
} from "vscode";
|
||||||
import { CompletionResponse, EventType, ChoiceEvent, CancelablePromise } from "tabby-agent";
|
import { CompletionResponse, CancelablePromise } from "tabby-agent";
|
||||||
import { Agent } from "./Agent";
|
import { Agent } from "./Agent";
|
||||||
import { sleep } from "./utils";
|
import { sleep } from "./utils";
|
||||||
|
|
||||||
|
|
@ -82,8 +82,8 @@ export class TabbyCompletionProvider implements InlineCompletionItemProvider {
|
||||||
private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] {
|
private toInlineCompletions(tabbyCompletion: CompletionResponse | null, range: Range): InlineCompletionItem[] {
|
||||||
return (
|
return (
|
||||||
tabbyCompletion?.choices?.map((choice: any) => {
|
tabbyCompletion?.choices?.map((choice: any) => {
|
||||||
let event: ChoiceEvent = {
|
let event = {
|
||||||
type: EventType.SELECT,
|
type: "select",
|
||||||
completion_id: tabbyCompletion.id,
|
completion_id: tabbyCompletion.id,
|
||||||
choice_index: choice.index,
|
choice_index: choice.index,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue