mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-11 19:57:41 +08:00
Promote raw stream replay into standalone simulator tool and add SSE field doc
This commit is contained in:
@@ -193,6 +193,9 @@ function extractContentRecursive(items, defaultType) {
|
||||
}
|
||||
|
||||
function shouldSkipPath(pathValue) {
|
||||
if (isFragmentStatusPath(pathValue)) {
|
||||
return true;
|
||||
}
|
||||
if (SKIP_EXACT_PATHS.has(pathValue)) {
|
||||
return true;
|
||||
}
|
||||
@@ -204,6 +207,13 @@ function shouldSkipPath(pathValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isFragmentStatusPath(pathValue) {
|
||||
if (!pathValue || pathValue === 'response/status') {
|
||||
return false;
|
||||
}
|
||||
return /^response\/fragments\/-?\d+\/status$/i.test(pathValue);
|
||||
}
|
||||
|
||||
function isCitation(text) {
|
||||
return asString(text).trim().startsWith('[citation:');
|
||||
}
|
||||
@@ -225,5 +235,6 @@ module.exports = {
|
||||
parseChunkForContent,
|
||||
extractContentRecursive,
|
||||
shouldSkipPath,
|
||||
isFragmentStatusPath,
|
||||
isCitation,
|
||||
};
|
||||
|
||||
@@ -31,6 +31,9 @@ func ParseDeepSeekSSELine(raw []byte) (map[string]any, bool, bool) {
|
||||
}
|
||||
|
||||
func shouldSkipPath(path string) bool {
|
||||
if isFragmentStatusPath(path) {
|
||||
return true
|
||||
}
|
||||
if _, ok := deepseek.SkipExactPathSet[path]; ok {
|
||||
return true
|
||||
}
|
||||
@@ -42,6 +45,31 @@ func shouldSkipPath(path string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func isFragmentStatusPath(path string) bool {
|
||||
if path == "" || path == "response/status" {
|
||||
return false
|
||||
}
|
||||
if !strings.HasPrefix(path, "response/fragments/") || !strings.HasSuffix(path, "/status") {
|
||||
return false
|
||||
}
|
||||
mid := strings.TrimSuffix(strings.TrimPrefix(path, "response/fragments/"), "/status")
|
||||
if mid == "" {
|
||||
return false
|
||||
}
|
||||
if strings.HasPrefix(mid, "-") {
|
||||
mid = mid[1:]
|
||||
}
|
||||
if mid == "" {
|
||||
return false
|
||||
}
|
||||
for _, r := range mid {
|
||||
if r < '0' || r > '9' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func ParseSSEChunkForContent(chunk map[string]any, thinkingEnabled bool, currentFragmentType string) ([]ContentPart, bool, string) {
|
||||
v, ok := chunk["v"]
|
||||
if !ok {
|
||||
|
||||
@@ -90,6 +90,15 @@ func TestShouldSkipPathFragmentStatus(t *testing.T) {
|
||||
if !shouldSkipPath("response/fragments/-3/status") {
|
||||
t.Fatal("expected skip for fragment -3 status")
|
||||
}
|
||||
if !shouldSkipPath("response/fragments/-16/status") {
|
||||
t.Fatal("expected skip for fragment -16 status")
|
||||
}
|
||||
if !shouldSkipPath("response/fragments/7/status") {
|
||||
t.Fatal("expected skip for fragment 7 status")
|
||||
}
|
||||
if shouldSkipPath("response/status") {
|
||||
t.Fatal("expected response/status to be handled by finish logic, not skipped")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldSkipPathRegularContent(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user