Skip to content
5 min read · 1,047 words

Variable: defaultBuildChatCompletionsHistory

ts
const defaultBuildChatCompletionsHistory: (input: {
  bucketOrder: ChatCompletionsBucketOrder;
  filterThoughts: (
    thoughts: Iterable<Thought>,
    mode: "all-self" | "latest-self" | "all",
    selfIdentity: string,
    replayCompatibility: readonly string[],
  ) => Thought[];
  memories: Iterable<Memory>;
  messages: Iterable<Message>;
  renderChatCompletionsSystemPrompt: (input: {
    bucketOrder: ChatCompletionsBucketOrder;
    memories: Iterable<Memory>;
    renderFirstPartyRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
    ) => string;
    renderMemories: (
      items: Iterable<{
        attrs: MemoryAttrs;
        memory: Memory;
      }>,
    ) => string;
    renderRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
      deps: {
        renderFirstPartyRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
        ) => string;
        renderRetrievableSafetyDirective: () => string;
        renderThirdPartyPrivateRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
          deps: {
            renderUntrustedContent: (
              content: string,
              attrs: UntrustedContentAttrs,
            ) => string;
          },
        ) => string;
        renderThirdPartyPublicRetrievables: (
          items: Iterable<{
            attrs: RetrievableAttrs;
            retrievable: Retrievable;
          }>,
          deps: {
            renderUntrustedContent: (
              content: string,
              attrs: UntrustedContentAttrs,
            ) => string;
          },
        ) => string;
        renderUntrustedContent: (
          content: string,
          attrs: UntrustedContentAttrs,
        ) => string;
      },
    ) => string;
    renderRetrievableSafetyDirective: () => string;
    renderStandingInstructions: (
      items: Iterable<Tokenizable>,
      attrs?: StandingInstructionAttrs,
    ) => string;
    renderThirdPartyPrivateRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
      deps: {
        renderUntrustedContent: (
          content: string,
          attrs: UntrustedContentAttrs,
        ) => string;
      },
    ) => string;
    renderThirdPartyPublicRetrievables: (
      items: Iterable<{
        attrs: RetrievableAttrs;
        retrievable: Retrievable;
      }>,
      deps: {
        renderUntrustedContent: (
          content: string,
          attrs: UntrustedContentAttrs,
        ) => string;
      },
    ) => string;
    renderUntrustedContent: (
      content: string,
      attrs: UntrustedContentAttrs,
    ) => string;
    retrievables: Iterable<Retrievable>;
    standingInstructions: Iterable<Tokenizable>;
    systemPrompt: Tokenizable;
  }) => string;
  renderChatCompletionsToolCallResult: (input: {
    renderTrustedContent: (
      content: string,
      attrs: TrustedContentAttrs,
    ) => string;
    renderUntrustedContent: (
      content: string,
      attrs: UntrustedContentAttrs,
    ) => string;
    results:
      | Tokenizable
      | SpooledArtifact
      | Media
      | Media[]
      | SpooledArtifact[];
    tool: Tool<SpooledArtifact> | ArtifactTool | undefined;
    toolCall: ToolCall;
    unsupportedMediaPolicy: UnsupportedMediaPolicy;
    warn?: (msg: string) => void;
  }) => Promise<string | ChatCompletionsContentBlock[]>;
  renderedToolCallResults: Map<string, string | ChatCompletionsContentBlock[]>;
  renderFirstPartyRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
  ) => string;
  renderMemories: (
    items: Iterable<{
      attrs: MemoryAttrs;
      memory: Memory;
    }>,
  ) => string;
  renderRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
    deps: {
      renderFirstPartyRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
      ) => string;
      renderRetrievableSafetyDirective: () => string;
      renderThirdPartyPrivateRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
        deps: {
          renderUntrustedContent: (
            content: string,
            attrs: UntrustedContentAttrs,
          ) => string;
        },
      ) => string;
      renderThirdPartyPublicRetrievables: (
        items: Iterable<{
          attrs: RetrievableAttrs;
          retrievable: Retrievable;
        }>,
        deps: {
          renderUntrustedContent: (
            content: string,
            attrs: UntrustedContentAttrs,
          ) => string;
        },
      ) => string;
      renderUntrustedContent: (
        content: string,
        attrs: UntrustedContentAttrs,
      ) => string;
    },
  ) => string;
  renderRetrievableSafetyDirective: () => string;
  renderStandingInstructions: (
    items: Iterable<Tokenizable>,
    attrs?: StandingInstructionAttrs,
  ) => string;
  renderThirdPartyPrivateRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
    deps: {
      renderUntrustedContent: (
        content: string,
        attrs: UntrustedContentAttrs,
      ) => string;
    },
  ) => string;
  renderThirdPartyPublicRetrievables: (
    items: Iterable<{
      attrs: RetrievableAttrs;
      retrievable: Retrievable;
    }>,
    deps: {
      renderUntrustedContent: (
        content: string,
        attrs: UntrustedContentAttrs,
      ) => string;
    },
  ) => string;
  renderThought: (
    content: string,
    attrs: ThoughtAttrs,
    payload?: unknown,
  ) => string;
  renderTimelineMessage: (input: {
    message: Message;
    selfIdentity: string;
    unsupportedMediaPolicy: UnsupportedMediaPolicy;
    warn?: (msg: string) => void;
  }) => Promise<ChatCompletionsMessage>;
  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;
  unsupportedMediaPolicy: UnsupportedMediaPolicy;
  warn?: (msg: string) => void;
}) => Promise<{
  messages: ChatCompletionsMessage[];
  reasoningPayloads: {
    id: string;
    payload: unknown;
    replayCompatibility: string;
  }[];
}> = buildChatCompletionsHistory;

