refactor(ai): remove unused metadata fields (#61018)

This commit is contained in:
Aiden Cline
2026-11-01 22:06:13 -06:00
committed by GitHub
Unverified
parent 3f3ee9e5f0
commit e5c9b0151b
8 changed files with 5 additions and 61 deletions
-2
View File
@@ -60,7 +60,6 @@ interface TextRequestFields<Model extends LanguageModel> {
readonly cache?: CachePolicy
/** Stable cache affinity for protocols that support provider-managed prompt caching. */
readonly promptCacheKey?: string
readonly metadata?: Record<string, unknown>
/** Emit a `raw` event with each provider frame before the events parsed from it. */
readonly includeRaw?: boolean
}
@@ -308,7 +307,6 @@ export const request = <const Model extends LanguageModel>(input: LLMRequestInpu
http: HttpOptions.make(input.http),
cache: input.cache,
promptCacheKey: input.promptCacheKey,
metadata: input.metadata,
includeRaw: input.includeRaw,
}
}
-8
View File
@@ -41,7 +41,6 @@ export const TextPart = Schema.Struct({
type: Schema.Literal("text"),
text: Schema.String,
cache: Schema.optional(CacheHint),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
providerMetadata: Schema.optional(ProviderMetadata),
}).annotate({ identifier: "LLM.Content.Text" })
export type TextPart = Schema.Schema.Type<typeof TextPart>
@@ -135,7 +134,6 @@ export const ToolCallPart = withStatics(
input: Schema.Unknown,
providerExecuted: Schema.optional(Schema.Boolean),
cache: Schema.optional(CacheHint),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
providerMetadata: Schema.optional(ProviderMetadata),
}).annotate({ identifier: "LLM.Content.ToolCall" }),
{
@@ -153,7 +151,6 @@ export const ToolResultPart = withStatics(
result: ToolResultValue,
providerExecuted: Schema.optional(Schema.Boolean),
cache: Schema.optional(CacheHint),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
providerMetadata: Schema.optional(ProviderMetadata),
}).annotate({ identifier: "LLM.Content.ToolResult" }),
{
@@ -170,7 +167,6 @@ export const ToolResultPart = withStatics(
result: ToolResultValue.make(input.result, input.resultType),
providerExecuted: input.providerExecuted,
cache: input.cache,
metadata: input.metadata,
providerMetadata: input.providerMetadata,
}),
},
@@ -182,7 +178,6 @@ export const ReasoningPart = Schema.Struct({
text: Schema.String,
encrypted: Schema.optional(Schema.String),
cache: Schema.optional(CacheHint),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
providerMetadata: Schema.optional(ProviderMetadata),
}).annotate({ identifier: "LLM.Content.Reasoning" })
export type ReasoningPart = Schema.Schema.Type<typeof ReasoningPart>
@@ -236,7 +231,6 @@ export class Message extends Schema.Class<Message>("LLM.Message")({
id: Schema.optional(Schema.String),
role: MessageRole,
content: Schema.Array(ContentPart),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
providerMetadata: Schema.optional(ProviderMetadata),
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
}) {}
@@ -301,7 +295,6 @@ const toolDefinitionFields = {
outputSchema: Schema.optional(JsonSchema),
freeform: Schema.optional(Freeform),
cache: Schema.optional(CacheHint),
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
}
@@ -418,7 +411,6 @@ export interface LLMRequest<Model extends LanguageModel = LanguageModel> {
readonly cache?: CachePolicy
/** Stable cache affinity for protocols that support provider-managed prompt caching. */
readonly promptCacheKey?: string
readonly metadata?: Record<string, unknown>
/** Emit a `raw` event with each provider frame before the events parsed from it. */
readonly includeRaw?: boolean
}
-1
View File
@@ -75,7 +75,6 @@ function normalizeToolMessage(message: Message, pending: Map<string, ToolCallPar
id: message.id,
role: message.role,
content,
metadata: message.metadata,
providerMetadata: message.providerMetadata,
native: message.native,
})
+2 -2
View File
@@ -53,7 +53,7 @@ describe("sanitizeSurrogates", () => {
tools: [tool],
messages: [...messages, Message.user("bad \uD800")],
generation: { maxTokens: 10 },
metadata: { nested: { list: ["a", "b"] } },
providerOptions: { nested: { list: ["a", "b"] } },
})
const sanitized = sanitizeRequest(request)
@@ -69,7 +69,7 @@ describe("sanitizeSurrogates", () => {
const output = sanitizeSurrogates(input)
expect(output.system).toBe(input.system)
expect(output.tools).toBe(input.tools)
expect(output.metadata).toBe(input.metadata)
expect(output.providerOptions).toBe(input.providerOptions)
expect(output.messages).not.toBe(input.messages)
const clean = ai.request({ model, system: "system", tools: [tool], messages })
@@ -21,7 +21,6 @@ const media = (file: FileAttachment): ContentPart => ({
type: "media",
media: Media.base64(file.data, file.mime),
filename: file.name,
metadata: file.description === undefined ? undefined : { description: file.description },
})
const attachmentLocation = (file: FileAttachment) => {
@@ -45,13 +44,6 @@ const textAttachment = (file: FileAttachment): ContentPart => ({
]
.filter((line): line is string => line !== undefined)
.join("\n")}`,
metadata: {
attachment: {
source: file.source,
name: file.name,
description: file.description,
},
},
})
const directoryAttachment = (file: FileAttachment): ContentPart => ({
@@ -64,13 +56,6 @@ const directoryAttachment = (file: FileAttachment): ContentPart => ({
]
.filter((line): line is string => line !== undefined)
.join("\n")}`,
metadata: {
attachment: {
source: file.source,
name: file.name,
description: file.description,
},
},
})
const attachmentContent = (file: FileAttachment): ContentPart[] => {
@@ -215,10 +200,7 @@ const assistant = (message: SessionMessage.Assistant, model: Model.Ref, provider
.filter((message) => message !== undefined)
.map(Message.tool)
if (meaningful.length === 0) return results
return [
Message.make({ id: message.id, role: "assistant", content: meaningful, metadata: message.metadata }),
...results,
]
return [Message.make({ id: message.id, role: "assistant", content: meaningful }), ...results]
}
const EFFORT_VARIANTS = new Set<string>(ReasoningEfforts)
@@ -252,7 +234,6 @@ function toLLMMessage(message: SessionMessage.Info, model: Model.Ref, providerMe
id: message.id,
role: "user",
content: `The working directory has been changed to ${message.location.directory}.`,
metadata: message.metadata,
}),
]
case "user":
@@ -267,16 +248,12 @@ function toLLMMessage(message: SessionMessage.Info, model: Model.Ref, providerMe
id: message.id,
role: "user",
content,
metadata: {
...message.metadata,
...(message.agents?.length ? { agents: message.agents } : {}),
},
}),
]
case "synthetic":
return [Message.make({ id: message.id, role: "user", content: message.text })]
case "skill":
return [Message.make({ id: message.id, role: "user", content: message.text, metadata: message.metadata })]
return [Message.make({ id: message.id, role: "user", content: message.text })]
case "system":
return [Message.system(message.text)]
case "shell":
@@ -287,7 +264,6 @@ function toLLMMessage(message: SessionMessage.Info, model: Model.Ref, providerMe
id: message.id,
role: "user",
content: `The following shell command was executed by the user:\n\nCommand:\n${message.command}\n\nOutput:\n${message.output?.output ?? ""}`,
metadata: message.metadata,
}),
]
case "assistant":
@@ -309,7 +285,6 @@ function toLLMMessage(message: SessionMessage.Info, model: Model.Ref, providerMe
...(kept ? ["", `<recent-context>\n${kept}\n</recent-context>`] : []),
"</conversation-checkpoint>",
].join("\n"),
metadata: message.metadata,
}),
]
}
@@ -344,7 +344,5 @@ describe("SessionInstructions", () => {
expect(messages).toHaveLength(1)
expect(messages[0]!.role).toBe("user")
expect(messages[0]!.content).toEqual([{ type: "text", text: "Instructions from: /repo/sub/AGENTS.md\ncontent" }])
// Metadata is bookkeeping for the dedup ledger; the model must not see it.
expect(messages[0]!.metadata).toBeUndefined()
})
})
+1 -4
View File
@@ -206,15 +206,12 @@ test("a native window round-trips tools, opaque checkpoints and binary media thr
const optionalMetadata = stored([
Message.make({
role: "user",
content: [
{ type: "text", text: "attachment", metadata: { attachment: { name: undefined, source: { type: "inline" } } } },
],
content: [{ type: "text", text: "attachment" }],
providerMetadata: { openai: { itemId: undefined, type: "message", status: undefined, phase: undefined } },
}),
])
expect(decode({ native: optionalMetadata })[0]).toMatchObject({
providerMetadata: { openai: { type: "message" } },
content: [{ metadata: { attachment: { source: { type: "inline" } } } }],
})
expect(() =>
decode({
@@ -172,7 +172,6 @@ describe("toLLMMessages", () => {
{ type: "text", text: "Inspect this image" },
{ type: "media", media: Media.base64("aGVsbG8=", "image/png"), filename: "hello.png" },
],
metadata: { agents: [{ name: "build" }] },
}),
)
expect(messages.slice(3).map((message) => message.content)).toEqual([
@@ -298,7 +297,6 @@ Earlier work
{
type: "text",
text: "\n\nAttached file: main.ts\n\nexport const value = 1",
metadata: { attachment: { source: file.source, name: "main.ts" } },
},
],
})
@@ -337,7 +335,6 @@ Earlier work
{ type: "text", text: "<skill_content>Design APIs</skill_content>" },
{ type: "text", text: "Use @effect and @api-design" },
],
metadata: {},
}),
])
})
@@ -428,7 +425,6 @@ Earlier work
{
type: "text",
text: `\n\nAttached directory: ${location}\n\nlib/\nindex.ts`,
metadata: { attachment: { source: directory.source, name: "harness-engineering" } },
},
],
})
@@ -591,12 +587,6 @@ Earlier work
{
type: "text",
text: "\n\nAttached directory: src/\n\nindex.ts",
metadata: {
attachment: {
source: { type: "uri", uri: "file:///project/src%2Flib" },
name: "src/",
},
},
},
{ type: "media", media: Media.base64(data, "image/png"), filename: "preview.png" },
])
@@ -675,7 +665,6 @@ Earlier work
type: "media",
media: Media.base64(data, "image/png"),
filename: "image.png",
metadata: { description: "alternate use" },
},
])
})
@@ -998,7 +987,6 @@ Earlier work
result: { type: "text", value: '{"found":true}' },
providerExecuted: true,
cache: undefined,
metadata: undefined,
providerMetadata: { provider: { itemId: "hosted_completed" } },
},
{
@@ -1022,7 +1010,6 @@ Earlier work
},
providerExecuted: true,
cache: undefined,
metadata: undefined,
providerMetadata: { provider: { itemId: "hosted_failed" } },
},
])
@@ -1123,7 +1110,6 @@ Earlier work
result: { type: "text", value: '{"status":"completed"}' },
providerExecuted: true,
cache: undefined,
metadata: undefined,
// Hosted result payloads are provider-format state and must survive a
// model switch within the same provider for replay to stay valid.
providerMetadata: { provider: { itemId: "hosted-old-model", result: { signature: "result-sig" } } },
@@ -1145,7 +1131,6 @@ Earlier work
result: { type: "text", value: "Hello" },
providerExecuted: false,
cache: undefined,
metadata: undefined,
providerMetadata: undefined,
},
])