@blocklet/pages-kit 0.2.370 → 0.2.372

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/session.js +48 -50
  2. package/lib/cjs/builtin/async/ai-runtime/components/AgentInputField/LanguageField.js +18 -33
  3. package/lib/cjs/builtin/async/ai-runtime/index.js +3 -1
  4. package/lib/cjs/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +6 -2
  5. package/lib/cjs/builtin/async/ai-runtime/state/session.js +3 -2
  6. package/lib/cjs/builtin/async/ai-runtime/utils/languages.js +36 -0
  7. package/lib/cjs/builtin/components.js +8 -0
  8. package/lib/cjs/builtin/mui/material.js +3 -2
  9. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  10. package/lib/cjs/utils/builtin.js +1 -0
  11. package/lib/cjs/utils/inject-global-components.js +2 -0
  12. package/lib/esm/builtin/async/ai-runtime/api/session.js +48 -50
  13. package/lib/esm/builtin/async/ai-runtime/components/AgentInputField/LanguageField.js +20 -35
  14. package/lib/esm/builtin/async/ai-runtime/index.js +1 -0
  15. package/lib/esm/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +6 -2
  16. package/lib/esm/builtin/async/ai-runtime/state/session.js +3 -2
  17. package/lib/esm/builtin/async/ai-runtime/utils/languages.js +33 -0
  18. package/lib/esm/builtin/components.js +1 -0
  19. package/lib/esm/builtin/mui/material.js +1 -1
  20. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  21. package/lib/esm/utils/builtin.js +1 -0
  22. package/lib/esm/utils/inject-global-components.js +2 -0
  23. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +16 -5
  24. package/lib/types/builtin/async/ai-runtime/index.d.ts +1 -0
  25. package/lib/types/builtin/async/ai-runtime/utils/languages.d.ts +8 -0
  26. package/lib/types/builtin/components.d.ts +1 -0
  27. package/lib/types/builtin/mui/material.d.ts +1 -1
  28. package/lib/types/tsconfig.tsbuildinfo +1 -1
  29. package/lib/types/utils/builtin.d.ts +1 -0
  30. package/package.json +12 -11
@@ -63,6 +63,7 @@ exports.BuiltinModules = {
63
63
  // The following packages are lazy loading
64
64
  '@blocklet/pages-kit/builtin/async/react-scroll-to-bottom': reactScrollToBottom,
65
65
  // The following packages are ignored at server side
66
+ '@blocklet/pages-kit/builtin/components': {},
66
67
  '@blocklet/pages-kit/builtin/session': {},
67
68
  '@blocklet/pages-kit/builtin/locale': {},
68
69
  '@blocklet/pages-kit/builtin/page/header': {},
@@ -34,6 +34,7 @@ const reactMarkdown = __importStar(require("../builtin/async/react-markdown"));
34
34
  const reactScrollToBottom = __importStar(require("../builtin/async/react-scroll-to-bottom"));
35
35
  const reactSyntaxHighlighter = __importStar(require("../builtin/async/react-syntax-highlighter"));
36
36
  const call = __importStar(require("../builtin/call"));
37
+ const components = __importStar(require("../builtin/components"));
37
38
  const dayjs = __importStar(require("../builtin/dayjs"));
38
39
  const emotionCss = __importStar(require("../builtin/emotion/css"));
39
40
  const iconifyReact = __importStar(require("../builtin/iconify/react"));
@@ -79,6 +80,7 @@ function injectGlobalComponents() {
79
80
  '@blocklet/pages-kit/builtin/react-router-dom': reactRouterDOM,
80
81
  '@blocklet/pages-kit/builtin/arcblock/ux': arcblockUx,
81
82
  '@blocklet/pages-kit/builtin/page/header': pageHeader,
83
+ '@blocklet/pages-kit/builtin/components': components,
82
84
  // The following packages are lazy loading
83
85
  '@blocklet/pages-kit/builtin/async/react-scroll-to-bottom': reactScrollToBottom,
84
86
  '@blocklet/pages-kit/builtin/async/react-markdown': reactMarkdown,
@@ -7,18 +7,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
11
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
14
- return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
15
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
16
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
17
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
18
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
19
- function fulfill(value) { resume("next", value); }
20
- function reject(value) { resume("throw", value); }
21
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
22
20
  };
23
21
  import { joinURL } from 'ufo';
24
22
  import { EventSourceParserStream } from '../../../stream';
@@ -76,46 +74,46 @@ export function deleteSession(_a) {
76
74
  });
