@kehto/paja 0.26.0 → 0.27.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.
@@ -2212,8 +2212,8 @@ function countCharacters(request) {
2212
2212
  }
2213
2213
  function createPajaLlmHost(options) {
2214
2214
  const { store, vault, confirm, getIdentity } = options;
2215
- const provider = options.provider ?? createHttpLlmProvider();
2216
- async function ensureCredential(record) {
2215
+ const provider = options.provider ?? createHttpLlmProvider({ stream: true });
2216
+ async function ensureCredential(record, signal) {
2217
2217
  if (record.credentialStorage === "none") return void 0;
2218
2218
  const existing = vault.getCredential(record.id);
2219
2219
  if (existing !== void 0) return existing;
@@ -2222,7 +2222,7 @@ function createPajaLlmHost(options) {
2222
2222
  throw new LlmServiceError("unsupported", "This connection's API key was kept for one session only. Enter it again in Language models.");
2223
2223
  }
2224
2224
  if (!vault.isUnlocked()) {
2225
- const unlocked = await options.requestUnlock();
2225
+ const unlocked = await options.requestUnlock(signal);
2226
2226
  if (!unlocked) throw new LlmServiceError("user-cancelled", "The credential vault stayed locked.");
2227
2227
  }
2228
2228
  const credential = vault.getCredential(record.id);
@@ -2232,16 +2232,17 @@ function createPajaLlmHost(options) {
2232
2232
  }
2233
2233
  return credential;
2234
2234
  }
2235
- async function select(context, requirements) {
2235
+ async function select(context, requirements, prompt) {
2236
+ const signal = prompt?.signal;
2236
2237
  const napplet = getIdentity(context.windowId);
2237
2238
  const candidates = store.list().filter((record) => meets(record, requirements));
2238
2239
  if (candidates.length === 0) {
2239
- const configure = await confirm({ action: "llm-configure", windowId: context.windowId, napplet, requirements: describeRequirements(requirements), configured: store.list().length });
2240
+ const configure = await confirm({ action: "llm-configure", windowId: context.windowId, napplet, requirements: describeRequirements(requirements), configured: store.list().length, ...signal ? { signal } : {} });
2240
2241
  if (!configure) return null;
2241
2242
  options.openPanel();
2242
2243
  throw new LlmServiceError("unsupported", "No compatible language model connection is configured yet. Add one in Paja's Language models panel, then select again.");
2243
2244
  }
2244
- const chosen = await options.chooseConnection(candidates, { windowId: context.windowId, napplet, requirements });
2245
+ const chosen = await options.chooseConnection(candidates, { windowId: context.windowId, napplet, requirements, ...signal ? { signal } : {} });
2245
2246
  if (!chosen) return null;
2246
2247
  const current = store.get(chosen.id);
2247
2248
  return current && meets(current, requirements) ? toConnection(current) : null;
@@ -2253,11 +2254,14 @@ function createPajaLlmHost(options) {
2253
2254
  const record = store.get(connectionId);
2254
2255
  return record ? toConnection(record) : null;
2255
2256
  },
2256
- async authorize(context, connection, request) {
2257
+ async authorize(context, connection, request, prompt) {
2258
+ const signal = prompt?.signal;
2257
2259
  const record = store.get(connection.id);
2258
2260
  if (!record) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
2259
- await ensureCredential(record);
2261
+ await ensureCredential(record, signal);
2262
+ if (signal?.aborted) return false;
2260
2263
  return confirm({
2264
+ ...signal ? { signal } : {},
2261
2265
  action: "llm",
2262
2266
  windowId: context.windowId,
2263
2267
  napplet: getIdentity(context.windowId),
@@ -2281,7 +2285,7 @@ function createPajaLlmHost(options) {
2281
2285
  model: record.model,
2282
2286
  ...credential === void 0 ? {} : { credential },
2283
2287
  ...record.credentialHeader ? { credentialHeader: record.credentialHeader } : {}
2284
- }, request, hooks.signal);
2288
+ }, request, hooks.signal, (text) => hooks.onDelta(text));
2285
2289
  },
2286
2290
  subscribe(listener) {
2287
2291
  const stopStore = store.subscribe(listener);
@@ -2507,4 +2511,4 @@ export {
2507
2511
  validatePajaLlmVaultPassword,
2508
2512
  createPajaLlmVault
2509
2513
  };
2510
- //# sourceMappingURL=chunk-EYSQOKVF.js.map
2514
+ //# sourceMappingURL=chunk-M5ZFET3T.js.map