/** * A route's request headers as a draft: pure edits, no Harness, no rendering. * * A pi-ai route's `headers` field is a plain `Record` sent with * every request that route makes — how a gateway that authenticates with * something other than an API key, or a deployment that must tag its traffic, * is reached at all. This module is what an editor does to that map in memory * before it is ever written: add one, change a value, remove one, and turn the * survivors back into the JSON-compatible object `settings.mutate` takes. * * A draft is an ordered array rather than an object because the terminal * renders rows in a stable order and a reader who adds three headers should * see them where they put them. The order is a presentation fact only; the * written value is an object, and nothing downstream depends on its key order. * * Validity is decided by the same standard the owning adapter validates * against. `PiAiProviderProfile.headers` is documented as "validated against * Fetch when the profile resolves", so a candidate name or value is checked * here by handing it to the platform `Headers` constructor — the WHATWG * definition both sides already refer to, not a regular expression this * frontend invented and would have to keep in step. Harness stays the * authority: a check that passes here can still be refused by * `settings.mutate`, and that refusal is what the reader is shown. What this * check buys is that an obviously impossible header is named at the prompt * that typed it, rather than after a save that looked like it worked. * * HTTP field names are case-insensitive, so `X-Key` and `x-key` are one * header. They would survive as two distinct keys in a JSON object and then * collapse unpredictably at the wire, so a second spelling of a name the draft * already carries is refused rather than stored. * * Every function here is a pure transform over `HeaderDraftEntry[]`. The * terminal loop that turns keystrokes into calls on these lives in * `route-editor.ts`; nothing here pushes an overlay or calls a seam. * @module dshline/connect/header-editor */ /** One request header in a draft being edited. */ export interface HeaderDraftEntry { /** The field name, exactly as the reader spelled it. */ readonly name: string; /** The field value. */ readonly value: string; } /** * Build a draft from a route's stored `headers` object. * * A non-string value is skipped rather than coerced: the schema types this * field as a dict of strings, so anything else in a hand-edited * `settings.yaml` is something this editor did not write and must not claim * to represent. Skipping it also keeps it from being silently rewritten, * because an unchanged draft writes nothing at all. * @param raw - the profile's stored `headers` value, whatever shape it is. * @returns one entry per usable pair, in the object's own key order. */ export declare function entriesFromRawHeaders(raw: unknown): HeaderDraftEntry[]; /** * Turn a draft back into the object a settings op writes. * * Built with `Object.fromEntries` rather than by assigning in a loop, because * `raw[name] = value` runs through a setter when `name` is `__proto__` and * quietly stores nothing. That is a legal HTTP field name — the token grammar * allows `_`, and the platform `Headers` this module defers to accepts it — so * a reader could add one, watch the draft show it, save, be told the route was * updated, and find the header absent. Nothing is exploitable there, since a * string value leaves the prototype untouched; but a write that silently drops * what the editor displayed is the one thing this surface must not do. * `fromEntries` defines an own property instead, which round-trips back through * {@link entriesFromRawHeaders} and through `JSON` intact. * @param entries - the draft as it stands. * @returns the JSON-compatible header map, in draft order. */ export declare function toRawHeaders(entries: readonly HeaderDraftEntry[]): Record; /** * Whether two drafts would write the same headers. * * Order is deliberately not compared: it is a presentation fact this module * keeps for the reader's benefit, and treating a reordering as a change would * make the editor report an edit nobody made. * @param left - one draft. * @param right - the other. * @returns true when both carry the same names with the same values. */ export declare function sameHeaderSet(left: readonly HeaderDraftEntry[], right: readonly HeaderDraftEntry[]): boolean; /** * Why a typed header name cannot be used, when it cannot. * @param name - the name as typed, untrimmed. * @param taken - names already in the draft, for the case-insensitive check; * pass the name being renamed's own spelling out of this set so re-typing it * unchanged is not read as a collision. * @returns the reason, already worded for a reader, or undefined when usable. */ export declare function headerNameProblem(name: string, taken: readonly string[]): string | undefined; /** * Why a typed header value cannot be used, when it cannot. * @param value - the value as typed. * @returns the reason, already worded for a reader, or undefined when usable. */ export declare function headerValueProblem(value: string): string | undefined; /** * Add a header, or replace the value of one already in the draft. * * Replacement keeps the entry's position, so changing a value does not move * the row a reader is looking at. The stored name keeps its ORIGINAL spelling * on a replacement: the two spellings are the same header, and rewriting the * key would be an edit nobody asked for. * @param entries - the draft before the change. * @param name - the header's name, already checked by {@link headerNameProblem}. * @param value - the header's value, already checked by {@link headerValueProblem}. * @returns the draft with the header set. */ export declare function upsertHeader(entries: readonly HeaderDraftEntry[], name: string, value: string): HeaderDraftEntry[]; /** * Remove one header from the draft. * @param entries - the draft before the change. * @param name - the name to remove, matched case-insensitively. * @returns the draft without it. */ export declare function removeHeader(entries: readonly HeaderDraftEntry[], name: string): HeaderDraftEntry[]; //# sourceMappingURL=header-editor.d.ts.map