Spaces:
Runtime error
Runtime error
canyuelangzzy
commited on
Upload 4 files
Browse files- src/index.js +151 -0
- src/message.js +1915 -0
- src/message.proto +51 -0
- src/utils.js +111 -0
src/index.js
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const express = require('express');
|
2 |
+
const { v4: uuidv4 } = require('uuid');
|
3 |
+
const { stringToHex, chunkToUtf8String, getRandomIDPro } = require('./utils.js');
|
4 |
+
const app = express();
|
5 |
+
|
6 |
+
// 中间件配置
|
7 |
+
app.use(express.json());
|
8 |
+
app.use(express.urlencoded({ extended: true }));
|
9 |
+
|
10 |
+
app.post('/v1/chat/completions', async (req, res) => {
|
11 |
+
// o1开头的模型,不支持流式输出
|
12 |
+
if (req.body.model.startsWith('o1-') && req.body.stream) {
|
13 |
+
return res.status(400).json({
|
14 |
+
error: 'Model not supported stream',
|
15 |
+
});
|
16 |
+
}
|
17 |
+
|
18 |
+
let currentKeyIndex = 0;
|
19 |
+
try {
|
20 |
+
const { model, messages, stream = false } = req.body;
|
21 |
+
let authToken = req.headers.authorization?.replace('Bearer ', '');
|
22 |
+
// 处理逗号分隔的密钥
|
23 |
+
const keys = authToken.split(',').map((key) => key.trim());
|
24 |
+
if (keys.length > 0) {
|
25 |
+
// 确保 currentKeyIndex 不会越界
|
26 |
+
if (currentKeyIndex >= keys.length) {
|
27 |
+
currentKeyIndex = 0;
|
28 |
+
}
|
29 |
+
// 使用当前索引获取密钥
|
30 |
+
authToken = keys[currentKeyIndex];
|
31 |
+
}
|
32 |
+
if (authToken && authToken.includes('%3A%3A')) {
|
33 |
+
authToken = authToken.split('%3A%3A')[1];
|
34 |
+
}
|
35 |
+
if (!messages || !Array.isArray(messages) || messages.length === 0 || !authToken) {
|
36 |
+
return res.status(400).json({
|
37 |
+
error: 'Invalid request. Messages should be a non-empty array and authorization is required',
|
38 |
+
});
|
39 |
+
}
|
40 |
+
|
41 |
+
const hexData = await stringToHex(messages, model);
|
42 |
+
|
43 |
+
// 获取checksum,req header中传递优先,环境变量中的等级第二,最后随机生成
|
44 |
+
const checksum =
|
45 |
+
req.headers['x-cursor-checksum'] ??
|
46 |
+
process.env['x-cursor-checksum'] ??
|
47 |
+
`zo${getRandomIDPro({ dictType: 'max', size: 6 })}${getRandomIDPro({ dictType: 'max', size: 64 })}/${getRandomIDPro({ dictType: 'max', size: 64 })}`;
|
48 |
+
|
49 |
+
const response = await fetch('https://api2.cursor.sh/aiserver.v1.AiService/StreamChat', {
|
50 |
+
method: 'POST',
|
51 |
+
headers: {
|
52 |
+
'Content-Type': 'application/connect+proto',
|
53 |
+
authorization: `Bearer ${authToken}`,
|
54 |
+
'connect-accept-encoding': 'gzip,br',
|
55 |
+
'connect-protocol-version': '1',
|
56 |
+
'user-agent': 'connect-es/1.4.0',
|
57 |
+
'x-amzn-trace-id': `Root=${uuidv4()}`,
|
58 |
+
'x-cursor-checksum': checksum,
|
59 |
+
'x-cursor-client-version': '0.42.3',
|
60 |
+
'x-cursor-timezone': 'Asia/Shanghai',
|
61 |
+
'x-ghost-mode': 'false',
|
62 |
+
'x-request-id': uuidv4(),
|
63 |
+
Host: 'api2.cursor.sh',
|
64 |
+
},
|
65 |
+
body: hexData,
|
66 |
+
});
|
67 |
+
|
68 |
+
if (stream) {
|
69 |
+
res.setHeader('Content-Type', 'text/event-stream');
|
70 |
+
res.setHeader('Cache-Control', 'no-cache');
|
71 |
+
res.setHeader('Connection', 'keep-alive');
|
72 |
+
|
73 |
+
const responseId = `chatcmpl-${uuidv4()}`;
|
74 |
+
|
75 |
+
// 使用封装的函数处理 chunk
|
76 |
+
for await (const chunk of response.body) {
|
77 |
+
const text = await chunkToUtf8String(chunk);
|
78 |
+
|
79 |
+
if (text.length > 0) {
|
80 |
+
res.write(
|
81 |
+
`data: ${JSON.stringify({
|
82 |
+
id: responseId,
|
83 |
+
object: 'chat.completion.chunk',
|
84 |
+
created: Math.floor(Date.now() / 1000),
|
85 |
+
model,
|
86 |
+
choices: [
|
87 |
+
{
|
88 |
+
index: 0,
|
89 |
+
delta: {
|
90 |
+
content: text,
|
91 |
+
},
|
92 |
+
},
|
93 |
+
],
|
94 |
+
})}\n\n`,
|
95 |
+
);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
res.write('data: [DONE]\n\n');
|
100 |
+
return res.end();
|
101 |
+
} else {
|
102 |
+
let text = '';
|
103 |
+
// 在非流模式下也使用封装的函数
|
104 |
+
for await (const chunk of response.body) {
|
105 |
+
text += await chunkToUtf8String(chunk);
|
106 |
+
}
|
107 |
+
// 对解析后的字符串进行进一步处理
|
108 |
+
text = text.replace(/^.*<\|END_USER\|>/s, '');
|
109 |
+
text = text.replace(/^\n[a-zA-Z]?/, '').trim();
|
110 |
+
// console.log(text)
|
111 |
+
|
112 |
+
return res.json({
|
113 |
+
id: `chatcmpl-${uuidv4()}`,
|
114 |
+
object: 'chat.completion',
|
115 |
+
created: Math.floor(Date.now() / 1000),
|
116 |
+
model,
|
117 |
+
choices: [
|
118 |
+
{
|
119 |
+
index: 0,
|
120 |
+
message: {
|
121 |
+
role: 'assistant',
|
122 |
+
content: text,
|
123 |
+
},
|
124 |
+
finish_reason: 'stop',
|
125 |
+
},
|
126 |
+
],
|
127 |
+
usage: {
|
128 |
+
prompt_tokens: 0,
|
129 |
+
completion_tokens: 0,
|
130 |
+
total_tokens: 0,
|
131 |
+
},
|
132 |
+
});
|
133 |
+
}
|
134 |
+
} catch (error) {
|
135 |
+
console.error('Error:', error);
|
136 |
+
if (!res.headersSent) {
|
137 |
+
if (req.body.stream) {
|
138 |
+
res.write(`data: ${JSON.stringify({ error: 'Internal server error' })}\n\n`);
|
139 |
+
return res.end();
|
140 |
+
} else {
|
141 |
+
return res.status(500).json({ error: 'Internal server error' });
|
142 |
+
}
|
143 |
+
}
|
144 |
+
}
|
145 |
+
});
|
146 |
+
|
147 |
+
// 启动服务器
|
148 |
+
const PORT = process.env.PORT || 3000;
|
149 |
+
app.listen(PORT, () => {
|
150 |
+
console.log(`服务器运行在端口 ${PORT}`);
|
151 |
+
});
|
src/message.js
ADDED
@@ -0,0 +1,1915 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
|
2 |
+
'use strict';
|
3 |
+
|
4 |
+
var $protobuf = require('protobufjs/minimal');
|
5 |
+
|
6 |
+
// Common aliases
|
7 |
+
var $Reader = $protobuf.Reader,
|
8 |
+
$Writer = $protobuf.Writer,
|
9 |
+
$util = $protobuf.util;
|
10 |
+
|
11 |
+
// Exported root namespace
|
12 |
+
var $root = $protobuf.roots['default'] || ($protobuf.roots['default'] = {});
|
13 |
+
|
14 |
+
$root.ChatMessage = (function () {
|
15 |
+
/**
|
16 |
+
* Properties of a ChatMessage.
|
17 |
+
* @exports IChatMessage
|
18 |
+
* @interface IChatMessage
|
19 |
+
* @property {Array.<ChatMessage.IUserMessage>|null} [messages] ChatMessage messages
|
20 |
+
* @property {ChatMessage.IInstructions|null} [instructions] ChatMessage instructions
|
21 |
+
* @property {string|null} [projectPath] ChatMessage projectPath
|
22 |
+
* @property {ChatMessage.IModel|null} [model] ChatMessage model
|
23 |
+
* @property {string|null} [requestId] ChatMessage requestId
|
24 |
+
* @property {string|null} [summary] ChatMessage summary
|
25 |
+
* @property {string|null} [conversationId] ChatMessage conversationId
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Constructs a new ChatMessage.
|
30 |
+
* @exports ChatMessage
|
31 |
+
* @classdesc Represents a ChatMessage.
|
32 |
+
* @implements IChatMessage
|
33 |
+
* @constructor
|
34 |
+
* @param {IChatMessage=} [properties] Properties to set
|
35 |
+
*/
|
36 |
+
function ChatMessage(properties) {
|
37 |
+
this.messages = [];
|
38 |
+
if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* ChatMessage messages.
|
43 |
+
* @member {Array.<ChatMessage.IUserMessage>} messages
|
44 |
+
* @memberof ChatMessage
|
45 |
+
* @instance
|
46 |
+
*/
|
47 |
+
ChatMessage.prototype.messages = $util.emptyArray;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* ChatMessage instructions.
|
51 |
+
* @member {ChatMessage.IInstructions|null|undefined} instructions
|
52 |
+
* @memberof ChatMessage
|
53 |
+
* @instance
|
54 |
+
*/
|
55 |
+
ChatMessage.prototype.instructions = null;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* ChatMessage projectPath.
|
59 |
+
* @member {string} projectPath
|
60 |
+
* @memberof ChatMessage
|
61 |
+
* @instance
|
62 |
+
*/
|
63 |
+
ChatMessage.prototype.projectPath = '';
|
64 |
+
|
65 |
+
/**
|
66 |
+
* ChatMessage model.
|
67 |
+
* @member {ChatMessage.IModel|null|undefined} model
|
68 |
+
* @memberof ChatMessage
|
69 |
+
* @instance
|
70 |
+
*/
|
71 |
+
ChatMessage.prototype.model = null;
|
72 |
+
|
73 |
+
/**
|
74 |
+
* ChatMessage requestId.
|
75 |
+
* @member {string} requestId
|
76 |
+
* @memberof ChatMessage
|
77 |
+
* @instance
|
78 |
+
*/
|
79 |
+
ChatMessage.prototype.requestId = '';
|
80 |
+
|
81 |
+
/**
|
82 |
+
* ChatMessage summary.
|
83 |
+
* @member {string} summary
|
84 |
+
* @memberof ChatMessage
|
85 |
+
* @instance
|
86 |
+
*/
|
87 |
+
ChatMessage.prototype.summary = '';
|
88 |
+
|
89 |
+
/**
|
90 |
+
* ChatMessage conversationId.
|
91 |
+
* @member {string} conversationId
|
92 |
+
* @memberof ChatMessage
|
93 |
+
* @instance
|
94 |
+
*/
|
95 |
+
ChatMessage.prototype.conversationId = '';
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Creates a new ChatMessage instance using the specified properties.
|
99 |
+
* @function create
|
100 |
+
* @memberof ChatMessage
|
101 |
+
* @static
|
102 |
+
* @param {IChatMessage=} [properties] Properties to set
|
103 |
+
* @returns {ChatMessage} ChatMessage instance
|
104 |
+
*/
|
105 |
+
ChatMessage.create = function create(properties) {
|
106 |
+
return new ChatMessage(properties);
|
107 |
+
};
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Encodes the specified ChatMessage message. Does not implicitly {@link ChatMessage.verify|verify} messages.
|
111 |
+
* @function encode
|
112 |
+
* @memberof ChatMessage
|
113 |
+
* @static
|
114 |
+
* @param {IChatMessage} message ChatMessage message or plain object to encode
|
115 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
116 |
+
* @returns {$protobuf.Writer} Writer
|
117 |
+
*/
|
118 |
+
ChatMessage.encode = function encode(message, writer) {
|
119 |
+
if (!writer) writer = $Writer.create();
|
120 |
+
if (message.messages != null && message.messages.length)
|
121 |
+
for (var i = 0; i < message.messages.length; ++i) $root.ChatMessage.UserMessage.encode(message.messages[i], writer.uint32(/* id 2, wireType 2 =*/ 18).fork()).ldelim();
|
122 |
+
if (message.instructions != null && Object.hasOwnProperty.call(message, 'instructions'))
|
123 |
+
$root.ChatMessage.Instructions.encode(message.instructions, writer.uint32(/* id 4, wireType 2 =*/ 34).fork()).ldelim();
|
124 |
+
if (message.projectPath != null && Object.hasOwnProperty.call(message, 'projectPath')) writer.uint32(/* id 5, wireType 2 =*/ 42).string(message.projectPath);
|
125 |
+
if (message.model != null && Object.hasOwnProperty.call(message, 'model'))
|
126 |
+
$root.ChatMessage.Model.encode(message.model, writer.uint32(/* id 7, wireType 2 =*/ 58).fork()).ldelim();
|
127 |
+
if (message.requestId != null && Object.hasOwnProperty.call(message, 'requestId')) writer.uint32(/* id 9, wireType 2 =*/ 74).string(message.requestId);
|
128 |
+
if (message.summary != null && Object.hasOwnProperty.call(message, 'summary')) writer.uint32(/* id 11, wireType 2 =*/ 90).string(message.summary);
|
129 |
+
if (message.conversationId != null && Object.hasOwnProperty.call(message, 'conversationId')) writer.uint32(/* id 15, wireType 2 =*/ 122).string(message.conversationId);
|
130 |
+
return writer;
|
131 |
+
};
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Encodes the specified ChatMessage message, length delimited. Does not implicitly {@link ChatMessage.verify|verify} messages.
|
135 |
+
* @function encodeDelimited
|
136 |
+
* @memberof ChatMessage
|
137 |
+
* @static
|
138 |
+
* @param {IChatMessage} message ChatMessage message or plain object to encode
|
139 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
140 |
+
* @returns {$protobuf.Writer} Writer
|
141 |
+
*/
|
142 |
+
ChatMessage.encodeDelimited = function encodeDelimited(message, writer) {
|
143 |
+
return this.encode(message, writer).ldelim();
|
144 |
+
};
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Decodes a ChatMessage message from the specified reader or buffer.
|
148 |
+
* @function decode
|
149 |
+
* @memberof ChatMessage
|
150 |
+
* @static
|
151 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
152 |
+
* @param {number} [length] Message length if known beforehand
|
153 |
+
* @returns {ChatMessage} ChatMessage
|
154 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
155 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
156 |
+
*/
|
157 |
+
ChatMessage.decode = function decode(reader, length) {
|
158 |
+
if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
|
159 |
+
var end = length === undefined ? reader.len : reader.pos + length,
|
160 |
+
message = new $root.ChatMessage();
|
161 |
+
while (reader.pos < end) {
|
162 |
+
var tag = reader.uint32();
|
163 |
+
switch (tag >>> 3) {
|
164 |
+
case 2: {
|
165 |
+
if (!(message.messages && message.messages.length)) message.messages = [];
|
166 |
+
message.messages.push($root.ChatMessage.UserMessage.decode(reader, reader.uint32()));
|
167 |
+
break;
|
168 |
+
}
|
169 |
+
case 4: {
|
170 |
+
message.instructions = $root.ChatMessage.Instructions.decode(reader, reader.uint32());
|
171 |
+
break;
|
172 |
+
}
|
173 |
+
case 5: {
|
174 |
+
message.projectPath = reader.string();
|
175 |
+
break;
|
176 |
+
}
|
177 |
+
case 7: {
|
178 |
+
message.model = $root.ChatMessage.Model.decode(reader, reader.uint32());
|
179 |
+
break;
|
180 |
+
}
|
181 |
+
case 9: {
|
182 |
+
message.requestId = reader.string();
|
183 |
+
break;
|
184 |
+
}
|
185 |
+
case 11: {
|
186 |
+
message.summary = reader.string();
|
187 |
+
break;
|
188 |
+
}
|
189 |
+
case 15: {
|
190 |
+
message.conversationId = reader.string();
|
191 |
+
break;
|
192 |
+
}
|
193 |
+
default:
|
194 |
+
reader.skipType(tag & 7);
|
195 |
+
break;
|
196 |
+
}
|
197 |
+
}
|
198 |
+
return message;
|
199 |
+
};
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Decodes a ChatMessage message from the specified reader or buffer, length delimited.
|
203 |
+
* @function decodeDelimited
|
204 |
+
* @memberof ChatMessage
|
205 |
+
* @static
|
206 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
207 |
+
* @returns {ChatMessage} ChatMessage
|
208 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
209 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
210 |
+
*/
|
211 |
+
ChatMessage.decodeDelimited = function decodeDelimited(reader) {
|
212 |
+
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
|
213 |
+
return this.decode(reader, reader.uint32());
|
214 |
+
};
|
215 |
+
|
216 |
+
/**
|
217 |
+
* Verifies a ChatMessage message.
|
218 |
+
* @function verify
|
219 |
+
* @memberof ChatMessage
|
220 |
+
* @static
|
221 |
+
* @param {Object.<string,*>} message Plain object to verify
|
222 |
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
223 |
+
*/
|
224 |
+
ChatMessage.verify = function verify(message) {
|
225 |
+
if (typeof message !== 'object' || message === null) return 'object expected';
|
226 |
+
if (message.messages != null && message.hasOwnProperty('messages')) {
|
227 |
+
if (!Array.isArray(message.messages)) return 'messages: array expected';
|
228 |
+
for (var i = 0; i < message.messages.length; ++i) {
|
229 |
+
var error = $root.ChatMessage.UserMessage.verify(message.messages[i]);
|
230 |
+
if (error) return 'messages.' + error;
|
231 |
+
}
|
232 |
+
}
|
233 |
+
if (message.instructions != null && message.hasOwnProperty('instructions')) {
|
234 |
+
var error = $root.ChatMessage.Instructions.verify(message.instructions);
|
235 |
+
if (error) return 'instructions.' + error;
|
236 |
+
}
|
237 |
+
if (message.projectPath != null && message.hasOwnProperty('projectPath')) if (!$util.isString(message.projectPath)) return 'projectPath: string expected';
|
238 |
+
if (message.model != null && message.hasOwnProperty('model')) {
|
239 |
+
var error = $root.ChatMessage.Model.verify(message.model);
|
240 |
+
if (error) return 'model.' + error;
|
241 |
+
}
|
242 |
+
if (message.requestId != null && message.hasOwnProperty('requestId')) if (!$util.isString(message.requestId)) return 'requestId: string expected';
|
243 |
+
if (message.summary != null && message.hasOwnProperty('summary')) if (!$util.isString(message.summary)) return 'summary: string expected';
|
244 |
+
if (message.conversationId != null && message.hasOwnProperty('conversationId')) if (!$util.isString(message.conversationId)) return 'conversationId: string expected';
|
245 |
+
return null;
|
246 |
+
};
|
247 |
+
|
248 |
+
/**
|
249 |
+
* Creates a ChatMessage message from a plain object. Also converts values to their respective internal types.
|
250 |
+
* @function fromObject
|
251 |
+
* @memberof ChatMessage
|
252 |
+
* @static
|
253 |
+
* @param {Object.<string,*>} object Plain object
|
254 |
+
* @returns {ChatMessage} ChatMessage
|
255 |
+
*/
|
256 |
+
ChatMessage.fromObject = function fromObject(object) {
|
257 |
+
if (object instanceof $root.ChatMessage) return object;
|
258 |
+
var message = new $root.ChatMessage();
|
259 |
+
if (object.messages) {
|
260 |
+
if (!Array.isArray(object.messages)) throw TypeError('.ChatMessage.messages: array expected');
|
261 |
+
message.messages = [];
|
262 |
+
for (var i = 0; i < object.messages.length; ++i) {
|
263 |
+
if (typeof object.messages[i] !== 'object') throw TypeError('.ChatMessage.messages: object expected');
|
264 |
+
message.messages[i] = $root.ChatMessage.UserMessage.fromObject(object.messages[i]);
|
265 |
+
}
|
266 |
+
}
|
267 |
+
if (object.instructions != null) {
|
268 |
+
if (typeof object.instructions !== 'object') throw TypeError('.ChatMessage.instructions: object expected');
|
269 |
+
message.instructions = $root.ChatMessage.Instructions.fromObject(object.instructions);
|
270 |
+
}
|
271 |
+
if (object.projectPath != null) message.projectPath = String(object.projectPath);
|
272 |
+
if (object.model != null) {
|
273 |
+
if (typeof object.model !== 'object') throw TypeError('.ChatMessage.model: object expected');
|
274 |
+
message.model = $root.ChatMessage.Model.fromObject(object.model);
|
275 |
+
}
|
276 |
+
if (object.requestId != null) message.requestId = String(object.requestId);
|
277 |
+
if (object.summary != null) message.summary = String(object.summary);
|
278 |
+
if (object.conversationId != null) message.conversationId = String(object.conversationId);
|
279 |
+
return message;
|
280 |
+
};
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Creates a plain object from a ChatMessage message. Also converts values to other types if specified.
|
284 |
+
* @function toObject
|
285 |
+
* @memberof ChatMessage
|
286 |
+
* @static
|
287 |
+
* @param {ChatMessage} message ChatMessage
|
288 |
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
289 |
+
* @returns {Object.<string,*>} Plain object
|
290 |
+
*/
|
291 |
+
ChatMessage.toObject = function toObject(message, options) {
|
292 |
+
if (!options) options = {};
|
293 |
+
var object = {};
|
294 |
+
if (options.arrays || options.defaults) object.messages = [];
|
295 |
+
if (options.defaults) {
|
296 |
+
object.instructions = null;
|
297 |
+
object.projectPath = '';
|
298 |
+
object.model = null;
|
299 |
+
object.requestId = '';
|
300 |
+
object.summary = '';
|
301 |
+
object.conversationId = '';
|
302 |
+
}
|
303 |
+
if (message.messages && message.messages.length) {
|
304 |
+
object.messages = [];
|
305 |
+
for (var j = 0; j < message.messages.length; ++j) object.messages[j] = $root.ChatMessage.UserMessage.toObject(message.messages[j], options);
|
306 |
+
}
|
307 |
+
if (message.instructions != null && message.hasOwnProperty('instructions')) object.instructions = $root.ChatMessage.Instructions.toObject(message.instructions, options);
|
308 |
+
if (message.projectPath != null && message.hasOwnProperty('projectPath')) object.projectPath = message.projectPath;
|
309 |
+
if (message.model != null && message.hasOwnProperty('model')) object.model = $root.ChatMessage.Model.toObject(message.model, options);
|
310 |
+
if (message.requestId != null && message.hasOwnProperty('requestId')) object.requestId = message.requestId;
|
311 |
+
if (message.summary != null && message.hasOwnProperty('summary')) object.summary = message.summary;
|
312 |
+
if (message.conversationId != null && message.hasOwnProperty('conversationId')) object.conversationId = message.conversationId;
|
313 |
+
return object;
|
314 |
+
};
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Converts this ChatMessage to JSON.
|
318 |
+
* @function toJSON
|
319 |
+
* @memberof ChatMessage
|
320 |
+
* @instance
|
321 |
+
* @returns {Object.<string,*>} JSON object
|
322 |
+
*/
|
323 |
+
ChatMessage.prototype.toJSON = function toJSON() {
|
324 |
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
325 |
+
};
|
326 |
+
|
327 |
+
/**
|
328 |
+
* Gets the default type url for ChatMessage
|
329 |
+
* @function getTypeUrl
|
330 |
+
* @memberof ChatMessage
|
331 |
+
* @static
|
332 |
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
333 |
+
* @returns {string} The default type url
|
334 |
+
*/
|
335 |
+
ChatMessage.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
336 |
+
if (typeUrlPrefix === undefined) {
|
337 |
+
typeUrlPrefix = 'type.googleapis.com';
|
338 |
+
}
|
339 |
+
return typeUrlPrefix + '/ChatMessage';
|
340 |
+
};
|
341 |
+
|
342 |
+
ChatMessage.FileContent = (function () {
|
343 |
+
/**
|
344 |
+
* Properties of a FileContent.
|
345 |
+
* @memberof ChatMessage
|
346 |
+
* @interface IFileContent
|
347 |
+
* @property {string|null} [filename] FileContent filename
|
348 |
+
* @property {string|null} [content] FileContent content
|
349 |
+
* @property {ChatMessage.FileContent.IPosition|null} [position] FileContent position
|
350 |
+
* @property {string|null} [language] FileContent language
|
351 |
+
* @property {ChatMessage.FileContent.IRange|null} [range] FileContent range
|
352 |
+
* @property {number|null} [length] FileContent length
|
353 |
+
* @property {number|null} [type] FileContent type
|
354 |
+
* @property {number|null} [errorCode] FileContent errorCode
|
355 |
+
*/
|
356 |
+
|
357 |
+
/**
|
358 |
+
* Constructs a new FileContent.
|
359 |
+
* @memberof ChatMessage
|
360 |
+
* @classdesc Represents a FileContent.
|
361 |
+
* @implements IFileContent
|
362 |
+
* @constructor
|
363 |
+
* @param {ChatMessage.IFileContent=} [properties] Properties to set
|
364 |
+
*/
|
365 |
+
function FileContent(properties) {
|
366 |
+
if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
|
367 |
+
}
|
368 |
+
|
369 |
+
/**
|
370 |
+
* FileContent filename.
|
371 |
+
* @member {string} filename
|
372 |
+
* @memberof ChatMessage.FileContent
|
373 |
+
* @instance
|
374 |
+
*/
|
375 |
+
FileContent.prototype.filename = '';
|
376 |
+
|
377 |
+
/**
|
378 |
+
* FileContent content.
|
379 |
+
* @member {string} content
|
380 |
+
* @memberof ChatMessage.FileContent
|
381 |
+
* @instance
|
382 |
+
*/
|
383 |
+
FileContent.prototype.content = '';
|
384 |
+
|
385 |
+
/**
|
386 |
+
* FileContent position.
|
387 |
+
* @member {ChatMessage.FileContent.IPosition|null|undefined} position
|
388 |
+
* @memberof ChatMessage.FileContent
|
389 |
+
* @instance
|
390 |
+
*/
|
391 |
+
FileContent.prototype.position = null;
|
392 |
+
|
393 |
+
/**
|
394 |
+
* FileContent language.
|
395 |
+
* @member {string} language
|
396 |
+
* @memberof ChatMessage.FileContent
|
397 |
+
* @instance
|
398 |
+
*/
|
399 |
+
FileContent.prototype.language = '';
|
400 |
+
|
401 |
+
/**
|
402 |
+
* FileContent range.
|
403 |
+
* @member {ChatMessage.FileContent.IRange|null|undefined} range
|
404 |
+
* @memberof ChatMessage.FileContent
|
405 |
+
* @instance
|
406 |
+
*/
|
407 |
+
FileContent.prototype.range = null;
|
408 |
+
|
409 |
+
/**
|
410 |
+
* FileContent length.
|
411 |
+
* @member {number} length
|
412 |
+
* @memberof ChatMessage.FileContent
|
413 |
+
* @instance
|
414 |
+
*/
|
415 |
+
FileContent.prototype.length = 0;
|
416 |
+
|
417 |
+
/**
|
418 |
+
* FileContent type.
|
419 |
+
* @member {number} type
|
420 |
+
* @memberof ChatMessage.FileContent
|
421 |
+
* @instance
|
422 |
+
*/
|
423 |
+
FileContent.prototype.type = 0;
|
424 |
+
|
425 |
+
/**
|
426 |
+
* FileContent errorCode.
|
427 |
+
* @member {number} errorCode
|
428 |
+
* @memberof ChatMessage.FileContent
|
429 |
+
* @instance
|
430 |
+
*/
|
431 |
+
FileContent.prototype.errorCode = 0;
|
432 |
+
|
433 |
+
/**
|
434 |
+
* Creates a new FileContent instance using the specified properties.
|
435 |
+
* @function create
|
436 |
+
* @memberof ChatMessage.FileContent
|
437 |
+
* @static
|
438 |
+
* @param {ChatMessage.IFileContent=} [properties] Properties to set
|
439 |
+
* @returns {ChatMessage.FileContent} FileContent instance
|
440 |
+
*/
|
441 |
+
FileContent.create = function create(properties) {
|
442 |
+
return new FileContent(properties);
|
443 |
+
};
|
444 |
+
|
445 |
+
/**
|
446 |
+
* Encodes the specified FileContent message. Does not implicitly {@link ChatMessage.FileContent.verify|verify} messages.
|
447 |
+
* @function encode
|
448 |
+
* @memberof ChatMessage.FileContent
|
449 |
+
* @static
|
450 |
+
* @param {ChatMessage.IFileContent} message FileContent message or plain object to encode
|
451 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
452 |
+
* @returns {$protobuf.Writer} Writer
|
453 |
+
*/
|
454 |
+
FileContent.encode = function encode(message, writer) {
|
455 |
+
if (!writer) writer = $Writer.create();
|
456 |
+
if (message.filename != null && Object.hasOwnProperty.call(message, 'filename')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.filename);
|
457 |
+
if (message.content != null && Object.hasOwnProperty.call(message, 'content')) writer.uint32(/* id 2, wireType 2 =*/ 18).string(message.content);
|
458 |
+
if (message.position != null && Object.hasOwnProperty.call(message, 'position'))
|
459 |
+
$root.ChatMessage.FileContent.Position.encode(message.position, writer.uint32(/* id 3, wireType 2 =*/ 26).fork()).ldelim();
|
460 |
+
if (message.language != null && Object.hasOwnProperty.call(message, 'language')) writer.uint32(/* id 5, wireType 2 =*/ 42).string(message.language);
|
461 |
+
if (message.range != null && Object.hasOwnProperty.call(message, 'range'))
|
462 |
+
$root.ChatMessage.FileContent.Range.encode(message.range, writer.uint32(/* id 6, wireType 2 =*/ 50).fork()).ldelim();
|
463 |
+
if (message.length != null && Object.hasOwnProperty.call(message, 'length')) writer.uint32(/* id 8, wireType 0 =*/ 64).int32(message.length);
|
464 |
+
if (message.type != null && Object.hasOwnProperty.call(message, 'type')) writer.uint32(/* id 9, wireType 0 =*/ 72).int32(message.type);
|
465 |
+
if (message.errorCode != null && Object.hasOwnProperty.call(message, 'errorCode')) writer.uint32(/* id 11, wireType 0 =*/ 88).int32(message.errorCode);
|
466 |
+
return writer;
|
467 |
+
};
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Encodes the specified FileContent message, length delimited. Does not implicitly {@link ChatMessage.FileContent.verify|verify} messages.
|
471 |
+
* @function encodeDelimited
|
472 |
+
* @memberof ChatMessage.FileContent
|
473 |
+
* @static
|
474 |
+
* @param {ChatMessage.IFileContent} message FileContent message or plain object to encode
|
475 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
476 |
+
* @returns {$protobuf.Writer} Writer
|
477 |
+
*/
|
478 |
+
FileContent.encodeDelimited = function encodeDelimited(message, writer) {
|
479 |
+
return this.encode(message, writer).ldelim();
|
480 |
+
};
|
481 |
+
|
482 |
+
/**
|
483 |
+
* Decodes a FileContent message from the specified reader or buffer.
|
484 |
+
* @function decode
|
485 |
+
* @memberof ChatMessage.FileContent
|
486 |
+
* @static
|
487 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
488 |
+
* @param {number} [length] Message length if known beforehand
|
489 |
+
* @returns {ChatMessage.FileContent} FileContent
|
490 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
491 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
492 |
+
*/
|
493 |
+
FileContent.decode = function decode(reader, length) {
|
494 |
+
if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
|
495 |
+
var end = length === undefined ? reader.len : reader.pos + length,
|
496 |
+
message = new $root.ChatMessage.FileContent();
|
497 |
+
while (reader.pos < end) {
|
498 |
+
var tag = reader.uint32();
|
499 |
+
switch (tag >>> 3) {
|
500 |
+
case 1: {
|
501 |
+
message.filename = reader.string();
|
502 |
+
break;
|
503 |
+
}
|
504 |
+
case 2: {
|
505 |
+
message.content = reader.string();
|
506 |
+
break;
|
507 |
+
}
|
508 |
+
case 3: {
|
509 |
+
message.position = $root.ChatMessage.FileContent.Position.decode(reader, reader.uint32());
|
510 |
+
break;
|
511 |
+
}
|
512 |
+
case 5: {
|
513 |
+
message.language = reader.string();
|
514 |
+
break;
|
515 |
+
}
|
516 |
+
case 6: {
|
517 |
+
message.range = $root.ChatMessage.FileContent.Range.decode(reader, reader.uint32());
|
518 |
+
break;
|
519 |
+
}
|
520 |
+
case 8: {
|
521 |
+
message.length = reader.int32();
|
522 |
+
break;
|
523 |
+
}
|
524 |
+
case 9: {
|
525 |
+
message.type = reader.int32();
|
526 |
+
break;
|
527 |
+
}
|
528 |
+
case 11: {
|
529 |
+
message.errorCode = reader.int32();
|
530 |
+
break;
|
531 |
+
}
|
532 |
+
default:
|
533 |
+
reader.skipType(tag & 7);
|
534 |
+
break;
|
535 |
+
}
|
536 |
+
}
|
537 |
+
return message;
|
538 |
+
};
|
539 |
+
|
540 |
+
/**
|
541 |
+
* Decodes a FileContent message from the specified reader or buffer, length delimited.
|
542 |
+
* @function decodeDelimited
|
543 |
+
* @memberof ChatMessage.FileContent
|
544 |
+
* @static
|
545 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
546 |
+
* @returns {ChatMessage.FileContent} FileContent
|
547 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
548 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
549 |
+
*/
|
550 |
+
FileContent.decodeDelimited = function decodeDelimited(reader) {
|
551 |
+
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
|
552 |
+
return this.decode(reader, reader.uint32());
|
553 |
+
};
|
554 |
+
|
555 |
+
/**
|
556 |
+
* Verifies a FileContent message.
|
557 |
+
* @function verify
|
558 |
+
* @memberof ChatMessage.FileContent
|
559 |
+
* @static
|
560 |
+
* @param {Object.<string,*>} message Plain object to verify
|
561 |
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
562 |
+
*/
|
563 |
+
FileContent.verify = function verify(message) {
|
564 |
+
if (typeof message !== 'object' || message === null) return 'object expected';
|
565 |
+
if (message.filename != null && message.hasOwnProperty('filename')) if (!$util.isString(message.filename)) return 'filename: string expected';
|
566 |
+
if (message.content != null && message.hasOwnProperty('content')) if (!$util.isString(message.content)) return 'content: string expected';
|
567 |
+
if (message.position != null && message.hasOwnProperty('position')) {
|
568 |
+
var error = $root.ChatMessage.FileContent.Position.verify(message.position);
|
569 |
+
if (error) return 'position.' + error;
|
570 |
+
}
|
571 |
+
if (message.language != null && message.hasOwnProperty('language')) if (!$util.isString(message.language)) return 'language: string expected';
|
572 |
+
if (message.range != null && message.hasOwnProperty('range')) {
|
573 |
+
var error = $root.ChatMessage.FileContent.Range.verify(message.range);
|
574 |
+
if (error) return 'range.' + error;
|
575 |
+
}
|
576 |
+
if (message.length != null && message.hasOwnProperty('length')) if (!$util.isInteger(message.length)) return 'length: integer expected';
|
577 |
+
if (message.type != null && message.hasOwnProperty('type')) if (!$util.isInteger(message.type)) return 'type: integer expected';
|
578 |
+
if (message.errorCode != null && message.hasOwnProperty('errorCode')) if (!$util.isInteger(message.errorCode)) return 'errorCode: integer expected';
|
579 |
+
return null;
|
580 |
+
};
|
581 |
+
|
582 |
+
/**
|
583 |
+
* Creates a FileContent message from a plain object. Also converts values to their respective internal types.
|
584 |
+
* @function fromObject
|
585 |
+
* @memberof ChatMessage.FileContent
|
586 |
+
* @static
|
587 |
+
* @param {Object.<string,*>} object Plain object
|
588 |
+
* @returns {ChatMessage.FileContent} FileContent
|
589 |
+
*/
|
590 |
+
FileContent.fromObject = function fromObject(object) {
|
591 |
+
if (object instanceof $root.ChatMessage.FileContent) return object;
|
592 |
+
var message = new $root.ChatMessage.FileContent();
|
593 |
+
if (object.filename != null) message.filename = String(object.filename);
|
594 |
+
if (object.content != null) message.content = String(object.content);
|
595 |
+
if (object.position != null) {
|
596 |
+
if (typeof object.position !== 'object') throw TypeError('.ChatMessage.FileContent.position: object expected');
|
597 |
+
message.position = $root.ChatMessage.FileContent.Position.fromObject(object.position);
|
598 |
+
}
|
599 |
+
if (object.language != null) message.language = String(object.language);
|
600 |
+
if (object.range != null) {
|
601 |
+
if (typeof object.range !== 'object') throw TypeError('.ChatMessage.FileContent.range: object expected');
|
602 |
+
message.range = $root.ChatMessage.FileContent.Range.fromObject(object.range);
|
603 |
+
}
|
604 |
+
if (object.length != null) message.length = object.length | 0;
|
605 |
+
if (object.type != null) message.type = object.type | 0;
|
606 |
+
if (object.errorCode != null) message.errorCode = object.errorCode | 0;
|
607 |
+
return message;
|
608 |
+
};
|
609 |
+
|
610 |
+
/**
|
611 |
+
* Creates a plain object from a FileContent message. Also converts values to other types if specified.
|
612 |
+
* @function toObject
|
613 |
+
* @memberof ChatMessage.FileContent
|
614 |
+
* @static
|
615 |
+
* @param {ChatMessage.FileContent} message FileContent
|
616 |
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
617 |
+
* @returns {Object.<string,*>} Plain object
|
618 |
+
*/
|
619 |
+
FileContent.toObject = function toObject(message, options) {
|
620 |
+
if (!options) options = {};
|
621 |
+
var object = {};
|
622 |
+
if (options.defaults) {
|
623 |
+
object.filename = '';
|
624 |
+
object.content = '';
|
625 |
+
object.position = null;
|
626 |
+
object.language = '';
|
627 |
+
object.range = null;
|
628 |
+
object.length = 0;
|
629 |
+
object.type = 0;
|
630 |
+
object.errorCode = 0;
|
631 |
+
}
|
632 |
+
if (message.filename != null && message.hasOwnProperty('filename')) object.filename = message.filename;
|
633 |
+
if (message.content != null && message.hasOwnProperty('content')) object.content = message.content;
|
634 |
+
if (message.position != null && message.hasOwnProperty('position')) object.position = $root.ChatMessage.FileContent.Position.toObject(message.position, options);
|
635 |
+
if (message.language != null && message.hasOwnProperty('language')) object.language = message.language;
|
636 |
+
if (message.range != null && message.hasOwnProperty('range')) object.range = $root.ChatMessage.FileContent.Range.toObject(message.range, options);
|
637 |
+
if (message.length != null && message.hasOwnProperty('length')) object.length = message.length;
|
638 |
+
if (message.type != null && message.hasOwnProperty('type')) object.type = message.type;
|
639 |
+
if (message.errorCode != null && message.hasOwnProperty('errorCode')) object.errorCode = message.errorCode;
|
640 |
+
return object;
|
641 |
+
};
|
642 |
+
|
643 |
+
/**
|
644 |
+
* Converts this FileContent to JSON.
|
645 |
+
* @function toJSON
|
646 |
+
* @memberof ChatMessage.FileContent
|
647 |
+
* @instance
|
648 |
+
* @returns {Object.<string,*>} JSON object
|
649 |
+
*/
|
650 |
+
FileContent.prototype.toJSON = function toJSON() {
|
651 |
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
652 |
+
};
|
653 |
+
|
654 |
+
/**
|
655 |
+
* Gets the default type url for FileContent
|
656 |
+
* @function getTypeUrl
|
657 |
+
* @memberof ChatMessage.FileContent
|
658 |
+
* @static
|
659 |
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
660 |
+
* @returns {string} The default type url
|
661 |
+
*/
|
662 |
+
FileContent.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
663 |
+
if (typeUrlPrefix === undefined) {
|
664 |
+
typeUrlPrefix = 'type.googleapis.com';
|
665 |
+
}
|
666 |
+
return typeUrlPrefix + '/ChatMessage.FileContent';
|
667 |
+
};
|
668 |
+
|
669 |
+
FileContent.Position = (function () {
|
670 |
+
/**
|
671 |
+
* Properties of a Position.
|
672 |
+
* @memberof ChatMessage.FileContent
|
673 |
+
* @interface IPosition
|
674 |
+
* @property {number|null} [line] Position line
|
675 |
+
* @property {number|null} [column] Position column
|
676 |
+
*/
|
677 |
+
|
678 |
+
/**
|
679 |
+
* Constructs a new Position.
|
680 |
+
* @memberof ChatMessage.FileContent
|
681 |
+
* @classdesc Represents a Position.
|
682 |
+
* @implements IPosition
|
683 |
+
* @constructor
|
684 |
+
* @param {ChatMessage.FileContent.IPosition=} [properties] Properties to set
|
685 |
+
*/
|
686 |
+
function Position(properties) {
|
687 |
+
if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
|
688 |
+
}
|
689 |
+
|
690 |
+
/**
|
691 |
+
* Position line.
|
692 |
+
* @member {number} line
|
693 |
+
* @memberof ChatMessage.FileContent.Position
|
694 |
+
* @instance
|
695 |
+
*/
|
696 |
+
Position.prototype.line = 0;
|
697 |
+
|
698 |
+
/**
|
699 |
+
* Position column.
|
700 |
+
* @member {number} column
|
701 |
+
* @memberof ChatMessage.FileContent.Position
|
702 |
+
* @instance
|
703 |
+
*/
|
704 |
+
Position.prototype.column = 0;
|
705 |
+
|
706 |
+
/**
|
707 |
+
* Creates a new Position instance using the specified properties.
|
708 |
+
* @function create
|
709 |
+
* @memberof ChatMessage.FileContent.Position
|
710 |
+
* @static
|
711 |
+
* @param {ChatMessage.FileContent.IPosition=} [properties] Properties to set
|
712 |
+
* @returns {ChatMessage.FileContent.Position} Position instance
|
713 |
+
*/
|
714 |
+
Position.create = function create(properties) {
|
715 |
+
return new Position(properties);
|
716 |
+
};
|
717 |
+
|
718 |
+
/**
|
719 |
+
* Encodes the specified Position message. Does not implicitly {@link ChatMessage.FileContent.Position.verify|verify} messages.
|
720 |
+
* @function encode
|
721 |
+
* @memberof ChatMessage.FileContent.Position
|
722 |
+
* @static
|
723 |
+
* @param {ChatMessage.FileContent.IPosition} message Position message or plain object to encode
|
724 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
725 |
+
* @returns {$protobuf.Writer} Writer
|
726 |
+
*/
|
727 |
+
Position.encode = function encode(message, writer) {
|
728 |
+
if (!writer) writer = $Writer.create();
|
729 |
+
if (message.line != null && Object.hasOwnProperty.call(message, 'line')) writer.uint32(/* id 1, wireType 0 =*/ 8).int32(message.line);
|
730 |
+
if (message.column != null && Object.hasOwnProperty.call(message, 'column')) writer.uint32(/* id 2, wireType 0 =*/ 16).int32(message.column);
|
731 |
+
return writer;
|
732 |
+
};
|
733 |
+
|
734 |
+
/**
|
735 |
+
* Encodes the specified Position message, length delimited. Does not implicitly {@link ChatMessage.FileContent.Position.verify|verify} messages.
|
736 |
+
* @function encodeDelimited
|
737 |
+
* @memberof ChatMessage.FileContent.Position
|
738 |
+
* @static
|
739 |
+
* @param {ChatMessage.FileContent.IPosition} message Position message or plain object to encode
|
740 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
741 |
+
* @returns {$protobuf.Writer} Writer
|
742 |
+
*/
|
743 |
+
Position.encodeDelimited = function encodeDelimited(message, writer) {
|
744 |
+
return this.encode(message, writer).ldelim();
|
745 |
+
};
|
746 |
+
|
747 |
+
/**
|
748 |
+
* Decodes a Position message from the specified reader or buffer.
|
749 |
+
* @function decode
|
750 |
+
* @memberof ChatMessage.FileContent.Position
|
751 |
+
* @static
|
752 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
753 |
+
* @param {number} [length] Message length if known beforehand
|
754 |
+
* @returns {ChatMessage.FileContent.Position} Position
|
755 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
756 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
757 |
+
*/
|
758 |
+
Position.decode = function decode(reader, length) {
|
759 |
+
if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
|
760 |
+
var end = length === undefined ? reader.len : reader.pos + length,
|
761 |
+
message = new $root.ChatMessage.FileContent.Position();
|
762 |
+
while (reader.pos < end) {
|
763 |
+
var tag = reader.uint32();
|
764 |
+
switch (tag >>> 3) {
|
765 |
+
case 1: {
|
766 |
+
message.line = reader.int32();
|
767 |
+
break;
|
768 |
+
}
|
769 |
+
case 2: {
|
770 |
+
message.column = reader.int32();
|
771 |
+
break;
|
772 |
+
}
|
773 |
+
default:
|
774 |
+
reader.skipType(tag & 7);
|
775 |
+
break;
|
776 |
+
}
|
777 |
+
}
|
778 |
+
return message;
|
779 |
+
};
|
780 |
+
|
781 |
+
/**
|
782 |
+
* Decodes a Position message from the specified reader or buffer, length delimited.
|
783 |
+
* @function decodeDelimited
|
784 |
+
* @memberof ChatMessage.FileContent.Position
|
785 |
+
* @static
|
786 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
787 |
+
* @returns {ChatMessage.FileContent.Position} Position
|
788 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
789 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
790 |
+
*/
|
791 |
+
Position.decodeDelimited = function decodeDelimited(reader) {
|
792 |
+
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
|
793 |
+
return this.decode(reader, reader.uint32());
|
794 |
+
};
|
795 |
+
|
796 |
+
/**
|
797 |
+
* Verifies a Position message.
|
798 |
+
* @function verify
|
799 |
+
* @memberof ChatMessage.FileContent.Position
|
800 |
+
* @static
|
801 |
+
* @param {Object.<string,*>} message Plain object to verify
|
802 |
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
803 |
+
*/
|
804 |
+
Position.verify = function verify(message) {
|
805 |
+
if (typeof message !== 'object' || message === null) return 'object expected';
|
806 |
+
if (message.line != null && message.hasOwnProperty('line')) if (!$util.isInteger(message.line)) return 'line: integer expected';
|
807 |
+
if (message.column != null && message.hasOwnProperty('column')) if (!$util.isInteger(message.column)) return 'column: integer expected';
|
808 |
+
return null;
|
809 |
+
};
|
810 |
+
|
811 |
+
/**
|
812 |
+
* Creates a Position message from a plain object. Also converts values to their respective internal types.
|
813 |
+
* @function fromObject
|
814 |
+
* @memberof ChatMessage.FileContent.Position
|
815 |
+
* @static
|
816 |
+
* @param {Object.<string,*>} object Plain object
|
817 |
+
* @returns {ChatMessage.FileContent.Position} Position
|
818 |
+
*/
|
819 |
+
Position.fromObject = function fromObject(object) {
|
820 |
+
if (object instanceof $root.ChatMessage.FileContent.Position) return object;
|
821 |
+
var message = new $root.ChatMessage.FileContent.Position();
|
822 |
+
if (object.line != null) message.line = object.line | 0;
|
823 |
+
if (object.column != null) message.column = object.column | 0;
|
824 |
+
return message;
|
825 |
+
};
|
826 |
+
|
827 |
+
/**
|
828 |
+
* Creates a plain object from a Position message. Also converts values to other types if specified.
|
829 |
+
* @function toObject
|
830 |
+
* @memberof ChatMessage.FileContent.Position
|
831 |
+
* @static
|
832 |
+
* @param {ChatMessage.FileContent.Position} message Position
|
833 |
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
834 |
+
* @returns {Object.<string,*>} Plain object
|
835 |
+
*/
|
836 |
+
Position.toObject = function toObject(message, options) {
|
837 |
+
if (!options) options = {};
|
838 |
+
var object = {};
|
839 |
+
if (options.defaults) {
|
840 |
+
object.line = 0;
|
841 |
+
object.column = 0;
|
842 |
+
}
|
843 |
+
if (message.line != null && message.hasOwnProperty('line')) object.line = message.line;
|
844 |
+
if (message.column != null && message.hasOwnProperty('column')) object.column = message.column;
|
845 |
+
return object;
|
846 |
+
};
|
847 |
+
|
848 |
+
/**
|
849 |
+
* Converts this Position to JSON.
|
850 |
+
* @function toJSON
|
851 |
+
* @memberof ChatMessage.FileContent.Position
|
852 |
+
* @instance
|
853 |
+
* @returns {Object.<string,*>} JSON object
|
854 |
+
*/
|
855 |
+
Position.prototype.toJSON = function toJSON() {
|
856 |
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
857 |
+
};
|
858 |
+
|
859 |
+
/**
|
860 |
+
* Gets the default type url for Position
|
861 |
+
* @function getTypeUrl
|
862 |
+
* @memberof ChatMessage.FileContent.Position
|
863 |
+
* @static
|
864 |
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
865 |
+
* @returns {string} The default type url
|
866 |
+
*/
|
867 |
+
Position.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
868 |
+
if (typeUrlPrefix === undefined) {
|
869 |
+
typeUrlPrefix = 'type.googleapis.com';
|
870 |
+
}
|
871 |
+
return typeUrlPrefix + '/ChatMessage.FileContent.Position';
|
872 |
+
};
|
873 |
+
|
874 |
+
return Position;
|
875 |
+
})();
|
876 |
+
|
877 |
+
FileContent.Range = (function () {
|
878 |
+
/**
|
879 |
+
* Properties of a Range.
|
880 |
+
* @memberof ChatMessage.FileContent
|
881 |
+
* @interface IRange
|
882 |
+
* @property {ChatMessage.FileContent.IPosition|null} [start] Range start
|
883 |
+
* @property {ChatMessage.FileContent.IPosition|null} [end] Range end
|
884 |
+
*/
|
885 |
+
|
886 |
+
/**
|
887 |
+
* Constructs a new Range.
|
888 |
+
* @memberof ChatMessage.FileContent
|
889 |
+
* @classdesc Represents a Range.
|
890 |
+
* @implements IRange
|
891 |
+
* @constructor
|
892 |
+
* @param {ChatMessage.FileContent.IRange=} [properties] Properties to set
|
893 |
+
*/
|
894 |
+
function Range(properties) {
|
895 |
+
if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
|
896 |
+
}
|
897 |
+
|
898 |
+
/**
|
899 |
+
* Range start.
|
900 |
+
* @member {ChatMessage.FileContent.IPosition|null|undefined} start
|
901 |
+
* @memberof ChatMessage.FileContent.Range
|
902 |
+
* @instance
|
903 |
+
*/
|
904 |
+
Range.prototype.start = null;
|
905 |
+
|
906 |
+
/**
|
907 |
+
* Range end.
|
908 |
+
* @member {ChatMessage.FileContent.IPosition|null|undefined} end
|
909 |
+
* @memberof ChatMessage.FileContent.Range
|
910 |
+
* @instance
|
911 |
+
*/
|
912 |
+
Range.prototype.end = null;
|
913 |
+
|
914 |
+
/**
|
915 |
+
* Creates a new Range instance using the specified properties.
|
916 |
+
* @function create
|
917 |
+
* @memberof ChatMessage.FileContent.Range
|
918 |
+
* @static
|
919 |
+
* @param {ChatMessage.FileContent.IRange=} [properties] Properties to set
|
920 |
+
* @returns {ChatMessage.FileContent.Range} Range instance
|
921 |
+
*/
|
922 |
+
Range.create = function create(properties) {
|
923 |
+
return new Range(properties);
|
924 |
+
};
|
925 |
+
|
926 |
+
/**
|
927 |
+
* Encodes the specified Range message. Does not implicitly {@link ChatMessage.FileContent.Range.verify|verify} messages.
|
928 |
+
* @function encode
|
929 |
+
* @memberof ChatMessage.FileContent.Range
|
930 |
+
* @static
|
931 |
+
* @param {ChatMessage.FileContent.IRange} message Range message or plain object to encode
|
932 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
933 |
+
* @returns {$protobuf.Writer} Writer
|
934 |
+
*/
|
935 |
+
Range.encode = function encode(message, writer) {
|
936 |
+
if (!writer) writer = $Writer.create();
|
937 |
+
if (message.start != null && Object.hasOwnProperty.call(message, 'start'))
|
938 |
+
$root.ChatMessage.FileContent.Position.encode(message.start, writer.uint32(/* id 1, wireType 2 =*/ 10).fork()).ldelim();
|
939 |
+
if (message.end != null && Object.hasOwnProperty.call(message, 'end'))
|
940 |
+
$root.ChatMessage.FileContent.Position.encode(message.end, writer.uint32(/* id 2, wireType 2 =*/ 18).fork()).ldelim();
|
941 |
+
return writer;
|
942 |
+
};
|
943 |
+
|
944 |
+
/**
|
945 |
+
* Encodes the specified Range message, length delimited. Does not implicitly {@link ChatMessage.FileContent.Range.verify|verify} messages.
|
946 |
+
* @function encodeDelimited
|
947 |
+
* @memberof ChatMessage.FileContent.Range
|
948 |
+
* @static
|
949 |
+
* @param {ChatMessage.FileContent.IRange} message Range message or plain object to encode
|
950 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
951 |
+
* @returns {$protobuf.Writer} Writer
|
952 |
+
*/
|
953 |
+
Range.encodeDelimited = function encodeDelimited(message, writer) {
|
954 |
+
return this.encode(message, writer).ldelim();
|
955 |
+
};
|
956 |
+
|
957 |
+
/**
|
958 |
+
* Decodes a Range message from the specified reader or buffer.
|
959 |
+
* @function decode
|
960 |
+
* @memberof ChatMessage.FileContent.Range
|
961 |
+
* @static
|
962 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
963 |
+
* @param {number} [length] Message length if known beforehand
|
964 |
+
* @returns {ChatMessage.FileContent.Range} Range
|
965 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
966 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
967 |
+
*/
|
968 |
+
Range.decode = function decode(reader, length) {
|
969 |
+
if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
|
970 |
+
var end = length === undefined ? reader.len : reader.pos + length,
|
971 |
+
message = new $root.ChatMessage.FileContent.Range();
|
972 |
+
while (reader.pos < end) {
|
973 |
+
var tag = reader.uint32();
|
974 |
+
switch (tag >>> 3) {
|
975 |
+
case 1: {
|
976 |
+
message.start = $root.ChatMessage.FileContent.Position.decode(reader, reader.uint32());
|
977 |
+
break;
|
978 |
+
}
|
979 |
+
case 2: {
|
980 |
+
message.end = $root.ChatMessage.FileContent.Position.decode(reader, reader.uint32());
|
981 |
+
break;
|
982 |
+
}
|
983 |
+
default:
|
984 |
+
reader.skipType(tag & 7);
|
985 |
+
break;
|
986 |
+
}
|
987 |
+
}
|
988 |
+
return message;
|
989 |
+
};
|
990 |
+
|
991 |
+
/**
|
992 |
+
* Decodes a Range message from the specified reader or buffer, length delimited.
|
993 |
+
* @function decodeDelimited
|
994 |
+
* @memberof ChatMessage.FileContent.Range
|
995 |
+
* @static
|
996 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
997 |
+
* @returns {ChatMessage.FileContent.Range} Range
|
998 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
999 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1000 |
+
*/
|
1001 |
+
Range.decodeDelimited = function decodeDelimited(reader) {
|
1002 |
+
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
|
1003 |
+
return this.decode(reader, reader.uint32());
|
1004 |
+
};
|
1005 |
+
|
1006 |
+
/**
|
1007 |
+
* Verifies a Range message.
|
1008 |
+
* @function verify
|
1009 |
+
* @memberof ChatMessage.FileContent.Range
|
1010 |
+
* @static
|
1011 |
+
* @param {Object.<string,*>} message Plain object to verify
|
1012 |
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
1013 |
+
*/
|
1014 |
+
Range.verify = function verify(message) {
|
1015 |
+
if (typeof message !== 'object' || message === null) return 'object expected';
|
1016 |
+
if (message.start != null && message.hasOwnProperty('start')) {
|
1017 |
+
var error = $root.ChatMessage.FileContent.Position.verify(message.start);
|
1018 |
+
if (error) return 'start.' + error;
|
1019 |
+
}
|
1020 |
+
if (message.end != null && message.hasOwnProperty('end')) {
|
1021 |
+
var error = $root.ChatMessage.FileContent.Position.verify(message.end);
|
1022 |
+
if (error) return 'end.' + error;
|
1023 |
+
}
|
1024 |
+
return null;
|
1025 |
+
};
|
1026 |
+
|
1027 |
+
/**
|
1028 |
+
* Creates a Range message from a plain object. Also converts values to their respective internal types.
|
1029 |
+
* @function fromObject
|
1030 |
+
* @memberof ChatMessage.FileContent.Range
|
1031 |
+
* @static
|
1032 |
+
* @param {Object.<string,*>} object Plain object
|
1033 |
+
* @returns {ChatMessage.FileContent.Range} Range
|
1034 |
+
*/
|
1035 |
+
Range.fromObject = function fromObject(object) {
|
1036 |
+
if (object instanceof $root.ChatMessage.FileContent.Range) return object;
|
1037 |
+
var message = new $root.ChatMessage.FileContent.Range();
|
1038 |
+
if (object.start != null) {
|
1039 |
+
if (typeof object.start !== 'object') throw TypeError('.ChatMessage.FileContent.Range.start: object expected');
|
1040 |
+
message.start = $root.ChatMessage.FileContent.Position.fromObject(object.start);
|
1041 |
+
}
|
1042 |
+
if (object.end != null) {
|
1043 |
+
if (typeof object.end !== 'object') throw TypeError('.ChatMessage.FileContent.Range.end: object expected');
|
1044 |
+
message.end = $root.ChatMessage.FileContent.Position.fromObject(object.end);
|
1045 |
+
}
|
1046 |
+
return message;
|
1047 |
+
};
|
1048 |
+
|
1049 |
+
/**
|
1050 |
+
* Creates a plain object from a Range message. Also converts values to other types if specified.
|
1051 |
+
* @function toObject
|
1052 |
+
* @memberof ChatMessage.FileContent.Range
|
1053 |
+
* @static
|
1054 |
+
* @param {ChatMessage.FileContent.Range} message Range
|
1055 |
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
1056 |
+
* @returns {Object.<string,*>} Plain object
|
1057 |
+
*/
|
1058 |
+
Range.toObject = function toObject(message, options) {
|
1059 |
+
if (!options) options = {};
|
1060 |
+
var object = {};
|
1061 |
+
if (options.defaults) {
|
1062 |
+
object.start = null;
|
1063 |
+
object.end = null;
|
1064 |
+
}
|
1065 |
+
if (message.start != null && message.hasOwnProperty('start')) object.start = $root.ChatMessage.FileContent.Position.toObject(message.start, options);
|
1066 |
+
if (message.end != null && message.hasOwnProperty('end')) object.end = $root.ChatMessage.FileContent.Position.toObject(message.end, options);
|
1067 |
+
return object;
|
1068 |
+
};
|
1069 |
+
|
1070 |
+
/**
|
1071 |
+
* Converts this Range to JSON.
|
1072 |
+
* @function toJSON
|
1073 |
+
* @memberof ChatMessage.FileContent.Range
|
1074 |
+
* @instance
|
1075 |
+
* @returns {Object.<string,*>} JSON object
|
1076 |
+
*/
|
1077 |
+
Range.prototype.toJSON = function toJSON() {
|
1078 |
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
1079 |
+
};
|
1080 |
+
|
1081 |
+
/**
|
1082 |
+
* Gets the default type url for Range
|
1083 |
+
* @function getTypeUrl
|
1084 |
+
* @memberof ChatMessage.FileContent.Range
|
1085 |
+
* @static
|
1086 |
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
1087 |
+
* @returns {string} The default type url
|
1088 |
+
*/
|
1089 |
+
Range.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
1090 |
+
if (typeUrlPrefix === undefined) {
|
1091 |
+
typeUrlPrefix = 'type.googleapis.com';
|
1092 |
+
}
|
1093 |
+
return typeUrlPrefix + '/ChatMessage.FileContent.Range';
|
1094 |
+
};
|
1095 |
+
|
1096 |
+
return Range;
|
1097 |
+
})();
|
1098 |
+
|
1099 |
+
return FileContent;
|
1100 |
+
})();
|
1101 |
+
|
1102 |
+
ChatMessage.UserMessage = (function () {
|
1103 |
+
/**
|
1104 |
+
* Properties of a UserMessage.
|
1105 |
+
* @memberof ChatMessage
|
1106 |
+
* @interface IUserMessage
|
1107 |
+
* @property {string|null} [content] UserMessage content
|
1108 |
+
* @property {number|null} [role] UserMessage role
|
1109 |
+
* @property {string|null} [messageId] UserMessage messageId
|
1110 |
+
*/
|
1111 |
+
|
1112 |
+
/**
|
1113 |
+
* Constructs a new UserMessage.
|
1114 |
+
* @memberof ChatMessage
|
1115 |
+
* @classdesc Represents a UserMessage.
|
1116 |
+
* @implements IUserMessage
|
1117 |
+
* @constructor
|
1118 |
+
* @param {ChatMessage.IUserMessage=} [properties] Properties to set
|
1119 |
+
*/
|
1120 |
+
function UserMessage(properties) {
|
1121 |
+
if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
|
1122 |
+
}
|
1123 |
+
|
1124 |
+
/**
|
1125 |
+
* UserMessage content.
|
1126 |
+
* @member {string} content
|
1127 |
+
* @memberof ChatMessage.UserMessage
|
1128 |
+
* @instance
|
1129 |
+
*/
|
1130 |
+
UserMessage.prototype.content = '';
|
1131 |
+
|
1132 |
+
/**
|
1133 |
+
* UserMessage role.
|
1134 |
+
* @member {number} role
|
1135 |
+
* @memberof ChatMessage.UserMessage
|
1136 |
+
* @instance
|
1137 |
+
*/
|
1138 |
+
UserMessage.prototype.role = 0;
|
1139 |
+
|
1140 |
+
/**
|
1141 |
+
* UserMessage messageId.
|
1142 |
+
* @member {string} messageId
|
1143 |
+
* @memberof ChatMessage.UserMessage
|
1144 |
+
* @instance
|
1145 |
+
*/
|
1146 |
+
UserMessage.prototype.messageId = '';
|
1147 |
+
|
1148 |
+
/**
|
1149 |
+
* Creates a new UserMessage instance using the specified properties.
|
1150 |
+
* @function create
|
1151 |
+
* @memberof ChatMessage.UserMessage
|
1152 |
+
* @static
|
1153 |
+
* @param {ChatMessage.IUserMessage=} [properties] Properties to set
|
1154 |
+
* @returns {ChatMessage.UserMessage} UserMessage instance
|
1155 |
+
*/
|
1156 |
+
UserMessage.create = function create(properties) {
|
1157 |
+
return new UserMessage(properties);
|
1158 |
+
};
|
1159 |
+
|
1160 |
+
/**
|
1161 |
+
* Encodes the specified UserMessage message. Does not implicitly {@link ChatMessage.UserMessage.verify|verify} messages.
|
1162 |
+
* @function encode
|
1163 |
+
* @memberof ChatMessage.UserMessage
|
1164 |
+
* @static
|
1165 |
+
* @param {ChatMessage.IUserMessage} message UserMessage message or plain object to encode
|
1166 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
1167 |
+
* @returns {$protobuf.Writer} Writer
|
1168 |
+
*/
|
1169 |
+
UserMessage.encode = function encode(message, writer) {
|
1170 |
+
if (!writer) writer = $Writer.create();
|
1171 |
+
if (message.content != null && Object.hasOwnProperty.call(message, 'content')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.content);
|
1172 |
+
if (message.role != null && Object.hasOwnProperty.call(message, 'role')) writer.uint32(/* id 2, wireType 0 =*/ 16).int32(message.role);
|
1173 |
+
if (message.messageId != null && Object.hasOwnProperty.call(message, 'messageId')) writer.uint32(/* id 13, wireType 2 =*/ 106).string(message.messageId);
|
1174 |
+
return writer;
|
1175 |
+
};
|
1176 |
+
|
1177 |
+
/**
|
1178 |
+
* Encodes the specified UserMessage message, length delimited. Does not implicitly {@link ChatMessage.UserMessage.verify|verify} messages.
|
1179 |
+
* @function encodeDelimited
|
1180 |
+
* @memberof ChatMessage.UserMessage
|
1181 |
+
* @static
|
1182 |
+
* @param {ChatMessage.IUserMessage} message UserMessage message or plain object to encode
|
1183 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
1184 |
+
* @returns {$protobuf.Writer} Writer
|
1185 |
+
*/
|
1186 |
+
UserMessage.encodeDelimited = function encodeDelimited(message, writer) {
|
1187 |
+
return this.encode(message, writer).ldelim();
|
1188 |
+
};
|
1189 |
+
|
1190 |
+
/**
|
1191 |
+
* Decodes a UserMessage message from the specified reader or buffer.
|
1192 |
+
* @function decode
|
1193 |
+
* @memberof ChatMessage.UserMessage
|
1194 |
+
* @static
|
1195 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
1196 |
+
* @param {number} [length] Message length if known beforehand
|
1197 |
+
* @returns {ChatMessage.UserMessage} UserMessage
|
1198 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
1199 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1200 |
+
*/
|
1201 |
+
UserMessage.decode = function decode(reader, length) {
|
1202 |
+
if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
|
1203 |
+
var end = length === undefined ? reader.len : reader.pos + length,
|
1204 |
+
message = new $root.ChatMessage.UserMessage();
|
1205 |
+
while (reader.pos < end) {
|
1206 |
+
var tag = reader.uint32();
|
1207 |
+
switch (tag >>> 3) {
|
1208 |
+
case 1: {
|
1209 |
+
message.content = reader.string();
|
1210 |
+
break;
|
1211 |
+
}
|
1212 |
+
case 2: {
|
1213 |
+
message.role = reader.int32();
|
1214 |
+
break;
|
1215 |
+
}
|
1216 |
+
case 13: {
|
1217 |
+
message.messageId = reader.string();
|
1218 |
+
break;
|
1219 |
+
}
|
1220 |
+
default:
|
1221 |
+
reader.skipType(tag & 7);
|
1222 |
+
break;
|
1223 |
+
}
|
1224 |
+
}
|
1225 |
+
return message;
|
1226 |
+
};
|
1227 |
+
|
1228 |
+
/**
|
1229 |
+
* Decodes a UserMessage message from the specified reader or buffer, length delimited.
|
1230 |
+
* @function decodeDelimited
|
1231 |
+
* @memberof ChatMessage.UserMessage
|
1232 |
+
* @static
|
1233 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
1234 |
+
* @returns {ChatMessage.UserMessage} UserMessage
|
1235 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
1236 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1237 |
+
*/
|
1238 |
+
UserMessage.decodeDelimited = function decodeDelimited(reader) {
|
1239 |
+
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
|
1240 |
+
return this.decode(reader, reader.uint32());
|
1241 |
+
};
|
1242 |
+
|
1243 |
+
/**
|
1244 |
+
* Verifies a UserMessage message.
|
1245 |
+
* @function verify
|
1246 |
+
* @memberof ChatMessage.UserMessage
|
1247 |
+
* @static
|
1248 |
+
* @param {Object.<string,*>} message Plain object to verify
|
1249 |
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
1250 |
+
*/
|
1251 |
+
UserMessage.verify = function verify(message) {
|
1252 |
+
if (typeof message !== 'object' || message === null) return 'object expected';
|
1253 |
+
if (message.content != null && message.hasOwnProperty('content')) if (!$util.isString(message.content)) return 'content: string expected';
|
1254 |
+
if (message.role != null && message.hasOwnProperty('role')) if (!$util.isInteger(message.role)) return 'role: integer expected';
|
1255 |
+
if (message.messageId != null && message.hasOwnProperty('messageId')) if (!$util.isString(message.messageId)) return 'messageId: string expected';
|
1256 |
+
return null;
|
1257 |
+
};
|
1258 |
+
|
1259 |
+
/**
|
1260 |
+
* Creates a UserMessage message from a plain object. Also converts values to their respective internal types.
|
1261 |
+
* @function fromObject
|
1262 |
+
* @memberof ChatMessage.UserMessage
|
1263 |
+
* @static
|
1264 |
+
* @param {Object.<string,*>} object Plain object
|
1265 |
+
* @returns {ChatMessage.UserMessage} UserMessage
|
1266 |
+
*/
|
1267 |
+
UserMessage.fromObject = function fromObject(object) {
|
1268 |
+
if (object instanceof $root.ChatMessage.UserMessage) return object;
|
1269 |
+
var message = new $root.ChatMessage.UserMessage();
|
1270 |
+
if (object.content != null) message.content = String(object.content);
|
1271 |
+
if (object.role != null) message.role = object.role | 0;
|
1272 |
+
if (object.messageId != null) message.messageId = String(object.messageId);
|
1273 |
+
return message;
|
1274 |
+
};
|
1275 |
+
|
1276 |
+
/**
|
1277 |
+
* Creates a plain object from a UserMessage message. Also converts values to other types if specified.
|
1278 |
+
* @function toObject
|
1279 |
+
* @memberof ChatMessage.UserMessage
|
1280 |
+
* @static
|
1281 |
+
* @param {ChatMessage.UserMessage} message UserMessage
|
1282 |
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
1283 |
+
* @returns {Object.<string,*>} Plain object
|
1284 |
+
*/
|
1285 |
+
UserMessage.toObject = function toObject(message, options) {
|
1286 |
+
if (!options) options = {};
|
1287 |
+
var object = {};
|
1288 |
+
if (options.defaults) {
|
1289 |
+
object.content = '';
|
1290 |
+
object.role = 0;
|
1291 |
+
object.messageId = '';
|
1292 |
+
}
|
1293 |
+
if (message.content != null && message.hasOwnProperty('content')) object.content = message.content;
|
1294 |
+
if (message.role != null && message.hasOwnProperty('role')) object.role = message.role;
|
1295 |
+
if (message.messageId != null && message.hasOwnProperty('messageId')) object.messageId = message.messageId;
|
1296 |
+
return object;
|
1297 |
+
};
|
1298 |
+
|
1299 |
+
/**
|
1300 |
+
* Converts this UserMessage to JSON.
|
1301 |
+
* @function toJSON
|
1302 |
+
* @memberof ChatMessage.UserMessage
|
1303 |
+
* @instance
|
1304 |
+
* @returns {Object.<string,*>} JSON object
|
1305 |
+
*/
|
1306 |
+
UserMessage.prototype.toJSON = function toJSON() {
|
1307 |
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
1308 |
+
};
|
1309 |
+
|
1310 |
+
/**
|
1311 |
+
* Gets the default type url for UserMessage
|
1312 |
+
* @function getTypeUrl
|
1313 |
+
* @memberof ChatMessage.UserMessage
|
1314 |
+
* @static
|
1315 |
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
1316 |
+
* @returns {string} The default type url
|
1317 |
+
*/
|
1318 |
+
UserMessage.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
1319 |
+
if (typeUrlPrefix === undefined) {
|
1320 |
+
typeUrlPrefix = 'type.googleapis.com';
|
1321 |
+
}
|
1322 |
+
return typeUrlPrefix + '/ChatMessage.UserMessage';
|
1323 |
+
};
|
1324 |
+
|
1325 |
+
return UserMessage;
|
1326 |
+
})();
|
1327 |
+
|
1328 |
+
ChatMessage.Instructions = (function () {
|
1329 |
+
/**
|
1330 |
+
* Properties of an Instructions.
|
1331 |
+
* @memberof ChatMessage
|
1332 |
+
* @interface IInstructions
|
1333 |
+
* @property {string|null} [instruction] Instructions instruction
|
1334 |
+
*/
|
1335 |
+
|
1336 |
+
/**
|
1337 |
+
* Constructs a new Instructions.
|
1338 |
+
* @memberof ChatMessage
|
1339 |
+
* @classdesc Represents an Instructions.
|
1340 |
+
* @implements IInstructions
|
1341 |
+
* @constructor
|
1342 |
+
* @param {ChatMessage.IInstructions=} [properties] Properties to set
|
1343 |
+
*/
|
1344 |
+
function Instructions(properties) {
|
1345 |
+
if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
|
1346 |
+
}
|
1347 |
+
|
1348 |
+
/**
|
1349 |
+
* Instructions instruction.
|
1350 |
+
* @member {string} instruction
|
1351 |
+
* @memberof ChatMessage.Instructions
|
1352 |
+
* @instance
|
1353 |
+
*/
|
1354 |
+
Instructions.prototype.instruction = '';
|
1355 |
+
|
1356 |
+
/**
|
1357 |
+
* Creates a new Instructions instance using the specified properties.
|
1358 |
+
* @function create
|
1359 |
+
* @memberof ChatMessage.Instructions
|
1360 |
+
* @static
|
1361 |
+
* @param {ChatMessage.IInstructions=} [properties] Properties to set
|
1362 |
+
* @returns {ChatMessage.Instructions} Instructions instance
|
1363 |
+
*/
|
1364 |
+
Instructions.create = function create(properties) {
|
1365 |
+
return new Instructions(properties);
|
1366 |
+
};
|
1367 |
+
|
1368 |
+
/**
|
1369 |
+
* Encodes the specified Instructions message. Does not implicitly {@link ChatMessage.Instructions.verify|verify} messages.
|
1370 |
+
* @function encode
|
1371 |
+
* @memberof ChatMessage.Instructions
|
1372 |
+
* @static
|
1373 |
+
* @param {ChatMessage.IInstructions} message Instructions message or plain object to encode
|
1374 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
1375 |
+
* @returns {$protobuf.Writer} Writer
|
1376 |
+
*/
|
1377 |
+
Instructions.encode = function encode(message, writer) {
|
1378 |
+
if (!writer) writer = $Writer.create();
|
1379 |
+
if (message.instruction != null && Object.hasOwnProperty.call(message, 'instruction')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.instruction);
|
1380 |
+
return writer;
|
1381 |
+
};
|
1382 |
+
|
1383 |
+
/**
|
1384 |
+
* Encodes the specified Instructions message, length delimited. Does not implicitly {@link ChatMessage.Instructions.verify|verify} messages.
|
1385 |
+
* @function encodeDelimited
|
1386 |
+
* @memberof ChatMessage.Instructions
|
1387 |
+
* @static
|
1388 |
+
* @param {ChatMessage.IInstructions} message Instructions message or plain object to encode
|
1389 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
1390 |
+
* @returns {$protobuf.Writer} Writer
|
1391 |
+
*/
|
1392 |
+
Instructions.encodeDelimited = function encodeDelimited(message, writer) {
|
1393 |
+
return this.encode(message, writer).ldelim();
|
1394 |
+
};
|
1395 |
+
|
1396 |
+
/**
|
1397 |
+
* Decodes an Instructions message from the specified reader or buffer.
|
1398 |
+
* @function decode
|
1399 |
+
* @memberof ChatMessage.Instructions
|
1400 |
+
* @static
|
1401 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
1402 |
+
* @param {number} [length] Message length if known beforehand
|
1403 |
+
* @returns {ChatMessage.Instructions} Instructions
|
1404 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
1405 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1406 |
+
*/
|
1407 |
+
Instructions.decode = function decode(reader, length) {
|
1408 |
+
if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
|
1409 |
+
var end = length === undefined ? reader.len : reader.pos + length,
|
1410 |
+
message = new $root.ChatMessage.Instructions();
|
1411 |
+
while (reader.pos < end) {
|
1412 |
+
var tag = reader.uint32();
|
1413 |
+
switch (tag >>> 3) {
|
1414 |
+
case 1: {
|
1415 |
+
message.instruction = reader.string();
|
1416 |
+
break;
|
1417 |
+
}
|
1418 |
+
default:
|
1419 |
+
reader.skipType(tag & 7);
|
1420 |
+
break;
|
1421 |
+
}
|
1422 |
+
}
|
1423 |
+
return message;
|
1424 |
+
};
|
1425 |
+
|
1426 |
+
/**
|
1427 |
+
* Decodes an Instructions message from the specified reader or buffer, length delimited.
|
1428 |
+
* @function decodeDelimited
|
1429 |
+
* @memberof ChatMessage.Instructions
|
1430 |
+
* @static
|
1431 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
1432 |
+
* @returns {ChatMessage.Instructions} Instructions
|
1433 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
1434 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1435 |
+
*/
|
1436 |
+
Instructions.decodeDelimited = function decodeDelimited(reader) {
|
1437 |
+
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
|
1438 |
+
return this.decode(reader, reader.uint32());
|
1439 |
+
};
|
1440 |
+
|
1441 |
+
/**
|
1442 |
+
* Verifies an Instructions message.
|
1443 |
+
* @function verify
|
1444 |
+
* @memberof ChatMessage.Instructions
|
1445 |
+
* @static
|
1446 |
+
* @param {Object.<string,*>} message Plain object to verify
|
1447 |
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
1448 |
+
*/
|
1449 |
+
Instructions.verify = function verify(message) {
|
1450 |
+
if (typeof message !== 'object' || message === null) return 'object expected';
|
1451 |
+
if (message.instruction != null && message.hasOwnProperty('instruction')) if (!$util.isString(message.instruction)) return 'instruction: string expected';
|
1452 |
+
return null;
|
1453 |
+
};
|
1454 |
+
|
1455 |
+
/**
|
1456 |
+
* Creates an Instructions message from a plain object. Also converts values to their respective internal types.
|
1457 |
+
* @function fromObject
|
1458 |
+
* @memberof ChatMessage.Instructions
|
1459 |
+
* @static
|
1460 |
+
* @param {Object.<string,*>} object Plain object
|
1461 |
+
* @returns {ChatMessage.Instructions} Instructions
|
1462 |
+
*/
|
1463 |
+
Instructions.fromObject = function fromObject(object) {
|
1464 |
+
if (object instanceof $root.ChatMessage.Instructions) return object;
|
1465 |
+
var message = new $root.ChatMessage.Instructions();
|
1466 |
+
if (object.instruction != null) message.instruction = String(object.instruction);
|
1467 |
+
return message;
|
1468 |
+
};
|
1469 |
+
|
1470 |
+
/**
|
1471 |
+
* Creates a plain object from an Instructions message. Also converts values to other types if specified.
|
1472 |
+
* @function toObject
|
1473 |
+
* @memberof ChatMessage.Instructions
|
1474 |
+
* @static
|
1475 |
+
* @param {ChatMessage.Instructions} message Instructions
|
1476 |
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
1477 |
+
* @returns {Object.<string,*>} Plain object
|
1478 |
+
*/
|
1479 |
+
Instructions.toObject = function toObject(message, options) {
|
1480 |
+
if (!options) options = {};
|
1481 |
+
var object = {};
|
1482 |
+
if (options.defaults) object.instruction = '';
|
1483 |
+
if (message.instruction != null && message.hasOwnProperty('instruction')) object.instruction = message.instruction;
|
1484 |
+
return object;
|
1485 |
+
};
|
1486 |
+
|
1487 |
+
/**
|
1488 |
+
* Converts this Instructions to JSON.
|
1489 |
+
* @function toJSON
|
1490 |
+
* @memberof ChatMessage.Instructions
|
1491 |
+
* @instance
|
1492 |
+
* @returns {Object.<string,*>} JSON object
|
1493 |
+
*/
|
1494 |
+
Instructions.prototype.toJSON = function toJSON() {
|
1495 |
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
1496 |
+
};
|
1497 |
+
|
1498 |
+
/**
|
1499 |
+
* Gets the default type url for Instructions
|
1500 |
+
* @function getTypeUrl
|
1501 |
+
* @memberof ChatMessage.Instructions
|
1502 |
+
* @static
|
1503 |
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
1504 |
+
* @returns {string} The default type url
|
1505 |
+
*/
|
1506 |
+
Instructions.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
1507 |
+
if (typeUrlPrefix === undefined) {
|
1508 |
+
typeUrlPrefix = 'type.googleapis.com';
|
1509 |
+
}
|
1510 |
+
return typeUrlPrefix + '/ChatMessage.Instructions';
|
1511 |
+
};
|
1512 |
+
|
1513 |
+
return Instructions;
|
1514 |
+
})();
|
1515 |
+
|
1516 |
+
ChatMessage.Model = (function () {
|
1517 |
+
/**
|
1518 |
+
* Properties of a Model.
|
1519 |
+
* @memberof ChatMessage
|
1520 |
+
* @interface IModel
|
1521 |
+
* @property {string|null} [name] Model name
|
1522 |
+
* @property {string|null} [empty] Model empty
|
1523 |
+
*/
|
1524 |
+
|
1525 |
+
/**
|
1526 |
+
* Constructs a new Model.
|
1527 |
+
* @memberof ChatMessage
|
1528 |
+
* @classdesc Represents a Model.
|
1529 |
+
* @implements IModel
|
1530 |
+
* @constructor
|
1531 |
+
* @param {ChatMessage.IModel=} [properties] Properties to set
|
1532 |
+
*/
|
1533 |
+
function Model(properties) {
|
1534 |
+
if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
|
1535 |
+
}
|
1536 |
+
|
1537 |
+
/**
|
1538 |
+
* Model name.
|
1539 |
+
* @member {string} name
|
1540 |
+
* @memberof ChatMessage.Model
|
1541 |
+
* @instance
|
1542 |
+
*/
|
1543 |
+
Model.prototype.name = '';
|
1544 |
+
|
1545 |
+
/**
|
1546 |
+
* Model empty.
|
1547 |
+
* @member {string} empty
|
1548 |
+
* @memberof ChatMessage.Model
|
1549 |
+
* @instance
|
1550 |
+
*/
|
1551 |
+
Model.prototype.empty = '';
|
1552 |
+
|
1553 |
+
/**
|
1554 |
+
* Creates a new Model instance using the specified properties.
|
1555 |
+
* @function create
|
1556 |
+
* @memberof ChatMessage.Model
|
1557 |
+
* @static
|
1558 |
+
* @param {ChatMessage.IModel=} [properties] Properties to set
|
1559 |
+
* @returns {ChatMessage.Model} Model instance
|
1560 |
+
*/
|
1561 |
+
Model.create = function create(properties) {
|
1562 |
+
return new Model(properties);
|
1563 |
+
};
|
1564 |
+
|
1565 |
+
/**
|
1566 |
+
* Encodes the specified Model message. Does not implicitly {@link ChatMessage.Model.verify|verify} messages.
|
1567 |
+
* @function encode
|
1568 |
+
* @memberof ChatMessage.Model
|
1569 |
+
* @static
|
1570 |
+
* @param {ChatMessage.IModel} message Model message or plain object to encode
|
1571 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
1572 |
+
* @returns {$protobuf.Writer} Writer
|
1573 |
+
*/
|
1574 |
+
Model.encode = function encode(message, writer) {
|
1575 |
+
if (!writer) writer = $Writer.create();
|
1576 |
+
if (message.name != null && Object.hasOwnProperty.call(message, 'name')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.name);
|
1577 |
+
if (message.empty != null && Object.hasOwnProperty.call(message, 'empty')) writer.uint32(/* id 4, wireType 2 =*/ 34).string(message.empty);
|
1578 |
+
return writer;
|
1579 |
+
};
|
1580 |
+
|
1581 |
+
/**
|
1582 |
+
* Encodes the specified Model message, length delimited. Does not implicitly {@link ChatMessage.Model.verify|verify} messages.
|
1583 |
+
* @function encodeDelimited
|
1584 |
+
* @memberof ChatMessage.Model
|
1585 |
+
* @static
|
1586 |
+
* @param {ChatMessage.IModel} message Model message or plain object to encode
|
1587 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
1588 |
+
* @returns {$protobuf.Writer} Writer
|
1589 |
+
*/
|
1590 |
+
Model.encodeDelimited = function encodeDelimited(message, writer) {
|
1591 |
+
return this.encode(message, writer).ldelim();
|
1592 |
+
};
|
1593 |
+
|
1594 |
+
/**
|
1595 |
+
* Decodes a Model message from the specified reader or buffer.
|
1596 |
+
* @function decode
|
1597 |
+
* @memberof ChatMessage.Model
|
1598 |
+
* @static
|
1599 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
1600 |
+
* @param {number} [length] Message length if known beforehand
|
1601 |
+
* @returns {ChatMessage.Model} Model
|
1602 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
1603 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1604 |
+
*/
|
1605 |
+
Model.decode = function decode(reader, length) {
|
1606 |
+
if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
|
1607 |
+
var end = length === undefined ? reader.len : reader.pos + length,
|
1608 |
+
message = new $root.ChatMessage.Model();
|
1609 |
+
while (reader.pos < end) {
|
1610 |
+
var tag = reader.uint32();
|
1611 |
+
switch (tag >>> 3) {
|
1612 |
+
case 1: {
|
1613 |
+
message.name = reader.string();
|
1614 |
+
break;
|
1615 |
+
}
|
1616 |
+
case 4: {
|
1617 |
+
message.empty = reader.string();
|
1618 |
+
break;
|
1619 |
+
}
|
1620 |
+
default:
|
1621 |
+
reader.skipType(tag & 7);
|
1622 |
+
break;
|
1623 |
+
}
|
1624 |
+
}
|
1625 |
+
return message;
|
1626 |
+
};
|
1627 |
+
|
1628 |
+
/**
|
1629 |
+
* Decodes a Model message from the specified reader or buffer, length delimited.
|
1630 |
+
* @function decodeDelimited
|
1631 |
+
* @memberof ChatMessage.Model
|
1632 |
+
* @static
|
1633 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
1634 |
+
* @returns {ChatMessage.Model} Model
|
1635 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
1636 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1637 |
+
*/
|
1638 |
+
Model.decodeDelimited = function decodeDelimited(reader) {
|
1639 |
+
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
|
1640 |
+
return this.decode(reader, reader.uint32());
|
1641 |
+
};
|
1642 |
+
|
1643 |
+
/**
|
1644 |
+
* Verifies a Model message.
|
1645 |
+
* @function verify
|
1646 |
+
* @memberof ChatMessage.Model
|
1647 |
+
* @static
|
1648 |
+
* @param {Object.<string,*>} message Plain object to verify
|
1649 |
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
1650 |
+
*/
|
1651 |
+
Model.verify = function verify(message) {
|
1652 |
+
if (typeof message !== 'object' || message === null) return 'object expected';
|
1653 |
+
if (message.name != null && message.hasOwnProperty('name')) if (!$util.isString(message.name)) return 'name: string expected';
|
1654 |
+
if (message.empty != null && message.hasOwnProperty('empty')) if (!$util.isString(message.empty)) return 'empty: string expected';
|
1655 |
+
return null;
|
1656 |
+
};
|
1657 |
+
|
1658 |
+
/**
|
1659 |
+
* Creates a Model message from a plain object. Also converts values to their respective internal types.
|
1660 |
+
* @function fromObject
|
1661 |
+
* @memberof ChatMessage.Model
|
1662 |
+
* @static
|
1663 |
+
* @param {Object.<string,*>} object Plain object
|
1664 |
+
* @returns {ChatMessage.Model} Model
|
1665 |
+
*/
|
1666 |
+
Model.fromObject = function fromObject(object) {
|
1667 |
+
if (object instanceof $root.ChatMessage.Model) return object;
|
1668 |
+
var message = new $root.ChatMessage.Model();
|
1669 |
+
if (object.name != null) message.name = String(object.name);
|
1670 |
+
if (object.empty != null) message.empty = String(object.empty);
|
1671 |
+
return message;
|
1672 |
+
};
|
1673 |
+
|
1674 |
+
/**
|
1675 |
+
* Creates a plain object from a Model message. Also converts values to other types if specified.
|
1676 |
+
* @function toObject
|
1677 |
+
* @memberof ChatMessage.Model
|
1678 |
+
* @static
|
1679 |
+
* @param {ChatMessage.Model} message Model
|
1680 |
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
1681 |
+
* @returns {Object.<string,*>} Plain object
|
1682 |
+
*/
|
1683 |
+
Model.toObject = function toObject(message, options) {
|
1684 |
+
if (!options) options = {};
|
1685 |
+
var object = {};
|
1686 |
+
if (options.defaults) {
|
1687 |
+
object.name = '';
|
1688 |
+
object.empty = '';
|
1689 |
+
}
|
1690 |
+
if (message.name != null && message.hasOwnProperty('name')) object.name = message.name;
|
1691 |
+
if (message.empty != null && message.hasOwnProperty('empty')) object.empty = message.empty;
|
1692 |
+
return object;
|
1693 |
+
};
|
1694 |
+
|
1695 |
+
/**
|
1696 |
+
* Converts this Model to JSON.
|
1697 |
+
* @function toJSON
|
1698 |
+
* @memberof ChatMessage.Model
|
1699 |
+
* @instance
|
1700 |
+
* @returns {Object.<string,*>} JSON object
|
1701 |
+
*/
|
1702 |
+
Model.prototype.toJSON = function toJSON() {
|
1703 |
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
1704 |
+
};
|
1705 |
+
|
1706 |
+
/**
|
1707 |
+
* Gets the default type url for Model
|
1708 |
+
* @function getTypeUrl
|
1709 |
+
* @memberof ChatMessage.Model
|
1710 |
+
* @static
|
1711 |
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
1712 |
+
* @returns {string} The default type url
|
1713 |
+
*/
|
1714 |
+
Model.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
1715 |
+
if (typeUrlPrefix === undefined) {
|
1716 |
+
typeUrlPrefix = 'type.googleapis.com';
|
1717 |
+
}
|
1718 |
+
return typeUrlPrefix + '/ChatMessage.Model';
|
1719 |
+
};
|
1720 |
+
|
1721 |
+
return Model;
|
1722 |
+
})();
|
1723 |
+
|
1724 |
+
return ChatMessage;
|
1725 |
+
})();
|
1726 |
+
|
1727 |
+
$root.ResMessage = (function () {
|
1728 |
+
/**
|
1729 |
+
* Properties of a ResMessage.
|
1730 |
+
* @exports IResMessage
|
1731 |
+
* @interface IResMessage
|
1732 |
+
* @property {string|null} [msg] ResMessage msg
|
1733 |
+
*/
|
1734 |
+
|
1735 |
+
/**
|
1736 |
+
* Constructs a new ResMessage.
|
1737 |
+
* @exports ResMessage
|
1738 |
+
* @classdesc Represents a ResMessage.
|
1739 |
+
* @implements IResMessage
|
1740 |
+
* @constructor
|
1741 |
+
* @param {IResMessage=} [properties] Properties to set
|
1742 |
+
*/
|
1743 |
+
function ResMessage(properties) {
|
1744 |
+
if (properties) for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
|
1745 |
+
}
|
1746 |
+
|
1747 |
+
/**
|
1748 |
+
* ResMessage msg.
|
1749 |
+
* @member {string} msg
|
1750 |
+
* @memberof ResMessage
|
1751 |
+
* @instance
|
1752 |
+
*/
|
1753 |
+
ResMessage.prototype.msg = '';
|
1754 |
+
|
1755 |
+
/**
|
1756 |
+
* Creates a new ResMessage instance using the specified properties.
|
1757 |
+
* @function create
|
1758 |
+
* @memberof ResMessage
|
1759 |
+
* @static
|
1760 |
+
* @param {IResMessage=} [properties] Properties to set
|
1761 |
+
* @returns {ResMessage} ResMessage instance
|
1762 |
+
*/
|
1763 |
+
ResMessage.create = function create(properties) {
|
1764 |
+
return new ResMessage(properties);
|
1765 |
+
};
|
1766 |
+
|
1767 |
+
/**
|
1768 |
+
* Encodes the specified ResMessage message. Does not implicitly {@link ResMessage.verify|verify} messages.
|
1769 |
+
* @function encode
|
1770 |
+
* @memberof ResMessage
|
1771 |
+
* @static
|
1772 |
+
* @param {IResMessage} message ResMessage message or plain object to encode
|
1773 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
1774 |
+
* @returns {$protobuf.Writer} Writer
|
1775 |
+
*/
|
1776 |
+
ResMessage.encode = function encode(message, writer) {
|
1777 |
+
if (!writer) writer = $Writer.create();
|
1778 |
+
if (message.msg != null && Object.hasOwnProperty.call(message, 'msg')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.msg);
|
1779 |
+
return writer;
|
1780 |
+
};
|
1781 |
+
|
1782 |
+
/**
|
1783 |
+
* Encodes the specified ResMessage message, length delimited. Does not implicitly {@link ResMessage.verify|verify} messages.
|
1784 |
+
* @function encodeDelimited
|
1785 |
+
* @memberof ResMessage
|
1786 |
+
* @static
|
1787 |
+
* @param {IResMessage} message ResMessage message or plain object to encode
|
1788 |
+
* @param {$protobuf.Writer} [writer] Writer to encode to
|
1789 |
+
* @returns {$protobuf.Writer} Writer
|
1790 |
+
*/
|
1791 |
+
ResMessage.encodeDelimited = function encodeDelimited(message, writer) {
|
1792 |
+
return this.encode(message, writer).ldelim();
|
1793 |
+
};
|
1794 |
+
|
1795 |
+
/**
|
1796 |
+
* Decodes a ResMessage message from the specified reader or buffer.
|
1797 |
+
* @function decode
|
1798 |
+
* @memberof ResMessage
|
1799 |
+
* @static
|
1800 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
1801 |
+
* @param {number} [length] Message length if known beforehand
|
1802 |
+
* @returns {ResMessage} ResMessage
|
1803 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
1804 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1805 |
+
*/
|
1806 |
+
ResMessage.decode = function decode(reader, length) {
|
1807 |
+
if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
|
1808 |
+
var end = length === undefined ? reader.len : reader.pos + length,
|
1809 |
+
message = new $root.ResMessage();
|
1810 |
+
while (reader.pos < end) {
|
1811 |
+
var tag = reader.uint32();
|
1812 |
+
switch (tag >>> 3) {
|
1813 |
+
case 1: {
|
1814 |
+
message.msg = reader.string();
|
1815 |
+
break;
|
1816 |
+
}
|
1817 |
+
default:
|
1818 |
+
reader.skipType(tag & 7);
|
1819 |
+
break;
|
1820 |
+
}
|
1821 |
+
}
|
1822 |
+
return message;
|
1823 |
+
};
|
1824 |
+
|
1825 |
+
/**
|
1826 |
+
* Decodes a ResMessage message from the specified reader or buffer, length delimited.
|
1827 |
+
* @function decodeDelimited
|
1828 |
+
* @memberof ResMessage
|
1829 |
+
* @static
|
1830 |
+
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
|
1831 |
+
* @returns {ResMessage} ResMessage
|
1832 |
+
* @throws {Error} If the payload is not a reader or valid buffer
|
1833 |
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
1834 |
+
*/
|
1835 |
+
ResMessage.decodeDelimited = function decodeDelimited(reader) {
|
1836 |
+
if (!(reader instanceof $Reader)) reader = new $Reader(reader);
|
1837 |
+
return this.decode(reader, reader.uint32());
|
1838 |
+
};
|
1839 |
+
|
1840 |
+
/**
|
1841 |
+
* Verifies a ResMessage message.
|
1842 |
+
* @function verify
|
1843 |
+
* @memberof ResMessage
|
1844 |
+
* @static
|
1845 |
+
* @param {Object.<string,*>} message Plain object to verify
|
1846 |
+
* @returns {string|null} `null` if valid, otherwise the reason why it is not
|
1847 |
+
*/
|
1848 |
+
ResMessage.verify = function verify(message) {
|
1849 |
+
if (typeof message !== 'object' || message === null) return 'object expected';
|
1850 |
+
if (message.msg != null && message.hasOwnProperty('msg')) if (!$util.isString(message.msg)) return 'msg: string expected';
|
1851 |
+
return null;
|
1852 |
+
};
|
1853 |
+
|
1854 |
+
/**
|
1855 |
+
* Creates a ResMessage message from a plain object. Also converts values to their respective internal types.
|
1856 |
+
* @function fromObject
|
1857 |
+
* @memberof ResMessage
|
1858 |
+
* @static
|
1859 |
+
* @param {Object.<string,*>} object Plain object
|
1860 |
+
* @returns {ResMessage} ResMessage
|
1861 |
+
*/
|
1862 |
+
ResMessage.fromObject = function fromObject(object) {
|
1863 |
+
if (object instanceof $root.ResMessage) return object;
|
1864 |
+
var message = new $root.ResMessage();
|
1865 |
+
if (object.msg != null) message.msg = String(object.msg);
|
1866 |
+
return message;
|
1867 |
+
};
|
1868 |
+
|
1869 |
+
/**
|
1870 |
+
* Creates a plain object from a ResMessage message. Also converts values to other types if specified.
|
1871 |
+
* @function toObject
|
1872 |
+
* @memberof ResMessage
|
1873 |
+
* @static
|
1874 |
+
* @param {ResMessage} message ResMessage
|
1875 |
+
* @param {$protobuf.IConversionOptions} [options] Conversion options
|
1876 |
+
* @returns {Object.<string,*>} Plain object
|
1877 |
+
*/
|
1878 |
+
ResMessage.toObject = function toObject(message, options) {
|
1879 |
+
if (!options) options = {};
|
1880 |
+
var object = {};
|
1881 |
+
if (options.defaults) object.msg = '';
|
1882 |
+
if (message.msg != null && message.hasOwnProperty('msg')) object.msg = message.msg;
|
1883 |
+
return object;
|
1884 |
+
};
|
1885 |
+
|
1886 |
+
/**
|
1887 |
+
* Converts this ResMessage to JSON.
|
1888 |
+
* @function toJSON
|
1889 |
+
* @memberof ResMessage
|
1890 |
+
* @instance
|
1891 |
+
* @returns {Object.<string,*>} JSON object
|
1892 |
+
*/
|
1893 |
+
ResMessage.prototype.toJSON = function toJSON() {
|
1894 |
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
1895 |
+
};
|
1896 |
+
|
1897 |
+
/**
|
1898 |
+
* Gets the default type url for ResMessage
|
1899 |
+
* @function getTypeUrl
|
1900 |
+
* @memberof ResMessage
|
1901 |
+
* @static
|
1902 |
+
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
|
1903 |
+
* @returns {string} The default type url
|
1904 |
+
*/
|
1905 |
+
ResMessage.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
|
1906 |
+
if (typeUrlPrefix === undefined) {
|
1907 |
+
typeUrlPrefix = 'type.googleapis.com';
|
1908 |
+
}
|
1909 |
+
return typeUrlPrefix + '/ResMessage';
|
1910 |
+
};
|
1911 |
+
|
1912 |
+
return ResMessage;
|
1913 |
+
})();
|
1914 |
+
|
1915 |
+
module.exports = $root;
|
src/message.proto
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
syntax = "proto3";
|
2 |
+
|
3 |
+
message ChatMessage {
|
4 |
+
message FileContent {
|
5 |
+
message Position {
|
6 |
+
int32 line = 1;
|
7 |
+
int32 column = 2;
|
8 |
+
}
|
9 |
+
message Range {
|
10 |
+
Position start = 1;
|
11 |
+
Position end = 2;
|
12 |
+
}
|
13 |
+
|
14 |
+
string filename = 1;
|
15 |
+
string content = 2;
|
16 |
+
Position position = 3;
|
17 |
+
string language = 5;
|
18 |
+
Range range = 6;
|
19 |
+
int32 length = 8;
|
20 |
+
int32 type = 9;
|
21 |
+
int32 error_code = 11;
|
22 |
+
}
|
23 |
+
|
24 |
+
message UserMessage {
|
25 |
+
string content = 1;
|
26 |
+
int32 role = 2;
|
27 |
+
string message_id = 13;
|
28 |
+
}
|
29 |
+
|
30 |
+
message Instructions {
|
31 |
+
string instruction = 1;
|
32 |
+
}
|
33 |
+
|
34 |
+
message Model {
|
35 |
+
string name = 1;
|
36 |
+
string empty = 4;
|
37 |
+
}
|
38 |
+
|
39 |
+
// repeated FileContent files = 1;
|
40 |
+
repeated UserMessage messages = 2;
|
41 |
+
Instructions instructions = 4;
|
42 |
+
string projectPath = 5;
|
43 |
+
Model model = 7;
|
44 |
+
string requestId = 9;
|
45 |
+
string summary = 11; // 或许是空的,描述会话做了什么事情,但是不是标题 或许可以当作额外的设定来用
|
46 |
+
string conversationId = 15; // 又来一个uuid
|
47 |
+
}
|
48 |
+
|
49 |
+
message ResMessage {
|
50 |
+
string msg = 1;
|
51 |
+
}
|
src/utils.js
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const { v4: uuidv4 } = require('uuid');
|
2 |
+
const zlib = require('zlib');
|
3 |
+
const $root = require('./message.js');
|
4 |
+
|
5 |
+
const regex = /<\|BEGIN_SYSTEM\|>.*?<\|END_SYSTEM\|>.*?<\|BEGIN_USER\|>.*?<\|END_USER\|>/s;
|
6 |
+
|
7 |
+
async function stringToHex(messages, modelName) {
|
8 |
+
const formattedMessages = messages.map((msg) => ({
|
9 |
+
...msg,
|
10 |
+
role: msg.role === 'user' ? 1 : 2,
|
11 |
+
message_id: uuidv4(),
|
12 |
+
}));
|
13 |
+
|
14 |
+
const message = {
|
15 |
+
messages: formattedMessages,
|
16 |
+
instructions: {
|
17 |
+
instruction: 'Always respond in 中文',
|
18 |
+
},
|
19 |
+
projectPath: '/path/to/project',
|
20 |
+
model: {
|
21 |
+
name: modelName,
|
22 |
+
empty: '',
|
23 |
+
},
|
24 |
+
requestId: uuidv4(),
|
25 |
+
summary: '',
|
26 |
+
conversationId: uuidv4(),
|
27 |
+
};
|
28 |
+
const errMsg = $root.ChatMessage.verify(message);
|
29 |
+
if (errMsg) throw Error(errMsg);
|
30 |
+
|
31 |
+
const messageInstance = $root.ChatMessage.create(message);
|
32 |
+
|
33 |
+
const buffer = $root.ChatMessage.encode(messageInstance).finish();
|
34 |
+
const hexString = (buffer.length.toString(16).padStart(10, '0') + buffer.toString('hex')).toUpperCase();
|
35 |
+
|
36 |
+
return Buffer.from(hexString, 'hex');
|
37 |
+
}
|
38 |
+
|
39 |
+
async function chunkToUtf8String(chunk) {
|
40 |
+
try {
|
41 |
+
let hex = Buffer.from(chunk).toString('hex');
|
42 |
+
|
43 |
+
let offset = 0;
|
44 |
+
let results = [];
|
45 |
+
|
46 |
+
while (offset < hex.length) {
|
47 |
+
if (offset + 10 > hex.length) break;
|
48 |
+
|
49 |
+
const dataLength = parseInt(hex.slice(offset, offset + 10), 16);
|
50 |
+
offset += 10;
|
51 |
+
|
52 |
+
if (offset + dataLength * 2 > hex.length) break;
|
53 |
+
|
54 |
+
const messageHex = hex.slice(offset, offset + dataLength * 2);
|
55 |
+
offset += dataLength * 2;
|
56 |
+
|
57 |
+
const messageBuffer = Buffer.from(messageHex, 'hex');
|
58 |
+
const message = $root.ResMessage.decode(messageBuffer);
|
59 |
+
results.push(message.msg);
|
60 |
+
}
|
61 |
+
|
62 |
+
if (results.length == 0) {
|
63 |
+
return gunzip(chunk);
|
64 |
+
}
|
65 |
+
return results.join('');
|
66 |
+
} catch (err) {
|
67 |
+
return gunzip(chunk);
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
function gunzip(chunk) {
|
72 |
+
return new Promise((resolve, reject) => {
|
73 |
+
zlib.gunzip(chunk.slice(5), (err, decompressed) => {
|
74 |
+
if (err) {
|
75 |
+
resolve('');
|
76 |
+
} else {
|
77 |
+
const text = decompressed.toString('utf-8');
|
78 |
+
// 这里只是尝试解析错误数据,如果是包含了全量的返回结果直接忽略
|
79 |
+
if (regex.test(text)) {
|
80 |
+
resolve('');
|
81 |
+
} else {
|
82 |
+
resolve(text);
|
83 |
+
}
|
84 |
+
}
|
85 |
+
});
|
86 |
+
});
|
87 |
+
}
|
88 |
+
|
89 |
+
function getRandomIDPro({ size, dictType, customDict }) {
|
90 |
+
let random = '';
|
91 |
+
if (!customDict) {
|
92 |
+
switch (dictType) {
|
93 |
+
case 'alphabet':
|
94 |
+
customDict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
95 |
+
break;
|
96 |
+
case 'max':
|
97 |
+
customDict = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-';
|
98 |
+
break;
|
99 |
+
default:
|
100 |
+
customDict = '0123456789';
|
101 |
+
}
|
102 |
+
}
|
103 |
+
for (; size--; ) random += customDict[(Math.random() * customDict.length) | 0];
|
104 |
+
return random;
|
105 |
+
}
|
106 |
+
|
107 |
+
module.exports = {
|
108 |
+
stringToHex,
|
109 |
+
chunkToUtf8String,
|
110 |
+
getRandomIDPro,
|
111 |
+
};
|