@opencode/ai 2.2.6 → 2.2.7

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.
Files changed (105) hide show
  1. package/README.md +96 -4
  2. package/dist/ai-client.d.ts +2 -2
  3. package/dist/ai-client.js +2 -1
  4. package/dist/decision.d.ts +10 -0
  5. package/dist/decision.js +2 -0
  6. package/dist/effect.d.ts +6 -0
  7. package/dist/effect.js +4 -0
  8. package/dist/embedding-client.d.ts +21 -0
  9. package/dist/embedding-client.js +30 -0
  10. package/dist/embedding.d.ts +111 -0
  11. package/dist/embedding.js +75 -0
  12. package/dist/image.d.ts +0 -1
  13. package/dist/image.js +0 -3
  14. package/dist/index.d.ts +7 -2
  15. package/dist/index.js +5 -0
  16. package/dist/protocols/alibaba-chat.d.ts +4 -0
  17. package/dist/protocols/anthropic-messages.js +3 -3
  18. package/dist/protocols/google-embed-content.d.ts +34 -0
  19. package/dist/protocols/google-embed-content.js +110 -0
  20. package/dist/protocols/google-vertex-predict-embeddings.d.ts +18 -0
  21. package/dist/protocols/google-vertex-predict-embeddings.js +74 -0
  22. package/dist/protocols/index.d.ts +3 -0
  23. package/dist/protocols/index.js +3 -0
  24. package/dist/protocols/open-responses.d.ts +1 -1
  25. package/dist/protocols/open-responses.js +31 -8
  26. package/dist/protocols/openai-chat.d.ts +24 -0
  27. package/dist/protocols/openai-chat.js +37 -11
  28. package/dist/protocols/openai-compatible-chat.d.ts +1 -0
  29. package/dist/protocols/openai-decisions.js +14 -1
  30. package/dist/protocols/openai-embeddings.d.ts +16 -0
  31. package/dist/protocols/openai-embeddings.js +76 -0
  32. package/dist/protocols/shared.d.ts +13 -3
  33. package/dist/protocols/shared.js +27 -4
  34. package/dist/protocols/system-one.js +8 -1
  35. package/dist/protocols/venice-chat.d.ts +4 -0
  36. package/dist/protocols/zai-chat.d.ts +4 -0
  37. package/dist/providers/alibaba/embeddings.d.ts +2 -0
  38. package/dist/providers/alibaba/embeddings.js +1 -0
  39. package/dist/providers/alibaba.d.ts +3 -0
  40. package/dist/providers/alibaba.js +14 -1
  41. package/dist/providers/amazon-bedrock-mantle.d.ts +1 -0
  42. package/dist/providers/azure/embeddings.d.ts +2 -0
  43. package/dist/providers/azure/embeddings.js +1 -0
  44. package/dist/providers/azure.d.ts +3 -0
  45. package/dist/providers/azure.js +15 -0
  46. package/dist/providers/baseten.d.ts +2 -0
  47. package/dist/providers/cerebras.d.ts +2 -0
  48. package/dist/providers/cloudflare-ai-gateway.d.ts +2 -0
  49. package/dist/providers/cloudflare-workers-ai.d.ts +2 -0
  50. package/dist/providers/cohere/embeddings.d.ts +2 -0
  51. package/dist/providers/cohere/embeddings.js +1 -0
  52. package/dist/providers/cohere.d.ts +8 -0
  53. package/dist/providers/cohere.js +17 -1
  54. package/dist/providers/deepinfra/embeddings.d.ts +2 -0
  55. package/dist/providers/deepinfra/embeddings.js +1 -0
  56. package/dist/providers/deepinfra.d.ts +6 -1
  57. package/dist/providers/deepinfra.js +15 -1
  58. package/dist/providers/deepseek.d.ts +2 -0
  59. package/dist/providers/digitalocean/embeddings.d.ts +2 -0
  60. package/dist/providers/digitalocean/embeddings.js +1 -0
  61. package/dist/providers/digitalocean.d.ts +10 -0
  62. package/dist/providers/digitalocean.js +15 -0
  63. package/dist/providers/fireworks/embeddings.d.ts +2 -0
  64. package/dist/providers/fireworks/embeddings.js +1 -0
  65. package/dist/providers/fireworks.d.ts +6 -1
  66. package/dist/providers/fireworks.js +15 -1
  67. package/dist/providers/google/embeddings.d.ts +2 -0
  68. package/dist/providers/google/embeddings.js +1 -0
  69. package/dist/providers/google-vertex/embeddings.d.ts +2 -0
  70. package/dist/providers/google-vertex/embeddings.js +1 -0
  71. package/dist/providers/google-vertex-chat.d.ts +1 -0
  72. package/dist/providers/google-vertex.d.ts +7 -0
  73. package/dist/providers/google-vertex.js +52 -0
  74. package/dist/providers/google.d.ts +6 -0
  75. package/dist/providers/google.js +14 -0
  76. package/dist/providers/groq.d.ts +5 -0
  77. package/dist/providers/meta.d.ts +1 -0
  78. package/dist/providers/minimax.d.ts +1 -0
  79. package/dist/providers/moonshot.d.ts +1 -0
  80. package/dist/providers/openai/embeddings.d.ts +2 -0
  81. package/dist/providers/openai/embeddings.js +1 -0
  82. package/dist/providers/openai-compatible/embeddings.d.ts +2 -0
  83. package/dist/providers/openai-compatible/embeddings.js +1 -0
  84. package/dist/providers/openai-compatible.d.ts +4 -0
  85. package/dist/providers/openai-compatible.js +13 -0
  86. package/dist/providers/openai.d.ts +7 -0
  87. package/dist/providers/openai.js +14 -0
  88. package/dist/providers/openrouter/embeddings.d.ts +2 -0
  89. package/dist/providers/openrouter/embeddings.js +1 -0
  90. package/dist/providers/openrouter.d.ts +16 -0
  91. package/dist/providers/openrouter.js +15 -0
  92. package/dist/providers/togetherai.d.ts +2 -0
  93. package/dist/providers/venice.d.ts +1 -0
  94. package/dist/providers/vercel-ai-gateway/embeddings.d.ts +2 -0
  95. package/dist/providers/vercel-ai-gateway/embeddings.js +1 -0
  96. package/dist/providers/vercel-ai-gateway.d.ts +4 -0
  97. package/dist/providers/vercel-ai-gateway.js +15 -1
  98. package/dist/providers/xai.d.ts +1 -0
  99. package/dist/providers/zai-coding-plan.d.ts +1 -0
  100. package/dist/providers/zai.d.ts +1 -0
  101. package/dist/public.d.ts +2 -0
  102. package/dist/public.js +1 -0
  103. package/dist/route/embedding.d.ts +61 -0
  104. package/dist/route/embedding.js +88 -0
  105. package/package.json +305 -253
