@gullabs/xai 0.7.0 → 0.8.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/dist/index.d.ts CHANGED
@@ -106,7 +106,12 @@ interface XaiFunctionCallOutputInputItem {
106
106
  call_id: string;
107
107
  output: string;
108
108
  }
109
- type XaiRequestInputItem = XaiInputItem | XaiFunctionCallInputItem | XaiFunctionCallOutputInputItem;
109
+ type XaiRequestInputItem = XaiInputItem | XaiFunctionCallInputItem | XaiFunctionCallOutputInputItem | XaiOutputItem;
110
+ /** Full wire history for stateless continuation. */
111
+ interface XaiReplayState {
112
+ model: string;
113
+ input: XaiRequestInputItem[];
114
+ }
110
115
  /**
111
116
  * Structured-output text-format request shape.
112
117
  * Real xAI field: `text.format`, NOT `response_format`.
@@ -507,6 +512,7 @@ declare const Grok45ConfigSchema: z.ZodObject<{
507
512
  high: "high";
508
513
  }>;
509
514
  }, z.core.$strict>>;
515
+ serviceTier: z.ZodOptional<z.ZodLiteral<"priority">>;
510
516
  timeoutMs: z.ZodOptional<z.ZodNumber>;
511
517
  providerOptions: z.ZodOptional<z.ZodObject<{
512
518
  xai: z.ZodOptional<z.ZodObject<{
@@ -756,10 +762,148 @@ declare const Grok46ConfigSchema: z.ZodObject<{
756
762
  }, z.core.$strict>>;
757
763
  }, z.core.$strict>;
758
764
 
765
+ /**
766
+ * Strict Zod config schema for xAI's `grok-4.7` model.
767
+ *
768
+ * Same Responses-API surface as grok-4.6: `reasoning.effort` of
769
+ * `'low' | 'medium' | 'high' | 'xhigh'` and `serviceTier: 'priority'`.
770
+ * Shaped from the grok-4.6 contract. The 2026-09-25 priority success and
771
+ * effort-none rejection and P-X3 encrypted-reasoning multi-turn replay are
772
+ * fixture-backed. `'none'` stays rejected.
773
+ * Unknown tiers (`flex`, `standard`, `batch`) are rejected.
774
+ *
775
+ * @module
776
+ */
777
+
778
+ declare const Grok47ConfigSchema: z.ZodObject<{
779
+ temperature: z.ZodOptional<z.ZodNumber>;
780
+ topP: z.ZodOptional<z.ZodNumber>;
781
+ maxOutputTokens: z.ZodOptional<z.ZodNumber>;
782
+ reasoning: z.ZodOptional<z.ZodObject<{
783
+ effort: z.ZodEnum<{
784
+ low: "low";
785
+ medium: "medium";
786
+ high: "high";
787
+ xhigh: "xhigh";
788
+ }>;
789
+ }, z.core.$strict>>;
790
+ serviceTier: z.ZodOptional<z.ZodLiteral<"priority">>;
791
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
792
+ providerOptions: z.ZodOptional<z.ZodObject<{
793
+ xai: z.ZodOptional<z.ZodObject<{
794
+ promptCacheKey: z.ZodOptional<z.ZodString>;
795
+ tools: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodUnion<readonly [z.ZodObject<{
796
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
797
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
798
+ type: z.ZodLiteral<"web_search">;
799
+ allowedDomains: z.ZodArray<z.ZodString>;
800
+ }, z.core.$strict>, z.ZodObject<{
801
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
802
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
803
+ type: z.ZodLiteral<"web_search">;
804
+ excludedDomains: z.ZodArray<z.ZodString>;
805
+ }, z.core.$strict>, z.ZodObject<{
806
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
807
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
808
+ type: z.ZodLiteral<"web_search">;
809
+ }, z.core.$strict>]>], null>, z.ZodTuple<[z.ZodUnion<readonly [z.ZodObject<{
810
+ fromDate: z.ZodOptional<z.ZodISODate>;
811
+ toDate: z.ZodOptional<z.ZodISODate>;
812
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
813
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
814
+ type: z.ZodLiteral<"x_search">;
815
+ allowedXHandles: z.ZodArray<z.ZodString>;
816
+ }, z.core.$strict>, z.ZodObject<{
817
+ fromDate: z.ZodOptional<z.ZodISODate>;
818
+ toDate: z.ZodOptional<z.ZodISODate>;
819
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
820
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
821
+ type: z.ZodLiteral<"x_search">;
822
+ excludedXHandles: z.ZodArray<z.ZodString>;
823
+ }, z.core.$strict>, z.ZodObject<{
824
+ fromDate: z.ZodOptional<z.ZodISODate>;
825
+ toDate: z.ZodOptional<z.ZodISODate>;
826
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
827
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
828
+ type: z.ZodLiteral<"x_search">;
829
+ }, z.core.$strict>]>], null>, z.ZodTuple<[z.ZodUnion<readonly [z.ZodObject<{
830
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
831
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
832
+ type: z.ZodLiteral<"web_search">;
833
+ allowedDomains: z.ZodArray<z.ZodString>;
834
+ }, z.core.$strict>, z.ZodObject<{
835
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
836
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
837
+ type: z.ZodLiteral<"web_search">;
838
+ excludedDomains: z.ZodArray<z.ZodString>;
839
+ }, z.core.$strict>, z.ZodObject<{
840
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
841
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
842
+ type: z.ZodLiteral<"web_search">;
843
+ }, z.core.$strict>]>, z.ZodUnion<readonly [z.ZodObject<{
844
+ fromDate: z.ZodOptional<z.ZodISODate>;
845
+ toDate: z.ZodOptional<z.ZodISODate>;
846
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
847
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
848
+ type: z.ZodLiteral<"x_search">;
849
+ allowedXHandles: z.ZodArray<z.ZodString>;
850
+ }, z.core.$strict>, z.ZodObject<{
851
+ fromDate: z.ZodOptional<z.ZodISODate>;
852
+ toDate: z.ZodOptional<z.ZodISODate>;
853
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
854
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
855
+ type: z.ZodLiteral<"x_search">;
856
+ excludedXHandles: z.ZodArray<z.ZodString>;
857
+ }, z.core.$strict>, z.ZodObject<{
858
+ fromDate: z.ZodOptional<z.ZodISODate>;
859
+ toDate: z.ZodOptional<z.ZodISODate>;
860
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
861
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
862
+ type: z.ZodLiteral<"x_search">;
863
+ }, z.core.$strict>]>], null>, z.ZodTuple<[z.ZodUnion<readonly [z.ZodObject<{
864
+ fromDate: z.ZodOptional<z.ZodISODate>;
865
+ toDate: z.ZodOptional<z.ZodISODate>;
866
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
867
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
868
+ type: z.ZodLiteral<"x_search">;
869
+ allowedXHandles: z.ZodArray<z.ZodString>;
870
+ }, z.core.$strict>, z.ZodObject<{
871
+ fromDate: z.ZodOptional<z.ZodISODate>;
872
+ toDate: z.ZodOptional<z.ZodISODate>;
873
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
874
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
875
+ type: z.ZodLiteral<"x_search">;
876
+ excludedXHandles: z.ZodArray<z.ZodString>;
877
+ }, z.core.$strict>, z.ZodObject<{
878
+ fromDate: z.ZodOptional<z.ZodISODate>;
879
+ toDate: z.ZodOptional<z.ZodISODate>;
880
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
881
+ enableVideoUnderstanding: z.ZodOptional<z.ZodBoolean>;
882
+ type: z.ZodLiteral<"x_search">;
883
+ }, z.core.$strict>]>, z.ZodUnion<readonly [z.ZodObject<{
884
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
885
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
886
+ type: z.ZodLiteral<"web_search">;
887
+ allowedDomains: z.ZodArray<z.ZodString>;
888
+ }, z.core.$strict>, z.ZodObject<{
889
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
890
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
891
+ type: z.ZodLiteral<"web_search">;
892
+ excludedDomains: z.ZodArray<z.ZodString>;
893
+ }, z.core.$strict>, z.ZodObject<{
894
+ enableImageUnderstanding: z.ZodOptional<z.ZodBoolean>;
895
+ enableImageSearch: z.ZodOptional<z.ZodBoolean>;
896
+ type: z.ZodLiteral<"web_search">;
897
+ }, z.core.$strict>]>], null>]>>;
898
+ parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
899
+ }, z.core.$strict>>;
900
+ }, z.core.$strict>>;
901
+ }, z.core.$strict>;
902
+
759
903
  /**
760
904
  * Model descriptor + registry for @gullabs/xai.
761
905
  *
762
- * Ships two canonical models: `grok-4.5` and `grok-4.6`. xAI aliases
906
+ * Ships `grok-4.5`, `grok-4.6`, and `grok-4.7`. xAI aliases
763
907
  * (`grok-4.5-latest`, `grok-build-latest`) visible in `/v1/models` are
764
908
  * intentionally NOT registered (reject-don't-map). `grok-4.6` has no
765
909
  * aliases as of the 2026-08-12 `/v1/models` listing.
@@ -769,6 +913,7 @@ declare const Grok46ConfigSchema: z.ZodObject<{
769
913
 
770
914
  declare const grok45ModelDescriptor: ModelDescriptor;
771
915
  declare const grok46ModelDescriptor: ModelDescriptor;
916
+ declare const grok47ModelDescriptor: ModelDescriptor;
772
917
  /** Every model descriptor `@gullabs/xai` contributes. */
