@cosmoops/connect-sdk 0.32.0 → 0.33.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.
@@ -534,6 +534,160 @@ export interface WriteLogResponse {
534
534
  attributed: boolean;
535
535
  }
536
536
  /** One turn of a RAG chat. Matches the AI SDK's `UIMessage` loosely enough to pass one straight through. */
537
+ /** Where a knowledge item's text came from. */
538
+ export type VisitorKnowledgeSource = "website" | "authored" | "upload";
539
+ /**
540
+ * How a published item reaches the model.
541
+ *
542
+ * `inline` is the **normal and better** state for a small knowledge base, not a
543
+ * degraded one: the model is shown every published item rather than a top-k
544
+ * slice, with no chunk boundaries and no retrieval round trip. The other three
545
+ * only occur once a knowledge base has outgrown the prompt.
546
+ */
547
+ export type VisitorKnowledgeIndexState = "inline" | "indexing" | "indexed" | "failed";
548
+ /**
549
+ * One thing a workspace's website chat is allowed to tell strangers.
550
+ *
551
+ * **Not the workspace's Context Index.** That corpus is fed by every Drive
552
+ * upload; this store holds only what somebody explicitly published, which is
553
+ * what makes it safe to answer an anonymous visitor from. Nothing arrives here
554
+ * as a side effect of anything else.
555
+ */
556
+ export interface VisitorKnowledgeItem {
557
+ id: string;
558
+ title: string;
559
+ body: string;
560
+ source: VisitorKnowledgeSource;
561
+ /** The crawled URL, or the uploaded file's name. `null` for authored text. */
562
+ sourceRef: string | null;
563
+ status: "draft" | "published";
564
+ indexState: VisitorKnowledgeIndexState;
565
+ /** Why the last index attempt failed, for your own screen to show. */
566
+ indexError: string | null;
567
+ /** ISO-8601, or `null` for a draft. */
568
+ publishedAt: string | null;
569
+ createdAt: string;
570
+ updatedAt: string;
571
+ }
572
+ /**
573
+ * The knowledge base, and how its published half reaches the model.
574
+ *
575
+ * `mode` is a property of the *set*, which is why it is here and not on each
576
+ * item - and why a screen should read it from here rather than inferring it.
577
+ */
578
+ export interface VisitorKnowledgeList {
579
+ /** Drafts included: this is the list a customer audits. */
580
+ items: VisitorKnowledgeItem[];
581
+ mode: "none" | "inline" | "retrieval";
582
+ }
583
+ /**
584
+ * What the widget should ask for next, decided by Connect.
585
+ *
586
+ * `"message"` is the ordinary composer. The others mean render that field's own
587
+ * input instead - and the reason this is a server decision rather than something
588
+ * the widget infers from the assistant's sentence is the phone: an email asked
589
+ * for in prose gets typed into a general text box with autocorrect on, where
590
+ * `type="email" inputmode="email" autocomplete="email"` brings up a keyboard
591
+ * with an `@` on it. A six-digit code wants `autocomplete="one-time-code"`,
592
+ * which is what lets iOS offer the code straight from the notification.
593
+ */
594
+ export type VisitorField = "message" | "email" | "code" | "name";
595
+ /** One stored message in a visitor conversation. `at` is ISO-8601. */
596
+ export interface VisitorMessage {
597
+ role: "visitor" | "assistant";
598
+ text: string;
599
+ at: string;
600
+ }
601
+ /**
602
+ * An appointment this conversation booked, as a visitor is allowed to see it.
603
+ *
604
+ * Deliberately not the booking: no host ids, no workspace ids, no internal
605
+ * reference - the same narrowing Connect's own public booking page makes.
606
+ */
607
+ export interface VisitorBooking {
608
+ startAt: string;
609
+ endAt: string;
610
+ /** The workspace's zone, not the visitor's - the zone the confirmation uses. */
611
+ timezone: string;
612
+ }
613
+ /**
614
+ * A conversation, as `visitor.startSession` opens or reopens it.
615
+ *
616
+ * **It carries no greeting and no suggestions.** Those are your own widget
617
+ * settings, rendered from your own store - so your bubble paints its first frame
618
+ * with no call to Connect at all, and this exists only to mint or recover the
619
+ * conversation Connect holds.
620
+ */
621
+ export interface VisitorSession {
622
+ /**
623
+ * Hold this and send it with every turn.
624
+ *
625
+ * Treat it as a credential: it is the only thing identifying the conversation,
626
+ * and anyone holding it can continue it. Keep it in `sessionStorage` - it
627
+ * should survive a reload, which is what lets somebody follow a link out of
628
+ * the chat and come back, and it should not travel to another tab or outlive
629
+ * the visit.
630
+ */
631
+ sessionId: string;
632
+ /** The transcript, oldest first. Empty on a new conversation. */
633
+ messages: VisitorMessage[];
634
+ field: VisitorField;
635
+ turnsRemaining: number;
636
+ booking: VisitorAppointment | null;
637
+ }
638
+ /**
639
+ * The appointment `visitor.book` placed, and the one a reopened conversation
640
+ * reports.
641
+ *
642
+ * `VisitorBooking` plus `label`, and the extra field is the point: the words are
643
+ * produced by the same formatter the confirmation email uses, so the chat and
644
+ * the email cannot read differently about the same appointment. Render it rather
645
+ * than formatting `startAt` yourself - the visitor's browser is in their zone and
646
+ * the appointment is in the host's, and `Intl`'s month names differ between
647
+ * engines besides.
648
+ */
649
+ export interface VisitorAppointment extends VisitorBooking {
650
+ label: string;
651
+ }
652
+ /** One time the assistant may offer, as its slot lookup returned it. */
653
+ export interface VisitorSlot {
654
+ /** ISO-8601. Pass this back verbatim to book it. */
655
+ startAt: string;
656
+ /** Already written out in the workspace's own timezone - render this, don't reformat. */
657
+ label: string;
658
+ }
659
+ /**
660
+ * The times a turn looked up, lifted out of the tool result.
661
+ *
662
+ * **Draw the buttons from this, never from the assistant's sentence.** A time the
663
+ * visitor taps is then one the server offered, which is what makes
664
+ * `visitor.book` unable to take a time nobody was given.
665
+ */
666
+ export interface VisitorSlotOffer {
667
+ eventType: string;
668
+ durationMinutes: number;
669
+ timezone: string;
670
+ slots: VisitorSlot[];
671
+ }
672
+ /** What a tool did this turn. `result` is the tool's own payload - switch on `name`. */
673
+ export interface VisitorToolCall {
674
+ name: string;
675
+ result: unknown;
676
+ }
677
+ /** The `done` event at the end of a streamed turn. */
678
+ export interface VisitorTurnDone {
679
+ toolCalls: VisitorToolCall[];
680
+ field: VisitorField;
681
+ turnsRemaining: number;
682
+ /**
683
+ * Whether the reply was grounded in published knowledge.
684
+ *
685
+ * `false` means nothing published covered the question, so the assistant said
686
+ * so and offered a call. Worth recording: a run of them is a knowledge base
687
+ * with a gap in it, which is the most useful signal this endpoint produces.
688
+ */
689
+ grounded: boolean;
690
+ }
537
691
  export interface ChatMessage {
538
692
  role: "user" | "assistant" | "system";
539
693
  [field: string]: unknown;
@@ -1909,6 +2063,265 @@ export type BrandExtractionResult = {
1909
2063
  status: "skipped";
1910
2064
  reason: BrandSkipReason;
1911
2065
  };
2066
+ /** The five questions a readiness report answers. */
2067
+ export type ReadinessDimension =
2068
+ /** Can an agent *act* here? MCP, OpenAPI, agent cards. */
2069
+ "agent_interfaces"
2070
+ /** Can an agent get the content at all? JavaScript dependency, bot walls, semantic structure. */
2071
+ | "retrievability"
2072
+ /** Can an agent *read* it? llms.txt, markdown twins, structured data. */
2073
+ | "machine_readable"
2074
+ /** Is an agent *allowed*, and does the site say so deliberately? */
2075
+ | "crawl_consent"
2076
+ /** Is the site safe and identifiable to transact with? */
2077
+ | "trust";
2078
+ /**
2079
+ * How a check came out.
2080
+ *
2081
+ * `error` is the one to handle deliberately: it means Connect **could not
2082
+ * measure** this - a timeout, a refused connection - and it is excluded from
2083
+ * the score rather than counted as a failure. Render it as unknown, never as a
2084
+ * problem. `absent` ("you do not have this") and `fail` ("you have it and it is
2085
+ * broken") are likewise distinct and want different words.
2086
+ */
2087
+ export type ReadinessCheckStatus = "pass" | "partial" | "fail" | "absent" | "error";
2088
+ /**
2089
+ * Whether a check can cost points or only earn them.
2090
+ *
2091
+ * A `bonus` check raises the score when it passes and leaves it alone when it
2092
+ * does not - so a site is never marked down for missing a convention almost
2093
+ * nobody has adopted yet. Worth surfacing differently in a UI: a failed `core`
2094
+ * check is a gap, an absent `bonus` one is an opportunity.
2095
+ */
2096
+ export type ReadinessCheckKind = "core" | "bonus";
2097
+ /** One measured fact, with the evidence that settles it. */
2098
+ export interface ReadinessCheck {
2099
+ /** Stable dotted id, e.g. `mcp.server`. Safe to key on; findings cite it. */
2100
+ id: string;
2101
+ dimension: ReadinessDimension;
2102
+ kind: ReadinessCheckKind;
2103
+ title: string;
2104
+ status: ReadinessCheckStatus;
2105
+ /** Relative importance inside its dimension. Only ratios are meaningful. */
2106
+ weight: number;
2107
+ /** What was actually observed, in one line - specific enough to show the user verbatim. */
2108
+ observed: string;
2109
+ /** The URL that proves it, where there is one. */
2110
+ evidence: string | null;
2111
+ }
2112
+ export interface ReadinessDimensionScore {
2113
+ dimension: ReadinessDimension;
2114
+ /** 0-100. */
2115
+ score: number;
2116
+ /** This dimension's share of the overall score. */
2117
+ weight: number;
2118
+ /** Core checks that could not be measured. Show this rather than implying full coverage. */
2119
+ unmeasured: number;
2120
+ }
2121
+ export type ReadinessGrade = "A" | "B" | "C" | "D" | "F";
2122
+ /** One thing to do about it, anchored in the checks that motivated it. */
2123
+ export interface ReadinessFinding {
2124
+ severity: "critical" | "warning" | "note";
2125
+ /** The checks this is about. Every id here appears in `checks`. */
2126
+ checkIds: string[];
2127
+ title: string;
2128
+ detail: string;
2129
+ fix: string;
2130
+ effort: "low" | "medium" | "high";
2131
+ }
2132
+ /**
2133
+ * Whether an assistant could answer a buyer's question from the site's own pages.
2134
+ *
2135
+ * The one judged rather than measured part of the report - a model read the
2136
+ * pages and decided. Everything else in `checks` was parsed from real responses.
2137
+ */
2138
+ export interface ReadinessAnswerability {
2139
+ offering: boolean;
2140
+ pricing: boolean;
2141
+ howToBuy: boolean;
2142
+ contact: boolean;
2143
+ summary: string;
2144
+ gaps: string[];
2145
+ }
2146
+ /**
2147
+ * How ready a site is for AI agents.
2148
+ *
2149
+ * The important property, and the one that makes this worth showing a customer:
2150
+ * **the score was computed from the checks, and the checks were measured.**
2151
+ * Whether an MCP server exists is a completed JSON-RPC handshake, not a file
2152
+ * that happened to answer 200; whether assistants are blocked is that site's
2153
+ * `robots.txt` evaluated by its real rules. A model contributed only
2154
+ * `answerability` and the prose in `findings`, and it cannot alter a status or
2155
+ * the score.
2156
+ */
2157
+ export interface ReadinessReport {
2158
+ /** Normalised - lowercase, no scheme, no `www.`. */
2159
+ domain: string;
2160
+ /** 0-100, weighted across dimensions. */
2161
+ score: number;
2162
+ grade: ReadinessGrade;
2163
+ dimensions: ReadinessDimensionScore[];
2164
+ checks: ReadinessCheck[];
2165
+ /** Ordered by consequence, most serious first. */
2166
+ findings: ReadinessFinding[];
2167
+ answerability: ReadinessAnswerability | null;
2168
+ /** The one thing to do first. Drawn from `findings`, so it never disagrees with them. */
2169
+ topFix: {
2170
+ checkId: string;
2171
+ title: string;
2172
+ fix: string;
2173
+ } | null;
2174
+ /** ISO-8601. Age the report against this. */
2175
+ assessedAt: string;
2176
+ }
2177
+ /**
2178
+ * Why there is nothing to report. A normal 200, not an error.
2179
+ *
2180
+ * The distinction that matters for what you show and whether you retry:
2181
+ * `unreachable` is about the **site** - it did not answer - and may succeed
2182
+ * later. `provider_unavailable` is about **Connect** - our assessment service
2183
+ * is down or unconfigured - and is worth retrying without telling the user
2184
+ * anything about their own site. `no_domain` and `blocked_domain` never succeed
2185
+ * on retry.
2186
+ */
2187
+ export type ReadinessSkipReason = "no_domain" | "blocked_domain" | "consumer_domain" | "unreachable" | "provider_unavailable";
2188
+ export type ReadinessAssessmentResult = {
2189
+ status: "assessed";
2190
+ report: ReadinessReport;
2191
+ /** Whether Connect served this from its platform-wide cache. The report is the same either way. */
2192
+ cached: boolean;
2193
+ } | {
2194
+ status: "skipped";
2195
+ reason: ReadinessSkipReason;
2196
+ };
2197
+ /** The five things a presence is scored on. */
2198
+ export type PresenceCategory = "findability" | "identity" | "social" | "contactability" | "trust";
2199
+ /**
2200
+ * How a check came out.
2201
+ *
2202
+ * `partial` is a real third state rather than a rounded failure: a site with
2203
+ * `og:title` but no `og:image` has done most of the work, and rendering that as
2204
+ * a failure is both wrong and discouraging.
2205
+ */
2206
+ export type PresenceCriterionStatus = "pass" | "partial" | "fail";
2207
+ /** Where a score sits, coarsely. Advisory - use it to pick wording, not to make a decision. */
2208
+ export type PresenceBand = "absent" | "emerging" | "established" | "strong";
2209
+ /** The networks a scan recognises. `other` is a profile that matched no known pattern, kept rather than dropped. */
2210
+ export type PresenceNetwork = "linkedin" | "instagram" | "facebook" | "youtube" | "google_business" | "crunchbase" | "x" | "tiktok" | "github" | "other";
2211
+ /**
2212
+ * One check, its verdict and the evidence behind it.
2213
+ *
2214
+ * `weight` and `earned` are both published so the total can be reconstructed:
2215
+ * a `partial` that cost two points and one that cost six look identical
2216
+ * without them, and a score nobody can reconstruct is a score nobody trusts.
2217
+ */
2218
+ export interface PresenceCriterion {
2219
+ /** Stable across scans, so two reports of one domain can be diffed. */
2220
+ key: string;
2221
+ category: PresenceCategory;
2222
+ label: string;
2223
+ status: PresenceCriterionStatus;
2224
+ /** The check's full weight in the rubric. */
2225
+ weight: number;
2226
+ /** The share of `weight` actually earned. */
2227
+ earned: number;
2228
+ /** What was seen, in one line. */
2229
+ observed: string;
2230
+ /** The URL that settles it, when there is one. */
2231
+ citation: string | null;
2232
+ /** What to change. `null` when the check passed. */
2233
+ fix: string | null;
2234
+ }
2235
+ export interface PresenceCategoryScore {
2236
+ category: PresenceCategory;
2237
+ /** 0-100 within the category, so a weak one is legible beside a strong one. */
2238
+ score: number;
2239
+ weight: number;
2240
+ earned: number;
2241
+ }
2242
+ /**
2243
+ * A profile the subject's own site linked.
2244
+ *
2245
+ * **Claimed, never verified.** Nothing in a scan proves the account belongs to
2246
+ * that business - that needs a credential for each network. Render it as
2247
+ * "linked from their site", never as a confirmed account.
2248
+ */
2249
+ export interface PresenceSocialProfile {
2250
+ network: PresenceNetwork;
2251
+ url: string;
2252
+ handle: string | null;
2253
+ /**
2254
+ * Whether the site declared it in `schema.org` `sameAs` markup rather than
2255
+ * only as a link.
2256
+ *
2257
+ * The one to read closely. `false` means a real presence with none of the
2258
+ * discoverability - a search engine has to infer the connection from a
2259
+ * footer icon - and it is among the most common findings a scan produces.
2260
+ */
2261
+ machineReadable: boolean;
2262
+ }
2263
+ /** One prioritised thing to do. `fix` is Connect's own reviewed text; `why` is written for this business. */
2264
+ export interface PresenceRecommendation {
2265
+ /** Names the check this came from, so advice is always traceable to evidence. */
2266
+ criterionKey: string;
2267
+ category: PresenceCategory;
2268
+ /** 1 is what to do first. Always 1..n with no gaps. */
2269
+ priority: number;
2270
+ title: string;
2271
+ /** What it costs this business specifically. Empty when the narrative could not be generated. */
2272
+ why: string;
2273
+ fix: string;
2274
+ }
2275
+ /**
2276
+ * How visible a business is online.
2277
+ *
2278
+ * The important property, and the one that makes this worth showing a
2279
+ * customer: **the score was computed from the checks, and the checks were
2280
+ * measured.** Every point comes from something a fetcher observed on the site.
2281
+ * A model contributed only the ordering of `recommendations` and the prose in
2282
+ * `why` and `summary`; it cannot alter a status, a weight or the score.
2283
+ */
2284
+ export interface PresenceScan {
2285
+ /** Normalised - lowercase, no scheme, no `www.`. */
2286
+ domain: string;
2287
+ /** 0-100. */
2288
+ score: number;
2289
+ band: PresenceBand;
2290
+ categories: PresenceCategoryScore[];
2291
+ /** Every check, passed and failed. The audit trail behind the number. */
2292
+ criteria: PresenceCriterion[];
2293
+ /** Every profile found, including networks the rubric does not weight individually. */
2294
+ social: PresenceSocialProfile[];
2295
+ /** Two or three sentences on the overall state. Empty when it could not be generated - the scan is complete without it. */
2296
+ summary: string;
2297
+ /** What to do, in order. Render this before `criteria`. */
2298
+ recommendations: PresenceRecommendation[];
2299
+ /** ISO-8601. Age the scan against this. */
2300
+ scannedAt: string;
2301
+ }
2302
+ /**
2303
+ * Why there is nothing to report. A normal 200, not an error.
2304
+ *
2305
+ * The distinction that matters for what you show and whether you retry:
2306
+ * `unreachable` is about the **site** - the home page did not answer - and may
2307
+ * succeed later. `provider_unavailable` is about **Connect** - our scanner is
2308
+ * down or unconfigured - and is worth retrying without telling the user
2309
+ * anything about their own site. `no_domain`, `consumer_domain` and
2310
+ * `blocked_domain` never succeed on retry.
2311
+ *
2312
+ * Note what is **not** here: a low score. Every check failing is a successful
2313
+ * scan and the most useful report this produces.
2314
+ */
2315
+ export type PresenceSkipReason = "no_domain" | "consumer_domain" | "blocked_domain" | "unreachable" | "provider_unavailable";
2316
+ export type PresenceScanResult = {
2317
+ status: "scanned";
2318
+ scan: PresenceScan;
2319
+ /** Whether Connect served this from its platform-wide cache. The scan is the same either way. */
2320
+ cached: boolean;
2321
+ } | {
2322
+ status: "skipped";
2323
+ reason: PresenceSkipReason;
2324
+ };
1912
2325
  /**
1913
2326
  * What kind of conversation a channel carries. `voice` is the only kind
1914
2327
  * Connect stocks inventory for today - `whatsapp` and `meeting` are modelled
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmoops/connect-sdk",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "description": "Official server-side SDK for the CosmoOps Connect platform API - Login with Connect, entitlements, billing and metering.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "commonjs",
@@ -83,7 +83,8 @@
83
83
  "test": "bun test",
84
84
  "docs:md": "typedoc --options typedoc.markdown.json",
85
85
  "storybook": "storybook dev -p 6106",
86
- "build:storybook": "storybook build -o storybook-static"
86
+ "build:storybook": "storybook build -o storybook-static",
87
+ "release:stage": "bun run scripts/stage-release.ts"
87
88
  },
88
89
  "devDependencies": {
89
90
  "@connect/ai": "workspace:*",