@simple-ai-lab/sdk 0.4.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 +54 -1
- 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 -1597
- package/dist/index.d.cts +12 -780
- package/dist/index.d.ts +12 -780
- package/dist/index.js +10 -1311
- 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 -31
- package/dist/chunk-V4E5PSKB.js +0 -267
- package/dist/chunk-V4E5PSKB.js.map +0 -1
- package/dist/code-action-CDt77m7I.d.cts +0 -191
- package/dist/code-action-CDt77m7I.d.ts +0 -191
- package/dist/code-action.cjs +0 -282
- package/dist/code-action.cjs.map +0 -1
- package/dist/code-action.d.cts +0 -2
- package/dist/code-action.d.ts +0 -2
- package/dist/code-action.js +0 -9
- package/dist/code-action.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Request wire schemas for the Simple AI public REST API (`/api/v1`).
|
|
4
|
+
*
|
|
5
|
+
* These deliberately mirror the server's own schemas (see
|
|
6
|
+
* `projects/server-v2/src/domains/data/query-schemas.ts` and
|
|
7
|
+
* `domains/data/public/types.ts`); a contract test in server-v2 keeps the two
|
|
8
|
+
* in sync. Responses are typed but not strictly validated, so additive server
|
|
9
|
+
* changes never break deployed SDK consumers.
|
|
10
|
+
*/
|
|
11
|
+
/** Hard cap on hits a single query may return. */
|
|
12
|
+
export declare const MAX_QUERY_SIZE = 50;
|
|
13
|
+
/** Maximum rows accepted by a single batch-upsert chunk. */
|
|
14
|
+
export declare const MAX_BATCH_ROWS = 1000;
|
|
15
|
+
export declare const tableNameSchema: z.ZodString;
|
|
16
|
+
export declare const filterValueSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>;
|
|
17
|
+
export declare const dataColumnPathSchema: z.ZodString;
|
|
18
|
+
export declare const dataFilterSchema: z.ZodObject<{
|
|
19
|
+
column: z.ZodString;
|
|
20
|
+
values: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export type DataFilter = z.infer<typeof dataFilterSchema>;
|
|
23
|
+
export declare const queryInputSchema: z.ZodObject<{
|
|
24
|
+
tableName: z.ZodString;
|
|
25
|
+
filters: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
26
|
+
column: z.ZodString;
|
|
27
|
+
values: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
28
|
+
}, z.core.$strip>>>;
|
|
29
|
+
text: z.ZodOptional<z.ZodString>;
|
|
30
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
from: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export type QueryInput = z.input<typeof queryInputSchema>;
|
|
34
|
+
export declare const listOptionsSchema: z.ZodObject<{
|
|
35
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
perPage: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
orderBy: z.ZodOptional<z.ZodString>;
|
|
38
|
+
orderDirection: z.ZodOptional<z.ZodEnum<{
|
|
39
|
+
asc: "asc";
|
|
40
|
+
desc: "desc";
|
|
41
|
+
}>>;
|
|
42
|
+
filters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type ListOptions = z.input<typeof listOptionsSchema>;
|
|
45
|
+
export declare const recordPayloadSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
46
|
+
export type RecordPayload = z.infer<typeof recordPayloadSchema>;
|
|
47
|
+
export declare const batchUpsertRowsSchema: z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
48
|
+
export type DataRecord = Record<string, unknown>;
|
|
49
|
+
export type QueryResult = {
|
|
50
|
+
records: DataRecord[];
|
|
51
|
+
total: number;
|
|
52
|
+
};
|
|
53
|
+
export type ListResult = {
|
|
54
|
+
records: DataRecord[];
|
|
55
|
+
total_count: number;
|
|
56
|
+
page: number;
|
|
57
|
+
per_page: number;
|
|
58
|
+
};
|
|
59
|
+
export type RecordResult = {
|
|
60
|
+
record: DataRecord;
|
|
61
|
+
};
|
|
62
|
+
export type DeleteResult = {
|
|
63
|
+
success: boolean;
|
|
64
|
+
message: string;
|
|
65
|
+
};
|
|
66
|
+
export type BatchUpsertResult = {
|
|
67
|
+
ingestBatchId: string;
|
|
68
|
+
status: string;
|
|
69
|
+
};
|
|
70
|
+
export type IngestBatchStatus = {
|
|
71
|
+
id: string;
|
|
72
|
+
tableName: string;
|
|
73
|
+
status: string;
|
|
74
|
+
rowCount: number;
|
|
75
|
+
upsertedCount: number | null;
|
|
76
|
+
errorMessage: string | null;
|
|
77
|
+
createdAt: string;
|
|
78
|
+
startedAt: string | null;
|
|
79
|
+
finishedAt: string | null;
|
|
80
|
+
};
|
|
81
|
+
export type FacetsResult = Record<string, unknown>;
|
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Request wire schemas for the Simple AI public REST API (`/api/v1`).
|
|
4
|
+
*
|
|
5
|
+
* These deliberately mirror the server's own schemas (see
|
|
6
|
+
* `projects/server-v2/src/domains/data/query-schemas.ts` and
|
|
7
|
+
* `domains/data/public/types.ts`); a contract test in server-v2 keeps the two
|
|
8
|
+
* in sync. Responses are typed but not strictly validated, so additive server
|
|
9
|
+
* changes never break deployed SDK consumers.
|
|
10
|
+
*/
|
|
11
|
+
/** Hard cap on hits a single query may return. */
|
|
12
|
+
export const MAX_QUERY_SIZE = 50;
|
|
13
|
+
/** Maximum rows accepted by a single batch-upsert chunk. */
|
|
14
|
+
export const MAX_BATCH_ROWS = 1000;
|
|
15
|
+
export const tableNameSchema = z.string().regex(/^[a-z0-9_]+$/, 'Table names are lowercase snake_case identifiers');
|
|
16
|
+
export const filterValueSchema = z.union([z.string(), z.number(), z.boolean()]);
|
|
17
|
+
// Mirrors the server's customDataFacetAttributePathSchema: dot-separated
|
|
18
|
+
// column paths with no empty segments (OBJECT leaves are parent.child).
|
|
19
|
+
export const dataColumnPathSchema = z
|
|
20
|
+
.string()
|
|
21
|
+
.trim()
|
|
22
|
+
.min(1)
|
|
23
|
+
.max(1024)
|
|
24
|
+
.refine((path) => path.split('.').every((segment) => segment.length > 0), {
|
|
25
|
+
message: 'Must be a dot-separated column path with no empty segments',
|
|
26
|
+
});
|
|
27
|
+
export const dataFilterSchema = z.object({
|
|
28
|
+
column: dataColumnPathSchema,
|
|
29
|
+
values: z.array(filterValueSchema),
|
|
30
|
+
});
|
|
31
|
+
export const queryInputSchema = z.object({
|
|
32
|
+
tableName: tableNameSchema,
|
|
33
|
+
filters: z.array(dataFilterSchema).optional(),
|
|
34
|
+
text: z.string().max(5000).optional(),
|
|
35
|
+
size: z.number().int().min(0).max(MAX_QUERY_SIZE).optional(),
|
|
36
|
+
from: z.number().int().min(0).optional(),
|
|
37
|
+
});
|
|
38
|
+
export const listOptionsSchema = z.object({
|
|
39
|
+
page: z.number().int().min(1).optional(),
|
|
40
|
+
perPage: z.number().int().min(1).max(200).optional(),
|
|
41
|
+
orderBy: z.string().optional(),
|
|
42
|
+
orderDirection: z.enum(['asc', 'desc']).optional(),
|
|
43
|
+
/** Column-name → value equality filters applied server-side. */
|
|
44
|
+
filters: z.record(z.string(), z.string()).optional(),
|
|
45
|
+
});
|
|
46
|
+
export const recordPayloadSchema = z.record(z.string(), z.unknown());
|
|
47
|
+
export const batchUpsertRowsSchema = z.array(recordPayloadSchema).min(1).max(MAX_BATCH_ROWS);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MissingCapabilityError = exports.SimpleAIError = void 0;
|
|
4
|
+
/** Error thrown for any non-2xx response from the Simple AI API. */
|
|
5
|
+
class SimpleAIError extends Error {
|
|
6
|
+
/** HTTP status code, or 0 when the request never reached the API. */
|
|
7
|
+
status;
|
|
8
|
+
/** Machine-readable error code from the API body, when present. */
|
|
9
|
+
code;
|
|
10
|
+
/** The parsed response body (JSON when possible, otherwise raw text). */
|
|
11
|
+
body;
|
|
12
|
+
constructor({ message, status, code, body, cause, }) {
|
|
13
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
14
|
+
this.name = 'SimpleAIError';
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.body = body;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.SimpleAIError = SimpleAIError;
|
|
21
|
+
/** Thrown when an Action uses a capability the invoking use site did not grant. */
|
|
22
|
+
class MissingCapabilityError extends Error {
|
|
23
|
+
capability;
|
|
24
|
+
constructor(capability) {
|
|
25
|
+
super(`This Action was invoked without the ${capability} capability. ` +
|
|
26
|
+
`Check metadata.capabilities.includes(ActionCapability.${capability}) before using it.`);
|
|
27
|
+
this.name = 'MissingCapabilityError';
|
|
28
|
+
this.capability = capability;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.MissingCapabilityError = MissingCapabilityError;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ActionCapability } from "../code-action/types.cjs";
|
|
2
|
+
/** Error thrown for any non-2xx response from the Simple AI API. */
|
|
3
|
+
export declare class SimpleAIError extends Error {
|
|
4
|
+
/** HTTP status code, or 0 when the request never reached the API. */
|
|
5
|
+
readonly status: number;
|
|
6
|
+
/** Machine-readable error code from the API body, when present. */
|
|
7
|
+
readonly code: string | null;
|
|
8
|
+
/** The parsed response body (JSON when possible, otherwise raw text). */
|
|
9
|
+
readonly body: unknown;
|
|
10
|
+
constructor({ message, status, code, body, cause, }: {
|
|
11
|
+
message: string;
|
|
12
|
+
status: number;
|
|
13
|
+
code: string | null;
|
|
14
|
+
body: unknown;
|
|
15
|
+
cause?: unknown;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Thrown when an Action uses a capability the invoking use site did not grant. */
|
|
19
|
+
export declare class MissingCapabilityError extends Error {
|
|
20
|
+
readonly capability: ActionCapability;
|
|
21
|
+
constructor(capability: ActionCapability);
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ActionCapability } from "../code-action/types.js";
|
|
2
|
+
/** Error thrown for any non-2xx response from the Simple AI API. */
|
|
3
|
+
export declare class SimpleAIError extends Error {
|
|
4
|
+
/** HTTP status code, or 0 when the request never reached the API. */
|
|
5
|
+
readonly status: number;
|
|
6
|
+
/** Machine-readable error code from the API body, when present. */
|
|
7
|
+
readonly code: string | null;
|
|
8
|
+
/** The parsed response body (JSON when possible, otherwise raw text). */
|
|
9
|
+
readonly body: unknown;
|
|
10
|
+
constructor({ message, status, code, body, cause, }: {
|
|
11
|
+
message: string;
|
|
12
|
+
status: number;
|
|
13
|
+
code: string | null;
|
|
14
|
+
body: unknown;
|
|
15
|
+
cause?: unknown;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/** Thrown when an Action uses a capability the invoking use site did not grant. */
|
|
19
|
+
export declare class MissingCapabilityError extends Error {
|
|
20
|
+
readonly capability: ActionCapability;
|
|
21
|
+
constructor(capability: ActionCapability);
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Error thrown for any non-2xx response from the Simple AI API. */
|
|
2
|
+
export class SimpleAIError extends Error {
|
|
3
|
+
/** HTTP status code, or 0 when the request never reached the API. */
|
|
4
|
+
status;
|
|
5
|
+
/** Machine-readable error code from the API body, when present. */
|
|
6
|
+
code;
|
|
7
|
+
/** The parsed response body (JSON when possible, otherwise raw text). */
|
|
8
|
+
body;
|
|
9
|
+
constructor({ message, status, code, body, cause, }) {
|
|
10
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
11
|
+
this.name = 'SimpleAIError';
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.body = body;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Thrown when an Action uses a capability the invoking use site did not grant. */
|
|
18
|
+
export class MissingCapabilityError extends Error {
|
|
19
|
+
capability;
|
|
20
|
+
constructor(capability) {
|
|
21
|
+
super(`This Action was invoked without the ${capability} capability. ` +
|
|
22
|
+
`Check metadata.capabilities.includes(ActionCapability.${capability}) before using it.`);
|
|
23
|
+
this.name = 'MissingCapabilityError';
|
|
24
|
+
this.capability = capability;
|
|
25
|
+
}
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simple-ai-lab/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Simple AI SDK
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "Simple AI SDK - define action-first agents and access your organization's data.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Elastic-2.0",
|
|
7
7
|
"author": "Simple AI Lab",
|
|
@@ -15,29 +15,10 @@
|
|
|
15
15
|
"LICENSE",
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
".": {
|
|
23
|
-
"import": {
|
|
24
|
-
"types": "./dist/index.d.ts",
|
|
25
|
-
"default": "./dist/index.js"
|
|
26
|
-
},
|
|
27
|
-
"require": {
|
|
28
|
-
"types": "./dist/index.d.cts",
|
|
29
|
-
"default": "./dist/index.cjs"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"./code-action": {
|
|
33
|
-
"import": {
|
|
34
|
-
"types": "./dist/code-action.d.ts",
|
|
35
|
-
"default": "./dist/code-action.js"
|
|
36
|
-
},
|
|
37
|
-
"require": {
|
|
38
|
-
"types": "./dist/code-action.d.cts",
|
|
39
|
-
"default": "./dist/code-action.cjs"
|
|
40
|
-
}
|
|
18
|
+
"zshy": {
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./src/index.ts",
|
|
21
|
+
"./code-action": "./src/code-action/index.ts"
|
|
41
22
|
}
|
|
42
23
|
},
|
|
43
24
|
"peerDependencies": {
|
|
@@ -46,10 +27,10 @@
|
|
|
46
27
|
"devDependencies": {
|
|
47
28
|
"@biomejs/biome": "^2.4.4",
|
|
48
29
|
"@types/node": "^25.9.3",
|
|
49
|
-
"tsup": "^8.5.1",
|
|
50
30
|
"typescript": "^5.9.3",
|
|
51
|
-
"vitest": "
|
|
52
|
-
"zod": "^4.1.12"
|
|
31
|
+
"vitest": "4.1.11",
|
|
32
|
+
"zod": "^4.1.12",
|
|
33
|
+
"zshy": "^0.7.3"
|
|
53
34
|
},
|
|
54
35
|
"publishConfig": {
|
|
55
36
|
"access": "public"
|
|
@@ -67,12 +48,27 @@
|
|
|
67
48
|
"actions",
|
|
68
49
|
"code-actions"
|
|
69
50
|
],
|
|
51
|
+
"main": "./dist/index.cjs",
|
|
52
|
+
"module": "./dist/index.js",
|
|
53
|
+
"types": "./dist/index.d.cts",
|
|
54
|
+
"exports": {
|
|
55
|
+
".": {
|
|
56
|
+
"types": "./dist/index.d.cts",
|
|
57
|
+
"import": "./dist/index.js",
|
|
58
|
+
"require": "./dist/index.cjs"
|
|
59
|
+
},
|
|
60
|
+
"./code-action": {
|
|
61
|
+
"types": "./dist/code-action/index.d.cts",
|
|
62
|
+
"import": "./dist/code-action/index.js",
|
|
63
|
+
"require": "./dist/code-action/index.cjs"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
70
66
|
"scripts": {
|
|
71
|
-
"build": "
|
|
67
|
+
"build": "zshy",
|
|
72
68
|
"lint": "tsc --noEmit",
|
|
73
|
-
"lint-fix": "pnpm --dir ../.. exec biome check --fix projects/simple-ai-sdk/src
|
|
69
|
+
"lint-fix": "pnpm --dir ../.. exec biome check --fix projects/simple-ai-sdk/src",
|
|
74
70
|
"typecheck": "tsc --noEmit",
|
|
75
71
|
"test": "vitest --run",
|
|
76
|
-
"format": "pnpm --dir ../.. exec biome check --fix projects/simple-ai-sdk/src
|
|
72
|
+
"format": "pnpm --dir ../.. exec biome check --fix projects/simple-ai-sdk/src"
|
|
77
73
|
}
|
|
78
74
|
}
|
package/dist/chunk-V4E5PSKB.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
// src/schemas.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
var MAX_QUERY_SIZE = 50;
|
|
4
|
-
var MAX_BATCH_ROWS = 1e3;
|
|
5
|
-
var tableNameSchema = z.string().regex(/^[a-z0-9_]+$/, "Table names are lowercase snake_case identifiers");
|
|
6
|
-
var filterValueSchema = z.union([z.string(), z.number(), z.boolean()]);
|
|
7
|
-
var dataColumnPathSchema = z.string().trim().min(1).max(1024).refine((path) => path.split(".").every((segment) => segment.length > 0), {
|
|
8
|
-
message: "Must be a dot-separated column path with no empty segments"
|
|
9
|
-
});
|
|
10
|
-
var dataFilterSchema = z.object({
|
|
11
|
-
column: dataColumnPathSchema,
|
|
12
|
-
values: z.array(filterValueSchema)
|
|
13
|
-
});
|
|
14
|
-
var queryInputSchema = z.object({
|
|
15
|
-
tableName: tableNameSchema,
|
|
16
|
-
filters: z.array(dataFilterSchema).optional(),
|
|
17
|
-
text: z.string().max(5e3).optional(),
|
|
18
|
-
size: z.number().int().min(0).max(MAX_QUERY_SIZE).optional(),
|
|
19
|
-
from: z.number().int().min(0).optional()
|
|
20
|
-
});
|
|
21
|
-
var listOptionsSchema = z.object({
|
|
22
|
-
page: z.number().int().min(1).optional(),
|
|
23
|
-
perPage: z.number().int().min(1).max(200).optional(),
|
|
24
|
-
orderBy: z.string().optional(),
|
|
25
|
-
orderDirection: z.enum(["asc", "desc"]).optional(),
|
|
26
|
-
/** Column-name → value equality filters applied server-side. */
|
|
27
|
-
filters: z.record(z.string(), z.string()).optional()
|
|
28
|
-
});
|
|
29
|
-
var recordPayloadSchema = z.record(z.string(), z.unknown());
|
|
30
|
-
var batchUpsertRowsSchema = z.array(recordPayloadSchema).min(1).max(MAX_BATCH_ROWS);
|
|
31
|
-
|
|
32
|
-
// src/data.ts
|
|
33
|
-
function encodeTable(tableName) {
|
|
34
|
-
return encodeURIComponent(tableNameSchema.parse(tableName));
|
|
35
|
-
}
|
|
36
|
-
var DataClient = class {
|
|
37
|
-
#http;
|
|
38
|
-
constructor(http) {
|
|
39
|
-
this.#http = http;
|
|
40
|
-
}
|
|
41
|
-
/** Facet-filtered search over an indexed table (Elasticsearch-backed, max 50 hits). */
|
|
42
|
-
async query(input) {
|
|
43
|
-
const parsed = queryInputSchema.parse(input);
|
|
44
|
-
const result = await this.#http.request({ method: "POST", path: "/data/query", body: parsed });
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
/** Facet values for an indexed table. */
|
|
48
|
-
async facets(tableName) {
|
|
49
|
-
const result = await this.#http.request({ method: "GET", path: `/data/facets/${encodeTable(tableName)}` });
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
/** Paginated listing straight from the relational store. */
|
|
53
|
-
async list(tableName, options = {}) {
|
|
54
|
-
const parsed = listOptionsSchema.parse(options);
|
|
55
|
-
const query = { ...parsed.filters ?? {} };
|
|
56
|
-
if (parsed.page !== void 0) {
|
|
57
|
-
query.page = String(parsed.page);
|
|
58
|
-
}
|
|
59
|
-
if (parsed.perPage !== void 0) {
|
|
60
|
-
query.per_page = String(parsed.perPage);
|
|
61
|
-
}
|
|
62
|
-
if (parsed.orderBy !== void 0) {
|
|
63
|
-
query.order_by = parsed.orderBy;
|
|
64
|
-
}
|
|
65
|
-
if (parsed.orderDirection !== void 0) {
|
|
66
|
-
query.order_direction = parsed.orderDirection;
|
|
67
|
-
}
|
|
68
|
-
const result = await this.#http.request({ method: "GET", path: `/data/${encodeTable(tableName)}`, query });
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
async get(tableName, id) {
|
|
72
|
-
const result = await this.#http.request({ method: "GET", path: `/data/${encodeTable(tableName)}/${id}` });
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
async create(tableName, payload) {
|
|
76
|
-
const result = await this.#http.request({
|
|
77
|
-
method: "PUT",
|
|
78
|
-
path: `/data/${encodeTable(tableName)}`,
|
|
79
|
-
body: recordPayloadSchema.parse(payload)
|
|
80
|
-
});
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
async update(tableName, id, payload) {
|
|
84
|
-
const result = await this.#http.request({
|
|
85
|
-
method: "PATCH",
|
|
86
|
-
path: `/data/${encodeTable(tableName)}/${id}`,
|
|
87
|
-
body: recordPayloadSchema.parse(payload)
|
|
88
|
-
});
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
async delete(tableName, id) {
|
|
92
|
-
const result = await this.#http.request({ method: "DELETE", path: `/data/${encodeTable(tableName)}/${id}` });
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
/** Deletes every record in the table. Irreversible. */
|
|
96
|
-
async deleteAll(tableName) {
|
|
97
|
-
const result = await this.#http.request({ method: "DELETE", path: `/data/${encodeTable(tableName)}` });
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Asynchronous bulk upsert (max 1000 rows per call). Rows are FULL-ROW
|
|
102
|
-
* REPLACE on key conflict — omitted columns are cleared, not preserved.
|
|
103
|
-
* Returns a batch handle; poll `getBatch` for completion.
|
|
104
|
-
*/
|
|
105
|
-
async batchUpsert(tableName, rows) {
|
|
106
|
-
const result = await this.#http.request({
|
|
107
|
-
method: "PUT",
|
|
108
|
-
path: `/data/${encodeTable(tableName)}/batch`,
|
|
109
|
-
body: { rows: batchUpsertRowsSchema.parse(rows) }
|
|
110
|
-
});
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
/** Status of an async upsert batch created by `batchUpsert`. */
|
|
114
|
-
async getBatch(ingestBatchId) {
|
|
115
|
-
const result = await this.#http.request({
|
|
116
|
-
method: "GET",
|
|
117
|
-
path: `/data/_batches/${encodeURIComponent(ingestBatchId)}`
|
|
118
|
-
});
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// src/errors.ts
|
|
124
|
-
var SimpleAIError = class extends Error {
|
|
125
|
-
/** HTTP status code, or 0 when the request never reached the API. */
|
|
126
|
-
status;
|
|
127
|
-
/** Machine-readable error code from the API body, when present. */
|
|
128
|
-
code;
|
|
129
|
-
/** The parsed response body (JSON when possible, otherwise raw text). */
|
|
130
|
-
body;
|
|
131
|
-
constructor({
|
|
132
|
-
message,
|
|
133
|
-
status,
|
|
134
|
-
code,
|
|
135
|
-
body,
|
|
136
|
-
cause
|
|
137
|
-
}) {
|
|
138
|
-
super(message, cause === void 0 ? void 0 : { cause });
|
|
139
|
-
this.name = "SimpleAIError";
|
|
140
|
-
this.status = status;
|
|
141
|
-
this.code = code;
|
|
142
|
-
this.body = body;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// src/http.ts
|
|
147
|
-
function parseBody(text) {
|
|
148
|
-
if (text.length === 0) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
try {
|
|
152
|
-
return JSON.parse(text);
|
|
153
|
-
} catch {
|
|
154
|
-
return text;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
function errorDetails(body) {
|
|
158
|
-
if (body !== null && typeof body === "object") {
|
|
159
|
-
const record = body;
|
|
160
|
-
const code = typeof record.code === "string" ? record.code : null;
|
|
161
|
-
const message = typeof record.message === "string" ? record.message : typeof record.error === "string" ? record.error : null;
|
|
162
|
-
return { code, message };
|
|
163
|
-
}
|
|
164
|
-
return { code: null, message: typeof body === "string" && body.length > 0 ? body : null };
|
|
165
|
-
}
|
|
166
|
-
function createHttpClient({
|
|
167
|
-
baseUrl,
|
|
168
|
-
apiKey,
|
|
169
|
-
fetchImplementation
|
|
170
|
-
}) {
|
|
171
|
-
const normalizedBase = baseUrl.replace(/\/+$/, "");
|
|
172
|
-
return {
|
|
173
|
-
request: async ({ method, path, query, body }) => {
|
|
174
|
-
const queryString = query === void 0 || Object.keys(query).length === 0 ? "" : `?${new URLSearchParams(query).toString()}`;
|
|
175
|
-
const url = `${normalizedBase}${path}${queryString}`;
|
|
176
|
-
let response;
|
|
177
|
-
try {
|
|
178
|
-
response = await fetchImplementation(url, {
|
|
179
|
-
method,
|
|
180
|
-
headers: {
|
|
181
|
-
authorization: `Bearer ${apiKey}`,
|
|
182
|
-
"content-type": "application/json",
|
|
183
|
-
accept: "application/json"
|
|
184
|
-
},
|
|
185
|
-
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
186
|
-
});
|
|
187
|
-
} catch (e) {
|
|
188
|
-
throw new SimpleAIError({
|
|
189
|
-
message: `Request to ${method} ${path} failed: ${e instanceof Error ? e.message : String(e)}`,
|
|
190
|
-
status: 0,
|
|
191
|
-
code: "network_error",
|
|
192
|
-
body: null,
|
|
193
|
-
cause: e
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
const parsed = parseBody(await response.text());
|
|
197
|
-
if (!response.ok) {
|
|
198
|
-
const { code, message } = errorDetails(parsed);
|
|
199
|
-
throw new SimpleAIError({
|
|
200
|
-
message: message ?? `Request to ${method} ${path} failed with status ${response.status}`,
|
|
201
|
-
status: response.status,
|
|
202
|
-
code,
|
|
203
|
-
body: parsed
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
return parsed;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/client.ts
|
|
212
|
-
var DEFAULT_BASE_URL = "https://api.prod.usesimple.ai/api/v1";
|
|
213
|
-
function envVar(name) {
|
|
214
|
-
if (typeof process === "undefined" || process.env === void 0) {
|
|
215
|
-
return void 0;
|
|
216
|
-
}
|
|
217
|
-
const value = process.env[name];
|
|
218
|
-
return value === void 0 || value === "" ? void 0 : value;
|
|
219
|
-
}
|
|
220
|
-
var SimpleAI = class {
|
|
221
|
-
/** Custom data tables — query, read, and write records. */
|
|
222
|
-
data;
|
|
223
|
-
constructor(options = {}) {
|
|
224
|
-
const apiKey = options.apiKey ?? envVar("SIMPLE_API_KEY");
|
|
225
|
-
if (apiKey === void 0) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
"Missing API key. Pass `apiKey` to new SimpleAI(...) or set the SIMPLE_API_KEY environment variable. Inside Simple AI code actions the key is injected automatically."
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
const baseUrl = options.baseUrl ?? envVar("SIMPLE_BASE_URL") ?? DEFAULT_BASE_URL;
|
|
231
|
-
const fetchImplementation = options.fetch ?? ((url, init) => fetch(url, init));
|
|
232
|
-
const http = createHttpClient({ baseUrl, apiKey, fetchImplementation });
|
|
233
|
-
this.data = new DataClient(http);
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
// src/define-action.ts
|
|
238
|
-
var SIMPLE_ACTION_BRAND = /* @__PURE__ */ Symbol.for("simple-ai.action");
|
|
239
|
-
var SIMPLE_ACTION_RUNTIME = /* @__PURE__ */ Symbol.for("simple-ai.action-runtime");
|
|
240
|
-
function defineAction(handler) {
|
|
241
|
-
const wrapped = async (invocation) => {
|
|
242
|
-
const { inputs, config } = invocation;
|
|
243
|
-
const runtime = invocation[SIMPLE_ACTION_RUNTIME];
|
|
244
|
-
const client = runtime === void 0 ? new SimpleAI() : new SimpleAI(runtime);
|
|
245
|
-
return handler({ inputs, config, client });
|
|
246
|
-
};
|
|
247
|
-
const brand = { [SIMPLE_ACTION_BRAND]: true };
|
|
248
|
-
return Object.assign(wrapped, brand);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
export {
|
|
252
|
-
MAX_QUERY_SIZE,
|
|
253
|
-
MAX_BATCH_ROWS,
|
|
254
|
-
tableNameSchema,
|
|
255
|
-
dataColumnPathSchema,
|
|
256
|
-
dataFilterSchema,
|
|
257
|
-
queryInputSchema,
|
|
258
|
-
listOptionsSchema,
|
|
259
|
-
recordPayloadSchema,
|
|
260
|
-
batchUpsertRowsSchema,
|
|
261
|
-
DataClient,
|
|
262
|
-
SimpleAIError,
|
|
263
|
-
SimpleAI,
|
|
264
|
-
SIMPLE_ACTION_BRAND,
|
|
265
|
-
defineAction
|
|
266
|
-
};
|
|
267
|
-
//# sourceMappingURL=chunk-V4E5PSKB.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas.ts","../src/data.ts","../src/errors.ts","../src/http.ts","../src/client.ts","../src/define-action.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Request wire schemas for the Simple AI public REST API (`/api/v1`).\n *\n * These deliberately mirror the server's own schemas (see\n * `projects/server-v2/src/domains/data/query-schemas.ts` and\n * `domains/data/public/types.ts`); a contract test in server-v2 keeps the two\n * in sync. Responses are typed but not strictly validated, so additive server\n * changes never break deployed SDK consumers.\n */\n\n/** Hard cap on hits a single query may return. */\nexport const MAX_QUERY_SIZE = 50;\n/** Maximum rows accepted by a single batch-upsert chunk. */\nexport const MAX_BATCH_ROWS = 1000;\n\nexport const tableNameSchema = z.string().regex(/^[a-z0-9_]+$/, 'Table names are lowercase snake_case identifiers');\n\nexport const filterValueSchema = z.union([z.string(), z.number(), z.boolean()]);\n\n// Mirrors the server's customDataFacetAttributePathSchema: dot-separated\n// column paths with no empty segments (OBJECT leaves are parent.child).\nexport const dataColumnPathSchema = z\n .string()\n .trim()\n .min(1)\n .max(1024)\n .refine((path) => path.split('.').every((segment) => segment.length > 0), {\n message: 'Must be a dot-separated column path with no empty segments',\n });\n\nexport const dataFilterSchema = z.object({\n column: dataColumnPathSchema,\n values: z.array(filterValueSchema),\n});\nexport type DataFilter = z.infer<typeof dataFilterSchema>;\n\nexport const queryInputSchema = z.object({\n tableName: tableNameSchema,\n filters: z.array(dataFilterSchema).optional(),\n text: z.string().max(5000).optional(),\n size: z.number().int().min(0).max(MAX_QUERY_SIZE).optional(),\n from: z.number().int().min(0).optional(),\n});\nexport type QueryInput = z.input<typeof queryInputSchema>;\n\nexport const listOptionsSchema = z.object({\n page: z.number().int().min(1).optional(),\n perPage: z.number().int().min(1).max(200).optional(),\n orderBy: z.string().optional(),\n orderDirection: z.enum(['asc', 'desc']).optional(),\n /** Column-name → value equality filters applied server-side. */\n filters: z.record(z.string(), z.string()).optional(),\n});\nexport type ListOptions = z.input<typeof listOptionsSchema>;\n\nexport const recordPayloadSchema = z.record(z.string(), z.unknown());\nexport type RecordPayload = z.infer<typeof recordPayloadSchema>;\n\nexport const batchUpsertRowsSchema = z.array(recordPayloadSchema).min(1).max(MAX_BATCH_ROWS);\n\n// ---------------------------------------------------------------------------\n// Response types (typed, tolerantly parsed)\n// ---------------------------------------------------------------------------\n\nexport type DataRecord = Record<string, unknown>;\n\nexport type QueryResult = {\n records: DataRecord[];\n total: number;\n};\n\nexport type ListResult = {\n records: DataRecord[];\n total_count: number;\n page: number;\n per_page: number;\n};\n\nexport type RecordResult = {\n record: DataRecord;\n};\n\nexport type DeleteResult = {\n success: boolean;\n message: string;\n};\n\nexport type BatchUpsertResult = {\n ingestBatchId: string;\n status: string;\n};\n\nexport type IngestBatchStatus = {\n id: string;\n tableName: string;\n status: string;\n rowCount: number;\n upsertedCount: number | null;\n errorMessage: string | null;\n createdAt: string;\n startedAt: string | null;\n finishedAt: string | null;\n};\n\nexport type FacetsResult = Record<string, unknown>;\n","import type { HttpClient } from './http';\nimport {\n type BatchUpsertResult,\n batchUpsertRowsSchema,\n type DataRecord,\n type DeleteResult,\n type FacetsResult,\n type IngestBatchStatus,\n type ListOptions,\n type ListResult,\n listOptionsSchema,\n type QueryInput,\n queryInputSchema,\n type RecordPayload,\n type RecordResult,\n recordPayloadSchema,\n tableNameSchema,\n} from './schemas';\n\nfunction encodeTable(tableName: string): string {\n return encodeURIComponent(tableNameSchema.parse(tableName));\n}\n\n/**\n * Custom data tables — query, read, and write your organization's records.\n * Wraps the `/api/v1/data` REST endpoints.\n */\nexport class DataClient {\n readonly #http: HttpClient;\n\n constructor(http: HttpClient) {\n this.#http = http;\n }\n\n /** Facet-filtered search over an indexed table (Elasticsearch-backed, max 50 hits). */\n async query<TRecord extends DataRecord = DataRecord>(\n input: QueryInput\n ): Promise<{ records: TRecord[]; total: number }> {\n const parsed = queryInputSchema.parse(input);\n const result = await this.#http.request({ method: 'POST', path: '/data/query', body: parsed });\n return result as { records: TRecord[]; total: number };\n }\n\n /** Facet values for an indexed table. */\n async facets(tableName: string): Promise<FacetsResult> {\n const result = await this.#http.request({ method: 'GET', path: `/data/facets/${encodeTable(tableName)}` });\n return result as FacetsResult;\n }\n\n /** Paginated listing straight from the relational store. */\n async list<TRecord extends DataRecord = DataRecord>(\n tableName: string,\n options: ListOptions = {}\n ): Promise<{ records: TRecord[]; total_count: number; page: number; per_page: number }> {\n const parsed = listOptionsSchema.parse(options);\n const query: Record<string, string> = { ...(parsed.filters ?? {}) };\n if (parsed.page !== undefined) {\n query.page = String(parsed.page);\n }\n if (parsed.perPage !== undefined) {\n query.per_page = String(parsed.perPage);\n }\n if (parsed.orderBy !== undefined) {\n query.order_by = parsed.orderBy;\n }\n if (parsed.orderDirection !== undefined) {\n query.order_direction = parsed.orderDirection;\n }\n const result = await this.#http.request({ method: 'GET', path: `/data/${encodeTable(tableName)}`, query });\n return result as ListResult & { records: TRecord[] };\n }\n\n async get<TRecord extends DataRecord = DataRecord>(tableName: string, id: number): Promise<{ record: TRecord }> {\n const result = await this.#http.request({ method: 'GET', path: `/data/${encodeTable(tableName)}/${id}` });\n return result as RecordResult & { record: TRecord };\n }\n\n async create<TRecord extends DataRecord = DataRecord>(\n tableName: string,\n payload: RecordPayload\n ): Promise<{ record: TRecord }> {\n const result = await this.#http.request({\n method: 'PUT',\n path: `/data/${encodeTable(tableName)}`,\n body: recordPayloadSchema.parse(payload),\n });\n return result as RecordResult & { record: TRecord };\n }\n\n async update<TRecord extends DataRecord = DataRecord>(\n tableName: string,\n id: number,\n payload: RecordPayload\n ): Promise<{ record: TRecord }> {\n const result = await this.#http.request({\n method: 'PATCH',\n path: `/data/${encodeTable(tableName)}/${id}`,\n body: recordPayloadSchema.parse(payload),\n });\n return result as RecordResult & { record: TRecord };\n }\n\n async delete(tableName: string, id: number): Promise<DeleteResult> {\n const result = await this.#http.request({ method: 'DELETE', path: `/data/${encodeTable(tableName)}/${id}` });\n return result as DeleteResult;\n }\n\n /** Deletes every record in the table. Irreversible. */\n async deleteAll(tableName: string): Promise<DeleteResult> {\n const result = await this.#http.request({ method: 'DELETE', path: `/data/${encodeTable(tableName)}` });\n return result as DeleteResult;\n }\n\n /**\n * Asynchronous bulk upsert (max 1000 rows per call). Rows are FULL-ROW\n * REPLACE on key conflict — omitted columns are cleared, not preserved.\n * Returns a batch handle; poll `getBatch` for completion.\n */\n async batchUpsert(tableName: string, rows: RecordPayload[]): Promise<BatchUpsertResult> {\n const result = await this.#http.request({\n method: 'PUT',\n path: `/data/${encodeTable(tableName)}/batch`,\n body: { rows: batchUpsertRowsSchema.parse(rows) },\n });\n return result as BatchUpsertResult;\n }\n\n /** Status of an async upsert batch created by `batchUpsert`. */\n async getBatch(ingestBatchId: string): Promise<IngestBatchStatus> {\n const result = await this.#http.request({\n method: 'GET',\n path: `/data/_batches/${encodeURIComponent(ingestBatchId)}`,\n });\n return result as IngestBatchStatus;\n }\n}\n","/** Error thrown for any non-2xx response from the Simple AI API. */\nexport class SimpleAIError extends Error {\n /** HTTP status code, or 0 when the request never reached the API. */\n readonly status: number;\n /** Machine-readable error code from the API body, when present. */\n readonly code: string | null;\n /** The parsed response body (JSON when possible, otherwise raw text). */\n readonly body: unknown;\n\n constructor({\n message,\n status,\n code,\n body,\n cause,\n }: {\n message: string;\n status: number;\n code: string | null;\n body: unknown;\n cause?: unknown;\n }) {\n super(message, cause === undefined ? undefined : { cause });\n this.name = 'SimpleAIError';\n this.status = status;\n this.code = code;\n this.body = body;\n }\n}\n","import { SimpleAIError } from './errors';\n\nexport type FetchLike = (url: string, init: RequestInit) => Promise<Response>;\n\nexport type HttpClient = {\n request: (args: {\n method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n path: string;\n query?: Record<string, string>;\n body?: unknown;\n }) => Promise<unknown>;\n};\n\nfunction parseBody(text: string): unknown {\n if (text.length === 0) {\n return null;\n }\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n}\n\nfunction errorDetails(body: unknown): { code: string | null; message: string | null } {\n if (body !== null && typeof body === 'object') {\n const record = body as { code?: unknown; error?: unknown; message?: unknown };\n const code = typeof record.code === 'string' ? record.code : null;\n const message =\n typeof record.message === 'string' ? record.message : typeof record.error === 'string' ? record.error : null;\n return { code, message };\n }\n return { code: null, message: typeof body === 'string' && body.length > 0 ? body : null };\n}\n\nexport function createHttpClient({\n baseUrl,\n apiKey,\n fetchImplementation,\n}: {\n baseUrl: string;\n apiKey: string;\n fetchImplementation: FetchLike;\n}): HttpClient {\n const normalizedBase = baseUrl.replace(/\\/+$/, '');\n\n return {\n request: async ({ method, path, query, body }) => {\n const queryString =\n query === undefined || Object.keys(query).length === 0 ? '' : `?${new URLSearchParams(query).toString()}`;\n const url = `${normalizedBase}${path}${queryString}`;\n\n let response: Response;\n try {\n response = await fetchImplementation(url, {\n method,\n headers: {\n authorization: `Bearer ${apiKey}`,\n 'content-type': 'application/json',\n accept: 'application/json',\n },\n ...(body === undefined ? {} : { body: JSON.stringify(body) }),\n });\n } catch (e) {\n throw new SimpleAIError({\n message: `Request to ${method} ${path} failed: ${e instanceof Error ? e.message : String(e)}`,\n status: 0,\n code: 'network_error',\n body: null,\n cause: e,\n });\n }\n\n const parsed = parseBody(await response.text());\n if (!response.ok) {\n const { code, message } = errorDetails(parsed);\n throw new SimpleAIError({\n message: message ?? `Request to ${method} ${path} failed with status ${response.status}`,\n status: response.status,\n code,\n body: parsed,\n });\n }\n return parsed;\n },\n };\n}\n","import { DataClient } from './data';\nimport type { FetchLike } from './http';\nimport { createHttpClient } from './http';\n\nconst DEFAULT_BASE_URL = 'https://api.prod.usesimple.ai/api/v1';\n\nexport type SimpleAIOptions = {\n /** API key (dashboard: Settings → API Keys). Defaults to SIMPLE_API_KEY — inside code actions this is injected automatically. */\n apiKey?: string;\n /** API base URL. Defaults to SIMPLE_BASE_URL, then the production API. */\n baseUrl?: string;\n /** Custom fetch implementation (for testing or instrumentation). */\n fetch?: FetchLike;\n};\n\nfunction envVar(name: string): string | undefined {\n if (typeof process === 'undefined' || process.env === undefined) {\n return undefined;\n }\n const value = process.env[name];\n return value === undefined || value === '' ? undefined : value;\n}\n\nexport class SimpleAI {\n /** Custom data tables — query, read, and write records. */\n readonly data: DataClient;\n\n constructor(options: SimpleAIOptions = {}) {\n const apiKey = options.apiKey ?? envVar('SIMPLE_API_KEY');\n if (apiKey === undefined) {\n throw new Error(\n 'Missing API key. Pass `apiKey` to new SimpleAI(...) or set the SIMPLE_API_KEY environment variable. ' +\n 'Inside Simple AI code actions the key is injected automatically.'\n );\n }\n const baseUrl = options.baseUrl ?? envVar('SIMPLE_BASE_URL') ?? DEFAULT_BASE_URL;\n const fetchImplementation: FetchLike = options.fetch ?? ((url, init) => fetch(url, init));\n\n const http = createHttpClient({ baseUrl, apiKey, fetchImplementation });\n this.data = new DataClient(http);\n }\n}\n","import { SimpleAI } from './client';\n\n/**\n * Brand the code-action runner uses to recognize `defineAction` handlers. The\n * runner calls the default export with `{ inputs, config }` either way; the\n * wrapper adds the authenticated `client` to the handler's context.\n */\nexport const SIMPLE_ACTION_BRAND = Symbol.for('simple-ai.action');\nconst SIMPLE_ACTION_RUNTIME = Symbol.for('simple-ai.action-runtime');\n\ntype ActionRuntime = {\n apiKey: string;\n baseUrl: string;\n};\n\nexport type ActionContext<TInputs = Record<string, unknown>> = {\n /** The Action's declared inputs, already validated against its input schema. */\n inputs: TInputs;\n /** Your organization's configuration variables. */\n config: Record<string, string>;\n /** The Simple AI SDK, authenticated for your organization. */\n client: SimpleAI;\n};\n\nexport type ActionHandler<TInputs = Record<string, unknown>, TResult = unknown> = ((args: {\n inputs: TInputs;\n config: Record<string, string>;\n [SIMPLE_ACTION_RUNTIME]?: ActionRuntime;\n}) => Promise<TResult>) & { [SIMPLE_ACTION_BRAND]: true };\n\n/**\n * Define a code action with a typed context and an org-authenticated SDK\n * client. The returned value must be your module's default export.\n *\n * ```ts\n * import { defineAction } from '@simple-ai-lab/sdk';\n *\n * export default defineAction(async ({ inputs, config, client }) => {\n * const { records } = await client.data.query({ tableName: 'customers', text: inputs.email });\n * return { found: records.length > 0 };\n * });\n * ```\n */\nexport function defineAction<TInputs = Record<string, unknown>, TResult = unknown>(\n handler: (context: ActionContext<TInputs>) => Promise<TResult> | TResult\n): ActionHandler<TInputs, TResult> {\n const wrapped = async (invocation: {\n inputs: TInputs;\n config: Record<string, string>;\n [SIMPLE_ACTION_RUNTIME]?: ActionRuntime;\n }): Promise<TResult> => {\n const { inputs, config } = invocation;\n const runtime = invocation[SIMPLE_ACTION_RUNTIME];\n // The Dynamic Worker runner supplies a non-secret API identity. The\n // outbound Worker injects the real short-lived credential after the\n // request has crossed the untrusted isolate boundary.\n const client = runtime === undefined ? new SimpleAI() : new SimpleAI(runtime);\n return handler({ inputs, config, client });\n };\n const brand: { [SIMPLE_ACTION_BRAND]: true } = { [SIMPLE_ACTION_BRAND]: true };\n return Object.assign(wrapped, brand);\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAaX,IAAM,iBAAiB;AAEvB,IAAM,iBAAiB;AAEvB,IAAM,kBAAkB,EAAE,OAAO,EAAE,MAAM,gBAAgB,kDAAkD;AAE3G,IAAM,oBAAoB,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC;AAIvE,IAAM,uBAAuB,E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