mirror of
https://github.com/openai/codex.git
synced 2026-05-02 12:21:26 +03:00
Merge remote-tracking branch 'origin/main' into pakrym/redo-codemode-to-link-against
# Conflicts: # codex-rs/core/src/tools/code_mode.rs # codex-rs/core/src/tools/code_mode_runner.cjs # codex-rs/core/src/tools/spec.rs # codex-rs/core/tests/suite/code_mode.rs
This commit is contained in:
@@ -16,8 +16,11 @@ pub enum ToolKind {
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
|
||||
pub struct EnabledTool {
|
||||
pub tool_name: String,
|
||||
#[serde(rename = "module")]
|
||||
pub module_path: String,
|
||||
pub namespace: Vec<String>,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub kind: ToolKind,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
const __codexEnabledTools = __CODE_MODE_ENABLED_TOOLS_PLACEHOLDER__;
|
||||
const __codexEnabledToolNames = __codexEnabledTools.map((tool) => tool.tool_name);
|
||||
const __codexAllTools = Object.freeze(
|
||||
__codexEnabledTools.map((tool) =>
|
||||
Object.freeze({
|
||||
module: tool.module,
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const __codexTools = Object.create(null);
|
||||
const __codexContentItems = Array.isArray(globalThis.__codexContentItems)
|
||||
? globalThis.__codexContentItems
|
||||
: [];
|
||||
@@ -87,6 +97,12 @@ Object.defineProperty(globalThis, '__codexStoredValues', {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
});
|
||||
Object.defineProperty(globalThis, 'ALL_TOOLS', {
|
||||
value: __codexAllTools,
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
});
|
||||
|
||||
globalThis.codex = {
|
||||
enabledTools: Object.freeze(__codexEnabledToolNames.slice()),
|
||||
@@ -135,13 +151,6 @@ globalThis.__codex_set_max_output_tokens_per_exec_call = (value) => {
|
||||
return __codex_set_max_output_tokens_per_exec_call_native(value);
|
||||
};
|
||||
|
||||
globalThis.tools = new Proxy(Object.create(null), {
|
||||
get(_target, prop) {
|
||||
const name = String(prop);
|
||||
return async (args) => __codex_tool_call(name, args);
|
||||
},
|
||||
});
|
||||
|
||||
globalThis.console = Object.freeze({
|
||||
log() {},
|
||||
info() {},
|
||||
@@ -151,12 +160,25 @@ globalThis.console = Object.freeze({
|
||||
});
|
||||
|
||||
for (const name of __codexEnabledToolNames) {
|
||||
if (/^[A-Za-z_$][0-9A-Za-z_$]*$/.test(name) && !(name in globalThis)) {
|
||||
Object.defineProperty(__codexTools, name, {
|
||||
value: async (args) => __codex_tool_call(name, args),
|
||||
configurable: false,
|
||||
enumerable: true,
|
||||
writable: false,
|
||||
});
|
||||
if (!(name in globalThis)) {
|
||||
Object.defineProperty(globalThis, name, {
|
||||
value: async (args) => __codex_tool_call(name, args),
|
||||
value: __codexTools[name],
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(globalThis, 'tools', {
|
||||
value: Object.freeze(__codexTools),
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
});
|
||||
|
||||
@@ -198,7 +198,7 @@ fn create_tools_module<'s>(
|
||||
scope: &mut v8::PinScope<'s, '_>,
|
||||
enabled_tools: &[EnabledTool],
|
||||
) -> Result<v8::Local<'s, v8::Module>, String> {
|
||||
let mut export_names = vec![v8_string(scope, "tools")?];
|
||||
let mut export_names = vec![v8_string(scope, "tools")?, v8_string(scope, "ALL_TOOLS")?];
|
||||
for tool in enabled_tools {
|
||||
if tool.tool_name != "tools" && is_valid_identifier(&tool.tool_name) {
|
||||
export_names.push(v8_string(scope, &tool.tool_name)?);
|
||||
@@ -229,6 +229,13 @@ fn evaluate_tools_module<'s>(
|
||||
return throw_v8_exception(scope, "code_mode tools namespace is not an object");
|
||||
};
|
||||
module.set_synthetic_module_export(scope, global_name, tools_object.into())?;
|
||||
let Some(all_tools_name) = v8::String::new(scope, "ALL_TOOLS") else {
|
||||
return throw_v8_exception(scope, "failed to allocate ALL_TOOLS export name");
|
||||
};
|
||||
let Some(all_tools_value) = global.get(scope, all_tools_name.into()) else {
|
||||
return throw_v8_exception(scope, "code_mode ALL_TOOLS export is unavailable");
|
||||
};
|
||||
module.set_synthetic_module_export(scope, all_tools_name, all_tools_value)?;
|
||||
|
||||
let enabled_tools = match scope.get_slot::<RuntimeState>() {
|
||||
Some(runtime_state) => runtime_state.enabled_tools.clone(),
|
||||
|
||||
Reference in New Issue
Block a user