@a3s-lab/code 3.2.0 → 3.3.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.
Files changed (2) hide show
  1. package/generated.d.ts +170 -0
  2. package/package.json +7 -7
package/generated.d.ts CHANGED
@@ -568,6 +568,35 @@ export interface SessionOptions {
568
568
  * ```
569
569
  */
570
570
  sessionId?: string
571
+ /**
572
+ * Host-defined tenant id. Opaque to the framework — propagated to
573
+ * SessionData, hooks, and traces for multi-tenant aggregation /
574
+ * billing. Pair with `principal` / `agentTemplateId` /
575
+ * `correlationId` for full identity context.
576
+ */
577
+ tenantId?: string
578
+ /**
579
+ * Identity of the principal (user / service / etc.) that triggered
580
+ * this session. Treated as opaque.
581
+ */
582
+ principal?: string
583
+ /**
584
+ * Logical identifier of the agent template / definition the session
585
+ * was instantiated from.
586
+ */
587
+ agentTemplateId?: string
588
+ /**
589
+ * Distributed-trace correlation id propagated through this
590
+ * session's events.
591
+ */
592
+ correlationId?: string
593
+ /**
594
+ * Optional FIFO retention caps on the session's in-memory stores.
595
+ * Cap any subset; missing fields keep the unbounded default for
596
+ * that store. Use this to stop long-running cluster sessions
597
+ * from leaking memory in the run / trace / subagent trackers.
598
+ */
599
+ retentionLimits?: RetentionLimitsObject
571
600
  /** Automatically save the session to the configured store after each turn (default: false). */
572
601
  autoSave?: boolean
573
602
  /**
@@ -716,6 +745,50 @@ export interface McpServerStatusEntry {
716
745
  toolCount: number
717
746
  error?: string
718
747
  }
748
+ /**
749
+ * Shape of the JS handlers object accepted by `session.setBudgetGuard`.
750
+ * Each field is optional — methods that aren't provided fall back to
751
+ * the framework's default Allow / no-op behaviour.
752
+ */
753
+ export interface BudgetGuardHandlers {
754
+ checkBeforeLlm?: (...args: any[]) => any
755
+ recordAfterLlm?: (...args: any[]) => any
756
+ checkBeforeTool?: (...args: any[]) => any
757
+ /**
758
+ * Max time (ms) to wait for a `check*` callback to return before
759
+ * the guard fails **closed** (denies). Default 5000. A guard that
760
+ * throws (so its return value never arrives) or hangs is denied
761
+ * after this deadline — budget enforcement never silently
762
+ * disables itself.
763
+ */
764
+ timeoutMs?: number
765
+ }
766
+ /**
767
+ * FIFO retention caps on the session's in-memory stores. All fields
768
+ * optional; missing fields keep the unbounded default for that
769
+ * store. Use to cap memory growth across long-running cluster
770
+ * sessions.
771
+ */
772
+ export interface RetentionLimitsObject {
773
+ /**
774
+ * Cap on the number of runs retained in InMemoryRunStore.
775
+ * When exceeded the oldest run is dropped along with its events.
776
+ */
777
+ maxRunsRetained?: number
778
+ /**
779
+ * Cap on event records retained per run. Oldest events
780
+ * FIFO-dropped from each run's buffer past this cap. The
781
+ * snapshot's cumulative `eventCount` is not decremented.
782
+ */
783
+ maxEventsPerRun?: number
784
+ /** Cap on events retained in InMemoryTraceSink. */
785
+ maxTraceEvents?: number
786
+ /**
787
+ * Cap on **terminal** (Completed / Failed / Cancelled) subagent
788
+ * task snapshots. Running tasks are never evicted.
789
+ */
790
+ maxTerminalSubagentTasks?: number
791
+ }
719
792
  /** MCP server metadata exposed to slash command handlers. */
720
793
  export interface CommandMcpServerInfo {
721
794
  /** MCP server name. */
@@ -1076,6 +1149,45 @@ export declare class Agent {
1076
1149
  * @param options - Optional session overrides layered on top of the worker definition
1077
1150
  */
1078
1151
  sessionForWorker(workspace: string, worker: WorkerAgentSpec, options?: SessionOptions | undefined | null): Session
1152
+ /**
1153
+ * List session IDs for every live session created from this agent.
1154
+ *
1155
+ * Sessions that have been dropped (no JS-side references remain) are
1156
+ * pruned lazily on each call. Result is sorted for stable output.
1157
+ */
1158
+ listSessions(): Promise<Array<string>>
1159
+ /**
1160
+ * Close a specific live session by its session ID.
1161
+ *
1162
+ * Returns `true` when a live session with the given id was found and
1163
+ * transitioned from open to closed by this call; `false` when no live
1164
+ * session has that id, or when it was already closed.
1165
+ *
1166
+ * Equivalent to calling `session.close()` directly, but does not
1167
+ * require holding a reference to the session — handy for control-plane
1168
+ * code that only knows the session ID.
1169
+ */
1170
+ closeSession(sessionId: string): Promise<boolean>
1171
+ /**
1172
+ * Close every live session created from this agent and disconnect
1173
+ * background resources owned by the agent (global MCP connections).
1174
+ *
1175
+ * After this call, `agent.session(...)` and `agent.resumeSession(...)`
1176
+ * reject with a "Session closed" error. Idempotent.
1177
+ */
1178
+ close(): Promise<void>
1179
+ /** Whether `close()` has been called on this agent. */
1180
+ isClosed(): boolean
1181
+ /**
1182
+ * Disconnect every global MCP server idle longer than
1183
+ * `idleThresholdMs`, returning the names disconnected. The server's
1184
+ * registered config is kept — a later tool call reconnects on
1185
+ * demand. Call periodically (e.g. every 60s with a 5-min threshold)
1186
+ * from a host-side sweeper to release file descriptors and
1187
+ * background workers from quiet MCP servers in long-running
1188
+ * deployments.
1189
+ */
1190
+ disconnectIdleMcp(idleThresholdMs: number): Promise<Array<string>>
1079
1191
  }
1080
1192
  /** Workspace-bound session. All LLM and tool operations happen here. */
1081
1193
  export declare class Session {
@@ -1088,6 +1200,19 @@ export declare class Session {
1088
1200
  send(request: string | SessionRequestOptions, history?: Array<MessageObject> | null): Promise<AgentResult>
1089
1201
  /** Alias for `send(...)` with a name that matches run/replay terminology. */
1090
1202
  run(request: string | SessionRequestOptions, history?: Array<MessageObject> | null): Promise<AgentResult>
1203
+ /**
1204
+ * Resume a previously-checkpointed run on this session.
1205
+ *
1206
+ * Loads the latest loop checkpoint stored under `checkpointRunId`
1207
+ * from the configured `SessionStore` and replays the agent loop
1208
+ * from that boundary. A new run id is allocated for the resumed
1209
+ * work; the relationship between the old and new run is host
1210
+ * metadata.
1211
+ *
1212
+ * Rejects when the session has no `sessionStore` configured, or
1213
+ * when no checkpoint exists for `checkpointRunId`.
1214
+ */
1215
+ resumeRun(checkpointRunId: string): Promise<AgentResult>
1091
1216
  /**
1092
1217
  * Send a prompt or request and get a streaming event iterator.
1093
1218
  *
@@ -1387,6 +1512,14 @@ export declare class Session {
1387
1512
  get workspace(): string
1388
1513
  /** Return any deferred init warning (e.g. memory store failed to initialize). */
1389
1514
  get initWarning(): string | null
1515
+ /** Host-defined tenant id attached at session creation, if any. */
1516
+ get tenantId(): string | null
1517
+ /** Identity of the principal that triggered the session, if any. */
1518
+ get principal(): string | null
1519
+ /** Logical agent template / definition id, if any. */
1520
+ get agentTemplateId(): string | null
1521
+ /** Distributed-trace correlation id propagated through this session, if any. */
1522
+ get correlationId(): string | null
1390
1523
  /** Save the session to the configured store. */
1391
1524
  save(): Promise<void>
1392
1525
  /** Check if memory is configured for this session. */
@@ -1509,4 +1642,41 @@ export declare class Session {
1509
1642
  * cleanly without waiting on session-scoped background workers.
1510
1643
  */
1511
1644
  close(): void
1645
+ /**
1646
+ * Whether [`close`](#method.close) has been called on this session.
1647
+ *
1648
+ * Once `true`, calls to `send` / `stream` reject with a "Session closed"
1649
+ * error instead of starting a new run.
1650
+ */
1651
+ isClosed(): boolean
1652
+ /**
1653
+ * Install a host-supplied BudgetGuard on this session.
1654
+ *
1655
+ * Each callback receives a single context object:
1656
+ * - `checkBeforeLlm({ sessionId, estimatedTokens }) -> BudgetDecision | null`
1657
+ * - `recordAfterLlm({ sessionId, usage }) -> void`
1658
+ * - `checkBeforeTool({ sessionId, toolName }) -> BudgetDecision | null`
1659
+ *
1660
+ * where `BudgetDecision` is one of:
1661
+ * - `null` / `{ decision: 'allow' }` → allow
1662
+ * - `{ decision: 'soft', resource, consumed, limit, message? }` → emits BudgetThresholdHit('soft'), proceeds
1663
+ * - `{ decision: 'deny', resource, reason }` → aborts the call, throws "Budget exhausted"
1664
+ *
1665
+ * FAIL-CLOSED on hang: a `check*` callback that does not return
1666
+ * within `timeoutMs` (default 5000) is treated as a **deny**, never
1667
+ * a silent allow — a budget control must not disable itself when the
1668
+ * guard stalls. A malformed/unreadable return likewise denies.
1669
+ *
1670
+ * ⚠吅 The callbacks MUST NOT throw. Due to a napi-rs limitation a JS
1671
+ * exception thrown from a budget-guard callback aborts the host
1672
+ * process (the return value cannot be converted). Wrap your logic in
1673
+ * try/catch and return a decision (e.g. a deny) instead of throwing.
1674
+ * (The Python SDK's BudgetGuard catches exceptions safely; only the
1675
+ * Node binding has this constraint.)
1676
+ *
1677
+ * The guard takes effect on the next `send` / `stream`. Pass `null`
1678
+ * for a method to leave it unhandled (default allow / no-op). Pass
1679
+ * `null` for the whole handlers arg to clear the guard.
1680
+ */
1681
+ setBudgetGuard(handlers: { checkBeforeLlm?: ((ctx: { sessionId: string; estimatedTokens: number }) => any) | null; recordAfterLlm?: ((ctx: { sessionId: string; usage: any }) => void) | null; checkBeforeTool?: ((ctx: { sessionId: string; toolName: string }) => any) | null; timeoutMs?: number | null } | null): void
1512
1682
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a3s-lab/code",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "A3S Code - Native Node.js bindings for the coding-agent runtime",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -43,11 +43,11 @@
43
43
  "test:helpers": "node test-helpers.mjs"
44
44
  },
45
45
  "optionalDependencies": {
46
- "@a3s-lab/code-darwin-arm64": "3.2.0",
47
- "@a3s-lab/code-linux-x64-gnu": "3.2.0",
48
- "@a3s-lab/code-linux-x64-musl": "3.2.0",
49
- "@a3s-lab/code-linux-arm64-gnu": "3.2.0",
50
- "@a3s-lab/code-linux-arm64-musl": "3.2.0",
51
- "@a3s-lab/code-win32-x64-msvc": "3.2.0"
46
+ "@a3s-lab/code-darwin-arm64": "3.3.0",
47
+ "@a3s-lab/code-linux-x64-gnu": "3.3.0",
48
+ "@a3s-lab/code-linux-x64-musl": "3.3.0",
49
+ "@a3s-lab/code-linux-arm64-gnu": "3.3.0",
50
+ "@a3s-lab/code-linux-arm64-musl": "3.3.0",
51
+ "@a3s-lab/code-win32-x64-msvc": "3.3.0"
52
52
  }
53
53
  }