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.
@@ -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 now = typeof req.body?.now === "string" ? req.body.now : undefined;
82
- const taskMatch = inspectTaskMessage({
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
- logTaskInspection({
93
+ logBookmarkDigestInspection({
89
94
  enabled: context.config.debugLoggingEnabled,
90
95
  route: "/v1/chat/completions",
91
- userId: taskMatch.userId,
96
+ userId: resolvedUserId,
92
97
  text: turn.userText,
93
- inspection: taskMatch.inspection,
98
+ inspection: digestInspection,
94
99
  previewChars: context.config.debugPreviewChars,
95
100
  });
96
-
97
- const taskResult = taskMatch.inspection.shouldHandle
98
- ? buildTaskEngineResult({
101
+ const digestResult = digestInspection.shouldHandle
102
+ ? respondToBookmarkDigestMessage({
103
+ bookmarkDigestService: context.bookmarkDigestService,
99
104
  turn,
100
- taskResult: context.taskService.processMessage({
101
- userId: taskMatch.userId,
102
- text: turn.userText,
103
- now,
104
- }),
105
+ userId: resolvedUserId,
105
106
  })
106
107
  : undefined;
107
- const weatherMatch = !taskResult
108
- ? inspectWeatherMessage({
109
- weatherService: context.weatherService,
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: parsed.data.user,
126
+ explicitUser: resolvedUserId,
112
127
  })
113
128
  : undefined;
114
- if (weatherMatch) {
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: taskResult ? "task" : weatherResult ? "weather" : "reply",
133
+ source: digestResult ? "reply" : searchResult ? "search" : "reply",
138
134
  finishReason: result.finishReason,
139
135
  matchedIntentId: result.matchedIntentId,
140
136
  templateId: result.templateId,
@@ -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: responseRequestToChatRequest(parsed.data),
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 now = typeof req.body?.now === "string" ? req.body.now : undefined;
87
- const taskMatch = inspectTaskMessage({
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
- logTaskInspection({
99
+ logBookmarkDigestInspection({
94
100
  enabled: context.config.debugLoggingEnabled,
95
101
  route: "/v1/responses",
96
- userId: taskMatch.userId,
102
+ userId: resolvedUserId,
97
103
  text: turn.userText,
98
- inspection: taskMatch.inspection,
104
+ inspection: digestInspection,
99
105
  previewChars: context.config.debugPreviewChars,
100
106
  });
101
-
102
- const taskResult = taskMatch.inspection.shouldHandle
103
- ? buildTaskEngineResult({
107
+ const digestResult = digestInspection.shouldHandle
108
+ ? respondToBookmarkDigestMessage({
109
+ bookmarkDigestService: context.bookmarkDigestService,
104
110
  turn,
105
- taskResult: context.taskService.processMessage({
106
- userId: taskMatch.userId,
107
- text: turn.userText,
108
- now,
109
- }),
111
+ userId: resolvedUserId,
110
112
  })
111
113
  : undefined;
112
- const weatherMatch = !taskResult
113
- ? inspectWeatherMessage({
114
- weatherService: context.weatherService,
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: parsed.data.user,
132
+ explicitUser: resolvedUserId,
117
133
  })
118
134
  : undefined;
119
- if (weatherMatch) {
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: taskResult ? "task" : weatherResult ? "weather" : "reply",
139
+ source: digestResult ? "reply" : searchResult ? "search" : "reply",
143
140
  finishReason: result.finishReason,
144
141
  matchedIntentId: result.matchedIntentId,
145
142
  templateId: result.templateId,