modality-ai 0.6.0 → 0.7.1

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,7 @@
1
+ /**
2
+ * Unit tests for Ollama V2 Adapter
3
+ *
4
+ * Tests the pure functions exported from src/provider/ollama-v2-adapter.ts.
5
+ * All tests import from the real source — no re-implementations.
6
+ */
7
+ export {};
@@ -2,5 +2,6 @@ export { createAIChat, mergeToolCallsAndResults, OllamaProvider, } from "./util_
2
2
  export { ModalityClient } from "./ModalityClient";
3
3
  export { setupStdioToHttpTools, createStdioClient, } from "./setupStdioToHttpTools";
4
4
  export type { ModalityClientInstance } from "./ModalityClient";
5
+ export type { ModelMessage } from "ai";
5
6
  export type { StdioClientOptions } from "./setupStdioToHttpTools";
6
7
  export { CLIBrowserOAuthProvider } from "./mcp-oauth-provider";
@@ -1,12 +1,85 @@
1
1
  /**
2
- * Ollama V2 Adapter
2
+ * Ollama Provider (V4 spec, native for ai@7.x)
3
3
  *
4
- * Clean V2-only adapter for ollama-ai-provider that converts V1 models to V2 interfaces.
5
- * This adapter ensures compatibility with AI SDK 5.0 by providing V2-compliant models.
4
+ * Standalone provider for Ollama that talks to the Ollama REST API directly
5
+ * (no `ollama-ai-provider` dependency). Implements the LanguageModelV4 and
6
+ * EmbeddingModelV4 specifications — the native spec for ai@7.x.
7
+ *
8
+ * API reference: https://github.com/ollama/ollama/blob/main/docs/api.md
9
+ * (message conversion modeled after https://github.com/sgomez/ollama-ai-provider)
10
+ */
11
+ import type { EmbeddingModelV4, LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4FinishReason, LanguageModelV4Prompt, LanguageModelV4Usage, SharedV4Warning } from "@ai-sdk/provider";
12
+ /**
13
+ * Ollama REST API wire types (subset used by this provider)
14
+ */
15
+ interface OllamaToolCall {
16
+ function: {
17
+ name: string;
18
+ arguments: unknown;
19
+ };
20
+ }
21
+ /** @internal exported for testing */
22
+ export interface OllamaMessage {
23
+ role: "system" | "user" | "assistant" | "tool";
24
+ content: string;
25
+ images?: string[];
26
+ tool_calls?: OllamaToolCall[];
27
+ }
28
+ /** @internal exported for testing */
29
+ export interface OllamaChatResponse {
30
+ model?: string;
31
+ created_at?: string;
32
+ message?: {
33
+ role?: string;
34
+ content?: string;
35
+ tool_calls?: OllamaToolCall[];
36
+ };
37
+ done?: boolean;
38
+ done_reason?: string;
39
+ prompt_eval_count?: number;
40
+ eval_count?: number;
41
+ error?: string;
42
+ }
43
+ /** @internal exported for testing */
44
+ export interface OllamaEmbedResponse {
45
+ embeddings: number[][];
46
+ prompt_eval_count?: number;
47
+ error?: string;
48
+ }
49
+ /**
50
+ * Accept both `http://host:11434` and `http://host:11434/api` forms.
51
+ * @internal exported for testing
52
+ */
53
+ export declare function normalizeBaseURL(baseURL?: string): string;
54
+ /** @internal exported for testing */
55
+ export declare function toBase64(data: Uint8Array | string | URL): string;
56
+ /**
57
+ * Safely parse JSON — returns `fallback` on failure instead of throwing.
58
+ * @internal exported for testing
59
+ */
60
+ export declare function safeParseJson(input: string, fallback?: unknown): unknown;
61
+ /** @internal exported for testing */
62
+ export declare function mapFinishReason(doneReason?: string): LanguageModelV4FinishReason;
63
+ /** @internal exported for testing */
64
+ export declare function mapUsage(response: OllamaChatResponse): LanguageModelV4Usage;
65
+ /**
66
+ * Convert an AI SDK V4 prompt into Ollama chat messages.
67
+ * @internal exported for testing
68
+ */
69
+ export declare function convertToOllamaMessages(prompt: LanguageModelV4Prompt): {
70
+ messages: OllamaMessage[];
71
+ warnings: SharedV4Warning[];
72
+ };
73
+ /**
74
+ * Convert AI SDK V4 call options into an Ollama /api/chat request body.
75
+ * @internal exported for testing
6
76
  */
