@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.
@@ -10,7 +10,7 @@
10
10
  * whatever theme the host application platform already configured, and one theme
11
11
  * change lands identically in all of them.
12
12
  */
13
- export { ConnectProvider, useConnect, useConnectUser, useConnectWorkspaceType, useConnectAudience, useConnectPlatformAccess, useConnectEntitlements, useConnectPlans, useConnectApps, useConnectCompanyProfile, useConnectAddonUsage, useConnectSessions, useConnectIntegrations, useConnectResource, CONNECT_APP_URL, } from "./provider.js";
13
+ export { ConnectProvider, useConnect, useConnectOptional, useConnectUser, useConnectWorkspaceType, useConnectAudience, useConnectPlatformAccess, useConnectEntitlements, useConnectPlans, useConnectApps, useConnectCompanyProfile, useConnectAddonUsage, useConnectSessions, useConnectIntegrations, useConnectResource, CONNECT_APP_URL, } from "./provider.js";
14
14
  export type { ConnectProviderProps, ConnectContextValue, ConnectSession, ConnectOneTapHint, ConnectOneTapFailure, UseConnectResourceOptions, } from "./provider.js";
15
15
  export { blockingBlockers, normalizePlanFeatures } from "../helpers.js";
16
16
  export type { WirePlanFeature } from "../helpers.js";
