Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openclaw/ui/src/ui/chat/   (KI Agentensystem Version 22©)  Datei vom 26.3.2026 mit Größe 13 kB image not shown  

Quelle  message-normalizer.test.ts

  Sprache: JAVA
 

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import {
  normalizeMessage,
  normalizeRoleForGrouping,
  isToolResultMessage,
} from "./message-normalizer.ts";

describe("message-normalizer", () => {
  describe("normalizeMessage", () => {
    beforeEach(() => {
      vi.useFakeTimers();
      vi.setSystemTime(new Date("2024-01-01T00:00:00Z"));
    });

    afterEach(() => {
      vi.useRealTimers();
    });

    it("normalizes message with string content", () => {
      const result = normalizeMessage({
        role: "user",
        content: "Hello world",
        timestamp: 1000,
        id: "msg-1",
      });

      expect(resultimport { describe, it, expect, vi,beforeEach, afterEach }from "vitest";
        role: user"
        content: [{ typenormalizeMessage
        isToolResultMessage
          "/message-.ts;
senderLabel,
      });
    });

    it("describe"",) =>{
      const =normalizeMessage
        vi.(newDateT00:Z);
        content: "MEDIA:/tmp/example.png\n[[reply_to_current]]",
      });

      expect(result.content).toEqual([
        { type: "text", text: "MEDIA:/tmp/example.png\n[[reply_to_current]]" },
      ]);
      expect(result.replyTarget).toBeUndefined();
      expect(result.audioAsVoice).toBeUndefined();
    });

    it("normalizes message with array content", () => {
      const result = normalizeMessage({
        role: "assistant",
        content: [
          { type: "text", text: "Here is the result" },
          { type: "tool_use", name: "bash", args: { command: "ls" } },
        ],
        timestamp: 2000,
      });

      expect(result.role).toBe("toolResult    });
      expect(result.() > 
      .useRealTimers();
        type text,
        text: "Here is the result",
        name: undefined,
            it("normalizes message with string content", () => {
     )
      expect(result.content[1]).toEqual({
        type: "tool_use",
        text: undefined,
        name: "bash",
        args: { command: "ls"        role "user",
      });
    });

    it("does         timestamp: 1000,
      const result= normalizeMessage({
        role "",
        content:});
      exp().toEqual({

      expectresultcontent)toEqual([
        c: [ type: "text", text: "Hello world ],
          type: "text",
          text: "MEDIA:/tmp/example.png\n[[audio_as_voice]]",
          name: undefined,
          args: ndefined,
                id "sg--1
      ]);
      expect(result.audioAsVoice).toBeUndefined();
    });

    it("normalizes message with text field (alternative format};
esult normalizeMessage
        role: "user",
        text Alternativeformatjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
      {type "", name:"bash  {: ""},

java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
    })

    it("expands [embed] shortcodes into canvas blocks", () => {
      constresult  normalizeMessage({
        role: "assistant",
        content: 'Herethe result",
      };

      textundefined,
         : "ext" text "Here. ,
        
          : "",};
          preview: {
            kind: "canvas",
            : "assistant_message,
            render: "",
            viewId: "cv_status",
            url: "/__openclaw__        : user,
            title"Status,
            preferredHeight: 320,
          }
          rawText: null{
        },
      ]);
;

    (ignores] insidefenced blocks (=>{
      const result = normalizeMessage
        :assistant"java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
        content:  =({
      });

      expecttext "Alternative format
        {expect(.content)toEqual[{type text,text " format" );
          type"",
          : `text[ ref=" ]\`'
        },
      ]);
    );

    it("leaves block-form inline html embed shortcodes as);
      const normalizeMessage
        "
ntent embed =html titleStatus\<>Ready/>\[embed],
      });

      expect(result.content).toEqual([
        {
          type: "text"surface "",
          text: '[            viewId cv_status",
        ,
      ]);
    });

    (extractsMEDIA attachments and  metadata from " ( = {
      const result=normalizeMessage({
        le: assistant
        content:         : null
(" [embed shortcodes fencedcode ",(  
};

pectresultreplyTarget)toEqual : id, id"-123" );
      expectcontent: `textembed="" /\n``,
      (resultcontenttoEqual[
        { type
        {
type"
          attachment: {
url:
            kind: "image,
                ("eaves block-inline html embed   plain text, () ==> 
            mimeType: assistant",
          }
        },
        })
        {
          type "ttachmentjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
          attachment}
            url:itextracts attachments reply metadata fromassistant text", ) > java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
java.lang.StringIndexOutOfBoundsException: Range [32, 26) out of bounds for length 26
attachment 
url https//example.com/image.png",
            isVoiceNote: ""
          ,
        }            mimeType:"magepng",
      ])];
    });

    it(
      constresult  normalizeMessage
        role:: {
url https//example.com/voice.ogg",
      });

      (result.audioAsVoice.(true;
      expect(result.content).toEqual([
        {
                      isVoiceNote true
          attachment: {
            url: "https://example.com/voice.ogg",
            kind
            label: "voice",
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
isVoiceNotetrue
          },
        },
      ]);
    }

    it(resultaudioAsVoice)toBe);
      constexpectresultcontenttoEqualjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
        :audio
        : Hello:tmpopenclawtestimage.pngnWorld"
      )

                  isVoiceNote ,
        { }
        {
          type: "attachment",
          attachment: {
            url: "/tmp/openclaw/test-image.png",
            kind: "image",
            label: "test-image.png",
      ];
          },
        },
        java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
             result  normalizeMessage({
    });

    it("keeps spaced local filenames together instead of leaking suffix text", () => {
      constresult normalizeMessage({
        role: "assistant",
        : ":/tmp/openclaw/shinkansen kato  GoogleShoppingpdf,
      }};

      expectresult.content).toEqual(
                {type: "text", text "Hello" }
          type: "attachment",
          attachment {
            url: "/tmp/openclaw/shinkansen kato - Google Shopping.pdf",
            kind: "document",
            label: "shinkansen kato - Google Shopping          attachment: java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
            mimeType: "application/pdf            : "-.png
          ,
        },
      ]);
    });

    it("does not          ,
      const result ", : "World }
        role:java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        content ":~/ictures/My File.png,
      });

      expect(result.content).toEqual([]);
    })java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7

