notte-sdk 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -185,6 +185,28 @@ await notte.Session().use(async (session) => {
185
185
  - `getId()` - Get agent ID
186
186
  - `isRunning()` - Check if agent is running
187
187
 
188
+ #### Structured answers with Zod
189
+
190
+ Both `agent.start()` and `agent.run()` accept a Zod schema as `response_format`.
191
+ The SDK converts it to JSON Schema before calling the API. On `run()`, the final
192
+ `answer` is validated against the schema and typed accordingly.
193
+
194
+ ```typescript
195
+ import { z } from 'zod';
196
+
197
+ const Answer = z.object({ title: z.string(), summary: z.string() });
198
+
199
+ await notte.Session().use(async (session) => {
200
+ const agent = notte.Agent({ session, max_steps: 5 });
201
+ const result = await agent.run({
202
+ task: 'Go to notte.cc and return the page title and summary',
203
+ response_format: Answer,
204
+ });
205
+ // result.answer is typed as { title: string; summary: string } and validated
206
+ console.log(result.answer.title);
207
+ });
208
+ ```
209
+
188
210
  ### Secret Vaults
189
211
 
190
212
  Manage credentials securely with enterprise-grade encryption.
package/dist/index.d.mts CHANGED
@@ -574,12 +574,6 @@ type AgentResponse = {
574
574
  * Whether the agent is saved as a workflow
575
575
  */
576
576
  saved?: boolean;
577
- /**
578
- * Credit Usage
579
- *
580
- * Credit usage for the agent. None if the agent is still running
581
- */
582
- credit_usage?: number | null;
583
577
  };
584
578
  /**
585
579
  * AgentStatus
@@ -589,12 +583,6 @@ type AgentStatus = 'active' | 'closed';
589
583
  * AgentStatusResponse
590
584
  */
591
585
  type AgentStatusResponse = {
592
- /**
593
- * Replay
594
- *
595
- * The session replay in `.webp` format
596
- */
597
- replay?: Blob | File | null;
598
586
  /**
599
587
  * Agent Id
600
588
  *
@@ -629,12 +617,6 @@ type AgentStatusResponse = {
629
617
  * Whether the agent is saved as a workflow
630
618
  */
631
619
  saved?: boolean;
632
- /**
633
- * Credit Usage
634
- *
635
- * Credit usage for the agent. None if the agent is still running
636
- */
637
- credit_usage?: number | null;
638
620
  /**
639
621
  * Task
640
622
  *
@@ -667,18 +649,6 @@ type AgentStatusResponse = {
667
649
  steps?: Array<{
668
650
  [key: string]: unknown;
669
651
  }>;
670
- /**
671
- * Replay Start Offset
672
- *
673
- * The start offset of the replay
674
- */
675
- replay_start_offset: number;
676
- /**
677
- * Replay Stop Offset
678
- *
679
- * The stop offset of the replay
680
- */
681
- replay_stop_offset: number;
682
652
  };
683
653
  /**
684
654
  * AnythingStartRequest
@@ -950,6 +920,12 @@ type ApiSessionStartRequest = {
950
920
  extra_http_headers?: {
951
921
  [key: string]: string;
952
922
  } | null;
923
+ /**
924
+ * Vault Id
925
+ *
926
+ * The vault to use for the session
927
+ */
928
+ vault_id?: string | null;
953
929
  };
954
930
  /**
955
931
  * BaseModel
@@ -2463,6 +2439,12 @@ type GlobalScrapeRequest = {
2463
2439
  extra_http_headers?: {
2464
2440
  [key: string]: string;
2465
2441
  } | null;
2442
+ /**
2443
+ * Vault Id
2444
+ *
2445
+ * The vault to use for the session
2446
+ */
2447
+ vault_id?: string | null;
2466
2448
  /**
2467
2449
  * Selector
2468
2450
  *
@@ -2696,12 +2678,6 @@ type ImprovePromptResponse = {
2696
2678
  * LegacyAgentStatusResponse
2697
2679
  */
2698
2680
  type LegacyAgentStatusResponse = {
2699
- /**
2700
- * Replay
2701
- *
2702
- * The session replay in `.webp` format
2703
- */
2704
- replay?: Blob | File | null;
2705
2681
  /**
2706
2682
  * Agent Id
2707
2683
  *
@@ -2736,12 +2712,6 @@ type LegacyAgentStatusResponse = {
2736
2712
  * Whether the agent is saved as a workflow
2737
2713
  */
2738
2714
  saved?: boolean;
2739
- /**
2740
- * Credit Usage
2741
- *
2742
- * Credit usage for the agent. None if the agent is still running
2743
- */
2744
- credit_usage?: number | null;
2745
2715
  /**
2746
2716
  * Task
2747
2717
  *
@@ -2772,18 +2742,6 @@ type LegacyAgentStatusResponse = {
2772
2742
  steps?: Array<{
2773
2743
  [key: string]: unknown;
2774
2744
  }>;
2775
- /**
2776
- * Replay Start Offset
2777
- *
2778
- * The start offset of the replay
2779
- */
2780
- replay_start_offset: number;
2781
- /**
2782
- * Replay Stop Offset
2783
- *
2784
- * The stop offset of the replay
2785
- */
2786
- replay_stop_offset: number;
2787
2745
  };
2788
2746
  /**
2789
2747
  * ListCredentialsResponse
@@ -4039,12 +3997,6 @@ type SessionResponse = {
4039
3997
  * Error message if the operation failed to complete
4040
3998
  */
4041
3999
  error?: string | null;
4042
- /**
4043
- * Credit Usage
4044
- *
4045
- * Credit usage for the session. None
4046
- */
4047
- credit_usage?: number | null;
4048
4000
  /**
4049
4001
  * Proxies
4050
4002
  *
@@ -5605,12 +5557,6 @@ type SessionResponseWritable = {
5605
5557
  * Error message if the operation failed to complete
5606
5558
  */
5607
5559
  error?: string | null;
5608
- /**
5609
- * Credit Usage
5610
- *
5611
- * Credit usage for the session. None
5612
- */
5613
- credit_usage?: number | null;
5614
5560
  /**
5615
5561
  * Proxies
5616
5562
  *
@@ -8907,11 +8853,19 @@ declare class Agent {
8907
8853
  /**
8908
8854
  * Start an agent task (non-blocking) - mirrors Python start method
8909
8855
  */
8856
+ start<T>(data: AgentRunRequest & {
8857
+ response_format: z.ZodSchema<T>;
8858
+ }): Promise<AgentResponse>;
8910
8859
  start(data: AgentRunRequest): Promise<AgentResponse>;
8911
8860
  /**
8912
8861
  * Run agent task (blocking) - mirrors Python run method behavior
8913
8862
  * This is the main method that mirrors the Python SDK's run method
8914
8863
  */
8864
+ run<T>(data: AgentRunRequest & {
8865
+ response_format: z.ZodSchema<T>;
8866
+ }): Promise<LegacyAgentStatusResponse & {
8867
+ answer: T | null;
8868
+ }>;
8915
8869
  run(data: AgentRunRequest): Promise<LegacyAgentStatusResponse>;
8916
8870
  /**
8917
8871
  * Watch logs and wait for completion - mirrors Python watch_logs_and_wait
package/dist/index.d.ts CHANGED
@@ -574,12 +574,6 @@ type AgentResponse = {
574
574
  * Whether the agent is saved as a workflow
575
575
  */
576
576
  saved?: boolean;
577
- /**
578
- * Credit Usage
579
- *
580
- * Credit usage for the agent. None if the agent is still running
581
- */
582
- credit_usage?: number | null;
583
577
  };
