@cpzxrobot/sdk 1.3.127 → 1.3.129
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/web_platform.js +9 -2
- package/package.json +1 -1
- package/web_platform.ts +18 -2
package/dist/web_platform.js
CHANGED
|
@@ -84,7 +84,14 @@ class WebPlatform {
|
|
|
84
84
|
headers.set('Miniapp-Code', (_a = this.appCode) !== null && _a !== void 0 ? _a : "");
|
|
85
85
|
headers.set('Accept', 'text/event-stream');
|
|
86
86
|
headers.set('Cache-Control', 'no-cache');
|
|
87
|
-
|
|
87
|
+
// 处理 body 是 object 的情况
|
|
88
|
+
let processedInit = init;
|
|
89
|
+
if ((init === null || init === void 0 ? void 0 : init.body) && typeof init.body === 'object' && !(init.body instanceof FormData) && !(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer)) {
|
|
90
|
+
processedInit = Object.assign(Object.assign({}, init), { body: JSON.stringify(init.body), headers: Object.assign(Object.assign({}, init.headers), { 'Content-Type': 'application/json' }) });
|
|
91
|
+
// 更新 headers 对象
|
|
92
|
+
headers.set('Content-Type', 'application/json');
|
|
93
|
+
}
|
|
94
|
+
const response = yield fetch(this.baseURL + input.toString(), Object.assign(Object.assign({}, processedInit), { headers }));
|
|
88
95
|
var reader = response.body.getReader();
|
|
89
96
|
const decoder = new TextDecoder("utf-8");
|
|
90
97
|
let done = false;
|
|
@@ -106,7 +113,7 @@ class WebPlatform {
|
|
|
106
113
|
if (line === "[DONE]") {
|
|
107
114
|
break;
|
|
108
115
|
}
|
|
109
|
-
else if (line.startsWith("data:
|
|
116
|
+
else if (line.startsWith("data:")) {
|
|
110
117
|
// remove prefix 'data: '
|
|
111
118
|
// 移除前缀 'data: '
|
|
112
119
|
var data = JSON.parse(line.split(": ")[1]);
|
package/package.json
CHANGED
package/web_platform.ts
CHANGED
|
@@ -79,8 +79,24 @@ export class WebPlatform implements PlatformInterface {
|
|
|
79
79
|
headers.set('Miniapp-Code', this.appCode ?? "");
|
|
80
80
|
headers.set('Accept', 'text/event-stream');
|
|
81
81
|
headers.set('Cache-Control', 'no-cache');
|
|
82
|
+
|
|
83
|
+
// 处理 body 是 object 的情况
|
|
84
|
+
let processedInit = init;
|
|
85
|
+
if (init?.body && typeof init.body === 'object' && !(init.body instanceof FormData) && !(init.body instanceof Blob) && !(init.body instanceof ArrayBuffer)) {
|
|
86
|
+
processedInit = {
|
|
87
|
+
...init,
|
|
88
|
+
body: JSON.stringify(init.body),
|
|
89
|
+
headers: {
|
|
90
|
+
...init.headers,
|
|
91
|
+
'Content-Type': 'application/json'
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// 更新 headers 对象
|
|
95
|
+
headers.set('Content-Type', 'application/json');
|
|
96
|
+
}
|
|
97
|
+
|
|
82
98
|
const response = await fetch(this.baseURL + input.toString(), {
|
|
83
|
-
...
|
|
99
|
+
...processedInit,
|
|
84
100
|
headers
|
|
85
101
|
});
|
|
86
102
|
|
|
@@ -105,7 +121,7 @@ export class WebPlatform implements PlatformInterface {
|
|
|
105
121
|
try {
|
|
106
122
|
if (line === "[DONE]") {
|
|
107
123
|
break;
|
|
108
|
-
} else if (line.startsWith("data:
|
|
124
|
+
} else if (line.startsWith("data:")) {
|
|
109
125
|
// remove prefix 'data: '
|
|
110
126
|
// 移除前缀 'data: '
|
|
111
127
|
var data = JSON.parse(line.split(": ")[1]!);
|