Parameters

ParameterType
input{ bucketOrder: ChatCompletionsBucketOrder; filterThoughts: (thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]; memories: Iterable<Memory>; messages: Iterable<Message>; renderChatCompletionsSystemPrompt: (input: { bucketOrder: ChatCompletionsBucketOrder; memories: Iterable<Memory>; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => string; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => string; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; retrievables: Iterable<Retrievable>; standingInstructions: Iterable<Tokenizable>; systemPrompt: Tokenizable; }) => string; renderChatCompletionsToolCallResult: (input: { renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; results: | Tokenizable | SpooledArtifact | Media | Media[] | SpooledArtifact[]; tool: | Tool<SpooledArtifact> | ArtifactTool | undefined; toolCall: ToolCall; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise< | string | ChatCompletionsContentBlock[]>; renderedToolCallResults: Map<string, | string | ChatCompletionsContentBlock[]>; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => string; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => string; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderThought: (content: string, attrs: ThoughtAttrs, payload?: unknown) => string; renderTimelineMessage: (input: { message: Message; selfIdentity: string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<ChatCompletionsMessage>; 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; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }
input.bucketOrderChatCompletionsBucketOrder
input.filterThoughts(thoughts: Iterable<Thought>, mode: "all-self" | "latest-self" | "all", selfIdentity: string, replayCompatibility: readonly string[]) => Thought[]
input.memoriesIterable<Memory>
input.messagesIterable<Message>
input.renderChatCompletionsSystemPrompt(input: { bucketOrder: ChatCompletionsBucketOrder; memories: Iterable<Memory>; renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => string; renderMemories: (items: Iterable<{ attrs: MemoryAttrs; memory: Memory; }>) => string; renderRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderFirstPartyRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => string; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderRetrievableSafetyDirective: () => string; renderStandingInstructions: (items: Iterable<Tokenizable>, attrs?: StandingInstructionAttrs) => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; retrievables: Iterable<Retrievable>; standingInstructions: Iterable<Tokenizable>; systemPrompt: Tokenizable; }) => string
input.renderChatCompletionsToolCallResult(input: { renderTrustedContent: (content: string, attrs: TrustedContentAttrs) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; results: | Tokenizable | SpooledArtifact | Media | Media[] | SpooledArtifact[]; tool: | Tool<SpooledArtifact> | ArtifactTool | undefined; toolCall: ToolCall; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise< | string | ChatCompletionsContentBlock[]>
input.renderedToolCallResultsMap<string, | string | ChatCompletionsContentBlock[]>
input.renderFirstPartyRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>) => 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; }>) => string; renderRetrievableSafetyDirective: () => string; renderThirdPartyPrivateRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderThirdPartyPublicRetrievables: (items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string; renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => 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; }) => string
input.renderThirdPartyPublicRetrievables(items: Iterable<{ attrs: RetrievableAttrs; retrievable: Retrievable; }>, deps: { renderUntrustedContent: (content: string, attrs: UntrustedContentAttrs) => string; }) => string
input.renderThought(content: string, attrs: ThoughtAttrs, payload?: unknown) => string
input.renderTimelineMessage(input: { message: Message; selfIdentity: string; unsupportedMediaPolicy: UnsupportedMediaPolicy; warn?: (msg: string) => void; }) => Promise<ChatCompletionsMessage>
input.renderTrustedContent(content: string, attrs: TrustedContentAttrs) => string
input.renderUntrustedContent(content: string, attrs: UntrustedContentAttrs) => string
input.replayCompatibilityreadonly string[]
input.retrievablesIterable<Retrievable>
input.selfIdentitystring
input.standingInstructionsIterable<Tokenizable>
input.systemPromptTokenizable
input.thoughtsIterable<Thought>
input.thoughtSurfacing"all-self" | "latest-self" | "all"
input.toolCallsIterable<ToolCall>
input.toolsToolRegistry
input.unsupportedMediaPolicyUnsupportedMediaPolicy
input.warn?(msg: string) => void

Returns

Promise<{ messages: ChatCompletionsMessage[]; reasoningPayloads: { id: string; payload: unknown; replayCompatibility: string; }[]; }>