@renderinc/sdk 0.1.0 → 0.2.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 (100) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +15 -15
  3. package/biome.json +84 -0
  4. package/dist/experimental/blob/api.d.ts +11 -0
  5. package/dist/experimental/blob/api.d.ts.map +1 -0
  6. package/dist/experimental/blob/api.js +44 -0
  7. package/dist/experimental/blob/client.d.ts +21 -0
  8. package/dist/experimental/blob/client.d.ts.map +1 -0
  9. package/dist/experimental/blob/client.js +127 -0
  10. package/dist/experimental/blob/index.d.ts +5 -0
  11. package/dist/experimental/blob/index.d.ts.map +1 -0
  12. package/dist/experimental/blob/index.js +8 -0
  13. package/dist/experimental/blob/types.d.ts +49 -0
  14. package/dist/experimental/blob/types.d.ts.map +1 -0
  15. package/dist/experimental/blob/types.js +2 -0
  16. package/dist/experimental/experimental.d.ts +8 -0
  17. package/dist/experimental/experimental.d.ts.map +1 -0
  18. package/dist/experimental/experimental.js +10 -0
  19. package/dist/experimental/index.d.ts +3 -0
  20. package/dist/experimental/index.d.ts.map +1 -0
  21. package/dist/experimental/index.js +9 -0
  22. package/dist/generated/schema.d.ts +9782 -0
  23. package/dist/generated/schema.d.ts.map +1 -0
  24. package/dist/generated/schema.js +2 -0
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +5 -2
  28. package/dist/render.d.ts +2 -0
  29. package/dist/render.d.ts.map +1 -1
  30. package/dist/render.js +4 -2
  31. package/dist/utils/create-api-client.d.ts +1 -1
  32. package/dist/utils/create-api-client.d.ts.map +1 -1
  33. package/dist/utils/create-api-client.js +2 -0
  34. package/dist/version.d.ts +3 -0
  35. package/dist/version.d.ts.map +1 -0
  36. package/dist/version.js +23 -0
  37. package/dist/workflows/client/client.d.ts +1 -1
  38. package/dist/workflows/client/client.d.ts.map +1 -1
  39. package/dist/workflows/client/sse.d.ts +2 -2
  40. package/dist/workflows/client/sse.d.ts.map +1 -1
  41. package/dist/workflows/client/sse.js +2 -0
  42. package/dist/workflows/client/types.d.ts +1 -1
  43. package/dist/workflows/client/types.d.ts.map +1 -1
  44. package/dist/workflows/executor.d.ts +2 -2
  45. package/dist/workflows/executor.d.ts.map +1 -1
  46. package/dist/workflows/registry.d.ts +1 -1
  47. package/dist/workflows/registry.d.ts.map +1 -1
  48. package/dist/workflows/registry.js +13 -6
  49. package/dist/workflows/runner.d.ts.map +1 -1
  50. package/dist/workflows/runner.js +2 -0
  51. package/dist/workflows/schema.d.ts +9 -0
  52. package/dist/workflows/schema.d.ts.map +1 -1
  53. package/dist/workflows/task.d.ts +1 -0
  54. package/dist/workflows/task.d.ts.map +1 -1
  55. package/dist/workflows/task.js +34 -0
  56. package/dist/workflows/types.d.ts +3 -1
  57. package/dist/workflows/types.d.ts.map +1 -1
  58. package/dist/workflows/uds.d.ts +1 -1
  59. package/dist/workflows/uds.d.ts.map +1 -1
  60. package/dist/workflows/uds.js +9 -39
  61. package/examples/client/main.ts +42 -0
  62. package/examples/client/package-lock.json +601 -0
  63. package/examples/client/package.json +16 -0
  64. package/examples/client/tsconfig.json +17 -0
  65. package/examples/task/main.ts +90 -0
  66. package/examples/task/package-lock.json +585 -0
  67. package/examples/task/package.json +16 -0
  68. package/examples/task/tsconfig.json +17 -0
  69. package/package.json +13 -22
  70. package/src/errors.ts +73 -0
  71. package/src/experimental/blob/api.ts +91 -0
  72. package/src/experimental/blob/client.ts +317 -0
  73. package/src/experimental/blob/index.ts +22 -0
  74. package/src/experimental/blob/types.ts +131 -0
  75. package/src/experimental/experimental.ts +33 -0
  76. package/src/experimental/index.ts +24 -0
  77. package/src/generated/schema.ts +12729 -0
  78. package/src/index.ts +7 -0
  79. package/src/render.ts +35 -0
  80. package/src/utils/create-api-client.ts +13 -0
  81. package/src/utils/get-base-url.ts +16 -0
  82. package/src/version.ts +37 -0
  83. package/src/workflows/client/client.ts +142 -0
  84. package/src/workflows/client/create-client.ts +17 -0
  85. package/src/workflows/client/index.ts +3 -0
  86. package/src/workflows/client/sse.ts +95 -0
  87. package/src/workflows/client/types.ts +56 -0
  88. package/src/workflows/executor.ts +124 -0
  89. package/src/workflows/index.ts +7 -0
  90. package/src/workflows/registry.test.ts +76 -0
  91. package/src/workflows/registry.ts +88 -0
  92. package/src/workflows/runner.ts +38 -0
  93. package/src/workflows/schema.ts +348 -0
  94. package/src/workflows/task.ts +117 -0
  95. package/src/workflows/types.ts +89 -0
  96. package/src/workflows/uds.ts +179 -0
  97. package/test-types.ts +14 -0
  98. package/tsconfig.build.json +4 -0
  99. package/tsconfig.json +23 -0
  100. package/vite.config.ts +7 -0
