@z3rno/sdk 0.4.0 → 0.6.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 +238 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +256 -1
- package/dist/index.d.ts +256 -1
- package/dist/index.js +233 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -421,6 +421,34 @@ var RefineJobStatusResponse = zod.z.object({
|
|
|
421
421
|
created_at: zod.z.string().nullable().optional(),
|
|
422
422
|
updated_at: zod.z.string().nullable().optional()
|
|
423
423
|
});
|
|
424
|
+
var ConversationResponse = zod.z.object({
|
|
425
|
+
id: zod.z.string(),
|
|
426
|
+
agent_id: zod.z.string(),
|
|
427
|
+
user_id: zod.z.string().nullable().optional(),
|
|
428
|
+
title: zod.z.string().nullable().optional(),
|
|
429
|
+
summary_cadence: zod.z.number(),
|
|
430
|
+
turn_count: zod.z.number(),
|
|
431
|
+
last_summary_turn: zod.z.number(),
|
|
432
|
+
metadata: zod.z.record(zod.z.unknown()).default({}),
|
|
433
|
+
created_at: zod.z.string(),
|
|
434
|
+
updated_at: zod.z.string()
|
|
435
|
+
});
|
|
436
|
+
var TurnAddResponse = zod.z.object({
|
|
437
|
+
turn_index: zod.z.number(),
|
|
438
|
+
needs_summary: zod.z.boolean()
|
|
439
|
+
});
|
|
440
|
+
var TurnResponse = zod.z.object({
|
|
441
|
+
memory_id: zod.z.string(),
|
|
442
|
+
turn_index: zod.z.number(),
|
|
443
|
+
turn_role: zod.z.string(),
|
|
444
|
+
content: zod.z.string(),
|
|
445
|
+
created_at: zod.z.string()
|
|
446
|
+
});
|
|
447
|
+
var TurnListResponse = zod.z.object({
|
|
448
|
+
turns: zod.z.array(TurnResponse),
|
|
449
|
+
total: zod.z.number(),
|
|
450
|
+
conversation_id: zod.z.string()
|
|
451
|
+
});
|
|
424
452
|
|
|
425
453
|
// src/client.ts
|
|
426
454
|
var Z3rnoClient = class {
|
|
@@ -557,6 +585,9 @@ var Z3rnoClient = class {
|
|
|
557
585
|
strategy: params.strategy ?? "AUTO",
|
|
558
586
|
rerank: params.rerank ?? false
|
|
559
587
|
};
|
|
588
|
+
if (params.conversationId) {
|
|
589
|
+
body.conversation_id = params.conversationId;
|
|
590
|
+
}
|
|
560
591
|
const resp = await this.request("POST", "/v1/memories/recall", body);
|
|
561
592
|
return RecallResponse.parse(resp);
|
|
562
593
|
}
|
|
@@ -860,6 +891,58 @@ var Z3rnoClient = class {
|
|
|
860
891
|
const resp = await this.request("GET", `/v1/refine/${jobId}`);
|
|
861
892
|
return RefineJobStatusResponse.parse(resp);
|
|
862
893
|
}
|
|
894
|
+
// --- Conversations (Phase G slice 2) ---
|
|
895
|
+
/**
|
|
896
|
+
* Open a new conversation. Returns the conversation row including
|
|
897
|
+
* the assigned `id`, which subsequent `recall`s and `addTurn`s
|
|
898
|
+
* reference. The `summaryCadence` controls how often the server
|
|
899
|
+
* flags the conversation for summarization.
|
|
900
|
+
*/
|
|
901
|
+
async createConversation(params) {
|
|
902
|
+
const body = {
|
|
903
|
+
agent_id: params.agentId,
|
|
904
|
+
summary_cadence: params.summaryCadence ?? 10
|
|
905
|
+
};
|
|
906
|
+
if (params.userId) body.user_id = params.userId;
|
|
907
|
+
if (params.title) body.title = params.title;
|
|
908
|
+
if (params.metadata) body.metadata = params.metadata;
|
|
909
|
+
const resp = await this.request("POST", "/v1/conversations", body);
|
|
910
|
+
return ConversationResponse.parse(resp);
|
|
911
|
+
}
|
|
912
|
+
async getConversation(conversationId) {
|
|
913
|
+
const resp = await this.request("GET", `/v1/conversations/${conversationId}`);
|
|
914
|
+
return ConversationResponse.parse(resp);
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Stamp an existing Memo as the next turn of the conversation.
|
|
918
|
+
* Returns the assigned `turn_index` plus `needs_summary` — when
|
|
919
|
+
* `true`, the conversation has crossed its cadence threshold.
|
|
920
|
+
*/
|
|
921
|
+
async addTurn(conversationId, params) {
|
|
922
|
+
const resp = await this.request(
|
|
923
|
+
"POST",
|
|
924
|
+
`/v1/conversations/${conversationId}/turns`,
|
|
925
|
+
{ memory_id: params.memoryId, turn_role: params.turnRole }
|
|
926
|
+
);
|
|
927
|
+
return TurnAddResponse.parse(resp);
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* v0.19.3 — soft-delete a conversation. Existing turn Memos stay
|
|
931
|
+
* queryable through standard recall; the conversation itself stops
|
|
932
|
+
* accepting turns and its endpoints 404. Idempotent.
|
|
933
|
+
*/
|
|
934
|
+
async deleteConversation(conversationId) {
|
|
935
|
+
await this.request("DELETE", `/v1/conversations/${conversationId}`);
|
|
936
|
+
}
|
|
937
|
+
async listTurns(conversationId, params) {
|
|
938
|
+
const query = new URLSearchParams();
|
|
939
|
+
if (params?.afterTurn !== void 0)
|
|
940
|
+
query.set("after_turn", String(params.afterTurn));
|
|
941
|
+
query.set("limit", String(params?.limit ?? 50));
|
|
942
|
+
const path = `/v1/conversations/${conversationId}/turns?${query.toString()}`;
|
|
943
|
+
const resp = await this.request("GET", path);
|
|
944
|
+
return TurnListResponse.parse(resp);
|
|
945
|
+
}
|
|
863
946
|
// --- HTTP layer ---
|
|
864
947
|
async request(method, path, body) {
|
|
865
948
|
let lastError;
|
|
@@ -977,10 +1060,160 @@ var Z3rnoClient = class {
|
|
|
977
1060
|
}
|
|
978
1061
|
};
|
|
979
1062
|
|
|
1063
|
+
// src/integrations/vercel-ai.ts
|
|
1064
|
+
var Z3rnoVercelMemory = class {
|
|
1065
|
+
client;
|
|
1066
|
+
agentId;
|
|
1067
|
+
conversationId;
|
|
1068
|
+
topK;
|
|
1069
|
+
constructor(options) {
|
|
1070
|
+
this.client = options.client;
|
|
1071
|
+
this.agentId = options.agentId;
|
|
1072
|
+
this.conversationId = options.conversationId;
|
|
1073
|
+
this.topK = options.topK ?? 50;
|
|
1074
|
+
}
|
|
1075
|
+
async messages() {
|
|
1076
|
+
if (this.conversationId) {
|
|
1077
|
+
const page = await this.client.listTurns(this.conversationId, {
|
|
1078
|
+
limit: this.topK
|
|
1079
|
+
});
|
|
1080
|
+
return page.turns.map((t) => ({
|
|
1081
|
+
role: this.normaliseRole(t.turn_role),
|
|
1082
|
+
content: t.content
|
|
1083
|
+
}));
|
|
1084
|
+
}
|
|
1085
|
+
const resp = await this.client.recall({
|
|
1086
|
+
agentId: this.agentId,
|
|
1087
|
+
topK: this.topK,
|
|
1088
|
+
memoryType: "episodic"
|
|
1089
|
+
});
|
|
1090
|
+
const reversed = [...resp.results].reverse();
|
|
1091
|
+
return reversed.map((r) => ({
|
|
1092
|
+
role: this.normaliseRole(
|
|
1093
|
+
(r.metadata ?? {})["role"]
|
|
1094
|
+
),
|
|
1095
|
+
content: r.content
|
|
1096
|
+
}));
|
|
1097
|
+
}
|
|
1098
|
+
async appendUserMessage(content) {
|
|
1099
|
+
await this.append(content, "user");
|
|
1100
|
+
}
|
|
1101
|
+
async appendAssistantMessage(content) {
|
|
1102
|
+
await this.append(content, "assistant");
|
|
1103
|
+
}
|
|
1104
|
+
async appendToolMessage(content) {
|
|
1105
|
+
await this.append(content, "tool");
|
|
1106
|
+
}
|
|
1107
|
+
async append(content, role) {
|
|
1108
|
+
const memory = await this.client.store({
|
|
1109
|
+
agentId: this.agentId,
|
|
1110
|
+
content,
|
|
1111
|
+
memoryType: "episodic",
|
|
1112
|
+
metadata: { role },
|
|
1113
|
+
relationships: []
|
|
1114
|
+
});
|
|
1115
|
+
if (this.conversationId) {
|
|
1116
|
+
await this.client.addTurn(this.conversationId, {
|
|
1117
|
+
memoryId: memory.id,
|
|
1118
|
+
turnRole: role
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
normaliseRole(raw) {
|
|
1123
|
+
switch (raw) {
|
|
1124
|
+
case "assistant":
|
|
1125
|
+
case "ai":
|
|
1126
|
+
return "assistant";
|
|
1127
|
+
case "system":
|
|
1128
|
+
return "system";
|
|
1129
|
+
case "tool":
|
|
1130
|
+
return "tool";
|
|
1131
|
+
default:
|
|
1132
|
+
return "user";
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
// src/integrations/mastra.ts
|
|
1138
|
+
var Z3rnoMastraMemory = class {
|
|
1139
|
+
client;
|
|
1140
|
+
agentId;
|
|
1141
|
+
conversationId;
|
|
1142
|
+
topK;
|
|
1143
|
+
constructor(options) {
|
|
1144
|
+
this.client = options.client;
|
|
1145
|
+
this.agentId = options.agentId;
|
|
1146
|
+
this.conversationId = options.conversationId;
|
|
1147
|
+
this.topK = options.topK ?? 50;
|
|
1148
|
+
}
|
|
1149
|
+
/** Mastra contract: return ordered prior messages for the thread. */
|
|
1150
|
+
async getMessages(_args) {
|
|
1151
|
+
const limit = _args?.limit ?? this.topK;
|
|
1152
|
+
if (this.conversationId) {
|
|
1153
|
+
const page = await this.client.listTurns(this.conversationId, { limit });
|
|
1154
|
+
return page.turns.map((t) => ({
|
|
1155
|
+
role: this.normaliseRole(t.turn_role),
|
|
1156
|
+
content: t.content,
|
|
1157
|
+
threadId: this.conversationId
|
|
1158
|
+
}));
|
|
1159
|
+
}
|
|
1160
|
+
const resp = await this.client.recall({
|
|
1161
|
+
agentId: this.agentId,
|
|
1162
|
+
topK: limit,
|
|
1163
|
+
memoryType: "episodic"
|
|
1164
|
+
});
|
|
1165
|
+
const reversed = [...resp.results].reverse();
|
|
1166
|
+
return reversed.map((r) => ({
|
|
1167
|
+
role: this.normaliseRole(
|
|
1168
|
+
(r.metadata ?? {})["role"]
|
|
1169
|
+
),
|
|
1170
|
+
content: r.content
|
|
1171
|
+
}));
|
|
1172
|
+
}
|
|
1173
|
+
/** Mastra contract: persist one message. */
|
|
1174
|
+
async addMessage(message) {
|
|
1175
|
+
const memory = await this.client.store({
|
|
1176
|
+
agentId: this.agentId,
|
|
1177
|
+
content: message.content,
|
|
1178
|
+
memoryType: "episodic",
|
|
1179
|
+
metadata: { role: message.role },
|
|
1180
|
+
relationships: []
|
|
1181
|
+
});
|
|
1182
|
+
if (this.conversationId) {
|
|
1183
|
+
await this.client.addTurn(this.conversationId, {
|
|
1184
|
+
memoryId: memory.id,
|
|
1185
|
+
turnRole: message.role
|
|
1186
|
+
});
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Mastra `clear()` — deliberate no-op. Z3rno keeps the source of
|
|
1191
|
+
* truth and recall is already scoped per conversation; flushing
|
|
1192
|
+
* the thread would risk losing audit-relevant history.
|
|
1193
|
+
*/
|
|
1194
|
+
async clear() {
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
normaliseRole(raw) {
|
|
1198
|
+
switch (raw) {
|
|
1199
|
+
case "assistant":
|
|
1200
|
+
case "ai":
|
|
1201
|
+
return "assistant";
|
|
1202
|
+
case "system":
|
|
1203
|
+
return "system";
|
|
1204
|
+
case "tool":
|
|
1205
|
+
return "tool";
|
|
1206
|
+
default:
|
|
1207
|
+
return "user";
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
|
|
980
1212
|
exports.AuditEntry = AuditEntry;
|
|
981
1213
|
exports.AuditPageResponse = AuditPageResponse;
|
|
982
1214
|
exports.AuthenticationError = AuthenticationError;
|
|
983
1215
|
exports.BatchStoreResponse = BatchStoreResponse;
|
|
1216
|
+
exports.ConversationResponse = ConversationResponse;
|
|
984
1217
|
exports.DistillJobResponse = DistillJobResponse;
|
|
985
1218
|
exports.DistillJobStatusResponse = DistillJobStatusResponse;
|
|
986
1219
|
exports.EndSessionResponse = EndSessionResponse;
|
|
@@ -1001,10 +1234,15 @@ exports.RelationshipType = RelationshipType;
|
|
|
1001
1234
|
exports.RetrievalStrategy = RetrievalStrategy;
|
|
1002
1235
|
exports.ServerError = ServerError;
|
|
1003
1236
|
exports.SessionResponse = SessionResponse;
|
|
1237
|
+
exports.TurnAddResponse = TurnAddResponse;
|
|
1238
|
+
exports.TurnListResponse = TurnListResponse;
|
|
1239
|
+
exports.TurnResponse = TurnResponse;
|
|
1004
1240
|
exports.ValidationError = ValidationError;
|
|
1005
1241
|
exports.Z3rnoClient = Z3rnoClient;
|
|
1006
1242
|
exports.Z3rnoConnectionError = Z3rnoConnectionError;
|
|
1007
1243
|
exports.Z3rnoError = Z3rnoError;
|
|
1244
|
+
exports.Z3rnoMastraMemory = Z3rnoMastraMemory;
|
|
1008
1245
|
exports.Z3rnoTimeoutError = Z3rnoTimeoutError;
|
|
1246
|
+
exports.Z3rnoVercelMemory = Z3rnoVercelMemory;
|
|
1009
1247
|
//# sourceMappingURL=index.cjs.map
|
|
1010
1248
|
//# sourceMappingURL=index.cjs.map
|