@treeseed/sdk 0.4.8 → 0.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +1 -1
  2. package/dist/control-plane-client.d.ts +45 -0
  3. package/dist/control-plane-client.js +229 -0
  4. package/dist/control-plane.d.ts +94 -0
  5. package/dist/control-plane.js +125 -0
  6. package/dist/d1-store.d.ts +56 -1
  7. package/dist/d1-store.js +132 -0
  8. package/dist/dispatch.d.ts +4 -0
  9. package/dist/dispatch.js +180 -0
  10. package/dist/index.d.ts +14 -2
  11. package/dist/index.js +94 -4
  12. package/dist/operations/services/config-runtime.d.ts +10 -0
  13. package/dist/operations/services/config-runtime.js +62 -4
  14. package/dist/operations/services/deploy.d.ts +95 -3
  15. package/dist/operations/services/deploy.js +351 -10
  16. package/dist/operations/services/github-automation.d.ts +37 -1
  17. package/dist/operations/services/github-automation.js +71 -14
  18. package/dist/operations/services/project-platform.d.ts +835 -0
  19. package/dist/operations/services/project-platform.js +782 -0
  20. package/dist/operations/services/railway-deploy.d.ts +113 -18
  21. package/dist/operations/services/railway-deploy.js +357 -8
  22. package/dist/operations/services/runtime-tools.d.ts +25 -1
  23. package/dist/operations/services/runtime-tools.js +66 -5
  24. package/dist/operations/services/template-registry.d.ts +1 -1
  25. package/dist/operations/services/template-registry.js +17 -3
  26. package/dist/platform/books-data.d.ts +3 -4
  27. package/dist/platform/books-data.js +30 -4
  28. package/dist/platform/contracts.d.ts +56 -4
  29. package/dist/platform/deploy-config.js +109 -4
  30. package/dist/platform/deploy-runtime.d.ts +2 -0
  31. package/dist/platform/deploy-runtime.js +9 -1
  32. package/dist/platform/env.yaml +677 -0
  33. package/dist/platform/environment.js +57 -2
  34. package/dist/platform/plugin.d.ts +8 -0
  35. package/dist/platform/plugins/constants.d.ts +2 -0
  36. package/dist/platform/plugins/constants.js +2 -0
  37. package/dist/platform/plugins/runtime.d.ts +2 -0
  38. package/dist/platform/plugins/runtime.js +9 -1
  39. package/dist/platform/plugins.d.ts +1 -1
  40. package/dist/platform/plugins.js +4 -0
  41. package/dist/platform/published-content-pipeline.d.ts +84 -0
  42. package/dist/platform/published-content-pipeline.js +543 -0
  43. package/dist/platform/published-content.d.ts +223 -0
  44. package/dist/platform/published-content.js +588 -0
  45. package/dist/platform/tenant/runtime-config.d.ts +1 -1
  46. package/dist/platform/tenant/runtime-config.js +34 -1
  47. package/dist/platform/tenant-config.d.ts +2 -1
  48. package/dist/platform/tenant-config.js +17 -1
  49. package/dist/platform/utils/site-config-schema.js +104 -0
  50. package/dist/plugin-default.d.ts +2 -0
  51. package/dist/plugin-default.js +2 -0
  52. package/dist/remote.d.ts +65 -9
  53. package/dist/remote.js +104 -28
  54. package/dist/scripts/check-build-warnings.js +50 -0
  55. package/dist/scripts/config-treeseed.js +7 -0
  56. package/dist/scripts/tenant-workflow-action.js +71 -0
  57. package/dist/sdk-dispatch.d.ts +12 -0
  58. package/dist/sdk-dispatch.js +142 -0
  59. package/dist/sdk-types.d.ts +579 -7
  60. package/dist/sdk-types.js +53 -1
  61. package/dist/sdk.d.ts +17 -1
  62. package/dist/sdk.js +109 -0
  63. package/dist/stores/operational-store.d.ts +22 -2
  64. package/dist/stores/operational-store.js +235 -0
  65. package/dist/template-catalog.js +8 -1
  66. package/dist/treeseed/template-catalog/templates/starter-basic/template/treeseed.site.yaml +20 -0
  67. package/dist/types/cloudflare.d.ts +23 -0
  68. package/dist/workflow/operations.d.ts +12 -3
  69. package/dist/workflow/policy.d.ts +1 -1
  70. package/dist/workflow-state.js +2 -1
  71. package/package.json +7 -2
  72. package/templates/github/deploy.workflow.yml +442 -0
  73. package/templates/github/hosted-project.workflow.yml +77 -0
