@makinbakin/sdk 0.0.1-rc.20 → 0.0.1-rc.21

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 (110) hide show
  1. package/_internal/app/components/agent-select.d.ts +10 -1
  2. package/_internal/app/components/asset-picker.d.ts +25 -0
  3. package/_internal/app/components/charts/bar-chart.d.ts +16 -0
  4. package/_internal/app/components/charts/chart-data-table.d.ts +31 -0
  5. package/_internal/app/components/charts/chart-explainer.d.ts +9 -0
  6. package/_internal/app/components/charts/chart-tooltip.d.ts +8 -0
  7. package/_internal/app/components/charts/line-chart.d.ts +13 -0
  8. package/_internal/app/components/charts/palette.d.ts +24 -0
  9. package/_internal/app/components/charts/sparkline.d.ts +12 -0
  10. package/_internal/app/components/charts/stacked-column-chart.d.ts +40 -0
  11. package/_internal/app/components/confirm-dialog.d.ts +23 -2
  12. package/_internal/app/components/conversation/activity-group.d.ts +15 -0
  13. package/_internal/app/components/conversation/agent-turn.d.ts +36 -0
  14. package/_internal/app/components/conversation/attention.d.ts +56 -0
  15. package/_internal/app/components/conversation/composer.d.ts +35 -0
  16. package/_internal/app/components/conversation/conversation-empty-state.d.ts +8 -0
  17. package/_internal/app/components/conversation/conversation-panel.d.ts +33 -0
  18. package/_internal/app/components/conversation/conversation.d.ts +14 -0
  19. package/_internal/app/components/conversation/fold.d.ts +129 -0
  20. package/_internal/app/components/conversation/notification-sound.d.ts +8 -0
  21. package/_internal/app/components/conversation/relative-time.d.ts +8 -0
  22. package/_internal/app/components/conversation/reply-toast.d.ts +15 -0
  23. package/_internal/app/components/conversation/thread-id.d.ts +8 -0
  24. package/_internal/app/components/conversation/tool-call-drawer.d.ts +7 -0
  25. package/_internal/app/components/conversation/turn-recorder.d.ts +37 -0
  26. package/_internal/app/components/conversation/use-conversation-attention.d.ts +64 -0
  27. package/_internal/app/components/conversation/use-conversation-thread.d.ts +55 -0
  28. package/_internal/app/components/conversation/user-message.d.ts +11 -0
  29. package/_internal/app/components/danger-zone.d.ts +28 -0
  30. package/_internal/app/components/empty-state.d.ts +5 -2
  31. package/_internal/app/components/plugin-header.d.ts +4 -3
  32. package/_internal/app/components/save-bar.d.ts +32 -0
  33. package/_internal/app/components/score-overlay.d.ts +33 -0
  34. package/_internal/app/components/search-degraded-chip.d.ts +4 -0
  35. package/_internal/app/components/search-partial-chip.d.ts +13 -0
  36. package/_internal/app/components/search-unavailable.d.ts +12 -0
  37. package/_internal/app/components/section-card.d.ts +22 -0
  38. package/_internal/app/components/segmented-control.d.ts +28 -0
  39. package/_internal/app/components/stat-tile.d.ts +26 -0
  40. package/_internal/app/components/status-badge.d.ts +19 -0
  41. package/_internal/app/components/turn-output-view.d.ts +57 -0
  42. package/_internal/app/components/ui/button.d.ts +1 -1
  43. package/_internal/app/components/underline-tabs.d.ts +6 -2
  44. package/_internal/app/components/unsaved-changes-guard.d.ts +34 -0
  45. package/_internal/app/core/conversation-turns.d.ts +148 -0
  46. package/_internal/app/core/logger.d.ts +1 -0
  47. package/_internal/app/hooks/use-file-drop.d.ts +25 -0
  48. package/_internal/app/hooks/use-history-back.d.ts +1 -0
  49. package/_internal/app/hooks/use-json-fetch.d.ts +5 -0
  50. package/_internal/app/hooks/use-query-state.d.ts +2 -0
  51. package/_internal/app/hooks/use-schedule.d.ts +45 -0
  52. package/_internal/app/hooks/use-search.d.ts +27 -8
  53. package/_internal/app/hooks/use-toast.d.ts +3 -3
  54. package/_internal/app/lib/browser-notify.d.ts +12 -1
  55. package/_internal/core/adapters/runtime/concepts.d.ts +547 -49
  56. package/_internal/core/adapters/runtime/errors.d.ts +13 -1
  57. package/_internal/core/adapters/runtime/helpers.d.ts +19 -0
  58. package/_internal/core/adapters/runtime/index.d.ts +5 -2
  59. package/_internal/core/adapters/runtime/testing.d.ts +79 -0
  60. package/_internal/core/adapters/runtime/turn-activity.d.ts +23 -0
  61. package/_internal/core/adapters/shared.d.ts +122 -12
  62. package/_internal/core/content-dir.d.ts +8 -0
  63. package/_internal/core/docs/route.d.ts +1 -1
  64. package/_internal/core/format/structured.d.ts +44 -0
  65. package/_internal/core/format.d.ts +5 -1
  66. package/_internal/core/media/downscale.d.ts +18 -0
  67. package/_internal/core/media/sharp-loader.d.ts +36 -0
  68. package/_internal/core/plugin-types.d.ts +102 -39
  69. package/_internal/core/routing/define.d.ts +26 -3
  70. package/_internal/core/routing/dispatcher.d.ts +15 -6
  71. package/_internal/core/routing/index.d.ts +1 -1
  72. package/_internal/core/routing/types.d.ts +13 -70
  73. package/_internal/core/storage/atomic-write.d.ts +11 -0
  74. package/_internal/core/tasks/store.d.ts +129 -0
  75. package/_internal/core/tasks/testing.d.ts +2 -0
  76. package/_internal/{plugins/workflows/lib → core/workflows}/notification-channel-registry.d.ts +1 -1
  77. package/_internal/plugins/team/types.d.ts +47 -0
  78. package/_internal/plugins/workflows/hooks/use-notification-channels.d.ts +1 -1
  79. package/components/index.d.ts +87 -19
  80. package/components/index.js +32904 -15368
  81. package/hooks/index.d.ts +24 -4
  82. package/hooks/index.js +837 -561
  83. package/hooks/router.d.ts +20 -4
  84. package/index.d.ts +5 -50
  85. package/index.js +223 -406
  86. package/internal/index.d.ts +70 -0
  87. package/internal/index.js +409 -0
  88. package/package.json +9 -2
  89. package/register.d.ts +19 -1
  90. package/routing/index.js +175 -147
  91. package/slots/index.js +20 -1
  92. package/testing/index.d.ts +122 -0
  93. package/testing/index.js +21874 -0
  94. package/types/index.d.ts +4 -0
  95. package/types/index.js +16 -0
  96. package/utils/index.d.ts +28 -25
  97. package/utils/index.js +279 -263
  98. package/_internal/app/components/integrated-brainstorm/activity.d.ts +0 -23
  99. package/_internal/app/components/integrated-brainstorm/collapsed-header.d.ts +0 -14
  100. package/_internal/app/components/integrated-brainstorm/empty-state.d.ts +0 -5
  101. package/_internal/app/components/integrated-brainstorm/index.d.ts +0 -8
  102. package/_internal/app/components/integrated-brainstorm/input-row.d.ts +0 -16
  103. package/_internal/app/components/integrated-brainstorm/message-list.d.ts +0 -8
  104. package/_internal/app/components/integrated-brainstorm/session.d.ts +0 -16
  105. package/_internal/app/components/integrated-brainstorm/sse.d.ts +0 -8
  106. package/_internal/app/components/integrated-brainstorm/thinking-indicator.d.ts +0 -19
  107. package/_internal/app/components/integrated-brainstorm/types.d.ts +0 -63
  108. package/_internal/app/components/integrated-brainstorm/use-auto-grow.d.ts +0 -6
  109. package/_internal/app/components/integrated-brainstorm/use-brainstorm-state.d.ts +0 -21
  110. /package/_internal/{plugins/models → app}/hooks/use-available-models.d.ts +0 -0
