@opencode/ai 0.0.0-dev-519 → 0.0.0-dev-520

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.
@@ -485,68 +485,15 @@ const lowerServerToolResult = Effect.fnUntraced(function* (part, providerMetadat
485
485
  content: payload,
486
486
  };
487
487
  });
488
- const fileIdFromMetadata = (metadata) => {
489
- if (!metadata)
490
- return undefined;
491
- const anthropic = metadata.anthropic;
492
- if (ProviderShared.isRecord(anthropic)) {
493
- if (typeof anthropic.file_id === "string")
494
- return anthropic.file_id;
495
- if (typeof anthropic.fileId === "string")
496
- return anthropic.fileId;
497
- }
498
- if (typeof metadata.file_id === "string")
499
- return metadata.file_id;
500
- if (typeof metadata.fileId === "string")
501
- return metadata.fileId;
502
- return undefined;
503
- };
504
- const transformationsFromMetadata = (metadata) => {
505
- if (!metadata)
506
- return undefined;
507
- const anthropic = ProviderShared.isRecord(metadata.anthropic) ? metadata.anthropic : undefined;
508
- const raw = anthropic?.transformations ?? metadata.transformations;
509
- if (ProviderShared.isRecord(raw)) {
510
- const value = raw.oversized_image;
511
- if (value === "downsize" || value === "error")
512
- return { oversized_image: value };
513
- }
514
- if (anthropic && (anthropic.oversized_image === "downsize" || anthropic.oversized_image === "error"))
515
- return { oversized_image: anthropic.oversized_image };
516
- return undefined;
517
- };
518
- const documentTitleFromPart = (part) => {
519
- if (part.metadata !== undefined) {
520
- const anthropic = part.metadata.anthropic;
521
- if (ProviderShared.isRecord(anthropic) && typeof anthropic.title === "string")
522
- return anthropic.title;
523
- if (typeof part.metadata.title === "string")
524
- return part.metadata.title;
525
- }
526
- if (part.filename && part.filename.length > 0)
527
- return part.filename;
528
- return undefined;
529
- };
530
- const documentContextFromMetadata = (metadata) => {
531
- if (!metadata)
532
- return undefined;
533
- const anthropic = ProviderShared.isRecord(metadata.anthropic) ? metadata.anthropic : undefined;
534
- if (anthropic && typeof anthropic.context === "string")
535
- return anthropic.context;
536
- if (typeof metadata.context === "string")
537
- return metadata.context;
538
- return undefined;
539
- };
540
- const citationsFromMetadata = (metadata) => {
541
- if (!metadata)
542
- return undefined;
543
- const raw = ProviderShared.isRecord(metadata.anthropic)
544
- ? (metadata.anthropic.citations ?? metadata.citations)
545
- : metadata.citations;
546
- if (ProviderShared.isRecord(raw) && typeof raw.enabled === "boolean")
547
- return { enabled: raw.enabled };
548
- return undefined;
549
- };
488
+ // Per-part Anthropic block fields, read from `providerMetadata[providerMetadataKey]` with Anthropic's wire names.
489
+ const MediaOptions = Schema.Struct({
490
+ file_id: Schema.optional(Schema.String),
491
+ title: Schema.optional(Schema.String),
492
+ context: Schema.optional(Schema.String),
493
+ citations: Schema.optional(Schema.Struct({ enabled: Schema.Boolean })),
494
+ transformations: Schema.optional(AnthropicImageTransformations),
495
+ });
496
+ const decodeMediaOptions = ProviderShared.validateWith(Schema.decodeUnknownEffect(MediaOptions));
550
497
  const isHttpUrl = (value) => /^https?:\/\//i.test(value.trim());
