Skip to content
6 min read · 1,181 words

Variable: defaultBuildTransformersJsMessages

ts
const defaultBuildTransformersJsMessages: (input: {
  bucketOrder: ChatCompletionsBucketOrder;
  decodeMedia?: (media: Media) => Promise<{
    data: unknown;
    kind: "audio" | "image";
  }>;
  filterThoughts: (
    thoughts: Iterable<Thought>,
    mode: "all-self" | "latest-self" | "all",
    selfIdentity: string,
    replayCompatibility: readonly string[],
  ) => Thought[];
  memories: Iterable<Memory>;
  messages: Iterable<Message>;
  multimodal?: {
    audio: boolean;
    image: boolean;
  };
  renderChatCompletionsSystemPrompt: (input: {
    bucketOrder: ChatCompletionsBucketOrder;
    memories: Iterable<Memory>;
    renderCtx?: unknown;
    renderFirstPartyRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
    ) => Promise<string>;
    renderMemories: (
      items: Iterable<{
        attrs: MemoryAttrs;
        memory: Memory;
      }>,
    ) => string;
    renderRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
      deps: {
        renderFirstPartyRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
        ) => Promise<string>;
        renderRetrievableSafetyDirective: () => string;
        renderThirdPartyPrivateRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
          deps: {
            renderUntrustedContent: (
              content: string,
              attrs: UntrustedContentAttrs,
            ) => string;
          },
        ) => Promise<string>;
        renderThirdPartyPublicRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
          deps: {
            renderUntrustedContent: (
              content: string,
              attrs: UntrustedContentAttrs,
            ) => string;
          },
        ) => Promise<string>;
        renderUntrustedContent: (
          content: string,
          attrs: UntrustedContentAttrs,
        ) => string;
      },
    ) => Promise<string>;
    renderRetrievableSafetyDirective: () => string;
    renderStandingInstructions: (
      items: Iterable<Tokenizable>,
      attrs?: StandingInstructionAttrs,
    ) => string;
    renderThirdPartyPrivateRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
      deps: {
        renderUntrustedContent: (
          content: string,
          attrs: UntrustedContentAttrs,
        ) => string;
      },
    ) => Promise<string>;
    renderThirdPartyPublicRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
      deps: {
        renderUntrustedContent: (
          content: string,
          attrs: UntrustedContentAttrs,
        ) => string;
      },
    ) => Promise<string>;
    renderUntrustedContent: (
      content: string,
      attrs: UntrustedContentAttrs,
    ) => string;
    retrievables: Iterable<Retrievable>;
    standingInstructions: Iterable<Tokenizable>;
    systemPrompt: Tokenizable;
  }) => Promise<string>;
  renderedToolCallResults: Map<string, string>;
  renderFirstPartyRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
  ) => Promise<string>;
  renderMemories: (
    items: Iterable<{
      attrs: MemoryAttrs;
      memory: Memory;
    }>,
  ) => string;
  renderRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
    deps: {
      renderFirstPartyRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
      ) => Promise<string>;
      renderRetrievableSafetyDirective: () => string;
      renderThirdPartyPrivateRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
        deps: {
          renderUntrustedContent: (
            content: string,
            attrs: UntrustedContentAttrs,
          ) => string;
        },
      ) => Promise<string>;
      renderThirdPartyPublicRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
        deps: {
          renderUntrustedContent: (
            content: string,
            attrs: UntrustedContentAttrs,
          ) => string;
        },
      ) => Promise<string>;
      renderUntrustedContent: (
        content: string,
        attrs: UntrustedContentAttrs,
      ) => string;
    },
  ) => Promise<string>;
  renderRetrievableSafetyDirective: () => string;
  renderStandingInstructions: (
    items: Iterable<Tokenizable>,
    attrs?: StandingInstructionAttrs,
  ) => string;
  renderThirdPartyPrivateRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
    deps: {
      renderUntrustedContent: (
        content: string,
        attrs: UntrustedContentAttrs,
      ) => string;
    },
  ) => Promise<string>;
  renderThirdPartyPublicRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
    deps: {
      renderUntrustedContent: (
        content: string,
        attrs: UntrustedContentAttrs,
      ) => string;
    },
  ) => Promise<string>;
  renderThought: (
    content: string,
    attrs: ThoughtAttrs,
    payload?: unknown,
  ) => string;
  renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string;
  renderUntrustedContent: (
    content: string,
    attrs: UntrustedContentAttrs,
  ) => string;
  replayCompatibility: readonly string[];
  retrievables: Iterable<Retrievable>;
  selfIdentity: string;
  standingInstructions: Iterable<Tokenizable>;
  systemPrompt: Tokenizable;
  thoughts: Iterable<Thought>;
  thoughtSurfacing: "all-self" | "latest-self" | "all";
  toolCalls: Iterable<ToolCall>;
  tools: ToolRegistry;
  toolsToTransformersJsTools: (
    tools: readonly (Tool<SpooledArtifact> | ArtifactTool)[],
    deps: {
      descriptionToChatCompletionsJsonSchema: (
        d: DescriptionLike,
      ) => JsonSchema;
    },
  ) => TransformersJsTool[];
  unsupportedMediaPolicy?: UnsupportedMediaPolicy;
  warn?: (msg: string) => void;
}) => Promise<{
  audio: unknown[];
  images: unknown[];
  messages: Message[];
  tools: TransformersJsTool[];
}> = buildTransformersJsMessages;

