@byok-sdk/client 0.8.1 → 0.9.0

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.
@@ -0,0 +1,58 @@
1
+ import { type AgentMessageContentType, type AgentMessageEgressRequirement, type AgentMessagePublishPayload } from '@byok-sdk/protocol';
2
+ import type { AgentRef } from '../agent-home';
3
+ export declare const AGENT_MESSAGE_DIRECTORY: string;
4
+ export declare const AGENT_MESSAGE_OUTBOX_FILENAME = "outbox-v1.jsonl";
5
+ export interface AgentMessageOutboxRecord {
6
+ readonly schema: 1;
7
+ readonly taskId: string;
8
+ readonly tenantId: string;
9
+ readonly agentRef: AgentRef;
10
+ readonly contract: string;
11
+ readonly messageId: string;
12
+ readonly cursor: number;
13
+ readonly contentType: AgentMessageContentType;
14
+ readonly body: string;
15
+ readonly contentHash: string;
16
+ readonly byteCount: number;
17
+ readonly createdAt: string;
18
+ readonly sessionRef?: string;
19
+ }
20
+ export declare class AgentMessageOutboxError extends Error {
21
+ constructor(message: string);
22
+ }
23
+ /** Agent-local, append-before-send outbox. Only exact accepted disposition retires bytes. */
24
+ export declare class AgentMessageOutbox {
25
+ readonly homeDir: string;
26
+ readonly outboxPath: string;
27
+ private readonly pendingByTask;
28
+ private readonly dispositionByTask;
29
+ private nextCursor;
30
+ private logEntries;
31
+ private writeTail;
32
+ private constructor();
33
+ static open(homeDir: string): Promise<AgentMessageOutbox>;
34
+ /** Re-open every existing Agent-local message outbox without following Agent-home symlinks. */
35
+ static recover(agentsRoot: string, tenantId: string): Promise<readonly AgentMessageOutbox[]>;
36
+ records(): readonly AgentMessageOutboxRecord[];
37
+ /** Activated records with no exact disposition yet; only these may be transport-replayed. */
38
+ retryableRecords(): readonly AgentMessageOutboxRecord[];
39
+ get(taskId: string): AgentMessageOutboxRecord | undefined;
40
+ appendDraft(input: {
41
+ readonly taskId: string;
42
+ readonly tenantId: string;
43
+ readonly agentRef: AgentRef;
44
+ readonly requirement: AgentMessageEgressRequirement;
45
+ readonly contentType: AgentMessageContentType;
46
+ readonly body: string;
47
+ readonly sessionRef?: string;
48
+ readonly maxPendingEvents: number;
49
+ readonly maxPendingBytes: number;
50
+ }): Promise<AgentMessageOutboxRecord>;
51
+ activate(taskId: string, sessionRef: string): Promise<AgentMessageOutboxRecord | undefined>;
52
+ publishPayload(record: AgentMessageOutboxRecord): AgentMessagePublishPayload;
53
+ applyDisposition(taskId: string, input: unknown): Promise<'accepted' | 'held' | 'refused' | 'mismatch' | 'unknown'>;
54
+ private load;
55
+ private appendEntry;
56
+ private compact;
57
+ private exclusive;
58
+ }
@@ -323,6 +323,31 @@ export interface ApprovalsRequestResult {
323
323
  approved: boolean;
324
324
  reason?: string;
325
325
  }
