@treeseed/sdk 0.3.0 → 0.3.2
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/platform/deploy-runtime.d.ts +18 -0
- package/dist/platform/deploy-runtime.js +78 -0
- package/dist/platform/plugins/runtime.js +41 -2
- package/dist/platform/plugins.d.ts +1 -0
- package/dist/platform/plugins.js +22 -0
- package/dist/sdk-types.d.ts +1 -1
- package/dist/utils/agents/contracts/messages.d.ts +88 -0
- package/dist/utils/agents/contracts/messages.js +139 -0
- package/dist/utils/agents/contracts/run.d.ts +20 -0
- package/dist/utils/agents/contracts/run.js +0 -0
- package/dist/utils/agents/runtime-types.d.ts +117 -0
- package/dist/utils/agents/runtime-types.js +4 -0
- package/package.json +17 -1
- package/scripts/verify-driver.mjs +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { getTreeseedVerifyDriverStatus, runTreeseedVerifyDriver } from './verifi
|
|
|
16
16
|
export * from './platform/contracts.ts';
|
|
17
17
|
export * from './platform/tenant-config.ts';
|
|
18
18
|
export * from './platform/deploy-config.ts';
|
|
19
|
+
export * from './platform/deploy-runtime.ts';
|
|
19
20
|
export * from './platform/environment.ts';
|
|
20
21
|
export * from './platform/plugins.ts';
|
|
21
22
|
export type { SdkContentEntry, SdkCursorEntity, SdkFilterCondition, SdkFollowRequest, SdkGraphEdge, SdkGraphEdgeType, SdkGraphDslRelation, SdkGraphDslParseResult, SdkGraphModelConfig, SdkGraphNode, SdkGraphNodeType, SdkGraphPathExplanation, SdkGraphQueryStage, SdkGraphQueryView, SdkGraphQueryOptions, SdkGraphQueryRequest, SdkGraphQueryResult, SdkGraphRankingBuildInput, SdkGraphRankingDiagnostics, SdkGraphRankingIndex, SdkGraphRankingNodeResult, SdkGraphRankingProvider, SdkGraphRankingQueryRequest, SdkGraphRankingQueryResult, SdkGraphRankingSearchRequest, SdkGraphRefreshPayload, SdkGraphRefreshRequest, SdkGraphSearchOptions, SdkGraphSearchResult, SdkGraphSeed, SdkGraphSeedResolution, SdkGraphTraversalResult, SdkGraphWhereFilter, SdkContextPack, SdkContextPackRequest, SdkGetRequest, SdkJsonEnvelope, SdkLeaseEntity, SdkManagerContextPayload, SdkMessageEntity, SdkModelFieldBinding, SdkModelDefinition, SdkModelRegistry, SdkModelName, SdkMutationRequest, SdkOperation, SdkPickRequest, SdkPickResult, SdkQueueMessageEnvelope, SdkRunEntity, SdkSearchRequest, SdkTaskEntity, SdkTaskEventEntity, SdkTaskOutputEntity, SdkWorkDayEntity, SdkGraphRunEntity, SdkReportEntity, SdkSubscriptionEntity, SdkTemplateCatalogEntry, SdkTemplateCatalogPublisher, SdkTemplateCatalogResponse, SdkTemplateCatalogSource, SdkUpdateRequest, } from './sdk-types.ts';
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ import { getTreeseedVerifyDriverStatus, runTreeseedVerifyDriver } from "./verifi
|
|
|
50
50
|
export * from "./platform/contracts.js";
|
|
51
51
|
export * from "./platform/tenant-config.js";
|
|
52
52
|
export * from "./platform/deploy-config.js";
|
|
53
|
+
export * from "./platform/deploy-runtime.js";
|
|
53
54
|
export * from "./platform/environment.js";
|
|
54
55
|
export * from "./platform/plugins.js";
|
|
55
56
|
export {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TreeseedDeployConfig } from './contracts.ts';
|
|
2
|
+
export declare function getTreeseedDeployConfig(): TreeseedDeployConfig;
|
|
3
|
+
export declare function resetTreeseedDeployConfigForTests(): void;
|
|
4
|
+
export declare function getTreeseedFormsProvider(): string;
|
|
5
|
+
export declare function getTreeseedOperationsProvider(): string;
|
|
6
|
+
export declare function getTreeseedAgentProviderSelections(): {
|
|
7
|
+
execution: string;
|
|
8
|
+
mutation: string;
|
|
9
|
+
repository: string;
|
|
10
|
+
verification: string;
|
|
11
|
+
notification: string;
|
|
12
|
+
research: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function getTreeseedDeployProvider(): string;
|
|
15
|
+
export declare function getTreeseedDocsProvider(): string;
|
|
16
|
+
export declare function getTreeseedSiteProvider(): string;
|
|
17
|
+
export declare function isTreeseedSmtpEnabled(): boolean;
|
|
18
|
+
export declare function isTreeseedTurnstileEnabled(): boolean;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { loadTreeseedDeployConfig } from "./deploy/config.js";
|
|
2
|
+
import { TREESEED_DEFAULT_PLUGIN_REFERENCES, TREESEED_DEFAULT_PROVIDER_SELECTIONS } from "./plugins/constants.js";
|
|
3
|
+
let cachedDeployConfig = null;
|
|
4
|
+
function defaultDeployConfig() {
|
|
5
|
+
return {
|
|
6
|
+
name: "Treeseed Site",
|
|
7
|
+
slug: "treeseed-site",
|
|
8
|
+
siteUrl: "https://example.com",
|
|
9
|
+
contactEmail: "contact@example.com",
|
|
10
|
+
cloudflare: {
|
|
11
|
+
accountId: "",
|
|
12
|
+
workerName: "treeseed-site"
|
|
13
|
+
},
|
|
14
|
+
plugins: [...TREESEED_DEFAULT_PLUGIN_REFERENCES],
|
|
15
|
+
providers: structuredClone(TREESEED_DEFAULT_PROVIDER_SELECTIONS),
|
|
16
|
+
smtp: {
|
|
17
|
+
enabled: false
|
|
18
|
+
},
|
|
19
|
+
turnstile: {
|
|
20
|
+
enabled: true
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getTreeseedDeployConfig() {
|
|
25
|
+
if (cachedDeployConfig) {
|
|
26
|
+
return cachedDeployConfig;
|
|
27
|
+
}
|
|
28
|
+
if (typeof __TREESEED_DEPLOY_CONFIG__ !== "undefined" && __TREESEED_DEPLOY_CONFIG__) {
|
|
29
|
+
cachedDeployConfig = __TREESEED_DEPLOY_CONFIG__;
|
|
30
|
+
return cachedDeployConfig;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
cachedDeployConfig = loadTreeseedDeployConfig();
|
|
34
|
+
return cachedDeployConfig;
|
|
35
|
+
} catch {
|
|
36
|
+
cachedDeployConfig = defaultDeployConfig();
|
|
37
|
+
return cachedDeployConfig;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function resetTreeseedDeployConfigForTests() {
|
|
41
|
+
cachedDeployConfig = null;
|
|
42
|
+
}
|
|
43
|
+
function getTreeseedFormsProvider() {
|
|
44
|
+
return getTreeseedDeployConfig().providers?.forms ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.forms;
|
|
45
|
+
}
|
|
46
|
+
function getTreeseedOperationsProvider() {
|
|
47
|
+
return getTreeseedDeployConfig().providers?.operations ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.operations;
|
|
48
|
+
}
|
|
49
|
+
function getTreeseedAgentProviderSelections() {
|
|
50
|
+
return getTreeseedDeployConfig().providers?.agents ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.agents;
|
|
51
|
+
}
|
|
52
|
+
function getTreeseedDeployProvider() {
|
|
53
|
+
return getTreeseedDeployConfig().providers?.deploy ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.deploy;
|
|
54
|
+
}
|
|
55
|
+
function getTreeseedDocsProvider() {
|
|
56
|
+
return getTreeseedDeployConfig().providers?.content?.docs ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.content.docs;
|
|
57
|
+
}
|
|
58
|
+
function getTreeseedSiteProvider() {
|
|
59
|
+
return getTreeseedDeployConfig().providers?.site ?? TREESEED_DEFAULT_PROVIDER_SELECTIONS.site;
|
|
60
|
+
}
|
|
61
|
+
function isTreeseedSmtpEnabled() {
|
|
62
|
+
return getTreeseedDeployConfig().smtp?.enabled ?? false;
|
|
63
|
+
}
|
|
64
|
+
function isTreeseedTurnstileEnabled() {
|
|
65
|
+
return getTreeseedDeployConfig().turnstile?.enabled ?? true;
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
getTreeseedAgentProviderSelections,
|
|
69
|
+
getTreeseedDeployConfig,
|
|
70
|
+
getTreeseedDeployProvider,
|
|
71
|
+
getTreeseedDocsProvider,
|
|
72
|
+
getTreeseedFormsProvider,
|
|
73
|
+
getTreeseedOperationsProvider,
|
|
74
|
+
getTreeseedSiteProvider,
|
|
75
|
+
isTreeseedSmtpEnabled,
|
|
76
|
+
isTreeseedTurnstileEnabled,
|
|
77
|
+
resetTreeseedDeployConfigForTests
|
|
78
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { createRequire } from "node:module";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { loadTreeseedDeployConfig } from "../deploy/config.js";
|
|
5
6
|
import { TREESEED_DEFAULT_PLUGIN_PACKAGE } from "./constants.js";
|
|
6
7
|
const require2 = createRequire(import.meta.url);
|
|
8
|
+
const runtimeDir = path.dirname(fileURLToPath(import.meta.url));
|
|
7
9
|
function normalizeLoadedPlugin(moduleExports, packageName) {
|
|
8
10
|
const plugin = moduleExports?.default ?? moduleExports;
|
|
9
11
|
if (!plugin || typeof plugin !== "object") {
|
|
@@ -14,9 +16,46 @@ function normalizeLoadedPlugin(moduleExports, packageName) {
|
|
|
14
16
|
function isPathLikePluginReference(packageName) {
|
|
15
17
|
return packageName.startsWith(".") || packageName.startsWith("/") || packageName.startsWith("file:");
|
|
16
18
|
}
|
|
19
|
+
function resolveLocalDefaultPluginPath() {
|
|
20
|
+
const candidates = [
|
|
21
|
+
path.resolve(runtimeDir, "../../../../core/dist/plugin-default.js"),
|
|
22
|
+
path.resolve(runtimeDir, "../../../../dist/plugin-default.js")
|
|
23
|
+
];
|
|
24
|
+
let current = runtimeDir;
|
|
25
|
+
while (true) {
|
|
26
|
+
const packageJsonPath = path.resolve(current, "package.json");
|
|
27
|
+
if (existsSync(packageJsonPath)) {
|
|
28
|
+
try {
|
|
29
|
+
const packageJson = require2(packageJsonPath);
|
|
30
|
+
if (packageJson?.name === "@treeseed/core") {
|
|
31
|
+
candidates.push(path.resolve(current, "dist/plugin-default.js"));
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const parent = path.resolve(current, "..");
|
|
38
|
+
if (parent === current) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
current = parent;
|
|
42
|
+
}
|
|
43
|
+
for (const candidate of candidates) {
|
|
44
|
+
if (existsSync(candidate)) {
|
|
45
|
+
return candidate;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function resolveInstalledPluginPath(packageName, tenantRoot) {
|
|
51
|
+
return require2.resolve(packageName, {
|
|
52
|
+
paths: [tenantRoot, process.cwd()]
|
|
53
|
+
});
|
|
54
|
+
}
|
|
17
55
|
function loadPluginModule(packageName, tenantRoot) {
|
|
18
56
|
if (packageName === TREESEED_DEFAULT_PLUGIN_PACKAGE) {
|
|
19
|
-
const
|
|
57
|
+
const localDefaultPluginPath = resolveLocalDefaultPluginPath();
|
|
58
|
+
const resolvedPath2 = localDefaultPluginPath ?? resolveInstalledPluginPath(packageName, tenantRoot);
|
|
20
59
|
return {
|
|
21
60
|
moduleExports: require2(resolvedPath2),
|
|
22
61
|
baseDir: path.dirname(resolvedPath2)
|
|
@@ -29,7 +68,7 @@ function loadPluginModule(packageName, tenantRoot) {
|
|
|
29
68
|
baseDir: path.dirname(resolvedPath2)
|
|
30
69
|
};
|
|
31
70
|
}
|
|
32
|
-
const resolvedPath =
|
|
71
|
+
const resolvedPath = resolveInstalledPluginPath(packageName, tenantRoot);
|
|
33
72
|
return {
|
|
34
73
|
moduleExports: require2(resolvedPath),
|
|
35
74
|
baseDir: path.dirname(resolvedPath)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { TREESEED_DEFAULT_PLUGIN_PACKAGE, TREESEED_DEFAULT_PLUGIN_REFERENCES, TREESEED_DEFAULT_PROVIDER_SELECTIONS, } from './plugins/constants.ts';
|
|
2
|
+
export { getTreeseedAgentProviderSelections, getTreeseedDeployConfig, getTreeseedDeployProvider, getTreeseedDocsProvider, getTreeseedFormsProvider, getTreeseedOperationsProvider, getTreeseedSiteProvider, isTreeseedSmtpEnabled, isTreeseedTurnstileEnabled, resetTreeseedDeployConfigForTests, } from './deploy-runtime.ts';
|
|
2
3
|
export { defineTreeseedPlugin } from './plugins/plugin.ts';
|
|
3
4
|
export type * from './plugins/plugin.ts';
|
|
4
5
|
export { loadTreeseedPluginRuntime, loadTreeseedPlugins, resolveTreeseedGraphRankingProvider } from './plugins/runtime.ts';
|
package/dist/platform/plugins.js
CHANGED
|
@@ -3,6 +3,18 @@ import {
|
|
|
3
3
|
TREESEED_DEFAULT_PLUGIN_REFERENCES,
|
|
4
4
|
TREESEED_DEFAULT_PROVIDER_SELECTIONS
|
|
5
5
|
} from "./plugins/constants.js";
|
|
6
|
+
import {
|
|
7
|
+
getTreeseedAgentProviderSelections,
|
|
8
|
+
getTreeseedDeployConfig,
|
|
9
|
+
getTreeseedDeployProvider,
|
|
10
|
+
getTreeseedDocsProvider,
|
|
11
|
+
getTreeseedFormsProvider,
|
|
12
|
+
getTreeseedOperationsProvider,
|
|
13
|
+
getTreeseedSiteProvider,
|
|
14
|
+
isTreeseedSmtpEnabled,
|
|
15
|
+
isTreeseedTurnstileEnabled,
|
|
16
|
+
resetTreeseedDeployConfigForTests
|
|
17
|
+
} from "./deploy-runtime.js";
|
|
6
18
|
import { defineTreeseedPlugin } from "./plugins/plugin.js";
|
|
7
19
|
import { loadTreeseedPluginRuntime, loadTreeseedPlugins, resolveTreeseedGraphRankingProvider } from "./plugins/runtime.js";
|
|
8
20
|
export {
|
|
@@ -10,7 +22,17 @@ export {
|
|
|
10
22
|
TREESEED_DEFAULT_PLUGIN_REFERENCES,
|
|
11
23
|
TREESEED_DEFAULT_PROVIDER_SELECTIONS,
|
|
12
24
|
defineTreeseedPlugin,
|
|
25
|
+
getTreeseedAgentProviderSelections,
|
|
26
|
+
getTreeseedDeployConfig,
|
|
27
|
+
getTreeseedDeployProvider,
|
|
28
|
+
getTreeseedDocsProvider,
|
|
29
|
+
getTreeseedFormsProvider,
|
|
30
|
+
getTreeseedOperationsProvider,
|
|
31
|
+
getTreeseedSiteProvider,
|
|
32
|
+
isTreeseedSmtpEnabled,
|
|
33
|
+
isTreeseedTurnstileEnabled,
|
|
13
34
|
loadTreeseedPluginRuntime,
|
|
14
35
|
loadTreeseedPlugins,
|
|
36
|
+
resetTreeseedDeployConfigForTests,
|
|
15
37
|
resolveTreeseedGraphRankingProvider
|
|
16
38
|
};
|
package/dist/sdk-types.d.ts
CHANGED
|
@@ -569,7 +569,7 @@ export interface SdkGraphRefreshPayload {
|
|
|
569
569
|
}
|
|
570
570
|
export interface SdkCreateMessageRequest {
|
|
571
571
|
type: string;
|
|
572
|
-
payload: Record<string, unknown
|
|
572
|
+
payload: Record<string, unknown> | string;
|
|
573
573
|
relatedModel?: string | null;
|
|
574
574
|
relatedId?: string | null;
|
|
575
575
|
priority?: number;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export interface QuestionPriorityUpdatedMessage {
|
|
2
|
+
questionId: string;
|
|
3
|
+
reason: string;
|
|
4
|
+
plannerRunId: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ObjectivePriorityUpdatedMessage {
|
|
7
|
+
objectiveId: string;
|
|
8
|
+
reason: string;
|
|
9
|
+
plannerRunId: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ArchitectureUpdatedMessage {
|
|
12
|
+
objectiveId: string;
|
|
13
|
+
knowledgeId: string;
|
|
14
|
+
architectRunId: string;
|
|
15
|
+
}
|
|
16
|
+
export interface SubscriberNotifiedMessage {
|
|
17
|
+
email: string;
|
|
18
|
+
itemCount: number;
|
|
19
|
+
notifierRunId: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ResearchStartedMessage {
|
|
22
|
+
questionId: string;
|
|
23
|
+
researcherRunId: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ResearchCompletedMessage {
|
|
26
|
+
questionId: string;
|
|
27
|
+
knowledgeId: string | null;
|
|
28
|
+
researcherRunId: string;
|
|
29
|
+
}
|
|
30
|
+
export interface TaskCompleteMessage {
|
|
31
|
+
branchName: string | null;
|
|
32
|
+
changedTargets: string[];
|
|
33
|
+
engineerRunId: string;
|
|
34
|
+
}
|
|
35
|
+
export interface TaskWaitingMessage {
|
|
36
|
+
blockingReason: string;
|
|
37
|
+
engineerRunId: string;
|
|
38
|
+
}
|
|
39
|
+
export interface TaskFailedMessage {
|
|
40
|
+
failureSummary: string;
|
|
41
|
+
engineerRunId: string;
|
|
42
|
+
}
|
|
43
|
+
export interface TaskVerifiedMessage {
|
|
44
|
+
branchName: string | null;
|
|
45
|
+
reviewerRunId: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ReviewFailedMessage {
|
|
48
|
+
failureSummary: string;
|
|
49
|
+
reviewerRunId: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ReviewWaitingMessage {
|
|
52
|
+
blockingReason: string;
|
|
53
|
+
reviewerRunId: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ReleaseStartedMessage {
|
|
56
|
+
taskRunId: string | null;
|
|
57
|
+
releaserRunId: string;
|
|
58
|
+
}
|
|
59
|
+
export interface ReleaseCompletedMessage {
|
|
60
|
+
releaseSummary: string;
|
|
61
|
+
releaserRunId: string;
|
|
62
|
+
}
|
|
63
|
+
export interface ReleaseFailedMessage {
|
|
64
|
+
failureSummary: string;
|
|
65
|
+
releaserRunId: string;
|
|
66
|
+
}
|
|
67
|
+
export interface AgentMessageContracts {
|
|
68
|
+
question_priority_updated: QuestionPriorityUpdatedMessage;
|
|
69
|
+
objective_priority_updated: ObjectivePriorityUpdatedMessage;
|
|
70
|
+
architecture_updated: ArchitectureUpdatedMessage;
|
|
71
|
+
subscriber_notified: SubscriberNotifiedMessage;
|
|
72
|
+
research_started: ResearchStartedMessage;
|
|
73
|
+
research_completed: ResearchCompletedMessage;
|
|
74
|
+
task_complete: TaskCompleteMessage;
|
|
75
|
+
task_waiting: TaskWaitingMessage;
|
|
76
|
+
task_failed: TaskFailedMessage;
|
|
77
|
+
task_verified: TaskVerifiedMessage;
|
|
78
|
+
review_failed: ReviewFailedMessage;
|
|
79
|
+
review_waiting: ReviewWaitingMessage;
|
|
80
|
+
release_started: ReleaseStartedMessage;
|
|
81
|
+
release_completed: ReleaseCompletedMessage;
|
|
82
|
+
release_failed: ReleaseFailedMessage;
|
|
83
|
+
}
|
|
84
|
+
export type AgentMessageType = keyof AgentMessageContracts;
|
|
85
|
+
export type AgentMessagePayload<TType extends AgentMessageType> = AgentMessageContracts[TType];
|
|
86
|
+
export declare const AGENT_MESSAGE_TYPES: readonly ["question_priority_updated", "objective_priority_updated", "architecture_updated", "subscriber_notified", "research_started", "research_completed", "task_complete", "task_waiting", "task_failed", "task_verified", "review_failed", "review_waiting", "release_started", "release_completed", "release_failed"];
|
|
87
|
+
export declare function parseAgentMessagePayload<TType extends AgentMessageType>(type: TType, payloadJson: string): AgentMessagePayload<TType>;
|
|
88
|
+
export declare function serializeAgentMessagePayload<TType extends AgentMessageType>(type: TType, payload: AgentMessagePayload<TType>): string;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const AGENT_MESSAGE_TYPES = [
|
|
2
|
+
"question_priority_updated",
|
|
3
|
+
"objective_priority_updated",
|
|
4
|
+
"architecture_updated",
|
|
5
|
+
"subscriber_notified",
|
|
6
|
+
"research_started",
|
|
7
|
+
"research_completed",
|
|
8
|
+
"task_complete",
|
|
9
|
+
"task_waiting",
|
|
10
|
+
"task_failed",
|
|
11
|
+
"task_verified",
|
|
12
|
+
"review_failed",
|
|
13
|
+
"review_waiting",
|
|
14
|
+
"release_started",
|
|
15
|
+
"release_completed",
|
|
16
|
+
"release_failed"
|
|
17
|
+
];
|
|
18
|
+
function ensureString(value, label) {
|
|
19
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
20
|
+
throw new Error(`Invalid ${label}: expected non-empty string.`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
function ensureOptionalString(value, label) {
|
|
25
|
+
if (value === null || value === void 0) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return ensureString(value, label);
|
|
29
|
+
}
|
|
30
|
+
function ensureStringArray(value, label) {
|
|
31
|
+
if (!Array.isArray(value)) {
|
|
32
|
+
throw new Error(`Invalid ${label}: expected array.`);
|
|
33
|
+
}
|
|
34
|
+
return value.map((entry, index) => ensureString(entry, `${label}[${index}]`));
|
|
35
|
+
}
|
|
36
|
+
function ensureNumber(value, label) {
|
|
37
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
38
|
+
throw new Error(`Invalid ${label}: expected number.`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
function parseAgentMessagePayload(type, payloadJson) {
|
|
43
|
+
const decoded = JSON.parse(payloadJson);
|
|
44
|
+
const parsed = typeof decoded === "string" ? JSON.parse(decoded) : decoded;
|
|
45
|
+
switch (type) {
|
|
46
|
+
case "question_priority_updated":
|
|
47
|
+
return {
|
|
48
|
+
questionId: ensureString(parsed.questionId, "questionId"),
|
|
49
|
+
reason: ensureString(parsed.reason, "reason"),
|
|
50
|
+
plannerRunId: ensureString(parsed.plannerRunId, "plannerRunId")
|
|
51
|
+
};
|
|
52
|
+
case "objective_priority_updated":
|
|
53
|
+
return {
|
|
54
|
+
objectiveId: ensureString(parsed.objectiveId, "objectiveId"),
|
|
55
|
+
reason: ensureString(parsed.reason, "reason"),
|
|
56
|
+
plannerRunId: ensureString(parsed.plannerRunId, "plannerRunId")
|
|
57
|
+
};
|
|
58
|
+
case "architecture_updated":
|
|
59
|
+
return {
|
|
60
|
+
objectiveId: ensureString(parsed.objectiveId, "objectiveId"),
|
|
61
|
+
knowledgeId: ensureString(parsed.knowledgeId, "knowledgeId"),
|
|
62
|
+
architectRunId: ensureString(parsed.architectRunId, "architectRunId")
|
|
63
|
+
};
|
|
64
|
+
case "subscriber_notified":
|
|
65
|
+
return {
|
|
66
|
+
email: ensureString(parsed.email, "email"),
|
|
67
|
+
itemCount: ensureNumber(parsed.itemCount, "itemCount"),
|
|
68
|
+
notifierRunId: ensureString(parsed.notifierRunId, "notifierRunId")
|
|
69
|
+
};
|
|
70
|
+
case "research_started":
|
|
71
|
+
return {
|
|
72
|
+
questionId: ensureString(parsed.questionId, "questionId"),
|
|
73
|
+
researcherRunId: ensureString(parsed.researcherRunId, "researcherRunId")
|
|
74
|
+
};
|
|
75
|
+
case "research_completed":
|
|
76
|
+
return {
|
|
77
|
+
questionId: ensureString(parsed.questionId, "questionId"),
|
|
78
|
+
knowledgeId: ensureOptionalString(parsed.knowledgeId, "knowledgeId"),
|
|
79
|
+
researcherRunId: ensureString(parsed.researcherRunId, "researcherRunId")
|
|
80
|
+
};
|
|
81
|
+
case "task_complete":
|
|
82
|
+
return {
|
|
83
|
+
branchName: ensureOptionalString(parsed.branchName, "branchName"),
|
|
84
|
+
changedTargets: ensureStringArray(parsed.changedTargets, "changedTargets"),
|
|
85
|
+
engineerRunId: ensureString(parsed.engineerRunId, "engineerRunId")
|
|
86
|
+
};
|
|
87
|
+
case "task_waiting":
|
|
88
|
+
return {
|
|
89
|
+
blockingReason: ensureString(parsed.blockingReason, "blockingReason"),
|
|
90
|
+
engineerRunId: ensureString(parsed.engineerRunId, "engineerRunId")
|
|
91
|
+
};
|
|
92
|
+
case "task_failed":
|
|
93
|
+
return {
|
|
94
|
+
failureSummary: ensureString(parsed.failureSummary, "failureSummary"),
|
|
95
|
+
engineerRunId: ensureString(parsed.engineerRunId, "engineerRunId")
|
|
96
|
+
};
|
|
97
|
+
case "task_verified":
|
|
98
|
+
return {
|
|
99
|
+
branchName: ensureOptionalString(parsed.branchName, "branchName"),
|
|
100
|
+
reviewerRunId: ensureString(parsed.reviewerRunId, "reviewerRunId")
|
|
101
|
+
};
|
|
102
|
+
case "review_failed":
|
|
103
|
+
return {
|
|
104
|
+
failureSummary: ensureString(parsed.failureSummary, "failureSummary"),
|
|
105
|
+
reviewerRunId: ensureString(parsed.reviewerRunId, "reviewerRunId")
|
|
106
|
+
};
|
|
107
|
+
case "review_waiting":
|
|
108
|
+
return {
|
|
109
|
+
blockingReason: ensureString(parsed.blockingReason, "blockingReason"),
|
|
110
|
+
reviewerRunId: ensureString(parsed.reviewerRunId, "reviewerRunId")
|
|
111
|
+
};
|
|
112
|
+
case "release_started":
|
|
113
|
+
return {
|
|
114
|
+
taskRunId: ensureOptionalString(parsed.taskRunId, "taskRunId"),
|
|
115
|
+
releaserRunId: ensureString(parsed.releaserRunId, "releaserRunId")
|
|
116
|
+
};
|
|
117
|
+
case "release_completed":
|
|
118
|
+
return {
|
|
119
|
+
releaseSummary: ensureString(parsed.releaseSummary, "releaseSummary"),
|
|
120
|
+
releaserRunId: ensureString(parsed.releaserRunId, "releaserRunId")
|
|
121
|
+
};
|
|
122
|
+
case "release_failed":
|
|
123
|
+
return {
|
|
124
|
+
failureSummary: ensureString(parsed.failureSummary, "failureSummary"),
|
|
125
|
+
releaserRunId: ensureString(parsed.releaserRunId, "releaserRunId")
|
|
126
|
+
};
|
|
127
|
+
default:
|
|
128
|
+
throw new Error(`Unknown agent message type "${String(type)}".`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function serializeAgentMessagePayload(type, payload) {
|
|
132
|
+
parseAgentMessagePayload(type, JSON.stringify(payload));
|
|
133
|
+
return JSON.stringify(payload);
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
AGENT_MESSAGE_TYPES,
|
|
137
|
+
parseAgentMessagePayload,
|
|
138
|
+
serializeAgentMessagePayload
|
|
139
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type AgentErrorCategory = 'trigger_resolution_error' | 'permission_error' | 'message_claim_error' | 'lease_error' | 'execution_error' | 'mutation_error' | 'sdk_error';
|
|
2
|
+
export interface AgentRunTrace {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
runId: string;
|
|
5
|
+
agentSlug: string;
|
|
6
|
+
handlerKind: string;
|
|
7
|
+
triggerKind: string;
|
|
8
|
+
triggerSource: string;
|
|
9
|
+
claimedMessageId: number | null;
|
|
10
|
+
selectedItemKey: string | null;
|
|
11
|
+
branchName: string | null;
|
|
12
|
+
commitSha: string | null;
|
|
13
|
+
changedPaths: string[];
|
|
14
|
+
summary: string | null;
|
|
15
|
+
error: string | null;
|
|
16
|
+
errorCategory: AgentErrorCategory | null;
|
|
17
|
+
startedAt: string;
|
|
18
|
+
finishedAt: string | null;
|
|
19
|
+
status: string;
|
|
20
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { AgentHandlerKind, AgentRuntimeSpec, AgentRunStatus, AgentTriggerConfig } from '../../types/agents.ts';
|
|
2
|
+
import type { AgentErrorCategory } from './contracts/run.ts';
|
|
3
|
+
import type { ScopedAgentSdk, SdkMessageEntity } from '../../sdk.ts';
|
|
4
|
+
export interface AgentTriggerInvocation {
|
|
5
|
+
kind: 'startup' | 'schedule' | 'message' | 'manual' | 'follow';
|
|
6
|
+
source: string;
|
|
7
|
+
trigger: AgentTriggerConfig;
|
|
8
|
+
message?: SdkMessageEntity | null;
|
|
9
|
+
followModels?: string[];
|
|
10
|
+
cursorValue?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export interface AgentExecutionResult {
|
|
13
|
+
status: AgentRunStatus;
|
|
14
|
+
summary: string;
|
|
15
|
+
stdout?: string;
|
|
16
|
+
stderr?: string;
|
|
17
|
+
errorCategory?: AgentErrorCategory | null;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentMutationResult {
|
|
21
|
+
branchName: string | null;
|
|
22
|
+
commitMessage: string | null;
|
|
23
|
+
worktreePath: string | null;
|
|
24
|
+
commitSha: string | null;
|
|
25
|
+
changedPaths: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface AgentRepositoryInspectionResult {
|
|
28
|
+
branchName: string | null;
|
|
29
|
+
changedPaths: string[];
|
|
30
|
+
commitSha: string | null;
|
|
31
|
+
summary: string;
|
|
32
|
+
}
|
|
33
|
+
export interface AgentVerificationResult {
|
|
34
|
+
status: 'completed' | 'failed' | 'waiting';
|
|
35
|
+
summary: string;
|
|
36
|
+
stdout?: string;
|
|
37
|
+
stderr?: string;
|
|
38
|
+
errorCategory?: AgentErrorCategory | null;
|
|
39
|
+
}
|
|
40
|
+
export interface AgentNotificationResult {
|
|
41
|
+
status: 'completed' | 'failed' | 'waiting';
|
|
42
|
+
summary: string;
|
|
43
|
+
deliveredCount: number;
|
|
44
|
+
}
|
|
45
|
+
export interface AgentResearchResult {
|
|
46
|
+
status: 'completed' | 'failed' | 'waiting';
|
|
47
|
+
summary: string;
|
|
48
|
+
markdown: string;
|
|
49
|
+
sources?: string[];
|
|
50
|
+
errorCategory?: AgentErrorCategory | null;
|
|
51
|
+
}
|
|
52
|
+
export interface AgentExecutionAdapter {
|
|
53
|
+
runTask(input: {
|
|
54
|
+
agent: AgentRuntimeSpec;
|
|
55
|
+
runId: string;
|
|
56
|
+
prompt: string;
|
|
57
|
+
}): Promise<AgentExecutionResult>;
|
|
58
|
+
}
|
|
59
|
+
export interface AgentMutationAdapter {
|
|
60
|
+
writeArtifact(input: {
|
|
61
|
+
runId: string;
|
|
62
|
+
agent: AgentRuntimeSpec;
|
|
63
|
+
relativePath: string;
|
|
64
|
+
content: string;
|
|
65
|
+
commitMessage: string;
|
|
66
|
+
}): Promise<AgentMutationResult>;
|
|
67
|
+
}
|
|
68
|
+
export interface AgentRepositoryInspectionAdapter {
|
|
69
|
+
inspectBranch(input: {
|
|
70
|
+
repoRoot: string;
|
|
71
|
+
branchName: string | null;
|
|
72
|
+
}): Promise<AgentRepositoryInspectionResult>;
|
|
73
|
+
}
|
|
74
|
+
export interface AgentVerificationAdapter {
|
|
75
|
+
runChecks(input: {
|
|
76
|
+
agent: AgentRuntimeSpec;
|
|
77
|
+
runId: string;
|
|
78
|
+
commands: string[];
|
|
79
|
+
}): Promise<AgentVerificationResult>;
|
|
80
|
+
}
|
|
81
|
+
export interface AgentNotificationAdapter {
|
|
82
|
+
deliver(input: {
|
|
83
|
+
agent: AgentRuntimeSpec;
|
|
84
|
+
runId: string;
|
|
85
|
+
recipients: string[];
|
|
86
|
+
subject: string;
|
|
87
|
+
body: string;
|
|
88
|
+
}): Promise<AgentNotificationResult>;
|
|
89
|
+
}
|
|
90
|
+
export interface AgentResearchAdapter {
|
|
91
|
+
research(input: {
|
|
92
|
+
agent: AgentRuntimeSpec;
|
|
93
|
+
runId: string;
|
|
94
|
+
questionId: string;
|
|
95
|
+
reason: string | null;
|
|
96
|
+
}): Promise<AgentResearchResult>;
|
|
97
|
+
}
|
|
98
|
+
export interface AgentContext {
|
|
99
|
+
runId: string;
|
|
100
|
+
repoRoot: string;
|
|
101
|
+
agent: AgentRuntimeSpec;
|
|
102
|
+
sdk: ScopedAgentSdk;
|
|
103
|
+
trigger: AgentTriggerInvocation;
|
|
104
|
+
execution: AgentExecutionAdapter;
|
|
105
|
+
mutations: AgentMutationAdapter;
|
|
106
|
+
repository: AgentRepositoryInspectionAdapter;
|
|
107
|
+
verification: AgentVerificationAdapter;
|
|
108
|
+
notifications: AgentNotificationAdapter;
|
|
109
|
+
research: AgentResearchAdapter;
|
|
110
|
+
}
|
|
111
|
+
export interface AgentHandler<TInputs = unknown, TResult = unknown> {
|
|
112
|
+
kind: AgentHandlerKind;
|
|
113
|
+
resolveInputs(context: AgentContext): Promise<TInputs>;
|
|
114
|
+
execute(context: AgentContext, inputs: TInputs): Promise<TResult>;
|
|
115
|
+
emitOutputs(context: AgentContext, result: TResult): Promise<AgentExecutionResult>;
|
|
116
|
+
}
|
|
117
|
+
export declare const TRESEED_AGENT_RUNTIME_TYPES_MODULE = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@treeseed/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -102,6 +102,10 @@
|
|
|
102
102
|
"types": "./dist/platform/deploy-config.d.ts",
|
|
103
103
|
"default": "./dist/platform/deploy-config.js"
|
|
104
104
|
},
|
|
105
|
+
"./platform/deploy-runtime": {
|
|
106
|
+
"types": "./dist/platform/deploy-runtime.d.ts",
|
|
107
|
+
"default": "./dist/platform/deploy-runtime.js"
|
|
108
|
+
},
|
|
105
109
|
"./platform/environment": {
|
|
106
110
|
"types": "./dist/platform/environment.d.ts",
|
|
107
111
|
"default": "./dist/platform/environment.js"
|
|
@@ -217,6 +221,18 @@
|
|
|
217
221
|
"./stores/subscription-store": {
|
|
218
222
|
"types": "./dist/stores/subscription-store.d.ts",
|
|
219
223
|
"default": "./dist/stores/subscription-store.js"
|
|
224
|
+
},
|
|
225
|
+
"./utils/agents/runtime-types": {
|
|
226
|
+
"types": "./dist/utils/agents/runtime-types.d.ts",
|
|
227
|
+
"default": "./dist/utils/agents/runtime-types.js"
|
|
228
|
+
},
|
|
229
|
+
"./utils/agents/contracts/messages": {
|
|
230
|
+
"types": "./dist/utils/agents/contracts/messages.d.ts",
|
|
231
|
+
"default": "./dist/utils/agents/contracts/messages.js"
|
|
232
|
+
},
|
|
233
|
+
"./utils/agents/contracts/run": {
|
|
234
|
+
"types": "./dist/utils/agents/contracts/run.d.ts",
|
|
235
|
+
"default": "./dist/utils/agents/contracts/run.js"
|
|
220
236
|
}
|
|
221
237
|
}
|
|
222
238
|
}
|
|
File without changes
|