773
918
  declare const xaiModelDescriptors: ModelDescriptor[];
774
919
  declare const xaiRegistry: ModelRegistry;
@@ -780,30 +925,35 @@ declare const xaiRegistry: ModelRegistry;
780
925
  * `@gullabs/core`'s `ModelRates` convention exactly: `cost_µUSD = N *
781
926
  * ratePerM / 1_000_000`.
782
927
  *
783
- * This is a SELF-CONTAINED, xai-owned reimplementation — it does NOT import
784
- * core's Gemini-specific `computeCost`/`GEMINI_PRICING`/`geminiPricingSource`
785
- * (those are Gemini-only). `PricingSource` is provider-scoped by contract
786
- * (see `packages/core/src/ports.ts`); this module is xai's own.
928
+ * Token arithmetic goes through core's `computeCost`. The xAI lookup resolves
929
+ * the concrete per-tier rates (including the `priority` multiplier) before
930
+ * that call, so core never sees an xAI tier name. Tool lanes stay here:
931
+ * `computeCost` prices tokens only. `PricingSource` is provider-scoped by
932
+ * contract (see `packages/core/src/ports.ts`).
787
933
  *
788
- * **Long-context tier.** grok-4.5 / grok-4.6 charge a premium when the GROSS
789
- * input token count exceeds 200,000 (`long_context_threshold` in xAI's
790
- * `/v1/models` listing). Selected by `inputTokens` (incl. cached), not by
791
- * billable input — mirrors core's `selectRates` convention exactly (strictly
792
- * greater than 200,000).
934
+ * **Long-context tier.** grok-4.5 / grok-4.6 / grok-4.7 charge a premium when the GROSS
935
+ * input token count is at or above 200,000. xAI's current pricing page
936
+ * (https://docs.x.ai/developers/pricing) explicitly labels the band
937
+ * "Long context ≥ 200k tokens"; the live listing returns 200000. Selected by
938
+ * `inputTokens` (incl. cached), not by billable input. Core's selector is
939
+ * strictly greater than 200,000; this module owns the `>=` predicate.
793
940
  *
794
- * **Service tiers.** grok-4.5 has none. grok-4.6 admits `'priority'`
795
- * (echo live-verified 2026-08-12). The 2× multiplier is confirmed by
796
- * fixture `12-grok-4-6-xhigh-priority.json` (`cost_in_usd_ticks` equals
797
- * exactly 2× standard list). `'default'` (the value xAI echoes when no
798
- * priority is served) and `undefined` (no tier requested) price at the
799
- * standard list. Any other defined tier is unpriced (reject-don't-map).
941
+ * **Service tiers.** grok-4.5, grok-4.6, and grok-4.7 admit `'priority'` at 2×
942
+ * on every token type, cached included. The 4.5 tier was live-verified
943
+ * 2026-09-25; the 4.6 tier is pinned by fixture 12. `'fast'` is an alias and
944
+ * is not admitted. `'default'` (the value
945
+ * xAI echoes when no priority is served) and `undefined` (no tier requested)
946
+ * price at the standard list. Any other defined tier is unpriced
947
+ * (reject-don't-map).
800
948
  *
801
949
  * **Conversion factor.** xAI's `/v1/models` raw `*_token_price` fields are
802
- * in hundred-thousandths of a dollar per token (i.e. divide the raw integer
803
- * by 10,000 to get USD per million tokens): e.g. `grok-4.6`'s raw
804
- * `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M.
950
+ * in hundred-thousandths of a dollar per token — cents per 100M tokens
951
+ * (divide the raw integer by 10,000 to get USD per million tokens): e.g.
952
+ * `grok-4.6`'s raw `prompt_text_token_price: 20000` ÷ 10,000 = $2.00/M.
805
953
  *
