@nodaro/shared 3.24.0 → 3.26.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.
Files changed (50) hide show
  1. package/dist/index.cjs +1086 -257
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +531 -97
  4. package/dist/index.d.ts +531 -97
  5. package/dist/index.js +1034 -258
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/condition-variables.test.ts +12 -0
  9. package/src/__tests__/content-recipe-ideas.test.ts +9 -4
  10. package/src/__tests__/credit-identifiers.test.ts +31 -6
  11. package/src/__tests__/dialogue-capabilities.test.ts +3 -2
  12. package/src/__tests__/edit-plan-minute-ids.test.ts +82 -0
  13. package/src/__tests__/image-model-roles.test.ts +57 -0
  14. package/src/__tests__/image-ref-limit.test.ts +1 -0
  15. package/src/__tests__/json-kinds.test.ts +179 -0
  16. package/src/__tests__/llm-models.test.ts +136 -37
  17. package/src/__tests__/lone-media-url.test.ts +78 -0
  18. package/src/__tests__/presentation-utils.test.ts +1 -0
  19. package/src/__tests__/preview-gate.test.ts +2 -2
  20. package/src/__tests__/pricing-default-duration.test.ts +56 -15
  21. package/src/__tests__/private-host.test.ts +24 -0
  22. package/src/__tests__/prompt-length-limits.test.ts +2 -0
  23. package/src/__tests__/render-nodes.test.ts +22 -3
  24. package/src/__tests__/tts-capabilities.test.ts +61 -1
  25. package/src/__tests__/video-link-input.test.ts +148 -0
  26. package/src/__tests__/video-link-needs.test.ts +67 -0
  27. package/src/__tests__/video-request-normalize.test.ts +18 -3
  28. package/src/condition-variables.ts +3 -1
  29. package/src/content-recipe-ideas.ts +5 -2
  30. package/src/credit-identifiers.ts +48 -37
  31. package/src/edit-plan-contract.ts +67 -1
  32. package/src/fan-out-rows.ts +2 -2
  33. package/src/image-model-roles.ts +62 -0
  34. package/src/index.ts +59 -1
  35. package/src/json-kinds.ts +188 -0
  36. package/src/llm-models.ts +348 -23
  37. package/src/lone-media-url.ts +57 -0
  38. package/src/model-catalog.ts +160 -13
  39. package/src/model-constants.ts +79 -43
  40. package/src/node-default-mappings.ts +4 -0
  41. package/src/pipeline-types.ts +13 -2
  42. package/src/presentation-utils.ts +8 -1
  43. package/src/private-host.ts +91 -0
  44. package/src/producer-types.ts +3 -0
  45. package/src/render-nodes.ts +12 -1
  46. package/src/scene-node-types.ts +17 -5
  47. package/src/settings-input.ts +2 -1
  48. package/src/social-post-readers.ts +37 -0
  49. package/src/video-link.ts +238 -0
  50. package/src/voices.ts +16 -9
package/src/llm-models.ts CHANGED
@@ -15,7 +15,7 @@
15
15
 
16
16
  export type LlmTier = "economy" | "standard" | "premium"
17
17
  export type KieApiFormat = "chat-completions" | "messages" | "responses"
18
- export type LlmVendor = "anthropic" | "google" | "openai" | "xai"
18
+ export type LlmVendor = "anthropic" | "deepseek" | "google" | "moonshot" | "openai" | "xai"
19
19
 
20
20
  export const LLM_REASONING_EFFORTS = ["none", "low", "medium", "high", "xhigh", "max"] as const
21
21
  export type LlmReasoningEffort = (typeof LLM_REASONING_EFFORTS)[number]
