@firststep-studio/sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +268 -3
- package/dist/index.d.ts +268 -3
- package/dist/index.js +93 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -3
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +8 -4
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +9 -5
- package/dist/server.mjs.map +1 -1
- package/dist/{types-Bm98aHcd.d.mts → types-B71xClvf.d.mts} +65 -1
- package/dist/{types-Bm98aHcd.d.ts → types-B71xClvf.d.ts} +65 -1
- package/llms.txt +464 -39
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ChatMessage } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { C as ChatMessage, S as SchemaDeclarationPayload, P as ProtocolStreamChunk, A as AgentTransitionPayload, R as RoutingClassificationPayload } from './types-B71xClvf.mjs';
|
|
2
|
+
export { y as AnalyticsContext, t as ChatbotInfo, u as ClassifierConfig, D as DeploymentInfo, F as FormData, G as FormFieldDefinition, J as FormFieldType, v as FormFieldValue, E as FormSchema, H as HandlerInfo, r as Helpline, q as HelplineResult, p as HelplineSearchOptions, I as IntegrationContext, o as IntegrationResult, z as InteractionEvent, B as InteractionEventType, K as KnowledgeContext, n as KnowledgeResult, L as LoggerContext, j as ProtocolCapabilities, k as ProtocolContext, h as ProtocolError, g as ProtocolFieldValidation, d as ProtocolForm, e as ProtocolFormField, f as ProtocolFormOption, i as ProtocolHandler, M as ProtocolRegistration, a as ProtocolRequest, b as ProtocolResponse, s as RoutingDecision, w as RoutingLog, N as SchemaAgent, O as SchemaQuestion, l as SessionContext, x as SessionMetadata, m as SessionState, c as SessionStatus } from './types-B71xClvf.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* UCP (Universal Classification Protocol) Types
|
|
@@ -235,12 +235,277 @@ declare function classifyWithUCP(endpoint: string, messages: ChatMessage[], opti
|
|
|
235
235
|
timeout?: number;
|
|
236
236
|
}): Promise<ClassificationResult>;
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Render Markers
|
|
240
|
+
*
|
|
241
|
+
* Utilities for building render markers that FirstStep Studio's frontend
|
|
242
|
+
* can parse and display as rich UI components (cards, alerts, forms, etc.).
|
|
243
|
+
*
|
|
244
|
+
* This module is the single source of truth for render marker specs.
|
|
245
|
+
* - Handlers (producers) use the builder functions to emit markers
|
|
246
|
+
* - Studio frontend (consumer) uses the types and MARKER_TYPES constants to parse them
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* import { renderMarkers } from '@firststep-studio/sdk';
|
|
251
|
+
*
|
|
252
|
+
* // In your handleStream():
|
|
253
|
+
* yield {
|
|
254
|
+
* type: 'text',
|
|
255
|
+
* content: renderMarkers.helplineCard({
|
|
256
|
+
* helplines: [{ name: '988 Lifeline', phoneNumber: '988', categories: ['crisis'], status: 'open', statusLabel: 'Available' }],
|
|
257
|
+
* }),
|
|
258
|
+
* };
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare const MARKER_TYPES: {
|
|
262
|
+
readonly HELPLINE_CARD: "RENDER_HELPLINE_CARD";
|
|
263
|
+
readonly EMERGENCY: "RENDER_EMERGENCY";
|
|
264
|
+
readonly RESOURCE_CARD: "RENDER_RESOURCE_CARD";
|
|
265
|
+
readonly PROVIDER_CARD: "RENDER_PROVIDER_CARD";
|
|
266
|
+
readonly SAFETY_PLAN: "RENDER_SAFETY_PLAN";
|
|
267
|
+
readonly REPORT_CARD: "RENDER_REPORT_CARD";
|
|
268
|
+
};
|
|
269
|
+
type MarkerType = typeof MARKER_TYPES[keyof typeof MARKER_TYPES];
|
|
270
|
+
/**
|
|
271
|
+
* Helpline card payload.
|
|
272
|
+
* Renders a carousel of helpline cards with contact buttons (call, text, chat, WhatsApp).
|
|
273
|
+
*/
|
|
274
|
+
interface HelplineCardPayload {
|
|
275
|
+
helplines: HelplineCardItem[];
|
|
276
|
+
type?: 'throughline' | 'throughline_fallback' | 'stage';
|
|
277
|
+
fallback?: {
|
|
278
|
+
message: string;
|
|
279
|
+
linkText?: string;
|
|
280
|
+
linkUrl?: string;
|
|
281
|
+
icon?: string;
|
|
282
|
+
topic?: string;
|
|
283
|
+
topics?: string[];
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
interface HelplineCardItem {
|
|
287
|
+
name: string;
|
|
288
|
+
description?: string;
|
|
289
|
+
categories: string[];
|
|
290
|
+
status: 'open' | 'closed';
|
|
291
|
+
statusLabel: string;
|
|
292
|
+
statusBadge?: string;
|
|
293
|
+
hoursText?: string;
|
|
294
|
+
supportTypes?: string;
|
|
295
|
+
smsNumber?: string;
|
|
296
|
+
phoneNumber?: string;
|
|
297
|
+
website?: string;
|
|
298
|
+
webchat?: string;
|
|
299
|
+
whatsapp?: string;
|
|
300
|
+
specialties?: string[];
|
|
301
|
+
highlightedTag?: string;
|
|
302
|
+
verified?: boolean;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Emergency number payload.
|
|
306
|
+
* Renders a prominent alert card with a large call button.
|
|
307
|
+
*/
|
|
308
|
+
interface EmergencyPayload {
|
|
309
|
+
number: string;
|
|
310
|
+
countryName?: string;
|
|
311
|
+
countryCode?: string;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Resource card payload.
|
|
315
|
+
* Renders a carousel of resource cards with video thumbnails, tags, and visit buttons.
|
|
316
|
+
*/
|
|
317
|
+
interface ResourceCardPayload {
|
|
318
|
+
resources: ResourceCardItem[];
|
|
319
|
+
}
|
|
320
|
+
interface ResourceCardItem {
|
|
321
|
+
name: string;
|
|
322
|
+
url?: string;
|
|
323
|
+
description?: string;
|
|
324
|
+
video_url?: string;
|
|
325
|
+
type?: string;
|
|
326
|
+
tags?: string[];
|
|
327
|
+
highlightedTag?: string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Provider card payload.
|
|
331
|
+
* Renders a carousel of provider directory cards with specialty/language tags and contact info.
|
|
332
|
+
*/
|
|
333
|
+
interface ProviderCardPayload {
|
|
334
|
+
providers: ProviderCardItem[];
|
|
335
|
+
}
|
|
336
|
+
interface ProviderCardItem {
|
|
337
|
+
id: string;
|
|
338
|
+
name: string;
|
|
339
|
+
type?: string;
|
|
340
|
+
specialty: string[];
|
|
341
|
+
language: string[];
|
|
342
|
+
description?: string;
|
|
343
|
+
location?: string;
|
|
344
|
+
open_hours?: string;
|
|
345
|
+
contact_phone?: string;
|
|
346
|
+
contact_email?: string;
|
|
347
|
+
address?: string;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Safety plan payload.
|
|
351
|
+
* Renders a multi-section table with expandable sections and save/export actions.
|
|
352
|
+
*/
|
|
353
|
+
interface SafetyPlanPayload {
|
|
354
|
+
sections: SafetyPlanSection[];
|
|
355
|
+
helplines?: Array<{
|
|
356
|
+
name: string;
|
|
357
|
+
phone?: string;
|
|
358
|
+
}>;
|
|
359
|
+
actions?: {
|
|
360
|
+
savePng?: boolean;
|
|
361
|
+
saveTxt?: boolean;
|
|
362
|
+
copy?: boolean;
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
interface SafetyPlanSection {
|
|
366
|
+
id: string;
|
|
367
|
+
title: string;
|
|
368
|
+
items: Array<string | {
|
|
369
|
+
name: string;
|
|
370
|
+
phone?: string;
|
|
371
|
+
description?: string;
|
|
372
|
+
}>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Report card payload.
|
|
376
|
+
* Renders a summary card of collected report data with a submit button.
|
|
377
|
+
*/
|
|
378
|
+
interface ReportCardPayload {
|
|
379
|
+
topic: string;
|
|
380
|
+
location?: string;
|
|
381
|
+
description?: string;
|
|
382
|
+
perpetrator_known?: boolean;
|
|
383
|
+
contact_mode?: string;
|
|
384
|
+
contact_value?: string;
|
|
385
|
+
submitEndpoint?: string;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Render marker builder functions.
|
|
389
|
+
*
|
|
390
|
+
* Each function takes a typed payload and returns a render marker string
|
|
391
|
+
* that can be yielded as a `text` chunk in handleStream().
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* // Emit helpline cards
|
|
396
|
+
* yield { type: 'text', content: renderMarkers.helplineCard({ helplines: [...] }) };
|
|
397
|
+
*
|
|
398
|
+
* // Emit emergency number
|
|
399
|
+
* yield { type: 'text', content: renderMarkers.emergency({ number: '911', countryName: 'United States' }) };
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
declare const renderMarkers: {
|
|
403
|
+
/** Build a helpline card carousel marker */
|
|
404
|
+
helplineCard: (payload: HelplineCardPayload) => string;
|
|
405
|
+
/** Build an emergency number alert marker */
|
|
406
|
+
emergency: (payload: EmergencyPayload) => string;
|
|
407
|
+
/** Build a resource card carousel marker */
|
|
408
|
+
resourceCard: (payload: ResourceCardPayload) => string;
|
|
409
|
+
/** Build a provider card carousel marker */
|
|
410
|
+
providerCard: (payload: ProviderCardPayload) => string;
|
|
411
|
+
/** Build a safety plan artifact marker */
|
|
412
|
+
safetyPlan: (payload: SafetyPlanPayload) => string;
|
|
413
|
+
/** Build a report draft card marker */
|
|
414
|
+
reportCard: (payload: ReportCardPayload) => string;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Stream Metadata Builders
|
|
419
|
+
*
|
|
420
|
+
* Utilities for building typed metadata stream chunks that FirstStep Studio's
|
|
421
|
+
* proxy persists to MongoDB for Dashboard features (Form Insights, Session
|
|
422
|
+
* History, Routing Logs, Agent Transitions).
|
|
423
|
+
*
|
|
424
|
+
* Each function returns a ready-to-yield ProtocolStreamChunk. No need to
|
|
425
|
+
* construct the `{ type, content }` wrapper manually.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* import { streamMetadata } from '@firststep-studio/sdk';
|
|
430
|
+
*
|
|
431
|
+
* // In your handleStream():
|
|
432
|
+
*
|
|
433
|
+
* // 1. Welcome path: declare your schema once
|
|
434
|
+
* yield streamMetadata.declareSchema({
|
|
435
|
+
* agents: [{ id: 'intake', title: 'Intake', order: 0 }],
|
|
436
|
+
* questions: [{ id: 'name', agentId: 'intake', title: 'Name', type: 'text' }],
|
|
437
|
+
* });
|
|
438
|
+
*
|
|
439
|
+
* // 2. After each turn: send collected field values
|
|
440
|
+
* yield streamMetadata.formDataUpdate({ name: 'Alice', age: '28' });
|
|
441
|
+
*
|
|
442
|
+
* // 3. On stage change: signal an agent transition
|
|
443
|
+
* yield streamMetadata.agentTransition({ id: 'support', title: 'Support' });
|
|
444
|
+
*
|
|
445
|
+
* // 4. On classification: send routing result
|
|
446
|
+
* yield streamMetadata.routingResult({
|
|
447
|
+
* decision: 'classified',
|
|
448
|
+
* reason: 'User mentioned self-harm',
|
|
449
|
+
* category: 'crisis',
|
|
450
|
+
* level: 'high',
|
|
451
|
+
* score: 92,
|
|
452
|
+
* });
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
|
|
456
|
+
declare const streamMetadata: {
|
|
457
|
+
/**
|
|
458
|
+
* Declare the form schema (agents + questions) for Dashboard Form Insights.
|
|
459
|
+
*
|
|
460
|
+
* Yield this once during session initialization (welcome message).
|
|
461
|
+
* The Studio proxy stores it in `chatbot.externalSchema` so that
|
|
462
|
+
* Dashboard Form Insights can display question-level analytics.
|
|
463
|
+
*
|
|
464
|
+
* @param schema - Agents and questions your handler uses
|
|
465
|
+
* @returns A metadata stream chunk ready to yield or queue.push
|
|
466
|
+
*/
|
|
467
|
+
declareSchema(schema: SchemaDeclarationPayload): ProtocolStreamChunk;
|
|
468
|
+
/**
|
|
469
|
+
* Send collected form field values for Dashboard persistence.
|
|
470
|
+
*
|
|
471
|
+
* Call this after each turn when new fields are captured.
|
|
472
|
+
* Values are incrementally merged into `ChatSession.formData`.
|
|
473
|
+
*
|
|
474
|
+
* @param fields - Key-value pairs of field IDs to their collected values
|
|
475
|
+
* @returns A metadata stream chunk ready to yield or queue.push
|
|
476
|
+
*/
|
|
477
|
+
formDataUpdate(fields: Record<string, string | number>): ProtocolStreamChunk;
|
|
478
|
+
/**
|
|
479
|
+
* Signal an agent/stage transition for routing logs.
|
|
480
|
+
*
|
|
481
|
+
* The Studio proxy records this in `ChatSession.routingLogs` so
|
|
482
|
+
* the Dashboard can show the conversation's agent flow.
|
|
483
|
+
*
|
|
484
|
+
* @param agent - The agent/stage being transitioned to
|
|
485
|
+
* @returns A metadata stream chunk ready to yield or queue.push
|
|
486
|
+
*/
|
|
487
|
+
agentTransition(agent: AgentTransitionPayload): ProtocolStreamChunk;
|
|
488
|
+
/**
|
|
489
|
+
* Send a routing/classification result for routing logs.
|
|
490
|
+
*
|
|
491
|
+
* The Studio proxy records this in `ChatSession.routingLogs` as a
|
|
492
|
+
* classification event with category, level, and confidence score.
|
|
493
|
+
*
|
|
494
|
+
* @param result - Classification/routing decision details
|
|
495
|
+
* @returns A metadata stream chunk ready to yield or queue.push
|
|
496
|
+
*/
|
|
497
|
+
routingResult(result: RoutingClassificationPayload): ProtocolStreamChunk;
|
|
498
|
+
};
|
|
499
|
+
|
|
238
500
|
/**
|
|
239
501
|
* Verify an HMAC-SHA256 request signature.
|
|
240
502
|
*
|
|
241
503
|
* The handler server can use this to verify that incoming webhook
|
|
242
504
|
* requests were signed by the FirstStep platform using the shared token.
|
|
243
505
|
*
|
|
506
|
+
* The HMAC key is SHA-256(token), matching the backend which only stores
|
|
507
|
+
* the token hash and uses it directly as the HMAC key.
|
|
508
|
+
*
|
|
244
509
|
* @param token - The API token (FIRSTSTEP_TOKEN)
|
|
245
510
|
* @param payload - The raw request body string
|
|
246
511
|
* @param signature - The signature from the X-FirstStep-Signature header
|
|
@@ -296,4 +561,4 @@ declare function createAuthHeader(token: string): string;
|
|
|
296
561
|
*/
|
|
297
562
|
declare function isValidToken(token: string): boolean;
|
|
298
563
|
|
|
299
|
-
export { ChatMessage, type ClassificationResult, type UCPClassifyRequest, type UCPClassifyResponse, UCPClient, type UCPClientConfig, type UCPEndpointConfig, UCPError, type UCPErrorResponse, type UCPInfoResponse, type UCPMessage, classifyWithUCP, createAuthHeader, createRequestSignature, createUCPClient, isValidToken, verifyRequestSignature };
|
|
564
|
+
export { AgentTransitionPayload, ChatMessage, type ClassificationResult, type EmergencyPayload, type HelplineCardItem, type HelplineCardPayload, MARKER_TYPES, type MarkerType, ProtocolStreamChunk, type ProviderCardItem, type ProviderCardPayload, type ReportCardPayload, type ResourceCardItem, type ResourceCardPayload, RoutingClassificationPayload, type SafetyPlanPayload, type SafetyPlanSection, SchemaDeclarationPayload, type UCPClassifyRequest, type UCPClassifyResponse, UCPClient, type UCPClientConfig, type UCPEndpointConfig, UCPError, type UCPErrorResponse, type UCPInfoResponse, type UCPMessage, classifyWithUCP, createAuthHeader, createRequestSignature, createUCPClient, isValidToken, renderMarkers, streamMetadata, verifyRequestSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ChatMessage } from './types-
|
|
2
|
-
export {
|
|
1
|
+
import { C as ChatMessage, S as SchemaDeclarationPayload, P as ProtocolStreamChunk, A as AgentTransitionPayload, R as RoutingClassificationPayload } from './types-B71xClvf.js';
|
|
2
|
+
export { y as AnalyticsContext, t as ChatbotInfo, u as ClassifierConfig, D as DeploymentInfo, F as FormData, G as FormFieldDefinition, J as FormFieldType, v as FormFieldValue, E as FormSchema, H as HandlerInfo, r as Helpline, q as HelplineResult, p as HelplineSearchOptions, I as IntegrationContext, o as IntegrationResult, z as InteractionEvent, B as InteractionEventType, K as KnowledgeContext, n as KnowledgeResult, L as LoggerContext, j as ProtocolCapabilities, k as ProtocolContext, h as ProtocolError, g as ProtocolFieldValidation, d as ProtocolForm, e as ProtocolFormField, f as ProtocolFormOption, i as ProtocolHandler, M as ProtocolRegistration, a as ProtocolRequest, b as ProtocolResponse, s as RoutingDecision, w as RoutingLog, N as SchemaAgent, O as SchemaQuestion, l as SessionContext, x as SessionMetadata, m as SessionState, c as SessionStatus } from './types-B71xClvf.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* UCP (Universal Classification Protocol) Types
|
|
@@ -235,12 +235,277 @@ declare function classifyWithUCP(endpoint: string, messages: ChatMessage[], opti
|
|
|
235
235
|
timeout?: number;
|
|
236
236
|
}): Promise<ClassificationResult>;
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Render Markers
|
|
240
|
+
*
|
|
241
|
+
* Utilities for building render markers that FirstStep Studio's frontend
|
|
242
|
+
* can parse and display as rich UI components (cards, alerts, forms, etc.).
|
|
243
|
+
*
|
|
244
|
+
* This module is the single source of truth for render marker specs.
|
|
245
|
+
* - Handlers (producers) use the builder functions to emit markers
|
|
246
|
+
* - Studio frontend (consumer) uses the types and MARKER_TYPES constants to parse them
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* import { renderMarkers } from '@firststep-studio/sdk';
|
|
251
|
+
*
|
|
252
|
+
* // In your handleStream():
|
|
253
|
+
* yield {
|
|
254
|
+
* type: 'text',
|
|
255
|
+
* content: renderMarkers.helplineCard({
|
|
256
|
+
* helplines: [{ name: '988 Lifeline', phoneNumber: '988', categories: ['crisis'], status: 'open', statusLabel: 'Available' }],
|
|
257
|
+
* }),
|
|
258
|
+
* };
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare const MARKER_TYPES: {
|
|
262
|
+
readonly HELPLINE_CARD: "RENDER_HELPLINE_CARD";
|
|
263
|
+
readonly EMERGENCY: "RENDER_EMERGENCY";
|
|
264
|
+
readonly RESOURCE_CARD: "RENDER_RESOURCE_CARD";
|
|
265
|
+
readonly PROVIDER_CARD: "RENDER_PROVIDER_CARD";
|
|
266
|
+
readonly SAFETY_PLAN: "RENDER_SAFETY_PLAN";
|
|
267
|
+
readonly REPORT_CARD: "RENDER_REPORT_CARD";
|
|
268
|
+
};
|
|
269
|
+
type MarkerType = typeof MARKER_TYPES[keyof typeof MARKER_TYPES];
|
|
270
|
+
/**
|
|
271
|
+
* Helpline card payload.
|
|
272
|
+
* Renders a carousel of helpline cards with contact buttons (call, text, chat, WhatsApp).
|
|
273
|
+
*/
|
|
274
|
+
interface HelplineCardPayload {
|
|
275
|
+
helplines: HelplineCardItem[];
|
|
276
|
+
type?: 'throughline' | 'throughline_fallback' | 'stage';
|
|
277
|
+
fallback?: {
|
|
278
|
+
message: string;
|
|
279
|
+
linkText?: string;
|
|
280
|
+
linkUrl?: string;
|
|
281
|
+
icon?: string;
|
|
282
|
+
topic?: string;
|
|
283
|
+
topics?: string[];
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
interface HelplineCardItem {
|
|
287
|
+
name: string;
|
|
288
|
+
description?: string;
|
|
289
|
+
categories: string[];
|
|
290
|
+
status: 'open' | 'closed';
|
|
291
|
+
statusLabel: string;
|
|
292
|
+
statusBadge?: string;
|
|
293
|
+
hoursText?: string;
|
|
294
|
+
supportTypes?: string;
|
|
295
|
+
smsNumber?: string;
|
|
296
|
+
phoneNumber?: string;
|
|
297
|
+
website?: string;
|
|
298
|
+
webchat?: string;
|
|
299
|
+
whatsapp?: string;
|
|
300
|
+
specialties?: string[];
|
|
301
|
+
highlightedTag?: string;
|
|
302
|
+
verified?: boolean;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Emergency number payload.
|
|
306
|
+
* Renders a prominent alert card with a large call button.
|
|
307
|
+
*/
|
|
308
|
+
interface EmergencyPayload {
|
|
309
|
+
number: string;
|
|
310
|
+
countryName?: string;
|
|
311
|
+
countryCode?: string;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Resource card payload.
|
|
315
|
+
* Renders a carousel of resource cards with video thumbnails, tags, and visit buttons.
|
|
316
|
+
*/
|
|
317
|
+
interface ResourceCardPayload {
|
|
318
|
+
resources: ResourceCardItem[];
|
|
319
|
+
}
|
|
320
|
+
interface ResourceCardItem {
|
|
321
|
+
name: string;
|
|
322
|
+
url?: string;
|
|
323
|
+
description?: string;
|
|
324
|
+
video_url?: string;
|
|
325
|
+
type?: string;
|
|
326
|
+
tags?: string[];
|
|
327
|
+
highlightedTag?: string;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Provider card payload.
|
|
331
|
+
* Renders a carousel of provider directory cards with specialty/language tags and contact info.
|
|
332
|
+
*/
|
|
333
|
+
interface ProviderCardPayload {
|
|
334
|
+
providers: ProviderCardItem[];
|
|
335
|
+
}
|
|
336
|
+
interface ProviderCardItem {
|
|
337
|
+
id: string;
|
|
338
|
+
name: string;
|
|
339
|
+
type?: string;
|
|
340
|
+
specialty: string[];
|
|
341
|
+
language: string[];
|
|
342
|
+
description?: string;
|
|
343
|
+
location?: string;
|
|
344
|
+
open_hours?: string;
|
|
345
|
+
contact_phone?: string;
|
|
346
|
+
contact_email?: string;
|
|
347
|
+
address?: string;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Safety plan payload.
|
|
351
|
+
* Renders a multi-section table with expandable sections and save/export actions.
|
|
352
|
+
*/
|
|
353
|
+
interface SafetyPlanPayload {
|
|
354
|
+
sections: SafetyPlanSection[];
|
|
355
|
+
helplines?: Array<{
|
|
356
|
+
name: string;
|
|
357
|
+
phone?: string;
|
|
358
|
+
}>;
|
|
359
|
+
actions?: {
|
|
360
|
+
savePng?: boolean;
|
|
361
|
+
saveTxt?: boolean;
|
|
362
|
+
copy?: boolean;
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
interface SafetyPlanSection {
|
|
366
|
+
id: string;
|
|
367
|
+
title: string;
|
|
368
|
+
items: Array<string | {
|
|
369
|
+
name: string;
|
|
370
|
+
phone?: string;
|
|
371
|
+
description?: string;
|
|
372
|
+
}>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Report card payload.
|
|
376
|
+
* Renders a summary card of collected report data with a submit button.
|
|
377
|
+
*/
|
|
378
|
+
interface ReportCardPayload {
|
|
379
|
+
topic: string;
|
|
380
|
+
location?: string;
|
|
381
|
+
description?: string;
|
|
382
|
+
perpetrator_known?: boolean;
|
|
383
|
+
contact_mode?: string;
|
|
384
|
+
contact_value?: string;
|
|
385
|
+
submitEndpoint?: string;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Render marker builder functions.
|
|
389
|
+
*
|
|
390
|
+
* Each function takes a typed payload and returns a render marker string
|
|
391
|
+
* that can be yielded as a `text` chunk in handleStream().
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* // Emit helpline cards
|
|
396
|
+
* yield { type: 'text', content: renderMarkers.helplineCard({ helplines: [...] }) };
|
|
397
|
+
*
|
|
398
|
+
* // Emit emergency number
|
|
399
|
+
* yield { type: 'text', content: renderMarkers.emergency({ number: '911', countryName: 'United States' }) };
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
declare const renderMarkers: {
|
|
403
|
+
/** Build a helpline card carousel marker */
|
|
404
|
+
helplineCard: (payload: HelplineCardPayload) => string;
|
|
405
|
+
/** Build an emergency number alert marker */
|
|
406
|
+
emergency: (payload: EmergencyPayload) => string;
|
|
407
|
+
/** Build a resource card carousel marker */
|
|
408
|
+
resourceCard: (payload: ResourceCardPayload) => string;
|
|
409
|
+
/** Build a provider card carousel marker */
|
|
410
|
+
providerCard: (payload: ProviderCardPayload) => string;
|
|
411
|
+
/** Build a safety plan artifact marker */
|
|
412
|
+
safetyPlan: (payload: SafetyPlanPayload) => string;
|
|
413
|
+
/** Build a report draft card marker */
|
|
414
|
+
reportCard: (payload: ReportCardPayload) => string;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Stream Metadata Builders
|
|
419
|
+
*
|
|
420
|
+
* Utilities for building typed metadata stream chunks that FirstStep Studio's
|
|
421
|
+
* proxy persists to MongoDB for Dashboard features (Form Insights, Session
|
|
422
|
+
* History, Routing Logs, Agent Transitions).
|
|
423
|
+
*
|
|
424
|
+
* Each function returns a ready-to-yield ProtocolStreamChunk. No need to
|
|
425
|
+
* construct the `{ type, content }` wrapper manually.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* import { streamMetadata } from '@firststep-studio/sdk';
|
|
430
|
+
*
|
|
431
|
+
* // In your handleStream():
|
|
432
|
+
*
|
|
433
|
+
* // 1. Welcome path: declare your schema once
|
|
434
|
+
* yield streamMetadata.declareSchema({
|
|
435
|
+
* agents: [{ id: 'intake', title: 'Intake', order: 0 }],
|
|
436
|
+
* questions: [{ id: 'name', agentId: 'intake', title: 'Name', type: 'text' }],
|
|
437
|
+
* });
|
|
438
|
+
*
|
|
439
|
+
* // 2. After each turn: send collected field values
|
|
440
|
+
* yield streamMetadata.formDataUpdate({ name: 'Alice', age: '28' });
|
|
441
|
+
*
|
|
442
|
+
* // 3. On stage change: signal an agent transition
|
|
443
|
+
* yield streamMetadata.agentTransition({ id: 'support', title: 'Support' });
|
|
444
|
+
*
|
|
445
|
+
* // 4. On classification: send routing result
|
|
446
|
+
* yield streamMetadata.routingResult({
|
|
447
|
+
* decision: 'classified',
|
|
448
|
+
* reason: 'User mentioned self-harm',
|
|
449
|
+
* category: 'crisis',
|
|
450
|
+
* level: 'high',
|
|
451
|
+
* score: 92,
|
|
452
|
+
* });
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
|
|
456
|
+
declare const streamMetadata: {
|
|
457
|
+
/**
|
|
458
|
+
* Declare the form schema (agents + questions) for Dashboard Form Insights.
|
|
459
|
+
*
|
|
460
|
+
* Yield this once during session initialization (welcome message).
|
|
461
|
+
* The Studio proxy stores it in `chatbot.externalSchema` so that
|
|
462
|
+
* Dashboard Form Insights can display question-level analytics.
|
|
463
|
+
*
|
|
464
|
+
* @param schema - Agents and questions your handler uses
|
|
465
|
+
* @returns A metadata stream chunk ready to yield or queue.push
|
|
466
|
+
*/
|
|
467
|
+
declareSchema(schema: SchemaDeclarationPayload): ProtocolStreamChunk;
|
|
468
|
+
/**
|
|
469
|
+
* Send collected form field values for Dashboard persistence.
|
|
470
|
+
*
|
|
471
|
+
* Call this after each turn when new fields are captured.
|
|
472
|
+
* Values are incrementally merged into `ChatSession.formData`.
|
|
473
|
+
*
|
|
474
|
+
* @param fields - Key-value pairs of field IDs to their collected values
|
|
475
|
+
* @returns A metadata stream chunk ready to yield or queue.push
|
|
476
|
+
*/
|
|
477
|
+
formDataUpdate(fields: Record<string, string | number>): ProtocolStreamChunk;
|
|
478
|
+
/**
|
|
479
|
+
* Signal an agent/stage transition for routing logs.
|
|
480
|
+
*
|
|
481
|
+
* The Studio proxy records this in `ChatSession.routingLogs` so
|
|
482
|
+
* the Dashboard can show the conversation's agent flow.
|
|
483
|
+
*
|
|
484
|
+
* @param agent - The agent/stage being transitioned to
|
|
485
|
+
* @returns A metadata stream chunk ready to yield or queue.push
|
|
486
|
+
*/
|
|
487
|
+
agentTransition(agent: AgentTransitionPayload): ProtocolStreamChunk;
|
|
488
|
+
/**
|
|
489
|
+
* Send a routing/classification result for routing logs.
|
|
490
|
+
*
|
|
491
|
+
* The Studio proxy records this in `ChatSession.routingLogs` as a
|
|
492
|
+
* classification event with category, level, and confidence score.
|
|
493
|
+
*
|
|
494
|
+
* @param result - Classification/routing decision details
|
|
495
|
+
* @returns A metadata stream chunk ready to yield or queue.push
|
|
496
|
+
*/
|
|
497
|
+
routingResult(result: RoutingClassificationPayload): ProtocolStreamChunk;
|
|
498
|
+
};
|
|
499
|
+
|
|
238
500
|
/**
|
|
239
501
|
* Verify an HMAC-SHA256 request signature.
|
|
240
502
|
*
|
|
241
503
|
* The handler server can use this to verify that incoming webhook
|
|
242
504
|
* requests were signed by the FirstStep platform using the shared token.
|
|
243
505
|
*
|
|
506
|
+
* The HMAC key is SHA-256(token), matching the backend which only stores
|
|
507
|
+
* the token hash and uses it directly as the HMAC key.
|
|
508
|
+
*
|
|
244
509
|
* @param token - The API token (FIRSTSTEP_TOKEN)
|
|
245
510
|
* @param payload - The raw request body string
|
|
246
511
|
* @param signature - The signature from the X-FirstStep-Signature header
|
|
@@ -296,4 +561,4 @@ declare function createAuthHeader(token: string): string;
|
|
|
296
561
|
*/
|
|
297
562
|
declare function isValidToken(token: string): boolean;
|
|
298
563
|
|
|
299
|
-
export { ChatMessage, type ClassificationResult, type UCPClassifyRequest, type UCPClassifyResponse, UCPClient, type UCPClientConfig, type UCPEndpointConfig, UCPError, type UCPErrorResponse, type UCPInfoResponse, type UCPMessage, classifyWithUCP, createAuthHeader, createRequestSignature, createUCPClient, isValidToken, verifyRequestSignature };
|
|
564
|
+
export { AgentTransitionPayload, ChatMessage, type ClassificationResult, type EmergencyPayload, type HelplineCardItem, type HelplineCardPayload, MARKER_TYPES, type MarkerType, ProtocolStreamChunk, type ProviderCardItem, type ProviderCardPayload, type ReportCardPayload, type ResourceCardItem, type ResourceCardPayload, RoutingClassificationPayload, type SafetyPlanPayload, type SafetyPlanSection, SchemaDeclarationPayload, type UCPClassifyRequest, type UCPClassifyResponse, UCPClient, type UCPClientConfig, type UCPEndpointConfig, UCPError, type UCPErrorResponse, type UCPInfoResponse, type UCPMessage, classifyWithUCP, createAuthHeader, createRequestSignature, createUCPClient, isValidToken, renderMarkers, streamMetadata, verifyRequestSignature };
|