@sprigr/apps-app-sdk 0.6.0 → 0.7.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 (2) hide show
  1. package/dist/index.d.ts +116 -15
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -901,6 +901,56 @@ interface SprigrDataSearchOpts {
901
901
  page?: number;
902
902
  /** Results per page. Default 20, platform-clamped to 100. */
903
903
  hitsPerPage?: number;
904
+ /**
905
+ * LOGICAL index name — a key of the manifest's `data_indexes` map.
906
+ * Required for apps that declare `data_indexes` (the platform rejects a
907
+ * call without it, naming the declared indexes); must be OMITTED for
908
+ * legacy single-`data_index` apps. An undeclared name is rejected with
909
+ * `unknown_data_index`, never auto-created.
910
+ */
911
+ index?: string;
912
+ /**
913
+ * Explicit shard subset for a sharded logical index: `['2026']` for
914
+ * `shard_by: 'year'`, `['2026-05', '2026-06']` for `'month'`. Omit to
915
+ * search every existing shard (newest first). Narrowing here is also the
916
+ * escape hatch when merged pagination hits the per-shard page cap.
917
+ */
918
+ shards?: string[];
919
+ /**
920
+ * Server-side aggregations computed over ALL matching docs (not just the
921
+ * returned page). On a sharded logical index the platform merges shard
922
+ * results exactly (sum/count add, min/max take extremes, avg re-derives
923
+ * count-weighted).
924
+ */
925
+ aggregations?: SprigrDataAggregationSpec[];
926
+ }
927
+ /** One server-side aggregation. Wire fields are snake_case (platform decision 0013). */
928
+ interface SprigrDataAggregationSpec {
929
+ /** Response key for this aggregation's result block. */
930
+ name: string;
931
+ /** Fold operation. `count` ignores `field`. */
932
+ op: 'sum' | 'avg' | 'min' | 'max' | 'count';
933
+ /** Numeric field to fold. Required for sum/avg/min/max. */
934
+ field?: string;
935
+ /** Bucket by this field; omit for one whole-result-set value. */
936
+ group_by?: string;
937
+ }
938
+ /** One aggregation result cell: the op value plus (for non-count ops) the numeric-value count. */
939
+ interface SprigrDataAggregationCell {
940
+ sum?: number | null;
941
+ avg?: number | null;
942
+ min?: number | null;
943
+ max?: number | null;
944
+ count?: number;
945
+ }
946
+ interface SprigrDataAggregationResult {
947
+ op: 'sum' | 'avg' | 'min' | 'max' | 'count';
948
+ field: string | null;
949
+ group_by: string | null;
950
+ /** Present for ungrouped specs. */
951
+ value?: SprigrDataAggregationCell;
952
+ /** Present for grouped specs: bucket value -> cell. */
953
+ groups?: Record<string, SprigrDataAggregationCell>;
904
954
  }