@@ -166,6 +166,108 @@ function parseTheme(value, path) {
166
166
  };
167
167
  }
168
168
 
169
+ function parseAccessRoles(value, path) {
170
+ const record = optionalRecord(value, path);
171
+ if (!record) {
172
+ return {};
173
+ }
174
+
175
+ return Object.fromEntries(
176
+ Object.entries(record).map(([roleId, rawRole]) => {
177
+ const parsedRole = expectRecord(rawRole, `${path}.${roleId}`);
178
+ return [
179
+ roleId,
180
+ {
181
+ grants: stringArray(parsedRole.grants, `${path}.${roleId}.grants`),
182
+ },
183
+ ];
184
+ }),
185
+ );
186
+ }
187
+
188
+ function parseAccessPolicies(value, path) {
189
+ const record = optionalRecord(value, path);
190
+ if (!record) {
191
+ return {};
192
+ }
193
+
194
+ return Object.fromEntries(
195
+ Object.entries(record).map(([policyId, rawPolicy]) => {
196
+ const parsedPolicy = expectRecord(rawPolicy, `${path}.${policyId}`);
197
+ return [
198
+ policyId,
199
+ {
200
+ audience: optionalString(parsedPolicy.audience, `${path}.${policyId}.audience`),
201
+ entitlement: optionalString(parsedPolicy.entitlement, `${path}.${policyId}.entitlement`),
202
+ offer: optionalString(parsedPolicy.offer, `${path}.${policyId}.offer`),
203
+ visibility: optionalString(parsedPolicy.visibility, `${path}.${policyId}.visibility`),
204
+ },
205
+ ];
206
+ }),
207
+ );
208
+ }
209
+
210
+ function parseAccessDefaults(value, path) {
211
+ const record = optionalRecord(value, path);
212
+ if (!record) {
213
+ return { models: {} };
214
+ }
215
+
216
+ const models = optionalRecord(record.models, `${path}.models`) ?? {};
217
+ return {
218
+ models: Object.fromEntries(
219
+ Object.entries(models).map(([modelId, rawSurfaces]) => {
220
+ const parsedSurfaces = expectRecord(rawSurfaces, `${path}.models.${modelId}`);
221
+ return [
222
+ modelId,
223
+ Object.fromEntries(
224
+ Object.entries(parsedSurfaces).map(([surfaceId, rawPolicy]) => [
225
+ surfaceId,
226
+ expectString(rawPolicy, `${path}.models.${modelId}.${surfaceId}`),
227
+ ]),
228
+ ),
229
+ ];
230
+ }),
231
+ ),
232
+ };
233
+ }
234
+
235
+ function parseAccessBootstrap(value, path) {
236
+ const record = optionalRecord(value, path);
237
+ if (!record) {
238
+ return {};
239
+ }
240
+
241
+ const owners = optionalRecord(record.owners, `${path}.owners`);
242
+ return {
243
+ owners: owners
244
+ ? {
245
+ emails: stringArray(owners.emails, `${path}.owners.emails`),
246
+ roles: stringArray(owners.roles, `${path}.owners.roles`),
247
+ }
248
+ : undefined,
249
+ };
250
+ }
251
+
252
+ function parseAccess(value, path) {
253
+ const record = optionalRecord(value, path);
254
+ if (!record) {
255
+ return {
256
+ roles: {},
257
+ policies: {},
258
+ defaults: { models: {} },
259
+ bootstrap: {},
260
+ };
261
+ }
262
+
263
+ return {
264
+ roles: parseAccessRoles(record.roles, `${path}.roles`),
265
+ policies: parseAccessPolicies(record.policies, `${path}.policies`),
266
+ defaults: parseAccessDefaults(record.defaults, `${path}.defaults`),
267
+ bootstrap: parseAccessBootstrap(record.bootstrap, `${path}.bootstrap`),
268
+ };
269
+ }
270
+
169
271
  /** @type {TreeseedFieldAliasRegistry} */
170
272
  const siteFieldAliases = {
171
273
  siteUrl: { key: 'siteUrl', aliases: ['site_url'] },
@@ -228,6 +330,7 @@ export function parseSiteConfig(source) {
228
330
  emailNotificationFieldAliases,
229
331
  expectRecord(site.emailNotifications, 'site.emailNotifications'),
230
332
  );
333
+ const access = parseAccess(parsed.access, 'access');
231
334
 
232
335
  return {
233
336
  site: {
@@ -317,5 +420,6 @@ export function parseSiteConfig(source) {
317
420
  },
318
421
  },
319
422
  },
423
+ access,
320
424
  };
