weave-typescript 0.44.0 → 0.46.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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listEntitiesByThreadQuery = exports.upsertEntityRelationshipQuery = exports.upsertThreadEntityQuery = exports.upsertEntityQuery = exports.listThreadActivityByThreadQuery = exports.createThreadActivityQuery = exports.listThreadReconciliationByPendingThreadQuery = exports.upsertThreadReconciliationQuery = exports.deleteThreadReconciliationByPendingThreadQuery = exports.getIngestionRunThreadCountsQuery = exports.listThreadsByIDsQuery = exports.listThreadsBySupersedesQuery = exports.markThreadsSupersededQuery = exports.bulkRejectThreadsQuery = exports.rejectThreadQuery = exports.bulkApproveThreadsQuery = exports.approveThreadQuery = exports.deleteDocumentThreadByOrganizationAndIDQuery = exports.editDocumentThreadQuery = exports.editPendingThreadQuery = exports.updateThreadClassificationQuery = exports.promoteThreadNextEmbeddingsByOrganizationQuery = exports.setThreadNextEmbeddingQuery = exports.updateThreadEmbeddingQuery = exports.listPendingThreadsByOrganizationQuery = exports.listPendingThreadsByRunQuery = exports.listThreadsByDocumentQuery = exports.listThreadsByIngestionRunQuery = exports.getThreadByOrganizationAndIDQuery = exports.createThreadQuery = exports.deleteDocumentByOrganizationAndIDQuery = exports.listDocumentTagsByDocumentIDQuery = exports.createDocumentTagQuery = exports.deleteDocumentTagByDocumentIDAndTagQuery = exports.deleteDocumentTagsByDocumentIDQuery = exports.listIngestionHistoryQuery = exports.listIngestionRunsByDocumentQuery = exports.listIngestionRunsByOrganizationQuery = exports.updateIngestionRunStateQuery = exports.getIngestionRunByOrganizationAndIDQuery = exports.createIngestionRunQuery = exports.getDatabaseConfigQuery = exports.getAccessibleDocumentSummaryQuery = exports.listAccessibleDocumentSummariesQuery = exports.listDocumentsByOrganizationQuery = exports.setDocumentStatusQuery = exports.setDocumentParseResultQuery = exports.getDocumentByOrganizationAndFingerprintQuery = exports.getDocumentByOrganizationAndIDQuery = exports.createDocumentQuery = void 0;
4
- exports.deactivateFacetConfigQuery = exports.upsertFacetConfigQuery = exports.listActiveFacetConfigsQuery = exports.listFacetConfigsQuery = exports.syncOrganizationIngestionReasoningDefaultsQuery = exports.upsertOrganizationIngestionSettingsQuery = exports.getOrganizationIngestionSettingsQuery = exports.ensureOrganizationIngestionSettingsQuery = void 0;
4
+ exports.deactivateFacetConfigQuery = exports.upsertFacetConfigQuery = exports.listActiveFacetConfigsQuery = exports.listFacetConfigsQuery = exports.deleteThreadFacetsByThreadQuery = exports.upsertThreadFacetQuery = exports.listThreadFacetsByThreadIDsQuery = exports.syncOrganizationIngestionReasoningDefaultsQuery = exports.upsertOrganizationIngestionStageSettingsQuery = exports.upsertOrganizationIngestionSettingsQuery = exports.getOrganizationIngestionSettingsQuery = exports.ensureOrganizationIngestionSettingsQuery = void 0;
5
5
  exports.createDocument = createDocument;
6
6
  exports.getDocumentByOrganizationAndID = getDocumentByOrganizationAndID;
7
7
  exports.getDocumentByOrganizationAndFingerprint = getDocumentByOrganizationAndFingerprint;
@@ -50,7 +50,10 @@ exports.listEntitiesByThread = listEntitiesByThread;
50
50
  exports.ensureOrganizationIngestionSettings = ensureOrganizationIngestionSettings;
51
51
  exports.getOrganizationIngestionSettings = getOrganizationIngestionSettings;
52
52
  exports.upsertOrganizationIngestionSettings = upsertOrganizationIngestionSettings;
53
+ exports.upsertOrganizationIngestionStageSettings = upsertOrganizationIngestionStageSettings;
53
54
  exports.syncOrganizationIngestionReasoningDefaults = syncOrganizationIngestionReasoningDefaults;
55
+ exports.listThreadFacetsByThreadIDs = listThreadFacetsByThreadIDs;
56
+ exports.upsertThreadFacet = upsertThreadFacet;
54
57
  exports.listFacetConfigs = listFacetConfigs;
55
58
  exports.listActiveFacetConfigs = listActiveFacetConfigs;
56
59
  exports.upsertFacetConfig = upsertFacetConfig;
