@hachej/boring-agent 0.1.90 → 0.1.91

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.
Files changed (36) hide show
  1. package/dist/{chunk-4PKGVPJA.js → chunk-2GBHYJVC.js} +27 -5
  2. package/dist/{chunk-5CYVBVP3.js → chunk-BHH5NH7P.js} +4766 -2153
  3. package/dist/{chunk-BEFJNMKQ.js → chunk-CJ2BW2W2.js} +23 -8
  4. package/dist/{chunk-F7ZS27HE.js → chunk-IWBC6SF7.js} +93 -19
  5. package/dist/chunk-NITBKFG6.js +1246 -0
  6. package/dist/{chunk-JEDRQAR5.js → chunk-PZC76CIA.js} +7 -1
  7. package/dist/core/index.d.ts +5 -5
  8. package/dist/core/index.js +2 -2
  9. package/dist/{createHarness-UCCGMVQJ.js → createHarness-PMYRKDE4.js} +2 -2
  10. package/dist/errors-BEmw9HMp.d.ts +200 -0
  11. package/dist/front/index.d.ts +20 -4
  12. package/dist/front/index.js +172 -44
  13. package/dist/{harness-Rbkdpvse.d.ts → harness-Bt_GMNYR.d.ts} +2 -2
  14. package/dist/{workspaceAgentDispatcher-50Uzuxhs.d.ts → lease-2aXepSBL.d.ts} +266 -57
  15. package/dist/{protocol-CDA4bcP9.d.ts → middleware-CzW8n7B7.d.ts} +20 -2
  16. package/dist/piChatEvent-DBO3M5lu.d.ts +367 -0
  17. package/dist/{piChatSessionService-DDKPOj4x.d.ts → piChatSessionService-BaaVWke7.d.ts} +5 -1
  18. package/dist/{sandbox-OEG_l9GE.d.ts → sandbox-DAD8cWQR.d.ts} +14 -1
  19. package/dist/server/agent-host/testing/gatewayConformance.d.ts +41 -0
  20. package/dist/server/agent-host/testing/gatewayConformance.js +465 -0
  21. package/dist/server/index.d.ts +451 -528
  22. package/dist/server/index.js +43 -9
  23. package/dist/server/worker/index.d.ts +2 -2
  24. package/dist/server/worker/index.js +7 -7
  25. package/dist/shared/index.d.ts +109 -41
  26. package/dist/shared/index.js +65 -282
  27. package/dist/types-jcMapYr9.d.ts +759 -0
  28. package/docs/ACCESSIBILITY.md +4 -5
  29. package/docs/API.md +3 -0
  30. package/docs/AUTHORING.md +68 -0
  31. package/docs/ERROR_CODES.md +27 -6
  32. package/docs/README.md +1 -0
  33. package/package.json +17 -8
  34. package/dist/chunk-CFQQXJKK.js +0 -385
  35. package/dist/chunk-DGRKMMXO.js +0 -8
  36. package/dist/piChatEvent-CHgln6yx.d.ts +0 -367
