@jaypie/llm 1.3.11 → 1.3.12

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,151 @@
1
+ import { JsonObject, NaturalSchema } from "@jaypie/types";
2
+ import { z } from "zod/v4";
3
+ import { Toolkit } from "../../tools/Toolkit.class.js";
4
+ import { LlmHistory, LlmOperateOptions, LlmUsageItem } from "../../types/LlmProvider.interface.js";
5
+ import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
6
+ import { ClassifiedError, OperateRequest, ParsedResponse, ProviderToolDefinition, StandardToolCall, StandardToolResult } from "../types.js";
7
+ import { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
8
+ interface FireworksMessage {
9
+ role: "system" | "user" | "assistant" | "tool";
10
+ content?: string | FireworksContentPart[] | null;
11
+ toolCalls?: FireworksToolCall[];
12
+ toolCallId?: string;
13
+ }
14
+ interface FireworksToolCall {
15
+ id: string;
16
+ type: "function";
17
+ function: {
18
+ name: string;
19
+ arguments: string;
20
+ };
21
+ }
22
+ interface FireworksResponseMessage {
23
+ role: "assistant";
24
+ content?: string | null;
25
+ toolCalls?: FireworksToolCall[];
26
+ refusal?: string | null;
27
+ reasoning?: string | null;
28
+ reasoning_content?: string | null;
29
+ }
30
+ interface FireworksChoice {
31
+ index: number;
32
+ message: FireworksResponseMessage;
33
+ finishReason: string | null;
34
+ finish_reason?: string | null;
35
+ }
36
+ interface FireworksUsage {
37
+ promptTokens: number;
38
+ completionTokens: number;
39
+ totalTokens: number;
40
+ prompt_tokens?: number;
41
+ completion_tokens?: number;
42
+ total_tokens?: number;
43
+ completionTokensDetails?: {
44
+ reasoningTokens?: number;
45
+ };
46
+ }
47
+ interface FireworksResponse {
48
+ id: string;
49
+ object: string;
50
+ created: number;
51
+ model: string;
52
+ choices: FireworksChoice[];
53
+ usage?: FireworksUsage;
54
+ }
55
+ interface FireworksTool {
56
+ type: "function";
57
+ function: {
58
+ name: string;
59
+ description: string;
60
+ parameters: JsonObject;
61
+ };
62
+ }
63
+ interface FireworksJsonSchemaConfig {
64
+ name: string;
65
+ description?: string;
66
+ schema: JsonObject;
67
+ strict?: boolean;
68
+ }
69
+ type FireworksResponseFormat = {
70
+ type: "json_schema";
71
+ json_schema: FireworksJsonSchemaConfig;
72
+ } | {
73
+ type: "json_object";
74
+ } | {
75
+ type: "text";
76
+ };
77
+ interface FireworksRequest {
78
+ model: string;
79
+ messages: FireworksMessage[];
80
+ tools?: FireworksTool[];
81
+ tool_choice?: "auto" | "none" | "required";
82
+ response_format?: FireworksResponseFormat;
83
+ reasoning_effort?: string;
84
+ user?: string;
85
+ }
86
+ /**
87
+ * Fireworks content part types. Fireworks follows the OpenAI Chat Completions
88
+ * multimodal schema for `image_url` parts (URL or base64 data URI). There is
89
+ * no OpenAI-style `file` part, and the API rejects `data:` URIs for documents
90
+ * ("Unsupported URL scheme 'data'"), so file inputs cannot be delivered.
91
+ */
92
+ type FireworksContentPart = {
93
+ type: "text";
94
+ text: string;
95
+ } | {
96
+ type: "image_url";
97
+ imageUrl: {
98
+ url: string;
99
+ };
100
+ };
101
+ /**
102
+ * FireworksAdapter implements the ProviderAdapter interface for Fireworks AI's
103
+ * OpenAI-compatible Chat Completions API. It handles request building,
104
+ * response parsing, and error classification specific to Fireworks.
105
+ */
106
+ export declare class FireworksAdapter extends BaseProviderAdapter {
107
+ readonly name: "fireworks";
108
+ readonly defaultModel: string;
109
+ private runtimeNoStructuredOutputModels;
110
+ rememberModelRejectsStructuredOutput(model: string): void;
111
+ clearRuntimeNoStructuredOutputModels(): void;
112
+ private supportsStructuredOutput;
113
+ private runtimeNoTemperatureModels;
114
+ rememberModelRejectsTemperature(model: string): void;
115
+ clearRuntimeNoTemperatureModels(): void;
116
+ private supportsTemperature;
117
+ buildRequest(request: OperateRequest): FireworksRequest;
118
+ formatTools(toolkit: Toolkit, _outputSchema?: JsonObject): ProviderToolDefinition[];
119
+ formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
120
+ executeRequest(client: unknown, request: unknown, signal?: AbortSignal): Promise<FireworksResponse>;
121
+ /**
122
+ * Serialize the internal request into the OpenAI-compatible wire body for
123
+ * Fireworks' Chat Completions endpoint. Top-level fields (model, tools,
124
+ * tool_choice, response_format, reasoning_effort, user, temperature, and any
125
+ * providerOptions) are already wire-shaped (snake_case); only messages carry
126
+ * camelCase tool fields that must become snake_case on the wire.
127
+ */
128
+ private toWireBody;
129
+ /**
130
+ * Rebuild a structured-output request without `response_format`, swapping in
131
+ * the legacy fake-tool emulation. Used as a runtime fallback when a model
132
+ * rejects native json_schema.
133
+ */
134
+ private toFallbackStructuredOutputRequest;
135
+ executeStreamRequest(client: unknown, request: unknown, signal?: AbortSignal): AsyncIterable<LlmStreamChunk>;
136
+ parseResponse(response: unknown, _options?: LlmOperateOptions): ParsedResponse;
137
+ extractToolCalls(response: unknown): StandardToolCall[];
138
+ extractUsage(response: unknown, model: string): LlmUsageItem;
139
+ formatToolResult(toolCall: StandardToolCall, result: StandardToolResult): FireworksMessage;
140
+ appendToolResult(request: unknown, toolCall: StandardToolCall, result: StandardToolResult): FireworksRequest;
141
+ responseToHistoryItems(response: unknown): LlmHistory;
142
+ classifyError(error: unknown): ClassifiedError;
143
+ isComplete(response: unknown): boolean;
144
+ hasStructuredOutput(response: unknown): boolean;
145
+ extractStructuredOutput(response: unknown): JsonObject | undefined;
146
+ private hasToolCalls;
147
+ private extractContent;
148
+ private convertMessagesToFireworks;
149
+ }
150
+ export declare const fireworksAdapter: FireworksAdapter;
151
+ export {};
@@ -2,6 +2,7 @@ export { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
2
2
  export type { ProviderAdapter } from "./ProviderAdapter.interface.js";
3
3
  export { AnthropicAdapter, anthropicAdapter } from "./AnthropicAdapter.js";
4
4
  export { BedrockAdapter, bedrockAdapter } from "./BedrockAdapter.js";
5
+ export { FireworksAdapter, fireworksAdapter } from "./FireworksAdapter.js";
5
6
  export { GoogleAdapter, googleAdapter } from "./GoogleAdapter.js";
6
7
  export { OpenAiAdapter, openAiAdapter } from "./OpenAiAdapter.js";
7
8
  export { OpenRouterAdapter, openRouterAdapter } from "./OpenRouterAdapter.js";
@@ -1,4 +1,4 @@
1
- export { AnthropicAdapter, anthropicAdapter, BaseProviderAdapter, BedrockAdapter, bedrockAdapter, GoogleAdapter, googleAdapter, OpenAiAdapter, openAiAdapter, OpenRouterAdapter, openRouterAdapter, XaiAdapter, xaiAdapter, } from "./adapters/index.js";
1
+ export { AnthropicAdapter, anthropicAdapter, BaseProviderAdapter, BedrockAdapter, bedrockAdapter, FireworksAdapter, fireworksAdapter, GoogleAdapter, googleAdapter, OpenAiAdapter, openAiAdapter, OpenRouterAdapter, openRouterAdapter, XaiAdapter, xaiAdapter, } from "./adapters/index.js";
2
2
  export type { ProviderAdapter } from "./adapters/index.js";
3
3
  export { createOperateLoop, OperateLoop } from "./OperateLoop.js";
4
4
  export type { OperateLoopConfig } from "./OperateLoop.js";
@@ -0,0 +1,21 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ import { LlmHistory, LlmInputMessage, LlmMessageOptions, LlmOperateOptions, LlmOperateResponse, LlmProvider } from "../../types/LlmProvider.interface.js";
3
+ import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
4
+ export declare class FireworksProvider implements LlmProvider {
5
+ private model;
6
+ private _client?;
7
+ private _operateLoop?;
8
+ private _streamLoop?;
9
+ private apiKey?;
10
+ private log;
11
+ private conversationHistory;
12
+ constructor(model?: string, { apiKey }?: {
13
+ apiKey?: string;
14
+ });
15
+ private getClient;
16
+ private getOperateLoop;
17
+ private getStreamLoop;
18
+ send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
19
+ operate(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
20
+ stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
21
+ }
@@ -0,0 +1,37 @@
1
+ import { JsonObject } from "@jaypie/types";
2
+ export interface FireworksClientOptions {
3
+ apiKey: string;
4
+ baseURL?: string;
5
+ }
6
+ export interface ChatCompletionOptions {
7
+ signal?: AbortSignal;
8
+ }
9
+ /**
10
+ * HTTP error carrying the upstream status and parsed API message. The
11
+ * FireworksAdapter classifies errors by reading `.status` / `.statusCode` and
12
+ * `.message` / `.error.message`.
13
+ */
14
+ export declare class FireworksHttpError extends Error {
15
+ readonly status: number;
16
+ readonly statusCode: number;
17
+ readonly error?: {
18
+ message?: string;
19
+ };
20
+ constructor(status: number, message: string, error?: {
21
+ message?: string;
22
+ });
23
+ }
24
+ /**
25
+ * Minimal `fetch`-based client for Fireworks AI's OpenAI-compatible Chat
26
+ * Completions endpoint. The adapter only needs a single POST (streaming and
27
+ * non-streaming), header auth, and HTTP error surfacing.
28
+ */
29
+ export declare class FireworksClient {
30
+ private readonly apiKey;
31
+ private readonly baseURL;
32
+ constructor({ apiKey, baseURL, }: FireworksClientOptions);
33
+ private headers;
34
+ private toError;
35
+ chatCompletion(body: Record<string, unknown>, { signal }?: ChatCompletionOptions): Promise<JsonObject>;
36
+ streamChatCompletion(body: Record<string, unknown>, { signal }?: ChatCompletionOptions): AsyncIterable<JsonObject>;
37
+ }
@@ -0,0 +1,2 @@
1
+ export { FireworksProvider } from "./FireworksProvider.class.js";
2
+ export * from "./utils.js";
@@ -0,0 +1,15 @@
1
+ import { createLogger } from "@jaypie/logger";
2
+ import { LlmMessageOptions } from "../../types/LlmProvider.interface.js";
3
+ import { FireworksClient } from "./client.js";
4
+ export declare const getLogger: () => ReturnType<typeof createLogger>;
5
+ export declare function initializeClient({ apiKey, }?: {
6
+ apiKey?: string;
7
+ }): Promise<FireworksClient>;
8
+ export declare function getDefaultModel(): string;
9
+ export interface ChatMessage {
10
+ role: "system" | "user" | "assistant";
11
+ content: string;
12
+ }
13
+ export declare function formatSystemMessage(systemPrompt: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
14
+ export declare function formatUserMessage(message: string, { data, placeholders }?: Pick<LlmMessageOptions, "data" | "placeholders">): ChatMessage;
15
+ export declare function prepareMessages(message: string, { system, data, placeholders }?: LlmMessageOptions): ChatMessage[];
@@ -39,4 +39,5 @@ export declare function toXaiEffort(effort: LlmEffort): LlmEffortMapping;
39
39
  export declare function toAnthropicEffort(effort: LlmEffort): LlmEffortMapping;
40
40
  export declare function toGeminiThinkingLevel(effort: LlmEffort): LlmEffortMapping;
41
41
  export declare function toGeminiThinkingBudget(effort: LlmEffort): LlmEffortMapping<number>;
42
+ export declare function toFireworksEffort(effort: LlmEffort): LlmEffortMapping;
42
43
  export declare function toOpenRouterEffort(effort: LlmEffort): LlmEffortMapping;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/llm",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "Large language model utilities",
5
5
  "repository": {
6
6
  "type": "git",