@proveanything/smartlinks 2.1.17 → 2.1.19

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 (80) hide show
  1. package/dist/adminViews.d.ts +104 -0
  2. package/dist/adminViews.js +275 -0
  3. package/dist/api/ai.d.ts +15 -5
  4. package/dist/api/ai.js +15 -9
  5. package/dist/api/aiGuide.d.ts +108 -0
  6. package/dist/api/aiGuide.js +161 -0
  7. package/dist/api/appObjects.d.ts +21 -0
  8. package/dist/api/appObjects.js +33 -1
  9. package/dist/api/authKit.d.ts +37 -1
  10. package/dist/api/authKit.js +51 -0
  11. package/dist/api/index.d.ts +2 -0
  12. package/dist/api/index.js +2 -0
  13. package/dist/api/operations.d.ts +36 -0
  14. package/dist/api/operations.js +56 -0
  15. package/dist/api/order.d.ts +12 -1
  16. package/dist/api/order.js +15 -0
  17. package/dist/api/userGroups.d.ts +78 -0
  18. package/dist/api/userGroups.js +124 -0
  19. package/dist/docs/API_SUMMARY.md +1111 -80
  20. package/dist/docs/admin-lists-and-pickers.md +140 -0
  21. package/dist/docs/admin-views.md +147 -0
  22. package/dist/docs/app-data-storage.md +277 -276
  23. package/dist/docs/app-manifest.md +2 -0
  24. package/dist/docs/auth-kit.md +872 -741
  25. package/dist/docs/comms.md +686 -644
  26. package/dist/docs/customer-guide.md +70 -0
  27. package/dist/docs/headless-providers.md +112 -112
  28. package/dist/docs/operations.md +281 -0
  29. package/dist/docs/overview.md +3 -0
  30. package/dist/docs/server-functions.md +87 -1
  31. package/dist/docs/ui-utils.md +123 -121
  32. package/dist/docs/user-groups.md +175 -0
  33. package/dist/docs/utils.md +17 -0
  34. package/dist/headless.js +38 -2
  35. package/dist/http.js +8 -0
  36. package/dist/iframeResponder.d.ts +15 -0
  37. package/dist/iframeResponder.js +39 -1
  38. package/dist/index.d.ts +3 -1
  39. package/dist/index.js +2 -0
  40. package/dist/live.d.ts +80 -0
  41. package/dist/live.js +315 -0
  42. package/dist/openapi.yaml +1864 -48
  43. package/dist/testing/index.d.ts +35 -0
  44. package/dist/testing/index.js +86 -0
  45. package/dist/types/appManifest.d.ts +297 -1
  46. package/dist/types/appOptions.d.ts +32 -0
  47. package/dist/types/appOptions.js +3 -0
  48. package/dist/types/authKit.d.ts +193 -4
  49. package/dist/types/comms.d.ts +41 -2
  50. package/dist/types/containers.d.ts +8 -0
  51. package/dist/types/headless.d.ts +49 -1
  52. package/dist/types/iframeResponder.d.ts +16 -1
  53. package/dist/types/index.d.ts +3 -0
  54. package/dist/types/index.js +3 -0
  55. package/dist/types/operations.d.ts +598 -0
  56. package/dist/types/operations.js +8 -0
  57. package/dist/types/order.d.ts +35 -6
  58. package/dist/types/userGroups.d.ts +103 -0
  59. package/dist/types/userGroups.js +5 -0
  60. package/dist/utils/conditions.d.ts +7 -0
  61. package/dist/utils/conditions.js +16 -9
  62. package/docs/API_SUMMARY.md +1111 -80
  63. package/docs/admin-lists-and-pickers.md +140 -0
  64. package/docs/admin-views.md +147 -0
  65. package/docs/app-data-storage.md +277 -276
  66. package/docs/app-manifest.md +2 -0
  67. package/docs/auth-kit.md +872 -741
  68. package/docs/comms.md +686 -644
  69. package/docs/customer-guide.md +70 -0
  70. package/docs/headless-providers.md +112 -112
  71. package/docs/operations.md +281 -0
  72. package/docs/overview.md +3 -0
  73. package/docs/server-functions.md +87 -1
  74. package/docs/ui-utils.md +123 -121
  75. package/docs/user-groups.md +175 -0
  76. package/docs/utils.md +17 -0
  77. package/openapi.yaml +1864 -48
  78. package/package.json +1 -1
  79. package/scripts/doctor.mjs +454 -428
  80. package/scripts/lib/keyed-app-data.mjs +21 -0
