@polymorphism-tech/morph-spec 8.38.0 → 8.40.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.
Files changed (227) hide show
  1. package/CLAUDE.md +19 -8
  2. package/README.md +2 -2
  3. package/bin/morph-spec.js +60 -43
  4. package/claude-plugin.json +1 -1
  5. package/docs/CHEATSHEET.md +1 -1
  6. package/docs/QUICKSTART.md +1 -1
  7. package/framework/CLAUDE.md +3 -2
  8. package/framework/MORPH.md +1 -1
  9. package/framework/agents.json +36 -25
  10. package/framework/docs/CLI.md +2 -2
  11. package/framework/evals/rubrics/code-quality.md +4 -4
  12. package/framework/evals/rubrics/condensed.md +2 -2
  13. package/framework/mcp/registry.json +33 -2
  14. package/framework/rules/infrastructure-standards.md +0 -1
  15. package/framework/rules/morph-workflow.md +9 -4
  16. package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
  17. package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
  18. package/framework/skills/core/morph-apply/SKILL.md +5 -1
  19. package/framework/skills/core/morph-brainstorming/SKILL.md +1 -1
  20. package/framework/skills/core/morph-eval/SKILL.md +1 -1
  21. package/framework/skills/core/morph-hotfix/SKILL.md +1 -1
  22. package/framework/skills/core/morph-implement/SKILL.md +6 -1
  23. package/framework/skills/core/morph-media/SKILL.md +1 -1
  24. package/framework/skills/core/morph-plan/SKILL.md +4 -3
  25. package/framework/skills/core/morph-proposal/SKILL.md +1 -1
  26. package/framework/skills/core/morph-review/SKILL.md +1 -1
  27. package/framework/skills/core/morph-stack-scan/SKILL.md +1 -1
  28. package/framework/skills/core/morph-standards/SKILL.md +1 -1
  29. package/framework/skills/core/morph-uiux/SKILL.md +6 -5
  30. package/framework/standards/STANDARDS.json +3 -3
  31. package/framework/standards/ai-agents/context-providers.md +16 -26
  32. package/framework/standards/ai-agents/durable-workflows-hitl.md +15 -21
  33. package/framework/standards/ai-agents/modalities-image-gen.md +21 -25
  34. package/framework/standards/ai-agents/modalities-speech-to-text.md +4 -15
  35. package/framework/standards/ai-agents/modalities-text-to-speech.md +2 -11
  36. package/framework/standards/ai-agents/modalities-vision.md +1 -18
  37. package/framework/standards/ai-agents/prompt-sources.md +0 -4
  38. package/framework/standards/architecture/code-comments.md +52 -16
  39. package/framework/standards/backend/integrations/neon-auth/neon-auth.md +63 -50
  40. package/framework/standards/frontend/design-system/ai-image-generation.md +5 -5
  41. package/framework/standards/integration/mcp/mcp-tools.md +48 -117
  42. package/framework/templates/code/dotnet/abstractions/result.cs +0 -2
  43. package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +26 -39
  44. package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +28 -68
  45. package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +99 -117
  46. package/framework/templates/code/dotnet/ai-agents/PromptRepository.cs.template +2 -44
  47. package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +40 -61
  48. package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +54 -107
  49. package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +53 -58
  50. package/framework/templates/code/dotnet/contracts/contracts-vsa.cs +192 -281
  51. package/framework/templates/code/dotnet/database/migration.cs +49 -83
  52. package/framework/templates/code/dotnet/database/vector-entity.cs +2 -46
  53. package/framework/templates/code/dotnet/extensions/result-extensions.cs +0 -2
  54. package/framework/templates/code/dotnet/feature/validator.cs.hbs +11 -15
  55. package/framework/templates/code/dotnet/jobs/agent.cs +3 -51
  56. package/framework/templates/code/dotnet/jobs/job.cs +2 -97
  57. package/framework/templates/code/dotnet/test.cs +2 -87
  58. package/framework/templates/code/typescript/contracts.ts +140 -167
  59. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentApi.cs +1 -48
  60. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentFactory.cs +3 -79
  61. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentFactoryOptions.cs +1 -70
  62. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentSpec.cs +1 -47
  63. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentSpecOptions.cs +2 -99
  64. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/AiKitAssemblyMarker.cs +0 -6
  65. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/ConversationStore.cs +3 -88
  66. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/IConversationStore.cs +1 -41
  67. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/InMemoryConversationStore.cs +0 -21
  68. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/CountingChatClient.cs +1 -25
  69. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalAssertion.cs +2 -63
  70. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheMissException.cs +0 -30
  71. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheOptions.cs +1 -52
  72. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheStamp.cs +3 -78
  73. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalFixture.cs +4 -109
  74. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalMode.cs +0 -22
  75. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalQualityEvaluators.cs +1 -36
  76. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalScenario.cs +2 -57
  77. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalSummary.cs +0 -75
  78. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/OfflineChatClient.cs +2 -59
  79. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/ShortPathResponseCache.cs +4 -111
  80. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/IMediaGenerator.cs +0 -34
  81. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/IMediaProvider.cs +1 -57
  82. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaArtifact.cs +0 -19
  83. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaDisclosure.cs +2 -74
  84. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaGenerator.cs +2 -33
  85. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaIdempotencyKey.cs +1 -43
  86. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJob.cs +1 -96
  87. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJobId.cs +0 -13
  88. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJobState.cs +0 -27
  89. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaPricing.cs +0 -33
  90. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaProvenance.cs +0 -31
  91. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaRequest.cs +3 -75
  92. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaResult.cs +0 -42
  93. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaReview.cs +0 -39
  94. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaSeams.cs +1 -55
  95. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaStore.cs +3 -59
  96. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MorphMedia.cs +0 -46
  97. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/GoogleImageProvider.cs +3 -28
  98. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/OpenAIImageProvider.cs +7 -61
  99. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/VeoVideoProvider.cs +2 -37
  100. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/IUsageCostSink.cs +1 -23
  101. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/UsageCostMiddleware.cs +2 -82
  102. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/UsageCostRecord.cs +1 -68
  103. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Observability/MorphOpenTelemetryExtensions.cs +1 -62
  104. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Observability/MorphTelemetryOptions.cs +2 -62
  105. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/IProviderClientFactory.cs +1 -25
  106. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/ModelAlias.cs +0 -124
  107. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/ModelRegistry.cs +1 -73
  108. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Rag/DeltaIngest.cs +1 -66
  109. package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Rag/DeltaPlan.cs +0 -41
  110. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/AgentFactoryTests.cs +2 -112
  111. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/AgentSpecTests.cs +2 -43
  112. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/ConversationStoreTests.cs +5 -110
  113. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/DeltaIngestTests.cs +7 -103
  114. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalAssertionTests.cs +1 -42
  115. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalCacheMissTests.cs +1 -30
  116. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalCacheStampTests.cs +1 -19
  117. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalFailuresTests.cs +0 -48
  118. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalFixtureTests.cs +1 -29
  119. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalRefreshTests.cs +2 -38
  120. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalWorkspace.cs +1 -14
  121. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/KitEvals.cs +4 -69
  122. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/OfflineChatClientTests.cs +1 -10
  123. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeChatClient.cs +1 -57
  124. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeChatClientTests.cs +0 -26
  125. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeClock.cs +1 -19
  126. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeMediaProvider.cs +0 -32
  127. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeProviderClientFactory.cs +0 -14
  128. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeUsageCostSink.cs +0 -24
  129. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/InMemoryMediaStore.cs +0 -32
  130. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaAccessibilityTests.cs +0 -37
  131. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaAliasIsNotAnAgentTests.cs +0 -24
  132. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaDisclosureTests.cs +0 -78
  133. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaGeneratorTests.cs +0 -53
  134. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaIdempotencyKeyTests.cs +0 -44
  135. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaJobStateTests.cs +0 -44
  136. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaReviewTests.cs +0 -19
  137. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaStoreTests.cs +0 -24
  138. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/ModelRegistryTests.cs +6 -48
  139. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/SkeletonSmokeTests.cs +1 -13
  140. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/TelemetryTests.cs +2 -71
  141. package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/UsageCostMiddlewareTests.cs +5 -100
  142. package/framework/templates/frontend/nextjs/Dockerfile.nextjs.hbs +39 -43
  143. package/framework/templates/frontend/nextjs/env.mjs.hbs +29 -32
  144. package/framework/templates/frontend/nextjs/page.tsx.hbs +21 -22
  145. package/framework/templates/frontend/nextjs/use-feature.ts.hbs +42 -54
  146. package/framework/templates/integrations/asaas-client.cs +332 -387
  147. package/framework/templates/integrations/asaas-webhook.cs +290 -351
  148. package/framework/templates/integrations/neon-auth-config.cs +9 -105
  149. package/framework/templates/project/validate.js +97 -120
  150. package/package.json +2 -2
  151. package/src/commands/dashboard/dashboard.js +80 -53
  152. package/src/commands/mcp/mcp-setup.js +37 -9
  153. package/src/commands/project/doctor.js +3 -5
  154. package/src/commands/project/init.js +6 -3
  155. package/src/commands/project/install-plugin-cmd.js +1 -1
  156. package/src/commands/project/update.js +5 -0
  157. package/src/dashboard/app/App.jsx +80 -16
  158. package/src/dashboard/app/components/ActivityFeed.jsx +172 -0
  159. package/src/dashboard/app/components/CommandPalette.jsx +155 -0
  160. package/src/dashboard/app/components/DetailPanel.jsx +47 -11
  161. package/src/dashboard/app/components/EntityLink.jsx +55 -0
  162. package/src/dashboard/app/components/ErrorBoundary.jsx +54 -0
  163. package/src/dashboard/app/components/FlowGraph.jsx +19 -17
  164. package/src/dashboard/app/components/KnowledgeMarkdown.jsx +53 -0
  165. package/src/dashboard/app/components/Markdown.jsx +47 -0
  166. package/src/dashboard/app/components/PhaseRail.jsx +111 -0
  167. package/src/dashboard/app/components/SearchFilter.jsx +40 -22
  168. package/src/dashboard/app/components/Sidebar.jsx +146 -37
  169. package/src/dashboard/app/hooks/useMorphQuery.js +54 -0
  170. package/src/dashboard/app/hooks/usePref.js +38 -0
  171. package/src/dashboard/app/lib/format.js +69 -0
  172. package/src/dashboard/app/lib/phases.js +56 -0
  173. package/src/dashboard/app/lib/project.js +50 -0
  174. package/src/dashboard/app/pages/Activity.jsx +24 -0
  175. package/src/dashboard/app/pages/AgentMap.jsx +371 -370
  176. package/src/dashboard/app/pages/FeatureDetail.jsx +604 -0
  177. package/src/dashboard/app/pages/Features.jsx +400 -0
  178. package/src/dashboard/app/pages/Guide.jsx +146 -0
  179. package/src/dashboard/app/pages/HookInspector.jsx +357 -322
  180. package/src/dashboard/app/pages/PhasePipeline.jsx +277 -408
  181. package/src/dashboard/app/pages/Portfolio.jsx +156 -0
  182. package/src/dashboard/app/pages/Rubrics.jsx +101 -0
  183. package/src/dashboard/app/pages/RulesMap.jsx +300 -273
  184. package/src/dashboard/app/pages/SkillsLibrary.jsx +483 -366
  185. package/src/dashboard/app/pages/Standards.jsx +407 -332
  186. package/src/dashboard/app/styles/index.css +187 -47
  187. package/src/dashboard/index.html +14 -12
  188. package/src/dashboard/package.json +32 -24
  189. package/src/dashboard/scanner/activity-scanner.js +351 -0
  190. package/src/dashboard/scanner/agents-scanner.js +59 -1
  191. package/src/dashboard/scanner/docs-scanner.js +59 -0
  192. package/src/dashboard/scanner/feature-status.js +10 -0
  193. package/src/dashboard/scanner/features-scanner.js +360 -0
  194. package/src/dashboard/scanner/index.js +14 -7
  195. package/src/dashboard/scanner/phases-scanner.js +14 -15
  196. package/src/dashboard/scanner/portfolio.js +153 -0
  197. package/src/dashboard/scanner/project-api.js +195 -0
  198. package/src/dashboard/scanner/rules-scanner.js +42 -37
  199. package/src/dashboard/scanner/skills-scanner.js +105 -43
  200. package/src/dashboard/scanner/standards-scanner.js +2 -0
  201. package/src/dashboard/vite-plugin-morph-data.js +134 -17
  202. package/src/lib/detectors/claude-config-detector.js +2 -7
  203. package/src/lib/detectors/index.js +5 -1
  204. package/src/lib/evaluator-report.js +22 -0
  205. package/src/lib/generators/settings-generator.js +208 -209
  206. package/src/lib/installers/mcp-installer.js +724 -719
  207. package/src/lib/installers/memory-installer.js +1 -2
  208. package/src/lib/projects/registry.js +154 -0
  209. package/src/lib/validators/code-budget/code-budget-validator.js +32 -4
  210. package/src/scripts/install-plugin.js +1 -1
  211. package/src/scripts/setup-infra.js +2 -4
  212. package/src/utils/agents-installer.js +57 -12
  213. package/src/utils/banner.js +1 -1
  214. package/src/commands/index.js +0 -13
  215. package/src/commands/project/checkpoint.js +0 -209
  216. package/src/core/state/phase-state-machine.js +0 -197
  217. package/src/dashboard/app/hooks/useDetailPanel.js +0 -15
  218. package/src/dashboard/app/pages/LiveState.jsx +0 -206
  219. package/src/dashboard/scanner/squads-scanner.js +0 -13
  220. package/src/dashboard/scanner/state-scanner.js +0 -85
  221. package/src/lib/generators/index.js +0 -10
  222. package/src/lib/hooks/hook-executor.js +0 -167
  223. package/src/lib/validators/checkpoint-persistence.js +0 -39
  224. package/src/lib/validators/shared/emit-validator-dispatch.js +0 -14
  225. package/src/lib/validators/shared/index.js +0 -12
  226. package/src/lib/validators/shared/issue-counter.js +0 -14
  227. package/src/lib/validators/shared/result-formatter.js +0 -124
