@karmaniverous/jeeves-meta 0.13.7 → 0.13.8

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.
@@ -9275,17 +9275,20 @@ class GatewayExecutor {
9275
9275
  }
9276
9276
  }
9277
9277
  /** Invoke a gateway tool via the /tools/invoke HTTP endpoint. */
9278
- async invoke(tool, args) {
9278
+ async invoke(tool, args, sessionKey) {
9279
9279
  const headers = {
9280
9280
  'Content-Type': 'application/json',
9281
9281
  };
9282
9282
  if (this.apiKey) {
9283
9283
  headers['Authorization'] = 'Bearer ' + this.apiKey;
9284
9284
  }
9285
+ const body = { tool, args };
9286
+ if (sessionKey)
9287
+ body.sessionKey = sessionKey;
9285
9288
  const res = await fetch(this.gatewayUrl + '/tools/invoke', {
9286
9289
  method: 'POST',
9287
9290
  headers,
9288
- body: JSON.stringify({ tool, args }),
9291
+ body: JSON.stringify(body),
9289
9292
  });
9290
9293
  if (!res.ok) {
9291
9294
  const text = await res.text();
@@ -9298,12 +9301,12 @@ class GatewayExecutor {
9298
9301
  return data;
9299
9302
  }
9300
9303
  /** Look up totalTokens for a session via sessions_list. */
9301
- async getSessionTokens(sessionKey) {
9304
+ async getSessionTokens(sessionKey, invokeSessionKey) {
9302
9305
  try {
9303
9306
  const result = await this.invoke('sessions_list', {
9304
9307
  limit: 20,
9305
9308
  messageLimit: 0,
9306
- });
9309
+ }, invokeSessionKey);
9307
9310
  const sessions = (result.result?.details?.sessions ??
9308
9311
  result.result?.sessions ??
9309
9312
  []);
@@ -9331,6 +9334,7 @@ class GatewayExecutor {
9331
9334
  // Generate unique output path for file-based output
9332
9335
  const outputId = randomUUID();
9333
9336
  const outputPath = this.workspaceDir + '/output-' + outputId + '.json';
9337
+ const invokeSessionKey = 'agent:main:meta-invoke:' + outputId;
9334
9338
  // Append file output instruction to the task
9335
9339
  const taskWithOutput = task +
9336
9340
  '\n\n## OUTPUT DELIVERY\n\n' +
@@ -9348,7 +9352,7 @@ class GatewayExecutor {
9348
9352
  runTimeoutSeconds: timeoutSeconds,
9349
9353
  ...(options?.thinking ? { thinking: options.thinking } : {}),
9350
9354
  ...(options?.model ? { model: options.model } : {}),
9351
- });
9355
+ }, invokeSessionKey);
9352
9356
  const details = (spawnResult.result?.details ?? spawnResult.result);
9353
9357
  const sessionKey = details?.childSessionKey ?? details?.sessionKey;
9354
9358
  if (typeof sessionKey !== 'string' || !sessionKey) {
@@ -9368,7 +9372,7 @@ class GatewayExecutor {
9368
9372
  sessionKey,
9369
9373
  limit: 5,
9370
9374
  includeTools: false,
9371
- });
9375
+ }, invokeSessionKey);
9372
9376
  const messages = historyResult.result?.details?.messages ??
9373
9377
  historyResult.result?.messages ??
9374
9378
  [];
