@blocklet/pages-kit 0.2.340 → 0.2.342

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 (97) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/agent.js +3 -5
  2. package/lib/cjs/builtin/async/ai-runtime/api/message.js +2 -4
  3. package/lib/cjs/builtin/async/ai-runtime/api/request.js +5 -1
  4. package/lib/cjs/builtin/async/ai-runtime/api/{subscription.js → secret.js} +7 -15
  5. package/lib/cjs/builtin/async/ai-runtime/api/session.js +9 -10
  6. package/lib/cjs/builtin/async/ai-runtime/components/AgentErrorBoundary.js +27 -0
  7. package/lib/cjs/builtin/async/ai-runtime/components/AgentSettings/AgentSettingsDialog.js +80 -0
  8. package/lib/cjs/builtin/async/ai-runtime/components/PopperMenuButton/LoadingMenuItem.js +1 -1
  9. package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +10 -10
  10. package/lib/cjs/builtin/async/ai-runtime/constants.js +2 -1
  11. package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +2 -2
  12. package/lib/cjs/builtin/async/ai-runtime/contexts/Runtime.js +4 -3
  13. package/lib/cjs/builtin/async/ai-runtime/hooks/use-agent-admin.js +11 -0
  14. package/lib/cjs/builtin/async/ai-runtime/hooks/use-header-menu.js +10 -2
  15. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +4 -0
  16. package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +5 -4
  17. package/lib/cjs/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +26 -57
  18. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +10 -19
  19. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/index.js +2 -2
  20. package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +1 -1
  21. package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +3 -3
  22. package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +5 -5
  23. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +5 -4
  24. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +1 -1
  25. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +2 -2
  26. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +5 -4
  27. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +2 -2
  28. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +2 -2
  29. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +1 -1
  30. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +5 -5
  31. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +7 -7
  32. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +8 -8
  33. package/lib/cjs/builtin/async/ai-runtime/state/agent.js +7 -8
  34. package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +5 -5
  35. package/lib/cjs/builtin/async/ai-runtime/state/session.js +15 -17
  36. package/lib/cjs/builtin/page/header.js +3 -3
  37. package/lib/cjs/components/CustomComponentRenderer/index.js +1 -1
  38. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  39. package/lib/esm/builtin/async/ai-runtime/api/agent.js +4 -6
  40. package/lib/esm/builtin/async/ai-runtime/api/message.js +3 -5
  41. package/lib/esm/builtin/async/ai-runtime/api/request.js +3 -0
  42. package/lib/esm/builtin/async/ai-runtime/api/{subscription.js → secret.js} +7 -14
  43. package/lib/esm/builtin/async/ai-runtime/api/session.js +10 -11
  44. package/lib/esm/builtin/async/ai-runtime/components/AgentErrorBoundary.js +22 -0
  45. package/lib/esm/builtin/async/ai-runtime/components/AgentSettings/AgentSettingsDialog.js +76 -0
  46. package/lib/esm/builtin/async/ai-runtime/components/PopperMenuButton/LoadingMenuItem.js +1 -1
  47. package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +10 -10
  48. package/lib/esm/builtin/async/ai-runtime/constants.js +1 -0
  49. package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +2 -2
  50. package/lib/esm/builtin/async/ai-runtime/contexts/Runtime.js +4 -3
  51. package/lib/esm/builtin/async/ai-runtime/hooks/use-agent-admin.js +7 -0
  52. package/lib/esm/builtin/async/ai-runtime/hooks/use-header-menu.js +11 -3
  53. package/lib/esm/builtin/async/ai-runtime/locales/index.js +4 -0
  54. package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +5 -4
  55. package/lib/esm/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +27 -58
  56. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +10 -19
  57. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/index.js +2 -2
  58. package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +1 -1
  59. package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +3 -3
  60. package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +5 -5
  61. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +5 -4
  62. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +1 -1
  63. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +2 -2
  64. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +5 -4
  65. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +2 -2
  66. package/lib/esm/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +2 -2
  67. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +1 -1
  68. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +5 -5
  69. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +7 -7
  70. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +8 -8
  71. package/lib/esm/builtin/async/ai-runtime/state/agent.js +6 -6
  72. package/lib/esm/builtin/async/ai-runtime/state/runtime.js +5 -5
  73. package/lib/esm/builtin/async/ai-runtime/state/session.js +15 -17
  74. package/lib/esm/builtin/page/header.js +3 -3
  75. package/lib/esm/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +1 -1
  76. package/lib/esm/components/CustomComponentRenderer/index.js +1 -1
  77. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  78. package/lib/types/builtin/async/ai-runtime/api/agent.d.ts +10 -1
  79. package/lib/types/builtin/async/ai-runtime/api/message.d.ts +4 -15
  80. package/lib/types/builtin/async/ai-runtime/api/request.d.ts +1 -0
  81. package/lib/types/builtin/async/ai-runtime/api/secret.d.ts +12 -0
  82. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +5 -8
  83. package/lib/types/builtin/async/ai-runtime/components/AgentErrorBoundary.d.ts +4 -0
  84. package/lib/types/builtin/async/ai-runtime/components/AgentSettings/AgentSettingsDialog.d.ts +10 -0
  85. package/lib/types/builtin/async/ai-runtime/constants.d.ts +1 -0
  86. package/lib/types/builtin/async/ai-runtime/contexts/Runtime.d.ts +3 -1
  87. package/lib/types/builtin/async/ai-runtime/hooks/use-agent-admin.d.ts +2 -0
  88. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +4 -0
  89. package/lib/types/builtin/async/ai-runtime/runtime/Runtime/index.d.ts +2 -1
  90. package/lib/types/builtin/async/ai-runtime/state/agent.d.ts +2 -6
  91. package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +2 -0
  92. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +1 -0
  93. package/lib/types/builtin/page/header.d.ts +2 -2
  94. package/lib/types/components/CustomComponentRenderer/index.d.ts +3 -0
  95. package/lib/types/tsconfig.tsbuildinfo +1 -1
  96. package/package.json +7 -7
  97. package/lib/types/builtin/async/ai-runtime/api/subscription.d.ts +0 -15
