usegrunt 0.5.0 → 0.6.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.
@@ -12,6 +12,7 @@ export class OpenCode {
12
12
  child;
13
13
  starting;
14
14
  sessions = new Map();
15
+ prepared = new Map();
15
16
  busy = new Set();
16
17
  shutdown = new AbortController();
17
18
  constructor(options = {}) {
@@ -46,7 +47,12 @@ export class OpenCode {
46
47
  const binary = await executable('opencode');
47
48
  this.starting = new Promise((resolve, reject) => {
48
49
  // Keep the normal OS home and the user's existing OpenCode login.
49
- const child = spawn(binary, ['serve', '--hostname', '127.0.0.1', '--port', '0'], { stdio: ['ignore', 'pipe', 'ignore'] });
50
+ const config = JSON.parse(process.env.OPENCODE_CONFIG_CONTENT || '{}');
51
+ const permission = typeof config.permission === 'string' ? { '*': config.permission } : config.permission;
52
+ const env = { ...process.env, OPENCODE_CONFIG_CONTENT: JSON.stringify({
53
+ ...config, permission: { ...permission, external_directory: 'deny' }
54
+ }) };
55
+ const child = spawn(binary, ['serve', '--hostname', '127.0.0.1', '--port', '0'], { stdio: ['ignore', 'pipe', 'ignore'], env });
50
56
  this.child = child;
51
57
  const timer = setTimeout(() => { child.kill(); reject(new SourceError('timeout', 'OpenCode server startup timed out')); }, 30000);
52
58
  let output = '';
@@ -58,7 +64,7 @@ export class OpenCode {
58
64
  resolve(address);
59
65
  }
60
66
  });
61
- const failed = () => { clearTimeout(timer); this.starting = undefined; this.sessions.clear(); reject(new SourceError('upstream', 'OpenCode server stopped; run opencode serve to check installation')); };
67
+ const failed = () => { clearTimeout(timer); this.starting = undefined; this.sessions.clear(); this.prepared.clear(); reject(new SourceError('upstream', 'OpenCode server stopped; run opencode serve to check installation')); };
62
68
  child.once('error', failed);
63
69
  child.once('exit', failed);
64
70
  });
@@ -72,28 +78,111 @@ export class OpenCode {
72
78
  const key = (history) => createHash('sha256').update(JSON.stringify([cwd, history])).digest('hex');
73
79
  const prior = this.sessions.get(key(turns)) ?? (turns.length > 1 ? this.sessions.get(key(turns.slice(0, -1))) : undefined);
74
80
  const continuation = prior && !this.busy.has(prior) ? prior : undefined;
75
- const signal = AbortSignal.any([caller, this.shutdown.signal, AbortSignal.timeout(this.options.timeout ?? 90000)]);
81
+ const signal = AbortSignal.any([caller, this.shutdown.signal, ...(this.options.timeout ? [AbortSignal.timeout(this.options.timeout)] : [])]);
76
82
  let session, base;
83
+ const events = new AbortController();
84
+ let reader;
85
+ let watching;
86
+ let guardFailed = false;
87
+ const turnSignal = AbortSignal.any([signal, events.signal]);
77
88
  const headers = { 'Content-Type': 'application/json', 'x-opencode-directory': cwd,
78
89
  ...(process.env.OPENCODE_SERVER_PASSWORD ? { Authorization: `Basic ${Buffer.from(`${process.env.OPENCODE_SERVER_USERNAME ?? 'opencode'}:${process.env.OPENCODE_SERVER_PASSWORD}`).toString('base64')}` } : {}) };
79
- const call = async (path, body) => {
80
- const res = await this.fetcher(`${base}${path}`, { method: 'POST', headers, redirect: 'error', signal, body: JSON.stringify(body) });
90
+ const check = (res) => {
81
91
  if (!res.ok) {
82
92
  const header = res.headers.get('Retry-After');
83
93
  const seconds = header === null ? NaN : /^\d+(?:\.\d+)?$/.test(header) ? Number(header) : (Date.parse(header) - Date.now()) / 1000;
84
94
  throw new SourceError(res.status === 403 ? 'refused' : res.status === 401 ? 'logged_out' : res.status === 429 ? 'quota' : 'upstream', `OpenCode returned HTTP ${res.status}`, Number.isFinite(seconds) ? Math.max(1, seconds) : undefined);
85
95
  }
96
+ };
97
+ const call = async (path, body) => {
98
+ const res = await this.fetcher(`${base}${path}`, { method: 'POST', headers, redirect: 'error', signal: turnSignal, body: JSON.stringify(body) });
99
+ check(res);
86
100
  return await res.json();
87
101
  };
88
102
  try {
89
103
  base = await this.server();
90
104
  signal.throwIfAborted();
105
+ if (!this.options.url) {
106
+ // Personal MCP catalogs can fill the model context before a task starts.
107
+ // Disconnect them only in our own worker instance, once per directory.
108
+ // OpenCode's coding tools, saved login and config files stay available.
109
+ let prepared = this.prepared.get(cwd);
110
+ if (!prepared) {
111
+ prepared = (async () => {
112
+ const preparationSignal = AbortSignal.any([this.shutdown.signal, AbortSignal.timeout(30000)]);
113
+ const prepare = async (path, method = 'GET') => {
114
+ const response = await this.fetcher(`${base}${path}`, { method, headers, redirect: 'error', signal: preparationSignal });
115
+ check(response);
116
+ return await response.json();
117
+ };
118
+ const peers = await prepare('/mcp');
119
+ if (!peers || typeof peers !== 'object' || Array.isArray(peers))
120
+ throw new SourceError('upstream', 'OpenCode returned invalid MCP status');
121
+ await Promise.all(Object.entries(peers).filter(([, peer]) => peer?.status === 'connected').map(async ([name]) => {
122
+ if (await prepare(`/mcp/${encodeURIComponent(name)}/disconnect`, 'POST') !== true)
123
+ throw new SourceError('upstream', 'OpenCode could not prepare its worker tools');
124
+ }));
125
+ })();
126
+ this.prepared.set(cwd, prepared);
127
+ const pending = prepared;
128
+ void pending.catch(() => { if (this.prepared.get(cwd) === pending)
129
+ this.prepared.delete(cwd); });
130
+ }
131
+ let cancel;
132
+ const cancellation = new Promise((_, reject) => { cancel = () => reject(turnSignal.reason); });
133
+ turnSignal.addEventListener('abort', cancel, { once: true });
134
+ try {
135
+ turnSignal.throwIfAborted();
136
+ await Promise.race([prepared, cancellation]);
137
+ }
138
+ finally {
139
+ turnSignal.removeEventListener('abort', cancel);
140
+ }
141
+ }
91
142
  session = continuation ?? (await call('/session', { title: 'grunt' })).id;
92
143
  if (!session || !/^[a-zA-Z0-9_-]+$/.test(session))
93
144
  throw new SourceError('upstream', 'OpenCode returned an invalid session');
94
145
  this.busy.add(session);
146
+ // OpenCode 1.18.31: subscribe before sending the message so a fast
147
+ // permission request cannot be missed, including on an existing server.
148
+ const stream = await this.fetcher(`${base}/event`, { headers, redirect: 'error', signal: turnSignal });
149
+ check(stream);
150
+ if (!stream.headers.get('content-type')?.includes('text/event-stream') || !stream.body) {
151
+ throw new SourceError('upstream', 'OpenCode permission event stream unavailable');
152
+ }
153
+ reader = stream.body.getReader();
154
+ watching = (async () => {
155
+ const decoder = new TextDecoder();
156
+ let buffer = '';
157
+ while (true) {
158
+ const chunk = await reader.read();
159
+ if (chunk.done)
160
+ throw new SourceError('upstream', 'OpenCode permission event stream closed');
161
+ buffer += decoder.decode(chunk.value, { stream: true });
162
+ let boundary;
163
+ while ((boundary = /\r?\n\r?\n/.exec(buffer))) {
164
+ const frame = buffer.slice(0, boundary.index);
165
+ buffer = buffer.slice(boundary.index + boundary[0].length);
166
+ const data = frame.split(/\r?\n/).filter(line => line.startsWith('data:')).map(line => line.slice(5).trimStart()).join('\n');
167
+ if (!data)
168
+ continue;
169
+ const event = JSON.parse(data);
170
+ if (event.type !== 'permission.asked')
171
+ continue;
172
+ const permission = event.properties;
173
+ if (typeof permission?.sessionID !== 'string')
174
+ throw new SourceError('upstream', 'OpenCode returned an invalid permission request');
175
+ if (permission.sessionID !== session)
176
+ continue;
177
+ if (typeof permission.id !== 'string' || !/^[a-zA-Z0-9_-]+$/.test(permission.id)) {
178
+ throw new SourceError('upstream', 'OpenCode returned an invalid permission request');
179
+ }
180
+ await call(`/permission/${permission.id}/reply`, { reply: 'reject' });
181
+ }
182
+ }
183
+ })().catch(error => { guardFailed = true; throw error; });
95
184
  const modelID = typeof this.options.model === 'function' ? this.options.model() : this.options.model ?? 'big-pickle';
96
- const reply = await call(`/session/${session}/message`, { model: { providerID: 'opencode', modelID }, parts: [{ type: 'text', text: prompt }] });
185
+ const reply = await Promise.race([watching, call(`/session/${session}/message`, { model: { providerID: 'opencode', modelID }, parts: [{ type: 'text', text: prompt }] })]);
97
186
  const parts = reply.parts ?? [];
98
187
  const text = parts.filter(p => p.type === 'text' && typeof p.text === 'string').map(p => p.text).join('\n');
99
188
  if (reply.info?.error) {
@@ -110,9 +199,9 @@ export class OpenCode {
110
199
  return { text };
111
200
  }
112
201
  catch (error) {
202
+ if ((signal.aborted || guardFailed) && session && base)
203
+ await this.fetcher(`${base}/session/${session}/abort`, { method: 'POST', headers, redirect: 'error', signal: AbortSignal.timeout(2000) }).catch(() => { });
113
204
  if (signal.aborted) {
114
- if (session && base)
115
- await this.fetcher(`${base}/session/${session}/abort`, { method: 'POST', headers, redirect: 'error', signal: AbortSignal.timeout(2000) }).catch(() => { });
116
205
  caller.throwIfAborted();
117
206
  if (this.shutdown.signal.aborted)
118
207
  throw new SourceError('cancelled', 'OpenCode request cancelled during shutdown');
@@ -123,6 +212,9 @@ export class OpenCode {
123
212
  throw new SourceError('upstream', 'OpenCode request failed');
124
213
  }
125
214
  finally {
215
+ events.abort();
216
+ await reader?.cancel().catch(() => { });
217
+ await watching?.catch(() => { });
126
218
  if (session)
127
219
  this.busy.delete(session);
128
220
  }
@@ -3,7 +3,7 @@ import { execFile } from 'node:child_process';
3
3
  import { promisify } from 'node:util';
4
4
  import { realpath } from 'node:fs/promises';
5
5
  import { userTurns } from './harness.js';
6
- import { SourceError } from './source.js';
6
+ import { SourceError, answeredBy } from './source.js';
7
7
  import { knownAdapters } from '../registry.js';
8
8
  const exec = promisify(execFile);
9
9
  export class StickyRouter {
@@ -24,7 +24,7 @@ export class StickyRouter {
24
24
  return (await exec('git', ['-C', cwd, ...args], { timeout: 10000, maxBuffer: 1024 * 1024 })).stdout.trim();
25
25
  }
26
26
  async createTask(request) {
27
- const task = { failures: 0, original: userTurns(request).at(-1) ?? '', output: '', switched: false, busy: false };
27
+ const task = { original: userTurns(request).at(-1) ?? '', output: '', switched: false, busy: false };
28
28
  try {
29
29
  task.checkpoint = await this.git(request.cwd, ['stash', 'create']) || await this.git(request.cwd, ['rev-parse', 'HEAD']);
30
30
  }
@@ -58,7 +58,7 @@ export class StickyRouter {
58
58
  let task = this.tasks.get(key);
59
59
  if (!task) {
60
60
  // Reserve the task before asynchronous checkpoint creation to avoid two bindings.
61
- task = { failures: 0, original: '', output: '', switched: false, busy: true };
61
+ task = { original: '', output: '', switched: false, busy: true };
62
62
  this.tasks.set(key, task);
63
63
  Object.assign(task, await this.createTask({ ...request, cwd }), { busy: true });
64
64
  }
@@ -91,14 +91,13 @@ export class StickyRouter {
91
91
  if (task.source)
92
92
  task.switched = true;
93
93
  task.source = selected.source.id;
94
- task.failures = 0;
95
94
  }
96
95
  try {
97
96
  const input = task.switched ? await this.handoff({ ...request, cwd }, task) : { ...request, cwd };
98
97
  const result = await selected.source.complete(input, signal);
99
- task.failures = 0;
100
98
  task.output = Buffer.from(result.text).subarray(-4096).toString('utf8');
101
99
  task.switched = false;
100
+ answeredBy.set(result, selected.source.id);
102
101
  return result;
103
102
  }
104
103
  catch (error) {
@@ -106,19 +105,16 @@ export class StickyRouter {
106
105
  const failure = error instanceof SourceError ? error : new SourceError('upstream', 'Adapter request failed');
107
106
  if (failure.output)
108
107
  task.output = failure.output;
109
- if (failure.code === 'cancelled' || failure.code === 'refused')
108
+ if (failure.code === 'cancelled')
110
109
  throw failure;
111
110
  let until;
112
111
  if (failure.code === 'quota')
113
112
  until = this.now() + (failure.retryAfter ?? 3600) * 1000;
114
113
  else if (failure.code === 'logged_out' || failure.code === 'not_installed')
115
114
  until = Infinity;
116
- else {
117
- task.failures++;
118
- if (task.failures < 3)
119
- throw failure;
115
+ // Any other failure moves this task to the next source now, so the request still gets an answer.
116
+ else
120
117
  until = this.now() + 15 * 60 * 1000;
121
- }
122
118
  this.bars.set(selected.source.id, until);
123
119
  task.switched = true;
124
120
  }
@@ -15,7 +15,10 @@ import { freeConfig, loopback } from './freellmapi.js';
15
15
  import { proxyApproval } from './approval-proxy.js';
16
16
  const exec = promisify(execFile);
17
17
  export const FREELLMAPI_IMAGE = 'ghcr.io/tashfeenahmed/freellmapi@sha256:845a4b568a20fffd5112e1b9c0258e7782d9eabbba2430612d2f7c811eee267e';
18
- export const PROVIDERS = { groq: 'https://console.groq.com/keys', cerebras: 'https://cloud.cerebras.ai/platform/api-keys' };
18
+ export const PROVIDERS = { groq: 'https://console.groq.com/keys', cerebras: 'https://cloud.cerebras.ai/platform/api-keys', kilo: 'https://app.kilo.ai/profile' };
19
+ export const KILO_NEMOTRON = 'nvidia/nemotron-3-ultra-550b-a55b:free';
20
+ const savedProviders = ['kilo'];
21
+ const providerModels = { kilo: [KILO_NEMOTRON, 'kilo-auto/free'] };
19
22
  const sameService = (credential, service) => credential.service?.trim().toLowerCase() === service.trim().toLowerCase();
20
23
  function apiKeyField(credential, provider) {
21
24
  return credential.field_names.find(field => {
@@ -104,6 +107,22 @@ export async function setupProviders(squire, router, options) {
104
107
  await router.addGrant(provider, grant);
105
108
  options.notify(`${provider}: connected through Squire grant`);
106
109
  }
110
+ // These sources reuse existing vault access only; missing keys never start signup.
111
+ for (const provider of savedProviders) {
112
+ if (options.providers?.includes(provider))
113
+ continue;
114
+ if (await router.hasKey?.(provider)) {
115
+ options.notify(`${provider}: connected`);
116
+ continue;
117
+ }
118
+ const credential = (await squire.credentials.list()).find(c => sameService(c, provider) && c.auth_strategy !== 'username_password' && apiKeyField(c, provider));
119
+ if (!credential) {
120
+ options.notify(`${provider}: skipped; no saved API access`);
121
+ continue;
122
+ }
123
+ await router.addGrant(provider, await squire.credentials.grant(credential.reference));
124
+ options.notify(`${provider}: connected through Squire grant`);
125
+ }
107
126
  return { pending, dropped };
108
127
  }
109
128
  const object = (value) => value && typeof value === 'object' && !Array.isArray(value) ? value : {};
@@ -218,7 +237,7 @@ export class BrowserSquire {
218
237
  const session = this.sessions.get(provider);
219
238
  const result = await this.call('operate_drive', {
220
239
  ...(session ? { session_id: session } : { url }),
221
- goal: goal ?? `Use the user's existing ${provider} account or sign up for the free plan. Create one API key for grunt and store it in this user's Squire vault with service ${provider}. Use operate_extract to capture the key directly into the vault; never put its value in your answer. No paid plan, payment method, extra account or account switching. If captcha, passkey or email confirmation needs a human, stop and report the required step so grunt can share this browser. Do not bypass verification. Stop on provider refusal.`,
240
+ goal: goal ?? `Use the user's existing ${provider} account or sign up for the free plan. Create one API key for grunt and store it in this user's Squire vault with service ${provider}. Use operate_extract to capture the key directly into the vault; never put its value in your answer.${provider === 'kilo' ? ' Reuse the existing profile API key without resetting it. Capture with api_hosts ["api.kilo.ai", "ai-gateway.kilo.ai"] in that order and auth_shape "bearer"; grunt uses /api/gateway beneath the grant.' : ''} No paid plan, payment method, extra account or account switching. If captcha, passkey or email confirmation needs a human, stop and report the required step so grunt can share this browser. Do not bypass verification. Stop on provider refusal.`,
222
241
  facts: { plan: 'free', project_name: 'grunt' }, max_seconds: 45, max_steps: 60
223
242
  });
224
243
  if (typeof result.session_id === 'string')
@@ -272,7 +291,7 @@ export class BrowserSquire {
272
291
  async close() { for (const handoff of this.handoffs)
273
292
  handoff.close(); await this.client.close(); }
274
293
  }
275
- const providerPath = (provider) => provider === 'groq' ? '/openai/v1' : '/v1';
294
+ const providerPath = (provider) => ({ groq: '/openai/v1', kilo: '/api/gateway' })[provider] ?? '/v1';
276
295
  export class FreeLLMAdmin {
277
296
  token = '';
278
297
  url;
@@ -290,7 +309,13 @@ export class FreeLLMAdmin {
290
309
  if (!key || !key.models?.length)
291
310
  return false;
292
311
  const discovery = await this.call('/keys/custom/discover-models', { keyId: key.id });
293
- return key.models.some(model => discovery.models.some(available => available.id === model.modelId));
312
+ const available = new Set(discovery.models.map(model => model.id));
313
+ const wanted = providerModels[platform]?.filter(id => available.has(id));
314
+ if (wanted) {
315
+ const required = platform === 'kilo' ? wanted : wanted.slice(0, 1);
316
+ return required.length > 0 && required.every(id => key.models.some(model => model.modelId === id));
317
+ }
318
+ return key.models.some(model => available.has(model.modelId));
294
319
  }
295
320
  async addGrant(platform, grant) {
296
321
  // Custom endpoints bind the grant URL and token to their own model rows.
@@ -298,12 +323,13 @@ export class FreeLLMAdmin {
298
323
  const label = `Milo ${platform} (Squire)`;
299
324
  const discovery = await this.call('/keys/custom/discover-models', { baseUrl, apiKey: grant.token });
300
325
  const available = new Set(discovery.models.map(model => model.id));
301
- const model = ['openai/gpt-oss-120b', 'gpt-oss-120b', 'llama-3.3-70b-versatile', 'openai/gpt-oss-20b'].find(id => available.has(id));
302
- if (!model)
326
+ const candidates = providerModels[platform] ?? ['openai/gpt-oss-120b', 'gpt-oss-120b', 'llama-3.3-70b-versatile', 'openai/gpt-oss-20b'];
327
+ const models = platform === 'kilo' ? candidates.filter(id => available.has(id)) : candidates.filter(id => available.has(id)).slice(0, 1);
328
+ if (!models.length)
303
329
  throw new Error(`No supported chat model is currently available from ${platform}`);
304
330
  const previous = await this.call('/keys', undefined, 'GET');
305
331
  await this.call('/keys/custom', { baseUrl, apiKey: grant.token,
306
- label, models: [{ model, supportsTools: true }] });
332
+ label, models: models.map(model => ({ model, supportsTools: true })) });
307
333
  for (const key of previous) {
308
334
  if (Number.isInteger(key.id) && key.platform === 'custom' && key.label === label && key.baseUrl !== baseUrl)
309
335
  await this.call(`/keys/${key.id}`, undefined, 'DELETE');
@@ -320,11 +346,12 @@ export class FreeLLMAdmin {
320
346
  async configureChain(excluded = []) {
321
347
  const chain = await this.call('/fallback', undefined, 'GET');
322
348
  const rows = chain.map(row => {
323
- const provider = Object.keys(PROVIDERS).find(provider => row.keyLabel === `Milo ${provider} (Squire)`);
324
- const fallback = row.modelId === 'freebuff' || row.modelId === 'kilo-auto/free';
349
+ const provider = [...Object.keys(PROVIDERS), ...savedProviders].find(provider => row.keyLabel === `Milo ${provider} (Squire)`);
350
+ const fallback = !provider && (row.modelId === 'freebuff' || row.modelId === 'kilo-auto/free');
351
+ const vetted = !provider || !providerModels[provider] || providerModels[provider].includes(row.modelId);
325
352
  return { modelDbId: row.modelDbId,
326
- enabled: fallback || (provider ? row.platform === 'custom' && !excluded.includes(provider) : row.enabled === true),
327
- priority: row.modelId === 'freebuff' ? 1000000 : row.modelId === 'kilo-auto/free' ? 999999 : row.priority };
353
+ enabled: fallback || (provider ? row.platform === 'custom' && vetted && !excluded.includes(provider) : row.enabled === true),
354
+ priority: provider === 'kilo' ? (row.modelId === KILO_NEMOTRON ? 999996 : 999997) : row.modelId === 'freebuff' ? 1000000 : row.modelId === 'kilo-auto/free' ? 999999 : row.priority };
328
355
  });
329
356
  await this.call('/fallback', rows, 'PUT');
330
357
  await this.call('/fallback/routing', { strategy: 'priority' }, 'PUT');
@@ -392,7 +419,7 @@ export async function ensureRouter(password, encryption, run = argsWithEnv, recr
392
419
  await run(['volume', 'rm', 'milo-freellmapi-data']);
393
420
  }
394
421
  // Docker copies named variables from env, keeping secrets out of argv.
395
- await run(['run', '-d', '--name', 'milo-freellmapi', '--label', 'io.milo.router=1', ...(process.platform === 'linux' ? ['--network', 'host'] : ['-p', '127.0.0.1:3001:3001']), '--restart', 'unless-stopped', '-v', 'milo-freellmapi-data:/app/server/data', '-e', process.platform === 'linux' ? 'HOST=127.0.0.1' : 'HOST=0.0.0.0', '-e', 'PORT=3001', '-e', 'ENCRYPTION_KEY', '-e', 'FREEAPI_CONFIG_JSON', FREELLMAPI_IMAGE], {
422
+ await run(['run', '-d', '--name', 'milo-freellmapi', '--label', 'io.milo.router=1', ...(process.platform === 'linux' ? ['--network', 'host'] : ['-p', '127.0.0.1:3001:3001']), '--restart', 'unless-stopped', '-v', 'milo-freellmapi-data:/app/server/data', '-e', process.platform === 'linux' ? 'HOST=127.0.0.1' : 'HOST=0.0.0.0', '-e', 'PORT=3001', '-e', 'PROVIDER_TIMEOUT_CUSTOM=600000', '-e', 'ENCRYPTION_KEY', '-e', 'FREEAPI_CONFIG_JSON', FREELLMAPI_IMAGE], {
396
423
  ...process.env, ENCRYPTION_KEY: encryption, FREEAPI_CONFIG_JSON: JSON.stringify({ admin: { email: 'milo@localhost.local', password }, ...freeConfig() })
397
424
  });
398
425
  }
@@ -9,9 +9,13 @@ export class SourceError extends Error {
9
9
  this.output = output;
10
10
  }
11
11
  }
12
+ // Names the adapter that produced each completion; setup checks it against the requested adapter.
13
+ export const answeredBy = new WeakMap();
12
14
  export class Sources {
13
15
  sources;
14
16
  router;
17
+ // Adapters whose background setup has not finished yet.
18
+ preparing = new Set();
15
19
  constructor(sources, routing) {
16
20
  this.sources = sources;
17
21
  if (!sources.length || new Set(sources.map(s => s.id)).size !== sources.length)
@@ -58,6 +62,7 @@ export class Sources {
58
62
  continue;
59
63
  }
60
64
  console.error(`grunt source: ${source.id} answered model ${request.model}`);
65
+ answeredBy.set(completion, source.id);
61
66
  return completion;
62
67
  }
63
68
  throw last;
@@ -68,6 +73,7 @@ export class Gateway {
68
73
  key;
69
74
  fetcher;
70
75
  id = 'gateway';
76
+ supportsFunctionTools = true;
71
77
  url;
72
78
  constructor(url, key, fetcher = fetch) {
73
79
  this.key = key;