@@ -9381,7 +9385,7 @@ class GatewayExecutor {
9381
9385
  lastMsg.stopReason !== 'toolUse' &&
9382
9386
  lastMsg.stopReason !== 'error') {
9383
9387
  // Fetch token usage from session metadata
9384
- const tokens = await this.getSessionTokens(sessionKey);
9388
+ const tokens = await this.getSessionTokens(sessionKey, invokeSessionKey);
9385
9389
  // Read output from file (sub-agent wrote it via Write tool)
9386
9390
  if (existsSync(outputPath)) {
9387
9391
  try {
package/dist/index.js CHANGED
@@ -8994,17 +8994,20 @@ class GatewayExecutor {
8994
8994
  }
8995
8995
  }
8996
8996
  /** Invoke a gateway tool via the /tools/invoke HTTP endpoint. */
8997
- async invoke(tool, args) {
8997
+ async invoke(tool, args, sessionKey) {
8998
8998
  const headers = {
8999
8999
  'Content-Type': 'application/json',
9000
9000
  };
9001
9001
  if (this.apiKey) {
9002
9002
  headers['Authorization'] = 'Bearer ' + this.apiKey;
9003
9003
  }
9004
+ const body = { tool, args };
9005
+ if (sessionKey)
9006
+ body.sessionKey = sessionKey;
9004
9007
  const res = await fetch(this.gatewayUrl + '/tools/invoke', {
9005
9008
  method: 'POST',
9006
9009
  headers,
9007
- body: JSON.stringify({ tool, args }),
9010
+ body: JSON.stringify(body),
9008
9011
  });
9009
9012
  if (!res.ok) {
9010
9013
  const text = await res.text();
@@ -9017,12 +9020,12 @@ class GatewayExecutor {
9017
9020
  return data;
9018
9021
  }
9019
9022
  /** Look up totalTokens for a session via sessions_list. */
9020
- async getSessionTokens(sessionKey) {
9023
+ async getSessionTokens(sessionKey, invokeSessionKey) {
9021
9024
  try {
9022
9025
  const result = await this.invoke('sessions_list', {
9023
9026
  limit: 20,
9024
9027
  messageLimit: 0,
9025
- });
9028
+ }, invokeSessionKey);
9026
9029
  const sessions = (result.result?.details?.sessions ??
9027
9030
  result.result?.sessions ??
9028
9031
  []);
@@ -9050,6 +9053,7 @@ class GatewayExecutor {
9050
9053
  // Generate unique output path for file-based output
9051
9054
  const outputId = randomUUID();
9052
9055
  const outputPath = this.workspaceDir + '/output-' + outputId + '.json';
9056
+ const invokeSessionKey = 'agent:main:meta-invoke:' + outputId;
9053
9057
  // Append file output instruction to the task
9054
9058
  const taskWithOutput = task +
9055
9059
  '\n\n## OUTPUT DELIVERY\n\n' +
@@ -9067,7 +9071,7 @@ class GatewayExecutor {
9067
9071
  runTimeoutSeconds: timeoutSeconds,
9068
9072
  ...(options?.thinking ? { thinking: options.thinking } : {}),
9069
9073
  ...(options?.model ? { model: options.model } : {}),
9070
- });
9074
+ }, invokeSessionKey);
9071
9075
  const details = (spawnResult.result?.details ?? spawnResult.result);
9072
9076
  const sessionKey = details?.childSessionKey ?? details?.sessionKey;
9073
9077
  if (typeof sessionKey !== 'string' || !sessionKey) {
@@ -9087,7 +9091,7 @@ class GatewayExecutor {
9087
9091
  sessionKey,
9088
9092
  limit: 5,
9089
9093
  includeTools: false,
9090
- });
9094
+ }, invokeSessionKey);
9091
9095
  const messages = historyResult.result?.details?.messages ??
9092
9096
  historyResult.result?.messages ??
9093
9097
  [];
@@ -9100,7 +9104,7 @@ class GatewayExecutor {
9100
9104
  lastMsg.stopReason !== 'toolUse' &&
9101
9105
  lastMsg.stopReason !== 'error') {
9102
9106
  // Fetch token usage from session metadata
9103
- const tokens = await this.getSessionTokens(sessionKey);
9107
+ const tokens = await this.getSessionTokens(sessionKey, invokeSessionKey);
9104
9108
  // Read output from file (sub-agent wrote it via Write tool)
9105
9109
  if (existsSync(outputPath)) {
9106
9110
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karmaniverous/jeeves-meta",
3
- "version": "0.13.7",
3
+ "version": "0.13.8",
4
4
  "author": "Jason Williscroft",
5
5
  "description": "Fastify HTTP service for the Jeeves Meta synthesis engine",
6
6
  "license": "BSD-3-Clause",