@@ -16,8 +16,8 @@ const Runtime_1 = require("../contexts/Runtime");
16
16
  const agent_1 = require("./agent");
17
17
  const session_2 = require("./session");
18
18
  function useRuntimeState() {
19
- const { aid, working } = (0, Runtime_1.useRuntimeContext)();
20
- const [agent] = (0, agent_1.useAgentState)({ aid, working });
19
+ const { blockletDid, aid, working } = (0, Runtime_1.useRuntimeContext)();
20
+ const [agent] = (0, agent_1.useAgentState)({ blockletDid, aid, working });
21
21
  const { session: authSession, events } = (0, session_1.useSessionContext)();
22
22
  const sessionState = (0, react_1.useMemo)(() => (0, session_2.createSessionState)({ aid }), [aid]);
23
23
  const exec = sessionState((s) => s.execute);
@@ -41,8 +41,8 @@ function useRuntimeState() {
41
41
  if (!authSession.user) {
42
42
  yield login();
43
43
  }
44
- return exec(Object.assign(Object.assign({}, args), { working }));
45
- }), [authSession.user, exec, working, login]);
46
- return { aid, working, agent, execute };
44
+ return exec(Object.assign(Object.assign({}, args), { blockletDid, working }));
45
+ }), [authSession.user, exec, blockletDid, working, login]);
46
+ return { blockletDid, aid, working, agent, execute };
47
47
  }
48
48
  exports.useRuntimeState = useRuntimeState;
@@ -246,7 +246,7 @@ const createSessionState = ({ aid }) => {
246
246
  }),
