@github/copilot-sdk-linuxmusl-x64 1.0.14-preview.1 → 1.0.14
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/copilot-sdk/cliVersion.d.ts +2 -0
- package/copilot-sdk/client.d.ts +5 -1
- package/copilot-sdk/docs/factories.md +36 -19
- package/copilot-sdk/extension.js +906 -185
- package/copilot-sdk/factory.d.ts +42 -16
- package/copilot-sdk/ffiRuntimeHost.d.ts +8 -2
- package/copilot-sdk/generated/rpc.d.ts +1683 -84
- package/copilot-sdk/generated/session-events.d.ts +987 -93
- package/copilot-sdk/index.d.ts +2 -2
- package/copilot-sdk/index.js +905 -184
- package/copilot-sdk/runtimeArtifacts.d.ts +13 -1
- package/copilot-sdk/session.d.ts +53 -1
- package/copilot-sdk/types.d.ts +78 -3
- package/package.json +1 -1
- package/prebuilds/linuxmusl-x64/runtime.node +0 -0
- package/schemas/api.schema.json +669 -107
- package/schemas/session-events.schema.json +560 -11
- package/sdk/index.js +256 -254
- package/tgrep/bin/linux-x64/tgrep +0 -0
- package/tgrep/bin/linuxmusl-x64/tgrep +0 -0
package/copilot-sdk/index.js
CHANGED
|
@@ -3318,7 +3318,7 @@ var require_empty_npm_package = __commonJS({
|
|
|
3318
3318
|
}
|
|
3319
3319
|
});
|
|
3320
3320
|
|
|
3321
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
3321
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/ffiRuntimeHost.js
|
|
3322
3322
|
var ffiRuntimeHost_exports = {};
|
|
3323
3323
|
__export(ffiRuntimeHost_exports, {
|
|
3324
3324
|
FfiRuntimeHost: () => FfiRuntimeHost
|
|
@@ -3391,12 +3391,13 @@ function buildEnvJson(environment) {
|
|
|
3391
3391
|
}
|
|
3392
3392
|
return Buffer.from(JSON.stringify(obj), "utf8");
|
|
3393
3393
|
}
|
|
3394
|
-
var import_koffi, SYMBOL_PREFIX, KEEP_ALIVE_INTERVAL_MS, loadedLibraryPath, loadedLibrary, FfiRuntimeHost;
|
|
3394
|
+
var import_koffi, SYMBOL_PREFIX, KEEP_ALIVE_INTERVAL_MS, CLEANUP_RETRY_INTERVAL_MS, loadedLibraryPath, loadedLibrary, FfiRuntimeHost;
|
|
3395
3395
|
var init_ffiRuntimeHost = __esm({
|
|
3396
|
-
"node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
3396
|
+
"node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/ffiRuntimeHost.js"() {
|
|
3397
3397
|
import_koffi = __toESM(require_empty_npm_package(), 1);
|
|
3398
3398
|
SYMBOL_PREFIX = "copilot_runtime_";
|
|
3399
3399
|
KEEP_ALIVE_INTERVAL_MS = 1 << 30;
|
|
3400
|
+
CLEANUP_RETRY_INTERVAL_MS = 100;
|
|
3400
3401
|
FfiRuntimeHost = class _FfiRuntimeHost {
|
|
3401
3402
|
constructor(libraryPath, cliEntrypoint, environment, args) {
|
|
3402
3403
|
this.libraryPath = libraryPath;
|
|
@@ -3422,12 +3423,16 @@ var init_ffiRuntimeHost = __esm({
|
|
|
3422
3423
|
cliEntrypoint;
|
|
3423
3424
|
environment;
|
|
3424
3425
|
args;
|
|
3426
|
+
static quarantinedHosts = /* @__PURE__ */ new Set();
|
|
3425
3427
|
lib;
|
|
3426
3428
|
serverId = 0;
|
|
3427
3429
|
connectionId = 0;
|
|
3428
3430
|
disposed = false;
|
|
3431
|
+
starting = false;
|
|
3429
3432
|
outboundCallback;
|
|
3430
3433
|
keepAliveTimer;
|
|
3434
|
+
cleanupRetryTimer;
|
|
3435
|
+
cleanupInProgress = false;
|
|
3431
3436
|
/** The stream JSON-RPC reads server→client frames from. */
|
|
3432
3437
|
receiveStream;
|
|
3433
3438
|
/** The stream JSON-RPC writes client→server frames to. */
|
|
@@ -3449,49 +3454,65 @@ var init_ffiRuntimeHost = __esm({
|
|
|
3449
3454
|
}
|
|
3450
3455
|
/** Starts the in-process Rust runtime and opens the FFI JSON-RPC connection. */
|
|
3451
3456
|
async start() {
|
|
3457
|
+
if (this.disposed) {
|
|
3458
|
+
throw new Error("The in-process runtime host is disposed.");
|
|
3459
|
+
}
|
|
3460
|
+
this.starting = true;
|
|
3452
3461
|
const argvJson = buildArgvJson(this.cliEntrypoint, this.args);
|
|
3453
3462
|
const envJson = buildEnvJson(this.environment);
|
|
3454
|
-
|
|
3455
|
-
this.
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3463
|
+
try {
|
|
3464
|
+
this.serverId = await new Promise((resolvePromise, rejectPromise) => {
|
|
3465
|
+
this.lib.hostStart.async(
|
|
3466
|
+
argvJson,
|
|
3467
|
+
argvJson.length,
|
|
3468
|
+
envJson,
|
|
3469
|
+
envJson ? envJson.length : 0,
|
|
3470
|
+
(error, result) => {
|
|
3471
|
+
if (error) {
|
|
3472
|
+
rejectPromise(error);
|
|
3473
|
+
} else {
|
|
3474
|
+
resolvePromise(result);
|
|
3475
|
+
}
|
|
3465
3476
|
}
|
|
3466
|
-
|
|
3477
|
+
);
|
|
3478
|
+
});
|
|
3479
|
+
if (!this.serverId) {
|
|
3480
|
+
throw new Error(
|
|
3481
|
+
`copilot_runtime_host_start failed (library '${this.libraryPath}').`
|
|
3482
|
+
);
|
|
3483
|
+
}
|
|
3484
|
+
if (this.disposed) {
|
|
3485
|
+
throw new Error("The in-process runtime host was disposed during startup.");
|
|
3486
|
+
}
|
|
3487
|
+
this.outboundCallback = import_koffi.default.register(
|
|
3488
|
+
(_userData, bytesPtr, bytesLen) => this.feedInbound(bytesPtr, bytesLen),
|
|
3489
|
+
this.lib.outboundCallbackType
|
|
3467
3490
|
);
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
this.
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3491
|
+
this.connectionId = this.lib.connectionOpen(
|
|
3492
|
+
this.serverId,
|
|
3493
|
+
this.outboundCallback,
|
|
3494
|
+
null,
|
|
3495
|
+
null,
|
|
3496
|
+
0,
|
|
3497
|
+
null,
|
|
3498
|
+
0,
|
|
3499
|
+
null,
|
|
3500
|
+
0
|
|
3501
|
+
);
|
|
3502
|
+
if (!this.connectionId) {
|
|
3503
|
+
this.unregisterCallback();
|
|
3504
|
+
this.lib.hostShutdown(this.serverId);
|
|
3505
|
+
this.serverId = 0;
|
|
3506
|
+
throw new Error("copilot_runtime_connection_open failed.");
|
|
3507
|
+
}
|
|
3508
|
+
this.keepAliveTimer = setInterval(() => {
|
|
3509
|
+
}, KEEP_ALIVE_INTERVAL_MS);
|
|
3510
|
+
} finally {
|
|
3511
|
+
this.starting = false;
|
|
3512
|
+
if (this.disposed) {
|
|
3513
|
+
void this.tryFinalizeCleanup();
|
|
3514
|
+
}
|
|
3492
3515
|
}
|
|
3493
|
-
this.keepAliveTimer = setInterval(() => {
|
|
3494
|
-
}, KEEP_ALIVE_INTERVAL_MS);
|
|
3495
3516
|
}
|
|
3496
3517
|
writeFrame(frame) {
|
|
3497
3518
|
if (this.disposed || !this.connectionId) {
|
|
@@ -3530,57 +3551,119 @@ var init_ffiRuntimeHost = __esm({
|
|
|
3530
3551
|
}
|
|
3531
3552
|
unregisterCallback() {
|
|
3532
3553
|
if (this.outboundCallback === void 0) {
|
|
3533
|
-
return;
|
|
3554
|
+
return true;
|
|
3534
3555
|
}
|
|
3535
3556
|
const callback = this.outboundCallback;
|
|
3536
|
-
this.outboundCallback = void 0;
|
|
3537
3557
|
try {
|
|
3538
3558
|
import_koffi.default.unregister(callback);
|
|
3539
|
-
|
|
3559
|
+
this.outboundCallback = void 0;
|
|
3560
|
+
return true;
|
|
3561
|
+
} catch (error) {
|
|
3562
|
+
console.error(
|
|
3563
|
+
`Failed to unregister in-process FFI callback: ${error instanceof Error ? error.stack ?? error.message : String(error)}`
|
|
3564
|
+
);
|
|
3565
|
+
_FfiRuntimeHost.quarantinedHosts.add(this);
|
|
3566
|
+
return false;
|
|
3540
3567
|
}
|
|
3541
3568
|
}
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
if (this.disposed) {
|
|
3569
|
+
scheduleCleanupRetry() {
|
|
3570
|
+
if (this.cleanupRetryTimer !== void 0) {
|
|
3545
3571
|
return;
|
|
3546
3572
|
}
|
|
3547
|
-
this.
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3573
|
+
this.cleanupRetryTimer = setTimeout(() => {
|
|
3574
|
+
this.cleanupRetryTimer = void 0;
|
|
3575
|
+
void this.tryFinalizeCleanup();
|
|
3576
|
+
}, CLEANUP_RETRY_INTERVAL_MS);
|
|
3577
|
+
}
|
|
3578
|
+
async tryFinalizeCleanup() {
|
|
3579
|
+
if (this.cleanupInProgress) {
|
|
3580
|
+
this.scheduleCleanupRetry();
|
|
3581
|
+
return;
|
|
3551
3582
|
}
|
|
3583
|
+
this.cleanupInProgress = true;
|
|
3552
3584
|
try {
|
|
3553
3585
|
if (this.connectionId) {
|
|
3554
|
-
|
|
3586
|
+
let closed = false;
|
|
3587
|
+
try {
|
|
3588
|
+
closed = await new Promise((resolvePromise, rejectPromise) => {
|
|
3589
|
+
this.lib.connectionClose.async(
|
|
3590
|
+
this.connectionId,
|
|
3591
|
+
(error, result) => {
|
|
3592
|
+
if (error) {
|
|
3593
|
+
rejectPromise(error);
|
|
3594
|
+
} else {
|
|
3595
|
+
resolvePromise(result);
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
);
|
|
3599
|
+
});
|
|
3600
|
+
} catch (error) {
|
|
3601
|
+
console.error(
|
|
3602
|
+
`Failed to close in-process FFI connection: ${error instanceof Error ? error.stack ?? error.message : String(error)}`
|
|
3603
|
+
);
|
|
3604
|
+
_FfiRuntimeHost.quarantinedHosts.add(this);
|
|
3605
|
+
if (this.keepAliveTimer !== void 0) {
|
|
3606
|
+
clearInterval(this.keepAliveTimer);
|
|
3607
|
+
this.keepAliveTimer = void 0;
|
|
3608
|
+
}
|
|
3609
|
+
return;
|
|
3610
|
+
}
|
|
3611
|
+
if (!closed) {
|
|
3612
|
+
this.scheduleCleanupRetry();
|
|
3613
|
+
return;
|
|
3614
|
+
}
|
|
3555
3615
|
this.connectionId = 0;
|
|
3556
3616
|
}
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3617
|
+
const callbackUnregistered = this.unregisterCallback();
|
|
3618
|
+
if (this.keepAliveTimer !== void 0) {
|
|
3619
|
+
clearInterval(this.keepAliveTimer);
|
|
3620
|
+
this.keepAliveTimer = void 0;
|
|
3621
|
+
}
|
|
3560
3622
|
if (this.serverId) {
|
|
3561
|
-
|
|
3623
|
+
try {
|
|
3624
|
+
if (!this.lib.hostShutdown(this.serverId)) {
|
|
3625
|
+
console.error(
|
|
3626
|
+
`In-process FFI host shutdown did not recognize server ${this.serverId}.`
|
|
3627
|
+
);
|
|
3628
|
+
}
|
|
3629
|
+
} catch (error) {
|
|
3630
|
+
console.error(
|
|
3631
|
+
`Failed to shut down in-process FFI host: ${error instanceof Error ? error.stack ?? error.message : String(error)}`
|
|
3632
|
+
);
|
|
3633
|
+
}
|
|
3562
3634
|
this.serverId = 0;
|
|
3563
3635
|
}
|
|
3564
|
-
|
|
3636
|
+
if (callbackUnregistered) {
|
|
3637
|
+
_FfiRuntimeHost.quarantinedHosts.delete(this);
|
|
3638
|
+
}
|
|
3639
|
+
} finally {
|
|
3640
|
+
this.cleanupInProgress = false;
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
/** Awaits the initial cleanup attempt; a non-quiescent close is retried in the background. */
|
|
3644
|
+
async dispose() {
|
|
3645
|
+
if (this.disposed) {
|
|
3646
|
+
return;
|
|
3565
3647
|
}
|
|
3648
|
+
this.disposed = true;
|
|
3566
3649
|
this.receiveStream.end();
|
|
3567
|
-
this.
|
|
3650
|
+
if (!this.starting) {
|
|
3651
|
+
await this.tryFinalizeCleanup();
|
|
3652
|
+
}
|
|
3568
3653
|
}
|
|
3569
3654
|
};
|
|
3570
3655
|
}
|
|
3571
3656
|
});
|
|
3572
3657
|
|
|
3573
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
3658
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/client.js
|
|
3574
3659
|
var import_node2 = __toESM(require_node(), 1);
|
|
3575
3660
|
import { spawn } from "node:child_process";
|
|
3576
3661
|
import { randomUUID } from "node:crypto";
|
|
3577
3662
|
import { existsSync as existsSync3 } from "node:fs";
|
|
3578
|
-
import {
|
|
3579
|
-
import { Socket } from "node:net";
|
|
3663
|
+
import { isIPv6, Socket } from "node:net";
|
|
3580
3664
|
import { dirname as dirname2, isAbsolute, join as join2, resolve as resolve2 } from "node:path";
|
|
3581
|
-
import { fileURLToPath } from "node:url";
|
|
3582
3665
|
|
|
3583
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
3666
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/generated/rpc.js
|
|
3584
3667
|
function createServerRpc(connection) {
|
|
3585
3668
|
return {
|
|
3586
3669
|
/**
|
|
@@ -3594,6 +3677,17 @@ function createServerRpc(connection) {
|
|
|
3594
3677
|
*/
|
|
3595
3678
|
ping: async (params) => connection.sendRequest("ping", params),
|
|
3596
3679
|
/** @experimental */
|
|
3680
|
+
hooks: {
|
|
3681
|
+
/**
|
|
3682
|
+
* Discovers hook actions enabled under server-side discovery settings from user, repository, plugin, and managed-policy sources.
|
|
3683
|
+
*
|
|
3684
|
+
* @param params Optional project paths and host-exclusion behavior for server-scoped hook discovery.
|
|
3685
|
+
*
|
|
3686
|
+
* @returns Server-discovered hook actions and partial-load diagnostics from user, repository, plugin, and managed-policy sources. Concrete sessions may include additional session-specific hook sources.
|
|
3687
|
+
*/
|
|
3688
|
+
discover: async (params) => connection.sendRequest("hooks.discover", params)
|
|
3689
|
+
},
|
|
3690
|
+
/** @experimental */
|
|
3597
3691
|
models: {
|
|
3598
3692
|
/**
|
|
3599
3693
|
* Lists Copilot models available to the authenticated user.
|
|
@@ -3810,13 +3904,13 @@ function createServerRpc(connection) {
|
|
|
3810
3904
|
/**
|
|
3811
3905
|
* Enables installed plugins for new sessions.
|
|
3812
3906
|
*
|
|
3813
|
-
* @param params Plugin names (or specs) to enable.
|
|
3907
|
+
* @param params Plugin names (or specs) to enable, plus the optional working directory the repository-controlled guard is evaluated against.
|
|
3814
3908
|
*/
|
|
3815
3909
|
enable: async (params) => connection.sendRequest("plugins.enable", params),
|
|
3816
3910
|
/**
|
|
3817
3911
|
* Disables installed plugins for new sessions.
|
|
3818
3912
|
*
|
|
3819
|
-
* @param params Plugin names (or specs) to disable.
|
|
3913
|
+
* @param params Plugin names (or specs) to disable, plus the optional working directory the repository-controlled guard is evaluated against.
|
|
3820
3914
|
*/
|
|
3821
3915
|
disable: async (params) => connection.sendRequest("plugins.disable", params),
|
|
3822
3916
|
/** @experimental */
|
|
@@ -3982,7 +4076,11 @@ function createServerRpc(connection) {
|
|
|
3982
4076
|
*
|
|
3983
4077
|
* @returns Validated device-managed settings discovered before a session exists.
|
|
3984
4078
|
*/
|
|
3985
|
-
read: async () => connection.sendRequest("managedSettings.read", {})
|
|
4079
|
+
read: async () => connection.sendRequest("managedSettings.read", {}),
|
|
4080
|
+
/**
|
|
4081
|
+
* Force-refreshes enterprise managed settings for every account: wipes the persistent server-policy cache (the whole `<cacheHome>/managed-settings` directory) and drops this runtime process's in-memory retained server policy. It does not itself fetch policy — the effect is that the next time a session resolves managed settings for an account, that resolution re-fetches the account's org policy from the network instead of serving a cached response. Note that `managedSettings.read` returns only device/MDM settings and never triggers the account server-policy fetch, so a host implementing "sync account policy" should start a fresh session resolution rather than treat a subsequent `managedSettings.read` as the refreshed org policy. Mirrors the invalidation a sign-out performs, broadened from the one signing-out account to all of them; device/MDM layers describe the machine, not the account, and are left untouched. Rejects if the on-disk cache cannot be removed.
|
|
4082
|
+
*/
|
|
4083
|
+
clearCache: async () => connection.sendRequest("managedSettings.clearCache", {})
|
|
3986
4084
|
},
|
|
3987
4085
|
/** @experimental */
|
|
3988
4086
|
runtime: {
|
|
@@ -4061,6 +4159,22 @@ function createServerRpc(connection) {
|
|
|
4061
4159
|
* @returns Sessions matching the filter, ordered most-recently-modified first.
|
|
4062
4160
|
*/
|
|
4063
4161
|
list: async (params) => connection.sendRequest("sessions.list", params),
|
|
4162
|
+
/**
|
|
4163
|
+
* Reads client-owned metadata for multiple persisted local sessions without opening them. Results preserve request order and report missing, corrupt, unsupported, or temporarily unavailable sessions independently.
|
|
4164
|
+
*
|
|
4165
|
+
* @param params Bounded batch request for client-owned metadata from persisted local sessions.
|
|
4166
|
+
*
|
|
4167
|
+
* @returns Ordered client metadata outcomes for the requested local sessions.
|
|
4168
|
+
*/
|
|
4169
|
+
getClientMetadata: async (params) => connection.sendRequest("sessions.getClientMetadata", params),
|
|
4170
|
+
/**
|
|
4171
|
+
* Reads a page of durable events directly from a local session's persisted journal without creating, resuming, or activating the session. The first read pins the currently opened journal generation and its byte-length boundary; opaque cursor continuations remain on that generation across runtime-owned compaction, truncation, and rewrite operations, which replace the live path atomically, and events appended after the boundary are excluded. For cold hydration, await the first successful page before activation and establish lossless live-event buffering before resume; merge subsequent live events by ID, preserving persisted order and letting live payloads win. Continuations are process-local, single-use capabilities bound to the originating session and storage context and must be paged sequentially; concurrent or repeated use of the same cursor expires that duplicate read rather than reading the generation twice. A complete snapshot has cursorStatus 'ok' and hasMore false. Snapshots expire after five idle minutes, with at most eight retained per process and idle-only eviction under pressure; completion and cancelled-worker exit release their handles. No transcript copy is created, but retained handles may keep replaced files' disk blocks alive until release. Pages have a soft 1 MiB serialized event-array budget including resolved binary assets; one oversized event is returned alone to guarantee progress. Working memory also includes a record/lookahead and asset resolution; resolving the first binary reference may scan the full pinned generation to build a bounded offset index. If the snapshot expires, is evicted, is cancelled before a continuation is established, or becomes unreadable after an observable unsupported in-place shortening, the continuation returns cursorStatus 'expired' with an empty terminal page and never falls back to a different generation. A missing or initially unreadable journal is an RPC error. Persisted history excludes ephemeral events and may omit payloads that are reconstructed only for an active session; use the active session event stream for post-resume live events.
|
|
4172
|
+
*
|
|
4173
|
+
* @param params Pagination options for reading an inactive or active local session's persisted event journal.
|
|
4174
|
+
*
|
|
4175
|
+
* @returns Batch of session events returned by a read, with cursor and continuation metadata.
|
|
4176
|
+
*/
|
|
4177
|
+
readPersistedEvents: async (params) => connection.sendRequest("sessions.readPersistedEvents", params),
|
|
4064
4178
|
/**
|
|
4065
4179
|
* Finds the local session bound to a GitHub task ID, if any.
|
|
4066
4180
|
*
|
|
@@ -4335,7 +4449,15 @@ function createSessionRpc(connection, sessionId) {
|
|
|
4335
4449
|
*
|
|
4336
4450
|
* @returns Managed sandbox enforcement state for a session.
|
|
4337
4451
|
*/
|
|
4338
|
-
getEnforcementStatus: async () => connection.sendRequest("session.sandbox.getEnforcementStatus", { sessionId })
|
|
4452
|
+
getEnforcementStatus: async () => connection.sendRequest("session.sandbox.getEnforcementStatus", { sessionId }),
|
|
4453
|
+
/**
|
|
4454
|
+
* Disables sandboxing for the remainder of the current session and approves the referenced pending sandbox-bypass permission request. The request is rejected unless the exact request is still pending and the effective sandbox policy permits bypass.
|
|
4455
|
+
*
|
|
4456
|
+
* @param params Request to disable sandboxing for the current session while resolving an active sandbox-bypass permission prompt.
|
|
4457
|
+
*
|
|
4458
|
+
* @returns Result of attempting to disable sandboxing for the current session.
|
|
4459
|
+
*/
|
|
4460
|
+
disableForSession: async (params) => connection.sendRequest("session.sandbox.disableForSession", { sessionId, ...params })
|
|
4339
4461
|
},
|
|
4340
4462
|
/**
|
|
4341
4463
|
* Aborts the current agent turn.
|
|
@@ -4499,6 +4621,14 @@ function createSessionRpc(connection, sessionId) {
|
|
|
4499
4621
|
* @returns Complete current or terminal factory run envelope.
|
|
4500
4622
|
*/
|
|
4501
4623
|
cancel: async (params) => connection.sendRequest("session.factory.cancel", { sessionId, ...params }),
|
|
4624
|
+
/**
|
|
4625
|
+
* Pauses a running factory and returns its settled run envelope.
|
|
4626
|
+
*
|
|
4627
|
+
* @param params Parameters for pausing a running factory.
|
|
4628
|
+
*
|
|
4629
|
+
* @returns Complete current or terminal factory run envelope.
|
|
4630
|
+
*/
|
|
4631
|
+
pause: async (params) => connection.sendRequest("session.factory.pause", { sessionId, ...params }),
|
|
4502
4632
|
/**
|
|
4503
4633
|
* Records a batch of ordered factory progress lines.
|
|
4504
4634
|
*
|
|
@@ -4538,9 +4668,9 @@ function createSessionRpc(connection, sessionId) {
|
|
|
4538
4668
|
/** @experimental */
|
|
4539
4669
|
model: {
|
|
4540
4670
|
/**
|
|
4541
|
-
* Gets the
|
|
4671
|
+
* Gets the session's authoritative model snapshot, including the committed Auto preference and any newer unclaimed Auto preference waiting for a future user turn.
|
|
4542
4672
|
*
|
|
4543
|
-
* @returns The
|
|
4673
|
+
* @returns The session's authoritative model snapshot. Auto preference fields are configuration for the virtual `auto` model and do not change the selected model identifier. The context tier reflects `Session.getContextTier()`, restored from the session journal on resume.
|
|
4544
4674
|
*/
|
|
4545
4675
|
getCurrent: async () => connection.sendRequest("session.model.getCurrent", { sessionId }),
|
|
4546
4676
|
/**
|
|
@@ -4551,6 +4681,22 @@ function createSessionRpc(connection, sessionId) {
|
|
|
4551
4681
|
* @returns The model identifier active on the session after the switch.
|
|
4552
4682
|
*/
|
|
4553
4683
|
switchTo: async (params) => connection.sendRequest("session.model.switchTo", { sessionId, ...params }),
|
|
4684
|
+
/**
|
|
4685
|
+
* Requests an Auto preference change without changing the session's selected model. The latest unclaimed request wins; the runtime commits it only after a later prompt using the `auto` model mints a usable model and token pair. A `pending` response confirms that the request was accepted, not that it committed. Observe eventual success through `session.model_change`, failure through the ephemeral `session.auto_tier_switch_failed` event, or current unclaimed state through `session.model.getCurrent`.
|
|
4686
|
+
*
|
|
4687
|
+
* @param params An Auto preference request for the session. This updates Auto configuration only; it does not change the selected model to `auto`.
|
|
4688
|
+
*
|
|
4689
|
+
* @returns Immediate acknowledgement and Auto preference snapshot after a switch request. This result never implies that a pending preference committed.
|
|
4690
|
+
*/
|
|
4691
|
+
switchAutoTier: async (params) => connection.sendRequest("session.model.switchAutoTier", { sessionId, ...params }),
|
|
4692
|
+
/**
|
|
4693
|
+
* Replaces or clears the host-supplied model allowlist for a running session.
|
|
4694
|
+
*
|
|
4695
|
+
* @param params Host-supplied exact model selection IDs to allow for this running session. CAPI IDs are intersected with repository `.github/allowed_models.txt` policy; provider-qualified IDs remain exempt from repository-only policy but are restricted by this host list. Omit or pass null to clear the host restriction; an explicit empty or disjoint list is rejected. Validation and pre-selection fallback failures preserve the previous restriction. Failures after a fallback selection commits retain the new restriction and selected model; callers should inspect current session state after such an error.
|
|
4696
|
+
*
|
|
4697
|
+
* @returns The applied host allowlist and effective session model policy after intersection.
|
|
4698
|
+
*/
|
|
4699
|
+
setAllowedModels: async (params) => connection.sendRequest("session.model.setAllowedModels", { sessionId, ...params }),
|
|
4554
4700
|
/**
|
|
4555
4701
|
* Updates the session's reasoning effort without changing the selected model.
|
|
4556
4702
|
*
|
|
@@ -4757,6 +4903,15 @@ function createSessionRpc(connection, sessionId) {
|
|
|
4757
4903
|
diff: async (params) => connection.sendRequest("session.workspaces.diff", { sessionId, ...params })
|
|
4758
4904
|
},
|
|
4759
4905
|
/** @experimental */
|
|
4906
|
+
autopilotObjective: {
|
|
4907
|
+
/**
|
|
4908
|
+
* Reads the current canonical autopilot objective state for this session.
|
|
4909
|
+
*
|
|
4910
|
+
* @returns Canonical runtime state for the session's current autopilot objective.
|
|
4911
|
+
*/
|
|
4912
|
+
getState: async () => connection.sendRequest("session.autopilotObjective.getState", { sessionId })
|
|
4913
|
+
},
|
|
4914
|
+
/** @experimental */
|
|
4760
4915
|
completions: {
|
|
4761
4916
|
/**
|
|
4762
4917
|
* Gets the characters that should trigger host-driven completions for the session. Empty disables host-driven completions (e.g. local sessions, or a relay host that does not advertise them).
|
|
@@ -4787,7 +4942,7 @@ function createSessionRpc(connection, sessionId) {
|
|
|
4787
4942
|
/**
|
|
4788
4943
|
* Starts fleet mode by submitting the fleet orchestration prompt to the session.
|
|
4789
4944
|
*
|
|
4790
|
-
* @param params
|
|
4945
|
+
* @param params Parameters for starting fleet orchestration: an optional user prompt combined with the fleet instructions, plus the send options forwarded to the resulting turn.
|
|
4791
4946
|
*
|
|
4792
4947
|
* @returns Indicates whether fleet mode was successfully activated.
|
|
4793
4948
|
*/
|
|
@@ -4850,6 +5005,22 @@ function createSessionRpc(connection, sessionId) {
|
|
|
4850
5005
|
* @returns Background tasks currently tracked by the session.
|
|
4851
5006
|
*/
|
|
4852
5007
|
list: async () => connection.sendRequest("session.tasks.list", { sessionId }),
|
|
5008
|
+
/**
|
|
5009
|
+
* Registers a client-owned task, or reclaims an orphaned task belonging to the same extension principal.
|
|
5010
|
+
*
|
|
5011
|
+
* @param params Registers or reclaims a client-owned task.
|
|
5012
|
+
*
|
|
5013
|
+
* @returns Result of registering or reclaiming a client-owned task.
|
|
5014
|
+
*/
|
|
5015
|
+
register: async (params) => connection.sendRequest("session.tasks.register", { sessionId, ...params }),
|
|
5016
|
+
/**
|
|
5017
|
+
* Publishes generic progress or a terminal outcome for a client-owned task.
|
|
5018
|
+
*
|
|
5019
|
+
* @param params Updates a client-owned task.
|
|
5020
|
+
*
|
|
5021
|
+
* @returns Result of publishing a client-owned task update.
|
|
5022
|
+
*/
|
|
5023
|
+
update: async (params) => connection.sendRequest("session.tasks.update", { sessionId, ...params }),
|
|
4853
5024
|
/**
|
|
4854
5025
|
* Refreshes metadata for any detached background shells the runtime knows about.
|
|
4855
5026
|
*
|
|
@@ -5313,7 +5484,7 @@ function createSessionRpc(connection, sessionId) {
|
|
|
5313
5484
|
*/
|
|
5314
5485
|
set: async (params) => connection.sendRequest("session.tools.set", { sessionId, ...params }),
|
|
5315
5486
|
/**
|
|
5316
|
-
*
|
|
5487
|
+
* Sets the current session's live subagent settings override, which takes precedence over persisted user settings until cleared. Persisted user settings remain the source of truth for future sessions.
|
|
5317
5488
|
*
|
|
5318
5489
|
* @param params Subagent settings to apply to the current session
|
|
5319
5490
|
*
|
|
@@ -5663,6 +5834,20 @@ function createSessionRpc(connection, sessionId) {
|
|
|
5663
5834
|
* @returns Point-in-time snapshot of slow-changing session identifier and state fields
|
|
5664
5835
|
*/
|
|
5665
5836
|
snapshot: async () => connection.sendRequest("session.metadata.snapshot", { sessionId }),
|
|
5837
|
+
/**
|
|
5838
|
+
* Returns the client-owned string metadata persisted with this local session. The metadata is not included in model context, events, telemetry, snapshots, or remote exports.
|
|
5839
|
+
*
|
|
5840
|
+
* @returns Client-owned, case-sensitive string metadata persisted with a local session. Clients should namespace keys by owner. Keys must be non-empty and at most 256 UTF-8 bytes; keys under `copilot/` and `github/` are reserved. Values may contain at most 16 KiB of UTF-8 data. A bag may contain at most 128 entries and its serialized sidecar may contain at most 64 KiB. The runtime stores but never interprets these values.
|
|
5841
|
+
*/
|
|
5842
|
+
getClientMetadata: async () => connection.sendRequest("session.metadata.getClientMetadata", { sessionId }),
|
|
5843
|
+
/**
|
|
5844
|
+
* Atomically patches the client-owned string metadata persisted with this local session and returns the committed bag.
|
|
5845
|
+
*
|
|
5846
|
+
* @param params Atomic patch for client-owned session metadata. Operations apply in clear, remove, then set order. The resulting bag must satisfy the ClientMetadata entry and serialized-size limits. Local storage coordinates concurrent runtime processes; custom SessionFs providers must serialize writers that access the same session from multiple processes.
|
|
5847
|
+
*
|
|
5848
|
+
* @returns Client-owned, case-sensitive string metadata persisted with a local session. Clients should namespace keys by owner. Keys must be non-empty and at most 256 UTF-8 bytes; keys under `copilot/` and `github/` are reserved. Values may contain at most 16 KiB of UTF-8 data. A bag may contain at most 128 entries and its serialized sidecar may contain at most 64 KiB. The runtime stores but never interprets these values.
|
|
5849
|
+
*/
|
|
5850
|
+
updateClientMetadata: async (params) => connection.sendRequest("session.metadata.updateClientMetadata", { sessionId, ...params }),
|
|
5666
5851
|
/**
|
|
5667
5852
|
* Reports whether the local session is currently processing user/agent messages.
|
|
5668
5853
|
*
|
|
@@ -6020,6 +6205,294 @@ function createSessionRpc(connection, sessionId) {
|
|
|
6020
6205
|
}
|
|
6021
6206
|
};
|
|
6022
6207
|
}
|
|
6208
|
+
function createInternalSessionRpc(connection, sessionId) {
|
|
6209
|
+
return {
|
|
6210
|
+
/**
|
|
6211
|
+
* Queues or sends an internal system notification to the session according to its passive policy.
|
|
6212
|
+
*
|
|
6213
|
+
* @param params Internal request for sending a system notification.
|
|
6214
|
+
*
|
|
6215
|
+
* @experimental
|
|
6216
|
+
*/
|
|
6217
|
+
sendSystemNotification: async (params) => connection.sendRequest("session.sendSystemNotification", { sessionId, ...params }),
|
|
6218
|
+
/** @experimental */
|
|
6219
|
+
gitHubAuth: {
|
|
6220
|
+
/**
|
|
6221
|
+
* Gets the current authentication information for internal session hosts.
|
|
6222
|
+
*
|
|
6223
|
+
* @returns Current authentication information, or null when no authentication is active.
|
|
6224
|
+
*/
|
|
6225
|
+
getCurrentAuthInfo: async () => connection.sendRequest("session.gitHubAuth.getCurrentAuthInfo", { sessionId }),
|
|
6226
|
+
/**
|
|
6227
|
+
* Gets all authentication accounts available to the internal session host.
|
|
6228
|
+
*
|
|
6229
|
+
* @returns Authentication accounts available to the internal session host.
|
|
6230
|
+
*/
|
|
6231
|
+
getAllAuthAvailable: async () => connection.sendRequest("session.gitHubAuth.getAllAuthAvailable", { sessionId }),
|
|
6232
|
+
/**
|
|
6233
|
+
* Refreshes Copilot account metadata for the current authentication.
|
|
6234
|
+
*
|
|
6235
|
+
* @returns Current authentication information, or null when no authentication is active.
|
|
6236
|
+
*/
|
|
6237
|
+
refreshCopilotUser: async () => connection.sendRequest("session.gitHubAuth.refreshCopilotUser", { sessionId }),
|
|
6238
|
+
/**
|
|
6239
|
+
* Logs in a GitHub user through the internal session host.
|
|
6240
|
+
*
|
|
6241
|
+
* @param params Internal GitHub login parameters.
|
|
6242
|
+
*
|
|
6243
|
+
* @returns Authentication credentials accepted only at native protocol ingress. Runtime outputs use credential-free `AuthIdentity` metadata.
|
|
6244
|
+
*/
|
|
6245
|
+
login: async (params) => connection.sendRequest("session.gitHubAuth.login", { sessionId, ...params }),
|
|
6246
|
+
/**
|
|
6247
|
+
* Switches the session to another available authentication.
|
|
6248
|
+
*
|
|
6249
|
+
* @param params Parameters for switching the session's active authentication.
|
|
6250
|
+
*/
|
|
6251
|
+
switchToAuth: async (params) => connection.sendRequest("session.gitHubAuth.switchToAuth", { sessionId, ...params }),
|
|
6252
|
+
/**
|
|
6253
|
+
* Logs out the session's current GitHub authentication.
|
|
6254
|
+
*
|
|
6255
|
+
* @returns Whether the current authentication was logged out.
|
|
6256
|
+
*/
|
|
6257
|
+
logout: async () => connection.sendRequest("session.gitHubAuth.logout", { sessionId }),
|
|
6258
|
+
/**
|
|
6259
|
+
* Logs out a specific GitHub authentication.
|
|
6260
|
+
*
|
|
6261
|
+
* @param params Parameters identifying a GitHub authentication to log out.
|
|
6262
|
+
*
|
|
6263
|
+
* @returns Whether the requested authentication was logged out.
|
|
6264
|
+
*/
|
|
6265
|
+
logoutUser: async (params) => connection.sendRequest("session.gitHubAuth.logoutUser", { sessionId, ...params }),
|
|
6266
|
+
/**
|
|
6267
|
+
* Gets validation errors from the most recent authentication attempt.
|
|
6268
|
+
*
|
|
6269
|
+
* @returns Validation errors from the most recent authentication attempt.
|
|
6270
|
+
*/
|
|
6271
|
+
lastAuthErrors: async () => connection.sendRequest("session.gitHubAuth.lastAuthErrors", { sessionId })
|
|
6272
|
+
},
|
|
6273
|
+
/** @experimental */
|
|
6274
|
+
canvas: {
|
|
6275
|
+
/** @experimental */
|
|
6276
|
+
provider: {
|
|
6277
|
+
/**
|
|
6278
|
+
* Registers an internal canvas provider connection and its contributions.
|
|
6279
|
+
*
|
|
6280
|
+
* @param params Internal canvas provider registration parameters.
|
|
6281
|
+
*/
|
|
6282
|
+
register: async (params) => connection.sendRequest("session.canvas.provider.register", { sessionId, ...params }),
|
|
6283
|
+
/**
|
|
6284
|
+
* Unregisters an internal canvas provider connection.
|
|
6285
|
+
*
|
|
6286
|
+
* @param params Internal canvas provider unregistration parameters.
|
|
6287
|
+
*/
|
|
6288
|
+
unregister: async (params) => connection.sendRequest("session.canvas.provider.unregister", { sessionId, ...params })
|
|
6289
|
+
}
|
|
6290
|
+
},
|
|
6291
|
+
/** @experimental */
|
|
6292
|
+
factory: {
|
|
6293
|
+
/**
|
|
6294
|
+
* Internal tool-originated factory invocation.
|
|
6295
|
+
*
|
|
6296
|
+
* @param params Internal parameters for invoking a registered factory from a tool.
|
|
6297
|
+
*
|
|
6298
|
+
* @returns Complete current or terminal factory run envelope.
|
|
6299
|
+
*/
|
|
6300
|
+
runFromTool: async (params) => connection.sendRequest("session.factory.runFromTool", { sessionId, ...params }),
|
|
6301
|
+
/**
|
|
6302
|
+
* Internal tool-originated factory resume.
|
|
6303
|
+
*
|
|
6304
|
+
* @param params Internal parameters for resuming a factory run from a tool.
|
|
6305
|
+
*
|
|
6306
|
+
* @returns Resolved persisted factory identity and resumed run envelope.
|
|
6307
|
+
*/
|
|
6308
|
+
resumeFromTool: async (params) => connection.sendRequest("session.factory.resumeFromTool", { sessionId, ...params }),
|
|
6309
|
+
/**
|
|
6310
|
+
* Atomically pauses an owned factory attempt at a durable checkpoint.
|
|
6311
|
+
*
|
|
6312
|
+
* @param params Parameters for an owned durable pause checkpoint.
|
|
6313
|
+
*/
|
|
6314
|
+
pauseAtCheckpoint: async (params) => connection.sendRequest("session.factory.pauseAtCheckpoint", { sessionId, ...params })
|
|
6315
|
+
},
|
|
6316
|
+
/** @experimental */
|
|
6317
|
+
model: {
|
|
6318
|
+
/**
|
|
6319
|
+
* Resolves and applies organization-managed and repository model overlays.
|
|
6320
|
+
*
|
|
6321
|
+
* @param params Managed, repository, and CLI model overrides to overlay onto the session at startup.
|
|
6322
|
+
*
|
|
6323
|
+
* @returns The model identifier active on the session after the switch.
|
|
6324
|
+
*/
|
|
6325
|
+
applyStartupOverlay: async (params) => connection.sendRequest("session.model.applyStartupOverlay", { sessionId, ...params })
|
|
6326
|
+
},
|
|
6327
|
+
/** @experimental */
|
|
6328
|
+
mcp: {
|
|
6329
|
+
/**
|
|
6330
|
+
* Reloads MCP server connections for the session with an explicit host-provided configuration.
|
|
6331
|
+
*
|
|
6332
|
+
* @param params Opaque MCP reload configuration.
|
|
6333
|
+
*
|
|
6334
|
+
* @returns MCP server startup filtering result.
|
|
6335
|
+
*/
|
|
6336
|
+
reloadWithConfig: async (params) => connection.sendRequest("session.mcp.reloadWithConfig", { sessionId, ...params }),
|
|
6337
|
+
/**
|
|
6338
|
+
* Configures the built-in GitHub MCP server for the session's current auth context.
|
|
6339
|
+
*
|
|
6340
|
+
* @param params Credential-free authentication identity used to configure GitHub MCP.
|
|
6341
|
+
*
|
|
6342
|
+
* @returns Result of configuring GitHub MCP.
|
|
6343
|
+
*/
|
|
6344
|
+
configureGitHub: async (params) => connection.sendRequest("session.mcp.configureGitHub", { sessionId, ...params }),
|
|
6345
|
+
/**
|
|
6346
|
+
* Registers a pre-connected external MCP client (e.g. IDE) on the session's host. The caller retains lifecycle ownership of the client and transport. Marked internal because the `client` and `transport` arguments are in-process MCP SDK instances that cannot be serialized across the JSON-RPC boundary; once the CLI moves on top of the SDK, external clients will be expressed as transport configs the runtime can construct itself.
|
|
6347
|
+
*
|
|
6348
|
+
* @param params Registration parameters for an external MCP client.
|
|
6349
|
+
*/
|
|
6350
|
+
registerExternalClient: async (params) => connection.sendRequest("session.mcp.registerExternalClient", { sessionId, ...params }),
|
|
6351
|
+
/**
|
|
6352
|
+
* Unregisters a previously registered external MCP client by server name. Marked internal as the paired companion of `registerExternalClient`: only in-process callers that registered a client this way can meaningfully unregister it. Disappears alongside `registerExternalClient`: once external clients are described to the runtime as config rather than handed in as instances, lifecycle (including deregistration) is owned entirely by the runtime.
|
|
6353
|
+
*
|
|
6354
|
+
* @param params Server name identifying the external client to remove.
|
|
6355
|
+
*/
|
|
6356
|
+
unregisterExternalClient: async (params) => connection.sendRequest("session.mcp.unregisterExternalClient", { sessionId, ...params })
|
|
6357
|
+
},
|
|
6358
|
+
/** @experimental */
|
|
6359
|
+
commands: {
|
|
6360
|
+
/**
|
|
6361
|
+
* Finalizes persistence associated with a client-applied slash-command effect.
|
|
6362
|
+
*
|
|
6363
|
+
* @param params The pending slash-command invocation effect to finalize, plus whether the host applied or cancelled it.
|
|
6364
|
+
*
|
|
6365
|
+
* @returns Whether finalizing the invocation effect succeeded, and the failure reason when it did not.
|
|
6366
|
+
*/
|
|
6367
|
+
finalizeInvocationEffect: async (params) => connection.sendRequest("session.commands.finalizeInvocationEffect", { sessionId, ...params })
|
|
6368
|
+
},
|
|
6369
|
+
/** @experimental */
|
|
6370
|
+
settings: {
|
|
6371
|
+
/**
|
|
6372
|
+
* Returns a redacted snapshot of session runtime settings, with secrets and raw feature flags excluded. Internal: the runtime settings shape is a runtime-internal surface and is deliberately kept out of the public SDK, because consumers should not depend on the runtime's internal settings layout. It remains callable in-process and is expected to be reworked as the runtime internals are consolidated.
|
|
6373
|
+
*
|
|
6374
|
+
* @returns Redacted, serializable view of session runtime settings for SDK boundary consumers. Secrets and raw feature flags are intentionally excluded.
|
|
6375
|
+
*/
|
|
6376
|
+
snapshot: async () => connection.sendRequest("session.settings.snapshot", { sessionId }),
|
|
6377
|
+
/**
|
|
6378
|
+
* Evaluates a named Rust-owned settings predicate without exposing raw feature flags. Internal: the raw feature-flag names and composition are runtime-internal, so this predicate-evaluation helper is kept out of the public SDK surface and is callable in-process only.
|
|
6379
|
+
*
|
|
6380
|
+
* @param params Named Rust-owned settings predicate to evaluate for this session.
|
|
6381
|
+
*
|
|
6382
|
+
* @returns Result of evaluating a Rust-owned settings predicate.
|
|
6383
|
+
*/
|
|
6384
|
+
evaluatePredicate: async (params) => connection.sendRequest("session.settings.evaluatePredicate", { sessionId, ...params })
|
|
6385
|
+
},
|
|
6386
|
+
/** @experimental */
|
|
6387
|
+
queue: {
|
|
6388
|
+
/**
|
|
6389
|
+
* Returns the internal native queue snapshot for in-process session orchestration.
|
|
6390
|
+
*
|
|
6391
|
+
* @returns Internal snapshot of native queue state for local session orchestration.
|
|
6392
|
+
*/
|
|
6393
|
+
snapshot: async () => connection.sendRequest("session.queue.snapshot", { sessionId }),
|
|
6394
|
+
/**
|
|
6395
|
+
* Reports whether the local session has native queued work pending.
|
|
6396
|
+
*
|
|
6397
|
+
* @returns Whether the native queue has pending work.
|
|
6398
|
+
*/
|
|
6399
|
+
hasPending: async () => connection.sendRequest("session.queue.hasPending", { sessionId }),
|
|
6400
|
+
/**
|
|
6401
|
+
* Begins a native deferred-idle drain when background work has quiesced.
|
|
6402
|
+
*
|
|
6403
|
+
* @param params Inputs for starting a deferred-idle drain.
|
|
6404
|
+
*
|
|
6405
|
+
* @returns Whether a deferred-idle drain should run.
|
|
6406
|
+
*/
|
|
6407
|
+
beginDeferredIdleDrain: async (params) => connection.sendRequest("session.queue.beginDeferredIdleDrain", { sessionId, ...params }),
|
|
6408
|
+
/**
|
|
6409
|
+
* Finishes a native deferred-idle drain and reports whether to drain queue work or emit idle.
|
|
6410
|
+
*
|
|
6411
|
+
* @param params Inputs for completing a deferred-idle drain.
|
|
6412
|
+
*
|
|
6413
|
+
* @returns Action selected by the native deferred-idle drain.
|
|
6414
|
+
*/
|
|
6415
|
+
finishDeferredIdleDrain: async (params) => connection.sendRequest("session.queue.finishDeferredIdleDrain", { sessionId, ...params }),
|
|
6416
|
+
/**
|
|
6417
|
+
* Marks session.idle as deferred by native background work state.
|
|
6418
|
+
*
|
|
6419
|
+
* @param params Inputs for marking session.idle deferred in native state.
|
|
6420
|
+
*/
|
|
6421
|
+
deferSessionIdle: async (params) => connection.sendRequest("session.queue.deferSessionIdle", { sessionId, ...params }),
|
|
6422
|
+
/**
|
|
6423
|
+
* Consumes queued native system notifications matching an internal filter.
|
|
6424
|
+
*
|
|
6425
|
+
* @param params Internal filter for consuming queued system notifications.
|
|
6426
|
+
*
|
|
6427
|
+
* @returns Indicates whether a user-facing pending item was removed.
|
|
6428
|
+
*/
|
|
6429
|
+
consumeSystemNotifications: async (params) => connection.sendRequest("session.queue.consumeSystemNotifications", { sessionId, ...params }),
|
|
6430
|
+
/**
|
|
6431
|
+
* Enqueues the internal resume-pending wake item when orphan handling needs a follow-up turn.
|
|
6432
|
+
*
|
|
6433
|
+
* @returns Result of enqueueing the resume-pending wake item.
|
|
6434
|
+
*/
|
|
6435
|
+
enqueueResumePending: async () => connection.sendRequest("session.queue.enqueueResumePending", { sessionId }),
|
|
6436
|
+
/**
|
|
6437
|
+
* Drains the native local-session work queue for in-process session orchestration.
|
|
6438
|
+
*/
|
|
6439
|
+
process: async () => connection.sendRequest("session.queue.process", { sessionId })
|
|
6440
|
+
},
|
|
6441
|
+
/** @experimental */
|
|
6442
|
+
schedule: {
|
|
6443
|
+
/**
|
|
6444
|
+
* Hydrates the native schedule registry from persisted session events.
|
|
6445
|
+
*/
|
|
6446
|
+
hydrate: async () => connection.sendRequest("session.schedule.hydrate", { sessionId }),
|
|
6447
|
+
/**
|
|
6448
|
+
* Reports whether the session has an active self-paced scheduled prompt.
|
|
6449
|
+
*
|
|
6450
|
+
* @returns Whether the session currently has an active self-paced schedule.
|
|
6451
|
+
*/
|
|
6452
|
+
hasSelfPaced: async () => connection.sendRequest("session.schedule.hasSelfPaced", { sessionId }),
|
|
6453
|
+
/**
|
|
6454
|
+
* Registers a relative-interval scheduled prompt.
|
|
6455
|
+
*
|
|
6456
|
+
* @param params Register a relative-interval scheduled prompt.
|
|
6457
|
+
*
|
|
6458
|
+
* @returns Result of registering or re-arming a scheduled prompt.
|
|
6459
|
+
*/
|
|
6460
|
+
add: async (params) => connection.sendRequest("session.schedule.add", { sessionId, ...params }),
|
|
6461
|
+
/**
|
|
6462
|
+
* Registers a recurring cron scheduled prompt.
|
|
6463
|
+
*
|
|
6464
|
+
* @param params Register a cron scheduled prompt.
|
|
6465
|
+
*
|
|
6466
|
+
* @returns Result of registering or re-arming a scheduled prompt.
|
|
6467
|
+
*/
|
|
6468
|
+
addCron: async (params) => connection.sendRequest("session.schedule.addCron", { sessionId, ...params }),
|
|
6469
|
+
/**
|
|
6470
|
+
* Registers an absolute-time scheduled prompt.
|
|
6471
|
+
*
|
|
6472
|
+
* @param params Register an absolute-time scheduled prompt.
|
|
6473
|
+
*
|
|
6474
|
+
* @returns Result of registering or re-arming a scheduled prompt.
|
|
6475
|
+
*/
|
|
6476
|
+
addAt: async (params) => connection.sendRequest("session.schedule.addAt", { sessionId, ...params }),
|
|
6477
|
+
/**
|
|
6478
|
+
* Registers a self-paced scheduled prompt.
|
|
6479
|
+
*
|
|
6480
|
+
* @param params Register a self-paced scheduled prompt.
|
|
6481
|
+
*
|
|
6482
|
+
* @returns Result of registering or re-arming a scheduled prompt.
|
|
6483
|
+
*/
|
|
6484
|
+
addSelfPaced: async (params) => connection.sendRequest("session.schedule.addSelfPaced", { sessionId, ...params }),
|
|
6485
|
+
/**
|
|
6486
|
+
* Re-arms an active self-paced scheduled prompt.
|
|
6487
|
+
*
|
|
6488
|
+
* @param params Re-arm a self-paced scheduled prompt.
|
|
6489
|
+
*
|
|
6490
|
+
* @returns Result of registering or re-arming a scheduled prompt.
|
|
6491
|
+
*/
|
|
6492
|
+
rearmSelfPaced: async (params) => connection.sendRequest("session.schedule.rearmSelfPaced", { sessionId, ...params })
|
|
6493
|
+
}
|
|
6494
|
+
};
|
|
6495
|
+
}
|
|
6023
6496
|
function registerClientSessionApiHandlers(connection, getHandlers) {
|
|
6024
6497
|
connection.onRequest("providerToken.getToken", async (params) => {
|
|
6025
6498
|
const handler = getHandlers(params.sessionId).providerToken;
|
|
@@ -6036,6 +6509,11 @@ function registerClientSessionApiHandlers(connection, getHandlers) {
|
|
|
6036
6509
|
if (!handler) throw new Error(`No factory handler registered for session: ${params.sessionId}`);
|
|
6037
6510
|
return handler.abort(params);
|
|
6038
6511
|
});
|
|
6512
|
+
connection.onRequest("tasks.cancel", async (params) => {
|
|
6513
|
+
const handler = getHandlers(params.sessionId).tasks;
|
|
6514
|
+
if (!handler) throw new Error(`No tasks handler registered for session: ${params.sessionId}`);
|
|
6515
|
+
return handler.cancel(params);
|
|
6516
|
+
});
|
|
6039
6517
|
connection.onRequest("sessionFs.readFile", async (params) => {
|
|
6040
6518
|
const handler = getHandlers(params.sessionId).sessionFs;
|
|
6041
6519
|
if (!handler) throw new Error(`No sessionFs handler registered for session: ${params.sessionId}`);
|
|
@@ -6145,17 +6623,17 @@ function registerClientGlobalApiHandlers(connection, handlers) {
|
|
|
6145
6623
|
});
|
|
6146
6624
|
}
|
|
6147
6625
|
|
|
6148
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
6626
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/sdkProtocolVersion.js
|
|
6149
6627
|
var SDK_PROTOCOL_VERSION = 3;
|
|
6150
6628
|
function getSdkProtocolVersion() {
|
|
6151
6629
|
return SDK_PROTOCOL_VERSION;
|
|
6152
6630
|
}
|
|
6153
6631
|
|
|
6154
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
6632
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/session.js
|
|
6155
6633
|
var import_node = __toESM(require_node(), 1);
|
|
6156
6634
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6157
6635
|
|
|
6158
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
6636
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/canvas.js
|
|
6159
6637
|
var CanvasError = class _CanvasError extends Error {
|
|
6160
6638
|
constructor(code, message) {
|
|
6161
6639
|
super(message);
|
|
@@ -6202,7 +6680,7 @@ function createCanvas(options) {
|
|
|
6202
6680
|
return new Canvas(options);
|
|
6203
6681
|
}
|
|
6204
6682
|
|
|
6205
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
6683
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/telemetry.js
|
|
6206
6684
|
async function getTraceContext(provider) {
|
|
6207
6685
|
if (!provider) return {};
|
|
6208
6686
|
try {
|
|
@@ -6212,7 +6690,7 @@ async function getTraceContext(provider) {
|
|
|
6212
6690
|
}
|
|
6213
6691
|
}
|
|
6214
6692
|
|
|
6215
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
6693
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/sessionFsProvider.js
|
|
6216
6694
|
var SessionFsSqliteTransactionFailure = class extends Error {
|
|
6217
6695
|
/** Failure classification reported to the runtime. */
|
|
6218
6696
|
errorClass;
|
|
@@ -6383,7 +6861,7 @@ function toSqliteTransactionError(err) {
|
|
|
6383
6861
|
};
|
|
6384
6862
|
}
|
|
6385
6863
|
|
|
6386
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
6864
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/copilotRequestHandler.js
|
|
6387
6865
|
var sharedTextDecoder = new TextDecoder("utf-8", { fatal: false });
|
|
6388
6866
|
var sharedTextEncoder = new TextEncoder();
|
|
6389
6867
|
var kBridge = /* @__PURE__ */ Symbol("copilotWebSocketResponseBridge");
|
|
@@ -6988,7 +7466,7 @@ var CopilotWebSocketResponseBridge = class {
|
|
|
6988
7466
|
}
|
|
6989
7467
|
};
|
|
6990
7468
|
|
|
6991
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
7469
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/types.js
|
|
6992
7470
|
var RuntimeConnection = {
|
|
6993
7471
|
/**
|
|
6994
7472
|
* Spawn a runtime child process and communicate over its stdin/stdout.
|
|
@@ -7124,10 +7602,11 @@ var DisableBypassPermissionsModes = {
|
|
|
7124
7602
|
AllowAutoOnly: "allow-auto-only"
|
|
7125
7603
|
};
|
|
7126
7604
|
|
|
7127
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
7605
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/factory.js
|
|
7128
7606
|
var FACTORY_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
7129
7607
|
"completed",
|
|
7130
7608
|
"halted",
|
|
7609
|
+
"paused",
|
|
7131
7610
|
"cancelled",
|
|
7132
7611
|
"error"
|
|
7133
7612
|
]);
|
|
@@ -7224,7 +7703,7 @@ function getFactoryDefinition(handle) {
|
|
|
7224
7703
|
return definition;
|
|
7225
7704
|
}
|
|
7226
7705
|
|
|
7227
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
7706
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/session.js
|
|
7228
7707
|
function isFactoryResumeErrorCode(value) {
|
|
7229
7708
|
return value === "not_found" || value === "non_resumable" || value === "already_active" || value === "factory_already_running" || value === "factory_limits_invalid" || value === "factory_session_disposed" || value === "factory_storage_unavailable" || value === "factory_storage_corrupt";
|
|
7230
7709
|
}
|
|
@@ -7238,10 +7717,14 @@ var factoryExecutionStore = new AsyncLocalStorage();
|
|
|
7238
7717
|
function throwIfFactoryExecutionIsActive() {
|
|
7239
7718
|
if (factoryExecutionStore.getStore()?.active) {
|
|
7240
7719
|
throw new Error(
|
|
7241
|
-
"factory.run and factory.
|
|
7720
|
+
"factory.run, factory.resume, and factory.pause are not allowed while a factory body is running on this call path."
|
|
7242
7721
|
);
|
|
7243
7722
|
}
|
|
7244
7723
|
}
|
|
7724
|
+
function runInFactoryHelperScope(helperScope, callback) {
|
|
7725
|
+
const current = factoryExecutionStore.getStore();
|
|
7726
|
+
return factoryExecutionStore.run({ active: current?.active ?? false, helperScope }, callback);
|
|
7727
|
+
}
|
|
7245
7728
|
function deserializeHookInput(raw) {
|
|
7246
7729
|
if (!raw || typeof raw !== "object" || typeof raw.timestamp !== "number") {
|
|
7247
7730
|
return raw;
|
|
@@ -7285,7 +7768,7 @@ async function runFactoryParallel(thunks) {
|
|
|
7285
7768
|
}
|
|
7286
7769
|
return Promise.all(
|
|
7287
7770
|
thunks.map(
|
|
7288
|
-
(thunk) => Promise.resolve().then(() => thunk
|
|
7771
|
+
(thunk) => Promise.resolve().then(() => runInFactoryHelperScope("parallel", thunk)).catch((error) => {
|
|
7289
7772
|
if (isFactoryFatalError(error)) {
|
|
7290
7773
|
throw error;
|
|
7291
7774
|
}
|
|
@@ -7304,7 +7787,10 @@ async function runFactoryPipeline(items, ...stages) {
|
|
|
7304
7787
|
let previous = item;
|
|
7305
7788
|
for (const stage of stages) {
|
|
7306
7789
|
try {
|
|
7307
|
-
previous = await
|
|
7790
|
+
previous = await runInFactoryHelperScope(
|
|
7791
|
+
"pipeline",
|
|
7792
|
+
() => stage(previous, item, index)
|
|
7793
|
+
);
|
|
7308
7794
|
} catch (error) {
|
|
7309
7795
|
if (isFactoryFatalError(error)) {
|
|
7310
7796
|
throw error;
|
|
@@ -7446,6 +7932,7 @@ var CopilotSession = class {
|
|
|
7446
7932
|
eventHandlers = /* @__PURE__ */ new Set();
|
|
7447
7933
|
typedEventHandlers = /* @__PURE__ */ new Map();
|
|
7448
7934
|
toolHandlers = /* @__PURE__ */ new Map();
|
|
7935
|
+
pendingExternalTools = /* @__PURE__ */ new Map();
|
|
7449
7936
|
canvases = /* @__PURE__ */ new Map();
|
|
7450
7937
|
bearerTokenProviders = /* @__PURE__ */ new Map();
|
|
7451
7938
|
commandHandlers = /* @__PURE__ */ new Map();
|
|
@@ -7460,11 +7947,13 @@ var CopilotSession = class {
|
|
|
7460
7947
|
hooks;
|
|
7461
7948
|
transformCallbacks;
|
|
7462
7949
|
_rpc = null;
|
|
7950
|
+
_internalRpc = null;
|
|
7463
7951
|
traceContextProvider;
|
|
7464
7952
|
managedSettingsEnabled;
|
|
7465
7953
|
_capabilities = {};
|
|
7466
7954
|
openCanvasInstances = [];
|
|
7467
7955
|
disconnected = false;
|
|
7956
|
+
disconnecting = false;
|
|
7468
7957
|
onDisconnected;
|
|
7469
7958
|
/** @internal Client session API handlers, populated by CopilotClient during create/resume. */
|
|
7470
7959
|
clientSessionApis = {};
|
|
@@ -7525,6 +8014,10 @@ var CopilotSession = class {
|
|
|
7525
8014
|
}),
|
|
7526
8015
|
getRunDetail: (runId) => this.rpc.factory.getRunDetail({ runId }),
|
|
7527
8016
|
getRunProgress: (runId, options = {}) => this.rpc.factory.getRunProgress({ runId, ...options }),
|
|
8017
|
+
pause: async (runId) => {
|
|
8018
|
+
throwIfFactoryExecutionIsActive();
|
|
8019
|
+
return this.rpc.factory.pause({ runId });
|
|
8020
|
+
},
|
|
7528
8021
|
cancel: async (runId) => this.rpc.factory.cancel({ runId })
|
|
7529
8022
|
};
|
|
7530
8023
|
/**
|
|
@@ -7623,6 +8116,13 @@ var CopilotSession = class {
|
|
|
7623
8116
|
}
|
|
7624
8117
|
return this._rpc;
|
|
7625
8118
|
}
|
|
8119
|
+
/** @internal */
|
|
8120
|
+
get internalRpc() {
|
|
8121
|
+
if (!this._internalRpc) {
|
|
8122
|
+
this._internalRpc = createInternalSessionRpc(this.connection, this.sessionId);
|
|
8123
|
+
}
|
|
8124
|
+
return this._internalRpc;
|
|
8125
|
+
}
|
|
7626
8126
|
/**
|
|
7627
8127
|
* Path to the session workspace directory when infinite sessions are enabled.
|
|
7628
8128
|
* Contains checkpoints/, plan.md, and files/ subdirectories.
|
|
@@ -7664,6 +8164,7 @@ var CopilotSession = class {
|
|
|
7664
8164
|
...await getTraceContext(this.traceContextProvider),
|
|
7665
8165
|
sessionId: this.sessionId,
|
|
7666
8166
|
prompt: options.prompt,
|
|
8167
|
+
source: options.source,
|
|
7667
8168
|
displayPrompt: options.displayPrompt,
|
|
7668
8169
|
attachments: options.attachments,
|
|
7669
8170
|
mode: options.mode,
|
|
@@ -7722,6 +8223,10 @@ var CopilotSession = class {
|
|
|
7722
8223
|
return;
|
|
7723
8224
|
}
|
|
7724
8225
|
this.disconnected = true;
|
|
8226
|
+
for (const controller of this.pendingExternalTools.values()) {
|
|
8227
|
+
controller.abort();
|
|
8228
|
+
}
|
|
8229
|
+
this.pendingExternalTools.clear();
|
|
7725
8230
|
this._runOnDisconnected();
|
|
7726
8231
|
this.eventHandlers.clear();
|
|
7727
8232
|
this.typedEventHandlers.clear();
|
|
@@ -7825,6 +8330,15 @@ var CopilotSession = class {
|
|
|
7825
8330
|
tracestate
|
|
7826
8331
|
);
|
|
7827
8332
|
}
|
|
8333
|
+
} else if (event.type === "external_tool.completed") {
|
|
8334
|
+
const { requestId } = event.data;
|
|
8335
|
+
if (requestId) {
|
|
8336
|
+
const controller = this.pendingExternalTools.get(requestId);
|
|
8337
|
+
if (controller) {
|
|
8338
|
+
this.pendingExternalTools.delete(requestId);
|
|
8339
|
+
controller.abort();
|
|
8340
|
+
}
|
|
8341
|
+
}
|
|
7828
8342
|
} else if (event.type === "permission.requested") {
|
|
7829
8343
|
const { requestId, permissionRequest, resolvedByHook } = event.data;
|
|
7830
8344
|
if (resolvedByHook) {
|
|
@@ -7905,16 +8419,35 @@ var CopilotSession = class {
|
|
|
7905
8419
|
* @internal
|
|
7906
8420
|
*/
|
|
7907
8421
|
async _executeToolAndRespond(requestId, toolName, toolCallId, args, handler, traceparent, tracestate) {
|
|
8422
|
+
const controller = new AbortController();
|
|
8423
|
+
if (this.disconnected || this.pendingExternalTools.has(requestId)) {
|
|
8424
|
+
return;
|
|
8425
|
+
}
|
|
8426
|
+
this.pendingExternalTools.set(requestId, controller);
|
|
7908
8427
|
try {
|
|
7909
8428
|
let availableTools;
|
|
7910
8429
|
if (toolName === TOOL_SEARCH_TOOL_NAME) {
|
|
8430
|
+
if (controller.signal.aborted) {
|
|
8431
|
+
return;
|
|
8432
|
+
}
|
|
8433
|
+
const aborted = new Promise((resolve3) => {
|
|
8434
|
+
controller.signal.addEventListener("abort", () => resolve3(void 0), {
|
|
8435
|
+
once: true
|
|
8436
|
+
});
|
|
8437
|
+
});
|
|
7911
8438
|
try {
|
|
7912
|
-
const metadata = await
|
|
7913
|
-
|
|
8439
|
+
const metadata = await Promise.race([
|
|
8440
|
+
this.rpc.tools.getCurrentMetadata(),
|
|
8441
|
+
aborted
|
|
8442
|
+
]);
|
|
8443
|
+
availableTools = metadata?.tools ?? void 0;
|
|
7914
8444
|
} catch {
|
|
7915
8445
|
availableTools = void 0;
|
|
7916
8446
|
}
|
|
7917
8447
|
}
|
|
8448
|
+
if (controller.signal.aborted) {
|
|
8449
|
+
return;
|
|
8450
|
+
}
|
|
7918
8451
|
const rawResult = await handler(args, {
|
|
7919
8452
|
sessionId: this.sessionId,
|
|
7920
8453
|
toolCallId,
|
|
@@ -7922,7 +8455,8 @@ var CopilotSession = class {
|
|
|
7922
8455
|
arguments: args,
|
|
7923
8456
|
availableTools,
|
|
7924
8457
|
traceparent,
|
|
7925
|
-
tracestate
|
|
8458
|
+
tracestate,
|
|
8459
|
+
signal: controller.signal
|
|
7926
8460
|
});
|
|
7927
8461
|
let result;
|
|
7928
8462
|
if (rawResult == null) {
|
|
@@ -7934,12 +8468,12 @@ var CopilotSession = class {
|
|
|
7934
8468
|
} else {
|
|
7935
8469
|
result = JSON.stringify(rawResult);
|
|
7936
8470
|
}
|
|
7937
|
-
if (this.
|
|
8471
|
+
if (!this._claimExternalTool(requestId, controller)) {
|
|
7938
8472
|
return;
|
|
7939
8473
|
}
|
|
7940
8474
|
await this.rpc.tools.handlePendingToolCall({ requestId, result });
|
|
7941
8475
|
} catch (error) {
|
|
7942
|
-
if (this.
|
|
8476
|
+
if (!this._claimExternalTool(requestId, controller)) {
|
|
7943
8477
|
return;
|
|
7944
8478
|
}
|
|
7945
8479
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -7950,8 +8484,20 @@ var CopilotSession = class {
|
|
|
7950
8484
|
throw rpcError;
|
|
7951
8485
|
}
|
|
7952
8486
|
}
|
|
8487
|
+
} finally {
|
|
8488
|
+
if (this.pendingExternalTools.get(requestId) === controller) {
|
|
8489
|
+
this.pendingExternalTools.delete(requestId);
|
|
8490
|
+
}
|
|
8491
|
+
controller.abort();
|
|
7953
8492
|
}
|
|
7954
8493
|
}
|
|
8494
|
+
_claimExternalTool(requestId, controller) {
|
|
8495
|
+
if (this.disconnected || this.pendingExternalTools.get(requestId) !== controller) {
|
|
8496
|
+
return false;
|
|
8497
|
+
}
|
|
8498
|
+
this.pendingExternalTools.delete(requestId);
|
|
8499
|
+
return true;
|
|
8500
|
+
}
|
|
7955
8501
|
/**
|
|
7956
8502
|
* Executes a permission handler and sends the result back via RPC.
|
|
7957
8503
|
* @internal
|
|
@@ -8259,6 +8805,36 @@ var CopilotSession = class {
|
|
|
8259
8805
|
);
|
|
8260
8806
|
return result2;
|
|
8261
8807
|
},
|
|
8808
|
+
pause: async (key) => {
|
|
8809
|
+
if (typeof key !== "string" || key.length === 0) {
|
|
8810
|
+
throw new Error("Factory pause checkpoint key must not be empty");
|
|
8811
|
+
}
|
|
8812
|
+
const helperScope = factoryExecutionStore.getStore()?.helperScope;
|
|
8813
|
+
if (helperScope !== void 0) {
|
|
8814
|
+
throw new Error(
|
|
8815
|
+
`Factory pause checkpoints are not allowed inside ${helperScope}() branches`
|
|
8816
|
+
);
|
|
8817
|
+
}
|
|
8818
|
+
await progress.flush();
|
|
8819
|
+
const response = await awaitFactoryOperation(
|
|
8820
|
+
() => self.internalRpc.factory.pauseAtCheckpoint({
|
|
8821
|
+
runId: params.runId,
|
|
8822
|
+
executionToken: params.executionToken,
|
|
8823
|
+
key
|
|
8824
|
+
}),
|
|
8825
|
+
controller.signal
|
|
8826
|
+
);
|
|
8827
|
+
switch (response.action) {
|
|
8828
|
+
case "continue":
|
|
8829
|
+
return;
|
|
8830
|
+
case "pause":
|
|
8831
|
+
await awaitFactoryOperation(
|
|
8832
|
+
() => new Promise(() => {
|
|
8833
|
+
}),
|
|
8834
|
+
controller.signal
|
|
8835
|
+
);
|
|
8836
|
+
}
|
|
8837
|
+
},
|
|
8262
8838
|
parallel: runFactoryParallel,
|
|
8263
8839
|
pipeline: runFactoryPipeline,
|
|
8264
8840
|
factory: async () => {
|
|
@@ -8294,11 +8870,9 @@ var CopilotSession = class {
|
|
|
8294
8870
|
},
|
|
8295
8871
|
async abort(params) {
|
|
8296
8872
|
const controllersForRun = self.factoryAbortControllers.get(params.runId);
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
controller.abort(reason);
|
|
8301
|
-
}
|
|
8873
|
+
const controller = controllersForRun?.get(params.executionToken);
|
|
8874
|
+
if (controller !== void 0) {
|
|
8875
|
+
controller.abort(new DOMException("Factory run was aborted", "AbortError"));
|
|
8302
8876
|
}
|
|
8303
8877
|
return {};
|
|
8304
8878
|
}
|
|
@@ -8704,13 +9278,27 @@ var CopilotSession = class {
|
|
|
8704
9278
|
* ```
|
|
8705
9279
|
*/
|
|
8706
9280
|
async disconnect() {
|
|
8707
|
-
if (this.disconnected) {
|
|
9281
|
+
if (this.disconnected || this.disconnecting) {
|
|
8708
9282
|
return;
|
|
8709
9283
|
}
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
9284
|
+
this.disconnecting = true;
|
|
9285
|
+
try {
|
|
9286
|
+
let response = { success: false };
|
|
9287
|
+
for (let attempt = 0; attempt < 2 && !response.success; attempt++) {
|
|
9288
|
+
response = await this.connection.sendRequest("session.detach", {
|
|
9289
|
+
sessionId: this.sessionId
|
|
9290
|
+
});
|
|
9291
|
+
}
|
|
9292
|
+
if (!response.success) {
|
|
9293
|
+
throw new Error(
|
|
9294
|
+
`Failed to disconnect session ${this.sessionId}: ${response.error || "Unknown error"}`
|
|
9295
|
+
);
|
|
9296
|
+
}
|
|
9297
|
+
this._markDisconnected();
|
|
9298
|
+
} catch (error) {
|
|
9299
|
+
this.disconnecting = false;
|
|
9300
|
+
throw error;
|
|
9301
|
+
}
|
|
8714
9302
|
}
|
|
8715
9303
|
/** Enables `await using session = ...` syntax for automatic cleanup. */
|
|
8716
9304
|
async [Symbol.asyncDispose]() {
|
|
@@ -8752,11 +9340,48 @@ var CopilotSession = class {
|
|
|
8752
9340
|
* ```typescript
|
|
8753
9341
|
* await session.setModel("gpt-5.4");
|
|
8754
9342
|
* await session.setModel("claude-sonnet-4.6", { reasoningEffort: "high" });
|
|
9343
|
+
*
|
|
9344
|
+
* // Select the Auto model and its routing preference in one call.
|
|
9345
|
+
* await session.setModel("auto", { autoTier: "intelligence" });
|
|
8755
9346
|
* ```
|
|
8756
9347
|
*/
|
|
8757
9348
|
async setModel(model, options) {
|
|
8758
9349
|
await this.rpc.model.switchTo({ modelId: model, ...options });
|
|
8759
9350
|
}
|
|
9351
|
+
/**
|
|
9352
|
+
* Change the Auto routing preference without changing the selected model.
|
|
9353
|
+
*
|
|
9354
|
+
* The runtime does not apply the preference immediately. It records the
|
|
9355
|
+
* request and commits it only when a later user turn using the `auto` model
|
|
9356
|
+
* successfully obtains a usable model from the provider. A `pending` status
|
|
9357
|
+
* therefore confirms that the request was accepted, not that it took effect.
|
|
9358
|
+
*
|
|
9359
|
+
* Watch for the outcome through the `session.model_change` event on success,
|
|
9360
|
+
* or the ephemeral `session.auto_tier_switch_failed` event on failure. You
|
|
9361
|
+
* can also read the current committed and in-flight state at any time with
|
|
9362
|
+
* `session.rpc.model.getCurrent()`.
|
|
9363
|
+
*
|
|
9364
|
+
* Only the most recent request survives: issuing a new request replaces any
|
|
9365
|
+
* earlier one that has not yet been claimed by a turn.
|
|
9366
|
+
*
|
|
9367
|
+
* @param autoTier - Routing preference to activate, or `null` to return to
|
|
9368
|
+
* the provider's default Auto routing
|
|
9369
|
+
* @returns The runtime's immediate acknowledgement and Auto preference snapshot
|
|
9370
|
+
*
|
|
9371
|
+
* @experimental Part of an experimental Auto routing surface and may change
|
|
9372
|
+
* or be removed in a future release.
|
|
9373
|
+
*
|
|
9374
|
+
* @example
|
|
9375
|
+
* ```typescript
|
|
9376
|
+
* const result = await session.setAutoTier("intelligence");
|
|
9377
|
+
* if (result.status === "pending") {
|
|
9378
|
+
* // Takes effect on a later turn that uses the `auto` model.
|
|
9379
|
+
* }
|
|
9380
|
+
* ```
|
|
9381
|
+
*/
|
|
9382
|
+
async setAutoTier(autoTier) {
|
|
9383
|
+
return await this.rpc.model.switchAutoTier({ autoTier });
|
|
9384
|
+
}
|
|
8760
9385
|
/**
|
|
8761
9386
|
* Log a message to the session timeline.
|
|
8762
9387
|
* The message appears in the session event stream and is visible to SDK consumers
|
|
@@ -8948,8 +9573,7 @@ function assertFactoryStepResult(value, key) {
|
|
|
8948
9573
|
});
|
|
8949
9574
|
}
|
|
8950
9575
|
|
|
8951
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
8952
|
-
import { createHash } from "node:crypto";
|
|
9576
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/runtimeArtifacts.js
|
|
8953
9577
|
import {
|
|
8954
9578
|
chmodSync,
|
|
8955
9579
|
copyFileSync,
|
|
@@ -8962,26 +9586,32 @@ import {
|
|
|
8962
9586
|
rmSync,
|
|
8963
9587
|
statSync
|
|
8964
9588
|
} from "node:fs";
|
|
9589
|
+
import { createHash } from "node:crypto";
|
|
9590
|
+
import { createRequire } from "node:module";
|
|
8965
9591
|
import { homedir } from "node:os";
|
|
8966
9592
|
import { dirname, join, relative, sep } from "node:path";
|
|
9593
|
+
|
|
9594
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/cliVersion.js
|
|
9595
|
+
var COPILOT_CLI_VERSION = "1.0.84-5";
|
|
9596
|
+
var COPILOT_CLI_USE_NPM_PACKAGE = false;
|
|
9597
|
+
|
|
9598
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/runtimeArtifacts.js
|
|
9599
|
+
var require2 = createRequire(typeof __filename === "string" ? __filename : import.meta.url);
|
|
8967
9600
|
var EXCLUDED_TOP_LEVEL = /* @__PURE__ */ new Set([
|
|
8968
9601
|
"app.js",
|
|
8969
9602
|
"assets",
|
|
8970
9603
|
"changelog.json",
|
|
8971
9604
|
"copilot",
|
|
8972
9605
|
"copilot.exe",
|
|
8973
|
-
"copilot-sdk",
|
|
8974
9606
|
"foundry-local-sdk",
|
|
8975
9607
|
"index.js",
|
|
8976
9608
|
"LICENSE.md",
|
|
8977
9609
|
"napi-oop-runtime",
|
|
8978
9610
|
"npm-loader.js",
|
|
8979
9611
|
"package.json",
|
|
8980
|
-
"preloads",
|
|
8981
9612
|
"pvrecorder",
|
|
8982
9613
|
"queries",
|
|
8983
9614
|
"README.md",
|
|
8984
|
-
"sdk",
|
|
8985
9615
|
"sea-loader.js",
|
|
8986
9616
|
"webview"
|
|
8987
9617
|
]);
|
|
@@ -9020,14 +9650,12 @@ function collectRuntimeAssets(sources) {
|
|
|
9020
9650
|
continue;
|
|
9021
9651
|
}
|
|
9022
9652
|
const parts = sourceRelative.split(sep);
|
|
9023
|
-
let relativePath = sourceRelative;
|
|
9024
9653
|
if (parts[0] === "prebuilds") {
|
|
9025
9654
|
if (parts[1] !== sources.platform || parts.length < 3) {
|
|
9026
9655
|
continue;
|
|
9027
9656
|
}
|
|
9028
|
-
relativePath = parts.slice(2).join(sep);
|
|
9029
9657
|
}
|
|
9030
|
-
assets.push({ source, relativePath });
|
|
9658
|
+
assets.push({ source, relativePath: sourceRelative });
|
|
9031
9659
|
}
|
|
9032
9660
|
};
|
|
9033
9661
|
visit(sources.packageRoot);
|
|
@@ -9055,15 +9683,20 @@ function defaultRuntimeCacheRoot(platform = process.platform, home = homedir(),
|
|
|
9055
9683
|
const cacheDirectory = platform === "win32" ? environment.LOCALAPPDATA ?? join(home, "AppData", "Local") : platform === "darwin" ? join(home, "Library", "Caches") : environment.XDG_CACHE_HOME ?? join(home, ".cache");
|
|
9056
9684
|
return join(cacheDirectory, "github-copilot-sdk", "runtime");
|
|
9057
9685
|
}
|
|
9058
|
-
function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot()) {
|
|
9686
|
+
function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot(), cacheKey = `${sources.platform}-${sourceFingerprint(collectRuntimeAssets(sources))}`) {
|
|
9059
9687
|
const assets = collectRuntimeAssets(sources);
|
|
9060
|
-
const wrapperName =
|
|
9061
|
-
const
|
|
9062
|
-
const
|
|
9688
|
+
const wrapperName = sources.platform.startsWith("win32") ? "copilot-runtime.exe" : "copilot-runtime";
|
|
9689
|
+
const prebuildDir = join("prebuilds", sources.platform);
|
|
9690
|
+
const wrapperRelative = join(prebuildDir, wrapperName);
|
|
9691
|
+
const runtimeNodeRelative = join(prebuildDir, "runtime.node");
|
|
9692
|
+
const sourceWrapper = assets.find((asset) => asset.relativePath === wrapperRelative)?.source;
|
|
9693
|
+
const sourceRuntimeNode = assets.find(
|
|
9694
|
+
(asset) => asset.relativePath === runtimeNodeRelative
|
|
9695
|
+
)?.source;
|
|
9063
9696
|
validateRuntimeBundle(sourceWrapper ?? "", sourceRuntimeNode ?? "");
|
|
9064
|
-
const installDir = join(cacheRoot,
|
|
9065
|
-
const installedWrapper = join(installDir,
|
|
9066
|
-
const installedRuntimeNode = join(installDir,
|
|
9697
|
+
const installDir = join(cacheRoot, cacheKey);
|
|
9698
|
+
const installedWrapper = join(installDir, wrapperRelative);
|
|
9699
|
+
const installedRuntimeNode = join(installDir, runtimeNodeRelative);
|
|
9067
9700
|
if (existsSync(installDir)) {
|
|
9068
9701
|
validateRuntimeBundle(installedWrapper, installedRuntimeNode);
|
|
9069
9702
|
makeExecutable(installedWrapper);
|
|
@@ -9077,7 +9710,7 @@ function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot()
|
|
|
9077
9710
|
mkdirSync(dirname(destination), { recursive: true });
|
|
9078
9711
|
copyFileSync(asset.source, destination);
|
|
9079
9712
|
}
|
|
9080
|
-
const stagedWrapper = join(stagingDir,
|
|
9713
|
+
const stagedWrapper = join(stagingDir, wrapperRelative);
|
|
9081
9714
|
makeExecutable(stagedWrapper);
|
|
9082
9715
|
renameSync(stagingDir, installDir);
|
|
9083
9716
|
} catch (error) {
|
|
@@ -9090,8 +9723,72 @@ function materializeRuntimeBundle(sources, cacheRoot = defaultRuntimeCacheRoot()
|
|
|
9090
9723
|
}
|
|
9091
9724
|
return installedWrapper;
|
|
9092
9725
|
}
|
|
9726
|
+
function isMusl() {
|
|
9727
|
+
if (process.platform !== "linux") {
|
|
9728
|
+
return false;
|
|
9729
|
+
}
|
|
9730
|
+
const report = process.report?.getReport();
|
|
9731
|
+
return report?.header?.glibcVersionRuntime === void 0;
|
|
9732
|
+
}
|
|
9733
|
+
function getRuntimePlatform(platform = process.platform, arch = process.arch, musl = isMusl()) {
|
|
9734
|
+
if (arch !== "x64" && arch !== "arm64") {
|
|
9735
|
+
throw new Error(`Unsupported Copilot CLI architecture: ${arch}.`);
|
|
9736
|
+
}
|
|
9737
|
+
if (platform === "linux") {
|
|
9738
|
+
return `${musl ? "linuxmusl" : "linux"}-${arch}`;
|
|
9739
|
+
}
|
|
9740
|
+
if (platform === "darwin" || platform === "win32") {
|
|
9741
|
+
return `${platform}-${arch}`;
|
|
9742
|
+
}
|
|
9743
|
+
throw new Error(`Unsupported Copilot CLI platform: ${platform}-${arch}.`);
|
|
9744
|
+
}
|
|
9745
|
+
function getRuntimePackageName(platform) {
|
|
9746
|
+
return `@github/copilot-sdk-${platform}`;
|
|
9747
|
+
}
|
|
9748
|
+
function resolvePackageRoot(packageName, searchPaths = require2.resolve.paths(packageName) ?? []) {
|
|
9749
|
+
return searchPaths.map((base) => join(base, ...packageName.split("/"))).find((candidate) => existsSync(join(candidate, "package.json")));
|
|
9750
|
+
}
|
|
9751
|
+
async function ensureRuntimeBundle(version, options = {}) {
|
|
9752
|
+
const platform = options.platform ?? getRuntimePlatform();
|
|
9753
|
+
if (COPILOT_CLI_USE_NPM_PACKAGE) {
|
|
9754
|
+
const packageName2 = `@github/copilot-${platform}`;
|
|
9755
|
+
const packageRoot2 = resolvePackageRoot(packageName2, options.packageSearchPaths);
|
|
9756
|
+
if (!packageRoot2) {
|
|
9757
|
+
throw new Error(`Could not resolve ${packageName2} for Copilot CLI ${version}.`);
|
|
9758
|
+
}
|
|
9759
|
+
validateFile(
|
|
9760
|
+
join(packageRoot2, "prebuilds", platform, "runtime.node"),
|
|
9761
|
+
"Copilot runtime.node"
|
|
9762
|
+
);
|
|
9763
|
+
return materializeRuntimeBundle(
|
|
9764
|
+
{ packageRoot: packageRoot2, platform },
|
|
9765
|
+
options.cacheRoot,
|
|
9766
|
+
`${version}-${platform}`
|
|
9767
|
+
);
|
|
9768
|
+
}
|
|
9769
|
+
const packageName = getRuntimePackageName(platform);
|
|
9770
|
+
const packageRoot = resolvePackageRoot(packageName, options.packageSearchPaths);
|
|
9771
|
+
if (!packageRoot) {
|
|
9772
|
+
throw new Error(
|
|
9773
|
+
`Could not resolve ${packageName}. Reinstall @github/copilot-sdk so its platform package is installed.`
|
|
9774
|
+
);
|
|
9775
|
+
}
|
|
9776
|
+
const wrapperName = platform.startsWith("win32") ? "copilot-runtime.exe" : "copilot-runtime";
|
|
9777
|
+
const prebuildDir = join(packageRoot, "prebuilds", platform);
|
|
9778
|
+
const wrapper = join(prebuildDir, wrapperName);
|
|
9779
|
+
try {
|
|
9780
|
+
validateRuntimeBundle(wrapper, join(prebuildDir, "runtime.node"));
|
|
9781
|
+
} catch (error) {
|
|
9782
|
+
throw new Error(
|
|
9783
|
+
`${packageName} is missing required Copilot CLI runtime files. Reinstall @github/copilot-sdk.`,
|
|
9784
|
+
{ cause: error }
|
|
9785
|
+
);
|
|
9786
|
+
}
|
|
9787
|
+
makeExecutable(wrapper);
|
|
9788
|
+
return wrapper;
|
|
9789
|
+
}
|
|
9093
9790
|
|
|
9094
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
9791
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/toolSet.js
|
|
9095
9792
|
var VALID_TOOL_NAME = /^[a-zA-Z0-9_-]+$/;
|
|
9096
9793
|
function validateName(kind, name) {
|
|
9097
9794
|
if (name === "*") {
|
|
@@ -9171,7 +9868,7 @@ var BuiltInTools = {
|
|
|
9171
9868
|
]
|
|
9172
9869
|
};
|
|
9173
9870
|
|
|
9174
|
-
// node_modules/.pnpm/@github+copilot-sdk@1.0.
|
|
9871
|
+
// node_modules/.pnpm/@github+copilot-sdk@1.0.14-preview.1/node_modules/@github/copilot-sdk/dist/client.js
|
|
9175
9872
|
var MIN_PROTOCOL_VERSION = 3;
|
|
9176
9873
|
var RUNTIME_SHUTDOWN_TIMEOUT_MS = 1e4;
|
|
9177
9874
|
function isZodSchema(value) {
|
|
@@ -9274,6 +9971,15 @@ function toWireCustomAgents(agents) {
|
|
|
9274
9971
|
return { ...rest, mcpServers: toWireMcpServers(mcpServers) };
|
|
9275
9972
|
});
|
|
9276
9973
|
}
|
|
9974
|
+
function clientInfoToWire(info) {
|
|
9975
|
+
if (info == null) return void 0;
|
|
9976
|
+
const wire = {};
|
|
9977
|
+
if (info.applicationName) wire.editorName = info.applicationName;
|
|
9978
|
+
if (info.applicationVersion) wire.editorVersion = info.applicationVersion;
|
|
9979
|
+
if (info.integrationName) wire.extensionName = info.integrationName;
|
|
9980
|
+
if (info.integrationVersion) wire.extensionVersion = info.integrationVersion;
|
|
9981
|
+
return Object.keys(wire).length > 0 ? wire : void 0;
|
|
9982
|
+
}
|
|
9277
9983
|
function toWireLargeOutput(config) {
|
|
9278
9984
|
if (!config) return void 0;
|
|
9279
9985
|
const { outputDirectory, ...rest } = config;
|
|
@@ -9331,53 +10037,8 @@ function getNodeExecPath() {
|
|
|
9331
10037
|
}
|
|
9332
10038
|
return process.execPath;
|
|
9333
10039
|
}
|
|
9334
|
-
function getCliPlatformPackageNames() {
|
|
9335
|
-
const arch = process.arch;
|
|
9336
|
-
const variants = process.platform === "linux" ? ["linux", "linuxmusl"] : [process.platform];
|
|
9337
|
-
return variants.map((variant) => `@github/copilot-${variant}-${arch}`);
|
|
9338
|
-
}
|
|
9339
|
-
function getBundledCliPackage() {
|
|
9340
|
-
const packageNames = getCliPlatformPackageNames();
|
|
9341
|
-
if (typeof import.meta.resolve === "function") {
|
|
9342
|
-
for (const packageName of packageNames) {
|
|
9343
|
-
try {
|
|
9344
|
-
const packageEntryUrl = import.meta.resolve(packageName);
|
|
9345
|
-
const packageEntryPath = fileURLToPath(packageEntryUrl);
|
|
9346
|
-
return {
|
|
9347
|
-
root: dirname2(packageEntryPath),
|
|
9348
|
-
platform: packageName.slice("@github/copilot-".length)
|
|
9349
|
-
};
|
|
9350
|
-
} catch {
|
|
9351
|
-
}
|
|
9352
|
-
}
|
|
9353
|
-
throw new Error(
|
|
9354
|
-
`Could not resolve a @github/copilot platform package (tried ${packageNames.join(", ")}). Ensure @github/copilot is installed, or pass cliPath/cliUrl to CopilotClient.`
|
|
9355
|
-
);
|
|
9356
|
-
}
|
|
9357
|
-
const req = createRequire(__filename);
|
|
9358
|
-
const searchPaths = req.resolve.paths("@github/copilot") ?? [];
|
|
9359
|
-
for (const base of searchPaths) {
|
|
9360
|
-
for (const packageName of packageNames) {
|
|
9361
|
-
const root = join2(base, ...packageName.split("/"));
|
|
9362
|
-
const candidate = join2(root, "index.js");
|
|
9363
|
-
if (existsSync3(candidate)) {
|
|
9364
|
-
return {
|
|
9365
|
-
root,
|
|
9366
|
-
platform: packageName.slice("@github/copilot-".length)
|
|
9367
|
-
};
|
|
9368
|
-
}
|
|
9369
|
-
}
|
|
9370
|
-
}
|
|
9371
|
-
throw new Error(
|
|
9372
|
-
`Could not find a @github/copilot platform package (tried ${packageNames.join(", ")}). Searched ${searchPaths.length} paths. Ensure @github/copilot is installed, or pass cliPath/cliUrl to CopilotClient.`
|
|
9373
|
-
);
|
|
9374
|
-
}
|
|
9375
10040
|
function getBundledRuntimePath() {
|
|
9376
|
-
|
|
9377
|
-
return materializeRuntimeBundle({
|
|
9378
|
-
packageRoot: bundled.root,
|
|
9379
|
-
platform: bundled.platform
|
|
9380
|
-
});
|
|
10041
|
+
return ensureRuntimeBundle(COPILOT_CLI_VERSION);
|
|
9381
10042
|
}
|
|
9382
10043
|
var TeardownResilientStreamMessageWriter = class extends import_node2.StreamMessageWriter {
|
|
9383
10044
|
suppressWriteErrors = false;
|
|
@@ -9397,10 +10058,13 @@ var CopilotClient = class _CopilotClient {
|
|
|
9397
10058
|
ffiHost = null;
|
|
9398
10059
|
connection = null;
|
|
9399
10060
|
messageWriter = null;
|
|
10061
|
+
connectionClosed = false;
|
|
9400
10062
|
socket = null;
|
|
9401
10063
|
runtimePort = null;
|
|
9402
10064
|
actualHost = "localhost";
|
|
9403
10065
|
state = "disconnected";
|
|
10066
|
+
/** Shared in-flight start; concurrent callers await it instead of spawning another CLI. */
|
|
10067
|
+
startPromise = null;
|
|
9404
10068
|
sessions = /* @__PURE__ */ new Map();
|
|
9405
10069
|
stderrBuffer = "";
|
|
9406
10070
|
// Captures CLI stderr for error messages
|
|
@@ -9596,8 +10260,6 @@ var CopilotClient = class _CopilotClient {
|
|
|
9596
10260
|
const explicitCliPath = conn.path ?? effectiveEnv.COPILOT_CLI_PATH;
|
|
9597
10261
|
if (explicitCliPath) {
|
|
9598
10262
|
this.resolvedCliPath = explicitCliPath;
|
|
9599
|
-
} else {
|
|
9600
|
-
this.resolvedCliPath = getBundledRuntimePath();
|
|
9601
10263
|
}
|
|
9602
10264
|
}
|
|
9603
10265
|
const connArgs = conn.kind === "stdio" || conn.kind === "tcp" ? conn.args ?? [] : [];
|
|
@@ -9612,7 +10274,8 @@ var CopilotClient = class _CopilotClient {
|
|
|
9612
10274
|
baseDirectory: options.baseDirectory,
|
|
9613
10275
|
sessionIdleTimeoutSeconds: options.sessionIdleTimeoutSeconds ?? 0,
|
|
9614
10276
|
enableRemoteSessions: options.enableRemoteSessions ?? false,
|
|
9615
|
-
mode: options.mode ?? "copilot-cli"
|
|
10277
|
+
mode: options.mode ?? "copilot-cli",
|
|
10278
|
+
clientInfo: options.clientInfo
|
|
9616
10279
|
};
|
|
9617
10280
|
if (this.options.mode === "empty") {
|
|
9618
10281
|
const hasPersistence = this.options.baseDirectory !== void 0 || this.sessionFsConfig !== null || // External runtimes manage their own persistence layer; the SDK
|
|
@@ -9628,17 +10291,29 @@ var CopilotClient = class _CopilotClient {
|
|
|
9628
10291
|
connectionExtraArgs = [];
|
|
9629
10292
|
/**
|
|
9630
10293
|
* Parse CLI URL into host and port
|
|
9631
|
-
* Supports formats: "host:port", "http://host:port", "https://host:port", or just "port"
|
|
10294
|
+
* Supports formats: "host:port", "[ipv6]:port", "http://host:port", "https://host:port", or just "port"
|
|
9632
10295
|
*/
|
|
9633
10296
|
parseCliUrl(url) {
|
|
9634
|
-
|
|
10297
|
+
const cleanUrl = url.replace(/^https?:\/\//, "");
|
|
9635
10298
|
if (/^\d+$/.test(cleanUrl)) {
|
|
9636
10299
|
return { host: "localhost", port: parseInt(cleanUrl, 10) };
|
|
9637
10300
|
}
|
|
10301
|
+
const ipv6Match = cleanUrl.match(/^\[([^\]]+)\]:(\d+)$/);
|
|
10302
|
+
if (ipv6Match) {
|
|
10303
|
+
const host2 = ipv6Match[1];
|
|
10304
|
+
if (!isIPv6(host2)) {
|
|
10305
|
+
throw new Error(`Invalid cliUrl format: ${url}`);
|
|
10306
|
+
}
|
|
10307
|
+
const port2 = parseInt(ipv6Match[2], 10);
|
|
10308
|
+
if (isNaN(port2) || port2 <= 0 || port2 > 65535) {
|
|
10309
|
+
throw new Error(`Invalid port in cliUrl: ${url}`);
|
|
10310
|
+
}
|
|
10311
|
+
return { host: host2, port: port2 };
|
|
10312
|
+
}
|
|
9638
10313
|
const parts = cleanUrl.split(":");
|
|
9639
10314
|
if (parts.length !== 2) {
|
|
9640
10315
|
throw new Error(
|
|
9641
|
-
`Invalid cliUrl format: ${url}. Expected "host:port", "http://host:port", or "port"`
|
|
10316
|
+
`Invalid cliUrl format: ${url}. Expected "host:port", "[ipv6]:port", "http://host:port", or "port"`
|
|
9642
10317
|
);
|
|
9643
10318
|
}
|
|
9644
10319
|
const host = parts[0] || "localhost";
|
|
@@ -9767,7 +10442,19 @@ var CopilotClient = class _CopilotClient {
|
|
|
9767
10442
|
if (this.state === "connected") {
|
|
9768
10443
|
return;
|
|
9769
10444
|
}
|
|
10445
|
+
if (this.startPromise) {
|
|
10446
|
+
return this.startPromise;
|
|
10447
|
+
}
|
|
10448
|
+
this.startPromise = this.doStart();
|
|
10449
|
+
try {
|
|
10450
|
+
await this.startPromise;
|
|
10451
|
+
} finally {
|
|
10452
|
+
this.startPromise = null;
|
|
10453
|
+
}
|
|
10454
|
+
}
|
|
10455
|
+
async doStart() {
|
|
9770
10456
|
this.forceStopping = false;
|
|
10457
|
+
this.connectionClosed = false;
|
|
9771
10458
|
this.processTransportError = null;
|
|
9772
10459
|
this.state = "connecting";
|
|
9773
10460
|
try {
|
|
@@ -9866,7 +10553,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
9866
10553
|
}
|
|
9867
10554
|
this.sessions.clear();
|
|
9868
10555
|
this.githubTokenProviders.clear();
|
|
9869
|
-
if (this.connection && (this.cliProcess || this.ffiHost) && !this.isExternalServer) {
|
|
10556
|
+
if (this.connection && !this.connectionClosed && (this.cliProcess || this.ffiHost) && !this.isExternalServer) {
|
|
9870
10557
|
const runtimeShutdownStart = Date.now();
|
|
9871
10558
|
const shutdownPromise = this.rpc.runtime.shutdown();
|
|
9872
10559
|
void shutdownPromise.catch(() => void 0);
|
|
@@ -9955,7 +10642,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
9955
10642
|
const host = this.ffiHost;
|
|
9956
10643
|
this.ffiHost = null;
|
|
9957
10644
|
try {
|
|
9958
|
-
host.dispose();
|
|
10645
|
+
await host.dispose();
|
|
9959
10646
|
} catch (error) {
|
|
9960
10647
|
errors.push(
|
|
9961
10648
|
new Error(
|
|
@@ -10050,11 +10737,12 @@ var CopilotClient = class _CopilotClient {
|
|
|
10050
10737
|
this.cliProcess = null;
|
|
10051
10738
|
}
|
|
10052
10739
|
if (this.ffiHost) {
|
|
10740
|
+
const host = this.ffiHost;
|
|
10741
|
+
this.ffiHost = null;
|
|
10053
10742
|
try {
|
|
10054
|
-
|
|
10743
|
+
await host.dispose();
|
|
10055
10744
|
} catch {
|
|
10056
10745
|
}
|
|
10057
|
-
this.ffiHost = null;
|
|
10058
10746
|
}
|
|
10059
10747
|
if (this.cliStartTimeout) {
|
|
10060
10748
|
clearTimeout(this.cliStartTimeout);
|
|
@@ -10371,6 +11059,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
10371
11059
|
...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
|
|
10372
11060
|
mcpServers: toWireMcpServers(config.mcpServers),
|
|
10373
11061
|
mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
|
|
11062
|
+
authClientIdMetadataUrl: config.authClientIdMetadataUrl,
|
|
10374
11063
|
envValueMode: "direct",
|
|
10375
11064
|
customAgents: toWireCustomAgents(config.customAgents),
|
|
10376
11065
|
customAgentsLocalOnly: config.customAgentsLocalOnly,
|
|
@@ -10397,6 +11086,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
10397
11086
|
gitHubTokenProviderRegistrationId,
|
|
10398
11087
|
remoteSession: config.remoteSession,
|
|
10399
11088
|
cloud: config.cloud,
|
|
11089
|
+
featureFlags: config.featureFlags,
|
|
10400
11090
|
expAssignments: config.expAssignments,
|
|
10401
11091
|
enableManagedSettings: config.enableManagedSettings,
|
|
10402
11092
|
managedSettings: config.managedSettings
|
|
@@ -10430,6 +11120,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
10430
11120
|
await this.updateSessionOptionsForMode(session, config);
|
|
10431
11121
|
this.commitGitHubTokenProvider(returnedSessionId, gitHubTokenProviderRegistrationId);
|
|
10432
11122
|
} catch (e) {
|
|
11123
|
+
session?._markDisconnected();
|
|
10433
11124
|
if (registeredId !== void 0) {
|
|
10434
11125
|
this.sessions.delete(registeredId);
|
|
10435
11126
|
}
|
|
@@ -10614,6 +11305,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
10614
11305
|
...this.onGitHubTelemetry != null ? { enableGitHubTelemetryForwarding: true } : {},
|
|
10615
11306
|
mcpServers: toWireMcpServers(config.mcpServers),
|
|
10616
11307
|
mcpOAuthTokenStorage: config.mcpOAuthTokenStorage,
|
|
11308
|
+
authClientIdMetadataUrl: config.authClientIdMetadataUrl,
|
|
10617
11309
|
envValueMode: "direct",
|
|
10618
11310
|
customAgents: toWireCustomAgents(config.customAgents),
|
|
10619
11311
|
customAgentsLocalOnly: config.customAgentsLocalOnly,
|
|
@@ -10632,6 +11324,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
10632
11324
|
gitHubTokenProviderRegistrationId,
|
|
10633
11325
|
remoteSession: config.remoteSession,
|
|
10634
11326
|
openCanvases: config.openCanvases,
|
|
11327
|
+
featureFlags: config.featureFlags,
|
|
10635
11328
|
expAssignments: config.expAssignments,
|
|
10636
11329
|
enableManagedSettings: config.enableManagedSettings,
|
|
10637
11330
|
managedSettings: config.managedSettings,
|
|
@@ -10661,6 +11354,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
10661
11354
|
await this.updateSessionOptionsForMode(session, config);
|
|
10662
11355
|
this.commitGitHubTokenProvider(sessionId, gitHubTokenProviderRegistrationId);
|
|
10663
11356
|
} catch (e) {
|
|
11357
|
+
session._markDisconnected();
|
|
10664
11358
|
this.sessions.delete(sessionId);
|
|
10665
11359
|
if (gitHubTokenProviderRegistrationId !== void 0) {
|
|
10666
11360
|
this.githubTokenProviders.delete(gitHubTokenProviderRegistrationId);
|
|
@@ -10776,10 +11470,17 @@ var CopilotClient = class _CopilotClient {
|
|
|
10776
11470
|
const raceAgainstExit = (p) => this.processExitPromise ? Promise.race([p, this.processExitPromise]) : p;
|
|
10777
11471
|
let serverVersion;
|
|
10778
11472
|
try {
|
|
10779
|
-
const connectParams = {
|
|
11473
|
+
const connectParams = {
|
|
11474
|
+
token: this.effectiveConnectionToken,
|
|
11475
|
+
supportedTaskKinds: ["agent", "client", "shell"]
|
|
11476
|
+
};
|
|
10780
11477
|
if (this.onGitHubTelemetry != null) {
|
|
10781
11478
|
connectParams.enableGitHubTelemetryForwarding = true;
|
|
10782
11479
|
}
|
|
11480
|
+
const clientInfo = clientInfoToWire(this.options.clientInfo);
|
|
11481
|
+
if (clientInfo != null) {
|
|
11482
|
+
connectParams.clientInfo = clientInfo;
|
|
11483
|
+
}
|
|
10783
11484
|
const result = await raceAgainstExit(this.internalRpc.connect(connectParams));
|
|
10784
11485
|
serverVersion = result.protocolVersion;
|
|
10785
11486
|
} catch (err) {
|
|
@@ -11040,6 +11741,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
11040
11741
|
* Start the CLI server process
|
|
11041
11742
|
*/
|
|
11042
11743
|
async startCLIServer() {
|
|
11744
|
+
this.resolvedCliPath ??= await getBundledRuntimePath();
|
|
11043
11745
|
return new Promise((resolve22, reject) => {
|
|
11044
11746
|
this.stderrBuffer = "";
|
|
11045
11747
|
const args = [...this.connectionExtraArgs, "--headless", "--no-auto-update"];
|
|
@@ -11077,7 +11779,7 @@ var CopilotClient = class _CopilotClient {
|
|
|
11077
11779
|
}
|
|
11078
11780
|
if (!existsSync3(this.resolvedCliPath)) {
|
|
11079
11781
|
throw new Error(
|
|
11080
|
-
`Copilot CLI not found at ${this.resolvedCliPath}.
|
|
11782
|
+
`Copilot CLI not found at ${this.resolvedCliPath}. Set COPILOT_CLI_PATH to use a custom installation.`
|
|
11081
11783
|
);
|
|
11082
11784
|
}
|
|
11083
11785
|
const stdioConfig = this.connectionConfig.kind === "stdio" ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"];
|
|
@@ -11204,12 +11906,19 @@ stderr: ${stderrOutput}`
|
|
|
11204
11906
|
/** Starts the in-process FFI runtime with SDK-managed typed options. */
|
|
11205
11907
|
async startInProcessFfi() {
|
|
11206
11908
|
const explicitEntrypoint = this.resolvedEnv.COPILOT_CLI_PATH;
|
|
11207
|
-
|
|
11208
|
-
|
|
11209
|
-
|
|
11210
|
-
|
|
11211
|
-
|
|
11212
|
-
|
|
11909
|
+
let runtimeLibrary;
|
|
11910
|
+
if (explicitEntrypoint) {
|
|
11911
|
+
const entrypointDirectory = dirname2(resolve2(explicitEntrypoint));
|
|
11912
|
+
const adjacentRuntime = join2(entrypointDirectory, "runtime.node");
|
|
11913
|
+
runtimeLibrary = existsSync3(adjacentRuntime) ? adjacentRuntime : join2(
|
|
11914
|
+
entrypointDirectory,
|
|
11915
|
+
"prebuilds",
|
|
11916
|
+
_CopilotClient.getNapiPrebuildsFolder(explicitEntrypoint),
|
|
11917
|
+
"runtime.node"
|
|
11918
|
+
);
|
|
11919
|
+
} else {
|
|
11920
|
+
runtimeLibrary = join2(dirname2(await getBundledRuntimePath()), "runtime.node");
|
|
11921
|
+
}
|
|
11213
11922
|
const { FfiRuntimeHost: FfiRuntimeHost2 } = await Promise.resolve().then(() => (init_ffiRuntimeHost(), ffiRuntimeHost_exports));
|
|
11214
11923
|
const environment = {};
|
|
11215
11924
|
if (this.options.gitHubToken) {
|
|
@@ -11395,12 +12104,24 @@ stderr: ${stderrOutput}` : ""}`
|
|
|
11395
12104
|
return await this.handleHooksInvoke(params);
|
|
11396
12105
|
}
|
|
11397
12106
|
);
|
|
11398
|
-
this.connection
|
|
12107
|
+
const connection = this.connection;
|
|
12108
|
+
const markDisconnected = () => {
|
|
12109
|
+
if (this.connection !== connection) {
|
|
12110
|
+
return;
|
|
12111
|
+
}
|
|
12112
|
+
this.connectionClosed = true;
|
|
11399
12113
|
this.state = "disconnected";
|
|
12114
|
+
for (const session of this.sessions.values()) {
|
|
12115
|
+
session._markDisconnected();
|
|
12116
|
+
}
|
|
12117
|
+
this.sessions.clear();
|
|
11400
12118
|
this.githubTokenProviders.clear();
|
|
11401
|
-
}
|
|
11402
|
-
this.connection.
|
|
11403
|
-
|
|
12119
|
+
};
|
|
12120
|
+
this.connection.onClose(markDisconnected);
|
|
12121
|
+
this.connection.onError(() => {
|
|
12122
|
+
if (this.connection === connection) {
|
|
12123
|
+
this.state = "disconnected";
|
|
12124
|
+
}
|
|
11404
12125
|
});
|
|
11405
12126
|
}
|
|
11406
12127
|
handleSessionEventNotification(notification) {
|