@stackbone/sdk 0.1.0-alpha.1 → 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/index.d.cts CHANGED
@@ -338,7 +338,7 @@ declare class ConnectionsFacade {
338
338
  list(): Promise<Result<readonly never[]>>;
339
339
  }
340
340
 
341
- /** Emit events to the workspace event bus. */
341
+ /** Emit events to the organization event bus. */
342
342
  declare class EventsFacade {
343
343
  private readonly _http;
344
344
  private readonly _gate;
@@ -425,7 +425,7 @@ declare class SecretsFacade {
425
425
  gate?: ModuleGate);
426
426
  get(name: string): Promise<Result<string>>;
427
427
  /**
428
- * Names absent from the workspace come back as omissions in the response —
428
+ * Names absent from the organization come back as omissions in the response —
429
429
  * the returned map only contains entries the control plane actually has.
430
430
  * Callers that need "all-or-nothing" semantics should diff the keys.
431
431
  */
@@ -1008,6 +1008,53 @@ type RagIngestProgress = {
1008
1008
  jobId: string;
1009
1009
  error: string;
1010
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
+ }
1011
1058
 
1012
1059
  interface ParseOptions {
1013
1060
  /** MIME type override. If omitted, the parser sniffs the input (Blob.type or PDF magic bytes). */
@@ -1121,13 +1168,26 @@ interface IngestAsyncHandle {
1121
1168
  * an operation hits `42P01 relation does not exist`, the pipeline returns
1122
1169
  * `SdkError('rag_schema_missing')` with an actionable hint.
1123
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
+ }
1124
1182
  declare class RagModule {
1125
1183
  private readonly _resolved;
1126
1184
  private readonly _getAi;
1127
1185
  private readonly _gate;
1186
+ private readonly _testSqlOverride?;
1187
+ private readonly _testJobWriterFactory?;
1128
1188
  constructor(_resolved: ResolvedConfig, _getAi: () => AiModule,
1129
1189
  /** Test seam — see `ModuleGate`. Defaults to the lazy contract gate. */
1130
- gate?: ModuleGate);
1190
+ gate?: ModuleGate, testDeps?: RagModuleTestDeps);
1131
1191
  ingest(request: IngestRequest): Promise<Result<IngestResponse>>;
1132
1192
  /**
1133
1193
  * Asynchronous ingest. Allocates a `stackbone_rag_jobs` row, returns the
@@ -1144,10 +1204,6 @@ declare class RagModule {
1144
1204
  * exactly one pool against `STACKBONE_POSTGRES_URL`.
1145
1205
  */
1146
1206
  ingestAsync(request: IngestRequest): Promise<Result<IngestAsyncHandle>>;
1147
- /** Test-only seam — assigned by `ingest-async.spec.ts`. */
1148
- private _testJobWriter?;
1149
- /** Test-only seam — assigned by `ingest-async.spec.ts`. */
1150
- private _testSqlOverride?;
1151
1207
  delete(ids: string | string[], options?: DeleteOptions): Promise<Result<DeleteResponse>>;
1152
1208
  deleteWhere(filter: Record<string, unknown>, options?: DeleteOptions): Promise<Result<DeleteResponse>>;
1153
1209
  retrieve(request: RetrieveRequest): Promise<Result<RetrieveHit[]>>;
@@ -1268,6 +1324,7 @@ declare class StorageBucket {
1268
1324
  getPublicUrl(key: string): Result<string>;
1269
1325
  getSignedUploadUrl(key: string, options?: SignedUrlOptions): Promise<Result<SignedUrl>>;
1270
1326
  getSignedDownloadUrl(key: string, options?: SignedUrlOptions): Promise<Result<SignedUrl>>;
1327
+ private signUrl;
1271
1328
  /**
1272
1329
  * Resolves S3 settings, validates the user key, and prefixes it with
1273
1330
  * `${agentId}/${bucketName}/`. Rejects path-traversal segments (`..`) so a
package/index.d.ts CHANGED
@@ -338,7 +338,7 @@ declare class ConnectionsFacade {
338
338
  list(): Promise<Result<readonly never[]>>;
339
339
  }
340
340
 
341
- /** Emit events to the workspace event bus. */
341
+ /** Emit events to the organization event bus. */
342
342
  declare class EventsFacade {
343
343
  private readonly _http;
344
344
  private readonly _gate;
@@ -425,7 +425,7 @@ declare class SecretsFacade {
425
425
  gate?: ModuleGate);
426
426
  get(name: string): Promise<Result<string>>;
427
427
  /**
428
- * Names absent from the workspace come back as omissions in the response —
428
+ * Names absent from the organization come back as omissions in the response —
429
429
  * the returned map only contains entries the control plane actually has.
430
430
  * Callers that need "all-or-nothing" semantics should diff the keys.
431
431
  */
@@ -1008,6 +1008,53 @@ type RagIngestProgress = {
1008
1008
  jobId: string;
1009
1009
  error: string;
1010
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
+ }
1011
1058
 
1012
1059
  interface ParseOptions {
1013
1060
  /** MIME type override. If omitted, the parser sniffs the input (Blob.type or PDF magic bytes). */
@@ -1121,13 +1168,26 @@ interface IngestAsyncHandle {
1121
1168
  * an operation hits `42P01 relation does not exist`, the pipeline returns
1122
1169
  * `SdkError('rag_schema_missing')` with an actionable hint.
1123
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
+ }
1124
1182
  declare class RagModule {
1125
1183
  private readonly _resolved;
1126
1184
  private readonly _getAi;
1127
1185
  private readonly _gate;
1186
+ private readonly _testSqlOverride?;
1187
+ private readonly _testJobWriterFactory?;
1128
1188
  constructor(_resolved: ResolvedConfig, _getAi: () => AiModule,
1129
1189
  /** Test seam — see `ModuleGate`. Defaults to the lazy contract gate. */
1130
- gate?: ModuleGate);
1190
+ gate?: ModuleGate, testDeps?: RagModuleTestDeps);
1131
1191
  ingest(request: IngestRequest): Promise<Result<IngestResponse>>;
1132
1192
  /**
1133
1193
  * Asynchronous ingest. Allocates a `stackbone_rag_jobs` row, returns the
@@ -1144,10 +1204,6 @@ declare class RagModule {
1144
1204
  * exactly one pool against `STACKBONE_POSTGRES_URL`.
1145
1205
  */
1146
1206
  ingestAsync(request: IngestRequest): Promise<Result<IngestAsyncHandle>>;
1147
- /** Test-only seam — assigned by `ingest-async.spec.ts`. */
1148
- private _testJobWriter?;
1149
- /** Test-only seam — assigned by `ingest-async.spec.ts`. */
1150
- private _testSqlOverride?;
1151
1207
  delete(ids: string | string[], options?: DeleteOptions): Promise<Result<DeleteResponse>>;
1152
1208
  deleteWhere(filter: Record<string, unknown>, options?: DeleteOptions): Promise<Result<DeleteResponse>>;
1153
1209
  retrieve(request: RetrieveRequest): Promise<Result<RetrieveHit[]>>;
@@ -1268,6 +1324,7 @@ declare class StorageBucket {
1268
1324
  getPublicUrl(key: string): Result<string>;
1269
1325
  getSignedUploadUrl(key: string, options?: SignedUrlOptions): Promise<Result<SignedUrl>>;
1270
1326
  getSignedDownloadUrl(key: string, options?: SignedUrlOptions): Promise<Result<SignedUrl>>;
1327
+ private signUrl;
1271
1328
  /**
1272
1329
  * Resolves S3 settings, validates the user key, and prefixes it with
1273
1330
  * `${agentId}/${bucketName}/`. Rejects path-traversal segments (`..`) so a