@github/copilot-sdk 1.0.25 → 1.0.26
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 +15 -23
- package/dist/cjs/cliVersion.js +1 -1
- package/dist/cjs/client.js +101 -13
- package/dist/cjs/generated/rpc.js +48 -2
- package/dist/cjs/host.js +7 -1
- package/dist/cjs/session.js +140 -14
- package/dist/cliVersion.d.ts +1 -1
- package/dist/cliVersion.js +1 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +104 -14
- package/dist/generated/rpc.d.ts +361 -22
- package/dist/generated/rpc.js +48 -2
- package/dist/generated/session-events.d.ts +90 -1
- package/dist/host.d.ts +41 -1
- package/dist/host.js +7 -1
- package/dist/index.d.ts +2 -2
- package/dist/session.d.ts +10 -7
- package/dist/session.js +146 -15
- package/dist/types.d.ts +18 -16
- package/package.json +12 -12
|
@@ -9,7 +9,7 @@ export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
|
9
9
|
/**
|
|
10
10
|
* Union of all session event variants emitted by the Copilot CLI runtime.
|
|
11
11
|
*/
|
|
12
|
-
export type SessionEvent = StartEvent | ResumeEvent | RemoteSteerableChangedEvent | ErrorEvent | IdleEvent | AutopilotStoppedEvent | TitleChangedEvent | ScheduleCreatedEvent | ScheduleCancelledEvent | ScheduleRearmedEvent | AutopilotObjectiveChangedEvent | InfoEvent | IndexedSearchEvent | WarningEvent | ModelChangeEvent | ModelDeselectedEvent | AutoTierRecommendationEvent | AutoTierSwitchFailedEvent | ModeChangedEvent | ModeNoticeDeliveredEvent | SessionLimitsChangedEvent | PermissionsChangedEvent | PlanChangedEvent | TodosChangedEvent | WorkspaceFileChangedEvent | HandoffEvent | TruncationEvent | SnapshotRewindEvent | ShutdownEvent | UsageCheckpointEvent | ProviderQuotaObservationEvent | ContextChangedEvent | UsageInfoEvent | ContextClearedEvent | CompactionStartEvent | CompactionCompleteEvent | TaskCompleteEvent | CompletionReceiptEvent | FusionRouteStartedEvent | FusionRouteFailedEvent | FusionResolvedEvent | FusionCompletedEvent | PermissionRecoveryEvent | UserMessageEvent | PendingMessagesModifiedEvent | AssistantTurnStartEvent | AssistantIntentEvent | AssistantFusionPhaseStartedEvent | AssistantFusionPhaseActivityEvent | AssistantFusionPhaseCompletedEvent | AssistantFusionPhaseFailedEvent | AssistantServerToolProgressEvent | AssistantReasoningEvent | AssistantReasoningDeltaEvent | AssistantToolCallDeltaEvent | AssistantStreamingDeltaEvent | AssistantMessageEvent | AssistantMessageStartEvent | AssistantMessageDeltaEvent | AssistantTurnEndEvent | AssistantIdleEvent | AssistantUsageEvent | ModelCallFailureEvent | ModelCallFinishedEvent | AbortEvent | ToolUserRequestedEvent | ToolExecutionStartEvent | ToolExecutionPartialResultEvent | ToolShellOutputEvent | ToolExecutionProgressEvent | ToolExecutionCompleteEvent | ToolSearchActivatedEvent | SkillInvokedEvent | SubagentStartedEvent | SubagentConfiguredEvent | SubagentCompletedEvent | SubagentFailedEvent | SubagentSelectedEvent | SubagentDeselectedEvent | HookStartEvent | HookEndEvent | HookProgressEvent | BinaryAssetEvent | SystemMessageEvent | SystemNotificationEvent | PermissionRequestedEvent | PermissionCompletedEvent | PermissionCarriedForwardEvent | PermissionMessageAuthorizationEvent | PermissionMessageAuthorizationReadEvent | PermissionMessageAuthorizationDegradedEvent | PermissionAssentDetectedEvent | PermissionContextualAuthorizationEvent | UserInputRequestedEvent | UserInputCompletedEvent | ElicitationRequestedEvent | ElicitationCompletedEvent | SamplingRequestedEvent | SamplingCompletedEvent | McpOauthRequiredEvent | McpOauthCompletedEvent | McpOauthRecoveryCompletedEvent | McpHeadersRefreshRequiredEvent | McpHeadersRefreshCompletedEvent | CustomNotificationEvent | UIEphemeralQueryEvent | ExternalToolRequestedEvent | ExternalToolCompletedEvent | CommandQueuedEvent | CommandExecuteEvent | CommandCompletedEvent | AutoModeSwitchRequestedEvent | AutoModeSwitchCompletedEvent | SessionLimitsExhaustedRequestedEvent | SessionLimitsExhaustedCompletedEvent | AutoModeResolvedEvent | ManagedPluginProgressEvent | ManagedSettingsResolvedEvent | ManagedSettingsEnforcedEvent | CommandsChangedEvent | CapabilitiesChangedEvent | ExitPlanModeRequestedEvent | ExitPlanModeCompletedEvent | HumanResponseRecordedEvent | ToolsUpdatedEvent | BackgroundTasksChangedEvent | WorkflowRunUpdatedEvent | WorkflowRunStartedEvent | WorkflowRunSettledEvent | SkillsLoadedEvent | CustomAgentsUpdatedEvent | McpServersLoadedEvent | McpServerStatusChangedEvent | McpServerToolsLoadedEvent | McpServerRemovedEvent | McpServerNeedsReconnectEvent | McpToolsListChangedEvent | McpResourcesListChangedEvent | McpPromptsListChangedEvent | ExtensionsLoadedEvent | CanvasOpenedEvent | CanvasRegistryChangedEvent | CanvasClosedEvent | CanvasUnavailableEvent | CanvasRecordedEvent | CanvasRemovedEvent | ExtensionsAttachmentsPushedEvent | McpAppToolCallCompleteEvent;
|
|
12
|
+
export type SessionEvent = StartEvent | ResumeEvent | RemoteSteerableChangedEvent | ErrorEvent | IdleEvent | AutopilotStoppedEvent | TitleChangedEvent | ScheduleCreatedEvent | ScheduleCancelledEvent | ScheduleRearmedEvent | AutopilotObjectiveChangedEvent | InfoEvent | IndexedSearchEvent | WarningEvent | ModelChangeEvent | ModelDeselectedEvent | AutoTierRecommendationEvent | AutoTierSwitchFailedEvent | ModeChangedEvent | ModeNoticeDeliveredEvent | SessionLimitsChangedEvent | PermissionsChangedEvent | PlanChangedEvent | TodosChangedEvent | WorkspaceFileChangedEvent | HandoffEvent | TruncationEvent | SnapshotRewindEvent | ShutdownEvent | UsageCheckpointEvent | ProviderQuotaObservationEvent | ContextChangedEvent | UsageInfoEvent | ContextClearedEvent | CompactionStartEvent | CompactionCompleteEvent | TaskCompleteEvent | CompletionReceiptEvent | FusionRouteStartedEvent | FusionRouteFailedEvent | FusionResolvedEvent | FusionCompletedEvent | PermissionRecoveryEvent | UserMessageEvent | PendingMessagesModifiedEvent | AssistantTurnStartEvent | AssistantIntentEvent | AssistantFusionPhaseStartedEvent | AssistantFusionPhaseActivityEvent | AssistantFusionPhaseCompletedEvent | AssistantFusionPhaseFailedEvent | AssistantServerToolProgressEvent | AssistantReasoningEvent | AssistantReasoningDeltaEvent | AssistantToolCallDeltaEvent | AssistantStreamingDeltaEvent | AssistantMessageEvent | AssistantMessageStartEvent | AssistantMessageDeltaEvent | AssistantTurnEndEvent | AssistantIdleEvent | AssistantUsageEvent | ModelCallFailureEvent | ModelCallFinishedEvent | AbortEvent | ToolUserRequestedEvent | ToolExecutionStartEvent | ToolExecutionPartialResultEvent | ToolShellOutputEvent | ToolExecutionProgressEvent | ToolExecutionCompleteEvent | ToolSearchActivatedEvent | SkillInvokedEvent | SubagentStartedEvent | SubagentConfiguredEvent | SubagentCompletedEvent | SubagentFailedEvent | SubagentSelectedEvent | SubagentDeselectedEvent | HookStartEvent | HookEndEvent | HookProgressEvent | BinaryAssetEvent | SystemMessageEvent | InstructionUpdateEvent | SystemNotificationEvent | PermissionRequestedEvent | PermissionCompletedEvent | PermissionCarriedForwardEvent | PermissionMessageAuthorizationEvent | PermissionMessageAuthorizationReadEvent | PermissionMessageAuthorizationDegradedEvent | PermissionAssentDetectedEvent | PermissionContextualAuthorizationEvent | UserInputRequestedEvent | UserInputCompletedEvent | ElicitationRequestedEvent | ElicitationCompletedEvent | SamplingRequestedEvent | SamplingCompletedEvent | McpOauthRequiredEvent | McpOauthCompletedEvent | McpOauthRecoveryCompletedEvent | McpHeadersRefreshRequiredEvent | McpHeadersRefreshCompletedEvent | CustomNotificationEvent | UIEphemeralQueryEvent | ExternalToolRequestedEvent | ExternalToolCompletedEvent | CommandQueuedEvent | CommandExecuteEvent | CommandCompletedEvent | AutoModeSwitchRequestedEvent | AutoModeSwitchCompletedEvent | SessionLimitsExhaustedRequestedEvent | SessionLimitsExhaustedCompletedEvent | AutoModeResolvedEvent | ManagedPluginProgressEvent | ManagedSettingsResolvedEvent | ManagedSettingsEnforcedEvent | CommandsChangedEvent | CapabilitiesChangedEvent | ExitPlanModeRequestedEvent | ExitPlanModeCompletedEvent | HumanResponseRecordedEvent | ToolsUpdatedEvent | BackgroundTasksChangedEvent | WorkflowRunUpdatedEvent | WorkflowRunStartedEvent | WorkflowRunSettledEvent | SkillsLoadedEvent | CustomAgentsUpdatedEvent | McpServersLoadedEvent | McpServerStatusChangedEvent | McpServerToolsLoadedEvent | McpServerRemovedEvent | McpServerNeedsReconnectEvent | McpToolsListChangedEvent | McpResourcesListChangedEvent | McpPromptsListChangedEvent | ExtensionsLoadedEvent | CanvasOpenedEvent | CanvasRegistryChangedEvent | CanvasClosedEvent | CanvasUnavailableEvent | CanvasRecordedEvent | CanvasRemovedEvent | ExtensionsAttachmentsPushedEvent | McpAppToolCallCompleteEvent;
|
|
13
13
|
/**
|
|
14
14
|
* Extensible routing preference for the virtual `auto` model. New identifiers must be advertised and enabled by the provider. `fast` is an integrator-only latency preset.
|
|
15
15
|
*/
|
|
@@ -1078,6 +1078,40 @@ export type SystemMessageRole =
|
|
|
1078
1078
|
"system"
|
|
1079
1079
|
/** Developer instruction message. */
|
|
1080
1080
|
| "developer";
|
|
1081
|
+
/**
|
|
1082
|
+
* Authority responsible for an instruction update
|
|
1083
|
+
*/
|
|
1084
|
+
export type InstructionUpdateAuthority =
|
|
1085
|
+
/** The runtime generated the instruction. */
|
|
1086
|
+
"runtime"
|
|
1087
|
+
/** The SDK host supplied the instruction. */
|
|
1088
|
+
| "host"
|
|
1089
|
+
/** Managed policy supplied the instruction. */
|
|
1090
|
+
| "managedPolicy";
|
|
1091
|
+
/**
|
|
1092
|
+
* Earliest legal insertion boundary for an instruction update
|
|
1093
|
+
*/
|
|
1094
|
+
export type InstructionUpdateBoundary =
|
|
1095
|
+
/** Insert after the current tool-result run and before the next model request. */
|
|
1096
|
+
"afterToolResults"
|
|
1097
|
+
/** Insert immediately before the next model request at a provider-legal boundary. */
|
|
1098
|
+
| "nextModelRequest";
|
|
1099
|
+
/**
|
|
1100
|
+
* Deterministic behavior when the active provider cannot represent the requested update
|
|
1101
|
+
*/
|
|
1102
|
+
export type InstructionUpdateFallback =
|
|
1103
|
+
/** Rebuild the leading system prompt rather than silently dropping the update. */
|
|
1104
|
+
"rebuildSystemPrompt"
|
|
1105
|
+
/** Reject the update without changing authoritative instructions. */
|
|
1106
|
+
| "reject";
|
|
1107
|
+
/**
|
|
1108
|
+
* How long an instruction update remains authoritative
|
|
1109
|
+
*/
|
|
1110
|
+
export type InstructionUpdateLifetime =
|
|
1111
|
+
/** Persists in event order across replay, resume, rewind, fork, and compaction. */
|
|
1112
|
+
"persistent"
|
|
1113
|
+
/** Applies only to the current turn and is not restored from durable history. */
|
|
1114
|
+
| "turn";
|
|
1081
1115
|
/**
|
|
1082
1116
|
* Structured metadata identifying what triggered this notification
|
|
1083
1117
|
*/
|
|
@@ -2740,6 +2774,10 @@ export interface ModeNoticeDeliveredData {
|
|
|
2740
2774
|
* Model-visible transition notice persisted for a mid-turn delivery
|
|
2741
2775
|
*/
|
|
2742
2776
|
content?: string;
|
|
2777
|
+
/**
|
|
2778
|
+
* Whether the model-visible transition notice was persisted separately as an instruction.update event
|
|
2779
|
+
*/
|
|
2780
|
+
instructionUpdatePersisted?: boolean;
|
|
2743
2781
|
mode: SessionMode;
|
|
2744
2782
|
}
|
|
2745
2783
|
/**
|
|
@@ -4553,6 +4591,10 @@ export interface FusionRouteFailedData {
|
|
|
4553
4591
|
* Concrete model selected as the deterministic fallback.
|
|
4554
4592
|
*/
|
|
4555
4593
|
fallbackModel: string;
|
|
4594
|
+
/**
|
|
4595
|
+
* Identifier of the HydraFusion turn whose routing failed; its fallback phase runs under the same id. Absent on events written before it was recorded.
|
|
4596
|
+
*/
|
|
4597
|
+
fusionId?: string;
|
|
4556
4598
|
/**
|
|
4557
4599
|
* HydraFusion routing policy requested for the turn.
|
|
4558
4600
|
*/
|
|
@@ -9112,6 +9154,53 @@ export interface SystemMessageMetadata {
|
|
|
9112
9154
|
[k: string]: JsonValue | undefined;
|
|
9113
9155
|
};
|
|
9114
9156
|
}
|
|
9157
|
+
/**
|
|
9158
|
+
* Session event "instruction.update". An authoritative developer-instruction update. Event order defines instruction order. Persistent updates are durable and restore across replay, resume, rewind, fork, and compaction; turn-scoped updates must be emitted with ephemeral=true and are never restored.
|
|
9159
|
+
*/
|
|
9160
|
+
export interface InstructionUpdateEvent {
|
|
9161
|
+
/**
|
|
9162
|
+
* Sub-agent instance identifier. Absent for events from the root/main agent and session-level events.
|
|
9163
|
+
*/
|
|
9164
|
+
agentId?: string;
|
|
9165
|
+
data: InstructionUpdateData;
|
|
9166
|
+
/**
|
|
9167
|
+
* When true, the event is transient and not persisted to the session event log on disk
|
|
9168
|
+
*/
|
|
9169
|
+
ephemeral?: boolean;
|
|
9170
|
+
/**
|
|
9171
|
+
* Unique event identifier (UUID v4), generated when the event is emitted
|
|
9172
|
+
*/
|
|
9173
|
+
id: string;
|
|
9174
|
+
/**
|
|
9175
|
+
* ID of the chronologically preceding event in the session, forming a linked chain. Null for the first event.
|
|
9176
|
+
*/
|
|
9177
|
+
parentId: string | null;
|
|
9178
|
+
/**
|
|
9179
|
+
* ISO 8601 timestamp when the event was created
|
|
9180
|
+
*/
|
|
9181
|
+
timestamp: string;
|
|
9182
|
+
/**
|
|
9183
|
+
* Type discriminator. Always "instruction.update".
|
|
9184
|
+
*/
|
|
9185
|
+
type: "instruction.update";
|
|
9186
|
+
}
|
|
9187
|
+
/**
|
|
9188
|
+
* An authoritative developer-instruction update. Event order defines instruction order. Persistent updates are durable and restore across replay, resume, rewind, fork, and compaction; turn-scoped updates must be emitted with ephemeral=true and are never restored.
|
|
9189
|
+
*/
|
|
9190
|
+
export interface InstructionUpdateData {
|
|
9191
|
+
authority: InstructionUpdateAuthority;
|
|
9192
|
+
boundary: InstructionUpdateBoundary;
|
|
9193
|
+
/**
|
|
9194
|
+
* Authoritative instruction text. Empty or whitespace-only content is rejected.
|
|
9195
|
+
*/
|
|
9196
|
+
content: string;
|
|
9197
|
+
fallback: InstructionUpdateFallback;
|
|
9198
|
+
lifetime: InstructionUpdateLifetime;
|
|
9199
|
+
/**
|
|
9200
|
+
* Optional stable source name for diagnostics and future host-authored updates.
|
|
9201
|
+
*/
|
|
9202
|
+
name?: string;
|
|
9203
|
+
}
|
|
9115
9204
|
/**
|
|
9116
9205
|
* Session event "system.notification". System-generated notification for runtime events like background task completion
|
|
9117
9206
|
*/
|
package/dist/host.d.ts
CHANGED
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
import type { HostExitedNotification, HostPublishSessionResult, HostUnpublishSessionResult, HostListSessionsResult, HostLocalServerOptions, HostGitHubEnvironmentOptions } from "./generated/rpc.js";
|
|
2
2
|
import type { CopilotSession } from "./session.js";
|
|
3
3
|
import type { SessionConfig, ResumeSessionConfig } from "./types.js";
|
|
4
|
+
/** Verified host admission identity, independent of inference authentication. @experimental */
|
|
5
|
+
export type AhpSessionAuthentication = {
|
|
6
|
+
mode: "github";
|
|
7
|
+
identity: string;
|
|
8
|
+
} | {
|
|
9
|
+
mode: "custom";
|
|
10
|
+
identity: string;
|
|
11
|
+
} | {
|
|
12
|
+
mode: "none";
|
|
13
|
+
};
|
|
14
|
+
/** Explicit host-wide admission policy. @experimental */
|
|
15
|
+
export type AhpHostAuthentication = {
|
|
16
|
+
mode: "github";
|
|
17
|
+
} | {
|
|
18
|
+
mode: "none";
|
|
19
|
+
} | {
|
|
20
|
+
mode: "custom";
|
|
21
|
+
/** Stable owner identity. Every accepted credential must match exactly. */
|
|
22
|
+
requireIdentity: string;
|
|
23
|
+
/** Receives a decrypted admission token, never used as an inference credential. */
|
|
24
|
+
authenticate: (request: {
|
|
25
|
+
token: string;
|
|
26
|
+
signal: AbortSignal;
|
|
27
|
+
}) => Promise<{
|
|
28
|
+
identity: string;
|
|
29
|
+
/** Required future RFC3339 expiration, enforced by the host. */
|
|
30
|
+
expiresAt: string;
|
|
31
|
+
} | null>;
|
|
32
|
+
};
|
|
4
33
|
/** Host-selected defaults for a fresh application-owned session. @experimental */
|
|
5
34
|
export interface AhpSessionCreateRequest {
|
|
35
|
+
/** Trusted admission context supplied by the host, not by the connecting client. */
|
|
36
|
+
authentication: AhpSessionAuthentication;
|
|
6
37
|
/** Pass these settings to createSession, adding your prompt, tools and callbacks. */
|
|
7
38
|
config: Omit<SessionConfig, "onPermissionRequest">;
|
|
8
39
|
/** Aborted when participation ends, including timeout or owner disconnection. */
|
|
@@ -10,6 +41,8 @@ export interface AhpSessionCreateRequest {
|
|
|
10
41
|
}
|
|
11
42
|
/** Host-selected settings for resuming a durable application-owned AHP session. @experimental */
|
|
12
43
|
export interface AhpSessionResumeRequest {
|
|
44
|
+
/** Trusted admission context under the application's current host policy. */
|
|
45
|
+
authentication: AhpSessionAuthentication;
|
|
13
46
|
sessionId: string;
|
|
14
47
|
/** Pass to resumeSession, adding application tools, hooks and callbacks. */
|
|
15
48
|
config: Omit<ResumeSessionConfig, "onPermissionRequest">;
|
|
@@ -30,12 +63,16 @@ export type AhpHostExit = HostExitedNotification;
|
|
|
30
63
|
* @experimental
|
|
31
64
|
*/
|
|
32
65
|
export interface AhpHostOptions {
|
|
66
|
+
/** Required even in copilot-cli client mode. Anonymous access must be explicitly selected. */
|
|
67
|
+
authentication: AhpHostAuthentication;
|
|
33
68
|
/** Stable catalog identity; must agree with githubEnvironment.computeId when both are supplied. */
|
|
34
69
|
computeId?: string;
|
|
35
70
|
/** Enable a local WebSocket listener; an empty object selects loopback defaults. */
|
|
36
71
|
localServer?: HostLocalServerOptions;
|
|
37
|
-
/** Register a Mission Control environment and enable remote WPS connections. */
|
|
72
|
+
/** Register a Mission Control environment and enable remote WPS connections; requires github authentication. */
|
|
38
73
|
githubEnvironment?: HostGitHubEnvironmentOptions;
|
|
74
|
+
/** Remote creation admission, independent of factories. Omitted means denied. */
|
|
75
|
+
allowCreatingNewSessions?: boolean;
|
|
39
76
|
/** Called at most once when hosting ends, not on runtime process death. Local, never serialized. */
|
|
40
77
|
onExit?: (exit: AhpHostExit) => void;
|
|
41
78
|
/**
|
|
@@ -73,6 +110,7 @@ export declare class AhpHost {
|
|
|
73
110
|
private readonly publishHostSession;
|
|
74
111
|
private readonly listHostSessions;
|
|
75
112
|
private readonly unpublishHostSession;
|
|
113
|
+
private readonly updateCreationPolicy;
|
|
76
114
|
readonly hostId: string;
|
|
77
115
|
/** Local WebSocket URL. Absent when only the GitHub environment is enabled. */
|
|
78
116
|
readonly url: string | undefined;
|
|
@@ -84,6 +122,8 @@ export declare class AhpHost {
|
|
|
84
122
|
readonly pid: number | undefined;
|
|
85
123
|
/** Ask the runtime to stop the listener and await its cleanup, on every call. */
|
|
86
124
|
dispose(): Promise<void>;
|
|
125
|
+
/** Change subsequent remote admissions without disconnecting clients; admitted creation may finish. */
|
|
126
|
+
setAllowCreatingNewSessions(allowed: boolean): Promise<void>;
|
|
87
127
|
/** Publish an attached application session into the durable compute-scoped host catalog. */
|
|
88
128
|
publishSession(sessionId: string): Promise<HostPublishSessionResult>;
|
|
89
129
|
/**
|
package/dist/host.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
class AhpHost {
|
|
2
2
|
/** @internal */
|
|
3
|
-
constructor(info, disposeHost, publishHostSession, listHostSessions, unpublishHostSession) {
|
|
3
|
+
constructor(info, disposeHost, publishHostSession, listHostSessions, unpublishHostSession, updateCreationPolicy) {
|
|
4
4
|
this.disposeHost = disposeHost;
|
|
5
5
|
this.publishHostSession = publishHostSession;
|
|
6
6
|
this.listHostSessions = listHostSessions;
|
|
7
7
|
this.unpublishHostSession = unpublishHostSession;
|
|
8
|
+
this.updateCreationPolicy = updateCreationPolicy;
|
|
8
9
|
this.hostId = info.hostId;
|
|
9
10
|
this.url = info.url;
|
|
10
11
|
this.environmentId = info.environmentId;
|
|
@@ -15,6 +16,7 @@ class AhpHost {
|
|
|
15
16
|
publishHostSession;
|
|
16
17
|
listHostSessions;
|
|
17
18
|
unpublishHostSession;
|
|
19
|
+
updateCreationPolicy;
|
|
18
20
|
hostId;
|
|
19
21
|
/** Local WebSocket URL. Absent when only the GitHub environment is enabled. */
|
|
20
22
|
url;
|
|
@@ -28,6 +30,10 @@ class AhpHost {
|
|
|
28
30
|
dispose() {
|
|
29
31
|
return this.disposeHost();
|
|
30
32
|
}
|
|
33
|
+
/** Change subsequent remote admissions without disconnecting clients; admitted creation may finish. */
|
|
34
|
+
setAllowCreatingNewSessions(allowed) {
|
|
35
|
+
return this.updateCreationPolicy(allowed);
|
|
36
|
+
}
|
|
31
37
|
/** Publish an attached application session into the durable compute-scoped host catalog. */
|
|
32
38
|
publishSession(sessionId) {
|
|
33
39
|
return this.publishHostSession(sessionId);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { CopilotClient } from "./client.js";
|
|
7
7
|
export type { HostLocalServerOptions, HostGitHubEnvironmentOptions, ModelGetReasoningSummariesRequest, ModelGetReasoningSummariesResult, SandboxConfig, AutopilotOptions, } from "./generated/rpc.js";
|
|
8
|
-
export { AhpHost, type AhpHostExit, type AhpHostOptions, type AhpSessionCreateRequest, type AhpSessionResumeRequest, } from "./host.js";
|
|
8
|
+
export { AhpHost, type AhpHostExit, type AhpHostOptions, type AhpHostAuthentication, type AhpSessionAuthentication, type AhpSessionCreateRequest, type AhpSessionResumeRequest, } from "./host.js";
|
|
9
9
|
export { DisableBypassPermissionsModes, RuntimeConnection } from "./types.js";
|
|
10
10
|
export { BuiltInTools, ToolSet } from "./toolSet.js";
|
|
11
11
|
export { CopilotSession, type AssistantMessageEvent } from "./session.js";
|
|
@@ -13,5 +13,5 @@ export { defineWorkflow, WorkflowResumeError, isWorkflowRunTerminal } from "./wo
|
|
|
13
13
|
export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclaration, type CanvasHostContext, type CanvasHostContextCapabilities, type CanvasJsonSchema, type CanvasOptions, } from "./canvas.js";
|
|
14
14
|
export { defineTool, approveAll, createAttributedPermissionResult, convertMcpCallToolResult, createSessionFsAdapter, CopilotRequestHandler, CopilotWebSocketHandler, CopilotWebSocketCloseStatus, CopilotWebSocketForwarder, SessionFsSqliteTransactionFailure, SessionFsWriteFailure, SYSTEM_MESSAGE_SECTIONS, } from "./types.js";
|
|
15
15
|
export type * from "./generated/session-events.js";
|
|
16
|
-
export type { AskUserVariant, CommandContext, CommandDefinition, CommandHandler, CanvasProviderIdentity, CloudSessionOptions, CloudSessionRepository, AuthIdentityMetadata, AuthInfoType, ConnectorAccountRequest, ConnectorAvailability, ConnectorCapabilities, ConnectorCatalogEntry, ConnectorCatalogResult, ConnectorCatalogStatus, ConnectorConnectRequest, ConnectorConnectResult, ConnectorContinueRequest, ConnectorDisconnectResult, ConnectorMcpStatus, ConnectorReconcileRequest, ConnectorRuntimeStatus, ConnectorSessionAccount, ConnectorSessionAccountResult, ConnectorStatus, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AgentStopHandler, AgentStopHookInput, AgentStopHookOutput, SubagentStartHandler, SubagentStartHookInput, SubagentStartHookOutput, SubagentStopHandler, SubagentStopHookInput, SubagentStopHookOutput, UserPromptTransformedHandler, UserPromptTransformedHookInput, UserPromptTransformedHookOutput, CopilotClientInfo, CopilotClientMode, CopilotClientOptions, InstallationConfirmationHandler, InstallationConfirmationRequest, InstallationConfirmationResponse, InstallationDecision, InstallationReview, McpInstallationReview, CopilotExpAssignmentResponse, StdioRuntimeConnection, InProcessRuntimeConnection, TcpRuntimeConnection, UriRuntimeConnection, ChildProcessRuntimeConnection, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExpConfigEntry, ExpFlagValue, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExtensionLaunchProfile, ExtensionLaunchProvider, ExtensionLaunchProviderResolveRequest, ExtensionLaunchProviderResolveResult, ExtensionInfo, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, GitHubMcpToolConfig, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTokenProvider, GitHubTokenProviderArgs, GitHubTokenProviderResult, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, ExtensionContextAttachment, MessageOptions, ResponseSchema, MessageSource, ManagedSettings, ManagedSettingsPermissions, ModelBilling, ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, AutoTier, CapiSessionOptions, CurrentModel, ModelSwitchAutoTierResult, ModelSwitchAutoTierStatus, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, NamedProviderConfig, PermissionHandler, PermissionRequest, PermissionRequestedData, PermissionRequestedEvent, PermissionRequestResult, AttributedPermissionResult, PermissionDecisionContext, PermissionDecisionOutcome, PermissionDecisionSource, PermissionDecisionSurface, PermissionResponseCapability, ProviderConfig, ProviderConfigModelProvider, ProviderModelConfig, ProviderTokenArgs, RemoteSessionMode, SandboxConfigSource, ResumeSessionConfig, TranscriptRecovery, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, WorkingDirectoryTrust, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventMetadata, SessionLifecycleEventType, SessionLifecycleHandler, SessionHooks, SessionCreatedEvent, SessionDeletedEvent, SessionUpdatedEvent, SessionForegroundEvent, SessionBackgroundEvent, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SessionFsSqliteQueryResult, SessionFsSqliteQueryType, SessionFsSqliteProvider, SessionFsSqliteStatement, SessionFsSqliteTransactionErrorClass, SkillProvider, SkillProviderCallOptions, SkillProviderDescriptor, CopilotRequestContext, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolNamespace, CurrentToolMetadata, ToolTelemetry, ToolResultObject, ToolSearchConfig, ImageGenerationConfig, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
|
|
16
|
+
export type { AskUserVariant, CommandContext, CommandDefinition, CommandHandler, CanvasProviderIdentity, CloudSessionOptions, CloudSessionRepository, AuthIdentityMetadata, AuthInfoType, ConnectorAccountRequest, ConnectorAvailability, ConnectorCapabilities, ConnectorCatalogEntry, ConnectorCatalogResult, ConnectorCatalogStatus, ConnectorConnectRequest, ConnectorConnectResult, ConnectorContinueRequest, ConnectorDisconnectResult, ConnectorMcpStatus, ConnectorReconcileRequest, ConnectorRuntimeStatus, ConnectorSessionAccount, ConnectorSessionAccountResult, ConnectorStatus, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AgentStopHandler, AgentStopHookInput, AgentStopHookOutput, SubagentStartHandler, SubagentStartHookInput, SubagentStartHookOutput, SubagentStopHandler, SubagentStopHookInput, SubagentStopHookOutput, UserPromptTransformedHandler, UserPromptTransformedHookInput, UserPromptTransformedHookOutput, CopilotClientInfo, CopilotClientMode, CopilotClientOptions, EntraAuthConfig, InstallationConfirmationHandler, InstallationConfirmationRequest, InstallationConfirmationResponse, InstallationDecision, InstallationReview, McpInstallationReview, CopilotExpAssignmentResponse, StdioRuntimeConnection, InProcessRuntimeConnection, TcpRuntimeConnection, UriRuntimeConnection, ChildProcessRuntimeConnection, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExpConfigEntry, ExpFlagValue, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExtensionLaunchProfile, ExtensionLaunchProvider, ExtensionLaunchProviderResolveRequest, ExtensionLaunchProviderResolveResult, ExtensionInfo, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, GitHubMcpToolConfig, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTokenProvider, GitHubTokenProviderArgs, GitHubTokenProviderResult, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, ExtensionContextAttachment, MessageOptions, ResponseSchema, MessageSource, ManagedSettings, ManagedSettingsPermissions, ModelBilling, ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, AutoTier, CapiSessionOptions, CurrentModel, ModelSwitchAutoTierResult, ModelSwitchAutoTierStatus, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, NamedProviderConfig, PermissionHandler, PermissionRequest, PermissionRequestedData, PermissionRequestedEvent, PermissionRequestResult, AttributedPermissionResult, PermissionDecisionContext, PermissionDecisionOutcome, PermissionDecisionSource, PermissionDecisionSurface, PermissionResponseCapability, ProviderConfig, ProviderConfigModelProvider, ProviderModelConfig, ProviderTokenArgs, RemoteSessionMode, SandboxConfigSource, ResumeSessionConfig, TranscriptRecovery, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, WorkingDirectoryTrust, SessionEvent, SessionEventHandler, SessionEventPayload, SessionEventType, SessionLifecycleEvent, SessionLifecycleEventMetadata, SessionLifecycleEventType, SessionLifecycleHandler, SessionHooks, SessionCreatedEvent, SessionDeletedEvent, SessionUpdatedEvent, SessionForegroundEvent, SessionBackgroundEvent, SessionContext, SessionListFilter, SessionMetadata, SessionUiApi, SessionFsConfig, SessionFsProvider, SessionFsFileInfo, SessionFsSqliteQueryResult, SessionFsSqliteQueryType, SessionFsSqliteProvider, SessionFsSqliteStatement, SessionFsSqliteTransactionErrorClass, SkillProvider, SkillProviderCallOptions, SkillProviderDescriptor, CopilotRequestContext, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, ToolNamespace, CurrentToolMetadata, ToolTelemetry, ToolResultObject, ToolSearchConfig, ImageGenerationConfig, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
|
|
17
17
|
export type { JsonValue, WorkflowRunOptions, WorkflowResumeOptions, WorkflowLimitOverrides, WorkflowResumeErrorCode, SessionWorkflowApi, WorkflowAgentOptions, WorkflowContext, WorkflowDefinition, WorkflowHandle, WorkflowJsonSchema, WorkflowLimits, WorkflowMeta, WorkflowPipelineStage, WorkflowStepOptions, WorkflowRunResult, WorkflowRunStatus, WorkflowRunSummary, WorkflowListRunsOptions, WorkflowRunsPage, WorkflowRunDetail, WorkflowProgressPage, WorkflowProgressLine, WorkflowPhaseObservation, WorkflowPhaseStatus, WorkflowAgentSummary, } from "./workflow.js";
|
package/dist/session.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ export declare class CopilotSession {
|
|
|
71
71
|
private disconnected;
|
|
72
72
|
private readonly pendingResponseWaits;
|
|
73
73
|
private readonly pendingStructuredWaits;
|
|
74
|
+
private completionRpcUnsupported;
|
|
74
75
|
private disconnecting;
|
|
75
76
|
private onDisconnected?;
|
|
76
77
|
/**
|
|
@@ -143,14 +144,15 @@ export declare class CopilotSession {
|
|
|
143
144
|
*/
|
|
144
145
|
send(prompt: string): Promise<string>;
|
|
145
146
|
send(options: MessageOptions): Promise<string>;
|
|
147
|
+
private sendMessage;
|
|
148
|
+
private createSendParams;
|
|
146
149
|
/**
|
|
147
150
|
* Sends a message and waits for its response to complete.
|
|
148
151
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* assistant has finished processing the message.
|
|
152
|
+
* Supported local runtimes correlate completion and the response with this
|
|
153
|
+
* message. Unsupported runtimes retain the legacy non-Autopilot `session.idle`
|
|
154
|
+
* or request-correlated `session.autopilot_stopped` wait. Autopilot completion
|
|
155
|
+
* does not wait for or stop attached shells.
|
|
154
156
|
*
|
|
155
157
|
* Events are still delivered to handlers registered via {@link on} while waiting.
|
|
156
158
|
* Sub-agent events with a non-empty `agentId` do not complete the wait or supply its reply.
|
|
@@ -160,10 +162,10 @@ export declare class CopilotSession {
|
|
|
160
162
|
*
|
|
161
163
|
* @param options - The message options including the prompt and optional attachments
|
|
162
164
|
* @param timeout - Timeout in milliseconds (default: 60000). Controls how long to wait; does not abort in-flight agent work.
|
|
163
|
-
* @returns A promise that resolves with
|
|
165
|
+
* @returns A promise that resolves with this message's final assistant response,
|
|
164
166
|
* or undefined if no assistant message was received
|
|
165
167
|
* @throws Error if the run is aborted before completion
|
|
166
|
-
* @throws Error if the timeout is reached before
|
|
168
|
+
* @throws Error if the timeout is reached before completion
|
|
167
169
|
* @throws Error if the session has been disconnected or the connection fails
|
|
168
170
|
*
|
|
169
171
|
* @example
|
|
@@ -176,6 +178,7 @@ export declare class CopilotSession {
|
|
|
176
178
|
sendAndWait(prompt: string, timeout?: number): Promise<AssistantMessageEvent | undefined>;
|
|
177
179
|
sendAndWait<TResult>(options: MessageOptions | string, responseSchema: ResponseSchema<TResult>, timeout?: number): Promise<TResult>;
|
|
178
180
|
sendAndWait(options: MessageOptions, timeout?: number): Promise<AssistantMessageEvent | undefined>;
|
|
181
|
+
private sendWithCompletion;
|
|
179
182
|
private sendAndWaitForStructuredMessage;
|
|
180
183
|
private assertConnected;
|
|
181
184
|
/**
|
package/dist/session.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CancellationTokenSource,
|
|
4
|
+
ConnectionError,
|
|
5
|
+
ErrorCodes,
|
|
6
|
+
ResponseError
|
|
7
|
+
} from "vscode-jsonrpc/node.js";
|
|
3
8
|
import { createInternalSessionRpc, createSessionRpc } from "./generated/rpc.js";
|
|
4
9
|
import { CanvasError } from "./canvas.js";
|
|
5
10
|
import { getTraceContext } from "./telemetry.js";
|
|
@@ -293,6 +298,7 @@ class CopilotSession {
|
|
|
293
298
|
disconnected = false;
|
|
294
299
|
pendingResponseWaits = /* @__PURE__ */ new Set();
|
|
295
300
|
pendingStructuredWaits = /* @__PURE__ */ new Set();
|
|
301
|
+
completionRpcUnsupported = false;
|
|
296
302
|
disconnecting = false;
|
|
297
303
|
onDisconnected;
|
|
298
304
|
/** @internal Client session API handlers, populated by CopilotClient during create/resume. */
|
|
@@ -494,9 +500,22 @@ class CopilotSession {
|
|
|
494
500
|
}
|
|
495
501
|
async send(optionsOrPrompt) {
|
|
496
502
|
const options = typeof optionsOrPrompt === "string" ? { prompt: optionsOrPrompt } : optionsOrPrompt;
|
|
503
|
+
return this.sendMessage(options);
|
|
504
|
+
}
|
|
505
|
+
async sendMessage(options, cancelled) {
|
|
506
|
+
const message = await this.createSendParams(options);
|
|
507
|
+
if (cancelled?.()) {
|
|
508
|
+
throw new Error("Completion wait cancelled");
|
|
509
|
+
}
|
|
497
510
|
const response = await this.connection.sendRequest("session.send", {
|
|
498
|
-
...await getTraceContext(this.traceContextProvider),
|
|
499
511
|
sessionId: this.sessionId,
|
|
512
|
+
...message
|
|
513
|
+
});
|
|
514
|
+
return response.messageId;
|
|
515
|
+
}
|
|
516
|
+
async createSendParams(options) {
|
|
517
|
+
return {
|
|
518
|
+
...await getTraceContext(this.traceContextProvider),
|
|
500
519
|
prompt: options.prompt,
|
|
501
520
|
source: options.source,
|
|
502
521
|
displayPrompt: options.displayPrompt,
|
|
@@ -514,8 +533,7 @@ class CopilotSession {
|
|
|
514
533
|
}
|
|
515
534
|
}
|
|
516
535
|
} : {}
|
|
517
|
-
}
|
|
518
|
-
return response.messageId;
|
|
536
|
+
};
|
|
519
537
|
}
|
|
520
538
|
async sendAndWait(optionsOrPrompt, schemaOrTimeout, timeout) {
|
|
521
539
|
const options = typeof optionsOrPrompt === "string" ? { prompt: optionsOrPrompt } : optionsOrPrompt;
|
|
@@ -536,10 +554,39 @@ class CopilotSession {
|
|
|
536
554
|
"Structured output cannot be requested on an immediate steering message."
|
|
537
555
|
);
|
|
538
556
|
}
|
|
557
|
+
const startedAt = Date.now();
|
|
558
|
+
const completion = await this.sendWithCompletion(
|
|
559
|
+
typedSchema ? { ...options, responseSchema: typedSchema } : options,
|
|
560
|
+
effectiveTimeout
|
|
561
|
+
);
|
|
562
|
+
if (completion !== void 0) {
|
|
563
|
+
const message = completion.response;
|
|
564
|
+
if (message !== void 0 && (message.type !== "assistant.message" || message.agentId)) {
|
|
565
|
+
throw new Error("The runtime returned a non-assistant response.");
|
|
566
|
+
}
|
|
567
|
+
if (typedSchema || options.responseSchema) {
|
|
568
|
+
if (completion.aborted) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
"The requested run was aborted before a structured result was completed."
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
if (!message || message.data.toolRequests?.length || !message.data.content.trim()) {
|
|
574
|
+
throw new Error(
|
|
575
|
+
"The requested run completed without a structured assistant response."
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
return typedSchema ? typedSchema.parse(JSON.parse(message.data.content)) : message;
|
|
579
|
+
}
|
|
580
|
+
if (completion.aborted) {
|
|
581
|
+
throw new Error("The requested run was aborted before completion.");
|
|
582
|
+
}
|
|
583
|
+
return message;
|
|
584
|
+
}
|
|
585
|
+
const remainingTimeout = Math.max(0, effectiveTimeout - (Date.now() - startedAt));
|
|
539
586
|
if (typedSchema || options.responseSchema) {
|
|
540
587
|
const message = await this.sendAndWaitForStructuredMessage(
|
|
541
588
|
typedSchema ? { ...options, responseSchema: typedSchema } : options,
|
|
542
|
-
|
|
589
|
+
remainingTimeout
|
|
543
590
|
);
|
|
544
591
|
if (typedSchema) {
|
|
545
592
|
if (!message) {
|
|
@@ -609,14 +656,8 @@ class CopilotSession {
|
|
|
609
656
|
};
|
|
610
657
|
this.pendingResponseWaits.add(fail);
|
|
611
658
|
let timeoutId;
|
|
659
|
+
let waiting = true;
|
|
612
660
|
try {
|
|
613
|
-
messageId = await this.send(options);
|
|
614
|
-
admitted = true;
|
|
615
|
-
for (const event of buffered) {
|
|
616
|
-
if (event instanceof Error) fail(event);
|
|
617
|
-
else observe(event);
|
|
618
|
-
}
|
|
619
|
-
buffered.length = 0;
|
|
620
661
|
const timeoutPromise = new Promise((_, reject) => {
|
|
621
662
|
timeoutId = setTimeout(
|
|
622
663
|
() => reject(
|
|
@@ -624,15 +665,28 @@ class CopilotSession {
|
|
|
624
665
|
`Timeout after ${effectiveTimeout}ms waiting for response completion`
|
|
625
666
|
)
|
|
626
667
|
),
|
|
627
|
-
|
|
668
|
+
remainingTimeout
|
|
628
669
|
);
|
|
629
670
|
});
|
|
630
|
-
const outcome = await Promise.race([
|
|
671
|
+
const outcome = await Promise.race([
|
|
672
|
+
this.sendMessage(options, () => !waiting).then((id) => {
|
|
673
|
+
messageId = id;
|
|
674
|
+
admitted = true;
|
|
675
|
+
for (const event of buffered) {
|
|
676
|
+
if (event instanceof Error) fail(event);
|
|
677
|
+
else observe(event);
|
|
678
|
+
}
|
|
679
|
+
buffered.length = 0;
|
|
680
|
+
return outcomePromise;
|
|
681
|
+
}),
|
|
682
|
+
timeoutPromise
|
|
683
|
+
]);
|
|
631
684
|
if (outcome.kind === "error") {
|
|
632
685
|
throw outcome.error;
|
|
633
686
|
}
|
|
634
687
|
return outcome.message;
|
|
635
688
|
} finally {
|
|
689
|
+
waiting = false;
|
|
636
690
|
if (timeoutId !== void 0) {
|
|
637
691
|
clearTimeout(timeoutId);
|
|
638
692
|
}
|
|
@@ -641,6 +695,81 @@ class CopilotSession {
|
|
|
641
695
|
this.pendingResponseWaits.delete(fail);
|
|
642
696
|
}
|
|
643
697
|
}
|
|
698
|
+
async sendWithCompletion(options, timeout) {
|
|
699
|
+
if (this.completionRpcUnsupported) return void 0;
|
|
700
|
+
if (this.disconnected) throw new Error("Session is disconnected");
|
|
701
|
+
const cancellation = new CancellationTokenSource();
|
|
702
|
+
const dispatched = /* @__PURE__ */ new Set();
|
|
703
|
+
let completionEventId;
|
|
704
|
+
let resolveDispatched;
|
|
705
|
+
const dispatchCompleted = new Promise((resolve) => {
|
|
706
|
+
resolveDispatched = resolve;
|
|
707
|
+
});
|
|
708
|
+
const unsubscribe = this.on((event) => {
|
|
709
|
+
if (event.agentId || event.type !== "session.idle" && event.type !== "session.autopilot_stopped" && event.type !== "session.error") {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
dispatched.add(event.id);
|
|
713
|
+
if (event.id === completionEventId) resolveDispatched();
|
|
714
|
+
});
|
|
715
|
+
const drain = async (id) => {
|
|
716
|
+
if (id && !dispatched.has(id)) {
|
|
717
|
+
completionEventId = id;
|
|
718
|
+
await dispatchCompleted;
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
let fail;
|
|
722
|
+
const stopped = new Promise((_, reject) => {
|
|
723
|
+
fail = reject;
|
|
724
|
+
});
|
|
725
|
+
this.pendingResponseWaits.add(fail);
|
|
726
|
+
const timer = setTimeout(
|
|
727
|
+
() => fail(new Error(`Timeout after ${timeout}ms waiting for session.idle`)),
|
|
728
|
+
timeout
|
|
729
|
+
);
|
|
730
|
+
const operation = async () => {
|
|
731
|
+
try {
|
|
732
|
+
const message = await this.createSendParams(options);
|
|
733
|
+
if (cancellation.token.isCancellationRequested) {
|
|
734
|
+
throw new Error("Completion wait cancelled");
|
|
735
|
+
}
|
|
736
|
+
const result = await this.connection.sendRequest(
|
|
737
|
+
"session.sendAndWait",
|
|
738
|
+
{
|
|
739
|
+
sessionId: this.sessionId,
|
|
740
|
+
...message
|
|
741
|
+
},
|
|
742
|
+
cancellation.token
|
|
743
|
+
);
|
|
744
|
+
await drain(result.completionEventId);
|
|
745
|
+
return result;
|
|
746
|
+
} catch (error) {
|
|
747
|
+
if (error instanceof ResponseError && error.code === ErrorCodes.MethodNotFound) {
|
|
748
|
+
this.completionRpcUnsupported = true;
|
|
749
|
+
return void 0;
|
|
750
|
+
}
|
|
751
|
+
if (error instanceof ResponseError && typeof error.data === "object" && error.data !== null) {
|
|
752
|
+
if ("stack" in error.data && typeof error.data.stack === "string") {
|
|
753
|
+
error.stack = error.data.stack;
|
|
754
|
+
}
|
|
755
|
+
if ("completionEventId" in error.data && typeof error.data.completionEventId === "string") {
|
|
756
|
+
await drain(error.data.completionEventId);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
throw error;
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
try {
|
|
763
|
+
return await Promise.race([operation(), stopped]);
|
|
764
|
+
} finally {
|
|
765
|
+
clearTimeout(timer);
|
|
766
|
+
unsubscribe();
|
|
767
|
+
this.pendingResponseWaits.delete(fail);
|
|
768
|
+
resolveDispatched();
|
|
769
|
+
cancellation.cancel();
|
|
770
|
+
cancellation.dispose();
|
|
771
|
+
}
|
|
772
|
+
}
|
|
644
773
|
async sendAndWaitForStructuredMessage(options, timeout) {
|
|
645
774
|
if (this.disconnected) {
|
|
646
775
|
throw new Error("Session is disconnected");
|
|
@@ -690,12 +819,13 @@ class CopilotSession {
|
|
|
690
819
|
}
|
|
691
820
|
});
|
|
692
821
|
this.pendingStructuredWaits.add(fail);
|
|
822
|
+
let waiting = true;
|
|
693
823
|
const timer = setTimeout(
|
|
694
824
|
() => fail(new Error(`Timeout after ${timeout}ms waiting for the structured response`)),
|
|
695
825
|
timeout
|
|
696
826
|
);
|
|
697
827
|
try {
|
|
698
|
-
const sendOutcome = this.
|
|
828
|
+
const sendOutcome = this.sendMessage(options, () => !waiting).then(
|
|
699
829
|
(id) => {
|
|
700
830
|
if (!id) {
|
|
701
831
|
throw new Error(
|
|
@@ -716,6 +846,7 @@ class CopilotSession {
|
|
|
716
846
|
if (outcome.kind === "error") throw outcome.error;
|
|
717
847
|
return outcome.message;
|
|
718
848
|
} finally {
|
|
849
|
+
waiting = false;
|
|
719
850
|
clearTimeout(timer);
|
|
720
851
|
buffered.length = 0;
|
|
721
852
|
unsubscribe();
|
package/dist/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type { InstallationConfirmationHandler } from "./installationConfirmation
|
|
|
9
9
|
import type { AgentModelPolicy, AttachmentExtensionContext as GeneratedExtensionContextAttachment, AutoTier, PermissionRequest as GeneratedPermissionRequest, PermissionRequestedData as GeneratedPermissionRequestedData, PermissionRequestedEvent as GeneratedPermissionRequestedEvent, ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
|
|
10
10
|
import type { CopilotSession } from "./session.js";
|
|
11
11
|
import type { JsonValue } from "./workflow.js";
|
|
12
|
-
import type { ExtensionLaunchProviderHandler as GeneratedExtensionLaunchProvider, AutopilotOptions, GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, ModelBillingTokenPrices, DiagnosticsConfiguration, OpenCanvasInstance, ProtocolExternalToolNamespace,
|
|
12
|
+
import type { ExtensionLaunchProviderHandler as GeneratedExtensionLaunchProvider, AutopilotOptions, GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, ModelBillingTokenPrices, DiagnosticsConfiguration, OpenCanvasInstance, ProtocolExternalToolNamespace, CurrentToolMetadata, SandboxConfig } from "./generated/rpc.js";
|
|
13
13
|
import type { ToolSet } from "./toolSet.js";
|
|
14
14
|
export type { RemoteSessionMode } from "./generated/rpc.js";
|
|
15
15
|
export type { AutopilotOptions } from "./generated/rpc.js";
|
|
@@ -265,7 +265,14 @@ export interface CopilotClientInfo {
|
|
|
265
265
|
*/
|
|
266
266
|
integrationVersion?: string;
|
|
267
267
|
}
|
|
268
|
+
export type EntraAuthConfig = import("./generated/rpc.js").EntraAuthConfig;
|
|
268
269
|
export interface CopilotClientOptions {
|
|
270
|
+
/**
|
|
271
|
+
* Host application's Microsoft Entra registration, shared by its sessions.
|
|
272
|
+
* Required for built-in Entra sign-in and token renewal; other authentication methods remain available.
|
|
273
|
+
* @experimental
|
|
274
|
+
*/
|
|
275
|
+
entra?: EntraAuthConfig;
|
|
269
276
|
/**
|
|
270
277
|
* How to connect to the Copilot runtime. When omitted, defaults to
|
|
271
278
|
* {@link RuntimeConnection.forStdio} with the bundled runtime.
|
|
@@ -425,14 +432,6 @@ export interface CopilotClientOptions {
|
|
|
425
432
|
* @default undefined (disabled)
|
|
426
433
|
*/
|
|
427
434
|
sessionIdleTimeoutSeconds?: number;
|
|
428
|
-
/**
|
|
429
|
-
* Enable remote session support (Mission Control integration).
|
|
430
|
-
* When true, sessions in a GitHub repository working directory are
|
|
431
|
-
* accessible from GitHub web and mobile.
|
|
432
|
-
* Ignored when connecting to an existing runtime via {@link RuntimeConnection.forUri}.
|
|
433
|
-
* @default false
|
|
434
|
-
*/
|
|
435
|
-
enableRemoteSessions?: boolean;
|
|
436
435
|
/**
|
|
437
436
|
* Identity of the integrating application, forwarded to the runtime on the
|
|
438
437
|
* `server.connect` handshake. Declaring it lets the telemetry the runtime
|
|
@@ -680,6 +679,16 @@ export interface ImageGenerationConfig {
|
|
|
680
679
|
* or enforce enterprise policy.
|
|
681
680
|
*/
|
|
682
681
|
watermark?: boolean;
|
|
682
|
+
/**
|
|
683
|
+
* Experimental. Save generated and edited images under the session-state
|
|
684
|
+
* directory's `images` folder and give the model each path as a
|
|
685
|
+
* `saved_to:` line in the tool result. Defaults to true; set false to opt
|
|
686
|
+
* out. Subagents follow
|
|
687
|
+
* their parent's value unless they set their own. A failed save still
|
|
688
|
+
* returns the image. Sessions without a local session-state directory never
|
|
689
|
+
* save. Re-supply after cold resume. Does not enable image generation.
|
|
690
|
+
*/
|
|
691
|
+
saveToDisk?: boolean;
|
|
683
692
|
}
|
|
684
693
|
/**
|
|
685
694
|
* SDK-supplied override for the runtime's built-in tool-search behavior.
|
|
@@ -2718,13 +2727,6 @@ export interface SessionConfigBase {
|
|
|
2718
2727
|
* `skillDirectories` or `enableConfigDiscovery` settings.
|
|
2719
2728
|
*/
|
|
2720
2729
|
enableSkills?: boolean;
|
|
2721
|
-
/**
|
|
2722
|
-
* Per-session remote behavior control:
|
|
2723
|
-
* - `"off"` — local only, no remote export (default)
|
|
2724
|
-
* - `"export"` — export session events to GitHub without enabling remote steering
|
|
2725
|
-
* - `"on"` — export to GitHub AND enable remote steering
|
|
2726
|
-
*/
|
|
2727
|
-
remoteSession?: RemoteSessionMode;
|
|
2728
2730
|
/**
|
|
2729
2731
|
* Optional event handler that is registered on the session before the
|
|
2730
2732
|
* session.create RPC is issued. This guarantees that early events emitted
|