@github/copilot-sdk 1.0.9-preview.0 → 1.0.9-preview.2

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/client.js CHANGED
@@ -497,9 +497,6 @@ class CopilotClient {
497
497
  }
498
498
  setupClientGlobalHandlers() {
499
499
  const handlers = {};
500
- handlers.hooks = {
501
- invoke: async (params) => await this.handleHooksInvoke(params)
502
- };
503
500
  if (this.requestHandler) {
504
501
  handlers.llmInference = createCopilotRequestAdapter(this.requestHandler, () => {
505
502
  if (!this.connection) {
@@ -894,7 +891,8 @@ class CopilotClient {
894
891
  enableHostGitOperations: false,
895
892
  enableSessionStore: false,
896
893
  enableSkills: false,
897
- memory: { enabled: false }
894
+ memory: { enabled: false },
895
+ customAgentsLocalOnly: true
898
896
  };
899
897
  }
900
898
  return {};
@@ -979,7 +977,9 @@ class CopilotClient {
979
977
  if (!this.connection) {
980
978
  await this.start();
981
979
  }
982
- config = { ...this.configDefaultsForMode(), ...config };
980
+ const modeDefaults = this.configDefaultsForMode();
981
+ config = { ...modeDefaults, ...config };
982
+ config.customAgentsLocalOnly ??= modeDefaults.customAgentsLocalOnly;
983
983
  config.systemMessage = this.getSystemMessageConfigForMode(config.systemMessage);
984
984
  const callerSessionId = config.sessionId;
985
985
  const useServerGeneratedId = config.cloud != null && callerSessionId == null;
@@ -1097,6 +1097,7 @@ class CopilotClient {
1097
1097
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1098
1098
  envValueMode: "direct",
1099
1099
  customAgents: toWireCustomAgents(config.customAgents),
1100
+ customAgentsLocalOnly: config.customAgentsLocalOnly,
1100
1101
  defaultAgent: config.defaultAgent,
1101
1102
  agent: config.agent,
1102
1103
  configDir: config.configDirectory,
@@ -1180,6 +1181,13 @@ class CopilotClient {
1180
1181
  * ```
1181
1182
  */
1182
1183
  async resumeSession(sessionId, config) {
1184
+ return this.resumeSessionInternal(sessionId, config);
1185
+ }
1186
+ /** @internal */
1187
+ async resumeSessionForExtension(sessionId, config, factories) {
1188
+ return this.resumeSessionInternal(sessionId, config, factories);
1189
+ }
1190
+ async resumeSessionInternal(sessionId, config, factories) {
1183
1191
  if (!this.connection) {
1184
1192
  await this.start();
1185
1193
  }
@@ -1193,6 +1201,7 @@ class CopilotClient {
1193
1201
  session.registerTools(config.tools);
1194
1202
  session.registerCanvases(config.canvases);
1195
1203
  session.registerCommands(config.commands);
1204
+ session.registerFactories(factories);
1196
1205
  const {
1197
1206
  wireProvider: bearerWireProvider,
1198
1207
  wireProviders: bearerWireProviders,
@@ -1217,7 +1226,9 @@ class CopilotClient {
1217
1226
  if (config.hooks) {
1218
1227
  session.registerHooks(config.hooks);
1219
1228
  }
1220
- config = { ...this.configDefaultsForMode(), ...config };
1229
+ const modeDefaults = this.configDefaultsForMode();
1230
+ config = { ...modeDefaults, ...config };
1231
+ config.customAgentsLocalOnly ??= modeDefaults.customAgentsLocalOnly;
1221
1232
  config.systemMessage = this.getSystemMessageConfigForMode(config.systemMessage);
1222
1233
  const { wirePayload: wireSystemMessage, transformCallbacks } = extractTransformCallbacks(
1223
1234
  config.systemMessage
@@ -1259,6 +1270,7 @@ class CopilotClient {
1259
1270
  })),
1260
1271
  toolSearch: config.toolSearch,
1261
1272
  canvases: config.canvases?.map((canvas) => canvas.declaration),
1273
+ factories: factories?.map((factory) => factory.meta),
1262
1274
  requestCanvasRenderer: config.requestCanvasRenderer,
1263
1275
  requestExtensions: config.requestExtensions,
1264
1276
  extensionSdkPath: config.extensionSdkPath,
@@ -1299,6 +1311,7 @@ class CopilotClient {
1299
1311
  mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
1300
1312
  envValueMode: "direct",
1301
1313
  customAgents: toWireCustomAgents(config.customAgents),
1314
+ customAgentsLocalOnly: config.customAgentsLocalOnly,
1302
1315
  defaultAgent: config.defaultAgent,
1303
1316
  agent: config.agent,
1304
1317
  skillDirectories: config.skillDirectories,
@@ -2056,6 +2069,12 @@ stderr: ${stderrOutput}`
2056
2069
  return session.clientSessionApis;
2057
2070
  });
2058
2071
  registerClientGlobalApiHandlers(this.connection, this.clientGlobalHandlers);
2072
+ this.connection.onRequest(
2073
+ "hooks.invoke",
2074
+ async (params) => {
2075
+ return await this.handleHooksInvoke(params);
2076
+ }
2077
+ );
2059
2078
  this.connection.onClose(() => {
2060
2079
  this.state = "disconnected";
2061
2080
  });
@@ -1,10 +1,19 @@
1
1
  import type { CopilotSession } from "./session.js";
2
- import { type ExtensionInfo, type PermissionHandler, type ResumeSessionConfig } from "./types.js";
2
+ import { type PermissionHandler, type ResumeSessionConfig } from "./types.js";
3
+ import type { FactoryHandle } from "./factory.js";
3
4
  export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclaration, type CanvasHostContext, type CanvasJsonSchema, type CanvasOptions, } from "./canvas.js";
4
5
  export type JoinSessionConfig = Omit<ResumeSessionConfig, "onPermissionRequest" | "extensionSdkPath"> & {
5
6
  onPermissionRequest?: PermissionHandler;
7
+ /**
8
+ * Factory handles to register when the extension joins the session.
9
+ *
10
+ * @experimental Part of the experimental Agent Factories surface and may
11
+ * change or be removed in future SDK or CLI releases.
12
+ */
13
+ factories?: FactoryHandle[];
6
14
  };
7
- export type { ExtensionInfo };
15
+ export type { ExtensionInfo, FactoryLimits, FactoryMeta } from "./types.js";
16
+ export { defineFactory, FactoryResumeError, isFactoryRunTerminal, type RunOptions, type ResumeOptions, type FactoryResumeErrorCode, type SessionFactoryApi, type FactoryAgentOptions, type FactoryContext, type FactoryDefinition, type FactoryHandle, type FactoryJsonSchema, type JsonValue, type FactoryPipelineStage, type FactoryStepOptions, type FactoryRunResult, type FactoryRunStatus, type FactoryRunSummary, type FactoryRunDetail, type FactoryProgressPage, type FactoryProgressLine, type FactoryPhaseObservation, type FactoryPhaseStatus, type FactoryAgentSummary, } from "./factory.js";
8
17
  /**
9
18
  * Joins the current foreground session.
10
19
  *
package/dist/extension.js CHANGED
@@ -7,6 +7,11 @@ import {
7
7
  CanvasError,
8
8
  createCanvas
9
9
  } from "./canvas.js";
10
+ import {
11
+ defineFactory,
12
+ FactoryResumeError,
13
+ isFactoryRunTerminal
14
+ } from "./factory.js";
10
15
  async function joinSession(config = {}) {
11
16
  const sessionId = process.env.SESSION_ID;
12
17
  if (!sessionId) {
@@ -15,17 +20,28 @@ async function joinSession(config = {}) {
15
20
  );
16
21
  }
17
22
  const client = new CopilotClient({ _internalConnection: { kind: "parent-process" } });
18
- const { extensionSdkPath: _stripped, ...rest } = config;
23
+ const {
24
+ extensionSdkPath: _stripped,
25
+ factories,
26
+ ...rest
27
+ } = config;
19
28
  void _stripped;
20
- return client.resumeSession(sessionId, {
21
- ...rest,
22
- onPermissionRequest: config.onPermissionRequest ?? defaultJoinSessionPermissionHandler,
23
- suppressResumeEvent: config.suppressResumeEvent ?? true
24
- });
29
+ return client.resumeSessionForExtension(
30
+ sessionId,
31
+ {
32
+ ...rest,
33
+ onPermissionRequest: config.onPermissionRequest ?? defaultJoinSessionPermissionHandler,
34
+ suppressResumeEvent: config.suppressResumeEvent ?? true
35
+ },
36
+ factories
37
+ );
25
38
  }
26
39
  export {
27
40
  Canvas,
28
41
  CanvasError,
42
+ FactoryResumeError,
29
43
  createCanvas,
44
+ defineFactory,
45
+ isFactoryRunTerminal,
30
46
  joinSession
31
47
  };
@@ -0,0 +1,273 @@
1
+ import type { FactoryGetRunProgressRequest, FactoryProgressPage, FactoryRunDetail, FactoryRunResult as WireFactoryRunResult, FactoryRunStatus, FactoryRunSummary } from "./generated/rpc.js";
2
+ import type { CopilotSession } from "./session.js";
3
+ import type { FactoryLimits, FactoryMeta } from "./types.js";
4
+ /**
5
+ * The envelope describing a factory run: its identity, status, and — once it
6
+ * has completed — its result. `getRun` returns this for an in-flight run too,
7
+ * so `status` may be `pending` or `running` and the outcome fields absent.
8
+ *
9
+ * `result` is re-typed here rather than taken from the generated wire type. The
10
+ * runtime returns any JSON value — including `null`, a string, a number, or an
11
+ * array — but the schema models the field as an opaque node, which the
12
+ * generator renders as an object. Narrowing the correction to this surface
13
+ * keeps the `x-opaque-json` handling unchanged for every other consumer.
14
+ *
15
+ * This override is temporary. Once the schema distinguishes an opaque JSON
16
+ * value from an opaque in-process value and that ships in a CLI release,
17
+ * regenerating produces the right type directly, and this declaration, the
18
+ * `toPublicFactoryRunResult` boundary helper, and the casts around it should
19
+ * all be deleted. Tracked by github/copilot-agent-runtime#14122.
20
+ *
21
+ * @experimental Part of the experimental Agent Factories surface and may
22
+ * change or be removed in future SDK or CLI releases.
23
+ */
24
+ export type FactoryRunResult = Omit<WireFactoryRunResult, "result"> & {
25
+ /** Completed factory result. */
26
+ result?: JsonValue;
27
+ };
28
+ export type { FactoryAgentSummary, FactoryPhaseStatus, FactoryPhaseObservation, FactoryProgressLine, FactoryProgressPage, FactoryRunDetail, FactoryRunStatus, FactoryRunSummary, } from "./generated/rpc.js";
29
+ /**
30
+ * Whether a factory run status is terminal.
31
+ *
32
+ * @experimental Part of the experimental Agent Factories surface and may
33
+ * change or be removed in future SDK or CLI releases.
34
+ */
35
+ export declare function isFactoryRunTerminal(status: FactoryRunStatus): boolean;
36
+ declare const factoryHandleBrand: unique symbol;
37
+ /** A value that can be represented losslessly on the SDK JSON wire. */
38
+ export type JsonValue = null | boolean | number | string | JsonValue[] | {
39
+ [key: string]: JsonValue;
40
+ };
41
+ /**
42
+ * Conservative JSON shape language accepted for structured factory agent output.
43
+ *
44
+ * This is a best-effort structural guard used to decide whether a subagent's
45
+ * structured output should be accepted or retried — **not** a full JSON Schema
46
+ * validator. Only these keywords are honored: `type`, `required`, `enum`,
47
+ * `const`, recursive `properties`/`items`, and `anyOf`/`oneOf`/`allOf`.
48
+ *
49
+ * Everything else is **ignored, not enforced**. In particular, string
50
+ * constraints (`pattern`, `minLength`, `maxLength`, `format`), numeric ranges
51
+ * (`minimum`, `maximum`), `additionalProperties`, and boolean (`true`/`false`)
52
+ * schemas do not reject non-conforming output. `oneOf` is treated like `anyOf`
53
+ * (at least one branch must match) rather than strict exactly-one. Author
54
+ * schemas within this subset; do not rely on unsupported constraints for
55
+ * correctness.
56
+ *
57
+ * @experimental Part of the experimental Agent Factories surface and may
58
+ * change or be removed in future SDK or CLI releases.
59
+ */
60
+ export type FactoryJsonSchema = {
61
+ [key: string]: JsonValue;
62
+ };
63
+ /**
64
+ * Options for one factory-scoped subagent call.
65
+ *
66
+ * @experimental Part of the experimental Agent Factories surface and may
67
+ * change or be removed in future SDK or CLI releases.
68
+ */
69
+ export interface FactoryAgentOptions {
70
+ label?: string;
71
+ schema?: FactoryJsonSchema;
72
+ model?: string;
73
+ }
74
+ /**
75
+ * Options for a durable factory step.
76
+ *
77
+ * @experimental Part of the experimental Agent Factories surface and may
78
+ * change or be removed in future SDK or CLI releases.
79
+ */
80
+ export interface FactoryStepOptions {
81
+ /** Skip the journal and always invoke the producer. */
82
+ volatile?: boolean;
83
+ }
84
+ /**
85
+ * One stage in a per-item factory pipeline.
86
+ *
87
+ * @experimental Part of the experimental Agent Factories surface and may
88
+ * change or be removed in future SDK or CLI releases.
89
+ */
90
+ export type FactoryPipelineStage<TInput = unknown, TResult = unknown> = (previous: TInput, item: unknown, index: number) => Promise<TResult> | TResult;
91
+ /**
92
+ * Context passed to an extension-authored factory body.
93
+ *
94
+ * @experimental Part of the experimental Agent Factories surface and may
95
+ * change or be removed in future SDK or CLI releases.
96
+ */
97
+ export interface FactoryContext<TArgs extends JsonValue = JsonValue> {
98
+ /** Stable identifier for the current factory run. */
99
+ readonly runId: string;
100
+ /** Spawn and await one factory-scoped subagent. */
101
+ agent(prompt: string, options?: FactoryAgentOptions): Promise<unknown>;
102
+ /** Memoize an arbitrary producer under a stable author-supplied key. */
103
+ step(key: string, producer: () => Promise<JsonValue> | JsonValue, options?: FactoryStepOptions): Promise<JsonValue>;
104
+ /**
105
+ * Run thunks concurrently and await all of them.
106
+ *
107
+ * A thunk that throws becomes `null` in the result array, so one failed
108
+ * item does not lose the rest. Cancellation and hard runtime failures
109
+ * (`ResponseError`, `ConnectionError`) are the exception: those propagate
110
+ * and reject the whole call, because they mean the run itself is in
111
+ * trouble rather than one item having failed.
112
+ */
113
+ parallel<TResult>(thunks: Array<() => Promise<TResult> | TResult>): Promise<Array<TResult | null>>;
114
+ /**
115
+ * Run each item through every stage without barriers between stages.
116
+ *
117
+ * A stage that throws drops that item to `null` and skips its remaining
118
+ * stages. As with {@link FactoryContext.parallel}, cancellation and hard
119
+ * runtime failures propagate instead of being recorded per item.
120
+ */
121
+ pipeline(items: unknown[], ...stages: FactoryPipelineStage[]): Promise<unknown[]>;
122
+ /** Start a named factory progress phase. */
123
+ phase(title: string): void;
124
+ /** Emit a factory progress line. */
125
+ log(message: string): void;
126
+ /** Reject because nested factories are not supported. */
127
+ factory(name: string, args?: JsonValue): Promise<JsonValue | void>;
128
+ /** Caller-supplied input, forwarded verbatim. */
129
+ args: TArgs;
130
+ /** The same full session instance returned by `joinSession`. */
131
+ session: CopilotSession;
132
+ /** Cooperative cancellation signal for the current factory run. */
133
+ signal: AbortSignal;
134
+ }
135
+ /**
136
+ * Definition accepted by {@link defineFactory}.
137
+ *
138
+ * @experimental Part of the experimental Agent Factories surface and may
139
+ * change or be removed in future SDK or CLI releases.
140
+ */
141
+ export interface FactoryDefinition<TArgs extends JsonValue = JsonValue, TResult extends JsonValue | void = JsonValue | void> {
142
+ meta: FactoryMeta;
143
+ run(context: FactoryContext<TArgs>): Promise<TResult>;
144
+ }
145
+ /**
146
+ * A deeply immutable view of a value.
147
+ *
148
+ * `defineFactory` deep-freezes the metadata it stores, so the handle's view of
149
+ * it has to be readonly all the way down or `handle.meta.name = "..."` and
150
+ * `handle.meta.phases.push(...)` would compile and then throw at runtime.
151
+ */
152
+ type DeepReadonly<T> = T extends (infer U)[] ? readonly DeepReadonly<U>[] : T extends object ? {
153
+ readonly [K in keyof T]: DeepReadonly<T[K]>;
154
+ } : T;
155
+ /**
156
+ * Opaque reusable reference to a defined factory.
157
+ *
158
+ * @experimental Part of the experimental Agent Factories surface and may
159
+ * change or be removed in future SDK or CLI releases.
160
+ */
161
+ export interface FactoryHandle<TArgs extends JsonValue = JsonValue, TResult extends JsonValue | void = JsonValue | void> {
162
+ readonly meta: DeepReadonly<FactoryMeta>;
163
+ readonly [factoryHandleBrand]: {
164
+ readonly args: TArgs;
165
+ readonly result: TResult;
166
+ };
167
+ }
168
+ /**
169
+ * Options for invoking a factory.
170
+ *
171
+ * @experimental Part of the experimental Agent Factories surface and may
172
+ * change or be removed in future SDK or CLI releases.
173
+ */
174
+ export interface RunOptions<TArgs extends JsonValue = JsonValue> {
175
+ /** Input surfaced as `context.args`. */
176
+ args?: TArgs;
177
+ /** Optional per-invocation resource ceiling overrides. */
178
+ limits?: FactoryLimits;
179
+ /**
180
+ * Prior run whose persisted identity, arguments, journal, and accounting should be resumed.
181
+ *
182
+ * @deprecated Use {@link SessionFactoryApi.resume} instead.
183
+ */
184
+ resumeFromRunId?: string;
185
+ }
186
+ /**
187
+ * Options for resuming a factory run by ID.
188
+ *
189
+ * @experimental Part of the experimental Agent Factories surface and may
190
+ * change or be removed in future SDK or CLI releases.
191
+ */
192
+ export interface ResumeOptions {
193
+ /** Optional per-invocation resource ceiling overrides. */
194
+ limits?: FactoryLimits;
195
+ }
196
+ /**
197
+ * Machine-readable pre-execution factory resume failure.
198
+ *
199
+ * @experimental Part of the experimental Agent Factories surface and may
200
+ * change or be removed in future SDK or CLI releases.
201
+ */
202
+ export type FactoryResumeErrorCode = "not_found" | "non_resumable" | "already_active" | "reapproval_declined" | "no_approval_provider";
203
+ /**
204
+ * Friendly factory API exposed on a session.
205
+ *
206
+ * @experimental Part of the experimental Agent Factories surface and may
207
+ * change or be removed in future SDK or CLI releases.
208
+ */
209
+ export interface SessionFactoryApi {
210
+ /**
211
+ * Run a registered factory and resolve with its run envelope.
212
+ *
213
+ * The envelope is returned for every outcome, including `error`, `halted`,
214
+ * and `cancelled` — inspect `status` and read `result` only when the run
215
+ * completed. A declined fresh run resolves with a terminal `cancelled`
216
+ * envelope. Failures that occur before a run exists (such as an unknown
217
+ * factory or an already-active session) still reject.
218
+ */
219
+ run(name: string, options?: RunOptions): Promise<FactoryRunResult>;
220
+ run<TArgs extends JsonValue>(factory: FactoryHandle<TArgs, JsonValue | void>, options?: RunOptions<TArgs>): Promise<FactoryRunResult>;
221
+ /**
222
+ * Resume a run from its persisted factory name, arguments, journal, and accounting.
223
+ *
224
+ * Resolves with the run envelope like {@link SessionFactoryApi.run}. A
225
+ * pre-execution failure, including declined reapproval, rejects with
226
+ * {@link FactoryResumeError}.
227
+ */
228
+ resume(runId: string, options?: ResumeOptions): Promise<FactoryRunResult>;
229
+ /** Read the latest durable envelope for a factory run. */
230
+ getRun(runId: string): Promise<FactoryRunResult>;
231
+ /**
232
+ * Wait for a run to settle and resolve with its terminal envelope.
233
+ *
234
+ * Resolves as soon as the run reaches `completed`, `error`, `halted`, or
235
+ * `cancelled`, and resolves immediately when it has already settled. A
236
+ * terminal envelope is final, so the resolved value never changes
237
+ * afterwards.
238
+ *
239
+ * This watches the run's `factory.run_updated` invalidation events and
240
+ * periodically re-reads the durable envelope so a missed event cannot
241
+ * leave the wait hanging. Pass a `signal` to stop waiting; aborting rejects
242
+ * and has no effect on the run itself, which keeps executing. Use
243
+ * {@link SessionFactoryApi.cancel} to actually stop it.
244
+ */
245
+ waitForRun(runId: string, options?: {
246
+ signal?: AbortSignal;
247
+ }): Promise<FactoryRunResult>;
248
+ /** List this session's durable factory runs in creation order. */
249
+ listRuns(): Promise<FactoryRunSummary[]>;
250
+ /** Read durable phases, direct agents, and the latest progress tail for a run. */
251
+ getRunDetail(runId: string): Promise<FactoryRunDetail>;
252
+ /** Page durable progress forward, backward, or from the latest tail. */
253
+ getRunProgress(runId: string, options?: Omit<FactoryGetRunProgressRequest, "runId">): Promise<FactoryProgressPage>;
254
+ /** Cancel a factory run and return its terminal envelope. */
255
+ cancel(runId: string): Promise<FactoryRunResult>;
256
+ }
257
+ /**
258
+ * Error thrown when a factory cannot be resumed before execution begins.
259
+ *
260
+ * @experimental Part of the experimental Agent Factories surface and may
261
+ * change or be removed in future SDK or CLI releases.
262
+ */
263
+ export declare class FactoryResumeError extends Error {
264
+ readonly code: FactoryResumeErrorCode;
265
+ constructor(code: FactoryResumeErrorCode, message: string);
266
+ }
267
+ /**
268
+ * Defines an extension-authored factory and returns an opaque registration handle.
269
+ *
270
+ * @experimental Part of the experimental Agent Factories surface and may
271
+ * change or be removed in future SDK or CLI releases.
272
+ */
273
+ export declare function defineFactory<TArgs extends JsonValue = JsonValue, TResult extends JsonValue | void = JsonValue | void>(definition: FactoryDefinition<TArgs, TResult>): FactoryHandle<TArgs, TResult>;
@@ -0,0 +1,96 @@
1
+ const FACTORY_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
2
+ "completed",
3
+ "halted",
4
+ "cancelled",
5
+ "error"
6
+ ]);
7
+ function isFactoryRunTerminal(status) {
8
+ return FACTORY_TERMINAL_STATUSES.has(status);
9
+ }
10
+ class FactoryResumeError extends Error {
11
+ constructor(code, message) {
12
+ super(message);
13
+ this.code = code;
14
+ this.name = "FactoryResumeError";
15
+ }
16
+ code;
17
+ }
18
+ const factoryHandles = /* @__PURE__ */ new WeakMap();
19
+ const MAX_FACTORY_TIMEOUT_SECONDS = 2147483647e-3;
20
+ const NANO_AIU_PER_AIU = 1e9;
21
+ function deepFreeze(value) {
22
+ if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
23
+ Object.freeze(value);
24
+ for (const nested of Object.values(value)) {
25
+ deepFreeze(nested);
26
+ }
27
+ }
28
+ return value;
29
+ }
30
+ function validateLimits(meta) {
31
+ const limits = meta.limits;
32
+ if (!limits) {
33
+ return;
34
+ }
35
+ for (const field of ["maxConcurrentSubagents", "maxTotalSubagents"]) {
36
+ const value = limits[field];
37
+ if (value !== void 0 && (!Number.isInteger(value) || value <= 0)) {
38
+ throw new Error(`Factory limit "${field}" must be a positive integer`);
39
+ }
40
+ }
41
+ if (limits.timeoutSeconds !== void 0 && (!Number.isFinite(limits.timeoutSeconds) || limits.timeoutSeconds <= 0)) {
42
+ throw new Error(
43
+ 'Factory limit "timeoutSeconds" must be a positive, finite number of seconds'
44
+ );
45
+ }
46
+ if (limits.timeoutSeconds !== void 0 && limits.timeoutSeconds > MAX_FACTORY_TIMEOUT_SECONDS) {
47
+ throw new Error(
48
+ `Factory limit "timeoutSeconds" must not exceed ${MAX_FACTORY_TIMEOUT_SECONDS} seconds`
49
+ );
50
+ }
51
+ if (limits.maxAiCredits !== void 0) {
52
+ const maxNanoAiu = Math.round(limits.maxAiCredits * NANO_AIU_PER_AIU);
53
+ if (!Number.isFinite(limits.maxAiCredits) || limits.maxAiCredits <= 0 || !Number.isSafeInteger(maxNanoAiu) || maxNanoAiu < 1) {
54
+ throw new Error(
55
+ 'Factory limit "maxAiCredits" must be a positive, finite number that rounds to a safe positive integer nano-AIU ceiling'
56
+ );
57
+ }
58
+ }
59
+ }
60
+ function validatePhases(meta) {
61
+ const titles = /* @__PURE__ */ new Set();
62
+ for (const phase of meta.phases) {
63
+ if (phase.title.trim().length === 0) {
64
+ throw new Error("Factory phase titles must not be empty");
65
+ }
66
+ if (titles.has(phase.title)) {
67
+ throw new Error(`Factory phase title "${phase.title}" is declared more than once`);
68
+ }
69
+ titles.add(phase.title);
70
+ }
71
+ }
72
+ function defineFactory(definition) {
73
+ const meta = deepFreeze(structuredClone(definition.meta));
74
+ validateLimits(meta);
75
+ validatePhases(meta);
76
+ const stored = {
77
+ meta,
78
+ run: definition.run
79
+ };
80
+ const handle = Object.freeze({ meta });
81
+ factoryHandles.set(handle, stored);
82
+ return handle;
83
+ }
84
+ function getFactoryDefinition(handle) {
85
+ const definition = factoryHandles.get(handle);
86
+ if (!definition) {
87
+ throw new Error("Invalid factory handle");
88
+ }
89
+ return definition;
90
+ }
91
+ export {
92
+ FactoryResumeError,
93
+ defineFactory,
94
+ getFactoryDefinition,
95
+ isFactoryRunTerminal
96
+ };
@@ -20142,18 +20142,6 @@ export interface ClientSessionApiHandlers {
20142
20142
  * function uses `getHandlers` to resolve the session's handlers.
20143
20143
  */
20144
20144
  export declare function registerClientSessionApiHandlers(connection: MessageConnection, getHandlers: (sessionId: string) => ClientSessionApiHandlers): void;
20145
- /** Handler for `hooks` client global API methods. */
20146
- /** @experimental */
20147
- export interface HooksHandler {
20148
- /**
20149
- * Dispatches one SDK callback hook from the runtime to the connection that registered it. Internal transport plumbing: clients opt in through session initialization and the Rust hook processor owns ordering, policy, timeout, and callback routing.
20150
- *
20151
- * @param params Runtime-owned wire payload for a server-to-client hook callback invocation.
20152
- *
20153
- * @returns Optional output returned by an SDK callback hook.
20154
- */
20155
- invoke(params: HookInvokeRequest): Promise<HookInvokeResponse>;
20156
- }
20157
20145
  /** Handler for `llmInference` client global API methods. */
20158
20146
  /** @experimental */
20159
20147
  export interface LlmInferenceHandler {
@@ -20186,7 +20174,6 @@ export interface GitHubTelemetryHandler {
20186
20174
  }
20187
20175
  /** All client global API handler groups. */
20188
20176
  export interface ClientGlobalApiHandlers {
20189
- hooks?: HooksHandler;
20190
20177
  llmInference?: LlmInferenceHandler;
20191
20178
  gitHubTelemetry?: GitHubTelemetryHandler;
20192
20179
  }
@@ -2554,11 +2554,6 @@ function registerClientSessionApiHandlers(connection, getHandlers) {
2554
2554
  });
2555
2555
  }
2556
2556
  function registerClientGlobalApiHandlers(connection, handlers) {
2557
- connection.onRequest("hooks.invoke", async (params) => {
2558
- const handler = handlers.hooks;
2559
- if (!handler) throw new Error("No hooks client-global handler registered");
2560
- return handler.invoke(params);
2561
- });
2562
2557
  connection.onRequest("llmInference.httpRequestStart", async (params) => {
2563
2558
  const handler = handlers.llmInference;
2564
2559
  if (!handler) throw new Error("No llmInference client-global handler registered");
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * Union of all session event variants emitted by the Copilot CLI runtime.
7
7
  */
8
- export type SessionEvent = StartEvent | ResumeEvent | RemoteSteerableChangedEvent | ErrorEvent | IdleEvent | TitleChangedEvent | ScheduleCreatedEvent | ScheduleCancelledEvent | ScheduleRearmedEvent | AutopilotObjectiveChangedEvent | InfoEvent | WarningEvent | ModelChangeEvent | ModeChangedEvent | SessionLimitsChangedEvent | PermissionsChangedEvent | PlanChangedEvent | TodosChangedEvent | WorkspaceFileChangedEvent | HandoffEvent | TruncationEvent | SnapshotRewindEvent | ShutdownEvent | UsageCheckpointEvent | ContextChangedEvent | UsageInfoEvent | CompactionStartEvent | CompactionCompleteEvent | TaskCompleteEvent | UserMessageEvent | PendingMessagesModifiedEvent | AssistantTurnStartEvent | AssistantTurnRetryEvent | AssistantIntentEvent | AssistantServerToolProgressEvent | AssistantReasoningEvent | AssistantReasoningDeltaEvent | AssistantToolCallDeltaEvent | AssistantStreamingDeltaEvent | AssistantMessageEvent | AssistantMessageStartEvent | AssistantMessageDeltaEvent | AssistantTurnEndEvent | AssistantIdleEvent | AssistantUsageEvent | ModelCallFailureEvent | ModelCallStartEvent | AbortEvent | ToolUserRequestedEvent | ToolExecutionStartEvent | ToolExecutionPartialResultEvent | ToolExecutionProgressEvent | ToolExecutionCompleteEvent | ToolSearchActivatedEvent | SkillInvokedEvent | SubagentStartedEvent | SubagentCompletedEvent | SubagentFailedEvent | SubagentSelectedEvent | SubagentDeselectedEvent | HookStartEvent | HookEndEvent | HookProgressEvent | BinaryAssetEvent | SystemMessageEvent | SystemNotificationEvent | PermissionRequestedEvent | PermissionCompletedEvent | UserInputRequestedEvent | UserInputCompletedEvent | ElicitationRequestedEvent | ElicitationCompletedEvent | SamplingRequestedEvent | SamplingCompletedEvent | McpOauthRequiredEvent | McpOauthCompletedEvent | McpHeadersRefreshRequiredEvent | McpHeadersRefreshCompletedEvent | CustomNotificationEvent | ExternalToolRequestedEvent | ExternalToolCompletedEvent | CommandQueuedEvent | CommandExecuteEvent | CommandCompletedEvent | AutoModeSwitchRequestedEvent | AutoModeSwitchCompletedEvent | SessionLimitsExhaustedRequestedEvent | SessionLimitsExhaustedCompletedEvent | AutoModeResolvedEvent | ManagedSettingsResolvedEvent | ManagedSettingsEnforcedEvent | CommandsChangedEvent | CapabilitiesChangedEvent | ExitPlanModeRequestedEvent | ExitPlanModeCompletedEvent | ToolsUpdatedEvent | BackgroundTasksChangedEvent | FactoryRunUpdatedEvent | SkillsLoadedEvent | CustomAgentsUpdatedEvent | McpServersLoadedEvent | McpServerStatusChangedEvent | McpToolsListChangedEvent | McpResourcesListChangedEvent | McpPromptsListChangedEvent | ExtensionsLoadedEvent | CanvasOpenedEvent | CanvasRegistryChangedEvent | CanvasClosedEvent | CanvasUnavailableEvent | CanvasRecordedEvent | CanvasRemovedEvent | ExtensionsAttachmentsPushedEvent | McpAppToolCallCompleteEvent;
8
+ export type SessionEvent = StartEvent | ResumeEvent | RemoteSteerableChangedEvent | ErrorEvent | IdleEvent | TitleChangedEvent | ScheduleCreatedEvent | ScheduleCancelledEvent | ScheduleRearmedEvent | AutopilotObjectiveChangedEvent | InfoEvent | WarningEvent | ModelChangeEvent | ModeChangedEvent | SessionLimitsChangedEvent | PermissionsChangedEvent | PlanChangedEvent | TodosChangedEvent | WorkspaceFileChangedEvent | HandoffEvent | TruncationEvent | SnapshotRewindEvent | ShutdownEvent | UsageCheckpointEvent | ContextChangedEvent | UsageInfoEvent | CompactionStartEvent | CompactionCompleteEvent | TaskCompleteEvent | UserMessageEvent | PendingMessagesModifiedEvent | AssistantTurnStartEvent | AssistantIntentEvent | AssistantServerToolProgressEvent | AssistantReasoningEvent | AssistantReasoningDeltaEvent | AssistantToolCallDeltaEvent | AssistantStreamingDeltaEvent | AssistantMessageEvent | AssistantMessageStartEvent | AssistantMessageDeltaEvent | AssistantTurnEndEvent | AssistantIdleEvent | AssistantUsageEvent | ModelCallFailureEvent | AbortEvent | ToolUserRequestedEvent | ToolExecutionStartEvent | ToolExecutionPartialResultEvent | ToolExecutionProgressEvent | ToolExecutionCompleteEvent | ToolSearchActivatedEvent | SkillInvokedEvent | SubagentStartedEvent | SubagentCompletedEvent | SubagentFailedEvent | SubagentSelectedEvent | SubagentDeselectedEvent | HookStartEvent | HookEndEvent | HookProgressEvent | BinaryAssetEvent | SystemMessageEvent | SystemNotificationEvent | PermissionRequestedEvent | PermissionCompletedEvent | UserInputRequestedEvent | UserInputCompletedEvent | ElicitationRequestedEvent | ElicitationCompletedEvent | SamplingRequestedEvent | SamplingCompletedEvent | McpOauthRequiredEvent | McpOauthCompletedEvent | McpHeadersRefreshRequiredEvent | McpHeadersRefreshCompletedEvent | CustomNotificationEvent | ExternalToolRequestedEvent | ExternalToolCompletedEvent | CommandQueuedEvent | CommandExecuteEvent | CommandCompletedEvent | AutoModeSwitchRequestedEvent | AutoModeSwitchCompletedEvent | SessionLimitsExhaustedRequestedEvent | SessionLimitsExhaustedCompletedEvent | AutoModeResolvedEvent | ManagedSettingsResolvedEvent | ManagedSettingsEnforcedEvent | CommandsChangedEvent | CapabilitiesChangedEvent | ExitPlanModeRequestedEvent | ExitPlanModeCompletedEvent | ToolsUpdatedEvent | BackgroundTasksChangedEvent | FactoryRunUpdatedEvent | SkillsLoadedEvent | CustomAgentsUpdatedEvent | McpServersLoadedEvent | McpServerStatusChangedEvent | McpToolsListChangedEvent | McpResourcesListChangedEvent | McpPromptsListChangedEvent | ExtensionsLoadedEvent | CanvasOpenedEvent | CanvasRegistryChangedEvent | CanvasClosedEvent | CanvasUnavailableEvent | CanvasRecordedEvent | CanvasRemovedEvent | ExtensionsAttachmentsPushedEvent | McpAppToolCallCompleteEvent;
9
9
  /**
10
10
  * Hosting platform type of the repository (github or ado)
11
11
  */
@@ -3025,23 +3025,6 @@ export interface AssistantTurnStartData {
3025
3025
  */
3026
3026
  turnId: string;
3027
3027
  }
3028
- /**
3029
- * Metadata for an additional model inference attempt within an existing assistant turn
3030
- */
3031
- export interface AssistantTurnRetryData {
3032
- /**
3033
- * Model identifier used for this retry, when known
3034
- */
3035
- model?: string;
3036
- /**
3037
- * Provider or runtime classification that caused the retry, when known
3038
- */
3039
- reason?: string;
3040
- /**
3041
- * Identifier of the turn whose model inference is being retried
3042
- */
3043
- turnId: string;
3044
- }
3045
3028
  /**
3046
3029
  * Session event "assistant.intent". Agent intent description for current activity or plan
3047
3030
  */
@@ -4052,19 +4035,6 @@ export interface ModelCallFailureRequestFingerprint {
4052
4035
  */
4053
4036
  toolResultMessageCount: number;
4054
4037
  }
4055
- /**
4056
- * Model API dispatch metadata for internal telemetry
4057
- */
4058
- export interface ModelCallStartData {
4059
- /**
4060
- * Model identifier used for this API call, when known
4061
- */
4062
- model?: string;
4063
- /**
4064
- * Identifier of the assistant turn that initiated the model call
4065
- */
4066
- turnId: string;
4067
- }
4068
4038
  /**
4069
4039
  * Session event "abort". Turn abort information including the reason for termination
4070
4040
  */
package/dist/index.d.ts CHANGED
@@ -7,7 +7,9 @@ export { CopilotClient } from "./client.js";
7
7
  export { RuntimeConnection } from "./types.js";
8
8
  export { BuiltInTools, ToolSet } from "./toolSet.js";
9
9
  export { CopilotSession, type AssistantMessageEvent } from "./session.js";
10
+ export { defineFactory, FactoryResumeError, isFactoryRunTerminal } from "./factory.js";
10
11
  export { Canvas, CanvasError, createCanvas, type CanvasAction, type CanvasDeclaration, type CanvasHostContext, type CanvasHostContextCapabilities, type CanvasJsonSchema, type CanvasOptions, } from "./canvas.js";
11
12
  export { defineTool, approveAll, convertMcpCallToolResult, createSessionFsAdapter, CopilotRequestHandler, CopilotWebSocketHandler, CopilotWebSocketCloseStatus, CopilotWebSocketForwarder, SessionFsSqliteTransactionFailure, SYSTEM_MESSAGE_SECTIONS, } from "./types.js";
12
13
  export type * from "./generated/session-events.js";
13
- export type { CommandContext, CommandDefinition, CommandHandler, CanvasProviderIdentity, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AgentStopHandler, AgentStopHookInput, AgentStopHookOutput, 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, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, MessageOptions, ModelBilling, ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, CapiSessionOptions, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, NamedProviderConfig, PermissionHandler, PermissionRequest, PermissionRequestResult, 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";
14
+ export type { CommandContext, CommandDefinition, CommandHandler, CanvasProviderIdentity, CloudSessionOptions, CloudSessionRepository, AutoModeSwitchHandler, AutoModeSwitchRequest, AutoModeSwitchResponse, AgentStopHandler, AgentStopHookInput, AgentStopHookOutput, 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, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, InfiniteSessionConfig, LargeToolOutputConfig, MemoryConfiguration, UiInputOptions, FactoryLimits, FactoryMeta, MCPStdioServerConfig, MCPHTTPServerConfig, MCPServerConfig, DefaultAgentConfig, BearerTokenProvider, MessageOptions, ModelBilling, ModelBillingTokenPrices, ModelBillingTokenPricesLongContext, CapiSessionOptions, ModelCapabilities, ModelCapabilitiesOverride, ModelInfo, ModelPolicy, NamedProviderConfig, PermissionHandler, PermissionRequest, PermissionRequestResult, 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, FactoryRunDetail, FactoryProgressPage, FactoryProgressLine, FactoryPhaseObservation, FactoryPhaseStatus, FactoryAgentSummary, } from "./factory.js";