551
498
  const lowerMedia = Effect.fnUntraced(function* (part, request, breakpoints) {
552
499
  const mime = part.media.mediaType.toLowerCase();
@@ -564,34 +511,29 @@ const lowerMedia = Effect.fnUntraced(function* (part, request, breakpoints) {
564
511
  ...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
565
512
  };
566
513
  }
567
- const fileId = fileIdFromMetadata(part.metadata);
568
- const image = (source) => {
569
- const transformations = transformationsFromMetadata(part.metadata);
570
- return {
571
- type: "image",
572
- source,
573
- ...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
574
- ...(transformations === undefined ? {} : { transformations }),
575
- };
576
- };
514
+ const options = yield* decodeMediaOptions(part.providerMetadata?.[request.model.route.providerMetadataKey ?? request.model.provider] ?? {});
515
+ const image = (source) => ({
516
+ type: "image",
517
+ source,
518
+ ...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
519
+ ...(options.transformations === undefined ? {} : { transformations: options.transformations }),
520
+ });
577
521
  const document = (source) => {
578
- const title = documentTitleFromPart(part);
579
- const context = documentContextFromMetadata(part.metadata);
580
- const citations = citationsFromMetadata(part.metadata);
522
+ const title = options.title ?? (part.filename ? part.filename : undefined);
581
523
  return {
582
524
  type: "document",
583
525
  source,
584
526
  ...(cacheControlValue === undefined ? {} : { cache_control: cacheControlValue }),
585
527
  ...(title === undefined ? {} : { title }),
586
- ...(context === undefined ? {} : { context }),
587
- ...(citations === undefined ? {} : { citations }),
528
+ ...(options.context === undefined ? {} : { context: options.context }),
529
+ ...(options.citations === undefined ? {} : { citations: options.citations }),
588
530
  };
589
531
  };
590
532
  // SDK file sources: FileImageSource:2350 / FileDocumentSource:2344 {type:"file", file_id}
591
- if (fileId) {
533
+ if (options.file_id) {
592
534
  if (mime.startsWith("image/"))
593
- return image({ type: "file", file_id: fileId });
594
- return document({ type: "file", file_id: fileId });
535
+ return image({ type: "file", file_id: options.file_id });
536
+ return document({ type: "file", file_id: options.file_id });
595
537
  }
596
538
  const rawString = ProviderShared.mediaUrl(part.media)?.trim();
597
539
  // SDK URL sources: URLImageSource:3817 / URLPDFSource:3823 {type:"url", url}
@@ -27,9 +27,6 @@ export declare const lower: (part: {
27
27
  readonly media: import("../../media.js").Asset;
28
28
  readonly filename?: string | undefined;
29
29
  readonly cache?: import("../../schema/options.js").CacheHint | undefined;
30
- readonly metadata?: {
31
- readonly [x: string]: unknown;
32
- } | undefined;
33
30
  readonly providerMetadata?: {
34
31
  readonly [x: string]: {
35
32
  readonly [x: string]: unknown;
@@ -63,7 +63,6 @@ export declare const MediaPart: Schema.Struct<{
63
63
  }>, never, never>;
64
64
  readonly filename: Schema.optional<Schema.String>;
65
65
  readonly cache: Schema.optional<typeof CacheHint>;
66
- readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
67
66
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
68
67
  }>;
69
68
  export type MediaPart = Schema.Schema.Type<typeof MediaPart>;
@@ -319,7 +318,6 @@ export declare const ContentPart: Schema.toTaggedUnion<"type", readonly [Schema.
319
318
  }>, never, never>;
320
319
  readonly filename: Schema.optional<Schema.String>;
321
320
  readonly cache: Schema.optional<typeof CacheHint>;
322
- readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
323
321
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
324
322
  }>, Schema.Struct<{
325
323
  readonly type: Schema.Literal<"tool-call">;
@@ -459,7 +457,6 @@ declare const Message_base: Schema.Class<Message, Schema.Struct<{
459
457
  }>, never, never>;
460
458
  readonly filename: Schema.optional<Schema.String>;
461
459
  readonly cache: Schema.optional<typeof CacheHint>;
462
- readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
463
460
  readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
464
461
  }>, Schema.Struct<{
465
462
  readonly type: Schema.Literal<"tool-call">;
@@ -32,7 +32,6 @@ export const MediaPart = Schema.Struct({
32
32
  media: Media.AssetSchema,
33
33
  filename: Schema.optional(Schema.String),
34
34
  cache: Schema.optional(CacheHint),
35
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
36
35
  providerMetadata: Schema.optional(ProviderMetadata),
37
36
  }).annotate({ identifier: "LLM.Content.Media" });
38
37
  const toolResultValueSchema = Schema.Union([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "0.0.0-dev-519",
3
+ "version": "0.0.0-dev-520",
4
4
  "name": "@opencode/ai",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -520,7 +520,7 @@
520
520
  "devDependencies": {
521
521
  "@clack/prompts": "1.0.0-alpha.1",
522
522
  "@effect/platform-node": "4.1.0",
523
- "@opencode/http-recorder": "0.0.0-dev-519",
523
+ "@opencode/http-recorder": "0.0.0-dev-520",
524
524
  "@tsconfig/bun": "1.0.9",
525
525
  "@types/bun": "1.4.3",
526
526
  "@typescript/native": "npm:typescript@7.1.0-beta",
@@ -530,7 +530,7 @@
530
530
  "@aws-sdk/credential-providers": "3.1057.0",
531
531
  "@smithy/eventstream-codec": "4.2.14",
532
532
  "@smithy/util-utf8": "4.2.2",
533
- "@opencode/schema": "0.0.0-dev-519",
533
+ "@opencode/schema": "0.0.0-dev-520",
534
534
  "aws4fetch": "1.0.20",
535
535
  "effect": "4.1.0",
536
536
  "google-auth-library": "10.5.0"