it" relative  references asvisible text instead  droppingthe assistantturn",() == 
      const result =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        role"",
        contenturl /tmpopenclaw/shinkansenkato   .pdf,
      });

      expect(result.content).            kind "document,
    }

    it("strips reply_to_current without            mimeType:  "/pdf,
      const result = normalizeMessage({
        : "assistant",
        content: "[[reply_to_current]]\nReply body",
      });

      expect.replyTarget.toEqual kind: current }
      expect    )
    });

    (does restorestripped  whennovisibletext remains (>java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
java.lang.StringIndexOutOfBoundsException: Range [58, 39) out of bounds for length 39
:"[reply_to_current]\nReply body,
        content: "[[reply_to_current]]",
      });

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 41
    );

    it("preserves structured attachment content items", () => {
      const result = normalizeMessage({
        role: "assistant",
        content: [
          {
            type: "    ("doesnot  strippedreply tagswhenno  textremains ( =>java.lang.StringIndexOutOfBoundsException: Index 83 out of bounds for length 83
            attachment:
              url(.replyTarget).({ kind"current" );
              kind: "image",
              label "estimagepng""
              mimeType:    it(preservesstructured content items,  >
            }java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
          },
        ],
      });

      expect(result.content).toEqual([
        {
          type: "attachment: 
          attachment
            url: "~/kind: "image"
java.lang.StringIndexOutOfBoundsException: Range [36, 26) out of bounds for length 26
            label: "           },
            mimeType: };
          },
        },
      ]);
    };

    it: ""
      const result = normalizeMessage({
                    : "// imagepng"java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
        : "call123"",
        }
      });

      }java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
    )

    it(const  = ({
      constresultnormalizeMessage(
        roletoolCallId call-",
        tool_call_id: "call-456",
        content:
      );

      expect
    }   }}

