@cortexkit/anthropic-auth-core 2.7.1 → 2.7.3
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/dump.d.ts +14 -0
- package/dist/index.js +105 -4
- package/package.json +3 -3
package/dist/dump.d.ts
CHANGED
|
@@ -71,10 +71,24 @@ export declare function dumpRelayRequest(input: {
|
|
|
71
71
|
relayBytes: number;
|
|
72
72
|
tag?: DumpTag;
|
|
73
73
|
}): Promise<DumpHandle | null>;
|
|
74
|
+
export type ReplyTextEdge = {
|
|
75
|
+
index: number;
|
|
76
|
+
leading: number;
|
|
77
|
+
trailing: number;
|
|
78
|
+
chars: number;
|
|
79
|
+
};
|
|
80
|
+
/** Summarize parsed provider events without retaining any reply text. */
|
|
81
|
+
export declare function createDumpResponseObserver(handle: DumpHandle | null, status: number): {
|
|
82
|
+
observe(event: Record<string, unknown>): void;
|
|
83
|
+
replyTextEdges: () => ReplyTextEdge[] | undefined;
|
|
84
|
+
fail(): void;
|
|
85
|
+
finish(): Promise<void>;
|
|
86
|
+
};
|
|
74
87
|
export declare function dumpResponseArtifact(handle: DumpHandle | null, input: {
|
|
75
88
|
status: number;
|
|
76
89
|
message: unknown;
|
|
77
90
|
complete?: boolean;
|
|
78
91
|
provider_error?: ProviderErrorSummary['provider_error'];
|
|
92
|
+
reply_text_edges?: readonly ReplyTextEdge[];
|
|
79
93
|
}): Promise<void>;
|
|
80
94
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -14482,6 +14482,100 @@ async function dumpRelayRequest(input) {
|
|
|
14482
14482
|
tag: input.tag
|
|
14483
14483
|
});
|
|
14484
14484
|
}
|
|
14485
|
+
function createDumpResponseObserver(handle, status) {
|
|
14486
|
+
const edges = new Map;
|
|
14487
|
+
let message;
|
|
14488
|
+
let complete = false;
|
|
14489
|
+
let failed = false;
|
|
14490
|
+
const record3 = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
14491
|
+
const replyTextEdges = () => message && !failed && status >= 200 && status < 300 ? [...edges.values()] : undefined;
|
|
14492
|
+
const append = (edge, text) => {
|
|
14493
|
+
if (typeof text !== "string")
|
|
14494
|
+
return;
|
|
14495
|
+
let leading = 0;
|
|
14496
|
+
while (leading < text.length && /\s/u.test(text.charAt(leading)))
|
|
14497
|
+
leading++;
|
|
14498
|
+
if (edge.leading === edge.chars)
|
|
14499
|
+
edge.leading += leading;
|
|
14500
|
+
let trailing = 0;
|
|
14501
|
+
while (trailing < text.length && /\s/u.test(text.charAt(text.length - trailing - 1)))
|
|
14502
|
+
trailing++;
|
|
14503
|
+
edge.trailing = trailing === text.length ? edge.trailing + trailing : trailing;
|
|
14504
|
+
edge.chars += text.length;
|
|
14505
|
+
};
|
|
14506
|
+
const start = (index, block) => {
|
|
14507
|
+
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0 || !block || typeof block !== "object" || block.type !== "text" || edges.has(index))
|
|
14508
|
+
return;
|
|
14509
|
+
const edge = { index, leading: 0, trailing: 0, chars: 0 };
|
|
14510
|
+
edges.set(index, edge);
|
|
14511
|
+
append(edge, block.text);
|
|
14512
|
+
};
|
|
14513
|
+
return {
|
|
14514
|
+
observe(event) {
|
|
14515
|
+
if (!handle)
|
|
14516
|
+
return;
|
|
14517
|
+
if (event.type === "message_start") {
|
|
14518
|
+
const opening = event.message;
|
|
14519
|
+
if (!opening || typeof opening !== "object")
|
|
14520
|
+
return;
|
|
14521
|
+
message = {};
|
|
14522
|
+
for (const key of [
|
|
14523
|
+
"id",
|
|
14524
|
+
"model",
|
|
14525
|
+
"usage",
|
|
14526
|
+
"diagnostics",
|
|
14527
|
+
"stop_reason"
|
|
14528
|
+
]) {
|
|
14529
|
+
if (Object.hasOwn(opening, key))
|
|
14530
|
+
message[key] = opening[key];
|
|
14531
|
+
}
|
|
14532
|
+
if (Array.isArray(opening.content)) {
|
|
14533
|
+
for (const [index, block] of opening.content.entries())
|
|
14534
|
+
start(index, block);
|
|
14535
|
+
}
|
|
14536
|
+
} else if (event.type === "content_block_start") {
|
|
14537
|
+
start(event.index, event.content_block);
|
|
14538
|
+
} else if (event.type === "content_block_delta") {
|
|
14539
|
+
const delta = event.delta;
|
|
14540
|
+
const edge = typeof event.index === "number" ? edges.get(event.index) : undefined;
|
|
14541
|
+
if (edge && delta?.type === "text_delta")
|
|
14542
|
+
append(edge, delta.text);
|
|
14543
|
+
} else if (event.type === "message_delta" && message) {
|
|
14544
|
+
const nested = record3(event.message);
|
|
14545
|
+
const usage = record3(event.usage) ?? record3(nested?.usage);
|
|
14546
|
+
const delta = record3(event.delta);
|
|
14547
|
+
const stopReason = [
|
|
14548
|
+
delta?.stop_reason,
|
|
14549
|
+
event.stop_reason,
|
|
14550
|
+
...usage ? [nested?.stop_reason] : []
|
|
14551
|
+
].find((value) => typeof value === "string");
|
|
14552
|
+
if (usage || stopReason) {
|
|
14553
|
+
if (usage)
|
|
14554
|
+
message.usage = { ...message.usage, ...usage };
|
|
14555
|
+
if (stopReason)
|
|
14556
|
+
message.stop_reason = stopReason;
|
|
14557
|
+
complete = true;
|
|
14558
|
+
}
|
|
14559
|
+
} else if (event.type === "error") {
|
|
14560
|
+
failed = true;
|
|
14561
|
+
}
|
|
14562
|
+
},
|
|
14563
|
+
replyTextEdges,
|
|
14564
|
+
fail() {
|
|
14565
|
+
failed = true;
|
|
14566
|
+
},
|
|
14567
|
+
async finish() {
|
|
14568
|
+
if (!message)
|
|
14569
|
+
return;
|
|
14570
|
+
await dumpResponseArtifact(handle, {
|
|
14571
|
+
status,
|
|
14572
|
+
message,
|
|
14573
|
+
complete: complete && !failed,
|
|
14574
|
+
...complete ? { reply_text_edges: replyTextEdges() } : {}
|
|
14575
|
+
});
|
|
14576
|
+
}
|
|
14577
|
+
};
|
|
14578
|
+
}
|
|
14485
14579
|
async function dumpResponseArtifact(handle, input) {
|
|
14486
14580
|
if (!handle)
|
|
14487
14581
|
return;
|
|
@@ -14502,6 +14596,13 @@ async function dumpResponseArtifact(handle, input) {
|
|
|
14502
14596
|
artifact.stop_reason = message.stop_reason;
|
|
14503
14597
|
if (input.provider_error)
|
|
14504
14598
|
artifact.provider_error = input.provider_error;
|
|
14599
|
+
if (input.reply_text_edges && input.complete !== false && input.status >= 200 && input.status < 300 && !input.provider_error)
|
|
14600
|
+
artifact.reply_text_edges = input.reply_text_edges.map(({ index, leading, trailing, chars }) => ({
|
|
14601
|
+
index,
|
|
14602
|
+
leading,
|
|
14603
|
+
trailing,
|
|
14604
|
+
chars
|
|
14605
|
+
}));
|
|
14505
14606
|
try {
|
|
14506
14607
|
await writeDumpFile(handle.responsePath, `${JSON.stringify(artifact, null, 2)}
|
|
14507
14608
|
`);
|
|
@@ -17062,7 +17163,7 @@ class CacheKeepManager2 {
|
|
|
17062
17163
|
}
|
|
17063
17164
|
track(input) {
|
|
17064
17165
|
const now = this.options.now?.() ?? Date.now();
|
|
17065
|
-
const acceptedAt = input.acceptedAt ?? now;
|
|
17166
|
+
const acceptedAt = input.acceptedAt ?? input.retained?.lastTouchAt ?? now;
|
|
17066
17167
|
if (input.retained && input.retained.cacheExpiresAt <= now)
|
|
17067
17168
|
return { tracked: false, reason: "cache expired" };
|
|
17068
17169
|
let bodyBytes;
|
|
@@ -17102,7 +17203,7 @@ class CacheKeepManager2 {
|
|
|
17102
17203
|
this.removeTarget(previous, reason, now);
|
|
17103
17204
|
return refuse(reason, reason);
|
|
17104
17205
|
};
|
|
17105
|
-
if (input.retained && (planned || isCacheKeepAlways(input.storage)) &&
|
|
17206
|
+
if (input.retained && (planned || isCacheKeepAlways(input.storage)) && input.retained.policyState?.needsRealRequest)
|
|
17106
17207
|
return retire("unsupported");
|
|
17107
17208
|
if (!policy && (input.retained?.policyState?.planned || previous?.policyState?.planned))
|
|
17108
17209
|
return retire("session-ended");
|
|
@@ -17189,8 +17290,7 @@ class CacheKeepManager2 {
|
|
|
17189
17290
|
lastRealRequestAt: acceptedAt,
|
|
17190
17291
|
warmsSinceLastRealRequest: 0,
|
|
17191
17292
|
warmCostSoFar: 0,
|
|
17192
|
-
hasWarmed: previous?.policyState?.hasWarmed ?? false
|
|
17193
|
-
...input.retained && { needsRealRequest: true }
|
|
17293
|
+
hasWarmed: input.retained ? false : previous?.policyState?.hasWarmed ?? false
|
|
17194
17294
|
},
|
|
17195
17295
|
...input.sourceWarm === true && { sourceWarm: true }
|
|
17196
17296
|
});
|
|
@@ -44271,6 +44371,7 @@ export {
|
|
|
44271
44371
|
createNativeCustody,
|
|
44272
44372
|
createNativeAccountRuntime,
|
|
44273
44373
|
createEmptyStorage,
|
|
44374
|
+
createDumpResponseObserver,
|
|
44274
44375
|
createAnthropicOAuthFetch,
|
|
44275
44376
|
countUserPrompts,
|
|
44276
44377
|
connectVaultHost,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/anthropic-auth-core",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"@cortexkit/common-auth": "0.42.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@cortexkit/claustrum-client": "0.
|
|
36
|
+
"@cortexkit/claustrum-client": "0.17.0",
|
|
37
37
|
"@cortexkit/private-files": "0.2.2",
|
|
38
|
-
"@cortexkit/subc-client": "^0.
|
|
38
|
+
"@cortexkit/subc-client": "^0.24",
|
|
39
39
|
"jsonc-parser": "^3.3.1",
|
|
40
40
|
"xxhash-wasm": "^1.1.0"
|
|
41
41
|
}
|