@@ -92,6 +92,43 @@ export interface LlmModelDef {
92
92
  directReasoningEfforts?: readonly LlmReasoningEffort[]
93
93
  /** false = model rejects `temperature` (Claude 5-era, GPT-5.6). Absent = accepts. */
94
94
  supportsTemperature?: false
95
+ /**
96
+ * false = the model 400s on a FORCED `tool_choice` (`{ type: "tool" }` /
97
+ * `{ type: "any" }`) — Claude Sonnet 5.5 and Opus 5.5 (vendor docs: "not
98
+ * supported for this model"). Absent = forcing is accepted.
99
+ *
100
+ * Only meaningful with `structuredOutputMode: "anthropic-tool"`: such a model
101
+ * is asked with `tool_choice: auto` plus an instruction naming the tool, and
102
+ * the tool carries `strict: true` whenever its schema is expressible in the
103
+ * vendor's strict subset (`anthropicStrictToolSchema` in llm-client). The
104
+ * caller's Zod still validates every answer, so nothing the wire withholds is
105
+ * lost. Declared per model, never matched on a model name.
106
+ */
107
+ supportsForcedToolChoice?: false
108
+ /**
109
+ * true = the model binds each thinking block to the exact conversation prefix
110
+ * that produced it ("preserved thinking" — Claude Sonnet 5.5 / Opus 5.5):
111
+ * replaying a block after an earlier turn was edited, dropped or rebuilt is a
112
+ * 400 on accounts the vendor enforces. A caller that trims or rebuilds stored
113
+ * history between requests (the Workflow Copilot keeps a token budget by
114
+ * dropping its oldest turns) must strip thinking blocks from the turns it
115
+ * replays. Within one request's own tool loop the history only grows, so
116
+ * blocks produced there stay valid.
117
+ */
118
+ conversationBoundThinking?: true
119
+ /**
120
+ * true = this model's reasoning effort takes effect ONLY on the vendor's own
121
+ * API: the aggregator accepts the field and silently ignores it. Measured
122
+ * 2026-10-08 for the Claude family on KIE — `low`, `max` and no effort gave
123
+ * the same output length on a reasoning-heavy prompt, and no thinking block
124
+ * ever came back, even on Sonnet 4.6 at `max`.
125
+ *
126
+ * So an effort-bearing call on such a model is SERVED direct, and it bills
127
+ * as Advanced mode does — one rung up (decided 2026-10-08: "effort =
128
+ * Advanced"). {@link llmServesDirect} is the one place that decides it, for
129
+ * the credit identifier and the routing alike.
130
+ */
131
+ effortRequiresDirect?: true
95
132
  /** Claude-only: KIE is the preferred routing, direct Anthropic the fallback. */
96
133
  preferKie?: true
97
134
  /**
@@ -306,6 +343,9 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
306
343
  supportsImages: true,
307
344
  maxOutputTokens: 8192,
308
345
  directFallbackModel: "claude-haiku-4-5-20251001",
346
+ // KIE-first since 2026-10-08 (a call is priced on the lane it runs on);
347
+ // KIE served it plain and with a tool on its streaming wire that day.
348
+ preferKie: true,
309
349
  },
310
350
  {
311
351
  id: "claude-sonnet-4.6",
@@ -319,7 +359,12 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
319
359
  supportsImages: true,
320
360
  maxOutputTokens: 16384,
321
361
  directFallbackModel: "claude-sonnet-4-6",
362
+ // KIE-first since 2026-10-08 (a call is priced on the lane it runs on);
363
+ // KIE served it plain and with a tool on its streaming wire that day.
364
+ preferKie: true,
322
365
  reasoningEfforts: ["low", "medium", "high", "max"],
366
+ // KIE ignores Claude effort (measured 2026-10-08): an effort call runs direct and bills as Advanced.
367
+ effortRequiresDirect: true,
323
368
  },
324
369
  {
325
370
  id: "gpt-5.2",
@@ -358,14 +403,14 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
358
403
  // text such as a name badge), which is exactly what video-analysis casts
359
404
  // identities from — so adding an entry here would silently move analysis to
360
405
  // the shallower lane. Don't. Full comparison lives with the analysis engine.
361
- // The ONE Gemini model routed direct-first. It is the premium/low-volume
362
- // tier (video-analysis `pro`, no LLM_FEATURE_DEFAULTS entry), so the ~4×
363
- // list-price premium lands on the smallest call volume — and it is where
364
- // the direct lane's capability wins actually matter: real `thinkingLevel`
365
- // control, native media ingestion, and a `responseJsonSchema` that honours
366
- // `additionalProperties` (KIE's `response_format` silently DROPS
406
+ // KIE-first since 2026-10-08 (decided: a call is priced on the lane it runs
407
+ // on, so the base premium price buys the KIE lane; the direct lane is
408
+ // Advanced mode, billed `premium-direct`). It was the one direct-first
409
+ // Gemini before. What the direct lane buys, now behind Advanced: real
410
+ // `thinkingLevel` control, native media ingestion, and a `responseJsonSchema`
411
+ // that honours `additionalProperties` (KIE's `response_format` silently DROPS
367
412
  // record/map-shaped fields — see the z.record rule in backend/CLAUDE.md).
368
- preferDirect: true,
413
+ // Video-analysis is unaffected: it pins `requireLane: "direct"` itself.
369
414
  // Reasons with no thinking param sent on both lanes — the proxied endpoint
370
415
  // DEFAULTS to "high" (above), and the direct lane reasons harder still.
371
416
  // Floored at its own 16384: its KIE fallback is not known to take more.
@@ -389,6 +434,8 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
389
434
  maxOutputTokens: 16384,
390
435
  directFallbackModel: "claude-opus-4-7",
391
436
  reasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
437
+ // KIE ignores Claude effort (measured 2026-10-08): an effort call runs direct and bills as Advanced.
438
+ effortRequiresDirect: true,
392
439
  supportsTemperature: false,
393
440
  preferKie: true,
394
441
  },
@@ -538,10 +585,76 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
538
585
  // why this is per-model and not a lane-wide flag.
539
586
  kieCollapseStream: true,
540
587
  },
588
+ // ── GPT-6 Luna / Sol / 6.1 Sol ────────────────────────────────────────────
589
+ // Same KIE endpoint and dialect as gpt-6-astra (codex/v1/responses; the doc
590
+ // pages differ only in the model name). Live-probed 2026-10-08, per model:
591
+ // `text.format` json_schema ENFORCED (echo `strict: true`, schema-valid
592
+ // reply), `temperature: 0.2` echoed back as 1 → silently ignored, no
593
+ // reasoning param → echo "medium" (reasons by default), and data-URI vision.
594
+ // Unlike astra, the NON-stream lane served them reliably — luna 10/10 and sol
595
+ // 10/10, 6.1 sol 8/8 at levels other than `none` (incl. 4 long structured
596
+ // calls each, 500–1,500 output tokens) — so none of them is collapsed:
597
+ // `credits_consumed` stays the real provider charge.
598
+ // Their ladder is WIDER than astra's doc-enum one: `none` and `max` were each
599
+ // sent and echoed back by the endpoint (6.1 sol excepted below).
600
+ {
601
+ id: "gpt-6-luna",
602
+ displayName: "GPT-6 Luna",
603
+ desc: "Fastest GPT-6, high-volume workloads",
604
+ tier: "economy",
605
+ kieFormat: "responses",
606
+ kieSlugOrModel: "gpt-6-luna",
607
+ vendor: "openai",
608
+ structuredOutputMode: "responses-json-schema",
609
+ supportsImages: true,
610
+ maxOutputTokens: 16384,
611
+ reasoningEfforts: ["none", "low", "medium", "high", "xhigh", "max"],
612
+ supportsTemperature: false,
613
+ thinkingDefaultOn: true,
614
+ },
615
+ {
616
+ id: "gpt-6-sol",
617
+ displayName: "GPT-6 Sol",
618
+ desc: "Strong GPT-6, deep reasoning at lower cost",
619
+ // Premium by decision (2026-10-08), not by unit cost — "Sol" is the
620
+ // deep-reasoning rung of the family, and gpt-5.6-sol bills premium too.
621
+ tier: "premium",
622
+ kieFormat: "responses",
623
+ kieSlugOrModel: "gpt-6-sol",
624
+ vendor: "openai",
625
+ structuredOutputMode: "responses-json-schema",
626
+ supportsImages: true,
627
+ maxOutputTokens: 16384,
628
+ reasoningEfforts: ["none", "low", "medium", "high", "xhigh", "max"],
629
+ supportsTemperature: false,
630
+ thinkingDefaultOn: true,
631
+ },
632
+ {
633
+ id: "gpt-6.1-sol",
634
+ displayName: "GPT-6.1 Sol",
635
+ // Measured slow: 30–76 s for 500–1,100 output tokens (2026-10-08), roughly
636
+ // twice gpt-6-sol on the same request — say so where the picker shows it.
637
+ desc: "Newest GPT-6 Sol, thorough but slower",
638
+ tier: "premium",
639
+ kieFormat: "responses",
640
+ kieSlugOrModel: "gpt-6-1-sol",
641
+ vendor: "openai",
642
+ structuredOutputMode: "responses-json-schema",
643
+ supportsImages: true,
644
+ maxOutputTokens: 16384,
645
+ // NO `none`: every probe at `reasoning.effort: none` failed (502, a 120 s
646
+ // timeout, 502, 429 — 0/4, 2026-10-08) while every other level answered,
647
+ // and the same request at `none` succeeded on luna and sol. Clamping maps a
648
+ // `none` request to nothing sent (Auto) rather than to a level that fails.
649
+ reasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
650
+ supportsTemperature: false,
651
+ thinkingDefaultOn: true,
652
+ },
541
653
  {
542
654
  id: "grok-4.6",
543
655
  displayName: "Grok 4.6",
544
- desc: "xAI flagship, strong reasoning",
656
+ // Demoted 2026-10-08 when grok-4.7 registered — the flagship copy moved up.
657
+ desc: "Previous Grok, strong reasoning",
545
658
  tier: "standard",
546
659
  kieFormat: "responses",
547
660
  // KIE serves Grok on the responses dialect under its own family path —
@@ -567,10 +680,35 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
567
680
  // call needs output headroom, not just xhigh.
568
681
  thinkingDefaultOn: true,
569
682
  },
683
+ {
684
+ id: "grok-4.7",
685
+ displayName: "Grok 4.7",
686
+ desc: "xAI flagship, strong reasoning",
687
+ tier: "standard",
688
+ kieFormat: "responses",
689
+ // Same grok/v1/responses family path and wire as grok-4.6 (the KIE doc
690
+ // pages differ only in the model name). Live-probed 2026-10-08: non-stream
691
+ // 6/6, `text.format` json_schema enforced, data-URI vision, SSE deltas.
692
+ kieSlugOrModel: "grok-4-7",
693
+ vendor: "xai",
694
+ structuredOutputMode: "responses-json-schema",
695
+ supportsImages: true,
696
+ maxOutputTokens: 16384,
697
+ // 4.6's ladder. `none` is NOT honoured: the endpoint echoed it back as
698
+ // "minimal" and still reasoned (33 of 35 output tokens), so offering it
699
+ // would promise a lever the wire overrides.
700
+ reasoningEfforts: ["low", "medium", "high", "xhigh"],
701
+ // `temperature: 0.2` → echo stayed at the 0.7 default: ignored.
702
+ supportsTemperature: false,
703
+ // "Capital of France" with no reasoning param spent 310 of 311 output
704
+ // tokens reasoning.
705
+ thinkingDefaultOn: true,
706
+ },
570
707
  {
571
708
  id: "claude-sonnet-5",
572
709
  displayName: "Claude Sonnet 5",
573
- desc: "Near-Opus quality at Sonnet cost",
710
+ // Demoted 2026-10-08 when claude-sonnet-5.5 registered.
711
+ desc: "Previous Sonnet, near-Opus quality",
574
712
  tier: "standard",
575
713
  kieFormat: "messages",
576
714
  kieSlugOrModel: "claude-sonnet-5",
@@ -580,9 +718,43 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
580
718
  maxOutputTokens: 16384,
581
719
  directFallbackModel: "claude-sonnet-5",
582
720
  reasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
721
+ // KIE ignores Claude effort (measured 2026-10-08): an effort call runs direct and bills as Advanced.
722
+ effortRequiresDirect: true,
583
723
  supportsTemperature: false,
584
724
  preferKie: true,
585
725
  },
726
+ {
727
+ id: "claude-sonnet-5.5",
728
+ displayName: "Claude Sonnet 5.5",
729
+ desc: "Latest Sonnet, near-Opus quality at Sonnet cost",
730
+ tier: "standard",
731
+ kieFormat: "messages",
732
+ // KIE serves it on the Claude-native messages dialect under its plain id
733
+ // (docs.kie.ai/market/claude/claude-sonnet-5-5.md — the page is
734
+ // claude-opus-5's with the model name swapped). Live-probed 2026-10-08 on
735
+ // the streaming wire: plain, effort, and forced/auto+strict tool calls all
736
+ // answered.
737
+ kieSlugOrModel: "claude-sonnet-5-5",
738
+ vendor: "anthropic",
739
+ structuredOutputMode: "anthropic-tool",
740
+ // Anthropic 400s a forced tool_choice on this model. KIE's proxy happened
741
+ // to accept one in the probe, but the direct lane is where every
742
+ // effort-bearing and every streamed structured call goes.
743
+ supportsForcedToolChoice: false,
744
+ conversationBoundThinking: true,
745
+ supportsImages: true,
746
+ maxOutputTokens: 16384,
747
+ directFallbackModel: "claude-sonnet-5-5",
748
+ reasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
749
+ // KIE ignores Claude effort (measured 2026-10-08): an effort call runs direct and bills as Advanced.
750
+ effortRequiresDirect: true,
751
+ // Anthropic rejects non-default sampling values on this model (KIE's proxy
752
+ // accepted temperature: 0.2 in the probe; the direct lane is the contract).
753
+ supportsTemperature: false,
754
+ preferKie: true,
755
+ // Adaptive thinking runs when no thinking param is sent (vendor default).
756
+ thinkingDefaultOn: true,
757
+ },
586
758
  {
587
759
  id: "claude-opus-4.8",
588
760
  displayName: "Claude Opus 4.8",
@@ -596,13 +768,16 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
596
768
  maxOutputTokens: 16384,
597
769
  directFallbackModel: "claude-opus-4-8",
598
770
  reasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
771
+ // KIE ignores Claude effort (measured 2026-10-08): an effort call runs direct and bills as Advanced.
772
+ effortRequiresDirect: true,
599
773
  supportsTemperature: false,
600
774
  preferKie: true,
601
775
  },
602
776
  {
603
777
  id: "claude-opus-5",
604
778
  displayName: "Claude Opus 5",
605
- desc: "Latest Opus, deepest agentic reasoning",
779
+ // Demoted 2026-10-08 when claude-opus-5.5 registered.
780
+ desc: "Previous Opus, deep agentic reasoning",
606
781
  tier: "premium",
607
782
  kieFormat: "messages",
608
783
  // KIE serves Opus 5 on the Claude-native messages dialect under the plain
@@ -615,12 +790,44 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
615
790
  maxOutputTokens: 16384,
616
791
  directFallbackModel: "claude-opus-5",
617
792
  reasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
793
+ // KIE ignores Claude effort (measured 2026-10-08): an effort call runs direct and bills as Advanced.
794
+ effortRequiresDirect: true,
618
795
  supportsTemperature: false,
619
796
  preferKie: true,
620
797
  // Opus 5 reasons with NO thinking param sent (vendor default flipped from
621
798
  // Opus 4.8/4.7) — so every call needs output headroom, not just xhigh/max.
622
799
  thinkingDefaultOn: true,
623
800
  },
801
+ {
802
+ id: "claude-opus-5.5",
803
+ displayName: "Claude Opus 5.5",
804
+ // Positioned as Fable-class (decided 2026-10-08: offered wherever Fable is).
805
+ desc: "Latest Opus, frontier-class reasoning",
806
+ tier: "premium",
807
+ kieFormat: "messages",
808
+ // KIE plain id on the messages dialect (docs.kie.ai/market/claude/
809
+ // claude-opus-5-5 — claude-opus-5's page with the name swapped).
810
+ // Live-probed 2026-10-08 on the streaming wire (plain + effort); the KIE
811
+ // Claude lane was erroring for claude-opus-5 too during the tool probes.
812
+ kieSlugOrModel: "claude-opus-5-5",
813
+ vendor: "anthropic",
814
+ structuredOutputMode: "anthropic-tool",
815
+ // Forced tool_choice is a 400 on this model (vendor docs) — see the field.
816
+ supportsForcedToolChoice: false,
817
+ conversationBoundThinking: true,
818
+ supportsImages: true,
819
+ maxOutputTokens: 16384,
820
+ directFallbackModel: "claude-opus-5-5",
821
+ reasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
822
+ // KIE ignores Claude effort (measured 2026-10-08): an effort call runs direct and bills as Advanced.
823
+ effortRequiresDirect: true,
824
+ supportsTemperature: false,
825
+ preferKie: true,
826
+ // Thinking cannot be turned off on this model at all (`disabled` is a 400
827
+ // at every effort); with no effort sent it runs adaptive at the vendor's
828
+ // `medium` default. Nothing on our wire sends `disabled`.
829
+ thinkingDefaultOn: true,
830
+ },
624
831
  {
625
832
  id: "claude-fable-5",
626
833
  displayName: "Claude Fable 5",
@@ -634,9 +841,61 @@ export const LLM_MODELS: readonly LlmModelDef[] = [
634
841
  maxOutputTokens: 16384,
635
842
  directFallbackModel: "claude-fable-5",
636
843
  reasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
844
+ // KIE ignores Claude effort (measured 2026-10-08): an effort call runs direct and bills as Advanced.
845
+ effortRequiresDirect: true,
637
846
  supportsTemperature: false,
638
847
  preferKie: true,
639
848
  },
849
+ // ── Moonshot / DeepSeek ───────────────────────────────────────────────────
850
+ // Both on KIE's THIRD responses family path, openai/v1/responses (llm-client
851
+ // derives it from `vendor`). KIE labels both pages "Chat only — not adapted
852
+ // for agent use": fine for single (structured) completions, so neither may
853
+ // back a tool-loop feature.
854
+ {
855
+ id: "kimi-k3",
856
+ displayName: "Kimi K3",
857
+ desc: "Moonshot flagship, 1M context, careful reasoning",
858
+ tier: "premium",
859
+ kieFormat: "responses",
860
+ kieSlugOrModel: "kimi-k3",
861
+ vendor: "moonshot",
862
+ // Live-probed 2026-10-08: `text.format` json_schema is ENFORCED — asked to
863
+ // answer "no json here" in plain prose, it returned schema-shaped JSON.
864
+ structuredOutputMode: "responses-json-schema",
865
+ supportsImages: true,
866
+ maxOutputTokens: 16384,
867
+ // KIE's documented enum. The endpoint accepted xhigh/none without error but
868
+ // never echoes an effort back, so nothing beyond the doc is verifiable.
869
+ reasoningEfforts: ["low", "medium", "high"],
870
+ // The doc lists no `temperature` field at all.
871
+ supportsTemperature: false,
872
+ // "Reasons by default" per KIE's doc (its usage reports no reasoning-token
873
+ // split, so this is the doc's word, not a measurement).
874
+ thinkingDefaultOn: true,
875
+ },
876
+ {
877
+ id: "deepseek-v4.1-flash",
878
+ displayName: "DeepSeek V4.1 Flash",
879
+ desc: "Very cheap and fast, solid reasoning",
880
+ tier: "economy",
881
+ kieFormat: "responses",
882
+ kieSlugOrModel: "deepseek-v4-1-flash",
883
+ vendor: "deepseek",
884
+ // Live-probed 2026-10-08: json_schema echoed `strict: true` and enforced.
885
+ structuredOutputMode: "responses-json-schema",
886
+ supportsImages: true,
887
+ // ADVISORY ONLY: KIE documents `max_output_tokens` as "not supported … no
888
+ // effect" on this model (a probe sending it was accepted and ignored), so
889
+ // neither this cap nor the reasoning floor binds its output length, and the
890
+ // `incomplete` cap-stop signal cannot fire from our own cap.
891
+ maxOutputTokens: 16384,
892
+ // The endpoint takes none/minimal/low/medium/high/xhigh/max; each of none,
893
+ // low and xhigh was echoed back. `minimal` is not in our ladder.
894
+ reasoningEfforts: ["none", "low", "medium", "high", "xhigh", "max"],
895
+ // Documented "not supported … no effect".
896
+ supportsTemperature: false,
897
+ thinkingDefaultOn: true,
898
+ },
640
899
  ] as const
641
900
 
642
901
  export const LLM_MODEL_IDS = LLM_MODELS.map((m) => m.id)
@@ -658,10 +917,12 @@ export const STRUCTURED_VISION_MODELS = LLM_MODELS.filter(
658
917
  * ship with its models silently sorted to the end of every menu unlabeled.
659
918
  * Alphabetical on purpose: stable, and no vendor-preference fights.
660
919
  */
661
- export const LLM_VENDOR_ORDER: readonly LlmVendor[] = ["anthropic", "google", "openai", "xai"]
920
+ export const LLM_VENDOR_ORDER: readonly LlmVendor[] = ["anthropic", "deepseek", "google", "moonshot", "openai", "xai"]
662
921
  export const LLM_VENDOR_LABELS: Record<LlmVendor, string> = {
663
922
  anthropic: "Anthropic",
923
+ deepseek: "DeepSeek",
664
924
  google: "Google",
925
+ moonshot: "Moonshot AI",
665
926
  openai: "OpenAI",
666
927
  xai: "xAI",
667
928
  }
@@ -763,7 +1024,9 @@ export const LLM_FEATURE_DEFAULTS: Record<LlmFeature, string> = {
763
1024
  // runs once per returned ad — volume, not depth. Must stay an image-capable
764
1025
  // structured-output model (STRUCTURED_VISION_MODELS); a registry test pins it.
765
1026
  "meta-ads-analysis": "gemini-3.6-flash",
766
- "describe-to-picker": "claude-opus-5",
1027
+ // Moved from claude-opus-5 on 2026-10-08 (decided: Opus 5.5 takes the Opus 5
1028
+ // defaults). Still an image-capable structured model — a registry test pins it.
1029
+ "describe-to-picker": "claude-opus-5.5",
767
1030
  "qa-check": "gemini-3.6-flash",
768
1031
  "generate-script": "gemini-3.6-flash",
769
1032
  "translate": "gemini-3.6-flash",
@@ -816,11 +1079,21 @@ export const LLM_MODALITY_CAPS: Record<string, { image: boolean; video: boolean;
816
1079
  "gpt-5.6-sol": { image: true, video: false, audio: false },
817
1080
  // KIE's GPT-6 doc lists text + image + file inputs only — no video, no audio.
818
1081
  "gpt-6-astra": { image: true, video: false, audio: false },
1082
+ // Same KIE doc as astra: text + image + file inputs only.
1083
+ "gpt-6-luna": { image: true, video: false, audio: false },
1084
+ "gpt-6-sol": { image: true, video: false, audio: false },
1085
+ "gpt-6.1-sol": { image: true, video: false, audio: false },
819
1086
  "grok-4.6": { image: true, video: false, audio: false },
1087
+ "grok-4.7": { image: true, video: false, audio: false },
820
1088
  "claude-sonnet-5": { image: true, video: false, audio: false },
1089
+ "claude-sonnet-5.5": { image: true, video: false, audio: false },
821
1090
  "claude-opus-4.8": { image: true, video: false, audio: false },
822
1091
  "claude-opus-5": { image: true, video: false, audio: false },
1092
+ "claude-opus-5.5": { image: true, video: false, audio: false },
823
1093
  "claude-fable-5": { image: true, video: false, audio: false },
1094
+ // KIE documents text + image input only for both.
1095
+ "kimi-k3": { image: true, video: false, audio: false },
1096
+ "deepseek-v4.1-flash": { image: true, video: false, audio: false },
824
1097
  }
825
1098
 
826
1099
  /** Capability lookup with safe default — unknown models get image-only. */
@@ -971,13 +1244,59 @@ function bumpTier(tier: LlmTier): LlmTier {
971
1244
  * rather than on a hand-maintained model list.
972
1245
  */
973
1246
  export function supportsAdvancedMode(modelId: string | undefined): boolean {
974
- return Boolean(modelId && getLlmModel(modelId)?.directGeminiModel)
1247
+ const model = modelId ? getLlmModel(modelId) : undefined
1248
+ return Boolean(model?.directGeminiModel || model?.directFallbackModel)
975
1249
  }
976
1250
 
977
1251
  /** User-facing reason a model can't offer Advanced mode. Single-sourced so the
978
1252
  * config panel's disabled hint and the route's 400 say the same thing. */
979
1253
  export const ADVANCED_MODE_UNAVAILABLE_REASON =
980
- "Advanced mode is available on Gemini models — switch the model to enable it."
1254
+ "Advanced mode is available on Gemini and Claude models — switch the model to enable it."
1255
+
1256
+ /**
1257
+ * Is this call served on the vendor's own API — and therefore billed as such?
1258
+ *
1259
+ * The rule (decided 2026-10-08): a call is priced on the lane it runs on.
1260
+ * It runs direct when Advanced mode is on, or when it carries a reasoning
1261
+ * effort on a model whose effort only works there (`effortRequiresDirect` —
1262
+ * the Claude family). Everything else runs on the aggregator at its price,
1263
+ * falling back to the vendor's API only if the aggregator fails (at no extra
1264
+ * charge).
1265
+ *
1266
+ * The SINGLE decision both the credit identifier and the LLM client's routing
1267
+ * read, so what is billed and where it runs cannot disagree. Ignores a stale
1268
+ * `advancedMode` on a model with no direct lane, like the bump always has.
1269
+ */
1270
+ export function llmServesDirect(
1271
+ modelId: string | undefined,
1272
+ reasoningEffort?: string,
1273
+ advancedMode?: boolean,
1274
+ ): boolean {
1275
+ if (!supportsAdvancedMode(modelId)) return false
1276
+ if (advancedMode) return true
1277
+ return Boolean(
1278
+ getLlmModel(modelId!)?.effortRequiresDirect && effectiveReasoningEffort(modelId, reasoningEffort) !== undefined,
1279
+ )
1280
+ }
1281
+
1282
+ /**
1283
+ * The credit rungs an LLM feature bills on, cheapest first. `premium-direct` is
1284
+ * reached only by a premium model served direct (decided 2026-10-08): the bump
1285
+ * for running direct moves one rung on THIS ladder, so a premium model has
1286
+ * somewhere to go. The effort bump keeps the three-rung ladder.
1287
+ */
1288
+ export const LLM_CREDIT_RUNGS = ["economy", "standard", "premium", "premium-direct"] as const
1289
+ export type LlmCreditRung = (typeof LLM_CREDIT_RUNGS)[number]
1290
+
1291
+ /** The credit identifier for `feature` on one rung — the standard rung is the bare feature id. */
1292
+ export function llmCreditIdForRung(feature: string, rung: LlmCreditRung): string {
1293
+ return rung === "standard" ? feature : `${feature}:${rung}`
1294
+ }
1295
+
1296
+ /** Every credit identifier a tier-priced LLM feature can bill under, in rung order. */
1297
+ export function llmTierCreditIds(feature: string): string[] {
1298
+ return LLM_CREDIT_RUNGS.map((rung) => llmCreditIdForRung(feature, rung))
1299
+ }
981
1300
 
982
1301
  export function buildLlmCreditIdentifier(
983
1302
  feature: string,
@@ -989,14 +1308,20 @@ export function buildLlmCreditIdentifier(
989
1308
  let tier = getLlmTier(modelId)
990
1309
  const eff = effectiveReasoningEffort(modelId, reasoningEffort)
991
1310
  if (eff !== undefined && EFFORT_TIER_BUMP.has(eff)) tier = bumpTier(tier)
992
- // Advanced mode routes to the vendor's own API, which bills materially more
993
- // per token than the aggregator. It bumps INDEPENDENTLY of the effort bump —
994
- // the two are separate cost levers and genuinely stack, so a max-effort
995
- // advanced economy call lands at premium. The bump is ignored on a model that
996
- // can't run advanced at all, so a stale flag never inflates a bill.
997
- if (advancedMode && supportsAdvancedMode(modelId)) tier = bumpTier(tier)
998
- if (tier === "standard") return feature
999
- return `${feature}:${tier}`
1311
+ // A call served on the vendor's own API (Advanced mode, or an effort on a
1312
+ // model whose effort only works there — llmServesDirect) bills materially
1313
+ // more per token than the aggregator. It bumps INDEPENDENTLY of the effort
1314
+ // bump — the two are separate cost levers and genuinely stack, so a
1315
+ // max-effort advanced economy call lands at premium — and on the four-rung
1316
+ // ladder, so a premium model served direct lands at `premium-direct`. A stale
1317
+ // flag on a model with no direct lane never inflates a bill.
1318
+ const rung: LlmCreditRung = llmServesDirect(modelId, reasoningEffort, advancedMode) ? bumpToDirectRung(tier) : tier
1319
+ return llmCreditIdForRung(feature, rung)
1320
+ }
1321
+
1322
+ /** One rung up the four-rung ladder — the direct-lane bump. */
1323
+ function bumpToDirectRung(tier: LlmTier): LlmCreditRung {
1324
+ return tier === "premium" ? "premium-direct" : bumpTier(tier)
1000
1325
  }
1001
1326
 
1002
1327
  /**
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The ONE rule both engines use when a text-shaped wire reaches a social post:
3
+ * a value that is exactly one media LINK — and nothing else — carries the
4
+ * medium, not the caption. An Extract Field over a saved record's cover posts
5
+ * the picture; a page link, a sentence with a link in it, a JSON value or a
6
+ * format no platform posts stays the caption (decided 2026-10-08).
7
+ *
8
+ * The file name is read from the parsed URL's PATH, anchored at its end: a host
9
+ * that merely contains a file ending (`movistar.es`, `webmd.com`, `gifs.com`)
10
+ * or a file name in the query (`?img=a.png`) is a page link. Only the formats
11
+ * the platforms accept count — avif / heic / svg / bmp are not pictures to
12
+ * Telegram, X or Instagram and would fail the post.
13
+ */
14
+ import { AUDIO_PRODUCER_TYPES, DYNAMIC_PRODUCER_TYPES, IMAGE_PRODUCER_TYPES, VIDEO_PRODUCER_TYPES } from "./producer-types.js"
15
+ import { ENTITY_NODE_KINDS } from "./entity-node-fields.js"
16
+
17
+ export type LoneMediaUrlKind = "image" | "video"
18
+
19
+ const IMAGE_FILE_RE = /\.(png|jpe?g|gif|webp)$/i
20
+ const VIDEO_FILE_RE = /\.(mp4|mov|webm|m4v)$/i
21
+
22
+ /** Which medium a text value is when its WHOLE value is one media link; `null`
23
+ * for anything else (empty, several words, a comma-joined pair of links, a
24
+ * page link, a file ending in the host or the query, an unsupported format). */
25
+ export function loneMediaUrlKind(value: string): LoneMediaUrlKind | null {
26
+ const s = value.trim()
27
+ if (s.length === 0 || /[\s,]/.test(s) || !/^https?:\/\//i.test(s)) return null
28
+ let pathname: string
29
+ try {
30
+ pathname = new URL(s).pathname
31
+ } catch {
32
+ return null
33
+ }
34
+ if (IMAGE_FILE_RE.test(pathname)) return "image"
35
+ if (VIDEO_FILE_RE.test(pathname)) return "video"
36
+ return null
37
+ }
38
+
39
+ /** A trigger whose ONE wire carries a message's text AND its medium (the
40
+ * caption and the photo of an incoming Telegram message): both engines route
41
+ * the two together from the message itself, so the wire's single value is
42
+ * never read as "one media link". */
43
+ const MESSAGE_TRIGGER_TYPES: ReadonlySet<string> = new Set(["telegram-trigger", "telegram-account-trigger"])
44
+
45
+ /** A source whose wire a social post reads as TEXT: not a declared image, video
46
+ * or audio producer, not a dynamic (multi-typed) one such as List — whose typed
47
+ * columns route by column type — not a message trigger, and not an entity
48
+ * whose picture is a reference. Derived from the producer sets, so a new text
49
+ * node is covered and a new media node (which must join its producer set to
50
+ * connect at all) is excluded, with nothing to remember. */
51
+ export function isLoneMediaLinkSource(nodeType: string | null | undefined): boolean {
52
+ if (!nodeType) return false
53
+ if (IMAGE_PRODUCER_TYPES.has(nodeType) || VIDEO_PRODUCER_TYPES.has(nodeType) || AUDIO_PRODUCER_TYPES.has(nodeType)) return false
54
+ if (DYNAMIC_PRODUCER_TYPES.has(nodeType) || MESSAGE_TRIGGER_TYPES.has(nodeType)) return false
55
+ if ((ENTITY_NODE_KINDS as readonly string[]).includes(nodeType) || nodeType === "face") return false
56
+ return true
57
+ }