smgc commited on
Commit
afb60d2
·
verified ·
1 Parent(s): 1198080

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +71 -63
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 $protobuf = require('protobufjs/minimal');
5
 
6
- // 初始化 protobuf
7
- const $Reader = $protobuf.Reader;
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
- ChatMessage: {
15
- nested: {
16
- FileContent: {
17
- fields: {
18
- filename: { type: "string", id: 1 },
19
- content: { type: "string", id: 2 },
20
- position: { type: "Position", id: 3 },
21
- language: { type: "string", id: 5 },
22
- range: { type: "Range", id: 6 },
23
- length: { type: "int32", id: 8 },
24
- type: { type: "int32", id: 9 },
25
- error_code: { type: "int32", id: 11 }
26
- },
27
- nested: {
28
- Position: {
29
- fields: {
30
- line: { type: "int32", id: 1 },
31
- column: { type: "int32", id: 2 }
32
- }
 
 
 
33
  },
34
- Range: {
35
- fields: {
36
- start: { type: "Position", id: 1 },
37
- end: { type: "Position", id: 2 }
 
 
 
 
 
 
 
 
38
  }
39
  }
40
- }
41
- },
42
- UserMessage: {
43
- fields: {
44
- content: { type: "string", id: 1 },
45
- role: { type: "int32", id: 2 },
46
- message_id: { type: "string", id: 13 }
47
- }
48
- },
49
- Instructions: {
50
- fields: {
51
- instruction: { type: "string", id: 1 }
52
- }
53
- },
54
- Model: {
55
- fields: {
56
- name: { type: "string", id: 1 },
57
- empty: { type: "string", id: 4 }
58
  }
59
  }
60
  },
61
- fields: {
62
- messages: { rule: "repeated", type: "UserMessage", id: 2 },
63
- instructions: { type: "Instructions", id: 4 },
64
- projectPath: { type: "string", id: 5 },
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
- $root.ChatMessage = $protobuf.Root.fromJSON(ChatMessageDefinition).lookupType("ChatMessage");
80
- $root.ResMessage = $protobuf.Root.fromJSON(ChatMessageDefinition).lookupType("ResMessage");
 
 
 
 
 
 
 
 
 
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;