@agentskit/adapters 0.10.0 → 0.12.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/dist/index.cjs CHANGED
@@ -1274,6 +1274,69 @@ function bedrock(config) {
1274
1274
  }
1275
1275
  var bedrockAdapter = bedrock;
1276
1276
 
1277
+ // src/webllm.ts
1278
+ var cachedSdk2 = null;
1279
+ async function loadSdk2() {
1280
+ if (!cachedSdk2) {
1281
+ cachedSdk2 = (async () => {
1282
+ try {
1283
+ const moduleId = "@mlc-ai/web-llm";
1284
+ return await import(
1285
+ /* @vite-ignore */
1286
+ moduleId
1287
+ );
1288
+ } catch {
1289
+ throw new Error("Install @mlc-ai/web-llm to use the webllm adapter: npm install @mlc-ai/web-llm");
1290
+ }
1291
+ })();
1292
+ }
1293
+ return cachedSdk2;
1294
+ }
1295
+ function webllm(config) {
1296
+ let enginePromise = null;
1297
+ const getEngine = () => {
1298
+ if (config.engine) return Promise.resolve(config.engine);
1299
+ if (!enginePromise) {
1300
+ enginePromise = (async () => {
1301
+ const sdk = await loadSdk2();
1302
+ return sdk.CreateMLCEngine(config.model, { initProgressCallback: config.onProgress });
1303
+ })();
1304
+ }
1305
+ return enginePromise;
1306
+ };
1307
+ return {
1308
+ capabilities: {
1309
+ streaming: true,
1310
+ tools: false
1311
+ },
1312
+ createSource: (request) => {
1313
+ let aborted = false;
1314
+ return {
1315
+ stream: async function* () {
1316
+ if (aborted) return;
1317
+ try {
1318
+ const engine = await getEngine();
1319
+ const messages = request.messages.map((m) => ({ role: m.role, content: m.content }));
1320
+ const completion = await engine.chat.completions.create({ messages, stream: true });
1321
+ for await (const chunk of completion) {
1322
+ if (aborted) return;
1323
+ const delta = chunk.choices[0]?.delta?.content;
1324
+ if (delta) yield { type: "text", content: delta };
1325
+ }
1326
+ yield { type: "done" };
1327
+ } catch (err) {
1328
+ yield { type: "error", content: err instanceof Error ? err.message : String(err) };
1329
+ }
1330
+ },
1331
+ abort: () => {
1332
+ aborted = true;
1333
+ }
1334
+ };
1335
+ }
1336
+ };
1337
+ }
1338
+ var webllmAdapter = webllm;
1339
+
1277
1340
  // src/router.ts
1278
1341
  function requireCapabilities(request) {
1279
1342
  const needs = {};
@@ -1852,5 +1915,7 @@ exports.vercelAI = vercelAI;
1852
1915
  exports.vertex = vertex;
1853
1916
  exports.vertexAdapter = vertexAdapter;
1854
1917
  exports.vllm = vllm;
1918
+ exports.webllm = webllm;
1919
+ exports.webllmAdapter = webllmAdapter;
1855
1920
  //# sourceMappingURL=index.cjs.map
1856
1921
  //# sourceMappingURL=index.cjs.map