@firststep-studio/sdk 0.13.0 → 0.14.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 CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ChatMessage, S as SchemaDeclarationPayload, P as ProtocolStreamChunk, A as AgentTransitionPayload, R as RoutingClassificationPayload, H as HandoffRequestPayload, a as HandoffReturnPayload, b as HandoffOfferPayload } from './types-DYJ44S2E.mjs';
2
- export { O as AnalyticsContext, E as ChatbotInfo, F as ClassifierConfig, D as DeploymentInfo, G as FormData, V as FormFieldDefinition, W as FormFieldType, J as FormFieldValue, U as FormSchema, n as HandlerInfo, _ as HandoffContext, f as HandoffInboundContext, $ as HandoffOptions, x as Helpline, w as HelplineResult, v as HelplineSearchOptions, I as IntegrationContext, u as IntegrationResult, Q as InteractionEvent, T as InteractionEventType, t as KnowledgeColumnMetadata, K as KnowledgeContext, s as KnowledgeMetadata, r as KnowledgeResult, L as LoggerContext, m as ProtocolCapabilities, o as ProtocolContext, k as ProtocolError, j as ProtocolFieldValidation, g as ProtocolForm, h as ProtocolFormField, i as ProtocolFormOption, l as ProtocolHandler, X as ProtocolRegistration, c as ProtocolRequest, d as ProtocolResponse, B as RoutingDecision, M as RoutingLog, Y as SchemaAgent, Z as SchemaQuestion, p as SessionContext, N as SessionMetadata, q as SessionState, e as SessionStatus, y as StorageContext, z as StorageSetOptions } from './types-DYJ44S2E.mjs';
1
+ import { C as ChatMessage, S as SchemaDeclarationPayload, P as ProtocolStreamChunk, A as AgentTransitionPayload, R as RoutingClassificationPayload, H as HandoffRequestPayload, a as HandoffReturnPayload, b as HandoffOfferPayload, c as StorageContext, d as StorageSetOptions, e as SessionContext, f as SessionState, F as FormData, g as FormFieldValue } from './types-D-QFhpnJ.mjs';
2
+ export { Q as AnalyticsContext, J as ChatbotInfo, M as ClassifierConfig, G as DeploymentInfo, X as FormFieldDefinition, Y as FormFieldType, W as FormSchema, s as HandlerInfo, a0 as HandoffContext, k as HandoffInboundContext, a1 as HandoffOptions, B as Helpline, z as HelplineResult, y as HelplineSearchOptions, I as IntegrationContext, x as IntegrationResult, U as InteractionEvent, V as InteractionEventType, w as KnowledgeColumnMetadata, K as KnowledgeContext, v as KnowledgeMetadata, u as KnowledgeResult, L as LoggerContext, r as ProtocolCapabilities, t as ProtocolContext, p as ProtocolError, o as ProtocolFieldValidation, l as ProtocolForm, m as ProtocolFormField, n as ProtocolFormOption, q as ProtocolHandler, Z as ProtocolRegistration, h as ProtocolRequest, i as ProtocolResponse, E as RoutingDecision, N as RoutingLog, _ as SchemaAgent, $ as SchemaQuestion, O as SessionMetadata, j as SessionStatus, T as ThroughlineReference, D as ThroughlineTopicFallback } from './types-D-QFhpnJ.mjs';
3
3
 
4
4
  /**
5
5
  * UCP (Universal Classification Protocol) Types
@@ -1233,4 +1233,51 @@ declare class LLMClient {
1233
1233
  */
1234
1234
  declare function createLLMClient(config: LLMClientConfig): LLMClient;
1235
1235
 
