-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathextension.ts
More file actions
71 lines (63 loc) · 2.28 KB
/
Copy pathextension.ts
File metadata and controls
71 lines (63 loc) · 2.28 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
66
67
68
69
70
71
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import { CopilotClient } from "./client.js";
import type { CopilotSession } from "./session.js";
import {
defaultJoinSessionPermissionHandler,
type ExtensionInfo,
type PermissionHandler,
type ResumeSessionConfig,
} from "./types.js";
export {
Canvas,
CanvasError,
createCanvas,
type CanvasAction,
type CanvasDeclaration,
type CanvasHostContext,
type CanvasJsonSchema,
type CanvasOptions,
} from "./canvas.js";
export type JoinSessionConfig = Omit<
ResumeSessionConfig,
"onPermissionRequest" | "extensionSdkPath"
> & {
onPermissionRequest?: PermissionHandler;
};
export type { ExtensionInfo };
/**
* Joins the current foreground session.
*
* @param config - Configuration to add to the session
* @returns A promise that resolves with the joined session
*
* @example
* ```typescript
* import { joinSession } from "@github/copilot-sdk/extension";
*
* const session = await joinSession({ tools: [myTool] });
* ```
*/
export async function joinSession(config: JoinSessionConfig = {}): Promise<CopilotSession> {
const sessionId = process.env.SESSION_ID;
if (!sessionId) {
throw new Error(
"joinSession() is intended for extensions running as child processes of the Copilot CLI."
);
}
const client = new CopilotClient({ _internalConnection: { kind: "parent-process" } });
// Strip `extensionSdkPath` at runtime even though `JoinSessionConfig` omits it
// at the type level — untyped (JS) callers can still slip it through, and
// honoring it here would be misleading since the extension subprocess has
// already been forked by the host with the SDK the host chose.
const { extensionSdkPath: _stripped, ...rest } = config as JoinSessionConfig & {
extensionSdkPath?: string;
};
void _stripped;
return client.resumeSession(sessionId, {
...rest,
onPermissionRequest: config.onPermissionRequest ?? defaultJoinSessionPermissionHandler,
suppressResumeEvent: config.suppressResumeEvent ?? true,
});
}