@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.
- package/CLAUDE.md +19 -8
- package/README.md +2 -2
- package/bin/morph-spec.js +60 -43
- package/claude-plugin.json +1 -1
- package/docs/CHEATSHEET.md +1 -1
- package/docs/QUICKSTART.md +1 -1
- package/framework/CLAUDE.md +3 -2
- package/framework/MORPH.md +1 -1
- package/framework/agents.json +36 -25
- package/framework/docs/CLI.md +2 -2
- package/framework/evals/rubrics/code-quality.md +4 -4
- package/framework/evals/rubrics/condensed.md +2 -2
- package/framework/mcp/registry.json +33 -2
- package/framework/rules/infrastructure-standards.md +0 -1
- package/framework/rules/morph-workflow.md +9 -4
- package/framework/skills/core/create-umbraco-lp/SKILL.md +1 -1
- package/framework/skills/core/migrate-lp-to-umbraco/SKILL.md +1 -1
- package/framework/skills/core/morph-apply/SKILL.md +5 -1
- package/framework/skills/core/morph-brainstorming/SKILL.md +1 -1
- package/framework/skills/core/morph-eval/SKILL.md +1 -1
- package/framework/skills/core/morph-hotfix/SKILL.md +1 -1
- package/framework/skills/core/morph-implement/SKILL.md +6 -1
- package/framework/skills/core/morph-media/SKILL.md +1 -1
- package/framework/skills/core/morph-plan/SKILL.md +4 -3
- package/framework/skills/core/morph-proposal/SKILL.md +1 -1
- package/framework/skills/core/morph-review/SKILL.md +1 -1
- package/framework/skills/core/morph-stack-scan/SKILL.md +1 -1
- package/framework/skills/core/morph-standards/SKILL.md +1 -1
- package/framework/skills/core/morph-uiux/SKILL.md +6 -5
- package/framework/standards/STANDARDS.json +3 -3
- package/framework/standards/ai-agents/context-providers.md +16 -26
- package/framework/standards/ai-agents/durable-workflows-hitl.md +15 -21
- package/framework/standards/ai-agents/modalities-image-gen.md +21 -25
- package/framework/standards/ai-agents/modalities-speech-to-text.md +4 -15
- package/framework/standards/ai-agents/modalities-text-to-speech.md +2 -11
- package/framework/standards/ai-agents/modalities-vision.md +1 -18
- package/framework/standards/ai-agents/prompt-sources.md +0 -4
- package/framework/standards/architecture/code-comments.md +52 -16
- package/framework/standards/backend/integrations/neon-auth/neon-auth.md +63 -50
- package/framework/standards/frontend/design-system/ai-image-generation.md +5 -5
- package/framework/standards/integration/mcp/mcp-tools.md +48 -117
- package/framework/templates/code/dotnet/abstractions/result.cs +0 -2
- package/framework/templates/code/dotnet/ai-agents/AgentBootstrap.cs.template +26 -39
- package/framework/templates/code/dotnet/ai-agents/EmbeddingService.cs.template +28 -68
- package/framework/templates/code/dotnet/ai-agents/ModelRegistry.cs.template +99 -117
- package/framework/templates/code/dotnet/ai-agents/PromptRepository.cs.template +2 -44
- package/framework/templates/code/dotnet/ai-agents/ResilientToolMiddleware.cs.template +40 -61
- package/framework/templates/code/dotnet/ai-agents/VectorSearchTool.cs.template +54 -107
- package/framework/templates/code/dotnet/ai-agents/model-registry.json.template +53 -58
- package/framework/templates/code/dotnet/contracts/contracts-vsa.cs +192 -281
- package/framework/templates/code/dotnet/database/migration.cs +49 -83
- package/framework/templates/code/dotnet/database/vector-entity.cs +2 -46
- package/framework/templates/code/dotnet/extensions/result-extensions.cs +0 -2
- package/framework/templates/code/dotnet/feature/validator.cs.hbs +11 -15
- package/framework/templates/code/dotnet/jobs/agent.cs +3 -51
- package/framework/templates/code/dotnet/jobs/job.cs +2 -97
- package/framework/templates/code/dotnet/test.cs +2 -87
- package/framework/templates/code/typescript/contracts.ts +140 -167
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentApi.cs +1 -48
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentFactory.cs +3 -79
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentFactoryOptions.cs +1 -70
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentSpec.cs +1 -47
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Agents/AgentSpecOptions.cs +2 -99
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/AiKitAssemblyMarker.cs +0 -6
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/ConversationStore.cs +3 -88
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/IConversationStore.cs +1 -41
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Conversation/InMemoryConversationStore.cs +0 -21
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/CountingChatClient.cs +1 -25
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalAssertion.cs +2 -63
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheMissException.cs +0 -30
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheOptions.cs +1 -52
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalCacheStamp.cs +3 -78
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalFixture.cs +4 -109
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalMode.cs +0 -22
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalQualityEvaluators.cs +1 -36
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalScenario.cs +2 -57
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/EvalSummary.cs +0 -75
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/OfflineChatClient.cs +2 -59
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Evals/ShortPathResponseCache.cs +4 -111
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/IMediaGenerator.cs +0 -34
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/IMediaProvider.cs +1 -57
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaArtifact.cs +0 -19
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaDisclosure.cs +2 -74
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaGenerator.cs +2 -33
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaIdempotencyKey.cs +1 -43
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJob.cs +1 -96
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJobId.cs +0 -13
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaJobState.cs +0 -27
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaPricing.cs +0 -33
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaProvenance.cs +0 -31
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaRequest.cs +3 -75
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaResult.cs +0 -42
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaReview.cs +0 -39
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaSeams.cs +1 -55
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MediaStore.cs +3 -59
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/MorphMedia.cs +0 -46
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/GoogleImageProvider.cs +3 -28
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/OpenAIImageProvider.cs +7 -61
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Media/Providers/VeoVideoProvider.cs +2 -37
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/IUsageCostSink.cs +1 -23
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/UsageCostMiddleware.cs +2 -82
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Middleware/UsageCostRecord.cs +1 -68
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Observability/MorphOpenTelemetryExtensions.cs +1 -62
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Observability/MorphTelemetryOptions.cs +2 -62
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/IProviderClientFactory.cs +1 -25
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/ModelAlias.cs +0 -124
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Providers/ModelRegistry.cs +1 -73
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Rag/DeltaIngest.cs +1 -66
- package/framework/templates/dotnet/ai-kit/src/Morph.AiKit/Rag/DeltaPlan.cs +0 -41
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/AgentFactoryTests.cs +2 -112
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/AgentSpecTests.cs +2 -43
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/ConversationStoreTests.cs +5 -110
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/DeltaIngestTests.cs +7 -103
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalAssertionTests.cs +1 -42
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalCacheMissTests.cs +1 -30
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalCacheStampTests.cs +1 -19
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalFailuresTests.cs +0 -48
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalFixtureTests.cs +1 -29
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalRefreshTests.cs +2 -38
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/EvalWorkspace.cs +1 -14
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/KitEvals.cs +4 -69
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Evals/OfflineChatClientTests.cs +1 -10
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeChatClient.cs +1 -57
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeChatClientTests.cs +0 -26
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeClock.cs +1 -19
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeMediaProvider.cs +0 -32
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeProviderClientFactory.cs +0 -14
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/FakeUsageCostSink.cs +0 -24
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/Fakes/InMemoryMediaStore.cs +0 -32
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaAccessibilityTests.cs +0 -37
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaAliasIsNotAnAgentTests.cs +0 -24
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaDisclosureTests.cs +0 -78
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaGeneratorTests.cs +0 -53
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaIdempotencyKeyTests.cs +0 -44
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaJobStateTests.cs +0 -44
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaReviewTests.cs +0 -19
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/MediaStoreTests.cs +0 -24
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/ModelRegistryTests.cs +6 -48
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/SkeletonSmokeTests.cs +1 -13
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/TelemetryTests.cs +2 -71
- package/framework/templates/dotnet/ai-kit/tests/Morph.AiKit.Tests/UsageCostMiddlewareTests.cs +5 -100
- package/framework/templates/frontend/nextjs/Dockerfile.nextjs.hbs +39 -43
- package/framework/templates/frontend/nextjs/env.mjs.hbs +29 -32
- package/framework/templates/frontend/nextjs/page.tsx.hbs +21 -22
- package/framework/templates/frontend/nextjs/use-feature.ts.hbs +42 -54
- package/framework/templates/integrations/asaas-client.cs +332 -387
- package/framework/templates/integrations/asaas-webhook.cs +290 -351
- package/framework/templates/integrations/neon-auth-config.cs +9 -105
- package/framework/templates/project/validate.js +97 -120
- package/package.json +2 -2
- package/src/commands/dashboard/dashboard.js +80 -53
- package/src/commands/mcp/mcp-setup.js +37 -9
- package/src/commands/project/doctor.js +3 -5
- package/src/commands/project/init.js +6 -3
- package/src/commands/project/install-plugin-cmd.js +1 -1
- package/src/commands/project/update.js +5 -0
- package/src/dashboard/app/App.jsx +80 -16
- package/src/dashboard/app/components/ActivityFeed.jsx +172 -0
- package/src/dashboard/app/components/CommandPalette.jsx +155 -0
- package/src/dashboard/app/components/DetailPanel.jsx +47 -11
- package/src/dashboard/app/components/EntityLink.jsx +55 -0
- package/src/dashboard/app/components/ErrorBoundary.jsx +54 -0
- package/src/dashboard/app/components/FlowGraph.jsx +19 -17
- package/src/dashboard/app/components/KnowledgeMarkdown.jsx +53 -0
- package/src/dashboard/app/components/Markdown.jsx +47 -0
- package/src/dashboard/app/components/PhaseRail.jsx +111 -0
- package/src/dashboard/app/components/SearchFilter.jsx +40 -22
- package/src/dashboard/app/components/Sidebar.jsx +146 -37
- package/src/dashboard/app/hooks/useMorphQuery.js +54 -0
- package/src/dashboard/app/hooks/usePref.js +38 -0
- package/src/dashboard/app/lib/format.js +69 -0
- package/src/dashboard/app/lib/phases.js +56 -0
- package/src/dashboard/app/lib/project.js +50 -0
- package/src/dashboard/app/pages/Activity.jsx +24 -0
- package/src/dashboard/app/pages/AgentMap.jsx +371 -370
- package/src/dashboard/app/pages/FeatureDetail.jsx +604 -0
- package/src/dashboard/app/pages/Features.jsx +400 -0
- package/src/dashboard/app/pages/Guide.jsx +146 -0
- package/src/dashboard/app/pages/HookInspector.jsx +357 -322
- package/src/dashboard/app/pages/PhasePipeline.jsx +277 -408
- package/src/dashboard/app/pages/Portfolio.jsx +156 -0
- package/src/dashboard/app/pages/Rubrics.jsx +101 -0
- package/src/dashboard/app/pages/RulesMap.jsx +300 -273
- package/src/dashboard/app/pages/SkillsLibrary.jsx +483 -366
- package/src/dashboard/app/pages/Standards.jsx +407 -332
- package/src/dashboard/app/styles/index.css +187 -47
- package/src/dashboard/index.html +14 -12
- package/src/dashboard/package.json +32 -24
- package/src/dashboard/scanner/activity-scanner.js +351 -0
- package/src/dashboard/scanner/agents-scanner.js +59 -1
- package/src/dashboard/scanner/docs-scanner.js +59 -0
- package/src/dashboard/scanner/feature-status.js +10 -0
- package/src/dashboard/scanner/features-scanner.js +360 -0
- package/src/dashboard/scanner/index.js +14 -7
- package/src/dashboard/scanner/phases-scanner.js +14 -15
- package/src/dashboard/scanner/portfolio.js +153 -0
- package/src/dashboard/scanner/project-api.js +195 -0
- package/src/dashboard/scanner/rules-scanner.js +42 -37
- package/src/dashboard/scanner/skills-scanner.js +105 -43
- package/src/dashboard/scanner/standards-scanner.js +2 -0
- package/src/dashboard/vite-plugin-morph-data.js +134 -17
- package/src/lib/detectors/claude-config-detector.js +2 -7
- package/src/lib/detectors/index.js +5 -1
- package/src/lib/evaluator-report.js +22 -0
- package/src/lib/generators/settings-generator.js +208 -209
- package/src/lib/installers/mcp-installer.js +724 -719
- package/src/lib/installers/memory-installer.js +1 -2
- package/src/lib/projects/registry.js +154 -0
- package/src/lib/validators/code-budget/code-budget-validator.js +32 -4
- package/src/scripts/install-plugin.js +1 -1
- package/src/scripts/setup-infra.js +2 -4
- package/src/utils/agents-installer.js +57 -12
- package/src/utils/banner.js +1 -1
- package/src/commands/index.js +0 -13
- package/src/commands/project/checkpoint.js +0 -209
- package/src/core/state/phase-state-machine.js +0 -197
- package/src/dashboard/app/hooks/useDetailPanel.js +0 -15
- package/src/dashboard/app/pages/LiveState.jsx +0 -206
- package/src/dashboard/scanner/squads-scanner.js +0 -13
- package/src/dashboard/scanner/state-scanner.js +0 -85
- package/src/lib/generators/index.js +0 -10
- package/src/lib/hooks/hook-executor.js +0 -167
- package/src/lib/validators/checkpoint-persistence.js +0 -39
- package/src/lib/validators/shared/emit-validator-dispatch.js +0 -14
- package/src/lib/validators/shared/index.js +0 -12
- package/src/lib/validators/shared/issue-counter.js +0 -14
- package/src/lib/validators/shared/result-formatter.js +0 -124
|
@@ -63,10 +63,8 @@ namespace {{pascalCase PROJECT_NAME}}.Abstractions
|
|
|
63
63
|
? _value!
|
|
64
64
|
: throw new InvalidOperationException("The value of a failure result can not be accessed.");
|
|
65
65
|
|
|
66
|
-
// ✅ SUCCESS implicit conversion
|
|
67
66
|
public static implicit operator Result<TValue>(TValue? value) => Create(value);
|
|
68
67
|
|
|
69
|
-
// ✅ ADD THIS (Failure implicit conversion)
|
|
70
68
|
public static implicit operator Result<TValue>(Error error)
|
|
71
69
|
=> Failure<TValue>(error);
|
|
72
70
|
}
|
|
@@ -1,39 +1,26 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
// Default agent — uses the default alias from model-registry.json
|
|
28
|
-
builder.Services.AddKeyedSingleton<AIAgent>("{{DEFAULT_AGENT_NAME}}", (sp, _) =>
|
|
29
|
-
{
|
|
30
|
-
var registry = sp.GetRequiredService<ModelRegistry>();
|
|
31
|
-
var chatClient = registry.GetChatClient(registry.DefaultAlias);
|
|
32
|
-
return chatClient.AsAIAgent(
|
|
33
|
-
instructions: "{{DEFAULT_INSTRUCTIONS}}",
|
|
34
|
-
name: "{{DEFAULT_AGENT_NAME}}");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return builder;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
// READS STANDARDS: ai-agents-setup, ai-agents-providers-model-registry
|
|
2
|
+
|
|
3
|
+
using Microsoft.Agents.AI;
|
|
4
|
+
using Microsoft.Extensions.AI;
|
|
5
|
+
using Microsoft.Extensions.DependencyInjection;
|
|
6
|
+
|
|
7
|
+
namespace {{PROJECT_NAMESPACE}}.AI;
|
|
8
|
+
|
|
9
|
+
public static class AgentBootstrap
|
|
10
|
+
{
|
|
11
|
+
public static WebApplicationBuilder AddMafAgents(this WebApplicationBuilder builder)
|
|
12
|
+
{
|
|
13
|
+
builder.Services.AddSingleton<ModelRegistry>();
|
|
14
|
+
|
|
15
|
+
builder.Services.AddKeyedSingleton<AIAgent>("{{DEFAULT_AGENT_NAME}}", (sp, _) =>
|
|
16
|
+
{
|
|
17
|
+
var registry = sp.GetRequiredService<ModelRegistry>();
|
|
18
|
+
var chatClient = registry.GetChatClient(registry.DefaultAlias);
|
|
19
|
+
return chatClient.AsAIAgent(
|
|
20
|
+
instructions: "{{DEFAULT_INSTRUCTIONS}}",
|
|
21
|
+
name: "{{DEFAULT_AGENT_NAME}}");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return builder;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,68 +1,28 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/// Wraps <see cref="IEmbeddingGenerator{TInput,TEmbedding}"/> so the rest of the project
|
|
30
|
-
/// does not take a direct dependency on the underlying provider SDK.
|
|
31
|
-
/// </summary>
|
|
32
|
-
public sealed class EmbeddingService(IEmbeddingGenerator<string, Embedding<float>> generator)
|
|
33
|
-
{
|
|
34
|
-
/// <summary>
|
|
35
|
-
/// Generates an embedding vector for a single text (used at query time).
|
|
36
|
-
/// </summary>
|
|
37
|
-
/// <param name="text">The text to embed.</param>
|
|
38
|
-
/// <param name="ct">Cancellation token.</param>
|
|
39
|
-
/// <returns>The embedding vector as <see cref="ReadOnlyMemory{T}"/> of float.</returns>
|
|
40
|
-
public async Task<ReadOnlyMemory<float>> EmbedAsync(
|
|
41
|
-
string text,
|
|
42
|
-
CancellationToken ct = default)
|
|
43
|
-
{
|
|
44
|
-
// GenerateAsync is the verified API: returns GeneratedEmbeddings<Embedding<float>>.
|
|
45
|
-
// Each Embedding<float>.Vector is a ReadOnlyMemory<float>.
|
|
46
|
-
// Source: Microsoft Learn — microsoft-extensions-ai (verified 2026-05-19).
|
|
47
|
-
GeneratedEmbeddings<Embedding<float>> result =
|
|
48
|
-
await generator.GenerateAsync([text], cancellationToken: ct);
|
|
49
|
-
|
|
50
|
-
return result[0].Vector;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/// <summary>
|
|
54
|
-
/// Generates embedding vectors for a batch of texts (used during document indexing).
|
|
55
|
-
/// </summary>
|
|
56
|
-
/// <param name="texts">The texts to embed.</param>
|
|
57
|
-
/// <param name="ct">Cancellation token.</param>
|
|
58
|
-
/// <returns>Embedding vectors in the same order as the input texts.</returns>
|
|
59
|
-
public async Task<IReadOnlyList<ReadOnlyMemory<float>>> EmbedBatchAsync(
|
|
60
|
-
IReadOnlyList<string> texts,
|
|
61
|
-
CancellationToken ct = default)
|
|
62
|
-
{
|
|
63
|
-
GeneratedEmbeddings<Embedding<float>> result =
|
|
64
|
-
await generator.GenerateAsync(texts, cancellationToken: ct);
|
|
65
|
-
|
|
66
|
-
return [.. result.Select(e => e.Vector)];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
1
|
+
// READS STANDARD: ai-agents-rag-custom-pgvector
|
|
2
|
+
|
|
3
|
+
using Microsoft.Extensions.AI;
|
|
4
|
+
|
|
5
|
+
namespace {{PROJECT_NAMESPACE}}.AI;
|
|
6
|
+
|
|
7
|
+
public sealed class EmbeddingService(IEmbeddingGenerator<string, Embedding<float>> generator)
|
|
8
|
+
{
|
|
9
|
+
public async Task<ReadOnlyMemory<float>> EmbedAsync(
|
|
10
|
+
string text,
|
|
11
|
+
CancellationToken ct = default)
|
|
12
|
+
{
|
|
13
|
+
GeneratedEmbeddings<Embedding<float>> result =
|
|
14
|
+
await generator.GenerateAsync([text], cancellationToken: ct);
|
|
15
|
+
|
|
16
|
+
return result[0].Vector;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public async Task<IReadOnlyList<ReadOnlyMemory<float>>> EmbedBatchAsync(
|
|
20
|
+
IReadOnlyList<string> texts,
|
|
21
|
+
CancellationToken ct = default)
|
|
22
|
+
{
|
|
23
|
+
GeneratedEmbeddings<Embedding<float>> result =
|
|
24
|
+
await generator.GenerateAsync(texts, cancellationToken: ct);
|
|
25
|
+
|
|
26
|
+
return [.. result.Select(e => e.Vector)];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,117 +1,99 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
AllowTrailingCommas = true
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// NOTE: Fallback is parsed but not yet acted on. Implementing automatic
|
|
104
|
-
// provider failover (retry on rate-limit/outage) is reserved for a later wave.
|
|
105
|
-
private sealed record RegistryDocument(
|
|
106
|
-
string Version,
|
|
107
|
-
string DefaultAlias,
|
|
108
|
-
Dictionary<string, ModelAlias> Aliases,
|
|
109
|
-
Dictionary<string, string>? Fallback
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
public sealed record ModelAlias(
|
|
113
|
-
string Provider,
|
|
114
|
-
string Model,
|
|
115
|
-
Dictionary<string, object>? Options
|
|
116
|
-
);
|
|
117
|
-
}
|
|
1
|
+
// READS STANDARD: ai-agents-providers-model-registry
|
|
2
|
+
|
|
3
|
+
using System.ClientModel;
|
|
4
|
+
using System.Text.Json;
|
|
5
|
+
using Microsoft.Extensions.AI;
|
|
6
|
+
using Microsoft.Extensions.Configuration;
|
|
7
|
+
using Microsoft.Extensions.Hosting;
|
|
8
|
+
using OpenAI;
|
|
9
|
+
using OpenAI.Chat;
|
|
10
|
+
|
|
11
|
+
namespace {{PROJECT_NAMESPACE}}.AI;
|
|
12
|
+
|
|
13
|
+
public sealed class ModelRegistry
|
|
14
|
+
{
|
|
15
|
+
private readonly Dictionary<string, ModelAlias> _aliases;
|
|
16
|
+
private readonly Dictionary<string, IChatClient> _chatClientCache = new();
|
|
17
|
+
private readonly IConfiguration _config;
|
|
18
|
+
private readonly object _lock = new();
|
|
19
|
+
|
|
20
|
+
public ModelRegistry(IConfiguration config, IHostEnvironment env)
|
|
21
|
+
{
|
|
22
|
+
_config = config;
|
|
23
|
+
var path = Path.Combine(env.ContentRootPath, "{{REGISTRY_PATH}}");
|
|
24
|
+
if (!File.Exists(path))
|
|
25
|
+
throw new InvalidOperationException($"Model registry not found at {path}");
|
|
26
|
+
|
|
27
|
+
var json = File.ReadAllText(path);
|
|
28
|
+
var doc = JsonSerializer.Deserialize<RegistryDocument>(json, JsonOpts)
|
|
29
|
+
?? throw new InvalidOperationException("Empty model-registry.json");
|
|
30
|
+
_aliases = doc.Aliases;
|
|
31
|
+
DefaultAlias = doc.DefaultAlias;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public string DefaultAlias { get; }
|
|
35
|
+
|
|
36
|
+
public IChatClient GetChatClient(string alias)
|
|
37
|
+
{
|
|
38
|
+
if (!_aliases.TryGetValue(alias, out var spec))
|
|
39
|
+
throw new InvalidOperationException($"Unknown model alias: {alias}");
|
|
40
|
+
|
|
41
|
+
lock (_lock)
|
|
42
|
+
{
|
|
43
|
+
if (_chatClientCache.TryGetValue(alias, out var cached))
|
|
44
|
+
return cached;
|
|
45
|
+
|
|
46
|
+
var client = spec.Provider switch
|
|
47
|
+
{
|
|
48
|
+
"openai" => BuildOpenAI(spec),
|
|
49
|
+
"ollama" => BuildOllama(spec),
|
|
50
|
+
_ => throw new NotSupportedException(
|
|
51
|
+
$"Provider '{spec.Provider}' has no branch. Add it following " +
|
|
52
|
+
$"the pattern in ai-agents-providers-model-registry.")
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
_chatClientCache[alias] = client;
|
|
56
|
+
return client;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private IChatClient BuildOpenAI(ModelAlias spec)
|
|
61
|
+
{
|
|
62
|
+
var apiKey = _config["OpenAI:ApiKey"]
|
|
63
|
+
?? throw new InvalidOperationException("OpenAI:ApiKey not configured");
|
|
64
|
+
return new ChatClient(spec.Model, apiKey).AsIChatClient();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private IChatClient BuildOllama(ModelAlias spec)
|
|
68
|
+
{
|
|
69
|
+
var endpoint = spec.Options?.GetValueOrDefault("endpoint")?.ToString()
|
|
70
|
+
?? "http://localhost:11434/v1";
|
|
71
|
+
// Ollama speaks the OpenAI protocol and ignores the key, but the SDK rejects an empty one.
|
|
72
|
+
return new ChatClient(
|
|
73
|
+
spec.Model,
|
|
74
|
+
new ApiKeyCredential("ollama"),
|
|
75
|
+
new OpenAIClientOptions { Endpoint = new Uri(endpoint) })
|
|
76
|
+
.AsIChatClient();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private static readonly JsonSerializerOptions JsonOpts = new()
|
|
80
|
+
{
|
|
81
|
+
PropertyNameCaseInsensitive = true,
|
|
82
|
+
ReadCommentHandling = JsonCommentHandling.Skip,
|
|
83
|
+
AllowTrailingCommas = true
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Fallback is parsed but nothing fails over to it yet.
|
|
87
|
+
private sealed record RegistryDocument(
|
|
88
|
+
string Version,
|
|
89
|
+
string DefaultAlias,
|
|
90
|
+
Dictionary<string, ModelAlias> Aliases,
|
|
91
|
+
Dictionary<string, string>? Fallback
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
public sealed record ModelAlias(
|
|
95
|
+
string Provider,
|
|
96
|
+
string Model,
|
|
97
|
+
Dictionary<string, object>? Options
|
|
98
|
+
);
|
|
99
|
+
}
|
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
// TEMPLATE: PromptRepository.cs
|
|
2
|
-
// PURPOSE: Loads agent system prompts from the agent_prompts table, with in-memory caching.
|
|
3
1
|
// READS STANDARD: ai-agents-prompt-sources
|
|
4
|
-
// PLACEHOLDERS:
|
|
5
|
-
// {{PROJECT_NAMESPACE}} — root namespace of the project
|
|
6
|
-
// LAST-VERIFIED: 2026-05-19
|
|
7
2
|
|
|
8
3
|
using Microsoft.EntityFrameworkCore;
|
|
9
4
|
using Microsoft.Extensions.Caching.Memory;
|
|
10
5
|
|
|
11
6
|
namespace {{PROJECT_NAMESPACE}}.AI;
|
|
12
7
|
|
|
13
|
-
//
|
|
14
|
-
// Entity — map this to the agent_prompts table (EF Core convention mapping).
|
|
15
|
-
// Alternatively, configure via Fluent API in your DbContext.OnModelCreating.
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
|
|
18
|
-
/// <summary>
|
|
19
|
-
/// EF Core entity for the agent_prompts table.
|
|
20
|
-
/// Content is immutable once written — use INSERT + flip is_active for versioning.
|
|
21
|
-
/// </summary>
|
|
8
|
+
// Rows are never updated: a new version is an INSERT plus flipping is_active.
|
|
22
9
|
public sealed class AgentPrompt
|
|
23
10
|
{
|
|
24
11
|
public Guid Id { get; init; } = Guid.CreateVersion7();
|
|
@@ -29,41 +16,12 @@ public sealed class AgentPrompt
|
|
|
29
16
|
public DateTimeOffset CreatedAt { get; init; } = DateTimeOffset.UtcNow;
|
|
30
17
|
}
|
|
31
18
|
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
// Interface
|
|
34
|
-
// ---------------------------------------------------------------------------
|
|
35
|
-
|
|
36
|
-
/// <summary>
|
|
37
|
-
/// Provides the active system-prompt content for a named agent.
|
|
38
|
-
/// </summary>
|
|
39
19
|
public interface IPromptRepository
|
|
40
20
|
{
|
|
41
|
-
/// <summary>
|
|
42
|
-
/// Returns the content of the currently active prompt for <paramref name="agentKey"/>.
|
|
43
|
-
/// </summary>
|
|
44
|
-
/// <exception cref="InvalidOperationException">
|
|
45
|
-
/// Thrown when no row with <c>is_active = true</c> exists for <paramref name="agentKey"/>.
|
|
46
|
-
/// </exception>
|
|
47
21
|
Task<string> GetActivePromptAsync(string agentKey, CancellationToken ct = default);
|
|
48
22
|
}
|
|
49
23
|
|
|
50
|
-
//
|
|
51
|
-
// Implementation
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
|
|
54
|
-
// NOTE: Register in Program.cs (or a bootstrap extension):
|
|
55
|
-
// builder.Services.AddMemoryCache();
|
|
56
|
-
// builder.Services.AddScoped<IPromptRepository, PromptRepository>();
|
|
57
|
-
//
|
|
58
|
-
// The DbContext must expose: public DbSet<AgentPrompt> AgentPrompts { get; set; }
|
|
59
|
-
// Replace YourDbContext below with the actual DbContext type of the project.
|
|
60
|
-
|
|
61
|
-
/// <summary>
|
|
62
|
-
/// Reads the active agent prompt from the database with an in-memory cache
|
|
63
|
-
/// (default TTL: 5 minutes sliding). Cache invalidation is time-based;
|
|
64
|
-
/// for immediate invalidation after a prompt update call
|
|
65
|
-
/// <c>IMemoryCache.Remove($"agent_prompt:{agentKey}")</c>.
|
|
66
|
-
/// </summary>
|
|
24
|
+
// Replace YourDbContext with the project's DbContext (it needs DbSet<AgentPrompt> AgentPrompts).
|
|
67
25
|
public sealed class PromptRepository(YourDbContext db, IMemoryCache cache) : IPromptRepository
|
|
68
26
|
{
|
|
69
27
|
private static readonly TimeSpan CacheTtl = TimeSpan.FromMinutes(5);
|
|
@@ -1,61 +1,40 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// return $"Descriptive error for '{context.Function.Name}': <what was wrong>.";
|
|
42
|
-
|
|
43
|
-
// ─── Resilience: execute tool and handle failures ───
|
|
44
|
-
try
|
|
45
|
-
{
|
|
46
|
-
return await next(context, cancellationToken);
|
|
47
|
-
}
|
|
48
|
-
catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
|
|
49
|
-
{
|
|
50
|
-
return "Service is temporarily busy. Please try again in a moment.";
|
|
51
|
-
}
|
|
52
|
-
catch (TimeoutException)
|
|
53
|
-
{
|
|
54
|
-
return $"Tool '{context.Function.Name}' timed out. Try a simpler query.";
|
|
55
|
-
}
|
|
56
|
-
catch (Exception ex)
|
|
57
|
-
{
|
|
58
|
-
return $"Error in {context.Function.Name}: {ex.Message}";
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
// READS STANDARD: ai-agents-middleware-patterns
|
|
2
|
+
|
|
3
|
+
using Microsoft.Agents.AI;
|
|
4
|
+
using Microsoft.Extensions.AI;
|
|
5
|
+
|
|
6
|
+
namespace {{PROJECT_NAMESPACE}}.AI;
|
|
7
|
+
|
|
8
|
+
public static class ResilientToolMiddleware
|
|
9
|
+
{
|
|
10
|
+
public static async ValueTask<object?> Handle(
|
|
11
|
+
AIAgent agent,
|
|
12
|
+
FunctionInvocationContext context,
|
|
13
|
+
Func<FunctionInvocationContext, CancellationToken, ValueTask<object?>> next,
|
|
14
|
+
CancellationToken cancellationToken)
|
|
15
|
+
{
|
|
16
|
+
// Return the error as text, not an exception: the agent reads it and fixes the arguments on its next turn.
|
|
17
|
+
if (context.Arguments.TryGetValue("date", out var dateArg)
|
|
18
|
+
&& !DateTime.TryParse(dateArg?.ToString(), out _))
|
|
19
|
+
{
|
|
20
|
+
return $"Invalid date format for '{context.Function.Name}'. Expected ISO 8601 (e.g. 2026-01-31).";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try
|
|
24
|
+
{
|
|
25
|
+
return await next(context, cancellationToken);
|
|
26
|
+
}
|
|
27
|
+
catch (HttpRequestException ex) when (ex.StatusCode == System.Net.HttpStatusCode.TooManyRequests)
|
|
28
|
+
{
|
|
29
|
+
return "Service is temporarily busy. Please try again in a moment.";
|
|
30
|
+
}
|
|
31
|
+
catch (TimeoutException)
|
|
32
|
+
{
|
|
33
|
+
return $"Tool '{context.Function.Name}' timed out. Try a simpler query.";
|
|
34
|
+
}
|
|
35
|
+
catch (Exception ex)
|
|
36
|
+
{
|
|
37
|
+
return $"Error in {context.Function.Name}: {ex.Message}";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|