@treeseed/core 0.4.8 → 0.4.10
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/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/dev.js +24 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -2
- package/dist/scripts/aggregate-book.js +13 -108
- package/dist/scripts/test-smoke.js +80 -24
- package/dist/services/common.d.ts +37 -4
- package/dist/services/common.js +135 -17
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +3 -2
- package/dist/services/remote-runner.d.ts +23 -0
- package/dist/services/remote-runner.js +105 -0
- package/dist/services/workday-report.js +13 -17
- package/dist/services/workday-start.d.ts +5 -1
- package/dist/services/workday-start.js +7 -13
- package/dist/services/worker.js +38 -57
- package/package.json +7 -11
- package/dist/api/gateway.d.ts +0 -5
- package/dist/api/gateway.js +0 -35
- package/dist/services/manager.d.ts +0 -4
- package/dist/services/manager.js +0 -199
package/dist/api/gateway.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Hono } from "hono";
|
|
2
|
-
import { AgentSdk } from "@treeseed/sdk";
|
|
3
|
-
import { registerAgentRoutes } from "./agent-routes.js";
|
|
4
|
-
import { bearerTokenFromRequest, jsonError } from "./http.js";
|
|
5
|
-
function createTreeseedGatewayApp(options) {
|
|
6
|
-
const sdk = options.sdk instanceof AgentSdk ? options.sdk : new AgentSdk();
|
|
7
|
-
const app = new Hono();
|
|
8
|
-
app.use("*", async (c, next) => {
|
|
9
|
-
const token = bearerTokenFromRequest(c.req.raw);
|
|
10
|
-
if (token !== options.bearerToken) {
|
|
11
|
-
return jsonError(c, 401, "Unauthorized gateway request.");
|
|
12
|
-
}
|
|
13
|
-
c.set("requestId", "gateway");
|
|
14
|
-
c.set("config", null);
|
|
15
|
-
c.set("principal", null);
|
|
16
|
-
c.set("actingUser", null);
|
|
17
|
-
c.set("credential", null);
|
|
18
|
-
c.set("actorType", "service");
|
|
19
|
-
c.set("permissionGrants", []);
|
|
20
|
-
await next();
|
|
21
|
-
});
|
|
22
|
-
app.get("/healthz", (c) => c.json({ ok: true, service: "treeseed-agent-gateway" }));
|
|
23
|
-
registerAgentRoutes(app, {
|
|
24
|
-
sdk,
|
|
25
|
-
prefix: "",
|
|
26
|
-
scope: null,
|
|
27
|
-
projectId: options.projectId,
|
|
28
|
-
queueProducer: options.queueProducer,
|
|
29
|
-
defaultActor: "gateway"
|
|
30
|
-
});
|
|
31
|
-
return app;
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
createTreeseedGatewayApp
|
|
35
|
-
};
|
package/dist/services/manager.js
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { createServer } from "node:http";
|
|
3
|
-
import { Readable } from "node:stream";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { Hono } from "hono";
|
|
6
|
-
import { AgentSdk } from "@treeseed/sdk/sdk";
|
|
7
|
-
import { createServiceSdk, resolveManagerConfig } from "./common.js";
|
|
8
|
-
async function honoNodeHandler(app, request, response) {
|
|
9
|
-
const origin = request.headers.host ? `http://${request.headers.host}` : "http://127.0.0.1";
|
|
10
|
-
const url = new URL(request.url ?? "/", origin);
|
|
11
|
-
const webRequest = new Request(url, {
|
|
12
|
-
method: request.method,
|
|
13
|
-
headers: request.headers,
|
|
14
|
-
body: request.method !== "GET" && request.method !== "HEAD" ? request : void 0,
|
|
15
|
-
duplex: "half"
|
|
16
|
-
});
|
|
17
|
-
const webResponse = await app.fetch(webRequest);
|
|
18
|
-
response.statusCode = webResponse.status;
|
|
19
|
-
webResponse.headers.forEach((value, key) => response.setHeader(key, value));
|
|
20
|
-
if (!webResponse.body) {
|
|
21
|
-
response.end();
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
Readable.fromWeb(webResponse.body).pipe(response);
|
|
25
|
-
}
|
|
26
|
-
async function seedRootTasks(sdk, workDayId) {
|
|
27
|
-
const specs = await sdk.listAgentSpecs({ enabled: true });
|
|
28
|
-
const created = [];
|
|
29
|
-
for (const spec of specs) {
|
|
30
|
-
const hasStartTrigger = spec.triggers.some((trigger) => trigger.type === "startup" || trigger.type === "schedule");
|
|
31
|
-
if (!hasStartTrigger) continue;
|
|
32
|
-
created.push(await sdk.createTask({
|
|
33
|
-
workDayId,
|
|
34
|
-
agentId: spec.slug,
|
|
35
|
-
type: "agent_root",
|
|
36
|
-
priority: 100,
|
|
37
|
-
idempotencyKey: `${workDayId}:${spec.slug}:root`,
|
|
38
|
-
payload: {
|
|
39
|
-
agentSlug: spec.slug,
|
|
40
|
-
handler: spec.handler,
|
|
41
|
-
triggerKinds: spec.triggers.map((entry) => entry.type)
|
|
42
|
-
},
|
|
43
|
-
graphVersion: null,
|
|
44
|
-
actor: "manager"
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
return created;
|
|
48
|
-
}
|
|
49
|
-
function createManagerApp(sdk = createServiceSdk()) {
|
|
50
|
-
const config = resolveManagerConfig();
|
|
51
|
-
const app = new Hono();
|
|
52
|
-
app.get("/internal/healthz", (c) => c.json({ ok: true, service: "manager" }));
|
|
53
|
-
app.post("/internal/workdays/start", async (c) => {
|
|
54
|
-
const body = await c.req.json().catch(() => ({}));
|
|
55
|
-
const graphRefresh = await sdk.refreshGraph();
|
|
56
|
-
const workDay = await sdk.startWorkDay({
|
|
57
|
-
id: typeof body.id === "string" ? body.id : void 0,
|
|
58
|
-
projectId: config.projectId,
|
|
59
|
-
capacityBudget: Number(body.capacityBudget ?? config.defaultCapacityBudget),
|
|
60
|
-
graphVersion: graphRefresh.snapshotRoot,
|
|
61
|
-
summary: { graphRefresh },
|
|
62
|
-
actor: "manager"
|
|
63
|
-
});
|
|
64
|
-
const tasks = workDay.payload ? await seedRootTasks(sdk, String(workDay.payload.id)) : [];
|
|
65
|
-
return c.json({
|
|
66
|
-
ok: true,
|
|
67
|
-
workDay: workDay.payload,
|
|
68
|
-
seededTasks: tasks.map((entry) => entry.payload).filter(Boolean)
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
app.post("/internal/workdays/:id/close", async (c) => {
|
|
72
|
-
const body = await c.req.json().catch(() => ({}));
|
|
73
|
-
const result = await sdk.closeWorkDay({
|
|
74
|
-
id: c.req.param("id"),
|
|
75
|
-
state: body.state,
|
|
76
|
-
summary: body.summary ?? null,
|
|
77
|
-
actor: "manager"
|
|
78
|
-
});
|
|
79
|
-
return c.json({ ok: true, payload: result.payload });
|
|
80
|
-
});
|
|
81
|
-
app.post("/internal/context/resolve-task", async (c) => {
|
|
82
|
-
const body = await c.req.json().catch(() => ({}));
|
|
83
|
-
const taskId = String(body.taskId ?? "");
|
|
84
|
-
const context = await sdk.getManagerContext(taskId);
|
|
85
|
-
const task = context.payload.task;
|
|
86
|
-
const agent = task ? (await sdk.get({ model: "agent", slug: String(task.agentId) })).payload : null;
|
|
87
|
-
return c.json({
|
|
88
|
-
ok: true,
|
|
89
|
-
payload: {
|
|
90
|
-
...context.payload,
|
|
91
|
-
agent
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
app.post("/internal/graph/search", async (c) => {
|
|
96
|
-
const body = await c.req.json().catch(() => ({}));
|
|
97
|
-
const query = String(body.query ?? "");
|
|
98
|
-
const scope = String(body.scope ?? "sections");
|
|
99
|
-
const payload = scope === "files" ? await sdk.searchFiles(query, body.options) : scope === "entities" ? await sdk.searchEntities(query, body.options) : await sdk.searchSections(query, body.options);
|
|
100
|
-
return c.json({ ok: true, payload });
|
|
101
|
-
});
|
|
102
|
-
app.post("/internal/graph/subgraph", async (c) => {
|
|
103
|
-
const body = await c.req.json().catch(() => ({}));
|
|
104
|
-
const payload = await sdk.getSubgraph(
|
|
105
|
-
Array.isArray(body.seedIds) ? body.seedIds.map(String) : [],
|
|
106
|
-
body.options
|
|
107
|
-
);
|
|
108
|
-
return c.json({ ok: true, payload });
|
|
109
|
-
});
|
|
110
|
-
app.post("/internal/graph/query", async (c) => {
|
|
111
|
-
const body = await c.req.json().catch(() => ({}));
|
|
112
|
-
const payload = await sdk.queryGraph(body);
|
|
113
|
-
if (typeof body.workDayId === "string" && body.workDayId) {
|
|
114
|
-
await sdk.create({
|
|
115
|
-
model: "graph_run",
|
|
116
|
-
data: {
|
|
117
|
-
workDayId: body.workDayId,
|
|
118
|
-
corpusHash: String(body.corpusHash ?? "query-graph"),
|
|
119
|
-
graphVersion: String(body.graphVersion ?? ""),
|
|
120
|
-
queryJson: JSON.stringify(body ?? {}),
|
|
121
|
-
seedIdsJson: JSON.stringify(payload.seedIds),
|
|
122
|
-
selectedNodeIdsJson: JSON.stringify(payload.nodes.map((entry) => entry.node.id)),
|
|
123
|
-
statsJson: JSON.stringify({ nodeCount: payload.nodes.length, edgeCount: payload.edges.length })
|
|
124
|
-
},
|
|
125
|
-
actor: "manager"
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return c.json({ ok: true, payload });
|
|
129
|
-
});
|
|
130
|
-
app.post("/internal/graph/context-pack", async (c) => {
|
|
131
|
-
const body = await c.req.json().catch(() => ({}));
|
|
132
|
-
const payload = await sdk.buildContextPack(body);
|
|
133
|
-
if (typeof body.workDayId === "string" && body.workDayId) {
|
|
134
|
-
await sdk.create({
|
|
135
|
-
model: "graph_run",
|
|
136
|
-
data: {
|
|
137
|
-
workDayId: body.workDayId,
|
|
138
|
-
corpusHash: String(body.corpusHash ?? "context-pack"),
|
|
139
|
-
graphVersion: String(body.graphVersion ?? ""),
|
|
140
|
-
queryJson: JSON.stringify(body ?? {}),
|
|
141
|
-
seedIdsJson: JSON.stringify(payload.seedIds),
|
|
142
|
-
selectedNodeIdsJson: JSON.stringify(payload.includedNodeIds),
|
|
143
|
-
statsJson: JSON.stringify({ nodeCount: payload.nodes.length, edgeCount: payload.edges.length, totalTokenEstimate: payload.totalTokenEstimate })
|
|
144
|
-
},
|
|
145
|
-
actor: "manager"
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
return c.json({ ok: true, payload });
|
|
149
|
-
});
|
|
150
|
-
app.post("/internal/graph/parse-dsl", async (c) => {
|
|
151
|
-
const body = await c.req.json().catch(() => ({}));
|
|
152
|
-
const payload = await sdk.parseGraphDsl(String(body.source ?? body.query ?? ""));
|
|
153
|
-
return c.json({ ok: true, payload });
|
|
154
|
-
});
|
|
155
|
-
app.get("/internal/graph/node/:id", async (c) => {
|
|
156
|
-
const payload = await sdk.getGraphNode(c.req.param("id"));
|
|
157
|
-
return payload ? c.json({ ok: true, payload }) : c.json({ ok: false, error: "Unknown graph node." }, 404);
|
|
158
|
-
});
|
|
159
|
-
app.post("/internal/tasks/:id/followups", async (c) => {
|
|
160
|
-
const body = await c.req.json().catch(() => ({}));
|
|
161
|
-
const current = await sdk.get({ model: "task", id: c.req.param("id") });
|
|
162
|
-
if (!current.payload) {
|
|
163
|
-
return c.json({ ok: false, error: "Unknown task." }, 404);
|
|
164
|
-
}
|
|
165
|
-
const followups = Array.isArray(body.followups) ? body.followups : [];
|
|
166
|
-
const created = [];
|
|
167
|
-
for (const followup of followups) {
|
|
168
|
-
created.push(await sdk.createTask({
|
|
169
|
-
workDayId: String(current.payload.workDayId ?? ""),
|
|
170
|
-
agentId: String(followup.agentId ?? current.payload.agentId ?? ""),
|
|
171
|
-
type: String(followup.type ?? "followup"),
|
|
172
|
-
priority: Number(followup.priority ?? 0),
|
|
173
|
-
idempotencyKey: String(followup.idempotencyKey ?? `${c.req.param("id")}:${created.length}`),
|
|
174
|
-
payload: followup.payload ?? {},
|
|
175
|
-
graphVersion: typeof followup.graphVersion === "string" ? followup.graphVersion : null,
|
|
176
|
-
parentTaskId: c.req.param("id"),
|
|
177
|
-
actor: "manager"
|
|
178
|
-
}));
|
|
179
|
-
}
|
|
180
|
-
return c.json({ ok: true, payload: created.map((entry) => entry.payload) });
|
|
181
|
-
});
|
|
182
|
-
return app;
|
|
183
|
-
}
|
|
184
|
-
const currentFile = fileURLToPath(import.meta.url);
|
|
185
|
-
const entryFile = process.argv[1] ?? "";
|
|
186
|
-
if (entryFile === currentFile) {
|
|
187
|
-
const config = resolveManagerConfig();
|
|
188
|
-
const app = createManagerApp();
|
|
189
|
-
const server = createServer((req, res) => {
|
|
190
|
-
void honoNodeHandler(app, req, res);
|
|
191
|
-
});
|
|
192
|
-
server.listen(config.port, config.host, () => {
|
|
193
|
-
process.stdout.write(`Treeseed manager listening on http://${config.host}:${config.port}
|
|
194
|
-
`);
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
export {
|
|
198
|
-
createManagerApp
|
|
199
|
-
};
|