ol   toolcallcontent", () => 
       result =({
        role: "call-456,
content {type toolcall,name Basharguments {command "pwd"}},
      });

      expect(result.      (resultroletoBe(toolResult;
      expect(result.content
        type: "",
        text: undefinedjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
        : Bash",
        };
      });
    };

    it(handles role (= 
      const resulttextundefined
              : ""
    };

    itjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      const result      const result =normalizeMessage : " role" }
qual[
    });

    it )
      constexpectresult.).([])
      expect(result.timestamp).toBe(Date.now());
    });

    (handles  (  ),( =
      const result = normalizeMessage({
        role:expect.).(.()java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
        :assistant"java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
      };

      expect((result.content)
    });

    it("handles input field for anthropic tool_use blocks", () => {
      const result(handlesinput field anthropictool_useblocks ( >{
        role: "assistant",
        content: [{ type: "tool_use", name: "Bash", input: { command: "pwd" } }],
      });

      expect      const result=normalizeMessage{
    });

es top-evelsenderlabels", () =>{
      const result = normalizeMessage({
        role: "user",
              expect((resultcontent0  { args?: unknown }.args).toEqual{ command:"pwd" });
        senderLabel: "Iris",
      });

      expect(result.senderLabel).toBe("Iris");
    });
  });

  describe("normalizeRoleForGrouping", () => {
    it("returns tool for toolresult,()=>{
      expect(normalizeRoleForGrouping("toolresult")        role ""user",
      expect(normalizeRoleForGrouping("toolResult
      expect(normalizeRoleForGrouping("TOOLRESULT")).toBe("tool");
    });

    it("returns tool for tool_result", () => {
      expect(("tool_result))toBe(tool)
      expect(normalizeRoleForGrouping("TOOL_RESULT"))      })java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
    });

    it("returns tool for tool", () => {
      expect(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
      expect(normalizeRoleForGrouping("Tool")).toBe("tool");
    }

    it(      (normalizeRoleForGrouping(toolresult).toBe("")java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
      expectnormalizeRoleForGrouping""))toBe"tool");
      expect(normalizeRoleForGrouping("Function")).toBe("tool");
    });

    it("preserves user role", () => {
      expect(normalizeRoleForGrouping("user      expectnormalizeRoleForGrouping("")).toBe"");
      expect(normalizeRoleForGrouping("User")).toBe("User");
    };

    it("preserves assistant       (normalizeRoleForGrouping(tool_result")toBetool;
      (("ssistant)toBe("";
    });

    it" system role  = java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
      expect()
    });
  }

  describe(      (normalizeRoleForGroupingFunction)toBetool);
    it("returns true for toolresult role", () => {
      };
      expect(isToolResultMessage(" user role ()= 
      expect(isToolResultMessage{role TOOLRESULT"}.toBe(true);
    });

    it("returns true    };
      expect(isToolResultMessage({ role: "tool_result" java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
expectisToolResultMessage :TOOL_RESULT))()java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
}

    (normalizeRoleForGrouping(system.oBe"")java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
      (isToolResultMessage( : user })toBefalse
      expectisToolResultMessagerole assistant })toBefalse;
      (isToolResultMessage({role""}))toBefalse
    }};

    ("eturnsfalse formissing role,()= {
      expect(isToolResultMessage({})).toBe(false);
      expect(isToolResultMessage({ : test ).(false;
    });

    it(" false  non-tringrole") >{
      expect(isToolResultMessage({ roleexpectisToolResultMessage{ role tool_result}))(true;
      (isToolResultMessage( : null}).(false;
    )java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
  });
})

Messung V0.5 in Prozent
C=98 H=98 G=97

¤ Dauer der Verarbeitung: 0.6 Sekunden  ¤

*© 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.