@github/copilot-sdk 1.0.0-beta.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -9
- package/dist/canvas.d.ts +26 -3
- package/dist/cjs/client.js +118 -40
- package/dist/cjs/extension.js +3 -1
- package/dist/cjs/generated/rpc.js +405 -43
- package/dist/cjs/session.js +46 -5
- package/dist/client.js +118 -40
- package/dist/extension.d.ts +1 -1
- package/dist/extension.js +3 -1
- package/dist/generated/rpc.d.ts +3268 -712
- package/dist/generated/rpc.js +404 -43
- package/dist/generated/session-events.d.ts +199 -28
- package/dist/index.d.ts +2 -2
- package/dist/session.d.ts +11 -5
- package/dist/session.js +46 -5
- package/dist/types.d.ts +172 -2
- package/docs/examples.md +7 -4
- package/package.json +4 -4
package/dist/cjs/session.js
CHANGED
|
@@ -33,6 +33,13 @@ function deserializeHookInput(raw) {
|
|
|
33
33
|
const { cwd, ...rest } = obj;
|
|
34
34
|
return { ...rest, timestamp: new Date(obj.timestamp), workingDirectory: cwd };
|
|
35
35
|
}
|
|
36
|
+
function isOpenCanvasInstance(value) {
|
|
37
|
+
if (!value || typeof value !== "object") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const instance = value;
|
|
41
|
+
return typeof instance.instanceId === "string" && instance.instanceId.length > 0 && typeof instance.extensionId === "string" && instance.extensionId.length > 0 && typeof instance.canvasId === "string" && instance.canvasId.length > 0 && typeof instance.reopen === "boolean" && (instance.availability === "ready" || instance.availability === "stale");
|
|
42
|
+
}
|
|
36
43
|
class CopilotSession {
|
|
37
44
|
/**
|
|
38
45
|
* Creates a new CopilotSession instance.
|
|
@@ -117,6 +124,7 @@ class CopilotSession {
|
|
|
117
124
|
...await (0, import_telemetry.getTraceContext)(this.traceContextProvider),
|
|
118
125
|
sessionId: this.sessionId,
|
|
119
126
|
prompt: options.prompt,
|
|
127
|
+
displayPrompt: options.displayPrompt,
|
|
120
128
|
attachments: options.attachments,
|
|
121
129
|
mode: options.mode,
|
|
122
130
|
agentMode: options.agentMode,
|
|
@@ -266,6 +274,39 @@ class CopilotSession {
|
|
|
266
274
|
}
|
|
267
275
|
} else if (event.type === "capabilities.changed") {
|
|
268
276
|
this._capabilities = { ...this._capabilities, ...event.data };
|
|
277
|
+
} else if (event.type === "session.canvas.opened") {
|
|
278
|
+
this.upsertOpenCanvasFromEvent(event.data);
|
|
279
|
+
} else if (event.type === "session.canvas.closed") {
|
|
280
|
+
this.removeOpenCanvasFromEvent(event.data);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
upsertOpenCanvasFromEvent(data) {
|
|
284
|
+
if (!isOpenCanvasInstance(data)) {
|
|
285
|
+
console.warn("failed to deserialize session.canvas.opened payload");
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
this.upsertOpenCanvas(data);
|
|
289
|
+
}
|
|
290
|
+
removeOpenCanvasFromEvent(data) {
|
|
291
|
+
if (!data || typeof data !== "object" || typeof data.instanceId !== "string" || data.instanceId.length === 0) {
|
|
292
|
+
console.warn("failed to deserialize session.canvas.closed payload");
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
this.removeOpenCanvas(data.instanceId);
|
|
296
|
+
}
|
|
297
|
+
removeOpenCanvas(instanceId) {
|
|
298
|
+
this.openCanvasInstances = this.openCanvasInstances.filter(
|
|
299
|
+
(open) => open.instanceId !== instanceId
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
upsertOpenCanvas(instance) {
|
|
303
|
+
const index = this.openCanvasInstances.findIndex(
|
|
304
|
+
(open) => open.instanceId === instance.instanceId
|
|
305
|
+
);
|
|
306
|
+
if (index >= 0) {
|
|
307
|
+
this.openCanvasInstances[index] = instance;
|
|
308
|
+
} else {
|
|
309
|
+
this.openCanvasInstances.push(instance);
|
|
269
310
|
}
|
|
270
311
|
}
|
|
271
312
|
/**
|
|
@@ -432,7 +473,7 @@ class CopilotSession {
|
|
|
432
473
|
throw toCanvasRpcError(error);
|
|
433
474
|
}
|
|
434
475
|
},
|
|
435
|
-
async
|
|
476
|
+
async invoke(params) {
|
|
436
477
|
const canvas = self.canvases.get(params.canvasId);
|
|
437
478
|
if (!canvas) throw new Error(`No canvas registered with id "${params.canvasId}"`);
|
|
438
479
|
const handler = canvas.actionHandlers.get(params.actionName);
|
|
@@ -547,10 +588,10 @@ class CopilotSession {
|
|
|
547
588
|
this._capabilities = capabilities ?? {};
|
|
548
589
|
}
|
|
549
590
|
/**
|
|
550
|
-
* Snapshot of canvas instances
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
* has no effect on the session.
|
|
591
|
+
* Snapshot of canvas instances currently known to be open for this session.
|
|
592
|
+
* Populated from the `session.resume` response and live `session.canvas.opened`
|
|
593
|
+
* and `session.canvas.closed` events. Returns a defensive copy — mutating the
|
|
594
|
+
* returned array has no effect on the session.
|
|
554
595
|
*/
|
|
555
596
|
get openCanvases() {
|
|
556
597
|
return [...this.openCanvasInstances];
|
package/dist/client.js
CHANGED
|
@@ -54,6 +54,15 @@ function toWireCustomAgents(agents) {
|
|
|
54
54
|
return { ...rest, mcpServers: toWireMcpServers(mcpServers) };
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
+
function toWireLargeOutput(config) {
|
|
58
|
+
if (!config) return void 0;
|
|
59
|
+
const { outputDirectory, ...rest } = config;
|
|
60
|
+
const wire = { ...rest };
|
|
61
|
+
if (outputDirectory !== void 0) {
|
|
62
|
+
wire.outputDir = outputDirectory;
|
|
63
|
+
}
|
|
64
|
+
return wire;
|
|
65
|
+
}
|
|
57
66
|
function toolFilterListToArray(value) {
|
|
58
67
|
if (value === void 0) {
|
|
59
68
|
return void 0;
|
|
@@ -606,7 +615,17 @@ class CopilotClient {
|
|
|
606
615
|
/** Mode-specific defaults spread under the caller's config (app values win). */
|
|
607
616
|
configDefaultsForMode() {
|
|
608
617
|
if (this.options.mode === "empty") {
|
|
609
|
-
return {
|
|
618
|
+
return {
|
|
619
|
+
enableSessionTelemetry: false,
|
|
620
|
+
mcpOAuthTokenStorage: "in-memory",
|
|
621
|
+
skipEmbeddingRetrieval: true,
|
|
622
|
+
embeddingCacheStorage: "in-memory",
|
|
623
|
+
enableOnDemandInstructionDiscovery: false,
|
|
624
|
+
enableFileHooks: false,
|
|
625
|
+
enableHostGitOperations: false,
|
|
626
|
+
enableSessionStore: false,
|
|
627
|
+
enableSkills: false
|
|
628
|
+
};
|
|
610
629
|
}
|
|
611
630
|
return {};
|
|
612
631
|
}
|
|
@@ -692,51 +711,64 @@ class CopilotClient {
|
|
|
692
711
|
}
|
|
693
712
|
config = { ...this.configDefaultsForMode(), ...config };
|
|
694
713
|
config.systemMessage = this.getSystemMessageConfigForMode(config.systemMessage);
|
|
695
|
-
const
|
|
696
|
-
const
|
|
697
|
-
|
|
698
|
-
this.connection,
|
|
699
|
-
void 0,
|
|
700
|
-
this.onGetTraceContext
|
|
701
|
-
);
|
|
702
|
-
session.registerTools(config.tools);
|
|
703
|
-
session.registerCanvases(config.canvases);
|
|
704
|
-
session.registerCommands(config.commands);
|
|
705
|
-
session.registerPermissionHandler(config.onPermissionRequest);
|
|
706
|
-
if (config.onUserInputRequest) {
|
|
707
|
-
session.registerUserInputHandler(config.onUserInputRequest);
|
|
708
|
-
}
|
|
709
|
-
if (config.onElicitationRequest) {
|
|
710
|
-
session.registerElicitationHandler(config.onElicitationRequest);
|
|
711
|
-
}
|
|
712
|
-
if (config.onExitPlanModeRequest) {
|
|
713
|
-
session.registerExitPlanModeHandler(config.onExitPlanModeRequest);
|
|
714
|
-
}
|
|
715
|
-
if (config.onAutoModeSwitchRequest) {
|
|
716
|
-
session.registerAutoModeSwitchHandler(config.onAutoModeSwitchRequest);
|
|
717
|
-
}
|
|
718
|
-
if (config.hooks) {
|
|
719
|
-
session.registerHooks(config.hooks);
|
|
720
|
-
}
|
|
714
|
+
const callerSessionId = config.sessionId;
|
|
715
|
+
const useServerGeneratedId = config.cloud != null && callerSessionId == null;
|
|
716
|
+
const localSessionId = useServerGeneratedId ? void 0 : callerSessionId ?? randomUUID();
|
|
721
717
|
const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(
|
|
722
718
|
config.systemMessage
|
|
723
719
|
);
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
720
|
+
const initializeSession = (sessionId) => {
|
|
721
|
+
const s = new CopilotSession(
|
|
722
|
+
sessionId,
|
|
723
|
+
this.connection,
|
|
724
|
+
void 0,
|
|
725
|
+
this.onGetTraceContext
|
|
726
|
+
);
|
|
727
|
+
s.registerTools(config.tools);
|
|
728
|
+
s.registerCanvases(config.canvases);
|
|
729
|
+
s.registerCommands(config.commands);
|
|
730
|
+
s.registerPermissionHandler(config.onPermissionRequest);
|
|
731
|
+
if (config.onUserInputRequest) {
|
|
732
|
+
s.registerUserInputHandler(config.onUserInputRequest);
|
|
733
|
+
}
|
|
734
|
+
if (config.onElicitationRequest) {
|
|
735
|
+
s.registerElicitationHandler(config.onElicitationRequest);
|
|
736
|
+
}
|
|
737
|
+
if (config.onExitPlanModeRequest) {
|
|
738
|
+
s.registerExitPlanModeHandler(config.onExitPlanModeRequest);
|
|
739
|
+
}
|
|
740
|
+
if (config.onAutoModeSwitchRequest) {
|
|
741
|
+
s.registerAutoModeSwitchHandler(config.onAutoModeSwitchRequest);
|
|
742
|
+
}
|
|
743
|
+
if (config.hooks) {
|
|
744
|
+
s.registerHooks(config.hooks);
|
|
745
|
+
}
|
|
746
|
+
if (transformCallbacks) {
|
|
747
|
+
s.registerTransformCallbacks(transformCallbacks);
|
|
748
|
+
}
|
|
749
|
+
if (config.onEvent) {
|
|
750
|
+
s.on(config.onEvent);
|
|
751
|
+
}
|
|
752
|
+
this.sessions.set(sessionId, s);
|
|
753
|
+
this.setupSessionFs(s, config);
|
|
754
|
+
return s;
|
|
755
|
+
};
|
|
756
|
+
let session;
|
|
757
|
+
let registeredId;
|
|
758
|
+
if (localSessionId !== void 0) {
|
|
759
|
+
session = initializeSession(localSessionId);
|
|
760
|
+
registeredId = localSessionId;
|
|
729
761
|
}
|
|
730
|
-
this.sessions.set(sessionId, session);
|
|
731
|
-
this.setupSessionFs(session, config);
|
|
732
762
|
const toolFilterOptions = this.resolveToolFilterOptions(config);
|
|
733
763
|
try {
|
|
734
764
|
const response = await this.connection.sendRequest("session.create", {
|
|
735
765
|
...await getTraceContext(this.onGetTraceContext),
|
|
736
766
|
model: config.model,
|
|
737
|
-
sessionId,
|
|
767
|
+
sessionId: localSessionId,
|
|
738
768
|
clientName: config.clientName,
|
|
739
769
|
reasoningEffort: config.reasoningEffort,
|
|
770
|
+
reasoningSummary: config.reasoningSummary,
|
|
771
|
+
contextTier: config.contextTier,
|
|
740
772
|
tools: config.tools?.map((tool) => ({
|
|
741
773
|
name: tool.name,
|
|
742
774
|
description: tool.description,
|
|
@@ -747,6 +779,7 @@ class CopilotClient {
|
|
|
747
779
|
canvases: config.canvases?.map((canvas) => canvas.declaration),
|
|
748
780
|
requestCanvasRenderer: config.requestCanvasRenderer,
|
|
749
781
|
requestExtensions: config.requestExtensions,
|
|
782
|
+
extensionSdkPath: config.extensionSdkPath,
|
|
750
783
|
extensionInfo: config.extensionInfo,
|
|
751
784
|
commands: config.commands?.map((cmd) => ({
|
|
752
785
|
name: cmd.name,
|
|
@@ -759,9 +792,11 @@ class CopilotClient {
|
|
|
759
792
|
provider: config.provider,
|
|
760
793
|
enableSessionTelemetry: config.enableSessionTelemetry,
|
|
761
794
|
modelCapabilities: config.modelCapabilities,
|
|
795
|
+
largeOutput: toWireLargeOutput(config.largeOutput),
|
|
762
796
|
requestPermission: !!config.onPermissionRequest,
|
|
763
797
|
requestUserInput: !!config.onUserInputRequest,
|
|
764
798
|
requestElicitation: !!config.onElicitationRequest,
|
|
799
|
+
...config.enableMcpApps ? { requestMcpApps: true } : {},
|
|
765
800
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
766
801
|
requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
|
|
767
802
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
@@ -769,13 +804,23 @@ class CopilotClient {
|
|
|
769
804
|
streaming: config.streaming,
|
|
770
805
|
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
771
806
|
mcpServers: toWireMcpServers(config.mcpServers),
|
|
807
|
+
mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
|
|
772
808
|
envValueMode: "direct",
|
|
773
809
|
customAgents: toWireCustomAgents(config.customAgents),
|
|
774
810
|
defaultAgent: config.defaultAgent,
|
|
775
811
|
agent: config.agent,
|
|
776
|
-
configDir: config.
|
|
812
|
+
configDir: config.configDirectory,
|
|
777
813
|
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
814
|
+
skipEmbeddingRetrieval: config.skipEmbeddingRetrieval,
|
|
815
|
+
embeddingCacheStorage: config.embeddingCacheStorage,
|
|
816
|
+
organizationCustomInstructions: config.organizationCustomInstructions,
|
|
817
|
+
enableOnDemandInstructionDiscovery: config.enableOnDemandInstructionDiscovery,
|
|
818
|
+
enableFileHooks: config.enableFileHooks,
|
|
819
|
+
enableHostGitOperations: config.enableHostGitOperations,
|
|
820
|
+
enableSessionStore: config.enableSessionStore,
|
|
821
|
+
enableSkills: config.enableSkills,
|
|
778
822
|
skillDirectories: config.skillDirectories,
|
|
823
|
+
pluginDirectories: config.pluginDirectories,
|
|
779
824
|
instructionDirectories: config.instructionDirectories,
|
|
780
825
|
disabledSkills: config.disabledSkills,
|
|
781
826
|
infiniteSessions: config.infiniteSessions,
|
|
@@ -783,12 +828,30 @@ class CopilotClient {
|
|
|
783
828
|
remoteSession: config.remoteSession,
|
|
784
829
|
cloud: config.cloud
|
|
785
830
|
});
|
|
786
|
-
const {
|
|
831
|
+
const {
|
|
832
|
+
sessionId: returnedSessionId,
|
|
833
|
+
workspacePath,
|
|
834
|
+
capabilities
|
|
835
|
+
} = response;
|
|
836
|
+
if (!returnedSessionId) {
|
|
837
|
+
throw new Error("session.create response did not include a sessionId");
|
|
838
|
+
}
|
|
839
|
+
if (localSessionId !== void 0 && localSessionId !== returnedSessionId) {
|
|
840
|
+
throw new Error(
|
|
841
|
+
`session.create returned sessionId ${returnedSessionId} but the caller requested ${localSessionId}`
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
if (session === void 0) {
|
|
845
|
+
session = initializeSession(returnedSessionId);
|
|
846
|
+
registeredId = returnedSessionId;
|
|
847
|
+
}
|
|
787
848
|
session["_workspacePath"] = workspacePath;
|
|
788
849
|
session.setCapabilities(capabilities);
|
|
789
850
|
await this.updateSessionOptionsForMode(session, config);
|
|
790
851
|
} catch (e) {
|
|
791
|
-
|
|
852
|
+
if (registeredId !== void 0) {
|
|
853
|
+
this.sessions.delete(registeredId);
|
|
854
|
+
}
|
|
792
855
|
throw e;
|
|
793
856
|
}
|
|
794
857
|
return session;
|
|
@@ -867,6 +930,8 @@ class CopilotClient {
|
|
|
867
930
|
clientName: config.clientName,
|
|
868
931
|
model: config.model,
|
|
869
932
|
reasoningEffort: config.reasoningEffort,
|
|
933
|
+
reasoningSummary: config.reasoningSummary,
|
|
934
|
+
contextTier: config.contextTier,
|
|
870
935
|
systemMessage: wireSystemMessage,
|
|
871
936
|
availableTools: toolFilterOptions.availableTools,
|
|
872
937
|
excludedTools: toolFilterOptions.excludedTools,
|
|
@@ -882,6 +947,7 @@ class CopilotClient {
|
|
|
882
947
|
canvases: config.canvases?.map((canvas) => canvas.declaration),
|
|
883
948
|
requestCanvasRenderer: config.requestCanvasRenderer,
|
|
884
949
|
requestExtensions: config.requestExtensions,
|
|
950
|
+
extensionSdkPath: config.extensionSdkPath,
|
|
885
951
|
extensionInfo: config.extensionInfo,
|
|
886
952
|
commands: config.commands?.map((cmd) => ({
|
|
887
953
|
name: cmd.name,
|
|
@@ -889,27 +955,39 @@ class CopilotClient {
|
|
|
889
955
|
})),
|
|
890
956
|
provider: config.provider,
|
|
891
957
|
modelCapabilities: config.modelCapabilities,
|
|
958
|
+
largeOutput: toWireLargeOutput(config.largeOutput),
|
|
892
959
|
requestPermission: config.onPermissionRequest !== defaultJoinSessionPermissionHandler,
|
|
893
960
|
requestUserInput: !!config.onUserInputRequest,
|
|
894
961
|
requestElicitation: !!config.onElicitationRequest,
|
|
962
|
+
...config.enableMcpApps ? { requestMcpApps: true } : {},
|
|
895
963
|
requestExitPlanMode: !!config.onExitPlanModeRequest,
|
|
896
964
|
requestAutoModeSwitch: !!config.onAutoModeSwitchRequest,
|
|
897
965
|
hooks: !!(config.hooks && Object.values(config.hooks).some(Boolean)),
|
|
898
966
|
workingDirectory: config.workingDirectory,
|
|
899
|
-
configDir: config.
|
|
967
|
+
configDir: config.configDirectory,
|
|
900
968
|
enableConfigDiscovery: config.enableConfigDiscovery,
|
|
969
|
+
skipEmbeddingRetrieval: config.skipEmbeddingRetrieval,
|
|
970
|
+
embeddingCacheStorage: config.embeddingCacheStorage,
|
|
971
|
+
organizationCustomInstructions: config.organizationCustomInstructions,
|
|
972
|
+
enableOnDemandInstructionDiscovery: config.enableOnDemandInstructionDiscovery,
|
|
973
|
+
enableFileHooks: config.enableFileHooks,
|
|
974
|
+
enableHostGitOperations: config.enableHostGitOperations,
|
|
975
|
+
enableSessionStore: config.enableSessionStore,
|
|
976
|
+
enableSkills: config.enableSkills,
|
|
901
977
|
streaming: config.streaming,
|
|
902
978
|
includeSubAgentStreamingEvents: config.includeSubAgentStreamingEvents ?? true,
|
|
903
979
|
mcpServers: toWireMcpServers(config.mcpServers),
|
|
980
|
+
mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
|
|
904
981
|
envValueMode: "direct",
|
|
905
982
|
customAgents: toWireCustomAgents(config.customAgents),
|
|
906
983
|
defaultAgent: config.defaultAgent,
|
|
907
984
|
agent: config.agent,
|
|
908
985
|
skillDirectories: config.skillDirectories,
|
|
986
|
+
pluginDirectories: config.pluginDirectories,
|
|
909
987
|
instructionDirectories: config.instructionDirectories,
|
|
910
988
|
disabledSkills: config.disabledSkills,
|
|
911
989
|
infiniteSessions: config.infiniteSessions,
|
|
912
|
-
|
|
990
|
+
disableResume: config.suppressResumeEvent,
|
|
913
991
|
continuePendingWork: config.continuePendingWork,
|
|
914
992
|
gitHubToken: config.gitHubToken,
|
|
915
993
|
remoteSession: config.remoteSession,
|
package/dist/extension.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CopilotSession } from "./session.js";
|
|
2
2
|
import { type ExtensionInfo, type PermissionHandler, type ResumeSessionConfig } from "./types.js";
|
|
3
3
|
export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclaration, type CanvasHostContext, type CanvasJsonSchema, type CanvasOptions, } from "./canvas.js";
|
|
4
|
-
export type JoinSessionConfig = Omit<ResumeSessionConfig, "onPermissionRequest"> & {
|
|
4
|
+
export type JoinSessionConfig = Omit<ResumeSessionConfig, "onPermissionRequest" | "extensionSdkPath"> & {
|
|
5
5
|
onPermissionRequest?: PermissionHandler;
|
|
6
6
|
};
|
|
7
7
|
export type { ExtensionInfo };
|
package/dist/extension.js
CHANGED
|
@@ -15,8 +15,10 @@ async function joinSession(config = {}) {
|
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
const client = new CopilotClient({ _internalConnection: { kind: "parent-process" } });
|
|
18
|
+
const { extensionSdkPath: _stripped, ...rest } = config;
|
|
19
|
+
void _stripped;
|
|
18
20
|
return client.resumeSession(sessionId, {
|
|
19
|
-
...
|
|
21
|
+
...rest,
|
|
20
22
|
onPermissionRequest: config.onPermissionRequest ?? defaultJoinSessionPermissionHandler,
|
|
21
23
|
suppressResumeEvent: config.suppressResumeEvent ?? true
|
|
22
24
|
});
|