@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 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,50 @@ 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
+ async listTurns(conversationId, params) {
930
+ const query = new URLSearchParams();
931
+ if (params?.afterTurn !== void 0)
932
+ query.set("after_turn", String(params.afterTurn));
933
+ query.set("limit", String(params?.limit ?? 50));
934
+ const path = `/v1/conversations/${conversationId}/turns?${query.toString()}`;
935
+ const resp = await this.request("GET", path);
936
+ return TurnListResponse.parse(resp);
937
+ }
863
938
  // --- HTTP layer ---
864
939
  async request(method, path, body) {
865
940
  let lastError;
@@ -977,10 +1052,160 @@ var Z3rnoClient = class {
977
1052
  }
978
1053
  };
979
1054
 
1055
+ // src/integrations/vercel-ai.ts
1056
+ var Z3rnoVercelMemory = class {
1057
+ client;
1058
+ agentId;
1059
+ conversationId;
1060
+ topK;
1061
+ constructor(options) {
1062
+ this.client = options.client;
1063
+ this.agentId = options.agentId;
1064
+ this.conversationId = options.conversationId;
1065
+ this.topK = options.topK ?? 50;
1066
+ }
1067
+ async messages() {
1068
+ if (this.conversationId) {
1069
+ const page = await this.client.listTurns(this.conversationId, {
1070
+ limit: this.topK
1071
+ });
1072
+ return page.turns.map((t) => ({
1073
+ role: this.normaliseRole(t.turn_role),
1074
+ content: t.content
1075
+ }));
1076
+ }
1077
+ const resp = await this.client.recall({
1078
+ agentId: this.agentId,
1079
+ topK: this.topK,
1080
+ memoryType: "episodic"
1081
+ });
1082
+ const reversed = [...resp.results].reverse();
1083
+ return reversed.map((r) => ({
1084
+ role: this.normaliseRole(
1085
+ (r.metadata ?? {})["role"]
1086
+ ),
1087
+ content: r.content
1088
+ }));
1089
+ }
1090
+ async appendUserMessage(content) {
1091
+ await this.append(content, "user");
1092
+ }
1093
+ async appendAssistantMessage(content) {
1094
+ await this.append(content, "assistant");
1095
+ }
1096
+ async appendToolMessage(content) {
1097
+ await this.append(content, "tool");
1098
+ }
1099
+ async append(content, role) {
1100
+ const memory = await this.client.store({
1101
+ agentId: this.agentId,
1102
+ content,
1103
+ memoryType: "episodic",
1104
+ metadata: { role },
1105
+ relationships: []
1106
+ });
1107
+ if (this.conversationId) {
1108
+ await this.client.addTurn(this.conversationId, {
1109
+ memoryId: memory.id,
1110
+ turnRole: role
1111
+ });
1112
+ }
1113
+ }
1114
+ normaliseRole(raw) {
1115
+ switch (raw) {
1116
+ case "assistant":
1117
+ case "ai":
1118
+ return "assistant";
1119
+ case "system":
1120
+ return "system";
1121
+ case "tool":
1122
+ return "tool";
1123
+ default:
1124
+ return "user";
1125
+ }
1126
+ }
1127
+ };
1128
+
1129
+ // src/integrations/mastra.ts
1130
+ var Z3rnoMastraMemory = class {
1131
+ client;
1132
+ agentId;
1133
+ conversationId;
1134
+ topK;
1135
+ constructor(options) {
1136
+ this.client = options.client;
1137
+ this.agentId = options.agentId;
1138
+ this.conversationId = options.conversationId;
1139
+ this.topK = options.topK ?? 50;
1140
+ }
1141
+ /** Mastra contract: return ordered prior messages for the thread. */
1142
+ async getMessages(_args) {
1143
+ const limit = _args?.limit ?? this.topK;
1144
+ if (this.conversationId) {
1145
+ const page = await this.client.listTurns(this.conversationId, { limit });
1146
+ return page.turns.map((t) => ({
1147
+ role: this.normaliseRole(t.turn_role),
1148
+ content: t.content,
1149
+ threadId: this.conversationId
1150
+ }));
1151
+ }
1152
+ const resp = await this.client.recall({
1153
+ agentId: this.agentId,
1154
+ topK: limit,
1155
+ memoryType: "episodic"
1156
+ });
1157
+ const reversed = [...resp.results].reverse();
1158
+ return reversed.map((r) => ({
1159
+ role: this.normaliseRole(
1160
+ (r.metadata ?? {})["role"]
1161
+ ),
1162
+ content: r.content
1163
+ }));
1164
+ }
1165
+ /** Mastra contract: persist one message. */
1166
+ async addMessage(message) {
1167
+ const memory = await this.client.store({
1168
+ agentId: this.agentId,
1169
+ content: message.content,
1170
+ memoryType: "episodic",
1171
+ metadata: { role: message.role },
1172
+ relationships: []
1173
+ });
1174
+ if (this.conversationId) {
1175
+ await this.client.addTurn(this.conversationId, {
1176
+ memoryId: memory.id,
1177
+ turnRole: message.role
1178
+ });
1179
+ }
1180
+ }
1181
+ /**
1182
+ * Mastra `clear()` — deliberate no-op. Z3rno keeps the source of
1183
+ * truth and recall is already scoped per conversation; flushing
1184
+ * the thread would risk losing audit-relevant history.
1185
+ */
1186
+ async clear() {
1187
+ return;
1188
+ }
1189
+ normaliseRole(raw) {
1190
+ switch (raw) {
1191
+ case "assistant":
1192
+ case "ai":
1193
+ return "assistant";
1194
+ case "system":
1195
+ return "system";
1196
+ case "tool":
1197
+ return "tool";
1198
+ default:
1199
+ return "user";
1200
+ }
1201
+ }
1202
+ };
1203
+
980
1204
  exports.AuditEntry = AuditEntry;
981
1205
  exports.AuditPageResponse = AuditPageResponse;
982
1206
  exports.AuthenticationError = AuthenticationError;
983
1207
  exports.BatchStoreResponse = BatchStoreResponse;
1208
+ exports.ConversationResponse = ConversationResponse;
984
1209
  exports.DistillJobResponse = DistillJobResponse;
985
1210
  exports.DistillJobStatusResponse = DistillJobStatusResponse;
986
1211
  exports.EndSessionResponse = EndSessionResponse;
@@ -1001,10 +1226,15 @@ exports.RelationshipType = RelationshipType;
1001
1226
  exports.RetrievalStrategy = RetrievalStrategy;
1002
1227
  exports.ServerError = ServerError;
1003
1228
  exports.SessionResponse = SessionResponse;
1229
+ exports.TurnAddResponse = TurnAddResponse;
1230
+ exports.TurnListResponse = TurnListResponse;
1231
+ exports.TurnResponse = TurnResponse;
1004
1232
  exports.ValidationError = ValidationError;
1005
1233
  exports.Z3rnoClient = Z3rnoClient;
1006
1234
  exports.Z3rnoConnectionError = Z3rnoConnectionError;
1007
1235
  exports.Z3rnoError = Z3rnoError;
1236
+ exports.Z3rnoMastraMemory = Z3rnoMastraMemory;
1008
1237
  exports.Z3rnoTimeoutError = Z3rnoTimeoutError;
1238
+ exports.Z3rnoVercelMemory = Z3rnoVercelMemory;
1009
1239
  //# sourceMappingURL=index.cjs.map
1010
1240
  //# sourceMappingURL=index.cjs.map