@mindstudio-ai/agent 0.1.119 → 0.1.120

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/dist/index.d.ts CHANGED
@@ -2521,6 +2521,12 @@ interface DataSourceDocument {
2521
2521
  createdAt: string;
2522
2522
  ingestedAt: string | null;
2523
2523
  }
2524
+ /** One page of a corpus. See {@link DataSource.documentsPage}. */
2525
+ interface DataSourceDocumentPage {
2526
+ documents: DataSourceDocument[];
2527
+ /** Pass to the next call; null when this was the last page. */
2528
+ nextCursor: string | null;
2529
+ }
2524
2530
  /** One chunk exactly as it was indexed. See {@link DataSource.chunks}. */
2525
2531
  interface DataSourceChunk {
2526
2532
  index: number;
@@ -2821,16 +2827,41 @@ declare class DataSource {
2821
2827
  /**
2822
2828
  * Documents in the corpus, with ingest status.
2823
2829
  *
2824
- * Without options this is the first thousand, newest first: enough to show
2825
- * a small corpus, not a way to walk a large one (a corpus of any size is
2826
- * loaded and inspected from the CLI). To follow what {@link add} just
2827
- * queued, pass the ids it returned: `documents({ ids })` answers only those,
2828
- * at most two hundred per call.
2830
+ * Without options this is the first page only: the oldest thousand, enough
2831
+ * to show a small corpus. To walk a corpus of any size use
2832
+ * {@link allDocuments} (or {@link documentsPage} for one page at a time). To
2833
+ * follow what {@link add} just queued, pass the ids it returned:
2834
+ * `documents({ ids })` answers only those, at most two hundred per call.
2829
2835
  */
2830
2836
  documents(options?: {
2831
2837
  /** Only these documents (at most 200). */
2832
2838
  ids?: string[];
2833
2839
  }): Promise<DataSourceDocument[]>;
2840
+ /**
2841
+ * One page of the corpus, oldest first, with the cursor for the next page.
2842
+ * `limit` is at most 1,000 (the default).
2843
+ */
2844
+ documentsPage(options?: {
2845
+ cursor?: string | null;
2846
+ limit?: number;
2847
+ }): Promise<DataSourceDocumentPage>;
2848
+ /**
2849
+ * Every document in the corpus, oldest first, a page at a time behind the
2850
+ * scenes. This is how an app builds its own view of a large corpus (a
2851
+ * timeline, counts by year, a table of ids) after an ingest: walk it once,
2852
+ * then keep up with what each sync adds. Millions of documents is thousands
2853
+ * of pages, so run it in a background task, not a request.
2854
+ *
2855
+ * ```ts
2856
+ * for await (const doc of Archive.allDocuments()) {
2857
+ * await index.upsert({ id: doc.id, year: doc.metadata?.year });
2858
+ * }
2859
+ * ```
2860
+ */
2861
+ allDocuments(options?: {
2862
+ /** Documents per page, at most 1,000 (the default). */
2863
+ pageSize?: number;
2864
+ }): AsyncGenerator<DataSourceDocument, void, undefined>;
2834
2865
  /** Remove a document and its vectors. */
2835
2866
  remove(documentId: string): Promise<void>;
2836
2867
  /**
package/dist/index.js CHANGED
@@ -2979,11 +2979,11 @@ var DataSource = class {
2979
2979
  /**
2980
2980
  * Documents in the corpus, with ingest status.
2981
2981
  *
2982
- * Without options this is the first thousand, newest first: enough to show
2983
- * a small corpus, not a way to walk a large one (a corpus of any size is
2984
- * loaded and inspected from the CLI). To follow what {@link add} just
2985
- * queued, pass the ids it returned: `documents({ ids })` answers only those,
2986
- * at most two hundred per call.
2982
+ * Without options this is the first page only: the oldest thousand, enough
2983
+ * to show a small corpus. To walk a corpus of any size use
2984
+ * {@link allDocuments} (or {@link documentsPage} for one page at a time). To
2985
+ * follow what {@link add} just queued, pass the ids it returned:
2986
+ * `documents({ ids })` answers only those, at most two hundred per call.
2987
2987
  */
2988
2988
  async documents(options) {
2989
2989
  const { documents: documents2 } = await this._call("documents", {
@@ -2992,6 +2992,47 @@ var DataSource = class {
2992
2992
  });
2993
2993
  return documents2 ?? [];
2994
2994
  }
2995
+ /**
2996
+ * One page of the corpus, oldest first, with the cursor for the next page.
2997
+ * `limit` is at most 1,000 (the default).
2998
+ */
2999
+ async documentsPage(options) {
3000
+ const { documents: documents2, nextCursor } = await this._call("documents", {
3001
+ slug: this._slug,
3002
+ ...options?.cursor ? { cursor: options.cursor } : {},
3003
+ ...options?.limit ? { limit: options.limit } : {}
3004
+ });
3005
+ return { documents: documents2 ?? [], nextCursor: nextCursor ?? null };
3006
+ }
3007
+ /**
3008
+ * Every document in the corpus, oldest first, a page at a time behind the
3009
+ * scenes. This is how an app builds its own view of a large corpus (a
3010
+ * timeline, counts by year, a table of ids) after an ingest: walk it once,
3011
+ * then keep up with what each sync adds. Millions of documents is thousands
3012
+ * of pages, so run it in a background task, not a request.
3013
+ *
3014
+ * ```ts
3015
+ * for await (const doc of Archive.allDocuments()) {
3016
+ * await index.upsert({ id: doc.id, year: doc.metadata?.year });
3017
+ * }
3018
+ * ```
3019
+ */
3020
+ async *allDocuments(options) {
3021
+ let cursor = null;
3022
+ while (true) {
3023
+ const page = await this.documentsPage({
3024
+ cursor,
3025
+ ...options?.pageSize ? { limit: options.pageSize } : {}
3026
+ });
3027
+ for (const doc of page.documents) {
3028
+ yield doc;
3029
+ }
3030
+ if (!page.nextCursor || page.documents.length === 0) {
3031
+ return;
3032
+ }
3033
+ cursor = page.nextCursor;
3034
+ }
3035
+ }
2995
3036
  /** Remove a document and its vectors. */
2996
3037
  async remove(documentId) {
2997
3038
  await this._call("remove", { slug: this._slug, documentId });