@github/copilot-sdk 1.0.14-preview.0 → 1.0.14-unstable.35049111350.g7f86a90
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 +4 -0
- package/dist/cjs/cliVersion.js +1 -1
- package/dist/cjs/factory.js +1 -0
- package/dist/cjs/generated/rpc.js +30 -12
- package/dist/cjs/session.js +55 -8
- package/dist/cliVersion.d.ts +1 -1
- package/dist/cliVersion.js +1 -1
- package/dist/factory.d.ts +42 -16
- package/dist/factory.js +1 -0
- package/dist/generated/rpc.d.ts +358 -28
- package/dist/generated/rpc.js +30 -12
- package/dist/generated/session-events.d.ts +61 -27
- package/dist/index.d.ts +1 -1
- package/dist/session.d.ts +1 -0
- package/dist/session.js +56 -9
- package/docs/factories.md +36 -19
- package/package.json +12 -10
package/dist/generated/rpc.js
CHANGED
|
@@ -732,15 +732,7 @@ function createInternalServerRpc(connection) {
|
|
|
732
732
|
*/
|
|
733
733
|
getBoardEntryCount: async (params) => connection.sendRequest("sessions.getBoardEntryCount", params),
|
|
734
734
|
/**
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
* @param params Params to attach an extension loader's tools to a session.
|
|
738
|
-
*
|
|
739
|
-
* @returns Handle for releasing the extension tool registration.
|
|
740
|
-
*/
|
|
741
|
-
registerExtensionToolsOnSession: async (params) => connection.sendRequest("sessions.registerExtensionToolsOnSession", params),
|
|
742
|
-
/**
|
|
743
|
-
* Attaches (or detaches) an in-process ExtensionController delegate for the given session, used by shared-API surfaces that need to query or modify the session's extension state. Pass `controller: undefined` to detach. Marked internal because the controller is an in-process object that cannot cross the JSON-RPC boundary. Disappears alongside `registerExtensionToolsOnSession`: once the runtime owns extension management, the public surface exposes list/enable/disable/reload as dedicated RPCs served by the runtime.
|
|
735
|
+
* Attaches (or detaches) an in-process ExtensionController delegate for the given session in a local host adapter. Pass `controller: undefined` to detach. Internal because the controller cannot cross the JSON-RPC boundary; the runtime manages its own session extension service.
|
|
744
736
|
*
|
|
745
737
|
* @param params Params to attach or detach an in-process ExtensionController delegate.
|
|
746
738
|
*/
|
|
@@ -849,11 +841,11 @@ function createSessionRpc(connection, sessionId) {
|
|
|
849
841
|
/** @experimental */
|
|
850
842
|
debug: {
|
|
851
843
|
/**
|
|
852
|
-
* Collects a
|
|
844
|
+
* Collects a session debug log bundle into a local archive or staging directory. Logs are redacted by default; redaction can be configured per caller-provided diagnostic entry. The runtime includes session-owned logs by default and accepts caller-provided diagnostic entries so host applications can add their own files without changing this API shape.
|
|
853
845
|
*
|
|
854
|
-
* @param params Options for collecting a
|
|
846
|
+
* @param params Options for collecting a session debug bundle with configurable redaction.
|
|
855
847
|
*
|
|
856
|
-
* @returns Result of collecting a
|
|
848
|
+
* @returns Result of collecting a session debug bundle.
|
|
857
849
|
*/
|
|
858
850
|
collectLogs: async (params) => connection.sendRequest("session.debug.collectLogs", { sessionId, ...params })
|
|
859
851
|
},
|
|
@@ -1163,6 +1155,32 @@ function createSessionRpc(connection, sessionId) {
|
|
|
1163
1155
|
* @param params Relative path and UTF-8 content for the workspace file to create or overwrite.
|
|
1164
1156
|
*/
|
|
1165
1157
|
createFile: async (params) => connection.sendRequest("session.workspaces.createFile", { sessionId, ...params }),
|
|
1158
|
+
/**
|
|
1159
|
+
* Returns metadata for a file or directory in the session workspace files directory.
|
|
1160
|
+
*
|
|
1161
|
+
* @param params Relative path of the workspace file or directory to inspect.
|
|
1162
|
+
*
|
|
1163
|
+
* @returns Filesystem metadata for a path in the session workspace files directory.
|
|
1164
|
+
*/
|
|
1165
|
+
statFile: async (params) => connection.sendRequest("session.workspaces.statFile", { sessionId, ...params }),
|
|
1166
|
+
/**
|
|
1167
|
+
* Creates a directory in the session workspace files directory.
|
|
1168
|
+
*
|
|
1169
|
+
* @param params Directory to create within the session workspace files directory.
|
|
1170
|
+
*/
|
|
1171
|
+
createDirectory: async (params) => connection.sendRequest("session.workspaces.createDirectory", { sessionId, ...params }),
|
|
1172
|
+
/**
|
|
1173
|
+
* Removes a file or directory from the session workspace files directory.
|
|
1174
|
+
*
|
|
1175
|
+
* @param params File or directory to remove from the session workspace files directory.
|
|
1176
|
+
*/
|
|
1177
|
+
removePath: async (params) => connection.sendRequest("session.workspaces.removePath", { sessionId, ...params }),
|
|
1178
|
+
/**
|
|
1179
|
+
* Renames a file or directory within the session workspace files directory.
|
|
1180
|
+
*
|
|
1181
|
+
* @param params Source and destination paths for a rename within the session workspace files directory.
|
|
1182
|
+
*/
|
|
1183
|
+
renamePath: async (params) => connection.sendRequest("session.workspaces.renamePath", { sessionId, ...params }),
|
|
1166
1184
|
/**
|
|
1167
1185
|
* Lists workspace checkpoints in chronological order.
|
|
1168
1186
|
*
|
|
@@ -482,6 +482,20 @@ export type AbortReason =
|
|
|
482
482
|
| "user_abort"
|
|
483
483
|
/** Autopilot stopped the run because the active objective reached its user-set --max-ai-credits limit. */
|
|
484
484
|
| "autopilot_credit_limit";
|
|
485
|
+
/**
|
|
486
|
+
* Configuration source: user, workspace, plugin, builtin, or managed
|
|
487
|
+
*/
|
|
488
|
+
export type McpServerSource =
|
|
489
|
+
/** Server configured in the user's global MCP configuration. */
|
|
490
|
+
"user"
|
|
491
|
+
/** Server configured by the current workspace. */
|
|
492
|
+
| "workspace"
|
|
493
|
+
/** Server contributed by an installed plugin. */
|
|
494
|
+
| "plugin"
|
|
495
|
+
/** Server bundled with the runtime. */
|
|
496
|
+
| "builtin"
|
|
497
|
+
/** Server supplied by a trusted host-managed catalog. */
|
|
498
|
+
| "managed";
|
|
485
499
|
/**
|
|
486
500
|
* Transport mechanism: stdio, http, sse (deprecated), or memory (in-process MCP server)
|
|
487
501
|
*/
|
|
@@ -565,18 +579,6 @@ export type SkillInvokedTrigger =
|
|
|
565
579
|
| "agent-invoked"
|
|
566
580
|
/** Skill content loaded as part of another context, such as a configured custom agent or subagent. */
|
|
567
581
|
| "context-load";
|
|
568
|
-
/**
|
|
569
|
-
* Where the model input for a task-tool sub-agent came from.
|
|
570
|
-
*/
|
|
571
|
-
export type SubagentTaskModelSource =
|
|
572
|
-
/** The spawning agent supplied the task tool's model argument. */
|
|
573
|
-
"task_argument"
|
|
574
|
-
/** The task omitted a model and the per-sub-agent settings entry supplied a concrete one. */
|
|
575
|
-
| "subagent_configuration"
|
|
576
|
-
/** The task omitted a model and the user-defined custom agent's definition supplied one. */
|
|
577
|
-
| "custom_agent_definition"
|
|
578
|
-
/** Neither the task call, the per-sub-agent settings entry, nor a custom agent definition supplied a model. */
|
|
579
|
-
| "unset";
|
|
580
582
|
/**
|
|
581
583
|
* Authority or runtime mechanism responsible for sub-agent model selection.
|
|
582
584
|
*/
|
|
@@ -595,6 +597,18 @@ export type SubagentModelSelectionSource =
|
|
|
595
597
|
| "agent_definition_default"
|
|
596
598
|
/** Runtime policy, Auto mode, or an experiment selected the model. */
|
|
597
599
|
| "runtime_policy";
|
|
600
|
+
/**
|
|
601
|
+
* Where the model input for a task-tool sub-agent came from.
|
|
602
|
+
*/
|
|
603
|
+
export type SubagentTaskModelSource =
|
|
604
|
+
/** The spawning agent supplied the task tool's model argument. */
|
|
605
|
+
"task_argument"
|
|
606
|
+
/** The task omitted a model and the per-sub-agent settings entry supplied a concrete one. */
|
|
607
|
+
| "subagent_configuration"
|
|
608
|
+
/** The task omitted a model and the user-defined custom agent's definition supplied one. */
|
|
609
|
+
| "custom_agent_definition"
|
|
610
|
+
/** Neither the task call, the per-sub-agent settings entry, nor a custom agent definition supplied a model. */
|
|
611
|
+
| "unset";
|
|
598
612
|
/**
|
|
599
613
|
* Binary asset type discriminator. Use "image" for images and "resource" otherwise.
|
|
600
614
|
*/
|
|
@@ -831,6 +845,8 @@ export type McpHeadersRefreshCompletedOutcome =
|
|
|
831
845
|
"headers"
|
|
832
846
|
/** The host responded with no dynamic headers. */
|
|
833
847
|
| "none"
|
|
848
|
+
/** The host credential broker rejected or failed the refresh. */
|
|
849
|
+
| "error"
|
|
834
850
|
/** No response arrived within the bounded window. */
|
|
835
851
|
| "timeout";
|
|
836
852
|
/**
|
|
@@ -976,18 +992,6 @@ export type AgentModelPolicy =
|
|
|
976
992
|
"preferred"
|
|
977
993
|
/** Require subagent execution to use one of the authored models. */
|
|
978
994
|
| "required";
|
|
979
|
-
/**
|
|
980
|
-
* Configuration source: user, workspace, plugin, or builtin
|
|
981
|
-
*/
|
|
982
|
-
export type McpServerSource =
|
|
983
|
-
/** Server configured in the user's global MCP configuration. */
|
|
984
|
-
"user"
|
|
985
|
-
/** Server configured by the current workspace. */
|
|
986
|
-
| "workspace"
|
|
987
|
-
/** Server contributed by an installed plugin. */
|
|
988
|
-
| "plugin"
|
|
989
|
-
/** Server bundled with the runtime. */
|
|
990
|
-
| "builtin";
|
|
991
995
|
/**
|
|
992
996
|
* Connection status: connected, failed, needs-auth, pending, disabled, stopped, or not_configured
|
|
993
997
|
*/
|
|
@@ -4745,6 +4749,10 @@ export interface AssistantMessageData {
|
|
|
4745
4749
|
* Model that produced this assistant message, if known
|
|
4746
4750
|
*/
|
|
4747
4751
|
model?: string;
|
|
4752
|
+
/**
|
|
4753
|
+
* Logical ID of the primary user message that initiated this run, matching the messageId returned by session.send (or the last messageId of session.sendMessages). Stable across model/tool iterations, steering messages, and stop-hook corrections. Subagent runs use their own initiating message ID, not the parent's. Absent for runs without an associated initiating message, such as empty batches.
|
|
4754
|
+
*/
|
|
4755
|
+
originatingMessageId?: string;
|
|
4748
4756
|
/**
|
|
4749
4757
|
* Actual output token count from the API response (completion_tokens), used for accurate token accounting
|
|
4750
4758
|
*/
|
|
@@ -5764,6 +5772,11 @@ export interface ToolExecutionStartData {
|
|
|
5764
5772
|
* @experimental
|
|
5765
5773
|
*/
|
|
5766
5774
|
fusion?: FusionAttribution;
|
|
5775
|
+
/**
|
|
5776
|
+
* Preferred lookup name for the MCP server hosting this tool: the configured (namespaced) config-map key when the tool carries one, otherwise the display name from `mcpServerName`. Present when the tool is an MCP tool; this is the name unrestricted provenance telemetry hashes so it joins with `mcp_server_setup`, which keys off the configured name too.
|
|
5777
|
+
*/
|
|
5778
|
+
mcpConfigServerName?: string;
|
|
5779
|
+
mcpConfigSource?: McpServerSource;
|
|
5767
5780
|
/**
|
|
5768
5781
|
* Name of the MCP server hosting this tool, when the tool is an MCP tool
|
|
5769
5782
|
*/
|
|
@@ -6012,6 +6025,12 @@ export interface ToolExecutionCompleteData {
|
|
|
6012
6025
|
* Whether this tool execution ran inside a sandbox container
|
|
6013
6026
|
*/
|
|
6014
6027
|
sandboxed?: boolean;
|
|
6028
|
+
/**
|
|
6029
|
+
* Experimental shell completion facts captured before the persisted result contents are stripped.
|
|
6030
|
+
*
|
|
6031
|
+
* @experimental
|
|
6032
|
+
*/
|
|
6033
|
+
shellExecution?: ToolExecutionCompleteShellExecution;
|
|
6015
6034
|
/**
|
|
6016
6035
|
* Whether the tool execution completed successfully
|
|
6017
6036
|
*/
|
|
@@ -6071,7 +6090,7 @@ export interface ToolExecutionCompleteResult {
|
|
|
6071
6090
|
*/
|
|
6072
6091
|
contents?: ToolExecutionCompleteContent[];
|
|
6073
6092
|
/**
|
|
6074
|
-
*
|
|
6093
|
+
* Detailed tool result for UI/timeline display, preserving complete content such as diffs for most tools. Successful skill invocations intentionally use the concise model-facing content here; the authoritative skill body is carried by the corresponding skill invocation event. Falls back to content when absent.
|
|
6075
6094
|
*/
|
|
6076
6095
|
detailedContent?: string;
|
|
6077
6096
|
/**
|
|
@@ -6485,6 +6504,16 @@ export interface ToolExecutionCompleteUIResourceMetaUIPermissionsGeolocation {
|
|
|
6485
6504
|
*/
|
|
6486
6505
|
export interface ToolExecutionCompleteUIResourceMetaUIPermissionsMicrophone {
|
|
6487
6506
|
}
|
|
6507
|
+
/**
|
|
6508
|
+
* Experimental shell completion facts retained independently of the full tool result.
|
|
6509
|
+
*/
|
|
6510
|
+
/** @experimental */
|
|
6511
|
+
export interface ToolExecutionCompleteShellExecution {
|
|
6512
|
+
/**
|
|
6513
|
+
* Process exit code reported by the shell driver.
|
|
6514
|
+
*/
|
|
6515
|
+
exitCode: number;
|
|
6516
|
+
}
|
|
6488
6517
|
/**
|
|
6489
6518
|
* Tool definition metadata, present for MCP tools with MCP Apps support
|
|
6490
6519
|
*/
|
|
@@ -6699,6 +6728,7 @@ export interface SubagentStartedData {
|
|
|
6699
6728
|
* Model the sub-agent will run with, when known at start.
|
|
6700
6729
|
*/
|
|
6701
6730
|
model?: string;
|
|
6731
|
+
modelSelectionSource?: SubagentModelSelectionSource;
|
|
6702
6732
|
/**
|
|
6703
6733
|
* Task-registry ID of the spawning sub-agent. Absent when the root session spawned this child.
|
|
6704
6734
|
*/
|
|
@@ -7073,7 +7103,7 @@ export interface HookStartData {
|
|
|
7073
7103
|
*/
|
|
7074
7104
|
hookType: string;
|
|
7075
7105
|
/**
|
|
7076
|
-
* Input data passed to the hook. For postToolUse hooks the retained copy served by session.eventLog.read (and by a resumed session)
|
|
7106
|
+
* Input data passed to the hook. For postToolUse hooks the retained copy served by session.eventLog.read (and by a resumed session) drops the tool result's inline `contents`/`uiResource`/`skillInvocation` and replaces duplicated text result fields with a `[copilot:elided ...]` marker; the live subscription stream still delivers the full value. Canonical tool output remains in the adjacent tool.execution_complete event, while an invoked skill's authoritative body remains in its skill invocation event.
|
|
7077
7107
|
*/
|
|
7078
7108
|
input?: JsonValue;
|
|
7079
7109
|
/**
|
|
@@ -7125,7 +7155,7 @@ export interface HookEndData {
|
|
|
7125
7155
|
*/
|
|
7126
7156
|
hookType: string;
|
|
7127
7157
|
/**
|
|
7128
|
-
* Output data produced by the hook
|
|
7158
|
+
* Output data produced by the hook. Durable and resumed postToolUse receipts may omit messages owned by a successful skill invocation and replace an unchanged skill sessionLog copy with an elision marker; hook-modified or re-sourced values are preserved, and the authoritative body remains in the skill invocation event.
|
|
7129
7159
|
*/
|
|
7130
7160
|
output?: JsonValue;
|
|
7131
7161
|
/**
|
|
@@ -11198,6 +11228,10 @@ export interface McpServersLoadedData {
|
|
|
11198
11228
|
* A single MCP server status summary in `session.mcp_servers_loaded`, including name, status, source, transport, and plugin metadata.
|
|
11199
11229
|
*/
|
|
11200
11230
|
export interface McpServersLoadedServer {
|
|
11231
|
+
/**
|
|
11232
|
+
* Human-readable display name supplied by a managed server catalog.
|
|
11233
|
+
*/
|
|
11234
|
+
displayName?: string;
|
|
11201
11235
|
/**
|
|
11202
11236
|
* Error message if the server failed to connect
|
|
11203
11237
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -12,4 +12,4 @@ export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclar
|
|
|
12
12
|
export { defineTool, approveAll, createAttributedPermissionResult, convertMcpCallToolResult, createSessionFsAdapter, CopilotRequestHandler, CopilotWebSocketHandler, CopilotWebSocketCloseStatus, CopilotWebSocketForwarder, SessionFsSqliteTransactionFailure, SYSTEM_MESSAGE_SECTIONS, } from "./types.js";
|
|
13
13
|
export type * from "./generated/session-events.js";
|
|
14
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 { RunOptions, ResumeOptions, FactoryResumeErrorCode, SessionFactoryApi, FactoryAgentOptions, FactoryContext, FactoryDefinition, FactoryHandle, FactoryJsonSchema, JsonValue, FactoryPipelineStage, FactoryStepOptions, FactoryRunResult, FactoryRunStatus, FactoryRunSummary, FactoryListRunsOptions, FactoryRunsPage, FactoryRunDetail, FactoryProgressPage, FactoryProgressLine, FactoryPhaseObservation, FactoryPhaseStatus, FactoryAgentSummary, } from "./factory.js";
|
|
15
|
+
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";
|
package/dist/session.d.ts
CHANGED
package/dist/session.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import { ConnectionError, ErrorCodes, ResponseError } from "vscode-jsonrpc/node.js";
|
|
3
|
-
import { createSessionRpc } from "./generated/rpc.js";
|
|
3
|
+
import { createInternalSessionRpc, createSessionRpc } from "./generated/rpc.js";
|
|
4
4
|
import { CanvasError } from "./canvas.js";
|
|
5
5
|
import { getTraceContext } from "./telemetry.js";
|
|
6
6
|
import { isAttributedPermissionResult } from "./types.js";
|
|
@@ -23,10 +23,14 @@ const factoryExecutionStore = new AsyncLocalStorage();
|
|
|
23
23
|
function throwIfFactoryExecutionIsActive() {
|
|
24
24
|
if (factoryExecutionStore.getStore()?.active) {
|
|
25
25
|
throw new Error(
|
|
26
|
-
"factory.run and factory.
|
|
26
|
+
"factory.run, factory.resume, and factory.pause are not allowed while a factory body is running on this call path."
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
function runInFactoryHelperScope(helperScope, callback) {
|
|
31
|
+
const current = factoryExecutionStore.getStore();
|
|
32
|
+
return factoryExecutionStore.run({ active: current?.active ?? false, helperScope }, callback);
|
|
33
|
+
}
|
|
30
34
|
function deserializeHookInput(raw) {
|
|
31
35
|
if (!raw || typeof raw !== "object" || typeof raw.timestamp !== "number") {
|
|
32
36
|
return raw;
|
|
@@ -70,7 +74,7 @@ async function runFactoryParallel(thunks) {
|
|
|
70
74
|
}
|
|
71
75
|
return Promise.all(
|
|
72
76
|
thunks.map(
|
|
73
|
-
(thunk) => Promise.resolve().then(() => thunk
|
|
77
|
+
(thunk) => Promise.resolve().then(() => runInFactoryHelperScope("parallel", thunk)).catch((error) => {
|
|
74
78
|
if (isFactoryFatalError(error)) {
|
|
75
79
|
throw error;
|
|
76
80
|
}
|
|
@@ -89,7 +93,10 @@ async function runFactoryPipeline(items, ...stages) {
|
|
|
89
93
|
let previous = item;
|
|
90
94
|
for (const stage of stages) {
|
|
91
95
|
try {
|
|
92
|
-
previous = await
|
|
96
|
+
previous = await runInFactoryHelperScope(
|
|
97
|
+
"pipeline",
|
|
98
|
+
() => stage(previous, item, index)
|
|
99
|
+
);
|
|
93
100
|
} catch (error) {
|
|
94
101
|
if (isFactoryFatalError(error)) {
|
|
95
102
|
throw error;
|
|
@@ -246,6 +253,7 @@ class CopilotSession {
|
|
|
246
253
|
hooks;
|
|
247
254
|
transformCallbacks;
|
|
248
255
|
_rpc = null;
|
|
256
|
+
_internalRpc = null;
|
|
249
257
|
traceContextProvider;
|
|
250
258
|
managedSettingsEnabled;
|
|
251
259
|
_capabilities = {};
|
|
@@ -312,6 +320,10 @@ class CopilotSession {
|
|
|
312
320
|
}),
|
|
313
321
|
getRunDetail: (runId) => this.rpc.factory.getRunDetail({ runId }),
|
|
314
322
|
getRunProgress: (runId, options = {}) => this.rpc.factory.getRunProgress({ runId, ...options }),
|
|
323
|
+
pause: async (runId) => {
|
|
324
|
+
throwIfFactoryExecutionIsActive();
|
|
325
|
+
return this.rpc.factory.pause({ runId });
|
|
326
|
+
},
|
|
315
327
|
cancel: async (runId) => this.rpc.factory.cancel({ runId })
|
|
316
328
|
};
|
|
317
329
|
/**
|
|
@@ -410,6 +422,13 @@ class CopilotSession {
|
|
|
410
422
|
}
|
|
411
423
|
return this._rpc;
|
|
412
424
|
}
|
|
425
|
+
/** @internal */
|
|
426
|
+
get internalRpc() {
|
|
427
|
+
if (!this._internalRpc) {
|
|
428
|
+
this._internalRpc = createInternalSessionRpc(this.connection, this.sessionId);
|
|
429
|
+
}
|
|
430
|
+
return this._internalRpc;
|
|
431
|
+
}
|
|
413
432
|
/**
|
|
414
433
|
* Path to the session workspace directory when infinite sessions are enabled.
|
|
415
434
|
* Contains checkpoints/, plan.md, and files/ subdirectories.
|
|
@@ -1092,6 +1111,36 @@ class CopilotSession {
|
|
|
1092
1111
|
);
|
|
1093
1112
|
return result2;
|
|
1094
1113
|
},
|
|
1114
|
+
pause: async (key) => {
|
|
1115
|
+
if (typeof key !== "string" || key.length === 0) {
|
|
1116
|
+
throw new Error("Factory pause checkpoint key must not be empty");
|
|
1117
|
+
}
|
|
1118
|
+
const helperScope = factoryExecutionStore.getStore()?.helperScope;
|
|
1119
|
+
if (helperScope !== void 0) {
|
|
1120
|
+
throw new Error(
|
|
1121
|
+
`Factory pause checkpoints are not allowed inside ${helperScope}() branches`
|
|
1122
|
+
);
|
|
1123
|
+
}
|
|
1124
|
+
await progress.flush();
|
|
1125
|
+
const response = await awaitFactoryOperation(
|
|
1126
|
+
() => self.internalRpc.factory.pauseAtCheckpoint({
|
|
1127
|
+
runId: params.runId,
|
|
1128
|
+
executionToken: params.executionToken,
|
|
1129
|
+
key
|
|
1130
|
+
}),
|
|
1131
|
+
controller.signal
|
|
1132
|
+
);
|
|
1133
|
+
switch (response.action) {
|
|
1134
|
+
case "continue":
|
|
1135
|
+
return;
|
|
1136
|
+
case "pause":
|
|
1137
|
+
await awaitFactoryOperation(
|
|
1138
|
+
() => new Promise(() => {
|
|
1139
|
+
}),
|
|
1140
|
+
controller.signal
|
|
1141
|
+
);
|
|
1142
|
+
}
|
|
1143
|
+
},
|
|
1095
1144
|
parallel: runFactoryParallel,
|
|
1096
1145
|
pipeline: runFactoryPipeline,
|
|
1097
1146
|
factory: async () => {
|
|
@@ -1127,11 +1176,9 @@ class CopilotSession {
|
|
|
1127
1176
|
},
|
|
1128
1177
|
async abort(params) {
|
|
1129
1178
|
const controllersForRun = self.factoryAbortControllers.get(params.runId);
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
controller.abort(reason);
|
|
1134
|
-
}
|
|
1179
|
+
const controller = controllersForRun?.get(params.executionToken);
|
|
1180
|
+
if (controller !== void 0) {
|
|
1181
|
+
controller.abort(new DOMException("Factory run was aborted", "AbortError"));
|
|
1135
1182
|
}
|
|
1136
1183
|
return {};
|
|
1137
1184
|
}
|
package/docs/factories.md
CHANGED
|
@@ -62,19 +62,20 @@ Validation covers the model's `run_factory` path only. An extension calling `ses
|
|
|
62
62
|
|
|
63
63
|
The `run()` context provides:
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
* `ctx.runId`: Stable ID reused across resumed attempts.
|
|
66
|
+
* `ctx.args`: Invocation arguments, forwarded verbatim. When the caller omits `args`, this is `{}` rather than `undefined`.
|
|
67
|
+
* `ctx.agent(prompt, options?)`: Runs one factory-owned subagent. Options are exactly `label`, `schema`, `model`, `agent`, `reasoningEffort`, and `contextTier`. See [Subagent calls](#subagent-calls).
|
|
68
|
+
* `ctx.parallel(thunks)`: Runs thunks concurrently and awaits all of them (a barrier). A thunk that throws becomes `null` in the result array, so one failed item does not lose the rest. Cancellation and hard runtime failures (`ResponseError`, `ConnectionError`) are the exception — those propagate and reject the whole call, because they mean the run itself is in trouble rather than one item having failed. Handle them at run level; do not assume every failure arrives as a `null`. Rejects above 4096 items.
|
|
69
|
+
* `ctx.pipeline(items, ...stages)`: Flows each item through every stage without a barrier between stages, so one item can be in a later stage while another is still in an earlier one. Each stage is called as `(previous, item, index)`, where `previous` is the prior stage's result and `item` is the original input. A stage that throws drops that item to `null` and skips its remaining stages, with the same exception for cancellation and hard runtime failures. Rejects above 4096 items.
|
|
70
|
+
* `ctx.phase(title)`: Starts a named progress phase. This sets a single run-global value, so calling it from inside concurrent `parallel`/`pipeline` stages races. Call it at run-level transitions and distinguish concurrent work by `label` instead.
|
|
71
|
+
* `ctx.log(message)`: Appends a progress line. When a factory bounds its own coverage (top-N, sampling), log what was dropped.
|
|
72
|
+
* `ctx.step(key, producer, options?)`: Journals the producer's JSON result under a stable key so a resume replays it without re-running the producer. A journaled (default) producer must return a JSON-serializable value; `undefined` or a non-JSON value is rejected. Pass `{ volatile: true }` to bypass the journal and run the producer every time.
|
|
73
73
|
|
|
74
74
|
The key is the *sole* identity: neither the producer body nor its inputs contribute to it. A resume replays the cached value for a matching key even if the producer has since changed, so version the key (`"scan-v2"`) whenever its inputs or meaning change. Journaled producers are best-effort at-least-once and may run again across crashes or concurrent same-key callers, so keep side effects idempotent.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
* `ctx.pause(key)`: Pauses at a durable, one-shot checkpoint. The first attempt records the checkpoint, pauses, and throws `AbortError` after cooperative cancellation. When the run resumes, the factory starts again and the same checkpoint returns so execution can continue. Call it only from the main factory flow, not inside `ctx.parallel()` or `ctx.pipeline()`.
|
|
76
|
+
* `ctx.session`: The session returned by `joinSession`. It refuses calls that start, resume, or pause a factory run. Call `extensions_manage` with `operation: "guide"` to read more about the session APIs.
|
|
77
|
+
* `ctx.signal`: Cooperative cancellation signal for extension work and subprocesses.
|
|
78
|
+
* `ctx.factory(...)`: Always rejects because nested factories are not supported.
|
|
78
79
|
|
|
79
80
|
Factory-owned subagents are intentionally hidden from `read_agent` and `write_agent`. Use the factory observability APIs instead.
|
|
80
81
|
|
|
@@ -157,7 +158,7 @@ session.factory.run(
|
|
|
157
158
|
name: string,
|
|
158
159
|
options?: {
|
|
159
160
|
args?: JsonValue;
|
|
160
|
-
limits?:
|
|
161
|
+
limits?: FactoryLimitOverrides;
|
|
161
162
|
notifyOnComplete?: boolean;
|
|
162
163
|
logPhaseNames?: boolean;
|
|
163
164
|
},
|
|
@@ -180,7 +181,7 @@ The signature is:
|
|
|
180
181
|
session.factory.resume(
|
|
181
182
|
runId: string,
|
|
182
183
|
options?: {
|
|
183
|
-
limits?:
|
|
184
|
+
limits?: FactoryLimitOverrides;
|
|
184
185
|
notifyOnComplete?: boolean;
|
|
185
186
|
logPhaseNames?: boolean;
|
|
186
187
|
},
|
|
@@ -189,15 +190,31 @@ session.factory.resume(
|
|
|
189
190
|
|
|
190
191
|
Set `notifyOnComplete` to `true` for factories that are likely to be invoked by an agent, so the originating session is notified when the factory completes. Set it to `false` for factories intended to be invoked programmatically, where the caller awaits the result directly. Set `logPhaseNames` to emit factory phase names to the session transcript. Both options apply to new and resumed runs.
|
|
191
192
|
|
|
192
|
-
Both resolve with the run envelope (`FactoryRunResult`) for **every** outcome
|
|
193
|
+
Both resolve with the run envelope (`FactoryRunResult`) for **every** outcome—`completed`, `error`, `halted`, `paused`, and `cancelled` alike. Inspect `status` and read `result` only when the run completed; a limit breach carries a typed `failure`. A `paused` envelope means that the current attempt settled, not that the durable run is permanently finished. Resume the same run ID to start another attempt with its journal and accounting intact. SDK-initiated `run` and `resume` do not request permission, so they have no declined outcome. The model's `run_factory` tool requests permission before the durable row exists; declining it creates no run row. An SDK-initiated run is refused only when the session already has its maximum number of active top-level runs. Pre-execution resume failures throw `FactoryResumeError`, whose `code` is one of `not_found`, `non_resumable`, `already_active`, `factory_already_running`, `factory_limits_invalid`, `factory_session_disposed`, `factory_storage_unavailable`, or `factory_storage_corrupt`.
|
|
193
194
|
|
|
194
195
|
An agent that no longer has a prior run's ID in context can recover it with `factories_manage` and `operation: "runs"`, which lists the session's factory runs with their IDs and statuses. This matters for resume: a run that reached a limit keeps its journal, so resuming it replays completed work for free, while restarting it from scratch pays for that work twice.
|
|
195
196
|
|
|
197
|
+
Pause a running attempt from outside its factory body:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
const paused = await session.factory.pause(runId);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Inside a factory body, use a durable checkpoint instead:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
await ctx.step("prepare", prepareInput);
|
|
207
|
+
await ctx.pause("review-ready");
|
|
208
|
+
await ctx.agent("Review the prepared input");
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The first attempt pauses at `"review-ready"` and ends through cooperative cancellation. On resume, the factory starts from the beginning, reuses the journaled step, returns from the checkpoint, and continues.
|
|
212
|
+
|
|
196
213
|
The agent-facing `run_factory` tool has exactly two input branches:
|
|
197
214
|
|
|
198
215
|
```ts
|
|
199
|
-
{ name: string; args?: JsonValue; limits?:
|
|
200
|
-
{ resumeFromRunId: string; limits?:
|
|
216
|
+
{ name: string; args?: JsonValue; limits?: FactoryLimitOverrides }
|
|
217
|
+
{ resumeFromRunId: string; limits?: FactoryLimitOverrides }
|
|
201
218
|
```
|
|
202
219
|
|
|
203
220
|
## Authoring a factory from inside a session
|
|
@@ -253,9 +270,9 @@ const progressPage = await session.factory.getRunProgress(runId, {
|
|
|
253
270
|
- `getRunDetail(runId)` returns phases, prompt-safe agent summaries, and the latest progress page.
|
|
254
271
|
- `getRunProgress(runId, options?)` pages progress forward, backward, by phase, or from the latest tail.
|
|
255
272
|
|
|
256
|
-
`getRun(runId)` reads the latest run envelope
|
|
273
|
+
`getRun(runId)` reads the latest run envelope. `pause(runId)` pauses a running attempt and returns its `paused` envelope. `cancel(runId)` cancels a run and returns its terminal envelope.
|
|
257
274
|
|
|
258
|
-
`waitForRun(runId, options?)` resolves with the
|
|
275
|
+
`waitForRun(runId, options?)` resolves with the current attempt's envelope once it settles into `completed`, `error`, `halted`, `paused`, or `cancelled`. It resolves immediately when the current attempt has already settled:
|
|
259
276
|
|
|
260
277
|
```ts
|
|
261
278
|
const settled = await session.factory.waitForRun(runId);
|
|
@@ -272,7 +289,7 @@ setTimeout(() => controller.abort(), 30_000);
|
|
|
272
289
|
const settled = await session.factory.waitForRun(runId, { signal: controller.signal });
|
|
273
290
|
```
|
|
274
291
|
|
|
275
|
-
Aborting rejects the wait and has no effect on the run, which keeps executing
|
|
292
|
+
Aborting rejects the wait and has no effect on the run, which keeps executing—use `pause(runId)` or `cancel(runId)` to stop it. The resolved object is a snapshot of that settled attempt. If its status is `paused`, a later resume updates the durable envelope under the same run ID. Call `getRun(runId)` to read the latest envelope. `isFactoryRunTerminal(status)` exposes the same current-attempt settlement test for callers driving their own loop.
|
|
276
293
|
|
|
277
294
|
Listen for the ephemeral `factory.run_updated` event. Its `{ runId, revision }` payload is an invalidation signal. Re-read the desired API when a newer monotonic revision arrives.
|
|
278
295
|
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "https://github.com/github/copilot-sdk.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.14-
|
|
8
|
-
"copilotCliVersion": "1.0.84-
|
|
7
|
+
"version": "1.0.14-unstable.35049111350.g7f86a90",
|
|
8
|
+
"copilotCliVersion": "1.0.84-9.unstable.r35045926061.g4848e94",
|
|
9
9
|
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
|
|
10
10
|
"main": "./dist/cjs/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
@@ -36,8 +36,10 @@
|
|
|
36
36
|
"auth:refresh": "node ../scripts/npm-auth-refresh.mjs --run",
|
|
37
37
|
"clean": "rimraf --glob dist *.tgz",
|
|
38
38
|
"build": "tsx esbuild-copilotsdk-nodejs.ts",
|
|
39
|
+
"acquire:runtime-packages": "tsx scripts/runtime-package-acquisition.ts",
|
|
39
40
|
"pack:release": "tsx scripts/package-sdk.ts",
|
|
40
41
|
"verify:release-packages": "tsx scripts/verify-release-packages.ts",
|
|
42
|
+
"release:manifest": "tsx scripts/release-manifest.ts",
|
|
41
43
|
"prepare:runtime": "tsx scripts/prepare-runtime.ts",
|
|
42
44
|
"test": "vitest run",
|
|
43
45
|
"test:watch": "vitest",
|
|
@@ -96,13 +98,13 @@
|
|
|
96
98
|
"README.md"
|
|
97
99
|
],
|
|
98
100
|
"optionalDependencies": {
|
|
99
|
-
"@github/copilot-sdk-darwin-arm64": "1.0.14-
|
|
100
|
-
"@github/copilot-sdk-darwin-x64": "1.0.14-
|
|
101
|
-
"@github/copilot-sdk-linux-arm64": "1.0.14-
|
|
102
|
-
"@github/copilot-sdk-linux-x64": "1.0.14-
|
|
103
|
-
"@github/copilot-sdk-linuxmusl-arm64": "1.0.14-
|
|
104
|
-
"@github/copilot-sdk-linuxmusl-x64": "1.0.14-
|
|
105
|
-
"@github/copilot-sdk-win32-arm64": "1.0.14-
|
|
106
|
-
"@github/copilot-sdk-win32-x64": "1.0.14-
|
|
101
|
+
"@github/copilot-sdk-darwin-arm64": "1.0.14-unstable.35049111350.g7f86a90",
|
|
102
|
+
"@github/copilot-sdk-darwin-x64": "1.0.14-unstable.35049111350.g7f86a90",
|
|
103
|
+
"@github/copilot-sdk-linux-arm64": "1.0.14-unstable.35049111350.g7f86a90",
|
|
104
|
+
"@github/copilot-sdk-linux-x64": "1.0.14-unstable.35049111350.g7f86a90",
|
|
105
|
+
"@github/copilot-sdk-linuxmusl-arm64": "1.0.14-unstable.35049111350.g7f86a90",
|
|
106
|
+
"@github/copilot-sdk-linuxmusl-x64": "1.0.14-unstable.35049111350.g7f86a90",
|
|
107
|
+
"@github/copilot-sdk-win32-arm64": "1.0.14-unstable.35049111350.g7f86a90",
|
|
108
|
+
"@github/copilot-sdk-win32-x64": "1.0.14-unstable.35049111350.g7f86a90"
|
|
107
109
|
}
|
|
108
110
|
}
|