@anthropic-ai/sdk 0.55.0 → 0.55.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.
- package/CHANGELOG.md +16 -0
- package/internal/types.d.mts +8 -6
- package/internal/types.d.mts.map +1 -1
- package/internal/types.d.ts +8 -6
- package/internal/types.d.ts.map +1 -1
- package/internal/uploads.js +1 -1
- package/internal/uploads.js.map +1 -1
- package/internal/uploads.mjs +1 -1
- package/internal/uploads.mjs.map +1 -1
- package/internal/utils/log.js +1 -1
- package/internal/utils/log.js.map +1 -1
- package/internal/utils/log.mjs +1 -1
- package/internal/utils/log.mjs.map +1 -1
- package/internal/utils/path.d.mts.map +1 -1
- package/internal/utils/path.d.ts.map +1 -1
- package/internal/utils/path.js +26 -5
- package/internal/utils/path.js.map +1 -1
- package/internal/utils/path.mjs +26 -5
- package/internal/utils/path.mjs.map +1 -1
- package/lib/BetaMessageStream.d.mts.map +1 -1
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +20 -7
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +20 -7
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/MessageStream.d.mts.map +1 -1
- package/lib/MessageStream.d.ts.map +1 -1
- package/lib/MessageStream.js +21 -8
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +21 -8
- package/lib/MessageStream.mjs.map +1 -1
- package/package.json +1 -1
- package/src/internal/types.ts +9 -6
- package/src/internal/uploads.ts +1 -1
- package/src/internal/utils/log.ts +1 -1
- package/src/internal/utils/path.ts +30 -7
- package/src/lib/BetaMessageStream.ts +20 -7
- package/src/lib/MessageStream.ts +21 -8
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/internal/types.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
|
|
7
7
|
|
|
8
8
|
export type FinalizedRequestInit = RequestInit & { headers: Headers };
|
|
9
9
|
|
|
10
|
-
type NotAny<T> = [
|
|
10
|
+
type NotAny<T> = [0] extends [1 & T] ? never : T;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Some environments overload the global fetch function, and Parameters<T> only gets the last signature.
|
|
@@ -64,13 +64,15 @@ type OverloadedParameters<T> =
|
|
|
64
64
|
* [1]: https://www.typescriptlang.org/tsconfig/#typeAcquisition
|
|
65
65
|
*/
|
|
66
66
|
/** @ts-ignore For users with \@types/node */
|
|
67
|
-
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types').RequestInit> | NotAny<import('../../node_modules/undici-types').RequestInit> | NotAny<import('../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types').RequestInit>;
|
|
67
|
+
type UndiciTypesRequestInit = NotAny<import('../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici-types/index.d.ts').RequestInit>;
|
|
68
68
|
/** @ts-ignore For users with undici */
|
|
69
|
-
type UndiciRequestInit = NotAny<import('../node_modules/undici').RequestInit> | NotAny<import('../../node_modules/undici').RequestInit> | NotAny<import('../../../node_modules/undici').RequestInit> | NotAny<import('../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici').RequestInit>;
|
|
69
|
+
type UndiciRequestInit = NotAny<import('../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/undici/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/undici/index.d.ts').RequestInit>;
|
|
70
70
|
/** @ts-ignore For users with \@types/bun */
|
|
71
71
|
type BunRequestInit = globalThis.FetchRequestInit;
|
|
72
|
-
/** @ts-ignore For users with node-fetch */
|
|
73
|
-
type
|
|
72
|
+
/** @ts-ignore For users with node-fetch@2 */
|
|
73
|
+
type NodeFetch2RequestInit = NotAny<import('../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/@types/node-fetch/index.d.ts').RequestInit>;
|
|
74
|
+
/** @ts-ignore For users with node-fetch@3, doesn't need file extension because types are at ./@types/index.d.ts */
|
|
75
|
+
type NodeFetch3RequestInit = NotAny<import('../node_modules/node-fetch').RequestInit> | NotAny<import('../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../node_modules/node-fetch').RequestInit> | NotAny<import('../../../../../../../../../../node_modules/node-fetch').RequestInit>;
|
|
74
76
|
/** @ts-ignore For users who use Deno */
|
|
75
77
|
type FetchRequestInit = NonNullable<OverloadedParameters<typeof fetch>[1]>;
|
|
76
78
|
/* eslint-enable */
|
|
@@ -79,7 +81,8 @@ type RequestInits =
|
|
|
79
81
|
| NotAny<UndiciTypesRequestInit>
|
|
80
82
|
| NotAny<UndiciRequestInit>
|
|
81
83
|
| NotAny<BunRequestInit>
|
|
82
|
-
| NotAny<
|
|
84
|
+
| NotAny<NodeFetch2RequestInit>
|
|
85
|
+
| NotAny<NodeFetch3RequestInit>
|
|
83
86
|
| NotAny<RequestInit>
|
|
84
87
|
| NotAny<FetchRequestInit>;
|
|
85
88
|
|
package/src/internal/uploads.ts
CHANGED
|
@@ -90,7 +90,7 @@ export const multipartFormRequestOptions = async (
|
|
|
90
90
|
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
const supportsFormDataMap =
|
|
93
|
+
const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>();
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* node-fetch doesn't support the global FormData object in recent node versions. Instead of sending
|
|
@@ -58,7 +58,7 @@ const noopLogger = {
|
|
|
58
58
|
debug: noop,
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
let cachedLoggers =
|
|
61
|
+
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
62
|
|
|
63
63
|
export function loggerFor(client: BaseAnthropic): Logger {
|
|
64
64
|
const logger = client.logger;
|
|
@@ -12,25 +12,43 @@ export function encodeURIPath(str: string) {
|
|
|
12
12
|
return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
16
|
+
|
|
15
17
|
export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
16
18
|
function path(statics: readonly string[], ...params: readonly unknown[]): string {
|
|
17
19
|
// If there are no params, no processing is needed.
|
|
18
20
|
if (statics.length === 1) return statics[0]!;
|
|
19
21
|
|
|
20
22
|
let postPath = false;
|
|
23
|
+
const invalidSegments = [];
|
|
21
24
|
const path = statics.reduce((previousValue, currentValue, index) => {
|
|
22
25
|
if (/[?#]/.test(currentValue)) {
|
|
23
26
|
postPath = true;
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const value = params[index];
|
|
29
|
+
let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
|
|
30
|
+
if (
|
|
31
|
+
index !== params.length &&
|
|
32
|
+
(value == null ||
|
|
33
|
+
(typeof value === 'object' &&
|
|
34
|
+
// handle values from other realms
|
|
35
|
+
value.toString ===
|
|
36
|
+
Object.getPrototypeOf(Object.getPrototypeOf((value as any).hasOwnProperty ?? EMPTY) ?? EMPTY)
|
|
37
|
+
?.toString))
|
|
38
|
+
) {
|
|
39
|
+
encoded = value + '';
|
|
40
|
+
invalidSegments.push({
|
|
41
|
+
start: previousValue.length + currentValue.length,
|
|
42
|
+
length: encoded.length,
|
|
43
|
+
error: `Value of type ${Object.prototype.toString
|
|
44
|
+
.call(value)
|
|
45
|
+
.slice(8, -1)} is not a valid path parameter`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return previousValue + currentValue + (index === params.length ? '' : encoded);
|
|
30
49
|
}, '');
|
|
31
50
|
|
|
32
51
|
const pathOnly = path.split(/[?#]/, 1)[0]!;
|
|
33
|
-
const invalidSegments = [];
|
|
34
52
|
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
35
53
|
let match;
|
|
36
54
|
|
|
@@ -39,9 +57,12 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
39
57
|
invalidSegments.push({
|
|
40
58
|
start: match.index,
|
|
41
59
|
length: match[0].length,
|
|
60
|
+
error: `Value "${match[0]}" can\'t be safely passed as a path parameter`,
|
|
42
61
|
});
|
|
43
62
|
}
|
|
44
63
|
|
|
64
|
+
invalidSegments.sort((a, b) => a.start - b.start);
|
|
65
|
+
|
|
45
66
|
if (invalidSegments.length > 0) {
|
|
46
67
|
let lastEnd = 0;
|
|
47
68
|
const underline = invalidSegments.reduce((acc, segment) => {
|
|
@@ -52,7 +73,9 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
52
73
|
}, '');
|
|
53
74
|
|
|
54
75
|
throw new AnthropicError(
|
|
55
|
-
`Path parameters result in path with invalid segments:\n${
|
|
76
|
+
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
|
+
.map((e) => e.error)
|
|
78
|
+
.join('\n')}\n${path}\n${underline}`,
|
|
56
79
|
);
|
|
57
80
|
}
|
|
58
81
|
|
|
@@ -583,14 +583,19 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
583
583
|
switch (event.delta.type) {
|
|
584
584
|
case 'text_delta': {
|
|
585
585
|
if (snapshotContent?.type === 'text') {
|
|
586
|
-
|
|
586
|
+
snapshot.content[event.index] = {
|
|
587
|
+
...snapshotContent,
|
|
588
|
+
text: (snapshotContent.text || '') + event.delta.text,
|
|
589
|
+
};
|
|
587
590
|
}
|
|
588
591
|
break;
|
|
589
592
|
}
|
|
590
593
|
case 'citations_delta': {
|
|
591
594
|
if (snapshotContent?.type === 'text') {
|
|
592
|
-
|
|
593
|
-
|
|
595
|
+
snapshot.content[event.index] = {
|
|
596
|
+
...snapshotContent,
|
|
597
|
+
citations: [...(snapshotContent.citations ?? []), event.delta.citation],
|
|
598
|
+
};
|
|
594
599
|
}
|
|
595
600
|
break;
|
|
596
601
|
}
|
|
@@ -602,7 +607,8 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
602
607
|
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
|
|
603
608
|
jsonBuf += event.delta.partial_json;
|
|
604
609
|
|
|
605
|
-
|
|
610
|
+
const newContent = { ...snapshotContent };
|
|
611
|
+
Object.defineProperty(newContent, JSON_BUF_PROPERTY, {
|
|
606
612
|
value: jsonBuf,
|
|
607
613
|
enumerable: false,
|
|
608
614
|
writable: true,
|
|
@@ -610,7 +616,7 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
610
616
|
|
|
611
617
|
if (jsonBuf) {
|
|
612
618
|
try {
|
|
613
|
-
|
|
619
|
+
newContent.input = partialParse(jsonBuf);
|
|
614
620
|
} catch (err) {
|
|
615
621
|
const error = new AnthropicError(
|
|
616
622
|
`Unable to parse tool parameter JSON from model. Please retry your request or adjust your prompt. Error: ${err}. JSON: ${jsonBuf}`,
|
|
@@ -618,18 +624,25 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
618
624
|
this.#handleError(error);
|
|
619
625
|
}
|
|
620
626
|
}
|
|
627
|
+
snapshot.content[event.index] = newContent;
|
|
621
628
|
}
|
|
622
629
|
break;
|
|
623
630
|
}
|
|
624
631
|
case 'thinking_delta': {
|
|
625
632
|
if (snapshotContent?.type === 'thinking') {
|
|
626
|
-
|
|
633
|
+
snapshot.content[event.index] = {
|
|
634
|
+
...snapshotContent,
|
|
635
|
+
thinking: snapshotContent.thinking + event.delta.thinking,
|
|
636
|
+
};
|
|
627
637
|
}
|
|
628
638
|
break;
|
|
629
639
|
}
|
|
630
640
|
case 'signature_delta': {
|
|
631
641
|
if (snapshotContent?.type === 'thinking') {
|
|
632
|
-
|
|
642
|
+
snapshot.content[event.index] = {
|
|
643
|
+
...snapshotContent,
|
|
644
|
+
signature: event.delta.signature,
|
|
645
|
+
};
|
|
633
646
|
}
|
|
634
647
|
break;
|
|
635
648
|
}
|
package/src/lib/MessageStream.ts
CHANGED
|
@@ -574,7 +574,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
574
574
|
|
|
575
575
|
return snapshot;
|
|
576
576
|
case 'content_block_start':
|
|
577
|
-
snapshot.content.push(event.content_block);
|
|
577
|
+
snapshot.content.push({ ...event.content_block });
|
|
578
578
|
return snapshot;
|
|
579
579
|
case 'content_block_delta': {
|
|
580
580
|
const snapshotContent = snapshot.content.at(event.index);
|
|
@@ -582,14 +582,19 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
582
582
|
switch (event.delta.type) {
|
|
583
583
|
case 'text_delta': {
|
|
584
584
|
if (snapshotContent?.type === 'text') {
|
|
585
|
-
|
|
585
|
+
snapshot.content[event.index] = {
|
|
586
|
+
...snapshotContent,
|
|
587
|
+
text: (snapshotContent.text || '') + event.delta.text,
|
|
588
|
+
};
|
|
586
589
|
}
|
|
587
590
|
break;
|
|
588
591
|
}
|
|
589
592
|
case 'citations_delta': {
|
|
590
593
|
if (snapshotContent?.type === 'text') {
|
|
591
|
-
|
|
592
|
-
|
|
594
|
+
snapshot.content[event.index] = {
|
|
595
|
+
...snapshotContent,
|
|
596
|
+
citations: [...(snapshotContent.citations ?? []), event.delta.citation],
|
|
597
|
+
};
|
|
593
598
|
}
|
|
594
599
|
break;
|
|
595
600
|
}
|
|
@@ -601,27 +606,35 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
601
606
|
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
|
|
602
607
|
jsonBuf += event.delta.partial_json;
|
|
603
608
|
|
|
604
|
-
|
|
609
|
+
const newContent = { ...snapshotContent };
|
|
610
|
+
Object.defineProperty(newContent, JSON_BUF_PROPERTY, {
|
|
605
611
|
value: jsonBuf,
|
|
606
612
|
enumerable: false,
|
|
607
613
|
writable: true,
|
|
608
614
|
});
|
|
609
615
|
|
|
610
616
|
if (jsonBuf) {
|
|
611
|
-
|
|
617
|
+
newContent.input = partialParse(jsonBuf);
|
|
612
618
|
}
|
|
619
|
+
snapshot.content[event.index] = newContent;
|
|
613
620
|
}
|
|
614
621
|
break;
|
|
615
622
|
}
|
|
616
623
|
case 'thinking_delta': {
|
|
617
624
|
if (snapshotContent?.type === 'thinking') {
|
|
618
|
-
|
|
625
|
+
snapshot.content[event.index] = {
|
|
626
|
+
...snapshotContent,
|
|
627
|
+
thinking: snapshotContent.thinking + event.delta.thinking,
|
|
628
|
+
};
|
|
619
629
|
}
|
|
620
630
|
break;
|
|
621
631
|
}
|
|
622
632
|
case 'signature_delta': {
|
|
623
633
|
if (snapshotContent?.type === 'thinking') {
|
|
624
|
-
|
|
634
|
+
snapshot.content[event.index] = {
|
|
635
|
+
...snapshotContent,
|
|
636
|
+
signature: event.delta.signature,
|
|
637
|
+
};
|
|
625
638
|
}
|
|
626
639
|
break;
|
|
627
640
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.55.
|
|
1
|
+
export const VERSION = '0.55.1'; // x-release-please-version
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.55.
|
|
1
|
+
export declare const VERSION = "0.55.1";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.55.
|
|
1
|
+
export declare const VERSION = "0.55.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.js
CHANGED
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.55.
|
|
1
|
+
export const VERSION = '0.55.1'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|