@uibot/application 0.0.0-stage → 0.2.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 (73) hide show
  1. package/dist/collection-application.d.ts +3 -0
  2. package/dist/collection-application.js +25 -0
  3. package/dist/compose-system-prompt.d.ts +104 -0
  4. package/dist/composition.d.ts +24 -0
  5. package/dist/context-service.d.ts +42 -0
  6. package/dist/creation-annotations.d.ts +5 -0
  7. package/dist/creation-assets.d.ts +15 -0
  8. package/dist/creation-brand-http.d.ts +9 -0
  9. package/dist/creation-brand.d.ts +25 -0
  10. package/dist/creation-copy.d.ts +11 -0
  11. package/dist/creation-domains.d.ts +25 -0
  12. package/dist/creation-facts.d.ts +8 -0
  13. package/dist/creation-http-helpers.d.ts +35 -0
  14. package/dist/creation-http.d.ts +99 -0
  15. package/dist/creation-layout.d.ts +4 -0
  16. package/dist/creation-legacy-flat-spec.d.ts +42 -0
  17. package/dist/creation-prompt.d.ts +33 -0
  18. package/dist/creation-requirements.d.ts +6 -0
  19. package/dist/creation-routes.d.ts +26 -0
  20. package/dist/creation-runner.d.ts +20 -0
  21. package/dist/creation-spec-prompt.d.ts +3 -0
  22. package/dist/creation-store.d.ts +121 -0
  23. package/dist/creation-theme-http.d.ts +13 -0
  24. package/dist/creation-theme.d.ts +16 -0
  25. package/dist/creation-web-data-prompt.d.ts +15 -0
  26. package/dist/discovery-protocol.d.ts +25 -0
  27. package/dist/gap-orchestrator.d.ts +19 -0
  28. package/dist/grounded-brief.d.ts +37 -0
  29. package/dist/html-preview/config.d.ts +14 -0
  30. package/dist/html-preview/index.d.ts +11 -0
  31. package/dist/html-preview/link-interceptor.d.ts +10 -0
  32. package/dist/html-preview/proxy.d.ts +57 -0
  33. package/dist/html-preview/render.d.ts +39 -0
  34. package/dist/html-preview/routes.d.ts +27 -0
  35. package/dist/html-preview/session-store.d.ts +44 -0
  36. package/dist/hub-client.d.ts +25 -0
  37. package/dist/index.d.ts +32 -0
  38. package/dist/index.js +819 -0
  39. package/dist/live-runtime-adapter.d.ts +11 -0
  40. package/dist/playground-session-http.d.ts +24 -0
  41. package/dist/prompt.d.ts +17 -0
  42. package/dist/resource-apply.d.ts +18 -0
  43. package/dist/runtime.d.ts +37 -0
  44. package/dist/studio-artifact-export-http.d.ts +52 -0
  45. package/dist/studio-compose-context.d.ts +47 -0
  46. package/dist/studio-compose-http.d.ts +31 -0
  47. package/dist/studio-design-http.d.ts +164 -0
  48. package/dist/studio-design-md-export-http.d.ts +11 -0
  49. package/dist/studio-http-shared.d.ts +34 -0
  50. package/dist/studio-http.d.ts +359 -0
  51. package/dist/studio-logo.d.ts +24 -0
  52. package/dist/studio-pages/agents-page.d.ts +48 -0
  53. package/dist/studio-pages/catalog-page.d.ts +22 -0
  54. package/dist/studio-pages/design-md-page.d.ts +55 -0
  55. package/dist/studio-pages/evolution-page.d.ts +111 -0
  56. package/dist/studio-pages/governance-page.d.ts +65 -0
  57. package/dist/studio-pages/index.d.ts +82 -0
  58. package/dist/studio-pages/models-page.d.ts +76 -0
  59. package/dist/studio-pages/operations-page.d.ts +61 -0
  60. package/dist/studio-pages/overview-page.d.ts +90 -0
  61. package/dist/studio-pages/plugins-page.d.ts +36 -0
  62. package/dist/studio-pages/shared.d.ts +25 -0
  63. package/dist/studio-pages/skills-page.d.ts +59 -0
  64. package/dist/studio-pages/spec-page.d.ts +33 -0
  65. package/dist/studio-project-design-http.d.ts +41 -0
  66. package/dist/studio-project-specs.d.ts +11 -0
  67. package/dist/studio-resource-index-http.d.ts +17 -0
  68. package/dist/studio-spec-recover-http.d.ts +45 -0
  69. package/dist/studio-spec-sync-http.d.ts +43 -0
  70. package/dist/studio.d.ts +64 -0
  71. package/dist/ui-craft-baseline.d.ts +14 -0
  72. package/package.json +49 -4
  73. package/README.md +0 -3
