@kehto/paja 0.31.0 → 0.32.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.
@@ -807,6 +807,9 @@ function renderPajaHtml(config) {
807
807
  <label class="llm-check"><input id="paja-llm-remember" type="checkbox"><span>Remember the key, encrypted with a vault password</span></label>
808
808
  <label class="llm-check"><input id="paja-llm-images" type="checkbox"><span>Accepts image input</span></label>
809
809
  <label class="llm-check"><input id="paja-llm-json" type="checkbox" checked><span>Supports JSON-object output</span></label>
810
+ <label class="llm-check"><input id="paja-llm-tools" type="checkbox"><span>Tool calling</span></label>
811
+ <label class="llm-check"><input id="paja-llm-tool-required" type="checkbox" disabled><span>Required tool choice</span></label>
812
+ <label class="llm-check"><input id="paja-llm-tool-named" type="checkbox" disabled><span>Named tool choice</span></label>
810
813
  <div class="llm-actions">
811
814
  <button type="submit" id="paja-llm-save">Add connection</button>
812
815
  <button type="button" id="paja-llm-vault-lock" hidden>Lock vault</button>
@@ -2167,6 +2170,7 @@ function normalizeServerTargetUrl(value) {
2167
2170
  import {
2168
2171
  LLM_PROVIDER_PRESETS,
2169
2172
  LlmServiceError,
2173
+ buildLlmProviderRequest,
2170
2174
  createHttpLlmProvider,
2171
2175
  countLlmImages
2172
2176
  } from "@kehto/services";
@@ -2174,6 +2178,7 @@ var PAJA_LLM_CONNECTIONS_STORAGE_KEY = "kehto:paja:llm-connections:v1";
2174
2178
  var MAX_CONNECTIONS = 32;
2175
2179
  var PROTOCOLS = /* @__PURE__ */ new Set(["openai-chat", "anthropic-messages", "gemini"]);
2176
2180
  var CREDENTIAL_HEADERS = /* @__PURE__ */ new Set(["authorization-bearer", "api-key", "x-api-key", "x-goog-api-key"]);
2181
+ var TOOL_CHOICE_ORDER = ["auto", "none", "required", "tool"];
2177
2182
  var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
2178
2183
  function normalizePajaLlmBaseUrl(value) {
2179
2184
  let url;
@@ -2193,6 +2198,11 @@ function normalizePajaLlmBaseUrl(value) {
2193
2198
  function isRecord2(value) {
2194
2199
  return typeof value === "object" && value !== null && !Array.isArray(value);
2195
2200
  }
2201
+ function canonicalToolChoiceModes(tools, requested) {
2202
+ if (!tools) return [];
2203
+ const wanted = new Set(Array.isArray(requested) ? requested : []);
2204
+ return TOOL_CHOICE_ORDER.filter((mode) => mode === "auto" || mode === "none" || wanted.has(mode));
2205
+ }
2196
2206
  function normalizeRecord(input) {
2197
2207
  const text = (value) => typeof value === "string" ? value : "";
2198
2208
  const name = text(input.name).trim();
@@ -2207,6 +2217,7 @@ function normalizeRecord(input) {
2207
2217
  if (!PROTOCOLS.has(protocol)) throw new Error("Unknown provider protocol.");
2208
2218
  if (credentialHeader !== void 0 && !CREDENTIAL_HEADERS.has(credentialHeader)) throw new Error("Unknown credential header.");
2209
2219
  if (!["vault", "session", "none"].includes(credentialStorage)) throw new Error("Unknown credential storage.");
2220
+ const tools = input.tools === true;
2210
2221
  const record = {
2211
2222
  id,
2212
2223
  name,
@@ -2216,6 +2227,8 @@ function normalizeRecord(input) {
2216
2227
  model,
2217
2228
  images: input.images === true,
2218
2229
  json: input.json === true,
2230
+ tools,
2231
+ toolChoiceModes: Object.freeze(canonicalToolChoiceModes(tools, input.toolChoiceModes)),
2219
2232
  credentialStorage,
2220
2233
  ...credentialHeader ? { credentialHeader } : {}
2221
2234
  };
@@ -2287,29 +2300,59 @@ function describePajaLlmRoute(record) {
2287
2300
  return `Paja (this browser) \u2192 ${label}`;
2288
2301
  }
2289
2302
  function toConnection(record) {
2290
- return { id: record.id, name: record.name, model: record.model, route: describePajaLlmRoute(record), images: record.images, json: record.json };
2303
+ const tools = record.tools === true;
2304
+ return {
2305
+ id: record.id,
2306
+ name: record.name,
2307
+ model: record.model,
2308
+ route: describePajaLlmRoute(record),
2309
+ images: record.images,
2310
+ json: record.json,
2311
+ tools,
2312
+ toolChoiceModes: tools ? canonicalToolChoiceModes(true, record.toolChoiceModes) : []
2313
+ };
2291
2314
  }
2292
2315
  function meets(record, requirements) {
2293
2316
  if (requirements.model !== void 0 && requirements.model !== record.model) return false;
2294
2317
  if (requirements.images === true && !record.images) return false;
2318
+ if (requirements.tools === true && record.tools !== true) return false;
2295
2319
  return !(requirements.json === true && !record.json);
2296
2320
  }
2297
2321
  function describeRequirements(requirements) {
2298
2322
  const parts = [
2299
2323
  requirements.model ? `model ${requirements.model}` : "any model",
2300
2324
  requirements.images ? "image input" : null,
2301
- requirements.json ? "JSON output" : null
2325
+ requirements.json ? "JSON output" : null,
2326
+ requirements.tools ? "tool calling" : null
2302
2327
  ].filter((part) => part !== null);
2303
2328
  return parts.join(", ");
2304
2329
  }
2305
2330
  function countCharacters(request) {
2306
2331
  let total = 0;
2307
- for (const message of request.messages) for (const part of message.content) total += part.type === "text" ? part.text.length : 0;
2332
+ for (const message of request.messages) {
2333
+ for (const part of message.content) {
2334
+ if (part.type === "text") total += part.text.length;
2335
+ else if (part.type === "toolCall") total += JSON.stringify(part.arguments).length;
2336
+ }
2337
+ }
2338
+ for (const tool of request.tools ?? []) total += JSON.stringify(tool).length;
2308
2339
  return total;
2309
2340
  }
2341
+ function countToolResults(request) {
2342
+ return request.messages.filter((message) => message.role === "toolResult").length;
2343
+ }
2310
2344
  function createPajaLlmHost(options) {
2311
2345
  const { store, vault, confirm, getIdentity } = options;
2312
2346
  const provider = options.provider ?? createHttpLlmProvider({ stream: true });
2347
+ function endpointFor(record, credential) {
2348
+ return {
2349
+ protocol: record.protocol,
2350
+ baseUrl: record.baseUrl,
2351
+ model: record.model,
2352
+ ...credential === void 0 ? {} : { credential },
2353
+ ...record.credentialHeader ? { credentialHeader: record.credentialHeader } : {}
2354
+ };
2355
+ }
2313
2356
  async function ensureCredential(record, signal) {
2314
2357
  if (record.credentialStorage === "none") return void 0;
2315
2358
  const existing = vault.getCredential(record.id);
@@ -2355,6 +2398,7 @@ function createPajaLlmHost(options) {
2355
2398
  const signal = prompt?.signal;
2356
2399
  const record = store.get(connection.id);
2357
2400
  if (!record) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
2401
+ buildLlmProviderRequest(endpointFor(record), request, { stream: true });
2358
2402
  await ensureCredential(record, signal);
2359
2403
  if (signal?.aborted) return false;
2360
2404
  return confirm({
@@ -2368,21 +2412,17 @@ function createPajaLlmHost(options) {
2368
2412
  messages: request.messages.length,
2369
2413
  characters: countCharacters(request),
2370
2414
  images: countLlmImages(request.messages),
2415
+ tools: (request.tools ?? []).map((tool) => tool.name),
2416
+ toolResults: countToolResults(request),
2371
2417
  format: request.format ?? "text",
2372
- warning: "The prompt text and images below leave this device for the provider named in the route. Provider charges and retention follow that service's terms."
2418
+ warning: "The prompt text, images, tool definitions and tool results disclosed here leave this device for the provider named in the route. Provider charges and retention follow that service's terms."
2373
2419
  });
2374
2420
  },
2375
2421
  async generate(_context, connection, request, hooks) {
2376
2422
  const record = store.get(connection.id);
2377
2423
  if (!record) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
2378
2424
  const credential = await ensureCredential(record);
2379
- return provider({
2380
- protocol: record.protocol,
2381
- baseUrl: record.baseUrl,
2382
- model: record.model,
2383
- ...credential === void 0 ? {} : { credential },
2384
- ...record.credentialHeader ? { credentialHeader: record.credentialHeader } : {}
2385
- }, request, hooks.signal, (text) => hooks.onDelta(text));
2425
+ return provider(endpointFor(record, credential), request, hooks.signal, (event) => hooks.onDelta(event));
2386
2426
  },
2387
2427
  subscribe(listener) {
2388
2428
  const stopStore = store.subscribe(listener);
@@ -2609,4 +2649,4 @@ export {
2609
2649
  validatePajaLlmVaultPassword,
2610
2650
  createPajaLlmVault
2611
2651
  };
2612
- //# sourceMappingURL=chunk-JVTK35QF.js.map
2652
+ //# sourceMappingURL=chunk-DDYBKY5L.js.map