agentic-server 0.30.1 → 0.30.2

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/esm/transforms.js CHANGED
@@ -145,12 +145,29 @@ export function transformChatRequest(provider, body) {
145
145
  // OpenAI-compatible (default)
146
146
  return { ...body, model: model || 'gpt-4o' };
147
147
  }
148
+ // Anchored, so text that merely mentions a data url stays text. A media type
149
+ // may carry parameters before the encoding (`image/svg+xml;charset=utf-8;base64,`)
150
+ // and both are case-insensitive (RFC 2397).
151
+ const IMAGE_DATA_URL = /^data:image\/[^;,]+(?:;[^;,]+)*;base64,/i;
152
+ /**
153
+ * One embed input in Ollama's shape. An image arrives as a base64 `data:` url,
154
+ * the way OpenAI-style clients carry bytes; Ollama's multimodal embed takes it
155
+ * as `{ image: <base64> }`, and embeds the same url left as a string as text —
156
+ * a vector of the right length for the wrong thing, with no error.
157
+ */
158
+ function ollamaEmbedInput(input) {
159
+ if (typeof input !== 'string')
160
+ return input;
161
+ const prefix = IMAGE_DATA_URL.exec(input)?.[0];
162
+ return prefix ? { image: input.slice(prefix.length) } : input;
163
+ }
148
164
  export function transformEmbedRequest(provider, body) {
149
165
  const model = upstreamModel(provider, body.model);
150
166
  if (provider.type === 'ollama') {
151
167
  return {
152
168
  model: model || 'nomic-embed-text',
153
- input: body.input
169
+ input: Array.isArray(body.input) ? body.input.map(ollamaEmbedInput) : ollamaEmbedInput(body.input),
170
+ ...(body.dimensions !== undefined && { dimensions: body.dimensions })
154
171
  };
155
172
  }
156
173
  return { ...body, model: model || 'text-embedding-3-small' };
@@ -243,8 +260,13 @@ function finishReason(doneReason) {
243
260
  }
244
261
  export function transformEmbedResponse(data, provider) {
245
262
  if (provider.type === 'ollama') {
246
- const raw = (data.embeddings || data.embedding || []);
247
- const embeddings = Array.isArray(raw[0]) ? raw : [raw];
263
+ const raw = (data.embeddings ?? data.embedding);
264
+ const embeddings = (Array.isArray(raw) && Array.isArray(raw[0]) ? raw : [raw]);
265
+ // An answer with no vector in it is not an embedding of nothing: passing it
266
+ // on would hand the caller one empty vector to store.
267
+ if (!Array.isArray(raw) || raw.length === 0 || embeddings.some((e) => !Array.isArray(e) || e.length === 0)) {
268
+ throw new Error(`ollama: the embed response carries no embedding${typeof data.error === 'string' ? ` (${data.error})` : ''}`);
269
+ }
248
270
  // Ollama reports the prompt tokens of an embed as `prompt_eval_count`.
249
271
  const promptTokens = data.prompt_eval_count || 0;
250
272
  const usage = { prompt_tokens: promptTokens, completion_tokens: 0, total_tokens: promptTokens };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-server",
3
- "version": "0.30.1",
3
+ "version": "0.30.2",
4
4
  "description": "Standalone OpenAI-compatible LLM gateway — multi-provider proxy with pluggable inference metering",
5
5
  "main": "index.js",
6
6
  "module": "esm/index.js",
@@ -51,5 +51,5 @@
51
51
  "metering",
52
52
  "constructive"
53
53
  ],
54
- "gitHead": "eb44afc5ecdfa6e91aeb7ad8e24c9021b97ec027"
54
+ "gitHead": "1dceb60e5be9ff31a9455f48a8a50399f0b9262c"
55
55
  }
package/transforms.js CHANGED
@@ -154,12 +154,29 @@ function transformChatRequest(provider, body) {
154
154
  // OpenAI-compatible (default)
155
155
  return { ...body, model: model || 'gpt-4o' };
156
156
  }
157
+ // Anchored, so text that merely mentions a data url stays text. A media type
158
+ // may carry parameters before the encoding (`image/svg+xml;charset=utf-8;base64,`)
159
+ // and both are case-insensitive (RFC 2397).
160
+ const IMAGE_DATA_URL = /^data:image\/[^;,]+(?:;[^;,]+)*;base64,/i;
161
+ /**
162
+ * One embed input in Ollama's shape. An image arrives as a base64 `data:` url,
163
+ * the way OpenAI-style clients carry bytes; Ollama's multimodal embed takes it
164
+ * as `{ image: <base64> }`, and embeds the same url left as a string as text —
165
+ * a vector of the right length for the wrong thing, with no error.
166
+ */
167
+ function ollamaEmbedInput(input) {
168
+ if (typeof input !== 'string')
169
+ return input;
170
+ const prefix = IMAGE_DATA_URL.exec(input)?.[0];
171
+ return prefix ? { image: input.slice(prefix.length) } : input;
172
+ }
157
173
  function transformEmbedRequest(provider, body) {
158
174
  const model = upstreamModel(provider, body.model);
159
175
  if (provider.type === 'ollama') {
160
176
  return {
161
177
  model: model || 'nomic-embed-text',
162
- input: body.input
178
+ input: Array.isArray(body.input) ? body.input.map(ollamaEmbedInput) : ollamaEmbedInput(body.input),
179
+ ...(body.dimensions !== undefined && { dimensions: body.dimensions })
163
180
  };
164
181
  }
165
182
  return { ...body, model: model || 'text-embedding-3-small' };
@@ -252,8 +269,13 @@ function finishReason(doneReason) {
252
269
  }
253
270
  function transformEmbedResponse(data, provider) {
254
271
  if (provider.type === 'ollama') {
255
- const raw = (data.embeddings || data.embedding || []);
256
- const embeddings = Array.isArray(raw[0]) ? raw : [raw];
272
+ const raw = (data.embeddings ?? data.embedding);
273
+ const embeddings = (Array.isArray(raw) && Array.isArray(raw[0]) ? raw : [raw]);
274
+ // An answer with no vector in it is not an embedding of nothing: passing it
275
+ // on would hand the caller one empty vector to store.
276
+ if (!Array.isArray(raw) || raw.length === 0 || embeddings.some((e) => !Array.isArray(e) || e.length === 0)) {
277
+ throw new Error(`ollama: the embed response carries no embedding${typeof data.error === 'string' ? ` (${data.error})` : ''}`);
278
+ }
257
279
  // Ollama reports the prompt tokens of an embed as `prompt_eval_count`.
258
280
  const promptTokens = data.prompt_eval_count || 0;
259
281
  const usage = { prompt_tokens: promptTokens, completion_tokens: 0, total_tokens: promptTokens };