@zenera/gym 1.2.6 → 1.2.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.
- package/README.md +2 -3
- package/dist/catalog.d.ts +5 -5
- package/dist/catalog.js +5 -5
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +1 -1
- package/dist/synth.js +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -101,8 +101,7 @@ zen gym serve specs/calendar.yaml --story world.md --docs kb/ --port 8788
|
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
[`examples/mock-apis`](https://github.com/zenera-ai/ZeneraNeo/tree/main/examples/mock-apis)
|
|
104
|
-
has a story and a knowledge base for the mail and calendar specs beside it
|
|
105
|
-
another for an NSX network.
|
|
104
|
+
has a story and a knowledge base for the mail and calendar specs beside it.
|
|
106
105
|
|
|
107
106
|
Everything is indexed before the server listens, so no request waits on an
|
|
108
107
|
index. Write every handler up front, before a demo or a test run:
|
|
@@ -153,7 +152,7 @@ an inbox nobody has read yet, an id nobody has seen — `ctx.ensure` and
|
|
|
153
152
|
docs, and consistent with everything already in the world, checked against the
|
|
154
153
|
schema type before anything can read them. On a first read it makes what the
|
|
155
154
|
story says exists, however many that is. Records it refers to that do not exist
|
|
156
|
-
yet — a label, a
|
|
155
|
+
yet — a label, a calendar — it makes too, in their own collections.
|
|
157
156
|
`me`, `primary` and the like resolve through `ctx.owner()`, the account the story
|
|
158
157
|
says the API belongs to.
|
|
159
158
|
|
package/dist/catalog.d.ts
CHANGED
|
@@ -38,12 +38,12 @@ export declare class Catalog {
|
|
|
38
38
|
/**
|
|
39
39
|
* The type of the records an operation is about: its response type, or —
|
|
40
40
|
* when that is a list envelope with no identity of its own — the type its
|
|
41
|
-
* list holds. `
|
|
41
|
+
* list holds. `RouterListResult` is about `Router`; `Event` is about `Event`.
|
|
42
42
|
*/
|
|
43
43
|
itemType(operation: Operation): string | undefined;
|
|
44
44
|
/**
|
|
45
45
|
* A type's own properties and the ones it inherits through `allOf`, which is
|
|
46
|
-
* how most documents spell inheritance —
|
|
46
|
+
* how most documents spell inheritance — a `Router` built on a base resource declares little of
|
|
47
47
|
* what it holds itself.
|
|
48
48
|
*/
|
|
49
49
|
properties(type: string): {
|
|
@@ -56,8 +56,8 @@ export declare class Catalog {
|
|
|
56
56
|
/**
|
|
57
57
|
* Fields that point at other entities, judged by name: `*_id`, `*_path`,
|
|
58
58
|
* `*Ref`, `parent`, `owner`… Names rather than the schema because the
|
|
59
|
-
* schema rarely says:
|
|
60
|
-
*
|
|
59
|
+
* schema rarely says: a `gateway_path` is a string, and only its name and
|
|
60
|
+
* its description say it names a Gateway.
|
|
61
61
|
*/
|
|
62
62
|
references(type: string): {
|
|
63
63
|
name: string;
|
|
@@ -66,7 +66,7 @@ export declare class Catalog {
|
|
|
66
66
|
}[];
|
|
67
67
|
/**
|
|
68
68
|
* The type a reference field most likely names, from the field's name:
|
|
69
|
-
* `labelIds` → `Label`, `
|
|
69
|
+
* `labelIds` → `Label`, `availability_zone_path` → `AvailabilityZone`. A
|
|
70
70
|
* field that names no type — a `threadId` where threads are not a schema —
|
|
71
71
|
* has no referent, and cannot dangle.
|
|
72
72
|
*/
|
package/dist/catalog.js
CHANGED
|
@@ -159,7 +159,7 @@ export class Catalog {
|
|
|
159
159
|
/**
|
|
160
160
|
* The type of the records an operation is about: its response type, or —
|
|
161
161
|
* when that is a list envelope with no identity of its own — the type its
|
|
162
|
-
* list holds. `
|
|
162
|
+
* list holds. `RouterListResult` is about `Router`; `Event` is about `Event`.
|
|
163
163
|
*/
|
|
164
164
|
itemType(operation) {
|
|
165
165
|
const op = this.find(operation);
|
|
@@ -181,7 +181,7 @@ export class Catalog {
|
|
|
181
181
|
}
|
|
182
182
|
/**
|
|
183
183
|
* A type's own properties and the ones it inherits through `allOf`, which is
|
|
184
|
-
* how most documents spell inheritance —
|
|
184
|
+
* how most documents spell inheritance — a `Router` built on a base resource declares little of
|
|
185
185
|
* what it holds itself.
|
|
186
186
|
*/
|
|
187
187
|
properties(type) {
|
|
@@ -216,8 +216,8 @@ export class Catalog {
|
|
|
216
216
|
/**
|
|
217
217
|
* Fields that point at other entities, judged by name: `*_id`, `*_path`,
|
|
218
218
|
* `*Ref`, `parent`, `owner`… Names rather than the schema because the
|
|
219
|
-
* schema rarely says:
|
|
220
|
-
*
|
|
219
|
+
* schema rarely says: a `gateway_path` is a string, and only its name and
|
|
220
|
+
* its description say it names a Gateway.
|
|
221
221
|
*/
|
|
222
222
|
references(type) {
|
|
223
223
|
const own = this.idField(type);
|
|
@@ -231,7 +231,7 @@ export class Catalog {
|
|
|
231
231
|
}
|
|
232
232
|
/**
|
|
233
233
|
* The type a reference field most likely names, from the field's name:
|
|
234
|
-
* `labelIds` → `Label`, `
|
|
234
|
+
* `labelIds` → `Label`, `availability_zone_path` → `AvailabilityZone`. A
|
|
235
235
|
* field that names no type — a `threadId` where threads are not a schema —
|
|
236
236
|
* has no referent, and cannot dangle.
|
|
237
237
|
*/
|
package/dist/prompt.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Catalog } from './catalog.ts';
|
|
2
2
|
import type { HandlerRequest } from './runtime.ts';
|
|
3
3
|
import { type Operation } from './spec.ts';
|
|
4
|
-
export declare const SYSTEM = "You write the request handler for one operation of a simulated HTTP API.\n\nTHE HANDLER is one TypeScript module, run by Node.js as it is:\n\n export default async function handle(req, ctx) { ... return body; }\n\n- `req`: { operationId, method, path, pathParams, query, headers, body, seed }.\n pathParams and query values are strings, as on the wire.\n- Return the response body. It must match the response type exactly.\n- No imports of any kind. Only erasable TypeScript: type annotations, interfaces and\n `type` aliases are fine; enums, namespaces and parameter properties are not.\n- No network, no files, no timers, no global state between calls.\n\nTHE WORLD. All content lives in a shared world of records, grouped by type. Several\nAPIs share it, so a message listed here is the message read there. Your handler owns\nthe mechanics \u2014 which type, which filter, what a write changes \u2014 and never invents\ncontent itself. Name records by their schema TYPE (a name with a capital: \"Message\",\n\"
|
|
4
|
+
export declare const SYSTEM = "You write the request handler for one operation of a simulated HTTP API.\n\nTHE HANDLER is one TypeScript module, run by Node.js as it is:\n\n export default async function handle(req, ctx) { ... return body; }\n\n- `req`: { operationId, method, path, pathParams, query, headers, body, seed }.\n pathParams and query values are strings, as on the wire.\n- Return the response body. It must match the response type exactly.\n- No imports of any kind. Only erasable TypeScript: type annotations, interfaces and\n `type` aliases are fine; enums, namespaces and parameter properties are not.\n- No network, no files, no timers, no global state between calls.\n\nTHE WORLD. All content lives in a shared world of records, grouped by type. Several\nAPIs share it, so a message listed here is the message read there. Your handler owns\nthe mechanics \u2014 which type, which filter, what a write changes \u2014 and never invents\ncontent itself. Name records by their schema TYPE (a name with a capital: \"Message\",\n\"Router\"); the world knows which collection and id field each type has. When the world\nlacks what a request needs, ask for it and an agent writes it, consistent with\neverything else:\n\n ctx.db.collection(Type) sync: all(), get(id), has(id), find(fn), count(),\n put(id, record), putMany([{id, value}]), delete(id)\n await ctx.lookup(Type, id, { where?, hint?, idField? })\n the record with that id, made if missing\n await ctx.ensure(Type, { min?, count?, where?, hint? })\n all records (matching where), making some if fewer than min\n await ctx.synthesize({ collection: Type, count?, ids?, where?, hint? })\n make new records now; returns them, already stored\n await ctx.owner() the account the API is called as: { id, email, displayName, timeZone? }\n ctx.page(items, { token?, offset?, size?, defaultSize? })\n -> { items, nextToken, nextOffset, hasMore, total }\n ctx.fail(status, body?) answer with an HTTP error instead\n ctx.newId(pattern?) ctx.fromPattern(regex) ctx.now() ctx.random() ctx.int(a, b) ctx.pick(list)\n\n`idField` is for the first use of a type whose id property is not `id` (e.g. \"user_id\");\nafter that the binding remembers it. `where` pins values every made record must carry\n(e.g. { calendarId }); `hint` says in a sentence what the request is after (a search\nquery, a filter), so the made records actually answer it.\n\nHOW EACH KIND OF OPERATION WORKS\n- Read one (GET /things/{id}): `await ctx.lookup('Thing', req.pathParams.id)`.\n- List (GET /things): `await ctx.ensure('Thing', { where, hint })`, then filter by the\n query parameters that describe content (search text, dates, labels, owner\u2026) in code,\n sort as the API would, then `ctx.page`. If filtering leaves nothing for a query that\n plainly expects results, `await ctx.synthesize({ collection: 'Thing', hint: <the query> })` and filter again.\n- Create (POST): build the stored record from the request body plus the server-assigned\n fields (id via ctx.newId(<the id pattern>), timestamps via ctx.now(), status\u2026),\n `put` it, return it. Later reads must see it.\n- Update (PUT/PATCH): lookup, merge, put, return. Delete: delete, return what the schema asks.\n- Actions and computed answers (free/busy, search, stats\u2026): derive the answer from the\n collections they are about, ensuring those exist first.\n- Store whole records \u2014 the richest type the API has for the thing (e.g. a full\n `Message`, not a `MessageRef`) \u2014 and project to the response shape. Use the type\n sibling operations use: read their handlers first.\n- People come from the world, never from code. Ids that stand for the caller \u2014 \"me\",\n \"primary\", \"self\", \"default\" \u2014 mean `await ctx.owner()`: resolve them to the owner's\n email (or whatever id the other records use for that person) before you store or\n filter by them, so \"primary\" and the owner's address are one calendar. Fields like\n sender, organizer, author or owner on a record you create are the owner's.\n- Where a path parameter has the same name as a property of the response, the response\n carries the request's value.\n- Paging: always through ctx.page, passing the client's token or offset as given.\n The token is opaque and always advances; on the last page leave the next token out\n (or null, if the schema allows) and set any has-more flag false.\n\nREFERENCE DOCUMENTS. When the brief quotes documentation, or search_docs is among your\ntools, the documents describe behaviour the schema cannot: what a write changes\nelsewhere, what is refused and with which status, defaults, state transitions.\nImplement what they say. Content still comes from the world, never from the documents.\n\nWORKFLOW\n1. Look before writing: read_handler for the related operations already built,\n list_collections for what the world holds, describe_types for types you were not\n shown. In a large API, trace_api on the record type finds every operation that\n carries it, and grep_api / list_api find the rest. Read the reference documents\n when the operation's behaviour is not obvious from its schema.\n2. test_handler with the whole module. It runs the handler against probe requests in a\n copy of the world and reports every problem. Fix and test again until it passes.\n A passing test is the end of the job.";
|
|
5
5
|
export interface BriefOptions {
|
|
6
6
|
catalog: Catalog;
|
|
7
7
|
/** operations this one must agree with, closest first, and whether each has a handler */
|
package/dist/prompt.js
CHANGED
|
@@ -28,7 +28,7 @@ THE WORLD. All content lives in a shared world of records, grouped by type. Seve
|
|
|
28
28
|
APIs share it, so a message listed here is the message read there. Your handler owns
|
|
29
29
|
the mechanics — which type, which filter, what a write changes — and never invents
|
|
30
30
|
content itself. Name records by their schema TYPE (a name with a capital: "Message",
|
|
31
|
-
"
|
|
31
|
+
"Router"); the world knows which collection and id field each type has. When the world
|
|
32
32
|
lacks what a request needs, ask for it and an agent writes it, consistent with
|
|
33
33
|
everything else:
|
|
34
34
|
|
package/dist/runtime.d.ts
CHANGED
|
@@ -125,7 +125,7 @@ export declare const OWNER_TYPE = "@owner";
|
|
|
125
125
|
export declare const isTypeName: (name: string) => boolean;
|
|
126
126
|
/**
|
|
127
127
|
* The collection an unbound type gets: `Message` → `messages`,
|
|
128
|
-
* `
|
|
128
|
+
* `AvailabilityZone` → `availability_zones`. Only ever a first guess —
|
|
129
129
|
* once bound, the binding is the answer.
|
|
130
130
|
*/
|
|
131
131
|
export declare function collectionFor(type: string): string;
|
package/dist/runtime.js
CHANGED
|
@@ -38,7 +38,7 @@ export const OWNER_TYPE = '@owner';
|
|
|
38
38
|
export const isTypeName = (name) => /^[A-Z]/.test(name);
|
|
39
39
|
/**
|
|
40
40
|
* The collection an unbound type gets: `Message` → `messages`,
|
|
41
|
-
* `
|
|
41
|
+
* `AvailabilityZone` → `availability_zones`. Only ever a first guess —
|
|
42
42
|
* once bound, the binding is the answer.
|
|
43
43
|
*/
|
|
44
44
|
export function collectionFor(type) {
|
package/dist/synth.js
CHANGED
|
@@ -474,7 +474,7 @@ export class World {
|
|
|
474
474
|
}
|
|
475
475
|
/**
|
|
476
476
|
* Where records of another type go, placing the type if nobody has: the
|
|
477
|
-
* world agent can be first to need a
|
|
477
|
+
* world agent can be first to need a label, before any handler has
|
|
478
478
|
* served one.
|
|
479
479
|
*/
|
|
480
480
|
#placeOf(type) {
|
|
@@ -503,7 +503,7 @@ export class World {
|
|
|
503
503
|
/**
|
|
504
504
|
* References in the records just made that point at nothing. Judged loosely:
|
|
505
505
|
* a value counts as found if any collection holds a record under it, or
|
|
506
|
-
* under its last path segment — `/
|
|
506
|
+
* under its last path segment — `/v1/gateways/gw-app` names `gw-app`.
|
|
507
507
|
* Reported, never repaired: a guess at the missing entity would be worse.
|
|
508
508
|
*/
|
|
509
509
|
#dangling(store, req, made) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenera/gym",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "Simulated API environments for agent training and evaluation, powered by OpenAPI and model-written generators.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openapi",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@apidevtools/swagger-parser": "^12.0.0",
|
|
49
|
-
"@zenera/cli": "^1.2.
|
|
50
|
-
"@zenera/neo": "^1.2.
|
|
51
|
-
"@zenera/rag": "^1.2.
|
|
49
|
+
"@zenera/cli": "^1.2.8",
|
|
50
|
+
"@zenera/neo": "^1.2.8",
|
|
51
|
+
"@zenera/rag": "^1.2.8",
|
|
52
52
|
"ajv": "^8.17.1",
|
|
53
53
|
"ajv-formats": "^3.0.1",
|
|
54
54
|
"randexp": "^0.5.3"
|