@40rty/ams-sdk 0.5.27 → 0.5.29

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 (35) hide show
  1. package/dist/index.js +1632 -1108
  2. package/dist/types/ecommerce/src/catalog-product-lookup.d.ts +24 -0
  3. package/dist/types/ecommerce/src/catalog-search.d.ts +7 -0
  4. package/dist/types/ecommerce/src/commerce-schemas.d.ts +22 -12
  5. package/dist/types/ecommerce/src/index.d.ts +2 -1
  6. package/dist/types/ecommerce/src/seller-profile.d.ts +19 -11
  7. package/dist/types/sdk/src/canvas/generation-style.d.ts +20 -1
  8. package/dist/types/sdk/src/canvas/index.d.ts +3 -3
  9. package/dist/types/sdk/src/canvas/runtime-hooks.d.ts +5 -1
  10. package/dist/types/sdk/src/canvas/runtime-types.d.ts +22 -1
  11. package/dist/types/sdk/src/host/host-modules.d.ts +46 -13
  12. package/dist/types/sdk/src/provider/index.d.ts +1 -0
  13. package/dist/types/sdk/src/provider/providers/page-claims.d.ts +50 -0
  14. package/dist/types/sdk/src/session/FourtySessionContext.d.ts +8 -0
  15. package/dist/types/sdk/src/session/conversation-key.d.ts +8 -0
  16. package/dist/types/sdk/src/session/index.d.ts +1 -0
  17. package/dist/types/sdk/src/shell/conversation/use-conversation-page.d.ts +9 -1
  18. package/dist/types/sdk/src/verticals/commerce/index.d.ts +2 -0
  19. package/dist/types/sdk/src/verticals/commerce/price/percent-off.d.ts +11 -0
  20. package/dist/types/sdk/src/verticals/commerce/product/product-detail-add.d.ts +52 -0
  21. package/dist/types/sdk/src/verticals/commerce/product/use-product-detail.d.ts +2 -1
  22. package/dist/types/sdk/src/verticals/commerce/variant/variant-selection.d.ts +22 -1
  23. package/dist/types/spacestation/src/analytics/index.d.ts +1 -0
  24. package/dist/types/spacestation/src/analytics/visitor.d.ts +4 -0
  25. package/dist/types/spacestation/src/contracts/tools/execution-context.d.ts +11 -0
  26. package/dist/types/spacestation/src/index.d.ts +5 -1
  27. package/dist/types/spacestation/src/layout/conversation.d.ts +22 -0
  28. package/dist/types/spacestation/src/signal/turn-ask.d.ts +6 -1
  29. package/dist/types/spacestation/src/space/space-config.d.ts +13 -0
  30. package/dist/types/spacestation/src/space/space-description.d.ts +27 -0
  31. package/dist/types/spacestation/src/space/space-share.d.ts +37 -0
  32. package/dist/types/spacestation/src/trace/trace-events.d.ts +19 -0
  33. package/dist/types/spacestation/src/types.d.ts +4 -0
  34. package/dist/types/spacestation/src/visitor/visitor-country.d.ts +63 -0
  35. package/package.json +1 -1
