openclaw-server 0.1.0 → 0.2.0
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/README.md +319 -0
- package/package.json +1 -1
- package/packs/default/templates.yaml +6 -6
- package/src/bookmark-digest/chat-integration.ts +49 -0
- package/src/bookmark-digest/service.test.ts +92 -0
- package/src/bookmark-digest/service.ts +573 -0
- package/src/bookmark-digest/store.ts +349 -0
- package/src/bookmark-digest/types.ts +62 -0
- package/src/bookmark-search/chat-integration.ts +56 -0
- package/src/bookmark-search/parser.test.ts +67 -0
- package/src/bookmark-search/parser.ts +235 -0
- package/src/bookmark-search/service.test.ts +330 -0
- package/src/bookmark-search/service.ts +660 -0
- package/src/bookmark-search/shuqianlan-provider.ts +334 -0
- package/src/bookmark-search/types.ts +78 -0
- package/src/config.ts +30 -2
- package/src/debug-log.ts +22 -18
- package/src/request-user.test.ts +29 -0
- package/src/request-user.ts +49 -0
- package/src/routes/admin.ts +53 -0
- package/src/routes/chat-completions.ts +42 -46
- package/src/routes/responses.ts +44 -47
- package/src/server.test.ts +336 -440
- package/src/server.ts +26 -18
- package/readme.md +0 -1219
- package/src/routes/tasks.ts +0 -138
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import type { Express } from "express";
|
|
1
|
+
import type { Express } from "express";
|
|
2
2
|
import { requireBearerAuth } from "../auth.js";
|
|
3
|
+
import {
|
|
4
|
+
inspectBookmarkDigestMessage,
|
|
5
|
+
respondToBookmarkDigestMessage,
|
|
6
|
+
} from "../bookmark-digest/chat-integration.js";
|
|
7
|
+
import {
|
|
8
|
+
inspectBookmarkSearchMessage,
|
|
9
|
+
respondToBookmarkSearchMessage,
|
|
10
|
+
} from "../bookmark-search/chat-integration.js";
|
|
3
11
|
import { normalizeRequest } from "../core/normalizer.js";
|
|
4
12
|
import { streamTextCompletion, streamToolCallCompletion } from "../core/stream-renderer.js";
|
|
5
13
|
import {
|
|
14
|
+
logBookmarkDigestInspection,
|
|
15
|
+
logBookmarkSearchInspection,
|
|
6
16
|
logRequestDebug,
|
|
7
17
|
logResponseSelection,
|
|
8
|
-
logTaskInspection,
|
|
9
|
-
logWeatherInspection,
|
|
10
18
|
} from "../debug-log.js";
|
|
11
19
|
import { buildCompletionResponse, createChatCompletionId } from "../openai.js";
|
|
20
|
+
import { resolveRequestUserId } from "../request-user.js";
|
|
12
21
|
import type { AppContext } from "../server.js";
|
|
13
|
-
import { buildTaskEngineResult, inspectTaskMessage } from "../tasks/chat-integration.js";
|
|
14
22
|
import { ChatCompletionsRequestSchema } from "../types.js";
|
|
15
|
-
import { inspectWeatherMessage, respondToWeatherMessage } from "../weather/chat-integration.js";
|
|
16
23
|
import { validateToolChoice } from "./request-validation.js";
|
|
17
24
|
|
|
18
25
|
export function registerChatCompletionsRoute(app: Express, context: AppContext): void {
|
|
@@ -52,6 +59,7 @@ export function registerChatCompletionsRoute(app: Express, context: AppContext):
|
|
|
52
59
|
request: parsed.data,
|
|
53
60
|
defaultModelId: context.config.defaultModelId,
|
|
54
61
|
});
|
|
62
|
+
const resolvedUserId = resolveRequestUserId(parsed.data) ?? turn.sessionId;
|
|
55
63
|
logRequestDebug({
|
|
56
64
|
enabled: context.config.debugLoggingEnabled,
|
|
57
65
|
route: "/v1/chat/completions",
|
|
@@ -78,63 +86,51 @@ export function registerChatCompletionsRoute(app: Express, context: AppContext):
|
|
|
78
86
|
}
|
|
79
87
|
|
|
80
88
|
const completionId = createChatCompletionId();
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
taskService: context.taskService,
|
|
89
|
+
const digestInspection = inspectBookmarkDigestMessage({
|
|
90
|
+
bookmarkDigestService: context.bookmarkDigestService,
|
|
84
91
|
turn,
|
|
85
|
-
explicitUser: parsed.data.user,
|
|
86
|
-
now,
|
|
87
92
|
});
|
|
88
|
-
|
|
93
|
+
logBookmarkDigestInspection({
|
|
89
94
|
enabled: context.config.debugLoggingEnabled,
|
|
90
95
|
route: "/v1/chat/completions",
|
|
91
|
-
userId:
|
|
96
|
+
userId: resolvedUserId,
|
|
92
97
|
text: turn.userText,
|
|
93
|
-
inspection:
|
|
98
|
+
inspection: digestInspection,
|
|
94
99
|
previewChars: context.config.debugPreviewChars,
|
|
95
100
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
const digestResult = digestInspection.shouldHandle
|
|
102
|
+
? respondToBookmarkDigestMessage({
|
|
103
|
+
bookmarkDigestService: context.bookmarkDigestService,
|
|
99
104
|
turn,
|
|
100
|
-
|
|
101
|
-
userId: taskMatch.userId,
|
|
102
|
-
text: turn.userText,
|
|
103
|
-
now,
|
|
104
|
-
}),
|
|
105
|
+
userId: resolvedUserId,
|
|
105
106
|
})
|
|
106
107
|
: undefined;
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const searchMatch = inspectBookmarkSearchMessage({
|
|
109
|
+
bookmarkSearchService: context.bookmarkSearchService,
|
|
110
|
+
turn,
|
|
111
|
+
explicitUser: resolvedUserId,
|
|
112
|
+
});
|
|
113
|
+
logBookmarkSearchInspection({
|
|
114
|
+
enabled: context.config.debugLoggingEnabled,
|
|
115
|
+
route: "/v1/chat/completions",
|
|
116
|
+
userId: searchMatch.userId,
|
|
117
|
+
text: turn.userText,
|
|
118
|
+
inspection: searchMatch.inspection,
|
|
119
|
+
previewChars: context.config.debugPreviewChars,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const searchResult = !digestResult && searchMatch.inspection.shouldHandle
|
|
123
|
+
? await respondToBookmarkSearchMessage({
|
|
124
|
+
bookmarkSearchService: context.bookmarkSearchService,
|
|
110
125
|
turn,
|
|
111
|
-
explicitUser:
|
|
126
|
+
explicitUser: resolvedUserId,
|
|
112
127
|
})
|
|
113
128
|
: undefined;
|
|
114
|
-
|
|
115
|
-
logWeatherInspection({
|
|
116
|
-
enabled: context.config.debugLoggingEnabled,
|
|
117
|
-
route: "/v1/chat/completions",
|
|
118
|
-
userId: weatherMatch.userId,
|
|
119
|
-
text: turn.userText,
|
|
120
|
-
inspection: weatherMatch.inspection,
|
|
121
|
-
previewChars: context.config.debugPreviewChars,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const weatherResult =
|
|
126
|
-
!taskResult && weatherMatch?.inspection.shouldHandle
|
|
127
|
-
? await respondToWeatherMessage({
|
|
128
|
-
weatherService: context.weatherService,
|
|
129
|
-
turn,
|
|
130
|
-
explicitUser: parsed.data.user,
|
|
131
|
-
})
|
|
132
|
-
: undefined;
|
|
133
|
-
const result = taskResult ?? weatherResult ?? context.replyEngine.respond(turn);
|
|
129
|
+
const result = digestResult ?? searchResult ?? context.replyEngine.respond(turn);
|
|
134
130
|
logResponseSelection({
|
|
135
131
|
enabled: context.config.debugLoggingEnabled,
|
|
136
132
|
route: "/v1/chat/completions",
|
|
137
|
-
source:
|
|
133
|
+
source: digestResult ? "reply" : searchResult ? "search" : "reply",
|
|
138
134
|
finishReason: result.finishReason,
|
|
139
135
|
matchedIntentId: result.matchedIntentId,
|
|
140
136
|
templateId: result.templateId,
|
package/src/routes/responses.ts
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import type { Express } from "express";
|
|
1
|
+
import type { Express } from "express";
|
|
2
2
|
import { requireBearerAuth } from "../auth.js";
|
|
3
|
+
import {
|
|
4
|
+
inspectBookmarkDigestMessage,
|
|
5
|
+
respondToBookmarkDigestMessage,
|
|
6
|
+
} from "../bookmark-digest/chat-integration.js";
|
|
7
|
+
import {
|
|
8
|
+
inspectBookmarkSearchMessage,
|
|
9
|
+
respondToBookmarkSearchMessage,
|
|
10
|
+
} from "../bookmark-search/chat-integration.js";
|
|
3
11
|
import { normalizeRequest } from "../core/normalizer.js";
|
|
4
12
|
import { responseRequestToChatRequest } from "../core/request-adapter.js";
|
|
5
13
|
import { streamResponsesText, streamResponsesToolCall } from "../core/stream-renderer.js";
|
|
6
14
|
import {
|
|
15
|
+
logBookmarkDigestInspection,
|
|
16
|
+
logBookmarkSearchInspection,
|
|
7
17
|
logRequestDebug,
|
|
8
18
|
logResponseSelection,
|
|
9
|
-
logTaskInspection,
|
|
10
|
-
logWeatherInspection,
|
|
11
19
|
} from "../debug-log.js";
|
|
12
20
|
import {
|
|
13
21
|
buildResponsesResponse,
|
|
14
22
|
createResponseId,
|
|
15
23
|
createResponseOutputId,
|
|
16
24
|
} from "../response-api.js";
|
|
25
|
+
import { resolveRequestUserId } from "../request-user.js";
|
|
17
26
|
import type { AppContext } from "../server.js";
|
|
18
|
-
import { buildTaskEngineResult, inspectTaskMessage } from "../tasks/chat-integration.js";
|
|
19
27
|
import { ResponsesRequestSchema } from "../types.js";
|
|
20
|
-
import { inspectWeatherMessage, respondToWeatherMessage } from "../weather/chat-integration.js";
|
|
21
28
|
import { validateToolChoice } from "./request-validation.js";
|
|
22
29
|
|
|
23
30
|
export function registerResponsesRoute(app: Express, context: AppContext): void {
|
|
@@ -53,10 +60,12 @@ export function registerResponsesRoute(app: Express, context: AppContext): void
|
|
|
53
60
|
return;
|
|
54
61
|
}
|
|
55
62
|
|
|
63
|
+
const request = responseRequestToChatRequest(parsed.data);
|
|
56
64
|
const turn = normalizeRequest({
|
|
57
|
-
request
|
|
65
|
+
request,
|
|
58
66
|
defaultModelId: context.config.defaultModelId,
|
|
59
67
|
});
|
|
68
|
+
const resolvedUserId = resolveRequestUserId(request) ?? turn.sessionId;
|
|
60
69
|
logRequestDebug({
|
|
61
70
|
enabled: context.config.debugLoggingEnabled,
|
|
62
71
|
route: "/v1/responses",
|
|
@@ -83,63 +92,51 @@ export function registerResponsesRoute(app: Express, context: AppContext): void
|
|
|
83
92
|
}
|
|
84
93
|
|
|
85
94
|
const responseId = createResponseId();
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
taskService: context.taskService,
|
|
95
|
+
const digestInspection = inspectBookmarkDigestMessage({
|
|
96
|
+
bookmarkDigestService: context.bookmarkDigestService,
|
|
89
97
|
turn,
|
|
90
|
-
explicitUser: parsed.data.user,
|
|
91
|
-
now,
|
|
92
98
|
});
|
|
93
|
-
|
|
99
|
+
logBookmarkDigestInspection({
|
|
94
100
|
enabled: context.config.debugLoggingEnabled,
|
|
95
101
|
route: "/v1/responses",
|
|
96
|
-
userId:
|
|
102
|
+
userId: resolvedUserId,
|
|
97
103
|
text: turn.userText,
|
|
98
|
-
inspection:
|
|
104
|
+
inspection: digestInspection,
|
|
99
105
|
previewChars: context.config.debugPreviewChars,
|
|
100
106
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
const digestResult = digestInspection.shouldHandle
|
|
108
|
+
? respondToBookmarkDigestMessage({
|
|
109
|
+
bookmarkDigestService: context.bookmarkDigestService,
|
|
104
110
|
turn,
|
|
105
|
-
|
|
106
|
-
userId: taskMatch.userId,
|
|
107
|
-
text: turn.userText,
|
|
108
|
-
now,
|
|
109
|
-
}),
|
|
111
|
+
userId: resolvedUserId,
|
|
110
112
|
})
|
|
111
113
|
: undefined;
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
const searchMatch = inspectBookmarkSearchMessage({
|
|
115
|
+
bookmarkSearchService: context.bookmarkSearchService,
|
|
116
|
+
turn,
|
|
117
|
+
explicitUser: resolvedUserId,
|
|
118
|
+
});
|
|
119
|
+
logBookmarkSearchInspection({
|
|
120
|
+
enabled: context.config.debugLoggingEnabled,
|
|
121
|
+
route: "/v1/responses",
|
|
122
|
+
userId: searchMatch.userId,
|
|
123
|
+
text: turn.userText,
|
|
124
|
+
inspection: searchMatch.inspection,
|
|
125
|
+
previewChars: context.config.debugPreviewChars,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const searchResult = !digestResult && searchMatch.inspection.shouldHandle
|
|
129
|
+
? await respondToBookmarkSearchMessage({
|
|
130
|
+
bookmarkSearchService: context.bookmarkSearchService,
|
|
115
131
|
turn,
|
|
116
|
-
explicitUser:
|
|
132
|
+
explicitUser: resolvedUserId,
|
|
117
133
|
})
|
|
118
134
|
: undefined;
|
|
119
|
-
|
|
120
|
-
logWeatherInspection({
|
|
121
|
-
enabled: context.config.debugLoggingEnabled,
|
|
122
|
-
route: "/v1/responses",
|
|
123
|
-
userId: weatherMatch.userId,
|
|
124
|
-
text: turn.userText,
|
|
125
|
-
inspection: weatherMatch.inspection,
|
|
126
|
-
previewChars: context.config.debugPreviewChars,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const weatherResult =
|
|
131
|
-
!taskResult && weatherMatch?.inspection.shouldHandle
|
|
132
|
-
? await respondToWeatherMessage({
|
|
133
|
-
weatherService: context.weatherService,
|
|
134
|
-
turn,
|
|
135
|
-
explicitUser: parsed.data.user,
|
|
136
|
-
})
|
|
137
|
-
: undefined;
|
|
138
|
-
const result = taskResult ?? weatherResult ?? context.replyEngine.respond(turn);
|
|
135
|
+
const result = digestResult ?? searchResult ?? context.replyEngine.respond(turn);
|
|
139
136
|
logResponseSelection({
|
|
140
137
|
enabled: context.config.debugLoggingEnabled,
|
|
141
138
|
route: "/v1/responses",
|
|
142
|
-
source:
|
|
139
|
+
source: digestResult ? "reply" : searchResult ? "search" : "reply",
|
|
143
140
|
finishReason: result.finishReason,
|
|
144
141
|
matchedIntentId: result.matchedIntentId,
|
|
145
142
|
templateId: result.templateId,
|