@z3rno/sdk 0.3.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 +374 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +509 -1
- package/dist/index.d.ts +509 -1
- package/dist/index.js +363 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -341,6 +341,112 @@ var EndSessionResponse = z.object({
|
|
|
341
341
|
/** Number of memories created during the session. */
|
|
342
342
|
memory_count: z.number()
|
|
343
343
|
});
|
|
344
|
+
var IngestJobResponse = z.object({
|
|
345
|
+
job_id: z.string(),
|
|
346
|
+
kind: z.string(),
|
|
347
|
+
status: z.string(),
|
|
348
|
+
dataset_id: z.string().nullable().optional(),
|
|
349
|
+
enqueued_at: z.string()
|
|
350
|
+
});
|
|
351
|
+
var IngestJobStatusResponse = z.object({
|
|
352
|
+
job_id: z.string(),
|
|
353
|
+
agent_id: z.string(),
|
|
354
|
+
dataset_id: z.string().nullable().optional(),
|
|
355
|
+
kind: z.string(),
|
|
356
|
+
status: z.string(),
|
|
357
|
+
source_uri: z.string().nullable().optional(),
|
|
358
|
+
content_type: z.string().nullable().optional(),
|
|
359
|
+
filename: z.string().nullable().optional(),
|
|
360
|
+
file_size: z.number().nullable().optional(),
|
|
361
|
+
memory_ids: z.array(z.string()).default([]),
|
|
362
|
+
memos_written: z.number().default(0),
|
|
363
|
+
distill_job_id: z.string().nullable().optional(),
|
|
364
|
+
codegraph_memos_written: z.number().default(0),
|
|
365
|
+
codegraph_edges_written: z.number().default(0),
|
|
366
|
+
error: z.string().nullable().optional(),
|
|
367
|
+
warnings: z.array(z.record(z.unknown())).default([]),
|
|
368
|
+
started_at: z.string().nullable().optional(),
|
|
369
|
+
completed_at: z.string().nullable().optional(),
|
|
370
|
+
created_at: z.string().nullable().optional(),
|
|
371
|
+
updated_at: z.string().nullable().optional()
|
|
372
|
+
});
|
|
373
|
+
var DistillJobResponse = z.object({
|
|
374
|
+
job_id: z.string(),
|
|
375
|
+
status: z.string(),
|
|
376
|
+
memory_ids: z.array(z.string()),
|
|
377
|
+
enqueued_at: z.string()
|
|
378
|
+
});
|
|
379
|
+
var DistillJobStatusResponse = z.object({
|
|
380
|
+
job_id: z.string(),
|
|
381
|
+
agent_id: z.string(),
|
|
382
|
+
status: z.string(),
|
|
383
|
+
model: z.string(),
|
|
384
|
+
memory_ids: z.array(z.string()),
|
|
385
|
+
chunk_size: z.number(),
|
|
386
|
+
chunk_overlap: z.number(),
|
|
387
|
+
max_concurrency: z.number(),
|
|
388
|
+
chunks_total: z.number(),
|
|
389
|
+
chunks_failed: z.number(),
|
|
390
|
+
entities_extracted: z.number(),
|
|
391
|
+
relationships_extracted: z.number(),
|
|
392
|
+
memos_written: z.number(),
|
|
393
|
+
error: z.string().nullable().optional(),
|
|
394
|
+
started_at: z.string().nullable().optional(),
|
|
395
|
+
completed_at: z.string().nullable().optional(),
|
|
396
|
+
created_at: z.string().nullable().optional(),
|
|
397
|
+
updated_at: z.string().nullable().optional()
|
|
398
|
+
});
|
|
399
|
+
var RefineJobResponse = z.object({
|
|
400
|
+
job_id: z.string(),
|
|
401
|
+
status: z.string(),
|
|
402
|
+
dataset_id: z.string().nullable().optional(),
|
|
403
|
+
enqueued_at: z.string()
|
|
404
|
+
});
|
|
405
|
+
var RefineJobStatusResponse = z.object({
|
|
406
|
+
job_id: z.string(),
|
|
407
|
+
status: z.string(),
|
|
408
|
+
dataset_id: z.string().nullable().optional(),
|
|
409
|
+
trigger: z.string(),
|
|
410
|
+
memos_scanned: z.number().default(0),
|
|
411
|
+
memos_deduped: z.number().default(0),
|
|
412
|
+
edges_reweighted: z.number().default(0),
|
|
413
|
+
edges_pruned: z.number().default(0),
|
|
414
|
+
feedback_drained: z.number().default(0),
|
|
415
|
+
job_metadata: z.record(z.unknown()).default({}),
|
|
416
|
+
error: z.string().nullable().optional(),
|
|
417
|
+
started_at: z.string().nullable().optional(),
|
|
418
|
+
completed_at: z.string().nullable().optional(),
|
|
419
|
+
created_at: z.string().nullable().optional(),
|
|
420
|
+
updated_at: z.string().nullable().optional()
|
|
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
|
+
});
|
|
344
450
|
|
|
345
451
|
// src/client.ts
|
|
346
452
|
var Z3rnoClient = class {
|
|
@@ -477,6 +583,9 @@ var Z3rnoClient = class {
|
|
|
477
583
|
strategy: params.strategy ?? "AUTO",
|
|
478
584
|
rerank: params.rerank ?? false
|
|
479
585
|
};
|
|
586
|
+
if (params.conversationId) {
|
|
587
|
+
body.conversation_id = params.conversationId;
|
|
588
|
+
}
|
|
480
589
|
const resp = await this.request("POST", "/v1/memories/recall", body);
|
|
481
590
|
return RecallResponse.parse(resp);
|
|
482
591
|
}
|
|
@@ -720,6 +829,110 @@ var Z3rnoClient = class {
|
|
|
720
829
|
const resp = await this.request("GET", path);
|
|
721
830
|
return AuditPageResponse.parse(resp);
|
|
722
831
|
}
|
|
832
|
+
// --- Forge: ingest / distill / refine -------------------------------
|
|
833
|
+
//
|
|
834
|
+
// Wrap the server's POST /v1/ingest, /v1/distill, /v1/refine plus the
|
|
835
|
+
// matching GET status endpoints. The server gates each verb behind an
|
|
836
|
+
// operator flag (INGEST_ENABLED / DISTILL_ENABLED / REFINE_ENABLED);
|
|
837
|
+
// when off, these methods throw NotFoundError.
|
|
838
|
+
async ingestText(params) {
|
|
839
|
+
const body = {
|
|
840
|
+
kind: "text",
|
|
841
|
+
agent_id: params.agentId,
|
|
842
|
+
text: params.text
|
|
843
|
+
};
|
|
844
|
+
if (params.datasetId) body.dataset_id = params.datasetId;
|
|
845
|
+
const resp = await this.request("POST", "/v1/ingest", body);
|
|
846
|
+
return IngestJobResponse.parse(resp);
|
|
847
|
+
}
|
|
848
|
+
async ingestUrl(params) {
|
|
849
|
+
const body = {
|
|
850
|
+
kind: "url",
|
|
851
|
+
agent_id: params.agentId,
|
|
852
|
+
url: params.url
|
|
853
|
+
};
|
|
854
|
+
if (params.datasetId) body.dataset_id = params.datasetId;
|
|
855
|
+
const resp = await this.request("POST", "/v1/ingest", body);
|
|
856
|
+
return IngestJobResponse.parse(resp);
|
|
857
|
+
}
|
|
858
|
+
async getIngestStatus(jobId) {
|
|
859
|
+
const resp = await this.request("GET", `/v1/ingest/${jobId}`);
|
|
860
|
+
return IngestJobStatusResponse.parse(resp);
|
|
861
|
+
}
|
|
862
|
+
async distill(params) {
|
|
863
|
+
const body = {
|
|
864
|
+
agent_id: params.agentId,
|
|
865
|
+
memory_ids: params.memoryIds,
|
|
866
|
+
include_summary: params.includeSummary ?? true
|
|
867
|
+
};
|
|
868
|
+
if (params.chunkSize !== void 0) body.chunk_size = params.chunkSize;
|
|
869
|
+
if (params.chunkOverlap !== void 0)
|
|
870
|
+
body.chunk_overlap = params.chunkOverlap;
|
|
871
|
+
if (params.maxConcurrency !== void 0)
|
|
872
|
+
body.max_concurrency = params.maxConcurrency;
|
|
873
|
+
if (params.summaryStyle !== void 0)
|
|
874
|
+
body.summary_style = params.summaryStyle;
|
|
875
|
+
const resp = await this.request("POST", "/v1/distill", body);
|
|
876
|
+
return DistillJobResponse.parse(resp);
|
|
877
|
+
}
|
|
878
|
+
async getDistillStatus(jobId) {
|
|
879
|
+
const resp = await this.request("GET", `/v1/distill/${jobId}`);
|
|
880
|
+
return DistillJobStatusResponse.parse(resp);
|
|
881
|
+
}
|
|
882
|
+
async refine(params) {
|
|
883
|
+
const body = {};
|
|
884
|
+
if (params?.datasetId) body.dataset_id = params.datasetId;
|
|
885
|
+
const resp = await this.request("POST", "/v1/refine", body);
|
|
886
|
+
return RefineJobResponse.parse(resp);
|
|
887
|
+
}
|
|
888
|
+
async getRefineStatus(jobId) {
|
|
889
|
+
const resp = await this.request("GET", `/v1/refine/${jobId}`);
|
|
890
|
+
return RefineJobStatusResponse.parse(resp);
|
|
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
|
+
}
|
|
723
936
|
// --- HTTP layer ---
|
|
724
937
|
async request(method, path, body) {
|
|
725
938
|
let lastError;
|
|
@@ -837,6 +1050,155 @@ var Z3rnoClient = class {
|
|
|
837
1050
|
}
|
|
838
1051
|
};
|
|
839
1052
|
|
|
840
|
-
|
|
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 };
|
|
841
1203
|
//# sourceMappingURL=index.js.map
|
|
842
1204
|
//# sourceMappingURL=index.js.map
|