7
- import type { LanguageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
77
+ export declare function buildChatRequest(modelId: string, options: LanguageModelV4CallOptions, stream: boolean): {
78
+ body: Record<string, unknown>;
79
+ warnings: SharedV4Warning[];
80
+ };
8
81
  /**
9
- * V2-compliant Ollama Provider
82
+ * Ollama Provider (V4 spec, native for ai@7.x)
10
83
  */
11
84
  export interface OllamaV2ProviderOptions {
12
85
  baseURL?: string;
@@ -14,18 +87,19 @@ export interface OllamaV2ProviderOptions {
14
87
  fetch?: typeof fetch;
15
88
  }
16
89
  export declare class OllamaV2Provider {
17
- private provider;
90
+ private context;
18
91
  constructor(options?: OllamaV2ProviderOptions);
19
92
  /**
20
- * Get V2-compliant language model
93
+ * Get language model
21
94
  */
22
- languageModel(modelId: string): LanguageModelV2;
95
+ languageModel(modelId: string): LanguageModelV4;
23
96
  /**
24
- * Get V2-compliant embedding model
97
+ * Get embedding model
25
98
  */
26
- embeddingModel<VALUE = string>(modelId: string): EmbeddingModelV2<VALUE>;
99
+ embeddingModel(modelId: string): EmbeddingModelV4;
27
100
  }
28
101
  /**
29
- * Create a V2-compliant Ollama provider
102
+ * Create an Ollama provider
30
103
  */
31
104
  export declare function createOllamaV2(options?: OllamaV2ProviderOptions): OllamaV2Provider;
105
+ export {};
@@ -3,9 +3,9 @@ export declare const DEFAULT_AI_PROVIDER = "gemini";
3
3
  export declare const OLLAMA_URL: string;
4
4
  export declare const chatMessageSchema: z.ZodObject<{
5
5
  role: z.ZodEnum<{
6
- user: "user";
7
6
  assistant: "assistant";
8
7
  system: "system";
8
+ user: "user";
9
9
  }>;
10
10
  content: z.ZodString;
11
11
  }, z.core.$strip>;
@@ -38,9 +38,9 @@ declare const chatOptionsSchema: z.ZodObject<{
38
38
  maxOutputTokens: z.ZodOptional<z.ZodNumber>;
39
39
  topP: z.ZodOptional<z.ZodNumber>;
40
40
  toolChoice: z.ZodOptional<z.ZodEnum<{
41
- required: "required";
42
41
  auto: "auto";
43
42
  none: "none";
43
+ required: "required";
44
44
  }>>;
45
45
  maxSteps: z.ZodOptional<z.ZodNumber>;
46
46
  }, z.core.$strip>;
@@ -54,8 +54,8 @@ export declare const simpleModalityAnswerSchema: z.ZodObject<{
54
54
  useMemory: z.ZodDefault<z.ZodBoolean>;
55
55
  }, z.core.$strip>;
56
56
  declare const providerEnum: z.ZodOptional<z.ZodEnum<{
57
- ollama: "ollama";
58
57
  gemini: "gemini";
58
+ ollama: "ollama";
59
59
  vscode: "vscode";
60
60
  }>>;
61
61
  export declare const modalityAnswerSchema: z.ZodObject<{
@@ -63,8 +63,8 @@ export declare const modalityAnswerSchema: z.ZodObject<{
63
63
  context: z.ZodOptional<z.ZodString>;
64
64
  useMemory: z.ZodDefault<z.ZodBoolean>;
65
65
  provider: z.ZodOptional<z.ZodEnum<{
66
- ollama: "ollama";
67
66
  gemini: "gemini";
67
+ ollama: "ollama";
68
68
  vscode: "vscode";
69
69
  }>>;
70
70
  ollama: z.ZodDefault<z.ZodOptional<z.ZodObject<{
@@ -84,9 +84,9 @@ export declare const modalityAnswerSchema: z.ZodObject<{
84
84
  maxOutputTokens: z.ZodOptional<z.ZodNumber>;
85
85
  topP: z.ZodOptional<z.ZodNumber>;
86
86
  toolChoice: z.ZodOptional<z.ZodEnum<{
87
- required: "required";
88
87
  auto: "auto";
89
88
  none: "none";
89
+ required: "required";
90
90
  }>>;
91
91
  maxSteps: z.ZodOptional<z.ZodNumber>;
92
92
  }, z.core.$strip>>>;
@@ -28,12 +28,8 @@ export declare const createAiModelMockModule: () => {
28
28
  OllamaProvider: typeof MockOllamaProvider;
29
29
  GeminiProvider: typeof MockGeminiProvider;
30
30
  AIChat: typeof MockAIChat;
31
- createOllamaChat: (_config: any) => {
32
- chat: () => Promise<never>;
33
- };
34
- createGeminiChat: (_config: any) => {
35
- chat: () => Promise<never>;
36
- };
31
+ createOllamaChat: typeof createMockOllamaChat;
32
+ createGeminiChat: typeof createMockGeminiChat;
37
33
  AIConfig: any;
38
34
  ChatOptions: any;
39
35
  ChatResponse: any;
@@ -97,5 +97,5 @@ export declare const MOCK_SCENARIOS: {
97
97
  /**
98
98
  * Client with custom responses
99
99
  */
100
- readonly CUSTOM_CLIENT: (responses: MockClientConfig["defaultResponses"]) => MockModalityClient;
100
+ readonly CUSTOM_CLIENT: (responses: MockClientConfig['defaultResponses']) => MockModalityClient;
101
101
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.0",
2
+ "version": "0.7.1",
3
3
  "name": "modality-ai",
4
4
  "repository": {
5
5
  "type": "git",
@@ -12,17 +12,16 @@
12
12
  "license": "ISC",
13
13
  "peerDependencies": {
14
14
  "@modelcontextprotocol/sdk": "^1.29.0",
15
- "modality-mcp-kit": "^1.6.2"
15
+ "modality-mcp-kit": "^2.0.2"
16
16
  },
17
17
  "dependencies": {
18
- "@ai-sdk/google": "^3.0.58",
19
- "ai": "^6.0.146",
20
- "ollama-ai-provider": "^1.2.0"
18
+ "@ai-sdk/google": "^4.0.10",
19
+ "ai": "^7.0.18"
21
20
  },
22
21
  "devDependencies": {
23
- "@types/bun": "^1.3.11",
24
- "modality-bun-kit": "^0.0.4",
25
- "typescript": "^6.0.2"
22
+ "@types/bun": "^1.3.14",
23
+ "modality-bun-kit": "^1.3.14",
24
+ "typescript": "^7.0.2"
26
25
  },
27
26
  "exports": {
28
27
  "types": "./dist/types/index.d.ts",