@@ -684,7 +687,9 @@ INSERT INTO weave.ingestion_runs (
684
687
  reasoning_provider_configuration_id,
685
688
  embedding_model_id,
686
689
  embedding_provider_configuration_id,
687
- embedding_dimensions
690
+ embedding_dimensions,
691
+ stage_model_settings,
692
+ refine_loop_count
688
693
  ) VALUES (
689
694
  $1,
690
695
  $2,
@@ -694,7 +699,9 @@ INSERT INTO weave.ingestion_runs (
694
699
  $6,
695
700
  $7,
696
701
  $8,
697
- $9
702
+ $9,
703
+ $10,
704
+ $11
698
705
  )
699
706
  RETURNING
700
707
  id,
@@ -706,6 +713,8 @@ RETURNING
706
713
  embedding_model_id,
707
714
  embedding_provider_configuration_id,
708
715
  embedding_dimensions,
716
+ stage_model_settings,
717
+ refine_loop_count,
709
718
  thread_count,
710
719
  pending_count,
711
720
  approved_count,
@@ -718,7 +727,7 @@ RETURNING
718
727
  async function createIngestionRun(client, args) {
719
728
  const result = await client.query({
720
729
  text: exports.createIngestionRunQuery,
721
- values: [args.id, args.organizationId, args.documentId, args.status, args.reasoningModelId, args.reasoningProviderConfigurationId, args.embeddingModelId, args.embeddingProviderConfigurationId, args.embeddingDimensions],
730
+ values: [args.id, args.organizationId, args.documentId, args.status, args.reasoningModelId, args.reasoningProviderConfigurationId, args.embeddingModelId, args.embeddingProviderConfigurationId, args.embeddingDimensions, args.stageModelSettings, args.refineLoopCount],
722
731
  rowMode: "array"
723
732
  });
724
733
  if (result.rows.length !== 1) {
@@ -735,15 +744,17 @@ async function createIngestionRun(client, args) {
735
744
  embeddingModelId: row[6],
736
745
  embeddingProviderConfigurationId: row[7],
737
746
  embeddingDimensions: row[8],
738
- threadCount: row[9],
739
- pendingCount: row[10],
740
- approvedCount: row[11],
741
- rejectedCount: row[12],
742
- error: row[13],
743
- tokenUsage: row[14],
744
- startedAt: row[15],
745
- completedAt: row[16],
746
- committedAt: row[17]
747
+ stageModelSettings: row[9],
748
+ refineLoopCount: row[10],
749
+ threadCount: row[11],
750
+ pendingCount: row[12],
751
+ approvedCount: row[13],
752
+ rejectedCount: row[14],
753
+ error: row[15],
754
+ tokenUsage: row[16],
755
+ startedAt: row[17],
756
+ completedAt: row[18],
757
+ committedAt: row[19]
747
758
  };
748
759
  }
749
760
  exports.getIngestionRunByOrganizationAndIDQuery = `-- name: GetIngestionRunByOrganizationAndID :one
@@ -757,6 +768,8 @@ SELECT
757
768
  embedding_model_id,
758
769
  embedding_provider_configuration_id,
759
770
  embedding_dimensions,
771
+ stage_model_settings,
772
+ refine_loop_count,
760
773
  thread_count,
761
774
  pending_count,
762
775
  approved_count,
@@ -789,15 +802,17 @@ async function getIngestionRunByOrganizationAndID(client, args) {
789
802
  embeddingModelId: row[6],
790
803
  embeddingProviderConfigurationId: row[7],
791
804
  embeddingDimensions: row[8],
792
- threadCount: row[9],
793
- pendingCount: row[10],
794
- approvedCount: row[11],
795
- rejectedCount: row[12],
796
- error: row[13],
797
- tokenUsage: row[14],
798
- startedAt: row[15],
799
- completedAt: row[16],
800
- committedAt: row[17]
805
+ stageModelSettings: row[9],
806
+ refineLoopCount: row[10],
807
+ threadCount: row[11],
808
+ pendingCount: row[12],
809
+ approvedCount: row[13],
810
+ rejectedCount: row[14],
811
+ error: row[15],
812
+ tokenUsage: row[16],
813
+ startedAt: row[17],
814
+ completedAt: row[18],
815
+ committedAt: row[19]
801
816
  };
802
817
  }
803
818
  exports.updateIngestionRunStateQuery = `-- name: UpdateIngestionRunState :one
@@ -824,6 +839,8 @@ RETURNING
824
839
  embedding_model_id,
825
840
  embedding_provider_configuration_id,
826
841
  embedding_dimensions,
842
+ stage_model_settings,
843
+ refine_loop_count,
827
844
  thread_count,
828
845
  pending_count,
829
846
  approved_count,
@@ -853,15 +870,17 @@ async function updateIngestionRunState(client, args) {
853
870
  embeddingModelId: row[6],
854
871
  embeddingProviderConfigurationId: row[7],
855
872
  embeddingDimensions: row[8],
856
- threadCount: row[9],
857
- pendingCount: row[10],
858
- approvedCount: row[11],
859
- rejectedCount: row[12],
860
- error: row[13],
861
- tokenUsage: row[14],
862
- startedAt: row[15],
863
- completedAt: row[16],
864
- committedAt: row[17]
873
+ stageModelSettings: row[9],
874
+ refineLoopCount: row[10],
875
+ threadCount: row[11],
876
+ pendingCount: row[12],
877
+ approvedCount: row[13],
878
+ rejectedCount: row[14],
879
+ error: row[15],
880
+ tokenUsage: row[16],
881
+ startedAt: row[17],
882
+ completedAt: row[18],
883
+ committedAt: row[19]
865
884
  };
866
885
  }
867
886
  exports.listIngestionRunsByOrganizationQuery = `-- name: ListIngestionRunsByOrganization :many
@@ -875,6 +894,8 @@ SELECT
875
894
  embedding_model_id,
876
895
  embedding_provider_configuration_id,
877
896
  embedding_dimensions,
897
+ stage_model_settings,
898
+ refine_loop_count,
878
899
  thread_count,
879
900
  pending_count,
880
901
  approved_count,
@@ -905,15 +926,17 @@ async function listIngestionRunsByOrganization(client, args) {
905
926
  embeddingModelId: row[6],
906
927
  embeddingProviderConfigurationId: row[7],
907
928
  embeddingDimensions: row[8],
908
- threadCount: row[9],
909
- pendingCount: row[10],
910
- approvedCount: row[11],
911
- rejectedCount: row[12],
912
- error: row[13],
913
- tokenUsage: row[14],
914
- startedAt: row[15],
915
- completedAt: row[16],
916
- committedAt: row[17]
929
+ stageModelSettings: row[9],
930
+ refineLoopCount: row[10],
931
+ threadCount: row[11],
932
+ pendingCount: row[12],
933
+ approvedCount: row[13],
934
+ rejectedCount: row[14],
935
+ error: row[15],
936
+ tokenUsage: row[16],
937
+ startedAt: row[17],
938
+ completedAt: row[18],
939
+ committedAt: row[19]
917
940
  };
918
941
  });
919
942
  }
@@ -928,6 +951,8 @@ SELECT
928
951
  embedding_model_id,
929
952
  embedding_provider_configuration_id,
930
953
  embedding_dimensions,
954
+ stage_model_settings,
955
+ refine_loop_count,
931
956
  thread_count,
932
957
  pending_count,
933
958
  approved_count,
@@ -958,15 +983,17 @@ async function listIngestionRunsByDocument(client, args) {
958
983
  embeddingModelId: row[6],
959
984
  embeddingProviderConfigurationId: row[7],
960
985
  embeddingDimensions: row[8],
961
- threadCount: row[9],
962
- pendingCount: row[10],
963
- approvedCount: row[11],
964
- rejectedCount: row[12],
965
- error: row[13],
966
- tokenUsage: row[14],
967
- startedAt: row[15],
968
- completedAt: row[16],
969
- committedAt: row[17]
986
+ stageModelSettings: row[9],
987
+ refineLoopCount: row[10],
988
+ threadCount: row[11],
989
+ pendingCount: row[12],
990
+ approvedCount: row[13],
991
+ rejectedCount: row[14],
992
+ error: row[15],
993
+ tokenUsage: row[16],
994
+ startedAt: row[17],
995
+ completedAt: row[18],
996
+ committedAt: row[19]
970
997
  };
971
998
  });
972
999
  }
@@ -2612,6 +2639,19 @@ WITH upsert AS (
2612
2639
  reasoning_provider_configuration_id,
2613
2640
  embedding_model_id,
2614
2641
  embedding_provider_configuration_id,
2642
+ classify_model_id,
2643
+ classify_provider_configuration_id,
2644
+ refine_model_id,
2645
+ refine_provider_configuration_id,
2646
+ extract_model_id,
2647
+ extract_provider_configuration_id,
2648
+ embed_model_id,
2649
+ embed_provider_configuration_id,
2650
+ reconcile_model_id,
2651
+ reconcile_provider_configuration_id,
2652
+ diff_model_id,
2653
+ diff_provider_configuration_id,
2654
+ refine_loop_count,
2615
2655
  updated_at
2616
2656
  )
2617
2657
  SELECT
@@ -2620,7 +2660,21 @@ SELECT
2620
2660
  upsert.reasoning_provider_configuration_id,
2621
2661
  upsert.embedding_model_id,
2622
2662
  upsert.embedding_provider_configuration_id,
2663
+ upsert.classify_model_id,
2664
+ upsert.classify_provider_configuration_id,
2665
+ upsert.refine_model_id,
2666
+ upsert.refine_provider_configuration_id,
2667
+ upsert.extract_model_id,
2668
+ upsert.extract_provider_configuration_id,
2669
+ upsert.embed_model_id,
2670
+ upsert.embed_provider_configuration_id,
2671
+ upsert.reconcile_model_id,
2672
+ upsert.reconcile_provider_configuration_id,
2673
+ upsert.diff_model_id,
2674
+ upsert.diff_provider_configuration_id,
2623
2675
  cfg.embedding_dimension AS embedding_dimensions,
2676
+ cfg.embedding_dimension AS embed_dimensions,
2677
+ upsert.refine_loop_count,
2624
2678
  upsert.updated_at
2625
2679
  FROM upsert
2626
2680
  JOIN weave.database_config cfg
@@ -2641,8 +2695,22 @@ async function ensureOrganizationIngestionSettings(client, args) {
2641
2695
  reasoningProviderConfigurationId: row[2],
2642
2696
  embeddingModelId: row[3],
2643
2697
  embeddingProviderConfigurationId: row[4],
2644
- embeddingDimensions: row[5],
2645
- updatedAt: row[6]
2698
+ classifyModelId: row[5],
2699
+ classifyProviderConfigurationId: row[6],
2700
+ refineModelId: row[7],
2701
+ refineProviderConfigurationId: row[8],
2702
+ extractModelId: row[9],
2703
+ extractProviderConfigurationId: row[10],
2704
+ embedModelId: row[11],
2705
+ embedProviderConfigurationId: row[12],
2706
+ reconcileModelId: row[13],
2707
+ reconcileProviderConfigurationId: row[14],
2708
+ diffModelId: row[15],
2709
+ diffProviderConfigurationId: row[16],
2710
+ embeddingDimensions: row[17],
2711
+ embedDimensions: row[18],
2712
+ refineLoopCount: row[19],
2713
+ updatedAt: row[20]
2646
2714
  };
2647
2715
  }
2648
2716
  exports.getOrganizationIngestionSettingsQuery = `-- name: GetOrganizationIngestionSettings :one
@@ -2652,7 +2720,21 @@ SELECT
2652
2720
  settings.reasoning_provider_configuration_id,
2653
2721
  settings.embedding_model_id,
2654
2722
  settings.embedding_provider_configuration_id,
2723
+ settings.classify_model_id,
2724
+ settings.classify_provider_configuration_id,
2725
+ settings.refine_model_id,
2726
+ settings.refine_provider_configuration_id,
2727
+ settings.extract_model_id,
2728
+ settings.extract_provider_configuration_id,
2729
+ settings.embed_model_id,
2730
+ settings.embed_provider_configuration_id,
2731
+ settings.reconcile_model_id,
2732
+ settings.reconcile_provider_configuration_id,
2733
+ settings.diff_model_id,
2734
+ settings.diff_provider_configuration_id,
2655
2735
  cfg.embedding_dimension AS embedding_dimensions,
2736
+ cfg.embedding_dimension AS embed_dimensions,
2737
+ settings.refine_loop_count,
2656
2738
  settings.updated_at
2657
2739
  FROM weave.org_ingestion_settings settings
2658
2740
  JOIN weave.database_config cfg
@@ -2674,8 +2756,22 @@ async function getOrganizationIngestionSettings(client, args) {
2674
2756
  reasoningProviderConfigurationId: row[2],
2675
2757
  embeddingModelId: row[3],
2676
2758
  embeddingProviderConfigurationId: row[4],
2677
- embeddingDimensions: row[5],
2678
- updatedAt: row[6]
2759
+ classifyModelId: row[5],
2760
+ classifyProviderConfigurationId: row[6],
2761
+ refineModelId: row[7],
2762
+ refineProviderConfigurationId: row[8],
2763
+ extractModelId: row[9],
2764
+ extractProviderConfigurationId: row[10],
2765
+ embedModelId: row[11],
2766
+ embedProviderConfigurationId: row[12],
2767
+ reconcileModelId: row[13],
2768
+ reconcileProviderConfigurationId: row[14],
2769
+ diffModelId: row[15],
2770
+ diffProviderConfigurationId: row[16],
2771
+ embeddingDimensions: row[17],
2772
+ embedDimensions: row[18],
2773
+ refineLoopCount: row[19],
2774
+ updatedAt: row[20]
2679
2775
  };
2680
2776
  }
