New:Socket for Asana Is Now Available.Learn more
Sign In

@opencode-ai/ai

Package Overview
Dependencies
Maintainers
2
Versions
958
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opencode-ai/ai - npm Package Compare versions

Comparing version
0.0.0-beta-18286
to
0.0.0-beta-18311
+315
dist/providers/groq.d.ts
import type { ProviderPackage } from "../provider-package.js";
import { OpenAIChat } from "../protocols/openai-chat.js";
import { type ProviderAuthOption } from "../route/auth-options.js";
import { Route, type RouteDefaultsInput } from "../route/client.js";
import { Protocol } from "../route/protocol.js";
import { type ModelID } from "../schema/index.js";
import type { OpenAIProviderOptionsInput } from "./openai-options.js";
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
export type ProviderOptions = Pick<OpenAIProviderOptionsInput, "reasoningEffort"> & {
/** Controls visible reasoning on GPT-OSS; other models always use parsed reasoning. */
readonly includeReasoning?: boolean;
readonly parallelToolCalls?: boolean;
readonly serviceTier?: "on_demand" | "flex" | "auto" | "performance" | (string & {});
readonly user?: string;
};
export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
readonly baseURL?: string;
readonly providerOptions?: ProviderOptions;
};
export interface Settings extends ProviderPackage.Settings {
readonly apiKey?: string;
readonly baseURL?: string;
readonly providerOptions?: ProviderOptions;
}
export declare const protocol: Protocol<{
readonly model: string;
readonly messages: readonly ({
readonly role: "system";
readonly content: string | readonly ({
readonly type: "text";
readonly text: string;
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
} | {
readonly type: "image_url";
readonly image_url: {
readonly url: string;
};
})[];
} | {
readonly role: "user";
readonly content: string | readonly ({
readonly type: "text";
readonly text: string;
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
} | {
readonly type: "image_url";
readonly image_url: {
readonly url: string;
};
})[];
} | {
readonly [x: string]: unknown;
readonly content: string | null;
readonly role: "assistant";
readonly reasoning?: string | undefined;
readonly reasoning_content?: string | undefined;
readonly reasoning_text?: string | undefined;
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
readonly tool_calls?: readonly {
readonly id: string;
readonly type: "function";
readonly function: {
readonly name: string;
readonly arguments: string;
};
}[] | undefined;
readonly reasoning_details?: unknown;
} | {
readonly content: string;
readonly role: "tool";
readonly tool_call_id: string;
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
})[];
readonly stream: true;
readonly max_completion_tokens?: number | undefined;
readonly max_tokens?: number | undefined;
readonly tools?: readonly {
readonly function: {
readonly description: string;
readonly name: string;
readonly parameters: {
readonly [x: string]: unknown;
};
readonly strict?: boolean | undefined;
};
readonly type: "function";
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
}[] | undefined;
readonly stop?: readonly string[] | undefined;
readonly user?: string | undefined;
readonly temperature?: number | undefined;
readonly seed?: number | undefined;
readonly service_tier?: string | undefined;
readonly tool_choice?: "required" | "auto" | "none" | {
readonly type: "function";
readonly function: {
readonly name: string;
};
} | undefined;
readonly top_p?: number | undefined;
readonly store?: boolean | undefined;
readonly stream_options?: {
readonly include_usage: boolean;
} | undefined;
readonly prompt_cache_key?: string | undefined;
readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
readonly tool_stream?: boolean | undefined;
readonly frequency_penalty?: number | undefined;
readonly presence_penalty?: number | undefined;
readonly parallel_tool_calls?: boolean | undefined;
readonly reasoning_format?: "parsed" | undefined;
readonly include_reasoning?: boolean | undefined;
}, string, {
readonly [x: string]: unknown;
readonly error?: {
readonly [x: string]: unknown;
readonly message: string;
readonly code?: string | number | null | undefined;
} | null | undefined;
readonly usage?: {
readonly [x: string]: unknown;
readonly prompt_tokens?: number | null | undefined;
readonly completion_tokens?: number | null | undefined;
readonly total_tokens?: number | null | undefined;
readonly cached_tokens?: number | null | undefined;
readonly prompt_cache_hit_tokens?: number | null | undefined;
readonly prompt_tokens_details?: {
readonly [x: string]: unknown;
readonly cached_tokens?: number | null | undefined;
readonly cache_write_tokens?: number | null | undefined;
} | null | undefined;
readonly completion_tokens_details?: {
readonly [x: string]: unknown;
readonly reasoning_tokens?: number | null | undefined;
readonly accepted_prediction_tokens?: number | null | undefined;
readonly rejected_prediction_tokens?: number | null | undefined;
} | null | undefined;
} | null | undefined;
readonly choices?: readonly {
readonly [x: string]: unknown;
readonly delta?: {
readonly [x: string]: unknown;
readonly reasoning?: string | null | undefined;
readonly reasoning_content?: string | null | undefined;
readonly reasoning_text?: string | null | undefined;
readonly content?: string | null | undefined;
readonly refusal?: string | null | undefined;
readonly tool_calls?: readonly {
readonly function?: {
readonly name?: string | null | undefined;
readonly arguments?: string | null | undefined;
} | null | undefined;
readonly id?: string | null | undefined;
readonly index?: number | null | undefined;
}[] | null | undefined;
readonly reasoning_details?: unknown;
} | null | undefined;
readonly usage?: {
readonly [x: string]: unknown;
readonly prompt_tokens?: number | null | undefined;
readonly completion_tokens?: number | null | undefined;
readonly total_tokens?: number | null | undefined;
readonly cached_tokens?: number | null | undefined;
readonly prompt_cache_hit_tokens?: number | null | undefined;
readonly prompt_tokens_details?: {
readonly [x: string]: unknown;
readonly cached_tokens?: number | null | undefined;
readonly cache_write_tokens?: number | null | undefined;
} | null | undefined;
readonly completion_tokens_details?: {
readonly [x: string]: unknown;
readonly reasoning_tokens?: number | null | undefined;
readonly accepted_prediction_tokens?: number | null | undefined;
readonly rejected_prediction_tokens?: number | null | undefined;
} | null | undefined;
} | null | undefined;
readonly finish_reason?: string | null | undefined;
readonly native_finish_reason?: string | null | undefined;
}[] | null | undefined;
}, OpenAIChat.ParserState>;
export declare const route: Route<{
readonly model: string;
readonly messages: readonly ({
readonly role: "system";
readonly content: string | readonly ({
readonly type: "text";
readonly text: string;
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
} | {
readonly type: "image_url";
readonly image_url: {
readonly url: string;
};
})[];
} | {
readonly role: "user";
readonly content: string | readonly ({
readonly type: "text";
readonly text: string;
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
} | {
readonly type: "image_url";
readonly image_url: {
readonly url: string;
};
})[];
} | {
readonly [x: string]: unknown;
readonly content: string | null;
readonly role: "assistant";
readonly reasoning?: string | undefined;
readonly reasoning_content?: string | undefined;
readonly reasoning_text?: string | undefined;
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
readonly tool_calls?: readonly {
readonly id: string;
readonly type: "function";
readonly function: {
readonly name: string;
readonly arguments: string;
};
}[] | undefined;
readonly reasoning_details?: unknown;
} | {
readonly content: string;
readonly role: "tool";
readonly tool_call_id: string;
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
})[];
readonly stream: true;
readonly max_completion_tokens?: number | undefined;
readonly max_tokens?: number | undefined;
readonly tools?: readonly {
readonly function: {
readonly description: string;
readonly name: string;
readonly parameters: {
readonly [x: string]: unknown;
};
readonly strict?: boolean | undefined;
};
readonly type: "function";
readonly cache_control?: {
readonly type: "ephemeral";
readonly ttl?: string | undefined;
} | undefined;
}[] | undefined;
readonly stop?: readonly string[] | undefined;
readonly user?: string | undefined;
readonly temperature?: number | undefined;
readonly seed?: number | undefined;
readonly service_tier?: string | undefined;
readonly tool_choice?: "required" | "auto" | "none" | {
readonly type: "function";
readonly function: {
readonly name: string;
};
} | undefined;
readonly top_p?: number | undefined;
readonly store?: boolean | undefined;
readonly stream_options?: {
readonly include_usage: boolean;
} | undefined;
readonly prompt_cache_key?: string | undefined;
readonly reasoning_effort?: import("../protocols/utils/open-responses-options.js").ReasoningEffort | undefined;
readonly tool_stream?: boolean | undefined;
readonly frequency_penalty?: number | undefined;
readonly presence_penalty?: number | undefined;
readonly parallel_tool_calls?: boolean | undefined;
readonly reasoning_format?: "parsed" | undefined;
readonly include_reasoning?: boolean | undefined;
}, import("../route/transport/http.js").HttpPrepared<string>>;
export declare const configure: (input?: LanguageModelOptions) => {
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptions>;
configure: (input?: LanguageModelOptions) => /*elided*/ any;
};
export declare const provider: {
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptions>;
configure: (input?: LanguageModelOptions) => {
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ProviderOptions>;
configure: /*elided*/ any;
};
};
export declare const model: ProviderPackage.Definition<Settings, ProviderOptions>["model"];
export * as Groq from "./groq.js";
import { Effect, Schema } from "effect";
import { OpenAIChat } from "../protocols/openai-chat.js";
import { ProviderShared } from "../protocols/shared.js";
import { AuthOptions } from "../route/auth-options.js";
import { Route } from "../route/client.js";
import { Endpoint } from "../route/endpoint.js";
import { Framing } from "../route/framing.js";
import { Protocol } from "../route/protocol.js";
import { ProviderID } from "../schema/index.js";
import { profiles } from "./openai-compatible-profile.js";
export const id = ProviderID.make("groq");
const Options = Schema.Struct({
includeReasoning: Schema.optional(Schema.Boolean),
parallelToolCalls: Schema.optional(Schema.Boolean),
serviceTier: Schema.optional(Schema.String),
user: Schema.optional(Schema.String),
});
export const protocol = Protocol.make({
id: "groq-chat",
body: {
schema: Schema.Struct({
...OpenAIChat.bodyFields,
reasoning_format: Schema.optional(Schema.Literal("parsed")),
include_reasoning: Schema.optional(Schema.Boolean),
parallel_tool_calls: Schema.optional(Schema.Boolean),
service_tier: Schema.optional(Schema.String),
user: Schema.optional(Schema.String),
}),
from: Effect.fn("Groq.fromRequest")(function* (request) {
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
const gptOSS = request.model.id.startsWith("openai/gpt-oss-");
return {
...(yield* OpenAIChat.fromRequest(request)),
reasoning_format: gptOSS ? undefined : "parsed",
include_reasoning: gptOSS ? options.includeReasoning : undefined,
parallel_tool_calls: options.parallelToolCalls,
service_tier: options.serviceTier,
user: options.user,
};
}),
},
stream: OpenAIChat.protocol.stream,
});
export const route = Route.make({
id: "groq-chat",
provider: id,
providerMetadataKey: "openai",
protocol,
endpoint: Endpoint.path("/chat/completions", { baseURL: profiles.groq.baseURL }),
framing: Framing.sse,
});
export const configure = (input = {}) => {
const { apiKey: _apiKey, auth: _auth, baseURL, ...defaults } = input;
const configured = route.with({
...defaults,
endpoint: { baseURL: baseURL ?? profiles.groq.baseURL },
auth: AuthOptions.bearer(input, "GROQ_API_KEY"),
});
return {
id,
model: (modelID) => configured.model({
id: modelID,
compatibility: {
maxTokensField: "max_completion_tokens",
reasoningField: "reasoning",
requireReasoning: false,
supportsStore: false,
supportsStrictMode: false,
},
}),
configure,
};
};
export const provider = configure();
export const model = (modelID, settings) => configure({
apiKey: settings.apiKey,
baseURL: settings.baseURL,
headers: settings.headers === undefined ? undefined : { ...settings.headers },
http: settings.body === undefined ? undefined : { body: { ...settings.body } },
providerOptions: settings.providerOptions,
}).model(modelID);
export * as Groq from "./groq.js";
+6
-1

