@dawn-ai/core 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/discovery/discover-routes.d.ts.map +1 -1
- package/dist/discovery/discover-routes.js +11 -2
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/state/resolve-state-fields.d.ts +7 -0
- package/dist/state/resolve-state-fields.d.ts.map +1 -0
- package/dist/state/resolve-state-fields.js +15 -0
- package/dist/typegen/extract-tool-schema.d.ts +7 -0
- package/dist/typegen/extract-tool-schema.d.ts.map +1 -0
- package/dist/typegen/extract-tool-schema.js +146 -0
- package/dist/typegen/extract-tool-types.d.ts.map +1 -1
- package/dist/typegen/extract-tool-types.js +9 -0
- package/dist/typegen/render-route-types.d.ts +2 -1
- package/dist/typegen/render-route-types.d.ts.map +1 -1
- package/dist/typegen/render-route-types.js +11 -5
- package/dist/typegen/render-state-types.d.ts +9 -0
- package/dist/typegen/render-state-types.d.ts.map +1 -0
- package/dist/typegen/render-state-types.js +15 -0
- package/dist/types.d.ts +35 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discover-routes.d.ts","sourceRoot":"","sources":["../../src/discovery/discover-routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"discover-routes.d.ts","sourceRoot":"","sources":["../../src/discovery/discover-routes.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,qBAAqB,EAAmB,aAAa,EAAE,MAAM,aAAa,CAAA;AAQxF,wBAAsB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,aAAa,CAAC,CAQhG"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readdir } from "node:fs/promises";
|
|
2
2
|
import { join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { isDawnAgent } from "@dawn-ai/sdk";
|
|
4
5
|
import { findDawnApp } from "./find-dawn-app.js";
|
|
5
6
|
import { isPrivateSegment, isRouteGroupSegment, toRouteSegments } from "./route-segments.js";
|
|
6
7
|
const INDEX_FILE = "index.ts";
|
|
@@ -61,12 +62,20 @@ async function readRouteEntry(routesDir, routeDir) {
|
|
|
61
62
|
async function inferRouteKind(indexFile) {
|
|
62
63
|
await registerTsxLoader();
|
|
63
64
|
const routeExports = await loadRouteExports(indexFile);
|
|
65
|
+
// Check default export for DawnAgent descriptor (preferred path)
|
|
66
|
+
if ("default" in routeExports && isDawnAgent(routeExports.default)) {
|
|
67
|
+
return "agent";
|
|
68
|
+
}
|
|
69
|
+
const hasAgent = "agent" in routeExports && routeExports.agent !== undefined;
|
|
64
70
|
const hasChain = "chain" in routeExports && routeExports.chain !== undefined;
|
|
65
71
|
const hasGraph = "graph" in routeExports && routeExports.graph !== undefined;
|
|
66
72
|
const hasWorkflow = "workflow" in routeExports && routeExports.workflow !== undefined;
|
|
67
|
-
const count = [hasChain, hasGraph, hasWorkflow].filter(Boolean).length;
|
|
73
|
+
const count = [hasAgent, hasChain, hasGraph, hasWorkflow].filter(Boolean).length;
|
|
68
74
|
if (count > 1) {
|
|
69
|
-
throw new Error(`Route index.ts must export exactly one of "workflow", "graph", or "chain"`);
|
|
75
|
+
throw new Error(`Route index.ts must export exactly one of "agent", "workflow", "graph", or "chain"`);
|
|
76
|
+
}
|
|
77
|
+
if (hasAgent) {
|
|
78
|
+
return "agent";
|
|
70
79
|
}
|
|
71
80
|
if (hasChain) {
|
|
72
81
|
return "chain";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,15 @@ export { loadDawnConfig } from "./config.js";
|
|
|
2
2
|
export { discoverRoutes } from "./discovery/discover-routes.js";
|
|
3
3
|
export { assertDawnRoutesDir, findDawnApp } from "./discovery/find-dawn-app.js";
|
|
4
4
|
export { isPrivateSegment, isRouteGroupSegment, toRouteSegments, } from "./discovery/route-segments.js";
|
|
5
|
+
export type { ResolveStateFieldsOptions } from "./state/resolve-state-fields.js";
|
|
6
|
+
export { resolveStateFields } from "./state/resolve-state-fields.js";
|
|
7
|
+
export type { ExtractToolSchemasOptions } from "./typegen/extract-tool-schema.js";
|
|
8
|
+
export { extractToolSchemasForRoute } from "./typegen/extract-tool-schema.js";
|
|
5
9
|
export type { ExtractToolTypesOptions } from "./typegen/extract-tool-types.js";
|
|
6
10
|
export { extractToolTypesForRoute } from "./typegen/extract-tool-types.js";
|
|
7
11
|
export { renderDawnTypes, renderRouteTypes } from "./typegen/render-route-types.js";
|
|
12
|
+
export type { RouteStateFields } from "./typegen/render-state-types.js";
|
|
13
|
+
export { renderStateTypes } from "./typegen/render-state-types.js";
|
|
8
14
|
export { renderToolTypes } from "./typegen/render-tool-types.js";
|
|
9
|
-
export type { DawnConfig, DiscoveredDawnApp, DiscoverRoutesOptions, ExtractedToolType, FindDawnAppOptions, LoadDawnConfigOptions, LoadedDawnConfig, RouteDefinition, RouteKind, RouteManifest, RouteSegment, RouteToolTypes, } from "./types.js";
|
|
15
|
+
export type { DawnConfig, DiscoveredDawnApp, DiscoverRoutesOptions, ExtractedToolSchema, ExtractedToolType, FindDawnAppOptions, JsonSchemaProperty, LoadDawnConfigOptions, LoadedDawnConfig, NormalizedRouteModule, ResolvedStateField, RouteDefinition, RouteKind, RouteManifest, RouteSegment, RouteToolSchemas, RouteToolTypes, StateFieldReducer, } from "./types.js";
|
|
10
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,8BAA8B,CA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vE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,iBAAiB,GAClB,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,9 @@ export { loadDawnConfig } from "./config.js";
|
|
|
2
2
|
export { discoverRoutes } from "./discovery/discover-routes.js";
|
|
3
3
|
export { assertDawnRoutesDir, findDawnApp } from "./discovery/find-dawn-app.js";
|
|
4
4
|
export { isPrivateSegment, isRouteGroupSegment, toRouteSegments, } from "./discovery/route-segments.js";
|
|
5
|
+
export { resolveStateFields } from "./state/resolve-state-fields.js";
|
|
6
|
+
export { extractToolSchemasForRoute } from "./typegen/extract-tool-schema.js";
|
|
5
7
|
export { extractToolTypesForRoute } from "./typegen/extract-tool-types.js";
|
|
6
8
|
export { renderDawnTypes, renderRouteTypes } from "./typegen/render-route-types.js";
|
|
9
|
+
export { renderStateTypes } from "./typegen/render-state-types.js";
|
|
7
10
|
export { renderToolTypes } from "./typegen/render-tool-types.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResolvedStateField } from "../types.js";
|
|
2
|
+
export interface ResolveStateFieldsOptions {
|
|
3
|
+
readonly defaults: ReadonlyMap<string, unknown>;
|
|
4
|
+
readonly reducerOverrides: ReadonlyMap<string, (current: unknown, incoming: unknown) => unknown>;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveStateFields(options: ResolveStateFieldsOptions): readonly ResolvedStateField[];
|
|
7
|
+
//# sourceMappingURL=resolve-state-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-state-fields.d.ts","sourceRoot":"","sources":["../../src/state/resolve-state-fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/C,QAAQ,CAAC,gBAAgB,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK,OAAO,CAAC,CAAA;CACjG;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,yBAAyB,GACjC,SAAS,kBAAkB,EAAE,CAgB/B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function resolveStateFields(options) {
|
|
2
|
+
const results = [];
|
|
3
|
+
for (const [name, defaultValue] of options.defaults) {
|
|
4
|
+
const override = options.reducerOverrides.get(name);
|
|
5
|
+
if (override) {
|
|
6
|
+
results.push({ name, reducer: override, default: defaultValue });
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const reducer = Array.isArray(defaultValue) ? "append" : "replace";
|
|
10
|
+
results.push({ name, reducer, default: defaultValue });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
results.sort((a, b) => a.name.localeCompare(b.name));
|
|
14
|
+
return results;
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ExtractedToolSchema } from "../types.js";
|
|
2
|
+
export interface ExtractToolSchemasOptions {
|
|
3
|
+
readonly routeDir: string;
|
|
4
|
+
readonly sharedToolsDir: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
export declare function extractToolSchemasForRoute(options: ExtractToolSchemasOptions): Promise<readonly ExtractedToolSchema[]>;
|
|
7
|
+
//# sourceMappingURL=extract-tool-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-tool-schema.d.ts","sourceRoot":"","sources":["../../src/typegen/extract-tool-schema.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,mBAAmB,EAAsB,MAAM,aAAa,CAAA;AAE1E,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5C;AAED,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,SAAS,mBAAmB,EAAE,CAAC,CA+GzC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
export async function extractToolSchemasForRoute(options) {
|
|
5
|
+
const routeToolFiles = discoverToolFiles(join(options.routeDir, "tools"));
|
|
6
|
+
const sharedToolFiles = options.sharedToolsDir
|
|
7
|
+
? discoverToolFiles(join(options.sharedToolsDir, "tools"))
|
|
8
|
+
: new Map();
|
|
9
|
+
// Merge: route-local tools shadow shared tools
|
|
10
|
+
const merged = new Map(sharedToolFiles);
|
|
11
|
+
for (const [name, filePath] of routeToolFiles) {
|
|
12
|
+
merged.set(name, filePath);
|
|
13
|
+
}
|
|
14
|
+
if (merged.size === 0)
|
|
15
|
+
return [];
|
|
16
|
+
const allFilePaths = [...merged.values()];
|
|
17
|
+
const compilerOptions = {
|
|
18
|
+
target: ts.ScriptTarget.ES2022,
|
|
19
|
+
module: ts.ModuleKind.ESNext,
|
|
20
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
21
|
+
strict: true,
|
|
22
|
+
noEmit: true,
|
|
23
|
+
lib: ["lib.es2022.d.ts"],
|
|
24
|
+
};
|
|
25
|
+
const program = ts.createProgram(allFilePaths, compilerOptions);
|
|
26
|
+
const checker = program.getTypeChecker();
|
|
27
|
+
const results = [];
|
|
28
|
+
for (const [name, filePath] of merged) {
|
|
29
|
+
const sourceFile = program.getSourceFile(filePath);
|
|
30
|
+
if (!sourceFile)
|
|
31
|
+
continue;
|
|
32
|
+
const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
|
|
33
|
+
if (!moduleSymbol)
|
|
34
|
+
continue;
|
|
35
|
+
const exports = checker.getExportsOfModule(moduleSymbol);
|
|
36
|
+
const defaultExport = exports.find((e) => e.escapedName === "default");
|
|
37
|
+
if (!defaultExport)
|
|
38
|
+
continue;
|
|
39
|
+
const exportType = checker.getTypeOfSymbolAtLocation(defaultExport, sourceFile);
|
|
40
|
+
const signatures = checker.getSignaturesOfType(exportType, ts.SignatureKind.Call);
|
|
41
|
+
if (signatures.length === 0)
|
|
42
|
+
continue;
|
|
43
|
+
const signature = signatures[0];
|
|
44
|
+
if (!signature)
|
|
45
|
+
continue;
|
|
46
|
+
// Extract tool description from JSDoc
|
|
47
|
+
const description = ts.displayPartsToString(defaultExport.getDocumentationComment(checker));
|
|
48
|
+
const params = signature.getParameters();
|
|
49
|
+
if (params.length === 0) {
|
|
50
|
+
results.push({
|
|
51
|
+
name,
|
|
52
|
+
description,
|
|
53
|
+
parameters: {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {},
|
|
56
|
+
required: [],
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const firstParam = params[0];
|
|
63
|
+
if (!firstParam)
|
|
64
|
+
continue;
|
|
65
|
+
const paramType = checker.getTypeOfSymbolAtLocation(firstParam, sourceFile);
|
|
66
|
+
const properties = {};
|
|
67
|
+
const required = [];
|
|
68
|
+
for (const prop of paramType.getProperties()) {
|
|
69
|
+
const propName = prop.getName();
|
|
70
|
+
const propType = checker.getTypeOfSymbolAtLocation(prop, sourceFile);
|
|
71
|
+
const schema = tsTypeToJsonSchema(propType, checker);
|
|
72
|
+
// Extract property JSDoc description
|
|
73
|
+
const propDoc = ts.displayPartsToString(prop.getDocumentationComment(checker));
|
|
74
|
+
if (propDoc) {
|
|
75
|
+
schema.description = propDoc;
|
|
76
|
+
}
|
|
77
|
+
properties[propName] = schema;
|
|
78
|
+
// Check if property is optional
|
|
79
|
+
const declarations = prop.getDeclarations();
|
|
80
|
+
const isOptional = declarations !== undefined &&
|
|
81
|
+
declarations.length > 0 &&
|
|
82
|
+
declarations.some((d) => ts.isPropertySignature(d) && d.questionToken !== undefined);
|
|
83
|
+
if (!isOptional) {
|
|
84
|
+
required.push(propName);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
results.push({
|
|
88
|
+
name,
|
|
89
|
+
description,
|
|
90
|
+
parameters: {
|
|
91
|
+
type: "object",
|
|
92
|
+
properties,
|
|
93
|
+
required,
|
|
94
|
+
additionalProperties: false,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
results.sort((a, b) => a.name.localeCompare(b.name));
|
|
99
|
+
return results;
|
|
100
|
+
}
|
|
101
|
+
function tsTypeToJsonSchema(type, checker) {
|
|
102
|
+
// Strip undefined from unions (optional properties resolve as T | undefined)
|
|
103
|
+
if (type.isUnion()) {
|
|
104
|
+
const nonUndefined = type.types.filter((t) => !(t.flags & ts.TypeFlags.Undefined));
|
|
105
|
+
if (nonUndefined.length === 1 && nonUndefined[0]) {
|
|
106
|
+
return tsTypeToJsonSchema(nonUndefined[0], checker);
|
|
107
|
+
}
|
|
108
|
+
// String literal union → enum
|
|
109
|
+
const allStringLiterals = nonUndefined.every((t) => t.isStringLiteral());
|
|
110
|
+
if (allStringLiterals && nonUndefined.length > 0) {
|
|
111
|
+
const enumValues = nonUndefined.map((t) => t.value);
|
|
112
|
+
return { type: "string", enum: enumValues };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Array type
|
|
116
|
+
if (checker.isArrayType(type)) {
|
|
117
|
+
const typeArgs = type.typeArguments;
|
|
118
|
+
const elementType = typeArgs && typeArgs.length > 0 && typeArgs[0];
|
|
119
|
+
const items = elementType ? tsTypeToJsonSchema(elementType, checker) : { type: "string" };
|
|
120
|
+
return { type: "array", items };
|
|
121
|
+
}
|
|
122
|
+
const typeString = checker.typeToString(type);
|
|
123
|
+
if (typeString === "string")
|
|
124
|
+
return { type: "string" };
|
|
125
|
+
if (typeString === "number")
|
|
126
|
+
return { type: "number" };
|
|
127
|
+
if (typeString === "boolean")
|
|
128
|
+
return { type: "boolean" };
|
|
129
|
+
// Fallback to string for unknown types
|
|
130
|
+
return { type: "string" };
|
|
131
|
+
}
|
|
132
|
+
function discoverToolFiles(toolsDir) {
|
|
133
|
+
const files = new Map();
|
|
134
|
+
if (!existsSync(toolsDir))
|
|
135
|
+
return files;
|
|
136
|
+
const entries = readdirSync(toolsDir);
|
|
137
|
+
for (const entry of entries) {
|
|
138
|
+
if (!entry.endsWith(".ts"))
|
|
139
|
+
continue;
|
|
140
|
+
if (entry.endsWith(".d.ts"))
|
|
141
|
+
continue;
|
|
142
|
+
const name = entry.replace(/\.ts$/, "");
|
|
143
|
+
files.set(name, join(toolsDir, entry));
|
|
144
|
+
}
|
|
145
|
+
return files;
|
|
146
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-tool-types.d.ts","sourceRoot":"","sources":["../../src/typegen/extract-tool-types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5C;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"extract-tool-types.d.ts","sourceRoot":"","sources":["../../src/typegen/extract-tool-types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEpD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,CAAA;CAC5C;AAED,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,SAAS,iBAAiB,EAAE,CAAC,CAyEvC"}
|
|
@@ -57,7 +57,9 @@ export async function extractToolTypesForRoute(options) {
|
|
|
57
57
|
}
|
|
58
58
|
const returnType = checker.getReturnTypeOfSignature(signature);
|
|
59
59
|
const outputType = unwrapPromise(returnType);
|
|
60
|
+
const description = extractJsDoc(defaultExport, checker);
|
|
60
61
|
results.push({
|
|
62
|
+
description,
|
|
61
63
|
name,
|
|
62
64
|
inputType,
|
|
63
65
|
outputType: checker.typeToString(outputType),
|
|
@@ -66,6 +68,13 @@ export async function extractToolTypesForRoute(options) {
|
|
|
66
68
|
results.sort((a, b) => a.name.localeCompare(b.name));
|
|
67
69
|
return results;
|
|
68
70
|
}
|
|
71
|
+
function extractJsDoc(symbol, checker) {
|
|
72
|
+
const docs = symbol.getDocumentationComment(checker);
|
|
73
|
+
return docs
|
|
74
|
+
.map((d) => d.text)
|
|
75
|
+
.join("")
|
|
76
|
+
.trim();
|
|
77
|
+
}
|
|
69
78
|
function unwrapPromise(type) {
|
|
70
79
|
const symbol = type.getSymbol();
|
|
71
80
|
if (symbol && symbol.getName() === "Promise") {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RouteManifest, RouteToolTypes } from "../types.js";
|
|
2
|
-
|
|
2
|
+
import { type RouteStateFields } from "./render-state-types.js";
|
|
3
|
+
export declare function renderDawnTypes(manifest: RouteManifest, toolTypes: readonly RouteToolTypes[], stateTypes?: readonly RouteStateFields[]): string;
|
|
3
4
|
export declare function renderRouteTypes(manifest: RouteManifest): string;
|
|
4
5
|
//# sourceMappingURL=render-route-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-route-types.d.ts","sourceRoot":"","sources":["../../src/typegen/render-route-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,cAAc,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"render-route-types.d.ts","sourceRoot":"","sources":["../../src/typegen/render-route-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAgB,cAAc,EAAE,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,KAAK,gBAAgB,EAAoB,MAAM,yBAAyB,CAAA;AAGjF,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,aAAa,EACvB,SAAS,EAAE,SAAS,cAAc,EAAE,EACpC,UAAU,CAAC,EAAE,SAAS,gBAAgB,EAAE,GACvC,MAAM,CAoCR;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,aAAa,GAAG,MAAM,CA+BhE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { renderStateTypes } from "./render-state-types.js";
|
|
1
2
|
import { renderToolTypes } from "./render-tool-types.js";
|
|
2
|
-
export function renderDawnTypes(manifest, toolTypes) {
|
|
3
|
+
export function renderDawnTypes(manifest, toolTypes, stateTypes) {
|
|
3
4
|
const pathUnion = manifest.routes.length > 0
|
|
4
5
|
? manifest.routes.map((route) => JSON.stringify(route.pathname)).join(" | ")
|
|
5
6
|
: "never";
|
|
@@ -11,16 +12,21 @@ export function renderDawnTypes(manifest, toolTypes) {
|
|
|
11
12
|
? " export interface DawnRouteParams {}"
|
|
12
13
|
: [" export interface DawnRouteParams {", ...paramLines, " }"].join("\n");
|
|
13
14
|
const toolBlock = renderToolTypes(toolTypes).trimEnd();
|
|
14
|
-
|
|
15
|
+
const parts = [
|
|
15
16
|
'declare module "dawn:routes" {',
|
|
16
17
|
` export type DawnRoutePath = ${pathUnion};`,
|
|
17
18
|
"",
|
|
18
19
|
paramBlock,
|
|
19
20
|
"",
|
|
20
21
|
toolBlock,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
];
|
|
23
|
+
if (stateTypes && stateTypes.length > 0) {
|
|
24
|
+
parts.push("");
|
|
25
|
+
parts.push(renderStateTypes(stateTypes).trimEnd());
|
|
26
|
+
}
|
|
27
|
+
parts.push("}");
|
|
28
|
+
parts.push("");
|
|
29
|
+
return parts.join("\n");
|
|
24
30
|
}
|
|
25
31
|
export function renderRouteTypes(manifest) {
|
|
26
32
|
const pathUnion = manifest.routes.length > 0
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface RouteStateFields {
|
|
2
|
+
readonly pathname: string;
|
|
3
|
+
readonly fields: readonly {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly type: string;
|
|
6
|
+
}[];
|
|
7
|
+
}
|
|
8
|
+
export declare function renderStateTypes(routeStates: readonly RouteStateFields[]): string;
|
|
9
|
+
//# sourceMappingURL=render-state-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-state-types.d.ts","sourceRoot":"","sources":["../../src/typegen/render-state-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC7E;AAED,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAmBjF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function renderStateTypes(routeStates) {
|
|
2
|
+
const routeStateType = " export type RouteState<P extends DawnRoutePath> = DawnRouteState[P];";
|
|
3
|
+
if (routeStates.length === 0) {
|
|
4
|
+
return [" export interface DawnRouteState {}", "", routeStateType, ""].join("\n");
|
|
5
|
+
}
|
|
6
|
+
const routeLines = [];
|
|
7
|
+
for (const route of routeStates) {
|
|
8
|
+
routeLines.push(` ${JSON.stringify(route.pathname)}: {`);
|
|
9
|
+
for (const field of route.fields) {
|
|
10
|
+
routeLines.push(` readonly ${field.name}: ${field.type};`);
|
|
11
|
+
}
|
|
12
|
+
routeLines.push(" };");
|
|
13
|
+
}
|
|
14
|
+
return [" export interface DawnRouteState {", ...routeLines, " }", "", routeStateType, ""].join("\n");
|
|
15
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -23,6 +23,11 @@ export interface RouteManifest {
|
|
|
23
23
|
readonly appRoot: string;
|
|
24
24
|
readonly routes: RouteDefinition[];
|
|
25
25
|
}
|
|
26
|
+
export interface NormalizedRouteModule {
|
|
27
|
+
readonly kind: RouteKind;
|
|
28
|
+
readonly entry: unknown;
|
|
29
|
+
readonly config: Record<string, unknown>;
|
|
30
|
+
}
|
|
26
31
|
export interface LoadDawnConfigOptions {
|
|
27
32
|
readonly appRoot: string;
|
|
28
33
|
}
|
|
@@ -46,6 +51,7 @@ export interface DiscoverRoutesOptions {
|
|
|
46
51
|
readonly cwd?: string;
|
|
47
52
|
}
|
|
48
53
|
export interface ExtractedToolType {
|
|
54
|
+
readonly description: string;
|
|
49
55
|
readonly name: string;
|
|
50
56
|
readonly inputType: string;
|
|
51
57
|
readonly outputType: string;
|
|
@@ -54,4 +60,33 @@ export interface RouteToolTypes {
|
|
|
54
60
|
readonly pathname: string;
|
|
55
61
|
readonly tools: readonly ExtractedToolType[];
|
|
56
62
|
}
|
|
63
|
+
export interface JsonSchemaProperty {
|
|
64
|
+
readonly type: string;
|
|
65
|
+
readonly description?: string;
|
|
66
|
+
readonly items?: JsonSchemaProperty;
|
|
67
|
+
readonly properties?: Record<string, JsonSchemaProperty>;
|
|
68
|
+
readonly required?: readonly string[];
|
|
69
|
+
readonly additionalProperties?: boolean;
|
|
70
|
+
readonly enum?: readonly string[];
|
|
71
|
+
}
|
|
72
|
+
export interface ExtractedToolSchema {
|
|
73
|
+
readonly name: string;
|
|
74
|
+
readonly description: string;
|
|
75
|
+
readonly parameters: {
|
|
76
|
+
readonly type: "object";
|
|
77
|
+
readonly properties: Record<string, JsonSchemaProperty>;
|
|
78
|
+
readonly required: readonly string[];
|
|
79
|
+
readonly additionalProperties: false;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export interface RouteToolSchemas {
|
|
83
|
+
readonly pathname: string;
|
|
84
|
+
readonly tools: readonly ExtractedToolSchema[];
|
|
85
|
+
}
|
|
86
|
+
export type StateFieldReducer = "append" | "replace";
|
|
87
|
+
export interface ResolvedStateField {
|
|
88
|
+
readonly name: string;
|
|
89
|
+
readonly reducer: StateFieldReducer | ((current: unknown, incoming: unknown) => unknown);
|
|
90
|
+
readonly default: unknown;
|
|
91
|
+
}
|
|
57
92
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,YAAY,EAAE,SAAS,EAAE,CAAA;AAEzB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,MAAM,YAAY,GACpB;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,mBAAmB,CAAA;IAC3D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB,CAAA;AAEL,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM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
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,19 +29,19 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"tsx": "^4.8.1",
|
|
34
|
-
"typescript": "5.8.3",
|
|
35
|
-
"@dawn-ai/sdk": "0.0.2"
|
|
36
|
-
},
|
|
37
|
-
"devDependencies": {
|
|
38
|
-
"@types/node": "25.6.0",
|
|
39
|
-
"@dawn-ai/config-typescript": "0.0.2"
|
|
40
|
-
},
|
|
41
32
|
"scripts": {
|
|
42
33
|
"build": "tsc -b tsconfig.json",
|
|
43
34
|
"lint": "biome check --config-path ../config-biome/biome.json package.json src test tsconfig.json vitest.config.ts",
|
|
44
35
|
"test": "vitest --run --config vitest.config.ts",
|
|
45
36
|
"typecheck": "tsc --noEmit"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@dawn-ai/sdk": "workspace:*",
|
|
40
|
+
"tsx": "^4.8.1",
|
|
41
|
+
"typescript": "5.8.3"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@dawn-ai/config-typescript": "workspace:*",
|
|
45
|
+
"@types/node": "25.6.0"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|