@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,51 @@
|
|
|
1
|
+
import { type Server } from 'node:http';
|
|
2
|
+
import type { Hono } from 'hono';
|
|
3
|
+
import type { ApiServerOptions } from './types.ts';
|
|
4
|
+
export declare function createTreeseedNodeServer(options?: ApiServerOptions): Promise<{
|
|
5
|
+
app: Hono<{
|
|
6
|
+
Variables: import("./types.ts").AppVariables;
|
|
7
|
+
}, import("hono/types").BlankSchema, "/">;
|
|
8
|
+
config: {
|
|
9
|
+
providers: {
|
|
10
|
+
agents: {
|
|
11
|
+
execution: string;
|
|
12
|
+
queue: string;
|
|
13
|
+
notification: string;
|
|
14
|
+
repository: string;
|
|
15
|
+
verification: string;
|
|
16
|
+
};
|
|
17
|
+
auth: string;
|
|
18
|
+
};
|
|
19
|
+
name: string;
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
issuer: string;
|
|
24
|
+
repoRoot: string;
|
|
25
|
+
projectId: string;
|
|
26
|
+
authSecret: string;
|
|
27
|
+
projectApiKey?: string;
|
|
28
|
+
projectApiLabel: string;
|
|
29
|
+
projectApiPermissions: string[];
|
|
30
|
+
cloudflareAccountId?: string;
|
|
31
|
+
cloudflareApiToken?: string;
|
|
32
|
+
d1DatabaseId?: string;
|
|
33
|
+
d1DatabaseName?: string;
|
|
34
|
+
d1LocalPersistTo?: string;
|
|
35
|
+
d1WranglerConfigPath?: string;
|
|
36
|
+
webServiceId: string;
|
|
37
|
+
webServiceSecret: string;
|
|
38
|
+
webAssertionSecret: string;
|
|
39
|
+
webExchangeTtlSeconds: number;
|
|
40
|
+
bootstrapAdminAllowlist: string[];
|
|
41
|
+
accessTokenTtlSeconds: number;
|
|
42
|
+
refreshTokenTtlSeconds: number;
|
|
43
|
+
deviceCodeTtlSeconds: number;
|
|
44
|
+
deviceCodePollIntervalSeconds: number;
|
|
45
|
+
templateCatalogPath?: string;
|
|
46
|
+
};
|
|
47
|
+
server: Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
48
|
+
url: string;
|
|
49
|
+
close(): Promise<void>;
|
|
50
|
+
}>;
|
|
51
|
+
export declare const createRailwayTreeseedApiServer: typeof createTreeseedNodeServer;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
import { createTreeseedApiApp } from "./app.js";
|
|
4
|
+
import { resolveApiConfig } from "./config.js";
|
|
5
|
+
function hasRequestBody(method) {
|
|
6
|
+
return method !== "GET" && method !== "HEAD";
|
|
7
|
+
}
|
|
8
|
+
async function honoNodeHandler(app, request, response) {
|
|
9
|
+
const req = request;
|
|
10
|
+
const res = response;
|
|
11
|
+
const origin = req.headers.host ? `http://${req.headers.host}` : "http://127.0.0.1";
|
|
12
|
+
const url = new URL(req.url ?? "/", origin);
|
|
13
|
+
const webRequest = new Request(url, {
|
|
14
|
+
method: req.method,
|
|
15
|
+
headers: req.headers,
|
|
16
|
+
body: hasRequestBody(req.method) ? req : void 0,
|
|
17
|
+
duplex: "half"
|
|
18
|
+
});
|
|
19
|
+
const webResponse = await app.fetch(webRequest);
|
|
20
|
+
res.statusCode = webResponse.status;
|
|
21
|
+
webResponse.headers.forEach((value, key) => {
|
|
22
|
+
res.setHeader(key, value);
|
|
23
|
+
});
|
|
24
|
+
if (!webResponse.body) {
|
|
25
|
+
res.end();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
Readable.fromWeb(webResponse.body).pipe(res);
|
|
29
|
+
}
|
|
30
|
+
async function createTreeseedNodeServer(options = {}) {
|
|
31
|
+
const config = {
|
|
32
|
+
...resolveApiConfig(),
|
|
33
|
+
...options.config ?? {},
|
|
34
|
+
providers: {
|
|
35
|
+
...resolveApiConfig().providers,
|
|
36
|
+
...options.config?.providers ?? {},
|
|
37
|
+
agents: {
|
|
38
|
+
...resolveApiConfig().providers.agents,
|
|
39
|
+
...options.config?.providers?.agents ?? {}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const app = createTreeseedApiApp({
|
|
44
|
+
...options,
|
|
45
|
+
config
|
|
46
|
+
});
|
|
47
|
+
const server = createServer((req, res) => {
|
|
48
|
+
void honoNodeHandler(app, req, res);
|
|
49
|
+
});
|
|
50
|
+
await new Promise((resolvePromise) => {
|
|
51
|
+
server.listen(config.port, config.host, () => resolvePromise());
|
|
52
|
+
});
|
|
53
|
+
const address = server.address();
|
|
54
|
+
const resolvedUrl = address ? `${config.baseUrl.startsWith("http") ? config.baseUrl : `http://${address.address}:${address.port}`}` : config.baseUrl;
|
|
55
|
+
return {
|
|
56
|
+
app,
|
|
57
|
+
config,
|
|
58
|
+
server,
|
|
59
|
+
url: resolvedUrl,
|
|
60
|
+
async close() {
|
|
61
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
62
|
+
server.close((error) => error ? rejectPromise(error) : resolvePromise());
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const createRailwayTreeseedApiServer = createTreeseedNodeServer;
|
|
68
|
+
export {
|
|
69
|
+
createRailwayTreeseedApiServer,
|
|
70
|
+
createTreeseedNodeServer
|
|
71
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AgentSdk, RemoteSdkOperationRequest } from '@treeseed/sdk';
|
|
2
|
+
import { executeSdkOperation, findSdkOperation, listSdkOperationNames } from '@treeseed/sdk';
|
|
3
|
+
import type { ApiConfig } from './types.ts';
|
|
4
|
+
export { executeSdkOperation, findSdkOperation, listSdkOperationNames, };
|
|
5
|
+
export declare function resolveSdkInstance(sharedSdk: AgentSdk | undefined, config: ApiConfig, request: RemoteSdkOperationRequest): AgentSdk;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AgentSdk as AgentSdkClass, executeSdkOperation, findSdkOperation, listSdkOperationNames } from "@treeseed/sdk";
|
|
2
|
+
function resolveSdkInstance(sharedSdk, config, request) {
|
|
3
|
+
if (!request.repoRoot || request.repoRoot === config.repoRoot) {
|
|
4
|
+
return sharedSdk ?? new AgentSdkClass({ repoRoot: config.repoRoot });
|
|
5
|
+
}
|
|
6
|
+
return new AgentSdkClass({ repoRoot: request.repoRoot });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
executeSdkOperation,
|
|
10
|
+
findSdkOperation,
|
|
11
|
+
listSdkOperationNames,
|
|
12
|
+
resolveSdkInstance
|
|
13
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import type { AgentSdk } from '@treeseed/sdk';
|
|
3
|
+
import type { ApiConfig } from './types.ts';
|
|
4
|
+
interface RegisterSdkRoutesOptions {
|
|
5
|
+
config: ApiConfig;
|
|
6
|
+
sharedSdk?: AgentSdk;
|
|
7
|
+
scope: string;
|
|
8
|
+
prefix?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function registerSdkRoutes(app: Hono<any>, options: RegisterSdkRoutesOptions): void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { executeSdkOperation, resolveSdkInstance } from "./sdk-dispatch.js";
|
|
2
|
+
import { jsonError, requireScope } from "./http.js";
|
|
3
|
+
function withPrefix(prefix, path) {
|
|
4
|
+
if (!prefix) return path;
|
|
5
|
+
return `${prefix}${path}`.replace(/\/{2,}/g, "/");
|
|
6
|
+
}
|
|
7
|
+
function registerSdkRoutes(app, options) {
|
|
8
|
+
app.post(withPrefix(options.prefix ?? "", "/sdk/:operation"), async (c) => {
|
|
9
|
+
const unauthorized = requireScope(c, options.scope);
|
|
10
|
+
if (unauthorized) return unauthorized;
|
|
11
|
+
const operation = c.req.param("operation");
|
|
12
|
+
const body = await c.req.json().catch(() => ({}));
|
|
13
|
+
try {
|
|
14
|
+
const result = await executeSdkOperation(
|
|
15
|
+
resolveSdkInstance(options.sharedSdk, options.config, body),
|
|
16
|
+
operation,
|
|
17
|
+
body.input ?? {}
|
|
18
|
+
);
|
|
19
|
+
return c.json(result);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
22
|
+
const status = /Unknown SDK operation/.test(message) ? 400 : 500;
|
|
23
|
+
return jsonError(c, status, message, { operation });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
registerSdkRoutes
|
|
29
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { createRailwayTreeseedApiServer } from "./railway.js";
|
|
4
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
5
|
+
const entryFile = process.argv[1] ?? "";
|
|
6
|
+
if (entryFile === currentFile) {
|
|
7
|
+
const instance = await createRailwayTreeseedApiServer();
|
|
8
|
+
process.stdout.write(`Treeseed API listening on ${instance.url}
|
|
9
|
+
`);
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { parseTemplateCatalogResponse } from "@treeseed/sdk/template-catalog";
|
|
5
|
+
const require2 = createRequire(import.meta.url);
|
|
6
|
+
function resolveSdkPackageRoot() {
|
|
7
|
+
const exportedEntrypoint = require2.resolve("@treeseed/sdk");
|
|
8
|
+
const distRoot = dirname(exportedEntrypoint);
|
|
9
|
+
const packageRoot = resolve(distRoot, "..");
|
|
10
|
+
return packageRoot;
|
|
11
|
+
}
|
|
12
|
+
function resolveDefaultCatalogPath() {
|
|
13
|
+
const sdkRoot = resolveSdkPackageRoot();
|
|
14
|
+
const candidates = [
|
|
15
|
+
resolve(sdkRoot, "dist", "treeseed", "template-catalog", "catalog.fixture.json"),
|
|
16
|
+
resolve(sdkRoot, "src", "treeseed", "template-catalog", "catalog.fixture.json")
|
|
17
|
+
];
|
|
18
|
+
for (const candidate of candidates) {
|
|
19
|
+
if (existsSync(candidate)) {
|
|
20
|
+
return candidate;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
throw new Error("Unable to resolve the bundled Treeseed template catalog fixture.");
|
|
24
|
+
}
|
|
25
|
+
function loadTemplateCatalog(config) {
|
|
26
|
+
const catalogPath = config.templateCatalogPath ?? resolveDefaultCatalogPath();
|
|
27
|
+
return parseTemplateCatalogResponse(JSON.parse(readFileSync(catalogPath, "utf8")));
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
loadTemplateCatalog
|
|
31
|
+
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import type { Hono } from 'hono';
|
|
2
|
+
import type { AgentSdk } from '@treeseed/sdk';
|
|
3
|
+
import type { ApiPrincipal, ApiScope, DeviceCodeApproveRequest as SdkDeviceCodeApproveRequest, DeviceCodePollRequest, DeviceCodePollResponse, DeviceCodeStartRequest, DeviceCodeStartResponse, RemoteWorkflowOperationRequest as WorkflowHttpOperationRequest, RemoteWorkflowOperationResponse as ApiWorkflowOperationResponse, RemoteSdkOperationRequest as SdkHttpOperationRequest, TokenRefreshRequest, TokenRefreshResponse } from '@treeseed/sdk/remote';
|
|
4
|
+
export type { ApiPrincipal, ApiScope, DeviceCodePollRequest, DeviceCodePollResponse, DeviceCodeStartRequest, DeviceCodeStartResponse, WorkflowHttpOperationRequest, ApiWorkflowOperationResponse, SdkHttpOperationRequest, TokenRefreshRequest, TokenRefreshResponse, };
|
|
5
|
+
export type DeviceCodeApproveRequest = SdkDeviceCodeApproveRequest;
|
|
6
|
+
export interface ApiAuthProvider {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
startDeviceFlow(request: DeviceCodeStartRequest): Promise<DeviceCodeStartResponse>;
|
|
9
|
+
pollDeviceFlow(request: DeviceCodePollRequest): Promise<DeviceCodePollResponse>;
|
|
10
|
+
refreshAccessToken(request: TokenRefreshRequest): Promise<TokenRefreshResponse>;
|
|
11
|
+
approveDeviceFlow(request: DeviceCodeApproveRequest): Promise<{
|
|
12
|
+
ok: true;
|
|
13
|
+
}>;
|
|
14
|
+
authenticateBearerToken(token: string): Promise<{
|
|
15
|
+
principal: ApiPrincipal;
|
|
16
|
+
credential: ApiCredential;
|
|
17
|
+
} | null>;
|
|
18
|
+
authenticateServiceCredential(serviceId: string, secret: string): Promise<{
|
|
19
|
+
principal: ApiPrincipal;
|
|
20
|
+
credential: ApiCredential;
|
|
21
|
+
} | null>;
|
|
22
|
+
createPersonalAccessToken(userId: string, input: {
|
|
23
|
+
name: string;
|
|
24
|
+
scopes?: string[];
|
|
25
|
+
expiresAt?: string | null;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
id: string;
|
|
28
|
+
token: string;
|
|
29
|
+
prefix: string;
|
|
30
|
+
name: string;
|
|
31
|
+
expiresAt: string | null;
|
|
32
|
+
}>;
|
|
33
|
+
listPersonalAccessTokens(userId: string): Promise<Array<{
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
token_prefix: string;
|
|
37
|
+
expires_at: string | null;
|
|
38
|
+
last_used_at: string | null;
|
|
39
|
+
revoked_at: string | null;
|
|
40
|
+
created_at: string;
|
|
41
|
+
}>>;
|
|
42
|
+
revokePersonalAccessToken(userId: string, tokenId: string): Promise<void>;
|
|
43
|
+
syncUserIdentity(identity: UserIdentityProfileInput): Promise<{
|
|
44
|
+
principal: ApiPrincipal;
|
|
45
|
+
userId: string;
|
|
46
|
+
identityId: string | null;
|
|
47
|
+
}>;
|
|
48
|
+
createUser?(input: {
|
|
49
|
+
email?: string | null;
|
|
50
|
+
username?: string | null;
|
|
51
|
+
displayName?: string | null;
|
|
52
|
+
metadata?: Record<string, unknown>;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
principal: ApiPrincipal;
|
|
55
|
+
userId: string;
|
|
56
|
+
}>;
|
|
57
|
+
setUserRoles?(userId: string, roles: string[]): Promise<{
|
|
58
|
+
principal: ApiPrincipal;
|
|
59
|
+
userId: string;
|
|
60
|
+
}>;
|
|
61
|
+
createServiceToken(input: {
|
|
62
|
+
serviceId: string;
|
|
63
|
+
name: string;
|
|
64
|
+
roles?: string[];
|
|
65
|
+
permissions?: string[];
|
|
66
|
+
}): Promise<{
|
|
67
|
+
id: string;
|
|
68
|
+
serviceId: string;
|
|
69
|
+
secret: string;
|
|
70
|
+
}>;
|
|
71
|
+
rotateServiceToken(serviceId: string): Promise<{
|
|
72
|
+
id: string;
|
|
73
|
+
serviceId: string;
|
|
74
|
+
secret: string;
|
|
75
|
+
}>;
|
|
76
|
+
createTrustedUserAssertion(claims: TrustedUserAssertionClaims): string;
|
|
77
|
+
verifyTrustedUserAssertion(assertion: string): TrustedUserAssertionClaims | null;
|
|
78
|
+
exchangeTrustedUserAssertion(claims: TrustedUserAssertionClaims): Promise<{
|
|
79
|
+
ok: true;
|
|
80
|
+
accessToken: string;
|
|
81
|
+
tokenType: 'Bearer';
|
|
82
|
+
expiresAt: string;
|
|
83
|
+
expiresInSeconds: number;
|
|
84
|
+
principal: ApiPrincipal;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
export type ApiRuntimeProviderSelections = {
|
|
88
|
+
auth: string;
|
|
89
|
+
agents: {
|
|
90
|
+
execution: string;
|
|
91
|
+
queue: string;
|
|
92
|
+
notification: string;
|
|
93
|
+
repository: string;
|
|
94
|
+
verification: string;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
export interface ApiConfig {
|
|
98
|
+
name: string;
|
|
99
|
+
host: string;
|
|
100
|
+
port: number;
|
|
101
|
+
baseUrl: string;
|
|
102
|
+
issuer: string;
|
|
103
|
+
repoRoot: string;
|
|
104
|
+
projectId: string;
|
|
105
|
+
authSecret: string;
|
|
106
|
+
projectApiKey?: string;
|
|
107
|
+
projectApiLabel: string;
|
|
108
|
+
projectApiPermissions: string[];
|
|
109
|
+
cloudflareAccountId?: string;
|
|
110
|
+
cloudflareApiToken?: string;
|
|
111
|
+
d1DatabaseId?: string;
|
|
112
|
+
d1DatabaseName?: string;
|
|
113
|
+
d1LocalPersistTo?: string;
|
|
114
|
+
d1WranglerConfigPath?: string;
|
|
115
|
+
webServiceId: string;
|
|
116
|
+
webServiceSecret: string;
|
|
117
|
+
webAssertionSecret: string;
|
|
118
|
+
webExchangeTtlSeconds: number;
|
|
119
|
+
bootstrapAdminAllowlist: string[];
|
|
120
|
+
accessTokenTtlSeconds: number;
|
|
121
|
+
refreshTokenTtlSeconds: number;
|
|
122
|
+
deviceCodeTtlSeconds: number;
|
|
123
|
+
deviceCodePollIntervalSeconds: number;
|
|
124
|
+
templateCatalogPath?: string;
|
|
125
|
+
providers: ApiRuntimeProviderSelections;
|
|
126
|
+
}
|
|
127
|
+
export interface AppVariables {
|
|
128
|
+
requestId: string;
|
|
129
|
+
config: ApiConfig;
|
|
130
|
+
principal: ApiPrincipal | null;
|
|
131
|
+
actingUser: ApiPrincipal | null;
|
|
132
|
+
credential: ApiCredential | null;
|
|
133
|
+
actorType: 'anonymous' | 'user' | 'service' | 'project';
|
|
134
|
+
permissionGrants: string[];
|
|
135
|
+
}
|
|
136
|
+
export interface ApiCredential {
|
|
137
|
+
type: 'access_token' | 'personal_access_token' | 'service_secret' | 'service_token' | 'project_api_key' | 'team_api_key';
|
|
138
|
+
id: string;
|
|
139
|
+
label?: string;
|
|
140
|
+
}
|
|
141
|
+
export interface TrustedUserAssertionClaims {
|
|
142
|
+
userId: string;
|
|
143
|
+
sessionId: string;
|
|
144
|
+
identityId?: string | null;
|
|
145
|
+
teamId?: string | null;
|
|
146
|
+
projectId?: string | null;
|
|
147
|
+
membershipId?: string | null;
|
|
148
|
+
teamRoles?: string[];
|
|
149
|
+
teamCapabilities?: string[];
|
|
150
|
+
authTime: string;
|
|
151
|
+
expiresAt: string;
|
|
152
|
+
nonce: string;
|
|
153
|
+
}
|
|
154
|
+
export interface UserIdentityProfileInput {
|
|
155
|
+
provider: string;
|
|
156
|
+
providerSubject: string;
|
|
157
|
+
email?: string | null;
|
|
158
|
+
emailVerified?: boolean;
|
|
159
|
+
username?: string | null;
|
|
160
|
+
displayName?: string | null;
|
|
161
|
+
profile?: Record<string, unknown>;
|
|
162
|
+
}
|
|
163
|
+
export type ApiProviderFactory<T> = (options: {
|
|
164
|
+
config: ApiConfig;
|
|
165
|
+
}) => T;
|
|
166
|
+
export interface ApiRuntimeProviders {
|
|
167
|
+
auth?: Record<string, ApiProviderFactory<ApiAuthProvider>>;
|
|
168
|
+
agentExecution?: Record<string, unknown>;
|
|
169
|
+
agentQueue?: Record<string, unknown>;
|
|
170
|
+
agentNotification?: Record<string, unknown>;
|
|
171
|
+
agentRepository?: Record<string, unknown>;
|
|
172
|
+
agentVerification?: Record<string, unknown>;
|
|
173
|
+
}
|
|
174
|
+
export interface ResolvedApiRuntimeProviders {
|
|
175
|
+
auth: ApiAuthProvider;
|
|
176
|
+
registries: {
|
|
177
|
+
auth: Map<string, ApiProviderFactory<ApiAuthProvider>>;
|
|
178
|
+
agentExecution: Map<string, unknown>;
|
|
179
|
+
agentQueue: Map<string, unknown>;
|
|
180
|
+
agentNotification: Map<string, unknown>;
|
|
181
|
+
agentRepository: Map<string, unknown>;
|
|
182
|
+
agentVerification: Map<string, unknown>;
|
|
183
|
+
};
|
|
184
|
+
selections: ApiRuntimeProviderSelections;
|
|
185
|
+
}
|
|
186
|
+
export interface ApiResolvedSettings {
|
|
187
|
+
config: ApiConfig;
|
|
188
|
+
surfaces: {
|
|
189
|
+
auth: boolean;
|
|
190
|
+
templates: boolean;
|
|
191
|
+
sdk: boolean;
|
|
192
|
+
agent: boolean;
|
|
193
|
+
operations: boolean;
|
|
194
|
+
project: boolean;
|
|
195
|
+
};
|
|
196
|
+
scopes: {
|
|
197
|
+
authMe: ApiScope;
|
|
198
|
+
sdk: ApiScope;
|
|
199
|
+
agent: ApiScope;
|
|
200
|
+
operations: ApiScope;
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
export interface ApiAppRuntime {
|
|
204
|
+
resolved: ApiResolvedSettings;
|
|
205
|
+
runtimeProviders: ResolvedApiRuntimeProviders;
|
|
206
|
+
sharedSdk: AgentSdk;
|
|
207
|
+
internalPrefix: string;
|
|
208
|
+
}
|
|
209
|
+
export type TreeseedApiContext = ApiAppRuntime;
|
|
210
|
+
export interface TreeseedApiExtension {
|
|
211
|
+
name: string;
|
|
212
|
+
mount(app: Hono<any>, context: TreeseedApiContext): void | Promise<void>;
|
|
213
|
+
}
|
|
214
|
+
export interface ApiServerOptions {
|
|
215
|
+
config?: Partial<ApiConfig>;
|
|
216
|
+
runtimeProviders?: ApiRuntimeProviders;
|
|
217
|
+
sdk?: AgentSdk;
|
|
218
|
+
workflowExecutor?: (operation: string, request: WorkflowHttpOperationRequest) => Promise<ApiWorkflowOperationResponse>;
|
|
219
|
+
surfaces?: Partial<{
|
|
220
|
+
auth: boolean;
|
|
221
|
+
templates: boolean;
|
|
222
|
+
sdk: boolean;
|
|
223
|
+
agent: boolean;
|
|
224
|
+
operations: boolean;
|
|
225
|
+
project: boolean;
|
|
226
|
+
}>;
|
|
227
|
+
scopes?: Partial<{
|
|
228
|
+
authMe: ApiScope;
|
|
229
|
+
sdk: ApiScope;
|
|
230
|
+
agent: ApiScope;
|
|
231
|
+
operations: ApiScope;
|
|
232
|
+
}>;
|
|
233
|
+
internalPrefix?: string;
|
|
234
|
+
extensions?: TreeseedApiExtension[];
|
|
235
|
+
extendApp?: (app: Hono<any>, runtime: ApiAppRuntime) => void;
|
|
236
|
+
log?: (message: string, details?: Record<string, unknown>) => void;
|
|
237
|
+
}
|
|
File without changes
|