Skip to content

Commit

Permalink
chore: extract tabby-openapi. (#2342)
Browse files Browse the repository at this point in the history
  • Loading branch information
icycodes authored Jun 4, 2024
1 parent f5e00a3 commit bd57267
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 442 deletions.
376 changes: 0 additions & 376 deletions clients/tabby-agent/openapi/tabby.json

This file was deleted.

1 change: 1 addition & 0 deletions clients/tabby-agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"randomstring": "^1.3.0",
"semver": "^7.6.0",
"stats-logscale": "^1.0.9",
"tabby-openapi": "workspace:*",
"toml": "^3.0.0",
"ts-node": "^10.9.1",
"tsc-watch": "^6.2.0",
Expand Down
2 changes: 1 addition & 1 deletion clients/tabby-agent/src/Agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { components as ApiComponents } from "./types/tabbyApi";
import type { components as ApiComponents } from "tabby-openapi/compatible";
import type { AgentConfig, PartialAgentConfig } from "./AgentConfig";
import type { DataStore } from "./dataStore";
import type { Logger } from "./logger";
Expand Down
2 changes: 1 addition & 1 deletion clients/tabby-agent/src/CompletionContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import hashObject from "object-hash";
import { splitLines, isBlank, regOnlyAutoClosingCloseChars } from "./utils";
import type { components as TabbyApiComponents } from "./types/tabbyApi";
import type { components as TabbyApiComponents } from "tabby-openapi/compatible";
import type { AgentConfig } from "./AgentConfig";

export type CompletionRequest = {
Expand Down
2 changes: 1 addition & 1 deletion clients/tabby-agent/src/CompletionSolution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { splitLines, isBlank } from "./utils";
import type { components as TabbyApiComponents } from "./types/tabbyApi";
import type { components as TabbyApiComponents } from "tabby-openapi/compatible";
import type { CompletionContext } from "./CompletionContext";

export type InlineCompletionItem = {
Expand Down
2 changes: 1 addition & 1 deletion clients/tabby-agent/src/TabbyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import createClient from "openapi-fetch";
import type { ParseAs } from "openapi-fetch";
import * as semver from "semver";
import { Readable } from "node:stream";
import type { paths as TabbyApi, components as TabbyApiComponents } from "./types/tabbyApi";
import type { paths as TabbyApi, components as TabbyApiComponents } from "tabby-openapi/compatible";
import type {
Agent,
AgentStatus,
Expand Down
2 changes: 1 addition & 1 deletion clients/tabby-agent/src/stream.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Readable } from "node:stream";
import type { ReadableStream as NodeReadableStream } from "node:stream/web";
import { EventSourceParserStream, ParsedEvent } from "eventsource-parser/stream";
import type { components as TabbyApiComponents } from "./types/tabbyApi";
import type { components as TabbyApiComponents } from "tabby-openapi/compatible";
import { getLogger } from "./logger";

const logger = getLogger("StreamParser");
Expand Down
1 change: 1 addition & 0 deletions clients/tabby-openapi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
35 changes: 35 additions & 0 deletions clients/tabby-openapi/compatible/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
paths as _paths,
webhooks as _webhooks,
components as _components,
$defs as _$defs,
external as _external,
operations as _operations,
} from "../lib";

export interface paths extends _paths {
"/v1/health": _paths["/v1/health"] & {
// backward compatible for Tabby server 0.2.x and earlier
post: operations["health"];
};
// backward compatible for Tabby server 0.10.x and earlier
"/v1beta/chat/completions": {
post: operations["chat_completions"];
};
}

export type webhooks = _webhooks;
export type components = _components;
export type $defs = _$defs;
export type external = _external;

export interface operations extends _operations {
event: _operations["event"] & {
// Add a query parameter to specify the select kind
parameters: {
query: {
select_kind?: string | null;
};
};
};
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/


/** OneOf type helpers */
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
type OneOf<T extends any[]> = T extends [infer Only] ? Only : T extends [infer A, infer B, ...infer Rest] ? OneOf<[XOR<A, B>, ...Rest]> : never;

export interface paths {
"/v1/chat/completions": {
post: operations["chat_completions"];
Expand All @@ -10,15 +21,9 @@ export interface paths {
};
"/v1/health": {
get: operations["health"];
// back compatible for Tabby server 0.2.x and earlier
post: operations["health"];
};
// back compatible for Tabby server 0.10.x and earlier
"/v1beta/chat/completions": {
post: operations["chat_completions"];
};
"/v1beta/search": {
get: operations["search"];
"/v1beta/answer": {
post: operations["answer"];
};
"/v1beta/server_setting": {
get: operations["config"];
Expand All @@ -29,6 +34,32 @@ export type webhooks = Record<string, never>;

export interface components {
schemas: {
/**
* @example {
* "messages": [
* {
* "content": "What is tail recursion?",
* "role": "user"
* }
* ]
* }
*/
AnswerRequest: {
user?: string | null;
messages: components["schemas"]["Message"][];
code_query?: components["schemas"]["CodeSearchQuery"] | null;
doc_query?: boolean;
generate_relevant_questions?: boolean;
};
AnswerResponseChunk: OneOf<[{
relevant_code: components["schemas"]["CodeSearchDocument"][];
}, {
relevant_documents: components["schemas"]["DocSearchDocument"][];
}, {
relevant_questions: string[];
}, {
answer_delta: string;
}]>;
ChatCompletionChoice: {
index: number;
logprobs?: string | null;
Expand Down Expand Up @@ -66,17 +97,33 @@ export interface components {
* }
*/
ChatCompletionRequest: {
user?: string | null;
messages: components["schemas"]["Message"][];
/** Format: float */
temperature?: number | null;
/** Format: int64 */
seed?: number | null;
/** Format: float */
presence_penalty?: number | null;
};
Choice: {
/** Format: int32 */
index: number;
text: string;
};
CodeSearchDocument: {
body: string;
filepath: string;
git_url: string;
language: string;
start_line: number;
};
CodeSearchQuery: {
git_url: string;
filepath?: string | null;
language: string;
content: string;
};
/**
* @example {
* "language": "python",
Expand Down Expand Up @@ -158,6 +205,11 @@ export interface components {
/** @description Body of the snippet. */
body: string;
};
DocSearchDocument: {
title: string;
link: string;
snippet: string;
};
HealthState: {
model?: string | null;
chat_model?: string | null;
Expand All @@ -170,19 +222,6 @@ export interface components {
version: components["schemas"]["Version"];
webserver?: boolean | null;
};
Hit: {
/** Format: float */
score: number;
doc: components["schemas"]["HitDocument"];
/** Format: int32 */
id: number;
};
HitDocument: {
body: string;
filepath: string;
git_url: string;
language: string;
};
LogEventRequest: {
/**
* @description Event type, should be `view`, `select` or `dismiss`.
Expand All @@ -200,10 +239,6 @@ export interface components {
role: string;
content: string;
};
SearchResponse: {
num_hits: number;
hits: components["schemas"]["Hit"][];
};
Segments: {
/** @description Content that appears before the cursor in the editor window. */
prefix: string;
Expand Down Expand Up @@ -270,6 +305,7 @@ export type $defs = Record<string, never>;
export type external = Record<string, never>;

export interface operations {

chat_completions: {
requestBody: {
content: {
Expand Down Expand Up @@ -313,11 +349,6 @@ export interface operations {
};
};
event: {
parameters: {
query: {
select_kind?: string | null;
};
};
requestBody: {
content: {
"application/json": components["schemas"]["LogEventRequest"];
Expand All @@ -344,22 +375,20 @@ export interface operations {
};
};
};
search: {
parameters: {
query: {
q: string;
limit?: number | null;
offset?: number | null;
answer: {
requestBody: {
content: {
"application/json": components["schemas"]["AnswerRequest"];
};
};
responses: {
/** @description Success */
200: {
content: {
"application/json": components["schemas"]["SearchResponse"];
"text/event-stream": components["schemas"]["AnswerResponseChunk"];
};
};
/** @description When code search is not enabled, the endpoint will returns 501 Not Implemented */
/** @description When answer search is not enabled, the endpoint will returns 501 Not Implemented */
501: {
content: never;
};
Expand Down
Loading

0 comments on commit bd57267

Please sign in to comment.