@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.
@@ -1,8 +1,58 @@
1
1
  import { B as MatrxTransport, w as MatrxRuntimeOperationEvent, v as MatrxRuntimeExecutionStatus, d as MatrxCancelResponse } from '../operations--f5ko9Su.cjs';
2
- import { Snapshot, Draft } from '@ai-matrx/kit/content-transfer';
2
+ import { PageAction, Payload, Snapshot, Draft, TransferOutcome, TransferTarget } from '@ai-matrx/kit/content-transfer';
3
3
  import { MatrxStreamEnvelope } from '../stream/ndjson.cjs';
4
4
  import '../stream/sse.cjs';
5
5
 
6
+ /** Bind once in a host; every menu and declared surface inherits these actions. */
7
+ type MatrxTransferDestination = "notes" | "scratch" | "document" | "workbook" | "task" | "attach" | "chat" | "assistant" | "tools" | "code";
8
+ interface MatrxTransferContent {
9
+ label: string;
10
+ markdown: string;
11
+ plainText: string;
12
+ payload: Payload;
13
+ snapshot: Snapshot;
14
+ draft: Draft;
15
+ table?: {
16
+ name: string;
17
+ headers: string[];
18
+ rows: string[][];
19
+ };
20
+ signal: AbortSignal;
21
+ }
22
+ type MatrxTransferPorts = Partial<Record<MatrxTransferDestination, (content: MatrxTransferContent) => Promise<TransferOutcome>>>;
23
+ type MatrxTransferAction = PageAction & {
24
+ group: "save" | "chat";
25
+ hint: string;
26
+ /** Only these actions are offered for a manually prepared revision. */
27
+ prepared: true;
28
+ };
29
+ /** Serializes the captured CURRENT revision, never re-reads the host's source. */
30
+ declare function createMatrxTransferActions(ports: MatrxTransferPorts): MatrxTransferAction[];
31
+
32
+ type MatrxTransferIdentity = {
33
+ userId: string;
34
+ organizationId: string;
35
+ };
36
+ type SaveResult = {
37
+ ok: boolean;
38
+ id?: string;
39
+ href?: string;
40
+ error?: string;
41
+ };
42
+ interface MatrxTransferBindings {
43
+ getIdentity(): MatrxTransferIdentity;
44
+ saveNote(content: MatrxTransferContent, folder: string): Promise<TransferTarget>;
45
+ saveDocument(content: MatrxTransferContent): Promise<SaveResult>;
46
+ saveWorkbook(content: MatrxTransferContent): Promise<SaveResult>;
47
+ openNotes(content: MatrxTransferContent): void | Promise<void>;
48
+ openTask(content: MatrxTransferContent): void | Promise<void>;
49
+ openCode(content: MatrxTransferContent): void | Promise<void>;
50
+ openAttachment(target: TransferTarget): void | Promise<void>;
51
+ openChat(content: MatrxTransferContent, mode: "chat" | "assistant" | "tools", identity: MatrxTransferIdentity): void | Promise<void>;
52
+ }
53
+ /** Portable workflow and failure semantics; hosts bind only their concrete services and UI openers. */
54
+ declare function createMatrxTransferPorts(bindings: MatrxTransferBindings): Required<MatrxTransferPorts>;
55
+
6
56
  type MatrxContentTransferStatus = "completed" | "failed" | "cancelled" | "detached" | "unavailable";
