@oyehello/chat 0.5.1 → 0.5.2

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.
@@ -308,6 +308,29 @@ var OyehelloChat = (function (exports) {
308
308
  // src/client.ts
309
309
  var seq = 0;
310
310
  var uid = (p) => `${p}_${Date.now().toString(36)}_${(seq++).toString(36)}`;
311
+ var isSafeRelativePath = (p) => p.startsWith("/") && !p.startsWith("//");
312
+ var isSafeHttpUrl = (u3) => {
313
+ try {
314
+ const parsed = new URL(u3, window.location.origin);
315
+ return parsed.protocol === "http:" || parsed.protocol === "https:";
316
+ } catch {
317
+ return false;
318
+ }
319
+ };
320
+ var BUILTIN_TOOL_HANDLERS = {
321
+ navigate: (args) => {
322
+ const path = String(args.path ?? "");
323
+ if (!isSafeRelativePath(path)) return { ok: false, error: "unsafe navigate path" };
324
+ window.location.assign(path);
325
+ return { ok: true };
326
+ },
327
+ openUrl: (args) => {
328
+ const url = String(args.url ?? "");
329
+ if (!isSafeHttpUrl(url)) return { ok: false, error: "unsafe url" };
330
+ window.open(url, args.newTab === false ? "_self" : "_blank", "noopener,noreferrer");
331
+ return { ok: true };
332
+ }
333
+ };
311
334
  function createChatClient(options) {
312
335
  const fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
313
336
  const ES = options.eventSource ?? globalThis.EventSource;
@@ -466,7 +489,7 @@ var OyehelloChat = (function (exports) {
466
489
  } else if (ev.type === "tool_call") {
467
490
  if (seenCallIds.has(ev.callId)) return;
468
491
  seenCallIds.add(ev.callId);
469
- const handler = toolHandlers.get(ev.name);
492
+ const handler = toolHandlers.get(ev.name) ?? BUILTIN_TOOL_HANDLERS[ev.name];
470
493
  void (async () => {
471
494
  if (!session) return;
472
495
  const base = { baseUrl: options.baseUrl, sessionId: session.sessionId, sessionToken: session.sessionToken, callId: ev.callId, fetchImpl };
@@ -564,7 +587,8 @@ var OyehelloChat = (function (exports) {
564
587
  return;
565
588
  }
566
589
  if (deviceFingerprint === void 0) deviceFingerprint = await computeDeviceFingerprint().catch(() => null);
567
- session = await openSession({ baseUrl: options.baseUrl, apiKey: options.apiKey, agentId: options.agentId, user: options.user, clientTools: Array.from(toolHandlers.keys()), fingerprint: deviceFingerprint ?? void 0, fetchImpl });
590
+ const advertisedTools = /* @__PURE__ */ new Set([...toolHandlers.keys(), ...Object.keys(BUILTIN_TOOL_HANDLERS)]);
591
+ session = await openSession({ baseUrl: options.baseUrl, apiKey: options.apiKey, agentId: options.agentId, user: options.user, clientTools: Array.from(advertisedTools), fingerprint: deviceFingerprint ?? void 0, fetchImpl });
568
592
  persistSession(session);
569
593
  if (!warnedProtocol && typeof session.protocol === "number" && session.protocol !== CHAT_PROTOCOL_VERSION) {
570
594
  warnedProtocol = true;