@nylorun/core 0.39.0-beta → 0.40.0-beta

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
@@ -1,5 +1,16 @@
1
1
  # @nylorun/core
2
2
 
3
+ ## 0.40.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - b6a7c1d: An agent sees the images and PDFs it makes in its sandbox (ADR-139). `read` of a file the turn's model reads as media, known by its extension (an image, a PDF, an Office document, audio or video), comes back as the file itself, shown to the model in the turn's files, instead of numbered lines of decoded bytes. Our engine runs it in the harness: it reads the bytes, checks they start as the type says, and stores them as an artifact for the model only. A model that can't read the kind is told so before anything is read or stored (`sandbox.unreadable`), and a file that isn't what its name says fails `sandbox.binary_file`.
8
+
9
+ - **Model-only artifacts.** `artifact.write` `begin` takes `audience: "model"` (Harness API 5, schema revision 5, `harness-api/v5.5.json`; only our own engine sends it). Such an artifact is readable by id and carries `audience: "model"` in its view and its `artifact.created` event, but is never listed (`GET /v1/artifacts`, a session's artifacts, pages) and is no A2A task file. Runtime store migration 0046 (`artifacts.audience`, nullable) runs at start.
10
+ - **Binary files.** The sandbox's `read` of any other binary file fails `sandbox.binary_file`, in words, instead of answering decoded bytes as text.
11
+ - **A cap per call.** A model call carries at most the 6 newest files from tool results as media; older ones in the same turn go as a note naming them, which `read_artifact` brings back. A person's own files are never capped.
12
+ - `read`'s description says what it now does, so the prompt prefix of every agent with a sandbox changes once: its first call after the upgrade misses the prompt cache.
13
+
3
14
  ## 0.39.0-beta
4
15
 
5
16
  ### Minor Changes
@@ -12,7 +12,7 @@ export type { WorkflowManifest } from "./types/workflow.js";
12
12
  export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
13
13
  export { SKILL_TOTAL_BYTES_DEFAULT, definitionFilesOf, isDefinitionFileHash, skillsOf, } from "./utils/definition-files.js";
14
14
  export { HARNESS_LIMIT_DEFAULTS, HarnessLimitsSchema, JS_STRING_MAX_LENGTH, RECORD_ENVELOPE_RESERVE_BYTES, RUNTIME_LIMIT_CEILINGS, RUNTIME_LIMIT_DEFAULTS, RuntimeLimitsSchema, S2_RECORD_MAX_BYTES, TIMER_MAX_MS, harnessLimitsOf, inlineBodyBytes, limitExceededMessage, runtimeLimitIssues, runtimeLimitsOf, type HarnessLimit, type HarnessLimits, type RuntimeLimit, type RuntimeLimits, } from "./utils/runtime-limits.js";
15
- export { DEFAULT_CONTENT_TYPE, MODEL_IMAGE_TYPES, contentTypeFor, essence, extensionFor, inputLabel, isModelImage, isOffice, isText, modelInputOf, normalizeContentType, } from "./utils/media-types.js";
15
+ export { DEFAULT_CONTENT_TYPE, MODEL_IMAGE_TYPES, contentTypeFor, essence, extensionFor, inputLabel, isModelImage, isOffice, isText, matchesSignature, modelInputOf, normalizeContentType, } from "./utils/media-types.js";
16
16
  export type { ErrorCode } from "./compatibility.js";
17
17
  export declare const RequestIdSchema: z.ZodString;
18
18
  /** At most 256 characters: an identifier's grammar is the protocol's (it crosses the Runtime API, the Harness API and tokens, and means the same in every installation), so its length is a constant of protocol 15, not a setting. */
@@ -5505,6 +5505,14 @@ export declare const ArtifactSourceSchema: z.ZodEnum<{
5505
5505
  upload: "upload";
5506
5506
  }>;
5507
5507
  export type ArtifactSource = z.infer<typeof ArtifactSourceSchema>;
5508
+ /**
5509
+ * Who an artifact is for (ADR-139): `model` for a file our engine stored only so its model could
5510
+ * see it (a sandbox image or PDF it read). Such an artifact stays in the session, readable by id,
5511
+ * but is no output: no A2A task file, no AG-UI history entry, not in a session's artifact list.
5512
+ * Absent for everything else.
5513
+ */
5514
+ export declare const ArtifactAudienceSchema: z.ZodLiteral<"model">;
5515
+ export type ArtifactAudience = z.infer<typeof ArtifactAudienceSchema>;
5508
5516
  /**
5509
5517
  * What an artifact holds: one file, or a folder, whose versions are manifests of paths to
5510
5518
  * content-addressed files.
@@ -5536,6 +5544,7 @@ export declare const ArtifactVersionPayloadSchema: z.ZodObject<{
5536
5544
  snapshot: "snapshot";
5537
5545
  upload: "upload";
5538
5546
  }>;
5547
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
5539
5548
  callId: z.ZodOptional<z.ZodString>;
5540
5549
  fileCount: z.ZodOptional<z.ZodNumber>;
5541
5550
  claimed: z.ZodOptional<z.ZodBoolean>;
@@ -6398,6 +6407,7 @@ export declare const EVENT_CATALOG: {
6398
6407
  snapshot: "snapshot";
6399
6408
  upload: "upload";
6400
6409
  }>;
6410
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
6401
6411
  callId: z.ZodOptional<z.ZodString>;
6402
6412
  fileCount: z.ZodOptional<z.ZodNumber>;
6403
6413
  claimed: z.ZodOptional<z.ZodBoolean>;
@@ -6423,6 +6433,7 @@ export declare const EVENT_CATALOG: {
6423
6433
  snapshot: "snapshot";
6424
6434
  upload: "upload";
6425
6435
  }>;
6436
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
6426
6437
  callId: z.ZodOptional<z.ZodString>;
6427
6438
  fileCount: z.ZodOptional<z.ZodNumber>;
6428
6439
  claimed: z.ZodOptional<z.ZodBoolean>;
@@ -8184,6 +8195,7 @@ export declare const ArtifactViewSchema: z.ZodObject<{
8184
8195
  agentId: z.ZodOptional<z.ZodString>;
8185
8196
  latestVersion: z.ZodNumber;
8186
8197
  labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8198
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
8187
8199
  createdAt: z.ZodString;
8188
8200
  updatedAt: z.ZodString;
8189
8201
  versions: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -8214,6 +8226,7 @@ export declare const ListArtifactsResponseSchema: z.ZodObject<{
8214
8226
  agentId: z.ZodOptional<z.ZodString>;
8215
8227
  latestVersion: z.ZodNumber;
8216
8228
  labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8229
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
8217
8230
  createdAt: z.ZodString;
8218
8231
  updatedAt: z.ZodString;
8219
8232
  versions: z.ZodOptional<z.ZodArray<z.ZodObject<{
@@ -8245,6 +8258,7 @@ export declare const ArtifactListItemSchema: z.ZodObject<{
8245
8258
  agentId: z.ZodOptional<z.ZodString>;
8246
8259
  latestVersion: z.ZodNumber;
8247
8260
  labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8261
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
8248
8262
  createdAt: z.ZodString;
8249
8263
  updatedAt: z.ZodString;
8250
8264
  }, z.core.$strict>;
@@ -8262,6 +8276,7 @@ export declare const ArtifactPageSchema: z.ZodObject<{
8262
8276
  agentId: z.ZodOptional<z.ZodString>;
8263
8277
  latestVersion: z.ZodNumber;
8264
8278
  labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8279
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
8265
8280
  createdAt: z.ZodString;
8266
8281
  updatedAt: z.ZodString;
8267
8282
  }, z.core.$strict>>;
@@ -8282,6 +8297,7 @@ export declare const UploadArtifactResponseSchema: z.ZodObject<{
8282
8297
  agentId: z.ZodOptional<z.ZodString>;
8283
8298
  latestVersion: z.ZodNumber;
8284
8299
  labels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8300
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
8285
8301
  createdAt: z.ZodString;
8286
8302
  updatedAt: z.ZodString;
8287
8303
  versions: z.ZodOptional<z.ZodArray<z.ZodObject<{
package/dist/contracts.js CHANGED
@@ -18,7 +18,7 @@ export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
18
18
  export { SKILL_TOTAL_BYTES_DEFAULT, definitionFilesOf, isDefinitionFileHash, skillsOf, } from "./utils/definition-files.js";
19
19
  export { HARNESS_LIMIT_DEFAULTS, HarnessLimitsSchema, JS_STRING_MAX_LENGTH, RECORD_ENVELOPE_RESERVE_BYTES, RUNTIME_LIMIT_CEILINGS, RUNTIME_LIMIT_DEFAULTS, RuntimeLimitsSchema, S2_RECORD_MAX_BYTES, TIMER_MAX_MS, harnessLimitsOf, inlineBodyBytes, limitExceededMessage, runtimeLimitIssues, runtimeLimitsOf, } from "./utils/runtime-limits.js";
20
20
  import { RuntimeLimitsSchema, TIMER_MAX_MS } from "./utils/runtime-limits.js";
21
- export { DEFAULT_CONTENT_TYPE, MODEL_IMAGE_TYPES, contentTypeFor, essence, extensionFor, inputLabel, isModelImage, isOffice, isText, modelInputOf, normalizeContentType, } from "./utils/media-types.js";
21
+ export { DEFAULT_CONTENT_TYPE, MODEL_IMAGE_TYPES, contentTypeFor, essence, extensionFor, inputLabel, isModelImage, isOffice, isText, matchesSignature, modelInputOf, normalizeContentType, } from "./utils/media-types.js";
22
22
  import { ERROR_CODES, isArtifactId } from "./compatibility.js";
23
23
  export const RequestIdSchema = z.string().min(1);
24
24
  /** At most 256 characters: an identifier's grammar is the protocol's (it crosses the Runtime API, the Harness API and tokens, and means the same in every installation), so its length is a constant of protocol 15, not a setting. */
@@ -3641,6 +3641,13 @@ export const TranscriptUpdatedPayloadSchema = z
3641
3641
  * before protocol 15 name (`export`).
3642
3642
  */
3643
3643
  export const ArtifactSourceSchema = z.enum(["upload", "engine", "export", "snapshot"]);
3644
+ /**
3645
+ * Who an artifact is for (ADR-139): `model` for a file our engine stored only so its model could
3646
+ * see it (a sandbox image or PDF it read). Such an artifact stays in the session, readable by id,
3647
+ * but is no output: no A2A task file, no AG-UI history entry, not in a session's artifact list.
3648
+ * Absent for everything else.
3649
+ */
3650
+ export const ArtifactAudienceSchema = z.literal("model");
3644
3651
  /**
3645
3652
  * What an artifact holds: one file, or a folder, whose versions are manifests of paths to
3646
3653
  * content-addressed files.
@@ -3661,6 +3668,8 @@ export const ArtifactVersionPayloadSchema = z
3661
3668
  size: z.number().int().nonnegative(),
3662
3669
  sha256: z.string(),
3663
3670
  source: ArtifactSourceSchema,
3671
+ /** `model`: stored only for the model to see (ADR-139); absent for an output. */
3672
+ audience: ArtifactAudienceSchema.optional(),
3664
3673
  /** The tool call that saved it (`save_artifact`), when our engine did. */
3665
3674
  callId: z.string().optional(),
3666
3675
  /** A folder's number of files. */
@@ -5021,6 +5030,11 @@ export const ArtifactViewSchema = z
5021
5030
  agentId: z.string().optional(),
5022
5031
  latestVersion: z.number().int().positive(),
5023
5032
  labels: z.record(z.string(), z.string()).optional(),
5033
+ /**
5034
+ * `model`: our engine stored it only so its model could see it (ADR-139). Readable by id;
5035
+ * never in a list of artifacts. Absent for every other artifact.
5036
+ */
5037
+ audience: ArtifactAudienceSchema.optional(),
5024
5038
  createdAt: z.string(),
5025
5039
  updatedAt: z.string(),
5026
5040
  /** Every version, oldest first (`GET /v1/artifacts/{id}` only). */
@@ -67,8 +67,10 @@ export function sandboxTools(limits, workspace, names = SANDBOX_TOOL_NAMES) {
67
67
  },
68
68
  {
69
69
  name: "read",
70
- description: `Read a text file from the sandbox. ${relative} Returns numbered lines. ` +
71
- "Use offset and limit to page through large files.",
70
+ description: `Read a file from the sandbox. ${relative} A text file returns numbered lines: use offset ` +
71
+ "and limit to page through a large one. An image, a PDF or another file your model reads, " +
72
+ "known by its extension, comes back as the file itself, shown to you and not to the user. " +
73
+ "Other binary files can't be read.",
72
74
  inputSchema: object({
73
75
  path: pathField,
74
76
  offset: {
@@ -44,6 +44,8 @@ export interface ArtifactWriteOptions {
44
44
  readonly effectId?: string;
45
45
  /** The body's size when known: core refuses one past its limits before a byte is sent. */
46
46
  readonly size?: number;
47
+ /** `model`: a new artifact stored only for the model to see, never an output (ADR-139). */
48
+ readonly audience?: "model";
47
49
  /** The most bytes one chunk carries: the run's `turn.start.limits.chunkBytes`. */
48
50
  readonly chunkBytes: number;
49
51
  readonly signal?: AbortSignal;
@@ -69,6 +69,7 @@ function beginOf(options) {
69
69
  ...(options.contentType === undefined ? {} : { contentType: options.contentType }),
70
70
  ...(options.effectId === undefined ? {} : { effectId: options.effectId }),
71
71
  ...(options.size === undefined ? {} : { size: options.size }),
72
+ ...(options.audience === undefined ? {} : { audience: options.audience }),
72
73
  };
73
74
  }
74
75
  function opened(channel, options, begun) {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "$id": "https://docs.nylorun.com/schemas/harness-api/v5.4.json",
3
+ "$id": "https://docs.nylorun.com/schemas/harness-api/v5.5.json",
4
4
  "title": "Nylorun Harness API 5",
5
5
  "$defs": {
6
6
  "ArtifactMeta": {
@@ -4774,6 +4774,10 @@
4774
4774
  },
4775
4775
  "base64": {
4776
4776
  "type": "string"
4777
+ },
4778
+ "audience": {
4779
+ "type": "string",
4780
+ "const": "model"
4777
4781
  }
4778
4782
  },
4779
4783
  "required": [
@@ -57,9 +57,10 @@ export function harnessApiSchemas() {
57
57
  * pinned). Revision 3: `turn.start.agent.triggers` and the `runtime` operation `triggers` (D83),
58
58
  * which a v5 harness that offers no `triggers` tool never sees. Revision 4: the effect kind `inputs`
59
59
  (D85): the messages steered into the running turn, which core answers at once and a v5 harness
60
- that never asks for it never sees.
60
+ that never asks for it never sees. Revision 5: `artifact.write` `begin` may carry
61
+ `audience: "model"` (ADR-139), which core accepts and only our own engine sends.
61
62
  */
62
- const SCHEMA_REVISION = 4;
63
+ const SCHEMA_REVISION = 5;
63
64
  /** The JSON Schema document of the Harness API (draft 2020-12). */
64
65
  export function harnessApiJsonSchema() {
65
66
  const $defs = {};
@@ -1075,6 +1075,7 @@ export declare const harnessRequests: {
1075
1075
  size: z.ZodOptional<z.ZodNumber>;
1076
1076
  effectId: z.ZodOptional<z.ZodString>;
1077
1077
  base64: z.ZodOptional<z.ZodString>;
1078
+ audience: z.ZodOptional<z.ZodLiteral<"model">>;
1078
1079
  }, z.core.$strict>, z.ZodObject<{
1079
1080
  runId: z.ZodString;
1080
1081
  op: z.ZodLiteral<"begin">;
@@ -7,7 +7,7 @@
7
7
  import { z } from "zod";
8
8
  import { ABORT_REASONS, HARNESS_API_VERSION, HARNESS_CLAIMS, HARNESS_ERROR_CODES, } from "./messages.js";
9
9
  import { HarnessApiError } from "./errors.js";
10
- import { ARTIFACT_NAME_MAX, ENVIRONMENT_KINDS, EffectOutcomeSchema, ModelInputSchema } from "../contracts.js";
10
+ import { ARTIFACT_NAME_MAX, ArtifactAudienceSchema, ENVIRONMENT_KINDS, EffectOutcomeSchema, ModelInputSchema, } from "../contracts.js";
11
11
  import { HarnessLimitsSchema, RUNTIME_LIMIT_CEILINGS } from "../utils/runtime-limits.js";
12
12
  import { SANDBOX_TOOL_NAMES } from "../utils/sandbox.js";
13
13
  import { McpFactsSchema, McpSnapshotSchema } from "./mcp.js";
@@ -641,6 +641,11 @@ export const harnessRequests = {
641
641
  size: z.number().int().nonnegative().optional(),
642
642
  effectId: id.optional(),
643
643
  base64: z.string().optional(),
644
+ /**
645
+ * `model` (ADR-139, revision 5): a file stored only for the model to see, never an
646
+ * output. Only our own engine sends it; core accepts it within v5.
647
+ */
648
+ audience: ArtifactAudienceSchema.optional(),
644
649
  })
645
650
  .strict(),
646
651
  runId
@@ -24,6 +24,12 @@ export declare function isText(contentType: string): boolean;
24
24
  export declare function extensionFor(contentType: string): string | undefined;
25
25
  /** Word, Excel and PowerPoint documents, old and Open XML. */
26
26
  export declare function isOffice(contentType: string): boolean;
27
+ /**
28
+ * Whether `bytes` start as a file of `contentType` does: true or false for a type with a known
29
+ * signature (PNG, JPEG, GIF, WebP, PDF, Office), undefined for one without. A sandbox file is typed
30
+ * by its extension; this keeps a `.png` that isn't a PNG from reaching a model as an image.
31
+ */
32
+ export declare function matchesSignature(contentType: string, bytes: Uint8Array): boolean | undefined;
27
33
  /** The model input a file of `contentType` is, or undefined for a type no model reads. */
28
34
  export declare function modelInputOf(contentType: string): ModelInput | undefined;
29
35
  /** An input, in a sentence: "PDFs", "Office documents"; "files of this type" for none. */
@@ -97,6 +97,34 @@ export function isOffice(contentType) {
97
97
  type === "application/vnd.ms-powerpoint" ||
98
98
  type.startsWith("application/vnd.openxmlformats-officedocument."));
99
99
  }
100
+ const ascii = (text) => [...text].map((char) => char.charCodeAt(0));
101
+ /** The first bytes a file of each type starts with, where the type has one. */
102
+ const SIGNATURES = {
103
+ "image/png": [[0x89, ...ascii("PNG\r\n"), 0x1a, 0x0a]],
104
+ "image/jpeg": [[0xff, 0xd8, 0xff]],
105
+ "image/gif": [ascii("GIF87a"), ascii("GIF89a")],
106
+ // RIFF, four bytes of size, then WEBP.
107
+ "image/webp": [[...ascii("RIFF"), undefined, undefined, undefined, undefined, ...ascii("WEBP")]],
108
+ "application/pdf": [ascii("%PDF-")],
109
+ // Old Office files are OLE compound documents; Open XML ones are zip archives.
110
+ "application/msword": [[0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]],
111
+ "application/vnd.ms-excel": [[0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]],
112
+ "application/vnd.ms-powerpoint": [[0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1]],
113
+ };
114
+ const ZIP = [0x50, 0x4b, 0x03, 0x04];
115
+ /**
116
+ * Whether `bytes` start as a file of `contentType` does: true or false for a type with a known
117
+ * signature (PNG, JPEG, GIF, WebP, PDF, Office), undefined for one without. A sandbox file is typed
118
+ * by its extension; this keeps a `.png` that isn't a PNG from reaching a model as an image.
119
+ */
120
+ export function matchesSignature(contentType, bytes) {
121
+ const type = essence(contentType);
122
+ const signatures = SIGNATURES[type] ?? (type.startsWith("application/vnd.openxmlformats-officedocument.") ? [ZIP] : undefined);
123
+ if (signatures === undefined)
124
+ return undefined;
125
+ return signatures.some((signature) => bytes.byteLength >= signature.length &&
126
+ signature.every((byte, index) => byte === undefined || bytes[index] === byte));
127
+ }
100
128
  /** The model input a file of `contentType` is, or undefined for a type no model reads. */
101
129
  export function modelInputOf(contentType) {
102
130
  const type = essence(contentType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/core",
3
- "version": "0.39.0-beta",
3
+ "version": "0.40.0-beta",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Shared agent definitions and wire contracts",