77
75
  }
78
76
  export function runAgent(_a) {
79
- return __asyncGenerator(this, arguments, function* runAgent_1({ aid, sessionId, blockletDid, working, parameters, }) {
77
+ return __awaiter(this, void 0, void 0, function* () {
80
78
  var _b;
81
- const res = yield __await(fetch(joinURL(getAIRuntimeApiPrefix(), '/api/ai/call'), {
82
- method: 'POST',
83
- headers: {
84
- 'Content-Type': 'application/json',
85
- Accept: 'text/event-stream',
86
- },
87
- body: JSON.stringify({
88
- blockletDid,
89
- sessionId,
90
- parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
91
- aid,
92
- working,
93
- }),
94
- }));
95
- if (!(res.status >= 200 && res.status < 300)) {
96
- let json;
97
- try {
98
- json = yield __await(res.json());
99
- }
100
- catch (error) {
101
- // ignore
79
+ var { responseType } = _a, input = __rest(_a, ["responseType"]);
80
+ if (responseType === 'stream') {
81
+ const res = yield fetch(joinURL(getAIRuntimeApiPrefix(), '/api/ai/call'), {
82
+ method: 'POST',
83
+ headers: {
84
+ 'Content-Type': 'application/json',
85
+ Accept: 'text/event-stream',
86
+ },
87
+ body: JSON.stringify({
88
+ blockletDid: input.blockletDid,
89
+ sessionId: input.sessionId,
90
+ inputs: Object.assign(Object.assign({}, input.inputs), { $clientTime: new Date().toISOString() }),
91
+ aid: input.aid,
92
+ working: input.working,
93
+ }),
94
+ });
95
+ if (!(res.status >= 200 && res.status < 300)) {
96
+ let json;
97
+ try {
98
+ json = yield res.json();
99
+ }
100
+ catch (error) {
101
+ // ignore
102
+ }
103
+ const message = (_b = json === null || json === void 0 ? void 0 : json.error) === null || _b === void 0 ? void 0 : _b.message;
104
+ if (typeof message === 'string') {
105
+ throw new Error(message);
106
+ }
107
+ throw new Error(`Unknown Error: ${res.status}`);
102
108
  }
103
- const message = (_b = json === null || json === void 0 ? void 0 : json.error) === null || _b === void 0 ? void 0 : _b.message;
104
- if (typeof message === 'string') {
105
- throw new Error(message);
106
- }
107
- throw new Error(`Unknown Error: ${res.status}`);
108
- }
109
- const stream = res
110
- .body.pipeThrough(new TextDecoderStream())
111
- .pipeThrough(new EventSourceParserStream())
112
- .getReader();
113
- for (;;) {
114
- const { value, done } = yield __await(stream.read());
115
- if (value)
116
- yield yield __await(value);
117
- if (done)
118
- break;
109
+ return res
110
+ .body.pipeThrough(new TextDecoderStream())
111
+ .pipeThrough(new EventSourceParserStream());
119
112
  }
113
+ return request({
114
+ method: 'POST',
115
+ url: joinURL(getAIRuntimeApiPrefix(), '/api/ai/call'),
116
+ body: input,
117
+ });
120
118
  });
121
119
  }
@@ -9,45 +9,30 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- import { MenuItem, TextField } from '@mui/material';
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Autocomplete, ListItem, ListItemIcon, ListItemText, MenuItem, TextField } from '@mui/material';
14
14
  import { forwardRef } from 'react';
15
15
  import { useLocaleContext } from '../../../../locale';
16
+ import { languages } from '../../utils/languages';
17
+ const filter = (options, state) => {
18
+ return options.filter((o) => {
19
+ if (state.inputValue) {
20
+ return (o.en.toLowerCase().includes(state.inputValue.toLowerCase()) ||
21
+ o.name.toLowerCase().includes(state.inputValue.toLowerCase()));
22
+ }
23
+ return true;
24
+ });
25
+ };
16
26
  const LanguageField = forwardRef((_a, ref) => {
17
27
  var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
18
28
  const { locale } = useLocaleContext();
19
- return (_jsx(TextField, Object.assign({ ref: ref, select: true, onChange: (e) => onChange(e.target.value) }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { readOnly }), children: languages.map((option) => (_jsx(MenuItem, { value: option.en, children: locale === 'zh' ? option.cn : option.en }, option.en))) })));
29
+ const value = (props === null || props === void 0 ? void 0 : props.value) ? languages.find((o) => o.en === props.value) : null;
30
+ return (_jsx(Autocomplete, { size: "small", ref: ref, renderInput: (params) => (_jsx(TextField, Object.assign({}, params, { inputRef: props.inputRef, required: parameter === null || parameter === void 0 ? void 0 : parameter.required, placeholder: parameter === null || parameter === void 0 ? void 0 : parameter.placeholder, helperText: parameter === null || parameter === void 0 ? void 0 : parameter.helper }))), options: languages, getOptionKey: (i) => i.en, getOptionLabel: (o) => {
31
+ return locale === 'zh' ? o.cn : o.en;
32
+ }, value: value, filterOptions: filter, onChange: (_e, newValue) => {
33
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue === null || newValue === void 0 ? void 0 : newValue.en);
34
+ }, renderOption: (props, option) => {
35
+ return (_jsx(MenuItem, Object.assign({}, props, { children: _jsxs(ListItem, { sx: { py: 0 }, children: [_jsx(ListItemIcon, { children: _jsx(option.flag, {}) }), _jsx(ListItemText, { primary: `${option.name} ${locale === 'zh' ? option.cn : option.en} (${option.abbr})` })] }) })));
36
+ } }));
20
37
  });
