@capybara-hq/testing 0.1.0-rc.6 → 0.1.0-rc.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.
@@ -96,15 +96,16 @@ export declare function joinOrg(k: Pick<TestKernel, "http">, owner: KernelReques
96
96
  req: KernelRequest;
97
97
  }>;
98
98
  /**
99
- * Creates an org-visible agent; returns its id. Without `tools` the agent has none (model-fake then
100
- * answers ordinary messages instead of calling the first tool).
99
+ * Creates an org-visible agent; returns its id. An agent has every tool the org offers unless
100
+ * `disabledTools` turns it off (tools default-on spec); with several tools model-fake answers
101
+ * ordinary messages instead of calling one.
101
102
  */
102
103
  export declare function createAgent(req: KernelRequest, orgId: string, opts?: {
103
104
  model?: {
104
105
  provider: string;
105
106
  model: string;
106
107
  };
107
- tools?: unknown[];
108
+ disabledTools?: unknown[];
108
109
  }): Promise<string>;
109
110
  /** Creates a conversation with the agent; returns its id. */
110
111
  export declare function createConversation(req: KernelRequest, orgId: string, agentId: string): Promise<string>;
@@ -178,8 +178,9 @@ export async function joinOrg(k, owner, orgId, name, role = "member") {
178
178
  return { accountId: accepted.json().account.id, req };
179
179
  }
180
180
  /**
181
- * Creates an org-visible agent; returns its id. Without `tools` the agent has none (model-fake then
182
- * answers ordinary messages instead of calling the first tool).
181
+ * Creates an org-visible agent; returns its id. An agent has every tool the org offers unless
182
+ * `disabledTools` turns it off (tools default-on spec); with several tools model-fake answers
183
+ * ordinary messages instead of calling one.
183
184
  */
184
185
  export async function createAgent(req, orgId, opts = {}) {
185
186
  const res = await req({
@@ -190,7 +191,7 @@ export async function createAgent(req, orgId, opts = {}) {
190
191
  name: "Helper",
191
192
  instructions: "Be helpful.",
192
193
  model: opts.model ?? { provider: "model-fake", model: "fake-1" },
193
- tools: opts.tools ?? [],
194
+ disabledTools: opts.disabledTools ?? [],
194
195
  },
195
196
  visibility: "org",
196
197
  },
@@ -4,6 +4,11 @@ interface TargetCommon {
4
4
  expect: {
5
5
  thinking: boolean;
6
6
  caching: boolean;
7
+ /** Set when the provider lists an embedding model: runs the embedding cases. */
8
+ embedding?: {
9
+ model: string;
10
+ dimensions: number;
11
+ };
7
12
  };
8
13
  /** caching 用例的稳定前缀大小(约 token 数),默认 5000。 */
9
14
  cachePrefixTokens?: number;
@@ -1,4 +1,4 @@
1
- import { assertValidDeclarations, EFFORT_VALUES, isModelError, sanitizeParams, validateParams, } from "@capybara-hq/plugin-sdk";
1
+ import { assertValidDeclarations, EFFORT_VALUES, isModelError, sanitizeParams, validateEmbedResult, validateParams, } from "@capybara-hq/plugin-sdk";
2
2
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
3
3
  import { pdfBase64, redPngBase64 } from "./media-samples.js";
4
4
  function streamOf(t, req, signal) {
@@ -260,6 +260,38 @@ export function describeModelProviderConformance(name, setup) {
260
260
  expect(done.stopReason).toBe("end_turn");
261
261
  expect(textOf(done.content).toUpperCase()).toContain(s.word);
262
262
  });
263
+ describe("embedding", () => {
264
+ const inputs = ["alpha", "bravo", "charlie"];
265
+ const run = async () => {
266
+ const emb = t.expect.embedding;
267
+ const provider = t.provider;
268
+ if (!emb || !provider.embed)
269
+ throw new Error("the target declares embedding but has no embed");
270
+ const req = { model: emb.model, input: inputs, dimensions: emb.dimensions };
271
+ const res = await provider.embed(req, { signal: new AbortController().signal });
272
+ const models = await provider.listModels();
273
+ const info = models.find((m) => m.id === emb.model)?.embedding;
274
+ return { req, res, info };
275
+ };
276
+ it("embeds a batch in order", async (ctx) => {
277
+ if (!t.expect.embedding)
278
+ return ctx.skip();
279
+ const { res } = await run();
280
+ expect(res.vectors).toHaveLength(inputs.length);
281
+ for (const v of res.vectors)
282
+ expect(v).toHaveLength(t.expect.embedding.dimensions);
283
+ expect(res.usage.inputTokens).toBeGreaterThanOrEqual(0);
284
+ });
285
+ it("embed result passes validateEmbedResult", async (ctx) => {
286
+ if (!t.expect.embedding)
287
+ return ctx.skip();
288
+ const { req, res, info } = await run();
289
+ expect(info).toBeDefined();
290
+ if (!info)
291
+ return;
292
+ expect(validateEmbedResult(req, info, res)).toBeNull();
293
+ });
294
+ });
263
295
  it("abort", async () => {
264
296
  const ac = new AbortController();
265
297
  const it = streamOf(t, base(), ac.signal)[Symbol.asyncIterator]();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/testing",
3
- "version": "0.1.0-rc.6",
3
+ "version": "0.1.0-rc.8",
4
4
  "description": "Test helpers for Capybara: test containers, dual-replica harness and fake third-party servers",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -47,17 +47,17 @@
47
47
  "tsx": "^4.23.15",
48
48
  "ws": "^8.22.0",
49
49
  "zod": "^4.6.7",
50
- "@capybara-hq/kernel": "^0.1.0-rc.5"
50
+ "@capybara-hq/kernel": "^0.1.0-rc.7"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/pg": "^8.23.1",
54
54
  "@types/ws": "^8.18.2",
55
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.3"
55
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.5"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "vitest": "^5.0.5",
59
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.3",
60
- "@capybara-hq/plugin-tools": "^0.1.0-rc.5"
59
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.5",
60
+ "@capybara-hq/plugin-tools": "^0.1.0-rc.6"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "@capybara-hq/plugin-tools": {