@github/copilot-sdk 1.0.14 → 1.0.15-preview.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/dist/index.d.ts CHANGED
@@ -8,8 +8,10 @@ export { DisableBypassPermissionsModes, RuntimeConnection } from "./types.js";
8
8
  export { BuiltInTools, ToolSet } from "./toolSet.js";
9
9
  export { CopilotSession, type AssistantMessageEvent } from "./session.js";
10
10
  export { defineFactory, FactoryResumeError, isFactoryRunTerminal } from "./factory.js";
11
+ export { defineWorkflow, WorkflowResumeError, isWorkflowRunTerminal } from "./workflow.js";
11
12
  export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclaration, type CanvasHostContext, type CanvasHostContextCapabilities, type CanvasJsonSchema, type CanvasOptions, } from "./canvas.js";
12
13
  export { defineTool, approveAll, createAttributedPermissionResult, convertMcpCallToolResult, createSessionFsAdapter, CopilotRequestHandler, CopilotWebSocketHandler, CopilotWebSocketCloseStatus, CopilotWebSocketForwarder, SessionFsSqliteTransactionFailure, SYSTEM_MESSAGE_SECTIONS, } from "./types.js";
13
14
  export type * from "./generated/session-events.js";
14
- export type { AskUserVariant, CommandContext, CommandDefinition, CommandHandler, CanvasProviderIdentity, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AgentStopHandler, AgentStopHookInput, AgentStopHookOutput, UserPromptTransformedHandler, UserPromptTransformedHookInput, UserPromptTransformedHookOutput, CopilotClientInfo, CopilotClientMode, CopilotClientOptions, CopilotExpAssignmentResponse, StdioRuntimeConnection, InProcessRuntimeConnection, TcpRuntimeConnection, UriRuntimeConnection, ChildProcessRuntimeConnection, CustomAgentConfig, ElicitationFieldValue, ElicitationHandler, ElicitationParams, ElicitationContext, ElicitationResult, ElicitationSchema, ElicitationSchemaField, ExpConfigEntry, ExpFlagValue, ExitPlanModeHandler, ExitPlanModeRequest, ExitPlanModeResult, ExtensionInfo, ForegroundSessionInfo, GetAuthStatusResponse, GetStatusResponse, GitHubMcpToolConfig, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTokenProvider, GitHubTokenProviderArgs, GitHubTokenProviderResult, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, FactoryLimits, FactoryMeta, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, MessageOptions, 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, ProviderModelConfig, ProviderTokenArgs, RemoteSessionMode, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, 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, CopilotRequestContext, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, CurrentToolMetadata, ToolTelemetry, ToolResultObject, ToolSearchConfig, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
15
+ export type { AskUserVariant, CommandContext, CommandDefinition, CommandHandler, CanvasProviderIdentity, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AgentStopHandler, AgentStopHookInput, AgentStopHookOutput, UserPromptTransformedHandler, UserPromptTransformedHookInput, UserPromptTransformedHookOutput, CopilotClientInfo, CopilotClientMode, CopilotClientOptions, 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, FactoryLimits, FactoryMeta, 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, ProviderModelConfig, ProviderTokenArgs, RemoteSessionMode, ResumeSessionConfig, SectionOverride, SectionOverrideAction, SectionTransformFn, SessionCapabilities, SessionConfig, SessionConfigBase, 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, CopilotRequestContext, SystemMessageAppendConfig, SystemMessageConfig, SystemMessageCustomizeConfig, SystemMessageReplaceConfig, SystemMessageSection, TelemetryConfig, TraceContext, TraceContextProvider, Tool, ToolHandler, ToolInvocation, CurrentToolMetadata, ToolTelemetry, ToolResultObject, ToolSearchConfig, TypedSessionEventHandler, TypedSessionLifecycleHandler, ZodSchema, } from "./types.js";
15
16
  export type { RunOptions, ResumeOptions, FactoryLimitOverrides, FactoryResumeErrorCode, SessionFactoryApi, FactoryAgentOptions, FactoryContext, FactoryDefinition, FactoryHandle, FactoryJsonSchema, JsonValue, FactoryPipelineStage, FactoryStepOptions, FactoryRunResult, FactoryRunStatus, FactoryRunSummary, FactoryListRunsOptions, FactoryRunsPage, FactoryRunDetail, FactoryProgressPage, FactoryProgressLine, FactoryPhaseObservation, FactoryPhaseStatus, FactoryAgentSummary, } from "./factory.js";
17
+ export type { 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/index.js CHANGED
@@ -3,6 +3,7 @@ import { DisableBypassPermissionsModes, RuntimeConnection } from "./types.js";
3
3
  import { BuiltInTools, ToolSet } from "./toolSet.js";
4
4
  import { CopilotSession } from "./session.js";
5
5
  import { defineFactory, FactoryResumeError, isFactoryRunTerminal } from "./factory.js";
6
+ import { defineWorkflow, WorkflowResumeError, isWorkflowRunTerminal } from "./workflow.js";
6
7
  import {
7
8
  Canvas,
8
9
  CanvasError,
@@ -37,6 +38,7 @@ export {
37
38
  SYSTEM_MESSAGE_SECTIONS,
38
39
  SessionFsSqliteTransactionFailure,
39
40
  ToolSet,
41
+ WorkflowResumeError,
40
42
  approveAll,
41
43
  convertMcpCallToolResult,
42
44
  createAttributedPermissionResult,
@@ -44,5 +46,7 @@ export {
44
46
  createSessionFsAdapter,
45
47
  defineFactory,
46
48
  defineTool,
47
- isFactoryRunTerminal
49
+ defineWorkflow,
50
+ isFactoryRunTerminal,
51
+ isWorkflowRunTerminal
48
52
  };
@@ -0,0 +1,4 @@
1
+ import type { ResponseSchema, ZodSchema } from "./types.js";
2
+ export declare function isZodSchema(value: unknown): value is ZodSchema;
3
+ export declare function toJsonSchema(schema: ZodSchema | Record<string, unknown> | undefined): Record<string, unknown> | undefined;
4
+ export declare function isResponseSchema(value: unknown): value is ResponseSchema;
package/dist/schema.js ADDED
@@ -0,0 +1,14 @@
1
+ function isZodSchema(value) {
2
+ return typeof value === "object" && value !== null && "toJSONSchema" in value && typeof value.toJSONSchema === "function";
3
+ }
4
+ function toJsonSchema(schema) {
5
+ return isZodSchema(schema) ? schema.toJSONSchema() : schema;
6
+ }
7
+ function isResponseSchema(value) {
8
+ return isZodSchema(value) && "parse" in value && typeof value.parse === "function";
9
+ }
10
+ export {
11
+ isResponseSchema,
12
+ isZodSchema,
13
+ toJsonSchema
14
+ };
package/dist/session.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { createSessionRpc } from "./generated/rpc.js";
2
2
  import type { ModelSwitchAutoTierResult } from "./generated/rpc.js";
3
3
  import type { OpenCanvasInstance } from "./generated/rpc.js";
4
- import type { MessageOptions, ContextTier, ReasoningEffort, ReasoningSummary, AutoTier, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TypedSessionEventHandler } from "./types.js";
4
+ import type { MessageOptions, ResponseSchema, ContextTier, ReasoningEffort, ReasoningSummary, AutoTier, ModelCapabilitiesOverride, SessionCapabilities, SessionEvent, SessionEventHandler, SessionEventType, SessionUiApi, TypedSessionEventHandler } from "./types.js";
5
5
  import { type SessionFactoryApi } from "./factory.js";
6
+ import { type SessionWorkflowApi } from "./workflow.js";
6
7
  /** Assistant message event - the final response from the assistant. */
7
8
  export type AssistantMessageEvent = Extract<SessionEvent, {
8
9
  type: "assistant.message";
@@ -50,6 +51,8 @@ export declare class CopilotSession {
50
51
  private commandHandlers;
51
52
  private factories;
52
53
  private factoryAbortControllers;
54
+ private workflows;
55
+ private workflowAbortControllers;
53
56
  private permissionHandler?;
54
57
  private mcpAuthHandler?;
55
58
  private userInputHandler?;
@@ -65,6 +68,7 @@ export declare class CopilotSession {
65
68
  private _capabilities;
66
69
  private openCanvasInstances;
67
70
  private disconnected;
71
+ private readonly pendingStructuredWaits;
68
72
  private disconnecting;
69
73
  private onDisconnected?;
70
74
  /**
@@ -74,6 +78,7 @@ export declare class CopilotSession {
74
78
  * change or be removed in future SDK or CLI releases.
75
79
  */
76
80
  readonly factory: SessionFactoryApi;
81
+ readonly workflow: SessionWorkflowApi;
77
82
  /**
78
83
  * Resolve a start/resume envelope into the terminal envelope callers expect.
79
84
  *
@@ -93,6 +98,18 @@ export declare class CopilotSession {
93
98
  * dropped invalidation from leaving the wait pending forever.
94
99
  */
95
100
  private waitForFactoryRun;
101
+ private settleWorkflowRun;
102
+ /**
103
+ * Resolve when a workflow run reaches a terminal status.
104
+ *
105
+ * The subscription is installed *before* the first read so a transition
106
+ * landing between the two cannot be missed, and re-reads are serialized so
107
+ * overlapping invalidation events cannot interleave — the run's revision
108
+ * advances once per operation, so a burst of events is common and must
109
+ * collapse into a single in-flight read. A bounded periodic re-read keeps a
110
+ * dropped invalidation from leaving the wait pending forever.
111
+ */
112
+ private waitForWorkflowRun;
96
113
  /**
97
114
  * Typed session-scoped RPC methods.
98
115
  */
@@ -122,13 +139,14 @@ export declare class CopilotSession {
122
139
  */
123
140
  get ui(): SessionUiApi;
124
141
  /**
125
- * Sends a message to this session and waits for the response.
142
+ * Sends a message to this session and returns once it is admitted.
126
143
  *
127
144
  * The message is processed asynchronously. Subscribe to events via {@link on}
128
145
  * to receive streaming responses and other session events.
129
146
  *
130
147
  * @param options - The message options including the prompt and optional attachments
131
- * @returns A promise that resolves with the message ID of the response
148
+ * @returns The submitted user message's ID, not an assistant response ID.
149
+ * When this send starts a run, root assistant messages carry it as originatingMessageId.
132
150
  * @throws Error if the session has been disconnected or the connection fails
133
151
  *
134
152
  * @example
@@ -149,6 +167,9 @@ export declare class CopilotSession {
149
167
  * assistant has finished processing the message.
150
168
  *
151
169
  * Events are still delivered to handlers registered via {@link on} while waiting.
170
+ * With a schema as the second argument, returns its parsed, validated result.
171
+ * Structured waits select only root-agent output originating from this send;
172
+ * other queued work may delay session.idle but cannot replace the result.
152
173
  *
153
174
  * @param options - The message options including the prompt and optional attachments
154
175
  * @param timeout - Timeout in milliseconds (default: 60000). Controls how long to wait; does not abort in-flight agent work.
@@ -165,7 +186,9 @@ export declare class CopilotSession {
165
186
  * ```
166
187
  */
167
188
  sendAndWait(prompt: string, timeout?: number): Promise<AssistantMessageEvent | undefined>;
189
+ sendAndWait<TResult>(options: MessageOptions | string, responseSchema: ResponseSchema<TResult>, timeout?: number): Promise<TResult>;
168
190
  sendAndWait(options: MessageOptions, timeout?: number): Promise<AssistantMessageEvent | undefined>;
191
+ private sendAndWaitForStructuredMessage;
169
192
  /**
170
193
  * Subscribes to events from this session.
171
194
  *