@@ -37,3 +37,8 @@ // Apply an `LLMRequest.cache` policy by injecting `CacheHint`s onto the parts

// whole policy pass for these — emitting hints would be harmless but pointless.
const RESPECTS_INLINE_HINTS = new Set(["anthropic-messages", "google-vertex-messages", "bedrock-converse", "openrouter"]);
const RESPECTS_INLINE_HINTS = new Set([
"anthropic-messages",
"google-vertex-messages",
"bedrock-converse",
"openrouter",
]);
const makeHint = (ttlSeconds) => ttlSeconds !== undefined ? new CacheHint({ type: "ephemeral", ttlSeconds }) : new CacheHint({ type: "ephemeral" });

@@ -40,0 +45,0 @@ const markLastTool = (tools, hint, budget) => {

+16
-6

@@ -181,3 +181,7 @@ import { Buffer } from "node:buffer";

}),
Schema.Struct({ type: Schema.tag("tool"), name: Schema.String, disable_parallel_tool_use: Schema.optional(Schema.Boolean) }),
Schema.Struct({
type: Schema.tag("tool"),
name: Schema.String,
disable_parallel_tool_use: Schema.optional(Schema.Boolean),
}),
]);

@@ -386,3 +390,7 @@ const AnthropicThinking = Schema.Union([

const payload = part.providerMetadata?.anthropic?.["result"] ?? part.result.value;
return { type: wireType, tool_use_id: scrubToolCallID(part.id), content: payload };
return {
type: wireType,
tool_use_id: scrubToolCallID(part.id),
content: payload,
};
});

