@hachej/boring-agent 0.1.76 → 0.1.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-FRFCVP3X.js → chunk-3WWLQAJB.js} +3 -3
- package/dist/{chunk-M4AY4VBI.js → chunk-6AEK34XU.js} +1 -0
- package/dist/{chunk-PMREGRGD.js → chunk-ORURYKNY.js} +1 -1
- package/dist/{chunk-OABGJVSA.js → chunk-TS3QGFKK.js} +1 -1
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +3 -3
- package/dist/{createHarness-HQ3RHXTF.js → createHarness-RZUU6MJQ.js} +2 -2
- package/dist/front/index.d.ts +2 -3
- package/dist/front/index.js +2 -2
- package/dist/{harness-BrX6CdMT.d.ts → harness-OsJBlx4u.d.ts} +1 -1
- package/dist/piChatCommand-BuWXytap.d.ts +60 -0
- package/dist/server/index.d.ts +26 -6
- package/dist/server/index.js +174 -24
- package/dist/session-FUiMWsyX.d.ts +297 -0
- package/dist/shared/index.d.ts +25 -26
- package/dist/shared/index.js +2 -2
- package/dist/{agentPluginEvents-CqLTEdG2.d.ts → workspaceAgentDispatcher-Cl3EBveh.d.ts} +15 -1
- package/docs/API.md +27 -0
- package/docs/ERROR_CODES.md +1 -0
- package/package.json +2 -2
- package/dist/chatSubmitPayload-DwOHyiqR.d.ts +0 -22
- package/dist/piChatCommand-5UO2F_gv.d.ts +0 -40
- package/dist/session-DTV7L5dc.d.ts +0 -297
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
import {
|
|
7
7
|
extractToolUiMetadata,
|
|
8
8
|
sanitizeToolUiMetadata2 as sanitizeToolUiMetadata
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-ORURYKNY.js";
|
|
10
10
|
import {
|
|
11
11
|
createLogger
|
|
12
12
|
} from "./chunk-AJZHR626.js";
|
|
13
13
|
import {
|
|
14
14
|
ErrorCode
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-6AEK34XU.js";
|
|
16
16
|
|
|
17
17
|
// src/server/pi-chat/metering.ts
|
|
18
18
|
var meteringLogger = createLogger("pi-chat-metering");
|
|
@@ -2485,7 +2485,7 @@ function createRuntimeLoader(config, options) {
|
|
|
2485
2485
|
};
|
|
2486
2486
|
}
|
|
2487
2487
|
async function createRuntime(config, options) {
|
|
2488
|
-
const harnessFactory = config.harnessFactory ?? (await import("./createHarness-
|
|
2488
|
+
const harnessFactory = config.harnessFactory ?? (await import("./createHarness-RZUU6MJQ.js")).createPiCodingAgentHarness;
|
|
2489
2489
|
const pureRuntimeCwd = config.runtime === "none" ? await createPureRuntimeCwd(config.sessionStorageRoot) : void 0;
|
|
2490
2490
|
const harnessInput = {
|
|
2491
2491
|
tools: config.tools ?? [],
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { w as AgentConfig, c as Agent } from '../harness-
|
|
2
|
-
export { a as AGENT_NOT_IMPLEMENTED_UNTIL_T1, b as AGENT_NO_FILESYSTEM_FOR_ATTACHMENTS, d as AgentActor, e as AgentCoreHarness, f as AgentCoreHarnessFactory, g as AgentCorePromptInput, h as AgentCoreSessionAdapter, i as AgentCoreSessionSnapshot, j as AgentEvent, k as AgentFilesystemRequiredError, m as AgentMessageContent, n as AgentMessagePart, o as AgentNotImplementedError, p as AgentReadiness, q as AgentReadinessStatus, r as AgentResolveInputResponse, s as AgentRuntimeAdapter, t as AgentSendInput, u as AgentStartReceipt, v as AgentStreamOptions } from '../harness-
|
|
3
|
-
import '../session-
|
|
1
|
+
import { w as AgentConfig, c as Agent } from '../harness-OsJBlx4u.js';
|
|
2
|
+
export { a as AGENT_NOT_IMPLEMENTED_UNTIL_T1, b as AGENT_NO_FILESYSTEM_FOR_ATTACHMENTS, d as AgentActor, e as AgentCoreHarness, f as AgentCoreHarnessFactory, g as AgentCorePromptInput, h as AgentCoreSessionAdapter, i as AgentCoreSessionSnapshot, j as AgentEvent, k as AgentFilesystemRequiredError, m as AgentMessageContent, n as AgentMessagePart, o as AgentNotImplementedError, p as AgentReadiness, q as AgentReadinessStatus, r as AgentResolveInputResponse, s as AgentRuntimeAdapter, t as AgentSendInput, u as AgentStartReceipt, v as AgentStreamOptions } from '../harness-OsJBlx4u.js';
|
|
3
|
+
import '../session-FUiMWsyX.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
import '@mariozechner/pi-coding-agent';
|
|
6
6
|
|
package/dist/core/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createAgent
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-3WWLQAJB.js";
|
|
4
4
|
import {
|
|
5
5
|
AGENT_NOT_IMPLEMENTED_UNTIL_T1,
|
|
6
6
|
AGENT_NO_FILESYSTEM_FOR_ATTACHMENTS,
|
|
7
7
|
AgentFilesystemRequiredError,
|
|
8
8
|
AgentNotImplementedError
|
|
9
9
|
} from "../chunk-ZUEITFIJ.js";
|
|
10
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-ORURYKNY.js";
|
|
11
11
|
import "../chunk-AJZHR626.js";
|
|
12
|
-
import "../chunk-
|
|
12
|
+
import "../chunk-6AEK34XU.js";
|
|
13
13
|
export {
|
|
14
14
|
AGENT_NOT_IMPLEMENTED_UNTIL_T1,
|
|
15
15
|
AGENT_NO_FILESYSTEM_FOR_ATTACHMENTS,
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
deriveSourcePlugin,
|
|
5
5
|
mergePiPackageSources,
|
|
6
6
|
withPiHarnessDefaults
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-TS3QGFKK.js";
|
|
8
8
|
import "./chunk-AQBXNPMD.js";
|
|
9
9
|
import "./chunk-AJZHR626.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-6AEK34XU.js";
|
|
11
11
|
export {
|
|
12
12
|
createPiCodingAgentHarness,
|
|
13
13
|
createResourceSettingsManager,
|
package/dist/front/index.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentProps, HTMLAttributes, FormEvent, ReactNode, ComponentType } from 'react';
|
|
3
3
|
import { FileUIPart, ChatStatus, UIMessage } from 'ai';
|
|
4
|
-
import { T as ToolUiMetadata, B as BoringChatPart, e as BoringChatMessage, k as PiChatStatus, Q as QueuedUserMessage, C as ChatError, P as PiChatEvent, n as SessionSummary } from '../session-
|
|
5
|
-
import { P as PromptPayload,
|
|
4
|
+
import { T as ToolUiMetadata, B as BoringChatPart, e as BoringChatMessage, k as PiChatStatus, Q as QueuedUserMessage, C as ChatError, P as PiChatEvent, n as SessionSummary } from '../session-FUiMWsyX.js';
|
|
5
|
+
import { P as PromptPayload, f as PromptReceipt, F as FollowUpPayload, d as FollowUpReceipt, Q as QueueClearPayload, g as QueueClearReceipt, I as InterruptPayload, c as CommandReceipt, S as StopPayload, h as StopReceipt } from '../piChatCommand-BuWXytap.js';
|
|
6
6
|
import { InputGroupAddon, InputGroupButton, InputGroupTextarea, Button, Collapsible, CollapsibleContent, CollapsibleTrigger } from '@hachej/boring-ui-kit';
|
|
7
7
|
import { Streamdown } from 'streamdown';
|
|
8
8
|
import { StickToBottom } from 'use-stick-to-bottom';
|
|
9
9
|
import { ClassValue } from 'clsx';
|
|
10
10
|
import 'zod';
|
|
11
|
-
import '../chatSubmitPayload-DwOHyiqR.js';
|
|
12
11
|
|
|
13
12
|
interface UploadFileOptions {
|
|
14
13
|
apiBaseUrl?: string;
|
package/dist/front/index.js
CHANGED
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
StopReceiptSchema,
|
|
13
13
|
extractToolUiMetadata,
|
|
14
14
|
sanitizeToolUiMetadata
|
|
15
|
-
} from "../chunk-
|
|
15
|
+
} from "../chunk-ORURYKNY.js";
|
|
16
16
|
import {
|
|
17
17
|
ErrorCode
|
|
18
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-6AEK34XU.js";
|
|
19
19
|
import {
|
|
20
20
|
DebugDrawer,
|
|
21
21
|
cn,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as SessionCtx, P as PiChatEvent, a as SessionStore } from './session-
|
|
1
|
+
import { S as SessionCtx, P as PiChatEvent, a as SessionStore } from './session-FUiMWsyX.js';
|
|
2
2
|
import { AgentSessionEvent, PromptOptions } from '@mariozechner/pi-coding-agent';
|
|
3
3
|
|
|
4
4
|
interface TelemetrySink {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Q as QueuedUserMessage } from './session-FUiMWsyX.js';
|
|
2
|
+
|
|
3
|
+
type ThinkingLevel = 'off' | 'low' | 'medium' | 'high';
|
|
4
|
+
interface ChatModelSelection {
|
|
5
|
+
provider: string;
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
interface ChatAttachmentPayload {
|
|
9
|
+
filename?: string;
|
|
10
|
+
mediaType?: string;
|
|
11
|
+
url: string;
|
|
12
|
+
/** Workspace-relative path when the browser upload endpoint persisted the attachment. */
|
|
13
|
+
path?: string;
|
|
14
|
+
}
|
|
15
|
+
interface ChatSubmitPayload {
|
|
16
|
+
message: string;
|
|
17
|
+
displayMessage?: string;
|
|
18
|
+
clientNonce: string;
|
|
19
|
+
model?: ChatModelSelection;
|
|
20
|
+
thinkingLevel?: ThinkingLevel;
|
|
21
|
+
attachments?: ChatAttachmentPayload[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type PromptPayload = ChatSubmitPayload;
|
|
25
|
+
interface FollowUpPayload {
|
|
26
|
+
message: string;
|
|
27
|
+
displayMessage?: string;
|
|
28
|
+
clientNonce: string;
|
|
29
|
+
clientSeq: number;
|
|
30
|
+
}
|
|
31
|
+
interface QueueClearPayload {
|
|
32
|
+
clientNonce?: string;
|
|
33
|
+
clientSeq?: number;
|
|
34
|
+
}
|
|
35
|
+
type InterruptPayload = Record<string, never>;
|
|
36
|
+
type StopPayload = Record<string, never>;
|
|
37
|
+
interface CommandReceipt {
|
|
38
|
+
accepted: true;
|
|
39
|
+
cursor: number;
|
|
40
|
+
}
|
|
41
|
+
type PromptReceipt = CommandReceipt & {
|
|
42
|
+
clientNonce: string;
|
|
43
|
+
duplicate?: boolean;
|
|
44
|
+
};
|
|
45
|
+
type FollowUpReceipt = CommandReceipt & {
|
|
46
|
+
clientNonce: string;
|
|
47
|
+
clientSeq: number;
|
|
48
|
+
queued: true;
|
|
49
|
+
duplicate?: boolean;
|
|
50
|
+
};
|
|
51
|
+
type QueueClearReceipt = CommandReceipt & {
|
|
52
|
+
cleared: number;
|
|
53
|
+
};
|
|
54
|
+
type InterruptReceipt = CommandReceipt;
|
|
55
|
+
type StopReceipt = CommandReceipt & {
|
|
56
|
+
stopped: boolean;
|
|
57
|
+
clearedQueue: QueuedUserMessage[];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type { ChatAttachmentPayload as C, FollowUpPayload as F, InterruptPayload as I, PromptPayload as P, QueueClearPayload as Q, StopPayload as S, ThinkingLevel as T, ChatModelSelection as a, ChatSubmitPayload as b, CommandReceipt as c, FollowUpReceipt as d, InterruptReceipt as e, PromptReceipt as f, QueueClearReceipt as g, StopReceipt as h };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { m as WorkspaceRuntimeContext, S as Sandbox, f as SandboxHandleStore, e as SandboxHandleRecord, W as Workspace, F as FileSearch, g as Stat, E as Entry, b as ExecResult, n as WorkspaceChangeEvent, a as ExecOptions, P as PluginRestartWarning, k as WorkspaceAgentDispatcherContext, j as WorkspaceAgentDispatcher } from '../workspaceAgentDispatcher-Cl3EBveh.js';
|
|
2
2
|
import { Sandbox as Sandbox$1 } from '@vercel/sandbox';
|
|
3
|
-
import { x as TelemetrySink, E as ToolReadinessRequirement, j as AgentEvent, c as Agent, d as AgentActor, A as AgentTool, F as AgentHarnessFactory } from '../harness-
|
|
4
|
-
export { w as AgentConfig, G as AgentHarnessFactoryInput } from '../harness-
|
|
3
|
+
import { x as TelemetrySink, E as ToolReadinessRequirement, j as AgentEvent, c as Agent, d as AgentActor, A as AgentTool, F as AgentHarnessFactory } from '../harness-OsJBlx4u.js';
|
|
4
|
+
export { w as AgentConfig, G as AgentHarnessFactoryInput } from '../harness-OsJBlx4u.js';
|
|
5
5
|
import { FastifyInstance, FastifyRequest, FastifyPluginAsync } from 'fastify';
|
|
6
6
|
export { createAgent } from '../core/index.js';
|
|
7
|
-
import { S as SessionCtx, f as ErrorCode } from '../session-
|
|
7
|
+
import { S as SessionCtx, f as ErrorCode } from '../session-FUiMWsyX.js';
|
|
8
8
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
9
9
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
10
10
|
import { PackageSource, ExtensionFactory, SettingsManager } from '@mariozechner/pi-coding-agent';
|
|
11
|
-
import {
|
|
11
|
+
import { a as ChatModelSelection } from '../piChatCommand-BuWXytap.js';
|
|
12
12
|
import 'zod';
|
|
13
13
|
|
|
14
14
|
interface CreateDirectSandboxOptions {
|
|
@@ -1083,6 +1083,13 @@ type MeteringErrorLogger = (message: string, error: unknown) => void;
|
|
|
1083
1083
|
* from an unexpected provider still meters as zeros instead of NaN. */
|
|
1084
1084
|
declare function normalizeMeteringUsage(value: unknown): MeteringUsage | undefined;
|
|
1085
1085
|
|
|
1086
|
+
interface WorkspaceAgentDispatcherResolveOptions {
|
|
1087
|
+
request?: FastifyRequest;
|
|
1088
|
+
}
|
|
1089
|
+
interface WorkspaceAgentDispatcherResolver {
|
|
1090
|
+
resolve(ctx: WorkspaceAgentDispatcherContext, options?: WorkspaceAgentDispatcherResolveOptions): Promise<WorkspaceAgentDispatcher>;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1086
1093
|
interface CreateAgentAppOptions {
|
|
1087
1094
|
workspaceRoot?: string;
|
|
1088
1095
|
sessionId?: string;
|
|
@@ -1172,6 +1179,11 @@ interface CreateAgentAppOptions {
|
|
|
1172
1179
|
message: string;
|
|
1173
1180
|
pluginId?: string;
|
|
1174
1181
|
}>>;
|
|
1182
|
+
/**
|
|
1183
|
+
* Trusted in-process host composition seam. The resolver trusts caller-supplied
|
|
1184
|
+
* workspace/user context; callers must authorize that context before resolving.
|
|
1185
|
+
*/
|
|
1186
|
+
onWorkspaceAgentDispatcher?: (resolver: WorkspaceAgentDispatcherResolver) => void;
|
|
1175
1187
|
}
|
|
1176
1188
|
declare function createAgentApp(opts?: CreateAgentAppOptions): Promise<FastifyInstance>;
|
|
1177
1189
|
|
|
@@ -1298,11 +1310,14 @@ interface RegisterAgentRoutesOptions {
|
|
|
1298
1310
|
workspaceId: string;
|
|
1299
1311
|
workspaceRoot: string;
|
|
1300
1312
|
request?: FastifyRequest;
|
|
1313
|
+
/** Verified actor id for trusted requestless dispatcher resolution. */
|
|
1314
|
+
userId?: string;
|
|
1301
1315
|
}) => string | undefined | Promise<string | undefined>;
|
|
1302
1316
|
registerHealthRoute?: boolean;
|
|
1303
1317
|
sandboxHandleStore?: SandboxHandleStore;
|
|
1304
1318
|
getWorkspaceId?: (request: FastifyRequest) => string | Promise<string>;
|
|
1305
1319
|
getWorkspaceRoot?: (workspaceId: string, request: FastifyRequest) => string | Promise<string>;
|
|
1320
|
+
getTrustedWorkspaceRoot?: (ctx: WorkspaceAgentDispatcherContext) => string | Promise<string>;
|
|
1306
1321
|
/** Generic runtime env contributors. Agent stays workspace-neutral; hosts decide env names/values. */
|
|
1307
1322
|
runtimeEnvContributions?: RuntimeEnvContribution[];
|
|
1308
1323
|
/**
|
|
@@ -1338,6 +1353,11 @@ interface RegisterAgentRoutesOptions {
|
|
|
1338
1353
|
message: string;
|
|
1339
1354
|
pluginId?: string;
|
|
1340
1355
|
}>>;
|
|
1356
|
+
/**
|
|
1357
|
+
* Trusted in-process host composition seam. The resolver trusts caller-supplied
|
|
1358
|
+
* workspace/user context; callers must authorize that context before resolving.
|
|
1359
|
+
*/
|
|
1360
|
+
onWorkspaceAgentDispatcher?: (resolver: WorkspaceAgentDispatcherResolver) => void;
|
|
1341
1361
|
}
|
|
1342
1362
|
/**
|
|
1343
1363
|
* Fastify plugin that mounts agent routes onto a host app (typically core-built).
|
|
@@ -1359,4 +1379,4 @@ interface Logger {
|
|
|
1359
1379
|
}
|
|
1360
1380
|
declare function createLogger(prefix: string): Logger;
|
|
1361
1381
|
|
|
1362
|
-
export { AgentHarnessFactory, type AgentMeteringSink, type BoringAgentRuntimePaths, type BuiltinRuntimeModeId, type BwrapResourceLimits, type CreateAgentAppOptions, type CreateBwrapSandboxOptions, type CreateVercelProvisioningAdapterOptions, type DeploymentSnapshotProvider, type DeploymentSnapshotRecipe, type DeploymentSnapshotResult, type DeploymentSnapshotStatus, FileHandleStore, type LogFields, type Logger, MANAGED_AGENT_MCP_DELIVERY_RULE, MANAGED_AGENT_MCP_ORIGIN_SURFACE, type ManagedAgentArtifactRef, type ManagedAgentCollectArtifactsInput, type ManagedAgentDelegateInput, type ManagedAgentDelegateProgress, type ManagedAgentDelegateRequestContext, type ManagedAgentDelegateResult, type ManagedAgentDelegateStatus, type ManagedAgentDelegateStatusResult, ManagedAgentMcpDelegateController, type ManagedAgentMcpDelegateOptions, ManagedAgentMcpError, type ManagedAgentMcpHttpHandlerOptions, type ManagedAgentMcpServerOptions, type ManagedAgentSafeError, type MeteringErrorLogger, type MeteringReleaseInput, type MeteringReleaseReason, type MeteringReservationResult, type MeteringReserveInput, type MeteringRunKind, type MeteringRunScope, type MeteringRunStatus, type MeteringSettleInput, type MeteringUsage, type MeteringUsageInput, type ModeContext, PI_PACKAGE_RESOURCE_FILTERS, type PiExtensionFactory, type PiHarnessOptions, type PiPackageSource, type PluginSkillSource, type ProvisionRuntimeWorkspaceOptions, type ProvisionWorkspaceRuntimeOptions, type ProvisioningArtifactRequest, REMOTE_WORKER_PROVIDER, REMOTE_WORKER_RUNTIME_CWD, type RegisterAgentRoutesOptions, RemoteWorkerClient, RemoteWorkerClientError, type RemoteWorkerClientOptions, type RemoteWorkerErrorPayload, type RemoteWorkerExecRequest, type RemoteWorkerExecResponse, type RemoteWorkerFsEventEnvelope, type RemoteWorkerModeAdapterOptions, type RemoteWorkerWorkspaceOp, type RemoteWorkerWorkspaceResult, type RuntimeBundle, type RuntimeEnvContribution, type RuntimeEnvContributionContext, type RuntimeFilesystemBinding, type RuntimeFilesystemBindingOperations, type RuntimeModeAdapter, type RuntimeModeId, type RuntimeNodePackageSpec$1 as RuntimeNodePackageSpec, type RuntimeProvisioningContribution$1 as RuntimeProvisioningContribution, type RuntimePythonSpec$1 as RuntimePythonSpec, type RuntimeTemplateContribution$1 as RuntimeTemplateContribution, type RuntimeWorkspaceProvisioningResult, type SnapshotBakeOptions, type SnapshotBakeResult, UV_SETUP_COMMANDS, VERCEL_PROVISIONING_CACHE_ROOT, VERCEL_SANDBOX_WORKSPACE_ROOT, UV_SETUP_COMMANDS as VERCEL_UV_SETUP_COMMANDS, type VercelBakeClient, type VercelBakeSandbox, type VercelDeploymentSnapshotOptions, WORKER_INTERNAL_TOKEN_HEADER, WORKER_REQUEST_ID_HEADER, WORKER_WORKSPACE_ID_HEADER, type WorkspaceProvisioningAdapter, type WorkspaceProvisioningExecResult, type WorkspaceProvisioningResult, applyCspHeaders, autoDetectMode, bakeSnapshotIfNeeded, buildDeploymentSnapshotRecipe, buildPackageHash, buildSnapshotRecipeHash, compactPiPackages, constantTimeTokenEqual, createAgentApp, createBwrapSandbox, createDirectSandbox, createLogger, createManagedAgentMcpDelegateController, createManagedAgentMcpHttpHandler, createManagedAgentMcpServer, createNodeWorkspace, createRemoteWorkerModeAdapter, createRemoteWorkerSandbox, createRemoteWorkerWorkspace, createResourceSettingsManager, createVercelDeploymentSnapshotProvider, createVercelProvisioningAdapter, createVercelSandboxWorkspace, decodeBytesFromWorker, encodeBytesForWorker, fileRoutes, getBoringAgentPathEntries, getBoringAgentRuntimeEnv, getBoringAgentRuntimePaths, hasBwrap, mergePiPackageSources, normalizeMeteringUsage, piPackageSourceKey, prepareDeploymentSnapshot, prepareVercelDeploymentSnapshot, provisionRuntimeWorkspace, provisionWorkspaceRuntime, registerAgentRoutes, resolveMode, resolveSandboxHandle };
|
|
1382
|
+
export { AgentHarnessFactory, type AgentMeteringSink, type BoringAgentRuntimePaths, type BuiltinRuntimeModeId, type BwrapResourceLimits, type CreateAgentAppOptions, type CreateBwrapSandboxOptions, type CreateVercelProvisioningAdapterOptions, type DeploymentSnapshotProvider, type DeploymentSnapshotRecipe, type DeploymentSnapshotResult, type DeploymentSnapshotStatus, FileHandleStore, type LogFields, type Logger, MANAGED_AGENT_MCP_DELIVERY_RULE, MANAGED_AGENT_MCP_ORIGIN_SURFACE, type ManagedAgentArtifactRef, type ManagedAgentCollectArtifactsInput, type ManagedAgentDelegateInput, type ManagedAgentDelegateProgress, type ManagedAgentDelegateRequestContext, type ManagedAgentDelegateResult, type ManagedAgentDelegateStatus, type ManagedAgentDelegateStatusResult, ManagedAgentMcpDelegateController, type ManagedAgentMcpDelegateOptions, ManagedAgentMcpError, type ManagedAgentMcpHttpHandlerOptions, type ManagedAgentMcpServerOptions, type ManagedAgentSafeError, type MeteringErrorLogger, type MeteringReleaseInput, type MeteringReleaseReason, type MeteringReservationResult, type MeteringReserveInput, type MeteringRunKind, type MeteringRunScope, type MeteringRunStatus, type MeteringSettleInput, type MeteringUsage, type MeteringUsageInput, type ModeContext, PI_PACKAGE_RESOURCE_FILTERS, type PiExtensionFactory, type PiHarnessOptions, type PiPackageSource, type PluginSkillSource, type ProvisionRuntimeWorkspaceOptions, type ProvisionWorkspaceRuntimeOptions, type ProvisioningArtifactRequest, REMOTE_WORKER_PROVIDER, REMOTE_WORKER_RUNTIME_CWD, type RegisterAgentRoutesOptions, RemoteWorkerClient, RemoteWorkerClientError, type RemoteWorkerClientOptions, type RemoteWorkerErrorPayload, type RemoteWorkerExecRequest, type RemoteWorkerExecResponse, type RemoteWorkerFsEventEnvelope, type RemoteWorkerModeAdapterOptions, type RemoteWorkerWorkspaceOp, type RemoteWorkerWorkspaceResult, type RuntimeBundle, type RuntimeEnvContribution, type RuntimeEnvContributionContext, type RuntimeFilesystemBinding, type RuntimeFilesystemBindingOperations, type RuntimeModeAdapter, type RuntimeModeId, type RuntimeNodePackageSpec$1 as RuntimeNodePackageSpec, type RuntimeProvisioningContribution$1 as RuntimeProvisioningContribution, type RuntimePythonSpec$1 as RuntimePythonSpec, type RuntimeTemplateContribution$1 as RuntimeTemplateContribution, type RuntimeWorkspaceProvisioningResult, type SnapshotBakeOptions, type SnapshotBakeResult, UV_SETUP_COMMANDS, VERCEL_PROVISIONING_CACHE_ROOT, VERCEL_SANDBOX_WORKSPACE_ROOT, UV_SETUP_COMMANDS as VERCEL_UV_SETUP_COMMANDS, type VercelBakeClient, type VercelBakeSandbox, type VercelDeploymentSnapshotOptions, WORKER_INTERNAL_TOKEN_HEADER, WORKER_REQUEST_ID_HEADER, WORKER_WORKSPACE_ID_HEADER, type WorkspaceAgentDispatcherResolveOptions, type WorkspaceAgentDispatcherResolver, type WorkspaceProvisioningAdapter, type WorkspaceProvisioningExecResult, type WorkspaceProvisioningResult, applyCspHeaders, autoDetectMode, bakeSnapshotIfNeeded, buildDeploymentSnapshotRecipe, buildPackageHash, buildSnapshotRecipeHash, compactPiPackages, constantTimeTokenEqual, createAgentApp, createBwrapSandbox, createDirectSandbox, createLogger, createManagedAgentMcpDelegateController, createManagedAgentMcpHttpHandler, createManagedAgentMcpServer, createNodeWorkspace, createRemoteWorkerModeAdapter, createRemoteWorkerSandbox, createRemoteWorkerWorkspace, createResourceSettingsManager, createVercelDeploymentSnapshotProvider, createVercelProvisioningAdapter, createVercelSandboxWorkspace, decodeBytesFromWorker, encodeBytesForWorker, fileRoutes, getBoringAgentPathEntries, getBoringAgentRuntimeEnv, getBoringAgentRuntimePaths, hasBwrap, mergePiPackageSources, normalizeMeteringUsage, piPackageSourceKey, prepareDeploymentSnapshot, prepareVercelDeploymentSnapshot, provisionRuntimeWorkspace, provisionWorkspaceRuntime, registerAgentRoutes, resolveMode, resolveSandboxHandle };
|
package/dist/server/index.js
CHANGED
|
@@ -7,16 +7,18 @@ import {
|
|
|
7
7
|
createAgent,
|
|
8
8
|
createAgentRuntimeBridge,
|
|
9
9
|
normalizeMeteringUsage
|
|
10
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-3WWLQAJB.js";
|
|
11
11
|
import "../chunk-ZUEITFIJ.js";
|
|
12
12
|
import {
|
|
13
|
+
CommandReceiptSchema,
|
|
13
14
|
FollowUpPayloadSchema,
|
|
14
15
|
InterruptPayloadSchema,
|
|
15
16
|
PiChatSnapshotSchema,
|
|
16
17
|
PromptPayloadSchema,
|
|
17
18
|
QueueClearPayloadSchema,
|
|
18
|
-
StopPayloadSchema
|
|
19
|
-
|
|
19
|
+
StopPayloadSchema,
|
|
20
|
+
StopReceiptSchema
|
|
21
|
+
} from "../chunk-ORURYKNY.js";
|
|
20
22
|
import {
|
|
21
23
|
PI_PACKAGE_RESOURCE_FILTERS,
|
|
22
24
|
PiSessionStore,
|
|
@@ -31,7 +33,7 @@ import {
|
|
|
31
33
|
registerConfiguredModelProviders,
|
|
32
34
|
setEnvDefault,
|
|
33
35
|
withPiHarnessDefaults
|
|
34
|
-
} from "../chunk-
|
|
36
|
+
} from "../chunk-TS3QGFKK.js";
|
|
35
37
|
import {
|
|
36
38
|
safeCapture
|
|
37
39
|
} from "../chunk-AQBXNPMD.js";
|
|
@@ -40,7 +42,7 @@ import {
|
|
|
40
42
|
} from "../chunk-AJZHR626.js";
|
|
41
43
|
import {
|
|
42
44
|
ErrorCode
|
|
43
|
-
} from "../chunk-
|
|
45
|
+
} from "../chunk-6AEK34XU.js";
|
|
44
46
|
|
|
45
47
|
// src/server/sandbox/direct/createDirectSandbox.ts
|
|
46
48
|
import { spawn } from "child_process";
|
|
@@ -9496,15 +9498,103 @@ async function registerAgentRouteBindingProfile(app, profile) {
|
|
|
9496
9498
|
await app.register(readyStatusRoutes, profile.readyStatus);
|
|
9497
9499
|
}
|
|
9498
9500
|
|
|
9501
|
+
// src/server/workspaceAgentDispatcher.ts
|
|
9502
|
+
function createBoundWorkspaceAgentDispatcher(agent, ctx) {
|
|
9503
|
+
const boundCtx = normalizeWorkspaceAgentDispatcherContext(ctx);
|
|
9504
|
+
return {
|
|
9505
|
+
send(input) {
|
|
9506
|
+
return agent.send({ ...input, ctx: boundCtx });
|
|
9507
|
+
},
|
|
9508
|
+
async interrupt(sessionId) {
|
|
9509
|
+
return parseControlReceipt(await agent.interrupt(sessionId, boundCtx), "interrupt");
|
|
9510
|
+
},
|
|
9511
|
+
async stop(sessionId) {
|
|
9512
|
+
return parseStopReceipt(await agent.stop(sessionId, boundCtx));
|
|
9513
|
+
}
|
|
9514
|
+
};
|
|
9515
|
+
}
|
|
9516
|
+
function assertWorkspaceAgentDispatcherRequestContext(ctx, request) {
|
|
9517
|
+
normalizeWorkspaceAgentDispatcherContext(ctx);
|
|
9518
|
+
if (!request) return;
|
|
9519
|
+
const requestWorkspaceId = request.workspaceContext?.workspaceId?.trim();
|
|
9520
|
+
if (!requestWorkspaceId) return;
|
|
9521
|
+
if (requestWorkspaceId !== ctx.workspaceId.trim()) {
|
|
9522
|
+
throw createWorkspaceAgentDispatcherError(
|
|
9523
|
+
ErrorCode.enum.UNAUTHORIZED,
|
|
9524
|
+
"workspace agent dispatcher context does not match request workspace",
|
|
9525
|
+
401
|
|
9526
|
+
);
|
|
9527
|
+
}
|
|
9528
|
+
}
|
|
9529
|
+
function normalizeWorkspaceAgentDispatcherContext(ctx) {
|
|
9530
|
+
const workspaceId = ctx.workspaceId?.trim();
|
|
9531
|
+
const userId = ctx.userId?.trim();
|
|
9532
|
+
if (!workspaceId) {
|
|
9533
|
+
throw createWorkspaceAgentDispatcherError(
|
|
9534
|
+
ErrorCode.enum.WORKSPACE_UNINITIALIZED,
|
|
9535
|
+
"workspace id is required",
|
|
9536
|
+
400
|
|
9537
|
+
);
|
|
9538
|
+
}
|
|
9539
|
+
if (!userId) {
|
|
9540
|
+
throw createWorkspaceAgentDispatcherError(
|
|
9541
|
+
ErrorCode.enum.UNAUTHORIZED,
|
|
9542
|
+
"user id is required",
|
|
9543
|
+
401
|
|
9544
|
+
);
|
|
9545
|
+
}
|
|
9546
|
+
return { workspaceId, userId };
|
|
9547
|
+
}
|
|
9548
|
+
function parseControlReceipt(receipt, action) {
|
|
9549
|
+
const parsed = CommandReceiptSchema.safeParse(receipt);
|
|
9550
|
+
if (parsed.success) return parsed.data;
|
|
9551
|
+
throw createWorkspaceAgentDispatcherError(
|
|
9552
|
+
ErrorCode.enum.AGENT_CONTROL_RECEIPT_INVALID,
|
|
9553
|
+
`agent ${action} returned a malformed receipt`,
|
|
9554
|
+
500
|
|
9555
|
+
);
|
|
9556
|
+
}
|
|
9557
|
+
function parseStopReceipt(receipt) {
|
|
9558
|
+
const parsed = StopReceiptSchema.safeParse(receipt);
|
|
9559
|
+
if (parsed.success) return parsed.data;
|
|
9560
|
+
throw createWorkspaceAgentDispatcherError(
|
|
9561
|
+
ErrorCode.enum.AGENT_CONTROL_RECEIPT_INVALID,
|
|
9562
|
+
"agent stop returned a malformed receipt",
|
|
9563
|
+
500
|
|
9564
|
+
);
|
|
9565
|
+
}
|
|
9566
|
+
function createWorkspaceAgentDispatcherError(code, message, statusCode) {
|
|
9567
|
+
const error = new Error(message);
|
|
9568
|
+
error.code = code;
|
|
9569
|
+
error.statusCode = statusCode;
|
|
9570
|
+
return error;
|
|
9571
|
+
}
|
|
9572
|
+
|
|
9499
9573
|
// src/server/createAgentApp.ts
|
|
9500
9574
|
var DEFAULT_VERSION = "0.1.0-dev";
|
|
9501
9575
|
var DEFAULT_SESSION_ID = "default";
|
|
9502
9576
|
var PURE_RUNTIME_MODE = "none";
|
|
9577
|
+
function createStaticWorkspaceAgentDispatcherResolver(agent, workspaceId) {
|
|
9578
|
+
return {
|
|
9579
|
+
async resolve(ctx, options) {
|
|
9580
|
+
const boundCtx = normalizeWorkspaceAgentDispatcherContext(ctx);
|
|
9581
|
+
assertWorkspaceAgentDispatcherRequestContext(boundCtx, options?.request);
|
|
9582
|
+
if (boundCtx.workspaceId !== workspaceId) {
|
|
9583
|
+
throw createWorkspaceAgentDispatcherError(
|
|
9584
|
+
ErrorCode.enum.UNAUTHORIZED,
|
|
9585
|
+
"workspace agent dispatcher context does not match bound workspace",
|
|
9586
|
+
401
|
|
9587
|
+
);
|
|
9588
|
+
}
|
|
9589
|
+
return createBoundWorkspaceAgentDispatcher(agent, boundCtx);
|
|
9590
|
+
}
|
|
9591
|
+
};
|
|
9592
|
+
}
|
|
9503
9593
|
async function createAgentApp(opts = {}) {
|
|
9504
9594
|
const sessionId = opts.sessionId ?? DEFAULT_SESSION_ID;
|
|
9505
9595
|
const app = Fastify({ logger: opts.logger ?? true, bodyLimit: 16 * 1024 * 1024 });
|
|
9506
9596
|
const resolvedMode = opts.runtimeModeAdapter?.id ?? opts.mode ?? autoDetectMode();
|
|
9507
|
-
const profile = !opts.runtimeModeAdapter && resolvedMode === PURE_RUNTIME_MODE ? await createPureAgentAppProfile(opts, resolvedMode) : await createWorkspaceAgentAppProfile(opts, sessionId, resolvedMode, app);
|
|
9597
|
+
const profile = !opts.runtimeModeAdapter && resolvedMode === PURE_RUNTIME_MODE ? await createPureAgentAppProfile(opts, sessionId, resolvedMode) : await createWorkspaceAgentAppProfile(opts, sessionId, resolvedMode, app);
|
|
9508
9598
|
app.addHook(
|
|
9509
9599
|
"onRequest",
|
|
9510
9600
|
createAuthMiddleware({
|
|
@@ -9515,7 +9605,7 @@ async function createAgentApp(opts = {}) {
|
|
|
9515
9605
|
await registerAgentRouteBindingProfile(app, profile);
|
|
9516
9606
|
return app;
|
|
9517
9607
|
}
|
|
9518
|
-
async function createPureAgentAppProfile(opts, resolvedMode) {
|
|
9608
|
+
async function createPureAgentAppProfile(opts, sessionId, resolvedMode) {
|
|
9519
9609
|
const runtimePi = withPiHarnessDefaults(opts.pi);
|
|
9520
9610
|
const baseHarnessFactory = opts.harnessFactory ?? ((input) => createPiCodingAgentHarness({
|
|
9521
9611
|
...input,
|
|
@@ -9539,6 +9629,7 @@ async function createPureAgentAppProfile(opts, resolvedMode) {
|
|
|
9539
9629
|
sessionStorageRoot: opts.sessionRoot
|
|
9540
9630
|
});
|
|
9541
9631
|
const agentRuntime = await coreAgent.getRuntime();
|
|
9632
|
+
opts.onWorkspaceAgentDispatcher?.(createStaticWorkspaceAgentDispatcherResolver(coreAgent.agent, sessionId));
|
|
9542
9633
|
const readyTracker = new ReadyStatusTracker({ sandboxReady: true, harnessReady: true });
|
|
9543
9634
|
return {
|
|
9544
9635
|
runtimeMode: resolvedMode,
|
|
@@ -9657,6 +9748,7 @@ async function createWorkspaceAgentAppProfile(opts, sessionId, resolvedMode, app
|
|
|
9657
9748
|
}
|
|
9658
9749
|
});
|
|
9659
9750
|
const agentRuntime = await coreAgent.getRuntime();
|
|
9751
|
+
opts.onWorkspaceAgentDispatcher?.(createStaticWorkspaceAgentDispatcherResolver(coreAgent.agent, sessionId));
|
|
9660
9752
|
const harness = agentRuntime.harness;
|
|
9661
9753
|
harnessRef = harness;
|
|
9662
9754
|
const readyTracker = createRuntimeReadyStatusTracker(modeAdapter, {
|
|
@@ -10043,7 +10135,7 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10043
10135
|
await modeAdapter.dispose?.();
|
|
10044
10136
|
});
|
|
10045
10137
|
const modelsWorkspaceScoped = Boolean(opts.filterModels);
|
|
10046
|
-
const requestScopedRuntime = typeof opts.getWorkspaceId === "function" || typeof opts.getWorkspaceRoot === "function" || typeof opts.getTemplatePath === "function" || typeof opts.getPi === "function" || typeof opts.getExtraTools === "function" || typeof opts.getSessionNamespace === "function" || typeof opts.getSystemPromptDynamic === "function";
|
|
10138
|
+
const requestScopedRuntime = typeof opts.getWorkspaceId === "function" || typeof opts.getWorkspaceRoot === "function" || typeof opts.getTemplatePath === "function" || typeof opts.getPi === "function" || typeof opts.getExtraTools === "function" || typeof opts.getSessionNamespace === "function" || typeof opts.getSystemPromptDynamic === "function" || typeof opts.getTrustedWorkspaceRoot === "function";
|
|
10047
10139
|
const sessionChangesTracker = new InMemorySessionChangesTracker();
|
|
10048
10140
|
const externalPluginsEnabled = opts.externalPlugins !== false;
|
|
10049
10141
|
const runtimeBindings = /* @__PURE__ */ new Map();
|
|
@@ -10058,12 +10150,23 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10058
10150
|
async function resolveScopePi(workspaceId, root, request) {
|
|
10059
10151
|
return withPiHarnessDefaults(opts.getPi ? await opts.getPi({ workspaceId, workspaceRoot: root, request }) : opts.pi);
|
|
10060
10152
|
}
|
|
10061
|
-
async function resolveRuntimeScope(workspaceId, request) {
|
|
10062
|
-
|
|
10153
|
+
async function resolveRuntimeScope(workspaceId, request, trustedCtx) {
|
|
10154
|
+
let root = workspaceRoot;
|
|
10155
|
+
if (request && opts.getWorkspaceRoot) {
|
|
10156
|
+
root = await opts.getWorkspaceRoot(workspaceId, request);
|
|
10157
|
+
} else if (trustedCtx && opts.getTrustedWorkspaceRoot) {
|
|
10158
|
+
root = await opts.getTrustedWorkspaceRoot(trustedCtx);
|
|
10159
|
+
} else if (!request && opts.getWorkspaceRoot) {
|
|
10160
|
+
throw createWorkspaceAgentDispatcherError(
|
|
10161
|
+
ErrorCode.enum.WORKSPACE_UNINITIALIZED,
|
|
10162
|
+
"workspace root resolution requires trusted workspace context",
|
|
10163
|
+
400
|
|
10164
|
+
);
|
|
10165
|
+
}
|
|
10063
10166
|
const scopedTemplatePath = opts.getTemplatePath ? await opts.getTemplatePath({ workspaceId, workspaceRoot: root, request }) : templatePath;
|
|
10064
10167
|
const pi = await resolveScopePi(workspaceId, root, request);
|
|
10065
|
-
const sessionNamespace = normalizeSessionNamespace(opts.getSessionNamespace ? await opts.getSessionNamespace({ workspaceId, workspaceRoot: root, request }) : opts.sessionNamespace);
|
|
10066
|
-
const extraToolsAuthSubject = opts.getExtraTools ? getRequestAuthSubject2(request) : void 0;
|
|
10168
|
+
const sessionNamespace = normalizeSessionNamespace(opts.getSessionNamespace ? await opts.getSessionNamespace({ workspaceId, workspaceRoot: root, request, userId: trustedCtx?.userId }) : opts.sessionNamespace);
|
|
10169
|
+
const extraToolsAuthSubject = opts.getExtraTools ? trustedCtx?.userId ?? getRequestAuthSubject2(request) : void 0;
|
|
10067
10170
|
return {
|
|
10068
10171
|
root,
|
|
10069
10172
|
templatePath: scopedTemplatePath,
|
|
@@ -10123,7 +10226,7 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10123
10226
|
request
|
|
10124
10227
|
});
|
|
10125
10228
|
}
|
|
10126
|
-
async function createRuntimeBinding(workspaceId, scope, request) {
|
|
10229
|
+
async function createRuntimeBinding(workspaceId, scope, request, trustedCtx) {
|
|
10127
10230
|
const root = scope.root;
|
|
10128
10231
|
const modeCtx = {
|
|
10129
10232
|
workspaceRoot: root,
|
|
@@ -10271,7 +10374,7 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10271
10374
|
workspaceRoot: root,
|
|
10272
10375
|
runtimeMode: resolvedMode,
|
|
10273
10376
|
workspaceFsCapability: runtimeBundle.workspace.fsCapability,
|
|
10274
|
-
authSubject: getRequestAuthSubject2(request)
|
|
10377
|
+
authSubject: trustedCtx?.userId ?? getRequestAuthSubject2(request)
|
|
10275
10378
|
}) : [];
|
|
10276
10379
|
const tools = mergeTools({
|
|
10277
10380
|
standardTools,
|
|
@@ -10347,12 +10450,12 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10347
10450
|
startRuntimeProvisioning(request);
|
|
10348
10451
|
return binding;
|
|
10349
10452
|
}
|
|
10350
|
-
function createRuntimeBindingEntry(workspaceId, scope, request) {
|
|
10453
|
+
function createRuntimeBindingEntry(workspaceId, scope, request, trustedCtx) {
|
|
10351
10454
|
const entry = {
|
|
10352
10455
|
state: "pending",
|
|
10353
10456
|
promise: Promise.resolve(null)
|
|
10354
10457
|
};
|
|
10355
|
-
entry.promise = createRuntimeBinding(workspaceId, scope, request).then(
|
|
10458
|
+
entry.promise = createRuntimeBinding(workspaceId, scope, request, trustedCtx).then(
|
|
10356
10459
|
(binding) => {
|
|
10357
10460
|
entry.state = "ready";
|
|
10358
10461
|
return binding;
|
|
@@ -10368,7 +10471,7 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10368
10471
|
return entry;
|
|
10369
10472
|
}
|
|
10370
10473
|
async function getOrCreateRuntimeBinding(workspaceId, request, options = {}) {
|
|
10371
|
-
const scope = await resolveRuntimeScope(workspaceId, request);
|
|
10474
|
+
const scope = await resolveRuntimeScope(workspaceId, request, options.trustedCtx);
|
|
10372
10475
|
const existing = runtimeBindings.get(scope.key);
|
|
10373
10476
|
if (existing) {
|
|
10374
10477
|
if (options.failIfPending && existing.state === "pending") {
|
|
@@ -10386,7 +10489,7 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10386
10489
|
);
|
|
10387
10490
|
}
|
|
10388
10491
|
}
|
|
10389
|
-
const created = createRuntimeBindingEntry(workspaceId, scope, request);
|
|
10492
|
+
const created = createRuntimeBindingEntry(workspaceId, scope, request, options.trustedCtx);
|
|
10390
10493
|
runtimeBindings.set(scope.key, created);
|
|
10391
10494
|
evictRuntimeBindings();
|
|
10392
10495
|
if (options.failIfPending) {
|
|
@@ -10442,6 +10545,24 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10442
10545
|
const staticBinding = requestScopedRuntime ? null : await getOrCreateRuntimeBinding(sessionId);
|
|
10443
10546
|
const skillsScopeByRequest = /* @__PURE__ */ new WeakMap();
|
|
10444
10547
|
const earlySessionStores = /* @__PURE__ */ new Map();
|
|
10548
|
+
opts.onWorkspaceAgentDispatcher?.({
|
|
10549
|
+
async resolve(ctx, options) {
|
|
10550
|
+
const boundCtx = normalizeWorkspaceAgentDispatcherContext(ctx);
|
|
10551
|
+
assertWorkspaceAgentDispatcherRequestContext(boundCtx, options?.request);
|
|
10552
|
+
if (staticBinding) {
|
|
10553
|
+
if (boundCtx.workspaceId !== sessionId) {
|
|
10554
|
+
throw createWorkspaceAgentDispatcherError(
|
|
10555
|
+
ErrorCode.enum.UNAUTHORIZED,
|
|
10556
|
+
"workspace agent dispatcher context does not match bound workspace",
|
|
10557
|
+
401
|
|
10558
|
+
);
|
|
10559
|
+
}
|
|
10560
|
+
return createBoundWorkspaceAgentDispatcher(staticBinding.agent, boundCtx);
|
|
10561
|
+
}
|
|
10562
|
+
const binding = await getOrCreateRuntimeBinding(boundCtx.workspaceId, options?.request, { trustedCtx: boundCtx });
|
|
10563
|
+
return createBoundWorkspaceAgentDispatcher(binding.agent, boundCtx);
|
|
10564
|
+
}
|
|
10565
|
+
});
|
|
10445
10566
|
function getSkillsScopeForRequest(request) {
|
|
10446
10567
|
let promise = skillsScopeByRequest.get(request);
|
|
10447
10568
|
if (!promise) {
|
|
@@ -10658,7 +10779,7 @@ var registerAgentRoutes = async (app, opts) => {
|
|
|
10658
10779
|
};
|
|
10659
10780
|
async function registerPureAgentRoutes(app, opts, sessionId, resolvedMode) {
|
|
10660
10781
|
const pureBindings = /* @__PURE__ */ new Map();
|
|
10661
|
-
const requestScopedPure = typeof opts.getWorkspaceId === "function" || typeof opts.getWorkspaceRoot === "function" || typeof opts.getExtraTools === "function" || typeof opts.getPi === "function" || typeof opts.getSessionNamespace === "function" || typeof opts.getSystemPromptDynamic === "function";
|
|
10782
|
+
const requestScopedPure = typeof opts.getWorkspaceId === "function" || typeof opts.getWorkspaceRoot === "function" || typeof opts.getExtraTools === "function" || typeof opts.getPi === "function" || typeof opts.getSessionNamespace === "function" || typeof opts.getSystemPromptDynamic === "function" || typeof opts.getTrustedWorkspaceRoot === "function";
|
|
10662
10783
|
function evictPureBindings() {
|
|
10663
10784
|
if (pureBindings.size <= MAX_PURE_BINDINGS) return;
|
|
10664
10785
|
const keys = Array.from(pureBindings.keys());
|
|
@@ -10671,12 +10792,23 @@ async function registerPureAgentRoutes(app, opts, sessionId, resolvedMode) {
|
|
|
10671
10792
|
});
|
|
10672
10793
|
}
|
|
10673
10794
|
}
|
|
10674
|
-
async function createPureBinding(request) {
|
|
10675
|
-
const workspaceId = request ? getRequestWorkspaceId2(request) : sessionId;
|
|
10676
|
-
|
|
10795
|
+
async function createPureBinding(request, trustedCtx) {
|
|
10796
|
+
const workspaceId = trustedCtx?.workspaceId ?? (request ? getRequestWorkspaceId2(request) : sessionId);
|
|
10797
|
+
let workspaceRoot = opts.workspaceRoot ?? "";
|
|
10798
|
+
if (request && opts.getWorkspaceRoot) {
|
|
10799
|
+
workspaceRoot = await opts.getWorkspaceRoot(workspaceId, request);
|
|
10800
|
+
} else if (trustedCtx && opts.getTrustedWorkspaceRoot) {
|
|
10801
|
+
workspaceRoot = await opts.getTrustedWorkspaceRoot(trustedCtx);
|
|
10802
|
+
} else if (!request && opts.getWorkspaceRoot) {
|
|
10803
|
+
throw createWorkspaceAgentDispatcherError(
|
|
10804
|
+
ErrorCode.enum.WORKSPACE_UNINITIALIZED,
|
|
10805
|
+
"workspace root resolution requires trusted workspace context",
|
|
10806
|
+
400
|
|
10807
|
+
);
|
|
10808
|
+
}
|
|
10677
10809
|
const pi = withPiHarnessDefaults(opts.getPi ? await opts.getPi({ workspaceId, workspaceRoot, request }) : opts.pi);
|
|
10678
|
-
const configuredSessionNamespace = normalizeSessionNamespace(opts.getSessionNamespace ? await opts.getSessionNamespace({ workspaceId, workspaceRoot, request }) : opts.sessionNamespace);
|
|
10679
|
-
const authSubject = opts.getExtraTools ? getRequestAuthSubject2(request) : void 0;
|
|
10810
|
+
const configuredSessionNamespace = normalizeSessionNamespace(opts.getSessionNamespace ? await opts.getSessionNamespace({ workspaceId, workspaceRoot, request, userId: trustedCtx?.userId }) : opts.sessionNamespace);
|
|
10811
|
+
const authSubject = opts.getExtraTools ? trustedCtx?.userId ?? getRequestAuthSubject2(request) : void 0;
|
|
10680
10812
|
const pureScopeNamespace = opts.getWorkspaceId ? pureSessionNamespaceFromWorkspaceId(workspaceId) : requestScopedPure ? pureSessionNamespaceFromScope([resolvedMode, workspaceId, workspaceRoot, pi, authSubject ?? null]) : void 0;
|
|
10681
10813
|
const sessionNamespace = configuredSessionNamespace && pureScopeNamespace ? `${configuredSessionNamespace}-${pureScopeNamespace}` : configuredSessionNamespace ?? pureScopeNamespace;
|
|
10682
10814
|
const key = JSON.stringify([
|
|
@@ -10739,6 +10871,24 @@ async function registerPureAgentRoutes(app, opts, sessionId, resolvedMode) {
|
|
|
10739
10871
|
return bindingPromise;
|
|
10740
10872
|
}
|
|
10741
10873
|
const staticBinding = requestScopedPure ? void 0 : await createPureBinding();
|
|
10874
|
+
opts.onWorkspaceAgentDispatcher?.({
|
|
10875
|
+
async resolve(ctx, options) {
|
|
10876
|
+
const boundCtx = normalizeWorkspaceAgentDispatcherContext(ctx);
|
|
10877
|
+
assertWorkspaceAgentDispatcherRequestContext(boundCtx, options?.request);
|
|
10878
|
+
if (staticBinding) {
|
|
10879
|
+
if (boundCtx.workspaceId !== sessionId) {
|
|
10880
|
+
throw createWorkspaceAgentDispatcherError(
|
|
10881
|
+
ErrorCode.enum.UNAUTHORIZED,
|
|
10882
|
+
"workspace agent dispatcher context does not match bound workspace",
|
|
10883
|
+
401
|
|
10884
|
+
);
|
|
10885
|
+
}
|
|
10886
|
+
return createBoundWorkspaceAgentDispatcher(staticBinding.agent, boundCtx);
|
|
10887
|
+
}
|
|
10888
|
+
const binding = await createPureBinding(options?.request, boundCtx);
|
|
10889
|
+
return createBoundWorkspaceAgentDispatcher(binding.agent, boundCtx);
|
|
10890
|
+
}
|
|
10891
|
+
});
|
|
10742
10892
|
const profile = {
|
|
10743
10893
|
runtimeMode: resolvedMode,
|
|
10744
10894
|
capabilities: {
|