@opengeni/runtime 4.0.3 → 4.1.0-canary.36239117573001

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 (38) hide show
  1. package/dist/assets/codemode-client.json +1 -1
  2. package/dist/{chunk-GBVN7WSK.js → chunk-ORTF5RRC.js} +371 -28
  3. package/dist/chunk-ORTF5RRC.js.map +1 -0
  4. package/dist/{chunk-LL2YQO5H.js → chunk-YAA7WDNO.js} +638 -71
  5. package/dist/chunk-YAA7WDNO.js.map +1 -0
  6. package/dist/codex-tool-search.d.ts +12 -0
  7. package/dist/context-compaction.d.ts +4 -2
  8. package/dist/index.d.ts +27 -8
  9. package/dist/index.js +18 -2
  10. package/dist/knowledge-model-projection.d.ts +28 -0
  11. package/dist/metrics.d.ts +17 -0
  12. package/dist/model-provider-routing.d.ts +14 -0
  13. package/dist/operational-instructions.d.ts +1 -1
  14. package/dist/provider-quota.d.ts +76 -0
  15. package/dist/sandbox/channel-a.d.ts +43 -0
  16. package/dist/sandbox/index.d.ts +1 -1
  17. package/dist/sandbox/index.js +5 -1
  18. package/dist/tool-result-spill.d.ts +11 -3
  19. package/dist/workspace-tool-gateway.js +2 -2
  20. package/package.json +11 -11
  21. package/src/codex-tool-search.ts +54 -6
  22. package/src/context-compaction.ts +19 -3
  23. package/src/index.ts +277 -56
  24. package/src/knowledge-model-projection.ts +169 -0
  25. package/src/lazy-tool-transport.ts +4 -0
  26. package/src/metrics.ts +26 -0
  27. package/src/model-context-inspector.ts +1 -0
  28. package/src/model-provider-client.ts +37 -16
  29. package/src/model-provider-routing.ts +32 -6
  30. package/src/operational-instructions.ts +1 -1
  31. package/src/provider-quota.ts +412 -0
  32. package/src/sandbox/browser-control-client.ts +70 -25
  33. package/src/sandbox/channel-a.ts +370 -0
  34. package/src/sandbox/index.ts +3 -0
  35. package/src/sandbox/routing/routing-session.ts +25 -4
  36. package/src/tool-result-spill.ts +17 -5
  37. package/dist/chunk-GBVN7WSK.js.map +0 -1
  38. package/dist/chunk-LL2YQO5H.js.map +0 -1