@@ -759,3 +767,4 @@ const fileIdFromMetadata = (metadata) => {

const input = request.providerOptions;
const rawServiceTier = input?.service_tier ?? input?.serviceTier;
const rawServiceTier = input?.service_tier ??
input?.serviceTier;
const service_tier = rawServiceTier === "auto" || rawServiceTier === "standard_only"

@@ -765,4 +774,3 @@ ? rawServiceTier

const rawMetadata = input?.metadata;
const metadata = ProviderShared.isRecord(rawMetadata) &&
(typeof rawMetadata.user_id === "string" || rawMetadata.user_id === null)
const metadata = ProviderShared.isRecord(rawMetadata) && (typeof rawMetadata.user_id === "string" || rawMetadata.user_id === null)
? { user_id: rawMetadata.user_id }

@@ -1258,3 +1266,5 @@ : undefined;

protocol,
endpoint: Endpoint.path((input) => (input.request.model.provider === "anthropic" ? `${PATH}?beta=true` : PATH), { baseURL: DEFAULT_BASE_URL }),
endpoint: Endpoint.path((input) => (input.request.model.provider === "anthropic" ? `${PATH}?beta=true` : PATH), {
baseURL: DEFAULT_BASE_URL,
}),
auth: Auth.none,

@@ -1261,0 +1271,0 @@ framing,

@@ -511,3 +511,5 @@ import { Effect, Schema } from "effect";

reason: classifyProviderFailure({
message: event.exception.details.message ?? event.exception.details.originalMessage ?? "Bedrock Converse stream error",
message: event.exception.details.message ??
event.exception.details.originalMessage ??
"Bedrock Converse stream error",
code: event.exception.type,

@@ -514,0 +516,0 @@ }),

@@ -538,3 +538,5 @@ import { Effect, Option, Schema } from "effect";

input,
providerMetadata: part.thoughtSignature ? googleMetadata({ thoughtSignature: part.thoughtSignature }) : undefined,
providerMetadata: part.thoughtSignature
? googleMetadata({ thoughtSignature: part.thoughtSignature })
: undefined,
}));