2681
2777
  exports.upsertOrganizationIngestionSettingsQuery = `-- name: UpsertOrganizationIngestionSettings :one
@@ -2690,14 +2786,38 @@ WITH cfg AS (
2690
2786
  reasoning_model_id,
2691
2787
  reasoning_provider_configuration_id,
2692
2788
  embedding_model_id,
2693
- embedding_provider_configuration_id
2789
+ embedding_provider_configuration_id,
2790
+ classify_model_id,
2791
+ classify_provider_configuration_id,
2792
+ refine_model_id,
2793
+ refine_provider_configuration_id,
2794
+ extract_model_id,
2795
+ extract_provider_configuration_id,
2796
+ embed_model_id,
2797
+ embed_provider_configuration_id,
2798
+ reconcile_model_id,
2799
+ reconcile_provider_configuration_id,
2800
+ diff_model_id,
2801
+ diff_provider_configuration_id
2694
2802
  )
2695
2803
  SELECT
2696
2804
  $2,
2697
2805
  $3,
2698
2806
  $4,
2699
2807
  $5,
2700
- $6
2808
+ $6,
2809
+ $3,
2810
+ $4,
2811
+ $3,
2812
+ $4,
2813
+ $3,
2814
+ $4,
2815
+ $5,
2816
+ $6,
2817
+ $3,
2818
+ $4,
2819
+ $3,
2820
+ $4
2701
2821
  FROM cfg
2702
2822
  ON CONFLICT (organization_id) DO UPDATE
2703
2823
  SET
@@ -2705,6 +2825,18 @@ WITH cfg AS (
2705
2825
  reasoning_provider_configuration_id = EXCLUDED.reasoning_provider_configuration_id,
2706
2826
  embedding_model_id = EXCLUDED.embedding_model_id,
2707
2827
  embedding_provider_configuration_id = EXCLUDED.embedding_provider_configuration_id,
2828
+ classify_model_id = EXCLUDED.classify_model_id,
2829
+ classify_provider_configuration_id = EXCLUDED.classify_provider_configuration_id,
2830
+ refine_model_id = EXCLUDED.refine_model_id,
2831
+ refine_provider_configuration_id = EXCLUDED.refine_provider_configuration_id,
2832
+ extract_model_id = EXCLUDED.extract_model_id,
2833
+ extract_provider_configuration_id = EXCLUDED.extract_provider_configuration_id,
2834
+ embed_model_id = EXCLUDED.embed_model_id,
2835
+ embed_provider_configuration_id = EXCLUDED.embed_provider_configuration_id,
2836
+ reconcile_model_id = EXCLUDED.reconcile_model_id,
2837
+ reconcile_provider_configuration_id = EXCLUDED.reconcile_provider_configuration_id,
2838
+ diff_model_id = EXCLUDED.diff_model_id,
2839
+ diff_provider_configuration_id = EXCLUDED.diff_provider_configuration_id,
2708
2840
  updated_at = now()
2709
2841
  RETURNING
2710
2842
  organization_id,
@@ -2712,6 +2844,19 @@ WITH cfg AS (
2712
2844
  reasoning_provider_configuration_id,
2713
2845
  embedding_model_id,
2714
2846
  embedding_provider_configuration_id,
2847
+ classify_model_id,
2848
+ classify_provider_configuration_id,
2849
+ refine_model_id,
2850
+ refine_provider_configuration_id,
2851
+ extract_model_id,
2852
+ extract_provider_configuration_id,
2853
+ embed_model_id,
2854
+ embed_provider_configuration_id,
2855
+ reconcile_model_id,
2856
+ reconcile_provider_configuration_id,
2857
+ diff_model_id,
2858
+ diff_provider_configuration_id,
2859
+ refine_loop_count,
2715
2860
  updated_at
2716
2861
  )
2717
2862
  SELECT
@@ -2720,7 +2865,21 @@ SELECT
2720
2865
  upsert.reasoning_provider_configuration_id,
2721
2866
  upsert.embedding_model_id,
2722
2867
  upsert.embedding_provider_configuration_id,
2868
+ upsert.classify_model_id,
2869
+ upsert.classify_provider_configuration_id,
2870
+ upsert.refine_model_id,
2871
+ upsert.refine_provider_configuration_id,
2872
+ upsert.extract_model_id,
2873
+ upsert.extract_provider_configuration_id,
2874
+ upsert.embed_model_id,
2875
+ upsert.embed_provider_configuration_id,
2876
+ upsert.reconcile_model_id,
2877
+ upsert.reconcile_provider_configuration_id,
2878
+ upsert.diff_model_id,
2879
+ upsert.diff_provider_configuration_id,
2723
2880
  cfg.embedding_dimension AS embedding_dimensions,
2881
+ cfg.embedding_dimension AS embed_dimensions,
2882
+ upsert.refine_loop_count,
2724
2883
  upsert.updated_at
2725
2884
  FROM upsert
2726
2885
  JOIN cfg
@@ -2741,8 +2900,145 @@ async function upsertOrganizationIngestionSettings(client, args) {
2741
2900
  reasoningProviderConfigurationId: row[2],
2742
2901
  embeddingModelId: row[3],
2743
2902
  embeddingProviderConfigurationId: row[4],
2744
- embeddingDimensions: row[5],
2745
- updatedAt: row[6]
2903
+ classifyModelId: row[5],
2904
+ classifyProviderConfigurationId: row[6],
2905
+ refineModelId: row[7],
2906
+ refineProviderConfigurationId: row[8],
2907
+ extractModelId: row[9],
2908
+ extractProviderConfigurationId: row[10],
2909
+ embedModelId: row[11],
2910
+ embedProviderConfigurationId: row[12],
2911
+ reconcileModelId: row[13],
2912
+ reconcileProviderConfigurationId: row[14],
2913
+ diffModelId: row[15],
2914
+ diffProviderConfigurationId: row[16],
2915
+ embeddingDimensions: row[17],
2916
+ embedDimensions: row[18],
2917
+ refineLoopCount: row[19],
2918
+ updatedAt: row[20]
2919
+ };
2920
+ }
2921
+ exports.upsertOrganizationIngestionStageSettingsQuery = `-- name: UpsertOrganizationIngestionStageSettings :one
2922
+ WITH cfg AS (
2923
+ SELECT embedding_dimension
2924
+ FROM weave.database_config
2925
+ WHERE id = 1
2926
+ AND ($1 = 0 OR $1 = embedding_dimension)
2927
+ ), upsert AS (
2928
+ INSERT INTO weave.org_ingestion_settings (
2929
+ organization_id,
2930
+ classify_model_id,
2931
+ classify_provider_configuration_id,
2932
+ refine_model_id,
2933
+ refine_provider_configuration_id,
2934
+ extract_model_id,
2935
+ extract_provider_configuration_id,
2936
+ embed_model_id,
2937
+ embed_provider_configuration_id,
2938
+ reconcile_model_id,
2939
+ reconcile_provider_configuration_id,
2940
+ diff_model_id,
2941
+ diff_provider_configuration_id,
2942
+ refine_loop_count
2943
+ )
2944
+ SELECT
2945
+ $2,
2946
+ $3,
2947
+ $4,
2948
+ $5,
2949
+ $6,
2950
+ $7,
2951
+ $8,
2952
+ $9,
2953
+ $10,
2954
+ $11,
2955
+ $12,
2956
+ $13,
2957
+ $14,
2958
+ $15
2959
+ FROM cfg
2960
+ ON CONFLICT (organization_id) DO UPDATE
2961
+ SET
2962
+ classify_model_id = EXCLUDED.classify_model_id,
2963
+ classify_provider_configuration_id = EXCLUDED.classify_provider_configuration_id,
2964
+ refine_model_id = EXCLUDED.refine_model_id,
2965
+ refine_provider_configuration_id = EXCLUDED.refine_provider_configuration_id,
2966
+ extract_model_id = EXCLUDED.extract_model_id,
2967
+ extract_provider_configuration_id = EXCLUDED.extract_provider_configuration_id,
2968
+ embed_model_id = EXCLUDED.embed_model_id,
2969
+ embed_provider_configuration_id = EXCLUDED.embed_provider_configuration_id,
2970
+ reconcile_model_id = EXCLUDED.reconcile_model_id,
2971
+ reconcile_provider_configuration_id = EXCLUDED.reconcile_provider_configuration_id,
2972
+ diff_model_id = EXCLUDED.diff_model_id,
2973
+ diff_provider_configuration_id = EXCLUDED.diff_provider_configuration_id,
2974
+ refine_loop_count = EXCLUDED.refine_loop_count,
2975
+ updated_at = now()
2976
+ RETURNING
2977
+ organization_id,
2978
+ classify_model_id,
2979
+ classify_provider_configuration_id,
2980
+ refine_model_id,
2981
+ refine_provider_configuration_id,
2982
+ extract_model_id,
2983
+ extract_provider_configuration_id,
2984
+ embed_model_id,
2985
+ embed_provider_configuration_id,
2986
+ reconcile_model_id,
2987
+ reconcile_provider_configuration_id,
2988
+ diff_model_id,
2989
+ diff_provider_configuration_id,
2990
+ refine_loop_count,
2991
+ updated_at
2992
+ )
2993
+ SELECT
2994
+ upsert.organization_id,
2995
+ upsert.classify_model_id,
2996
+ upsert.classify_provider_configuration_id,
2997
+ upsert.refine_model_id,
2998
+ upsert.refine_provider_configuration_id,
2999
+ upsert.extract_model_id,
3000
+ upsert.extract_provider_configuration_id,
3001
+ upsert.embed_model_id,
3002
+ upsert.embed_provider_configuration_id,
3003
+ upsert.reconcile_model_id,
3004
+ upsert.reconcile_provider_configuration_id,
3005
+ upsert.diff_model_id,
3006
+ upsert.diff_provider_configuration_id,
3007
+ cfg.embedding_dimension AS embedding_dimensions,
3008
+ cfg.embedding_dimension AS embed_dimensions,
3009
+ upsert.refine_loop_count,
3010
+ upsert.updated_at
3011
+ FROM upsert
3012
+ JOIN cfg
3013
+ ON TRUE`;
3014
+ async function upsertOrganizationIngestionStageSettings(client, args) {
3015
+ const result = await client.query({
3016
+ text: exports.upsertOrganizationIngestionStageSettingsQuery,
3017
+ values: [args.embedDimensions, args.organizationId, args.classifyModelId, args.classifyProviderConfigurationId, args.refineModelId, args.refineProviderConfigurationId, args.extractModelId, args.extractProviderConfigurationId, args.embedModelId, args.embedProviderConfigurationId, args.reconcileModelId, args.reconcileProviderConfigurationId, args.diffModelId, args.diffProviderConfigurationId, args.refineLoopCount],
3018
+ rowMode: "array"
3019
+ });
3020
+ if (result.rows.length !== 1) {
3021
+ return null;
3022
+ }
3023
+ const row = result.rows[0];
3024
+ return {
3025
+ organizationId: row[0],
3026
+ classifyModelId: row[1],
3027
+ classifyProviderConfigurationId: row[2],
3028
+ refineModelId: row[3],
3029
+ refineProviderConfigurationId: row[4],
3030
+ extractModelId: row[5],
3031
+ extractProviderConfigurationId: row[6],
3032
+ embedModelId: row[7],
3033
+ embedProviderConfigurationId: row[8],
3034
+ reconcileModelId: row[9],
3035
+ reconcileProviderConfigurationId: row[10],
3036
+ diffModelId: row[11],
3037
+ diffProviderConfigurationId: row[12],
3038
+ embeddingDimensions: row[13],
3039
+ embedDimensions: row[14],
3040
+ refineLoopCount: row[15],
3041
+ updatedAt: row[16]
2746
3042
  };
2747
3043
  }
2748
3044
  exports.syncOrganizationIngestionReasoningDefaultsQuery = `-- name: SyncOrganizationIngestionReasoningDefaults :one