1236
- export { AgentTransitionPayload, ChatMessage, type ClassificationResult, type CreateKnowledgeOptions, type CreateKnowledgeSheet, type EmergencyPayload, HandoffOfferPayload, HandoffRequestPayload, HandoffReturnPayload, type HelplineCardItem, type HelplineCardPayload, type KnowledgeSearchOptions, type LLMCacheCreateRequest, type LLMCachedContent, type LLMCandidate, LLMClient, type LLMClientConfig, type LLMContent, LLMError, type LLMGenerateRequest, type LLMGenerateResponse, type LLMGenerationConfig, type LLMPart, type LLMSafetySetting, type LLMUsageMetadata, type ListKnowledgeOptions, MARKER_TYPES, type MarkerType, type PlatformChatbot, PlatformClient, type PlatformClientConfig, PlatformError, type PlatformKnowledge, type PlatformKnowledgeRecord, type PlatformKnowledgeSearchHit, type PlatformKnowledgeSummary, ProtocolStreamChunk, type ProviderCardItem, type ProviderCardPayload, type ReportCardPayload, type ResourceCardItem, type ResourceCardPayload, RoutingClassificationPayload, type SafetyPlanPayload, type SafetyPlanSection, SchemaDeclarationPayload, type ThroughlineHelplinesQuery, type UCPClassifyRequest, type UCPClassifyResponse, UCPClient, type UCPClientConfig, type UCPEndpointConfig, UCPError, type UCPErrorResponse, type UCPInfoResponse, type UCPMessage, classifyWithUCP, createAuthHeader, createLLMClient, createPlatformClient, createRequestSignature, createUCPClient, isValidToken, renderMarkers, streamMetadata, verifyRequestSignature };
1236
+ /**
1237
+ * HTTP-backed implementation of StorageContext.
1238
+ * All operations call back to Studio's protocol-resources API.
1239
+ * Data is scoped to the deployment via the JWT token.
1240
+ */
1241
+ declare class StorageClient implements StorageContext {
1242
+ private baseUrl;
1243
+ private token;
1244
+ constructor(baseUrl: string, token: string);
1245
+ get<T = unknown>(key: string): Promise<T | null>;
1246
+ set(key: string, value: unknown, options?: StorageSetOptions): Promise<void>;
1247
+ delete(key: string): Promise<void>;
1248
+ has(key: string): Promise<boolean>;
1249
+ keys(prefix?: string): Promise<string[]>;
1250
+ merge(key: string, partial: Record<string, unknown>): Promise<void>;
1251
+ append(key: string, item: unknown): Promise<void>;
1252
+ private _post;
1253
+ }
1254
+
1255
+ /**
1256
+ * HTTP-backed implementation of SessionContext.
1257
+ *
1258
+ * All operations call back to Studio's protocol-resources `/session/*` API,
1259
+ * which is backed by the Redis hot-session store (protocolSession.service).
1260
+ * Session is scoped to the deployment + sessionId encoded in the JWT token, so
1261
+ * the request bodies never carry the session id themselves.
1262
+ *
1263
+ * This is the external-handler counterpart to the in-process SessionContext
1264
+ * the built-in GuidedForm engine gets via handlers/context.ts — same
1265
+ * interface, same Redis backend, reached over HTTP instead of in-process.
1266
+ */
1267
+ declare class SessionClient implements SessionContext {
1268
+ sessionId: string;
1269
+ private baseUrl;
1270
+ private token;
1271
+ constructor(baseUrl: string, token: string, sessionId: string);
1272
+ getState(): Promise<SessionState>;
1273
+ updateState(updates: Partial<SessionState>): Promise<void>;
1274
+ getHistory(): Promise<ChatMessage[]>;
1275
+ saveMessage(message: ChatMessage): Promise<void>;
1276
+ complete(): Promise<void>;
1277
+ getFormData(): Promise<FormData>;
1278
+ updateFormField(fieldId: string, value: FormFieldValue): Promise<void>;
1279
+ updateFormData(fields: Record<string, FormFieldValue>): Promise<void>;
1280
+ private _post;
1281
+ }
1282
+
1283
+ export { AgentTransitionPayload, ChatMessage, type ClassificationResult, type CreateKnowledgeOptions, type CreateKnowledgeSheet, type EmergencyPayload, FormData, FormFieldValue, HandoffOfferPayload, HandoffRequestPayload, HandoffReturnPayload, type HelplineCardItem, type HelplineCardPayload, type KnowledgeSearchOptions, type LLMCacheCreateRequest, type LLMCachedContent, type LLMCandidate, LLMClient, type LLMClientConfig, type LLMContent, LLMError, type LLMGenerateRequest, type LLMGenerateResponse, type LLMGenerationConfig, type LLMPart, type LLMSafetySetting, type LLMUsageMetadata, type ListKnowledgeOptions, MARKER_TYPES, type MarkerType, type PlatformChatbot, PlatformClient, type PlatformClientConfig, PlatformError, type PlatformKnowledge, type PlatformKnowledgeRecord, type PlatformKnowledgeSearchHit, type PlatformKnowledgeSummary, ProtocolStreamChunk, type ProviderCardItem, type ProviderCardPayload, type ReportCardPayload, type ResourceCardItem, type ResourceCardPayload, RoutingClassificationPayload, type SafetyPlanPayload, type SafetyPlanSection, SchemaDeclarationPayload, SessionClient, SessionContext, SessionState, StorageClient, StorageContext, StorageSetOptions, type ThroughlineHelplinesQuery, type UCPClassifyRequest, type UCPClassifyResponse, UCPClient, type UCPClientConfig, type UCPEndpointConfig, UCPError, type UCPErrorResponse, type UCPInfoResponse, type UCPMessage, classifyWithUCP, createAuthHeader, createLLMClient, createPlatformClient, createRequestSignature, createUCPClient, isValidToken, renderMarkers, streamMetadata, verifyRequestSignature };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ChatMessage, S as SchemaDeclarationPayload, P as ProtocolStreamChunk, A as AgentTransitionPayload, R as RoutingClassificationPayload, H as HandoffRequestPayload, a as HandoffReturnPayload, b as HandoffOfferPayload } from './types-DYJ44S2E.js';
2
- export { O as AnalyticsContext, E as ChatbotInfo, F as ClassifierConfig, D as DeploymentInfo, G as FormData, V as FormFieldDefinition, W as FormFieldType, J as FormFieldValue, U as FormSchema, n as HandlerInfo, _ as HandoffContext, f as HandoffInboundContext, $ as HandoffOptions, x as Helpline, w as HelplineResult, v as HelplineSearchOptions, I as IntegrationContext, u as IntegrationResult, Q as InteractionEvent, T as InteractionEventType, t as KnowledgeColumnMetadata, K as KnowledgeContext, s as KnowledgeMetadata, r as KnowledgeResult, L as LoggerContext, m as ProtocolCapabilities, o as ProtocolContext, k as ProtocolError, j as ProtocolFieldValidation, g as ProtocolForm, h as ProtocolFormField, i as ProtocolFormOption, l as ProtocolHandler, X as ProtocolRegistration, c as ProtocolRequest, d as ProtocolResponse, B as RoutingDecision, M as RoutingLog, Y as SchemaAgent, Z as SchemaQuestion, p as SessionContext, N as SessionMetadata, q as SessionState, e as SessionStatus, y as StorageContext, z as StorageSetOptions } from './types-DYJ44S2E.js';
1
+ import { C as ChatMessage, S as SchemaDeclarationPayload, P as ProtocolStreamChunk, A as AgentTransitionPayload, R as RoutingClassificationPayload, H as HandoffRequestPayload, a as HandoffReturnPayload, b as HandoffOfferPayload, c as StorageContext, d as StorageSetOptions, e as SessionContext, f as SessionState, F as FormData, g as FormFieldValue } from './types-D-QFhpnJ.js';
2
+ export { Q as AnalyticsContext, J as ChatbotInfo, M as ClassifierConfig, G as DeploymentInfo, X as FormFieldDefinition, Y as FormFieldType, W as FormSchema, s as HandlerInfo, a0 as HandoffContext, k as HandoffInboundContext, a1 as HandoffOptions, B as Helpline, z as HelplineResult, y as HelplineSearchOptions, I as IntegrationContext, x as IntegrationResult, U as InteractionEvent, V as InteractionEventType, w as KnowledgeColumnMetadata, K as KnowledgeContext, v as KnowledgeMetadata, u as KnowledgeResult, L as LoggerContext, r as ProtocolCapabilities, t as ProtocolContext, p as ProtocolError, o as ProtocolFieldValidation, l as ProtocolForm, m as ProtocolFormField, n as ProtocolFormOption, q as ProtocolHandler, Z as ProtocolRegistration, h as ProtocolRequest, i as ProtocolResponse, E as RoutingDecision, N as RoutingLog, _ as SchemaAgent, $ as SchemaQuestion, O as SessionMetadata, j as SessionStatus, T as ThroughlineReference, D as ThroughlineTopicFallback } from './types-D-QFhpnJ.js';
3
3
 
