Repository navigation
Expand file tree
/
Copy pathhost.ts
More file actions
65 lines (58 loc) · 2.36 KB
/
Copy pathhost.ts
File metadata and controls
65 lines (58 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import type { HostExitedNotification, HostStartResult } from "./generated/rpc.js";
/**
* A runtime exit report, or an owner disconnect that cannot acknowledge reaping.
* @experimental
*/
export type AhpHostExit = HostExitedNotification;
/** Options for a runtime-supervised AHP listener. @experimental */
export interface AhpHostOptions {
/** Listener hostname. The runtime defaults to 127.0.0.1. */
hostname?: string;
/** Listener port. Omitted or zero asks the runtime for an available port. */
port?: number;
/** Connection token. The runtime generates one when required and omitted. */
token?: string;
/** Whether the listener requires token authentication. */
requireConnectionToken?: boolean;
/** Called at most once. This callback is local and is never sent to the runtime. */
onExit?: (exit: AhpHostExit) => void;
}
/**
* A connection-owned AHP listener supervised by the runtime.
*
* The runtime, not this SDK, launches and reaps copilotd-lite. Disconnecting
* the owning client also stops the host; reconnecting does not reclaim it.
* Stopping a host does not delete its underlying sessions.
* Its durable AHP catalog is shared by successive lite hosts in the runtime's
* effective Copilot home; a concurrent lite host for that catalog is rejected.
*
* @experimental
*/
export class AhpHost {
readonly hostId: string;
readonly url: string;
/** Connection token, when required by the listener. Treat this value as a secret. */
readonly token: string | undefined;
/** Process ID of the runtime's child, not an SDK-owned process. */
readonly pid: number;
/** @internal */
constructor(
info: HostStartResult,
private readonly disposeHost: () => Promise<void>
) {
this.hostId = info.hostId;
this.url = info.url;
this.token = info.token;
this.pid = info.pid;
}
/** Ask the runtime to stop the listener and await its cleanup, on every call. */
dispose(): Promise<void> {
return this.disposeHost();
}
async [Symbol.asyncDispose](): Promise<void> {
await this.dispose();
}
}