@mars-sea/dsh-commandcode-provider 0.10.0-alpha.4 → 0.10.0-alpha.6
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/CHANGELOG.md +23 -0
- package/lib/client.js +183 -227
- package/lib/client.js.map +1 -1
- package/lib/index.d.ts +249 -213
- package/lib/index.js +201 -120
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -235,27 +235,27 @@ var CommandCodeAccountPool = class {
|
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
237
|
//#endregion
|
|
238
|
-
//#region src/
|
|
238
|
+
//#region src/capabilities.ts
|
|
239
239
|
/**
|
|
240
|
-
*
|
|
240
|
+
* Static capability snapshot for the Command Code provider: model →
|
|
241
|
+
* reasoning-effort levels, vision/thinking flags, model → minimum plan tier,
|
|
242
|
+
* subscription-plan labels, deals, and hourly (peak/off-peak) pricing.
|
|
241
243
|
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
244
|
+
* Everything in this module is synced from official sources (the command-code
|
|
245
|
+
* CLI bundle's model table and the official plan/pricing/model docs — see the
|
|
246
|
+
* dsh-commandcode-upstream skill for the exact extraction procedures), and
|
|
247
|
+
* changes whenever an upstream CLI release reshuffles models/plans/prices.
|
|
248
|
+
* Keeping the snapshot in its own module confines those frequent sync diffs
|
|
249
|
+
* here: src/adapter.ts holds only the stable wire/runtime logic and imports
|
|
250
|
+
* these tables + read helpers.
|
|
245
251
|
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
* body: { config, memory, taste, skills, params: { model, messages, tools,
|
|
251
|
-
* system, max_tokens, temperature, stream, reasoning_effort? }, threadId }
|
|
252
|
-
* SSE-ish JSONL events: text-delta | reasoning-start/delta/end | tool-call
|
|
253
|
-
* | tool-result | finish | error
|
|
254
|
-
* Model catalog: GET {apiBase}/provider/v1/models -> { object: 'list', data: [...] }
|
|
252
|
+
* Snapshot read helpers (planLabel, dealLabel, formatContext,
|
|
253
|
+
* capabilityDescription, peakPricing*, compareByPlan, modelVisibleInPlan,
|
|
254
|
+
* subscriptionPlanInfo, isFreeModel) live here too — they exist only to read
|
|
255
|
+
* the tables, so a sync never has to touch src/adapter.ts.
|
|
255
256
|
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* (src/index.ts), so a settings change reaches the very next request.
|
|
257
|
+
* Ported from pi-commandcode-provider (MIT); originally part of src/adapter.ts
|
|
258
|
+
* and split out so upstream syncs stay reviewable.
|
|
259
259
|
*/
|
|
260
260
|
const KNOWN_EFFORTS = {
|
|
261
261
|
"Qwen/Qwen3.8-Max": [
|
|
@@ -263,6 +263,11 @@ const KNOWN_EFFORTS = {
|
|
|
263
263
|
"medium",
|
|
264
264
|
"xhigh"
|
|
265
265
|
],
|
|
266
|
+
"Qwen/Qwen3.8-Max-0902": [
|
|
267
|
+
"low",
|
|
268
|
+
"medium",
|
|
269
|
+
"xhigh"
|
|
270
|
+
],
|
|
266
271
|
"Qwen/Qwen3.8-27B": [
|
|
267
272
|
"low",
|
|
268
273
|
"medium",
|
|
@@ -273,6 +278,13 @@ const KNOWN_EFFORTS = {
|
|
|
273
278
|
"medium",
|
|
274
279
|
"xhigh"
|
|
275
280
|
],
|
|
281
|
+
"claude-fable-5-1": [
|
|
282
|
+
"low",
|
|
283
|
+
"medium",
|
|
284
|
+
"high",
|
|
285
|
+
"xhigh",
|
|
286
|
+
"max"
|
|
287
|
+
],
|
|
276
288
|
"claude-fable-5": [
|
|
277
289
|
"low",
|
|
278
290
|
"medium",
|
|
@@ -392,6 +404,16 @@ const KNOWN_EFFORTS = {
|
|
|
392
404
|
"xhigh",
|
|
393
405
|
"max"
|
|
394
406
|
],
|
|
407
|
+
"moonshotai/Kimi-K3": [
|
|
408
|
+
"low",
|
|
409
|
+
"high",
|
|
410
|
+
"max"
|
|
411
|
+
],
|
|
412
|
+
"google/gemini-3.8-flash": [
|
|
413
|
+
"low",
|
|
414
|
+
"medium",
|
|
415
|
+
"high"
|
|
416
|
+
],
|
|
395
417
|
"sakana/fugu-ultra": ["high", "xhigh"],
|
|
396
418
|
"tencent/hy4-preview": [
|
|
397
419
|
"low",
|
|
@@ -444,6 +466,8 @@ const KNOWN_IMAGE_MODELS = /* @__PURE__ */ new Set([
|
|
|
444
466
|
"Qwen/Qwen3.8-27B",
|
|
445
467
|
"Qwen/Qwen3.8-Flash",
|
|
446
468
|
"Qwen/Qwen3.8-Max",
|
|
469
|
+
"Qwen/Qwen3.8-Max-0902",
|
|
470
|
+
"claude-fable-5-1",
|
|
447
471
|
"claude-fable-5",
|
|
448
472
|
"claude-haiku-4-5-20251001",
|
|
449
473
|
"claude-opus-4-7",
|
|
@@ -457,6 +481,7 @@ const KNOWN_IMAGE_MODELS = /* @__PURE__ */ new Set([
|
|
|
457
481
|
"google/gemini-3.5-flash-lite",
|
|
458
482
|
"google/gemini-3.6-flash",
|
|
459
483
|
"google/gemini-3.7-flash",
|
|
484
|
+
"google/gemini-3.8-flash",
|
|
460
485
|
"gpt-5.3-codex",
|
|
461
486
|
"gpt-5.4",
|
|
462
487
|
"gpt-5.4-mini",
|
|
@@ -467,6 +492,8 @@ const KNOWN_IMAGE_MODELS = /* @__PURE__ */ new Set([
|
|
|
467
492
|
"meta/muse-spark-1.1",
|
|
468
493
|
"meta/muse-spark-1.2",
|
|
469
494
|
"meta/muse-spark-1.2-contributor",
|
|
495
|
+
"meta/muse-spark-1.3",
|
|
496
|
+
"meta/muse-spark-1.3-contributor",
|
|
470
497
|
"minimax/minimax-m3-free",
|
|
471
498
|
"moonshotai/Kimi-K2.5",
|
|
472
499
|
"moonshotai/Kimi-K2.6",
|
|
@@ -482,7 +509,7 @@ const KNOWN_IMAGE_MODELS = /* @__PURE__ */ new Set([
|
|
|
482
509
|
"z-ai/glm-5.3-flash"
|
|
483
510
|
]);
|
|
484
511
|
/**
|
|
485
|
-
* Models the official CLI's model table (command-code@1.
|
|
512
|
+
* Models the official CLI's model table (command-code@1.44.0) marks
|
|
486
513
|
* `reasoning:!0` but defines no selectable `reasoning_effort` levels — they
|
|
487
514
|
* think automatically, with Command Code driving the depth. This is the
|
|
488
515
|
* authoritative "thinks, effort not adjustable" set: `KNOWN_EFFORTS` (which
|
|
@@ -490,7 +517,7 @@ const KNOWN_IMAGE_MODELS = /* @__PURE__ */ new Set([
|
|
|
490
517
|
* effort levels, and this snapshot is not surfaced in the picker's compact
|
|
491
518
|
* description — it exists for programmatic consumers.
|
|
492
519
|
*
|
|
493
|
-
* Source: the command-code@1.
|
|
520
|
+
* Source: the command-code@1.44.0 bundled model table (dist/cli.mjs),
|
|
494
521
|
* cross-checked with https://commandcode.ai/docs/reference/cli/models.
|
|
495
522
|
* (`stealth/ox-alpha` left this set in command-code@1.32.1, which gave it
|
|
496
523
|
* selectable `['low', 'high', 'max']` efforts; the preview then ended in
|
|
@@ -498,7 +525,12 @@ const KNOWN_IMAGE_MODELS = /* @__PURE__ */ new Set([
|
|
|
498
525
|
* joined this set in command-code@1.37.0 — reasoning:!0, no efforts, 1M
|
|
499
526
|
* context, routed through OpenRouter — then gained selectable
|
|
500
527
|
* `['low', 'medium', 'high']` efforts in command-code@1.38.0 and moved to
|
|
501
|
-
* `KNOWN_EFFORTS`.
|
|
528
|
+
* `KNOWN_EFFORTS`. `moonshotai/Kimi-K3` followed the same path in
|
|
529
|
+
* command-code@1.39.3 — it gained `['low', 'high', 'max']` efforts and moved
|
|
530
|
+
* to `KNOWN_EFFORTS`. command-code@1.42.0 added `meituan/LongCat-2.0:free`
|
|
531
|
+
* (reasoning:!0, no efforts) and command-code@1.44.0 added both
|
|
532
|
+
* `meta/muse-spark-1.3` variants — all think automatically with no
|
|
533
|
+
* selectable levels.)
|
|
502
534
|
* Keep in sync via the dsh-commandcode-upstream skill.
|
|
503
535
|
*/
|
|
504
536
|
const KNOWN_THINKING_MODELS = /* @__PURE__ */ new Set([
|
|
@@ -509,7 +541,6 @@ const KNOWN_THINKING_MODELS = /* @__PURE__ */ new Set([
|
|
|
509
541
|
"Qwen/Qwen3.7-Max",
|
|
510
542
|
"Qwen/Qwen3.7-Plus",
|
|
511
543
|
"minimax/minimax-m3-free",
|
|
512
|
-
"moonshotai/Kimi-K3",
|
|
513
544
|
"moonshotai/Kimi-K2.7-Code",
|
|
514
545
|
"moonshotai/Kimi-K2.7-Code-Highspeed",
|
|
515
546
|
"stepfun/Step-3.5-Flash",
|
|
@@ -519,9 +550,12 @@ const KNOWN_THINKING_MODELS = /* @__PURE__ */ new Set([
|
|
|
519
550
|
"thinkingmachines/inkling",
|
|
520
551
|
"thinkingmachines/inkling-small",
|
|
521
552
|
"poolside/laguna-s-2.1-free",
|
|
553
|
+
"meituan/LongCat-2.0:free",
|
|
522
554
|
"meta/muse-spark-1.1",
|
|
523
555
|
"meta/muse-spark-1.2",
|
|
524
|
-
"meta/muse-spark-1.2-contributor"
|
|
556
|
+
"meta/muse-spark-1.2-contributor",
|
|
557
|
+
"meta/muse-spark-1.3",
|
|
558
|
+
"meta/muse-spark-1.3-contributor"
|
|
525
559
|
]);
|
|
526
560
|
/**
|
|
527
561
|
* The minimum subscription plan a model is included in, per the official plan
|
|
@@ -529,6 +563,14 @@ const KNOWN_THINKING_MODELS = /* @__PURE__ */ new Set([
|
|
|
529
563
|
* and `/docs/resources/pricing-limits`). Each plan's model list is a superset of
|
|
530
564
|
* the one below it: Go ⊂ GOAT ⊂ Pro ⊂ Provider/Max. Models absent from every
|
|
531
565
|
* plan list (Claude Opus/Fable, Fugu Ultra) are Provider-tier.
|
|
566
|
+
* `claude-fable-5-1` (Claude Fable 5.1, added in command-code@1.40.0) is
|
|
567
|
+
* Provider/Max-tier exactly like `claude-fable-5` — its availability matrix on
|
|
568
|
+
* the official plan/pricing pages grants individual-provider/max/ultra and
|
|
569
|
+
* teams-pro only, and the CLI's plan-access map blocks it on Go/GOAT/Pro.
|
|
570
|
+
* command-code@1.41.0 added `Qwen/Qwen3.8-Max-0902` (Go) and 1.42.0 added
|
|
571
|
+
* `meituan/LongCat-2.0:free` (Go, free promo); command-code@1.43.0 added
|
|
572
|
+
* `google/gemini-3.8-flash` (GOAT) and 1.44.0 added `meta/muse-spark-1.3`
|
|
573
|
+
* (GOAT) plus its Contributor sibling (Go).
|
|
532
574
|
*
|
|
533
575
|
* The Provider API exposes no plan metadata, so this snapshot is the source of
|
|
534
576
|
* truth for the picker's plan annotation — it answers "which plan do I need to
|
|
@@ -550,13 +592,16 @@ const KNOWN_PLANS = {
|
|
|
550
592
|
"Qwen/Qwen3.8-27B": "go",
|
|
551
593
|
"Qwen/Qwen3.8-Flash": "go",
|
|
552
594
|
"Qwen/Qwen3.8-Max": "go",
|
|
595
|
+
"Qwen/Qwen3.8-Max-0902": "go",
|
|
553
596
|
"deepseek/deepseek-v4-flash-fast": "go",
|
|
554
597
|
"deepseek/deepseek-v4-flash": "go",
|
|
555
598
|
"deepseek/deepseek-v4-flash-vision-exp": "go",
|
|
556
599
|
"deepseek/deepseek-v4-pro": "go",
|
|
557
600
|
"gpt-5.6-luna": "go",
|
|
558
601
|
"inclusionai/ling-3.0-flash-free": "go",
|
|
602
|
+
"meituan/LongCat-2.0:free": "go",
|
|
559
603
|
"meta/muse-spark-1.2-contributor": "go",
|
|
604
|
+
"meta/muse-spark-1.3-contributor": "go",
|
|
560
605
|
"minimax/minimax-m2.7-free": "go",
|
|
561
606
|
"minimax/minimax-m3-free": "go",
|
|
562
607
|
"moonshotai/Kimi-K2.5": "go",
|
|
@@ -583,8 +628,10 @@ const KNOWN_PLANS = {
|
|
|
583
628
|
"zai-org/GLM-5.2-Fast": "go",
|
|
584
629
|
"zai-org/GLM-5.3": "go",
|
|
585
630
|
"google/gemini-3.7-flash": "goat",
|
|
631
|
+
"google/gemini-3.8-flash": "goat",
|
|
586
632
|
"gpt-5.6-sol": "goat",
|
|
587
633
|
"meta/muse-spark-1.2": "goat",
|
|
634
|
+
"meta/muse-spark-1.3": "goat",
|
|
588
635
|
"xai/grok-4.6": "goat",
|
|
589
636
|
"claude-haiku-4-5-20251001": "pro",
|
|
590
637
|
"claude-sonnet-4-6": "pro",
|
|
@@ -599,6 +646,7 @@ const KNOWN_PLANS = {
|
|
|
599
646
|
"gpt-5.5": "pro",
|
|
600
647
|
"gpt-5.6-terra": "pro",
|
|
601
648
|
"meta/muse-spark-1.1": "pro",
|
|
649
|
+
"claude-fable-5-1": "provider",
|
|
602
650
|
"claude-fable-5": "provider",
|
|
603
651
|
"claude-opus-4-7": "provider",
|
|
604
652
|
"claude-opus-4-8": "provider",
|
|
@@ -739,6 +787,10 @@ const KNOWN_DEALS = {
|
|
|
739
787
|
"poolside/laguna-s-2.1-free": {
|
|
740
788
|
label: "FREE",
|
|
741
789
|
free: true
|
|
790
|
+
},
|
|
791
|
+
"meituan/LongCat-2.0:free": {
|
|
792
|
+
label: "FREE",
|
|
793
|
+
free: true
|
|
742
794
|
}
|
|
743
795
|
};
|
|
744
796
|
/**
|
|
@@ -792,30 +844,6 @@ function peakPricingLabel(modelId, now = Date.now()) {
|
|
|
792
844
|
if (state === void 0) return void 0;
|
|
793
845
|
return state === "peak" ? "Peak" : "Half";
|
|
794
846
|
}
|
|
795
|
-
const COMMAND_CODE_CLI_VERSION = "1.39.2";
|
|
796
|
-
const DEFAULT_API_BASE = "https://api.commandcode.ai";
|
|
797
|
-
const DEFAULT_GENERATE_MAX_TOKENS = 64e3;
|
|
798
|
-
const DEFAULT_MAX_OUTPUT_TOKENS = 65536;
|
|
799
|
-
const MODELS_TIMEOUT_MS = 1e4;
|
|
800
|
-
/** How long the picker's plan-filter billing facts stay cached before refetching. */
|
|
801
|
-
const BILLING_ACCESS_TTL_MS = 3e5;
|
|
802
|
-
/**
|
|
803
|
-
* Subscription statuses the CLI treats as live (`Mr` in command-code's
|
|
804
|
-
* cli.mjs): the plan gate applies only under one of these.
|
|
805
|
-
*/
|
|
806
|
-
const ACTIVE_SUBSCRIPTION_STATUSES = /* @__PURE__ */ new Set([
|
|
807
|
-
"active",
|
|
808
|
-
"trialing",
|
|
809
|
-
"past_due"
|
|
810
|
-
]);
|
|
811
|
-
/** Head-of-request timeout: how long to wait for the first response byte. */
|
|
812
|
-
const DEFAULT_REQUEST_TIMEOUT_MS = 6e4;
|
|
813
|
-
/** Stream idle timeout: a generation that stalls this long is a dead connection. */
|
|
814
|
-
const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 3e5;
|
|
815
|
-
const MODEL_CACHE_VERSION = 1;
|
|
816
|
-
function isRecord(value) {
|
|
817
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
818
|
-
}
|
|
819
847
|
/**
|
|
820
848
|
* Official display label for a model's minimum plan, or undefined for models
|
|
821
849
|
* outside the snapshot (e.g. future catalog additions).
|
|
@@ -871,6 +899,53 @@ function capabilityDescription(modelId, contextWindow, now = Date.now()) {
|
|
|
871
899
|
if (ctx !== void 0) parts.push(ctx);
|
|
872
900
|
return parts.join(" · ");
|
|
873
901
|
}
|
|
902
|
+
//#endregion
|
|
903
|
+
//#region src/adapter.ts
|
|
904
|
+
/**
|
|
905
|
+
* DeepSeek Harness LLM adapter for the Command Code Provider API.
|
|
906
|
+
*
|
|
907
|
+
* Ported from pi-commandcode-provider@0.5.1 (MIT). This is an unofficial,
|
|
908
|
+
* community-maintained integration; you need your own Command Code account
|
|
909
|
+
* and API key or subscription, and Command Code's terms apply.
|
|
910
|
+
*
|
|
911
|
+
* Wire protocol (reverse-engineered by the pi plugin, command-code@1.28.4;
|
|
912
|
+
* re-verified against command-code@1.44.0 — endpoints, request shape, and
|
|
913
|
+
* stream events unchanged):
|
|
914
|
+
* POST {apiBase}/alpha/generate
|
|
915
|
+
* body: { config, memory, taste, skills, params: { model, messages, tools,
|
|
916
|
+
* system, max_tokens, temperature, stream, reasoning_effort? }, threadId }
|
|
917
|
+
* SSE-ish JSONL events: text-delta | reasoning-start/delta/end | tool-call
|
|
918
|
+
* | tool-result | finish | error
|
|
919
|
+
* Model catalog: GET {apiBase}/provider/v1/models -> { object: 'list', data: [...] }
|
|
920
|
+
*
|
|
921
|
+
* The adapter is deliberately free of cordis/schemastery: it receives a
|
|
922
|
+
* per-request options thunk and an API-key resolver from the plugin entry
|
|
923
|
+
* (src/index.ts), so a settings change reaches the very next request.
|
|
924
|
+
*/
|
|
925
|
+
const COMMAND_CODE_CLI_VERSION = "1.44.0";
|
|
926
|
+
const DEFAULT_API_BASE = "https://api.commandcode.ai";
|
|
927
|
+
const DEFAULT_GENERATE_MAX_TOKENS = 64e3;
|
|
928
|
+
const DEFAULT_MAX_OUTPUT_TOKENS = 65536;
|
|
929
|
+
const MODELS_TIMEOUT_MS = 1e4;
|
|
930
|
+
/** How long the picker's plan-filter billing facts stay cached before refetching. */
|
|
931
|
+
const BILLING_ACCESS_TTL_MS = 3e5;
|
|
932
|
+
/**
|
|
933
|
+
* Subscription statuses the CLI treats as live (`Mr` in command-code's
|
|
934
|
+
* cli.mjs): the plan gate applies only under one of these.
|
|
935
|
+
*/
|
|
936
|
+
const ACTIVE_SUBSCRIPTION_STATUSES = /* @__PURE__ */ new Set([
|
|
937
|
+
"active",
|
|
938
|
+
"trialing",
|
|
939
|
+
"past_due"
|
|
940
|
+
]);
|
|
941
|
+
/** Head-of-request timeout: how long to wait for the first response byte. */
|
|
942
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 6e4;
|
|
943
|
+
/** Stream idle timeout: a generation that stalls this long is a dead connection. */
|
|
944
|
+
const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 3e5;
|
|
945
|
+
const MODEL_CACHE_VERSION = 1;
|
|
946
|
+
function isRecord(value) {
|
|
947
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
948
|
+
}
|
|
874
949
|
function stringValue(value) {
|
|
875
950
|
return typeof value === "string" ? value : void 0;
|
|
876
951
|
}
|
|
@@ -2020,38 +2095,75 @@ function applyCommands(ctx, deps) {
|
|
|
2020
2095
|
ctx.commands.register(commandDefinition(deps));
|
|
2021
2096
|
}
|
|
2022
2097
|
//#endregion
|
|
2098
|
+
//#region src/wire-shared.ts
|
|
2099
|
+
/** The npm package identity every contribution and descriptor claims. */
|
|
2100
|
+
const REMOTE_PACKAGE = "@mars-sea/dsh-commandcode-provider";
|
|
2101
|
+
/** The Cordis service key the Gateway resolves every Command Code Remote from. */
|
|
2102
|
+
const REMOTE_SERVICE = "commandcodeUsage";
|
|
2103
|
+
/** The wire namespace all Command Code endpoints share. */
|
|
2104
|
+
const REMOTE_NAMESPACE = "commandcode";
|
|
2105
|
+
/**
|
|
2106
|
+
* Build the validator helpers one endpoint uses Sequence. `prefix` names the
|
|
2107
|
+
* endpoint in the rejection message (e.g. `commandcode/report result:`), so
|
|
2108
|
+
* each wire file keeps its own diagnostic phrasing while sharing the helper
|
|
2109
|
+
* bodies.
|
|
2110
|
+
*
|
|
2111
|
+
* The helpers return the reject call directly in the failure branch: since
|
|
2112
|
+
* `reject` is typed `never`, the ternary's union collapses to the success type
|
|
2113
|
+
* without relying on TypeScript's control-flow analysis of a never-returning
|
|
2114
|
+
* call (which only recognizes function declarations, not the destructured
|
|
2115
|
+
* arrow `reject` callers receive from this factory).
|
|
2116
|
+
*/
|
|
2117
|
+
function makeBoundaryValidator(prefix) {
|
|
2118
|
+
const reject = (field) => {
|
|
2119
|
+
throw new TypeError(`${prefix} invalid ${field}`);
|
|
2120
|
+
};
|
|
2121
|
+
const record = (value, field) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : reject(field);
|
|
2122
|
+
const stringField = (source, key, field) => typeof source[key] === "string" ? source[key] : reject(field);
|
|
2123
|
+
const numberField = (source, key, field) => typeof source[key] === "number" && Number.isFinite(source[key]) ? source[key] : reject(field);
|
|
2124
|
+
const booleanField = (source, key, field) => typeof source[key] === "boolean" ? source[key] : reject(field);
|
|
2125
|
+
return {
|
|
2126
|
+
reject,
|
|
2127
|
+
record,
|
|
2128
|
+
stringField,
|
|
2129
|
+
numberField,
|
|
2130
|
+
booleanField
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Build one strict invocation descriptor. Every Command Code Remote shares the
|
|
2135
|
+
* `commandcode` namespace, the `commandcodeUsage` service, and a strict
|
|
2136
|
+
* `mode: 'strict'` result — only the endpoint, method, result type symbol, and
|
|
2137
|
+
* schema differ — so the boilerplate lives here once and each endpoint supplies
|
|
2138
|
+
* only its own facts.
|
|
2139
|
+
*/
|
|
2140
|
+
function makeRemoteDescriptor(endpoint, method, typeSymbol, schema) {
|
|
2141
|
+
return {
|
|
2142
|
+
id: `${REMOTE_PACKAGE}#${endpoint}`,
|
|
2143
|
+
service: REMOTE_SERVICE,
|
|
2144
|
+
namespace: REMOTE_NAMESPACE,
|
|
2145
|
+
method,
|
|
2146
|
+
invocation: { kind: "direct" },
|
|
2147
|
+
parameters: [],
|
|
2148
|
+
result: {
|
|
2149
|
+
mode: "strict",
|
|
2150
|
+
typeSymbol,
|
|
2151
|
+
schema
|
|
2152
|
+
}
|
|
2153
|
+
};
|
|
2154
|
+
}
|
|
2155
|
+
//#endregion
|
|
2023
2156
|
//#region src/usage-wire.ts
|
|
2024
2157
|
/** The npm package identity both contribution registrations claim. */
|
|
2025
|
-
const USAGE_REMOTE_PACKAGE =
|
|
2158
|
+
const USAGE_REMOTE_PACKAGE = REMOTE_PACKAGE;
|
|
2026
2159
|
/** Canonical `<namespace>/<method>` endpoint of the usage report Remote. */
|
|
2027
2160
|
const USAGE_REPORT_ENDPOINT = "commandcode/report";
|
|
2028
|
-
/**
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
const value = source[key];
|
|
2035
|
-
if (typeof value !== "number" || !Number.isFinite(value)) reject$1(field);
|
|
2036
|
-
return value;
|
|
2037
|
-
}
|
|
2038
|
-
/** Read one required string field (`field` is the dotted error label). */
|
|
2039
|
-
function stringField(source, key, field) {
|
|
2040
|
-
const value = source[key];
|
|
2041
|
-
if (typeof value !== "string") reject$1(field);
|
|
2042
|
-
return value;
|
|
2043
|
-
}
|
|
2044
|
-
/** Read one required boolean field (`field` is the dotted error label). */
|
|
2045
|
-
function booleanField(source, key, field) {
|
|
2046
|
-
const value = source[key];
|
|
2047
|
-
if (typeof value !== "boolean") reject$1(field);
|
|
2048
|
-
return value;
|
|
2049
|
-
}
|
|
2050
|
-
/** Narrow an unknown value to a plain record, or reject. */
|
|
2051
|
-
function record(value, field) {
|
|
2052
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) reject$1(field);
|
|
2053
|
-
return value;
|
|
2054
|
-
}
|
|
2161
|
+
/**
|
|
2162
|
+
* The shared read/validate helpers, prefixed with the report endpoint so
|
|
2163
|
+
* rejection messages name the offending boundary (the catalog endpoint below
|
|
2164
|
+
* shares this prefix, matching the historical behavior).
|
|
2165
|
+
*/
|
|
2166
|
+
const { reject: reject$1, record, stringField, numberField, booleanField } = makeBoundaryValidator("commandcode/report result:");
|
|
2055
2167
|
/** Validate one window-limit block (`fiveHour` / `weekly`). */
|
|
2056
2168
|
function windowLimit(value, field) {
|
|
2057
2169
|
const source = record(value, field);
|
|
@@ -2074,8 +2186,8 @@ function parseUsageReport(value) {
|
|
|
2074
2186
|
const report = { failures };
|
|
2075
2187
|
if (source.blocked !== void 0) {
|
|
2076
2188
|
const blocked = source.blocked;
|
|
2077
|
-
if (blocked
|
|
2078
|
-
|
|
2189
|
+
if (blocked === "invalid-key" || blocked === "service-unavailable" || blocked === "network") report.blocked = blocked;
|
|
2190
|
+
else reject$1("blocked");
|
|
2079
2191
|
}
|
|
2080
2192
|
if (source.account !== void 0) {
|
|
2081
2193
|
const account = record(source.account, "account");
|
|
@@ -2139,8 +2251,8 @@ function parseAccountUsage(value) {
|
|
|
2139
2251
|
/** Parse the wire result into a {@link CommandCodeAccountsReport}. */
|
|
2140
2252
|
function parseAccountsReport(value) {
|
|
2141
2253
|
const accounts = record(value, "result").accounts;
|
|
2142
|
-
if (
|
|
2143
|
-
return
|
|
2254
|
+
if (Array.isArray(accounts)) return { accounts: accounts.map(parseAccountUsage) };
|
|
2255
|
+
return reject$1("accounts");
|
|
2144
2256
|
}
|
|
2145
2257
|
/**
|
|
2146
2258
|
* The strict result codec both halves attach to the descriptor. Hand-rolled:
|
|
@@ -2158,19 +2270,7 @@ const USAGE_HOST_CONTRIBUTION = {
|
|
|
2158
2270
|
events: [],
|
|
2159
2271
|
objects: []
|
|
2160
2272
|
},
|
|
2161
|
-
invocations: [{
|
|
2162
|
-
id: `${USAGE_REMOTE_PACKAGE}#${USAGE_REPORT_ENDPOINT}`,
|
|
2163
|
-
service: "commandcodeUsage",
|
|
2164
|
-
namespace: "commandcode",
|
|
2165
|
-
method: "report",
|
|
2166
|
-
invocation: { kind: "direct" },
|
|
2167
|
-
parameters: [],
|
|
2168
|
-
result: {
|
|
2169
|
-
mode: "strict",
|
|
2170
|
-
typeSymbol: `${USAGE_REMOTE_PACKAGE}#CommandCodeAccountsReport`,
|
|
2171
|
-
schema: usageReportSchema
|
|
2172
|
-
}
|
|
2173
|
-
}]
|
|
2273
|
+
invocations: [makeRemoteDescriptor(USAGE_REPORT_ENDPOINT, "report", `${USAGE_REMOTE_PACKAGE}#CommandCodeAccountsReport`, usageReportSchema)]
|
|
2174
2274
|
};
|
|
2175
2275
|
/** Canonical `<namespace>/<method>` endpoint of the model-catalog Remote. */
|
|
2176
2276
|
const MODELS_ENDPOINT = "commandcode/models";
|
|
@@ -2185,26 +2285,14 @@ function parseCatalogModel(value) {
|
|
|
2185
2285
|
/** Parse the wire result into a {@link CommandCodeCatalog}. */
|
|
2186
2286
|
function parseCatalog(value) {
|
|
2187
2287
|
const models = record(value, "result").models;
|
|
2188
|
-
if (
|
|
2189
|
-
return
|
|
2288
|
+
if (Array.isArray(models)) return { models: models.map(parseCatalogModel) };
|
|
2289
|
+
return reject$1("models");
|
|
2190
2290
|
}
|
|
2191
2291
|
/**
|
|
2192
2292
|
* The model-catalog invocation descriptor, sharing the same `commandcodeUsage`
|
|
2193
2293
|
* service and `commandcode` namespace as the usage report.
|
|
2194
2294
|
*/
|
|
2195
|
-
const MODELS_DESCRIPTOR = {
|
|
2196
|
-
id: `${USAGE_REMOTE_PACKAGE}#${MODELS_ENDPOINT}`,
|
|
2197
|
-
service: "commandcodeUsage",
|
|
2198
|
-
namespace: "commandcode",
|
|
2199
|
-
method: "models",
|
|
2200
|
-
invocation: { kind: "direct" },
|
|
2201
|
-
parameters: [],
|
|
2202
|
-
result: {
|
|
2203
|
-
mode: "strict",
|
|
2204
|
-
typeSymbol: `${USAGE_REMOTE_PACKAGE}#CommandCodeCatalog`,
|
|
2205
|
-
schema: { parse: parseCatalog }
|
|
2206
|
-
}
|
|
2207
|
-
};
|
|
2295
|
+
const MODELS_DESCRIPTOR = makeRemoteDescriptor(MODELS_ENDPOINT, "models", `${USAGE_REMOTE_PACKAGE}#CommandCodeCatalog`, { parse: parseCatalog });
|
|
2208
2296
|
//#endregion
|
|
2209
2297
|
//#region src/login-wire.ts
|
|
2210
2298
|
/** The canonical endpoint paths of the three login Remotes. */
|
|
@@ -2220,7 +2308,12 @@ const REASONS = [
|
|
|
2220
2308
|
"cancelled",
|
|
2221
2309
|
"error"
|
|
2222
2310
|
];
|
|
2223
|
-
/**
|
|
2311
|
+
/** The shared read/validate helpers, prefixed with the login endpoint so
|
|
2312
|
+
* rejection messages name the offending boundary. */
|
|
2313
|
+
/** Reject one boundary value with a field-naming error. A module-level
|
|
2314
|
+
* function declaration (not the factory's destructured arrow) so TypeScript's
|
|
2315
|
+
* control-flow analysis recognizes it as never-returning and narrows `state`
|
|
2316
|
+
* after the guard below. */
|
|
2224
2317
|
function reject(field) {
|
|
2225
2318
|
throw new TypeError(`commandcode/login result: invalid ${field}`);
|
|
2226
2319
|
}
|
|
@@ -2261,19 +2354,7 @@ function parseLoginStatus(value) {
|
|
|
2261
2354
|
const loginStatusSchema = { parse: parseLoginStatus };
|
|
2262
2355
|
/** Build one login invocation descriptor (uniform result, no parameters). */
|
|
2263
2356
|
function loginDescriptor(endpoint, method) {
|
|
2264
|
-
return {
|
|
2265
|
-
id: `${USAGE_REMOTE_PACKAGE}#${endpoint}`,
|
|
2266
|
-
service: "commandcodeUsage",
|
|
2267
|
-
namespace: "commandcode",
|
|
2268
|
-
method,
|
|
2269
|
-
invocation: { kind: "direct" },
|
|
2270
|
-
parameters: [],
|
|
2271
|
-
result: {
|
|
2272
|
-
mode: "strict",
|
|
2273
|
-
typeSymbol: `${USAGE_REMOTE_PACKAGE}#CommandCodeLoginStatus`,
|
|
2274
|
-
schema: loginStatusSchema
|
|
2275
|
-
}
|
|
2276
|
-
};
|
|
2357
|
+
return makeRemoteDescriptor(endpoint, method, `${REMOTE_PACKAGE}#CommandCodeLoginStatus`, loginStatusSchema);
|
|
2277
2358
|
}
|
|
2278
2359
|
/** The three login descriptors, shared verbatim by Host registration and Client mount. */
|
|
2279
2360
|
const LOGIN_DESCRIPTORS = [
|