584
578
  /**
585
579
  * AgentStatus
@@ -589,12 +583,6 @@ type AgentStatus = 'active' | 'closed';
589
583
  * AgentStatusResponse
590
584
  */
591
585
  type AgentStatusResponse = {
592
- /**
593
- * Replay
594
- *
595
- * The session replay in `.webp` format
596
- */
597
- replay?: Blob | File | null;
598
586
  /**
599
587
  * Agent Id
600
588
  *
@@ -629,12 +617,6 @@ type AgentStatusResponse = {
629
617
  * Whether the agent is saved as a workflow
630
618
  */
631
619
  saved?: boolean;
632
- /**
633
- * Credit Usage
634
- *
635
- * Credit usage for the agent. None if the agent is still running
636
- */
637
- credit_usage?: number | null;
638
620
  /**
639
621
  * Task
640
622
  *
@@ -667,18 +649,6 @@ type AgentStatusResponse = {
667
649
  steps?: Array<{
668
650
  [key: string]: unknown;
669
651
  }>;
670
- /**
671
- * Replay Start Offset
672
- *
673
- * The start offset of the replay
674
- */
675
- replay_start_offset: number;
676
- /**
677
- * Replay Stop Offset
678
- *
679
- * The stop offset of the replay
680
- */
681
- replay_stop_offset: number;
682
652
  };
