@stackbone/sdk 0.1.0-alpha.0 → 0.1.0-alpha.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/CHANGELOG.md +64 -0
- package/README.md +13 -12
- package/index.cjs +186 -242
- package/index.cjs.map +1 -1
- package/index.d.cts +73 -15
- package/index.d.ts +73 -15
- package/index.js +186 -242
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/stackbone-sdk-0.1.0-alpha.2.tgz +0 -0
- package/stackbone-sdk-0.1.0-alpha.0.tgz +0 -0
package/index.d.cts
CHANGED
|
@@ -19,10 +19,9 @@ interface ClientConfig {
|
|
|
19
19
|
agentId?: string;
|
|
20
20
|
/**
|
|
21
21
|
* Postgres connection string consumed by `client.rag` and the platform
|
|
22
|
-
* observability exporter. Falls back to `
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `DATABASE_URL` consumers until `feature 30` consolidates them.
|
|
22
|
+
* observability exporter. Falls back to `STACKBONE_POSTGRES_URL` — the same
|
|
23
|
+
* env var `client.database` reads, so a single connection string covers
|
|
24
|
+
* every SDK consumer that talks to the agent's Postgres.
|
|
26
25
|
*/
|
|
27
26
|
databaseUrl?: string;
|
|
28
27
|
openrouterKey?: string;
|
|
@@ -46,14 +45,16 @@ interface ClientConfig {
|
|
|
46
45
|
*/
|
|
47
46
|
installationId?: string;
|
|
48
47
|
s3?: {
|
|
49
|
-
/** Falls back to `
|
|
48
|
+
/** Falls back to `STACKBONE_S3_ACCESS_KEY`. */
|
|
50
49
|
accessKeyId?: string;
|
|
51
|
-
/** Falls back to `
|
|
50
|
+
/** Falls back to `STACKBONE_S3_SECRET_KEY`. */
|
|
52
51
|
secretAccessKey?: string;
|
|
53
|
-
/** Falls back to `
|
|
52
|
+
/** Falls back to `STACKBONE_S3_ENDPOINT`. */
|
|
54
53
|
endpoint?: string;
|
|
55
|
-
/** Physical R2/S3 bucket scoped to the agent. Falls back to `
|
|
54
|
+
/** Physical R2/S3 bucket scoped to the agent. Falls back to `STACKBONE_S3_BUCKET`. */
|
|
56
55
|
bucket?: string;
|
|
56
|
+
/** AWS region. Falls back to `STACKBONE_S3_REGION`, defaults to `'auto'` (R2/MinIO). */
|
|
57
|
+
region?: string;
|
|
57
58
|
};
|
|
58
59
|
otel?: {
|
|
59
60
|
exporterOtlpEndpoint?: string;
|
|
@@ -337,7 +338,7 @@ declare class ConnectionsFacade {
|
|
|
337
338
|
list(): Promise<Result<readonly never[]>>;
|
|
338
339
|
}
|
|
339
340
|
|
|
340
|
-
/** Emit events to the
|
|
341
|
+
/** Emit events to the organization event bus. */
|
|
341
342
|
declare class EventsFacade {
|
|
342
343
|
private readonly _http;
|
|
343
344
|
private readonly _gate;
|
|
@@ -424,7 +425,7 @@ declare class SecretsFacade {
|
|
|
424
425
|
gate?: ModuleGate);
|
|
425
426
|
get(name: string): Promise<Result<string>>;
|
|
426
427
|
/**
|
|
427
|
-
* Names absent from the
|
|
428
|
+
* Names absent from the organization come back as omissions in the response —
|
|
428
429
|
* the returned map only contains entries the control plane actually has.
|
|
429
430
|
* Callers that need "all-or-nothing" semantics should diff the keys.
|
|
430
431
|
*/
|
|
@@ -1007,6 +1008,53 @@ type RagIngestProgress = {
|
|
|
1007
1008
|
jobId: string;
|
|
1008
1009
|
error: string;
|
|
1009
1010
|
};
|
|
1011
|
+
interface IngestJobStartArgs {
|
|
1012
|
+
collection: string;
|
|
1013
|
+
source: string;
|
|
1014
|
+
totalChunks: number;
|
|
1015
|
+
}
|
|
1016
|
+
interface IngestJobProgressArgs {
|
|
1017
|
+
jobId: string;
|
|
1018
|
+
processedChunks: number;
|
|
1019
|
+
totalChunks: number;
|
|
1020
|
+
currentDocument?: {
|
|
1021
|
+
source: string;
|
|
1022
|
+
ordinal: number;
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
interface IngestJobCompleteArgs {
|
|
1026
|
+
jobId: string;
|
|
1027
|
+
totalChunks: number;
|
|
1028
|
+
}
|
|
1029
|
+
interface IngestJobFailArgs {
|
|
1030
|
+
jobId: string;
|
|
1031
|
+
error: string;
|
|
1032
|
+
}
|
|
1033
|
+
interface IngestJobWriter {
|
|
1034
|
+
/**
|
|
1035
|
+
* Allocates a `stackbone_rag_jobs` row in `running` state and returns its
|
|
1036
|
+
* id. Caller is expected to surface this id to the user before any
|
|
1037
|
+
* progress event fires so a `client.rag.ingestAsync` consumer can
|
|
1038
|
+
* immediately address the job (e.g. `POST /api/rag/jobs/:jobId/cancel`).
|
|
1039
|
+
*/
|
|
1040
|
+
start(args: IngestJobStartArgs): Promise<Result<{
|
|
1041
|
+
jobId: string;
|
|
1042
|
+
}>>;
|
|
1043
|
+
/** Idempotent — last write wins on `progress` jsonb. */
|
|
1044
|
+
progress(args: IngestJobProgressArgs): Promise<void>;
|
|
1045
|
+
/** Marks the row terminal (status='succeeded'). */
|
|
1046
|
+
complete(args: IngestJobCompleteArgs): Promise<void>;
|
|
1047
|
+
/** Marks the row terminal (status='failed') and stores the error message. */
|
|
1048
|
+
fail(args: IngestJobFailArgs): Promise<void>;
|
|
1049
|
+
/**
|
|
1050
|
+
* Polled between chunk batches. Returning `true` makes the pipeline abort
|
|
1051
|
+
* with `rag_ingest_cancelled`, leaving the row in whatever terminal state
|
|
1052
|
+
* the writer transitions it to next (typically `cancelled`).
|
|
1053
|
+
*/
|
|
1054
|
+
isCancelled(args: {
|
|
1055
|
+
jobId: string;
|
|
1056
|
+
}): Promise<boolean>;
|
|
1057
|
+
}
|
|
1010
1058
|
|
|
1011
1059
|
interface ParseOptions {
|
|
1012
1060
|
/** MIME type override. If omitted, the parser sniffs the input (Blob.type or PDF magic bytes). */
|
|
@@ -1120,13 +1168,26 @@ interface IngestAsyncHandle {
|
|
|
1120
1168
|
* an operation hits `42P01 relation does not exist`, the pipeline returns
|
|
1121
1169
|
* `SdkError('rag_schema_missing')` with an actionable hint.
|
|
1122
1170
|
*/
|
|
1171
|
+
/**
|
|
1172
|
+
* Test-only seams accepted by `RagModule`. Production callers leave these
|
|
1173
|
+
* unset — they are injected by `ingest-async.spec.ts` to substitute the
|
|
1174
|
+
* shared-pool lookup and the SQL-backed job writer.
|
|
1175
|
+
*/
|
|
1176
|
+
interface RagModuleTestDeps {
|
|
1177
|
+
/** Replaces the lazy `getDatabaseHandle()` lookup used by `ingestAsync`. */
|
|
1178
|
+
sqlProvider?: () => Result<Sql>;
|
|
1179
|
+
/** Builds an `IngestJobWriter` from the resolved SQL. Defaults to `createSqlJobWriter`. */
|
|
1180
|
+
jobWriterFactory?: (sql: Sql) => IngestJobWriter;
|
|
1181
|
+
}
|
|
1123
1182
|
declare class RagModule {
|
|
1124
1183
|
private readonly _resolved;
|
|
1125
1184
|
private readonly _getAi;
|
|
1126
1185
|
private readonly _gate;
|
|
1186
|
+
private readonly _testSqlOverride?;
|
|
1187
|
+
private readonly _testJobWriterFactory?;
|
|
1127
1188
|
constructor(_resolved: ResolvedConfig, _getAi: () => AiModule,
|
|
1128
1189
|
/** Test seam — see `ModuleGate`. Defaults to the lazy contract gate. */
|
|
1129
|
-
gate?: ModuleGate);
|
|
1190
|
+
gate?: ModuleGate, testDeps?: RagModuleTestDeps);
|
|
1130
1191
|
ingest(request: IngestRequest): Promise<Result<IngestResponse>>;
|
|
1131
1192
|
/**
|
|
1132
1193
|
* Asynchronous ingest. Allocates a `stackbone_rag_jobs` row, returns the
|
|
@@ -1143,10 +1204,6 @@ declare class RagModule {
|
|
|
1143
1204
|
* exactly one pool against `STACKBONE_POSTGRES_URL`.
|
|
1144
1205
|
*/
|
|
1145
1206
|
ingestAsync(request: IngestRequest): Promise<Result<IngestAsyncHandle>>;
|
|
1146
|
-
/** Test-only seam — assigned by `ingest-async.spec.ts`. */
|
|
1147
|
-
private _testJobWriter?;
|
|
1148
|
-
/** Test-only seam — assigned by `ingest-async.spec.ts`. */
|
|
1149
|
-
private _testSqlOverride?;
|
|
1150
1207
|
delete(ids: string | string[], options?: DeleteOptions): Promise<Result<DeleteResponse>>;
|
|
1151
1208
|
deleteWhere(filter: Record<string, unknown>, options?: DeleteOptions): Promise<Result<DeleteResponse>>;
|
|
1152
1209
|
retrieve(request: RetrieveRequest): Promise<Result<RetrieveHit[]>>;
|
|
@@ -1267,6 +1324,7 @@ declare class StorageBucket {
|
|
|
1267
1324
|
getPublicUrl(key: string): Result<string>;
|
|
1268
1325
|
getSignedUploadUrl(key: string, options?: SignedUrlOptions): Promise<Result<SignedUrl>>;
|
|
1269
1326
|
getSignedDownloadUrl(key: string, options?: SignedUrlOptions): Promise<Result<SignedUrl>>;
|
|
1327
|
+
private signUrl;
|
|
1270
1328
|
/**
|
|
1271
1329
|
* Resolves S3 settings, validates the user key, and prefixes it with
|
|
1272
1330
|
* `${agentId}/${bucketName}/`. Rejects path-traversal segments (`..`) so a
|
package/index.d.ts
CHANGED
|
@@ -19,10 +19,9 @@ interface ClientConfig {
|
|
|
19
19
|
agentId?: string;
|
|
20
20
|
/**
|
|
21
21
|
* Postgres connection string consumed by `client.rag` and the platform
|
|
22
|
-
* observability exporter. Falls back to `
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* `DATABASE_URL` consumers until `feature 30` consolidates them.
|
|
22
|
+
* observability exporter. Falls back to `STACKBONE_POSTGRES_URL` — the same
|
|
23
|
+
* env var `client.database` reads, so a single connection string covers
|
|
24
|
+
* every SDK consumer that talks to the agent's Postgres.
|
|
26
25
|
*/
|
|
27
26
|
databaseUrl?: string;
|
|
28
27
|
openrouterKey?: string;
|
|
@@ -46,14 +45,16 @@ interface ClientConfig {
|
|
|
46
45
|
*/
|
|
47
46
|
installationId?: string;
|
|
48
47
|
s3?: {
|
|
49
|
-
/** Falls back to `
|
|
48
|
+
/** Falls back to `STACKBONE_S3_ACCESS_KEY`. */
|
|
50
49
|
accessKeyId?: string;
|
|
51
|
-
/** Falls back to `
|
|
50
|
+
/** Falls back to `STACKBONE_S3_SECRET_KEY`. */
|
|
52
51
|
secretAccessKey?: string;
|
|
53
|
-
/** Falls back to `
|
|
52
|
+
/** Falls back to `STACKBONE_S3_ENDPOINT`. */
|
|
54
53
|
endpoint?: string;
|
|
55
|
-
/** Physical R2/S3 bucket scoped to the agent. Falls back to `
|
|
54
|
+
/** Physical R2/S3 bucket scoped to the agent. Falls back to `STACKBONE_S3_BUCKET`. */
|
|
56
55
|
bucket?: string;
|
|
56
|
+
/** AWS region. Falls back to `STACKBONE_S3_REGION`, defaults to `'auto'` (R2/MinIO). */
|
|
57
|
+
region?: string;
|
|
57
58
|
};
|
|
58
59
|
otel?: {
|
|
59
60
|
exporterOtlpEndpoint?: string;
|
|
@@ -337,7 +338,7 @@ declare class ConnectionsFacade {
|
|
|
337
338
|
list(): Promise<Result<readonly never[]>>;
|
|
338
339
|
}
|
|
339
340
|
|
|
340
|
-
/** Emit events to the
|
|
341
|
+
/** Emit events to the organization event bus. */
|
|
341
342
|
declare class EventsFacade {
|
|
342
343
|
private readonly _http;
|
|
343
344
|
private readonly _gate;
|
|
@@ -424,7 +425,7 @@ declare class SecretsFacade {
|
|
|
424
425
|
gate?: ModuleGate);
|
|
425
426
|
get(name: string): Promise<Result<string>>;
|
|
426
427
|
/**
|
|
427
|
-
* Names absent from the
|
|
428
|
+
* Names absent from the organization come back as omissions in the response —
|
|
428
429
|
* the returned map only contains entries the control plane actually has.
|
|
429
430
|
* Callers that need "all-or-nothing" semantics should diff the keys.
|
|
430
431
|
*/
|
|
@@ -1007,6 +1008,53 @@ type RagIngestProgress = {
|
|
|
1007
1008
|
jobId: string;
|
|
1008
1009
|
error: string;
|
|
1009
1010
|
};
|
|
1011
|
+
interface IngestJobStartArgs {
|
|
1012
|
+
collection: string;
|
|
1013
|
+
source: string;
|
|
1014
|
+
totalChunks: number;
|
|
1015
|
+
}
|
|
1016
|
+
interface IngestJobProgressArgs {
|
|
1017
|
+
jobId: string;
|
|
1018
|
+
processedChunks: number;
|
|
1019
|
+
totalChunks: number;
|
|
1020
|
+
currentDocument?: {
|
|
1021
|
+
source: string;
|
|
1022
|
+
ordinal: number;
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
interface IngestJobCompleteArgs {
|
|
1026
|
+
jobId: string;
|
|
1027
|
+
totalChunks: number;
|
|
1028
|
+
}
|
|
1029
|
+
interface IngestJobFailArgs {
|
|
1030
|
+
jobId: string;
|
|
1031
|
+
error: string;
|
|
1032
|
+
}
|
|
1033
|
+
interface IngestJobWriter {
|
|
1034
|
+
/**
|
|
1035
|
+
* Allocates a `stackbone_rag_jobs` row in `running` state and returns its
|
|
1036
|
+
* id. Caller is expected to surface this id to the user before any
|
|
1037
|
+
* progress event fires so a `client.rag.ingestAsync` consumer can
|
|
1038
|
+
* immediately address the job (e.g. `POST /api/rag/jobs/:jobId/cancel`).
|
|
1039
|
+
*/
|
|
1040
|
+
start(args: IngestJobStartArgs): Promise<Result<{
|
|
1041
|
+
jobId: string;
|
|
1042
|
+
}>>;
|
|
1043
|
+
/** Idempotent — last write wins on `progress` jsonb. */
|
|
1044
|
+
progress(args: IngestJobProgressArgs): Promise<void>;
|
|
1045
|
+
/** Marks the row terminal (status='succeeded'). */
|
|
1046
|
+
complete(args: IngestJobCompleteArgs): Promise<void>;
|
|
1047
|
+
/** Marks the row terminal (status='failed') and stores the error message. */
|
|
1048
|
+
fail(args: IngestJobFailArgs): Promise<void>;
|
|
1049
|
+
/**
|
|
1050
|
+
* Polled between chunk batches. Returning `true` makes the pipeline abort
|
|
1051
|
+
* with `rag_ingest_cancelled`, leaving the row in whatever terminal state
|
|
1052
|
+
* the writer transitions it to next (typically `cancelled`).
|
|
1053
|
+
*/
|
|
1054
|
+
isCancelled(args: {
|
|
1055
|
+
jobId: string;
|
|
1056
|
+
}): Promise<boolean>;
|
|
1057
|
+
}
|
|
1010
1058
|
|
|
1011
1059
|
interface ParseOptions {
|
|
1012
1060
|
/** MIME type override. If omitted, the parser sniffs the input (Blob.type or PDF magic bytes). */
|
|
@@ -1120,13 +1168,26 @@ interface IngestAsyncHandle {
|
|
|
1120
1168
|
* an operation hits `42P01 relation does not exist`, the pipeline returns
|
|
1121
1169
|
* `SdkError('rag_schema_missing')` with an actionable hint.
|
|
1122
1170
|
*/
|
|
1171
|
+
/**
|
|
1172
|
+
* Test-only seams accepted by `RagModule`. Production callers leave these
|
|
1173
|
+
* unset — they are injected by `ingest-async.spec.ts` to substitute the
|
|
1174
|
+
* shared-pool lookup and the SQL-backed job writer.
|
|
1175
|
+
*/
|
|
1176
|
+
interface RagModuleTestDeps {
|
|
1177
|
+
/** Replaces the lazy `getDatabaseHandle()` lookup used by `ingestAsync`. */
|
|
1178
|
+
sqlProvider?: () => Result<Sql>;
|
|
1179
|
+
/** Builds an `IngestJobWriter` from the resolved SQL. Defaults to `createSqlJobWriter`. */
|
|
1180
|
+
jobWriterFactory?: (sql: Sql) => IngestJobWriter;
|
|
1181
|
+
}
|
|
1123
1182
|
declare class RagModule {
|
|
1124
1183
|
private readonly _resolved;
|
|
1125
1184
|
private readonly _getAi;
|
|
1126
1185
|
private readonly _gate;
|
|
1186
|
+
private readonly _testSqlOverride?;
|
|
1187
|
+
private readonly _testJobWriterFactory?;
|
|
1127
1188
|
constructor(_resolved: ResolvedConfig, _getAi: () => AiModule,
|
|
1128
1189
|
/** Test seam — see `ModuleGate`. Defaults to the lazy contract gate. */
|
|
1129
|
-
gate?: ModuleGate);
|
|
1190
|
+
gate?: ModuleGate, testDeps?: RagModuleTestDeps);
|
|
1130
1191
|
ingest(request: IngestRequest): Promise<Result<IngestResponse>>;
|
|
1131
1192
|
/**
|
|
1132
1193
|
* Asynchronous ingest. Allocates a `stackbone_rag_jobs` row, returns the
|
|
@@ -1143,10 +1204,6 @@ declare class RagModule {
|
|
|
1143
1204
|
* exactly one pool against `STACKBONE_POSTGRES_URL`.
|
|
1144
1205
|
*/
|
|
1145
1206
|
ingestAsync(request: IngestRequest): Promise<Result<IngestAsyncHandle>>;
|
|
1146
|
-
/** Test-only seam — assigned by `ingest-async.spec.ts`. */
|
|
1147
|
-
private _testJobWriter?;
|
|
1148
|
-
/** Test-only seam — assigned by `ingest-async.spec.ts`. */
|
|
1149
|
-
private _testSqlOverride?;
|
|
1150
1207
|
delete(ids: string | string[], options?: DeleteOptions): Promise<Result<DeleteResponse>>;
|
|
1151
1208
|
deleteWhere(filter: Record<string, unknown>, options?: DeleteOptions): Promise<Result<DeleteResponse>>;
|
|
1152
1209
|
retrieve(request: RetrieveRequest): Promise<Result<RetrieveHit[]>>;
|
|
@@ -1267,6 +1324,7 @@ declare class StorageBucket {
|
|
|
1267
1324
|
getPublicUrl(key: string): Result<string>;
|
|
1268
1325
|
getSignedUploadUrl(key: string, options?: SignedUrlOptions): Promise<Result<SignedUrl>>;
|
|
1269
1326
|
getSignedDownloadUrl(key: string, options?: SignedUrlOptions): Promise<Result<SignedUrl>>;
|
|
1327
|
+
private signUrl;
|
|
1270
1328
|
/**
|
|
1271
1329
|
* Resolves S3 settings, validates the user key, and prefixes it with
|
|
1272
1330
|
* `${agentId}/${bucketName}/`. Rejects path-traversal segments (`..`) so a
|