@agentic-kit/ollama 1.0.3 → 1.2.0
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.
- package/README.md +47 -12
- package/esm/index.js +437 -99
- package/esm/package.json +1 -0
- package/index.d.ts +162 -9
- package/index.js +438 -101
- package/package.json +13 -5
package/index.d.ts
CHANGED
|
@@ -1,29 +1,182 @@
|
|
|
1
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
2
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
3
|
+
interface JsonObject {
|
|
4
|
+
[key: string]: JsonValue | undefined;
|
|
5
|
+
}
|
|
6
|
+
interface ModelDescriptor {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
api: string;
|
|
10
|
+
provider: string;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
input: Array<'text' | 'image'>;
|
|
13
|
+
reasoning: boolean;
|
|
14
|
+
tools?: boolean;
|
|
15
|
+
contextWindow?: number;
|
|
16
|
+
maxOutputTokens?: number;
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
interface TextContent {
|
|
20
|
+
type: 'text';
|
|
21
|
+
text: string;
|
|
22
|
+
}
|
|
23
|
+
interface ImageContent {
|
|
24
|
+
type: 'image';
|
|
25
|
+
data: string;
|
|
26
|
+
mimeType: string;
|
|
27
|
+
}
|
|
28
|
+
interface ThinkingContent {
|
|
29
|
+
type: 'thinking';
|
|
30
|
+
thinking: string;
|
|
31
|
+
}
|
|
32
|
+
interface ToolCallContent {
|
|
33
|
+
type: 'toolCall';
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
arguments: Record<string, JsonValue | undefined>;
|
|
37
|
+
}
|
|
38
|
+
interface Usage {
|
|
39
|
+
input: number;
|
|
40
|
+
output: number;
|
|
41
|
+
cacheRead: number;
|
|
42
|
+
cacheWrite: number;
|
|
43
|
+
totalTokens: number;
|
|
44
|
+
cost: {
|
|
45
|
+
input: number;
|
|
46
|
+
output: number;
|
|
47
|
+
cacheRead: number;
|
|
48
|
+
cacheWrite: number;
|
|
49
|
+
total: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
type Message = {
|
|
53
|
+
role: 'user';
|
|
54
|
+
content: string | Array<TextContent | ImageContent>;
|
|
55
|
+
timestamp: number;
|
|
56
|
+
} | {
|
|
57
|
+
role: 'assistant';
|
|
58
|
+
content: Array<TextContent | ThinkingContent | ToolCallContent>;
|
|
59
|
+
api: string;
|
|
60
|
+
provider: string;
|
|
61
|
+
model: string;
|
|
62
|
+
usage: Usage;
|
|
63
|
+
stopReason: 'stop' | 'length' | 'toolUse' | 'error' | 'aborted';
|
|
64
|
+
errorMessage?: string;
|
|
65
|
+
timestamp: number;
|
|
66
|
+
} | {
|
|
67
|
+
role: 'toolResult';
|
|
68
|
+
toolCallId: string;
|
|
69
|
+
toolName: string;
|
|
70
|
+
content: Array<TextContent | ImageContent>;
|
|
71
|
+
isError: boolean;
|
|
72
|
+
details?: unknown;
|
|
73
|
+
timestamp: number;
|
|
74
|
+
};
|
|
75
|
+
interface Context {
|
|
76
|
+
systemPrompt?: string;
|
|
77
|
+
messages: Message[];
|
|
78
|
+
}
|
|
79
|
+
interface StreamOptions {
|
|
80
|
+
maxTokens?: number;
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
temperature?: number;
|
|
83
|
+
}
|
|
84
|
+
type AssistantMessage = Extract<Message, {
|
|
85
|
+
role: 'assistant';
|
|
86
|
+
}>;
|
|
87
|
+
type AssistantMessageEvent = {
|
|
88
|
+
type: 'start';
|
|
89
|
+
partial: AssistantMessage;
|
|
90
|
+
} | {
|
|
91
|
+
type: 'text_start';
|
|
92
|
+
contentIndex: number;
|
|
93
|
+
partial: AssistantMessage;
|
|
94
|
+
} | {
|
|
95
|
+
type: 'text_delta';
|
|
96
|
+
contentIndex: number;
|
|
97
|
+
delta: string;
|
|
98
|
+
partial: AssistantMessage;
|
|
99
|
+
} | {
|
|
100
|
+
type: 'text_end';
|
|
101
|
+
contentIndex: number;
|
|
102
|
+
content: string;
|
|
103
|
+
partial: AssistantMessage;
|
|
104
|
+
} | {
|
|
105
|
+
type: 'thinking_start';
|
|
106
|
+
contentIndex: number;
|
|
107
|
+
partial: AssistantMessage;
|
|
108
|
+
} | {
|
|
109
|
+
type: 'thinking_delta';
|
|
110
|
+
contentIndex: number;
|
|
111
|
+
delta: string;
|
|
112
|
+
partial: AssistantMessage;
|
|
113
|
+
} | {
|
|
114
|
+
type: 'thinking_end';
|
|
115
|
+
contentIndex: number;
|
|
116
|
+
content: string;
|
|
117
|
+
partial: AssistantMessage;
|
|
118
|
+
} | {
|
|
119
|
+
type: 'toolcall_start';
|
|
120
|
+
contentIndex: number;
|
|
121
|
+
partial: AssistantMessage;
|
|
122
|
+
} | {
|
|
123
|
+
type: 'toolcall_delta';
|
|
124
|
+
contentIndex: number;
|
|
125
|
+
delta: string;
|
|
126
|
+
partial: AssistantMessage;
|
|
127
|
+
} | {
|
|
128
|
+
type: 'toolcall_end';
|
|
129
|
+
contentIndex: number;
|
|
130
|
+
toolCall: ToolCallContent;
|
|
131
|
+
partial: AssistantMessage;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'done';
|
|
134
|
+
reason: 'stop' | 'length' | 'toolUse';
|
|
135
|
+
message: AssistantMessage;
|
|
136
|
+
} | {
|
|
137
|
+
type: 'error';
|
|
138
|
+
reason: 'error' | 'aborted';
|
|
139
|
+
error: AssistantMessage;
|
|
140
|
+
};
|
|
141
|
+
interface AssistantMessageEventStream extends AsyncIterable<AssistantMessageEvent> {
|
|
142
|
+
result(): Promise<AssistantMessage>;
|
|
143
|
+
}
|
|
1
144
|
export interface ChatMessage {
|
|
2
145
|
role: 'system' | 'user' | 'assistant';
|
|
3
146
|
content: string;
|
|
4
147
|
}
|
|
5
148
|
export interface GenerateInput {
|
|
6
149
|
model: string;
|
|
7
|
-
/** Single-shot prompt — routes to /api/generate */
|
|
8
150
|
prompt?: string;
|
|
9
|
-
/** Multi-turn messages — routes to /api/chat (takes precedence over prompt) */
|
|
10
151
|
messages?: ChatMessage[];
|
|
11
|
-
/** System prompt — injected into /api/generate or prepended to /api/chat messages */
|
|
12
152
|
system?: string;
|
|
13
153
|
stream?: boolean;
|
|
14
154
|
temperature?: number;
|
|
15
155
|
maxTokens?: number;
|
|
16
156
|
}
|
|
17
|
-
export
|
|
18
|
-
|
|
157
|
+
export declare const OLLAMA_MODELS: ModelDescriptor[];
|
|
158
|
+
export declare class OllamaClient {
|
|
159
|
+
private readonly baseUrl;
|
|
19
160
|
constructor(baseUrl?: string);
|
|
20
161
|
listModels(): Promise<string[]>;
|
|
162
|
+
showModel(model: string): Promise<{
|
|
163
|
+
capabilities?: string[];
|
|
164
|
+
} | null>;
|
|
21
165
|
pullModel(model: string): Promise<void>;
|
|
22
166
|
deleteModel(model: string): Promise<void>;
|
|
167
|
+
generateEmbedding(text: string, model?: string): Promise<number[]>;
|
|
23
168
|
generate(input: GenerateInput): Promise<string>;
|
|
24
169
|
generate(input: GenerateInput, onChunk: (chunk: string) => void): Promise<void>;
|
|
25
|
-
generateEmbedding(text: string, model?: string): Promise<number[]>;
|
|
26
|
-
private _generate;
|
|
27
|
-
private _chat;
|
|
28
|
-
private _streamResponse;
|
|
29
170
|
}
|
|
171
|
+
export declare class OllamaAdapter {
|
|
172
|
+
readonly api = "ollama-native";
|
|
173
|
+
readonly provider = "ollama";
|
|
174
|
+
readonly name = "ollama";
|
|
175
|
+
private readonly client;
|
|
176
|
+
private readonly baseUrl;
|
|
177
|
+
constructor(baseUrl?: string);
|
|
178
|
+
createModel(modelId: string, overrides?: Partial<ModelDescriptor>): ModelDescriptor;
|
|
179
|
+
listModels(): Promise<Array<ModelDescriptor | string>>;
|
|
180
|
+
stream(model: ModelDescriptor, context: Context, options?: StreamOptions): AssistantMessageEventStream;
|
|
181
|
+
}
|
|
182
|
+
export default OllamaClient;
|