Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:2aronS Duel Agents buildOpenClawPatch

From Leeroopedia
Knowledge Sources
Domains Configuration, Developer_Tools
Last Updated 2026-10-27 14:00 GMT

Overview

Concrete tool for constructing the JSON patch object that adds the Duel provider to an OpenClaw config, with the API key as an environment-variable reference rather than plaintext, provided by @duel-agents/core.

Description

The buildOpenClawPatch function is a pure factory that returns the patch object to be deep-merged into an existing OpenClaw config. The key design property is that the API key is referenced as "${DUEL_API_KEY}" — an interpolation placeholder — and never written as plaintext. The actual key is written separately to ~/.openclaw/.env by the caller.

The patch object contains three top-level keys:

  • models — sets merge mode and adds the duel provider with the duel-auto model
  • agents — sets the default model to duel/duel-auto with alias Duel
  • env — sets DUEL_PROXY_URL (the proxy URL is not secret)

The output of this function matches the reference file integrations/openclaw/duel-provider.json exactly.

Usage

Import this function when you need to:

  • Construct the OpenClaw patch object programmatically
  • Inspect the expected patch shape for testing or documentation
  • Build a custom patch that extends the Duel provider entry

Code Reference

Source Location

  • Repository: Duel-Agents
  • File: packages/core/src/config.ts (lines 99-139)
  • Reference: integrations/openclaw/duel-provider.json (matches output)

Signature

export function buildOpenClawPatch(
  apiKey: string,
  proxyUrl?: string,           // default: getProxyUrl()
): Record<string, unknown>;

Import

import { buildOpenClawPatch } from "@duel-agents/core";

I/O Contract

Inputs

Name Type Required Description
apiKey string Yes Validated key (re-validated; not stored in output)
proxyUrl string No Proxy URL (default getProxyUrl())

Outputs

Name Type Description
returns Record<string, unknown> Patch object with ${DUEL_API_KEY} placeholder

Usage Examples

Build and Inspect the Patch

import { buildOpenClawPatch } from "@duel-agents/core";

const patch = buildOpenClawPatch("duel_abcd1234_...");
console.log(JSON.stringify(patch, null, 2));
// {
//   "models": { "mode": "merge", "providers": { "duel": {
//     "baseUrl": "https://duelagents.com/v1",
//     "apiKey": "${DUEL_API_KEY}",   ← placeholder, NOT plaintext
//     "api": "openai-completions",
//     "models": [{ "id": "duel-auto", ... }]
//   }}},
//   "agents": { "defaults": { "model": { "primary": "duel/duel-auto" }, ... }},
//   "env": { "DUEL_PROXY_URL": "https://duelagents.com/v1" }
// }

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment