@firststep-studio/sdk 0.10.0 → 0.12.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-GoTI_c14.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-GoTI_c14.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 } 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';
3
3
 
4
4
  /**
5
5
  * UCP (Universal Classification Protocol) Types
@@ -678,8 +678,16 @@ interface PlatformKnowledgeSummary {
678
678
  description?: string;
679
679
  /** Knowledge type (e.g. 'text', 'database') */
680
680
  type?: string;
681
- /** Owning organization ID */
682
- organizationId: string;
681
+ /** Owning organization ID. Null for org-less system documents. */
682
+ organizationId: string | null;
683
+ /**
684
+ * True for handler-managed documents created through the protocol
685
+ * write API. System-owned knowledge is hidden from every Studio UI
686
+ * surface and only appears in `list` when `includeSystemOwned` is set.
687
+ */
688
+ isSystemOwned?: boolean;
689
+ /** Whether semantic search (record embedding) is enabled. */
690
+ ragEnabled?: boolean;
683
691
  /** Timestamps */
684
692
  createdAt?: number | string;
685
693
  updatedAt?: number | string;
@@ -698,6 +706,55 @@ interface ListKnowledgeOptions {
698
706
  * `publicReadable` in Studio).
699
707
  */
700
708
  orgId?: string;
709
+ /**
710
+ * Include system-owned (handler-managed) knowledge in the listing.
711
+ * Only honored when listing the token's own org; other orgs never
712
+ * expose their system-owned documents.
713
+ */
714
+ includeSystemOwned?: boolean;
715
+ /**
716
+ * 'system' lists ORG-LESS platform documents instead of org
717
+ * knowledge. orgId and includeSystemOwned are ignored in that mode.
718
+ */
719
+ scope?: 'system';
720
+ }
721
+ /** Sheet definition for `knowledge.create`. */
722
+ interface CreateKnowledgeSheet {
723
+ /** Stable sheet id, referenced later by record writes and search. */
724
+ id: string;
725
+ name: string;
726
+ description?: string;
727
+ /**
728
+ * Column definitions ({ id, name, type, ... }). Loose-typed; the
729
+ * Studio schema validates `type` against its column-type enum.
730
+ */
731
+ columns?: Array<Record<string, unknown>>;
732
+ }
733
+ interface CreateKnowledgeOptions {
734
+ description?: string;
735
+ /**
736
+ * Enable semantic search at creation time. Defaults to false; can be
737
+ * flipped later with `setRagEnabled` (which also backfills embeddings
738
+ * for records inserted while the flag was off).
739
+ */
740
+ ragEnabled?: boolean;
741
+ /**
742
+ * Create the knowledge as an ORG-LESS platform document: no
743
+ * organizationId at all, structurally invisible to every org-scoped
744
+ * Studio surface. This is the home for handler-managed data. Without
745
+ * it the document is created under the token's org (hidden from the
746
+ * UI by isSystemOwned, but org-bound).
747
+ */
748
+ system?: boolean;
749
+ }
750
+ /** A raw record as returned by the protocol record-write endpoints. */
751
+ interface PlatformKnowledgeRecord {
752
+ id: string;
753
+ knowledgeId: string;
754
+ sheetId: string;
755
+ data: Record<string, unknown>;
756
+ createdAt?: number | string;
757
+ updatedAt?: number | string;
701
758
  }