326
+ export interface AgentMessagePublishParams {
327
+ contextToken: string;
328
+ contentType: 'text/plain' | 'text/markdown';
329
+ body: string;
330
+ }
331
+ export declare function parseAgentMessagePublishParams(value: unknown): AgentMessagePublishParams | undefined;
332
+ export interface AgentMessagePublishResult {
333
+ messageId: string;
334
+ state: 'staged' | 'pending';
335
+ }
336
+ export interface AgentMemoryRecallParams {
337
+ contextToken: string;
338
+ path: string;
339
+ ifRevision?: string;
340
+ }
341
+ export interface AgentMemorySaveParams {
342
+ contextToken: string;
343
+ op: 'replace' | 'delete';
344
+ path: string;
345
+ expectedRevision: string;
346
+ content?: string;
347
+ }
348
+ /** Parser only validates the local IPC shape. Agent identity and memory root stay daemon-owned. */
349
+ export declare function parseAgentMemoryRecallParams(value: unknown): AgentMemoryRecallParams | undefined;
350
+ export declare function parseAgentMemorySaveParams(value: unknown): AgentMemorySaveParams | undefined;
326
351
  /**
327
352
  * Params for `assertion.issue`: a sibling local process (the host's own CLI,
328
353
  * installed alongside this daemon) asking the daemon to mint one short-lived,
@@ -18,6 +18,8 @@ import { type ProgressBatcherOptions } from './progress-batcher';
18
18
  import { type AgentEgressReliableAppendResult } from './agent-egress-controller';
19
19
  import { type AgentEgressStatus } from './agent-egress-policy';
20
20
  import { type AgentEgressSanitizer } from './agent-egress-sanitizer';
21
+ import { type AgentMemoryHostedProjection } from './agent-memory';
22
+ import type { AgentMemoryFilesystemHelperConfig } from './agent-memory-filesystem';
21
23
  import { type AgentContentReadRoot } from './agent-content-read';
22
24
  /**
23
25
  * Optional white-label product display info — purely opaque passthrough
@@ -100,6 +102,14 @@ export interface DaemonConfig {
100
102
  hostStorageRoot: string;
101
103
  projection?: AgentHomeProjection;
102
104
  };
105
+ /** Optional, one-way hosted projection. Without all guards it has zero network activity. */
106
+ agentMemory?: AgentMemoryHostedProjection;
107
+ /**
108
+ * Product-owned external secure-filesystem helper. The path must be absolute;
109
+ * the SDK never searches PATH or bundles a native addon. Required for Phase
110
+ * 2 on macOS. Windows remains fail-closed pending its native race proof.
111
+ */
112
+ agentMemoryFilesystem?: AgentMemoryFilesystemHelperConfig;
103
113
  /**
104
114
  * Refuse legacy task offers locally. This is an additive capability only
105
115
  * after the SDK-owned Agent home has passed construction-time preflight.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Runtime-neutral instructions for an Agent's model-authored local memory.
3
+ *
4
+ * This is deliberately prompt guidance only: the SDK does not read memory
5
+ * content, infer durable values, or auto-inject files into the operation.
6
+ */
7
+ export declare const AGENT_MEMORY_GUIDANCE: string;
8
+ export declare function prependAgentMemoryGuidance(instruction: string): string;
@@ -0,0 +1,6 @@
1
+ export interface ResolvedAgentMemoryMcpBin {
2
+ readonly command: string;
3
+ readonly args: readonly string[];
4
+ }
5
+ /** Resolve the SDK-owned stdio Agent-memory MCP helper shipped beside the client bundle. */
6
+ export declare function resolveAgentMemoryMcpBin(externalHelperConfigured?: boolean): ResolvedAgentMemoryMcpBin | undefined;
@@ -0,0 +1,6 @@
1
+ export interface ResolvedAgentMessageMcpBin {
2
+ readonly command: string;
3
+ readonly args: readonly string[];
4
+ }
5
+ /** Resolve the SDK-owned stdio MCP helper shipped beside the client bundle. */
6
+ export declare function resolveAgentMessageMcpBin(): ResolvedAgentMessageMcpBin;
@@ -1,4 +1,4 @@
1
- import { type AgentEgressPolicy, type Envelope, type PermissionPolicy, type RuntimeId, type TaskOfferPayload, type TaskOfferForAgentPayload, type TaskOfferForAgentWithEgressPayload, type TaskOfferForAgentWithEgressFreshPayload, type TaskOfferWithToolsetsPayload } from '@byok-sdk/protocol';
1
+ import { type AgentMessageContentType, type AgentEgressPolicy, type Envelope, type PermissionPolicy, type RuntimeId, type TerminalProjectionSelection, type TaskOfferPayload, type TaskOfferForAgentPayload, type TaskOfferForAgentWithEgressPayload, type TaskOfferForAgentWithEgressFreshPayload, type TaskOfferWithToolsetsPayload } from '@byok-sdk/protocol';
2
2
  import { type McpToolsetConfig, type RuntimeAdapter } from '../types';
