libfx 0.0.12 → 0.0.13

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/node.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
 
21
21
  export { encodeXtermKeyEvent, fxSdkApiVersion, listModels, supportsJspi, xtermAdapter };
22
22
  export const libfxApiVersion = 2;
23
- const nativeCoreApiVersion = 3;
23
+ const nativeCoreApiVersion = 4;
24
24
 
25
25
  const fetchOperationStale = 0;
26
26
  const fetchOperationApplied = 1;
@@ -346,7 +346,12 @@ export async function getBackendInfo(value = {}) {
346
346
  }
347
347
 
348
348
  function createNativeCoreRuntime(addon, options) {
349
- const { apiKey, model, effort, fast, gatewayChatUrl } = options;
349
+ const { apiKey, model, effort, fast, ultrafast, gatewayChatUrl } = options;
350
+ if (ultrafast !== undefined && addon.supportsUltrafast !== true) {
351
+ const error = new Error("native addon does not support the ultrafast option");
352
+ error.code = "LIBFX_NATIVE_CAPABILITY_UNAVAILABLE";
353
+ throw error;
354
+ }
350
355
  const core = addon.createCore({
351
356
  apiKey,
352
357
  home: options.home ?? homedir(),
@@ -354,6 +359,7 @@ function createNativeCoreRuntime(addon, options) {
354
359
  ...(model === undefined ? {} : { model }),
355
360
  ...(effort === undefined ? {} : { effort }),
356
361
  ...(fast === undefined ? {} : { fast }),
362
+ ...(ultrafast === undefined ? {} : { ultrafast }),
357
363
  ...(gatewayChatUrl === undefined ? {} : { gatewayChatUrl }),
358
364
  });
359
365
  let readyFd;
@@ -391,7 +397,7 @@ function createNativeCoreRuntime(addon, options) {
391
397
  readySocket.destroy();
392
398
  void readyClosed.then(() => exitedResolve(code));
393
399
  };
394
- const pumpFetch = async (request) => {
400
+ const pumpFetch = async (request, body) => {
395
401
  const controller = new AbortController();
396
402
  const state = { handle: request.handle, controller };
397
403
  fetchState = state;
@@ -399,7 +405,7 @@ function createNativeCoreRuntime(addon, options) {
399
405
  const response = await (options.fetch ?? globalThis.fetch)(request.url, {
400
406
  method: request.method,
401
407
  headers: new Headers(JSON.parse(request.headers).map(({ name, value }) => [name, value])),
402
- body: request.body?.length ? Buffer.from(request.body, "base64") : undefined,
408
+ body: body.length ? body : undefined,
403
409
  signal: controller.signal,
404
410
  });
405
411
  const started = addon.startCoreFetchResponse(core, state.handle, response.status);
@@ -448,8 +454,9 @@ function createNativeCoreRuntime(addon, options) {
448
454
  fetchState.controller.abort();
449
455
  }
450
456
  } else {
457
+ // The core hands over JSON metadata and the raw request body separately.
451
458
  const fetchRequest = addon.takeCoreFetch(core);
452
- if (fetchRequest) void pumpFetch(JSON.parse(fetchRequest.toString("utf8")));
459
+ if (fetchRequest) void pumpFetch(JSON.parse(fetchRequest.request.toString("utf8")), fetchRequest.body);
453
460
  }
454
461
  if (addon.coreExitCode(core) !== 0) {
455
462
  finish(1, new Error("native output delivery failed"));
@@ -494,6 +501,12 @@ function createNativeCoreRuntime(addon, options) {
494
501
  exited,
495
502
  get error() { return outputError; },
496
503
  write(data) { addon.writeCore(core, Buffer.from(data)); },
504
+ // The addon copies attachment bytes before returning.
505
+ writeAttachment(id, bytes) {
506
+ addon.writeCoreAttachment(core, id, Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength));
507
+ },
508
+ takeAttachment(id) { return addon.takeCoreAttachment(core, id); },
509
+ discardAttachments() { addon.discardCoreAttachments(core); },
497
510
  closeStdin() { addon.closeCore(core); },
498
511
  abortHostEffects,
499
512
  abort(error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libfx",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Embed fx agents and terminals in JavaScript hosts",
5
5
  "type": "module",
6
6
  "repository": {