247
247
  execute: (_g) => __awaiter(void 0, void 0, void 0, function* () {
248
248
  var _h, e_1, _j, _k;
249
- var { aid, working, parameters, onResponseStart } = _g, args = __rest(_g, ["aid", "working", "parameters", "onResponseStart"]);
249
+ var { blockletDid, aid, working, parameters, onResponseStart } = _g, args = __rest(_g, ["blockletDid", "aid", "working", "parameters", "onResponseStart"]);
250
250
  const sessionId = args.sessionId ||
251
251
  get().currentSessionId ||
252
252
  (yield get().createSession({
@@ -264,6 +264,7 @@ const createSessionState = ({ aid }) => {
264
264
  });
265
265
  try {
266
266
  const stream = (0, session_1.runAgent)({
267
+ blockletDid,
267
268
  aid,
268
269
  sessionId,
269
270
  working,
@@ -282,10 +283,10 @@ const createSessionState = ({ aid }) => {
282
283
  if ((value === null || value === void 0 ? void 0 : value.type) === 'CHUNK') {
283
284
  if (!message) {
284
285
  message = {
285
- taskId: value.taskId,
286
- assistantId: identity.assistantId,
286
+ id: value.taskId,
287
+ agentId: identity.assistantId,
287
288
  sessionId,
288
- parameters,
289
+ inputs: parameters,
289
290
  createdAt: new Date().toISOString(),
290
291
  updatedAt: new Date().toISOString(),
291
292
  loading: true,
@@ -299,25 +300,22 @@ const createSessionState = ({ aid }) => {
299
300
  s.messages.push(message);
300
301
  });
301
302
  }
302
- if (message.taskId === value.taskId) {
303
+ if (message.id === value.taskId) {
303
304
  requestAnimationFrame(() => {
304
305
  set((state) => {
305
- var _a, _b, _c, _d, _e, _f, _g;
306
- var _h;
306
+ var _a, _b, _c, _d;
307
+ var _e;
307
308
  const s = (_a = state.sessionMap) === null || _a === void 0 ? void 0 : _a[sessionId];
308
309
  if (!s)
309
310
  return;
310
- const msg = (_b = s.messages) === null || _b === void 0 ? void 0 : _b.findLast((i) => i.taskId === message.taskId);
311
+ const msg = (_b = s.messages) === null || _b === void 0 ? void 0 : _b.findLast((i) => i.id === message.id);
311
312
  if (!msg)
312
313
  return;
313
- (_c = msg.result) !== null && _c !== void 0 ? _c : (msg.result = {});
314
- msg.result.content = (msg.result.content || '') + (value.delta.content || '');
315
- if ((_e = (_d = value.delta) === null || _d === void 0 ? void 0 : _d.images) === null || _e === void 0 ? void 0 : _e.length) {
316
- msg.result.images = ((_f = msg.result.images) !== null && _f !== void 0 ? _f : []).concat(value.delta.images);
317
- }
314
+ (_c = msg.outputs) !== null && _c !== void 0 ? _c : (msg.outputs = {});
315
+ msg.outputs.content = (msg.outputs.content || '') + (value.delta.content || '');
318
316
  if (value.delta.object) {
319
- (_g = (_h = msg.result).objects) !== null && _g !== void 0 ? _g : (_h.objects = []);
320
- msg.result.objects.push({ taskId: value.taskId, data: value.delta.object });
317
+ (_d = (_e = msg.outputs).objects) !== null && _d !== void 0 ? _d : (_e.objects = []);
318
+ msg.outputs.objects.push(value.delta.object);
321
319
  }
322
320
  });
323
321
  });
@@ -329,7 +327,7 @@ const createSessionState = ({ aid }) => {
329
327
  const s = (_a = state.sessionMap) === null || _a === void 0 ? void 0 : _a[sessionId];
330
328
  if (!s)
331
329
  return;
332
- const msg = (_b = s.messages) === null || _b === void 0 ? void 0 : _b.findLast((i) => i.taskId === message.taskId);
330
+ const msg = (_b = s.messages) === null || _b === void 0 ? void 0 : _b.findLast((i) => i.id === message.id);
333
331
  if (msg)
334
332
  msg.error = value.error;
335
333
  else
@@ -363,7 +361,7 @@ const createSessionState = ({ aid }) => {
363
361
  return;
364
362
  s.running = false;
365
363
  if (message) {
366
- const msg = (_b = s.messages) === null || _b === void 0 ? void 0 : _b.findLast((i) => i.taskId === message.taskId);
364
+ const msg = (_b = s.messages) === null || _b === void 0 ? void 0 : _b.findLast((i) => i.id === message.id);
367
365
  if (msg)
368
366
  msg.loading = false;
369
367
  }
@@ -25,10 +25,10 @@ exports.useHeaderState = (0, zustand_1.create)()((0, immer_2.immer)((set, get) =
25
25
  for (const i of get().stack) {
26
26
  widgets.push(i());
27
27
  }
28
- const r = widgets.reduce((res, i) => (Object.assign(Object.assign(Object.assign({}, res), i), { addons: (...exists) => {
28
+ const r = widgets.reduce((res, i) => (Object.assign(Object.assign(Object.assign({}, res), i), { addons: (exists) => {
29
29
  var _a, _b, _c, _d;
30
- const a = (_b = (_a = res.addons) === null || _a === void 0 ? void 0 : _a.call(res, ...exists)) !== null && _b !== void 0 ? _b : exists;
31
- const b = (_d = (_c = i.addons) === null || _c === void 0 ? void 0 : _c.call(i, ...a)) !== null && _d !== void 0 ? _d : a;
30
+ const a = (_b = (_a = res.addons) === null || _a === void 0 ? void 0 : _a.call(res, exists)) !== null && _b !== void 0 ? _b : exists;
31
+ const b = (_d = (_c = i.addons) === null || _c === void 0 ? void 0 : _c.call(i, a)) !== null && _d !== void 0 ? _d : a;
32
32
  return b;
33
33
  } })), {});
34
34
  set((state) => {
@@ -42,7 +42,7 @@ function CustomComponentRenderer(_a) {
42
42
  var { dev } = _a, props = __rest(_a, ["dev"]);
43
43
  const inheritedDev = (0, DevProvider_1.useDev)();
44
44
  const BuiltinComponent = BuiltinComponents[props.componentId];
45
- return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { fallbackRender: (props === null || props === void 0 ? void 0 : props.fallbackRender) || ErrorView, children: (0, jsx_runtime_1.jsx)(DevProvider_1.DevProvider, { dev: dev !== null && dev !== void 0 ? dev : inheritedDev, children: BuiltinComponent ? ((0, jsx_runtime_1.jsx)(BuiltinComponent, Object.assign({}, props))) : ((0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId }))) }) }));
45
+ return ((0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: (props === null || props === void 0 ? void 0 : props.fallbackRender) || ErrorView, children: (0, jsx_runtime_1.jsx)(DevProvider_1.DevProvider, { dev: dev !== null && dev !== void 0 ? dev : inheritedDev, children: BuiltinComponent ? ((0, jsx_runtime_1.jsx)(BuiltinComponent, Object.assign({}, props))) : ((0, jsx_runtime_1.jsx)(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId }))) }) }));
46
46
  }
47
47
  exports.default = CustomComponentRenderer;
48
48
  const BuiltinComponents = {