@@ -0,0 +1,34 @@
1
+ import { EmbeddingRoute } from "../route/embedding.js";
2
+ import { type OpenString } from "../schema/index.js";
3
+ export declare const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
4
+ /** `batchEmbedContents` takes at most 100 requests. */
5
+ export declare const MAX_BATCH = 100;
6
+ export type TaskType = OpenString<"RETRIEVAL_QUERY" | "RETRIEVAL_DOCUMENT" | "SEMANTIC_SIMILARITY" | "CLASSIFICATION" | "CLUSTERING" | "QUESTION_ANSWERING" | "FACT_VERIFICATION" | "CODE_RETRIEVAL_QUERY">;
7
+ /**
8
+ * Per-value embedding fields, sent with each value. `taskType` replaces the one `inputType` maps to; Gemini Embedding 2
9
+ * ignores task types and documents task prefixes in the text instead (`task: search result | query: …`).
10
+ */
11
+ export interface OptionsInput {
12
+ readonly [key: string]: unknown;
13
+ readonly taskType?: TaskType;
14
+ readonly title?: string;
15
+ }
16
+ /** Vertex `embedContentConfig` fields; Vertex alone takes `autoTruncate`, `documentOcr` and `audioTrackExtraction`. */
17
+ export interface VertexOptionsInput extends OptionsInput {
18
+ readonly autoTruncate?: boolean;
19
+ readonly documentOcr?: boolean;
20
+ readonly audioTrackExtraction?: boolean;
21
+ }
22
+ /** Gemini API `batchEmbedContents`: one request per value, so every value gets its own vector. */
23
+ export declare const protocol: EmbeddingRoute.Protocol;
24
+ /**
25
+ * Vertex `embedContent`: one content per request, with options under `embedContentConfig`. Routes using it set
26
+ * `maxValues: 1`.
27
+ */
28
+ export declare const vertexProtocol: EmbeddingRoute.Protocol;
29
+ export declare const route: EmbeddingRoute.Route;
30
+ export declare const GoogleEmbedContent: {
31
+ readonly protocol: EmbeddingRoute.Protocol;
32
+ readonly vertexProtocol: EmbeddingRoute.Protocol;
33
+ readonly route: EmbeddingRoute.Route;
34
+ };
@@ -0,0 +1,110 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { EmbeddingResponse, EmbeddingUsage } from "../embedding.js";
3
+ import { EmbeddingRoute } from "../route/embedding.js";
4
+ import { Endpoint } from "../route/endpoint.js";
5
+ import { MediaProtocol } from "../route/media-protocol.js";
6
+ import { mergeJsonRecords } from "../schema/index.js";
7
+ import { GeminiGenerateContent } from "./utils/gemini-generate-content.js";
8
+ const ID = "google-embed-content";
9
+ const NAME = "Google embedContent";
10
+ export const DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
11
+ /** `batchEmbedContents` takes at most 100 requests. */
12
+ export const MAX_BATCH = 100;
13
+ const Values = Schema.Struct({ values: Schema.Array(Schema.Number) });
14
+ const UsageMetadata = Schema.StructWithRest(Schema.Struct({ promptTokenCount: Schema.optional(Schema.Number) }), [
15
+ Schema.Record(Schema.String, Schema.Unknown),
16
+ ]);
17
+ const BatchResponse = Schema.Struct({
18
+ embeddings: Schema.Array(Values),
19
+ usageMetadata: Schema.optional(UsageMetadata),
20
+ });
21
+ const SingleResponse = Schema.Struct({
22
+ embedding: Values,
23
+ usageMetadata: Schema.optional(UsageMetadata),
24
+ truncated: Schema.optional(Schema.Boolean),
25
+ });
26
+ const TASK_TYPES = { query: "RETRIEVAL_QUERY", document: "RETRIEVAL_DOCUMENT" };
27
+ // Each value is its own content: several parts in one content embed into one aggregated vector.
28
+ const content = (value) => typeof value === "string"
29
+ ? Effect.succeed({ parts: [{ text: value }] })
30
+ : GeminiGenerateContent.mediaPart(NAME, value).pipe(Effect.map((part) => ({ parts: [part] })));
31
+ const config = (request) => ({
32
+ ...(request.inputType === undefined ? {} : { taskType: TASK_TYPES[request.inputType] }),
33
+ ...(request.dimensions === undefined ? {} : { outputDimensionality: request.dimensions }),
34
+ ...request.providerOptions,
35
+ });
36
+ const identity = MediaProtocol.identity({ id: ID, name: NAME, provider: "google" });
37
+ const decodeBatch = identity.decodeJson(BatchResponse);
38
+ const decodeSingle = identity.decodeJson(SingleResponse);
39
+ const usage = (metadata) => metadata?.promptTokenCount === undefined ? undefined : new EmbeddingUsage({ inputTokens: metadata.promptTokenCount });
40
+ /** Gemini API `batchEmbedContents`: one request per value, so every value gets its own vector. */
41
+ export const protocol = EmbeddingRoute.protocol({
42
+ id: ID,
43
+ name: NAME,
44
+ body: {
45
+ from: Effect.fn("GoogleEmbedContent.fromRequest")(function* (request) {
46
+ const contents = yield* Effect.forEach(request.values, content);
47
+ const fields = config(request);
48
+ return (mergeJsonRecords({ requests: contents.map((item) => ({ model: `models/${request.model.id}`, content: item, ...fields })) }, request.http?.body) ?? {});
49
+ }),
50
+ },
51
+ response: {
52
+ decode: Effect.fn("GoogleEmbedContent.decodeResponse")(function* (response, context) {
53
+ const output = yield* decodeBatch(response);
54
+ return new EmbeddingResponse({
55
+ embeddings: output.value.embeddings.map((item) => item.values),
56
+ usage: usage(output.value.usageMetadata),
57
+ providerMetadata: {
58
+ [context.providerMetadataKey]: output.value.usageMetadata === undefined ? {} : { usageMetadata: output.value.usageMetadata },
59
+ },
60
+ });
61
+ }),
62
+ },
63
+ });
64
+ /**
65
+ * Vertex `embedContent`: one content per request, with options under `embedContentConfig`. Routes using it set
66
+ * `maxValues: 1`.
67
+ */
68
+ export const vertexProtocol = EmbeddingRoute.protocol({
69
+ id: "google-vertex-embed-content",
70
+ name: "Google Vertex embedContent",
71
+ body: {
72
+ from: Effect.fn("GoogleEmbedContent.vertexFromRequest")(function* (request) {
73
+ const contents = yield* Effect.forEach(request.values, content);
74
+ const fields = config(request);
75
+ return (mergeJsonRecords({
76
+ content: contents[0],
77
+ ...(Object.keys(fields).length === 0 ? {} : { embedContentConfig: fields }),
78
+ }, request.http?.body) ?? {});
79
+ }),
80
+ },
81
+ response: {
82
+ decode: Effect.fn("GoogleEmbedContent.vertexDecodeResponse")(function* (response, context) {
83
+ const output = yield* decodeSingle(response);
84
+ return new EmbeddingResponse({
85
+ embeddings: [output.value.embedding.values],
86
+ usage: usage(output.value.usageMetadata),
87
+ providerMetadata: {
88
+ [context.providerMetadataKey]: {
89
+ ...(output.value.usageMetadata === undefined ? {} : { usageMetadata: output.value.usageMetadata }),
90
+ ...(output.value.truncated === undefined ? {} : { truncated: output.value.truncated }),
91
+ },
92
+ },
93
+ });
94
+ }),
95
+ },
96
+ });
97
+ export const route = EmbeddingRoute.make({
98
+ id: ID,
99
+ provider: "google",
100
+ protocol,
101
+ endpoint: Endpoint.path(({ request }) => `/models/${request.model.id}:batchEmbedContents`, {
102
+ baseURL: DEFAULT_BASE_URL,
103
+ }),
104
+ maxValues: MAX_BATCH,
105
+ });
106
+ export const GoogleEmbedContent = {
107
+ protocol,
108
+ vertexProtocol,
109
+ route,
110
+ };
@@ -0,0 +1,18 @@
1
+ import { EmbeddingRoute } from "../route/embedding.js";
2
+ import type { TaskType } from "./google-embed-content.js";
3
+ /** `text-embedding-005` and `text-multilingual-embedding-002` take up to 250 instances per request. */
4
+ export declare const MAX_INSTANCES = 250;
5
+ /**
6
+ * The same option names as `embedContent`, so a model can move between the two APIs: `taskType` and `title` go on
7
+ * each instance (`task_type`, `title`), and `autoTruncate` and anything else go under `parameters`.
8
+ */
9
+ export interface OptionsInput {
10
+ readonly [key: string]: unknown;
11
+ readonly taskType?: TaskType;
12
+ readonly title?: string;
13
+ readonly autoTruncate?: boolean;
14
+ }
15
+ export declare const protocol: EmbeddingRoute.Protocol;
16
+ export declare const GoogleVertexPredictEmbeddings: {
17
+ readonly protocol: EmbeddingRoute.Protocol;
18
+ };
@@ -0,0 +1,74 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { EmbeddingResponse, EmbeddingUsage } from "../embedding.js";
3
+ import { EmbeddingRoute } from "../route/embedding.js";
4
+ import { MediaProtocol } from "../route/media-protocol.js";
5
+ import { AIError, UnsupportedOperationError, mergeJsonRecords } from "../schema/index.js";
6
+ const ID = "google-vertex-predict-embeddings";
7
+ const NAME = "Google Vertex text embeddings";
8
+ /** `text-embedding-005` and `text-multilingual-embedding-002` take up to 250 instances per request. */
9
+ export const MAX_INSTANCES = 250;
10
+ const Statistics = Schema.StructWithRest(Schema.Struct({ token_count: Schema.optional(Schema.Number), truncated: Schema.optional(Schema.Boolean) }), [Schema.Record(Schema.String, Schema.Unknown)]);
11
+ const Response = Schema.Struct({
12
+ predictions: Schema.Array(Schema.Struct({
13
+ embeddings: Schema.Struct({ values: Schema.Array(Schema.Number), statistics: Schema.optional(Statistics) }),
14
+ })),
15
+ metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
16
+ });
17
+ const TASK_TYPES = { query: "RETRIEVAL_QUERY", document: "RETRIEVAL_DOCUMENT" };
18
+ const fromRequest = Effect.fn("GoogleVertexPredictEmbeddings.fromRequest")(function* (request) {
19
+ const contents = request.values.filter((value) => typeof value === "string");
20
+ if (contents.length !== request.values.length)
21
+ return yield* new AIError({
22
+ reason: new UnsupportedOperationError({
23
+ operation: "embedding.media",
24
+ provider: request.model.provider,
25
+ route: request.model.route.id,
26
+ message: `${request.model.id} on Vertex :predict embeds text only; use gemini-embedding-2 for media values`,
27
+ }),
28
+ });
29
+ const { taskType, title, ...parameters } = request.providerOptions ?? {};
30
+ const instance = {
31
+ ...(taskType === undefined
32
+ ? request.inputType === undefined
33
+ ? {}
34
+ : { task_type: TASK_TYPES[request.inputType] }
35
+ : { task_type: taskType }),
36
+ ...(title === undefined ? {} : { title }),
37
+ };
38
+ const merged = {
39
+ ...(request.dimensions === undefined ? {} : { outputDimensionality: request.dimensions }),
40
+ ...parameters,
41
+ };
42
+ return (mergeJsonRecords({
43
+ instances: contents.map((content) => ({ content, ...instance })),
44
+ ...(Object.keys(merged).length === 0 ? {} : { parameters: merged }),
45
+ }, request.http?.body) ?? {});
46
+ });
47
+ const decodeDocument = MediaProtocol.identity({ id: ID, name: NAME, provider: "google-vertex" }).decodeJson(Response);
48
+ export const protocol = EmbeddingRoute.protocol({
49
+ id: ID,
50
+ name: NAME,
51
+ body: { from: fromRequest },
52
+ response: {
53
+ decode: Effect.fn("GoogleVertexPredictEmbeddings.decodeResponse")(function* (response, context) {
54
+ const output = yield* decodeDocument(response);
55
+ const statistics = output.value.predictions.map((prediction) => prediction.embeddings.statistics ?? {});
56
+ const tokens = statistics.map((item) => item.token_count);
57
+ return new EmbeddingResponse({
58
+ embeddings: output.value.predictions.map((prediction) => prediction.embeddings.values),
59
+ usage: tokens.every((count) => count !== undefined)
60
+ ? new EmbeddingUsage({ inputTokens: tokens.reduce((sum, count) => sum + count, 0) })
61
+ : undefined,
62
+ providerMetadata: {
63
+ [context.providerMetadataKey]: {
64
+ statistics,
65
+ ...(output.value.metadata === undefined ? {} : { metadata: output.value.metadata }),
66
+ },
67
+ },
68
+ });
69
+ }),
70
+ },
71
+ });
72
+ export const GoogleVertexPredictEmbeddings = {
73
+ protocol,
74
+ };
@@ -3,10 +3,13 @@ export * as BedrockConverse from "./bedrock-converse.js";
3
3
  export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
