zangief 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +115 -33
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -60866,7 +60866,11 @@ AVAILABLE GADGETS`);
60866
60866
  `);
60867
60867
  for (const gadget of gadgets) {
60868
60868
  const gadgetName = gadget.name ?? gadget.constructor.name;
60869
- const instruction = gadget.getInstruction(this.argPrefix);
60869
+ const instruction = gadget.getInstruction({
60870
+ argPrefix: this.argPrefix,
60871
+ startPrefix: this.startPrefix,
60872
+ endPrefix: this.endPrefix
60873
+ });
60870
60874
  const schemaMarker = `
60871
60875
 
60872
60876
  Input Schema (BLOCK):`;
@@ -64792,13 +64796,13 @@ var init_openai = __esm2({
64792
64796
  async generateSpeech(options) {
64793
64797
  const client = this.client;
64794
64798
  const spec = getOpenAISpeechModelSpec(options.model);
64795
- const format = options.responseFormat ?? spec?.defaultFormat ?? "mp3";
64799
+ const format2 = options.responseFormat ?? spec?.defaultFormat ?? "mp3";
64796
64800
  const voice = options.voice ?? spec?.defaultVoice ?? "alloy";
64797
64801
  const response = await client.audio.speech.create({
64798
64802
  model: options.model,
64799
64803
  input: options.input,
64800
64804
  voice,
64801
- response_format: format,
64805
+ response_format: format2,
64802
64806
  speed: options.speed ?? 1
64803
64807
  });
64804
64808
  const audioBuffer = await response.arrayBuffer();
@@ -64810,7 +64814,7 @@ var init_openai = __esm2({
64810
64814
  characterCount: options.input.length
64811
64815
  },
64812
64816
  cost,
64813
- format
64817
+ format: format2
64814
64818
  };
64815
64819
  }
64816
64820
  buildApiRequest(options, descriptor, spec, messages) {
@@ -66320,7 +66324,8 @@ var init_executor = __esm2({
66320
66324
  } else {
66321
66325
  validatedParameters = schemaAwareParameters;
66322
66326
  }
66323
- const timeoutMs = gadget.timeoutMs ?? this.defaultGadgetTimeoutMs;
66327
+ const subagentTimeout = this.subagentConfig?.[call.gadgetName]?.timeoutMs;
66328
+ const timeoutMs = subagentTimeout ?? gadget.timeoutMs ?? this.defaultGadgetTimeoutMs;
66324
66329
  const abortController = new AbortController;
66325
66330
  let callbackCost = 0;
66326
66331
  const reportCost = (amount) => {
@@ -66347,7 +66352,8 @@ var init_executor = __esm2({
66347
66352
  nodeId: gadgetNodeId,
66348
66353
  depth: gadgetDepth,
66349
66354
  hostExports: getHostExportsInternal(),
66350
- logger: this.logger
66355
+ logger: this.logger,
66356
+ requestHumanInput: this.requestHumanInput
66351
66357
  };
66352
66358
  let rawResult;
66353
66359
  if (timeoutMs && timeoutMs > 0) {
@@ -66543,6 +66549,9 @@ var init_stream_processor = __esm2({
66543
66549
  failedInvocations = /* @__PURE__ */ new Set;
66544
66550
  inFlightExecutions = /* @__PURE__ */ new Map;
66545
66551
  completedResultsQueue = [];
66552
+ subagentConfig;
66553
+ activeCountByGadget = /* @__PURE__ */ new Map;
66554
+ concurrencyQueue = /* @__PURE__ */ new Map;
66546
66555
  priorCompletedInvocations;
66547
66556
  priorFailedInvocations;
66548
66557
  constructor(options) {
@@ -66555,6 +66564,7 @@ var init_stream_processor = __esm2({
66555
66564
  this.baseDepth = options.baseDepth ?? 0;
66556
66565
  this.priorCompletedInvocations = options.priorCompletedInvocations ?? /* @__PURE__ */ new Set;
66557
66566
  this.priorFailedInvocations = options.priorFailedInvocations ?? /* @__PURE__ */ new Set;
66567
+ this.subagentConfig = options.subagentConfig;
66558
66568
  this.parser = new GadgetCallParser({
66559
66569
  startPrefix: options.gadgetStartPrefix,
66560
66570
  endPrefix: options.gadgetEndPrefix,
@@ -66779,9 +66789,53 @@ var init_stream_processor = __esm2({
66779
66789
  }
66780
66790
  return;
66781
66791
  }
66782
- const executionPromise = this.executeGadgetAndCollect(call);
66792
+ const limit2 = this.getConcurrencyLimit(call.gadgetName);
66793
+ const activeCount = this.activeCountByGadget.get(call.gadgetName) ?? 0;
66794
+ if (limit2 > 0 && activeCount >= limit2) {
66795
+ this.logger.debug("Gadget queued due to concurrency limit", {
66796
+ gadgetName: call.gadgetName,
66797
+ invocationId: call.invocationId,
66798
+ activeCount,
66799
+ limit: limit2
66800
+ });
66801
+ const queue = this.concurrencyQueue.get(call.gadgetName) ?? [];
66802
+ queue.push(call);
66803
+ this.concurrencyQueue.set(call.gadgetName, queue);
66804
+ return;
66805
+ }
66806
+ this.startGadgetWithConcurrencyTracking(call);
66807
+ }
66808
+ getConcurrencyLimit(gadgetName) {
66809
+ const config2 = this.subagentConfig?.[gadgetName];
66810
+ return config2?.maxConcurrent ?? 0;
66811
+ }
66812
+ startGadgetWithConcurrencyTracking(call) {
66813
+ const gadgetName = call.gadgetName;
66814
+ const currentCount = this.activeCountByGadget.get(gadgetName) ?? 0;
66815
+ this.activeCountByGadget.set(gadgetName, currentCount + 1);
66816
+ const executionPromise = this.executeGadgetAndCollect(call).finally(() => {
66817
+ const newCount = (this.activeCountByGadget.get(gadgetName) ?? 1) - 1;
66818
+ this.activeCountByGadget.set(gadgetName, newCount);
66819
+ this.processQueuedGadget(gadgetName);
66820
+ });
66783
66821
  this.inFlightExecutions.set(call.invocationId, executionPromise);
66784
66822
  }
66823
+ processQueuedGadget(gadgetName) {
66824
+ const queue = this.concurrencyQueue.get(gadgetName);
66825
+ if (!queue || queue.length === 0)
66826
+ return;
66827
+ const limit2 = this.getConcurrencyLimit(gadgetName);
66828
+ const activeCount = this.activeCountByGadget.get(gadgetName) ?? 0;
66829
+ if (limit2 === 0 || activeCount < limit2) {
66830
+ const nextCall = queue.shift();
66831
+ this.logger.debug("Processing queued gadget", {
66832
+ gadgetName,
66833
+ invocationId: nextCall.invocationId,
66834
+ remainingInQueue: queue.length
66835
+ });
66836
+ this.startGadgetWithConcurrencyTracking(nextCall);
66837
+ }
66838
+ }
66785
66839
  async* executeGadgetGenerator(call) {
66786
66840
  if (call.parseError) {
66787
66841
  this.logger.warn("Gadget has parse error", {
@@ -66946,27 +67000,49 @@ var init_stream_processor = __esm2({
66946
67000
  }
66947
67001
  }
66948
67002
  async* waitForInFlightExecutions() {
66949
- if (this.inFlightExecutions.size === 0) {
67003
+ if (this.inFlightExecutions.size === 0 && !this.hasQueuedGadgets()) {
66950
67004
  return;
66951
67005
  }
66952
67006
  this.logger.debug("Waiting for in-flight gadget executions", {
66953
67007
  count: this.inFlightExecutions.size,
66954
- invocationIds: Array.from(this.inFlightExecutions.keys())
67008
+ invocationIds: Array.from(this.inFlightExecutions.keys()),
67009
+ queuedCount: this.getQueuedGadgetCount()
66955
67010
  });
66956
- const allDone = Promise.all(this.inFlightExecutions.values()).then(() => "done");
66957
67011
  const POLL_INTERVAL_MS = 100;
66958
- while (true) {
67012
+ while (this.inFlightExecutions.size > 0 || this.hasQueuedGadgets()) {
67013
+ const allDone = this.inFlightExecutions.size > 0 ? Promise.all(this.inFlightExecutions.values()).then(() => "done") : Promise.resolve("done");
66959
67014
  const result = await Promise.race([
66960
67015
  allDone,
66961
67016
  new Promise((resolve) => setTimeout(() => resolve("poll"), POLL_INTERVAL_MS))
66962
67017
  ]);
66963
67018
  yield* this.drainCompletedResults();
66964
- if (result === "done") {
67019
+ if (result === "done" && this.getTotalActiveGadgetCount() === 0 && !this.hasQueuedGadgets()) {
66965
67020
  break;
66966
67021
  }
66967
67022
  }
66968
67023
  this.inFlightExecutions.clear();
66969
67024
  }
67025
+ hasQueuedGadgets() {
67026
+ for (const queue of this.concurrencyQueue.values()) {
67027
+ if (queue.length > 0)
67028
+ return true;
67029
+ }
67030
+ return false;
67031
+ }
67032
+ getQueuedGadgetCount() {
67033
+ let count = 0;
67034
+ for (const queue of this.concurrencyQueue.values()) {
67035
+ count += queue.length;
67036
+ }
67037
+ return count;
67038
+ }
67039
+ getTotalActiveGadgetCount() {
67040
+ let total = 0;
67041
+ for (const count of this.activeCountByGadget.values()) {
67042
+ total += count;
67043
+ }
67044
+ return total;
67045
+ }
66970
67046
  async handleFailedDependency(call, failedDep) {
66971
67047
  const events = [];
66972
67048
  const depResult = this.completedResults.get(failedDep);
@@ -68010,6 +68086,9 @@ var init_builder = __esm2({
68010
68086
  if (ctx.signal && !this.signal) {
68011
68087
  this.signal = ctx.signal;
68012
68088
  }
68089
+ if (ctx.logger && !this.logger) {
68090
+ this.logger = ctx.logger;
68091
+ }
68013
68092
  return this;
68014
68093
  }
68015
68094
  withTrailingMessage(message) {
@@ -68237,6 +68316,30 @@ init_anthropic();
68237
68316
  init_discovery();
68238
68317
  init_gemini();
68239
68318
  init_openai();
68319
+ function formatBytes(bytes2, decimals = 1) {
68320
+ if (bytes2 === 0)
68321
+ return "0 B";
68322
+ const k = 1024;
68323
+ const sizes = ["B", "KB", "MB", "GB", "TB", "PB"];
68324
+ const i2 = Math.floor(Math.log(bytes2) / Math.log(k));
68325
+ const size = bytes2 / Math.pow(k, i2);
68326
+ const formatted = size % 1 === 0 ? size.toString() : size.toFixed(decimals);
68327
+ return `${formatted} ${sizes[i2]}`;
68328
+ }
68329
+ function formatDate(isoDate, options = {
68330
+ year: "numeric",
68331
+ month: "short",
68332
+ day: "numeric",
68333
+ hour: "2-digit",
68334
+ minute: "2-digit"
68335
+ }) {
68336
+ try {
68337
+ const date5 = new Date(isoDate);
68338
+ return date5.toLocaleString(undefined, options);
68339
+ } catch {
68340
+ return isoDate;
68341
+ }
68342
+ }
68240
68343
 
68241
68344
  // src/client.ts
68242
68345
  var SOURCEGRAPH_API_URL = "https://sourcegraph.com/.api/graphql";
@@ -68426,27 +68529,6 @@ function formatFileContent(repo, path5, content, byteSize) {
68426
68529
  return lines.join(`
68427
68530
  `);
68428
68531
  }
68429
- function formatBytes(bytes2) {
68430
- if (bytes2 < 1024)
68431
- return `${bytes2} bytes`;
68432
- if (bytes2 < 1024 * 1024)
68433
- return `${(bytes2 / 1024).toFixed(1)} KB`;
68434
- return `${(bytes2 / (1024 * 1024)).toFixed(1)} MB`;
68435
- }
68436
- function formatDate(isoDate) {
68437
- try {
68438
- const date5 = new Date(isoDate);
68439
- return date5.toLocaleDateString("en-US", {
68440
- year: "numeric",
68441
- month: "short",
68442
- day: "numeric",
68443
- hour: "2-digit",
68444
- minute: "2-digit"
68445
- });
68446
- } catch {
68447
- return isoDate;
68448
- }
68449
- }
68450
68532
 
68451
68533
  // src/gadgets/search.ts
68452
68534
  var SEARCH_QUERY = `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zangief",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "llmist gadgets for exploring GitHub repos via Sourcegraph API",
6
6
  "main": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "scripts": {
18
- "build": "bun build src/index.ts --outdir dist --target node",
18
+ "build": "bun build src/index.ts --outdir dist --target node --external:tiktoken",
19
19
  "dev": "bun run src/index.ts",
20
20
  "demo": "bun run examples/demo.ts",
21
21
  "typecheck": "tsc --noEmit"