@dbx-tools/appkit-generator 0.0.0-stage → 0.9.138
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/LICENSE +202 -0
- package/README.md +181 -2
- package/index.ts +44 -0
- package/lib/index.d.ts +40 -0
- package/lib/index.js +30 -0
- package/lib/src/assets.d.ts +33 -0
- package/lib/src/assets.js +224 -0
- package/lib/src/config.d.ts +75 -0
- package/lib/src/config.js +31 -0
- package/lib/src/dashboard.d.ts +30 -0
- package/lib/src/dashboard.js +257 -0
- package/lib/src/data.d.ts +17 -0
- package/lib/src/data.js +114 -0
- package/lib/src/defaults.d.ts +39 -0
- package/lib/src/defaults.js +36 -0
- package/lib/src/generate.d.ts +51 -0
- package/lib/src/generate.js +163 -0
- package/lib/src/genie.d.ts +51 -0
- package/lib/src/genie.js +84 -0
- package/lib/src/kpi.d.ts +22 -0
- package/lib/src/kpi.js +74 -0
- package/lib/src/manifest.json +72 -0
- package/lib/src/namespace.d.ts +36 -0
- package/lib/src/namespace.js +119 -0
- package/lib/src/operations.d.ts +42 -0
- package/lib/src/operations.js +96 -0
- package/lib/src/palette.d.ts +10 -0
- package/lib/src/palette.js +69 -0
- package/lib/src/plan.d.ts +21 -0
- package/lib/src/plan.js +33 -0
- package/lib/src/plugin.d.ts +619 -0
- package/lib/src/plugin.js +205 -0
- package/lib/src/research.d.ts +78 -0
- package/lib/src/research.js +235 -0
- package/lib/src/schema.d.ts +52 -0
- package/lib/src/schema.js +82 -0
- package/lib/src/structured.d.ts +27 -0
- package/lib/src/structured.js +30 -0
- package/lib/src/workflow.d.ts +314 -0
- package/lib/src/workflow.js +171 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +218 -4
- package/src/assets.ts +248 -0
- package/src/config.ts +98 -0
- package/src/dashboard.ts +295 -0
- package/src/data.ts +167 -0
- package/src/defaults.ts +61 -0
- package/src/generate.ts +250 -0
- package/src/genie.ts +111 -0
- package/src/kpi.ts +106 -0
- package/src/manifest.json +72 -0
- package/src/namespace.ts +192 -0
- package/src/operations.ts +171 -0
- package/src/palette.ts +81 -0
- package/src/plan.ts +59 -0
- package/src/plugin.ts +244 -0
- package/src/research.ts +382 -0
- package/src/schema.ts +114 -0
- package/src/structured.ts +54 -0
- package/src/workflow.ts +221 -0
package/src/schema.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing profile contract and AppKit tool description for researched
|
|
3
|
+
* brand generation. Browser-safe request, event, and package contracts are
|
|
4
|
+
* owned by `@dbx-tools/shared-generator`.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { stringUtils } from "@dbx-tools/shared-core";
|
|
10
|
+
import type { BrandGenerationRequest as SharedBrandGenerationRequest } from "@dbx-tools/shared-generator/brand";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
BrandGenerationErrorEventSchema,
|
|
15
|
+
BrandGenerationEventSchema,
|
|
16
|
+
BrandGenerationProgressEventSchema,
|
|
17
|
+
BrandGenerationRequestSchema,
|
|
18
|
+
BrandGenerationResultEventSchema,
|
|
19
|
+
BrandGenerationStageSchema,
|
|
20
|
+
BrandPackageSchema,
|
|
21
|
+
BrandPackageSourceSchema,
|
|
22
|
+
BrandVisualImageSchema,
|
|
23
|
+
BrandVisualReferenceSchema,
|
|
24
|
+
} from "@dbx-tools/shared-generator/brand";
|
|
25
|
+
export type {
|
|
26
|
+
BrandGenerationErrorEvent,
|
|
27
|
+
BrandGenerationEvent,
|
|
28
|
+
BrandGenerationProgressEvent,
|
|
29
|
+
BrandGenerationRequest,
|
|
30
|
+
BrandGenerationResultEvent,
|
|
31
|
+
BrandGenerationStage,
|
|
32
|
+
BrandPackage,
|
|
33
|
+
BrandPackageSource,
|
|
34
|
+
BrandVisualImage,
|
|
35
|
+
BrandVisualReference,
|
|
36
|
+
} from "@dbx-tools/shared-generator/brand";
|
|
37
|
+
|
|
38
|
+
const nonBlankString = z.string().trim().min(1);
|
|
39
|
+
const color = z.string().regex(/^#(?:[\da-f]{3}|[\da-f]{6}|[\da-f]{8})$/i, "Expected a hex color.");
|
|
40
|
+
|
|
41
|
+
/** Resolve the human-readable subject from a validated brand request. */
|
|
42
|
+
export function brandRequestSubject(request: SharedBrandGenerationRequest): string {
|
|
43
|
+
return request.name ?? request.prompt!;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Description shared by the native AppKit brand-generation tool. */
|
|
47
|
+
export const GENERATE_BRAND_TOOL_DESCRIPTION = stringUtils.toDescription(`
|
|
48
|
+
Research a named organization or product on the web and generate a portable
|
|
49
|
+
branding package. The result includes a validated BrandContext for
|
|
50
|
+
application and email presentation plus the sources used. Supply the
|
|
51
|
+
official website when known to disambiguate brands with similar names.
|
|
52
|
+
`);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Structured model output before deterministic asset references and schema
|
|
56
|
+
* metadata are attached.
|
|
57
|
+
*/
|
|
58
|
+
export const GeneratedBrandProfileSchema = z
|
|
59
|
+
.object({
|
|
60
|
+
name: nonBlankString.describe("Canonical display name supported by the sources."),
|
|
61
|
+
shortName: nonBlankString.describe("Compact brand name suitable for constrained UI."),
|
|
62
|
+
tagline: nonBlankString.describe("Short brand line suitable for a header or metadata."),
|
|
63
|
+
description: nonBlankString.describe("Plain-language description of the brand."),
|
|
64
|
+
colors: z
|
|
65
|
+
.object({
|
|
66
|
+
primary: color.describe("Primary identity color."),
|
|
67
|
+
primaryHover: color.describe("Accessible hover or pressed color for the primary color."),
|
|
68
|
+
accent: color.describe("Secondary accent color."),
|
|
69
|
+
foreground: color.describe("Default high-contrast text and mark color."),
|
|
70
|
+
background: color.describe("Default page background."),
|
|
71
|
+
surface: color.describe("Secondary surface background."),
|
|
72
|
+
muted: color.describe("Muted text color with readable contrast."),
|
|
73
|
+
border: color.describe("Default border color."),
|
|
74
|
+
})
|
|
75
|
+
.strict()
|
|
76
|
+
.describe("Usable interface palette based on the researched identity."),
|
|
77
|
+
typography: z
|
|
78
|
+
.object({
|
|
79
|
+
sans: nonBlankString.describe("CSS font-family stack for normal interface text."),
|
|
80
|
+
mono: nonBlankString.describe("CSS font-family stack for code and tabular text."),
|
|
81
|
+
})
|
|
82
|
+
.strict()
|
|
83
|
+
.describe("Brand-compatible CSS font stacks."),
|
|
84
|
+
voice: z
|
|
85
|
+
.object({
|
|
86
|
+
audience: z
|
|
87
|
+
.array(nonBlankString)
|
|
88
|
+
.describe("Primary audiences explicitly supported by the sources."),
|
|
89
|
+
tone: z.array(nonBlankString).describe("Concise descriptors for the brand's writing tone."),
|
|
90
|
+
principles: z
|
|
91
|
+
.array(nonBlankString)
|
|
92
|
+
.describe("Concrete rules for writing in the brand voice."),
|
|
93
|
+
avoid: z.array(nonBlankString).describe("Writing patterns the brand should avoid."),
|
|
94
|
+
})
|
|
95
|
+
.strict()
|
|
96
|
+
.describe("Evidence-based writing voice guidance."),
|
|
97
|
+
links: z
|
|
98
|
+
.object({
|
|
99
|
+
website: z.string().url().describe("Official brand website."),
|
|
100
|
+
repository: z.string().url().optional().describe("Official source repository, if any."),
|
|
101
|
+
documentation: z
|
|
102
|
+
.string()
|
|
103
|
+
.url()
|
|
104
|
+
.optional()
|
|
105
|
+
.describe("Official documentation site, if distinct from the website."),
|
|
106
|
+
})
|
|
107
|
+
.strict()
|
|
108
|
+
.describe("Verified first-party brand links."),
|
|
109
|
+
})
|
|
110
|
+
.strict()
|
|
111
|
+
.describe("Evidence-based brand profile produced by the synthesis model.");
|
|
112
|
+
|
|
113
|
+
/** Structured model output before deterministic package assembly. */
|
|
114
|
+
export type GeneratedBrandProfile = z.infer<typeof GeneratedBrandProfileSchema>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mastra-backed prompt-injected structured generation.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { WorkspaceClient } from "@databricks/appkit";
|
|
8
|
+
import { buildModel, RESPONSES_PROVIDER_OPTIONS } from "@dbx-tools/appkit-mastra/model";
|
|
9
|
+
import { Agent } from "@mastra/core/agent";
|
|
10
|
+
import type { MessageListInput } from "@mastra/core/agent/message-list";
|
|
11
|
+
import type { z } from "zod";
|
|
12
|
+
|
|
13
|
+
/** Options for one isolated structured synthesis pass. */
|
|
14
|
+
export interface StructuredGenerationOptions<TSchema extends z.ZodType> {
|
|
15
|
+
/** Stable operation identifier. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Trusted system instructions. */
|
|
18
|
+
instructions: string;
|
|
19
|
+
/** Data-only prompt. */
|
|
20
|
+
prompt: MessageListInput;
|
|
21
|
+
/** Zod-owned output contract. */
|
|
22
|
+
schema: TSchema;
|
|
23
|
+
/** Optional model preference. */
|
|
24
|
+
model?: string;
|
|
25
|
+
/** Explicit workspace client for standalone callers. */
|
|
26
|
+
workspaceClient?: WorkspaceClient;
|
|
27
|
+
/** External cancellation. */
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Generate and validate one structured object without provider response-format APIs. */
|
|
32
|
+
export async function generateStructured<TSchema extends z.ZodType>(
|
|
33
|
+
options: StructuredGenerationOptions<TSchema>,
|
|
34
|
+
): Promise<z.output<TSchema>> {
|
|
35
|
+
const model = await buildModel({ modelOverride: false }, undefined, {
|
|
36
|
+
...(options.model ? { modelId: options.model } : {}),
|
|
37
|
+
...(options.workspaceClient ? { workspaceClient: options.workspaceClient } : {}),
|
|
38
|
+
});
|
|
39
|
+
const agent = new Agent({
|
|
40
|
+
id: options.id,
|
|
41
|
+
name: options.id,
|
|
42
|
+
instructions: options.instructions,
|
|
43
|
+
model,
|
|
44
|
+
});
|
|
45
|
+
const result = await agent.generate(options.prompt, {
|
|
46
|
+
structuredOutput: {
|
|
47
|
+
schema: options.schema,
|
|
48
|
+
jsonPromptInjection: "system",
|
|
49
|
+
},
|
|
50
|
+
providerOptions: RESPONSES_PROVIDER_OPTIONS,
|
|
51
|
+
...(options.signal ? { abortSignal: options.signal } : {}),
|
|
52
|
+
});
|
|
53
|
+
return options.schema.parse(result.object);
|
|
54
|
+
}
|
package/src/workflow.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mastra workflow composing reusable generator operations.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { BrandPackageSchema, type BrandGenerationRequest } from "@dbx-tools/shared-generator/brand";
|
|
8
|
+
import { KpiResearchResultSchema } from "@dbx-tools/shared-generator/kpi";
|
|
9
|
+
import {
|
|
10
|
+
GeneratedAssetsSchema,
|
|
11
|
+
GeneratedSchemaSchema,
|
|
12
|
+
GeneratorPlanSchema,
|
|
13
|
+
GeneratorRequestSchema,
|
|
14
|
+
MaterializedGeneratorDataSchema,
|
|
15
|
+
} from "@dbx-tools/shared-generator/workflow";
|
|
16
|
+
import { createStep, createWorkflow } from "@mastra/core/workflows";
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
import type { GeneratorOperations } from "./operations.ts";
|
|
19
|
+
|
|
20
|
+
/** Operation surface consumed by the workflow and implemented by GeneratorOperations. */
|
|
21
|
+
export type GeneratorWorkflowOperations = Pick<
|
|
22
|
+
GeneratorOperations,
|
|
23
|
+
| "generateBrand"
|
|
24
|
+
| "researchKpis"
|
|
25
|
+
| "planData"
|
|
26
|
+
| "provisionSchema"
|
|
27
|
+
| "materializeData"
|
|
28
|
+
| "createDashboard"
|
|
29
|
+
| "createGenie"
|
|
30
|
+
>;
|
|
31
|
+
|
|
32
|
+
/** Construction options for workflow hosts and isolated tests. */
|
|
33
|
+
export interface GeneratorWorkflowOptions {
|
|
34
|
+
/** Suspend before mutations. Defaults to true. */
|
|
35
|
+
approval?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const ResearchOutputSchema = z
|
|
39
|
+
.object({
|
|
40
|
+
request: GeneratorRequestSchema,
|
|
41
|
+
brand: BrandPackageSchema,
|
|
42
|
+
kpiResearch: KpiResearchResultSchema,
|
|
43
|
+
})
|
|
44
|
+
.strict();
|
|
45
|
+
|
|
46
|
+
const PlanOutputSchema = ResearchOutputSchema.extend({
|
|
47
|
+
plan: GeneratorPlanSchema,
|
|
48
|
+
}).strict();
|
|
49
|
+
|
|
50
|
+
const ProvisionOutputSchema = PlanOutputSchema.extend({
|
|
51
|
+
location: GeneratedSchemaSchema,
|
|
52
|
+
}).strict();
|
|
53
|
+
|
|
54
|
+
const MaterializeOutputSchema = ProvisionOutputSchema.extend({
|
|
55
|
+
materialized: MaterializedGeneratorDataSchema,
|
|
56
|
+
}).strict();
|
|
57
|
+
|
|
58
|
+
/** Build one typed workflow over an isolated generator operation owner. */
|
|
59
|
+
export function createGeneratorWorkflow(
|
|
60
|
+
operations: GeneratorWorkflowOperations,
|
|
61
|
+
options: GeneratorWorkflowOptions = {},
|
|
62
|
+
) {
|
|
63
|
+
const research = createStep({
|
|
64
|
+
id: "research-brand-and-kpis",
|
|
65
|
+
inputSchema: GeneratorRequestSchema,
|
|
66
|
+
outputSchema: ResearchOutputSchema,
|
|
67
|
+
execute: async ({ inputData, abortSignal, writer }) => {
|
|
68
|
+
await writer?.write({ type: "generator-progress", stage: "research", status: "started" });
|
|
69
|
+
const brandRequest: BrandGenerationRequest = {
|
|
70
|
+
name: inputData.company,
|
|
71
|
+
...(inputData.website ? { website: inputData.website } : {}),
|
|
72
|
+
};
|
|
73
|
+
const [brand, kpiResearch] = await Promise.all([
|
|
74
|
+
operations.generateBrand(brandRequest, abortSignal),
|
|
75
|
+
operations.researchKpis(
|
|
76
|
+
{
|
|
77
|
+
company: inputData.company,
|
|
78
|
+
purpose: inputData.purpose,
|
|
79
|
+
queries: inputData.queries,
|
|
80
|
+
},
|
|
81
|
+
abortSignal,
|
|
82
|
+
),
|
|
83
|
+
]);
|
|
84
|
+
return { request: inputData, brand, kpiResearch };
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const plan = createStep({
|
|
89
|
+
id: "plan-demo-data",
|
|
90
|
+
inputSchema: ResearchOutputSchema,
|
|
91
|
+
outputSchema: PlanOutputSchema,
|
|
92
|
+
execute: async ({ inputData, abortSignal, writer }) => {
|
|
93
|
+
await writer?.write({ type: "generator-progress", stage: "plan", status: "started" });
|
|
94
|
+
const generatedPlan = await operations.planData(inputData, abortSignal);
|
|
95
|
+
return { ...inputData, plan: generatedPlan };
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const approval = createStep({
|
|
100
|
+
id: "approve-mutation-plan",
|
|
101
|
+
inputSchema: PlanOutputSchema,
|
|
102
|
+
outputSchema: PlanOutputSchema,
|
|
103
|
+
resumeSchema: z.object({
|
|
104
|
+
approved: z.boolean().describe("Whether the generated mutation plan is approved."),
|
|
105
|
+
}),
|
|
106
|
+
suspendSchema: z.object({
|
|
107
|
+
reason: z.string().describe("Why approval is required."),
|
|
108
|
+
plan: GeneratorPlanSchema,
|
|
109
|
+
}),
|
|
110
|
+
execute: async ({ inputData, resumeData, suspend }) => {
|
|
111
|
+
if (options.approval === false) return inputData;
|
|
112
|
+
if (resumeData === undefined) {
|
|
113
|
+
return suspend({
|
|
114
|
+
reason: "Approve schema, data, and presentation creation.",
|
|
115
|
+
plan: inputData.plan,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (!resumeData.approved) {
|
|
119
|
+
throw new Error("Generator mutation plan was rejected");
|
|
120
|
+
}
|
|
121
|
+
return inputData;
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const provision = createStep({
|
|
126
|
+
id: "provision-schema",
|
|
127
|
+
inputSchema: PlanOutputSchema,
|
|
128
|
+
outputSchema: ProvisionOutputSchema,
|
|
129
|
+
execute: async ({ inputData, abortSignal, writer }) => {
|
|
130
|
+
await writer?.write({ type: "generator-progress", stage: "schema", status: "started" });
|
|
131
|
+
const location = await operations.provisionSchema(
|
|
132
|
+
{
|
|
133
|
+
request: {
|
|
134
|
+
company: inputData.request.company,
|
|
135
|
+
purpose: inputData.request.purpose,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
abortSignal,
|
|
139
|
+
);
|
|
140
|
+
return { ...inputData, location };
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const materialize = createStep({
|
|
145
|
+
id: "materialize-and-validate-data",
|
|
146
|
+
inputSchema: ProvisionOutputSchema,
|
|
147
|
+
outputSchema: MaterializeOutputSchema,
|
|
148
|
+
execute: async ({ inputData, abortSignal, writer }) => {
|
|
149
|
+
await writer?.write({ type: "generator-progress", stage: "data", status: "started" });
|
|
150
|
+
const materialized = await operations.materializeData(
|
|
151
|
+
{
|
|
152
|
+
location: inputData.location,
|
|
153
|
+
plan: inputData.plan,
|
|
154
|
+
},
|
|
155
|
+
abortSignal,
|
|
156
|
+
);
|
|
157
|
+
return { ...inputData, materialized };
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const presentation = createStep({
|
|
162
|
+
id: "create-presentation",
|
|
163
|
+
inputSchema: MaterializeOutputSchema,
|
|
164
|
+
outputSchema: GeneratedAssetsSchema,
|
|
165
|
+
execute: async ({ inputData, abortSignal, writer }) => {
|
|
166
|
+
await writer?.write({
|
|
167
|
+
type: "generator-progress",
|
|
168
|
+
stage: "presentation",
|
|
169
|
+
status: "started",
|
|
170
|
+
});
|
|
171
|
+
const presentationInput = {
|
|
172
|
+
request: {
|
|
173
|
+
company: inputData.request.company,
|
|
174
|
+
purpose: inputData.request.purpose,
|
|
175
|
+
},
|
|
176
|
+
location: inputData.location,
|
|
177
|
+
plan: inputData.plan,
|
|
178
|
+
brand: inputData.brand,
|
|
179
|
+
};
|
|
180
|
+
if (inputData.request.presentation === "dashboard") {
|
|
181
|
+
const dashboard = await operations.createDashboard(presentationInput, abortSignal);
|
|
182
|
+
return GeneratedAssetsSchema.parse({
|
|
183
|
+
request: inputData.request,
|
|
184
|
+
schema: inputData.location,
|
|
185
|
+
tables: inputData.materialized.tables,
|
|
186
|
+
brand: inputData.brand,
|
|
187
|
+
kpiResearch: inputData.kpiResearch,
|
|
188
|
+
plan: inputData.plan,
|
|
189
|
+
dashboard,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const genie = await operations.createGenie(presentationInput, abortSignal);
|
|
193
|
+
return GeneratedAssetsSchema.parse({
|
|
194
|
+
request: inputData.request,
|
|
195
|
+
schema: inputData.location,
|
|
196
|
+
tables: inputData.materialized.tables,
|
|
197
|
+
brand: inputData.brand,
|
|
198
|
+
kpiResearch: inputData.kpiResearch,
|
|
199
|
+
plan: inputData.plan,
|
|
200
|
+
genie,
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return createWorkflow({
|
|
206
|
+
id: "generator-demo-assets",
|
|
207
|
+
inputSchema: GeneratorRequestSchema,
|
|
208
|
+
outputSchema: GeneratedAssetsSchema,
|
|
209
|
+
options: { autoRestartActiveRuns: false },
|
|
210
|
+
})
|
|
211
|
+
.then(research)
|
|
212
|
+
.then(plan)
|
|
213
|
+
.then(approval)
|
|
214
|
+
.then(provision)
|
|
215
|
+
.then(materialize)
|
|
216
|
+
.then(presentation)
|
|
217
|
+
.commit();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Generator workflow type. */
|
|
221
|
+
export type GeneratorWorkflow = ReturnType<typeof createGeneratorWorkflow>;
|