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