7
57
  interface MatrxContentTransferIdentity {
8
58
  requestId: string;
@@ -81,4 +131,4 @@ declare function createMatrxContentTransferAdapter(options: MatrxContentTransfer
81
131
  };
82
132
  type MatrxContentTransferAdapter = ReturnType<typeof createMatrxContentTransferAdapter>;
83
133
 
84
- export { type MatrxContentTransferAdapter, type MatrxContentTransferAdapterOptions, type MatrxContentTransferDbResponse, type MatrxContentTransferDbRow, type MatrxContentTransferIdentity, type MatrxContentTransferLaunchInput, type MatrxContentTransferProgress, type MatrxContentTransferQuery, type MatrxContentTransferResult, type MatrxContentTransferStatus, type MatrxContentTransferSupabase, createMatrxContentTransferAdapter };
134
+ export { type MatrxContentTransferAdapter, type MatrxContentTransferAdapterOptions, type MatrxContentTransferDbResponse, type MatrxContentTransferDbRow, type MatrxContentTransferIdentity, type MatrxContentTransferLaunchInput, type MatrxContentTransferProgress, type MatrxContentTransferQuery, type MatrxContentTransferResult, type MatrxContentTransferStatus, type MatrxContentTransferSupabase, type MatrxTransferAction, type MatrxTransferBindings, type MatrxTransferContent, type MatrxTransferDestination, type MatrxTransferIdentity, type MatrxTransferPorts, createMatrxContentTransferAdapter, createMatrxTransferActions, createMatrxTransferPorts };
@@ -1,8 +1,58 @@
1
1
  import { B as MatrxTransport, w as MatrxRuntimeOperationEvent, v as MatrxRuntimeExecutionStatus, d as MatrxCancelResponse } from '../operations-Dp4ut-ac.js';
2
- import { Snapshot, Draft } from '@ai-matrx/kit/content-transfer';
2
+ import { PageAction, Payload, Snapshot, Draft, TransferOutcome, TransferTarget } from '@ai-matrx/kit/content-transfer';
3
3
  import { MatrxStreamEnvelope } from '../stream/ndjson.js';
4
4
  import '../stream/sse.js';
5
5
 
6
+ /** Bind once in a host; every menu and declared surface inherits these actions. */
7
+ type MatrxTransferDestination = "notes" | "scratch" | "document" | "workbook" | "task" | "attach" | "chat" | "assistant" | "tools" | "code";
8
+ interface MatrxTransferContent {
9
+ label: string;
10
+ markdown: string;
11
+ plainText: string;
12
+ payload: Payload;
13
+ snapshot: Snapshot;
14
+ draft: Draft;
15
+ table?: {
16
+ name: string;
17
+ headers: string[];
18
+ rows: string[][];
19
+ };
20
+ signal: AbortSignal;
21
+ }
22
+ type MatrxTransferPorts = Partial<Record<MatrxTransferDestination, (content: MatrxTransferContent) => Promise<TransferOutcome>>>;
23
+ type MatrxTransferAction = PageAction & {
24
+ group: "save" | "chat";
25
+ hint: string;
26
+ /** Only these actions are offered for a manually prepared revision. */
27
+ prepared: true;
28
+ };
29
+ /** Serializes the captured CURRENT revision, never re-reads the host's source. */
30
+ declare function createMatrxTransferActions(ports: MatrxTransferPorts): MatrxTransferAction[];
31
+
32
+ type MatrxTransferIdentity = {
33
+ userId: string;
34
+ organizationId: string;
35
+ };
36
+ type SaveResult = {
37
+ ok: boolean;
38
+ id?: string;
39
+ href?: string;
40
+ error?: string;
41
+ };
42
+ interface MatrxTransferBindings {
43
+ getIdentity(): MatrxTransferIdentity;
44
+ saveNote(content: MatrxTransferContent, folder: string): Promise<TransferTarget>;
45
+ saveDocument(content: MatrxTransferContent): Promise<SaveResult>;
46
+ saveWorkbook(content: MatrxTransferContent): Promise<SaveResult>;
47
+ openNotes(content: MatrxTransferContent): void | Promise<void>;
48
+ openTask(content: MatrxTransferContent): void | Promise<void>;
49
+ openCode(content: MatrxTransferContent): void | Promise<void>;
50
+ openAttachment(target: TransferTarget): void | Promise<void>;
51
+ openChat(content: MatrxTransferContent, mode: "chat" | "assistant" | "tools", identity: MatrxTransferIdentity): void | Promise<void>;
52
+ }
53
+ /** Portable workflow and failure semantics; hosts bind only their concrete services and UI openers. */
54
+ declare function createMatrxTransferPorts(bindings: MatrxTransferBindings): Required<MatrxTransferPorts>;
55
+
6
56
  type MatrxContentTransferStatus = "completed" | "failed" | "cancelled" | "detached" | "unavailable";
7
57
  interface MatrxContentTransferIdentity {
8
58
  requestId: string;
@@ -81,4 +131,4 @@ declare function createMatrxContentTransferAdapter(options: MatrxContentTransfer
81
131
  };
82
132
  type MatrxContentTransferAdapter = ReturnType<typeof createMatrxContentTransferAdapter>;
83
133
 
84
- export { type MatrxContentTransferAdapter, type MatrxContentTransferAdapterOptions, type MatrxContentTransferDbResponse, type MatrxContentTransferDbRow, type MatrxContentTransferIdentity, type MatrxContentTransferLaunchInput, type MatrxContentTransferProgress, type MatrxContentTransferQuery, type MatrxContentTransferResult, type MatrxContentTransferStatus, type MatrxContentTransferSupabase, createMatrxContentTransferAdapter };
134
+ export { type MatrxContentTransferAdapter, type MatrxContentTransferAdapterOptions, type MatrxContentTransferDbResponse, type MatrxContentTransferDbRow, type MatrxContentTransferIdentity, type MatrxContentTransferLaunchInput, type MatrxContentTransferProgress, type MatrxContentTransferQuery, type MatrxContentTransferResult, type MatrxContentTransferStatus, type MatrxContentTransferSupabase, type MatrxTransferAction, type MatrxTransferBindings, type MatrxTransferContent, type MatrxTransferDestination, type MatrxTransferIdentity, type MatrxTransferPorts, createMatrxContentTransferAdapter, createMatrxTransferActions, createMatrxTransferPorts };
@@ -1,7 +1,68 @@
1
+ // content-transfer/destinations.ts
2
+ import {
3
+ readTransferCell,
4
+ serialize
5
+ } from "@ai-matrx/kit/content-transfer";
6
+ var DESTINATIONS = [
7
+ { key: "notes", label: "Save to Notes", hint: "Choose a note or create one", group: "save" },
8
+ { key: "scratch", label: "Save to Scratch", hint: "Capture a new note immediately", group: "save" },
9
+ { key: "document", label: "Create a document", hint: "A native Matrx document", group: "save" },
10
+ { key: "workbook", label: "Create a workbook", hint: "Selected columns and rows in Matrx Sheets", group: "save" },
11
+ { key: "task", label: "Create a task", hint: "Review the title and content before saving", group: "save" },
12
+ { key: "attach", label: "Save and attach to a task or project", hint: "Save a note, then choose where it belongs", group: "save" },
13
+ { key: "code", label: "Save to Code", hint: "Choose a file and language", group: "save" },
14
+ { key: "chat", label: "Open in a new chat", hint: "Attach this content and write your request", group: "chat" },
15
+ { key: "assistant", label: "Open an assistant window", hint: "Keep this page open while you work", group: "chat" },
16
+ { key: "tools", label: "Use with connected tools", hint: "Open an assistant and choose tools or MCPs", group: "chat" }
17
+ ];
18
+ function createMatrxTransferActions(ports) {
19
+ return DESTINATIONS.flatMap(({ key, ...presentation }) => {
20
+ const port = ports[key];
21
+ if (!port) return [];
22
+ const supports = (snapshot, draft) => key !== "workbook" || (draft?.payload ?? snapshot.payload).kind === "rows";
23
+ return [{
24
+ id: `matrx:${key}`,
25
+ ...presentation,
26
+ prepared: true,
27
+ supports,
28
+ async run({ snapshot, draft, signal }) {
29
+ signal.throwIfAborted();
30
+ if (draft.snapshotId !== snapshot.id || draft.sourceId !== snapshot.sourceId || draft.sourceRevision !== snapshot.revision)
31
+ throw new Error("The prepared content does not belong to this source revision. Refresh Alchemy before continuing.");
32
+ if (!supports(snapshot, draft))
33
+ throw new Error(`${presentation.label} is unavailable for this prepared content.`);
34
+ const current = draft;
35
+ const payload = current.payload;
36
+ const columns = payload.kind === "rows" ? payload.columns.filter((column) => column.visible && column.exportable !== false && column.classification !== "secret" && column.classification !== "credential") : [];
37
+ const table = payload.kind === "rows" ? {
38
+ name: snapshot.label,
39
+ headers: columns.map((column) => column.label),
40
+ rows: payload.rows.map((row) => columns.map((column) => {
41
+ const value = readTransferCell(row, column);
42
+ return value == null ? "" : typeof value === "object" ? JSON.stringify(value) : String(value);
43
+ }))
44
+ } : void 0;
45
+ const content = {
46
+ label: snapshot.label,
47
+ snapshot,
48
+ draft: current,
49
+ payload,
50
+ markdown: serialize(current, "markdown").plainText,
51
+ plainText: serialize(current, "plain").plainText,
52
+ signal,
53
+ ...table ? { table } : {}
54
+ };
55
+ signal.throwIfAborted();
56
+ return port(content);
57
+ }
58
+ }];
59
+ });
60
+ }
61
+
1
62
  // content-transfer/index.ts
2
63
  import {
3
64
  editDraft,
4
- serialize
65
+ serialize as serialize2
5
66
  } from "@ai-matrx/kit/content-transfer";
6
67
 
7
68
  // mandates/keys.generated.ts
@@ -1021,6 +1082,109 @@ async function rejoinRuntimeOperation(transport, requestId, options = {}) {
1021
1082
  return toRunHandle(response, options);
1022
1083
  }
1023
1084
 
1085
+ // content-transfer/destination-ports.ts
1086
+ var success = (message, target) => ({ status: "success", delivered: "action", mimeTypes: [], message, ...target ? { target } : {} });
1087
+ var active = (bindings, content, expected) => {
1088
+ content.signal.throwIfAborted();
1089
+ const identity = bindings.getIdentity();
1090
+ if (!identity.userId || !identity.organizationId) throw new Error("Sign in and select an organization to use Matrx destinations.");
1091
+ if (expected && (identity.userId !== expected.userId || identity.organizationId !== expected.organizationId)) throw new Error("Your account or organization changed while this action was being prepared.");
1092
+ return identity;
1093
+ };
1094
+ var receipt = (bindings, content, identity, target, message) => {
1095
+ try {
1096
+ active(bindings, content, identity);
1097
+ return success(message, target);
1098
+ } catch {
1099
+ 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.` };
1100
+ }
1101
+ };
1102
+ var failed = (kind, content, result) => ({
1103
+ status: "error",
1104
+ code: `${kind}-save-failed`,
1105
+ retryable: false,
1106
+ message: result.error ?? `${kind === "document" ? "Document" : "Workbook"} could not be saved.`,
1107
+ ...result.id ? { target: { kind, id: result.id, label: content.label, ...result.href ? { href: result.href } : {} } } : {}
1108
+ });
1109
+ function createMatrxTransferPorts(bindings) {
1110
+ const attached = /* @__PURE__ */ new Map();
1111
+ return {
1112
+ notes: async (content) => {
1113
+ const identity = active(bindings, content);
1114
+ await bindings.openNotes(content);
1115
+ active(bindings, content, identity);
1116
+ return success("Notes editor opened. Choose where to save this content.");
1117
+ },
1118
+ scratch: async (content) => {
1119
+ const identity = active(bindings, content);
1120
+ const target = await bindings.saveNote(content, "Scratch");
1121
+ return receipt(bindings, content, identity, target, "Saved to Scratch.");
1122
+ },
1123
+ document: async (content) => {
1124
+ const identity = active(bindings, content);
1125
+ const result = await bindings.saveDocument(content);
1126
+ if (!result.ok || !result.id || !result.href) return failed("document", content, result);
1127
+ return receipt(bindings, content, identity, { kind: "document", id: result.id, label: content.label, href: result.href }, "Saved as a Matrx document.");
1128
+ },
1129
+ workbook: async (content) => {
1130
+ const identity = active(bindings, content);
1131
+ if (!content.table) throw new Error("A workbook requires tabular content.");
1132
+ const result = await bindings.saveWorkbook(content);
1133
+ if (!result.ok || !result.id || !result.href) return failed("workbook", content, result);
1134
+ return receipt(bindings, content, identity, { kind: "workbook", id: result.id, label: content.label, href: result.href }, "Saved as a Matrx workbook.");
1135
+ },
1136
+ task: async (content) => {
1137
+ const identity = active(bindings, content);
1138
+ await bindings.openTask(content);
1139
+ active(bindings, content, identity);
1140
+ return success("Task editor opened with this content. Review and save the task.");
1141
+ },
1142
+ attach: async (content) => {
1143
+ const identity = active(bindings, content);
1144
+ const key = JSON.stringify([identity.userId, identity.organizationId, content.draft.sourceId, content.draft.sourceRevision, content.draft.revision, content.label, content.markdown]);
1145
+ let pending = attached.get(key);
1146
+ if (!pending) {
1147
+ pending = bindings.saveNote(content, "Alchemy");
1148
+ attached.set(key, pending);
1149
+ pending.catch(() => attached.delete(key));
1150
+ }
1151
+ const target = await pending;
1152
+ try {
1153
+ active(bindings, content, identity);
1154
+ await bindings.openAttachment(target);
1155
+ active(bindings, content, identity);
1156
+ return success("Note saved. Choose a task or project in the attachment window to finish attaching it.", target);
1157
+ } catch {
1158
+ 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." };
1159
+ }
1160
+ },
1161
+ code: async (content) => {
1162
+ const identity = active(bindings, content);
1163
+ await bindings.openCode(content);
1164
+ active(bindings, content, identity);
1165
+ return success("Code editor opened. Choose the file name and language before saving.");
1166
+ },
1167
+ chat: async (content) => {
1168
+ const identity = active(bindings, content);
1169
+ await bindings.openChat(content, "chat", identity);
1170
+ active(bindings, content, identity);
1171
+ return success("New chat opened with this content attached. Write your request when ready.");
1172
+ },
1173
+ assistant: async (content) => {
1174
+ const identity = active(bindings, content);
1175
+ await bindings.openChat(content, "assistant", identity);
1176
+ active(bindings, content, identity);
1177
+ return success("Assistant window opened with this content attached. Nothing has been sent yet.");
1178
+ },
1179
+ tools: async (content) => {
1180
+ const identity = active(bindings, content);
1181
+ await bindings.openChat(content, "tools", identity);
1182
+ active(bindings, content, identity);
1183
+ return success("Assistant opened with this content attached. Choose Tools in Chat Options to use your connected MCPs.");
1184
+ }
1185
+ };
1186
+ }
1187
+
1024
1188
  // content-transfer/index.ts
1025
1189
  var SupersededRunError = class extends Error {
1026
1190
  constructor() {
@@ -1076,7 +1240,7 @@ function responseMessageId(metadata) {
1076
1240
  }
1077
1241
  function draftFromAssistant(source, text, identity) {
1078
1242
  const edited = editDraft(source, { kind: "markdown", text });
1079
- const reducedBy = serialize(source, "markdown").plainText.length - text.length;
1243
+ const reducedBy = serialize2(source, "markdown").plainText.length - text.length;
1080
1244
  return deepFreeze({
1081
1245
  ...edited,
1082
1246
  manuallyEdited: source.manuallyEdited,
@@ -1293,7 +1457,7 @@ function createMatrxContentTransferAdapter(options) {
1293
1457
  executionId: null,
1294
1458
  status: "starting"
1295
1459
  });
1296
- const preparedContent = serialize(input.draft, "markdown").plainText;
1460
+ const preparedContent = serialize2(input.draft, "markdown").plainText;
1297
1461
  let identity = null;
1298
1462
  try {
1299
1463
  const handle = await startMandateRun(
@@ -1407,6 +1571,8 @@ function createMatrxContentTransferAdapter(options) {
1407
1571
  };
1408
1572
  }
1409
1573
  export {
1410
- createMatrxContentTransferAdapter
1574
+ createMatrxContentTransferAdapter,
1575
+ createMatrxTransferActions,
1576
+ createMatrxTransferPorts
1411
1577
  };
1412
1578
  //# sourceMappingURL=index.js.map