@@ -52,6 +52,11 @@ export { normalizeNav, flattenNav, normalizePath, resolveActivePath, isNavItemAc
52
52
  export type { ConnectNav, ConnectNavItem, ConnectNavSection, ConnectNavLinkProps, ConnectLinkRenderer, } from "./components/nav.js";
53
53
  export type { ConnectScreen } from "../types.js";
54
54
  export { matchConnectScreen, isLinkableConnectScreen, } from "./components/ai-screens.js";
55
+ export { ConnectVisitorChat } from "./components/visitor-chat.js";
56
+ export type { ConnectVisitorChatProps } from "./components/visitor-chat.js";
57
+ export { readVisitorStream, visitorSlotOfferFrom } from "./components/visitor-stream.js";
58
+ export type { VisitorStreamHandlers } from "./components/visitor-stream.js";
59
+ export type { VisitorAppointment, VisitorBooking, VisitorField, VisitorMessage, VisitorSession, VisitorSlot, VisitorSlotOffer, VisitorToolCall, VisitorTurnDone, } from "../types.js";
55
60
  export { ConnectAppsGrid } from "./components/apps-grid.js";
56
61
  export type { ConnectAppsGridProps } from "./components/apps-grid.js";
57
62
  export { ConnectAskAi } from "./components/ask-ai.js";
@@ -245,6 +245,27 @@ export interface ConnectProviderProps {
245
245
  */
246
246
  export declare function ConnectProvider({ clientId, basePath, redirectUri, appUrl, fetch: fetchImpl, silentSignIn, children, }: ConnectProviderProps): import("react").JSX.Element;
247
247
  export declare function useConnect(): ConnectContextValue;
248
+ /**
249
+ * The context when there is one, `null` when there is not.
250
+ *
251
+ * **For a component that must work on a page with no provider**, which is a
252
+ * real case rather than defensive coding: `<ConnectVisitorChat>` goes on a
253
+ * public marketing page, and those pages frequently have no `ConnectProvider`
254
+ * anywhere near them - there is no session to hold and nothing on the page that
255
+ * needs one. `useConnect()` throwing is right for every component that reads a
256
+ * session; it is wrong for one whose whole purpose is the visitor who has none.
257
+ *
258
+ * What inheriting the context buys such a component, when it is inside one, is
259
+ * `basePath` and the injected `fetch` - so the same component renders against
260
+ * Storybook's mock bridge and the docs site's canned fetch without either of
261
+ * them having to pass anything.
262
+ *
263
+ * Do not reach for this to make an ordinary component tolerant of a missing
264
+ * provider. A session-reading component that silently renders a signed-out
265
+ * state because somebody forgot to wrap their app is a bug that looks like a
266
+ * product decision.
267
+ */
268
+ export declare function useConnectOptional(): ConnectContextValue | null;
248
269
  /** The signed-in user, or `null`. Sugar over `useConnect().session`. */
249
270
  export declare function useConnectUser(): ConnectUser | null;
250
271
  /**
@@ -21,6 +21,7 @@ import { AnalyticsResource } from "./resources/analytics.js";
21
21
  import { OtpResource } from "./resources/otp.js";
22
22
  import { SessionsResource } from "./resources/sessions.js";
23
23
  import { PlatformResource } from "./resources/platform.js";
24
+ import { VisitorResource } from "./resources/visitor.js";
24
25
  import { PushResource } from "./resources/push.js";
25
26
  export declare const DEFAULT_BASE_URL = "https://connect.cosmoops.com";
26
27
  export interface ConnectClientOptions {
@@ -111,6 +112,11 @@ export declare class ConnectClient {
111
112
  readonly integrations: IntegrationsResource;
112
113
  /** Which workspaces the signed-in user belongs to, switching between them, and the team - see `WorkspacesResource`. */
113
114
  readonly workspaces: WorkspacesResource;
115
+ /**
116
+ * The public chat bubble on your own site - see `VisitorResource`. The one
117
+ * resource here whose caller is not one of your users.
118
+ */
119
+ readonly visitor: VisitorResource;
114
120
  /** The platform's own legal identity and DPDP grievance channel - see `PlatformResource`. */
115
121
  readonly platform: PlatformResource;
116
122
  /**
@@ -40,28 +40,4 @@ export interface ConnectHandlerOptions {
40
40
  */
41
41
  stateCookieName?: string;
42
42
  }
43
- /**
44
- * The browser half of this SDK cannot hold an API key - so it does not.
45
- *
46
- * `@cosmoops/connect-sdk/client` talks only to your own origin, and this
47
- * handler is what answers. It lives in your backend, holds the key, and
48
- * exposes a fixed, named set of reads plus sign-out and session revocation.
49
- * Nothing here proxies arbitrary paths: a generic passthrough would hand the
50
- * browser your whole API surface under your credentials, which is the same
51
- * leak with extra steps.
52
- *
53
- * Framework-agnostic - `Request` in, `Response` out, so it mounts anywhere
54
- * that shape exists.
55
- *
56
- * ```ts
57
- * // app/api/connect/[...route]/route.ts
58
- * const handler = createConnectHandler({ client, session });
59
- * export { handler as GET, handler as POST };
60
- * ```
61
- *
62
- * Every route resolves the workspace from the caller's *own* session, never
63
- * from a query parameter. A browser must not be able to ask about an
64
- * workspace it is not signed into, and a client-supplied `workspaceId`
65
- * is exactly that hole.
66
- */
67
43
  export declare function createConnectHandler(options: ConnectHandlerOptions): (request: Request) => Promise<Response>;
@@ -1,5 +1,5 @@
1
1
  import { type TransportOptions } from "../http.js";
2
- import type { AiConversationDetail, AiConversationList, AssessmentAnswers, AssessmentDraft, AssessmentReview, ChatMessage, ConnectScreen } from "../../types.js";
2
+ import type { AiConversationDetail, AiConversationList, AssessmentAnswers, AssessmentDraft, AssessmentReview, ChatMessage, ConnectScreen, ReadinessAssessmentResult } from "../../types.js";
3
3
  /**
4
4
  * RAG chat and structured extraction against a workspace's data.
5
5
  *
@@ -114,4 +114,51 @@ export declare class AiResource {
114
114
  assessmentKey: string;
115
115
  answers: AssessmentAnswers;
116
116
  }): Promise<AssessmentReview>;
117
+ /**
118
+ * How ready the site at a domain is for AI agents.
119
+ *
120
+ * Probes for an MCP server, an OpenAPI description, `llms.txt`, structured
121
+ * data and a markdown twin; evaluates the site's `robots.txt` against the
122
+ * assistants that actually fetch pages; checks whether its content survives
123
+ * without JavaScript and whether a bot wall refuses agents outright. Then
124
+ * grades what it found and says what to fix first.
125
+ *
126
+ * Needs an API key scoped to **`ai:readiness`**, which is separate from every
127
+ * other AI scope because it is the widest outbound surface on the API - it
128
+ * POSTs to candidate MCP endpoints and fetches the home page under two user
129
+ * agents.
130
+ *
131
+ * ```ts
132
+ * const result = await connect.ai.readiness({ domain: "acme.com" });
133
+ * if (result.status === "assessed") {
134
+ * console.log(result.report.grade, result.report.topFix?.fix);
135
+ * }
136
+ * ```
137
+ *
138
+ * Four things to know before wiring it in:
139
+ *
140
+ * - **Set your client timeout to at least 90 seconds.** A cold assessment
141
+ * runs the whole probe before answering and can take up to a minute; many
142
+ * HTTP clients default to 30s and abandon a request that was about to
143
+ * succeed. Cached reads return in milliseconds and are the normal case -
144
+ * reports are held for a week.
145
+ * - **A week, not ninety days**, because a report is a to-do list somebody is
146
+ * working through. Pass `refresh` after shipping a fix to see it land.
147
+ * - **Handle `status: "error"` checks as unknown, not as failures.** They mean
148
+ * Connect could not measure that check, and they are excluded from the
149
+ * score rather than counted against it.
150
+ * - **`skipped` says whose problem it is.** `unreachable` means the site did
151
+ * not answer; `provider_unavailable` means Connect's own assessment service
152
+ * did. Only the second is worth retrying silently, and neither should be
153
+ * shown as a failing grade.
154
+ */
155
+ readiness(input: {
156
+ /** A domain or a URL in any form - `acme.com`, `www.acme.com`, `https://acme.com/pricing`. */
157
+ domain: string;
158
+ asUser?: string;
159
+ /** Re-assess even if Connect has a fresh report cached. For an operator who has just shipped a fix. */
160
+ refresh?: boolean;
161
+ }, options?: {
162
+ signal?: AbortSignal;
163
+ }): Promise<ReadinessAssessmentResult>;
117
164
  }
