notte-sdk 0.0.1 → 0.0.2
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 +22 -0
- package/dist/index.d.mts +20 -66
- package/dist/index.d.ts +20 -66
- package/dist/index.js +32 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.mjs
CHANGED
|
@@ -1585,6 +1585,16 @@ var Session = class {
|
|
|
1585
1585
|
|
|
1586
1586
|
// src/agent.ts
|
|
1587
1587
|
import WebSocket from "ws";
|
|
1588
|
+
import { z as z2 } from "zod";
|
|
1589
|
+
function prepareAgentRequest(data) {
|
|
1590
|
+
const apiData = { ...data };
|
|
1591
|
+
const rf = data.response_format;
|
|
1592
|
+
if (rf && typeof rf.parse === "function" && typeof rf.safeParse === "function") {
|
|
1593
|
+
apiData.response_format = z2.toJSONSchema(rf);
|
|
1594
|
+
return { apiData, zodSchema: rf };
|
|
1595
|
+
}
|
|
1596
|
+
return { apiData, zodSchema: null };
|
|
1597
|
+
}
|
|
1588
1598
|
function validatePersonaOption(persona, persona_id) {
|
|
1589
1599
|
if (persona) {
|
|
1590
1600
|
try {
|
|
@@ -1707,9 +1717,6 @@ var Agent = class {
|
|
|
1707
1717
|
throw new Error("Either session (for running a new agent) or agent_id (for accessing an existing agent) have to be provided");
|
|
1708
1718
|
}
|
|
1709
1719
|
}
|
|
1710
|
-
/**
|
|
1711
|
-
* Start an agent task (non-blocking) - mirrors Python start method
|
|
1712
|
-
*/
|
|
1713
1720
|
async start(data) {
|
|
1714
1721
|
if (this.existingAgent) {
|
|
1715
1722
|
throw new Error("You cannot call start() on an agent instantiated from agent id");
|
|
@@ -1718,9 +1725,10 @@ var Agent = class {
|
|
|
1718
1725
|
throw new Error("Agent not properly initialized with session");
|
|
1719
1726
|
}
|
|
1720
1727
|
try {
|
|
1728
|
+
const { apiData } = prepareAgentRequest(data);
|
|
1721
1729
|
const requestBody = {
|
|
1722
1730
|
...this.request,
|
|
1723
|
-
...
|
|
1731
|
+
...apiData
|
|
1724
1732
|
};
|
|
1725
1733
|
const response = await agentStart({
|
|
1726
1734
|
client: this.client.getClient(),
|
|
@@ -1735,17 +1743,28 @@ var Agent = class {
|
|
|
1735
1743
|
throw new Error(`Failed to start agent: ${error instanceof Error ? error.message : String(error)}`);
|
|
1736
1744
|
}
|
|
1737
1745
|
}
|
|
1738
|
-
/**
|
|
1739
|
-
* Run agent task (blocking) - mirrors Python run method behavior
|
|
1740
|
-
* This is the main method that mirrors the Python SDK's run method
|
|
1741
|
-
*/
|
|
1742
1746
|
async run(data) {
|
|
1743
1747
|
if (this.existingAgent) {
|
|
1744
1748
|
throw new Error("You cannot call run() on an agent instantiated from agent id");
|
|
1745
1749
|
}
|
|
1746
|
-
|
|
1750
|
+
const { apiData, zodSchema } = prepareAgentRequest(data);
|
|
1751
|
+
this.response = await this.start(apiData);
|
|
1747
1752
|
console.log(`[Agent] ${this.agentId} started`);
|
|
1748
|
-
|
|
1753
|
+
const result = await this.watchLogsAndWait(true, data.updateHandler || null);
|
|
1754
|
+
if (zodSchema && result && result.answer !== void 0 && result.answer !== null) {
|
|
1755
|
+
let candidate;
|
|
1756
|
+
try {
|
|
1757
|
+
candidate = typeof result.answer === "string" ? JSON.parse(result.answer) : result.answer;
|
|
1758
|
+
} catch {
|
|
1759
|
+
throw new Error(`Agent answer is not valid JSON and cannot be validated against the schema`);
|
|
1760
|
+
}
|
|
1761
|
+
try {
|
|
1762
|
+
result.answer = zodSchema.parse(candidate);
|
|
1763
|
+
} catch (error) {
|
|
1764
|
+
throw new Error(`Agent answer schema validation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
return result;
|
|
1749
1768
|
}
|
|
1750
1769
|
/**
|
|
1751
1770
|
* Watch logs and wait for completion - mirrors Python watch_logs_and_wait
|
|
@@ -2463,7 +2482,7 @@ var NottePersona = class {
|
|
|
2463
2482
|
};
|
|
2464
2483
|
|
|
2465
2484
|
// src/version.ts
|
|
2466
|
-
var SDK_VERSION = true ? "0.0.
|
|
2485
|
+
var SDK_VERSION = true ? "0.0.2" : "dev";
|
|
2467
2486
|
|
|
2468
2487
|
// src/functions.ts
|
|
2469
2488
|
var NotteFunction = class {
|
|
@@ -2540,7 +2559,7 @@ var NotteFunction = class {
|
|
|
2540
2559
|
};
|
|
2541
2560
|
|
|
2542
2561
|
// src/client.ts
|
|
2543
|
-
import { z as
|
|
2562
|
+
import { z as z3 } from "zod";
|
|
2544
2563
|
var NotteClient = class {
|
|
2545
2564
|
constructor(config = {}) {
|
|
2546
2565
|
const apiKey = config.apiKey || process.env.NOTTE_API_KEY;
|
|
@@ -2622,7 +2641,7 @@ var NotteClient = class {
|
|
|
2622
2641
|
if (options.json_schema) {
|
|
2623
2642
|
apiOptions.response_format = options.json_schema;
|
|
2624
2643
|
} else {
|
|
2625
|
-
apiOptions.response_format =
|
|
2644
|
+
apiOptions.response_format = z3.toJSONSchema(options.response_format);
|
|
2626
2645
|
}
|
|
2627
2646
|
if (!apiOptions.instructions) {
|
|
2628
2647
|
const schemaStr = JSON.stringify(apiOptions.response_format);
|