@opengeni/runtime 0.6.0 → 0.7.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 (44) hide show
  1. package/dist/{chunk-BHA2SU3H.js → chunk-RYDCVTMW.js} +1959 -208
  2. package/dist/chunk-RYDCVTMW.js.map +1 -0
  3. package/dist/{index-otZkoLYq.d.ts → index-DIiiwQY2.d.ts} +693 -55
  4. package/dist/index.d.ts +293 -121
  5. package/dist/index.js +1819 -786
  6. package/dist/index.js.map +1 -1
  7. package/dist/sandbox/index.d.ts +1 -1
  8. package/dist/sandbox/index.js +79 -3
  9. package/package.json +21 -20
  10. package/src/codex-tool-search.ts +185 -31
  11. package/src/context-compaction.ts +78 -243
  12. package/src/history-sanitizer.ts +172 -20
  13. package/src/index.ts +2573 -897
  14. package/src/metrics.ts +28 -2
  15. package/src/sandbox/capabilities.ts +12 -3
  16. package/src/sandbox/channel-a.ts +420 -72
  17. package/src/sandbox/display-stack.ts +18 -4
  18. package/src/sandbox/errors.ts +13 -0
  19. package/src/sandbox/index.ts +398 -112
  20. package/src/sandbox/op-correlation.ts +70 -0
  21. package/src/sandbox/providers/index.ts +9 -3
  22. package/src/sandbox/providers/modal.ts +99 -24
  23. package/src/sandbox/providers/selfhosted.ts +1 -4
  24. package/src/sandbox/recording.ts +146 -90
  25. package/src/sandbox/routing/backend-resolver.ts +144 -10
  26. package/src/sandbox/routing/routing-session.ts +129 -25
  27. package/src/sandbox/select.ts +60 -8
  28. package/src/sandbox/selfhosted/capabilities.ts +59 -25
  29. package/src/sandbox/selfhosted/control-rpc.ts +160 -28
  30. package/src/sandbox/selfhosted/fault-rendering.ts +226 -0
  31. package/src/sandbox/selfhosted/op-observer.ts +54 -0
  32. package/src/sandbox/selfhosted/op-stream.ts +801 -0
  33. package/src/sandbox/selfhosted/op-testing.ts +468 -0
  34. package/src/sandbox/selfhosted/op-transport.ts +151 -0
  35. package/src/sandbox/selfhosted/retry-policy.ts +177 -0
  36. package/src/sandbox/selfhosted/session.ts +498 -55
  37. package/src/sandbox/selfhosted/testing.ts +60 -19
  38. package/src/sandbox/stream-port.ts +17 -5
  39. package/src/sandbox/stream-token.ts +8 -2
  40. package/src/sandbox/terminal-server.ts +18 -4
  41. package/src/sandbox-computer.ts +332 -70
  42. package/src/usage-telemetry.ts +73 -0
  43. package/dist/chunk-BHA2SU3H.js.map +0 -1
  44. package/src/image-history.ts +0 -149
