@promptev/context-engine 0.0.1 → 0.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.
@@ -1,7 +1,7 @@
1
1
  import { Pool } from 'pg';
2
- import { G as GraphConfig, C as ContextEngineConfig } from '../config-CNnASw5X.cjs';
2
+ import { G as GraphConfig, C as ContextEngineConfig } from '../config-C5RZ00W6.cjs';
3
3
  import { H as Hooks } from '../redaction-BqD_DEUQ.cjs';
4
- import { E as Embedder, A as AnnTunable } from '../storage-DU1JRno5.cjs';
4
+ import { E as Embedder, A as AnnTunable } from '../storage-Dvpq2xAC.cjs';
5
5
  import 'zod';
6
6
 
7
7
  type Neo4jDriver = {
@@ -1,7 +1,7 @@
1
1
  import { Pool } from 'pg';
2
- import { G as GraphConfig, C as ContextEngineConfig } from '../config-CdlSkKgV.js';
2
+ import { G as GraphConfig, C as ContextEngineConfig } from '../config-BODDdXJ7.js';
3
3
  import { H as Hooks } from '../redaction-BqD_DEUQ.js';
4
- import { E as Embedder, A as AnnTunable } from '../storage-Dvt2ZxsV.js';
4
+ import { E as Embedder, A as AnnTunable } from '../storage-CJrKgJeJ.js';
5
5
  import 'zod';
6
6
 
7
7
  type Neo4jDriver = {
@@ -59,6 +59,47 @@ var init_hooks = __esm({
59
59
  }
60
60
  });
61
61
 
62
+ // src/providers/google.ts
63
+ async function buildGenaiClient(cfg, timeoutMs, purpose) {
64
+ const specifier = "@google/genai";
65
+ let mod;
66
+ try {
67
+ mod = await import(specifier);
68
+ } catch {
69
+ throw new ExtraMissingError("gemini", specifier, purpose);
70
+ }
71
+ const Ctor = mod.GoogleGenAI ?? mod.Client;
72
+ if (!Ctor) {
73
+ throw new ExtraMissingError("gemini", specifier, purpose);
74
+ }
75
+ const opts = { httpOptions: { timeout: timeoutMs } };
76
+ if (cfg.provider === "vertex_ai") {
77
+ opts.vertexai = true;
78
+ if (cfg.project || cfg.location) {
79
+ if (cfg.project) opts.project = cfg.project;
80
+ if (cfg.location) opts.location = cfg.location;
81
+ } else if (cfg.apiKey) {
82
+ opts.apiKey = cfg.apiKey;
83
+ }
84
+ } else {
85
+ opts.apiKey = cfg.apiKey ?? null;
86
+ }
87
+ try {
88
+ return new Ctor(opts);
89
+ } catch (err) {
90
+ const message = err instanceof Error ? err.message : String(err);
91
+ if (!message.includes("Authentication is not set up")) throw err;
92
+ throw new Error(
93
+ `${message} Set \`project\` on the provider config, or export GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION. Credentials themselves come from Application Default Credentials.`
94
+ );
95
+ }
96
+ }
97
+ var init_google = __esm({
98
+ "src/providers/google.ts"() {
99
+ init_errors();
100
+ }
101
+ });
102
+
62
103
  // src/providers/llm.ts
63
104
  var llm_exports = {};
64
105
  __export(llm_exports, {
@@ -94,20 +135,6 @@ function buildOpenAIChatClient(cfg) {
94
135
  maxRetries: 0
95
136
  });
96
137
  }
97
- async function loadGeminiChatClient(apiKey) {
98
- const specifier = "@google/genai";
99
- let mod;
100
- try {
101
- mod = await import(specifier);
102
- } catch {
103
- throw new ExtraMissingError("gemini", specifier, "gemini llm");
104
- }
105
- const Ctor = mod.GoogleGenAI ?? mod.Client;
106
- if (!Ctor) {
107
- throw new ExtraMissingError("gemini", specifier, "gemini llm");
108
- }
109
- return new Ctor({ apiKey: apiKey ?? null, httpOptions: { timeout: GEMINI_CALL_TIMEOUT_MS } });
110
- }
111
138
  async function loadBedrockSdk() {
112
139
  const specifier = "@aws-sdk/client-bedrock-runtime";
113
140
  try {
@@ -126,7 +153,7 @@ function buildLlmClient(cfg, opts) {
126
153
  if (OPENAI_FAMILY.has(cfg.provider)) {
127
154
  return new LLMClient(cfg, { client: buildOpenAIChatClient(cfg) });
128
155
  }
129
- if (cfg.provider === "gemini" || cfg.provider === "bedrock") {
156
+ if (GOOGLE_FAMILY.has(cfg.provider) || cfg.provider === "bedrock") {
130
157
  return new LLMClient(cfg);
131
158
  }
132
159
  throw new Error(`unknown llm provider: ${JSON.stringify(cfg.provider)}`);
@@ -143,16 +170,18 @@ async function callLlm(cfg, opts) {
143
170
  await owned.aclose();
144
171
  }
145
172
  }
146
- var CALL_TIMEOUT_MS, TIMEOUT_MS, GEMINI_CALL_TIMEOUT_MS, ANTHROPIC_VERSION, ANTHROPIC_MAX_TOKENS, OPENAI_FAMILY, LLMClient;
173
+ var CALL_TIMEOUT_MS, TIMEOUT_MS, GEMINI_CALL_TIMEOUT_MS, ANTHROPIC_VERSION, ANTHROPIC_MAX_TOKENS, OPENAI_FAMILY, GOOGLE_FAMILY, LLMClient;
147
174
  var init_llm = __esm({
148
175
  "src/providers/llm.ts"() {
149
176
  init_errors();
177
+ init_google();
150
178
  CALL_TIMEOUT_MS = 24e4;
151
179
  TIMEOUT_MS = CALL_TIMEOUT_MS;
152
180
  GEMINI_CALL_TIMEOUT_MS = CALL_TIMEOUT_MS;
153
181
  ANTHROPIC_VERSION = "2023-06-01";
154
182
  ANTHROPIC_MAX_TOKENS = 4096;
155
183
  OPENAI_FAMILY = /* @__PURE__ */ new Set(["openai", "azure_openai", "custom"]);
184
+ GOOGLE_FAMILY = /* @__PURE__ */ new Set(["gemini", "vertex_ai"]);
156
185
  LLMClient = class {
157
186
  cfg;
158
187
  provider;
@@ -192,7 +221,7 @@ var init_llm = __esm({
192
221
  if (OPENAI_FAMILY.has(this.provider)) {
193
222
  return this.callOpenAI(system, user, jsonMode, images, maxTokens, temperature);
194
223
  }
195
- if (this.provider === "gemini") {
224
+ if (GOOGLE_FAMILY.has(this.provider)) {
196
225
  return this.callGemini(system, user, jsonMode, images, maxTokens, thinkingBudget, temperature);
197
226
  }
198
227
  if (this.provider === "bedrock") {
@@ -275,7 +304,11 @@ Respond with valid JSON only.`;
275
304
  }
276
305
  async callGemini(system, user, jsonMode, images, maxTokens, thinkingBudget = null, temperature = null) {
277
306
  if (!this.genaiClient) {
278
- this.genaiClient = await loadGeminiChatClient(this.cfg.apiKey);
307
+ this.genaiClient = await buildGenaiClient(
308
+ this.cfg,
309
+ GEMINI_CALL_TIMEOUT_MS,
310
+ "gemini llm"
311
+ );
279
312
  }
280
313
  const parts = [];
281
314
  for (const img of images ?? []) {