@@ -27,7 +27,8 @@ export interface ProductDetailOptions {
27
27
  * - findVariant(opts) → ProductVariant | undefined
28
28
  * - isVariantUnavailable(group, opt)
29
29
  * - descExpanded / toggleDesc
30
- * - onAddToBag (dispatches cart.add only when allSelected; carries variantId)
30
+ * - onAddToBag / onBuyNow (dispatch cart.add only when the selection resolves
31
+ * to a variant; `productDetailAddResult` says beforehand whether it will)
31
32
  * - onAskAgent (sends a chat message asking about this product)
32
33
  * - onPickSibling (navigates to a colour-sibling product)
33
34
  * - onSale predicate
@@ -12,11 +12,32 @@ export declare function deriveVariantGroups(product: Product): Array<{
12
12
  name: string;
13
13
  options: string[];
14
14
  }>;
15
- /** The variant whose selected-options exactly satisfy `opts`, if any. */
15
+ /**
16
+ * The variant the selection `opts` picks, if any — the first in product order.
17
+ *
18
+ * A variant that lists option values (`selectedOptions` non-empty) matches when
19
+ * `opts` holds every one of them.
20
+ *
21
+ * A variant that lists none (`selectedOptions` absent or `[]` — the two mean
22
+ * the same: it is defined by no option value) is placed on no axis, so:
23
+ * - on a product WITHOUT option groups it matches whatever `opts` holds —
24
+ * there is nothing to pick and nothing it could contradict. This is the
25
+ * single-variant product: the Shopify catalog connector (UCP) leaves
26
+ * `selectedOptions` absent on a variant with no options, the Storefront
27
+ * connector strips Shopify's `Title: Default Title` placeholder to `[]`.
28
+ * With several such variants (Storefront: a product whose only axis is an
29
+ * internal one like `Color Code`, stripped at the provider) the first wins —
30
+ * the visitor has no picker to choose another, and it is the lead variant
31
+ * whose price the product shows.
32
+ * - on a product WITH option groups it never matches: a variant that names no
33
+ * value cannot be the one the visitor picked "M" for.
34
+ */
16
35
  export declare function matchVariant(product: Product, opts: Record<string, string>): ProductVariant | undefined;
17
36
  /**
18
37
  * A `(group, opt)` pair is unavailable when EVERY product variant that
19
38
  * includes it is sold out. Picks in OTHER groups narrow the pool first,
20
39
  * falling back to the full candidate set when the narrowing empties it.
40
+ * A variant that lists no option values includes no `(group, opt)` pair, so it
41
+ * is never a candidate — the same reading `matchVariant` gives it.
21
42
  */
22
43
  export declare function isOptionUnavailable(product: Product, selectedVariants: Record<string, string>, group: string, opt: string): boolean;
@@ -22,6 +22,7 @@
22
22
  export { defineEventKind } from './kind';
23
23
  export type { AnyEventKind, ClientEventKind, EventKind, EventTrust, Identical, NameOf, PayloadGuard, PayloadOf, } from './kind';
24
24
  export { ENGAGEMENT_DWELL_MS, SESSION_ENGAGED } from './session';
25
+ export { VISITOR_COUNTRY_CHOSEN } from './visitor';
25
26
  export { catalogEmittableSchema, catalogEventSchema, eventCatalog } from './catalog';
26
27
  export type { CatalogEmittable, CatalogEvent, EmittableOf, EventCatalog, EventOf, } from './catalog';
27
28
  export { ANALYTICS_CONSENTS, ANALYTICS_MAX_QUEUED, ANALYTICS_SURFACES, AnalyticsBatchSchema, AnalyticsConsentSchema, AnalyticsDropCountsSchema, AnalyticsSurfaceSchema, AnalyticsWireEventSchema, } from './envelope';
@@ -0,0 +1,4 @@
1
+ export declare const VISITOR_COUNTRY_CHOSEN: import("./kind").EventKind<"visitor.country_chosen", {
2
+ chosen: string;
3
+ observed: string | null;
4
+ }, "client">;
@@ -1,5 +1,6 @@
1
1
  import type { EmitFn } from '../../trace/trace-events';
2
2
  import type { VisitorLocation, EntityKind } from '../../types';
3
+ import type { VisitorCountry } from '../../visitor/visitor-country';
3
4
  /**
4
5
  * Runtime context passed to tool execute() functions.
5
6
  *
@@ -109,6 +110,16 @@ export interface ToolExecutionContext {
109
110
  * policy). Absent when the route had no IP or geoip returned no
110
111
  * match — tools must guard before using. */
111
112
  visitorLocation?: VisitorLocation;
113
+ /**
114
+ * The visitor's country IN EFFECT right now — chosen, else observed
115
+ * (`visitorCountryInEffect`) — read fresh per call, so a choice made mid-
116
+ * session reaches the very next tool call. Present only when the space
117
+ * follows the visitor's country (`spaces.config.followVisitorCountry`) AND a
118
+ * country is known; absent otherwise, and a tool then answers exactly as it
119
+ * did before the field existed. What a tool does with it is the tool's own
120
+ * business (a commerce connector searches what ships there).
121
+ */
122
+ visitorCountry?: VisitorCountry;
112
123
  /** Known entity refs the session has seen, EACH WITH ITS KIND — gids
113
124
  * returned by prior tool calls, gids in the active layout, gids in the
114
125
  * entity index. Tools that take entity-id input (any
@@ -10,7 +10,7 @@ export { PRODUCT_SELECT_OPTION_SIGNAL, SELECTION_ORIGIN_VISITOR, VARIANT_SELECTE
10
10
  export { CART_ADD_SIGNAL, CART_ADD_MALFORMED_REASON, CartAddSignalPayloadSchema, CartLineAttributeSchema, withCartActorOrigin, type CartAddSignalPayload, type CartLineAttribute, } from './commerce/cart-add-signal';
11
11
  export { CART_REMOVE_SIGNAL, CART_SET_QUANTITY_SIGNAL, CHECKOUT_BEGIN_SIGNAL, CART_REMOVE_MALFORMED_REASON, CartRemoveSignalPayloadSchema, type CartRemoveSignalPayload, } from './commerce/cart-verb-signals';
12
12
  export { type ChatMessage, type ConversationSummary, type StreamRecord, type ReasoningBeat, type Message, type PendingMessage, } from './layout/conversation';
13
- export { type StepName, type TraceEvent, type EmitFn, type TraceStartInfo, type StepConfig, type SystemPromptSnapshot, type VisitorIdentity, type PhaseProgress, type PhaseProgressPreview, } from './trace/trace-events';
13
+ export { type StepName, type TraceEvent, type EmitFn, type TraceStartInfo, type StepConfig, type SystemPromptSnapshot, type VisitorIdentity, type PhaseProgress, type PhaseProgressPreview, type TurnErrorReason, type TurnFailure, } from './trace/trace-events';
14
14
  export { type TraceDiagnostic, type DiagnosticKind, type TraceStage, } from './trace/trace-diagnostics';
15
15
  export { type SuggestionAction, type SuggestionActions, type SuggestionRendererProps, SuggestionActionSchema, SuggestionActionsSchema, SIGNAL_PATCH_PREFIX, type SuggestionActionInput, type AgentSignal, type AgentSignalInput, AgentSignalSchema, InteractionSignalSchema, MAX_VISITOR_PROMPT_CHARS, type ToolCallHint, ToolCallHintSchema, type ActionDefinition, type ActionConfirmation, type ActionGuardEntities, type ActionPrepareContext, type ActionNamedEntity, type ActionPrepared, type ActionManifest, type AskDefinition, type AskManifest, NAVIGATE_SIGNAL, FLOW_OUTPUT_SIGNAL, PRESENCE_FLOW, PRESENCE_OPTIMISTIC_FACTS_FLOW, EXTEND_FLOW, DIRECTION_FLOW, COMPANION_FLOW, GREETING_FLOW, FEED_SECTION_FLOW, FEED_QUESTION_FLOW, EPHEMERAL_FACT_FLOWS, type FlowSpec, type FacultyFlowSpec, } from './signal/agent-signals';
16
16
  export { CHIP_SHOW_SIGNAL, chipsFromShowSignal } from './signal/chip-show';
@@ -58,6 +58,8 @@ export type { AgentDirective, SpaceAgentDirective, SpaceAgentDirectiveListItem,
58
58
  export { BotCheckNoticeSchema, type BotCheckNotice } from './shell/bot-check-notice';
59
59
  export { DEFAULT_SPACE_LOCALE, SpaceLocaleSchema, textDirectionOf, languageOf, languageNameOf, spaceLocaleOf, declaredSpaceLocaleOf, SUPPORTED_SPACE_LOCALES, } from './space/space-locale';
60
60
  export type { TextDirection } from './space/space-locale';
61
+ export { SPACE_DESCRIPTION_MAX_CHARS, SpaceDescriptionSchema, spaceDescriptionOf } from './space/space-description';
62
+ export { SPACE_SHARE_QUERY_MAX_CHARS, SpaceShareQuerySchema, X_HANDLE_PATTERN, XHandleSchema, bareXHandle, spaceShareOf, type SpaceShare, } from './space/space-share';
61
63
  export { DEFAULT_SPACE_CONFIG, DEFAULT_VISITOR_ACCESS, VISITOR_ACCESS, visitorAccessOf, } from './space/space-config';
62
64
  export type { ThemePackageOption, BrandDefinition, BrandPromptSection } from './space/workspace-catalog';
63
65
  export { COMPONENT_SOURCE, THEME_PACKAGE, THEME_CLASS, COMPONENT_SOURCE_DEFAULT_THEME, WORKSPACE_THEME_PACKAGES, } from './space/workspace-catalog';
@@ -85,3 +87,5 @@ export { tokenize, splitSentences, createTokenOverlapScorer, compressString, com
85
87
  export type { Scorer, ScorerFactoryContext, CompressStringOpts, CompressStringResult, CompressArrayOpts, CompressArrayResult, } from './tool-compression';
86
88
  export { BOARD_NAMESPACE, BOARD_MAX_FACTS, BOARD_MAX_ITEMS, BOARD_TITLE_MAX, BOARD_NAME_MAX, BoardFactSchema, BoardItemSchema, BoardMemberSchema, BoardProjectionSchema, BoardStateSchema, BoardEditSchema, BoardShareSchema, boardLabelKey, previewBoardEdit, } from './board/board';
87
89
  export type { BoardCall, BoardFact, BoardItem, BoardMember, BoardProjection, BoardState, BoardEdit, BoardShare } from './board/board';
90
+ export { CountryCodeSchema, isCountryCode, visitorCountryInEffect, NO_VISITOR_COUNTRY, VISITOR_COUNTRY_CHOICE_NAMESPACE, VISITOR_COUNTRY_OBSERVED_NAMESPACE, VisitorCountryStateSchema, } from './visitor/visitor-country';
91
+ export type { VisitorCountry, VisitorCountrySource, VisitorCountryState } from './visitor/visitor-country';
@@ -2,6 +2,7 @@ import type { AgentSignal } from '../signal/agent-signals';
2
2
  import type { TurnAsk } from '../signal/turn-ask';
3
3
  import type { View } from './page';
4
4
  import type { AttachmentRef } from '../attachment/attachment';
5
+ import type { TurnFailure } from '../trace/trace-events';
5
6
  /**
6
7
  * Conversation-log + agent-stream data shapes.
7
8
  *
@@ -120,6 +121,13 @@ export interface Message {
120
121
  * keeps the row honest afterwards, once the banner has cleared.
121
122
  */
122
123
  error?: string;
124
+ /**
125
+ * What a client can act on about the failure — present only on a turn that
126
+ * failed with an `error` event (not on `'no_response'`), and only when the
127
+ * server said (an older server sends nothing). `retryAfterMs` counts from
128
+ * `committedAt`: e.g. "try again in N minutes" for `reason: 'over_budget'`.
129
+ */
130
+ failure?: TurnFailure;
123
131
  }
