spine-framework 0.3.124 → 0.3.126
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/.framework/cli/commands/agents.ts +35 -37
- package/.framework/cli/commands/auth.ts +35 -34
- package/.framework/cli/commands/create-app.ts +104 -40
- package/.framework/cli/commands/dev.ts +104 -69
- package/.framework/cli/commands/doctor.ts +179 -69
- package/.framework/cli/commands/generate.ts +83 -143
- package/.framework/cli/commands/init.ts +72 -34
- package/.framework/cli/commands/install-app.ts +260 -125
- package/.framework/cli/commands/items.ts +33 -44
- package/.framework/cli/commands/migrate.ts +122 -40
- package/.framework/cli/commands/migrations.ts +33 -40
- package/.framework/cli/commands/pipelines.ts +31 -39
- package/.framework/cli/commands/status.ts +47 -23
- package/.framework/cli/commands/system.ts +47 -37
- package/.framework/cli/commands/test.ts +112 -68
- package/.framework/cli/commands/validate-app.ts +215 -121
- package/.framework/cli/context.ts +112 -130
- package/.framework/cli/env-loader.ts +47 -18
- package/.framework/cli/index.ts +81 -42
- package/.framework/docs/runtime-types.md +1024 -0
- package/.framework/functions/_shared/agent-runner.ts +1296 -961
- package/.framework/functions/_shared/app-manifest.ts +82 -68
- package/.framework/functions/_shared/audit.ts +135 -83
- package/.framework/functions/_shared/{cil-state.ts → cil.ts} +158 -56
- package/.framework/functions/_shared/db.ts +80 -126
- package/.framework/functions/_shared/hash-api-key.ts +63 -0
- package/.framework/functions/_shared/index.ts +224 -335
- package/.framework/functions/_shared/kb.ts +319 -0
- package/.framework/functions/_shared/llm.ts +92 -0
- package/.framework/functions/_shared/logging.ts +288 -0
- package/.framework/functions/_shared/middleware.ts +329 -365
- package/.framework/functions/_shared/outcomes.ts +36 -0
- package/.framework/functions/_shared/permissions.ts +359 -643
- package/.framework/functions/_shared/pipeline-runner.ts +243 -316
- package/.framework/functions/_shared/principal.ts +376 -468
- package/.framework/functions/_shared/resolve-credentials.ts +102 -0
- package/.framework/functions/_shared/resolve-ids.ts +188 -16
- package/.framework/functions/_shared/retry-deliveries.ts +104 -0
- package/.framework/functions/_shared/schema-utils.ts +611 -373
- package/.framework/functions/_shared/testing.ts +207 -137
- package/.framework/functions/_shared/tracing.ts +276 -0
- package/.framework/functions/_shared/trigger-engine.ts +159 -211
- package/.framework/functions/_shared/webhook-registration.ts +95 -81
- package/.framework/functions/_shared/webhook-registry.ts +153 -75
- package/.framework/functions/account-nodes.ts +31 -53
- package/.framework/functions/adapters/generic-webhook-inbound.ts +56 -0
- package/.framework/functions/adapters/generic-webhook-outbound.ts +43 -0
- package/.framework/functions/adapters/openai-outbound.ts +40 -0
- package/.framework/functions/admin-data.ts +685 -537
- package/.framework/functions/admin-funnel.ts +31 -20
- package/.framework/functions/admin-install-funnel.ts +47 -28
- package/.framework/functions/admin-signals.ts +47 -29
- package/.framework/functions/ai-agents.ts +122 -147
- package/.framework/functions/ai-interactions.ts +180 -90
- package/.framework/functions/api-keys.ts +250 -192
- package/.framework/functions/apps.ts +203 -197
- package/.framework/functions/auth.ts +98 -91
- package/.framework/functions/cil-agent-ingest.ts +773 -0
- package/.framework/functions/cil-agent.ts +592 -0
- package/.framework/functions/cil-callmap.ts +1227 -0
- package/.framework/functions/cil-config.ts +583 -0
- package/.framework/functions/cil-context.ts +445 -0
- package/.framework/functions/cil-doc.ts +1752 -0
- package/.framework/functions/cil-embeddings.ts +1202 -0
- package/.framework/functions/cil-graph.ts +585 -0
- package/.framework/functions/cil-ingest.ts +2416 -0
- package/.framework/functions/cil-pipeline.ts +318 -0
- package/.framework/functions/cil-project.ts +499 -0
- package/.framework/functions/cil-validate.ts +469 -0
- package/.framework/functions/debug-auth.ts +73 -53
- package/.framework/functions/deliveries.ts +117 -0
- package/.framework/functions/embeddings.ts +528 -516
- package/.framework/functions/eval-harness.ts +158 -106
- package/.framework/functions/integration-outbound.ts +311 -0
- package/.framework/functions/integration-routes.ts +240 -466
- package/.framework/functions/integrations.ts +132 -140
- package/.framework/functions/invites.ts +401 -201
- package/.framework/functions/item-progress.ts +113 -53
- package/.framework/functions/kb.ts +28 -0
- package/.framework/functions/logs.ts +239 -222
- package/.framework/functions/observability.ts +308 -259
- package/.framework/functions/pipeline-executions.ts +179 -235
- package/.framework/functions/pipelines.ts +163 -205
- package/.framework/functions/prompt-configs.ts +109 -156
- package/.framework/functions/roles.ts +97 -147
- package/.framework/functions/system-cron.ts +132 -218
- package/.framework/functions/system.ts +112 -52
- package/.framework/functions/tests.ts +32 -28
- package/.framework/functions/timers.ts +162 -210
- package/.framework/functions/triggers.ts +282 -346
- package/.framework/functions/types.ts +283 -400
- package/.framework/migrations/001_core_schema.sql +630 -0
- package/.framework/migrations/002_core_rls_and_functions.sql +532 -0
- package/.framework/migrations/{003_system_data.sql → 003_core_system_data.sql} +26 -153
- package/.framework/migrations/004_core_rpc_and_broker.sql +421 -0
- package/.framework/migrations/005_core_observability.sql +598 -0
- package/.framework/migrations/006_security_hardening_rls.sql +97 -0
- package/.framework/migrations/007_kb_article_list.sql +237 -0
- package/.framework/migrations/008_items_target.sql +8 -0
- package/.framework/migrations/009_roles_slug_unique.sql +11 -0
- package/.framework/public/spine.config.json +91 -0
- package/.framework/scripts/app-install-cli.ts +112 -98
- package/.framework/src/App.tsx +67 -20
- package/.framework/src/apps/admin/index.tsx +97 -27
- package/.framework/src/components/AppWrapper.tsx +50 -11
- package/.framework/src/components/CustomAppLoader.tsx +131 -22
- package/.framework/src/components/admin/AdminListPage.tsx +75 -8
- package/.framework/src/components/admin/AdminSidebar.tsx +148 -36
- package/.framework/src/components/admin/AdminStatsCard.tsx +48 -29
- package/.framework/src/components/admin/PageInstructions.tsx +49 -0
- package/.framework/src/components/admin/SortableTableHeader.tsx +49 -2
- package/.framework/src/components/app-shell/GenericAppShell.tsx +69 -11
- package/.framework/src/components/app-shell/GenericDetailPage.tsx +55 -10
- package/.framework/src/components/app-shell/GenericListPage.tsx +76 -9
- package/.framework/src/components/app-sidebar.tsx +50 -3
- package/.framework/src/components/auth/ProtectedRoute.tsx +53 -45
- package/.framework/src/components/kb/KBArticleEditor.tsx +409 -0
- package/.framework/src/components/kb/KBArticleList.tsx +557 -0
- package/.framework/src/components/layout/AppShell.tsx +54 -16
- package/.framework/src/components/layout/Header.tsx +50 -38
- package/.framework/src/components/layout/Layout.tsx +48 -32
- package/.framework/src/components/layout/Sidebar.tsx +167 -16
- package/.framework/src/components/runtime/DataDetailHeader.tsx +33 -1
- package/.framework/src/components/runtime/DataDetailPage.tsx +289 -4
- package/.framework/src/components/runtime/DataFilters.tsx +78 -1
- package/.framework/src/components/runtime/DataHeader.tsx +32 -29
- package/.framework/src/components/runtime/DataListPage.tsx +161 -2
- package/.framework/src/components/runtime/DataStats.tsx +48 -1
- package/.framework/src/components/runtime/DataTable.tsx +153 -1
- package/.framework/src/components/runtime/SchemaDetailForm.tsx +77 -46
- package/.framework/src/components/runtime/index.ts +16 -9
- package/.framework/src/components/search-form.tsx +33 -1
- package/.framework/src/components/shared/AgentView.tsx +48 -51
- package/.framework/src/components/shared/FieldRenderer.tsx +84 -67
- package/.framework/src/components/shared/InviteManager.tsx +113 -52
- package/.framework/src/components/shared/MemberList.tsx +182 -0
- package/.framework/src/components/shared/SchemaFields.tsx +96 -78
- package/.framework/src/components/ui/DataTable.tsx +86 -56
- package/.framework/src/components/ui/Form.tsx +188 -109
- package/.framework/src/components/ui/ItemCard.tsx +86 -58
- package/.framework/src/components/ui/ItemListView.tsx +88 -61
- package/.framework/src/components/ui/LoadingSpinner.tsx +52 -27
- package/.framework/src/components/ui/Modal.tsx +81 -4
- package/.framework/src/components/ui/RichTextEditor.tsx +101 -9
- package/.framework/src/components/ui/accordion.tsx +97 -5
- package/.framework/src/components/ui/alert-dialog.tsx +225 -13
- package/.framework/src/components/ui/alert.tsx +113 -6
- package/.framework/src/components/ui/aspect-ratio.tsx +49 -2
- package/.framework/src/components/ui/avatar.tsx +129 -7
- package/.framework/src/components/ui/badge.tsx +65 -3
- package/.framework/src/components/ui/breadcrumb.tsx +145 -8
- package/.framework/src/components/ui/button-group.tsx +81 -4
- package/.framework/src/components/ui/button.tsx +49 -2
- package/.framework/src/components/ui/calendar.tsx +65 -3
- package/.framework/src/components/ui/card.tsx +145 -8
- package/.framework/src/components/ui/carousel.tsx +129 -7
- package/.framework/src/components/ui/chart.tsx +161 -10
- package/.framework/src/components/ui/checkbox.tsx +49 -2
- package/.framework/src/components/ui/collapsible.tsx +81 -5
- package/.framework/src/components/ui/combobox.tsx +305 -20
- package/.framework/src/components/ui/command.tsx +177 -11
- package/.framework/src/components/ui/context-menu.tsx +273 -17
- package/.framework/src/components/ui/dialog.tsx +209 -27
- package/.framework/src/components/ui/direction.tsx +64 -4
- package/.framework/src/components/ui/drawer.tsx +193 -12
- package/.framework/src/components/ui/dropdown-menu.tsx +273 -18
- package/.framework/src/components/ui/empty.tsx +145 -9
- package/.framework/src/components/ui/field.tsx +209 -14
- package/.framework/src/components/ui/hover-card.tsx +81 -4
- package/.framework/src/components/ui/input-group.tsx +162 -10
- package/.framework/src/components/ui/input-otp.tsx +98 -5
- package/.framework/src/components/ui/input.tsx +49 -2
- package/.framework/src/components/ui/item.tsx +225 -13
- package/.framework/src/components/ui/kbd.tsx +65 -3
- package/.framework/src/components/ui/label.tsx +49 -2
- package/.framework/src/components/ui/menubar.tsx +289 -17
- package/.framework/src/components/ui/native-select.tsx +97 -5
- package/.framework/src/components/ui/navigation-menu.tsx +177 -10
- package/.framework/src/components/ui/pagination.tsx +161 -9
- package/.framework/src/components/ui/popover.tsx +145 -8
- package/.framework/src/components/ui/progress.tsx +49 -2
- package/.framework/src/components/ui/radio-group.tsx +65 -3
- package/.framework/src/components/ui/resizable.tsx +82 -4
- package/.framework/src/components/ui/scroll-area.tsx +65 -3
- package/.framework/src/components/ui/select.tsx +193 -11
- package/.framework/src/components/ui/separator.tsx +49 -2
- package/.framework/src/components/ui/sheet.tsx +193 -11
- package/.framework/src/components/ui/sidebar.tsx +481 -38
- package/.framework/src/components/ui/skeleton.tsx +49 -2
- package/.framework/src/components/ui/slider.tsx +49 -2
- package/.framework/src/components/ui/sonner.tsx +49 -2
- package/.framework/src/components/ui/spinner.tsx +49 -2
- package/.framework/src/components/ui/switch.tsx +49 -2
- package/.framework/src/components/ui/table-primitives.tsx +160 -33
- package/.framework/src/components/ui/table.tsx +161 -9
- package/.framework/src/components/ui/tabs.tsx +113 -6
- package/.framework/src/components/ui/textarea.tsx +49 -2
- package/.framework/src/components/ui/toggle-group.tsx +81 -4
- package/.framework/src/components/ui/toggle.tsx +65 -3
- package/.framework/src/components/ui/tooltip.tsx +97 -5
- package/.framework/src/contexts/AppContext.tsx +129 -45
- package/.framework/src/contexts/AuthContext.tsx +187 -144
- package/.framework/src/hooks/use-mobile.ts +48 -2
- package/.framework/src/hooks/useApi.ts +208 -159
- package/.framework/src/hooks/useAppPath.ts +32 -23
- package/.framework/src/hooks/useApps.ts +51 -20
- package/.framework/src/hooks/useEntityList.ts +32 -78
- package/.framework/src/hooks/useEntityRecord.ts +35 -96
- package/.framework/src/hooks/useForm.ts +32 -92
- package/.framework/src/hooks/useListSchema.ts +49 -78
- package/.framework/src/hooks/useSchemaRecord.ts +114 -105
- package/.framework/src/lib/api.ts +195 -116
- package/.framework/src/lib/supabase.ts +98 -64
- package/.framework/src/lib/utils.ts +287 -151
- package/.framework/src/main.tsx +49 -3
- package/.framework/src/pages/DashboardPage.tsx +52 -29
- package/.framework/src/pages/NotFoundPage.tsx +32 -10
- package/.framework/src/pages/SetupPage.tsx +32 -12
- package/.framework/src/pages/admin/AIAgentDetailPage.tsx +119 -10
- package/.framework/src/pages/admin/AIAgentsPage.tsx +48 -19
- package/.framework/src/pages/admin/APIKeyDetailPage.tsx +187 -17
- package/.framework/src/pages/admin/APIKeysPage.tsx +98 -22
- package/.framework/src/pages/admin/AlertsConfigPage.tsx +113 -26
- package/.framework/src/pages/admin/AppDetailPage.tsx +125 -8
- package/.framework/src/pages/admin/AppsPage.tsx +49 -2
- package/.framework/src/pages/admin/DeliveriesPage.tsx +196 -0
- package/.framework/src/pages/admin/DesignedPage.tsx +32 -18
- package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +215 -484
- package/.framework/src/pages/admin/EmbeddingsPage.tsx +116 -319
- package/.framework/src/pages/admin/ExtendedShadcnTestPage.tsx +34 -9
- package/.framework/src/pages/admin/IncrementalShadcnTestPage.tsx +34 -9
- package/.framework/src/pages/admin/IntegratedDashboard.tsx +32 -16
- package/.framework/src/pages/admin/IntegrationDetailPage.tsx +183 -26
- package/.framework/src/pages/admin/IntegrationsPage.tsx +48 -19
- package/.framework/src/pages/admin/InvitesPage.tsx +48 -14
- package/.framework/src/pages/admin/LogsPage.tsx +422 -75
- package/.framework/src/pages/admin/MinimalShadcnTestPage.tsx +34 -9
- package/.framework/src/pages/admin/ObservabilityDashboard.tsx +113 -24
- package/.framework/src/pages/admin/PipelineDetailPage.tsx +206 -34
- package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +50 -17
- package/.framework/src/pages/admin/PipelinesPage.tsx +160 -21
- package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +378 -88
- package/.framework/src/pages/admin/PromptConfigsPage.tsx +125 -16
- package/.framework/src/pages/admin/ProperlyDesignedPage.tsx +49 -10
- package/.framework/src/pages/admin/RoleDetailPage.tsx +130 -10
- package/.framework/src/pages/admin/RolesPage.tsx +171 -18
- package/.framework/src/pages/admin/SelectTestPage.tsx +34 -9
- package/.framework/src/pages/admin/ShadcnTestPage.tsx +49 -11
- package/.framework/src/pages/admin/SimpleDashboard.tsx +49 -10
- package/.framework/src/pages/admin/TestRunDetailPage.tsx +49 -4
- package/.framework/src/pages/admin/TestingDashboard.tsx +98 -28
- package/.framework/src/pages/admin/TimerDetailPage.tsx +143 -33
- package/.framework/src/pages/admin/TimersPage.tsx +48 -20
- package/.framework/src/pages/admin/TriggerDetailPage.tsx +118 -30
- package/.framework/src/pages/admin/TriggersPage.tsx +64 -19
- package/.framework/src/pages/admin/TypeDetailPage.tsx +138 -15
- package/.framework/src/pages/admin/TypesPage.tsx +48 -20
- package/.framework/src/pages/admin/cil/CILAgentPage.tsx +465 -0
- package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +787 -0
- package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +699 -0
- package/.framework/src/pages/admin/cil/CILFileListPage.tsx +647 -0
- package/.framework/src/pages/admin/cil/CILGraphPage.tsx +616 -0
- package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +1402 -0
- package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +614 -0
- package/.framework/src/pages/admin/cil/CILSearchPage.tsx +571 -0
- package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +731 -0
- package/.framework/src/pages/admin/kb/KBAdminPage.tsx +64 -0
- package/.framework/src/pages/auth/AuthConfirmPage.tsx +52 -51
- package/.framework/src/pages/auth/ForgotPasswordPage.tsx +31 -22
- package/.framework/src/pages/auth/LoginPage.tsx +50 -23
- package/.framework/src/pages/auth/PendingApprovalPage.tsx +31 -15
- package/.framework/src/pages/auth/RegisterPage.tsx +281 -317
- package/.framework/src/pages/spine-framework/APIPage.tsx +33 -0
- package/.framework/src/pages/spine-framework/CLIPage.tsx +33 -0
- package/.framework/src/types/auth.ts +128 -71
- package/.framework/src/types/types.ts +373 -157
- package/custom/.devin/skills/spine-workbench-discovery/SKILL.md +39 -0
- package/custom/.devin/skills/spine-workbench-idea/SKILL.md +36 -0
- package/custom/.devin/skills/spine-workbench-implement/SKILL.md +46 -0
- package/custom/.devin/skills/spine-workbench-initiative/SKILL.md +28 -0
- package/custom/.devin/skills/spine-workbench-plan/SKILL.md +38 -0
- package/docs/README.md +9 -130
- package/netlify.toml +5 -2
- package/package.json +13 -25
- package/scripts/kb-ingest-docs.ts +203 -0
- package/spine.config.json +65 -4
- package/.framework/migrations/001_schema.sql +0 -425
- package/.framework/migrations/002_rls_and_functions.sql +0 -763
- package/.framework/migrations/004_enhancements.sql +0 -43
- package/.framework/migrations/005_auth_user_trigger.sql +0 -105
- package/.framework/migrations/006_fix_current_actor_id.sql +0 -21
- package/.framework/migrations/016_invites.sql +0 -27
- package/.framework/migrations/017_fix_get_account_apps.sql +0 -78
- package/.framework/migrations/018_apps_required_roles.sql +0 -17
- package/.framework/migrations/019_triggers_unique_constraint.sql +0 -13
- package/.framework/migrations/020_get_account_apps_role_filter.sql +0 -117
- package/.framework/migrations/021_app_domains.sql +0 -112
- package/.framework/migrations/022_route_prefix_domain_unique.sql +0 -21
- package/.framework/migrations/023_match_embeddings_rpc.sql +0 -78
- package/.framework/migrations/024_messages_account_id.sql +0 -9
- package/.framework/migrations/025_retype_threads_messages.sql +0 -240
- package/.framework/migrations/026_fix_rls_policies.sql +0 -47
- package/.framework/migrations/027_embedding_lifecycle.sql +0 -176
- package/.framework/migrations/028_fix_message_data_permissions.sql +0 -49
- package/.framework/migrations/029_tighten_support_triage_prompt.sql +0 -41
- package/.framework/migrations/030_messages_updated_by.sql +0 -6
- package/.framework/migrations/031_seed_upsert_constraints.sql +0 -35
- package/docs/APPS.md +0 -232
- package/docs/ARCHITECTURE.md +0 -246
- package/docs/INSTALL.md +0 -155
- package/docs/design-schema-spec.md +0 -1837
- package/docs/dev-guides/01-create-an-app.md +0 -183
- package/docs/dev-guides/02-create-a-function.md +0 -178
- package/docs/dev-guides/03-create-a-component.md +0 -178
- package/docs/dev-guides/04-webhook-handlers.md +0 -129
- package/docs/dev-guides/05-testing.md +0 -168
- package/docs/dev-guides/README.md +0 -40
- package/docs/npm-packages-plan.md +0 -288
- package/docs/spine-core--api-reference.md +0 -822
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
// CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_graph_module_header_1784235266" type="module_header" identity="module_header" parent="none"]
|
|
2
|
+
// CIL[DOC-MACRO purpose="Module header and top-level exports for cortex.functions.custom_cil-graph"]
|
|
3
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Own module-level imports, exports, and configuration for cortex.functions.custom_cil-graph"]
|
|
4
|
+
// CIL[DOC-CONTEXT module="cortex.functions.custom_cil-graph" layer="function" related_files="[\"custom/apps/cortex/pages/operations/OperationsDashboard.tsx\",\"custom/apps/portal/pages/ContentPage.tsx\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/functions/_shared/schema-utils.ts\",\"\\\"]"]
|
|
5
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="module exports and side effects" errors="none" side_effects="none"]
|
|
6
|
+
// CIL[DOC-MICRO logic_summary="Declares module scope, imports dependencies, and exports public surface of cortex.functions.custom_cil-graph" notable_decisions="[]"]
|
|
7
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
8
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
9
|
+
// CIL[DOC-AUDIENCE audience="developer"]
|
|
10
|
+
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: custom/apps/cortex/pages/operations/OperationsDashboard.tsx, custom/apps/portal/pages/ContentPage.tsx, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/functions/_shared/schema-utils.ts, \."]
|
|
11
|
+
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
12
|
+
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
13
|
+
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
14
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
15
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import { createHandler } from './_shared/middleware'
|
|
19
|
+
import { adminDb } from './_shared/db'
|
|
20
|
+
import { resolveLinkTypeId } from './_shared/resolve-ids'
|
|
21
|
+
import { callOpenAIEmbeddings } from './_shared/llm'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
// CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_graph_module_header_1784235266"]
|
|
30
|
+
// CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_graph_chunkcontract_1784235266" type="interface" identity="chunkcontract" parent="none"]
|
|
31
|
+
// CIL[DOC-MACRO purpose="Defines the chunkcontract type contract in cortex.functions.custom_cil-graph"]
|
|
32
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Describe the shape and allowed fields for chunkcontract"]
|
|
33
|
+
// CIL[DOC-CONTEXT module="cortex.functions.custom_cil-graph" layer="function" related_files="[\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"custom/apps/cortex/pages/operations/OperationsDashboard.tsx\",\"\\\"]"]
|
|
34
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="type definition for chunkcontract" errors="none" side_effects="none"]
|
|
35
|
+
// CIL[DOC-MICRO logic_summary="Declares TypeScript type/interface chunkcontract with member definitions" notable_decisions="[]"]
|
|
36
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
37
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
38
|
+
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, custom/apps/cortex/functions/custom_cil-embeddings.ts, .framework/src/pages/admin/IntegrationsPage.tsx, custom/apps/cortex/pages/operations/OperationsDashboard.tsx, \."]
|
|
39
|
+
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
40
|
+
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
41
|
+
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
42
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
43
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
44
|
+
interface ChunkContract {
|
|
45
|
+
id: string
|
|
46
|
+
chunk_name: string
|
|
47
|
+
file_path: string
|
|
48
|
+
line_start: number
|
|
49
|
+
line_end: number
|
|
50
|
+
chunk_type: string
|
|
51
|
+
macro: string
|
|
52
|
+
micro: string
|
|
53
|
+
input_spec: string
|
|
54
|
+
output_spec: string
|
|
55
|
+
side_effects: string
|
|
56
|
+
stability: string
|
|
57
|
+
test_unit_path: string | null
|
|
58
|
+
test_e2e_path: string | null
|
|
59
|
+
doc_confidence: string
|
|
60
|
+
boundary_confidence: string
|
|
61
|
+
stored_hash: string | null
|
|
62
|
+
hash_status: 'current' | 'drift_detected' | 'unknown'
|
|
63
|
+
callers: { chunk_id: string; chunk_name: string; file_path: string }[]
|
|
64
|
+
callees: { chunk_id: string; chunk_name: string; file_path: string }[]
|
|
65
|
+
is_dead_code: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
// CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_graph_chunkcontract_1784235266"]
|
|
75
|
+
// CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_graph_getchunkbyid_1784235266" type="function" identity="getchunkbyid" parent="none"]
|
|
76
|
+
// CIL[DOC-MACRO purpose="Implements getchunkbyid logic in cortex.functions.custom_cil-graph"]
|
|
77
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Execute getchunkbyid and return its computed result"]
|
|
78
|
+
// CIL[DOC-CONTEXT module="cortex.functions.custom_cil-graph" layer="function" related_files="[\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"\\\"]"]
|
|
79
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
|
|
80
|
+
// CIL[DOC-MICRO logic_summary="Provides getchunkbyid with getChunkById(chunkId: string inputs, handling internal flow and returning a result" notable_decisions="[]"]
|
|
81
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
82
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
83
|
+
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: custom/apps/cortex/functions/custom_cil-embeddings.ts, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/src/pages/admin/IntegrationsPage.tsx, \."]
|
|
84
|
+
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
85
|
+
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
86
|
+
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
87
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
88
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
89
|
+
async function getChunkById(chunkId: string): Promise<any | null> {
|
|
90
|
+
const { data: byId } = await adminDb
|
|
91
|
+
.from('items')
|
|
92
|
+
.select('id, title, data')
|
|
93
|
+
.eq('id', chunkId)
|
|
94
|
+
.maybeSingle()
|
|
95
|
+
if (byId) return byId
|
|
96
|
+
|
|
97
|
+
const { data: byTitle } = await adminDb
|
|
98
|
+
.from('items')
|
|
99
|
+
.select('id, title, data')
|
|
100
|
+
.eq('title', chunkId)
|
|
101
|
+
.eq('is_active', true)
|
|
102
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
103
|
+
.maybeSingle()
|
|
104
|
+
if (byTitle) return byTitle
|
|
105
|
+
|
|
106
|
+
const { data: byChunkName } = await adminDb
|
|
107
|
+
.from('items')
|
|
108
|
+
.select('id, title, data')
|
|
109
|
+
.filter('data->>chunk_name', 'eq', chunkId)
|
|
110
|
+
.eq('is_active', true)
|
|
111
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
112
|
+
.maybeSingle()
|
|
113
|
+
return byChunkName
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
// CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_graph_getchunkbyid_1784235266"]
|
|
121
|
+
// CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_graph_getlinkedchunks_1784235266" type="function" identity="getlinkedchunks" parent="none"]
|
|
122
|
+
// CIL[DOC-MACRO purpose="Implements getlinkedchunks logic in cortex.functions.custom_cil-graph"]
|
|
123
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Execute getlinkedchunks and return its computed result"]
|
|
124
|
+
// CIL[DOC-CONTEXT module="cortex.functions.custom_cil-graph" layer="function" related_files="[\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"\\\"]"]
|
|
125
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="return value from function execution" errors="throws on invalid input or runtime failure" side_effects="none"]
|
|
126
|
+
// CIL[DOC-MICRO logic_summary="Provides getlinkedchunks with getLinkedChunks( inputs, handling internal flow and returning a result" notable_decisions="[]"]
|
|
127
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
128
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
129
|
+
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: custom/apps/cortex/functions/custom_cil-embeddings.ts, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/src/pages/admin/IntegrationsPage.tsx, \."]
|
|
130
|
+
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
131
|
+
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
132
|
+
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
133
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
134
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
135
|
+
async function getLinkedChunks(
|
|
136
|
+
chunkId: string,
|
|
137
|
+
linkTypeSlug: string,
|
|
138
|
+
direction: 'callers' | 'callees'
|
|
139
|
+
): Promise<{ chunk_id: string; chunk_name: string; file_path: string }[]> {
|
|
140
|
+
try {
|
|
141
|
+
const linkTypeId = await resolveLinkTypeId(linkTypeSlug)
|
|
142
|
+
|
|
143
|
+
const query = direction === 'callees'
|
|
144
|
+
? adminDb.from('links').select('target_id').eq('source_id', chunkId).eq('link_type_id', linkTypeId)
|
|
145
|
+
: adminDb.from('links').select('source_id').eq('target_id', chunkId).eq('link_type_id', linkTypeId)
|
|
146
|
+
|
|
147
|
+
const { data: links } = await query
|
|
148
|
+
if (!links || links.length === 0) return []
|
|
149
|
+
|
|
150
|
+
const ids = direction === 'callees'
|
|
151
|
+
? links.map((l: any) => l.target_id)
|
|
152
|
+
: links.map((l: any) => l.source_id)
|
|
153
|
+
|
|
154
|
+
const { data: chunks } = await adminDb
|
|
155
|
+
.from('items')
|
|
156
|
+
.select('id, data')
|
|
157
|
+
.in('id', ids)
|
|
158
|
+
|
|
159
|
+
return (chunks || []).map((c: any) => ({
|
|
160
|
+
chunk_id: c.id,
|
|
161
|
+
chunk_name: c.data?.chunk_name || c.data?.title || 'Unknown',
|
|
162
|
+
file_path: c.data?.file_path || '',
|
|
163
|
+
}))
|
|
164
|
+
} catch {
|
|
165
|
+
return []
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
// CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_graph_getlinkedchunks_1784235266"]
|
|
176
|
+
// CIL[BEGIN chunk_id="custom_apps_cortex_functions_custom_cil_graph_handler_1784235266" type="variable" identity="handler" parent="none"]
|
|
177
|
+
// CIL[DOC-MACRO purpose="Defines handler configuration or state in cortex.functions.custom_cil-graph"]
|
|
178
|
+
// CIL[DOC-RESPONSIBILITY responsibility="Hold the value and default configuration for handler"]
|
|
179
|
+
// CIL[DOC-CONTEXT module="cortex.functions.custom_cil-graph" layer="function" related_files="[\"custom/apps/cortex/functions/custom_cil-embeddings.ts\",\".framework/src/pages/admin/TypeDetailPage.tsx\",\".framework/functions/_shared/principal.ts\",\".framework/src/pages/admin/IntegrationsPage.tsx\",\"\\\"]"]
|
|
180
|
+
// CIL[DOC-CONTRACT inputs="none" outputs="value of handler" errors="none" side_effects="none"]
|
|
181
|
+
// CIL[DOC-MICRO logic_summary="Declares handler with initial value or constant binding used by cortex.functions.custom_cil-graph" notable_decisions="[]"]
|
|
182
|
+
// CIL[DOC-CONFIDENCE pass="second" score="0.95" flags="none"]
|
|
183
|
+
// CIL[DOC-STABILITY stability="stable"]
|
|
184
|
+
// CIL[DOC-VECTOR type="context" content="Layer: function. Direct callers: 0. Direct calls: 0. Related files: custom/apps/cortex/functions/custom_cil-embeddings.ts, .framework/src/pages/admin/TypeDetailPage.tsx, .framework/functions/_shared/principal.ts, .framework/src/pages/admin/IntegrationsPage.tsx, \."]
|
|
185
|
+
// CIL[DOC-VECTOR type="blast_radius" content="Direct callers: 0. Total affected: 0."]
|
|
186
|
+
// CIL[DOC-VECTOR type="configuration" content="No configuration dependencies."]
|
|
187
|
+
// CIL[DOC-VECTOR type="constraint" content="No test paths identified."]
|
|
188
|
+
// CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
|
|
189
|
+
// CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
|
|
190
|
+
export const handler = createHandler(async (ctx, body) => {
|
|
191
|
+
const action = ctx.query?.action
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if (action === 'get_chunk_contract') {
|
|
195
|
+
const chunkId = ctx.query?.chunk_id
|
|
196
|
+
if (!chunkId) throw new Error('chunk_id is required')
|
|
197
|
+
|
|
198
|
+
const chunk = await getChunkById(chunkId)
|
|
199
|
+
if (!chunk) throw new Error(`Chunk not found: ${chunkId}`)
|
|
200
|
+
const resolvedChunkId = chunk.id
|
|
201
|
+
|
|
202
|
+
const [callers, callees] = await Promise.all([
|
|
203
|
+
getLinkedChunks(resolvedChunkId, 'cil_calls', 'callers'),
|
|
204
|
+
getLinkedChunks(resolvedChunkId, 'cil_calls', 'callees'),
|
|
205
|
+
])
|
|
206
|
+
|
|
207
|
+
const d = chunk.data || {}
|
|
208
|
+
const contract: ChunkContract = {
|
|
209
|
+
id: chunk.id,
|
|
210
|
+
chunk_name: d.chunk_name || chunk.title || '',
|
|
211
|
+
file_path: d.file_path || '',
|
|
212
|
+
line_start: d.line_start || 0,
|
|
213
|
+
line_end: d.line_end || 0,
|
|
214
|
+
chunk_type: d.chunk_type || '',
|
|
215
|
+
macro: d.macro || '',
|
|
216
|
+
micro: d.micro || '',
|
|
217
|
+
input_spec: d.input_spec || '',
|
|
218
|
+
output_spec: d.output_spec || '',
|
|
219
|
+
side_effects: d.side_effects || '',
|
|
220
|
+
stability: d.stability || 'unknown',
|
|
221
|
+
test_unit_path: d.test_unit_path || null,
|
|
222
|
+
test_e2e_path: d.test_e2e_path || null,
|
|
223
|
+
doc_confidence: d.doc_confidence || 'unknown',
|
|
224
|
+
boundary_confidence: d.boundary_confidence || 'unknown',
|
|
225
|
+
stored_hash: d.stored_hash || null,
|
|
226
|
+
hash_status: 'unknown', // validated on demand via custom_cil-validate
|
|
227
|
+
callers,
|
|
228
|
+
callees,
|
|
229
|
+
is_dead_code: d.is_dead_code || false,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return { contract }
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
if (action === 'get_callers') {
|
|
237
|
+
const chunkId = ctx.query?.chunk_id
|
|
238
|
+
if (!chunkId) throw new Error('chunk_id is required')
|
|
239
|
+
const chunk = await getChunkById(chunkId)
|
|
240
|
+
if (!chunk) throw new Error(`Chunk not found: ${chunkId}`)
|
|
241
|
+
const callers = await getLinkedChunks(chunk.id, 'cil_calls', 'callers')
|
|
242
|
+
return { chunk_id: chunk.id, callers }
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
if (action === 'get_blast_radius') {
|
|
247
|
+
const chunkId = ctx.query?.chunk_id
|
|
248
|
+
const maxDepth = parseInt(ctx.query?.max_depth || '3')
|
|
249
|
+
if (!chunkId) throw new Error('chunk_id is required')
|
|
250
|
+
|
|
251
|
+
const rootChunk = await getChunkById(chunkId)
|
|
252
|
+
if (!rootChunk) throw new Error(`Chunk not found: ${chunkId}`)
|
|
253
|
+
const resolvedChunkId = rootChunk.id
|
|
254
|
+
|
|
255
|
+
const visited = new Set<string>()
|
|
256
|
+
const queue: { id: string; depth: number }[] = [{ id: resolvedChunkId, depth: 0 }]
|
|
257
|
+
const affected: { chunk_id: string; chunk_name: string; file_path: string; depth: number }[] = []
|
|
258
|
+
|
|
259
|
+
while (queue.length > 0) {
|
|
260
|
+
const { id, depth } = queue.shift()!
|
|
261
|
+
if (visited.has(id) || depth > maxDepth) continue
|
|
262
|
+
visited.add(id)
|
|
263
|
+
|
|
264
|
+
if (id !== resolvedChunkId) {
|
|
265
|
+
const chunk = await getChunkById(id)
|
|
266
|
+
if (chunk) {
|
|
267
|
+
affected.push({
|
|
268
|
+
chunk_id: id,
|
|
269
|
+
chunk_name: chunk.data?.chunk_name || chunk.title || 'Unknown',
|
|
270
|
+
file_path: chunk.data?.file_path || '',
|
|
271
|
+
depth,
|
|
272
|
+
})
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (depth < maxDepth) {
|
|
277
|
+
const callers = await getLinkedChunks(id, 'cil_calls', 'callers')
|
|
278
|
+
for (const caller of callers) {
|
|
279
|
+
if (!visited.has(caller.chunk_id)) {
|
|
280
|
+
queue.push({ id: caller.chunk_id, depth: depth + 1 })
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
chunk_id: resolvedChunkId,
|
|
288
|
+
max_depth: maxDepth,
|
|
289
|
+
affected_count: affected.length,
|
|
290
|
+
affected,
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
if (action === 'get_test_paths') {
|
|
296
|
+
const chunkId = ctx.query?.chunk_id
|
|
297
|
+
if (!chunkId) throw new Error('chunk_id is required')
|
|
298
|
+
|
|
299
|
+
const chunk = await getChunkById(chunkId)
|
|
300
|
+
if (!chunk) throw new Error(`Chunk not found: ${chunkId}`)
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
chunk_id: chunk.id,
|
|
304
|
+
chunk_name: chunk.data?.chunk_name || '',
|
|
305
|
+
test_unit_path: chunk.data?.test_unit_path || null,
|
|
306
|
+
test_e2e_path: chunk.data?.test_e2e_path || null,
|
|
307
|
+
doc_confidence: chunk.data?.doc_confidence || 'unknown',
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
if (action === 'get_file_graph') {
|
|
313
|
+
const fileId = ctx.query?.file_id
|
|
314
|
+
if (!fileId) throw new Error('file_id is required')
|
|
315
|
+
|
|
316
|
+
const { data: file } = await adminDb
|
|
317
|
+
.from('items')
|
|
318
|
+
.select('id, title, data')
|
|
319
|
+
.eq('id', fileId)
|
|
320
|
+
.maybeSingle()
|
|
321
|
+
|
|
322
|
+
if (!file) throw new Error(`File not found: ${fileId}`)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
const { data: chunks } = await adminDb
|
|
326
|
+
.from('items')
|
|
327
|
+
.select('id, title, data')
|
|
328
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
329
|
+
.filter('data->>file_id', 'eq', fileId)
|
|
330
|
+
.eq('is_active', true)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
let imports: any[] = []
|
|
334
|
+
try {
|
|
335
|
+
const importLinkTypeId = await resolveLinkTypeId('cil_imports')
|
|
336
|
+
const { data: importLinks } = await adminDb
|
|
337
|
+
.from('links')
|
|
338
|
+
.select('target_id, metadata')
|
|
339
|
+
.eq('source_id', fileId)
|
|
340
|
+
.eq('link_type_id', importLinkTypeId)
|
|
341
|
+
imports = importLinks || []
|
|
342
|
+
} catch { /* link type may not exist yet */ }
|
|
343
|
+
|
|
344
|
+
return {
|
|
345
|
+
file: {
|
|
346
|
+
id: file.id,
|
|
347
|
+
file_path: file.data?.file_path || '',
|
|
348
|
+
language: file.data?.language || '',
|
|
349
|
+
ingestion_pass: file.data?.ingestion_pass || 0,
|
|
350
|
+
stored_hash: file.data?.stored_hash || null,
|
|
351
|
+
is_dead_code: file.data?.is_dead_code || false,
|
|
352
|
+
},
|
|
353
|
+
chunks: (chunks || []).map(c => ({
|
|
354
|
+
id: c.id,
|
|
355
|
+
chunk_name: c.data?.chunk_name || '',
|
|
356
|
+
line_start: c.data?.line_start || 0,
|
|
357
|
+
line_end: c.data?.line_end || 0,
|
|
358
|
+
chunk_type: c.data?.chunk_type || '',
|
|
359
|
+
boundary_confidence: c.data?.boundary_confidence || '',
|
|
360
|
+
review_status: c.data?.review_status || '',
|
|
361
|
+
doc_confidence: c.data?.doc_confidence || '',
|
|
362
|
+
is_dead_code: c.data?.is_dead_code || false,
|
|
363
|
+
stored_hash: c.data?.stored_hash || null,
|
|
364
|
+
})),
|
|
365
|
+
imports,
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
if (action === 'search') {
|
|
371
|
+
const query = ctx.query?.q || body?.q
|
|
372
|
+
const projectId = ctx.query?.project_id || body?.project_id
|
|
373
|
+
const limit = parseInt(ctx.query?.limit || '20')
|
|
374
|
+
const mode = ctx.query?.mode || body?.mode || 'hybrid'
|
|
375
|
+
if (!query) throw new Error('q is required')
|
|
376
|
+
|
|
377
|
+
const results: any[] = []
|
|
378
|
+
const seenIds = new Set<string>()
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
if (mode !== 'text') {
|
|
382
|
+
try {
|
|
383
|
+
const ej = await callOpenAIEmbeddings(ctx, [query], 'text-embedding-3-small')
|
|
384
|
+
const vec = ej.data?.[0]?.embedding
|
|
385
|
+
if (vec) {
|
|
386
|
+
const vectorLiteral = `[${vec.join(',')}]`
|
|
387
|
+
const { data: matches } = await adminDb.rpc('match_embeddings', {
|
|
388
|
+
query_embedding: vectorLiteral,
|
|
389
|
+
match_count: limit,
|
|
390
|
+
filter_vector_type: 'semantic',
|
|
391
|
+
similarity_threshold: 0.2,
|
|
392
|
+
filter_item_types: ['cil_chunk'],
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
const matchIds = [...new Set((matches || []).map((m: any) => m.document_id))]
|
|
396
|
+
if (matchIds.length > 0) {
|
|
397
|
+
let chunkQuery = adminDb
|
|
398
|
+
.from('items')
|
|
399
|
+
.select('id, title, data')
|
|
400
|
+
.in('id', matchIds)
|
|
401
|
+
.eq('is_active', true)
|
|
402
|
+
|
|
403
|
+
if (projectId) {
|
|
404
|
+
chunkQuery = chunkQuery.filter('data->>project_id', 'eq', projectId)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const { data: chunks } = await chunkQuery
|
|
408
|
+
const chunkMap = new Map((chunks || []).map((c: any) => [c.id, c]))
|
|
409
|
+
|
|
410
|
+
for (const m of (matches || [])) {
|
|
411
|
+
const chunk = chunkMap.get(m.document_id)
|
|
412
|
+
if (!chunk || seenIds.has(chunk.id)) continue
|
|
413
|
+
seenIds.add(chunk.id)
|
|
414
|
+
results.push({
|
|
415
|
+
id: chunk.id,
|
|
416
|
+
chunk_name: chunk.data?.chunk_name || chunk.title,
|
|
417
|
+
file_path: chunk.data?.file_path || '',
|
|
418
|
+
macro: chunk.data?.macro || '',
|
|
419
|
+
chunk_type: chunk.data?.chunk_type || '',
|
|
420
|
+
doc_confidence: chunk.data?.doc_confidence || '',
|
|
421
|
+
similarity: m.similarity,
|
|
422
|
+
match_type: 'semantic',
|
|
423
|
+
})
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
} catch { /* fall through to text search */ }
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
if (mode !== 'semantic' && results.length < limit) {
|
|
432
|
+
let dbQuery = adminDb
|
|
433
|
+
.from('items')
|
|
434
|
+
.select('id, title, data')
|
|
435
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
436
|
+
.eq('is_active', true)
|
|
437
|
+
.limit(limit - results.length)
|
|
438
|
+
|
|
439
|
+
if (projectId) dbQuery = dbQuery.filter('data->>project_id', 'eq', projectId)
|
|
440
|
+
const { data: textResults } = await dbQuery.ilike('title', `%${query}%`)
|
|
441
|
+
|
|
442
|
+
for (const r of textResults || []) {
|
|
443
|
+
if (seenIds.has(r.id)) continue
|
|
444
|
+
seenIds.add(r.id)
|
|
445
|
+
results.push({
|
|
446
|
+
id: r.id,
|
|
447
|
+
chunk_name: r.data?.chunk_name || r.title,
|
|
448
|
+
file_path: r.data?.file_path || '',
|
|
449
|
+
macro: r.data?.macro || '',
|
|
450
|
+
chunk_type: r.data?.chunk_type || '',
|
|
451
|
+
doc_confidence: r.data?.doc_confidence || '',
|
|
452
|
+
similarity: null,
|
|
453
|
+
match_type: 'text',
|
|
454
|
+
})
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return { query, mode, results, count: results.length }
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
if (action === 'get_file_chunks') {
|
|
463
|
+
const fileId = ctx.query?.file_id
|
|
464
|
+
if (!fileId) throw new Error('file_id is required')
|
|
465
|
+
|
|
466
|
+
const { data: fileItem } = await adminDb.from('items').select('id, title, data')
|
|
467
|
+
.eq('id', fileId).maybeSingle()
|
|
468
|
+
if (!fileItem) throw new Error(`File not found: ${fileId}`)
|
|
469
|
+
|
|
470
|
+
const { data: chunks } = await adminDb.from('items').select('id, title, data')
|
|
471
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
472
|
+
.filter('data->>file_id', 'eq', fileId)
|
|
473
|
+
.eq('is_active', true)
|
|
474
|
+
|
|
475
|
+
const sorted = (chunks || [])
|
|
476
|
+
.map((c: any) => ({
|
|
477
|
+
id: c.id,
|
|
478
|
+
chunk_name: c.data?.chunk_name || '',
|
|
479
|
+
chunk_type: c.data?.chunk_type || '',
|
|
480
|
+
line_start: c.data?.line_start || 0,
|
|
481
|
+
line_end: c.data?.line_end || 0,
|
|
482
|
+
macro: c.data?.macro || '',
|
|
483
|
+
doc_confidence: c.data?.doc_confidence || 'unverified_legacy',
|
|
484
|
+
boundary_confidence: c.data?.boundary_confidence || '',
|
|
485
|
+
stored_hash: c.data?.stored_hash || null,
|
|
486
|
+
is_dead_code: c.data?.is_dead_code || false,
|
|
487
|
+
review_status: c.data?.review_status || '',
|
|
488
|
+
stability: c.data?.stability || '',
|
|
489
|
+
file_path: c.data?.file_path || fileItem.data?.file_path || '',
|
|
490
|
+
project_id: c.data?.project_id || '',
|
|
491
|
+
}))
|
|
492
|
+
.sort((a: any, b: any) => a.line_start - b.line_start)
|
|
493
|
+
|
|
494
|
+
return {
|
|
495
|
+
file_id: fileId,
|
|
496
|
+
file_path: fileItem.data?.file_path || '',
|
|
497
|
+
language: fileItem.data?.language || '',
|
|
498
|
+
chunk_count: sorted.length,
|
|
499
|
+
chunks: sorted,
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
if (action === 'get_project_graph') {
|
|
505
|
+
const projectId = ctx.query?.project_id
|
|
506
|
+
if (!projectId) throw new Error('project_id is required')
|
|
507
|
+
|
|
508
|
+
const [filesResult, chunksResult] = await Promise.all([
|
|
509
|
+
adminDb.from('items').select('id, title, data')
|
|
510
|
+
.filter('data->>kb_type', 'eq', 'cil_file')
|
|
511
|
+
.filter('data->>project_id', 'eq', projectId)
|
|
512
|
+
.eq('is_active', true),
|
|
513
|
+
adminDb.from('items').select('id, title, data')
|
|
514
|
+
.filter('data->>kb_type', 'eq', 'cil_chunk')
|
|
515
|
+
.filter('data->>project_id', 'eq', projectId)
|
|
516
|
+
.eq('is_active', true)
|
|
517
|
+
.limit(500),
|
|
518
|
+
])
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
let importEdges: any[] = []
|
|
522
|
+
try {
|
|
523
|
+
const importLinkTypeId = await resolveLinkTypeId('cil_imports')
|
|
524
|
+
const fileIds = (filesResult.data || []).map((f: any) => f.id)
|
|
525
|
+
if (fileIds.length > 0) {
|
|
526
|
+
const { data: edges } = await adminDb
|
|
527
|
+
.from('links')
|
|
528
|
+
.select('source_id, target_id, metadata')
|
|
529
|
+
.eq('link_type_id', importLinkTypeId)
|
|
530
|
+
.in('source_id', fileIds)
|
|
531
|
+
importEdges = edges || []
|
|
532
|
+
}
|
|
533
|
+
} catch { /* link type may not exist yet */ }
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
let callEdges: any[] = []
|
|
537
|
+
try {
|
|
538
|
+
const callLinkTypeId = await resolveLinkTypeId('cil_calls')
|
|
539
|
+
const chunkIds = (chunksResult.data || []).map((c: any) => c.id)
|
|
540
|
+
if (chunkIds.length > 0) {
|
|
541
|
+
const { data: edges } = await adminDb
|
|
542
|
+
.from('links')
|
|
543
|
+
.select('source_id, target_id, metadata')
|
|
544
|
+
.eq('link_type_id', callLinkTypeId)
|
|
545
|
+
.in('source_id', chunkIds)
|
|
546
|
+
callEdges = edges || []
|
|
547
|
+
}
|
|
548
|
+
} catch { /* link type may not exist yet */ }
|
|
549
|
+
|
|
550
|
+
return {
|
|
551
|
+
project_id: projectId,
|
|
552
|
+
nodes: {
|
|
553
|
+
files: (filesResult.data || []).map((f: any) => ({
|
|
554
|
+
id: f.id,
|
|
555
|
+
file_path: f.data?.file_path || '',
|
|
556
|
+
language: f.data?.language || '',
|
|
557
|
+
ingestion_pass: f.data?.ingestion_pass || 0,
|
|
558
|
+
is_dead_code: f.data?.is_dead_code || false,
|
|
559
|
+
chunk_count: f.data?.chunk_count || 0,
|
|
560
|
+
})),
|
|
561
|
+
chunks: (chunksResult.data || []).map((c: any) => ({
|
|
562
|
+
id: c.id,
|
|
563
|
+
chunk_name: c.data?.chunk_name || '',
|
|
564
|
+
file_id: c.data?.file_id || '',
|
|
565
|
+
file_path: c.data?.file_path || '',
|
|
566
|
+
chunk_type: c.data?.chunk_type || '',
|
|
567
|
+
boundary_confidence: c.data?.boundary_confidence || '',
|
|
568
|
+
doc_confidence: c.data?.doc_confidence || '',
|
|
569
|
+
is_dead_code: c.data?.is_dead_code || false,
|
|
570
|
+
stored_hash: c.data?.stored_hash || null,
|
|
571
|
+
})),
|
|
572
|
+
},
|
|
573
|
+
edges: {
|
|
574
|
+
imports: importEdges,
|
|
575
|
+
calls: callEdges,
|
|
576
|
+
},
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
throw new Error(`Unknown action: ${action}. Valid: get_chunk_contract, get_callers, get_blast_radius, get_test_paths, get_file_graph, get_file_chunks, search, get_project_graph`)
|
|
581
|
+
})
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
// CIL[END chunk_id="custom_apps_cortex_functions_custom_cil_graph_handler_1784235266"]
|