Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/JAVA/Openclaw/extensions/feishu/src/   (KI Agentensystem Version 22©)  Datei vom 26.3.2026 mit Größe 2 kB image not shown  

Quelle  tool-factory-test-harness.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import type { OpenClawPluginApi } from "../runtime-api.js";

type ToolContextLike = {
  agentAccountId?: string;
};

export type ToolLike = {
  name: string;
  execute: (
    toolCallId: string,
    params: unknown,
  ) => Promise<{ details: Record<string, unknown> }> | { details: Record<string, unknown> };
};

type RegisteredTool = {
  tool: unknown;
  opts?: { name?: string };
};

function toToolList(value: unknown): unknown[] {
  if (!value) {
    return [];
  }
  return Array.isArray(value) ? value : [value];
}

function asToolLike(tool: unknown, fallbackName?: string): ToolLike {
  const candidate = tool as Partial<ToolLike>;
  const name = candidate.name ?? fallbackName;
  const execute = candidate.execute;
  if (!name || typeof execute !== "function") {
    throw new Error(`Resolved tool is missing required fields (name=${String(name)})`);
  }
  return {
    name,
    execute: (toolCallId, params) => execute(toolCallId, params),
  };
}

export function createToolFactoryHarness(cfg: OpenClawPluginApi["config"]) {
  const registered: RegisteredTool[] = [];

  const api: Pick<OpenClawPluginApi, "config" | "logger" | "registerTool"> = {
    config: cfg,
    logger: {
      info: () => {},
      warn: () => {},
      error: () => {},
      debug: () => {},
    },
    registerTool: (tool, opts) => {
      registered.push({ tool, opts });
    },
  };

  const resolveTool = (name: string, ctx: ToolContextLike = {}): ToolLike => {
    for (const entry of registered) {
      if (entry.opts?.name === name && typeof entry.tool !== "function") {
        return asToolLike(entry.tool, name);
      }

      if (typeof entry.tool === "function") {
        const builtTools = toToolList(entry.tool(ctx));
        const hit = builtTools.find((tool) => (tool as { name?: string }).name === name);
        if (hit) {
          return asToolLike(hit, name);
        }
      } else if ((entry.tool as { name?: string }).name === name) {
        return asToolLike(entry.tool, name);
      }
    }
    throw new Error(`Tool not registered: ${name}`);
  };

  return {
    api: api as OpenClawPluginApi,
    resolveTool,
  };
}

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.