@@ -0,0 +1,99 @@
1
+ import type { CreationBrandAssets } from "./creation-brand.js";
2
+ import type { Catalog, LLMBaseInferenceObservation, CreationSourceFormat, UIBotSpec } from "@uibot/contracts";
3
+ import type { CreationDomainDefinition } from "./creation-domains.js";
4
+ import { type CreationRepository } from "./creation-store.js";
5
+ import type { CreationWebDataGenerationGrant } from "./creation-web-data-prompt.js";
6
+ export type { CreationWebDataGenerationGrant } from "./creation-web-data-prompt.js";
7
+ export interface CreationGenerateInput {
8
+ inferenceId?: string;
9
+ purpose?: "generation" | "requirement-review";
10
+ requestId?: string;
11
+ system: string;
12
+ prompt: string;
13
+ modelId: string;
14
+ signal: AbortSignal;
15
+ outputFormat?: CreationSourceFormat;
16
+ outputProtocol?: "uibot.creation-layout.v1";
17
+ maxOutputTokens?: number;
18
+ }
19
+ /** Runtime functions stay in application; persisted runs contain only IDs/budgets. */
20
+ export interface CreationModelBinding {
21
+ inference?: {
22
+ endpointId: string;
23
+ credentialId: string;
24
+ createId: () => string;
25
+ query: (id: string, signal: AbortSignal) => Promise<LLMBaseInferenceObservation>;
26
+ };
27
+ modelId: string;
28
+ configurationId?: string;
29
+ budget?: {
30
+ contextTokens: number;
31
+ outputTokens: number;
32
+ };
33
+ generate?: (input: CreationGenerateInput) => Promise<string>;
34
+ }
35
+ /**
36
+ * Frozen identity captured before authorization. A claim cannot change these
37
+ * fields or add runs. `version` is the project version; `attempt` is the run attempt.
38
+ */
39
+ export interface CreationRunReference {
40
+ readonly projectId: string;
41
+ readonly runId: string;
42
+ readonly version: number;
43
+ readonly attempt: number;
44
+ }
45
+ /** Current persisted run identity supplied to a trusted host, never request data. */
46
+ export interface CreationWebDataGenerationRequest extends CreationRunReference {
47
+ readonly artifactId: string;
48
+ readonly expectedRevisionId: string | null;
49
+ readonly signal: AbortSignal;
50
+ }
51
+ /**
52
+ * Permission to mark exactly these observed runs interrupted inside one tenant scope.
53
+ * The host must already have confirmed that each run stopped. This is not a lease.
54
+ */
55
+ export interface CreationRecoveryClaim {
56
+ readonly tenantScope: string;
57
+ readonly runs: readonly CreationRunReference[];
58
+ }
59
+ export interface CreationRecoveryRequest {
60
+ readonly tenantScope: string;
61
+ readonly runs: readonly CreationRunReference[];
62
+ }
63
+ /** Host gate. Null, another scope, or a widened reference leaves stored runs untouched. */
64
+ export type CreationRecoveryAuthorizer = (request: CreationRecoveryRequest) => Promise<CreationRecoveryClaim | null> | CreationRecoveryClaim | null;
65
+ export interface CreateCreationHandlerOptions {
66
+ repository: CreationRepository;
67
+ domains: CreationDomainDefinition[];
68
+ catalog?: Catalog;
69
+ templates?: Readonly<Record<string, UIBotSpec>>;
70
+ modelId: string;
71
+ generate?: (input: CreationGenerateInput) => Promise<string>;
72
+ getModel?: () => Promise<CreationModelBinding>;
73
+ timeoutMs?: number;
74
+ /** Optional operator request ceiling; never substitutes model output. */
75
+ beforeModelRequest?: (input: CreationGenerateInput) => void;
76
+ /** Optional host-authorized data hint for plain HTML Web generation only. */
77
+ resolveWebData?: (request: CreationWebDataGenerationRequest) => Promise<CreationWebDataGenerationGrant | null | undefined>;
78
+ brandAssets?: CreationBrandAssets;
79
+ /** Trusted host identity/ACL, never a body or raw end-user header. */
80
+ authorizeReconciliation?: (request: Request, context: {
81
+ projectId: string;
82
+ runId?: string;
83
+ }) => Promise<string | undefined>;
84
+ /** Explicit host authority for the operator-only full snapshot import route. */
85
+ authorizeSnapshotImport?: (request: Request) => Promise<string | undefined> | string | undefined;
86
+ /**
87
+ * Tenant of this handler. A recovery claim for any other scope is ignored.
88
+ * Omit this or authorizeRecovery and unfinished runs stay as committed.
89
+ */
90
+ tenantScope?: string;
91
+ /**
92
+ * Host recovery authority for runs the host has already confirmed stopped.
93
+ * The handler submits frozen version/attempt references and writes only with
94
+ * that project version. A stale or widened claim does not commit or re-authorize.
95
+ */
96
+ authorizeRecovery?: CreationRecoveryAuthorizer;
97
+ }
98
+ /** Durable single-service workflow: generate -> validate -> conditional commit. */
99
+ export declare function createUIBotStudioCreationHandler(options: CreateCreationHandlerOptions): Promise<(request: Request) => Promise<Response | null>>;
@@ -0,0 +1,4 @@
1
+ import type { CreationFactSourcePin, CreationSource } from "@uibot/contracts";
2
+ export declare const CREATION_LAYOUT_PROTOCOL = "uibot.creation-layout.v1";
3
+ export declare function decodeCreationLayout(raw: string, sources: CreationSource[], copyPins: CreationFactSourcePin[], factPins: CreationFactSourcePin[], brandTitle?: string): string;
4
+ export declare function creationLayoutPrompt(sources: CreationSource[], copyPins: CreationFactSourcePin[], factPins: CreationFactSourcePin[], hasBrand: boolean): string;
@@ -0,0 +1,42 @@
1
+ import type { ActionChain, Catalog, UIBotSpec } from "@uibot/contracts";
2
+ export interface FlatElementTreePage {
3
+ id: string;
4
+ path: string;
5
+ title?: string;
6
+ }
7
+ export interface FlatElementTreeComponentMapping {
8
+ type: string;
9
+ props?: Record<string, unknown>;
10
+ /** Source props explicitly handled by this mapping; no legacy key may be dropped. */
11
+ consumedProps: readonly string[];
12
+ }
13
+ export interface FlatElementTreeActionMapping {
14
+ actions: ActionChain;
15
+ /** Source args explicitly handled by this mapping; no legacy key may be dropped. */
16
+ consumedArgs: readonly string[];
17
+ }
18
+ export interface FlatElementTreeEventMappingInput {
19
+ sourceType: string;
20
+ targetType: string;
21
+ elementId: string;
22
+ sourceEvent: string;
23
+ }
24
+ export interface FlatElementTreeConversionOptions {
25
+ mapComponent?: (sourceType: string, sourceProps: Readonly<Record<string, unknown>>, elementId: string) => FlatElementTreeComponentMapping | undefined;
26
+ mapAction?: (actionId: string, args: Readonly<Record<string, unknown>>, elementId: string, event: string) => FlatElementTreeActionMapping | undefined;
27
+ mapEvent?: (input: Readonly<FlatElementTreeEventMappingInput>) => string;
28
+ }
29
+ export interface FlatElementTreeDiagnostic {
30
+ code: string;
31
+ path: string;
32
+ message: string;
33
+ }
34
+ export type FlatElementTreeConversionResult = {
35
+ ok: true;
36
+ spec: UIBotSpec;
37
+ } | {
38
+ ok: false;
39
+ diagnostics: FlatElementTreeDiagnostic[];
40
+ };
41
+ /** Converts a legacy flat UI tree only through explicit, host-owned semantic mappers. */
42
+ export declare function convertFlatElementTreeSpec(input: unknown, catalog: Catalog, page: FlatElementTreePage, options?: FlatElementTreeConversionOptions): Promise<FlatElementTreeConversionResult>;
@@ -0,0 +1,33 @@
1
+ import { type ContextFragment } from "@uibot/context";
2
+ import type { Catalog, CreationProject, CreationRun } from "@uibot/contracts";
3
+ import type { CreationBrandAssets } from "./creation-brand.js";
4
+ import type { CreationDomainDefinition } from "./creation-domains.js";
5
+ export interface CreationPromptInput {
6
+ project: CreationProject;
7
+ run: CreationRun;
8
+ definition: CreationDomainDefinition;
9
+ /** Mutated: the repair fragment is appended. */
10
+ fragments: ContextFragment[];
11
+ repairData: string | undefined;
12
+ brandAssets: CreationBrandAssets | undefined;
13
+ catalog: Catalog | undefined;
14
+ /** Only the application-built output of creationWebDataPrompt, never host prose. */
15
+ webDataHint?: string;
16
+ }
17
+ /**
18
+ * Compose the system prompt and assemble the context pack for one run.
19
+ * Throws the same CreationError codes the inline code did (context-too-large,
20
+ * validation-unavailable, repair-context-unavailable).
21
+ */
22
+ export declare function buildCreationPrompt(input: CreationPromptInput): Promise<{
23
+ outputFormat: import("@uibot/contracts").CreationSourceFormat;
24
+ fullSystem: string;
25
+ prompt: string;
26
+ budget: {
27
+ contextTokens: number;
28
+ outputTokens: number;
29
+ };
30
+ pinnedBrand: import("@uibot/contracts").CreationBrandRevision | undefined;
31
+ pinnedTheme: import("@uibot/contracts").CreationThemeRevision | undefined;
32
+ context: import("@uibot/context").ContextPack;
33
+ }>;
@@ -0,0 +1,6 @@
1
+ import type { CreationRequirementFinding } from "@uibot/contracts";
2
+ export declare function readRequirementReport(content: string): {
3
+ findings: CreationRequirementFinding[];
4
+ state: "needs-repair" | "pending-confirmation";
5
+ };
6
+ export declare function requirementReviewPrompt(intent: string, source: string, material: string[], prior?: CreationRequirementFinding[]): string;
@@ -0,0 +1,26 @@
1
+ import type { createCreationBrandHandler } from "./creation-brand-http.js";
2
+ import type { createCreationThemeHandler } from "./creation-theme-http.js";
3
+ import type { CreationContent, CreationProject, CreationRun, CreationRunInput } from "@uibot/contracts";
4
+ import type { CreationDomainDefinition } from "./creation-domains.js";
5
+ import { type CreationRepository } from "./creation-store.js";
6
+ import type { CreateCreationHandlerOptions, CreationModelBinding } from "./creation-http.js";
7
+ /** Closure members of the creation handler that the HTTP router needs. */
8
+ export interface CreationRouteContext {
9
+ base: string;
10
+ store: CreationRepository;
11
+ options: Pick<CreateCreationHandlerOptions, "authorizeReconciliation" | "authorizeSnapshotImport" | "brandAssets" | "catalog" | "domains">;
12
+ active: Map<string, AbortController>;
13
+ runModels: Map<string, CreationModelBinding>;
14
+ brandHandler: ReturnType<typeof createCreationBrandHandler>;
15
+ themeHandler: ReturnType<typeof createCreationThemeHandler>;
16
+ currentModel: () => Promise<CreationModelBinding>;
17
+ modelFor: (run: CreationRun) => Promise<CreationModelBinding>;
18
+ domainFor: (kind: string, enabled?: boolean) => CreationDomainDefinition;
19
+ validate: (source: CreationContent, kind: string, strict?: boolean) => Promise<void>;
20
+ createProject: (value: unknown) => Promise<CreationProject>;
21
+ launch: (projectId: string, runId: string) => void;
22
+ recoverInterrupted: (projectId: string) => Promise<void>;
23
+ repairOrigin: (project: CreationProject, input: CreationRunInput) => CreationRun;
24
+ }
25
+ /** Build the request router; the body is the former `handleCreation` closure. */
26
+ export declare function createCreationRouter(context: CreationRouteContext): (request: Request) => Promise<Response | null>;
@@ -0,0 +1,20 @@
1
+ import type { CreationContent, CreationProject, CreationRun, CreationRunInput } from "@uibot/contracts";
2
+ import type { CreationRepository } from "./creation-store.js";
3
+ import type { CreateCreationHandlerOptions, CreationModelBinding } from "./creation-http.js";
4
+ /** State the run engine shares with the HTTP handler. */
5
+ export interface CreationRunnerContext {
6
+ options: CreateCreationHandlerOptions;
7
+ store: CreationRepository;
8
+ active: Map<string, AbortController>;
9
+ runModels: Map<string, CreationModelBinding>;
10
+ currentModel: () => Promise<CreationModelBinding>;
11
+ }
12
+ /** Run engine: model binding, validation, repair, execute and launch (former handler closure). */
13
+ export declare function createCreationRunner(context: CreationRunnerContext): Promise<{
14
+ modelFor: (run: CreationRun) => Promise<CreationModelBinding>;
15
+ recoverInterrupted: (projectId: string) => Promise<void>;
16
+ domainFor: (kind: string, enabled?: boolean) => import("./creation-domains.js").CreationDomainDefinition;
17
+ validate: (source: CreationContent, kind: string, strict?: boolean) => Promise<void>;
18
+ repairOrigin: (project: CreationProject, input: CreationRunInput) => CreationRun;
19
+ launch: (projectId: string, runId: string) => void;
20
+ }>;
@@ -0,0 +1,3 @@
1
+ import { type Catalog } from "@uibot/contracts";
2
+ /** Shared Spec grammar and installed component catalog, independent of artifact kind. */
3
+ export declare function creationSpecPrompt(catalog: Catalog): string;
@@ -0,0 +1,121 @@
1
+ import type { CreationArtifact, CreationContent, CreationDesignPreferences, CreationProject, CreationProjectSummary, CreationReference, CreationRevision, CreationSnapshotExport, CreationSource, CreationSnapshotImportInput, CreationSnapshotImportReceipt } from "@uibot/contracts";
2
+ export declare class CreationError extends Error {
3
+ readonly code: string;
4
+ readonly status: number;
5
+ constructor(code: string, message: string, status?: number);
6
+ }
7
+ export declare function creationHash(content: string): string;
8
+ export declare function assertCreationId(id: string): void;
9
+ export declare function creationText(value: unknown, field: string, max?: number): string;
10
+ export declare function creationRecord(value: unknown): Record<string, unknown>;
11
+ export declare function readCreationContent(value: unknown): CreationContent;
12
+ export interface CreationRepository {
13
+ list(): Promise<CreationProjectSummary[]>;
14
+ listWithIssues(): Promise<{
15
+ projects: CreationProjectSummary[];
16
+ issues: Array<{
17
+ projectId: string;
18
+ code: string;
19
+ message: string;
20
+ }>;
21
+ }>;
22
+ get(id: string): Promise<CreationProject>;
23
+ /**
24
+ * Optional operator capability. Reads every complete project and its saved
25
+ * import lineage while the host confirms that source writes remain frozen.
26
+ */
27
+ exportSnapshots?(input: {
28
+ assertSourceFrozen: () => unknown | Promise<unknown>;
29
+ }): Promise<CreationSnapshotExport>;
30
+ /**
31
+ * Create one project. initialize may set fields other than id and contract.
32
+ * Changing id or contract is invalid-input and does not write. A thrown
33
+ * initialize does not write.
34
+ */
35
+ create(title: string, id?: string, initialize?: (project: CreationProject) => void): Promise<CreationProject>;
36
+ /**
37
+ * Apply one project transaction. Omit expectedVersion to change the current
38
+ * committed project. A provided version must be a positive safe integer and
39
+ * match before the callback runs. invalid-input, project-conflict, or a
40
+ * thrown callback leaves the committed project unchanged and does not keep
41
+ * callback mutations. Returning false keeps the current project and version
42
+ * and returns that committed snapshot. Changing id or contract is
43
+ * invalid-input and does not write. Each successful update stores
44
+ * committed.version + 1. The callback does not choose that version or the
45
+ * CAS expectedVersion. Reads return clones; overlapping updates apply one
46
+ * at a time.
47
+ */
48
+ update(id: string, change: (project: CreationProject) => unknown, expectedVersion?: number): Promise<CreationProject>;
49
+ /**
50
+ * Optional operator capability. Implementations must atomically persist the
51
+ * exact snapshot and its source/operation receipt; consumers must not emulate
52
+ * this with get/create when the capability is absent.
53
+ */
54
+ importSnapshot?(input: CreationSnapshotImportInput): Promise<CreationSnapshotImportReceipt>;
55
+ }
56
+ /** Injectable clock and id for the shared initial project record. */
57
+ export interface CreationProjectRecordOptions {
58
+ id?: string;
59
+ now?: string;
60
+ createId?: () => string;
61
+ }
62
+ /** Initial project record shared by every CreationRepository. Does not store or authorize. */
63
+ export declare function createCreationProjectRecord(title: string, options?: CreationProjectRecordOptions): CreationProject;
64
+ /**
65
+ * Validate an unknown stored project for one expected id.
66
+ * Errors do not include the body. The result is a deep copy.
67
+ */
68
+ export declare function readCreationProjectEnvelope(value: unknown, expectedId: string): CreationProject;
69
+ export type PreparedCreationSnapshotImport = Omit<CreationSnapshotImportReceipt, "importedAt"> & {
70
+ project: CreationProject;
71
+ };
72
+ /**
73
+ * Validate and freeze one import snapshot for a host-owned transaction.
74
+ * This pure helper does not authorize the source or persist the importedAt receipt.
75
+ */
76
+ export declare function prepareCreationSnapshotImport(input: CreationSnapshotImportInput): PreparedCreationSnapshotImport;
77
+ /** One project file is the transaction boundary. Unique claims avoid stale-lock unlink races. */
78
+ export declare class FileCreationRepository implements CreationRepository {
79
+ private readonly dir;
80
+ constructor(rootDir: string);
81
+ list(): Promise<CreationProjectSummary[]>;
82
+ listWithIssues(): Promise<{
83
+ projects: {
84
+ id: string;
85
+ title: string;
86
+ updatedAt: string;
87
+ artifactCount: number;
88
+ }[];
89
+ issues: {
90
+ projectId: string;
91
+ code: string;
92
+ message: string;
93
+ }[];
94
+ }>;
95
+ get(id: string): Promise<CreationProject>;
96
+ exportSnapshots(input?: {
97
+ assertSourceFrozen: () => unknown | Promise<unknown>;
98
+ }): Promise<CreationSnapshotExport>;
99
+ private captureSnapshotExport;
100
+ private readProject;
101
+ private readStoredProject;
102
+ private parseStoredProject;
103
+ create(title: string, id?: string, initialize?: (project: CreationProject) => void): Promise<CreationProject>;
104
+ update(id: string, change: (project: CreationProject) => unknown, expectedVersion?: number): Promise<CreationProject>;
105
+ importSnapshot(input: CreationSnapshotImportInput): Promise<CreationSnapshotImportReceipt>;
106
+ private path;
107
+ private findSnapshotImport;
108
+ private lockSnapshotSource;
109
+ private lock;
110
+ private write;
111
+ }
112
+ export declare function findCreationArtifact(project: CreationProject, id: string): CreationArtifact;
113
+ export declare function findCreationRevision(project: CreationProject, reference: CreationReference): CreationRevision;
114
+ export declare function appendCreationRevision(project: CreationProject, artifact: CreationArtifact, source: CreationContent, expectedRevisionId: string | null, extra?: Partial<Pick<CreationRevision, "references" | "sourceIds" | "runId" | "restoredFrom" | "brandRevisionId" | "themeRevisionId" | "copySources" | "factSources">>): CreationRevision;
115
+ export declare function readCreationDesignPreferences(value: unknown): CreationDesignPreferences;
116
+ export declare function appendCreationSource(project: CreationProject, input: {
117
+ title: string;
118
+ content: string;
119
+ kind: "reference" | "brand";
120
+ design?: CreationDesignPreferences;
121
+ }): CreationSource;
@@ -0,0 +1,13 @@
1
+ import type { CreationContent } from "@uibot/contracts";
2
+ import { type CreationRepository } from "./creation-store.js";
3
+ /**
4
+ * Project theme routes, mounted beside the brand routes:
5
+ * POST /projects/:id/theme save a version (or restore one)
6
+ * GET /projects/:id/theme/:revisionId read one version
7
+ * POST /projects/:id/artifacts/:artifactId/theme apply a version as a new artifact revision
8
+ * Returns null for any other path so the router can continue.
9
+ */
10
+ export declare function createCreationThemeHandler(options: {
11
+ repository: CreationRepository;
12
+ validate(source: CreationContent, kind: string, strict?: boolean): Promise<void>;
13
+ }): (request: Request, projectId: string, resource: string, resourceId?: string, action?: string) => Promise<Response | null>;
@@ -0,0 +1,16 @@
1
+ import { type CreationContent, type CreationProject, type CreationThemeRevision } from "@uibot/contracts";
2
+ type ThemeInput = Omit<CreationThemeRevision, "id" | "number" | "createdAt">;
3
+ /** Validate untrusted theme input. Only whitelisted shapes survive; CSS is never passed through. */
4
+ export declare function readThemeInput(value: unknown): ThemeInput;
5
+ export declare function themeRevision(project: CreationProject, id: string): CreationThemeRevision;
6
+ export declare function appendTheme(project: CreationProject, expected: unknown, value: ThemeInput): void;
7
+ /** Variables for the light scheme plus shape/type, then the dark overrides. */
8
+ export declare function themeCss(revision: CreationThemeRevision): string;
9
+ /** Insert (or replace) the single theme stylesheet at the end of `<head>` so it wins the cascade. */
10
+ export declare function materializeThemeHtml(html: string, revision: CreationThemeRevision): string;
11
+ /** Specs carry the flat resolved variables under `design.tokens`/`darkTokens`. */
12
+ export declare function materializeThemeSpec(source: string, revision: CreationThemeRevision): string;
13
+ export declare function applyThemeToContent(source: CreationContent, revision: CreationThemeRevision): CreationContent;
14
+ /** Prompt addition so generated markup uses the variables the theme defines. */
15
+ export declare function themePromptSection(revision: CreationThemeRevision): string;
16
+ export {};
@@ -0,0 +1,15 @@
1
+ import { CREATION_DATA_WEB_PROTOCOL, CREATION_DATA_WEB_V2_PROTOCOL } from "@uibot/contracts";
2
+ export interface CreationWebDataGenerationGrant {
3
+ readonly protocol: typeof CREATION_DATA_WEB_PROTOCOL | typeof CREATION_DATA_WEB_V2_PROTOCOL;
4
+ /** The host-injected browser client name; usually __uibotData. */
5
+ readonly alias: string;
6
+ readonly entities: readonly {
7
+ /** Host-approved entity alias, not a storage table name. */
8
+ readonly alias: string;
9
+ /** Host-approved field aliases visible to this generated document. */
10
+ readonly fields: readonly string[];
11
+ readonly operations: readonly ("list" | "get" | "create" | "update" | "remove")[];
12
+ }[];
13
+ }
14
+ /** Turn a bounded, structured host grant into a prompt. No host prose crosses this seam. */
15
+ export declare function creationWebDataPrompt(grant: CreationWebDataGenerationGrant): string;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Discovery Form 协议 —— v2.15 Playground demo 模式(prototype / deck)的前置约束。
3
+ *
4
+ * 目的:让 LLM 在 demo 模式的第一轮不要直接动手出 artifact,而是先 emit 一个
5
+ * `<question-form>` 块让用户用 30 秒勾选关键决策(受众、平台、调性、品牌、规模等),
6
+ * 把"模型 freestyle"收敛成"用户填表 + 模型按表执行"。
7
+ *
8
+ * 该协议借鉴 open-design `packages/contracts/src/prompts/discovery.ts` 的 RULE 1:
9
+ * 第一轮必须发表单,跳过的 narrow case 只有 (a) 用户消息以 `[form answers — `
10
+ * 开头(已收到答案),(b) 用户明确说"skip questions / 直接出"。
11
+ *
12
+ * Spec 模式(UIBotSpec YAML 生成"真品")不注入此协议——它已经有自己的 YAML+HTML
13
+ * 双 artifact 输出契约,不需要前置表单。
14
+ */
15
+ /** Playground 生成模式。spec=UIBotSpec 真品,prototype/deck=单 HTML demo。 */
16
+ export type PlaygroundMode = "spec" | "prototype" | "deck";
17
+ export declare const DISCOVERY_FORM_TAG = "question-form";
18
+ export declare const DISCOVERY_ANSWER_PREFIX = "[form answers \u2014";
19
+ /**
20
+ * 返回应该注入到 system prompt 的 Discovery Form 协议段。
21
+ *
22
+ * @param mode Playground 模式
23
+ * @returns prompt 段;spec 模式返回 null(不注入)
24
+ */
25
+ export declare function getDiscoveryProtocolSection(mode: PlaygroundMode | undefined): string | null;
@@ -0,0 +1,19 @@
1
+ import type { Catalog, ComponentArtifact, CompileResult, UIBotSpec } from "@uibot/contracts";
2
+ export interface GapResolutionInstallResult {
3
+ catalogPatch: Partial<Catalog>;
4
+ artifactLock: {
5
+ name: string;
6
+ version: string;
7
+ };
8
+ }
9
+ export interface GapResolutionServices {
10
+ compile(spec: UIBotSpec, catalog: Catalog): Promise<CompileResult> | CompileResult;
11
+ requestComponent(missingType: string, context?: string): Promise<ComponentArtifact>;
12
+ installArtifact(artifact: ComponentArtifact): Promise<GapResolutionInstallResult>;
13
+ }
14
+ export interface GapResolutionResult {
15
+ catalog: Catalog;
16
+ compileResult: CompileResult;
17
+ installedArtifacts: GapResolutionInstallResult["artifactLock"][];
18
+ }
19
+ export declare function compileWithGapRecovery(spec: UIBotSpec, catalog: Catalog, services: GapResolutionServices, maxIterations?: number): Promise<GapResolutionResult>;
@@ -0,0 +1,37 @@
1
+ import type { PlaygroundMode } from "./discovery-protocol.js";
2
+ export declare const GROUNDED_FORM_ID = "grounded";
3
+ export declare const GROUNDED_ANSWER_PREFIX = "[form answers \u2014 grounded]";
4
+ export type GroundedLane = "admin" | "marketing" | "ops" | "unknown";
5
+ export type GroundedPain = "density-too-high" | "unclear-hierarchy" | "thumb-reach" | "empty-state";
6
+ export interface GroundedBrief {
7
+ lane: GroundedLane;
8
+ pains: GroundedPain[];
9
+ hierarchy?: {
10
+ primary: string;
11
+ };
12
+ density?: "compact" | "comfortable" | "sparse";
13
+ touch?: {
14
+ primaryCtaMinPt: number;
15
+ };
16
+ empty?: "guided";
17
+ confidence: "high" | "low";
18
+ }
19
+ export type ResolvedGenerateIntent = {
20
+ kind: "generate";
21
+ intent: string;
22
+ brief: GroundedBrief;
23
+ } | {
24
+ kind: "confirm";
25
+ form: string;
26
+ brief: GroundedBrief;
27
+ } | {
28
+ kind: "passthrough";
29
+ intent: string;
30
+ };
31
+ export declare function translateGroundedBrief(intent: string): GroundedBrief;
32
+ export declare function serializeGroundedBrief(brief: GroundedBrief): string;
33
+ export declare function parseGroundedBrief(text: string): GroundedBrief | null;
34
+ export declare function briefSearchText(brief: GroundedBrief): string;
35
+ export declare function groundedConfirmationForm(_brief: GroundedBrief): string;
36
+ export declare function resolveGenerateIntent(intent: string, mode?: PlaygroundMode): ResolvedGenerateIntent;
37
+ export declare function groundedExecuteInstruction(brief: GroundedBrief): string;
@@ -0,0 +1,14 @@
1
+ import type { StoredApi } from "./session-store.js";
2
+ export interface PreviewGatewayConfig {
3
+ nowapiUrl?: string;
4
+ nowapiApiKey?: string;
5
+ serverAllowlist: StoredApi[];
6
+ }
7
+ export declare function parsePreviewApiAllowlist(raw: string | undefined): {
8
+ ok: true;
9
+ apis: StoredApi[];
10
+ } | {
11
+ ok: false;
12
+ error: string;
13
+ };
14
+ export declare function resolvePreviewGatewayConfig(env?: Record<string, string | undefined>): PreviewGatewayConfig;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Server-only HTML preview factory shared by the backend and external hosts.
3
+ * Browsers must not import this module. Opening a preview URL is not authorization.
4
+ */
5
+ export declare const HTML_PREVIEW_IFRAME_SANDBOX = "allow-scripts";
6
+ export { parsePreviewApiAllowlist, resolvePreviewGatewayConfig, type PreviewGatewayConfig, } from "./config.js";
7
+ export { LINK_INTERCEPTOR_SCRIPT } from "./link-interceptor.js";
8
+ export { createPreviewProxyHandler, type CreatePreviewProxyHandlerOptions } from "./proxy.js";
9
+ export { loadTailwindInline, renderPage, renderShell } from "./render.js";
10
+ export { createPreviewRoutes, type PreviewRoutesOptions } from "./routes.js";
11
+ export { createSessionStore, type SessionRole, type SessionStoreOptions, type StoredApi, type StoredPage, type StoredProject, type StoredSession, } from "./session-store.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Script injected into every preview page. Intercepts link clicks, form GETs,
3
+ * and programmatic navigation, posting the intent to the parent iframe shell
4
+ * via postMessage instead of letting the browser navigate the iframe.
5
+ *
6
+ * Origin for the iframe is opaque (sandbox="allow-scripts" without
7
+ * allow-same-origin), so the iframe can't read the parent and vice-versa —
8
+ * postMessage is the only safe channel.
9
+ */
10
+ export declare const LINK_INTERCEPTOR_SCRIPT = "<script>\n(function(){\n function isExternal(href){\n return /^(https?:|\\/\\/|mailto:|tel:)/i.test(href);\n }\n function report(to){\n try{window.parent.postMessage(JSON.stringify({__uibot_nav:true,to:to}),\"*\");}catch(e){}\n }\n function isLocalFormAction(form,submitter){\n var action=submitter&&submitter.getAttribute(\"formaction\");\n if(action===null||action===undefined)action=form.getAttribute(\"action\");\n return action===null||action.trim()===\"\"||action.trim().charAt(0)===\"#\";\n }\n function isSubmitControl(control){\n return control&&(\n control.tagName===\"BUTTON\"&&control.type===\"submit\"||\n control.tagName===\"INPUT\"&&(control.type===\"submit\"||control.type===\"image\")\n );\n }\n function submitLocalForm(form,submitter){\n if(!form.checkValidity()){\n form.reportValidity();\n return;\n }\n form.dispatchEvent(new SubmitEvent(\"submit\",{\n bubbles:true,cancelable:true,submitter:submitter||null\n }));\n }\n // <a> clicks\n document.addEventListener(\"click\",function(e){\n if(window.__uibotAnnotationActive)return;\n var a=e.target.closest(\"a[href]\");\n if(!a||a.target===\"_blank\")return;\n var href=a.getAttribute(\"href\");\n if(!href||href.charAt(0)===\"#\"||isExternal(href))return;\n e.preventDefault();\n report(href);\n },true);\n // Sandboxed previews block native form submission before local handlers run.\n document.addEventListener(\"click\",function(e){\n if(window.__uibotAnnotationActive)return;\n if(e.defaultPrevented)return;\n var control=e.target.closest(\"button,input\");\n if(!isSubmitControl(control)||control.disabled||!control.form||!isLocalFormAction(control.form,control))return;\n e.preventDefault();\n submitLocalForm(control.form,control);\n });\n // Enter in a text input is an implicit submit, including forms without a button.\n document.addEventListener(\"keydown\",function(e){\n if(e.defaultPrevented||e.key!==\"Enter\"||e.isComposing||\n e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;\n var input=e.target;\n if(!input||input.tagName!==\"INPUT\"||input.disabled||input.readOnly||input.isContentEditable)return;\n var type=input.type||\"text\";\n if([\"text\",\"search\",\"email\",\"url\",\"tel\",\"password\",\"number\",\"date\",\"month\",\"week\",\"time\",\"datetime-local\"].indexOf(type)===-1)return;\n var form=input.form;\n if(!form)return;\n var submitter=null;\n var blockingInputs=0;\n for(var i=0;i<form.elements.length;i++){\n var control=form.elements[i];\n if(!submitter&&isSubmitControl(control))submitter=control;\n if(control.tagName===\"INPUT\"&&[\"text\",\"search\",\"email\",\"url\",\"tel\",\"password\",\"number\",\"date\",\"month\",\"week\",\"time\",\"datetime-local\"].indexOf(control.type) !== -1)blockingInputs++;\n }\n if(submitter&&submitter.disabled)return;\n if(!submitter&&blockingInputs>1)return;\n if(!isLocalFormAction(form,submitter))return;\n e.preventDefault();\n submitLocalForm(form,submitter);\n });\n // form GET submits\n document.addEventListener(\"submit\",function(e){\n var f=e.target;\n if(f&&f.tagName===\"FORM\"&&isLocalFormAction(f,e.submitter)){\n e.preventDefault();\n return;\n }\n if(!f||!f.action||(f.method||\"GET\").toUpperCase()!==\"GET\")return;\n if(isExternal(f.action))return;\n e.preventDefault();\n report(f.action);\n },true);\n // Programmatic navigation shims\n [\"assign\",\"replace\"].forEach(function(m){\n var orig=location[m].bind(location);\n location[m]=function(u){\n if(typeof u===\"string\"&&u.charAt(0)!==\"#\"&&!isExternal(u)){\n report(u);\n return;\n }\n return orig(u);\n };\n });\n})();\n</script>";
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Same-origin proxy for Playground preview (v2.13.1).
3
+ *
4
+ * Replaces the former mock runtime: iframe-generated HTML sends `/api/*`
5
+ * requests, the in-iframe PathRewrite script rewrites them to
6
+ * `/preview/api/:sid/*`, and this handler forwards to the real NowAPI
7
+ * gateway. No mock fallback — memory `feedback_no_mock_preview` freeze.
8
+ *
9
+ * Responsibilities:
10
+ * - Look up session by `:sid`, enforce path + method allowlist against
11
+ * `session.project.apis`
12
+ * - Forward to `gatewayUrl` with `Authorization: Bearer <apiKey>` header,
13
+ * filter Host/Origin/Cookie to prevent gateway auth confusion
14
+ * - Stamp `Access-Control-Allow-Origin: null` so the opaque-origin iframe
15
+ * can read the response
16
+ * - Structured JSON errors for all failure modes (never fabricate data)
17
+ */
18
+ import type { StoredApi } from "./session-store.js";
19
+ type StoredSessionLike = {
20
+ project: {
21
+ apis: ReadonlyArray<StoredApi>;
22
+ };
23
+ };
24
+ export interface CreatePreviewProxyHandlerOptions {
25
+ /**
26
+ * Session store — only `.get(sid)` is required. Typed loosely so the
27
+ * handler stays framework-neutral.
28
+ */
29
+ sessions: {
30
+ get(id: string): StoredSessionLike | undefined;
31
+ };
32
+ /**
33
+ * NowAPI gateway base URL (e.g. `https://nowapi.internal`). When absent,
34
+ * every call fails fast with `gateway-url-missing` — no mock fallback.
35
+ */
36
+ gatewayUrl?: string;
37
+ /**
38
+ * Server-held maximum allowlist. A request must match both this policy and
39
+ * the session project allowlist before any API key is injected.
40
+ */
41
+ serverAllowlist?: ReadonlyArray<StoredApi>;
42
+ /**
43
+ * Bearer token injected as `Authorization: Bearer <apiKey>` on upstream
44
+ * requests. Never relayed back to the browser. Optional — public NowAPI
45
+ * endpoints may not require auth.
46
+ */
47
+ apiKey?: string;
48
+ /** Upstream request deadline. Defaults to 10_000ms. */
49
+ timeoutMs?: number;
50
+ }
51
+ /**
52
+ * Build a proxy handler. Callers should pre-filter by `/preview/api/`
53
+ * prefix in their dispatcher; this handler returns 404 for non-matching
54
+ * paths just in case.
55
+ */
56
+ export declare function createPreviewProxyHandler(options: CreatePreviewProxyHandlerOptions): (req: Request) => Promise<Response>;
57
+ export {};
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Preview HTML rendering. Produces the SPA shell (`/preview/shell/:sid`) and
3
+ * individual page documents (`/preview/page/:sid/:pageId`). Under opaque-origin
4
+ * sandboxing, the iframe cannot fetch parent-origin endpoints — Tailwind Play
5
+ * is inlined, link interception is injected. As of v2.13.1, API calls are
6
+ * rewritten by the path-rewrite runtime (Sprint 2) and proxied through
7
+ * `/preview/api/:sid/*` to the real NowAPI gateway. No mock runtime.
8
+ */
9
+ import type { StoredApi, StoredSession } from "./session-store.js";
10
+ export declare function loadTailwindInline(path: string): Promise<string>;
11
+ /**
12
+ * Path-rewrite runtime (v2.13.1): rewrites every `/api/*` fetch and form
13
+ * action inside the preview iframe to `/preview/api/:sid/*` so the browser
14
+ * routes them to the backend same-origin proxy. Never fabricates data —
15
+ * failures surface as real HTTP errors (see memory
16
+ * `feedback_no_mock_preview`).
17
+ *
18
+ * Injected as the first inline script in `<head>` so it wins before any
19
+ * AI-generated code reads `window.fetch`.
20
+ */
21
+ declare function buildPathRewriteScript(sid: string): string;
22
+ export { buildPathRewriteScript };
23
+ /**
24
+ * Render a single page document. Injects Tailwind Play inline, the
25
+ * path-rewrite runtime (replaces the old mock runtime — v2.13.1), the
26
+ * session bridge, and the link interceptor. AI-generated HTML is trusted
27
+ * in shape but sandboxed by opaque origin.
28
+ *
29
+ * `apis` currently informs upstream allowlist enforcement on the proxy
30
+ * side (see `proxy.ts`); it is kept in the signature as future-proofing
31
+ * even though path rewriting itself is session-id-driven.
32
+ */
33
+ export declare function renderPage(sid: string, pageHtml: string, _apis: StoredApi[], tailwindInline: string): string;
34
+ /**
35
+ * Render the SPA shell wrapping all project pages. Inner frames reference
36
+ * `/preview/page/:sid/:pageId` via src, not srcdoc — same opaque-origin
37
+ * isolation with normal HTTP fetch semantics (CSP allows self).
38
+ */
39
+ export declare function renderShell(sid: string, sess: StoredSession): string;