@@ -541,0 +543,0 @@ hasToolCalls = true;

@@ -364,3 +364,6 @@ import { Effect, Schema } from "effect";

if (mistral)
return id.replace(/[^a-zA-Z0-9]/g, "").slice(0, 9).padEnd(9, "0");
return id
.replace(/[^a-zA-Z0-9]/g, "")
.slice(0, 9)
.padEnd(9, "0");
if (modelID.includes("claude"))

@@ -428,3 +431,4 @@ return id.replace(/[^a-zA-Z0-9_-]/g, "_");

}
if (message.role === "assistant" && message.content.every((part) => part.type === "text" && part.text.trim() === ""))
if (message.role === "assistant" &&
message.content.every((part) => part.type === "text" && part.text.trim() === ""))
continue;

@@ -578,4 +582,3 @@ if (message.role === "tool") {

const supportsStrictMode = request.model.compatibility?.supportsStrictMode ?? detectSupportsStrictMode(provider, baseURL);
const zaiToolStream = request.model.compatibility?.zaiToolStream ??
detectZaiToolStream(provider, baseURL, request.model.id);
const zaiToolStream = request.model.compatibility?.zaiToolStream ?? detectZaiToolStream(provider, baseURL, request.model.id);
const hasHistory = hasToolHistory(request.messages);

@@ -582,0 +585,0 @@ const hasActiveTools = request.tools.length > 0;

@@ -17,3 +17,5 @@ import { Option, Schema } from "effect";

export const ServiceTiers = ["auto", "default", "flex", "priority"];
export const ServiceTier = Schema.declare((value) => typeof value === "string", { title: "ServiceTier" });
export const ServiceTier = Schema.declare((value) => typeof value === "string", {
title: "ServiceTier",
});
export const Truncations = ["auto", "disabled"];

@@ -20,0 +22,0 @@ export const TextVerbositySchema = TextVerbosity;

@@ -15,2 +15,3 @@ export * as Anthropic from "./anthropic.js";

export * as GoogleVertexResponses from "./google-vertex-responses.js";
export * as Groq from "./groq.js";
export * as OpenAI from "./openai.js";

@@ -17,0 +18,0 @@ export * as OpenAICompatible from "./openai-compatible.js";

@@ -15,2 +15,3 @@ export * as Anthropic from "./anthropic.js";

export * as GoogleVertexResponses from "./google-vertex-responses.js";
export * as Groq from "./groq.js";
export * as OpenAI from "./openai.js";

@@ -17,0 +18,0 @@ export * as OpenAICompatible from "./openai-compatible.js";

{
"$schema": "https://json.schemastore.org/package.json",
"version": "0.0.0-beta-18286",
"version": "0.0.0-beta-18311",
"name": "@opencode-ai/ai",

@@ -33,3 +33,3 @@ "type": "module",

"@effect/platform-node": "4.0.0-rc.111",
"@opencode-ai/http-recorder": "0.0.0-beta-18286",
"@opencode-ai/http-recorder": "0.0.0-beta-18311",
"@tsconfig/bun": "1.0.9",

@@ -43,3 +43,3 @@ "@types/bun": "1.3.13",

"@smithy/util-utf8": "4.2.2",
"@opencode-ai/schema": "0.0.0-beta-18286",
"@opencode-ai/schema": "0.0.0-beta-18311",
"aws4fetch": "1.0.20",

@@ -46,0 +46,0 @@ "effect": "4.0.0-rc.111",