@mindstudio-ai/agent 0.1.182 → 0.1.184

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 CHANGED
@@ -4,6 +4,25 @@ What changed in `@mindstudio-ai/agent`, newest first, each version under its own
4
4
 
5
5
  Versions before 0.1.163 aren't recorded here.
6
6
 
7
+ ## 0.1.184
8
+
9
+ ### New
10
+
11
+ - A data source's `addMany(documents, { budgetDollars? })` adds many records at once: rows of the app's own tables rendered to text, as an array or any iterable or async iterable of `{ externalId, title, markdown, metadata?, entities?, replaces? }`, in any number. One job builds them, priced before it runs and starting on its own within the budget, and the call returns `{ documentCount, job }`. An `externalId` the source already holds is superseded when the job finishes, and unchanged markdown builds nothing. It throws `data_source_busy` while another job runs on the source and `data_source_mapped` on a source with a mapper. Check: code that loads many records by calling `add()` in a loop can give them to `addMany()` in one call.
12
+
13
+ ### Changed behavior
14
+
15
+ - The platform limits `add()` to 300 calls a minute per app and answers `rate_limited` (429) past it. Check: a method that adds documents in a loop, or in a `Promise.all` larger than that, should give them to `addMany()`.
16
+ - A source has no limit on how many documents it holds beyond the room where it lives. `add()` doesn't throw `document_limit_reached`; it throws `data_source_full` (422) when the source has no room, and the message says how to give it more. Check: code that catches `document_limit_reached` can catch `data_source_full` instead, or drop the catch.
17
+ - Types only: a job's `source` may be `{ type: 'documents', documents }`, the documents an `addMany()` gave. Check: code that switches over a job's `source.type`.
18
+
19
+ ## 0.1.183
20
+
21
+ ### Changed behavior
22
+
23
+ - `mindstudio login` waits for the browser's approval for as long as the platform keeps the sign-in open, which the platform now says when the sign-in starts: three minutes. It waited two minutes whatever the platform's own limit was, and against a platform that doesn't say it still does. Check: nothing in app code. A script that drives `mindstudio login` and expects it to give up after two minutes should allow three.
24
+ - `extractText`'s usage notes say which size limit applies to a file: 50 MB for a URL that isn't one of the app's own files, and for a kind read without a model (text, HTML, spreadsheets, office documents); the model's own limit for one of the app's files that a model reads. They used to say both "up to 100 MB" for LlamaParse and "50MB per URL". Nothing changed at run time. Check: nothing.
25
+
7
26
  ## 0.1.182
8
27
 
9
28
  ### New