21
38
  export default LanguageField;
22
- const languages = [
23
- { en: 'English', cn: '英语' },
24
- { en: 'Simplified Chinese', cn: '中文-简体' },
25
- { en: 'Traditional Chinese', cn: '中文-繁体' },
26
- { en: 'Spanish', cn: '西班牙语' },
27
- { en: 'French', cn: '法语' },
28
- { en: 'German', cn: '德语' },
29
- { en: 'Italian', cn: '意大利语' },
30
- { en: 'Portuguese', cn: '葡萄牙语' },
31
- { en: 'Japanese', cn: '日语' },
32
- { en: 'Korean', cn: '韩语' },
33
- { en: 'Russian', cn: '俄语' },
34
- { en: 'Polish', cn: '波兰语' },
35
- { en: 'Arabic', cn: '阿拉伯语' },
36
- { en: 'Dutch', cn: '荷兰语' },
37
- { en: 'Swedish', cn: '瑞典语' },
38
- { en: 'Finnish', cn: '芬兰语' },
39
- { en: 'Czech', cn: '捷克语' },
40
- { en: 'Danish', cn: '丹麦语' },
41
- { en: 'Greek', cn: '希腊语' },
42
- { en: 'Romanian', cn: '罗马尼亚语' },
43
- { en: 'Hungarian', cn: '匈牙利语' },
44
- { en: 'Bulgarian', cn: '保加利亚语' },
45
- { en: 'Slovak', cn: '斯洛伐克语' },
46
- { en: 'Norwegian', cn: '挪威语' },
47
- { en: 'Hebrew', cn: '希伯来语' },
48
- { en: 'Turkish', cn: '土耳其语' },
49
- { en: 'Thai', cn: '泰语' },
50
- { en: 'Indonesian', cn: '印尼语' },
51
- { en: 'Vietnamese', cn: '越南语' },
52
- { en: 'Hindi', cn: '印地语' },
53
- ];
@@ -1,3 +1,4 @@
1
+ export { runAgent } from './api/session';
1
2
  export * from './contexts/Runtime';
2
3
  export { default as RuntimeProvider } from './contexts/Runtime';
3
4
  export * from './contexts/ComponentPreferences';
