@mastra/claude 1.0.0 → 1.0.2
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/claude.cjs.development.js +531 -0
- package/dist/claude.cjs.development.js.map +1 -0
- package/dist/claude.cjs.production.min.js +2 -0
- package/dist/claude.cjs.production.min.js.map +1 -0
- package/dist/claude.esm.js +527 -0
- package/dist/claude.esm.js.map +1 -0
- package/dist/index.js +8 -0
- package/dist/packages/claude/src/client/index.d.ts +3 -0
- package/dist/packages/claude/src/client/schemas.gen.d.ts +212 -0
- package/dist/packages/claude/src/client/service-comments.d.ts +6 -0
- package/dist/packages/claude/src/client/services.gen.d.ts +9 -0
- package/dist/packages/claude/src/client/types.gen.d.ts +167 -0
- package/dist/packages/claude/src/client/zodSchema.d.ts +240 -0
- package/dist/packages/claude/src/index.d.ts +21 -0
- package/dist/packages/claude/src/openapi-components.d.ts +228 -0
- package/dist/packages/claude/src/openapi-paths.d.ts +42 -0
- package/dist/packages/claude/src/openapi.d.ts +285 -0
- package/package.json +8 -6
- package/src/Claude.test.ts +7 -18
- package/src/assets/claude.png +0 -0
- package/src/client/index.ts +4 -0
- package/src/client/schemas.gen.ts +288 -0
- package/src/client/service-comments.ts +6 -0
- package/src/client/services.gen.ts +14 -0
- package/src/client/types.gen.ts +178 -0
- package/src/client/zodSchema.ts +74 -0
- package/src/index.ts +29 -19
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export const ErrorSchema = {
|
|
4
|
+
type: 'object',
|
|
5
|
+
properties: {
|
|
6
|
+
type: {
|
|
7
|
+
type: 'string',
|
|
8
|
+
nullable: false
|
|
9
|
+
},
|
|
10
|
+
message: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
nullable: false
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
required: ['type', 'message']
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
export const ErrorResponseSchema = {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
error: {
|
|
22
|
+
'$ref': '#/components/schemas/Error'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
required: ['error']
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
export const CreateCompletionRequestSchema = {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
model: {
|
|
32
|
+
description: `The model that will complete your prompt.
|
|
33
|
+
As we improve Claude, we develop new versions of it that you can query.
|
|
34
|
+
This parameter controls which version of Claude answers your request.
|
|
35
|
+
Right now we are offering two model families: Claude, and Claude Instant.
|
|
36
|
+
You can use them by setting model to "claude-2" or "claude-instant-1", respectively.
|
|
37
|
+
See models for additional details.
|
|
38
|
+
`,
|
|
39
|
+
oneOf: [
|
|
40
|
+
{
|
|
41
|
+
type: 'string'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'string',
|
|
45
|
+
enum: ['claude-2', 'claude-2.0', 'claude-instant-1', 'claude-instant-1.1']
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
'x-oaiTypeLabel': 'string'
|
|
49
|
+
},
|
|
50
|
+
prompt: {
|
|
51
|
+
description: `The prompt that you want Claude to complete.
|
|
52
|
+
|
|
53
|
+
For proper response generation you will need to format your prompt as follows:
|
|
54
|
+
\n\nHuman: \${userQuestion}\n\nAssistant:
|
|
55
|
+
See our comments on prompts for more context.
|
|
56
|
+
`,
|
|
57
|
+
default: '<|endoftext|>',
|
|
58
|
+
nullable: true,
|
|
59
|
+
oneOf: [
|
|
60
|
+
{
|
|
61
|
+
type: 'string',
|
|
62
|
+
default: '',
|
|
63
|
+
example: 'This is a test.'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'array',
|
|
67
|
+
items: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
default: '',
|
|
70
|
+
example: 'This is a test.'
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'array',
|
|
75
|
+
minItems: 1,
|
|
76
|
+
items: {
|
|
77
|
+
type: 'integer'
|
|
78
|
+
},
|
|
79
|
+
example: '[1212, 318, 257, 1332, 13]'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'array',
|
|
83
|
+
minItems: 1,
|
|
84
|
+
items: {
|
|
85
|
+
type: 'array',
|
|
86
|
+
minItems: 1,
|
|
87
|
+
items: {
|
|
88
|
+
type: 'integer'
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
example: '[[1212, 318, 257, 1332, 13]]'
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
max_tokens_to_sample: {
|
|
96
|
+
type: 'integer',
|
|
97
|
+
minimum: 1,
|
|
98
|
+
default: 256,
|
|
99
|
+
example: 256,
|
|
100
|
+
nullable: true,
|
|
101
|
+
description: `The maximum number of tokens to generate before stopping.
|
|
102
|
+
|
|
103
|
+
Note that our models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.
|
|
104
|
+
`
|
|
105
|
+
},
|
|
106
|
+
temperature: {
|
|
107
|
+
type: 'number',
|
|
108
|
+
minimum: 0,
|
|
109
|
+
maximum: 1,
|
|
110
|
+
default: 1,
|
|
111
|
+
example: 1,
|
|
112
|
+
nullable: true,
|
|
113
|
+
description: `Amount of randomness injected into the response.
|
|
114
|
+
|
|
115
|
+
Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / multiple choice, and closer to 1 for creative and generative tasks.
|
|
116
|
+
`
|
|
117
|
+
},
|
|
118
|
+
top_p: {
|
|
119
|
+
type: 'number',
|
|
120
|
+
minimum: 0,
|
|
121
|
+
maximum: 1,
|
|
122
|
+
default: 1,
|
|
123
|
+
example: 1,
|
|
124
|
+
nullable: true,
|
|
125
|
+
description: `Use nucleus sampling.
|
|
126
|
+
|
|
127
|
+
In nucleus sampling, we compute the cumulative distribution over all the options
|
|
128
|
+
for each subsequent token in decreasing probability order and cut it off once
|
|
129
|
+
it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.
|
|
130
|
+
`
|
|
131
|
+
},
|
|
132
|
+
top_k: {
|
|
133
|
+
type: 'number',
|
|
134
|
+
minimum: 0,
|
|
135
|
+
default: 5,
|
|
136
|
+
example: 5,
|
|
137
|
+
nullable: true,
|
|
138
|
+
description: `Only sample from the top K options for each subsequent token.
|
|
139
|
+
|
|
140
|
+
Used to remove "long tail" low probability responses. Learn more technical details here.
|
|
141
|
+
`
|
|
142
|
+
},
|
|
143
|
+
stream: {
|
|
144
|
+
description: `Whether to incrementally stream the response using server-sent events.
|
|
145
|
+
See this guide to SSE events for details.type: boolean
|
|
146
|
+
`,
|
|
147
|
+
nullable: true,
|
|
148
|
+
default: false
|
|
149
|
+
},
|
|
150
|
+
stop_sequences: {
|
|
151
|
+
description: `Sequences that will cause the model to stop generating completion text.
|
|
152
|
+
Our models stop on "\n\nHuman:", and may include additional built-in stop sequences in the future. By providing the stop_sequences parameter, you may include additional strings that will cause the model to stop generating.
|
|
153
|
+
`,
|
|
154
|
+
default: null,
|
|
155
|
+
nullable: true,
|
|
156
|
+
oneOf: [
|
|
157
|
+
{
|
|
158
|
+
type: 'string',
|
|
159
|
+
default: '<|endoftext|>',
|
|
160
|
+
example: `
|
|
161
|
+
`,
|
|
162
|
+
nullable: true
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
type: 'array',
|
|
166
|
+
minItems: 1,
|
|
167
|
+
maxItems: 4,
|
|
168
|
+
items: {
|
|
169
|
+
type: 'string',
|
|
170
|
+
example: '["\\n"]'
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
metadata: {
|
|
176
|
+
type: 'object',
|
|
177
|
+
properties: {
|
|
178
|
+
user_id: {
|
|
179
|
+
type: 'string',
|
|
180
|
+
example: '13803d75-b4b5-4c3e-b2a2-6f21399b021b',
|
|
181
|
+
description: `An external identifier for the user who is associated with the request.
|
|
182
|
+
|
|
183
|
+
This should be a uuid, hash value, or other opaque identifier. Anthropic may use this id to help detect abuse.
|
|
184
|
+
Do not include any identifying information such as name, email address, or phone number.
|
|
185
|
+
`
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
description: `An object describing metadata about the request.
|
|
189
|
+
`
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
required: ['model', 'prompt', 'max_tokens_to_sample']
|
|
193
|
+
} as const;
|
|
194
|
+
|
|
195
|
+
export const CreateCompletionResponseSchema = {
|
|
196
|
+
type: 'object',
|
|
197
|
+
properties: {
|
|
198
|
+
stop_reason: {
|
|
199
|
+
type: 'string',
|
|
200
|
+
enum: ['stop_sequence', 'max_tokens'],
|
|
201
|
+
description: `The reason that we stopped sampling.
|
|
202
|
+
|
|
203
|
+
This may be one the following values:
|
|
204
|
+
|
|
205
|
+
"stop_sequence": we reached a stop sequence — either provided by you via the stop_sequences parameter, or a stop sequence built into the model
|
|
206
|
+
"max_tokens": we exceeded max_tokens_to_sample or the model's maximum
|
|
207
|
+
`
|
|
208
|
+
},
|
|
209
|
+
model: {
|
|
210
|
+
type: 'string',
|
|
211
|
+
description: `The model that performed the completion.
|
|
212
|
+
`
|
|
213
|
+
},
|
|
214
|
+
completion: {
|
|
215
|
+
type: 'string',
|
|
216
|
+
description: `The resulting completion up to and excluding the stop sequences.
|
|
217
|
+
`
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
required: ['completion', 'stop_reason', 'model']
|
|
221
|
+
} as const;
|
|
222
|
+
|
|
223
|
+
export const CreateCompletionStreamResponseSchema = {
|
|
224
|
+
type: 'object',
|
|
225
|
+
properties: {
|
|
226
|
+
stop_reason: {
|
|
227
|
+
type: 'string',
|
|
228
|
+
enum: ['stop_sequence', 'max_tokens'],
|
|
229
|
+
description: `The reason that we stopped sampling.
|
|
230
|
+
|
|
231
|
+
This may be one the following values:
|
|
232
|
+
|
|
233
|
+
"stop_sequence": we reached a stop sequence — either provided by you via the stop_sequences parameter, or a stop sequence built into the model
|
|
234
|
+
"max_tokens": we exceeded max_tokens_to_sample or the model's maximum
|
|
235
|
+
`
|
|
236
|
+
},
|
|
237
|
+
model: {
|
|
238
|
+
type: 'string',
|
|
239
|
+
description: `The model that performed the completion.
|
|
240
|
+
`
|
|
241
|
+
},
|
|
242
|
+
completion: {
|
|
243
|
+
type: 'string',
|
|
244
|
+
description: `The resulting completion up to and excluding the stop sequences.
|
|
245
|
+
`
|
|
246
|
+
},
|
|
247
|
+
choices: {
|
|
248
|
+
type: 'array',
|
|
249
|
+
items: {
|
|
250
|
+
type: 'object',
|
|
251
|
+
properties: {
|
|
252
|
+
delta: {
|
|
253
|
+
'$ref': '#/components/schemas/CompletionStreamResponseDelta'
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
required: ['completion', 'stop_reason', 'model']
|
|
260
|
+
} as const;
|
|
261
|
+
|
|
262
|
+
export const CompletionStreamResponseDeltaSchema = {
|
|
263
|
+
type: 'object',
|
|
264
|
+
properties: {
|
|
265
|
+
completion: {
|
|
266
|
+
type: 'string',
|
|
267
|
+
description: 'The contents of the chunk message.',
|
|
268
|
+
nullable: true
|
|
269
|
+
},
|
|
270
|
+
stop_reason: {
|
|
271
|
+
type: 'string',
|
|
272
|
+
enum: ['stop_sequence', 'max_tokens'],
|
|
273
|
+
description: `The reason that we stopped sampling.
|
|
274
|
+
|
|
275
|
+
This may be one the following values:
|
|
276
|
+
|
|
277
|
+
"stop_sequence": we reached a stop sequence — either provided by you via the stop_sequences parameter, or a stop sequence built into the model
|
|
278
|
+
"max_tokens": we exceeded max_tokens_to_sample or the model's maximum
|
|
279
|
+
`,
|
|
280
|
+
nullable: true
|
|
281
|
+
},
|
|
282
|
+
model: {
|
|
283
|
+
type: 'string',
|
|
284
|
+
description: `The model that performed the completion.
|
|
285
|
+
`
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} as const;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import { createClient, createConfig, type Options } from '@hey-api/client-fetch';
|
|
4
|
+
import type { CompleteData, CompleteError, CompleteResponse } from './types.gen';
|
|
5
|
+
|
|
6
|
+
export const client = createClient(createConfig());
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Creates a completion for the provided prompt and parameters.
|
|
10
|
+
*/
|
|
11
|
+
export const complete = <ThrowOnError extends boolean = false>(options: Options<CompleteData, ThrowOnError>) => { return (options?.client ?? client).post<CompleteResponse, CompleteError, ThrowOnError>({
|
|
12
|
+
...options,
|
|
13
|
+
url: '/complete'
|
|
14
|
+
}); };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type Error = {
|
|
4
|
+
type: string;
|
|
5
|
+
message: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ErrorResponse = {
|
|
9
|
+
error: Error;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type CreateCompletionRequest = {
|
|
13
|
+
/**
|
|
14
|
+
* The model that will complete your prompt.
|
|
15
|
+
* As we improve Claude, we develop new versions of it that you can query.
|
|
16
|
+
* This parameter controls which version of Claude answers your request.
|
|
17
|
+
* Right now we are offering two model families: Claude, and Claude Instant.
|
|
18
|
+
* You can use them by setting model to "claude-2" or "claude-instant-1", respectively.
|
|
19
|
+
* See models for additional details.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
model: (string | 'claude-2' | 'claude-2.0' | 'claude-instant-1' | 'claude-instant-1.1');
|
|
23
|
+
/**
|
|
24
|
+
* The prompt that you want Claude to complete.
|
|
25
|
+
*
|
|
26
|
+
* For proper response generation you will need to format your prompt as follows:
|
|
27
|
+
* \n\nHuman: ${userQuestion}\n\nAssistant:
|
|
28
|
+
* See our comments on prompts for more context.
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
prompt: ((string | Array<(string)> | Array<(number)> | Array<Array<(number)>>) | null);
|
|
32
|
+
/**
|
|
33
|
+
* The maximum number of tokens to generate before stopping.
|
|
34
|
+
*
|
|
35
|
+
* Note that our models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
max_tokens_to_sample: (number) | null;
|
|
39
|
+
/**
|
|
40
|
+
* Amount of randomness injected into the response.
|
|
41
|
+
*
|
|
42
|
+
* Defaults to 1. Ranges from 0 to 1. Use temp closer to 0 for analytical / multiple choice, and closer to 1 for creative and generative tasks.
|
|
43
|
+
*
|
|
44
|
+
*/
|
|
45
|
+
temperature?: (number) | null;
|
|
46
|
+
/**
|
|
47
|
+
* Use nucleus sampling.
|
|
48
|
+
*
|
|
49
|
+
* In nucleus sampling, we compute the cumulative distribution over all the options
|
|
50
|
+
* for each subsequent token in decreasing probability order and cut it off once
|
|
51
|
+
* it reaches a particular probability specified by top_p. You should either alter temperature or top_p, but not both.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
top_p?: (number) | null;
|
|
55
|
+
/**
|
|
56
|
+
* Only sample from the top K options for each subsequent token.
|
|
57
|
+
*
|
|
58
|
+
* Used to remove "long tail" low probability responses. Learn more technical details here.
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
top_k?: (number) | null;
|
|
62
|
+
/**
|
|
63
|
+
* Whether to incrementally stream the response using server-sent events.
|
|
64
|
+
* See this guide to SSE events for details.type: boolean
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
stream?: unknown;
|
|
68
|
+
/**
|
|
69
|
+
* Sequences that will cause the model to stop generating completion text.
|
|
70
|
+
* Our models stop on "\n\nHuman:", and may include additional built-in stop sequences in the future. By providing the stop_sequences parameter, you may include additional strings that will cause the model to stop generating.
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
stop_sequences?: ((string) | null | Array<(string)>);
|
|
74
|
+
/**
|
|
75
|
+
* An object describing metadata about the request.
|
|
76
|
+
*
|
|
77
|
+
*/
|
|
78
|
+
metadata?: {
|
|
79
|
+
/**
|
|
80
|
+
* An external identifier for the user who is associated with the request.
|
|
81
|
+
*
|
|
82
|
+
* This should be a uuid, hash value, or other opaque identifier. Anthropic may use this id to help detect abuse.
|
|
83
|
+
* Do not include any identifying information such as name, email address, or phone number.
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
user_id?: string;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type CreateCompletionResponse = {
|
|
91
|
+
/**
|
|
92
|
+
* The reason that we stopped sampling.
|
|
93
|
+
*
|
|
94
|
+
* This may be one the following values:
|
|
95
|
+
*
|
|
96
|
+
* "stop_sequence": we reached a stop sequence — either provided by you via the stop_sequences parameter, or a stop sequence built into the model
|
|
97
|
+
* "max_tokens": we exceeded max_tokens_to_sample or the model's maximum
|
|
98
|
+
*
|
|
99
|
+
*/
|
|
100
|
+
stop_reason: 'stop_sequence' | 'max_tokens';
|
|
101
|
+
/**
|
|
102
|
+
* The model that performed the completion.
|
|
103
|
+
*
|
|
104
|
+
*/
|
|
105
|
+
model: string;
|
|
106
|
+
/**
|
|
107
|
+
* The resulting completion up to and excluding the stop sequences.
|
|
108
|
+
*
|
|
109
|
+
*/
|
|
110
|
+
completion: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The reason that we stopped sampling.
|
|
115
|
+
*
|
|
116
|
+
* This may be one the following values:
|
|
117
|
+
*
|
|
118
|
+
* "stop_sequence": we reached a stop sequence — either provided by you via the stop_sequences parameter, or a stop sequence built into the model
|
|
119
|
+
* "max_tokens": we exceeded max_tokens_to_sample or the model's maximum
|
|
120
|
+
*
|
|
121
|
+
*/
|
|
122
|
+
export type stop_reason = 'stop_sequence' | 'max_tokens';
|
|
123
|
+
|
|
124
|
+
export type CreateCompletionStreamResponse = {
|
|
125
|
+
/**
|
|
126
|
+
* The reason that we stopped sampling.
|
|
127
|
+
*
|
|
128
|
+
* This may be one the following values:
|
|
129
|
+
*
|
|
130
|
+
* "stop_sequence": we reached a stop sequence — either provided by you via the stop_sequences parameter, or a stop sequence built into the model
|
|
131
|
+
* "max_tokens": we exceeded max_tokens_to_sample or the model's maximum
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
stop_reason: 'stop_sequence' | 'max_tokens';
|
|
135
|
+
/**
|
|
136
|
+
* The model that performed the completion.
|
|
137
|
+
*
|
|
138
|
+
*/
|
|
139
|
+
model: string;
|
|
140
|
+
/**
|
|
141
|
+
* The resulting completion up to and excluding the stop sequences.
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
completion: string;
|
|
145
|
+
choices?: Array<{
|
|
146
|
+
delta?: CompletionStreamResponseDelta;
|
|
147
|
+
}>;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type CompletionStreamResponseDelta = {
|
|
151
|
+
/**
|
|
152
|
+
* The contents of the chunk message.
|
|
153
|
+
*/
|
|
154
|
+
completion?: (string) | null;
|
|
155
|
+
/**
|
|
156
|
+
* The reason that we stopped sampling.
|
|
157
|
+
*
|
|
158
|
+
* This may be one the following values:
|
|
159
|
+
*
|
|
160
|
+
* "stop_sequence": we reached a stop sequence — either provided by you via the stop_sequences parameter, or a stop sequence built into the model
|
|
161
|
+
* "max_tokens": we exceeded max_tokens_to_sample or the model's maximum
|
|
162
|
+
*
|
|
163
|
+
*/
|
|
164
|
+
stop_reason?: ('stop_sequence' | 'max_tokens') | null;
|
|
165
|
+
/**
|
|
166
|
+
* The model that performed the completion.
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
model?: string;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
export type CompleteData = {
|
|
173
|
+
body: CreateCompletionRequest;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export type CompleteResponse = (CreateCompletionResponse);
|
|
177
|
+
|
|
178
|
+
export type CompleteError = unknown;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Generated by ts-to-zod
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export const errorSchema = z.object({
|
|
5
|
+
type: z.string(),
|
|
6
|
+
message: z.string(),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export const errorResponseSchema = z.object({
|
|
10
|
+
error: errorSchema,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const createCompletionRequestSchema = z.object({
|
|
14
|
+
model: z.union([
|
|
15
|
+
z.string(),
|
|
16
|
+
z.literal('claude-2'),
|
|
17
|
+
z.literal('claude-2.0'),
|
|
18
|
+
z.literal('claude-instant-1'),
|
|
19
|
+
z.literal('claude-instant-1.1'),
|
|
20
|
+
]),
|
|
21
|
+
prompt: z.union([z.string(), z.array(z.string()), z.array(z.number()), z.array(z.array(z.number()))]).nullable(),
|
|
22
|
+
max_tokens_to_sample: z.number().nullable(),
|
|
23
|
+
temperature: z.number().optional().nullable(),
|
|
24
|
+
top_p: z.number().optional().nullable(),
|
|
25
|
+
top_k: z.number().optional().nullable(),
|
|
26
|
+
stream: z.unknown().optional(),
|
|
27
|
+
stop_sequences: z
|
|
28
|
+
.union([z.string(), z.array(z.string())])
|
|
29
|
+
.optional()
|
|
30
|
+
.nullable(),
|
|
31
|
+
metadata: z
|
|
32
|
+
.object({
|
|
33
|
+
user_id: z.string().optional(),
|
|
34
|
+
})
|
|
35
|
+
.optional(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const createCompletionResponseSchema = z.object({
|
|
39
|
+
stop_reason: z.union([z.literal('stop_sequence'), z.literal('max_tokens')]),
|
|
40
|
+
model: z.string(),
|
|
41
|
+
completion: z.string(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const stopReasonSchema = z.union([z.literal('stop_sequence'), z.literal('max_tokens')]);
|
|
45
|
+
|
|
46
|
+
export const completionStreamResponseDeltaSchema = z.object({
|
|
47
|
+
completion: z.string().optional().nullable(),
|
|
48
|
+
stop_reason: z
|
|
49
|
+
.union([z.literal('stop_sequence'), z.literal('max_tokens')])
|
|
50
|
+
.optional()
|
|
51
|
+
.nullable(),
|
|
52
|
+
model: z.string().optional(),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const completeDataSchema = z.object({
|
|
56
|
+
body: createCompletionRequestSchema,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const completeResponseSchema = createCompletionResponseSchema;
|
|
60
|
+
|
|
61
|
+
export const completeErrorSchema = z.unknown();
|
|
62
|
+
|
|
63
|
+
export const createCompletionStreamResponseSchema = z.object({
|
|
64
|
+
stop_reason: z.union([z.literal('stop_sequence'), z.literal('max_tokens')]),
|
|
65
|
+
model: z.string(),
|
|
66
|
+
completion: z.string(),
|
|
67
|
+
choices: z
|
|
68
|
+
.array(
|
|
69
|
+
z.object({
|
|
70
|
+
delta: completionStreamResponseDeltaSchema.optional(),
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
.optional(),
|
|
74
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { Integration,
|
|
2
|
-
import { createClient, type OASClient, type NormalizeOAS } from 'fets';
|
|
1
|
+
import { Integration, IntegrationCredentialType, IntegrationAuth } from '@mastra/core';
|
|
3
2
|
import { z } from 'zod';
|
|
4
3
|
|
|
5
4
|
// @ts-ignore
|
|
6
|
-
import ClaudeLogo from './assets/claude.
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
5
|
+
import ClaudeLogo from './assets/claude.png';
|
|
6
|
+
import { comments } from './client/service-comments';
|
|
7
|
+
import * as integrationClient from './client/services.gen';
|
|
8
|
+
import * as zodSchema from './client/zodSchema';
|
|
10
9
|
|
|
11
10
|
export class ClaudeIntegration extends Integration {
|
|
11
|
+
categories = ['ai', 'communications'];
|
|
12
|
+
description = 'Claude is a next generation AI assistant built for work and trained to be safe, accurate, and secure.';
|
|
13
|
+
|
|
12
14
|
constructor() {
|
|
13
15
|
super({
|
|
14
16
|
authType: IntegrationCredentialType.API_KEY,
|
|
@@ -20,30 +22,38 @@ export class ClaudeIntegration extends Integration {
|
|
|
20
22
|
});
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
return
|
|
25
|
+
getClientZodSchema() {
|
|
26
|
+
return zodSchema;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
getCommentsForClientApis() {
|
|
30
|
+
return comments;
|
|
25
31
|
}
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
getBaseClient() {
|
|
34
|
+
integrationClient.client.setConfig({
|
|
35
|
+
baseUrl: `https://api.anthropic.com/v1`,
|
|
36
|
+
});
|
|
37
|
+
return integrationClient;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getApiClient = async ({ connectionId }: { connectionId: string }) => {
|
|
28
41
|
const connection = await this.dataLayer?.getConnection({ name: this.name, connectionId });
|
|
29
42
|
|
|
30
43
|
if (!connection) {
|
|
31
44
|
throw new Error(`Connection not found for connectionId: ${connectionId}`);
|
|
32
45
|
}
|
|
33
|
-
|
|
34
46
|
const credential = await this.dataLayer?.getCredentialsByConnection(connection.id);
|
|
35
|
-
const value = credential?.value as Record<string,
|
|
47
|
+
const value = credential?.value as Record<string, any>;
|
|
36
48
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
},
|
|
49
|
+
const baseClient = this.getBaseClient();
|
|
50
|
+
|
|
51
|
+
baseClient.client.interceptors.request.use((request, options) => {
|
|
52
|
+
request.headers.set('x-api-key', value?.['ANTHROPIC_API_KEY']);
|
|
53
|
+
return request;
|
|
44
54
|
});
|
|
45
55
|
|
|
46
|
-
return
|
|
56
|
+
return integrationClient;
|
|
47
57
|
};
|
|
48
58
|
|
|
49
59
|
registerEvents() {
|