@blocklet/pages-kit 0.2.371 → 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.
@@ -8,18 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
12
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
13
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
15
- return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
16
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
17
- 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]); } }
18
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
19
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
20
- function fulfill(value) { resume("next", value); }
21
- function reject(value) { resume("throw", value); }
22
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
23
21
  };
24
22
  Object.defineProperty(exports, "__esModule", { value: true });
25
23
  exports.getSessions = getSessions;
@@ -85,46 +83,46 @@ function deleteSession(_a) {
85
83
  });
86
84
  }
87
85
  function runAgent(_a) {
88
- return __asyncGenerator(this, arguments, function* runAgent_1({ aid, sessionId, blockletDid, working, parameters, }) {
86
+ return __awaiter(this, void 0, void 0, function* () {
89
87
  var _b;
90
- const res = yield __await((0, request_1.fetch)((0, ufo_1.joinURL)((0, request_1.getAIRuntimeApiPrefix)(), '/api/ai/call'), {
91
- method: 'POST',
92
- headers: {
93
- 'Content-Type': 'application/json',
94
- Accept: 'text/event-stream',
95
- },
96
- body: JSON.stringify({
97
- blockletDid,
98
- sessionId,
99
- parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
100
- aid,
101
- working,
102
- }),
103
- }));
104
- if (!(res.status >= 200 && res.status < 300)) {
105
- let json;
106
- try {
107
- json = yield __await(res.json());
108
- }
109
- catch (error) {
110
- // ignore
88
+ var { responseType } = _a, input = __rest(_a, ["responseType"]);
89
+ if (responseType === 'stream') {
90
+ const res = yield (0, request_1.fetch)((0, ufo_1.joinURL)((0, request_1.getAIRuntimeApiPrefix)(), '/api/ai/call'), {
91
+ method: 'POST',
92
+ headers: {
93
+ 'Content-Type': 'application/json',
94
+ Accept: 'text/event-stream',
95
+ },
96
+ body: JSON.stringify({
97
+ blockletDid: input.blockletDid,
98
+ sessionId: input.sessionId,
99
+ inputs: Object.assign(Object.assign({}, input.inputs), { $clientTime: new Date().toISOString() }),
100
+ aid: input.aid,
101
+ working: input.working,
102
+ }),
103
+ });
104
+ if (!(res.status >= 200 && res.status < 300)) {
105
+ let json;
106
+ try {
107
+ json = yield res.json();
108
+ }
109
+ catch (error) {
110
+ // ignore
111
+ }
112
+ const message = (_b = json === null || json === void 0 ? void 0 : json.error) === null || _b === void 0 ? void 0 : _b.message;
113
+ if (typeof message === 'string') {
114
+ throw new Error(message);
115
+ }
116
+ throw new Error(`Unknown Error: ${res.status}`);
111
117
  }
112
- const message = (_b = json === null || json === void 0 ? void 0 : json.error) === null || _b === void 0 ? void 0 : _b.message;
113
- if (typeof message === 'string') {
114
- throw new Error(message);
115
- }
116
- throw new Error(`Unknown Error: ${res.status}`);
117
- }
118
- const stream = res
119
- .body.pipeThrough(new TextDecoderStream())
120
- .pipeThrough(new stream_1.EventSourceParserStream())
121
- .getReader();
122
- for (;;) {
123
- const { value, done } = yield __await(stream.read());
124
- if (value)
125
- yield yield __await(value);
126
- if (done)
127
- break;
118
+ return res
119
+ .body.pipeThrough(new TextDecoderStream())
120
+ .pipeThrough(new stream_1.EventSourceParserStream());
128
121
  }
122
+ return (0, request_1.request)({
123
+ method: 'POST',
124
+ url: (0, ufo_1.joinURL)((0, request_1.getAIRuntimeApiPrefix)(), '/api/ai/call'),
125
+ body: input,
126
+ });
129
127
  });
130
128
  }
@@ -17,7 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.MarkdownView = exports.GoogleSearchSourcesView = exports.GoogleSearchRelatedQuestionsView = exports.ImagesView = exports.OpeningQuestionsView = exports.ShareView = exports.ReferencedLinksView = exports.SuggestedQuestionsView = exports.PhotoGalleryItem = exports.ChatOutput = exports.SimpleOutput = exports.AutoForm = exports.PhotoGallery = exports.SimpleChat = exports.SimplePage = exports.ChatBotButton = exports.Runtime = exports.useAppearances = exports.ActiveAgentProvider = exports.CurrentMessageProvider = exports.CurrentAgentProvider = exports.ComponentPreferencesProvider = exports.RuntimeProvider = void 0;
20
+ exports.MarkdownView = exports.GoogleSearchSourcesView = exports.GoogleSearchRelatedQuestionsView = exports.ImagesView = exports.OpeningQuestionsView = exports.ShareView = exports.ReferencedLinksView = exports.SuggestedQuestionsView = exports.PhotoGalleryItem = exports.ChatOutput = exports.SimpleOutput = exports.AutoForm = exports.PhotoGallery = exports.SimpleChat = exports.SimplePage = exports.ChatBotButton = exports.Runtime = exports.useAppearances = exports.ActiveAgentProvider = exports.CurrentMessageProvider = exports.CurrentAgentProvider = exports.ComponentPreferencesProvider = exports.RuntimeProvider = exports.runAgent = void 0;
21
+ var session_1 = require("./api/session");
22
+ Object.defineProperty(exports, "runAgent", { enumerable: true, get: function () { return session_1.runAgent; } });
21
23
  __exportStar(require("./contexts/Runtime"), exports);
22
24
  var Runtime_1 = require("./contexts/Runtime");
23
25
  Object.defineProperty(exports, "RuntimeProvider", { enumerable: true, get: function () { return __importDefault(Runtime_1).default; } });
@@ -266,12 +266,13 @@ const createSessionState = ({ aid }) => {
266
266
  s.error = undefined;
267
267
  });
268
268
  try {
269
- const stream = (0, session_1.runAgent)({
269
+ const stream = yield (0, session_1.runAgent)({
270
270
  blockletDid,
271
271
  aid,
272
272
  sessionId,
273
273
  working,
274
- parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
274
+ inputs: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
275
+ responseType: 'stream',
275
276
  });
276
277
  let responseStarted = false;
277
278
  let mainTaskId;