@@ -82,11 +82,15 @@ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = t
82
82
  : undefined,
83
83
  }, render: ({ field, fieldState }) => {
84
84
  var _a;
85
- return (_jsxs(Stack, { className: "form-item", children: [parameter.label && _jsx(FormLabel, { children: parameter.label }), _jsx(AgentInputField, { inputProps: { 'data-testid': `runtime-input-${key}` }, inputRef: field.ref, autoFocus: index === 0, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), InputProps: parameter.key === 'question' && submitInQuestionField
85
+ return (_jsxs(Stack, { className: "form-item", children: [parameter.label && _jsx(FormLabel, { children: parameter.label }), _jsx(AgentInputField
86
+ // inputProps={{ 'data-testid': `runtime-input-${key}` }}
87
+ , {
88
+ // inputProps={{ 'data-testid': `runtime-input-${key}` }}
89
+ inputRef: field.ref, autoFocus: index === 0, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), InputProps: Object.assign(Object.assign({}, (parameter.key === 'question' && submitInQuestionField
86
90
  ? {
87
91
  endAdornment: (_jsx(InputAdornment, { position: "end", sx: { py: 3, mr: -0.75, alignSelf: 'flex-end' }, children: _jsx(LoadingButton, { "data-testid": "runtime-submit-button", ref: submitRef, type: "submit", variant: "contained", loading: running, disabled: submitDisabled, sx: { borderRadius: 1.5 }, children: submitText }) })),
88
92
  }
89
- : undefined })] }));
93
+ : {})), ({ 'data-testid': `runtime-input-${key}` } || {})) })] }));
90
94
  } }) }, parameter.id));
91
95
  }), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && (_jsx(LoadingButton, { "data-testid": "runtime-submit-button", ref: submitRef, type: "submit", variant: "contained", loading: running, disabled: submitDisabled, sx: { height: 40 }, children: submitText || t('generate') }))] }));
92
96
  }
@@ -260,12 +260,13 @@ export const createSessionState = ({ aid }) => {
260
260
  s.error = undefined;
261
261
  });
