@project-ajax/sdk 0.0.28

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 (145) hide show
  1. package/README.md +22 -0
  2. package/dist/block.d.ts +321 -0
  3. package/dist/block.d.ts.map +1 -0
  4. package/dist/block.js +0 -0
  5. package/dist/builder.d.ts +12 -0
  6. package/dist/builder.d.ts.map +1 -0
  7. package/dist/builder.js +22 -0
  8. package/dist/capabilities/slashCommand.d.ts +56 -0
  9. package/dist/capabilities/slashCommand.d.ts.map +1 -0
  10. package/dist/capabilities/slashCommand.js +32 -0
  11. package/dist/capabilities/sync.d.ts +58 -0
  12. package/dist/capabilities/sync.d.ts.map +1 -0
  13. package/dist/capabilities/sync.js +26 -0
  14. package/dist/capabilities/tool.d.ts +69 -0
  15. package/dist/capabilities/tool.d.ts.map +1 -0
  16. package/dist/capabilities/tool.js +75 -0
  17. package/dist/capabilities/tool.test.d.ts +2 -0
  18. package/dist/capabilities/tool.test.d.ts.map +1 -0
  19. package/dist/cli/api/client.d.ts +185 -0
  20. package/dist/cli/api/client.d.ts.map +1 -0
  21. package/dist/cli/api/client.js +315 -0
  22. package/dist/cli/api/result.d.ts +43 -0
  23. package/dist/cli/api/result.d.ts.map +1 -0
  24. package/dist/cli/api/result.js +43 -0
  25. package/dist/cli/bin/cli.d.ts +3 -0
  26. package/dist/cli/bin/cli.d.ts.map +1 -0
  27. package/dist/cli/bin/cli.js +5 -0
  28. package/dist/cli/commands/auth.d.ts +2 -0
  29. package/dist/cli/commands/auth.d.ts.map +1 -0
  30. package/dist/cli/commands/auth.impl.d.ts +10 -0
  31. package/dist/cli/commands/auth.impl.d.ts.map +1 -0
  32. package/dist/cli/commands/auth.impl.js +68 -0
  33. package/dist/cli/commands/auth.js +71 -0
  34. package/dist/cli/commands/bundle.d.ts +2 -0
  35. package/dist/cli/commands/bundle.d.ts.map +1 -0
  36. package/dist/cli/commands/bundle.impl.d.ts +2 -0
  37. package/dist/cli/commands/bundle.impl.d.ts.map +1 -0
  38. package/dist/cli/commands/bundle.impl.js +21 -0
  39. package/dist/cli/commands/bundle.js +23 -0
  40. package/dist/cli/commands/capabilities.d.ts +2 -0
  41. package/dist/cli/commands/capabilities.d.ts.map +1 -0
  42. package/dist/cli/commands/capabilities.impl.d.ts +3 -0
  43. package/dist/cli/commands/capabilities.impl.d.ts.map +1 -0
  44. package/dist/cli/commands/capabilities.impl.js +40 -0
  45. package/dist/cli/commands/capabilities.js +24 -0
  46. package/dist/cli/commands/deploy.d.ts +3 -0
  47. package/dist/cli/commands/deploy.d.ts.map +1 -0
  48. package/dist/cli/commands/deploy.impl.d.ts +2 -0
  49. package/dist/cli/commands/deploy.impl.d.ts.map +1 -0
  50. package/dist/cli/commands/deploy.impl.js +31 -0
  51. package/dist/cli/commands/deploy.js +16 -0
  52. package/dist/cli/commands/exec.d.ts +3 -0
  53. package/dist/cli/commands/exec.d.ts.map +1 -0
  54. package/dist/cli/commands/exec.impl.d.ts +7 -0
  55. package/dist/cli/commands/exec.impl.d.ts.map +1 -0
  56. package/dist/cli/commands/exec.impl.js +122 -0
  57. package/dist/cli/commands/exec.js +30 -0
  58. package/dist/cli/commands/runs.d.ts +2 -0
  59. package/dist/cli/commands/runs.d.ts.map +1 -0
  60. package/dist/cli/commands/runs.impl.d.ts +4 -0
  61. package/dist/cli/commands/runs.impl.d.ts.map +1 -0
  62. package/dist/cli/commands/runs.impl.js +71 -0
  63. package/dist/cli/commands/runs.js +45 -0
  64. package/dist/cli/commands/secrets.d.ts +2 -0
  65. package/dist/cli/commands/secrets.d.ts.map +1 -0
  66. package/dist/cli/commands/secrets.impl.d.ts +5 -0
  67. package/dist/cli/commands/secrets.impl.d.ts.map +1 -0
  68. package/dist/cli/commands/secrets.impl.js +93 -0
  69. package/dist/cli/commands/secrets.js +64 -0
  70. package/dist/cli/config.d.ts +38 -0
  71. package/dist/cli/config.d.ts.map +1 -0
  72. package/dist/cli/config.js +133 -0
  73. package/dist/cli/context.d.ts +15 -0
  74. package/dist/cli/context.d.ts.map +1 -0
  75. package/dist/cli/context.js +16 -0
  76. package/dist/cli/deploy.d.ts +25 -0
  77. package/dist/cli/deploy.d.ts.map +1 -0
  78. package/dist/cli/deploy.js +101 -0
  79. package/dist/cli/flags.d.ts +16 -0
  80. package/dist/cli/flags.d.ts.map +1 -0
  81. package/dist/cli/flags.js +24 -0
  82. package/dist/cli/handler.d.ts +14 -0
  83. package/dist/cli/handler.d.ts.map +1 -0
  84. package/dist/cli/handler.js +30 -0
  85. package/dist/cli/routes.d.ts +2 -0
  86. package/dist/cli/routes.d.ts.map +1 -0
  87. package/dist/cli/routes.js +44 -0
  88. package/dist/cli/utils/array.d.ts +2 -0
  89. package/dist/cli/utils/array.d.ts.map +1 -0
  90. package/dist/cli/utils/array.js +10 -0
  91. package/dist/cli/utils/string.d.ts +2 -0
  92. package/dist/cli/utils/string.d.ts.map +1 -0
  93. package/dist/cli/utils/string.js +12 -0
  94. package/dist/cli/writer.d.ts +48 -0
  95. package/dist/cli/writer.d.ts.map +1 -0
  96. package/dist/cli/writer.js +73 -0
  97. package/dist/error.d.ts +8 -0
  98. package/dist/error.d.ts.map +1 -0
  99. package/dist/error.js +11 -0
  100. package/dist/index.d.ts +4 -0
  101. package/dist/index.d.ts.map +1 -0
  102. package/dist/index.js +8 -0
  103. package/dist/schema.d.ts +45 -0
  104. package/dist/schema.d.ts.map +1 -0
  105. package/dist/schema.js +14 -0
  106. package/dist/types.d.ts +11 -0
  107. package/dist/types.d.ts.map +1 -0
  108. package/dist/types.js +0 -0
  109. package/package.json +79 -0
  110. package/src/block.ts +529 -0
  111. package/src/builder.ts +26 -0
  112. package/src/capabilities/slashCommand.ts +71 -0
  113. package/src/capabilities/sync.ts +76 -0
  114. package/src/capabilities/tool.test.ts +181 -0
  115. package/src/capabilities/tool.ts +145 -0
  116. package/src/cli/api/client.ts +588 -0
  117. package/src/cli/api/result.ts +71 -0
  118. package/src/cli/bin/cli.ts +7 -0
  119. package/src/cli/commands/auth.impl.ts +92 -0
  120. package/src/cli/commands/auth.ts +77 -0
  121. package/src/cli/commands/bundle.impl.ts +21 -0
  122. package/src/cli/commands/bundle.ts +23 -0
  123. package/src/cli/commands/capabilities.impl.ts +47 -0
  124. package/src/cli/commands/capabilities.ts +25 -0
  125. package/src/cli/commands/deploy.impl.ts +34 -0
  126. package/src/cli/commands/deploy.ts +16 -0
  127. package/src/cli/commands/exec.impl.ts +169 -0
  128. package/src/cli/commands/exec.ts +32 -0
  129. package/src/cli/commands/runs.impl.ts +87 -0
  130. package/src/cli/commands/runs.ts +49 -0
  131. package/src/cli/commands/secrets.impl.ts +124 -0
  132. package/src/cli/commands/secrets.ts +73 -0
  133. package/src/cli/config.ts +175 -0
  134. package/src/cli/context.ts +26 -0
  135. package/src/cli/deploy.ts +175 -0
  136. package/src/cli/flags.ts +43 -0
  137. package/src/cli/handler.ts +62 -0
  138. package/src/cli/routes.ts +43 -0
  139. package/src/cli/utils/array.ts +7 -0
  140. package/src/cli/utils/string.ts +9 -0
  141. package/src/cli/writer.ts +97 -0
  142. package/src/error.ts +12 -0
  143. package/src/index.ts +3 -0
  144. package/src/schema.ts +54 -0
  145. package/src/types.ts +10 -0
