@lssm/bundle.contractspec-workspace 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217073102
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/dist/_virtual/rolldown_runtime.js +22 -1
- package/dist/adapters/ai.js +82 -1
- package/dist/adapters/factory.js +36 -1
- package/dist/adapters/fs.js +118 -1
- package/dist/adapters/git.js +54 -1
- package/dist/adapters/index.js +7 -1
- package/dist/adapters/logger.js +80 -1
- package/dist/adapters/watcher.js +69 -1
- package/dist/adapters/workspace.js +190 -2
- package/dist/ai/agents/claude-code-agent.js +146 -9
- package/dist/ai/agents/cursor-agent.js +286 -17
- package/dist/ai/agents/index.js +5 -1
- package/dist/ai/agents/openai-codex-agent.js +140 -8
- package/dist/ai/agents/orchestrator.js +142 -1
- package/dist/ai/agents/simple-agent.js +80 -4
- package/dist/ai/client.js +162 -1
- package/dist/ai/index.js +27 -1
- package/dist/ai/prompts/code-generation.js +55 -13
- package/dist/ai/prompts/index.js +12 -1
- package/dist/ai/prompts/spec-creation.js +61 -20
- package/dist/ai/providers.js +40 -1
- package/dist/formatters/index.js +18 -1
- package/dist/formatters/json.js +71 -1
- package/dist/formatters/sarif.js +163 -1
- package/dist/formatters/text.js +208 -2
- package/dist/index.js +81 -1
- package/dist/libs/ai-providers/dist/factory.js +154 -1
- package/dist/libs/ai-providers/dist/index.js +4 -1
- package/dist/libs/ai-providers/dist/legacy.js +72 -1
- package/dist/libs/ai-providers/dist/models.js +287 -1
- package/dist/libs/ai-providers/dist/validation.js +1 -1
- package/dist/libs/contracts/dist/capabilities/openbanking.js +88 -1
- package/dist/libs/contracts/dist/client/index.js +5 -1
- package/dist/libs/contracts/dist/client/react/feature-render.js +2 -1
- package/dist/libs/contracts/dist/client/react/form-render.js +4 -1
- package/dist/libs/contracts/dist/client/react/index.js +4 -1
- package/dist/libs/contracts/dist/contract-registry/index.js +1 -1
- package/dist/libs/contracts/dist/contract-registry/schemas.js +60 -1
- package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +16 -76
- package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -350
- package/dist/libs/contracts/dist/docs/index.js +29 -1
- package/dist/libs/contracts/dist/docs/presentations.js +71 -1
- package/dist/libs/contracts/dist/docs/registry.js +44 -1
- package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -383
- package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -68
- package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -140
- package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -86
- package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -1
- package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +24 -2
- package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +21 -2
- package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -213
- package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +73 -5
- package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -1
- package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -1
- package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +20 -262
- package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -1
- package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +24 -2
- package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +23 -2
- package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +25 -16
- package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -1
- package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +22 -2
- package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +40 -36
- package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -1
- package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +23 -2
- package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +36 -3
- package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -1
- package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +36 -3
- package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -1
- package/dist/libs/contracts/dist/events.js +8 -1
- package/dist/libs/contracts/dist/experiments/evaluator.js +1 -1
- package/dist/libs/contracts/dist/index.js +72 -1
- package/dist/libs/contracts/dist/install.js +2 -1
- package/dist/libs/contracts/dist/integrations/contracts.js +377 -1
- package/dist/libs/contracts/dist/integrations/index.js +18 -1
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/accounts.js +228 -1
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/balances.js +159 -1
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/index.js +3 -1
- package/dist/libs/contracts/dist/integrations/openbanking/contracts/transactions.js +210 -1
- package/dist/libs/contracts/dist/integrations/openbanking/models.js +242 -1
- package/dist/libs/contracts/dist/integrations/openbanking/telemetry.js +13 -1
- package/dist/libs/contracts/dist/integrations/providers/elevenlabs.js +52 -1
- package/dist/libs/contracts/dist/integrations/providers/gcs-storage.js +75 -1
- package/dist/libs/contracts/dist/integrations/providers/gmail.js +87 -1
- package/dist/libs/contracts/dist/integrations/providers/google-calendar.js +66 -1
- package/dist/libs/contracts/dist/integrations/providers/index.js +11 -1
- package/dist/libs/contracts/dist/integrations/providers/mistral.js +68 -1
- package/dist/libs/contracts/dist/integrations/providers/postmark.js +68 -1
- package/dist/libs/contracts/dist/integrations/providers/powens.js +116 -1
- package/dist/libs/contracts/dist/integrations/providers/qdrant.js +73 -1
- package/dist/libs/contracts/dist/integrations/providers/registry.js +10 -1
- package/dist/libs/contracts/dist/integrations/providers/stripe.js +83 -1
- package/dist/libs/contracts/dist/integrations/providers/twilio-sms.js +61 -1
- package/dist/libs/contracts/dist/jsonschema.js +24 -1
- package/dist/libs/contracts/dist/knowledge/contracts.js +306 -1
- package/dist/libs/contracts/dist/knowledge/index.js +7 -1
- package/dist/libs/contracts/dist/knowledge/spaces/email-threads.js +34 -1
- package/dist/libs/contracts/dist/knowledge/spaces/financial-docs.js +34 -1
- package/dist/libs/contracts/dist/knowledge/spaces/financial-overview.js +38 -1
- package/dist/libs/contracts/dist/knowledge/spaces/index.js +6 -1
- package/dist/libs/contracts/dist/knowledge/spaces/product-canon.js +34 -1
- package/dist/libs/contracts/dist/knowledge/spaces/support-faq.js +37 -1
- package/dist/libs/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -1
- package/dist/libs/contracts/dist/llm/exporters.js +352 -4
- package/dist/libs/contracts/dist/llm/index.js +2 -1
- package/dist/libs/contracts/dist/llm/prompts.js +143 -7
- package/dist/libs/contracts/dist/onboarding-base.js +196 -1
- package/dist/libs/contracts/dist/openapi.js +75 -1
- package/dist/libs/contracts/dist/ownership.js +21 -1
- package/dist/libs/contracts/dist/presentations.js +1 -1
- package/dist/libs/contracts/dist/presentations.v2.js +11 -1
- package/dist/libs/contracts/dist/prompt.js +1 -1
- package/dist/libs/contracts/dist/promptRegistry.js +1 -1
- package/dist/libs/contracts/dist/regenerator/index.js +2 -1
- package/dist/libs/contracts/dist/regenerator/service.js +92 -1
- package/dist/libs/contracts/dist/regenerator/utils.js +51 -1
- package/dist/libs/contracts/dist/registry.js +208 -1
- package/dist/libs/contracts/dist/resources.js +1 -1
- package/dist/libs/contracts/dist/schema/dist/EnumType.js +2 -1
- package/dist/libs/contracts/dist/schema/dist/FieldType.js +49 -1
- package/dist/libs/contracts/dist/schema/dist/ScalarTypeEnum.js +236 -1
- package/dist/libs/contracts/dist/schema/dist/SchemaModel.js +34 -1
- package/dist/libs/contracts/dist/schema/dist/entity/defineEntity.js +1 -1
- package/dist/libs/contracts/dist/schema/dist/entity/index.js +2 -1
- package/dist/libs/contracts/dist/schema/dist/entity/types.js +1 -1
- package/dist/libs/contracts/dist/schema/dist/index.js +6 -1
- package/dist/libs/contracts/dist/server/graphql-pothos.js +6 -1
- package/dist/libs/contracts/dist/server/index.js +8 -1
- package/dist/libs/contracts/dist/server/mcp/createMcpServer.js +4 -1
- package/dist/libs/contracts/dist/server/mcp/registerPresentations.js +2 -1
- package/dist/libs/contracts/dist/server/mcp/registerPrompts.js +1 -1
- package/dist/libs/contracts/dist/server/mcp/registerResources.js +2 -1
- package/dist/libs/contracts/dist/server/mcp/registerTools.js +1 -1
- package/dist/libs/contracts/dist/server/provider-mcp.js +1 -1
- package/dist/libs/contracts/dist/server/rest-elysia.js +1 -1
- package/dist/libs/contracts/dist/server/rest-express.js +1 -1
- package/dist/libs/contracts/dist/server/rest-generic.js +1 -1
- package/dist/libs/contracts/dist/server/rest-next-app.js +1 -1
- package/dist/libs/contracts/dist/server/rest-next-pages.js +1 -1
- package/dist/libs/contracts/dist/spec.js +35 -1
- package/dist/libs/contracts/dist/telemetry/index.js +1 -1
- package/dist/libs/contracts/dist/telemetry/tracker.js +1 -1
- package/dist/libs/contracts/dist/tests/index.js +1 -1
- package/dist/libs/contracts/dist/tests/runner.js +150 -1
- package/dist/libs/contracts/dist/workflow/index.js +1 -1
- package/dist/libs/contracts/dist/workflow/runner.js +1 -1
- package/dist/libs/contracts-transformers/dist/common/utils.js +47 -1
- package/dist/libs/contracts-transformers/dist/openapi/exporter.js +1 -1
- package/dist/libs/contracts-transformers/dist/openapi/importer.js +255 -2
- package/dist/libs/contracts-transformers/dist/openapi/index.js +4 -1
- package/dist/libs/contracts-transformers/dist/openapi/parser.js +231 -1
- package/dist/libs/contracts-transformers/dist/openapi/schema-converter.js +201 -4
- package/dist/modules/contractspec-workspace/dist/ai/code-generation.js +50 -13
- package/dist/modules/contractspec-workspace/dist/ai/spec-creation.js +50 -18
- package/dist/modules/contractspec-workspace/dist/analysis/deps/graph.js +84 -2
- package/dist/modules/contractspec-workspace/dist/analysis/deps/parse-imports.js +30 -1
- package/dist/modules/contractspec-workspace/dist/analysis/diff/semantic.js +96 -1
- package/dist/modules/contractspec-workspace/dist/analysis/feature-scan.js +151 -1
- package/dist/modules/contractspec-workspace/dist/analysis/spec-scan.js +344 -1
- package/dist/modules/contractspec-workspace/dist/analysis/validate/spec-structure.js +122 -1
- package/dist/modules/contractspec-workspace/dist/templates/app-config.js +100 -28
- package/dist/modules/contractspec-workspace/dist/templates/data-view.js +41 -27
- package/dist/modules/contractspec-workspace/dist/templates/event.js +28 -14
- package/dist/modules/contractspec-workspace/dist/templates/experiment.js +76 -51
- package/dist/modules/contractspec-workspace/dist/templates/handler.js +49 -17
- package/dist/modules/contractspec-workspace/dist/templates/integration-utils.js +97 -26
- package/dist/modules/contractspec-workspace/dist/templates/integration.js +46 -23
- package/dist/modules/contractspec-workspace/dist/templates/knowledge.js +59 -19
- package/dist/modules/contractspec-workspace/dist/templates/migration.js +49 -26
- package/dist/modules/contractspec-workspace/dist/templates/operation.js +40 -28
- package/dist/modules/contractspec-workspace/dist/templates/presentation.js +45 -20
- package/dist/modules/contractspec-workspace/dist/templates/telemetry.js +73 -53
- package/dist/modules/contractspec-workspace/dist/templates/utils.js +38 -1
- package/dist/modules/contractspec-workspace/dist/templates/workflow-runner.js +12 -6
- package/dist/modules/contractspec-workspace/dist/templates/workflow.js +50 -24
- package/dist/modules/contractspec-workspace/dist/types/generation-types.js +20 -1
- package/dist/services/agent-guide/adapters/claude-code.js +144 -3
- package/dist/services/agent-guide/adapters/cursor-cli.js +135 -3
- package/dist/services/agent-guide/adapters/generic-mcp.js +159 -3
- package/dist/services/agent-guide/adapters/index.js +30 -1
- package/dist/services/agent-guide/agent-guide-service.js +148 -1
- package/dist/services/agent-guide/index.js +5 -1
- package/dist/services/build.js +140 -1
- package/dist/services/ci-check/ci-check-service.js +393 -1
- package/dist/services/ci-check/index.js +2 -1
- package/dist/services/ci-check/types.js +28 -1
- package/dist/services/clean.js +71 -1
- package/dist/services/config.js +76 -1
- package/dist/services/deps.js +62 -1
- package/dist/services/diff.js +33 -1
- package/dist/services/doctor/checks/ai.js +118 -2
- package/dist/services/doctor/checks/cli.js +146 -1
- package/dist/services/doctor/checks/config.js +170 -1
- package/dist/services/doctor/checks/deps.js +180 -1
- package/dist/services/doctor/checks/index.js +6 -1
- package/dist/services/doctor/checks/mcp.js +144 -1
- package/dist/services/doctor/checks/workspace.js +243 -1
- package/dist/services/doctor/doctor-service.js +115 -2
- package/dist/services/doctor/index.js +2 -1
- package/dist/services/doctor/types.js +26 -1
- package/dist/services/implementation/discovery.js +143 -2
- package/dist/services/implementation/index.js +2 -1
- package/dist/services/implementation/resolver.js +223 -1
- package/dist/services/index.js +53 -1
- package/dist/services/integrity-diagram.js +274 -6
- package/dist/services/integrity.js +272 -1
- package/dist/services/list.js +35 -1
- package/dist/services/openapi/export-service.js +51 -2
- package/dist/services/openapi/import-service.js +75 -1
- package/dist/services/openapi/index.js +4 -1
- package/dist/services/openapi/sync-service.js +121 -1
- package/dist/services/openapi/validate-service.js +130 -1
- package/dist/services/regenerator.js +23 -1
- package/dist/services/registry.js +73 -1
- package/dist/services/setup/config-generators.js +113 -26
- package/dist/services/setup/file-merger.js +60 -2
- package/dist/services/setup/index.js +4 -1
- package/dist/services/setup/setup-service.js +95 -1
- package/dist/services/setup/targets/agents-md.js +46 -1
- package/dist/services/setup/targets/cli-config.js +59 -1
- package/dist/services/setup/targets/cursor-rules.js +47 -1
- package/dist/services/setup/targets/mcp-claude.js +59 -1
- package/dist/services/setup/targets/mcp-cursor.js +58 -1
- package/dist/services/setup/targets/vscode-settings.js +62 -1
- package/dist/services/setup/types.js +26 -1
- package/dist/services/sync.js +62 -1
- package/dist/services/test.js +30 -1
- package/dist/services/validate-implementation.js +69 -1
- package/dist/services/validate.js +47 -1
- package/dist/services/verification-cache/adapters/filesystem.js +121 -1
- package/dist/services/verification-cache/adapters/in-memory.js +45 -1
- package/dist/services/verification-cache/adapters/index.js +3 -1
- package/dist/services/verification-cache/adapters/workspace-state.js +90 -1
- package/dist/services/verification-cache/cache-service.js +255 -1
- package/dist/services/verification-cache/index.js +6 -1
- package/dist/services/verification-cache/types.js +15 -1
- package/dist/services/verify/ai-verifier.js +336 -9
- package/dist/services/verify/behavior-verifier.js +185 -1
- package/dist/services/verify/index.js +4 -1
- package/dist/services/verify/structure-verifier.js +195 -2
- package/dist/services/verify/verify-service.js +203 -3
- package/dist/services/watch.js +31 -1
- package/dist/services/workspace-info.js +102 -2
- package/dist/templates/app-config.template.js +101 -28
- package/dist/templates/data-view.template.js +42 -27
- package/dist/templates/event.template.js +29 -14
- package/dist/templates/experiment.template.js +77 -51
- package/dist/templates/handler.template.js +53 -17
- package/dist/templates/index.js +36 -1
- package/dist/templates/integration.template.js +134 -50
- package/dist/templates/knowledge.template.js +62 -21
- package/dist/templates/migration.template.js +50 -26
- package/dist/templates/operation.template.js +44 -28
- package/dist/templates/presentation.template.js +46 -20
- package/dist/templates/telemetry.template.js +74 -53
- package/dist/templates/workflow-runner.template.js +12 -6
- package/dist/templates/workflow.template.js +51 -24
- package/package.json +13 -9
|
@@ -1 +1,231 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { parse } from "yaml";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/contracts-transformers/dist/openapi/parser.js
|
|
4
|
+
/**
|
|
5
|
+
* OpenAPI document parser.
|
|
6
|
+
* Parses OpenAPI 3.x documents from JSON/YAML files or URLs.
|
|
7
|
+
*/
|
|
8
|
+
const HTTP_METHODS = [
|
|
9
|
+
"get",
|
|
10
|
+
"post",
|
|
11
|
+
"put",
|
|
12
|
+
"delete",
|
|
13
|
+
"patch",
|
|
14
|
+
"head",
|
|
15
|
+
"options",
|
|
16
|
+
"trace"
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* Parse an OpenAPI document from a string (JSON or YAML).
|
|
20
|
+
*/
|
|
21
|
+
function parseOpenApiString(content, format = "json") {
|
|
22
|
+
if (format === "yaml") return parse(content);
|
|
23
|
+
return JSON.parse(content);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Detect the format of content (JSON or YAML).
|
|
27
|
+
*/
|
|
28
|
+
function detectFormat(content) {
|
|
29
|
+
const trimmed = content.trim();
|
|
30
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) return "json";
|
|
31
|
+
return "yaml";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Detect OpenAPI version from document.
|
|
35
|
+
*/
|
|
36
|
+
function detectVersion(doc) {
|
|
37
|
+
if (doc.openapi.startsWith("3.1")) return "3.1";
|
|
38
|
+
return "3.0";
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if a value is a reference object.
|
|
42
|
+
*/
|
|
43
|
+
function isReference(obj) {
|
|
44
|
+
return typeof obj === "object" && obj !== null && "$ref" in obj;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolve a $ref reference in the document.
|
|
48
|
+
*/
|
|
49
|
+
function resolveRef(doc, ref) {
|
|
50
|
+
if (!ref.startsWith("#/")) return;
|
|
51
|
+
const path = ref.slice(2).split("/");
|
|
52
|
+
let current = doc;
|
|
53
|
+
for (const part of path) {
|
|
54
|
+
if (current === null || current === void 0) return void 0;
|
|
55
|
+
if (typeof current !== "object") return void 0;
|
|
56
|
+
current = current[part];
|
|
57
|
+
}
|
|
58
|
+
return current;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Resolve a schema, following $ref if needed.
|
|
62
|
+
*/
|
|
63
|
+
function resolveSchema(doc, schema) {
|
|
64
|
+
if (!schema) return void 0;
|
|
65
|
+
if (isReference(schema)) return resolveRef(doc, schema.$ref) ?? schema;
|
|
66
|
+
return schema;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parse parameters from an operation.
|
|
70
|
+
*/
|
|
71
|
+
function parseParameters(doc, params) {
|
|
72
|
+
const result = {
|
|
73
|
+
path: [],
|
|
74
|
+
query: [],
|
|
75
|
+
header: [],
|
|
76
|
+
cookie: []
|
|
77
|
+
};
|
|
78
|
+
if (!params) return result;
|
|
79
|
+
for (const param of params) {
|
|
80
|
+
let resolved;
|
|
81
|
+
if (isReference(param)) {
|
|
82
|
+
const ref = resolveRef(doc, param.$ref);
|
|
83
|
+
if (!ref) continue;
|
|
84
|
+
resolved = ref;
|
|
85
|
+
} else resolved = param;
|
|
86
|
+
const parsed = {
|
|
87
|
+
name: resolved.name,
|
|
88
|
+
in: resolved.in,
|
|
89
|
+
required: resolved.required ?? resolved.in === "path",
|
|
90
|
+
description: resolved.description,
|
|
91
|
+
schema: resolved.schema,
|
|
92
|
+
deprecated: resolved.deprecated ?? false
|
|
93
|
+
};
|
|
94
|
+
result[resolved.in]?.push(parsed);
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Generate an operationId if not present.
|
|
100
|
+
*/
|
|
101
|
+
function generateOperationId(method, path) {
|
|
102
|
+
return method + path.split("/").filter(Boolean).map((part) => {
|
|
103
|
+
if (part.startsWith("{") && part.endsWith("}")) return "By" + part.slice(1, -1).charAt(0).toUpperCase() + part.slice(2, -1);
|
|
104
|
+
return part.charAt(0).toUpperCase() + part.slice(1);
|
|
105
|
+
}).join("");
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Parse a single operation.
|
|
109
|
+
*/
|
|
110
|
+
function parseOperation(doc, method, path, operation, pathParams) {
|
|
111
|
+
const params = parseParameters(doc, [...pathParams ?? [], ...operation.parameters ?? []]);
|
|
112
|
+
let requestBody;
|
|
113
|
+
if (operation.requestBody) {
|
|
114
|
+
const body = isReference(operation.requestBody) ? resolveRef(doc, operation.requestBody.$ref) : operation.requestBody;
|
|
115
|
+
if (body) {
|
|
116
|
+
const contentType = Object.keys(body.content ?? {})[0] ?? "application/json";
|
|
117
|
+
const content = body.content?.[contentType];
|
|
118
|
+
if (content?.schema) requestBody = {
|
|
119
|
+
required: body.required ?? false,
|
|
120
|
+
schema: resolveSchema(doc, content.schema),
|
|
121
|
+
contentType
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const responses = {};
|
|
126
|
+
for (const [status, response] of Object.entries(operation.responses ?? {})) {
|
|
127
|
+
const resolved = isReference(response) ? resolveRef(doc, response.$ref) : response;
|
|
128
|
+
if (resolved) {
|
|
129
|
+
const contentType = Object.keys(resolved.content ?? {})[0];
|
|
130
|
+
const content = contentType ? resolved.content?.[contentType] : void 0;
|
|
131
|
+
responses[status] = {
|
|
132
|
+
description: resolved.description,
|
|
133
|
+
schema: content?.schema ? resolveSchema(doc, content.schema) : void 0,
|
|
134
|
+
contentType
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const contractSpecMeta = operation?.["x-contractspec"];
|
|
139
|
+
return {
|
|
140
|
+
operationId: operation.operationId ?? generateOperationId(method, path),
|
|
141
|
+
method,
|
|
142
|
+
path,
|
|
143
|
+
summary: operation.summary,
|
|
144
|
+
description: operation.description,
|
|
145
|
+
tags: operation.tags ?? [],
|
|
146
|
+
pathParams: params.path,
|
|
147
|
+
queryParams: params.query,
|
|
148
|
+
headerParams: params.header,
|
|
149
|
+
cookieParams: params.cookie,
|
|
150
|
+
requestBody,
|
|
151
|
+
responses,
|
|
152
|
+
deprecated: operation.deprecated ?? false,
|
|
153
|
+
security: operation.security,
|
|
154
|
+
contractSpecMeta
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Parse an OpenAPI document into a structured result.
|
|
159
|
+
*/
|
|
160
|
+
function parseOpenApiDocument(doc, _options = {}) {
|
|
161
|
+
const version = detectVersion(doc);
|
|
162
|
+
const warnings = [];
|
|
163
|
+
const operations = [];
|
|
164
|
+
for (const [path, pathItem] of Object.entries(doc.paths ?? {})) {
|
|
165
|
+
if (!pathItem) continue;
|
|
166
|
+
const pathParams = pathItem.parameters;
|
|
167
|
+
for (const method of HTTP_METHODS) {
|
|
168
|
+
const operation = pathItem[method];
|
|
169
|
+
if (operation) try {
|
|
170
|
+
operations.push(parseOperation(doc, method, path, operation, pathParams));
|
|
171
|
+
} catch (error) {
|
|
172
|
+
warnings.push(`Failed to parse ${method.toUpperCase()} ${path}: ${error}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const schemas = {};
|
|
177
|
+
const components = doc.components;
|
|
178
|
+
if (components?.schemas) for (const [name, schema] of Object.entries(components.schemas)) schemas[name] = schema;
|
|
179
|
+
const servers = (doc.servers ?? []).map((s) => ({
|
|
180
|
+
url: s.url,
|
|
181
|
+
description: s.description,
|
|
182
|
+
variables: s.variables
|
|
183
|
+
}));
|
|
184
|
+
return {
|
|
185
|
+
document: doc,
|
|
186
|
+
version,
|
|
187
|
+
info: {
|
|
188
|
+
title: doc.info.title,
|
|
189
|
+
version: doc.info.version,
|
|
190
|
+
description: doc.info.description
|
|
191
|
+
},
|
|
192
|
+
operations,
|
|
193
|
+
schemas,
|
|
194
|
+
servers,
|
|
195
|
+
warnings
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Parse OpenAPI from a file path or URL.
|
|
200
|
+
* Note: This is an async function that requires I/O adapters.
|
|
201
|
+
* For pure parsing, use parseOpenApiString or parseOpenApiDocument.
|
|
202
|
+
*/
|
|
203
|
+
async function parseOpenApi(source, options = {}) {
|
|
204
|
+
const { fetch: fetchFn = globalThis.fetch, readFile, timeout = 3e4 } = options;
|
|
205
|
+
let content;
|
|
206
|
+
let format;
|
|
207
|
+
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
208
|
+
const controller = new AbortController();
|
|
209
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
210
|
+
try {
|
|
211
|
+
const response = await fetchFn(source, { signal: controller.signal });
|
|
212
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
213
|
+
content = await response.text();
|
|
214
|
+
} finally {
|
|
215
|
+
clearTimeout(timeoutId);
|
|
216
|
+
}
|
|
217
|
+
if (source.endsWith(".yaml") || source.endsWith(".yml")) format = "yaml";
|
|
218
|
+
else if (source.endsWith(".json")) format = "json";
|
|
219
|
+
else format = detectFormat(content);
|
|
220
|
+
} else {
|
|
221
|
+
if (!readFile) throw new Error("readFile adapter required for file paths");
|
|
222
|
+
content = await readFile(source);
|
|
223
|
+
if (source.endsWith(".yaml") || source.endsWith(".yml")) format = "yaml";
|
|
224
|
+
else if (source.endsWith(".json")) format = "json";
|
|
225
|
+
else format = detectFormat(content);
|
|
226
|
+
}
|
|
227
|
+
return parseOpenApiDocument(parseOpenApiString(content, format), options);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
//#endregion
|
|
231
|
+
export { detectFormat, detectVersion, parseOpenApi, parseOpenApiDocument, parseOpenApiString };
|
|
@@ -1,4 +1,201 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { toCamelCase, toPascalCase, toValidIdentifier } from "../common/utils.js";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/contracts-transformers/dist/openapi/schema-converter.js
|
|
4
|
+
/**
|
|
5
|
+
* Map JSON Schema types to ContractSpec ScalarTypeEnum values.
|
|
6
|
+
*/
|
|
7
|
+
const JSON_SCHEMA_TO_SCALAR = {
|
|
8
|
+
string: "ScalarTypeEnum.STRING",
|
|
9
|
+
integer: "ScalarTypeEnum.INT",
|
|
10
|
+
number: "ScalarTypeEnum.FLOAT",
|
|
11
|
+
boolean: "ScalarTypeEnum.BOOLEAN",
|
|
12
|
+
"string:date": "ScalarTypeEnum.DATE",
|
|
13
|
+
"string:date-time": "ScalarTypeEnum.DATE_TIME",
|
|
14
|
+
"string:email": "ScalarTypeEnum.EMAIL",
|
|
15
|
+
"string:uri": "ScalarTypeEnum.URL",
|
|
16
|
+
"string:uuid": "ScalarTypeEnum.ID"
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Check if a schema is a reference object.
|
|
20
|
+
*/
|
|
21
|
+
function isReference(schema) {
|
|
22
|
+
return "$ref" in schema;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Extract type name from a $ref.
|
|
26
|
+
*/
|
|
27
|
+
function typeNameFromRef(ref) {
|
|
28
|
+
const parts = ref.split("/");
|
|
29
|
+
return parts[parts.length - 1] ?? "Unknown";
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert a JSON Schema to a TypeScript type representation.
|
|
33
|
+
*/
|
|
34
|
+
function jsonSchemaToType(schema, name) {
|
|
35
|
+
if (isReference(schema)) return {
|
|
36
|
+
type: toPascalCase(typeNameFromRef(schema.$ref)),
|
|
37
|
+
optional: false,
|
|
38
|
+
array: false,
|
|
39
|
+
primitive: false
|
|
40
|
+
};
|
|
41
|
+
const schemaObj = schema;
|
|
42
|
+
const type = schemaObj["type"];
|
|
43
|
+
const format = schemaObj["format"];
|
|
44
|
+
const nullable = schemaObj["nullable"];
|
|
45
|
+
if (type === "array") {
|
|
46
|
+
const items = schemaObj["items"];
|
|
47
|
+
if (items) return {
|
|
48
|
+
...jsonSchemaToType(items, name),
|
|
49
|
+
array: true,
|
|
50
|
+
optional: nullable ?? false
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
type: "unknown",
|
|
54
|
+
optional: nullable ?? false,
|
|
55
|
+
array: true,
|
|
56
|
+
primitive: false
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (type === "object" || schemaObj["properties"]) return {
|
|
60
|
+
type: name ? toPascalCase(name) : "Record<string, unknown>",
|
|
61
|
+
optional: nullable ?? false,
|
|
62
|
+
array: false,
|
|
63
|
+
primitive: false
|
|
64
|
+
};
|
|
65
|
+
if (schemaObj["enum"]) return {
|
|
66
|
+
type: name ? toPascalCase(name) : "string",
|
|
67
|
+
optional: nullable ?? false,
|
|
68
|
+
array: false,
|
|
69
|
+
primitive: false
|
|
70
|
+
};
|
|
71
|
+
format && `${type}${format}`;
|
|
72
|
+
if (type === "string") return {
|
|
73
|
+
type: "string",
|
|
74
|
+
optional: nullable ?? false,
|
|
75
|
+
array: false,
|
|
76
|
+
primitive: true
|
|
77
|
+
};
|
|
78
|
+
if (type === "integer" || type === "number") return {
|
|
79
|
+
type: "number",
|
|
80
|
+
optional: nullable ?? false,
|
|
81
|
+
array: false,
|
|
82
|
+
primitive: true
|
|
83
|
+
};
|
|
84
|
+
if (type === "boolean") return {
|
|
85
|
+
type: "boolean",
|
|
86
|
+
optional: nullable ?? false,
|
|
87
|
+
array: false,
|
|
88
|
+
primitive: true
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
type: "unknown",
|
|
92
|
+
optional: nullable ?? false,
|
|
93
|
+
array: false,
|
|
94
|
+
primitive: false
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the ScalarTypeEnum value for a JSON Schema type.
|
|
99
|
+
*/
|
|
100
|
+
function getScalarType(schema) {
|
|
101
|
+
if (isReference(schema)) return;
|
|
102
|
+
const schemaObj = schema;
|
|
103
|
+
const type = schemaObj["type"];
|
|
104
|
+
const format = schemaObj["format"];
|
|
105
|
+
if (!type) return void 0;
|
|
106
|
+
return JSON_SCHEMA_TO_SCALAR[format ? `${type}:${format}` : type] ?? JSON_SCHEMA_TO_SCALAR[type];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Convert a JSON Schema to a SchemaModel field definition.
|
|
110
|
+
*/
|
|
111
|
+
function jsonSchemaToField(schema, fieldName, required) {
|
|
112
|
+
const type = jsonSchemaToType(schema, fieldName);
|
|
113
|
+
const scalarType = getScalarType(schema);
|
|
114
|
+
let enumValues;
|
|
115
|
+
if (!isReference(schema)) {
|
|
116
|
+
const enumArr = schema["enum"];
|
|
117
|
+
if (enumArr) enumValues = enumArr.map(String);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
name: toValidIdentifier(toCamelCase(fieldName)),
|
|
121
|
+
type: {
|
|
122
|
+
...type,
|
|
123
|
+
optional: !required || type.optional,
|
|
124
|
+
description: !isReference(schema) ? schema["description"] : void 0
|
|
125
|
+
},
|
|
126
|
+
scalarType,
|
|
127
|
+
enumValues
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Generate SchemaModel TypeScript code for a JSON Schema object.
|
|
132
|
+
*/
|
|
133
|
+
function generateSchemaModelCode(schema, modelName, indent = 0) {
|
|
134
|
+
const spaces = " ".repeat(indent);
|
|
135
|
+
const fields = [];
|
|
136
|
+
let description;
|
|
137
|
+
if (isReference(schema)) return {
|
|
138
|
+
name: toPascalCase(typeNameFromRef(schema.$ref)),
|
|
139
|
+
fields: [],
|
|
140
|
+
code: `// Reference to ${schema.$ref}`
|
|
141
|
+
};
|
|
142
|
+
const schemaObj = schema;
|
|
143
|
+
description = schemaObj["description"];
|
|
144
|
+
const properties = schemaObj["properties"];
|
|
145
|
+
const required = schemaObj["required"] ?? [];
|
|
146
|
+
if (!properties) return {
|
|
147
|
+
name: toPascalCase(modelName),
|
|
148
|
+
description,
|
|
149
|
+
fields: [],
|
|
150
|
+
code: `${spaces}// Empty schema for ${modelName}`
|
|
151
|
+
};
|
|
152
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
153
|
+
const isRequired = required.includes(propName);
|
|
154
|
+
fields.push(jsonSchemaToField(propSchema, propName, isRequired));
|
|
155
|
+
}
|
|
156
|
+
const lines = [];
|
|
157
|
+
const safeModelName = toPascalCase(toValidIdentifier(modelName));
|
|
158
|
+
lines.push(`${spaces}export const ${safeModelName} = defineSchemaModel({`);
|
|
159
|
+
lines.push(`${spaces} name: '${safeModelName}',`);
|
|
160
|
+
if (description) lines.push(`${spaces} description: ${JSON.stringify(description)},`);
|
|
161
|
+
lines.push(`${spaces} fields: {`);
|
|
162
|
+
for (const field of fields) {
|
|
163
|
+
const fieldLines = generateFieldCode(field, indent + 2);
|
|
164
|
+
lines.push(fieldLines);
|
|
165
|
+
}
|
|
166
|
+
lines.push(`${spaces} },`);
|
|
167
|
+
lines.push(`${spaces}});`);
|
|
168
|
+
return {
|
|
169
|
+
name: safeModelName,
|
|
170
|
+
description,
|
|
171
|
+
fields,
|
|
172
|
+
code: lines.join("\n")
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Generate TypeScript code for a single field.
|
|
177
|
+
*/
|
|
178
|
+
function generateFieldCode(field, indent) {
|
|
179
|
+
const spaces = " ".repeat(indent);
|
|
180
|
+
const lines = [];
|
|
181
|
+
lines.push(`${spaces}${field.name}: {`);
|
|
182
|
+
if (field.enumValues) lines.push(`${spaces} type: new EnumType([${field.enumValues.map((v) => `'${v}'`).join(", ")}]),`);
|
|
183
|
+
else if (field.scalarType) lines.push(`${spaces} type: ${field.scalarType},`);
|
|
184
|
+
else lines.push(`${spaces} type: ${field.type.type}, // TODO: Define or import this type`);
|
|
185
|
+
if (field.type.optional) lines.push(`${spaces} isOptional: true,`);
|
|
186
|
+
if (field.type.array) lines.push(`${spaces} isArray: true,`);
|
|
187
|
+
lines.push(`${spaces}},`);
|
|
188
|
+
return lines.join("\n");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Generate import statements for a SchemaModel.
|
|
192
|
+
*/
|
|
193
|
+
function generateImports(fields) {
|
|
194
|
+
const imports = /* @__PURE__ */ new Set();
|
|
195
|
+
imports.add("import { defineSchemaModel, ScalarTypeEnum, EnumType } from '@lssm/lib.schema';");
|
|
196
|
+
for (const field of fields) if (!field.type.primitive && !field.enumValues && !field.scalarType) {}
|
|
197
|
+
return Array.from(imports).join("\n");
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
export { generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToField, jsonSchemaToType };
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
//#region ../../modules/contractspec-workspace/dist/ai/code-generation.js
|
|
2
|
+
/**
|
|
3
|
+
* AI prompts for code generation.
|
|
4
|
+
* Extracted from cli-contracts/src/ai/prompts/code-generation.ts
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Build prompt for generating handler implementation.
|
|
8
|
+
*/
|
|
9
|
+
function buildHandlerPrompt(specCode) {
|
|
10
|
+
return `You are a senior TypeScript developer implementing a handler for a contract specification.
|
|
2
11
|
|
|
3
12
|
Here is the contract spec:
|
|
4
13
|
|
|
5
14
|
\`\`\`typescript
|
|
6
|
-
${
|
|
15
|
+
${specCode}
|
|
7
16
|
\`\`\`
|
|
8
17
|
|
|
9
18
|
Generate a complete handler implementation that:
|
|
@@ -17,12 +26,18 @@ Generate a complete handler implementation that:
|
|
|
17
26
|
|
|
18
27
|
The handler should be production-ready with proper error handling, logging points, and clear structure.
|
|
19
28
|
|
|
20
|
-
Return only the TypeScript code for the handler function
|
|
29
|
+
Return only the TypeScript code for the handler function.`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Build prompt for generating React component from presentation spec.
|
|
33
|
+
*/
|
|
34
|
+
function buildComponentPrompt(specCode) {
|
|
35
|
+
return `You are a senior React developer creating a component for a presentation specification.
|
|
21
36
|
|
|
22
37
|
Here is the presentation spec:
|
|
23
38
|
|
|
24
39
|
\`\`\`typescript
|
|
25
|
-
${
|
|
40
|
+
${specCode}
|
|
26
41
|
\`\`\`
|
|
27
42
|
|
|
28
43
|
Generate a complete React component that:
|
|
@@ -36,12 +51,18 @@ Generate a complete React component that:
|
|
|
36
51
|
|
|
37
52
|
The component should follow Atomic Design principles and be reusable.
|
|
38
53
|
|
|
39
|
-
Return only the TypeScript/TSX code for the component
|
|
54
|
+
Return only the TypeScript/TSX code for the component.`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Build prompt for generating form component.
|
|
58
|
+
*/
|
|
59
|
+
function buildFormPrompt(specCode) {
|
|
60
|
+
return `You are a senior React developer creating a form component from a form specification.
|
|
40
61
|
|
|
41
62
|
Here is the form spec:
|
|
42
63
|
|
|
43
64
|
\`\`\`typescript
|
|
44
|
-
${
|
|
65
|
+
${specCode}
|
|
45
66
|
\`\`\`
|
|
46
67
|
|
|
47
68
|
Generate a complete form component using react-hook-form that:
|
|
@@ -56,25 +77,31 @@ Generate a complete form component using react-hook-form that:
|
|
|
56
77
|
|
|
57
78
|
The form should provide excellent UX with real-time validation and helpful feedback.
|
|
58
79
|
|
|
59
|
-
Return only the TypeScript/TSX code for the form component
|
|
80
|
+
Return only the TypeScript/TSX code for the form component.`;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build prompt for generating tests.
|
|
84
|
+
*/
|
|
85
|
+
function buildTestPrompt(specCode, implementationCode, testType) {
|
|
86
|
+
return `You are a senior developer writing comprehensive tests.
|
|
60
87
|
|
|
61
88
|
Spec:
|
|
62
89
|
\`\`\`typescript
|
|
63
|
-
${
|
|
90
|
+
${specCode}
|
|
64
91
|
\`\`\`
|
|
65
92
|
|
|
66
93
|
Implementation:
|
|
67
94
|
\`\`\`typescript
|
|
68
|
-
${
|
|
95
|
+
${implementationCode}
|
|
69
96
|
\`\`\`
|
|
70
97
|
|
|
71
98
|
Generate complete test suite using Vitest that:
|
|
72
|
-
${
|
|
99
|
+
${testType === "handler" ? `
|
|
73
100
|
- Test all acceptance scenarios from the spec
|
|
74
101
|
- Test error cases defined in spec.io.errors
|
|
75
102
|
- Verify events are emitted correctly
|
|
76
103
|
- Test input validation
|
|
77
|
-
- Test happy path and edge cases
|
|
104
|
+
- Test happy path and edge cases` : `
|
|
78
105
|
- Test rendering with various props
|
|
79
106
|
- Test user interactions
|
|
80
107
|
- Test accessibility (a11y)
|
|
@@ -83,7 +110,13 @@ ${n===`handler`?`
|
|
|
83
110
|
|
|
84
111
|
Use clear test descriptions and follow AAA pattern (Arrange, Act, Assert).
|
|
85
112
|
|
|
86
|
-
Return only the TypeScript test code
|
|
113
|
+
Return only the TypeScript test code.`;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* System prompt for code generation.
|
|
117
|
+
*/
|
|
118
|
+
function getCodeGenSystemPrompt() {
|
|
119
|
+
return `You are an expert TypeScript developer with deep knowledge of:
|
|
87
120
|
- Type-safe API design
|
|
88
121
|
- React and modern hooks
|
|
89
122
|
- Test-driven development
|
|
@@ -97,4 +130,8 @@ Generate production-ready code that is:
|
|
|
97
130
|
- Defensive and error-safe
|
|
98
131
|
- Easy to maintain and extend
|
|
99
132
|
|
|
100
|
-
Always prioritize code quality, safety, and user experience
|
|
133
|
+
Always prioritize code quality, safety, and user experience.`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
export { buildComponentPrompt, buildFormPrompt, buildHandlerPrompt, buildTestPrompt, getCodeGenSystemPrompt };
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
//#region ../../modules/contractspec-workspace/dist/ai/spec-creation.js
|
|
2
|
+
/**
|
|
3
|
+
* Build prompt for creating operation spec from description.
|
|
4
|
+
*/
|
|
5
|
+
function buildOperationSpecPrompt(description, kind) {
|
|
6
|
+
return `You are a senior software architect creating a contract specification for an operation.
|
|
2
7
|
|
|
3
|
-
The operation is a ${
|
|
8
|
+
The operation is a ${kind} (${kind === "command" ? "changes state, has side effects" : "read-only, idempotent"}).
|
|
4
9
|
|
|
5
|
-
User description: ${
|
|
10
|
+
User description: ${description}
|
|
6
11
|
|
|
7
12
|
Create a complete contract specification following these guidelines:
|
|
8
13
|
|
|
@@ -16,9 +21,15 @@ Create a complete contract specification following these guidelines:
|
|
|
16
21
|
8. **Feature Flags**: Any flags that gate this operation
|
|
17
22
|
9. **Side Effects**: What events might be emitted, analytics to track
|
|
18
23
|
|
|
19
|
-
Respond with a structured spec
|
|
24
|
+
Respond with a structured spec.`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build prompt for creating event spec from description.
|
|
28
|
+
*/
|
|
29
|
+
function buildEventSpecPrompt(description) {
|
|
30
|
+
return `You are a senior software architect creating an event specification.
|
|
20
31
|
|
|
21
|
-
User description: ${
|
|
32
|
+
User description: ${description}
|
|
22
33
|
|
|
23
34
|
Create a complete event specification following these guidelines:
|
|
24
35
|
|
|
@@ -30,11 +41,21 @@ Create a complete event specification following these guidelines:
|
|
|
30
41
|
|
|
31
42
|
Events represent things that have already happened and should use past tense.
|
|
32
43
|
|
|
33
|
-
Respond with a structured spec
|
|
44
|
+
Respond with a structured spec.`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Build prompt for creating presentation spec from description.
|
|
48
|
+
*/
|
|
49
|
+
function buildPresentationSpecPrompt(description, kind) {
|
|
50
|
+
return `You are a senior software architect creating a presentation specification.
|
|
34
51
|
|
|
35
|
-
This is a ${
|
|
52
|
+
This is a ${kind} presentation - ${{
|
|
53
|
+
web_component: "a React component with props schema",
|
|
54
|
+
markdown: "markdown/MDX documentation or guide",
|
|
55
|
+
data: "structured data export (JSON/XML)"
|
|
56
|
+
}[kind]}.
|
|
36
57
|
|
|
37
|
-
User description: ${
|
|
58
|
+
User description: ${description}
|
|
38
59
|
|
|
39
60
|
Create a complete presentation specification following these guidelines:
|
|
40
61
|
|
|
@@ -42,13 +63,15 @@ Create a complete presentation specification following these guidelines:
|
|
|
42
63
|
2. **Version**: Start at 1
|
|
43
64
|
3. **Description**: What this presentation shows/provides
|
|
44
65
|
4. **Kind-specific details**:
|
|
45
|
-
${
|
|
46
|
-
- Props structure
|
|
47
|
-
- Analytics events to track`:t===`markdown`?`- Content or resource URI
|
|
48
|
-
- Target audience`:`- MIME type (e.g., application/json)
|
|
49
|
-
- Data structure description`}
|
|
66
|
+
${kind === "web_component" ? "- Component key (symbolic, resolved by host app)\n - Props structure\n - Analytics events to track" : kind === "markdown" ? "- Content or resource URI\n - Target audience" : "- MIME type (e.g., application/json)\n - Data structure description"}
|
|
50
67
|
|
|
51
|
-
Respond with a structured spec
|
|
68
|
+
Respond with a structured spec.`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build system prompt for all spec generation.
|
|
72
|
+
*/
|
|
73
|
+
function getSystemPrompt() {
|
|
74
|
+
return `You are an expert software architect specializing in API design and contract-driven development.
|
|
52
75
|
|
|
53
76
|
You create clear, well-documented specifications that serve as the single source of truth for operations, events, and presentations.
|
|
54
77
|
|
|
@@ -58,12 +81,21 @@ Your specs are:
|
|
|
58
81
|
- Business-oriented (capturing the "why" not just "what")
|
|
59
82
|
- Designed for both humans and AI agents to understand
|
|
60
83
|
|
|
61
|
-
Always use proper dot notation for names and ensure all metadata is meaningful and accurate
|
|
84
|
+
Always use proper dot notation for names and ensure all metadata is meaningful and accurate.`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Create example-based prompt for better results.
|
|
88
|
+
*/
|
|
89
|
+
function addExampleContext(basePrompt, examples) {
|
|
90
|
+
if (examples.length === 0) return basePrompt;
|
|
91
|
+
return `${basePrompt}
|
|
62
92
|
|
|
63
93
|
Here are some good examples for reference:
|
|
64
94
|
|
|
65
|
-
${
|
|
95
|
+
${examples.join("\n\n")}
|
|
66
96
|
|
|
67
|
-
|
|
97
|
+
Follow this structure and quality level.`;
|
|
98
|
+
}
|
|
68
99
|
|
|
69
|
-
|
|
100
|
+
//#endregion
|
|
101
|
+
export { addExampleContext, buildEventSpecPrompt, buildOperationSpecPrompt, buildPresentationSpecPrompt, getSystemPrompt };
|