@treeseed/agent 0.8.5
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/Dockerfile +7 -0
- package/README.md +198 -0
- package/dist/agent-runtime.d.ts +17 -0
- package/dist/agent-runtime.js +117 -0
- package/dist/agents/adapters/execution.d.ts +41 -0
- package/dist/agents/adapters/execution.js +73 -0
- package/dist/agents/adapters/mutations.d.ts +22 -0
- package/dist/agents/adapters/mutations.js +30 -0
- package/dist/agents/adapters/notification.d.ts +26 -0
- package/dist/agents/adapters/notification.js +46 -0
- package/dist/agents/adapters/repository.d.ts +28 -0
- package/dist/agents/adapters/repository.js +61 -0
- package/dist/agents/adapters/research.d.ts +26 -0
- package/dist/agents/adapters/research.js +59 -0
- package/dist/agents/adapters/verification.d.ts +36 -0
- package/dist/agents/adapters/verification.js +62 -0
- package/dist/agents/cli-tools.d.ts +1 -0
- package/dist/agents/cli-tools.js +5 -0
- package/dist/agents/cli.d.ts +15 -0
- package/dist/agents/cli.js +109 -0
- package/dist/agents/contracts/messages.d.ts +88 -0
- package/dist/agents/contracts/messages.js +138 -0
- package/dist/agents/contracts/run.d.ts +21 -0
- package/dist/agents/contracts/run.js +0 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.js +5 -0
- package/dist/agents/kernel/agent-kernel.d.ts +63 -0
- package/dist/agents/kernel/agent-kernel.js +291 -0
- package/dist/agents/kernel/trigger-resolver.d.ts +19 -0
- package/dist/agents/kernel/trigger-resolver.js +157 -0
- package/dist/agents/registry-helper.d.ts +4 -0
- package/dist/agents/registry-helper.js +14 -0
- package/dist/agents/registry.d.ts +6 -0
- package/dist/agents/registry.js +98 -0
- package/dist/agents/runtime-types.d.ts +118 -0
- package/dist/agents/runtime-types.js +0 -0
- package/dist/agents/spec-loader.d.ts +18 -0
- package/dist/agents/spec-loader.js +54 -0
- package/dist/agents/spec-normalizer.d.ts +2 -0
- package/dist/agents/spec-normalizer.js +327 -0
- package/dist/agents/spec-types.d.ts +64 -0
- package/dist/agents/spec-types.js +0 -0
- package/dist/agents/testing/agents-smoke.d.ts +1 -0
- package/dist/agents/testing/agents-smoke.js +32 -0
- package/dist/agents/testing/e2e-harness.d.ts +44 -0
- package/dist/agents/testing/e2e-harness.js +503 -0
- package/dist/api/agent-routes.d.ts +13 -0
- package/dist/api/agent-routes.js +327 -0
- package/dist/api/app.d.ts +8 -0
- package/dist/api/app.js +444 -0
- package/dist/api/auth/d1-database.d.ts +3 -0
- package/dist/api/auth/d1-database.js +20 -0
- package/dist/api/auth/d1-provider.d.ts +79 -0
- package/dist/api/auth/d1-provider.js +92 -0
- package/dist/api/auth/d1-store.d.ts +114 -0
- package/dist/api/auth/d1-store.js +895 -0
- package/dist/api/auth/memory-provider.d.ts +77 -0
- package/dist/api/auth/memory-provider.js +249 -0
- package/dist/api/auth/rbac.d.ts +22 -0
- package/dist/api/auth/rbac.js +162 -0
- package/dist/api/auth/tokens.d.ts +18 -0
- package/dist/api/auth/tokens.js +56 -0
- package/dist/api/capabilities.d.ts +9 -0
- package/dist/api/capabilities.js +33 -0
- package/dist/api/config.d.ts +2 -0
- package/dist/api/config.js +77 -0
- package/dist/api/http.d.ts +28 -0
- package/dist/api/http.js +51 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/index.js +20 -0
- package/dist/api/operations-routes.d.ts +11 -0
- package/dist/api/operations-routes.js +87 -0
- package/dist/api/operations.d.ts +3 -0
- package/dist/api/operations.js +26 -0
- package/dist/api/project-routes.d.ts +8 -0
- package/dist/api/project-routes.js +585 -0
- package/dist/api/providers.d.ts +2 -0
- package/dist/api/providers.js +62 -0
- package/dist/api/railway.d.ts +51 -0
- package/dist/api/railway.js +71 -0
- package/dist/api/sdk-dispatch.d.ts +5 -0
- package/dist/api/sdk-dispatch.js +13 -0
- package/dist/api/sdk-routes.d.ts +11 -0
- package/dist/api/sdk-routes.js +29 -0
- package/dist/api/server.d.ts +2 -0
- package/dist/api/server.js +10 -0
- package/dist/api/templates.d.ts +3 -0
- package/dist/api/templates.js +31 -0
- package/dist/api/types.d.ts +237 -0
- package/dist/api/types.js +0 -0
- package/dist/env.yaml +957 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +41 -0
- package/dist/scripts/assert-release-tag-version.d.ts +1 -0
- package/dist/scripts/assert-release-tag-version.js +20 -0
- package/dist/scripts/build-dist.d.ts +1 -0
- package/dist/scripts/build-dist.js +106 -0
- package/dist/scripts/package-tools.d.ts +1 -0
- package/dist/scripts/package-tools.js +7 -0
- package/dist/scripts/publish-package.d.ts +1 -0
- package/dist/scripts/publish-package.js +24 -0
- package/dist/scripts/release-verify.d.ts +1 -0
- package/dist/scripts/release-verify.js +152 -0
- package/dist/scripts/test-smoke.d.ts +1 -0
- package/dist/scripts/test-smoke.js +23 -0
- package/dist/scripts/treeseed-agent-api.d.ts +2 -0
- package/dist/scripts/treeseed-agent-api.js +25 -0
- package/dist/scripts/treeseed-agent-service.d.ts +2 -0
- package/dist/scripts/treeseed-agent-service.js +36 -0
- package/dist/scripts/treeseed-agents.d.ts +2 -0
- package/dist/scripts/treeseed-agents.js +13 -0
- package/dist/services/agents.d.ts +17 -0
- package/dist/services/agents.js +48 -0
- package/dist/services/common.d.ts +66 -0
- package/dist/services/common.js +212 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.js +19 -0
- package/dist/services/manager.d.ts +333 -0
- package/dist/services/manager.js +1368 -0
- package/dist/services/remote-runner.d.ts +30 -0
- package/dist/services/remote-runner.js +230 -0
- package/dist/services/workday-content.d.ts +53 -0
- package/dist/services/workday-content.js +190 -0
- package/dist/services/workday-manager.d.ts +391 -0
- package/dist/services/workday-manager.js +163 -0
- package/dist/services/workday-report.d.ts +238 -0
- package/dist/services/workday-report.js +17 -0
- package/dist/services/workday-start.d.ts +238 -0
- package/dist/services/workday-start.js +17 -0
- package/dist/services/worker-capacity.d.ts +58 -0
- package/dist/services/worker-capacity.js +208 -0
- package/dist/services/worker-pool-scaler.d.ts +27 -0
- package/dist/services/worker-pool-scaler.js +127 -0
- package/dist/services/worker.d.ts +19 -0
- package/dist/services/worker.js +436 -0
- package/dist/templates/github/deploy-processing.workflow.yml +119 -0
- package/package.json +136 -0
- package/templates/github/deploy-processing.workflow.yml +119 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { listRegisteredAgentHandlers as listCoreRegisteredAgentHandlers } from "../agents/registry.js";
|
|
2
|
+
import { buildTaskContext, enqueueTaskFromSdk } from "../services/common.js";
|
|
3
|
+
import { jsonError, requireScope } from "./http.js";
|
|
4
|
+
async function listRegisteredHandlers() {
|
|
5
|
+
return listCoreRegisteredAgentHandlers();
|
|
6
|
+
}
|
|
7
|
+
async function safeListRegisteredHandlers() {
|
|
8
|
+
try {
|
|
9
|
+
return {
|
|
10
|
+
handlers: await listRegisteredHandlers(),
|
|
11
|
+
error: null
|
|
12
|
+
};
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return {
|
|
15
|
+
handlers: [],
|
|
16
|
+
error: error instanceof Error ? error.message : String(error)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function withPrefix(prefix, path) {
|
|
21
|
+
return `${prefix}${path}`.replace(/\/{2,}/g, "/");
|
|
22
|
+
}
|
|
23
|
+
function actor(body, fallback) {
|
|
24
|
+
return String(body.actor ?? fallback);
|
|
25
|
+
}
|
|
26
|
+
function authorizeRequest(c, options) {
|
|
27
|
+
const routeUnauthorized = options.authorize?.(c);
|
|
28
|
+
if (routeUnauthorized) {
|
|
29
|
+
return routeUnauthorized;
|
|
30
|
+
}
|
|
31
|
+
if (options.scope) {
|
|
32
|
+
return requireScope(c, options.scope);
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function registerAgentRoutes(app, options) {
|
|
37
|
+
const prefix = options.prefix ?? "/agent";
|
|
38
|
+
const defaultActor = options.defaultActor ?? "api";
|
|
39
|
+
app.get(withPrefix(prefix, "/healthz"), async (c) => {
|
|
40
|
+
const registration = await safeListRegisteredHandlers();
|
|
41
|
+
return c.json({
|
|
42
|
+
ok: true,
|
|
43
|
+
service: "treeseed-agent-api",
|
|
44
|
+
handlerCount: registration.handlers.length,
|
|
45
|
+
registrationError: registration.error
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
app.get(withPrefix(prefix, "/specs"), async (c) => {
|
|
49
|
+
const unauthorized = authorizeRequest(c, options);
|
|
50
|
+
if (unauthorized) return unauthorized;
|
|
51
|
+
const payload = await options.sdk.listAgentSpecs({ enabled: true });
|
|
52
|
+
return c.json({
|
|
53
|
+
ok: true,
|
|
54
|
+
payload,
|
|
55
|
+
handlers: await listRegisteredHandlers()
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
app.post(withPrefix(prefix, "/workdays/start"), async (c) => {
|
|
59
|
+
const unauthorized = authorizeRequest(c, options);
|
|
60
|
+
if (unauthorized) return unauthorized;
|
|
61
|
+
return jsonError(c, 410, "Starting workdays through /agent/workdays/start is deprecated. Use project workday policy and workday requests instead.");
|
|
62
|
+
});
|
|
63
|
+
app.post(withPrefix(prefix, "/workdays/:id/close"), async (c) => {
|
|
64
|
+
const unauthorized = authorizeRequest(c, options);
|
|
65
|
+
if (unauthorized) return unauthorized;
|
|
66
|
+
const body = await c.req.json().catch(() => ({}));
|
|
67
|
+
const result = await options.sdk.closeWorkDay({
|
|
68
|
+
id: c.req.param("id"),
|
|
69
|
+
state: body.state,
|
|
70
|
+
summary: body.summary ?? null,
|
|
71
|
+
actor: actor(body, defaultActor)
|
|
72
|
+
});
|
|
73
|
+
return result.payload ? c.json(result) : jsonError(c, 404, "Unknown work day.");
|
|
74
|
+
});
|
|
75
|
+
app.post(withPrefix(prefix, "/tasks"), async (c) => {
|
|
76
|
+
const unauthorized = authorizeRequest(c, options);
|
|
77
|
+
if (unauthorized) return unauthorized;
|
|
78
|
+
const body = await c.req.json().catch(() => ({}));
|
|
79
|
+
const result = await options.sdk.createTask({
|
|
80
|
+
id: typeof body.id === "string" ? body.id : void 0,
|
|
81
|
+
workDayId: String(body.workDayId ?? ""),
|
|
82
|
+
agentId: String(body.agentId ?? ""),
|
|
83
|
+
type: String(body.type ?? ""),
|
|
84
|
+
state: typeof body.state === "string" ? body.state : "pending",
|
|
85
|
+
priority: body.priority === void 0 ? void 0 : Number(body.priority),
|
|
86
|
+
idempotencyKey: String(body.idempotencyKey ?? ""),
|
|
87
|
+
payload: body.payload ?? {},
|
|
88
|
+
payloadHash: typeof body.payloadHash === "string" ? body.payloadHash : null,
|
|
89
|
+
maxAttempts: body.maxAttempts === void 0 ? void 0 : Number(body.maxAttempts),
|
|
90
|
+
availableAt: typeof body.availableAt === "string" ? body.availableAt : void 0,
|
|
91
|
+
graphVersion: typeof body.graphVersion === "string" ? body.graphVersion : null,
|
|
92
|
+
parentTaskId: typeof body.parentTaskId === "string" ? body.parentTaskId : null,
|
|
93
|
+
actor: actor(body, defaultActor)
|
|
94
|
+
});
|
|
95
|
+
return c.json(result);
|
|
96
|
+
});
|
|
97
|
+
app.post(withPrefix(prefix, "/tasks/search"), async (c) => {
|
|
98
|
+
const unauthorized = authorizeRequest(c, options);
|
|
99
|
+
if (unauthorized) return unauthorized;
|
|
100
|
+
const body = await c.req.json().catch(() => ({}));
|
|
101
|
+
const result = await options.sdk.searchTasks({
|
|
102
|
+
workDayId: typeof body.workDayId === "string" ? body.workDayId : void 0,
|
|
103
|
+
agentId: typeof body.agentId === "string" ? body.agentId : void 0,
|
|
104
|
+
state: Array.isArray(body.state) || typeof body.state === "string" ? body.state : void 0,
|
|
105
|
+
limit: body.limit === void 0 ? void 0 : Number(body.limit)
|
|
106
|
+
});
|
|
107
|
+
return c.json(result);
|
|
108
|
+
});
|
|
109
|
+
app.post(withPrefix(prefix, "/tasks/:id/claim"), async (c) => {
|
|
110
|
+
const unauthorized = authorizeRequest(c, options);
|
|
111
|
+
if (unauthorized) return unauthorized;
|
|
112
|
+
const body = await c.req.json().catch(() => ({}));
|
|
113
|
+
const result = await options.sdk.claimTask({
|
|
114
|
+
id: c.req.param("id"),
|
|
115
|
+
workerId: String(body.workerId ?? "worker"),
|
|
116
|
+
leaseSeconds: Number(body.leaseSeconds ?? 120),
|
|
117
|
+
actor: actor(body, defaultActor)
|
|
118
|
+
});
|
|
119
|
+
return result.payload ? c.json(result) : jsonError(c, 404, "Unknown task.");
|
|
120
|
+
});
|
|
121
|
+
app.post(withPrefix(prefix, "/tasks/:id/progress"), async (c) => {
|
|
122
|
+
const unauthorized = authorizeRequest(c, options);
|
|
123
|
+
if (unauthorized) return unauthorized;
|
|
124
|
+
const body = await c.req.json().catch(() => ({}));
|
|
125
|
+
const result = await options.sdk.recordTaskProgress({
|
|
126
|
+
id: c.req.param("id"),
|
|
127
|
+
workerId: typeof body.workerId === "string" ? body.workerId : null,
|
|
128
|
+
state: typeof body.state === "string" ? body.state : void 0,
|
|
129
|
+
appendEvent: body.appendEvent,
|
|
130
|
+
patch: body.patch,
|
|
131
|
+
actor: actor(body, defaultActor)
|
|
132
|
+
});
|
|
133
|
+
return result.payload ? c.json(result) : jsonError(c, 404, "Unknown task.");
|
|
134
|
+
});
|
|
135
|
+
app.post(withPrefix(prefix, "/tasks/:id/complete"), async (c) => {
|
|
136
|
+
const unauthorized = authorizeRequest(c, options);
|
|
137
|
+
if (unauthorized) return unauthorized;
|
|
138
|
+
const body = await c.req.json().catch(() => ({}));
|
|
139
|
+
const result = await options.sdk.completeTask({
|
|
140
|
+
id: c.req.param("id"),
|
|
141
|
+
output: body.output ?? null,
|
|
142
|
+
outputRef: typeof body.outputRef === "string" ? body.outputRef : null,
|
|
143
|
+
summary: body.summary ?? null,
|
|
144
|
+
actor: actor(body, defaultActor)
|
|
145
|
+
});
|
|
146
|
+
return result.payload ? c.json(result) : jsonError(c, 404, "Unknown task.");
|
|
147
|
+
});
|
|
148
|
+
app.post(withPrefix(prefix, "/tasks/:id/fail"), async (c) => {
|
|
149
|
+
const unauthorized = authorizeRequest(c, options);
|
|
150
|
+
if (unauthorized) return unauthorized;
|
|
151
|
+
const body = await c.req.json().catch(() => ({}));
|
|
152
|
+
const result = await options.sdk.failTask({
|
|
153
|
+
id: c.req.param("id"),
|
|
154
|
+
errorCode: typeof body.errorCode === "string" ? body.errorCode : null,
|
|
155
|
+
errorMessage: String(body.errorMessage ?? "Task failed"),
|
|
156
|
+
retryable: Boolean(body.retryable),
|
|
157
|
+
nextVisibleAt: typeof body.nextVisibleAt === "string" ? body.nextVisibleAt : null,
|
|
158
|
+
actor: actor(body, defaultActor)
|
|
159
|
+
});
|
|
160
|
+
return result.payload ? c.json(result) : jsonError(c, 404, "Unknown task.");
|
|
161
|
+
});
|
|
162
|
+
app.post(withPrefix(prefix, "/tasks/:id/requeue"), async (c) => {
|
|
163
|
+
const unauthorized = authorizeRequest(c, options);
|
|
164
|
+
if (unauthorized) return unauthorized;
|
|
165
|
+
const body = await c.req.json().catch(() => ({}));
|
|
166
|
+
try {
|
|
167
|
+
return c.json(await enqueueTaskFromSdk(options.sdk, {
|
|
168
|
+
taskId: c.req.param("id"),
|
|
169
|
+
queueName: typeof body.queueName === "string" ? body.queueName : void 0,
|
|
170
|
+
deliveryDelaySeconds: body.delaySeconds === void 0 ? void 0 : Number(body.delaySeconds),
|
|
171
|
+
actor: actor(body, defaultActor)
|
|
172
|
+
}));
|
|
173
|
+
} catch (error) {
|
|
174
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
175
|
+
return jsonError(c, /Unknown task/.test(message) ? 404 : /Queue producer/.test(message) ? 501 : 500, message);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
app.post(withPrefix(prefix, "/tasks/:id/followups"), async (c) => {
|
|
179
|
+
const unauthorized = authorizeRequest(c, options);
|
|
180
|
+
if (unauthorized) return unauthorized;
|
|
181
|
+
const body = await c.req.json().catch(() => ({}));
|
|
182
|
+
const current = await options.sdk.get({ model: "task", id: c.req.param("id") });
|
|
183
|
+
if (!current.payload) {
|
|
184
|
+
return jsonError(c, 404, "Unknown task.");
|
|
185
|
+
}
|
|
186
|
+
const currentTask = current.payload;
|
|
187
|
+
const followups = Array.isArray(body.followups) ? body.followups : [];
|
|
188
|
+
const created = [];
|
|
189
|
+
for (const followup of followups) {
|
|
190
|
+
created.push(await options.sdk.createTask({
|
|
191
|
+
workDayId: String(followup.workDayId ?? currentTask.workDayId ?? ""),
|
|
192
|
+
agentId: String(followup.agentId ?? currentTask.agentId ?? ""),
|
|
193
|
+
type: String(followup.type ?? "followup"),
|
|
194
|
+
priority: followup.priority === void 0 ? void 0 : Number(followup.priority),
|
|
195
|
+
idempotencyKey: String(followup.idempotencyKey ?? `${c.req.param("id")}:${created.length}`),
|
|
196
|
+
payload: followup.payload ?? {},
|
|
197
|
+
graphVersion: typeof followup.graphVersion === "string" ? followup.graphVersion : null,
|
|
198
|
+
parentTaskId: c.req.param("id"),
|
|
199
|
+
actor: actor(followup, defaultActor)
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
202
|
+
return c.json({ ok: true, payload: created.map((entry) => entry.payload) });
|
|
203
|
+
});
|
|
204
|
+
app.post(withPrefix(prefix, "/queue/enqueue"), async (c) => {
|
|
205
|
+
const unauthorized = authorizeRequest(c, options);
|
|
206
|
+
if (unauthorized) return unauthorized;
|
|
207
|
+
const body = await c.req.json().catch(() => ({}));
|
|
208
|
+
try {
|
|
209
|
+
return c.json(await enqueueTaskFromSdk(options.sdk, {
|
|
210
|
+
taskId: String(body.taskId ?? ""),
|
|
211
|
+
queueName: typeof body.queueName === "string" ? body.queueName : void 0,
|
|
212
|
+
deliveryDelaySeconds: body.deliveryDelaySeconds === void 0 ? void 0 : Number(body.deliveryDelaySeconds),
|
|
213
|
+
actor: actor(body, defaultActor)
|
|
214
|
+
}));
|
|
215
|
+
} catch (error) {
|
|
216
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
217
|
+
return jsonError(c, /Unknown task/.test(message) ? 404 : /Queue push client/.test(message) ? 501 : 500, message);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
app.post(withPrefix(prefix, "/reports"), async (c) => {
|
|
221
|
+
const unauthorized = authorizeRequest(c, options);
|
|
222
|
+
if (unauthorized) return unauthorized;
|
|
223
|
+
const body = await c.req.json().catch(() => ({}));
|
|
224
|
+
const result = await options.sdk.createReport({
|
|
225
|
+
id: typeof body.id === "string" ? body.id : void 0,
|
|
226
|
+
workDayId: String(body.workDayId ?? ""),
|
|
227
|
+
kind: String(body.kind ?? "workday_summary"),
|
|
228
|
+
body: body.body ?? {},
|
|
229
|
+
renderedRef: typeof body.renderedRef === "string" ? body.renderedRef : null,
|
|
230
|
+
sentAt: typeof body.sentAt === "string" ? body.sentAt : null,
|
|
231
|
+
actor: actor(body, defaultActor)
|
|
232
|
+
});
|
|
233
|
+
return c.json(result);
|
|
234
|
+
});
|
|
235
|
+
app.post(withPrefix(prefix, "/context/resolve-task"), async (c) => {
|
|
236
|
+
const unauthorized = authorizeRequest(c, options);
|
|
237
|
+
if (unauthorized) return unauthorized;
|
|
238
|
+
const body = await c.req.json().catch(() => ({}));
|
|
239
|
+
return c.json({
|
|
240
|
+
ok: true,
|
|
241
|
+
payload: await buildTaskContext(options.sdk, String(body.taskId ?? ""))
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
app.post(withPrefix(prefix, "/graph/search"), async (c) => {
|
|
245
|
+
const unauthorized = authorizeRequest(c, options);
|
|
246
|
+
if (unauthorized) return unauthorized;
|
|
247
|
+
const body = await c.req.json().catch(() => ({}));
|
|
248
|
+
const query = String(body.query ?? "");
|
|
249
|
+
const scope = String(body.scope ?? "sections");
|
|
250
|
+
const payload = scope === "files" ? await options.sdk.searchFiles(query, body.options) : scope === "entities" ? await options.sdk.searchEntities(query, body.options) : await options.sdk.searchSections(query, body.options);
|
|
251
|
+
return c.json({ ok: true, payload });
|
|
252
|
+
});
|
|
253
|
+
app.post(withPrefix(prefix, "/graph/subgraph"), async (c) => {
|
|
254
|
+
const unauthorized = authorizeRequest(c, options);
|
|
255
|
+
if (unauthorized) return unauthorized;
|
|
256
|
+
const body = await c.req.json().catch(() => ({}));
|
|
257
|
+
const payload = await options.sdk.getSubgraph(
|
|
258
|
+
Array.isArray(body.seedIds) ? body.seedIds.map(String) : [],
|
|
259
|
+
body.options
|
|
260
|
+
);
|
|
261
|
+
return c.json({ ok: true, payload });
|
|
262
|
+
});
|
|
263
|
+
app.post(withPrefix(prefix, "/graph/query"), async (c) => {
|
|
264
|
+
const unauthorized = authorizeRequest(c, options);
|
|
265
|
+
if (unauthorized) return unauthorized;
|
|
266
|
+
const body = await c.req.json().catch(() => ({}));
|
|
267
|
+
const payload = await options.sdk.queryGraph(body);
|
|
268
|
+
if (typeof body.workDayId === "string" && body.workDayId) {
|
|
269
|
+
await options.sdk.create({
|
|
270
|
+
model: "graph_run",
|
|
271
|
+
data: {
|
|
272
|
+
workDayId: body.workDayId,
|
|
273
|
+
corpusHash: String(body.corpusHash ?? "query-graph"),
|
|
274
|
+
graphVersion: String(body.graphVersion ?? ""),
|
|
275
|
+
queryJson: JSON.stringify(body),
|
|
276
|
+
seedIdsJson: JSON.stringify(payload.seedIds),
|
|
277
|
+
selectedNodeIdsJson: JSON.stringify(payload.nodes.map((entry) => entry.node.id)),
|
|
278
|
+
statsJson: JSON.stringify({ nodeCount: payload.nodes.length, edgeCount: payload.edges.length })
|
|
279
|
+
},
|
|
280
|
+
actor: actor(body, defaultActor)
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
return c.json({ ok: true, payload });
|
|
284
|
+
});
|
|
285
|
+
app.post(withPrefix(prefix, "/graph/context-pack"), async (c) => {
|
|
286
|
+
const unauthorized = authorizeRequest(c, options);
|
|
287
|
+
if (unauthorized) return unauthorized;
|
|
288
|
+
const body = await c.req.json().catch(() => ({}));
|
|
289
|
+
const payload = await options.sdk.buildContextPack(body);
|
|
290
|
+
if (typeof body.workDayId === "string" && body.workDayId) {
|
|
291
|
+
await options.sdk.create({
|
|
292
|
+
model: "graph_run",
|
|
293
|
+
data: {
|
|
294
|
+
workDayId: body.workDayId,
|
|
295
|
+
corpusHash: String(body.corpusHash ?? "context-pack"),
|
|
296
|
+
graphVersion: String(body.graphVersion ?? ""),
|
|
297
|
+
queryJson: JSON.stringify(body),
|
|
298
|
+
seedIdsJson: JSON.stringify(payload.seedIds),
|
|
299
|
+
selectedNodeIdsJson: JSON.stringify(payload.includedNodeIds),
|
|
300
|
+
statsJson: JSON.stringify({
|
|
301
|
+
nodeCount: payload.nodes.length,
|
|
302
|
+
edgeCount: payload.edges.length,
|
|
303
|
+
totalTokenEstimate: payload.totalTokenEstimate
|
|
304
|
+
})
|
|
305
|
+
},
|
|
306
|
+
actor: actor(body, defaultActor)
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return c.json({ ok: true, payload });
|
|
310
|
+
});
|
|
311
|
+
app.post(withPrefix(prefix, "/graph/parse-dsl"), async (c) => {
|
|
312
|
+
const unauthorized = authorizeRequest(c, options);
|
|
313
|
+
if (unauthorized) return unauthorized;
|
|
314
|
+
const body = await c.req.json().catch(() => ({}));
|
|
315
|
+
const payload = await options.sdk.parseGraphDsl(String(body.source ?? body.query ?? ""));
|
|
316
|
+
return c.json({ ok: true, payload });
|
|
317
|
+
});
|
|
318
|
+
app.get(withPrefix(prefix, "/graph/node/:id"), async (c) => {
|
|
319
|
+
const unauthorized = authorizeRequest(c, options);
|
|
320
|
+
if (unauthorized) return unauthorized;
|
|
321
|
+
const payload = await options.sdk.getGraphNode(c.req.param("id"));
|
|
322
|
+
return payload ? c.json({ ok: true, payload }) : jsonError(c, 404, "Unknown graph node.");
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
export {
|
|
326
|
+
registerAgentRoutes
|
|
327
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import type { ApiServerOptions, AppVariables } from './types.ts';
|
|
3
|
+
export declare function createTreeseedApiRouter(options?: ApiServerOptions): Hono<{
|
|
4
|
+
Variables: AppVariables;
|
|
5
|
+
}, import("hono/types").BlankSchema, "/">;
|
|
6
|
+
export declare function createTreeseedApiApp(options?: ApiServerOptions): Hono<{
|
|
7
|
+
Variables: AppVariables;
|
|
8
|
+
}, import("hono/types").BlankSchema, "/">;
|