@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.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,58 @@ 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
+ /**
928
+ * v0.19.3 — soft-delete a conversation. Existing turn Memos stay
929
+ * queryable through standard recall; the conversation itself stops
930
+ * accepting turns and its endpoints 404. Idempotent.
931
+ */
932
+ async deleteConversation(conversationId) {
933
+ await this.request("DELETE", `/v1/conversations/${conversationId}`);
934
+ }
935
+ async listTurns(conversationId, params) {
936
+ const query = new URLSearchParams();
937
+ if (params?.afterTurn !== void 0)
938
+ query.set("after_turn", String(params.afterTurn));
939
+ query.set("limit", String(params?.limit ?? 50));
940
+ const path = `/v1/conversations/${conversationId}/turns?${query.toString()}`;
941
+ const resp = await this.request("GET", path);
942
+ return TurnListResponse.parse(resp);
943
+ }
861
944
  // --- HTTP layer ---
862
945
  async request(method, path, body) {
863
946
  let lastError;
@@ -975,6 +1058,155 @@ var Z3rnoClient = class {
975
1058
  }
976
1059
  };
977
1060
 
978
- export { AuditEntry, AuditPageResponse, AuthenticationError, BatchStoreResponse, DistillJobResponse, DistillJobStatusResponse, EndSessionResponse, ForgetResponse, IngestJobResponse, IngestJobStatusResponse, MemoryHistoryResponse, MemoryResponse, MemoryType, MemoryVersion, NotFoundError, RateLimitError, RecallResponse, RecallResultItem, RefineJobResponse, RefineJobStatusResponse, RelationshipType, RetrievalStrategy, ServerError, SessionResponse, ValidationError, Z3rnoClient, Z3rnoConnectionError, Z3rnoError, Z3rnoTimeoutError };
1061
+ // src/integrations/vercel-ai.ts
1062
+ var Z3rnoVercelMemory = class {
1063
+ client;
1064
+ agentId;
1065
+ conversationId;
1066
+ topK;
1067
+ constructor(options) {
1068
+ this.client = options.client;
1069
+ this.agentId = options.agentId;
1070
+ this.conversationId = options.conversationId;
1071
+ this.topK = options.topK ?? 50;
1072
+ }
1073
+ async messages() {
1074
+ if (this.conversationId) {
1075
+ const page = await this.client.listTurns(this.conversationId, {
1076
+ limit: this.topK
1077
+ });
1078
+ return page.turns.map((t) => ({
1079
+ role: this.normaliseRole(t.turn_role),
1080
+ content: t.content
1081
+ }));
1082
+ }
1083
+ const resp = await this.client.recall({
1084
+ agentId: this.agentId,
1085
+ topK: this.topK,
1086
+ memoryType: "episodic"
1087
+ });
1088
+ const reversed = [...resp.results].reverse();
1089
+ return reversed.map((r) => ({
1090
+ role: this.normaliseRole(
1091
+ (r.metadata ?? {})["role"]
1092
+ ),
1093
+ content: r.content
1094
+ }));
1095
+ }
1096
+ async appendUserMessage(content) {
1097
+ await this.append(content, "user");
1098
+ }
1099
+ async appendAssistantMessage(content) {
1100
+ await this.append(content, "assistant");
1101
+ }
1102
+ async appendToolMessage(content) {
1103
+ await this.append(content, "tool");
1104
+ }
1105
+ async append(content, role) {
1106
+ const memory = await this.client.store({
1107
+ agentId: this.agentId,
1108
+ content,
1109
+ memoryType: "episodic",
1110
+ metadata: { role },
1111
+ relationships: []
1112
+ });
1113
+ if (this.conversationId) {
1114
+ await this.client.addTurn(this.conversationId, {
1115
+ memoryId: memory.id,
1116
+ turnRole: role
1117
+ });
1118
+ }
1119
+ }
1120
+ normaliseRole(raw) {
1121
+ switch (raw) {
1122
+ case "assistant":
1123
+ case "ai":
1124
+ return "assistant";
1125
+ case "system":
1126
+ return "system";
1127
+ case "tool":
1128
+ return "tool";
1129
+ default:
1130
+ return "user";
1131
+ }
1132
+ }
1133
+ };
1134
+
1135
+ // src/integrations/mastra.ts
1136
+ var Z3rnoMastraMemory = class {
1137
+ client;
1138
+ agentId;
1139
+ conversationId;
1140
+ topK;
1141
+ constructor(options) {
1142
+ this.client = options.client;
1143
+ this.agentId = options.agentId;
1144
+ this.conversationId = options.conversationId;
1145
+ this.topK = options.topK ?? 50;
1146
+ }
1147
+ /** Mastra contract: return ordered prior messages for the thread. */
1148
+ async getMessages(_args) {
1149
+ const limit = _args?.limit ?? this.topK;
1150
+ if (this.conversationId) {
1151
+ const page = await this.client.listTurns(this.conversationId, { limit });
1152
+ return page.turns.map((t) => ({
1153
+ role: this.normaliseRole(t.turn_role),
1154
+ content: t.content,
1155
+ threadId: this.conversationId
1156
+ }));
1157
+ }
1158
+ const resp = await this.client.recall({
1159
+ agentId: this.agentId,
1160
+ topK: limit,
1161
+ memoryType: "episodic"
1162
+ });
1163
+ const reversed = [...resp.results].reverse();
1164
+ return reversed.map((r) => ({
1165
+ role: this.normaliseRole(
1166
+ (r.metadata ?? {})["role"]
1167
+ ),
1168
+ content: r.content
1169
+ }));
1170
+ }
1171
+ /** Mastra contract: persist one message. */
1172
+ async addMessage(message) {
1173
+ const memory = await this.client.store({
1174
+ agentId: this.agentId,
1175
+ content: message.content,
1176
+ memoryType: "episodic",
1177
+ metadata: { role: message.role },
1178
+ relationships: []
1179
+ });
1180
+ if (this.conversationId) {
1181
+ await this.client.addTurn(this.conversationId, {
1182
+ memoryId: memory.id,
1183
+ turnRole: message.role
1184
+ });
1185
+ }
1186
+ }
1187
+ /**
1188
+ * Mastra `clear()` — deliberate no-op. Z3rno keeps the source of
1189
+ * truth and recall is already scoped per conversation; flushing
1190
+ * the thread would risk losing audit-relevant history.
1191
+ */
1192
+ async clear() {
1193
+ return;
1194
+ }
1195
+ normaliseRole(raw) {
1196
+ switch (raw) {
1197
+ case "assistant":
1198
+ case "ai":
1199
+ return "assistant";
1200
+ case "system":
1201
+ return "system";
1202
+ case "tool":
1203
+ return "tool";
1204
+ default:
1205
+ return "user";
1206
+ }
1207
+ }
1208
+ };
1209
+
1210
+ 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
1211
  //# sourceMappingURL=index.js.map
980
1212
  //# sourceMappingURL=index.js.map