@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
package/dist/cli-tools.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const AGENT_CLI_ALLOW_TOOLS = [
|
|
2
|
+
"shell(git)",
|
|
3
|
+
"shell(npm)",
|
|
4
|
+
"web"
|
|
5
|
+
];
|
|
4
6
|
const ALLOWED_TOOL_SET = new Set(AGENT_CLI_ALLOW_TOOLS);
|
|
5
7
|
function normalizeStringArray(value, field) {
|
|
6
8
|
if (value === void 0 || value === null) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { SdkContentEntry, SdkFollowRequest, SdkGetRequest, SdkMutationRequest, SdkPickRequest, SdkPickResult, SdkSearchRequest, SdkUpdateRequest } from './sdk-types.ts';
|
|
1
|
+
import type { SdkContentEntry, SdkFollowRequest, SdkGetRequest, SdkModelRegistry, SdkMutationRequest, SdkPickRequest, SdkPickResult, SdkSearchRequest, SdkUpdateRequest } from './sdk-types.ts';
|
|
2
2
|
import type { AgentDatabase } from './d1-store.ts';
|
|
3
3
|
export declare class ContentStore {
|
|
4
4
|
private readonly repoRoot;
|
|
5
5
|
private readonly database;
|
|
6
|
+
private readonly models;
|
|
6
7
|
private readonly gitRuntime;
|
|
7
|
-
constructor(repoRoot: string, database: AgentDatabase);
|
|
8
|
+
constructor(repoRoot: string, database: AgentDatabase, models: SdkModelRegistry);
|
|
8
9
|
list(model: string): Promise<SdkContentEntry[]>;
|
|
9
10
|
get(request: SdkGetRequest): Promise<SdkContentEntry | null>;
|
|
10
11
|
search(request: SdkSearchRequest): Promise<SdkContentEntry[]>;
|
package/dist/content-store.js
CHANGED
|
@@ -4,7 +4,26 @@ import crypto from "node:crypto";
|
|
|
4
4
|
import { parseFrontmatterDocument, serializeFrontmatterDocument } from "./frontmatter.js";
|
|
5
5
|
import { resolveModelDefinition } from "./model-registry.js";
|
|
6
6
|
import { applyFilters, applySort } from "./sdk-filters.js";
|
|
7
|
+
import { canonicalizeFrontmatter, normalizeFilterFields, normalizeMutationData, normalizeRecordToCanonicalShape, normalizeSortFields, readCanonicalFieldValue } from "./sdk-fields.js";
|
|
8
|
+
import { assertExpectedVersion } from "./sdk-version.js";
|
|
7
9
|
import { GitRuntime } from "./git-runtime.js";
|
|
10
|
+
function pickSortForStrategy(definition, request) {
|
|
11
|
+
switch (request.strategy) {
|
|
12
|
+
case "oldest":
|
|
13
|
+
return [{ field: definition.pickField, direction: "asc" }];
|
|
14
|
+
case "highest_priority":
|
|
15
|
+
if (definition.sortableFields.includes("priority") || definition.filterableFields.includes("priority")) {
|
|
16
|
+
return [
|
|
17
|
+
{ field: "priority", direction: "desc" },
|
|
18
|
+
{ field: definition.pickField, direction: "desc" }
|
|
19
|
+
];
|
|
20
|
+
}
|
|
21
|
+
return [{ field: definition.pickField, direction: "desc" }];
|
|
22
|
+
case "latest":
|
|
23
|
+
default:
|
|
24
|
+
return [{ field: definition.pickField, direction: "desc" }];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
8
27
|
async function walkMarkdownFiles(root) {
|
|
9
28
|
try {
|
|
10
29
|
const entries = await readdir(root, { withFileTypes: true });
|
|
@@ -45,16 +64,20 @@ async function readContentEntry(definition, filePath, contentDir) {
|
|
|
45
64
|
const parsed = parseFrontmatterDocument(source);
|
|
46
65
|
const fileStats = await stat(filePath);
|
|
47
66
|
const slug = inferSlug(filePath, contentDir);
|
|
67
|
+
const titleField = definition.fields.title ? readCanonicalFieldValue(definition, { frontmatter: parsed.frontmatter }, "title") : void 0;
|
|
68
|
+
const createdField = definition.fields.created_at ? readCanonicalFieldValue(definition, { frontmatter: parsed.frontmatter }, "created_at") : void 0;
|
|
69
|
+
const updatedField = definition.fields.updated_at ? readCanonicalFieldValue(definition, { frontmatter: parsed.frontmatter }, "updated_at") : void 0;
|
|
70
|
+
const nameField = definition.fields.name ? readCanonicalFieldValue(definition, { frontmatter: parsed.frontmatter }, "name") : void 0;
|
|
48
71
|
return {
|
|
49
72
|
id: slug,
|
|
50
73
|
slug,
|
|
51
74
|
model: definition.name,
|
|
52
|
-
title: typeof
|
|
75
|
+
title: typeof titleField === "string" ? String(titleField) : typeof nameField === "string" ? String(nameField) : void 0,
|
|
53
76
|
path: filePath,
|
|
54
77
|
body: parsed.body,
|
|
55
78
|
frontmatter: parsed.frontmatter,
|
|
56
|
-
createdAt: typeof
|
|
57
|
-
updatedAt: typeof
|
|
79
|
+
createdAt: typeof createdField === "string" ? String(createdField) : fileStats.birthtime.toISOString(),
|
|
80
|
+
updatedAt: typeof updatedField === "string" ? String(updatedField) : fileStats.mtime.toISOString()
|
|
58
81
|
};
|
|
59
82
|
}
|
|
60
83
|
function entryMatchesIdentity(entry, request) {
|
|
@@ -72,9 +95,10 @@ function sanitizeFrontmatterInput(data) {
|
|
|
72
95
|
return next;
|
|
73
96
|
}
|
|
74
97
|
class ContentStore {
|
|
75
|
-
constructor(repoRoot, database) {
|
|
98
|
+
constructor(repoRoot, database, models) {
|
|
76
99
|
this.repoRoot = repoRoot;
|
|
77
100
|
this.database = database;
|
|
101
|
+
this.models = models;
|
|
78
102
|
this.gitRuntime = new GitRuntime(
|
|
79
103
|
repoRoot,
|
|
80
104
|
process.env.TREESEED_AGENT_DISABLE_GIT === "true"
|
|
@@ -82,9 +106,10 @@ class ContentStore {
|
|
|
82
106
|
}
|
|
83
107
|
repoRoot;
|
|
84
108
|
database;
|
|
109
|
+
models;
|
|
85
110
|
gitRuntime;
|
|
86
111
|
async list(model) {
|
|
87
|
-
const definition = resolveModelDefinition(model);
|
|
112
|
+
const definition = resolveModelDefinition(model, this.models);
|
|
88
113
|
if (definition.storage !== "content" || !definition.contentDir) {
|
|
89
114
|
throw new Error(`Model "${model}" is not content-backed.`);
|
|
90
115
|
}
|
|
@@ -122,9 +147,10 @@ class ContentStore {
|
|
|
122
147
|
return entries.find((entry) => entryMatchesIdentity(entry, request)) ?? null;
|
|
123
148
|
}
|
|
124
149
|
async search(request) {
|
|
150
|
+
const definition = resolveModelDefinition(request.model, this.models);
|
|
125
151
|
const items = await this.list(request.model);
|
|
126
|
-
const filtered = applyFilters(items, request.filters);
|
|
127
|
-
const sorted = applySort(filtered, request.sort);
|
|
152
|
+
const filtered = applyFilters(items, normalizeFilterFields(definition, request.filters), definition);
|
|
153
|
+
const sorted = applySort(filtered, normalizeSortFields(definition, request.sort), definition);
|
|
128
154
|
return sorted.slice(0, request.limit ?? sorted.length);
|
|
129
155
|
}
|
|
130
156
|
async follow(request) {
|
|
@@ -145,11 +171,11 @@ class ContentStore {
|
|
|
145
171
|
};
|
|
146
172
|
}
|
|
147
173
|
async pick(request) {
|
|
148
|
-
const definition = resolveModelDefinition(request.model);
|
|
174
|
+
const definition = resolveModelDefinition(request.model, this.models);
|
|
149
175
|
const sorted = await this.search({
|
|
150
176
|
model: request.model,
|
|
151
177
|
filters: request.filters,
|
|
152
|
-
sort:
|
|
178
|
+
sort: pickSortForStrategy(definition, request),
|
|
153
179
|
limit: 25
|
|
154
180
|
});
|
|
155
181
|
for (const item of sorted) {
|
|
@@ -172,7 +198,7 @@ class ContentStore {
|
|
|
172
198
|
};
|
|
173
199
|
}
|
|
174
200
|
async create(request) {
|
|
175
|
-
const definition = resolveModelDefinition(request.model);
|
|
201
|
+
const definition = resolveModelDefinition(request.model, this.models);
|
|
176
202
|
ensureMutationAllowed(definition, "create");
|
|
177
203
|
if (!definition.contentDir) {
|
|
178
204
|
throw new Error(`Model "${request.model}" is not content-backed.`);
|
|
@@ -185,11 +211,12 @@ class ContentStore {
|
|
|
185
211
|
const contentDirInWorktree = path.join(worktreePath, path.relative(this.repoRoot, definition.contentDir));
|
|
186
212
|
const relativePath = path.relative(this.repoRoot, path.join(definition.contentDir, `${slug}${extension}`));
|
|
187
213
|
const filePath = path.join(worktreePath, relativePath);
|
|
188
|
-
const
|
|
189
|
-
|
|
214
|
+
const mutationData = normalizeMutationData(definition, sanitizeFrontmatterInput(request.data));
|
|
215
|
+
const frontmatter = canonicalizeFrontmatter(definition, {}, {
|
|
216
|
+
...mutationData,
|
|
190
217
|
slug,
|
|
191
|
-
|
|
192
|
-
};
|
|
218
|
+
updated_at: mutationData.updated_at ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
219
|
+
});
|
|
193
220
|
await mkdir(path.dirname(filePath), { recursive: true });
|
|
194
221
|
await writeFile(filePath, serializeFrontmatterDocument(frontmatter, body), "utf8");
|
|
195
222
|
const git = await this.gitRuntime.commitFileChange(
|
|
@@ -203,21 +230,26 @@ class ContentStore {
|
|
|
203
230
|
};
|
|
204
231
|
}
|
|
205
232
|
async update(request) {
|
|
206
|
-
const definition = resolveModelDefinition(request.model);
|
|
233
|
+
const definition = resolveModelDefinition(request.model, this.models);
|
|
207
234
|
ensureMutationAllowed(definition, "update");
|
|
208
235
|
const existing = await this.get(request);
|
|
209
236
|
if (!existing) {
|
|
210
237
|
throw new Error(`No ${request.model} entry found for update.`);
|
|
211
238
|
}
|
|
239
|
+
assertExpectedVersion(request.expectedVersion, existing, `${definition.name} "${existing.slug}"`);
|
|
212
240
|
const branchName = `${String(request.data.branchPrefix ?? "agent")}/${definition.name}-${existing.slug}`;
|
|
213
241
|
const worktreePath = await this.gitRuntime.ensureWorktree(branchName);
|
|
214
242
|
const relativePath = path.relative(this.repoRoot, existing.path);
|
|
215
243
|
const targetPath = path.join(worktreePath, relativePath);
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
244
|
+
const mutationData = normalizeMutationData(definition, sanitizeFrontmatterInput(request.data));
|
|
245
|
+
const nextFrontmatter = canonicalizeFrontmatter(
|
|
246
|
+
definition,
|
|
247
|
+
normalizeRecordToCanonicalShape(definition, existing.frontmatter),
|
|
248
|
+
{
|
|
249
|
+
...mutationData,
|
|
250
|
+
updated_at: mutationData.updated_at ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
251
|
+
}
|
|
252
|
+
);
|
|
221
253
|
const nextBody = typeof request.data.body === "string" ? request.data.body : existing.body;
|
|
222
254
|
await mkdir(path.dirname(targetPath), { recursive: true });
|
|
223
255
|
await writeFile(targetPath, serializeFrontmatterDocument(nextFrontmatter, nextBody), "utf8");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContentLeaseRecord } from './types/agents.ts';
|
|
2
2
|
import type { D1DatabaseLike } from './types/cloudflare.ts';
|
|
3
|
-
import type { SdkAckMessageRequest, SdkClaimMessageRequest, SdkCreateMessageRequest, SdkCursorEntity, SdkCursorRequest, SdkFollowRequest, SdkGetRequest, SdkGetCursorRequest, SdkLeaseEntity, SdkLeaseReleaseRequest, SdkMessageEntity, SdkMutationRequest, SdkPickRequest, SdkPickResult, SdkRecordRunRequest, SdkRunEntity, SdkSearchRequest, SdkSubscriptionEntity, SdkUpdateRequest } from './sdk-types.ts';
|
|
3
|
+
import type { SdkAppendTaskEventRequest, SdkAckMessageRequest, SdkClaimMessageRequest, SdkClaimTaskRequest, SdkCloseWorkDayRequest, SdkCompleteTaskRequest, SdkCreateReportRequest, SdkCreateMessageRequest, SdkCreateTaskRequest, SdkCursorEntity, SdkCursorRequest, SdkFailTaskRequest, SdkFollowRequest, SdkGetRequest, SdkGetCursorRequest, SdkLeaseEntity, SdkLeaseReleaseRequest, SdkManagerContextPayload, SdkMessageEntity, SdkMutationRequest, SdkPickRequest, SdkPickResult, SdkRecordRunRequest, SdkReportEntity, SdkRunEntity, SdkSearchRequest, SdkStartWorkDayRequest, SdkSubscriptionEntity, SdkTaskEntity, SdkTaskSearchRequest, SdkTaskProgressRequest, SdkUpdateRequest, SdkWorkDayEntity } from './sdk-types.ts';
|
|
4
4
|
import { type LeaseClaimInput } from './stores/lease-store.ts';
|
|
5
5
|
export interface TryClaimContentLeaseInput extends LeaseClaimInput {
|
|
6
6
|
}
|
|
@@ -23,6 +23,17 @@ export interface AgentDatabase {
|
|
|
23
23
|
releaseLease(request: SdkLeaseReleaseRequest): Promise<void>;
|
|
24
24
|
tryClaimContentLease(input: TryClaimContentLeaseInput): Promise<string | null>;
|
|
25
25
|
releaseAllLeases(): Promise<number>;
|
|
26
|
+
startWorkDay(request: SdkStartWorkDayRequest): Promise<SdkWorkDayEntity | null>;
|
|
27
|
+
closeWorkDay(request: SdkCloseWorkDayRequest): Promise<SdkWorkDayEntity | null>;
|
|
28
|
+
createTask(request: SdkCreateTaskRequest): Promise<SdkTaskEntity | null>;
|
|
29
|
+
claimTask(request: SdkClaimTaskRequest): Promise<SdkTaskEntity | null>;
|
|
30
|
+
recordTaskProgress(request: SdkTaskProgressRequest): Promise<SdkTaskEntity | null>;
|
|
31
|
+
completeTask(request: SdkCompleteTaskRequest): Promise<SdkTaskEntity | null>;
|
|
32
|
+
failTask(request: SdkFailTaskRequest): Promise<SdkTaskEntity | null>;
|
|
33
|
+
appendTaskEvent(request: SdkAppendTaskEventRequest): Promise<Record<string, unknown> | null>;
|
|
34
|
+
searchTasks(request: SdkTaskSearchRequest): Promise<SdkTaskEntity[]>;
|
|
35
|
+
createReport(request: SdkCreateReportRequest): Promise<SdkReportEntity | null>;
|
|
36
|
+
getManagerContext(taskId: string): Promise<SdkManagerContextPayload>;
|
|
26
37
|
}
|
|
27
38
|
export declare class MemoryAgentDatabase implements AgentDatabase {
|
|
28
39
|
private readonly subscriptions;
|
|
@@ -30,6 +41,12 @@ export declare class MemoryAgentDatabase implements AgentDatabase {
|
|
|
30
41
|
private readonly runs;
|
|
31
42
|
private readonly contentLeases;
|
|
32
43
|
private readonly cursors;
|
|
44
|
+
private readonly workDays;
|
|
45
|
+
private readonly tasks;
|
|
46
|
+
private readonly taskEvents;
|
|
47
|
+
private readonly taskOutputs;
|
|
48
|
+
private readonly graphRuns;
|
|
49
|
+
private readonly reports;
|
|
33
50
|
private messageId;
|
|
34
51
|
constructor(seed?: {
|
|
35
52
|
subscriptions?: SdkSubscriptionEntity[];
|
|
@@ -72,6 +89,31 @@ export declare class MemoryAgentDatabase implements AgentDatabase {
|
|
|
72
89
|
releaseAllLeases(): Promise<number>;
|
|
73
90
|
inspectRuns(): SdkRunEntity[];
|
|
74
91
|
inspectLeases(): ContentLeaseRecord[];
|
|
92
|
+
startWorkDay(request: SdkStartWorkDayRequest): Promise<SdkWorkDayEntity>;
|
|
93
|
+
closeWorkDay(request: SdkCloseWorkDayRequest): Promise<SdkWorkDayEntity | null>;
|
|
94
|
+
createTask(request: SdkCreateTaskRequest): Promise<SdkTaskEntity>;
|
|
95
|
+
claimTask(request: SdkClaimTaskRequest): Promise<SdkTaskEntity | null>;
|
|
96
|
+
recordTaskProgress(request: SdkTaskProgressRequest): Promise<SdkTaskEntity | null>;
|
|
97
|
+
completeTask(request: SdkCompleteTaskRequest): Promise<SdkTaskEntity | null>;
|
|
98
|
+
failTask(request: SdkFailTaskRequest): Promise<SdkTaskEntity | null>;
|
|
99
|
+
appendTaskEvent(request: SdkAppendTaskEventRequest): Promise<{
|
|
100
|
+
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
101
|
+
taskId: string;
|
|
102
|
+
seq: number;
|
|
103
|
+
kind: string;
|
|
104
|
+
dataJson: string;
|
|
105
|
+
createdAt: string;
|
|
106
|
+
}>;
|
|
107
|
+
searchTasks(request: SdkTaskSearchRequest): Promise<SdkTaskEntity[]>;
|
|
108
|
+
createReport(request: SdkCreateReportRequest): Promise<SdkReportEntity>;
|
|
109
|
+
getManagerContext(taskId: string): Promise<{
|
|
110
|
+
task: SdkTaskEntity | null;
|
|
111
|
+
workDay: SdkWorkDayEntity | null;
|
|
112
|
+
agent: null;
|
|
113
|
+
graph: {
|
|
114
|
+
graphVersion: string;
|
|
115
|
+
} | null;
|
|
116
|
+
}>;
|
|
75
117
|
}
|
|
76
118
|
export declare class CloudflareD1AgentDatabase implements AgentDatabase {
|
|
77
119
|
readonly db: D1DatabaseLike;
|
|
@@ -80,6 +122,7 @@ export declare class CloudflareD1AgentDatabase implements AgentDatabase {
|
|
|
80
122
|
private readonly runs;
|
|
81
123
|
private readonly cursors;
|
|
82
124
|
private readonly leases;
|
|
125
|
+
private readonly operational;
|
|
83
126
|
constructor(db: D1DatabaseLike);
|
|
84
127
|
get(request: SdkGetRequest): Promise<Record<string, unknown> | null>;
|
|
85
128
|
search(request: SdkSearchRequest): Promise<Record<string, unknown>[]>;
|
|
@@ -105,4 +148,22 @@ export declare class CloudflareD1AgentDatabase implements AgentDatabase {
|
|
|
105
148
|
releaseLease(request: SdkLeaseReleaseRequest): Promise<void>;
|
|
106
149
|
tryClaimContentLease(input: TryClaimContentLeaseInput): Promise<`${string}-${string}-${string}-${string}-${string}` | null>;
|
|
107
150
|
releaseAllLeases(): Promise<number>;
|
|
151
|
+
startWorkDay(request: SdkStartWorkDayRequest): Promise<SdkWorkDayEntity | null>;
|
|
152
|
+
closeWorkDay(request: SdkCloseWorkDayRequest): Promise<SdkWorkDayEntity | null>;
|
|
153
|
+
createTask(request: SdkCreateTaskRequest): Promise<SdkTaskEntity | null>;
|
|
154
|
+
claimTask(request: SdkClaimTaskRequest): Promise<SdkTaskEntity | null>;
|
|
155
|
+
recordTaskProgress(request: SdkTaskProgressRequest): Promise<SdkTaskEntity | null>;
|
|
156
|
+
completeTask(request: SdkCompleteTaskRequest): Promise<SdkTaskEntity | null>;
|
|
157
|
+
failTask(request: SdkFailTaskRequest): Promise<SdkTaskEntity | null>;
|
|
158
|
+
appendTaskEvent(request: SdkAppendTaskEventRequest): Promise<import("./sdk-types.ts").SdkTaskEventEntity | null>;
|
|
159
|
+
searchTasks(request: SdkTaskSearchRequest): Promise<SdkTaskEntity[]>;
|
|
160
|
+
createReport(request: SdkCreateReportRequest): Promise<SdkReportEntity | null>;
|
|
161
|
+
getManagerContext(taskId: string): Promise<{
|
|
162
|
+
task: SdkTaskEntity | null;
|
|
163
|
+
workDay: SdkWorkDayEntity | null;
|
|
164
|
+
agent: null;
|
|
165
|
+
graph: {
|
|
166
|
+
graphVersion: string;
|
|
167
|
+
} | null;
|
|
168
|
+
}>;
|
|
108
169
|
}
|