@opengeni/runtime 0.2.2 → 0.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.
- package/dist/{chunk-2PO56VAL.js → chunk-D5KU3QUC.js} +240 -23
- package/dist/chunk-D5KU3QUC.js.map +1 -0
- package/dist/index.d.ts +106 -178
- package/dist/index.js +427 -161
- package/dist/index.js.map +1 -1
- package/dist/sandbox/index.d.ts +54 -6
- package/dist/sandbox/index.js +11 -1
- package/package.json +3 -3
- package/src/context-compaction.ts +217 -348
- package/src/image-history.ts +149 -0
- package/src/index.ts +195 -38
- package/src/sandbox/display-stack.ts +96 -12
- package/src/sandbox/index.ts +72 -12
- package/src/sandbox/providers/modal.ts +225 -0
- package/src/sandbox/routing/routing-session.ts +2 -2
- package/src/sandbox/selfhosted/session.ts +21 -5
- package/src/sandbox-computer.ts +88 -26
- package/dist/chunk-2PO56VAL.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { ReasoningEffort, SessionEventType, ResourceRef, ToolRef, Permission } f
|
|
|
7
7
|
export { CAPABILITY_DESCRIPTORS, CapabilityDescriptor, DESKTOP_STREAM_PORT, StreamTokenPayload, StreamTokenPayload as StreamTokenPayloadType, TERMINAL_STREAM_PORT } from '@opengeni/contracts';
|
|
8
8
|
import { Capability, SandboxSessionLike, SandboxSessionState, Manifest, Capabilities, LocalDirLazySkillSource, SandboxClient } from '@openai/agents/sandbox';
|
|
9
9
|
import OpenAI from 'openai';
|
|
10
|
-
export { ActiveBackendResolverDeps, ActiveBackendUnresolvableError, ActivePointer, ChannelAConflictError, ChannelAEmitter, ChannelAExecArgs, ChannelAExecResult, ChannelANotFoundError, ChannelASession, ChannelAUnsupportedError, ChannelAValidationError, ControlRpc, DEFAULT_DESKTOP_GEOMETRY, DISPLAY_STACK_TIMEOUT_MS, DesktopGeometry, DisplayStackError, DisplayStackUnsupportedError, EnsureDisplayStackOptions, EnsureDisplayStackResult, EnsureTerminalServerOptions, EnsureTerminalServerResult, EstablishedSandboxSession, ExposeStreamPortInput, ExposeStreamPortResult, ExposedPortEndpoint, FinalizeRecordingResult, MintStreamTokenInput, MockAgentResponder, MockAgentResponderOptions, MockExecHandler, NatsControlRpc, NatsRequestConnection, NegotiationContext, NumstatEntry, PROVIDER_REGISTRY, ProviderConstructionContext, ProviderRegistration, RecordingCodec, RecordingContentType, RecordingError, RecordingProcess, RecordingUnavailableError, ResolvedActiveBackend, RoutableBackendSession, RoutableSandbox, RoutingSandboxSession, RoutingSandboxSessionDeps, RoutingTransitionEvent, RoutingUnsupportedError, SELFHOSTED_DEFAULT_TIMEOUT_MS, SELFHOSTED_RECONNECT_WINDOW_MS, SELFHOSTED_RELAY_STREAM_PATH, STREAM_PORT, STREAM_TOKEN_DEFAULT_TTL_SECONDS, SandboxChannelAService, SandboxChannelAServiceOptions, SandboxConfigError, SandboxProviderUnavailableError, SelfhostedApplyDiff, SelfhostedControlError, SelfhostedEditor, SelfhostedEnrollment, SelfhostedExecArgs, SelfhostedExecResult, SelfhostedImageOutput, SelfhostedLivenessState, SelfhostedNegotiationInput, SelfhostedRelayConfig, SelfhostedSandboxClient, SelfhostedSession, SelfhostedSessionBuild, SelfhostedSessionDeps, SelfhostedSessionState, SelfhostedUnavailableReason, StartRecordingInput, StreamPortUnavailableError, TERMINAL_SERVER_TIMEOUT_MS, TerminalServerError, TerminalServerUnsupportedError, agentErrorToControlError, assertDescriptorRegistryInvariants, assertProviderRegistryInvariants, assertSafeRelPath, backendSupportsOs, buildDisplayStackScript, buildSelfhostedBackendSession, buildStreamUrl, buildTerminalServerScript, contentTypeForCodec, createSandboxClient, createSandboxClientForBackend, decodeModalSnapshotId, deletePriorPersistedSnapshot, deleteRecordingArtifacts, deserializeSandboxSessionStateEnvelope, desktopCapableBackend, ensureDisplayStack, ensureTerminalServer, establishSandboxSessionFromEnvelope, exposeStreamPort, extForCodec, isExecSessionLostBanner, isProviderSandboxNotFoundError, isSelfhostedProviderNotFoundError, isWorkspaceEscapeError, makeActiveBackendResolver, mintStreamToken, negotiateCapabilities, negotiateSelfhostedCapabilities, offlineAgentError, offlineControlResponse, parseExecBannerSessionId, parseNumstatZ, parsePorcelainV2, parseUnifiedPatch, readRecordingBytes, readWorkspaceArchiveFromEnvelopeSessionState, recordingStorageKey, restoredSandboxSessionStateFromEntry, sandboxStateEntryFromRunState, selectBackend, selfhostedLiveness, serializeEstablishedSandboxEnvelope, setSelfhostedApplyDiff, startRecording, stopRecording, stripExecBanner, subjectFor, tearDownDisplayStack, tearDownTerminalServer, timeoutAgentError, timeoutControlResponse, verifyStreamToken } from './sandbox/index.js';
|
|
10
|
+
export { ActiveBackendResolverDeps, ActiveBackendUnresolvableError, ActivePointer, ChannelAConflictError, ChannelAEmitter, ChannelAExecArgs, ChannelAExecResult, ChannelANotFoundError, ChannelASession, ChannelAUnsupportedError, ChannelAValidationError, ControlRpc, DEFAULT_DESKTOP_GEOMETRY, DISPLAY_STACK_TIMEOUT_MS, DesktopGeometry, DisplayStackError, DisplayStackUnsupportedError, EnsureDisplayStackOptions, EnsureDisplayStackResult, EnsureTerminalServerOptions, EnsureTerminalServerResult, EstablishedSandboxSession, ExposeStreamPortInput, ExposeStreamPortResult, ExposedPortEndpoint, FinalizeRecordingResult, LiveModalSandboxLeaseAttribution, MintStreamTokenInput, MockAgentResponder, MockAgentResponderOptions, MockExecHandler, ModalOrphanSweepResult, ModalSandboxAttribution, NatsControlRpc, NatsRequestConnection, NegotiationContext, NumstatEntry, PROVIDER_REGISTRY, ProviderConstructionContext, ProviderRegistration, RecordingCodec, RecordingContentType, RecordingError, RecordingProcess, RecordingUnavailableError, ResolvedActiveBackend, RoutableBackendSession, RoutableSandbox, RoutingSandboxSession, RoutingSandboxSessionDeps, RoutingTransitionEvent, RoutingUnsupportedError, SELFHOSTED_DEFAULT_TIMEOUT_MS, SELFHOSTED_RECONNECT_WINDOW_MS, SELFHOSTED_RELAY_STREAM_PATH, STREAM_PORT, STREAM_TOKEN_DEFAULT_TTL_SECONDS, SandboxChannelAService, SandboxChannelAServiceOptions, SandboxConfigError, SandboxCreatedCallback, SandboxProviderUnavailableError, SelfhostedApplyDiff, SelfhostedControlError, SelfhostedEditor, SelfhostedEnrollment, SelfhostedExecArgs, SelfhostedExecResult, SelfhostedImageOutput, SelfhostedLivenessState, SelfhostedNegotiationInput, SelfhostedRelayConfig, SelfhostedSandboxClient, SelfhostedSession, SelfhostedSessionBuild, SelfhostedSessionDeps, SelfhostedSessionState, SelfhostedUnavailableReason, StartRecordingInput, StreamPortUnavailableError, TERMINAL_SERVER_TIMEOUT_MS, TerminalServerError, TerminalServerUnsupportedError, agentErrorToControlError, assertDescriptorRegistryInvariants, assertProviderRegistryInvariants, assertSafeRelPath, backendSupportsOs, buildDisplayStackScript, buildSelfhostedBackendSession, buildStreamUrl, buildTerminalServerScript, contentTypeForCodec, createSandboxClient, createSandboxClientForBackend, decodeModalSnapshotId, deletePriorPersistedSnapshot, deleteRecordingArtifacts, deserializeSandboxSessionStateEnvelope, desktopCapableBackend, ensureDisplayStack, ensureTerminalServer, establishSandboxSessionFromEnvelope, exposeStreamPort, extForCodec, isExecSessionLostBanner, isProviderSandboxNotFoundError, isSelfhostedProviderNotFoundError, isWorkspaceEscapeError, makeActiveBackendResolver, mintStreamToken, modalSandboxAttributionEnvironment, modalSandboxAttributionTags, negotiateCapabilities, negotiateSelfhostedCapabilities, offlineAgentError, offlineControlResponse, parseExecBannerSessionId, parseNumstatZ, parsePorcelainV2, parseUnifiedPatch, readRecordingBytes, readWorkspaceArchiveFromEnvelopeSessionState, recordingStorageKey, restoredSandboxSessionStateFromEntry, sandboxStateEntryFromRunState, selectBackend, selfhostedLiveness, serializeEstablishedSandboxEnvelope, setSelfhostedApplyDiff, startRecording, stopRecording, stripExecBanner, subjectFor, sweepModalOrphanSandboxes, tagModalSandbox, tearDownDisplayStack, tearDownTerminalServer, terminateModalSandboxById, timeoutAgentError, timeoutControlResponse, verifyStreamToken } from './sandbox/index.js';
|
|
11
|
+
import 'modal';
|
|
11
12
|
import '@opengeni/agent-proto';
|
|
12
13
|
|
|
13
14
|
type ComputerButton = "left" | "right" | "wheel" | "back" | "forward";
|
|
@@ -18,6 +19,8 @@ type SandboxComputerOptions = {
|
|
|
18
19
|
typeDelayMs?: number;
|
|
19
20
|
readOnly?: boolean;
|
|
20
21
|
screenshotTmpDir?: string;
|
|
22
|
+
screenshotWarmupBudgetMs?: number;
|
|
23
|
+
screenshotRetryDelayMs?: number;
|
|
21
24
|
};
|
|
22
25
|
/** No exec/execCommand on the session, or the display is not up. */
|
|
23
26
|
declare class ComputerUnavailableError extends Error {
|
|
@@ -53,6 +56,8 @@ declare class SandboxComputer implements Computer {
|
|
|
53
56
|
private readonly typeDelayMs;
|
|
54
57
|
private readonly readOnly;
|
|
55
58
|
private readonly tmp;
|
|
59
|
+
private readonly screenshotWarmupBudgetMs;
|
|
60
|
+
private readonly screenshotRetryDelayMs;
|
|
56
61
|
constructor(session: SandboxSessionLike, opts?: SandboxComputerOptions);
|
|
57
62
|
/** Rebind to a freshly resumed-by-id session after a box rollover / re-establish. */
|
|
58
63
|
rebind(session: SandboxSessionLike): void;
|
|
@@ -280,97 +285,77 @@ declare function stripReasoningIdentityFromSerializedRunState(serialized: string
|
|
|
280
285
|
declare function neutralizeToolSearchItemsInSerializedRunState(serialized: string): string;
|
|
281
286
|
|
|
282
287
|
/**
|
|
283
|
-
* Client-side conversation context compaction (the Azure path).
|
|
288
|
+
* Client-side conversation context compaction (the Azure/client path).
|
|
284
289
|
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
* This module is the Azure-safe replacement. It is built from two pure pieces
|
|
292
|
-
* plus one impure step the caller wires in:
|
|
293
|
-
*
|
|
294
|
-
* 1. `planCompaction` — given the active history items, the last turn's actual
|
|
295
|
-
* input-token count, and the token budget, decide WHETHER to compact and,
|
|
296
|
-
* if so, WHERE the orphan-safe cut boundary is (the prefix to summarize vs
|
|
297
|
-
* the recent tail to keep verbatim). Pure, exhaustively testable.
|
|
298
|
-
* 2. (caller) summarize the prefix into ONE plain user `message` item via a
|
|
299
|
-
* model call — see `buildCompactionMessages` / `SUMMARY_PREFIX`.
|
|
300
|
-
* 3. `applyCompaction` shape — the storage write the caller performs:
|
|
301
|
-
* supersede the prefix rows, insert the summary at the boundary position.
|
|
302
|
-
*
|
|
303
|
-
* Design constraints (non-negotiable):
|
|
304
|
-
* - The summary is a PLAIN user message, NOT the SDK `compaction` item type
|
|
305
|
-
* (that requires server-minted `encrypted_content`; a hand-rolled one risks
|
|
306
|
-
* an Azure 400).
|
|
307
|
-
* - ORPHAN SAFETY: the cut lands only at a clean turn boundary (start of a
|
|
308
|
-
* user message). No tool call_id may straddle the cut — for every
|
|
309
|
-
* `function_call` dropped, its `function_call_result` is also dropped, and
|
|
310
|
-
* vice versa. Reasoning items drop/keep with their whole turn.
|
|
311
|
-
* - SINGLE LIVE SUMMARY: each compaction folds the prior summary forward
|
|
312
|
-
* (summarize [prior summary] + [items since]); prior summaries are excluded
|
|
313
|
-
* from re-collection so drift stays bounded.
|
|
290
|
+
* This mirrors Codex CLI's compaction model: the checkpoint model sees the
|
|
291
|
+
* current active history plus one fixed checkpoint prompt, then the active
|
|
292
|
+
* history is rebuilt as all real user messages plus one summary message.
|
|
293
|
+
* Assistant messages, tool calls/results, reasoning, and images are removed
|
|
294
|
+
* from the active model-facing history; the database audit rows remain.
|
|
314
295
|
*/
|
|
315
296
|
type CompactionItem = Record<string, unknown>;
|
|
316
297
|
/**
|
|
317
|
-
* Marker stored on the synthetic summary item so
|
|
318
|
-
* next
|
|
319
|
-
* lives in the item JSON, not a DB column, so it survives verbatim replay.
|
|
298
|
+
* Marker stored on the synthetic summary item so the UI can render it and the
|
|
299
|
+
* next rebuild can exclude old summaries from the retained user-message set.
|
|
320
300
|
*/
|
|
321
301
|
declare const COMPACTION_SUMMARY_MARKER = "opengeni_context_summary";
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
declare const SUMMARY_PREFIX: string;
|
|
302
|
+
declare const SUMMARY_BUFFER_TOKENS = 20000;
|
|
303
|
+
declare const COMPACT_USER_MESSAGE_MAX_TOKENS = 20000;
|
|
304
|
+
declare const CLIENT_COMPACTION_TRIGGER_FRACTION = 0.9;
|
|
305
|
+
declare const COMPACTION_PROMPT: string;
|
|
306
|
+
declare const SUMMARY_PREFIX = "Another language model started to solve this problem and produced a summary of its thinking process. You also have access to the state of the tools that were used by that language model. Use this to build on the work that has already been done and avoid duplicating work. Here is the summary produced by the other language model, use the information in this summary to assist with your own analysis:";
|
|
307
|
+
declare const USER_MESSAGE_TRUNCATION_MARKER = "\n[... middle truncated for context compaction ...]\n";
|
|
329
308
|
/** A user-authored `message` item is the only legal turn boundary. */
|
|
330
309
|
declare function isUserMessage(item: unknown): boolean;
|
|
331
310
|
/** True for our synthetic compaction summary item. */
|
|
332
311
|
declare function isCompactionSummary(item: unknown): boolean;
|
|
333
312
|
/**
|
|
334
|
-
* Rough token estimate for an item: char/4 over its serialized text. Used
|
|
335
|
-
*
|
|
336
|
-
* token count, falling back to this when that is unavailable.
|
|
313
|
+
* Rough token estimate for an item: char/4 over its serialized text. Used for
|
|
314
|
+
* the pre-first-call fallback, per-user-message cap, and read-path airbag.
|
|
337
315
|
*/
|
|
338
316
|
declare function estimateItemTokens(item: CompactionItem): number;
|
|
339
317
|
declare function estimateTokens(items: readonly CompactionItem[]): number;
|
|
318
|
+
declare function clientCompactionThresholdTokens(input: {
|
|
319
|
+
contextWindowTokens: number;
|
|
320
|
+
contextReservedOutputTokens: number;
|
|
321
|
+
}): number;
|
|
322
|
+
type ClientCompactionDecision = {
|
|
323
|
+
shouldCompact: boolean;
|
|
324
|
+
reason: "force" | "above_threshold" | "below_threshold" | "no_history";
|
|
325
|
+
signalTokens: number;
|
|
326
|
+
thresholdTokens: number;
|
|
327
|
+
};
|
|
328
|
+
declare function decideClientCompaction(input: {
|
|
329
|
+
items: readonly CompactionItem[];
|
|
330
|
+
lastInputTokens?: number | null;
|
|
331
|
+
contextWindowTokens: number;
|
|
332
|
+
contextReservedOutputTokens: number;
|
|
333
|
+
force?: boolean;
|
|
334
|
+
}): ClientCompactionDecision;
|
|
335
|
+
declare class CompactionNeededError extends Error {
|
|
336
|
+
readonly signalTokens: number;
|
|
337
|
+
readonly thresholdTokens: number;
|
|
338
|
+
readonly signalSource: "provider" | "estimate";
|
|
339
|
+
constructor(input: {
|
|
340
|
+
signalTokens: number;
|
|
341
|
+
thresholdTokens: number;
|
|
342
|
+
signalSource: "provider" | "estimate";
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
declare function findCompactionNeededError(error: unknown, seen?: WeakSet<object>): CompactionNeededError | null;
|
|
340
346
|
/**
|
|
341
347
|
* Walk backwards from the end of `items` keeping whole turns until the kept
|
|
342
348
|
* tail would exceed `keepRecentTokens`, and return the index of the first kept
|
|
343
|
-
* item.
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
* Returns `items.length` when nothing fits within the budget yet a boundary is
|
|
347
|
-
* required (degenerate); callers treat an index of 0 or length as "no useful
|
|
348
|
-
* cut".
|
|
349
|
+
* item. Retained for the read-path budget guard only; the client compaction
|
|
350
|
+
* rebuild no longer uses a keep-recent tail.
|
|
349
351
|
*/
|
|
350
352
|
declare function findKeepBoundary(items: readonly CompactionItem[], keepRecentTokens: number): number;
|
|
351
353
|
/**
|
|
352
354
|
* READ-PATH BUDGET GUARD (last-resort backstop).
|
|
353
355
|
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* model context window. The #61 orphan sanitizer is purely structural — it has
|
|
358
|
-
* NO size awareness — so without this guard an over-budget input is sent and
|
|
359
|
-
* 400s every turn, re-bricking the session.
|
|
360
|
-
*
|
|
361
|
-
* `enforceInputBudget` drops the OLDEST history at a clean turn boundary until
|
|
362
|
-
* the estimated input fits `maxTokens`, ALWAYS keeping the most recent turn(s).
|
|
363
|
-
* It is orphan-safe by construction: it only ever cuts at the start of a user
|
|
364
|
-
* message (via `findKeepBoundary`), so no tool-call pair is split. It is a
|
|
365
|
-
* crude data-loss fallback (no summary is generated) that exists solely so a
|
|
366
|
-
* single over-budget assembled input is never put on the wire — real context
|
|
367
|
-
* preservation is the summarizing pre-turn path; this is the airbag.
|
|
368
|
-
*
|
|
369
|
-
* Pure: returns a new array (same item references, in order) with an oldest
|
|
370
|
-
* prefix omitted, or the input unchanged when it already fits. The provided
|
|
371
|
-
* `trailingTokens` accounts for the un-stored part of the assembled input (the
|
|
372
|
-
* new user/continuation message + fixed system/tool overhead) so the cap is
|
|
373
|
-
* measured against the WHOLE request, not just the stored history.
|
|
356
|
+
* Drops the oldest history at a clean user-message boundary until an assembled
|
|
357
|
+
* input fits the request budget. This remains a request-local safety rail; it
|
|
358
|
+
* is not the compaction strategy.
|
|
374
359
|
*/
|
|
375
360
|
declare function enforceInputBudget<T extends CompactionItem>(items: readonly T[], maxTokens: number, trailingTokens?: number): {
|
|
376
361
|
items: T[];
|
|
@@ -378,111 +363,35 @@ declare function enforceInputBudget<T extends CompactionItem>(items: readonly T[
|
|
|
378
363
|
droppedCount: number;
|
|
379
364
|
estimatedTokens: number;
|
|
380
365
|
};
|
|
381
|
-
type CompactionPlan = {
|
|
382
|
-
/** Whether a compaction should run this turn. */
|
|
383
|
-
shouldCompact: boolean;
|
|
384
|
-
/** Why not, when shouldCompact is false (for logs/tests). */
|
|
385
|
-
reason: "below_threshold" | "no_boundary" | "nothing_to_summarize" | "compact";
|
|
386
|
-
/**
|
|
387
|
-
* The signal-token count the trigger decision was made on:
|
|
388
|
-
* max(actual last-turn input tokens, char/4 estimate of the active items).
|
|
389
|
-
* Recorded for logging / metrics and so a caller can reason about pressure.
|
|
390
|
-
*/
|
|
391
|
-
signalTokens: number;
|
|
392
|
-
/**
|
|
393
|
-
* True when the signal reached hardFraction*B — the session is at/over the
|
|
394
|
-
* hard ceiling and compaction was forced even if the recorded last-turn count
|
|
395
|
-
* was stale-low. The boundary walk is run with a SHRUNK keep-recent budget in
|
|
396
|
-
* this case so an over-budget history always yields a non-empty prefix to
|
|
397
|
-
* summarize (the everything-is-"recent" deadlock can't strand it un-compacted).
|
|
398
|
-
*/
|
|
399
|
-
hardForced: boolean;
|
|
400
|
-
/** Index (into the active items) where the kept tail begins. */
|
|
401
|
-
boundaryIndex: number;
|
|
402
|
-
/**
|
|
403
|
-
* The prefix items to summarize: active[0, boundaryIndex), EXCLUDING any
|
|
404
|
-
* prior compaction summary (which is folded forward via `priorSummaryItem`).
|
|
405
|
-
*/
|
|
406
|
-
prefixItems: CompactionItem[];
|
|
407
|
-
/** The prior live summary item folded into this compaction, if any. */
|
|
408
|
-
priorSummaryItem: CompactionItem | null;
|
|
409
|
-
/** Items kept verbatim: active[boundaryIndex, end). */
|
|
410
|
-
tailItems: CompactionItem[];
|
|
411
|
-
};
|
|
412
|
-
type PlanCompactionInput = {
|
|
413
|
-
/** Active history items in position order (already excludes superseded rows). */
|
|
414
|
-
items: readonly CompactionItem[];
|
|
415
|
-
/**
|
|
416
|
-
* Actual input tokens reported for the last model call of the previous turn.
|
|
417
|
-
* Null/undefined falls back to a char/4 estimate over `items`.
|
|
418
|
-
*/
|
|
419
|
-
lastInputTokens?: number | null;
|
|
420
|
-
/** Usable input budget B = window - reserved output. */
|
|
421
|
-
inputBudgetTokens: number;
|
|
422
|
-
softFraction: number;
|
|
423
|
-
hardFraction: number;
|
|
424
|
-
keepRecentTokens: number;
|
|
425
|
-
/**
|
|
426
|
-
* Operator-forced compaction (the /compact command): bypass the soft-limit
|
|
427
|
-
* token trigger and compact now if there is anything to summarize. The
|
|
428
|
-
* boundary / nothing-to-summarize guards still apply — force never invents a
|
|
429
|
-
* cut that would orphan a tool-call pair or summarize an empty prefix.
|
|
430
|
-
*/
|
|
431
|
-
force?: boolean;
|
|
432
|
-
};
|
|
433
|
-
/**
|
|
434
|
-
* Decide whether and where to compact. Pure.
|
|
435
|
-
*
|
|
436
|
-
* Trigger: signal tokens >= softFraction*B (soft) or hardFraction*B (hard).
|
|
437
|
-
* Signal = MAX(actual last-turn input tokens, char/4 estimate of the active
|
|
438
|
-
* items). The max — not "trust the recorded count, estimate only when it's
|
|
439
|
-
* null" — is the self-heal fix: `sessions.last_input_tokens` is written ONLY
|
|
440
|
-
* when a model response reports usage, so a turn that OVERFLOWS on its first
|
|
441
|
-
* model call records NOTHING and the column keeps a STALE-POSITIVE value from
|
|
442
|
-
* the last good turn (e.g. ~600k). Trusting that stale-low number let an
|
|
443
|
-
* actually-over-budget history (>1.05M) slip under the soft limit and overflow
|
|
444
|
-
* again, re-bricking with no self-heal. Taking the max means a bloated history
|
|
445
|
-
* triggers compaction regardless of a stale recorded count.
|
|
446
|
-
*
|
|
447
|
-
* Hard force (hardFraction*B): at/over the hard ceiling we compact even if the
|
|
448
|
-
* recorded count was stale-low, AND we run the boundary walk with a shrunk
|
|
449
|
-
* keep-recent budget so an over-budget history always yields a non-empty prefix
|
|
450
|
-
* — otherwise a history where the whole thing reads as "recent" (tail within
|
|
451
|
-
* keepRecentTokens) would find no prefix and strand the session over budget.
|
|
452
|
-
*
|
|
453
|
-
* Boundary: the earliest user-message boundary whose kept tail fits the
|
|
454
|
-
* (possibly shrunk) keep-recent budget. The prefix before it (minus any prior
|
|
455
|
-
* summary, which is folded forward) is what gets summarized.
|
|
456
|
-
*/
|
|
457
|
-
declare function planCompaction(input: PlanCompactionInput): CompactionPlan;
|
|
458
|
-
/** Extract the plain-text body of the prior summary item, if any. */
|
|
459
|
-
declare function compactionSummaryText(item: CompactionItem | null): string;
|
|
460
366
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
367
|
+
* The exact checkpoint input shape: current active history followed by Codex's
|
|
368
|
+
* checkpoint prompt as a synthesized user message.
|
|
463
369
|
*/
|
|
464
|
-
declare function
|
|
465
|
-
/**
|
|
466
|
-
* Instruction prompt for the summarizer model call. Leans on OpenGeni's durable
|
|
467
|
-
* structured memory (the notebook) so the summary stays a light working-memory
|
|
468
|
-
* bridge, never a place secret values get copied.
|
|
469
|
-
*/
|
|
470
|
-
declare const SUMMARY_INSTRUCTIONS: string;
|
|
370
|
+
declare function buildCompactionPromptInput(items: readonly CompactionItem[]): CompactionItem[];
|
|
471
371
|
/**
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
372
|
+
* Build the active history after compaction:
|
|
373
|
+
* all real user messages (prior summaries excluded, images removed, each
|
|
374
|
+
* message capped) plus one marked summary item.
|
|
475
375
|
*/
|
|
476
|
-
declare function
|
|
376
|
+
declare function buildCompactionReplacementHistory(items: readonly CompactionItem[], summaryBody: string): CompactionItem[];
|
|
477
377
|
/**
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
* tools, no streaming) and feeds the text result into `buildSummaryItem`.
|
|
378
|
+
* Build the synthetic summary item (a plain user message) appended to the
|
|
379
|
+
* rebuilt active history.
|
|
481
380
|
*/
|
|
482
|
-
declare function
|
|
483
|
-
|
|
484
|
-
|
|
381
|
+
declare function buildSummaryItem(summaryBody: string): CompactionItem;
|
|
382
|
+
declare function renderCompactionPromptInputForChat(input: readonly CompactionItem[]): string;
|
|
383
|
+
|
|
384
|
+
declare const SCREENSHOT_OMITTED_PLACEHOLDER = "[screenshot omitted: an older desktop frame \u2014 the full image remains in the session event log]";
|
|
385
|
+
type ElideStaleScreenshotsResult<T> = {
|
|
386
|
+
items: T[];
|
|
387
|
+
imageCount: number;
|
|
388
|
+
elidedCount: number;
|
|
485
389
|
};
|
|
390
|
+
type ElideStaleScreenshotsOptions = {
|
|
391
|
+
keepLast?: number;
|
|
392
|
+
placeholder?: string;
|
|
393
|
+
};
|
|
394
|
+
declare function elideStaleScreenshotImages<T extends AgentInputItem>(items: readonly T[], options?: ElideStaleScreenshotsOptions): ElideStaleScreenshotsResult<T>;
|
|
486
395
|
|
|
487
396
|
type NormalizedRuntimeEvent = {
|
|
488
397
|
type: SessionEventType;
|
|
@@ -613,10 +522,10 @@ declare class CodexSubscriptionUnavailableError extends Error {
|
|
|
613
522
|
declare function configureOpenAI(settings: Settings): void;
|
|
614
523
|
/**
|
|
615
524
|
* Run the compaction summarizer as one plain, tool-less, non-streaming model
|
|
616
|
-
* call against the resolved provider. `
|
|
617
|
-
*
|
|
525
|
+
* call against the resolved provider. `input` is the active history plus
|
|
526
|
+
* Codex's checkpoint prompt. Returns the trimmed summary text, or null on any
|
|
618
527
|
* failure (the caller treats a failed summarize as "skip compaction this turn"
|
|
619
|
-
*
|
|
528
|
+
* - never fatal). The call deliberately does NOT request reasoning encryption,
|
|
620
529
|
* tools, or server-side compaction; it is a self-contained summarize.
|
|
621
530
|
*
|
|
622
531
|
* Provider-aware: the summary always runs on the SAME provider that serves the
|
|
@@ -628,10 +537,7 @@ declare function configureOpenAI(settings: Settings): void;
|
|
|
628
537
|
* legacy global-client callers are byte-for-byte unchanged. store:false is set
|
|
629
538
|
* only on the OpenAI-platform Responses path (Azure rejects it; chat ignores it).
|
|
630
539
|
*/
|
|
631
|
-
declare function summarizeForCompaction(settings: Settings,
|
|
632
|
-
system: string;
|
|
633
|
-
user: string;
|
|
634
|
-
}, options?: {
|
|
540
|
+
declare function summarizeForCompaction(settings: Settings, input: Array<Record<string, unknown>>, options?: {
|
|
635
541
|
client?: OpenAI;
|
|
636
542
|
api?: ModelProviderApi;
|
|
637
543
|
maxOutputTokens?: number;
|
|
@@ -664,6 +570,7 @@ type BuildAgentOptions = {
|
|
|
664
570
|
gitTokenSeed?: string;
|
|
665
571
|
genesisTitleHint?: boolean;
|
|
666
572
|
instructionsTemplate?: string;
|
|
573
|
+
sessionInstructions?: string;
|
|
667
574
|
packSkills?: PackSkill[];
|
|
668
575
|
};
|
|
669
576
|
type PackSkillFile = {
|
|
@@ -710,6 +617,20 @@ declare function coreInstructions(workspaceEnvironment?: WorkspaceEnvironmentCon
|
|
|
710
617
|
* with an empty environment reproduces the historical preamble byte-for-byte.
|
|
711
618
|
*/
|
|
712
619
|
declare function composeAgentInstructions(template: string, workspaceEnvironment?: WorkspaceEnvironmentContext): string;
|
|
620
|
+
/**
|
|
621
|
+
* Appends the per-session persona instructions to the already-composed
|
|
622
|
+
* (workspace + CORE) instructions, joined by " " — exactly the join used
|
|
623
|
+
* throughout the persona composition. The session slice is intentionally LAST
|
|
624
|
+
* (session-specific refinement of the workspace persona). An absent/blank value
|
|
625
|
+
* is a no-op that returns the composed string byte-for-byte.
|
|
626
|
+
*/
|
|
627
|
+
declare function appendSessionInstructions(composed: string, sessionInstructions?: string): string;
|
|
628
|
+
/**
|
|
629
|
+
* Appends the one-shot genesis title directive (genesis turn only), joined by
|
|
630
|
+
* " " and always LAST so a white-label persona template or a per-session
|
|
631
|
+
* instruction can't drop it. A no-op when the hint is absent.
|
|
632
|
+
*/
|
|
633
|
+
declare function appendGenesisTitleDirective(instructions: string, genesisTitleHint?: boolean): string;
|
|
713
634
|
declare function buildOpenGeniAgent(settings: Settings, resources: ResourceRef[], options?: BuildAgentOptions): Agent<any, any>;
|
|
714
635
|
/**
|
|
715
636
|
* Build the SandboxAgent capability set provider-aware.
|
|
@@ -773,6 +694,7 @@ type RunAgentStreamOptions = {
|
|
|
773
694
|
sandboxClient?: unknown;
|
|
774
695
|
sandboxEnvironment?: Record<string, string>;
|
|
775
696
|
onRuntimeEvent?: (event: NormalizedRuntimeEvent) => Promise<void> | void;
|
|
697
|
+
contextCompactionSignalTokens?: () => number | null | undefined;
|
|
776
698
|
ownedSandbox?: {
|
|
777
699
|
client: unknown;
|
|
778
700
|
session: unknown;
|
|
@@ -781,6 +703,10 @@ type RunAgentStreamOptions = {
|
|
|
781
703
|
};
|
|
782
704
|
callModelInputFilter?: CallModelInputFilter;
|
|
783
705
|
};
|
|
706
|
+
type ContextRobustnessFilterOptions = {
|
|
707
|
+
contextCompactionSignalTokens?: () => number | null | undefined;
|
|
708
|
+
throwOnCompactionNeeded?: boolean;
|
|
709
|
+
};
|
|
784
710
|
declare const GENESIS_TITLE_DIRECTIVE = "This is the first turn of a new session. Before responding to the user, call the opengeni__set_session_title tool with a concise 3-7 word title that summarizes what this session is about, then address the user's request normally.";
|
|
785
711
|
/**
|
|
786
712
|
* callModelInputFilter that removes provider-assigned item ids (rs_/msg_/fc_…)
|
|
@@ -811,13 +737,15 @@ declare const stripProviderItemIdsFilter: CallModelInputFilter;
|
|
|
811
737
|
* never mutated.
|
|
812
738
|
*/
|
|
813
739
|
declare const normalizeComputerCallsFilter: CallModelInputFilter;
|
|
740
|
+
declare function contextRobustnessFilterForSettings(settings: Settings, options?: ContextRobustnessFilterOptions): CallModelInputFilter;
|
|
814
741
|
/**
|
|
815
742
|
* The model-input filter applied before every model call. The computer_call
|
|
816
743
|
* action/actions normalizer is ALWAYS on (the Azure endpoint 400s without it);
|
|
817
744
|
* the provider-item-id strip is layered on top when the configured policy
|
|
818
|
-
* selects it
|
|
745
|
+
* selects it; the context-robustness guard then elides stale screenshots on
|
|
746
|
+
* every mode and applies hard budget trimming only on the client-compaction path.
|
|
819
747
|
*/
|
|
820
|
-
declare function callModelInputFilterForSettings(settings: Settings): CallModelInputFilter | undefined;
|
|
748
|
+
declare function callModelInputFilterForSettings(settings: Settings, options?: ContextRobustnessFilterOptions): CallModelInputFilter | undefined;
|
|
821
749
|
declare function runAgentStream(agent: Agent<any, any>, input: PreparedAgentInput | string | RunState<any, any>, settings: Settings, overrides?: RunAgentStreamOptions): Promise<_openai_agents.StreamedRunResult<any, Agent<any, any>>>;
|
|
822
750
|
|
|
823
751
|
/**
|
|
@@ -933,4 +861,4 @@ declare function azureOpenAIDefaultQuery(settings: Pick<Settings, "azureOpenaiAp
|
|
|
933
861
|
*/
|
|
934
862
|
declare function lazySkillSourceWithPackSkills(packSkills: PackSkill[]): LocalDirLazySkillSource;
|
|
935
863
|
|
|
936
|
-
export { type AgentSegmentInput, type BuildAgentOptions, COMPACTION_SUMMARY_MARKER,
|
|
864
|
+
export { type AgentSegmentInput, type BuildAgentOptions, CLIENT_COMPACTION_TRIGGER_FRACTION, COMPACTION_PROMPT, COMPACTION_SUMMARY_MARKER, COMPACT_USER_MESSAGE_MAX_TOKENS, type ClientCompactionDecision, CodexSubscriptionUnavailableError, type CompactionItem, CompactionNeededError, ComputerActionError, ComputerReadOnlyError, type ComputerToolMode, ComputerUnavailableError, type ComputerUseArgs, ComputerUseCapability, type ContextRobustnessFilterOptions, type ElideStaleScreenshotsOptions, type ElideStaleScreenshotsResult, GENESIS_TITLE_DIRECTIVE, type HistoryItem, type ModelResponseUsage, MultiProviderModelProvider, type NormalizedRuntimeEvent, type OpenGeniRuntime, type PackSkill, type PackSkillFile, type PrepareInputOptions, type PrepareToolsOptions, type PreparedAgentInput, type PreparedAgentTools, type ProductionRuntimeOverrides, type RunAgentStreamOptions, SCREENSHOT_OMITTED_PLACEHOLDER, SUMMARY_BUFFER_TOKENS, SUMMARY_PREFIX, SandboxComputer, type SandboxComputerOptions, type SandboxFileDownload, type SandboxLifecycleHook, type SandboxLifecycleHookContext, type SandboxLifecycleHookPhase, USER_MESSAGE_TRUNCATION_MARKER, type WorkspaceEnvironmentContext, agentsErrorRunState, appendGenesisTitleDirective, appendSessionInstructions, applyMissingManifestEntries, azureCliLoginCommand, azureOpenAIDefaultQuery, buildAgentCapabilities, buildCompactionPromptInput, buildCompactionReplacementHistory, buildManifest, buildModelInstance, buildOpenAIClientFromSettings, buildOpenGeniAgent, buildProviderClient, buildSummaryItem, callModelInputFilterForSettings, clientCompactionThresholdTokens, composeAgentInstructions, computerUse, configureOpenAI, contextRobustnessFilterForSettings, coreInstructions, createProductionAgentRuntime, decideClientCompaction, elideStaleScreenshotImages, enforceInputBudget, ensureReadableStreamFrom, estimateItemTokens, estimateTokens, extractResponseOutputText, findCompactionNeededError, findKeepBoundary, isCompactionSummary, isUserMessage, lazySkillSourceWithPackSkills, materializeSandboxFileDownloads, maxTurnsExceededRunState, modelResponseUsageFromSdkEvent, neutralizeToolSearchItemsInSerializedRunState, normalizeComputerCallsFilter, normalizeSdkEvent, normalizeToolOutputForEvent, prefixedMcpToolName, prepareAgentTools, prepareRunInput, renderCompactionPromptInputForChat, repositoryCloneCommand, repositoryUsesSandboxClone, resolveTurnModel, runAgentStream, runAzureCliLoginHook, runBeforeAgentStartHooks, runRepositoryCloneHook, sandboxCommandExitCode, sandboxCommandOutput, sandboxCommandStillRunning, sandboxFileDownloadsForAgent, sandboxLifecycleHooksForIds, sandboxRunAs, sanitizeHistoryItemsForModel, serializeApprovals, stripProviderItemIdsFilter, stripReasoningEncryptedContent, stripReasoningIdentityFromSerializedRunState, summarizeForCompaction, withManifestRefreshOnResume, withSandboxFileDownloads, withSandboxLifecycleHooks, workspaceEnvironmentInstructions };
|