3
3
  import { AgentHomeManager, type AgentRef } from '../agent-home';
4
4
  import { AgentSessionHandoffStore, type AgentTerminalCause } from './agent-session-handoff-store';
@@ -12,6 +12,9 @@ import type { SessionWorkspaceStore } from './session-workspace-store';
12
12
  import type { GitWorkspaceManager, GitWorkspaceObservation } from './git-workspace';
13
13
  import type { GitWorkspaceStore, GitWorkspacePhase } from './git-workspace-store';
14
14
  import type { AgentEgressController } from './agent-egress-controller';
15
+ import type { ResolvedAgentMessageMcpBin } from './resolve-agent-message-mcp-bin';
16
+ import type { ResolvedAgentMemoryMcpBin } from './resolve-agent-memory-mcp-bin';
17
+ import { type AgentMemoryAuditWarning, type AgentMemoryHostedProjection } from './agent-memory';
15
18
  /**
16
19
  * M4 Phase 3: default wait for `requestApproval` (see its own doc comment)
17
20
  * before force-resolving an unanswered out-of-band approval as a fail-closed
@@ -138,12 +141,15 @@ export declare const RESULT_DOCUMENT_UNDELIVERABLE_REASON_PREFIX = "result docum
138
141
  export interface ResultDocumentTask {
139
142
  readonly taskId: string;
140
143
  readonly sessionRef: string;
144
+ /** Exact offer-scoped second projection; absent for legacy and message-only offers. */
145
+ readonly terminalProjection?: Readonly<TerminalProjectionSelection>;
141
146
  }
142
147
  /**
143
148
  * Host-supplied glue that turns a finished task's final output into the
144
149
  * product's structured terminal result (`task.complete.document`). Returning
145
- * `undefined` means "this task has no structured result" and completes the
146
- * task exactly as it would have without an extractor configured at all.
150
+ * `undefined` means "this task has no structured result" for legacy offers.
151
+ * An explicit `terminalProjection.mode: 'result-document'` instead treats
152
+ * `undefined` as a fail-closed missing required document.
147
153
  *
148
154
  * SYNCHRONOUS by contract, like every other single-purpose callback on
149
155
  * `TaskRunnerDeps`, and the runtime ENFORCES that rather than trusting it:
@@ -258,6 +264,8 @@ export interface TaskRunnerDeps {
258
264
  approvalRegistry: ApprovalRegistry;
259
265
  storeDir: string;
260
266
  productId: string;
267
+ /** Authenticated enrollment tenant projection; required by Agent message durability/recovery. */
268
+ tenantId?: string;
261
269
  /**
262
270
  * The already-resolved, process-immutable U4a Local Agent release identity.
263
271
  * `TaskRunner` only consumes this value; it never creates, normalizes, or
@@ -359,6 +367,14 @@ export interface TaskRunnerDeps {
359
367
  resultDocument?: {
360
368
  readonly extract: ResultDocumentExtractor;
361
369
  };
370
+ /** SDK-owned, task-scoped MCP helper. Required only for offers declaring messageEgress. */
371
+ agentMessageMcpBin?: Readonly<ResolvedAgentMessageMcpBin>;
372
+ /** SDK-owned MCP helper injected only into strict Agent tasks. */
373
+ agentMemoryMcpBin?: Readonly<ResolvedAgentMemoryMcpBin>;
374
+ /** Explicit external secure-fs helper. No PATH discovery or bundled native addon exists. */
375
+ agentMemoryFilesystemHelperBin?: string;
376
+ /** Optional local-to-hosted redacted projection port. Omission is zero-network. */
377
+ agentMemoryHostedProjection?: AgentMemoryHostedProjection;
362
378
  }
