Spaces:
Paused
Paused
Update app.js
Browse files
app.js
CHANGED
|
@@ -1,83 +1,91 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const { v4: uuidv4 } = require('uuid');
|
| 3 |
const zlib = require('zlib');
|
| 4 |
-
const
|
| 5 |
|
| 6 |
-
//
|
| 7 |
-
const
|
| 8 |
-
const $Writer = $protobuf.Writer;
|
| 9 |
-
const $util = $protobuf.util;
|
| 10 |
-
const $root = $protobuf.roots['default'] || ($protobuf.roots['default'] = {});
|
| 11 |
|
| 12 |
// Proto 消息定义
|
| 13 |
const ChatMessageDefinition = {
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
}
|
|
|
|
|
|
|
|
|
|
| 33 |
},
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
}
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
}
|
| 59 |
}
|
| 60 |
},
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
model: { type: "Model", id: 7 },
|
| 66 |
-
requestId: { type: "string", id: 9 },
|
| 67 |
-
summary: { type: "string", id: 11 },
|
| 68 |
-
conversationId: { type: "string", id: 15 }
|
| 69 |
-
}
|
| 70 |
-
},
|
| 71 |
-
ResMessage: {
|
| 72 |
-
fields: {
|
| 73 |
-
msg: { type: "string", id: 1 }
|
| 74 |
}
|
| 75 |
}
|
| 76 |
};
|
| 77 |
|
| 78 |
-
//
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
// 工具函数
|
| 83 |
const regex = /<\|BEGIN_SYSTEM\|>.*?<\|END_SYSTEM\|>.*?<\|BEGIN_USER\|>.*?<\|END_USER\|>/s;
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const { v4: uuidv4 } = require('uuid');
|
| 3 |
const zlib = require('zlib');
|
| 4 |
+
const protobuf = require('protobufjs');
|
| 5 |
|
| 6 |
+
// 创建一个新的 Root 实例
|
| 7 |
+
const root = new protobuf.Root();
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
// Proto 消息定义
|
| 10 |
const ChatMessageDefinition = {
|
| 11 |
+
nested: {
|
| 12 |
+
ChatMessage: {
|
| 13 |
+
fields: {
|
| 14 |
+
messages: { rule: "repeated", type: "UserMessage", id: 2 },
|
| 15 |
+
instructions: { type: "Instructions", id: 4 },
|
| 16 |
+
projectPath: { type: "string", id: 5 },
|
| 17 |
+
model: { type: "Model", id: 7 },
|
| 18 |
+
requestId: { type: "string", id: 9 },
|
| 19 |
+
summary: { type: "string", id: 11 },
|
| 20 |
+
conversationId: { type: "string", id: 15 }
|
| 21 |
+
},
|
| 22 |
+
nested: {
|
| 23 |
+
FileContent: {
|
| 24 |
+
fields: {
|
| 25 |
+
filename: { type: "string", id: 1 },
|
| 26 |
+
content: { type: "string", id: 2 },
|
| 27 |
+
position: { type: "Position", id: 3 },
|
| 28 |
+
language: { type: "string", id: 5 },
|
| 29 |
+
range: { type: "Range", id: 6 },
|
| 30 |
+
length: { type: "int32", id: 8 },
|
| 31 |
+
type: { type: "int32", id: 9 },
|
| 32 |
+
error_code: { type: "int32", id: 11 }
|
| 33 |
},
|
| 34 |
+
nested: {
|
| 35 |
+
Position: {
|
| 36 |
+
fields: {
|
| 37 |
+
line: { type: "int32", id: 1 },
|
| 38 |
+
column: { type: "int32", id: 2 }
|
| 39 |
+
}
|
| 40 |
+
},
|
| 41 |
+
Range: {
|
| 42 |
+
fields: {
|
| 43 |
+
start: { type: "Position", id: 1 },
|
| 44 |
+
end: { type: "Position", id: 2 }
|
| 45 |
+
}
|
| 46 |
}
|
| 47 |
}
|
| 48 |
+
},
|
| 49 |
+
UserMessage: {
|
| 50 |
+
fields: {
|
| 51 |
+
content: { type: "string", id: 1 },
|
| 52 |
+
role: { type: "int32", id: 2 },
|
| 53 |
+
message_id: { type: "string", id: 13 }
|
| 54 |
+
}
|
| 55 |
+
},
|
| 56 |
+
Instructions: {
|
| 57 |
+
fields: {
|
| 58 |
+
instruction: { type: "string", id: 1 }
|
| 59 |
+
}
|
| 60 |
+
},
|
| 61 |
+
Model: {
|
| 62 |
+
fields: {
|
| 63 |
+
name: { type: "string", id: 1 },
|
| 64 |
+
empty: { type: "string", id: 4 }
|
| 65 |
+
}
|
| 66 |
}
|
| 67 |
}
|
| 68 |
},
|
| 69 |
+
ResMessage: {
|
| 70 |
+
fields: {
|
| 71 |
+
msg: { type: "string", id: 1 }
|
| 72 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
| 74 |
}
|
| 75 |
};
|
| 76 |
|
| 77 |
+
// 加载消息类型定义
|
| 78 |
+
root.define("ChatMessage").add(ChatMessageDefinition);
|
| 79 |
+
|
| 80 |
+
// 获取消息类型
|
| 81 |
+
const ChatMessage = root.lookupType("ChatMessage");
|
| 82 |
+
const ResMessage = root.lookupType("ResMessage");
|
| 83 |
+
|
| 84 |
+
// 替换原来的 $root 对象
|
| 85 |
+
const $root = {
|
| 86 |
+
ChatMessage,
|
| 87 |
+
ResMessage
|
| 88 |
+
};
|
| 89 |
|
| 90 |
// 工具函数
|
| 91 |
const regex = /<\|BEGIN_SYSTEM\|>.*?<\|END_SYSTEM\|>.*?<\|BEGIN_USER\|>.*?<\|END_USER\|>/s;
|