@librechat/agents 1.9.95 → 1.9.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/main.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  var run = require('./run.cjs');
4
4
  var stream = require('./stream.cjs');
5
+ var splitStream = require('./splitStream.cjs');
5
6
  var events = require('./events.cjs');
6
7
  var messages = require('./messages.cjs');
7
8
  var Graph = require('./graphs/Graph.cjs');
@@ -17,6 +18,8 @@ exports.Run = run.Run;
17
18
  exports.ChatModelStreamHandler = stream.ChatModelStreamHandler;
18
19
  exports.createContentAggregator = stream.createContentAggregator;
19
20
  exports.handleToolCalls = stream.handleToolCalls;
21
+ exports.SEPARATORS = splitStream.SEPARATORS;
22
+ exports.SplitStreamHandler = splitStream.SplitStreamHandler;
20
23
  exports.HandlerRegistry = events.HandlerRegistry;
21
24
  exports.LLMStreamHandler = events.LLMStreamHandler;
22
25
  exports.ModelEndHandler = events.ModelEndHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"main.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"main.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,175 @@
1
+ 'use strict';
2
+
3
+ var nanoid = require('nanoid');
4
+ var _enum = require('./common/enum.cjs');
5
+
6
+ const SEPARATORS = ['.', '?', '!', '۔', '。', '‥', ';', '¡', '¿', '\n', '```'];
7
+ class SplitStreamHandler {
8
+ inCodeBlock = false;
9
+ inThinkBlock = false;
10
+ accumulate;
11
+ tokens = [];
12
+ lastToken = '';
13
+ reasoningTokens = [];
14
+ currentStepId;
15
+ currentMessageId;
16
+ currentType;
17
+ currentLength = 0;
18
+ reasoningKey = 'reasoning_content';
19
+ currentIndex = -1;
20
+ blockThreshold = 4500;
21
+ /** The run ID AKA the Message ID associated with the complete generation */
22
+ runId;
23
+ handlers;
24
+ constructor({ runId, handlers, accumulate, reasoningKey, blockThreshold, }) {
25
+ this.runId = runId;
26
+ this.handlers = handlers;
27
+ if (reasoningKey) {
28
+ this.reasoningKey = reasoningKey;
29
+ }
30
+ if (blockThreshold != null) {
31
+ this.blockThreshold = blockThreshold;
32
+ }
33
+ this.accumulate = accumulate ?? false;
34
+ }
35
+ getMessageId = () => {
36
+ const messageId = this.currentMessageId;
37
+ if (messageId != null && messageId) {
38
+ return messageId;
39
+ }
40
+ return undefined;
41
+ };
42
+ createMessageStep = (type) => {
43
+ if (type != null && this.currentType !== type) {
44
+ this.currentType = type;
45
+ }
46
+ this.currentLength = 0;
47
+ this.currentIndex += 1;
48
+ this.currentStepId = `step_${nanoid.nanoid()}`;
49
+ this.currentMessageId = `msg_${nanoid.nanoid()}`;
50
+ return [this.currentStepId, this.currentMessageId];
51
+ };
52
+ dispatchRunStep = (stepId, stepDetails) => {
53
+ const runStep = {
54
+ id: stepId,
55
+ runId: this.runId,
56
+ type: stepDetails.type,
57
+ index: this.currentIndex,
58
+ stepDetails,
59
+ // usage: null,
60
+ };
61
+ this.handlers?.[_enum.GraphEvents.ON_RUN_STEP]?.({ event: _enum.GraphEvents.ON_RUN_STEP, data: runStep });
62
+ };
63
+ dispatchMessageDelta = (stepId, delta) => {
64
+ const messageDelta = {
65
+ id: stepId,
66
+ delta,
67
+ };
68
+ this.handlers?.[_enum.GraphEvents.ON_MESSAGE_DELTA]?.({ event: _enum.GraphEvents.ON_MESSAGE_DELTA, data: messageDelta });
69
+ };
70
+ dispatchReasoningDelta = (stepId, delta) => {
71
+ const reasoningDelta = {
72
+ id: stepId,
73
+ delta,
74
+ };
75
+ this.handlers?.[_enum.GraphEvents.ON_REASONING_DELTA]?.({ event: _enum.GraphEvents.ON_REASONING_DELTA, data: reasoningDelta });
76
+ };
77
+ handleContent = (content, stepId, _type) => {
78
+ let type = _type;
79
+ if (this.inThinkBlock && type === _enum.ContentTypes.TEXT) {
80
+ type = _enum.ContentTypes.THINK;
81
+ }
82
+ if (this.accumulate) {
83
+ if (type === _enum.ContentTypes.THINK) {
84
+ this.reasoningTokens.push(content);
85
+ }
86
+ else {
87
+ this.tokens.push(content);
88
+ }
89
+ }
90
+ if (this.currentType !== type) {
91
+ const [newStepId, newMessageId] = this.createMessageStep(type);
92
+ this.dispatchRunStep(newStepId, {
93
+ type: _enum.StepTypes.MESSAGE_CREATION,
94
+ message_creation: {
95
+ message_id: newMessageId,
96
+ },
97
+ });
98
+ }
99
+ if (content.includes('```')) {
100
+ this.inCodeBlock = !this.inCodeBlock;
101
+ }
102
+ this.currentLength += content.length;
103
+ if (type === _enum.ContentTypes.THINK) {
104
+ this.dispatchReasoningDelta(stepId, {
105
+ content: [{
106
+ type: _enum.ContentTypes.THINK,
107
+ think: content,
108
+ }],
109
+ });
110
+ }
111
+ else {
112
+ this.dispatchMessageDelta(stepId, {
113
+ content: [{
114
+ type: _enum.ContentTypes.TEXT,
115
+ text: content,
116
+ }],
117
+ });
118
+ }
119
+ if (this.inCodeBlock) {
120
+ return;
121
+ }
122
+ if (this.currentLength > this.blockThreshold && SEPARATORS.some(sep => content.includes(sep))) {
123
+ const [newStepId, newMessageId] = this.createMessageStep(type);
124
+ this.dispatchRunStep(newStepId, {
125
+ type: _enum.StepTypes.MESSAGE_CREATION,
126
+ message_creation: {
127
+ message_id: newMessageId,
128
+ },
129
+ });
130
+ }
131
+ };
132
+ handle(chunk) {
133
+ if (!chunk) {
134
+ return;
135
+ }
136
+ const content = chunk.choices?.[0]?.delta.content ?? '';
137
+ const reasoning_content = chunk.choices?.[0]?.delta[this.reasoningKey] ?? '';
138
+ if (!content.length && !reasoning_content.length) {
139
+ return;
140
+ }
141
+ if (content === '<think>' && !this.inCodeBlock) {
142
+ this.inThinkBlock = true;
143
+ }
144
+ else if (this.lastToken === '</think>' && !this.inCodeBlock) {
145
+ this.inThinkBlock = false;
146
+ }
147
+ this.lastToken = content;
148
+ const message_id = this.getMessageId() ?? '';
149
+ if (!message_id) {
150
+ const initialContentType = this.inThinkBlock ? _enum.ContentTypes.THINK : _enum.ContentTypes.TEXT;
151
+ const initialType = reasoning_content ? _enum.ContentTypes.THINK : initialContentType;
152
+ const [stepId, message_id] = this.createMessageStep(initialType);
153
+ this.dispatchRunStep(stepId, {
154
+ type: _enum.StepTypes.MESSAGE_CREATION,
155
+ message_creation: {
156
+ message_id,
157
+ },
158
+ });
159
+ }
160
+ const stepId = this.currentStepId ?? '';
161
+ if (!stepId) {
162
+ return;
163
+ }
164
+ if (reasoning_content) {
165
+ this.handleContent(reasoning_content, stepId, _enum.ContentTypes.THINK);
166
+ }
167
+ else {
168
+ this.handleContent(content, stepId, _enum.ContentTypes.TEXT);
169
+ }
170
+ }
171
+ }
172
+
173
+ exports.SEPARATORS = SEPARATORS;
174
+ exports.SplitStreamHandler = SplitStreamHandler;
175
+ //# sourceMappingURL=splitStream.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitStream.cjs","sources":["../../src/splitStream.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport type * as t from '@/types';\nimport { ContentTypes, GraphEvents, StepTypes } from '@/common';\n\nexport const SEPARATORS = ['.', '?', '!', '۔', '。', '‥', ';', '¡', '¿', '\\n', '```'];\n\nexport class SplitStreamHandler {\n private inCodeBlock = false;\n private inThinkBlock = false;\n private accumulate: boolean;\n tokens: string[] = [];\n lastToken = '';\n reasoningTokens: string[] = [];\n currentStepId?: string;\n currentMessageId?: string;\n currentType?: ContentTypes.TEXT | ContentTypes.THINK;\n currentLength = 0;\n reasoningKey: 'reasoning_content' | 'reasoning' = 'reasoning_content';\n currentIndex = -1;\n blockThreshold = 4500;\n /** The run ID AKA the Message ID associated with the complete generation */\n runId: string;\n handlers?: t.SplitStreamHandlers;\n constructor({\n runId,\n handlers,\n accumulate,\n reasoningKey,\n blockThreshold,\n }: {\n runId: string,\n accumulate?: boolean,\n handlers: t.SplitStreamHandlers\n blockThreshold?: number,\n reasoningKey?: 'reasoning_content' | 'reasoning',\n }) {\n this.runId = runId;\n this.handlers = handlers;\n if (reasoningKey) {\n this.reasoningKey = reasoningKey;\n }\n if (blockThreshold != null) {\n this.blockThreshold = blockThreshold;\n }\n this.accumulate = accumulate ?? false;\n }\n getMessageId = (): string | undefined => {\n const messageId = this.currentMessageId;\n if (messageId != null && messageId) {\n return messageId;\n }\n return undefined;\n };\n createMessageStep = (type?: ContentTypes.TEXT | ContentTypes.THINK): [string, string] => {\n if (type != null && this.currentType !== type) {\n this.currentType = type;\n }\n this.currentLength = 0;\n this.currentIndex += 1;\n this.currentStepId = `step_${nanoid()}`;\n this.currentMessageId = `msg_${nanoid()}`;\n return [this.currentStepId, this.currentMessageId];\n };\n dispatchRunStep = (stepId: string, stepDetails: t.StepDetails): void => {\n const runStep: t.RunStep = {\n id: stepId,\n runId: this.runId,\n type: stepDetails.type,\n index: this.currentIndex,\n stepDetails,\n // usage: null,\n };\n this.handlers?.[GraphEvents.ON_RUN_STEP]?.({ event: GraphEvents.ON_RUN_STEP, data: runStep });\n };\n dispatchMessageDelta = (stepId: string, delta: t.MessageDelta): void => {\n const messageDelta: t.MessageDeltaEvent = {\n id: stepId,\n delta,\n };\n this.handlers?.[GraphEvents.ON_MESSAGE_DELTA]?.({ event: GraphEvents.ON_MESSAGE_DELTA, data: messageDelta });\n };\n dispatchReasoningDelta = (stepId: string, delta: t.ReasoningDelta): void => {\n const reasoningDelta: t.ReasoningDeltaEvent = {\n id: stepId,\n delta,\n };\n this.handlers?.[GraphEvents.ON_REASONING_DELTA]?.({ event: GraphEvents.ON_REASONING_DELTA, data: reasoningDelta });\n };\n handleContent = (content: string, stepId: string, _type: ContentTypes.TEXT | ContentTypes.THINK): void => {\n let type = _type;\n if (this.inThinkBlock && type === ContentTypes.TEXT) {\n type = ContentTypes.THINK;\n }\n if (this.accumulate) {\n if (type === ContentTypes.THINK) {\n this.reasoningTokens.push(content);\n } else {\n this.tokens.push(content);\n }\n }\n\n if (this.currentType !== type) {\n const [newStepId, newMessageId] = this.createMessageStep(type);\n this.dispatchRunStep(newStepId, {\n type: StepTypes.MESSAGE_CREATION,\n message_creation: {\n message_id: newMessageId,\n },\n });\n }\n\n if (content.includes('```')) {\n this.inCodeBlock = !this.inCodeBlock;\n }\n\n this.currentLength += content.length;\n\n if (type === ContentTypes.THINK) {\n this.dispatchReasoningDelta(stepId, {\n content: [{\n type: ContentTypes.THINK,\n think: content,\n }],\n });\n } else {\n this.dispatchMessageDelta(stepId, {\n content: [{\n type: ContentTypes.TEXT,\n text: content,\n }],\n });\n }\n\n if (this.inCodeBlock) {\n return;\n }\n\n if (this.currentLength > this.blockThreshold && SEPARATORS.some(sep => content.includes(sep))) {\n const [newStepId, newMessageId] = this.createMessageStep(type);\n this.dispatchRunStep(newStepId, {\n type: StepTypes.MESSAGE_CREATION,\n message_creation: {\n message_id: newMessageId,\n },\n });\n }\n };\n handle(chunk?: t.CustomChunk): void {\n if (!chunk) {\n return;\n }\n\n const content = chunk.choices?.[0]?.delta.content ?? '';\n const reasoning_content = chunk.choices?.[0]?.delta[this.reasoningKey] ?? '';\n\n if (!content.length && !reasoning_content.length) {\n return;\n }\n\n if (content === '<think>' && !this.inCodeBlock) {\n this.inThinkBlock = true;\n } else if (this.lastToken === '</think>' && !this.inCodeBlock) {\n this.inThinkBlock = false;\n }\n\n this.lastToken = content;\n\n const message_id = this.getMessageId() ?? '';\n\n if (!message_id) {\n const initialContentType = this.inThinkBlock ? ContentTypes.THINK : ContentTypes.TEXT;\n const initialType = reasoning_content ? ContentTypes.THINK : initialContentType;\n const [stepId, message_id] = this.createMessageStep(initialType);\n this.dispatchRunStep(stepId, {\n type: StepTypes.MESSAGE_CREATION,\n message_creation: {\n message_id,\n },\n });\n }\n\n const stepId = this.currentStepId ?? '';\n if (!stepId) {\n return;\n }\n\n if (reasoning_content) {\n this.handleContent(reasoning_content, stepId, ContentTypes.THINK);\n } else {\n this.handleContent(content, stepId, ContentTypes.TEXT);\n }\n }\n}"],"names":["nanoid","GraphEvents","ContentTypes","StepTypes"],"mappings":";;;;;AAIa,MAAA,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE;MAExE,kBAAkB,CAAA;IACrB,WAAW,GAAG,KAAK,CAAC;IACpB,YAAY,GAAG,KAAK,CAAC;AACrB,IAAA,UAAU,CAAU;IAC5B,MAAM,GAAa,EAAE,CAAC;IACtB,SAAS,GAAG,EAAE,CAAC;IACf,eAAe,GAAa,EAAE,CAAC;AAC/B,IAAA,aAAa,CAAU;AACvB,IAAA,gBAAgB,CAAU;AAC1B,IAAA,WAAW,CAA0C;IACrD,aAAa,GAAG,CAAC,CAAC;IAClB,YAAY,GAAsC,mBAAmB,CAAC;IACtE,YAAY,GAAG,CAAC,CAAC,CAAC;IAClB,cAAc,GAAG,IAAI,CAAC;;AAEtB,IAAA,KAAK,CAAS;AACd,IAAA,QAAQ,CAAyB;IACjC,WAAY,CAAA,EACV,KAAK,EACL,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,cAAc,GAOb,EAAA;AACD,QAAA,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AACnB,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,YAAY,EAAE;AAChB,YAAA,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;SAClC;AACD,QAAA,IAAI,cAAc,IAAI,IAAI,EAAE;AAC1B,YAAA,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;SACtC;AACD,QAAA,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI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,gBAAgB;AAChC,gBAAA,gBAAgB,EAAE;oBAChB,UAAU;AACX,iBAAA;AACF,aAAA,CAAC,CAAC;SACJ;AAED,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC,MAAM,EAAE;YACX,OAAO;SACR;QAED,IAAI,iBAAiB,EAAE;YACrB,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE,MAAM,EAAED,kBAAY,CAAC,KAAK,CAAC,CAAC;SACnE;aAAM;YACL,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAEA,kBAAY,CAAC,IAAI,CAAC,CAAC;SACxD;KACF;AACF;;;;;"}
package/dist/esm/main.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Run } from './run.mjs';
2
2
  export { ChatModelStreamHandler, createContentAggregator, handleToolCalls } from './stream.mjs';
