@chat-lab/ui 0.1.0-beta.41 → 0.1.0-beta.43
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/dist/_virtual/_commonjsHelpers.cjs +26 -0
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -1
- package/dist/_virtual/_commonjsHelpers.js +26 -1
- package/dist/_virtual/_commonjsHelpers.js.map +1 -1
- package/dist/_virtual/index.cjs +2 -2
- package/dist/_virtual/index.js +2 -2
- package/dist/_virtual/index2.cjs +2 -2
- package/dist/_virtual/index2.js +2 -2
- package/dist/_virtual/index3.cjs +2 -2
- package/dist/_virtual/index3.js +2 -2
- package/dist/_virtual/index4.cjs +5 -2
- package/dist/_virtual/index4.cjs.map +1 -1
- package/dist/_virtual/index4.js +5 -2
- package/dist/_virtual/index4.js.map +1 -1
- package/dist/_virtual/index5.cjs +2 -5
- package/dist/_virtual/index5.cjs.map +1 -1
- package/dist/_virtual/index5.js +2 -5
- package/dist/_virtual/index5.js.map +1 -1
- package/dist/adk/components/Debug/Events/index.cjs +1 -1
- package/dist/adk/components/Debug/Events/index.js +1 -1
- package/dist/adk/components/Debug/Trace/store.cjs +3 -3
- package/dist/adk/components/Debug/Trace/store.cjs.map +1 -1
- package/dist/adk/components/Debug/Trace/store.js +1 -1
- package/dist/adk/hooks/useEvents.cjs +4 -4
- package/dist/adk/hooks/useEvents.cjs.map +1 -1
- package/dist/adk/hooks/useEvents.js +2 -2
- package/dist/components/Chatkit/index.cjs +8 -9
- package/dist/components/Chatkit/index.cjs.map +1 -1
- package/dist/components/Chatkit/index.d.ts +2 -2
- package/dist/components/Chatkit/index.d.ts.map +1 -1
- package/dist/components/Chatkit/index.js +8 -9
- package/dist/components/Chatkit/index.js.map +1 -1
- package/dist/components/Chatkit/types.d.ts +1 -0
- package/dist/components/Chatkit/types.d.ts.map +1 -1
- package/dist/components/assistant-ui/thread.cjs +17 -15
- package/dist/components/assistant-ui/thread.cjs.map +1 -1
- package/dist/components/assistant-ui/thread.d.ts.map +1 -1
- package/dist/components/assistant-ui/thread.js +16 -14
- package/dist/components/assistant-ui/thread.js.map +1 -1
- package/dist/components/thread-list.cjs +5 -5
- package/dist/components/thread-list.cjs.map +1 -1
- package/dist/index.css +2 -1
- package/dist/node_modules/.pnpm/@assistant-ui_react@0.11.37_patch_hash_wncib234fzw2z5h67nrdhchb2a_@types_react-dom@17.0.2_@ty_c64hu5rigivj2gtpzfqjqatr5y/node_modules/@assistant-ui/react/dist/primitives/messagePart/useMessagePartText.cjs.map +1 -1
- package/dist/node_modules/.pnpm/@assistant-ui_react@0.11.37_patch_hash_wncib234fzw2z5h67nrdhchb2a_@types_react-dom@17.0.2_@ty_c64hu5rigivj2gtpzfqjqatr5y/node_modules/@assistant-ui/react/dist/primitives/messagePart/useMessagePartText.js.map +1 -1
- package/dist/node_modules/.pnpm/@cloudfun_web-sdk@3.1.7_@volcengine_console-web-sdk@6.2.0/node_modules/@cloudfun/web-sdk/lib/util.cjs +1 -1
- package/dist/node_modules/.pnpm/@cloudfun_web-sdk@3.1.7_@volcengine_console-web-sdk@6.2.0/node_modules/@cloudfun/web-sdk/lib/util.js +1 -1
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@3.29.5_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.cjs +18 -0
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@3.29.5_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.cjs.map +1 -1
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@3.29.5_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js +17 -1
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@11.1.6_rollup@3.29.5_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.cjs +1 -1
- package/dist/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js +1 -1
- package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.cjs +1 -1
- package/dist/node_modules/.pnpm/crypto-js@4.2.0/node_modules/crypto-js/index.js +1 -1
- package/dist/node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.cjs +4 -1
- package/dist/node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.cjs.map +1 -1
- package/dist/node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.js +1 -1
- package/dist/node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/findLastIndex.cjs +62 -0
- package/dist/node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/findLastIndex.cjs.map +1 -0
- package/dist/node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/findLastIndex.js +60 -0
- package/dist/node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/findLastIndex.js.map +1 -0
- package/dist/node_modules/.pnpm/secure-json-parse@4.1.0/node_modules/secure-json-parse/index.cjs +1 -1
- package/dist/node_modules/.pnpm/secure-json-parse@4.1.0/node_modules/secure-json-parse/index.js +1 -1
- package/dist/node_modules/.pnpm/style-to-js@1.1.18/node_modules/style-to-js/cjs/index.cjs +1 -1
- package/dist/node_modules/.pnpm/style-to-js@1.1.18/node_modules/style-to-js/cjs/index.js +1 -1
- package/dist/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.cjs +1 -1
- package/dist/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.js +1 -1
- package/dist/node_modules/.pnpm/use-sidecar@1.1.3_@types_react@17.0.2_react@17.0.2/node_modules/use-sidecar/dist/es2015/medium.cjs +5 -0
- package/dist/node_modules/.pnpm/use-sidecar@1.1.3_@types_react@17.0.2_react@17.0.2/node_modules/use-sidecar/dist/es2015/medium.cjs.map +1 -1
- package/dist/node_modules/.pnpm/use-sidecar@1.1.3_@types_react@17.0.2_react@17.0.2/node_modules/use-sidecar/dist/es2015/medium.js +5 -1
- package/dist/node_modules/.pnpm/use-sidecar@1.1.3_@types_react@17.0.2_react@17.0.2/node_modules/use-sidecar/dist/es2015/medium.js.map +1 -1
- package/dist/node_modules/.pnpm/use-sync-external-store@1.6.0_react@17.0.2/node_modules/use-sync-external-store/shim/index.cjs +1 -1
- package/dist/node_modules/.pnpm/use-sync-external-store@1.6.0_react@17.0.2/node_modules/use-sync-external-store/shim/index.js +1 -1
- package/dist/node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/vanilla.cjs +1 -0
- package/dist/node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/vanilla.cjs.map +1 -1
- package/dist/node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/vanilla.js +1 -0
- package/dist/node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/vanilla.js.map +1 -1
- package/dist/node_modules/clsx/dist/clsx.cjs +9 -0
- package/dist/node_modules/clsx/dist/clsx.cjs.map +1 -0
- package/dist/node_modules/clsx/dist/clsx.js +4 -0
- package/dist/node_modules/clsx/dist/clsx.js.map +1 -0
- package/dist/node_modules/dayjs/dayjs.min.cjs +14 -0
- package/dist/node_modules/dayjs/dayjs.min.cjs.map +1 -0
- package/dist/node_modules/dayjs/dayjs.min.js +12 -0
- package/dist/node_modules/dayjs/dayjs.min.js.map +1 -0
- package/dist/packages/chatui/node_modules/@cloudfun/top-proxy-sdk/lib/client.cjs +1 -1
- package/dist/packages/chatui/node_modules/@cloudfun/top-proxy-sdk/lib/client.cjs.map +1 -1
- package/dist/packages/chatui/node_modules/@cloudfun/top-proxy-sdk/lib/client.js +1 -1
- package/dist/packages/chatui/node_modules/@cloudfun/top-proxy-sdk/lib/client.js.map +1 -1
- package/dist/packages/core/dist/index.cjs +87 -54
- package/dist/packages/core/dist/index.cjs.map +1 -1
- package/dist/packages/core/dist/index.js +79 -46
- package/dist/packages/core/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,32 @@ function getDefaultExportFromCjs (x) {
|
|
|
6
6
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
function getAugmentedNamespace(n) {
|
|
10
|
+
if (n.__esModule) return n;
|
|
11
|
+
var f = n.default;
|
|
12
|
+
if (typeof f == "function") {
|
|
13
|
+
var a = function a () {
|
|
14
|
+
if (this instanceof a) {
|
|
15
|
+
return Reflect.construct(f, arguments, this.constructor);
|
|
16
|
+
}
|
|
17
|
+
return f.apply(this, arguments);
|
|
18
|
+
};
|
|
19
|
+
a.prototype = f.prototype;
|
|
20
|
+
} else a = {};
|
|
21
|
+
Object.defineProperty(a, '__esModule', {value: true});
|
|
22
|
+
Object.keys(n).forEach(function (k) {
|
|
23
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
24
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return n[k];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
return a;
|
|
32
|
+
}
|
|
33
|
+
|
|
9
34
|
exports.commonjsGlobal = commonjsGlobal;
|
|
35
|
+
exports.getAugmentedNamespace = getAugmentedNamespace;
|
|
10
36
|
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
|
|
11
37
|
//# sourceMappingURL=_commonjsHelpers.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_commonjsHelpers.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_commonjsHelpers.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -4,5 +4,30 @@ function getDefaultExportFromCjs (x) {
|
|
|
4
4
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function getAugmentedNamespace(n) {
|
|
8
|
+
if (n.__esModule) return n;
|
|
9
|
+
var f = n.default;
|
|
10
|
+
if (typeof f == "function") {
|
|
11
|
+
var a = function a () {
|
|
12
|
+
if (this instanceof a) {
|
|
13
|
+
return Reflect.construct(f, arguments, this.constructor);
|
|
14
|
+
}
|
|
15
|
+
return f.apply(this, arguments);
|
|
16
|
+
};
|
|
17
|
+
a.prototype = f.prototype;
|
|
18
|
+
} else a = {};
|
|
19
|
+
Object.defineProperty(a, '__esModule', {value: true});
|
|
20
|
+
Object.keys(n).forEach(function (k) {
|
|
21
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
22
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return n[k];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
return a;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { commonjsGlobal, getAugmentedNamespace, getDefaultExportFromCjs };
|
|
8
33
|
//# sourceMappingURL=_commonjsHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/_virtual/index.cjs
CHANGED
package/dist/_virtual/index.js
CHANGED
package/dist/_virtual/index2.cjs
CHANGED
package/dist/_virtual/index2.js
CHANGED
package/dist/_virtual/index3.cjs
CHANGED
package/dist/_virtual/index3.js
CHANGED
package/dist/_virtual/index4.cjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _commonjsHelpers = require('./_commonjsHelpers.cjs');
|
|
4
|
+
var index = require('../node_modules/.pnpm/@volcengine_console-web-sdk@6.2.0/node_modules/@volcengine/console-web-sdk/dist/js/treeshaking/index.cjs');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
var require$$0 = /*@__PURE__*/_commonjsHelpers.getAugmentedNamespace(index);
|
|
7
|
+
|
|
8
|
+
module.exports = require$$0;
|
|
6
9
|
//# sourceMappingURL=index4.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index4.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index4.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
package/dist/_virtual/index4.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { getAugmentedNamespace } from './_commonjsHelpers.js';
|
|
2
|
+
import * as index from '../node_modules/.pnpm/@volcengine_console-web-sdk@6.2.0/node_modules/@volcengine/console-web-sdk/dist/js/treeshaking/index.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
var require$$0 = /*@__PURE__*/getAugmentedNamespace(index);
|
|
5
|
+
|
|
6
|
+
export { require$$0 as default };
|
|
4
7
|
//# sourceMappingURL=index4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index4.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index4.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/dist/_virtual/index5.cjs
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var index = require('../node_modules/.pnpm/@volcengine_console-web-sdk@6.2.0/node_modules/@volcengine/console-web-sdk/dist/js/treeshaking/index.cjs');
|
|
3
|
+
var cryptoJs = {exports: {}};
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
module.exports = require$$0;
|
|
5
|
+
exports.__module = cryptoJs;
|
|
9
6
|
//# sourceMappingURL=index5.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index5.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index5.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
package/dist/_virtual/index5.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import * as index from '../node_modules/.pnpm/@volcengine_console-web-sdk@6.2.0/node_modules/@volcengine/console-web-sdk/dist/js/treeshaking/index.js';
|
|
1
|
+
var cryptoJs = {exports: {}};
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { require$$0 as default };
|
|
3
|
+
export { cryptoJs as __module };
|
|
7
4
|
//# sourceMappingURL=index5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index5.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index5.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var React = require('react');
|
|
5
|
-
var index = require('../../../../node_modules/ahooks/es/useVirtualList/index.cjs');
|
|
5
|
+
var index = require('../../../../node_modules/.pnpm/ahooks@3.9.6_react-dom@17.0.2_react@17.0.2__react@17.0.2/node_modules/ahooks/es/useVirtualList/index.cjs');
|
|
6
6
|
var card = require('../../../../components/ui/card.cjs');
|
|
7
7
|
var EventDetail = require('./EventDetail.cjs');
|
|
8
8
|
var Empty = require('../../../../assets/Empty.cjs');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useRef, useMemo } from 'react';
|
|
3
|
-
import useVirtualList from '../../../../node_modules/ahooks/es/useVirtualList/index.js';
|
|
3
|
+
import useVirtualList from '../../../../node_modules/.pnpm/ahooks@3.9.6_react-dom@17.0.2_react@17.0.2__react@17.0.2/node_modules/ahooks/es/useVirtualList/index.js';
|
|
4
4
|
import { Card, CardContent } from '../../../../components/ui/card.js';
|
|
5
5
|
import EventDetail from './EventDetail.js';
|
|
6
6
|
import Empty from '../../../../assets/Empty.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var dayjs_min = require('../../../../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.cjs');
|
|
4
|
-
var fetch = require('../../../../node_modules/@byted-iaas/fetch/lib/fetch.cjs');
|
|
4
|
+
var fetch = require('../../../../node_modules/.pnpm/@byted-iaas_fetch@0.0.13_@arco-design_web-react@2.64.1_@types_react@17.0.2_react-dom@17.0.2_r_c5lheq6mbvfvtoizhtvrll35su/node_modules/@byted-iaas/fetch/lib/fetch.cjs');
|
|
5
5
|
var react = require('../../../../node_modules/.pnpm/zustand@5.0.8_patch_hash_rz6xqpd4m4x2bh7isifaksfeb4_@types_react@17.0.2_react@17.0.2_use-sync_ay3nj3f4buvymz7rhhedugq5p4/node_modules/zustand/esm/react.cjs');
|
|
6
6
|
|
|
7
7
|
const FetchInstance = new fetch.IaasFetch({
|
|
@@ -76,12 +76,12 @@ const useTraceStore = react.create((set, get) => ({
|
|
|
76
76
|
// Always set loading to true when fetching starts
|
|
77
77
|
set({ isLoading: true });
|
|
78
78
|
try {
|
|
79
|
-
const now = dayjs_min();
|
|
79
|
+
const now = dayjs_min.default();
|
|
80
80
|
const res = await FetchInstance.request({
|
|
81
81
|
action: 'GetSessionSpans',
|
|
82
82
|
params: {
|
|
83
83
|
SessionId: sessionId || '',
|
|
84
|
-
StartTime: dayjs_min().subtract(1, 'd').valueOf(),
|
|
84
|
+
StartTime: dayjs_min.default().subtract(1, 'd').valueOf(),
|
|
85
85
|
EndTime: now.valueOf(),
|
|
86
86
|
},
|
|
87
87
|
type: 'open-top',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.cjs","sources":["../../../../../src/adk/components/Debug/Trace/store.ts"],"sourcesContent":["import { create } from 'zustand';\nimport { TraceSpan, TraceNode } from './types';\nimport dayjs from 'dayjs';\nimport IaasFetch from '@byted-iaas/fetch';\n\nconst FetchInstance = new IaasFetch({\n service: 'apmplus_server',\n version: '2024-07-30',\n platform: 'VOLCENGINE',\n disablePreTcc: true,\n});\n\ninterface RawSpan {\n OperationName: string;\n SpanId: string;\n TraceId: string;\n Input: string;\n Output: string;\n SpanKind: string;\n Model: string;\n InputTokens: number;\n OutputTokens: number;\n TotalTokens: number;\n Duration: number;\n StartTime: number;\n EndTime: number;\n ParentSpanId?: string;\n Tags?: Record<string, any>;\n}\n\n// Helper function to convert RawSpan to TraceSpan\nconst convertToTraceSpan = (raw: RawSpan): TraceSpan => {\n return {\n id: raw.SpanId,\n name: raw.OperationName,\n status: 'success', // Default to success as per provided data\n startTime: raw.StartTime,\n endTime: raw.EndTime,\n duration: raw.Duration,\n children: [],\n metadata: {\n parentSpanId: raw.ParentSpanId,\n input: raw.Input,\n output: raw.Output,\n spanKind: raw.SpanKind,\n model: raw.Model,\n tags: raw.Tags,\n tokens: {\n input: raw.InputTokens,\n output: raw.OutputTokens,\n total: raw.TotalTokens,\n },\n },\n };\n};\n\n// Function to build the tree\nconst buildTraceTree = (spans: RawSpan[]): TraceSpan[] => {\n // Convert all raw spans to TraceSpan objects first\n const traceSpans = spans.map(convertToTraceSpan);\n const spanMap = new Map<string, TraceSpan>();\n const roots: TraceSpan[] = [];\n\n // Index by ID\n traceSpans.forEach(span => spanMap.set(span.id, span));\n\n // Build relationships\n traceSpans.forEach(span => {\n const parentSpanId = span.metadata?.parentSpanId;\n if (parentSpanId && spanMap.has(parentSpanId)) {\n const parent = spanMap.get(parentSpanId)!;\n parent.children = parent.children || [];\n parent.children.push(span);\n } else {\n roots.push(span);\n }\n });\n\n return roots;\n};\n\n// Helper to flatten the tree\nconst flattenTree = (spans: TraceSpan[], level: number = 0): TraceNode[] => {\n const tree = spans.flatMap(span => [\n { span, level },\n ...(span.children ? flattenTree(span.children, level + 1) : []),\n ]);\n return tree;\n};\n\nexport interface EventData {\n flatTree: TraceNode[];\n trace: TraceSpan[] | null;\n}\n\ninterface TraceState {\n selectedSpan: TraceSpan | null;\n setSelectedSpan: (span: TraceSpan | null) => void;\n\n // Cache events by sessionId\n events: Record<string, EventData>;\n isLoading: boolean;\n fetchEvents: (sessionId: string) => Promise<void>;\n}\n\nexport const useTraceStore = create<TraceState>((set, get) => ({\n selectedSpan: null,\n setSelectedSpan: (span) => set({ selectedSpan: span }),\n\n events: {},\n isLoading: false,\n\n fetchEvents: async (sessionId: string) => {\n if (!sessionId) return;\n\n // Always set loading to true when fetching starts\n set({ isLoading: true });\n\n try {\n const now = dayjs();\n const res = await FetchInstance.request<{ data: { Spans: RawSpan[] } }>({\n action: 'GetSessionSpans',\n params: {\n SessionId: sessionId || '',\n StartTime: dayjs().subtract(1, 'd').valueOf(),\n EndTime: now.valueOf(),\n },\n type: 'open-top',\n method: 'POST',\n });\n\n const [err, data] = res;\n if (err) {\n throw err;\n }\n\n const spans: RawSpan[] = data?.data?.Spans || [];\n\n // Build Trace Tree\n const traceTree = buildTraceTree(spans);\n const trace = traceTree.length > 0 ? traceTree : null;\n const flatTree = traceTree.length > 0 ? flattenTree(traceTree) : [];\n\n set((state) => ({\n events: {\n ...state.events,\n [sessionId]: {\n trace,\n flatTree,\n },\n },\n isLoading: false,\n }));\n } catch (error) {\n console.error('Failed to fetch trace events:', error);\n set({ isLoading: false });\n }\n },\n}));\n"],"names":["IaasFetch","create","dayjs"],"mappings":";;;;;;AAKA,MAAM,aAAa,GAAG,IAAIA,eAAS,CAAC;AAClC,IAAA,OAAO,EAAE,gBAAgB;AACzB,IAAA,OAAO,EAAE,YAAY;AACrB,IAAA,QAAQ,EAAE,YAAY;AACtB,IAAA,aAAa,EAAE,IAAI;AACpB,CAAA,CAAC,CAAC;AAoBH;AACA,MAAM,kBAAkB,GAAG,CAAC,GAAY,KAAe;IACrD,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,MAAM;QACd,IAAI,EAAE,GAAG,CAAC,aAAa;QACvB,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,QAAQ,EAAE,GAAG,CAAC,QAAQ;AACtB,QAAA,QAAQ,EAAE,EAAE;AACZ,QAAA,QAAQ,EAAE;YACR,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;YACtB,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB,IAAI,EAAE,GAAG,CAAC,IAAI;AACd,YAAA,MAAM,EAAE;gBACN,KAAK,EAAE,GAAG,CAAC,WAAW;gBACtB,MAAM,EAAE,GAAG,CAAC,YAAY;gBACxB,KAAK,EAAE,GAAG,CAAC,WAAW;AACvB,aAAA;AACF,SAAA;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;AACA,MAAM,cAAc,GAAG,CAAC,KAAgB,KAAiB;;IAEvD,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;AACjD,IAAA,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC7C,M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EtD,IAAA,MAAM,EAAE,EAAE;AACV,IAAA,SAAS,EAAE,KAAK;AAEhB,IAAA,WAAW,EAAE,OAAO,SAAiB,KAAI;AACvC,QAAA,IAAI,CAAC,SAAS;YAAE,OAAO;;AAGvB,QAAA,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAEzB,QAAA,IAAI;AACF,YAAA,MAAM,GAAG,GAAGC,
|
|
1
|
+
{"version":3,"file":"store.cjs","sources":["../../../../../src/adk/components/Debug/Trace/store.ts"],"sourcesContent":["import { create } from 'zustand';\nimport { TraceSpan, TraceNode } from './types';\nimport dayjs from 'dayjs';\nimport IaasFetch from '@byted-iaas/fetch';\n\nconst FetchInstance = new IaasFetch({\n service: 'apmplus_server',\n version: '2024-07-30',\n platform: 'VOLCENGINE',\n disablePreTcc: true,\n});\n\ninterface RawSpan {\n OperationName: string;\n SpanId: string;\n TraceId: string;\n Input: string;\n Output: string;\n SpanKind: string;\n Model: string;\n InputTokens: number;\n OutputTokens: number;\n TotalTokens: number;\n Duration: number;\n StartTime: number;\n EndTime: number;\n ParentSpanId?: string;\n Tags?: Record<string, any>;\n}\n\n// Helper function to convert RawSpan to TraceSpan\nconst convertToTraceSpan = (raw: RawSpan): TraceSpan => {\n return {\n id: raw.SpanId,\n name: raw.OperationName,\n status: 'success', // Default to success as per provided data\n startTime: raw.StartTime,\n endTime: raw.EndTime,\n duration: raw.Duration,\n children: [],\n metadata: {\n parentSpanId: raw.ParentSpanId,\n input: raw.Input,\n output: raw.Output,\n spanKind: raw.SpanKind,\n model: raw.Model,\n tags: raw.Tags,\n tokens: {\n input: raw.InputTokens,\n output: raw.OutputTokens,\n total: raw.TotalTokens,\n },\n },\n };\n};\n\n// Function to build the tree\nconst buildTraceTree = (spans: RawSpan[]): TraceSpan[] => {\n // Convert all raw spans to TraceSpan objects first\n const traceSpans = spans.map(convertToTraceSpan);\n const spanMap = new Map<string, TraceSpan>();\n const roots: TraceSpan[] = [];\n\n // Index by ID\n traceSpans.forEach(span => spanMap.set(span.id, span));\n\n // Build relationships\n traceSpans.forEach(span => {\n const parentSpanId = span.metadata?.parentSpanId;\n if (parentSpanId && spanMap.has(parentSpanId)) {\n const parent = spanMap.get(parentSpanId)!;\n parent.children = parent.children || [];\n parent.children.push(span);\n } else {\n roots.push(span);\n }\n });\n\n return roots;\n};\n\n// Helper to flatten the tree\nconst flattenTree = (spans: TraceSpan[], level: number = 0): TraceNode[] => {\n const tree = spans.flatMap(span => [\n { span, level },\n ...(span.children ? flattenTree(span.children, level + 1) : []),\n ]);\n return tree;\n};\n\nexport interface EventData {\n flatTree: TraceNode[];\n trace: TraceSpan[] | null;\n}\n\ninterface TraceState {\n selectedSpan: TraceSpan | null;\n setSelectedSpan: (span: TraceSpan | null) => void;\n\n // Cache events by sessionId\n events: Record<string, EventData>;\n isLoading: boolean;\n fetchEvents: (sessionId: string) => Promise<void>;\n}\n\nexport const useTraceStore = create<TraceState>((set, get) => ({\n selectedSpan: null,\n setSelectedSpan: (span) => set({ selectedSpan: span }),\n\n events: {},\n isLoading: false,\n\n fetchEvents: async (sessionId: string) => {\n if (!sessionId) return;\n\n // Always set loading to true when fetching starts\n set({ isLoading: true });\n\n try {\n const now = dayjs();\n const res = await FetchInstance.request<{ data: { Spans: RawSpan[] } }>({\n action: 'GetSessionSpans',\n params: {\n SessionId: sessionId || '',\n StartTime: dayjs().subtract(1, 'd').valueOf(),\n EndTime: now.valueOf(),\n },\n type: 'open-top',\n method: 'POST',\n });\n\n const [err, data] = res;\n if (err) {\n throw err;\n }\n\n const spans: RawSpan[] = data?.data?.Spans || [];\n\n // Build Trace Tree\n const traceTree = buildTraceTree(spans);\n const trace = traceTree.length > 0 ? traceTree : null;\n const flatTree = traceTree.length > 0 ? flattenTree(traceTree) : [];\n\n set((state) => ({\n events: {\n ...state.events,\n [sessionId]: {\n trace,\n flatTree,\n },\n },\n isLoading: false,\n }));\n } catch (error) {\n console.error('Failed to fetch trace events:', error);\n set({ isLoading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;AACF,iBAAA;AACD,gBAAA,SAAS,EAAE,KAAK;AACjB,aAAA,CAAC,CAAC,CAAC;SACL;QAAC,OAAO,KAAK,EAAE;AACd,YAAA,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;AACtD,YAAA,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;SAC3B;KACF;AACF,CAAA,CAAC;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dayjs from '../../../../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.js';
|
|
2
|
-
import { IaasFetch } from '../../../../node_modules/@byted-iaas/fetch/lib/fetch.js';
|
|
2
|
+
import { IaasFetch } from '../../../../node_modules/.pnpm/@byted-iaas_fetch@0.0.13_@arco-design_web-react@2.64.1_@types_react@17.0.2_react-dom@17.0.2_r_c5lheq6mbvfvtoizhtvrll35su/node_modules/@byted-iaas/fetch/lib/fetch.js';
|
|
3
3
|
import { create } from '../../../../node_modules/.pnpm/zustand@5.0.8_patch_hash_rz6xqpd4m4x2bh7isifaksfeb4_@types_react@17.0.2_react@17.0.2_use-sync_ay3nj3f4buvymz7rhhedugq5p4/node_modules/zustand/esm/react.js';
|
|
4
4
|
|
|
5
5
|
const FetchInstance = new IaasFetch({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var dayjs_min = require('../../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.cjs');
|
|
4
|
-
var useRequest = require('../../node_modules/ahooks/es/useRequest/src/useRequest.cjs');
|
|
5
|
-
var fetch = require('../../node_modules/@byted-iaas/fetch/lib/fetch.cjs');
|
|
4
|
+
var useRequest = require('../../node_modules/.pnpm/ahooks@3.9.6_react-dom@17.0.2_react@17.0.2__react@17.0.2/node_modules/ahooks/es/useRequest/src/useRequest.cjs');
|
|
5
|
+
var fetch = require('../../node_modules/.pnpm/@byted-iaas_fetch@0.0.13_@arco-design_web-react@2.64.1_@types_react@17.0.2_react-dom@17.0.2_r_c5lheq6mbvfvtoizhtvrll35su/node_modules/@byted-iaas/fetch/lib/fetch.cjs');
|
|
6
6
|
require('../../packages/core/dist/index.cjs');
|
|
7
7
|
var react = require('../../node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/react.cjs');
|
|
8
8
|
|
|
@@ -76,7 +76,7 @@ const useEvent = (sessionId, region, controller) => {
|
|
|
76
76
|
const { currentThreadId, threadMap } = react.useSnapshot(controller.store.state);
|
|
77
77
|
const currentThread = currentThreadId ? threadMap?.[currentThreadId] : null;
|
|
78
78
|
const { data, refresh, loading } = useRequest(async () => {
|
|
79
|
-
const now = dayjs_min();
|
|
79
|
+
const now = dayjs_min.default();
|
|
80
80
|
const res = await FetchInstance.request({
|
|
81
81
|
action: 'GetSessionSpans',
|
|
82
82
|
errorDisplay: 'none',
|
|
@@ -86,7 +86,7 @@ const useEvent = (sessionId, region, controller) => {
|
|
|
86
86
|
region: region,
|
|
87
87
|
params: {
|
|
88
88
|
SessionId: sessionId || '',
|
|
89
|
-
StartTime: dayjs_min().subtract(1, 'd').valueOf(),
|
|
89
|
+
StartTime: dayjs_min.default().subtract(1, 'd').valueOf(),
|
|
90
90
|
EndTime: now.valueOf(),
|
|
91
91
|
},
|
|
92
92
|
type: 'open-top',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEvents.cjs","sources":["../../../src/adk/hooks/useEvents.ts"],"sourcesContent":["import dayjs from 'dayjs';\nimport { useRequest } from 'ahooks';\nimport IaasFetch from '@byted-iaas/fetch';\nimport { TraceSpan, TraceNode } from '../components/Debug/Trace/types';\nimport useThread from '@/hooks/useThread';\nimport { ChatController, useSnapshot } from '@chat-lab/core';\n\nconst FetchInstance = new IaasFetch({\n service: 'apmplus_server',\n version: '2024-07-30',\n platform: 'VOLCENGINE',\n disablePreTcc: true,\n});\n\ninterface RawSpan {\n OperationName: string;\n SpanId: string;\n TraceId: string;\n Input: string;\n Output: string;\n SpanKind: string;\n Model: string;\n InputTokens: number;\n OutputTokens: number;\n TotalTokens: number;\n Duration: number;\n StartTime: number;\n Tags?: Record<string, string>;\n EndTime: number;\n ParentSpanId?: string;\n}\n\n// Helper function to convert RawSpan to TraceSpan\nconst convertToTraceSpan = (raw: RawSpan): TraceSpan => {\n const statusCode = raw?.Tags?.['http.status_code'];\n let status: 'success' | 'error' = 'success';\n if (statusCode && statusCode !== '200') {\n status = 'error';\n }\n return {\n id: raw.SpanId,\n name: raw.OperationName,\n status: status, // Default to success as per provided data\n startTime: raw.StartTime,\n endTime: raw.EndTime,\n duration: raw.Duration,\n tags: raw.Tags || {},\n children: [],\n metadata: {\n parentSpanId: raw.ParentSpanId,\n input: raw.Input,\n output: raw.Output,\n spanKind: raw.SpanKind,\n model: raw.Model,\n tokens: {\n input: raw.InputTokens,\n output: raw.OutputTokens,\n total: raw.TotalTokens,\n },\n },\n };\n};\n\n// Function to build the tree\nconst buildTraceTree = (spans: RawSpan[]): TraceSpan[] => {\n // Convert all raw spans to TraceSpan objects first\n const traceSpans = spans.map(convertToTraceSpan);\n const spanMap = new Map<string, TraceSpan>();\n const roots: TraceSpan[] = [];\n\n // Index by ID\n traceSpans.forEach(span => spanMap.set(span.id, span));\n\n // Build relationships\n traceSpans.forEach(span => {\n const parentSpanId = span.metadata?.parentSpanId as string;\n if (parentSpanId && spanMap.has(parentSpanId)) {\n const parent = spanMap.get(parentSpanId)!;\n parent.children = parent.children || [];\n parent.children.push(span);\n } else {\n roots.push(span);\n }\n });\n\n return roots;\n};\n\n// Helper to flatten the tree\nconst flattenTree = (spans: TraceSpan[], level: number = 0): TraceNode[] => {\n const tree = spans.flatMap(span => [\n { span, level },\n ...(span.children ? flattenTree(span.children, level + 1) : []),\n ]);\n return tree;\n};\n\nexport const useEvent = (\n sessionId: string | null,\n region: string,\n controller: ChatController,\n) => {\n const { currentThreadId, threadMap } = useSnapshot(controller.store.state);\n const currentThread = currentThreadId ? threadMap?.[currentThreadId] : null;\n const { data, refresh, loading } = useRequest(\n async () => {\n const now = dayjs();\n const res = await FetchInstance.request<{ data: { Spans: RawSpan[] } }>({\n action: 'GetSessionSpans',\n errorDisplay: 'none',\n headers: {\n 'x-apmplus-region': region,\n },\n region: region,\n params: {\n SessionId: sessionId || '',\n StartTime: dayjs().subtract(1, 'd').valueOf(),\n EndTime: now.valueOf(),\n },\n type: 'open-top',\n method: 'POST',\n });\n const [err, data] = res;\n if (err) {\n throw err as any;\n }\n\n const spans: RawSpan[] = data?.data?.Spans || [];\n\n // Build Trace Tree\n const traceTree = buildTraceTree(spans);\n const trace = traceTree.length > 0 ? traceTree : null;\n const flatTree = traceTree.length > 0 ? flattenTree(traceTree) : [];\n\n return {\n traceTree,\n flatTree,\n trace,\n };\n },\n {\n ready: !!sessionId && (currentThread?.messages?.length||0) > 0,\n refreshDeps: [sessionId],\n pollingInterval: 2000,\n },\n );\n\n return {\n data,\n loading,\n refresh,\n };\n};\n"],"names":["IaasFetch","useSnapshot","dayjs"],"mappings":";;;;;;;;AAOA,MAAM,aAAa,GAAG,IAAIA,eAAS,CAAC;AAClC,IAAA,OAAO,EAAE,gBAAgB;AACzB,IAAA,OAAO,EAAE,YAAY;AACrB,IAAA,QAAQ,EAAE,YAAY;AACtB,IAAA,aAAa,EAAE,IAAI;AACpB,CAAA,CAAC,CAAC;AAoBH;AACA,MAAM,kBAAkB,GAAG,CAAC,GAAY,KAAe;IACrD,MAAM,UAAU,GAAG,GAAG,EAAE,IAAI,GAAG,kBAAkB,CAAC,CAAC;IACnD,IAAI,MAAM,GAAwB,SAAS,CAAC;AAC5C,IAAA,IAAI,UAAU,IAAI,UAAU,KAAK,KAAK,EAAE;QACtC,MAAM,GAAG,OAAO,CAAC;KAClB;IACD,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,MAAM;QACd,IAAI,EAAE,GAAG,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AC,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC;AACxC,YAAA,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC5B;aAAM;AACL,YAAA,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAClB;AACH,KAAC,CAAC,CAAC;AAEH,IAAA,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF;AACA,MAAM,WAAW,GAAG,CAAC,KAAkB,EAAE,KAAgB,GAAA,CAAC,KAAiB;IACzE,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI;QACjC,EAAE,IAAI,EAAE,KAAK,EAAE;QACf,IAAI,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;AAChE,KAAA,CAAC,CAAC;AACH,IAAA,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEW,MAAA,QAAQ,GAAG,CACtB,SAAwB,EACxB,MAAc,EACd,UAA0B,KACxB;AACF,IAAA,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,GAAGC,iBAAW,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC3E,IAAA,MAAM,aAAa,GAAG,eAAe,GAAG,SAAS,GAAG,eAAe,CAAC,GAAG,IAAI,CAAC;AAC5E,IAAA,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,UAAU,CAC3C,YAAW;AACT,QAAA,MAAM,GAAG,GAAGC,
|
|
1
|
+
{"version":3,"file":"useEvents.cjs","sources":["../../../src/adk/hooks/useEvents.ts"],"sourcesContent":["import dayjs from 'dayjs';\nimport { useRequest } from 'ahooks';\nimport IaasFetch from '@byted-iaas/fetch';\nimport { TraceSpan, TraceNode } from '../components/Debug/Trace/types';\nimport useThread from '@/hooks/useThread';\nimport { ChatController, useSnapshot } from '@chat-lab/core';\n\nconst FetchInstance = new IaasFetch({\n service: 'apmplus_server',\n version: '2024-07-30',\n platform: 'VOLCENGINE',\n disablePreTcc: true,\n});\n\ninterface RawSpan {\n OperationName: string;\n SpanId: string;\n TraceId: string;\n Input: string;\n Output: string;\n SpanKind: string;\n Model: string;\n InputTokens: number;\n OutputTokens: number;\n TotalTokens: number;\n Duration: number;\n StartTime: number;\n Tags?: Record<string, string>;\n EndTime: number;\n ParentSpanId?: string;\n}\n\n// Helper function to convert RawSpan to TraceSpan\nconst convertToTraceSpan = (raw: RawSpan): TraceSpan => {\n const statusCode = raw?.Tags?.['http.status_code'];\n let status: 'success' | 'error' = 'success';\n if (statusCode && statusCode !== '200') {\n status = 'error';\n }\n return {\n id: raw.SpanId,\n name: raw.OperationName,\n status: status, // Default to success as per provided data\n startTime: raw.StartTime,\n endTime: raw.EndTime,\n duration: raw.Duration,\n tags: raw.Tags || {},\n children: [],\n metadata: {\n parentSpanId: raw.ParentSpanId,\n input: raw.Input,\n output: raw.Output,\n spanKind: raw.SpanKind,\n model: raw.Model,\n tokens: {\n input: raw.InputTokens,\n output: raw.OutputTokens,\n total: raw.TotalTokens,\n },\n },\n };\n};\n\n// Function to build the tree\nconst buildTraceTree = (spans: RawSpan[]): TraceSpan[] => {\n // Convert all raw spans to TraceSpan objects first\n const traceSpans = spans.map(convertToTraceSpan);\n const spanMap = new Map<string, TraceSpan>();\n const roots: TraceSpan[] = [];\n\n // Index by ID\n traceSpans.forEach(span => spanMap.set(span.id, span));\n\n // Build relationships\n traceSpans.forEach(span => {\n const parentSpanId = span.metadata?.parentSpanId as string;\n if (parentSpanId && spanMap.has(parentSpanId)) {\n const parent = spanMap.get(parentSpanId)!;\n parent.children = parent.children || [];\n parent.children.push(span);\n } else {\n roots.push(span);\n }\n });\n\n return roots;\n};\n\n// Helper to flatten the tree\nconst flattenTree = (spans: TraceSpan[], level: number = 0): TraceNode[] => {\n const tree = spans.flatMap(span => [\n { span, level },\n ...(span.children ? flattenTree(span.children, level + 1) : []),\n ]);\n return tree;\n};\n\nexport const useEvent = (\n sessionId: string | null,\n region: string,\n controller: ChatController,\n) => {\n const { currentThreadId, threadMap } = useSnapshot(controller.store.state);\n const currentThread = currentThreadId ? threadMap?.[currentThreadId] : null;\n const { data, refresh, loading } = useRequest(\n async () => {\n const now = dayjs();\n const res = await FetchInstance.request<{ data: { Spans: RawSpan[] } }>({\n action: 'GetSessionSpans',\n errorDisplay: 'none',\n headers: {\n 'x-apmplus-region': region,\n },\n region: region,\n params: {\n SessionId: sessionId || '',\n StartTime: dayjs().subtract(1, 'd').valueOf(),\n EndTime: now.valueOf(),\n },\n type: 'open-top',\n method: 'POST',\n });\n const [err, data] = res;\n if (err) {\n throw err as any;\n }\n\n const spans: RawSpan[] = data?.data?.Spans || [];\n\n // Build Trace Tree\n const traceTree = buildTraceTree(spans);\n const trace = traceTree.length > 0 ? traceTree : null;\n const flatTree = traceTree.length > 0 ? flattenTree(traceTree) : [];\n\n return {\n traceTree,\n flatTree,\n trace,\n };\n },\n {\n ready: !!sessionId && (currentThread?.messages?.length||0) > 0,\n refreshDeps: [sessionId],\n pollingInterval: 2000,\n },\n );\n\n return {\n data,\n loading,\n refresh,\n };\n};\n"],"names":["IaasFetch","useSnapshot","dayjs"],"mappings":";;;;;;;;AAOA,MAAM,aAAa,GAAG,IAAIA,eAAS,CAAC;AAClC,IAAA,OAAO,EAAE,gBAAgB;AACzB,IAAA,OAAO,EAAE,YAAY;AACrB,IAAA,QAAQ,EAAE,YAAY;AACtB,IAAA,aAAa,EAAE,IAAI;AACpB,CAAA,CAAC,CAAC;AAoBH;AACA,MAAM,kBAAkB,GAAG,CAAC,GAAY,KAAe;IACrD,MAAM,UAAU,GAAG,GAAG,EAAE,IAAI,GAAG,kBAAkB,CAAC,CAAC;IACnD,IAAI,MAAM,GAAwB,SAAS,CAAC;AAC5C,IAAA,IAAI,UAAU,IAAI,UAAU,KAAK,KAAK,EAAE;QACtC,MAAM,GAAG,OAAO,CA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import dayjs from '../../node_modules/.pnpm/dayjs@1.11.18/node_modules/dayjs/dayjs.min.js';
|
|
2
|
-
import useRequest from '../../node_modules/ahooks/es/useRequest/src/useRequest.js';
|
|
3
|
-
import { IaasFetch } from '../../node_modules/@byted-iaas/fetch/lib/fetch.js';
|
|
2
|
+
import useRequest from '../../node_modules/.pnpm/ahooks@3.9.6_react-dom@17.0.2_react@17.0.2__react@17.0.2/node_modules/ahooks/es/useRequest/src/useRequest.js';
|
|
3
|
+
import { IaasFetch } from '../../node_modules/.pnpm/@byted-iaas_fetch@0.0.13_@arco-design_web-react@2.64.1_@types_react@17.0.2_react-dom@17.0.2_r_c5lheq6mbvfvtoizhtvrll35su/node_modules/@byted-iaas/fetch/lib/fetch.js';
|
|
4
4
|
import '../../packages/core/dist/index.js';
|
|
5
5
|
import { useSnapshot } from '../../node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/react.js';
|
|
6
6
|
|
|
@@ -15,7 +15,6 @@ var checkMedia = require('../../utils/checkMedia.cjs');
|
|
|
15
15
|
var TraceDetail = require('../../adk/components/Debug/Trace/TraceDetail.cjs');
|
|
16
16
|
var store = require('../../adk/components/Debug/Trace/store.cjs');
|
|
17
17
|
var index$1 = require('../../adk/components/Debug/index.cjs');
|
|
18
|
-
var cloneDeep = require('../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/cloneDeep.cjs');
|
|
19
18
|
var useExternalStoreRuntime = require('../../node_modules/.pnpm/@assistant-ui_react@0.11.37_patch_hash_wncib234fzw2z5h67nrdhchb2a_@types_react-dom@17.0.2_@ty_c64hu5rigivj2gtpzfqjqatr5y/node_modules/@assistant-ui/react/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.cjs');
|
|
20
19
|
var compact = require('../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/compact.cjs');
|
|
21
20
|
var v4 = require('../../node_modules/.pnpm/uuid@13.0.0/node_modules/uuid/dist/v4.cjs');
|
|
@@ -24,12 +23,12 @@ var values = require('../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lo
|
|
|
24
23
|
var react = require('../../node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/react.cjs');
|
|
25
24
|
|
|
26
25
|
const ChatkitImpl = React.forwardRef((props, ref) => {
|
|
27
|
-
const { initialConfig, tools, toolDisplay = 'group', welcome, recommends, plugins, threadList: threadList$1, showHeader = true, placeholder, expandToolGroup = false, expandReasoning = false, expandToolDetail = false,
|
|
26
|
+
const { initialConfig, tools, toolDisplay = 'group', welcome, recommends, plugins, threadList: threadList$1, showHeader = true, placeholder, expandToolGroup = false, expandReasoning = false, expandToolDetail = false, threadBottom, } = props;
|
|
28
27
|
const controller = props.controller;
|
|
29
28
|
const { threadMap, currentThreadId } = react.useSnapshot(controller.store.state);
|
|
30
29
|
// useImperativeHandleChatkitRef(ref, controller, onError);
|
|
31
30
|
const currentThread = currentThreadId ? threadMap[currentThreadId] : null;
|
|
32
|
-
const messages = React.useMemo(() =>
|
|
31
|
+
const messages = React.useMemo(() => threadMap[currentThread?.id || '']?.messages || [] || [], [currentThread?.id, threadMap]);
|
|
33
32
|
const uiMessages = React.useMemo(() => convertToAssistantMessage(messages, {
|
|
34
33
|
toolDisplay: toolDisplay || 'group',
|
|
35
34
|
}), [messages]);
|
|
@@ -137,17 +136,17 @@ const ChatkitImpl = React.forwardRef((props, ref) => {
|
|
|
137
136
|
controller,
|
|
138
137
|
}, children: jsxRuntime.jsxs("div", { className: "flex h-full w-full", children: [threadList$1 !== false &&
|
|
139
138
|
(typeof threadList$1 === 'function' ? (threadList$1({
|
|
140
|
-
threadList:
|
|
141
|
-
})) : (jsxRuntime.jsx(threadList, {}))), jsxRuntime.jsx("div", { className: "flex-1 h-full w-[calc(100%-200px)]", children: jsxRuntime.jsxs(reactResizablePanels.Group, { orientation: "vertical", style: { height: '100%', width: '100%' }, children: [jsxRuntime.jsx(reactResizablePanels.Panel, { children: jsxRuntime.jsx(thread.Thread, { welcome: welcome, recommends: recommends }) }), selectedSpan && (jsxRuntime.jsx(reactResizablePanels.Panel, { defaultSize: '30%', children: jsxRuntime.jsx(TraceDetail, { selectedSpan: selectedSpan || undefined, onCancel: () => setSelectedSpan(null) }) }))] }) })] }) }), (tools || []).map((tool, index) => tool)] }, currentThreadId));
|
|
139
|
+
threadList: values(threadMap),
|
|
140
|
+
})) : (jsxRuntime.jsx(threadList, {}))), jsxRuntime.jsx("div", { className: "flex-1 h-full w-[calc(100%-200px)]", children: jsxRuntime.jsxs(reactResizablePanels.Group, { orientation: "vertical", style: { height: '100%', width: '100%' }, children: [jsxRuntime.jsx(reactResizablePanels.Panel, { children: jsxRuntime.jsx(thread.Thread, { welcome: welcome, recommends: recommends }) }), selectedSpan && (jsxRuntime.jsx(reactResizablePanels.Panel, { defaultSize: '30%', children: jsxRuntime.jsx(TraceDetail, { selectedSpan: selectedSpan || undefined, onCancel: () => setSelectedSpan(null) }) })), threadBottom] }) })] }) }), (tools || []).map((tool, index) => tool)] }, currentThreadId));
|
|
142
141
|
});
|
|
143
|
-
const Chatkit = (props
|
|
144
|
-
const { initialConfig, welcome, recommends, onError, toolDisplay, plugins, chatController: chatControllerFromProps = null, chatControllerPlugins, threadList, showHeader = true, placeholder, expandToolGroup, expandToolDetail, region, } = props;
|
|
142
|
+
const Chatkit = (props) => {
|
|
143
|
+
const { initialConfig, welcome, recommends, onError, toolDisplay, plugins, chatController: chatControllerFromProps = null, threadBottom, chatControllerPlugins, threadList, showHeader = true, placeholder, expandToolGroup, expandToolDetail, region, } = props;
|
|
145
144
|
const controllerRef = React.useRef(chatControllerFromProps);
|
|
146
145
|
const controller = controllerRef.current;
|
|
147
146
|
const { currentThreadId, threadMap } = react.useSnapshot(controller.store.state);
|
|
148
147
|
const currentThread = currentThreadId ? threadMap[currentThreadId] : null;
|
|
149
|
-
const messages = React.useMemo(() =>
|
|
150
|
-
return (jsxRuntime.jsx("div", { className: 'chatkit-wrapper', style: { height: '100%' }, "data-chatkit": true, children: jsxRuntime.jsxs(reactResizablePanels.Group, { style: { height: '100%' }, children: [jsxRuntime.jsx(reactResizablePanels.Panel, { minSize: 750, maxSize: 900, children: jsxRuntime.jsx(ChatkitImpl, { tools: [jsxRuntime.jsx(toaster.Toaster, {}), jsxRuntime.jsx(executionCard, {})], showHeader: showHeader, recommends: recommends, initialConfig: initialConfig, expandToolGroup: expandToolGroup, expandToolDetail: expandToolDetail, placeholder: placeholder, welcome: welcome, plugins: plugins, threadList: threadList, controller: controller }, currentThreadId) }), region && (jsxRuntime.jsx(reactResizablePanels.Panel, { defaultSize: '25%', className: "border-l", children: jsxRuntime.jsx(index$1, { region: region, controller: controller, messages: (messages.filter(msg => msg.role !== 'user') || []) }) }))] }) }));
|
|
148
|
+
const messages = React.useMemo(() => threadMap[currentThread?.id || '']?.messages || [], [currentThread?.id, threadMap]);
|
|
149
|
+
return (jsxRuntime.jsx("div", { className: 'chatkit-wrapper', style: { height: '100%' }, "data-chatkit": true, children: jsxRuntime.jsxs(reactResizablePanels.Group, { style: { height: '100%' }, children: [jsxRuntime.jsx(reactResizablePanels.Panel, { minSize: 750, maxSize: 900, children: jsxRuntime.jsx(ChatkitImpl, { tools: [jsxRuntime.jsx(toaster.Toaster, {}), jsxRuntime.jsx(executionCard, {})], showHeader: showHeader, recommends: recommends, initialConfig: initialConfig, expandToolGroup: expandToolGroup, expandToolDetail: expandToolDetail, placeholder: placeholder, welcome: welcome, plugins: plugins, threadList: threadList, threadBottom: threadBottom, controller: controller }, currentThreadId) }), region && (jsxRuntime.jsx(reactResizablePanels.Panel, { defaultSize: '25%', className: "border-l", children: jsxRuntime.jsx(index$1, { region: region, controller: controller, messages: (messages.filter(msg => msg.role !== 'user') || []) }) }))] }) }));
|
|
151
150
|
};
|
|
152
151
|
var index = React.forwardRef(Chatkit);
|
|
153
152
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/components/Chatkit/index.tsx"],"sourcesContent":["import {\n ForwardedRef,\n forwardRef,\n MutableRefObject,\n Ref,\n useMemo,\n useRef,\n useEffect,\n useState,\n} from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { ChatkitProps, ChatkitRef } from './types';\nimport { cloneDeep, compact, findLastIndex, isString, values } from 'lodash-es';\nimport { ChatkitProvider } from '@/contexts/ChatkitContext';\n\nimport { Thread } from '../assistant-ui/thread';\nimport {\n AssistantRuntimeProvider,\n useExternalStoreRuntime,\n} from '@assistant-ui/react';\nimport { ChatMessage, ChatController } from '@chat-lab/core';\nimport { Group, Panel } from 'react-resizable-panels';\nimport convertToAssistantMessage from '@/utils/convertToAssistantMessage';\nimport ThreadList from '../thread-list';\nimport { Thread as ThreadType, useSnapshot } from '@chat-lab/core';\nimport { Toaster } from '../ui/toaster';\nimport { toast } from '@/hooks/use-toast';\nimport ExecutionCard from '../assistant-ui-tools/execution-card';\nimport { convertToBase64 } from '@/utils/convertToBase64';\nimport checkMedia from '@/utils/checkMedia';\nimport { TextMessage } from '@chat-lab/core';\nimport './style.less';\nimport TraceDetail from '@/adk/components/Debug/Trace/TraceDetail';\nimport { useTraceStore } from '@/adk/components/Debug/Trace/store';\nimport Debug from '@/adk/components/Debug';\nconst ChatkitImpl = forwardRef(\n (\n props: {\n initialConfig: ChatkitProps['initialConfig'];\n welcome?: React.ReactNode;\n recommends?: string[];\n plugins?: React.ReactNode[];\n tools?: React.ReactNode[];\n placeholder?: string;\n threadList?:\n | React.ReactNode\n | boolean\n | ((props: { threadList: Readonly<ThreadType>[] }) => React.ReactNode);\n showHeader?: boolean;\n expandToolGroup?: boolean;\n expandToolDetail?: boolean;\n toolDisplay?: 'group' | 'none' | 'step';\n expandReasoning?: boolean;\n controller: ChatController;\n region?: string;\n },\n ref: ForwardedRef<ChatkitRef>,\n ) => {\n const {\n initialConfig,\n tools,\n toolDisplay = 'group',\n welcome,\n recommends,\n plugins,\n threadList,\n showHeader = true,\n placeholder,\n expandToolGroup = false,\n expandReasoning = false,\n expandToolDetail = false,\n region,\n } = props;\n const controller = props.controller;\n const { threadMap, currentThreadId } = useSnapshot(controller.store.state);\n // useImperativeHandleChatkitRef(ref, controller, onError);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n const messages = useMemo(\n () => cloneDeep(threadMap[currentThread?.id || '']?.messages || []) || [],\n [currentThread?.id, threadMap],\n );\n\n const uiMessages = useMemo(\n () =>\n convertToAssistantMessage(messages as Readonly<ChatMessage>[], {\n toolDisplay: toolDisplay || 'group',\n }),\n [messages],\n );\n\n const runtime = useExternalStoreRuntime({\n messages: uiMessages,\n isLoading: currentThread?.sending,\n isDisabled: !!currentThread?.metadata['isInitingSession'],\n convertMessage: message => message,\n onNew: async message => {\n const attachments = await Promise.all(\n message.attachments?.map(async item => {\n return {\n ...item,\n base64: await convertToBase64(item.file as File),\n };\n }) || [],\n );\n\n controller?.sendMessage({\n attaches: attachments.map(item => ({\n id: item.id,\n attachId: item.id,\n url: item.base64,\n status: 'success',\n type: checkMedia(item.contentType),\n mimeType: item.contentType,\n })),\n content: compact([\n ...message.content.map(item => {\n if (item.type === 'text') {\n return {\n type: 'text',\n text: item.text,\n } as TextMessage;\n }\n }),\n ]),\n });\n },\n onReload: async (parentId, config) => {\n if (currentThread?.id && parentId)\n controller?.reloadMessage({\n threadId: currentThread?.id,\n messageId: parentId,\n });\n else {\n controller.onError?.(new Error('未找到对应的对话'));\n }\n },\n onCancel: async () => {\n controller?.abortMessage();\n },\n adapters: {\n attachments: {\n remove: async ({ id }) => {\n console.log(id);\n },\n send: async ({ id, file }) => {\n return {\n id,\n type: 'image',\n name: file.name,\n contentType: file.type,\n content: [\n {\n type: 'image',\n image: file.name,\n },\n ],\n status: {\n type: 'complete',\n },\n file,\n };\n },\n accept: 'image/*',\n add: async ({ file }) => {\n return {\n file,\n id: uuid(),\n type: 'image',\n name: file.name,\n contentType: file.type,\n status: {\n type: 'running',\n reason: 'uploading',\n progress: 0,\n },\n };\n },\n },\n },\n });\n\n const selectedSpan = useTraceStore(state => state.selectedSpan);\n const setSelectedSpan = useTraceStore(state => state.setSelectedSpan);\n useEffect(() => () => setSelectedSpan(null), [setSelectedSpan]);\n // const events = useEvent(currentThreadId);\n // useEvent(currentThreadId);\n return (\n <AssistantRuntimeProvider key={currentThreadId} runtime={runtime}>\n <Toaster />\n <ExecutionCard />\n <ChatkitProvider\n value={{\n ref: ref as MutableRefObject<ChatkitRef | null>,\n plugins: plugins || [],\n showThreadList: threadList !== false,\n placeholder: placeholder || '请输入内容',\n showHeader,\n expandToolGroup,\n expandToolDetail,\n expandReasoning,\n controller,\n }}\n >\n <div className=\"flex h-full w-full\">\n {threadList !== false &&\n (typeof threadList === 'function' ? (\n threadList({\n threadList: cloneDeep(values(threadMap)) as ThreadType[],\n })\n ) : (\n <ThreadList />\n ))}\n <div className=\"flex-1 h-full w-[calc(100%-200px)]\">\n <Group\n orientation=\"vertical\"\n style={{ height: '100%', width: '100%' }}\n >\n <Panel>\n <Thread welcome={welcome} recommends={recommends} />\n </Panel>\n {selectedSpan && (\n <Panel defaultSize={'30%'}>\n <TraceDetail\n selectedSpan={selectedSpan || undefined}\n onCancel={() => setSelectedSpan(null)}\n />\n </Panel>\n )}\n </Group>\n </div>\n </div>\n </ChatkitProvider>\n {(tools || []).map((tool, index) => tool)}\n </AssistantRuntimeProvider>\n );\n },\n);\n\nconst Chatkit = (\n props: ChatkitProps,\n refFromProps: ForwardedRef<ChatkitRef>,\n) => {\n const {\n initialConfig,\n welcome,\n recommends,\n onError,\n toolDisplay,\n plugins,\n chatController: chatControllerFromProps = null,\n chatControllerPlugins,\n threadList,\n showHeader = true,\n placeholder,\n expandToolGroup,\n expandToolDetail,\n region,\n } = props;\n\n const controllerRef = useRef<ChatController | null>(chatControllerFromProps);\n\n const controller = controllerRef.current;\n\n const { currentThreadId, threadMap } = useSnapshot(controller!.store.state);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n\n const messages = useMemo(\n () => cloneDeep(threadMap[currentThread?.id || '']?.messages || []) || [],\n [currentThread?.id, threadMap],\n );\n return (\n <div className={'chatkit-wrapper'} style={{ height: '100%' }} data-chatkit>\n <Group style={{ height: '100%' }}>\n <Panel minSize={750} maxSize={900}>\n <ChatkitImpl\n key={currentThreadId}\n tools={[<Toaster />, <ExecutionCard />]}\n showHeader={showHeader}\n recommends={recommends}\n initialConfig={initialConfig}\n expandToolGroup={expandToolGroup}\n expandToolDetail={expandToolDetail}\n placeholder={placeholder}\n welcome={welcome}\n plugins={plugins}\n threadList={threadList}\n controller={controller!}\n />\n </Panel>\n {region && (\n <Panel defaultSize={'25%'} className=\"border-l\">\n <Debug\n region={region}\n controller={controller!}\n messages={\n (messages.filter(msg => msg.role !== 'user') || []) as any[]\n }\n />\n </Panel>\n )}\n </Group>\n </div>\n );\n};\n\nexport default forwardRef(Chatkit);\n"],"names":["forwardRef","threadList","useSnapshot","useMemo","useExternalStoreRuntime","convertToBase64","uuid","useTraceStore","useEffect","_jsxs","AssistantRuntimeProvider","_jsx","Toaster","ExecutionCard","ChatkitProvider","ThreadList","Group","Panel","Thread","useRef","Debug"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,WAAW,GAAGA,gBAAU,CAC5B,CACE,KAkBC,EACD,GAA6B,KAC3B;AACF,IAAA,MAAM,EACJ,aAAa,EACb,KAAK,EACL,WAAW,GAAG,OAAO,EACrB,OAAO,EACP,UAAU,EACV,OAAO,cACPC,YAAU,EACV,UAAU,GAAG,IAAI,EACjB,WAAW,EACX,eAAe,GAAG,KAAK,EACvB,eAAe,GAAG,KAAK,EACvB,gBAAgB,GAAG,KAAK,EACxB,MAAM,GACP,GAAG,KAAK,CAAC;AACV,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;AACpC,IAAA,MAAM,EAAE,SAAS,E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AE,UAAU,EACtB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,EAC5B,eAAe,EAAE,eAAe,EAChC,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,WAAW,EACxB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAW,EAAA,EAXlB,eAAe,CAYpB,EACI,CAAA,EACP,MAAM,KACLF,cAAC,CAAAM,0BAAK,EAAC,EAAA,WAAW,EAAE,KAAK,EAAE,SAAS,EAAC,UAAU,EAC7C,QAAA,EAAAN,cAAA,CAACS,OAAK,EAAA,EACJ,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAW,EACvB,QAAQ,GACL,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,EAAE,CAAU,GAE9D,EACI,CAAA,CACT,CACK,EAAA,CAAA,EAAA,CACJ,EACN;AACJ,CAAC,CAAC;AAEF,YAAepB,gBAAU,CAAC,OAAO,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/components/Chatkit/index.tsx"],"sourcesContent":["import {\n ForwardedRef,\n forwardRef,\n MutableRefObject,\n Ref,\n useMemo,\n useRef,\n useEffect,\n useState,\n} from 'react';\nimport { v4 as uuid } from 'uuid';\nimport { ChatkitProps, ChatkitRef } from './types';\nimport { compact, findLastIndex, isString, values } from 'lodash-es';\nimport { ChatkitProvider } from '@/contexts/ChatkitContext';\n\nimport { Thread } from '../assistant-ui/thread';\nimport {\n AssistantRuntimeProvider,\n useExternalStoreRuntime,\n} from '@assistant-ui/react';\nimport { ChatMessage, ChatController } from '@chat-lab/core';\nimport { Group, Panel } from 'react-resizable-panels';\nimport convertToAssistantMessage from '@/utils/convertToAssistantMessage';\nimport ThreadList from '../thread-list';\nimport { Thread as ThreadType, useSnapshot } from '@chat-lab/core';\nimport { Toaster } from '../ui/toaster';\nimport { toast } from '@/hooks/use-toast';\nimport ExecutionCard from '../assistant-ui-tools/execution-card';\nimport { convertToBase64 } from '@/utils/convertToBase64';\nimport checkMedia from '@/utils/checkMedia';\nimport { TextMessage } from '@chat-lab/core';\nimport './style.less';\nimport TraceDetail from '@/adk/components/Debug/Trace/TraceDetail';\nimport { useTraceStore } from '@/adk/components/Debug/Trace/store';\nimport Debug from '@/adk/components/Debug';\nconst ChatkitImpl = forwardRef(\n (\n props: {\n initialConfig: ChatkitProps['initialConfig'];\n welcome?: React.ReactNode;\n recommends?: string[];\n plugins?: React.ReactNode[];\n tools?: React.ReactNode[];\n placeholder?: string;\n threadList?:\n | React.ReactNode\n | boolean\n | ((props: { threadList: Readonly<ThreadType>[] }) => React.ReactNode);\n threadBottom?: React.ReactNode;\n showHeader?: boolean;\n expandToolGroup?: boolean;\n expandToolDetail?: boolean;\n toolDisplay?: 'group' | 'none' | 'step';\n expandReasoning?: boolean;\n controller: ChatController;\n },\n ref: ForwardedRef<ChatkitRef>,\n ) => {\n const {\n initialConfig,\n tools,\n toolDisplay = 'group',\n welcome,\n recommends,\n plugins,\n threadList,\n showHeader = true,\n placeholder,\n expandToolGroup = false,\n expandReasoning = false,\n expandToolDetail = false,\n threadBottom,\n } = props;\n const controller = props.controller;\n const { threadMap, currentThreadId } = useSnapshot(controller.store.state);\n // useImperativeHandleChatkitRef(ref, controller, onError);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [] || [],\n [currentThread?.id, threadMap],\n );\n\n const uiMessages = useMemo(\n () =>\n convertToAssistantMessage(messages as Readonly<ChatMessage>[], {\n toolDisplay: toolDisplay || 'group',\n }),\n [messages],\n );\n\n const runtime = useExternalStoreRuntime({\n messages: uiMessages,\n isLoading: currentThread?.sending,\n isDisabled: !!currentThread?.metadata['isInitingSession'],\n convertMessage: message => message,\n onNew: async message => {\n const attachments = await Promise.all(\n message.attachments?.map(async item => {\n return {\n ...item,\n base64: await convertToBase64(item.file as File),\n };\n }) || [],\n );\n\n controller?.sendMessage({\n attaches: attachments.map(item => ({\n id: item.id,\n attachId: item.id,\n url: item.base64,\n status: 'success',\n type: checkMedia(item.contentType),\n mimeType: item.contentType,\n })),\n content: compact([\n ...message.content.map(item => {\n if (item.type === 'text') {\n return {\n type: 'text',\n text: item.text,\n } as TextMessage;\n }\n }),\n ]),\n });\n },\n onReload: async (parentId, config) => {\n if (currentThread?.id && parentId)\n controller?.reloadMessage({\n threadId: currentThread?.id,\n messageId: parentId,\n });\n else {\n controller.onError?.(new Error('未找到对应的对话'));\n }\n },\n onCancel: async () => {\n controller?.abortMessage();\n },\n adapters: {\n attachments: {\n remove: async ({ id }) => {\n console.log(id);\n },\n send: async ({ id, file }) => {\n return {\n id,\n type: 'image',\n name: file.name,\n contentType: file.type,\n content: [\n {\n type: 'image',\n image: file.name,\n },\n ],\n status: {\n type: 'complete',\n },\n file,\n };\n },\n accept: 'image/*',\n add: async ({ file }) => {\n return {\n file,\n id: uuid(),\n type: 'image',\n name: file.name,\n contentType: file.type,\n status: {\n type: 'running',\n reason: 'uploading',\n progress: 0,\n },\n };\n },\n },\n },\n });\n\n const selectedSpan = useTraceStore(state => state.selectedSpan);\n const setSelectedSpan = useTraceStore(state => state.setSelectedSpan);\n useEffect(() => () => setSelectedSpan(null), [setSelectedSpan]);\n // const events = useEvent(currentThreadId);\n // useEvent(currentThreadId);\n return (\n <AssistantRuntimeProvider key={currentThreadId} runtime={runtime}>\n <Toaster />\n <ExecutionCard />\n <ChatkitProvider\n value={{\n ref: ref as MutableRefObject<ChatkitRef | null>,\n plugins: plugins || [],\n showThreadList: threadList !== false,\n placeholder: placeholder || '请输入内容',\n showHeader,\n expandToolGroup,\n expandToolDetail,\n expandReasoning,\n controller,\n }}\n >\n <div className=\"flex h-full w-full\">\n {threadList !== false &&\n (typeof threadList === 'function' ? (\n threadList({\n threadList: values(threadMap) as ThreadType[],\n })\n ) : (\n <ThreadList />\n ))}\n <div className=\"flex-1 h-full w-[calc(100%-200px)]\">\n <Group\n orientation=\"vertical\"\n style={{ height: '100%', width: '100%' }}\n >\n <Panel>\n <Thread welcome={welcome} recommends={recommends} />\n </Panel>\n {selectedSpan && (\n <Panel defaultSize={'30%'}>\n <TraceDetail\n selectedSpan={selectedSpan || undefined}\n onCancel={() => setSelectedSpan(null)}\n />\n </Panel>\n )}\n {threadBottom}\n </Group>\n </div>\n </div>\n </ChatkitProvider>\n {(tools || []).map((tool, index) => tool)}\n </AssistantRuntimeProvider>\n );\n },\n);\n\nconst Chatkit = (props: ChatkitProps) => {\n const {\n initialConfig,\n welcome,\n recommends,\n onError,\n toolDisplay,\n plugins,\n chatController: chatControllerFromProps = null,\n threadBottom,\n chatControllerPlugins,\n threadList,\n showHeader = true,\n placeholder,\n expandToolGroup,\n expandToolDetail,\n region,\n } = props;\n\n const controllerRef = useRef<ChatController | null>(chatControllerFromProps);\n\n const controller = controllerRef.current;\n\n const { currentThreadId, threadMap } = useSnapshot(controller!.store.state);\n\n const currentThread = currentThreadId ? threadMap[currentThreadId] : null;\n\n const messages = useMemo(\n () => threadMap[currentThread?.id || '']?.messages || [],\n [currentThread?.id, threadMap],\n );\n return (\n <div className={'chatkit-wrapper'} style={{ height: '100%' }} data-chatkit>\n <Group style={{ height: '100%' }}>\n <Panel minSize={750} maxSize={900}>\n <ChatkitImpl\n key={currentThreadId}\n tools={[<Toaster />, <ExecutionCard />]}\n showHeader={showHeader}\n recommends={recommends}\n initialConfig={initialConfig}\n expandToolGroup={expandToolGroup}\n expandToolDetail={expandToolDetail}\n placeholder={placeholder}\n welcome={welcome}\n plugins={plugins}\n threadList={threadList}\n threadBottom={threadBottom}\n controller={controller!}\n />\n </Panel>\n {region && (\n <Panel defaultSize={'25%'} className=\"border-l\">\n <Debug\n region={region}\n controller={controller!}\n messages={\n (messages.filter(msg => msg.role !== 'user') || []) as any[]\n }\n />\n </Panel>\n )}\n </Group>\n </div>\n );\n};\n\nexport default forwardRef(Chatkit);\n"],"names":["forwardRef","threadList","useSnapshot","useMemo","useExternalStoreRuntime","convertToBase64","uuid","useTraceStore","useEffect","_jsxs","AssistantRuntimeProvider","_jsx","Toaster","ExecutionCard","ChatkitProvider","ThreadList","Group","Panel","Thread","useRef","Debug"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,WAAW,GAAGA,gBAAU,CAC5B,CACE,KAkBC,EACD,GAA6B,KAC3B;AACF,IAAA,MAAM,EACJ,aAAa,EACb,KAAK,EACL,WAAW,GAAG,OAAO,EACrB,OAAO,EACP,UAAU,EACV,OAAO,cACPC,YAAU,EACV,UAAU,GAAG,IAAI,EACjB,WAAW,EACX,eAAe,GAAG,KAAK,EACvB,eAAe,GAAG,KAAK,EACvB,gBAAgB,GAAG,KAAK,EACxB,YAAY,GACb,GAAG,KAAK,CAAC;AACV,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;AACpC,IAAA,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAGC,iBAAW,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;;AAG3E,IAAA,MAAM,aAAa,GAAG,eAAe,GAAG,SAAS,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;AAC1E,IAAA,MAAM,QAAQ,GAAGC,aAAO,CACtB,MAAM,SAAS,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,IAAI,EAAE,IAAI,EAAE,EAC9D,CAAC,aAAa,EAAE,EAAE,EAAE,SAAS,CAAC,CAC/B,CAAC;IAEF,MAAM,UAAU,GAAGA,aAAO,CACxB,MACE,yBAAyB,CAAC,QAAmC,EAAE;QAC7D,WAAW,EAAE,WAAW,IAAI,OAAO;AACpC,KAAA,CAAC,EACJ,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,MAAM,OAAO,GAAGC,+CAAuB,CAAC;AACtC,QAAA,QAAQ,EAAE,UAAU;QACpB,SAAS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CACT,CACK,EAAA,CAAA,EAAA,CACJ,EACN;AACJ,CAAC,CAAC;AAEF,YAAepB,gBAAU,CAAC,OAAO,CAAC;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChatkitProps
|
|
1
|
+
import { ChatkitProps } from './types';
|
|
2
2
|
import './style.less';
|
|
3
|
-
declare const _default: import("react").ForwardRefExoticComponent<ChatkitProps & import("react").RefAttributes<
|
|
3
|
+
declare const _default: import("react").ForwardRefExoticComponent<ChatkitProps & import("react").RefAttributes<unknown>>;
|
|
4
4
|
export default _default;
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Chatkit/index.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/Chatkit/index.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAc,MAAM,SAAS,CAAC;AAoBnD,OAAO,cAAc,CAAC;;AAoRtB,wBAAmC"}
|
|
@@ -13,7 +13,6 @@ import checkMedia from '../../utils/checkMedia.js';
|
|
|
13
13
|
import TraceDetail from '../../adk/components/Debug/Trace/TraceDetail.js';
|
|
14
14
|
import { useTraceStore } from '../../adk/components/Debug/Trace/store.js';
|
|
15
15
|
import ADK from '../../adk/components/Debug/index.js';
|
|
16
|
-
import cloneDeep from '../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/cloneDeep.js';
|
|
17
16
|
import { useExternalStoreRuntime } from '../../node_modules/.pnpm/@assistant-ui_react@0.11.37_patch_hash_wncib234fzw2z5h67nrdhchb2a_@types_react-dom@17.0.2_@ty_c64hu5rigivj2gtpzfqjqatr5y/node_modules/@assistant-ui/react/dist/legacy-runtime/runtime-cores/external-store/useExternalStoreRuntime.js';
|
|
18
17
|
import compact from '../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/compact.js';
|
|
19
18
|
import v4 from '../../node_modules/.pnpm/uuid@13.0.0/node_modules/uuid/dist/v4.js';
|
|
@@ -22,12 +21,12 @@ import values from '../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/loda
|
|
|
22
21
|
import { useSnapshot } from '../../node_modules/.pnpm/valtio@2.1.8_patch_hash_boxi3qpsg2dztwe4vz7tsjpr3m_@types_react@17.0.2_react@17.0.2/node_modules/valtio/esm/react.js';
|
|
23
22
|
|
|
24
23
|
const ChatkitImpl = forwardRef((props, ref) => {
|
|
25
|
-
const { initialConfig, tools, toolDisplay = 'group', welcome, recommends, plugins, threadList, showHeader = true, placeholder, expandToolGroup = false, expandReasoning = false, expandToolDetail = false,
|
|
24
|
+
const { initialConfig, tools, toolDisplay = 'group', welcome, recommends, plugins, threadList, showHeader = true, placeholder, expandToolGroup = false, expandReasoning = false, expandToolDetail = false, threadBottom, } = props;
|
|
26
25
|
const controller = props.controller;
|
|
27
26
|
const { threadMap, currentThreadId } = useSnapshot(controller.store.state);
|
|
28
27
|
// useImperativeHandleChatkitRef(ref, controller, onError);
|
|
29
28
|
const currentThread = currentThreadId ? threadMap[currentThreadId] : null;
|
|
30
|
-
const messages = useMemo(() =>
|
|
29
|
+
const messages = useMemo(() => threadMap[currentThread?.id || '']?.messages || [] || [], [currentThread?.id, threadMap]);
|
|
31
30
|
const uiMessages = useMemo(() => convertToAssistantMessage(messages, {
|
|
32
31
|
toolDisplay: toolDisplay || 'group',
|
|
33
32
|
}), [messages]);
|
|
@@ -135,17 +134,17 @@ const ChatkitImpl = forwardRef((props, ref) => {
|
|
|
135
134
|
controller,
|
|
136
135
|
}, children: jsxs("div", { className: "flex h-full w-full", children: [threadList !== false &&
|
|
137
136
|
(typeof threadList === 'function' ? (threadList({
|
|
138
|
-
threadList:
|
|
139
|
-
})) : (jsx(ThreadList, {}))), jsx("div", { className: "flex-1 h-full w-[calc(100%-200px)]", children: jsxs(Tt, { orientation: "vertical", style: { height: '100%', width: '100%' }, children: [jsx($t, { children: jsx(Thread, { welcome: welcome, recommends: recommends }) }), selectedSpan && (jsx($t, { defaultSize: '30%', children: jsx(TraceDetail, { selectedSpan: selectedSpan || undefined, onCancel: () => setSelectedSpan(null) }) }))] }) })] }) }), (tools || []).map((tool, index) => tool)] }, currentThreadId));
|
|
137
|
+
threadList: values(threadMap),
|
|
138
|
+
})) : (jsx(ThreadList, {}))), jsx("div", { className: "flex-1 h-full w-[calc(100%-200px)]", children: jsxs(Tt, { orientation: "vertical", style: { height: '100%', width: '100%' }, children: [jsx($t, { children: jsx(Thread, { welcome: welcome, recommends: recommends }) }), selectedSpan && (jsx($t, { defaultSize: '30%', children: jsx(TraceDetail, { selectedSpan: selectedSpan || undefined, onCancel: () => setSelectedSpan(null) }) })), threadBottom] }) })] }) }), (tools || []).map((tool, index) => tool)] }, currentThreadId));
|
|
140
139
|
});
|
|
141
|
-
const Chatkit = (props
|
|
142
|
-
const { initialConfig, welcome, recommends, onError, toolDisplay, plugins, chatController: chatControllerFromProps = null, chatControllerPlugins, threadList, showHeader = true, placeholder, expandToolGroup, expandToolDetail, region, } = props;
|
|
140
|
+
const Chatkit = (props) => {
|
|
141
|
+
const { initialConfig, welcome, recommends, onError, toolDisplay, plugins, chatController: chatControllerFromProps = null, threadBottom, chatControllerPlugins, threadList, showHeader = true, placeholder, expandToolGroup, expandToolDetail, region, } = props;
|
|
143
142
|
const controllerRef = useRef(chatControllerFromProps);
|
|
144
143
|
const controller = controllerRef.current;
|
|
145
144
|
const { currentThreadId, threadMap } = useSnapshot(controller.store.state);
|
|
146
145
|
const currentThread = currentThreadId ? threadMap[currentThreadId] : null;
|
|
147
|
-
const messages = useMemo(() =>
|
|
148
|
-
return (jsx("div", { className: 'chatkit-wrapper', style: { height: '100%' }, "data-chatkit": true, children: jsxs(Tt, { style: { height: '100%' }, children: [jsx($t, { minSize: 750, maxSize: 900, children: jsx(ChatkitImpl, { tools: [jsx(Toaster, {}), jsx(ExecutionCard, {})], showHeader: showHeader, recommends: recommends, initialConfig: initialConfig, expandToolGroup: expandToolGroup, expandToolDetail: expandToolDetail, placeholder: placeholder, welcome: welcome, plugins: plugins, threadList: threadList, controller: controller }, currentThreadId) }), region && (jsx($t, { defaultSize: '25%', className: "border-l", children: jsx(ADK, { region: region, controller: controller, messages: (messages.filter(msg => msg.role !== 'user') || []) }) }))] }) }));
|
|
146
|
+
const messages = useMemo(() => threadMap[currentThread?.id || '']?.messages || [], [currentThread?.id, threadMap]);
|
|
147
|
+
return (jsx("div", { className: 'chatkit-wrapper', style: { height: '100%' }, "data-chatkit": true, children: jsxs(Tt, { style: { height: '100%' }, children: [jsx($t, { minSize: 750, maxSize: 900, children: jsx(ChatkitImpl, { tools: [jsx(Toaster, {}), jsx(ExecutionCard, {})], showHeader: showHeader, recommends: recommends, initialConfig: initialConfig, expandToolGroup: expandToolGroup, expandToolDetail: expandToolDetail, placeholder: placeholder, welcome: welcome, plugins: plugins, threadList: threadList, threadBottom: threadBottom, controller: controller }, currentThreadId) }), region && (jsx($t, { defaultSize: '25%', className: "border-l", children: jsx(ADK, { region: region, controller: controller, messages: (messages.filter(msg => msg.role !== 'user') || []) }) }))] }) }));
|
|
149
148
|
};
|
|
150
149
|
var index = forwardRef(Chatkit);
|
|
151
150
|
|