@treeseed/sdk 0.1.2 → 0.3.1
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/README.md +97 -506
- package/dist/{src/cli-tools.d.ts → cli-tools.d.ts} +1 -1
- package/dist/cli-tools.js +5 -3
- package/dist/{src/content-store.d.ts → content-store.d.ts} +3 -2
- package/dist/content-store.js +52 -20
- package/dist/{src/d1-store.d.ts → d1-store.d.ts} +62 -1
- package/dist/d1-store.js +625 -65
- package/dist/field-aliases.d.ts +11 -0
- package/dist/field-aliases.js +41 -0
- package/dist/graph/build.d.ts +19 -0
- package/dist/graph/build.js +949 -0
- package/dist/graph/dsl.d.ts +2 -0
- package/dist/graph/dsl.js +243 -0
- package/dist/graph/query.d.ts +47 -0
- package/dist/graph/query.js +447 -0
- package/dist/graph/ranking.d.ts +3 -0
- package/dist/graph/ranking.js +483 -0
- package/dist/graph/schema.d.ts +142 -0
- package/dist/graph/schema.js +133 -0
- package/dist/graph.d.ts +52 -0
- package/dist/graph.js +133 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +91 -2
- package/dist/model-registry.d.ts +8 -0
- package/dist/model-registry.js +351 -25
- package/dist/operations/providers/default.d.ts +10 -0
- package/dist/operations/providers/default.js +514 -0
- package/dist/operations/runtime.d.ts +7 -0
- package/dist/operations/runtime.js +60 -0
- package/dist/operations/services/config-runtime.d.ts +269 -0
- package/dist/operations/services/config-runtime.js +1397 -0
- package/dist/operations/services/d1-migration.d.ts +6 -0
- package/dist/operations/services/d1-migration.js +89 -0
- package/dist/operations/services/deploy.d.ts +371 -0
- package/dist/operations/services/deploy.js +981 -0
- package/dist/operations/services/git-workflow.d.ts +49 -0
- package/dist/operations/services/git-workflow.js +218 -0
- package/dist/operations/services/github-automation.d.ts +156 -0
- package/dist/operations/services/github-automation.js +256 -0
- package/dist/operations/services/local-dev.d.ts +9 -0
- package/dist/operations/services/local-dev.js +106 -0
- package/dist/operations/services/mailpit-runtime.d.ts +4 -0
- package/dist/operations/services/mailpit-runtime.js +59 -0
- package/dist/operations/services/railway-deploy.d.ts +53 -0
- package/dist/operations/services/railway-deploy.js +123 -0
- package/dist/operations/services/runtime-paths.d.ts +19 -0
- package/dist/operations/services/runtime-paths.js +54 -0
- package/dist/operations/services/runtime-tools.d.ts +117 -0
- package/dist/operations/services/runtime-tools.js +358 -0
- package/dist/operations/services/save-deploy-preflight.d.ts +34 -0
- package/dist/operations/services/save-deploy-preflight.js +76 -0
- package/dist/operations/services/template-registry.d.ts +88 -0
- package/dist/operations/services/template-registry.js +407 -0
- package/dist/operations/services/watch-dev.d.ts +21 -0
- package/dist/operations/services/watch-dev.js +284 -0
- package/dist/operations/services/workspace-preflight.d.ts +40 -0
- package/dist/operations/services/workspace-preflight.js +165 -0
- package/dist/operations/services/workspace-save.d.ts +42 -0
- package/dist/operations/services/workspace-save.js +235 -0
- package/dist/operations/services/workspace-tools.d.ts +16 -0
- package/dist/operations/services/workspace-tools.js +270 -0
- package/dist/operations-registry.d.ts +5 -0
- package/dist/operations-registry.js +68 -0
- package/dist/operations-types.d.ts +71 -0
- package/dist/operations-types.js +17 -0
- package/dist/operations.d.ts +6 -0
- package/dist/operations.js +16 -0
- package/dist/platform/books-data.d.ts +1 -0
- package/dist/platform/books-data.js +1 -0
- package/dist/platform/contracts.d.ts +158 -0
- package/dist/platform/contracts.js +0 -0
- package/dist/platform/deploy/config.d.ts +4 -0
- package/dist/platform/deploy/config.js +222 -0
- package/dist/platform/deploy-config.d.ts +1 -0
- package/dist/platform/deploy-config.js +1 -0
- package/dist/platform/deploy-runtime.d.ts +18 -0
- package/dist/platform/deploy-runtime.js +78 -0
- package/dist/platform/env.yaml +394 -0
- package/dist/platform/environment.d.ts +130 -0
- package/dist/platform/environment.js +331 -0
- package/dist/platform/plugin.d.ts +2 -0
- package/dist/platform/plugin.js +4 -0
- package/dist/platform/plugins/constants.d.ts +22 -0
- package/dist/platform/plugins/constants.js +29 -0
- package/dist/platform/plugins/plugin.d.ts +51 -0
- package/dist/platform/plugins/plugin.js +6 -0
- package/dist/platform/plugins/runtime.d.ts +35 -0
- package/dist/platform/plugins/runtime.js +161 -0
- package/dist/platform/plugins.d.ts +6 -0
- package/dist/platform/plugins.js +38 -0
- package/dist/platform/site-config-schema.js +1 -0
- package/dist/platform/tenant/config.d.ts +9 -0
- package/dist/platform/tenant/config.js +154 -0
- package/dist/platform/tenant/runtime-config.d.ts +4 -0
- package/dist/platform/tenant/runtime-config.js +20 -0
- package/dist/platform/tenant-config.d.ts +1 -0
- package/dist/platform/tenant-config.js +1 -0
- package/dist/platform/utils/books-data.d.ts +29 -0
- package/dist/platform/utils/books-data.js +82 -0
- package/dist/platform/utils/site-config-schema.js +321 -0
- package/dist/remote.d.ts +175 -0
- package/dist/remote.js +202 -0
- package/dist/runtime.js +35 -22
- package/dist/scripts/aggregate-book.js +121 -0
- package/dist/scripts/build-dist.js +54 -13
- package/dist/scripts/build-tenant-worker.js +36 -0
- package/dist/scripts/cleanup-markdown.js +373 -0
- package/dist/scripts/cli-test-fixtures.js +48 -0
- package/dist/scripts/config-treeseed.js +95 -0
- package/dist/scripts/ensure-mailpit.js +29 -0
- package/dist/scripts/local-dev.js +129 -0
- package/dist/scripts/logs-mailpit.js +2 -0
- package/dist/scripts/patch-starlight-content-path.js +172 -0
- package/dist/scripts/release-verify.js +34 -6
- package/dist/scripts/run-fixture-astro-command.js +18 -0
- package/dist/scripts/scaffold-site.js +65 -0
- package/dist/scripts/stop-mailpit.js +5 -0
- package/dist/scripts/sync-dev-vars.js +6 -0
- package/dist/scripts/sync-template.js +20 -0
- package/dist/scripts/template-catalog.test.js +100 -0
- package/dist/scripts/template-command.js +31 -0
- package/dist/scripts/tenant-astro-command.js +3 -0
- package/dist/scripts/tenant-build.js +16 -0
- package/dist/scripts/tenant-check.js +7 -0
- package/dist/scripts/tenant-d1-migrate-local.js +11 -0
- package/dist/scripts/tenant-deploy.js +180 -0
- package/dist/scripts/tenant-destroy.js +104 -0
- package/dist/scripts/tenant-dev.js +171 -0
- package/dist/scripts/tenant-lint.js +4 -0
- package/dist/scripts/tenant-test.js +4 -0
- package/dist/scripts/test-cloudflare-local.js +212 -0
- package/dist/scripts/test-scaffold.js +314 -0
- package/dist/scripts/test-smoke.js +71 -13
- package/dist/scripts/treeseed-assert-release-tag-version.js +21 -0
- package/dist/scripts/treeseed-build-dist.js +134 -0
- package/dist/scripts/treeseed-publish-package.js +19 -0
- package/dist/scripts/treeseed-release-verify.js +131 -0
- package/dist/scripts/treeseed-run-ts.js +45 -0
- package/dist/scripts/validate-templates.js +6 -0
- package/dist/scripts/verify-driver.js +29 -0
- package/dist/scripts/workflow-commands.test.js +39 -0
- package/dist/scripts/workspace-close.js +24 -0
- package/dist/scripts/workspace-command-e2e.js +718 -0
- package/dist/scripts/workspace-lint.js +9 -0
- package/dist/scripts/workspace-preflight.js +22 -0
- package/dist/scripts/workspace-publish-changed-packages.js +16 -0
- package/dist/scripts/workspace-release-verify.js +81 -0
- package/dist/scripts/workspace-release.js +42 -0
- package/dist/scripts/workspace-save.js +124 -0
- package/dist/scripts/workspace-start-warning.js +3 -0
- package/dist/scripts/workspace-start.js +71 -0
- package/dist/scripts/workspace-test-unit.js +4 -0
- package/dist/scripts/workspace-test.js +11 -0
- package/dist/sdk-fields.d.ts +11 -0
- package/dist/sdk-fields.js +169 -0
- package/dist/sdk-filters.d.ts +4 -0
- package/dist/sdk-filters.js +12 -15
- package/dist/sdk-types.d.ts +796 -0
- package/dist/sdk-types.js +7 -1
- package/dist/sdk-version.d.ts +2 -0
- package/dist/sdk-version.js +42 -0
- package/dist/sdk.d.ts +215 -0
- package/dist/sdk.js +235 -11
- package/dist/stores/cursor-store.js +9 -3
- package/dist/stores/lease-store.js +8 -2
- package/dist/{src/stores → stores}/message-store.d.ts +1 -1
- package/dist/stores/message-store.js +27 -3
- package/dist/stores/operational-store.d.ts +24 -0
- package/dist/stores/operational-store.js +279 -0
- package/dist/stores/run-store.js +8 -1
- package/dist/stores/subscription-store.js +7 -5
- package/dist/template-catalog.d.ts +13 -0
- package/dist/template-catalog.js +141 -0
- package/dist/treeseed/services/compose.yml +7 -0
- package/dist/treeseed/template-catalog/catalog.fixture.json +55 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/astro.config.d.ts +2 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/astro.config.ts +3 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/package.json +32 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/config.yaml +40 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/empty/.gitkeep +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/knowledge/handbook/index.mdx +11 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content/pages/welcome.mdx +11 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content.config.d.ts +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/content.config.ts +3 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/env.yaml +1 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/src/manifest.yaml +19 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/treeseed.site.yaml +26 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template/tsconfig.json +9 -0
- package/dist/treeseed/template-catalog/templates/starter-basic/template.config.json +90 -0
- package/dist/utils/agents/contracts/messages.d.ts +88 -0
- package/dist/utils/agents/contracts/messages.js +138 -0
- package/dist/utils/agents/contracts/run.d.ts +20 -0
- package/dist/utils/agents/contracts/run.js +0 -0
- package/dist/utils/agents/runtime-types.d.ts +117 -0
- package/dist/utils/agents/runtime-types.js +4 -0
- package/dist/verification.d.ts +20 -0
- package/dist/verification.js +98 -0
- package/dist/workflow/operations.d.ts +396 -0
- package/dist/workflow/operations.js +841 -0
- package/dist/workflow-state.d.ts +56 -0
- package/dist/workflow-state.js +195 -0
- package/dist/workflow-support.d.ts +9 -0
- package/dist/workflow-support.js +176 -0
- package/dist/workflow.d.ts +111 -0
- package/dist/workflow.js +97 -0
- package/package.json +111 -5
- package/scripts/verify-driver.mjs +29 -0
- package/dist/scripts/.ts-run-1775630384291-crtqr3izsa.js +0 -22
- package/dist/scripts/.ts-run-1775630388025-vnjle0z75a.js +0 -129
- package/dist/scripts/assert-release-tag-version.d.ts +0 -1
- package/dist/scripts/build-dist.d.ts +0 -1
- package/dist/scripts/fixture-tools.d.ts +0 -5
- package/dist/scripts/package-tools.d.ts +0 -15
- package/dist/scripts/publish-package.d.ts +0 -1
- package/dist/scripts/release-verify.d.ts +0 -1
- package/dist/scripts/test-smoke.d.ts +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/model-registry.d.ts +0 -4
- package/dist/src/sdk-filters.d.ts +0 -4
- package/dist/src/sdk-types.d.ts +0 -285
- package/dist/src/sdk.d.ts +0 -109
- package/dist/test/test-fixture.d.ts +0 -1
- package/dist/test/utils/envelopes.test.d.ts +0 -1
- package/dist/test/utils/sdk.test.d.ts +0 -1
- package/dist/vitest.config.d.ts +0 -2
- /package/dist/{src/frontmatter.d.ts → frontmatter.d.ts} +0 -0
- /package/dist/{src/git-runtime.d.ts → git-runtime.d.ts} +0 -0
- /package/dist/{src/runtime.d.ts → runtime.d.ts} +0 -0
- /package/dist/{src/stores → stores}/cursor-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/envelopes.d.ts +0 -0
- /package/dist/{src/stores → stores}/helpers.d.ts +0 -0
- /package/dist/{src/stores → stores}/lease-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/run-store.d.ts +0 -0
- /package/dist/{src/stores → stores}/subscription-store.d.ts +0 -0
- /package/dist/{src/types → types}/agents.d.ts +0 -0
- /package/dist/{src/types → types}/cloudflare.d.ts +0 -0
- /package/dist/{src/wrangler-d1.d.ts → wrangler-d1.d.ts} +0 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const GRAPH_SNAPSHOT_VERSION = 1;
|
|
4
|
+
const AUTHORED_GRAPH_EDGE_TYPES = [
|
|
5
|
+
"REFERENCES",
|
|
6
|
+
"HAS_TAG",
|
|
7
|
+
"IN_SERIES",
|
|
8
|
+
"RELATES_TO",
|
|
9
|
+
"DEPENDS_ON",
|
|
10
|
+
"IMPLEMENTS",
|
|
11
|
+
"EXTENDS",
|
|
12
|
+
"SUPERSEDES",
|
|
13
|
+
"BELONGS_TO",
|
|
14
|
+
"ABOUT",
|
|
15
|
+
"USED_BY",
|
|
16
|
+
"GENERATED_FROM"
|
|
17
|
+
];
|
|
18
|
+
function sha1(value) {
|
|
19
|
+
return crypto.createHash("sha1").update(value).digest("hex");
|
|
20
|
+
}
|
|
21
|
+
function computeEdgeId(sourceId, edgeType, targetId, provenance = "") {
|
|
22
|
+
return `edge:${sha1(`${sourceId}|${edgeType}|${targetId}|${provenance}`)}`;
|
|
23
|
+
}
|
|
24
|
+
function createFileNodeId(model, slug) {
|
|
25
|
+
return `file:${model}:${slug}`;
|
|
26
|
+
}
|
|
27
|
+
function createEntityNodeId(definition, slug, frontmatter) {
|
|
28
|
+
const explicitId = typeof frontmatter.id === "string" && frontmatter.id.trim() ? frontmatter.id.trim() : null;
|
|
29
|
+
return explicitId ?? `entity:${definition.name}:${slug}`;
|
|
30
|
+
}
|
|
31
|
+
function normalizeText(value) {
|
|
32
|
+
return value.replace(/\s+/g, " ").trim().toLowerCase();
|
|
33
|
+
}
|
|
34
|
+
function ensureArray(value) {
|
|
35
|
+
if (Array.isArray(value)) {
|
|
36
|
+
return value.map((entry) => typeof entry === "string" ? entry.trim() : "").filter(Boolean);
|
|
37
|
+
}
|
|
38
|
+
if (typeof value === "string" && value.trim()) {
|
|
39
|
+
return [value.trim()];
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
function builtinEntityTypeFor(model) {
|
|
44
|
+
switch (model) {
|
|
45
|
+
case "agent":
|
|
46
|
+
return "Agent";
|
|
47
|
+
case "objective":
|
|
48
|
+
return "Objective";
|
|
49
|
+
case "question":
|
|
50
|
+
return "Question";
|
|
51
|
+
case "note":
|
|
52
|
+
return "Note";
|
|
53
|
+
case "knowledge":
|
|
54
|
+
return "Knowledge";
|
|
55
|
+
case "book":
|
|
56
|
+
return "Book";
|
|
57
|
+
case "page":
|
|
58
|
+
return "Page";
|
|
59
|
+
case "person":
|
|
60
|
+
return "Person";
|
|
61
|
+
default:
|
|
62
|
+
return "Entity";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function resolveGraphModelConfig(definition) {
|
|
66
|
+
return {
|
|
67
|
+
entityType: definition.graph?.entityType ?? builtinEntityTypeFor(definition.name),
|
|
68
|
+
referenceFields: definition.graph?.referenceFields ?? [],
|
|
69
|
+
tagField: definition.graph?.tagField ?? (definition.fields.tags ? "tags" : ""),
|
|
70
|
+
seriesField: definition.graph?.seriesField ?? "",
|
|
71
|
+
titleField: definition.graph?.titleField ?? (definition.fields.title ? "title" : definition.fields.name ? "name" : "title"),
|
|
72
|
+
enableSections: definition.graph?.enableSections ?? true
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function computeModelSignature(models) {
|
|
76
|
+
const contentModels = Object.values(models).filter((definition) => definition.storage === "content" && definition.contentDir).map((definition) => ({
|
|
77
|
+
name: definition.name,
|
|
78
|
+
contentDir: definition.contentDir,
|
|
79
|
+
contentCollection: definition.contentCollection ?? null,
|
|
80
|
+
fields: Object.keys(definition.fields).sort(),
|
|
81
|
+
graph: resolveGraphModelConfig(definition)
|
|
82
|
+
})).sort((left, right) => left.name.localeCompare(right.name));
|
|
83
|
+
return sha1(JSON.stringify(contentModels));
|
|
84
|
+
}
|
|
85
|
+
function graphSnapshotRoot(repoRoot) {
|
|
86
|
+
return path.join(repoRoot, ".treeseed", "state", "graph");
|
|
87
|
+
}
|
|
88
|
+
function emptyGraphMetrics() {
|
|
89
|
+
return {
|
|
90
|
+
totalFiles: 0,
|
|
91
|
+
totalSections: 0,
|
|
92
|
+
totalEntities: 0,
|
|
93
|
+
totalEdges: 0,
|
|
94
|
+
unresolvedReferences: 0,
|
|
95
|
+
validation: {
|
|
96
|
+
missingIds: 0,
|
|
97
|
+
duplicateIds: 0,
|
|
98
|
+
brokenReferences: 0,
|
|
99
|
+
invalidEdgeTypes: 0,
|
|
100
|
+
invalidCanonicalRefs: 0,
|
|
101
|
+
invalidSupersedesRefs: 0
|
|
102
|
+
},
|
|
103
|
+
queryCounts: {},
|
|
104
|
+
topTraversedEdgeTypes: {},
|
|
105
|
+
lastRefreshAt: null
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function emptyGraphValidation() {
|
|
109
|
+
return {
|
|
110
|
+
missingIds: [],
|
|
111
|
+
duplicateIds: [],
|
|
112
|
+
brokenReferences: [],
|
|
113
|
+
invalidEdgeTypes: [],
|
|
114
|
+
invalidCanonicalRefs: [],
|
|
115
|
+
invalidSupersedesRefs: []
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
AUTHORED_GRAPH_EDGE_TYPES,
|
|
120
|
+
GRAPH_SNAPSHOT_VERSION,
|
|
121
|
+
builtinEntityTypeFor,
|
|
122
|
+
computeEdgeId,
|
|
123
|
+
computeModelSignature,
|
|
124
|
+
createEntityNodeId,
|
|
125
|
+
createFileNodeId,
|
|
126
|
+
emptyGraphMetrics,
|
|
127
|
+
emptyGraphValidation,
|
|
128
|
+
ensureArray,
|
|
129
|
+
graphSnapshotRoot,
|
|
130
|
+
normalizeText,
|
|
131
|
+
resolveGraphModelConfig,
|
|
132
|
+
sha1
|
|
133
|
+
};
|
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SdkContextPack, SdkContextPackRequest, SdkGraphPathExplanation, SdkGraphDslParseResult, SdkGraphQueryOptions, SdkGraphQueryRequest, SdkGraphQueryResult, SdkGraphRefreshPayload, SdkGraphRefreshRequest, SdkGraphSearchOptions, SdkGraphSearchResult, SdkGraphSeedResolution, SdkGraphTraversalResult, SdkModelRegistry, SdkGraphRankingProvider } from './sdk-types.ts';
|
|
2
|
+
import type { LoadedTreeseedPluginEntry } from './platform/plugins.ts';
|
|
3
|
+
export interface ContentGraphRuntimeOptions {
|
|
4
|
+
rankingProvider?: SdkGraphRankingProvider;
|
|
5
|
+
plugins?: LoadedTreeseedPluginEntry[];
|
|
6
|
+
}
|
|
7
|
+
/** Advanced direct graph runtime used internally by AgentSdk and available for low-level integrations. */
|
|
8
|
+
export declare class ContentGraphRuntime {
|
|
9
|
+
private readonly repoRoot;
|
|
10
|
+
private readonly models;
|
|
11
|
+
private state;
|
|
12
|
+
private queryEngine;
|
|
13
|
+
private readonly rankingProvider;
|
|
14
|
+
constructor(repoRoot: string, models: SdkModelRegistry, options?: ContentGraphRuntimeOptions);
|
|
15
|
+
private trackQuery;
|
|
16
|
+
private ensureLoaded;
|
|
17
|
+
private persist;
|
|
18
|
+
refresh(request?: SdkGraphRefreshRequest): Promise<SdkGraphRefreshPayload>;
|
|
19
|
+
/** Advanced lexical graph primitive for file nodes. */
|
|
20
|
+
searchFiles(query: string, options?: SdkGraphSearchOptions): Promise<SdkGraphSearchResult[]>;
|
|
21
|
+
/** Advanced lexical graph primitive for section nodes. */
|
|
22
|
+
searchSections(query: string, options?: SdkGraphSearchOptions): Promise<SdkGraphSearchResult[]>;
|
|
23
|
+
/** Advanced lexical graph primitive for entity nodes. */
|
|
24
|
+
searchEntities(query: string, options?: SdkGraphSearchOptions): Promise<SdkGraphSearchResult[]>;
|
|
25
|
+
getNode(id: string): Promise<import("./sdk-types.ts").SdkGraphNode | null>;
|
|
26
|
+
getNeighbors(id: string, options?: SdkGraphQueryOptions): Promise<{
|
|
27
|
+
node: import("./sdk-types.ts").SdkGraphNode | null;
|
|
28
|
+
nodes: import("./sdk-types.ts").SdkGraphNode[];
|
|
29
|
+
edges: import("./sdk-types.ts").SdkGraphEdge[];
|
|
30
|
+
}>;
|
|
31
|
+
followReferences(id: string, options?: SdkGraphQueryOptions): Promise<SdkGraphTraversalResult>;
|
|
32
|
+
getBacklinks(id: string, options?: SdkGraphQueryOptions): Promise<{
|
|
33
|
+
node: import("./sdk-types.ts").SdkGraphNode | null;
|
|
34
|
+
nodes: import("./sdk-types.ts").SdkGraphNode[];
|
|
35
|
+
edges: import("./sdk-types.ts").SdkGraphEdge[];
|
|
36
|
+
}>;
|
|
37
|
+
getRelated(id: string, options?: SdkGraphQueryOptions): Promise<import("./sdk-types.ts").SdkGraphQueryNodeResult[]>;
|
|
38
|
+
getSubgraph(seedIds: string[], options?: SdkGraphQueryOptions): Promise<SdkGraphTraversalResult>;
|
|
39
|
+
resolveSeeds(request: SdkGraphQueryRequest): Promise<SdkGraphSeedResolution>;
|
|
40
|
+
/** Preferred ranked graph retrieval entrypoint when using the graph runtime directly. */
|
|
41
|
+
queryGraph(request: SdkGraphQueryRequest): Promise<SdkGraphQueryResult>;
|
|
42
|
+
/** Preferred prompt-ready context assembly entrypoint when using the graph runtime directly. */
|
|
43
|
+
buildContextPack(request: SdkContextPackRequest): Promise<SdkContextPack>;
|
|
44
|
+
/** Parses the public ctx DSL into a typed graph request. */
|
|
45
|
+
parseGraphDsl(source: string): Promise<SdkGraphDslParseResult>;
|
|
46
|
+
resolveReference(reference: string, options?: {
|
|
47
|
+
fromNodeId?: string;
|
|
48
|
+
fromPath?: string;
|
|
49
|
+
models?: string[];
|
|
50
|
+
}): Promise<import("./sdk-types.ts").SdkGraphNode | null>;
|
|
51
|
+
explainReferenceChain(fromId: string, toId: string): Promise<SdkGraphPathExplanation | null>;
|
|
52
|
+
}
|
package/dist/graph.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { loadGraphSnapshot, refreshGraphBuildState, saveGraphSnapshot } from "./graph/build.js";
|
|
4
|
+
import { GraphQueryEngine } from "./graph/query.js";
|
|
5
|
+
import { DEFAULT_GRAPH_RANKING_PROVIDER } from "./graph/ranking.js";
|
|
6
|
+
import { resolveTreeseedGraphRankingProvider } from "./platform/plugins.js";
|
|
7
|
+
class ContentGraphRuntime {
|
|
8
|
+
constructor(repoRoot, models, options = {}) {
|
|
9
|
+
this.repoRoot = repoRoot;
|
|
10
|
+
this.models = models;
|
|
11
|
+
this.rankingProvider = options.rankingProvider ?? (options.plugins?.length ? resolveTreeseedGraphRankingProvider(options.plugins, { projectRoot: repoRoot }) ?? DEFAULT_GRAPH_RANKING_PROVIDER : DEFAULT_GRAPH_RANKING_PROVIDER);
|
|
12
|
+
}
|
|
13
|
+
repoRoot;
|
|
14
|
+
models;
|
|
15
|
+
state = null;
|
|
16
|
+
queryEngine = null;
|
|
17
|
+
rankingProvider;
|
|
18
|
+
trackQuery(name, detail) {
|
|
19
|
+
if (!this.state) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.state.metrics.queryCounts[name] = (this.state.metrics.queryCounts[name] ?? 0) + 1;
|
|
23
|
+
if (detail && name === "followReferences") {
|
|
24
|
+
const edgeType = detail.split(":")[0] ?? "follow";
|
|
25
|
+
this.state.metrics.topTraversedEdgeTypes[edgeType] = (this.state.metrics.topTraversedEdgeTypes[edgeType] ?? 0) + 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async ensureLoaded() {
|
|
29
|
+
if (this.state && this.queryEngine) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.state = await loadGraphSnapshot(this.repoRoot, this.models);
|
|
33
|
+
if (!this.state) {
|
|
34
|
+
this.state = await refreshGraphBuildState(this.repoRoot, this.models);
|
|
35
|
+
await this.persist();
|
|
36
|
+
}
|
|
37
|
+
this.queryEngine = new GraphQueryEngine(this.state, (name, detail) => this.trackQuery(name, detail), this.rankingProvider);
|
|
38
|
+
}
|
|
39
|
+
async persist() {
|
|
40
|
+
if (!this.state || !this.queryEngine) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await saveGraphSnapshot(this.state);
|
|
44
|
+
const serializedIndexes = this.queryEngine.serializeIndexes();
|
|
45
|
+
await writeFile(
|
|
46
|
+
path.join(this.state.snapshotRoot, "indexes.json"),
|
|
47
|
+
`${JSON.stringify(serializedIndexes, null, 2)}
|
|
48
|
+
`,
|
|
49
|
+
"utf8"
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
async refresh(request) {
|
|
53
|
+
await this.ensureLoaded();
|
|
54
|
+
this.state = await refreshGraphBuildState(this.repoRoot, this.models, request, this.state);
|
|
55
|
+
this.queryEngine = new GraphQueryEngine(this.state, (name, detail) => this.trackQuery(name, detail), this.rankingProvider);
|
|
56
|
+
await this.persist();
|
|
57
|
+
return {
|
|
58
|
+
ready: true,
|
|
59
|
+
snapshotRoot: this.state.snapshotRoot,
|
|
60
|
+
changed: this.state.delta,
|
|
61
|
+
metrics: this.state.metrics
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Advanced lexical graph primitive for file nodes. */
|
|
65
|
+
async searchFiles(query, options) {
|
|
66
|
+
await this.ensureLoaded();
|
|
67
|
+
return this.queryEngine.searchFiles(query, options);
|
|
68
|
+
}
|
|
69
|
+
/** Advanced lexical graph primitive for section nodes. */
|
|
70
|
+
async searchSections(query, options) {
|
|
71
|
+
await this.ensureLoaded();
|
|
72
|
+
return this.queryEngine.searchSections(query, options);
|
|
73
|
+
}
|
|
74
|
+
/** Advanced lexical graph primitive for entity nodes. */
|
|
75
|
+
async searchEntities(query, options) {
|
|
76
|
+
await this.ensureLoaded();
|
|
77
|
+
return this.queryEngine.searchEntities(query, options);
|
|
78
|
+
}
|
|
79
|
+
async getNode(id) {
|
|
80
|
+
await this.ensureLoaded();
|
|
81
|
+
return this.queryEngine.getNode(id);
|
|
82
|
+
}
|
|
83
|
+
async getNeighbors(id, options) {
|
|
84
|
+
await this.ensureLoaded();
|
|
85
|
+
return this.queryEngine.getNeighbors(id, options);
|
|
86
|
+
}
|
|
87
|
+
async followReferences(id, options) {
|
|
88
|
+
await this.ensureLoaded();
|
|
89
|
+
return this.queryEngine.followReferences(id, options);
|
|
90
|
+
}
|
|
91
|
+
async getBacklinks(id, options) {
|
|
92
|
+
await this.ensureLoaded();
|
|
93
|
+
return this.queryEngine.getBacklinks(id, options);
|
|
94
|
+
}
|
|
95
|
+
async getRelated(id, options) {
|
|
96
|
+
await this.ensureLoaded();
|
|
97
|
+
return this.queryEngine.getRelated(id, options);
|
|
98
|
+
}
|
|
99
|
+
async getSubgraph(seedIds, options) {
|
|
100
|
+
await this.ensureLoaded();
|
|
101
|
+
return this.queryEngine.getSubgraph(seedIds, options);
|
|
102
|
+
}
|
|
103
|
+
async resolveSeeds(request) {
|
|
104
|
+
await this.ensureLoaded();
|
|
105
|
+
return this.queryEngine.resolveSeeds(request);
|
|
106
|
+
}
|
|
107
|
+
/** Preferred ranked graph retrieval entrypoint when using the graph runtime directly. */
|
|
108
|
+
async queryGraph(request) {
|
|
109
|
+
await this.ensureLoaded();
|
|
110
|
+
return this.queryEngine.queryGraph(request);
|
|
111
|
+
}
|
|
112
|
+
/** Preferred prompt-ready context assembly entrypoint when using the graph runtime directly. */
|
|
113
|
+
async buildContextPack(request) {
|
|
114
|
+
await this.ensureLoaded();
|
|
115
|
+
return this.queryEngine.buildContextPack(request);
|
|
116
|
+
}
|
|
117
|
+
/** Parses the public ctx DSL into a typed graph request. */
|
|
118
|
+
async parseGraphDsl(source) {
|
|
119
|
+
await this.ensureLoaded();
|
|
120
|
+
return this.queryEngine.parseDsl(source);
|
|
121
|
+
}
|
|
122
|
+
async resolveReference(reference, options) {
|
|
123
|
+
await this.ensureLoaded();
|
|
124
|
+
return this.queryEngine.resolveReference(reference, options);
|
|
125
|
+
}
|
|
126
|
+
async explainReferenceChain(fromId, toId) {
|
|
127
|
+
await this.ensureLoaded();
|
|
128
|
+
return this.queryEngine.explainReferenceChain(fromId, toId);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export {
|
|
132
|
+
ContentGraphRuntime
|
|
133
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { AgentSdk, ScopedAgentSdk } from './sdk.ts';
|
|
2
|
+
export { ContentGraphRuntime } from './graph.ts';
|
|
3
|
+
export { parseGraphDsl } from './graph/dsl.ts';
|
|
4
|
+
export { createDefaultGraphRankingProvider, DEFAULT_GRAPH_RANKING_PROVIDER } from './graph/ranking.ts';
|
|
5
|
+
export { BUILTIN_MODEL_REGISTRY, MODEL_REGISTRY, buildBuiltinModelRegistry, buildModelRegistry, buildScopedModelRegistry, mergeModelRegistries, resolveModelDefinition, } from './model-registry.ts';
|
|
6
|
+
export { normalizeAgentCliOptions, buildCopilotAllowToolArgs } from './cli-tools.ts';
|
|
7
|
+
export { resolveSdkRecordVersion } from './sdk-version.ts';
|
|
8
|
+
export { normalizeAliasedRecord, preprocessAliasedRecord, resolveAliasedField, } from './field-aliases.ts';
|
|
9
|
+
export { canonicalizeFrontmatter, normalizeFilterFields, normalizeMutationData, normalizeRecordToCanonicalShape, normalizeSortFields, readCanonicalFieldValue, resolveModelField, validateModelFieldAliases, } from './sdk-fields.ts';
|
|
10
|
+
export { RemoteTemplateCatalogClient, parseTemplateCatalogResponse } from './template-catalog.ts';
|
|
11
|
+
export { TREESEED_REMOTE_CONTRACT_HEADER, TREESEED_REMOTE_CONTRACT_VERSION, CloudflareQueuePullClient, RemoteTreeseedClient, RemoteTreeseedAuthClient, RemoteTreeseedSdkClient, RemoteTreeseedOperationsClient, TreeseedGatewayClient, } from './remote.ts';
|
|
12
|
+
export { TRESEED_OPERATION_SPECS, findTreeseedOperation, listTreeseedOperationNames, } from './operations-registry.ts';
|
|
13
|
+
export { TreeseedOperationsSdk } from './operations/runtime.ts';
|
|
14
|
+
export { TreeseedWorkflowSdk } from './workflow.ts';
|
|
15
|
+
export { getTreeseedVerifyDriverStatus, runTreeseedVerifyDriver } from './verification.ts';
|
|
16
|
+
export * from './platform/contracts.ts';
|
|
17
|
+
export * from './platform/tenant-config.ts';
|
|
18
|
+
export * from './platform/deploy-config.ts';
|
|
19
|
+
export * from './platform/deploy-runtime.ts';
|
|
20
|
+
export * from './platform/environment.ts';
|
|
21
|
+
export * from './platform/plugins.ts';
|
|
22
|
+
export type { SdkContentEntry, SdkCursorEntity, SdkFilterCondition, SdkFollowRequest, SdkGraphEdge, SdkGraphEdgeType, SdkGraphDslRelation, SdkGraphDslParseResult, SdkGraphModelConfig, SdkGraphNode, SdkGraphNodeType, SdkGraphPathExplanation, SdkGraphQueryStage, SdkGraphQueryView, SdkGraphQueryOptions, SdkGraphQueryRequest, SdkGraphQueryResult, SdkGraphRankingBuildInput, SdkGraphRankingDiagnostics, SdkGraphRankingIndex, SdkGraphRankingNodeResult, SdkGraphRankingProvider, SdkGraphRankingQueryRequest, SdkGraphRankingQueryResult, SdkGraphRankingSearchRequest, SdkGraphRefreshPayload, SdkGraphRefreshRequest, SdkGraphSearchOptions, SdkGraphSearchResult, SdkGraphSeed, SdkGraphSeedResolution, SdkGraphTraversalResult, SdkGraphWhereFilter, SdkContextPack, SdkContextPackRequest, SdkGetRequest, SdkJsonEnvelope, SdkLeaseEntity, SdkManagerContextPayload, SdkMessageEntity, SdkModelFieldBinding, SdkModelDefinition, SdkModelRegistry, SdkModelName, SdkMutationRequest, SdkOperation, SdkPickRequest, SdkPickResult, SdkQueueMessageEnvelope, SdkRunEntity, SdkSearchRequest, SdkTaskEntity, SdkTaskEventEntity, SdkTaskOutputEntity, SdkWorkDayEntity, SdkGraphRunEntity, SdkReportEntity, SdkSubscriptionEntity, SdkTemplateCatalogEntry, SdkTemplateCatalogPublisher, SdkTemplateCatalogResponse, SdkTemplateCatalogSource, SdkUpdateRequest, } from './sdk-types.ts';
|
|
23
|
+
export type { TreeseedFieldAliasBinding, TreeseedFieldAliasRegistry, } from './field-aliases.ts';
|
|
24
|
+
export type { TreeseedOperationContext, TreeseedOperationGroup, TreeseedOperationImplementation, TreeseedOperationId, TreeseedOperationMetadata, TreeseedOperationProvider, TreeseedOperationProviderId, TreeseedOperationRequest, TreeseedOperationResult, } from './operations-types.ts';
|
|
25
|
+
export type * from './workflow.ts';
|
|
26
|
+
export type { AgentDatabase } from './d1-store.ts';
|
|
27
|
+
export type { D1DatabaseLike, D1PreparedStatementLike } from './types/cloudflare.ts';
|
|
28
|
+
export type * from './remote.ts';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,101 @@
|
|
|
1
1
|
import { AgentSdk, ScopedAgentSdk } from "./sdk.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ContentGraphRuntime } from "./graph.js";
|
|
3
|
+
import { parseGraphDsl } from "./graph/dsl.js";
|
|
4
|
+
import { createDefaultGraphRankingProvider, DEFAULT_GRAPH_RANKING_PROVIDER } from "./graph/ranking.js";
|
|
5
|
+
import {
|
|
6
|
+
BUILTIN_MODEL_REGISTRY,
|
|
7
|
+
MODEL_REGISTRY,
|
|
8
|
+
buildBuiltinModelRegistry,
|
|
9
|
+
buildModelRegistry,
|
|
10
|
+
buildScopedModelRegistry,
|
|
11
|
+
mergeModelRegistries,
|
|
12
|
+
resolveModelDefinition
|
|
13
|
+
} from "./model-registry.js";
|
|
3
14
|
import { normalizeAgentCliOptions, buildCopilotAllowToolArgs } from "./cli-tools.js";
|
|
15
|
+
import { resolveSdkRecordVersion } from "./sdk-version.js";
|
|
16
|
+
import {
|
|
17
|
+
normalizeAliasedRecord,
|
|
18
|
+
preprocessAliasedRecord,
|
|
19
|
+
resolveAliasedField
|
|
20
|
+
} from "./field-aliases.js";
|
|
21
|
+
import {
|
|
22
|
+
canonicalizeFrontmatter,
|
|
23
|
+
normalizeFilterFields,
|
|
24
|
+
normalizeMutationData,
|
|
25
|
+
normalizeRecordToCanonicalShape,
|
|
26
|
+
normalizeSortFields,
|
|
27
|
+
readCanonicalFieldValue,
|
|
28
|
+
resolveModelField,
|
|
29
|
+
validateModelFieldAliases
|
|
30
|
+
} from "./sdk-fields.js";
|
|
31
|
+
import { RemoteTemplateCatalogClient, parseTemplateCatalogResponse } from "./template-catalog.js";
|
|
32
|
+
import {
|
|
33
|
+
TREESEED_REMOTE_CONTRACT_HEADER,
|
|
34
|
+
TREESEED_REMOTE_CONTRACT_VERSION,
|
|
35
|
+
CloudflareQueuePullClient,
|
|
36
|
+
RemoteTreeseedClient,
|
|
37
|
+
RemoteTreeseedAuthClient,
|
|
38
|
+
RemoteTreeseedSdkClient,
|
|
39
|
+
RemoteTreeseedOperationsClient,
|
|
40
|
+
TreeseedGatewayClient
|
|
41
|
+
} from "./remote.js";
|
|
42
|
+
import {
|
|
43
|
+
TRESEED_OPERATION_SPECS,
|
|
44
|
+
findTreeseedOperation,
|
|
45
|
+
listTreeseedOperationNames
|
|
46
|
+
} from "./operations-registry.js";
|
|
47
|
+
import { TreeseedOperationsSdk } from "./operations/runtime.js";
|
|
48
|
+
import { TreeseedWorkflowSdk } from "./workflow.js";
|
|
49
|
+
import { getTreeseedVerifyDriverStatus, runTreeseedVerifyDriver } from "./verification.js";
|
|
50
|
+
export * from "./platform/contracts.js";
|
|
51
|
+
export * from "./platform/tenant-config.js";
|
|
52
|
+
export * from "./platform/deploy-config.js";
|
|
53
|
+
export * from "./platform/deploy-runtime.js";
|
|
54
|
+
export * from "./platform/environment.js";
|
|
55
|
+
export * from "./platform/plugins.js";
|
|
4
56
|
export {
|
|
5
57
|
AgentSdk,
|
|
58
|
+
BUILTIN_MODEL_REGISTRY,
|
|
59
|
+
CloudflareQueuePullClient,
|
|
60
|
+
ContentGraphRuntime,
|
|
61
|
+
DEFAULT_GRAPH_RANKING_PROVIDER,
|
|
6
62
|
MODEL_REGISTRY,
|
|
63
|
+
RemoteTemplateCatalogClient,
|
|
64
|
+
RemoteTreeseedAuthClient,
|
|
65
|
+
RemoteTreeseedClient,
|
|
66
|
+
RemoteTreeseedOperationsClient,
|
|
67
|
+
RemoteTreeseedSdkClient,
|
|
7
68
|
ScopedAgentSdk,
|
|
69
|
+
TREESEED_REMOTE_CONTRACT_HEADER,
|
|
70
|
+
TREESEED_REMOTE_CONTRACT_VERSION,
|
|
71
|
+
TRESEED_OPERATION_SPECS,
|
|
72
|
+
TreeseedGatewayClient,
|
|
73
|
+
TreeseedOperationsSdk,
|
|
74
|
+
TreeseedWorkflowSdk,
|
|
75
|
+
buildBuiltinModelRegistry,
|
|
8
76
|
buildCopilotAllowToolArgs,
|
|
9
77
|
buildModelRegistry,
|
|
78
|
+
buildScopedModelRegistry,
|
|
79
|
+
canonicalizeFrontmatter,
|
|
80
|
+
createDefaultGraphRankingProvider,
|
|
81
|
+
findTreeseedOperation,
|
|
82
|
+
getTreeseedVerifyDriverStatus,
|
|
83
|
+
listTreeseedOperationNames,
|
|
84
|
+
mergeModelRegistries,
|
|
10
85
|
normalizeAgentCliOptions,
|
|
11
|
-
|
|
86
|
+
normalizeAliasedRecord,
|
|
87
|
+
normalizeFilterFields,
|
|
88
|
+
normalizeMutationData,
|
|
89
|
+
normalizeRecordToCanonicalShape,
|
|
90
|
+
normalizeSortFields,
|
|
91
|
+
parseGraphDsl,
|
|
92
|
+
parseTemplateCatalogResponse,
|
|
93
|
+
preprocessAliasedRecord,
|
|
94
|
+
readCanonicalFieldValue,
|
|
95
|
+
resolveAliasedField,
|
|
96
|
+
resolveModelDefinition,
|
|
97
|
+
resolveModelField,
|
|
98
|
+
resolveSdkRecordVersion,
|
|
99
|
+
runTreeseedVerifyDriver,
|
|
100
|
+
validateModelFieldAliases
|
|
12
101
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SdkBuiltinModelName, SdkModelDefinition, SdkModelRegistry } from './sdk-types.ts';
|
|
2
|
+
export declare function buildBuiltinModelRegistry(repoRoot?: string): Record<SdkBuiltinModelName, SdkModelDefinition>;
|
|
3
|
+
export declare function mergeModelRegistries(baseRegistry: SdkModelRegistry, definitions?: SdkModelDefinition[]): SdkModelRegistry;
|
|
4
|
+
export declare function buildModelRegistry(definitions?: SdkModelDefinition[]): SdkModelRegistry;
|
|
5
|
+
export declare function buildScopedModelRegistry(repoRoot: string | undefined, definitions?: SdkModelDefinition[]): SdkModelRegistry;
|
|
6
|
+
export declare const BUILTIN_MODEL_REGISTRY: SdkModelRegistry;
|
|
7
|
+
export declare const MODEL_REGISTRY: SdkModelRegistry;
|
|
8
|
+
export declare function resolveModelDefinition(model: string, registry?: SdkModelRegistry): SdkModelDefinition;
|