3
+ export { SEPARATORS, SplitStreamHandler } from './splitStream.mjs';
3
4
  export { HandlerRegistry, LLMStreamHandler, ModelEndHandler, TestChatStreamHandler, TestLLMStreamHandler, ToolEndHandler, createMetadataAggregator } from './events.mjs';
4
5
  export { convertMessagesToContent, findLastIndex, formatAnthropicArtifactContent, formatAnthropicMessage, formatOpenAIArtifactContent, getConverseOverrideMessage, modifyDeltaProperties } from './messages.mjs';
5
6
  export { Graph, StandardGraph } from './graphs/Graph.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
1
+ {"version":3,"file":"main.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
@@ -0,0 +1,172 @@
1
+ import { nanoid } from 'nanoid';
2
+ import { GraphEvents, ContentTypes, StepTypes } from './common/enum.mjs';
3
+
4
+ const SEPARATORS = ['.', '?', '!', '۔', '。', '‥', ';', '¡', '¿', '\n', '```'];
5
+ class SplitStreamHandler {
6
+ inCodeBlock = false;
7
+ inThinkBlock = false;
8
+ accumulate;
9
+ tokens = [];
10
+ lastToken = '';
11
+ reasoningTokens = [];
12
+ currentStepId;
13
+ currentMessageId;
14
+ currentType;
15
+ currentLength = 0;
16
+ reasoningKey = 'reasoning_content';
17
+ currentIndex = -1;
18
+ blockThreshold = 4500;
19
+ /** The run ID AKA the Message ID associated with the complete generation */
20
+ runId;
21
+ handlers;
22
+ constructor({ runId, handlers, accumulate, reasoningKey, blockThreshold, }) {
23
+ this.runId = runId;
24
+ this.handlers = handlers;
25
+ if (reasoningKey) {
26
+ this.reasoningKey = reasoningKey;
27
+ }
28
+ if (blockThreshold != null) {
29
+ this.blockThreshold = blockThreshold;
30
+ }
31
+ this.accumulate = accumulate ?? false;
32
+ }
33
+ getMessageId = () => {
34
+ const messageId = this.currentMessageId;
35
+ if (messageId != null && messageId) {
36
+ return messageId;
37
+ }
38
+ return undefined;
39
+ };
40
+ createMessageStep = (type) => {
41
+ if (type != null && this.currentType !== type) {
42
+ this.currentType = type;
43
+ }
44
+ this.currentLength = 0;
45
+ this.currentIndex += 1;
46
+ this.currentStepId = `step_${nanoid()}`;
47
+ this.currentMessageId = `msg_${nanoid()}`;
48
+ return [this.currentStepId, this.currentMessageId];
49
+ };
50
+ dispatchRunStep = (stepId, stepDetails) => {
51
+ const runStep = {
52
+ id: stepId,
53
+ runId: this.runId,
54
+ type: stepDetails.type,
55
+ index: this.currentIndex,
56
+ stepDetails,
57
+ // usage: null,
58
+ };
59
+ this.handlers?.[GraphEvents.ON_RUN_STEP]?.({ event: GraphEvents.ON_RUN_STEP, data: runStep });
60
+ };
61
+ dispatchMessageDelta = (stepId, delta) => {
62
+ const messageDelta = {
63
+ id: stepId,
64
+ delta,
65
+ };
66
+ this.handlers?.[GraphEvents.ON_MESSAGE_DELTA]?.({ event: GraphEvents.ON_MESSAGE_DELTA, data: messageDelta });
67
+ };
68
+ dispatchReasoningDelta = (stepId, delta) => {
69
+ const reasoningDelta = {
70
+ id: stepId,
71
+ delta,
72
+ };
73
+ this.handlers?.[GraphEvents.ON_REASONING_DELTA]?.({ event: GraphEvents.ON_REASONING_DELTA, data: reasoningDelta });
74
+ };
75
+ handleContent = (content, stepId, _type) => {
76
+ let type = _type;
77
+ if (this.inThinkBlock && type === ContentTypes.TEXT) {
78
+ type = ContentTypes.THINK;
79
+ }
80
+ if (this.accumulate) {
81
+ if (type === ContentTypes.THINK) {
82
+ this.reasoningTokens.push(content);
83
+ }
84
+ else {
85
+ this.tokens.push(content);
86
+ }
87
+ }
88
+ if (this.currentType !== type) {
89
+ const [newStepId, newMessageId] = this.createMessageStep(type);
90
+ this.dispatchRunStep(newStepId, {
91
+ type: StepTypes.MESSAGE_CREATION,
92
+ message_creation: {
93
+ message_id: newMessageId,
94
+ },
95
+ });
96
+ }
97
+ if (content.includes('```')) {
98
+ this.inCodeBlock = !this.inCodeBlock;
99
+ }
100
+ this.currentLength += content.length;
101
+ if (type === ContentTypes.THINK) {
102
+ this.dispatchReasoningDelta(stepId, {
103
+ content: [{
104
+ type: ContentTypes.THINK,
105
+ think: content,
106
+ }],
107
+ });
108
+ }
109
+ else {
110
+ this.dispatchMessageDelta(stepId, {
111
+ content: [{
112
+ type: ContentTypes.TEXT,
113
+ text: content,
114
+ }],
115
+ });
116
+ }
117
+ if (this.inCodeBlock) {
118
+ return;
119
+ }
120
+ if (this.currentLength > this.blockThreshold && SEPARATORS.some(sep => content.includes(sep))) {
121
+ const [newStepId, newMessageId] = this.createMessageStep(type);
122
+ this.dispatchRunStep(newStepId, {
123
+ type: StepTypes.MESSAGE_CREATION,
124
+ message_creation: {
125
+ message_id: newMessageId,
126
+ },
127
+ });
128
+ }
129
+ };
130
+ handle(chunk) {
131
+ if (!chunk) {
132
+ return;
133
+ }
134
+ const content = chunk.choices?.[0]?.delta.content ?? '';
135
+ const reasoning_content = chunk.choices?.[0]?.delta[this.reasoningKey] ?? '';
136
+ if (!content.length && !reasoning_content.length) {
137
+ return;
138
+ }
139
+ if (content === '<think>' && !this.inCodeBlock) {
140
+ this.inThinkBlock = true;
141
+ }
142
+ else if (this.lastToken === '</think>' && !this.inCodeBlock) {
143
+ this.inThinkBlock = false;
144
+ }
145
+ this.lastToken = content;
146
+ const message_id = this.getMessageId() ?? '';
147
+ if (!message_id) {
148
+ const initialContentType = this.inThinkBlock ? ContentTypes.THINK : ContentTypes.TEXT;
149
+ const initialType = reasoning_content ? ContentTypes.THINK : initialContentType;
150
+ const [stepId, message_id] = this.createMessageStep(initialType);
151
+ this.dispatchRunStep(stepId, {
152
+ type: StepTypes.MESSAGE_CREATION,
153
+ message_creation: {
154
+ message_id,
155
+ },
156
+ });
157
+ }
158
+ const stepId = this.currentStepId ?? '';
159
+ if (!stepId) {
160
+ return;
161
+ }
162
+ if (reasoning_content) {
163
+ this.handleContent(reasoning_content, stepId, ContentTypes.THINK);
164
+ }
165
+ else {
166
+ this.handleContent(content, stepId, ContentTypes.TEXT);
167
+ }
168
+ }
169
+ }
170
+
171
+ export { SEPARATORS, SplitStreamHandler };
172
+ //# sourceMappingURL=splitStream.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitStream.mjs","sources":["../../src/splitStream.ts"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport type * as t from '@/types';\nimport { ContentTypes, GraphEvents, StepTypes } from '@/common';\n\nexport const SEPARATORS = ['.', '?', '!', '۔', '。', '‥', ';', '¡', '¿', '\\n', '```'];\n\nexport class SplitStreamHandler {\n private inCodeBlock = false;\n private inThinkBlock = false;\n private accumulate: boolean;\n tokens: string[] = [];\n lastToken = '';\n reasoningTokens: string[] = [];\n currentStepId?: string;\n currentMessageId?: string;\n currentType?: ContentTypes.TEXT | ContentTypes.THINK;\n currentLength = 0;\n reasoningKey: 'reasoning_content' | 'reasoning' = 'reasoning_content';\n currentIndex = -1;\n blockThreshold = 4500;\n /** The run ID AKA the Message ID associated with the complete generation */\n runId: string;\n handlers?: t.SplitStreamHandlers;\n constructor({\n runId,\n handlers,\n accumulate,\n reasoningKey,\n blockThreshold,\n }: {\n runId: string,\n accumulate?: boolean,\n handlers: t.SplitStreamHandlers\n blockThreshold?: number,\n reasoningKey?: 'reasoning_content' | 'reasoning',\n }) {\n this.runId = runId;\n this.handlers = handlers;\n if (reasoningKey) {\n this.reasoningKey = reasoningKey;\n }\n if (blockThreshold != null) {\n this.blockThreshold = blockThreshold;\n }\n this.accumulate = accumulate ?? false;\n }\n getMessageId = (): string | undefined => {\n const messageId = this.currentMessageId;\n if (messageId != null && messageId) {\n return messageId;\n }\n return undefined;\n };\n createMessageStep = (type?: ContentTypes.TEXT | ContentTypes.THINK): [string, string] => {\n if (type != null && this.currentType !== type) {\n this.currentType = type;\n }\n this.currentLength = 0;\n this.currentIndex += 1;\n this.currentStepId = `step_${nanoid()}`;\n this.currentMessageId = `msg_${nanoid()}`;\n return [this.currentStepId, this.currentMessageId];\n };\n dispatchRunStep = (stepId: string, stepDetails: t.StepDetails): void => {\n const runStep: t.RunStep = {\n id: stepId,\n runId: this.runId,\n type: stepDetails.type,\n index: this.currentIndex,\n stepDetails,\n // usage: null,\n };\n this.handlers?.[GraphEvents.ON_RUN_STEP]?.({ event: GraphEvents.ON_RUN_STEP, data: runStep });\n };\n dispatchMessageDelta = (stepId: string, delta: t.MessageDelta): void => {\n const messageDelta: t.MessageDeltaEvent = {\n id: stepId,\n delta,\n };\n this.handlers?.[GraphEvents.ON_MESSAGE_DELTA]?.({ event: GraphEvents.ON_MESSAGE_DELTA, data: messageDelta });\n };\n dispatchReasoningDelta = (stepId: string, delta: t.ReasoningDelta): void => {\n const reasoningDelta: t.ReasoningDeltaEvent = {\n id: stepId,\n delta,\n };\n this.handlers?.[GraphEvents.ON_REASONING_DELTA]?.({ event: GraphEvents.ON_REASONING_DELTA, data: reasoningDelta });\n };\n handleContent = (content: string, stepId: string, _type: ContentTypes.TEXT | ContentTypes.THINK): void => {\n let type = _type;\n if (this.inThinkBlock && type === ContentTypes.TEXT) {\n type = ContentTypes.THINK;\n }\n if (this.accumulate) {\n if (type === ContentTypes.THINK) {\n this.reasoningTokens.push(content);\n } else {\n this.tokens.push(content);\n }\n }\n\n if (this.currentType !== type) {\n const [newStepId, newMessageId] = this.createMessageStep(type);\n this.dispatchRunStep(newStepId, {\n type: StepTypes.MESSAGE_CREATION,\n message_creation: {\n message_id: newMessageId,\n },\n });\n }\n\n if (content.includes('```')) {\n this.inCodeBlock = !this.inCodeBlock;\n }\n\n this.currentLength += content.length;\n\n if (type === ContentTypes.THINK) {\n this.dispatchReasoningDelta(stepId, {\n content: [{\n type: ContentTypes.THINK,\n think: content,\n }],\n });\n } else {\n this.dispatchMessageDelta(stepId, {\n content: [{\n type: ContentTypes.TEXT,\n text: content,\n }],\n });\n }\n\n if (this.inCodeBlock) {\n return;\n }\n\n if (this.currentLength > this.blockThreshold && SEPARATORS.some(sep => content.includes(sep))) {\n const [newStepId, newMessageId] = this.createMessageStep(type);\n this.dispatchRunStep(newStepId, {\n type: StepTypes.MESSAGE_CREATION,\n message_creation: {\n message_id: newMessageId,\n },\n });\n }\n };\n handle(chunk?: t.CustomChunk): void {\n if (!chunk) {\n return;\n }\n\n const content = chunk.choices?.[0]?.delta.content ?? '';\n const reasoning_content = chunk.choices?.[0]?.delta[this.reasoningKey] ?? '';\n\n if (!content.length && !reasoning_content.length) {\n return;\n }\n\n if (content === '<think>' && !this.inCodeBlock) {\n this.inThinkBlock = true;\n } else if (this.lastToken === '</think>' && !this.inCodeBlock) {\n this.inThinkBlock = false;\n }\n\n this.lastToken = content;\n\n const message_id = this.getMessageId() ?? '';\n\n if (!message_id) {\n const initialContentType = this.inThinkBlock ? ContentTypes.THINK : ContentTypes.TEXT;\n const initialType = reasoning_content ? ContentTypes.THINK : initialContentType;\n const [stepId, message_id] = this.createMessageStep(initialType);\n this.dispatchRunStep(stepId, {\n type: StepTypes.MESSAGE_CREATION,\n message_creation: {\n message_id,\n },\n });\n }\n\n const stepId = this.currentStepId ?? '';\n if (!stepId) {\n return;\n }\n\n if (reasoning_content) {\n this.handleContent(reasoning_content, stepId, ContentTyp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AM,EAAE;YACX,OAAO;SACR;QAED,IAAI,iBAAiB,EAAE;YACrB,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;SACnE;aAAM;YACL,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;SACxD;KACF;AACF;;;;"}
@@ -1,5 +1,6 @@
1
1
  export * from './run';
2
2
  export * from './stream';
3
+ export * from './splitStream';
3
4
  export * from './events';
4
5
  export * from './messages';
5
6
  export * from './graphs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@librechat/agents",
3
- "version": "1.9.95",
3
+ "version": "1.9.96",
4
4
  "main": "./dist/cjs/main.cjs",
5
5
  "module": "./dist/esm/main.mjs",
6
6
  "types": "./dist/types/index.d.ts",
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /* Main Operations */
2
2
  export * from './run';
3
3
  export * from './stream';
4
+ export * from './splitStream';
4
5
  export * from './events';
5
6
  export * from './messages';
6
7