321
425
  }
@@ -14,6 +14,8 @@ declare const _default: {
14
14
  };
15
15
  deploy: string[];
16
16
  content: {
17
+ runtime: string[];
18
+ publish: string[];
17
19
  docs: string[];
18
20
  };
19
21
  site: string[];
@@ -24,6 +24,8 @@ var plugin_default_default = defineTreeseedPlugin({
24
24
  },
25
25
  deploy: ["cloudflare"],
26
26
  content: {
27
+ runtime: ["filesystem", "team_scoped_r2_overlay"],
28
+ publish: ["filesystem", "team_scoped_r2_overlay"],
27
29
  docs: ["default"]
28
30
  },
29
31
  site: ["default"]
package/dist/remote.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { RemoteJob, RemoteJobEvent, SdkDispatchRequest, SdkDispatchResult } from './sdk-types.ts';
1
2
  export declare const TREESEED_REMOTE_CONTRACT_VERSION = 1;
2
3
  export declare const TREESEED_REMOTE_CONTRACT_HEADER = "x-treeseed-remote-contract-version";
3
4
  export type ApiScope = string;
@@ -111,6 +112,25 @@ export interface RemoteWorkflowOperationResponse {
111
112
  payload?: Record<string, unknown> | null;
112
113
  nextSteps?: RemoteWorkflowNextStep[];
113
114
  }
115
+ export interface RemoteJobPullRequest {
116
+ limit?: number;
117
+ runnerId?: string;
118
+ }
119
+ export interface RemoteJobPullResponse {
120
+ ok: true;
121
+ payload: RemoteJob[];
122
+ }
123
+ export interface RemoteJobProgressRequest {
124
+ summary?: string;
125
+ data?: Record<string, unknown>;
126
+ }
127
+ export interface RemoteJobCompletionRequest {
128
+ output?: unknown;
129
+ }
130
+ export interface RemoteJobFailureRequest {
131
+ code?: string;
132
+ message: string;
133
+ }
114
134
  export declare class RemoteTreeseedClient {
115
135
  readonly config: RemoteTreeseedConfig;
116
136
  private readonly fetchImpl;
@@ -141,15 +161,6 @@ export declare class RemoteTreeseedSdkClient {
141
161
  constructor(client: RemoteTreeseedClient);
142
162
  execute<T = unknown>(operation: string, request: RemoteSdkOperationRequest): Promise<T>;
143
163
  }
144
- export declare class TreeseedGatewayClient {
145
- private readonly baseUrl;
146
- private readonly token;
147
- private readonly fetchImpl;
148
- constructor(config: import('./sdk-types.ts').SdkGatewayClientConfig);
149
- requestJson<T>(path: string, options?: RemoteGatewayRequest): Promise<T & {
150
- error?: string;
151
- }>;
152
- }
153
164
  export declare class CloudflareQueuePullClient {
154
165
  private readonly baseUrl;
155
166
  private readonly token;
@@ -170,8 +181,53 @@ export declare class CloudflareQueuePullClient {
170
181
  delaySeconds?: number;
171
182
  }>): Promise<unknown>;
172
183
  }
184
+ export declare class CloudflareQueuePushClient {
185
+ private readonly baseUrl;
186
+ private readonly token;
187
+ private readonly fetchImpl;
188
+ constructor(config: import('./sdk-types.ts').SdkQueuePushClientConfig);
189
+ enqueue(request: import('./sdk-types.ts').SdkQueuePushRequest): Promise<void>;
190
+ }
173
191
  export declare class RemoteTreeseedOperationsClient {
174
192
  private readonly client;
175
193
  constructor(client: RemoteTreeseedClient);
176
194
  execute(operation: string, request: RemoteWorkflowOperationRequest): Promise<RemoteWorkflowOperationResponse>;
177
195
  }
196
+ export declare class RemoteTreeseedDispatchClient {
197
+ private readonly client;
198
+ constructor(client: RemoteTreeseedClient);
199
+ dispatch(projectId: string, request: SdkDispatchRequest): Promise<SdkDispatchResult>;
200
+ }
201
+ export declare class RemoteTreeseedJobsClient {
202
+ private readonly client;
203
+ constructor(client: RemoteTreeseedClient);
204
+ get(jobId: string): Promise<{
205
+ ok: true;
206
+ payload: RemoteJob;
207
+ }>;
208
+ cancel(jobId: string): Promise<{
209
+ ok: true;
210
+ payload: RemoteJob;
211
+ }>;
212
+ events(jobId: string): Promise<{
213
+ ok: true;
214
+ payload: RemoteJobEvent[];
215
+ }>;
216
+ }
217
+ export declare class RemoteTreeseedRunnerClient {
218
+ private readonly client;
219
+ constructor(client: RemoteTreeseedClient);
220
+ pull(projectId: string, request?: RemoteJobPullRequest): Promise<RemoteJobPullResponse>;
221
+ progress(jobId: string, request?: RemoteJobProgressRequest): Promise<{
222
+ ok: true;
223
+ payload: RemoteJob;
224
+ }>;
225
+ complete(jobId: string, request?: RemoteJobCompletionRequest): Promise<{
226
+ ok: true;
227
+ payload: RemoteJob;
228
+ }>;
229
+ fail(jobId: string, request: RemoteJobFailureRequest): Promise<{
230
+ ok: true;
231
+ payload: RemoteJob;
232
+ }>;
233
+ }
package/dist/remote.js CHANGED
@@ -100,32 +100,6 @@ class RemoteTreeseedSdkClient {
100
100
  function normalizeExternalBaseUrl(baseUrl) {
101
101
  return baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
102
102
  }
103
- class TreeseedGatewayClient {
104
- baseUrl;
105
- token;
106
- fetchImpl;
107
- constructor(config) {
108
- this.baseUrl = normalizeExternalBaseUrl(config.baseUrl);
109
- this.token = config.bearerToken;
110
- this.fetchImpl = config.fetchImpl ?? fetch;
111
- }
112
- async requestJson(path, options = {}) {
113
- const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
114
- method: options.method ?? "POST",
115
- headers: {
116
- accept: "application/json",
117
- authorization: `Bearer ${this.token}`,
118
- ...options.body === void 0 ? {} : { "content-type": "application/json" }
119
- },
120
- body: options.body === void 0 ? void 0 : JSON.stringify(options.body)
121
- });
122
- const payload = await response.json().catch(() => ({}));
123
- if (!response.ok) {
124
- throw new Error(typeof payload.error === "string" ? payload.error : `Gateway request failed with ${response.status}.`);
125
- }
126
- return payload;
127
- }
128
- }
129
103
  class CloudflareQueuePullClient {
130
104
  baseUrl;
131
105
  token;
@@ -177,6 +151,36 @@ class CloudflareQueuePullClient {
177
151
  });
