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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = true ? "1.9.2" : "dev";
2
+ var SDK_VERSION = true ? "1.9.4" : "dev";
3
3
  var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
4
4
 
5
5
  // src/version-check.ts
@@ -5345,32 +5345,75 @@ var RemoteFileStorage = class _RemoteFileStorage {
5345
5345
  };
5346
5346
 
5347
5347
  // src/anything.ts
5348
+ async function* readAnythingStream(body) {
5349
+ const reader = body.getReader();
5350
+ const decoder = new TextDecoder();
5351
+ let buffer = "";
5352
+ try {
5353
+ while (true) {
5354
+ const { value, done } = await reader.read();
5355
+ buffer += decoder.decode(value, { stream: !done });
5356
+ let end;
5357
+ while ((end = buffer.indexOf("\n")) !== -1) {
5358
+ const line = buffer.slice(0, end).replace(/\r$/, "");
5359
+ buffer = buffer.slice(end + 1);
5360
+ if (!line.startsWith("data:")) continue;
5361
+ const payload = line.slice(5).replace(/^ /, "");
5362
+ if (payload === "[DONE]") return;
5363
+ try {
5364
+ yield JSON.parse(payload);
5365
+ } catch (error) {
5366
+ throw new NotteError(`Malformed Anything stream event: ${payload}`, { cause: error });
5367
+ }
5368
+ }
5369
+ if (done) break;
5370
+ }
5371
+ } finally {
5372
+ await reader.cancel().catch(() => {
5373
+ });
5374
+ reader.releaseLock();
5375
+ }
5376
+ }
5348
5377
  var NotteAnything = class {
5349
5378
  client;
5350
5379
  constructor(client2) {
5351
5380
  this.client = client2;
5352
5381
  }
5353
5382
  /**
5354
- * Start building a function for `task`. Building is slow (minutes) and
5355
- * billable; prefer the marketplace (`client.functions.list()`) when a
5356
- * ready-made function already fits.
5383
+ * Start a run for `task` and stream the agent's progress back.
5384
+ *
5385
+ * Running is slow (minutes) and billable; prefer the marketplace
5386
+ * (`client.functions.list()`) when a ready-made function already fits.
5387
+ *
5388
+ * The returned `chunks` generator holds the connection open — iterate it to
5389
+ * completion, or `return`/`break` out of the loop to cancel and release the
5390
+ * stream.
5357
5391
  *
5358
5392
  * ```ts
5359
- * const result = await client.anything.start({ task: 'get the weather in Paris' });
5360
- * if (typeof result.function_id === 'string') {
5361
- * const fn = client.NotteFunction({ function_id: result.function_id });
5393
+ * const run = await client.anything.start({ task: 'get the weather in Paris' });
5394
+ * for await (const chunk of run.chunks) {
5395
+ * if (chunk.type === 'text-delta') process.stdout.write(String(chunk.delta ?? ''));
5362
5396
  * }
5363
5397
  * ```
5364
5398
  *
5365
5399
  * Rejects with a `NotteAPIError` when the API answers with a non-2xx status.
5366
5400
  */
5367
5401
  async start(body) {
5368
- const response = await anythingStart({
5402
+ const { data, response } = await anythingStart({
5369
5403
  client: this.client.getClient(),
5370
5404
  body,
5405
+ parseAs: "stream",
5371
5406
  throwOnError: true
5372
5407
  });
5373
- return response.data ?? {};
5408
+ const stream = data;
5409
+ if (!stream) {
5410
+ throw new NotteError("Anything start returned no response stream");
5411
+ }
5412
+ return {
5413
+ threadId: response.headers.get("x-thread-id"),
5414
+ uiMessageStreamVersion: response.headers.get("x-vercel-ai-ui-message-stream"),
5415
+ chunks: readAnythingStream(stream)
5416
+ };
5374
5417
  }
5375
5418
  };
5376
5419