683
653
  /**
684
654
  * AnythingStartRequest
@@ -950,6 +920,12 @@ type ApiSessionStartRequest = {
950
920
  extra_http_headers?: {
951
921
  [key: string]: string;
952
922
  } | null;
923
+ /**
924
+ * Vault Id
925
+ *
926
+ * The vault to use for the session
927
+ */
928
+ vault_id?: string | null;
953
929
  };
954
930
  /**
955
931
  * BaseModel
@@ -2463,6 +2439,12 @@ type GlobalScrapeRequest = {
2463
2439
  extra_http_headers?: {
2464
2440
  [key: string]: string;
2465
2441
  } | null;
2442
+ /**
2443
+ * Vault Id
2444
+ *
2445
+ * The vault to use for the session
2446
+ */
2447
+ vault_id?: string | null;
2466
2448
  /**
2467
2449
  * Selector
2468
2450
  *
@@ -2696,12 +2678,6 @@ type ImprovePromptResponse = {
2696
2678
  * LegacyAgentStatusResponse
2697
2679
  */
2698
2680
  type LegacyAgentStatusResponse = {
2699
- /**
2700
- * Replay
2701
- *
2702
- * The session replay in `.webp` format
2703
- */
2704
- replay?: Blob | File | null;
2705
2681
  /**
2706
2682
  * Agent Id
2707
2683
  *
@@ -2736,12 +2712,6 @@ type LegacyAgentStatusResponse = {
2736
2712
  * Whether the agent is saved as a workflow
2737
2713
  */
2738
2714
  saved?: boolean;
2739
- /**
2740
- * Credit Usage
2741
- *
2742
- * Credit usage for the agent. None if the agent is still running
2743
- */
2744
- credit_usage?: number | null;
2745
2715
  /**
2746
2716
  * Task
2747
2717
  *
@@ -2772,18 +2742,6 @@ type LegacyAgentStatusResponse = {
2772
2742
  steps?: Array<{
2773
2743
  [key: string]: unknown;
2774
2744
  }>;
2775
- /**
2776
- * Replay Start Offset
2777
- *
2778
- * The start offset of the replay
2779
- */
2780
- replay_start_offset: number;
2781
- /**
2782
- * Replay Stop Offset
2783
- *
2784
- * The stop offset of the replay
2785
- */
2786
- replay_stop_offset: number;
2787
2745
  };
2788
2746
  /**
2789
2747
  * ListCredentialsResponse
@@ -4039,12 +3997,6 @@ type SessionResponse = {
4039
3997
  * Error message if the operation failed to complete
4040
3998
  */
4041
3999
  error?: string | null;
4042
- /**
4043
- * Credit Usage
4044
- *
4045
- * Credit usage for the session. None
4046
- */
4047
- credit_usage?: number | null;
4048
4000
  /**
4049
4001
  * Proxies
4050
4002
  *
@@ -5605,12 +5557,6 @@ type SessionResponseWritable = {
5605
5557
  * Error message if the operation failed to complete
5606
5558
  */
5607
5559
  error?: string | null;
5608
- /**
5609
- * Credit Usage
5610
- *
5611
- * Credit usage for the session. None
5612
- */
5613
- credit_usage?: number | null;
5614
5560
  /**
5615
5561
  * Proxies
5616
5562
  *
@@ -8907,11 +8853,19 @@ declare class Agent {
8907
8853
  /**
8908
8854
  * Start an agent task (non-blocking) - mirrors Python start method
8909
8855
  */
