nuxt-ollama 1.2.26 → 1.3.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.
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "1.2.26",
7
+ "version": "1.3.1",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { defineNuxtModule, createResolver, addImportsDir, addServerImportsDir } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addImportsDir, addServerImportsDir, addServerHandler } from '@nuxt/kit';
2
2
  import { defu } from 'defu';
3
3
 
4
4
  const module$1 = defineNuxtModule({
@@ -20,10 +20,13 @@ const module$1 = defineNuxtModule({
20
20
  setup(_options, _nuxt) {
21
21
  const resolver = createResolver(import.meta.url);
22
22
  const runtimeConfig = _nuxt.options.runtimeConfig;
23
- const currentConfig = runtimeConfig.public.ollama ?? {};
24
- runtimeConfig.public.ollama = defu(currentConfig, _options);
23
+ runtimeConfig.ollama = defu(runtimeConfig.ollama ?? {}, _options);
25
24
  addImportsDir(resolver.resolve("./runtime/composables"));
26
25
  addServerImportsDir(resolver.resolve("./runtime/server/utils"));
26
+ addServerHandler({
27
+ route: "/api/__ollama/**",
28
+ handler: resolver.resolve("./runtime/server/routes/ollama-proxy")
29
+ });
27
30
  }
28
31
  });
29
32
 
@@ -1,15 +1,12 @@
1
1
  import { Ollama } from "ollama/browser";
2
- import { useRuntimeConfig } from "#imports";
2
+ import { useRequestURL } from "#imports";
3
3
  export function useOllama() {
4
- const options = useRuntimeConfig().public.ollama;
5
- const headers = {};
6
- if (options.api_key) {
7
- headers.Authorization = `Bearer ${options.api_key}`;
8
- }
9
- const host = `${options.protocol}://${options.host}${options.port ? `:${options.port}` : ""}`;
4
+ const { origin } = useRequestURL();
10
5
  return new Ollama({
11
- host,
12
- proxy: options.proxy,
13
- headers
6
+ host: origin,
7
+ fetch: (input, init) => {
8
+ const url = new URL(input.toString());
9
+ return fetch(`${origin}/api/__ollama${url.pathname}`, init);
10
+ }
14
11
  });
15
12
  }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void | null>>;
2
+ export default _default;
@@ -0,0 +1,32 @@
1
+ import {
2
+ defineEventHandler,
3
+ getMethod,
4
+ getHeader,
5
+ readRawBody,
6
+ setResponseStatus,
7
+ setResponseHeader,
8
+ sendStream
9
+ } from "h3";
10
+ import { useRuntimeConfig } from "#imports";
11
+ export default defineEventHandler(async (event) => {
12
+ const options = useRuntimeConfig().ollama;
13
+ const ollamaBase = `${options.protocol}://${options.host}${options.port ? `:${options.port}` : ""}`;
14
+ const subpath = event.path.replace(/^\/api\/__ollama/, "");
15
+ const headers = {};
16
+ const contentType = getHeader(event, "content-type");
17
+ if (contentType) headers["content-type"] = contentType;
18
+ if (options.api_key) {
19
+ headers["authorization"] = `Bearer ${options.api_key}`;
20
+ }
21
+ const body = await readRawBody(event);
22
+ const response = await fetch(`${ollamaBase}${subpath}`, {
23
+ method: getMethod(event),
24
+ headers,
25
+ body: body ?? void 0
26
+ });
27
+ setResponseStatus(event, response.status);
28
+ const responseContentType = response.headers.get("content-type");
29
+ if (responseContentType) setResponseHeader(event, "content-type", responseContentType);
30
+ if (!response.body) return null;
31
+ return sendStream(event, response.body);
32
+ });
@@ -1,7 +1,7 @@
1
1
  import { Ollama } from "ollama";
2
2
  import { useRuntimeConfig } from "#imports";
3
3
  export function useOllama() {
4
- const options = useRuntimeConfig().public.ollama;
4
+ const options = useRuntimeConfig().ollama;
5
5
  const headers = {};
6
6
  if (options.api_key) {
7
7
  headers.Authorization = `Bearer ${options.api_key}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-ollama",
3
- "version": "1.2.26",
3
+ "version": "1.3.1",
4
4
  "description": "Easy ollama integration for Nuxt",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,25 +23,25 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "@typescript-eslint/eslint-plugin": "^8.59.2",
27
- "@typescript-eslint/parser": "^8.59.2",
26
+ "@typescript-eslint/eslint-plugin": "^8.61.1",
27
+ "@typescript-eslint/parser": "^8.61.1",
28
28
  "defu": "^6.1.7",
29
29
  "ollama": "^0.6.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@nuxt/devtools": "^3.2.4",
33
- "@nuxt/eslint-config": "^1.15.2",
34
- "@nuxt/kit": "^4.4.4",
33
+ "@nuxt/eslint-config": "^1.16.0",
34
+ "@nuxt/kit": "^4.4.8",
35
35
  "@nuxt/module-builder": "^1.0.2",
36
- "@nuxt/schema": "^4.4.4",
36
+ "@nuxt/schema": "^4.4.8",
37
37
  "@nuxt/test-utils": "^4.0.3",
38
38
  "@types/node": "latest",
39
39
  "changelogen": "^0.6.2",
40
- "eslint": "^10.3.0",
41
- "nuxt": "^4.4.4",
40
+ "eslint": "^10.5.0",
41
+ "nuxt": "^4.4.8",
42
42
  "typescript": "^6.0.3",
43
- "vitest": "^4.1.5",
44
- "vue-tsc": "^3.2.8"
43
+ "vitest": "^4.1.9",
44
+ "vue-tsc": "^3.3.5"
45
45
  },
46
46
  "scripts": {
47
47
  "dev": "nuxi dev playground",