notte-sdk 1.9.2 → 1.9.4

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.js CHANGED
@@ -195,7 +195,7 @@ __export(index_exports, {
195
195
  module.exports = __toCommonJS(index_exports);
196
196
 
197
197
  // src/version.ts
198
- var SDK_VERSION = true ? "1.9.2" : "dev";
198
+ var SDK_VERSION = true ? "1.9.4" : "dev";
199
199
  var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
200
200
 
201
201
  // src/version-check.ts
@@ -5541,32 +5541,75 @@ var RemoteFileStorage = class _RemoteFileStorage {
5541
5541
  };
5542
5542
 
5543
5543
  // src/anything.ts
5544
+ async function* readAnythingStream(body) {
5545
+ const reader = body.getReader();
5546
+ const decoder = new TextDecoder();
5547
+ let buffer = "";
5548
+ try {
5549
+ while (true) {
5550
+ const { value, done } = await reader.read();
5551
+ buffer += decoder.decode(value, { stream: !done });
5552
+ let end;
5553
+ while ((end = buffer.indexOf("\n")) !== -1) {
5554
+ const line = buffer.slice(0, end).replace(/\r$/, "");
5555
+ buffer = buffer.slice(end + 1);
5556
+ if (!line.startsWith("data:")) continue;
5557
+ const payload = line.slice(5).replace(/^ /, "");
5558
+ if (payload === "[DONE]") return;
5559
+ try {
5560
+ yield JSON.parse(payload);
5561
+ } catch (error) {
5562
+ throw new NotteError(`Malformed Anything stream event: ${payload}`, { cause: error });
5563
+ }
5564
+ }
5565
+ if (done) break;
5566
+ }
5567
+ } finally {
5568
+ await reader.cancel().catch(() => {
5569
+ });
5570
+ reader.releaseLock();
5571
+ }
5572
+ }
5544
5573
  var NotteAnything = class {
5545
5574
  client;
5546
5575
  constructor(client2) {
5547
5576
  this.client = client2;
5548
5577
  }
5549
5578
  /**
5550
- * Start building a function for `task`. Building is slow (minutes) and
5551
- * billable; prefer the marketplace (`client.functions.list()`) when a
5552
- * ready-made function already fits.
5579
+ * Start a run for `task` and stream the agent's progress back.
5580
+ *
5581
+ * Running is slow (minutes) and billable; prefer the marketplace
5582
+ * (`client.functions.list()`) when a ready-made function already fits.
5583
+ *
5584
+ * The returned `chunks` generator holds the connection open — iterate it to
5585
+ * completion, or `return`/`break` out of the loop to cancel and release the
5586
+ * stream.
5553
5587
  *
5554
5588
  * ```ts
5555
- * const result = await client.anything.start({ task: 'get the weather in Paris' });
5556
- * if (typeof result.function_id === 'string') {
5557
- * const fn = client.NotteFunction({ function_id: result.function_id });
5589
+ * const run = await client.anything.start({ task: 'get the weather in Paris' });
5590
+ * for await (const chunk of run.chunks) {
5591
+ * if (chunk.type === 'text-delta') process.stdout.write(String(chunk.delta ?? ''));
5558
5592
  * }
5559
5593
  * ```
5560
5594
  *
5561
5595
  * Rejects with a `NotteAPIError` when the API answers with a non-2xx status.
5562
5596
  */
5563
5597
  async start(body) {
5564
- const response = await anythingStart({
5598
+ const { data, response } = await anythingStart({
5565
5599
  client: this.client.getClient(),
5566
5600
  body,
5601
+ parseAs: "stream",
5567
5602
  throwOnError: true
5568
5603
  });
5569
- return response.data ?? {};
5604
+ const stream = data;
5605
+ if (!stream) {
5606
+ throw new NotteError("Anything start returned no response stream");
5607
+ }
5608
+ return {
5609
+ threadId: response.headers.get("x-thread-id"),
5610
+ uiMessageStreamVersion: response.headers.get("x-vercel-ai-ui-message-stream"),
5611
+ chunks: readAnythingStream(stream)
5612
+ };
5570
5613
  }
5571
5614
  };
5572
5615