Defined in: src/batteries/llm/transformers_js/helpers.ts:446

Default buildTransformersJsMessages.

Build the transformers.js messages array + tools from the ADK dispatch context buckets.

Parameters

| Parameter | Type | Description | | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | input | { bucketOrder: ChatCompletionsBucketOrder; decodeMedia?: (media: Media) => Promise<{ data: unknown; kind: "audio" | "image"; }>; filterThoughts: (thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]; memories: Iterable<Memory>; messages: Iterable<Message>; multimodal?: { audio: boolean; image: boolean; }; renderChatCompletionsSystemPrompt: (input: { bucketOrder: ChatCompletionsBucketOrder; memories: Iterable<Memory>; renderCtx?: unknown; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; retrievables: Iterable<Retrievable>; standingInstructions: Iterable<Tokenizable>; systemPrompt: Tokenizable; }) => Promise<string>; renderedToolCallResults: Map<string, string>; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThought: (content: string, attrs: ThoughtAttrs, payload?: unknown) => string; renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; replayCompatibility: readonly string[]; retrievables: Iterable<Retrievable>; selfIdentity: string; standingInstructions: Iterable<Tokenizable>; systemPrompt: Tokenizable; thoughts: Iterable<Thought>; thoughtSurfacing: "all-self" | "latest-self" | "all"; toolCalls: Iterable<ToolCall>; tools: ToolRegistry; toolsToTransformersJsTools: (tools: readonly ( | Tool<SpooledArtifact> | ArtifactTool)[], deps: { descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema; }) => TransformersJsTool[]; unsupportedMediaPolicy?: UnsupportedMediaPolicy; warn?: (msg: string) => void; } | - | | input.bucketOrder | ChatCompletionsBucketOrder | - | | input.decodeMedia? | (media: Media) => Promise<{ data: unknown; kind: "audio" | "image"; }> | Decodes a Media instance to a transformers.js input (RawImage / audio samples). Adapter-injected. | | input.filterThoughts | (thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[] | - | | input.memories | Iterable<Memory> | - | | input.messages | Iterable<Message> | - | | input.multimodal? | { audio: boolean; image: boolean; } | Multimodal config. Absent/false → text-only (every message renders a plain string content, the byte-for-byte original behavior). When set, a message carrying attachments of an enabled kind renders a content-array (text + {type:'image' | 'audio'}placeholders) and the decoded media is collected intoimages/audio(consumed positionally byprocessor(prompt, images, audio)). | | input.multimodal.audio | boolean | - | | input.multimodal.image | boolean | - | | input.renderChatCompletionsSystemPrompt | (input: { bucketOrder: ChatCompletionsBucketOrder; memories: Iterable<Memory>; renderCtx?: unknown; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; retrievables: Iterable<Retrievable>; standingInstructions: Iterable<Tokenizable>; systemPrompt: Tokenizable; }) => Promise<string> | - | | input.renderedToolCallResults | Map<string, string> | - | | input.renderFirstPartyRetrievables | (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string> | - | | input.renderMemories | (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string | - | | input.renderRetrievables | (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => Promise<string>; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string>; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string> | - | | input.renderRetrievableSafetyDirective | () => string | - | | input.renderStandingInstructions | (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string | - | | input.renderThirdPartyPrivateRetrievables | (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string> | - | | input.renderThirdPartyPublicRetrievables | (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => Promise<string> | - | | input.renderThought | (content: string, attrs: ThoughtAttrs, payload?: unknown) => string | - | | input.renderTrustedContent | (content: string, attrs: TrustedContentAttrs) => string | - | | input.renderUntrustedContent | (content: string, attrs: UntrustedContentAttrs) => string | - | | input.replayCompatibility | readonly string[] | - | | input.retrievables | Iterable<Retrievable> | - | | input.selfIdentity | string | - | | input.standingInstructions | Iterable<Tokenizable> | - | | input.systemPrompt | Tokenizable | - | | input.thoughts | Iterable<Thought> | - | | input.thoughtSurfacing | "all-self" | "latest-self" | "all" | - | | input.toolCalls | Iterable<ToolCall> | - | | input.tools | ToolRegistry | - | | input.toolsToTransformersJsTools | (tools: readonly ( | Tool<SpooledArtifact> | ArtifactTool)[], deps: { descriptionToChatCompletionsJsonSchema: (d: DescriptionLike) => JsonSchema; }) => TransformersJsTool[] | - | | input.unsupportedMediaPolicy? | UnsupportedMediaPolicy | - | | input.warn? | (msg: string) => void | - |

Returns

Promise<{ audio: unknown[]; images: unknown[]; messages: Message[]; tools: TransformersJsTool[]; }>

Remarks

Leading buckets (system prompt + standing instructions / memories / retrievables) render into a single system message; the timeline (messages, surviving thoughts, tool calls — chronological) renders into user/assistant/tool messages. Tools are returned separately for the tools generate-kwarg. Mirrors buildLiteRtConversationInput.