@opencode/ai 0.0.0-beta-19365 → 0.0.0-beta-19378

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.
@@ -0,0 +1,80 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { Protocol } from "../route/protocol.js";
3
+ import { OpenResponses } from "./open-responses.js";
4
+ import { JsonObject, optionalArray, ProviderShared } from "./shared.js";
5
+ import { OpenResponsesOptions } from "./utils/open-responses-options.js";
6
+ import { ResponsesHostedTools } from "./utils/responses-hosted-tools.js";
7
+ const Options = Schema.Struct({
8
+ reasoningEffort: OpenResponsesOptions.Options.fields.reasoningEffort,
9
+ enableThinking: Schema.optional(Schema.Boolean),
10
+ store: OpenResponsesOptions.Options.fields.store,
11
+ previousResponseId: Schema.optional(Schema.String),
12
+ conversation: Schema.optional(Schema.String),
13
+ });
14
+ const NativeTool = Schema.Struct({ type: Schema.Literals(["web_search", "web_extractor", "code_interpreter"]) });
15
+ const WebExtractorItem = Schema.StructWithRest(Schema.Struct({
16
+ type: Schema.Literal("web_extractor_call"),
17
+ id: Schema.String,
18
+ urls: Schema.optional(Schema.Array(Schema.String)),
19
+ goal: Schema.optional(Schema.String),
20
+ }), [JsonObject]);
21
+ const Body = Schema.Struct({
22
+ ...OpenResponses.coreFields,
23
+ input: Schema.Array(Schema.Union([OpenResponses.InputItem, WebExtractorItem])),
24
+ tools: optionalArray(Schema.Union([OpenResponses.Tool, NativeTool])),
25
+ enable_thinking: Options.fields.enableThinking,
26
+ previous_response_id: Options.fields.previousResponseId,
27
+ conversation: Options.fields.conversation,
28
+ stream: Schema.Literal(true),
29
+ });
30
+ const adapter = {
31
+ id: "alibaba-responses",
32
+ name: "Alibaba Responses",
33
+ nativeTool: (native) => ProviderShared.validateWith(Schema.decodeUnknownEffect(NativeTool))(native.alibaba),
34
+ restoreHostedToolItem: (item) => (Schema.is(WebExtractorItem)(item) ? item : undefined),
35
+ };
36
+ const tools = {
37
+ web_search_call: { name: "web_search", input: (item) => item.action ?? {} },
38
+ code_interpreter_call: { name: "code_interpreter", input: (item) => ({ code: item.code }) },
39
+ };
40
+ export const protocol = Protocol.make({
41
+ id: adapter.id,
42
+ body: {
43
+ schema: Body,
44
+ from: Effect.fn("AlibabaResponses.fromRequest")(function* (req) {
45
+ const opts = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(req.providerOptions ?? {});
46
+ const body = yield* OpenResponses.fromRequestWithAdapter(req, adapter);
47
+ const choice = body.tool_choice;
48
+ return yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Body))({
49
+ ...body,
50
+ enable_thinking: opts.enableThinking,
51
+ previous_response_id: opts.previousResponseId,
52
+ conversation: opts.conversation,
53
+ // Model Studio expresses named selection through allowed_tools.
54
+ tool_choice: typeof choice === "object" && choice.type === "function"
55
+ ? { type: "allowed_tools", mode: "required", tools: [choice] }
56
+ : choice,
57
+ });
58
+ }),
59
+ },
60
+ stream: {
61
+ event: OpenResponses.protocol.stream.event,
62
+ initial: (req) => OpenResponses.initial(req, adapter),
63
+ step: (state, input) => Effect.gen(function* () {
64
+ const event = OpenResponses.normalize(state, input);
65
+ if (event.type !== "response.output_item.done" || !event.item)
66
+ return yield* OpenResponses.step(state, event);
67
+ if (event.item.type === "web_extractor_call") {
68
+ const item = yield* Schema.decodeUnknownEffect(WebExtractorItem)(event.item).pipe(Effect.mapError((cause) => ProviderShared.eventError(adapter.id, "Alibaba returned an invalid web extraction item", ProviderShared.encodeJson(event), cause)));
69
+ return yield* ResponsesHostedTools.onDone(state, item, {
70
+ web_extractor_call: { name: "web_extractor", input: () => ({ urls: item.urls, goal: item.goal }) },
71
+ });
72
+ }
73
+ if (ResponsesHostedTools.isItem(event.item, tools))
74
+ return yield* ResponsesHostedTools.onDone(state, event.item, tools);
75
+ return yield* OpenResponses.step(state, event);
76
+ }),
77
+ terminal: OpenResponses.terminal,
78
+ },
79
+ });
80
+ export * as AlibabaResponses from "./alibaba-responses.js";
@@ -656,6 +656,9 @@ export type NormalizedEvent = Event & {
656
656
  export interface ProviderAdapter {
657
657
  readonly id: string;
658
658
  readonly name: string;
659
+ readonly nativeTool?: (native: NonNullable<ToolDefinition["native"]>) => Effect.Effect<{
660
+ readonly type: string;
661
+ }, AIError>;
659
662
  readonly lowerMedia?: (input: {
660
663
  readonly part: MediaPart;
661
664
  readonly media: ProviderShared.NormalizedMedia;
@@ -750,13 +753,7 @@ export declare const fromRequestWithAdapter: (request: LLMRequest<import("../sch
750
753
  readonly [x: string]: unknown;
751
754
  }, import("../route.js").CompactionOperations | undefined>>, adapter: ProviderAdapter) => Effect.Effect<{
752
755
  tools: {
753
- type: "function";
754
- name: string;
755
- description: string;
756
- parameters: {
757
- readonly [x: string]: unknown;
758
- };
759
- strict: boolean;
756
+ readonly type: string;
760
757
  }[] | undefined;
761
758
  tool_choice: "required" | "auto" | "none" | {
762
759
  type: "allowed_tools";
@@ -597,7 +597,9 @@ export const fromRequestWithAdapter = Effect.fn("OpenResponses.fromRequestWithAd
597
597
  ...lowerGeneration(request),
598
598
  tools: projected.tools.length === 0
599
599
  ? undefined
600
- : yield* Effect.forEach(projected.tools, (tool) => lowerTool(adapter.name, tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, toolSchemaCompatibility))),
600
+ : yield* Effect.forEach(projected.tools, (tool) => tool.native !== undefined && adapter.nativeTool
601
+ ? adapter.nativeTool(tool.native)
602
+ : lowerTool(adapter.name, tool, ToolSchemaProjection.modelCompatibility(tool.inputSchema, toolSchemaCompatibility))),
601
603
  tool_choice: allowedToolChoice(request) ??
602
604
  (request.toolChoice ? yield* lowerToolChoice(adapter.name, request.toolChoice) : undefined),
603
605
  };
@@ -0,0 +1 @@
1
+ export { model, type Settings } from "../alibaba.js";
@@ -0,0 +1 @@
1
+ export { model } from "../alibaba.js";
@@ -0,0 +1,3 @@
1
+ import type { Alibaba } from "../alibaba.js";
2
+ export { messagesModel as model } from "../alibaba.js";
3
+ export type Settings = Alibaba.Settings<Alibaba.MessagesOptionsInput>;
@@ -0,0 +1 @@
1
+ export { messagesModel as model } from "../alibaba.js";
@@ -0,0 +1,3 @@
1
+ import type { Alibaba } from "../alibaba.js";
2
+ export { responsesModel as model } from "../alibaba.js";
3
+ export type Settings = Alibaba.Settings<Alibaba.ResponsesOptionsInput>;
@@ -0,0 +1 @@
1
+ export { responsesModel as model } from "../alibaba.js";