4
4
  export * as CohereChat from "./cohere-chat.js";
5
5
  export * as Gemini from "./gemini.js";
6
+ export * as GoogleEmbedContent from "./google-embed-content.js";
6
7
  export * as GoogleInteractions from "./google-interactions.js";
8
+ export * as GoogleVertexPredictEmbeddings from "./google-vertex-predict-embeddings.js";
7
9
  export * as MistralChat from "./mistral-chat.js";
8
10
  export * as OpenAIChat from "./openai-chat.js";
9
11
  export * as OpenAIDecisions from "./openai-decisions.js";
12
+ export * as OpenAIEmbeddings from "./openai-embeddings.js";
10
13
  export * as OpenAIImages from "./openai-images.js";
11
14
  export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
12
15
  export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
@@ -3,10 +3,13 @@ export * as BedrockConverse from "./bedrock-converse.js";
3
3
  export * as CloudflareRunDecisions from "./cloudflare-run-decisions.js";
4
4
  export * as CohereChat from "./cohere-chat.js";
5
5
  export * as Gemini from "./gemini.js";
6
+ export * as GoogleEmbedContent from "./google-embed-content.js";
6
7
  export * as GoogleInteractions from "./google-interactions.js";
8
+ export * as GoogleVertexPredictEmbeddings from "./google-vertex-predict-embeddings.js";
7
9
  export * as MistralChat from "./mistral-chat.js";