806
- * Verified against `/v1/models` on 2026-08-12. Prior snapshot
954
+ * Grok 4.5/4.6 rates were verified against `/v1/models` on 2026-08-12.
955
+ * Grok 4.7 rates are published in xAI's 2026-09-21 release notes:
956
+ * https://docs.x.ai/developers/release-notes. Prior snapshot
807
957
  * `xai-2026-07-09` priced grok-4.5 cached input at $0.50 / $1.00; the live
808
958
  * listing now reports $0.30 / $0.60.
809
959
  *
@@ -811,20 +961,27 @@ declare const xaiRegistry: ModelRegistry;
811
961
  */
812
962
 
813
963
  /** Identifies this pricing snapshot — bump the date when rates change. */
814
- declare const xaiPricingVersion: "xai-2026-08-24";
964
+ declare const xaiPricingVersion: "xai-2026-09-25";
815
965
  /**
816
- * Live-pinned 2026-08-24 per-invocation tool rates (µUSD per call).
817
- * Source: `usage.server_side_tool_usage_details` on /v1/responses.
818
- * $5 / 1,000 web or X searches. Attachment search is not priced until live-pinned.
966
+ * Tool rates in µUSD per unit.
967
+ *
968
+ * - `web_search_calls`: $5 / 1,000 calls (per invocation).
969
+ * - `x_posts_fetched`: $5 / 1,000 posts (per item, since 2026-09-21).
970
+ * - `x_users_fetched`: $10 / 1,000 profiles (per item, since 2026-09-21).
971
+ *
972
+ * The per-call `x_search_calls` rate is gone. Attachment search stays
973
+ * unpriced until a live probe pins the counter name (P-X2); a file-ref call
974
+ * is estimated, not billed at an invented counter.
819
975
  */
