@celljs/ai-anthropic 3.7.8 → 3.9.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 (100) hide show
  1. package/esm/common/api/anthropic-api.d.ts +15 -0
  2. package/esm/common/api/anthropic-api.js +93 -0
  3. package/esm/common/api/anthropic-api.js.map +1 -0
  4. package/esm/common/api/anthropic-model.d.ts +33 -0
  5. package/esm/common/api/anthropic-model.js +36 -0
  6. package/esm/common/api/anthropic-model.js.map +1 -0
  7. package/esm/common/api/api-protocol.d.ts +40 -0
  8. package/esm/common/api/api-protocol.js +3 -0
  9. package/esm/common/api/api-protocol.js.map +1 -0
  10. package/esm/common/api/chat-request.d.ts +149 -0
  11. package/esm/common/api/chat-request.js +184 -0
  12. package/esm/common/api/chat-request.js.map +1 -0
  13. package/esm/common/api/chat-response.d.ts +71 -0
  14. package/esm/common/api/chat-response.js +120 -0
  15. package/esm/common/api/chat-response.js.map +1 -0
  16. package/esm/common/api/content-block.d.ts +99 -0
  17. package/esm/common/api/content-block.js +127 -0
  18. package/esm/common/api/content-block.js.map +1 -0
  19. package/esm/common/api/event.d.ts +187 -0
  20. package/esm/common/api/event.js +344 -0
  21. package/esm/common/api/event.js.map +1 -0
  22. package/esm/common/api/index.d.ts +9 -0
  23. package/esm/common/api/index.js +10 -0
  24. package/esm/common/api/index.js.map +1 -0
  25. package/esm/common/api/message.d.ts +40 -0
  26. package/esm/common/api/message.js +54 -0
  27. package/esm/common/api/message.js.map +1 -0
  28. package/esm/common/api/usage.d.ts +14 -0
  29. package/esm/common/api/usage.js +28 -0
  30. package/esm/common/api/usage.js.map +1 -0
  31. package/esm/common/index.d.ts +2 -0
  32. package/esm/common/index.js +3 -0
  33. package/esm/common/index.js.map +1 -0
  34. package/esm/common/model/anthropic-chat-model.d.ts +19 -0
  35. package/esm/common/model/anthropic-chat-model.js +169 -0
  36. package/esm/common/model/anthropic-chat-model.js.map +1 -0
  37. package/esm/common/model/anthropic-chat-options.d.ts +54 -0
  38. package/esm/common/model/anthropic-chat-options.js +170 -0
  39. package/esm/common/model/anthropic-chat-options.js.map +1 -0
  40. package/esm/common/model/index.d.ts +2 -0
  41. package/esm/common/model/index.js +3 -0
  42. package/esm/common/model/index.js.map +1 -0
  43. package/esm/common/module.d.ts +3 -0
  44. package/esm/common/module.js +4 -0
  45. package/esm/common/module.js.map +1 -0
  46. package/esm/common/test/mock-anthropic-api.d.ts +9 -0
  47. package/esm/common/test/mock-anthropic-api.js +61 -0
  48. package/esm/common/test/mock-anthropic-api.js.map +1 -0
  49. package/esm/common/test/test-container.d.ts +2 -0
  50. package/esm/common/test/test-container.js +11 -0
  51. package/esm/common/test/test-container.js.map +1 -0
  52. package/esm/common/utils/index.d.ts +1 -0
  53. package/esm/common/utils/index.js +2 -0
  54. package/esm/common/utils/index.js.map +1 -0
  55. package/esm/common/utils/stream-util.d.ts +8 -0
  56. package/esm/common/utils/stream-util.js +110 -0
  57. package/esm/common/utils/stream-util.js.map +1 -0
  58. package/esm/package.json +3 -0
  59. package/lib/common/api/anthropic-api.d.ts.map +1 -1
  60. package/lib/common/api/anthropic-api.js +9 -6
  61. package/lib/common/api/anthropic-api.js.map +1 -1
  62. package/lib/common/api/anthropic-api.spec.d.ts.map +1 -1
  63. package/lib/common/api/anthropic-api.spec.js +9 -8
  64. package/lib/common/api/anthropic-api.spec.js.map +1 -1
  65. package/lib/common/api/anthropic-model.js.map +1 -1
  66. package/lib/common/api/chat-request.d.ts.map +1 -1
  67. package/lib/common/api/chat-request.js.map +1 -1
  68. package/lib/common/api/chat-response.d.ts.map +1 -1
  69. package/lib/common/api/chat-response.js.map +1 -1
  70. package/lib/common/api/content-block.d.ts.map +1 -1
  71. package/lib/common/api/content-block.js.map +1 -1
  72. package/lib/common/api/event.d.ts.map +1 -1
  73. package/lib/common/api/event.js.map +1 -1
  74. package/lib/common/api/message.d.ts.map +1 -1
  75. package/lib/common/api/message.js.map +1 -1
  76. package/lib/common/api/usage.d.ts.map +1 -1
  77. package/lib/common/api/usage.js.map +1 -1
  78. package/lib/common/model/anthropic-chat-model.d.ts.map +1 -1
  79. package/lib/common/model/anthropic-chat-model.js.map +1 -1
  80. package/lib/common/model/anthropic-chat-model.spec.d.ts.map +1 -1
  81. package/lib/common/model/anthropic-chat-model.spec.js +9 -8
  82. package/lib/common/model/anthropic-chat-model.spec.js.map +1 -1
  83. package/lib/common/model/anthropic-chat-options.d.ts.map +1 -1
  84. package/lib/common/model/anthropic-chat-options.js.map +1 -1
  85. package/lib/common/module.d.ts.map +1 -1
  86. package/lib/common/module.js.map +1 -1
  87. package/lib/common/test/mock-anthropic-api.d.ts.map +1 -1
  88. package/lib/common/test/mock-anthropic-api.js.map +1 -1
  89. package/lib/common/test/test-container.js +4 -1
  90. package/lib/common/test/test-container.js.map +1 -1
  91. package/lib/common/utils/stream-util.d.ts.map +1 -1
  92. package/lib/common/utils/stream-util.js.map +1 -1
  93. package/lib/package.spec.d.ts +1 -0
  94. package/lib/package.spec.js +5 -2
  95. package/lib/package.spec.js.map +1 -1
  96. package/package.json +48 -13
  97. package/src/common/api/anthropic-api.spec.ts +1 -0
  98. package/src/common/model/anthropic-chat-model.spec.ts +2 -1
  99. package/src/package.spec.ts +1 -0
  100. package/LICENSE +0 -21
