nexus-ai-pro 2.20.2 → 2.22.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.
- package/API_STABILITY.md +93 -0
- package/CHANGELOG.md +208 -1
- package/README.md +11 -6
- package/SECURITY.md +16 -2
- package/dist/adapter-kit/gather.d.ts +76 -0
- package/dist/adapter-kit/gather.js +147 -0
- package/dist/adapter-kit/index.d.ts +1 -0
- package/dist/adapter-kit/index.js +1 -0
- package/dist/adapter-kit/record.d.ts +3 -1
- package/dist/adapter-kit/record.js +20 -5
- package/dist/agent/openapi.d.ts +94 -8
- package/dist/agent/openapi.js +528 -32
- package/dist/cli/adapters.d.ts +4 -3
- package/dist/cli/adapters.js +71 -2
- package/dist/cli/doctor.js +3 -0
- package/dist/cli.js +3 -1
- package/dist/core/config-builder.d.ts +1 -0
- package/dist/core/config-builder.js +1 -0
- package/dist/core/defaults.d.ts +34 -0
- package/dist/core/defaults.js +39 -0
- package/dist/core/secure-stream.js +4 -1
- package/dist/decisions/completion.d.ts +10 -7
- package/dist/decisions/completion.js +82 -8
- package/dist/decisions/core.d.ts +88 -43
- package/dist/decisions/core.js +115 -28
- package/dist/decisions/errors.d.ts +25 -0
- package/dist/decisions/errors.js +12 -0
- package/dist/decisions/index.d.ts +6 -5
- package/dist/decisions/index.js +2 -1
- package/dist/decisions/integrations.d.ts +14 -5
- package/dist/decisions/integrations.js +16 -1
- package/dist/decisions/mock.d.ts +5 -3
- package/dist/decisions/mock.js +4 -1
- package/dist/decisions/pictures.d.ts +43 -0
- package/dist/decisions/pictures.js +103 -0
- package/dist/decisions/typesafe.d.ts +33 -5
- package/dist/decisions/typesafe.js +121 -8
- package/dist/doctor/index.d.ts +6 -9
- package/dist/doctor/index.js +41 -0
- package/dist/embeddings/adapters.d.ts +1 -1
- package/dist/embeddings/adapters.js +3 -3
- package/dist/embeddings/batch-google.d.ts +27 -8
- package/dist/embeddings/batch-google.js +112 -36
- package/dist/embeddings/batch-mock.js +1 -1
- package/dist/embeddings/batch.js +10 -4
- package/dist/embeddings/engine.js +14 -13
- package/dist/embeddings/index.d.ts +1 -1
- package/dist/embeddings/inputs.d.ts +26 -3
- package/dist/embeddings/inputs.js +84 -5
- package/dist/embeddings/mock.js +1 -1
- package/dist/embeddings/models.js +39 -4
- package/dist/loaders/csv.d.ts +23 -1
- package/dist/loaders/csv.js +125 -72
- package/dist/loaders/index.d.ts +7 -2
- package/dist/loaders/input.d.ts +6 -0
- package/dist/loaders/input.js +42 -1
- package/dist/loaders/json.d.ts +14 -3
- package/dist/loaders/json.js +171 -20
- package/dist/loaders/web.d.ts +55 -0
- package/dist/loaders/web.js +20 -1
- package/dist/mcp/client.d.ts +54 -5
- package/dist/mcp/client.js +171 -20
- package/dist/mcp/http.d.ts +45 -0
- package/dist/mcp/http.js +233 -0
- package/dist/mcp/index.d.ts +4 -2
- package/dist/mcp/index.js +3 -1
- package/dist/mcp/protocol.d.ts +107 -0
- package/dist/mcp/sampling.d.ts +41 -0
- package/dist/mcp/sampling.js +52 -0
- package/dist/mcp/server.d.ts +96 -14
- package/dist/mcp/server.js +274 -59
- package/dist/models/data.js +20 -1
- package/dist/operations/adapters.d.ts +1 -0
- package/dist/operations/adapters.js +3 -1
- package/dist/protocols/a2a-grpc.js +10 -3
- package/dist/protocols/a2a-signing.d.ts +65 -0
- package/dist/protocols/a2a-signing.js +133 -0
- package/dist/protocols/a2a.d.ts +14 -0
- package/dist/protocols/a2a.js +60 -5
- package/dist/providers/cohere.js +16 -2
- package/dist/providers/google.js +7 -1
- package/dist/providers/ollama.d.ts +1 -1
- package/dist/providers/ollama.js +35 -27
- package/dist/providers/openai.js +19 -2
- package/dist/rag/pinecone.d.ts +63 -2
- package/dist/rag/pinecone.js +80 -0
- package/dist/realtime/conversation.js +18 -0
- package/dist/realtime/gemini-live.transport.d.ts +28 -3
- package/dist/realtime/gemini-live.transport.js +170 -32
- package/dist/realtime/session.d.ts +2 -0
- package/dist/realtime/session.js +19 -4
- package/dist/realtime/types.d.ts +35 -3
- package/dist/security/output-guard.js +4 -1
- package/dist/server/auth.d.ts +263 -2
- package/dist/server/auth.js +432 -5
- package/dist/server/deployments.d.ts +3 -2
- package/dist/server/deployments.js +6 -1
- package/dist/telephony/index.d.ts +1 -1
- package/dist/telephony/manager.d.ts +8 -1
- package/dist/telephony/manager.js +13 -0
- package/dist/telephony/providers/telnyx.d.ts +18 -5
- package/dist/telephony/providers/telnyx.js +44 -7
- package/dist/telephony/providers/twilio.d.ts +3 -1
- package/dist/telephony/providers/twilio.js +16 -0
- package/dist/tracing/stores.d.ts +2 -0
- package/dist/tracing/stores.js +1 -0
- package/dist/tracing/tracer.d.ts +5 -2
- package/dist/tracing/tracer.js +6 -3
- package/dist/types/embeddings.d.ts +47 -5
- package/dist/types/messages.d.ts +7 -0
- package/dist/types/principal.d.ts +1 -1
- package/dist/types/response.d.ts +5 -0
- package/dist/types/telephony.d.ts +38 -0
- package/dist/types/tracing.d.ts +6 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/voice/providers/google.d.ts +44 -0
- package/dist/voice/providers/google.js +215 -0
- package/dist-cjs/adapter-kit/gather.d.ts +76 -0
- package/dist-cjs/adapter-kit/gather.js +152 -0
- package/dist-cjs/adapter-kit/index.d.ts +1 -0
- package/dist-cjs/adapter-kit/index.js +4 -1
- package/dist-cjs/adapter-kit/record.d.ts +3 -1
- package/dist-cjs/adapter-kit/record.js +20 -5
- package/dist-cjs/agent/openapi.d.ts +94 -8
- package/dist-cjs/agent/openapi.js +530 -32
- package/dist-cjs/cli/adapters.d.ts +4 -3
- package/dist-cjs/cli/adapters.js +70 -1
- package/dist-cjs/cli/doctor.js +3 -0
- package/dist-cjs/core/config-builder.d.ts +1 -0
- package/dist-cjs/core/config-builder.js +5 -1
- package/dist-cjs/core/defaults.d.ts +34 -0
- package/dist-cjs/core/defaults.js +44 -0
- package/dist-cjs/core/secure-stream.js +4 -1
- package/dist-cjs/decisions/completion.d.ts +10 -7
- package/dist-cjs/decisions/completion.js +81 -7
- package/dist-cjs/decisions/core.d.ts +88 -43
- package/dist-cjs/decisions/core.js +134 -46
- package/dist-cjs/decisions/errors.d.ts +25 -0
- package/dist-cjs/decisions/errors.js +16 -0
- package/dist-cjs/decisions/index.d.ts +6 -5
- package/dist-cjs/decisions/index.js +5 -1
- package/dist-cjs/decisions/integrations.d.ts +14 -5
- package/dist-cjs/decisions/integrations.js +16 -1
- package/dist-cjs/decisions/mock.d.ts +5 -3
- package/dist-cjs/decisions/mock.js +4 -1
- package/dist-cjs/decisions/pictures.d.ts +43 -0
- package/dist-cjs/decisions/pictures.js +109 -0
- package/dist-cjs/decisions/typesafe.d.ts +33 -5
- package/dist-cjs/decisions/typesafe.js +126 -13
- package/dist-cjs/doctor/index.d.ts +6 -9
- package/dist-cjs/doctor/index.js +41 -0
- package/dist-cjs/embeddings/adapters.d.ts +1 -1
- package/dist-cjs/embeddings/adapters.js +3 -3
- package/dist-cjs/embeddings/batch-google.d.ts +27 -8
- package/dist-cjs/embeddings/batch-google.js +112 -36
- package/dist-cjs/embeddings/batch-mock.js +1 -1
- package/dist-cjs/embeddings/batch.js +9 -3
- package/dist-cjs/embeddings/engine.js +13 -12
- package/dist-cjs/embeddings/index.d.ts +1 -1
- package/dist-cjs/embeddings/inputs.d.ts +26 -3
- package/dist-cjs/embeddings/inputs.js +89 -5
- package/dist-cjs/embeddings/mock.js +1 -1
- package/dist-cjs/embeddings/models.js +39 -4
- package/dist-cjs/loaders/csv.d.ts +23 -1
- package/dist-cjs/loaders/csv.js +126 -71
- package/dist-cjs/loaders/index.d.ts +7 -2
- package/dist-cjs/loaders/input.d.ts +6 -0
- package/dist-cjs/loaders/input.js +43 -1
- package/dist-cjs/loaders/json.d.ts +14 -3
- package/dist-cjs/loaders/json.js +170 -19
- package/dist-cjs/loaders/web.d.ts +55 -0
- package/dist-cjs/loaders/web.js +21 -1
- package/dist-cjs/mcp/client.d.ts +54 -5
- package/dist-cjs/mcp/client.js +171 -20
- package/dist-cjs/mcp/http.d.ts +45 -0
- package/dist-cjs/mcp/http.js +236 -0
- package/dist-cjs/mcp/index.d.ts +4 -2
- package/dist-cjs/mcp/index.js +5 -1
- package/dist-cjs/mcp/protocol.d.ts +107 -0
- package/dist-cjs/mcp/sampling.d.ts +41 -0
- package/dist-cjs/mcp/sampling.js +55 -0
- package/dist-cjs/mcp/server.d.ts +96 -14
- package/dist-cjs/mcp/server.js +273 -58
- package/dist-cjs/models/data.js +20 -1
- package/dist-cjs/operations/adapters.d.ts +1 -0
- package/dist-cjs/operations/adapters.js +3 -1
- package/dist-cjs/protocols/a2a-grpc.js +10 -3
- package/dist-cjs/protocols/a2a-signing.d.ts +65 -0
- package/dist-cjs/protocols/a2a-signing.js +140 -0
- package/dist-cjs/protocols/a2a.d.ts +14 -0
- package/dist-cjs/protocols/a2a.js +65 -6
- package/dist-cjs/providers/cohere.js +16 -2
- package/dist-cjs/providers/google.js +7 -1
- package/dist-cjs/providers/ollama.d.ts +1 -1
- package/dist-cjs/providers/ollama.js +35 -27
- package/dist-cjs/providers/openai.js +19 -2
- package/dist-cjs/rag/pinecone.d.ts +63 -2
- package/dist-cjs/rag/pinecone.js +81 -0
- package/dist-cjs/realtime/conversation.js +18 -0
- package/dist-cjs/realtime/gemini-live.transport.d.ts +28 -3
- package/dist-cjs/realtime/gemini-live.transport.js +170 -32
- package/dist-cjs/realtime/session.d.ts +2 -0
- package/dist-cjs/realtime/session.js +19 -4
- package/dist-cjs/realtime/types.d.ts +35 -3
- package/dist-cjs/security/output-guard.js +4 -1
- package/dist-cjs/server/auth.d.ts +263 -2
- package/dist-cjs/server/auth.js +437 -5
- package/dist-cjs/server/deployments.d.ts +3 -2
- package/dist-cjs/server/deployments.js +6 -1
- package/dist-cjs/telephony/index.d.ts +1 -1
- package/dist-cjs/telephony/manager.d.ts +8 -1
- package/dist-cjs/telephony/manager.js +13 -0
- package/dist-cjs/telephony/providers/telnyx.d.ts +18 -5
- package/dist-cjs/telephony/providers/telnyx.js +44 -7
- package/dist-cjs/telephony/providers/twilio.d.ts +3 -1
- package/dist-cjs/telephony/providers/twilio.js +16 -0
- package/dist-cjs/tracing/stores.d.ts +2 -0
- package/dist-cjs/tracing/stores.js +1 -0
- package/dist-cjs/tracing/tracer.d.ts +5 -2
- package/dist-cjs/tracing/tracer.js +6 -3
- package/dist-cjs/types/embeddings.d.ts +47 -5
- package/dist-cjs/types/messages.d.ts +7 -0
- package/dist-cjs/types/principal.d.ts +1 -1
- package/dist-cjs/types/response.d.ts +5 -0
- package/dist-cjs/types/telephony.d.ts +38 -0
- package/dist-cjs/types/tracing.d.ts +6 -0
- package/dist-cjs/version.d.ts +1 -1
- package/dist-cjs/version.js +1 -1
- package/dist-cjs/voice/providers/google.d.ts +44 -0
- package/dist-cjs/voice/providers/google.js +252 -0
- package/llms.txt +1 -1
- package/package.json +17 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.A2aCardSignatureError = void 0;
|
|
4
|
+
exports.canonicalA2aCard = canonicalA2aCard;
|
|
5
|
+
exports.signA2aCard = signA2aCard;
|
|
6
|
+
exports.verifyA2aCard = verifyA2aCard;
|
|
7
|
+
const base64_js_1 = require("../utils/base64.js");
|
|
8
|
+
const a2a_proto_js_1 = require("./a2a-proto.js");
|
|
9
|
+
class A2aCardSignatureError extends Error {
|
|
10
|
+
reasons;
|
|
11
|
+
constructor(message, reasons = []) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.reasons = reasons;
|
|
14
|
+
this.name = 'A2aCardSignatureError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.A2aCardSignatureError = A2aCardSignatureError;
|
|
18
|
+
const ALGORITHMS = {
|
|
19
|
+
ES256: { key: { name: 'ECDSA', namedCurve: 'P-256' }, sign: { name: 'ECDSA', hash: 'SHA-256' } },
|
|
20
|
+
ES384: { key: { name: 'ECDSA', namedCurve: 'P-384' }, sign: { name: 'ECDSA', hash: 'SHA-384' } },
|
|
21
|
+
ES512: { key: { name: 'ECDSA', namedCurve: 'P-521' }, sign: { name: 'ECDSA', hash: 'SHA-512' } },
|
|
22
|
+
RS256: { key: { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, sign: { name: 'RSASSA-PKCS1-v1_5' } },
|
|
23
|
+
RS384: { key: { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-384' }, sign: { name: 'RSASSA-PKCS1-v1_5' } },
|
|
24
|
+
RS512: { key: { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-512' }, sign: { name: 'RSASSA-PKCS1-v1_5' } },
|
|
25
|
+
PS256: { key: { name: 'RSA-PSS', hash: 'SHA-256' }, sign: { name: 'RSA-PSS', saltLength: 32 } },
|
|
26
|
+
PS384: { key: { name: 'RSA-PSS', hash: 'SHA-384' }, sign: { name: 'RSA-PSS', saltLength: 48 } },
|
|
27
|
+
PS512: { key: { name: 'RSA-PSS', hash: 'SHA-512' }, sign: { name: 'RSA-PSS', saltLength: 64 } },
|
|
28
|
+
EdDSA: { key: { name: 'Ed25519' }, sign: { name: 'Ed25519' } },
|
|
29
|
+
Ed25519: { key: { name: 'Ed25519' }, sign: { name: 'Ed25519' } },
|
|
30
|
+
};
|
|
31
|
+
const sameAlgorithm = (a, b) => a === b || ((a === 'EdDSA' || a === 'Ed25519') && (b === 'EdDSA' || b === 'Ed25519'));
|
|
32
|
+
function canonicalA2aCard(card) {
|
|
33
|
+
const normalized = (0, a2a_proto_js_1.decodeA2a)('AgentCard', (0, a2a_proto_js_1.encodeA2a)('AgentCard', card));
|
|
34
|
+
delete normalized.signatures;
|
|
35
|
+
const cleaned = withoutEmpty(normalized);
|
|
36
|
+
return cleaned === undefined ? '{}' : canonicalJson(cleaned);
|
|
37
|
+
}
|
|
38
|
+
async function signA2aCard(card, signer) {
|
|
39
|
+
if (!Object.hasOwn(ALGORITHMS, signer.alg)) {
|
|
40
|
+
throw new A2aCardSignatureError(`A card is not signed with ${String(signer.alg)}`);
|
|
41
|
+
}
|
|
42
|
+
const protectedHeader = base64url(new TextEncoder().encode(JSON.stringify({ alg: signer.alg, kid: signer.kid, typ: 'JOSE', ...(signer.jku ? { jku: signer.jku } : {}) })));
|
|
43
|
+
const key = await keyOf(signer.key, signer.alg, 'sign');
|
|
44
|
+
const signed = await subtle().sign(ALGORITHMS[signer.alg].sign, key, signingInput(protectedHeader, canonicalA2aCard(card)));
|
|
45
|
+
const signature = {
|
|
46
|
+
protected: protectedHeader,
|
|
47
|
+
signature: base64url(new Uint8Array(signed)),
|
|
48
|
+
...(signer.header ? { header: signer.header } : {}),
|
|
49
|
+
};
|
|
50
|
+
return { ...card, signatures: [...(card.signatures ?? []), signature] };
|
|
51
|
+
}
|
|
52
|
+
async function verifyA2aCard(card, resolveKey) {
|
|
53
|
+
const signatures = card.signatures ?? [];
|
|
54
|
+
if (signatures.length === 0)
|
|
55
|
+
throw new A2aCardSignatureError('The agent card carries no signature');
|
|
56
|
+
const payload = canonicalA2aCard(card);
|
|
57
|
+
const reasons = [];
|
|
58
|
+
for (const [index, entry] of signatures.entries()) {
|
|
59
|
+
try {
|
|
60
|
+
const header = JSON.parse(new TextDecoder().decode(fromBase64url(entry.protected)));
|
|
61
|
+
const alg = header.alg;
|
|
62
|
+
if (typeof alg !== 'string' || !Object.hasOwn(ALGORITHMS, alg)) {
|
|
63
|
+
throw new Error(`its algorithm, ${JSON.stringify(header.alg)}, is not one a card is signed with`);
|
|
64
|
+
}
|
|
65
|
+
if (typeof header.kid !== 'string' || !header.kid)
|
|
66
|
+
throw new Error('its header names no key id');
|
|
67
|
+
const jku = typeof header.jku === 'string' ? header.jku : undefined;
|
|
68
|
+
const found = await resolveKey(header.kid, jku, alg);
|
|
69
|
+
if (!found)
|
|
70
|
+
throw new Error(`no key is trusted as ${header.kid}`);
|
|
71
|
+
const key = await keyOf(found, alg, 'verify');
|
|
72
|
+
const held = await subtle().verify(ALGORITHMS[alg].sign, key, fromBase64url(entry.signature), signingInput(entry.protected, payload));
|
|
73
|
+
if (held)
|
|
74
|
+
return { kid: header.kid, alg };
|
|
75
|
+
reasons.push(`signature ${index + 1}, by ${header.kid}: it does not match the card`);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
reasons.push(`signature ${index + 1}: ${error instanceof Error ? error.message : String(error)}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw new A2aCardSignatureError(`No signature on the agent card holds: ${reasons.join('; ')}`, reasons);
|
|
82
|
+
}
|
|
83
|
+
async function keyOf(key, alg, use) {
|
|
84
|
+
if (!isJwk(key))
|
|
85
|
+
return key;
|
|
86
|
+
if (key.alg !== undefined && !sameAlgorithm(key.alg, alg))
|
|
87
|
+
throw new Error(`the key is for ${key.alg}, not ${alg}`);
|
|
88
|
+
const { d: _d, dp: _dp, dq: _dq, p: _p, q: _q, qi: _qi, oth: _oth, key_ops: _ops, ...publicPart } = key;
|
|
89
|
+
return subtle().importKey('jwk', use === 'verify' ? publicPart : key, ALGORITHMS[alg].key, false, [use]);
|
|
90
|
+
}
|
|
91
|
+
function isJwk(key) {
|
|
92
|
+
return typeof key.kty === 'string';
|
|
93
|
+
}
|
|
94
|
+
function subtle() {
|
|
95
|
+
const crypto = globalThis.crypto;
|
|
96
|
+
if (!crypto?.subtle)
|
|
97
|
+
throw new A2aCardSignatureError('Signing a card needs the Web Crypto API');
|
|
98
|
+
return crypto.subtle;
|
|
99
|
+
}
|
|
100
|
+
function signingInput(protectedHeader, payload) {
|
|
101
|
+
return new TextEncoder().encode(`${protectedHeader}.${base64url(new TextEncoder().encode(payload))}`);
|
|
102
|
+
}
|
|
103
|
+
function base64url(bytes) {
|
|
104
|
+
return (0, base64_js_1.encodeBase64)(bytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
105
|
+
}
|
|
106
|
+
function fromBase64url(text) {
|
|
107
|
+
if (typeof text !== 'string' || !/^[A-Za-z0-9_-]*$/.test(text))
|
|
108
|
+
throw new Error('it is not base64url');
|
|
109
|
+
const padded = text.replace(/-/g, '+').replace(/_/g, '/');
|
|
110
|
+
return (0, base64_js_1.decodeBase64)(padded + '='.repeat((4 - (padded.length % 4)) % 4));
|
|
111
|
+
}
|
|
112
|
+
function withoutEmpty(value) {
|
|
113
|
+
if (value === '' || value === null || value === undefined)
|
|
114
|
+
return undefined;
|
|
115
|
+
if (Array.isArray(value)) {
|
|
116
|
+
const kept = value.map(withoutEmpty).filter((item) => item !== undefined);
|
|
117
|
+
return kept.length ? kept : undefined;
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === 'object') {
|
|
120
|
+
const kept = {};
|
|
121
|
+
for (const [key, item] of Object.entries(value)) {
|
|
122
|
+
const cleaned = withoutEmpty(item);
|
|
123
|
+
if (cleaned !== undefined)
|
|
124
|
+
kept[key] = cleaned;
|
|
125
|
+
}
|
|
126
|
+
return Object.keys(kept).length ? kept : undefined;
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
function canonicalJson(value) {
|
|
131
|
+
if (value === null || typeof value !== 'object')
|
|
132
|
+
return JSON.stringify(value);
|
|
133
|
+
if (Array.isArray(value))
|
|
134
|
+
return `[${value.map(canonicalJson).join(',')}]`;
|
|
135
|
+
const record = value;
|
|
136
|
+
return `{${Object.keys(record)
|
|
137
|
+
.sort()
|
|
138
|
+
.map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`)
|
|
139
|
+
.join(',')}}`;
|
|
140
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Message, ToolDefinition } from '../types/messages.js';
|
|
2
2
|
import type { Principal } from '../types/principal.js';
|
|
3
3
|
import type { Store } from '../types/store.js';
|
|
4
|
+
import { type A2aCardKeyResolver, type A2aCardSigner } from './a2a-signing.js';
|
|
4
5
|
import { type ProtocolGraph, type ProtocolInterrupt } from './shared.js';
|
|
5
6
|
export type { ProtocolGraph, ProtocolInterrupt, ProtocolResult, ProtocolRunOptions } from './shared.js';
|
|
6
7
|
/** The protocol version this module speaks. */
|
|
@@ -454,6 +455,12 @@ export interface A2aServerOptions {
|
|
|
454
455
|
* anything else this caller may see. Without it, there is no extended card.
|
|
455
456
|
*/
|
|
456
457
|
extendedCard?: (principal: Principal) => Partial<A2aAgentCard> | Promise<Partial<A2aAgentCard>>;
|
|
458
|
+
/**
|
|
459
|
+
* Signs every card this handler serves, its own, each tenant's, and the extended card, with each key
|
|
460
|
+
* given, as protocol 1.0 signs a card: a JWS over its canonical form. A card's own `signatures` are
|
|
461
|
+
* kept, and these follow them.
|
|
462
|
+
*/
|
|
463
|
+
sign?: A2aCardSigner | readonly A2aCardSigner[];
|
|
457
464
|
/** How often `SubscribeToTask` reads a task another replica runs, in milliseconds. Defaults to 1 second. */
|
|
458
465
|
pollMs?: number;
|
|
459
466
|
/**
|
|
@@ -604,6 +611,12 @@ export interface A2aClientOptions {
|
|
|
604
611
|
* binding, as protocol 1.0 requires a client to send it.
|
|
605
612
|
*/
|
|
606
613
|
tenant?: string;
|
|
614
|
+
/**
|
|
615
|
+
* Checks the agent's card before the first call: a signature on it must hold against the public key
|
|
616
|
+
* this gives for the signature's key id, or every call fails with `A2aCardSignatureError`. Given an
|
|
617
|
+
* endpoint rather than the card, the card is read from the endpoint's origin to check it.
|
|
618
|
+
*/
|
|
619
|
+
verifyCard?: A2aCardKeyResolver;
|
|
607
620
|
}
|
|
608
621
|
/** What to send: text, and optionally data, a conversation, or the paused task it answers. */
|
|
609
622
|
export interface A2aSendOptions {
|
|
@@ -687,3 +700,4 @@ export interface A2aToolOptions extends A2aClientOptions {
|
|
|
687
700
|
* `network:<host>`, so a permission policy grants or denies it like any other.
|
|
688
701
|
*/
|
|
689
702
|
export declare function a2aTool(options: A2aToolOptions): ToolDefinition;
|
|
703
|
+
export { type A2aCardKeyResolver, type A2aCryptoKey, type A2aJsonWebKey, A2aCardSignatureError, type A2aCardSigner, type A2aSignatureAlgorithm, canonicalA2aCard, signA2aCard, verifyA2aCard, } from './a2a-signing.js';
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MemoryA2aTaskStore = exports.A2aError = exports.A2A_ERRORS = exports.A2A_PROTOCOL_VERSION = void 0;
|
|
3
|
+
exports.verifyA2aCard = exports.signA2aCard = exports.canonicalA2aCard = exports.A2aCardSignatureError = exports.MemoryA2aTaskStore = exports.A2aError = exports.A2A_ERRORS = exports.A2A_PROTOCOL_VERSION = void 0;
|
|
4
4
|
exports.storeA2aTasks = storeA2aTasks;
|
|
5
5
|
exports.a2aErrorStatus = a2aErrorStatus;
|
|
6
6
|
exports.a2aErrorCode = a2aErrorCode;
|
|
7
7
|
exports.a2aHandler = a2aHandler;
|
|
8
8
|
exports.a2aClient = a2aClient;
|
|
9
9
|
exports.a2aTool = a2aTool;
|
|
10
|
+
const a2a_signing_js_1 = require("./a2a-signing.js");
|
|
10
11
|
const shared_js_1 = require("./shared.js");
|
|
11
12
|
exports.A2A_PROTOCOL_VERSION = '1.0';
|
|
12
13
|
exports.A2A_ERRORS = {
|
|
@@ -771,7 +772,7 @@ function a2aHandler(graph, options) {
|
|
|
771
772
|
if (!principal) {
|
|
772
773
|
return fail(exports.A2A_ERRORS.extendedCardNotConfigured, 'The extended card needs an authenticated caller');
|
|
773
774
|
}
|
|
774
|
-
return { result: { ...card, ...(await options.extendedCard(principal)) } };
|
|
775
|
+
return { result: await signed({ ...card, ...(await options.extendedCard(principal)) }) };
|
|
775
776
|
}
|
|
776
777
|
default:
|
|
777
778
|
return fail(-32601, `Method ${method} is not supported`);
|
|
@@ -903,12 +904,57 @@ function a2aHandler(graph, options) {
|
|
|
903
904
|
return restError(outcome.error.code, outcome.error.message);
|
|
904
905
|
return Response.json(outcome.result ?? {});
|
|
905
906
|
};
|
|
907
|
+
const cardFor = (prefix) => {
|
|
908
|
+
if (!tenancy)
|
|
909
|
+
return { card };
|
|
910
|
+
const rest = base && (prefix === base || prefix.startsWith(`${base}/`)) ? prefix.slice(base.length) : prefix;
|
|
911
|
+
const segment = /^\/([^/]+)$/.exec(rest)?.[1];
|
|
912
|
+
if (!segment)
|
|
913
|
+
return { card };
|
|
914
|
+
let tenant;
|
|
915
|
+
try {
|
|
916
|
+
tenant = decodeURIComponent(segment);
|
|
917
|
+
}
|
|
918
|
+
catch {
|
|
919
|
+
return { card };
|
|
920
|
+
}
|
|
921
|
+
return {
|
|
922
|
+
tenant,
|
|
923
|
+
card: {
|
|
924
|
+
...card,
|
|
925
|
+
supportedInterfaces: card.supportedInterfaces.map((item) => (item.tenant ? item : { ...item, tenant })),
|
|
926
|
+
},
|
|
927
|
+
};
|
|
928
|
+
};
|
|
929
|
+
const signers = options.sign === undefined ? [] : Array.isArray(options.sign) ? options.sign : [options.sign];
|
|
930
|
+
const signed = async (unsigned) => {
|
|
931
|
+
let result = unsigned;
|
|
932
|
+
for (const signer of signers)
|
|
933
|
+
result = await (0, a2a_signing_js_1.signA2aCard)(result, signer);
|
|
934
|
+
return result;
|
|
935
|
+
};
|
|
936
|
+
const servedCards = new Map();
|
|
937
|
+
const served = (prefix) => {
|
|
938
|
+
const { tenant, card: unsigned } = cardFor(prefix);
|
|
939
|
+
if (signers.length === 0)
|
|
940
|
+
return Promise.resolve(unsigned);
|
|
941
|
+
const key = tenant ?? '';
|
|
942
|
+
let found = servedCards.get(key);
|
|
943
|
+
if (!found) {
|
|
944
|
+
found = signed(unsigned);
|
|
945
|
+
found.catch(() => servedCards.delete(key));
|
|
946
|
+
if (servedCards.size >= 1_000)
|
|
947
|
+
servedCards.delete(servedCards.keys().next().value);
|
|
948
|
+
servedCards.set(key, found);
|
|
949
|
+
}
|
|
950
|
+
return found;
|
|
951
|
+
};
|
|
906
952
|
const handle = async (request) => {
|
|
907
953
|
const url = new URL(request.url);
|
|
908
954
|
if (request.method === 'GET') {
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
955
|
+
const asked = /^(.*?)\/(?:\.well-known\/)?agent-card\.json$/.exec(url.pathname);
|
|
956
|
+
if (asked)
|
|
957
|
+
return Response.json(await served(asked[1]));
|
|
912
958
|
}
|
|
913
959
|
const route = url.pathname.startsWith(base) ? url.pathname.slice(base.length) : undefined;
|
|
914
960
|
if (bindings.has('HTTP+JSON') && route && route !== '/') {
|
|
@@ -1089,11 +1135,19 @@ function a2aClient(options) {
|
|
|
1089
1135
|
cached ??= fetcher(cardUrl, { headers: { accept: 'application/json', ...options.headers } }).then(async (response) => {
|
|
1090
1136
|
if (!response.ok)
|
|
1091
1137
|
throw new A2aError(response.status, `The agent card answered ${response.status}`);
|
|
1092
|
-
|
|
1138
|
+
const read = (await response.json());
|
|
1139
|
+
if (options.verifyCard)
|
|
1140
|
+
await (0, a2a_signing_js_1.verifyA2aCard)(read, options.verifyCard);
|
|
1141
|
+
return read;
|
|
1142
|
+
});
|
|
1143
|
+
cached.catch(() => {
|
|
1144
|
+
cached = undefined;
|
|
1093
1145
|
});
|
|
1094
1146
|
return cached;
|
|
1095
1147
|
};
|
|
1096
1148
|
const target = async () => {
|
|
1149
|
+
if (options.verifyCard && !isCard)
|
|
1150
|
+
await card();
|
|
1097
1151
|
if (!isCard)
|
|
1098
1152
|
return { url: options.url, ...(options.tenant ? { tenant: options.tenant } : {}) };
|
|
1099
1153
|
const chosen = (await card()).supportedInterfaces.find((item) => item.protocolBinding === binding);
|
|
@@ -1326,3 +1380,8 @@ function a2aTool(options) {
|
|
|
1326
1380
|
},
|
|
1327
1381
|
};
|
|
1328
1382
|
}
|
|
1383
|
+
var a2a_signing_js_2 = require("./a2a-signing.js");
|
|
1384
|
+
Object.defineProperty(exports, "A2aCardSignatureError", { enumerable: true, get: function () { return a2a_signing_js_2.A2aCardSignatureError; } });
|
|
1385
|
+
Object.defineProperty(exports, "canonicalA2aCard", { enumerable: true, get: function () { return a2a_signing_js_2.canonicalA2aCard; } });
|
|
1386
|
+
Object.defineProperty(exports, "signA2aCard", { enumerable: true, get: function () { return a2a_signing_js_2.signA2aCard; } });
|
|
1387
|
+
Object.defineProperty(exports, "verifyA2aCard", { enumerable: true, get: function () { return a2a_signing_js_2.verifyA2aCard; } });
|
|
@@ -38,6 +38,7 @@ class CohereProvider extends base_js_1.BaseProvider {
|
|
|
38
38
|
seed: request.seed,
|
|
39
39
|
frequency_penalty: request.frequencyPenalty,
|
|
40
40
|
presence_penalty: request.presencePenalty,
|
|
41
|
+
...(request.logprobs ? { logprobs: true } : {}),
|
|
41
42
|
}),
|
|
42
43
|
signal: request.signal,
|
|
43
44
|
});
|
|
@@ -58,7 +59,8 @@ class CohereProvider extends base_js_1.BaseProvider {
|
|
|
58
59
|
});
|
|
59
60
|
if (meta.usage)
|
|
60
61
|
meta.cost = (0, usage_js_1.priceUsage)({ model: `cohere/${model}`, usage: meta.usage });
|
|
61
|
-
|
|
62
|
+
const logprobs = cohereLogprobs(result.logprobs);
|
|
63
|
+
return { content, role: 'assistant', finishReason: 'stop', ...(logprobs ? { logprobs } : {}), meta };
|
|
62
64
|
}
|
|
63
65
|
catch (error) {
|
|
64
66
|
throw this.normalizeProviderError(error, request, { model });
|
|
@@ -70,7 +72,11 @@ class CohereProvider extends base_js_1.BaseProvider {
|
|
|
70
72
|
try {
|
|
71
73
|
const response = await self.complete(request, context);
|
|
72
74
|
if (response.content) {
|
|
73
|
-
yield {
|
|
75
|
+
yield {
|
|
76
|
+
type: 'text',
|
|
77
|
+
content: response.content,
|
|
78
|
+
...(response.logprobs ? { logprobs: response.logprobs } : {}),
|
|
79
|
+
};
|
|
74
80
|
}
|
|
75
81
|
yield { type: 'done', meta: response.meta };
|
|
76
82
|
}
|
|
@@ -113,3 +119,11 @@ class CohereProvider extends base_js_1.BaseProvider {
|
|
|
113
119
|
}
|
|
114
120
|
}
|
|
115
121
|
exports.CohereProvider = CohereProvider;
|
|
122
|
+
function cohereLogprobs(items) {
|
|
123
|
+
if (!items?.length)
|
|
124
|
+
return undefined;
|
|
125
|
+
return items.map((item) => ({
|
|
126
|
+
token: item.text ?? '',
|
|
127
|
+
logprob: (item.logprobs ?? []).reduce((sum, value) => sum + value, 0),
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
@@ -104,10 +104,16 @@ class GoogleProvider extends base_js_1.BaseProvider {
|
|
|
104
104
|
if (parsed.usageMetadata)
|
|
105
105
|
usage = geminiUsage(parsed.usageMetadata);
|
|
106
106
|
const parts = parsed.candidates?.[0]?.content?.parts || [];
|
|
107
|
+
let logprobs = geminiLogprobs(parsed.candidates?.[0]?.logprobsResult);
|
|
107
108
|
for (const part of parts) {
|
|
108
109
|
if (typeof part.text !== 'string' || !part.text)
|
|
109
110
|
continue;
|
|
110
|
-
|
|
111
|
+
if (part.thought) {
|
|
112
|
+
yield { type: 'reasoning', content: part.text };
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
yield { type: 'text', content: part.text, ...(logprobs ? { logprobs } : {}) };
|
|
116
|
+
logprobs = undefined;
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
119
|
}
|
|
@@ -16,7 +16,7 @@ export declare class OllamaProvider extends BaseProvider {
|
|
|
16
16
|
complete(request: CompletionRequest): Promise<NexusResponse>;
|
|
17
17
|
/** Streams one completion. */
|
|
18
18
|
stream(request: CompletionRequest): NexusStream;
|
|
19
|
-
/** Shared sampling options so buffered and streamed calls cannot drift apart. */
|
|
19
|
+
/** Shared sampling options so buffered and streamed calls cannot drift apart: a stream stops where a call does. */
|
|
20
20
|
private samplingOptions;
|
|
21
21
|
private formatResponseFormat;
|
|
22
22
|
}
|
|
@@ -78,34 +78,11 @@ class OllamaProvider extends base_js_1.BaseProvider {
|
|
|
78
78
|
messages: this.formatMessages(request.messages),
|
|
79
79
|
format: this.formatResponseFormat(request),
|
|
80
80
|
signal: request.signal,
|
|
81
|
-
...(request
|
|
82
|
-
|
|
83
|
-
logprobs: true,
|
|
84
|
-
...(request.logprobs.top
|
|
85
|
-
? { top_logprobs: Math.min(20, Math.max(0, Math.floor(request.logprobs.top))) }
|
|
86
|
-
: {}),
|
|
87
|
-
}
|
|
88
|
-
: {}),
|
|
89
|
-
options: {
|
|
90
|
-
...this.samplingOptions(request),
|
|
91
|
-
stop: request.stop ? (Array.isArray(request.stop) ? request.stop : [request.stop]) : undefined,
|
|
92
|
-
},
|
|
81
|
+
...logprobOptions(request),
|
|
82
|
+
options: this.samplingOptions(request),
|
|
93
83
|
});
|
|
94
84
|
const latency = Date.now() - startTime;
|
|
95
|
-
const logprobs = result.logprobs
|
|
96
|
-
? result.logprobs.map((item) => ({
|
|
97
|
-
token: item.token ?? '',
|
|
98
|
-
logprob: item.logprob ?? Number.NEGATIVE_INFINITY,
|
|
99
|
-
...(item.top_logprobs?.length
|
|
100
|
-
? {
|
|
101
|
-
top: item.top_logprobs.map((alternative) => ({
|
|
102
|
-
token: alternative.token ?? '',
|
|
103
|
-
logprob: alternative.logprob ?? Number.NEGATIVE_INFINITY,
|
|
104
|
-
})),
|
|
105
|
-
}
|
|
106
|
-
: {}),
|
|
107
|
-
}))
|
|
108
|
-
: undefined;
|
|
85
|
+
const logprobs = ollamaLogprobs(result.logprobs);
|
|
109
86
|
return {
|
|
110
87
|
content: result.message?.content || '',
|
|
111
88
|
role: 'assistant',
|
|
@@ -138,11 +115,17 @@ class OllamaProvider extends base_js_1.BaseProvider {
|
|
|
138
115
|
stream: true,
|
|
139
116
|
format: self.formatResponseFormat(request),
|
|
140
117
|
signal: request.signal,
|
|
118
|
+
...logprobOptions(request),
|
|
141
119
|
options: self.samplingOptions(request),
|
|
142
120
|
});
|
|
143
121
|
for await (const chunk of stream) {
|
|
144
122
|
if (chunk.message?.content) {
|
|
145
|
-
|
|
123
|
+
const logprobs = ollamaLogprobs(chunk.logprobs);
|
|
124
|
+
yield {
|
|
125
|
+
type: 'text',
|
|
126
|
+
content: chunk.message.content,
|
|
127
|
+
...(logprobs ? { logprobs } : {}),
|
|
128
|
+
};
|
|
146
129
|
}
|
|
147
130
|
if (chunk.done) {
|
|
148
131
|
yield {
|
|
@@ -172,6 +155,7 @@ class OllamaProvider extends base_js_1.BaseProvider {
|
|
|
172
155
|
frequency_penalty: request.frequencyPenalty,
|
|
173
156
|
presence_penalty: request.presencePenalty,
|
|
174
157
|
num_predict: request.maxTokens,
|
|
158
|
+
stop: request.stop ? (Array.isArray(request.stop) ? request.stop : [request.stop]) : undefined,
|
|
175
159
|
};
|
|
176
160
|
}
|
|
177
161
|
formatResponseFormat(request) {
|
|
@@ -181,3 +165,27 @@ class OllamaProvider extends base_js_1.BaseProvider {
|
|
|
181
165
|
}
|
|
182
166
|
}
|
|
183
167
|
exports.OllamaProvider = OllamaProvider;
|
|
168
|
+
function logprobOptions(request) {
|
|
169
|
+
if (!request.logprobs)
|
|
170
|
+
return {};
|
|
171
|
+
return {
|
|
172
|
+
logprobs: true,
|
|
173
|
+
...(request.logprobs.top ? { top_logprobs: Math.min(20, Math.max(0, Math.floor(request.logprobs.top))) } : {}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function ollamaLogprobs(items) {
|
|
177
|
+
if (!items?.length)
|
|
178
|
+
return undefined;
|
|
179
|
+
return items.map((item) => ({
|
|
180
|
+
token: item.token ?? '',
|
|
181
|
+
logprob: item.logprob ?? Number.NEGATIVE_INFINITY,
|
|
182
|
+
...(item.top_logprobs?.length
|
|
183
|
+
? {
|
|
184
|
+
top: item.top_logprobs.map((alternative) => ({
|
|
185
|
+
token: alternative.token ?? '',
|
|
186
|
+
logprob: alternative.logprob ?? Number.NEGATIVE_INFINITY,
|
|
187
|
+
})),
|
|
188
|
+
}
|
|
189
|
+
: {}),
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
@@ -212,7 +212,8 @@ class OpenAIProvider extends base_js_1.BaseProvider {
|
|
|
212
212
|
yield { type: 'reasoning', content: delta.reasoning_content };
|
|
213
213
|
}
|
|
214
214
|
if (delta.content) {
|
|
215
|
-
|
|
215
|
+
const logprobs = chatLogprobs(choice.logprobs?.content);
|
|
216
|
+
yield { type: 'text', content: delta.content, ...(logprobs ? { logprobs } : {}) };
|
|
216
217
|
}
|
|
217
218
|
for (const toolCall of (0, type_guards_js_1.asArray)(delta.tool_calls)) {
|
|
218
219
|
const index = thisToolCallIndex(toolCall, toolCallBuffers.size);
|
|
@@ -324,10 +325,12 @@ class OpenAIProvider extends base_js_1.BaseProvider {
|
|
|
324
325
|
const startTime = Date.now();
|
|
325
326
|
const result = await responses.create(this.createResponsesParams(request), await this.requestOptions(request, context));
|
|
326
327
|
const toolCalls = this.extractResponsesToolCalls(result);
|
|
328
|
+
const logprobs = request.logprobs ? responsesLogprobs(result) : undefined;
|
|
327
329
|
return {
|
|
328
330
|
content: this.extractResponsesText(result),
|
|
329
331
|
role: 'assistant',
|
|
330
332
|
toolCalls: toolCalls.length ? toolCalls : undefined,
|
|
333
|
+
...(logprobs ? { logprobs } : {}),
|
|
331
334
|
finishReason: toolCalls.length ? 'tool_calls' : this.mapResponsesFinishReason(result.status),
|
|
332
335
|
meta: this.createMeta(result.model || request.model, Date.now() - startTime, responsesUsage(result.usage)),
|
|
333
336
|
};
|
|
@@ -348,8 +351,11 @@ class OpenAIProvider extends base_js_1.BaseProvider {
|
|
|
348
351
|
switch (event.type) {
|
|
349
352
|
case 'response.output_text.delta': {
|
|
350
353
|
const delta = (0, type_guards_js_1.getString)(event, 'delta');
|
|
354
|
+
const logprobs = request.logprobs
|
|
355
|
+
? chatLogprobs((0, type_guards_js_1.getArray)(event, 'logprobs'))
|
|
356
|
+
: undefined;
|
|
351
357
|
if (delta)
|
|
352
|
-
yield { type: 'text', content: delta };
|
|
358
|
+
yield { type: 'text', content: delta, ...(logprobs ? { logprobs } : {}) };
|
|
353
359
|
break;
|
|
354
360
|
}
|
|
355
361
|
case 'response.output_item.added':
|
|
@@ -446,6 +452,11 @@ class OpenAIProvider extends base_js_1.BaseProvider {
|
|
|
446
452
|
},
|
|
447
453
|
};
|
|
448
454
|
}
|
|
455
|
+
if (request.logprobs && this.reportsLogprobs()) {
|
|
456
|
+
params.include = ['message.output_text.logprobs'];
|
|
457
|
+
if (request.logprobs.top)
|
|
458
|
+
params.top_logprobs = Math.min(20, Math.max(0, Math.floor(request.logprobs.top)));
|
|
459
|
+
}
|
|
449
460
|
return params;
|
|
450
461
|
}
|
|
451
462
|
requiresResponsesApi(model) {
|
|
@@ -693,6 +704,12 @@ function mapResponsesToolChoice(choice) {
|
|
|
693
704
|
return choice;
|
|
694
705
|
return { type: 'function', name: choice.name };
|
|
695
706
|
}
|
|
707
|
+
function responsesLogprobs(result) {
|
|
708
|
+
const parts = (0, type_guards_js_1.asArray)(result.output)
|
|
709
|
+
.flatMap((item) => (0, type_guards_js_1.getArray)(item, 'content'))
|
|
710
|
+
.filter((part) => (0, type_guards_js_1.isRecord)(part) && (0, type_guards_js_1.asString)(part.type) === 'output_text');
|
|
711
|
+
return chatLogprobs(parts.flatMap((part) => (0, type_guards_js_1.getArray)(part, 'logprobs')));
|
|
712
|
+
}
|
|
696
713
|
function chatLogprobs(content) {
|
|
697
714
|
if (!content?.length)
|
|
698
715
|
return undefined;
|
|
@@ -37,8 +37,9 @@ export declare class PineconeError extends Error {
|
|
|
37
37
|
/**
|
|
38
38
|
* Retrieval chunks in a Pinecone index, through its data-plane REST API.
|
|
39
39
|
*
|
|
40
|
-
* No Pinecone client is a dependency.
|
|
41
|
-
*
|
|
40
|
+
* No Pinecone client is a dependency. `PineconeVectorStore.create()` creates the index, with the cosine
|
|
41
|
+
* metric and the store's width, or give the store the host of one made so; chunk ids are Pinecone ids
|
|
42
|
+
* as they are. Each chunk's text, source, and metadata travel in the
|
|
42
43
|
* vector's metadata, and its top-level string, number, and boolean metadata fields are copied under
|
|
43
44
|
* `meta_` names, which is what a search filter matches on.
|
|
44
45
|
*/
|
|
@@ -47,6 +48,14 @@ export declare class PineconeVectorStore implements VectorStore {
|
|
|
47
48
|
private readonly base;
|
|
48
49
|
private readonly embed;
|
|
49
50
|
constructor(options: PineconeVectorStoreOptions);
|
|
51
|
+
/**
|
|
52
|
+
* A store over the named index, created first, as `ensurePineconeIndex()` does, when it does not exist.
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* const store = await PineconeVectorStore.create({ apiKey, name: 'docs', dimensions: 1536, embed });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
static create(options: PineconeCreateOptions): Promise<PineconeVectorStore>;
|
|
50
59
|
/** Adds chunks, or replaces those whose id exists, embedding those without a vector in one batch. */
|
|
51
60
|
add(documents: VectorDocument[]): Promise<void>;
|
|
52
61
|
/** The chunks most similar to a query, best first. */
|
|
@@ -58,3 +67,55 @@ export declare class PineconeVectorStore implements VectorStore {
|
|
|
58
67
|
private namespace;
|
|
59
68
|
private request;
|
|
60
69
|
}
|
|
70
|
+
/** Options for `ensurePineconeIndex()`: the index, and how to reach Pinecone's control plane. */
|
|
71
|
+
export interface PineconeIndexOptions {
|
|
72
|
+
/** The Pinecone API key. */
|
|
73
|
+
apiKey: string;
|
|
74
|
+
/** The index's name: 1 to 45 lowercase letters, digits, and hyphens, beginning and ending with a letter or digit. */
|
|
75
|
+
name: string;
|
|
76
|
+
/** Width of every vector. An index that exists must have it. */
|
|
77
|
+
dimensions: number;
|
|
78
|
+
/** Where a new serverless index runs. Defaults to `aws`. */
|
|
79
|
+
cloud?: 'aws' | 'gcp' | 'azure';
|
|
80
|
+
/** The cloud's region for a new index. Defaults to `us-east-1`. */
|
|
81
|
+
region?: string;
|
|
82
|
+
/** Protects a new index from deletion. Defaults to false. */
|
|
83
|
+
deletionProtection?: boolean;
|
|
84
|
+
/** Tags on a new index. */
|
|
85
|
+
tags?: Readonly<Record<string, string>>;
|
|
86
|
+
/** How long to wait for the index to be ready, in milliseconds. Defaults to 5 minutes. */
|
|
87
|
+
readyTimeoutMs?: number;
|
|
88
|
+
/** How often to ask whether it is ready, in milliseconds. Defaults to 2 seconds. */
|
|
89
|
+
pollMs?: number;
|
|
90
|
+
/** The control plane's URL. Defaults to `https://api.pinecone.io`. */
|
|
91
|
+
controlUrl?: string;
|
|
92
|
+
/** The `X-Pinecone-API-Version` header. Defaults to `2025-04`. */
|
|
93
|
+
apiVersion?: string;
|
|
94
|
+
/** Replaces the global `fetch`. */
|
|
95
|
+
fetch?: typeof globalThis.fetch;
|
|
96
|
+
/** Headers added to every request. */
|
|
97
|
+
headers?: Record<string, string>;
|
|
98
|
+
/** Aborts a request that takes longer, in milliseconds. Defaults to 30 seconds. */
|
|
99
|
+
timeoutMs?: number;
|
|
100
|
+
}
|
|
101
|
+
/** An index ready to take vectors. */
|
|
102
|
+
export interface PineconeIndex {
|
|
103
|
+
/** Its name. */
|
|
104
|
+
name: string;
|
|
105
|
+
/** Its data-plane host, which `PineconeVectorStore` takes. */
|
|
106
|
+
host: string;
|
|
107
|
+
/** Whether this call created it, rather than finding it. */
|
|
108
|
+
created: boolean;
|
|
109
|
+
}
|
|
110
|
+
/** What `PineconeVectorStore.create()` takes: the store's options, its host aside, and the index's. */
|
|
111
|
+
export type PineconeCreateOptions = Omit<PineconeVectorStoreOptions, 'host'> & Pick<PineconeIndexOptions, 'name' | 'cloud' | 'region' | 'deletionProtection' | 'tags' | 'readyTimeoutMs' | 'pollMs' | 'controlUrl'>;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a serverless index with the cosine metric and the store's width, unless one of that name
|
|
114
|
+
* exists, and waits until it is ready. An index that exists is used when its width and metric are the
|
|
115
|
+
* store's, and refused otherwise; one created by another process at the same moment is used as found.
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* const { host } = await ensurePineconeIndex({ apiKey, name: 'docs', dimensions: 1536, region: 'eu-west-1' });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function ensurePineconeIndex(options: PineconeIndexOptions): Promise<PineconeIndex>;
|