@opengeni/runtime 0.14.1 → 0.14.15

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 (79) hide show
  1. package/dist/{chunk-4YJ5Z52Z.js → chunk-7E2ZSCZK.js} +6 -6
  2. package/dist/{chunk-4YJ5Z52Z.js.map → chunk-7E2ZSCZK.js.map} +1 -1
  3. package/dist/{chunk-HHWIZHQM.js → chunk-GNEGANUF.js} +942 -300
  4. package/dist/chunk-GNEGANUF.js.map +1 -0
  5. package/dist/codex-tool-search.d.ts +100 -0
  6. package/dist/context-compaction.d.ts +236 -0
  7. package/dist/history-sanitizer.d.ts +320 -0
  8. package/dist/index.d.ts +186 -718
  9. package/dist/index.js +612 -126
  10. package/dist/index.js.map +1 -1
  11. package/dist/{localSources-T3HZ6KY4.js → localSources-BXHBKGF4.js} +2 -2
  12. package/dist/mcp-network.d.ts +32 -35
  13. package/dist/metrics.d.ts +33 -0
  14. package/dist/sandbox/capabilities.d.ts +11 -0
  15. package/dist/sandbox/channel-a.d.ts +226 -0
  16. package/dist/sandbox/display-stack.d.ts +99 -0
  17. package/dist/sandbox/errors.d.ts +16 -0
  18. package/dist/sandbox/exec-banner.d.ts +19 -0
  19. package/dist/sandbox/index.d.ts +190 -6
  20. package/dist/sandbox/index.js +20 -4
  21. package/dist/sandbox/op-correlation.d.ts +24 -0
  22. package/dist/sandbox/provider-errors.d.ts +32 -0
  23. package/dist/sandbox/provider-operation-gate.d.ts +12 -0
  24. package/dist/sandbox/providers/blaxel.d.ts +2 -0
  25. package/dist/sandbox/providers/cloudflare.d.ts +2 -0
  26. package/dist/sandbox/providers/daytona.d.ts +2 -0
  27. package/dist/sandbox/providers/docker.d.ts +2 -0
  28. package/dist/sandbox/providers/e2b.d.ts +2 -0
  29. package/dist/sandbox/providers/index.d.ts +11 -0
  30. package/dist/sandbox/providers/local.d.ts +2 -0
  31. package/dist/sandbox/providers/modal.d.ts +132 -0
  32. package/dist/sandbox/providers/none.d.ts +2 -0
  33. package/dist/sandbox/providers/runloop.d.ts +2 -0
  34. package/dist/sandbox/providers/selfhosted.d.ts +2 -0
  35. package/dist/sandbox/providers/types.d.ts +30 -0
  36. package/dist/sandbox/providers/vercel.d.ts +2 -0
  37. package/dist/sandbox/recording.d.ts +80 -0
  38. package/dist/sandbox/routing/backend-resolver.d.ts +173 -0
  39. package/dist/sandbox/routing/routing-session.d.ts +401 -0
  40. package/dist/sandbox/run-credentials.d.ts +65 -0
  41. package/dist/sandbox/select.d.ts +120 -0
  42. package/dist/sandbox/selfhosted/capabilities.d.ts +91 -0
  43. package/dist/sandbox/selfhosted/control-rpc.d.ts +175 -0
  44. package/dist/sandbox/selfhosted/fault-rendering.d.ts +40 -0
  45. package/dist/sandbox/selfhosted/op-observer.d.ts +40 -0
  46. package/dist/sandbox/selfhosted/op-stream.d.ts +104 -0
  47. package/dist/sandbox/selfhosted/op-testing.d.ts +108 -0
  48. package/dist/sandbox/selfhosted/op-transport.d.ts +60 -0
  49. package/dist/sandbox/selfhosted/retry-policy.d.ts +106 -0
  50. package/dist/sandbox/selfhosted/session.d.ts +552 -0
  51. package/dist/sandbox/selfhosted/testing.d.ts +48 -0
  52. package/dist/sandbox/stream-port.d.ts +80 -0
  53. package/dist/sandbox/stream-token.d.ts +44 -0
  54. package/dist/sandbox/terminal-server.d.ts +67 -0
  55. package/dist/sandbox/toolspace-token.d.ts +23 -0
  56. package/dist/sandbox/turn-tool-cancellation.d.ts +72 -0
  57. package/dist/sandbox/workspace-archive.d.ts +39 -0
  58. package/dist/sandbox-computer.d.ts +227 -0
  59. package/dist/screenshot-error-card.d.ts +1 -0
  60. package/dist/skill-library.d.ts +10 -12
  61. package/dist/usage-telemetry.d.ts +45 -0
  62. package/dist/workspace-skills.d.ts +31 -0
  63. package/package.json +7 -7
  64. package/src/context-compaction.ts +600 -6
  65. package/src/history-sanitizer.ts +10 -92
  66. package/src/index.ts +301 -62
  67. package/src/sandbox/channel-a.ts +267 -81
  68. package/src/sandbox/index.ts +56 -94
  69. package/src/sandbox/provider-operation-gate.ts +110 -0
  70. package/src/sandbox/providers/docker.ts +13 -1
  71. package/src/sandbox/providers/modal.ts +433 -3
  72. package/src/sandbox/routing/routing-session.ts +84 -8
  73. package/src/sandbox/selfhosted/session.ts +7 -6
  74. package/src/sandbox/turn-tool-cancellation.ts +47 -7
  75. package/src/sandbox/workspace-archive.ts +176 -73
  76. package/src/sandbox-computer.ts +25 -75
  77. package/dist/chunk-HHWIZHQM.js.map +0 -1
  78. package/dist/index-BraazrAO.d.ts +0 -2931
  79. /package/dist/{localSources-T3HZ6KY4.js.map → localSources-BXHBKGF4.js.map} +0 -0
