@zeabur/ai-sdk 1.0.0

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 (50) hide show
  1. package/README.md +244 -0
  2. package/dist/core/command.d.ts +18 -0
  3. package/dist/core/command.d.ts.map +1 -0
  4. package/dist/core/command.js +34 -0
  5. package/dist/core/command.js.map +1 -0
  6. package/dist/core/deploy.d.ts +175 -0
  7. package/dist/core/deploy.d.ts.map +1 -0
  8. package/dist/core/deploy.js +96 -0
  9. package/dist/core/deploy.js.map +1 -0
  10. package/dist/core/files.d.ts +94 -0
  11. package/dist/core/files.d.ts.map +1 -0
  12. package/dist/core/files.js +200 -0
  13. package/dist/core/files.js.map +1 -0
  14. package/dist/core/graphql.d.ts +15 -0
  15. package/dist/core/graphql.d.ts.map +1 -0
  16. package/dist/core/graphql.js +13 -0
  17. package/dist/core/graphql.js.map +1 -0
  18. package/dist/core/index.d.ts +411 -0
  19. package/dist/core/index.d.ts.map +1 -0
  20. package/dist/core/index.js +65 -0
  21. package/dist/core/index.js.map +1 -0
  22. package/dist/core/logs.d.ts +42 -0
  23. package/dist/core/logs.d.ts.map +1 -0
  24. package/dist/core/logs.js +76 -0
  25. package/dist/core/logs.js.map +1 -0
  26. package/dist/core/render.d.ts +81 -0
  27. package/dist/core/render.d.ts.map +1 -0
  28. package/dist/core/render.js +68 -0
  29. package/dist/core/render.js.map +1 -0
  30. package/dist/core/template.d.ts +18 -0
  31. package/dist/core/template.d.ts.map +1 -0
  32. package/dist/core/template.js +31 -0
  33. package/dist/core/template.js.map +1 -0
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +40 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/types/index.d.ts +46 -0
  39. package/dist/types/index.d.ts.map +1 -0
  40. package/dist/types/index.js +2 -0
  41. package/dist/types/index.js.map +1 -0
  42. package/dist/utils/context.d.ts +22 -0
  43. package/dist/utils/context.d.ts.map +1 -0
  44. package/dist/utils/context.js +37 -0
  45. package/dist/utils/context.js.map +1 -0
  46. package/dist/utils/demo.d.ts +15 -0
  47. package/dist/utils/demo.d.ts.map +1 -0
  48. package/dist/utils/demo.js +113 -0
  49. package/dist/utils/demo.js.map +1 -0
  50. package/package.json +43 -0
