@ai-matrx/agents 0.11.4 → 0.12.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.1
4
+
5
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
6
+ `git diff npm/matrx-agents/v0.12.0..npm/matrx-agents/v0.12.1 -- apps/shared/matrx-agents`).
7
+ No source changes intended and no consumer action required.
8
+
9
+ ## 0.12.0
10
+
11
+ Ships createMatrxTransferActions and createMatrxTransferPorts for the standard Matrx destination catalog. Current-draft serialization, eligibility, identity checks, attachment deduplication and partial-save receipts live in the package.
12
+
13
+ ### Consumer action
14
+
15
+ Bind createMatrxTransferPorts to existing Matrx service/opening ports once at the authenticated application provider, then register createMatrxTransferActions with the shared capabilities. Pages supply only their source or mounted surface. Pass the capture identity when opening an assistant with initial text resources; never put captured source into the human composer or auto-run it.
16
+
3
17
  ## 0.11.4
4
18
 
5
19
  Automatic changed-only republish (docs/metadata drift since the last tag — see
@@ -20,10 +20,72 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // content-transfer/index.ts
21
21
  var content_transfer_exports = {};
22
22
  __export(content_transfer_exports, {
23
- createMatrxContentTransferAdapter: () => createMatrxContentTransferAdapter
23
+ createMatrxContentTransferAdapter: () => createMatrxContentTransferAdapter,
24
+ createMatrxTransferActions: () => createMatrxTransferActions,
25
+ createMatrxTransferPorts: () => createMatrxTransferPorts
24
26
  });
25
27
  module.exports = __toCommonJS(content_transfer_exports);
28
+
29
+ // content-transfer/destinations.ts
26
30
  var import_content_transfer = require("@ai-matrx/kit/content-transfer");
31
+ var DESTINATIONS = [
32
+ { key: "notes", label: "Save to Notes", hint: "Choose a note or create one", group: "save" },
33
+ { key: "scratch", label: "Save to Scratch", hint: "Capture a new note immediately", group: "save" },
34
+ { key: "document", label: "Create a document", hint: "A native Matrx document", group: "save" },
35
+ { key: "workbook", label: "Create a workbook", hint: "Selected columns and rows in Matrx Sheets", group: "save" },
36
+ { key: "task", label: "Create a task", hint: "Review the title and content before saving", group: "save" },
37
+ { key: "attach", label: "Save and attach to a task or project", hint: "Save a note, then choose where it belongs", group: "save" },
38
+ { key: "code", label: "Save to Code", hint: "Choose a file and language", group: "save" },
39
+ { key: "chat", label: "Open in a new chat", hint: "Attach this content and write your request", group: "chat" },
40
+ { key: "assistant", label: "Open an assistant window", hint: "Keep this page open while you work", group: "chat" },
41
+ { key: "tools", label: "Use with connected tools", hint: "Open an assistant and choose tools or MCPs", group: "chat" }
42
+ ];
43
+ function createMatrxTransferActions(ports) {
44
+ return DESTINATIONS.flatMap(({ key, ...presentation }) => {
45
+ const port = ports[key];
46
+ if (!port) return [];
47
+ const supports = (snapshot, draft) => key !== "workbook" || (draft?.payload ?? snapshot.payload).kind === "rows";
48
+ return [{
49
+ id: `matrx:${key}`,
50
+ ...presentation,
51
+ prepared: true,
52
+ supports,
53
+ async run({ snapshot, draft, signal }) {
54
+ signal.throwIfAborted();
55
+ if (draft.snapshotId !== snapshot.id || draft.sourceId !== snapshot.sourceId || draft.sourceRevision !== snapshot.revision)
56
+ throw new Error("The prepared content does not belong to this source revision. Refresh Alchemy before continuing.");
57
+ if (!supports(snapshot, draft))
58
+ throw new Error(`${presentation.label} is unavailable for this prepared content.`);
59
+ const current = draft;
60
+ const payload = current.payload;
61
+ const columns = payload.kind === "rows" ? payload.columns.filter((column) => column.visible && column.exportable !== false && column.classification !== "secret" && column.classification !== "credential") : [];
62
+ const table = payload.kind === "rows" ? {
63
+ name: snapshot.label,
64
+ headers: columns.map((column) => column.label),
65
+ rows: payload.rows.map((row) => columns.map((column) => {
66
+ const value = (0, import_content_transfer.readTransferCell)(row, column);
67
+ return value == null ? "" : typeof value === "object" ? JSON.stringify(value) : String(value);
68
+ }))
69
+ } : void 0;
70
+ const content = {
71
+ label: snapshot.label,
72
+ snapshot,
73
+ draft: current,
74
+ payload,
75
+ markdown: (0, import_content_transfer.serialize)(current, "markdown").plainText,
76
+ plainText: (0, import_content_transfer.serialize)(current, "plain").plainText,
77
+ signal,
78
+ ...table ? { table } : {}
79
+ };
80
+ signal.throwIfAborted();
81
+ return port(content);
82
+ }
83
+ }];
84
+ });
85
+ }
86
+
87
+ // content-transfer/index.ts
88
+ var import_content_transfer2 = require("@ai-matrx/kit/content-transfer");
27
89
 
28
90
  // mandates/keys.generated.ts
29
91
  var MANDATE_KEYS = {
@@ -1042,6 +1104,109 @@ async function rejoinRuntimeOperation(transport, requestId, options = {}) {
1042
1104
  return toRunHandle(response, options);
1043
1105
  }
1044
1106
 
1107
+ // content-transfer/destination-ports.ts
1108
+ var success = (message, target) => ({ status: "success", delivered: "action", mimeTypes: [], message, ...target ? { target } : {} });
1109
+ var active = (bindings, content, expected) => {
1110
+ content.signal.throwIfAborted();
1111
+ const identity = bindings.getIdentity();
1112
+ if (!identity.userId || !identity.organizationId) throw new Error("Sign in and select an organization to use Matrx destinations.");
1113
+ if (expected && (identity.userId !== expected.userId || identity.organizationId !== expected.organizationId)) throw new Error("Your account or organization changed while this action was being prepared.");
1114
+ return identity;
1115
+ };
1116
+ var receipt = (bindings, content, identity, target, message) => {
1117
+ try {
1118
+ active(bindings, content, identity);
1119
+ return success(message, target);
1120
+ } catch {
1121
+ return { status: "error", code: "saved-before-context-change", retryable: false, target, message: `${target.label} was saved. Your account or organization changed before it could be opened.` };
1122
+ }
1123
+ };
1124
+ var failed = (kind, content, result) => ({
1125
+ status: "error",
1126
+ code: `${kind}-save-failed`,
1127
+ retryable: false,
1128
+ message: result.error ?? `${kind === "document" ? "Document" : "Workbook"} could not be saved.`,
1129
+ ...result.id ? { target: { kind, id: result.id, label: content.label, ...result.href ? { href: result.href } : {} } } : {}
1130
+ });
1131
+ function createMatrxTransferPorts(bindings) {
1132
+ const attached = /* @__PURE__ */ new Map();
1133
+ return {
1134
+ notes: async (content) => {
1135
+ const identity = active(bindings, content);
1136
+ await bindings.openNotes(content);
1137
+ active(bindings, content, identity);
1138
+ return success("Notes editor opened. Choose where to save this content.");
1139
+ },
1140
+ scratch: async (content) => {
1141
+ const identity = active(bindings, content);
1142
+ const target = await bindings.saveNote(content, "Scratch");
1143
+ return receipt(bindings, content, identity, target, "Saved to Scratch.");
1144
+ },
1145
+ document: async (content) => {
1146
+ const identity = active(bindings, content);
1147
+ const result = await bindings.saveDocument(content);
1148
+ if (!result.ok || !result.id || !result.href) return failed("document", content, result);
1149
+ return receipt(bindings, content, identity, { kind: "document", id: result.id, label: content.label, href: result.href }, "Saved as a Matrx document.");
1150
+ },
1151
+ workbook: async (content) => {
1152
+ const identity = active(bindings, content);
1153
+ if (!content.table) throw new Error("A workbook requires tabular content.");
1154
+ const result = await bindings.saveWorkbook(content);
1155
+ if (!result.ok || !result.id || !result.href) return failed("workbook", content, result);
1156
+ return receipt(bindings, content, identity, { kind: "workbook", id: result.id, label: content.label, href: result.href }, "Saved as a Matrx workbook.");
1157
+ },
1158
+ task: async (content) => {
1159
+ const identity = active(bindings, content);
1160
+ await bindings.openTask(content);
1161
+ active(bindings, content, identity);
1162
+ return success("Task editor opened with this content. Review and save the task.");
1163
+ },
1164
+ attach: async (content) => {
1165
+ const identity = active(bindings, content);
1166
+ const key = JSON.stringify([identity.userId, identity.organizationId, content.draft.sourceId, content.draft.sourceRevision, content.draft.revision, content.label, content.markdown]);
1167
+ let pending = attached.get(key);
1168
+ if (!pending) {
1169
+ pending = bindings.saveNote(content, "Alchemy");
1170
+ attached.set(key, pending);
1171
+ pending.catch(() => attached.delete(key));
1172
+ }
1173
+ const target = await pending;
1174
+ try {
1175
+ active(bindings, content, identity);
1176
+ await bindings.openAttachment(target);
1177
+ active(bindings, content, identity);
1178
+ return success("Note saved. Choose a task or project in the attachment window to finish attaching it.", target);
1179
+ } catch {
1180
+ return { status: "error", code: "note-saved-chooser-not-opened", retryable: false, target, message: "Note saved, but the attachment window did not open. Reopen this note to attach it; do not save another copy." };
1181
+ }
1182
+ },
1183
+ code: async (content) => {
1184
+ const identity = active(bindings, content);
1185
+ await bindings.openCode(content);
1186
+ active(bindings, content, identity);
1187
+ return success("Code editor opened. Choose the file name and language before saving.");
1188
+ },
1189
+ chat: async (content) => {
1190
+ const identity = active(bindings, content);
1191
+ await bindings.openChat(content, "chat", identity);
1192
+ active(bindings, content, identity);
1193
+ return success("New chat opened with this content attached. Write your request when ready.");
1194
+ },
1195
+ assistant: async (content) => {
1196
+ const identity = active(bindings, content);
1197
+ await bindings.openChat(content, "assistant", identity);
1198
+ active(bindings, content, identity);
1199
+ return success("Assistant window opened with this content attached. Nothing has been sent yet.");
1200
+ },
1201
+ tools: async (content) => {
1202
+ const identity = active(bindings, content);
1203
+ await bindings.openChat(content, "tools", identity);
1204
+ active(bindings, content, identity);
1205
+ return success("Assistant opened with this content attached. Choose Tools in Chat Options to use your connected MCPs.");
1206
+ }
1207
+ };
1208
+ }
1209
+
1045
1210
  // content-transfer/index.ts
1046
1211
  var SupersededRunError = class extends Error {
1047
1212
  constructor() {
@@ -1096,8 +1261,8 @@ function responseMessageId(metadata) {
1096
1261
  return typeof value === "string" && value.length > 0 ? value : null;
1097
1262
  }
1098
1263
  function draftFromAssistant(source, text, identity) {
1099
- const edited = (0, import_content_transfer.editDraft)(source, { kind: "markdown", text });
1100
- const reducedBy = (0, import_content_transfer.serialize)(source, "markdown").plainText.length - text.length;
1264
+ const edited = (0, import_content_transfer2.editDraft)(source, { kind: "markdown", text });
1265
+ const reducedBy = (0, import_content_transfer2.serialize)(source, "markdown").plainText.length - text.length;
1101
1266
  return deepFreeze({
1102
1267
  ...edited,
1103
1268
  manuallyEdited: source.manuallyEdited,
@@ -1314,7 +1479,7 @@ function createMatrxContentTransferAdapter(options) {
1314
1479
  executionId: null,
1315
1480
  status: "starting"
1316
1481
  });
1317
- const preparedContent = (0, import_content_transfer.serialize)(input.draft, "markdown").plainText;
1482
+ const preparedContent = (0, import_content_transfer2.serialize)(input.draft, "markdown").plainText;
1318
1483
  let identity = null;
1319
1484
  try {
1320
1485
  const handle = await startMandateRun(