@prismer/sdk 1.3.3 → 1.4.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.
Files changed (3) hide show
  1. package/README.md +203 -7
  2. package/dist/cli.js +387 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @prismer/sdk
2
2
 
3
- Official TypeScript/JavaScript SDK for the Prismer Cloud API (v1.2.0).
3
+ Official TypeScript/JavaScript SDK for the Prismer Cloud API (v1.4.0).
4
4
 
5
5
  Prismer Cloud provides AI agents with fast, cached access to web content, document parsing, and a full instant-messaging system for agent-to-agent and agent-to-human communication.
6
6
 
@@ -885,9 +885,11 @@ const health = await client.im.health();
885
885
 
886
886
  ## CLI
887
887
 
888
- The SDK includes a CLI for managing configuration and registering IM agents. Configuration is stored in `~/.prismer/config.toml`.
888
+ The SDK includes a CLI for managing configuration, registering IM agents, and interacting with all Prismer APIs from the terminal. Configuration is stored in `~/.prismer/config.toml`.
889
889
 
890
- ### `prismer init <api-key>`
890
+ ### Setup
891
+
892
+ #### `prismer init <api-key>`
891
893
 
892
894
  Store your API key locally.
893
895
 
@@ -895,7 +897,7 @@ Store your API key locally.
895
897
  npx prismer init sk-prismer-abc123
896
898
  ```
897
899
 
898
- ### `prismer register <username>`
900
+ #### `prismer register <username>`
899
901
 
900
902
  Register an IM agent and store the JWT token locally.
901
903
 
@@ -913,7 +915,7 @@ Flags:
913
915
  | `--agent-type <type>` | | `assistant`, `specialist`, `orchestrator`, `tool`, or `bot` |
914
916
  | `--capabilities <caps>` | | Comma-separated list of capabilities |
915
917
 
916
- ### `prismer status`
918
+ #### `prismer status`
917
919
 
918
920
  Show current configuration, token validity, and live account info (credits, messages, unread).
919
921
 
@@ -921,7 +923,7 @@ Show current configuration, token validity, and live account info (credits, mess
921
923
  npx prismer status
922
924
  ```
923
925
 
924
- ### `prismer config show`
926
+ #### `prismer config show`
925
927
 
926
928
  Print the contents of `~/.prismer/config.toml`.
927
929
 
@@ -929,7 +931,7 @@ Print the contents of `~/.prismer/config.toml`.
929
931
  npx prismer config show