package/dist/cli.js CHANGED
@@ -306,8 +306,8 @@ var init_metadata = __esm({
306
306
  "evaluateDecision": {
307
307
  stepType: "evaluateDecision",
308
308
  description: "Ask structured questions about text, JSON, or images and get calibrated answers from a decision model. The model returns a probability, a selected option, or a score. It does not write a reply. Each question is a noul (yes or no, as a probability from 0 to 1), a choice (one option from a set you define, with a probability for each), or a score (a rating against ordered levels). Put every question in the same call. The question id is yours: answers come back under the same ids. The model defaults to Jev (jev-latest).",
309
- usageNotes: "- state is the content to judge: a string, or a JSON object or array (a record, a chat log, application state).\n- questions is a map. The key is an id you choose. It is not shown to the model. The answer comes back under the same id.\n- A noul asks a yes/no question and returns noul, a probability from 0 (no) to 1 (yes). Optional criteria.true and criteria.false say what a yes and a no mean.\n- A choice picks one option. criteria is a map of option id to a short description (or null). At most 255 options. The answer includes the winning choice, a probability for every option, and confidence.\n- A score rates the state on an ordered rubric. criteria is 2 to 10 level descriptions, low to high. The answer's score can land between levels, and includes a probability per level plus confidence.\n- An answer of type refusal means the model declined that question (GPT-6 Luna Decisions can).\n- instructions may be a string, or an object that keeps the question in one field and reference data in the others. Refer to those fields by name in backticks.\n- Send every question you need in one call. The model reads the state once and answers them together.\n- Probabilities from different models are not comparable: tune a threshold against the model, and the version, it will run on.\n- decisionModelOverride.model picks the model:\n - jev-latest (the default) is TypeSafe's current stable release, text only, up to 64k tokens. jev-preview tracks TypeSafe's newest release. Pin a version such as jev-1.13.0 when a threshold was tuned against that version.\n - clef and clef-flash run Cloudflare Clef, which also reads up to 4 PNG, JPEG, or WebP images, each at most 4 MiB and 8 MiB together, and takes at most 64 questions, each id using only letters, digits, underscore, dot, and hyphen, up to 100 characters. clef is the larger model, clef-flash the faster one. @cf/cloudflare/clef and @cf/cloudflare/clef-flash name the same two.\n - mercury-decide runs Inception's Mercury Decide, which reads up to 64k tokens and up to 16 PNG, JPEG, WebP, or GIF images, each at most 10 MiB and 14 MiB together.\n - drex-max, drex-v2.0 and drex-v1.5 run Nace.AI's Drex, served by DeepInfra, and take at most 16 questions. drex-max reads up to 262k tokens and up to 4 PNG, JPEG, WebP, or GIF images, 9 MiB together. drex-v2.0 and drex-v1.5 read text only, up to 128k tokens. nace-ai/drex-max, nace-ai/drex-v2.0 and nace-ai/drex-v1.5 name the same three.\n - gpt-6-luna-decisions runs OpenAI's Decisions API (in beta), which reads up to 922k tokens and PNG, JPEG, WebP, or GIF images of up to 20 MB each. It takes up to 200 questions, and a choice needs at least 2 options. gpt-6-luna names it too.\n- images is for a model that reads them. Pass URLs or data URLs. A model that reads none refuses the call.\n- The response model field is the version that answered.\n- Billed per input token. Output tokens are free. Each model has its own rate, and GPT-6 Luna Decisions bills a prompt over 272k tokens at twice its rate.",
310
- inputSchema: { "type": "object", "properties": { "state": { "anyOf": [{ "type": "string" }, { "type": "object", "properties": {}, "required": [] }, { "type": "array", "items": {} }] }, "questions": { "type": "object", "properties": {}, "required": [], "description": "Questions to ask about the state, keyed by an id you choose." }, "images": { "type": "array", "items": { "type": "string" }, "description": "Images for a model that reads them (Clef, Clef Flash, GPT-6 Luna Decisions). Each entry is a URL or a data URL. A model that reads none refuses the call." }, "decisionModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": "Decision model: a catalog id, its vendor's name for it (`@cf/cloudflare/clef`, `gpt-6-luna`), or a version it pins (`jev-1.13.0`)" }, "config": { "type": "object", "properties": {}, "required": [], "description": "Additional model-specific configuration" } }, "required": ["model"], "description": "Optional model override. Uses the workspace's default decision model (Jev) if not specified" } }, "required": ["state", "questions"] },
309
+ usageNotes: "- state is the content to judge: a string, or a JSON object or array (a record, a chat log, application state).\n- questions is a map. The key is an id you choose. It is not shown to the model. The answer comes back under the same id.\n- A noul asks a yes/no question and returns noul, a probability from 0 (no) to 1 (yes). Optional criteria.true and criteria.false say what a yes and a no mean.\n- A choice picks one option. criteria is a map of option id to a short description (or null). At most 255 options. The answer includes the winning choice, a probability for every option, and confidence.\n- A score rates the state on an ordered rubric. criteria is 2 to 10 level descriptions, low to high. The answer's score can land between levels, and includes a probability per level plus confidence.\n- An answer of type refusal means the model declined that question (GPT-6 Luna Decisions can).\n- instructions may be a string, or an object that keeps the question in one field and reference data in the others. Refer to those fields by name in backticks.\n- Send every question you need in one call. The model reads the state once and answers them together.\n- Probabilities from different models are not comparable: tune a threshold against the model, and the version, it will run on.\n- decisionModelOverride.model picks the model:\n - jev-latest (the default) is TypeSafe's current stable release, text only, up to 64k tokens. jev-preview tracks TypeSafe's newest release. Pin a version such as jev-1.13.0 when a threshold was tuned against that version.\n - clef and clef-flash run Cloudflare Clef, which also reads up to 4 PNG, JPEG, or WebP images, each at most 4 MiB and 8 MiB together, and takes at most 64 questions, each id using only letters, digits, underscore, dot, and hyphen, up to 100 characters. clef is the larger model, clef-flash the faster one. @cf/cloudflare/clef and @cf/cloudflare/clef-flash name the same two.\n - mercury-decide runs Inception's Mercury Decide, which reads up to 64k tokens and up to 16 PNG, JPEG, WebP, or GIF images, each at most 10 MiB and 14 MiB together.\n - drex-max, drex-v2.0 and drex-v1.5 run Nace.AI's Drex, served by DeepInfra, and take at most 16 questions. drex-max reads up to 262k tokens and up to 4 PNG, JPEG, WebP, or GIF images, 9 MiB together. drex-v2.0 and drex-v1.5 read text only, up to 128k tokens. nace-ai/drex-max, nace-ai/drex-v2.0 and nace-ai/drex-v1.5 name the same three.\n - gpt-6-luna-decisions runs OpenAI's Decisions API (in beta), which reads up to 922k tokens and PNG, JPEG, WebP, or GIF images of up to 20 MB each. It takes up to 200 questions, and a choice needs at least 2 options. gpt-6-luna names it too.\n - gemini-decision-1 runs Google's Gemini Decision 1, which reads up to 262k tokens and PNG, JPEG, WebP, or GIF images, up to 100 MB of image data in one request. It takes 1 to 1,000 questions. A question id uses only letters, digits, underscore, and hyphen, up to 64 characters, and a choice needs 2 to 255 options. A yes/no probability is between 0.01 and 0.99.\n- images is for a model that reads them. Pass URLs or data URLs. A model that reads none refuses the call.\n- The response model field is the version that answered.\n- Billed per input token. Output tokens are free. Each model has its own rate, and GPT-6 Luna Decisions bills a prompt over 272k tokens at twice its rate.",
310
+ inputSchema: { "type": "object", "properties": { "state": { "anyOf": [{ "type": "string" }, { "type": "object", "properties": {}, "required": [] }, { "type": "array", "items": {} }] }, "questions": { "type": "object", "properties": {}, "required": [], "description": "Questions to ask about the state, keyed by an id you choose." }, "images": { "type": "array", "items": { "type": "string" }, "description": "Images for a model that reads them (Clef, Clef Flash, GPT-6 Luna Decisions, Gemini Decision 1). Each entry is a URL or a data URL. A model that reads none refuses the call." }, "decisionModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": "Decision model: a catalog id, its vendor's name for it (`@cf/cloudflare/clef`, `gpt-6-luna`), or a version it pins (`jev-1.13.0`)" }, "config": { "type": "object", "properties": {}, "required": [], "description": "Additional model-specific configuration" } }, "required": ["model"], "description": "Optional model override. Uses the workspace's default decision model (Jev) if not specified" } }, "required": ["state", "questions"] },
311
311
  outputSchema: { "type": "object", "properties": { "model": { "type": "string", "description": "Versioned model id that answered, such as jev-1.13.0." }, "answers": { "type": "object", "properties": {}, "required": [], "description": "One answer per question, under the same ids." }, "usage": { "type": "object", "properties": { "input_tokens": { "type": "number" }, "output_tokens": { "type": "number" } }, "required": ["input_tokens", "output_tokens"], "description": "Token counts for the call. Input tokens are what the model bills." } }, "required": ["model", "answers", "usage"] }