package/utils/index.js CHANGED
@@ -1798,6 +1798,145 @@ var twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
1798
1798
  function cn(...inputs) {
1799
1799
  return twMerge(clsx(inputs));
1800
1800
  }
1801
+ // packages/sdk/src/utils/asset-id.ts
1802
+ var ASSET_ID_RE = /^(\d{4})(\d{2})(\d{2})-.+-[0-9a-f]{8}$/i;
1803
+ function yearMonthFromAssetId(assetId) {
1804
+ const m = ASSET_ID_RE.exec(assetId);
1805
+ if (!m)
1806
+ return null;
1807
+ const year = parseInt(m[1], 10);
1808
+ const month = parseInt(m[2], 10);
1809
+ const day = parseInt(m[3], 10);
1810
+ if (year < 1970 || year > 9999)
1811
+ return null;
1812
+ if (month < 1 || month > 12)
1813
+ return null;
1814
+ if (day < 1 || day > 31)
1815
+ return null;
1816
+ return `${m[1]}-${m[2]}`;
1817
+ }
1818
+ function isValidAssetId(assetId) {
1819
+ return assetId.length > 0 && !assetId.includes("/") && !assetId.includes("\\") && !assetId.includes("..") && yearMonthFromAssetId(assetId) !== null;
1820
+ }
1821
+ // packages/core/src/format/structured.ts
1822
+ function humanizeKey(key) {
1823
+ const spaced = key.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().trim();
1824
+ return spaced.charAt(0).toUpperCase() + spaced.slice(1);
1825
+ }
1826
+ function isScalar(value) {
1827
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
1828
+ }
1829
+ function renderEntry(key, value, indent, markdown) {
1830
+ const name = humanizeKey(key);
1831
+ const label = `${indent}${markdown ? `**${name}:**` : `${name}:`}`;
1832
+ if (value === null || value === undefined || value === "")
1833
+ return [];
1834
+ if (isScalar(value)) {
1835
+ const text = String(value);
1836
+ return text.length > 80 ? [label, `${indent}${text}`] : [`${label} ${text}`];
1837
+ }
1838
+ if (Array.isArray(value)) {
1839
+ if (value.length === 0)
1840
+ return [];
1841
+ if (value.every(isScalar))
1842
+ return [`${label} ${value.map(String).join(", ")}`];
1843
+ return [label, ...value.flatMap((entry, i) => renderEntry(String(i + 1), entry, `${indent} `, markdown))];
1844
+ }
1845
+ if (typeof value === "object") {
1846
+ const children = Object.entries(value).flatMap(([childKey, child]) => renderEntry(childKey, child, `${indent} `, markdown));
1847
+ return children.length > 0 ? [label, ...children] : [];
1848
+ }
1849
+ return [];
1850
+ }
1851
+ function formatStructured(value, opts = {}) {
1852
+ if (value === null || value === undefined)
1853
+ return "";
1854
+ if (isScalar(value))
1855
+ return String(value);
1856
+ const markdown = opts.markdown ?? false;
1857
+ const entries = Array.isArray(value) ? value.flatMap((entry, i) => renderEntry(String(i + 1), entry, "", markdown)) : Object.entries(value).flatMap(([k, v]) => renderEntry(k, v, "", markdown));
1858
+ if (entries.length === 0)
1859
+ return "";
1860
+ const rendered = entries.join(`
1861
+ `);
1862
+ const cap = opts.cap ?? Infinity;
1863
+ const body = rendered.length > cap ? `${rendered.slice(0, cap)}
1864
+ ...[truncated]` : rendered;
1865
+ if (opts.heading)
1866
+ return `${opts.heading}
1867
+
1868
+ ${body}`;
1869
+ return body;
1870
+ }
1871
+ var SUMMARY_FIELDS = ["notice", "summary", "message", "title", "name", "assetId", "id"];
1872
+ var NOISE_KEYS = new Set(["ok", "success", "status", "version", "taskid", "via", "duplicate"]);
1873
+ function summarizeStructured(value, cap = 120) {
1874
+ const clip = (text) => text.length > cap ? `${text.slice(0, cap - 1)}\u2026` : text;
1875
+ const v = unwrapToolResult(value);
1876
+ if (v === null || v === undefined)
1877
+ return "";
1878
+ if (isScalar(v))
1879
+ return clip(String(v));
1880
+ if (Array.isArray(v))
1881
+ return clip(`${v.length} item${v.length === 1 ? "" : "s"}`);
1882
+ const obj = v;
1883
+ if (obj.ok === false || obj.success === false) {
1884
+ const err = obj.error ?? obj.message ?? obj.reason;
1885
+ if (isScalar(err) && err !== "")
1886
+ return clip(`error: ${err}`);
1887
+ return "error";
1888
+ }
1889
+ if (isScalar(obj.error) && obj.error !== "")
1890
+ return clip(`error: ${obj.error}`);
1891
+ for (const key of SUMMARY_FIELDS) {
1892
+ if (isScalar(obj[key]) && obj[key] !== "")
1893
+ return clip(String(obj[key]));
1894
+ }
1895
+ const parts = [];
1896
+ for (const [k, val] of Object.entries(obj)) {
1897
+ if (NOISE_KEYS.has(k.toLowerCase()))
1898
+ continue;
1899
+ if (val === null || val === undefined || val === "")
1900
+ continue;
1901
+ if (Array.isArray(val))
1902
+ parts.push(`${val.length} ${humanizeKey(k).toLowerCase()}`);
1903
+ else if (isScalar(val))
1904
+ parts.push(`${humanizeKey(k)}: ${val}`);
1905
+ else
1906
+ parts.push(humanizeKey(k).toLowerCase());
1907
+ }
1908
+ if (parts.length > 0)
1909
+ return clip(parts.join(", "));
1910
+ return obj.ok === true || obj.success === true ? "done" : "";
1911
+ }
1912
+ function unwrapToolResult(value, depth = 6) {
1913
+ if (depth <= 0)
1914
+ return value;
1915
+ if (typeof value === "string") {
1916
+ const parsed = maybeParseJson(value);
1917
+ return parsed === value ? value : unwrapToolResult(parsed, depth - 1);
1918
+ }
1919
+ if (!value || typeof value !== "object" || Array.isArray(value))
1920
+ return value;
1921
+ const content = value.content;
1922
+ if (Array.isArray(content)) {
1923
+ const text = content.map((part) => part && typeof part === "object" && part.type === "text" ? String(part.text ?? "") : "").join("").trim();
1924
+ if (text)
1925
+ return unwrapToolResult(text, depth - 1);
1926
+ }
1927
+ return value;
1928
+ }
1929
+ function maybeParseJson(text) {
1930
+ const trimmed = text.trim();
1931
+ if (!(trimmed.startsWith("{") || trimmed.startsWith("[")))
1932
+ return text;
1933
+ try {
1934
+ return JSON.parse(trimmed);
1935
+ } catch {
1936
+ return text;
1937
+ }
1938
+ }
1939
+
1801
1940
  // packages/core/src/format.ts
