Skip to content

Commit

Permalink
feat: add tabby-chat-panel sdk (#1991)
Browse files Browse the repository at this point in the history
* init

* update

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
wsxiaoys and autofix-ci[bot] authored May 6, 2024
1 parent 2785a9a commit 7b872a5
Show file tree
Hide file tree
Showing 21 changed files with 4,934 additions and 0 deletions.
1 change: 1 addition & 0 deletions clients/tabby-chat-panel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tabby-chat-panel
13 changes: 13 additions & 0 deletions clients/tabby-chat-panel/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
entries: [
'src/index',
'src/react',
],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
},
})
17 changes: 17 additions & 0 deletions clients/tabby-chat-panel/dist/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const rpc = require('@remote-ui/rpc');

function createClient(endpoint) {
return rpc.createEndpoint(endpoint);
}
function createServer(endpoint, api) {
const server = rpc.createEndpoint(endpoint);
server.expose({
init: api.init
});
return server;
}

exports.createClient = createClient;
exports.createServer = createServer;
30 changes: 30 additions & 0 deletions clients/tabby-chat-panel/dist/index.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as _remote_ui_rpc from '@remote-ui/rpc';
import { MessageEndpoint } from '@remote-ui/rpc';

interface LineRange {
start: number;
end: number;
}
interface FileContext {
kind: 'file';
range: LineRange;
filename: string;
link: string;
}
type Context = FileContext;
interface FetcherOptions {
authorization: string;
}
interface InitRequest {
message?: string;
selectContext?: Context;
relevantContext?: Array<Context>;
fetcherOptions?: FetcherOptions;
}
interface Api {
init: (request: InitRequest) => void;
}
declare function createClient(endpoint: MessageEndpoint): _remote_ui_rpc.Endpoint<Api>;
declare function createServer(endpoint: MessageEndpoint, api: Api): _remote_ui_rpc.Endpoint<unknown>;

export { type Api, type Context, type FetcherOptions, type FileContext, type InitRequest, type LineRange, createClient, createServer };
30 changes: 30 additions & 0 deletions clients/tabby-chat-panel/dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as _remote_ui_rpc from '@remote-ui/rpc';
import { MessageEndpoint } from '@remote-ui/rpc';

interface LineRange {
start: number;
end: number;
}
interface FileContext {
kind: 'file';
range: LineRange;
filename: string;
link: string;
}
type Context = FileContext;
interface FetcherOptions {
authorization: string;
}
interface InitRequest {
message?: string;
selectContext?: Context;
relevantContext?: Array<Context>;
fetcherOptions?: FetcherOptions;
}
interface Api {
init: (request: InitRequest) => void;
}
declare function createClient(endpoint: MessageEndpoint): _remote_ui_rpc.Endpoint<Api>;
declare function createServer(endpoint: MessageEndpoint, api: Api): _remote_ui_rpc.Endpoint<unknown>;

export { type Api, type Context, type FetcherOptions, type FileContext, type InitRequest, type LineRange, createClient, createServer };
30 changes: 30 additions & 0 deletions clients/tabby-chat-panel/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as _remote_ui_rpc from '@remote-ui/rpc';
import { MessageEndpoint } from '@remote-ui/rpc';

interface LineRange {
start: number;
end: number;
}
interface FileContext {
kind: 'file';
range: LineRange;
filename: string;
link: string;
}
type Context = FileContext;
interface FetcherOptions {
authorization: string;
}
interface InitRequest {
message?: string;
selectContext?: Context;
relevantContext?: Array<Context>;
fetcherOptions?: FetcherOptions;
}
interface Api {
init: (request: InitRequest) => void;
}
declare function createClient(endpoint: MessageEndpoint): _remote_ui_rpc.Endpoint<Api>;
declare function createServer(endpoint: MessageEndpoint, api: Api): _remote_ui_rpc.Endpoint<unknown>;

export { type Api, type Context, type FetcherOptions, type FileContext, type InitRequest, type LineRange, createClient, createServer };
14 changes: 14 additions & 0 deletions clients/tabby-chat-panel/dist/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createEndpoint } from '@remote-ui/rpc';

function createClient(endpoint) {
return createEndpoint(endpoint);
}
function createServer(endpoint, api) {
const server = createEndpoint(endpoint);
server.expose({
init: api.init
});
return server;
}

export { createClient, createServer };
20 changes: 20 additions & 0 deletions clients/tabby-chat-panel/dist/react.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const rpc = require('@remote-ui/rpc');
const react = require('react');
const index = require('./index.cjs');

function useClient(iframeRef) {
return react.useMemo(() => {
if (iframeRef.current)
return index.createClient(rpc.fromIframe(iframeRef.current));
}, [iframeRef.current]);
}
function useServer(api) {
return react.useMemo(() => {
return index.createServer(rpc.fromInsideIframe(), api);
}, []);
}

exports.useClient = useClient;
exports.useServer = useServer;
8 changes: 8 additions & 0 deletions clients/tabby-chat-panel/dist/react.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as _remote_ui_rpc from '@remote-ui/rpc';
import { RefObject } from 'react';
import { Api } from './index.cjs';

declare function useClient(iframeRef: RefObject<HTMLIFrameElement>): _remote_ui_rpc.Endpoint<Api> | undefined;
declare function useServer(api: Api): _remote_ui_rpc.Endpoint<unknown>;

