@treeseed/core 0.4.9 → 0.4.11
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 +1 -2
- package/dist/agent.d.ts +0 -1
- package/dist/agent.js +0 -2
- package/dist/agents/spec-types.d.ts +10 -10
- package/dist/api/agent-routes.d.ts +2 -2
- package/dist/api/agent-routes.js +51 -125
- package/dist/api/app.js +56 -4
- package/dist/api/auth/d1-store.d.ts +1 -0
- package/dist/api/auth/d1-store.js +21 -1
- package/dist/api/auth/rbac.d.ts +2 -2
- package/dist/api/auth/rbac.js +2 -1
- package/dist/api/config.js +4 -0
- package/dist/api/http.d.ts +4 -0
- package/dist/api/http.js +7 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +2 -2
- package/dist/api/operations-routes.d.ts +1 -0
- package/dist/api/operations-routes.js +6 -1
- package/dist/api/railway.d.ts +4 -0
- package/dist/api/sdk-dispatch.d.ts +2 -11
- package/dist/api/sdk-dispatch.js +1 -133
- package/dist/api/sdk-routes.d.ts +1 -0
- package/dist/api/sdk-routes.js +5 -1
- package/dist/api/types.d.ts +32 -16
- package/dist/components/site/RouteNotFound.astro +25 -0
- package/dist/content-config.d.ts +1 -0
- package/dist/content.d.ts +1 -0
- package/dist/content.js +177 -1
- package/dist/dev.d.ts +7 -2
- package/dist/dev.js +83 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -3
- package/dist/middleware/editorial-preview.d.ts +26 -0
- package/dist/middleware/editorial-preview.js +37 -0
- package/dist/middleware/starlightRouteData.js +15 -4
- package/dist/pages/[slug].astro +12 -10
- package/dist/pages/agents/[slug].astro +28 -21
- package/dist/pages/books/[slug].astro +19 -12
- package/dist/pages/feed.xml.js +6 -4
- package/dist/pages/index.astro +43 -14
- package/dist/pages/notes/[slug].astro +19 -12
- package/dist/pages/objectives/[slug].astro +30 -23
- package/dist/pages/people/[slug].astro +28 -21
- package/dist/pages/questions/[slug].astro +30 -23
- package/dist/scripts/build-dist.js +6 -1
- package/dist/scripts/dev-platform.js +9 -1
- package/dist/scripts/test-smoke.js +0 -1
- package/dist/services/agents.d.ts +22 -0
- package/dist/services/agents.js +29 -0
- package/dist/services/common.d.ts +37 -4
- package/dist/services/common.js +135 -17
- package/dist/services/index.d.ts +4 -1
- package/dist/services/index.js +14 -2
- package/dist/services/manager.d.ts +246 -3
- package/dist/services/manager.js +1101 -171
- package/dist/services/remote-runner.d.ts +30 -0
- package/dist/services/remote-runner.js +111 -0
- package/dist/services/workday-content.d.ts +53 -0
- package/dist/services/workday-content.js +190 -0
- package/dist/services/workday-report.d.ts +160 -2
- package/dist/services/workday-report.js +4 -31
- package/dist/services/workday-start.d.ts +174 -1
- package/dist/services/workday-start.js +3 -13
- package/dist/services/worker-pool-scaler.d.ts +27 -0
- package/dist/services/worker-pool-scaler.js +109 -0
- package/dist/services/worker.d.ts +7 -0
- package/dist/services/worker.js +41 -57
- package/dist/site.js +43 -27
- package/dist/templates.d.ts +98 -0
- package/dist/templates.js +170 -0
- package/dist/tenant/runtime-config.d.ts +4 -0
- package/dist/tenant/runtime-config.js +34 -1
- package/dist/utils/hub-content.js +35 -0
- package/dist/utils/published-content.js +60 -0
- package/dist/utils/site-models.d.ts +6 -0
- package/dist/utils/site-models.js +16 -0
- package/dist/utils/starlight-nav.js +50 -0
- package/package.json +23 -9
- package/templates/github/deploy.workflow.yml +404 -9
- package/templates/github/hosted-project.workflow.yml +77 -0
- package/dist/api/gateway.d.ts +0 -5
- package/dist/api/gateway.js +0 -35
|
@@ -2,30 +2,37 @@
|
|
|
2
2
|
import { getCollection, render } from 'astro:content';
|
|
3
3
|
import AuthoredEntryLayout from '../../layouts/AuthoredEntryLayout.astro';
|
|
4
4
|
import { resolveContributor, resolveReferences } from '../../utils/hub-content';
|
|
5
|
+
import RouteNotFound from '../../components/site/RouteNotFound.astro';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
const objectives = await getCollection('objectives', ({ data }) => !data.draft);
|
|
8
|
-
return objectives.map((objective) => ({
|
|
9
|
-
params: { slug: objective.id },
|
|
10
|
-
props: { objective },
|
|
11
|
-
}));
|
|
12
|
-
}
|
|
7
|
+
export const prerender = false;
|
|
13
8
|
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const slug = String(Astro.params.slug ?? '');
|
|
10
|
+
const objectives = await getCollection('objectives', ({ data }) => !data.draft);
|
|
11
|
+
const objective = objectives.find((candidate) => candidate.id === slug) ?? null;
|
|
12
|
+
if (!objective) {
|
|
13
|
+
Astro.response.status = 404;
|
|
14
|
+
}
|
|
15
|
+
const rendered = objective ? await render(objective) : null;
|
|
16
|
+
const Content = rendered?.Content ?? null;
|
|
17
|
+
const contributor = objective ? await resolveContributor(objective.data.primaryContributor) : null;
|
|
18
|
+
const relatedQuestions = objective ? await resolveReferences(objective.data.relatedQuestions) : [];
|
|
19
|
+
const relatedBooks = objective ? await resolveReferences(objective.data.relatedBooks) : [];
|
|
19
20
|
---
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
{
|
|
23
|
+
!objective || !Content ? (
|
|
24
|
+
<RouteNotFound title="Objective not found" description="The requested objective could not be found in this Treeseed." currentPath="/objectives/" />
|
|
25
|
+
) : (
|
|
26
|
+
<AuthoredEntryLayout
|
|
27
|
+
entry={objective.data}
|
|
28
|
+
currentPath="/objectives/"
|
|
29
|
+
contributor={contributor}
|
|
30
|
+
metaLabel="Time horizon"
|
|
31
|
+
metaValue={objective.data.timeHorizon}
|
|
32
|
+
relatedQuestions={relatedQuestions}
|
|
33
|
+
relatedBooks={relatedBooks}
|
|
34
|
+
>
|
|
35
|
+
<Content />
|
|
36
|
+
</AuthoredEntryLayout>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -2,28 +2,35 @@
|
|
|
2
2
|
import { getCollection, render } from 'astro:content';
|
|
3
3
|
import ProfileLayout from '../../layouts/ProfileLayout.astro';
|
|
4
4
|
import { resolveReferences } from '../../utils/hub-content';
|
|
5
|
+
import RouteNotFound from '../../components/site/RouteNotFound.astro';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
const people = await getCollection('people');
|
|
8
|
-
return people.map((person) => ({
|
|
9
|
-
params: { slug: person.id },
|
|
10
|
-
props: { person },
|
|
11
|
-
}));
|
|
12
|
-
}
|
|
7
|
+
export const prerender = false;
|
|
13
8
|
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
9
|
+
const slug = String(Astro.params.slug ?? '');
|
|
10
|
+
const people = await getCollection('people');
|
|
11
|
+
const person = people.find((candidate) => candidate.id === slug) ?? null;
|
|
12
|
+
if (!person) {
|
|
13
|
+
Astro.response.status = 404;
|
|
14
|
+
}
|
|
15
|
+
const rendered = person ? await render(person) : null;
|
|
16
|
+
const Content = rendered?.Content ?? null;
|
|
17
|
+
const relatedQuestions = person ? await resolveReferences(person.data.relatedQuestions) : [];
|
|
18
|
+
const relatedObjectives = person ? await resolveReferences(person.data.relatedObjectives) : [];
|
|
18
19
|
---
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
{
|
|
22
|
+
!person || !Content ? (
|
|
23
|
+
<RouteNotFound title="Profile not found" description="The requested person profile could not be found in this Treeseed." currentPath="/people/" />
|
|
24
|
+
) : (
|
|
25
|
+
<ProfileLayout
|
|
26
|
+
entry={person.data}
|
|
27
|
+
currentPath="/people/"
|
|
28
|
+
metaLabel="Role"
|
|
29
|
+
metaValue={`${person.data.role} · ${person.data.affiliation}`}
|
|
30
|
+
relatedQuestions={relatedQuestions}
|
|
31
|
+
relatedObjectives={relatedObjectives}
|
|
32
|
+
>
|
|
33
|
+
<Content />
|
|
34
|
+
</ProfileLayout>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -2,30 +2,37 @@
|
|
|
2
2
|
import { getCollection, render } from 'astro:content';
|
|
3
3
|
import AuthoredEntryLayout from '../../layouts/AuthoredEntryLayout.astro';
|
|
4
4
|
import { resolveContributor, resolveReferences } from '../../utils/hub-content';
|
|
5
|
+
import RouteNotFound from '../../components/site/RouteNotFound.astro';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
const questions = await getCollection('questions', ({ data }) => !data.draft);
|
|
8
|
-
return questions.map((question) => ({
|
|
9
|
-
params: { slug: question.id },
|
|
10
|
-
props: { question },
|
|
11
|
-
}));
|
|
12
|
-
}
|
|
7
|
+
export const prerender = false;
|
|
13
8
|
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const slug = String(Astro.params.slug ?? '');
|
|
10
|
+
const questions = await getCollection('questions', ({ data }) => !data.draft);
|
|
11
|
+
const question = questions.find((candidate) => candidate.id === slug) ?? null;
|
|
12
|
+
if (!question) {
|
|
13
|
+
Astro.response.status = 404;
|
|
14
|
+
}
|
|
15
|
+
const rendered = question ? await render(question) : null;
|
|
16
|
+
const Content = rendered?.Content ?? null;
|
|
17
|
+
const contributor = question ? await resolveContributor(question.data.primaryContributor) : null;
|
|
18
|
+
const relatedObjectives = question ? await resolveReferences(question.data.relatedObjectives) : [];
|
|
19
|
+
const relatedBooks = question ? await resolveReferences(question.data.relatedBooks) : [];
|
|
19
20
|
---
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
{
|
|
23
|
+
!question || !Content ? (
|
|
24
|
+
<RouteNotFound title="Question not found" description="The requested question could not be found in this Treeseed." currentPath="/questions/" />
|
|
25
|
+
) : (
|
|
26
|
+
<AuthoredEntryLayout
|
|
27
|
+
entry={question.data}
|
|
28
|
+
currentPath="/questions/"
|
|
29
|
+
contributor={contributor}
|
|
30
|
+
metaLabel="Question type"
|
|
31
|
+
metaValue={question.data.questionType}
|
|
32
|
+
relatedObjectives={relatedObjectives}
|
|
33
|
+
relatedBooks={relatedBooks}
|
|
34
|
+
>
|
|
35
|
+
<Content />
|
|
36
|
+
</AuthoredEntryLayout>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -204,7 +204,10 @@ function rewriteDeclarations() {
|
|
|
204
204
|
}
|
|
205
205
|
function emitTypeDeclarations() {
|
|
206
206
|
const sourceFiles = [
|
|
207
|
+
resolve(srcRoot, 'types/astro-build.d.ts'),
|
|
207
208
|
resolve(srcRoot, 'types/cloudflare.ts'),
|
|
209
|
+
resolve(srcRoot, 'utils/site-models.ts'),
|
|
210
|
+
resolve(srcRoot, 'middleware/editorial-preview.ts'),
|
|
208
211
|
resolve(srcRoot, 'site-resources.ts'),
|
|
209
212
|
resolve(srcRoot, 'platform-resources.ts'),
|
|
210
213
|
resolve(srcRoot, 'api.ts'),
|
|
@@ -212,6 +215,7 @@ function emitTypeDeclarations() {
|
|
|
212
215
|
resolve(srcRoot, 'agent-runtime.ts'),
|
|
213
216
|
resolve(srcRoot, 'railway.ts'),
|
|
214
217
|
resolve(srcRoot, 'platform.ts'),
|
|
218
|
+
resolve(srcRoot, 'templates.ts'),
|
|
215
219
|
resolve(srcRoot, 'services/index.ts'),
|
|
216
220
|
resolve(srcRoot, 'plugin-default.ts'),
|
|
217
221
|
resolve(srcRoot, 'index.ts'),
|
|
@@ -370,8 +374,9 @@ async function main() {
|
|
|
370
374
|
}
|
|
371
375
|
writeCompatibilityEntrypoint(resolve(distRoot, 'config.js'), "import starlight from './vendor/starlight/index.js';\nimport { loadTreeseedManifest } from '@treeseed/sdk/platform/tenant-config';\nimport { createTreeseedSite } from './site.js';\n\nexport function createTreeseedTenantSite(manifestPath) {\n\tconst tenant = loadTreeseedManifest(manifestPath);\n\treturn createTreeseedSite(tenant, { starlight });\n}");
|
|
372
376
|
writeCompatibilityEntrypoint(resolve(distRoot, 'config.d.ts'), "export declare function createTreeseedTenantSite(manifestPath?: string): import('astro').AstroUserConfig<never, never, never>;");
|
|
377
|
+
writeCompatibilityEntrypoint(resolve(distRoot, 'content.d.ts'), "export declare function createTreeseedCollections(tenantConfig: any, dependencies: any): Record<string, any>;");
|
|
373
378
|
writeCompatibilityEntrypoint(resolve(distRoot, 'content-config.js'), "import { loadTreeseedManifest } from '@treeseed/sdk/platform/tenant-config';\nimport { docsLoader } from './vendor/starlight/loaders.js';\nimport { docsSchema } from './vendor/starlight/schema.js';\nimport { createTreeseedCollections } from './content.js';\n\nexport function createTreeseedTenantCollections(manifestPath) {\n\tconst tenant = loadTreeseedManifest(manifestPath);\n\treturn createTreeseedCollections(tenant, { docsLoader, docsSchema });\n}");
|
|
374
|
-
writeCompatibilityEntrypoint(resolve(distRoot, 'content-config.d.ts'), "export declare function createTreeseedTenantCollections(manifestPath?: string): {\n\tpages: any;\n\tnotes: any;\n\tquestions: any;\n\tobjectives: any;\n\tpeople: any;\n\tagents: any;\n\tbooks: any;\n\tdocs: any;\n};");
|
|
379
|
+
writeCompatibilityEntrypoint(resolve(distRoot, 'content-config.d.ts'), "export declare function createTreeseedTenantCollections(manifestPath?: string): {\n\tpages: any;\n\tnotes: any;\n\tquestions: any;\n\tobjectives: any;\n\tpeople: any;\n\tagents: any;\n\tbooks: any;\n\tdocs: any;\n\tworkdays?: any;\n};");
|
|
375
380
|
rmSync(resolve(distRoot, 'config.d.js'), { force: true });
|
|
376
381
|
rmSync(resolve(distRoot, 'content-config.d.js'), { force: true });
|
|
377
382
|
writeCompatibilityEntrypoint(resolve(vendoredStarlightRoot, 'utils', 'routing.js'), "export * from './routing/index.js';");
|
|
@@ -12,7 +12,13 @@ function readOption(name) {
|
|
|
12
12
|
return args[index + 1];
|
|
13
13
|
}
|
|
14
14
|
function parseSurface(value) {
|
|
15
|
-
if (value === 'web'
|
|
15
|
+
if (value === 'web'
|
|
16
|
+
|| value === 'api'
|
|
17
|
+
|| value === 'manager'
|
|
18
|
+
|| value === 'worker'
|
|
19
|
+
|| value === 'agents'
|
|
20
|
+
|| value === 'services'
|
|
21
|
+
|| value === 'integrated') {
|
|
16
22
|
return value;
|
|
17
23
|
}
|
|
18
24
|
return 'integrated';
|
|
@@ -20,5 +26,7 @@ function parseSurface(value) {
|
|
|
20
26
|
const exitCode = await runTreeseedIntegratedDev({
|
|
21
27
|
surface: parseSurface(readOption('--surface')),
|
|
22
28
|
watch: readFlag('--watch'),
|
|
29
|
+
projectId: readOption('--project-id'),
|
|
30
|
+
teamId: readOption('--team-id'),
|
|
23
31
|
});
|
|
24
32
|
process.exit(exitCode);
|
|
@@ -174,7 +174,6 @@ try {
|
|
|
174
174
|
'await import("@treeseed/core/runtime-types");',
|
|
175
175
|
'await import("@treeseed/core/contracts/messages");',
|
|
176
176
|
'await import("@treeseed/core/contracts/run");',
|
|
177
|
-
'await import("@treeseed/core/services/manager");',
|
|
178
177
|
'await import("@treeseed/core/services/worker");',
|
|
179
178
|
'await import("@treeseed/core/services/workday-start");',
|
|
180
179
|
'await import("@treeseed/core/services/workday-report");',
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export declare function resolveAgentsServiceConfig(): {
|
|
3
|
+
serviceName: string;
|
|
4
|
+
marketBaseUrl: string;
|
|
5
|
+
projectId: string;
|
|
6
|
+
runnerToken: string;
|
|
7
|
+
runnerId: string;
|
|
8
|
+
batchSize: number;
|
|
9
|
+
pollIntervalMs: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function runAgentsCycle(): Promise<{
|
|
12
|
+
ok: boolean;
|
|
13
|
+
processed: number;
|
|
14
|
+
idle: boolean;
|
|
15
|
+
reason: string;
|
|
16
|
+
} | {
|
|
17
|
+
ok: boolean;
|
|
18
|
+
processed: number;
|
|
19
|
+
idle?: undefined;
|
|
20
|
+
reason?: undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function startAgentsLoop(): Promise<void>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { runRemoteRunnerCycle, startRemoteRunnerLoop, resolveRemoteRunnerConfig } from "./remote-runner.js";
|
|
4
|
+
function resolveAgentsServiceConfig() {
|
|
5
|
+
return {
|
|
6
|
+
...resolveRemoteRunnerConfig(),
|
|
7
|
+
serviceName: process.env.TREESEED_AGENTS_SERVICE_NAME?.trim() || "agents"
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
async function runAgentsCycle() {
|
|
11
|
+
return runRemoteRunnerCycle({
|
|
12
|
+
config: resolveAgentsServiceConfig()
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
async function startAgentsLoop() {
|
|
16
|
+
return startRemoteRunnerLoop({
|
|
17
|
+
config: resolveAgentsServiceConfig()
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
21
|
+
const entryFile = process.argv[1] ?? "";
|
|
22
|
+
if (entryFile === currentFile) {
|
|
23
|
+
await startAgentsLoop();
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
resolveAgentsServiceConfig,
|
|
27
|
+
runAgentsCycle,
|
|
28
|
+
startAgentsLoop
|
|
29
|
+
};
|
|
@@ -1,9 +1,43 @@
|
|
|
1
|
-
import { AgentSdk } from '@treeseed/sdk
|
|
2
|
-
import {
|
|
1
|
+
import { AgentSdk } from '@treeseed/sdk';
|
|
2
|
+
import { CloudflareQueuePullClient } from '@treeseed/sdk/remote';
|
|
3
|
+
import type { SdkQueueMessageEnvelope } from '@treeseed/sdk';
|
|
3
4
|
export declare function resolveServiceRepoRoot(): string;
|
|
4
5
|
export declare function createServiceSdk(): AgentSdk;
|
|
5
|
-
export declare function createGatewayClient(): TreeseedGatewayClient;
|
|
6
6
|
export declare function createQueueClient(): CloudflareQueuePullClient;
|
|
7
|
+
export declare function createQueuePushClient(): {
|
|
8
|
+
enqueue(request: {
|
|
9
|
+
message: SdkQueueMessageEnvelope;
|
|
10
|
+
delaySeconds?: number;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export declare function queueEnvelopeForTask(task: Record<string, unknown>): SdkQueueMessageEnvelope;
|
|
14
|
+
export declare function enqueueTaskFromSdk(sdk: AgentSdk, request: {
|
|
15
|
+
taskId: string;
|
|
16
|
+
queueName?: string;
|
|
17
|
+
deliveryDelaySeconds?: number;
|
|
18
|
+
actor?: string;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
ok: boolean;
|
|
21
|
+
taskId: string;
|
|
22
|
+
queued: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function buildTaskContext(sdk: AgentSdk, taskId: string): Promise<{
|
|
25
|
+
agent: Record<string, unknown> | import("@treeseed/sdk").SdkContentEntry;
|
|
26
|
+
task: import("@treeseed/sdk").SdkTaskEntity | null;
|
|
27
|
+
workDay: import("@treeseed/sdk").SdkWorkDayEntity | null;
|
|
28
|
+
graph: Record<string, unknown> | null;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function seedRootTasks(sdk: AgentSdk, workDayId: string): Promise<any[]>;
|
|
31
|
+
export declare function startAndSeedWorkday(sdk: AgentSdk, request: {
|
|
32
|
+
id?: string;
|
|
33
|
+
projectId: string;
|
|
34
|
+
capacityBudget: number;
|
|
35
|
+
actor?: string;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
ok: boolean;
|
|
38
|
+
workDay: import("@treeseed/sdk").SdkWorkDayEntity;
|
|
39
|
+
seededTasks: any[];
|
|
40
|
+
}>;
|
|
7
41
|
export declare function resolveManagerConfig(): {
|
|
8
42
|
host: string;
|
|
9
43
|
port: number;
|
|
@@ -16,5 +50,4 @@ export declare function resolveWorkerConfig(): {
|
|
|
16
50
|
visibilityTimeoutMs: number;
|
|
17
51
|
pollIntervalMs: number;
|
|
18
52
|
leaseSeconds: number;
|
|
19
|
-
managerBaseUrl: string;
|
|
20
53
|
};
|
package/dist/services/common.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { AgentSdk } from "@treeseed/sdk";
|
|
3
|
+
import { CloudflareQueuePullClient } from "@treeseed/sdk/remote";
|
|
3
4
|
function integerFromEnv(name, fallback) {
|
|
4
5
|
const value = process.env[name];
|
|
5
6
|
if (!value) return fallback;
|
|
@@ -16,27 +17,140 @@ function createServiceSdk() {
|
|
|
16
17
|
persistTo: process.env.TREESEED_AGENT_D1_PERSIST_TO ?? void 0
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
const baseUrl = process.env.TREESEED_GATEWAY_BASE_URL?.trim();
|
|
21
|
-
const bearerToken = process.env.TREESEED_GATEWAY_BEARER_TOKEN?.trim();
|
|
22
|
-
if (!baseUrl || !bearerToken) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
return new TreeseedGatewayClient({ baseUrl, bearerToken });
|
|
26
|
-
}
|
|
27
|
-
function createQueueClient() {
|
|
20
|
+
function createQueueClientConfig(token) {
|
|
28
21
|
const accountId = process.env.CLOUDFLARE_ACCOUNT_ID?.trim();
|
|
29
22
|
const queueId = process.env.TREESEED_QUEUE_ID?.trim();
|
|
30
|
-
const token = process.env.TREESEED_QUEUE_PULL_TOKEN?.trim();
|
|
31
23
|
if (!accountId || !queueId || !token) {
|
|
32
24
|
return null;
|
|
33
25
|
}
|
|
34
|
-
return
|
|
26
|
+
return {
|
|
35
27
|
accountId,
|
|
36
28
|
queueId,
|
|
37
29
|
token,
|
|
38
30
|
apiBaseUrl: process.env.TREESEED_QUEUE_API_BASE_URL?.trim() || void 0
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function createQueueClient() {
|
|
34
|
+
const config = createQueueClientConfig(process.env.TREESEED_QUEUE_PULL_TOKEN?.trim() || "");
|
|
35
|
+
if (!config) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return new CloudflareQueuePullClient(config);
|
|
39
|
+
}
|
|
40
|
+
function createQueuePushClient() {
|
|
41
|
+
const config = createQueueClientConfig(
|
|
42
|
+
process.env.TREESEED_QUEUE_PUSH_TOKEN?.trim() || process.env.CLOUDFLARE_API_TOKEN?.trim() || ""
|
|
43
|
+
);
|
|
44
|
+
if (!config) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const apiBaseUrl = config.apiBaseUrl ?? "https://api.cloudflare.com/client/v4/accounts";
|
|
48
|
+
const baseUrl = `${apiBaseUrl.replace(/\/$/u, "")}/${config.accountId}/queues/${config.queueId}`;
|
|
49
|
+
return {
|
|
50
|
+
async enqueue(request) {
|
|
51
|
+
const response = await fetch(`${baseUrl}/messages`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: {
|
|
54
|
+
accept: "application/json",
|
|
55
|
+
authorization: `Bearer ${config.token}`,
|
|
56
|
+
"content-type": "application/json"
|
|
57
|
+
},
|
|
58
|
+
body: JSON.stringify({
|
|
59
|
+
body: request.message,
|
|
60
|
+
content_type: "json",
|
|
61
|
+
delay_seconds: request.delaySeconds ?? 0
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
const payload = await response.json().catch(() => ({}));
|
|
65
|
+
if (!response.ok || payload.success === false) {
|
|
66
|
+
throw new Error(payload.errors?.[0]?.message ?? `Queue request failed with ${response.status}.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function queueEnvelopeForTask(task) {
|
|
72
|
+
return {
|
|
73
|
+
messageId: crypto.randomUUID(),
|
|
74
|
+
taskId: String(task.id ?? ""),
|
|
75
|
+
workDayId: String(task.workDayId ?? task.work_day_id ?? ""),
|
|
76
|
+
agentId: String(task.agentId ?? task.agent_id ?? ""),
|
|
77
|
+
taskType: String(task.type ?? ""),
|
|
78
|
+
idempotencyKey: String(task.idempotencyKey ?? task.idempotency_key ?? ""),
|
|
79
|
+
attempt: Number(task.attemptCount ?? task.attempt_count ?? 0) + 1,
|
|
80
|
+
payloadRef: `d1:tasks/${String(task.id ?? "")}`,
|
|
81
|
+
graphVersion: task.graphVersion !== void 0 && task.graphVersion !== null ? String(task.graphVersion) : task.graph_version !== void 0 && task.graph_version !== null ? String(task.graph_version) : null,
|
|
82
|
+
budgetHint: 1
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async function enqueueTaskFromSdk(sdk, request) {
|
|
86
|
+
const queue = createQueuePushClient();
|
|
87
|
+
if (!queue) {
|
|
88
|
+
throw new Error("Queue push client not configured.");
|
|
89
|
+
}
|
|
90
|
+
const task = await sdk.get({ model: "task", id: request.taskId });
|
|
91
|
+
if (!task.payload) {
|
|
92
|
+
throw new Error("Unknown task.");
|
|
93
|
+
}
|
|
94
|
+
await queue.enqueue({
|
|
95
|
+
message: queueEnvelopeForTask(task.payload),
|
|
96
|
+
delaySeconds: request.deliveryDelaySeconds ?? 0
|
|
97
|
+
});
|
|
98
|
+
await sdk.recordTaskProgress({
|
|
99
|
+
id: request.taskId,
|
|
100
|
+
state: "queued",
|
|
101
|
+
appendEvent: { kind: "queued", data: { queueName: request.queueName ?? null } },
|
|
102
|
+
actor: request.actor
|
|
39
103
|
});
|
|
104
|
+
return { ok: true, taskId: request.taskId, queued: true };
|
|
105
|
+
}
|
|
106
|
+
async function buildTaskContext(sdk, taskId) {
|
|
107
|
+
const context = await sdk.getManagerContext(taskId);
|
|
108
|
+
const task = context.payload.task;
|
|
109
|
+
const agent = task ? (await sdk.get({ model: "agent", slug: String(task.agentId) })).payload : null;
|
|
110
|
+
return {
|
|
111
|
+
...context.payload,
|
|
112
|
+
agent
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function seedRootTasks(sdk, workDayId) {
|
|
116
|
+
const specs = await sdk.listAgentSpecs({ enabled: true });
|
|
117
|
+
const created = [];
|
|
118
|
+
for (const spec of specs) {
|
|
119
|
+
const hasStartTrigger = spec.triggers.some((trigger) => trigger.type === "startup" || trigger.type === "schedule");
|
|
120
|
+
if (!hasStartTrigger) continue;
|
|
121
|
+
created.push(await sdk.createTask({
|
|
122
|
+
workDayId,
|
|
123
|
+
agentId: spec.slug,
|
|
124
|
+
type: "agent_root",
|
|
125
|
+
priority: 100,
|
|
126
|
+
idempotencyKey: `${workDayId}:${spec.slug}:root`,
|
|
127
|
+
payload: {
|
|
128
|
+
agentSlug: spec.slug,
|
|
129
|
+
handler: spec.handler,
|
|
130
|
+
triggerKinds: spec.triggers.map((entry) => entry.type)
|
|
131
|
+
},
|
|
132
|
+
graphVersion: null,
|
|
133
|
+
actor: "manager"
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
return created;
|
|
137
|
+
}
|
|
138
|
+
async function startAndSeedWorkday(sdk, request) {
|
|
139
|
+
const graphRefresh = await sdk.refreshGraph();
|
|
140
|
+
const workDay = await sdk.startWorkDay({
|
|
141
|
+
id: request.id,
|
|
142
|
+
projectId: request.projectId,
|
|
143
|
+
capacityBudget: request.capacityBudget,
|
|
144
|
+
graphVersion: graphRefresh.snapshotRoot,
|
|
145
|
+
summary: { graphRefresh },
|
|
146
|
+
actor: request.actor ?? "manager"
|
|
147
|
+
});
|
|
148
|
+
const tasks = workDay.payload ? await seedRootTasks(sdk, String(workDay.payload.id)) : [];
|
|
149
|
+
return {
|
|
150
|
+
ok: true,
|
|
151
|
+
workDay: workDay.payload,
|
|
152
|
+
seededTasks: tasks.map((entry) => entry.payload).filter(Boolean)
|
|
153
|
+
};
|
|
40
154
|
}
|
|
41
155
|
function resolveManagerConfig() {
|
|
42
156
|
return {
|
|
@@ -52,15 +166,19 @@ function resolveWorkerConfig() {
|
|
|
52
166
|
batchSize: integerFromEnv("TREESEED_QUEUE_BATCH_SIZE", 1),
|
|
53
167
|
visibilityTimeoutMs: integerFromEnv("TREESEED_QUEUE_VISIBILITY_TIMEOUT_MS", 12e4),
|
|
54
168
|
pollIntervalMs: integerFromEnv("TREESEED_WORKER_POLL_INTERVAL_MS", 5e3),
|
|
55
|
-
leaseSeconds: integerFromEnv("TREESEED_TASK_LEASE_SECONDS", 120)
|
|
56
|
-
managerBaseUrl: process.env.TREESEED_MANAGER_BASE_URL?.trim() || `http://${process.env.TREESEED_MANAGER_HOST?.trim() || "manager.railway.internal"}:${integerFromEnv("TREESEED_MANAGER_PORT", 3100)}`
|
|
169
|
+
leaseSeconds: integerFromEnv("TREESEED_TASK_LEASE_SECONDS", 120)
|
|
57
170
|
};
|
|
58
171
|
}
|
|
59
172
|
export {
|
|
60
|
-
|
|
173
|
+
buildTaskContext,
|
|
61
174
|
createQueueClient,
|
|
175
|
+
createQueuePushClient,
|
|
62
176
|
createServiceSdk,
|
|
177
|
+
enqueueTaskFromSdk,
|
|
178
|
+
queueEnvelopeForTask,
|
|
63
179
|
resolveManagerConfig,
|
|
64
180
|
resolveServiceRepoRoot,
|
|
65
|
-
resolveWorkerConfig
|
|
181
|
+
resolveWorkerConfig,
|
|
182
|
+
seedRootTasks,
|
|
183
|
+
startAndSeedWorkday
|
|
66
184
|
};
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { runManagerAction, runManagerCycle, startManagerLoop } from './manager.ts';
|
|
2
2
|
export { runWorkerCycle, startWorkerLoop } from './worker.ts';
|
|
3
|
+
export { runRemoteRunnerCycle, startRemoteRunnerLoop } from './remote-runner.ts';
|
|
4
|
+
export { runAgentsCycle, startAgentsLoop } from './agents.ts';
|
|
3
5
|
export { runWorkdayStart } from './workday-start.ts';
|
|
4
6
|
export { runWorkdayReport } from './workday-report.ts';
|
|
7
|
+
export { createWorkerPoolScaler, RailwayWorkerPoolScaler, NoopWorkerPoolScaler } from './worker-pool-scaler.ts';
|
package/dist/services/index.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runManagerAction, runManagerCycle, startManagerLoop } from "./manager.js";
|
|
2
2
|
import { runWorkerCycle, startWorkerLoop } from "./worker.js";
|
|
3
|
+
import { runRemoteRunnerCycle, startRemoteRunnerLoop } from "./remote-runner.js";
|
|
4
|
+
import { runAgentsCycle, startAgentsLoop } from "./agents.js";
|
|
3
5
|
import { runWorkdayStart } from "./workday-start.js";
|
|
4
6
|
import { runWorkdayReport } from "./workday-report.js";
|
|
7
|
+
import { createWorkerPoolScaler, RailwayWorkerPoolScaler, NoopWorkerPoolScaler } from "./worker-pool-scaler.js";
|
|
5
8
|
export {
|
|
6
|
-
|
|
9
|
+
NoopWorkerPoolScaler,
|
|
10
|
+
RailwayWorkerPoolScaler,
|
|
11
|
+
createWorkerPoolScaler,
|
|
12
|
+
runAgentsCycle,
|
|
13
|
+
runManagerAction,
|
|
14
|
+
runManagerCycle,
|
|
15
|
+
runRemoteRunnerCycle,
|
|
7
16
|
runWorkdayReport,
|
|
8
17
|
runWorkdayStart,
|
|
9
18
|
runWorkerCycle,
|
|
19
|
+
startAgentsLoop,
|
|
20
|
+
startManagerLoop,
|
|
21
|
+
startRemoteRunnerLoop,
|
|
10
22
|
startWorkerLoop
|
|
11
23
|
};
|