@z3rno/sdk 0.4.0 → 0.5.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 +230 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +250 -1
- package/dist/index.d.ts +250 -1
- package/dist/index.js +225 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -419,6 +419,34 @@ var RefineJobStatusResponse = z.object({
|
|
|
419
419
|
created_at: z.string().nullable().optional(),
|
|
420
420
|
updated_at: z.string().nullable().optional()
|
|
421
421
|
});
|
|
422
|
+
var ConversationResponse = z.object({
|
|
423
|
+
id: z.string(),
|
|
424
|
+
agent_id: z.string(),
|
|
425
|
+
user_id: z.string().nullable().optional(),
|
|
426
|
+
title: z.string().nullable().optional(),
|
|
427
|
+
summary_cadence: z.number(),
|
|
428
|
+
turn_count: z.number(),
|
|
429
|
+
last_summary_turn: z.number(),
|
|
430
|
+
metadata: z.record(z.unknown()).default({}),
|
|
431
|
+
created_at: z.string(),
|
|
432
|
+
updated_at: z.string()
|
|
433
|
+
});
|
|
434
|
+
var TurnAddResponse = z.object({
|
|
435
|
+
turn_index: z.number(),
|
|
436
|
+
needs_summary: z.boolean()
|
|
437
|
+
});
|
|
438
|
+
var TurnResponse = z.object({
|
|
439
|
+
memory_id: z.string(),
|
|
440
|
+
turn_index: z.number(),
|
|
441
|
+
turn_role: z.string(),
|
|
442
|
+
content: z.string(),
|
|
443
|
+
created_at: z.string()
|
|
444
|
+
});
|
|
445
|
+
var TurnListResponse = z.object({
|
|
446
|
+
turns: z.array(TurnResponse),
|
|
447
|
+
total: z.number(),
|
|
448
|
+
conversation_id: z.string()
|
|
449
|
+
});
|
|
422
450
|
|
|
423
451
|
// src/client.ts
|
|
424
452
|
var Z3rnoClient = class {
|
|
@@ -555,6 +583,9 @@ var Z3rnoClient = class {
|
|
|
555
583
|
strategy: params.strategy ?? "AUTO",
|
|
556
584
|
rerank: params.rerank ?? false
|
|
557
585
|
};
|
|
586
|
+
if (params.conversationId) {
|
|
587
|
+
body.conversation_id = params.conversationId;
|
|
588
|
+
}
|
|
558
589
|
const resp = await this.request("POST", "/v1/memories/recall", body);
|
|
559
590
|
return RecallResponse.parse(resp);
|
|
560
591
|
}
|
|
@@ -858,6 +889,50 @@ var Z3rnoClient = class {
|
|
|
858
889
|
const resp = await this.request("GET", `/v1/refine/${jobId}`);
|
|
859
890
|
return RefineJobStatusResponse.parse(resp);
|
|
860
891
|
}
|
|
892
|
+
// --- Conversations (Phase G slice 2) ---
|
|
893
|
+
/**
|
|
894
|
+
* Open a new conversation. Returns the conversation row including
|
|
895
|
+
* the assigned `id`, which subsequent `recall`s and `addTurn`s
|
|
896
|
+
* reference. The `summaryCadence` controls how often the server
|
|
897
|
+
* flags the conversation for summarization.
|
|
898
|
+
*/
|
|
899
|
+
async createConversation(params) {
|
|
900
|
+
const body = {
|
|
901
|
+
agent_id: params.agentId,
|
|
902
|
+
summary_cadence: params.summaryCadence ?? 10
|
|
903
|
+
};
|
|
904
|
+
if (params.userId) body.user_id = params.userId;
|
|
905
|
+
if (params.title) body.title = params.title;
|
|
906
|
+
if (params.metadata) body.metadata = params.metadata;
|
|
907
|
+
const resp = await this.request("POST", "/v1/conversations", body);
|
|
908
|
+
return ConversationResponse.parse(resp);
|
|
909
|
+
}
|
|
910
|
+
async getConversation(conversationId) {
|
|
911
|
+
const resp = await this.request("GET", `/v1/conversations/${conversationId}`);
|
|
912
|
+
return ConversationResponse.parse(resp);
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Stamp an existing Memo as the next turn of the conversation.
|
|
916
|
+
* Returns the assigned `turn_index` plus `needs_summary` — when
|
|
917
|
+
* `true`, the conversation has crossed its cadence threshold.
|
|
918
|
+
*/
|
|
919
|
+
async addTurn(conversationId, params) {
|
|
920
|
+
const resp = await this.request(
|
|
921
|
+
"POST",
|
|
922
|
+
`/v1/conversations/${conversationId}/turns`,
|
|
923
|
+
{ memory_id: params.memoryId, turn_role: params.turnRole }
|
|
924
|
+
);
|
|
925
|
+
return TurnAddResponse.parse(resp);
|
|
926
|
+
}
|
|
927
|
+
async listTurns(conversationId, params) {
|
|
928
|
+
const query = new URLSearchParams();
|
|
929
|
+
if (params?.afterTurn !== void 0)
|
|
930
|
+
query.set("after_turn", String(params.afterTurn));
|
|
931
|
+
query.set("limit", String(params?.limit ?? 50));
|
|
932
|
+
const path = `/v1/conversations/${conversationId}/turns?${query.toString()}`;
|
|
933
|
+
const resp = await this.request("GET", path);
|
|
934
|
+
return TurnListResponse.parse(resp);
|
|
935
|
+
}
|
|
861
936
|
// --- HTTP layer ---
|
|
862
937
|
async request(method, path, body) {
|
|
863
938
|
let lastError;
|
|
@@ -975,6 +1050,155 @@ var Z3rnoClient = class {
|
|
|
975
1050
|
}
|
|
976
1051
|
};
|
|
977
1052
|
|
|
978
|
-
|
|
1053
|
+
// src/integrations/vercel-ai.ts
|
|
1054
|
+
var Z3rnoVercelMemory = class {
|
|
1055
|
+
client;
|
|
1056
|
+
agentId;
|
|
1057
|
+
conversationId;
|
|
1058
|
+
topK;
|
|
1059
|
+
constructor(options) {
|
|
1060
|
+
this.client = options.client;
|
|
1061
|
+
this.agentId = options.agentId;
|
|
1062
|
+
this.conversationId = options.conversationId;
|
|
1063
|
+
this.topK = options.topK ?? 50;
|
|
1064
|
+
}
|
|
1065
|
+
async messages() {
|
|
1066
|
+
if (this.conversationId) {
|
|
1067
|
+
const page = await this.client.listTurns(this.conversationId, {
|
|
1068
|
+
limit: this.topK
|
|
1069
|
+
});
|
|
1070
|
+
return page.turns.map((t) => ({
|
|
1071
|
+
role: this.normaliseRole(t.turn_role),
|
|
1072
|
+
content: t.content
|
|
1073
|
+
}));
|
|
1074
|
+
}
|
|
1075
|
+
const resp = await this.client.recall({
|
|
1076
|
+
agentId: this.agentId,
|
|
1077
|
+
topK: this.topK,
|
|
1078
|
+
memoryType: "episodic"
|
|
1079
|
+
});
|
|
1080
|
+
const reversed = [...resp.results].reverse();
|
|
1081
|
+
return reversed.map((r) => ({
|
|
1082
|
+
role: this.normaliseRole(
|
|
1083
|
+
(r.metadata ?? {})["role"]
|
|
1084
|
+
),
|
|
1085
|
+
content: r.content
|
|
1086
|
+
}));
|
|
1087
|
+
}
|
|
1088
|
+
async appendUserMessage(content) {
|
|
1089
|
+
await this.append(content, "user");
|
|
1090
|
+
}
|
|
1091
|
+
async appendAssistantMessage(content) {
|
|
1092
|
+
await this.append(content, "assistant");
|
|
1093
|
+
}
|
|
1094
|
+
async appendToolMessage(content) {
|
|
1095
|
+
await this.append(content, "tool");
|
|
1096
|
+
}
|
|
1097
|
+
async append(content, role) {
|
|
1098
|
+
const memory = await this.client.store({
|
|
1099
|
+
agentId: this.agentId,
|
|
1100
|
+
content,
|
|
1101
|
+
memoryType: "episodic",
|
|
1102
|
+
metadata: { role },
|
|
1103
|
+
relationships: []
|
|
1104
|
+
});
|
|
1105
|
+
if (this.conversationId) {
|
|
1106
|
+
await this.client.addTurn(this.conversationId, {
|
|
1107
|
+
memoryId: memory.id,
|
|
1108
|
+
turnRole: role
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
normaliseRole(raw) {
|
|
1113
|
+
switch (raw) {
|
|
1114
|
+
case "assistant":
|
|
1115
|
+
case "ai":
|
|
1116
|
+
return "assistant";
|
|
1117
|
+
case "system":
|
|
1118
|
+
return "system";
|
|
1119
|
+
case "tool":
|
|
1120
|
+
return "tool";
|
|
1121
|
+
default:
|
|
1122
|
+
return "user";
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
// src/integrations/mastra.ts
|
|
1128
|
+
var Z3rnoMastraMemory = class {
|
|
1129
|
+
client;
|
|
1130
|
+
agentId;
|
|
1131
|
+
conversationId;
|
|
1132
|
+
topK;
|
|
1133
|
+
constructor(options) {
|
|
1134
|
+
this.client = options.client;
|
|
1135
|
+
this.agentId = options.agentId;
|
|
1136
|
+
this.conversationId = options.conversationId;
|
|
1137
|
+
this.topK = options.topK ?? 50;
|
|
1138
|
+
}
|
|
1139
|
+
/** Mastra contract: return ordered prior messages for the thread. */
|
|
1140
|
+
async getMessages(_args) {
|
|
1141
|
+
const limit = _args?.limit ?? this.topK;
|
|
1142
|
+
if (this.conversationId) {
|
|
1143
|
+
const page = await this.client.listTurns(this.conversationId, { limit });
|
|
1144
|
+
return page.turns.map((t) => ({
|
|
1145
|
+
role: this.normaliseRole(t.turn_role),
|
|
1146
|
+
content: t.content,
|
|
1147
|
+
threadId: this.conversationId
|
|
1148
|
+
}));
|
|
1149
|
+
}
|
|
1150
|
+
const resp = await this.client.recall({
|
|
1151
|
+
agentId: this.agentId,
|
|
1152
|
+
topK: limit,
|
|
1153
|
+
memoryType: "episodic"
|
|
1154
|
+
});
|
|
1155
|
+
const reversed = [...resp.results].reverse();
|
|
1156
|
+
return reversed.map((r) => ({
|
|
1157
|
+
role: this.normaliseRole(
|
|
1158
|
+
(r.metadata ?? {})["role"]
|
|
1159
|
+
),
|
|
1160
|
+
content: r.content
|
|
1161
|
+
}));
|
|
1162
|
+
}
|
|
1163
|
+
/** Mastra contract: persist one message. */
|
|
1164
|
+
async addMessage(message) {
|
|
1165
|
+
const memory = await this.client.store({
|
|
1166
|
+
agentId: this.agentId,
|
|
1167
|
+
content: message.content,
|
|
1168
|
+
memoryType: "episodic",
|
|
1169
|
+
metadata: { role: message.role },
|
|
1170
|
+
relationships: []
|
|
1171
|
+
});
|
|
1172
|
+
if (this.conversationId) {
|
|
1173
|
+
await this.client.addTurn(this.conversationId, {
|
|
1174
|
+
memoryId: memory.id,
|
|
1175
|
+
turnRole: message.role
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Mastra `clear()` — deliberate no-op. Z3rno keeps the source of
|
|
1181
|
+
* truth and recall is already scoped per conversation; flushing
|
|
1182
|
+
* the thread would risk losing audit-relevant history.
|
|
1183
|
+
*/
|
|
1184
|
+
async clear() {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
normaliseRole(raw) {
|
|
1188
|
+
switch (raw) {
|
|
1189
|
+
case "assistant":
|
|
1190
|
+
case "ai":
|
|
1191
|
+
return "assistant";
|
|
1192
|
+
case "system":
|
|
1193
|
+
return "system";
|
|
1194
|
+
case "tool":
|
|
1195
|
+
return "tool";
|
|
1196
|
+
default:
|
|
1197
|
+
return "user";
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
|
|
1202
|
+
export { AuditEntry, AuditPageResponse, AuthenticationError, BatchStoreResponse, ConversationResponse, DistillJobResponse, DistillJobStatusResponse, EndSessionResponse, ForgetResponse, IngestJobResponse, IngestJobStatusResponse, MemoryHistoryResponse, MemoryResponse, MemoryType, MemoryVersion, NotFoundError, RateLimitError, RecallResponse, RecallResultItem, RefineJobResponse, RefineJobStatusResponse, RelationshipType, RetrievalStrategy, ServerError, SessionResponse, TurnAddResponse, TurnListResponse, TurnResponse, ValidationError, Z3rnoClient, Z3rnoConnectionError, Z3rnoError, Z3rnoMastraMemory, Z3rnoTimeoutError, Z3rnoVercelMemory };
|
|
979
1203
|
//# sourceMappingURL=index.js.map
|
|
980
1204
|
//# sourceMappingURL=index.js.map
|