@@ -0,0 +1,120 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Expose, Type } from 'class-transformer';
11
+ import { Role } from './message.js';
12
+ import { Assert } from '@celljs/core';
13
+ import { ContentBlock } from './content-block.js';
14
+ import { Usage } from './usage.js';
15
+ /**
16
+ * Chat completion response object.
17
+ */
18
+ export class ChatResponse {
19
+ constructor(id, type, role, content, model, stopReason, stopSequence, usage) {
20
+ this.id = id;
21
+ this.type = type;
22
+ this.role = role;
23
+ this.content = content;
24
+ this.model = model;
25
+ this.stopReason = stopReason;
26
+ this.stopSequence = stopSequence;
27
+ this.usage = usage;
28
+ }
29
+ static builder() {
30
+ return new ChatResponseBuilder();
31
+ }
32
+ }
33
+ __decorate([
34
+ Expose(),
35
+ __metadata("design:type", String)
36
+ ], ChatResponse.prototype, "id", void 0);
37
+ __decorate([
38
+ Expose(),
39
+ __metadata("design:type", String)
40
+ ], ChatResponse.prototype, "type", void 0);
41
+ __decorate([
42
+ Expose(),
43
+ __metadata("design:type", String)
44
+ ], ChatResponse.prototype, "role", void 0);
45
+ __decorate([
46
+ Type(() => ContentBlock),
47
+ __metadata("design:type", Array)
48
+ ], ChatResponse.prototype, "content", void 0);
49
+ __decorate([
50
+ Expose(),
51
+ __metadata("design:type", String)
52
+ ], ChatResponse.prototype, "model", void 0);
53
+ __decorate([
54
+ Expose({ name: 'stop_reason' }),
55
+ __metadata("design:type", String)
56
+ ], ChatResponse.prototype, "stopReason", void 0);
57
+ __decorate([
58
+ Expose({ name: 'stop_sequence' }),
59
+ __metadata("design:type", String)
60
+ ], ChatResponse.prototype, "stopSequence", void 0);
61
+ __decorate([
62
+ Expose(),
63
+ __metadata("design:type", Usage)
64
+ ], ChatResponse.prototype, "usage", void 0);
65
+ export class ChatResponseBuilder {
66
+ constructor() {
67
+ }
68
+ withType(type) {
69
+ this.type = type;
70
+ return this;
71
+ }
72
+ withId(id) {
73
+ this.id = id;
74
+ return this;
75
+ }
76
+ withRole(role) {
77
+ this.role = role;
78
+ return this;
79
+ }
80
+ withContent(content) {
81
+ this.content = content;
82
+ return this;
83
+ }
84
+ withModel(model) {
85
+ this.model = model;
86
+ return this;
87
+ }
88
+ withStopReason(stopReason) {
89
+ this.stopReason = stopReason;
90
+ return this;
91
+ }
92
+ withStopSequence(stopSequence) {
93
+ this.stopSequence = stopSequence;
94
+ return this;
95
+ }
96
+ withUsage(usage) {
97
+ this.usage = usage;
98
+ return this;
99
+ }
100
+ withOutputTokens(outputTokens) {
101
+ Assert.isTrue(!!this.usage, 'Usage must be set before setting output tokens');
102
+ this.usage.outputTokens = outputTokens;
103
+ return this;
104
+ }
105
+ build() {
106
+ return new ChatResponse(this.id, this.type, this.role, this.content, this.model, this.stopReason, this.stopSequence, this.usage);
107
+ }
108
+ }
109
+ export class ChatResponseBuilderReference {
110
+ static get() {
111
+ if (!this.instance) {
112
+ this.instance = new ChatResponseBuilder();
113
+ }
114
+ return this.instance;
115
+ }
116
+ static reset() {
117
+ this.instance = new ChatResponseBuilder();
118
+ }
119
+ }
120
+ //# sourceMappingURL=chat-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-response.js","sourceRoot":"","sources":["../../../src/common/api/chat-response.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;GAEG;AACH,MAAM,OAAO,YAAY;IAqDrB,YACI,EAAU,EACV,IAAY,EACZ,IAAU,EACV,OAAuB,EACvB,KAAa,EACb,UAAkB,EAClB,YAAgC,EAChC,KAAU;QAEV,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI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tool result back to LLM.
11
+ */
12
+ TOOL_RESULT = "tool_result",
13
+ /**
14
+ * Text message.
15
+ */
16
+ TEXT = "text",
17
+ /**
18
+ * Text delta message. Returned from the streaming response.
19
+ */
20
+ TEXT_DELTA = "text_delta",
21
+ /**
22
+ * Tool use input partial JSON delta streaming.
23
+ */
24
+ INPUT_JSON_DELTA = "input_json_delta",
25
+ /**
26
+ * Image message.
27
+ */
28
+ IMAGE = "image",
29
+ /**
30
+ * Document message.
31
+ */
32
+ DOCUMENT = "document"
33
+ }
34
+ /**
35
+ * The source of the media content. (Applicable for "image" types only)
36
+ */
37
+ export declare class Source {
38
+ /**
39
+ * The type of the media content. Only "base64" is supported at the moment.
40
+ */
41
+ type: string;
42
+ /**
43
+ * The media type of the content. For example, "image/png" or "image/jpeg".
44
+ */
45
+ mediaType: string;
46
+ /**
47
+ * The base64-encoded data of the content.
48
+ */
49
+ data: string;
50
+ constructor(type: string, mediaType: string, data: string);
51
+ /**
52
+ * Create source
53
+ * @param mediaType The media type of the content.
54
+ * @param data The content data.
55
+ */
56
+ static from(mediaType: string, data: string): Source;
57
+ }
58
+ /**
59
+ * The content block of the message.
60
+ */
61
+ export declare class ContentBlock {
62
+ /**
63
+ * The content type can be "text", "image", "tool_use", "tool_result" or "text_delta".
64
+ */
65
+ type: ContentBlockType;
66
+ /**
67
+ * The source of the media content. Applicable for "image" types only.
68
+ */
69
+ source?: Source;
70
+ /**
71
+ * The text of the message. Applicable for "text" types only.
72
+ */
73
+ text?: string;
74
+ /**
75
+ * The index of the content block. Applicable only for streaming responses.
76
+ */
77
+ index?: number;
78
+ /**
79
+ * The id of the tool use. Applicable only for tool_use response.
80
+ */
81
+ id?: string;
82
+ /**
83
+ * The name of the tool use. Applicable only for tool_use response.
84
+ */
85
+ name?: string;
86
+ /**
87
+ * The input of the tool use. Applicable only for tool_use response.
88
+ */
89
+ input?: Record<string, any>;
90
+ /**
91
+ * The id of the tool use. Applicable only for tool_result response.
92
+ */
93
+ toolUseId?: string;
94
+ /**
95
+ * The content of the tool result. Applicable only for tool_result response.
96
+ */
97
+ content?: string;
98
+ constructor(type: ContentBlockType, source?: Source, text?: string, index?: number, id?: string, name?: string, input?: Record<string, any>, toolUseId?: string, content?: string);
99
+ }
@@ -0,0 +1,127 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ import { Expose } from 'class-transformer';
11
+ /**
12
+ * The type of the content block.
13
+ */
14
+ export var ContentBlockType;
15
+ (function (ContentBlockType) {
16
+ /**
17
+ * Tool request
18
+ */
19
+ ContentBlockType["TOOL_USE"] = "tool_use";
20
+ /**
21
+ * Send tool result back to LLM.
22
+ */
23
+ ContentBlockType["TOOL_RESULT"] = "tool_result";
24
+ /**
25
+ * Text message.
26
+ */
27
+ ContentBlockType["TEXT"] = "text";
28
+ /**
29
+ * Text delta message. Returned from the streaming response.
30
+ */
31
+ ContentBlockType["TEXT_DELTA"] = "text_delta";
32
+ /**
33
+ * Tool use input partial JSON delta streaming.
34
+ */
35
+ ContentBlockType["INPUT_JSON_DELTA"] = "input_json_delta";
36
+ /**
37
+ * Image message.
38
+ */
39
+ ContentBlockType["IMAGE"] = "image";
40
+ /**
41
+ * Document message.
42
+ */
43
+ ContentBlockType["DOCUMENT"] = "document";
44
+ })(ContentBlockType || (ContentBlockType = {}));
45
+ /**
46
+ * The source of the media content. (Applicable for "image" types only)
47
+ */
48
+ export class Source {
49
+ constructor(type, mediaType, data) {
50
+ this.type = type;
51
+ this.mediaType = mediaType;
52
+ this.data = data;
53
+ }
54
+ /**
55
+ * Create source
56
+ * @param mediaType The media type of the content.
57
+ * @param data The content data.
58
+ */
59
+ static from(mediaType, data) {
60
+ return new Source('base64', mediaType, data);
61
+ }
62
+ }
63
+ __decorate([
64
+ Expose(),
65
+ __metadata("design:type", String)
66
+ ], Source.prototype, "type", void 0);
67
+ __decorate([
68
+ Expose({ name: 'media_type' }),
69
+ __metadata("design:type", String)
70
+ ], Source.prototype, "mediaType", void 0);
71
+ __decorate([
72
+ Expose(),
73
+ __metadata("design:type", String)
74
+ ], Source.prototype, "data", void 0);
75
+ /**
76
+ * The content block of the message.
77
+ */
78
+ export class ContentBlock {
79
+ constructor(type, source, text, index, id, name, input, toolUseId, content) {
80
+ this.type = type;
81
+ this.source = source;
82
+ this.text = text;
83
+ this.index = index;
84
+ this.id = id;
85
+ this.name = name;
86
+ this.input = input;
87
+ this.toolUseId = toolUseId;
88
+ this.content = content;
89
+ }
90
+ }
91
+ __decorate([
92
+ Expose(),
93
+ __metadata("design:type", String)
94
+ ], ContentBlock.prototype, "type", void 0);
95
+ __decorate([
96
+ Expose(),
97
+ __metadata("design:type", Source)
98
+ ], ContentBlock.prototype, "source", void 0);
99
+ __decorate([
100
+ Expose(),
101
+ __metadata("design:type", String)
102
+ ], ContentBlock.prototype, "text", void 0);
103
+ __decorate([
104
+ Expose(),
105
+ __metadata("design:type", Number)
106
+ ], ContentBlock.prototype, "index", void 0);
107
+ __decorate([
108
+ Expose(),
109
+ __metadata("design:type", String)
110
+ ], ContentBlock.prototype, "id", void 0);
111
+ __decorate([
112
+ Expose(),
113
+ __metadata("design:type", String)
114
+ ], ContentBlock.prototype, "name", void 0);
115
+ __decorate([
116
+ Expose(),
117
+ __metadata("design:type", Object)
118
+ ], ContentBlock.prototype, "input", void 0);
119
+ __decorate([
120
+ Expose({ name: 'tool_use_id' }),
121
+ __metadata("design:type", String)
122
+ ], ContentBlock.prototype, "toolUseId", void 0);
123
+ __decorate([
124
+ Expose(),
125
+ __metadata("design:type", String)
126
+ ], ContentBlock.prototype, "content", void 0);
127
+ //# sourceMappingURL=content-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-block.js","sourceRoot":"","sources":["../../../src/common/api/content-block.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAN,IAAY,gBAoCX;AApCD,WAAY,gBAAgB;IACxB;;OAEG;IACH,yCAAqB,CAAA;IAErB;;OAEG;IACH,+CAA2B,CAAA;IAE3B;;OAEG;IACH,iCAAa,CAAA;IAEb;;OAEG;IACH,6CAAyB,CAAA;IAEzB;;OAEG;IACH,yDAAqC,CAAA;IAErC;;OAEG;IACH,mCAAe,CAAA;IAEf;;OAEG;IACH,yCAAqB,CAAA;AAEzB,CAAC,EApCW,gBAAgB,KAAhB,gBAAgB,QAoC3B;AAED;;GAEG;AACH,MAAM,OAAO,MAAM;IAoBf,YAAY,IAAY,EAAE,SAAiB,EAAE,IAAY;QACrD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,SAAiB,EAAE,IAAY;QAC9C,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;CAEJ;AA7BG;IADC,MAAM,EAAE;;oCACI;AAMb;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;;yCACb;AAMlB;IADC,MAAM,EAAE;;oCACI;AAmBjB;;GAEG;AACH,MAAM,OAAO,YAAY;IAwDrB,YACI,IAAsB,EACtB,MAAe,EACf,IAAa,EACb,KAAc,EACd,EAAW,EACX,IAAa,EACb,KAA2B,EAC3B,SAAkB,EAClB,OAAgB;QAEhB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;CAEJ;AAxEG;IADC,MAAM,EAAE;;0CACc;AAMvB;IADC,MAAM,EAAE;8BACA,MAAM;4CAAC;AAMhB;IADC,MAAM,EAAE;;0CACK;AAMd;IADC,MAAM,EAAE;;2CACM;AAMf;IADC,MAAM,EAAE;;wCACG;AAMZ;IADC,MAAM,EAAE;;0CACK;AAMd;IADC,MAAM,EAAE;;2CACmB;AAM5B;IADC,MAAM,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;;+CACb;AAMnB;IADC,MAAM,EAAE;;6CACQ"}
@@ -0,0 +1,187 @@
1
+ import { ChatResponse } from './chat-response.js';
2
+ import { StreamEvent } from '@celljs/ai-core';
3
+ import { ContentBlockType } from './content-block.js';
4
+ /**
5
+ * The event type of the streamed chunk.
6
+ */
7
+ export declare enum EventType {
8
+ /**
9
+ * Message start event. Contains a Message object with empty content.
10
+ */
11
+ MESSAGE_START = "message_start",
12
+ /**
13
+ * Message delta event, indicating top-level changes to the final Message object.
14
+ */
15
+ MESSAGE_DELTA = "message_delta",
16
+ /**
17
+ * A final message stop event.
18
+ */
19
+ MESSAGE_STOP = "message_stop",
20
+ /**
21
+ * Content block start event.
22
+ */
23
+ CONTENT_BLOCK_START = "content_block_start",
24
+ /**
25
+ * Content block delta event.
26
+ */
27
+ CONTENT_BLOCK_DELTA = "content_block_delta",
28
+ /**
29
+ * A final content block stop event.
30
+ */
31
+ CONTENT_BLOCK_STOP = "content_block_stop",
32
+ /**
33
+ * Error event.
34
+ */
35
+ ERROR = "error",
36
+ /**
37
+ * Ping event.
38
+ */
39
+ PING = "ping",
40
+ /**
41
+ * Artificially created event to aggregate tool use events.
42
+ */
43
+ TOOL_USE_AGGREGATE = "tool_use_aggregate"
44
+ }
45
+ /**
46
+ * Anthropic event.
47
+ */
48
+ export declare class AnthropicEvent {
49
+ type: EventType;
50
+ }
51
+ /**
52
+ * Content block body.
53
+ */
54
+ export declare class ContentBlockBody {
55
+ /**
56
+ * The type of the content block. e.g. "text", "tool_use".
57
+ */
58
+ type: string;
59
+ }
60
+ /**
61
+ * Text content block delta.
62
+ */
63
+ export declare class ContentBlockText extends ContentBlockBody {
64
+ text: string;
65
+ }
66
+ /**
67
+ * Tool use content block.
68
+ */
69
+ export declare class ContentBlockToolUse extends ContentBlockBody {
70
+ id: string;
71
+ name: string;
72
+ input: Record<string, any>;
73
+ constructor(type: ContentBlockType, id: string, name: string, input: Record<string, any>);
74
+ }
75
+ export declare class AnthropicEventWithContentBlock extends AnthropicEvent {
76
+ /**
77
+ * The content block body.
78
+ */
79
+ contentBlock: ContentBlockBody;
80
+ }
81
+ /**
82
+ * Special event used to aggregate multiple tool use events into a single event with
83
+ * list of aggregated ContentBlockToolUse.
84
+ */
85
+ export declare class ToolUseAggregationEvent extends AnthropicEvent {
86
+ index?: number;
87
+ id?: string;
88
+ name?: string;
89
+ partialJson: string;
90
+ toolContentBlocks: ContentBlockToolUse[];
91
+ isEmpty(): boolean;
92
+ appendPartialJson(partialJson: string): ToolUseAggregationEvent;
93
+ squashIntoContentBlock(): void;
94
+ }
95
+ /**
96
+ * Content block delta body.
97
+ */
98
+ export declare class ContentBlockDeltaBody {
99
+ type: string;
100
+ }
101
+ /**
102
+ * Text content block delta.
103
+ */
104
+ export declare class ContentBlockDeltaText extends ContentBlockDeltaBody {
105
+ text: string;
106
+ }
107
+ /**
108
+ * JSON content block delta.
109
+ */
110
+ export declare class ContentBlockDeltaJson extends ContentBlockDeltaBody {
111
+ partialJson: string;
112
+ }
113
+ /**
114
+ * Content block stop event.
115
+ */
116
+ export declare class ContentBlockStopEvent extends AnthropicEvent {
117
+ index: number;
118
+ }
119
+ /**
120
+ * Content block start event.
121
+ */
122
+ export declare class ContentBlockStartEvent extends AnthropicEventWithContentBlock {
123
+ index: number;
124
+ }
125
+ /**
126
+ * Content block delta event.
127
+ */
128
+ export declare class ContentBlockDeltaEvent extends AnthropicEvent {
129
+ index: number;
130
+ delta: ContentBlockDeltaBody;
131
+ }
132
+ /**
133
+ * Message start event.
134
+ */
135
+ export declare class MessageStartEvent {
136
+ type: EventType;
137
+ message: ChatResponse;
138
+ constructor(type: EventType, message: ChatResponse);
139
+ }
140
+ /**
141
+ * Message delta.
142
+ */
143
+ export declare class MessageDelta {
144
+ stopReason: string;
145
+ stopSequence: string;
146
+ }
147
+ /**
148
+ * Message delta usage.
149
+ */
150
+ export declare class MessageDeltaUsage {
151
+ outputTokens: number;
152
+ }
153
+ /**
154
+ * Message delta event.
155
+ */
156
+ export declare class MessageDeltaEvent extends AnthropicEvent {
157
+ delta: MessageDelta;
158
+ usage: MessageDeltaUsage;
159
+ }
160
+ /**
161
+ * Message stop event.
162
+ */
163
+ export declare class MessageStopEvent extends AnthropicEvent {
164
+ }
165
+ /**
166
+ * Error event.
167
+ */
168
+ export declare class ErrorEvent extends AnthropicEvent {
169
+ error: Error;
170
+ }
171
+ /**
172
+ * Error body.
173
+ */
174
+ export declare class Error {
175
+ type: string;
176
+ message: string;
177
+ }
178
+ /**
179
+ * Ping event.
180
+ */
181
+ export declare class PingEvent extends AnthropicEvent {
182
+ }
183
+ export declare class AnthropicStreamEvent implements StreamEvent<AnthropicEvent> {
184
+ event?: EventType;
185
+ data: AnthropicEvent;
186
+ raw: string[];
187
+ }