363
379
  /** See {@link TaskRunnerDeps.admissionGuard}. */
364
380
  export type AdmissionGuardDecision = {
@@ -387,6 +403,16 @@ type AcceptedOfferPayload = TaskOfferPayload | TaskOfferWithToolsetsPayload | Ta
387
403
  export declare class TaskRunner {
388
404
  private readonly deps;
389
405
  private readonly tasks;
406
+ private readonly pendingMessageTasks;
407
+ private readonly messageContextByToken;
408
+ private readonly messageContextByTask;
409
+ private readonly memoryContextByToken;
410
+ private readonly memoryContextByTask;
411
+ private readonly memoryInFlightByTask;
412
+ private readonly memoryClosingTasks;
413
+ private readonly memoryFilesystemByTask;
414
+ private readonly recoveredMessageOutboxes;
415
+ private readonly recoveredMessageRetryTimers;
390
416
  /**
391
417
  * Finding F4 (cancel lost during the offer-processing window): a
392
418
  * `task.cancel` for a taskId that hasn't finished `handleOffer` yet (still
@@ -515,6 +541,44 @@ export declare class TaskRunner {
515
541
  * approval count, not the adapter's own event-queue depth.
516
542
  */
517
543
  getQueueWatermarks(): TaskQueueWatermark[];
544
+ /** Authenticated control-socket entry used only by the SDK-owned task MCP helper. */
545
+ publishAgentMessage(input: {
546
+ readonly contextToken: string;
547
+ readonly contentType: AgentMessageContentType;
548
+ readonly body: string;
549
+ }): Promise<{
550
+ messageId: string;
551
+ state: 'staged' | 'pending';
552
+ }>;
553
+ /** Authenticated control-socket entry used only by the SDK-owned memory MCP helper. */
554
+ recallAgentMemory(input: {
555
+ readonly contextToken: string;
556
+ readonly path: string;
557
+ readonly ifRevision?: string;
558
+ }): Promise<{
559
+ path: string;
560
+ revision: string;
561
+ content: string;
562
+ auditWarning?: AgentMemoryAuditWarning;
563
+ }>;
564
+ /** Authenticated control-socket entry used only by the SDK-owned memory MCP helper. */
565
+ saveAgentMemory(input: {
566
+ readonly contextToken: string;
567
+ readonly op: 'replace' | 'delete';
568
+ readonly path: string;
569
+ readonly expectedRevision: string;
570
+ readonly content?: string;
571
+ }): Promise<{
572
+ path: string;
573
+ revision?: string;
574
+ deleted: boolean;
575
+ }>;
576
+ /** Restore activated, unaccepted message drafts before transport admission on daemon restart. */
577
+ recoverAgentMessageOutboxes(agentsRoot: string): Promise<void>;
578
+ /** Retry stable recovered records after a transport handshake/re-handshake. */
579
+ retryRecoveredAgentMessages(): void;
580
+ private sendAgentMessageRecord;
581
+ private handleAgentMessageDisposition;
518
582
  /** M4 Phase 2: stop claiming any FUTURE `task.offer` — see `stoppingOffers`'s own doc comment. Idempotent. */
519
583
  stopAcceptingOffers(): void;
520
584
  /**
@@ -620,11 +684,23 @@ export declare class TaskRunner {
620
684
  private armMaxDurationTimer;
621
685
  handleEnvelope(envelope: Envelope): Promise<void>;
622
686
  private handleOffer;
687
+ private withAgentMessageMcp;
688
+ private revokeAgentMessageContext;
689
+ /** Injected only after strict Agent admission; a host registry may never replace this reserved name. */
690
+ private withAgentMemoryMcp;
691
+ /** Reconstruct all sensitive context from the active sealed task, never from MCP/model arguments. */
692
+ private activeMemoryContext;
693
+ private runMemoryOperation;
694
+ private quiesceAndSnapshotAgentMemory;
695
+ private bindAgentMemoryFilesystem;
696
+ private closeAgentMemoryFilesystem;
697
+ private revokeAgentMemoryContext;
623
698
  /** Protocol §7: an instruction too large to inline arrives as a `blobRef` — resolve it via the blob client rather than failing closed. */
624
699
  private resolveInstruction;
625
700
  /** Resolve every requested logical id locally and reject missing/colliding server authority before claim. */
626
701
  private resolveMcpServers;
627
702
  private pump;
703
+ private publishSuccessfulCompletion;
628
704
  /**
629
705
  * Protocol §7: an `artifact` `AgentEvent` only names a file the runtime
630
706
  * wrote into the task workspace (`name`/`contentType` — it carries no
@@ -1,5 +1,7 @@
1
1
  import { type ToolsetId } from '@byok-sdk/protocol';
2
2
  import type { McpToolsetConfig, McpToolsetObservation, McpToolsetRegistryStatus, McpToolsetReloadReceipt } from '../types';
3
+ export declare const AGENT_MESSAGE_MCP_SERVER_NAME = "byokagentmessage";
4
+ export declare const AGENT_MEMORY_MCP_SERVER_NAME = "byokagentmemory";
3
5
  export type McpToolsetConfigInput = Record<string, McpToolsetConfig> | undefined;
4
6
  export interface McpToolsetRegistrySnapshot {
5
7
  revision: string;
package/dist/index.d.ts CHANGED
@@ -18,6 +18,9 @@ export { GitWorkspaceStore } from './daemon/git-workspace-store';
18
18
  export type { GitWorkspaceLedger, GitWorkspaceLedgerRecord, GitWorkspacePhase } from './daemon/git-workspace-store';
19
19
  export { createDaemon, createDaemonWithAdapters } from './daemon/create-daemon';
20
20
  export type { Daemon, DaemonConfig, DaemonStatus, DaemonOverrides, DaemonBranding, HostedJournalConfig, DeviceAssertionConfig, AgentEgressConfig, AgentContentReadConfig, AgentContentReadSurfaceConfig, AgentReliableEgressInput, } from './daemon/create-daemon';
21
+ export { AgentMemoryError, AgentMemoryRevisionConflictError, isAgentMemorySecureFilesystemAvailable, AGENT_MEMORY_AUDIT_FILENAME, AGENT_MEMORY_OUTBOX_FILENAME, } from './daemon/agent-memory';
22
+ export type { AgentMemoryFilesystemHelperConfig } from './daemon/agent-memory-filesystem';
23
+ export type { AgentMemoryFile, AgentMemorySnapshot, AgentMemoryRedactor, AgentMemoryProjectionGrant, AgentMemoryProjectionPort, AgentMemoryHostedProjection, } from './daemon/agent-memory';
21
24
  export type { AgentEgressDropReceipt, AgentEgressLaneStatus, AgentEgressStatus, } from './daemon/agent-egress-policy';
22
25
  export type { AgentEgressSanitizer, AgentEgressSanitizerContext } from './daemon/agent-egress-sanitizer';
23
26
  export { AGENT_CONTENT_READ_CAPABILITIES, AGENT_CONTENT_READ_CAPABILITY_WORKSPACE, AGENT_CONTENT_READ_CAPABILITY_TRANSCRIPT, AGENT_CONTENT_READ_CAPABILITY_ARTIFACT, } from './daemon/agent-content-read';