4
4
  /**
5
5
  * UCP (Universal Classification Protocol) Types
@@ -1233,4 +1233,51 @@ declare class LLMClient {
1233
1233
  */
1234
1234
  declare function createLLMClient(config: LLMClientConfig): LLMClient;
1235
1235
 
1236
- export { AgentTransitionPayload, ChatMessage, type ClassificationResult, type CreateKnowledgeOptions, type CreateKnowledgeSheet, type EmergencyPayload, HandoffOfferPayload, HandoffRequestPayload, HandoffReturnPayload, type HelplineCardItem, type HelplineCardPayload, type KnowledgeSearchOptions, type LLMCacheCreateRequest, type LLMCachedContent, type LLMCandidate, LLMClient, type LLMClientConfig, type LLMContent, LLMError, type LLMGenerateRequest, type LLMGenerateResponse, type LLMGenerationConfig, type LLMPart, type LLMSafetySetting, type LLMUsageMetadata, type ListKnowledgeOptions, MARKER_TYPES, type MarkerType, type PlatformChatbot, PlatformClient, type PlatformClientConfig, PlatformError, type PlatformKnowledge, type PlatformKnowledgeRecord, type PlatformKnowledgeSearchHit, type PlatformKnowledgeSummary, ProtocolStreamChunk, type ProviderCardItem, type ProviderCardPayload, type ReportCardPayload, type ResourceCardItem, type ResourceCardPayload, RoutingClassificationPayload, type SafetyPlanPayload, type SafetyPlanSection, SchemaDeclarationPayload, type ThroughlineHelplinesQuery, type UCPClassifyRequest, type UCPClassifyResponse, UCPClient, type UCPClientConfig, type UCPEndpointConfig, UCPError, type UCPErrorResponse, type UCPInfoResponse, type UCPMessage, classifyWithUCP, createAuthHeader, createLLMClient, createPlatformClient, createRequestSignature, createUCPClient, isValidToken, renderMarkers, streamMetadata, verifyRequestSignature };
1236
+ /**
1237
+ * HTTP-backed implementation of StorageContext.
1238
+ * All operations call back to Studio's protocol-resources API.
1239
+ * Data is scoped to the deployment via the JWT token.
1240
+ */
1241
+ declare class StorageClient implements StorageContext {
1242
+ private baseUrl;
1243
+ private token;
1244
+ constructor(baseUrl: string, token: string);
1245
+ get<T = unknown>(key: string): Promise<T | null>;
1246
+ set(key: string, value: unknown, options?: StorageSetOptions): Promise<void>;
1247
+ delete(key: string): Promise<void>;
1248
+ has(key: string): Promise<boolean>;
1249
+ keys(prefix?: string): Promise<string[]>;
1250
+ merge(key: string, partial: Record<string, unknown>): Promise<void>;
1251
+ append(key: string, item: unknown): Promise<void>;
1252
+ private _post;
1253
+ }
1254
+
1255
+ /**
1256
+ * HTTP-backed implementation of SessionContext.
1257
+ *
1258
+ * All operations call back to Studio's protocol-resources `/session/*` API,
1259
+ * which is backed by the Redis hot-session store (protocolSession.service).
1260
+ * Session is scoped to the deployment + sessionId encoded in the JWT token, so
1261
+ * the request bodies never carry the session id themselves.
1262
+ *
1263
+ * This is the external-handler counterpart to the in-process SessionContext
1264
+ * the built-in GuidedForm engine gets via handlers/context.ts — same
1265
+ * interface, same Redis backend, reached over HTTP instead of in-process.
1266
+ */
1267
+ declare class SessionClient implements SessionContext {
1268
+ sessionId: string;
1269
+ private baseUrl;
1270
+ private token;
1271
+ constructor(baseUrl: string, token: string, sessionId: string);
1272
+ getState(): Promise<SessionState>;
1273
+ updateState(updates: Partial<SessionState>): Promise<void>;
1274
+ getHistory(): Promise<ChatMessage[]>;
1275
+ saveMessage(message: ChatMessage): Promise<void>;
1276
+ complete(): Promise<void>;
1277
+ getFormData(): Promise<FormData>;
1278
+ updateFormField(fieldId: string, value: FormFieldValue): Promise<void>;
1279
+ updateFormData(fields: Record<string, FormFieldValue>): Promise<void>;
1280
+ private _post;
1281
+ }
1282
+
1283
+ export { AgentTransitionPayload, ChatMessage, type ClassificationResult, type CreateKnowledgeOptions, type CreateKnowledgeSheet, type EmergencyPayload, FormData, FormFieldValue, HandoffOfferPayload, HandoffRequestPayload, HandoffReturnPayload, type HelplineCardItem, type HelplineCardPayload, type KnowledgeSearchOptions, type LLMCacheCreateRequest, type LLMCachedContent, type LLMCandidate, LLMClient, type LLMClientConfig, type LLMContent, LLMError, type LLMGenerateRequest, type LLMGenerateResponse, type LLMGenerationConfig, type LLMPart, type LLMSafetySetting, type LLMUsageMetadata, type ListKnowledgeOptions, MARKER_TYPES, type MarkerType, type PlatformChatbot, PlatformClient, type PlatformClientConfig, PlatformError, type PlatformKnowledge, type PlatformKnowledgeRecord, type PlatformKnowledgeSearchHit, type PlatformKnowledgeSummary, ProtocolStreamChunk, type ProviderCardItem, type ProviderCardPayload, type ReportCardPayload, type ResourceCardItem, type ResourceCardPayload, RoutingClassificationPayload, type SafetyPlanPayload, type SafetyPlanSection, SchemaDeclarationPayload, SessionClient, SessionContext, SessionState, StorageClient, StorageContext, StorageSetOptions, type ThroughlineHelplinesQuery, type UCPClassifyRequest, type UCPClassifyResponse, UCPClient, type UCPClientConfig, type UCPEndpointConfig, UCPError, type UCPErrorResponse, type UCPInfoResponse, type UCPMessage, classifyWithUCP, createAuthHeader, createLLMClient, createPlatformClient, createRequestSignature, createUCPClient, isValidToken, renderMarkers, streamMetadata, verifyRequestSignature };
package/dist/index.js CHANGED
@@ -25,6 +25,8 @@ __export(index_exports, {
25
25
  MARKER_TYPES: () => MARKER_TYPES,
26
26
  PlatformClient: () => PlatformClient,
27
27
  PlatformError: () => PlatformError,
28
+ SessionClient: () => SessionClient,
29
+ StorageClient: () => StorageClient,
28
30
  UCPClient: () => UCPClient,
29
31
  UCPError: () => UCPError,
30
32
  classifyWithUCP: () => classifyWithUCP,
@@ -868,6 +870,117 @@ var LLMClient = class {
868
870
  function createLLMClient(config) {
869
871
  return new LLMClient(config);
870
872
  }
873
+
874
+ // src/resources/storageClient.ts
875
+ var StorageClient = class {
876
+ constructor(baseUrl, token) {
877
+ this.baseUrl = baseUrl;
878
+ this.token = token;
879
+ }
880
+ async get(key) {
881
+ const res = await this._post("/storage/get", { key });
882
+ if (!res.success) return null;
883
+ return res.value ?? null;
884
+ }
885
+ async set(key, value, options) {
886
+ await this._post("/storage/set", { key, value, ttl: options?.ttl });
887
+ }
888
+ async delete(key) {
889
+ await this._post("/storage/delete", { key });
890
+ }
891
+ async has(key) {
892
+ const res = await this._post("/storage/has", { key });
893
+ return res.exists === true;
894
+ }
895
+ async keys(prefix) {
896
+ const res = await this._post("/storage/keys", { prefix });
897
+ return res.keys ?? [];
898
+ }
899
+ async merge(key, partial) {
900
+ await this._post("/storage/merge", { key, partial });
901
+ }
902
+ async append(key, item) {
903
+ await this._post("/storage/append", { key, item });
904
+ }
905
+ async _post(path, body) {
906
+ const res = await fetch(`${this.baseUrl}${path}`, {
907
+ method: "POST",
908
+ headers: {
909
+ "Content-Type": "application/json",
910
+ Authorization: `Bearer ${this.token}`
911
+ },
912
+ body: JSON.stringify(body)
913
+ });
914
+ if (!res.ok) {
915
+ const text = await res.text().catch(() => "");
916
+ console.error(`[StorageClient] ${path} failed: ${res.status} ${text}`);
917
+ return { success: false, error: `HTTP ${res.status}` };
918
+ }
919
+ return res.json();
920
+ }
921
+ };
922
+
923
+ // src/resources/sessionClient.ts
924
+ var SessionClient = class {
925
+ constructor(baseUrl, token, sessionId) {
926
+ this.baseUrl = baseUrl;
927
+ this.token = token;
928
+ this.sessionId = sessionId;
929
+ }
930
+ async getState() {
931
+ const res = await this._post("/session/get-state", {});
932
+ return reviveState(res.state);
933
+ }
934
+ async updateState(updates) {
935
+ await this._post("/session/update-state", { updates });
936
+ }
937
+ async getHistory() {
938
+ const res = await this._post("/session/get-history", {});
939
+ return (res.messages ?? []).map(reviveMessage);
940
+ }
941
+ async saveMessage(message) {
942
+ await this._post("/session/save-message", { message });
943
+ }
944
+ async complete() {
945
+ await this._post("/session/complete", {});
946
+ }
947
+ async getFormData() {
948
+ const res = await this._post("/session/get-form-data", {});
949
+ return res.formData ?? {};
950
+ }
951
+ async updateFormField(fieldId, value) {
952
+ await this._post("/session/update-form-field", { fieldId, value });
953
+ }
954
+ async updateFormData(fields) {
955
+ await this._post("/session/update-form-data", { fields });
956
+ }
957
+ async _post(path, body) {
958
+ const res = await fetch(`${this.baseUrl}${path}`, {
959
+ method: "POST",
960
+ headers: {
961
+ "Content-Type": "application/json",
962
+ Authorization: `Bearer ${this.token}`
963
+ },
964
+ body: JSON.stringify(body)
965
+ });
966
+ if (!res.ok) {
967
+ const text = await res.text().catch(() => "");
968
+ console.error(`[SessionClient] ${path} failed: ${res.status} ${text}`);
969
+ throw new Error(`SessionClient ${path} failed: HTTP ${res.status}`);
970
+ }
971
+ return res.json();
972
+ }
973
+ };
974
+ function reviveState(state) {
975
+ if (!state) return state;
976
+ if (state.createdAt) state.createdAt = new Date(state.createdAt);
977
+ if (state.updatedAt) state.updatedAt = new Date(state.updatedAt);
978
+ return state;
979
+ }
980
+ function reviveMessage(msg) {
981
+ if (msg?.timestamp) msg.timestamp = new Date(msg.timestamp);
982
+ return msg;
983
+ }
871
984
  // Annotate the CommonJS export names for ESM import in node:
872
985
  0 && (module.exports = {
873
986
  LLMClient,
@@ -875,6 +988,8 @@ function createLLMClient(config) {
875
988
  MARKER_TYPES,
876
989
  PlatformClient,
877
990
  PlatformError,
991
+ SessionClient,
992
+ StorageClient,
878
993
  UCPClient,
879
994
  UCPError,
880
995
  classifyWithUCP,