dsh-lcx-codex 0.6.0-pre.1 → 0.6.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/lib/dsh-compat.js CHANGED
@@ -56,8 +56,8 @@ export function readSelectedAgentRouteState(agent) {
56
56
  return route;
57
57
  // Cold/resumed Agents recover pending selection from DSH's public projection.
58
58
  const projections = resolveScopedService(agent, "sessionProjections");
59
- if (mutableService(projections) && typeof projections.stateOf === "function") {
60
- const selection = Reflect.apply(projections.stateOf, projections, [session, "modelSelection"]);
59
+ if (typeof projections?.stateOf === "function") {
60
+ const selection = projections.stateOf(session, "modelSelection");
61
61
  if (mutableService(selection))
62
62
  return { ...route, requestConfig: selection.pending ?? route.requestConfig };
63
63
  }
@@ -66,13 +66,11 @@ export function readSelectedAgentRouteState(agent) {
66
66
  }
67
67
  export function scopedToolRuntime(agent) {
68
68
  const tools = resolveScopedService(agent, "tools");
69
- if (!mutableService(tools) || typeof tools.register !== "function")
69
+ if (typeof tools?.register !== "function")
70
70
  return undefined;
71
71
  return {
72
72
  register: tools.register.bind(tools),
73
- ...(typeof tools.get === "function"
74
- ? { get: tools.get.bind(tools) }
75
- : {}),
73
+ ...(typeof tools.get === "function" ? { get: tools.get.bind(tools) } : {}),
76
74
  };
77
75
  }
78
76
  /**
@@ -82,31 +80,32 @@ export function scopedToolRuntime(agent) {
82
80
  */
83
81
  export function onScopedToolExecute(agent, listener) {
84
82
  const ctx = agentLike(agent)?.ctx;
85
- if (!mutableService(ctx) || typeof ctx.on !== "function")
83
+ if (typeof ctx?.on !== "function")
86
84
  return undefined;
87
85
  try {
88
- const dispose = Reflect.apply(ctx.on, ctx, ["tools/execute", listener]);
89
- return typeof dispose === "function" ? () => void Reflect.apply(dispose, undefined, []) : undefined;
86
+ const dispose = ctx.on("tools/execute", listener);
87
+ return typeof dispose === "function" ? () => void dispose() : undefined;
90
88
  }
91
89
  catch {
92
90
  return undefined;
93
91
  }
94
92
  }
95
93
  export function tokenMeterTotal(value, session) {
96
- if (!mutableService(value) || typeof value.measure !== "function")
94
+ const meter = value;
95
+ if (typeof meter?.measure !== "function")
97
96
  return undefined;
98
- const measurement = Reflect.apply(value.measure, value, [session]);
99
- if (!mutableService(measurement) || typeof measurement.totalTokens !== "number")
100
- return undefined;
101
- return Number.isFinite(measurement.totalTokens) ? measurement.totalTokens : undefined;
97
+ const measurement = meter.measure(session);
98
+ return typeof measurement?.totalTokens === "number" && Number.isFinite(measurement.totalTokens)
99
+ ? measurement.totalTokens
100
+ : undefined;
102
101
  }
103
102
  export function sessionsService(ctx) {
104
103
  const service = resolveContextService(ctx, "sessions");
105
- if (!mutableService(service) || typeof service.get !== "function")
104
+ if (typeof service?.get !== "function")
106
105
  return undefined;
107
106
  return {
108
107
  get(id) {
109
- const value = Reflect.apply(service.get, service, [id]);
108
+ const value = service.get?.(id);
110
109
  return value instanceof Session ? value : undefined;
111
110
  },
112
111
  };
@@ -116,30 +115,6 @@ export function sessionFor(ctx, sessionId) {
116
115
  ? sessionsService(ctx)?.get(SessionId(sessionId))
117
116
  : undefined;
118
117
  }
119
- export function readWebSearchProvider(ctx) {
120
- const web = resolveContextService(ctx, "web");
121
- if (!mutableService(web))
122
- return undefined;
123
- try {
124
- return Reflect.get(web, "searchProviderId");
125
- }
126
- catch {
127
- return undefined;
128
- }
129
- }
130
- export function writeWebSearchProvider(ctx, providerId) {
131
- const web = resolveContextService(ctx, "web");
132
- if (!mutableService(web))
133
- return false;
134
- try {
135
- if (!Reflect.set(web, "searchProviderId", providerId))
136
- return false;
137
- return Reflect.get(web, "searchProviderId") === providerId;
138
- }
139
- catch {
140
- return false;
141
- }
142
- }
143
118
  export function contextService(ctx, name) {
144
119
  if (!mutableService(ctx))
145
120
  return undefined;
@@ -334,39 +309,3 @@ export function restoreCompactionConfig(record) {
334
309
  catch { }
335
310
  }
336
311
  }
337
- export function patchVisibleWebSearchTimeout(agent, getTimeoutMs, patchedDefinitions) {
338
- const tools = resolveScopedService(agent, "tools");
339
- if (!mutableService(tools) || typeof tools.get !== "function")
340
- return;
341
- const definition = Reflect.apply(tools.get, tools, ["web_search", agent]);
342
- if (!mutableService(definition))
343
- return;
344
- if (!patchedDefinitions.has(definition))
345
- patchedDefinitions.set(definition, definition.timeoutMs);
346
- const timeoutMs = getTimeoutMs();
347
- const target = timeoutMs === undefined ? patchedDefinitions.get(definition) : timeoutMs;
348
- try {
349
- definition.timeoutMs = target;
350
- }
351
- catch { }
352
- }
353
- export function refreshVisibleWebSearchTimeouts(patchedDefinitions, timeoutMs) {
354
- for (const [definition, original] of patchedDefinitions) {
355
- try {
356
- definition.timeoutMs = timeoutMs === undefined ? original : timeoutMs;
357
- }
358
- catch { }
359
- }
360
- }
361
- export function restoreVisibleWebSearchTimeouts(patchedDefinitions) {
362
- for (const [definition, original] of patchedDefinitions) {
363
- try {
364
- if (original === undefined)
365
- delete definition.timeoutMs;
366
- else
367
- definition.timeoutMs = original;
368
- }
369
- catch { }
370
- }
371
- patchedDefinitions.clear();
372
- }