@firststep-studio/sdk 0.10.0 → 0.11.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
@@ -680,6 +680,14 @@ interface PlatformKnowledgeSummary {
680
680
  type?: string;
681
681
  /** Owning organization ID */
682
682
  organizationId: string;
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,42 @@ 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
+ /** Sheet definition for `knowledge.create`. */
717
+ interface CreateKnowledgeSheet {
718
+ /** Stable sheet id, referenced later by record writes and search. */
719
+ id: string;
720
+ name: string;
721
+ description?: string;
722
+ /**
723
+ * Column definitions ({ id, name, type, ... }). Loose-typed; the
724
+ * Studio schema validates `type` against its column-type enum.
725
+ */
726
+ columns?: Array<Record<string, unknown>>;
727
+ }
728
+ interface CreateKnowledgeOptions {
729
+ description?: string;
730
+ /**
731
+ * Enable semantic search at creation time. Defaults to false; can be
732
+ * flipped later with `setRagEnabled` (which also backfills embeddings
733
+ * for records inserted while the flag was off).
734
+ */
735
+ ragEnabled?: boolean;
736
+ }
737
+ /** A raw record as returned by the protocol record-write endpoints. */
738
+ interface PlatformKnowledgeRecord {
739
+ id: string;
740
+ knowledgeId: string;
741
+ sheetId: string;
742
+ data: Record<string, unknown>;
743
+ createdAt?: number | string;
744
+ updatedAt?: number | string;
701
745
  }
702
746
  interface KnowledgeSearchOptions {
703
747
  /** Max records to return (server-side clamped to 1..50, default 10). */
@@ -769,8 +813,12 @@ declare class PlatformClient {
769
813
  *
770
814
  * Reads are allowed when the SDK token's org matches the target org,
771
815
  * 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.
816
+ *
817
+ * Writes target system-owned (handler-managed) knowledge only: the
818
+ * protocol API stamps everything created here `isSystemOwned: true`,
819
+ * which keeps it out of every Studio UI surface — Studio acts as a
820
+ * plain storage + RAG layer for it. UI-managed knowledge cannot be
821
+ * modified through this surface.
774
822
  */
775
823
  knowledge: {
776
824
  /**
@@ -813,6 +861,43 @@ declare class PlatformClient {
813
861
  ragEnabled: boolean;
814
862
  backfillTriggered: boolean;
815
863
  }>;
864
+ /**
865
+ * Create a system-owned database knowledge under the token's org.
866
+ *
867
+ * 409 (surfaced as an error) means a knowledge of the same name
868
+ * already exists in the org. Idempotent callers should recover by
869
+ * listing with `includeSystemOwned: true` and matching on name.
870
+ */
871
+ create: (name: string, sheets: CreateKnowledgeSheet[], options?: CreateKnowledgeOptions) => Promise<PlatformKnowledge>;
872
+ /**
873
+ * Delete a system-owned knowledge and all of its records.
874
+ * Refused (403) for UI-managed knowledge.
875
+ */
876
+ delete: (id: string) => Promise<{
877
+ deletedRecords: number;
878
+ }>;
879
+ /**
880
+ * Append one record to a sheet. Embeds async when ragEnabled.
881
+ */
882
+ addRecord: (id: string, sheetId: string, data: Record<string, unknown>) => Promise<PlatformKnowledgeRecord>;
883
+ /**
884
+ * Replace a record's data payload. Re-embeds async when ragEnabled.
885
+ */
886
+ updateRecord: (id: string, recordId: string, data: Record<string, unknown>) => Promise<PlatformKnowledgeRecord>;
887
+ /** Delete one record. */
888
+ deleteRecord: (id: string, recordId: string) => Promise<void>;
889
+ /**
890
+ * Bulk-insert records into one sheet (each array entry becomes one
891
+ * record's `data`). With `replace: true` the sheet's existing
892
+ * records are deleted first — the full-resync primitive backfills
893
+ * use. Server caps a single call at 5000 records.
894
+ */
895
+ bulkRecords: (id: string, sheetId: string, records: Array<Record<string, unknown>>, options?: {
896
+ replace?: boolean;
897
+ }) => Promise<{
898
+ insertedCount: number;
899
+ deletedCount: number;
900
+ }>;
816
901
  };
817
902
  /**
818
903
  * Throughline (find-a-helpline) surface.
@@ -1123,4 +1208,4 @@ declare class LLMClient {
1123
1208
  */
1124
1209
  declare function createLLMClient(config: LLMClientConfig): LLMClient;
1125
1210
 
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 };
1211
+ 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
@@ -680,6 +680,14 @@ interface PlatformKnowledgeSummary {
680
680
  type?: string;
681
681
  /** Owning organization ID */
682
682
  organizationId: string;
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,42 @@ 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
+ /** Sheet definition for `knowledge.create`. */
717
+ interface CreateKnowledgeSheet {
718
+ /** Stable sheet id, referenced later by record writes and search. */
719
+ id: string;
720
+ name: string;
721
+ description?: string;
722
+ /**
723
+ * Column definitions ({ id, name, type, ... }). Loose-typed; the
724
+ * Studio schema validates `type` against its column-type enum.
725
+ */
726
+ columns?: Array<Record<string, unknown>>;
727
+ }
728
+ interface CreateKnowledgeOptions {
729
+ description?: string;
730
+ /**
731
+ * Enable semantic search at creation time. Defaults to false; can be
732
+ * flipped later with `setRagEnabled` (which also backfills embeddings
733
+ * for records inserted while the flag was off).
734
+ */
735
+ ragEnabled?: boolean;
736
+ }
737
+ /** A raw record as returned by the protocol record-write endpoints. */
738
+ interface PlatformKnowledgeRecord {
739
+ id: string;
740
+ knowledgeId: string;
741
+ sheetId: string;
742
+ data: Record<string, unknown>;
743
+ createdAt?: number | string;
744
+ updatedAt?: number | string;
701
745
  }
702
746
  interface KnowledgeSearchOptions {
703
747
  /** Max records to return (server-side clamped to 1..50, default 10). */
@@ -769,8 +813,12 @@ declare class PlatformClient {
769
813
  *
770
814
  * Reads are allowed when the SDK token's org matches the target org,
771
815
  * 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.
816
+ *
817
+ * Writes target system-owned (handler-managed) knowledge only: the
818
+ * protocol API stamps everything created here `isSystemOwned: true`,
819
+ * which keeps it out of every Studio UI surface — Studio acts as a
820
+ * plain storage + RAG layer for it. UI-managed knowledge cannot be
821
+ * modified through this surface.
774
822
  */
775
823
  knowledge: {
776
824
  /**
@@ -813,6 +861,43 @@ declare class PlatformClient {
813
861
  ragEnabled: boolean;
814
862
  backfillTriggered: boolean;
815
863
  }>;
864
+ /**
865
+ * Create a system-owned database knowledge under the token's org.
866
+ *
867
+ * 409 (surfaced as an error) means a knowledge of the same name
868
+ * already exists in the org. Idempotent callers should recover by
869
+ * listing with `includeSystemOwned: true` and matching on name.
870
+ */
871
+ create: (name: string, sheets: CreateKnowledgeSheet[], options?: CreateKnowledgeOptions) => Promise<PlatformKnowledge>;
872
+ /**
873
+ * Delete a system-owned knowledge and all of its records.
874
+ * Refused (403) for UI-managed knowledge.
875
+ */
876
+ delete: (id: string) => Promise<{
877
+ deletedRecords: number;
878
+ }>;
879
+ /**
880
+ * Append one record to a sheet. Embeds async when ragEnabled.
881
+ */
882
+ addRecord: (id: string, sheetId: string, data: Record<string, unknown>) => Promise<PlatformKnowledgeRecord>;
883
+ /**
884
+ * Replace a record's data payload. Re-embeds async when ragEnabled.
885
+ */
886
+ updateRecord: (id: string, recordId: string, data: Record<string, unknown>) => Promise<PlatformKnowledgeRecord>;
887
+ /** Delete one record. */
888
+ deleteRecord: (id: string, recordId: string) => Promise<void>;
889
+ /**
890
+ * Bulk-insert records into one sheet (each array entry becomes one
891
+ * record's `data`). With `replace: true` the sheet's existing
892
+ * records are deleted first — the full-resync primitive backfills
893
+ * use. Server caps a single call at 5000 records.
894
+ */
895
+ bulkRecords: (id: string, sheetId: string, records: Array<Record<string, unknown>>, options?: {
896
+ replace?: boolean;
897
+ }) => Promise<{
898
+ insertedCount: number;
899
+ deletedCount: number;
900
+ }>;
816
901
  };
817
902
  /**
818
903
  * Throughline (find-a-helpline) surface.
@@ -1123,4 +1208,4 @@ declare class LLMClient {
1123
1208
  */
1124
1209
  declare function createLLMClient(config: LLMClientConfig): LLMClient;
1125
1210
 
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 };
1211
+ 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,12 @@ 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.orgId) params.set("organizationId", options.orgId);
361
+ if (options.includeSystemOwned) params.set("includeSystemOwned", "1");
362
+ const qsStr = params.toString();
356
363
  const data = await this.request(
357
- `/api/protocol/knowledge${qs}`,
364
+ `/api/protocol/knowledge${qsStr ? `?${qsStr}` : ""}`,
358
365
  "Failed to list knowledge"
359
366
  );
360
367
  return data.knowledge;
@@ -416,6 +423,92 @@ var PlatformClient = class {
416
423
  { method: "POST", body: { enabled } }
417
424
  );
418
425
  return data.knowledge;
426
+ },
427
+ /**
428
+ * Create a system-owned database knowledge under the token's org.
429
+ *
430
+ * 409 (surfaced as an error) means a knowledge of the same name
431
+ * already exists in the org. Idempotent callers should recover by
432
+ * listing with `includeSystemOwned: true` and matching on name.
433
+ */
434
+ create: async (name, sheets, options = {}) => {
435
+ const data = await this.request(
436
+ "/api/protocol/knowledge",
437
+ "Failed to create knowledge",
438
+ {
439
+ method: "POST",
440
+ body: {
441
+ name,
442
+ sheets,
443
+ ...options.description !== void 0 ? { description: options.description } : {},
444
+ ...options.ragEnabled !== void 0 ? { ragEnabled: options.ragEnabled } : {}
445
+ }
446
+ }
447
+ );
448
+ return data.knowledge;
449
+ },
450
+ /**
451
+ * Delete a system-owned knowledge and all of its records.
452
+ * Refused (403) for UI-managed knowledge.
453
+ */
454
+ delete: async (id) => {
455
+ const data = await this.request(
456
+ `/api/protocol/knowledge/${encodeURIComponent(id)}`,
457
+ "Failed to delete knowledge",
458
+ { method: "DELETE" }
459
+ );
460
+ return { deletedRecords: data.deletedRecords };
461
+ },
462
+ /**
463
+ * Append one record to a sheet. Embeds async when ragEnabled.
464
+ */
465
+ addRecord: async (id, sheetId, data) => {
466
+ const res = await this.request(
467
+ `/api/protocol/knowledge/${encodeURIComponent(id)}/records`,
468
+ "Failed to create record",
469
+ { method: "POST", body: { sheetId, data } }
470
+ );
471
+ return res.record;
472
+ },
473
+ /**
474
+ * Replace a record's data payload. Re-embeds async when ragEnabled.
475
+ */
476
+ updateRecord: async (id, recordId, data) => {
477
+ const res = await this.request(
478
+ `/api/protocol/knowledge/${encodeURIComponent(id)}/records/${encodeURIComponent(recordId)}`,
479
+ "Failed to update record",
480
+ { method: "PUT", body: { data } }
481
+ );
482
+ return res.record;
483
+ },
484
+ /** Delete one record. */
485
+ deleteRecord: async (id, recordId) => {
486
+ await this.request(
487
+ `/api/protocol/knowledge/${encodeURIComponent(id)}/records/${encodeURIComponent(recordId)}`,
488
+ "Failed to delete record",
489
+ { method: "DELETE" }
490
+ );
491
+ },
492
+ /**
493
+ * Bulk-insert records into one sheet (each array entry becomes one
494
+ * record's `data`). With `replace: true` the sheet's existing
495
+ * records are deleted first — the full-resync primitive backfills
496
+ * use. Server caps a single call at 5000 records.
497
+ */
498
+ bulkRecords: async (id, sheetId, records, options = {}) => {
499
+ const data = await this.request(
500
+ `/api/protocol/knowledge/${encodeURIComponent(id)}/records/bulk`,
501
+ "Failed to bulk-write records",
502
+ {
503
+ method: "POST",
504
+ body: {
505
+ sheetId,
506
+ records,
507
+ ...options.replace !== void 0 ? { replace: options.replace } : {}
508
+ }
509
+ }
510
+ );
511
+ return { insertedCount: data.insertedCount, deletedCount: data.deletedCount };
419
512
  }
420
513
  };
421
514
  /**