702
759
  interface KnowledgeSearchOptions {
703
760
  /** Max records to return (server-side clamped to 1..50, default 10). */
@@ -769,8 +826,12 @@ declare class PlatformClient {
769
826
  *
770
827
  * Reads are allowed when the SDK token's org matches the target org,
771
828
  * OR when the target org has `publicReadable: true` on the Studio side.
772
- * Writes are not yet exposed here — those still go through the user-
773
- * authenticated /api/knowledge routes from the Studio UI.
829
+ *
830
+ * Writes target system-owned (handler-managed) knowledge only: the
831
+ * protocol API stamps everything created here `isSystemOwned: true`,
832
+ * which keeps it out of every Studio UI surface — Studio acts as a
833
+ * plain storage + RAG layer for it. UI-managed knowledge cannot be
834
+ * modified through this surface.
774
835
  */
775
836
  knowledge: {
776
837
  /**
@@ -813,6 +874,43 @@ declare class PlatformClient {
813
874
  ragEnabled: boolean;
814
875
  backfillTriggered: boolean;
815
876
  }>;
877
+ /**
878
+ * Create a system-owned database knowledge under the token's org.
879
+ *
880
+ * 409 (surfaced as an error) means a knowledge of the same name
881
+ * already exists in the org. Idempotent callers should recover by
882
+ * listing with `includeSystemOwned: true` and matching on name.
883
+ */
884
+ create: (name: string, sheets: CreateKnowledgeSheet[], options?: CreateKnowledgeOptions) => Promise<PlatformKnowledge>;
885
+ /**
886
+ * Delete a system-owned knowledge and all of its records.
887
+ * Refused (403) for UI-managed knowledge.
888
+ */
889
+ delete: (id: string) => Promise<{
890
+ deletedRecords: number;
891
+ }>;
892
+ /**
893
+ * Append one record to a sheet. Embeds async when ragEnabled.
894
+ */
895
+ addRecord: (id: string, sheetId: string, data: Record<string, unknown>) => Promise<PlatformKnowledgeRecord>;
896
+ /**
897
+ * Replace a record's data payload. Re-embeds async when ragEnabled.
898
+ */
899
+ updateRecord: (id: string, recordId: string, data: Record<string, unknown>) => Promise<PlatformKnowledgeRecord>;
900
+ /** Delete one record. */
901
+ deleteRecord: (id: string, recordId: string) => Promise<void>;
902
+ /**
903
+ * Bulk-insert records into one sheet (each array entry becomes one
904
+ * record's `data`). With `replace: true` the sheet's existing
905
+ * records are deleted first — the full-resync primitive backfills
906
+ * use. Server caps a single call at 5000 records.
907
+ */
908
+ bulkRecords: (id: string, sheetId: string, records: Array<Record<string, unknown>>, options?: {
909
+ replace?: boolean;
910
+ }) => Promise<{
911
+ insertedCount: number;
912
+ deletedCount: number;
913
+ }>;
816
914
  };
817
915
  /**
818
916
  * Throughline (find-a-helpline) surface.
@@ -1123,4 +1221,4 @@ declare class LLMClient {
1123
1221
  */
1124
1222
  declare function createLLMClient(config: LLMClientConfig): LLMClient;
1125
1223
 
1126
- export { AgentTransitionPayload, ChatMessage, type ClassificationResult, 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 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 };
1224
+ 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 };
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-GoTI_c14.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-GoTI_c14.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 } 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';
3
3
 
4
4
  /**
5
5
  * UCP (Universal Classification Protocol) Types
@@ -678,8 +678,16 @@ interface PlatformKnowledgeSummary {
678
678
  description?: string;
679
679
  /** Knowledge type (e.g. 'text', 'database') */
680
680
  type?: string;
681
- /** Owning organization ID */
682
- organizationId: string;
681
+ /** Owning organization ID. Null for org-less system documents. */
682
+ organizationId: string | null;
683
+ /**
684
+ * True for handler-managed documents created through the protocol
685
+ * write API. System-owned knowledge is hidden from every Studio UI
686
+ * surface and only appears in `list` when `includeSystemOwned` is set.
687
+ */
688
+ isSystemOwned?: boolean;
689
+ /** Whether semantic search (record embedding) is enabled. */
690
+ ragEnabled?: boolean;
683
691
  /** Timestamps */
684
692
  createdAt?: number | string;
685
693
  updatedAt?: number | string;
@@ -698,6 +706,55 @@ interface ListKnowledgeOptions {
698
706
  * `publicReadable` in Studio).
699
707
  */
700
708
  orgId?: string;
709
+ /**
710
+ * Include system-owned (handler-managed) knowledge in the listing.
711
+ * Only honored when listing the token's own org; other orgs never
712
+ * expose their system-owned documents.
713
+ */
714
+ includeSystemOwned?: boolean;
715
+ /**
716
+ * 'system' lists ORG-LESS platform documents instead of org
717
+ * knowledge. orgId and includeSystemOwned are ignored in that mode.
718
+ */
719
+ scope?: 'system';
720
+ }
721
+ /** Sheet definition for `knowledge.create`. */
722
+ interface CreateKnowledgeSheet {
723
+ /** Stable sheet id, referenced later by record writes and search. */
724
+ id: string;
725
+ name: string;
726
+ description?: string;
727
+ /**
728
+ * Column definitions ({ id, name, type, ... }). Loose-typed; the
729
+ * Studio schema validates `type` against its column-type enum.
730
+ */
731
+ columns?: Array<Record<string, unknown>>;
732
+ }
733
+ interface CreateKnowledgeOptions {
734
+ description?: string;
735
+ /**
736
+ * Enable semantic search at creation time. Defaults to false; can be
737
+ * flipped later with `setRagEnabled` (which also backfills embeddings
738
+ * for records inserted while the flag was off).
739
+ */
740
+ ragEnabled?: boolean;
741
+ /**
742
+ * Create the knowledge as an ORG-LESS platform document: no
743
+ * organizationId at all, structurally invisible to every org-scoped
744
+ * Studio surface. This is the home for handler-managed data. Without
745
+ * it the document is created under the token's org (hidden from the
746
+ * UI by isSystemOwned, but org-bound).
747
+ */
748
+ system?: boolean;
749
+ }
750
+ /** A raw record as returned by the protocol record-write endpoints. */
751
+ interface PlatformKnowledgeRecord {
752
+ id: string;
753
+ knowledgeId: string;
754
+ sheetId: string;
755
+ data: Record<string, unknown>;
756
+ createdAt?: number | string;
757
+ updatedAt?: number | string;
701
758
  }