178
152
  }
179
153
  }
154
+ class CloudflareQueuePushClient {
155
+ baseUrl;
156
+ token;
157
+ fetchImpl;
158
+ constructor(config) {
159
+ const apiBaseUrl = config.apiBaseUrl ?? "https://api.cloudflare.com/client/v4/accounts";
160
+ this.baseUrl = `${normalizeExternalBaseUrl(apiBaseUrl)}/${config.accountId}/queues/${config.queueId}`;
161
+ this.token = config.token;
162
+ this.fetchImpl = config.fetchImpl ?? fetch;
163
+ }
164
+ async enqueue(request) {
165
+ const response = await this.fetchImpl(`${this.baseUrl}/messages`, {
166
+ method: "POST",
167
+ headers: {
168
+ accept: "application/json",
169
+ authorization: `Bearer ${this.token}`,
170
+ "content-type": "application/json"
171
+ },
172
+ body: JSON.stringify({
173
+ body: request.message,
174
+ content_type: "json",
175
+ delay_seconds: request.delaySeconds ?? 0
176
+ })
177
+ });
178
+ const payload = await response.json().catch(() => ({}));
179
+ if (!response.ok || payload.success === false) {
180
+ throw new Error(payload.errors?.[0]?.message ?? `Queue request failed with ${response.status}.`);
181
+ }
182
+ }
183
+ }
180
184
  class RemoteTreeseedOperationsClient {
181
185
  constructor(client) {
182
186
  this.client = client;
@@ -190,13 +194,85 @@ class RemoteTreeseedOperationsClient {
190
194
  });
191
195
  }
192
196
  }
