@kweaver-ai/kweaver-sdk 0.5.2 → 0.6.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.
Files changed (57) hide show
  1. package/README.md +19 -1
  2. package/README.zh.md +19 -1
  3. package/dist/api/agent-chat.d.ts +7 -1
  4. package/dist/api/agent-chat.js +146 -40
  5. package/dist/api/agent-list.js +13 -13
  6. package/dist/api/business-domains.js +9 -5
  7. package/dist/api/context-loader.js +4 -1
  8. package/dist/api/conversations.js +4 -9
  9. package/dist/api/dataflow2.d.ts +95 -0
  10. package/dist/api/dataflow2.js +80 -0
  11. package/dist/api/headers.d.ts +2 -0
  12. package/dist/api/headers.js +7 -2
  13. package/dist/api/skills.js +2 -10
  14. package/dist/api/vega.d.ts +0 -16
  15. package/dist/api/vega.js +0 -33
  16. package/dist/auth/oauth.d.ts +7 -6
  17. package/dist/auth/oauth.js +170 -80
  18. package/dist/cli.js +21 -1
  19. package/dist/client.d.ts +9 -0
  20. package/dist/client.js +48 -8
  21. package/dist/commands/auth.js +103 -42
  22. package/dist/commands/bkn-schema.js +22 -0
  23. package/dist/commands/call.js +8 -5
  24. package/dist/commands/dataflow.d.ts +1 -0
  25. package/dist/commands/dataflow.js +251 -0
  26. package/dist/commands/explore-bkn.d.ts +79 -0
  27. package/dist/commands/explore-bkn.js +273 -0
  28. package/dist/commands/explore-chat.d.ts +3 -0
  29. package/dist/commands/explore-chat.js +193 -0
  30. package/dist/commands/explore-vega.d.ts +3 -0
  31. package/dist/commands/explore-vega.js +71 -0
  32. package/dist/commands/explore.d.ts +9 -0
  33. package/dist/commands/explore.js +258 -0
  34. package/dist/commands/vega.js +2 -104
  35. package/dist/config/no-auth.d.ts +3 -0
  36. package/dist/config/no-auth.js +5 -0
  37. package/dist/config/store.d.ts +8 -0
  38. package/dist/config/store.js +22 -0
  39. package/dist/index.d.ts +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/kweaver.d.ts +5 -0
  42. package/dist/kweaver.js +32 -2
  43. package/dist/resources/bkn.js +2 -3
  44. package/dist/resources/knowledge-networks.js +3 -8
  45. package/dist/resources/vega.d.ts +0 -6
  46. package/dist/resources/vega.js +1 -10
  47. package/dist/templates/explorer/app.js +136 -0
  48. package/dist/templates/explorer/bkn.js +747 -0
  49. package/dist/templates/explorer/chat.js +980 -0
  50. package/dist/templates/explorer/dashboard.js +82 -0
  51. package/dist/templates/explorer/index.html +35 -0
  52. package/dist/templates/explorer/style.css +2440 -0
  53. package/dist/templates/explorer/vega.js +291 -0
  54. package/dist/utils/browser.js +33 -10
  55. package/dist/utils/http.d.ts +3 -0
  56. package/dist/utils/http.js +37 -1
  57. package/package.json +9 -5