8
10
  export * as OpenAIChat from "./openai-chat.js";
9
11
  export * as OpenAIDecisions from "./openai-decisions.js";
12
+ export * as OpenAIEmbeddings from "./openai-embeddings.js";
10
13
  export * as OpenAIImages from "./openai-images.js";
11
14
  export * as OpenAICompatibleChat from "./openai-compatible-chat.js";
12
15
  export * as OpenAICompatibleResponses from "./openai-compatible-responses.js";
@@ -1566,7 +1566,7 @@ export declare const fromRequest: (request: LLMRequest) => Effect.Effect<{
1566
1566
  }[];
1567
1567
  } | undefined;
1568
1568
  }, AIError, never>;
1569
- export declare const mapUsage: (usage: OpenResponsesUsage | null | undefined, providerMetadataKey: string) => Usage | undefined;
1569
+ export declare const mapUsage: (usage: OpenResponsesUsage | null | undefined, providerMetadataKey: string, ...frames: ReadonlyArray<unknown>) => Usage | undefined;
1570
1570
  export declare const metadataKey: (model: LLMRequest["model"]) => string;
1571
1571
  export declare const providerMetadata: (state: ParserState, metadata: Record<string, unknown>) => ProviderMetadata;
1572
1572
  export type StepResult = readonly [ParserState, ReadonlyArray<LLMEvent>];
