@hue-run/sdk 0.17.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -520,9 +520,10 @@ export async function runExperiment(options) {
520
520
  // copies of its inputs, its work, the evaluator's downloads and the staged outputs.
521
521
  // A retry gets its own, so an agent a dead run left behind cannot write into it.
522
522
  const worldDirectoryOf = (itemId, attempt) => join(filesRoot, `world-case-${uuid(itemId)}${attempt ? `-${uuid(attempt)}` : ""}`);
523
+ const directDirectoryOf = (itemId) => join(filesRoot, `case-${uuid(itemId)}`);
523
524
  const runCase = async (item, files) => {
524
525
  const file = `case-${uuid(item.id)}`;
525
- const directDirectory = join(filesRoot, `case-${uuid(item.id)}`);
526
+ const directDirectory = directDirectoryOf(item.id);
526
527
  const caseDirectoryOf = (frozen) => frozen.environmentVersionId ? files.directory : directDirectory;
527
528
  let checkpoint;
528
529
  try {
@@ -605,122 +606,139 @@ export async function runExperiment(options) {
605
606
  const outputDirectory = join(caseDirectory, "work");
606
607
  await mkdir(outputDirectory, { recursive: true, mode: 0o700 });
607
608
  const failureSequenceBefore = options.hue.transport.getFailureSequence();
608
- checkpoint = await options.hue.withSpan("hue.experiment.case", async (span) => {
609
- const start = {
610
- stage: "starting",
611
- startKey: randomUUID(),
612
- traceExternalId: span.traceId,
613
- ...(retryOf ? { previousExecutionId: retryOf } : {}),
614
- };
615
- await store.write(file, start);
616
- const execution = await options.client.startExecution(experiment.id, item.id, {
617
- idempotencyKey: start.startKey,
618
- traceExternalId: span.traceId,
619
- ...retry(retryOf),
620
- });
621
- const attempt = retryOf ? { attempt: retryOf } : {};
622
- await store.write(file, { stage: "running", executionId: execution.id, ...attempt });
623
- let state = "succeeded";
624
- let output;
625
- let generated;
626
- let targetError;
627
- try {
628
- const result = await options.target(targetInputs, {
629
- config: targetConfig,
630
- item: structuredClone(frozenCase),
631
- span,
632
- executionId: execution.id,
633
- files: structuredClone(inputFiles),
634
- outputDirectory,
609
+ let outcome;
610
+ try {
611
+ checkpoint = await options.hue.withSpan("hue.experiment.case", async (span) => {
612
+ const start = {
613
+ stage: "starting",
614
+ startKey: randomUUID(),
615
+ traceExternalId: span.traceId,
616
+ ...(retryOf ? { previousExecutionId: retryOf } : {}),
617
+ };
618
+ await store.write(file, start);
619
+ const execution = await options.client.startExecution(experiment.id, item.id, {
620
+ idempotencyKey: start.startKey,
621
+ traceExternalId: span.traceId,
622
+ ...retry(retryOf),
635
623
  });
636
- if (result instanceof TargetResult) {
637
- output = result.output;
638
- generated = result.files;
639
- }
640
- else
641
- output = result;
642
- }
643
- catch (error) {
644
- if (error instanceof TargetOutcomeUncertainError)
645
- throw error;
646
- // A stop the caller asked for is no outcome: the execution stays open for the
647
- // resumed run to replace instead of being scored as cancelled.
648
- if (error instanceof TargetCancelledError && options.signal?.aborted) {
649
- options.hue.recordError(span.span, error);
650
- await store.write(file, {
651
- stage: "interrupted",
624
+ const attempt = retryOf ? { attempt: retryOf } : {};
625
+ await store.write(file, { stage: "running", executionId: execution.id, ...attempt });
626
+ let state = "succeeded";
627
+ let output;
628
+ let generated;
629
+ let targetError;
630
+ try {
631
+ const result = await options.target(targetInputs, {
632
+ config: targetConfig,
633
+ item: structuredClone(frozenCase),
634
+ span,
652
635
  executionId: execution.id,
653
- ...attempt,
636
+ files: structuredClone(inputFiles),
637
+ outputDirectory,
654
638
  });
655
- throw error;
656
- }
657
- state = error instanceof TargetCancelledError ? "cancelled" : "error";
658
- targetError = error;
659
- options.hue.recordError(span.span, error);
660
- }
661
- // Output validation is outside the target catch: a successful target never becomes an agent error because upload serialization failed.
662
- if (output !== undefined) {
663
- try {
664
- output = json(output);
639
+ if (result instanceof TargetResult) {
640
+ output = result.output;
641
+ generated = result.files;
642
+ }
643
+ else
644
+ output = result;
665
645
  }
666
646
  catch (error) {
667
- // An output over the size, count or depth bounds is the target's own failure, as
668
- // a file it cannot deliver is: the case completes as an error and the run goes
669
- // on. Output that is not JSON at all still stops the run for inspection.
670
- const limit = error instanceof RangeError ? outputLimits.get(error.message) : undefined;
671
- if (limit === undefined) {
647
+ if (error instanceof TargetOutcomeUncertainError)
648
+ throw error;
649
+ // A stop the caller asked for is no outcome: the execution stays open for the
650
+ // resumed run to replace instead of being scored as cancelled.
651
+ if (error instanceof TargetCancelledError && options.signal?.aborted) {
652
+ options.hue.recordError(span.span, error);
672
653
  await store.write(file, {
673
- stage: "serialization_failed",
654
+ stage: "interrupted",
674
655
  executionId: execution.id,
656
+ ...attempt,
675
657
  });
676
- throw new OutcomeSerializationError(execution.id);
677
- }
678
- state = "error";
679
- output = undefined;
680
- targetError = new OutputTooLargeError(limit);
681
- options.hue.recordError(span.span, targetError);
682
- }
683
- }
684
- if (output !== undefined)
685
- span.setOutput(output);
686
- let staged = [];
687
- // An empty declared list (a direct case answered only through stdout, or
688
- // `withFiles(output, [])`) means no generated files, not a missing-files error.
689
- if (generated !== undefined && generated.length > 0 && state === "succeeded") {
690
- try {
691
- staged = await stageOutputFiles(generated, join(caseDirectory, "outputs"));
692
- }
693
- catch (error) {
694
- // Files the target declared but did not deliver are its own failure; the
695
- // outcome is still saved instead of leaving the execution uncertain.
696
- if (!(error instanceof OutputFileError))
697
658
  throw error;
698
- state = "error";
659
+ }
660
+ state = error instanceof TargetCancelledError ? "cancelled" : "error";
699
661
  targetError = error;
700
662
  options.hue.recordError(span.span, error);
701
663
  }
664
+ // Output validation is outside the target catch: a successful target never becomes an agent error because upload serialization failed.
665
+ if (output !== undefined) {
666
+ try {
667
+ output = json(output);
668
+ }
669
+ catch (error) {
670
+ // An output over the size, count or depth bounds is the target's own failure, as
671
+ // a file it cannot deliver is: the case completes as an error and the run goes
672
+ // on. Output that is not JSON at all still stops the run for inspection.
673
+ const limit = error instanceof RangeError ? outputLimits.get(error.message) : undefined;
674
+ if (limit === undefined) {
675
+ await store.write(file, {
676
+ stage: "serialization_failed",
677
+ executionId: execution.id,
678
+ });
679
+ throw new OutcomeSerializationError(execution.id);
680
+ }
681
+ state = "error";
682
+ output = undefined;
683
+ targetError = new OutputTooLargeError(limit);
684
+ options.hue.recordError(span.span, targetError);
685
+ }
686
+ }
687
+ if (output !== undefined)
688
+ span.setOutput(output);
689
+ let staged = [];
690
+ // An empty declared list (a direct case answered only through stdout, or
691
+ // `withFiles(output, [])`) means no generated files, not a missing-files error.
692
+ if (generated !== undefined && generated.length > 0 && state === "succeeded") {
693
+ try {
694
+ staged = await stageOutputFiles(generated, join(caseDirectory, "outputs"));
695
+ }
696
+ catch (error) {
697
+ // Files the target declared but did not deliver are its own failure; the
698
+ // outcome is still saved instead of leaving the execution uncertain.
699
+ if (!(error instanceof OutputFileError))
700
+ throw error;
701
+ state = "error";
702
+ targetError = error;
703
+ options.hue.recordError(span.span, error);
704
+ }
705
+ }
706
+ const uploading = {
707
+ stage: "uploading",
708
+ executionId: execution.id,
709
+ trace: { traceId: span.traceId, spanId: span.spanId },
710
+ state,
711
+ hasOutput: output !== undefined,
712
+ ...(options.persistResultContent && output !== undefined ? { output } : {}),
713
+ ...(state === "error" ? { error: errorPayload(targetError) } : {}),
714
+ files: staged,
715
+ ...attempt,
716
+ };
717
+ // Without persisted result content a restart cannot reconstruct the outcome; the
718
+ // saved stage then reports the execution as uncertain instead of guessing.
719
+ files.keepOutputs = true;
720
+ await store.write(file, uploading);
721
+ outcome = uploading;
722
+ return prepare(file, uploading, frozenCase, caseDirectory, output);
723
+ }, {
724
+ parentContext: ROOT_CONTEXT,
725
+ input: frozenCase.inputs,
726
+ attributes: { "hue.experiment.id": experiment.id, "hue.dataset.case.id": item.id },
727
+ });
728
+ }
729
+ catch (error) {
730
+ // A failure after the outcome was saved (fetching the scorers' files, uploading the
731
+ // target's files): the root has ended, so the count of spans the case ended is saved with
732
+ // the outcome, and a resume holds the trace's receipt to it before completing.
733
+ const spans = outcome?.trace
734
+ ? options.hue.transport.spansEnded?.(outcome.trace.traceId)
735
+ : undefined;
736
+ if (outcome?.trace && spans !== undefined) {
737
+ outcome.trace.spans = spans;
738
+ await store.write(file, outcome);
702
739
  }
703
- const uploading = {
704
- stage: "uploading",
705
- executionId: execution.id,
706
- trace: { traceId: span.traceId, spanId: span.spanId },
707
- state,
708
- hasOutput: output !== undefined,
709
- ...(options.persistResultContent && output !== undefined ? { output } : {}),
710
- ...(state === "error" ? { error: errorPayload(targetError) } : {}),
711
- files: staged,
712
- ...attempt,
713
- };
714
- // Without persisted result content a restart cannot reconstruct the outcome; the
715
- // saved stage then reports the execution as uncertain instead of guessing.
716
- files.keepOutputs = true;
717
- await store.write(file, uploading);
718
- return prepare(file, uploading, frozenCase, caseDirectory, output);
719
- }, {
720
- parentContext: ROOT_CONTEXT,
721
- input: frozenCase.inputs,
722
- attributes: { "hue.experiment.id": experiment.id, "hue.dataset.case.id": item.id },
723
- });
740
+ throw error;
741
+ }
724
742
  files.keepOutputs = false;
725
743
  // End root before waiting for both OTLP signals. Export failure leaves the prepared checkpoint intact.
726
744
  let exportError;
@@ -888,9 +906,14 @@ export async function runExperiment(options) {
888
906
  await pool(items, concurrency, async (item) => {
889
907
  // A world case's directory goes however the case ends, a forced exit included. An
890
908
  // interrupted upload keeps only the staged outputs it resumes from; inputs are downloaded
891
- // anew for scoring. A direct case has no such directory, so nothing is removed for it.
909
+ // anew for scoring. A direct case's directory stays for inspection, except the scorers'
910
+ // copies of evaluator-only files, which go too, so no later case's target finds them.
892
911
  const files = { keepOutputs: true, directory: worldDirectoryOf(item.id) };
893
- const untrack = onForcedExit(() => releaseWorldFilesSync(files.directory, files.keepOutputs));
912
+ const evaluatorInputs = join(directDirectoryOf(item.id), "evaluator-inputs");
913
+ const untrack = onForcedExit(() => {
914
+ releaseWorldFilesSync(files.directory, files.keepOutputs);
915
+ rmSync(evaluatorInputs, { recursive: true, force: true });
916
+ });
894
917
  try {
895
918
  await runCase(item, files);
896
919
  await releaseWorldFiles(files.directory, false);
@@ -900,6 +923,7 @@ export async function runExperiment(options) {
900
923
  throw error;
901
924
  }
902
925
  finally {
926
+ await removeCaseFiles(evaluatorInputs);
903
927
  untrack();
904
928
  }
905
929
  });
@@ -172,7 +172,54 @@ export interface CaseWrite {
172
172
  metadata?: Record<string, JsonValue>;
173
173
  /** Immutable simulated-world version selected for this case. */
174
174
  environmentVersionId?: string | null;
175
+ /** Input files pinned to the case, at most 32: artifacts this project already holds, or bytes
176
+ * the client uploads first. Roles other than `org_template` and `evaluator_reference` reach the
177
+ * target; those two reach only scorers. */
178
+ files?: CaseFileWrite[];
175
179
  }
180
+ /** A pinned input file as the case API takes it. */
181
+ export interface CaseFileReference {
182
+ /** A ready artifact of this project. */
183
+ artifactId: string;
184
+ /** Who receives the file. */
185
+ role: CaseFile["role"];
186
+ }
187
+ /**
188
+ * A pinned input file for {@link CaseWrite.files}: a {@link CaseFileReference}, or a file the
189
+ * client uploads as a verified artifact, from `bytes` or read from `path`: hashed a slice at a
190
+ * time when the case is checked, then read again as it is uploaded, one file at a time. An
191
+ * uploaded file must have one of `outputContentTypes`, a well-formed name of 1–255 UTF-16 code
192
+ * units without path separators or control characters, and 1 byte to 25 MiB.
193
+ */
194
+ export type CaseFileWrite = (CaseFileReference & {
195
+ /** Not set on an artifact reference: the artifact keeps its own name. */
196
+ filename?: undefined;
197
+ /** Not set on an artifact reference: the artifact keeps its own type. */
198
+ contentType?: undefined;
199
+ /** Not set in this form. */
200
+ bytes?: undefined;
201
+ /** Not set in this form. */
202
+ path?: undefined;
203
+ }) | ({
204
+ /** Who receives the file. */
205
+ role: CaseFile["role"];
206
+ /** File name Hue stores. */
207
+ filename: string;
208
+ /** One of `outputContentTypes`, the media types Hue stores as artifacts. */
209
+ contentType: string;
210
+ /** Not set when the file is given as bytes or a path. */
211
+ artifactId?: undefined;
212
+ } & ({
213
+ /** The file's bytes. */
214
+ bytes: Uint8Array;
215
+ /** Not set in this form. */
216
+ path?: undefined;
217
+ } | {
218
+ /** Path of the file on this machine. */
219
+ path: string;
220
+ /** Not set in this form. */
221
+ bytes?: undefined;
222
+ }));
176
223
  /** A typed metric a scorer declares and must report exactly once per scored result. */
177
224
  export type MetricDefinition = {
178
225
  /** Metric name. */
@@ -851,11 +898,13 @@ export type OutputFile = {
851
898
  /** Path of the generated file on this machine. */
852
899
  path: string;
853
900
  /** Not used when `path` is given. */
901
+ /** Not set in this form. */
854
902
  bytes?: undefined;
855
903
  } | {
856
904
  /** Generated bytes held in memory. */
857
905
  bytes: Uint8Array;
858
906
  /** Not used when `bytes` is given. */
907
+ /** Not set in this form. */
859
908
  path?: undefined;
860
909
  });
861
910
  /** A target's saved outcome when it produced files. Create it with `withFiles`. */
package/dist/evals.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  export { ArtifactSizeError, createEvaluationClient, EvaluationClient, HueApiError, isTransientApiError, } from "./evals/client.js";
2
2
  export type { EvaluationClientOptions } from "./evals/client.js";
3
+ export { MediaFetchError, rehydrateMedia } from "./evals/media.js";
4
+ export type { MediaClient, MediaFetchErrorReason, MediaFetchOptions, MediaFetchTarget, MediaFile, MediaResolution, MediaResolveFailure, MediaResolveOptions, MediaSourceFile, MediaWriteOptions, } from "./evals/media.js";
3
5
  export { runExperiment, rescore, UncertainExecutionError, OutcomeSerializationError, TargetCancelledError, TargetOutcomeUncertainError, TargetTimeoutError, TraceExportUnacknowledgedError, } from "./evals/runner.js";
4
6
  export type { RunExperimentOptions, RunExperimentTargetContext, RescoreOptions, RunnerReport, TelemetryIssueCount, TelemetryNotAccepted, TracePending, } from "./evals/runner.js";
5
7
  export { TargetResult, withFiles } from "./evals/types.js";
package/dist/evals.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ArtifactSizeError, createEvaluationClient, EvaluationClient, HueApiError, isTransientApiError, } from "./evals/client.js";
2
+ export { MediaFetchError, rehydrateMedia } from "./evals/media.js";
2
3
  export { runExperiment, rescore, UncertainExecutionError, OutcomeSerializationError, TargetCancelledError, TargetOutcomeUncertainError, TargetTimeoutError, TraceExportUnacknowledgedError, } from "./evals/runner.js";
3
4
  export { TargetResult, withFiles } from "./evals/types.js";
4
5
  export { CaseFileError, outputContentTypes, outputFileLimits, OutputFileError, safeFilename, targetFileRoles, } from "./evals/files.js";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createHue, createHueSafe, HueClient, HueConnectionError, type ExistingHueProviders, } from "./client.js";
2
+ export { Attachment, type AttachmentOptions } from "./attachment.js";
2
3
  export { createHueTransport, HueTransport, HueExportError } from "./transport.js";
3
4
  export type { RecordValue } from "./transport.js";
4
5
  export { hueExperimentalTelemetry } from "./experimental-telemetry.js";
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createHue, createHueSafe, HueClient, HueConnectionError, } from "./client.js";
2
+ export { Attachment } from "./attachment.js";
2
3
  export { createHueTransport, HueTransport, HueExportError } from "./transport.js";
3
4
  export { hueExperimentalTelemetry } from "./experimental-telemetry.js";
4
5
  export { contentPrefixes } from "./privacy.js";
@@ -1,3 +1,4 @@
1
+ import { type JsonEdit } from "./json-edits.js";
1
2
  /** Text media above this decoded byte limit is offloaded; binary media always uses a digest. */
2
3
  export declare const INLINE_FILE_LIMIT: number;
3
4
  /** The longest message text, in UTF-16 code units, inspected for inline files. */
@@ -6,12 +7,29 @@ export declare const MAX_INLINE_FILE_TEXT: number;
6
7
  export declare const INLINE_FILE_TEXT_PER_RECORD: number;
7
8
  /** Whether an attribute is one of the recorded message attributes that can inline files. */
8
9
  export declare function isMessageKey(key: string): boolean;
10
+ /** How an attribute's text is read for files: JSON by convention, metadata, an OpenLLMetry parts
11
+ * list, or a URL that is the file. */
12
+ export type MediaReading = "json" | "metadata" | "parts" | "url";
13
+ /** How an attribute's text is read for files, when it is read at all. */
14
+ export declare function readingOf(key: string): MediaReading | undefined;
15
+ /**
16
+ * The attributes of a record that hold literal text: OpenInference's `input.value` and
17
+ * `output.value` when the record declares `input.mime_type` / `output.mime_type` as `text/plain`.
18
+ * Hue reads no JSON, and so no file, in them; neither does the SDK.
19
+ */
20
+ export declare function literalKeys(attributes: unknown): ReadonlySet<string>;
21
+ /** Whether a span attribute is one whose value the SDK inspects for inline media: the attributes
22
+ * Hue's reader reads files from. */
23
+ export declare function isMediaKey(key: string): boolean;
9
24
  /** An inline file's bytes, whether they were decoded from the part's text (base64 or
10
25
  * percent-escapes) rather than taken as its UTF-8, and the media type its `data:` URL names. */
11
26
  export interface InlineFileBytes {
12
27
  bytes: Buffer;
13
28
  decoded: boolean;
14
29
  urlMediaType?: string;
30
+ /** The bytes were decoded from text that reads as base64 by its alphabet alone, not from a
31
+ * `data:` URL or a field its convention declares base64. */
32
+ bareBase64?: boolean;
15
33
  }
16
34
  /**
17
35
  * The bytes an inline file part carries, the file's own bytes whatever its media type: a `data:`
@@ -20,29 +38,117 @@ export interface InlineFileBytes {
20
38
  * `data:` URL whose data does not decode is taken as UTF-8 too.
21
39
  */
22
40
  export declare function inlineFileBytes(content: string): InlineFileBytes;
41
+ /** JSON text a placed file sits in: its edits, at JSON pointers relative to `at`, the pointer of
42
+ * the text in the recorded value ("" for the value itself). */
43
+ export interface MediaDocument {
44
+ at: string;
45
+ edits: JsonEdit[];
46
+ }
47
+ /** A string inside a recorded value whose JSON the walk read (a tool call's arguments, a tool
48
+ * result): written again once a file inside it is placed, every byte the placement does not
49
+ * change kept as recorded. */
50
+ export interface EncodedValue extends MediaDocument {
51
+ owner: Record<string, unknown>;
52
+ key: string;
53
+ value: unknown;
54
+ dirty: boolean;
55
+ /** The string as recorded. */
56
+ text: string;
57
+ /** The JSON text the string sits in: an encoded string's, else the recorded value's. */
58
+ parent: MediaDocument;
59
+ }
23
60
  /** A part and the exact leaf that contains its bytes. Nested provider metadata stays in place. */
24
61
  export interface InlineFilePart {
62
+ /** The part that carries the digest: the provider part, or for OpenAI assistant audio the
63
+ * message. Unused for a whole string. */
25
64
  part: Record<string, unknown>;
26
- owner: Record<string, unknown>;
27
- key: string;
65
+ owner: Record<string, unknown> | unknown[];
66
+ key: string | number;
28
67
  content: string;
29
68
  pointer: string;
30
69
  partPointer: string;
31
70
  contentType?: string;
32
71
  name?: string;
33
72
  base64?: boolean;
73
+ /** A whole string that is a `data:` URL: replaced by a GenAI `blob` part in digest form. */
74
+ whole?: boolean;
75
+ /** The JSON-encoded strings the file sits in, outermost first: no `hue.blobs` key can address
76
+ * inside a string, so such a file is placed by its digest. */
77
+ encoded?: EncodedValue[];
78
+ /** The JSON text the file sits in, which records its placement as edits. */
79
+ document?: MediaDocument;
34
80
  }
35
81
  export declare function isMediaName(value: unknown): value is string;
36
82
  /** Whether the receiver can preview these bytes as text. */
37
83
  export declare function isTextMediaType(contentType: string): boolean;
38
- /** Cheap shared prefilter before bounded parsing of span message attributes. */
84
+ /** Cheap shared prefilter before bounded parsing of the attributes inspected for media. */
39
85
  export declare function mayInlineFiles(key: string, value: unknown): boolean;
86
+ /** Whether text may hold inline media at all: cheap, before it is parsed or walked. */
87
+ export declare function mayHoldMedia(value: unknown): value is string;
40
88
  /** A printable MIME type with optional parameters, accepted by the upload contract. */
41
89
  export declare function isMediaContentType(value: unknown): value is string;
42
90
  /** Detect the content pointer, MIME, name, and encoding contract of a provider media part. */
43
91
  export declare function contentPath(part: Record<string, unknown>, pointer?: string): InlineFilePart | undefined;
44
- /** Inline media in document order. The caller applies the decoded text threshold. */
45
- export declare function largeInlineFileParts(value: unknown): InlineFilePart[];
92
+ /** The modality a media type implies, as Hue's reader names it. */
93
+ export declare function modalityOf(mediaType: string): "image" | "audio" | "video" | "document" | "file";
94
+ /** How deep Hue's reader looks for files in a recorded value: a part more than ten levels below
95
+ * the value's root (an encoded string's JSON counting as a level) is not read as a file, so it is
96
+ * not inspected either. */
97
+ export declare const MAX_MEDIA_DEPTH = 10;
98
+ /**
99
+ * Whether Hue's reader reads JSON text as the value it encodes, and so reads files in it: nested
100
+ * at most 32 levels, with no number JavaScript cannot hold exactly (an integer past 2^53, or one
101
+ * past the double range). Hue keeps any other text as it is, so the SDK leaves it as recorded.
102
+ */
103
+ export declare function readerParses(value: unknown): boolean;
104
+ /** The files a recorded value holds, the box holding the value (so a whole-string file at its
105
+ * root can be replaced), the JSON-encoded strings the walk read, innermost first, to write again
106
+ * once a file inside one is placed, and the value's own JSON text when it was read from text. */
107
+ export interface MediaValue {
108
+ box: {
109
+ value: unknown;
110
+ };
111
+ files: InlineFilePart[];
112
+ encoded: EncodedValue[];
113
+ /** The value's JSON text as recorded, edited in place when its files are placed. */
114
+ source?: string;
115
+ document: MediaDocument;
116
+ }
117
+ /**
118
+ * Every file a recorded value carries for upload, in reading order, as Hue's reader finds them
119
+ * (`forEachMediaPart`): a provider part with inline bytes, an OpenAI assistant message's audio,
120
+ * a whole string that is a typed `data:` URL, and the files inside a tool call's or tool result's
121
+ * JSON-encoded string. A part whose bytes are not inline (a remote URL, a file id) is left whole.
122
+ * The caller applies the decoded text threshold.
123
+ */
124
+ export declare function mediaIn(value: unknown, source?: string): MediaValue;
125
+ /**
126
+ * An attribute's recorded text read for files as Hue's reader reads that attribute: JSON by its
127
+ * convention; metadata as JSON when it reads as an object or array, otherwise as the text itself;
128
+ * an OpenLLMetry content as the parts list it encodes (any other content stays text); an
129
+ * OpenInference image URL as the text itself. Undefined for text that reading finds nothing in.
130
+ * Throws for JSON that does not parse or nests too deep.
131
+ */
132
+ export declare function readMediaText(key: string, text: string): MediaValue | undefined;
133
+ /** The recorded value's text once its files are placed: its JSON text as recorded with only the
134
+ * placed files' values (or their parts' members) replaced, each JSON-encoded string a placed file
135
+ * sits in written again the same way, innermost first. */
136
+ export declare function placedMediaText(media: MediaValue): string;
137
+ /** Each JSON-encoded string a placed file sits in, written again, innermost first: the string as
138
+ * recorded with only its placed files changed. */
139
+ export declare function reencodeMedia(media: MediaValue): void;
140
+ /** Whether a found file has bytes to place: nonempty, and a whole string's `data:` URL decodes. */
141
+ export declare function placeable(file: InlineFilePart, decoded: InlineFileBytes): boolean;
142
+ /** Whether an uploaded file keeps a 16 KiB prefix of its content in place (text media in a
143
+ * provider part, whose entry names the content) rather than its digest. A whole string, a file
144
+ * inside a JSON-encoded string, and a text file a part holds as bare base64 (a GenAI `blob`,
145
+ * Vertex `media` or AI SDK part, whose content is not the text itself) take the digest form. */
146
+ export declare function keepsPrefix(file: InlineFilePart, textual: boolean, decoded: InlineFileBytes): boolean;
147
+ /** A file's bytes: a field its convention declares base64 decoded, any other content read as
148
+ * Hue's reader reads it, whatever the part's media type (`inlineFileBytes`): a `data:` URL by its
149
+ * own encoding, text that reads as base64 decoded (what the GenAI conventions, and
150
+ * `client.media.resolve`, write in a `blob` or `media` part for every media type), anything else
151
+ * as its UTF-8. */
46
152
  export declare function mediaBytes(file: InlineFilePart): InlineFileBytes;
47
153
  export declare function mediaContentType(file: InlineFilePart, decoded: InlineFileBytes): string;
48
154
  export interface FileDigest {
@@ -57,10 +163,36 @@ export declare class MediaDigestMemo {
57
163
  digest(file: InlineFilePart, decoded?: InlineFileBytes, traceId?: string): FileDigest;
58
164
  bytes(bytes: Uint8Array, traceId: string): FileDigest;
59
165
  }
60
- /** Digest placement removes only the leaf and adds identity to the provider part. */
166
+ /** Digest placement removes only the leaf and adds identity to the provider part (the message,
167
+ * for OpenAI assistant audio); a whole string becomes a GenAI `blob` part in digest form. */
61
168
  export declare function digestPart(file: InlineFilePart, digest: FileDigest): void;
169
+ /** Prefix placement keeps the first 16 KiB of a text file's content in place. */
170
+ export declare function prefixPart(file: InlineFilePart, prefix: string): void;
171
+ /**
172
+ * A span's own attribute with its inline media replaced by their digest, as export places media
173
+ * it does not upload. Only the recorded message attributes (`isMessageKey`) shrink without an
174
+ * upload; every other inspected attribute keeps its bytes inline unless they upload, so `anyKey`
175
+ * asks for the digest form of any inspected attribute (what the queue is charged for a value it
176
+ * holds whole for upload).
177
+ */
62
178
  export declare function hashInlineFiles(key: string, value: unknown, count?: {
63
179
  files: number;
64
- }, memo?: MediaDigestMemo, traceId?: string): unknown;
180
+ }, memo?: MediaDigestMemo, traceId?: string, anyKey?: boolean): unknown;
65
181
  /** Nested message attributes retain small media and digest larger media without upload state. */
66
- export declare function hashNestedInlineFiles(key: string, value: unknown): unknown;
182
+ export declare function hashNestedInlineFiles(key: string, value: unknown, count?: {
183
+ files: number;
184
+ }): unknown;
185
+ /**
186
+ * Each file a recorded value holds replaced by its digest, as export places a file it does not
187
+ * upload: binary media of any size (`nested`: over the inline limit) and text media over the
188
+ * inline limit. Whether any was replaced; `count` counts them.
189
+ */
190
+ export declare function digestMedia(media: MediaValue, nested: boolean, count?: {
191
+ files: number;
192
+ }, memo?: MediaDigestMemo, traceId?: string): boolean;
193
+ /**
194
+ * The UTF-8 size of a structured value's JSON once each file the SDK may upload from it, within
195
+ * the inspection limits, is placed in its digest form: whether a log body over the value cap fits
196
+ * it once its media upload. Mutates `value`, a copy the caller owns.
197
+ */
198
+ export declare function digestFormBytes(value: unknown): number;