Files
openclaw/extensions/meta/stream.ts
Peter Steinberger 7bf80dc2c6 chore(tooling): enforce formatting and refresh TypeScript checks (#104239)
* chore(tooling): enforce current formatter and refresh checks

* chore(tooling): keep release changelog formatter-owned

* chore(tooling): retain compatible Node type surface

* ci: enforce formatting for docs-only changes

* ci: isolate docs formatter check

* chore(tooling): apply updated lint and format rules

* chore(tooling): satisfy updated switch lint

* style(ui): apply Linux formatter layout

* test(doctor): match quiet local audio contribution

* test(doctor): assert quiet output only

* test(doctor): follow restored information contract
2026-07-11 01:09:51 -07:00

41 lines
1.6 KiB
TypeScript

// Meta plugin module implements stream behavior.
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
import { streamSimple } from "openclaw/plugin-sdk/llm";
import type { ProviderWrapStreamFnContext } from "openclaw/plugin-sdk/plugin-entry";
import { streamWithPayloadPatch } from "openclaw/plugin-sdk/provider-stream-shared";
const META_REASONING_ENCRYPTED_CONTENT_INCLUDE = "reasoning.encrypted_content";
function ensureMetaResponsesReplayFields(payloadObj: Record<string, unknown>): void {
const existing = payloadObj.include;
const include = Array.isArray(existing)
? existing.filter((entry): entry is string => typeof entry === "string")
: [];
if (!include.includes(META_REASONING_ENCRYPTED_CONTENT_INCLUDE)) {
include.push(META_REASONING_ENCRYPTED_CONTENT_INCLUDE);
}
payloadObj.include = include;
payloadObj.store = false;
}
export function createMetaResponsesWrapper(baseStreamFn: StreamFn | undefined): StreamFn {
const underlying = baseStreamFn ?? streamSimple;
return (model, context, options) =>
streamWithPayloadPatch(underlying, model, context, options, (payloadObj) => {
if (model.provider !== "meta" || model.api !== "openai-responses") {
return;
}
if (!model.reasoning) {
return;
}
ensureMetaResponsesReplayFields(payloadObj);
});
}
export function wrapMetaProviderStream(ctx: ProviderWrapStreamFnContext): StreamFn | undefined {
if (ctx.provider !== "meta" || ctx.model?.api !== "openai-responses") {
return undefined;
}
return createMetaResponsesWrapper(ctx.streamFn);
}