Skip to content

Commit

Permalink
refactor: improve client auth flow (TabbyML#269)
Browse files Browse the repository at this point in the history
* refactor: improve client auth flow

* fix: agent waiting for auth token should update status before resolve.
  • Loading branch information
icycodes authored Jun 24, 2023
1 parent 7abca76 commit af517fb
Show file tree
Hide file tree
Showing 15 changed files with 491 additions and 363 deletions.
118 changes: 59 additions & 59 deletions clients/tabby-agent/dist/cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clients/tabby-agent/dist/cli.js.map

Large diffs are not rendered by default.

27 changes: 23 additions & 4 deletions clients/tabby-agent/dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,21 @@ interface AgentFunction {
getConfig(): AgentConfig;
getStatus(): AgentStatus;
/**
* @returns string auth url if AgentStatus is `unauthorized`, null otherwise
* @returns the auth url for redirecting, and the code for next step `waitingForAuth`, only return value when
* `AgentStatus` is `unauthorized`, return null otherwise
* @throws Error if agent is not initialized
*/
startAuth(): CancelablePromise<string | null>;
requestAuthUrl(): CancelablePromise<{
authUrl: string;
code: string;
} | null>;
/**
* Wait for auth token to be ready after redirecting user to auth url,
* returns nothing, but `AgentStatus` will change to `ready` if resolved successfully
* @param code from `requestAuthUrl`
* @throws Error if agent is not initialized
*/
waitForAuthToken(code: string): CancelablePromise<any>;
/**
* @param request
* @returns
Expand All @@ -94,7 +105,11 @@ type ConfigUpdatedEvent = {
event: "configUpdated";
config: AgentConfig;
};
type AgentEvent = StatusChangedEvent | ConfigUpdatedEvent;
type AuthRequiredEvent = {
event: "authRequired";
server: AgentConfig["server"];
};
type AgentEvent = StatusChangedEvent | ConfigUpdatedEvent | AuthRequiredEvent;
declare const agentEventNames: AgentEvent["event"][];
interface AgentEventEmitter {
on<T extends AgentEvent>(eventName: T["event"], callback: (event: T) => void): this;
Expand Down Expand Up @@ -145,7 +160,11 @@ declare class TabbyAgent extends EventEmitter implements Agent {
updateConfig(config: Partial<AgentConfig>): Promise<boolean>;
getConfig(): AgentConfig;
getStatus(): AgentStatus;
startAuth(): CancelablePromise<string | null>;
requestAuthUrl(): CancelablePromise<{
authUrl: string;
code: string;
} | null>;
waitForAuthToken(code: string): CancelablePromise<any>;
getCompletions(request: CompletionRequest): CancelablePromise<CompletionResponse>;
postEvent(request: LogEventRequest): CancelablePromise<boolean>;
}
Expand Down
16 changes: 8 additions & 8 deletions clients/tabby-agent/dist/index.global.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion clients/tabby-agent/dist/index.global.js.map

Large diffs are not rendered by default.

183 changes: 103 additions & 80 deletions clients/tabby-agent/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clients/tabby-agent/dist/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit af517fb

Please sign in to comment.