@@ -0,0 +1,136 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Shared state
3
+ // ---------------------------------------------------------------------------
4
+ let navGeneration = 0;
5
+
6
+ // ---------------------------------------------------------------------------
7
+ // Utilities
8
+ // ---------------------------------------------------------------------------
9
+ function esc(s) {
10
+ if (s == null) return "";
11
+ return String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;")
12
+ .replace(/>/g, "&gt;").replace(/"/g, "&quot;");
13
+ }
14
+
15
+ function enc(s) { return encodeURIComponent(s); }
16
+
17
+ function formatValue(v) {
18
+ if (v == null) return '<span class="null">—</span>';
19
+ if (typeof v === "object") return "<pre>" + esc(JSON.stringify(v, null, 2)) + "</pre>";
20
+ return esc(String(v));
21
+ }
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // Cache utility
25
+ // ---------------------------------------------------------------------------
26
+ const CACHE_TTL = 5 * 60 * 1000;
27
+
28
+ function cachedFetch(cache, key, fetcher) {
29
+ const entry = cache[key];
30
+ if (entry && Date.now() - entry.ts < CACHE_TTL) return Promise.resolve(entry.data);
31
+ return fetcher().then(data => { cache[key] = { data, ts: Date.now() }; return data; });
32
+ }
33
+
34
+ // ---------------------------------------------------------------------------
35
+ // API helper
36
+ // ---------------------------------------------------------------------------
37
+ async function api(method, url, body) {
38
+ const opts = { method, headers: {} };
39
+ if (body) {
40
+ opts.headers["Content-Type"] = "application/json";
41
+ opts.body = JSON.stringify(body);
42
+ }
43
+ const res = await fetch(url, opts);
44
+ if (!res.ok) {
45
+ let msg = `${res.status} ${res.statusText}`;
46
+ try { const err = await res.json(); if (err.error) msg = err.error; } catch {}
47
+ const error = new Error(msg);
48
+ error.status = res.status;
49
+ throw error;
50
+ }
51
+ return res.json();
52
+ }
53
+
54
+ // ---------------------------------------------------------------------------
55
+ // List extraction helper (handles various API response shapes)
56
+ // ---------------------------------------------------------------------------
57
+ function extractList(obj) {
58
+ if (obj == null || obj.error) return [];
59
+ if (Array.isArray(obj)) return obj;
60
+ for (const k of ["entries", "data", "knowledge_networks", "items"]) {
61
+ if (Array.isArray(obj[k])) return obj[k];
62
+ }
63
+ return [];
64
+ }
65
+
66
+ // ---------------------------------------------------------------------------
67
+ // Router
68
+ // ---------------------------------------------------------------------------
69
+ function getRoute() {
70
+ const hash = location.hash.slice(1) || "/";
71
+ const [path, qs] = hash.split("?");
72
+ const parts = path.split("/").filter(Boolean);
73
+ const params = new URLSearchParams(qs || "");
74
+
75
+ if (parts.length === 0) return { view: "dashboard" };
76
+
77
+ const tab = parts[0];
78
+ return { tab, parts: parts.slice(1), params };
79
+ }
80
+
81
+ function navigate() {
82
+ navGeneration++;
83
+ const route = getRoute();
84
+ const $content = document.getElementById("content");
85
+
86
+ // Update active tab
87
+ document.querySelectorAll("#tab-bar .tab").forEach(t => {
88
+ const tabName = t.dataset.tab;
89
+ const isActive = route.view === "dashboard"
90
+ ? tabName === "dashboard"
91
+ : tabName === route.tab;
92
+ t.classList.toggle("active", isActive);
93
+ });
94
+
95
+ // Dispatch to tab renderer
96
+ if (route.view === "dashboard") {
97
+ if (typeof renderDashboard === "function") renderDashboard($content);
98
+ else $content.innerHTML = '<div class="loading">Dashboard loading...</div>';
99
+ } else if (route.tab === "chat") {
100
+ if (typeof renderChat === "function") renderChat($content, route.parts, route.params);
101
+ else $content.innerHTML = '<div class="loading">Chat loading...</div>';
102
+ } else if (route.tab === "bkn") {
103
+ if (typeof renderBkn === "function") renderBkn($content, route.parts, route.params);
104
+ else $content.innerHTML = '<div class="loading">BKN loading...</div>';
105
+ } else if (route.tab === "vega") {
106
+ if (typeof renderVega === "function") renderVega($content, route.parts, route.params);
107
+ else $content.innerHTML = '<div class="loading">Vega loading...</div>';
108
+ } else {
109
+ $content.innerHTML = '<div class="error-banner">Unknown route</div>';
110
+ }
111
+ }
112
+
113
+ // ---------------------------------------------------------------------------
114
+ // Init
115
+ // ---------------------------------------------------------------------------
116
+ window.addEventListener("hashchange", navigate);
117
+ window.addEventListener("DOMContentLoaded", () => {
118
+ // Theme Toggle
119
+ const themeToggle = document.getElementById("theme-toggle");
120
+ if (themeToggle) {
121
+ const savedTheme = localStorage.getItem("kweaver-theme");
122
+ if (savedTheme) {
123
+ document.documentElement.setAttribute("data-theme", savedTheme);
124
+ themeToggle.textContent = savedTheme === "dark" ? "☀️" : "🌙";
125
+ }
126
+ themeToggle.addEventListener("click", () => {
127
+ const currentTheme = document.documentElement.getAttribute("data-theme");
128
+ const newTheme = currentTheme === "dark" ? "light" : "dark";
129
+ document.documentElement.setAttribute("data-theme", newTheme);
130
+ localStorage.setItem("kweaver-theme", newTheme);
131
+ themeToggle.textContent = newTheme === "dark" ? "☀️" : "🌙";
132
+ });
133
+ }
134
+
135
+ navigate();
136
+ });