820
976
  declare const XAI_TOOL_RATE_MICRO_USD: {
821
977
  readonly web_search_calls: 5000;
822
- readonly x_search_calls: 5000;
978
+ readonly x_posts_fetched: 5000;
979
+ readonly x_users_fetched: 10000;
823
980
  };
824
981
  /**
825
982
  * Per-model rate entry (all values in µUSD per million tokens).
826
983
  *
827
- * `gt200k` (when present) applies when GROSS input tokens > 200,000.
984
+ * `gt200k` (when present) applies when GROSS input tokens >= 200,000.
828
985
  */
829
986
  interface XaiModelRates {
830
987
  /** µUSD per million input tokens (billable = gross − cached). */
@@ -833,7 +990,7 @@ interface XaiModelRates {
833
990
  cachedPerM: number;
834
991
  /** µUSD per million output tokens (reasoning tokens are folded in). */
835
992
  outputPerM: number;
836
- /** Optional high-tier rates for long-context (GROSS input > 200k). */
993
+ /** Optional high-tier rates for long-context (GROSS input >= 200_000). */
837
994
  gt200k?: {
838
995
  inputPerM: number;
839
996
  cachedPerM: number;
@@ -862,24 +1019,25 @@ declare const XAI_PRICING: Readonly<Record<string, XaiModelRates>>;
862
1019
  *
863
1020
  * Pure function — no side effects, always returns a well-formed {@link Cost}.
864
1021
  *
865
- * **Algorithm** (mirrors `@gullabs/core`'s `computeCost` exactly, xai-owned):
866
- * 1. Look up rates for `model`; if not found, return an unpriced `Cost`
867
- * (`microUsd: null`) naming the model.
868
- * 2. `undefined` or `'default'` prices at the standard list.
869
- * `'priority'` applies `rates.priorityFactor` when present.
870
- * Any other defined tier, or `'priority'` on a model without
871
- * `priorityFactor`, is unpriced (reject-don't-map).
872
- * 3. Select base vs. `>200k` long-context rates from GROSS `inputTokens`.
1022
+ * **Algorithm:**
1023
+ * 1. `lookupConcreteRates` resolves the model and tier. `undefined` or
1024
+ * `'default'` is the standard list. `'priority'` returns rates scaled by
1025
+ * `priorityFactor` when the model admits it. An unknown model, any other
1026
+ * defined tier, or `'priority'` on a model without `priorityFactor` is
1027
+ * unpriced (reject-don't-map) — `computeCost` returns `microUsd: null`.
1028
+ * 2. `selectXaiRates` applies long-context rates when GROSS input is
1029
+ * `>= 200_000` (xAI's inclusive threshold; core's selector stays `>`).
873
1030
  * 4. Billable input = `inputTokens − (cachedInputTokens ?? 0)`, clamped to 0.
874
1031
  * 5. Round each component (input, cached, output) independently to the
875
1032
  * nearest integer micro-USD.
876
1033
  * 6. `microUsd` is the sum of the four components — guarantees
877
1034
  * `details.input + details.cached + details.output + details.tools === microUsd`.
878
- * 7. Tool lanes: live-pinned counters `web_search_calls`, `x_search_calls`.
879
- * Missing expected counters → `tools: 0`, `estimated`. File-ref sets
880
- * `attachment_search_unpinned` → `estimated` (attachment not priced).
881
- * `'exact'` requires no unpinned attachment and counters present or no
882
- * server tools requested.
1035
+ * 7. Tool lanes: `web_search_calls` per call; x_search is
1036
+ * `x_posts_fetched` × $5/1k + `x_users_fetched` × $10/1k. A missing
1037
+ * item counter leaves the call unpriced; the provider's billed ticks remain
1038
+ * in `usage.details` for reconciliation outside this rate snapshot.
1039
+ * File-ref still sets `attachment_search_unpinned` and the call is
1040
+ * estimated — the counter name is not pinned (P-X2).
883
1041
  */
884
1042
  declare function computeXaiCost(model: string, usage: Usage, tier?: string): Cost;
885
1043
  /**
@@ -925,4 +1083,4 @@ declare function xaiPricingSource(): PricingSource;
925
1083
  */
926
1084
  declare function xaiProvider(opts?: XaiAdapterOptions): ProviderPlugin;
927
1085
 
928
- export { type FileDeleteOptions, Grok45ConfigSchema, Grok46ConfigSchema, XAI_FILES_DEFAULT_BASE_URL, XAI_FILE_MAX_BYTES, XAI_FILE_TTL_MAX_SECONDS, XAI_FILE_TTL_MIN_SECONDS, XAI_PRICING, XAI_TOOL_RATE_MICRO_USD, type XaiAdapterOptions, type XaiClientLike, type XaiFileHandle, type XaiFileListOptions, type XaiFileListResult, XaiFileStore, type XaiFileStoreOptions, type XaiFileUploadInput, type XaiInputContentPart, type XaiInputFilePart, type XaiInputImagePart, type XaiInputItem, type XaiInputTextPart, type XaiMessageOutputItem, type XaiModelRates, type XaiOutputItem, type XaiOutputTextPart, type XaiProviderOptions, type XaiReasoningOutputItem, type XaiReasoningSummaryPart, type XaiResponseCreateParams, type XaiResponseShape, type XaiTextFormat, type XaiUsageShape, type XaiWebSearchTool, type XaiXSearchTool, buildXaiClient, classifyXaiError, computeXaiCost, grok45ModelDescriptor, grok46ModelDescriptor, requireApiKey, xaiAdapter, xaiModelDescriptors, xaiPricingSource, xaiPricingVersion, xaiProvider, xaiRegistry };
1086
+ export { type FileDeleteOptions, Grok45ConfigSchema, Grok46ConfigSchema, Grok47ConfigSchema, XAI_FILES_DEFAULT_BASE_URL, XAI_FILE_MAX_BYTES, XAI_FILE_TTL_MAX_SECONDS, XAI_FILE_TTL_MIN_SECONDS, XAI_PRICING, XAI_TOOL_RATE_MICRO_USD, type XaiAdapterOptions, type XaiClientLike, type XaiFileHandle, type XaiFileListOptions, type XaiFileListResult, XaiFileStore, type XaiFileStoreOptions, type XaiFileUploadInput, type XaiInputContentPart, type XaiInputFilePart, type XaiInputImagePart, type XaiInputItem, type XaiInputTextPart, type XaiMessageOutputItem, type XaiModelRates, type XaiOutputItem, type XaiOutputTextPart, type XaiProviderOptions, type XaiReasoningOutputItem, type XaiReasoningSummaryPart, type XaiReplayState, type XaiRequestInputItem, type XaiResponseCreateParams, type XaiResponseShape, type XaiTextFormat, type XaiUsageShape, type XaiWebSearchTool, type XaiXSearchTool, buildXaiClient, classifyXaiError, computeXaiCost, grok45ModelDescriptor, grok46ModelDescriptor, grok47ModelDescriptor, requireApiKey, xaiAdapter, xaiModelDescriptors, xaiPricingSource, xaiPricingVersion, xaiProvider, xaiRegistry };