@finalai/agent-provider 0.19.0 → 0.20.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.
@@ -2,7 +2,7 @@ import {
2
2
  client,
3
3
  methods,
4
4
  PROTOCOL_VERSION
5
- } from "@agentclientprotocol/sdk/experimental/v2";
5
+ } from "@agentclientprotocol/sdk/experimental/v2/unstable";
6
6
  import {
7
7
  accumulateAgentMessages,
8
8
  acpSchemas,
@@ -174,7 +174,6 @@ const toolBlocksOf = (updates) => updates.flatMap((update) => {
174
174
  });
175
175
  const requestIdSchema = z.object({ id: z.union([z.string(), z.number()]), method: z.string() });
176
176
  const responseIdSchema = z.object({ id: z.union([z.string(), z.number(), z.null()]) });
177
- const isBatch = (wire) => Array.isArray(wire);
178
177
  const BIG_RESULT_BYTES = 3 * 1024 * 1024;
179
178
  const providerErrorSchema = z.object({
180
179
  [FINAL_META_KEY]: z.object({
@@ -389,11 +388,9 @@ const runHarnessConformance = async (args) => {
389
388
  const writer = inner.writable.getWriter();
390
389
  const writable = new WritableStream({
391
390
  write: async (wire) => {
392
- for (const message of isBatch(wire) ? wire : [wire]) {
393
- const request = requestIdSchema.safeParse(message);
394
- if (promptDrop.armed && promptDrop.id == null && request.success && request.data.method === methods.agent.session.prompt) {
395
- promptDrop.id = JSON.stringify(request.data.id);
396
- }
391
+ const request = requestIdSchema.safeParse(wire);
392
+ if (promptDrop.armed && promptDrop.id == null && request.success && request.data.method === methods.agent.session.prompt) {
393
+ promptDrop.id = JSON.stringify(request.data.id);
397
394
  }
398
395
  await writer.write(wire);
399
396
  },
@@ -405,7 +402,7 @@ const runHarnessConformance = async (args) => {
405
402
  transform: (wire, controller) => {
406
403
  inboundFrameBytes.push(serializedFrameBytes(wire));
407
404
  const response = responseIdSchema.safeParse(wire);
408
- if (promptDrop.id != null && !isBatch(wire) && !("method" in wire) && response.success && JSON.stringify(response.data.id) === promptDrop.id) {
405
+ if (promptDrop.id != null && !("method" in wire) && response.success && JSON.stringify(response.data.id) === promptDrop.id) {
409
406
  promptDrop.id = null;
410
407
  promptDrop.armed = false;
411
408
  promptDrop.dropped = true;
@@ -1305,15 +1302,13 @@ const runHarnessConformance = async (args) => {
1305
1302
  const watch = watchInitializeVersion({
1306
1303
  writable: new WritableStream({
1307
1304
  write: async (wire) => {
1308
- for (const message of isBatch(wire) ? wire : [wire]) {
1309
- const close = z.object({
1310
- id: z.union([z.string(), z.number()]),
1311
- method: z.literal("session/close"),
1312
- params: z.object({ sessionId: z.string() })
1313
- }).safeParse(message);
1314
- if (close.success)
1315
- closeIds.set(JSON.stringify(close.data.id), close.data.params.sessionId);
1316
- }
1305
+ const close = z.object({
1306
+ id: z.union([z.string(), z.number()]),
1307
+ method: z.literal("session/close"),
1308
+ params: z.object({ sessionId: z.string() })
1309
+ }).safeParse(wire);
1310
+ if (close.success)
1311
+ closeIds.set(JSON.stringify(close.data.id), close.data.params.sessionId);
1317
1312
  await outgoing.write(wire);
1318
1313
  },
1319
1314
  close: () => outgoing.close(),
@@ -1322,27 +1317,24 @@ const runHarnessConformance = async (args) => {
1322
1317
  readable: dialed.readable.pipeThrough(
1323
1318
  new TransformStream({
1324
1319
  transform: (wire, controller) => {
1325
- for (const message of isBatch(wire) ? wire : [wire]) {
1326
- const state = z.object({
1327
- method: z.literal("session/update"),
1328
- params: z.object({
1329
- sessionId: z.string(),
1330
- update: z.object({
1331
- sessionUpdate: z.literal("state_update"),
1332
- state: z.string()
1333
- })
1320
+ const state = z.object({
1321
+ method: z.literal("session/update"),
1322
+ params: z.object({
1323
+ sessionId: z.string(),
1324
+ update: z.object({
1325
+ sessionUpdate: z.literal("state_update"),
1326
+ state: z.string()
1334
1327
  })
1335
- }).safeParse(message);
1336
- if (state.success) {
1337
- if (state.data.params.update.state === "idle")
1338
- idleSeen.add(state.data.params.sessionId);
1339
- else idleSeen.delete(state.data.params.sessionId);
1340
- }
1341
- const reply = z.object({ id: z.union([z.string(), z.number()]), result: z.unknown() }).safeParse(message);
1342
- const sessionId2 = reply.success ? closeIds.get(JSON.stringify(reply.data.id)) : null;
1343
- if (sessionId2 != null && idleSeen.has(sessionId2))
1344
- settledBeforeReply.add(sessionId2);
1328
+ })
1329
+ }).safeParse(wire);
1330
+ if (state.success) {
1331
+ if (state.data.params.update.state === "idle")
1332
+ idleSeen.add(state.data.params.sessionId);
1333
+ else idleSeen.delete(state.data.params.sessionId);
1345
1334
  }
1335
+ const reply = z.object({ id: z.union([z.string(), z.number()]), result: z.unknown() }).safeParse(wire);
1336
+ const sessionId2 = reply.success ? closeIds.get(JSON.stringify(reply.data.id)) : null;
1337
+ if (sessionId2 != null && idleSeen.has(sessionId2)) settledBeforeReply.add(sessionId2);
1346
1338
  controller.enqueue(wire);
1347
1339
  }
1348
1340
  })