1802
1941
  function formatAge(timestamp) {
1803
1942
  const ms = Date.now() - new Date(timestamp).getTime();
@@ -1836,7 +1975,13 @@ function formatDuration(ms) {
1836
1975
  const s = Math.round(ms / 1000);
1837
1976
  if (s < 60)
1838
1977
  return `${s}s`;
1839
- return `${Math.floor(s / 60)}m ${s % 60}s`;
1978
+ const m = Math.floor(s / 60);
1979
+ if (m < 60)
1980
+ return `${m}m ${s % 60}s`;
1981
+ const h = Math.floor(m / 60);
1982
+ if (h < 24)
1983
+ return `${h}h ${m % 60}m`;
1984
+ return `${Math.floor(h / 24)}d ${h % 24}h`;
1840
1985
  }
1841
1986
  function formatSize(bytes) {
1842
1987
  if (bytes < 1024)
@@ -1850,280 +1995,144 @@ function formatSize(bytes) {
1850
1995
  function isStale(timestamp, thresholdMs = 15 * 60 * 1000) {
1851
1996
  return Date.now() - new Date(timestamp).getTime() > thresholdMs;
1852
1997
  }
1853
- // src/components/integrated-brainstorm/session.ts
1854
- var ACTIVITY_CONTENT_MAX_CHARS = 500;
1855
- var ACTIVITY_PREVIEW_MAX_CHARS = 2000;
1856
- var ACTIVITY_METADATA_MAX_CHARS = 4000;
1857
- var ACTIVITY_DATA_MAX_KEYS = 24;
1858
- function brainstormThreadId(scope, entityId, agentId) {
1998
+ // src/components/conversation/thread-id.ts
1999
+ function conversationThreadId(scope, entityId, agentId) {
1859
2000
  return [scope, entityId, agentId].map(threadIdPart).join(":");
1860
2001
  }
1861
- function normalizeBrainstormActivityForStorage(activity) {
1862
- const content = typeof activity.content === "string" ? truncate(activity.content.trim(), ACTIVITY_CONTENT_MAX_CHARS) : "";
1863
- if (!content)
1864
- return null;
1865
- const data = normalizeActivityData(activity.data);
1866
- return {
1867
- kind: typeof activity.kind === "string" && activity.kind ? activity.kind : "runtime_status",
1868
- content,
1869
- ...data !== undefined ? { data } : {}
1870
- };
1871
- }
1872
- function normalizeBrainstormActivityMessageForStorage(activity) {
1873
- const normalized = normalizeBrainstormActivityForStorage(activity);
1874
- if (!normalized)
1875
- return null;
1876
- return {
1877
- role: "activity",
1878
- kind: normalized.kind,
1879
- content: normalized.content,
1880
- ...normalized.data !== undefined ? { data: normalized.data } : {}
1881
- };
1882
- }
1883
2002
  function threadIdPart(value) {
1884
2003
  const trimmed = value.trim();
1885
2004
  return encodeURIComponent(trimmed || "default");
1886
2005
  }
1887
- function normalizeActivityData(data) {
1888
- if (data === undefined)
1889
- return;
1890
- if (!isRecord(data))
1891
- return normalizeActivityValue(data, "value");
1892
- const out = {};
1893
- let count = 0;
1894
- for (const [key, value] of Object.entries(data)) {
1895
- if (count >= ACTIVITY_DATA_MAX_KEYS) {
1896
- out.truncatedKeys = Object.keys(data).length - count;
1897
- break;
1898
- }
1899
- out[key] = normalizeActivityValue(value, key);
1900
- count += 1;
1901
- }
1902
- return out;
1903
- }
1904
- function normalizeActivityValue(value, key) {
1905
- if (typeof value === "string") {
1906
- const max = isPreviewKey(key) ? ACTIVITY_PREVIEW_MAX_CHARS : ACTIVITY_METADATA_MAX_CHARS;
1907
- return truncate(value, max);
1908
- }
1909
- if (typeof value === "number" || typeof value === "boolean" || value === null)
1910
- return value;
1911
- if (value === undefined)
1912
- return;
1913
- return truncate(stringify(value), ACTIVITY_METADATA_MAX_CHARS);
1914
- }
1915
- function isPreviewKey(key) {
1916
- return key === "inputPreview" || key === "argumentsPreview" || key === "outputPreview" || key === "resultPreview";
1917
- }
1918
- function stringify(value) {
1919
- try {
1920
- return JSON.stringify(value);
1921
- } catch {
1922
- return String(value);
1923
- }
1924
- }
1925
- function truncate(value, maxChars) {
1926
- if (value.length <= maxChars)
1927
- return value;
1928
- return `${value.slice(0, Math.max(0, maxChars - 3))}...`;
1929
- }
1930
- function isRecord(value) {
1931
- return Boolean(value && typeof value === "object" && !Array.isArray(value));
1932
- }
1933
-
1934
- // src/components/integrated-brainstorm/activity.ts
1935
- function newActivityId() {
1936
- return `act-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
1937
- }
1938
- function runtimeChunkToBrainstormActivity(chunk) {
1939
- if (chunk.type === "status") {
1940
- return {
1941
- kind: "runtime_status",
1942
- content: chunk.content || "Agent status update",
1943
- data: chunk.data
1944
- };
1945
- }
1946
- if (chunk.type === "tool") {
1947
- return {
1948
- kind: "tool_call",
1949
- content: chunk.content || "Tool call",
1950
- data: chunk.data
1951
- };
1952
- }
1953
- if (chunk.type === "error") {
1954
- return {
1955
- kind: "error",
1956
- content: chunk.content || "Runtime stream error",
1957
- data: chunk.data
1958
- };
1959
- }
1960
- return null;
1961
- }
1962
- function brainstormActivityMessageFromCustom(name, data) {
1963
- if (name !== "activity")
1964
- return null;
1965
- const payload = data && typeof data === "object" && "activity" in data ? data.activity : data;
1966
- if (!payload || typeof payload !== "object")
1967
- return null;
1968
- const activity = payload;
1969
- const content = typeof activity.content === "string" ? activity.content : "";
1970
- if (!content)
1971
- return null;
1972
- const normalized = normalizeBrainstormActivityForStorage({
1973
- kind: typeof activity.kind === "string" ? activity.kind : "runtime_status",
1974
- content,
1975
- data: activity.data
1976
- });
1977
- if (!normalized)
1978
- return null;
1979
- return {
1980
- id: typeof activity.id === "string" ? activity.id : newActivityId(),
1981
- role: "activity",
1982
- kind: normalized.kind,
1983
- content: normalized.content,
1984
- ...normalized.data !== undefined ? { data: normalized.data } : {},
1985
- timestamp: typeof activity.timestamp === "string" ? activity.timestamp : new Date().toISOString()
1986
- };
2006
+ // src/components/conversation/turn-recorder.ts
2007
+ var SUMMARY_MAX_CHARS = 500;
2008
+ var PREVIEW_MAX_CHARS = 2000;
2009
+ function clip(value, max) {
2010
+ if (value.length <= max)
2011
+ return { value, clipped: false };
2012
+ return { value: `${value.slice(0, Math.max(0, max - 1))}\u2026`, clipped: true };
1987
2013
  }
1988
- function toBrainstormTimeline(agentId, input) {
1989
- return [
1990
- ...input.messages.map((message) => ({
1991
- id: message.id,
1992
- role: message.role === "user" ? "user" : "assistant",
1993
- content: message.content,
1994
- agentId: message.role === "user" ? undefined : agentId,
1995
- timestamp: message.timestamp
1996
- })),
1997
- ...(input.activities ?? []).map((activity) => ({
1998
- id: activity.id,
1999
- role: "activity",
2000
- kind: activity.kind,
2001
- content: activity.content,
2002
- data: activity.data,
2003
- timestamp: activity.timestamp
2004
- }))
2005
- ].sort((a, b) => {
2006
- const aTime = a.timestamp ? Date.parse(a.timestamp) : 0;
2007
- const bTime = b.timestamp ? Date.parse(b.timestamp) : 0;
2008
- return aTime - bTime;
2014
+ function createTurnRecorder({ turnId, agentId, now }) {
2015
+ const stamp = now ?? (() => new Date().toISOString());
2016
+ const rows = [];
2017
+ const callPhase = new Map;
2018
+ let pendingText = "";
2019
+ const base = () => ({
2020
+ ts: stamp(),
2021
+ turnId,
2022
+ ...agentId ? { agentId } : {}
2009
2023
  });
2010
- }
2011
- // src/components/integrated-brainstorm/sse.ts
2012
- async function readBrainstormSseResponse(response, ctx, options = {}) {
2013
- if (!response.ok || !response.body) {
2014
- const text = await response.text().catch(() => "");
2015
- throw new Error(text || `Server returned ${response.status}`);
2016
- }
2017
- const reader = response.body.getReader();
2018
- const abort = () => {
2019
- reader.cancel().catch(() => {});
2020
- };
2021
- ctx.signal.addEventListener("abort", abort, { once: true });
2022
- const decoder = new TextDecoder;
2023
- let buffer = "";
2024
- let accumulated = "";
2025
- let finalContent = "";
2026
- const dispatch = (frame) => {
2027
- if (frame.event === "token") {
2028
- const text = textField(frame.data, "text");
2029
- accumulated += text;
2030
- ctx.onToken(text);
2024
+ const flushText = () => {
2025
+ if (!pendingText.trim()) {
2026
+ pendingText = "";
2031
2027
  return;
2032
2028
  }
2033
- if (frame.event === "activity") {
2034
- ctx.onCustom?.("activity", frame.data);
2035
- return;
2036
- }
2037
- if (frame.event === "done") {
2038
- finalContent = textField(frame.data, "content") || accumulated;
2039
- return;
2040
- }
2041
- if (frame.event === "error") {
2042
- throw new Error(textField(frame.data, "message") || "Unknown error");
2043
- }
2044
- if (options.onCustomEvent?.(frame.event, frame.data) === true)
2045
- return;
2046
- ctx.onCustom?.(frame.event, frame.data);
2029
+ rows.push({ kind: "assistant", ...base(), content: pendingText });
2030
+ pendingText = "";
2047
2031
  };
2048
- try {
2049
- while (true) {
2050
- if (ctx.signal.aborted)
2051
- throw abortError();
2052
- const { done, value } = await reader.read();
2053
- if (done)
2032
+ const ingest = (chunk) => {
2033
+ switch (chunk.type) {
2034
+ case "text":
2035
+ pendingText += chunk.content;
2036
+ break;
2037
+ case "tool": {
2038
+ const data = chunk.data;
2039
+ if (!data?.toolName)
2040
+ break;
2041
+ if (data.phase === "call") {
2042
+ if (data.callId)
2043
+ callPhase.set(data.callId, data);
2044
+ break;
2045
+ }
2046
+ flushText();
2047
+ const call = data.callId ? callPhase.get(data.callId) : undefined;
2048
+ const summaryRaw = data.summary ?? call?.summary;
2049
+ const inputRaw = data.inputPreview ?? call?.inputPreview;
2050
+ const outputRaw = data.outputPreview;
2051
+ const summary = summaryRaw ? clip(summaryRaw, SUMMARY_MAX_CHARS) : undefined;
2052
+ const input = inputRaw ? clip(inputRaw, PREVIEW_MAX_CHARS) : undefined;
2053
+ const output = outputRaw ? clip(outputRaw, PREVIEW_MAX_CHARS) : undefined;
2054
+ const truncated = Boolean(summary?.clipped || input?.clipped || output?.clipped);
2055
+ rows.push({
2056
+ kind: "tool",
2057
+ ...base(),
2058
+ ...data.callId ? { callId: data.callId } : {},
2059
+ toolName: data.toolName,
2060
+ status: data.status === "failed" ? "failed" : "completed",
2061
+ ...summary ? { summary: summary.value } : {},
2062
+ ...input ? { inputPreview: input.value } : {},
2063
+ ...output ? { outputPreview: output.value } : {},
2064
+ ...data.durationMs !== undefined ? { durationMs: data.durationMs } : {},
2065
+ ...data.metadata || truncated ? { metadata: { ...data.metadata ?? {}, ...truncated ? { truncated: true } : {} } } : {}
2066
+ });
2067
+ break;
2068
+ }
2069
+ case "error":
2070
+ flushText();
2071
+ rows.push({
2072
+ kind: "error",
2073
+ ...base(),
2074
+ message: chunk.content || "turn failed",
2075
+ ...typeof chunk.data?.kind === "string" ? { errorKind: chunk.data.kind } : {}
2076
+ });
2077
+ break;
2078
+ case "status":
2079
+ case "done":
2054
2080
  break;
2055
- buffer += decoder.decode(value, { stream: true });
2056
- const parsed2 = drainSseFrames(buffer);
2057
- buffer = parsed2.remainder;
2058
- for (const frame of parsed2.frames)
2059
- dispatch(frame);
2060
2081
  }
2061
- buffer += decoder.decode();
2062
- const parsed = drainSseFrames(buffer, true);
2063
- for (const frame of parsed.frames)
2064
- dispatch(frame);
2065
- } finally {
2066
- ctx.signal.removeEventListener("abort", abort);
2067
- reader.releaseLock();
2068
- }
2069
- return { content: finalContent || accumulated };
2070
- }
2071
- function drainSseFrames(input, flush = false) {
2072
- const parts = input.split(/\r?\n\r?\n/);
2073
- const remainder = flush ? "" : parts.pop() ?? "";
2074
- const frames = parts.map(parseSseFrame).filter((frame) => frame !== null);
2075
- if (flush && parts.length === 0 && input.trim()) {
2076
- const frame = parseSseFrame(input);
2077
- if (frame)
2078
- frames.push(frame);
2079
- }
2080
- return { frames, remainder };
2081
- }
2082
- function parseSseFrame(frame) {
2083
- let event = "message";
2084
- const dataLines = [];
2085
- for (const rawLine of frame.split(/\r?\n/)) {
2086
- const line = rawLine.trimEnd();
2087
- if (line.startsWith("event:")) {
2088
- event = line.slice("event:".length).trim();
2089
- } else if (line.startsWith("data:")) {
2090
- dataLines.push(line.slice("data:".length).trimStart());
2082
+ };
2083
+ let drained = 0;
2084
+ return {
2085
+ ingest,
2086
+ drain: () => {
2087
+ const fresh = rows.slice(drained);
2088
+ drained = rows.length;
2089
+ return fresh;
2090
+ },
2091
+ finish: () => {
2092
+ flushText();
2093
+ const fresh = rows.slice(drained);
2094
+ drained = rows.length;
2095
+ return fresh;
2091
2096
  }
2092
- }
2093
- if (dataLines.length === 0)
2094
- return null;
2095
- const rawData = dataLines.join(`
2096
- `);
2097
- let data = rawData;
2098
- try {
2099
- data = JSON.parse(rawData);
2100
- } catch {}
2101
- return { event, data };
2097
+ };
2102
2098
  }
2103
- function textField(data, key) {
2104
- if (!data || typeof data !== "object")
2105
- return "";
2106
- const value = data[key];
2107
- return typeof value === "string" ? value : "";
2099
+ // packages/sdk/src/utils/plugin-fetch.ts
2100
+ function pluginApiUrl(pluginId, path) {
2101
+ const clean = path.startsWith("/") ? path.slice(1) : path;
2102
+ return `/api/plugins/${pluginId}/${clean}`;
2108
2103
  }
2109
- function abortError() {
2110
- const err = new Error("Aborted");
2111
- err.name = "AbortError";
2112
- return err;
2104
+ function pluginFetch(pluginId, path, init) {
2105
+ const headers = new Headers(init?.headers);
2106
+ if (!headers.has("Accept"))
2107
+ headers.set("Accept", "application/json");
2108
+ let body = init?.body;
2109
+ const isPlainObject = init?.body !== undefined && init.body !== null && typeof init.body === "object" && !(init.body instanceof FormData) && !(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer) && !(init.body instanceof URLSearchParams) && !(typeof ReadableStream !== "undefined" && init.body instanceof ReadableStream);
2110
+ if (isPlainObject) {
2111
+ body = JSON.stringify(init.body);
2112
+ if (!headers.has("Content-Type"))
2113
+ headers.set("Content-Type", "application/json");
2114
+ }
2115
+ return fetch(pluginApiUrl(pluginId, path), { ...init, headers, body });
2113
2116
  }
2114
2117
 
2115
2118
  // packages/sdk/src/utils/index.ts
2116
- function healthOk(check, message) {
2117
- return { check, status: "ok", message, autoFixable: false };
2119
+ function healthHealthy(input) {
2120
+ return { ...input, status: "healthy" };
2121
+ }
2122
+ function healthWarning(input) {
2123
+ return { ...input, status: "warning" };
2124
+ }
2125
+ function healthError(input) {
2126
+ return { ...input, status: "error" };
2118
2127
  }
2119
- function healthWarn(check, message, autoFixable = false) {
2120
- return { check, status: "warn", message, autoFixable };
2128
+ function healthUnknown(input) {
2129
+ return { ...input, status: "unknown" };
2121
2130
  }
2122
- function healthError(check, message, autoFixable = false) {
2123
- return { check, status: "error", message, autoFixable };
2131
+ function healthObserved(observations) {
2132
+ return { outcome: "observed", observations };
2124
2133
  }
2125
- function healthFixed(check, message) {
2126
- return { check, status: "fixed", message, autoFixable: true };
2134
+ function healthNotApplicable(reason) {
2135
+ return { outcome: "not_applicable", reason };
2127
2136
  }
2128
2137
  var TONE_BADGE_CLASS = {
2129
2138
  success: "bg-green-500/10 text-green-400 border-green-500/20",
@@ -2136,22 +2145,29 @@ function toneBadgeClass(tone) {
2136
2145
  return TONE_BADGE_CLASS[tone];
2137
2146
  }
2138
2147
  export {
2148
+ yearMonthFromAssetId,
2149
+ unwrapToolResult,
2139
2150
  toneBadgeClass,
2140
- toBrainstormTimeline,
2141
- runtimeChunkToBrainstormActivity,
2142
- readBrainstormSseResponse,
2143
- normalizeBrainstormActivityMessageForStorage,
2144
- normalizeBrainstormActivityForStorage,
2151
+ summarizeStructured,
2152
+ pluginFetch,
2153
+ pluginApiUrl,
2154
+ isValidAssetId,
2145
2155
  isStale,
2146
- healthWarn,
2147
- healthOk,
2148
- healthFixed,
2156
+ humanizeKey,
2157
+ healthWarning,
2158
+ healthUnknown,
2159
+ healthObserved,
2160
+ healthNotApplicable,
2161
+ healthHealthy,
2149
2162
  healthError,
2163
+ formatStructured,
2150
2164
  formatSize,
2151
2165
  formatDuration,
2152
2166
  formatDateTime,
2153
2167
  formatAge,
2168
+ createTurnRecorder,
2169
+ conversationThreadId,
2154
2170
  cn,
2155
- brainstormThreadId,
2156
- brainstormActivityMessageFromCustom
2171
+ SUMMARY_MAX_CHARS,
2172
+ PREVIEW_MAX_CHARS
2157
2173
  };
@@ -1,23 +0,0 @@
1
- import type { RuntimeChatChunk } from '@makinbakin/sdk/types';
2
- import type { BrainstormMessage } from './types';
3
- export interface BrainstormActivityInput {
4
- kind: string;
5
- content: string;
6
- data?: unknown;
7
- }
8
- export interface BrainstormTimelineMessageInput {
9
- id: string;
10
- role: 'user' | 'assistant' | 'agent';
11
- content: string;
12
- timestamp?: string;
13
- }
14
- export interface BrainstormTimelineActivityInput extends BrainstormActivityInput {
15
- id: string;
16
- timestamp?: string;
17
- }
18
- export declare function runtimeChunkToBrainstormActivity(chunk: RuntimeChatChunk): BrainstormActivityInput | null;
19
- export declare function brainstormActivityMessageFromCustom(name: string, data: unknown): BrainstormMessage | null;
20
- export declare function toBrainstormTimeline(agentId: string, input: {
21
- messages: BrainstormTimelineMessageInput[];
22
- activities?: BrainstormTimelineActivityInput[];
23
- }): BrainstormMessage[];
@@ -1,14 +0,0 @@
1
- import { type LucideIcon } from 'lucide-react';
2
- interface CollapsedHeaderProps {
3
- open: boolean;
4
- collapsible: boolean;
5
- onToggle: () => void;
6
- label: string;
7
- icon: LucideIcon;
8
- replyCount: number;
9
- bodyId: string;
10
- }
11
- export declare function CollapsedHeader({ open, collapsible, onToggle, label, icon: Icon, replyCount, bodyId, }: CollapsedHeaderProps): import("react/jsx-runtime").JSX.Element;
12
- export declare const DEFAULT_LABEL = "Brainstorm";
13
- export declare const DEFAULT_ICON: LucideIcon;
14
- export {};
@@ -1,5 +0,0 @@
1
- interface DefaultEmptyStateProps {
2
- agentId: string;
3
- }
4
- export declare function DefaultEmptyState({ agentId }: DefaultEmptyStateProps): import("react/jsx-runtime").JSX.Element;
5
- export {};
@@ -1,8 +0,0 @@
1
- import type { IntegratedBrainstormProps } from './types';
2
- export type { BrainstormMessage, IntegratedBrainstormProps, BrainstormOnSend, SendContext, AssistantTransformed, } from './types';
3
- export { brainstormActivityMessageFromCustom, runtimeChunkToBrainstormActivity, toBrainstormTimeline, } from './activity';
4
- export { brainstormThreadId, normalizeBrainstormActivityForStorage, normalizeBrainstormActivityMessageForStorage, } from './session';
5
- export type { BrainstormActivityInput, BrainstormTimelineActivityInput, BrainstormTimelineMessageInput, } from './activity';
6
- export type { BrainstormActivityStorageInput, BrainstormActivityStorageRecord, } from './session';
7
- export { readBrainstormSseResponse } from './sse';
8
- export declare function IntegratedBrainstorm({ messages, onMessagesChange, onSend, agentId, onAgentChange, label, icon, placeholder, emptyState, collapsible, defaultOpen, defaultHeight, minHeight, maxHeight, maxInputHeight, storageKey, fitParent, showHeader, readOnly, readOnlyNotice, transformAssistantMessage, }: IntegratedBrainstormProps): import("react/jsx-runtime").JSX.Element;
@@ -1,16 +0,0 @@
1
- import type { BrainstormStatus } from './use-brainstorm-state';
2
- export interface InputRowHandle {
3
- focus: () => void;
4
- }
5
- interface InputRowProps {
6
- placeholder: string;
7
- disabled: boolean;
8
- status: BrainstormStatus;
9
- maxInputHeight: number;
10
- agentId?: string;
11
- onAgentChange?: (agentId: string) => void;
12
- onSubmit: (text: string) => void | Promise<void>;
13
- onAbort: () => void;
14
- }
15
- export declare const InputRow: import("react").ForwardRefExoticComponent<InputRowProps & import("react").RefAttributes<InputRowHandle>>;
16
- export {};
@@ -1,8 +0,0 @@
1
- import type { AssistantTransformed, BrainstormMessage } from './types';
2
- interface MessageListProps {
3
- messages: BrainstormMessage[];
4
- defaultAgentId: string;
5
- transform?: (raw: string) => AssistantTransformed;
6
- }
7
- export declare function MessageList({ messages, defaultAgentId, transform }: MessageListProps): import("react/jsx-runtime").JSX.Element;
8
- export {};