package/README.md ADDED
@@ -0,0 +1,244 @@
1
+ # Zeabur AI SDK
2
+
3
+ The Zeabur AI SDK is a TypeScript toolkit designed to help you build AI-powered deployment agents and automation tools using popular frameworks like Next.js, React, and Node.js.
4
+
5
+ ## Installation
6
+
7
+ You will need Node.js 18+ and npm (or another package manager) installed on your local development machine.
8
+
9
+ ```bash
10
+ npm install @zeabur/ai-sdk
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Executing Commands
16
+
17
+ ```typescript
18
+ import { zeaburTools, createZeaburContext } from '@zeabur/ai-sdk';
19
+
20
+ const context = createZeaburContext('your-api-token');
21
+
22
+ const result = await zeaburTools.executeCommand({
23
+ serviceId: 'service-123',
24
+ environmentId: 'env-456',
25
+ command: ['ls', '-la']
26
+ }, context);
27
+ ```
28
+
29
+ ### Deploying from Specifications
30
+
31
+ ```typescript
32
+ import { zeaburTools, createZeaburContext } from '@zeabur/ai-sdk';
33
+
34
+ const context = createZeaburContext('your-api-token');
35
+
36
+ const result = await zeaburTools.deployFromSpecification({
37
+ projectID: 'project-123',
38
+ specification: {
39
+ services: [
40
+ {
41
+ name: 'web',
42
+ template: 'NODEJS',
43
+ // ... service configuration
44
+ }
45
+ ]
46
+ }
47
+ }, context);
48
+ ```
49
+
50
+ ### Monitoring and Logs
51
+
52
+ ```typescript
53
+ import { zeaburTools } from '@zeabur/ai-sdk';
54
+
55
+ // Get build logs
56
+ const buildLogs = await zeaburTools.getBuildLogs({
57
+ projectID: 'project-123',
58
+ deploymentID: 'deploy-456'
59
+ }, context);
60
+
61
+ // Get runtime logs
62
+ const runtimeLogs = await zeaburTools.getRuntimeLogs({
63
+ serviceID: 'service-123',
64
+ environmentID: 'env-456',
65
+ type: 'BUILD'
66
+ }, context);
67
+
68
+ // Get deployment history
69
+ const deployments = await zeaburTools.getDeployments({
70
+ serviceId: 'service-123'
71
+ }, context);
72
+ ```
73
+
74
+ ### Working with Templates
75
+
76
+ ```typescript
77
+ import { zeaburTools } from '@zeabur/ai-sdk';
78
+
79
+ const templates = await zeaburTools.searchTemplate({
80
+ query: 'nextjs'
81
+ }, context);
82
+ ```
83
+
84
+ ## AI SDK Integration
85
+
86
+ The Zeabur AI SDK works seamlessly with the Vercel AI SDK to build intelligent deployment agents.
87
+
88
+ ### Agent Example
89
+
90
+ ```typescript
91
+ import { ToolLoopAgent } from 'ai';
92
+ import { zeaburTools, createZeaburContext } from '@zeabur/ai-sdk';
93
+ import { openai } from '@ai-sdk/openai';
94
+
95
+ const zeaburContext = createZeaburContext(process.env.ZEABUR_API_TOKEN);
96
+
97
+ const deploymentAgent = new ToolLoopAgent({
98
+ model: openai('gpt-4o'),
99
+ system: 'You are a Zeabur deployment assistant.',
100
+ tools: {
101
+ execute_command: {
102
+ description: 'Execute commands on Zeabur services',
103
+ inputSchema: zeaburSchemas.executeCommandSchema,
104
+ execute: async (input) => {
105
+ return await zeaburTools.executeCommand(input, zeaburContext);
106
+ }
107
+ },
108
+ deploy_service: {
109
+ description: 'Deploy services on Zeabur',
110
+ inputSchema: zeaburSchemas.deployFromSpecificationSchema,
111
+ execute: async (input) => {
112
+ return await zeaburTools.deployFromSpecification(input, zeaburContext);
113
+ }
114
+ }
115
+ }
116
+ });
117
+ ```
118
+
119
+ ### Next.js API Route
120
+
121
+ ```typescript
122
+ // app/api/chat/route.ts
123
+ import { createZeaburContext, zeaburTools } from '@zeabur/ai-sdk';
124
+ import { streamText } from 'ai';
125
+ import { openai } from '@ai-sdk/openai';
126
+
127
+ export async function POST(req: Request) {
128
+ const { messages } = await req.json();
129
+
130
+ const zeaburContext = createZeaburContext(
131
+ process.env.ZEABUR_API_TOKEN
132
+ );
133
+
134
+ const result = streamText({
135
+ model: openai('gpt-4o'),
136
+ messages,
137
+ tools: {
138
+ execute_command: {
139
+ description: 'Execute commands on services',
140
+ parameters: zeaburSchemas.executeCommandSchema,
141
+ execute: async (args) => {
142
+ return await zeaburTools.executeCommand(args, zeaburContext);
143
+ }
144
+ }
145
+ }
146
+ });
147
+
148
+ return result.toDataStreamResponse();
149
+ }
150
+ ```
151
+
152
+ ## Demo Mode
153
+
154
+ Try the SDK without authentication - perfect for testing and learning:
155
+
156
+ ```typescript
157
+ import { zeaburTools, createZeaburDemoContext } from '@zeabur/ai-sdk';
158
+
159
+ // No API token required - returns mock data
160
+ const demoContext = createZeaburDemoContext();
161
+
162
+ const result = await zeaburTools.executeCommand({
163
+ serviceId: 'demo-service',
164
+ environmentId: 'demo-env',
165
+ command: ['ls', '-la']
166
+ }, demoContext);
167
+
168
+ console.log(result); // Returns: "Mock command output: Hello from demo mode!"
169
+ ```
170
+
171
+ ## Available Tools
172
+
173
+ ### Core Operations
174
+ - **executeCommand** - Execute shell commands on services
175
+ - **deployFromSpecification** - Deploy services from YAML/JSON specifications
176
+ - **executeGraphQL** - Run custom GraphQL queries
177
+
178
+ ### File System
179
+ - **decideFilesystem** - Determine GitHub or Upload ID
180
+ - **listFiles** - List directory contents
181
+ - **readFile** - Read file with pagination support
182
+ - **fileDirRead** - Execute safe read-only commands
183
+
184
+ ### Monitoring
185
+ - **getBuildLogs** - Fetch build logs for deployments
186
+ - **getRuntimeLogs** - Get service runtime logs
187
+ - **getDeployments** - List deployment history
188
+
189
+ ### Templates
190
+ - **searchTemplate** - Search deployment templates
191
+
192
+ ### UI Components
193
+ - **renderRegionSelector** - Region selection interface
194
+ - **renderProjectSelector** - Project selection interface
195
+ - **renderServiceCard** - Service status cards
196
+ - **renderDockerfile** - Syntax-highlighted Dockerfile viewer
197
+ - **renderRecommendation** - Smart recommendation buttons
198
+ - **renderFloatingButton** - Floating action buttons
199
+
200
+ ## Authentication
201
+
202
+ The SDK requires a Zeabur API token to be explicitly passed by your application:
203
+
204
+ ```typescript
205
+ // ✅ Correct - Your application manages the token
206
+ const token = process.env.ZEABUR_API_TOKEN;
207
+ const context = createZeaburContext(token);
208
+
209
+ // Or from cookies, headers, database, etc.
210
+ const token = cookies().get('token')?.value;
211
+ const context = createZeaburContext(token);
212
+ ```
213
+
214
+ **Note:** This SDK is a library and does NOT read environment variables directly. The consuming application is responsible for managing authentication.
215
+
216
+ ## Development
217
+
218
+ ```bash
219
+ npm install # Install dependencies
220
+ npm run build # Build TypeScript
221
+ npm run demo # Run demo mode
222
+ npm run type-check # Type checking
223
+ npm run lint # Linting
224
+ ```
225
+
226
+ ## Community
227
+
228
+ Join the Zeabur community to ask questions, share ideas, and get help:
229
+
230
+ - [Discord](https://discord.gg/zeabur)
231
+ - [GitHub Discussions](https://github.com/zeabur/zeabur/discussions)
232
+ - [Documentation](https://zeabur.com/docs)
233
+
234
+ ## Contributing
235
+
236
+ Contributions to the Zeabur AI SDK are welcome and highly appreciated. Please check out our contributing guidelines before getting started.
237
+
238
+ ## Authors
239
+
240
+ This library is created by the Zeabur team, with contributions from the Open Source Community.
241
+
242
+ ## License
243
+
244
+ MIT
@@ -0,0 +1,18 @@
1
+ import { z } from "zod";
2
+ import { ZeaburContext } from "../types/index.js";
3
+ export declare const executeCommandSchema: z.ZodObject<{
4
+ serviceId: z.ZodString;
5
+ environmentId: z.ZodString;
6
+ command: z.ZodArray<z.ZodString, "many">;
7
+ }, "strip", z.ZodTypeAny, {
8
+ serviceId: string;
9
+ environmentId: string;
10
+ command: string[];
11
+ }, {
12
+ serviceId: string;
13
+ environmentId: string;
14
+ command: string[];
15
+ }>;
16
+ export type ExecuteCommandInput = z.infer<typeof executeCommandSchema>;
17
+ export declare function executeCommand(args: ExecuteCommandInput, context: ZeaburContext): Promise<string>;
18
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/core/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAIxE,eAAO,MAAM,oBAAoB;;;;;;;;;;;;EAI/B,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEvE,wBAAsB,cAAc,CAClC,IAAI,EAAE,mBAAmB,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,CAAC,CA+BjB"}
@@ -0,0 +1,34 @@
1
+ import { z } from "zod";
2
+ const MAX_COMMAND_RESPONSE_LENGTH = 2048;
3
+ export const executeCommandSchema = z.object({
4
+ serviceId: z.string(),
5
+ environmentId: z.string(),
6
+ command: z.array(z.string())
7
+ });
8
+ export async function executeCommand(args, context) {
9
+ const query = `
10
+ mutation ExecuteCommand($serviceId: ObjectID!, $environmentId: ObjectID!, $command: [String!]!) {
11
+ executeCommand(serviceID: $serviceId, environmentID: $environmentId, command: $command) {
12
+ exitCode
13
+ output
14
+ }
15
+ }
16
+ `;
17
+ const variables = {
18
+ serviceId: args.serviceId,
19
+ environmentId: args.environmentId,
20
+ command: args.command
21
+ };
22
+ const response = await context.graphql.query(query, variables);
23
+ if (response.errors) {
24
+ throw new Error(JSON.stringify(response.errors));
25
+ }
26
+ const output = response.data.executeCommand.output ?? "";
27
+ let truncatedResponse = output.slice(0, MAX_COMMAND_RESPONSE_LENGTH)
28
+ + (output.length > MAX_COMMAND_RESPONSE_LENGTH ? '... (truncated)' : '');
29
+ if (response.data.executeCommand.exitCode !== 0) {
30
+ truncatedResponse = `(exit code ${response.data.executeCommand.exitCode}) ` + truncatedResponse;
31
+ }
32
+ return truncatedResponse;
33
+ }
34
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/core/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,K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AAC;IAClG,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,175 @@
1
+ import { z } from "zod";
2
+ import { ZeaburContext } from "../types/index.js";
3
+ export declare const deployFromSpecificationSchema: z.ZodObject<{
4
+ service_id: z.ZodString;
5
+ source: z.ZodObject<{
6
+ type: z.ZodEnum<["BUILD_FROM_SOURCE", "DOCKER_IMAGE"]>;
7
+ build_from_source: z.ZodOptional<z.ZodObject<{
8
+ source: z.ZodObject<{
9
+ type: z.ZodEnum<["GITHUB", "UPLOAD_ID"]>;
10
+ github: z.ZodOptional<z.ZodObject<{
11
+ repo_id: z.ZodNumber;
12
+ ref: z.ZodOptional<z.ZodString>;
13
+ }, "strip", z.ZodTypeAny, {
14
+ repo_id: number;
15
+ ref?: string | undefined;
16
+ }, {
17
+ repo_id: number;
18
+ ref?: string | undefined;
19
+ }>>;
20
+ upload_id: z.ZodOptional<z.ZodString>;
21
+ }, "strip", z.ZodTypeAny, {
22
+ type: "GITHUB" | "UPLOAD_ID";
23
+ github?: {
24
+ repo_id: number;
25
+ ref?: string | undefined;
26
+ } | undefined;
27
+ upload_id?: string | undefined;
28
+ }, {
29
+ type: "GITHUB" | "UPLOAD_ID";
30
+ github?: {
31
+ repo_id: number;
32
+ ref?: string | undefined;
33
+ } | undefined;
34
+ upload_id?: string | undefined;
35
+ }>;
36
+ dockerfile: z.ZodObject<{
37
+ content: z.ZodOptional<z.ZodNullable<z.ZodString>>;
38
+ path: z.ZodOptional<z.ZodNullable<z.ZodString>>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ path?: string | null | undefined;
41
+ content?: string | null | undefined;
42
+ }, {
43
+ path?: string | null | undefined;
44
+ content?: string | null | undefined;
45
+ }>;
46
+ }, "strip", z.ZodTypeAny, {
47
+ dockerfile: {
48
+ path?: string | null | undefined;
49
+ content?: string | null | undefined;
50
+ };
51
+ source: {
52
+ type: "GITHUB" | "UPLOAD_ID";
53
+ github?: {
54
+ repo_id: number;
55
+ ref?: string | undefined;
56
+ } | undefined;
57
+ upload_id?: string | undefined;
58
+ };
59
+ }, {
60
+ dockerfile: {
61
+ path?: string | null | undefined;
62
+ content?: string | null | undefined;
63
+ };
64
+ source: {
65
+ type: "GITHUB" | "UPLOAD_ID";
66
+ github?: {
67
+ repo_id: number;
68
+ ref?: string | undefined;
69
+ } | undefined;
70
+ upload_id?: string | undefined;
71
+ };
72
+ }>>;
73
+ docker_image: z.ZodOptional<z.ZodString>;
74
+ }, "strip", z.ZodTypeAny, {
75
+ type: "BUILD_FROM_SOURCE" | "DOCKER_IMAGE";
76
+ build_from_source?: {
77
+ dockerfile: {
78
+ path?: string | null | undefined;
79
+ content?: string | null | undefined;
80
+ };
81
+ source: {
82
+ type: "GITHUB" | "UPLOAD_ID";
83
+ github?: {
84
+ repo_id: number;
85
+ ref?: string | undefined;
86
+ } | undefined;
87
+ upload_id?: string | undefined;
88
+ };
89
+ } | undefined;
90
+ docker_image?: string | undefined;
91
+ }, {
92
+ type: "BUILD_FROM_SOURCE" | "DOCKER_IMAGE";
93
+ build_from_source?: {
94
+ dockerfile: {
95
+ path?: string | null | undefined;
96
+ content?: string | null | undefined;
97
+ };
98
+ source: {
99
+ type: "GITHUB" | "UPLOAD_ID";
100
+ github?: {
101
+ repo_id: number;
102
+ ref?: string | undefined;
103
+ } | undefined;
104
+ upload_id?: string | undefined;
105
+ };
106
+ } | undefined;
107
+ docker_image?: string | undefined;
108
+ }>;
109
+ env: z.ZodArray<z.ZodObject<{
110
+ key: z.ZodString;
111
+ value: z.ZodString;
112
+ expose: z.ZodDefault<z.ZodBoolean>;
113
+ }, "strip", z.ZodTypeAny, {
114
+ value: string;
115
+ key: string;
116
+ expose: boolean;
117
+ }, {
118
+ value: string;
119
+ key: string;
120
+ expose?: boolean | undefined;
121
+ }>, "many">;
122
+ }, "strip", z.ZodTypeAny, {
123
+ service_id: string;
124
+ source: {
125
+ type: "BUILD_FROM_SOURCE" | "DOCKER_IMAGE";
126
+ build_from_source?: {
127
+ dockerfile: {
128
+ path?: string | null | undefined;
129
+ content?: string | null | undefined;
130
+ };
131
+ source: {
132
+ type: "GITHUB" | "UPLOAD_ID";
133
+ github?: {
134
+ repo_id: number;
135
+ ref?: string | undefined;
136
+ } | undefined;
137
+ upload_id?: string | undefined;
138
+ };
139
+ } | undefined;
140
+ docker_image?: string | undefined;
141
+ };
142
+ env: {
143
+ value: string;
144
+ key: string;
145
+ expose: boolean;
146
+ }[];
147
+ }, {
148
+ service_id: string;
149
+ source: {
150
+ type: "BUILD_FROM_SOURCE" | "DOCKER_IMAGE";
151
+ build_from_source?: {
152
+ dockerfile: {
153
+ path?: string | null | undefined;
154
+ content?: string | null | undefined;
155
+ };
156
+ source: {
157
+ type: "GITHUB" | "UPLOAD_ID";
158
+ github?: {
159
+ repo_id: number;
160
+ ref?: string | undefined;
161
+ } | undefined;
162
+ upload_id?: string | undefined;
163
+ };
164
+ } | undefined;
165
+ docker_image?: string | undefined;
166
+ };
167
+ env: {
168
+ value: string;
169
+ key: string;
170
+ expose?: boolean | undefined;
171
+ }[];
172
+ }>;
173
+ export type DeployFromSpecificationInput = z.infer<typeof deployFromSpecificationSchema>;
174
+ export declare function deployFromSpecification(args: DeployFromSpecificationInput, context: ZeaburContext): Promise<string>;
175
+ //# sourceMappingURL=deploy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/core/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAwC,MAAM,mBAAmB,CAAC;AAoBxF,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBxC,CAAC;AAEH,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEzF,wBAAsB,uBAAuB,CAC3C,IAAI,EAAE,4BAA4B,EAClC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,MAAM,CAAC,CAsDjB"}
@@ -0,0 +1,96 @@
1
+ import { z } from "zod";
2
+ import { decideFilesystemFromSchema } from "./files.js";
3
+ const DEPLOY_FROM_SPECIFICATION_GQL = `
4
+ mutation DeployFromSpecification($serviceId: ObjectID!, $specification: DeploymentSpecification!) {
5
+ deployFromSpecification(serviceID: $serviceId, specification: $specification) {
6
+ deploymentID
7
+ }
8
+ }
9
+ `;
10
+ const sourceSchema = z.object({
11
+ type: z.enum(["GITHUB", "UPLOAD_ID"]),
12
+ github: z.object({
13
+ repo_id: z.number(),
14
+ ref: z.string().optional(),
15
+ }).optional(),
16
+ upload_id: z.string().optional(),
17
+ });
18
+ export const deployFromSpecificationSchema = z.object({
19
+ service_id: z.string(),
20
+ source: z.object({
21
+ type: z.enum(["BUILD_FROM_SOURCE", "DOCKER_IMAGE"]),
22
+ build_from_source: z.object({
23
+ source: sourceSchema,
24
+ dockerfile: z.object({
25
+ content: z.string().nullable().optional(),
26
+ path: z.string().nullable().optional(),
27
+ }),
28
+ }).optional(),
29
+ docker_image: z.string().optional(),
30
+ }),
31
+ env: z.array(z.object({
32
+ key: z.string(),
33
+ value: z.string(),
34
+ expose: z.boolean().default(false),
35
+ })),
36
+ });
37
+ export async function deployFromSpecification(args, context) {
38
+ let spec = {
39
+ source: {},
40
+ env: args.env.map((e) => ({
41
+ key: e.key,
42
+ default: e.value,
43
+ expose: e.expose,
44
+ })),
45
+ };
46
+ switch (args.source.type) {
47
+ case "BUILD_FROM_SOURCE":
48
+ if (!args.source.build_from_source) {
49
+ throw new Error("When the source type is 'BUILD_FROM_SOURCE', you must specify the 'build_from_source' object.");
50
+ }
51
+ const fs = decideFilesystemFromSchema(context.graphql, args.source.build_from_source.source);
52
+ const dockerfileContent = await getDockerfileContent(fs, args.source.build_from_source.dockerfile);
53
+ switch (args.source.build_from_source.source.type) {
54
+ case "GITHUB":
55
+ spec.source = {
56
+ source: "GITHUB",
57
+ repoID: args.source.build_from_source.source.github?.repo_id,
58
+ branch: args.source.build_from_source.source.github?.ref ?? undefined,
59
+ dockerfile: dockerfileContent,
60
+ };
61
+ break;
62
+ case "UPLOAD_ID":
63
+ spec.source = {
64
+ source: "UPLOAD_ID",
65
+ uploadID: args.source.build_from_source.source.upload_id ?? undefined,
66
+ dockerfile: dockerfileContent,
67
+ };
68
+ break;
69
+ default:
70
+ throw new Error("Invalid 'build_from_source' source type");
71
+ }
72
+ break;
73
+ case "DOCKER_IMAGE":
74
+ spec.source = {
75
+ image: args.source.docker_image ?? undefined,
76
+ };
77
+ break;
78
+ default:
79
+ throw new Error("Invalid 'source' type");
80
+ }
81
+ const result = await context.graphql.query(DEPLOY_FROM_SPECIFICATION_GQL, {
82
+ serviceId: args.service_id,
83
+ specification: spec,
84
+ });
85
+ return JSON.stringify(result);
86
+ }
87
+ async function getDockerfileContent(fs, dockerfile) {
88
+ if (dockerfile.content) {
89
+ return dockerfile.content;
90
+ }
91
+ if (dockerfile.path) {
92
+ return await fs.read(dockerfile.path);
93
+ }
94
+ throw new Error("No Dockerfile content provided. You should specify 'content' or 'path' in the Dockerfile object.");
95
+ }
96
+ //# sourceMappingURL=deploy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.js","sourceRoot":"","sources":["../../src/core/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,6BAA6B,GAAG;;;;;;CAMrC,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC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AC,iBAAiB,CAAC,MAAM,CAAC,SAAS,IAAI,SAAS;wBACrE,UAAU,EAAE,iBAAiB;qBAC9B,CAAC;oBACF,MAAM;gBACR;oBACE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;YAC/D,CAAC;YACD,MAAM;QACR,KAAK,cAAc;YACjB,IAAI,CAAC,MAAM,GAAG;gBACZ,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,SAAS;aAC7C,CAAC;YACF,MAAM;QACR;YACE,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE;QACxE,SAAS,EAAE,IAAI,CAAC,UAAU;QAC1B,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAChC,CAAC;AAED,KAAK,UAAU,oBAAoB,CAAC,EAAO,EAAE,UAA6D;IACxG,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,UAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;QACpB,OAAO,MAAM,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAC;AACtH,CAAC"}
@@ -0,0 +1,94 @@
1
+ import { z } from "zod";
2
+ import { ZeaburContext, Filesystem, GraphQLClient } from "../types/index.js";
3
+ export declare class UploadIdFilesystem implements Filesystem {
4
+ private graphql;
5
+ private uploadId;
6
+ constructor(graphql: GraphQLClient, uploadId: string);
7
+ list(path: string): Promise<string[]>;
8
+ read(path: string): Promise<string>;
9
+ }
10
+ export declare class GitHubFilesystem implements Filesystem {
11
+ private graphql;
12
+ private repoId;
13
+ private ref;
14
+ constructor(graphql: GraphQLClient, repoId: number, ref: string | null);
15
+ list(path: string): Promise<string[]>;
16
+ read(path: string): Promise<string>;
17
+ }
18
+ export declare function decideFilesystemFromSchema(graphql: GraphQLClient, source: any): Filesystem;
19
+ export declare const decideFilesystemSchema: z.ZodObject<{
20
+ type: z.ZodEnum<["GITHUB", "UPLOAD_ID"]>;
21
+ github: z.ZodOptional<z.ZodObject<{
22
+ repo_id: z.ZodNumber;
23
+ ref: z.ZodOptional<z.ZodString>;
24
+ }, "strip", z.ZodTypeAny, {
25
+ repo_id: number;
26
+ ref?: string | undefined;
27
+ }, {
28
+ repo_id: number;
29
+ ref?: string | undefined;
30
+ }>>;
31
+ upload_id: z.ZodOptional<z.ZodString>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ type: "GITHUB" | "UPLOAD_ID";
34
+ github?: {
35
+ repo_id: number;
36
+ ref?: string | undefined;
37
+ } | undefined;
38
+ upload_id?: string | undefined;
39
+ }, {
40
+ type: "GITHUB" | "UPLOAD_ID";
41
+ github?: {
42
+ repo_id: number;
43
+ ref?: string | undefined;
44
+ } | undefined;
45
+ upload_id?: string | undefined;
46
+ }>;
47
+ export type DecideFilesystemInput = z.infer<typeof decideFilesystemSchema>;
48
+ export declare function decideFilesystem(args: DecideFilesystemInput, context: ZeaburContext): Promise<string>;
49
+ export declare const listFilesSchema: z.ZodObject<{
50
+ path: z.ZodString;
51
+ limit: z.ZodDefault<z.ZodNumber>;
52
+ offset: z.ZodDefault<z.ZodNumber>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ path: string;
55
+ limit: number;
56
+ offset: number;
57
+ }, {
58
+ path: string;
59
+ limit?: number | undefined;
60
+ offset?: number | undefined;
61
+ }>;
62
+ export type ListFilesInput = z.infer<typeof listFilesSchema>;
63
+ export declare function listFiles(args: ListFilesInput, context: ZeaburContext): Promise<string>;
64
+ export declare const readFileSchema: z.ZodObject<{
65
+ path: z.ZodString;
66
+ limit: z.ZodDefault<z.ZodNumber>;
67
+ offset: z.ZodDefault<z.ZodNumber>;
68
+ }, "strip", z.ZodTypeAny, {
69
+ path: string;
70
+ limit: number;
71
+ offset: number;
72
+ }, {
73
+ path: string;
74
+ limit?: number | undefined;
75
+ offset?: number | undefined;
76
+ }>;
77
+ export type ReadFileInput = z.infer<typeof readFileSchema>;
78
+ export declare function readFile(args: ReadFileInput, context: ZeaburContext): Promise<string>;
79
+ export declare const fileDirReadSchema: z.ZodObject<{
80
+ serviceId: z.ZodString;
81
+ environmentId: z.ZodString;
82
+ command: z.ZodArray<z.ZodString, "many">;
83
+ }, "strip", z.ZodTypeAny, {
84
+ serviceId: string;
85
+ environmentId: string;
86
+ command: string[];
87
+ }, {
88
+ serviceId: string;
89
+ environmentId: string;
90
+ command: string[];
91
+ }>;
92
+ export type FileDirReadInput = z.infer<typeof fileDirReadSchema>;
93
+ export declare function fileDirRead(args: FileDirReadInput, context: ZeaburContext): Promise<string>;
94
+ //# sourceMappingURL=files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/core/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAInG,qBAAa,kBAAmB,YAAW,UAAU;IACnD,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,QAAQ,CAAS;gBAEb,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM;IAK9C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAkBrC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAkB1C;AAED,qBAAa,gBAAiB,YAAW,UAAU;IACjD,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,GAAG,CAA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