312
312
  },
313
313
  "extractAudioFromVideo": {
@@ -320,7 +320,7 @@ var init_metadata = __esm({
320
320
  "extractText": {
321
321
  stepType: "extractText",
322
322
  description: "Download a file from a URL and extract its text content. Supports PDFs (including scanned/image-based PDFs via OCR), plain text files, and other document formats.",
323
- usageNotes: "- Best suited for PDFs and raw text/document files. For web pages, use the scrapeUrl step instead.\n- Handles both text-layer PDFs and image-based/scanned PDFs (e.g. Figma/Canva exports, scanned documents). Image-based PDFs are processed with OCR automatically \u2014 there is no need to convert PDF pages to images first.\n- Plain text, code, HTML, spreadsheets and Office documents (docx, pptx, odt, rtf, epub) are read without a model and cost nothing. PDFs and images go to the extraction model, billed per page.\n- Accepts a single URL, a comma-separated list of URLs, or a JSON array of URLs.\n- Nothing is published. One of the app's own files \u2014 including a private one, or a share link \u2014 is read where it sits; any other URL is downloaded and staged privately for the extraction model, then discarded when extraction finishes.\n- `text` is each document's text: a string for one URL, an array for several. `documents` has each document page by page, with its page numbers and the pages billed. Set `includeBlocks` to add each page's typed blocks (title, text, table, image, header, footer\u2026) with their bounding boxes, and the page's size.\n- A file that can't be read (unreachable, an unsupported type, past the model's limits, or refused by the model) fails the step with the reason.\n- `extractionModelOverride.model` picks the model; omit it to use the workspace's default:\n - `mistral-ocr-4.1` (the default): PDFs and images up to 50 MB and 1,000 pages, with typed blocks.\n - `mistral-document-ai-2512`: Mistral Document AI on Microsoft Foundry, up to 30 MB and 30 pages, with typed blocks.\n - `llamaparse`: LlamaParse's agentic mode, up to 100 MB and 1,000 pages, markdown without blocks.\n - `google-document-ai`: Google Document AI OCR, up to 500 pages, where the deployment has set it up.\n- Maximum file size is 50MB per URL.",
323
+ usageNotes: "- Best suited for PDFs and raw text/document files. For web pages, use the scrapeUrl step instead.\n- Handles both text-layer PDFs and image-based/scanned PDFs (e.g. Figma/Canva exports, scanned documents). Image-based PDFs are processed with OCR automatically \u2014 there is no need to convert PDF pages to images first.\n- Plain text, code, HTML, spreadsheets and Office documents (docx, pptx, odt, rtf, epub) are read without a model and cost nothing. PDFs and images go to the extraction model, billed per page.\n- Accepts a single URL, a comma-separated list of URLs, or a JSON array of URLs.\n- Nothing is published. One of the app's own files \u2014 including a private one, or a share link \u2014 is read where it sits; any other URL is downloaded and staged privately for the extraction model, then discarded when extraction finishes.\n- `text` is each document's text: a string for one URL, an array for several. `documents` has each document page by page, with its page numbers and the pages billed. Set `includeBlocks` to add each page's typed blocks (title, text, table, image, header, footer\u2026) with their bounding boxes, and the page's size.\n- A file that can't be read (unreachable, an unsupported type, past the model's limits, or refused by the model) fails the step with the reason.\n- `extractionModelOverride.model` picks the model; omit it to use the workspace's default:\n - `mistral-ocr-4.1` (the default): PDFs and images up to 50 MB and 1,000 pages, with typed blocks.\n - `mistral-document-ai-2512`: Mistral Document AI on Microsoft Foundry, up to 30 MB and 30 pages, with typed blocks.\n - `llamaparse`: LlamaParse's agentic mode, up to 100 MB and 1,000 pages, markdown without blocks.\n - `google-document-ai`: Google Document AI OCR, up to 500 pages, where the deployment has set it up.\n- A URL that isn't one of the app's own files is downloaded first, and can be at most 50 MB. One of the app's own files is read where it sits: up to the model's limit when a model reads it (a PDF, an image), and up to 50 MB for a kind read without a model (text, HTML, spreadsheets and office documents).",
324
324
  inputSchema: { "type": "object", "properties": { "url": { "anyOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] }, "extractionModelOverride": { "type": "object", "properties": { "model": { "type": "string", "description": "Document extraction model identifier" }, "config": { "type": "object", "properties": {}, "required": [], "description": "Additional model-specific configuration" } }, "required": ["model"], "description": "Optional model override. Uses the workspace's default document extraction model if not specified" }, "model": { "type": "string", "description": "Optional extraction model id." }, "includeBlocks": { "type": "boolean", "description": "Add each page's typed blocks, with their bounding boxes, and the page's size to `documents`. Off by default, since they're several times the size of the text." } }, "required": ["url"] },
325
325
  outputSchema: { "type": "object", "properties": { "text": { "anyOf": [{ "type": "string" }, { "type": "array", "items": { "type": "string" } }] }, "documents": { "type": "array", "items": { "type": "object", "properties": { "url": { "type": "string", "description": "The URL the document was read from." }, "text": { "type": "string", "description": "The whole document's text." }, "pages": { "type": "array", "items": { "type": "object", "properties": { "pageNumber": { "type": "number", "description": "1-based." }, "markdown": { "type": "string", "description": "The page's text, as markdown." }, "blocks": { "type": "array", "items": { "type": "string" }, "description": "The page's typed regions (title, text, table, image, header, footer\u2026), each with its bounding box, when `includeBlocks` was set and the model returns them." }, "dimensions": { "type": "object", "properties": { "width": { "type": "number" }, "height": { "type": "number" }, "dpi": { "type": "number" } }, "required": ["width", "height"], "description": "The page's size in pixels, the space `blocks`' bounding boxes are in." } }, "required": ["pageNumber", "markdown"], "description": "One page of an extracted document." }, "description": "Its pages, in order. A format read without a model is one page." }, "pagesProcessed": { "type": "number", "description": "The pages the model read and billed, 0 for a format read without one." } }, "required": ["url", "text", "pages", "pagesProcessed"] }, "description": "Each URL's document, in the order given, page by page." } }, "required": ["text", "documents"] }
326
326
  },
@@ -1096,7 +1096,7 @@ var init_metadata = __esm({
1096
1096
  stepType: "typesafeEvaluate",
1097
1097
  description: "Use evaluateDecision: the same questions, answers and models, with decisionModelOverride in place of model. evaluateDecision's earlier name, which still runs: ask structured questions about text, JSON, or images and get calibrated answers from a decision model.",
1098
1098
  usageNotes: "- Runs exactly as evaluateDecision does, with the same questions, answers, models and limits (see its notes), and model in place of decisionModelOverride.model.",
1099
- inputSchema: { "type": "object", "properties": { "state": { "anyOf": [{ "type": "string" }, { "type": "object", "properties": {}, "required": [] }, { "type": "array", "items": {} }] }, "questions": { "type": "object", "properties": {}, "required": [], "description": "Questions to ask about the state, keyed by an id you choose." }, "model": { "type": "string", "description": "Model id or alias. Defaults to the workspace's default decision model (jev-latest). Every model evaluateDecision takes: jev-preview, a pinned version such as jev-1.13.0, clef and clef-flash, gpt-6-luna-decisions." }, "images": { "type": "array", "items": { "type": "string" }, "description": "Images for a model that reads them (Clef, Clef Flash, GPT-6 Luna Decisions). Each entry is a URL or a data URL. A model that reads none refuses the call." } }, "required": ["state", "questions"] },
1099
+ inputSchema: { "type": "object", "properties": { "state": { "anyOf": [{ "type": "string" }, { "type": "object", "properties": {}, "required": [] }, { "type": "array", "items": {} }] }, "questions": { "type": "object", "properties": {}, "required": [], "description": "Questions to ask about the state, keyed by an id you choose." }, "model": { "type": "string", "description": "Model id or alias. Defaults to the workspace's default decision model (jev-latest). Every model evaluateDecision takes: jev-preview, a pinned version such as jev-1.13.0, clef and clef-flash, gpt-6-luna-decisions, gemini-decision-1." }, "images": { "type": "array", "items": { "type": "string" }, "description": "Images for a model that reads them (Clef, Clef Flash, GPT-6 Luna Decisions, Gemini Decision 1). Each entry is a URL or a data URL. A model that reads none refuses the call." } }, "required": ["state", "questions"] },
1100
1100
  outputSchema: { "type": "object", "properties": { "model": { "type": "string", "description": "Versioned model id that answered, such as jev-1.13.0." }, "answers": { "type": "object", "properties": {}, "required": [], "description": "One answer per question, under the same ids." }, "usage": { "type": "object", "properties": { "input_tokens": { "type": "number" }, "output_tokens": { "type": "number" } }, "required": ["input_tokens", "output_tokens"], "description": "Token counts for the call. Input tokens are what the model bills." } }, "required": ["model", "answers", "usage"] }
1101
1101
  },
1102
1102
  "updateGmailLabels": {
@@ -5108,12 +5108,46 @@ var init_files = __esm({
5108
5108
  }
5109
5109
  });
5110
5110
 
5111
+ // src/datasources/parts.ts
5112
+ import { gzipSync } from "node:zlib";
5113
+ async function storePart(grant, lines) {
5114
+ const form = new FormData();
5115
+ for (const [k, v] of Object.entries(grant.uploadFields)) {
5116
+ form.append(k, v);
5117
+ }
5118
+ form.append(
5119
+ "file",
5120
+ new Blob([new Uint8Array(gzipSync(Buffer.from(lines.join("\n") + "\n")))], {
5121
+ type: "application/gzip"
5122
+ }),
5123
+ `${grant.part}.ndjson.gz`
5124
+ );
5125
+ const response = await fetch(grant.uploadUrl, {
5126
+ method: "POST",
5127
+ body: form
5128
+ });
5129
+ if (!response.ok) {
5130
+ throw new Error(
5131
+ `Could not store part ${grant.part} of the documents: HTTP ${response.status}`
5132
+ );
5133
+ }
5134
+ }
5135
+ var PART_DOCUMENTS, PART_BYTES;
5136
+ var init_parts = __esm({
5137
+ "src/datasources/parts.ts"() {
5138
+ "use strict";
5139
+ PART_DOCUMENTS = 1e3;
5140
+ PART_BYTES = 8 * 1024 * 1024;
5141
+ }
5142
+ });
5143
+
5111
5144
  // src/datasources/source.ts
5112
5145
  import { createHash as createHash2 } from "node:crypto";
5113
5146
  var DICTIONARY_PAGE_ENTRIES, DICTIONARY_PAGE_BYTES, REMOVE_WHERE_MAX_PAGES, DataSource;
5114
5147
  var init_source = __esm({
5115
5148
  "src/datasources/source.ts"() {
5116
5149
  "use strict";
5150
+ init_parts();
5117
5151
  DICTIONARY_PAGE_ENTRIES = 1e4;
5118
5152
  DICTIONARY_PAGE_BYTES = 4e6;
5119
5153
  REMOVE_WHERE_MAX_PAGES = 100;
@@ -5415,6 +5449,87 @@ var init_source = __esm({
5415
5449
  body: bytes.toString("base64")
5416
5450
  });
5417
5451
  }
5452
+ /**
5453
+ * Add many documents at once, built as one job.
5454
+ *
5455
+ * For records your app renders to text: a row of its own table as a short
5456
+ * markdown card, in any number. Each is what a mapper's `documents()`
5457
+ * returns (an `externalId`, a `title`, `markdown`, and optionally
5458
+ * `metadata`, `entities` and `replaces`), given as an array or any iterable
5459
+ * or async iterable, so a generator that yields a document per row never
5460
+ * holds them all. {@link add} is for a file.
5461
+ *
5462
+ * ```ts
5463
+ * const { job } = await Claims.addMany(
5464
+ * claims.map((claim) => ({
5465
+ * externalId: claim.id,
5466
+ * title: claim.title,
5467
+ * markdown: renderCard(claim),
5468
+ * metadata: { firmId: claim.firmId, status: claim.status },
5469
+ * })),
5470
+ * );
5471
+ * ```
5472
+ *
5473
+ * The documents are stored a thousand at a time and one job registers and
5474
+ * builds them, planned and priced like any other; it starts on its own
5475
+ * within `budgetDollars`, or within its plan's projection with headroom when
5476
+ * none is given. The call returns once the job has started: follow it with
5477
+ * {@link job}, and a search sees what has been built throughout.
5478
+ *
5479
+ * The external id is a document's identity. Giving one the source already
5480
+ * holds supersedes that document once the job's documents are all
5481
+ * searchable; unchanged markdown builds nothing, and new metadata or
5482
+ * entities on unchanged markdown update in place. A document that fails
5483
+ * validation is left out and counted on the job; the rest go in. Nothing is
5484
+ * removed for being left out of a later call: use {@link remove} or
5485
+ * {@link removeWhere}.
5486
+ *
5487
+ * @throws `data_source_mapped` on a source with a mapper, which is what
5488
+ * makes that source's documents; `data_source_busy` while another job or
5489
+ * a move is in flight, since a source runs one job at a time.
5490
+ */
5491
+ async addMany(documents, options) {
5492
+ const { uploadId } = await this._call("add-many/open", {
5493
+ slug: this._slug
5494
+ });
5495
+ const parts = [];
5496
+ let lines = [];
5497
+ let bytes = 0;
5498
+ let documentCount = 0;
5499
+ const storeLines = async () => {
5500
+ if (lines.length === 0) {
5501
+ return;
5502
+ }
5503
+ const grant = await this._call("add-many/part", {
5504
+ slug: this._slug,
5505
+ uploadId
5506
+ });
5507
+ await storePart(grant, lines);
5508
+ parts.push({ part: grant.part, count: lines.length });
5509
+ lines = [];
5510
+ bytes = 0;
5511
+ };
5512
+ for await (const d of documents) {
5513
+ const line = JSON.stringify({ o: 0, i: documentCount, d });
5514
+ lines.push(line);
5515
+ bytes += line.length;
5516
+ documentCount += 1;
5517
+ if (lines.length >= PART_DOCUMENTS || bytes >= PART_BYTES) {
5518
+ await storeLines();
5519
+ }
5520
+ }
5521
+ await storeLines();
5522
+ if (parts.length === 0) {
5523
+ return { documentCount: 0, job: null };
5524
+ }
5525
+ const { job } = await this._call("add-many/start", {
5526
+ slug: this._slug,
5527
+ uploadId,
5528
+ parts,
5529
+ ...options?.budgetDollars !== void 0 ? { budgetDollars: options.budgetDollars } : {}
5530
+ });
5531
+ return { documentCount, job };
5532
+ }
5418
5533
  /**
5419
5534
  * Documents in the corpus, with ingest status.
5420
5535
  *
@@ -10143,7 +10258,7 @@ async function startMcpServer(options) {
10143
10258
  capabilities: { tools: {} },
10144
10259
  serverInfo: {
10145
10260
  name: "mindstudio-agent",
10146
- version: "0.1.182"
10261
+ version: "0.1.184"
10147
10262
  },
10148
10263
  instructions: 'Welcome to MindStudio \u2014 a platform with 200+ AI models, 850+ third-party integrations, and pre-built agents.\n\nGetting started:\n1. Call `ask` with any question about the SDK \u2014 it knows every action, model, and connector and returns working code with real model IDs and config options. Examples: ask("generate an image with FLUX"), ask("what models support vision?"), ask("how do I send a Slack message?").\n2. Call `changeName` to set your display name \u2014 use your name or whatever your user calls you. This is how you\'ll appear in MindStudio request logs.\n3. If you have a profile picture, pass its public image URL to `changeProfilePicture`.\n4. For manual browsing, call `listActions` to discover all available actions.\n\nThen use the tools to generate text, images, video, audio, search the web, work with data sources, run agents, and more.\n\nImportant:\n- AI-powered actions (text generation, image generation, video, audio, etc.) cost money. Before running these, call `estimateActionCost` and confirm with the user before proceeding \u2014 unless they\'ve explicitly told you to go ahead.\n- Not all agents from `listAgents` are configured for API use. Do not try to run an agent just because it appears in the list \u2014 it will likely fail. Only run agents the user specifically asks you to run.'
10149
10264
  });
@@ -11183,7 +11298,7 @@ function isNewerVersion(current, latest) {
11183
11298
  return false;
11184
11299
  }
11185
11300
  async function checkForUpdate() {
11186
- const currentVersion = "0.1.182";
11301
+ const currentVersion = "0.1.184";
11187
11302
  if (!currentVersion || process.env.MINDSTUDIO_NO_UPDATE_CHECK) {
11188
11303
  return null;
11189
11304
  }
@@ -11218,7 +11333,7 @@ async function checkForUpdate() {
11218
11333
  }
11219
11334
  }
11220
11335
  function printUpdateNotice(latestVersion) {
11221
- const currentVersion = "0.1.182";
11336
+ const currentVersion = "0.1.184";
11222
11337
  process.stderr.write(
11223
11338
  `
11224
11339
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -11231,7 +11346,7 @@ function isStandaloneBinary() {
11231
11346
  return !argv1.includes("node_modules");
11232
11347
  }
11233
11348
  async function cmdUpdate() {
11234
- const currentVersion = "0.1.182";
11349
+ const currentVersion = "0.1.184";
11235
11350
  process.stderr.write(
11236
11351
  ` ${ansi2.gray("Current version:")} ${currentVersion}
11237
11352
  `
@@ -11372,7 +11487,7 @@ async function cmdLogin(options) {
11372
11487
  process.stderr.write("\n");
11373
11488
  printLogo();
11374
11489
  process.stderr.write("\n");
11375
- const ver = "0.1.182";
11490
+ const ver = "0.1.184";
11376
11491
  process.stderr.write(
11377
11492
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
11378
11493
  `
@@ -11407,7 +11522,7 @@ async function cmdLogin(options) {
11407
11522
  `Failed to request auth URL: ${authRes.status} ${authRes.statusText}`
11408
11523
  );
11409
11524
  }
11410
- const { url, token } = await authRes.json();
11525
+ const { url, token, expiresInSeconds } = await authRes.json();
11411
11526
  openBrowser(url);
11412
11527
  process.stderr.write(
11413
11528
  ` ${ansi2.cyanBright("Opening browser to authenticate...")}
@@ -11418,7 +11533,9 @@ async function cmdLogin(options) {
11418
11533
  `
11419
11534
  );
11420
11535
  const POLL_INTERVAL = 2e3;
11421
- const MAX_ATTEMPTS = 60;
11536
+ const MAX_ATTEMPTS = Math.ceil(
11537
+ (expiresInSeconds ?? 120) * 1e3 / POLL_INTERVAL
11538
+ );
11422
11539
  for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
11423
11540
  await sleep5(POLL_INTERVAL);
11424
11541
  const frame = SPINNER_FRAMES[attempt % SPINNER_FRAMES.length];
@@ -11700,7 +11817,7 @@ async function main() {
11700
11817
  const updatePromise = command !== "mcp" && command !== "login" && command !== "update" ? checkForUpdate() : Promise.resolve(null);
11701
11818
  try {
11702
11819
  if (command === "version" || command === "-v") {
11703
- process.stdout.write("0.1.182\n");
11820
+ process.stdout.write("0.1.184\n");
11704
11821
  return;
11705
11822
  }
11706
11823
  if (command === "login") {
@@ -31,7 +31,7 @@
31
31
  */
32
32
  import { DataSource, type DataSourcesTransport } from './source.js';
33
33
  export { DataSource } from './source.js';
34
- export type { AddOptions, AddResult, BranchPosition, Citation, DataSourceChunk, DataSourceDocument, DataSourceJob, DataSourceJobPlan, DataSourceJobState, DataSourcePassage, DataSourcePassagePage, DataSourceStats, DictionaryEntry, DictionaryPushResult, DictionaryRelink, DictionaryReport, DocumentMetadata, DocumentSelector, MetadataRange, MetadataValue, SearchExplain, SearchFilter, SearchHit, SearchMode, SearchOptions, SearchRan, } from './source.js';
34
+ export type { AddManyResult, AddOptions, AddResult, BranchPosition, Citation, DataSourceChunk, DataSourceDocument, DataSourceJob, DataSourceJobPlan, DataSourceJobState, DataSourcePassage, DataSourcePassagePage, DataSourceStats, DictionaryEntry, DictionaryPushResult, DictionaryRelink, DictionaryReport, DocumentMetadata, DocumentSelector, MetadataRange, MetadataValue, SearchExplain, SearchFilter, SearchHit, SearchMode, SearchOptions, SearchRan, } from './source.js';
35
35
  /** The `dataSources` namespace object. */
36
36
  export interface DataSources {
37
37
  /**
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A part: what the platform registers in one batch (its own `PART_DOCUMENTS`,
3
+ * the api's customerApps/AppDataSources/mapSpill.ts).
4
+ */
5
+ export declare const PART_DOCUMENTS = 1000;
6
+ export declare const PART_BYTES: number;
7
+ /** A grant to store the next part. */
8
+ export interface PartGrant {
9
+ part: number;
10
+ uploadUrl: string;
11
+ uploadFields: Record<string, string>;
12
+ }
13
+ /** Store one part's lines under its grant. Throws when storage refuses them. */
14
+ export declare function storePart(grant: PartGrant, lines: string[]): Promise<void>;
@@ -1,3 +1,4 @@
1
+ import type { MappedDocument } from '../mapper/index.js';
1
2
  /** @internal Transport: `POST /_internal/v2/datasources/<op>` with the hook token. */
2
3
  export type DataSourcesTransport = (op: string, body: unknown) => Promise<any>;
3
4
  /** Where a retrieved chunk came from — enough to show the user the source. */
@@ -385,6 +386,19 @@ export interface AddResult {
385
386
  */
386
387
  job: DataSourceJob | null;
387
388
  }
389
+ /** What {@link DataSource.addMany} returns. */
390
+ export interface AddManyResult {
391
+ /** How many documents were given. */
392
+ documentCount: number;
393
+ /**
394
+ * The job registering and building them; null only when none were given.
395
+ * It plans and starts on its own (within `budgetDollars`); follow it with
396
+ * {@link DataSource.job}. A document whose external id the source already
397
+ * holds is superseded when the job finishes, once every document of the
398
+ * call is searchable.
399
+ */
400
+ job: DataSourceJob | null;
401
+ }
388
402
  export interface DataSourceDocument {
389
403
  id: string;
390
404
  filename: string | null;
@@ -543,8 +557,9 @@ export interface DataSourceJobPlan {
543
557
  /**
544
558
  * A bulk ingestion job — a sync, a corpus load started from the CLI, a remap
545
559
  * of a mapped source's raw copies, a replay of an earlier job's quarantine, a
546
- * reread of the source's documents by its reader, or the rest of one large
547
- * object an {@link DataSource.add} took.
560
+ * reread of the source's documents by its reader, the rest of one large
561
+ * object an {@link DataSource.add} took, or the documents a
562
+ * {@link DataSource.addMany} gave.
548
563
  */
549
564
  export interface DataSourceJob {
550
565
  id: string;
@@ -576,6 +591,9 @@ export interface DataSourceJob {
576
591
  } | {
577
592
  type: 'object';
578
593
  ref: string;
594
+ } | {
595
+ type: 'documents';
596
+ documents: number;
579
597
  };
580
598
  /**
581
599
  * Objects the mapper skipped or failed on, and documents the reader failed
@@ -907,6 +925,49 @@ export declare class DataSource {
907
925
  * the source refuses it with `data_source_busy`.
908
926
  */
909
927
  add(content: Buffer | Uint8Array | string, options: AddOptions): Promise<AddResult>;
928
+ /**
929
+ * Add many documents at once, built as one job.
930
+ *
931
+ * For records your app renders to text: a row of its own table as a short
932
+ * markdown card, in any number. Each is what a mapper's `documents()`
933
+ * returns (an `externalId`, a `title`, `markdown`, and optionally
934
+ * `metadata`, `entities` and `replaces`), given as an array or any iterable
935
+ * or async iterable, so a generator that yields a document per row never
936
+ * holds them all. {@link add} is for a file.
937
+ *
938
+ * ```ts
939
+ * const { job } = await Claims.addMany(
940
+ * claims.map((claim) => ({
941
+ * externalId: claim.id,
942
+ * title: claim.title,
943
+ * markdown: renderCard(claim),
944
+ * metadata: { firmId: claim.firmId, status: claim.status },
945
+ * })),
946
+ * );
947
+ * ```
948
+ *
949
+ * The documents are stored a thousand at a time and one job registers and
950
+ * builds them, planned and priced like any other; it starts on its own
951
+ * within `budgetDollars`, or within its plan's projection with headroom when
952
+ * none is given. The call returns once the job has started: follow it with
953
+ * {@link job}, and a search sees what has been built throughout.
954
+ *
955
+ * The external id is a document's identity. Giving one the source already
956
+ * holds supersedes that document once the job's documents are all
957
+ * searchable; unchanged markdown builds nothing, and new metadata or
958
+ * entities on unchanged markdown update in place. A document that fails
959
+ * validation is left out and counted on the job; the rest go in. Nothing is
960
+ * removed for being left out of a later call: use {@link remove} or
961
+ * {@link removeWhere}.
962
+ *
963
+ * @throws `data_source_mapped` on a source with a mapper, which is what
964
+ * makes that source's documents; `data_source_busy` while another job or
965
+ * a move is in flight, since a source runs one job at a time.
966
+ */
967
+ addMany(documents: Iterable<MappedDocument> | AsyncIterable<MappedDocument>, options?: {
968
+ /** The job's ceiling, in dollars: it pauses there, and a plan projected over it waits for an approval. */
969
+ budgetDollars?: number;
970
+ }): Promise<AddManyResult>;
910
971
  /**
911
972
  * Documents in the corpus, with ingest status.
912
973
  *
@@ -644,6 +644,7 @@ export interface StepMethods {
644
644
  * - mercury-decide runs Inception's Mercury Decide, which reads up to 64k tokens and up to 16 PNG, JPEG, WebP, or GIF images, each at most 10 MiB and 14 MiB together.
645
645
  * - drex-max, drex-v2.0 and drex-v1.5 run Nace.AI's Drex, served by DeepInfra, and take at most 16 questions. drex-max reads up to 262k tokens and up to 4 PNG, JPEG, WebP, or GIF images, 9 MiB together. drex-v2.0 and drex-v1.5 read text only, up to 128k tokens. nace-ai/drex-max, nace-ai/drex-v2.0 and nace-ai/drex-v1.5 name the same three.
646
646
  * - gpt-6-luna-decisions runs OpenAI's Decisions API (in beta), which reads up to 922k tokens and PNG, JPEG, WebP, or GIF images of up to 20 MB each. It takes up to 200 questions, and a choice needs at least 2 options. gpt-6-luna names it too.
647
+ * - gemini-decision-1 runs Google's Gemini Decision 1, which reads up to 262k tokens and PNG, JPEG, WebP, or GIF images, up to 100 MB of image data in one request. It takes 1 to 1,000 questions. A question id uses only letters, digits, underscore, and hyphen, up to 64 characters, and a choice needs 2 to 255 options. A yes/no probability is between 0.01 and 0.99.
647
648
  * - images is for a model that reads them. Pass URLs or data URLs. A model that reads none refuses the call.
648
649
  * - The response model field is the version that answered.
649
650
  * - Billed per input token. Output tokens are free. Each model has its own rate, and GPT-6 Luna Decisions bills a prompt over 272k tokens at twice its rate.
@@ -684,7 +685,7 @@ export interface StepMethods {
684
685
  * - `mistral-document-ai-2512`: Mistral Document AI on Microsoft Foundry, up to 30 MB and 30 pages, with typed blocks.
685
686
  * - `llamaparse`: LlamaParse's agentic mode, up to 100 MB and 1,000 pages, markdown without blocks.
686
687
  * - `google-document-ai`: Google Document AI OCR, up to 500 pages, where the deployment has set it up.
687
- * - Maximum file size is 50MB per URL.
688
+ * - A URL that isn't one of the app's own files is downloaded first, and can be at most 50 MB. One of the app's own files is read where it sits: up to the model's limit when a model reads it (a PDF, an image), and up to 50 MB for a kind read without a model (text, HTML, spreadsheets and office documents).
688
689
  *
689
690
  * @example
690
691
  * ```typescript
@@ -755,7 +755,7 @@ export interface EvaluateDecisionStepInput {
755
755
  /** Ordered level descriptions, from low to high. At least 2, at most 10. */
756
756
  criteria: string[];
757
757
  }>;
758
- /** Images for a model that reads them (Clef, Clef Flash, GPT-6 Luna Decisions). Each entry is a URL or a data URL. A model that reads none refuses the call. */
758
+ /** Images for a model that reads them (Clef, Clef Flash, GPT-6 Luna Decisions, Gemini Decision 1). Each entry is a URL or a data URL. A model that reads none refuses the call. */
759
759
  images?: string[];
760
760
  /** Optional model override. Uses the workspace's default decision model (Jev) if not specified */
761
761
  decisionModelOverride?: {
@@ -3793,9 +3793,9 @@ export interface TypesafeEvaluateStepInput {
3793
3793
  /** Ordered level descriptions, from low to high. At least 2, at most 10. */
3794
3794
  criteria: string[];
3795
3795
  }>;
3796
- /** Model id or alias. Defaults to the workspace's default decision model (jev-latest). Every model evaluateDecision takes: jev-preview, a pinned version such as jev-1.13.0, clef and clef-flash, gpt-6-luna-decisions. */
3796
+ /** Model id or alias. Defaults to the workspace's default decision model (jev-latest). Every model evaluateDecision takes: jev-preview, a pinned version such as jev-1.13.0, clef and clef-flash, gpt-6-luna-decisions, gemini-decision-1. */
3797
3797
  model?: string;
3798
- /** Images for a model that reads them (Clef, Clef Flash, GPT-6 Luna Decisions). Each entry is a URL or a data URL. A model that reads none refuses the call. */
3798
+ /** Images for a model that reads them (Clef, Clef Flash, GPT-6 Luna Decisions, Gemini Decision 1). Each entry is a URL or a data URL. A model that reads none refuses the call. */
3799
3799
  images?: string[];
3800
3800
  }
3801
3801
  export interface TypesafeEvaluateStepOutput {