@@ -0,0 +1,179 @@
1
+ import { createConnection } from "node:net";
2
+ import { getUserAgent } from "../version.js";
3
+
4
+ const CONTENT_LENGTH_REGEX = /Content-Length:\s*(\d+)/i;
5
+
6
+ import type {
7
+ CallbackRequest,
8
+ GetInputResponse,
9
+ GetSubtaskResultRequest,
10
+ GetSubtaskResultResponse,
11
+ RegisterTasksRequest,
12
+ RunSubtaskRequest,
13
+ RunSubtaskResponse,
14
+ TaskMetadata,
15
+ } from "./types.js";
16
+
17
+ /**
18
+ * Unix Domain Socket client for communicating with the workflow system
19
+ */
20
+ export class UDSClient {
21
+ constructor(private readonly socketPath: string) {}
22
+
23
+ /**
24
+ * Get task input and name
25
+ */
26
+ async getInput(): Promise<GetInputResponse> {
27
+ return this.request<GetInputResponse>("/input", "GET");
28
+ }
29
+
30
+ private buildCallbackBody(results?: any, error?: string): CallbackRequest {
31
+ if (results !== undefined) {
32
+ const resultsArray = [results];
33
+ const output = Buffer.from(JSON.stringify(resultsArray)).toString("base64");
34
+ return {
35
+ complete: {
36
+ output,
37
+ },
38
+ };
39
+ }
40
+
41
+ if (error === undefined) {
42
+ throw new Error("Either results or error must be provided");
43
+ }
44
+
45
+ return {
46
+ error: {
47
+ details: error,
48
+ },
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Send task result or error
54
+ */
55
+ async sendCallback(results?: any, error?: string): Promise<void> {
56
+ await this.request<void>("/callback", "POST", this.buildCallbackBody(results, error));
57
+ }
58
+
59
+ /**
60
+ * Run a subtask
61
+ */
62
+ async runSubtask(taskName: string, input: any[]): Promise<string> {
63
+ const inputBase64 = Buffer.from(JSON.stringify(input)).toString("base64");
64
+ const body: RunSubtaskRequest = {
65
+ task_name: taskName,
66
+ input: inputBase64,
67
+ };
68
+ const response = await this.request<RunSubtaskResponse>("/run-subtask", "POST", body);
69
+ return response.task_run_id;
70
+ }
71
+
72
+ /**
73
+ * Get subtask result
74
+ */
75
+ async getSubtaskResult(subtaskId: string): Promise<GetSubtaskResultResponse> {
76
+ const body: GetSubtaskResultRequest = {
77
+ task_run_id: subtaskId,
78
+ };
79
+ return this.request<GetSubtaskResultResponse>("/get-subtask-result", "POST", body);
80
+ }
81
+
82
+ /**
83
+ * Register tasks with the workflow system
84
+ */
85
+ async registerTasks(tasks: TaskMetadata[]): Promise<void> {
86
+ const body: RegisterTasksRequest = {
87
+ tasks: tasks.map((task) => ({
88
+ name: task.name,
89
+ options: task.options,
90
+ })),
91
+ };
92
+ await this.request<void>("/register-tasks", "POST", body);
93
+ }
94
+
95
+ /**
96
+ * Make a request to the Unix socket
97
+ */
98
+ private async request<T>(path: string, method: string, body?: any): Promise<T> {
99
+ return new Promise((resolve, reject) => {
100
+ const client = createConnection({ path: this.socketPath }, () => {
101
+ const bodyStr = body ? JSON.stringify(body) : "";
102
+ const userAgent = getUserAgent();
103
+ const request = `${method} ${path} HTTP/1.1\r\nHost: unix\r\nContent-Length: ${bodyStr.length}\r\nContent-Type: application/json\r\nUser-Agent: ${userAgent}\r\n\r\n${bodyStr}`;
104
+ client.write(request);
105
+ });
106
+
107
+ let data = "";
108
+ let contentLength: number | null = null;
109
+ let headersParsed = false;
110
+ let bodyStartIndex = -1;
111
+
112
+ client.on("data", (chunk) => {
113
+ data += chunk.toString();
114
+
115
+ // Check if we have received the full response
116
+ if (!headersParsed) {
117
+ const headerEndIndex = data.indexOf("\r\n\r\n");
118
+ if (headerEndIndex !== -1) {
119
+ headersParsed = true;
120
+ bodyStartIndex = headerEndIndex + 4;
121
+
122
+ // Parse Content-Length header
123
+ const headers = data.substring(0, headerEndIndex);
124
+ const contentLengthMatch = headers.match(CONTENT_LENGTH_REGEX);
125
+ if (contentLengthMatch) {
126
+ contentLength = Number.parseInt(contentLengthMatch[1], 10);
127
+ }
128
+ }
129
+ }
130
+
131
+ // Check if we have received the complete body
132
+ if (headersParsed && contentLength !== null) {
133
+ const bodyReceived = data.length - bodyStartIndex;
134
+ if (bodyReceived >= contentLength) {
135
+ // We have the complete response, close the connection
136
+ client.end();
137
+ }
138
+ }
139
+ });
140
+
141
+ client.on("end", () => {
142
+ try {
143
+ // Parse HTTP response
144
+ const lines = data.split("\r\n");
145
+ const statusLine = lines[0];
146
+ const statusCode = Number.parseInt(statusLine.split(" ")[1], 10);
147
+
148
+ if (statusCode >= 400) {
149
+ reject(new Error(`HTTP ${statusCode}: ${data}`));
150
+ return;
151
+ }
152
+
153
+ // Find empty line (separates headers from body)
154
+ const emptyLineIndex = lines.indexOf("");
155
+ if (emptyLineIndex === -1) {
156
+ resolve(undefined as T);
157
+ return;
158
+ }
159
+
160
+ const bodyLines = lines.slice(emptyLineIndex + 1);
161
+ const responseBody = bodyLines.join("\r\n").trim();
162
+
163
+ if (!responseBody) {
164
+ resolve(undefined as T);
165
+ return;
166
+ }
167
+
168
+ resolve(JSON.parse(responseBody));
169
+ } catch (error) {
170
+ reject(error);
171
+ }
172
+ });
173
+
174
+ client.on("error", (error) => {
175
+ reject(error);
176
+ });
177
+ });
178
+ }
179
+ }
package/test-types.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { Render } from "./src";
2
+
3
+ export async function test() {
4
+ const render = new Render({
5
+ baseUrl: "https://api.localhost.render.com:8443",
6
+ token: "test",
7
+ });
8
+
9
+ const taskRun = await render.workflows.runTask("workflow-sdk/greet", ["Ruben"]);
10
+
11
+ // This should show the type
12
+ const taskRunType = typeof taskRun;
13
+ console.log(taskRunType);
14
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["node_modules", "dist", "**/*.test.ts"]
4
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "NodeNext",
5
+ "lib": ["ES2020"],
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "outDir": "./dist",
9
+ "rootDir": "./src",
10
+ "removeComments": true,
11
+ "strict": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "moduleResolution": "NodeNext",
16
+ "resolveJsonModule": true,
17
+ "experimentalDecorators": true,
18
+ "emitDecoratorMetadata": true,
19
+ "types": ["vitest/globals"]
20
+ },
21
+ "include": ["src/**/*"],
22
+ "exclude": ["node_modules", "dist"]
23
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ },
7
+ });