@init.computer/sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# Init SDK
|
|
2
|
+
|
|
3
|
+
Official SDK for Init. Generate, deploy, and run backend endpoints in seconds, with compute, storage, and database included.
|
|
4
|
+
|
|
5
|
+
Init turns a prompt into a deployed API endpoint with a route, schema, runtime, and version history. Describe the inputs, outputs, and behavior you want. Init builds the endpoint and returns a URL you can call immediately.
|
|
6
|
+
|
|
7
|
+
Use this SDK to generate endpoints, run them, edit versions, manage resources, upload files, and automate recurring tasks.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @init.computer/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Create a client
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { createClient } from "@init.computer/sdk";
|
|
19
|
+
|
|
20
|
+
const init = createClient({
|
|
21
|
+
apiKey: process.env.INIT_API_KEY,
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
You can also set `INIT_API_KEY` in the environment and call `createClient()` with no arguments.
|
|
26
|
+
|
|
27
|
+
## Generate an endpoint
|
|
28
|
+
|
|
29
|
+
Use `init.generate()` to create a new deployed endpoint from a description. Be specific about the input fields, output fields, storage behavior, and any external work the endpoint should perform.
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
const api = await init.generate({
|
|
33
|
+
prompt: `
|
|
34
|
+
Create a lead enrichment API for B2B sales teams.
|
|
35
|
+
|
|
36
|
+
Input fields:
|
|
37
|
+
- companyName: string, required
|
|
38
|
+
- website: url, required
|
|
39
|
+
- targetPersona: string, optional
|
|
40
|
+
|
|
41
|
+
Output fields:
|
|
42
|
+
- companySummary: string
|
|
43
|
+
- buyingSignals: array of objects with title, evidence, and urgency
|
|
44
|
+
- recommendedPersonas: array of objects with role, reason, and outreachAngle
|
|
45
|
+
- nextSteps: array of strings
|
|
46
|
+
|
|
47
|
+
Behavior:
|
|
48
|
+
- Research the company from public web context.
|
|
49
|
+
- Prioritize signals related to growth, hiring, product launches, funding, and technology changes.
|
|
50
|
+
- Store each generated brief so it can be reviewed later.
|
|
51
|
+
- Return structured JSON only.
|
|
52
|
+
`,
|
|
53
|
+
directories: ["Sales"],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log(api.result.url);
|
|
57
|
+
console.log(api.result.inputStructure);
|
|
58
|
+
console.log(api.result.outputStructure);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The response includes the live URL, route, resource ID, version, input schema, output schema, and generated pipeline.
|
|
62
|
+
|
|
63
|
+
Save the `resourceId` if you want to inspect, edit, organize, or automate the endpoint later.
|
|
64
|
+
|
|
65
|
+
## Run an endpoint
|
|
66
|
+
|
|
67
|
+
Use `init.run()` to call a generated endpoint. You can pass a bare route, a `/v1/...` path, or the full URL returned from `generate`.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const response = await init.run(api.result.url, {
|
|
71
|
+
companyName: "Snowflake",
|
|
72
|
+
website: "https://www.snowflake.com",
|
|
73
|
+
targetPersona: "VP Sales",
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log(response.result.buyingSignals);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The request body should match the input fields you asked Init to create. The response follows the output shape from the generated endpoint.
|
|
80
|
+
|
|
81
|
+
## Edit an endpoint
|
|
82
|
+
|
|
83
|
+
Use `resource.edit()` to change an existing endpoint. Init keeps the same resource and creates a new version.
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
const edited = await init.resource.edit(api.result.resourceId, {
|
|
87
|
+
prompt: `
|
|
88
|
+
Keep the same lead enrichment behavior, but add:
|
|
89
|
+
- csv: string, a CSV version of the recommendedPersonas array
|
|
90
|
+
- confidenceScore: number from 0 to 1
|
|
91
|
+
`,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
console.log(edited.result.url);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then call the new version URL returned by the edit response, or inspect versions with `init.resource.versions()`.
|
|
98
|
+
|
|
99
|
+
## Work with files
|
|
100
|
+
|
|
101
|
+
Generated endpoints can accept multipart input when the endpoint needs uploaded files.
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const form = new FormData();
|
|
105
|
+
form.append("file", reportFile);
|
|
106
|
+
form.append("summaryStyle", "executive");
|
|
107
|
+
|
|
108
|
+
const report = await init.run("quarterly-report-reader", form, {
|
|
109
|
+
requestFormat: "multipart/form-data",
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
console.log(report.result);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Manage resources
|
|
116
|
+
|
|
117
|
+
Resources are the APIs you have generated.
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
await init.resource.list({ q: "lead" });
|
|
121
|
+
|
|
122
|
+
const resource = await init.resource.get(api.result.resourceId);
|
|
123
|
+
|
|
124
|
+
await init.resource.update(api.result.resourceId, {
|
|
125
|
+
name: "Lead Enrichment",
|
|
126
|
+
status: "enabled",
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const versions = await init.resource.versions(api.result.resourceId);
|
|
130
|
+
|
|
131
|
+
await init.resource.activateVersion(api.result.resourceId, "version_uuid");
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Organize with directories
|
|
135
|
+
|
|
136
|
+
Directories group related endpoints.
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
const directory = await init.directory.create({
|
|
140
|
+
name: "Sales Workflows",
|
|
141
|
+
description: "Prospecting, enrichment, and outbound APIs",
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await init.directory.addResources(directory.result.directory.id, [
|
|
145
|
+
api.result.resourceId,
|
|
146
|
+
]);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Automate with daemons
|
|
150
|
+
|
|
151
|
+
Daemons run an endpoint on a schedule or on demand.
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
const daemon = await init.daemon.create({
|
|
155
|
+
resource_id: api.result.resourceId,
|
|
156
|
+
input: {
|
|
157
|
+
companyName: "Snowflake",
|
|
158
|
+
website: "https://www.snowflake.com",
|
|
159
|
+
},
|
|
160
|
+
interval_seconds: 86400,
|
|
161
|
+
max_runs: 30,
|
|
162
|
+
description: "Refresh Snowflake account research daily",
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
await init.daemon.run(daemon.result.daemon.id);
|
|
166
|
+
await init.daemon.pause(daemon.result.daemon.id);
|
|
167
|
+
await init.daemon.resume(daemon.result.daemon.id);
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Discover packages
|
|
171
|
+
|
|
172
|
+
Packages are the capabilities available to generated endpoints.
|
|
173
|
+
|
|
174
|
+
A package can be an Init-provided capability, an external app, or one of your own tools. Packages can give endpoints access to compute, storage, databases, models, APIs, and integrations such as OpenAI, Anthropic, Neon, Supabase, or custom internal services.
|
|
175
|
+
|
|
176
|
+
Use packages to see what your generated endpoints can connect to and use during execution.
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
await init.pkg.list({ category: "Database" });
|
|
180
|
+
await init.pkg.list({ category: "Model" });
|
|
181
|
+
await init.pkg.list({ category: "Integration" });
|
|
182
|
+
await init.pkg.list({ enabled_category: "Storage" });
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
For example, you can generate an endpoint that uses connected packages:
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
const api = await init.generate({
|
|
189
|
+
prompt: `
|
|
190
|
+
Create a customer support triage API.
|
|
191
|
+
|
|
192
|
+
Input fields:
|
|
193
|
+
- message: string, required
|
|
194
|
+
- customerId: string, optional
|
|
195
|
+
|
|
196
|
+
Output fields:
|
|
197
|
+
- category: string
|
|
198
|
+
- priority: string
|
|
199
|
+
- summary: string
|
|
200
|
+
- suggestedReply: string
|
|
201
|
+
- shouldEscalate: boolean
|
|
202
|
+
|
|
203
|
+
Behavior:
|
|
204
|
+
- Use the connected Anthropic package to classify and summarize the request.
|
|
205
|
+
- Use the connected Supabase package to store the support ticket.
|
|
206
|
+
- Return structured JSON only.
|
|
207
|
+
`,
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Once your own tools are connected to Init as packages, generated endpoints can call them the same way they call built-in or third-party capabilities.
|
|
212
|
+
|
|
213
|
+
## API surface
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
init.generate(request);
|
|
217
|
+
init.run(route, input, options);
|
|
218
|
+
|
|
219
|
+
init.resource.list(query);
|
|
220
|
+
init.resource.get(id);
|
|
221
|
+
init.resource.update(id, patch);
|
|
222
|
+
init.resource.edit(id, request);
|
|
223
|
+
init.resource.versions(id);
|
|
224
|
+
init.resource.activateVersion(id, versionId);
|
|
225
|
+
|
|
226
|
+
init.directory.list(query);
|
|
227
|
+
init.directory.create(input);
|
|
228
|
+
init.directory.get(id);
|
|
229
|
+
init.directory.update(id, patch);
|
|
230
|
+
init.directory.delete(id);
|
|
231
|
+
init.directory.addResources(id, resourceIds);
|
|
232
|
+
init.directory.removeResource(id, resourceId);
|
|
233
|
+
|
|
234
|
+
init.daemon.list(query);
|
|
235
|
+
init.daemon.create(input);
|
|
236
|
+
init.daemon.get(id);
|
|
237
|
+
init.daemon.pause(id);
|
|
238
|
+
init.daemon.resume(id);
|
|
239
|
+
init.daemon.stop(id);
|
|
240
|
+
init.daemon.run(id);
|
|
241
|
+
|
|
242
|
+
init.pkg.list(query);
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Errors
|
|
246
|
+
|
|
247
|
+
Failed requests throw `InitApiError`.
|
|
248
|
+
|
|
249
|
+
```js
|
|
250
|
+
import { InitApiError } from "@init.computer/sdk";
|
|
251
|
+
|
|
252
|
+
try {
|
|
253
|
+
await init.run("missing-route", {});
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (error instanceof InitApiError) {
|
|
256
|
+
console.log(error.status);
|
|
257
|
+
console.log(error.details);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@init.computer/sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Official
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Official SDK for Init. Generate, deploy, and run backend endpoints in seconds, with compute, storage, and database included.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|