@@ -671,7 +671,7 @@ export const fromRequest = (request) => fromRequestWithAdapter(request, BASE_ADA
671
671
  // cached-read and cache-write subsets, and `output_tokens` (inclusive total)
672
672
  // with a `reasoning_tokens` subset. Pass the totals through and derive the
673
673
  // non-cached breakdown.
674
- export const mapUsage = (usage, providerMetadataKey) => {
674
+ export const mapUsage = (usage, providerMetadataKey, ...frames) => {
675
675
  if (!usage)
676
676
  return undefined;
677
677
  const cached = usage.input_tokens_details?.cached_tokens;
@@ -686,10 +686,29 @@ export const mapUsage = (usage, providerMetadataKey) => {
686
686
  cacheWriteInputTokens: cacheWrite,
687
687
  reasoningTokens: reasoning,
688
688
  totalTokens: ProviderShared.totalTokens(usage.input_tokens, usage.output_tokens, usage.total_tokens),
689
- ...ProviderShared.reportedBilling(usage),
689
+ ...ProviderShared.reportedBilling(usage, ...frames),
690
690
  providerMetadata: { [providerMetadataKey]: usage },
691
691
  });
692
692
  };
693
+ // GitHub Copilot lists the filters that ran; the blocking one names its rule in `content_filter_raw`.
694
+ const decodeContentFilters = Schema.decodeUnknownOption(Schema.Array(Schema.Struct({
695
+ source_type: Schema.optional(Schema.String),
696
+ blocked: Schema.optional(Schema.Boolean),
697
+ content_filter_raw: Schema.optional(Schema.Array(Schema.Struct({
698
+ action: Schema.optional(Schema.String),
699
+ label: Schema.optional(Schema.String),
700
+ result: Schema.optional(Schema.Unknown),
701
+ }))),
702
+ content_filter_results: Schema.optional(Schema.Unknown),
703
+ })));
704
+ const contentFilterCategory = (raw) => {
705
+ const blocked = Option.getOrElse(decodeContentFilters(raw), () => []).filter((filter) => filter.blocked);
706
+ const filter = blocked.find((item) => item.source_type === "completion") ?? blocked[0];
707
+ if (!filter)
708
+ return undefined;
709
+ return (filter.content_filter_raw?.find((rule) => rule.action === "BLOCK" && rule.result === true)?.label ??
710
+ ProviderShared.contentFilterCategory(filter.content_filter_results));
711
+ };
693
712
  const mapFinishReason = (event, hasFunctionCall) => {
694
713
  const reason = event.response?.incomplete_details?.reason;
695
714
  if (reason === undefined) {
@@ -749,12 +768,13 @@ const ITEM_ID_PREFIX = {
749
768
  custom_tool_call: "ctc",
750
769
  compaction: "cmp",
751
770
  };
752
- // An item without an id adopts the id already open in its output slot,
753
- // otherwise it gets a locally minted one.
771
+ // An item adopts the id already open in its output slot, since GitHub Copilot
772
+ // sends a different id on every event, including the item's own done event.
773
+ // Otherwise it keeps its id or gets a locally minted one.
754
774
  const resolveItem = (state, item, index) => ({
755
775
  ...item,
756
- id: item.id ??
757
- (index === undefined ? undefined : state.outputItems[index]) ??
776
+ id: (index === undefined ? undefined : state.outputItems[index]) ??
777
+ item.id ??
758
778
  `${ITEM_ID_PREFIX[item.type] ?? "item"}_${crypto.randomUUID().replaceAll("-", "")}`,
759
779
  });
760
780
  // Registered output slots are authoritative for `item_id` routing, and items
@@ -1128,12 +1148,15 @@ const onResponseFinish = Effect.fnUntraced(function* (state, event) {
1128
1148
  };
1129
1149
  events.push(...pending.events);
1130
1150
  }
1151
+ const normalized = mapFinishReason(event, current.hasFunctionCall);
1131
1152
  const lifecycle = Lifecycle.finish(current.lifecycle, events, {
1132
1153
  reason: {
1133
- normalized: mapFinishReason(event, current.hasFunctionCall),
1154
+ normalized,
1134
1155
  raw: event.response?.incomplete_details?.reason,
1156
+ ...(normalized === "content-filter" ? { category: contentFilterCategory(event.response?.content_filters) } : {}),
1135
1157
  },
1136
- usage: mapUsage(event.response?.usage, current.providerMetadataKey),
1158
+ // Copilot reports its billing on the terminal event, beside `response`.
1159
+ usage: mapUsage(event.response?.usage, current.providerMetadataKey, event, event.response),
1137
1160
  providerMetadata: event.response?.id || event.response?.service_tier
1138
1161
  ? providerMetadata(current, {
1139
1162
  responseId: event.response.id,
@@ -158,6 +158,7 @@ export declare const OpenAIChatMessage: Schema.toTaggedUnion<"role", readonly [S
158
158
  readonly reasoning: Schema.optional<Schema.String>;
159
159
  readonly reasoning_text: Schema.optional<Schema.String>;
160
160
  readonly reasoning_details: Schema.optional<Schema.Unknown>;
161
+ readonly reasoning_opaque: Schema.optional<Schema.String>;
161
162
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
162
163
  readonly role: Schema.Literal<"tool">;
163
164
  readonly tool_call_id: Schema.String;
@@ -259,6 +260,7 @@ export declare const bodyFields: {
259
260
  readonly reasoning: Schema.optional<Schema.String>;
260
261
  readonly reasoning_text: Schema.optional<Schema.String>;
261
262
  readonly reasoning_details: Schema.optional<Schema.Unknown>;
263
+ readonly reasoning_opaque: Schema.optional<Schema.String>;
262
264
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
263
265
  readonly role: Schema.Literal<"tool">;
264
266
  readonly tool_call_id: Schema.String;
@@ -428,6 +430,7 @@ declare const OpenAIChatBody: Schema.Struct<{
428
430
  readonly reasoning: Schema.optional<Schema.String>;
429
431
  readonly reasoning_text: Schema.optional<Schema.String>;
430
432
  readonly reasoning_details: Schema.optional<Schema.Unknown>;
433
+ readonly reasoning_opaque: Schema.optional<Schema.String>;
431
434
  }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>, Schema.Struct<{
432
435
  readonly role: Schema.Literal<"tool">;
433
436
  readonly tool_call_id: Schema.String;
@@ -518,6 +521,7 @@ export declare const OpenAIChatUsage: Schema.StructWithRest<Schema.Struct<{
518
521
  readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
519
522
  readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
520
523
  readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
524
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
521
525
  readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
522
526
  readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
523
527
  readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
@@ -548,6 +552,7 @@ export declare const OpenAIChatDelta: Schema.StructWithRest<Schema.Struct<{
548
552
  readonly reasoning: Schema.optional<Schema.NullOr<Schema.String>>;
549
553
  readonly reasoning_text: Schema.optional<Schema.NullOr<Schema.String>>;
550
554
  readonly reasoning_details: Schema.optional<Schema.NullOr<Schema.Unknown>>;
555
+ readonly reasoning_opaque: Schema.optional<Schema.NullOr<Schema.String>>;
551
556
  readonly tool_calls: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
552
557
  readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
553
558
  readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
@@ -570,6 +575,7 @@ export declare const OpenAIChatChoice: Schema.StructWithRest<Schema.Struct<{
570
575
  readonly reasoning: Schema.optional<Schema.NullOr<Schema.String>>;
571
576
  readonly reasoning_text: Schema.optional<Schema.NullOr<Schema.String>>;
572
577
  readonly reasoning_details: Schema.optional<Schema.NullOr<Schema.Unknown>>;
578
+ readonly reasoning_opaque: Schema.optional<Schema.NullOr<Schema.String>>;
573
579
  readonly tool_calls: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
574
580
  readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
575
581
  readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
@@ -594,6 +600,7 @@ export declare const OpenAIChatChoice: Schema.StructWithRest<Schema.Struct<{
594
600
  readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
595
601
  readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
596
602
  readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
603
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
597
604
  readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
598
605
  readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
599
606
  readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
@@ -614,6 +621,7 @@ export declare const OpenAIChatEvent: Schema.StructWithRest<Schema.Struct<{
614
621
  readonly reasoning: Schema.optional<Schema.NullOr<Schema.String>>;
615
622
  readonly reasoning_text: Schema.optional<Schema.NullOr<Schema.String>>;
616
623
  readonly reasoning_details: Schema.optional<Schema.NullOr<Schema.Unknown>>;
624
+ readonly reasoning_opaque: Schema.optional<Schema.NullOr<Schema.String>>;
617
625
  readonly tool_calls: Schema.optional<Schema.NullOr<Schema.$Array<Schema.Struct<{
618
626
  readonly index: Schema.optional<Schema.NullOr<Schema.Number>>;
619
627
  readonly id: Schema.optional<Schema.NullOr<Schema.String>>;
@@ -638,6 +646,7 @@ export declare const OpenAIChatEvent: Schema.StructWithRest<Schema.Struct<{
638
646
  readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
639
647
  readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
640
648
  readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
649
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
641
650
  readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
642
651
  readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
643
652
  readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
@@ -657,6 +666,7 @@ export declare const OpenAIChatEvent: Schema.StructWithRest<Schema.Struct<{
657
666
  readonly prompt_cache_hit_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
658
667
  readonly cache_read_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
659
668
  readonly cache_created_input_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
669
+ readonly reasoning_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
660
670
  readonly prompt_tokens_details: Schema.optional<Schema.NullOr<Schema.StructWithRest<Schema.Struct<{
661
671
  readonly cached_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
662
672
  readonly cache_write_tokens: Schema.optional<Schema.NullOr<Schema.Number>>;
@@ -695,6 +705,8 @@ export interface ParserState {
695
705
  readonly reasoningTextObserved: boolean;
696
706
  readonly reasoningDetails: Array<ReasoningDetail>;
697
707
  readonly reasoningDetailsObserved: boolean;
708
+ /** Latest `reasoning_opaque`; interleaved reasoning sends a new one before each tool call. */
709
+ readonly reasoningOpaque?: string;
698
710
  readonly reasoningEmitted: boolean;
699
711
  readonly latestToolIndex?: number;
700
712
  readonly nextToolIndex: number;
@@ -820,6 +832,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
820
832
  readonly reasoning?: string | undefined;
821
833
  readonly reasoning_text?: string | undefined;
822
834
  readonly reasoning_details?: unknown;
835
+ readonly reasoning_opaque?: string | undefined;
823
836
  })[];
824
837
  tools: ({
825
838
  readonly type: "function";
@@ -992,6 +1005,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
992
1005
  readonly reasoning?: string | undefined;
993
1006
  readonly reasoning_text?: string | undefined;
994
1007
  readonly reasoning_details?: unknown;
1008
+ readonly reasoning_opaque?: string | undefined;
995
1009
  })[];
996
1010
  tools: ({
997
1011
  readonly type: "function";
@@ -1166,6 +1180,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
1166
1180
  readonly reasoning?: string | undefined;
1167
1181
  readonly reasoning_text?: string | undefined;
1168
1182
  readonly reasoning_details?: unknown;
1183
+ readonly reasoning_opaque?: string | undefined;
1169
1184
  })[];
1170
1185
  tools: ({
1171
1186
  readonly type: "function";
@@ -1338,6 +1353,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
1338
1353
  readonly reasoning?: string | undefined;
1339
1354
  readonly reasoning_text?: string | undefined;
1340
1355
  readonly reasoning_details?: unknown;
1356
+ readonly reasoning_opaque?: string | undefined;
1341
1357
  })[];
1342
1358
  tools: ({
1343
1359
  readonly type: "function";
@@ -1510,6 +1526,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
1510
1526
  readonly reasoning?: string | undefined;
1511
1527
  readonly reasoning_text?: string | undefined;
1512
1528
  readonly reasoning_details?: unknown;
1529
+ readonly reasoning_opaque?: string | undefined;
1513
1530
  })[];
1514
1531
  tools: ({
1515
1532
  readonly type: "function";
@@ -1684,6 +1701,7 @@ export declare const fromRequest: (request: LLMRequest<import("../schema/options
1684
1701
  readonly reasoning?: string | undefined;
1685
1702
  readonly reasoning_text?: string | undefined;
1686
1703
  readonly reasoning_details?: unknown;
1704
+ readonly reasoning_opaque?: string | undefined;
1687
1705
  })[];
1688
1706
  tools: ({
1689
1707
  readonly type: "function";
@@ -2050,6 +2068,7 @@ export declare const protocol: Protocol<{
2050
2068
  readonly reasoning?: string | undefined;
2051
2069
  readonly reasoning_text?: string | undefined;
2052
2070
  readonly reasoning_details?: unknown;
2071
+ readonly reasoning_opaque?: string | undefined;
2053
2072
  })[];
2054
2073
  readonly tools?: readonly ({
2055
2074
  readonly type: "function";
@@ -2135,6 +2154,7 @@ export declare const protocol: Protocol<{
2135
2154
  readonly reasoning?: string | null | undefined;
2136
2155
  readonly reasoning_text?: string | null | undefined;
2137
2156
  readonly reasoning_details?: unknown;
2157
+ readonly reasoning_opaque?: string | null | undefined;
2138
2158
  readonly tool_calls?: readonly {
2139
2159
  readonly index?: number | null | undefined;
2140
2160
  readonly id?: string | null | undefined;
@@ -2160,6 +2180,7 @@ export declare const protocol: Protocol<{
2160
2180
  readonly prompt_cache_hit_tokens?: number | null | undefined;
2161
2181
  readonly cache_read_input_tokens?: number | null | undefined;
2162
2182
  readonly cache_created_input_tokens?: number | null | undefined;
2183
+ readonly reasoning_tokens?: number | null | undefined;
2163
2184
  readonly prompt_tokens_details?: {
2164
2185
  readonly [x: string]: unknown;
2165
2186
  readonly cached_tokens?: number | null | undefined;
@@ -2182,6 +2203,7 @@ export declare const protocol: Protocol<{
2182
2203
  readonly prompt_cache_hit_tokens?: number | null | undefined;
2183
2204
  readonly cache_read_input_tokens?: number | null | undefined;
2184
2205
  readonly cache_created_input_tokens?: number | null | undefined;
2206
+ readonly reasoning_tokens?: number | null | undefined;
2185
2207
  readonly prompt_tokens_details?: {
2186
2208
  readonly [x: string]: unknown;
2187
2209
  readonly cached_tokens?: number | null | undefined;
@@ -2301,6 +2323,7 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
2301
2323
  readonly reasoning?: string | undefined;
2302
2324
  readonly reasoning_text?: string | undefined;
2303
2325
  readonly reasoning_details?: unknown;
2326
+ readonly reasoning_opaque?: string | undefined;
2304
2327
  })[];
2305
2328
  readonly tools?: readonly ({
2306
2329
  readonly type: "function";
@@ -2475,6 +2498,7 @@ export declare const route: Route<{
2475
2498
  readonly reasoning?: string | undefined;
2476
2499
  readonly reasoning_text?: string | undefined;
2477
2500
  readonly reasoning_details?: unknown;
2501
+ readonly reasoning_opaque?: string | undefined;
2478
2502
  })[];
2479
2503
  readonly tools?: readonly ({
2480
2504
  readonly type: "function";