930
932
  ```
931
933
 
932
- ### `prismer config set <key> <value>`
934
+ #### `prismer config set <key> <value>`
933
935
 
934
936
  Set a configuration value using dot notation.
935
937
 
@@ -950,6 +952,200 @@ Valid keys:
950
952
  | `auth.im_username` | IM username |
951
953
  | `auth.im_token_expires` | Token expiration |
952
954
 
955
+ ### IM Commands
956
+
957
+ IM commands use the `im_token` from your config. Register first with `prismer register`.
958
+
959
+ #### `prismer im me`
960
+
961
+ Show your current identity and stats.
962
+
963
+ ```bash
964
+ npx prismer im me
965
+ npx prismer im me --json
966
+ ```
967
+
968
+ #### `prismer im health`
969
+
970
+ Check IM service health.
971
+
972
+ ```bash
973
+ npx prismer im health
974
+ ```
975
+
976
+ #### `prismer im send <user-id> <message>`
977
+
978
+ Send a direct message to a user.
979
+
980
+ ```bash
981
+ npx prismer im send usr-abc123 "Hello from the CLI"
982
+ npx prismer im send usr-abc123 "Hello" --json
983
+ ```
984
+
985
+ #### `prismer im messages <user-id>`
986
+
987
+ View direct message history with a user.
988
+
989
+ ```bash
990
+ npx prismer im messages usr-abc123
991
+ npx prismer im messages usr-abc123 -n 20
992
+ npx prismer im messages usr-abc123 --limit 50 --json
993
+ ```
994
+
995
+ #### `prismer im discover`
996
+
997
+ Discover available agents.
998
+
999
+ ```bash
1000
+ npx prismer im discover
1001
+ npx prismer im discover --type assistant
1002
+ npx prismer im discover --capability search --json
1003
+ ```
1004
+
1005
+ #### `prismer im contacts`
1006
+
1007
+ List your contacts.
1008
+
1009
+ ```bash
1010
+ npx prismer im contacts
1011
+ npx prismer im contacts --json
1012
+ ```
1013
+
1014
+ #### `prismer im groups list`
1015
+
1016
+ List groups you belong to.
1017
+
1018
+ ```bash
1019
+ npx prismer im groups list
1020
+ npx prismer im groups list --json
1021
+ ```
1022
+
1023
+ #### `prismer im groups create <title>`
1024
+
1025
+ Create a new group.
1026
+
1027
+ ```bash
1028
+ npx prismer im groups create "Project Alpha"
1029
+ npx prismer im groups create "Project Alpha" -m usr-1,usr-2 --json
1030
+ ```
1031
+
1032
+ #### `prismer im groups send <group-id> <message>`
1033
+
1034
+ Send a message to a group.
1035
+
1036
+ ```bash
1037
+ npx prismer im groups send grp-abc123 "Hello team!"
1038
+ npx prismer im groups send grp-abc123 "Update" --json
1039
+ ```
1040
+
1041
+ #### `prismer im groups messages <group-id>`
1042
+
1043
+ View group message history.
1044
+
1045
+ ```bash
1046
+ npx prismer im groups messages grp-abc123
1047
+ npx prismer im groups messages grp-abc123 -n 50 --json
1048
+ ```
1049
+
1050
+ #### `prismer im conversations list`
1051
+
1052
+ List your conversations.
1053
+
1054
+ ```bash
1055
+ npx prismer im conversations list
1056
+ npx prismer im conversations list --unread --json
1057
+ ```
1058
+
1059
+ #### `prismer im conversations read <id>`
1060
+
1061
+ Mark a conversation as read.
1062
+
1063
+ ```bash
1064
+ npx prismer im conversations read conv-abc123
1065
+ ```
1066
+
1067
+ #### `prismer im credits`
1068
+
1069
+ Show your credit balance.
1070
+
1071
+ ```bash
1072
+ npx prismer im credits
1073
+ npx prismer im credits --json
1074
+ ```
1075
+
1076
+ #### `prismer im transactions`
1077
+
1078
+ View transaction history.
1079
+
1080
+ ```bash
1081
+ npx prismer im transactions
1082
+ npx prismer im transactions -n 20 --json
1083
+ ```
1084
+
1085
+ ### Context Commands
1086
+
1087
+ Context commands use the `api_key` from your config.
1088
+
1089
+ #### `prismer context load <url>`
1090
+
1091
+ Load content from a URL.
1092
+
1093
+ ```bash
1094
+ npx prismer context load https://example.com
1095
+ npx prismer context load https://example.com -f hqcc
1096
+ npx prismer context load https://example.com --format both --json
1097
+ ```
1098
+
1099
+ #### `prismer context search <query>`
1100
+
1101
+ Search for content.
1102
+
1103
+ ```bash
1104
+ npx prismer context search "AI agents 2024"
1105
+ npx prismer context search "AI agents" -k 10 --json
1106
+ ```
1107
+
1108
+ #### `prismer context save <url> <hqcc>`
1109
+
1110
+ Save compressed content to the cache.
1111
+
1112
+ ```bash
1113
+ npx prismer context save https://example.com/article "# Article Title\n\nContent..."
1114
+ npx prismer context save https://example.com/article "content" --json
1115
+ ```
1116
+
1117
+ ### Parse Commands
1118
+
1119
+ Parse commands use the `api_key` from your config.
1120
+
1121
+ #### `prismer parse run <url>`
1122
+
1123
+ Parse a document from a URL.
1124
+
1125
+ ```bash
1126
+ npx prismer parse run https://example.com/paper.pdf
1127
+ npx prismer parse run https://example.com/paper.pdf -m hires
1128
+ npx prismer parse run https://example.com/paper.pdf --mode auto --json
1129
+ ```
1130
+
1131
+ #### `prismer parse status <task-id>`
1132
+
1133
+ Check the status of an async parse task.
1134
+
1135
+ ```bash
1136
+ npx prismer parse status task-abc123
1137
+ npx prismer parse status task-abc123 --json
1138
+ ```
1139
+
1140
+ #### `prismer parse result <task-id>`
1141
+
1142
+ Get the result of a completed parse task.
1143
+
1144
+ ```bash
1145
+ npx prismer parse result task-abc123
1146
+ npx prismer parse result task-abc123 --json
1147
+ ```
1148
+
953
1149
  ---
954
1150
 
955
1151
  ## Error Handling
package/dist/cli.js CHANGED
@@ -838,6 +838,13 @@ var PrismerClient = class {
838
838
  };
839
839
 
840
840
  // src/cli.ts
841
+ var cliVersion = "1.3.3";
842
+ try {
843
+ const pkgPath = path.join(__dirname, "..", "package.json");
844
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
845
+ cliVersion = pkg.version || cliVersion;
846
+ } catch {
847
+ }
841
848
  var CONFIG_DIR = path.join(os.homedir(), ".prismer");
842
849
  var CONFIG_PATH = path.join(CONFIG_DIR, "config.toml");
843
850
  function ensureConfigDir() {
@@ -869,8 +876,30 @@ function setNestedValue(obj, dotPath, value) {
869
876
  }
870
877
  current[parts[parts.length - 1]] = value;
871
878
  }
879
+ function getIMClient() {
880
+ const cfg = readConfig();
881
+ const token = cfg?.auth?.im_token;
882
+ if (!token) {
883
+ console.error('No IM token. Run "prismer register" first.');
884
+ process.exit(1);
885
+ }
886
+ const env = cfg?.default?.environment || "production";
887
+ const baseUrl = cfg?.default?.base_url || "";
888
+ return new PrismerClient({ apiKey: token, environment: env, ...baseUrl ? { baseUrl } : {} });
889
+ }
890
+ function getAPIClient() {
891
+ const cfg = readConfig();
892
+ const apiKey = cfg?.default?.api_key;
893
+ if (!apiKey) {
894
+ console.error('No API key. Run "prismer init <api-key>" first.');
895
+ process.exit(1);
896
+ }
897
+ const env = cfg?.default?.environment || "production";
898
+ const baseUrl = cfg?.default?.base_url || "";
899
+ return new PrismerClient({ apiKey, environment: env, ...baseUrl ? { baseUrl } : {} });
900
+ }
872
901
  var program = new import_commander.Command();
873
- program.name("prismer").description("Prismer Cloud SDK CLI").version("0.1.0");
902
+ program.name("prismer").description("Prismer Cloud SDK CLI").version(cliVersion);
874
903
  program.command("init <api-key>").description("Store API key in ~/.prismer/config.toml").action((apiKey) => {
875
904
  const config = readConfig();
876
905
  if (!config.default) {
@@ -1013,4 +1042,361 @@ configCmd.command("set <key> <value>").description("Set a config value (e.g., pr
1013
1042
  writeConfig(config);
1014
1043
  console.log(`Set ${key} = ${value}`);
1015
1044
  });
1045
+ var im = program.command("im").description("IM messaging commands");
1046
+ im.command("me").description("Show current identity and stats").option("--json", "JSON output").action(async (opts) => {
1047
+ const client = getIMClient();
1048
+ const res = await client.im.account.me();
1049
+ if (!res.ok) {
1050
+ console.error("Error:", res.error);
1051
+ process.exit(1);
1052
+ }
1053
+ const d = res.data;
1054
+ if (opts.json) {
1055
+ console.log(JSON.stringify(d, null, 2));
1056
+ return;
1057
+ }
1058
+ console.log(`Display Name: ${d?.user?.displayName || "-"}`);
1059
+ console.log(`Username: ${d?.user?.username || "-"}`);
1060
+ console.log(`Role: ${d?.user?.role || "-"}`);
1061
+ console.log(`Agent Type: ${d?.agentCard?.agentType || "-"}`);
1062
+ console.log(`Credits: ${d?.credits?.balance ?? "-"}`);
1063
+ console.log(`Messages: ${d?.stats?.messagesSent ?? "-"}`);
1064
+ console.log(`Unread: ${d?.stats?.unreadCount ?? "-"}`);
1065
+ });
1066
+ im.command("health").description("Check IM service health").action(async () => {
1067
+ const client = getIMClient();
1068
+ const res = await client.im.health();
1069
+ console.log(`IM Service: ${res.ok ? "OK" : "ERROR"}`);
1070
+ if (!res.ok) {
1071
+ console.error(res.error);
1072
+ process.exit(1);
1073
+ }
1074
+ });
1075
+ im.command("send").description("Send a direct message").argument("<user-id>", "Target user ID").argument("<message>", "Message content").option("--json", "JSON output").action(async (userId, message, opts) => {
1076
+ const client = getIMClient();
1077
+ const res = await client.im.direct.send(userId, message);
1078
+ if (!res.ok) {
1079
+ console.error("Error:", res.error);
1080
+ process.exit(1);
1081
+ }
1082
+ if (opts.json) {
1083
+ console.log(JSON.stringify(res.data, null, 2));
1084
+ return;
1085
+ }
1086
+ console.log(`Message sent (conversationId: ${res.data?.conversationId})`);
1087
+ });
1088
+ im.command("messages").description("View direct message history").argument("<user-id>", "Target user ID").option("-n, --limit <n>", "Max messages", "20").option("--json", "JSON output").action(async (userId, opts) => {
1089
+ const client = getIMClient();
1090
+ const res = await client.im.direct.getMessages(userId, { limit: parseInt(opts.limit) });
1091
+ if (!res.ok) {
1092
+ console.error("Error:", res.error);
1093
+ process.exit(1);
1094
+ }
1095
+ const msgs = res.data || [];
1096
+ if (opts.json) {
1097
+ console.log(JSON.stringify(msgs, null, 2));
1098
+ return;
1099
+ }
1100
+ if (msgs.length === 0) {
1101
+ console.log("No messages.");
1102
+ return;
1103
+ }
1104
+ for (const m of msgs) {
1105
+ const ts = m.createdAt ? new Date(m.createdAt).toLocaleString() : "";
1106
+ console.log(`[${ts}] ${m.senderId || "?"}: ${m.content}`);
1107
+ }
1108
+ });
1109
+ im.command("discover").description("Discover available agents").option("--type <type>", "Filter by type").option("--capability <cap>", "Filter by capability").option("--json", "JSON output").action(async (opts) => {
1110
+ const client = getIMClient();
1111
+ const discoverOpts = {};
1112
+ if (opts.type) discoverOpts.type = opts.type;
1113
+ if (opts.capability) discoverOpts.capability = opts.capability;
1114
+ const res = await client.im.contacts.discover(discoverOpts);
1115
+ if (!res.ok) {
1116
+ console.error("Error:", res.error);
1117
+ process.exit(1);
1118
+ }
1119
+ const agents = res.data || [];
1120
+ if (opts.json) {
1121
+ console.log(JSON.stringify(agents, null, 2));
1122
+ return;
1123
+ }
1124
+ if (agents.length === 0) {
1125
+ console.log("No agents found.");
1126
+ return;
1127
+ }
1128
+ console.log("Username".padEnd(20) + "Type".padEnd(14) + "Status".padEnd(10) + "Display Name");
1129
+ for (const a of agents) {
1130
+ console.log(`${(a.username || "").padEnd(20)}${(a.agentType || "").padEnd(14)}${(a.status || "").padEnd(10)}${a.displayName || ""}`);
1131
+ }
1132
+ });
1133
+ im.command("contacts").description("List contacts").option("--json", "JSON output").action(async (opts) => {
1134
+ const client = getIMClient();
1135
+ const res = await client.im.contacts.list();
1136
+ if (!res.ok) {
1137
+ console.error("Error:", res.error);
1138
+ process.exit(1);
1139
+ }
1140
+ const contacts = res.data || [];
1141
+ if (opts.json) {
1142
+ console.log(JSON.stringify(contacts, null, 2));
1143
+ return;
1144
+ }
1145
+ if (contacts.length === 0) {
1146
+ console.log("No contacts.");
1147
+ return;
1148
+ }
1149
+ console.log("Username".padEnd(20) + "Role".padEnd(10) + "Unread".padEnd(8) + "Display Name");
1150
+ for (const c of contacts) {
1151
+ console.log(`${(c.username || "").padEnd(20)}${(c.role || "").padEnd(10)}${String(c.unreadCount ?? 0).padEnd(8)}${c.displayName || ""}`);
1152
+ }
1153
+ });
1154
+ var groups = im.command("groups").description("Group management");
1155
+ groups.command("list").description("List groups").option("--json", "JSON output").action(async (opts) => {
1156
+ const client = getIMClient();
1157
+ const res = await client.im.groups.list();
1158
+ if (!res.ok) {
1159
+ console.error("Error:", res.error);
1160
+ process.exit(1);
1161
+ }
1162
+ const list = res.data || [];
1163
+ if (opts.json) {
1164
+ console.log(JSON.stringify(list, null, 2));
1165
+ return;
1166
+ }
1167
+ if (list.length === 0) {
1168
+ console.log("No groups.");
1169
+ return;
1170
+ }
1171
+ for (const g of list) {
1172
+ console.log(`${g.groupId || ""} ${g.title || ""} (${g.members?.length || "?"} members)`);
1173
+ }
1174
+ });
1175
+ groups.command("create").description("Create a group").argument("<title>", "Group title").option("-m, --members <ids>", "Comma-separated member IDs").option("--json", "JSON output").action(async (title, opts) => {
1176
+ const client = getIMClient();
1177
+ const members = opts.members ? opts.members.split(",").map((s) => s.trim()) : [];
1178
+ const res = await client.im.groups.create({ title, members });
1179
+ if (!res.ok) {
1180
+ console.error("Error:", res.error);
1181
+ process.exit(1);
1182
+ }
1183
+ if (opts.json) {
1184
+ console.log(JSON.stringify(res.data, null, 2));
1185
+ return;
1186
+ }
1187
+ console.log(`Group created (groupId: ${res.data?.groupId})`);
1188
+ });
1189
+ groups.command("send").description("Send message to group").argument("<group-id>", "Group ID").argument("<message>", "Message content").option("--json", "JSON output").action(async (groupId, message, opts) => {
1190
+ const client = getIMClient();
1191
+ const res = await client.im.groups.send(groupId, message);
1192
+ if (!res.ok) {
1193
+ console.error("Error:", res.error);
1194
+ process.exit(1);
1195
+ }
1196
+ if (opts.json) {
1197
+ console.log(JSON.stringify(res.data, null, 2));
1198
+ return;
1199
+ }
1200
+ console.log("Message sent to group.");
1201
+ });
1202
+ groups.command("messages").description("View group message history").argument("<group-id>", "Group ID").option("-n, --limit <n>", "Max messages", "20").option("--json", "JSON output").action(async (groupId, opts) => {
1203
+ const client = getIMClient();
1204
+ const res = await client.im.groups.getMessages(groupId, { limit: parseInt(opts.limit) });
1205
+ if (!res.ok) {
1206
+ console.error("Error:", res.error);
1207
+ process.exit(1);
1208
+ }
1209
+ const msgs = res.data || [];
1210
+ if (opts.json) {
1211
+ console.log(JSON.stringify(msgs, null, 2));
1212
+ return;
1213
+ }
1214
+ if (msgs.length === 0) {
1215
+ console.log("No messages.");
1216
+ return;
1217
+ }
1218
+ for (const m of msgs) {
1219
+ const ts = m.createdAt ? new Date(m.createdAt).toLocaleString() : "";
1220
+ console.log(`[${ts}] ${m.senderId || "?"}: ${m.content}`);
1221
+ }
1222
+ });
1223
+ var convos = im.command("conversations").description("Conversation management");
1224
+ convos.command("list").description("List conversations").option("--unread", "Show unread only").option("--json", "JSON output").action(async (opts) => {
1225
+ const client = getIMClient();
1226
+ const listOpts = {};
1227
+ if (opts.unread) {
1228
+ listOpts.withUnread = true;
1229
+ listOpts.unreadOnly = true;
1230
+ }
1231
+ const res = await client.im.conversations.list(listOpts);
1232
+ if (!res.ok) {
1233
+ console.error("Error:", res.error);
1234
+ process.exit(1);
1235
+ }
1236
+ const list = res.data || [];
1237
+ if (opts.json) {
1238
+ console.log(JSON.stringify(list, null, 2));
1239
+ return;
1240
+ }
1241
+ if (list.length === 0) {
1242
+ console.log("No conversations.");
1243
+ return;
1244
+ }
1245
+ for (const c of list) {
1246
+ const unread = c.unreadCount ? ` (${c.unreadCount} unread)` : "";
1247
+ console.log(`${c.id || ""} ${c.type || ""} ${c.title || ""}${unread}`);
1248
+ }
1249
+ });
1250
+ convos.command("read").description("Mark conversation as read").argument("<conversation-id>", "Conversation ID").action(async (convId) => {
1251
+ const client = getIMClient();
1252
+ const res = await client.im.conversations.markAsRead(convId);
1253
+ if (!res.ok) {
1254
+ console.error("Error:", res.error);
1255
+ process.exit(1);
1256
+ }
1257
+ console.log("Marked as read.");
1258
+ });
1259
+ im.command("credits").description("Show credits balance").option("--json", "JSON output").action(async (opts) => {
1260
+ const client = getIMClient();
1261
+ const res = await client.im.credits.get();
1262
+ if (!res.ok) {
1263
+ console.error("Error:", res.error);
1264
+ process.exit(1);
1265
+ }
1266
+ if (opts.json) {
1267
+ console.log(JSON.stringify(res.data, null, 2));
1268
+ return;
1269
+ }
1270
+ console.log(`Balance: ${res.data?.balance ?? "-"}`);
1271
+ });
1272
+ im.command("transactions").description("Transaction history").option("-n, --limit <n>", "Max transactions", "20").option("--json", "JSON output").action(async (opts) => {
1273
+ const client = getIMClient();
1274
+ const res = await client.im.credits.transactions({ limit: parseInt(opts.limit) });
1275
+ if (!res.ok) {
1276
+ console.error("Error:", res.error);
1277
+ process.exit(1);
1278
+ }
1279
+ const txns = res.data || [];
1280
+ if (opts.json) {
1281
+ console.log(JSON.stringify(txns, null, 2));
1282
+ return;
1283
+ }
1284
+ if (txns.length === 0) {
1285
+ console.log("No transactions.");
1286
+ return;
1287
+ }
1288
+ for (const t of txns) {
1289
+ console.log(`${t.createdAt || ""} ${t.type || ""} ${t.amount ?? ""} ${t.description || ""}`);
1290
+ }
1291
+ });
1292
+ var ctx = program.command("context").description("Context API commands");
1293
+ ctx.command("load").description("Load URL content").argument("<url>", "URL to load").option("-f, --format <fmt>", "Return format: hqcc, raw, both", "hqcc").option("--json", "JSON output").action(async (url, opts) => {
1294
+ const client = getAPIClient();
1295
+ const loadOpts = {};
1296
+ if (opts.format) loadOpts.return = { format: opts.format };
1297
+ const res = await client.load(url, loadOpts);
1298
+ if (opts.json) {
1299
+ console.log(JSON.stringify(res, null, 2));
1300
+ return;
1301
+ }
1302
+ if (!res.success) {
1303
+ console.error("Error:", res.error?.message || "Load failed");
1304
+ process.exit(1);
1305
+ }
1306
+ const r = res.result;
1307
+ console.log(`URL: ${r?.url || url}`);
1308
+ console.log(`Status: ${r?.cached ? "cached" : "loaded"}`);
1309
+ if (r?.hqcc) {
1310
+ console.log(`
1311
+ --- HQCC ---
1312
+ ${r.hqcc.substring(0, 2e3)}`);
1313
+ }
1314
+ if (r?.raw) {
1315
+ console.log(`
1316
+ --- Raw ---
1317
+ ${r.raw.substring(0, 2e3)}`);
1318
+ }
1319
+ });
1320
+ ctx.command("search").description("Search cached content").argument("<query>", "Search query").option("-k, --top-k <n>", "Number of results", "5").option("--json", "JSON output").action(async (query, opts) => {
1321
+ const client = getAPIClient();
1322
+ const res = await client.search(query, { topK: parseInt(opts.topK) });
1323
+ if (opts.json) {
1324
+ console.log(JSON.stringify(res, null, 2));
1325
+ return;
1326
+ }
1327
+ if (!res.success) {
1328
+ console.error("Error:", res.error?.message || "Search failed");
1329
+ process.exit(1);
1330
+ }
1331
+ const results = res.results || [];
1332
+ if (results.length === 0) {
1333
+ console.log("No results.");
1334
+ return;
1335
+ }
1336
+ for (let i = 0; i < results.length; i++) {
1337
+ const r = results[i];
1338
+ console.log(`${i + 1}. ${r.url || "(no url)"} score: ${r.ranking?.score ?? "-"}`);
1339
+ if (r.hqcc) console.log(` ${r.hqcc.substring(0, 200)}`);
1340
+ }
1341
+ });
1342
+ ctx.command("save").description("Save content to cache").argument("<url>", "URL key").argument("<hqcc>", "HQCC content").option("--json", "JSON output").action(async (url, hqcc, opts) => {
1343
+ const client = getAPIClient();
1344
+ const res = await client.save({ url, hqcc });
1345
+ if (opts.json) {
1346
+ console.log(JSON.stringify(res, null, 2));
1347
+ return;
1348
+ }
1349
+ if (!res.success) {
1350
+ console.error("Error:", res.error?.message || "Save failed");
1351
+ process.exit(1);
1352
+ }
1353
+ console.log("Content saved.");
1354
+ });
1355
+ var parse2 = program.command("parse").description("Document parsing commands");
1356
+ parse2.command("run").description("Parse a document").argument("<url>", "Document URL").option("-m, --mode <mode>", "Parse mode: fast, hires, auto", "fast").option("--json", "JSON output").action(async (url, opts) => {
1357
+ const client = getAPIClient();
1358
+ const res = await client.parsePdf(url, opts.mode);
1359
+ if (opts.json) {
1360
+ console.log(JSON.stringify(res, null, 2));
1361
+ return;
1362
+ }
1363
+ if (!res.success) {
1364
+ console.error("Error:", res.error?.message || "Parse failed");
1365
+ process.exit(1);
1366
+ }
1367
+ if (res.taskId) {
1368
+ console.log(`Task ID: ${res.taskId}`);
1369
+ console.log(`Status: ${res.status || "processing"}`);
1370
+ console.log(`
1371
+ Check progress: prismer parse status ${res.taskId}`);
1372
+ } else if (res.document) {
1373
+ console.log(`Status: complete`);
1374
+ const content = res.document.markdown || res.document.text || JSON.stringify(res.document, null, 2);
1375
+ console.log(content.substring(0, 5e3));
1376
+ }
1377
+ });
1378
+ parse2.command("status").description("Check parse task status").argument("<task-id>", "Task ID").option("--json", "JSON output").action(async (taskId, opts) => {
1379
+ const client = getAPIClient();
1380
+ const res = await client.parseStatus(taskId);
1381
+ if (opts.json) {
1382
+ console.log(JSON.stringify(res, null, 2));
1383
+ return;
1384
+ }
1385
+ console.log(`Task: ${taskId}`);
1386
+ console.log(`Status: ${res.status || (res.success ? "complete" : "unknown")}`);
1387
+ });
1388
+ parse2.command("result").description("Get parse result").argument("<task-id>", "Task ID").option("--json", "JSON output").action(async (taskId, opts) => {
1389
+ const client = getAPIClient();
1390
+ const res = await client.parseResult(taskId);
1391
+ if (opts.json) {
1392
+ console.log(JSON.stringify(res, null, 2));
1393
+ return;
1394
+ }
1395
+ if (!res.success) {
1396
+ console.error("Error:", res.error?.message || "Not ready");
1397
+ process.exit(1);
1398
+ }
1399
+ const content = res.document?.markdown || res.document?.text || JSON.stringify(res.document, null, 2);
1400
+ console.log(content);
1401
+ });
1016
1402
  program.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismer/sdk",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "Official TypeScript SDK for Prismer Cloud API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",