@@ -1,5 +1,5 @@
1
1
  import { type TransportOptions } from "../http.js";
2
- import type { BrandExtractionResult, CompanyEnrichmentResult } from "../../types.js";
2
+ import type { BrandExtractionResult, CompanyEnrichmentResult, PresenceScanResult } from "../../types.js";
3
3
  /**
4
4
  * What Connect knows about the company at a domain.
5
5
  *
@@ -86,4 +86,60 @@ export declare class EnrichmentResource {
86
86
  }, options?: {
87
87
  signal?: AbortSignal;
88
88
  }): Promise<BrandExtractionResult>;
89
+ /**
90
+ * How **visible** the business at a domain is online, scored out of 100.
91
+ *
92
+ * The third sibling of `company()` and `brand()`: that one answers what a
93
+ * business does, the other what it looks like, and this one answers how
94
+ * findable it is - by a search engine, by a customer, and by the assistants
95
+ * that increasingly answer questions about a business before anybody visits
96
+ * its site.
97
+ *
98
+ * Needs an API key scoped to **`enrichment:presence`** - separate from
99
+ * `enrichment:read` and `enrichment:brand` because it is the widest outbound
100
+ * read of the three: roughly twenty fetches across the site's well-known
101
+ * paths, and sometimes a headless browser.
102
+ *
103
+ * ```ts
104
+ * const result = await connect.enrichment.presence({ domain: "acme.com" });
105
+ * if (result.status === "scanned") {
106
+ * for (const next of result.scan.recommendations) {
107
+ * console.log(`${next.priority}. ${next.title} - ${next.fix}`);
108
+ * }
109
+ * }
110
+ * ```
111
+ *
112
+ * Four things to know before wiring it in:
113
+ *
114
+ * - **The score is computed, not generated.** Every point comes from a check
115
+ * run against something actually observed, and every check ships with its
116
+ * weight, what was seen and the URL that settles it - so the total is
117
+ * reconstructable. A model only orders `recommendations` and writes the
118
+ * prose; it cannot move the number. That is the whole reason this is worth
119
+ * showing a customer: ask a model how good a company's web presence is and
120
+ * it answers 72 with total confidence for a site it never read.
121
+ * - **`social` is claimed, never verified.** Those are URLs the site itself
122
+ * printed. Nothing proves the account belongs to that business - render it
123
+ * as "linked from their site". Check `machineReadable` too: `false` means
124
+ * a real profile that search engines have to infer from a footer link,
125
+ * which is a specific, common and easily fixed finding.
126
+ * - **A low score is a success, not a skip.** Every check failing is the most
127
+ * useful report this produces. Only `unreachable` means the site did not
128
+ * answer - and `provider_unavailable` means *Connect* did not, which is
129
+ * never something to tell your user about their own site.
130
+ * - **Set your client timeout to at least 90 seconds.** A cold scan runs the
131
+ * whole probe before answering; many HTTP clients default to 30s and
132
+ * abandon a request that was about to succeed. Cached scans return in
133
+ * milliseconds, and cached is the normal case - results are held for a
134
+ * fortnight, so you pay the cold path roughly once per domain.
135
+ */
136
+ presence(input: {
137
+ /** A domain or a URL in any form - `acme.com`, `www.acme.com`, `https://acme.com/pricing`. */
138
+ domain: string;
139
+ asUser?: string;
140
+ /** Re-scan even if Connect has a fresh result cached. For an operator who has just shipped a fix - not for automatic calls. */
141
+ refresh?: boolean;
142
+ }, options?: {
143
+ signal?: AbortSignal;
144
+ }): Promise<PresenceScanResult>;
89
145
  }