@@ -0,0 +1,759 @@
1
+ import * as fastify from 'fastify';
2
+ import { FastifyRequest, FastifyPluginAsync } from 'fastify';
3
+ import { w as ToolReadinessRequirement, T as TelemetrySink, b as Agent, A as AgentHarness, t as AgentTool, u as AgentHarnessFactory } from './harness-Bt_GMNYR.js';
4
+ import { F as FileSearch, b as AgentSessionRef, V as VerifiedAgentScopeClaim, g as AgentGatewayErrorDTO, J as JsonValue, a as AuthorizedAgentScope, A as AgentGateway, h as AgentScopeVerifier } from './errors-BEmw9HMp.js';
5
+ import { o as ChatModelSelection } from './piChatEvent-DBO3M5lu.js';
6
+ import { b as Workspace, c as WorkspaceRuntimeContext, S as Sandbox } from './sandbox-DAD8cWQR.js';
7
+ import { RuntimeHostOperations } from '@hachej/boring-bash/agent';
8
+ import { CreateNodeWorkspaceOptions, BoringAgentRuntimePaths } from '@hachej/boring-sandbox/providers/node-workspace';
9
+ import { PackageSource, ExtensionFactory, SettingsManager } from '@mariozechner/pi-coding-agent';
10
+ import { A as AgentCoreSessionService, g as PiChatSessionService } from './piChatSessionService-BaaVWke7.js';
11
+
12
+ /**
13
+ * Generic metering seam for hosts that bill native Pi usage.
14
+ *
15
+ * The agent package owns lifecycle correctness (when to reserve, record,
16
+ * settle, release based on native Pi events); the host-provided sink owns
17
+ * persistence and product policy (credits, pricing, currencies, hard stops).
18
+ *
19
+ * Lifecycle per accepted prompt/follow-up ("run", identified by `runId`):
20
+ *
21
+ * reserveRun before execution starts; throwing rejects the request
22
+ * (fail closed) so hosts can enforce hard stops.
23
+ * recordUsage once per native assistant message carrying usage.
24
+ * `usageId` is a stable idempotency key.
25
+ * settleRun when the run reaches a native terminal state and usage
26
+ * was recorded (or it finished ok).
27
+ * releaseRun when the run never produced billable usage: rejected
28
+ * execution, cleared queue, cancel/abort, or error before
29
+ * any usage arrived.
30
+ *
31
+ * Every run terminates with exactly one settle or release from the
32
+ * coordinator; sinks should still treat all four methods as idempotent
33
+ * because process restarts and client retries can replay transitions.
34
+ */
35
+ interface AgentMeteringSink {
36
+ /** False means the sink is installed but policy is disabled/no-op. Omitted means active for fail-closed callers. */
37
+ isEnabled?: () => boolean;
38
+ reserveRun(input: MeteringReserveInput): Promise<MeteringReservationResult>;
39
+ /** Records the usage and returns the credit micros it was actually billed. The
40
+ * coordinator counts a usage as billable from this charged amount (not raw provider
41
+ * fields), so a row that prices to 0 (e.g. cost-only usage when provider cost isn't
42
+ * trusted) doesn't make a free run settle. */
43
+ recordUsage(input: MeteringUsageInput): Promise<MeteringUsageResult>;
44
+ settleRun(input: MeteringSettleInput): Promise<void>;
45
+ releaseRun(input: MeteringReleaseInput): Promise<void>;
46
+ }
47
+ interface MeteringUsageResult {
48
+ /** Credit micros this usage row was billed (0 = no real debit). */
49
+ billedMicros: number;
50
+ }
51
+ interface MeteringRunScope {
52
+ workspaceId?: string;
53
+ userId?: string;
54
+ userEmail?: string;
55
+ userEmailVerified?: boolean;
56
+ sessionId: string;
57
+ /** Stable id for one accepted prompt/follow-up run. */
58
+ runId: string;
59
+ source: 'pi-chat';
60
+ }
61
+ type MeteringRunKind = 'prompt' | 'followup';
62
+ interface MeteringReserveInput extends MeteringRunScope {
63
+ kind: MeteringRunKind;
64
+ message: string;
65
+ model?: ChatModelSelection;
66
+ }
67
+ /** Sinks without reservation rows can return an empty object. */
68
+ interface MeteringReservationResult {
69
+ reservationId?: string;
70
+ }
71
+ interface MeteringUsage {
72
+ input: number;
73
+ output: number;
74
+ cacheRead: number;
75
+ cacheWrite: number;
76
+ cost: {
77
+ input: number;
78
+ output: number;
79
+ cacheRead: number;
80
+ cacheWrite: number;
81
+ total: number;
82
+ };
83
+ }
84
+ interface MeteringUsageInput extends MeteringRunScope {
85
+ reservationId?: string;
86
+ /** Stable idempotency key for this usage row. */
87
+ usageId: string;
88
+ messageId?: string;
89
+ model?: {
90
+ provider?: string;
91
+ id?: string;
92
+ };
93
+ usage: MeteringUsage;
94
+ stopReason?: string;
95
+ metadata?: Record<string, unknown>;
96
+ }
97
+ type MeteringRunStatus = 'ok' | 'error' | 'aborted';
98
+ interface MeteringSettleInput extends MeteringRunScope {
99
+ reservationId?: string;
100
+ status: MeteringRunStatus;
101
+ }
102
+ type MeteringReleaseReason = 'run-rejected' | 'queue-cleared' | 'cancelled' | 'error-before-usage' | 'usage-write-failed' | 'fallback-hold-charge';
103
+ interface MeteringReleaseInput extends MeteringRunScope {
104
+ reservationId?: string;
105
+ reason: MeteringReleaseReason;
106
+ }
107
+ type MeteringErrorLogger = (message: string, error: unknown) => void;
108
+ /** Native Pi usage objects always carry token + cost breakdowns; normalize
109
+ * defensively (zero-filling gaps and clamping negatives) so a partial object
110
+ * from an unexpected provider still meters as zeros instead of NaN. */
111
+ declare function normalizeMeteringUsage(value: unknown): MeteringUsage | undefined;
112
+
113
+ type ReadyState = 'provisioning' | 'ready' | 'degraded';
114
+ type CapabilityState = 'not-started' | 'preparing' | 'ready' | 'failed';
115
+ interface CapabilityReadinessDetail {
116
+ state: CapabilityState;
117
+ requirement?: ToolReadinessRequirement;
118
+ startedAt?: string;
119
+ completedAt?: string;
120
+ errorCode?: string;
121
+ causeCode?: string;
122
+ retryable?: boolean;
123
+ message?: string;
124
+ }
125
+ interface AgentCapabilityReadiness {
126
+ chat: CapabilityReadinessDetail;
127
+ workspace: CapabilityReadinessDetail;
128
+ runtimeDependencies: CapabilityReadinessDetail;
129
+ }
130
+ interface ReadyStatusEvent {
131
+ state: ReadyState;
132
+ sandboxReady: boolean;
133
+ harnessReady: boolean;
134
+ capabilities: AgentCapabilityReadiness;
135
+ message?: string;
136
+ timestamp: string;
137
+ }
138
+ interface ReadinessSnapshot {
139
+ sandboxReady: boolean;
140
+ harnessReady: boolean;
141
+ capabilities: AgentCapabilityReadiness;
142
+ degradedReason?: string;
143
+ }
144
+ type StatusHandler = (event: ReadyStatusEvent) => void;
145
+ declare class ReadyStatusTracker {
146
+ private _sandboxReady;
147
+ private _harnessReady;
148
+ private _degradedReason?;
149
+ private _capabilities;
150
+ private subscribers;
151
+ constructor(opts?: {
152
+ sandboxReady?: boolean;
153
+ harnessReady?: boolean;
154
+ capabilities?: Partial<AgentCapabilityReadiness>;
155
+ });
156
+ get state(): ReadyState;
157
+ isReady(): boolean;
158
+ getReadiness(): ReadinessSnapshot;
159
+ getCapabilities(): AgentCapabilityReadiness;
160
+ updateCapability(name: keyof AgentCapabilityReadiness, detail: CapabilityReadinessDetail): void;
161
+ updateRuntimeDependencies(detail: CapabilityReadinessDetail): void;
162
+ markSandboxReady(): void;
163
+ markHarnessReady(): void;
164
+ markDegraded(reason: string): void;
165
+ clearDegraded(): void;
166
+ subscribe(handler: StatusHandler): () => void;
167
+ private emit;
168
+ private snapshot;
169
+ }
170
+
171
+ /**
172
+ * Host-owned values used by Agent's provider-neutral runtime composition.
173
+ *
174
+ * Built-in concrete operations live in `sandboxRuntimeHost.ts`; custom hosts
175
+ * may inject an equivalent implementation with their Workspace + Sandbox pair.
176
+ */
177
+ interface AgentRuntimeHostOperations extends RuntimeHostOperations {
178
+ createNodeWorkspace(root: string, options?: CreateNodeWorkspaceOptions): Workspace;
179
+ getNodeWorkspaceHostRoot(workspace: Workspace): string | undefined;
180
+ getBoringAgentRuntimePaths(workspaceRoot: string): BoringAgentRuntimePaths;
181
+ getBoringAgentRuntimeEnv(paths: BoringAgentRuntimePaths, cacheRoot?: string): Record<string, string>;
182
+ getBoringAgentPathEntries(paths: BoringAgentRuntimePaths): string[];
183
+ readonly runtimeLayout: Readonly<{
184
+ agentDir: string;
185
+ runtimeDirNames: readonly string[];
186
+ gitignoreContent: string;
187
+ }>;
188
+ validatePath(root: string, requestedPath: string): string;
189
+ assertRealPathWithinWorkspace(root: string, targetPath: string): Promise<void>;
190
+ isIgnoredDirName(name: string): boolean;
191
+ }
192
+
193
+ interface ProvisioningLogger {
194
+ info?(message: string, fields?: Record<string, unknown>): void;
195
+ warn?(message: string, fields?: Record<string, unknown>): void;
196
+ error?(message: string, fields?: Record<string, unknown>): void;
197
+ }
198
+
199
+ interface PluginSkillSource {
200
+ name: string;
201
+ source: string | URL;
202
+ }
203
+ interface RuntimeTemplateContribution {
204
+ id: string;
205
+ path: string | URL;
206
+ target?: string;
207
+ }
208
+ interface RuntimePythonSpec {
209
+ id: string;
210
+ projectFile: string | URL;
211
+ packageName?: string;
212
+ packageRoot?: string | URL;
213
+ version?: string;
214
+ extraLibs?: string[];
215
+ env?: Record<string, string | URL>;
216
+ expectedBins?: string[];
217
+ }
218
+ interface RuntimeNodePackageSpec {
219
+ id: string;
220
+ packageName: string;
221
+ packageRoot?: string | URL;
222
+ version?: string;
223
+ expectedBins?: string[];
224
+ }
225
+ interface RuntimeProvisioningContribution {
226
+ templateDirs?: RuntimeTemplateContribution[];
227
+ python?: RuntimePythonSpec[];
228
+ nodePackages?: RuntimeNodePackageSpec[];
229
+ }
230
+ interface WorkspaceProvisioningResult {
231
+ changed: boolean;
232
+ env: Record<string, string>;
233
+ pathEntries: string[];
234
+ skillPaths: string[];
235
+ }
236
+ interface WorkspaceProvisioningExecResult {
237
+ stdout?: string;
238
+ stderr?: string;
239
+ }
240
+ interface ResolveInstallSourceOpts {
241
+ kind: 'node' | 'python';
242
+ id: string;
243
+ fingerprint: string;
244
+ }
245
+ interface WorkspaceProvisioningAdapter {
246
+ mode: 'direct' | 'local' | 'vercel-sandbox';
247
+ exec(command: string, args: string[], opts?: {
248
+ cwd?: string;
249
+ env?: Record<string, string>;
250
+ timeoutMs?: number;
251
+ }): Promise<WorkspaceProvisioningExecResult | void>;
252
+ resolveInstallSource(source: string | URL, opts: ResolveInstallSourceOpts): Promise<string>;
253
+ workspaceFs: {
254
+ exists(workspaceRelativePath: string): Promise<boolean>;
255
+ /** Remove a workspace-relative generated path. Missing path is success. */
256
+ rm(workspaceRelativePath: string): Promise<void>;
257
+ /** Create a workspace-relative directory recursively. */
258
+ mkdir(workspaceRelativePath: string): Promise<void>;
259
+ writeText(workspaceRelativePath: string, content: string): Promise<void>;
260
+ readText(workspaceRelativePath: string): Promise<string | null>;
261
+ /** Copy a host file or directory into the workspace; directory copies are recursive. */
262
+ copyFromHost(hostSourcePath: string | URL, workspaceRelativeTarget: string): Promise<void>;
263
+ };
264
+ getRuntimeCacheRoot(): string;
265
+ }
266
+ interface ProvisioningTelemetryContext {
267
+ workspaceId?: string;
268
+ sessionId?: string;
269
+ requestId?: string;
270
+ runtimeMode?: string;
271
+ }
272
+ interface ProvisionWorkspaceRuntimeOptions {
273
+ plugins: Array<{
274
+ id: string;
275
+ skills?: PluginSkillSource[];
276
+ provisioning?: RuntimeProvisioningContribution;
277
+ }>;
278
+ adapter: WorkspaceProvisioningAdapter;
279
+ runtimeLayout: BoringAgentRuntimePaths;
280
+ runtimeHost: AgentRuntimeHostOperations;
281
+ logger?: ProvisioningLogger;
282
+ telemetry?: TelemetrySink;
283
+ telemetryContext?: ProvisioningTelemetryContext;
284
+ }
285
+
286
+ type BuiltinRuntimeModeId = 'direct' | 'local' | 'vercel-sandbox';
287
+ type RuntimeModeId = BuiltinRuntimeModeId | (string & {});
288
+ interface RuntimeModeReadinessHooks {
289
+ initialSandboxReady?: boolean;
290
+ initialWorkspaceReadiness?: CapabilityReadinessDetail;
291
+ onTrackerCreated?: (tracker: ReadyStatusTracker) => void;
292
+ }
293
+ type RuntimeCachedBindingHealthCheckResult = {
294
+ state: 'ok';
295
+ } | {
296
+ state: 'recreate';
297
+ message?: string;
298
+ error?: unknown;
299
+ };
300
+ interface RuntimeCachedBindingHealthCheck {
301
+ intervalMs?: number;
302
+ check(ctx: {
303
+ runtimeBundle: RuntimeBundle;
304
+ workspaceId: string;
305
+ }): Promise<RuntimeCachedBindingHealthCheckResult>;
306
+ }
307
+ type RuntimeBashStrategy = {
308
+ kind: 'host';
309
+ preserveHostHome?: boolean;
310
+ } | {
311
+ kind: 'local-sandbox';
312
+ sandboxRoot: string;
313
+ } | {
314
+ kind: 'remote';
315
+ defaultPath?: string;
316
+ };
317
+ interface RuntimeRemoteWorkspacePathOptions {
318
+ rootAliases?: string[];
319
+ toRemotePath?: (value: string) => string;
320
+ toRuntimePath?: (value: string) => string;
321
+ sanitizeErrorText?: (value: string) => string;
322
+ }
323
+ type RuntimeFilesystemStrategy = {
324
+ kind: 'host';
325
+ } | {
326
+ kind: 'remote-workspace';
327
+ pathOptions?: RuntimeRemoteWorkspacePathOptions;
328
+ };
329
+ interface RuntimeModeAdapter {
330
+ readonly id: RuntimeModeId;
331
+ readonly runtimeHost?: AgentRuntimeHostOperations;
332
+ /**
333
+ * Declares whether the workspace files are strongly available on the host
334
+ * path before create() runs. Composition layers use this to decide whether
335
+ * host-side fs checks/prompts are safe without hard-coding sandbox IDs.
336
+ */
337
+ readonly workspaceFsCapability?: Workspace['fsCapability'];
338
+ readonly readiness?: RuntimeModeReadinessHooks;
339
+ readonly cachedBindingHealthCheck?: RuntimeCachedBindingHealthCheck;
340
+ create(ctx: ModeContext): Promise<RuntimeBundle>;
341
+ getRuntimeLayoutRoot?(ctx: ModeContext): string;
342
+ evictCachedRuntime?(ctx: {
343
+ workspaceId: string;
344
+ }): void | Promise<void>;
345
+ dispose?(): Promise<void>;
346
+ }
347
+ interface ModeContext {
348
+ workspaceRoot: string;
349
+ sessionId: string;
350
+ workspaceId?: string;
351
+ templatePath?: string;
352
+ requestId?: string;
353
+ telemetry?: TelemetrySink;
354
+ }
355
+ interface RuntimeFilesystemBindingOperations {
356
+ read(descriptor: {
357
+ filesystem: string;
358
+ path: string;
359
+ }): Promise<{
360
+ content: string;
361
+ mtimeMs?: number;
362
+ metadata?: unknown;
363
+ }>;
364
+ list(descriptor: {
365
+ filesystem: string;
366
+ path: string;
367
+ }): Promise<{
368
+ entries: string[];
369
+ metadata?: unknown;
370
+ }>;
371
+ find(descriptor: {
372
+ filesystem: string;
373
+ path: string;
374
+ }, pattern: string, options?: {
375
+ limit?: number;
376
+ offset?: number;
377
+ }): Promise<{
378
+ paths: string[];
379
+ metadata?: unknown;
380
+ }>;
381
+ grep(descriptor: {
382
+ filesystem: string;
383
+ path: string;
384
+ }, pattern: string, options?: {
385
+ limit?: number;
386
+ offset?: number;
387
+ }): Promise<{
388
+ matches: Array<{
389
+ path: string;
390
+ line: number;
391
+ text: string;
392
+ }>;
393
+ metadata?: unknown;
394
+ }>;
395
+ stat(descriptor: {
396
+ filesystem: string;
397
+ path: string;
398
+ }): Promise<{
399
+ isDirectory: boolean;
400
+ metadata?: unknown;
401
+ }>;
402
+ write?(descriptor: {
403
+ filesystem: string;
404
+ path: string;
405
+ content: string;
406
+ expectedMtimeMs?: number;
407
+ }): Promise<{
408
+ mtimeMs?: number;
409
+ metadata?: unknown;
410
+ }>;
411
+ delete?(descriptor: {
412
+ filesystem: string;
413
+ path: string;
414
+ }): Promise<{
415
+ metadata?: unknown;
416
+ }>;
417
+ move?(descriptor: {
418
+ filesystem: string;
419
+ from: string;
420
+ to: string;
421
+ }): Promise<{
422
+ metadata?: unknown;
423
+ }>;
424
+ mkdir?(descriptor: {
425
+ filesystem: string;
426
+ path: string;
427
+ recursive?: boolean;
428
+ }): Promise<{
429
+ metadata?: unknown;
430
+ }>;
431
+ rejectMutation(operation: string, descriptor: {
432
+ filesystem: string;
433
+ path: string;
434
+ }): never;
435
+ }
436
+ interface RuntimeFilesystemBinding {
437
+ readonly filesystem: string;
438
+ readonly access: 'readonly' | 'readwrite';
439
+ readonly operations: RuntimeFilesystemBindingOperations;
440
+ }
441
+ interface RuntimeBundle {
442
+ runtimeContext?: WorkspaceRuntimeContext;
443
+ /**
444
+ * Server-private host/storage root for host-side filesystem work. Do not use
445
+ * this as the agent-visible cwd; Workspace.root remains the public runtime
446
+ * namespace shown to tools/model.
447
+ */
448
+ storageRoot?: string;
449
+ workspace: Workspace;
450
+ sandbox: Sandbox;
451
+ fileSearch: FileSearch;
452
+ /** Host-owned provider utilities injected at the application boundary. */
453
+ runtimeHost?: AgentRuntimeHostOperations;
454
+ /** Optional per-execution runtime env provider for local/direct operations that do not call Sandbox.exec. */
455
+ getRuntimeEnv?: () => Promise<Record<string, string>>;
456
+ /** Runtime-owned bash execution strategy, consumed by the agent bash tool builder. */
457
+ bash?: RuntimeBashStrategy;
458
+ /** Runtime-owned filesystem strategy, consumed by the agent filesystem tool builder. */
459
+ filesystem?: RuntimeFilesystemStrategy;
460
+ /** Optional filesystem bindings prepared for this runtime/session. */
461
+ filesystemBindings?: RuntimeFilesystemBinding[];
462
+ /** Provisioning operations derived from this bundle's acquired Workspace + Sandbox pair. */
463
+ provisioningAdapter?: WorkspaceProvisioningAdapter;
464
+ /** Idempotently releases the acquired Workspace + Sandbox pair. */
465
+ disposeRuntime?: () => Promise<void>;
466
+ }
467
+
468
+ type PiPackageSource = PackageSource;
469
+ declare const PI_PACKAGE_RESOURCE_FILTERS: readonly ["extensions", "skills", "prompts", "themes"];
470
+ declare function piPackageSourceKey(source: PiPackageSource): string;
471
+ declare function compactPiPackages(sources: Array<PiPackageSource | undefined>): PiPackageSource[];
472
+ declare function mergePiPackageSources(base?: PiPackageSource[], additional?: PiPackageSource[]): PiPackageSource[];
473
+
474
+ interface PiHarnessOptions {
475
+ noContextFiles?: boolean;
476
+ noSkills?: boolean;
477
+ additionalSkillPaths?: string[];
478
+ defaultModel?: {
479
+ provider: string;
480
+ id: string;
481
+ };
482
+ /**
483
+ * Additional native Pi package sources to enable for this agent runtime.
484
+ * These are applied as in-memory SettingsManager overrides, so host/plugin
485
+ * declarations do not mutate .pi/settings.json.
486
+ */
487
+ packages?: PiPackageSource[];
488
+ /**
489
+ * Additional native pi extension entrypoints. Pi loads these through jiti and
490
+ * re-imports them on ctx.reload(), which is required for hot-reloadable
491
+ * boring agent plugins.
492
+ */
493
+ extensionPaths?: string[];
494
+ /** In-process host extensions. Use only for trusted built-ins; hot plugin code should use paths. */
495
+ extensionFactories?: ExtensionFactory[];
496
+ /**
497
+ * Optional source of hot-reloadable Pi resources. Pi calls it on every
498
+ * reloadSession() (and once at session build) and merges the result with
499
+ * the static fields above. Lets the workspace plugin layer refresh
500
+ * package.json-discovered skills/packages/extensions without mutating
501
+ * arrays that the harness already captured.
502
+ */
503
+ getHotReloadableResources?: () => HotReloadablePiResources;
504
+ /** Reject an explicit unavailable/unknown model instead of silently falling back. */
505
+ strictModelResolution?: boolean;
506
+ }
507
+ interface HotReloadablePiResources {
508
+ additionalSkillPaths?: string[];
509
+ packages?: PiPackageSource[];
510
+ extensionPaths?: string[];
511
+ }
512
+ type PiExtensionFactory = ExtensionFactory;
513
+ declare function createResourceSettingsManager(cwd: string, agentDir: string, piPackages: PiPackageSource[]): SettingsManager;
514
+
515
+ type AgentGatewayEffect = 'session.create' | 'session.rename' | 'session.delete' | 'session.prompt' | 'session.followup' | 'session.interrupt' | 'session.stop' | 'session.queue.clear';
516
+ type AgentRequestTarget = {
517
+ readonly kind: 'agent';
518
+ readonly agentTypeId: string;
519
+ } | {
520
+ readonly kind: 'session';
521
+ readonly ref: AgentSessionRef;
522
+ };
523
+ interface AgentRequestKey {
524
+ readonly workspaceScopeId: string;
525
+ readonly authSubjectId: string;
526
+ readonly operation: AgentGatewayEffect;
527
+ readonly target: AgentRequestTarget;
528
+ readonly requestId: string;
529
+ }
530
+ type AgentRequestFailure = {
531
+ readonly kind: 'gateway';
532
+ readonly error: AgentGatewayErrorDTO;
533
+ } | {
534
+ /** Server-only compatibility envelope; never returned by AgentGateway. */
535
+ readonly kind: 'legacy-admission';
536
+ readonly code: string;
537
+ readonly statusCode: 500;
538
+ readonly message: string;
539
+ readonly details?: JsonValue;
540
+ } | {
541
+ /** Server-only observed legacy service failure; never returned by AgentGateway. */
542
+ readonly kind: 'legacy-service';
543
+ readonly name: string;
544
+ readonly message: string;
545
+ readonly code?: string;
546
+ readonly statusCode?: number;
547
+ readonly retryable?: boolean;
548
+ readonly details?: JsonValue;
549
+ };
550
+ interface AgentRequestLedgerRecordBase {
551
+ readonly key: AgentRequestKey;
552
+ readonly digest: string;
553
+ readonly updatedAt: number;
554
+ }
555
+ type AgentRequestLedgerRecord = (AgentRequestLedgerRecordBase & {
556
+ readonly state: 'pending-admission';
557
+ }) | (AgentRequestLedgerRecordBase & {
558
+ readonly state: 'admission-accepted';
559
+ readonly admissionReceipt: string;
560
+ }) | (AgentRequestLedgerRecordBase & {
561
+ readonly state: 'in-flight';
562
+ }) | (AgentRequestLedgerRecordBase & {
563
+ readonly state: 'rejected';
564
+ readonly failure: AgentRequestFailure;
565
+ }) | (AgentRequestLedgerRecordBase & {
566
+ readonly state: 'completed';
567
+ readonly receipt: JsonValue;
568
+ }) | (AgentRequestLedgerRecordBase & {
569
+ readonly state: 'outcome-unknown';
570
+ readonly error: AgentGatewayErrorDTO;
571
+ });
572
+ interface AgentRequestLedger {
573
+ prepare(key: AgentRequestKey, digest: string): Promise<AgentRequestLedgerRecord>;
574
+ acceptAdmission(key: AgentRequestKey, admissionReceipt: string): Promise<void>;
575
+ beginEffect(key: AgentRequestKey): Promise<void>;
576
+ reject(key: AgentRequestKey, failure: AgentRequestFailure): Promise<void>;
577
+ complete(key: AgentRequestKey, receipt: JsonValue): Promise<void>;
578
+ markOutcomeUnknown(key: AgentRequestKey, error: AgentGatewayErrorDTO): Promise<void>;
579
+ read(key: AgentRequestKey): Promise<AgentRequestLedgerRecord | undefined>;
580
+ }
581
+ type AgentEffectAdmissionResult = {
582
+ readonly type: 'accepted';
583
+ readonly admissionReceipt: string;
584
+ } | {
585
+ readonly type: 'rejected';
586
+ readonly error: AgentGatewayErrorDTO;
587
+ } | {
588
+ readonly type: 'retryable';
589
+ readonly error: AgentGatewayErrorDTO;
590
+ };
591
+ interface AgentEffectAdmission {
592
+ /** Must be idempotent and reconcilable on the complete ledger key. */
593
+ admit(input: {
594
+ readonly key: AgentRequestKey;
595
+ readonly digest: string;
596
+ readonly scope: VerifiedAgentScopeClaim;
597
+ readonly operation: AgentGatewayEffect;
598
+ readonly target: AgentRequestTarget;
599
+ }): Promise<AgentEffectAdmissionResult>;
600
+ }
601
+ interface ConfiguredAgentHostAgentSpec {
602
+ readonly agentTypeId: string;
603
+ readonly definition: {
604
+ readonly instructions: string;
605
+ readonly label: string;
606
+ readonly version?: string;
607
+ };
608
+ readonly plugins?: readonly {
609
+ /** Canonical app-preflighted plugin ID. */
610
+ readonly name: string;
611
+ readonly config?: JsonValue;
612
+ }[];
613
+ readonly model?: {
614
+ readonly preferred?: string;
615
+ /** RESERVED / NOT ENFORCED. Per-turn token-limit enforcement is future work. */
616
+ readonly maxTokensPerTurn?: number;
617
+ };
618
+ }
619
+ interface LegacyDefaultAgentHostSpec {
620
+ readonly agentTypeId: 'default';
621
+ readonly legacyDefault: true;
622
+ }
623
+ type AgentHostAgentSpec = ConfiguredAgentHostAgentSpec | LegacyDefaultAgentHostSpec;
624
+ /**
625
+ * Server-only compiler output. App-specific validated handles may be attached,
626
+ * but the Host revalidates the complete agent ID set before freezing it.
627
+ */
628
+ type CompiledAgentHostAgentSpec = AgentHostAgentSpec & {
629
+ readonly resolvedPolicy?: Readonly<Record<string, unknown>>;
630
+ /** Required when resolvedPolicy contains opaque/non-JSON runtime handles. */
631
+ readonly resolvedPolicyDigest?: string;
632
+ };
633
+ interface AgentFleetCompiler {
634
+ compile(input: {
635
+ readonly agents: readonly AgentHostAgentSpec[];
636
+ }): Promise<readonly CompiledAgentHostAgentSpec[]>;
637
+ }
638
+ interface ResolvedEnvironmentScope {
639
+ readonly placementIdentity: string;
640
+ readonly workspaceRoot: string;
641
+ readonly templatePath?: string;
642
+ readonly provisioningFingerprint: string;
643
+ readonly provisionRuntime?: (input: {
644
+ readonly runtimeBundle: Awaited<ReturnType<RuntimeModeAdapter['create']>>;
645
+ readonly signal: AbortSignal;
646
+ }) => Promise<WorkspaceProvisioningResult | undefined>;
647
+ }
648
+ interface ResolvedAgentRuntimeScope {
649
+ /** Complete app-canonicalized PL1 composition identity. */
650
+ readonly identity: string;
651
+ readonly environment: ResolvedEnvironmentScope;
652
+ readonly sessionNamespace: string;
653
+ readonly pi?: PiHarnessOptions;
654
+ readonly extraTools?: readonly AgentTool[];
655
+ readonly getFilesystemBindings?: (input: {
656
+ readonly scope: VerifiedAgentScopeClaim;
657
+ readonly sessionId?: string;
658
+ readonly requestId: string;
659
+ }) => Promise<readonly RuntimeFilesystemBinding[] | undefined>;
660
+ readonly systemPromptAppend?: string;
661
+ readonly loadSystemPromptAppend?: () => Promise<string | undefined>;
662
+ }
663
+ interface AgentHostLegacyProjectionComposition {
664
+ readonly agent: Agent;
665
+ readonly harness: AgentHarness;
666
+ readonly service: AgentCoreSessionService;
667
+ readonly tools: readonly AgentTool[];
668
+ readonly runtimeBundle: RuntimeBundle;
669
+ readonly readyTracker: ReadyStatusTracker;
670
+ retire(): Promise<void>;
671
+ }
672
+ /** Narrow Host-owned facade used only while mounting the compatibility profile. */
673
+ interface AgentHostLegacyProjectionRuntime {
674
+ readonly gateway: AgentGateway;
675
+ resolveComposition(agentTypeId: string, scope: AuthorizedAgentScope): Promise<AgentHostLegacyProjectionComposition>;
676
+ createAddressedRoutes(options: {
677
+ readonly authorizeRequest: (request: FastifyRequest) => Promise<AuthorizedAgentScope>;
678
+ readonly defaultAgentTypeId: string;
679
+ }): FastifyPluginAsync;
680
+ createPiChatService(input: {
681
+ readonly service: AgentCoreSessionService;
682
+ readonly scope: AuthorizedAgentScope;
683
+ readonly agentTypeId: string;
684
+ }): PiChatSessionService;
685
+ }
686
+ interface AgentHostLegacyProjectionLifecycle {
687
+ startDraining(): void;
688
+ closeBindings(): Promise<void>;
689
+ }
690
+ interface AgentHostLegacyRoutePolicyMountInput {
691
+ readonly app: fastify.FastifyInstance;
692
+ readonly runtime: AgentHostLegacyProjectionRuntime;
693
+ readonly defaultAgentTypeId: string;
694
+ registerLifecycle(lifecycle: AgentHostLegacyProjectionLifecycle): void;
695
+ }
696
+ /**
697
+ * Normalized legacy/application route profile mounted only through the Host.
698
+ * Omission keeps the addressed-only HTTP projection.
699
+ */
700
+ interface AgentHostLegacyRoutePolicy {
701
+ mount(input: AgentHostLegacyRoutePolicyMountInput): Promise<void>;
702
+ }
703
+ interface AgentHostHttpProjectionBaseOptions {
704
+ readonly defaultAgentTypeId: string;
705
+ }
706
+ /** Addressed Gateway projection, optionally with its frozen Pi-chat aliases. */
707
+ type AgentHostAddressedHttpProjectionOptions = AgentHostHttpProjectionBaseOptions & {
708
+ readonly authorizeRequest: (request: FastifyRequest) => Promise<AuthorizedAgentScope>;
709
+ readonly legacyPiChatAliases?: boolean;
710
+ readonly legacyRoutePolicy?: never;
711
+ };
712
+ /** Full legacy/application route profile with its own normalized scope bridge. */
713
+ type AgentHostLegacyHttpProjectionOptions = AgentHostHttpProjectionBaseOptions & {
714
+ readonly legacyRoutePolicy: AgentHostLegacyRoutePolicy;
715
+ readonly authorizeRequest?: never;
716
+ readonly legacyPiChatAliases?: never;
717
+ };
718
+ type AgentHostHttpProjectionOptions = AgentHostAddressedHttpProjectionOptions | AgentHostLegacyHttpProjectionOptions;
719
+ interface AgentHostDescription {
720
+ readonly hostId: string;
721
+ readonly agents: readonly {
722
+ readonly agentTypeId: string;
723
+ readonly label: string;
724
+ }[];
725
+ readonly draining: boolean;
726
+ }
727
+ interface AgentHostHandle {
728
+ readonly hostId: string;
729
+ describe(): Promise<AgentHostDescription>;
730
+ drain(): Promise<void>;
731
+ close(): Promise<void>;
732
+ }
733
+ interface CreateAgentHostOptions {
734
+ readonly agents: readonly AgentHostAgentSpec[];
735
+ readonly fleetCompiler: AgentFleetCompiler;
736
+ readonly hostId?: string;
737
+ readonly scopeVerifier: AgentScopeVerifier;
738
+ readonly runtimeModeAdapter: RuntimeModeAdapter;
739
+ readonly runtimeHost?: AgentRuntimeHostOperations;
740
+ readonly sessionRoot?: string;
741
+ readonly resolveRuntimeScope: (input: {
742
+ readonly agentTypeId: string;
743
+ readonly scope: AuthorizedAgentScope;
744
+ }) => Promise<ResolvedAgentRuntimeScope>;
745
+ readonly telemetry?: TelemetrySink;
746
+ readonly metering?: AgentMeteringSink;
747
+ readonly requestLedger?: AgentRequestLedger;
748
+ readonly requestRetentionMs?: number;
749
+ readonly effectAdmission?: AgentEffectAdmission;
750
+ readonly shutdownGraceMs?: number;
751
+ readonly harnessFactory?: AgentHarnessFactory;
752
+ }
753
+ interface CreatedAgentHost {
754
+ readonly host: AgentHostHandle;
755
+ readonly gateway: AgentGateway;
756
+ registerRoutes(options: AgentHostHttpProjectionOptions): FastifyPluginAsync;
757
+ }
758
+
759
+ export { type PiPackageSource as $, type AgentGatewayEffect as A, type BuiltinRuntimeModeId as B, type CreateAgentHostOptions as C, type AgentHostHttpProjectionOptions as D, type AgentHostLegacyHttpProjectionOptions as E, type AgentHostLegacyProjectionComposition as F, type AgentHostLegacyProjectionLifecycle as G, type AgentHostLegacyProjectionRuntime as H, type AgentHostLegacyRoutePolicyMountInput as I, type ConfiguredAgentHostAgentSpec as J, type MeteringReleaseInput as K, type LegacyDefaultAgentHostSpec as L, type ModeContext as M, type MeteringReleaseReason as N, type MeteringReservationResult as O, type ProvisionWorkspaceRuntimeOptions as P, type MeteringReserveInput as Q, type RuntimeModeAdapter as R, type MeteringRunKind as S, type MeteringRunScope as T, type MeteringRunStatus as U, type MeteringSettleInput as V, type WorkspaceProvisioningResult as W, type MeteringUsage as X, type MeteringUsageInput as Y, PI_PACKAGE_RESOURCE_FILTERS as Z, type PiExtensionFactory as _, type RuntimeModeId as a, type PluginSkillSource as a0, type ResolvedEnvironmentScope as a1, type RuntimeFilesystemBindingOperations as a2, type RuntimeNodePackageSpec as a3, type RuntimeProvisioningContribution as a4, type RuntimePythonSpec as a5, type RuntimeTemplateContribution as a6, type WorkspaceProvisioningExecResult as a7, compactPiPackages as a8, createResourceSettingsManager as a9, mergePiPackageSources as aa, normalizeMeteringUsage as ab, piPackageSourceKey as ac, type AgentRuntimeHostOperations as b, type RuntimeBashStrategy as c, type RuntimeFilesystemStrategy as d, type WorkspaceProvisioningAdapter as e, type RuntimeBundle as f, type PiHarnessOptions as g, type AgentMeteringSink as h, type RuntimeFilesystemBinding as i, type MeteringErrorLogger as j, ReadyStatusTracker as k, type ResolvedAgentRuntimeScope as l, type CompiledAgentHostAgentSpec as m, type AgentRequestLedger as n, type AgentEffectAdmission as o, type AgentRequestKey as p, type CreatedAgentHost as q, type AgentFleetCompiler as r, type AgentRequestTarget as s, type AgentRequestLedgerRecord as t, type AgentRequestFailure as u, type AgentHostLegacyRoutePolicy as v, type AgentHostAddressedHttpProjectionOptions as w, type AgentHostAgentSpec as x, type AgentHostDescription as y, type AgentHostHandle as z };