905
955
  interface SprigrDataSearchResult {
906
956
  ok: boolean;
@@ -911,14 +961,34 @@ interface SprigrDataSearchResult {
911
961
  nbHits: number;
912
962
  page: number;
913
963
  facetCounts?: Record<string, Record<string, number>>;
914
- /** The private index that was queried (informational). */
964
+ /** Present when the request carried `aggregations`. */
965
+ aggregations?: Record<string, SprigrDataAggregationResult>;
966
+ /**
967
+ * The logical index name for multi-index apps, else the physical index
968
+ * that was queried (informational).
969
+ */
915
970
  index: string;
971
+ /** Multi-index apps: the physical index/shard names this read covered. */
972
+ physical_indexes?: string[];
973
+ }
974
+ /** Options shared by data methods that can target a logical index. */
975
+ interface SprigrDataIndexOpts {
976
+ /** LOGICAL index name (a `data_indexes` key). See {@link SprigrDataSearchOpts.index}. */
977
+ index?: string;
916
978
  }
917
979
  /**
918
- * The marketplace install's PRIVATE per-company datastore: a Sprigr
919
- * index named `<companyId>-app-<slug>`, reachable only through these
920
- * methods (agents have no direct index access). Injected on
921
- * `env.SPRIGR` by the platform wrapper for /__sprigr/* dispatch.
980
+ * The marketplace install's per-company datastore on Sprigr search,
981
+ * injected on `env.SPRIGR` by the platform wrapper for /__sprigr/*
982
+ * dispatch.
983
+ *
984
+ * Single-index apps (manifest `data_index`) get the fixed
985
+ * `<companyId>-app-<slug>` index and never pass `index`. Multi-index apps
986
+ * (manifest `data_indexes`, a map of logical name -> config) pass
987
+ * `{ index: '<logical name>' }` on EVERY call; the platform derives the
988
+ * physical name(s) server-side, including per-year/per-month shards for
989
+ * logical indexes that declare `shard_by` + an immutable ISO-date
990
+ * `shard_field`. Every physical index is registered with the company at
991
+ * creation, so agents can discover it via `sprigr_list_my_indexes`.
922
992
  *
923
993
  * Intended pattern: the app syncs lean provider objects via `import`,
924
994
  * its tool handlers call `search` to resolve a fuzzy human reference
@@ -928,30 +998,61 @@ interface SprigrDataSearchResult {
928
998
  */
929
999
  interface SprigrDataApi {
930
1000
  /**
931
- * Upsert objects into the private index. Each object MUST carry a
932
- * unique string `objectID`. The index is auto-created on first
933
- * import from the manifest's `data_index` settings; re-imports
934
- * upsert by objectID. Max 1000 objects per call.
1001
+ * Upsert objects into the store. Each object MUST carry a unique string
1002
+ * `objectID`. Max 1000 objects per call. Indexes are auto-created on
1003
+ * first import from the manifest settings; re-imports upsert by
1004
+ * objectID.
1005
+ *
1006
+ * Sharded logical indexes route each object by its `shard_field` date;
1007
+ * an object whose value is missing or not an ISO-8601 date string fails
1008
+ * the WHOLE batch (`shard_field_invalid`) — fix the data, don't guess.
1009
+ * The response's `physical_indexes` lists what was written per shard.
935
1010
  */
936
1011
  import(objects: Array<{
937
1012
  objectID: string;
938
1013
  [key: string]: unknown;
939
- }>): Promise<{
1014
+ }>, opts?: SprigrDataIndexOpts): Promise<{
940
1015
  ok: boolean;
941
1016
  indexed: number;
942
1017
  index: string;
1018
+ physical_indexes?: Array<{
1019
+ index: string;
1020
+ shard?: string;
1021
+ indexed: number;
1022
+ }>;
943
1023
  }>;
944
1024
  /**
945
- * Search the private index. A never-imported index yields an empty
946
- * hit list, not an error.
1025
+ * Search the store. A never-imported index yields an empty hit list,
1026
+ * not an error. Sharded logical indexes fan out across shards and merge
1027
+ * (nbHits sums, facet counts sum, aggregations merge exactly; without
1028
+ * `sortBy`, merged hits come newest shard first).
947
1029
  */
948
1030
  search(opts?: SprigrDataSearchOpts): Promise<SprigrDataSearchResult>;
949
- /** Fetch one object by objectID. `object` is null when absent. */
950
- get(objectID: string): Promise<{
1031
+ /**
1032
+ * Fetch one object by objectID. `object` is null when absent. On a
1033
+ * sharded logical index the platform probes shards newest-first.
1034
+ */
1035
+ get(objectID: string, opts?: SprigrDataIndexOpts): Promise<{
951
1036
  ok: boolean;
952
1037
  object: Record<string, unknown> | null;
953
1038
  index: string;
954
1039
  }>;
1040
+ /**
1041
+ * Delete objects by objectID (mirror maintenance for source-side
1042
+ * deletions). Idempotent: unknown ids and never-imported indexes are a
1043
+ * no-op success. On a sharded logical index the delete fans out to
1044
+ * every shard. `?`-optional because older platform wrapper builds
1045
+ * predate it — feature-detect and degrade (never delete on
1046
+ * uncertainty), per the mirror-maintenance guidance in
1047
+ * docs/platform-reference.md.
1048
+ */
1049
+ delete?(objectIDs: string[], opts?: SprigrDataIndexOpts & {
1050
+ withAcl?: boolean;
1051
+ }): Promise<{
1052
+ ok: boolean;
1053
+ deleted: number;
1054
+ index: string;
1055
+ }>;
955
1056
  }
956
1057
  /**
957
1058
  * Durable app file storage exposed on `env.SPRIGR.files` by the platform
@@ -1124,4 +1225,4 @@ interface ExecutionContextLike {
1124
1225
  }
1125
1226
  type HandlerFn<TArgs, TResult> = (args: TArgs, env: Record<string, unknown>, ctx?: ExecutionContextLike) => Promise<TResult>;
1126
1227
 
1127
- export { type Actor, type AppFileListItem, type AppFileUrlArgs, type AppFileUrlResult, type AppFilesEnv, type D1Like, type D1PreparedStatementLike, DEFAULT_EMIT_TIMEOUT_MS, DEFAULT_MAX_FILE_BYTES, type EmitMarketplaceEventOptions, type EmitResult, type EmitTransport, type EventArgs, type ExecutionContextLike, type FetchFileResult, type FetchWithRetryOptions, type GetAppFileResult, type HandlerFn, type InboxOwner, type InstallBridge, type MarketplaceEventEmitOpts, type MarketplaceEventSourceIntegration, NotConnectedError, type OAuthBouncerSignals, type OAuthState, type PlatformHostEnv, type PutAppFileArgs, type PutAppFileResult, type PutAppFileStreamArgs, type ScheduleArgs, type SprigrDataApi, type SprigrDataSearchOpts, type SprigrDataSearchResult, type SprigrFilesApi, type SprigrFilesApiWithEdit, type SprigrFilesCreateInput, type SprigrFilesCreateResult, type SprigrFilesEditInput, type SprigrFilesEditResult, type SprigrFilesJobResult, type ToolResult, type ToolWrapperOptions, type WebhookArgs, type WfpBridgeEnv, type WfpEmitReply, actorKey, actorTool, appFileUrl, base64ToBytes, buildMarketplaceWebhookUrl, bytesToBase64, canEmit, constantTimeEqual, createMarketplaceEmitter, createToolWrappers, decodeState, deleteAppFile, describeMissingBridge, emitMarketplaceEvent, encodeState, fetchFileAsBase64, fetchFileBytes, fetchWithRetry, getAppFile, hmacSha256Hex, installTokenPost, isNotConnectedError, isStagingHost, listAppFiles, overlaySprigr, ownerFromActorKey, parseActor, putAppFile, putAppFileStream, randomHex, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, tool, withSprigrEmitFallback };
1228
+ export { type Actor, type AppFileListItem, type AppFileUrlArgs, type AppFileUrlResult, type AppFilesEnv, type D1Like, type D1PreparedStatementLike, DEFAULT_EMIT_TIMEOUT_MS, DEFAULT_MAX_FILE_BYTES, type EmitMarketplaceEventOptions, type EmitResult, type EmitTransport, type EventArgs, type ExecutionContextLike, type FetchFileResult, type FetchWithRetryOptions, type GetAppFileResult, type HandlerFn, type InboxOwner, type InstallBridge, type MarketplaceEventEmitOpts, type MarketplaceEventSourceIntegration, NotConnectedError, type OAuthBouncerSignals, type OAuthState, type PlatformHostEnv, type PutAppFileArgs, type PutAppFileResult, type PutAppFileStreamArgs, type ScheduleArgs, type SprigrDataAggregationCell, type SprigrDataAggregationResult, type SprigrDataAggregationSpec, type SprigrDataApi, type SprigrDataIndexOpts, type SprigrDataSearchOpts, type SprigrDataSearchResult, type SprigrFilesApi, type SprigrFilesApiWithEdit, type SprigrFilesCreateInput, type SprigrFilesCreateResult, type SprigrFilesEditInput, type SprigrFilesEditResult, type SprigrFilesJobResult, type ToolResult, type ToolWrapperOptions, type WebhookArgs, type WfpBridgeEnv, type WfpEmitReply, actorKey, actorTool, appFileUrl, base64ToBytes, buildMarketplaceWebhookUrl, bytesToBase64, canEmit, constantTimeEqual, createMarketplaceEmitter, createToolWrappers, decodeState, deleteAppFile, describeMissingBridge, emitMarketplaceEvent, encodeState, fetchFileAsBase64, fetchFileBytes, fetchWithRetry, getAppFile, hmacSha256Hex, installTokenPost, isNotConnectedError, isStagingHost, listAppFiles, overlaySprigr, ownerFromActorKey, parseActor, putAppFile, putAppFileStream, randomHex, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, tool, withSprigrEmitFallback };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprigr/apps-app-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",