@twinsearth/w2m-dsh-plugin 3.0.0 → 3.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/.claude-plugin/marketplace.json +3 -3
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +38 -0
- package/README.md +16 -1
- package/codex/mcp-servers.toml +1 -1
- package/cordis.patch.yml +10 -0
- package/docs/acceptance/3.0.0/RELEASE-3000.json +3 -1
- package/docs/acceptance/3.1.0/RELEASE-3100.json +46 -0
- package/docs/acceptance/3.2.0/RELEASE-3200.json +47 -0
- package/lib/client.js +444 -0
- package/lib/contract.js +22 -0
- package/lib/queue-journal.js +15 -0
- package/package.json +9 -4
- package/plugin.json +1 -1
- package/src/decision-center/kernel.mjs +2 -3
- package/src/decision-center/routes.mjs +52 -26
- package/src/interop/contract/LICENSE +661 -0
- package/src/interop/contract/PROVENANCE.md +26 -0
- package/src/interop/contract/client.js +93 -0
- package/src/interop/contract/constants.js +94 -0
- package/src/interop/contract/envelope.js +83 -0
- package/src/interop/contract/index.js +20 -0
- package/src/interop/contract/negotiate.js +106 -0
- package/src/interop/contract/relay.js +229 -0
- package/src/interop/contract/server.js +77 -0
- package/src/interop/contract/transports.js +319 -0
- package/src/interop/index.mjs +270 -0
- package/src/plugin/tools.mjs +1 -1
- package/src/queue-journal/index.mjs +188 -0
- package/src/queue-journal/lib/composer-journal.mjs +128 -0
|
@@ -216,8 +216,12 @@ export function registerDecisionCenterRoutes(ctx) {
|
|
|
216
216
|
if (center === undefined || typeof center.ingest !== 'function') return unavailable();
|
|
217
217
|
const body = await bodyOf(request);
|
|
218
218
|
const out = center.ingest(body ?? {});
|
|
219
|
-
const statusCode = out.ok
|
|
220
|
-
|
|
219
|
+
const statusCode = out.ok
|
|
220
|
+
? 200
|
|
221
|
+
: out.reason === 'title-required' ||
|
|
222
|
+
out.reason === 'options-required' ||
|
|
223
|
+
out.reason === 'gray-is-terminal'
|
|
224
|
+
? 400
|
|
221
225
|
: 409;
|
|
222
226
|
return json(statusCode, out);
|
|
223
227
|
});
|
|
@@ -228,7 +232,12 @@ export function registerDecisionCenterRoutes(ctx) {
|
|
|
228
232
|
if (center === undefined || typeof center.list !== 'function') return unavailable();
|
|
229
233
|
if (streams >= MAX_EVENT_STREAMS) return json(429, { ok: false, error: 'too-many-event-streams' });
|
|
230
234
|
streams += 1;
|
|
231
|
-
const response = sseResponse({
|
|
235
|
+
const response = sseResponse({
|
|
236
|
+
center,
|
|
237
|
+
pump: () => () => {
|
|
238
|
+
streams = Math.max(0, streams - 1);
|
|
239
|
+
},
|
|
240
|
+
});
|
|
232
241
|
return response;
|
|
233
242
|
});
|
|
234
243
|
|
|
@@ -237,17 +246,25 @@ export function registerDecisionCenterRoutes(ctx) {
|
|
|
237
246
|
if (center === undefined || typeof center.resolve !== 'function') return unavailable();
|
|
238
247
|
const body = await bodyOf(request);
|
|
239
248
|
if (Array.isArray(body?.ids)) {
|
|
240
|
-
if (typeof center.resolveMany !== 'function')
|
|
241
|
-
|
|
249
|
+
if (typeof center.resolveMany !== 'function')
|
|
250
|
+
return json(503, { ok: false, error: 'decision-center-batch-unavailable' });
|
|
251
|
+
return json(
|
|
252
|
+
200,
|
|
253
|
+
center.resolveMany(body.ids, { option: body?.option, by: body?.by ?? 'w2m-api', note: body?.note }),
|
|
254
|
+
);
|
|
242
255
|
}
|
|
243
256
|
const resolveOptions = { by: body?.by ?? 'w2m-api', note: body?.note };
|
|
244
257
|
if (body?.custom !== undefined) resolveOptions.custom = body.custom;
|
|
245
|
-
const out =
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
258
|
+
const out =
|
|
259
|
+
body?.actionId !== undefined && typeof center.resolveAction === 'function'
|
|
260
|
+
? center.resolveAction(body?.id, body.actionId, body?.payload, resolveOptions)
|
|
261
|
+
: center.resolve(body?.id, body?.option, resolveOptions);
|
|
262
|
+
const statusCode = out.ok
|
|
263
|
+
? 200
|
|
264
|
+
: out.reason === 'not-found'
|
|
265
|
+
? 404
|
|
266
|
+
: out.reason === 'option-required' || out.reason === 'unknown-option'
|
|
267
|
+
? 400
|
|
251
268
|
: 409;
|
|
252
269
|
return json(statusCode, out);
|
|
253
270
|
});
|
|
@@ -257,11 +274,12 @@ export function registerDecisionCenterRoutes(ctx) {
|
|
|
257
274
|
if (center === undefined || typeof center.abandon !== 'function') return unavailable();
|
|
258
275
|
const body = await bodyOf(request);
|
|
259
276
|
if (Array.isArray(body?.ids)) {
|
|
260
|
-
if (typeof center.abandonMany !== 'function')
|
|
277
|
+
if (typeof center.abandonMany !== 'function')
|
|
278
|
+
return json(503, { ok: false, error: 'decision-center-batch-unavailable' });
|
|
261
279
|
return json(200, center.abandonMany(body.ids, { by: body?.by ?? 'w2m-api', note: body?.note }));
|
|
262
280
|
}
|
|
263
281
|
const out = center.abandon(body?.id, { by: body?.by ?? 'w2m-api', note: body?.note });
|
|
264
|
-
return json(out.ok ? 200 :
|
|
282
|
+
return json(out.ok ? 200 : out.reason === 'not-found' ? 404 : 409, out);
|
|
265
283
|
});
|
|
266
284
|
|
|
267
285
|
register(`${DECISION_ROUTE_PREFIX}/ai`, ['GET'], () => {
|
|
@@ -274,7 +292,7 @@ export function registerDecisionCenterRoutes(ctx) {
|
|
|
274
292
|
const center = centerOf(ctx);
|
|
275
293
|
if (center === undefined || typeof center.testAi !== 'function') return unavailable();
|
|
276
294
|
const out = await center.testAi((await bodyOf(request)) ?? {});
|
|
277
|
-
return json(out.ok ? 200 :
|
|
295
|
+
return json(out.ok ? 200 : out.status === 429 ? 429 : 400, out);
|
|
278
296
|
});
|
|
279
297
|
|
|
280
298
|
register(`${DECISION_ROUTE_PREFIX}/ai/config`, ['POST'], async (request) => {
|
|
@@ -296,17 +314,21 @@ export function registerDecisionCenterRoutes(ctx) {
|
|
|
296
314
|
send('start', { id });
|
|
297
315
|
void (async () => {
|
|
298
316
|
try {
|
|
299
|
-
const out =
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
317
|
+
const out =
|
|
318
|
+
typeof center.adviseStream === 'function'
|
|
319
|
+
? await center.adviseStream(id, (delta, text) => {
|
|
320
|
+
if (!cancelled) send('delta', { delta, text });
|
|
321
|
+
})
|
|
322
|
+
: await center.advise(id);
|
|
323
|
+
if (!cancelled)
|
|
324
|
+
send(out.ok ? 'done' : 'error', out.ok ? { advice: out.advice, ticket: out.ticket } : out);
|
|
305
325
|
} catch (error) {
|
|
306
326
|
if (!cancelled) send('error', { ok: false, error: String(error?.message ?? error) });
|
|
307
327
|
}
|
|
308
328
|
})();
|
|
309
|
-
return () => {
|
|
329
|
+
return () => {
|
|
330
|
+
cancelled = true;
|
|
331
|
+
};
|
|
310
332
|
},
|
|
311
333
|
});
|
|
312
334
|
});
|
|
@@ -316,11 +338,15 @@ export function registerDecisionCenterRoutes(ctx) {
|
|
|
316
338
|
if (center === undefined || typeof center.advise !== 'function') return unavailable();
|
|
317
339
|
const body = await bodyOf(request);
|
|
318
340
|
const out = await center.advise(body?.id);
|
|
319
|
-
const limited =
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
341
|
+
const limited =
|
|
342
|
+
out?.reason === 'ai-rate-limited' ||
|
|
343
|
+
out?.reason === 'ai-circuit-open' ||
|
|
344
|
+
out?.reason === 'ai-daily-quota-exceeded';
|
|
345
|
+
const headers =
|
|
346
|
+
limited && Number.isFinite(out?.retryAfterMs) && out.retryAfterMs > 0
|
|
347
|
+
? { 'retry-after': String(Math.ceil(out.retryAfterMs / 1000)) }
|
|
348
|
+
: {};
|
|
349
|
+
return json(out.ok ? 200 : out.reason === 'not-found' ? 404 : limited ? 429 : 409, out, headers);
|
|
324
350
|
});
|
|
325
351
|
|
|
326
352
|
status.mounted = true;
|