@github/copilot-sdk 1.0.15-preview.2 → 1.0.15-preview.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -25
- package/dist/cjs/cliVersion.js +1 -1
- package/dist/cjs/client.js +21 -6
- package/dist/cjs/extension.js +1 -12
- package/dist/cjs/generated/rpc.js +307 -177
- package/dist/cjs/index.js +0 -7
- package/dist/cjs/installationConfirmation.js +98 -0
- package/dist/cjs/session.js +15 -524
- package/dist/cliVersion.d.ts +1 -1
- package/dist/cliVersion.js +1 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +23 -6
- package/dist/extension.d.ts +10 -24
- package/dist/extension.js +1 -13
- package/dist/generated/rpc.d.ts +4455 -2788
- package/dist/generated/rpc.js +307 -177
- package/dist/generated/session-events.d.ts +211 -120
- package/dist/index.d.ts +2 -4
- package/dist/index.js +0 -4
- package/dist/installationConfirmation.d.ts +19 -0
- package/dist/installationConfirmation.js +77 -0
- package/dist/session.d.ts +3 -25
- package/dist/session.js +15 -529
- package/dist/types.d.ts +31 -66
- package/dist/workflow.d.ts +5 -2
- package/docs/extensions.md +0 -1
- package/docs/workflows.md +2 -4
- package/package.json +10 -10
- package/dist/cjs/factory.js +0 -134
- package/dist/factory.d.ts +0 -327
- package/dist/factory.js +0 -106
- package/docs/factories.md +0 -296
- package/docs/factory-patterns.md +0 -194
package/dist/types.d.ts
CHANGED
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
import type { Canvas } from "./canvas.js";
|
|
5
5
|
import type { SessionFsProvider } from "./sessionFsProvider.js";
|
|
6
6
|
import type { CopilotRequestHandler } from "./copilotRequestHandler.js";
|
|
7
|
+
import type { InstallationConfirmationHandler } from "./installationConfirmation.js";
|
|
8
|
+
export type { InstallationConfirmationHandler } from "./installationConfirmation.js";
|
|
7
9
|
import type { AttachmentExtensionContext as GeneratedExtensionContextAttachment, AutoTier, PermissionRequest as GeneratedPermissionRequest, PermissionRequestedData as GeneratedPermissionRequestedData, PermissionRequestedEvent as GeneratedPermissionRequestedEvent, ReasoningSummary, SessionLimitsConfig, SessionEvent as GeneratedSessionEvent } from "./generated/session-events.js";
|
|
8
10
|
import type { CopilotSession } from "./session.js";
|
|
9
|
-
import type {
|
|
10
|
-
import type { ExtensionLaunchProviderHandler as GeneratedExtensionLaunchProvider, GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, ModelBillingTokenPrices, OpenCanvasInstance, RemoteSessionMode, CurrentToolMetadata } from "./generated/rpc.js";
|
|
11
|
+
import type { JsonValue } from "./workflow.js";
|
|
12
|
+
import type { ExtensionLaunchProviderHandler as GeneratedExtensionLaunchProvider, GitHubTokenAcquireRequest, GitHubTokenAcquireResult, GitHubTelemetryNotification, ModelBillingTokenPrices, DiagnosticsConfiguration, OpenCanvasInstance, RemoteSessionMode, CurrentToolMetadata } from "./generated/rpc.js";
|
|
11
13
|
import type { ToolSet } from "./toolSet.js";
|
|
12
14
|
export type { RemoteSessionMode } from "./generated/rpc.js";
|
|
13
15
|
export type { CurrentToolMetadata } from "./generated/rpc.js";
|
|
14
|
-
export type { ExtensionLaunchProfile, ExtensionLaunchProviderResolveRequest, ExtensionLaunchProviderResolveResult, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, } from "./generated/rpc.js";
|
|
16
|
+
export type { ConnectorAccountRequest, ConnectorAvailability, ConnectorCapabilities, ConnectorCatalogEntry, ConnectorCatalogResult, ConnectorCatalogStatus, ConnectorConnectRequest, ConnectorConnectResult, ConnectorContinueRequest, ConnectorDisconnectResult, ConnectorMcpStatus, ConnectorReconcileRequest, ConnectorRuntimeStatus, ConnectorStatus, ExtensionLaunchProfile, ExtensionLaunchProviderResolveRequest, ExtensionLaunchProviderResolveResult, GitHubTokenAcquireReason, GitHubTokenAcquireResult, GitHubTelemetryNotification, GitHubTelemetryEvent, GitHubTelemetryClientInfo, InstallationConfirmationRequest, InstallationConfirmationResponse, InstallationDecision, InstallationReview, McpInstallationReview, } from "./generated/rpc.js";
|
|
15
17
|
/**
|
|
16
18
|
* Arguments passed to a session's {@link GitHubTokenProvider}.
|
|
17
19
|
*
|
|
@@ -290,6 +292,12 @@ export interface CopilotClientOptions {
|
|
|
290
292
|
* @experimental
|
|
291
293
|
*/
|
|
292
294
|
extensionLaunchProvider?: ExtensionLaunchProvider;
|
|
295
|
+
/**
|
|
296
|
+
* Connection-global human review for experimental installation operations.
|
|
297
|
+
* Does not register or enable installation capabilities on the runtime.
|
|
298
|
+
* @experimental
|
|
299
|
+
*/
|
|
300
|
+
installationConfirmationHandler?: InstallationConfirmationHandler;
|
|
293
301
|
/**
|
|
294
302
|
* Log level for the Copilot runtime. When omitted, the runtime uses its
|
|
295
303
|
* own default (currently `"info"`).
|
|
@@ -1622,6 +1630,8 @@ export interface McpAuthStaticClientConfig {
|
|
|
1622
1630
|
grantType?: "client_credentials";
|
|
1623
1631
|
/** Whether this is a public OAuth client. */
|
|
1624
1632
|
publicClient?: boolean;
|
|
1633
|
+
/** Configured OAuth scope string used when the server challenge omits scope. */
|
|
1634
|
+
scope?: string;
|
|
1625
1635
|
}
|
|
1626
1636
|
/** MCP OAuth request that the SDK host can satisfy with a host-acquired token. */
|
|
1627
1637
|
export interface McpAuthRequest {
|
|
@@ -1690,69 +1700,6 @@ export interface CanvasProviderIdentity {
|
|
|
1690
1700
|
/** Optional display name surfaced as the canvas extension name. */
|
|
1691
1701
|
name?: string;
|
|
1692
1702
|
}
|
|
1693
|
-
/**
|
|
1694
|
-
* Static resource ceilings declared by a factory before it runs.
|
|
1695
|
-
*
|
|
1696
|
-
* @experimental Part of the experimental Agent Factories surface and may
|
|
1697
|
-
* change or be removed in future SDK or CLI releases.
|
|
1698
|
-
*/
|
|
1699
|
-
export interface FactoryLimits {
|
|
1700
|
-
/** Maximum number of factory subagents that may run concurrently. Must be positive when present. */
|
|
1701
|
-
maxConcurrentSubagents?: number;
|
|
1702
|
-
/** Maximum total number of factory subagents that may be spawned. Must be positive when present. */
|
|
1703
|
-
maxTotalSubagents?: number;
|
|
1704
|
-
/** Maximum AI credits consumed by factory subagents and descendants. This post-paid ceiling is soft. */
|
|
1705
|
-
maxAiCredits?: number;
|
|
1706
|
-
/**
|
|
1707
|
-
* Maximum accumulated active-execution time, in seconds. Active execution includes the entire extension body,
|
|
1708
|
-
* subprocess waits, queued-agent waits, and sleeps. The limit is armed from the remaining headroom when a run
|
|
1709
|
-
* resumes; time between attempts is not counted. Must be finite and positive when present.
|
|
1710
|
-
*/
|
|
1711
|
-
timeoutSeconds?: number;
|
|
1712
|
-
}
|
|
1713
|
-
/**
|
|
1714
|
-
* Registration metadata for an extension-authored factory.
|
|
1715
|
-
*
|
|
1716
|
-
* @experimental Part of the experimental Agent Factories surface and may
|
|
1717
|
-
* change or be removed in future SDK or CLI releases.
|
|
1718
|
-
*/
|
|
1719
|
-
export interface FactoryMeta {
|
|
1720
|
-
/** Stable factory name used for invocation. */
|
|
1721
|
-
name: string;
|
|
1722
|
-
/** Human-readable factory description. */
|
|
1723
|
-
description: string;
|
|
1724
|
-
/** Display metadata for the progress phases the factory may report. */
|
|
1725
|
-
phases: Array<{
|
|
1726
|
-
title: string;
|
|
1727
|
-
detail?: string;
|
|
1728
|
-
}>;
|
|
1729
|
-
/**
|
|
1730
|
-
* Optional declared shape of the arguments this factory expects as `ctx.args`.
|
|
1731
|
-
*
|
|
1732
|
-
* Declaring one is strongly recommended for any factory that reads `ctx.args`.
|
|
1733
|
-
* When the model invokes the factory through the `run_factory` tool, the CLI
|
|
1734
|
-
* validates `args` against this declaration **before** the run starts, so a
|
|
1735
|
-
* malformed call is rejected with a correction hint and retried without ever
|
|
1736
|
-
* creating a run row, prompting the user for permission, or spending credits. A
|
|
1737
|
-
* factory that declares nothing is never validated: a malformed call starts,
|
|
1738
|
-
* takes an approval, spends credits, and then fails inside the factory body.
|
|
1739
|
-
* `factories_manage` with `operation: "inspect"` reports the declared shape so an
|
|
1740
|
-
* agent can read it before invoking.
|
|
1741
|
-
*
|
|
1742
|
-
* This covers the model's `run_factory` path only. `session.factory.run(...)` is
|
|
1743
|
-
* not validated against the declaration, so a factory should still check
|
|
1744
|
-
* `ctx.args` rather than assume the declared shape held.
|
|
1745
|
-
*
|
|
1746
|
-
* Enforcement covers structure — types, required properties, and enum/const
|
|
1747
|
-
* values. Finer constraints such as `minLength`, `pattern`, and
|
|
1748
|
-
* `additionalProperties` are recorded in the declaration but not enforced. See
|
|
1749
|
-
* {@link FactoryJsonSchema} for the accepted subset. A declaration outside that
|
|
1750
|
-
* subset is rejected at registration.
|
|
1751
|
-
*/
|
|
1752
|
-
argsSchema?: FactoryJsonSchema;
|
|
1753
|
-
/** Optional resource ceilings presented to the user before execution. */
|
|
1754
|
-
limits?: FactoryLimits;
|
|
1755
|
-
}
|
|
1756
1703
|
/**
|
|
1757
1704
|
* Provider-scoped options for the Copilot API (CAPI).
|
|
1758
1705
|
*
|
|
@@ -1922,6 +1869,16 @@ export interface SessionConfigBase {
|
|
|
1922
1869
|
* the session to the long-context tier; omit or use "default" otherwise.
|
|
1923
1870
|
*/
|
|
1924
1871
|
contextTier?: ContextTier;
|
|
1872
|
+
/**
|
|
1873
|
+
* Enables session-scoped MCP diagnostic capture at the requested level.
|
|
1874
|
+
*
|
|
1875
|
+
* Diagnostics are off by default. At `"debug"` and `"trace"` levels, entries
|
|
1876
|
+
* can contain MCP payloads, tool arguments, paths, and server stderr. Do not
|
|
1877
|
+
* upload entries as telemetry or export them without deliberate host action.
|
|
1878
|
+
* Omit this option when resuming a resident session to preserve its current
|
|
1879
|
+
* diagnostic level.
|
|
1880
|
+
*/
|
|
1881
|
+
diagnostics?: DiagnosticsConfiguration;
|
|
1925
1882
|
/** Per-property overrides for model capabilities, deep-merged over runtime defaults. */
|
|
1926
1883
|
modelCapabilities?: ModelCapabilitiesOverride;
|
|
1927
1884
|
/**
|
|
@@ -2465,6 +2422,14 @@ export interface SessionConfig extends SessionConfigBase {
|
|
|
2465
2422
|
* Optional custom session ID. If not provided, the server generates one.
|
|
2466
2423
|
*/
|
|
2467
2424
|
sessionId?: string;
|
|
2425
|
+
/**
|
|
2426
|
+
* Invalidates the process-wide custom-instruction discovery cache before
|
|
2427
|
+
* creating this session. Use when instruction files changed in the same runtime.
|
|
2428
|
+
* Other sessions in this runtime may observe updated instructions on later turns
|
|
2429
|
+
* or discovery. This does not watch files or enable disabled instruction loading.
|
|
2430
|
+
* @default false
|
|
2431
|
+
*/
|
|
2432
|
+
refreshCustomInstructions?: boolean;
|
|
2468
2433
|
/**
|
|
2469
2434
|
* Creates a remote session in the cloud instead of a local session.
|
|
2470
2435
|
* The optional repository is associated with the cloud session.
|
package/dist/workflow.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { WorkflowGetRunProgressRequest, WorkflowListRunsRequest, WorkflowListRunsResult, WorkflowProgressPage, WorkflowRunDetail, WorkflowRunResult, WorkflowRunStatus, WorkflowRunSummary } from "./generated/rpc.js";
|
|
2
2
|
import type { ContextTier } from "./generated/session-events.js";
|
|
3
3
|
import type { CopilotSession } from "./session.js";
|
|
4
|
-
import type { JsonValue } from "./factory.js";
|
|
5
4
|
export type { WorkflowRunResult };
|
|
5
|
+
/** A value that can be represented losslessly on the SDK JSON wire. */
|
|
6
|
+
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
7
|
+
[key: string]: JsonValue;
|
|
8
|
+
};
|
|
6
9
|
export type { WorkflowAgentSummary, WorkflowPhaseStatus, WorkflowPhaseObservation, WorkflowProgressLine, WorkflowProgressPage, WorkflowRunDetail, WorkflowRunStatus, WorkflowRunSummary, } from "./generated/rpc.js";
|
|
7
10
|
/**
|
|
8
11
|
* Options for paging durable workflow runs.
|
|
@@ -311,7 +314,7 @@ export interface SessionWorkflowApi {
|
|
|
311
314
|
* snapshot: resuming the same durable run can later change the envelope
|
|
312
315
|
* returned by {@link SessionWorkflowApi.getRun}.
|
|
313
316
|
*
|
|
314
|
-
* This watches the runtime's `
|
|
317
|
+
* This watches the runtime's `workflow.run_updated` event and
|
|
315
318
|
* periodically re-reads the durable envelope so a missed event cannot
|
|
316
319
|
* leave the wait hanging. Pass a `signal` to stop waiting; aborting rejects
|
|
317
320
|
* and has no effect on the run itself, which keeps executing. Use
|
package/docs/extensions.md
CHANGED
|
@@ -78,5 +78,4 @@ An approved extension can pass a granted value to anything it starts, so ask onl
|
|
|
78
78
|
|
|
79
79
|
- `examples.md` — Practical code examples for tools, hooks, events, and complete extensions
|
|
80
80
|
- `workflows.md` — Authoring, running, resuming, and observing Dynamic Workflows
|
|
81
|
-
- `factories.md`: Authoring, running, resuming, and observing Agent Factories
|
|
82
81
|
- `agent-author.md` — Step-by-step workflow for agents authoring extensions programmatically
|
package/docs/workflows.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Dynamic Workflows are extension-authored, session-scoped workflows that coordinate subagents and durable steps. The API is experimental.
|
|
4
4
|
|
|
5
|
-
Use Dynamic Workflows for new extension-authored orchestration. Existing Agent Factory extensions remain supported during the transition, but one `joinSession` call must register either `workflows` or `factories`, never both.
|
|
6
|
-
|
|
7
5
|
## Define and register a workflow
|
|
8
6
|
|
|
9
7
|
Use `defineWorkflow` and pass the returned handle to `joinSession`:
|
|
@@ -242,7 +240,7 @@ if (settled.status === "completed") {
|
|
|
242
240
|
}
|
|
243
241
|
```
|
|
244
242
|
|
|
245
|
-
It watches
|
|
243
|
+
It watches `workflow.run_updated` and re-reads the durable envelope on each invalidation, collapsing a burst of events into a single in-flight read. A low-frequency periodic re-read runs alongside the subscription, so a dropped or missing invalidation degrades into a slightly late resolution rather than an unbounded wait. Pass a `signal` to stop waiting:
|
|
246
244
|
|
|
247
245
|
```ts
|
|
248
246
|
const controller = new AbortController();
|
|
@@ -252,6 +250,6 @@ const settled = await session.workflow.waitForRun(runId, { signal: controller.si
|
|
|
252
250
|
|
|
253
251
|
Aborting rejects the wait and has no effect on the run, which keeps executing—use `pause(runId)` or `cancel(runId)` to stop it. The resolved object is a snapshot of that settled attempt. If its status is `paused`, a later resume updates the durable envelope under the same run ID. Call `getRun(runId)` to read the latest envelope. `isWorkflowRunTerminal(status)` exposes the same current-attempt settlement test for callers driving their own loop.
|
|
254
252
|
|
|
255
|
-
Listen for the ephemeral `
|
|
253
|
+
Listen for the ephemeral `workflow.run_updated` event. Its `{ runId, revision }` payload is an invalidation signal. Re-read the desired API when a newer monotonic revision arrives.
|
|
256
254
|
|
|
257
255
|
Revisions cover durable lifecycle, accounting, phase, agent, and progress changes. Continuous read-time fields can change without a new revision. These include `observedAt`, active-time calculations, live counts, and a live agent's status or prompt-safe activity text. Workflow prompts are never exposed by these APIs. A run is visible only through the session that owns it.
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "https://github.com/github/copilot-sdk.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0.15-preview.
|
|
8
|
-
"copilotCliVersion": "1.0.89-
|
|
7
|
+
"version": "1.0.15-preview.4",
|
|
8
|
+
"copilotCliVersion": "1.0.89-7",
|
|
9
9
|
"description": "TypeScript SDK for programmatic control of GitHub Copilot CLI via JSON-RPC",
|
|
10
10
|
"main": "./dist/cjs/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
@@ -101,13 +101,13 @@
|
|
|
101
101
|
"README.md"
|
|
102
102
|
],
|
|
103
103
|
"optionalDependencies": {
|
|
104
|
-
"@github/copilot-sdk-darwin-arm64": "1.0.15-preview.
|
|
105
|
-
"@github/copilot-sdk-darwin-x64": "1.0.15-preview.
|
|
106
|
-
"@github/copilot-sdk-linux-arm64": "1.0.15-preview.
|
|
107
|
-
"@github/copilot-sdk-linux-x64": "1.0.15-preview.
|
|
108
|
-
"@github/copilot-sdk-linuxmusl-arm64": "1.0.15-preview.
|
|
109
|
-
"@github/copilot-sdk-linuxmusl-x64": "1.0.15-preview.
|
|
110
|
-
"@github/copilot-sdk-win32-arm64": "1.0.15-preview.
|
|
111
|
-
"@github/copilot-sdk-win32-x64": "1.0.15-preview.
|
|
104
|
+
"@github/copilot-sdk-darwin-arm64": "1.0.15-preview.4",
|
|
105
|
+
"@github/copilot-sdk-darwin-x64": "1.0.15-preview.4",
|
|
106
|
+
"@github/copilot-sdk-linux-arm64": "1.0.15-preview.4",
|
|
107
|
+
"@github/copilot-sdk-linux-x64": "1.0.15-preview.4",
|
|
108
|
+
"@github/copilot-sdk-linuxmusl-arm64": "1.0.15-preview.4",
|
|
109
|
+
"@github/copilot-sdk-linuxmusl-x64": "1.0.15-preview.4",
|
|
110
|
+
"@github/copilot-sdk-win32-arm64": "1.0.15-preview.4",
|
|
111
|
+
"@github/copilot-sdk-win32-x64": "1.0.15-preview.4"
|
|
112
112
|
}
|
|
113
113
|
}
|
package/dist/cjs/factory.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var factory_exports = {};
|
|
20
|
-
__export(factory_exports, {
|
|
21
|
-
FACTORY_AGENT_OPTION_KEYS: () => FACTORY_AGENT_OPTION_KEYS,
|
|
22
|
-
FactoryResumeError: () => FactoryResumeError,
|
|
23
|
-
defineFactory: () => defineFactory,
|
|
24
|
-
getFactoryDefinition: () => getFactoryDefinition,
|
|
25
|
-
isFactoryRunTerminal: () => isFactoryRunTerminal
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(factory_exports);
|
|
28
|
-
const FACTORY_TERMINAL_STATUSES = /* @__PURE__ */ new Set([
|
|
29
|
-
"completed",
|
|
30
|
-
"halted",
|
|
31
|
-
"paused",
|
|
32
|
-
"cancelled",
|
|
33
|
-
"error"
|
|
34
|
-
]);
|
|
35
|
-
function isFactoryRunTerminal(status) {
|
|
36
|
-
return FACTORY_TERMINAL_STATUSES.has(status);
|
|
37
|
-
}
|
|
38
|
-
const FACTORY_AGENT_OPTION_KEYS = [
|
|
39
|
-
"label",
|
|
40
|
-
"schema",
|
|
41
|
-
"model",
|
|
42
|
-
"reasoningEffort",
|
|
43
|
-
"contextTier",
|
|
44
|
-
"agent"
|
|
45
|
-
];
|
|
46
|
-
class FactoryResumeError extends Error {
|
|
47
|
-
constructor(code, message) {
|
|
48
|
-
super(message);
|
|
49
|
-
this.code = code;
|
|
50
|
-
this.name = "FactoryResumeError";
|
|
51
|
-
}
|
|
52
|
-
code;
|
|
53
|
-
}
|
|
54
|
-
const factoryHandles = /* @__PURE__ */ new WeakMap();
|
|
55
|
-
const MAX_FACTORY_TIMEOUT_SECONDS = 2147483647e-3;
|
|
56
|
-
const NANO_AIU_PER_AIU = 1e9;
|
|
57
|
-
function deepFreeze(value) {
|
|
58
|
-
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
59
|
-
Object.freeze(value);
|
|
60
|
-
for (const nested of Object.values(value)) {
|
|
61
|
-
deepFreeze(nested);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return value;
|
|
65
|
-
}
|
|
66
|
-
function validateLimits(meta) {
|
|
67
|
-
const limits = meta.limits;
|
|
68
|
-
if (!limits) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
for (const field of ["maxConcurrentSubagents", "maxTotalSubagents"]) {
|
|
72
|
-
const value = limits[field];
|
|
73
|
-
if (value !== void 0 && (!Number.isInteger(value) || value <= 0)) {
|
|
74
|
-
throw new Error(`Factory limit "${field}" must be a positive integer`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (limits.timeoutSeconds !== void 0 && (!Number.isFinite(limits.timeoutSeconds) || limits.timeoutSeconds <= 0)) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
'Factory limit "timeoutSeconds" must be a positive, finite number of seconds'
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
if (limits.timeoutSeconds !== void 0 && limits.timeoutSeconds > MAX_FACTORY_TIMEOUT_SECONDS) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
`Factory limit "timeoutSeconds" must not exceed ${MAX_FACTORY_TIMEOUT_SECONDS} seconds`
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
if (limits.maxAiCredits !== void 0) {
|
|
88
|
-
const maxNanoAiu = Math.round(limits.maxAiCredits * NANO_AIU_PER_AIU);
|
|
89
|
-
if (!Number.isFinite(limits.maxAiCredits) || limits.maxAiCredits <= 0 || !Number.isSafeInteger(maxNanoAiu) || maxNanoAiu < 1) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
'Factory limit "maxAiCredits" must be a positive, finite number that rounds to a safe positive integer nano-AIU ceiling'
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function validatePhases(meta) {
|
|
97
|
-
const titles = /* @__PURE__ */ new Set();
|
|
98
|
-
for (const phase of meta.phases) {
|
|
99
|
-
if (phase.title.trim().length === 0) {
|
|
100
|
-
throw new Error("Factory phase titles must not be empty");
|
|
101
|
-
}
|
|
102
|
-
if (titles.has(phase.title)) {
|
|
103
|
-
throw new Error(`Factory phase title "${phase.title}" is declared more than once`);
|
|
104
|
-
}
|
|
105
|
-
titles.add(phase.title);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function defineFactory(definition) {
|
|
109
|
-
const meta = deepFreeze(structuredClone(definition.meta));
|
|
110
|
-
validateLimits(meta);
|
|
111
|
-
validatePhases(meta);
|
|
112
|
-
const stored = {
|
|
113
|
-
meta,
|
|
114
|
-
run: definition.run
|
|
115
|
-
};
|
|
116
|
-
const handle = Object.freeze({ meta });
|
|
117
|
-
factoryHandles.set(handle, stored);
|
|
118
|
-
return handle;
|
|
119
|
-
}
|
|
120
|
-
function getFactoryDefinition(handle) {
|
|
121
|
-
const definition = factoryHandles.get(handle);
|
|
122
|
-
if (!definition) {
|
|
123
|
-
throw new Error("Invalid factory handle");
|
|
124
|
-
}
|
|
125
|
-
return definition;
|
|
126
|
-
}
|
|
127
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
128
|
-
0 && (module.exports = {
|
|
129
|
-
FACTORY_AGENT_OPTION_KEYS,
|
|
130
|
-
FactoryResumeError,
|
|
131
|
-
defineFactory,
|
|
132
|
-
getFactoryDefinition,
|
|
133
|
-
isFactoryRunTerminal
|
|
134
|
-
});
|