@@ -13,6 +13,7 @@ import {
13
13
  BrowserControlUnsupportedError,
14
14
  CAPABILITY_DESCRIPTORS,
15
15
  CODEMODE_TOKEN_TTL_SECONDS,
16
+ CODE_SEARCH_RG_MAX_BYTES,
16
17
  ChannelAConflictError,
17
18
  ChannelAFileSystemRouteChangedError,
18
19
  ChannelANotFoundError,
@@ -258,6 +259,7 @@ import {
258
259
  timeoutAgentError,
259
260
  timeoutControlResponse,
260
261
  uploadRecordingArtifact,
262
+ validateCodeSearchRipgrepArgs,
261
263
  validateComputerControlFrameEvidence,
262
264
  verifyRestoredWorkspace,
263
265
  verifySandboxExecReadiness,
@@ -269,7 +271,7 @@ import {
269
271
  withRunCredentialsClient,
270
272
  withRunCredentialsSession,
271
273
  withoutSandboxProviderIdentity
272
- } from "../chunk-GBVN7WSK.js";
274
+ } from "../chunk-ORTF5RRC.js";
273
275
  import "../chunk-PRHMSM6C.js";
274
276
  import "../chunk-4A4XTKKX.js";
275
277
  import "../chunk-JAYHA6BF.js";
@@ -290,6 +292,7 @@ export {
290
292
  BrowserControlUnsupportedError,
291
293
  CAPABILITY_DESCRIPTORS,
292
294
  CODEMODE_TOKEN_TTL_SECONDS,
295
+ CODE_SEARCH_RG_MAX_BYTES,
293
296
  ChannelAConflictError,
294
297
  ChannelAFileSystemRouteChangedError,
295
298
  ChannelANotFoundError,
@@ -535,6 +538,7 @@ export {
535
538
  timeoutAgentError,
536
539
  timeoutControlResponse,
537
540
  uploadRecordingArtifact,
541
+ validateCodeSearchRipgrepArgs,
538
542
  validateComputerControlFrameEvidence,
539
543
  verifyRestoredWorkspace,
540
544
  verifySandboxExecReadiness,
@@ -1,5 +1,5 @@
1
1
  import type { AttemptToolDefinition, AttemptToolExecutionContext } from "@opengeni/codemode";
2
- import { type AttemptToolResult as AttemptToolResultValue, type ToolResultSpilledReceipt as ToolResultSpilledReceiptValue } from "@opengeni/contracts";
2
+ import { type AttemptToolIdentity, type AttemptToolResult as AttemptToolResultValue, type ToolResultSpilledReceipt as ToolResultSpilledReceiptValue } from "@opengeni/contracts";
3
3
  export type SpillOversizedModelToolResult = (input: {
4
4
  operationId: string;
5
5
  result: AttemptToolResultValue;
@@ -7,6 +7,14 @@ export type SpillOversizedModelToolResult = (input: {
7
7
  }) => Promise<AttemptToolResultValue>;
8
8
  export declare function modelToolResultOverflowError(): AttemptToolResultValue;
9
9
  export declare function spilledModelToolResult(receipt: ToolResultSpilledReceiptValue): AttemptToolResultValue;
10
- export declare function projectAttemptToolResultForCaller(result: AttemptToolResultValue, context: AttemptToolExecutionContext, spill?: SpillOversizedModelToolResult): Promise<AttemptToolResultValue>;
11
- export declare function wrapAttemptToolExecute(execute: AttemptToolDefinition["execute"], spill?: SpillOversizedModelToolResult): AttemptToolDefinition["execute"];
10
+ /**
11
+ * The single per-caller seam over one executor result. Codemode receives the
12
+ * exact result. The model receives its model-visible projection (compact
13
+ * Knowledge discovery output for the exact tool identity) when that fits in
14
+ * 1 MiB; otherwise the exact result is spilled to a file, as for any tool.
15
+ * MCP-backed tools are already bounded on their exact result by the MCP
16
+ * transport cap before this seam runs.
17
+ */
18
+ export declare function projectAttemptToolResultForCaller(result: AttemptToolResultValue, context: AttemptToolExecutionContext, spill?: SpillOversizedModelToolResult, identity?: AttemptToolIdentity): Promise<AttemptToolResultValue>;
19
+ export declare function wrapAttemptToolExecute(execute: AttemptToolDefinition["execute"], spill?: SpillOversizedModelToolResult, identity?: AttemptToolIdentity): AttemptToolDefinition["execute"];
12
20
  export declare function wrapAttemptToolDefinitions(definitions: readonly AttemptToolDefinition[], spill?: SpillOversizedModelToolResult): AttemptToolDefinition[];
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  prepareAgentTools
3
- } from "./chunk-LL2YQO5H.js";
4
- import "./chunk-GBVN7WSK.js";
3
+ } from "./chunk-YAA7WDNO.js";
4
+ import "./chunk-ORTF5RRC.js";
5
5
  import "./chunk-PRHMSM6C.js";
6
6
  import "./chunk-4A4XTKKX.js";
7
7
  import "./chunk-JAYHA6BF.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/runtime",
3
- "version": "4.0.3",
3
+ "version": "4.1.0-canary.36239117573001",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,16 +63,16 @@
63
63
  "@openai/agents": "0.14.3",
64
64
  "@openai/agents-core": "0.14.3",
65
65
  "@openai/agents-extensions": "0.14.3",
66
- "@opengeni/agent-proto": "^0.6.0",
67
- "@opengeni/capabilities": "^0.3.4",
68
- "@opengeni/codemode": "^0.6.2",
69
- "@opengeni/codex": "^0.2.26",
70
- "@opengeni/config": "^2.1.1",
71
- "@opengeni/contracts": "^5.1.1",
72
- "@opengeni/network": "^0.3.1",
73
- "@opengeni/sdk": "^7.1.1",
74
- "@opengeni/tool-gateway": "^0.1.13",
75
- "@opengeni/xai-subscription": "^0.1.4",
66
+ "@opengeni/agent-proto": "^0.6.0-canary.36239117573001",
67
+ "@opengeni/capabilities": "^0.3.4-canary.36239117573001",
68
+ "@opengeni/codemode": "^0.6.3-canary.36239117573001",
69
+ "@opengeni/codex": "^0.2.27-canary.36239117573001",
70
+ "@opengeni/config": "^3.0.0-canary.36239117573001",
71
+ "@opengeni/contracts": "^5.2.0-canary.36239117573001",
72
+ "@opengeni/network": "^0.3.1-canary.36239117573001",
73
+ "@opengeni/sdk": "^7.2.0-canary.36239117573001",
74
+ "@opengeni/tool-gateway": "^0.1.14-canary.36239117573001",
75
+ "@opengeni/xai-subscription": "^0.1.4-canary.36239117573001",
76
76
  "debug": "4.4.3",
77
77
  "modal": "0.9.0",
78
78
  "openai": "6.47.0",
@@ -185,6 +185,41 @@ export function bm25RankTools(tools: Tool[], query: string, limit: number): Tool
185
185
  return hits.slice(0, limit).map((s) => s.tool); // no hits ⇒ [] (codex-rs parity; see doc)
186
186
  }
187
187
 
188
+ /**
189
+ * Tools a free-text query names exactly, in query order. A query token that
190
+ * contains "_" names a tool when it equals the tool's full model name or the
191
+ * part after its last "__" server separator (`goal_complete` and
192
+ * `opengeni__goal_complete` both name `opengeni__goal_complete`). Single words
193
+ * such as "read" are never treated as names. Agents often search by exact name,
194
+ * and BM25 alone ranked a neighbouring tool first for about a fifth of those
195
+ * queries (`goal_complete` returned `goal_set` first).
196
+ */
197
+ export function toolsNamedInQuery<T extends Tool & { name: string }>(
198
+ tools: T[],
199
+ query: string,
200
+ ): T[] {
201
+ const byName = new Map<string, T[]>();
202
+ for (const tool of tools) {
203
+ const full = tool.name.toLowerCase();
204
+ const separator = full.lastIndexOf(MCP_TOOL_NAME_SEPARATOR);
205
+ const short = separator >= 0 ? full.slice(separator + MCP_TOOL_NAME_SEPARATOR.length) : full;
206
+ for (const key of new Set([full, short])) {
207
+ const named = byName.get(key) ?? [];
208
+ named.push(tool);
209
+ byName.set(key, named);
210
+ }
211
+ }
212
+ const named: T[] = [];
213
+ for (const raw of query.toLowerCase().split(/[^a-z0-9_]+/)) {
214
+ const token = raw.replace(/^_+|_+$/g, "");
215
+ if (!token.includes("_")) continue;
216
+ for (const tool of byName.get(token) ?? []) {
217
+ if (!named.includes(tool)) named.push(tool);
218
+ }
219
+ }
220
+ return named;
221
+ }
222
+
188
223
  /** Parse ranked or exact-name discovery arguments (string or object). */
189
224
  function parseSearchArgs(raw: unknown): { query: string; limit: number; names?: string[] } {
190
225
  let obj: Record<string, unknown> = {};
@@ -231,12 +266,25 @@ export function searchToolPool(availableTools: Tool[], rawArguments: unknown): T
231
266
  tool.type === "function" && typeof (tool as { name?: unknown }).name === "string",
232
267
  );
233
268
  if (searchable.length === 0) return [];
234
- const { query, limit, names } = parseSearchArgs(rawArguments);
235
- // Exact disclosure is a lookup in this already-authorized pool, not a fuzzy
236
- // search or another executor registry. Keep the SDK's original references.
237
- const ranked = names
238
- ? searchable.filter((tool) => names.includes(tool.name))
239
- : bm25RankTools(searchable, query, searchable.length);
269
+ const { query, limit: requestedLimit, names } = parseSearchArgs(rawArguments);
270
+ let ranked: Tool[];
271
+ let limit = requestedLimit;
272
+ if (names) {
273
+ // Exact disclosure is a lookup in this already-authorized pool, not a fuzzy
274
+ // search or another executor registry. Keep the SDK's original references.
275
+ ranked = searchable.filter((tool) => names.includes(tool.name));
276
+ } else {
277
+ // Every tool the query names comes first, even beyond the requested limit;
278
+ // BM25 fills any remaining places.
279
+ const named = toolsNamedInQuery(searchable, query);
280
+ ranked = [
281
+ ...named,
282
+ ...bm25RankTools(searchable, query, searchable.length).filter(
283
+ (tool) => !named.includes(tool as Tool & { name: string }),
284
+ ),
285
+ ];
286
+ limit = Math.min(MAX_SEARCH_LIMIT, Math.max(requestedLimit, named.length));
287
+ }
240
288
  const bounded: Tool[] = [];
241
289
  let disclosedBytes = 0;
242
290
  for (const tool of ranked) {
@@ -43,6 +43,10 @@ export type CompactionItem = Record<string, unknown>;
43
43
  export const COMPACTION_SUMMARY_MARKER = "opengeni_context_summary";
44
44
 
45
45
  export const SUMMARY_BUFFER_TOKENS = 20_000;
46
+ /** Leave input room on models whose entire context is smaller than the normal reserve. */
47
+ export function compactionSummaryOutputTokens(contextWindowTokens: number): number {
48
+ return Math.min(SUMMARY_BUFFER_TOKENS, Math.max(1, Math.floor(contextWindowTokens / 4)));
49
+ }
46
50
  // A single cumulative budget for all retained real user messages, matching
47
51
  // Codex core's build_compacted_history_with_limit (not a per-message allowance).
48
52
  export const COMPACT_USER_MESSAGE_MAX_TOKENS = 20_000;
@@ -1243,7 +1247,7 @@ export class EmptyCompactionSummaryError extends Error {
1243
1247
  constructor(diagnostics: Record<string, unknown> = {}) {
1244
1248
  const compact = JSON.stringify(diagnostics).slice(0, 2_000);
1245
1249
  super(
1246
- `Compaction summarizer returned no assistant text; active history was preserved${compact ? ` (${compact})` : ""}`,
1250
+ `Compaction could not produce a usable checkpoint; active history was preserved${compact ? ` (${compact})` : ""}`,
1247
1251
  );
1248
1252
  this.name = "EmptyCompactionSummaryError";
1249
1253
  this.diagnostics = diagnostics;
@@ -1520,10 +1524,18 @@ export function omitOpaqueArtifactsFromPortableCompactionHistory(
1520
1524
  }
1521
1525
  if (type === "reasoning" && hasOpaqueProviderArtifact(item)) {
1522
1526
  const projected = projectRejectedReasoningArtifact(item);
1527
+ if (Object.keys(projected).length === 1) {
1528
+ changed = true;
1529
+ continue;
1530
+ }
1523
1531
  changed ||= projected !== item;
1524
1532
  out.push(projected as CompactionItem);
1525
1533
  continue;
1526
1534
  }
1535
+ if (type === "reasoning" && Object.keys(item).length === 1) {
1536
+ changed = true;
1537
+ continue;
1538
+ }
1527
1539
  out.push(item);
1528
1540
  }
1529
1541
  return changed ? out : (items as CompactionItem[]);
@@ -1605,16 +1617,20 @@ function oldestLogicalUnitCuts(items: readonly CompactionItem[]): number[] {
1605
1617
 
1606
1618
  /**
1607
1619
  * Build the active history after compaction:
1608
- * the newest real user messages that fit one cumulative 20k-token budget
1620
+ * the newest real user messages that fit one cumulative, model-bounded budget
1609
1621
  * (prior summaries excluded, retained images preserved) plus one marked summary item.
1610
1622
  */
1611
1623
  export function buildCompactionReplacementHistory(
1612
1624
  items: readonly CompactionItem[],
1613
1625
  summaryBody: string,
1614
1626
  retainedItemTokens: (item: CompactionItem) => number = (item) => estimateTokens([item]),
1627
+ retainedMessageBudgetTokens = COMPACT_USER_MESSAGE_MAX_TOKENS,
1615
1628
  ): CompactionItem[] {
1616
1629
  const retainedReversed: CompactionItem[] = [];
1617
- let remaining = COMPACT_USER_MESSAGE_MAX_TOKENS;
1630
+ let remaining = Math.max(
1631
+ 0,
1632
+ Math.min(COMPACT_USER_MESSAGE_MAX_TOKENS, retainedMessageBudgetTokens),
1633
+ );
1618
1634
  for (let index = items.length - 1; index >= 0 && remaining > 0; index -= 1) {
1619
1635
  const item = items[index]!;
1620
1636
  if (!isUserMessage(item) || isCompactionSummary(item) || isAttachmentCatalog(item)) {