@agentic-kit/ollama 2.0.0 โ 2.1.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/LICENSE +3 -2
- package/README.md +41 -3
- package/esm/index.js +1 -105
- package/index.d.ts +1 -150
- package/index.js +16 -120
- package/package.json +8 -16
- package/esm/package.json +0 -1
package/LICENSE
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
MIT License
|
|
1
|
+
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
4
|
Copyright (c) 2025 Constructive <developers@constructive.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
5
6
|
|
|
6
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
8
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -19,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
19
20
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
21
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
SOFTWARE.
|
|
23
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -130,11 +130,30 @@ Please open issues or pull requests on [GitHub](https://github.com/constructive-
|
|
|
130
130
|
|
|
131
131
|
---
|
|
132
132
|
|
|
133
|
-
##
|
|
133
|
+
## Education and Tutorials
|
|
134
|
+
|
|
135
|
+
1. ๐ [Quickstart: Getting Up and Running](https://constructive.io/learn/quickstart)
|
|
136
|
+
Get started with modular databases in minutes. Install prerequisites and deploy your first module.
|
|
137
|
+
|
|
138
|
+
2. ๐ฆ [Modular PostgreSQL Development with Database Packages](https://constructive.io/learn/modular-postgres)
|
|
139
|
+
Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
|
|
140
|
+
|
|
141
|
+
3. โ๏ธ [Authoring Database Changes](https://constructive.io/learn/authoring-database-changes)
|
|
142
|
+
Master the workflow for adding, organizing, and managing database changes with pgpm.
|
|
134
143
|
|
|
135
|
-
|
|
144
|
+
4. ๐งช [End-to-End PostgreSQL Testing with TypeScript](https://constructive.io/learn/e2e-postgres-testing)
|
|
145
|
+
Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
|
|
136
146
|
|
|
137
|
-
|
|
147
|
+
5. โก [Supabase Testing](https://constructive.io/learn/supabase)
|
|
148
|
+
Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
|
|
149
|
+
|
|
150
|
+
6. ๐ง [Drizzle ORM Testing](https://constructive.io/learn/drizzle-testing)
|
|
151
|
+
Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
|
|
152
|
+
|
|
153
|
+
7. ๐ง [Troubleshooting](https://constructive.io/learn/troubleshooting)
|
|
154
|
+
Common issues and solutions for pgpm, PostgreSQL, and testing.
|
|
155
|
+
|
|
156
|
+
## Related Constructive Tooling
|
|
138
157
|
|
|
139
158
|
### ๐ฆ Package Management
|
|
140
159
|
|
|
@@ -145,14 +164,33 @@ Please open issues or pull requests on [GitHub](https://github.com/constructive-
|
|
|
145
164
|
* [pgsql-test](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-test): **๐ Isolated testing environments** with per-test transaction rollbacksโideal for integration tests, complex migrations, and RLS simulation.
|
|
146
165
|
* [pgsql-seed](https://github.com/constructive-io/constructive/tree/main/postgres/pgsql-seed): **๐ฑ PostgreSQL seeding utilities** for CSV, JSON, SQL data loading, and pgpm deployment.
|
|
147
166
|
* [supabase-test](https://github.com/constructive-io/constructive/tree/main/postgres/supabase-test): **๐งช Supabase-native test harness** preconfigured for the local Supabase stackโper-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
|
|
167
|
+
* [graphile-test](https://github.com/constructive-io/constructive/tree/main/graphile/graphile-test): **๐ Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
|
|
168
|
+
* [pg-query-context](https://github.com/constructive-io/constructive/tree/main/postgres/pg-query-context): **๐ Session context injection** to add session-local context (e.g., `SET LOCAL`) into queriesโideal for setting `role`, `jwt.claims`, and other session settings.
|
|
148
169
|
|
|
149
170
|
### ๐ง Parsing & AST
|
|
150
171
|
|
|
151
172
|
* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): **๐ SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
152
173
|
* [libpg-query-node](https://www.npmjs.com/package/libpg-query): **๐ Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
174
|
+
* [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): **๐ฆ Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
|
|
175
|
+
* [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): **๐ท๏ธ TypeScript enums** for PostgreSQL AST for safe and ergonomic parsing logic.
|
|
153
176
|
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): **๐ Type definitions** for PostgreSQL AST nodes in TypeScript.
|
|
154
177
|
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): **๐ ๏ธ AST utilities** for constructing and transforming PostgreSQL syntax trees.
|
|
155
178
|
|
|
179
|
+
### ๐ Documentation & Skills
|
|
180
|
+
|
|
181
|
+
* [constructive-skills](https://github.com/constructive-io/constructive-skills): **๐ Platform documentation and AI agent skills** โ feature catalog, blueprint reference, SDK guides (i18n, billing, limits, events, uploads, security, entities, search, AI), and deployment guides.
|
|
182
|
+
|
|
183
|
+
Install skills for AI coding agents:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# All platform skills (security, blueprints, codegen, billing, etc.)
|
|
187
|
+
npx skills add constructive-io/constructive-skills
|
|
188
|
+
|
|
189
|
+
# Individual repo skills (pgpm, testing, CLI, search, etc.)
|
|
190
|
+
npx skills add https://github.com/constructive-io/constructive --skill pgpm
|
|
191
|
+
npx skills add https://github.com/constructive-io/constructive --skill constructive-testing
|
|
192
|
+
```
|
|
193
|
+
|
|
156
194
|
## Credits
|
|
157
195
|
|
|
158
196
|
**๐ Built by the [Constructive](https://constructive.io) team โ creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
|
package/esm/index.js
CHANGED
|
@@ -1,78 +1,5 @@
|
|
|
1
|
+
import { calculateUsageCost, clone, createAssistantMessage, DefaultAssistantMessageEventStream, } from '@agentic-kit/protocol';
|
|
1
2
|
const fetch = globalThis.fetch.bind(globalThis);
|
|
2
|
-
class EventStream {
|
|
3
|
-
isTerminal;
|
|
4
|
-
extractResult;
|
|
5
|
-
queue = [];
|
|
6
|
-
waiting = [];
|
|
7
|
-
done = false;
|
|
8
|
-
finalResultPromise;
|
|
9
|
-
resolveFinalResult;
|
|
10
|
-
constructor(isTerminal, extractResult) {
|
|
11
|
-
this.isTerminal = isTerminal;
|
|
12
|
-
this.extractResult = extractResult;
|
|
13
|
-
this.finalResultPromise = new Promise((resolve) => {
|
|
14
|
-
this.resolveFinalResult = resolve;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
push(event) {
|
|
18
|
-
if (this.done) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (this.isTerminal(event)) {
|
|
22
|
-
this.done = true;
|
|
23
|
-
this.resolveFinalResult(this.extractResult(event));
|
|
24
|
-
}
|
|
25
|
-
const waiter = this.waiting.shift();
|
|
26
|
-
if (waiter) {
|
|
27
|
-
waiter({ value: event, done: false });
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
this.queue.push(event);
|
|
31
|
-
}
|
|
32
|
-
end(result) {
|
|
33
|
-
this.done = true;
|
|
34
|
-
if (result !== undefined) {
|
|
35
|
-
this.resolveFinalResult(result);
|
|
36
|
-
}
|
|
37
|
-
while (this.waiting.length > 0) {
|
|
38
|
-
this.waiting.shift()({ value: undefined, done: true });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async *[Symbol.asyncIterator]() {
|
|
42
|
-
while (true) {
|
|
43
|
-
if (this.queue.length > 0) {
|
|
44
|
-
yield this.queue.shift();
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
if (this.done) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const next = await new Promise((resolve) => {
|
|
51
|
-
this.waiting.push(resolve);
|
|
52
|
-
});
|
|
53
|
-
if (next.done) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
yield next.value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
result() {
|
|
60
|
-
return this.finalResultPromise;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
class DefaultAssistantMessageEventStream extends EventStream {
|
|
64
|
-
constructor() {
|
|
65
|
-
super((event) => event.type === 'done' || event.type === 'error', (event) => {
|
|
66
|
-
if (event.type === 'done') {
|
|
67
|
-
return event.message;
|
|
68
|
-
}
|
|
69
|
-
if (event.type === 'error') {
|
|
70
|
-
return event.error;
|
|
71
|
-
}
|
|
72
|
-
throw new Error('Unexpected terminal event');
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
3
|
export const OLLAMA_MODELS = [];
|
|
77
4
|
export class OllamaClient {
|
|
78
5
|
baseUrl;
|
|
@@ -405,34 +332,6 @@ function toOllamaMessages(context) {
|
|
|
405
332
|
}
|
|
406
333
|
return messages;
|
|
407
334
|
}
|
|
408
|
-
function createAssistantMessage(model) {
|
|
409
|
-
return {
|
|
410
|
-
role: 'assistant',
|
|
411
|
-
api: model.api,
|
|
412
|
-
provider: model.provider,
|
|
413
|
-
model: model.id,
|
|
414
|
-
content: [],
|
|
415
|
-
usage: {
|
|
416
|
-
input: 0,
|
|
417
|
-
output: 0,
|
|
418
|
-
reasoning: 0,
|
|
419
|
-
cacheRead: 0,
|
|
420
|
-
cacheWrite: 0,
|
|
421
|
-
totalTokens: 0,
|
|
422
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
423
|
-
},
|
|
424
|
-
stopReason: 'stop',
|
|
425
|
-
timestamp: Date.now(),
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
function calculateUsageCost(model, usage) {
|
|
429
|
-
usage.cost.input = ((model.cost?.input ?? 0) / 1_000_000) * usage.input;
|
|
430
|
-
usage.cost.output = ((model.cost?.output ?? 0) / 1_000_000) * usage.output;
|
|
431
|
-
usage.cost.cacheRead = ((model.cost?.cacheRead ?? 0) / 1_000_000) * usage.cacheRead;
|
|
432
|
-
usage.cost.cacheWrite = ((model.cost?.cacheWrite ?? 0) / 1_000_000) * usage.cacheWrite;
|
|
433
|
-
usage.cost.total =
|
|
434
|
-
usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
435
|
-
}
|
|
436
335
|
function legacyInputToContext(input) {
|
|
437
336
|
const messages = input.messages
|
|
438
337
|
? input.messages
|
|
@@ -467,9 +366,6 @@ function legacyInputToContext(input) {
|
|
|
467
366
|
messages,
|
|
468
367
|
};
|
|
469
368
|
}
|
|
470
|
-
function clone(value) {
|
|
471
|
-
return JSON.parse(JSON.stringify(value));
|
|
472
|
-
}
|
|
473
369
|
async function* iterateResponseBody(body) {
|
|
474
370
|
if ('getReader' in body && typeof body.getReader === 'function') {
|
|
475
371
|
const reader = body.getReader();
|
package/index.d.ts
CHANGED
|
@@ -1,153 +1,4 @@
|
|
|
1
|
-
type
|
|
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
|
-
cost?: {
|
|
18
|
-
input?: number;
|
|
19
|
-
output?: number;
|
|
20
|
-
cacheRead?: number;
|
|
21
|
-
cacheWrite?: number;
|
|
22
|
-
};
|
|
23
|
-
headers?: Record<string, string>;
|
|
24
|
-
}
|
|
25
|
-
interface TextContent {
|
|
26
|
-
type: 'text';
|
|
27
|
-
text: string;
|
|
28
|
-
}
|
|
29
|
-
interface ImageContent {
|
|
30
|
-
type: 'image';
|
|
31
|
-
data: string;
|
|
32
|
-
mimeType: string;
|
|
33
|
-
}
|
|
34
|
-
interface ThinkingContent {
|
|
35
|
-
type: 'thinking';
|
|
36
|
-
thinking: string;
|
|
37
|
-
}
|
|
38
|
-
interface ToolCallContent {
|
|
39
|
-
type: 'toolCall';
|
|
40
|
-
id: string;
|
|
41
|
-
name: string;
|
|
42
|
-
arguments: Record<string, JsonValue | undefined>;
|
|
43
|
-
}
|
|
44
|
-
interface Usage {
|
|
45
|
-
input: number;
|
|
46
|
-
output: number;
|
|
47
|
-
reasoning: number;
|
|
48
|
-
cacheRead: number;
|
|
49
|
-
cacheWrite: number;
|
|
50
|
-
totalTokens: number;
|
|
51
|
-
cost: {
|
|
52
|
-
input: number;
|
|
53
|
-
output: number;
|
|
54
|
-
cacheRead: number;
|
|
55
|
-
cacheWrite: number;
|
|
56
|
-
total: number;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
type Message = {
|
|
60
|
-
role: 'user';
|
|
61
|
-
content: string | Array<TextContent | ImageContent>;
|
|
62
|
-
timestamp: number;
|
|
63
|
-
} | {
|
|
64
|
-
role: 'assistant';
|
|
65
|
-
content: Array<TextContent | ThinkingContent | ToolCallContent>;
|
|
66
|
-
api: string;
|
|
67
|
-
provider: string;
|
|
68
|
-
model: string;
|
|
69
|
-
usage: Usage;
|
|
70
|
-
stopReason: 'stop' | 'length' | 'toolUse' | 'error' | 'aborted';
|
|
71
|
-
errorMessage?: string;
|
|
72
|
-
timestamp: number;
|
|
73
|
-
} | {
|
|
74
|
-
role: 'toolResult';
|
|
75
|
-
toolCallId: string;
|
|
76
|
-
toolName: string;
|
|
77
|
-
content: Array<TextContent | ImageContent>;
|
|
78
|
-
isError: boolean;
|
|
79
|
-
details?: unknown;
|
|
80
|
-
timestamp: number;
|
|
81
|
-
};
|
|
82
|
-
interface Context {
|
|
83
|
-
systemPrompt?: string;
|
|
84
|
-
messages: Message[];
|
|
85
|
-
}
|
|
86
|
-
interface StreamOptions {
|
|
87
|
-
maxTokens?: number;
|
|
88
|
-
signal?: AbortSignal;
|
|
89
|
-
temperature?: number;
|
|
90
|
-
}
|
|
91
|
-
type AssistantMessage = Extract<Message, {
|
|
92
|
-
role: 'assistant';
|
|
93
|
-
}>;
|
|
94
|
-
type AssistantMessageEvent = {
|
|
95
|
-
type: 'start';
|
|
96
|
-
partial: AssistantMessage;
|
|
97
|
-
} | {
|
|
98
|
-
type: 'text_start';
|
|
99
|
-
contentIndex: number;
|
|
100
|
-
partial: AssistantMessage;
|
|
101
|
-
} | {
|
|
102
|
-
type: 'text_delta';
|
|
103
|
-
contentIndex: number;
|
|
104
|
-
delta: string;
|
|
105
|
-
partial: AssistantMessage;
|
|
106
|
-
} | {
|
|
107
|
-
type: 'text_end';
|
|
108
|
-
contentIndex: number;
|
|
109
|
-
content: string;
|
|
110
|
-
partial: AssistantMessage;
|
|
111
|
-
} | {
|
|
112
|
-
type: 'thinking_start';
|
|
113
|
-
contentIndex: number;
|
|
114
|
-
partial: AssistantMessage;
|
|
115
|
-
} | {
|
|
116
|
-
type: 'thinking_delta';
|
|
117
|
-
contentIndex: number;
|
|
118
|
-
delta: string;
|
|
119
|
-
partial: AssistantMessage;
|
|
120
|
-
} | {
|
|
121
|
-
type: 'thinking_end';
|
|
122
|
-
contentIndex: number;
|
|
123
|
-
content: string;
|
|
124
|
-
partial: AssistantMessage;
|
|
125
|
-
} | {
|
|
126
|
-
type: 'toolcall_start';
|
|
127
|
-
contentIndex: number;
|
|
128
|
-
partial: AssistantMessage;
|
|
129
|
-
} | {
|
|
130
|
-
type: 'toolcall_delta';
|
|
131
|
-
contentIndex: number;
|
|
132
|
-
delta: string;
|
|
133
|
-
partial: AssistantMessage;
|
|
134
|
-
} | {
|
|
135
|
-
type: 'toolcall_end';
|
|
136
|
-
contentIndex: number;
|
|
137
|
-
toolCall: ToolCallContent;
|
|
138
|
-
partial: AssistantMessage;
|
|
139
|
-
} | {
|
|
140
|
-
type: 'done';
|
|
141
|
-
reason: 'stop' | 'length' | 'toolUse';
|
|
142
|
-
message: AssistantMessage;
|
|
143
|
-
} | {
|
|
144
|
-
type: 'error';
|
|
145
|
-
reason: 'error' | 'aborted';
|
|
146
|
-
error: AssistantMessage;
|
|
147
|
-
};
|
|
148
|
-
interface AssistantMessageEventStream extends AsyncIterable<AssistantMessageEvent> {
|
|
149
|
-
result(): Promise<AssistantMessage>;
|
|
150
|
-
}
|
|
1
|
+
import { type AssistantMessageEventStream, type Context, type ModelDescriptor, type StreamOptions } from '@agentic-kit/protocol';
|
|
151
2
|
export interface ChatMessage {
|
|
152
3
|
role: 'system' | 'user' | 'assistant';
|
|
153
4
|
content: string;
|
package/index.js
CHANGED
|
@@ -1,81 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OllamaAdapter = exports.OllamaClient = exports.OLLAMA_MODELS = void 0;
|
|
4
|
+
const protocol_1 = require("@agentic-kit/protocol");
|
|
4
5
|
const fetch = globalThis.fetch.bind(globalThis);
|
|
5
|
-
class EventStream {
|
|
6
|
-
isTerminal;
|
|
7
|
-
extractResult;
|
|
8
|
-
queue = [];
|
|
9
|
-
waiting = [];
|
|
10
|
-
done = false;
|
|
11
|
-
finalResultPromise;
|
|
12
|
-
resolveFinalResult;
|
|
13
|
-
constructor(isTerminal, extractResult) {
|
|
14
|
-
this.isTerminal = isTerminal;
|
|
15
|
-
this.extractResult = extractResult;
|
|
16
|
-
this.finalResultPromise = new Promise((resolve) => {
|
|
17
|
-
this.resolveFinalResult = resolve;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
push(event) {
|
|
21
|
-
if (this.done) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (this.isTerminal(event)) {
|
|
25
|
-
this.done = true;
|
|
26
|
-
this.resolveFinalResult(this.extractResult(event));
|
|
27
|
-
}
|
|
28
|
-
const waiter = this.waiting.shift();
|
|
29
|
-
if (waiter) {
|
|
30
|
-
waiter({ value: event, done: false });
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
this.queue.push(event);
|
|
34
|
-
}
|
|
35
|
-
end(result) {
|
|
36
|
-
this.done = true;
|
|
37
|
-
if (result !== undefined) {
|
|
38
|
-
this.resolveFinalResult(result);
|
|
39
|
-
}
|
|
40
|
-
while (this.waiting.length > 0) {
|
|
41
|
-
this.waiting.shift()({ value: undefined, done: true });
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async *[Symbol.asyncIterator]() {
|
|
45
|
-
while (true) {
|
|
46
|
-
if (this.queue.length > 0) {
|
|
47
|
-
yield this.queue.shift();
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (this.done) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const next = await new Promise((resolve) => {
|
|
54
|
-
this.waiting.push(resolve);
|
|
55
|
-
});
|
|
56
|
-
if (next.done) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
yield next.value;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
result() {
|
|
63
|
-
return this.finalResultPromise;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
class DefaultAssistantMessageEventStream extends EventStream {
|
|
67
|
-
constructor() {
|
|
68
|
-
super((event) => event.type === 'done' || event.type === 'error', (event) => {
|
|
69
|
-
if (event.type === 'done') {
|
|
70
|
-
return event.message;
|
|
71
|
-
}
|
|
72
|
-
if (event.type === 'error') {
|
|
73
|
-
return event.error;
|
|
74
|
-
}
|
|
75
|
-
throw new Error('Unexpected terminal event');
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
6
|
exports.OLLAMA_MODELS = [];
|
|
80
7
|
class OllamaClient {
|
|
81
8
|
baseUrl;
|
|
@@ -200,8 +127,8 @@ class OllamaAdapter {
|
|
|
200
127
|
return this.client.generateEmbedding(text, model);
|
|
201
128
|
}
|
|
202
129
|
stream(model, context, options) {
|
|
203
|
-
const stream = new DefaultAssistantMessageEventStream();
|
|
204
|
-
const output = createAssistantMessage(model);
|
|
130
|
+
const stream = new protocol_1.DefaultAssistantMessageEventStream();
|
|
131
|
+
const output = (0, protocol_1.createAssistantMessage)(model);
|
|
205
132
|
void (async () => {
|
|
206
133
|
const body = {
|
|
207
134
|
model: model.id,
|
|
@@ -225,7 +152,7 @@ class OllamaAdapter {
|
|
|
225
152
|
const text = await response.text().catch(() => '');
|
|
226
153
|
throw new Error(`Ollama error ${response.status}: ${text}`);
|
|
227
154
|
}
|
|
228
|
-
stream.push({ type: 'start', partial: clone(output) });
|
|
155
|
+
stream.push({ type: 'start', partial: (0, protocol_1.clone)(output) });
|
|
229
156
|
if (!response.body) {
|
|
230
157
|
throw new Error('No response body');
|
|
231
158
|
}
|
|
@@ -242,7 +169,7 @@ class OllamaAdapter {
|
|
|
242
169
|
stream.push({
|
|
243
170
|
type: 'thinking_start',
|
|
244
171
|
contentIndex: thinkingIndex,
|
|
245
|
-
partial: clone(output),
|
|
172
|
+
partial: (0, protocol_1.clone)(output),
|
|
246
173
|
});
|
|
247
174
|
}
|
|
248
175
|
const block = output.content[thinkingIndex];
|
|
@@ -251,14 +178,14 @@ class OllamaAdapter {
|
|
|
251
178
|
type: 'thinking_delta',
|
|
252
179
|
contentIndex: thinkingIndex,
|
|
253
180
|
delta: thinking,
|
|
254
|
-
partial: clone(output),
|
|
181
|
+
partial: (0, protocol_1.clone)(output),
|
|
255
182
|
});
|
|
256
183
|
}
|
|
257
184
|
const text = payload.message?.content ?? payload.response ?? '';
|
|
258
185
|
if (text) {
|
|
259
186
|
if (textIndex === undefined) {
|
|
260
187
|
textIndex = output.content.push({ type: 'text', text: '' }) - 1;
|
|
261
|
-
stream.push({ type: 'text_start', contentIndex: textIndex, partial: clone(output) });
|
|
188
|
+
stream.push({ type: 'text_start', contentIndex: textIndex, partial: (0, protocol_1.clone)(output) });
|
|
262
189
|
}
|
|
263
190
|
const block = output.content[textIndex];
|
|
264
191
|
block.text += text;
|
|
@@ -266,7 +193,7 @@ class OllamaAdapter {
|
|
|
266
193
|
type: 'text_delta',
|
|
267
194
|
contentIndex: textIndex,
|
|
268
195
|
delta: text,
|
|
269
|
-
partial: clone(output),
|
|
196
|
+
partial: (0, protocol_1.clone)(output),
|
|
270
197
|
});
|
|
271
198
|
}
|
|
272
199
|
if (!payload.done) {
|
|
@@ -275,14 +202,14 @@ class OllamaAdapter {
|
|
|
275
202
|
output.usage.input = payload.prompt_eval_count ?? output.usage.input;
|
|
276
203
|
output.usage.output = payload.eval_count ?? output.usage.output;
|
|
277
204
|
output.usage.totalTokens = output.usage.input + output.usage.output;
|
|
278
|
-
calculateUsageCost(model, output.usage);
|
|
205
|
+
(0, protocol_1.calculateUsageCost)(model, output.usage);
|
|
279
206
|
output.stopReason = payload.done_reason === 'length' ? 'length' : 'stop';
|
|
280
207
|
if (thinkingIndex !== undefined) {
|
|
281
208
|
stream.push({
|
|
282
209
|
type: 'thinking_end',
|
|
283
210
|
contentIndex: thinkingIndex,
|
|
284
211
|
content: output.content[thinkingIndex].thinking,
|
|
285
|
-
partial: clone(output),
|
|
212
|
+
partial: (0, protocol_1.clone)(output),
|
|
286
213
|
});
|
|
287
214
|
}
|
|
288
215
|
if (textIndex !== undefined) {
|
|
@@ -290,13 +217,13 @@ class OllamaAdapter {
|
|
|
290
217
|
type: 'text_end',
|
|
291
218
|
contentIndex: textIndex,
|
|
292
219
|
content: output.content[textIndex].text,
|
|
293
|
-
partial: clone(output),
|
|
220
|
+
partial: (0, protocol_1.clone)(output),
|
|
294
221
|
});
|
|
295
222
|
}
|
|
296
223
|
stream.push({
|
|
297
224
|
type: 'done',
|
|
298
225
|
reason: output.stopReason === 'length' ? 'length' : 'stop',
|
|
299
|
-
message: clone(output),
|
|
226
|
+
message: (0, protocol_1.clone)(output),
|
|
300
227
|
});
|
|
301
228
|
stream.end(output);
|
|
302
229
|
finished = true;
|
|
@@ -329,7 +256,7 @@ class OllamaAdapter {
|
|
|
329
256
|
type: 'thinking_end',
|
|
330
257
|
contentIndex: thinkingIndex,
|
|
331
258
|
content: output.content[thinkingIndex].thinking,
|
|
332
|
-
partial: clone(output),
|
|
259
|
+
partial: (0, protocol_1.clone)(output),
|
|
333
260
|
});
|
|
334
261
|
}
|
|
335
262
|
if (textIndex !== undefined) {
|
|
@@ -337,13 +264,13 @@ class OllamaAdapter {
|
|
|
337
264
|
type: 'text_end',
|
|
338
265
|
contentIndex: textIndex,
|
|
339
266
|
content: output.content[textIndex].text,
|
|
340
|
-
partial: clone(output),
|
|
267
|
+
partial: (0, protocol_1.clone)(output),
|
|
341
268
|
});
|
|
342
269
|
}
|
|
343
270
|
stream.push({
|
|
344
271
|
type: 'done',
|
|
345
272
|
reason: output.stopReason === 'length' ? 'length' : 'stop',
|
|
346
|
-
message: clone(output),
|
|
273
|
+
message: (0, protocol_1.clone)(output),
|
|
347
274
|
});
|
|
348
275
|
stream.end(output);
|
|
349
276
|
}
|
|
@@ -353,7 +280,7 @@ class OllamaAdapter {
|
|
|
353
280
|
stream.push({
|
|
354
281
|
type: 'error',
|
|
355
282
|
reason: output.stopReason === 'aborted' ? 'aborted' : 'error',
|
|
356
|
-
error: clone(output),
|
|
283
|
+
error: (0, protocol_1.clone)(output),
|
|
357
284
|
});
|
|
358
285
|
stream.end(output);
|
|
359
286
|
}
|
|
@@ -410,34 +337,6 @@ function toOllamaMessages(context) {
|
|
|
410
337
|
}
|
|
411
338
|
return messages;
|
|
412
339
|
}
|
|
413
|
-
function createAssistantMessage(model) {
|
|
414
|
-
return {
|
|
415
|
-
role: 'assistant',
|
|
416
|
-
api: model.api,
|
|
417
|
-
provider: model.provider,
|
|
418
|
-
model: model.id,
|
|
419
|
-
content: [],
|
|
420
|
-
usage: {
|
|
421
|
-
input: 0,
|
|
422
|
-
output: 0,
|
|
423
|
-
reasoning: 0,
|
|
424
|
-
cacheRead: 0,
|
|
425
|
-
cacheWrite: 0,
|
|
426
|
-
totalTokens: 0,
|
|
427
|
-
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
428
|
-
},
|
|
429
|
-
stopReason: 'stop',
|
|
430
|
-
timestamp: Date.now(),
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
function calculateUsageCost(model, usage) {
|
|
434
|
-
usage.cost.input = ((model.cost?.input ?? 0) / 1_000_000) * usage.input;
|
|
435
|
-
usage.cost.output = ((model.cost?.output ?? 0) / 1_000_000) * usage.output;
|
|
436
|
-
usage.cost.cacheRead = ((model.cost?.cacheRead ?? 0) / 1_000_000) * usage.cacheRead;
|
|
437
|
-
usage.cost.cacheWrite = ((model.cost?.cacheWrite ?? 0) / 1_000_000) * usage.cacheWrite;
|
|
438
|
-
usage.cost.total =
|
|
439
|
-
usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
|
|
440
|
-
}
|
|
441
340
|
function legacyInputToContext(input) {
|
|
442
341
|
const messages = input.messages
|
|
443
342
|
? input.messages
|
|
@@ -472,9 +371,6 @@ function legacyInputToContext(input) {
|
|
|
472
371
|
messages,
|
|
473
372
|
};
|
|
474
373
|
}
|
|
475
|
-
function clone(value) {
|
|
476
|
-
return JSON.parse(JSON.stringify(value));
|
|
477
|
-
}
|
|
478
374
|
async function* iterateResponseBody(body) {
|
|
479
375
|
if ('getReader' in body && typeof body.getReader === 'function') {
|
|
480
376
|
const reader = body.getReader();
|
package/package.json
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentic-kit/ollama",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "Ollama",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"module": "esm/index.js",
|
|
8
8
|
"types": "index.d.ts",
|
|
9
|
-
"
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./index.d.ts",
|
|
12
|
-
"import": "./esm/index.js",
|
|
13
|
-
"require": "./index.js"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"homepage": "https://github.com/constructive-io/agentic-kit",
|
|
9
|
+
"homepage": "https://github.com/constructive-io/constructive",
|
|
17
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
18
11
|
"publishConfig": {
|
|
19
12
|
"access": "public",
|
|
@@ -21,24 +14,23 @@
|
|
|
21
14
|
},
|
|
22
15
|
"repository": {
|
|
23
16
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/constructive-io/
|
|
17
|
+
"url": "https://github.com/constructive-io/constructive"
|
|
25
18
|
},
|
|
26
19
|
"bugs": {
|
|
27
|
-
"url": "https://github.com/constructive-io/
|
|
20
|
+
"url": "https://github.com/constructive-io/constructive/issues"
|
|
28
21
|
},
|
|
29
22
|
"scripts": {
|
|
30
23
|
"clean": "makage clean",
|
|
31
24
|
"prepack": "npm run build",
|
|
32
25
|
"build": "makage build",
|
|
33
|
-
"postbuild": "node ../../scripts/write-esm-package-json.js",
|
|
34
26
|
"build:dev": "makage build --dev",
|
|
35
27
|
"lint": "eslint . --fix",
|
|
36
28
|
"test": "jest",
|
|
37
|
-
"test:live": "node ./scripts/run-live-tests.js smoke",
|
|
38
|
-
"test:live:smoke": "node ./scripts/run-live-tests.js smoke",
|
|
39
|
-
"test:live:extended": "node ./scripts/run-live-tests.js extended",
|
|
40
29
|
"test:watch": "jest --watch"
|
|
41
30
|
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@agentic-kit/protocol": "1.2.0"
|
|
33
|
+
},
|
|
42
34
|
"keywords": [],
|
|
43
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "fc6f9780ea1cab2c9344c2e392649ae644e84849"
|
|
44
36
|
}
|
package/esm/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|