@@ -0,0 +1,75 @@
1
+ import { Ajv } from "ajv";
2
+ class InvalidToolInputError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "InvalidToolInputError";
6
+ }
7
+ }
8
+ class InvalidToolOutputError extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "InvalidToolOutputError";
12
+ }
13
+ }
14
+ class ToolExecutionError extends Error {
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = "ToolExecutionError";
18
+ }
19
+ }
20
+ function tool(config) {
21
+ const ajv = new Ajv();
22
+ const validateInput = ajv.compile(config.schema);
23
+ const validateOutput = config.outputSchema ? ajv.compile(config.outputSchema) : null;
24
+ return {
25
+ _tag: "tool",
26
+ config: {
27
+ description: config.description,
28
+ schema: config.schema,
29
+ outputSchema: config.outputSchema
30
+ },
31
+ async handler(input) {
32
+ if (!validateInput(input)) {
33
+ if (validateInput.errors == null) {
34
+ throw new Error(
35
+ "Unexpected: No validation errors after failed validation"
36
+ );
37
+ }
38
+ return {
39
+ _tag: "error",
40
+ error: new InvalidToolInputError(
41
+ JSON.stringify(validateInput.errors, null, 2)
42
+ )
43
+ };
44
+ }
45
+ try {
46
+ const result = await config.execute(input);
47
+ if (validateOutput && !validateOutput(result)) {
48
+ return {
49
+ _tag: "error",
50
+ error: new InvalidToolOutputError(
51
+ JSON.stringify(validateOutput.errors, null, 2)
52
+ )
53
+ };
54
+ }
55
+ return {
56
+ _tag: "success",
57
+ value: result
58
+ };
59
+ } catch (err) {
60
+ return {
61
+ _tag: "error",
62
+ error: new ToolExecutionError(
63
+ err instanceof Error ? err.message : String(err)
64
+ )
65
+ };
66
+ }
67
+ }
68
+ };
69
+ }
70
+ export {
71
+ InvalidToolInputError,
72
+ InvalidToolOutputError,
73
+ ToolExecutionError,
74
+ tool
75
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tool.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.test.d.ts","sourceRoot":"","sources":["../../src/capabilities/tool.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * API client for making authenticated requests to the Workers API
3
+ */
4
+ import type { Writer } from "../writer.js";
5
+ import { Result } from "./result.js";
6
+ export type Environment = "local" | "staging" | "dev" | "prod";
7
+ interface ApiClientConfig {
8
+ token: string;
9
+ environment: Environment;
10
+ baseUrl?: string | undefined;
11
+ cellId: string;
12
+ writer: Writer;
13
+ }
14
+ export interface ApiError {
15
+ status: number;
16
+ statusText: string;
17
+ message: string;
18
+ validationError?: {
19
+ errorId: string;
20
+ name: string;
21
+ debugMessage: string;
22
+ message: string;
23
+ };
24
+ }
25
+ /**
26
+ * Get the base URL for the given environment
27
+ */
28
+ export declare function baseUrl({ environment, override, }: {
29
+ environment: Environment;
30
+ override?: string | undefined;
31
+ }): string;
32
+ /**
33
+ * API client for making authenticated requests to Workers endpoints
34
+ */
35
+ export declare class ApiClient {
36
+ #private;
37
+ constructor(config: ApiClientConfig);
38
+ private baseApiUrl;
39
+ /**
40
+ * Make an authenticated fetch request to the Workers API
41
+ */
42
+ private fetch;
43
+ /**
44
+ * Create a new worker
45
+ */
46
+ createWorker(name: string): Promise<Result<{
47
+ worker: {
48
+ workerId: string;
49
+ name: string;
50
+ spaceId: string;
51
+ createdAt: string;
52
+ updatedAt: string;
53
+ state: unknown;
54
+ };
55
+ url: string;
56
+ fields: Record<string, string>;
57
+ }, ApiError>>;
58
+ /**
59
+ * Update an existing worker's bundle
60
+ */
61
+ updateWorkerBundle(workerId: string): Promise<Result<{
62
+ url: string;
63
+ fields: Record<string, string>;
64
+ }, ApiError>>;
65
+ /**
66
+ * Get a worker by ID
67
+ */
68
+ getWorker(workerId: string): Promise<Result<{
69
+ worker: {
70
+ workerId: string;
71
+ name: string;
72
+ spaceId: string;
73
+ state: unknown;
74
+ tools: unknown[];
75
+ createdAt: string;
76
+ updatedAt: string;
77
+ };
78
+ }, ApiError>>;
79
+ /**
80
+ * List all workers in the space
81
+ */
82
+ listWorkers(): Promise<Result<{
83
+ workers: Array<{
84
+ workerId: string;
85
+ name: string;
86
+ spaceId: string;
87
+ state: unknown;
88
+ createdAt: string;
89
+ updatedAt: string;
90
+ }>;
91
+ }, ApiError>>;
92
+ /**
93
+ * Delete a worker
94
+ */
95
+ deleteWorker(workerId: string): Promise<Result<Record<string, never>, ApiError>>;
96
+ /**
97
+ * Fetch and save worker capabilities
98
+ */
99
+ fetchAndSaveCapabilities(workerId: string): Promise<Result<{
100
+ capabilities: ReadonlyArray<{
101
+ _tag: "sync" | "slashCommand";
102
+ spaceId: string;
103
+ workerId: string;
104
+ key: string;
105
+ config: unknown;
106
+ }>;
107
+ }, ApiError>>;
108
+ /**
109
+ * Upsert secrets (create or update multiple secrets)
110
+ */
111
+ upsertSecrets(workerId: string, secrets: Array<{
112
+ key: string;
113
+ value: string;
114
+ }>): Promise<Result<{
115
+ secrets: Array<{
116
+ spaceId: string;
117
+ workerId: string;
118
+ key: string;
119
+ createdAt: string;
120
+ }>;
121
+ }, ApiError>>;
122
+ /**
123
+ * List all secrets for a worker (keys only, not values)
124
+ */
125
+ listSecrets(workerId: string): Promise<Result<{
126
+ secrets: Array<{
127
+ spaceId: string;
128
+ workerId: string;
129
+ key: string;
130
+ createdAt: string;
131
+ }>;
132
+ }, ApiError>>;
133
+ /**
134
+ * Delete a secret
135
+ */
136
+ deleteSecret(workerId: string, key: string): Promise<Result<Record<string, never>, ApiError>>;
137
+ /**
138
+ * List all capabilities for a worker
139
+ */
140
+ listCapabilities(workerId: string): Promise<Result<{
141
+ capabilities: Array<{
142
+ _tag: "sync" | "slashCommand";
143
+ key: string;
144
+ }>;
145
+ }, ApiError>>;
146
+ /**
147
+ * Run a capability
148
+ */
149
+ runCapability(workerId: string, capabilityKey: string, functionName: string | null, args: Array<{
150
+ name: string;
151
+ value: string;
152
+ }>, stream: true): Promise<Result<ReadableStream<Uint8Array<ArrayBufferLike>>, ApiError>>;
153
+ runCapability(workerId: string, capabilityKey: string, functionName: string | null, args: Array<{
154
+ name: string;
155
+ value: string;
156
+ }>, stream?: false | undefined): Promise<Result<{
157
+ result: unknown;
158
+ }, ApiError>>;
159
+ /**
160
+ * Download the bundle for a worker
161
+ */
162
+ downloadWorkerBundle(workerId: string): Promise<Result<ReadableStream<Uint8Array<ArrayBufferLike>>, ApiError>>;
163
+ /**
164
+ * List all runs for a worker
165
+ */
166
+ listRunsForWorker(workerId: string): Promise<Result<{
167
+ runs: Array<{
168
+ workerId: string;
169
+ spaceId: string;
170
+ runId: string;
171
+ name: string;
172
+ exitCode: number | null;
173
+ startedAt: string;
174
+ endedAt: string | null;
175
+ }>;
176
+ }, ApiError>>;
177
+ /**
178
+ * Get logs for a specific run
179
+ */
180
+ getRunLogs(workerId: string, runId: string): Promise<Result<{
181
+ logs: string;
182
+ }, ApiError>>;
183
+ }
184
+ export {};
185
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/cli/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAE/D,UAAU,eAAe;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf;AAID,MAAM,WAAW,QAAQ;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;KAChB,CAAC;CACF;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,EACvB,WAAW,EACX,QAAQ,GACR,EAAE;IACF,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B,GAAG,MAAM,CAeT;AAeD;;GAEG;AACH,qBAAa,SAAS;;gBAOT,MAAM,EAAE,eAAe;IAQnC,OAAO,CAAC,UAAU;IAIlB;;OAEG;YACW,KAAK;IAoEnB;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CACxC,MAAM,CACL;QACC,MAAM,EAAE;YACP,QAAQ,EAA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,EAAE,MAAM,GAAG,IAAI,CAAC;YACxB,SAAS,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;SACvB,CAAC,CAAC;KACH,EACD,QAAQ,CACR,CACD;IASD;;OAEG;IACG,UAAU,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACX,OAAO,CACT,MAAM,CACL;QACC,IAAI,EAAE,MAAM,CAAC;KACb,EACD,QAAQ,CACR,CACD;CASD"}
@@ -0,0 +1,315 @@
1
+ import { Result } from "./result.js";
2
+ function baseUrl({
3
+ environment,
4
+ override
5
+ }) {
6
+ if (override) {
7
+ return override;
8
+ }
9
+ switch (environment) {
10
+ case "local":
11
+ return "http://localhost:3000";
12
+ case "staging":
13
+ return "https://staging.notion.so";
14
+ case "dev":
15
+ return "https://dev.notion.so";
16
+ case "prod":
17
+ return "https://www.notion.so";
18
+ }
19
+ }
20
+ function baseApiUrl({
21
+ environment,
22
+ override
23
+ }) {
24
+ return `${baseUrl({ environment, override })}/api/v3`;
25
+ }
26
+ class ApiClient {
27
+ #token;
28
+ #env;
29
+ #baseUrl;
30
+ #cellId;
31
+ #writer;
32
+ constructor(config) {
33
+ this.#token = config.token;
34
+ this.#env = config.environment;
35
+ this.#baseUrl = config.baseUrl;
36
+ this.#cellId = config.cellId;
37
+ this.#writer = config.writer;
38
+ }
39
+ baseApiUrl() {
40
+ return baseApiUrl({ environment: this.#env, override: this.#baseUrl });
41
+ }
42
+ async fetch(endpoint, requestOptions = {}, options) {
43
+ if (!endpoint.startsWith("/")) {
44
+ throw new Error("Endpoint must start with a slash (/)");
45
+ }
46
+ const url = `${this.baseApiUrl()}${endpoint}`;
47
+ this.#writer.debug(`Fetching ${url}`);
48
+ this.#writer.debug(
49
+ `Options: ${JSON.stringify(requestOptions, null, " ")}`
50
+ );
51
+ const headers = new Headers({
52
+ Authorization: `Bearer ${this.#token}`,
53
+ "Content-Type": "application/json",
54
+ "X-Notion-Cell": this.#cellId
55
+ });
56
+ const addlHeaders = headersInitToEntries(requestOptions.headers);
57
+ for (const [key, value] of addlHeaders) {
58
+ headers.append(key, value);
59
+ }
60
+ const response = await fetch(url, {
61
+ method: requestOptions.method ?? "GET",
62
+ headers,
63
+ body: requestOptions.body ? JSON.stringify(requestOptions.body) : null
64
+ });
65
+ this.#writer.debug(`Response: ${response.status} ${response.statusText}`);
66
+ if (!response.ok) {
67
+ const error = await parseApiError(response);
68
+ return Result.fail(error);
69
+ }
70
+ if (options?.stream) {
71
+ if (!response.body) {
72
+ return Result.fail({
73
+ status: response.status,
74
+ statusText: response.statusText,
75
+ message: "No body in response"
76
+ });
77
+ }
78
+ return Result.success(response.body);
79
+ } else {
80
+ const data = await response.json();
81
+ return Result.success(data);
82
+ }
83
+ }
84
+ /**
85
+ * Create a new worker
86
+ */
87
+ async createWorker(name) {
88
+ return this.fetch("/workersCreateWorker", {
89
+ method: "POST",
90
+ body: {
91
+ name
92
+ }
93
+ });
94
+ }
95
+ /**
96
+ * Update an existing worker's bundle
97
+ */
98
+ async updateWorkerBundle(workerId) {
99
+ return this.fetch("/workersUpdateWorker", {
100
+ method: "POST",
101
+ body: {
102
+ workerId
103
+ }
104
+ });
105
+ }
106
+ /**
107
+ * Get a worker by ID
108
+ */
109
+ async getWorker(workerId) {
110
+ return this.fetch("/workersGetWorker", {
111
+ method: "POST",
112
+ body: {
113
+ workerId
114
+ }
115
+ });
116
+ }
117
+ /**
118
+ * List all workers in the space
119
+ */
120
+ async listWorkers() {
121
+ return this.fetch("/workersListWorkers", {
122
+ method: "POST",
123
+ body: {}
124
+ });
125
+ }
126
+ /**
127
+ * Delete a worker
128
+ */
129
+ async deleteWorker(workerId) {
130
+ return this.fetch("/workersDeleteWorker", {
131
+ method: "POST",
132
+ body: {
133
+ workerId
134
+ }
135
+ });
136
+ }
137
+ /**
138
+ * Fetch and save worker capabilities
139
+ */
140
+ async fetchAndSaveCapabilities(workerId) {
141
+ return this.fetch("/workersFetchAndSaveCapabilities", {
142
+ method: "POST",
143
+ body: {
144
+ workerId
145
+ }
146
+ });
147
+ }
148
+ /**
149
+ * Upsert secrets (create or update multiple secrets)
150
+ */
151
+ async upsertSecrets(workerId, secrets) {
152
+ return this.fetch("/workersUpsertSecrets", {
153
+ method: "POST",
154
+ body: {
155
+ workerId,
156
+ secrets
157
+ }
158
+ });
159
+ }
160
+ /**
161
+ * List all secrets for a worker (keys only, not values)
162
+ */
163
+ async listSecrets(workerId) {
164
+ return this.fetch("/workersListSecrets", {
165
+ method: "POST",
166
+ body: {
167
+ workerId
168
+ }
169
+ });
170
+ }
171
+ /**
172
+ * Delete a secret
173
+ */
174
+ async deleteSecret(workerId, key) {
175
+ return this.fetch("/workersDeleteSecret", {
176
+ method: "POST",
177
+ body: {
178
+ workerId,
179
+ key
180
+ }
181
+ });
182
+ }
183
+ /**
184
+ * List all capabilities for a worker
185
+ */
186
+ async listCapabilities(workerId) {
187
+ return this.fetch("/workersListCapabilities", {
188
+ method: "POST",
189
+ body: {
190
+ workerId
191
+ }
192
+ });
193
+ }
194
+ async runCapability(workerId, capabilityKey, functionName, args, stream) {
195
+ if (stream) {
196
+ return this.fetch(
197
+ "/workersRunCapability",
198
+ {
199
+ method: "POST",
200
+ body: {
201
+ workerId,
202
+ capabilityKey,
203
+ functionName,
204
+ args,
205
+ stream
206
+ }
207
+ },
208
+ { stream }
209
+ );
210
+ } else {
211
+ return this.fetch("/workersRunCapability", {
212
+ method: "POST",
213
+ body: {
214
+ workerId,
215
+ capabilityKey,
216
+ functionName,
217
+ args,
218
+ stream
219
+ }
220
+ });
221
+ }
222
+ }
223
+ /**
224
+ * Download the bundle for a worker
225
+ */
226
+ async downloadWorkerBundle(workerId) {
227
+ return this.fetch(
228
+ "/workersGetBundle",
229
+ {
230
+ method: "POST",
231
+ body: {
232
+ workerId
233
+ }
234
+ },
235
+ { stream: true }
236
+ );
237
+ }
238
+ /**
239
+ * List all runs for a worker
240
+ */
241
+ async listRunsForWorker(workerId) {
242
+ return this.fetch("/workersListRunsForWorker", {
243
+ method: "POST",
244
+ body: {
245
+ workerId
246
+ }
247
+ });
248
+ }
249
+ /**
250
+ * Get logs for a specific run
251
+ */
252
+ async getRunLogs(workerId, runId) {
253
+ return this.fetch("/workersGetRunLogs", {
254
+ method: "POST",
255
+ body: {
256
+ workerId,
257
+ runId
258
+ }
259
+ });
260
+ }
261
+ }
262
+ function headersInitToEntries(headersInit) {
263
+ if (headersInit instanceof Headers) {
264
+ return Array.from(headersInit.entries());
265
+ }
266
+ if (Array.isArray(headersInit)) {
267
+ return headersInit;
268
+ }
269
+ if (headersInit === void 0) {
270
+ return [];
271
+ }
272
+ const entries = [];
273
+ for (const [key, value] of Object.entries(headersInit)) {
274
+ if (value === void 0) {
275
+ continue;
276
+ }
277
+ entries.push([key, value]);
278
+ }
279
+ return entries;
280
+ }
281
+ async function parseApiError(response) {
282
+ const errorText = await response.text();
283
+ const message = `[${response.status}] ${response.statusText}: ${errorText}`;
284
+ const error = {
285
+ status: response.status,
286
+ statusText: response.statusText,
287
+ message
288
+ };
289
+ if (response.status === 400) {
290
+ const validationError = parseValidationError(errorText);
291
+ if (validationError) {
292
+ error.validationError = validationError;
293
+ }
294
+ }
295
+ return error;
296
+ }
297
+ function parseValidationError(errorText) {
298
+ try {
299
+ const errorJson = JSON.parse(errorText);
300
+ if (errorJson.name === "ValidationError" && errorJson.debugMessage && errorJson.errorId) {
301
+ return {
302
+ errorId: errorJson.errorId,
303
+ name: errorJson.name,
304
+ debugMessage: errorJson.debugMessage,
305
+ message: errorJson.message
306
+ };
307
+ }
308
+ } catch {
309
+ }
310
+ return void 0;
311
+ }
312
+ export {
313
+ ApiClient,
314
+ baseUrl
315
+ };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Represents the union of *either* the value returned
3
+ * from some function *or* an arbitrary error emitted during computation.
4
+ */
5
+ /**
6
+ * The left side of the Result type, the value.
7
+ */
8
+ export interface Success<T> {
9
+ _tag: "success";
10
+ value: T;
11
+ }
12
+ /**
13
+ * The right side of the Result type, the error.
14
+ */
15
+ export interface Fail<E> {
16
+ _tag: "fail";
17
+ error: E;
18
+ }
19
+ export type Result<S, E> = Success<S> | Fail<E>;
20
+ /**
21
+ * Type predicates and helpers for the Result type.
22
+ */
23
+ export declare const Result: {
24
+ success<S>(value: S): Success<S>;
25
+ fail<E>(error: E): Fail<E>;
26
+ /**
27
+ * Success (left side) type predicate for the Result type.
28
+ */
29
+ isSuccess<S, E>(result: Result<S, E>): result is Success<S>;
30
+ /**
31
+ * Fail (right side) type predicate for the Result type.
32
+ */
33
+ isFail<S, E>(result: Result<S, E>): result is Fail<E>;
34
+ /**
35
+ * Unwrap a Result value, throwing the error if it's set.
36
+ */
37
+ unwrap<S, E>(result: Result<S, E>): S;
38
+ /**
39
+ * Unwrap a Result value, or return a default value if an error is set.
40
+ */
41
+ unwrapOr<S, E>(result: Result<S, E>, defaultValue: S): S;
42
+ };
43
+ //# sourceMappingURL=result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../../src/cli/api/result.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,OAAO,CAAC,CAAC;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,CAAC,CAAC;CACT;AAED;;GAEG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,CAAC,CAAC;CACT;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAEhD;;GAEG;AACH,eAAO,MAAM,MAAM;YACV,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;SAI3B,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAI1B;;OAEG;cACO,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC;IAI3D;;OAEG;WACI,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC;IAIrD;;OAEG;WACI,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;IAQrC;;OAEG;aACM,CAAC,EAAE,CAAC,UAAU,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC;CAOxD,CAAC"}
@@ -0,0 +1,43 @@
1
+ const Result = {
2
+ success(value) {
3
+ return { _tag: "success", value };
4
+ },
5
+ fail(error) {
6
+ return { _tag: "fail", error };
7
+ },
8
+ /**
9
+ * Success (left side) type predicate for the Result type.
10
+ */
11
+ isSuccess(result) {
12
+ return result._tag === "success";
13
+ },
14
+ /**
15
+ * Fail (right side) type predicate for the Result type.
16
+ */
17
+ isFail(result) {
18
+ return result._tag === "fail";
19
+ },
20
+ /**
21
+ * Unwrap a Result value, throwing the error if it's set.
22
+ */
23
+ unwrap(result) {
24
+ if (Result.isFail(result)) {
25
+ throw result.error;
26
+ } else {
27
+ return result.value;
28
+ }
29
+ },
30
+ /**
31
+ * Unwrap a Result value, or return a default value if an error is set.
32
+ */
33
+ unwrapOr(result, defaultValue) {
34
+ if (Result.isFail(result)) {
35
+ return defaultValue;
36
+ } else {
37
+ return result.value;
38
+ }
39
+ }
40
+ };
41
+ export {
42
+ Result
43
+ };
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/cli/bin/cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { run } from "@stricli/core";
3
+ import { buildContext } from "../context.js";
4
+ import { app } from "../routes.js";
5
+ await run(app, process.argv.slice(2), buildContext(process));
@@ -0,0 +1,2 @@
1
+ export declare const authCommands: import("@stricli/core").RouteMap<import("../context.js").LocalContext>;
2
+ //# sourceMappingURL=auth.d.ts.map