@jrkropp/codex-js 0.1.1 → 0.1.3

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 (132) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/ClientNotification-B6-FhXQf.d.ts +5 -0
  3. package/dist/{DynamicToolCallResponse-D2OVpa4p.d.ts → DynamicToolCallResponse-82DFjES2.d.ts} +1 -1
  4. package/dist/DynamicToolSpec-CfnhqAYK.d.ts +29 -0
  5. package/dist/PermissionsRequestApprovalResponse-DxzPPDRb.d.ts +55 -0
  6. package/dist/ProviderStatusBanner-BlP6lzwE.d.ts +441 -0
  7. package/dist/ServerRequest-B5cKVJjr.d.ts +2181 -0
  8. package/dist/{session-BO6EZNK7.d.ts → ThreadResumeResponse-DvmE1juU.d.ts} +3 -290
  9. package/dist/ToolRequestUserInputQuestion-CeZa5X1J.d.ts +23 -0
  10. package/dist/{ToolRequestUserInputResponse-Bxjlpgho.d.ts → ToolRequestUserInputResponse-zcPLwbiK.d.ts} +1 -1
  11. package/dist/TurnSteerResponse-0kBCfplh.d.ts +209 -0
  12. package/dist/WebSearchToolConfig-D3ep0625.d.ts +18 -0
  13. package/dist/chat-runtime-B6azJyKo.d.ts +381 -0
  14. package/dist/chunk-2DZRMCI2.js +1258 -0
  15. package/dist/chunk-2DZRMCI2.js.map +1 -0
  16. package/dist/chunk-4DPLJPB5.js +396 -0
  17. package/dist/chunk-4DPLJPB5.js.map +1 -0
  18. package/dist/chunk-5JMJ6OI5.js +3 -0
  19. package/dist/chunk-5JMJ6OI5.js.map +1 -0
  20. package/dist/chunk-6ZMJ34KE.js +1153 -0
  21. package/dist/chunk-6ZMJ34KE.js.map +1 -0
  22. package/dist/chunk-CGBS37IU.js +128 -0
  23. package/dist/chunk-CGBS37IU.js.map +1 -0
  24. package/dist/chunk-DCMKA2A6.js +18 -0
  25. package/dist/chunk-DCMKA2A6.js.map +1 -0
  26. package/dist/chunk-DYLHN3HG.js +937 -0
  27. package/dist/chunk-DYLHN3HG.js.map +1 -0
  28. package/dist/chunk-ILXA6HLX.js +1973 -0
  29. package/dist/chunk-ILXA6HLX.js.map +1 -0
  30. package/dist/{chunk-TZBLUZ2X.js → chunk-LWQNX4LI.js} +7811 -12696
  31. package/dist/chunk-LWQNX4LI.js.map +1 -0
  32. package/dist/{chunk-FFASNDXU.js → chunk-NCI4MAWZ.js} +317 -1967
  33. package/dist/chunk-NCI4MAWZ.js.map +1 -0
  34. package/dist/chunk-O44XP7LH.js +214 -0
  35. package/dist/chunk-O44XP7LH.js.map +1 -0
  36. package/dist/chunk-PST3ZWX2.js +555 -0
  37. package/dist/chunk-PST3ZWX2.js.map +1 -0
  38. package/dist/chunk-SYPHCDRD.js +1133 -0
  39. package/dist/chunk-SYPHCDRD.js.map +1 -0
  40. package/dist/chunk-V4BMZWBM.js +2401 -0
  41. package/dist/chunk-V4BMZWBM.js.map +1 -0
  42. package/dist/chunk-YHVCFD2D.js +117 -0
  43. package/dist/chunk-YHVCFD2D.js.map +1 -0
  44. package/dist/chunk-Z63UPBS3.js +152 -0
  45. package/dist/chunk-Z63UPBS3.js.map +1 -0
  46. package/dist/client/index.d.ts +16 -111
  47. package/dist/client/index.js +13 -1
  48. package/dist/codex-rs/app-server/index.d.ts +161 -0
  49. package/dist/codex-rs/app-server/index.js +13 -0
  50. package/dist/codex-rs/app-server/index.js.map +1 -0
  51. package/dist/codex-rs/app-server-protocol/index.d.ts +1722 -0
  52. package/dist/codex-rs/app-server-protocol/index.js +6 -0
  53. package/dist/codex-rs/app-server-protocol/index.js.map +1 -0
  54. package/dist/codex-rs/app-server-protocol/protocol.d.ts +19 -0
  55. package/dist/codex-rs/app-server-protocol/protocol.js +4 -0
  56. package/dist/codex-rs/app-server-protocol/protocol.js.map +1 -0
  57. package/dist/codex-rs/codex-api/index.d.ts +104 -0
  58. package/dist/codex-rs/codex-api/index.js +11 -0
  59. package/dist/codex-rs/codex-api/index.js.map +1 -0
  60. package/dist/codex-rs/config/index.d.ts +88 -0
  61. package/dist/codex-rs/config/index.js +4 -0
  62. package/dist/codex-rs/config/index.js.map +1 -0
  63. package/dist/codex-rs/core/config/index.d.ts +61 -0
  64. package/dist/codex-rs/core/config/index.js +5 -0
  65. package/dist/codex-rs/core/config/index.js.map +1 -0
  66. package/dist/codex-rs/core/index.d.ts +1393 -0
  67. package/dist/codex-rs/core/index.js +11 -0
  68. package/dist/codex-rs/core/index.js.map +1 -0
  69. package/dist/codex-rs/model-provider/index.d.ts +2 -0
  70. package/dist/codex-rs/model-provider/index.js +4 -0
  71. package/dist/codex-rs/model-provider/index.js.map +1 -0
  72. package/dist/codex-rs/models-manager/index.d.ts +2 -0
  73. package/dist/codex-rs/models-manager/index.js +4 -0
  74. package/dist/codex-rs/models-manager/index.js.map +1 -0
  75. package/dist/codex-rs/parity.d.ts +26 -0
  76. package/dist/codex-rs/parity.js +3 -0
  77. package/dist/codex-rs/parity.js.map +1 -0
  78. package/dist/codex-rs/thread-store/index.d.ts +5 -0
  79. package/dist/codex-rs/thread-store/index.js +4 -0
  80. package/dist/codex-rs/thread-store/index.js.map +1 -0
  81. package/dist/codex-rs/unsupported.d.ts +15 -0
  82. package/dist/codex-rs/unsupported.js +22 -0
  83. package/dist/codex-rs/unsupported.js.map +1 -0
  84. package/dist/codex-rs/utils/output-truncation.d.ts +21 -0
  85. package/dist/codex-rs/utils/output-truncation.js +4 -0
  86. package/dist/codex-rs/utils/output-truncation.js.map +1 -0
  87. package/dist/codex-rs/utils/string.d.ts +7 -0
  88. package/dist/codex-rs/utils/string.js +3 -0
  89. package/dist/codex-rs/utils/string.js.map +1 -0
  90. package/dist/common-CTyph5x8.d.ts +40 -0
  91. package/dist/event-mapping-CbISdQ1D.d.ts +43 -0
  92. package/dist/history-CfM-4V7b.d.ts +1654 -0
  93. package/dist/index-77U_Oc-a.d.ts +63 -0
  94. package/dist/index-CoDZosq0.d.ts +261 -0
  95. package/dist/index.d.ts +18 -8
  96. package/dist/index.js +16 -2
  97. package/dist/lib-nXlaKiS-.d.ts +48 -0
  98. package/dist/live-thread-BMvlflzM.d.ts +30 -0
  99. package/dist/merge-B_AWVmnI.d.ts +24 -0
  100. package/dist/mod-DYVLSWO4.d.ts +91 -0
  101. package/dist/plan-mode-Cv6KWb_S.d.ts +14 -0
  102. package/dist/proposed-plan-DpN1ma0Y.d.ts +53 -0
  103. package/dist/protocol-mpBcYHrm.d.ts +1655 -0
  104. package/dist/react/index.d.ts +20 -53
  105. package/dist/react/index.js +16 -2
  106. package/dist/{remote-DMPfepa9.d.ts → remote-ClZbq9KN.d.ts} +3 -1
  107. package/dist/rendered-thread-AOxw3V5b.d.ts +29 -0
  108. package/dist/responses_websocket-BhxSgCzK.d.ts +183 -0
  109. package/dist/runtime-Cm6ml53h.d.ts +528 -0
  110. package/dist/server/index.d.ts +29 -1999
  111. package/dist/server/index.js +13 -1
  112. package/dist/session-BRYzi8OT.d.ts +46 -0
  113. package/dist/shadcn/index.d.ts +1 -1
  114. package/dist/{sidebar-DT2XoitN.d.ts → sidebar-DMMij22z.d.ts} +1 -1
  115. package/dist/spec_plan_types-CmsJ-Tfn.d.ts +260 -0
  116. package/dist/{store-H2cQxdpe.d.ts → store-AGRxhgQ3.d.ts} +2 -1
  117. package/dist/t3code/apps/web/components/chat.d.ts +508 -0
  118. package/dist/t3code/apps/web/components/chat.js +12 -0
  119. package/dist/t3code/apps/web/components/chat.js.map +1 -0
  120. package/dist/t3code/apps/web/index.d.ts +12 -0
  121. package/dist/t3code/apps/web/index.js +13 -0
  122. package/dist/t3code/apps/web/index.js.map +1 -0
  123. package/dist/testing/index.d.ts +9 -91
  124. package/dist/testing/index.js +13 -1
  125. package/dist/thread-history-builder-zW0zeqcS.d.ts +58 -0
  126. package/dist/thread_event_store-C0zYzukG.d.ts +77 -0
  127. package/dist/types-BTeabLYr.d.ts +126 -0
  128. package/package.json +152 -88
  129. package/dist/chat-runtime-CMli5dzJ.d.ts +0 -748
  130. package/dist/chunk-FFASNDXU.js.map +0 -1
  131. package/dist/chunk-TZBLUZ2X.js.map +0 -1
  132. package/dist/thread_event_store-BIS0qzhi.d.ts +0 -3843
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/upstream/codex-rs/utils/string/src/truncate.ts"],"names":[],"mappings":";AAAA,IAAM,sBAAA,GAAyB,CAAA;AAExB,SAAS,qBAAA,CAAsB,OAAe,QAAA,EAA0B;AAC9E,EAAA,OAAO,2BAAA,CAA4B,KAAA,EAAO,QAAA,EAAU,KAAK,CAAA;AAC1D;AAEO,SAAS,iCAAA,CACf,OACA,SAAA,EAC0B;AAC1B,EAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACvB,IAAA,OAAO,CAAC,IAAI,IAAI,CAAA;AAAA,EACjB;AACA,EAAA,IAAI,YAAY,CAAA,IAAK,cAAA,CAAe,KAAK,CAAA,IAAK,uBAAA,CAAwB,SAAS,CAAA,EAAG;AACjF,IAAA,OAAO,CAAC,OAAO,IAAI,CAAA;AAAA,EACpB;AAEA,EAAA,MAAM,SAAA,GAAY,2BAAA;AAAA,IACjB,KAAA;AAAA,IACA,wBAAwB,SAAS,CAAA;AAAA,IACjC;AAAA,GACD;AACA,EAAA,MAAM,WAAA,GAAc,mBAAmB,KAAK,CAAA;AAC5C,EAAA,OAAO,SAAA,KAAc,QAAQ,CAAC,SAAA,EAAW,IAAI,CAAA,GAAI,CAAC,WAAW,WAAW,CAAA;AACzE;AAEO,SAAS,mBAAmB,IAAA,EAAsB;AACxD,EAAA,MAAM,MAAA,GAAS,eAAe,IAAI,CAAA;AAClC,EAAA,OAAO,IAAA,CAAK,IAAA,CAAK,MAAA,GAAS,sBAAsB,CAAA;AACjD;AAEO,SAAS,wBAAwB,MAAA,EAAwB;AAC/D,EAAA,OAAO,KAAK,GAAA,CAAI,CAAA,EAAG,KAAK,KAAA,CAAM,MAAM,CAAC,CAAA,GAAI,sBAAA;AAC1C;AAEO,SAAS,8BAA8B,KAAA,EAAuB;AACpE,E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ACA,MAAA,EACS;AACT,EAAA,IAAI,CAAC,IAAA,IAAQ,CAAC,KAAA,EAAO;AACpB,IAAA,OAAO,MAAA;AAAA,EACR;AACA,EAAA,IAAI,CAAC,IAAA,EAAM;AACV,IAAA,OAAO,CAAA,EAAG,MAAM,CAAA,EAAG,KAAK,CAAA,CAAA;AAAA,EACzB;AACA,EAAA,IAAI,CAAC,KAAA,EAAO;AACX,IAAA,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM,CAAA,CAAA;AAAA,EACxB;AACA,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,EAAG,MAAM,GAAG,KAAK,CAAA,CAAA;AAChC;AAEA,SAAS,wBAAA,CAAyB,WAAoB,YAAA,EAA8B;AACnF,EAAA,MAAM,IAAA,GAAO,YAAY,QAAA,GAAW,OAAA;AACpC,EAAA,OAAO,CAAA,MAAA,EAAI,YAAY,CAAA,CAAA,EAAI,IAAI,CAAA,gBAAA,CAAA;AAChC;AAEA,SAAS,aAAA,CACR,SAAA,EACA,YAAA,EACA,YAAA,EACS;AACT,EAAA,OAAO,SAAA,GAAY,6BAAA,CAA8B,YAAY,CAAA,GAAI,YAAA;AAClE;AAEA,SAAS,eAAe,KAAA,EAAuB;AAC9C,EAAA,OAAO,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,KAAK,CAAA,CAAE,UAAA;AACxC","file":"chunk-YHVCFD2D.js","sourcesContent":["const APPROX_BYTES_PER_TOKEN = 4;\n\nexport function truncate_middle_chars(value: string, maxBytes: number): string {\n\treturn truncate_with_byte_estimate(value, maxBytes, false);\n}\n\nexport function truncate_middle_with_token_budget(\n\tvalue: string,\n\tmaxTokens: number,\n): [string, number | null] {\n\tif (value.length === 0) {\n\t\treturn [\"\", null];\n\t}\n\tif (maxTokens > 0 && utf8ByteLength(value) <= approx_bytes_for_tokens(maxTokens)) {\n\t\treturn [value, null];\n\t}\n\n\tconst truncated = truncate_with_byte_estimate(\n\t\tvalue,\n\t\tapprox_bytes_for_tokens(maxTokens),\n\t\ttrue,\n\t);\n\tconst totalTokens = approx_token_count(value);\n\treturn truncated === value ? [truncated, null] : [truncated, totalTokens];\n}\n\nexport function approx_token_count(text: string): number {\n\tconst length = utf8ByteLength(text);\n\treturn Math.ceil(length / APPROX_BYTES_PER_TOKEN);\n}\n\nexport function approx_bytes_for_tokens(tokens: number): number {\n\treturn Math.max(0, Math.trunc(tokens)) * APPROX_BYTES_PER_TOKEN;\n}\n\nexport function approx_tokens_from_byte_count(bytes: number): number {\n\treturn Math.ceil(Math.max(0, Math.trunc(bytes)) / APPROX_BYTES_PER_TOKEN);\n}\n\nfunction truncate_with_byte_estimate(\n\tvalue: string,\n\tmaxBytes: number,\n\tuseTokens: boolean,\n): string {\n\tif (value.length === 0) {\n\t\treturn \"\";\n\t}\n\tconst normalizedMaxBytes = Math.max(0, Math.trunc(maxBytes));\n\tconst totalBytes = utf8ByteLength(value);\n\tif (normalizedMaxBytes === 0) {\n\t\treturn format_truncation_marker(\n\t\t\tuseTokens,\n\t\t\tremoved_units(useTokens, totalBytes, [...value].length),\n\t\t);\n\t}\n\tif (totalBytes <= normalizedMaxBytes) {\n\t\treturn value;\n\t}\n\n\tconst [leftBudget, rightBudget] = split_budget(normalizedMaxBytes);\n\tconst { left, removedChars, right } = split_string(value, leftBudget, rightBudget);\n\tconst marker = format_truncation_marker(\n\t\tuseTokens,\n\t\tremoved_units(\n\t\t\tuseTokens,\n\t\t\tMath.max(0, totalBytes - normalizedMaxBytes),\n\t\t\tremovedChars,\n\t\t),\n\t);\n\treturn assemble_truncated_output(left, right, marker);\n}\n\nfunction split_budget(maxBytes: number): [number, number] {\n\tconst left = Math.floor(maxBytes / 2);\n\treturn [left, maxBytes - left];\n}\n\nfunction split_string(\n\tvalue: string,\n\tbeginningBytes: number,\n\tendBytes: number,\n): { left: string; removedChars: number; right: string } {\n\tlet left = \"\";\n\tlet right = \"\";\n\tlet leftBytes = 0;\n\tconst chars = [...value];\n\tfor (const char of chars) {\n\t\tconst nextBytes = utf8ByteLength(char);\n\t\tif (leftBytes + nextBytes > beginningBytes) {\n\t\t\tbreak;\n\t\t}\n\t\tleft += char;\n\t\tleftBytes += nextBytes;\n\t}\n\n\tlet rightBytes = 0;\n\tfor (let index = chars.length - 1; index >= 0; index -= 1) {\n\t\tconst char = chars[index] ?? \"\";\n\t\tconst nextBytes = utf8ByteLength(char);\n\t\tif (rightBytes + nextBytes > endBytes) {\n\t\t\tbreak;\n\t\t}\n\t\tright = `${char}${right}`;\n\t\trightBytes += nextBytes;\n\t}\n\n\tconst keptChars = [...left].length + [...right].length;\n\treturn {\n\t\tleft,\n\t\tremovedChars: Math.max(0, chars.length - keptChars),\n\t\tright,\n\t};\n}\n\nfunction assemble_truncated_output(\n\tleft: string,\n\tright: string,\n\tmarker: string,\n): string {\n\tif (!left && !right) {\n\t\treturn marker;\n\t}\n\tif (!left) {\n\t\treturn `${marker}${right}`;\n\t}\n\tif (!right) {\n\t\treturn `${left}${marker}`;\n\t}\n\treturn `${left}${marker}${right}`;\n}\n\nfunction format_truncation_marker(useTokens: boolean, removedUnits: number): string {\n\tconst unit = useTokens ? \"tokens\" : \"chars\";\n\treturn `…${removedUnits} ${unit} truncated…`;\n}\n\nfunction removed_units(\n\tuseTokens: boolean,\n\tremovedBytes: number,\n\tremovedChars: number,\n): number {\n\treturn useTokens ? approx_tokens_from_byte_count(removedBytes) : removedChars;\n}\n\nfunction utf8ByteLength(value: string): number {\n\treturn new TextEncoder().encode(value).byteLength;\n}\n"]}
@@ -0,0 +1,152 @@
1
+ import { truncate_middle_chars, truncate_middle_with_token_budget, approx_token_count, approx_tokens_from_byte_count, approx_bytes_for_tokens } from './chunk-YHVCFD2D.js';
2
+
3
+ // src/upstream/codex-rs/utils/output-truncation/src/lib.ts
4
+ var DEFAULT_TRUNCATION_POLICY = {
5
+ mode: "bytes",
6
+ limit: 1e4
7
+ };
8
+ function resolve_truncation_policy(policy) {
9
+ if (isResolvedPolicy(policy)) {
10
+ return { mode: policy.mode, limit: normalizeLimit(policy.limit) };
11
+ }
12
+ if (isRecord(policy)) {
13
+ const mode = policy.mode;
14
+ const limit = normalizeLimit(policy.limit);
15
+ if (mode === "bytes" || mode === "Bytes") {
16
+ return { mode: "bytes", limit };
17
+ }
18
+ if (mode === "tokens" || mode === "Tokens") {
19
+ return { mode: "tokens", limit };
20
+ }
21
+ }
22
+ return DEFAULT_TRUNCATION_POLICY;
23
+ }
24
+ function scale_truncation_policy(policy, scale) {
25
+ const resolved = resolve_truncation_policy(policy);
26
+ return {
27
+ mode: resolved.mode,
28
+ limit: Math.max(0, Math.trunc(resolved.limit * scale))
29
+ };
30
+ }
31
+ function formatted_truncate_text(content, policy) {
32
+ const resolved = resolve_truncation_policy(policy);
33
+ if (utf8ByteLength(content) <= byte_budget(resolved)) {
34
+ return content;
35
+ }
36
+ const totalLines = content.split(/\r?\n/u).length;
37
+ return `Total output lines: ${totalLines}
38
+
39
+ ${truncate_text(content, resolved)}`;
40
+ }
41
+ function truncate_text(content, policy) {
42
+ const resolved = resolve_truncation_policy(policy);
43
+ if (resolved.mode === "bytes") {
44
+ return truncate_middle_chars(content, resolved.limit);
45
+ }
46
+ return truncate_middle_with_token_budget(content, resolved.limit)[0];
47
+ }
48
+ function formatted_truncate_text_content_items_with_policy(items, policy) {
49
+ const textSegments = items.flatMap(
50
+ (item) => item.type === "input_text" ? [item.text] : []
51
+ );
52
+ if (textSegments.length === 0) {
53
+ return [[...items], null];
54
+ }
55
+ const combined = textSegments.join("\n");
56
+ const resolved = resolve_truncation_policy(policy);
57
+ if (utf8ByteLength(combined) <= byte_budget(resolved)) {
58
+ return [[...items], null];
59
+ }
60
+ return [
61
+ [
62
+ { type: "input_text", text: formatted_truncate_text(combined, resolved) },
63
+ ...items.flatMap(
64
+ (item) => item.type === "input_image" ? [{ ...item }] : []
65
+ )
66
+ ],
67
+ approx_token_count(combined)
68
+ ];
69
+ }
70
+ function truncate_function_output_items_with_policy(items, policy) {
71
+ const resolved = resolve_truncation_policy(policy);
72
+ const output = [];
73
+ let remainingBudget = resolved.mode === "bytes" ? byte_budget(resolved) : token_budget(resolved);
74
+ let omittedTextItems = 0;
75
+ for (const item of items) {
76
+ if (item.type === "input_image") {
77
+ output.push({ ...item });
78
+ continue;
79
+ }
80
+ if (remainingBudget <= 0) {
81
+ omittedTextItems += 1;
82
+ continue;
83
+ }
84
+ const cost = resolved.mode === "bytes" ? utf8ByteLength(item.text) : approx_token_count(item.text);
85
+ if (cost <= remainingBudget) {
86
+ output.push({ ...item });
87
+ remainingBudget -= cost;
88
+ continue;
89
+ }
90
+ const snippetPolicy = {
91
+ mode: resolved.mode,
92
+ limit: remainingBudget
93
+ };
94
+ const snippet = truncate_text(item.text, snippetPolicy);
95
+ if (snippet.length === 0) {
96
+ omittedTextItems += 1;
97
+ } else {
98
+ output.push({ type: "input_text", text: snippet });
99
+ }
100
+ remainingBudget = 0;
101
+ }
102
+ if (omittedTextItems > 0) {
103
+ output.push({
104
+ type: "input_text",
105
+ text: `[omitted ${omittedTextItems} text items ...]`
106
+ });
107
+ }
108
+ return output;
109
+ }
110
+ function truncate_function_output_payload(output, policy) {
111
+ if (output.body.type === "text") {
112
+ return {
113
+ ...output,
114
+ body: { type: "text", text: truncate_text(output.body.text, policy) }
115
+ };
116
+ }
117
+ return {
118
+ ...output,
119
+ body: {
120
+ type: "content_items",
121
+ items: truncate_function_output_items_with_policy(output.body.items, policy)
122
+ }
123
+ };
124
+ }
125
+ function approx_tokens_from_byte_count_i64(bytes) {
126
+ if (bytes <= 0) {
127
+ return 0;
128
+ }
129
+ return approx_tokens_from_byte_count(bytes);
130
+ }
131
+ function byte_budget(policy) {
132
+ return policy.mode === "bytes" ? policy.limit : approx_bytes_for_tokens(policy.limit);
133
+ }
134
+ function token_budget(policy) {
135
+ return policy.mode === "tokens" ? policy.limit : approx_tokens_from_byte_count(policy.limit);
136
+ }
137
+ function isResolvedPolicy(value) {
138
+ return isRecord(value) && (value.mode === "bytes" || value.mode === "tokens") && typeof value.limit === "number";
139
+ }
140
+ function isRecord(value) {
141
+ return typeof value === "object" && value !== null && !Array.isArray(value);
142
+ }
143
+ function normalizeLimit(value) {
144
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.trunc(value) : DEFAULT_TRUNCATION_POLICY.limit;
145
+ }
146
+ function utf8ByteLength(value) {
147
+ return new TextEncoder().encode(value).byteLength;
148
+ }
149
+
150
+ export { DEFAULT_TRUNCATION_POLICY, approx_tokens_from_byte_count_i64, formatted_truncate_text, formatted_truncate_text_content_items_with_policy, resolve_truncation_policy, scale_truncation_policy, truncate_function_output_items_with_policy, truncate_function_output_payload, truncate_text };
151
+ //# sourceMappingURL=chunk-Z63UPBS3.js.map
152
+ //# sourceMappingURL=chunk-Z63UPBS3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/upstream/codex-rs/utils/output-truncation/src/lib.ts"],"names":[],"mappings":";;;AAuBO,IAAM,yBAAA,GAAsD;AAAA,EAClE,IAAA,EAAM,OAAA;AAAA,EACN,KAAA,EAAO;AACR;AAEO,SAAS,0BACf,MAAA,EAC2B;AAC3B,EAAA,IAAI,gBAAA,CAAiB,MAAM,CAAA,EAAG;AAC7B,IAAA,OAAO,EAAE,MAAM,MAAA,CAAO,IAAA,EAAM,OAAO,cAAA,CAAe,MAAA,CAAO,KAAK,CAAA,EAAE;AAAA,EACjE;AACA,EAAA,IAAI,QAAA,CAAS,MAAM,CAAA,EAAG;AACrB,IAAA,MAAM,OAAO,MAAA,CAAO,IAAA;AACpB,IAAA,MAAM,KAAA,GAAQ,cAAA,CAAe,MAAA,CAAO,KAAK,CAAA;AACzC,IAAA,IAAI,IAAA,KAAS,OAAA,IAAW,IAAA,KAAS,OAAA,EAAS;AACzC,MAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,KAAA,EAAM;AAAA,IAC/B;AACA,IAAA,IAAI,IAAA,KAAS,QAAA,IAAY,IAAA,KAAS,QAAA,EAAU;AAC3C,MAAA,OAA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AC9C,EAAA,OAAO,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,KAAK,CAAA,CAAE,UAAA;AACxC","file":"chunk-Z63UPBS3.js","sourcesContent":["import type {\n\tFunctionCallOutputContentItem,\n\tFunctionCallOutputPayload,\n\tTruncationPolicy,\n} from \"../../../core/src/protocol\";\nimport {\n\tapprox_bytes_for_tokens,\n\tapprox_token_count,\n\tapprox_tokens_from_byte_count,\n\ttruncate_middle_chars,\n\ttruncate_middle_with_token_budget,\n} from \"../../string/src/lib\";\n\nexport {\n\tapprox_bytes_for_tokens,\n\tapprox_token_count,\n\tapprox_tokens_from_byte_count,\n};\n\nexport type ResolvedTruncationPolicy =\n\t| { mode: \"bytes\"; limit: number }\n\t| { mode: \"tokens\"; limit: number };\n\nexport const DEFAULT_TRUNCATION_POLICY: ResolvedTruncationPolicy = {\n\tmode: \"bytes\",\n\tlimit: 10_000,\n};\n\nexport function resolve_truncation_policy(\n\tpolicy: TruncationPolicy | ResolvedTruncationPolicy | null | undefined,\n): ResolvedTruncationPolicy {\n\tif (isResolvedPolicy(policy)) {\n\t\treturn { mode: policy.mode, limit: normalizeLimit(policy.limit) };\n\t}\n\tif (isRecord(policy)) {\n\t\tconst mode = policy.mode;\n\t\tconst limit = normalizeLimit(policy.limit);\n\t\tif (mode === \"bytes\" || mode === \"Bytes\") {\n\t\t\treturn { mode: \"bytes\", limit };\n\t\t}\n\t\tif (mode === \"tokens\" || mode === \"Tokens\") {\n\t\t\treturn { mode: \"tokens\", limit };\n\t\t}\n\t}\n\treturn DEFAULT_TRUNCATION_POLICY;\n}\n\nexport function scale_truncation_policy(\n\tpolicy: TruncationPolicy | ResolvedTruncationPolicy | null | undefined,\n\tscale: number,\n): ResolvedTruncationPolicy {\n\tconst resolved = resolve_truncation_policy(policy);\n\treturn {\n\t\tmode: resolved.mode,\n\t\tlimit: Math.max(0, Math.trunc(resolved.limit * scale)),\n\t};\n}\n\nexport function formatted_truncate_text(\n\tcontent: string,\n\tpolicy: TruncationPolicy | ResolvedTruncationPolicy | null | undefined,\n): string {\n\tconst resolved = resolve_truncation_policy(policy);\n\tif (utf8ByteLength(content) <= byte_budget(resolved)) {\n\t\treturn content;\n\t}\n\tconst totalLines = content.split(/\\r?\\n/u).length;\n\treturn `Total output lines: ${totalLines}\\n\\n${truncate_text(content, resolved)}`;\n}\n\nexport function truncate_text(\n\tcontent: string,\n\tpolicy: TruncationPolicy | ResolvedTruncationPolicy | null | undefined,\n): string {\n\tconst resolved = resolve_truncation_policy(policy);\n\tif (resolved.mode === \"bytes\") {\n\t\treturn truncate_middle_chars(content, resolved.limit);\n\t}\n\treturn truncate_middle_with_token_budget(content, resolved.limit)[0];\n}\n\nexport function formatted_truncate_text_content_items_with_policy(\n\titems: readonly FunctionCallOutputContentItem[],\n\tpolicy: TruncationPolicy | ResolvedTruncationPolicy | null | undefined,\n): [FunctionCallOutputContentItem[], number | null] {\n\tconst textSegments = items.flatMap((item) =>\n\t\titem.type === \"input_text\" ? [item.text] : [],\n\t);\n\tif (textSegments.length === 0) {\n\t\treturn [[...items], null];\n\t}\n\n\tconst combined = textSegments.join(\"\\n\");\n\tconst resolved = resolve_truncation_policy(policy);\n\tif (utf8ByteLength(combined) <= byte_budget(resolved)) {\n\t\treturn [[...items], null];\n\t}\n\n\treturn [\n\t\t[\n\t\t\t{ type: \"input_text\", text: formatted_truncate_text(combined, resolved) },\n\t\t\t...items.flatMap((item) =>\n\t\t\t\titem.type === \"input_image\" ? [{ ...item }] : [],\n\t\t\t),\n\t\t],\n\t\tapprox_token_count(combined),\n\t];\n}\n\nexport function truncate_function_output_items_with_policy(\n\titems: readonly FunctionCallOutputContentItem[],\n\tpolicy: TruncationPolicy | ResolvedTruncationPolicy | null | undefined,\n): FunctionCallOutputContentItem[] {\n\tconst resolved = resolve_truncation_policy(policy);\n\tconst output: FunctionCallOutputContentItem[] = [];\n\tlet remainingBudget =\n\t\tresolved.mode === \"bytes\" ? byte_budget(resolved) : token_budget(resolved);\n\tlet omittedTextItems = 0;\n\n\tfor (const item of items) {\n\t\tif (item.type === \"input_image\") {\n\t\t\toutput.push({ ...item });\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (remainingBudget <= 0) {\n\t\t\tomittedTextItems += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst cost =\n\t\t\tresolved.mode === \"bytes\" ? utf8ByteLength(item.text) : approx_token_count(item.text);\n\t\tif (cost <= remainingBudget) {\n\t\t\toutput.push({ ...item });\n\t\t\tremainingBudget -= cost;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst snippetPolicy: ResolvedTruncationPolicy = {\n\t\t\tmode: resolved.mode,\n\t\t\tlimit: remainingBudget,\n\t\t};\n\t\tconst snippet = truncate_text(item.text, snippetPolicy);\n\t\tif (snippet.length === 0) {\n\t\t\tomittedTextItems += 1;\n\t\t} else {\n\t\t\toutput.push({ type: \"input_text\", text: snippet });\n\t\t}\n\t\tremainingBudget = 0;\n\t}\n\n\tif (omittedTextItems > 0) {\n\t\toutput.push({\n\t\t\ttype: \"input_text\",\n\t\t\ttext: `[omitted ${omittedTextItems} text items ...]`,\n\t\t});\n\t}\n\n\treturn output;\n}\n\nexport function truncate_function_output_payload(\n\toutput: FunctionCallOutputPayload,\n\tpolicy: TruncationPolicy | ResolvedTruncationPolicy | null | undefined,\n): FunctionCallOutputPayload {\n\tif (output.body.type === \"text\") {\n\t\treturn {\n\t\t\t...output,\n\t\t\tbody: { type: \"text\", text: truncate_text(output.body.text, policy) },\n\t\t};\n\t}\n\treturn {\n\t\t...output,\n\t\tbody: {\n\t\t\ttype: \"content_items\",\n\t\t\titems: truncate_function_output_items_with_policy(output.body.items, policy),\n\t\t},\n\t};\n}\n\nexport function approx_tokens_from_byte_count_i64(bytes: number): number {\n\tif (bytes <= 0) {\n\t\treturn 0;\n\t}\n\treturn approx_tokens_from_byte_count(bytes);\n}\n\nfunction byte_budget(policy: ResolvedTruncationPolicy): number {\n\treturn policy.mode === \"bytes\" ? policy.limit : approx_bytes_for_tokens(policy.limit);\n}\n\nfunction token_budget(policy: ResolvedTruncationPolicy): number {\n\treturn policy.mode === \"tokens\"\n\t\t? policy.limit\n\t\t: approx_tokens_from_byte_count(policy.limit);\n}\n\nfunction isResolvedPolicy(value: unknown): value is ResolvedTruncationPolicy {\n\treturn (\n\t\tisRecord(value) &&\n\t\t(value.mode === \"bytes\" || value.mode === \"tokens\") &&\n\t\ttypeof value.limit === \"number\"\n\t);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction normalizeLimit(value: unknown): number {\n\treturn typeof value === \"number\" && Number.isFinite(value) && value >= 0\n\t\t? Math.trunc(value)\n\t\t: DEFAULT_TRUNCATION_POLICY.limit;\n}\n\nfunction utf8ByteLength(value: string): number {\n\treturn new TextEncoder().encode(value).byteLength;\n}\n"]}
@@ -1,111 +1,16 @@
1
- import { R as Result } from '../session-BO6EZNK7.js';
2
- export { A as AppServerEvent, a as AppServerRequestHandle, b as AppServerSession, c as ClientRequest, C as CodexAppServer, I as InitializeParams, d as InitializeResponse, T as TypedRequestError, r as requestMethodName, e as requestTyped, s as serverNotificationRequiresDelivery } from '../session-BO6EZNK7.js';
3
- import { E as ExecPolicyAmendment, N as NetworkPolicyAmendment, j as AdditionalNetworkPermissions, k as AdditionalFileSystemPermissions, J as JsonValue, a as ServerRequest, l as RequestId } from '../thread_event_store-BIS0qzhi.js';
4
- export { S as ServerNotification, m as ThreadEventSnapshot, n as ThreadEventStore, o as ThreadTokenUsageSnapshot, s as serverNotificationThreadTarget, p as serverRequestThreadId, t as threadEventSnapshotHasStarted } from '../thread_event_store-BIS0qzhi.js';
5
- export { a as CodexAppServerClientConnectionStatus, C as CodexAppServerClientOptions, b as CodexAppServerClientTransportError, c as createCodexAppServerClient, p as parseCodexAppServerEvent } from '../remote-DMPfepa9.js';
6
- import { D as DynamicToolCallResponse } from '../DynamicToolCallResponse-D2OVpa4p.js';
7
- import { T as ToolRequestUserInputResponse } from '../ToolRequestUserInputResponse-Bxjlpgho.js';
8
-
9
- type CommandExecutionApprovalDecision = "accept" | "acceptForSession" | {
10
- "acceptWithExecpolicyAmendment": {
11
- execpolicy_amendment: ExecPolicyAmendment;
12
- };
13
- } | {
14
- "applyNetworkPolicyAmendment": {
15
- network_policy_amendment: NetworkPolicyAmendment;
16
- };
17
- } | "decline" | "cancel";
18
-
19
- type CommandExecutionRequestApprovalResponse = {
20
- decision: CommandExecutionApprovalDecision;
21
- };
22
-
23
- type FileChangeApprovalDecision = "accept" | "acceptForSession" | "decline" | "cancel";
24
-
25
- type FileChangeRequestApprovalResponse = {
26
- decision: FileChangeApprovalDecision;
27
- };
28
-
29
- type GrantedPermissionProfile = {
30
- network?: AdditionalNetworkPermissions;
31
- fileSystem?: AdditionalFileSystemPermissions;
32
- };
33
-
34
- type McpServerElicitationAction = "accept" | "decline" | "cancel";
35
-
36
- type McpServerElicitationRequestResponse = {
37
- action: McpServerElicitationAction;
38
- /**
39
- * Structured user input for accepted elicitations, mirroring RMCP `CreateElicitationResult`.
40
- *
41
- * This is nullable because decline/cancel responses have no content.
42
- */
43
- content: JsonValue | null;
44
- /**
45
- * Optional client metadata for form-mode action handling.
46
- */
47
- _meta: JsonValue | null;
48
- };
49
-
50
- type PermissionGrantScope = "turn" | "session";
51
-
52
- type PermissionsRequestApprovalResponse = {
53
- permissions: GrantedPermissionProfile;
54
- scope: PermissionGrantScope;
55
- /**
56
- * Review every subsequent command in this turn before normal sandboxed execution.
57
- */
58
- strictAutoReview?: boolean;
59
- };
60
-
61
- type AppServerRequestResolution = {
62
- requestId: RequestId;
63
- result: Result;
64
- };
65
- type UnsupportedAppServerRequest = {
66
- message: string;
67
- requestId: RequestId;
68
- };
69
- type ResolvedAppServerRequest = {
70
- id: string;
71
- type: "exec_approval";
72
- } | {
73
- id: string;
74
- type: "file_change_approval";
75
- } | {
76
- id: string;
77
- type: "permissions_approval";
78
- } | {
79
- itemId: string;
80
- type: "user_input";
81
- } | {
82
- requestId: RequestId;
83
- serverName: string;
84
- type: "mcp_elicitation";
85
- } | {
86
- callId: string;
87
- type: "dynamic_tool_call";
88
- };
89
- declare class PendingAppServerRequests {
90
- private readonly dynamicToolCalls;
91
- private readonly execApprovals;
92
- private readonly fileChangeApprovals;
93
- private readonly mcpRequests;
94
- private readonly permissionsApprovals;
95
- private readonly userInputs;
96
- clear(): void;
97
- noteServerRequest(request: ServerRequest): UnsupportedAppServerRequest | null;
98
- takeCommandExecutionApprovalResolution(id: string, response: CommandExecutionRequestApprovalResponse): AppServerRequestResolution | null;
99
- takeFileChangeApprovalResolution(id: string, response: FileChangeRequestApprovalResponse): AppServerRequestResolution | null;
100
- takePermissionsApprovalResolution(id: string, response: PermissionsRequestApprovalResponse): AppServerRequestResolution | null;
101
- takeDynamicToolCallResolution(callId: string, response: DynamicToolCallResponse): AppServerRequestResolution | null;
102
- takeUserInputResolution(turnId: string, response: ToolRequestUserInputResponse): AppServerRequestResolution | null;
103
- takeMcpElicitationResolution(serverName: string, requestId: RequestId, response: McpServerElicitationRequestResponse): AppServerRequestResolution | null;
104
- resolveNotification(requestId: RequestId): ResolvedAppServerRequest | null;
105
- containsServerRequest(request: ServerRequest): boolean;
106
- private requestIds;
107
- private popUserInputRequestForTurn;
108
- private removeUserInputRequest;
109
- }
110
-
111
- export { PendingAppServerRequests, RequestId, ServerRequest };
1
+ export { C as ClientRequest, I as InitializeParams } from '../ThreadResumeResponse-DvmE1juU.js';
2
+ export { I as InitializeResponse } from '../TurnSteerResponse-0kBCfplh.js';
3
+ export { R as RequestId } from '../ToolRequestUserInputQuestion-CeZa5X1J.js';
4
+ export { S as ServerNotification, a as ServerRequest } from '../ServerRequest-B5cKVJjr.js';
5
+ export { A as AppServerEvent, a as AppServerRequestHandle, T as TypedRequestError, r as requestMethodName, b as requestTyped, s as serverNotificationRequiresDelivery } from '../lib-nXlaKiS-.js';
6
+ export { a as CodexAppServerClientConnectionStatus, C as CodexAppServerClientOptions, b as CodexAppServerClientTransportError, c as createCodexAppServerClient, p as parseCodexAppServerEvent } from '../remote-ClZbq9KN.js';
7
+ export { A as AppServerSession, C as CodexAppServer } from '../session-BRYzi8OT.js';
8
+ export { a as ThreadEventSnapshot, b as ThreadEventStore, c as ThreadTokenUsageSnapshot, s as serverNotificationThreadTarget, d as serverRequestThreadId, t as threadEventSnapshotHasStarted } from '../thread_event_store-C0zYzukG.js';
9
+ export { P as PendingAppServerRequests } from '../index-77U_Oc-a.js';
10
+ import '../rendered-thread-AOxw3V5b.js';
11
+ import '../protocol-mpBcYHrm.js';
12
+ import '../types-BTeabLYr.js';
13
+ import '../thread-history-builder-zW0zeqcS.js';
14
+ import '../PermissionsRequestApprovalResponse-DxzPPDRb.js';
15
+ import '../DynamicToolCallResponse-82DFjES2.js';
16
+ import '../ToolRequestUserInputResponse-zcPLwbiK.js';
@@ -1,4 +1,16 @@
1
1
  import '../chunk-ZX5OIIJX.js';
2
- export { AppServerSession, CodexAppServerClientTransportError, PendingAppServerRequests, ThreadEventStore, createCodexAppServerClient, parseCodexAppServerEvent, requestMethodName, requestTyped, serverNotificationRequiresDelivery, serverNotificationThreadTarget, serverRequestThreadId, threadEventSnapshotHasStarted } from '../chunk-TZBLUZ2X.js';
2
+ export { AppServerSession, CodexAppServerClientTransportError, PendingAppServerRequests, ThreadEventStore, createCodexAppServerClient, parseCodexAppServerEvent, requestMethodName, requestTyped, serverNotificationRequiresDelivery, serverNotificationThreadTarget, serverRequestThreadId, threadEventSnapshotHasStarted } from '../chunk-6ZMJ34KE.js';
3
+ import '../chunk-4DPLJPB5.js';
4
+ import '../chunk-V4BMZWBM.js';
5
+ import '../chunk-LWQNX4LI.js';
6
+ import '../chunk-PST3ZWX2.js';
7
+ import '../chunk-Z63UPBS3.js';
8
+ import '../chunk-YHVCFD2D.js';
9
+ import '../chunk-DCMKA2A6.js';
10
+ import '../chunk-CGBS37IU.js';
11
+ import '../chunk-2DZRMCI2.js';
12
+ import '../chunk-DYLHN3HG.js';
13
+ import '../chunk-SYPHCDRD.js';
14
+ import '../chunk-O44XP7LH.js';
3
15
  //# sourceMappingURL=index.js.map
4
16
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,161 @@
1
+ import { E as EventMsg, a5 as DynamicToolResponse, k as Submission, l as ThreadId, j as RolloutItem, x as TokenUsageInfo } from '../../protocol-mpBcYHrm.js';
2
+ import { E as EventMappingContext, A as AppServerProtocolEvent } from '../../event-mapping-CbISdQ1D.js';
3
+ export { S as ServerRequestCoreTarget, s as serverRequestResolvedNotification } from '../../event-mapping-CbISdQ1D.js';
4
+ export { a2 as AppServerEvent, C as CodexAppServerConnectionRequestOutcome, a as CodexAppServerConnectionSessionState, b as CodexAppServerDeferredResponse, c as CodexAppServerEventSink, d as CodexAppServerMessageProcessor, e as CodexAppServerMessageProcessorOptions, f as CodexAppServerMethodHandlers, g as CodexAppServerOutgoingSink, h as CodexAppServerRequestContext, i as CodexAppServerRequestError, j as CodexAppServerRuntime, k as CodexAppServerRuntimeContext, l as CodexAppServerRuntimeOptions, a3 as CodexSessionTaskRunner, a4 as CodexSessionTaskRunnerCreateModelClientInput, a5 as CodexSessionTaskRunnerOptions, m as ConnectionId, n as ConnectionOrigin, o as ConnectionRequestId, p as ConnectionRpcGate, q as ConnectionRpcGateClosedError, I as InitializedConnectionSessionState, J as JSONRPCError, a6 as JSONRPCErrorError, r as JSONRPCMessage, s as JSONRPCNotification, t as JSONRPCRequest, u as JSONRPCResponse, M as McpRequestProcessor, a7 as McpRequestProcessorOptions, O as OutgoingError, v as OutgoingMessage, w as OutgoingMessageSender, a8 as OutgoingMessageSenderOptions, x as OutgoingResponse, a9 as OutgoingServerRequestHandle, P as ParsedClientTransportMessage, y as ParsedServerTransportMessage, z as ParsedTransportPayload, aa as ProcessorCreateSession, ab as ProcessorEmit, Q as QueuedOutgoingMessage, R as RequestContext, A as RequestSerializationQueueKey, B as RequestSerializationQueues, ac as Result, D as RuntimeSession, T as ThreadRequestProcessor, ad as ThreadRequestProcessorOptions, E as ThreadScopedOutgoingMessageSender, F as TransportEvent, G as TurnRequestProcessor, ae as TurnRequestProcessorOptions, af as TurnStartParamsWithClientMessageId, ag as TurnStartParamsWithCollaborationMode, ah as appServerUserInputToCoreUserInput, ai as approvalPolicyString, H as codexAppServerDeferredResponse, K as createCodexAppServerRuntime, aj as defaultId, ak as errorToJsonRpcError, al as jsonRpcError, L as jsonRpcInternalError, N as jsonRpcInvalidRequestError, S as jsonRpcParseError, U as outgoingMessageToAppServerEvent, V as parseClientTransportPayload, W as parseJsonRpcMessage, X as parseJsonRpcTransportPayload, Y as parseServerTransportPayload, Z as queuedOutgoingMessage, _ as requestSerializationQueueKeyFromScope, $ as serializeJsonRpcError, a0 as serializeJsonRpcResponse, a1 as serializeOutgoingMessage, am as steerErrorCode, an as threadIdFromStartParams, ao as unsupportedMethodError, ap as valueOrNull } from '../../runtime-Cm6ml53h.js';
5
+ import { D as DynamicToolCallResponse } from '../../DynamicToolCallResponse-82DFjES2.js';
6
+ import { R as RequestId } from '../../ToolRequestUserInputQuestion-CeZa5X1J.js';
7
+ import { a as ServerRequest, T as Thread, c as Turn, S as ServerNotification } from '../../ServerRequest-B5cKVJjr.js';
8
+ import { J as JSONRPCErrorError } from '../../lib-nXlaKiS-.js';
9
+ import { g as SessionConfiguration, b as Event, h as Session, M as McpConnectionManager } from '../../history-CfM-4V7b.js';
10
+ import { k as ThreadStartParams, h as ThreadResumeParams, n as TurnStartParams, d as ThreadCompactStartParams } from '../../ThreadResumeResponse-DvmE1juU.js';
11
+ import { T as ThreadStore } from '../../store-AGRxhgQ3.js';
12
+ import '../../ClientNotification-B6-FhXQf.js';
13
+ import '../../TurnSteerResponse-0kBCfplh.js';
14
+ import '../../types-BTeabLYr.js';
15
+ import '../../common-CTyph5x8.js';
16
+ import '../../index-CoDZosq0.js';
17
+ import '../../spec_plan_types-CmsJ-Tfn.js';
18
+ import '../../WebSearchToolConfig-D3ep0625.js';
19
+ import '../../live-thread-BMvlflzM.js';
20
+ import '../../responses_websocket-BhxSgCzK.js';
21
+
22
+ declare function apply_bespoke_event_handling(msg: EventMsg, context: EventMappingContext): AppServerProtocolEvent[];
23
+
24
+ declare function coreDynamicToolResponseFromAppServerResponse(value: unknown): DynamicToolResponse;
25
+ declare function decodeDynamicToolCallResponse(value: unknown): DynamicToolCallResponse;
26
+ declare function fallbackDynamicToolCallResponse(message: string): DynamicToolCallResponse;
27
+
28
+ type ServerRequestResponseTarget = {
29
+ responseId: string;
30
+ type: "user_input";
31
+ } | {
32
+ callId: string;
33
+ type: "request_permissions";
34
+ } | {
35
+ callId: string;
36
+ type: "dynamic_tool";
37
+ } | {
38
+ requestId: string | number;
39
+ serverName: string;
40
+ type: "mcp_elicitation";
41
+ };
42
+ declare function submissionFromServerRequestResult(input: {
43
+ request: ServerRequest | null;
44
+ requestId: RequestId;
45
+ result: unknown;
46
+ target?: ServerRequestResponseTarget | null;
47
+ }): Submission;
48
+ declare function submissionFromServerRequestError(input: {
49
+ error: JSONRPCErrorError;
50
+ request: ServerRequest | null;
51
+ requestId: RequestId;
52
+ target?: ServerRequestResponseTarget | null;
53
+ }): Submission;
54
+ declare function isServerRequestResponseSubmission(submission: Submission): boolean;
55
+
56
+ type CodexSessionRequestParams = ThreadStartParams | ThreadResumeParams | TurnStartParams | ThreadCompactStartParams;
57
+ type CodexSessionFactoryOptions<Context = unknown> = {
58
+ buildSessionConfiguration?: (input: {
59
+ context?: Context;
60
+ params: CodexSessionRequestParams;
61
+ thread: Awaited<ReturnType<ThreadStore["readThread"]>>;
62
+ }) => Partial<SessionConfiguration> | Promise<Partial<SessionConfiguration>>;
63
+ createSession?: (input: {
64
+ context?: Context;
65
+ eventSink: (event: Event) => void;
66
+ params: CodexSessionRequestParams;
67
+ submission?: Submission;
68
+ threadId: ThreadId;
69
+ }) => Session | Promise<Session>;
70
+ emitCoreEvent: (threadId: ThreadId, event: Event, context?: Context) => void;
71
+ mcpConnectionManager?: McpConnectionManager | null;
72
+ store: ThreadStore;
73
+ };
74
+ declare class CodexSessionFactory<Context = unknown> {
75
+ private readonly options;
76
+ constructor(options: CodexSessionFactoryOptions<Context>);
77
+ createSession: (input: {
78
+ context?: Context;
79
+ params: CodexSessionRequestParams;
80
+ submission?: Submission;
81
+ threadId: ThreadId;
82
+ }) => Promise<Session>;
83
+ }
84
+
85
+ type TokenUsageTurnOwner = {
86
+ id: string;
87
+ position: number | null;
88
+ };
89
+ declare function latest_token_usage_turn_id_from_rollout_items(rolloutItems: readonly RolloutItem[], turns: readonly Turn[]): string | null;
90
+ declare function latest_token_usage_turn_id(thread: Thread): string;
91
+ declare function last_token_info_from_rollout_items(rolloutItems: readonly RolloutItem[]): TokenUsageInfo | null;
92
+ declare function thread_token_usage_updated_notification_from_info(input: {
93
+ thread: Thread;
94
+ threadId: ThreadId | string;
95
+ tokenUsageInfo: TokenUsageInfo;
96
+ tokenUsageTurnId?: string | null;
97
+ }): ServerNotification;
98
+ declare function thread_token_usage_updated_notification_from_rollout_items(input: {
99
+ rolloutItems: readonly RolloutItem[];
100
+ thread: Thread;
101
+ threadId: ThreadId | string;
102
+ }): ServerNotification | null;
103
+
104
+ type PendingInterruptQueue = RequestId[];
105
+ type PendingThreadResumeRequest = {
106
+ includeTurns: boolean;
107
+ requestId: RequestId;
108
+ threadId: ThreadId;
109
+ };
110
+ type ThreadListenerCommand = {
111
+ request: PendingThreadResumeRequest;
112
+ type: "send_thread_resume_response";
113
+ } | {
114
+ requestId: RequestId;
115
+ type: "resolve_server_request";
116
+ };
117
+ type TurnSummary = {
118
+ lastError: {
119
+ message: string;
120
+ } | null;
121
+ startedAt: number | null;
122
+ };
123
+ type ThreadStateTrackResult = {
124
+ activeTurn: Turn | null;
125
+ terminalTurn: Turn | null;
126
+ };
127
+ declare class ThreadState {
128
+ pendingInterrupts: PendingInterruptQueue;
129
+ turnSummary: TurnSummary;
130
+ lastTerminalTurnId: string | null;
131
+ experimentalRawEvents: boolean;
132
+ listenerGeneration: number;
133
+ private currentTurnHistory;
134
+ private listenerActive;
135
+ setListener(): number;
136
+ clearListener(): void;
137
+ hasListener(): boolean;
138
+ setExperimentalRawEvents(enabled: boolean): void;
139
+ activeTurnSnapshot(): Turn | null;
140
+ trackCurrentTurnEvent(eventTurnId: string, event: EventMsg): ThreadStateTrackResult;
141
+ }
142
+ declare class ThreadStateManager {
143
+ private readonly liveConnections;
144
+ private readonly threads;
145
+ private readonly threadIdsByConnection;
146
+ connectionInitialized(connectionId: number): void;
147
+ threadState(threadId: ThreadId): ThreadState;
148
+ removeThreadState(threadId: ThreadId): void;
149
+ clearAllListeners(): void;
150
+ subscribedConnectionIds(threadId: ThreadId): number[];
151
+ tryEnsureConnectionSubscribed(threadId: ThreadId, connectionId: number, experimentalRawEvents?: boolean): ThreadState | null;
152
+ unsubscribeConnectionFromThread(threadId: ThreadId, connectionId: number): boolean;
153
+ removeConnection(connectionId: number): ThreadId[];
154
+ private threadEntry;
155
+ }
156
+
157
+ type AppServerAdapterBoundary = {
158
+ readonly kind: "app-server-adapter-boundary";
159
+ };
160
+
161
+ export { type AppServerAdapterBoundary, AppServerProtocolEvent, CodexSessionFactory, type CodexSessionFactoryOptions, type CodexSessionRequestParams, EventMappingContext, type PendingInterruptQueue, type PendingThreadResumeRequest, type ServerRequestResponseTarget, type ThreadListenerCommand, ThreadState, ThreadStateManager, type ThreadStateTrackResult, type TokenUsageTurnOwner, type TurnSummary, apply_bespoke_event_handling, coreDynamicToolResponseFromAppServerResponse, decodeDynamicToolCallResponse, fallbackDynamicToolCallResponse, isServerRequestResponseSubmission, last_token_info_from_rollout_items, latest_token_usage_turn_id, latest_token_usage_turn_id_from_rollout_items, submissionFromServerRequestError, submissionFromServerRequestResult, thread_token_usage_updated_notification_from_info, thread_token_usage_updated_notification_from_rollout_items };
@@ -0,0 +1,13 @@
1
+ export { CodexAppServerConnectionSessionState, CodexAppServerMessageProcessor, CodexAppServerRequestError, CodexSessionFactory, CodexSessionTaskRunner, ConnectionRpcGate, ConnectionRpcGateClosedError, McpRequestProcessor, OutgoingMessageSender, RequestSerializationQueues, ThreadRequestProcessor, ThreadScopedOutgoingMessageSender, ThreadState, ThreadStateManager, TurnRequestProcessor, appServerUserInputToCoreUserInput, apply_bespoke_event_handling, approvalPolicyString, codexAppServerDeferredResponse, coreDynamicToolResponseFromAppServerResponse, createCodexAppServerRuntime, decodeDynamicToolCallResponse, defaultId, errorToJsonRpcError, fallbackDynamicToolCallResponse, isServerRequestResponseSubmission, jsonRpcError, jsonRpcInternalError, jsonRpcInvalidRequestError, jsonRpcParseError, last_token_info_from_rollout_items, latest_token_usage_turn_id, latest_token_usage_turn_id_from_rollout_items, outgoingMessageToAppServerEvent, parseClientTransportPayload, parseJsonRpcMessage, parseJsonRpcTransportPayload, parseServerTransportPayload, queuedOutgoingMessage, requestSerializationQueueKeyFromScope, serializeJsonRpcError, serializeJsonRpcResponse, serializeOutgoingMessage, steerErrorCode, submissionFromServerRequestError, submissionFromServerRequestResult, threadIdFromStartParams, thread_token_usage_updated_notification_from_info, thread_token_usage_updated_notification_from_rollout_items, unsupportedMethodError, valueOrNull } from '../../chunk-V4BMZWBM.js';
2
+ import '../../chunk-LWQNX4LI.js';
3
+ import '../../chunk-PST3ZWX2.js';
4
+ import '../../chunk-Z63UPBS3.js';
5
+ import '../../chunk-YHVCFD2D.js';
6
+ import '../../chunk-DCMKA2A6.js';
7
+ import '../../chunk-CGBS37IU.js';
8
+ export { serverRequestResolvedNotification } from '../../chunk-2DZRMCI2.js';
9
+ import '../../chunk-DYLHN3HG.js';
10
+ import '../../chunk-SYPHCDRD.js';
11
+ import '../../chunk-O44XP7LH.js';
12
+ //# sourceMappingURL=index.js.map
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}