124
132
  /** The in-flight turn the `Conversation` runtime is streaming into. */
125
133
  export interface PendingMessage {
@@ -138,4 +146,18 @@ export interface PendingMessage {
138
146
  * Wire shape: `reasoning_update` TraceEvent → routed here.
139
147
  */
140
148
  reasoning: ReasoningBeat[];
149
+ /**
150
+ * The turn's LAYOUT is final: every layout patch it sends has been applied to
151
+ * the canvas and no more will come. Set when the turn's `layout_committed`
152
+ * frame lands for the view the visitor is on — before the follow-up chip pass,
153
+ * typically ~0.7–0.9 s before `done` closes the bubble.
154
+ *
155
+ * What it does NOT promise: prose may still be streaming (the reveal is paced,
156
+ * and the question the turn closes on may not be shown yet), the follow-up
157
+ * chips have not arrived, and images in the layout have not loaded. Only ever
158
+ * `true`; absent means "not known final yet" — on a new turn, after a server
159
+ * restart re-runs the turn, and on any turn whose commit frame was fenced
160
+ * because the visitor navigated away.
161
+ */
162
+ layoutFinal?: true;
141
163
  }
@@ -12,7 +12,12 @@ import type { AgentSignal } from './agent-signals';
12
12
  * word. A `choice` carries 2-4 `{answer}` parts, an `open` none; a choice
13
13
  * that came out without them reads as open (`ModelTurnAskSchema`). Each `{answer}` is a reply the visitor
14
14
  * sends with one tap, in place in the sentence — so a shell renders the
15
- * clickable words without matching anything back into text. Read it through
15
+ * clickable words without matching anything back into text. A question that
16
+ * cannot hold its answers in the sentence lists them after it:
17
+ *
18
+ * {"kind":"choice","parts":["What kind of trips does she take most? ",{"answer":"Weekend road trips"}," ",{"answer":"Flying carry-on"}]}
19
+ *
20
+ * Read it through
16
21
  * `turnAskSegments` (render), `turnAskAnswers` (the replies) and
17
22
  * `turnAskPlainText` (anything that shows or feeds it as text: the prose fold,
18
23
  * the model's own history).
@@ -65,6 +65,19 @@ export interface SpaceConfig {
65
65
  * chrome, direction and formatting all follow it. Absent ⇒ `en-US`. Public
66
66
  * by design: the page renders in it. See `space-locale.ts`. */
67
67
  locale?: string;
68
+ /** What the space is, in its owner's words — its public summary for search
69
+ * engines and agents (meta description, share card, `/llms.txt`). Absent ⇒
70
+ * the space says nothing beyond its name. Public by design; read through
71
+ * `spaceDescriptionOf` (`space-description.ts`). */
72
+ description?: string;
73
+ /** The site's X account (`twitter:site`), without the `@`. Public by design;
74
+ * read through `spaceShareOf` (`space-share.ts`). */
75
+ twitterSite?: string;
76
+ /** The X account of the site's author (`twitter:creator`), without the `@`. */
77
+ twitterCreator?: string;
78
+ /** The catalog search the site's share image and server-rendered deals are
79
+ * drawn from (`"black friday deals"`). Absent ⇒ a name-and-description card. */
80
+ shareQuery?: string;
68
81
  /** IANA zone the space's reporting DAY is measured on (e.g.
69
82
  * `America/Los_Angeles`), seeded from the connected store at install. Absent ⇒
70
83
  * the platform reports in UTC and labels it as such. A REPORTING concern only:
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * WHAT A SPACE IS, IN ITS OWNER'S WORDS — one or two sentences on
4
+ * `spaces.config.description`.
5
+ *
6
+ * It is the space's public summary: the spacefront's `<meta name="description">`,
7
+ * its Open Graph / Twitter card, its `Organization` structured data, the
8
+ * server-rendered summary a reader sees before the page's script runs, and the
9
+ * opening of its `/llms.txt`. Public by design — it exists to be read by search
10
+ * engines and agents — which is why the public space projection carries it.
11
+ *
12
+ * Absent ⇒ none of those surfaces says anything about the space beyond its
13
+ * name. Nothing is ever derived in its place (the platform's own copy on a
14
+ * customer's site was the bug this field fixed), and nothing is written on the
15
+ * owner's behalf.
16
+ */
17
+ /** A search result shows ~160 characters; an agent's summary a little more. A description is not an essay. */
18
+ export declare const SPACE_DESCRIPTION_MAX_CHARS = 300;
19
+ /** Strict at the write boundary — trimmed, non-empty, bounded. */
20
+ export declare const SpaceDescriptionSchema: z.ZodString;
21
+ /**
22
+ * The space's description, or `null` when it declared none. A stored value the
23
+ * schema refuses (written before the boundary existed, or by hand) reads as
24
+ * none: a public page is no place to repair it, and the write boundary refuses
25
+ * it on the next save.
26
+ */
27
+ export declare function spaceDescriptionOf(config: Readonly<Record<string, unknown>>): string | null;
@@ -0,0 +1,37 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * HOW A SPACE'S SITE IS SHARED — three optional keys on `spaces.config`, all
4
+ * public by design (they exist to be published in a link preview):
5
+ *
6
+ * - `twitterSite` the X account of the site (`twitter:site`),
7
+ * - `twitterCreator` the X account of its author (`twitter:creator`),
8
+ * - `shareQuery` the catalog search the site's share image and its
9
+ * server-rendered deals are drawn from ("black friday
10
+ * deals"). Absent ⇒ the share card is the space's name,
11
+ * mark and description, and the page lists no products.
12
+ *
13
+ * Handles are stored WITHOUT the leading `@` (the settings form strips it) and
14
+ * read the same way whatever was stored, so the head prints `@handle` once.
15
+ * Nothing here is ever derived: a space that declares none says nothing.
16
+ */
17
+ /** An X handle as typed: 1-15 letters, digits or `_`, an optional leading `@`. */
18
+ export declare const X_HANDLE_PATTERN: RegExp;
19
+ /** Strict at the write boundary. */
20
+ export declare const XHandleSchema: z.ZodString;
21
+ /** A share query is a search, not a sentence. */
22
+ export declare const SPACE_SHARE_QUERY_MAX_CHARS = 120;
23
+ export declare const SpaceShareQuerySchema: z.ZodString;
24
+ export interface SpaceShare {
25
+ /** Without the `@`, or `null`. */
26
+ twitterSite: string | null;
27
+ /** Without the `@`, or `null`. */
28
+ twitterCreator: string | null;
29
+ shareQuery: string | null;
30
+ }
31
+ /** The handle with no `@` — the one stored form. */
32
+ export declare function bareXHandle(handle: string): string;
33
+ /**
34
+ * The space's share settings. A stored value the schemas refuse reads as none,
35
+ * like `spaceDescriptionOf`: a public page is no place to repair it.
36
+ */
37
+ export declare function spaceShareOf(config: Readonly<Record<string, unknown>>): SpaceShare;
@@ -440,6 +440,9 @@ export type TraceEvent = {
440
440
  message: string;
441
441
  step?: string;
442
442
  visitorSafe?: true;
443
+ reason?: TurnErrorReason;
444
+ retryAfterMs?: number;
445
+ sessionUnavailable?: true;
443
446
  } | {
444
447
  type: 'diagnostic';
445
448
  diagnostic: TraceDiagnostic;
@@ -449,3 +452,19 @@ export type TraceEvent = {
449
452
  runId: string;
450
453
  };
451
454
  export type EmitFn = (event: TraceEvent) => void;
455
+ /**
456
+ * Why a turn failed, as a client can act on it. A CLOSED set, and deliberately
457
+ * coarse: it says what the visitor can do, never what tripped.
458
+ * - `over_budget` — refused by the space's spend guardrail for now. Comes with
459
+ * `retryAfterMs` (ms from the event until the window reopens): asking again
460
+ * sooner is refused again. Nothing else about the ceiling (which one, its
461
+ * size, what is left) ever reaches the client.
462
+ * - `failed` — anything else. Asking again may work.
463
+ */
464
+ export type TurnErrorReason = 'over_budget' | 'failed';
465
+ /** The failure a FAILED turn carries to the client (`Message.failure`). */
466
+ export interface TurnFailure {
467
+ reason: TurnErrorReason;
468
+ /** From the moment the turn failed (`Message.committedAt`): the window reopens after this many ms. Only with `over_budget`, and only when the server knows it. */
469
+ retryAfterMs?: number;
470
+ }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import type { VisitorCountrySource } from './visitor/visitor-country';
2
3
  /**
3
4
  * Best-effort coarse geolocation for the visitor's session. Resolved
4
5
  * silently from the request IP (no browser permission). All fields are
@@ -12,6 +13,9 @@ import { z } from 'zod';
12
13
  export interface VisitorLocation {
13
14
  /** ISO 3166-1 alpha-2 country code, e.g. "US". */
14
15
  country?: string;
16
+ /** Where `country` came from — the visitor chose it, or it was observed from
17
+ * their connection (`VisitorCountry`). Absent on a bare IP-geo location. */
18
+ countrySource?: VisitorCountrySource;
15
19
  /** Subdivision code, e.g. "NY". Source-dependent format. */
16
20
  region?: string;
17
21
  /** Best human-readable city name, e.g. "Brooklyn". */
@@ -0,0 +1,63 @@
1
+ /**
2
+ * The visitor's COUNTRY — where the visitor is, as far as the space can tell.
3
+ *
4
+ * A platform fact, vertical-neutral: it says nothing about what a space does
5
+ * with it. A commerce connector reads it as "deliver here"; a content space
6
+ * could read it as "regional edition". Those words belong to the connector.
7
+ *
8
+ * Two sources, and the order is the whole contract:
9
+ * 1. CHOSEN — the visitor said so (a header control, an outside agent
10
+ * speaking for them). It always wins: the visitor knows where
11
+ * they want things better than an IP lookup does.
12
+ * 2. OBSERVED — what the server saw of their connection: the edge's geo
13
+ * header, else the browser's time zone (`sessions.visitor_country`).
14
+ * Neither → `null`, which is "unknown", never a default country.
15
+ *
16
+ * It is never an access decision. A chosen country only changes what a
17
+ * space's reads answer for; it cannot open or close anything.
18
+ *
19
+ * ── HOW IT TRAVELS ─────────────────────────────────────────────────────────
20
+ *
21
+ * On the session state-agreement rail (docs/session-state-agreement.md), one
22
+ * namespace each way:
23
+ * - `visitorCountryChoice` (client-leads) — the choice the browser holds,
24
+ * `{ country }` with `null` for "no choice". Re-sent in full on every
25
+ * connection open, so a reload, a new session and a recovered session all
26
+ * carry it without a code path of their own.
27
+ * - `visitorCountryObserved` (server-leads) — what the server observed,
28
+ * `{ country }`. The browser cannot see the edge's header, so the server
29
+ * tells it, and the page can show the guess before the visitor corrects it.
30
+ */
31
+ import { z } from 'zod';
32
+ /** True when `value` is an assigned ISO 3166-1 alpha-2 code (upper case). */
33
+ export declare function isCountryCode(value: unknown): value is string;
34
+ export declare const CountryCodeSchema: z.ZodEffects<z.ZodString, string, string>;
35
+ export type VisitorCountrySource = 'chosen' | 'observed';
36
+ /** The country in effect for a visitor, and where it came from. */
37
+ export interface VisitorCountry {
38
+ /** ISO 3166-1 alpha-2, or `null` when neither source knows. */
39
+ country: string | null;
40
+ /** `null` exactly when `country` is. */
41
+ source: VisitorCountrySource | null;
42
+ }
43
+ export declare const NO_VISITOR_COUNTRY: VisitorCountry;
44
+ /** Chosen first, observed second, else none. The ONE definition of the order —
45
+ * the server's turn, the server's feed search and the browser's hook all call it. */
46
+ export declare function visitorCountryInEffect(facts: {
47
+ chosen: string | null;
48
+ observed: string | null;
49
+ }): VisitorCountry;
50
+ /** Client-leads: the country the visitor chose, `null` when they chose none. */
51
+ export declare const VISITOR_COUNTRY_CHOICE_NAMESPACE = "visitorCountryChoice";
52
+ /** Server-leads: the country the server observed for this session's visitor. */
53
+ export declare const VISITOR_COUNTRY_OBSERVED_NAMESPACE = "visitorCountryObserved";
54
+ /** Payload of both namespaces. A malformed code never parses, so it can never
55
+ * reach a search as a country. */
56
+ export declare const VisitorCountryStateSchema: z.ZodObject<{
57
+ country: z.ZodNullable<z.ZodEffects<z.ZodString, string, string>>;
58
+ }, "strip", z.ZodTypeAny, {
59
+ country: string | null;
60
+ }, {
61
+ country: string | null;
62
+ }>;
63
+ export type VisitorCountryState = z.infer<typeof VisitorCountryStateSchema>;
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "react": "^18.3.0 || ^19.0.0",
27
27
  "react-dom": "^18.3.0 || ^19.0.0"
28
28
  },
29
- "version": "0.5.27",
29
+ "version": "0.5.29",
30
30
  "homepage": "https://docs.40rty.ai",
31
31
  "license": "UNLICENSED",
32
32
  "engines": {