@aigne/core 1.18.3 → 1.18.4

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/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@
5
5
 
6
6
  * add user context support ([#131](https://github.com/AIGNE-io/aigne-framework/issues/131)) ([4dd9d20](https://github.com/AIGNE-io/aigne-framework/commit/4dd9d20953f6ac33933723db56efd9b44bafeb02))
7
7
 
8
+ ## [1.18.4](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.18.3...core-v1.18.4) (2025-06-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **core:** prioritize returning json chunks ([#151](https://github.com/AIGNE-io/aigne-framework/issues/151)) ([8bf49a1](https://github.com/AIGNE-io/aigne-framework/commit/8bf49a18c083b33d2e0b35e8d0f22f68d9d6effa))
14
+
8
15
  ## [1.18.3](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.18.2...core-v1.18.3) (2025-06-05)
9
16
 
10
17
 
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.AIGNEContext = void 0;
7
+ const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
4
8
  const strict_event_emitter_1 = require("strict-event-emitter");
5
9
  const uuid_1 = require("uuid");
6
10
  const zod_1 = require("zod");
@@ -182,7 +186,6 @@ class AIGNEContextShared {
182
186
  }
183
187
  async *invokeAgent(agent, input, context, options) {
184
188
  let activeAgent = agent;
185
- let output;
186
189
  for (;;) {
187
190
  const result = {};
188
191
  if (options?.sourceAgent && activeAgent !== options.sourceAgent) {
@@ -195,12 +198,14 @@ class AIGNEContextShared {
195
198
  }
196
199
  const stream = await activeAgent.invoke(input, { ...options, context, streaming: true });
197
200
  for await (const value of stream) {
198
- if (value.delta.text) {
199
- yield { delta: { text: value.delta.text } };
200
- }
201
201
  if (value.delta.json) {
202
+ value.delta.json = omitExistsProperties(result, value.delta.json);
202
203
  Object.assign(result, value.delta.json);
203
204
  }
205
+ delete value.delta.json?.[types_js_1.transferAgentOutputKey];
206
+ if ((0, agent_js_1.isEmptyChunk)(value))
207
+ continue;
208
+ yield value;
204
209
  }
205
210
  if (!options?.disableTransfer) {
206
211
  const transferToAgent = (0, types_js_1.isTransferAgentOutput)(result)
@@ -211,21 +216,22 @@ class AIGNEContextShared {
211
216
  continue;
212
217
  }
213
218
  }
214
- output = result;
215
219
  break;
216
220
  }
217
- if (!output)
218
- throw new Error("Unexpected empty output");
219
221
  yield {
220
222
  delta: {
221
- json: {
222
- ...output,
223
- __activeAgent__: activeAgent,
224
- },
223
+ json: { __activeAgent__: activeAgent },
225
224
  },
226
225
  };
227
226
  }
228
227
  }
228
+ function omitExistsProperties(result, { ...delta }) {
229
+ for (const [key, val] of Object.entries(delta)) {
230
+ if ((0, fast_deep_equal_1.default)(result[key], val))
231
+ delete delta[key];
232
+ }
233
+ return (0, type_utils_js_1.isEmpty)(delta) ? undefined : delta;
234
+ }
229
235
  async function* withAbortSignal(signal, error, fn) {
230
236
  const iterator = fn();
231
237
  const timeoutPromise = (0, promise_js_1.promiseWithResolvers)();
@@ -1,13 +1,14 @@
1
+ import equal from "fast-deep-equal";
1
2
  import { Emitter } from "strict-event-emitter";
2
3
  import { v7 } from "uuid";
3
4
  import { z } from "zod";
4
- import { Agent, } from "../agents/agent.js";
5
+ import { Agent, isEmptyChunk, } from "../agents/agent.js";
5
6
  import { isTransferAgentOutput, transferAgentOutputKey, } from "../agents/types.js";
6
7
  import { UserAgent } from "../agents/user-agent.js";
7
8
  import { createMessage } from "../prompt/prompt-builder.js";
8
9
  import { promiseWithResolvers } from "../utils/promise.js";
9
10
  import { agentResponseStreamToObject, asyncGeneratorToReadableStream, onAgentResponseStreamEnd, } from "../utils/stream-utils.js";
10
- import { checkArguments, isNil, omitBy, } from "../utils/type-utils.js";
11
+ import { checkArguments, isEmpty, isNil, omitBy, } from "../utils/type-utils.js";
11
12
  import { MessageQueue, toMessagePayload, } from "./message-queue.js";
12
13
  import { newEmptyContextUsage } from "./usage.js";
13
14
  /**
@@ -178,7 +179,6 @@ class AIGNEContextShared {
178
179
  }
179
180
  async *invokeAgent(agent, input, context, options) {
180
181
  let activeAgent = agent;
181
- let output;
182
182
  for (;;) {
183
183
  const result = {};
184
184
  if (options?.sourceAgent && activeAgent !== options.sourceAgent) {
@@ -191,12 +191,14 @@ class AIGNEContextShared {
191
191
  }
192
192
  const stream = await activeAgent.invoke(input, { ...options, context, streaming: true });
193
193
  for await (const value of stream) {
194
- if (value.delta.text) {
195
- yield { delta: { text: value.delta.text } };
196
- }
197
194
  if (value.delta.json) {
195
+ value.delta.json = omitExistsProperties(result, value.delta.json);
198
196
  Object.assign(result, value.delta.json);
199
197
  }
198
+ delete value.delta.json?.[transferAgentOutputKey];
199
+ if (isEmptyChunk(value))
200
+ continue;
201
+ yield value;
200
202
  }
201
203
  if (!options?.disableTransfer) {
202
204
  const transferToAgent = isTransferAgentOutput(result)
@@ -207,21 +209,22 @@ class AIGNEContextShared {
207
209
  continue;
208
210
  }
209
211
  }
210
- output = result;
211
212
  break;
212
213
  }
213
- if (!output)
214
- throw new Error("Unexpected empty output");
215
214
  yield {
216
215
  delta: {
217
- json: {
218
- ...output,
219
- __activeAgent__: activeAgent,
220
- },
216
+ json: { __activeAgent__: activeAgent },
221
217
  },
222
218
  };
223
219
  }
224
220
  }
221
+ function omitExistsProperties(result, { ...delta }) {
222
+ for (const [key, val] of Object.entries(delta)) {
223
+ if (equal(result[key], val))
224
+ delete delta[key];
225
+ }
226
+ return isEmpty(delta) ? undefined : delta;
227
+ }
225
228
  async function* withAbortSignal(signal, error, fn) {
226
229
  const iterator = fn();
227
230
  const timeoutPromise = promiseWithResolvers();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.18.3",
3
+ "version": "1.18.4",
4
4
  "description": "AIGNE core library for building AI-powered applications",
5
5
  "publishConfig": {
6
6
  "access": "public"