@fayz-ai/plugin-scribe 0.14.11 → 0.14.13

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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,eAAe,CAAA;AAY5E,OAAO,KAAK,EAEV,mBAAmB,EAEpB,MAAM,SAAS,CAAA;AA0BhB,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,cAAc,CAgM/E;AAMD,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC5F,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,kBAAkB,GACnB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAA;AACxB,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,WAAW,GACZ,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,eAAe,CAAA;AAY5E,OAAO,KAAK,EAEV,mBAAmB,EAEpB,MAAM,SAAS,CAAA;AA0BhB,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,cAAc,CA+L/E;AAMD,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC5F,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,kBAAkB,GACnB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAA;AACxB,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,WAAW,GACZ,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { PROMPT_VERSION, buildUserPrompt, renderTranscript, buildSystemPrompt, f
2
2
  export { PROMPT_VERSION, formatOffset, parseSections, renderTranscript } from './chunk-V2YWQDBI.js';
3
3
  import * as React5 from 'react';
4
4
  import React5__default from 'react';
5
- import { getActiveTenantId, getSupabaseClientOptional, registerTranslations } from '@fayz-ai/core';
5
+ import { getActiveTenantId, getSupabaseClientOptional, registerTranslations, currentAppPath, navigateApp } from '@fayz-ai/core';
6
6
  import { create } from 'zustand';
7
7
  import { createPortal } from 'react-dom';
8
8
  import { Mic, FileText, Sparkles, Loader2, Pause, Play, Square, Settings2, AlertTriangle, RefreshCw, Trash2, Check } from 'lucide-react';
@@ -10,6 +10,7 @@ import { Button, toast, Skeleton, Badge, Tabs, TabsList, TabsTrigger, TabsConten
10
10
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
11
11
  import { openAssistantAs, useAgentSurface, registerTimelineSource, useAccessOptional, useHeaderAction, useAuth, usePublishAssistantActivity, useRegisterAssistantLauncher, resolveFayzAgentConnection } from '@fayz-ai/admin';
12
12
  import { SubpageHeader } from '@fayz-ai/ui/layout';
13
+ import { MIGRATIONS } from '#migrations/main';
13
14
 
14
15
  // src/locales/en.ts
15
16
  var en = {
@@ -2552,578 +2553,6 @@ function ScribeHeaderAction({ labels, item, entityId }) {
2552
2553
  );
2553
2554
  return null;
2554
2555
  }
2555
-
2556
- // src/migrations/index.ts
2557
- var MIGRATION_000_BASELINE = `-- ============================================================================
2558
- -- plugins/plugin-scribe/src/migrations/000_baseline.sql \u2014 what installing this provisions, as one file.
2559
- --
2560
- -- GENERATED by scripts/emit-unit-baselines.mjs (#338). Do not edit by hand:
2561
- -- change the schema, regenerate, and let scripts/check-chain-equivalence.mjs
2562
- -- prove the result still matches.
2563
- --
2564
- -- This replaced 3 migration files. They are kept, unapplied, in
2565
- -- migrations.archive/ \u2014 a year of decisions is worth reading even when it is no
2566
- -- longer worth replaying.
2567
- --
2568
- -- Object order is fixed rather than dependency-sorted: schemas, types,
2569
- -- sequences, tables, defaults, functions, constraints, views, indexes, foreign
2570
- -- keys, triggers, row security, policies, grants. Dependencies BETWEEN units
2571
- -- are carried by the order packages/db/chain.json declares.
2572
- -- ============================================================================
2573
-
2574
- -- A LANGUAGE sql function binds its body at CREATE time, and 570 functions
2575
- -- sorted by name are not sorted by who calls whom. This is what lets them load
2576
- -- in any order; every body is still compiled on first call, so a genuinely
2577
- -- broken reference surfaces then rather than never. Session-scoped.
2578
- SET check_function_bodies = false;
2579
-
2580
-
2581
-
2582
- -- \u2500\u2500 default privileges: reset \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2583
- -- Cleared BEFORE anything is created, so every object below gets the ACL the
2584
- -- dump describes rather than the image's defaults on top of it. Restored at
2585
- -- the end of this file.
2586
-
2587
- DO $dp$ BEGIN
2588
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public REVOKE ALL ON SEQUENCES FROM anon, authenticated, service_role, fayz_connector$stmt$;
2589
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2590
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public REVOKE ALL ON SEQUENCES FROM anon, authenticated, service_role, fayz_connector$stmt$;
2591
- END $dp$;
2592
-
2593
- DO $dp$ BEGIN
2594
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE ALL ON SEQUENCES FROM anon, authenticated, service_role, fayz_connector$stmt$;
2595
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2596
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE ALL ON SEQUENCES FROM anon, authenticated, service_role, fayz_connector$stmt$;
2597
- END $dp$;
2598
-
2599
- DO $dp$ BEGIN
2600
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public REVOKE ALL ON FUNCTIONS FROM anon, authenticated, service_role, fayz_connector$stmt$;
2601
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2602
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public REVOKE ALL ON FUNCTIONS FROM anon, authenticated, service_role, fayz_connector$stmt$;
2603
- END $dp$;
2604
-
2605
- DO $dp$ BEGIN
2606
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE ALL ON FUNCTIONS FROM anon, authenticated, service_role, fayz_connector$stmt$;
2607
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2608
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE ALL ON FUNCTIONS FROM anon, authenticated, service_role, fayz_connector$stmt$;
2609
- END $dp$;
2610
-
2611
- DO $dp$ BEGIN
2612
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public REVOKE ALL ON TABLES FROM anon, authenticated, service_role, fayz_connector$stmt$;
2613
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2614
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public REVOKE ALL ON TABLES FROM anon, authenticated, service_role, fayz_connector$stmt$;
2615
- END $dp$;
2616
-
2617
- DO $dp$ BEGIN
2618
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE ALL ON TABLES FROM anon, authenticated, service_role, fayz_connector$stmt$;
2619
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2620
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public REVOKE ALL ON TABLES FROM anon, authenticated, service_role, fayz_connector$stmt$;
2621
- END $dp$;
2622
-
2623
-
2624
- -- \u2500\u2500 table \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2625
-
2626
- CREATE TABLE public.plg_scribe_generations (
2627
- id uuid DEFAULT gen_random_uuid() NOT NULL,
2628
- tenant_id uuid NOT NULL,
2629
- session_id uuid NOT NULL,
2630
- template_id uuid,
2631
- template_key text,
2632
- tab_order integer DEFAULT 0 NOT NULL,
2633
- title text,
2634
- status text DEFAULT 'pending'::text NOT NULL,
2635
- markdown text,
2636
- markdown_edited text,
2637
- facts jsonb,
2638
- model text,
2639
- prompt_version text,
2640
- input_tokens integer,
2641
- output_tokens integer,
2642
- error text,
2643
- document_id uuid,
2644
- created_by uuid,
2645
- created_at timestamp with time zone DEFAULT now() NOT NULL,
2646
- updated_at timestamp with time zone DEFAULT now() NOT NULL,
2647
- CONSTRAINT plg_scribe_generations_status_check CHECK ((status = ANY (ARRAY['pending'::text, 'running'::text, 'ready'::text, 'failed'::text, 'committed'::text, 'discarded'::text])))
2648
- );
2649
-
2650
- CREATE TABLE public.plg_scribe_segments (
2651
- session_id uuid NOT NULL,
2652
- seg_index integer NOT NULL,
2653
- tenant_id uuid NOT NULL,
2654
- storage_path text,
2655
- bytes integer,
2656
- start_offset_ms integer NOT NULL,
2657
- duration_ms integer,
2658
- partial boolean DEFAULT false NOT NULL,
2659
- gap boolean DEFAULT false NOT NULL,
2660
- upload_state text DEFAULT 'pending'::text NOT NULL,
2661
- uploaded_at timestamp with time zone,
2662
- stt_state text DEFAULT 'pending'::text NOT NULL,
2663
- stt_provider text,
2664
- stt_attempts smallint DEFAULT 0 NOT NULL,
2665
- stt_error text,
2666
- text text,
2667
- words jsonb,
2668
- confidence real,
2669
- created_at timestamp with time zone DEFAULT now() NOT NULL,
2670
- updated_at timestamp with time zone DEFAULT now() NOT NULL,
2671
- CONSTRAINT plg_scribe_segments_stt_state_check CHECK ((stt_state = ANY (ARRAY['pending'::text, 'running'::text, 'done'::text, 'failed'::text, 'skipped'::text]))),
2672
- CONSTRAINT plg_scribe_segments_upload_state_check CHECK ((upload_state = ANY (ARRAY['pending'::text, 'uploaded'::text, 'missing'::text])))
2673
- );
2674
-
2675
- CREATE TABLE public.plg_scribe_sessions (
2676
- id uuid NOT NULL,
2677
- tenant_id uuid NOT NULL,
2678
- subject_id uuid,
2679
- context_kind text DEFAULT 'person'::text NOT NULL,
2680
- appointment_id uuid,
2681
- owner_user_id uuid NOT NULL,
2682
- status text DEFAULT 'recording'::text NOT NULL,
2683
- locale text DEFAULT 'pt-BR'::text NOT NULL,
2684
- mime_type text,
2685
- started_at timestamp with time zone DEFAULT now() NOT NULL,
2686
- ended_at timestamp with time zone,
2687
- wall_duration_ms integer DEFAULT 0 NOT NULL,
2688
- audio_duration_ms integer DEFAULT 0 NOT NULL,
2689
- segment_count integer DEFAULT 0 NOT NULL,
2690
- uploaded_segment_count integer DEFAULT 0 NOT NULL,
2691
- transcribed_segment_count integer DEFAULT 0 NOT NULL,
2692
- transcript_chars integer DEFAULT 0 NOT NULL,
2693
- consent_at timestamp with time zone,
2694
- consent_mode text,
2695
- retention_until date,
2696
- audio_deleted_at timestamp with time zone,
2697
- error text,
2698
- metadata jsonb DEFAULT '{}'::jsonb NOT NULL,
2699
- created_at timestamp with time zone DEFAULT now() NOT NULL,
2700
- updated_at timestamp with time zone DEFAULT now() NOT NULL,
2701
- CONSTRAINT plg_scribe_sessions_consent_mode_check CHECK ((consent_mode = ANY (ARRAY['verbal'::text, 'written'::text, 'implied_contract'::text]))),
2702
- CONSTRAINT plg_scribe_sessions_context_kind_check CHECK ((context_kind = ANY (ARRAY['person'::text, 'appointment'::text, 'standalone'::text]))),
2703
- CONSTRAINT plg_scribe_sessions_status_check CHECK ((status = ANY (ARRAY['recording'::text, 'paused'::text, 'interrupted'::text, 'uploading'::text, 'transcribing'::text, 'ready'::text, 'generating'::text, 'completed'::text, 'abandoned'::text, 'failed'::text])))
2704
- );
2705
-
2706
-
2707
- -- \u2500\u2500 function \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2708
-
2709
- CREATE FUNCTION public.scribe_audio_path_ok(p_name text) RETURNS boolean
2710
- LANGUAGE sql STABLE SECURITY DEFINER
2711
- SET search_path TO 'public'
2712
- AS $_$
2713
- SELECT
2714
- p_name IS NOT NULL
2715
- AND length(p_name) <= 200
2716
- AND p_name ~ ('^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
2717
- || '/[0-9]{4}/[0-9]{2}'
2718
- || '/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
2719
- || '/[0-9]{5}\\.(webm|ogg|m4a|mp3)$')
2720
- -- compara\xE7\xE3o em texto (nunca \`::uuid\`): entrada malformada devolve falso em
2721
- -- vez de derrubar a policy com erro de cast.
2722
- AND EXISTS (
2723
- SELECT 1 FROM public.tenants t WHERE t.id::text = split_part(p_name, '/', 1)
2724
- );
2725
- $_$;
2726
-
2727
- CREATE FUNCTION public.scribe_record_segment(p_payload jsonb) RETURNS jsonb
2728
- LANGUAGE plpgsql
2729
- SET search_path TO 'public'
2730
- AS $$
2731
- DECLARE
2732
- v_session_id uuid;
2733
- v_seg_index integer;
2734
- v_tenant_id uuid;
2735
- v_result jsonb;
2736
- BEGIN
2737
- v_session_id := (p_payload->>'session_id')::uuid;
2738
- v_seg_index := (p_payload->>'seg_index')::integer;
2739
-
2740
- IF v_session_id IS NULL OR v_seg_index IS NULL THEN
2741
- RAISE EXCEPTION 'session_id and seg_index are required';
2742
- END IF;
2743
-
2744
- -- O tenant vem da SESS\xC3O, nunca do payload. Se o cliente pudesse informar o
2745
- -- tenant, ele escolheria em que pasta escrever.
2746
- SELECT s.tenant_id INTO v_tenant_id
2747
- FROM plg_scribe_sessions s WHERE s.id = v_session_id;
2748
-
2749
- IF v_tenant_id IS NULL THEN
2750
- -- Sess\xE3o inexistente OU invis\xEDvel pela RLS: a mesma resposta nos dois
2751
- -- casos, de prop\xF3sito \u2014 n\xE3o vaza a exist\xEAncia de sess\xE3o de outro tenant.
2752
- RAISE EXCEPTION 'unknown session';
2753
- END IF;
2754
-
2755
- INSERT INTO plg_scribe_segments (
2756
- session_id, seg_index, tenant_id, storage_path, bytes,
2757
- start_offset_ms, duration_ms, partial, gap, upload_state, uploaded_at, stt_state
2758
- ) VALUES (
2759
- v_session_id, v_seg_index, v_tenant_id,
2760
- p_payload->>'storage_path',
2761
- (p_payload->>'bytes')::integer,
2762
- COALESCE((p_payload->>'start_offset_ms')::integer, 0),
2763
- (p_payload->>'duration_ms')::integer,
2764
- COALESCE((p_payload->>'partial')::boolean, false),
2765
- COALESCE((p_payload->>'gap')::boolean, false),
2766
- CASE WHEN COALESCE((p_payload->>'gap')::boolean, false) THEN 'missing' ELSE 'uploaded' END,
2767
- now(),
2768
- -- Buraco n\xE3o vai para o STT: n\xE3o h\xE1 \xE1udio para transcrever, e mand\xE1-lo
2769
- -- queimaria uma chamada para receber string vazia.
2770
- CASE WHEN COALESCE((p_payload->>'gap')::boolean, false) THEN 'skipped' ELSE 'pending' END
2771
- )
2772
- ON CONFLICT (session_id, seg_index) DO UPDATE SET
2773
- storage_path = COALESCE(EXCLUDED.storage_path, plg_scribe_segments.storage_path),
2774
- bytes = COALESCE(EXCLUDED.bytes, plg_scribe_segments.bytes),
2775
- duration_ms = COALESCE(EXCLUDED.duration_ms, plg_scribe_segments.duration_ms),
2776
- partial = EXCLUDED.partial,
2777
- upload_state = EXCLUDED.upload_state,
2778
- uploaded_at = COALESCE(plg_scribe_segments.uploaded_at, EXCLUDED.uploaded_at),
2779
- updated_at = now();
2780
-
2781
- -- Contadores derivados. \`audio_duration_ms\` soma s\xF3 o que tem dura\xE7\xE3o medida,
2782
- -- ent\xE3o um segmento que ainda n\xE3o voltou do STT n\xE3o infla o total.
2783
- UPDATE plg_scribe_sessions s SET
2784
- segment_count = agg.total,
2785
- uploaded_segment_count = agg.uploaded,
2786
- transcribed_segment_count = agg.transcribed,
2787
- audio_duration_ms = agg.audio_ms,
2788
- transcript_chars = agg.chars,
2789
- updated_at = now()
2790
- FROM (
2791
- SELECT
2792
- count(*)::int AS total,
2793
- count(*) FILTER (WHERE upload_state = 'uploaded')::int AS uploaded,
2794
- count(*) FILTER (WHERE stt_state = 'done')::int AS transcribed,
2795
- COALESCE(sum(duration_ms) FILTER (WHERE NOT gap), 0)::int AS audio_ms,
2796
- COALESCE(sum(length(text)), 0)::int AS chars
2797
- FROM plg_scribe_segments WHERE session_id = v_session_id
2798
- ) agg
2799
- WHERE s.id = v_session_id;
2800
-
2801
- SELECT to_jsonb(x) INTO v_result FROM (
2802
- SELECT s.segment_count, s.uploaded_segment_count,
2803
- s.transcribed_segment_count, s.audio_duration_ms, s.status
2804
- FROM plg_scribe_sessions s WHERE s.id = v_session_id
2805
- ) x;
2806
-
2807
- RETURN v_result;
2808
- END;
2809
- $$;
2810
-
2811
-
2812
- -- \u2500\u2500 constraint \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2813
-
2814
- ALTER TABLE ONLY public.plg_scribe_generations
2815
- ADD CONSTRAINT plg_scribe_generations_pkey PRIMARY KEY (id);
2816
-
2817
- ALTER TABLE ONLY public.plg_scribe_segments
2818
- ADD CONSTRAINT plg_scribe_segments_pkey PRIMARY KEY (session_id, seg_index);
2819
-
2820
- ALTER TABLE ONLY public.plg_scribe_sessions
2821
- ADD CONSTRAINT plg_scribe_sessions_pkey PRIMARY KEY (id);
2822
-
2823
-
2824
- -- \u2500\u2500 view \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2825
-
2826
- CREATE VIEW public.v_scribe_generations WITH (security_invoker='true') AS
2827
- SELECT g.id,
2828
- g.tenant_id,
2829
- g.session_id,
2830
- g.template_id,
2831
- g.template_key,
2832
- g.tab_order,
2833
- g.title,
2834
- g.status,
2835
- g.markdown,
2836
- g.markdown_edited,
2837
- g.facts,
2838
- g.model,
2839
- g.prompt_version,
2840
- g.input_tokens,
2841
- g.output_tokens,
2842
- g.error,
2843
- g.document_id,
2844
- g.created_by,
2845
- g.created_at,
2846
- g.updated_at,
2847
- (t.id IS NOT NULL) AS template_exists,
2848
- t.name AS template_name
2849
- FROM (public.plg_scribe_generations g
2850
- LEFT JOIN public.plg_forms_templates t ON ((t.id = g.template_id)));
2851
-
2852
-
2853
- -- \u2500\u2500 index \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2854
-
2855
- CREATE INDEX idx_plg_scribe_generations_session ON public.plg_scribe_generations USING btree (session_id, tab_order);
2856
-
2857
- CREATE INDEX idx_plg_scribe_generations_tenant ON public.plg_scribe_generations USING btree (tenant_id);
2858
-
2859
- CREATE INDEX idx_plg_scribe_segments_stt_queue ON public.plg_scribe_segments USING btree (tenant_id, stt_state, created_at) WHERE ((upload_state = 'uploaded'::text) AND (stt_state = ANY (ARRAY['pending'::text, 'failed'::text])));
2860
-
2861
- CREATE INDEX idx_plg_scribe_segments_tenant ON public.plg_scribe_segments USING btree (tenant_id);
2862
-
2863
- CREATE INDEX idx_plg_scribe_sessions_appointment ON public.plg_scribe_sessions USING btree (appointment_id) WHERE (appointment_id IS NOT NULL);
2864
-
2865
- CREATE INDEX idx_plg_scribe_sessions_open ON public.plg_scribe_sessions USING btree (tenant_id, owner_user_id, status) WHERE (status = ANY (ARRAY['recording'::text, 'paused'::text, 'interrupted'::text, 'uploading'::text, 'transcribing'::text, 'ready'::text, 'generating'::text]));
2866
-
2867
- CREATE INDEX idx_plg_scribe_sessions_retention ON public.plg_scribe_sessions USING btree (retention_until) WHERE ((audio_deleted_at IS NULL) AND (retention_until IS NOT NULL));
2868
-
2869
- CREATE INDEX idx_plg_scribe_sessions_subject ON public.plg_scribe_sessions USING btree (subject_id) WHERE (subject_id IS NOT NULL);
2870
-
2871
- CREATE INDEX idx_plg_scribe_sessions_tenant ON public.plg_scribe_sessions USING btree (tenant_id);
2872
-
2873
-
2874
- -- \u2500\u2500 fk constraint \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2875
-
2876
- ALTER TABLE ONLY public.plg_scribe_generations
2877
- ADD CONSTRAINT plg_scribe_generations_document_fk FOREIGN KEY (document_id) REFERENCES public.documents(id) ON DELETE SET NULL;
2878
-
2879
- ALTER TABLE ONLY public.plg_scribe_generations
2880
- ADD CONSTRAINT plg_scribe_generations_session_id_fkey FOREIGN KEY (session_id) REFERENCES public.plg_scribe_sessions(id) ON DELETE CASCADE;
2881
-
2882
- ALTER TABLE ONLY public.plg_scribe_generations
2883
- ADD CONSTRAINT plg_scribe_generations_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenants(id) ON DELETE CASCADE;
2884
-
2885
- ALTER TABLE ONLY public.plg_scribe_segments
2886
- ADD CONSTRAINT plg_scribe_segments_session_id_fkey FOREIGN KEY (session_id) REFERENCES public.plg_scribe_sessions(id) ON DELETE CASCADE;
2887
-
2888
- ALTER TABLE ONLY public.plg_scribe_segments
2889
- ADD CONSTRAINT plg_scribe_segments_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenants(id) ON DELETE CASCADE;
2890
-
2891
- ALTER TABLE ONLY public.plg_scribe_sessions
2892
- ADD CONSTRAINT plg_scribe_sessions_appointment_id_fkey FOREIGN KEY (appointment_id) REFERENCES public.appointments(id) ON DELETE SET NULL;
2893
-
2894
- ALTER TABLE ONLY public.plg_scribe_sessions
2895
- ADD CONSTRAINT plg_scribe_sessions_subject_id_fkey FOREIGN KEY (subject_id) REFERENCES public.people(id) ON DELETE SET NULL;
2896
-
2897
- ALTER TABLE ONLY public.plg_scribe_sessions
2898
- ADD CONSTRAINT plg_scribe_sessions_tenant_id_fkey FOREIGN KEY (tenant_id) REFERENCES public.tenants(id) ON DELETE CASCADE;
2899
-
2900
-
2901
- -- \u2500\u2500 row security \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2902
-
2903
- ALTER TABLE public.plg_scribe_generations ENABLE ROW LEVEL SECURITY;
2904
-
2905
- ALTER TABLE public.plg_scribe_segments ENABLE ROW LEVEL SECURITY;
2906
-
2907
- ALTER TABLE public.plg_scribe_sessions ENABLE ROW LEVEL SECURITY;
2908
-
2909
-
2910
- -- \u2500\u2500 policy \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2911
-
2912
- CREATE POLICY plg_scribe_generations_delete ON public.plg_scribe_generations FOR DELETE TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2913
-
2914
- CREATE POLICY plg_scribe_generations_insert ON public.plg_scribe_generations FOR INSERT TO authenticated WITH CHECK ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2915
-
2916
- CREATE POLICY plg_scribe_generations_select ON public.plg_scribe_generations FOR SELECT TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2917
-
2918
- CREATE POLICY plg_scribe_generations_update ON public.plg_scribe_generations FOR UPDATE TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2919
-
2920
- CREATE POLICY plg_scribe_segments_delete ON public.plg_scribe_segments FOR DELETE TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2921
-
2922
- CREATE POLICY plg_scribe_segments_insert ON public.plg_scribe_segments FOR INSERT TO authenticated WITH CHECK ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2923
-
2924
- CREATE POLICY plg_scribe_segments_select ON public.plg_scribe_segments FOR SELECT TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2925
-
2926
- CREATE POLICY plg_scribe_segments_update ON public.plg_scribe_segments FOR UPDATE TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2927
-
2928
- CREATE POLICY plg_scribe_sessions_delete ON public.plg_scribe_sessions FOR DELETE TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2929
-
2930
- CREATE POLICY plg_scribe_sessions_insert ON public.plg_scribe_sessions FOR INSERT TO authenticated WITH CHECK ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2931
-
2932
- CREATE POLICY plg_scribe_sessions_select ON public.plg_scribe_sessions FOR SELECT TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2933
-
2934
- CREATE POLICY plg_scribe_sessions_update ON public.plg_scribe_sessions FOR UPDATE TO authenticated USING ((tenant_id IN ( SELECT public.user_tenant_ids() AS user_tenant_ids)));
2935
-
2936
-
2937
- -- \u2500\u2500 acl \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2938
-
2939
- GRANT ALL ON FUNCTION public.scribe_audio_path_ok(p_name text) TO authenticated;
2940
- GRANT ALL ON FUNCTION public.scribe_audio_path_ok(p_name text) TO service_role;
2941
-
2942
- GRANT ALL ON FUNCTION public.scribe_record_segment(p_payload jsonb) TO authenticated;
2943
- GRANT ALL ON FUNCTION public.scribe_record_segment(p_payload jsonb) TO service_role;
2944
-
2945
- GRANT MAINTAIN ON TABLE public.plg_scribe_generations TO anon;
2946
- GRANT ALL ON TABLE public.plg_scribe_generations TO authenticated;
2947
- GRANT ALL ON TABLE public.plg_scribe_generations TO service_role;
2948
-
2949
- GRANT MAINTAIN ON TABLE public.plg_scribe_segments TO anon;
2950
- GRANT ALL ON TABLE public.plg_scribe_segments TO authenticated;
2951
- GRANT ALL ON TABLE public.plg_scribe_segments TO service_role;
2952
-
2953
- GRANT MAINTAIN ON TABLE public.plg_scribe_sessions TO anon;
2954
- GRANT ALL ON TABLE public.plg_scribe_sessions TO authenticated;
2955
- GRANT ALL ON TABLE public.plg_scribe_sessions TO service_role;
2956
-
2957
- GRANT MAINTAIN ON TABLE public.v_scribe_generations TO anon;
2958
- GRANT ALL ON TABLE public.v_scribe_generations TO authenticated;
2959
- GRANT ALL ON TABLE public.v_scribe_generations TO service_role;
2960
-
2961
-
2962
- -- \u2500\u2500 comment \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2963
-
2964
- COMMENT ON FUNCTION public.scribe_audio_path_ok(p_name text) IS 'True when a storage object name follows the scribe-audio grammar {tenant}/{yyyy}/{mm}/{session}/{segIndex}.{ext} and segment 1 is a real tenant. Used by the INSERT policy on that bucket.';
2965
-
2966
- COMMENT ON FUNCTION public.scribe_record_segment(p_payload jsonb) IS 'Idempotent upsert of one audio segment + recomputation of the parent session counters from the segments table. Called by the browser upload pump after each successful Storage write.';
2967
-
2968
- COMMENT ON COLUMN public.plg_scribe_generations.template_id IS 'The forms template this generation came from, by id and not by foreign key (003, ADR 0015). A soft reference on purpose: forms owns that table and must be able to release it without scribe''s permission. A row whose template is gone reads as absent, which is what the old ON DELETE SET NULL was arranging.';
2969
-
2970
- COMMENT ON VIEW public.v_scribe_generations IS 'Generations with their forms template resolved by LEFT JOIN rather than by foreign key (003). \`template_exists\` is the honest answer on a cluster where forms is not installed, or where the template was deleted.';
2971
-
2972
-
2973
- -- \u2500\u2500 default privileges: restore \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
2974
- -- Put back, so the NEXT thing installed inherits what the chain had.
2975
-
2976
- DO $dp$ BEGIN
2977
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO postgres$stmt$;
2978
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2979
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO postgres$stmt$;
2980
- END $dp$;
2981
-
2982
- DO $dp$ BEGIN
2983
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO anon$stmt$;
2984
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2985
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO anon$stmt$;
2986
- END $dp$;
2987
-
2988
- DO $dp$ BEGIN
2989
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO authenticated$stmt$;
2990
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2991
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO authenticated$stmt$;
2992
- END $dp$;
2993
-
2994
- DO $dp$ BEGIN
2995
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO service_role$stmt$;
2996
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
2997
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO service_role$stmt$;
2998
- END $dp$;
2999
-
3000
- DO $dp$ BEGIN
3001
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO postgres$stmt$;
3002
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3003
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO postgres$stmt$;
3004
- END $dp$;
3005
-
3006
- DO $dp$ BEGIN
3007
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO anon$stmt$;
3008
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3009
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO anon$stmt$;
3010
- END $dp$;
3011
-
3012
- DO $dp$ BEGIN
3013
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO authenticated$stmt$;
3014
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3015
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO authenticated$stmt$;
3016
- END $dp$;
3017
-
3018
- DO $dp$ BEGIN
3019
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO service_role$stmt$;
3020
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3021
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON SEQUENCES TO service_role$stmt$;
3022
- END $dp$;
3023
-
3024
- DO $dp$ BEGIN
3025
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO postgres$stmt$;
3026
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3027
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO postgres$stmt$;
3028
- END $dp$;
3029
-
3030
- DO $dp$ BEGIN
3031
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO authenticated$stmt$;
3032
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3033
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO authenticated$stmt$;
3034
- END $dp$;
3035
-
3036
- DO $dp$ BEGIN
3037
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO service_role$stmt$;
3038
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3039
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO service_role$stmt$;
3040
- END $dp$;
3041
-
3042
- DO $dp$ BEGIN
3043
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO postgres$stmt$;
3044
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3045
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO postgres$stmt$;
3046
- END $dp$;
3047
-
3048
- DO $dp$ BEGIN
3049
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO anon$stmt$;
3050
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3051
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO anon$stmt$;
3052
- END $dp$;
3053
-
3054
- DO $dp$ BEGIN
3055
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO authenticated$stmt$;
3056
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3057
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO authenticated$stmt$;
3058
- END $dp$;
3059
-
3060
- DO $dp$ BEGIN
3061
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO service_role$stmt$;
3062
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3063
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON FUNCTIONS TO service_role$stmt$;
3064
- END $dp$;
3065
-
3066
- DO $dp$ BEGIN
3067
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO postgres$stmt$;
3068
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3069
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO postgres$stmt$;
3070
- END $dp$;
3071
-
3072
- DO $dp$ BEGIN
3073
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT MAINTAIN ON TABLES TO anon$stmt$;
3074
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3075
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT MAINTAIN ON TABLES TO anon$stmt$;
3076
- END $dp$;
3077
-
3078
- DO $dp$ BEGIN
3079
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO authenticated$stmt$;
3080
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3081
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO authenticated$stmt$;
3082
- END $dp$;
3083
-
3084
- DO $dp$ BEGIN
3085
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO service_role$stmt$;
3086
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3087
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO service_role$stmt$;
3088
- END $dp$;
3089
-
3090
- DO $dp$ BEGIN
3091
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO postgres$stmt$;
3092
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3093
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO postgres$stmt$;
3094
- END $dp$;
3095
-
3096
- DO $dp$ BEGIN
3097
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO anon$stmt$;
3098
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3099
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO anon$stmt$;
3100
- END $dp$;
3101
-
3102
- DO $dp$ BEGIN
3103
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO authenticated$stmt$;
3104
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3105
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO authenticated$stmt$;
3106
- END $dp$;
3107
-
3108
- DO $dp$ BEGIN
3109
- EXECUTE $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO service_role$stmt$;
3110
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3111
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$ALTER DEFAULT PRIVILEGES FOR ROLE supabase_admin IN SCHEMA public GRANT ALL ON TABLES TO service_role$stmt$;
3112
- END $dp$;
3113
-
3114
- DO $dp$ BEGIN
3115
- EXECUTE $stmt$--
3116
- -- PostgreSQL database dump complete
3117
- --$stmt$;
3118
- EXCEPTION WHEN insufficient_privilege OR undefined_object THEN
3119
- RAISE NOTICE 'baseline: not ours to set \u2014 %', $stmt$--
3120
- -- PostgreSQL database dump complete
3121
- --$stmt$;
3122
- END $dp$;
3123
- `;
3124
- var MIGRATIONS = [
3125
- { id: "000_baseline", sql: MIGRATION_000_BASELINE }
3126
- ];
3127
2556
  var STATUS_LABELS = {
3128
2557
  recording: "Gravando",
3129
2558
  paused: "Pausado",
@@ -3460,13 +2889,12 @@ function createScribePlugin(options) {
3460
2889
  const subjectEntities = options.subjectEntities ?? ["clients", "patients", "people", "persons", "customers"];
3461
2890
  const sessionPath = options.sessionPath ?? ((args) => scribeSessionPath({ ...args, subjectEntity: subjectEntities[0] }));
3462
2891
  const openSession = (sessionId, subjectId) => {
3463
- window.location.hash = sessionPath({ sessionId, subjectId });
2892
+ navigateApp(sessionPath({ sessionId, subjectId }));
3464
2893
  };
3465
2894
  const ShellMount = () => React5__default.createElement(ScribeShellMount, { labels, retention: retention2, stt: options.stt, locale, onOpenSession: openSession });
3466
2895
  ShellMount.displayName = "ScribeShellMount";
3467
2896
  const SessionRoute = () => {
3468
- const hash = typeof window !== "undefined" ? window.location.hash : "";
3469
- const sessionId = hash.split("/scribe/")[1]?.split("/")[0] ?? "";
2897
+ const sessionId = currentAppPath().split("/scribe/")[1]?.split("/")[0] ?? "";
3470
2898
  if (!sessionId) return null;
3471
2899
  return React5__default.createElement(ScribeSessionPage, {
3472
2900
  sessionId,
@@ -3478,10 +2906,10 @@ function createScribePlugin(options) {
3478
2906
  if (session.subjectId) openSession(session.id, session.subjectId);
3479
2907
  },
3480
2908
  onBack: () => {
3481
- window.location.hash = `/${subjectEntities[0]}`;
2909
+ navigateApp(`/${subjectEntities[0]}`);
3482
2910
  },
3483
2911
  onOpenDocument: () => {
3484
- window.location.hash = `/${subjectEntities[0]}`;
2912
+ navigateApp(`/${subjectEntities[0]}`);
3485
2913
  }
3486
2914
  });
3487
2915
  };