@@ -1,149 +0,0 @@
1
- import type { AgentInputItem } from "@openai/agents";
2
-
3
- export const SCREENSHOT_OMITTED_PLACEHOLDER =
4
- "[screenshot omitted: an older desktop frame — the full image remains in the session event log]";
5
-
6
- const DATA_IMAGE_BASE64_PATTERN = /data:image\/[a-z0-9.+-]+;base64,[a-z0-9+/=_-]+/i;
7
-
8
- type PathSegment = string | number;
9
-
10
- type ImageOccurrence = {
11
- path: PathSegment[];
12
- replacement: unknown;
13
- };
14
-
15
- export type ElideStaleScreenshotsResult<T> = {
16
- items: T[];
17
- imageCount: number;
18
- elidedCount: number;
19
- };
20
-
21
- export type ElideStaleScreenshotsOptions = {
22
- keepLast?: number;
23
- placeholder?: string;
24
- };
25
-
26
- export function elideStaleScreenshotImages<T extends AgentInputItem>(
27
- items: readonly T[],
28
- options: ElideStaleScreenshotsOptions = {},
29
- ): ElideStaleScreenshotsResult<T> {
30
- const keepLast = Math.max(0, Math.floor(options.keepLast ?? 3));
31
- const placeholder = options.placeholder ?? SCREENSHOT_OMITTED_PLACEHOLDER;
32
- const occurrences: ImageOccurrence[] = [];
33
- for (let i = 0; i < items.length; i += 1) {
34
- collectItemImageOccurrences(items[i], [i], placeholder, occurrences);
35
- }
36
-
37
- const elidedCount = Math.max(0, occurrences.length - keepLast);
38
- if (elidedCount === 0) {
39
- return { items: items.slice(), imageCount: occurrences.length, elidedCount: 0 };
40
- }
41
-
42
- const cloned = structuredClone(items) as T[];
43
- for (const occurrence of occurrences.slice(0, elidedCount)) {
44
- setPath(cloned, occurrence.path, occurrence.replacement);
45
- }
46
- return { items: cloned, imageCount: occurrences.length, elidedCount };
47
- }
48
-
49
- function collectItemImageOccurrences(
50
- item: unknown,
51
- path: PathSegment[],
52
- placeholder: string,
53
- out: ImageOccurrence[],
54
- ): void {
55
- if (!isRecord(item)) {
56
- return;
57
- }
58
- if (item.type === "message" && (item.role === "user" || item.role === "system")) {
59
- return;
60
- }
61
- if (item.type === "computer_call_result" || item.type === "computer_call_output") {
62
- collectComputerOutputImages(item, path, placeholder, out);
63
- return;
64
- }
65
- if (item.type === "function_call_result" || item.type === "function_call_output") {
66
- collectToolResultImages(item.output, [...path, "output"], placeholder, out);
67
- }
68
- }
69
-
70
- function collectComputerOutputImages(
71
- item: Record<string, unknown>,
72
- path: PathSegment[],
73
- placeholder: string,
74
- out: ImageOccurrence[],
75
- ): void {
76
- const output = item.output;
77
- if (!isRecord(output) || output.type !== "computer_screenshot") {
78
- return;
79
- }
80
- for (const key of ["data", "image_url", "imageUrl"]) {
81
- if (isImageDataUrl(output[key])) {
82
- out.push({ path: [...path, "output", key], replacement: placeholder });
83
- return;
84
- }
85
- }
86
- }
87
-
88
- function collectToolResultImages(
89
- value: unknown,
90
- path: PathSegment[],
91
- placeholder: string,
92
- out: ImageOccurrence[],
93
- ): void {
94
- if (typeof value === "string") {
95
- if (isImageDataUrl(value)) {
96
- out.push({ path, replacement: placeholder });
97
- }
98
- return;
99
- }
100
- if (Array.isArray(value)) {
101
- for (let i = 0; i < value.length; i += 1) {
102
- collectToolResultImages(value[i], [...path, i], placeholder, out);
103
- }
104
- return;
105
- }
106
- if (!isRecord(value)) {
107
- return;
108
- }
109
- if (value.type === "input_image") {
110
- for (const key of ["image", "imageUrl", "image_url"]) {
111
- if (isImageDataUrl(value[key])) {
112
- out.push({ path, replacement: { type: "input_text", text: placeholder } });
113
- return;
114
- }
115
- }
116
- }
117
- for (const key of ["content", "text", "output"]) {
118
- if (key in value) {
119
- collectToolResultImages(value[key], [...path, key], placeholder, out);
120
- }
121
- }
122
- }
123
-
124
- function isImageDataUrl(value: unknown): value is string {
125
- return typeof value === "string" && DATA_IMAGE_BASE64_PATTERN.test(value);
126
- }
127
-
128
- function isRecord(value: unknown): value is Record<string, unknown> {
129
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
130
- }
131
-
132
- function setPath(root: unknown, path: PathSegment[], value: unknown): void {
133
- if (path.length === 0) {
134
- return;
135
- }
136
- let cursor = root;
137
- for (let i = 0; i < path.length - 1; i += 1) {
138
- const segment = path[i]!;
139
- cursor = Array.isArray(cursor)
140
- ? cursor[segment as number]
141
- : (cursor as Record<string, unknown>)[segment as string];
142
- }
143
- const last = path[path.length - 1]!;
144
- if (Array.isArray(cursor)) {
145
- cursor[last as number] = value;
146
- } else {
147
- (cursor as Record<string, unknown>)[last as string] = value;
148
- }
149
- }