-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tabby-chat-panel sdk (#1991)
* init * update * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
2785a9a
commit 7b872a5
Showing
21 changed files
with
4,934 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# tabby-chat-panel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import antfu from '@antfu/eslint-config' | ||
|
||
export default antfu() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
Oops, something went wrong.