@kehto/paja 0.30.0 → 0.32.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.
@@ -275,6 +275,7 @@ function mergePajaRawOptions(base, override) {
275
275
  port: override.port ?? base.port,
276
276
  readyTimeoutMs: override.readyTimeoutMs ?? base.readyTimeoutMs,
277
277
  configPath: override.configPath ?? base.configPath,
278
+ experimental: override.experimental ?? base.experimental,
278
279
  simulation: mergeSimulationOptions(base.simulation, override.simulation)
279
280
  };
280
281
  }
@@ -331,6 +332,13 @@ var DEFAULT_PAJA_WINDOW_ID = "kehto-paja-window";
331
332
  var DEFAULT_PAJA_DTAG = "dev-target";
332
333
  var DEFAULT_PAJA_AGGREGATE_HASH = "paja";
333
334
  var DEFAULT_PAJA_RUNTIME_WAIT_MS = 5e3;
335
+ function normalizePajaExperimental(raw) {
336
+ const setting = raw?.nestedContextLock ?? "auto";
337
+ if (setting !== "on" && setting !== "off" && setting !== "auto") {
338
+ throw new Error(`experimental.nestedContextLock must be "on", "off", or "auto"; got ${String(setting)}`);
339
+ }
340
+ return { nestedContextLock: setting };
341
+ }
334
342
  function normalizePajaOptions(raw) {
335
343
  const targetUrl = normalizeTargetUrl(raw.targetUrl);
336
344
  const host = normalizeHost(raw.host);
@@ -342,6 +350,7 @@ function normalizePajaOptions(raw) {
342
350
  const command = normalizeCommand(raw.command);
343
351
  const configPath = raw.configPath?.trim();
344
352
  const simulation = normalizePajaSimulation(raw.simulation);
353
+ const experimental = normalizePajaExperimental(raw.experimental);
345
354
  return {
346
355
  targetUrl,
347
356
  command,
@@ -350,6 +359,7 @@ function normalizePajaOptions(raw) {
350
359
  readyTimeoutMs,
351
360
  configPath: configPath && configPath.length > 0 ? configPath : void 0,
352
361
  simulation,
362
+ experimental,
353
363
  mode: command ? "managed-command" : "external-target"
354
364
  };
355
365
  }
@@ -357,6 +367,7 @@ function createPajaHostConfig(options, now = /* @__PURE__ */ new Date()) {
357
367
  const base = createPajaHostConfigBase(options.simulation);
358
368
  return {
359
369
  ...base,
370
+ ...options.experimental ? { experimental: options.experimental } : {},
360
371
  target: {
361
372
  mode: "iframe-url",
362
373
  url: options.targetUrl,
@@ -378,6 +389,7 @@ function createPajaRuntimeHostConfig(options = {}, now = /* @__PURE__ */ new Dat
378
389
  return {
379
390
  ...base,
380
391
  ...options.csp ? { csp: options.csp } : {},
392
+ ...options.experimental ? { experimental: options.experimental } : {},
381
393
  target: {
382
394
  mode: "runtime-pointer",
383
395
  url: "about:blank",
@@ -769,6 +781,18 @@ function renderPajaHtml(config) {
769
781
  <div id="paja-resource-servers-status" role="status" aria-live="polite"></div>
770
782
  </form>
771
783
  </div></details>
784
+ <details class="section" id="paja-section-security" data-paja-section="security" open>
785
+ <summary class="section-title">Security<span class="section-chevron" aria-hidden="true">\u203A</span></summary><div class="section-body">
786
+ <label class="section-title" for="paja-nested-context-lock">Frame-creation lock (experimental)</label>
787
+ <select id="paja-nested-context-lock" aria-describedby="paja-nested-context-lock-help paja-nested-context-lock-status">
788
+ <option value="">Host default</option>
789
+ <option value="auto">Auto (lock private-data napplets)</option>
790
+ <option value="on">On (lock every napplet)</option>
791
+ <option value="off">Off</option>
792
+ </select>
793
+ <small id="paja-nested-context-lock-help">Stops a napplet creating an iframe. Auto locks napplets granted a private domain (e.g. DM). Applies on the next napplet load. Turning it off for a private-data napplet lowers exfiltration protection.</small>
794
+ <div id="paja-nested-context-lock-status" role="status" aria-live="polite"></div>
795
+ </div></details>
772
796
  <details class="section" id="paja-section-llm" data-paja-section="llm" open>
773
797
  <summary class="section-title">Language models<span class="section-chevron" aria-hidden="true">\u203A</span></summary><div class="section-body">
774
798
  <ul class="llm-connections" id="paja-llm-connections" aria-label="Configured model connections"></ul>
@@ -783,6 +807,9 @@ function renderPajaHtml(config) {
783
807
  <label class="llm-check"><input id="paja-llm-remember" type="checkbox"><span>Remember the key, encrypted with a vault password</span></label>
784
808
  <label class="llm-check"><input id="paja-llm-images" type="checkbox"><span>Accepts image input</span></label>
785
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>
786
813
  <div class="llm-actions">
787
814
  <button type="submit" id="paja-llm-save">Add connection</button>
788
815
  <button type="button" id="paja-llm-vault-lock" hidden>Lock vault</button>
@@ -2143,6 +2170,7 @@ function normalizeServerTargetUrl(value) {
2143
2170
  import {
2144
2171
  LLM_PROVIDER_PRESETS,
2145
2172
  LlmServiceError,
2173
+ buildLlmProviderRequest,
2146
2174
  createHttpLlmProvider,
2147
2175
  countLlmImages
2148
2176
  } from "@kehto/services";
@@ -2150,6 +2178,7 @@ var PAJA_LLM_CONNECTIONS_STORAGE_KEY = "kehto:paja:llm-connections:v1";
2150
2178
  var MAX_CONNECTIONS = 32;
2151
2179
  var PROTOCOLS = /* @__PURE__ */ new Set(["openai-chat", "anthropic-messages", "gemini"]);
2152
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"];
2153
2182
  var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
2154
2183
  function normalizePajaLlmBaseUrl(value) {
2155
2184
  let url;
@@ -2169,6 +2198,11 @@ function normalizePajaLlmBaseUrl(value) {
2169
2198
  function isRecord2(value) {
2170
2199
  return typeof value === "object" && value !== null && !Array.isArray(value);
2171
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
+ }
2172
2206
  function normalizeRecord(input) {
2173
2207
  const text = (value) => typeof value === "string" ? value : "";
2174
2208
  const name = text(input.name).trim();
@@ -2183,6 +2217,7 @@ function normalizeRecord(input) {
2183
2217
  if (!PROTOCOLS.has(protocol)) throw new Error("Unknown provider protocol.");
2184
2218
  if (credentialHeader !== void 0 && !CREDENTIAL_HEADERS.has(credentialHeader)) throw new Error("Unknown credential header.");
2185
2219
  if (!["vault", "session", "none"].includes(credentialStorage)) throw new Error("Unknown credential storage.");
2220
+ const tools = input.tools === true;
2186
2221
  const record = {
2187
2222
  id,
2188
2223
  name,
@@ -2192,6 +2227,8 @@ function normalizeRecord(input) {
2192
2227
  model,
2193
2228
  images: input.images === true,
2194
2229
  json: input.json === true,
2230
+ tools,
2231
+ toolChoiceModes: Object.freeze(canonicalToolChoiceModes(tools, input.toolChoiceModes)),
2195
2232
  credentialStorage,
2196
2233
  ...credentialHeader ? { credentialHeader } : {}
2197
2234
  };
@@ -2263,29 +2300,59 @@ function describePajaLlmRoute(record) {
2263
2300
  return `Paja (this browser) \u2192 ${label}`;
2264
2301
  }
2265
2302
  function toConnection(record) {
2266
- 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
+ };
2267
2314
  }
2268
2315
  function meets(record, requirements) {
2269
2316
  if (requirements.model !== void 0 && requirements.model !== record.model) return false;
2270
2317
  if (requirements.images === true && !record.images) return false;
2318
+ if (requirements.tools === true && record.tools !== true) return false;
2271
2319
  return !(requirements.json === true && !record.json);
2272
2320
  }
2273
2321
  function describeRequirements(requirements) {
2274
2322
  const parts = [
2275
2323
  requirements.model ? `model ${requirements.model}` : "any model",
2276
2324
  requirements.images ? "image input" : null,
2277
- requirements.json ? "JSON output" : null
2325
+ requirements.json ? "JSON output" : null,
2326
+ requirements.tools ? "tool calling" : null
2278
2327
  ].filter((part) => part !== null);
2279
2328
  return parts.join(", ");
2280
2329
  }
2281
2330
  function countCharacters(request) {
2282
2331
  let total = 0;
2283
- 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;
2284
2339
  return total;
2285
2340
  }
2341
+ function countToolResults(request) {
2342
+ return request.messages.filter((message) => message.role === "toolResult").length;
2343
+ }
2286
2344
  function createPajaLlmHost(options) {
2287
2345
  const { store, vault, confirm, getIdentity } = options;
2288
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
+ }
2289
2356
  async function ensureCredential(record, signal) {
2290
2357
  if (record.credentialStorage === "none") return void 0;
2291
2358
  const existing = vault.getCredential(record.id);
@@ -2331,6 +2398,7 @@ function createPajaLlmHost(options) {
2331
2398
  const signal = prompt?.signal;
2332
2399
  const record = store.get(connection.id);
2333
2400
  if (!record) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
2401
+ buildLlmProviderRequest(endpointFor(record), request, { stream: true });
2334
2402
  await ensureCredential(record, signal);
2335
2403
  if (signal?.aborted) return false;
2336
2404
  return confirm({
@@ -2344,21 +2412,17 @@ function createPajaLlmHost(options) {
2344
2412
  messages: request.messages.length,
2345
2413
  characters: countCharacters(request),
2346
2414
  images: countLlmImages(request.messages),
2415
+ tools: (request.tools ?? []).map((tool) => tool.name),
2416
+ toolResults: countToolResults(request),
2347
2417
  format: request.format ?? "text",
2348
- 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."
2349
2419
  });
2350
2420
  },
2351
2421
  async generate(_context, connection, request, hooks) {
2352
2422
  const record = store.get(connection.id);
2353
2423
  if (!record) throw new LlmServiceError("selection-expired", "The selected connection was removed; select again.");
2354
2424
  const credential = await ensureCredential(record);
2355
- return provider({
2356
- protocol: record.protocol,
2357
- baseUrl: record.baseUrl,
2358
- model: record.model,
2359
- ...credential === void 0 ? {} : { credential },
2360
- ...record.credentialHeader ? { credentialHeader: record.credentialHeader } : {}
2361
- }, request, hooks.signal, (text) => hooks.onDelta(text));
2425
+ return provider(endpointFor(record, credential), request, hooks.signal, (event) => hooks.onDelta(event));
2362
2426
  },
2363
2427
  subscribe(listener) {
2364
2428
  const stopStore = store.subscribe(listener);
@@ -2585,4 +2649,4 @@ export {
2585
2649
  validatePajaLlmVaultPassword,
2586
2650
  createPajaLlmVault
2587
2651
  };
2588
- //# sourceMappingURL=chunk-4GUFJFK7.js.map
2652
+ //# sourceMappingURL=chunk-DDYBKY5L.js.map