spine-framework 0.3.145 → 0.4.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/.env.example +76 -0
- package/.framework/.spine-manifest.json +19 -0
- package/.framework/cli/commands/agents.ts +61 -33
- package/.framework/cli/commands/auth.ts +60 -28
- package/.framework/cli/commands/create-app.ts +212 -80
- package/.framework/cli/commands/dev.ts +184 -68
- package/.framework/cli/commands/doctor.ts +324 -152
- package/.framework/cli/commands/generate.ts +119 -68
- package/.framework/cli/commands/init.ts +141 -242
- package/.framework/cli/commands/install-app.ts +1336 -314
- package/.framework/cli/commands/items.ts +31 -29
- package/.framework/cli/commands/migrate.ts +299 -156
- package/.framework/cli/commands/migrations.ts +62 -30
- package/.framework/cli/commands/pipelines.ts +31 -29
- package/.framework/cli/commands/status.ts +105 -45
- package/.framework/cli/commands/system.ts +47 -42
- package/.framework/cli/commands/test.ts +161 -102
- package/.framework/cli/commands/upgrade.ts +260 -0
- package/.framework/cli/commands/validate-app.ts +517 -161
- package/.framework/cli/context.ts +117 -85
- package/.framework/cli/env-loader.ts +74 -43
- package/.framework/cli/index.ts +70 -46
- package/.framework/cli/lib/project-files.ts +404 -0
- package/.framework/docs/guides/testing-guide.md +1 -1
- package/.framework/docs/runtime-types.md +72 -72
- package/.framework/functions/_shared/access.ts +84 -0
- package/.framework/functions/_shared/agent-runner.ts +5051 -1026
- package/.framework/functions/_shared/app-manifest.ts +214 -94
- package/.framework/functions/_shared/ast.ts +214 -0
- package/.framework/functions/_shared/audit.ts +91 -55
- package/.framework/functions/_shared/cil.ts +368 -127
- package/.framework/functions/_shared/db.ts +337 -68
- package/.framework/functions/_shared/funnel.ts +228 -0
- package/.framework/functions/_shared/geo.ts +105 -0
- package/.framework/functions/_shared/hash-api-key.ts +94 -17
- package/.framework/functions/_shared/index.ts +22 -224
- package/.framework/functions/_shared/kb.ts +832 -58
- package/.framework/functions/_shared/llm.ts +118 -18
- package/.framework/functions/_shared/logging.ts +317 -19
- package/.framework/functions/_shared/middleware.ts +701 -131
- package/.framework/functions/_shared/notify.ts +70 -0
- package/.framework/functions/_shared/outcomes.ts +34 -19
- package/.framework/functions/_shared/permissions.ts +501 -315
- package/.framework/functions/_shared/pipeline-runner.ts +704 -155
- package/.framework/functions/_shared/principal.ts +436 -263
- package/.framework/functions/_shared/rate-limit.ts +233 -0
- package/.framework/functions/_shared/resolve-credentials.ts +86 -19
- package/.framework/functions/_shared/resolve-ids.ts +203 -139
- package/.framework/functions/_shared/retry-deliveries.ts +51 -16
- package/.framework/functions/_shared/schema-utils.ts +602 -521
- package/.framework/functions/_shared/security.ts +345 -0
- package/.framework/functions/_shared/testing.ts +197 -172
- package/.framework/functions/_shared/tracing.ts +351 -21
- package/.framework/functions/_shared/trigger-engine.ts +425 -136
- package/.framework/functions/_shared/webhook-registration.ts +71 -70
- package/.framework/functions/_shared/webhook-registry.ts +126 -83
- package/.framework/functions/account-nodes.ts +30 -30
- package/.framework/functions/adapters/generic-webhook-inbound.ts +49 -16
- package/.framework/functions/adapters/generic-webhook-outbound.ts +17 -17
- package/.framework/functions/adapters/openai-outbound.ts +15 -16
- package/.framework/functions/admin-data.ts +596 -173
- package/.framework/functions/admin-funnel.ts +64 -60
- package/.framework/functions/admin-install-funnel.ts +84 -66
- package/.framework/functions/admin-signals.ts +69 -51
- package/.framework/functions/ai-agents.ts +431 -106
- package/.framework/functions/ai-interactions.ts +186 -112
- package/.framework/functions/api-keys.ts +107 -107
- package/.framework/functions/apps.ts +154 -136
- package/.framework/functions/auth.ts +83 -65
- package/.framework/functions/cil-agent-ingest.ts +189 -232
- package/.framework/functions/cil-agent.ts +433 -177
- package/.framework/functions/cil-callmap.ts +642 -430
- package/.framework/functions/cil-config.ts +139 -135
- package/.framework/functions/cil-context.ts +214 -127
- package/.framework/functions/cil-doc.ts +587 -458
- package/.framework/functions/cil-embeddings.ts +453 -364
- package/.framework/functions/cil-graph.ts +427 -142
- package/.framework/functions/cil-ingest.ts +1418 -1154
- package/.framework/functions/cil-pipeline.ts +276 -21
- package/.framework/functions/cil-project.ts +659 -132
- package/.framework/functions/cil-validate.ts +198 -164
- package/.framework/functions/debug-auth.ts +57 -55
- package/.framework/functions/deliveries.ts +80 -21
- package/.framework/functions/embeddings.ts +1023 -318
- package/.framework/functions/eval-harness.ts +146 -108
- package/.framework/functions/integration-outbound.ts +205 -75
- package/.framework/functions/integration-routes.ts +128 -23
- package/.framework/functions/integrations.ts +125 -100
- package/.framework/functions/invites.ts +1095 -460
- package/.framework/functions/item-progress.ts +158 -102
- package/.framework/functions/kb.ts +34 -10
- package/.framework/functions/logs.ts +133 -133
- package/.framework/functions/observability.ts +152 -122
- package/.framework/functions/pipeline-executions.ts +147 -132
- package/.framework/functions/pipelines.ts +134 -119
- package/.framework/functions/prompt-configs.ts +96 -80
- package/.framework/functions/roles.ts +112 -82
- package/.framework/functions/security.ts +450 -0
- package/.framework/functions/system-cron.ts +117 -80
- package/.framework/functions/system.ts +158 -98
- package/.framework/functions/tests.ts +29 -29
- package/.framework/functions/timers.ts +94 -95
- package/.framework/functions/trigger-scheduler.ts +10 -0
- package/.framework/functions/triggers.ts +179 -149
- package/.framework/functions/types.ts +137 -125
- package/.framework/mcp/index.ts +133 -0
- package/.framework/mcp/load-env.ts +60 -0
- package/.framework/mcp/shared/app-manifest.ts +275 -0
- package/.framework/mcp/shared/db.ts +477 -0
- package/.framework/mcp/shared/kb.ts +118 -0
- package/.framework/mcp/tools/architect.ts +431 -0
- package/.framework/mcp/tools/cil/context.ts +345 -0
- package/.framework/mcp/tools/cil/graph.ts +242 -0
- package/.framework/mcp/tools/cil/ingest.ts +1217 -0
- package/.framework/mcp/tools/cil/pipeline-orchestrator.ts +693 -0
- package/.framework/mcp/tools/cil/pipeline.ts +767 -0
- package/.framework/mcp/tools/cil/project.ts +791 -0
- package/.framework/mcp/tools/cil/retrieval.ts +336 -0
- package/.framework/mcp/tools/cil/search-core.ts +454 -0
- package/.framework/mcp/tools/cil/search.ts +97 -0
- package/.framework/mcp/tools/cil/suggest.ts +186 -0
- package/.framework/mcp/tools/cil/validate.ts +1369 -0
- package/.framework/mcp/tools/kb/delete.ts +139 -0
- package/.framework/mcp/tools/kb/index.ts +52 -0
- package/.framework/mcp/tools/kb/ingest.ts +84 -0
- package/.framework/mcp/tools/kb/list-types.ts +102 -0
- package/.framework/mcp/tools/kb/publish.ts +100 -0
- package/.framework/mcp/tools/kb/reindex.ts +86 -0
- package/.framework/mcp/tools/kb/revoke.ts +85 -0
- package/.framework/mcp/tools/kb/search.ts +101 -0
- package/.framework/mcp/tools/kb/upsert.ts +125 -0
- package/.framework/mcp/tools/observability.ts +510 -0
- package/.framework/migrations/001_core_schema.sql +15 -0
- package/.framework/migrations/002_core_rls_and_functions.sql +15 -0
- package/.framework/migrations/003_core_system_data.sql +16 -1
- package/.framework/migrations/004_core_rpc_and_broker.sql +17 -1
- package/.framework/migrations/005_core_observability.sql +17 -1
- package/.framework/migrations/006_security_hardening_rls.sql +15 -0
- package/.framework/migrations/007_kb_article_list.sql +17 -1
- package/.framework/migrations/008_items_target.sql +15 -0
- package/.framework/migrations/009_roles_slug_unique.sql +15 -0
- package/.framework/migrations/010_auth_user_trigger.sql +15 -0
- package/.framework/migrations/011_spine_system_account.sql +16 -0
- package/.framework/migrations/012_service_role_grants.sql +16 -0
- package/.framework/migrations/013_get_account_apps_role_filter.sql +15 -0
- package/.framework/migrations/014_apps_required_roles.sql +16 -0
- package/.framework/migrations/015_types_kind_slug_unique.sql +15 -0
- package/.framework/migrations/016_cil_types.sql +281 -0
- package/.framework/migrations/017_cil_stable_ids.sql +37 -0
- package/.framework/migrations/018_runtime_tables.sql +129 -0
- package/.framework/migrations/019_agent_prompt_columns.sql +56 -0
- package/.framework/migrations/020_schema_reconciliation.sql +67 -0
- package/.framework/migrations/021_kb_embedding_lifecycle.sql +31 -0
- package/.framework/migrations/032_cil_status_migration.sql +73 -0
- package/.framework/migrations/033_cil_versioning.sql +73 -0
- package/.framework/migrations/034_match_embeddings_knn.sql +115 -0
- package/.framework/migrations/035_rate_limits.sql +55 -0
- package/.framework/migrations/036_demo_record_flags.sql +72 -0
- package/.framework/migrations/037_kb_types_canonical.sql +244 -0
- package/.framework/migrations/038_drop_demo_record_flags.sql +38 -0
- package/.framework/migrations/042_registration_hierarchy.sql +309 -0
- package/.framework/migrations/043_policy_actor_cleanup.sql +39 -0
- package/.framework/migrations/044_match_embeddings_filtered_knn.sql +151 -0
- package/.framework/migrations/045_security_critical_rls.sql +139 -0
- package/.framework/migrations/046_security_missing_rls.sql +79 -0
- package/.framework/migrations/047_people_updated_by.sql +27 -0
- package/.framework/migrations/048_watcher_last_seen_at.sql +24 -0
- package/.framework/migrations/049_security_blocklist.sql +148 -0
- package/.framework/migrations/050_notifications.sql +49 -0
- package/.framework/migrations/051_message_agent_fields.sql +74 -0
- package/.framework/migrations/052_registration_security.sql +421 -0
- package/.framework/migrations/053_builtin_action_seeds.sql +66 -0
- package/.framework/migrations/054_kb_ingest_lease.sql +157 -0
- package/.framework/migrations/055_type_id_drift_reconciliation.sql +33 -0
- package/.framework/migrations/056_slug_column_reconciliation.sql +38 -0
- package/.framework/migrations/057_pipelines_slug_identity.sql +14 -0
- package/.framework/migrations/058_account_data_field_declarations.sql +53 -0
- package/.framework/migrations/059_registration_placement_fixes.sql +269 -0
- package/.framework/migrations/060_account_person_record_permissions.sql +38 -0
- package/.framework/migrations/061_fk_dedup.sql +32 -0
- package/.framework/public/spine-logo.svg +10 -3
- package/.framework/scripts/app-install-cli.ts +190 -93
- package/.framework/scripts/assemble-frontend.sh +127 -44
- package/.framework/scripts/assemble-functions.sh +128 -30
- package/.framework/scripts/boundary-check.sh +6 -2
- package/.framework/scripts/build-manifest.sh +24 -68
- package/.framework/scripts/check-core-integrity.sh +15 -76
- package/.framework/scripts/checksum-manifest.mts +343 -0
- package/.framework/scripts/cil-migrate-markers.ts +403 -0
- package/.framework/scripts/fix-cil-markers.mjs +176 -0
- package/.framework/scripts/verify-integrity.sh +21 -57
- package/.framework/scripts/verify-manifest.mts +305 -0
- package/.framework/seeds/types/funnel_signal_use.json +74 -21
- package/.framework/seeds/types/spine_instance.json +73 -21
- package/.framework/src/App.tsx +118 -72
- package/.framework/src/apps/admin/index.tsx +855 -58
- package/.framework/src/components/AppWrapper.tsx +43 -45
- package/.framework/src/components/CustomAppLoader.tsx +160 -116
- package/.framework/src/components/admin/AdminListPage.tsx +46 -44
- package/.framework/src/components/admin/AdminSidebar.tsx +57 -47
- package/.framework/src/components/admin/AdminStatsCard.tsx +46 -44
- package/.framework/src/components/admin/PageInstructions.tsx +98 -2
- package/.framework/src/components/admin/SortableTableHeader.tsx +44 -45
- package/.framework/src/components/app-shell/GenericAppShell.tsx +64 -65
- package/.framework/src/components/app-shell/GenericDetailPage.tsx +44 -47
- package/.framework/src/components/app-shell/GenericListPage.tsx +45 -49
- package/.framework/src/components/app-sidebar.tsx +42 -45
- package/.framework/src/components/auth/ProtectedRoute.tsx +48 -41
- package/.framework/src/components/auth/TurnstileWidget.tsx +27 -0
- package/.framework/src/components/kb/KBArticleEditor.tsx +231 -22
- package/.framework/src/components/kb/KBArticleList.tsx +251 -10
- package/.framework/src/components/layout/AppShell.tsx +51 -45
- package/.framework/src/components/layout/Header.tsx +42 -43
- package/.framework/src/components/layout/Layout.tsx +46 -46
- package/.framework/src/components/layout/Sidebar.tsx +196 -96
- package/.framework/src/components/runtime/DataDetailHeader.tsx +55 -30
- package/.framework/src/components/runtime/DataDetailPage.tsx +31 -269
- package/.framework/src/components/runtime/DataFilters.tsx +49 -74
- package/.framework/src/components/runtime/DataHeader.tsx +53 -32
- package/.framework/src/components/runtime/DataListPage.tsx +51 -155
- package/.framework/src/components/runtime/DataStats.tsx +66 -44
- package/.framework/src/components/runtime/DataTable.tsx +49 -149
- package/.framework/src/components/runtime/SchemaDetailForm.tsx +45 -75
- package/.framework/src/components/runtime/index.ts +119 -16
- package/.framework/src/components/search-form.tsx +46 -29
- package/.framework/src/components/shared/AgentView.tsx +65 -48
- package/.framework/src/components/shared/FieldRenderer.tsx +144 -50
- package/.framework/src/components/shared/InviteManager.tsx +207 -97
- package/.framework/src/components/shared/MemberList.tsx +97 -0
- package/.framework/src/components/shared/SchemaFields.tsx +107 -86
- package/.framework/src/components/ui/DataTable.tsx +80 -68
- package/.framework/src/components/ui/Form.tsx +157 -146
- package/.framework/src/components/ui/ItemCard.tsx +74 -67
- package/.framework/src/components/ui/ItemListView.tsx +73 -68
- package/.framework/src/components/ui/LoadingSpinner.tsx +43 -48
- package/.framework/src/components/ui/Modal.tsx +78 -68
- package/.framework/src/components/ui/RichTextEditor.tsx +89 -69
- package/.framework/src/components/ui/accordion.tsx +85 -86
- package/.framework/src/components/ui/alert-dialog.tsx +197 -184
- package/.framework/src/components/ui/alert.tsx +105 -94
- package/.framework/src/components/ui/aspect-ratio.tsx +57 -43
- package/.framework/src/components/ui/avatar.tsx +122 -107
- package/.framework/src/components/ui/badge.tsx +60 -55
- package/.framework/src/components/ui/breadcrumb.tsx +127 -128
- package/.framework/src/components/ui/button-group.tsx +86 -72
- package/.framework/src/components/ui/button.tsx +71 -50
- package/.framework/src/components/ui/calendar.tsx +72 -57
- package/.framework/src/components/ui/card.tsx +136 -129
- package/.framework/src/components/ui/carousel.tsx +226 -107
- package/.framework/src/components/ui/chart.tsx +252 -147
- package/.framework/src/components/ui/checkbox.tsx +43 -44
- package/.framework/src/components/ui/collapsible.tsx +86 -71
- package/.framework/src/components/ui/combobox.tsx +282 -249
- package/.framework/src/components/ui/command.tsx +158 -146
- package/.framework/src/components/ui/context-menu.tsx +239 -240
- package/.framework/src/components/ui/dialog.tsx +174 -157
- package/.framework/src/components/ui/direction.tsx +72 -56
- package/.framework/src/components/ui/drawer.tsx +168 -169
- package/.framework/src/components/ui/dropdown-menu.tsx +254 -223
- package/.framework/src/components/ui/empty.tsx +131 -120
- package/.framework/src/components/ui/field.tsx +205 -173
- package/.framework/src/components/ui/hover-card.tsx +71 -72
- package/.framework/src/components/ui/input-group.tsx +148 -133
- package/.framework/src/components/ui/input-otp.tsx +99 -86
- package/.framework/src/components/ui/input.tsx +43 -41
- package/.framework/src/components/ui/item.tsx +207 -185
- package/.framework/src/components/ui/kbd.tsx +57 -56
- package/.framework/src/components/ui/label.tsx +45 -41
- package/.framework/src/components/ui/menubar.tsx +268 -236
- package/.framework/src/components/ui/native-select.tsx +85 -86
- package/.framework/src/components/ui/navigation-menu.tsx +166 -156
- package/.framework/src/components/ui/pagination.tsx +131 -141
- package/.framework/src/components/ui/popover.tsx +125 -128
- package/.framework/src/components/ui/progress.tsx +47 -44
- package/.framework/src/components/ui/radio-group.tsx +60 -55
- package/.framework/src/components/ui/resizable.tsx +85 -72
- package/.framework/src/components/ui/scroll-area.tsx +57 -58
- package/.framework/src/components/ui/select.tsx +182 -169
- package/.framework/src/components/ui/separator.tsx +42 -43
- package/.framework/src/components/ui/sheet.tsx +170 -159
- package/.framework/src/components/ui/sidebar.tsx +395 -398
- package/.framework/src/components/ui/skeleton.tsx +42 -43
- package/.framework/src/components/ui/slider.tsx +61 -44
- package/.framework/src/components/ui/sonner.tsx +44 -44
- package/.framework/src/components/ui/spinner.tsx +47 -42
- package/.framework/src/components/ui/switch.tsx +56 -42
- package/.framework/src/components/ui/table-primitives.tsx +272 -132
- package/.framework/src/components/ui/table.tsx +140 -142
- package/.framework/src/components/ui/tabs.tsx +110 -93
- package/.framework/src/components/ui/textarea.tsx +43 -44
- package/.framework/src/components/ui/toggle-group.tsx +87 -71
- package/.framework/src/components/ui/toggle.tsx +56 -56
- package/.framework/src/components/ui/tooltip.tsx +99 -85
- package/.framework/src/contexts/AppContext.tsx +166 -114
- package/.framework/src/contexts/AuthContext.tsx +232 -137
- package/.framework/src/hooks/use-mobile.ts +43 -44
- package/.framework/src/hooks/useApi.ts +185 -172
- package/.framework/src/hooks/useAppPath.ts +31 -29
- package/.framework/src/hooks/useApps.ts +77 -42
- package/.framework/src/hooks/useEntityList.ts +66 -29
- package/.framework/src/hooks/useEntityRecord.ts +76 -32
- package/.framework/src/hooks/useForm.ts +62 -30
- package/.framework/src/hooks/useListSchema.ts +60 -43
- package/.framework/src/hooks/useSchemaRecord.ts +115 -95
- package/.framework/src/lib/api.ts +258 -134
- package/.framework/src/lib/registration.ts +181 -0
- package/.framework/src/lib/supabase.ts +118 -81
- package/.framework/src/lib/utils.ts +266 -266
- package/.framework/src/main.tsx +43 -44
- package/.framework/src/pages/DashboardPage.tsx +44 -43
- package/.framework/src/pages/NoAppPage.tsx +50 -0
- package/.framework/src/pages/NotFoundPage.tsx +32 -29
- package/.framework/src/pages/SetupPage.tsx +34 -33
- package/.framework/src/pages/admin/AIAgentDetailPage.tsx +69 -58
- package/.framework/src/pages/admin/AIAgentsPage.tsx +43 -40
- package/.framework/src/pages/admin/APIKeyDetailPage.tsx +63 -55
- package/.framework/src/pages/admin/APIKeysPage.tsx +44 -42
- package/.framework/src/pages/admin/AlertsConfigPage.tsx +117 -94
- package/.framework/src/pages/admin/AppDetailPage.tsx +48 -42
- package/.framework/src/pages/admin/AppsPage.tsx +45 -42
- package/.framework/src/pages/admin/DeliveriesPage.tsx +49 -17
- package/.framework/src/pages/admin/DesignedPage.tsx +31 -30
- package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +58 -0
- package/.framework/src/pages/admin/EmbeddingsPage.tsx +49 -0
- package/.framework/src/pages/admin/ExtendedShadcnTestPage.tsx +31 -29
- package/.framework/src/pages/admin/IncrementalShadcnTestPage.tsx +46 -29
- package/.framework/src/pages/admin/IntegratedDashboard.tsx +32 -29
- package/.framework/src/pages/admin/IntegrationDetailPage.tsx +68 -55
- package/.framework/src/pages/admin/IntegrationsPage.tsx +45 -42
- package/.framework/src/pages/admin/InvitesPage.tsx +60 -44
- package/.framework/src/pages/admin/LogsPage.tsx +87 -137
- package/.framework/src/pages/admin/MinimalShadcnTestPage.tsx +31 -29
- package/.framework/src/pages/admin/ObservabilityDashboard.tsx +150 -89
- package/.framework/src/pages/admin/PipelineDetailPage.tsx +77 -104
- package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +44 -43
- package/.framework/src/pages/admin/PipelinesPage.tsx +59 -145
- package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +53 -42
- package/.framework/src/pages/admin/PromptConfigsPage.tsx +47 -117
- package/.framework/src/pages/admin/ProperlyDesignedPage.tsx +31 -44
- package/.framework/src/pages/admin/RoleDetailPage.tsx +49 -92
- package/.framework/src/pages/admin/RolesPage.tsx +47 -164
- package/.framework/src/pages/admin/SecurityPage.tsx +310 -0
- package/.framework/src/pages/admin/SelectTestPage.tsx +30 -32
- package/.framework/src/pages/admin/ShadcnTestPage.tsx +37 -44
- package/.framework/src/pages/admin/SimpleDashboard.tsx +32 -44
- package/.framework/src/pages/admin/TestRunDetailPage.tsx +97 -44
- package/.framework/src/pages/admin/TestingDashboard.tsx +126 -71
- package/.framework/src/pages/admin/TimerDetailPage.tsx +67 -55
- package/.framework/src/pages/admin/TimersPage.tsx +44 -42
- package/.framework/src/pages/admin/TriggerDetailPage.tsx +47 -42
- package/.framework/src/pages/admin/TriggersPage.tsx +58 -57
- package/.framework/src/pages/admin/TypeDetailPage.tsx +91 -55
- package/.framework/src/pages/admin/TypesPage.tsx +45 -42
- package/.framework/src/pages/admin/cil/CILAgentPage.tsx +258 -128
- package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +127 -123
- package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +308 -235
- package/.framework/src/pages/admin/cil/CILFileListPage.tsx +159 -110
- package/.framework/src/pages/admin/cil/CILFileSelectPage.tsx +432 -0
- package/.framework/src/pages/admin/cil/CILGraphPage.tsx +200 -178
- package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +286 -239
- package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +211 -90
- package/.framework/src/pages/admin/cil/CILSearchPage.tsx +156 -143
- package/.framework/src/pages/admin/cil/CILSuggestionsPage.tsx +379 -0
- package/.framework/src/pages/admin/cil/CILVersionsPage.tsx +337 -0
- package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +219 -214
- package/.framework/src/pages/admin/kb/KBAdminPage.tsx +64 -0
- package/.framework/src/pages/auth/AuthConfirmPage.tsx +135 -65
- package/.framework/src/pages/auth/ForgotPasswordPage.tsx +39 -31
- package/.framework/src/pages/auth/LoginPage.tsx +38 -32
- package/.framework/src/pages/auth/PendingApprovalPage.tsx +31 -28
- package/.framework/src/pages/auth/RegisterPage.tsx +429 -155
- package/.framework/src/pages/spine-framework/APIPage.tsx +33 -30
- package/.framework/src/pages/spine-framework/CLIPage.tsx +32 -30
- package/.framework/src/types/auth.ts +101 -93
- package/.framework/src/types/types.ts +283 -262
- package/.framework/templates/project.json +87 -0
- package/.framework/templates/spine.config.neutral.json +7 -0
- package/.framework/tests/api/api-surface.test.ts +381 -0
- package/.framework/tests/fixtures/seed.ts +427 -0
- package/.framework/tests/fixtures/teardown.ts +228 -0
- package/.framework/tests/reporter.ts +351 -0
- package/.framework/tests/setup.ts +135 -0
- package/.framework/tests/ui/ui-sweep.ts +278 -0
- package/.framework/tests/unit/admin-data-logger.test.ts +310 -0
- package/.framework/tests/unit/agent-runner.test.ts +2389 -0
- package/.framework/tests/unit/ai-interactions.test.ts +81 -0
- package/.framework/tests/unit/app-manifest.test.ts +359 -0
- package/.framework/tests/unit/assembly-scripts.test.ts +172 -0
- package/.framework/tests/unit/cil-determinism.test.ts +85 -0
- package/.framework/tests/unit/core-isolation.test.ts +153 -0
- package/.framework/tests/unit/funnel-signals.test.ts +135 -0
- package/.framework/tests/unit/install-app.test.ts +1759 -0
- package/.framework/tests/unit/invites-security.test.ts +572 -0
- package/.framework/tests/unit/kb-ingest-lease.test.ts +287 -0
- package/.framework/tests/unit/kb-search.test.ts +119 -0
- package/.framework/tests/unit/migrate.test.ts +509 -0
- package/.framework/tests/unit/notify.test.ts +136 -0
- package/.framework/tests/unit/permissions.test.ts +269 -0
- package/.framework/tests/unit/pipeline-runner.test.ts +755 -0
- package/.framework/tests/unit/principal-cache.test.ts +138 -0
- package/.framework/tests/unit/retrieval-golden.test.ts +520 -0
- package/.framework/tests/unit/runtime-isolation.test.ts +642 -0
- package/.framework/tests/unit/schema-utils.test.ts +225 -0
- package/.framework/tests/unit/trigger-engine.test.ts +513 -0
- package/.framework/tests/unit/validate-app.test.ts +527 -0
- package/README.md +34 -3
- package/bin/spine-framework.cjs +1 -0
- package/config/tailwind.config.cjs +7 -0
- package/config/tsconfig.functions.json +42 -0
- package/config/tsconfig.json +37 -9
- package/config/vite.config.ts +31 -2
- package/netlify.toml +31 -3
- package/package.json +46 -29
- package/scripts/assemble-frontend.sh +127 -44
- package/scripts/assemble-functions.sh +127 -29
- package/scripts/boundary-check.sh +6 -2
- package/scripts/build-manifest.sh +24 -68
- package/scripts/checksum-manifest.mts +345 -0
- package/scripts/dev-clean.sh +86 -0
- package/scripts/dev-netlify.sh +49 -0
- package/scripts/netlify-dev-wrapper.sh +2 -0
- package/scripts/verify-install.ts +358 -0
- package/scripts/verify-integrity.sh +21 -57
- package/scripts/verify-manifest.mts +305 -0
- package/templates/project/gitignore +45 -0
- package/{config → templates/project}/package-lock.json +22335 -9366
- package/vitest.config.ts +46 -0
- package/.framework/public/spine.config.json +0 -91
- package/config/deno.lock +0 -108
- package/config/tsconfig.node.tsbuildinfo +0 -1
- package/config/tsconfig.tsbuildinfo +0 -1
- package/config/vite.config.d.ts +0 -2
- package/custom/.devin/AGENT.md +0 -357
- package/custom/.devin/skills/install-app/SKILL.md +0 -39
- package/custom/.devin/skills/spine-workbench-discovery/SKILL.md +0 -39
- package/custom/.devin/skills/spine-workbench-idea/SKILL.md +0 -36
- package/custom/.devin/skills/spine-workbench-implement/SKILL.md +0 -46
- package/custom/.devin/skills/spine-workbench-initiative/SKILL.md +0 -28
- package/custom/.devin/skills/spine-workbench-plan/SKILL.md +0 -38
- package/custom/.devin/workflows/app-install.yaml +0 -83
- package/custom/README.md +0 -79
- package/docs/README.md +0 -15
- package/scripts/app-install-cli.ts +0 -286
- package/scripts/check-core-integrity.sh +0 -82
- package/scripts/ingest-chunks.cjs +0 -202
- package/scripts/kb-chunk-parser.cjs +0 -312
- package/scripts/kb-chunk-parser.ts +0 -330
- package/scripts/kb-ingest-docs.ts +0 -203
- package/scripts/load-test-app-install.ts +0 -484
- package/scripts/test-login.js +0 -33
- package/spine.config.json +0 -91
|
@@ -1,42 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// CIL[DOC-MACRO purpose="Create single embedding record"]
|
|
24
|
-
// CIL[DOC-RESPONSIBILITY responsibility="Create embedding with validation and audit logging"]
|
|
25
|
-
// CIL[DOC-CONTEXT module="embeddings" layer="backend_functions" related_files="[]"]
|
|
26
|
-
// CIL[DOC-CONTRACT inputs="embedding_data" outputs="created_embedding" errors="validation_errors,db_errors" side_effects="db_write,audit_log"]
|
|
27
|
-
// CIL[DOC-MICRO logic_summary="Validate input, create embedding record, log creation event" notable_decisions="[]"]
|
|
28
|
-
// CIL[DOC-CONFIDENCE pass="first" score="0.90" flags="none"]
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new embedding record for a knowledge base item and persists it to the database. This function also handles ownership and audit logging for the embedding.
|
|
3
|
+
*
|
|
4
|
+
* @throws Error — if required fields are missing, user/account context is invalid, or database insert fails.
|
|
5
|
+
* @sideEffects Inserts one row into the embeddings table and emits an audit log.
|
|
6
|
+
* @stability stable
|
|
7
|
+
* @calls ctx.db.from, emitLog
|
|
8
|
+
* @cil-generated
|
|
9
|
+
*/
|
|
10
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:create:constant" type="constant" identity="create" parent="~/.framework/functions/embeddings.ts"]
|
|
29
11
|
export const create = createHandler(async (ctx, body) => {
|
|
30
12
|
const { model_id, document_id, chunk_index, content, metadata } = body
|
|
31
|
-
|
|
32
13
|
if (!model_id || !document_id || !content) {
|
|
33
14
|
throw new Error('model_id, document_id, and content are required')
|
|
34
15
|
}
|
|
35
|
-
|
|
36
16
|
if (!ctx.principal || ctx.principal.id === 'anonymous' || !ctx.accountId) {
|
|
37
17
|
throw new Error('User context (person and account) required')
|
|
38
18
|
}
|
|
39
|
-
|
|
40
19
|
const { data, error: err } = await ctx.db
|
|
41
20
|
.from('embeddings')
|
|
42
21
|
.insert({
|
|
@@ -49,105 +28,88 @@ export const create = createHandler(async (ctx, body) => {
|
|
|
49
28
|
})
|
|
50
29
|
.select()
|
|
51
30
|
.single()
|
|
52
|
-
|
|
53
31
|
if (err) throw err
|
|
54
|
-
|
|
55
32
|
await emitLog(ctx, 'embedding.created',
|
|
56
33
|
{ type: 'embedding', id: data.id },
|
|
57
34
|
{ after: { document_id, model_id } }
|
|
58
35
|
)
|
|
59
|
-
|
|
60
36
|
return data
|
|
61
37
|
})
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:create:constant"]
|
|
39
|
+
/**
|
|
40
|
+
* Updates an existing embedding's content and metadata, applying partial updates to an embedding record. It also emits an audit log for tracking changes.
|
|
41
|
+
*
|
|
42
|
+
* @throws Error — if no id is provided or the database update fails.
|
|
43
|
+
* @sideEffects Updates the embeddings row in the database and emits an audit log.
|
|
44
|
+
* @stability stable
|
|
45
|
+
* @calls ctx.db.from('embeddings'), emitLog
|
|
46
|
+
* @cil-generated
|
|
47
|
+
*/
|
|
48
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:update:constant" type="constant" identity="update" parent="~/.framework/functions/embeddings.ts"]
|
|
72
49
|
export const update = createHandler(async (ctx, body) => {
|
|
73
50
|
const id = body?.id || ctx.query?.id
|
|
74
51
|
const { id: _bodyId, content, metadata } = body || {}
|
|
75
|
-
|
|
76
52
|
if (!id) {
|
|
77
53
|
throw new Error('Embedding ID is required')
|
|
78
54
|
}
|
|
79
|
-
|
|
80
55
|
const updateFields: Record<string, any> = {}
|
|
81
56
|
if (content !== undefined) updateFields.content = content
|
|
82
57
|
if (metadata !== undefined) updateFields.metadata = metadata
|
|
83
|
-
|
|
84
58
|
const { data, error: err } = await ctx.db
|
|
85
59
|
.from('embeddings')
|
|
86
60
|
.update(updateFields)
|
|
87
61
|
.eq('id', id)
|
|
88
62
|
.select()
|
|
89
63
|
.single()
|
|
90
|
-
|
|
91
64
|
if (err) throw err
|
|
92
|
-
|
|
93
65
|
await emitLog(ctx, 'embedding.updated',
|
|
94
66
|
{ type: 'embedding', id },
|
|
95
67
|
{ after: { content_updated: !!content } }
|
|
96
68
|
)
|
|
97
|
-
|
|
98
69
|
return data
|
|
99
70
|
})
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// CIL[DOC-MACRO purpose="Generate embeddings for knowledge item"]
|
|
129
|
-
// CIL[DOC-RESPONSIBILITY responsibility="Create vectors for item content using multiple strategies"]
|
|
130
|
-
// CIL[DOC-CONTEXT module="embeddings" layer="backend_functions" related_files="[]"]
|
|
131
|
-
// CIL[DOC-CONTRACT inputs="item_id,options" outputs="generation_result" errors="validation_errors,api_errors" side_effects="db_write,api_calls,audit_log"]
|
|
132
|
-
// CIL[DOC-MICRO logic_summary="Extract content, call embedding API, store vectors with metadata" notable_decisions="[]"]
|
|
133
|
-
// CIL[DOC-CONFIDENCE pass="first" score="0.80" flags="complex_logic,external_api"]
|
|
71
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:update:constant"]
|
|
72
|
+
/**
|
|
73
|
+
* VECTOR_TYPE_SLOTS defines a mapping of vector types to their corresponding fixed slots, ensuring consistency with the CIL pipeline's conventions. This structure is essential for managing unique identifiers for each vector type based on model and document IDs.
|
|
74
|
+
*
|
|
75
|
+
* @sideEffects none
|
|
76
|
+
* @stability stable
|
|
77
|
+
* @cil-generated
|
|
78
|
+
*/
|
|
79
|
+
// chunk_index is unique per (model_id, document_id) — each vector type
|
|
80
|
+
// occupies a fixed slot (matching the CIL pipeline's convention).
|
|
81
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:vector_type_slots:constant" type="constant" identity="VECTOR_TYPE_SLOTS" parent="~/.framework/functions/embeddings.ts"]
|
|
82
|
+
const VECTOR_TYPE_SLOTS: Record<string, number> = {
|
|
83
|
+
semantic: 0, structure: 1, context: 2, blast_radius: 3,
|
|
84
|
+
configuration: 4, constraint: 5, summary: 6, intent: 7,
|
|
85
|
+
cause: 8, procedure: 9, outcome: 10, error_signal: 11,
|
|
86
|
+
}
|
|
87
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:vector_type_slots:constant"]
|
|
88
|
+
/**
|
|
89
|
+
* Generates or refreshes vector embeddings for a knowledge base item. This function builds text content for configured vector types, calls an embedding API, and persists vectors with hashes.
|
|
90
|
+
*
|
|
91
|
+
* @throws Error — if item_id missing, item not found, or embedding API fails
|
|
92
|
+
* @sideEffects reads and writes embeddings rows, calls external OpenAI embedding API, emits an audit log
|
|
93
|
+
* @stability stable
|
|
94
|
+
* @calls adminDb.from('items'), adminDb.select, adminDb.eq, adminDb.single
|
|
95
|
+
* @cil-generated
|
|
96
|
+
*/
|
|
97
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:generate:constant" type="constant" identity="generate" parent="~/.framework/functions/embeddings.ts"]
|
|
134
98
|
export const generate = createHandler(async (ctx, body) => {
|
|
135
99
|
const { item_id, force_regenerate = false, account_id_override } = body || {}
|
|
136
100
|
if (!item_id) throw new Error('item_id is required')
|
|
137
|
-
|
|
138
|
-
|
|
139
101
|
const { data: item, error: itemErr } = await adminDb
|
|
140
102
|
.from('items')
|
|
141
|
-
.select('*, type:types(design_schema)')
|
|
103
|
+
.select('*, type:types(slug, design_schema)')
|
|
142
104
|
.eq('id', item_id)
|
|
143
105
|
.single()
|
|
144
|
-
|
|
145
106
|
if (itemErr || !item) throw new Error(`Item ${item_id} not found`)
|
|
146
|
-
|
|
147
107
|
const typeDesign = item.type?.design_schema || {}
|
|
108
|
+
const typeSlug = item.type?.slug || ''
|
|
109
|
+
// Match the kbIngest convention (metadata.item_type = type slug) so retrieval
|
|
110
|
+
// item_type filters behave the same regardless of which pipeline wrote the row.
|
|
111
|
+
const itemType = typeSlug.startsWith('kb') ? typeSlug : (item.data?.kb_type ? 'kb_article' : 'item')
|
|
148
112
|
const kbType = item.data?.kb_type || 'article'
|
|
149
|
-
|
|
150
|
-
|
|
151
113
|
let vectorTypes: string[] = []
|
|
152
114
|
const rawVT = typeDesign.vector_types
|
|
153
115
|
if (Array.isArray(rawVT)) {
|
|
@@ -157,53 +119,50 @@ export const generate = createHandler(async (ctx, body) => {
|
|
|
157
119
|
} else {
|
|
158
120
|
vectorTypes = ['semantic', 'structure']
|
|
159
121
|
}
|
|
160
|
-
|
|
161
122
|
const embeddingFields: string[] = typeDesign.embedding_fields?.structure || []
|
|
162
123
|
const resolvedAccountId = account_id_override || item.account_id || await getPlatformAccountId()
|
|
163
124
|
const isPublished = item.status === 'published'
|
|
164
|
-
|
|
165
|
-
|
|
166
125
|
const { data: existing } = await adminDb
|
|
167
126
|
.from('embeddings')
|
|
168
127
|
.select('id, content_hash, chunk_index, metadata')
|
|
169
128
|
.eq('document_id', item_id)
|
|
170
|
-
|
|
171
129
|
const existingMap = new Map<string, any>()
|
|
172
130
|
for (const row of existing || []) {
|
|
173
131
|
const vt = row.metadata?.vector_type || ''
|
|
174
132
|
const ci = row.chunk_index ?? 0
|
|
175
133
|
existingMap.set(`${vt}:${ci}`, row)
|
|
176
134
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
135
|
if (force_regenerate) {
|
|
180
136
|
await adminDb.from('embeddings').delete().eq('document_id', item_id)
|
|
181
137
|
existingMap.clear()
|
|
182
138
|
}
|
|
183
|
-
|
|
184
139
|
const created: string[] = []
|
|
185
140
|
const skipped: string[] = []
|
|
186
141
|
const errors: string[] = []
|
|
187
|
-
|
|
188
|
-
|
|
189
142
|
const syncVectors = vectorTypes.filter(vt => vt !== 'summary')
|
|
190
143
|
const contents: Array<{ vt: string; text: string; chunkIndex: number }> = []
|
|
191
|
-
|
|
144
|
+
// chunk_index must be unique per (model_id, document_id) — assign each
|
|
145
|
+
// vector type a fixed slot (same convention as the CIL pipeline) so rows
|
|
146
|
+
// for different vector types never collide on the UNIQUE constraint.
|
|
192
147
|
for (const vt of syncVectors) {
|
|
193
148
|
const builder = CONTENT_BUILDERS[vt]
|
|
194
149
|
if (!builder) { errors.push(`Unknown vector type: ${vt}`); continue }
|
|
195
150
|
const text = builder(item, { embedding_fields: embeddingFields })
|
|
196
151
|
if (!text) { skipped.push(`${vt}:empty`); continue }
|
|
197
|
-
contents.push({ vt, text, chunkIndex:
|
|
152
|
+
contents.push({ vt, text, chunkIndex: VECTOR_TYPE_SLOTS[vt] ?? (20 + syncVectors.indexOf(vt)) })
|
|
153
|
+
}
|
|
154
|
+
// Drop rows left over from a previously larger vector-type set.
|
|
155
|
+
const keep = new Set(contents.map(c => `${c.vt}:${c.chunkIndex}`))
|
|
156
|
+
const staleIds = (existing || [])
|
|
157
|
+
.filter(r => !keep.has(`${r.metadata?.vector_type || ''}:${r.chunk_index ?? 0}`))
|
|
158
|
+
.map(r => r.id)
|
|
159
|
+
if (staleIds.length) {
|
|
160
|
+
await adminDb.from('embeddings').delete().in('id', staleIds)
|
|
198
161
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
162
|
if (vectorTypes.includes('summary')) {
|
|
202
163
|
const summaryText = await generateAiSummary(item, ctx)
|
|
203
164
|
if (summaryText) contents.push({ vt: 'summary', text: summaryText, chunkIndex: 0 })
|
|
204
165
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
166
|
const toEmbed = contents.filter(({ vt, text, chunkIndex }) => {
|
|
208
167
|
const hash = contentHash(text)
|
|
209
168
|
const key = `${vt}:${chunkIndex}`
|
|
@@ -211,28 +170,21 @@ export const generate = createHandler(async (ctx, body) => {
|
|
|
211
170
|
if (row && row.content_hash === hash) { skipped.push(key); return false }
|
|
212
171
|
return true
|
|
213
172
|
})
|
|
214
|
-
|
|
215
173
|
if (!toEmbed.length) {
|
|
216
174
|
return { item_id, embeddings_created: 0, embeddings_skipped: skipped.length, errors }
|
|
217
175
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
176
|
let vectors: string[] = []
|
|
221
177
|
try {
|
|
222
178
|
vectors = await callEmbeddingApi(toEmbed.map(c => c.text), ctx)
|
|
223
179
|
} catch (e: any) {
|
|
224
180
|
throw new Error(`Embedding API call failed: ${e.message}`)
|
|
225
181
|
}
|
|
226
|
-
|
|
227
182
|
const now = new Date().toISOString()
|
|
228
|
-
|
|
229
|
-
|
|
230
183
|
for (let i = 0; i < toEmbed.length; i++) {
|
|
231
184
|
const { vt, text, chunkIndex } = toEmbed[i]
|
|
232
185
|
const hash = contentHash(text)
|
|
233
186
|
const key = `${vt}:${chunkIndex}`
|
|
234
187
|
const existingRow = existingMap.get(key)
|
|
235
|
-
|
|
236
188
|
const row = {
|
|
237
189
|
account_id: resolvedAccountId,
|
|
238
190
|
model_id: 'text-embedding-3-small',
|
|
@@ -245,13 +197,12 @@ export const generate = createHandler(async (ctx, body) => {
|
|
|
245
197
|
revoked_at: null,
|
|
246
198
|
metadata: {
|
|
247
199
|
vector_type: vt,
|
|
248
|
-
item_type:
|
|
200
|
+
item_type: itemType,
|
|
249
201
|
kb_type: kbType,
|
|
250
202
|
security_level: item.data?.security_level || 'internal',
|
|
251
203
|
source_item_id: item_id,
|
|
252
204
|
},
|
|
253
205
|
}
|
|
254
|
-
|
|
255
206
|
if (existingRow) {
|
|
256
207
|
await adminDb.from('embeddings').update(row).eq('id', existingRow.id)
|
|
257
208
|
} else {
|
|
@@ -259,12 +210,10 @@ export const generate = createHandler(async (ctx, body) => {
|
|
|
259
210
|
}
|
|
260
211
|
created.push(key)
|
|
261
212
|
}
|
|
262
|
-
|
|
263
213
|
await emitLog(ctx, 'embeddings.generated',
|
|
264
214
|
{ type: 'item', id: item_id },
|
|
265
215
|
{ after: { vectors_created: created.length, vectors_skipped: skipped.length, is_published: isPublished } }
|
|
266
216
|
)
|
|
267
|
-
|
|
268
217
|
return {
|
|
269
218
|
item_id,
|
|
270
219
|
embeddings_created: created.length,
|
|
@@ -272,6 +221,98 @@ export const generate = createHandler(async (ctx, body) => {
|
|
|
272
221
|
errors,
|
|
273
222
|
}
|
|
274
223
|
})
|
|
224
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:generate:constant"]
|
|
225
|
+
/**
|
|
226
|
+
* @module embeddings
|
|
227
|
+
* @audience internal
|
|
228
|
+
* @layer app-specific
|
|
229
|
+
* @stability stable
|
|
230
|
+
*
|
|
231
|
+
* This module imports shared utilities for the embeddings Netlify function, setting up the necessary dependencies for handling embedding requests. It plays a crucial role in the system by providing essential functions for authentication, database access, and logging. INVARIANT: No verified external callers; all interactions are local and managed through the defined imports.
|
|
232
|
+
*
|
|
233
|
+
* @seeAlso .framework/functions/_shared/middleware.ts (provides middleware for request handling).
|
|
234
|
+
* @seeAlso .framework/functions/_shared/db.ts (handles database interactions).
|
|
235
|
+
* @seeAlso .framework/functions/_shared/audit.ts (manages logging and auditing).
|
|
236
|
+
*
|
|
237
|
+
* @cil-generated
|
|
238
|
+
*/
|
|
239
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:module_header:module_header" type="module_header" identity="module_header" parent="~/.framework/functions/embeddings.ts"]
|
|
240
|
+
// CIL[DOC-MACRO purpose="Creates a new embedding record for a knowledge base item."]
|
|
241
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Persists an embedding to the embeddings table with ownership and audit logging."]
|
|
242
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
243
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { model_id, document_id, chunk_index, content, metadata }" outputs="the inserted embedding record" errors="throws if required fields missing, user/account context invalid, or database insert fails" side_effects="inserts one row into embeddings table and emits an audit log"]
|
|
244
|
+
// CIL[DOC-MICRO logic_summary="Validates required fields and account context, inserts the embedding row into the database, and emits an embedding.created audit log." notable_decisions="none"]
|
|
245
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
246
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
247
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
// CIL[DOC-MACRO purpose="create constant"]
|
|
271
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the create constant."]
|
|
272
|
+
// CIL[DOC-CONTEXT module=".framework/functions/embeddings.ts" layer="app-specific" related_files=""]
|
|
273
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
274
|
+
// CIL[DOC-MICRO logic_summary="Implements the create constant." notable_decisions="[]"]
|
|
275
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
276
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Creates a new embedding record for a knowledge base item.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
284
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
285
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
286
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
287
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
288
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
// CIL[DOC-MACRO purpose="Updates an existing embedding's content and metadata."]
|
|
294
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Applies partial updates to an embedding record and emits an audit log."]
|
|
295
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
296
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { id?, content?, metadata? }" outputs="the updated embedding record" errors="throws if no id is provided or the database update fails" side_effects="updates embeddings row and emits an audit log"]
|
|
297
|
+
// CIL[DOC-MICRO logic_summary="Resolves the embedding ID from the request, builds an update object, patches the database row, and emits an embedding.updated log." notable_decisions="none"]
|
|
298
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
299
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
300
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Updates an existing embedding's content and metadata.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
308
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
309
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
310
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
311
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
312
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
275
316
|
|
|
276
317
|
|
|
277
318
|
|
|
@@ -285,22 +326,110 @@ export const generate = createHandler(async (ctx, body) => {
|
|
|
285
326
|
|
|
286
327
|
|
|
287
328
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
// CIL[DOC-MACRO purpose="VECTOR_TYPE_SLOTS defines a mapping of vector types to their corresponding fixed slots, ensuring consistency with the CIL pipeline's conventions."]
|
|
342
|
+
// CIL[DOC-RESPONSIBILITY responsibility="VECTOR_TYPE_SLOTS defines a mapping of vector types to their corresponding fixed slots, ensuring consistency with the CIL pipeline's conventions. This structure is essential for managing unique identifiers for each vector type based on model and document IDs."]
|
|
343
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="app-specific" related_files=".framework/functions/_shared/middleware,.framework/functions/_shared/db,.framework/functions/_shared/audit,.framework/functions/_shared/principal,.framework/functions/_shared/permissions,.framework/functions/_shared/llm"]
|
|
344
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
345
|
+
// CIL[DOC-MICRO logic_summary="VECTOR_TYPE_SLOTS defines a mapping of vector types to their corresponding fixed slots, ensuring consistency with the CIL pipeline's conventions. This structure is essential for managing unique identifiers for each vector type based on model and document IDs." notable_decisions="none"]
|
|
346
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
347
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
348
|
+
// CIL[DOC-MACRO purpose="VECTOR_TYPE_SLOTS constant"]
|
|
349
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Implements the VECTOR_TYPE_SLOTS constant."]
|
|
350
|
+
// CIL[DOC-CONTEXT module=".framework/functions/embeddings.ts" layer="app-specific" related_files=""]
|
|
351
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
352
|
+
// CIL[DOC-MICRO logic_summary="Implements the VECTOR_TYPE_SLOTS constant." notable_decisions="[]"]
|
|
353
|
+
// CIL[DOC-CONFIDENCE pass="first" score="0.8" flags="none"]
|
|
295
354
|
// CIL[DOC-STABILITY stability="stable"]
|
|
296
|
-
// CIL[DOC-
|
|
297
|
-
// CIL[DOC-VECTOR type="
|
|
298
|
-
// CIL[DOC-VECTOR type="
|
|
299
|
-
// CIL[DOC-VECTOR type="
|
|
300
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
355
|
+
// CIL[DOC-VECTOR type="context" content="purpose='VECTOR_TYPE_SLOTS defines a mapping of vector types to their corresponding fixed slots, ensuring consistency with the CIL pipeline's conventions.'; No verified external callers" status="ready"]
|
|
356
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only" status="ready"]
|
|
357
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified" status="ready"]
|
|
358
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented" status="ready"]
|
|
301
359
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
302
360
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
303
361
|
|
|
362
|
+
// CIL[DOC-MACRO purpose="Generates or refreshes vector embeddings for a knowledge base item."]
|
|
363
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Builds text content for configured vector types, calls an embedding API, and persists vectors with hashes."]
|
|
364
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
365
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { item_id, force_regenerate?, account_id_override? }" outputs="{ item_id, embeddings_created, embeddings_skipped, errors }" errors="throws if item_id missing, item not found, or embedding API fails" side_effects="reads and writes embeddings rows, calls external OpenAI embedding API, emits an audit log"]
|
|
366
|
+
// CIL[DOC-MICRO logic_summary="Fetches the item and its type slug+design schema, determines vector types, builds content for each at a per-type chunk_index slot, removes stale rows, compares hashes, calls the embedding API for missing or changed vectors, inserts or updates embeddings rows, and emits an embeddings.generated log." notable_decisions="Hashes and skips unchanged vectors; uses text-embedding-3-small by default; falls back vector types to semantic/structure; summary vectors generated via AI if configured; item_type follows the kbIngest convention (type slug for kb-* items)."]
|
|
367
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
368
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
369
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Generates or refreshes vector embeddings for a knowledge base item.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
402
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
403
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
404
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
405
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
406
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
421
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
422
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
423
|
+
// CIL[DOC-CONTEXT module="unknown" layer="unknown" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts"]
|
|
424
|
+
|
|
425
|
+
// CIL[DOC-MACRO purpose="Imports shared utilities for the embeddings Netlify function."]
|
|
426
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Sets up the module's dependencies and shared functions."]
|
|
427
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts"]
|
|
428
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
429
|
+
// CIL[DOC-MICRO logic_summary="Imports crypto, middleware, admin db, audit, principal, permissions, and LLM helpers used by the embedding handlers." notable_decisions="none"]
|
|
430
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
431
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
432
|
+
// CIL[DOC-AUDIENCE audience="developers, operators"]
|
|
304
433
|
import { createHash } from 'crypto'
|
|
305
434
|
import { createHandler } from './_shared/middleware'
|
|
306
435
|
import { adminDb } from './_shared/db'
|
|
@@ -308,21 +437,32 @@ import { emitLog } from './_shared/audit'
|
|
|
308
437
|
import { isSystemAdmin } from './_shared/principal'
|
|
309
438
|
import { sanitizeRecordData } from './_shared/permissions'
|
|
310
439
|
import { callOpenAIEmbeddings, callOpenAIChat } from './_shared/llm'
|
|
311
|
-
// CIL[END
|
|
312
|
-
// CIL[
|
|
313
|
-
// CIL[DOC-
|
|
314
|
-
// CIL[DOC-
|
|
315
|
-
// CIL[DOC-
|
|
316
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="text_content" errors="none" side_effects="none"]
|
|
317
|
-
// CIL[DOC-MICRO logic_summary="Extract and format various content types from knowledge base items" notable_decisions="[]"]
|
|
318
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="complex_logic"]
|
|
319
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
320
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: custom/apps/portal/pages/ContentPage.tsx, custom/apps/cortex/functions/custom_cil-embeddings.ts, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, custom/apps/cortex/pages/operations/OperationsDashboard.tsx, \."]
|
|
321
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
322
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
323
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
440
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:module_header:module_header"]
|
|
441
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Imports shared utilities for the embeddings Netlify function.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
442
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
443
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
444
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
324
445
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
325
446
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
447
|
+
/**
|
|
448
|
+
* Strips HTML tags and decodes common HTML entities to normalize HTML content into plain text for embedding. This function is essential for preparing text data by removing formatting and special characters.
|
|
449
|
+
*
|
|
450
|
+
* @inputSpec
|
|
451
|
+
* html: string (required) — the HTML content to be processed.
|
|
452
|
+
* @outputSpec string — plain text string without HTML tags.
|
|
453
|
+
* @sideEffects none
|
|
454
|
+
* @stability stable
|
|
455
|
+
* @cil-generated
|
|
456
|
+
*/
|
|
457
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:striphtml:function" type="function" identity="stripHtml" parent="~/.framework/functions/embeddings.ts"]
|
|
458
|
+
// CIL[DOC-MACRO purpose="Strips HTML tags and decodes common HTML entities."]
|
|
459
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Normalizes HTML content into plain text for embedding."]
|
|
460
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
461
|
+
// CIL[DOC-CONTRACT inputs="html: string" outputs="plain text string" errors="none" side_effects="none"]
|
|
462
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
463
|
+
// CIL[DOC-MICRO logic_summary="Replaces tags, decodes entities, collapses whitespace, and trims the string." notable_decisions="none"]
|
|
464
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
465
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
326
466
|
function stripHtml(html: string): string {
|
|
327
467
|
return html
|
|
328
468
|
.replace(/<[^>]+>/g, ' ')
|
|
@@ -330,20 +470,104 @@ function stripHtml(html: string): string {
|
|
|
330
470
|
.replace(/"/g, '"').replace(/'/g, "'").replace(/ /g, ' ')
|
|
331
471
|
.replace(/\s+/g, ' ').trim()
|
|
332
472
|
}
|
|
473
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:striphtml:function"]
|
|
333
474
|
|
|
475
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Strips HTML tags and decodes common HTML entities.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
476
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
477
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
478
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
479
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
480
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
481
|
+
/**
|
|
482
|
+
* Returns the first non-empty string from a list of values. This function is useful for extracting meaningful input from potentially undefined or null values.
|
|
483
|
+
*
|
|
484
|
+
* @inputSpec
|
|
485
|
+
* - values: (string | undefined | null)[] (required) — a list of strings that may include undefined or null values.
|
|
486
|
+
* @outputSpec string — the first non-empty string or an empty string if none are found.
|
|
487
|
+
* @sideEffects none
|
|
488
|
+
* @stability stable
|
|
489
|
+
* @cil-generated
|
|
490
|
+
*/
|
|
491
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:firstnonempty:function" type="function" identity="firstNonEmpty" parent="~/.framework/functions/embeddings.ts"]
|
|
492
|
+
// CIL[DOC-MACRO purpose="Returns the first non-empty string from a list of values."]
|
|
493
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Selects the first truthy, trimmed string from candidates."]
|
|
494
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
495
|
+
// CIL[DOC-CONTRACT inputs="...values: (string | undefined | null)[]" outputs="first non-empty string or empty string" errors="none" side_effects="none"]
|
|
496
|
+
// CIL[DOC-MICRO logic_summary="Iterates over arguments and returns the first value that is non-empty after trimming, or an empty string." notable_decisions="none"]
|
|
497
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
498
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
499
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
334
500
|
function firstNonEmpty(...values: (string | undefined | null)[]): string {
|
|
335
501
|
for (const v of values) {
|
|
336
502
|
if (v && String(v).trim()) return String(v).trim()
|
|
337
503
|
}
|
|
338
504
|
return ''
|
|
339
505
|
}
|
|
506
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:firstnonempty:function"]
|
|
507
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Returns the first non-empty string from a list of values.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
508
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
509
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
510
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
511
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
512
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
340
513
|
|
|
514
|
+
/**
|
|
515
|
+
* Builds the semantic text content for an item embedding by concatenating the item title, description blurb, and data-level body for vector search. This function ensures that the content is formatted correctly for retrieval purposes.
|
|
516
|
+
*
|
|
517
|
+
* @inputSpec
|
|
518
|
+
* item: any — the item containing title, description, and data content.
|
|
519
|
+
* @outputSpec string — the concatenated semantic content.
|
|
520
|
+
* @sideEffects none
|
|
521
|
+
* @stability stable
|
|
522
|
+
* @calls stripHtml
|
|
523
|
+
* @cil-generated
|
|
524
|
+
*/
|
|
525
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:buildsemanticcontent:function" type="function" identity="buildSemanticContent" parent="~/.framework/functions/embeddings.ts"]
|
|
526
|
+
// CIL[DOC-MACRO purpose="Builds the semantic text content for an item embedding."]
|
|
527
|
+
// CIL[DOC-LEARNING topic="retrieval" content="KB articles store their body in data.content (data.body/markdown for other kinds) while description is only a short blurb — embedding title+description alone produced useless vectors."]
|
|
528
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Concatenates the item title, description blurb, and data-level body for vector search."]
|
|
529
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
530
|
+
// CIL[DOC-CONTRACT inputs="item: any" outputs="string" errors="none" side_effects="none"]
|
|
531
|
+
// CIL[DOC-MICRO logic_summary="Strips HTML from description and data.content/body/markdown, then joins title, blurb, and body with newlines, filtering empty parts." notable_decisions="none"]
|
|
532
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
533
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
534
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
341
535
|
function buildSemanticContent(item: any): string {
|
|
342
536
|
const title = item.title || ''
|
|
343
|
-
const
|
|
344
|
-
|
|
537
|
+
const blurb = stripHtml(item.description || '')
|
|
538
|
+
const body = stripHtml(
|
|
539
|
+
item.data?.content || item.data?.body || item.data?.markdown || ''
|
|
540
|
+
)
|
|
541
|
+
return [title, blurb, body].filter(Boolean).join('\n')
|
|
345
542
|
}
|
|
543
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:buildsemanticcontent:function"]
|
|
544
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds the semantic text content for an item embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
545
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
546
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
547
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
548
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
549
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
346
550
|
|
|
551
|
+
/**
|
|
552
|
+
* Builds a structured JSON representation of an item for vector indexing. It serializes item fields, metadata, and configured embedding fields into JSON.
|
|
553
|
+
*
|
|
554
|
+
* @inputSpec
|
|
555
|
+
* - item: any (required) — the item to be serialized.
|
|
556
|
+
* - embeddingFields: string[] (optional) — an array of field names to include in the serialization.
|
|
557
|
+
* @outputSpec string — a JSON string representation of the structured item.
|
|
558
|
+
* @sideEffects none
|
|
559
|
+
* @stability stable
|
|
560
|
+
* @cil-generated
|
|
561
|
+
*/
|
|
562
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:buildstructurecontent:function" type="function" identity="buildStructureContent" parent="~/.framework/functions/embeddings.ts"]
|
|
563
|
+
// CIL[DOC-MACRO purpose="Builds a structured JSON representation of an item for vector indexing."]
|
|
564
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Serializes item fields, metadata, and configured embedding fields into JSON."]
|
|
565
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
566
|
+
// CIL[DOC-CONTRACT inputs="item: any, embeddingFields?: string[]" outputs="JSON string" errors="none" side_effects="none"]
|
|
567
|
+
// CIL[DOC-MICRO logic_summary="Collects title, status, kb fields, and any configured embedding fields into an object and serializes it to JSON." notable_decisions="none"]
|
|
568
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
569
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
570
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
347
571
|
function buildStructureContent(item: any, embeddingFields: string[] = []): string {
|
|
348
572
|
const base: Record<string, any> = {
|
|
349
573
|
title: item.title || '',
|
|
@@ -360,7 +584,34 @@ function buildStructureContent(item: any, embeddingFields: string[] = []): strin
|
|
|
360
584
|
}
|
|
361
585
|
return JSON.stringify(base)
|
|
362
586
|
}
|
|
587
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:buildstructurecontent:function"]
|
|
588
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds a structured JSON representation of an item for vector indexing.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
589
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
590
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
591
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
592
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
593
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
363
594
|
|
|
595
|
+
/**
|
|
596
|
+
* Extracts the intent text for an item embedding by selecting the first available intent field from the provided item data. This function is essential for retrieving meaningful intent information from various potential sources within the item structure.
|
|
597
|
+
*
|
|
598
|
+
* @inputSpec
|
|
599
|
+
* item: any (required) — the item object containing data fields for intent extraction.
|
|
600
|
+
* @outputSpec string — the extracted intent text or an empty string if none are found.
|
|
601
|
+
* @sideEffects none
|
|
602
|
+
* @stability internal
|
|
603
|
+
* @calls firstNonEmpty
|
|
604
|
+
* @cil-generated
|
|
605
|
+
*/
|
|
606
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:buildintentcontent:function" type="function" identity="buildIntentContent" parent="~/.framework/functions/embeddings.ts"]
|
|
607
|
+
// CIL[DOC-MACRO purpose="Extracts the intent text for an item embedding."]
|
|
608
|
+
// CIL[DOC-STABILITY stability="internal"]
|
|
609
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
610
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
611
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Picks the first available intent field from item data."]
|
|
612
|
+
// CIL[DOC-CONTRACT inputs="item: any" outputs="string" errors="none" side_effects="none"]
|
|
613
|
+
// CIL[DOC-MICRO logic_summary="Returns the first non-empty value among intent, learning_objectives, ca_reported_issue, use_case." notable_decisions="none"]
|
|
614
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
364
615
|
function buildIntentContent(item: any): string {
|
|
365
616
|
return firstNonEmpty(
|
|
366
617
|
item.data?.intent,
|
|
@@ -369,7 +620,34 @@ function buildIntentContent(item: any): string {
|
|
|
369
620
|
item.data?.use_case,
|
|
370
621
|
)
|
|
371
622
|
}
|
|
372
|
-
|
|
623
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:buildintentcontent:function"]
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Extracts the intent text for an item embedding by retrieving the first non-empty cause-related field from the item data. This function is designed to facilitate the processing of item embeddings in the context of the application.
|
|
627
|
+
*
|
|
628
|
+
* @inputSpec
|
|
629
|
+
* - item: any (required) — the item data containing potential cause-related fields.
|
|
630
|
+
* @outputSpec string — the first non-empty cause-related field value.
|
|
631
|
+
* @sideEffects none
|
|
632
|
+
* @stability stable
|
|
633
|
+
* @calls firstNonEmpty
|
|
634
|
+
* @cil-generated
|
|
635
|
+
*/
|
|
636
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:buildcausecontent:function" type="function" identity="buildCauseContent" parent="~/.framework/functions/embeddings.ts"]
|
|
637
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Extracts the intent text for an item embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
638
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
639
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
640
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
641
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
642
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
643
|
+
// CIL[DOC-MACRO purpose="Extracts the cause text for an item embedding."]
|
|
644
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Picks the first available cause or root-cause field from item data."]
|
|
645
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
646
|
+
// CIL[DOC-CONTRACT inputs="item: any" outputs="string" errors="none" side_effects="none"]
|
|
647
|
+
// CIL[DOC-MICRO logic_summary="Returns the first non-empty value among cause, ca_true_problem, concept, root_cause." notable_decisions="none"]
|
|
648
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
649
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
650
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
373
651
|
function buildCauseContent(item: any): string {
|
|
374
652
|
return firstNonEmpty(
|
|
375
653
|
item.data?.cause,
|
|
@@ -378,7 +656,34 @@ function buildCauseContent(item: any): string {
|
|
|
378
656
|
item.data?.root_cause,
|
|
379
657
|
)
|
|
380
658
|
}
|
|
659
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:buildcausecontent:function"]
|
|
660
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Extracts the cause text for an item embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
661
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
662
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
663
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
664
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
665
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
381
666
|
|
|
667
|
+
/**
|
|
668
|
+
* Extracts the procedure text for an item embedding by selecting the first available procedure or resolution text from item data. This function is designed to format the procedure steps into a numbered list if available.
|
|
669
|
+
*
|
|
670
|
+
* @inputSpec
|
|
671
|
+
* item: any — the item containing procedure or resolution data.
|
|
672
|
+
* @outputSpec string — a formatted string of procedure steps or resolution text.
|
|
673
|
+
* @sideEffects none
|
|
674
|
+
* @stability stable
|
|
675
|
+
* @calls firstNonEmpty
|
|
676
|
+
* @cil-generated
|
|
677
|
+
*/
|
|
678
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:buildprocedurecontent:function" type="function" identity="buildProcedureContent" parent="~/.framework/functions/embeddings.ts"]
|
|
679
|
+
// CIL[DOC-MACRO purpose="Extracts the procedure text for an item embedding."]
|
|
680
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Picks the first available procedure or resolution text from item data."]
|
|
681
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
682
|
+
// CIL[DOC-CONTRACT inputs="item: any" outputs="string" errors="none" side_effects="none"]
|
|
683
|
+
// CIL[DOC-MICRO logic_summary="Joins arrays of steps into numbered text, or falls back to the procedure/resolution field." notable_decisions="none"]
|
|
684
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
685
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
686
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
382
687
|
function buildProcedureContent(item: any): string {
|
|
383
688
|
const steps = item.data?.procedure || item.data?.ca_solution_steps || item.data?.steps
|
|
384
689
|
if (Array.isArray(steps) && steps.length) {
|
|
@@ -386,7 +691,34 @@ function buildProcedureContent(item: any): string {
|
|
|
386
691
|
}
|
|
387
692
|
return firstNonEmpty(item.data?.procedure, item.data?.resolution)
|
|
388
693
|
}
|
|
694
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:buildprocedurecontent:function"]
|
|
695
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Extracts the procedure text for an item embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
696
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
697
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
698
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
699
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
700
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
389
701
|
|
|
702
|
+
/**
|
|
703
|
+
* Extracts the outcome text for an item embedding by selecting the first available outcome or result field from the item data. This function is designed to streamline the retrieval of relevant outcome information.
|
|
704
|
+
*
|
|
705
|
+
* @inputSpec
|
|
706
|
+
* item: any — the item data containing potential outcome fields.
|
|
707
|
+
* @outputSpec string — the first non-empty outcome text.
|
|
708
|
+
* @sideEffects none
|
|
709
|
+
* @stability internal
|
|
710
|
+
* @calls firstNonEmpty
|
|
711
|
+
* @cil-generated
|
|
712
|
+
*/
|
|
713
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:buildoutcomecontent:function" type="function" identity="buildOutcomeContent" parent="~/.framework/functions/embeddings.ts"]
|
|
714
|
+
// CIL[DOC-MACRO purpose="Extracts the outcome text for an item embedding."]
|
|
715
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Picks the first available outcome or result field from item data."]
|
|
716
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
717
|
+
// CIL[DOC-CONTRACT inputs="item: any" outputs="string" errors="none" side_effects="none"]
|
|
718
|
+
// CIL[DOC-MICRO logic_summary="Returns the first non-empty value among outcome, ca_final_solution, outcomes, result." notable_decisions="none"]
|
|
719
|
+
// CIL[DOC-STABILITY stability="internal"]
|
|
720
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
721
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
390
722
|
function buildOutcomeContent(item: any): string {
|
|
391
723
|
return firstNonEmpty(
|
|
392
724
|
item.data?.outcome,
|
|
@@ -395,7 +727,34 @@ function buildOutcomeContent(item: any): string {
|
|
|
395
727
|
item.data?.result,
|
|
396
728
|
)
|
|
397
729
|
}
|
|
730
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:buildoutcomecontent:function"]
|
|
731
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Extracts the outcome text for an item embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
732
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
733
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
734
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
735
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
736
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
398
737
|
|
|
738
|
+
/**
|
|
739
|
+
* Extracts the context text for an item embedding by prioritizing diagnostic steps or fallback context fields. This function is essential for providing relevant information associated with an item.
|
|
740
|
+
*
|
|
741
|
+
* @inputSpec
|
|
742
|
+
* item: any (required) — the item containing data for context extraction.
|
|
743
|
+
* @outputSpec string — the formatted context text or fallback information.
|
|
744
|
+
* @sideEffects none
|
|
745
|
+
* @stability stable
|
|
746
|
+
* @calls firstNonEmpty
|
|
747
|
+
* @cil-generated
|
|
748
|
+
*/
|
|
749
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:buildcontextcontent:function" type="function" identity="buildContextContent" parent="~/.framework/functions/embeddings.ts"]
|
|
750
|
+
// CIL[DOC-MACRO purpose="Extracts the context text for an item embedding."]
|
|
751
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Picks the first available context or prerequisite field from item data."]
|
|
752
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
753
|
+
// CIL[DOC-CONTRACT inputs="item: any" outputs="string" errors="none" side_effects="none"]
|
|
754
|
+
// CIL[DOC-MICRO logic_summary="Joins diagnostic steps into numbered text, or falls back to context, prerequisites, when_to_use, product_area." notable_decisions="none"]
|
|
755
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
756
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
757
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
399
758
|
function buildContextContent(item: any): string {
|
|
400
759
|
const steps = item.data?.ca_diagnostic_steps
|
|
401
760
|
if (Array.isArray(steps) && steps.length) {
|
|
@@ -408,7 +767,36 @@ function buildContextContent(item: any): string {
|
|
|
408
767
|
item.data?.product_area,
|
|
409
768
|
)
|
|
410
769
|
}
|
|
770
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:buildcontextcontent:function"]
|
|
771
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Extracts the context text for an item embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
772
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
773
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
774
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
775
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
776
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
411
777
|
|
|
778
|
+
// CIL[DOC-STABILITY stability="internal"]
|
|
779
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
780
|
+
// CIL[DOC-CONTEXT module="unknown" layer="unknown" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
781
|
+
/**
|
|
782
|
+
* Extracts error signals or code blocks for an item embedding. This function is designed to retrieve relevant error information from the provided item data.
|
|
783
|
+
*
|
|
784
|
+
* @inputSpec
|
|
785
|
+
* item: any (required) — the item containing data to extract error signals from.
|
|
786
|
+
* @outputSpec string — a concatenated string of error signatures, analysis tags, or code blocks.
|
|
787
|
+
* @sideEffects none
|
|
788
|
+
* @stability stable
|
|
789
|
+
* @cil-generated
|
|
790
|
+
*/
|
|
791
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:builderrorsignalcontent:function" type="function" identity="buildErrorSignalContent" parent="~/.framework/functions/embeddings.ts"]
|
|
792
|
+
// CIL[DOC-MACRO purpose="Extracts error signals or code blocks for an item embedding."]
|
|
793
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Picks the first available error signature or code block from item data."]
|
|
794
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
795
|
+
// CIL[DOC-CONTRACT inputs="item: any" outputs="string" errors="none" side_effects="none"]
|
|
796
|
+
// CIL[DOC-MICRO logic_summary="Joins error_signatures or ca_analysis_tags arrays, or extracts code blocks from the description." notable_decisions="none"]
|
|
797
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
798
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
799
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
412
800
|
function buildErrorSignalContent(item: any): string {
|
|
413
801
|
const sigs = item.data?.error_signatures
|
|
414
802
|
if (Array.isArray(sigs) && sigs.length) return sigs.join('\n')
|
|
@@ -419,13 +807,68 @@ function buildErrorSignalContent(item: any): string {
|
|
|
419
807
|
const codeBlocks = desc.match(/```[\s\S]*?```/g) || []
|
|
420
808
|
return codeBlocks.map((b: string) => b.replace(/```\w*\n?/g, '')).join('\n').trim()
|
|
421
809
|
}
|
|
422
|
-
|
|
810
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:builderrorsignalcontent:function"]
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Builds a synchronous summary string for an item by extracting and formatting its title and description. This function is designed to provide a concise overview of an item embedding.
|
|
814
|
+
*
|
|
815
|
+
* @inputSpec
|
|
816
|
+
* item: any (required) — the item object containing title and description.
|
|
817
|
+
* @outputSpec string — a formatted summary string combining the item title and a snippet of its description.
|
|
818
|
+
* @sideEffects none
|
|
819
|
+
* @stability stable
|
|
820
|
+
* @calls stripHtml
|
|
821
|
+
* @cil-generated
|
|
822
|
+
*/
|
|
823
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:buildsummarycontentsync:function" type="function" identity="buildSummaryContentSync" parent="~/.framework/functions/embeddings.ts"]
|
|
824
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Extracts error signals or code blocks for an item embedding.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
825
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
826
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
827
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
828
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
829
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
830
|
+
// CIL[DOC-MACRO purpose="Builds a synchronous summary string for an item."]
|
|
831
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Produces a short title-plus-description summary."]
|
|
832
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
833
|
+
// CIL[DOC-CONTRACT inputs="item: any" outputs="string" errors="none" side_effects="none"]
|
|
834
|
+
// CIL[DOC-MICRO logic_summary="Strips HTML from the description and combines the item title with a 300-character snippet." notable_decisions="none"]
|
|
835
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
836
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
837
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
423
838
|
function buildSummaryContentSync(item: any): string {
|
|
424
839
|
|
|
425
840
|
const desc = stripHtml(item.description || '')
|
|
426
841
|
return `${item.title || ''}: ${desc.slice(0, 300)}`
|
|
427
842
|
}
|
|
843
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:buildsummarycontentsync:function"]
|
|
844
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Builds a synchronous summary string for an item.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
845
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
846
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
847
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
848
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
849
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
428
850
|
|
|
851
|
+
/**
|
|
852
|
+
* Generates an AI-written summary for an item, with a synchronous fallback. It calls OpenAI chat to summarize an article, falling back to a synchronous summary on failure.
|
|
853
|
+
*
|
|
854
|
+
* @inputSpec
|
|
855
|
+
* item: any (required) — the item to summarize.
|
|
856
|
+
* ctx: any (optional) — the context for the OpenAI call.
|
|
857
|
+
* @outputSpec Promise<string> — a summary of the item.
|
|
858
|
+
* @sideEffects calls external OpenAI chat API
|
|
859
|
+
* @stability internal
|
|
860
|
+
* @calls callOpenAIChat, buildSummaryContentSync
|
|
861
|
+
* @cil-generated
|
|
862
|
+
*/
|
|
863
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:generateaisummary:function" type="function" identity="generateAiSummary" parent="~/.framework/functions/embeddings.ts"]
|
|
864
|
+
// CIL[DOC-MACRO purpose="Generates an AI-written summary for an item, with a sync fallback."]
|
|
865
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Calls OpenAI chat to summarize an article, falling back to a synchronous summary on failure."]
|
|
866
|
+
// CIL[DOC-STABILITY stability="internal"]
|
|
867
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
868
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
869
|
+
// CIL[DOC-CONTRACT inputs="item: any, ctx?: any" outputs="string summary" errors="none; failures are handled and fallback is returned" side_effects="calls external OpenAI chat API"]
|
|
870
|
+
// CIL[DOC-MICRO logic_summary="Strips HTML and truncates the description, calls the LLM with a concise system prompt, and falls back to buildSummaryContentSync if the call fails." notable_decisions="none"]
|
|
871
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
429
872
|
async function generateAiSummary(item: any, ctx?: any): Promise<string> {
|
|
430
873
|
const plain = stripHtml(item.description || '').slice(0, 3000)
|
|
431
874
|
try {
|
|
@@ -443,47 +886,186 @@ async function generateAiSummary(item: any, ctx?: any): Promise<string> {
|
|
|
443
886
|
return buildSummaryContentSync(item)
|
|
444
887
|
}
|
|
445
888
|
}
|
|
889
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:generateaisummary:function"]
|
|
446
890
|
|
|
891
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Generates an AI-written summary for an item, with a sync fallback.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
892
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
893
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
894
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
895
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
896
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
897
|
+
/**
|
|
898
|
+
* Calls the OpenAI embedding API to convert text inputs into vector arrays. It formats the results for further use in the application.
|
|
899
|
+
*
|
|
900
|
+
* @inputSpec
|
|
901
|
+
* inputs: string[] (required) — array of text inputs to be converted into embeddings.
|
|
902
|
+
* ctx: any (optional) — context object for the API call.
|
|
903
|
+
* @outputSpec Promise<string[]> — an array of formatted embedding vectors as bracketed comma-delimited strings.
|
|
904
|
+
* @sideEffects calls external OpenAI embedding API
|
|
905
|
+
* @stability stable
|
|
906
|
+
* @calls callOpenAIEmbeddings
|
|
907
|
+
* @cil-generated
|
|
908
|
+
*/
|
|
909
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:callembeddingapi:function" type="function" identity="callEmbeddingApi" parent="~/.framework/functions/embeddings.ts"]
|
|
910
|
+
// CIL[DOC-MACRO purpose="Calls the OpenAI embedding API and formats the result."]
|
|
911
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Converts text inputs into vector arrays from the embedding model."]
|
|
912
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
913
|
+
// CIL[DOC-CONTRACT inputs="inputs: string[], ctx?: any" outputs="string[] of formatted embedding vectors" errors="throws if the embedding API call fails" side_effects="calls external OpenAI embedding API"]
|
|
914
|
+
// CIL[DOC-MICRO logic_summary="If inputs are empty returns empty strings, otherwise calls callOpenAIEmbeddings, sorts by index, and formats each embedding as a bracketed comma-delimited string." notable_decisions="none"]
|
|
915
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
916
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
917
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
447
918
|
async function callEmbeddingApi(inputs: string[], ctx?: any): Promise<string[]> {
|
|
448
919
|
if (!inputs.length) return inputs.map(() => '')
|
|
449
920
|
const j = await callOpenAIEmbeddings(ctx, inputs, 'text-embedding-3-small')
|
|
450
921
|
const sorted = (j.data || []).sort((a: any, b: any) => a.index - b.index)
|
|
451
922
|
return sorted.map((d: any) => `[${d.embedding.join(',')}]`)
|
|
452
923
|
}
|
|
924
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:callembeddingapi:function"]
|
|
925
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Calls the OpenAI embedding API and formats the result.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
926
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
927
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
928
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
929
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
930
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
453
931
|
|
|
932
|
+
/**
|
|
933
|
+
* Computes a short SHA-256 hash of the provided text to generate a unique content identifier. This function is essential for creating consistent embeddings based on textual input.
|
|
934
|
+
*
|
|
935
|
+
* @inputSpec
|
|
936
|
+
* - text: string (required) — the input text to hash.
|
|
937
|
+
* @outputSpec string — a 16-character hex hash string.
|
|
938
|
+
* @sideEffects none
|
|
939
|
+
* @stability stable
|
|
940
|
+
* @calls createHash
|
|
941
|
+
* @cil-generated
|
|
942
|
+
*/
|
|
943
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:contenthash:function" type="function" identity="contentHash" parent="~/.framework/functions/embeddings.ts"]
|
|
944
|
+
// CIL[DOC-MACRO purpose="Computes a short SHA-256 hash of text."]
|
|
945
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Generates a 16-hex-character content hash for embeddings."]
|
|
946
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
947
|
+
// CIL[DOC-CONTRACT inputs="text: string" outputs="16-character hex hash string" errors="none" side_effects="none"]
|
|
948
|
+
// CIL[DOC-MICRO logic_summary="Creates a SHA-256 digest of the text and slices the first 16 hex characters." notable_decisions="none"]
|
|
949
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
950
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
951
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
454
952
|
function contentHash(text: string): string {
|
|
455
953
|
return createHash('sha256').update(text).digest('hex').slice(0, 16)
|
|
456
954
|
}
|
|
955
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:contenthash:function"]
|
|
956
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Computes a short SHA-256 hash of text.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
957
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
958
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
959
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
960
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
961
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
962
|
+
|
|
457
963
|
|
|
458
964
|
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* The _platformAccountId constant holds a cached identifier for the spine-system account to optimize performance by avoiding repeated lookups. It is initialized as null and is intended for use within the embeddings module.
|
|
968
|
+
*
|
|
969
|
+
* @sideEffects none
|
|
970
|
+
* @stability stable
|
|
971
|
+
* @cil-generated
|
|
972
|
+
*/
|
|
973
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:_platformaccountid:constant" type="constant" identity="_platformAccountId" parent="~/.framework/functions/embeddings.ts"]
|
|
974
|
+
// CIL[DOC-MACRO purpose="Cached platform account identifier for spine-system."]
|
|
975
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Holds the cached spine-system account id to avoid repeated lookups."]
|
|
976
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
977
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
978
|
+
// CIL[DOC-MICRO logic_summary="Module-level variable that caches the resolved platform account id." notable_decisions="none"]
|
|
979
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
980
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
981
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
459
982
|
let _platformAccountId: string | null = null
|
|
983
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:_platformaccountid:constant"]
|
|
984
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Cached platform account identifier for spine-system.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
985
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
986
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
987
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
988
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
989
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* Resolves and caches the spine-system platform account id. It fetches the platform account from the accounts table and caches it for future use.
|
|
993
|
+
*
|
|
994
|
+
* @outputSpec Promise<string | null> — resolves to the platform account id or null if not found.
|
|
995
|
+
* @sideEffects queries the accounts table and caches the id in _platformAccountId
|
|
996
|
+
* @stability stable
|
|
997
|
+
* @calls adminDb.from('accounts')
|
|
998
|
+
* @cil-generated
|
|
999
|
+
*/
|
|
1000
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:getplatformaccountid:function" type="function" identity="getPlatformAccountId" parent="~/.framework/functions/embeddings.ts"]
|
|
1001
|
+
// CIL[DOC-MACRO purpose="Resolves and caches the spine-system platform account id."]
|
|
1002
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Fetches the platform account from the accounts table and caches it."]
|
|
1003
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1004
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="string | null" errors="none" side_effects="queries the accounts table and caches the id in _platformAccountId"]
|
|
1005
|
+
// CIL[DOC-MICRO logic_summary="Returns the cached id if present, otherwise queries the accounts table for slug spine-system and stores the result." notable_decisions="none"]
|
|
1006
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1007
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1008
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
460
1009
|
async function getPlatformAccountId(): Promise<string | null> {
|
|
461
1010
|
if (_platformAccountId) return _platformAccountId
|
|
462
1011
|
const { data } = await adminDb.from('accounts').select('id').eq('slug', 'spine-system').maybeSingle()
|
|
463
1012
|
_platformAccountId = data?.id ?? null
|
|
464
1013
|
return _platformAccountId
|
|
465
1014
|
}
|
|
1015
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:getplatformaccountid:function"]
|
|
1016
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Resolves and caches the spine-system platform account id.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1017
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1018
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1019
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
1020
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
1021
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1022
|
+
|
|
466
1023
|
|
|
467
1024
|
|
|
468
1025
|
|
|
469
1026
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
// CIL[
|
|
1027
|
+
/**
|
|
1028
|
+
* ContentBuilder is a type alias for functions that create embedding content. It defines the function signature used by CONTENT_BUILDERS.
|
|
1029
|
+
*
|
|
1030
|
+
* @sideEffects none
|
|
1031
|
+
* @stability stable
|
|
1032
|
+
* @cil-generated
|
|
1033
|
+
*/
|
|
1034
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:contentbuilder:type" type="type" identity="ContentBuilder" parent="~/.framework/functions/embeddings.ts"]
|
|
1035
|
+
// CIL[DOC-MACRO purpose="Type alias for embedding content builder functions."]
|
|
1036
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Defines the function signature used by CONTENT_BUILDERS."]
|
|
1037
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1038
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="none" errors="none" side_effects="none"]
|
|
1039
|
+
// CIL[DOC-MICRO logic_summary="Declares a function type that accepts an item and optional meta and returns a string." notable_decisions="none"]
|
|
1040
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
478
1041
|
// CIL[DOC-STABILITY stability="stable"]
|
|
479
|
-
// CIL[DOC-
|
|
480
|
-
|
|
481
|
-
// CIL[
|
|
482
|
-
// CIL[DOC-VECTOR type="
|
|
1042
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
1043
|
+
type ContentBuilder = (item: any, meta?: any) => string
|
|
1044
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:contentbuilder:type"]
|
|
1045
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Type alias for embedding content builder functions.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1046
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1047
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1048
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
483
1049
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
484
1050
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
485
|
-
type ContentBuilder = (item: any, meta?: any) => string
|
|
486
1051
|
|
|
1052
|
+
/**
|
|
1053
|
+
* CONTENT_BUILDERS is a mapping of vector type names to their corresponding content builder functions, facilitating the creation of various content types. It registers builders for semantic, structure, intent, cause, procedure, outcome, context, and error_signal vectors.
|
|
1054
|
+
*
|
|
1055
|
+
* @sideEffects none
|
|
1056
|
+
* @stability stable
|
|
1057
|
+
* @calls buildSemanticContent, buildStructureContent, buildIntentContent, buildCauseContent, buildProcedureContent, buildOutcomeContent, buildContextContent, buildErrorSignalContent
|
|
1058
|
+
* @cil-generated
|
|
1059
|
+
*/
|
|
1060
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:content_builders:constant" type="constant" identity="CONTENT_BUILDERS" parent="~/.framework/functions/embeddings.ts"]
|
|
1061
|
+
// CIL[DOC-MACRO purpose="Mapping of vector type names to content builder functions."]
|
|
1062
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Registers content builders for semantic, structure, intent, cause, procedure, outcome, context, and error_signal vectors."]
|
|
1063
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1064
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="Record<string, ContentBuilder>" errors="none" side_effects="none"]
|
|
1065
|
+
// CIL[DOC-MICRO logic_summary="Defines a record that maps each vector type to a builder function, embedding fields for the structure builder." notable_decisions="none"]
|
|
1066
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1067
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1068
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
487
1069
|
const CONTENT_BUILDERS: Record<string, ContentBuilder> = {
|
|
488
1070
|
semantic: buildSemanticContent,
|
|
489
1071
|
structure: (item, meta) => buildStructureContent(item, meta?.embedding_fields ?? []),
|
|
@@ -495,21 +1077,31 @@ const CONTENT_BUILDERS: Record<string, ContentBuilder> = {
|
|
|
495
1077
|
error_signal: buildErrorSignalContent,
|
|
496
1078
|
|
|
497
1079
|
}
|
|
498
|
-
// CIL[END
|
|
499
|
-
// CIL[
|
|
500
|
-
// CIL[DOC-
|
|
501
|
-
// CIL[DOC-
|
|
502
|
-
// CIL[DOC-
|
|
503
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="sanitized_embeddings" errors="auth_errors,db_errors" side_effects="none"]
|
|
504
|
-
// CIL[DOC-MICRO logic_summary="Query embeddings with filters, sanitize data, return paginated results" notable_decisions="[]"]
|
|
505
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
506
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
507
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 3. Direct calls: 0. Related files: custom/apps/cortex/functions/custom_cil-embeddings.ts, .framework/functions/_shared/schema-utils.ts, .framework/src/components/ui/dialog.tsx, .framework/functions/_shared/principal.ts, .framework/functions/_shared/db.ts, \."]
|
|
508
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 3. Total affected: 3."]
|
|
509
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
510
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1080
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:content_builders:constant"]
|
|
1081
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Mapping of vector type names to content builder functions.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1082
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1083
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1084
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
511
1085
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
512
1086
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1087
|
+
/**
|
|
1088
|
+
* Lists embedding records with optional filters for the current account. It returns a paginated, sanitized list of embeddings.
|
|
1089
|
+
*
|
|
1090
|
+
* @throws Error — if account context is missing
|
|
1091
|
+
* @sideEffects queries the embeddings table
|
|
1092
|
+
* @stability stable
|
|
1093
|
+
* @calls sanitizeRecordData, adminDb.from, ctx.db.from
|
|
1094
|
+
* @cil-generated
|
|
1095
|
+
*/
|
|
1096
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:list:constant" type="constant" identity="list" parent="~/.framework/functions/embeddings.ts"]
|
|
1097
|
+
// CIL[DOC-MACRO purpose="Lists embedding records with optional filters."]
|
|
1098
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Returns a paginated, sanitized list of embeddings for the current account."]
|
|
1099
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1100
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, _body: any" outputs="sanitized embedding record array" errors="throws if account context is missing or the query fails" side_effects="queries the embeddings table"]
|
|
1101
|
+
// CIL[DOC-MICRO logic_summary="Parses query parameters, builds a database query filtered by model_id and document_id, fetches a range, sanitizes each row, and returns the results." notable_decisions="none"]
|
|
1102
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1103
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1104
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
513
1105
|
export const list = createHandler(async (ctx, _body) => {
|
|
514
1106
|
const { model_id, document_id, limit = 100, offset = 0 } = ctx.query || {}
|
|
515
1107
|
|
|
@@ -548,21 +1140,31 @@ export const list = createHandler(async (ctx, _body) => {
|
|
|
548
1140
|
|
|
549
1141
|
return sanitized
|
|
550
1142
|
})
|
|
551
|
-
// CIL[END
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
// CIL[
|
|
562
|
-
// CIL[DOC-
|
|
563
|
-
// CIL[DOC-VECTOR type="
|
|
1143
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:list:constant"]
|
|
1144
|
+
/**
|
|
1145
|
+
* Retrieves a single embedding record by its ID from the database. This function ensures that the embedding data is fetched and sanitized before being returned.
|
|
1146
|
+
*
|
|
1147
|
+
* @throws Error — if id missing or query fails
|
|
1148
|
+
* @sideEffects queries the embeddings table
|
|
1149
|
+
* @stability stable
|
|
1150
|
+
* @calls adminDb.from('embeddings'), ctx.db.from('embeddings'), sanitizeRecordData
|
|
1151
|
+
* @cil-generated
|
|
1152
|
+
*/
|
|
1153
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:get:constant" type="constant" identity="get" parent="~/.framework/functions/embeddings.ts"]
|
|
1154
|
+
// CIL[DOC-MACRO purpose="Retrieves a single embedding by id."]
|
|
1155
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Lists embedding records with optional filters.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1156
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1157
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1158
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
564
1159
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
565
1160
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1161
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Fetches and sanitizes one embedding record."]
|
|
1162
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1163
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, _body: any" outputs="sanitized embedding record" errors="throws if id missing or query fails" side_effects="queries the embeddings table"]
|
|
1164
|
+
// CIL[DOC-MICRO logic_summary="Reads the id from query, selects the matching embedding from the database, and sanitizes the result." notable_decisions="none"]
|
|
1165
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1166
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1167
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
566
1168
|
export const get = createHandler(async (ctx, _body) => {
|
|
567
1169
|
const { id } = ctx.query || {}
|
|
568
1170
|
|
|
@@ -582,21 +1184,31 @@ export const get = createHandler(async (ctx, _body) => {
|
|
|
582
1184
|
|
|
583
1185
|
return await sanitizeRecordData(ctx, data, 'embedding')
|
|
584
1186
|
})
|
|
585
|
-
// CIL[END
|
|
586
|
-
// CIL[
|
|
587
|
-
// CIL[DOC-
|
|
588
|
-
// CIL[DOC-
|
|
589
|
-
// CIL[DOC-
|
|
590
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="embedding_stats" errors="auth_errors,db_errors" side_effects="none"]
|
|
591
|
-
// CIL[DOC-MICRO logic_summary="Count total embeddings in database for account" notable_decisions="[]"]
|
|
592
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
593
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
594
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
595
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
596
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
597
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1187
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:get:constant"]
|
|
1188
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Retrieves a single embedding by id.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1189
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1190
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1191
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
598
1192
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
599
1193
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1194
|
+
/**
|
|
1195
|
+
* Returns the total count of embeddings for the current account. This function counts the number of embeddings owned by the account.
|
|
1196
|
+
*
|
|
1197
|
+
* @throws Error — if account context missing or query fails
|
|
1198
|
+
* @sideEffects queries the embeddings table
|
|
1199
|
+
* @stability stable
|
|
1200
|
+
* @calls ctx.db.from('embeddings')
|
|
1201
|
+
* @cil-generated
|
|
1202
|
+
*/
|
|
1203
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:getstats:constant" type="constant" identity="getStats" parent="~/.framework/functions/embeddings.ts"]
|
|
1204
|
+
// CIL[DOC-MACRO purpose="Returns the total count of embeddings for the current account."]
|
|
1205
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Counts the number of embeddings owned by the account."]
|
|
1206
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1207
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, _body: any" outputs="{ total_embeddings: number }" errors="throws if account context missing or query fails" side_effects="queries the embeddings table"]
|
|
1208
|
+
// CIL[DOC-MICRO logic_summary="Verifies account context, queries the embeddings table with an exact count, and returns the total." notable_decisions="none"]
|
|
1209
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1210
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1211
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
600
1212
|
export const getStats = createHandler(async (ctx, _body) => {
|
|
601
1213
|
if (!ctx.accountId) {
|
|
602
1214
|
throw new Error('Account context required')
|
|
@@ -610,21 +1222,31 @@ export const getStats = createHandler(async (ctx, _body) => {
|
|
|
610
1222
|
|
|
611
1223
|
return { total_embeddings: count || 0 }
|
|
612
1224
|
})
|
|
613
|
-
// CIL[END
|
|
614
|
-
// CIL[
|
|
615
|
-
// CIL[DOC-
|
|
616
|
-
// CIL[DOC-
|
|
617
|
-
// CIL[DOC-
|
|
618
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="created_embeddings" errors="validation_errors,db_errors" side_effects="db_write,audit_log"]
|
|
619
|
-
// CIL[DOC-MICRO logic_summary="Bulk insert embeddings with account context, log batch creation" notable_decisions="[]"]
|
|
620
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
621
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
622
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
623
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
624
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
625
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1225
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:getstats:constant"]
|
|
1226
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Returns the total count of embeddings for the current account.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1227
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1228
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1229
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
626
1230
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
627
1231
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1232
|
+
/**
|
|
1233
|
+
* Bulk inserts multiple embedding records into the database and logs the batch operation. It ensures that the provided data is valid and associates each embedding with the account context.
|
|
1234
|
+
*
|
|
1235
|
+
* @throws Error — if embeddings_data is missing/invalid, account context is missing, or insert fails.
|
|
1236
|
+
* @sideEffects Inserts multiple embeddings rows and emits an audit log.
|
|
1237
|
+
* @stability stable
|
|
1238
|
+
* @calls ctx.db.from('embeddings'), emitLog
|
|
1239
|
+
* @cil-generated
|
|
1240
|
+
*/
|
|
1241
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:batchcreate:constant" type="constant" identity="batchCreate" parent="~/.framework/functions/embeddings.ts"]
|
|
1242
|
+
// CIL[DOC-MACRO purpose="Bulk inserts multiple embedding records."]
|
|
1243
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Creates many embeddings in one transaction and logs the batch."]
|
|
1244
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1245
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { embeddings_data: any[] }" outputs="inserted embedding records" errors="throws if embeddings_data is missing/invalid, account context is missing, or insert fails" side_effects="inserts multiple embeddings rows and emits an audit log"]
|
|
1246
|
+
// CIL[DOC-MICRO logic_summary="Validates the embeddings_data array and account context, appends the account id to each row, inserts the batch, and emits an audit log." notable_decisions="none"]
|
|
1247
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1248
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1249
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
628
1250
|
export const batchCreate = createHandler(async (ctx, body) => {
|
|
629
1251
|
const { embeddings_data } = body
|
|
630
1252
|
|
|
@@ -655,21 +1277,31 @@ export const batchCreate = createHandler(async (ctx, body) => {
|
|
|
655
1277
|
|
|
656
1278
|
return data
|
|
657
1279
|
})
|
|
658
|
-
// CIL[END
|
|
659
|
-
// CIL[
|
|
660
|
-
// CIL[DOC-
|
|
661
|
-
// CIL[DOC-
|
|
662
|
-
// CIL[DOC-
|
|
663
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="deletion_count" errors="validation_errors,db_errors" side_effects="db_write,audit_log"]
|
|
664
|
-
// CIL[DOC-MICRO logic_summary="Delete embeddings by document ID, log deletion event" notable_decisions="[]"]
|
|
665
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
666
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
667
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
668
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
669
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
670
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1280
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:batchcreate:constant"]
|
|
1281
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Bulk inserts multiple embedding records.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1282
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1283
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1284
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
671
1285
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
672
1286
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1287
|
+
/**
|
|
1288
|
+
* Deletes all embeddings associated with a given document. This function ensures that the specified document's embeddings are removed from the database and logs the deletion event.
|
|
1289
|
+
*
|
|
1290
|
+
* @throws Error — if document_id is missing or deletion fails
|
|
1291
|
+
* @sideEffects deletes embeddings rows and emits an audit log
|
|
1292
|
+
* @stability stable
|
|
1293
|
+
* @calls ctx.db.from('embeddings'), emitLog
|
|
1294
|
+
* @cil-generated
|
|
1295
|
+
*/
|
|
1296
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:deletebydocument:constant" type="constant" identity="deleteByDocument" parent="~/.framework/functions/embeddings.ts"]
|
|
1297
|
+
// CIL[DOC-MACRO purpose="Deletes all embeddings for a given document."]
|
|
1298
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Removes embeddings associated with a document and logs the deletion."]
|
|
1299
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1300
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { document_id }" outputs="{ deleted_count: number }" errors="throws if document_id missing or delete fails" side_effects="deletes embeddings rows and emits an audit log"]
|
|
1301
|
+
// CIL[DOC-MICRO logic_summary="Validates document_id, deletes matching rows from the embeddings table, and emits an embeddings.document_deleted log." notable_decisions="none"]
|
|
1302
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1303
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1304
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
673
1305
|
export const deleteByDocument = createHandler(async (ctx, body) => {
|
|
674
1306
|
const { document_id } = body
|
|
675
1307
|
|
|
@@ -692,21 +1324,31 @@ export const deleteByDocument = createHandler(async (ctx, body) => {
|
|
|
692
1324
|
|
|
693
1325
|
return { deleted_count: data?.length || 0 }
|
|
694
1326
|
})
|
|
695
|
-
// CIL[END
|
|
696
|
-
// CIL[
|
|
697
|
-
// CIL[DOC-
|
|
698
|
-
// CIL[DOC-
|
|
699
|
-
// CIL[DOC-
|
|
700
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="deletion_count" errors="db_errors" side_effects="db_write,audit_log"]
|
|
701
|
-
// CIL[DOC-MICRO logic_summary="Delete embeddings older than cutoff date, log cleanup" notable_decisions="[]"]
|
|
702
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
703
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
704
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
705
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
706
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
707
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1327
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:deletebydocument:constant"]
|
|
1328
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Deletes all embeddings for a given document.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1329
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1330
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1331
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
708
1332
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
709
1333
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1334
|
+
/**
|
|
1335
|
+
* Deletes embedding records that are older than a specified threshold to manage data retention. This function ensures that the database remains efficient by purging outdated records.
|
|
1336
|
+
*
|
|
1337
|
+
* @throws Error — if account context is missing or delete operation fails.
|
|
1338
|
+
* @sideEffects Deletes embedding rows from the database and emits an audit log.
|
|
1339
|
+
* @stability stable
|
|
1340
|
+
* @calls ctx.db.from('embeddings'), emitLog
|
|
1341
|
+
* @cil-generated
|
|
1342
|
+
*/
|
|
1343
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:cleanup:constant" type="constant" identity="cleanup" parent="~/.framework/functions/embeddings.ts"]
|
|
1344
|
+
// CIL[DOC-MACRO purpose="Deletes embedding records older than a threshold."]
|
|
1345
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Purges old embeddings based on a retention policy."]
|
|
1346
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1347
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { days_to_keep? }" outputs="{ deleted_count: number }" errors="throws if account context missing or delete fails" side_effects="deletes embeddings rows and emits an audit log"]
|
|
1348
|
+
// CIL[DOC-MICRO logic_summary="Computes a cutoff date from days_to_keep, deletes embeddings with created_at before that date, and emits an embeddings.cleaned log." notable_decisions="none"]
|
|
1349
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1350
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1351
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
710
1352
|
export const cleanup = createHandler(async (ctx, body) => {
|
|
711
1353
|
const { days_to_keep } = body
|
|
712
1354
|
const daysToKeep = days_to_keep || 365
|
|
@@ -729,39 +1371,57 @@ export const cleanup = createHandler(async (ctx, body) => {
|
|
|
729
1371
|
|
|
730
1372
|
return { deleted_count: data?.length || 0 }
|
|
731
1373
|
})
|
|
732
|
-
// CIL[END
|
|
733
|
-
// CIL[
|
|
734
|
-
// CIL[DOC-
|
|
735
|
-
// CIL[DOC-
|
|
736
|
-
// CIL[DOC-
|
|
737
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="similar_results" errors="validation_errors,db_errors" side_effects="none"]
|
|
738
|
-
// CIL[DOC-MICRO logic_summary="Call stored procedure for vector similarity search with threshold" notable_decisions="[]"]
|
|
739
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="external_symbols_unknown"]
|
|
740
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
741
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
742
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
743
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
744
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1374
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:cleanup:constant"]
|
|
1375
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Deletes embedding records older than a threshold.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1376
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1377
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1378
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
745
1379
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
746
1380
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1381
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1382
|
+
// CIL[DOC-CONTEXT module="unknown" layer="unknown" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1383
|
+
/**
|
|
1384
|
+
* Performs vector similarity search over embeddings to find relevant results based on a query embedding. It returns embeddings whose vectors are within a specified threshold of the query embedding.
|
|
1385
|
+
*
|
|
1386
|
+
* @throws Error — if account or query_embedding is missing, or if RPC fails.
|
|
1387
|
+
* @sideEffects executes a database RPC
|
|
1388
|
+
* @stability stable
|
|
1389
|
+
* @calls ctx.db.rpc
|
|
1390
|
+
* @cil-generated
|
|
1391
|
+
*/
|
|
1392
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:searchsimilar:constant" type="constant" identity="searchSimilar" parent="~/.framework/functions/embeddings.ts"]
|
|
1393
|
+
// CIL[DOC-MACRO purpose="Performs vector similarity search over embeddings."]
|
|
1394
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Returns embeddings whose vectors are within a threshold of a query embedding."]
|
|
1395
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1396
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { query_embedding, model_id?, limit?, threshold? }" outputs="{ results, count, model_id, threshold }" errors="throws if account or query_embedding missing, or RPC fails" side_effects="executes a database RPC"]
|
|
1397
|
+
// CIL[DOC-MICRO logic_summary="Validates account and query_embedding, calls the search_similar_embeddings RPC, and returns the results, count, model, and threshold." notable_decisions="none"]
|
|
1398
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1399
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1400
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
747
1401
|
export const searchSimilar = createHandler(async (ctx, body) => {
|
|
748
|
-
const {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
1402
|
+
const {
|
|
1403
|
+
query_embedding,
|
|
1404
|
+
model_id,
|
|
1405
|
+
limit = 10,
|
|
1406
|
+
threshold = 0.7,
|
|
1407
|
+
filter_account_ids,
|
|
1408
|
+
filter_vector_type,
|
|
1409
|
+
filter_item_types,
|
|
1410
|
+
filter_document_ids,
|
|
1411
|
+
} = body || {}
|
|
753
1412
|
|
|
754
1413
|
if (!query_embedding) {
|
|
755
1414
|
throw new Error('query_embedding is required for similarity search')
|
|
756
1415
|
}
|
|
757
1416
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
1417
|
+
const { data, error: err } = await ctx.db.rpc('match_embeddings', {
|
|
1418
|
+
query_embedding,
|
|
1419
|
+
match_count: parseInt(limit.toString()),
|
|
1420
|
+
filter_account_ids: filter_account_ids ?? null,
|
|
1421
|
+
filter_vector_type: filter_vector_type ?? null,
|
|
1422
|
+
similarity_threshold: parseFloat(threshold.toString()),
|
|
1423
|
+
filter_item_types: filter_item_types ?? null,
|
|
1424
|
+
filter_document_ids: filter_document_ids ?? null,
|
|
765
1425
|
})
|
|
766
1426
|
|
|
767
1427
|
if (err) throw err
|
|
@@ -769,25 +1429,35 @@ export const searchSimilar = createHandler(async (ctx, body) => {
|
|
|
769
1429
|
return {
|
|
770
1430
|
results: data || [],
|
|
771
1431
|
count: data?.length || 0,
|
|
772
|
-
model_id: model_id || 'text-embedding-
|
|
1432
|
+
model_id: model_id || 'text-embedding-3-small',
|
|
773
1433
|
threshold: parseFloat(threshold.toString())
|
|
774
1434
|
}
|
|
775
1435
|
})
|
|
776
|
-
// CIL[END
|
|
777
|
-
// CIL[
|
|
778
|
-
// CIL[DOC-
|
|
779
|
-
// CIL[DOC-
|
|
780
|
-
// CIL[DOC-
|
|
781
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="search_results" errors="validation_errors,db_errors" side_effects="none"]
|
|
782
|
-
// CIL[DOC-MICRO logic_summary="Use database full-text search on embedding content" notable_decisions="[]"]
|
|
783
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
784
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
785
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
786
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
787
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
788
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1436
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:searchsimilar:constant"]
|
|
1437
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Performs vector similarity search over embeddings.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1438
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1439
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1440
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
789
1441
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
790
1442
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1443
|
+
/**
|
|
1444
|
+
* Performs text search against embedding content to retrieve relevant results based on a query. It validates the account and query before executing a full-text search on the embeddings database.
|
|
1445
|
+
*
|
|
1446
|
+
* @throws Error — if account or query is missing, or if the query fails.
|
|
1447
|
+
* @sideEffects queries the embeddings table using full-text search
|
|
1448
|
+
* @stability stable
|
|
1449
|
+
* @calls ctx.db.from('embeddings'), ctx.db.select, ctx.db.eq, ctx.db.textSearch, ctx.db.limit, ctx.db.in
|
|
1450
|
+
* @cil-generated
|
|
1451
|
+
*/
|
|
1452
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:searchsemantic:constant" type="constant" identity="searchSemantic" parent="~/.framework/functions/embeddings.ts"]
|
|
1453
|
+
// CIL[DOC-MACRO purpose="Performs text search against embedding content."]
|
|
1454
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Returns embeddings matching a text query using full-text search."]
|
|
1455
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1456
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { query, model_id?, document_ids?, limit? }" outputs="{ results, count, method, query }" errors="throws if account or query missing, or query fails" side_effects="queries the embeddings table using full-text search"]
|
|
1457
|
+
// CIL[DOC-MICRO logic_summary="Validates account and query, builds a textSearch query with optional model_id and document_ids filters, and returns the results and count." notable_decisions="none"]
|
|
1458
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1459
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1460
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
791
1461
|
export const searchSemantic = createHandler(async (ctx, body) => {
|
|
792
1462
|
const { query, model_id, document_ids, limit = 10 } = body || {}
|
|
793
1463
|
|
|
@@ -828,21 +1498,31 @@ export const searchSemantic = createHandler(async (ctx, body) => {
|
|
|
828
1498
|
query
|
|
829
1499
|
}
|
|
830
1500
|
})
|
|
831
|
-
// CIL[END
|
|
832
|
-
// CIL[
|
|
833
|
-
// CIL[DOC-
|
|
834
|
-
// CIL[DOC-
|
|
835
|
-
// CIL[DOC-
|
|
836
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="revocation_count" errors="validation_errors,db_errors" side_effects="db_write,audit_log"]
|
|
837
|
-
// CIL[DOC-MICRO logic_summary="Set revoked_at timestamp for document embeddings" notable_decisions="[]"]
|
|
838
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
839
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
840
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
841
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
842
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
843
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1501
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:searchsemantic:constant"]
|
|
1502
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Performs text search against embedding content.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1503
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1504
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1505
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
844
1506
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
845
1507
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1508
|
+
/**
|
|
1509
|
+
* Revokes all active embeddings for a document by marking them as revoked. This is achieved by updating the revoked_at timestamp for the specified document's embeddings.
|
|
1510
|
+
*
|
|
1511
|
+
* @throws Error — if document_id is missing or update fails
|
|
1512
|
+
* @sideEffects updates embeddings rows and emits an audit log
|
|
1513
|
+
* @stability stable
|
|
1514
|
+
* @calls adminDb.from('embeddings'), emitLog
|
|
1515
|
+
* @cil-generated
|
|
1516
|
+
*/
|
|
1517
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:revoke:constant" type="constant" identity="revoke" parent="~/.framework/functions/embeddings.ts"]
|
|
1518
|
+
// CIL[DOC-MACRO purpose="Revokes all active embeddings for a document."]
|
|
1519
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Marks embeddings for a document as revoked by setting revoked_at."]
|
|
1520
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1521
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { document_id }" outputs="{ document_id, revoked_count }" errors="throws if document_id missing or update fails" side_effects="updates embeddings rows and emits an audit log"]
|
|
1522
|
+
// CIL[DOC-MICRO logic_summary="Updates all non-revoked embeddings for the document with the current timestamp and emits an embeddings.revoked log." notable_decisions="none"]
|
|
1523
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1524
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1525
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
846
1526
|
export const revoke = createHandler(async (ctx, body) => {
|
|
847
1527
|
const { document_id } = body || {}
|
|
848
1528
|
if (!document_id) throw new Error('document_id is required')
|
|
@@ -863,21 +1543,31 @@ export const revoke = createHandler(async (ctx, body) => {
|
|
|
863
1543
|
|
|
864
1544
|
return { document_id, revoked_count: data?.length || 0 }
|
|
865
1545
|
})
|
|
866
|
-
// CIL[END
|
|
867
|
-
// CIL[
|
|
868
|
-
// CIL[DOC-
|
|
869
|
-
// CIL[DOC-
|
|
870
|
-
// CIL[DOC-
|
|
871
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="approval_count" errors="validation_errors,db_errors" side_effects="db_write,audit_log"]
|
|
872
|
-
// CIL[DOC-MICRO logic_summary="Set approved_at timestamp and clear revoked_at" notable_decisions="[]"]
|
|
873
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
874
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
875
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
876
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
877
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
878
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1546
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:revoke:constant"]
|
|
1547
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Revokes all active embeddings for a document.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1548
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1549
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1550
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
879
1551
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
880
1552
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1553
|
+
/**
|
|
1554
|
+
* Approves all embeddings for a document by updating their approval timestamps. This function ensures that embeddings are marked as approved and any revoked timestamps are cleared.
|
|
1555
|
+
*
|
|
1556
|
+
* @throws Error — if document_id is missing or update fails
|
|
1557
|
+
* @sideEffects updates embeddings rows and emits an audit log
|
|
1558
|
+
* @stability stable
|
|
1559
|
+
* @calls adminDb.from('embeddings'), emitLog
|
|
1560
|
+
* @cil-generated
|
|
1561
|
+
*/
|
|
1562
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:approve:constant" type="constant" identity="approve" parent="~/.framework/functions/embeddings.ts"]
|
|
1563
|
+
// CIL[DOC-MACRO purpose="Approves all embeddings for a document."]
|
|
1564
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Marks embeddings for a document as approved by setting approved_at and clearing revoked_at."]
|
|
1565
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1566
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: { document_id }" outputs="{ document_id, approved_count }" errors="throws if document_id missing or update fails" side_effects="updates embeddings rows and emits an audit log"]
|
|
1567
|
+
// CIL[DOC-MICRO logic_summary="Updates all embeddings for the document with the current approved timestamp, clears any revoked timestamp, and emits an embeddings.approved log." notable_decisions="none"]
|
|
1568
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1569
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1570
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
881
1571
|
export const approve = createHandler(async (ctx, body) => {
|
|
882
1572
|
const { document_id } = body || {}
|
|
883
1573
|
if (!document_id) throw new Error('document_id is required')
|
|
@@ -898,23 +1588,32 @@ export const approve = createHandler(async (ctx, body) => {
|
|
|
898
1588
|
|
|
899
1589
|
return { document_id, approved_count: data?.length || 0 }
|
|
900
1590
|
})
|
|
901
|
-
// CIL[END
|
|
902
|
-
// CIL[
|
|
903
|
-
// CIL[DOC-
|
|
904
|
-
// CIL[DOC-
|
|
905
|
-
// CIL[DOC-
|
|
906
|
-
// CIL[DOC-RESPONSIBILITY responsibility="Dispatch requests to embedding operations"]
|
|
907
|
-
// CIL[DOC-CONTEXT module="embeddings" layer="backend_functions" related_files="[]"]
|
|
908
|
-
// CIL[DOC-CONTRACT inputs="none" outputs="function_responses" errors="method_errors" side_effects="none"]
|
|
909
|
-
// CIL[DOC-MICRO logic_summary="Route based on action and method to specific embedding functions" notable_decisions="[]"]
|
|
910
|
-
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
911
|
-
// CIL[DOC-STABILITY stability="stable"]
|
|
912
|
-
// CIL[DOC-VECTOR type="context" content="Layer: backend_functions. Direct callers: 0. Direct calls: 0. Related files: none."]
|
|
913
|
-
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
914
|
-
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
915
|
-
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
1591
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:approve:constant"]
|
|
1592
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Approves all embeddings for a document.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1593
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1594
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1595
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
916
1596
|
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
917
1597
|
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
1598
|
+
/**
|
|
1599
|
+
* The handler is a Netlify function that routes HTTP requests to the appropriate embedding operation based on the specified action and method. It facilitates various embedding-related actions such as create, update, and search operations.
|
|
1600
|
+
*
|
|
1601
|
+
* @throws Error — throws if action and method do not match any valid route.
|
|
1602
|
+
* @sideEffects dispatches to create, update, generate, revoke, approve, stats, batch-create, delete-document, cleanup, search-similar, search-semantic, list, or get
|
|
1603
|
+
* @stability stable
|
|
1604
|
+
* @calls generate, revoke, approve, getStats, batchCreate, deleteByDocument, cleanup, searchSimilar, searchSemantic, get, list, create, update
|
|
1605
|
+
* @errorHandling none
|
|
1606
|
+
* @cil-generated
|
|
1607
|
+
*/
|
|
1608
|
+
// CIL[BEGIN stable_id="~/.framework/functions/embeddings.ts:handler:constant" type="constant" identity="handler" parent="~/.framework/functions/embeddings.ts"]
|
|
1609
|
+
// CIL[DOC-MACRO purpose="Netlify function router that dispatches embedding actions."]
|
|
1610
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Routes HTTP requests to the correct embedding operation based on action and method."]
|
|
1611
|
+
// CIL[DOC-CONTEXT module="embeddings" layer="functions" related_files=".framework/functions/_shared/audit.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/permissions.ts,.framework/functions/_shared/principal.ts,.framework/functions/embeddings.ts"]
|
|
1612
|
+
// CIL[DOC-CONTRACT inputs="ctx: RequestContext, body: any" outputs="handler result" errors="throws if action and method do not match any valid route" side_effects="dispatches to create, update, generate, revoke, approve, stats, batch-create, delete-document, cleanup, search-similar, search-semantic, list, or get"]
|
|
1613
|
+
// CIL[DOC-MICRO logic_summary="Reads action and method from the request, switches to the matching handler, and falls back to GET/POST/PATCH default CRUD actions." notable_decisions="Uses action/method routing; supports both action-specific POST routes and default GET/POST/PATCH CRUD paths."]
|
|
1614
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
|
|
1615
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
1616
|
+
// CIL[DOC-AUDIENCE audience="developers"]
|
|
918
1617
|
export const handler = createHandler(async (ctx, body) => {
|
|
919
1618
|
const { action } = ctx.query || {}
|
|
920
1619
|
const method = ctx.query?.method || 'GET'
|
|
@@ -981,4 +1680,10 @@ export const handler = createHandler(async (ctx, body) => {
|
|
|
981
1680
|
|
|
982
1681
|
throw new Error('Invalid action or method')
|
|
983
1682
|
})
|
|
984
|
-
// CIL[END
|
|
1683
|
+
// CIL[END stable_id="~/.framework/functions/embeddings.ts:handler:constant"]
|
|
1684
|
+
// CIL[DOC-VECTOR type="context" content="purpose='Netlify function router that dispatches embedding actions.'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts"]
|
|
1685
|
+
// CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
|
|
1686
|
+
// CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
|
|
1687
|
+
// CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
|
|
1688
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
1689
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|