@@ -0,0 +1,104 @@
1
+ import type { AdminView } from './types/appManifest.js';
2
+ export type { AdminView };
3
+ /** What the host asks for. Either a declared `view` (with its params) or a raw hash `path`. */
4
+ export interface NavigateRequest {
5
+ view?: string;
6
+ path?: string;
7
+ params?: Record<string, string>;
8
+ /** Something on the screen to point at: an id the app understands (a row, a field). Optional. */
9
+ highlight?: string;
10
+ }
11
+ /** What the app's handler is given: the resolved hash path (query included) to hand to its router. */
12
+ export interface NavigateTarget {
13
+ /** Hash route, with any optional params as a query string: `/campaigns/c_1?tab=results`. */
14
+ path: string;
15
+ /** The declared view, when the host named one or the path matches one. */
16
+ view?: AdminView;
17
+ params: Record<string, string>;
18
+ highlight?: string;
19
+ }
20
+ /**
21
+ * The hash path for a view: `{name}` placeholders filled from `params` (required — null when one is
22
+ * missing or empty), every other param appended as a query string.
23
+ *
24
+ * @example pathFor({ id: 'campaign', title: 'Campaign', path: '/campaigns/{campaignId}' }, { campaignId: 'c_1' })
25
+ * // → '/campaigns/c_1'
26
+ */
27
+ export declare function pathFor(view: Pick<AdminView, 'path'>, params?: Record<string, string | undefined>): string | null;
28
+ /**
29
+ * Which declared view a hash path is (with its params), or null. When several match, the one with the
30
+ * most fixed segments wins (`/campaigns/new` over `/campaigns/{campaignId}`).
31
+ */
32
+ export declare function match(views: AdminView[], path: string): {
33
+ view: AdminView;
34
+ params: Record<string, string>;
35
+ } | null;
36
+ /** The side menu: areas in declared order, and Settings for the bottom. Record views are left out. */
37
+ export declare function menu(views: AdminView[]): {
38
+ main: AdminView[];
39
+ settings: AdminView[];
40
+ };
41
+ /**
42
+ * The chain from a top-level area down to `id`: `['campaigns', 'campaign', 'campaign.results']`.
43
+ * The first entry is the menu item to show as current; for a record view, the record's first view
44
+ * is `chain[1]`.
45
+ */
46
+ export declare function trail(views: AdminView[], id: string): AdminView[];
47
+ /**
48
+ * The swapped menu while one record is open: `back` is the area to return to ("← All campaigns"),
49
+ * `items` the record's first view followed by the views within it. Null when `id` isn't a record view.
50
+ */
51
+ export declare function recordMenu(views: AdminView[], id: string): {
52
+ back?: AdminView;
53
+ record: AdminView;
54
+ items: AdminView[];
55
+ } | null;
56
+ /**
57
+ * Resolve a host's request against the app's views: a named view becomes its path; a raw path is
58
+ * matched to a view where it can be. Null when the view is unknown, a required param is missing, or
59
+ * the path isn't a hash route of this app (`/…`, no scheme, no `//`).
60
+ */
61
+ export declare function resolve(views: AdminView[], req: NavigateRequest): NavigateTarget | null;
62
+ /**
63
+ * `'none'` when the host opened this page with `chrome=none`: the host's own menu carries this app's
64
+ * views, so the app hides its side menu (and the bar with its toggle) and shows only the content.
65
+ * Read from the address the page was first opened at.
66
+ */
67
+ export declare function hostChrome(): 'none' | 'full';
68
+ /**
69
+ * Follow the host's `smartlinks:navigate`: the handler gets the resolved hash path and hands it to the
70
+ * app's router (no reload). Registering tells the host this page follows navigate, so it stops
71
+ * reloading the frame to change screens. Only messages from the parent window are taken. Returns a
72
+ * function that stops listening.
73
+ *
74
+ * @example
75
+ * // React Router, with the views from the app's own manifest
76
+ * import manifest from '../public/app.manifest.json'
77
+ * const navigate = useNavigate()
78
+ * useEffect(() => SL.adminViews.onNavigate(manifest.adminViews, (to) => navigate(to.path)), [navigate])
79
+ */
80
+ export declare function onNavigate(views: AdminView[] | undefined | null, handler: (to: NavigateTarget) => void): () => void;
81
+ /** Another app's screen to open: by its admin view (and params), or by a hash path. */
82
+ export interface OpenAppRequest {
83
+ /** The installed app's id in this collection (`'crm'`, `'messages'`, `'appointment-booking'`). */
84
+ appId: string;
85
+ view?: string;
86
+ params?: Record<string, string>;
87
+ path?: string;
88
+ }
89
+ /**
90
+ * Ask the host (Studio) to open ANOTHER app at one of its screens: a contact in the CRM, a booking in
91
+ * the booking app, a person's messages in Messages. The host reads that app's manifest `adminViews`,
92
+ * turns the view into its address and opens it, so it works whichever SDK the other app is on. Posts
93
+ * `{ type: 'smartlinks:open-app', payload: { appId, view?, params?, path? } }` to the parent. No-op
94
+ * outside a frame.
95
+ *
96
+ * @example
97
+ * SL.adminViews.openApp({ appId: 'crm', view: 'contact', params: { contactId } })
98
+ */
99
+ export declare function openApp(req: OpenAppRequest): void;
100
+ /**
101
+ * Ask an embedded app to open a screen. Post this only once the app has said it follows navigate
102
+ * (`smartlinks:navigable`); otherwise reload the frame at the new path as before.
103
+ */
104
+ export declare function postNavigate(target: Window | null | undefined, req: NavigateRequest, targetOrigin?: string): void;
@@ -0,0 +1,275 @@
1
+ // src/adminViews.ts
2
+ // ADMIN VIEWS — an app's admin screens by name (app.manifest.json#adminViews), and the two runtime
3
+ // messages that use them:
4
+ // host → app { type: 'smartlinks:navigate', view?, path?, params?, highlight? } open a screen, no reload
5
+ // app → host 'smartlinks:navigable' (the app follows navigate) 'smartlinks:navigate-result'
6
+ // app → host 'smartlinks:open-app' { appId, view?, params?, path? } open ANOTHER app at a screen
7
+ // plus `chrome=none`: the host carries the app's menu itself, so the app hides its own.
8
+ // One list drives the app's own side menu, Studio's workspace menu and the assistant. See
9
+ // docs/admin-views.md.
10
+ const PLACEHOLDER = /\{([A-Za-z0-9_]+)\}/g;
11
+ /**
12
+ * The hash path for a view: `{name}` placeholders filled from `params` (required — null when one is
13
+ * missing or empty), every other param appended as a query string.
14
+ *
15
+ * @example pathFor({ id: 'campaign', title: 'Campaign', path: '/campaigns/{campaignId}' }, { campaignId: 'c_1' })
16
+ * // → '/campaigns/c_1'
17
+ */
18
+ export function pathFor(view, params = {}) {
19
+ const used = new Set();
20
+ let missing = false;
21
+ const filled = view.path.replace(PLACEHOLDER, (_, name) => {
22
+ used.add(name);
23
+ const v = params[name];
24
+ if (v == null || v === '') {
25
+ missing = true;
26
+ return '';
27
+ }
28
+ return encodeURIComponent(v);
29
+ });
30
+ if (missing)
31
+ return null;
32
+ const q = new URLSearchParams();
33
+ for (const [k, v] of Object.entries(params)) {
34
+ if (!used.has(k) && v != null && v !== '')
35
+ q.set(k, v);
36
+ }
37
+ const qs = q.toString();
38
+ return qs ? `${filled}?${qs}` : filled;
39
+ }
40
+ function splitPath(path) {
41
+ const i = path.indexOf('?');
42
+ return i < 0 ? { pathname: path, query: new URLSearchParams() } : { pathname: path.slice(0, i), query: new URLSearchParams(path.slice(i + 1)) };
43
+ }
44
+ const trimSlash = (p) => (p.length > 1 ? p.replace(/\/+$/, '') : p);
45
+ /**
46
+ * Which declared view a hash path is (with its params), or null. When several match, the one with the
47
+ * most fixed segments wins (`/campaigns/new` over `/campaigns/{campaignId}`).
48
+ */
49
+ export function match(views, path) {
50
+ const { pathname, query } = splitPath(path || '/');
51
+ const segs = trimSlash(pathname).split('/');
52
+ let best = null;
53
+ for (const view of views) {
54
+ const tsegs = trimSlash(view.path).split('/');
55
+ if (tsegs.length !== segs.length)
56
+ continue;
57
+ const params = {};
58
+ let fixed = 0;
59
+ let ok = true;
60
+ for (let i = 0; i < tsegs.length; i++) {
61
+ const t = tsegs[i];
62
+ const m = /^\{([A-Za-z0-9_]+)\}$/.exec(t);
63
+ if (m) {
64
+ if (!segs[i]) {
65
+ ok = false;
66
+ break;
67
+ }
68
+ try {
69
+ params[m[1]] = decodeURIComponent(segs[i]);
70
+ }
71
+ catch (_a) {
72
+ params[m[1]] = segs[i];
73
+ }
74
+ }
75
+ else if (t === segs[i]) {
76
+ fixed++;
77
+ }
78
+ else {
79
+ ok = false;
80
+ break;
81
+ }
82
+ }
83
+ if (!ok)
84
+ continue;
85
+ if (!best || fixed > best.fixed)
86
+ best = { view, params, fixed };
87
+ }
88
+ if (!best)
89
+ return null;
90
+ query.forEach((v, k) => { if (best.params[k] == null)
91
+ best.params[k] = v; });
92
+ return { view: best.view, params: best.params };
93
+ }
94
+ /** The side menu: areas in declared order, and Settings for the bottom. Record views are left out. */
95
+ export function menu(views) {
96
+ return {
97
+ main: views.filter((v) => { var _a; return ((_a = v.group) !== null && _a !== void 0 ? _a : 'main') === 'main'; }),
98
+ settings: views.filter((v) => v.group === 'settings'),
99
+ };
100
+ }
101
+ /**
102
+ * The chain from a top-level area down to `id`: `['campaigns', 'campaign', 'campaign.results']`.
103
+ * The first entry is the menu item to show as current; for a record view, the record's first view
104
+ * is `chain[1]`.
105
+ */
106
+ export function trail(views, id) {
107
+ const byId = new Map(views.map((v) => [v.id, v]));
108
+ const out = [];
109
+ let cur = byId.get(id);
110
+ while (cur && !out.includes(cur)) {
111
+ out.unshift(cur);
112
+ cur = cur.within ? byId.get(cur.within) : undefined;
113
+ }
114
+ return out;
115
+ }
116
+ /**
117
+ * The swapped menu while one record is open: `back` is the area to return to ("← All campaigns"),
118
+ * `items` the record's first view followed by the views within it. Null when `id` isn't a record view.
119
+ */
120
+ export function recordMenu(views, id) {
121
+ const chain = trail(views, id);
122
+ const record = chain.find((v) => v.group === 'record');
123
+ if (!record)
124
+ return null;
125
+ const back = record.within ? views.find((v) => v.id === record.within) : undefined;
126
+ return { back, record, items: [record, ...views.filter((v) => v.within === record.id && v.group === 'record')] };
127
+ }
128
+ /**
129
+ * Resolve a host's request against the app's views: a named view becomes its path; a raw path is
130
+ * matched to a view where it can be. Null when the view is unknown, a required param is missing, or
131
+ * the path isn't a hash route of this app (`/…`, no scheme, no `//`).
132
+ */
133
+ export function resolve(views, req) {
134
+ const params = {};
135
+ for (const [k, v] of Object.entries(req.params || {}))
136
+ if (typeof v === 'string')
137
+ params[k] = v;
138
+ if (req.view) {
139
+ const view = views.find((v) => v.id === req.view);
140
+ if (!view)
141
+ return null;
142
+ const path = pathFor(view, params);
143
+ if (path == null)
144
+ return null;
145
+ return Object.assign({ path, view, params }, (req.highlight ? { highlight: req.highlight } : {}));
146
+ }
147
+ if (typeof req.path !== 'string' || !req.path.startsWith('/') || req.path.startsWith('//') || req.path.includes('://'))
148
+ return null;
149
+ let path = req.path;
150
+ if (Object.keys(params).length) {
151
+ const { pathname, query } = splitPath(path);
152
+ for (const [k, v] of Object.entries(params))
153
+ query.set(k, v);
154
+ path = `${pathname}?${query.toString()}`;
155
+ }
156
+ const m = match(views, path);
157
+ return Object.assign(Object.assign(Object.assign({ path }, (m ? { view: m.view } : {})), { params: m ? Object.assign(Object.assign({}, m.params), params) : params }), (req.highlight ? { highlight: req.highlight } : {}));
158
+ }
159
+ // -----------------------------------------------------------------------------
160
+ // App side
161
+ // -----------------------------------------------------------------------------
162
+ function inIframe() {
163
+ return typeof window !== 'undefined' && !!window.parent && window.parent !== window;
164
+ }
165
+ function postParent(type, payload) {
166
+ if (!inIframe())
167
+ return;
168
+ try {
169
+ window.parent.postMessage({ _smartlinksIframeMessage: true, type, payload }, '*');
170
+ }
171
+ catch (_a) {
172
+ /* ignore */
173
+ }
174
+ }
175
+ /** `chrome` as the page was first opened: read once, so the app's own navigation can't lose it. */
176
+ const INITIAL_CHROME = (() => {
177
+ try {
178
+ if (typeof window === 'undefined' || !window.location)
179
+ return 'full';
180
+ const hash = window.location.hash || '';
181
+ const q = hash.indexOf('?');
182
+ const fromHash = q >= 0 ? new URLSearchParams(hash.slice(q + 1)).get('chrome') : null;
183
+ const v = fromHash !== null && fromHash !== void 0 ? fromHash : new URLSearchParams(window.location.search || '').get('chrome');
184
+ return v === 'none' ? 'none' : 'full';
185
+ }
186
+ catch (_a) {
187
+ return 'full';
188
+ }
189
+ })();
190
+ /**
191
+ * `'none'` when the host opened this page with `chrome=none`: the host's own menu carries this app's
192
+ * views, so the app hides its side menu (and the bar with its toggle) and shows only the content.
193
+ * Read from the address the page was first opened at.
194
+ */
195
+ export function hostChrome() {
196
+ return INITIAL_CHROME;
197
+ }
198
+ /**
199
+ * Follow the host's `smartlinks:navigate`: the handler gets the resolved hash path and hands it to the
200
+ * app's router (no reload). Registering tells the host this page follows navigate, so it stops
201
+ * reloading the frame to change screens. Only messages from the parent window are taken. Returns a
202
+ * function that stops listening.
203
+ *
204
+ * @example
205
+ * // React Router, with the views from the app's own manifest
206
+ * import manifest from '../public/app.manifest.json'
207
+ * const navigate = useNavigate()
208
+ * useEffect(() => SL.adminViews.onNavigate(manifest.adminViews, (to) => navigate(to.path)), [navigate])
209
+ */
210
+ export function onNavigate(views, handler) {
211
+ if (typeof window === 'undefined' || !inIframe())
212
+ return () => { };
213
+ const list = Array.isArray(views) ? views : [];
214
+ const onMsg = (e) => {
215
+ var _a, _b, _c, _d, _e, _f;
216
+ if (e.source !== window.parent)
217
+ return;
218
+ const d = e.data;
219
+ if (!d || typeof d !== 'object' || d.type !== 'smartlinks:navigate')
220
+ return;
221
+ const req = { view: d.view, path: d.path, params: d.params, highlight: d.highlight };
222
+ const target = resolve(list, req);
223
+ if (!target) {
224
+ postParent('smartlinks:navigate-result', { ok: false, view: (_a = req.view) !== null && _a !== void 0 ? _a : null, path: (_b = req.path) !== null && _b !== void 0 ? _b : null, reason: req.view ? 'unknown-view-or-missing-param' : 'bad-path' });
225
+ return;
226
+ }
227
+ try {
228
+ handler(target);
229
+ postParent('smartlinks:navigate-result', { ok: true, view: (_d = (_c = target.view) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : null, path: target.path });
230
+ }
231
+ catch (_g) {
232
+ postParent('smartlinks:navigate-result', { ok: false, view: (_f = (_e = target.view) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : null, path: target.path, reason: 'handler-failed' });
233
+ }
234
+ };
235
+ window.addEventListener('message', onMsg);
236
+ postParent('smartlinks:navigable', { views: list.map((v) => v.id), chrome: INITIAL_CHROME });
237
+ return () => {
238
+ try {
239
+ window.removeEventListener('message', onMsg);
240
+ }
241
+ catch ( /* ignore */_a) { /* ignore */ }
242
+ };
243
+ }
244
+ /**
245
+ * Ask the host (Studio) to open ANOTHER app at one of its screens: a contact in the CRM, a booking in
246
+ * the booking app, a person's messages in Messages. The host reads that app's manifest `adminViews`,
247
+ * turns the view into its address and opens it, so it works whichever SDK the other app is on. Posts
248
+ * `{ type: 'smartlinks:open-app', payload: { appId, view?, params?, path? } }` to the parent. No-op
249
+ * outside a frame.
250
+ *
251
+ * @example
252
+ * SL.adminViews.openApp({ appId: 'crm', view: 'contact', params: { contactId } })
253
+ */
254
+ export function openApp(req) {
255
+ if (!req || typeof req.appId !== 'string' || !req.appId)
256
+ return;
257
+ postParent('smartlinks:open-app', Object.assign(Object.assign(Object.assign({ appId: req.appId }, (req.view ? { view: req.view } : {})), (req.params ? { params: req.params } : {})), (req.path ? { path: req.path } : {})));
258
+ }
259
+ // -----------------------------------------------------------------------------
260
+ // Host side
261
+ // -----------------------------------------------------------------------------
262
+ /**
263
+ * Ask an embedded app to open a screen. Post this only once the app has said it follows navigate
264
+ * (`smartlinks:navigable`); otherwise reload the frame at the new path as before.
265
+ */
266
+ export function postNavigate(target, req, targetOrigin = '*') {
267
+ if (!target)
268
+ return;
269
+ try {
270
+ target.postMessage(Object.assign({ type: 'smartlinks:navigate' }, req), targetOrigin);
271
+ }
272
+ catch (_a) {
273
+ /* ignore */
274
+ }
275
+ }
package/dist/api/ai.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { guide as guideApi, content as contentApi, startLive } from "./aiGuide.js";
1
2
  import type { ContentPart, FunctionCall, ToolCall, ChatMessage, ToolDefinition, ResponseTool, ResponseInputItem, ResponsesRequest, ResponsesResult, ResponsesStreamEvent, ChatCompletionRequest, ChatCompletionChoice, ChatCompletionResponse, ChatCompletionChunk, AIModel, AIModelListParams, AIModelListResponse, AgentRunRequest, AgentRunResult, AgentToolsQuery, AgentToolsResponse, ToolRunResult, AiToolName, AiToolArgsMap, PublicAgentRunRequest, ClientTool, RunWithClientToolsOptions, SkillsListResponse, CatalogResponse, DocumentChunk, IndexDocumentRequest, IndexDocumentResponse, ConfigureAssistantRequest, ConfigureAssistantResponse, PublicChatRequest, PublicChatResponse, Session, RateLimitStatus, SessionStatistics, AiSession, AiSessionCreate, AiUsageReport, VoiceSessionRequest, VoiceSessionResponse, EphemeralTokenRequest, EphemeralTokenResponse, TranscriptionResponse, TTSRequest, GeneratePodcastRequest, PodcastScript, GeneratePodcastResponse, PodcastStatus, AIGenerateContentRequest, AIGenerateContentCandidate, AIGenerateContentResponse, AIGenerateImageRequest, AIGenerateImageResponse, AIGeneratedImage, AISearchPhotosRequest, AISearchPhotosPhoto, AISearchPhotosResponse, AIUploadedFile, AICacheRef } from "../types/ai.js";
2
3
  export type { ContentPart, FunctionCall, ToolCall, ChatMessage, ToolDefinition, ResponseTool, ResponseInputItem, ResponsesRequest, ResponsesResult, ResponsesStreamEvent, ChatCompletionRequest, ChatCompletionChoice, ChatCompletionResponse, ChatCompletionChunk, AIModel, AIModelListParams, AIModelListResponse, DocumentChunk, IndexDocumentRequest, IndexDocumentResponse, ConfigureAssistantRequest, ConfigureAssistantResponse, PublicChatRequest, PublicChatResponse, Session, RateLimitStatus, SessionStatistics, AiSession, AiSessionCreate, AiUsageReport, VoiceSessionRequest, VoiceSessionResponse, EphemeralTokenRequest, EphemeralTokenResponse, TranscriptionResponse, TTSRequest, GeneratePodcastRequest, PodcastScript, GeneratePodcastResponse, PodcastStatus, AIGenerateContentRequest, AIGenerateContentCandidate, AIGenerateContentResponse, AIGenerateImageRequest, AIGenerateImageResponse, AIGeneratedImage, AISearchPhotosRequest, AISearchPhotosPhoto, AISearchPhotosResponse, AIUploadedFile, AICacheRef, };
3
4
  declare namespace aiInternal {
@@ -197,10 +198,6 @@ declare namespace aiInternal {
197
198
  * Check rate limit status
198
199
  */
199
200
  function getRateLimit(collectionId: string, userId: string): Promise<RateLimitStatus>;
200
- /**
201
- * Generate ephemeral token for Gemini Live
202
- */
203
- function getToken(collectionId: string, request: EphemeralTokenRequest): Promise<EphemeralTokenResponse>;
204
201
  }
205
202
  namespace voice {
206
203
  /**
@@ -294,13 +291,26 @@ export declare const ai: {
294
291
  getSession: typeof aiInternal.publicClient.getSession;
295
292
  clearSession: typeof aiInternal.publicClient.clearSession;
296
293
  getRateLimit: typeof aiInternal.publicClient.getRateLimit;
297
- getToken: typeof aiInternal.publicClient.getToken;
298
294
  };
299
295
  voice: {
300
296
  isSupported: typeof aiInternal.voice.isSupported;
301
297
  listen: typeof aiInternal.voice.listen;
302
298
  speak: typeof aiInternal.voice.speak;
303
299
  };
300
+ /** The customer guide: a business's assistant for its visitors (docs/customer-guide.md). */
301
+ guide: {
302
+ get: typeof guideApi.get;
303
+ start: typeof guideApi.start;
304
+ };
305
+ /** What's on screen, in words, for an assistant: apps provide it, hosts request it. */
306
+ content: {
307
+ provide: typeof contentApi.provide;
308
+ request: typeof contentApi.request;
309
+ };
310
+ /** A live conversation by voice or text, with your own endpoints (the guide and the Studio assistant use it). */
311
+ live: {
312
+ start: typeof startLive;
313
+ };
304
314
  agent: {
305
315
  run: typeof aiInternal.agent.run;
306
316
  listTools: typeof aiInternal.agent.listTools;
package/dist/api/ai.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/api/ai.ts
2
2
  // AI endpoints: public and admin helpers
3
3
  import { post, request, del, requestStream } from "../http.js";
4
+ import { guide as guideApi, content as contentApi, startLive } from "./aiGuide.js";
4
5
  function encodeQueryParams(params) {
5
6
  if (!params)
6
7
  return '';
@@ -375,14 +376,6 @@ var aiInternal;
375
376
  return request(path);
376
377
  }
377
378
  publicClient.getRateLimit = getRateLimit;
378
- /**
379
- * Generate ephemeral token for Gemini Live
380
- */
381
- async function getToken(collectionId, request) {
382
- const path = `/public/collection/${encodeURIComponent(collectionId)}/ai/token`;
383
- return post(path, request);
384
- }
385
- publicClient.getToken = getToken;
386
379
  })(publicClient = aiInternal.publicClient || (aiInternal.publicClient = {}));
387
380
  // ============================================================================
388
381
  // Voice Helpers (Browser-only)
@@ -578,13 +571,26 @@ export const ai = {
578
571
  getSession: aiInternal.publicClient.getSession,
579
572
  clearSession: aiInternal.publicClient.clearSession,
580
573
  getRateLimit: aiInternal.publicClient.getRateLimit,
581
- getToken: aiInternal.publicClient.getToken,
582
574
  },
583
575
  voice: {
584
576
  isSupported: aiInternal.voice.isSupported,
585
577
  listen: aiInternal.voice.listen,
586
578
  speak: aiInternal.voice.speak,
587
579
  },
580
+ /** The customer guide: a business's assistant for its visitors (docs/customer-guide.md). */
581
+ guide: {
582
+ get: guideApi.get,
583
+ start: guideApi.start,
584
+ },
585
+ /** What's on screen, in words, for an assistant: apps provide it, hosts request it. */
586
+ content: {
587
+ provide: contentApi.provide,
588
+ request: contentApi.request,
589
+ },
590
+ /** A live conversation by voice or text, with your own endpoints (the guide and the Studio assistant use it). */
591
+ live: {
592
+ start: startLive,
593
+ },
588
594
  agent: {
589
595
  run: aiInternal.agent.run,
590
596
  listTools: aiInternal.agent.listTools,
@@ -0,0 +1,108 @@
1
+ import { startLive, type LiveHandle, type LiveOptions, type LiveState, type LiveToolHandler, type LiveMintReply, type LiveEvent } from '../live.js';
2
+ export type GuideSurface = 'portal' | 'hub';
3
+ /** What a page may know about a business's guide before starting one. */
4
+ export interface GuideInfo {
5
+ enabled: boolean;
6
+ name?: string;
7
+ modes?: {
8
+ voice: boolean;
9
+ text: boolean;
10
+ start: 'voice' | 'text';
11
+ };
12
+ suggestions?: string[];
13
+ handoff?: {
14
+ kind: 'email' | 'phone' | 'url';
15
+ value: string;
16
+ } | null;
17
+ }
18
+ /** What is on the visitor's screen, in words. */
19
+ export interface ScreenContent {
20
+ appId?: string | null;
21
+ title?: string | null;
22
+ content?: string | null;
23
+ }
24
+ /** Where the visitor is: the app on screen and the page in it (as the host's deep link). */
25
+ export interface GuideWhere {
26
+ appId?: string | null;
27
+ path?: string | null;
28
+ params?: Record<string, string>;
29
+ }
30
+ /** A page the guide opened (the host moves the app there). */
31
+ export interface GuideNavigate {
32
+ appId: string;
33
+ path: string;
34
+ params?: Record<string, string>;
35
+ }
36
+ /** Products the guide found, for the screen: each row can take the visitor there. */
37
+ export interface GuideCard {
38
+ title: string;
39
+ rows: Array<{
40
+ title: string;
41
+ detail?: string | null;
42
+ goTo?: string;
43
+ }>;
44
+ more?: number;
45
+ }
46
+ export interface GuideStartOptions {
47
+ surface: GuideSurface;
48
+ mode?: 'voice' | 'text';
49
+ productId?: string | null;
50
+ proofId?: string | null;
51
+ /** The apps on the visitor's page: the guide reads their pages and may open them. A core app says so. */
52
+ apps?: Array<{
53
+ id: string;
54
+ title: string;
55
+ kind?: 'core' | 'app';
56
+ channel?: string;
57
+ }>;
58
+ /** Where the visitor is when the conversation starts. Later, tell it with handle.note(). */
59
+ where?: GuideWhere;
60
+ /** The visitor's language (e.g. 'fr'); default: theirs as the browser says. */
61
+ language?: string;
62
+ /** What's on screen when the conversation starts. Later, the guide asks with read_screen. */
63
+ screen?: ScreenContent;
64
+ /** Read the screen now (the guide's read_screen tool). Default: ask the app on screen (ai.content.request). */
65
+ readScreen?: () => Promise<ScreenContent | null> | ScreenContent | null;
66
+ /** Open one of the business's apps at its start (the guide's show_app tool). */
67
+ showApp?: (appId: string) => Promise<void> | void;
68
+ /** Open a page of an app (the guide's open_page tool: SmartLinks resolves the page's address). */
69
+ openPage?: (to: GuideNavigate) => Promise<void> | void;
70
+ /** Go to another product's page (the guide's go_to tool). */
71
+ goTo?: (productId: string) => Promise<void> | void;
72
+ /** Products the guide found, to show (each row can call goTo). */
73
+ onShow?: (card: GuideCard) => void;
74
+ /** Show how to reach a person (the guide's offer_person tool). */
75
+ offerPerson?: (handoff: GuideInfo['handoff']) => Promise<void> | void;
76
+ onState?: (s: LiveState) => void;
77
+ onCaption?: (text: string) => void;
78
+ onReply?: (text: string) => void;
79
+ onError?: (message: string) => void;
80
+ }
81
+ export declare namespace guide {
82
+ /** Is the guide on for this surface, and how does it present itself? */
83
+ function get(collectionId: string, surface?: GuideSurface): Promise<GuideInfo>;
84
+ /** Start a live conversation with the guide. Resolves once connected; the handle pauses, stops, sends text. */
85
+ function start(collectionId: string, options: GuideStartOptions): Promise<LiveHandle>;
86
+ }
87
+ type ContentHandler = (ctx: {
88
+ reason?: string;
89
+ }) => Promise<ScreenContent | null> | ScreenContent | null;
90
+ export declare namespace content {
91
+ /**
92
+ * An app says what its screen shows, in words (an exhibit's text, a recipe, a form's purpose). Called
93
+ * whenever an assistant needs it. Works in an iframe (the host asks by message) and in the same page
94
+ * (a direct component). Returns a function that stops providing.
95
+ */
96
+ function provide(handler: ContentHandler): () => void;
97
+ /**
98
+ * A host asks what the app on screen shows: an app in an iframe (pass its window as `frame`), or apps in
99
+ * this page that called `provide`. Resolves null if nothing answers within the time.
100
+ */
101
+ function request(options?: {
102
+ frame?: Window | null;
103
+ reason?: string;
104
+ timeoutMs?: number;
105
+ }): Promise<ScreenContent | null>;
106
+ }
107
+ export { startLive };
108
+ export type { LiveHandle, LiveState, LiveOptions, LiveToolHandler, LiveMintReply, LiveEvent };