@prismatic-io/components-anthropic 0.0.0-stage → 0.0.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/README.md +64 -2
- package/dist/icon.png +0 -0
- package/dist/index.js +227 -0
- package/npm-dist/icon.png +0 -0
- package/npm-dist/index.cjs +660 -0
- package/npm-dist/index.d.cts +362 -0
- package/package.json +48 -4
|
Binary file
|
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
let _prismatic_io_spectral = require("@prismatic-io/spectral");
|
|
2
|
+
let _prismatic_io_spectral_http = require("@prismatic-io/spectral/http");
|
|
3
|
+
//#region src/constants.ts
|
|
4
|
+
const BASE_URL = "https://api.anthropic.com/v1";
|
|
5
|
+
const ANTHROPIC_VERSION = "2023-06-01";
|
|
6
|
+
const MAX_LIMIT = 1e3;
|
|
7
|
+
const DEFAULT_MODEL = "claude-sonnet-4-6";
|
|
8
|
+
const DEFAULT_MAX_TOKENS = 4096;
|
|
9
|
+
const DEFAULT_RAW_REQUEST_URL = "/models";
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/util/clean.ts
|
|
12
|
+
const cleanStringInput = (value) => value ? _prismatic_io_spectral.util.types.toString(value) : void 0;
|
|
13
|
+
const cleanNumberInput = (value) => value ? _prismatic_io_spectral.util.types.toNumber(value) : void 0;
|
|
14
|
+
const cleanNumberWithDefault = (defaultValue) => (value) => value ? _prismatic_io_spectral.util.types.toNumber(value) : defaultValue;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/connections/index.ts
|
|
17
|
+
var connections_default = [(0, _prismatic_io_spectral.connection)({
|
|
18
|
+
key: "anthropic",
|
|
19
|
+
display: {
|
|
20
|
+
label: "Anthropic API",
|
|
21
|
+
description: "Connection to Anthropic's Claude API"
|
|
22
|
+
},
|
|
23
|
+
inputs: { apiKey: {
|
|
24
|
+
label: "API Key",
|
|
25
|
+
type: "password",
|
|
26
|
+
required: true,
|
|
27
|
+
comments: "Your Anthropic API key.",
|
|
28
|
+
shown: true
|
|
29
|
+
} }
|
|
30
|
+
})];
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/util/connection.ts
|
|
33
|
+
const validateConnection = (connection) => {
|
|
34
|
+
if (!connections_default.map((c) => c.key).includes(connection.key)) throw new _prismatic_io_spectral.ConnectionError(connection, `Unsupported connection ${connection.key}.`);
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/util/pagination.ts
|
|
38
|
+
const getPaginatedResponse = async (client, path, fetchAll, params) => {
|
|
39
|
+
const finalParams = fetchAll ? { limit: MAX_LIMIT } : { ...params };
|
|
40
|
+
const response = await client.get(path, { params: finalParams });
|
|
41
|
+
if (!fetchAll) return response;
|
|
42
|
+
const firstId = response.data.first_id;
|
|
43
|
+
const data = response.data.data;
|
|
44
|
+
let hasMore = response.data.has_more;
|
|
45
|
+
let lastId = response.data.last_id;
|
|
46
|
+
finalParams.after_id = lastId ?? void 0;
|
|
47
|
+
while (hasMore) {
|
|
48
|
+
const newResponse = await client.get(path, { params: finalParams });
|
|
49
|
+
data.push(...newResponse.data.data);
|
|
50
|
+
hasMore = newResponse.data.has_more;
|
|
51
|
+
lastId = newResponse.data.last_id;
|
|
52
|
+
finalParams.after_id = lastId ?? void 0;
|
|
53
|
+
}
|
|
54
|
+
return { data: {
|
|
55
|
+
data,
|
|
56
|
+
has_more: hasMore,
|
|
57
|
+
first_id: firstId,
|
|
58
|
+
last_id: lastId
|
|
59
|
+
} };
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/client.ts
|
|
63
|
+
const createAnthropicClient = (connection, debug) => {
|
|
64
|
+
validateConnection(connection);
|
|
65
|
+
return (0, _prismatic_io_spectral_http.createClient)({
|
|
66
|
+
baseUrl: BASE_URL,
|
|
67
|
+
debug,
|
|
68
|
+
headers: {
|
|
69
|
+
"x-api-key": _prismatic_io_spectral.util.types.toString(connection.fields.apiKey),
|
|
70
|
+
"anthropic-version": ANTHROPIC_VERSION,
|
|
71
|
+
"content-type": "application/json"
|
|
72
|
+
},
|
|
73
|
+
responseType: "json"
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/examplePayloads.ts
|
|
78
|
+
const chatExamplePayload = { data: {
|
|
79
|
+
content: [{
|
|
80
|
+
text: "Hi! My name is Claude.",
|
|
81
|
+
type: "text"
|
|
82
|
+
}],
|
|
83
|
+
id: "msg_013Zva2CMHLNnXjNJJKqJ2EF",
|
|
84
|
+
model: "claude-sonnet-4-6",
|
|
85
|
+
role: "assistant",
|
|
86
|
+
stop_reason: "end_turn",
|
|
87
|
+
stop_sequence: null,
|
|
88
|
+
type: "message",
|
|
89
|
+
usage: {
|
|
90
|
+
input_tokens: 2095,
|
|
91
|
+
output_tokens: 503
|
|
92
|
+
}
|
|
93
|
+
} };
|
|
94
|
+
const countTokensExamplePayload = { data: { input_tokens: 100 } };
|
|
95
|
+
const getModelExamplePayload = { data: {
|
|
96
|
+
created_at: "2025-02-19T00:00:00Z",
|
|
97
|
+
display_name: "Claude Sonnet 4.6",
|
|
98
|
+
id: "claude-sonnet-4-6",
|
|
99
|
+
type: "model"
|
|
100
|
+
} };
|
|
101
|
+
const listModelsExamplePayload = { data: {
|
|
102
|
+
data: [{
|
|
103
|
+
created_at: "2025-02-19T00:00:00Z",
|
|
104
|
+
display_name: "Claude Sonnet 4.6",
|
|
105
|
+
id: "claude-sonnet-4-6",
|
|
106
|
+
type: "model"
|
|
107
|
+
}],
|
|
108
|
+
first_id: "claude-sonnet-4-6",
|
|
109
|
+
has_more: false,
|
|
110
|
+
last_id: "claude-haiku-4-5-20251001"
|
|
111
|
+
} };
|
|
112
|
+
const selectModelExamplePayload = { result: [{
|
|
113
|
+
key: "claude-sonnet-4-6",
|
|
114
|
+
label: "Claude Sonnet 4.6"
|
|
115
|
+
}] };
|
|
116
|
+
const rawRequestExamplePayload = { data: {
|
|
117
|
+
data: [{
|
|
118
|
+
created_at: "2025-02-19T00:00:00Z",
|
|
119
|
+
display_name: "Claude Sonnet 4.6",
|
|
120
|
+
id: "claude-sonnet-4-6",
|
|
121
|
+
type: "model"
|
|
122
|
+
}, {
|
|
123
|
+
created_at: "2024-10-22T00:00:00Z",
|
|
124
|
+
display_name: "Claude Haiku 4.5",
|
|
125
|
+
id: "claude-haiku-4-5-20251001",
|
|
126
|
+
type: "model"
|
|
127
|
+
}],
|
|
128
|
+
first_id: "claude-sonnet-4-6",
|
|
129
|
+
has_more: false,
|
|
130
|
+
last_id: "claude-haiku-4-5-20251001"
|
|
131
|
+
} };
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/inputs/common.ts
|
|
134
|
+
const connectionInput = (0, _prismatic_io_spectral.input)({
|
|
135
|
+
label: "Connection",
|
|
136
|
+
type: "connection",
|
|
137
|
+
required: true,
|
|
138
|
+
comments: "The Anthropic API connection to use."
|
|
139
|
+
});
|
|
140
|
+
const modelInput = (0, _prismatic_io_spectral.input)({
|
|
141
|
+
label: "Model",
|
|
142
|
+
type: "string",
|
|
143
|
+
required: true,
|
|
144
|
+
default: DEFAULT_MODEL,
|
|
145
|
+
comments: "The Claude model to use.",
|
|
146
|
+
dataSource: "selectModel",
|
|
147
|
+
clean: _prismatic_io_spectral.util.types.toString,
|
|
148
|
+
placeholder: "Enter a Claude model name",
|
|
149
|
+
example: "claude-sonnet-4-6"
|
|
150
|
+
});
|
|
151
|
+
const beforeIdInput = (0, _prismatic_io_spectral.input)({
|
|
152
|
+
label: "Before ID",
|
|
153
|
+
type: "string",
|
|
154
|
+
required: false,
|
|
155
|
+
comments: "ID of the object to use as a cursor for pagination. Returns the page of results immediately before this object.",
|
|
156
|
+
clean: cleanStringInput,
|
|
157
|
+
placeholder: "Enter a model ID to paginate before",
|
|
158
|
+
example: "claude-sonnet-4-6"
|
|
159
|
+
});
|
|
160
|
+
const afterIdInput = (0, _prismatic_io_spectral.input)({
|
|
161
|
+
label: "After ID",
|
|
162
|
+
type: "string",
|
|
163
|
+
required: false,
|
|
164
|
+
comments: "ID of the object to use as a cursor for pagination. Returns the page of results immediately after this object.",
|
|
165
|
+
clean: cleanStringInput,
|
|
166
|
+
placeholder: "Enter a model ID to paginate after",
|
|
167
|
+
example: "claude-sonnet-4-6"
|
|
168
|
+
});
|
|
169
|
+
const limitInput = (0, _prismatic_io_spectral.input)({
|
|
170
|
+
label: "Limit",
|
|
171
|
+
type: "string",
|
|
172
|
+
required: false,
|
|
173
|
+
default: _prismatic_io_spectral.util.types.toString(20),
|
|
174
|
+
comments: `Number of items to return per page. Defaults to 20. Range: 1-${MAX_LIMIT}.`,
|
|
175
|
+
clean: cleanNumberWithDefault(20),
|
|
176
|
+
placeholder: "Enter number of items per page",
|
|
177
|
+
example: "10"
|
|
178
|
+
});
|
|
179
|
+
const fetchAllInput = (0, _prismatic_io_spectral.input)({
|
|
180
|
+
label: "Fetch All",
|
|
181
|
+
type: "boolean",
|
|
182
|
+
required: false,
|
|
183
|
+
default: "false",
|
|
184
|
+
comments: "When true, automatically fetches all pages of results. The Limit, After ID, and Before ID inputs are ignored.",
|
|
185
|
+
clean: _prismatic_io_spectral.util.types.toBool
|
|
186
|
+
});
|
|
187
|
+
const messageInput = (0, _prismatic_io_spectral.input)({
|
|
188
|
+
label: "Message",
|
|
189
|
+
type: "string",
|
|
190
|
+
required: true,
|
|
191
|
+
comments: "The message to send in the conversation.",
|
|
192
|
+
clean: _prismatic_io_spectral.util.types.toString,
|
|
193
|
+
placeholder: "Enter a message to Claude",
|
|
194
|
+
example: "What is the capital of France?"
|
|
195
|
+
});
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/inputs/dataSources.ts
|
|
198
|
+
const selectModelInputs = { connection: connectionInput };
|
|
199
|
+
//#endregion
|
|
200
|
+
//#region src/inputs/messages.ts
|
|
201
|
+
const temperatureInput = (0, _prismatic_io_spectral.input)({
|
|
202
|
+
label: "Temperature",
|
|
203
|
+
type: "string",
|
|
204
|
+
required: false,
|
|
205
|
+
default: _prismatic_io_spectral.util.types.toString(1),
|
|
206
|
+
comments: `Randomness of the output (0-1, default: 1). Note: temperature is not supported on Claude Opus 4.7+ models and will return a 400 error if set to a non-default value.`,
|
|
207
|
+
clean: cleanNumberInput,
|
|
208
|
+
placeholder: "Enter a value between 0 and 1",
|
|
209
|
+
example: "0.7"
|
|
210
|
+
});
|
|
211
|
+
const chatInputs = {
|
|
212
|
+
connection: connectionInput,
|
|
213
|
+
model: modelInput,
|
|
214
|
+
initialMessage: messageInput,
|
|
215
|
+
systemPrompt: (0, _prismatic_io_spectral.input)({
|
|
216
|
+
label: "System Prompt",
|
|
217
|
+
type: "string",
|
|
218
|
+
required: false,
|
|
219
|
+
comments: "A system prompt to set the context and behavior for the conversation.",
|
|
220
|
+
clean: cleanStringInput,
|
|
221
|
+
placeholder: "Enter a system prompt to guide Claude's behavior",
|
|
222
|
+
example: "You are a helpful AI assistant that specializes in answering questions about science."
|
|
223
|
+
}),
|
|
224
|
+
maxTokens: (0, _prismatic_io_spectral.input)({
|
|
225
|
+
label: "Max Tokens",
|
|
226
|
+
type: "string",
|
|
227
|
+
required: false,
|
|
228
|
+
default: _prismatic_io_spectral.util.types.toString(DEFAULT_MAX_TOKENS),
|
|
229
|
+
comments: `Maximum number of tokens to generate (default: ${DEFAULT_MAX_TOKENS}).`,
|
|
230
|
+
clean: cleanNumberInput,
|
|
231
|
+
placeholder: "Enter maximum number of tokens to generate",
|
|
232
|
+
example: "1000"
|
|
233
|
+
}),
|
|
234
|
+
temperature: temperatureInput
|
|
235
|
+
};
|
|
236
|
+
const countTokensInputs = {
|
|
237
|
+
connection: connectionInput,
|
|
238
|
+
model: modelInput,
|
|
239
|
+
message: messageInput
|
|
240
|
+
};
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/inputs/misc.ts
|
|
243
|
+
const { debugRequest: _, ...httpClientInputs } = _prismatic_io_spectral_http.inputs;
|
|
244
|
+
const rawRequestInputs = {
|
|
245
|
+
connection: connectionInput,
|
|
246
|
+
...httpClientInputs,
|
|
247
|
+
url: {
|
|
248
|
+
...httpClientInputs.url,
|
|
249
|
+
comments: `Input the path only (${DEFAULT_RAW_REQUEST_URL}), The base URL is already included (${BASE_URL}). For example, to connect to ${BASE_URL}${DEFAULT_RAW_REQUEST_URL}, only ${DEFAULT_RAW_REQUEST_URL} is entered in this field.`,
|
|
250
|
+
example: DEFAULT_RAW_REQUEST_URL,
|
|
251
|
+
default: DEFAULT_RAW_REQUEST_URL
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region src/inputs/models.ts
|
|
256
|
+
const getModelInputs = {
|
|
257
|
+
connection: connectionInput,
|
|
258
|
+
model: modelInput
|
|
259
|
+
};
|
|
260
|
+
const listModelsInputs = {
|
|
261
|
+
connection: connectionInput,
|
|
262
|
+
fetchAll: fetchAllInput,
|
|
263
|
+
pagination: (0, _prismatic_io_spectral.structuredObjectInput)({
|
|
264
|
+
key: "pagination",
|
|
265
|
+
label: "Pagination",
|
|
266
|
+
comments: "Cursor and page-size controls for paging through results.",
|
|
267
|
+
inputs: {
|
|
268
|
+
beforeId: beforeIdInput,
|
|
269
|
+
afterId: afterIdInput,
|
|
270
|
+
limit: limitInput
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
};
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/outputSchemas/messages.ts
|
|
276
|
+
const chatOutputSchema = {
|
|
277
|
+
type: "object",
|
|
278
|
+
properties: {
|
|
279
|
+
id: { type: "string" },
|
|
280
|
+
type: {
|
|
281
|
+
type: "string",
|
|
282
|
+
enum: ["message"]
|
|
283
|
+
},
|
|
284
|
+
role: {
|
|
285
|
+
type: "string",
|
|
286
|
+
enum: ["assistant"]
|
|
287
|
+
},
|
|
288
|
+
model: { type: "string" },
|
|
289
|
+
content: {
|
|
290
|
+
type: "array",
|
|
291
|
+
items: {
|
|
292
|
+
type: "object",
|
|
293
|
+
properties: {
|
|
294
|
+
type: {
|
|
295
|
+
type: "string",
|
|
296
|
+
enum: ["text"]
|
|
297
|
+
},
|
|
298
|
+
text: { type: "string" }
|
|
299
|
+
},
|
|
300
|
+
required: ["type", "text"]
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
stop_reason: {
|
|
304
|
+
type: ["string", "null"],
|
|
305
|
+
enum: [
|
|
306
|
+
"end_turn",
|
|
307
|
+
"max_tokens",
|
|
308
|
+
"stop_sequence",
|
|
309
|
+
"tool_use",
|
|
310
|
+
"pause_turn",
|
|
311
|
+
"refusal",
|
|
312
|
+
"model_context_window_exceeded",
|
|
313
|
+
null
|
|
314
|
+
]
|
|
315
|
+
},
|
|
316
|
+
stop_sequence: { type: ["string", "null"] },
|
|
317
|
+
usage: {
|
|
318
|
+
type: "object",
|
|
319
|
+
properties: {
|
|
320
|
+
input_tokens: { type: "number" },
|
|
321
|
+
output_tokens: { type: "number" },
|
|
322
|
+
cache_creation_input_tokens: { type: ["number", "null"] },
|
|
323
|
+
cache_read_input_tokens: { type: ["number", "null"] },
|
|
324
|
+
cache_creation: {
|
|
325
|
+
type: ["object", "null"],
|
|
326
|
+
properties: {
|
|
327
|
+
ephemeral_5m_input_tokens: { type: "number" },
|
|
328
|
+
ephemeral_1h_input_tokens: { type: "number" }
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
output_tokens_details: {
|
|
332
|
+
type: ["object", "null"],
|
|
333
|
+
properties: { thinking_tokens: { type: "number" } }
|
|
334
|
+
},
|
|
335
|
+
inference_geo: { type: ["string", "null"] },
|
|
336
|
+
service_tier: {
|
|
337
|
+
type: ["string", "null"],
|
|
338
|
+
enum: [
|
|
339
|
+
"standard",
|
|
340
|
+
"priority",
|
|
341
|
+
"batch",
|
|
342
|
+
null
|
|
343
|
+
]
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
required: ["input_tokens", "output_tokens"]
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
required: [
|
|
350
|
+
"id",
|
|
351
|
+
"type",
|
|
352
|
+
"role",
|
|
353
|
+
"model",
|
|
354
|
+
"content",
|
|
355
|
+
"stop_reason",
|
|
356
|
+
"stop_sequence",
|
|
357
|
+
"usage"
|
|
358
|
+
]
|
|
359
|
+
};
|
|
360
|
+
const countTokensOutputSchema = {
|
|
361
|
+
type: "object",
|
|
362
|
+
properties: { input_tokens: { type: "number" } },
|
|
363
|
+
required: ["input_tokens"]
|
|
364
|
+
};
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/outputSchemas/models.ts
|
|
367
|
+
const capabilitySupportSchema = {
|
|
368
|
+
type: "object",
|
|
369
|
+
properties: { supported: { type: "boolean" } },
|
|
370
|
+
required: ["supported"]
|
|
371
|
+
};
|
|
372
|
+
const nullableCapabilitySupportSchema = {
|
|
373
|
+
type: ["object", "null"],
|
|
374
|
+
properties: { supported: { type: "boolean" } },
|
|
375
|
+
required: ["supported"]
|
|
376
|
+
};
|
|
377
|
+
const getModelOutputSchema = {
|
|
378
|
+
type: "object",
|
|
379
|
+
properties: {
|
|
380
|
+
id: { type: "string" },
|
|
381
|
+
type: {
|
|
382
|
+
type: "string",
|
|
383
|
+
enum: ["model"]
|
|
384
|
+
},
|
|
385
|
+
display_name: { type: "string" },
|
|
386
|
+
created_at: {
|
|
387
|
+
type: "string",
|
|
388
|
+
format: "date-time"
|
|
389
|
+
},
|
|
390
|
+
max_input_tokens: { type: ["number", "null"] },
|
|
391
|
+
max_tokens: { type: ["number", "null"] },
|
|
392
|
+
capabilities: {
|
|
393
|
+
type: ["object", "null"],
|
|
394
|
+
properties: {
|
|
395
|
+
batch: capabilitySupportSchema,
|
|
396
|
+
citations: capabilitySupportSchema,
|
|
397
|
+
code_execution: capabilitySupportSchema,
|
|
398
|
+
image_input: capabilitySupportSchema,
|
|
399
|
+
pdf_input: capabilitySupportSchema,
|
|
400
|
+
structured_outputs: capabilitySupportSchema,
|
|
401
|
+
context_management: {
|
|
402
|
+
type: "object",
|
|
403
|
+
properties: {
|
|
404
|
+
supported: { type: "boolean" },
|
|
405
|
+
clear_thinking_20251015: nullableCapabilitySupportSchema,
|
|
406
|
+
clear_tool_uses_20250919: nullableCapabilitySupportSchema,
|
|
407
|
+
compact_20260112: nullableCapabilitySupportSchema
|
|
408
|
+
},
|
|
409
|
+
required: [
|
|
410
|
+
"supported",
|
|
411
|
+
"clear_thinking_20251015",
|
|
412
|
+
"clear_tool_uses_20250919",
|
|
413
|
+
"compact_20260112"
|
|
414
|
+
]
|
|
415
|
+
},
|
|
416
|
+
effort: {
|
|
417
|
+
type: "object",
|
|
418
|
+
properties: {
|
|
419
|
+
supported: { type: "boolean" },
|
|
420
|
+
low: capabilitySupportSchema,
|
|
421
|
+
medium: capabilitySupportSchema,
|
|
422
|
+
high: capabilitySupportSchema,
|
|
423
|
+
max: capabilitySupportSchema,
|
|
424
|
+
xhigh: nullableCapabilitySupportSchema
|
|
425
|
+
},
|
|
426
|
+
required: [
|
|
427
|
+
"supported",
|
|
428
|
+
"low",
|
|
429
|
+
"medium",
|
|
430
|
+
"high",
|
|
431
|
+
"max",
|
|
432
|
+
"xhigh"
|
|
433
|
+
]
|
|
434
|
+
},
|
|
435
|
+
thinking: {
|
|
436
|
+
type: "object",
|
|
437
|
+
properties: {
|
|
438
|
+
supported: { type: "boolean" },
|
|
439
|
+
types: {
|
|
440
|
+
type: "object",
|
|
441
|
+
properties: {
|
|
442
|
+
adaptive: capabilitySupportSchema,
|
|
443
|
+
enabled: capabilitySupportSchema
|
|
444
|
+
},
|
|
445
|
+
required: ["adaptive", "enabled"]
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
required: ["supported", "types"]
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
required: [
|
|
452
|
+
"batch",
|
|
453
|
+
"citations",
|
|
454
|
+
"code_execution",
|
|
455
|
+
"context_management",
|
|
456
|
+
"effort",
|
|
457
|
+
"image_input",
|
|
458
|
+
"pdf_input",
|
|
459
|
+
"structured_outputs",
|
|
460
|
+
"thinking"
|
|
461
|
+
]
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
required: [
|
|
465
|
+
"id",
|
|
466
|
+
"type",
|
|
467
|
+
"display_name",
|
|
468
|
+
"created_at"
|
|
469
|
+
]
|
|
470
|
+
};
|
|
471
|
+
const listModelsOutputSchema = {
|
|
472
|
+
type: "object",
|
|
473
|
+
properties: {
|
|
474
|
+
data: {
|
|
475
|
+
type: "array",
|
|
476
|
+
items: getModelOutputSchema
|
|
477
|
+
},
|
|
478
|
+
first_id: { type: ["string", "null"] },
|
|
479
|
+
has_more: { type: "boolean" },
|
|
480
|
+
last_id: { type: ["string", "null"] }
|
|
481
|
+
},
|
|
482
|
+
required: [
|
|
483
|
+
"data",
|
|
484
|
+
"first_id",
|
|
485
|
+
"has_more",
|
|
486
|
+
"last_id"
|
|
487
|
+
]
|
|
488
|
+
};
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/actions/messages/index.ts
|
|
491
|
+
var messages_default = {
|
|
492
|
+
chat: (0, _prismatic_io_spectral.action)({
|
|
493
|
+
display: {
|
|
494
|
+
label: "Chat",
|
|
495
|
+
description: "Start a new conversation with Claude."
|
|
496
|
+
},
|
|
497
|
+
inputs: chatInputs,
|
|
498
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
499
|
+
type: "actionOutput",
|
|
500
|
+
schema: chatOutputSchema
|
|
501
|
+
}),
|
|
502
|
+
performSafety: "notAllowed",
|
|
503
|
+
perform: async (context, { connection, model, systemPrompt, initialMessage, maxTokens, temperature }) => {
|
|
504
|
+
const client = createAnthropicClient(connection, context.debug.enabled);
|
|
505
|
+
const request = {
|
|
506
|
+
model,
|
|
507
|
+
messages: [{
|
|
508
|
+
role: "user",
|
|
509
|
+
content: initialMessage
|
|
510
|
+
}],
|
|
511
|
+
system: systemPrompt,
|
|
512
|
+
max_tokens: maxTokens,
|
|
513
|
+
temperature
|
|
514
|
+
};
|
|
515
|
+
const { data } = await client.post("/messages", request);
|
|
516
|
+
return { data };
|
|
517
|
+
},
|
|
518
|
+
examplePerform: async (_context, { model }) => ({ data: {
|
|
519
|
+
...chatExamplePayload.data,
|
|
520
|
+
model
|
|
521
|
+
} }),
|
|
522
|
+
examplePayload: chatExamplePayload
|
|
523
|
+
}),
|
|
524
|
+
countTokens: (0, _prismatic_io_spectral.action)({
|
|
525
|
+
display: {
|
|
526
|
+
label: "Count Tokens",
|
|
527
|
+
description: "Count the number of tokens in a message or conversation."
|
|
528
|
+
},
|
|
529
|
+
inputs: countTokensInputs,
|
|
530
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
531
|
+
type: "actionOutput",
|
|
532
|
+
schema: countTokensOutputSchema
|
|
533
|
+
}),
|
|
534
|
+
performSafety: "safe",
|
|
535
|
+
perform: async (context, { connection, model, message }) => {
|
|
536
|
+
const client = createAnthropicClient(connection, context.debug.enabled);
|
|
537
|
+
const messages = [{
|
|
538
|
+
role: "user",
|
|
539
|
+
content: message
|
|
540
|
+
}];
|
|
541
|
+
const { data } = await client.post("/messages/count_tokens", {
|
|
542
|
+
model,
|
|
543
|
+
messages
|
|
544
|
+
});
|
|
545
|
+
return { data };
|
|
546
|
+
},
|
|
547
|
+
examplePayload: countTokensExamplePayload
|
|
548
|
+
})
|
|
549
|
+
};
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/actions/misc/index.ts
|
|
552
|
+
var misc_default = { rawRequest: (0, _prismatic_io_spectral.action)({
|
|
553
|
+
display: {
|
|
554
|
+
label: "Raw Request",
|
|
555
|
+
description: "Send raw HTTP request to Anthropic."
|
|
556
|
+
},
|
|
557
|
+
inputs: rawRequestInputs,
|
|
558
|
+
examplePayload: rawRequestExamplePayload,
|
|
559
|
+
performSafety: "notAllowed",
|
|
560
|
+
perform: async (context, { connection, ...httpClientInputs }) => {
|
|
561
|
+
const { data } = await (0, _prismatic_io_spectral_http.sendRawRequest)(BASE_URL, {
|
|
562
|
+
...httpClientInputs,
|
|
563
|
+
debugRequest: context.debug.enabled
|
|
564
|
+
}, {
|
|
565
|
+
"x-api-key": _prismatic_io_spectral.util.types.toString(connection.fields.apiKey),
|
|
566
|
+
"anthropic-version": ANTHROPIC_VERSION
|
|
567
|
+
});
|
|
568
|
+
return { data };
|
|
569
|
+
}
|
|
570
|
+
}) };
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/actions/models/index.ts
|
|
573
|
+
var models_default = {
|
|
574
|
+
getModel: (0, _prismatic_io_spectral.action)({
|
|
575
|
+
display: {
|
|
576
|
+
label: "Get Model",
|
|
577
|
+
description: "Get details of a specific Claude model."
|
|
578
|
+
},
|
|
579
|
+
inputs: getModelInputs,
|
|
580
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
581
|
+
type: "actionOutput",
|
|
582
|
+
schema: getModelOutputSchema
|
|
583
|
+
}),
|
|
584
|
+
performSafety: "safe",
|
|
585
|
+
perform: async (context, { connection, model }) => {
|
|
586
|
+
const { data } = await createAnthropicClient(connection, context.debug.enabled).get(`/models/${model}`);
|
|
587
|
+
return { data };
|
|
588
|
+
},
|
|
589
|
+
examplePayload: getModelExamplePayload
|
|
590
|
+
}),
|
|
591
|
+
listModels: (0, _prismatic_io_spectral.action)({
|
|
592
|
+
display: {
|
|
593
|
+
label: "List Models",
|
|
594
|
+
description: "List all available Claude models."
|
|
595
|
+
},
|
|
596
|
+
inputs: listModelsInputs,
|
|
597
|
+
outputSchema: (0, _prismatic_io_spectral.outputSchema)({
|
|
598
|
+
type: "actionOutput",
|
|
599
|
+
schema: listModelsOutputSchema
|
|
600
|
+
}),
|
|
601
|
+
performSafety: "notAllowed",
|
|
602
|
+
perform: async (context, { connection, fetchAll, pagination }) => {
|
|
603
|
+
const { data } = await getPaginatedResponse(createAnthropicClient(connection, context.debug.enabled), "/models", fetchAll, {
|
|
604
|
+
before_id: pagination?.beforeId,
|
|
605
|
+
after_id: pagination?.afterId,
|
|
606
|
+
limit: pagination?.limit
|
|
607
|
+
});
|
|
608
|
+
return { data };
|
|
609
|
+
},
|
|
610
|
+
examplePerform: async () => ({ data: listModelsExamplePayload.data }),
|
|
611
|
+
examplePayload: listModelsExamplePayload
|
|
612
|
+
})
|
|
613
|
+
};
|
|
614
|
+
//#endregion
|
|
615
|
+
//#region src/actions/index.ts
|
|
616
|
+
var actions_default = {
|
|
617
|
+
...messages_default,
|
|
618
|
+
...models_default,
|
|
619
|
+
...misc_default
|
|
620
|
+
};
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/dataSources/index.ts
|
|
623
|
+
var dataSources_default = { selectModel: (0, _prismatic_io_spectral.dataSource)({
|
|
624
|
+
display: {
|
|
625
|
+
label: "List Models",
|
|
626
|
+
description: "List all available Claude models."
|
|
627
|
+
},
|
|
628
|
+
dataSourceType: "picklist",
|
|
629
|
+
inputs: selectModelInputs,
|
|
630
|
+
perform: async (_context, { connection }) => {
|
|
631
|
+
const { data } = await getPaginatedResponse(createAnthropicClient(connection, false), "/models", false, {});
|
|
632
|
+
return { result: data.data.map((model) => ({
|
|
633
|
+
key: model.id,
|
|
634
|
+
label: model.display_name
|
|
635
|
+
})) };
|
|
636
|
+
},
|
|
637
|
+
examplePayload: selectModelExamplePayload
|
|
638
|
+
}) };
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/index.ts
|
|
641
|
+
var src_default = (0, _prismatic_io_spectral.component)({
|
|
642
|
+
key: "anthropic",
|
|
643
|
+
public: true,
|
|
644
|
+
documentationUrl: "https://prismatic.io/docs/components/anthropic/",
|
|
645
|
+
display: {
|
|
646
|
+
label: "Anthropic",
|
|
647
|
+
description: "Generate chat responses and completions using Anthropic's Claude models.",
|
|
648
|
+
iconPath: "icon.png",
|
|
649
|
+
category: "Application Connectors"
|
|
650
|
+
},
|
|
651
|
+
hooks: { error: _prismatic_io_spectral_http.handleErrors },
|
|
652
|
+
actions: actions_default,
|
|
653
|
+
connections: connections_default,
|
|
654
|
+
dataSources: dataSources_default
|
|
655
|
+
});
|
|
656
|
+
//#endregion
|
|
657
|
+
//#region npm-dist/.entry.ts
|
|
658
|
+
var _entry_default = (0, _prismatic_io_spectral.callableComponent)(src_default);
|
|
659
|
+
//#endregion
|
|
660
|
+
module.exports = _entry_default;
|