@@ -0,0 +1,200 @@
1
+ import { type TransportOptions } from "../http.js";
2
+ import type { VisitorAppointment, VisitorKnowledgeItem, VisitorKnowledgeList, VisitorKnowledgeSource, VisitorSession } from "../../types.js";
3
+ /**
4
+ * What `book` takes.
5
+ *
6
+ * A named interface rather than an inline shape, so `conformance.test.ts` can
7
+ * pin it against the server's own request schema - the check that stops a
8
+ * required field being optional here, which is a 400 a partner only meets at
9
+ * runtime.
10
+ */
11
+ export interface VisitorBookInput {
12
+ sessionId: string;
13
+ workspaceId: string;
14
+ /** The same published slug the turn's slot lookup used. */
15
+ eventTypeSlug: string;
16
+ /** ISO-8601, or a `Date`. Must be one of the offered slots. */
17
+ startAt: string | Date;
18
+ name: string;
19
+ /** Required - it is how the host reaches them, and the second limiter key. */
20
+ phone: string;
21
+ email?: string | null;
22
+ notes?: string | null;
23
+ }
24
+ /** The per-call option every visitor method takes, so the limiter can see a visitor. */
25
+ export interface VisitorCallOptions {
26
+ /** The visitor's address, as your bridge saw it. See `VISITOR_IP_HEADER`. */
27
+ visitorIp?: string | null;
28
+ signal?: AbortSignal;
29
+ }
30
+ /**
31
+ * The public chat bubble on your own marketing site.
32
+ *
33
+ * The one resource here whose caller is **not** one of your users. There is no
34
+ * `asUser`, no `workspaceId` and no session anywhere in it: the counterpart is a
35
+ * stranger who has no account, and everything the assistant may say or do is
36
+ * configuration a platform admin set on your application record.
37
+ *
38
+ * That is why none of these methods takes an id naming anything. The workspace a
39
+ * call books into, the event type it books, the knowledge it answers from and the
40
+ * daily budget it spends are all read from your application - so nothing a
41
+ * visitor types, and nothing an injection attempt in your own chat window
42
+ * achieves, reaches a different tenant.
43
+ *
44
+ * **Never call these from a browser.** They take your API key, like every other
45
+ * resource on this client. `createConnectHandler` already exposes them on your
46
+ * own origin for `<ConnectVisitorChat>` to use, which is how the credential stays
47
+ * server-side.
48
+ */
49
+ export declare class VisitorResource {
50
+ private readonly transport;
51
+ /**
52
+ * The knowledge base behind the assistant - see `VisitorKnowledgeResource`.
53
+ *
54
+ * Nested rather than a top-level resource, because it is meaningless on its
55
+ * own: it exists to decide what *this* assistant may say.
56
+ */
57
+ readonly knowledge: VisitorKnowledgeResource;
58
+ constructor(transport: TransportOptions);
59
+ /**
60
+ * Open a conversation, or reopen one.
61
+ *
62
+ * Generates nothing - the greeting and the suggested questions come off the
63
+ * application record - so this is the one call in the flow that is always fast,
64
+ * which is what lets a bubble paint real copy instead of a spinner.
65
+ *
66
+ * Pass `resume` with a `sessionId` you kept and the transcript comes back with
67
+ * it. A `resume` that is expired, unknown or another application's silently
68
+ * starts a fresh conversation rather than failing: the token is the only thing
69
+ * being offered and it is being rejected, so there is nothing for the visitor
70
+ * to do about an error.
71
+ */
72
+ startSession(input: {
73
+ /** The customer whose website this is. Checked against your subscriptions. */
74
+ workspaceId: string;
75
+ /**
76
+ * Where the bubble was opened - a path or a page title.
77
+ *
78
+ * Worth passing: "how much is this?" asked from a pricing page and from a
79
+ * docs page are different questions, and this is the only signal of which.
80
+ * Treated as an untrusted hint and nothing else.
81
+ */
82
+ page?: string | null;
83
+ resume?: string | null;
84
+ }, options?: VisitorCallOptions): Promise<VisitorSession>;
85
+ /**
86
+ * One turn, streamed.
87
+ *
88
+ * Returns the raw `Response` rather than a parsed body, the same way
89
+ * `ai.chat` does: this answers server-sent events, and buffering them here
90
+ * would throw away the only reason to stream. The events are `delta`
91
+ * (`{text}`), `done` (`VisitorTurnDone`) and `error` (`{message}`).
92
+ *
93
+ * **The transcript is not a parameter**, which is the security property this
94
+ * endpoint is built around: the caller is ultimately a browser on a public
95
+ * page, and a client that can supply its own transcript can supply one in
96
+ * which anything has already been established. Only the conversation id and
97
+ * the new message travel.
98
+ */
99
+ chat(input: {
100
+ sessionId: string;
101
+ workspaceId: string;
102
+ message: string;
103
+ /** What the assistant calls itself, from your own widget settings. */
104
+ assistantName?: string;
105
+ /** A published event type slug in that workspace, for the booking exit. */
106
+ bookingEventTypeSlug?: string | null;
107
+ }, options?: VisitorCallOptions): Promise<Response>;
108
+ /**
109
+ * Book the call a visitor chose.
110
+ *
111
+ * `startAt` must be a time the turn's own slot lookup returned - an arbitrary
112
+ * instant is refused. That, plus a name and phone collected in real fields,
113
+ * is what makes it impossible to book an appointment at a time nobody offered
114
+ * or with a phone number a model parsed out of prose.
115
+ *
116
+ * A conversation books at most one appointment; a second call answers `409`.
117
+ */
118
+ book(input: VisitorBookInput, options?: VisitorCallOptions): Promise<VisitorAppointment>;
119
+ }
120
+ /**
121
+ * What `knowledge.save` takes.
122
+ *
123
+ * A named interface so `conformance.test.ts` can pin it against the server's own
124
+ * request schema - the check that stops a required field being optional here,
125
+ * which is a 400 a partner only meets at runtime.
126
+ */
127
+ export interface SaveVisitorKnowledgeInput {
128
+ workspaceId: string;
129
+ /** Omit to create. An id that does not exist is refused, never created under. */
130
+ itemId?: string | null;
131
+ title: string;
132
+ body: string;
133
+ source: VisitorKnowledgeSource;
134
+ /** The crawled URL or the uploaded file's name. */
135
+ sourceRef?: string | null;
136
+ }
137
+ /**
138
+ * A subscribing workspace's **public** knowledge base - what their website chat
139
+ * may tell strangers.
140
+ *
141
+ * ## It is deliberately not their Context Index
142
+ *
143
+ * `ai.chat` answers from a workspace's Drive-fed corpus, for a signed-in member
144
+ * of that workspace. This is a separate store that holds only what somebody
145
+ * explicitly published, and the separation is the reason a publishable widget
146
+ * credential is safe to publish: everything the widget can reach was already
147
+ * meant for the public.
148
+ *
149
+ * Do not try to fill it by uploading to Drive. Nothing reaches this store as a
150
+ * side effect of anything else - that is the invariant, not an inconvenience.
151
+ *
152
+ * ## Publishing is its own call
153
+ *
154
+ * `save` always writes a draft. `publish` is what makes text readable by
155
+ * strangers, so no edit can do it by accident, and `unpublish` can fail - which
156
+ * means the item is **still live**, not that the call was pointless.
157
+ */
158
+ export declare class VisitorKnowledgeResource {
159
+ private readonly transport;
160
+ constructor(transport: TransportOptions);
161
+ /** Everything, drafts included - the list a customer audits. */
162
+ list(workspaceId: string): Promise<VisitorKnowledgeList>;
163
+ /**
164
+ * Create or edit a draft.
165
+ *
166
+ * A body over the cap is **refused rather than truncated** - split a long page
167
+ * into sections, which is also what makes retrieval work.
168
+ */
169
+ save(input: SaveVisitorKnowledgeInput): Promise<VisitorKnowledgeItem>;
170
+ /**
171
+ * Make one item readable by strangers.
172
+ *
173
+ * May be slow: the publish that outgrows the prompt provisions a retrieval
174
+ * corpus and indexes everything published so far. An indexing failure still
175
+ * publishes and comes back with `indexState: "failed"` and `indexError` set,
176
+ * so a provider hiccup never makes your button look broken.
177
+ */
178
+ publish(input: {
179
+ workspaceId: string;
180
+ itemId: string;
181
+ }): Promise<VisitorKnowledgeItem>;
182
+ /**
183
+ * Take one item out of what strangers can read.
184
+ *
185
+ * **A failure means it is still live.** The retrievable copy is removed before
186
+ * the record is flipped, so a provider that refuses the delete aborts rather
187
+ * than leaving an item your screen shows as withdrawn that the widget goes on
188
+ * quoting. Surface the error and let them retry; do not grey the row out
189
+ * optimistically.
190
+ */
191
+ unpublish(input: {
192
+ workspaceId: string;
193
+ itemId: string;
194
+ }): Promise<VisitorKnowledgeItem>;
195
+ /** Remove it entirely. A published item is unpublished first. */
196
+ delete(input: {
197
+ workspaceId: string;
198
+ itemId: string;
199
+ }): Promise<void>;
200
+ }