2ch commited on
Commit
44d3414
·
verified ·
1 Parent(s): 69a5ea7

Upload 6 files

Browse files
Files changed (6) hide show
  1. Dockerfile +12 -0
  2. package.json +22 -0
  3. src/index.js +151 -0
  4. src/message.js +1918 -0
  5. src/message.proto +51 -0
  6. src/utils.js +111 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:lts-alpine
2
+
3
+ EXPOSE 3000
4
+ ENV TZ=Europe/Moscow
5
+
6
+ WORKDIR /app
7
+ COPY . .
8
+
9
+ RUN yarn config set registry https://registry.npmmirror.com/
10
+ RUN yarn
11
+
12
+ CMD ["npm", "run", "start"]
package.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "cursor-api",
3
+ "version": "1.0.0",
4
+ "description": "cursor reverse-API",
5
+ "author": "zhx47",
6
+ "private": false,
7
+ "main": "index.js",
8
+ "url": "https://github.com/zhx47/cursor-api",
9
+ "license": "MIT",
10
+ "dependencies": {
11
+ "express": "4.21.1",
12
+ "protobufjs": "^7.4.0",
13
+ "uuid": "11.0.3"
14
+ },
15
+ "scripts": {
16
+ "format": "prettier --write \"src/**/*.js\"",
17
+ "start": "node src/index.js"
18
+ },
19
+ "devDependencies": {
20
+ "prettier": "^3.4.0"
21
+ }
22
+ }
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
+ // Middleware configuration
7
+ app.use(express.json());
8
+ app.use(express.urlencoded({ extended: true }));
9
+
10
+ app.post('/v1/chat/completions', async (req, res) => {
11
+ // Models starting with o1 do not support streaming output
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
+ // Handle comma-separated keys
23
+ const keys = authToken.split(',').map((key) => key.trim());
24
+ if (keys.length > 0) {
25
+ // make sure currentKeyIndex won't cross the line
26
+ if (currentKeyIndex >= keys.length) {
27
+ currentKeyIndex = 0;
28
+ }
29
+ // Use the current index to get the key
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
+ // get checksum,req header Medium passes first, the environment variable ranks second, and is randomly generated last
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
+ // Use encapsulated function processing 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
+ // Encapsulated functions are also used in non-streaming mode
104
+ for await (const chunk of response.body) {
105
+ text += await chunkToUtf8String(chunk);
106
+ }
107
+ // Further processing of the parsed string
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
+ // Start the server
148
+ const PORT = process.env.PORT || 3000;
149
+ app.listen(PORT, () => {
150
+ console.log(`The server runs on the port ${PORT}`);
151
+ });
src/message.js ADDED
@@ -0,0 +1,1918 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ const $protobuf = require('protobufjs/minimal');
5
+
6
+ // Common aliases
7
+ const $Reader = $protobuf.Reader,
8
+ $Writer = $protobuf.Writer,
9
+ $util = $protobuf.util;
10
+
11
+ // Exported root namespace
12
+ const $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) let keys = Object.keys(properties), i = 0; for (; 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 (let 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
+ const end = length === undefined ? reader.len : reader.pos + length,
160
+ message = new $root.ChatMessage();
161
+ while (reader.pos < end) {
162
+ const 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
+ let error;
226
+ if (typeof message !== 'object' || message === null) return 'object expected';
227
+ if (message.messages != null && message.hasOwnProperty('messages')) {
228
+ if (!Array.isArray(message.messages)) return 'messages: array expected';
229
+ for (let i = 0; i < message.messages.length; ++i) {
230
+ error = $root.ChatMessage.UserMessage.verify(message.messages[i]);
231
+ if (error) return 'messages.' + error;
232
+ }
233
+ }
234
+ if (message.instructions != null && message.hasOwnProperty('instructions')) {
235
+ error = $root.ChatMessage.Instructions.verify(message.instructions);
236
+ if (error) return 'instructions.' + error;
237
+ }
238
+ if (message.projectPath != null && message.hasOwnProperty('projectPath')) if (!$util.isString(message.projectPath)) return 'projectPath: string expected';
239
+ if (message.model != null && message.hasOwnProperty('model')) {
240
+ error = $root.ChatMessage.Model.verify(message.model);
241
+ if (error) return 'model.' + error;
242
+ }
243
+ if (message.requestId != null && message.hasOwnProperty('requestId')) if (!$util.isString(message.requestId)) return 'requestId: string expected';
244
+ if (message.summary != null && message.hasOwnProperty('summary')) if (!$util.isString(message.summary)) return 'summary: string expected';
245
+ if (message.conversationId != null && message.hasOwnProperty('conversationId')) if (!$util.isString(message.conversationId)) return 'conversationId: string expected';
246
+ return null;
247
+ };
248
+
249
+ /**
250
+ * Creates a ChatMessage message from a plain object. Also converts values to their respective internal types.
251
+ * @function fromObject
252
+ * @memberof ChatMessage
253
+ * @static
254
+ * @param {Object.<string,*>} object Plain object
255
+ * @returns {ChatMessage} ChatMessage
256
+ */
257
+ ChatMessage.fromObject = function fromObject(object) {
258
+ if (object instanceof $root.ChatMessage) return object;
259
+ const message = new $root.ChatMessage();
260
+ if (object.messages) {
261
+ if (!Array.isArray(object.messages)) throw TypeError('.ChatMessage.messages: array expected');
262
+ message.messages = [];
263
+ for (let i = 0; i < object.messages.length; ++i) {
264
+ if (typeof object.messages[i] !== 'object') throw TypeError('.ChatMessage.messages: object expected');
265
+ message.messages[i] = $root.ChatMessage.UserMessage.fromObject(object.messages[i]);
266
+ }
267
+ }
268
+ if (object.instructions != null) {
269
+ if (typeof object.instructions !== 'object') throw TypeError('.ChatMessage.instructions: object expected');
270
+ message.instructions = $root.ChatMessage.Instructions.fromObject(object.instructions);
271
+ }
272
+ if (object.projectPath != null) message.projectPath = String(object.projectPath);
273
+ if (object.model != null) {
274
+ if (typeof object.model !== 'object') throw TypeError('.ChatMessage.model: object expected');
275
+ message.model = $root.ChatMessage.Model.fromObject(object.model);
276
+ }
277
+ if (object.requestId != null) message.requestId = String(object.requestId);
278
+ if (object.summary != null) message.summary = String(object.summary);
279
+ if (object.conversationId != null) message.conversationId = String(object.conversationId);
280
+ return message;
281
+ };
282
+
283
+ /**
284
+ * Creates a plain object from a ChatMessage message. Also converts values to other types if specified.
285
+ * @function toObject
286
+ * @memberof ChatMessage
287
+ * @static
288
+ * @param {ChatMessage} message ChatMessage
289
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
290
+ * @returns {Object.<string,*>} Plain object
291
+ */
292
+ ChatMessage.toObject = function toObject(message, options) {
293
+ if (!options) options = {};
294
+ const object = {};
295
+ if (options.arrays || options.defaults) object.messages = [];
296
+ if (options.defaults) {
297
+ object.instructions = null;
298
+ object.projectPath = '';
299
+ object.model = null;
300
+ object.requestId = '';
301
+ object.summary = '';
302
+ object.conversationId = '';
303
+ }
304
+ if (message.messages && message.messages.length) {
305
+ object.messages = [];
306
+ for (let j = 0; j < message.messages.length; ++j) object.messages[j] = $root.ChatMessage.UserMessage.toObject(message.messages[j], options);
307
+ }
308
+ if (message.instructions != null && message.hasOwnProperty('instructions')) object.instructions = $root.ChatMessage.Instructions.toObject(message.instructions, options);
309
+ if (message.projectPath != null && message.hasOwnProperty('projectPath')) object.projectPath = message.projectPath;
310
+ if (message.model != null && message.hasOwnProperty('model')) object.model = $root.ChatMessage.Model.toObject(message.model, options);
311
+ if (message.requestId != null && message.hasOwnProperty('requestId')) object.requestId = message.requestId;
312
+ if (message.summary != null && message.hasOwnProperty('summary')) object.summary = message.summary;
313
+ if (message.conversationId != null && message.hasOwnProperty('conversationId')) object.conversationId = message.conversationId;
314
+ return object;
315
+ };
316
+
317
+ /**
318
+ * Converts this ChatMessage to JSON.
319
+ * @function toJSON
320
+ * @memberof ChatMessage
321
+ * @instance
322
+ * @returns {Object.<string,*>} JSON object
323
+ */
324
+ ChatMessage.prototype.toJSON = function toJSON() {
325
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
326
+ };
327
+
328
+ /**
329
+ * Gets the default type url for ChatMessage
330
+ * @function getTypeUrl
331
+ * @memberof ChatMessage
332
+ * @static
333
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
334
+ * @returns {string} The default type url
335
+ */
336
+ ChatMessage.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
337
+ if (typeUrlPrefix === undefined) {
338
+ typeUrlPrefix = 'type.googleapis.com';
339
+ }
340
+ return typeUrlPrefix + '/ChatMessage';
341
+ };
342
+
343
+ ChatMessage.FileContent = (function () {
344
+ /**
345
+ * Properties of a FileContent.
346
+ * @memberof ChatMessage
347
+ * @interface IFileContent
348
+ * @property {string|null} [filename] FileContent filename
349
+ * @property {string|null} [content] FileContent content
350
+ * @property {ChatMessage.FileContent.IPosition|null} [position] FileContent position
351
+ * @property {string|null} [language] FileContent language
352
+ * @property {ChatMessage.FileContent.IRange|null} [range] FileContent range
353
+ * @property {number|null} [length] FileContent length
354
+ * @property {number|null} [type] FileContent type
355
+ * @property {number|null} [errorCode] FileContent errorCode
356
+ */
357
+
358
+ /**
359
+ * Constructs a new FileContent.
360
+ * @memberof ChatMessage
361
+ * @classdesc Represents a FileContent.
362
+ * @implements IFileContent
363
+ * @constructor
364
+ * @param {ChatMessage.IFileContent=} [properties] Properties to set
365
+ */
366
+ function FileContent(properties) {
367
+ if (properties) let keys = Object.keys(properties), i = 0; for (; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
368
+ }
369
+
370
+ /**
371
+ * FileContent filename.
372
+ * @member {string} filename
373
+ * @memberof ChatMessage.FileContent
374
+ * @instance
375
+ */
376
+ FileContent.prototype.filename = '';
377
+
378
+ /**
379
+ * FileContent content.
380
+ * @member {string} content
381
+ * @memberof ChatMessage.FileContent
382
+ * @instance
383
+ */
384
+ FileContent.prototype.content = '';
385
+
386
+ /**
387
+ * FileContent position.
388
+ * @member {ChatMessage.FileContent.IPosition|null|undefined} position
389
+ * @memberof ChatMessage.FileContent
390
+ * @instance
391
+ */
392
+ FileContent.prototype.position = null;
393
+
394
+ /**
395
+ * FileContent language.
396
+ * @member {string} language
397
+ * @memberof ChatMessage.FileContent
398
+ * @instance
399
+ */
400
+ FileContent.prototype.language = '';
401
+
402
+ /**
403
+ * FileContent range.
404
+ * @member {ChatMessage.FileContent.IRange|null|undefined} range
405
+ * @memberof ChatMessage.FileContent
406
+ * @instance
407
+ */
408
+ FileContent.prototype.range = null;
409
+
410
+ /**
411
+ * FileContent length.
412
+ * @member {number} length
413
+ * @memberof ChatMessage.FileContent
414
+ * @instance
415
+ */
416
+ FileContent.prototype.length = 0;
417
+
418
+ /**
419
+ * FileContent type.
420
+ * @member {number} type
421
+ * @memberof ChatMessage.FileContent
422
+ * @instance
423
+ */
424
+ FileContent.prototype.type = 0;
425
+
426
+ /**
427
+ * FileContent errorCode.
428
+ * @member {number} errorCode
429
+ * @memberof ChatMessage.FileContent
430
+ * @instance
431
+ */
432
+ FileContent.prototype.errorCode = 0;
433
+
434
+ /**
435
+ * Creates a new FileContent instance using the specified properties.
436
+ * @function create
437
+ * @memberof ChatMessage.FileContent
438
+ * @static
439
+ * @param {ChatMessage.IFileContent=} [properties] Properties to set
440
+ * @returns {ChatMessage.FileContent} FileContent instance
441
+ */
442
+ FileContent.create = function create(properties) {
443
+ return new FileContent(properties);
444
+ };
445
+
446
+ /**
447
+ * Encodes the specified FileContent message. Does not implicitly {@link ChatMessage.FileContent.verify|verify} messages.
448
+ * @function encode
449
+ * @memberof ChatMessage.FileContent
450
+ * @static
451
+ * @param {ChatMessage.IFileContent} message FileContent message or plain object to encode
452
+ * @param {$protobuf.Writer} [writer] Writer to encode to
453
+ * @returns {$protobuf.Writer} Writer
454
+ */
455
+ FileContent.encode = function encode(message, writer) {
456
+ if (!writer) writer = $Writer.create();
457
+ if (message.filename != null && Object.hasOwnProperty.call(message, 'filename')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.filename);
458
+ if (message.content != null && Object.hasOwnProperty.call(message, 'content')) writer.uint32(/* id 2, wireType 2 =*/ 18).string(message.content);
459
+ if (message.position != null && Object.hasOwnProperty.call(message, 'position'))
460
+ $root.ChatMessage.FileContent.Position.encode(message.position, writer.uint32(/* id 3, wireType 2 =*/ 26).fork()).ldelim();
461
+ if (message.language != null && Object.hasOwnProperty.call(message, 'language')) writer.uint32(/* id 5, wireType 2 =*/ 42).string(message.language);
462
+ if (message.range != null && Object.hasOwnProperty.call(message, 'range'))
463
+ $root.ChatMessage.FileContent.Range.encode(message.range, writer.uint32(/* id 6, wireType 2 =*/ 50).fork()).ldelim();
464
+ if (message.length != null && Object.hasOwnProperty.call(message, 'length')) writer.uint32(/* id 8, wireType 0 =*/ 64).int32(message.length);
465
+ if (message.type != null && Object.hasOwnProperty.call(message, 'type')) writer.uint32(/* id 9, wireType 0 =*/ 72).int32(message.type);
466
+ if (message.errorCode != null && Object.hasOwnProperty.call(message, 'errorCode')) writer.uint32(/* id 11, wireType 0 =*/ 88).int32(message.errorCode);
467
+ return writer;
468
+ };
469
+
470
+ /**
471
+ * Encodes the specified FileContent message, length delimited. Does not implicitly {@link ChatMessage.FileContent.verify|verify} messages.
472
+ * @function encodeDelimited
473
+ * @memberof ChatMessage.FileContent
474
+ * @static
475
+ * @param {ChatMessage.IFileContent} message FileContent message or plain object to encode
476
+ * @param {$protobuf.Writer} [writer] Writer to encode to
477
+ * @returns {$protobuf.Writer} Writer
478
+ */
479
+ FileContent.encodeDelimited = function encodeDelimited(message, writer) {
480
+ return this.encode(message, writer).ldelim();
481
+ };
482
+
483
+ /**
484
+ * Decodes a FileContent message from the specified reader or buffer.
485
+ * @function decode
486
+ * @memberof ChatMessage.FileContent
487
+ * @static
488
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
489
+ * @param {number} [length] Message length if known beforehand
490
+ * @returns {ChatMessage.FileContent} FileContent
491
+ * @throws {Error} If the payload is not a reader or valid buffer
492
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
493
+ */
494
+ FileContent.decode = function decode(reader, length) {
495
+ if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
496
+ const end = length === undefined ? reader.len : reader.pos + length,
497
+ message = new $root.ChatMessage.FileContent();
498
+ while (reader.pos < end) {
499
+ const tag = reader.uint32();
500
+ switch (tag >>> 3) {
501
+ case 1: {
502
+ message.filename = reader.string();
503
+ break;
504
+ }
505
+ case 2: {
506
+ message.content = reader.string();
507
+ break;
508
+ }
509
+ case 3: {
510
+ message.position = $root.ChatMessage.FileContent.Position.decode(reader, reader.uint32());
511
+ break;
512
+ }
513
+ case 5: {
514
+ message.language = reader.string();
515
+ break;
516
+ }
517
+ case 6: {
518
+ message.range = $root.ChatMessage.FileContent.Range.decode(reader, reader.uint32());
519
+ break;
520
+ }
521
+ case 8: {
522
+ message.length = reader.int32();
523
+ break;
524
+ }
525
+ case 9: {
526
+ message.type = reader.int32();
527
+ break;
528
+ }
529
+ case 11: {
530
+ message.errorCode = reader.int32();
531
+ break;
532
+ }
533
+ default:
534
+ reader.skipType(tag & 7);
535
+ break;
536
+ }
537
+ }
538
+ return message;
539
+ };
540
+
541
+ /**
542
+ * Decodes a FileContent message from the specified reader or buffer, length delimited.
543
+ * @function decodeDelimited
544
+ * @memberof ChatMessage.FileContent
545
+ * @static
546
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
547
+ * @returns {ChatMessage.FileContent} FileContent
548
+ * @throws {Error} If the payload is not a reader or valid buffer
549
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
550
+ */
551
+ FileContent.decodeDelimited = function decodeDelimited(reader) {
552
+ if (!(reader instanceof $Reader)) reader = new $Reader(reader);
553
+ return this.decode(reader, reader.uint32());
554
+ };
555
+
556
+ /**
557
+ * Verifies a FileContent message.
558
+ * @function verify
559
+ * @memberof ChatMessage.FileContent
560
+ * @static
561
+ * @param {Object.<string,*>} message Plain object to verify
562
+ * @returns {string|null} `null` if valid, otherwise the reason why it is not
563
+ */
564
+ FileContent.verify = function verify(message) {
565
+ let error;
566
+ if (typeof message !== 'object' || message === null) return 'object expected';
567
+ if (message.filename != null && message.hasOwnProperty('filename')) if (!$util.isString(message.filename)) return 'filename: string expected';
568
+ if (message.content != null && message.hasOwnProperty('content')) if (!$util.isString(message.content)) return 'content: string expected';
569
+ if (message.position != null && message.hasOwnProperty('position')) {
570
+ error = $root.ChatMessage.FileContent.Position.verify(message.position);
571
+ if (error) return 'position.' + error;
572
+ }
573
+ if (message.language != null && message.hasOwnProperty('language')) if (!$util.isString(message.language)) return 'language: string expected';
574
+ if (message.range != null && message.hasOwnProperty('range')) {
575
+ error = $root.ChatMessage.FileContent.Range.verify(message.range);
576
+ if (error) return 'range.' + error;
577
+ }
578
+ if (message.length != null && message.hasOwnProperty('length')) if (!$util.isInteger(message.length)) return 'length: integer expected';
579
+ if (message.type != null && message.hasOwnProperty('type')) if (!$util.isInteger(message.type)) return 'type: integer expected';
580
+ if (message.errorCode != null && message.hasOwnProperty('errorCode')) if (!$util.isInteger(message.errorCode)) return 'errorCode: integer expected';
581
+ return null;
582
+ };
583
+
584
+ /**
585
+ * Creates a FileContent message from a plain object. Also converts values to their respective internal types.
586
+ * @function fromObject
587
+ * @memberof ChatMessage.FileContent
588
+ * @static
589
+ * @param {Object.<string,*>} object Plain object
590
+ * @returns {ChatMessage.FileContent} FileContent
591
+ */
592
+ FileContent.fromObject = function fromObject(object) {
593
+ if (object instanceof $root.ChatMessage.FileContent) return object;
594
+ const message = new $root.ChatMessage.FileContent();
595
+ if (object.filename != null) message.filename = String(object.filename);
596
+ if (object.content != null) message.content = String(object.content);
597
+ if (object.position != null) {
598
+ if (typeof object.position !== 'object') throw TypeError('.ChatMessage.FileContent.position: object expected');
599
+ message.position = $root.ChatMessage.FileContent.Position.fromObject(object.position);
600
+ }
601
+ if (object.language != null) message.language = String(object.language);
602
+ if (object.range != null) {
603
+ if (typeof object.range !== 'object') throw TypeError('.ChatMessage.FileContent.range: object expected');
604
+ message.range = $root.ChatMessage.FileContent.Range.fromObject(object.range);
605
+ }
606
+ if (object.length != null) message.length = object.length | 0;
607
+ if (object.type != null) message.type = object.type | 0;
608
+ if (object.errorCode != null) message.errorCode = object.errorCode | 0;
609
+ return message;
610
+ };
611
+
612
+ /**
613
+ * Creates a plain object from a FileContent message. Also converts values to other types if specified.
614
+ * @function toObject
615
+ * @memberof ChatMessage.FileContent
616
+ * @static
617
+ * @param {ChatMessage.FileContent} message FileContent
618
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
619
+ * @returns {Object.<string,*>} Plain object
620
+ */
621
+ FileContent.toObject = function toObject(message, options) {
622
+ if (!options) options = {};
623
+ const object = {};
624
+ if (options.defaults) {
625
+ object.filename = '';
626
+ object.content = '';
627
+ object.position = null;
628
+ object.language = '';
629
+ object.range = null;
630
+ object.length = 0;
631
+ object.type = 0;
632
+ object.errorCode = 0;
633
+ }
634
+ if (message.filename != null && message.hasOwnProperty('filename')) object.filename = message.filename;
635
+ if (message.content != null && message.hasOwnProperty('content')) object.content = message.content;
636
+ if (message.position != null && message.hasOwnProperty('position')) object.position = $root.ChatMessage.FileContent.Position.toObject(message.position, options);
637
+ if (message.language != null && message.hasOwnProperty('language')) object.language = message.language;
638
+ if (message.range != null && message.hasOwnProperty('range')) object.range = $root.ChatMessage.FileContent.Range.toObject(message.range, options);
639
+ if (message.length != null && message.hasOwnProperty('length')) object.length = message.length;
640
+ if (message.type != null && message.hasOwnProperty('type')) object.type = message.type;
641
+ if (message.errorCode != null && message.hasOwnProperty('errorCode')) object.errorCode = message.errorCode;
642
+ return object;
643
+ };
644
+
645
+ /**
646
+ * Converts this FileContent to JSON.
647
+ * @function toJSON
648
+ * @memberof ChatMessage.FileContent
649
+ * @instance
650
+ * @returns {Object.<string,*>} JSON object
651
+ */
652
+ FileContent.prototype.toJSON = function toJSON() {
653
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
654
+ };
655
+
656
+ /**
657
+ * Gets the default type url for FileContent
658
+ * @function getTypeUrl
659
+ * @memberof ChatMessage.FileContent
660
+ * @static
661
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
662
+ * @returns {string} The default type url
663
+ */
664
+ FileContent.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
665
+ if (typeUrlPrefix === undefined) {
666
+ typeUrlPrefix = 'type.googleapis.com';
667
+ }
668
+ return typeUrlPrefix + '/ChatMessage.FileContent';
669
+ };
670
+
671
+ FileContent.Position = (function () {
672
+ /**
673
+ * Properties of a Position.
674
+ * @memberof ChatMessage.FileContent
675
+ * @interface IPosition
676
+ * @property {number|null} [line] Position line
677
+ * @property {number|null} [column] Position column
678
+ */
679
+
680
+ /**
681
+ * Constructs a new Position.
682
+ * @memberof ChatMessage.FileContent
683
+ * @classdesc Represents a Position.
684
+ * @implements IPosition
685
+ * @constructor
686
+ * @param {ChatMessage.FileContent.IPosition=} [properties] Properties to set
687
+ */
688
+ function Position(properties) {
689
+ if (properties) let keys = Object.keys(properties), i = 0; for (; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
690
+ }
691
+
692
+ /**
693
+ * Position line.
694
+ * @member {number} line
695
+ * @memberof ChatMessage.FileContent.Position
696
+ * @instance
697
+ */
698
+ Position.prototype.line = 0;
699
+
700
+ /**
701
+ * Position column.
702
+ * @member {number} column
703
+ * @memberof ChatMessage.FileContent.Position
704
+ * @instance
705
+ */
706
+ Position.prototype.column = 0;
707
+
708
+ /**
709
+ * Creates a new Position instance using the specified properties.
710
+ * @function create
711
+ * @memberof ChatMessage.FileContent.Position
712
+ * @static
713
+ * @param {ChatMessage.FileContent.IPosition=} [properties] Properties to set
714
+ * @returns {ChatMessage.FileContent.Position} Position instance
715
+ */
716
+ Position.create = function create(properties) {
717
+ return new Position(properties);
718
+ };
719
+
720
+ /**
721
+ * Encodes the specified Position message. Does not implicitly {@link ChatMessage.FileContent.Position.verify|verify} messages.
722
+ * @function encode
723
+ * @memberof ChatMessage.FileContent.Position
724
+ * @static
725
+ * @param {ChatMessage.FileContent.IPosition} message Position message or plain object to encode
726
+ * @param {$protobuf.Writer} [writer] Writer to encode to
727
+ * @returns {$protobuf.Writer} Writer
728
+ */
729
+ Position.encode = function encode(message, writer) {
730
+ if (!writer) writer = $Writer.create();
731
+ if (message.line != null && Object.hasOwnProperty.call(message, 'line')) writer.uint32(/* id 1, wireType 0 =*/ 8).int32(message.line);
732
+ if (message.column != null && Object.hasOwnProperty.call(message, 'column')) writer.uint32(/* id 2, wireType 0 =*/ 16).int32(message.column);
733
+ return writer;
734
+ };
735
+
736
+ /**
737
+ * Encodes the specified Position message, length delimited. Does not implicitly {@link ChatMessage.FileContent.Position.verify|verify} messages.
738
+ * @function encodeDelimited
739
+ * @memberof ChatMessage.FileContent.Position
740
+ * @static
741
+ * @param {ChatMessage.FileContent.IPosition} message Position message or plain object to encode
742
+ * @param {$protobuf.Writer} [writer] Writer to encode to
743
+ * @returns {$protobuf.Writer} Writer
744
+ */
745
+ Position.encodeDelimited = function encodeDelimited(message, writer) {
746
+ return this.encode(message, writer).ldelim();
747
+ };
748
+
749
+ /**
750
+ * Decodes a Position message from the specified reader or buffer.
751
+ * @function decode
752
+ * @memberof ChatMessage.FileContent.Position
753
+ * @static
754
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
755
+ * @param {number} [length] Message length if known beforehand
756
+ * @returns {ChatMessage.FileContent.Position} Position
757
+ * @throws {Error} If the payload is not a reader or valid buffer
758
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
759
+ */
760
+ Position.decode = function decode(reader, length) {
761
+ if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
762
+ const end = length === undefined ? reader.len : reader.pos + length,
763
+ message = new $root.ChatMessage.FileContent.Position();
764
+ while (reader.pos < end) {
765
+ const tag = reader.uint32();
766
+ switch (tag >>> 3) {
767
+ case 1: {
768
+ message.line = reader.int32();
769
+ break;
770
+ }
771
+ case 2: {
772
+ message.column = reader.int32();
773
+ break;
774
+ }
775
+ default:
776
+ reader.skipType(tag & 7);
777
+ break;
778
+ }
779
+ }
780
+ return message;
781
+ };
782
+
783
+ /**
784
+ * Decodes a Position message from the specified reader or buffer, length delimited.
785
+ * @function decodeDelimited
786
+ * @memberof ChatMessage.FileContent.Position
787
+ * @static
788
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
789
+ * @returns {ChatMessage.FileContent.Position} Position
790
+ * @throws {Error} If the payload is not a reader or valid buffer
791
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
792
+ */
793
+ Position.decodeDelimited = function decodeDelimited(reader) {
794
+ if (!(reader instanceof $Reader)) reader = new $Reader(reader);
795
+ return this.decode(reader, reader.uint32());
796
+ };
797
+
798
+ /**
799
+ * Verifies a Position message.
800
+ * @function verify
801
+ * @memberof ChatMessage.FileContent.Position
802
+ * @static
803
+ * @param {Object.<string,*>} message Plain object to verify
804
+ * @returns {string|null} `null` if valid, otherwise the reason why it is not
805
+ */
806
+ Position.verify = function verify(message) {
807
+ if (typeof message !== 'object' || message === null) return 'object expected';
808
+ if (message.line != null && message.hasOwnProperty('line')) if (!$util.isInteger(message.line)) return 'line: integer expected';
809
+ if (message.column != null && message.hasOwnProperty('column')) if (!$util.isInteger(message.column)) return 'column: integer expected';
810
+ return null;
811
+ };
812
+
813
+ /**
814
+ * Creates a Position message from a plain object. Also converts values to their respective internal types.
815
+ * @function fromObject
816
+ * @memberof ChatMessage.FileContent.Position
817
+ * @static
818
+ * @param {Object.<string,*>} object Plain object
819
+ * @returns {ChatMessage.FileContent.Position} Position
820
+ */
821
+ Position.fromObject = function fromObject(object) {
822
+ if (object instanceof $root.ChatMessage.FileContent.Position) return object;
823
+ const message = new $root.ChatMessage.FileContent.Position();
824
+ if (object.line != null) message.line = object.line | 0;
825
+ if (object.column != null) message.column = object.column | 0;
826
+ return message;
827
+ };
828
+
829
+ /**
830
+ * Creates a plain object from a Position message. Also converts values to other types if specified.
831
+ * @function toObject
832
+ * @memberof ChatMessage.FileContent.Position
833
+ * @static
834
+ * @param {ChatMessage.FileContent.Position} message Position
835
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
836
+ * @returns {Object.<string,*>} Plain object
837
+ */
838
+ Position.toObject = function toObject(message, options) {
839
+ if (!options) options = {};
840
+ const object = {};
841
+ if (options.defaults) {
842
+ object.line = 0;
843
+ object.column = 0;
844
+ }
845
+ if (message.line != null && message.hasOwnProperty('line')) object.line = message.line;
846
+ if (message.column != null && message.hasOwnProperty('column')) object.column = message.column;
847
+ return object;
848
+ };
849
+
850
+ /**
851
+ * Converts this Position to JSON.
852
+ * @function toJSON
853
+ * @memberof ChatMessage.FileContent.Position
854
+ * @instance
855
+ * @returns {Object.<string,*>} JSON object
856
+ */
857
+ Position.prototype.toJSON = function toJSON() {
858
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
859
+ };
860
+
861
+ /**
862
+ * Gets the default type url for Position
863
+ * @function getTypeUrl
864
+ * @memberof ChatMessage.FileContent.Position
865
+ * @static
866
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
867
+ * @returns {string} The default type url
868
+ */
869
+ Position.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
870
+ if (typeUrlPrefix === undefined) {
871
+ typeUrlPrefix = 'type.googleapis.com';
872
+ }
873
+ return typeUrlPrefix + '/ChatMessage.FileContent.Position';
874
+ };
875
+
876
+ return Position;
877
+ })();
878
+
879
+ FileContent.Range = (function () {
880
+ /**
881
+ * Properties of a Range.
882
+ * @memberof ChatMessage.FileContent
883
+ * @interface IRange
884
+ * @property {ChatMessage.FileContent.IPosition|null} [start] Range start
885
+ * @property {ChatMessage.FileContent.IPosition|null} [end] Range end
886
+ */
887
+
888
+ /**
889
+ * Constructs a new Range.
890
+ * @memberof ChatMessage.FileContent
891
+ * @classdesc Represents a Range.
892
+ * @implements IRange
893
+ * @constructor
894
+ * @param {ChatMessage.FileContent.IRange=} [properties] Properties to set
895
+ */
896
+ function Range(properties) {
897
+ if (properties) let keys = Object.keys(properties), i = 0; for (; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
898
+ }
899
+
900
+ /**
901
+ * Range start.
902
+ * @member {ChatMessage.FileContent.IPosition|null|undefined} start
903
+ * @memberof ChatMessage.FileContent.Range
904
+ * @instance
905
+ */
906
+ Range.prototype.start = null;
907
+
908
+ /**
909
+ * Range end.
910
+ * @member {ChatMessage.FileContent.IPosition|null|undefined} end
911
+ * @memberof ChatMessage.FileContent.Range
912
+ * @instance
913
+ */
914
+ Range.prototype.end = null;
915
+
916
+ /**
917
+ * Creates a new Range instance using the specified properties.
918
+ * @function create
919
+ * @memberof ChatMessage.FileContent.Range
920
+ * @static
921
+ * @param {ChatMessage.FileContent.IRange=} [properties] Properties to set
922
+ * @returns {ChatMessage.FileContent.Range} Range instance
923
+ */
924
+ Range.create = function create(properties) {
925
+ return new Range(properties);
926
+ };
927
+
928
+ /**
929
+ * Encodes the specified Range message. Does not implicitly {@link ChatMessage.FileContent.Range.verify|verify} messages.
930
+ * @function encode
931
+ * @memberof ChatMessage.FileContent.Range
932
+ * @static
933
+ * @param {ChatMessage.FileContent.IRange} message Range message or plain object to encode
934
+ * @param {$protobuf.Writer} [writer] Writer to encode to
935
+ * @returns {$protobuf.Writer} Writer
936
+ */
937
+ Range.encode = function encode(message, writer) {
938
+ if (!writer) writer = $Writer.create();
939
+ if (message.start != null && Object.hasOwnProperty.call(message, 'start'))
940
+ $root.ChatMessage.FileContent.Position.encode(message.start, writer.uint32(/* id 1, wireType 2 =*/ 10).fork()).ldelim();
941
+ if (message.end != null && Object.hasOwnProperty.call(message, 'end'))
942
+ $root.ChatMessage.FileContent.Position.encode(message.end, writer.uint32(/* id 2, wireType 2 =*/ 18).fork()).ldelim();
943
+ return writer;
944
+ };
945
+
946
+ /**
947
+ * Encodes the specified Range message, length delimited. Does not implicitly {@link ChatMessage.FileContent.Range.verify|verify} messages.
948
+ * @function encodeDelimited
949
+ * @memberof ChatMessage.FileContent.Range
950
+ * @static
951
+ * @param {ChatMessage.FileContent.IRange} message Range message or plain object to encode
952
+ * @param {$protobuf.Writer} [writer] Writer to encode to
953
+ * @returns {$protobuf.Writer} Writer
954
+ */
955
+ Range.encodeDelimited = function encodeDelimited(message, writer) {
956
+ return this.encode(message, writer).ldelim();
957
+ };
958
+
959
+ /**
960
+ * Decodes a Range message from the specified reader or buffer.
961
+ * @function decode
962
+ * @memberof ChatMessage.FileContent.Range
963
+ * @static
964
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
965
+ * @param {number} [length] Message length if known beforehand
966
+ * @returns {ChatMessage.FileContent.Range} Range
967
+ * @throws {Error} If the payload is not a reader or valid buffer
968
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
969
+ */
970
+ Range.decode = function decode(reader, length) {
971
+ if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
972
+ const end = length === undefined ? reader.len : reader.pos + length,
973
+ message = new $root.ChatMessage.FileContent.Range();
974
+ while (reader.pos < end) {
975
+ const tag = reader.uint32();
976
+ switch (tag >>> 3) {
977
+ case 1: {
978
+ message.start = $root.ChatMessage.FileContent.Position.decode(reader, reader.uint32());
979
+ break;
980
+ }
981
+ case 2: {
982
+ message.end = $root.ChatMessage.FileContent.Position.decode(reader, reader.uint32());
983
+ break;
984
+ }
985
+ default:
986
+ reader.skipType(tag & 7);
987
+ break;
988
+ }
989
+ }
990
+ return message;
991
+ };
992
+
993
+ /**
994
+ * Decodes a Range message from the specified reader or buffer, length delimited.
995
+ * @function decodeDelimited
996
+ * @memberof ChatMessage.FileContent.Range
997
+ * @static
998
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
999
+ * @returns {ChatMessage.FileContent.Range} Range
1000
+ * @throws {Error} If the payload is not a reader or valid buffer
1001
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1002
+ */
1003
+ Range.decodeDelimited = function decodeDelimited(reader) {
1004
+ if (!(reader instanceof $Reader)) reader = new $Reader(reader);
1005
+ return this.decode(reader, reader.uint32());
1006
+ };
1007
+
1008
+ /**
1009
+ * Verifies a Range message.
1010
+ * @function verify
1011
+ * @memberof ChatMessage.FileContent.Range
1012
+ * @static
1013
+ * @param {Object.<string,*>} message Plain object to verify
1014
+ * @returns {string|null} `null` if valid, otherwise the reason why it is not
1015
+ */
1016
+ Range.verify = function verify(message) {
1017
+ let error;
1018
+ if (typeof message !== 'object' || message === null) return 'object expected';
1019
+ if (message.start != null && message.hasOwnProperty('start')) {
1020
+ error = $root.ChatMessage.FileContent.Position.verify(message.start);
1021
+ if (error) return 'start.' + error;
1022
+ }
1023
+ if (message.end != null && message.hasOwnProperty('end')) {
1024
+ error = $root.ChatMessage.FileContent.Position.verify(message.end);
1025
+ if (error) return 'end.' + error;
1026
+ }
1027
+ return null;
1028
+ };
1029
+
1030
+ /**
1031
+ * Creates a Range message from a plain object. Also converts values to their respective internal types.
1032
+ * @function fromObject
1033
+ * @memberof ChatMessage.FileContent.Range
1034
+ * @static
1035
+ * @param {Object.<string,*>} object Plain object
1036
+ * @returns {ChatMessage.FileContent.Range} Range
1037
+ */
1038
+ Range.fromObject = function fromObject(object) {
1039
+ if (object instanceof $root.ChatMessage.FileContent.Range) return object;
1040
+ const message = new $root.ChatMessage.FileContent.Range();
1041
+ if (object.start != null) {
1042
+ if (typeof object.start !== 'object') throw TypeError('.ChatMessage.FileContent.Range.start: object expected');
1043
+ message.start = $root.ChatMessage.FileContent.Position.fromObject(object.start);
1044
+ }
1045
+ if (object.end != null) {
1046
+ if (typeof object.end !== 'object') throw TypeError('.ChatMessage.FileContent.Range.end: object expected');
1047
+ message.end = $root.ChatMessage.FileContent.Position.fromObject(object.end);
1048
+ }
1049
+ return message;
1050
+ };
1051
+
1052
+ /**
1053
+ * Creates a plain object from a Range message. Also converts values to other types if specified.
1054
+ * @function toObject
1055
+ * @memberof ChatMessage.FileContent.Range
1056
+ * @static
1057
+ * @param {ChatMessage.FileContent.Range} message Range
1058
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
1059
+ * @returns {Object.<string,*>} Plain object
1060
+ */
1061
+ Range.toObject = function toObject(message, options) {
1062
+ if (!options) options = {};
1063
+ const object = {};
1064
+ if (options.defaults) {
1065
+ object.start = null;
1066
+ object.end = null;
1067
+ }
1068
+ if (message.start != null && message.hasOwnProperty('start')) object.start = $root.ChatMessage.FileContent.Position.toObject(message.start, options);
1069
+ if (message.end != null && message.hasOwnProperty('end')) object.end = $root.ChatMessage.FileContent.Position.toObject(message.end, options);
1070
+ return object;
1071
+ };
1072
+
1073
+ /**
1074
+ * Converts this Range to JSON.
1075
+ * @function toJSON
1076
+ * @memberof ChatMessage.FileContent.Range
1077
+ * @instance
1078
+ * @returns {Object.<string,*>} JSON object
1079
+ */
1080
+ Range.prototype.toJSON = function toJSON() {
1081
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
1082
+ };
1083
+
1084
+ /**
1085
+ * Gets the default type url for Range
1086
+ * @function getTypeUrl
1087
+ * @memberof ChatMessage.FileContent.Range
1088
+ * @static
1089
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
1090
+ * @returns {string} The default type url
1091
+ */
1092
+ Range.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
1093
+ if (typeUrlPrefix === undefined) {
1094
+ typeUrlPrefix = 'type.googleapis.com';
1095
+ }
1096
+ return typeUrlPrefix + '/ChatMessage.FileContent.Range';
1097
+ };
1098
+
1099
+ return Range;
1100
+ })();
1101
+
1102
+ return FileContent;
1103
+ })();
1104
+
1105
+ ChatMessage.UserMessage = (function () {
1106
+ /**
1107
+ * Properties of a UserMessage.
1108
+ * @memberof ChatMessage
1109
+ * @interface IUserMessage
1110
+ * @property {string|null} [content] UserMessage content
1111
+ * @property {number|null} [role] UserMessage role
1112
+ * @property {string|null} [messageId] UserMessage messageId
1113
+ */
1114
+
1115
+ /**
1116
+ * Constructs a new UserMessage.
1117
+ * @memberof ChatMessage
1118
+ * @classdesc Represents a UserMessage.
1119
+ * @implements IUserMessage
1120
+ * @constructor
1121
+ * @param {ChatMessage.IUserMessage=} [properties] Properties to set
1122
+ */
1123
+ function UserMessage(properties) {
1124
+ if (properties) let keys = Object.keys(properties), i = 0; for (; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
1125
+ }
1126
+
1127
+ /**
1128
+ * UserMessage content.
1129
+ * @member {string} content
1130
+ * @memberof ChatMessage.UserMessage
1131
+ * @instance
1132
+ */
1133
+ UserMessage.prototype.content = '';
1134
+
1135
+ /**
1136
+ * UserMessage role.
1137
+ * @member {number} role
1138
+ * @memberof ChatMessage.UserMessage
1139
+ * @instance
1140
+ */
1141
+ UserMessage.prototype.role = 0;
1142
+
1143
+ /**
1144
+ * UserMessage messageId.
1145
+ * @member {string} messageId
1146
+ * @memberof ChatMessage.UserMessage
1147
+ * @instance
1148
+ */
1149
+ UserMessage.prototype.messageId = '';
1150
+
1151
+ /**
1152
+ * Creates a new UserMessage instance using the specified properties.
1153
+ * @function create
1154
+ * @memberof ChatMessage.UserMessage
1155
+ * @static
1156
+ * @param {ChatMessage.IUserMessage=} [properties] Properties to set
1157
+ * @returns {ChatMessage.UserMessage} UserMessage instance
1158
+ */
1159
+ UserMessage.create = function create(properties) {
1160
+ return new UserMessage(properties);
1161
+ };
1162
+
1163
+ /**
1164
+ * Encodes the specified UserMessage message. Does not implicitly {@link ChatMessage.UserMessage.verify|verify} messages.
1165
+ * @function encode
1166
+ * @memberof ChatMessage.UserMessage
1167
+ * @static
1168
+ * @param {ChatMessage.IUserMessage} message UserMessage message or plain object to encode
1169
+ * @param {$protobuf.Writer} [writer] Writer to encode to
1170
+ * @returns {$protobuf.Writer} Writer
1171
+ */
1172
+ UserMessage.encode = function encode(message, writer) {
1173
+ if (!writer) writer = $Writer.create();
1174
+ if (message.content != null && Object.hasOwnProperty.call(message, 'content')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.content);
1175
+ if (message.role != null && Object.hasOwnProperty.call(message, 'role')) writer.uint32(/* id 2, wireType 0 =*/ 16).int32(message.role);
1176
+ if (message.messageId != null && Object.hasOwnProperty.call(message, 'messageId')) writer.uint32(/* id 13, wireType 2 =*/ 106).string(message.messageId);
1177
+ return writer;
1178
+ };
1179
+
1180
+ /**
1181
+ * Encodes the specified UserMessage message, length delimited. Does not implicitly {@link ChatMessage.UserMessage.verify|verify} messages.
1182
+ * @function encodeDelimited
1183
+ * @memberof ChatMessage.UserMessage
1184
+ * @static
1185
+ * @param {ChatMessage.IUserMessage} message UserMessage message or plain object to encode
1186
+ * @param {$protobuf.Writer} [writer] Writer to encode to
1187
+ * @returns {$protobuf.Writer} Writer
1188
+ */
1189
+ UserMessage.encodeDelimited = function encodeDelimited(message, writer) {
1190
+ return this.encode(message, writer).ldelim();
1191
+ };
1192
+
1193
+ /**
1194
+ * Decodes a UserMessage message from the specified reader or buffer.
1195
+ * @function decode
1196
+ * @memberof ChatMessage.UserMessage
1197
+ * @static
1198
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1199
+ * @param {number} [length] Message length if known beforehand
1200
+ * @returns {ChatMessage.UserMessage} UserMessage
1201
+ * @throws {Error} If the payload is not a reader or valid buffer
1202
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1203
+ */
1204
+ UserMessage.decode = function decode(reader, length) {
1205
+ if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
1206
+ const end = length === undefined ? reader.len : reader.pos + length,
1207
+ message = new $root.ChatMessage.UserMessage();
1208
+ while (reader.pos < end) {
1209
+ const tag = reader.uint32();
1210
+ switch (tag >>> 3) {
1211
+ case 1: {
1212
+ message.content = reader.string();
1213
+ break;
1214
+ }
1215
+ case 2: {
1216
+ message.role = reader.int32();
1217
+ break;
1218
+ }
1219
+ case 13: {
1220
+ message.messageId = reader.string();
1221
+ break;
1222
+ }
1223
+ default:
1224
+ reader.skipType(tag & 7);
1225
+ break;
1226
+ }
1227
+ }
1228
+ return message;
1229
+ };
1230
+
1231
+ /**
1232
+ * Decodes a UserMessage message from the specified reader or buffer, length delimited.
1233
+ * @function decodeDelimited
1234
+ * @memberof ChatMessage.UserMessage
1235
+ * @static
1236
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1237
+ * @returns {ChatMessage.UserMessage} UserMessage
1238
+ * @throws {Error} If the payload is not a reader or valid buffer
1239
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1240
+ */
1241
+ UserMessage.decodeDelimited = function decodeDelimited(reader) {
1242
+ if (!(reader instanceof $Reader)) reader = new $Reader(reader);
1243
+ return this.decode(reader, reader.uint32());
1244
+ };
1245
+
1246
+ /**
1247
+ * Verifies a UserMessage message.
1248
+ * @function verify
1249
+ * @memberof ChatMessage.UserMessage
1250
+ * @static
1251
+ * @param {Object.<string,*>} message Plain object to verify
1252
+ * @returns {string|null} `null` if valid, otherwise the reason why it is not
1253
+ */
1254
+ UserMessage.verify = function verify(message) {
1255
+ if (typeof message !== 'object' || message === null) return 'object expected';
1256
+ if (message.content != null && message.hasOwnProperty('content')) if (!$util.isString(message.content)) return 'content: string expected';
1257
+ if (message.role != null && message.hasOwnProperty('role')) if (!$util.isInteger(message.role)) return 'role: integer expected';
1258
+ if (message.messageId != null && message.hasOwnProperty('messageId')) if (!$util.isString(message.messageId)) return 'messageId: string expected';
1259
+ return null;
1260
+ };
1261
+
1262
+ /**
1263
+ * Creates a UserMessage message from a plain object. Also converts values to their respective internal types.
1264
+ * @function fromObject
1265
+ * @memberof ChatMessage.UserMessage
1266
+ * @static
1267
+ * @param {Object.<string,*>} object Plain object
1268
+ * @returns {ChatMessage.UserMessage} UserMessage
1269
+ */
1270
+ UserMessage.fromObject = function fromObject(object) {
1271
+ if (object instanceof $root.ChatMessage.UserMessage) return object;
1272
+ const message = new $root.ChatMessage.UserMessage();
1273
+ if (object.content != null) message.content = String(object.content);
1274
+ if (object.role != null) message.role = object.role | 0;
1275
+ if (object.messageId != null) message.messageId = String(object.messageId);
1276
+ return message;
1277
+ };
1278
+
1279
+ /**
1280
+ * Creates a plain object from a UserMessage message. Also converts values to other types if specified.
1281
+ * @function toObject
1282
+ * @memberof ChatMessage.UserMessage
1283
+ * @static
1284
+ * @param {ChatMessage.UserMessage} message UserMessage
1285
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
1286
+ * @returns {Object.<string,*>} Plain object
1287
+ */
1288
+ UserMessage.toObject = function toObject(message, options) {
1289
+ if (!options) options = {};
1290
+ const object = {};
1291
+ if (options.defaults) {
1292
+ object.content = '';
1293
+ object.role = 0;
1294
+ object.messageId = '';
1295
+ }
1296
+ if (message.content != null && message.hasOwnProperty('content')) object.content = message.content;
1297
+ if (message.role != null && message.hasOwnProperty('role')) object.role = message.role;
1298
+ if (message.messageId != null && message.hasOwnProperty('messageId')) object.messageId = message.messageId;
1299
+ return object;
1300
+ };
1301
+
1302
+ /**
1303
+ * Converts this UserMessage to JSON.
1304
+ * @function toJSON
1305
+ * @memberof ChatMessage.UserMessage
1306
+ * @instance
1307
+ * @returns {Object.<string,*>} JSON object
1308
+ */
1309
+ UserMessage.prototype.toJSON = function toJSON() {
1310
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
1311
+ };
1312
+
1313
+ /**
1314
+ * Gets the default type url for UserMessage
1315
+ * @function getTypeUrl
1316
+ * @memberof ChatMessage.UserMessage
1317
+ * @static
1318
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
1319
+ * @returns {string} The default type url
1320
+ */
1321
+ UserMessage.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
1322
+ if (typeUrlPrefix === undefined) {
1323
+ typeUrlPrefix = 'type.googleapis.com';
1324
+ }
1325
+ return typeUrlPrefix + '/ChatMessage.UserMessage';
1326
+ };
1327
+
1328
+ return UserMessage;
1329
+ })();
1330
+
1331
+ ChatMessage.Instructions = (function () {
1332
+ /**
1333
+ * Properties of an Instructions.
1334
+ * @memberof ChatMessage
1335
+ * @interface IInstructions
1336
+ * @property {string|null} [instruction] Instructions instruction
1337
+ */
1338
+
1339
+ /**
1340
+ * Constructs a new Instructions.
1341
+ * @memberof ChatMessage
1342
+ * @classdesc Represents an Instructions.
1343
+ * @implements IInstructions
1344
+ * @constructor
1345
+ * @param {ChatMessage.IInstructions=} [properties] Properties to set
1346
+ */
1347
+ function Instructions(properties) {
1348
+ if (properties) let keys = Object.keys(properties), i = 0; for (; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
1349
+ }
1350
+
1351
+ /**
1352
+ * Instructions instruction.
1353
+ * @member {string} instruction
1354
+ * @memberof ChatMessage.Instructions
1355
+ * @instance
1356
+ */
1357
+ Instructions.prototype.instruction = '';
1358
+
1359
+ /**
1360
+ * Creates a new Instructions instance using the specified properties.
1361
+ * @function create
1362
+ * @memberof ChatMessage.Instructions
1363
+ * @static
1364
+ * @param {ChatMessage.IInstructions=} [properties] Properties to set
1365
+ * @returns {ChatMessage.Instructions} Instructions instance
1366
+ */
1367
+ Instructions.create = function create(properties) {
1368
+ return new Instructions(properties);
1369
+ };
1370
+
1371
+ /**
1372
+ * Encodes the specified Instructions message. Does not implicitly {@link ChatMessage.Instructions.verify|verify} messages.
1373
+ * @function encode
1374
+ * @memberof ChatMessage.Instructions
1375
+ * @static
1376
+ * @param {ChatMessage.IInstructions} message Instructions message or plain object to encode
1377
+ * @param {$protobuf.Writer} [writer] Writer to encode to
1378
+ * @returns {$protobuf.Writer} Writer
1379
+ */
1380
+ Instructions.encode = function encode(message, writer) {
1381
+ if (!writer) writer = $Writer.create();
1382
+ if (message.instruction != null && Object.hasOwnProperty.call(message, 'instruction')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.instruction);
1383
+ return writer;
1384
+ };
1385
+
1386
+ /**
1387
+ * Encodes the specified Instructions message, length delimited. Does not implicitly {@link ChatMessage.Instructions.verify|verify} messages.
1388
+ * @function encodeDelimited
1389
+ * @memberof ChatMessage.Instructions
1390
+ * @static
1391
+ * @param {ChatMessage.IInstructions} message Instructions message or plain object to encode
1392
+ * @param {$protobuf.Writer} [writer] Writer to encode to
1393
+ * @returns {$protobuf.Writer} Writer
1394
+ */
1395
+ Instructions.encodeDelimited = function encodeDelimited(message, writer) {
1396
+ return this.encode(message, writer).ldelim();
1397
+ };
1398
+
1399
+ /**
1400
+ * Decodes an Instructions message from the specified reader or buffer.
1401
+ * @function decode
1402
+ * @memberof ChatMessage.Instructions
1403
+ * @static
1404
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1405
+ * @param {number} [length] Message length if known beforehand
1406
+ * @returns {ChatMessage.Instructions} Instructions
1407
+ * @throws {Error} If the payload is not a reader or valid buffer
1408
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1409
+ */
1410
+ Instructions.decode = function decode(reader, length) {
1411
+ if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
1412
+ const end = length === undefined ? reader.len : reader.pos + length,
1413
+ message = new $root.ChatMessage.Instructions();
1414
+ while (reader.pos < end) {
1415
+ const tag = reader.uint32();
1416
+ switch (tag >>> 3) {
1417
+ case 1: {
1418
+ message.instruction = reader.string();
1419
+ break;
1420
+ }
1421
+ default:
1422
+ reader.skipType(tag & 7);
1423
+ break;
1424
+ }
1425
+ }
1426
+ return message;
1427
+ };
1428
+
1429
+ /**
1430
+ * Decodes an Instructions message from the specified reader or buffer, length delimited.
1431
+ * @function decodeDelimited
1432
+ * @memberof ChatMessage.Instructions
1433
+ * @static
1434
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1435
+ * @returns {ChatMessage.Instructions} Instructions
1436
+ * @throws {Error} If the payload is not a reader or valid buffer
1437
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1438
+ */
1439
+ Instructions.decodeDelimited = function decodeDelimited(reader) {
1440
+ if (!(reader instanceof $Reader)) reader = new $Reader(reader);
1441
+ return this.decode(reader, reader.uint32());
1442
+ };
1443
+
1444
+ /**
1445
+ * Verifies an Instructions message.
1446
+ * @function verify
1447
+ * @memberof ChatMessage.Instructions
1448
+ * @static
1449
+ * @param {Object.<string,*>} message Plain object to verify
1450
+ * @returns {string|null} `null` if valid, otherwise the reason why it is not
1451
+ */
1452
+ Instructions.verify = function verify(message) {
1453
+ if (typeof message !== 'object' || message === null) return 'object expected';
1454
+ if (message.instruction != null && message.hasOwnProperty('instruction')) if (!$util.isString(message.instruction)) return 'instruction: string expected';
1455
+ return null;
1456
+ };
1457
+
1458
+ /**
1459
+ * Creates an Instructions message from a plain object. Also converts values to their respective internal types.
1460
+ * @function fromObject
1461
+ * @memberof ChatMessage.Instructions
1462
+ * @static
1463
+ * @param {Object.<string,*>} object Plain object
1464
+ * @returns {ChatMessage.Instructions} Instructions
1465
+ */
1466
+ Instructions.fromObject = function fromObject(object) {
1467
+ if (object instanceof $root.ChatMessage.Instructions) return object;
1468
+ const message = new $root.ChatMessage.Instructions();
1469
+ if (object.instruction != null) message.instruction = String(object.instruction);
1470
+ return message;
1471
+ };
1472
+
1473
+ /**
1474
+ * Creates a plain object from an Instructions message. Also converts values to other types if specified.
1475
+ * @function toObject
1476
+ * @memberof ChatMessage.Instructions
1477
+ * @static
1478
+ * @param {ChatMessage.Instructions} message Instructions
1479
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
1480
+ * @returns {Object.<string,*>} Plain object
1481
+ */
1482
+ Instructions.toObject = function toObject(message, options) {
1483
+ if (!options) options = {};
1484
+ const object = {};
1485
+ if (options.defaults) object.instruction = '';
1486
+ if (message.instruction != null && message.hasOwnProperty('instruction')) object.instruction = message.instruction;
1487
+ return object;
1488
+ };
1489
+
1490
+ /**
1491
+ * Converts this Instructions to JSON.
1492
+ * @function toJSON
1493
+ * @memberof ChatMessage.Instructions
1494
+ * @instance
1495
+ * @returns {Object.<string,*>} JSON object
1496
+ */
1497
+ Instructions.prototype.toJSON = function toJSON() {
1498
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
1499
+ };
1500
+
1501
+ /**
1502
+ * Gets the default type url for Instructions
1503
+ * @function getTypeUrl
1504
+ * @memberof ChatMessage.Instructions
1505
+ * @static
1506
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
1507
+ * @returns {string} The default type url
1508
+ */
1509
+ Instructions.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
1510
+ if (typeUrlPrefix === undefined) {
1511
+ typeUrlPrefix = 'type.googleapis.com';
1512
+ }
1513
+ return typeUrlPrefix + '/ChatMessage.Instructions';
1514
+ };
1515
+
1516
+ return Instructions;
1517
+ })();
1518
+
1519
+ ChatMessage.Model = (function () {
1520
+ /**
1521
+ * Properties of a Model.
1522
+ * @memberof ChatMessage
1523
+ * @interface IModel
1524
+ * @property {string|null} [name] Model name
1525
+ * @property {string|null} [empty] Model empty
1526
+ */
1527
+
1528
+ /**
1529
+ * Constructs a new Model.
1530
+ * @memberof ChatMessage
1531
+ * @classdesc Represents a Model.
1532
+ * @implements IModel
1533
+ * @constructor
1534
+ * @param {ChatMessage.IModel=} [properties] Properties to set
1535
+ */
1536
+ function Model(properties) {
1537
+ if (properties) let keys = Object.keys(properties), i = 0; for (; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
1538
+ }
1539
+
1540
+ /**
1541
+ * Model name.
1542
+ * @member {string} name
1543
+ * @memberof ChatMessage.Model
1544
+ * @instance
1545
+ */
1546
+ Model.prototype.name = '';
1547
+
1548
+ /**
1549
+ * Model empty.
1550
+ * @member {string} empty
1551
+ * @memberof ChatMessage.Model
1552
+ * @instance
1553
+ */
1554
+ Model.prototype.empty = '';
1555
+
1556
+ /**
1557
+ * Creates a new Model instance using the specified properties.
1558
+ * @function create
1559
+ * @memberof ChatMessage.Model
1560
+ * @static
1561
+ * @param {ChatMessage.IModel=} [properties] Properties to set
1562
+ * @returns {ChatMessage.Model} Model instance
1563
+ */
1564
+ Model.create = function create(properties) {
1565
+ return new Model(properties);
1566
+ };
1567
+
1568
+ /**
1569
+ * Encodes the specified Model message. Does not implicitly {@link ChatMessage.Model.verify|verify} messages.
1570
+ * @function encode
1571
+ * @memberof ChatMessage.Model
1572
+ * @static
1573
+ * @param {ChatMessage.IModel} message Model message or plain object to encode
1574
+ * @param {$protobuf.Writer} [writer] Writer to encode to
1575
+ * @returns {$protobuf.Writer} Writer
1576
+ */
1577
+ Model.encode = function encode(message, writer) {
1578
+ if (!writer) writer = $Writer.create();
1579
+ if (message.name != null && Object.hasOwnProperty.call(message, 'name')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.name);
1580
+ if (message.empty != null && Object.hasOwnProperty.call(message, 'empty')) writer.uint32(/* id 4, wireType 2 =*/ 34).string(message.empty);
1581
+ return writer;
1582
+ };
1583
+
1584
+ /**
1585
+ * Encodes the specified Model message, length delimited. Does not implicitly {@link ChatMessage.Model.verify|verify} messages.
1586
+ * @function encodeDelimited
1587
+ * @memberof ChatMessage.Model
1588
+ * @static
1589
+ * @param {ChatMessage.IModel} message Model message or plain object to encode
1590
+ * @param {$protobuf.Writer} [writer] Writer to encode to
1591
+ * @returns {$protobuf.Writer} Writer
1592
+ */
1593
+ Model.encodeDelimited = function encodeDelimited(message, writer) {
1594
+ return this.encode(message, writer).ldelim();
1595
+ };
1596
+
1597
+ /**
1598
+ * Decodes a Model message from the specified reader or buffer.
1599
+ * @function decode
1600
+ * @memberof ChatMessage.Model
1601
+ * @static
1602
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1603
+ * @param {number} [length] Message length if known beforehand
1604
+ * @returns {ChatMessage.Model} Model
1605
+ * @throws {Error} If the payload is not a reader or valid buffer
1606
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1607
+ */
1608
+ Model.decode = function decode(reader, length) {
1609
+ if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
1610
+ const end = length === undefined ? reader.len : reader.pos + length,
1611
+ message = new $root.ChatMessage.Model();
1612
+ while (reader.pos < end) {
1613
+ const tag = reader.uint32();
1614
+ switch (tag >>> 3) {
1615
+ case 1: {
1616
+ message.name = reader.string();
1617
+ break;
1618
+ }
1619
+ case 4: {
1620
+ message.empty = reader.string();
1621
+ break;
1622
+ }
1623
+ default:
1624
+ reader.skipType(tag & 7);
1625
+ break;
1626
+ }
1627
+ }
1628
+ return message;
1629
+ };
1630
+
1631
+ /**
1632
+ * Decodes a Model message from the specified reader or buffer, length delimited.
1633
+ * @function decodeDelimited
1634
+ * @memberof ChatMessage.Model
1635
+ * @static
1636
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1637
+ * @returns {ChatMessage.Model} Model
1638
+ * @throws {Error} If the payload is not a reader or valid buffer
1639
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1640
+ */
1641
+ Model.decodeDelimited = function decodeDelimited(reader) {
1642
+ if (!(reader instanceof $Reader)) reader = new $Reader(reader);
1643
+ return this.decode(reader, reader.uint32());
1644
+ };
1645
+
1646
+ /**
1647
+ * Verifies a Model message.
1648
+ * @function verify
1649
+ * @memberof ChatMessage.Model
1650
+ * @static
1651
+ * @param {Object.<string,*>} message Plain object to verify
1652
+ * @returns {string|null} `null` if valid, otherwise the reason why it is not
1653
+ */
1654
+ Model.verify = function verify(message) {
1655
+ if (typeof message !== 'object' || message === null) return 'object expected';
1656
+ if (message.name != null && message.hasOwnProperty('name')) if (!$util.isString(message.name)) return 'name: string expected';
1657
+ if (message.empty != null && message.hasOwnProperty('empty')) if (!$util.isString(message.empty)) return 'empty: string expected';
1658
+ return null;
1659
+ };
1660
+
1661
+ /**
1662
+ * Creates a Model message from a plain object. Also converts values to their respective internal types.
1663
+ * @function fromObject
1664
+ * @memberof ChatMessage.Model
1665
+ * @static
1666
+ * @param {Object.<string,*>} object Plain object
1667
+ * @returns {ChatMessage.Model} Model
1668
+ */
1669
+ Model.fromObject = function fromObject(object) {
1670
+ if (object instanceof $root.ChatMessage.Model) return object;
1671
+ const message = new $root.ChatMessage.Model();
1672
+ if (object.name != null) message.name = String(object.name);
1673
+ if (object.empty != null) message.empty = String(object.empty);
1674
+ return message;
1675
+ };
1676
+
1677
+ /**
1678
+ * Creates a plain object from a Model message. Also converts values to other types if specified.
1679
+ * @function toObject
1680
+ * @memberof ChatMessage.Model
1681
+ * @static
1682
+ * @param {ChatMessage.Model} message Model
1683
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
1684
+ * @returns {Object.<string,*>} Plain object
1685
+ */
1686
+ Model.toObject = function toObject(message, options) {
1687
+ if (!options) options = {};
1688
+ const object = {};
1689
+ if (options.defaults) {
1690
+ object.name = '';
1691
+ object.empty = '';
1692
+ }
1693
+ if (message.name != null && message.hasOwnProperty('name')) object.name = message.name;
1694
+ if (message.empty != null && message.hasOwnProperty('empty')) object.empty = message.empty;
1695
+ return object;
1696
+ };
1697
+
1698
+ /**
1699
+ * Converts this Model to JSON.
1700
+ * @function toJSON
1701
+ * @memberof ChatMessage.Model
1702
+ * @instance
1703
+ * @returns {Object.<string,*>} JSON object
1704
+ */
1705
+ Model.prototype.toJSON = function toJSON() {
1706
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
1707
+ };
1708
+
1709
+ /**
1710
+ * Gets the default type url for Model
1711
+ * @function getTypeUrl
1712
+ * @memberof ChatMessage.Model
1713
+ * @static
1714
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
1715
+ * @returns {string} The default type url
1716
+ */
1717
+ Model.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
1718
+ if (typeUrlPrefix === undefined) {
1719
+ typeUrlPrefix = 'type.googleapis.com';
1720
+ }
1721
+ return typeUrlPrefix + '/ChatMessage.Model';
1722
+ };
1723
+
1724
+ return Model;
1725
+ })();
1726
+
1727
+ return ChatMessage;
1728
+ })();
1729
+
1730
+ $root.ResMessage = (function () {
1731
+ /**
1732
+ * Properties of a ResMessage.
1733
+ * @exports IResMessage
1734
+ * @interface IResMessage
1735
+ * @property {string|null} [msg] ResMessage msg
1736
+ */
1737
+
1738
+ /**
1739
+ * Constructs a new ResMessage.
1740
+ * @exports ResMessage
1741
+ * @classdesc Represents a ResMessage.
1742
+ * @implements IResMessage
1743
+ * @constructor
1744
+ * @param {IResMessage=} [properties] Properties to set
1745
+ */
1746
+ function ResMessage(properties) {
1747
+ if (properties) let keys = Object.keys(properties), i = 0; for (; i < keys.length; ++i) if (properties[keys[i]] != null) this[keys[i]] = properties[keys[i]];
1748
+ }
1749
+
1750
+ /**
1751
+ * ResMessage msg.
1752
+ * @member {string} msg
1753
+ * @memberof ResMessage
1754
+ * @instance
1755
+ */
1756
+ ResMessage.prototype.msg = '';
1757
+
1758
+ /**
1759
+ * Creates a new ResMessage instance using the specified properties.
1760
+ * @function create
1761
+ * @memberof ResMessage
1762
+ * @static
1763
+ * @param {IResMessage=} [properties] Properties to set
1764
+ * @returns {ResMessage} ResMessage instance
1765
+ */
1766
+ ResMessage.create = function create(properties) {
1767
+ return new ResMessage(properties);
1768
+ };
1769
+
1770
+ /**
1771
+ * Encodes the specified ResMessage message. Does not implicitly {@link ResMessage.verify|verify} messages.
1772
+ * @function encode
1773
+ * @memberof ResMessage
1774
+ * @static
1775
+ * @param {IResMessage} message ResMessage message or plain object to encode
1776
+ * @param {$protobuf.Writer} [writer] Writer to encode to
1777
+ * @returns {$protobuf.Writer} Writer
1778
+ */
1779
+ ResMessage.encode = function encode(message, writer) {
1780
+ if (!writer) writer = $Writer.create();
1781
+ if (message.msg != null && Object.hasOwnProperty.call(message, 'msg')) writer.uint32(/* id 1, wireType 2 =*/ 10).string(message.msg);
1782
+ return writer;
1783
+ };
1784
+
1785
+ /**
1786
+ * Encodes the specified ResMessage message, length delimited. Does not implicitly {@link ResMessage.verify|verify} messages.
1787
+ * @function encodeDelimited
1788
+ * @memberof ResMessage
1789
+ * @static
1790
+ * @param {IResMessage} message ResMessage message or plain object to encode
1791
+ * @param {$protobuf.Writer} [writer] Writer to encode to
1792
+ * @returns {$protobuf.Writer} Writer
1793
+ */
1794
+ ResMessage.encodeDelimited = function encodeDelimited(message, writer) {
1795
+ return this.encode(message, writer).ldelim();
1796
+ };
1797
+
1798
+ /**
1799
+ * Decodes a ResMessage message from the specified reader or buffer.
1800
+ * @function decode
1801
+ * @memberof ResMessage
1802
+ * @static
1803
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1804
+ * @param {number} [length] Message length if known beforehand
1805
+ * @returns {ResMessage} ResMessage
1806
+ * @throws {Error} If the payload is not a reader or valid buffer
1807
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1808
+ */
1809
+ ResMessage.decode = function decode(reader, length) {
1810
+ if (!(reader instanceof $Reader)) reader = $Reader.create(reader);
1811
+ const end = length === undefined ? reader.len : reader.pos + length,
1812
+ message = new $root.ResMessage();
1813
+ while (reader.pos < end) {
1814
+ const tag = reader.uint32();
1815
+ switch (tag >>> 3) {
1816
+ case 1: {
1817
+ message.msg = reader.string();
1818
+ break;
1819
+ }
1820
+ default:
1821
+ reader.skipType(tag & 7);
1822
+ break;
1823
+ }
1824
+ }
1825
+ return message;
1826
+ };
1827
+
1828
+ /**
1829
+ * Decodes a ResMessage message from the specified reader or buffer, length delimited.
1830
+ * @function decodeDelimited
1831
+ * @memberof ResMessage
1832
+ * @static
1833
+ * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
1834
+ * @returns {ResMessage} ResMessage
1835
+ * @throws {Error} If the payload is not a reader or valid buffer
1836
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
1837
+ */
1838
+ ResMessage.decodeDelimited = function decodeDelimited(reader) {
1839
+ if (!(reader instanceof $Reader)) reader = new $Reader(reader);
1840
+ return this.decode(reader, reader.uint32());
1841
+ };
1842
+
1843
+ /**
1844
+ * Verifies a ResMessage message.
1845
+ * @function verify
1846
+ * @memberof ResMessage
1847
+ * @static
1848
+ * @param {Object.<string,*>} message Plain object to verify
1849
+ * @returns {string|null} `null` if valid, otherwise the reason why it is not
1850
+ */
1851
+ ResMessage.verify = function verify(message) {
1852
+ if (typeof message !== 'object' || message === null) return 'object expected';
1853
+ if (message.msg != null && message.hasOwnProperty('msg')) if (!$util.isString(message.msg)) return 'msg: string expected';
1854
+ return null;
1855
+ };
1856
+
1857
+ /**
1858
+ * Creates a ResMessage message from a plain object. Also converts values to their respective internal types.
1859
+ * @function fromObject
1860
+ * @memberof ResMessage
1861
+ * @static
1862
+ * @param {Object.<string,*>} object Plain object
1863
+ * @returns {ResMessage} ResMessage
1864
+ */
1865
+ ResMessage.fromObject = function fromObject(object) {
1866
+ if (object instanceof $root.ResMessage) return object;
1867
+ const message = new $root.ResMessage();
1868
+ if (object.msg != null) message.msg = String(object.msg);
1869
+ return message;
1870
+ };
1871
+
1872
+ /**
1873
+ * Creates a plain object from a ResMessage message. Also converts values to other types if specified.
1874
+ * @function toObject
1875
+ * @memberof ResMessage
1876
+ * @static
1877
+ * @param {ResMessage} message ResMessage
1878
+ * @param {$protobuf.IConversionOptions} [options] Conversion options
1879
+ * @returns {Object.<string,*>} Plain object
1880
+ */
1881
+ ResMessage.toObject = function toObject(message, options) {
1882
+ if (!options) options = {};
1883
+ const object = {};
1884
+ if (options.defaults) object.msg = '';
1885
+ if (message.msg != null && message.hasOwnProperty('msg')) object.msg = message.msg;
1886
+ return object;
1887
+ };
1888
+
1889
+ /**
1890
+ * Converts this ResMessage to JSON.
1891
+ * @function toJSON
1892
+ * @memberof ResMessage
1893
+ * @instance
1894
+ * @returns {Object.<string,*>} JSON object
1895
+ */
1896
+ ResMessage.prototype.toJSON = function toJSON() {
1897
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
1898
+ };
1899
+
1900
+ /**
1901
+ * Gets the default type url for ResMessage
1902
+ * @function getTypeUrl
1903
+ * @memberof ResMessage
1904
+ * @static
1905
+ * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
1906
+ * @returns {string} The default type url
1907
+ */
1908
+ ResMessage.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
1909
+ if (typeUrlPrefix === undefined) {
1910
+ typeUrlPrefix = 'type.googleapis.com';
1911
+ }
1912
+ return typeUrlPrefix + '/ResMessage';
1913
+ };
1914
+
1915
+ return ResMessage;
1916
+ })();
1917
+
1918
+ 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; // Maybe it's empty, describing what the session did, but it's not a title, and it might be used as an additional setting
46
+ string conversationId = 15; // Here's another one 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 Russian',
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
+ };