262
262
  try {
263
- const stream = runAgent({
263
+ const stream = yield runAgent({
264
264
  blockletDid,
265
265
  aid,
266
266
  sessionId,
267
267
  working,
268
- parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
268
+ inputs: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
269
+ responseType: 'stream',
269
270
  });
270
271
  let responseStarted = false;
271
272
  let mainTaskId;
@@ -0,0 +1,33 @@
1
+ import { Bg, Cn, Cz, De, Dk, Es, Fi, Fr, Gb, Gr, Hu, Id, Il, In, It, Jp, Kr, Nl, No, Pl, Pt, Ro, Ru, Sa, Se, Sk, Th, Tr, Tw, Vn, } from 'react-flags-select';
2
+ export const languages = [
3
+ { en: 'English', name: 'English', abbr: 'GB', flag: Gb, cn: '英语' },
4
+ { en: 'Simplified Chinese', name: '简体中文', abbr: 'CN', flag: Cn, cn: '简体中文' },
5
+ { en: 'Traditional Chinese', name: '繁体中文', abbr: 'ZH-TW', flag: Tw, cn: '繁体中文' },
6
+ { en: 'Spanish', name: 'Español', abbr: 'ES', flag: Es, cn: '西班牙语' },
7
+ { en: 'French', name: 'Français', abbr: 'FR', flag: Fr, cn: '法语' },
8
+ { en: 'German', name: 'Deutsch', abbr: 'DE', flag: De, cn: '德语' },
9
+ { en: 'Italian', name: 'Italiano', abbr: 'IT', flag: It, cn: '意大利语' },
10
+ { en: 'Portuguese', name: 'Português', abbr: 'PT', flag: Pt, cn: '葡萄牙语' },
11
+ { en: 'Japanese', name: '日本語', abbr: 'JP', flag: Jp, cn: '日语' },
12
+ { en: 'Korean', name: '한국어', abbr: 'KR', flag: Kr, cn: '韩语' },
13
+ { en: 'Russian', name: 'Русский', abbr: 'RU', flag: Ru, cn: '俄语' },
14
+ { en: 'Polish', name: 'Polski', abbr: 'PL', flag: Pl, cn: '波兰语' },
15
+ { en: 'Arabic', name: 'العربية', abbr: 'SA', flag: Sa, cn: '阿拉伯语' },
16
+ { en: 'Dutch', name: 'Nederlands', abbr: 'NL', flag: Nl, cn: '荷兰语' },
17
+ { en: 'Swedish', name: 'Svenska', abbr: 'SE', flag: Se, cn: '瑞典语' },
18
+ { en: 'Finnish', name: 'Suomi', abbr: 'FI', flag: Fi, cn: '芬兰语' },
19
+ { en: 'Czech', name: 'Čeština', abbr: 'CZ', flag: Cz, cn: '捷克语' },
20
+ { en: 'Danish', name: 'Dansk', abbr: 'DK', flag: Dk, cn: '丹麦语' },
21
+ { en: 'Greek', name: 'Ελληνικά', abbr: 'GR', flag: Gr, cn: '希腊语' },
22
+ { en: 'Romanian', name: 'Română', abbr: 'RO', flag: Ro, cn: '罗马尼亚语' },
23
+ { en: 'Hungarian', name: 'Magyar', abbr: 'HU', flag: Hu, cn: '匈牙利语' },
24
+ { en: 'Bulgarian', name: 'Български', abbr: 'BG', flag: Bg, cn: '保加利亚语' },
25
+ { en: 'Slovak', name: 'Slovenčina', abbr: 'SK', flag: Sk, cn: '斯洛伐克语' },
26
+ { en: 'Norwegian', name: 'Norsk', abbr: 'NO', flag: No, cn: '挪威语' },
27
+ { en: 'Hebrew', name: 'עברית', abbr: 'IL', flag: Il, cn: '希伯来语' },
28
+ { en: 'Turkish', name: 'Türkçe', abbr: 'TR', flag: Tr, cn: '土耳其语' },
29
+ { en: 'Thai', name: 'ไทย', abbr: 'TH', flag: Th, cn: '泰语' },
30
+ { en: 'Indonesian', name: 'Bahasa Indonesia', abbr: 'ID', flag: Id, cn: '印尼语' },
31
+ { en: 'Vietnamese', name: 'Tiếng Việt', abbr: 'VN', flag: Vn, cn: '越南语' },
32
+ { en: 'Hindi', name: 'हिन्दी', abbr: 'IN', flag: In, cn: '印地语' },
33
+ ];
@@ -0,0 +1 @@
1
+ export { default as LanguageField } from './async/ai-runtime/components/AgentInputField/LanguageField';
@@ -1 +1 @@
1
- export { Checkbox, ListItemText, Alert, AlertTitle, Autocomplete, Avatar, Box, Button, IconButton, ButtonGroup, Card, CardActionArea, CardActions, CardContent, CardHeader, CardMedia, CircularProgress, ClickAwayListener, Collapse, Container, Dialog, DialogActions, DialogContent, DialogTitle, Divider, Fade, GlobalStyles, Grid, Grow, LinearProgress, Link, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemSecondaryAction, ListSubheader, Menu, MenuItem, MenuList, Paper, Popper, Slide, Stack, Switch, TextField, ThemeProvider, Tooltip, Typography, Zoom, alpha, createTheme, styled, useMediaQuery, useTheme, } from '@mui/material';
1
+ export { Checkbox, ListItemText, Alert, AlertTitle, Autocomplete, Avatar, Box, Button, IconButton, ButtonGroup, Card, CardActionArea, CardActions, CardContent, CardHeader, CardMedia, CircularProgress, ClickAwayListener, Collapse, Container, Dialog, DialogActions, DialogContent, DialogTitle, Divider, Fade, GlobalStyles, Grid, Grow, LinearProgress, Link, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemSecondaryAction, ListSubheader, Menu, MenuItem, MenuList, Paper, Popper, Select, Slide, Stack, Switch, TextField, ThemeProvider, Tooltip, Typography, Zoom, alpha, createTheme, styled, useMediaQuery, useTheme, } from '@mui/material';