@makinbakin/sdk 0.0.1-rc.2 → 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.
- package/README.md +1 -0
- package/_internal/app/components/agent-select.d.ts +16 -2
- package/_internal/app/components/asset-picker.d.ts +25 -0
- package/_internal/app/components/charts/bar-chart.d.ts +16 -0
- package/_internal/app/components/charts/chart-data-table.d.ts +31 -0
- package/_internal/app/components/charts/chart-explainer.d.ts +9 -0
- package/_internal/app/components/charts/chart-tooltip.d.ts +8 -0
- package/_internal/app/components/charts/line-chart.d.ts +13 -0
- package/_internal/app/components/charts/palette.d.ts +24 -0
- package/_internal/app/components/charts/sparkline.d.ts +12 -0
- package/_internal/app/components/charts/stacked-column-chart.d.ts +40 -0
- package/_internal/app/components/confirm-dialog.d.ts +54 -0
- package/_internal/app/components/conversation/activity-group.d.ts +15 -0
- package/_internal/app/components/conversation/agent-turn.d.ts +36 -0
- package/_internal/app/components/conversation/attention.d.ts +56 -0
- package/_internal/app/components/conversation/composer.d.ts +35 -0
- package/_internal/app/components/conversation/conversation-empty-state.d.ts +8 -0
- package/_internal/app/components/conversation/conversation-panel.d.ts +33 -0
- package/_internal/app/components/conversation/conversation.d.ts +14 -0
- package/_internal/app/components/conversation/fold.d.ts +129 -0
- package/_internal/app/components/conversation/notification-sound.d.ts +8 -0
- package/_internal/app/components/conversation/relative-time.d.ts +8 -0
- package/_internal/app/components/conversation/reply-toast.d.ts +15 -0
- package/_internal/app/components/conversation/thread-id.d.ts +8 -0
- package/_internal/app/components/conversation/tool-call-drawer.d.ts +7 -0
- package/_internal/app/components/conversation/turn-recorder.d.ts +37 -0
- package/_internal/app/components/conversation/use-conversation-attention.d.ts +64 -0
- package/_internal/app/components/conversation/use-conversation-thread.d.ts +55 -0
- package/_internal/app/components/conversation/user-message.d.ts +11 -0
- package/_internal/app/components/danger-zone.d.ts +28 -0
- package/_internal/app/components/empty-state.d.ts +18 -6
- package/_internal/app/components/plugin-header.d.ts +4 -3
- package/_internal/app/components/save-bar.d.ts +32 -0
- package/_internal/app/components/score-overlay.d.ts +33 -0
- package/_internal/app/components/search-degraded-chip.d.ts +4 -0
- package/_internal/app/components/search-partial-chip.d.ts +13 -0
- package/_internal/app/components/search-unavailable.d.ts +12 -0
- package/_internal/app/components/section-card.d.ts +22 -0
- package/_internal/app/components/segmented-control.d.ts +28 -0
- package/_internal/app/components/stat-tile.d.ts +26 -0
- package/_internal/app/components/status-badge.d.ts +19 -0
- package/_internal/app/components/turn-output-view.d.ts +57 -0
- package/_internal/app/components/ui/badge.d.ts +1 -1
- package/_internal/app/components/ui/button.d.ts +1 -1
- package/_internal/app/components/underline-tabs.d.ts +6 -2
- package/_internal/app/components/unsaved-changes-guard.d.ts +34 -0
- package/_internal/app/core/conversation-turns.d.ts +148 -0
- package/_internal/app/core/logger.d.ts +1 -0
- package/_internal/app/hooks/use-available-models.d.ts +5 -0
- package/_internal/app/hooks/use-content-store.d.ts +0 -9
- package/_internal/app/hooks/use-file-drop.d.ts +25 -0
- package/_internal/app/hooks/use-history-back.d.ts +1 -0
- package/_internal/app/hooks/use-horizontal-resize.d.ts +22 -0
- package/_internal/app/hooks/use-json-fetch.d.ts +26 -0
- package/_internal/app/hooks/use-nav-badge.d.ts +13 -0
- package/_internal/app/hooks/use-plugin-event.d.ts +19 -0
- package/_internal/app/hooks/use-query-state.d.ts +2 -0
- package/_internal/app/hooks/use-resizable-pane.d.ts +35 -0
- package/_internal/app/hooks/use-schedule.d.ts +47 -1
- package/_internal/app/hooks/use-search.d.ts +27 -8
- package/_internal/app/hooks/use-task-run-history.d.ts +26 -0
- package/_internal/app/hooks/use-toast.d.ts +3 -3
- package/_internal/app/hooks/use-vertical-resize.d.ts +6 -7
- package/_internal/app/lib/browser-notify.d.ts +12 -1
- package/_internal/app/types/index.d.ts +1 -105
- package/_internal/core/adapters/runtime/concepts.d.ts +671 -99
- package/_internal/core/adapters/runtime/errors.d.ts +98 -0
- package/_internal/core/adapters/runtime/helpers.d.ts +19 -0
- package/_internal/core/adapters/runtime/index.d.ts +7 -2
- package/_internal/core/adapters/runtime/testing.d.ts +79 -0
- package/_internal/core/adapters/runtime/turn-activity.d.ts +23 -0
- package/_internal/core/adapters/shared.d.ts +122 -12
- package/_internal/core/content-dir.d.ts +9 -0
- package/_internal/core/docs/route.d.ts +1 -1
- package/_internal/core/format/structured.d.ts +44 -0
- package/_internal/core/format.d.ts +13 -0
- package/_internal/core/media/downscale.d.ts +18 -0
- package/_internal/core/media/sharp-loader.d.ts +36 -0
- package/_internal/core/plugin-types.d.ts +216 -499
- package/_internal/core/routing/define.d.ts +26 -3
- package/_internal/core/routing/dispatcher.d.ts +15 -6
- package/_internal/core/routing/index.d.ts +1 -1
- package/_internal/core/routing/types.d.ts +13 -70
- package/_internal/core/storage/atomic-write.d.ts +11 -0
- package/_internal/core/tasks/store.d.ts +129 -0
- package/_internal/core/tasks/testing.d.ts +2 -0
- package/_internal/{plugins/workflows/lib → core/workflows}/notification-channel-registry.d.ts +1 -1
- package/_internal/plugins/team/types.d.ts +61 -4
- package/_internal/plugins/workflows/hooks/use-notification-channels.d.ts +1 -1
- package/components/index.d.ts +111 -5
- package/components/index.js +61815 -30060
- package/hooks/index.d.ts +90 -9
- package/hooks/index.js +15181 -685
- package/hooks/router.d.ts +20 -4
- package/index.d.ts +20 -3
- package/index.js +297 -259
- package/internal/index.d.ts +70 -0
- package/internal/index.js +409 -0
- package/metadata/index.d.ts +14 -1
- package/package.json +9 -2
- package/register.d.ts +63 -9
- package/routing/index.d.ts +6 -1
- package/routing/index.js +187 -147
- package/slots/index.d.ts +16 -24
- package/slots/index.js +215 -30
- package/testing/index.d.ts +122 -0
- package/testing/index.js +21874 -0
- package/types/index.d.ts +19 -919
- package/types/index.js +16 -0
- package/ui/index.js +2 -1
- package/utils/index.d.ts +46 -6
- package/utils/index.js +322 -249
- package/_internal/app/components/integrated-brainstorm/activity.d.ts +0 -23
- package/_internal/app/components/integrated-brainstorm/collapsed-header.d.ts +0 -14
- package/_internal/app/components/integrated-brainstorm/empty-state.d.ts +0 -5
- package/_internal/app/components/integrated-brainstorm/index.d.ts +0 -8
- package/_internal/app/components/integrated-brainstorm/input-row.d.ts +0 -16
- package/_internal/app/components/integrated-brainstorm/message-list.d.ts +0 -8
- package/_internal/app/components/integrated-brainstorm/session.d.ts +0 -16
- package/_internal/app/components/integrated-brainstorm/sse.d.ts +0 -8
- package/_internal/app/components/integrated-brainstorm/thinking-indicator.d.ts +0 -19
- package/_internal/app/components/integrated-brainstorm/types.d.ts +0 -63
- package/_internal/app/components/integrated-brainstorm/use-auto-grow.d.ts +0 -6
- package/_internal/app/components/integrated-brainstorm/use-brainstorm-state.d.ts +0 -21
- package/_internal/app/hooks/use-assets.d.ts +0 -25
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();
|
|
@@ -1812,6 +1951,38 @@ function formatAge(timestamp) {
|
|
|
1812
1951
|
const days = Math.floor(hours / 24);
|
|
1813
1952
|
return `${days}d ago`;
|
|
1814
1953
|
}
|
|
1954
|
+
function formatDateTime(timestamp) {
|
|
1955
|
+
const d = new Date(timestamp);
|
|
1956
|
+
if (isNaN(d.getTime()))
|
|
1957
|
+
return timestamp;
|
|
1958
|
+
const now = new Date;
|
|
1959
|
+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
1960
|
+
const target = new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
1961
|
+
const diffDays = Math.round((today.getTime() - target.getTime()) / 86400000);
|
|
1962
|
+
const time = d.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" });
|
|
1963
|
+
if (diffDays === 0)
|
|
1964
|
+
return `Today ${time}`;
|
|
1965
|
+
if (diffDays === 1)
|
|
1966
|
+
return `Yesterday ${time}`;
|
|
1967
|
+
const sameYear = d.getFullYear() === now.getFullYear();
|
|
1968
|
+
return `${d.toLocaleDateString("en-US", { month: "short", day: "numeric", ...sameYear ? {} : { year: "numeric" } })} ${time}`;
|
|
1969
|
+
}
|
|
1970
|
+
function formatDuration(ms) {
|
|
1971
|
+
if (ms == null)
|
|
1972
|
+
return null;
|
|
1973
|
+
if (ms < 1000)
|
|
1974
|
+
return `${ms}ms`;
|
|
1975
|
+
const s = Math.round(ms / 1000);
|
|
1976
|
+
if (s < 60)
|
|
1977
|
+
return `${s}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`;
|
|
1985
|
+
}
|
|
1815
1986
|
function formatSize(bytes) {
|
|
1816
1987
|
if (bytes < 1024)
|
|
1817
1988
|
return `${bytes} B`;
|
|
@@ -1824,277 +1995,179 @@ function formatSize(bytes) {
|
|
|
1824
1995
|
function isStale(timestamp, thresholdMs = 15 * 60 * 1000) {
|
|
1825
1996
|
return Date.now() - new Date(timestamp).getTime() > thresholdMs;
|
|
1826
1997
|
}
|
|
1827
|
-
// src/components/
|
|
1828
|
-
|
|
1829
|
-
var ACTIVITY_PREVIEW_MAX_CHARS = 2000;
|
|
1830
|
-
var ACTIVITY_METADATA_MAX_CHARS = 4000;
|
|
1831
|
-
var ACTIVITY_DATA_MAX_KEYS = 24;
|
|
1832
|
-
function brainstormThreadId(scope, entityId, agentId) {
|
|
1998
|
+
// src/components/conversation/thread-id.ts
|
|
1999
|
+
function conversationThreadId(scope, entityId, agentId) {
|
|
1833
2000
|
return [scope, entityId, agentId].map(threadIdPart).join(":");
|
|
1834
2001
|
}
|
|
1835
|
-
function normalizeBrainstormActivityForStorage(activity) {
|
|
1836
|
-
const content = typeof activity.content === "string" ? truncate(activity.content.trim(), ACTIVITY_CONTENT_MAX_CHARS) : "";
|
|
1837
|
-
if (!content)
|
|
1838
|
-
return null;
|
|
1839
|
-
const data = normalizeActivityData(activity.data);
|
|
1840
|
-
return {
|
|
1841
|
-
kind: typeof activity.kind === "string" && activity.kind ? activity.kind : "runtime_status",
|
|
1842
|
-
content,
|
|
1843
|
-
...data !== undefined ? { data } : {}
|
|
1844
|
-
};
|
|
1845
|
-
}
|
|
1846
|
-
function normalizeBrainstormActivityMessageForStorage(activity) {
|
|
1847
|
-
const normalized = normalizeBrainstormActivityForStorage(activity);
|
|
1848
|
-
if (!normalized)
|
|
1849
|
-
return null;
|
|
1850
|
-
return {
|
|
1851
|
-
role: "activity",
|
|
1852
|
-
kind: normalized.kind,
|
|
1853
|
-
content: normalized.content,
|
|
1854
|
-
...normalized.data !== undefined ? { data: normalized.data } : {}
|
|
1855
|
-
};
|
|
1856
|
-
}
|
|
1857
2002
|
function threadIdPart(value) {
|
|
1858
2003
|
const trimmed = value.trim();
|
|
1859
2004
|
return encodeURIComponent(trimmed || "default");
|
|
1860
2005
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
for (const [key, value] of Object.entries(data)) {
|
|
1869
|
-
if (count >= ACTIVITY_DATA_MAX_KEYS) {
|
|
1870
|
-
out.truncatedKeys = Object.keys(data).length - count;
|
|
1871
|
-
break;
|
|
1872
|
-
}
|
|
1873
|
-
out[key] = normalizeActivityValue(value, key);
|
|
1874
|
-
count += 1;
|
|
1875
|
-
}
|
|
1876
|
-
return out;
|
|
1877
|
-
}
|
|
1878
|
-
function normalizeActivityValue(value, key) {
|
|
1879
|
-
if (typeof value === "string") {
|
|
1880
|
-
const max = isPreviewKey(key) ? ACTIVITY_PREVIEW_MAX_CHARS : ACTIVITY_METADATA_MAX_CHARS;
|
|
1881
|
-
return truncate(value, max);
|
|
1882
|
-
}
|
|
1883
|
-
if (typeof value === "number" || typeof value === "boolean" || value === null)
|
|
1884
|
-
return value;
|
|
1885
|
-
if (value === undefined)
|
|
1886
|
-
return;
|
|
1887
|
-
return truncate(stringify(value), ACTIVITY_METADATA_MAX_CHARS);
|
|
1888
|
-
}
|
|
1889
|
-
function isPreviewKey(key) {
|
|
1890
|
-
return key === "inputPreview" || key === "argumentsPreview" || key === "outputPreview" || key === "resultPreview";
|
|
1891
|
-
}
|
|
1892
|
-
function stringify(value) {
|
|
1893
|
-
try {
|
|
1894
|
-
return JSON.stringify(value);
|
|
1895
|
-
} catch {
|
|
1896
|
-
return String(value);
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
function truncate(value, maxChars) {
|
|
1900
|
-
if (value.length <= maxChars)
|
|
1901
|
-
return value;
|
|
1902
|
-
return `${value.slice(0, Math.max(0, maxChars - 3))}...`;
|
|
1903
|
-
}
|
|
1904
|
-
function isRecord(value) {
|
|
1905
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1908
|
-
// src/components/integrated-brainstorm/activity.ts
|
|
1909
|
-
function newActivityId() {
|
|
1910
|
-
return `act-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1911
|
-
}
|
|
1912
|
-
function runtimeChunkToBrainstormActivity(chunk) {
|
|
1913
|
-
if (chunk.type === "status") {
|
|
1914
|
-
return {
|
|
1915
|
-
kind: "runtime_status",
|
|
1916
|
-
content: chunk.content || "Agent status update",
|
|
1917
|
-
data: chunk.data
|
|
1918
|
-
};
|
|
1919
|
-
}
|
|
1920
|
-
if (chunk.type === "tool") {
|
|
1921
|
-
return {
|
|
1922
|
-
kind: "tool_call",
|
|
1923
|
-
content: chunk.content || "Tool call",
|
|
1924
|
-
data: chunk.data
|
|
1925
|
-
};
|
|
1926
|
-
}
|
|
1927
|
-
if (chunk.type === "error") {
|
|
1928
|
-
return {
|
|
1929
|
-
kind: "error",
|
|
1930
|
-
content: chunk.content || "Runtime stream error",
|
|
1931
|
-
data: chunk.data
|
|
1932
|
-
};
|
|
1933
|
-
}
|
|
1934
|
-
return null;
|
|
1935
|
-
}
|
|
1936
|
-
function brainstormActivityMessageFromCustom(name, data) {
|
|
1937
|
-
if (name !== "activity")
|
|
1938
|
-
return null;
|
|
1939
|
-
const payload = data && typeof data === "object" && "activity" in data ? data.activity : data;
|
|
1940
|
-
if (!payload || typeof payload !== "object")
|
|
1941
|
-
return null;
|
|
1942
|
-
const activity = payload;
|
|
1943
|
-
const content = typeof activity.content === "string" ? activity.content : "";
|
|
1944
|
-
if (!content)
|
|
1945
|
-
return null;
|
|
1946
|
-
const normalized = normalizeBrainstormActivityForStorage({
|
|
1947
|
-
kind: typeof activity.kind === "string" ? activity.kind : "runtime_status",
|
|
1948
|
-
content,
|
|
1949
|
-
data: activity.data
|
|
1950
|
-
});
|
|
1951
|
-
if (!normalized)
|
|
1952
|
-
return null;
|
|
1953
|
-
return {
|
|
1954
|
-
id: typeof activity.id === "string" ? activity.id : newActivityId(),
|
|
1955
|
-
role: "activity",
|
|
1956
|
-
kind: normalized.kind,
|
|
1957
|
-
content: normalized.content,
|
|
1958
|
-
...normalized.data !== undefined ? { data: normalized.data } : {},
|
|
1959
|
-
timestamp: typeof activity.timestamp === "string" ? activity.timestamp : new Date().toISOString()
|
|
1960
|
-
};
|
|
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 };
|
|
1961
2013
|
}
|
|
1962
|
-
function
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
}
|
|
1971
|
-
...(input.activities ?? []).map((activity) => ({
|
|
1972
|
-
id: activity.id,
|
|
1973
|
-
role: "activity",
|
|
1974
|
-
kind: activity.kind,
|
|
1975
|
-
content: activity.content,
|
|
1976
|
-
data: activity.data,
|
|
1977
|
-
timestamp: activity.timestamp
|
|
1978
|
-
}))
|
|
1979
|
-
].sort((a, b) => {
|
|
1980
|
-
const aTime = a.timestamp ? Date.parse(a.timestamp) : 0;
|
|
1981
|
-
const bTime = b.timestamp ? Date.parse(b.timestamp) : 0;
|
|
1982
|
-
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 } : {}
|
|
1983
2023
|
});
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
if (!response.ok || !response.body) {
|
|
1988
|
-
const text = await response.text().catch(() => "");
|
|
1989
|
-
throw new Error(text || `Server returned ${response.status}`);
|
|
1990
|
-
}
|
|
1991
|
-
const reader = response.body.getReader();
|
|
1992
|
-
const abort = () => {
|
|
1993
|
-
reader.cancel().catch(() => {});
|
|
1994
|
-
};
|
|
1995
|
-
ctx.signal.addEventListener("abort", abort, { once: true });
|
|
1996
|
-
const decoder = new TextDecoder;
|
|
1997
|
-
let buffer = "";
|
|
1998
|
-
let accumulated = "";
|
|
1999
|
-
let finalContent = "";
|
|
2000
|
-
const dispatch = (frame) => {
|
|
2001
|
-
if (frame.event === "token") {
|
|
2002
|
-
const text = textField(frame.data, "text");
|
|
2003
|
-
accumulated += text;
|
|
2004
|
-
ctx.onToken(text);
|
|
2005
|
-
return;
|
|
2006
|
-
}
|
|
2007
|
-
if (frame.event === "activity") {
|
|
2008
|
-
ctx.onCustom?.("activity", frame.data);
|
|
2024
|
+
const flushText = () => {
|
|
2025
|
+
if (!pendingText.trim()) {
|
|
2026
|
+
pendingText = "";
|
|
2009
2027
|
return;
|
|
2010
2028
|
}
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
return;
|
|
2014
|
-
}
|
|
2015
|
-
if (frame.event === "error") {
|
|
2016
|
-
throw new Error(textField(frame.data, "message") || "Unknown error");
|
|
2017
|
-
}
|
|
2018
|
-
if (options.onCustomEvent?.(frame.event, frame.data) === true)
|
|
2019
|
-
return;
|
|
2020
|
-
ctx.onCustom?.(frame.event, frame.data);
|
|
2029
|
+
rows.push({ kind: "assistant", ...base(), content: pendingText });
|
|
2030
|
+
pendingText = "";
|
|
2021
2031
|
};
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
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":
|
|
2028
2080
|
break;
|
|
2029
|
-
buffer += decoder.decode(value, { stream: true });
|
|
2030
|
-
const parsed2 = drainSseFrames(buffer);
|
|
2031
|
-
buffer = parsed2.remainder;
|
|
2032
|
-
for (const frame of parsed2.frames)
|
|
2033
|
-
dispatch(frame);
|
|
2034
2081
|
}
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
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;
|
|
2096
|
+
}
|
|
2097
|
+
};
|
|
2044
2098
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
const
|
|
2048
|
-
|
|
2049
|
-
if (flush && parts.length === 0 && input.trim()) {
|
|
2050
|
-
const frame = parseSseFrame(input);
|
|
2051
|
-
if (frame)
|
|
2052
|
-
frames.push(frame);
|
|
2053
|
-
}
|
|
2054
|
-
return { frames, remainder };
|
|
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}`;
|
|
2055
2103
|
}
|
|
2056
|
-
function
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
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");
|
|
2066
2114
|
}
|
|
2067
|
-
|
|
2068
|
-
return null;
|
|
2069
|
-
const rawData = dataLines.join(`
|
|
2070
|
-
`);
|
|
2071
|
-
let data = rawData;
|
|
2072
|
-
try {
|
|
2073
|
-
data = JSON.parse(rawData);
|
|
2074
|
-
} catch {}
|
|
2075
|
-
return { event, data };
|
|
2115
|
+
return fetch(pluginApiUrl(pluginId, path), { ...init, headers, body });
|
|
2076
2116
|
}
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2117
|
+
|
|
2118
|
+
// packages/sdk/src/utils/index.ts
|
|
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" };
|
|
2127
|
+
}
|
|
2128
|
+
function healthUnknown(input) {
|
|
2129
|
+
return { ...input, status: "unknown" };
|
|
2082
2130
|
}
|
|
2083
|
-
function
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2131
|
+
function healthObserved(observations) {
|
|
2132
|
+
return { outcome: "observed", observations };
|
|
2133
|
+
}
|
|
2134
|
+
function healthNotApplicable(reason) {
|
|
2135
|
+
return { outcome: "not_applicable", reason };
|
|
2136
|
+
}
|
|
2137
|
+
var TONE_BADGE_CLASS = {
|
|
2138
|
+
success: "bg-green-500/10 text-green-400 border-green-500/20",
|
|
2139
|
+
pending: "bg-amber-500/10 text-amber-400 border-amber-500/20",
|
|
2140
|
+
error: "bg-red-500/10 text-red-400 border-red-500/20",
|
|
2141
|
+
muted: "bg-zinc-500/10 text-zinc-400 border-zinc-500/20",
|
|
2142
|
+
info: "bg-blue-500/10 text-blue-400 border-blue-500/20"
|
|
2143
|
+
};
|
|
2144
|
+
function toneBadgeClass(tone) {
|
|
2145
|
+
return TONE_BADGE_CLASS[tone];
|
|
2087
2146
|
}
|
|
2088
2147
|
export {
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2148
|
+
yearMonthFromAssetId,
|
|
2149
|
+
unwrapToolResult,
|
|
2150
|
+
toneBadgeClass,
|
|
2151
|
+
summarizeStructured,
|
|
2152
|
+
pluginFetch,
|
|
2153
|
+
pluginApiUrl,
|
|
2154
|
+
isValidAssetId,
|
|
2094
2155
|
isStale,
|
|
2156
|
+
humanizeKey,
|
|
2157
|
+
healthWarning,
|
|
2158
|
+
healthUnknown,
|
|
2159
|
+
healthObserved,
|
|
2160
|
+
healthNotApplicable,
|
|
2161
|
+
healthHealthy,
|
|
2162
|
+
healthError,
|
|
2163
|
+
formatStructured,
|
|
2095
2164
|
formatSize,
|
|
2165
|
+
formatDuration,
|
|
2166
|
+
formatDateTime,
|
|
2096
2167
|
formatAge,
|
|
2168
|
+
createTurnRecorder,
|
|
2169
|
+
conversationThreadId,
|
|
2097
2170
|
cn,
|
|
2098
|
-
|
|
2099
|
-
|
|
2171
|
+
SUMMARY_MAX_CHARS,
|
|
2172
|
+
PREVIEW_MAX_CHARS
|
|
2100
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,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;
|