@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
@@ -148,6 +148,7 @@ export const OpenAIChatMessage = Schema.Union([
148
148
  reasoning: Schema.optional(Schema.String),
149
149
  reasoning_text: Schema.optional(Schema.String),
150
150
  reasoning_details: Schema.optional(Schema.Unknown),
151
+ reasoning_opaque: Schema.optional(Schema.String),
151
152
  }), [Schema.Record(Schema.String, Schema.Unknown)]),
152
153
  Schema.Struct({
153
154
  role: Schema.Literal("tool"),
@@ -209,6 +210,8 @@ export const OpenAIChatUsage = Schema.StructWithRest(Schema.Struct({
209
210
  prompt_cache_hit_tokens: optionalNull(Schema.Number),
210
211
  cache_read_input_tokens: optionalNull(Schema.Number),
211
212
  cache_created_input_tokens: optionalNull(Schema.Number),
213
+ // GitHub Copilot reports reasoning at the top level instead of in `completion_tokens_details`.
214
+ reasoning_tokens: optionalNull(Schema.Number),
212
215
  prompt_tokens_details: optionalNull(Schema.StructWithRest(Schema.Struct({
213
216
  cached_tokens: optionalNull(Schema.Number),
214
217
  cache_write_tokens: optionalNull(Schema.Number),
@@ -237,6 +240,8 @@ export const OpenAIChatDelta = Schema.StructWithRest(Schema.Struct({
237
240
  reasoning: optionalNull(Schema.String),
238
241
  reasoning_text: optionalNull(Schema.String),
239
242
  reasoning_details: optionalNull(Schema.Unknown),
243
+ // GitHub Copilot's opaque reasoning state, which must be replayed for multi-turn reasoning.
244
+ reasoning_opaque: optionalNull(Schema.String),
240
245
  tool_calls: optionalNull(Schema.Array(OpenAIChatToolCallDelta)),
241
246
  }), [Schema.Record(Schema.String, Schema.Unknown)]);
242
247
  export const OpenAIChatChoice = Schema.StructWithRest(Schema.Struct({
@@ -346,6 +351,11 @@ const lowerReasoningDetail = (detail) => {
346
351
  return { type: detail.type, encrypted: detail.encrypted };
347
352
  return detail;
348
353
  };
354
+ // Interleaved reasoning yields one opaque value per segment; like the Copilot VS Code
355
+ // client, replay the latest one with the concatenated reasoning text.
356
+ const reasoningOpaque = (parts, providerMetadataKey) => parts
357
+ .map((part) => part.providerMetadata?.[providerMetadataKey]?.reasoningOpaque)
358
+ .findLast((value) => typeof value === "string");
349
359
  const isKimiDetail = (detail) => detail.type === "summary" || detail.type === "encrypted";
350
360
  const lowerUserMessage = Effect.fnUntraced(function* (message, options) {
351
361
  const content = [];
@@ -406,7 +416,8 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
406
416
  if (details?.some(isKimiDetail))
407
417
  return "reasoning_content";
408
418
  })();
409
- const reasoningText = reasoning.length === 0 ? (requireReasoning ? "" : undefined) : text;
419
+ const opaque = reasoningOpaque(reasoning, options.providerMetadataKey);
420
+ const reasoningText = reasoning.length === 0 || (opaque !== undefined && text === "") ? (requireReasoning ? "" : undefined) : text;
410
421
  const result = {
411
422
  role: "assistant",
412
423
  content: (() => {
@@ -418,6 +429,7 @@ const lowerAssistantMessage = Effect.fnUntraced(function* (message, configuredFi
418
429
  })(),
419
430
  ...(toolCalls.length > 0 ? { tool_calls: toolCalls } : {}),
420
431
  ...(details !== undefined ? { reasoning_details: details } : {}),
432
+ ...(opaque !== undefined ? { reasoning_opaque: opaque } : {}),
421
433
  };
422
434
  if (field === undefined || reasoningText === undefined)
423
435
  return result;
@@ -749,18 +761,24 @@ const mapFinishReason = Effect.fnUntraced(function* (event, reason) {
749
761
  // `prompt_tokens_details.cached_tokens`, DeepSeek uses
750
762
  // `prompt_cache_hit_tokens`, Zai uses top-level `cached_tokens`, and
751
763
  // DigitalOcean uses top-level `cache_read_input_tokens` / `cache_created_input_tokens`.
752
- const mapUsage = (usage, providerMetadataKey) => {
764
+ const mapUsage = (usage, providerMetadataKey, frame) => {
753
765
  if (!usage)
754
766
  return undefined;
755
767
  const input = usage.prompt_tokens ?? undefined;
756
- const output = usage.completion_tokens ?? undefined;
768
+ const completion = usage.completion_tokens ?? undefined;
757
769
  const cached = usage.prompt_tokens_details?.cached_tokens ??
758
770
  usage.prompt_cache_hit_tokens ??
759
771
  usage.cached_tokens ??
760
772
  usage.cache_read_input_tokens ??
761
773
  undefined;
762
774
  const cacheWrite = usage.prompt_tokens_details?.cache_write_tokens ?? usage.cache_created_input_tokens ?? undefined;
763
- const reasoning = usage.completion_tokens_details?.reasoning_tokens ?? undefined;
775
+ const reasoning = usage.completion_tokens_details?.reasoning_tokens ?? usage.reasoning_tokens ?? undefined;
776
+ // Copilot's Gemini counts reasoning beside `completion_tokens` rather than inside it; the total tells which.
777
+ const output = completion !== undefined &&
778
+ reasoning !== undefined &&
779
+ usage.total_tokens === ProviderShared.sumTokens(input, completion, reasoning)
780
+ ? completion + reasoning
781
+ : completion;
764
782
  const nonCached = ProviderShared.subtractTokens(input, ProviderShared.sumTokens(cached, cacheWrite));
765
783
  return new Usage({
766
784
  inputTokens: input,
@@ -770,7 +788,7 @@ const mapUsage = (usage, providerMetadataKey) => {
770
788
  cacheWriteInputTokens: cacheWrite,
771
789
  reasoningTokens: reasoning,
772
790
  totalTokens: ProviderShared.totalTokens(input, output, usage.total_tokens ?? undefined),
773
- ...ProviderShared.reportedBilling(usage),
791
+ ...ProviderShared.reportedBilling(usage, frame),
774
792
  providerMetadata: { [providerMetadataKey]: usage },
775
793
  });
776
794
  };
@@ -857,10 +875,11 @@ const conflictingReasoningDetails = (previous, current) => conflictingDetailValu
857
875
  conflictingDetailValue(previous.format, current.format) ||
858
876
  (Boolean(previous.signature) && Boolean(current.signature) && previous.signature !== current.signature);
859
877
  const conflictingDetailValue = (previous, current) => previous !== undefined && previous !== null && current !== undefined && current !== null && previous !== current;
860
- const reasoningMetadata = (providerMetadataKey, field, details) => ({
878
+ const reasoningMetadata = (providerMetadataKey, field, details, opaque) => ({
861
879
  [providerMetadataKey]: {
862
880
  ...(field ? { reasoningField: field } : {}),
863
881
  ...(details ? { reasoningDetails: details } : {}),
882
+ ...(opaque ? { reasoningOpaque: opaque } : {}),
864
883
  },
865
884
  });
866
885
  const step = (state, event) => Effect.gen(function* () {
@@ -878,14 +897,19 @@ const step = (state, event) => Effect.gen(function* () {
878
897
  const choice = event.choices?.[0];
879
898
  // Moonshot (and a few other OpenAI-compatible providers) attach usage to
880
899
  // `choice.usage` instead of the top-level `usage` field.
881
- const usage = mapUsage(event.usage, state.providerMetadataKey) ??
882
- mapUsage(choice?.usage, state.providerMetadataKey) ??
900
+ const usage = mapUsage(event.usage, state.providerMetadataKey, event) ??
901
+ mapUsage(choice?.usage, state.providerMetadataKey, event) ??
883
902
  state.usage;
884
903
  const rawFinishReason = choice?.finish_reason;
885
904
  const finishReason = rawFinishReason
886
905
  ? {
887
906
  normalized: yield* mapFinishReason(event, rawFinishReason),
888
907
  raw: choice?.native_finish_reason ?? rawFinishReason,
908
+ ...(rawFinishReason === "content_filter"
909
+ ? {
910
+ category: ProviderShared.contentFilterCategory(choice?.delta?.copilot_annotations, choice?.content_filter_results),
911
+ }
912
+ : {}),
889
913
  }
890
914
  : state.finishReason;
891
915
  const delta = choice?.delta;
@@ -911,13 +935,14 @@ const step = (state, event) => Effect.gen(function* () {
911
935
  if (detailDelta !== undefined)
912
936
  appendReasoningDetails(state.reasoningDetails, detailDelta);
913
937
  const reasoningDetailsObserved = state.reasoningDetailsObserved || detailDelta !== undefined;
938
+ const reasoningOpaque = delta?.reasoning_opaque || state.reasoningOpaque;
914
939
  const deltaMetadata = reasoningMetadata(state.providerMetadataKey, reasoningField);
915
940
  const text = detailDelta?.length
916
941
  ? (detailText(detailDelta, reasoningTextObserved) ?? reasoning?.text)
917
942
  : reasoning?.text;
918
943
  if (text !== undefined)
919
944
  lifecycle = Lifecycle.reasoningDelta(lifecycle, events, "reasoning-0", text, deltaMetadata);
920
- else if (reasoningDetailsObserved &&
945
+ else if ((reasoningDetailsObserved || reasoningOpaque !== undefined) &&
921
946
  !lifecycle.reasoning.has("reasoning-0") &&
922
947
  (Boolean(delta?.content) || Boolean(delta?.refusal) || toolDeltas.length > 0))
923
948
  lifecycle = Lifecycle.reasoningStart(lifecycle, events, "reasoning-0", deltaMetadata);
@@ -1013,6 +1038,7 @@ const step = (state, event) => Effect.gen(function* () {
1013
1038
  reasoningTextObserved,
1014
1039
  reasoningDetails: state.reasoningDetails,
1015
1040
  reasoningDetailsObserved,
1041
+ reasoningOpaque,
1016
1042
  reasoningEmitted,
1017
1043
  latestToolIndex,
1018
1044
  nextToolIndex,
@@ -1049,8 +1075,8 @@ export const finishEvents = Effect.fnUntraced(function* (state) {
1049
1075
  : { normalized: hasToolCalls ? "tool-calls" : "stop" };
1050
1076
  // Snapshot details at publish time so the emitted event never observes later
1051
1077
  // mutation of the accumulated `reasoningDetails` array.
1052
- const metadata = reasoningMetadata(state.providerMetadataKey, state.reasoningField, state.reasoningDetailsObserved ? [...state.reasoningDetails] : undefined);
1053
- const started = state.reasoningDetailsObserved && !state.reasoningEmitted
1078
+ const metadata = reasoningMetadata(state.providerMetadataKey, state.reasoningField, state.reasoningDetailsObserved ? [...state.reasoningDetails] : undefined, state.reasoningOpaque);
1079
+ const started = (state.reasoningDetailsObserved || state.reasoningOpaque !== undefined) && !state.reasoningEmitted
1054
1080
  ? Lifecycle.reasoningStart(state.lifecycle, events, "reasoning-0", reasoningMetadata(state.providerMetadataKey, state.reasoningField))
1055
1081
  : state.lifecycle;
1056
1082
  const ended = Lifecycle.reasoningEnd(started, events, "reasoning-0", metadata);
@@ -106,6 +106,7 @@ export declare const route: Route<{
106
106
  readonly reasoning?: string | undefined;
107
107
  readonly reasoning_text?: string | undefined;
108
108
  readonly reasoning_details?: unknown;
109
+ readonly reasoning_opaque?: string | undefined;
109
110
  })[];
110
111
  readonly tools?: readonly ({
111
112
  readonly type: "function";
@@ -54,7 +54,20 @@ const fromRequest = Effect.fn("OpenAIDecisions.fromRequest")(function* (request)
54
54
  }, request.http?.body),
55
55
  model: request.model.id,
56
56
  input: [{ role: "user", content: yield* Effect.forEach(request.input, (part) => inputPart(request, part)) }],
57
- questions: request.questions,
57
+ questions: request.questions.map((question) => {
58
+ if (question.type !== "predicate")
59
+ return question;
60
+ // Predicates have no criteria field, so what true and false mean is appended to the instructions.
61
+ const meanings = [
62
+ question.criteria?.true === undefined ? [] : [`True means: ${question.criteria.true}`],
63
+ question.criteria?.false === undefined ? [] : [`False means: ${question.criteria.false}`],
64
+ ].flat();
65
+ return {
66
+ name: question.name,
67
+ type: question.type,
68
+ instructions: meanings.length === 0 ? question.instructions : `${question.instructions}\n\n${meanings.join("\n")}`,
69
+ };
70
+ }),
58
71
  };
59
72
  });
60
73
  // `input_json` takes an object or a list of objects; other JSON values go as text.
@@ -0,0 +1,16 @@
1
+ import { EmbeddingRoute } from "../route/embedding.js";
2
+ import { type OpenString } from "../schema/index.js";
3
+ export declare const DEFAULT_BASE_URL = "https://api.openai.com/v1";
4
+ export declare const PATH = "/embeddings";
5
+ /** Sent as given; anything else a host accepts (`input_type`, `truncate`, …) goes alongside. */
6
+ export interface OptionsInput {
7
+ readonly [key: string]: unknown;
8
+ readonly user?: string;
9
+ readonly encoding_format?: OpenString<"float" | "base64">;
10
+ }
11
+ export declare const protocol: EmbeddingRoute.Protocol;
12
+ export declare const route: EmbeddingRoute.Route;
13
+ export declare const OpenAIEmbeddings: {
14
+ readonly protocol: EmbeddingRoute.Protocol;
15
+ readonly route: EmbeddingRoute.Route;
16
+ };
@@ -0,0 +1,76 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Base64 } from "effect/encoding";
3
+ import { EmbeddingResponse, EmbeddingUsage } from "../embedding.js";
4
+ import { EmbeddingRoute } from "../route/embedding.js";
5
+ import { Endpoint } from "../route/endpoint.js";
6
+ import { MediaProtocol } from "../route/media-protocol.js";
7
+ import { AIError, UnsupportedOperationError, mergeJsonRecords } from "../schema/index.js";
8
+ const ID = "openai-embeddings";
9
+ const NAME = "OpenAI Embeddings";
10
+ export const DEFAULT_BASE_URL = "https://api.openai.com/v1";
11
+ export const PATH = "/embeddings";
12
+ const Response = Schema.Struct({
13
+ data: Schema.Array(Schema.Struct({
14
+ index: Schema.optional(Schema.Int),
15
+ // `base64` encoding returns little-endian float32 bytes instead of a number list.
16
+ embedding: Schema.Union([Schema.Array(Schema.Number), Schema.String]),
17
+ })),
18
+ model: Schema.optional(Schema.String),
19
+ usage: Schema.optional(Schema.StructWithRest(Schema.Struct({ prompt_tokens: Schema.optional(Schema.Number), total_tokens: Schema.optional(Schema.Number) }), [Schema.Record(Schema.String, Schema.Unknown)])),
20
+ });
21
+ // `inputType` has no field here; OpenAI's models embed queries and documents the same way.
22
+ const fromRequest = Effect.fn("OpenAIEmbeddings.fromRequest")(function* (request) {
23
+ const input = request.values.filter((value) => typeof value === "string");
24
+ if (input.length !== request.values.length)
25
+ return yield* new AIError({
26
+ reason: new UnsupportedOperationError({
27
+ operation: "embedding.media",
28
+ provider: request.model.provider,
29
+ route: request.model.route.id,
30
+ message: `${NAME} embeds text only; pass media values to a host with a multimodal embedding API`,
31
+ }),
32
+ });
33
+ return {
34
+ ...mergeJsonRecords({ encoding_format: "float", ...request.providerOptions }, request.http?.body),
35
+ model: request.model.id,
36
+ input,
37
+ ...(request.dimensions === undefined ? {} : { dimensions: request.dimensions }),
38
+ };
39
+ });
40
+ const decodeDocument = MediaProtocol.identity({ id: ID, name: NAME, provider: "openai" }).decodeJson(Response);
41
+ export const protocol = EmbeddingRoute.protocol({
42
+ id: ID,
43
+ name: NAME,
44
+ body: { from: fromRequest },
45
+ response: {
46
+ decode: Effect.fn("OpenAIEmbeddings.decodeResponse")(function* (response, context) {
47
+ const output = yield* decodeDocument(response);
48
+ const embeddings = yield* Effect.forEach(output.value.data
49
+ .map((item, position) => ({ index: item.index ?? position, embedding: item.embedding }))
50
+ .toSorted((a, b) => a.index - b.index), (item) => typeof item.embedding !== "string"
51
+ ? Effect.succeed(item.embedding)
52
+ : Effect.fromResult(Base64.decode(item.embedding)).pipe(Effect.map((bytes) => Array.from(new Float32Array(bytes.slice().buffer))), Effect.mapError((cause) => output.invalid(`${NAME} returned an invalid base64 embedding`, cause))));
53
+ const usage = output.value.usage;
54
+ return new EmbeddingResponse({
55
+ embeddings,
56
+ usage: usage?.prompt_tokens === undefined ? undefined : new EmbeddingUsage({ inputTokens: usage.prompt_tokens }),
57
+ providerMetadata: {
58
+ [context.providerMetadataKey]: {
59
+ ...(output.value.model === undefined ? {} : { model: output.value.model }),
60
+ ...(usage === undefined ? {} : { usage }),
61
+ },
62
+ },
63
+ });
64
+ }),
65
+ },
66
+ });
67
+ export const route = EmbeddingRoute.make({
68
+ id: ID,
69
+ provider: "openai",
70
+ protocol,
71
+ endpoint: Endpoint.path(PATH, { baseURL: DEFAULT_BASE_URL }),
72
+ });
73
+ export const OpenAIEmbeddings = {
74
+ protocol,
75
+ route,
76
+ };
@@ -17,10 +17,20 @@ export declare const lenient: <const S extends Schema.Top>(schema: S) => Schema.
17
17
  export declare const ReportedBilling: Schema.Struct<{
18
18
  readonly cost: Schema.optionalKey<Schema.middlewareDecoding<Schema.UndefinedOr<Schema.Finite>, never>>;
19
19
  }>;
20
- /** Reads `ReportedBilling` from a raw usage object, which provider metadata keeps as the endpoint sent it. */
21
- export declare const reportedBilling: (usage: unknown) => {} | {
22
- cost: number | undefined;
20
+ /**
21
+ * Reads `ReportedBilling` from a raw usage object, which provider metadata keeps as the endpoint sent it, or
22
+ * Copilot's billing from the frames that carry the usage.
23
+ */
24
+ export declare const reportedBilling: (usage: unknown, ...frames: ReadonlyArray<unknown>) => {
25
+ cost: number;
26
+ } | {
27
+ cost?: undefined;
23
28
  };
29
+ /**
30
+ * The filter that blocked a response, from maps keyed by filter name: Azure's `content_filter_results`
31
+ * (`{ hate: { filtered: true } }`) or GitHub Copilot's `copilot_annotations` (`{ TextCopyright: [...] }`).
32
+ */
33
+ export declare const contentFilterCategory: (...sources: ReadonlyArray<unknown>) => string | undefined;
24
34
  /**
25
35
  * Accepts stream frames that carry no `type`, alongside the typed event schema. Gateways inject such frames as
26
36
  * keep-alives, so they decode as an ignored event; one with an `error` still decodes as an error event.
@@ -23,11 +23,34 @@ const billedAmount = lenient(Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0
23
23
  export const ReportedBilling = Schema.Struct({
24
24
  cost: billedAmount,
25
25
  });
26
- /** Reads `ReportedBilling` from a raw usage object, which provider metadata keeps as the endpoint sent it. */
27
- export const reportedBilling = (usage) => Option.match(Schema.decodeUnknownOption(ReportedBilling)(usage), {
28
- onNone: () => ({}),
29
- onSome: (billing) => ({ cost: billing.cost }),
26
+ /**
27
+ * GitHub Copilot reports its charge beside usage on the frame that carries it, as `copilot_usage.total_nano_aiu`:
28
+ * billionths of an AI credit, which costs $0.01.
29
+ */
30
+ const CopilotBilling = Schema.Struct({
31
+ copilot_usage: Schema.Struct({ total_nano_aiu: Schema.Finite.check(Schema.isGreaterThanOrEqualTo(0)) }),
30
32
  });
33
+ const decodeCopilotBilling = Schema.decodeUnknownOption(CopilotBilling);
34
+ /**
35
+ * Reads `ReportedBilling` from a raw usage object, which provider metadata keeps as the endpoint sent it, or
36
+ * Copilot's billing from the frames that carry the usage.
37
+ */
38
+ export const reportedBilling = (usage, ...frames) => {
39
+ const reported = Option.getOrUndefined(Schema.decodeUnknownOption(ReportedBilling)(usage))?.cost;
40
+ if (reported !== undefined)
41
+ return { cost: reported };
42
+ const nanoAiu = frames
43
+ .map((frame) => Option.getOrUndefined(decodeCopilotBilling(frame))?.copilot_usage.total_nano_aiu)
44
+ .find((value) => value !== undefined);
45
+ return nanoAiu === undefined ? {} : { cost: nanoAiu / 100_000_000_000 };
46
+ };
47
+ /**
48
+ * The filter that blocked a response, from maps keyed by filter name: Azure's `content_filter_results`
49
+ * (`{ hate: { filtered: true } }`) or GitHub Copilot's `copilot_annotations` (`{ TextCopyright: [...] }`).
50
+ */
51
+ export const contentFilterCategory = (...sources) => sources
52
+ .flatMap((source) => (isRecord(source) ? Object.entries(source) : []))
53
+ .find(([, value]) => (isRecord(value) && "filtered" in value ? value.filtered === true : Boolean(value)))?.[0];
31
54
  /**
32
55
  * Accepts stream frames that carry no `type`, alongside the typed event schema. Gateways inject such frames as
33
56
  * keep-alives, so they decode as an ignored event; one with an `error` still decodes as an error event.
@@ -47,7 +47,14 @@ export const encodeBody = Effect.fn("SystemOne.encodeBody")(function* (request,
47
47
  });
48
48
  const encodeQuestions = (questions) => Effect.forEach(questions, (question) => {
49
49
  if (question.type === "predicate")
50
- return Effect.succeed([question.name, { type: "noul", instructions: question.instructions }]);
50
+ return Effect.succeed([
51
+ question.name,
52
+ {
53
+ type: "noul",
54
+ instructions: question.instructions,
55
+ ...(question.criteria === undefined ? {} : { criteria: question.criteria }),
56
+ },
57
+ ]);
51
58
  if (question.type === "score")
52
59
  return Effect.succeed([
53
60
  question.name,
@@ -202,6 +202,7 @@ export declare const protocol: Protocol<{
202
202
  readonly reasoning?: string | undefined;
203
203
  readonly reasoning_text?: string | undefined;
204
204
  readonly reasoning_details?: unknown;
205
+ readonly reasoning_opaque?: string | undefined;
205
206
  readonly tool_calls?: readonly ({
206
207
  readonly id: string;
207
208
  readonly type: "custom";
@@ -262,6 +263,7 @@ export declare const protocol: Protocol<{
262
263
  readonly prompt_cache_hit_tokens?: number | null | undefined;
263
264
  readonly cache_read_input_tokens?: number | null | undefined;
264
265
  readonly cache_created_input_tokens?: number | null | undefined;
266
+ readonly reasoning_tokens?: number | null | undefined;
265
267
  readonly prompt_tokens_details?: {
266
268
  readonly [x: string]: unknown;
267
269
  readonly cached_tokens?: number | null | undefined;
@@ -282,6 +284,7 @@ export declare const protocol: Protocol<{
282
284
  readonly reasoning?: string | null | undefined;
283
285
  readonly reasoning_text?: string | null | undefined;
284
286
  readonly reasoning_details?: unknown;
287
+ readonly reasoning_opaque?: string | null | undefined;
285
288
  readonly tool_calls?: readonly {
286
289
  readonly index?: number | null | undefined;
287
290
  readonly id?: string | null | undefined;
@@ -308,6 +311,7 @@ export declare const protocol: Protocol<{
308
311
  readonly prompt_cache_hit_tokens?: number | null | undefined;
309
312
  readonly cache_read_input_tokens?: number | null | undefined;
310
313
  readonly cache_created_input_tokens?: number | null | undefined;
314
+ readonly reasoning_tokens?: number | null | undefined;
311
315
  readonly completion_tokens_details?: {
312
316
  readonly [x: string]: unknown;
313
317
  readonly reasoning_tokens?: number | null | undefined;
@@ -129,6 +129,7 @@ export declare const protocol: Protocol<{
129
129
  readonly reasoning?: string | undefined;
130
130
  readonly reasoning_text?: string | undefined;
131
131
  readonly reasoning_details?: unknown;
132
+ readonly reasoning_opaque?: string | undefined;
132
133
  })[];
133
134
  readonly tools?: readonly ({
134
135
  readonly type: "function";
@@ -224,6 +225,7 @@ export declare const protocol: Protocol<{
224
225
  readonly reasoning?: string | null | undefined;
225
226
  readonly reasoning_text?: string | null | undefined;
226
227
  readonly reasoning_details?: unknown;
228
+ readonly reasoning_opaque?: string | null | undefined;
227
229
  readonly tool_calls?: readonly {
228
230
  readonly index?: number | null | undefined;
229
231
  readonly id?: string | null | undefined;
@@ -249,6 +251,7 @@ export declare const protocol: Protocol<{
249
251
  readonly prompt_cache_hit_tokens?: number | null | undefined;
250
252
  readonly cache_read_input_tokens?: number | null | undefined;
251
253
  readonly cache_created_input_tokens?: number | null | undefined;
254
+ readonly reasoning_tokens?: number | null | undefined;
252
255
  readonly prompt_tokens_details?: {
253
256
  readonly [x: string]: unknown;
254
257
  readonly cached_tokens?: number | null | undefined;
@@ -271,6 +274,7 @@ export declare const protocol: Protocol<{
271
274
  readonly prompt_cache_hit_tokens?: number | null | undefined;
272
275
  readonly cache_read_input_tokens?: number | null | undefined;
273
276
  readonly cache_created_input_tokens?: number | null | undefined;
277
+ readonly reasoning_tokens?: number | null | undefined;
274
278
  readonly prompt_tokens_details?: {
275
279
  readonly [x: string]: unknown;
276
280
  readonly cached_tokens?: number | null | undefined;
@@ -0,0 +1,2 @@
1
+ export { embeddingModel as model } from "../alibaba.js";
2
+ export type { Settings } from "../alibaba.js";
@@ -0,0 +1 @@
1
+ export { embeddingModel as model } from "../alibaba.js";
@@ -124,6 +124,7 @@ export declare const routes: (Route<{
124
124
  readonly reasoning?: string | undefined;
125
125
  readonly reasoning_text?: string | undefined;
126
126
  readonly reasoning_details?: unknown;
127
+ readonly reasoning_opaque?: string | undefined;
127
128
  })[];
128
129
  readonly tools?: readonly ({
129
130
  readonly type: "function";
@@ -775,6 +776,7 @@ export declare const configure: (input: Config) => {
775
776
  readonly conversation?: string | undefined;
776
777
  }, import("../route/client.js").CompactionOperations | undefined>;
777
778
  image: (id: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("./alibaba.js").AlibabaImageOptions>;
779
+ embedding: (id: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
778
780
  configure: typeof configure;
779
781
  };
780
782
  export declare const provider: {
@@ -848,6 +850,7 @@ export declare const responses: ProviderPackage.Model<Settings<{
848
850
  readonly conversation?: string | undefined;
849
851
  }, import("../route/client.js").CompactionOperations | undefined>;
850
852
  export declare const imageModel: (id: string, settings: Settings) => import("../image.js").ImageModel<import("./alibaba.js").AlibabaImageOptions>;
853
+ export declare const embeddingModel: (id: string, settings: Settings) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
851
854
  export declare const webSearch: () => ToolDefinition;
852
855
  export declare const webExtractor: () => ToolDefinition;
853
856
  export declare const codeInterpreter: () => ToolDefinition;
@@ -1,6 +1,7 @@
1
1
  import { Struct } from "effect";
2
2
  import { AlibabaChat } from "../protocols/alibaba-chat.js";
3
3
  import { AlibabaImages } from "../protocols/alibaba-images.js";
4
+ import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
4
5
  import { AlibabaMessages } from "../protocols/alibaba-messages.js";
5
6
  import { AlibabaResponses } from "../protocols/alibaba-responses.js";
6
7
  import { AuthOptions } from "../route/auth-options.js";
@@ -72,7 +73,15 @@ export const configure = (input) => {
72
73
  const responses = (id) => responsesRoute.with(common).model({ id });
73
74
  const media = MediaRoute.deployment({ ...input, baseURL: baseURL ?? `https://${host}/api/v1` }, opts.auth);
74
75
  const image = (id, providerOptions) => AlibabaImages.model({ ...media, id, providerOptions });
75
- return { id, model: chat, chat, messages, responses, image, configure };
76
+ const embeddingRoute = OpenAIEmbeddings.route.with({
77
+ provider: id,
78
+ endpoint: common.endpoint,
79
+ auth: opts.auth,
80
+ headers: input.headers,
81
+ http: input.http,
82
+ });
83
+ const embedding = (id, providerOptions) => embeddingRoute.model({ id, providerOptions });
84
+ return { id, model: chat, chat, messages, responses, image, embedding, configure };
76
85
  };
77
86
  export const provider = { id, configure };
78
87
  export const model = (id, input) => configure(config(input)).chat(id);
@@ -85,6 +94,10 @@ export const imageModel = (id, settings) => {
85
94
  const input = config(settings);
86
95
  return configure(input).image(id, input.providerOptions);
87
96
  };
97
+ export const embeddingModel = (id, settings) => {
98
+ const input = config(settings);
99
+ return configure(input).embedding(id, input.providerOptions);
100
+ };
88
101
  function config(input) {
89
102
  const { body, ...rest } = input;
90
103
  return {
@@ -641,6 +641,7 @@ export declare const routes: (Route<{
641
641
  readonly reasoning?: string | undefined;
642
642
  readonly reasoning_text?: string | undefined;
643
643
  readonly reasoning_details?: unknown;
644
+ readonly reasoning_opaque?: string | undefined;
644
645
  })[];
645
646
  readonly tools?: readonly ({
646
647
  readonly type: "function";
@@ -0,0 +1,2 @@
1
+ export { embeddingModel as model } from "../azure.js";
2
+ export type { Settings } from "../azure.js";
@@ -0,0 +1 @@
1
+ export { embeddingModel as model } from "../azure.js";
@@ -661,6 +661,7 @@ export declare const routes: (Route<{
661
661
  readonly reasoning?: string | undefined;
662
662
  readonly reasoning_text?: string | undefined;
663
663
  readonly reasoning_details?: unknown;
664
+ readonly reasoning_opaque?: string | undefined;
664
665
  })[];
665
666
  readonly tools?: readonly ({
666
667
  readonly type: "function";
@@ -977,6 +978,7 @@ export declare const configure: (input: Config) => {
977
978
  chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<import("./openai-options.js").OpenAIOptionsInput, CompactionOperations | undefined>;
978
979
  messages: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<AnthropicMessages.OptionsInput, CompactionOperations | undefined>;
979
980
  image: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
981
+ embedding: (modelID: string | ModelID, providerOptions?: ProviderOptions) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
980
982
  configure: typeof configure;
981
983
  };
982
984
  export declare const provider: {
@@ -987,6 +989,7 @@ export declare const responsesModel: ProviderPackage.Model<Settings, OpenAIProvi
987
989
  export declare const chatModel: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput>;
988
990
  export declare const messagesModel: ProviderPackage.Model<MessagesSettings, AnthropicMessages.ProviderOptionsInput>;
989
991
  export declare const imageModel: (modelID: string, settings: Settings) => import("../image.js").ImageModel<import("../protocols/openai-images.js").OpenAIImageOptions>;
992
+ export declare const embeddingModel: (modelID: string, settings: Settings) => import("../embedding.js").EmbeddingModel<import("../embedding.js").EmbeddingOptions>;
990
993
  export declare const model: ProviderPackage.Model<Settings<import("./openai-options.js").OpenAIOptionsInput>, import("./openai-options.js").OpenAIOptionsInput, {
991
994
  endpoint: import("../route/client.js").CompactOperation;
992
995
  }>;
@@ -5,6 +5,7 @@ import { MediaRoute } from "../route/media.js";
5
5
  import { ProviderConfigurationError, ProviderID, } from "../schema/index.js";
6
6
  import { AnthropicMessages } from "../protocols/anthropic-messages.js";
7
7
  import { OpenAIImages } from "../protocols/openai-images.js";
8
+ import { OpenAIEmbeddings } from "../protocols/openai-embeddings.js";
8
9
  import * as OpenAIChat from "../protocols/openai-chat.js";
9
10
  import * as OpenAIResponses from "../protocols/openai-responses.js";
10
11
  import { withOpenAIOptions } from "./openai-options.js";
@@ -100,6 +101,15 @@ export const configure = (input) => {
100
101
  http: { ...media.http, query: { ...media.http?.query, ...target.query } },
101
102
  });
102
103
  };
104
+ const embedding = (modelID, providerOptions) => OpenAIEmbeddings.route
105
+ .with({
106
+ provider: id,
107
+ endpoint: endpoint(input, modelID),
108
+ auth: auth(input),
109
+ headers: input.headers,
110
+ http: input.http,
111
+ })
112
+ .model({ id: modelID, providerOptions });
103
113
  return {
104
114
  id,
105
115
  model: responses,
@@ -107,6 +117,7 @@ export const configure = (input) => {
107
117
  chat,
108
118
  messages,
109
119
  image,
120
+ embedding,
110
121
  configure,
111
122
  };
112
123
  };
@@ -137,6 +148,10 @@ export const imageModel = (modelID, settings) => {
137
148
  const input = config(settings);
138
149
  return configure(input).image(modelID, input.providerOptions);
139
150
  };
151
+ export const embeddingModel = (modelID, settings) => {
152
+ const input = config(settings);
153
+ return configure(input).embedding(modelID, input.providerOptions);
154
+ };
140
155
  export const model = responsesModel;
141
156
  export const responses = responsesModel;
142
157
  export const chat = chatModel;
@@ -116,6 +116,7 @@ export declare const route: Route<{
116
116
  readonly reasoning?: string | undefined;
117
117
  readonly reasoning_text?: string | undefined;
118
118
  readonly reasoning_details?: unknown;
119
+ readonly reasoning_opaque?: string | undefined;
119
120
  })[];
120
121
  readonly tools?: readonly ({
121
122
  readonly type: "function";
@@ -290,6 +291,7 @@ export declare const routes: Route<{
290
291
  readonly reasoning?: string | undefined;
291
292
  readonly reasoning_text?: string | undefined;
292
293
  readonly reasoning_details?: unknown;
294
+ readonly reasoning_opaque?: string | undefined;
293
295
  })[];
294
296
  readonly tools?: readonly ({
295
297
  readonly type: "function";
@@ -112,6 +112,7 @@ export declare const route: Route<{
112
112
  readonly reasoning?: string | undefined;
113
113
  readonly reasoning_text?: string | undefined;
114
114
  readonly reasoning_details?: unknown;
115
+ readonly reasoning_opaque?: string | undefined;
115
116
  })[];
116
117
  readonly tools?: readonly ({
117
118
  readonly type: "function";
@@ -286,6 +287,7 @@ export declare const routes: Route<{
286
287
  readonly reasoning?: string | undefined;
287
288
  readonly reasoning_text?: string | undefined;
288
289
  readonly reasoning_details?: unknown;
290
+ readonly reasoning_opaque?: string | undefined;
289
291
  })[];
290
292
  readonly tools?: readonly ({
291
293
  readonly type: "function";
@@ -669,6 +669,7 @@ export declare const route: import("../route.js").Route<{
669
669
  readonly reasoning?: string | undefined;
670
670
  readonly reasoning_text?: string | undefined;
671
671
  readonly reasoning_details?: unknown;
672
+ readonly reasoning_opaque?: string | undefined;
672
673
  })[];
673
674
  readonly tools?: readonly ({
674
675
  readonly type: "function";
@@ -1150,6 +1151,7 @@ export declare const routes: (import("../route.js").Route<{
1150
1151
  readonly reasoning?: string | undefined;
1151
1152
  readonly reasoning_text?: string | undefined;
1152
1153
  readonly reasoning_details?: unknown;
1154
+ readonly reasoning_opaque?: string | undefined;
1153
1155
  })[];
1154
1156
  readonly tools?: readonly ({
1155
1157
  readonly type: "function";