@baishuyun/coze-provider 1.0.3 → 1.1.0

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.
@@ -1,22 +1,23 @@
1
-
2
- > @baishuyun/coze-provider@1.0.1 build /Users/bbbottle/Code/bs-chat-sdk/packages/coze-provider
3
- > tsup --tsconfig tsconfig.json --clean
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.1
8
- CLI Using tsup config: /Users/bbbottle/Code/bs-chat-sdk/packages/coze-provider/tsup.config.ts
9
- CLI Target: es2022
10
- CLI Cleaning output folder
11
- CJS Build start
12
- ESM Build start
13
- ESM dist/index.mjs 49.49 KB
14
- ESM dist/index.mjs.map 95.37 KB
15
- ESM ⚡️ Build success in 44ms
16
- CJS dist/index.js 51.55 KB
17
- CJS dist/index.js.map 95.69 KB
18
- CJS ⚡️ Build success in 44ms
19
- DTS Build start
20
- DTS ⚡️ Build success in 1056ms
21
- DTS dist/index.d.ts 1.57 KB
22
- DTS dist/index.d.mts 1.57 KB
1
+
2
+ 
3
+ > @baishuyun/coze-provider@1.0.3 build /Users/bbbottle/Code/bs-chat-sdk/packages/coze-provider
4
+ > tsup --tsconfig tsconfig.json --clean
5
+
6
+ CLI Building entry: src/index.ts
7
+ CLI Using tsconfig: tsconfig.json
8
+ CLI tsup v8.5.1
9
+ CLI Using tsup config: /Users/bbbottle/Code/bs-chat-sdk/packages/coze-provider/tsup.config.ts
10
+ CLI Target: es2022
11
+ CLI Cleaning output folder
12
+ CJS Build start
13
+ ESM Build start
14
+ CJS dist/index.js 49.81 KB
15
+ CJS dist/index.js.map 93.74 KB
16
+ CJS ⚡️ Build success in 26ms
17
+ ESM dist/index.mjs 48.39 KB
18
+ ESM dist/index.mjs.map 93.45 KB
19
+ ESM ⚡️ Build success in 26ms
20
+ DTS Build start
21
+ DTS ⚡️ Build success in 895ms
22
+ DTS dist/index.d.ts 1.57 KB
23
+ DTS dist/index.d.mts 1.57 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @baishuyun/coze-provider
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - prepare for pub
8
+
3
9
  ## 1.0.3
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -50,95 +40,48 @@ var import_web2 = require("stream/web");
50
40
 
51
41
  // src/utils/prompt-to-model-msg.ts
52
42
  var import_api = require("@coze/api");
53
-
54
- // src/utils/excel2json.ts
55
- var import_xlsx = __toESM(require("xlsx"));
56
- var excel2json = (file) => {
57
- let workbook;
58
- try {
59
- workbook = import_xlsx.default.read(file, {
60
- type: "array",
61
- // 或 'buffer'
62
- cellFormula: false
63
- });
64
- } catch (e) {
65
- return JSON.stringify(null);
66
- }
67
- const result = {
68
- sheets: []
69
- };
70
- workbook.SheetNames.forEach((sheetName) => {
71
- const worksheet = workbook.Sheets[sheetName];
72
- if (!worksheet) {
73
- return;
74
- }
75
- const maxRows = 1e3;
76
- const ref = worksheet["!ref"] || "A1";
77
- const range = import_xlsx.default.utils.decode_range(ref);
78
- const limitedRange = {
79
- ...range,
80
- e: { ...range.e, r: Math.min(range.e.r, range.s.r + maxRows - 1) }
81
- };
82
- const data = import_xlsx.default.utils.sheet_to_json(worksheet, {
83
- header: 1,
84
- // 使用数组格式
85
- raw: false,
86
- // 格式化值
87
- dateNF: "yyyy-mm-dd",
88
- // 日期格式
89
- range: limitedRange,
90
- // 使用限制后的范围
91
- defval: null
92
- // 空单元格默认值
93
- });
94
- result.sheets.push({
95
- name: sheetName,
96
- data,
97
- range: worksheet["!ref"],
98
- merges: worksheet["!merges"] || []
99
- });
100
- });
101
- return JSON.stringify(result);
102
- };
103
-
104
- // src/utils/prompt-to-model-msg.ts
105
43
  var decoder = new TextDecoder("utf-8");
106
- var data2csvText = (data) => {
107
- return decoder.decode(data);
44
+ var getPartType = (part) => {
45
+ if (part.type === "text") {
46
+ return "text";
47
+ }
48
+ const isImg = part.mediaType?.startsWith("image/");
49
+ if (isImg) {
50
+ return "image";
51
+ }
52
+ const isAudio = part.mediaType?.startsWith("audio/");
53
+ if (isAudio) {
54
+ return "audio";
55
+ }
56
+ return "file";
108
57
  };
109
- var parseMessageContent = (message, isMultiModalMsg) => {
110
- const result = message.content.map((part) => {
111
- if (part.type === "text") {
112
- return part.text;
113
- }
114
- const isCsv = part.mediaType === "text/csv";
115
- const isTxt = part.mediaType === "text/plain";
116
- const isImg = part.mediaType?.startsWith("image/");
117
- const isExcel = part.mediaType === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
118
- if (isImg) {
58
+ var parseMessageContent = (message, isTextOnly) => {
59
+ if (isTextOnly) {
60
+ return message.content.map((part) => part.text).join("\n");
61
+ }
62
+ const result = message.content.map(
63
+ (part) => {
119
64
  const meta = part.providerOptions?.uploadMetadata;
120
- return meta?.parsedData;
121
- }
122
- if (isExcel) {
123
- return excel2json(part.data);
124
- }
125
- if (isCsv || isTxt) {
126
- return data2csvText(part.data);
65
+ const url = meta?.url;
66
+ return {
67
+ type: getPartType(part),
68
+ text: part.type === "text" ? part.text : "",
69
+ file_url: part.type === "text" ? void 0 : url
70
+ };
127
71
  }
128
- return "";
129
- }).join("");
130
- return result;
72
+ );
73
+ return JSON.stringify(result);
131
74
  };
75
+ var isTextOnlyMsg = (message) => message.content.every((part) => part.type === "text");
132
76
  var convertPromptToMessages = (messages) => {
133
77
  return messages.map((message) => {
78
+ const isTextOnly = isTextOnlyMsg(message);
134
79
  switch (message.role) {
135
80
  case "user":
136
81
  return {
137
82
  role: import_api.RoleType.User,
138
- // content: parseMessageContent(message, multiModal) || "",
139
- // content_type: multiModal ? "object_string" : "text",
140
- content: parseMessageContent(message) || "",
141
- content_type: "text"
83
+ content: parseMessageContent(message, isTextOnly),
84
+ content_type: isTextOnly ? "text" : "object_string"
142
85
  };
143
86
  break;
144
87
  case "assistant":