@opperai/agents 0.3.0-beta → 0.3.0
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.cjs +91 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -14
- package/dist/index.d.ts +20 -14
- package/dist/index.js +72 -46
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,26 @@ var sse_js = require('@modelcontextprotocol/sdk/client/sse.js');
|
|
|
10
10
|
var stdio_js = require('@modelcontextprotocol/sdk/client/stdio.js');
|
|
11
11
|
var streamableHttp_js = require('@modelcontextprotocol/sdk/client/streamableHttp.js');
|
|
12
12
|
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule) return e;
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var zod__namespace = /*#__PURE__*/_interopNamespace(zod);
|
|
32
|
+
|
|
13
33
|
var __defProp = Object.defineProperty;
|
|
14
34
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
15
35
|
var __esm = (fn, res) => function __init() {
|
|
@@ -572,8 +592,11 @@ function getSchemaName(schema) {
|
|
|
572
592
|
return schemaAny._def.description;
|
|
573
593
|
}
|
|
574
594
|
const typeName = schemaAny._def?.typeName;
|
|
575
|
-
|
|
576
|
-
|
|
595
|
+
const type = schemaAny._def?.type;
|
|
596
|
+
const isObject = typeName === "ZodObject" || type === "object";
|
|
597
|
+
if (isObject && schemaAny._def) {
|
|
598
|
+
const shapeRaw = schemaAny._def.shape;
|
|
599
|
+
const shape = typeof shapeRaw === "function" ? shapeRaw() : shapeRaw;
|
|
577
600
|
if (shape && typeof shape === "object") {
|
|
578
601
|
const keys = Object.keys(shape);
|
|
579
602
|
if (keys.length > 0) {
|
|
@@ -586,6 +609,9 @@ function getSchemaName(schema) {
|
|
|
586
609
|
if (typeName) {
|
|
587
610
|
return typeName.replace("Zod", "").replace("Type", "");
|
|
588
611
|
}
|
|
612
|
+
if (type) {
|
|
613
|
+
return type.charAt(0).toUpperCase() + type.slice(1);
|
|
614
|
+
}
|
|
589
615
|
return "Any";
|
|
590
616
|
} catch {
|
|
591
617
|
return "Any";
|
|
@@ -597,12 +623,15 @@ function extractParameters(schema) {
|
|
|
597
623
|
}
|
|
598
624
|
try {
|
|
599
625
|
const schemaAny = schema;
|
|
600
|
-
|
|
601
|
-
|
|
626
|
+
const isObject = schemaAny._def?.typeName === "ZodObject" || schemaAny._def?.type === "object";
|
|
627
|
+
if (isObject) {
|
|
628
|
+
const shapeRaw = schemaAny._def?.shape;
|
|
629
|
+
const shape = typeof shapeRaw === "function" ? shapeRaw() : shapeRaw;
|
|
602
630
|
if (shape && typeof shape === "object") {
|
|
603
631
|
const params = [];
|
|
604
632
|
for (const [key, value] of Object.entries(shape)) {
|
|
605
|
-
const
|
|
633
|
+
const valueAny = value;
|
|
634
|
+
const fieldType = valueAny._def?.typeName || valueAny.def?.type || valueAny.type;
|
|
606
635
|
if (fieldType) {
|
|
607
636
|
const cleanType = fieldType.replace("Zod", "").toLowerCase();
|
|
608
637
|
params.push(`${key}: ${cleanType}`);
|
|
@@ -1430,7 +1459,7 @@ var ThoughtSchema = zod.z.object({
|
|
|
1430
1459
|
*/
|
|
1431
1460
|
confidence: zod.z.number().min(0).max(1).optional(),
|
|
1432
1461
|
/**
|
|
1433
|
-
* Additional metadata
|
|
1462
|
+
* Additional metadata (key-value pairs)
|
|
1434
1463
|
*/
|
|
1435
1464
|
metadata: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
1436
1465
|
});
|
|
@@ -1483,7 +1512,7 @@ var AgentDecisionSchema = zod.z.object({
|
|
|
1483
1512
|
/**
|
|
1484
1513
|
* Memory entries to write/update (key -> payload)
|
|
1485
1514
|
*/
|
|
1486
|
-
memoryUpdates: zod.z.record(MemoryUpdateSchema).default({}),
|
|
1515
|
+
memoryUpdates: zod.z.record(zod.z.string(), MemoryUpdateSchema).default({}),
|
|
1487
1516
|
/**
|
|
1488
1517
|
* Whether the task is complete and finalResult is available
|
|
1489
1518
|
* (single LLM call pattern)
|
|
@@ -1505,7 +1534,7 @@ function createAgentDecisionWithOutputSchema(outputSchema) {
|
|
|
1505
1534
|
userMessage: zod.z.string().default("Working on it..."),
|
|
1506
1535
|
toolCalls: zod.z.array(ToolCallSchema).default([]),
|
|
1507
1536
|
memoryReads: zod.z.array(zod.z.string()).default([]),
|
|
1508
|
-
memoryUpdates: zod.z.record(MemoryUpdateSchema).default({}),
|
|
1537
|
+
memoryUpdates: zod.z.record(zod.z.string(), MemoryUpdateSchema).default({}),
|
|
1509
1538
|
isComplete: zod.z.boolean().default(false),
|
|
1510
1539
|
finalResult: finalResultSchema
|
|
1511
1540
|
});
|
|
@@ -1529,10 +1558,60 @@ var ToolExecutionSummarySchema = zod.z.object({
|
|
|
1529
1558
|
*/
|
|
1530
1559
|
error: zod.z.string().optional()
|
|
1531
1560
|
});
|
|
1561
|
+
var hasNativeToJSONSchema = typeof zod__namespace.toJSONSchema === "function";
|
|
1562
|
+
function zodSchemaToJsonSchema(schema) {
|
|
1563
|
+
if (hasNativeToJSONSchema) {
|
|
1564
|
+
try {
|
|
1565
|
+
const toJSONSchema2 = zod__namespace.toJSONSchema;
|
|
1566
|
+
const result = toJSONSchema2(schema);
|
|
1567
|
+
return result;
|
|
1568
|
+
} catch {
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
return zodToJsonSchema.zodToJsonSchema(schema);
|
|
1572
|
+
}
|
|
1573
|
+
var SchemaValidationError = class extends Error {
|
|
1574
|
+
issues;
|
|
1575
|
+
constructor(message, issues) {
|
|
1576
|
+
super(message);
|
|
1577
|
+
this.name = "SchemaValidationError";
|
|
1578
|
+
this.issues = issues;
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
var validateSchema = (schema, value, options = {}) => {
|
|
1582
|
+
const result = schema.safeParse(value);
|
|
1583
|
+
if (!result.success) {
|
|
1584
|
+
throw new SchemaValidationError(
|
|
1585
|
+
options.message ?? "Schema validation failed",
|
|
1586
|
+
result.error.issues
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
return result.data;
|
|
1590
|
+
};
|
|
1591
|
+
var isSchemaValid = (schema, value) => {
|
|
1592
|
+
return schema.safeParse(value).success;
|
|
1593
|
+
};
|
|
1594
|
+
var schemaToJson = (schema, options = {}) => {
|
|
1595
|
+
if (hasNativeToJSONSchema) {
|
|
1596
|
+
return zodSchemaToJsonSchema(schema);
|
|
1597
|
+
}
|
|
1598
|
+
return zodToJsonSchema.zodToJsonSchema(schema, options);
|
|
1599
|
+
};
|
|
1600
|
+
var getSchemaDefault = (schema) => {
|
|
1601
|
+
const result = schema.safeParse(void 0);
|
|
1602
|
+
return result.success ? result.data : void 0;
|
|
1603
|
+
};
|
|
1604
|
+
var mergeSchemaDefaults = (schema, value) => {
|
|
1605
|
+
const defaults = getSchemaDefault(schema);
|
|
1606
|
+
if (defaults && typeof defaults === "object") {
|
|
1607
|
+
return validateSchema(schema, { ...defaults, ...value });
|
|
1608
|
+
}
|
|
1609
|
+
return validateSchema(schema, value);
|
|
1610
|
+
};
|
|
1532
1611
|
|
|
1533
1612
|
// package.json
|
|
1534
1613
|
var package_default = {
|
|
1535
|
-
version: "0.3.0
|
|
1614
|
+
version: "0.3.0"};
|
|
1536
1615
|
|
|
1537
1616
|
// src/utils/version.ts
|
|
1538
1617
|
var SDK_NAME = "@opperai/agents";
|
|
@@ -1763,7 +1842,7 @@ var OpperClient = class {
|
|
|
1763
1842
|
}
|
|
1764
1843
|
if (isZodSchema(schema)) {
|
|
1765
1844
|
try {
|
|
1766
|
-
return
|
|
1845
|
+
return zodSchemaToJsonSchema(schema);
|
|
1767
1846
|
} catch (error) {
|
|
1768
1847
|
this.logger.warn("Failed to convert Zod schema to JSON Schema", {
|
|
1769
1848
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -1789,41 +1868,6 @@ var OpperClient = class {
|
|
|
1789
1868
|
function createOpperClient(apiKey, options) {
|
|
1790
1869
|
return new OpperClient(apiKey, options);
|
|
1791
1870
|
}
|
|
1792
|
-
var SchemaValidationError = class extends Error {
|
|
1793
|
-
issues;
|
|
1794
|
-
constructor(message, issues) {
|
|
1795
|
-
super(message);
|
|
1796
|
-
this.name = "SchemaValidationError";
|
|
1797
|
-
this.issues = issues;
|
|
1798
|
-
}
|
|
1799
|
-
};
|
|
1800
|
-
var validateSchema = (schema, value, options = {}) => {
|
|
1801
|
-
const result = schema.safeParse(value);
|
|
1802
|
-
if (!result.success) {
|
|
1803
|
-
throw new SchemaValidationError(
|
|
1804
|
-
options.message ?? "Schema validation failed",
|
|
1805
|
-
result.error.issues
|
|
1806
|
-
);
|
|
1807
|
-
}
|
|
1808
|
-
return result.data;
|
|
1809
|
-
};
|
|
1810
|
-
var isSchemaValid = (schema, value) => {
|
|
1811
|
-
return schema.safeParse(value).success;
|
|
1812
|
-
};
|
|
1813
|
-
var schemaToJson = (schema, options = {}) => {
|
|
1814
|
-
return zodToJsonSchema.zodToJsonSchema(schema, options);
|
|
1815
|
-
};
|
|
1816
|
-
var getSchemaDefault = (schema) => {
|
|
1817
|
-
const result = schema.safeParse(void 0);
|
|
1818
|
-
return result.success ? result.data : void 0;
|
|
1819
|
-
};
|
|
1820
|
-
var mergeSchemaDefaults = (schema, value) => {
|
|
1821
|
-
const defaults = getSchemaDefault(schema);
|
|
1822
|
-
if (defaults && typeof defaults === "object") {
|
|
1823
|
-
return validateSchema(schema, { ...defaults, ...value });
|
|
1824
|
-
}
|
|
1825
|
-
return validateSchema(schema, value);
|
|
1826
|
-
};
|
|
1827
1871
|
|
|
1828
1872
|
// src/utils/streaming.ts
|
|
1829
1873
|
var STREAM_ROOT_PATH = "_root";
|
|
@@ -2108,6 +2152,7 @@ var Agent = class extends BaseAgent {
|
|
|
2108
2152
|
this.log("Task completed with final result in single call", {
|
|
2109
2153
|
iteration: currentIteration
|
|
2110
2154
|
});
|
|
2155
|
+
await this.handleMemoryActions(decision, context, thinkSpanId);
|
|
2111
2156
|
let finalResult;
|
|
2112
2157
|
if (this.outputSchema) {
|
|
2113
2158
|
const parseResult = this.outputSchema.safeParse(
|
|
@@ -3792,5 +3837,6 @@ exports.schemaToJson = schemaToJson;
|
|
|
3792
3837
|
exports.setDefaultLogger = setDefaultLogger;
|
|
3793
3838
|
exports.tool = tool;
|
|
3794
3839
|
exports.validateSchema = validateSchema;
|
|
3840
|
+
exports.zodSchemaToJsonSchema = zodSchemaToJsonSchema;
|
|
3795
3841
|
//# sourceMappingURL=index.cjs.map
|
|
3796
3842
|
//# sourceMappingURL=index.cjs.map
|