export { useClient, useServer };
8 changes: 8 additions & 0 deletions clients/tabby-chat-panel/dist/react.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as _remote_ui_rpc from '@remote-ui/rpc';
import { RefObject } from 'react';
import { Api } from './index.mjs';

declare function useClient(iframeRef: RefObject<HTMLIFrameElement>): _remote_ui_rpc.Endpoint<Api> | undefined;
declare function useServer(api: Api): _remote_ui_rpc.Endpoint<unknown>;

export { useClient, useServer };
8 changes: 8 additions & 0 deletions clients/tabby-chat-panel/dist/react.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as _remote_ui_rpc from '@remote-ui/rpc';
import { RefObject } from 'react';
import { Api } from './index.js';

declare function useClient(iframeRef: RefObject<HTMLIFrameElement>): _remote_ui_rpc.Endpoint<Api> | undefined;
declare function useServer(api: Api): _remote_ui_rpc.Endpoint<unknown>;

export { useClient, useServer };
17 changes: 17 additions & 0 deletions clients/tabby-chat-panel/dist/react.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { fromIframe, fromInsideIframe } from '@remote-ui/rpc';
import { useMemo } from 'react';
import { createClient, createServer } from './index.mjs';

function useClient(iframeRef) {
return useMemo(() => {
if (iframeRef.current)
return createClient(fromIframe(iframeRef.current));
}, [iframeRef.current]);
}
function useServer(api) {
return useMemo(() => {
return createServer(fromInsideIframe(), api);
}, []);
}

export { useClient, useServer };
3 changes: 3 additions & 0 deletions clients/tabby-chat-panel/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import antfu from '@antfu/eslint-config'

export default antfu()
73 changes: 73 additions & 0 deletions clients/tabby-chat-panel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"name": "tabby-chat-panel",
"type": "module",
"version": "0.0.0",
"packageManager": "[email protected]",
"keywords": [],
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./react": {
"types": "./dist/react.d.ts",
"import": "./dist/react.mjs",
"require": "./dist/react.cjs"
}
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
"./dist/*",
"./dist/index.d.ts"
]
}
},
"files": [
"dist"
],
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub",
"fix": "eslint . -f mo --fix",
"lint": "eslint . -f mo",
"prepack": "nr build",
"preview": "node --watch bin/index.js",
"release": "bumpp && npm publish",
"start": "tsx src/index.ts",
"test": "vitest",
"test:once": "vitest run",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@remote-ui/rpc": "^1.4.5",
"react": "^18.3.1"
},
"devDependencies": {
"@antfu/eslint-config": "^2.16.0",
"@antfu/ni": "^0.21.12",
"@types/node": "^20.12.7",
"@types/react": "^18.3.1",
"bumpp": "^9.4.0",
"eslint": "^9.1.1",
"eslint-formatter-mo": "^1.2.0",
"lint-staged": "^15.2.2",
"rimraf": "^5.0.5",
"tsx": "^4.7.3",
"typescript": "^5.4.5",
"unbuild": "^2.0.0",
"vite": "^5.2.10",
"vitest": "^1.5.2"
},
"lint-staged": {
"*": "eslint --fix"
},
"publishConfig": {
"access": "public"
}
}
42 changes: 42 additions & 0 deletions clients/tabby-chat-panel/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { MessageEndpoint, createEndpoint, fromIframe, fromInsideIframe } from '@remote-ui/rpc'

export interface LineRange {
start: number
end: number
}

export interface FileContext {
kind: 'file'
range: LineRange
filename: string
link: string
}

export type Context = FileContext

export interface FetcherOptions {
authorization: string
}

export interface InitRequest {
message?: string
selectContext?: Context
relevantContext?: Array<Context>
fetcherOptions?: FetcherOptions
}

export interface Api {
init: (request: InitRequest) => void
}

export function createClient(endpoint: MessageEndpoint) {
return createEndpoint<Api>(endpoint)
}

export function createServer(endpoint: MessageEndpoint, api: Api) {
const server = createEndpoint(endpoint)
server.expose({
init: api.init,
})
return server;
}
21 changes: 21 additions & 0 deletions clients/tabby-chat-panel/src/react.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { fromIframe, fromInsideIframe } from "@remote-ui/rpc"
import { RefObject, useMemo } from "react"
import { Api, createClient, createServer } from "./index"

function useClient(iframeRef: RefObject<HTMLIFrameElement>) {
return useMemo(() => {
if (iframeRef.current)
return createClient(fromIframe(iframeRef.current))
}, [iframeRef.current])
}

function useServer(api: Api) {
return useMemo(() => {
return createServer(fromInsideIframe(), api)
}, [])
}

export {
useClient,
useServer,
}
7 changes: 7 additions & 0 deletions clients/tabby-chat-panel/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, expect, it } from 'vitest'

describe('should', () => {
it('exported', () => {
expect(1).toEqual(1)
})
})
15 changes: 15 additions & 0 deletions clients/tabby-chat-panel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["ESNext", "DOM"],
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"strict": true,
"strictNullChecks": true,
"esModuleInterop": true,
"skipDefaultLibCheck": true,
"skipLibCheck": true
},
"include": ["src", "test", "build.config.ts"]
}
Loading

0 comments on commit 7b872a5

Please sign in to comment.