@hjd-hitsz/claudex-web 4.2.0 → 4.2.1

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.
@@ -2,6 +2,7 @@ import { backgroundTaskViews } from "./background-task-views.mjs";
2
2
  import {
3
3
  backgroundParams,
4
4
  backgroundTerminals,
5
+ backgroundTurnParams,
5
6
  } from "./background-terminals.mjs";
6
7
  import { threadMethods } from "./methods.mjs";
7
8
  import { referenceToolParams } from "./reference-tools.mjs";
@@ -19,6 +20,7 @@ import { createBridgeEvents } from "./events.mjs";
19
20
  import { createRequestHandler } from "./requests.mjs";
20
21
  import { createProductMethods } from "../../bridge/product-methods.mjs";
21
22
  import { readCodexTokenUsage } from "./token-usage.mjs";
23
+ import { createStreamingMessages } from "./streaming-messages.mjs";
22
24
 
23
25
  export function createCodexAdapter({
24
26
  backend,
@@ -36,6 +38,7 @@ export function createCodexAdapter({
36
38
  const activeThreads = new Set();
37
39
  const terminals = new Map();
38
40
  const compactions = createCompactions(broadcast);
41
+ const streamingMessages = createStreamingMessages();
39
42
  const handoff = createNativeBackgroundHandoff({
40
43
  background,
41
44
  enabled: () => Boolean(background?.available && backgroundEnabled()),
@@ -54,6 +57,7 @@ export function createCodexAdapter({
54
57
  },
55
58
  onEvent(message) {
56
59
  handoff.event(message);
60
+ streamingMessages.event(message);
57
61
  events.onEvent(message);
58
62
  },
59
63
  onResponse: (request, message) => events.onResponse(request, message),
@@ -64,6 +68,7 @@ export function createCodexAdapter({
64
68
  questions.clear();
65
69
  activeTurns.clear();
66
70
  activeThreads.clear();
71
+ streamingMessages.clear();
67
72
  handoff.disconnected();
68
73
  subscriptions.reset();
69
74
  for (const terminal of terminals.values()) terminal.running = false;
@@ -71,19 +76,21 @@ export function createCodexAdapter({
71
76
  },
72
77
  });
73
78
  const nativeCall = transport.call;
74
- const sessionParams = async (method, params) =>
75
- subagentModelParams(
79
+ const sessionParams = async (method, params) => {
80
+ const enabled = backgroundEnabled();
81
+ if (!threadMethods.has(method))
82
+ return enabled ? backgroundTurnParams(method, params) : params;
83
+ return subagentModelParams(
76
84
  method,
77
85
  backgroundParams(
78
86
  method,
79
87
  referenceToolParams(method, params, config),
80
- threadMethods.has(method) && backgroundEnabled()
81
- ? await background.ensure()
82
- : null,
88
+ enabled ? await background.ensure() : null,
83
89
  config.upstreamUrl,
84
90
  ),
85
- threadMethods.has(method) ? await readSubagentSettings() : backend,
91
+ await readSubagentSettings(),
86
92
  );
93
+ };
87
94
  transport.call = async (method, params, options) =>
88
95
  nativeCall(method, await sessionParams(method, params), options);
89
96
  const threadNaming = createThreadNaming({
@@ -128,6 +135,7 @@ export function createCodexAdapter({
128
135
  terminals,
129
136
  ...subscriptions,
130
137
  compactions,
138
+ streamingMessages,
131
139
  threadNaming,
132
140
  send,
133
141
  broadcast,
@@ -196,6 +204,7 @@ export function createCodexAdapter({
196
204
  close() {
197
205
  threadNaming.clear();
198
206
  handoff.disconnected();
207
+ streamingMessages.clear();
199
208
  transport.close();
200
209
  subscriptions.reset();
201
210
  },
@@ -2,6 +2,7 @@ import {
2
2
  mcpConfig,
3
3
  taskRequest,
4
4
  } from "../../../../packages/background-terminal/client.mjs";
5
+ import { BACKGROUND_TURN_CONTEXT } from "../../../../packages/background-terminal/background-protocol.mjs";
5
6
  import { threadMethods } from "./methods.mjs";
6
7
 
7
8
  const prefix = "claudex-background:";
@@ -18,6 +19,17 @@ export function backgroundParams(method, params, directory, upstream) {
18
19
  };
19
20
  }
20
21
 
22
+ export function backgroundTurnParams(method, params) {
23
+ if (method !== "turn/start" && method !== "turn/steer") return params;
24
+ return {
25
+ ...params,
26
+ additionalContext: {
27
+ ...params.additionalContext,
28
+ ...BACKGROUND_TURN_CONTEXT,
29
+ },
30
+ };
31
+ }
32
+
21
33
  export function backgroundTerminals(
22
34
  directory,
23
35
  upstream,
@@ -9,6 +9,7 @@ export function createBridgeEvents({
9
9
  unwrittenThreads,
10
10
  updateGoal,
11
11
  compactions,
12
+ streamingMessages,
12
13
  threadNaming,
13
14
  send,
14
15
  broadcast,
@@ -120,7 +121,19 @@ export function createBridgeEvents({
120
121
  },
121
122
  });
122
123
  }
123
- if (!request.timedOut) send(request.client, { ...message, id: request.id });
124
+ if (!request.timedOut) {
125
+ const streamed = request.includeStreaming
126
+ ? streamingMessages.read(request.threadId)
127
+ : [];
128
+ send(request.client, {
129
+ ...message,
130
+ id: request.id,
131
+ ...(message.result &&
132
+ streamed.length && {
133
+ result: { ...message.result, streamingMessages: streamed },
134
+ }),
135
+ });
136
+ }
124
137
  releaseUnusedThreads();
125
138
  if (!message.error && !request.timedOut && !request.client?.readOnly) {
126
139
  if (request.method === "turn/start")
@@ -84,6 +84,21 @@ export function createRequestHandler({
84
84
  ...message.params,
85
85
  config: { ...message.params?.config, thread_unload_delay_secs: 0 },
86
86
  };
87
+ if (
88
+ message.method === "thread/list" &&
89
+ message.params?.modelProviders === undefined
90
+ )
91
+ message.params = { ...message.params, modelProviders: [] };
92
+ const includeStreaming =
93
+ Boolean(threadId) &&
94
+ ["thread/items/list", "thread/turns/list"].includes(message.method) &&
95
+ !message.params.cursor &&
96
+ message.params.includeStreaming === true;
97
+ if (message.params && Object.hasOwn(message.params, "includeStreaming")) {
98
+ const { includeStreaming: _includeStreaming, ...params } =
99
+ message.params;
100
+ message.params = params;
101
+ }
87
102
  if (
88
103
  backgroundCall &&
89
104
  terminalMethods.has(message.method) &&
@@ -142,6 +157,7 @@ export function createRequestHandler({
142
157
  processId,
143
158
  method: message.method,
144
159
  threadId,
160
+ includeStreaming,
145
161
  ...(message.method === "thread/resume" && {
146
162
  resumeParams: message.params,
147
163
  }),
@@ -0,0 +1,50 @@
1
+ export function createStreamingMessages() {
2
+ const threads = new Map();
3
+ function event({ method, params = {} }) {
4
+ const { threadId, turnId, item, itemId, delta } = params;
5
+ if (
6
+ [
7
+ "thread/closed",
8
+ "thread/archived",
9
+ "thread/deleted",
10
+ "turn/started",
11
+ ].includes(method)
12
+ ) {
13
+ threads.delete(threadId);
14
+ return;
15
+ }
16
+ const messages = threads.get(threadId);
17
+ if (method === "turn/completed") {
18
+ if (messages?.turnId === params.turn.id) threads.delete(threadId);
19
+ return;
20
+ }
21
+ if (method === "item/completed") {
22
+ if (messages?.turnId === turnId) messages.items.delete(item.id);
23
+ return;
24
+ }
25
+ if (
26
+ method !== "item/agentMessage/delta" &&
27
+ !(method === "item/started" && item.type === "agentMessage")
28
+ )
29
+ return;
30
+ if (!messages || messages.turnId !== turnId)
31
+ threads.set(threadId, { turnId, items: new Map() });
32
+ const { items } = threads.get(threadId);
33
+ if (method === "item/started") {
34
+ items.set(item.id, { ...item, turnId });
35
+ } else {
36
+ const message = items.get(itemId) ?? {
37
+ id: itemId,
38
+ turnId,
39
+ type: "agentMessage",
40
+ text: "",
41
+ };
42
+ items.set(itemId, { ...message, text: message.text + delta });
43
+ }
44
+ }
45
+ return {
46
+ event,
47
+ read: (threadId) => [...(threads.get(threadId)?.items.values() ?? [])],
48
+ clear: () => threads.clear(),
49
+ };
50
+ }