@@ -0,0 +1,108 @@
1
+ import { ControlRequest, ControlResponse, OpAck, OpFrame, type AgentError, type OpExit } from "@opengeni/agent-proto";
2
+ import type { ControlRpc } from "./control-rpc";
3
+ import { type OpStreamSubscription, type OpStreamTransport } from "./op-transport";
4
+ /**
5
+ * An in-memory `OpStreamTransport`: subscriptions are a subject→handler map,
6
+ * and everything the CLIENT publishes (its acks) is recorded for assertions
7
+ * and mirrored to `onPublish` (the fake runner's ack intake). `available =
8
+ * false` makes both primitives throw `OpStreamUnavailableError` — the
9
+ * legacy-fallback path.
10
+ */
11
+ export declare class InMemoryOpStreamTransport implements OpStreamTransport {
12
+ available: boolean;
13
+ readonly published: Array<{
14
+ subject: string;
15
+ payload: Uint8Array;
16
+ }>;
17
+ onPublish: ((subject: string, payload: Uint8Array) => void) | undefined;
18
+ private readonly handlers;
19
+ subscribe(subject: string, onMessage: (payload: Uint8Array) => void): Promise<OpStreamSubscription>;
20
+ publish(subject: string, payload: Uint8Array): Promise<void>;
21
+ /** Deliver a payload to the subject's subscribers (the runner→client leg). */
22
+ deliver(subject: string, payload: Uint8Array): void;
23
+ /** Every OpAck the client published, decoded, in publish order. */
24
+ decodedAcks(): OpAck[];
25
+ }
26
+ /** One scripted data frame (the exit frame is synthesized from `exit`). */
27
+ export interface FakeOpDataFrame {
28
+ channel: "stdout" | "stderr";
29
+ bytes: Uint8Array | string;
30
+ }
31
+ export interface FakeOpScript {
32
+ /** Data/progress frames in emission order (seq 1..N; the exit takes N+1). */
33
+ frames: Array<FakeOpDataFrame | "progress">;
34
+ /** Exit overrides (exitCode/timedOut/failureCode/…). Digests and totals are
35
+ * computed from the scripted data frames unless overridden. */
36
+ exit?: Partial<OpExit>;
37
+ /** LIVE mode: the first attach replays nothing and triggers the (faulty)
38
+ * live emission; later attaches replay from retention unfiltered. Default
39
+ * false = the op is COMPLETE at start (pure collection). */
40
+ live?: boolean;
41
+ /** Keep a live op RUNNING with no frames until OpCancel is received. */
42
+ holdUntilCancel?: boolean;
43
+ /** Seqs whose LIVE emission is dropped (retention keeps them). */
44
+ dropLiveSeqs?: ReadonlySet<number>;
45
+ /** Seqs whose LIVE emission is duplicated (delivered twice back-to-back). */
46
+ duplicateLiveSeqs?: ReadonlySet<number>;
47
+ /** Swap each adjacent live pair (1,2 → 2,1) to exercise the stash path. */
48
+ reorderLivePairs?: boolean;
49
+ /** The first N OpStarts answer a DRAINING AgentError (admission pressure). */
50
+ drainingStarts?: number;
51
+ /** Refuse every OpStart with this error (e.g. a PROTOCOL refusal from a
52
+ * runner that does not speak op-stream — the legacy-fallback race). */
53
+ startError?: AgentError;
54
+ }
55
+ interface FakeOpRun {
56
+ script: FakeOpScript;
57
+ frames: OpFrame[];
58
+ exitSeq: bigint;
59
+ exit: OpExit;
60
+ startCount: number;
61
+ attachCount: number;
62
+ drainingRemaining: number;
63
+ liveEmitted: boolean;
64
+ finalAcked: boolean;
65
+ acks: OpAck[];
66
+ highestGeneration: bigint;
67
+ }
68
+ /**
69
+ * The scripted fake runner: a `ControlRpc` that answers the op-stream control
70
+ * ops and emits frames through an `InMemoryOpStreamTransport`. Non-op-stream
71
+ * requests are delegated to `fallback` (a `MockAgentResponder`) so the
72
+ * legacy-fallback path is testable through the same instance.
73
+ */
74
+ export declare class FakeOpRunner implements ControlRpc {
75
+ private readonly transport;
76
+ private readonly fallback;
77
+ private readonly workspaceId;
78
+ private readonly agentId;
79
+ private readonly scripts;
80
+ readonly runs: Map<string, FakeOpRun>;
81
+ /** Op ids that answer LOST (evicted) on query/attach — bounded-retention
82
+ * collateral. */
83
+ readonly lostOps: Set<string>;
84
+ private readonly cancelledBeforeStart;
85
+ constructor(opts: {
86
+ transport: InMemoryOpStreamTransport;
87
+ workspaceId: string;
88
+ agentId: string;
89
+ /** Handles every non-op-stream ControlRequest (the legacy ops). */
90
+ fallback?: ControlRpc;
91
+ });
92
+ /** Script the op the NEXT OpStart with this id will run. */
93
+ script(opId: string, script: FakeOpScript): void;
94
+ private onAck;
95
+ request(subject: string, req: ControlRequest, opts: {
96
+ timeoutMs: number;
97
+ }): Promise<ControlResponse>;
98
+ private handleStart;
99
+ private handleAttach;
100
+ private handleQuery;
101
+ private handleCancel;
102
+ /** The LIVE flow: fault filters applied (drops, duplicates, adjacent
103
+ * reordering); retention still holds every frame for the heal replay. */
104
+ private emitLive;
105
+ private statusOf;
106
+ private buildRun;
107
+ }
108
+ export {};
@@ -0,0 +1,60 @@
1
+ /** The per-op frame subject (runner→server, fire-and-forget). Mirrors the
2
+ * runner's wire constant: `agent.<ws>.<id>.op.<op_id>`. */
3
+ export declare function opFrameSubject(workspaceId: string, agentId: string, opId: string): string;
4
+ /** The per-agent ack subject (server→runner, fire-and-forget). Mirrors the
5
+ * runner's wire constant: `agent.<ws>.<id>.ack`. */
6
+ export declare function opAckSubject(workspaceId: string, agentId: string): string;
7
+ /** A live subscription handle. `unsubscribe` is idempotent and never throws. */
8
+ export interface OpStreamSubscription {
9
+ unsubscribe(): void;
10
+ }
11
+ /**
12
+ * The op-stream transport seam. `subscribe` MUST be established before the
13
+ * OpStart that makes frames flow (subscription-before-start is a protocol
14
+ * invariant: no frame is published before the consumer exists on a healthy
15
+ * path; a missed frame is healed via OpAttach replay regardless). `onMessage`
16
+ * is invoked in arrival order; a decode failure inside the handler must be
17
+ * contained by the caller (a torn frame must never kill the subscription).
18
+ */
19
+ export interface OpStreamTransport {
20
+ subscribe(subject: string, onMessage: (payload: Uint8Array) => void): Promise<OpStreamSubscription>;
21
+ publish(subject: string, payload: Uint8Array): Promise<void>;
22
+ }
23
+ /** Thrown when the transport has no live connection: the op-stream path is
24
+ * UNAVAILABLE (never silently degraded). The session catches this pre-start
25
+ * and falls back to the legacy exec — the op provably never started. */
26
+ export declare class OpStreamUnavailableError extends Error {
27
+ readonly name = "OpStreamUnavailableError";
28
+ }
29
+ /**
30
+ * The minimal NATS surface the transport needs — mirrors the `nats`
31
+ * `NatsConnection` subscribe/publish WITHOUT importing `nats` into the
32
+ * agent-loop-free runtime leaf (the worker injects the live `@opengeni/events`
33
+ * bus connection, exactly like `NatsRequestConnection` in control-rpc.ts).
34
+ * `subscribe` returns the nats.js Subscription shape: an async iterable of
35
+ * messages plus `unsubscribe()`.
36
+ */
37
+ export interface NatsOpStreamConnection {
38
+ subscribe(subject: string): AsyncIterable<{
39
+ data: Uint8Array;
40
+ }> & {
41
+ unsubscribe(): void;
42
+ };
43
+ publish(subject: string, payload: Uint8Array): void;
44
+ }
45
+ /**
46
+ * The NATS-backed transport. Lazy memoized factory (identical discipline to
47
+ * `NatsControlRpc`): the connection resolves on first use; a null factory
48
+ * result or a dial failure surfaces `OpStreamUnavailableError` — the caller
49
+ * (the session) falls back to the LEGACY exec path rather than failing the op,
50
+ * so a NATS-less boot or a torn bus never strands a turn on a dead transport.
51
+ */
52
+ export declare class NatsOpStreamTransport implements OpStreamTransport {
53
+ private readonly connect;
54
+ private connection;
55
+ private connecting;
56
+ constructor(connect: () => Promise<NatsOpStreamConnection | null>);
57
+ private resolveConnection;
58
+ subscribe(subject: string, onMessage: (payload: Uint8Array) => void): Promise<OpStreamSubscription>;
59
+ publish(subject: string, payload: Uint8Array): Promise<void>;
60
+ }
@@ -0,0 +1,106 @@
1
+ import type { SelfhostedControlError } from "./control-rpc";
2
+ /**
3
+ * The read-only, idempotent-safe control ops that MAY be retried after a TIMEOUT
4
+ * / `agent_reconnecting` blip.
5
+ *
6
+ * A timed-out request is AT-LEAST-ONCE on the wire: the agent may have RECEIVED
7
+ * and fully EXECUTED the op before its reply was lost, so re-issuing it is only
8
+ * safe when a second execution is observably identical to one — i.e. a pure read.
9
+ * Every MUTATING op (`exec`, `git`, `fsWrite`/`fsMove`/`fsMkdir`/`fsRemove`, and
10
+ * the pty/desktop input ops) is DELIBERATELY EXCLUDED: re-running a mutation that
11
+ * already ran on the machine is a real correctness hazard (a duplicated write, a
12
+ * second `git push`, a re-applied command). Only DRAINING (a pre-admission
13
+ * rejection — see `decideSelfhostedRetry`) is safe to retry for those.
14
+ */
15
+ export declare const SELFHOSTED_IDEMPOTENT_READONLY_OPS: ReadonlySet<string>;
16
+ /**
17
+ * DRAINING is a pre-admission backpressure rejection (the op never started), so it
18
+ * is safe to retry for ANY op kind. The budget is split by op class:
19
+ *
20
+ * - NON-EXEC control ops (fs/git/desktop/pty) keep a SHORT budget — 3 retries,
21
+ * worst-case backoff 500+1000+2000 = 3.5s (≤5s). Their start latency matters
22
+ * (fs/git ops gate the model's next step), so a saturated machine should surface
23
+ * quickly rather than stall.
24
+ * - EXEC gets a LONG, patient budget — 10 retries, worst-case ≈55.5s (<60s). exec
25
+ * start is not latency-critical, and the agent-side admission pool is (until a
26
+ * later agent release) a FLAT 8 permits with no per-class split: a burst of slow
27
+ * execs can hold every permit and blanket-DRAIN all fs/git ops. A patient exec
28
+ * retry converts those DRAINING storms into mild queueing instead of a wall of
29
+ * failed tool calls, and pairs with the deliberately modest exec deadline (which,
30
+ * for the same 8-permit reason, defaults to 2min, not 5).
31
+ */
32
+ export declare const SELFHOSTED_DRAINING_MAX_RETRIES = 3;
33
+ export declare const SELFHOSTED_EXEC_DRAINING_MAX_RETRIES = 10;
34
+ /** A read-only op that timed out is retried at most once (see the at-least-once
35
+ * note above — even a read gets a single re-issue, not an unbounded loop). */
36
+ export declare const SELFHOSTED_TIMEOUT_MAX_RETRIES = 1;
37
+ /** A fault the transport synthesized PRE-SEND (no connection / no responder) — the
38
+ * op provably never reached the machine, so it is safe to re-issue for ANY op kind.
39
+ * Short bounded budget (≈3.5s summed): enough to ride out a NATS reconnect blip
40
+ * quietly, not so long it stalls the model on a machine that is genuinely down. */
41
+ export declare const SELFHOSTED_NEVER_SENT_MAX_RETRIES = 3;
42
+ /** Full-jitter backoff base (ms). Delay N is sampled in `[0, base * factor^N)`. */
43
+ export declare const SELFHOSTED_RETRY_BACKOFF_BASE_MS = 500;
44
+ export declare const SELFHOSTED_RETRY_BACKOFF_FACTOR = 2;
45
+ /** Per-delay ceiling: 500 → 1s → 2s → 4s → 8s, then flat at 8s. Bounds the summed
46
+ * backoff — non-exec (3 retries) ≈3.5s ≤5s; exec (10 retries) ≈55.5s <60s. */
47
+ export declare const SELFHOSTED_RETRY_BACKOFF_CAP_MS = 8000;
48
+ export type SelfhostedRetryDecision = {
49
+ readonly action: "fail";
50
+ } | {
51
+ readonly action: "retry";
52
+ readonly delayMs: number;
53
+ };
54
+ /**
55
+ * Full-jitter exponential backoff. Returns a delay in
56
+ * `[0, min(cap, base * factor^attempt))`. `jitter` is an injected sample in
57
+ * `[0, 1)` so the delay is fully deterministic under test.
58
+ */
59
+ export declare function selfhostedRetryBackoffMs(attempt: number, jitter: number): number;
60
+ /**
61
+ * PURE retry policy for one selfhosted control-op reply.
62
+ *
63
+ * - `error.draining` (DRAINING — pre-admission host-work backpressure; the op was
64
+ * rejected at the pool gate and NEVER started) → retry for ANY op kind, since
65
+ * nothing executed. exec gets the long `SELFHOSTED_EXEC_DRAINING_MAX_RETRIES`
66
+ * budget (≈60s of patient queueing under the flat 8-permit pool); every other op
67
+ * keeps the short `SELFHOSTED_DRAINING_MAX_RETRIES` budget (≤5s).
68
+ * - `error.neverSent` (a pre-send AGENT_OFFLINE synthesis — no connection / no
69
+ * responder; the op provably never reached the machine) → retry for ANY op kind
70
+ * up to `SELFHOSTED_NEVER_SENT_MAX_RETRIES`. At-least-once does NOT apply (nothing
71
+ * executed), so even a mutation is safe to re-issue; this heals a NATS reconnect
72
+ * blip quietly. A truly-offline machine surfaces honestly after the short budget.
73
+ * - `error.reason === "agent_reconnecting"` (a TIMEOUT / transient blip AFTER send)
74
+ * → retry at most `SELFHOSTED_TIMEOUT_MAX_RETRIES`, and ONLY for a read-only
75
+ * idempotent-safe op (`SELFHOSTED_IDEMPOTENT_READONLY_OPS`). A timed-out
76
+ * MUTATION is never retried here — it may already have run (at-least-once).
77
+ * - Everything else → no retry at this layer:
78
+ * · FENCED is retried by the routing proxy against a RE-RESOLVED backend
79
+ * (retrying here under the same stale epoch would just re-fence);
80
+ * · AGENT_OFFLINE / OS / PROTOCOL / PAYLOAD_TOO_LARGE / CONSENT_REQUIRED are
81
+ * not transient and must surface to the caller.
82
+ *
83
+ * The draining and timeout budgets are SEPARATE counters so a read that first hit
84
+ * backpressure still keeps its single timeout re-issue (and vice versa); both are
85
+ * bounded, so the total number of attempts — and the summed backoff — is bounded.
86
+ */
87
+ export declare function decideSelfhostedRetry(input: {
88
+ opKind: string;
89
+ error: SelfhostedControlError;
90
+ drainingRetries: number;
91
+ timeoutRetries: number;
92
+ /** Prior never-sent retries. Optional (default 0) — only the pre-send AGENT_OFFLINE
93
+ * branch reads it, so callers that cannot hit that class may omit it. */
94
+ neverSentRetries?: number;
95
+ jitter: number;
96
+ }): SelfhostedRetryDecision;
97
+ /**
98
+ * The injected clock the retry loop drives — real in production, a deterministic
99
+ * fake in tests. `jitter()` returns a full-jitter sample in `[0, 1)`.
100
+ */
101
+ export interface SelfhostedRetryClock {
102
+ sleep(ms: number): Promise<void>;
103
+ jitter(): number;
104
+ }
105
+ /** The production clock: a real timer + `Math.random()` jitter. */
106
+ export declare const defaultSelfhostedRetryClock: SelfhostedRetryClock;