@superatomai/sdk-node 0.0.95-dsp → 0.0.96-dsp
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.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +40 -4
- package/dist/index.mjs +40 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1463,10 +1463,12 @@ declare const MessageSchema: z.ZodObject<{
|
|
|
1463
1463
|
from: z.ZodObject<{
|
|
1464
1464
|
id: z.ZodOptional<z.ZodString>;
|
|
1465
1465
|
type: z.ZodOptional<z.ZodString>;
|
|
1466
|
+
parcels: z.ZodOptional<z.ZodBoolean>;
|
|
1466
1467
|
}, z.core.$strip>;
|
|
1467
1468
|
to: z.ZodOptional<z.ZodObject<{
|
|
1468
1469
|
id: z.ZodOptional<z.ZodString>;
|
|
1469
1470
|
type: z.ZodOptional<z.ZodString>;
|
|
1471
|
+
parcels: z.ZodOptional<z.ZodBoolean>;
|
|
1470
1472
|
}, z.core.$strip>>;
|
|
1471
1473
|
payload: z.ZodUnknown;
|
|
1472
1474
|
}, z.core.$strip>;
|
|
@@ -1477,10 +1479,12 @@ declare const IncomingMessageSchema: z.ZodObject<{
|
|
|
1477
1479
|
from: z.ZodObject<{
|
|
1478
1480
|
id: z.ZodOptional<z.ZodString>;
|
|
1479
1481
|
type: z.ZodOptional<z.ZodString>;
|
|
1482
|
+
parcels: z.ZodOptional<z.ZodBoolean>;
|
|
1480
1483
|
}, z.core.$strip>;
|
|
1481
1484
|
to: z.ZodOptional<z.ZodObject<{
|
|
1482
1485
|
id: z.ZodOptional<z.ZodString>;
|
|
1483
1486
|
type: z.ZodOptional<z.ZodString>;
|
|
1487
|
+
parcels: z.ZodOptional<z.ZodBoolean>;
|
|
1484
1488
|
}, z.core.$strip>>;
|
|
1485
1489
|
payload: z.ZodUnknown;
|
|
1486
1490
|
}, z.core.$strip>;
|
|
@@ -6069,6 +6073,8 @@ declare class SuperatomSDK {
|
|
|
6069
6073
|
private parcelClient;
|
|
6070
6074
|
private outgoing;
|
|
6071
6075
|
private incoming;
|
|
6076
|
+
/** The client sockets that said they read parcels; only they get large JSON as parcels or parts. */
|
|
6077
|
+
private parcelReaders;
|
|
6072
6078
|
constructor(config: SuperatomSDKConfig);
|
|
6073
6079
|
/**
|
|
6074
6080
|
* Initialize PromptLoader and load prompts into memory
|
package/dist/index.d.ts
CHANGED
|
@@ -1463,10 +1463,12 @@ declare const MessageSchema: z.ZodObject<{
|
|
|
1463
1463
|
from: z.ZodObject<{
|
|
1464
1464
|
id: z.ZodOptional<z.ZodString>;
|
|
1465
1465
|
type: z.ZodOptional<z.ZodString>;
|
|
1466
|
+
parcels: z.ZodOptional<z.ZodBoolean>;
|
|
1466
1467
|
}, z.core.$strip>;
|
|
1467
1468
|
to: z.ZodOptional<z.ZodObject<{
|
|
1468
1469
|
id: z.ZodOptional<z.ZodString>;
|
|
1469
1470
|
type: z.ZodOptional<z.ZodString>;
|
|
1471
|
+
parcels: z.ZodOptional<z.ZodBoolean>;
|
|
1470
1472
|
}, z.core.$strip>>;
|
|
1471
1473
|
payload: z.ZodUnknown;
|
|
1472
1474
|
}, z.core.$strip>;
|
|
@@ -1477,10 +1479,12 @@ declare const IncomingMessageSchema: z.ZodObject<{
|
|
|
1477
1479
|
from: z.ZodObject<{
|
|
1478
1480
|
id: z.ZodOptional<z.ZodString>;
|
|
1479
1481
|
type: z.ZodOptional<z.ZodString>;
|
|
1482
|
+
parcels: z.ZodOptional<z.ZodBoolean>;
|
|
1480
1483
|
}, z.core.$strip>;
|
|
1481
1484
|
to: z.ZodOptional<z.ZodObject<{
|
|
1482
1485
|
id: z.ZodOptional<z.ZodString>;
|
|
1483
1486
|
type: z.ZodOptional<z.ZodString>;
|
|
1487
|
+
parcels: z.ZodOptional<z.ZodBoolean>;
|
|
1484
1488
|
}, z.core.$strip>>;
|
|
1485
1489
|
payload: z.ZodUnknown;
|
|
1486
1490
|
}, z.core.$strip>;
|
|
@@ -6069,6 +6073,8 @@ declare class SuperatomSDK {
|
|
|
6069
6073
|
private parcelClient;
|
|
6070
6074
|
private outgoing;
|
|
6071
6075
|
private incoming;
|
|
6076
|
+
/** The client sockets that said they read parcels; only they get large JSON as parcels or parts. */
|
|
6077
|
+
private parcelReaders;
|
|
6072
6078
|
constructor(config: SuperatomSDKConfig);
|
|
6073
6079
|
/**
|
|
6074
6080
|
* Initialize PromptLoader and load prompts into memory
|
package/dist/index.js
CHANGED
|
@@ -348,7 +348,9 @@ var UsersDataSchema = import_zod3.z.object({
|
|
|
348
348
|
});
|
|
349
349
|
var MessageParticipantSchema = import_zod3.z.object({
|
|
350
350
|
id: import_zod3.z.string().optional(),
|
|
351
|
-
type: import_zod3.z.string().optional()
|
|
351
|
+
type: import_zod3.z.string().optional(),
|
|
352
|
+
/** On `from`: the sending client reads parcels and parts (see parcels/ParcelReaders). */
|
|
353
|
+
parcels: import_zod3.z.boolean().optional()
|
|
352
354
|
});
|
|
353
355
|
var MessageSchema = import_zod3.z.object({
|
|
354
356
|
id: import_zod3.z.string().optional(),
|
|
@@ -28581,6 +28583,26 @@ var recipientOf = (message) => {
|
|
|
28581
28583
|
const id = message.to?.id;
|
|
28582
28584
|
return typeof id === "string" ? id : "";
|
|
28583
28585
|
};
|
|
28586
|
+
var MAX_READERS = 1e4;
|
|
28587
|
+
var ParcelReaders = class {
|
|
28588
|
+
constructor(max = MAX_READERS) {
|
|
28589
|
+
this.max = max;
|
|
28590
|
+
this.ids = /* @__PURE__ */ new Set();
|
|
28591
|
+
}
|
|
28592
|
+
/** Notes what a received message says about its sender. */
|
|
28593
|
+
noteSender(message) {
|
|
28594
|
+
const from = message?.from;
|
|
28595
|
+
if (typeof from?.id !== "string" || !from.id) return;
|
|
28596
|
+
this.ids.delete(from.id);
|
|
28597
|
+
if (from.parcels !== true) return;
|
|
28598
|
+
this.ids.add(from.id);
|
|
28599
|
+
if (this.ids.size > this.max) this.ids.delete(this.ids.values().next().value);
|
|
28600
|
+
}
|
|
28601
|
+
/** Whether the message is addressed to a socket that said it reads parcels. */
|
|
28602
|
+
reads(message) {
|
|
28603
|
+
return this.ids.has(recipientOf(message));
|
|
28604
|
+
}
|
|
28605
|
+
};
|
|
28584
28606
|
var InOrder = class {
|
|
28585
28607
|
/** `onIdle` runs each time the last waiting task finishes. */
|
|
28586
28608
|
constructor(onIdle) {
|
|
@@ -28602,15 +28624,19 @@ var InOrder = class {
|
|
|
28602
28624
|
}
|
|
28603
28625
|
};
|
|
28604
28626
|
var OutgoingParcels = class {
|
|
28605
|
-
constructor(client, jsonParcels, deliver, threshold = PARCEL_THRESHOLD_BYTES) {
|
|
28627
|
+
constructor(client, jsonParcels, deliver, readers = null, threshold = PARCEL_THRESHOLD_BYTES) {
|
|
28606
28628
|
this.client = client;
|
|
28607
28629
|
this.jsonParcels = jsonParcels;
|
|
28608
28630
|
this.deliver = deliver;
|
|
28631
|
+
this.readers = readers;
|
|
28609
28632
|
this.threshold = threshold;
|
|
28610
28633
|
/** Only recipients with something waiting; a queue is dropped once it empties. */
|
|
28611
28634
|
this.queues = /* @__PURE__ */ new Map();
|
|
28612
28635
|
this.warnedNoClient = false;
|
|
28613
28636
|
}
|
|
28637
|
+
readsParcels(message) {
|
|
28638
|
+
return this.readers ? this.readers.reads(message) : true;
|
|
28639
|
+
}
|
|
28614
28640
|
/**
|
|
28615
28641
|
* Same contract as the SDK's `send`: never throws, returns whether the message
|
|
28616
28642
|
* went out (or, for a queued one, was accepted).
|
|
@@ -28630,7 +28656,7 @@ var OutgoingParcels = class {
|
|
|
28630
28656
|
files = false;
|
|
28631
28657
|
}
|
|
28632
28658
|
if (!files) {
|
|
28633
|
-
if (!this.jsonParcels || !this.client) return this.now(message);
|
|
28659
|
+
if (!this.jsonParcels || !this.client || !this.readsParcels(message)) return this.now(message);
|
|
28634
28660
|
let wire;
|
|
28635
28661
|
try {
|
|
28636
28662
|
wire = JSON.stringify(message);
|
|
@@ -28692,6 +28718,12 @@ var OutgoingParcels = class {
|
|
|
28692
28718
|
}
|
|
28693
28719
|
const size = Buffer.byteLength(wire, "utf8");
|
|
28694
28720
|
if (size < this.threshold) return [{ message: current, wire }];
|
|
28721
|
+
if (!this.readsParcels(message)) {
|
|
28722
|
+
if (size > MAX_INLINE_BYTES) {
|
|
28723
|
+
logger.warn(`[parcels] ${message.type} (${size} bytes) is for a client that doesn't read parcels \u2014 sent inline; the relay may refuse it`);
|
|
28724
|
+
}
|
|
28725
|
+
return [{ message: current, wire }];
|
|
28726
|
+
}
|
|
28695
28727
|
let reason = "large-JSON parcels are off";
|
|
28696
28728
|
if (this.jsonParcels && !storage.down) {
|
|
28697
28729
|
const started = Date.now();
|
|
@@ -30152,6 +30184,8 @@ var SuperatomSDK = class {
|
|
|
30152
30184
|
// since an outage of unknown length shouldn't grow this without limit.
|
|
30153
30185
|
this.pendingOutbox = [];
|
|
30154
30186
|
this.MAX_OUTBOX_SIZE = 50;
|
|
30187
|
+
/** The client sockets that said they read parcels; only they get large JSON as parcels or parts. */
|
|
30188
|
+
this.parcelReaders = new ParcelReaders();
|
|
30155
30189
|
/**
|
|
30156
30190
|
* The dashboard contract, as registered by the browser bundle that holds it.
|
|
30157
30191
|
*
|
|
@@ -30178,7 +30212,8 @@ var SuperatomSDK = class {
|
|
|
30178
30212
|
this.outgoing = new OutgoingParcels(
|
|
30179
30213
|
this.parcelClient,
|
|
30180
30214
|
jsonParcels,
|
|
30181
|
-
(message, wire) => this.deliver(message, wire)
|
|
30215
|
+
(message, wire) => this.deliver(message, wire),
|
|
30216
|
+
this.parcelReaders
|
|
30182
30217
|
);
|
|
30183
30218
|
this.incoming = new IncomingParcels(this.parcelClient, (parsed) => this.dispatchMessage(parsed));
|
|
30184
30219
|
this.anthropicApiKey = config2.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY || "";
|
|
@@ -30345,6 +30380,7 @@ var SuperatomSDK = class {
|
|
|
30345
30380
|
logger.error("Failed to parse incoming message:", error);
|
|
30346
30381
|
return;
|
|
30347
30382
|
}
|
|
30383
|
+
this.parcelReaders.noteSender(parsed);
|
|
30348
30384
|
this.incoming.receive(parsed, data);
|
|
30349
30385
|
}
|
|
30350
30386
|
/** Routes one parsed message — everything `handleMessage` did after parsing. */
|
package/dist/index.mjs
CHANGED
|
@@ -228,7 +228,9 @@ var UsersDataSchema = z3.object({
|
|
|
228
228
|
});
|
|
229
229
|
var MessageParticipantSchema = z3.object({
|
|
230
230
|
id: z3.string().optional(),
|
|
231
|
-
type: z3.string().optional()
|
|
231
|
+
type: z3.string().optional(),
|
|
232
|
+
/** On `from`: the sending client reads parcels and parts (see parcels/ParcelReaders). */
|
|
233
|
+
parcels: z3.boolean().optional()
|
|
232
234
|
});
|
|
233
235
|
var MessageSchema = z3.object({
|
|
234
236
|
id: z3.string().optional(),
|
|
@@ -28461,6 +28463,26 @@ var recipientOf = (message) => {
|
|
|
28461
28463
|
const id = message.to?.id;
|
|
28462
28464
|
return typeof id === "string" ? id : "";
|
|
28463
28465
|
};
|
|
28466
|
+
var MAX_READERS = 1e4;
|
|
28467
|
+
var ParcelReaders = class {
|
|
28468
|
+
constructor(max = MAX_READERS) {
|
|
28469
|
+
this.max = max;
|
|
28470
|
+
this.ids = /* @__PURE__ */ new Set();
|
|
28471
|
+
}
|
|
28472
|
+
/** Notes what a received message says about its sender. */
|
|
28473
|
+
noteSender(message) {
|
|
28474
|
+
const from = message?.from;
|
|
28475
|
+
if (typeof from?.id !== "string" || !from.id) return;
|
|
28476
|
+
this.ids.delete(from.id);
|
|
28477
|
+
if (from.parcels !== true) return;
|
|
28478
|
+
this.ids.add(from.id);
|
|
28479
|
+
if (this.ids.size > this.max) this.ids.delete(this.ids.values().next().value);
|
|
28480
|
+
}
|
|
28481
|
+
/** Whether the message is addressed to a socket that said it reads parcels. */
|
|
28482
|
+
reads(message) {
|
|
28483
|
+
return this.ids.has(recipientOf(message));
|
|
28484
|
+
}
|
|
28485
|
+
};
|
|
28464
28486
|
var InOrder = class {
|
|
28465
28487
|
/** `onIdle` runs each time the last waiting task finishes. */
|
|
28466
28488
|
constructor(onIdle) {
|
|
@@ -28482,15 +28504,19 @@ var InOrder = class {
|
|
|
28482
28504
|
}
|
|
28483
28505
|
};
|
|
28484
28506
|
var OutgoingParcels = class {
|
|
28485
|
-
constructor(client, jsonParcels, deliver, threshold = PARCEL_THRESHOLD_BYTES) {
|
|
28507
|
+
constructor(client, jsonParcels, deliver, readers = null, threshold = PARCEL_THRESHOLD_BYTES) {
|
|
28486
28508
|
this.client = client;
|
|
28487
28509
|
this.jsonParcels = jsonParcels;
|
|
28488
28510
|
this.deliver = deliver;
|
|
28511
|
+
this.readers = readers;
|
|
28489
28512
|
this.threshold = threshold;
|
|
28490
28513
|
/** Only recipients with something waiting; a queue is dropped once it empties. */
|
|
28491
28514
|
this.queues = /* @__PURE__ */ new Map();
|
|
28492
28515
|
this.warnedNoClient = false;
|
|
28493
28516
|
}
|
|
28517
|
+
readsParcels(message) {
|
|
28518
|
+
return this.readers ? this.readers.reads(message) : true;
|
|
28519
|
+
}
|
|
28494
28520
|
/**
|
|
28495
28521
|
* Same contract as the SDK's `send`: never throws, returns whether the message
|
|
28496
28522
|
* went out (or, for a queued one, was accepted).
|
|
@@ -28510,7 +28536,7 @@ var OutgoingParcels = class {
|
|
|
28510
28536
|
files = false;
|
|
28511
28537
|
}
|
|
28512
28538
|
if (!files) {
|
|
28513
|
-
if (!this.jsonParcels || !this.client) return this.now(message);
|
|
28539
|
+
if (!this.jsonParcels || !this.client || !this.readsParcels(message)) return this.now(message);
|
|
28514
28540
|
let wire;
|
|
28515
28541
|
try {
|
|
28516
28542
|
wire = JSON.stringify(message);
|
|
@@ -28572,6 +28598,12 @@ var OutgoingParcels = class {
|
|
|
28572
28598
|
}
|
|
28573
28599
|
const size = Buffer.byteLength(wire, "utf8");
|
|
28574
28600
|
if (size < this.threshold) return [{ message: current, wire }];
|
|
28601
|
+
if (!this.readsParcels(message)) {
|
|
28602
|
+
if (size > MAX_INLINE_BYTES) {
|
|
28603
|
+
logger.warn(`[parcels] ${message.type} (${size} bytes) is for a client that doesn't read parcels \u2014 sent inline; the relay may refuse it`);
|
|
28604
|
+
}
|
|
28605
|
+
return [{ message: current, wire }];
|
|
28606
|
+
}
|
|
28575
28607
|
let reason = "large-JSON parcels are off";
|
|
28576
28608
|
if (this.jsonParcels && !storage.down) {
|
|
28577
28609
|
const started = Date.now();
|
|
@@ -30032,6 +30064,8 @@ var SuperatomSDK = class {
|
|
|
30032
30064
|
// since an outage of unknown length shouldn't grow this without limit.
|
|
30033
30065
|
this.pendingOutbox = [];
|
|
30034
30066
|
this.MAX_OUTBOX_SIZE = 50;
|
|
30067
|
+
/** The client sockets that said they read parcels; only they get large JSON as parcels or parts. */
|
|
30068
|
+
this.parcelReaders = new ParcelReaders();
|
|
30035
30069
|
/**
|
|
30036
30070
|
* The dashboard contract, as registered by the browser bundle that holds it.
|
|
30037
30071
|
*
|
|
@@ -30058,7 +30092,8 @@ var SuperatomSDK = class {
|
|
|
30058
30092
|
this.outgoing = new OutgoingParcels(
|
|
30059
30093
|
this.parcelClient,
|
|
30060
30094
|
jsonParcels,
|
|
30061
|
-
(message, wire) => this.deliver(message, wire)
|
|
30095
|
+
(message, wire) => this.deliver(message, wire),
|
|
30096
|
+
this.parcelReaders
|
|
30062
30097
|
);
|
|
30063
30098
|
this.incoming = new IncomingParcels(this.parcelClient, (parsed) => this.dispatchMessage(parsed));
|
|
30064
30099
|
this.anthropicApiKey = config2.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY || "";
|
|
@@ -30225,6 +30260,7 @@ var SuperatomSDK = class {
|
|
|
30225
30260
|
logger.error("Failed to parse incoming message:", error);
|
|
30226
30261
|
return;
|
|
30227
30262
|
}
|
|
30263
|
+
this.parcelReaders.noteSender(parsed);
|
|
30228
30264
|
this.incoming.receive(parsed, data);
|
|
30229
30265
|
}
|
|
30230
30266
|
/** Routes one parsed message — everything `handleMessage` did after parsing. */
|