@simple-ai-lab/sdk 0.3.0 → 0.6.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.
- package/README.md +56 -3
- package/dist/actions.cjs +438 -0
- package/dist/actions.d.cts +336 -0
- package/dist/actions.d.ts +336 -0
- package/dist/actions.js +429 -0
- package/dist/agents.cjs +1054 -0
- package/dist/agents.d.cts +1016 -0
- package/dist/agents.d.ts +1016 -0
- package/dist/agents.js +1044 -0
- package/dist/built-in-actions.cjs +356 -0
- package/dist/built-in-actions.d.cts +41 -0
- package/dist/built-in-actions.d.ts +41 -0
- package/dist/built-in-actions.js +353 -0
- package/dist/client.cjs +29 -0
- package/dist/client.d.cts +15 -0
- package/dist/client.d.ts +15 -0
- package/dist/client.js +25 -0
- package/dist/code-action/defaults.cjs +11 -0
- package/dist/code-action/defaults.d.cts +7 -0
- package/dist/code-action/defaults.d.ts +7 -0
- package/dist/code-action/defaults.js +8 -0
- package/dist/code-action/define-action.cjs +74 -0
- package/dist/code-action/define-action.d.cts +94 -0
- package/dist/code-action/define-action.d.ts +94 -0
- package/dist/code-action/define-action.js +69 -0
- package/dist/code-action/index.cjs +11 -0
- package/dist/code-action/index.d.cts +4 -0
- package/dist/code-action/index.d.ts +4 -0
- package/dist/code-action/index.js +3 -0
- package/dist/code-action/types.cjs +13 -0
- package/dist/code-action/types.d.cts +13 -0
- package/dist/code-action/types.d.ts +13 -0
- package/dist/code-action/types.js +10 -0
- package/dist/code-action/workflow.cjs +29 -0
- package/dist/code-action/workflow.d.cts +53 -0
- package/dist/code-action/workflow.d.ts +53 -0
- package/dist/code-action/workflow.js +26 -0
- package/dist/data.cjs +98 -0
- package/dist/data.d.cts +44 -0
- package/dist/data.d.ts +44 -0
- package/dist/data.js +94 -0
- package/dist/http.cjs +65 -0
- package/dist/http.d.cts +14 -0
- package/dist/http.d.ts +14 -0
- package/dist/http.js +62 -0
- package/dist/index.cjs +68 -1593
- package/dist/index.d.cts +12 -961
- package/dist/index.d.ts +12 -961
- package/dist/index.js +10 -1540
- package/dist/projects.cjs +234 -0
- package/dist/projects.d.cts +24 -0
- package/dist/projects.d.ts +24 -0
- package/dist/projects.js +228 -0
- package/dist/schemas.cjs +50 -0
- package/dist/schemas.d.cts +81 -0
- package/dist/schemas.d.ts +81 -0
- package/dist/schemas.js +47 -0
- package/dist/shared/errors.cjs +31 -0
- package/dist/shared/errors.d.cts +22 -0
- package/dist/shared/errors.d.ts +22 -0
- package/dist/shared/errors.js +26 -0
- package/package.json +27 -21
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/data.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { batchUpsertRowsSchema, listOptionsSchema, queryInputSchema, recordPayloadSchema, tableNameSchema, } from "./schemas.js";
|
|
2
|
+
function encodeTable(tableName) {
|
|
3
|
+
return encodeURIComponent(tableNameSchema.parse(tableName));
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Custom data tables — query, read, and write your organization's records.
|
|
7
|
+
* Wraps the `/api/v1/data` REST endpoints.
|
|
8
|
+
*/
|
|
9
|
+
export class DataClient {
|
|
10
|
+
#http;
|
|
11
|
+
constructor(http) {
|
|
12
|
+
this.#http = http;
|
|
13
|
+
}
|
|
14
|
+
/** Facet-filtered search over an indexed table (Elasticsearch-backed, max 50 hits). */
|
|
15
|
+
async query(input) {
|
|
16
|
+
const parsed = queryInputSchema.parse(input);
|
|
17
|
+
const result = await this.#http.request({ method: 'POST', path: '/data/query', body: parsed });
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
/** Facet values for an indexed table. */
|
|
21
|
+
async facets(tableName) {
|
|
22
|
+
const result = await this.#http.request({ method: 'GET', path: `/data/facets/${encodeTable(tableName)}` });
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
/** Paginated listing straight from the relational store. */
|
|
26
|
+
async list(tableName, options = {}) {
|
|
27
|
+
const parsed = listOptionsSchema.parse(options);
|
|
28
|
+
const query = { ...(parsed.filters ?? {}) };
|
|
29
|
+
if (parsed.page !== undefined) {
|
|
30
|
+
query.page = String(parsed.page);
|
|
31
|
+
}
|
|
32
|
+
if (parsed.perPage !== undefined) {
|
|
33
|
+
query.per_page = String(parsed.perPage);
|
|
34
|
+
}
|
|
35
|
+
if (parsed.orderBy !== undefined) {
|
|
36
|
+
query.order_by = parsed.orderBy;
|
|
37
|
+
}
|
|
38
|
+
if (parsed.orderDirection !== undefined) {
|
|
39
|
+
query.order_direction = parsed.orderDirection;
|
|
40
|
+
}
|
|
41
|
+
const result = await this.#http.request({ method: 'GET', path: `/data/${encodeTable(tableName)}`, query });
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
async get(tableName, id) {
|
|
45
|
+
const result = await this.#http.request({ method: 'GET', path: `/data/${encodeTable(tableName)}/${id}` });
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
async create(tableName, payload) {
|
|
49
|
+
const result = await this.#http.request({
|
|
50
|
+
method: 'PUT',
|
|
51
|
+
path: `/data/${encodeTable(tableName)}`,
|
|
52
|
+
body: recordPayloadSchema.parse(payload),
|
|
53
|
+
});
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
async update(tableName, id, payload) {
|
|
57
|
+
const result = await this.#http.request({
|
|
58
|
+
method: 'PATCH',
|
|
59
|
+
path: `/data/${encodeTable(tableName)}/${id}`,
|
|
60
|
+
body: recordPayloadSchema.parse(payload),
|
|
61
|
+
});
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
async delete(tableName, id) {
|
|
65
|
+
const result = await this.#http.request({ method: 'DELETE', path: `/data/${encodeTable(tableName)}/${id}` });
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/** Deletes every record in the table. Irreversible. */
|
|
69
|
+
async deleteAll(tableName) {
|
|
70
|
+
const result = await this.#http.request({ method: 'DELETE', path: `/data/${encodeTable(tableName)}` });
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Asynchronous bulk upsert (max 1000 rows per call). Rows are FULL-ROW
|
|
75
|
+
* REPLACE on key conflict — omitted columns are cleared, not preserved.
|
|
76
|
+
* Returns a batch handle; poll `getBatch` for completion.
|
|
77
|
+
*/
|
|
78
|
+
async batchUpsert(tableName, rows) {
|
|
79
|
+
const result = await this.#http.request({
|
|
80
|
+
method: 'PUT',
|
|
81
|
+
path: `/data/${encodeTable(tableName)}/batch`,
|
|
82
|
+
body: { rows: batchUpsertRowsSchema.parse(rows) },
|
|
83
|
+
});
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/** Status of an async upsert batch created by `batchUpsert`. */
|
|
87
|
+
async getBatch(ingestBatchId) {
|
|
88
|
+
const result = await this.#http.request({
|
|
89
|
+
method: 'GET',
|
|
90
|
+
path: `/data/_batches/${encodeURIComponent(ingestBatchId)}`,
|
|
91
|
+
});
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
}
|
package/dist/http.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHttpClient = createHttpClient;
|
|
4
|
+
const errors_1 = require("./shared/errors.cjs");
|
|
5
|
+
function parseBody(text) {
|
|
6
|
+
if (text.length === 0) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(text);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return text;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function errorDetails(body) {
|
|
17
|
+
if (body !== null && typeof body === 'object') {
|
|
18
|
+
const record = body;
|
|
19
|
+
const code = typeof record.code === 'string' ? record.code : null;
|
|
20
|
+
const message = typeof record.message === 'string' ? record.message : typeof record.error === 'string' ? record.error : null;
|
|
21
|
+
return { code, message };
|
|
22
|
+
}
|
|
23
|
+
return { code: null, message: typeof body === 'string' && body.length > 0 ? body : null };
|
|
24
|
+
}
|
|
25
|
+
function createHttpClient({ baseUrl, apiKey, fetchImplementation, }) {
|
|
26
|
+
const normalizedBase = baseUrl.replace(/\/+$/, '');
|
|
27
|
+
return {
|
|
28
|
+
request: async ({ method, path, query, body }) => {
|
|
29
|
+
const queryString = query === undefined || Object.keys(query).length === 0 ? '' : `?${new URLSearchParams(query).toString()}`;
|
|
30
|
+
const url = `${normalizedBase}${path}${queryString}`;
|
|
31
|
+
let response;
|
|
32
|
+
try {
|
|
33
|
+
response = await fetchImplementation(url, {
|
|
34
|
+
method,
|
|
35
|
+
headers: {
|
|
36
|
+
authorization: `Bearer ${apiKey}`,
|
|
37
|
+
'content-type': 'application/json',
|
|
38
|
+
accept: 'application/json',
|
|
39
|
+
},
|
|
40
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
throw new errors_1.SimpleAIError({
|
|
45
|
+
message: `Request to ${method} ${path} failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
46
|
+
status: 0,
|
|
47
|
+
code: 'network_error',
|
|
48
|
+
body: null,
|
|
49
|
+
cause: e,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const parsed = parseBody(await response.text());
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const { code, message } = errorDetails(parsed);
|
|
55
|
+
throw new errors_1.SimpleAIError({
|
|
56
|
+
message: message ?? `Request to ${method} ${path} failed with status ${response.status}`,
|
|
57
|
+
status: response.status,
|
|
58
|
+
code,
|
|
59
|
+
body: parsed,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return parsed;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
package/dist/http.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type FetchLike = (url: string, init: RequestInit) => Promise<Response>;
|
|
2
|
+
export type HttpClient = {
|
|
3
|
+
request: (args: {
|
|
4
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
5
|
+
path: string;
|
|
6
|
+
query?: Record<string, string>;
|
|
7
|
+
body?: unknown;
|
|
8
|
+
}) => Promise<unknown>;
|
|
9
|
+
};
|
|
10
|
+
export declare function createHttpClient({ baseUrl, apiKey, fetchImplementation, }: {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
apiKey: string;
|
|
13
|
+
fetchImplementation: FetchLike;
|
|
14
|
+
}): HttpClient;
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type FetchLike = (url: string, init: RequestInit) => Promise<Response>;
|
|
2
|
+
export type HttpClient = {
|
|
3
|
+
request: (args: {
|
|
4
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
5
|
+
path: string;
|
|
6
|
+
query?: Record<string, string>;
|
|
7
|
+
body?: unknown;
|
|
8
|
+
}) => Promise<unknown>;
|
|
9
|
+
};
|
|
10
|
+
export declare function createHttpClient({ baseUrl, apiKey, fetchImplementation, }: {
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
apiKey: string;
|
|
13
|
+
fetchImplementation: FetchLike;
|
|
14
|
+
}): HttpClient;
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { SimpleAIError } from "./shared/errors.js";
|
|
2
|
+
function parseBody(text) {
|
|
3
|
+
if (text.length === 0) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(text);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return text;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function errorDetails(body) {
|
|
14
|
+
if (body !== null && typeof body === 'object') {
|
|
15
|
+
const record = body;
|
|
16
|
+
const code = typeof record.code === 'string' ? record.code : null;
|
|
17
|
+
const message = typeof record.message === 'string' ? record.message : typeof record.error === 'string' ? record.error : null;
|
|
18
|
+
return { code, message };
|
|
19
|
+
}
|
|
20
|
+
return { code: null, message: typeof body === 'string' && body.length > 0 ? body : null };
|
|
21
|
+
}
|
|
22
|
+
export function createHttpClient({ baseUrl, apiKey, fetchImplementation, }) {
|
|
23
|
+
const normalizedBase = baseUrl.replace(/\/+$/, '');
|
|
24
|
+
return {
|
|
25
|
+
request: async ({ method, path, query, body }) => {
|
|
26
|
+
const queryString = query === undefined || Object.keys(query).length === 0 ? '' : `?${new URLSearchParams(query).toString()}`;
|
|
27
|
+
const url = `${normalizedBase}${path}${queryString}`;
|
|
28
|
+
let response;
|
|
29
|
+
try {
|
|
30
|
+
response = await fetchImplementation(url, {
|
|
31
|
+
method,
|
|
32
|
+
headers: {
|
|
33
|
+
authorization: `Bearer ${apiKey}`,
|
|
34
|
+
'content-type': 'application/json',
|
|
35
|
+
accept: 'application/json',
|
|
36
|
+
},
|
|
37
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
throw new SimpleAIError({
|
|
42
|
+
message: `Request to ${method} ${path} failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
43
|
+
status: 0,
|
|
44
|
+
code: 'network_error',
|
|
45
|
+
body: null,
|
|
46
|
+
cause: e,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const parsed = parseBody(await response.text());
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const { code, message } = errorDetails(parsed);
|
|
52
|
+
throw new SimpleAIError({
|
|
53
|
+
message: message ?? `Request to ${method} ${path} failed with status ${response.status}`,
|
|
54
|
+
status: response.status,
|
|
55
|
+
code,
|
|
56
|
+
body: parsed,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return parsed;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|