@@ -2754,11 +3050,31 @@ WITH cfg AS (
2754
3050
  INSERT INTO weave.org_ingestion_settings (
2755
3051
  organization_id,
2756
3052
  reasoning_model_id,
2757
- reasoning_provider_configuration_id
3053
+ reasoning_provider_configuration_id,
3054
+ classify_model_id,
3055
+ classify_provider_configuration_id,
3056
+ refine_model_id,
3057
+ refine_provider_configuration_id,
3058
+ extract_model_id,
3059
+ extract_provider_configuration_id,
3060
+ reconcile_model_id,
3061
+ reconcile_provider_configuration_id,
3062
+ diff_model_id,
3063
+ diff_provider_configuration_id
2758
3064
  )
2759
3065
  SELECT
2760
3066
  cs.organization_id,
2761
3067
  cs.default_chat_model_id,
3068
+ cs.default_provider_configuration_id,
3069
+ cs.default_chat_model_id,
3070
+ cs.default_provider_configuration_id,
3071
+ cs.default_chat_model_id,
3072
+ cs.default_provider_configuration_id,
3073
+ cs.default_chat_model_id,
3074
+ cs.default_provider_configuration_id,
3075
+ cs.default_chat_model_id,
3076
+ cs.default_provider_configuration_id,
3077
+ cs.default_chat_model_id,
2762
3078
  cs.default_provider_configuration_id
2763
3079
  FROM weave.organization_chat_settings cs
2764
3080
  WHERE cs.organization_id = $1
@@ -2769,6 +3085,31 @@ WITH cfg AS (
2769
3085
  weave.org_ingestion_settings.reasoning_provider_configuration_id,
2770
3086
  EXCLUDED.reasoning_provider_configuration_id
2771
3087
  ),
3088
+ classify_model_id = COALESCE(weave.org_ingestion_settings.classify_model_id, EXCLUDED.classify_model_id),
3089
+ classify_provider_configuration_id = COALESCE(
3090
+ weave.org_ingestion_settings.classify_provider_configuration_id,
3091
+ EXCLUDED.classify_provider_configuration_id
3092
+ ),
3093
+ refine_model_id = COALESCE(weave.org_ingestion_settings.refine_model_id, EXCLUDED.refine_model_id),
3094
+ refine_provider_configuration_id = COALESCE(
3095
+ weave.org_ingestion_settings.refine_provider_configuration_id,
3096
+ EXCLUDED.refine_provider_configuration_id
3097
+ ),
3098
+ extract_model_id = COALESCE(weave.org_ingestion_settings.extract_model_id, EXCLUDED.extract_model_id),
3099
+ extract_provider_configuration_id = COALESCE(
3100
+ weave.org_ingestion_settings.extract_provider_configuration_id,
3101
+ EXCLUDED.extract_provider_configuration_id
3102
+ ),
3103
+ reconcile_model_id = COALESCE(weave.org_ingestion_settings.reconcile_model_id, EXCLUDED.reconcile_model_id),
3104
+ reconcile_provider_configuration_id = COALESCE(
3105
+ weave.org_ingestion_settings.reconcile_provider_configuration_id,
3106
+ EXCLUDED.reconcile_provider_configuration_id
3107
+ ),
3108
+ diff_model_id = COALESCE(weave.org_ingestion_settings.diff_model_id, EXCLUDED.diff_model_id),
3109
+ diff_provider_configuration_id = COALESCE(
3110
+ weave.org_ingestion_settings.diff_provider_configuration_id,
3111
+ EXCLUDED.diff_provider_configuration_id
3112
+ ),
2772
3113
  updated_at = now()
2773
3114
  RETURNING
2774
3115
  organization_id,
@@ -2776,6 +3117,19 @@ WITH cfg AS (
2776
3117
  reasoning_provider_configuration_id,
2777
3118
  embedding_model_id,
2778
3119
  embedding_provider_configuration_id,
3120
+ classify_model_id,
3121
+ classify_provider_configuration_id,
3122
+ refine_model_id,
3123
+ refine_provider_configuration_id,
3124
+ extract_model_id,
3125
+ extract_provider_configuration_id,
3126
+ embed_model_id,
3127
+ embed_provider_configuration_id,
3128
+ reconcile_model_id,
3129
+ reconcile_provider_configuration_id,
3130
+ diff_model_id,
3131
+ diff_provider_configuration_id,
3132
+ refine_loop_count,
2779
3133
  updated_at
2780
3134
  )
2781
3135
  SELECT
@@ -2784,7 +3138,21 @@ SELECT
2784
3138
  upsert.reasoning_provider_configuration_id,
2785
3139
  upsert.embedding_model_id,
2786
3140
  upsert.embedding_provider_configuration_id,
3141
+ upsert.classify_model_id,
3142
+ upsert.classify_provider_configuration_id,
3143
+ upsert.refine_model_id,
3144
+ upsert.refine_provider_configuration_id,
3145
+ upsert.extract_model_id,
3146
+ upsert.extract_provider_configuration_id,
3147
+ upsert.embed_model_id,
3148
+ upsert.embed_provider_configuration_id,
3149
+ upsert.reconcile_model_id,
3150
+ upsert.reconcile_provider_configuration_id,
3151
+ upsert.diff_model_id,
3152
+ upsert.diff_provider_configuration_id,
2787
3153
  cfg.embedding_dimension AS embedding_dimensions,
3154
+ cfg.embedding_dimension AS embed_dimensions,
3155
+ upsert.refine_loop_count,
2788
3156
  upsert.updated_at
2789
3157
  FROM upsert
2790
3158
  JOIN cfg
@@ -2805,10 +3173,147 @@ async function syncOrganizationIngestionReasoningDefaults(client, args) {
2805
3173
  reasoningProviderConfigurationId: row[2],
2806
3174
  embeddingModelId: row[3],
2807
3175
  embeddingProviderConfigurationId: row[4],
2808
- embeddingDimensions: row[5],
2809
- updatedAt: row[6]
3176
+ classifyModelId: row[5],
3177
+ classifyProviderConfigurationId: row[6],
3178
+ refineModelId: row[7],
3179
+ refineProviderConfigurationId: row[8],
3180
+ extractModelId: row[9],
3181
+ extractProviderConfigurationId: row[10],
3182
+ embedModelId: row[11],
3183
+ embedProviderConfigurationId: row[12],
3184
+ reconcileModelId: row[13],
3185
+ reconcileProviderConfigurationId: row[14],
3186
+ diffModelId: row[15],
3187
+ diffProviderConfigurationId: row[16],
3188
+ embeddingDimensions: row[17],
3189
+ embedDimensions: row[18],
3190
+ refineLoopCount: row[19],
3191
+ updatedAt: row[20]
3192
+ };
3193
+ }
3194
+ exports.listThreadFacetsByThreadIDsQuery = `-- name: ListThreadFacetsByThreadIDs :many
3195
+ SELECT
3196
+ thread_id,
3197
+ organization_id,
3198
+ knowledge_type,
3199
+ score,
3200
+ facet_fields,
3201
+ rationale,
3202
+ is_primary,
3203
+ created_at,
3204
+ updated_at
3205
+ FROM weave.thread_facets
3206
+ WHERE organization_id = $1
3207
+ AND thread_id = ANY($2::uuid[])
3208
+ ORDER BY thread_id ASC, is_primary DESC, score DESC, knowledge_type ASC`;
3209
+ async function listThreadFacetsByThreadIDs(client, args) {
3210
+ const result = await client.query({
3211
+ text: exports.listThreadFacetsByThreadIDsQuery,
3212
+ values: [args.organizationId, args.threadIds],
3213
+ rowMode: "array"
3214
+ });
3215
+ return result.rows.map(row => {
3216
+ return {
3217
+ threadId: row[0],
3218
+ organizationId: row[1],
3219
+ knowledgeType: row[2],
3220
+ score: row[3],
3221
+ facetFields: row[4],
3222
+ rationale: row[5],
3223
+ isPrimary: row[6],
3224
+ createdAt: row[7],
3225
+ updatedAt: row[8]
3226
+ };
3227
+ });
3228
+ }
3229
+ exports.upsertThreadFacetQuery = `-- name: UpsertThreadFacet :one
3230
+ WITH scoped_thread AS (
3231
+ SELECT t.id
3232
+ FROM weave.threads t
3233
+ WHERE t.organization_id = $1
3234
+ AND t.id = $2
3235
+ ), clear_primary AS (
3236
+ UPDATE weave.thread_facets tf
3237
+ SET is_primary = FALSE,
3238
+ updated_at = now()
3239
+ WHERE tf.organization_id = $1
3240
+ AND tf.thread_id = $2
3241
+ AND $3::boolean
3242
+ RETURNING tf.thread_id
3243
+ ), upsert AS (
3244
+ INSERT INTO weave.thread_facets (
3245
+ thread_id,
3246
+ organization_id,
3247
+ knowledge_type,
3248
+ score,
3249
+ facet_fields,
3250
+ rationale,
3251
+ is_primary
3252
+ )
3253
+ SELECT
3254
+ scoped_thread.id,
3255
+ $1,
3256
+ $4,
3257
+ $5,
3258
+ $6,
3259
+ $7,
3260
+ $3
3261
+ FROM scoped_thread
3262
+ ON CONFLICT (thread_id, knowledge_type) DO UPDATE
3263
+ SET
3264
+ score = EXCLUDED.score,
3265
+ facet_fields = EXCLUDED.facet_fields,
3266
+ rationale = EXCLUDED.rationale,
3267
+ is_primary = EXCLUDED.is_primary,
3268
+ updated_at = now()
3269
+ RETURNING
3270
+ thread_id,
3271
+ organization_id,
3272
+ knowledge_type,
3273
+ score,
3274
+ facet_fields,
3275
+ rationale,
3276
+ is_primary,
3277
+ created_at,
3278
+ updated_at
3279
+ )
3280
+ SELECT
3281
+ thread_id,
3282
+ organization_id,
3283
+ knowledge_type,
3284
+ score,
3285
+ facet_fields,
3286
+ rationale,
3287
+ is_primary,
3288
+ created_at,
3289
+ updated_at
3290
+ FROM upsert`;
3291
+ async function upsertThreadFacet(client, args) {
3292
+ const result = await client.query({
3293
+ text: exports.upsertThreadFacetQuery,
3294
+ values: [args.organizationId, args.threadId, args.isPrimary, args.knowledgeType, args.score, args.facetFields, args.rationale],
3295
+ rowMode: "array"
3296
+ });
3297
+ if (result.rows.length !== 1) {
3298
+ return null;
3299
+ }
3300
+ const row = result.rows[0];
3301
+ return {
3302
+ threadId: row[0],
3303
+ organizationId: row[1],
3304
+ knowledgeType: row[2],
3305
+ score: row[3],
3306
+ facetFields: row[4],
3307
+ rationale: row[5],
3308
+ isPrimary: row[6],
3309
+ createdAt: row[7],
3310
+ updatedAt: row[8]
2810
3311
  };
2811
3312
  }
3313
+ exports.deleteThreadFacetsByThreadQuery = `-- name: DeleteThreadFacetsByThread :execrows
3314
+ DELETE FROM weave.thread_facets
3315
+ WHERE organization_id = $1
3316
+ AND thread_id = $2`;
2812
3317
  exports.listFacetConfigsQuery = `-- name: ListFacetConfigs :many
2813
3318
  SELECT
2814
3319
  organization_id,