197
+ class RemoteTreeseedDispatchClient {
198
+ constructor(client) {
199
+ this.client = client;
200
+ }
201
+ client;
202
+ dispatch(projectId, request) {
203
+ return this.client.requestJson(`/v1/projects/${encodeURIComponent(projectId)}/dispatch`, {
204
+ method: "POST",
205
+ body: request,
206
+ requireAuth: true
207
+ });
208
+ }
209
+ }
210
+ class RemoteTreeseedJobsClient {
211
+ constructor(client) {
212
+ this.client = client;
213
+ }
214
+ client;
215
+ get(jobId) {
216
+ return this.client.requestJson(`/v1/jobs/${encodeURIComponent(jobId)}`, {
217
+ requireAuth: true
218
+ });
219
+ }
220
+ cancel(jobId) {
221
+ return this.client.requestJson(`/v1/jobs/${encodeURIComponent(jobId)}/cancel`, {
222
+ method: "POST",
223
+ requireAuth: true
224
+ });
225
+ }
226
+ events(jobId) {
227
+ return this.client.requestJson(`/v1/jobs/${encodeURIComponent(jobId)}/events`, {
228
+ requireAuth: true
229
+ });
230
+ }
231
+ }
232
+ class RemoteTreeseedRunnerClient {
233
+ constructor(client) {
234
+ this.client = client;
235
+ }
236
+ client;
237
+ pull(projectId, request = {}) {
238
+ return this.client.requestJson(`/v1/projects/${encodeURIComponent(projectId)}/runner/jobs/pull`, {
239
+ method: "POST",
240
+ body: request,
241
+ requireAuth: true
242
+ });
243
+ }
244
+ progress(jobId, request = {}) {
245
+ return this.client.requestJson(`/v1/jobs/${encodeURIComponent(jobId)}/progress`, {
246
+ method: "POST",
247
+ body: request,
248
+ requireAuth: true
249
+ });
250
+ }
251
+ complete(jobId, request = {}) {
252
+ return this.client.requestJson(`/v1/jobs/${encodeURIComponent(jobId)}/complete`, {
253
+ method: "POST",
254
+ body: request,
255
+ requireAuth: true
256
+ });
257
+ }
258
+ fail(jobId, request) {
259
+ return this.client.requestJson(`/v1/jobs/${encodeURIComponent(jobId)}/fail`, {
260
+ method: "POST",
261
+ body: request,
262
+ requireAuth: true
263
+ });
264
+ }
265
+ }
193
266
  export {
194
267
  CloudflareQueuePullClient,
268
+ CloudflareQueuePushClient,
195
269
  RemoteTreeseedAuthClient,
196
270
  RemoteTreeseedClient,
271
+ RemoteTreeseedDispatchClient,
272
+ RemoteTreeseedJobsClient,
197
273
  RemoteTreeseedOperationsClient,
274
+ RemoteTreeseedRunnerClient,
198
275
  RemoteTreeseedSdkClient,
199
276
  TREESEED_REMOTE_CONTRACT_HEADER,
200
- TREESEED_REMOTE_CONTRACT_VERSION,
201
- TreeseedGatewayClient
277
+ TREESEED_REMOTE_CONTRACT_VERSION
202
278
  };
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { readFileSync } from 'node:fs';
4
+ import { resolve } from 'node:path';
5
+
6
+ const args = process.argv.slice(2);
7
+ const allowlisted = [];
8
+ const files = [];
9
+
10
+ for (let index = 0; index < args.length; index += 1) {
11
+ const arg = args[index];
12
+ if (arg === '--allow') {
13
+ const pattern = args[index + 1];
14
+ if (!pattern) {
15
+ throw new Error('Missing value for --allow.');
16
+ }
17
+ allowlisted.push(new RegExp(pattern));
18
+ index += 1;
19
+ continue;
20
+ }
21
+ files.push(arg);
22
+ }
23
+
24
+ if (files.length === 0) {
25
+ throw new Error('Usage: node check-build-warnings.mjs <log-file> [<log-file> ...] [--allow <regex>]');
26
+ }
27
+
28
+ const warningLines = [];
29
+ for (const file of files) {
30
+ const contents = readFileSync(resolve(process.cwd(), file), 'utf8');
31
+ for (const line of contents.split(/\r?\n/u)) {
32
+ if (!line.includes('[WARN]')) {
33
+ continue;
34
+ }
35
+ if (allowlisted.some((pattern) => pattern.test(line))) {
36
+ continue;
37
+ }
38
+ warningLines.push(line);
39
+ }
40
+ }
41
+
42
+ if (warningLines.length > 0) {
43
+ console.error('Unexpected build warnings detected:');
44
+ for (const line of warningLines) {
45
+ console.error(`- ${line}`);
46
+ }
47
+ process.exit(1);
48
+ }
49
+
50
+ console.log('No unexpected build warnings detected.');
@@ -74,6 +74,13 @@ try {
74
74
  console.log(`Machine key: ${keyPath}`);
75
75
  console.log(`Updated values: ${applyResult.updated.length}`);
76
76
  console.log(`Initialized environments: ${result.initialized.length}`);
77
+ for (const scope of scopes) {
78
+ const readiness = result.readinessByScope?.[scope];
79
+ if (!readiness)
80
+ continue;
81
+ const status = readiness.deployable ? 'deployable' : readiness.provisioned ? 'provisioned' : readiness.configured ? 'configured' : 'pending';
82
+ console.log(`Readiness (${scope}): ${status}`);
83
+ }
77
84
  if (result.synced.github) {
78
85
  console.log(`GitHub sync: ${result.synced.github.secrets.length} secrets, ${result.synced.github.variables.length} variables (${result.synced.github.repository})`);
79
86
  }
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+ import { resolveScope, runProjectPlatformAction, } from '../operations/services/project-platform.js';
3
+ const tenantRoot = process.cwd();
4
+ function parseArgs(argv) {
5
+ const parsed = {
6
+ action: 'deploy_code',
7
+ environment: null,
8
+ projectId: null,
9
+ previewId: null,
10
+ dryRun: false,
11
+ };
12
+ const rest = [...argv];
13
+ while (rest.length) {
14
+ const current = rest.shift();
15
+ if (!current)
16
+ continue;
17
+ if (current === '--action') {
18
+ parsed.action = (rest.shift() ?? parsed.action);
19
+ continue;
20
+ }
21
+ if (current.startsWith('--action=')) {
22
+ parsed.action = (current.split('=', 2)[1] ?? parsed.action);
23
+ continue;
24
+ }
25
+ if (current === '--environment') {
26
+ parsed.environment = rest.shift() ?? null;
27
+ continue;
28
+ }
29
+ if (current.startsWith('--environment=')) {
30
+ parsed.environment = current.split('=', 2)[1] ?? null;
31
+ continue;
32
+ }
33
+ if (current === '--project-id') {
34
+ parsed.projectId = rest.shift() ?? null;
35
+ continue;
36
+ }
37
+ if (current.startsWith('--project-id=')) {
38
+ parsed.projectId = current.split('=', 2)[1] ?? null;
39
+ continue;
40
+ }
41
+ if (current === '--preview-id') {
42
+ parsed.previewId = rest.shift() ?? null;
43
+ continue;
44
+ }
45
+ if (current.startsWith('--preview-id=')) {
46
+ parsed.previewId = current.split('=', 2)[1] ?? null;
47
+ continue;
48
+ }
49
+ if (current === '--dry-run') {
50
+ parsed.dryRun = true;
51
+ continue;
52
+ }
53
+ throw new Error(`Unknown workflow action argument: ${current}`);
54
+ }
55
+ return parsed;
56
+ }
57
+ async function main() {
58
+ const options = parseArgs(process.argv.slice(2));
59
+ const scope = resolveScope(options.environment);
60
+ const result = await runProjectPlatformAction(options.action, {
61
+ tenantRoot,
62
+ scope,
63
+ projectId: options.projectId ?? process.env.TREESEED_PROJECT_ID ?? null,
64
+ previewId: options.previewId,
65
+ dryRun: options.dryRun,
66
+ });
67
+ if (result !== undefined) {
68
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
69
+ }
70
+ }
71
+ await main();
@@ -0,0 +1,12 @@
1
+ import type { AgentSdk } from './sdk.ts';
2
+ type JsonRecord = Record<string, unknown>;
3
+ type SdkOperationHandler = (sdk: AgentSdk, input: JsonRecord) => Promise<unknown> | unknown;
4
+ interface SdkOperationSpec {
5
+ name: string;
6
+ aliases?: string[];
7
+ handler: SdkOperationHandler;
8
+ }
9
+ export declare function listSdkOperationNames(): string[];
10
+ export declare function findSdkOperation(name: string): SdkOperationSpec | null;
11
+ export declare function executeSdkOperation(sdk: AgentSdk, operationName: string, input: JsonRecord): Promise<unknown>;
12
+ export {};
@@ -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
+ };