8856
+ start<T>(data: AgentRunRequest & {
8857
+ response_format: z.ZodSchema<T>;
8858
+ }): Promise<AgentResponse>;
8910
8859
  start(data: AgentRunRequest): Promise<AgentResponse>;
8911
8860
  /**
8912
8861
  * Run agent task (blocking) - mirrors Python run method behavior
8913
8862
  * This is the main method that mirrors the Python SDK's run method
8914
8863
  */
8864
+ run<T>(data: AgentRunRequest & {
8865
+ response_format: z.ZodSchema<T>;
8866
+ }): Promise<LegacyAgentStatusResponse & {
8867
+ answer: T | null;
8868
+ }>;
8915
8869
  run(data: AgentRunRequest): Promise<LegacyAgentStatusResponse>;
8916
8870
  /**
8917
8871
  * Watch logs and wait for completion - mirrors Python watch_logs_and_wait
package/dist/index.js CHANGED
@@ -1690,6 +1690,16 @@ var Session = class {
1690
1690
 
1691
1691
  // src/agent.ts
1692
1692
  var import_ws = __toESM(require("ws"));
1693
+ var import_zod2 = require("zod");
1694
+ function prepareAgentRequest(data) {
1695
+ const apiData = { ...data };
1696
+ const rf = data.response_format;
1697
+ if (rf && typeof rf.parse === "function" && typeof rf.safeParse === "function") {
1698
+ apiData.response_format = import_zod2.z.toJSONSchema(rf);
1699
+ return { apiData, zodSchema: rf };
1700
+ }
1701
+ return { apiData, zodSchema: null };
1702
+ }
1693
1703
  function validatePersonaOption(persona, persona_id) {
1694
1704
  if (persona) {
1695
1705
  try {
@@ -1812,9 +1822,6 @@ var Agent = class {
1812
1822
  throw new Error("Either session (for running a new agent) or agent_id (for accessing an existing agent) have to be provided");
1813
1823
  }
1814
1824
  }
1815
- /**
1816
- * Start an agent task (non-blocking) - mirrors Python start method
1817
- */
1818
1825
  async start(data) {
1819
1826
  if (this.existingAgent) {
1820
1827
  throw new Error("You cannot call start() on an agent instantiated from agent id");
@@ -1823,9 +1830,10 @@ var Agent = class {
1823
1830
  throw new Error("Agent not properly initialized with session");
1824
1831
  }
1825
1832
  try {
1833
+ const { apiData } = prepareAgentRequest(data);
1826
1834
  const requestBody = {
1827
1835
  ...this.request,
1828
- ...data
1836
+ ...apiData
1829
1837
  };
1830
1838
  const response = await agentStart({
1831
1839
  client: this.client.getClient(),
@@ -1840,17 +1848,28 @@ var Agent = class {
1840
1848
  throw new Error(`Failed to start agent: ${error instanceof Error ? error.message : String(error)}`);
1841
1849
  }
1842
1850
  }
1843
- /**
1844
- * Run agent task (blocking) - mirrors Python run method behavior
1845
- * This is the main method that mirrors the Python SDK's run method
1846
- */
1847
1851
  async run(data) {
1848
1852
  if (this.existingAgent) {
1849
1853
  throw new Error("You cannot call run() on an agent instantiated from agent id");
1850
1854
  }
1851
- this.response = await this.start(data);
1855
+ const { apiData, zodSchema } = prepareAgentRequest(data);
1856
+ this.response = await this.start(apiData);
1852
1857
  console.log(`[Agent] ${this.agentId} started`);
1853
- return await this.watchLogsAndWait(true, data.updateHandler || null);
1858
+ const result = await this.watchLogsAndWait(true, data.updateHandler || null);
1859
+ if (zodSchema && result && result.answer !== void 0 && result.answer !== null) {
1860
+ let candidate;
1861
+ try {
1862
+ candidate = typeof result.answer === "string" ? JSON.parse(result.answer) : result.answer;
1863
+ } catch {
1864
+ throw new Error(`Agent answer is not valid JSON and cannot be validated against the schema`);
1865
+ }
1866
+ try {
1867
+ result.answer = zodSchema.parse(candidate);
1868
+ } catch (error) {
1869
+ throw new Error(`Agent answer schema validation failed: ${error instanceof Error ? error.message : String(error)}`);
1870
+ }
1871
+ }
1872
+ return result;
1854
1873
  }
1855
1874
  /**
1856
1875
  * Watch logs and wait for completion - mirrors Python watch_logs_and_wait
@@ -2568,7 +2587,7 @@ var NottePersona = class {
2568
2587
  };
2569
2588
 
2570
2589
  // src/version.ts
2571
- var SDK_VERSION = true ? "0.0.1" : "dev";
2590
+ var SDK_VERSION = true ? "0.0.3" : "dev";
2572
2591
 
2573
2592
  // src/functions.ts
2574
2593
  var NotteFunction = class {
@@ -2645,7 +2664,7 @@ var NotteFunction = class {
2645
2664
  };
2646
2665
 
2647
2666
  // src/client.ts
2648
- var import_zod2 = require("zod");
2667
+ var import_zod3 = require("zod");
2649
2668
  var NotteClient = class {
2650
2669
  constructor(config = {}) {
2651
2670
  const apiKey = config.apiKey || process.env.NOTTE_API_KEY;
@@ -2654,12 +2673,13 @@ var NotteClient = class {
2654
2673
  throw new Error("API key is required. Provide it via config.apiKey or set the NOTTE_API_KEY environment variable.");
2655
2674
  }
2656
2675
  this.config = {
2657
- baseUrl: config.baseUrl || "https://api.notte.cc",
2676
+ baseUrl: config.baseUrl || process.env.NOTTE_API_URL || "https://api.notte.cc",
2658
2677
  apiKey,
2659
2678
  ...config
2660
2679
  };
2661
2680
  client.setConfig({
2662
- baseUrl: this.config.baseUrl
2681
+ baseUrl: this.config.baseUrl,
2682
+ redirect: "manual"
2663
2683
  });
2664
2684
  client.interceptors.request.use((request) => {
2665
2685
  request.headers.set("Authorization", `Bearer ${this.config.apiKey}`);
@@ -2667,6 +2687,33 @@ var NotteClient = class {
2667
2687
  request.headers.set("x-notte-sdk-version", SDK_VERSION);
2668
2688
  return request;
2669
2689
  });
2690
+ client.interceptors.response.use(async (response, request, opts) => {
2691
+ if ((response.status === 307 || response.status === 308) && response.headers.get("location")) {
2692
+ const location = response.headers.get("location");
2693
+ const headers = new Headers(request.headers);
2694
+ if (new URL(location).origin !== new URL(request.url).origin) {
2695
+ headers.delete("Authorization");
2696
+ }
2697
+ const headerRecord = {};
2698
+ headers.forEach((v, k) => {
2699
+ headerRecord[k] = v;
2700
+ });
2701
+ const redirected = await fetch(location, {
2702
+ method: request.method,
2703
+ headers: headerRecord,
2704
+ body: opts.serializedBody ?? void 0
2705
+ });
2706
+ return redirected;
2707
+ }
2708
+ const ct = response.headers.get("content-type") ?? "";
2709
+ if (ct.split(";")[0]?.trim() === "text/plain") {
2710
+ const body = await response.arrayBuffer();
2711
+ const headers = new Headers(response.headers);
2712
+ headers.set("content-type", "application/json");
2713
+ return new Response(body, { status: response.status, statusText: response.statusText, headers });
2714
+ }
2715
+ return response;
2716
+ });
2670
2717
  }
2671
2718
  /**
2672
2719
  * Create a new session
@@ -2727,7 +2774,7 @@ var NotteClient = class {
2727
2774
  if (options.json_schema) {
2728
2775
  apiOptions.response_format = options.json_schema;
2729
2776
  } else {
2730
- apiOptions.response_format = import_zod2.z.toJSONSchema(options.response_format);
2777
+ apiOptions.response_format = import_zod3.z.toJSONSchema(options.response_format);
2731
2778
  }
2732
2779
  if (!apiOptions.instructions) {
2733
2780
  const schemaStr = JSON.stringify(apiOptions.response_format);