@@ -1,107 +1,54 @@
1
- // TEMPLATE: VectorSearchTool.cs
2
- // PURPOSE: A typed MAF tool that retrieves relevant chunks from the pgvector knowledge base.
3
- // READS STANDARD: ai-agents-rag-custom-pgvector
4
- // PLACEHOLDERS:
5
- // {{PROJECT_NAMESPACE}} — root namespace of the project (e.g., MyProject)
6
- // LAST-VERIFIED: 2026-05-19
7
- //
8
- // SECURITY NOTE — tenant_id:
9
- // tenant_id is resolved from the injected ITenantContext (or equivalent auth accessor),
10
- // NEVER from a tool parameter visible to the LLM. A model-facing tenant parameter would
11
- // allow prompt-injection to cross tenant boundaries.
12
- //
13
- // NPGSQL + PGVECTOR PARAMETER BINDING:
14
- // This template uses NpgsqlDataSource (raw SQL) for the cosine-distance query.
15
- // The project must call dataSourceBuilder.UseVector() before building the data source
16
- // so Npgsql can map the vector type — see infrastructure-neon-pgvector.
17
- //
18
- // // VERIFY: The exact Npgsql parameter binding for a pgvector type has been written
19
- // // conservatively below using new Pgvector.Vector(float[]).
20
- // // Confirmed pattern from neon-pgvector standard (Pgvector package):
21
- // // cmd.Parameters.AddWithValue("queryVec", new Pgvector.Vector(embedding.ToArray()));
22
- // // If the project uses a different Npgsql/Pgvector version, verify the parameter API.
23
- //
24
- // REGISTRATION (in agent setup code):
25
- // var tool = sp.GetRequiredService<VectorSearchTool>();
26
- // var agent = modelRegistry.GetChatClient("text-default")
27
- // .AsAIAgent(
28
- // instructions: systemPrompt,
29
- // tools: [AIFunctionFactory.Create(tool.SearchAsync)]);
30
- //
31
- // ALTERNATIVE — EF Core:
32
- // If the project already wires pgvector through EF Core (UseVector(), HasMethod("hnsw")),
33
- // replace the NpgsqlDataSource usage with db.Database.SqlQuery<string>() per
34
- // infrastructure-neon-pgvector. The tool method signature stays identical.
35
-
36
- using System.ComponentModel;
37
- using Npgsql;
38
- using Pgvector;
39
-
40
- namespace {{PROJECT_NAMESPACE}}.AI;
41
-
42
- /// <summary>
43
- /// MAF tool: searches the knowledge base for chunks semantically similar to a query.
44
- /// Registered on an agent via <c>AIFunctionFactory.Create(tool.SearchAsync)</c>.
45
- /// The agent calls this autonomously when it needs grounding context.
46
- /// </summary>
47
- public sealed class VectorSearchTool(
48
- EmbeddingService embeddingService,
49
- NpgsqlDataSource dataSource,
50
- ITenantContext tenantContext) // Resolved from DI — scoped to the authenticated request.
51
- // Replace with Guid currentTenantId if a simpler accessor is preferred.
52
- {
53
- private const int DefaultTopK = 5;
54
-
55
- /// <summary>
56
- /// Searches the knowledge base for context relevant to a question.
57
- /// </summary>
58
- /// <param name="query">The natural-language search query.</param>
59
- /// <param name="ct">Cancellation token.</param>
60
- /// <returns>
61
- /// Concatenated text of the top matching chunks, separated by double newlines.
62
- /// Returns an empty string if no results are found.
63
- /// </returns>
64
- [Description("Searches the knowledge base for context relevant to a question")]
65
- public async Task<string> SearchAsync(
66
- [Description("the natural-language search query")] string query,
67
- CancellationToken ct = default)
68
- {
69
- // 1. Embed the query at search time.
70
- ReadOnlyMemory<float> queryVector = await embeddingService.EmbedAsync(query, ct);
71
-
72
- // 2. Resolve tenant from auth context — never from a model-supplied parameter.
73
- Guid tenantId = tenantContext.CurrentTenantId;
74
-
75
- // 3. Run parameterized cosine-distance query.
76
- // ORDER BY embedding <=> @queryVec sorts ascending by distance (most similar first).
77
- const string sql = """
78
- SELECT content
79
- FROM kb_embeddings
80
- WHERE tenant_id = @tenant
81
- ORDER BY embedding <=> @queryVec
82
- LIMIT @topK
83
- """;
84
-
85
- var chunks = new List<string>(DefaultTopK);
86
-
87
- await using var conn = await dataSource.OpenConnectionAsync(ct);
88
- await using var cmd = new NpgsqlCommand(sql, conn);
89
-
90
- cmd.Parameters.AddWithValue("tenant", tenantId);
91
-
92
- // VERIFY: Pgvector.Vector wraps a float[] for Npgsql parameter binding.
93
- // The project must have called dataSourceBuilder.UseVector() on NpgsqlDataSourceBuilder.
94
- // NuGet: Pgvector (matches the Pgvector.EntityFrameworkCore used in neon-pgvector.md).
95
- cmd.Parameters.AddWithValue("queryVec", new Vector(queryVector.ToArray()));
96
-
97
- cmd.Parameters.AddWithValue("topK", DefaultTopK);
98
-
99
- await using var reader = await cmd.ExecuteReaderAsync(ct);
100
- while (await reader.ReadAsync(ct))
101
- {
102
- chunks.Add(reader.GetString(0));
103
- }
104
-
105
- return string.Join("\n\n", chunks);
106
- }
107
- }
1
+ // READS STANDARD: ai-agents-rag-custom-pgvector
2
+
3
+ using System.ComponentModel;
4
+ using Npgsql;
5
+ using Pgvector;
6
+
7
+ namespace {{PROJECT_NAMESPACE}}.AI;
8
+
9
+ public sealed class VectorSearchTool(
10
+ EmbeddingService embeddingService,
11
+ NpgsqlDataSource dataSource,
12
+ ITenantContext tenantContext)
13
+ {
14
+ private const int DefaultTopK = 5;
15
+
16
+ [Description("Searches the knowledge base for context relevant to a question")]
17
+ public async Task<string> SearchAsync(
18
+ [Description("the natural-language search query")] string query,
19
+ CancellationToken ct = default)
20
+ {
21
+ ReadOnlyMemory<float> queryVector = await embeddingService.EmbedAsync(query, ct);
22
+
23
+ // Tenant comes from auth, never a tool parameter: the model could be prompt-injected into another tenant.
24
+ Guid tenantId = tenantContext.CurrentTenantId;
25
+
26
+ const string sql = """
27
+ SELECT content
28
+ FROM kb_embeddings
29
+ WHERE tenant_id = @tenant
30
+ ORDER BY embedding <=> @queryVec
31
+ LIMIT @topK
32
+ """;
33
+
34
+ var chunks = new List<string>(DefaultTopK);
35
+
36
+ await using var conn = await dataSource.OpenConnectionAsync(ct);
37
+ await using var cmd = new NpgsqlCommand(sql, conn);
38
+
39
+ cmd.Parameters.AddWithValue("tenant", tenantId);
40
+
41
+ // VERIFY: binding Pgvector.Vector needs dataSourceBuilder.UseVector(); confirm against the project's Npgsql/Pgvector versions.
42
+ cmd.Parameters.AddWithValue("queryVec", new Vector(queryVector.ToArray()));
43
+
44
+ cmd.Parameters.AddWithValue("topK", DefaultTopK);
45
+
46
+ await using var reader = await cmd.ExecuteReaderAsync(ct);
47
+ while (await reader.ReadAsync(ct))
48
+ {
49
+ chunks.Add(reader.GetString(0));
50
+ }
51
+
52
+ return string.Join("\n\n", chunks);
53
+ }
54
+ }
@@ -1,58 +1,53 @@
1
- // TEMPLATE: model-registry.json (place in project at config/model-registry.json)
2
- // PURPOSE: Single source of truth for model selection. Agents reference aliases, not models.
3
- // READS STANDARD: ai-agents-providers-model-registry
4
- // PROVIDERS: openai + ollama work out-of-the-box with the ModelRegistry template.
5
- // For google / anthropic, add a provider branch first (see the standard).
6
- // PLACEHOLDERS:
7
- // {{PROJECT_DEFAULT_ALIAS}} — alias used when none specified (default: "text-default")
8
- // LAST-VERIFIED: 2026-05-19
9
- {
10
- "$schema": "./model-registry.schema.json",
11
- "version": "1.0",
12
- "defaultAlias": "{{PROJECT_DEFAULT_ALIAS}}",
13
- "aliases": {
14
- "text-default": {
15
- "provider": "openai",
16
- "model": "gpt-4o-mini",
17
- "options": { "temperature": 0.7 }
18
- },
19
- "text-heavy": {
20
- "provider": "openai",
21
- "model": "gpt-4o",
22
- "options": { "temperature": 0.5 }
23
- },
24
- "reasoning": {
25
- "provider": "openai",
26
- "model": "o3-mini",
27
- "options": { "reasoningEffort": "medium" }
28
- },
29
- "long-form": {
30
- "provider": "anthropic",
31
- "model": "claude-sonnet-4-6",
32
- "options": {}
33
- },
34
- "vision": {
35
- "provider": "google",
36
- "model": "gemini-2.5-flash",
37
- "options": {}
38
- },
39
- "embeddings": {
40
- "provider": "openai",
41
- "model": "text-embedding-3-small",
42
- "options": { "dimensions": 1536 }
43
- },
44
- "local-dev": {
45
- "provider": "ollama",
46
- "model": "llama3.2:3b",
47
- "options": { "endpoint": "http://localhost:11434/v1" }
48
- },
49
- "transcription": {
50
- "provider": "openai",
51
- "model": "whisper-1",
52
- "options": {}
53
- }
54
- },
55
- "fallback": {
56
- "text-default": "ollama/llama3.2:3b"
57
- }
58
- }
1
+ // READS STANDARD: ai-agents-providers-model-registry
2
+ // Goes in config/model-registry.json. ModelRegistry only builds openai and ollama:
3
+ // the anthropic and google aliases throw until a provider branch is added there.
4
+ {
5
+ "$schema": "./model-registry.schema.json",
6
+ "version": "1.0",
7
+ "defaultAlias": "{{PROJECT_DEFAULT_ALIAS}}",
8
+ "aliases": {
9
+ "text-default": {
10
+ "provider": "openai",
11
+ "model": "gpt-4o-mini",
12
+ "options": { "temperature": 0.7 }
13
+ },
14
+ "text-heavy": {
15
+ "provider": "openai",
16
+ "model": "gpt-4o",
17
+ "options": { "temperature": 0.5 }
18
+ },
19
+ "reasoning": {
20
+ "provider": "openai",
21
+ "model": "o3-mini",
22
+ "options": { "reasoningEffort": "medium" }
23
+ },
24
+ "long-form": {
25
+ "provider": "anthropic",
26
+ "model": "claude-sonnet-4-6",
27
+ "options": {}
28
+ },
29
+ "vision": {
30
+ "provider": "google",
31
+ "model": "gemini-2.5-flash",
32
+ "options": {}
33
+ },
34
+ "embeddings": {
35
+ "provider": "openai",
36
+ "model": "text-embedding-3-small",
37
+ "options": { "dimensions": 1536 }
38
+ },
39
+ "local-dev": {
40
+ "provider": "ollama",
41
+ "model": "llama3.2:3b",
42
+ "options": { "endpoint": "http://localhost:11434/v1" }
43
+ },
44
+ "transcription": {
45
+ "provider": "openai",
46
+ "model": "whisper-1",
47
+ "options": {}
48
+ }
49
+ },
50
+ "fallback": {
51
+ "text-default": "ollama/llama3.2:3b"
52
+ }
53
+ }