@rowan-agent/agent 0.8.3 → 0.8.4
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.ts +1 -1
- package/dist/index.js +45 -18
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1391,7 +1391,7 @@ declare class InMemoryStore implements DurableStore {
|
|
|
1391
1391
|
ownerId: string;
|
|
1392
1392
|
leaseMs: number;
|
|
1393
1393
|
}): Promise<OwnedStore>;
|
|
1394
|
-
assertOwner(lease: OwnerLease): void;
|
|
1394
|
+
assertOwner(lease: OwnerLease, requireLive?: boolean): void;
|
|
1395
1395
|
renewOwner(lease: OwnerLease, leaseMs: number): OwnerLease;
|
|
1396
1396
|
releaseOwner(lease: OwnerLease): void;
|
|
1397
1397
|
reserveAgent(lease: OwnerLease, input: {
|
package/dist/index.js
CHANGED
|
@@ -767,6 +767,15 @@ var EmptyResponseError = class extends Error {
|
|
|
767
767
|
this.name = "EmptyResponseError";
|
|
768
768
|
}
|
|
769
769
|
};
|
|
770
|
+
var ModelOutputLimitError = class extends Error {
|
|
771
|
+
constructor(limit) {
|
|
772
|
+
super(`Model output exceeded the ${limit}-character safety limit.`);
|
|
773
|
+
this.limit = limit;
|
|
774
|
+
this.name = "ModelOutputLimitError";
|
|
775
|
+
}
|
|
776
|
+
limit;
|
|
777
|
+
code = "model_output_limit";
|
|
778
|
+
};
|
|
770
779
|
var LoopGuard = {
|
|
771
780
|
/** Returns abort result if signal is aborted */
|
|
772
781
|
checkAbort(signal) {
|
|
@@ -778,6 +787,7 @@ var LoopGuard = {
|
|
|
778
787
|
};
|
|
779
788
|
|
|
780
789
|
// src/loop/stream-collector.ts
|
|
790
|
+
var MAX_STREAMED_OUTPUT_CHARACTERS = 1024 * 1024;
|
|
781
791
|
async function invokeModel(input) {
|
|
782
792
|
const events = input.config.stream(input.request, { signal: input.config.signal });
|
|
783
793
|
const result = await collectStreamResult({
|
|
@@ -811,7 +821,22 @@ async function collectStreamResult(input) {
|
|
|
811
821
|
let lastPartial;
|
|
812
822
|
let stopReason;
|
|
813
823
|
let doneResponse;
|
|
824
|
+
let streamedOutputCharacters = 0;
|
|
825
|
+
const toolCallsWithDeltas = /* @__PURE__ */ new Set();
|
|
814
826
|
for await (const event of input.events) {
|
|
827
|
+
if (event.type === "text_delta") {
|
|
828
|
+
streamedOutputCharacters += event.text.length;
|
|
829
|
+
} else if (event.type === "thinking_delta") {
|
|
830
|
+
streamedOutputCharacters += event.thinking.length;
|
|
831
|
+
} else if (event.type === "tool_call_delta") {
|
|
832
|
+
streamedOutputCharacters += event.arguments.length;
|
|
833
|
+
toolCallsWithDeltas.add(event.id);
|
|
834
|
+
} else if (event.type === "tool_call_end" && !toolCallsWithDeltas.has(event.id)) {
|
|
835
|
+
streamedOutputCharacters += event.arguments.length;
|
|
836
|
+
}
|
|
837
|
+
if (streamedOutputCharacters > MAX_STREAMED_OUTPUT_CHARACTERS) {
|
|
838
|
+
throw new ModelOutputLimitError(MAX_STREAMED_OUTPUT_CHARACTERS);
|
|
839
|
+
}
|
|
815
840
|
const abortResult2 = LoopGuard.checkAbort(input.config.signal);
|
|
816
841
|
if (abortResult2.stopReason !== "none") {
|
|
817
842
|
if (activeMessageId) {
|
|
@@ -4495,17 +4520,17 @@ var InMemoryStore = class _InMemoryStore {
|
|
|
4495
4520
|
};
|
|
4496
4521
|
return new MemoryOwnedStore(this, clone(this.owner));
|
|
4497
4522
|
}
|
|
4498
|
-
assertOwner(lease) {
|
|
4523
|
+
assertOwner(lease, requireLive = true) {
|
|
4499
4524
|
const actual = this.owner;
|
|
4500
4525
|
if (!actual || actual.token !== lease.token || actual.epoch !== lease.epoch || actual.ownerId !== lease.ownerId) {
|
|
4501
4526
|
throw ownershipLost(lease, actual, "epoch_advanced");
|
|
4502
4527
|
}
|
|
4503
|
-
if (Date.parse(actual.expiresAt) <= Date.now()) {
|
|
4528
|
+
if (requireLive && Date.parse(actual.expiresAt) <= Date.now()) {
|
|
4504
4529
|
throw ownershipLost(lease, actual, "expired");
|
|
4505
4530
|
}
|
|
4506
4531
|
}
|
|
4507
4532
|
renewOwner(lease, leaseMs) {
|
|
4508
|
-
this.assertOwner(lease);
|
|
4533
|
+
this.assertOwner(lease, false);
|
|
4509
4534
|
assertLeaseDuration(leaseMs);
|
|
4510
4535
|
this.owner.expiresAt = expiry(leaseMs);
|
|
4511
4536
|
return clone(this.owner);
|
|
@@ -4600,23 +4625,25 @@ var InMemoryStore = class _InMemoryStore {
|
|
|
4600
4625
|
if ([...this.runs.values()].some((candidate) => candidate.agentId === run.agentId && candidate.id !== run.id && ["running", "input_required"].includes(candidate.state))) {
|
|
4601
4626
|
throw new RuntimeError("run_state_conflict", { runId: run.id, expected: ["queued"], actual: run.state });
|
|
4602
4627
|
}
|
|
4603
|
-
const messageId = input.messageId ?? createId("msg");
|
|
4604
4628
|
if (run.pinnedConfigToken && input.configToken && run.pinnedConfigToken !== input.configToken) {
|
|
4605
4629
|
throw new RuntimeError("run_state_conflict", { runId: run.id, expected: ["queued"], actual: run.state });
|
|
4606
4630
|
}
|
|
4607
4631
|
if (!run.pinnedConfigToken && input.configToken) run.pinnedConfigToken = input.configToken;
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4632
|
+
let message;
|
|
4633
|
+
if (!run.checkpoint) {
|
|
4634
|
+
const userInput = normalizeUserInput(run.input);
|
|
4635
|
+
message = {
|
|
4636
|
+
id: input.messageId ?? createId("msg"),
|
|
4637
|
+
agentId: run.agentId,
|
|
4638
|
+
runId: run.id,
|
|
4639
|
+
role: "user",
|
|
4640
|
+
content: userInputContent(userInput),
|
|
4641
|
+
...userInputMetadata(userInput) ? { metadata: clone(userInputMetadata(userInput)) } : {},
|
|
4642
|
+
sequenceWithinRun: this.nextMessageSequence(run.id),
|
|
4643
|
+
createdAt: createTimestamp()
|
|
4644
|
+
};
|
|
4645
|
+
this.messages.set(message.id, message);
|
|
4646
|
+
}
|
|
4620
4647
|
const execution = {
|
|
4621
4648
|
runId: run.id,
|
|
4622
4649
|
ownerEpoch: lease.epoch,
|
|
@@ -4626,7 +4653,7 @@ var InMemoryStore = class _InMemoryStore {
|
|
|
4626
4653
|
run.execution = execution;
|
|
4627
4654
|
run.revision += 1;
|
|
4628
4655
|
run.updatedAt = createTimestamp();
|
|
4629
|
-
this.appendMessage(run, message);
|
|
4656
|
+
if (message) this.appendMessage(run, message);
|
|
4630
4657
|
this.appendTransition(run, "queued", "running");
|
|
4631
4658
|
const result = { run: clone(run), execution: clone(execution), history: this.history(run.agentId, run.agentSequence) };
|
|
4632
4659
|
this.writeOperationReceipt(operationKey, operationPayload, result);
|
|
@@ -5533,7 +5560,7 @@ var SqliteStore = class {
|
|
|
5533
5560
|
this.assertOpen();
|
|
5534
5561
|
assertOwnerInput(lease.ownerId, leaseMs);
|
|
5535
5562
|
return this.immediateTransaction(() => {
|
|
5536
|
-
const row = this.requireMatchingOwner(lease,
|
|
5563
|
+
const row = this.requireMatchingOwner(lease, false);
|
|
5537
5564
|
const expiresAt = Date.now() + leaseMs;
|
|
5538
5565
|
this.writeOwner({ ...row, expires_at: expiresAt });
|
|
5539
5566
|
return { ...lease, expiresAt: new Date(expiresAt).toISOString() };
|