@nemesis-oss/ollama-sdk 1.1.0 → 1.4.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/CHANGELOG.md +43 -92
- package/README.md +749 -11
- package/dist/compose-BR70yb4W.d.cts +164 -0
- package/dist/compose-DfAqKAFj.d.ts +164 -0
- package/dist/generated-api.cjs +454 -0
- package/dist/generated-api.cjs.map +1 -0
- package/dist/generated-api.d.cts +1651 -0
- package/dist/generated-api.d.ts +1651 -0
- package/dist/generated-api.js +428 -0
- package/dist/generated-api.js.map +1 -0
- package/dist/generated-models-schemas.cjs +328 -0
- package/dist/generated-models-schemas.cjs.map +1 -0
- package/dist/generated-models-schemas.d.cts +463 -0
- package/dist/generated-models-schemas.d.ts +463 -0
- package/dist/generated-models-schemas.js +291 -0
- package/dist/generated-models-schemas.js.map +1 -0
- package/dist/generated-runtime.cjs +145 -0
- package/dist/generated-runtime.cjs.map +1 -0
- package/dist/generated-runtime.d.cts +2 -0
- package/dist/generated-runtime.d.ts +2 -0
- package/dist/generated-runtime.js +143 -0
- package/dist/generated-runtime.js.map +1 -0
- package/dist/index-2RIErNT5.d.cts +583 -0
- package/dist/index-DIQ8NUbU.d.ts +583 -0
- package/dist/index.cjs +2308 -184
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1123 -421
- package/dist/index.d.ts +1123 -421
- package/dist/index.js +2293 -185
- package/dist/index.js.map +1 -1
- package/dist/mcp/tools.json +1058 -0
- package/dist/mcp-generated.cjs +386 -0
- package/dist/mcp-generated.cjs.map +1 -0
- package/dist/mcp-generated.d.cts +35 -0
- package/dist/mcp-generated.d.ts +35 -0
- package/dist/mcp-generated.js +381 -0
- package/dist/mcp-generated.js.map +1 -0
- package/dist/mcp-http.cjs +100 -0
- package/dist/mcp-http.cjs.map +1 -0
- package/dist/mcp-http.d.cts +48 -0
- package/dist/mcp-http.d.ts +48 -0
- package/dist/mcp-http.js +96 -0
- package/dist/mcp-http.js.map +1 -0
- package/dist/mcp-stdio.cjs +49 -0
- package/dist/mcp-stdio.cjs.map +1 -0
- package/dist/mcp-stdio.d.cts +34 -0
- package/dist/mcp-stdio.d.ts +34 -0
- package/dist/mcp-stdio.js +47 -0
- package/dist/mcp-stdio.js.map +1 -0
- package/dist/skills.cjs.map +1 -1
- package/dist/skills.d.cts +3 -2
- package/dist/skills.d.ts +3 -2
- package/dist/skills.js.map +1 -1
- package/dist/types-B9_axjum.d.cts +66 -0
- package/dist/types-B9_axjum.d.ts +66 -0
- package/dist/{compose-DJjVpDrk.d.cts → types-BQhgW-du.d.cts} +118 -172
- package/dist/{compose-DJjVpDrk.d.ts → types-BQhgW-du.d.ts} +118 -172
- package/package.json +96 -5
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { T as ToolDefinition, a as ToolCall, M as Message } from './types-BQhgW-du.cjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tool definition, handler, and execution types.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface ToolExecutionContext {
|
|
9
|
+
readonly signal?: AbortSignal | undefined;
|
|
10
|
+
}
|
|
11
|
+
type ToolHandler<TParams, TResult> = (params: TParams, context: ToolExecutionContext) => Promise<TResult> | TResult;
|
|
12
|
+
interface Tool<TParams = Record<string, unknown>, TResult = unknown> {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly description: string;
|
|
15
|
+
readonly schema: z.ZodType<TParams>;
|
|
16
|
+
readonly execute: ToolHandler<TParams, TResult>;
|
|
17
|
+
readonly definition: ToolDefinition;
|
|
18
|
+
/**
|
|
19
|
+
* Per-tool execution timeout in milliseconds, overriding the registry's default.
|
|
20
|
+
* Pass `0` to explicitly disable timeout enforcement for this tool.
|
|
21
|
+
*/
|
|
22
|
+
readonly timeoutMs?: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A `Tool` of *any* parameter shape, for heterogeneous collections — i.e. what
|
|
26
|
+
* `ToolRegistry` stores and accepts.
|
|
27
|
+
*
|
|
28
|
+
* `Tool<TParams>` is **invariant** in `TParams`, because `TParams` appears both
|
|
29
|
+
* covariantly (`schema: z.ZodType<TParams>`) and contravariantly
|
|
30
|
+
* (`execute: ToolHandler<TParams, …>`). That makes `Tool<never, unknown>` — the obvious-
|
|
31
|
+
* looking "bottom" type for a mixed collection — assignable from *nothing*: a perfectly
|
|
32
|
+
* ordinary `Tool<{ city: string }, string>` from `defineTool` is rejected by it. `any` is
|
|
33
|
+
* the standard escape hatch for exactly this case, and it is confined to this one alias:
|
|
34
|
+
* `defineTool` still infers `TParams` from the Zod schema and still type-checks `execute`
|
|
35
|
+
* against it, so tool authoring keeps full type safety. Only the registry's *storage*
|
|
36
|
+
* type is widened, and the registry never does anything with a tool's params beyond
|
|
37
|
+
* handing `schema.safeParse`'s validated output straight back to that same tool's
|
|
38
|
+
* `execute`.
|
|
39
|
+
*/
|
|
40
|
+
type AnyTool = Tool<any, unknown>;
|
|
41
|
+
interface ToolExecutionSuccess {
|
|
42
|
+
readonly toolName: string;
|
|
43
|
+
/** Echoes the originating {@link ToolCall.id}, if the call had one. */
|
|
44
|
+
readonly toolCallId?: string | undefined;
|
|
45
|
+
readonly success: true;
|
|
46
|
+
readonly result: unknown;
|
|
47
|
+
readonly outputString: string;
|
|
48
|
+
}
|
|
49
|
+
interface ToolExecutionFailure {
|
|
50
|
+
readonly toolName: string;
|
|
51
|
+
/** Echoes the originating {@link ToolCall.id}, if the call had one. */
|
|
52
|
+
readonly toolCallId?: string | undefined;
|
|
53
|
+
readonly success: false;
|
|
54
|
+
readonly error: Error;
|
|
55
|
+
readonly outputString: string;
|
|
56
|
+
}
|
|
57
|
+
type ToolExecutionResult = ToolExecutionSuccess | ToolExecutionFailure;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Tool registry for managing definitions and executing model tool calls.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
interface ToolRegistryOptions {
|
|
64
|
+
readonly tools?: readonly AnyTool[] | undefined;
|
|
65
|
+
readonly onError?: ((error: Error, toolCall: ToolCall) => string) | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Default per-call execution timeout in milliseconds, applied to any tool that
|
|
68
|
+
* doesn't declare its own `timeoutMs`. Undefined (the default) means no timeout is
|
|
69
|
+
* enforced, matching prior behavior. Recommended whenever tool arguments or
|
|
70
|
+
* implementations are influenced by model output you don't fully control, since an
|
|
71
|
+
* unbounded tool call can otherwise stall the entire agent loop indefinitely.
|
|
72
|
+
*
|
|
73
|
+
* Enforcement is cooperative: it races the tool's promise against a timer and
|
|
74
|
+
* reports a timeout failure, but cannot forcibly halt synchronous or non-abort-aware
|
|
75
|
+
* asynchronous work already in flight on the same thread. Tools that perform I/O
|
|
76
|
+
* should honor `ToolExecutionContext.signal` to stop promptly on timeout.
|
|
77
|
+
*/
|
|
78
|
+
readonly timeoutMs?: number | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Maximum number of tool calls executed concurrently by `executeToolCalls`.
|
|
81
|
+
* Undefined (the default) runs all calls in parallel, matching prior behavior.
|
|
82
|
+
*/
|
|
83
|
+
readonly maxConcurrency?: number | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Maximum length of a tool's `outputString` before it is truncated. Guards against a
|
|
86
|
+
* single tool call flooding the conversation history / model context (and process
|
|
87
|
+
* memory) with unbounded output. Undefined (the default) applies no limit.
|
|
88
|
+
*/
|
|
89
|
+
readonly maxOutputChars?: number | undefined;
|
|
90
|
+
}
|
|
91
|
+
declare class ToolRegistry {
|
|
92
|
+
private readonly tools;
|
|
93
|
+
private readonly onError?;
|
|
94
|
+
private readonly defaultTimeoutMs?;
|
|
95
|
+
private readonly maxConcurrency?;
|
|
96
|
+
private readonly maxOutputChars?;
|
|
97
|
+
constructor(toolsOrOptions?: readonly AnyTool[] | ToolRegistryOptions | undefined);
|
|
98
|
+
register(tool: AnyTool): this;
|
|
99
|
+
registerMany(tools: readonly AnyTool[]): this;
|
|
100
|
+
get(name: string): AnyTool | undefined;
|
|
101
|
+
definitions(): ToolDefinition[];
|
|
102
|
+
executeToolCall(toolCall: ToolCall, ctx?: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
103
|
+
private executeToolCallUninstrumented;
|
|
104
|
+
/**
|
|
105
|
+
* Executes every call in `toolCalls` and returns results in the same order, so results
|
|
106
|
+
* are always correlatable by array position regardless of `id`. Each result also echoes
|
|
107
|
+
* its call's `toolCallId` for callers who'd rather match by ID — see the {@link ToolCall}
|
|
108
|
+
* docs for how that id is produced. Runs fully in parallel (`Promise.all`) unless
|
|
109
|
+
* `maxConcurrency` was configured, in which case a bounded worker pool is used instead.
|
|
110
|
+
*/
|
|
111
|
+
executeToolCalls(toolCalls: readonly ToolCall[], ctx?: ToolExecutionContext): Promise<ToolExecutionResult[]>;
|
|
112
|
+
private runWithTimeout;
|
|
113
|
+
private truncateOutput;
|
|
114
|
+
private handleExecutionError;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* SKILL.md frontmatter and skill registry types.
|
|
119
|
+
*/
|
|
120
|
+
interface SkillFrontmatter {
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly description: string;
|
|
123
|
+
readonly 'allowed-tools'?: readonly string[] | undefined;
|
|
124
|
+
readonly [key: string]: unknown;
|
|
125
|
+
}
|
|
126
|
+
interface SkillSummary {
|
|
127
|
+
readonly name: string;
|
|
128
|
+
readonly description: string;
|
|
129
|
+
readonly path: string;
|
|
130
|
+
}
|
|
131
|
+
interface Skill extends SkillSummary {
|
|
132
|
+
readonly frontmatter: SkillFrontmatter;
|
|
133
|
+
readonly body: string;
|
|
134
|
+
readonly allowedTools?: readonly string[] | undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Lightweight frontmatter parser for SKILL.md files.
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
interface ParsedFrontmatter {
|
|
142
|
+
readonly frontmatter: SkillFrontmatter;
|
|
143
|
+
readonly body: string;
|
|
144
|
+
}
|
|
145
|
+
declare function parseFrontmatter(source: string, path?: string): ParsedFrontmatter;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Skill composition and context injection.
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
interface ApplySkillOptions {
|
|
152
|
+
readonly messages: readonly Message[];
|
|
153
|
+
readonly tools?: ToolRegistry;
|
|
154
|
+
}
|
|
155
|
+
interface AppliedSkillResult {
|
|
156
|
+
readonly messages: readonly Message[];
|
|
157
|
+
readonly tools?: ToolRegistry;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Injects a skill's body into messages as a system prompt and applies allowed tool filters.
|
|
161
|
+
*/
|
|
162
|
+
declare function applySkill(skill: Skill, options: ApplySkillOptions): AppliedSkillResult;
|
|
163
|
+
|
|
164
|
+
export { type AppliedSkillResult as A, type ParsedFrontmatter as P, type SkillSummary as S, type ToolHandler as T, type Skill as a, type ApplySkillOptions as b, type SkillFrontmatter as c, applySkill as d, type Tool as e, type AnyTool as f, ToolRegistry as g, type ToolExecutionResult as h, type ToolExecutionContext as i, type ToolExecutionFailure as j, type ToolExecutionSuccess as k, type ToolRegistryOptions as l, parseFrontmatter as p };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { T as ToolDefinition, a as ToolCall, M as Message } from './types-BQhgW-du.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tool definition, handler, and execution types.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface ToolExecutionContext {
|
|
9
|
+
readonly signal?: AbortSignal | undefined;
|
|
10
|
+
}
|
|
11
|
+
type ToolHandler<TParams, TResult> = (params: TParams, context: ToolExecutionContext) => Promise<TResult> | TResult;
|
|
12
|
+
interface Tool<TParams = Record<string, unknown>, TResult = unknown> {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly description: string;
|
|
15
|
+
readonly schema: z.ZodType<TParams>;
|
|
16
|
+
readonly execute: ToolHandler<TParams, TResult>;
|
|
17
|
+
readonly definition: ToolDefinition;
|
|
18
|
+
/**
|
|
19
|
+
* Per-tool execution timeout in milliseconds, overriding the registry's default.
|
|
20
|
+
* Pass `0` to explicitly disable timeout enforcement for this tool.
|
|
21
|
+
*/
|
|
22
|
+
readonly timeoutMs?: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A `Tool` of *any* parameter shape, for heterogeneous collections — i.e. what
|
|
26
|
+
* `ToolRegistry` stores and accepts.
|
|
27
|
+
*
|
|
28
|
+
* `Tool<TParams>` is **invariant** in `TParams`, because `TParams` appears both
|
|
29
|
+
* covariantly (`schema: z.ZodType<TParams>`) and contravariantly
|
|
30
|
+
* (`execute: ToolHandler<TParams, …>`). That makes `Tool<never, unknown>` — the obvious-
|
|
31
|
+
* looking "bottom" type for a mixed collection — assignable from *nothing*: a perfectly
|
|
32
|
+
* ordinary `Tool<{ city: string }, string>` from `defineTool` is rejected by it. `any` is
|
|
33
|
+
* the standard escape hatch for exactly this case, and it is confined to this one alias:
|
|
34
|
+
* `defineTool` still infers `TParams` from the Zod schema and still type-checks `execute`
|
|
35
|
+
* against it, so tool authoring keeps full type safety. Only the registry's *storage*
|
|
36
|
+
* type is widened, and the registry never does anything with a tool's params beyond
|
|
37
|
+
* handing `schema.safeParse`'s validated output straight back to that same tool's
|
|
38
|
+
* `execute`.
|
|
39
|
+
*/
|
|
40
|
+
type AnyTool = Tool<any, unknown>;
|
|
41
|
+
interface ToolExecutionSuccess {
|
|
42
|
+
readonly toolName: string;
|
|
43
|
+
/** Echoes the originating {@link ToolCall.id}, if the call had one. */
|
|
44
|
+
readonly toolCallId?: string | undefined;
|
|
45
|
+
readonly success: true;
|
|
46
|
+
readonly result: unknown;
|
|
47
|
+
readonly outputString: string;
|
|
48
|
+
}
|
|
49
|
+
interface ToolExecutionFailure {
|
|
50
|
+
readonly toolName: string;
|
|
51
|
+
/** Echoes the originating {@link ToolCall.id}, if the call had one. */
|
|
52
|
+
readonly toolCallId?: string | undefined;
|
|
53
|
+
readonly success: false;
|
|
54
|
+
readonly error: Error;
|
|
55
|
+
readonly outputString: string;
|
|
56
|
+
}
|
|
57
|
+
type ToolExecutionResult = ToolExecutionSuccess | ToolExecutionFailure;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Tool registry for managing definitions and executing model tool calls.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
interface ToolRegistryOptions {
|
|
64
|
+
readonly tools?: readonly AnyTool[] | undefined;
|
|
65
|
+
readonly onError?: ((error: Error, toolCall: ToolCall) => string) | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Default per-call execution timeout in milliseconds, applied to any tool that
|
|
68
|
+
* doesn't declare its own `timeoutMs`. Undefined (the default) means no timeout is
|
|
69
|
+
* enforced, matching prior behavior. Recommended whenever tool arguments or
|
|
70
|
+
* implementations are influenced by model output you don't fully control, since an
|
|
71
|
+
* unbounded tool call can otherwise stall the entire agent loop indefinitely.
|
|
72
|
+
*
|
|
73
|
+
* Enforcement is cooperative: it races the tool's promise against a timer and
|
|
74
|
+
* reports a timeout failure, but cannot forcibly halt synchronous or non-abort-aware
|
|
75
|
+
* asynchronous work already in flight on the same thread. Tools that perform I/O
|
|
76
|
+
* should honor `ToolExecutionContext.signal` to stop promptly on timeout.
|
|
77
|
+
*/
|
|
78
|
+
readonly timeoutMs?: number | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Maximum number of tool calls executed concurrently by `executeToolCalls`.
|
|
81
|
+
* Undefined (the default) runs all calls in parallel, matching prior behavior.
|
|
82
|
+
*/
|
|
83
|
+
readonly maxConcurrency?: number | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Maximum length of a tool's `outputString` before it is truncated. Guards against a
|
|
86
|
+
* single tool call flooding the conversation history / model context (and process
|
|
87
|
+
* memory) with unbounded output. Undefined (the default) applies no limit.
|
|
88
|
+
*/
|
|
89
|
+
readonly maxOutputChars?: number | undefined;
|
|
90
|
+
}
|
|
91
|
+
declare class ToolRegistry {
|
|
92
|
+
private readonly tools;
|
|
93
|
+
private readonly onError?;
|
|
94
|
+
private readonly defaultTimeoutMs?;
|
|
95
|
+
private readonly maxConcurrency?;
|
|
96
|
+
private readonly maxOutputChars?;
|
|
97
|
+
constructor(toolsOrOptions?: readonly AnyTool[] | ToolRegistryOptions | undefined);
|
|
98
|
+
register(tool: AnyTool): this;
|
|
99
|
+
registerMany(tools: readonly AnyTool[]): this;
|
|
100
|
+
get(name: string): AnyTool | undefined;
|
|
101
|
+
definitions(): ToolDefinition[];
|
|
102
|
+
executeToolCall(toolCall: ToolCall, ctx?: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
103
|
+
private executeToolCallUninstrumented;
|
|
104
|
+
/**
|
|
105
|
+
* Executes every call in `toolCalls` and returns results in the same order, so results
|
|
106
|
+
* are always correlatable by array position regardless of `id`. Each result also echoes
|
|
107
|
+
* its call's `toolCallId` for callers who'd rather match by ID — see the {@link ToolCall}
|
|
108
|
+
* docs for how that id is produced. Runs fully in parallel (`Promise.all`) unless
|
|
109
|
+
* `maxConcurrency` was configured, in which case a bounded worker pool is used instead.
|
|
110
|
+
*/
|
|
111
|
+
executeToolCalls(toolCalls: readonly ToolCall[], ctx?: ToolExecutionContext): Promise<ToolExecutionResult[]>;
|
|
112
|
+
private runWithTimeout;
|
|
113
|
+
private truncateOutput;
|
|
114
|
+
private handleExecutionError;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* SKILL.md frontmatter and skill registry types.
|
|
119
|
+
*/
|
|
120
|
+
interface SkillFrontmatter {
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly description: string;
|
|
123
|
+
readonly 'allowed-tools'?: readonly string[] | undefined;
|
|
124
|
+
readonly [key: string]: unknown;
|
|
125
|
+
}
|
|
126
|
+
interface SkillSummary {
|
|
127
|
+
readonly name: string;
|
|
128
|
+
readonly description: string;
|
|
129
|
+
readonly path: string;
|
|
130
|
+
}
|
|
131
|
+
interface Skill extends SkillSummary {
|
|
132
|
+
readonly frontmatter: SkillFrontmatter;
|
|
133
|
+
readonly body: string;
|
|
134
|
+
readonly allowedTools?: readonly string[] | undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Lightweight frontmatter parser for SKILL.md files.
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
interface ParsedFrontmatter {
|
|
142
|
+
readonly frontmatter: SkillFrontmatter;
|
|
143
|
+
readonly body: string;
|
|
144
|
+
}
|
|
145
|
+
declare function parseFrontmatter(source: string, path?: string): ParsedFrontmatter;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Skill composition and context injection.
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
interface ApplySkillOptions {
|
|
152
|
+
readonly messages: readonly Message[];
|
|
153
|
+
readonly tools?: ToolRegistry;
|
|
154
|
+
}
|
|
155
|
+
interface AppliedSkillResult {
|
|
156
|
+
readonly messages: readonly Message[];
|
|
157
|
+
readonly tools?: ToolRegistry;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Injects a skill's body into messages as a system prompt and applies allowed tool filters.
|
|
161
|
+
*/
|
|
162
|
+
declare function applySkill(skill: Skill, options: ApplySkillOptions): AppliedSkillResult;
|
|
163
|
+
|
|
164
|
+
export { type AppliedSkillResult as A, type ParsedFrontmatter as P, type SkillSummary as S, type ToolHandler as T, type Skill as a, type ApplySkillOptions as b, type SkillFrontmatter as c, applySkill as d, type Tool as e, type AnyTool as f, ToolRegistry as g, type ToolExecutionResult as h, type ToolExecutionContext as i, type ToolExecutionFailure as j, type ToolExecutionSuccess as k, type ToolRegistryOptions as l, parseFrontmatter as p };
|