@dxos/plugin-native 0.9.1-main.c7dcc2e112 → 0.9.1-staging.ee54ba693a
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/lib/neutral/{NativeSettings-EYX4X3D3.mjs → NativeSettings-33K63AVG.mjs} +15 -8
- package/dist/lib/neutral/NativeSettings-33K63AVG.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +2 -2
- package/dist/lib/neutral/{components → containers}/index.mjs +2 -2
- package/dist/lib/neutral/{components → containers}/index.mjs.map +1 -1
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/ollama-HZEXAT2P.mjs +312 -0
- package/dist/lib/neutral/ollama-HZEXAT2P.mjs.map +7 -0
- package/dist/lib/neutral/{react-surface-BVH3ZPG5.mjs → react-surface-YST5DQA3.mjs} +2 -2
- package/dist/lib/neutral/{react-surface-BVH3ZPG5.mjs.map → react-surface-YST5DQA3.mjs.map} +1 -1
- package/dist/lib/neutral/translations.mjs +0 -1
- package/dist/lib/neutral/translations.mjs.map +2 -2
- package/dist/types/src/capabilities/index.d.ts +1 -1
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/ollama.d.ts +3 -2
- package/dist/types/src/capabilities/ollama.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/settings.d.ts +1 -3
- package/dist/types/src/capabilities/settings.d.ts.map +1 -1
- package/dist/types/src/capabilities/spotlight-listener.d.ts +1 -1
- package/dist/types/src/capabilities/updater.d.ts +1 -2
- package/dist/types/src/capabilities/updater.d.ts.map +1 -1
- package/dist/types/src/{components → containers}/NativeSettings/NativeSettings.d.ts +1 -1
- package/dist/types/src/containers/NativeSettings/NativeSettings.d.ts.map +1 -0
- package/dist/types/src/{components → containers}/NativeSettings/index.d.ts.map +1 -1
- package/dist/types/src/{components → containers}/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +4 -0
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +0 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -24
- package/src/capabilities/ollama.ts +281 -16
- package/src/capabilities/react-surface.tsx +1 -1
- package/src/{components → containers}/NativeSettings/NativeSettings.tsx +14 -9
- package/src/translations.ts +0 -1
- package/dist/lib/neutral/NativeSettings-EYX4X3D3.mjs.map +0 -7
- package/dist/lib/neutral/ollama-BHWFTROM.mjs +0 -62
- package/dist/lib/neutral/ollama-BHWFTROM.mjs.map +0 -7
- package/dist/types/src/components/NativeSettings/NativeSettings.d.ts.map +0 -1
- /package/dist/types/src/{components → containers}/NativeSettings/index.d.ts +0 -0
- /package/dist/types/src/{components → containers}/index.d.ts +0 -0
- /package/src/{components → containers}/NativeSettings/index.ts +0 -0
- /package/src/{components → containers}/index.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-native",
|
|
3
|
-
"version": "0.9.1-
|
|
3
|
+
"version": "0.9.1-staging.ee54ba693a",
|
|
4
4
|
"description": "Composer plugin that runs when on a native device.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"types": "./dist/types/src/capabilities/index.d.ts",
|
|
19
19
|
"default": "./dist/lib/neutral/capabilities/index.mjs"
|
|
20
20
|
},
|
|
21
|
-
"#
|
|
22
|
-
"source": "./src/
|
|
23
|
-
"types": "./dist/types/src/
|
|
24
|
-
"default": "./dist/lib/neutral/
|
|
21
|
+
"#containers": {
|
|
22
|
+
"source": "./src/containers/index.ts",
|
|
23
|
+
"types": "./dist/types/src/containers/index.d.ts",
|
|
24
|
+
"default": "./dist/lib/neutral/containers/index.mjs"
|
|
25
25
|
},
|
|
26
26
|
"#meta": {
|
|
27
27
|
"source": "./src/meta.ts",
|
|
@@ -71,36 +71,36 @@
|
|
|
71
71
|
],
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@effect-atom/atom-react": "^0.5.0",
|
|
74
|
-
"@effect/platform": "0.96.
|
|
74
|
+
"@effect/platform": "0.96.2",
|
|
75
75
|
"@tauri-apps/api": "^2.11.0",
|
|
76
76
|
"@tauri-apps/plugin-os": "^2.3.2",
|
|
77
77
|
"@tauri-apps/plugin-process": "^2.3.1",
|
|
78
78
|
"@tauri-apps/plugin-shell": "^2.3.5",
|
|
79
79
|
"@tauri-apps/plugin-updater": "^2.10.1",
|
|
80
80
|
"date-fns": "^3.6.0",
|
|
81
|
-
"@dxos/
|
|
82
|
-
"@dxos/
|
|
83
|
-
"@dxos/
|
|
84
|
-
"@dxos/
|
|
85
|
-
"@dxos/
|
|
86
|
-
"@dxos/
|
|
87
|
-
"@dxos/
|
|
88
|
-
"@dxos/util": "0.9.1-
|
|
81
|
+
"@dxos/ai": "0.9.1-staging.ee54ba693a",
|
|
82
|
+
"@dxos/app-toolkit": "0.9.1-staging.ee54ba693a",
|
|
83
|
+
"@dxos/effect": "0.9.1-staging.ee54ba693a",
|
|
84
|
+
"@dxos/keys": "0.9.1-staging.ee54ba693a",
|
|
85
|
+
"@dxos/app-framework": "0.9.1-staging.ee54ba693a",
|
|
86
|
+
"@dxos/plugin-assistant": "0.9.1-staging.ee54ba693a",
|
|
87
|
+
"@dxos/log": "0.9.1-staging.ee54ba693a",
|
|
88
|
+
"@dxos/util": "0.9.1-staging.ee54ba693a"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
|
-
"@types/react": "~19.2.
|
|
92
|
-
"effect": "3.21.
|
|
93
|
-
"react": "~19.2.
|
|
91
|
+
"@types/react": "~19.2.17",
|
|
92
|
+
"effect": "3.21.4",
|
|
93
|
+
"react": "~19.2.7",
|
|
94
94
|
"vite": "^8.0.16",
|
|
95
|
-
"@dxos/plugin-testing": "0.9.1-
|
|
96
|
-
"@dxos/react-ui
|
|
97
|
-
"@dxos/react-ui": "0.9.1-
|
|
95
|
+
"@dxos/plugin-testing": "0.9.1-staging.ee54ba693a",
|
|
96
|
+
"@dxos/react-ui": "0.9.1-staging.ee54ba693a",
|
|
97
|
+
"@dxos/react-ui-form": "0.9.1-staging.ee54ba693a"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
|
-
"effect": "3.21.
|
|
101
|
-
"react": "~19.2.
|
|
102
|
-
"@dxos/react-ui": "0.9.1-
|
|
103
|
-
"@dxos/react-ui-form": "0.9.1-
|
|
100
|
+
"effect": "3.21.4",
|
|
101
|
+
"react": "~19.2.7",
|
|
102
|
+
"@dxos/react-ui": "0.9.1-staging.ee54ba693a",
|
|
103
|
+
"@dxos/react-ui-form": "0.9.1-staging.ee54ba693a"
|
|
104
104
|
},
|
|
105
105
|
"publishConfig": {
|
|
106
106
|
"access": "public"
|
|
@@ -2,27 +2,40 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
5
6
|
import * as FetchHttpClient from '@effect/platform/FetchHttpClient';
|
|
6
7
|
import * as HttpClient from '@effect/platform/HttpClient';
|
|
7
8
|
import { Command } from '@tauri-apps/plugin-shell';
|
|
9
|
+
import * as Cause from 'effect/Cause';
|
|
8
10
|
import * as Context from 'effect/Context';
|
|
11
|
+
import * as Duration from 'effect/Duration';
|
|
9
12
|
import * as Effect from 'effect/Effect';
|
|
13
|
+
import * as Either from 'effect/Either';
|
|
14
|
+
import * as Exit from 'effect/Exit';
|
|
15
|
+
import * as Fiber from 'effect/Fiber';
|
|
10
16
|
import * as Layer from 'effect/Layer';
|
|
11
17
|
import * as ManagedRuntime from 'effect/ManagedRuntime';
|
|
18
|
+
import * as Schedule from 'effect/Schedule';
|
|
19
|
+
import * as Stream from 'effect/Stream';
|
|
12
20
|
|
|
13
|
-
import { type AiModelResolver } from '@dxos/ai';
|
|
14
|
-
import { OllamaResolver } from '@dxos/ai/resolvers';
|
|
15
|
-
import { Capability } from '@dxos/app-framework';
|
|
21
|
+
import { type AiModelResolver, Provider } from '@dxos/ai';
|
|
22
|
+
import { OllamaAdmin, OllamaResolver } from '@dxos/ai/resolvers';
|
|
23
|
+
import { Capabilities, Capability } from '@dxos/app-framework';
|
|
16
24
|
import { AppCapabilities } from '@dxos/app-toolkit';
|
|
17
25
|
import { log } from '@dxos/log';
|
|
26
|
+
import { AssistantCapabilities, type Ollama } from '@dxos/plugin-assistant';
|
|
18
27
|
|
|
19
28
|
// NOTE: Running ollama on non-standard port (config Tauri).
|
|
20
29
|
const OLLAMA_HOST = 'http://localhost:21434';
|
|
21
30
|
|
|
22
|
-
export type OllamaCapabilities =
|
|
31
|
+
export type OllamaCapabilities =
|
|
32
|
+
| Capability.Capability<typeof AppCapabilities.AiModelResolver>
|
|
33
|
+
| Capability.Capability<typeof AssistantCapabilities.OllamaManager>;
|
|
34
|
+
|
|
35
|
+
export default Capability.makeModule(
|
|
36
|
+
Effect.fnUntraced(function* () {
|
|
37
|
+
const registry = yield* Capability.get(Capabilities.AtomRegistry);
|
|
23
38
|
|
|
24
|
-
export default Capability.makeModule<[], OllamaCapabilities>(() =>
|
|
25
|
-
Effect.sync(() => {
|
|
26
39
|
const runtime = ManagedRuntime.make(OllamaSidecar.layerLive);
|
|
27
40
|
|
|
28
41
|
// Layer for the sidecar but the lifecycle is managed by the runtime.
|
|
@@ -30,11 +43,232 @@ export default Capability.makeModule<[], OllamaCapabilities>(() =>
|
|
|
30
43
|
runtime.runtimeEffect.pipe(Effect.map((rt) => rt.context.pipe(Context.pick(OllamaSidecar)))),
|
|
31
44
|
);
|
|
32
45
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
const admin = OllamaAdmin.make({ endpoint: OLLAMA_HOST });
|
|
47
|
+
const stateAtom = Atom.make<Ollama.ModelsState>({
|
|
48
|
+
kind: 'idle',
|
|
49
|
+
models: [],
|
|
50
|
+
loaded: [],
|
|
51
|
+
pulls: {},
|
|
52
|
+
errors: {},
|
|
53
|
+
}).pipe(Atom.keepAlive);
|
|
54
|
+
|
|
55
|
+
// Read/update the reactive state atom as Effects.
|
|
56
|
+
const getState = Effect.sync(() => registry.get(stateAtom));
|
|
57
|
+
const updateState = (f: (state: Ollama.ModelsState) => Ollama.ModelsState): Effect.Effect<void> =>
|
|
58
|
+
Effect.sync(() => registry.set(stateAtom, f(registry.get(stateAtom))));
|
|
59
|
+
|
|
60
|
+
// Connection-level failure (reaching the service); shown at the section, not tied to a model.
|
|
61
|
+
const fail = (error: string): Effect.Effect<void> => updateState((state) => ({ ...state, kind: 'failed', error }));
|
|
62
|
+
|
|
63
|
+
// Per-model action error (load/unload/remove/pull); shown inline on that model's row. Pass
|
|
64
|
+
// `undefined` to clear.
|
|
65
|
+
const setError = (name: string, error: string | undefined): Effect.Effect<void> =>
|
|
66
|
+
updateState((state) => {
|
|
67
|
+
const errors = { ...state.errors };
|
|
68
|
+
if (error) {
|
|
69
|
+
errors[name] = error;
|
|
70
|
+
} else {
|
|
71
|
+
delete errors[name];
|
|
72
|
+
}
|
|
73
|
+
return { ...state, errors };
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Write (or clear, when `progress` is undefined) the in-flight progress for `name`.
|
|
77
|
+
const setProgress = (name: string, progress: OllamaAdmin.PullProgress | undefined): Effect.Effect<void> =>
|
|
78
|
+
updateState((state) => {
|
|
79
|
+
const pulls = { ...state.pulls };
|
|
80
|
+
if (progress) {
|
|
81
|
+
pulls[name] = progress;
|
|
82
|
+
} else {
|
|
83
|
+
delete pulls[name];
|
|
84
|
+
}
|
|
85
|
+
return { ...state, pulls };
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Force the scoped sidecar layer, spawning the process idempotently — the runtime is lazy and
|
|
89
|
+
// only spawns on first force, so opening settings starts Ollama rather than hitting a refused
|
|
90
|
+
// connection, and a chat already using the resolver does not spawn a second process. The endpoint
|
|
91
|
+
// is unused; forcing `OllamaSidecar` is what triggers the spawn. Failures surface as defects.
|
|
92
|
+
const ensureRunning: Effect.Effect<void> = Effect.asVoid(OllamaSidecar).pipe(Effect.provide(sidecarLayer));
|
|
93
|
+
|
|
94
|
+
// Run an admin effect with the HttpClient provided, folding its typed failure into an Either so
|
|
95
|
+
// callers branch on the result without a typed error channel.
|
|
96
|
+
const runAdmin = <A, E extends { readonly message: string }>(
|
|
97
|
+
effect: Effect.Effect<A, E, HttpClient.HttpClient>,
|
|
98
|
+
): Effect.Effect<Either.Either<A, string>> =>
|
|
99
|
+
effect.pipe(Effect.provide(clientLayer), Effect.either, Effect.map(Either.mapLeft((error) => error.message)));
|
|
100
|
+
|
|
101
|
+
// In-flight pull fibers, so a pull can be cancelled via interruption.
|
|
102
|
+
const pullFibers = new Map<string, Fiber.RuntimeFiber<void>>();
|
|
103
|
+
|
|
104
|
+
// Refresh only the loaded-into-memory set (cheap; no spawn). Logs load/unload transitions so the
|
|
105
|
+
// console reflects which model is resident when a chat request triggers a load.
|
|
106
|
+
const refreshLoaded: Effect.Effect<void> = Effect.gen(function* () {
|
|
107
|
+
const result = yield* runAdmin(admin.ps);
|
|
108
|
+
if (Either.isLeft(result)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const before = (yield* getState).loaded.map((model) => model.name);
|
|
112
|
+
const after = result.right.map((model) => model.name);
|
|
113
|
+
if (before.join() !== after.join()) {
|
|
114
|
+
yield* Effect.sync(() => log.info('ollama loaded models changed', { loaded: after }));
|
|
115
|
+
}
|
|
116
|
+
yield* updateState((state) => ({ ...state, loaded: result.right }));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const refresh: Effect.Effect<void> = Effect.gen(function* () {
|
|
120
|
+
yield* updateState((state) => ({ ...state, kind: 'loading', error: undefined }));
|
|
121
|
+
const started = yield* Effect.exit(ensureRunning);
|
|
122
|
+
if (Exit.isFailure(started)) {
|
|
123
|
+
return yield* fail(formatError(Cause.squash(started.cause)));
|
|
124
|
+
}
|
|
125
|
+
// The sidecar process spawns before its HTTP server is listening, so retry until the first
|
|
126
|
+
// `list` succeeds rather than reporting a spurious failure on startup.
|
|
127
|
+
const result = yield* runAdmin(
|
|
128
|
+
admin.list.pipe(Effect.retry({ schedule: Schedule.spaced(Duration.millis(300)), times: 29 })),
|
|
129
|
+
);
|
|
130
|
+
if (Either.isLeft(result)) {
|
|
131
|
+
return yield* fail(result.left);
|
|
132
|
+
}
|
|
133
|
+
yield* updateState((state) => ({ ...state, kind: 'ready', models: result.right, error: undefined }));
|
|
134
|
+
yield* Effect.sync(() => log.info('ollama models', { installed: result.right.map((model) => model.name) }));
|
|
135
|
+
yield* refreshLoaded;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const pull = (name: string): Effect.Effect<void> =>
|
|
139
|
+
Effect.gen(function* () {
|
|
140
|
+
const started = yield* Effect.exit(ensureRunning);
|
|
141
|
+
if (Exit.isFailure(started)) {
|
|
142
|
+
return yield* fail(formatError(Cause.squash(started.cause)));
|
|
143
|
+
}
|
|
144
|
+
yield* setError(name, undefined);
|
|
145
|
+
yield* Effect.sync(() => log.info('ollama pull started', { name }));
|
|
146
|
+
yield* setProgress(name, { status: 'starting' });
|
|
147
|
+
|
|
148
|
+
// Ollama reports `completed`/`total` per layer (digest); aggregate across layers so the
|
|
149
|
+
// overall percent is monotonic rather than resetting to 0 as each layer starts.
|
|
150
|
+
const downloaded = new Map<string, { completed: number; total: number }>();
|
|
151
|
+
const onProgress = (progress: OllamaAdmin.PullProgress): Effect.Effect<void> =>
|
|
152
|
+
Effect.suspend(() => {
|
|
153
|
+
if (progress.digest && progress.total) {
|
|
154
|
+
downloaded.set(progress.digest, { completed: progress.completed ?? 0, total: progress.total });
|
|
155
|
+
let completed = 0;
|
|
156
|
+
let total = 0;
|
|
157
|
+
for (const layer of downloaded.values()) {
|
|
158
|
+
completed += layer.completed;
|
|
159
|
+
total += layer.total;
|
|
160
|
+
}
|
|
161
|
+
return setProgress(name, { status: progress.status, completed, total });
|
|
162
|
+
}
|
|
163
|
+
// Non-download phase (manifest, verifying, writing): keep the status label, drop totals.
|
|
164
|
+
return setProgress(name, { status: progress.status });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Run the pull on a daemon fiber so `cancel` can interrupt it; clear progress and drop the
|
|
168
|
+
// fiber on every exit path. A cancelled pull interrupts the fiber — treated as a no-op.
|
|
169
|
+
const work = admin.pull(name).pipe(
|
|
170
|
+
Stream.runForEach(onProgress),
|
|
171
|
+
Effect.provide(clientLayer),
|
|
172
|
+
Effect.matchCauseEffect({
|
|
173
|
+
onFailure: (cause) =>
|
|
174
|
+
Cause.isInterruptedOnly(cause)
|
|
175
|
+
? Effect.sync(() => log.info('ollama pull finished', { name, cancelled: true }))
|
|
176
|
+
: Effect.gen(function* () {
|
|
177
|
+
const message = formatError(Cause.squash(cause));
|
|
178
|
+
yield* Effect.sync(() => log.warn('ollama pull failed', { name, error: message }));
|
|
179
|
+
yield* setError(name, message);
|
|
180
|
+
}),
|
|
181
|
+
onSuccess: () =>
|
|
182
|
+
Effect.gen(function* () {
|
|
183
|
+
yield* Effect.sync(() => log.info('ollama pull finished', { name, cancelled: false }));
|
|
184
|
+
yield* refresh;
|
|
185
|
+
}),
|
|
186
|
+
}),
|
|
187
|
+
Effect.ensuring(setProgress(name, undefined)),
|
|
188
|
+
Effect.ensuring(Effect.sync(() => pullFibers.delete(name))),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const fiber = yield* Effect.forkDaemon(work);
|
|
192
|
+
yield* Effect.sync(() => pullFibers.set(name, fiber));
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const cancel = (name: string): Effect.Effect<void> =>
|
|
196
|
+
Effect.gen(function* () {
|
|
197
|
+
yield* Effect.sync(() => log.info('ollama pull cancelled', { name }));
|
|
198
|
+
const fiber = pullFibers.get(name);
|
|
199
|
+
if (fiber) {
|
|
200
|
+
// The pull's `ensuring` clears progress and drops the fiber on interruption.
|
|
201
|
+
yield* Fiber.interrupt(fiber);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const load = (name: string): Effect.Effect<void> =>
|
|
206
|
+
Effect.gen(function* () {
|
|
207
|
+
yield* setError(name, undefined);
|
|
208
|
+
const started = yield* Effect.exit(ensureRunning);
|
|
209
|
+
if (Exit.isFailure(started)) {
|
|
210
|
+
return yield* setError(name, formatError(Cause.squash(started.cause)));
|
|
211
|
+
}
|
|
212
|
+
yield* Effect.sync(() => log.info('ollama load', { name }));
|
|
213
|
+
const result = yield* runAdmin(admin.load(name));
|
|
214
|
+
if (Either.isLeft(result)) {
|
|
215
|
+
yield* Effect.sync(() => log.warn('ollama load failed', { name, error: result.left }));
|
|
216
|
+
return yield* setError(name, result.left);
|
|
217
|
+
}
|
|
218
|
+
yield* refreshLoaded;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const unload = (name: string): Effect.Effect<void> =>
|
|
222
|
+
Effect.gen(function* () {
|
|
223
|
+
yield* setError(name, undefined);
|
|
224
|
+
const started = yield* Effect.exit(ensureRunning);
|
|
225
|
+
if (Exit.isFailure(started)) {
|
|
226
|
+
return yield* setError(name, formatError(Cause.squash(started.cause)));
|
|
227
|
+
}
|
|
228
|
+
yield* Effect.sync(() => log.info('ollama unload', { name }));
|
|
229
|
+
const result = yield* runAdmin(admin.unload(name));
|
|
230
|
+
if (Either.isLeft(result)) {
|
|
231
|
+
return yield* setError(name, result.left);
|
|
232
|
+
}
|
|
233
|
+
yield* refreshLoaded;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const remove = (name: string): Effect.Effect<void> =>
|
|
237
|
+
Effect.gen(function* () {
|
|
238
|
+
yield* setError(name, undefined);
|
|
239
|
+
const started = yield* Effect.exit(ensureRunning);
|
|
240
|
+
if (Exit.isFailure(started)) {
|
|
241
|
+
return yield* setError(name, formatError(Cause.squash(started.cause)));
|
|
242
|
+
}
|
|
243
|
+
const result = yield* runAdmin(admin.remove(name));
|
|
244
|
+
if (Either.isLeft(result)) {
|
|
245
|
+
return yield* setError(name, result.left);
|
|
246
|
+
}
|
|
247
|
+
yield* refresh;
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const manager: Ollama.Manager = {
|
|
251
|
+
endpoint: OLLAMA_HOST,
|
|
252
|
+
state: stateAtom,
|
|
253
|
+
refresh,
|
|
254
|
+
refreshLoaded,
|
|
255
|
+
pull,
|
|
256
|
+
cancel,
|
|
257
|
+
load,
|
|
258
|
+
unload,
|
|
259
|
+
remove,
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
return [
|
|
263
|
+
// The runtime-dispose finalizer lives on the resolver contribution only; the manager closes
|
|
264
|
+
// over the same runtime, so there is a single disposal path.
|
|
265
|
+
Capability.contributes(
|
|
266
|
+
AppCapabilities.AiModelResolver,
|
|
267
|
+
OllamaSidecarModelResolver.pipe(Layer.provide(sidecarLayer)),
|
|
268
|
+
() => Effect.tryPromise(() => runtime.dispose()),
|
|
269
|
+
),
|
|
270
|
+
Capability.contributes(AssistantCapabilities.OllamaManager, manager),
|
|
271
|
+
];
|
|
38
272
|
}),
|
|
39
273
|
);
|
|
40
274
|
|
|
@@ -47,6 +281,9 @@ class OllamaSidecar extends Context.Tag('@dxos/plugin-native/OllamaSidecar')<
|
|
|
47
281
|
static layerLive = Layer.scoped(
|
|
48
282
|
OllamaSidecar,
|
|
49
283
|
Effect.gen(function* () {
|
|
284
|
+
// The `ollama` launcher discovers `llama-server` + its libraries relative to its own
|
|
285
|
+
// executable (`<exe>/lib/ollama/`), ignoring OLLAMA_LIBRARY_PATH, so the runtime ships into
|
|
286
|
+
// `Contents/MacOS/lib/ollama` next to the signed sidecar (see tauri.conf bundle.macOS.files).
|
|
50
287
|
const command = Command.sidecar('sidecar/ollama', ['serve'], {
|
|
51
288
|
env: {
|
|
52
289
|
OLLAMA_HOST,
|
|
@@ -54,11 +291,11 @@ class OllamaSidecar extends Context.Tag('@dxos/plugin-native/OllamaSidecar')<
|
|
|
54
291
|
},
|
|
55
292
|
});
|
|
56
293
|
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
command.stderr.on('data', (data) =>
|
|
294
|
+
// Ollama writes nearly all of its output (including normal startup/inference logs) to stderr,
|
|
295
|
+
// so route by the structured `level=` field rather than the stream to avoid flooding the
|
|
296
|
+
// console with red errors. Kept on `console.*` for Ollama's own line formatting.
|
|
297
|
+
command.stdout.on('data', (data) => logSidecar(data.toString()));
|
|
298
|
+
command.stderr.on('data', (data) => logSidecar(data.toString()));
|
|
62
299
|
command.on('close', (code) => log.info('Ollama process exited', { code }));
|
|
63
300
|
command.on('error', (error) => log.error('Ollama error', { error }));
|
|
64
301
|
const child = yield* Effect.promise(() => command.spawn());
|
|
@@ -82,7 +319,35 @@ const OllamaSidecarModelResolver: Layer.Layer<AiModelResolver.AiModelResolver, n
|
|
|
82
319
|
const { endpoint } = yield* OllamaSidecar;
|
|
83
320
|
return OllamaResolver.make({
|
|
84
321
|
endpoint,
|
|
322
|
+
provider: Provider.builtIn.id,
|
|
85
323
|
transformClient: HttpClient.withTracerPropagation(false),
|
|
86
324
|
});
|
|
87
325
|
}),
|
|
88
326
|
).pipe(Layer.provide(FetchHttpClient.layer));
|
|
327
|
+
|
|
328
|
+
const formatError = (error: unknown): string =>
|
|
329
|
+
typeof error === 'string' ? error : error instanceof Error ? error.message : String(error);
|
|
330
|
+
|
|
331
|
+
/** Effect HttpClient layer shared by every admin call. */
|
|
332
|
+
const clientLayer = FetchHttpClient.layer;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Route a chunk of Ollama process output to the console by its structured log level. Ollama emits
|
|
336
|
+
* `INFO`/`WARN` to stderr alongside genuine errors, so only `level=ERROR` lines surface as errors.
|
|
337
|
+
*/
|
|
338
|
+
const logSidecar = (chunk: string): void => {
|
|
339
|
+
for (const line of chunk.split('\n')) {
|
|
340
|
+
if (line.trim().length === 0) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
/* eslint-disable no-console */
|
|
344
|
+
if (line.includes('level=ERROR')) {
|
|
345
|
+
console.error('[ollama]', line);
|
|
346
|
+
} else if (line.includes('level=WARN')) {
|
|
347
|
+
console.warn('[ollama]', line);
|
|
348
|
+
} else {
|
|
349
|
+
console.log('[ollama]', line);
|
|
350
|
+
}
|
|
351
|
+
/* eslint-enable no-console */
|
|
352
|
+
}
|
|
353
|
+
};
|
|
@@ -9,7 +9,7 @@ import { Capabilities, Capability } from '@dxos/app-framework';
|
|
|
9
9
|
import { Surface, useSettingsState } from '@dxos/app-framework/ui';
|
|
10
10
|
import { AppSurface } from '@dxos/app-toolkit/ui';
|
|
11
11
|
|
|
12
|
-
import { NativeSettings } from '#
|
|
12
|
+
import { NativeSettings } from '#containers';
|
|
13
13
|
import { meta } from '#meta';
|
|
14
14
|
import { type Settings } from '#types';
|
|
15
15
|
|
|
@@ -5,17 +5,18 @@
|
|
|
5
5
|
import { useAtomValue } from '@effect-atom/atom-react';
|
|
6
6
|
import { formatDistanceToNow } from 'date-fns/formatDistanceToNow';
|
|
7
7
|
import * as Match from 'effect/Match';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
8
9
|
import React, { type ReactNode, useState } from 'react';
|
|
9
10
|
|
|
10
11
|
import { useCapability } from '@dxos/app-framework/ui';
|
|
11
12
|
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
12
13
|
import { Button, useTranslation } from '@dxos/react-ui';
|
|
13
|
-
import {
|
|
14
|
+
import { Form } from '@dxos/react-ui-form';
|
|
14
15
|
|
|
15
16
|
import { meta } from '#meta';
|
|
16
17
|
import { NativeCapabilities, type Settings, type Update } from '#types';
|
|
17
18
|
|
|
18
|
-
export type NativeSettingsProps = AppSurface.
|
|
19
|
+
export type NativeSettingsProps = AppSurface.SettingsProps<Settings.Settings>;
|
|
19
20
|
|
|
20
21
|
type Pending = null | 'check' | 'install' | 'relaunch';
|
|
21
22
|
|
|
@@ -53,13 +54,17 @@ export const NativeSettings = (_props: NativeSettingsProps) => {
|
|
|
53
54
|
});
|
|
54
55
|
|
|
55
56
|
return (
|
|
56
|
-
<
|
|
57
|
-
<
|
|
58
|
-
<
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
<Form.Root schema={Schema.Struct({})} values={{}} variant='settings'>
|
|
58
|
+
<Form.Viewport scroll>
|
|
59
|
+
<Form.Content>
|
|
60
|
+
<Form.Section title={meta.profile.name ?? meta.profile.key}>
|
|
61
|
+
<Form.Row label={t('settings.updates.label')} description={description}>
|
|
62
|
+
{button}
|
|
63
|
+
</Form.Row>
|
|
64
|
+
</Form.Section>
|
|
65
|
+
</Form.Content>
|
|
66
|
+
</Form.Viewport>
|
|
67
|
+
</Form.Root>
|
|
63
68
|
);
|
|
64
69
|
};
|
|
65
70
|
|
package/src/translations.ts
CHANGED
|
@@ -14,7 +14,6 @@ export const translations = [
|
|
|
14
14
|
'update-ready.description': 'A new version of Composer is available.',
|
|
15
15
|
'update.label': 'Update',
|
|
16
16
|
'update.alt': 'Relaunch the app to update',
|
|
17
|
-
'settings.title': 'App',
|
|
18
17
|
'settings.updates.label': 'Updates',
|
|
19
18
|
'settings.updates.check.label': 'Check for updates',
|
|
20
19
|
'settings.updates.checking.label': 'Checking…',
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/NativeSettings/NativeSettings.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useAtomValue } from '@effect-atom/atom-react';\nimport { formatDistanceToNow } from 'date-fns/formatDistanceToNow';\nimport * as Match from 'effect/Match';\nimport React, { type ReactNode, useState } from 'react';\n\nimport { useCapability } from '@dxos/app-framework/ui';\nimport { type AppSurface } from '@dxos/app-toolkit/ui';\nimport { Button, useTranslation } from '@dxos/react-ui';\nimport { Settings as SettingsForm } from '@dxos/react-ui-form';\n\nimport { meta } from '#meta';\nimport { NativeCapabilities, type Settings, type Update } from '#types';\n\nexport type NativeSettingsProps = AppSurface.SettingsArticleProps<Settings.Settings>;\n\ntype Pending = null | 'check' | 'install' | 'relaunch';\n\ntype UpdateActions = {\n onCheck: () => Promise<void>;\n onInstall: () => Promise<void>;\n onRelaunch: () => Promise<void>;\n};\n\ntype UpdateRow = { description: string; button: ReactNode };\n\nexport const NativeSettings = (_props: NativeSettingsProps) => {\n const { t } = useTranslation(meta.profile.key);\n const manager = useCapability(NativeCapabilities.UpdateManager);\n const status = useAtomValue(manager.status);\n\n // UI-level pending flag. The status atom can flip between `checking` and `up-to-date` faster\n // than the user can perceive, so we also gate the button on the click handler's lifetime to\n // guarantee no duplicate triggers and a visible busy state.\n const [pending, setPending] = useState<Pending>(null);\n\n const runAction = (kind: Exclude<Pending, null>, action: () => Promise<void>) => async () => {\n setPending(kind);\n try {\n await action();\n } finally {\n setPending(null);\n }\n };\n\n const { description, button } = renderUpdateRow(status, pending, t, {\n onCheck: runAction('check', manager.check),\n onInstall: runAction('install', manager.install),\n onRelaunch: runAction('relaunch', manager.relaunch),\n });\n\n return (\n <SettingsForm.Viewport>\n <SettingsForm.Section title={t('settings.title')}>\n <SettingsForm.Item title={t('settings.updates.label')} description={description}>\n {button}\n </SettingsForm.Item>\n </SettingsForm.Section>\n </SettingsForm.Viewport>\n );\n};\n\nconst renderUpdateRow = (\n status: Update.Status,\n pending: Pending,\n t: (key: string, options?: Record<string, unknown>) => string,\n { onCheck, onInstall, onRelaunch }: UpdateActions,\n): UpdateRow => {\n const isChecking = pending === 'check' || status.kind === 'checking';\n const isInstalling = pending === 'install' || status.kind === 'downloading';\n\n const checkButton = (disabled = false) => (\n <Button disabled={disabled || isChecking || isInstalling || pending === 'relaunch'} onClick={() => void onCheck()}>\n {isChecking ? t('settings.updates.checking.label') : t('settings.updates.check.label')}\n </Button>\n );\n\n return Match.value(status).pipe(\n Match.withReturnType<UpdateRow>(),\n Match.when({ kind: 'unsupported' }, () => ({\n description: t('settings.updates.unsupported.message'),\n button: checkButton(true),\n })),\n Match.when({ kind: 'idle' }, () => ({\n description: isChecking ? t('settings.updates.checking.message') : t('settings.updates.idle.message'),\n button: checkButton(),\n })),\n Match.when({ kind: 'checking' }, () => ({\n description: t('settings.updates.checking.message'),\n button: checkButton(),\n })),\n Match.when({ kind: 'up-to-date' }, (s) => ({\n description: isChecking\n ? t('settings.updates.checking.message')\n : t('settings.updates.up-to-date.message', {\n checkedAt: formatDistanceToNow(new Date(s.checkedAt), { addSuffix: true }),\n }),\n button: checkButton(),\n })),\n Match.when({ kind: 'available' }, (s) => ({\n description: t('settings.updates.available.message', { version: s.version }),\n button: (\n <Button variant='primary' disabled={isInstalling} onClick={() => void onInstall()}>\n {isInstalling ? t('settings.updates.downloading.label') : t('settings.updates.update-now.label')}\n </Button>\n ),\n })),\n Match.when({ kind: 'downloading' }, (s) => {\n const percent = s.contentLength > 0 ? Math.round((s.downloaded / s.contentLength) * 100) : 0;\n return {\n description: t('settings.updates.downloading.message', { percent }),\n button: <Button disabled>{t('settings.updates.downloading.label')}</Button>,\n };\n }),\n Match.when({ kind: 'ready' }, () => ({\n description: t('settings.updates.ready.message'),\n button: (\n <Button variant='primary' disabled={pending === 'relaunch'} onClick={() => void onRelaunch()}>\n {t('settings.updates.relaunch.label')}\n </Button>\n ),\n })),\n Match.when({ kind: 'failed' }, (s) => ({\n description: t('settings.updates.failed.message', { error: s.error }),\n button: checkButton(),\n })),\n Match.exhaustive,\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,oBAAoB;AAC7B,SAASC,2BAA2B;AACpC,YAAYC,WAAW;AACvB,OAAOC,SAAyBC,gBAAgB;AAEhD,SAASC,qBAAqB;AAE9B,SAASC,QAAQC,sBAAsB;AACvC,SAASC,YAAYC,oBAAoB;AAEzC,SAASC,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,MAAM;EAAQ,GAAG,OAAO;IACnCE,aAAaX,EAAE,gCAAA;IACfY,QACE,sBAAA,cAACpB,QAAAA;MAAO8C,SAAQ;MAAUX,UAAUrB,YAAY;MAAYsB,SAAS,MAAM,KAAKV,WAAAA;OAC7ElB,EAAE,iCAAA,CAAA;EAGT,EAAA,GACMgC,WAAK;IAAEvB,MAAM;EAAS,GAAG,CAACwB,OAAO;IACrCtB,aAAaX,EAAE,mCAAmC;MAAE4C,OAAOX,EAAEW;IAAM,CAAA;IACnEhC,QAAQc,YAAAA;EACV,EAAA,GACMmB,gBAAU;AAEpB;",
|
|
6
|
-
"names": ["useAtomValue", "formatDistanceToNow", "Match", "React", "useState", "useCapability", "Button", "useTranslation", "Settings", "SettingsForm", "meta", "NativeCapabilities", "NativeSettings", "_props", "t", "profile", "key", "manager", "UpdateManager", "status", "pending", "setPending", "runAction", "kind", "action", "description", "button", "renderUpdateRow", "onCheck", "check", "onInstall", "install", "onRelaunch", "relaunch", "Viewport", "Section", "title", "Item", "isChecking", "isInstalling", "checkButton", "disabled", "onClick", "value", "pipe", "withReturnType", "when", "s", "checkedAt", "Date", "addSuffix", "version", "variant", "percent", "contentLength", "Math", "round", "downloaded", "error", "exhaustive"]
|
|
7
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import "./chunk-J5LGTIGS.mjs";
|
|
2
|
-
|
|
3
|
-
// src/capabilities/ollama.ts
|
|
4
|
-
import * as FetchHttpClient from "@effect/platform/FetchHttpClient";
|
|
5
|
-
import * as HttpClient from "@effect/platform/HttpClient";
|
|
6
|
-
import { Command } from "@tauri-apps/plugin-shell";
|
|
7
|
-
import * as Context from "effect/Context";
|
|
8
|
-
import * as Effect from "effect/Effect";
|
|
9
|
-
import * as Layer from "effect/Layer";
|
|
10
|
-
import * as ManagedRuntime from "effect/ManagedRuntime";
|
|
11
|
-
import { OllamaResolver } from "@dxos/ai/resolvers";
|
|
12
|
-
import { Capability } from "@dxos/app-framework";
|
|
13
|
-
import { AppCapabilities } from "@dxos/app-toolkit";
|
|
14
|
-
import { log } from "@dxos/log";
|
|
15
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-native/src/capabilities/ollama.ts";
|
|
16
|
-
var OLLAMA_HOST = "http://localhost:21434";
|
|
17
|
-
var ollama_default = Capability.makeModule(() => Effect.sync(() => {
|
|
18
|
-
const runtime = ManagedRuntime.make(OllamaSidecar.layerLive);
|
|
19
|
-
const sidecarLayer = Layer.effectContext(runtime.runtimeEffect.pipe(Effect.map((rt) => rt.context.pipe(Context.pick(OllamaSidecar)))));
|
|
20
|
-
return Capability.contributes(AppCapabilities.AiModelResolver, OllamaSidecarModelResolver.pipe(Layer.provide(sidecarLayer)), () => Effect.tryPromise(() => runtime.dispose()));
|
|
21
|
-
}));
|
|
22
|
-
var OllamaSidecar = class _OllamaSidecar extends Context.Tag("@dxos/plugin-native/OllamaSidecar")() {
|
|
23
|
-
static layerLive = Layer.scoped(_OllamaSidecar, Effect.gen(function* () {
|
|
24
|
-
const command = Command.sidecar("sidecar/ollama", [
|
|
25
|
-
"serve"
|
|
26
|
-
], {
|
|
27
|
-
env: {
|
|
28
|
-
OLLAMA_HOST,
|
|
29
|
-
OLLAMA_ORIGINS: "*"
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
command.stdout.on("data", (data) => console.log("[ollama]", data.toString()));
|
|
33
|
-
command.stderr.on("data", (data) => console.error("[ollama]", data.toString()));
|
|
34
|
-
command.on("close", (code) => log.info("Ollama process exited", {
|
|
35
|
-
code
|
|
36
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 38, S: this }));
|
|
37
|
-
command.on("error", (error) => log.error("Ollama error", {
|
|
38
|
-
error
|
|
39
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 41, S: this }));
|
|
40
|
-
const child = yield* Effect.promise(() => command.spawn());
|
|
41
|
-
yield* Effect.addFinalizer(Effect.fn(function* () {
|
|
42
|
-
yield* Effect.promise(() => child.kill());
|
|
43
|
-
}));
|
|
44
|
-
log.info("Running ollama", {
|
|
45
|
-
pid: child.pid
|
|
46
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 48, S: this });
|
|
47
|
-
return {
|
|
48
|
-
endpoint: OLLAMA_HOST
|
|
49
|
-
};
|
|
50
|
-
}));
|
|
51
|
-
};
|
|
52
|
-
var OllamaSidecarModelResolver = Layer.unwrapEffect(Effect.gen(function* () {
|
|
53
|
-
const { endpoint } = yield* OllamaSidecar;
|
|
54
|
-
return OllamaResolver.make({
|
|
55
|
-
endpoint,
|
|
56
|
-
transformClient: HttpClient.withTracerPropagation(false)
|
|
57
|
-
});
|
|
58
|
-
})).pipe(Layer.provide(FetchHttpClient.layer));
|
|
59
|
-
export {
|
|
60
|
-
ollama_default as default
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=ollama-BHWFTROM.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/capabilities/ollama.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as FetchHttpClient from '@effect/platform/FetchHttpClient';\nimport * as HttpClient from '@effect/platform/HttpClient';\nimport { Command } from '@tauri-apps/plugin-shell';\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as ManagedRuntime from 'effect/ManagedRuntime';\n\nimport { type AiModelResolver } from '@dxos/ai';\nimport { OllamaResolver } from '@dxos/ai/resolvers';\nimport { Capability } from '@dxos/app-framework';\nimport { AppCapabilities } from '@dxos/app-toolkit';\nimport { log } from '@dxos/log';\n\n// NOTE: Running ollama on non-standard port (config Tauri).\nconst OLLAMA_HOST = 'http://localhost:21434';\n\nexport type OllamaCapabilities = Capability.Capability<typeof AppCapabilities.AiModelResolver>;\n\nexport default Capability.makeModule<[], OllamaCapabilities>(() =>\n Effect.sync(() => {\n const runtime = ManagedRuntime.make(OllamaSidecar.layerLive);\n\n // Layer for the sidecar but the lifecycle is managed by the runtime.\n const sidecarLayer = Layer.effectContext(\n runtime.runtimeEffect.pipe(Effect.map((rt) => rt.context.pipe(Context.pick(OllamaSidecar)))),\n );\n\n return Capability.contributes(\n AppCapabilities.AiModelResolver,\n OllamaSidecarModelResolver.pipe(Layer.provide(sidecarLayer)),\n () => Effect.tryPromise(() => runtime.dispose()),\n );\n }),\n);\n\nclass OllamaSidecar extends Context.Tag('@dxos/plugin-native/OllamaSidecar')<\n OllamaSidecar,\n {\n endpoint: string;\n }\n>() {\n static layerLive = Layer.scoped(\n OllamaSidecar,\n Effect.gen(function* () {\n const command = Command.sidecar('sidecar/ollama', ['serve'], {\n env: {\n OLLAMA_HOST,\n OLLAMA_ORIGINS: '*', // CORS\n },\n });\n\n // NOTE: Keeping those as console.log for consistent formatting.\n // eslint-disable-next-line no-console\n command.stdout.on('data', (data) => console.log('[ollama]', data.toString()));\n // eslint-disable-next-line no-console\n command.stderr.on('data', (data) => console.error('[ollama]', data.toString()));\n command.on('close', (code) => log.info('Ollama process exited', { code }));\n command.on('error', (error) => log.error('Ollama error', { error }));\n const child = yield* Effect.promise(() => command.spawn());\n yield* Effect.addFinalizer(\n Effect.fn(function* () {\n yield* Effect.promise(() => child.kill());\n }),\n );\n log.info('Running ollama', { pid: child.pid });\n\n return {\n endpoint: OLLAMA_HOST,\n };\n }),\n );\n}\n\nconst OllamaSidecarModelResolver: Layer.Layer<AiModelResolver.AiModelResolver, never, OllamaSidecar> =\n Layer.unwrapEffect(\n Effect.gen(function* () {\n const { endpoint } = yield* OllamaSidecar;\n return OllamaResolver.make({\n endpoint,\n transformClient: HttpClient.withTracerPropagation(false),\n });\n }),\n ).pipe(Layer.provide(FetchHttpClient.layer));\n"],
|
|
5
|
-
"mappings": ";;;AAIA,YAAYA,qBAAqB;AACjC,YAAYC,gBAAgB;AAC5B,SAASC,eAAe;AACxB,YAAYC,aAAa;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,MAAA,KAAA,CAAA;;AAAiB,QAAA,KAAA,kBAAA;MAE5C,KAAO,MAAA;qBACKC,YAAAA,GAAAA,cAAAA,GAAAA,IAAAA,GAAAA,KAAAA,CAAAA;AACZ,WAAA;MAEF,UAAA;IACJ;EAEA,CAAA,CAAMC;;IAIA,6BAA2B,mBAAA,WAAA,aAAA;QACzBC,EAAAA,SAAAA,IAAAA,OAAAA;SACAC,eAAiBlC,KAAAA;IACnB;IAEE,iBAAeD,iCAAqB,KAAA;;;",
|
|
6
|
-
"names": ["FetchHttpClient", "HttpClient", "Command", "Context", "Effect", "Layer", "ManagedRuntime", "OllamaResolver", "Capability", "AppCapabilities", "log", "runtime", "sidecarLayer", "effectContext", "runtimeEffect", "OllamaSidecar", "Tag", "sidecar", "env", "OLLAMA_ORIGINS", "command", "stderr", "on", "data", "console", "error", "toString", "code", "child", "addFinalizer", "kill", "info", "OLLAMA_HOST", "OllamaSidecarModelResolver", "endpoint", "transformClient"]
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativeSettings.d.ts","sourceRoot":"","sources":["../../../../../src/components/NativeSettings/NativeSettings.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAmC,MAAM,OAAO,CAAC;AAGxD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKvD,OAAO,EAAsB,KAAK,QAAQ,EAAe,MAAM,QAAQ,CAAC;AAExE,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,oBAAoB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAYrF,eAAO,MAAM,cAAc,WAAY,mBAAmB,sBAkCzD,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|