@treeseed/sdk 0.4.7 → 0.4.9
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 -1
- package/dist/dispatch.d.ts +4 -0
- package/dist/dispatch.js +180 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +25 -3
- package/dist/operations/providers/default.js +1 -0
- package/dist/operations/services/config-runtime.d.ts +121 -26
- package/dist/operations/services/config-runtime.js +332 -198
- package/dist/operations/services/deploy.d.ts +0 -3
- package/dist/operations/services/deploy.js +1 -1
- package/dist/operations/services/export-runtime.d.ts +18 -0
- package/dist/operations/services/export-runtime.js +136 -0
- package/dist/operations/services/railway-deploy.js +2 -2
- package/dist/operations/services/runtime-tools.d.ts +0 -1
- package/dist/operations/services/runtime-tools.js +1 -2
- package/dist/operations-registry.js +1 -0
- package/dist/operations-types.d.ts +1 -1
- package/dist/platform/book-export.d.ts +78 -0
- package/dist/platform/book-export.js +449 -0
- package/dist/platform/contracts.d.ts +6 -2
- package/dist/platform/deploy-config.d.ts +2 -0
- package/dist/platform/deploy-config.js +30 -2
- package/dist/platform/env.yaml +5 -0
- package/dist/platform/environment.d.ts +10 -1
- package/dist/platform/environment.js +82 -6
- package/dist/remote.d.ts +65 -9
- package/dist/remote.js +104 -28
- package/dist/scripts/aggregate-book.js +13 -118
- package/dist/scripts/config-treeseed.js +18 -27
- package/dist/sdk-dispatch.d.ts +12 -0
- package/dist/sdk-dispatch.js +142 -0
- package/dist/sdk-types.d.ts +137 -4
- package/dist/sdk-types.js +16 -0
- package/dist/sdk.d.ts +7 -1
- package/dist/sdk.js +69 -0
- package/dist/workflow/operations.d.ts +59 -15
- package/dist/workflow/operations.js +61 -81
- package/dist/workflow-state.js +2 -1
- package/dist/workflow-support.d.ts +2 -1
- package/dist/workflow-support.js +14 -6
- package/dist/workflow.d.ts +11 -1
- package/dist/workflow.js +6 -0
- package/package.json +6 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
function passthrough(methodName) {
|
|
2
|
+
return (sdk, input) => sdk[methodName](input);
|
|
3
|
+
}
|
|
4
|
+
const SDK_OPERATION_SPECS = [
|
|
5
|
+
{ name: "get", handler: passthrough("get") },
|
|
6
|
+
{ name: "read", handler: passthrough("read") },
|
|
7
|
+
{ name: "search", handler: passthrough("search") },
|
|
8
|
+
{ name: "follow", handler: passthrough("follow") },
|
|
9
|
+
{ name: "pick", handler: passthrough("pick") },
|
|
10
|
+
{ name: "create", handler: passthrough("create") },
|
|
11
|
+
{ name: "update", handler: passthrough("update") },
|
|
12
|
+
{ name: "claimMessage", aliases: ["claim-message"], handler: passthrough("claimMessage") },
|
|
13
|
+
{ name: "ackMessage", aliases: ["ack-message"], handler: passthrough("ackMessage") },
|
|
14
|
+
{ name: "createMessage", aliases: ["create-message"], handler: passthrough("createMessage") },
|
|
15
|
+
{ name: "recordRun", aliases: ["record-run"], handler: passthrough("recordRun") },
|
|
16
|
+
{ name: "getCursor", aliases: ["get-cursor"], handler: passthrough("getCursor") },
|
|
17
|
+
{ name: "upsertCursor", aliases: ["upsert-cursor"], handler: passthrough("upsertCursor") },
|
|
18
|
+
{ name: "releaseLease", aliases: ["release-lease"], handler: passthrough("releaseLease") },
|
|
19
|
+
{
|
|
20
|
+
name: "releaseAllLeases",
|
|
21
|
+
aliases: ["release-all-leases"],
|
|
22
|
+
handler: (sdk) => sdk.releaseAllLeases()
|
|
23
|
+
},
|
|
24
|
+
{ name: "startWorkDay", aliases: ["start-work-day"], handler: passthrough("startWorkDay") },
|
|
25
|
+
{ name: "closeWorkDay", aliases: ["close-work-day"], handler: passthrough("closeWorkDay") },
|
|
26
|
+
{ name: "createTask", aliases: ["create-task"], handler: passthrough("createTask") },
|
|
27
|
+
{ name: "claimTask", aliases: ["claim-task"], handler: passthrough("claimTask") },
|
|
28
|
+
{
|
|
29
|
+
name: "recordTaskProgress",
|
|
30
|
+
aliases: ["record-task-progress"],
|
|
31
|
+
handler: passthrough("recordTaskProgress")
|
|
32
|
+
},
|
|
33
|
+
{ name: "completeTask", aliases: ["complete-task"], handler: passthrough("completeTask") },
|
|
34
|
+
{ name: "failTask", aliases: ["fail-task"], handler: passthrough("failTask") },
|
|
35
|
+
{ name: "appendTaskEvent", aliases: ["append-task-event"], handler: passthrough("appendTaskEvent") },
|
|
36
|
+
{ name: "searchTasks", aliases: ["search-tasks"], handler: passthrough("searchTasks") },
|
|
37
|
+
{
|
|
38
|
+
name: "getManagerContext",
|
|
39
|
+
aliases: ["get-manager-context"],
|
|
40
|
+
handler: (sdk, input) => sdk.getManagerContext(String(input.taskId ?? input.id ?? ""))
|
|
41
|
+
},
|
|
42
|
+
{ name: "createReport", aliases: ["create-report"], handler: passthrough("createReport") },
|
|
43
|
+
{
|
|
44
|
+
name: "listAgentSpecs",
|
|
45
|
+
aliases: ["list-agent-specs"],
|
|
46
|
+
handler: (sdk, input) => sdk.listAgentSpecs(input)
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "listRawAgentSpecs",
|
|
50
|
+
aliases: ["list-raw-agent-specs"],
|
|
51
|
+
handler: (sdk, input) => sdk.listRawAgentSpecs(input)
|
|
52
|
+
},
|
|
53
|
+
{ name: "refreshGraph", aliases: ["refresh-graph"], handler: passthrough("refreshGraph") },
|
|
54
|
+
{
|
|
55
|
+
name: "searchFiles",
|
|
56
|
+
aliases: ["search-files"],
|
|
57
|
+
handler: (sdk, input) => sdk.searchFiles(String(input.query ?? ""), input.options)
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "searchSections",
|
|
61
|
+
aliases: ["search-sections"],
|
|
62
|
+
handler: (sdk, input) => sdk.searchSections(String(input.query ?? ""), input.options)
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "searchEntities",
|
|
66
|
+
aliases: ["search-entities"],
|
|
67
|
+
handler: (sdk, input) => sdk.searchEntities(String(input.query ?? ""), input.options)
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "getGraphNode",
|
|
71
|
+
aliases: ["get-graph-node"],
|
|
72
|
+
handler: (sdk, input) => sdk.getGraphNode(String(input.id ?? ""))
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: "getNeighbors",
|
|
76
|
+
aliases: ["get-neighbors"],
|
|
77
|
+
handler: (sdk, input) => sdk.getNeighbors(String(input.id ?? ""), input.options)
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "followReferences",
|
|
81
|
+
aliases: ["follow-references"],
|
|
82
|
+
handler: (sdk, input) => sdk.followReferences(String(input.id ?? ""), input.options)
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "getBacklinks",
|
|
86
|
+
aliases: ["get-backlinks"],
|
|
87
|
+
handler: (sdk, input) => sdk.getBacklinks(String(input.id ?? ""), input.options)
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "getRelated",
|
|
91
|
+
aliases: ["get-related"],
|
|
92
|
+
handler: (sdk, input) => sdk.getRelated(String(input.id ?? ""), input.options)
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "getSubgraph",
|
|
96
|
+
aliases: ["get-subgraph"],
|
|
97
|
+
handler: (sdk, input) => sdk.getSubgraph(Array.isArray(input.seedIds) ? input.seedIds.map(String) : [], input.options)
|
|
98
|
+
},
|
|
99
|
+
{ name: "resolveSeeds", aliases: ["resolve-seeds"], handler: passthrough("resolveSeeds") },
|
|
100
|
+
{ name: "queryGraph", aliases: ["query-graph"], handler: passthrough("queryGraph") },
|
|
101
|
+
{ name: "buildContextPack", aliases: ["build-context-pack"], handler: passthrough("buildContextPack") },
|
|
102
|
+
{
|
|
103
|
+
name: "parseGraphDsl",
|
|
104
|
+
aliases: ["parse-graph-dsl"],
|
|
105
|
+
handler: (sdk, input) => sdk.parseGraphDsl(String(input.source ?? input.query ?? ""))
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
name: "resolveReference",
|
|
109
|
+
aliases: ["resolve-reference"],
|
|
110
|
+
handler: (sdk, input) => sdk.resolveReference(String(input.reference ?? ""), input.options)
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "explainReferenceChain",
|
|
114
|
+
aliases: ["explain-reference-chain"],
|
|
115
|
+
handler: (sdk, input) => sdk.explainReferenceChain(String(input.fromId ?? ""), String(input.toId ?? ""))
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
const SDK_OPERATION_INDEX = /* @__PURE__ */ new Map();
|
|
119
|
+
for (const spec of SDK_OPERATION_SPECS) {
|
|
120
|
+
SDK_OPERATION_INDEX.set(spec.name, spec);
|
|
121
|
+
for (const alias of spec.aliases ?? []) {
|
|
122
|
+
SDK_OPERATION_INDEX.set(alias, spec);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function listSdkOperationNames() {
|
|
126
|
+
return [...new Set(SDK_OPERATION_SPECS.map((entry) => entry.name))];
|
|
127
|
+
}
|
|
128
|
+
function findSdkOperation(name) {
|
|
129
|
+
return SDK_OPERATION_INDEX.get(name) ?? null;
|
|
130
|
+
}
|
|
131
|
+
async function executeSdkOperation(sdk, operationName, input) {
|
|
132
|
+
const spec = findSdkOperation(operationName);
|
|
133
|
+
if (!spec) {
|
|
134
|
+
throw new Error(`Unknown SDK operation "${operationName}".`);
|
|
135
|
+
}
|
|
136
|
+
return await spec.handler(sdk, input);
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
executeSdkOperation,
|
|
140
|
+
findSdkOperation,
|
|
141
|
+
listSdkOperationNames
|
|
142
|
+
};
|
package/dist/sdk-types.d.ts
CHANGED
|
@@ -3,12 +3,139 @@ export declare const SDK_MODEL_NAMES: readonly ["page", "note", "question", "boo
|
|
|
3
3
|
export declare const SDK_OPERATIONS: readonly ["get", "read", "search", "follow", "pick", "create", "update"];
|
|
4
4
|
export declare const SDK_STORAGE_BACKENDS: readonly ["content", "d1"];
|
|
5
5
|
export declare const SDK_PICK_STRATEGIES: readonly ["latest", "highest_priority", "oldest"];
|
|
6
|
+
export declare const SDK_DISPATCH_EXECUTION_CLASSES: readonly ["local_only", "remote_inline", "remote_job"];
|
|
7
|
+
export declare const SDK_DISPATCH_TARGETS: readonly ["local", "project_api", "project_runner", "market_catalog"];
|
|
8
|
+
export declare const SDK_DISPATCH_POLICIES: readonly ["auto", "prefer_local", "prefer_remote", "remote_only"];
|
|
9
|
+
export declare const SDK_DISPATCH_NAMESPACES: readonly ["sdk", "workflow"];
|
|
10
|
+
export declare const PROJECT_CONNECTION_MODES: readonly ["hosted", "self_hosted", "hybrid"];
|
|
11
|
+
export declare const PROJECT_RUNNER_REGISTRATION_STATES: readonly ["pending", "registered", "offline"];
|
|
12
|
+
export declare const PROJECT_EXECUTION_OWNERS: readonly ["project_api", "project_runner", "market"];
|
|
13
|
+
export declare const REMOTE_JOB_STATUSES: readonly ["pending", "claimed", "running", "completed", "failed", "cancelled"];
|
|
6
14
|
export type SdkBuiltinModelName = (typeof SDK_MODEL_NAMES)[number];
|
|
7
15
|
export type SdkModelName = SdkBuiltinModelName | (string & {});
|
|
8
16
|
export type SdkOperation = (typeof SDK_OPERATIONS)[number];
|
|
9
17
|
export type SdkStorageBackend = (typeof SDK_STORAGE_BACKENDS)[number];
|
|
10
18
|
export type SdkPickStrategy = (typeof SDK_PICK_STRATEGIES)[number];
|
|
11
19
|
export type SdkComparableAs = 'string' | 'number' | 'date' | 'boolean' | 'string_array';
|
|
20
|
+
export type SdkDispatchExecutionClass = (typeof SDK_DISPATCH_EXECUTION_CLASSES)[number];
|
|
21
|
+
export type SdkDispatchTarget = (typeof SDK_DISPATCH_TARGETS)[number];
|
|
22
|
+
export type SdkDispatchPolicy = (typeof SDK_DISPATCH_POLICIES)[number];
|
|
23
|
+
export type SdkDispatchNamespace = (typeof SDK_DISPATCH_NAMESPACES)[number];
|
|
24
|
+
export type ProjectConnectionMode = (typeof PROJECT_CONNECTION_MODES)[number];
|
|
25
|
+
export type ProjectRunnerRegistrationState = (typeof PROJECT_RUNNER_REGISTRATION_STATES)[number];
|
|
26
|
+
export type ProjectExecutionOwner = (typeof PROJECT_EXECUTION_OWNERS)[number];
|
|
27
|
+
export type RemoteJobStatus = (typeof REMOTE_JOB_STATUSES)[number];
|
|
28
|
+
export type RemoteJobRequestedByType = 'user' | 'team_api_key' | 'service' | 'runner' | 'system';
|
|
29
|
+
export interface SdkDispatchCapability {
|
|
30
|
+
namespace: SdkDispatchNamespace;
|
|
31
|
+
operation: string;
|
|
32
|
+
executionClass: SdkDispatchExecutionClass;
|
|
33
|
+
allowedTargets: SdkDispatchTarget[];
|
|
34
|
+
defaultTarget: SdkDispatchTarget;
|
|
35
|
+
defaultDispatchMode: SdkDispatchPolicy;
|
|
36
|
+
summary?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface ProjectConnection {
|
|
39
|
+
id: string;
|
|
40
|
+
projectId: string;
|
|
41
|
+
mode: ProjectConnectionMode;
|
|
42
|
+
projectApiBaseUrl: string | null;
|
|
43
|
+
runnerRegistrationState: ProjectRunnerRegistrationState;
|
|
44
|
+
executionOwner: ProjectExecutionOwner;
|
|
45
|
+
runnerRegisteredAt: string | null;
|
|
46
|
+
runnerLastSeenAt: string | null;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
updatedAt: string;
|
|
49
|
+
metadata?: Record<string, unknown>;
|
|
50
|
+
}
|
|
51
|
+
export interface ProjectCapabilityGrant {
|
|
52
|
+
id: string;
|
|
53
|
+
projectId: string;
|
|
54
|
+
namespace: SdkDispatchNamespace;
|
|
55
|
+
operation: string;
|
|
56
|
+
executionClass: SdkDispatchExecutionClass;
|
|
57
|
+
allowedTargets: SdkDispatchTarget[];
|
|
58
|
+
defaultDispatchMode: SdkDispatchPolicy;
|
|
59
|
+
enabled: boolean;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
updatedAt: string;
|
|
62
|
+
}
|
|
63
|
+
export interface RemoteJobError {
|
|
64
|
+
code?: string | null;
|
|
65
|
+
message: string;
|
|
66
|
+
}
|
|
67
|
+
export interface RemoteJob {
|
|
68
|
+
id: string;
|
|
69
|
+
projectId: string;
|
|
70
|
+
namespace: SdkDispatchNamespace;
|
|
71
|
+
operation: string;
|
|
72
|
+
status: RemoteJobStatus;
|
|
73
|
+
preferredMode: SdkDispatchPolicy;
|
|
74
|
+
selectedTarget: SdkDispatchTarget;
|
|
75
|
+
input: Record<string, unknown>;
|
|
76
|
+
output?: unknown;
|
|
77
|
+
error?: RemoteJobError | null;
|
|
78
|
+
requestedByType: RemoteJobRequestedByType;
|
|
79
|
+
requestedById: string | null;
|
|
80
|
+
assignedRunnerId: string | null;
|
|
81
|
+
idempotencyKey: string | null;
|
|
82
|
+
capability?: SdkDispatchCapability | null;
|
|
83
|
+
pollUrl?: string | null;
|
|
84
|
+
streamUrl?: string | null;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
startedAt: string | null;
|
|
88
|
+
finishedAt: string | null;
|
|
89
|
+
cancelledAt: string | null;
|
|
90
|
+
}
|
|
91
|
+
export interface RemoteJobEvent {
|
|
92
|
+
id: string;
|
|
93
|
+
jobId: string;
|
|
94
|
+
seq: number;
|
|
95
|
+
kind: string;
|
|
96
|
+
data?: Record<string, unknown>;
|
|
97
|
+
createdAt: string;
|
|
98
|
+
}
|
|
99
|
+
export interface SdkDispatchRequest {
|
|
100
|
+
namespace?: SdkDispatchNamespace;
|
|
101
|
+
operation: string;
|
|
102
|
+
input?: Record<string, unknown>;
|
|
103
|
+
preferredMode?: SdkDispatchPolicy;
|
|
104
|
+
idempotencyKey?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface SdkDispatchInlineResult {
|
|
107
|
+
ok: true;
|
|
108
|
+
mode: 'inline';
|
|
109
|
+
namespace: SdkDispatchNamespace;
|
|
110
|
+
operation: string;
|
|
111
|
+
target: SdkDispatchTarget;
|
|
112
|
+
capability: SdkDispatchCapability;
|
|
113
|
+
payload: unknown;
|
|
114
|
+
}
|
|
115
|
+
export interface SdkDispatchJobResult {
|
|
116
|
+
ok: true;
|
|
117
|
+
mode: 'job';
|
|
118
|
+
namespace: SdkDispatchNamespace;
|
|
119
|
+
operation: string;
|
|
120
|
+
target: SdkDispatchTarget;
|
|
121
|
+
capability: SdkDispatchCapability;
|
|
122
|
+
job: RemoteJob;
|
|
123
|
+
}
|
|
124
|
+
export type SdkDispatchResult = SdkDispatchInlineResult | SdkDispatchJobResult;
|
|
125
|
+
export type SdkDispatchCredentialSource = {
|
|
126
|
+
type: 'bearer';
|
|
127
|
+
token: string;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'resolver';
|
|
130
|
+
resolveToken: () => Promise<string | null> | string | null;
|
|
131
|
+
};
|
|
132
|
+
export interface SdkDispatchConfig {
|
|
133
|
+
projectId: string;
|
|
134
|
+
marketBaseUrl: string;
|
|
135
|
+
policy?: SdkDispatchPolicy;
|
|
136
|
+
credentialSource?: SdkDispatchCredentialSource;
|
|
137
|
+
fetchImpl?: typeof fetch;
|
|
138
|
+
}
|
|
12
139
|
export type SdkFilterOperator = 'eq' | 'in' | 'contains' | 'prefix' | 'gt' | 'gte' | 'lt' | 'lte' | 'updated_since' | 'related_to';
|
|
13
140
|
export type TreeseedSchemaVersion = number;
|
|
14
141
|
export type TreeseedRuntimeRecordType = 'subscription' | 'contact_submission' | 'agent_run' | 'message' | 'agent_cursor' | 'content_lease' | 'work_day' | 'task' | 'task_event' | 'task_output' | 'graph_run' | 'report';
|
|
@@ -701,12 +828,14 @@ export interface SdkManagerContextPayload {
|
|
|
701
828
|
agent: Record<string, unknown> | null;
|
|
702
829
|
graph: Record<string, unknown> | null;
|
|
703
830
|
}
|
|
704
|
-
export interface
|
|
705
|
-
|
|
706
|
-
|
|
831
|
+
export interface SdkQueuePullClientConfig {
|
|
832
|
+
accountId: string;
|
|
833
|
+
queueId: string;
|
|
834
|
+
token: string;
|
|
835
|
+
apiBaseUrl?: string;
|
|
707
836
|
fetchImpl?: typeof fetch;
|
|
708
837
|
}
|
|
709
|
-
export interface
|
|
838
|
+
export interface SdkQueuePushClientConfig {
|
|
710
839
|
accountId: string;
|
|
711
840
|
queueId: string;
|
|
712
841
|
token: string;
|
|
@@ -738,6 +867,10 @@ export interface SdkPulledQueueMessage {
|
|
|
738
867
|
export interface SdkQueuePullResult {
|
|
739
868
|
messages: SdkPulledQueueMessage[];
|
|
740
869
|
}
|
|
870
|
+
export interface SdkQueuePushRequest {
|
|
871
|
+
message: SdkQueueMessageEnvelope;
|
|
872
|
+
delaySeconds?: number;
|
|
873
|
+
}
|
|
741
874
|
export interface SdkFollowResult<TItem> {
|
|
742
875
|
items: TItem[];
|
|
743
876
|
since: string;
|
package/dist/sdk-types.js
CHANGED
|
@@ -22,7 +22,23 @@ const SDK_MODEL_NAMES = [
|
|
|
22
22
|
const SDK_OPERATIONS = ["get", "read", "search", "follow", "pick", "create", "update"];
|
|
23
23
|
const SDK_STORAGE_BACKENDS = ["content", "d1"];
|
|
24
24
|
const SDK_PICK_STRATEGIES = ["latest", "highest_priority", "oldest"];
|
|
25
|
+
const SDK_DISPATCH_EXECUTION_CLASSES = ["local_only", "remote_inline", "remote_job"];
|
|
26
|
+
const SDK_DISPATCH_TARGETS = ["local", "project_api", "project_runner", "market_catalog"];
|
|
27
|
+
const SDK_DISPATCH_POLICIES = ["auto", "prefer_local", "prefer_remote", "remote_only"];
|
|
28
|
+
const SDK_DISPATCH_NAMESPACES = ["sdk", "workflow"];
|
|
29
|
+
const PROJECT_CONNECTION_MODES = ["hosted", "self_hosted", "hybrid"];
|
|
30
|
+
const PROJECT_RUNNER_REGISTRATION_STATES = ["pending", "registered", "offline"];
|
|
31
|
+
const PROJECT_EXECUTION_OWNERS = ["project_api", "project_runner", "market"];
|
|
32
|
+
const REMOTE_JOB_STATUSES = ["pending", "claimed", "running", "completed", "failed", "cancelled"];
|
|
25
33
|
export {
|
|
34
|
+
PROJECT_CONNECTION_MODES,
|
|
35
|
+
PROJECT_EXECUTION_OWNERS,
|
|
36
|
+
PROJECT_RUNNER_REGISTRATION_STATES,
|
|
37
|
+
REMOTE_JOB_STATUSES,
|
|
38
|
+
SDK_DISPATCH_EXECUTION_CLASSES,
|
|
39
|
+
SDK_DISPATCH_NAMESPACES,
|
|
40
|
+
SDK_DISPATCH_POLICIES,
|
|
41
|
+
SDK_DISPATCH_TARGETS,
|
|
26
42
|
SDK_MODEL_NAMES,
|
|
27
43
|
SDK_OPERATIONS,
|
|
28
44
|
SDK_PICK_STRATEGIES,
|
package/dist/sdk.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { AgentPermissionConfig, AgentRuntimeSpec } from './types/agents.ts'
|
|
|
2
2
|
import { ContentStore } from './content-store.ts';
|
|
3
3
|
import { type AgentDatabase } from './d1-store.ts';
|
|
4
4
|
import { type LoadedTreeseedPluginEntry } from './platform/plugins.ts';
|
|
5
|
-
import type { SdkAckMessageRequest, SdkClaimMessageRequest, SdkClaimTaskRequest, SdkCloseWorkDayRequest, SdkCompleteTaskRequest, SdkCreateReportRequest, SdkCreateMessageRequest, SdkCreateTaskRequest, SdkCursorRequest, SdkFailTaskRequest, SdkFollowRequest, SdkGetRequest, SdkGetCursorRequest, SdkJsonEnvelope, SdkLeaseReleaseRequest, SdkManagerContextPayload, SdkMutationRequest, SdkGraphQueryOptions, SdkGraphQueryRequest, SdkGraphRefreshRequest, SdkGraphSearchOptions, SdkContextPackRequest, SdkGraphDslParseResult, SdkPickRequest, SdkRecordRunRequest, SdkSearchRequest, SdkStartWorkDayRequest, SdkTaskProgressRequest, SdkTaskSearchRequest, SdkUpdateRequest, SdkModelDefinition, SdkModelRegistry, SdkGraphRankingProvider } from './sdk-types.ts';
|
|
5
|
+
import type { SdkAckMessageRequest, SdkClaimMessageRequest, SdkClaimTaskRequest, SdkCloseWorkDayRequest, SdkCompleteTaskRequest, SdkCreateReportRequest, SdkCreateMessageRequest, SdkCreateTaskRequest, SdkCursorRequest, SdkFailTaskRequest, SdkFollowRequest, SdkGetRequest, SdkGetCursorRequest, SdkJsonEnvelope, SdkLeaseReleaseRequest, SdkManagerContextPayload, SdkMutationRequest, SdkGraphQueryOptions, SdkGraphQueryRequest, SdkGraphRefreshRequest, SdkGraphSearchOptions, SdkContextPackRequest, SdkGraphDslParseResult, SdkPickRequest, SdkRecordRunRequest, SdkSearchRequest, SdkStartWorkDayRequest, SdkTaskProgressRequest, SdkTaskSearchRequest, SdkUpdateRequest, SdkModelDefinition, SdkModelRegistry, SdkGraphRankingProvider, SdkDispatchConfig, SdkDispatchRequest, SdkDispatchResult } from './sdk-types.ts';
|
|
6
6
|
export interface AgentSdkOptions {
|
|
7
7
|
repoRoot?: string;
|
|
8
8
|
database?: AgentDatabase;
|
|
@@ -10,12 +10,15 @@ export interface AgentSdkOptions {
|
|
|
10
10
|
modelRegistry?: SdkModelRegistry;
|
|
11
11
|
graphRankingProvider?: SdkGraphRankingProvider;
|
|
12
12
|
plugins?: LoadedTreeseedPluginEntry[];
|
|
13
|
+
dispatch?: SdkDispatchConfig;
|
|
13
14
|
}
|
|
14
15
|
export declare class AgentSdk {
|
|
16
|
+
readonly repoRoot: string;
|
|
15
17
|
readonly database: AgentDatabase;
|
|
16
18
|
readonly content: ContentStore;
|
|
17
19
|
readonly models: SdkModelRegistry;
|
|
18
20
|
private readonly graph;
|
|
21
|
+
private readonly dispatchConfig?;
|
|
19
22
|
constructor(options?: AgentSdkOptions);
|
|
20
23
|
static createLocal(options: {
|
|
21
24
|
repoRoot?: string;
|
|
@@ -24,6 +27,9 @@ export declare class AgentSdk {
|
|
|
24
27
|
models?: SdkModelDefinition[];
|
|
25
28
|
modelRegistry?: SdkModelRegistry;
|
|
26
29
|
}): AgentSdk;
|
|
30
|
+
private resolveDispatchToken;
|
|
31
|
+
private executeDispatchLocally;
|
|
32
|
+
dispatch(request: SdkDispatchRequest): Promise<SdkDispatchResult>;
|
|
27
33
|
private envelope;
|
|
28
34
|
get(request: SdkGetRequest): Promise<SdkJsonEnvelope<Record<string, unknown> | import("./sdk-types.ts").SdkContentEntry | null>>;
|
|
29
35
|
read(request: SdkGetRequest): Promise<{
|
package/dist/sdk.js
CHANGED
|
@@ -5,6 +5,10 @@ import { CloudflareD1AgentDatabase, MemoryAgentDatabase } from "./d1-store.js";
|
|
|
5
5
|
import { ContentGraphRuntime } from "./graph.js";
|
|
6
6
|
import { loadTreeseedPlugins } from "./platform/plugins.js";
|
|
7
7
|
import { buildScopedModelRegistry, resolveModelDefinition } from "./model-registry.js";
|
|
8
|
+
import { findDispatchCapability } from "./dispatch.js";
|
|
9
|
+
import { RemoteTreeseedClient, RemoteTreeseedDispatchClient } from "./remote.js";
|
|
10
|
+
import { executeSdkOperation } from "./sdk-dispatch.js";
|
|
11
|
+
import { TreeseedOperationsSdk } from "./operations/runtime.js";
|
|
8
12
|
import { WranglerD1Database } from "./wrangler-d1.js";
|
|
9
13
|
function normalizeAgentSpec(entry) {
|
|
10
14
|
if (!entry) {
|
|
@@ -27,12 +31,15 @@ function operationAllowed(permissions, model, operation) {
|
|
|
27
31
|
);
|
|
28
32
|
}
|
|
29
33
|
class AgentSdk {
|
|
34
|
+
repoRoot;
|
|
30
35
|
database;
|
|
31
36
|
content;
|
|
32
37
|
models;
|
|
33
38
|
graph;
|
|
39
|
+
dispatchConfig;
|
|
34
40
|
constructor(options = {}) {
|
|
35
41
|
const repoRoot = resolveSdkRepoRoot(options.repoRoot);
|
|
42
|
+
this.repoRoot = repoRoot;
|
|
36
43
|
this.models = options.modelRegistry ?? buildScopedModelRegistry(repoRoot, options.models);
|
|
37
44
|
this.database = options.database ?? new MemoryAgentDatabase();
|
|
38
45
|
this.content = new ContentStore(repoRoot, this.database, this.models);
|
|
@@ -48,6 +55,7 @@ class AgentSdk {
|
|
|
48
55
|
rankingProvider: options.graphRankingProvider,
|
|
49
56
|
plugins
|
|
50
57
|
});
|
|
58
|
+
this.dispatchConfig = options.dispatch;
|
|
51
59
|
}
|
|
52
60
|
static createLocal(options) {
|
|
53
61
|
const repoRoot = resolveSdkRepoRoot(options.repoRoot);
|
|
@@ -63,6 +71,67 @@ class AgentSdk {
|
|
|
63
71
|
modelRegistry: options.modelRegistry
|
|
64
72
|
});
|
|
65
73
|
}
|
|
74
|
+
async resolveDispatchToken(source) {
|
|
75
|
+
if (!source) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (source.type === "bearer") {
|
|
79
|
+
return source.token;
|
|
80
|
+
}
|
|
81
|
+
return await source.resolveToken();
|
|
82
|
+
}
|
|
83
|
+
async executeDispatchLocally(request) {
|
|
84
|
+
const namespace = request.namespace ?? "sdk";
|
|
85
|
+
if (namespace === "workflow") {
|
|
86
|
+
const operations = new TreeseedOperationsSdk();
|
|
87
|
+
return operations.execute({
|
|
88
|
+
operationName: request.operation,
|
|
89
|
+
input: request.input ?? {}
|
|
90
|
+
}, {
|
|
91
|
+
cwd: this.repoRoot,
|
|
92
|
+
env: process.env,
|
|
93
|
+
transport: "sdk"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return executeSdkOperation(this, request.operation, request.input ?? {});
|
|
97
|
+
}
|
|
98
|
+
async dispatch(request) {
|
|
99
|
+
const namespace = request.namespace ?? "sdk";
|
|
100
|
+
const capability = findDispatchCapability(namespace, request.operation);
|
|
101
|
+
if (!capability) {
|
|
102
|
+
throw new Error(`Unknown dispatch operation "${namespace}:${request.operation}".`);
|
|
103
|
+
}
|
|
104
|
+
const preferredMode = request.preferredMode ?? this.dispatchConfig?.policy ?? capability.defaultDispatchMode;
|
|
105
|
+
const dispatchConfig = this.dispatchConfig;
|
|
106
|
+
if (!dispatchConfig && preferredMode === "remote_only") {
|
|
107
|
+
throw new Error(`Dispatch for "${namespace}:${request.operation}" requires a remote market configuration.`);
|
|
108
|
+
}
|
|
109
|
+
const shouldStayLocal = capability.executionClass === "local_only" || !dispatchConfig || preferredMode === "prefer_local";
|
|
110
|
+
if (shouldStayLocal) {
|
|
111
|
+
return {
|
|
112
|
+
ok: true,
|
|
113
|
+
mode: "inline",
|
|
114
|
+
namespace,
|
|
115
|
+
operation: request.operation,
|
|
116
|
+
target: "local",
|
|
117
|
+
capability,
|
|
118
|
+
payload: await this.executeDispatchLocally({ ...request, namespace })
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const token = await this.resolveDispatchToken(dispatchConfig.credentialSource);
|
|
122
|
+
const client = new RemoteTreeseedDispatchClient(new RemoteTreeseedClient({
|
|
123
|
+
hosts: [{ id: "market", baseUrl: dispatchConfig.marketBaseUrl }],
|
|
124
|
+
activeHostId: "market",
|
|
125
|
+
auth: token ? { accessToken: token } : void 0
|
|
126
|
+
}, {
|
|
127
|
+
fetchImpl: dispatchConfig.fetchImpl
|
|
128
|
+
}));
|
|
129
|
+
return client.dispatch(dispatchConfig.projectId, {
|
|
130
|
+
...request,
|
|
131
|
+
namespace,
|
|
132
|
+
preferredMode
|
|
133
|
+
});
|
|
134
|
+
}
|
|
66
135
|
envelope(model, operation, payload, meta) {
|
|
67
136
|
return {
|
|
68
137
|
ok: true,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { checkTreeseedProviderConnections } from '../operations/services/config-runtime.ts';
|
|
1
2
|
import { resolveTreeseedWorkflowState } from '../workflow-state.ts';
|
|
2
|
-
import type { TreeseedCloseInput, TreeseedConfigInput, TreeseedDestroyInput, TreeseedReleaseInput, TreeseedSaveInput, TreeseedStageInput, TreeseedSwitchInput, TreeseedTaskBranchMetadata, TreeseedWorkflowContext, TreeseedWorkflowDevInput, TreeseedWorkflowNextStep, TreeseedWorkflowOperationId, TreeseedWorkflowResult } from '../workflow.ts';
|
|
3
|
+
import type { TreeseedCloseInput, TreeseedConfigInput, TreeseedDestroyInput, TreeseedExportInput, TreeseedReleaseInput, TreeseedSaveInput, TreeseedStageInput, TreeseedSwitchInput, TreeseedTaskBranchMetadata, TreeseedWorkflowContext, TreeseedWorkflowDevInput, TreeseedWorkflowNextStep, TreeseedWorkflowOperationId, TreeseedWorkflowResult } from '../workflow.ts';
|
|
3
4
|
type WorkflowWrite = NonNullable<TreeseedWorkflowContext['write']>;
|
|
4
5
|
type WorkflowStatePayload = ReturnType<typeof resolveTreeseedWorkflowState>;
|
|
5
6
|
export type TreeseedWorkflowErrorCode = 'validation_failed' | 'merge_conflict' | 'missing_runtime_auth' | 'deployment_timeout' | 'confirmation_required' | 'unsupported_transport' | 'unsupported_state';
|
|
@@ -22,10 +23,6 @@ export type WorkflowOperationHelpers = {
|
|
|
22
23
|
tasks: TreeseedTaskBranchMetadata[];
|
|
23
24
|
}>>;
|
|
24
25
|
};
|
|
25
|
-
type TreeseedRepairAction = {
|
|
26
|
-
id: string;
|
|
27
|
-
detail: string;
|
|
28
|
-
};
|
|
29
26
|
export declare function workflowStatus(helpers: WorkflowOperationHelpers): Promise<TreeseedWorkflowResult<import("../workflow-state.ts").TreeseedWorkflowState>>;
|
|
30
27
|
export declare function workflowTasks(helpers: WorkflowOperationHelpers): Promise<TreeseedWorkflowResult<{
|
|
31
28
|
tasks: TreeseedTaskBranchMetadata[];
|
|
@@ -36,7 +33,7 @@ export declare function workflowConfig(helpers: WorkflowOperationHelpers, input?
|
|
|
36
33
|
sync: "all" | "cloudflare" | "railway" | "none" | "github";
|
|
37
34
|
configPath: string;
|
|
38
35
|
keyPath: string;
|
|
39
|
-
repairs: TreeseedRepairAction[];
|
|
36
|
+
repairs: import("../operations/services/config-runtime.ts").TreeseedRepairAction[];
|
|
40
37
|
preflight: {
|
|
41
38
|
ok: boolean;
|
|
42
39
|
requireAuth: boolean;
|
|
@@ -71,13 +68,45 @@ export declare function workflowConfig(helpers: WorkflowOperationHelpers, input?
|
|
|
71
68
|
actVerificationReady: any;
|
|
72
69
|
remediation: string[];
|
|
73
70
|
};
|
|
71
|
+
context: import("../operations/services/config-runtime.ts").TreeseedCollectedConfigContext;
|
|
74
72
|
result: {
|
|
75
|
-
scopes:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
scopes: ("local" | "staging" | "prod")[];
|
|
74
|
+
synced: Record<string, unknown>;
|
|
75
|
+
initialized: Array<{
|
|
76
|
+
scope: import("../operations/services/config-runtime.ts").TreeseedConfigScope;
|
|
77
|
+
secrets: number;
|
|
78
|
+
target: string;
|
|
79
|
+
}>;
|
|
80
|
+
connectionChecks: ReturnType<typeof checkTreeseedProviderConnections>[];
|
|
81
|
+
validationByScope: Record<import("../operations/services/config-runtime.ts").TreeseedConfigScope, ReturnType<typeof import("../platform/environment.ts").validateTreeseedEnvironmentValues>>;
|
|
82
|
+
updated: {
|
|
83
|
+
scope: import("../operations/services/config-runtime.ts").TreeseedConfigScope | "shared";
|
|
84
|
+
id: string;
|
|
85
|
+
reused: boolean;
|
|
86
|
+
cleared: boolean;
|
|
87
|
+
}[];
|
|
88
|
+
envFiles: {
|
|
89
|
+
envLocalPath: string;
|
|
90
|
+
devVarsPath: string;
|
|
91
|
+
} | null;
|
|
80
92
|
};
|
|
93
|
+
reports: {
|
|
94
|
+
scope: "local" | "staging" | "prod";
|
|
95
|
+
environment: {
|
|
96
|
+
scope: "local" | "staging" | "prod";
|
|
97
|
+
revealSecrets: boolean;
|
|
98
|
+
entries: any;
|
|
99
|
+
};
|
|
100
|
+
provider: {
|
|
101
|
+
scope: string;
|
|
102
|
+
ok: boolean;
|
|
103
|
+
checks: {
|
|
104
|
+
provider: any;
|
|
105
|
+
ready: any;
|
|
106
|
+
detail: any;
|
|
107
|
+
}[];
|
|
108
|
+
};
|
|
109
|
+
}[];
|
|
81
110
|
state: import("../workflow-state.ts").TreeseedWorkflowState;
|
|
82
111
|
readiness: {
|
|
83
112
|
local: {
|
|
@@ -108,10 +137,22 @@ export declare function workflowConfig(helpers: WorkflowOperationHelpers, input?
|
|
|
108
137
|
secretsRevealed: boolean;
|
|
109
138
|
reports: {
|
|
110
139
|
scope: "local" | "staging" | "prod";
|
|
111
|
-
|
|
112
|
-
|
|
140
|
+
environment: {
|
|
141
|
+
scope: "local" | "staging" | "prod";
|
|
142
|
+
revealSecrets: boolean;
|
|
143
|
+
entries: any;
|
|
144
|
+
};
|
|
145
|
+
provider: {
|
|
146
|
+
scope: string;
|
|
147
|
+
ok: boolean;
|
|
148
|
+
checks: {
|
|
149
|
+
provider: any;
|
|
150
|
+
ready: any;
|
|
151
|
+
detail: any;
|
|
152
|
+
}[];
|
|
153
|
+
};
|
|
113
154
|
}[];
|
|
114
|
-
repairs: TreeseedRepairAction[];
|
|
155
|
+
repairs: import("../operations/services/config-runtime.ts").TreeseedRepairAction[];
|
|
115
156
|
preflight: {
|
|
116
157
|
ok: boolean;
|
|
117
158
|
requireAuth: boolean;
|
|
@@ -157,7 +198,7 @@ export declare function workflowConfig(helpers: WorkflowOperationHelpers, input?
|
|
|
157
198
|
scopes: ("local" | "staging" | "prod")[];
|
|
158
199
|
sync: "all" | "cloudflare" | "railway" | "none" | "github";
|
|
159
200
|
keyPath: string;
|
|
160
|
-
repairs: TreeseedRepairAction[];
|
|
201
|
+
repairs: import("../operations/services/config-runtime.ts").TreeseedRepairAction[];
|
|
161
202
|
preflight: {
|
|
162
203
|
ok: boolean;
|
|
163
204
|
requireAuth: boolean;
|
|
@@ -197,6 +238,9 @@ export declare function workflowConfig(helpers: WorkflowOperationHelpers, input?
|
|
|
197
238
|
};
|
|
198
239
|
nextSteps: TreeseedWorkflowNextStep[];
|
|
199
240
|
}>;
|
|
241
|
+
export declare function workflowExport(helpers: WorkflowOperationHelpers, input?: TreeseedExportInput): Promise<TreeseedWorkflowResult<import("../operations/services/export-runtime.ts").TreeseedExportResult & {
|
|
242
|
+
finalState: WorkflowStatePayload;
|
|
243
|
+
}>>;
|
|
200
244
|
export declare function workflowSwitch(helpers: WorkflowOperationHelpers, input: TreeseedSwitchInput): Promise<TreeseedWorkflowResult<{
|
|
201
245
|
branchName: string;
|
|
202
246
|
created: boolean;
|