702
759
  interface KnowledgeSearchOptions {
703
760
  /** Max records to return (server-side clamped to 1..50, default 10). */
@@ -769,8 +826,12 @@ declare class PlatformClient {
769
826
  *
770
827
  * Reads are allowed when the SDK token's org matches the target org,
771
828
  * OR when the target org has `publicReadable: true` on the Studio side.
772
- * Writes are not yet exposed here — those still go through the user-
773
- * authenticated /api/knowledge routes from the Studio UI.
829
+ *
830
+ * Writes target system-owned (handler-managed) knowledge only: the
831
+ * protocol API stamps everything created here `isSystemOwned: true`,
832
+ * which keeps it out of every Studio UI surface — Studio acts as a
833
+ * plain storage + RAG layer for it. UI-managed knowledge cannot be
834
+ * modified through this surface.
774
835
  */
775
836
  knowledge: {
776
837
  /**
@@ -813,6 +874,43 @@ declare class PlatformClient {
813
874
  ragEnabled: boolean;
814
875
  backfillTriggered: boolean;
815
876
  }>;
877
+ /**
878
+ * Create a system-owned database knowledge under the token's org.
879
+ *
880
+ * 409 (surfaced as an error) means a knowledge of the same name
881
+ * already exists in the org. Idempotent callers should recover by
882
+ * listing with `includeSystemOwned: true` and matching on name.
883
+ */
884
+ create: (name: string, sheets: CreateKnowledgeSheet[], options?: CreateKnowledgeOptions) => Promise<PlatformKnowledge>;
885
+ /**
886
+ * Delete a system-owned knowledge and all of its records.
887
+ * Refused (403) for UI-managed knowledge.
888
+ */
889
+ delete: (id: string) => Promise<{
890
+ deletedRecords: number;
891
+ }>;
892
+ /**
893
+ * Append one record to a sheet. Embeds async when ragEnabled.
894
+ */
895
+ addRecord: (id: string, sheetId: string, data: Record<string, unknown>) => Promise<PlatformKnowledgeRecord>;
896
+ /**
897
+ * Replace a record's data payload. Re-embeds async when ragEnabled.
898
+ */
899
+ updateRecord: (id: string, recordId: string, data: Record<string, unknown>) => Promise<PlatformKnowledgeRecord>;
900
+ /** Delete one record. */
901
+ deleteRecord: (id: string, recordId: string) => Promise<void>;
902
+ /**
903
+ * Bulk-insert records into one sheet (each array entry becomes one
904
+ * record's `data`). With `replace: true` the sheet's existing
905
+ * records are deleted first — the full-resync primitive backfills
906
+ * use. Server caps a single call at 5000 records.
907
+ */
908
+ bulkRecords: (id: string, sheetId: string, records: Array<Record<string, unknown>>, options?: {
909
+ replace?: boolean;
910
+ }) => Promise<{
911
+ insertedCount: number;
912
+ deletedCount: number;
913
+ }>;
816
914
  };
817
915
  /**
818
916
  * Throughline (find-a-helpline) surface.
@@ -1123,4 +1221,4 @@ declare class LLMClient {
1123
1221
  */
1124
1222
  declare function createLLMClient(config: LLMClientConfig): LLMClient;
1125
1223
 
1126
- export { AgentTransitionPayload, ChatMessage, type ClassificationResult, 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 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 };
1224
+ 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 };
package/dist/index.js CHANGED
@@ -343,8 +343,12 @@ var PlatformClient = class {
343
343
  *
344
344
  * Reads are allowed when the SDK token's org matches the target org,
345
345
  * OR when the target org has `publicReadable: true` on the Studio side.
346
- * Writes are not yet exposed here — those still go through the user-
347
- * authenticated /api/knowledge routes from the Studio UI.
346
+ *
347
+ * Writes target system-owned (handler-managed) knowledge only: the
348
+ * protocol API stamps everything created here `isSystemOwned: true`,
349
+ * which keeps it out of every Studio UI surface — Studio acts as a
350
+ * plain storage + RAG layer for it. UI-managed knowledge cannot be
351
+ * modified through this surface.
348
352
  */
349
353
  this.knowledge = {
350
354
  /**
@@ -352,9 +356,16 @@ var PlatformClient = class {
352
356
  * Defaults to the SDK token's own org if `orgId` is omitted.
353
357
  */
354
358
  list: async (options = {}) => {
355
- const qs = options.orgId ? `?organizationId=${encodeURIComponent(options.orgId)}` : "";
359
+ const params = new URLSearchParams();
360
+ if (options.scope === "system") {
361
+ params.set("scope", "system");
362
+ } else {
363
+ if (options.orgId) params.set("organizationId", options.orgId);
364
+ if (options.includeSystemOwned) params.set("includeSystemOwned", "1");
365
+ }
366
+ const qsStr = params.toString();
356
367
  const data = await this.request(
357
- `/api/protocol/knowledge${qs}`,
368
+ `/api/protocol/knowledge${qsStr ? `?${qsStr}` : ""}`,
358
369
  "Failed to list knowledge"
359
370
  );
360
371
  return data.knowledge;
@@ -416,6 +427,93 @@ var PlatformClient = class {
416
427
  { method: "POST", body: { enabled } }
417
428
  );
418
429
  return data.knowledge;
430
+ },
431
+ /**
432
+ * Create a system-owned database knowledge under the token's org.
433
+ *
434
+ * 409 (surfaced as an error) means a knowledge of the same name
435
+ * already exists in the org. Idempotent callers should recover by
436
+ * listing with `includeSystemOwned: true` and matching on name.
437
+ */
438
+ create: async (name, sheets, options = {}) => {
439
+ const data = await this.request(
440
+ "/api/protocol/knowledge",
441
+ "Failed to create knowledge",
442
+ {
443
+ method: "POST",
444
+ body: {
445
+ name,
446
+ sheets,
447
+ ...options.description !== void 0 ? { description: options.description } : {},
448
+ ...options.ragEnabled !== void 0 ? { ragEnabled: options.ragEnabled } : {},
449
+ ...options.system !== void 0 ? { system: options.system } : {}
450
+ }
451
+ }
452
+ );
453
+ return data.knowledge;
454
+ },
455
+ /**
456
+ * Delete a system-owned knowledge and all of its records.
457
+ * Refused (403) for UI-managed knowledge.
458
+ */
459
+ delete: async (id) => {
460
+ const data = await this.request(
461
+ `/api/protocol/knowledge/${encodeURIComponent(id)}`,
462
+ "Failed to delete knowledge",
463
+ { method: "DELETE" }
464
+ );
465
+ return { deletedRecords: data.deletedRecords };
466
+ },
467
+ /**
468
+ * Append one record to a sheet. Embeds async when ragEnabled.
469
+ */
470
+ addRecord: async (id, sheetId, data) => {
471
+ const res = await this.request(
472
+ `/api/protocol/knowledge/${encodeURIComponent(id)}/records`,
473
+ "Failed to create record",
474
+ { method: "POST", body: { sheetId, data } }
475
+ );
476
+ return res.record;
477
+ },
478
+ /**
479
+ * Replace a record's data payload. Re-embeds async when ragEnabled.
480
+ */
481
+ updateRecord: async (id, recordId, data) => {
482
+ const res = await this.request(
483
+ `/api/protocol/knowledge/${encodeURIComponent(id)}/records/${encodeURIComponent(recordId)}`,
484
+ "Failed to update record",
485
+ { method: "PUT", body: { data } }
486
+ );
487
+ return res.record;
488
+ },
489
+ /** Delete one record. */
490
+ deleteRecord: async (id, recordId) => {
491
+ await this.request(
492
+ `/api/protocol/knowledge/${encodeURIComponent(id)}/records/${encodeURIComponent(recordId)}`,
493
+ "Failed to delete record",
494
+ { method: "DELETE" }
495
+ );
496
+ },
497
+ /**
498
+ * Bulk-insert records into one sheet (each array entry becomes one
499
+ * record's `data`). With `replace: true` the sheet's existing
500
+ * records are deleted first — the full-resync primitive backfills
501
+ * use. Server caps a single call at 5000 records.
502
+ */
503
+ bulkRecords: async (id, sheetId, records, options = {}) => {
504
+ const data = await this.request(
505
+ `/api/protocol/knowledge/${encodeURIComponent(id)}/records/bulk`,
506
+ "Failed to bulk-write records",
507
+ {
508
+ method: "POST",
509
+ body: {
510
+ sheetId,
511
+ records,
512
+ ...options.replace !== void 0 ? { replace: options.replace } : {}
513
+ }
514
+ }
515
+ );
516
+ return { insertedCount: data.insertedCount, deletedCount: data.deletedCount };
419
517
  }
420
518
  };
421
519
  /**