@agentshouse/mdruntime-adapter 0.1.0-c341663d60099 → 0.1.0-c343dc02413f9

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/dist/upload.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { sha256 } from '@agentshouse/mdruntime/digest';
2
+ import { answeredFailure, doorRefusal } from './refusal.js';
2
3
  import { houseDoorRoute } from './transport.js';
4
+ import { unusable } from './uncertain.js';
3
5
  const FINISHING_ROUNDS = 24;
4
6
  function record(value) {
5
7
  return value !== null && typeof value === 'object' ? value : {};
@@ -63,3 +65,42 @@ export async function finishedUpload(transport, first, blob) {
63
65
  }
64
66
  return { unfinished: 200 };
65
67
  }
68
+ function unstagedRefusal(answer) {
69
+ const refusal = doorRefusal(answer.body);
70
+ return refusal?.code === 'files_unstaged' ? refusal : null;
71
+ }
72
+ async function staged(transport, named, file) {
73
+ const upload = houseUpload(named);
74
+ if (upload === null)
75
+ return unusable();
76
+ const blob = file(record(named).sha256);
77
+ if (blob === null)
78
+ return unusable();
79
+ const sent = await finishedUpload(transport, upload, await blob);
80
+ if ('unfinished' in sent)
81
+ return answeredFailure(sent.unfinished, null);
82
+ if (sent.status !== 200)
83
+ return answeredFailure(sent.status, sent.body);
84
+ return record(sent.body).staged === true ? null : unusable();
85
+ }
86
+ export async function stagedBatch(transport, body, file) {
87
+ let answer = await transport.door(houseDoorRoute('update'), body);
88
+ const finished = new Set();
89
+ for (let unstaged = unstagedRefusal(answer); unstaged !== null; unstaged = unstagedRefusal(answer)) {
90
+ const named = unstaged.fields.upload;
91
+ if (!Array.isArray(named))
92
+ return unusable();
93
+ const fresh = named.filter((upload) => !finished.has(record(upload).id));
94
+ if (fresh.length === 0)
95
+ return answeredFailure(answer.status, answer.body);
96
+ for (const upload of fresh) {
97
+ const staging = await staged(transport, upload, file);
98
+ if (staging !== null)
99
+ return staging;
100
+ }
101
+ for (const upload of fresh)
102
+ finished.add(record(upload).id);
103
+ answer = await transport.door(houseDoorRoute('update'), body);
104
+ }
105
+ return answer;
106
+ }
package/dist/write.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
- import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
2
+ import { answered, answering, attachmentOf, headChange, revised } from './read.js';
3
3
  import { sha256Hex, textBytes } from './digest.js';
4
4
  import { nativePath, roomLocalPath } from './map.js';
5
5
  import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
@@ -182,7 +182,7 @@ function* material(value, handle, within = () => true) {
182
182
  return null;
183
183
  if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
184
184
  return null;
185
- const binary = binaryFileOf(file);
185
+ const binary = attachmentOf(file);
186
186
  if (binary === null)
187
187
  return null;
188
188
  const head = headChange(file);
@@ -225,14 +225,14 @@ function* acceptedOf(at, contents) {
225
225
  if (entry.content !== null)
226
226
  answer.documents.set(entry.path, entry.content);
227
227
  if (entry.binary !== undefined)
228
- answer.binaryFiles.set(entry.path, entry.binary);
228
+ answer.attachments.set(entry.path, entry.binary);
229
229
  revised(answer, entry.path, entry.revision);
230
230
  if (entry.head !== undefined)
231
231
  answer.changes.set(entry.path, entry.head);
232
232
  }
233
- const unbinaried = answer.binaryFiles.size === 0;
234
- const { binaryFiles, facts: _facts, ...room } = yield* answered(answer);
235
- return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
233
+ const unbinaried = answer.attachments.size === 0;
234
+ const { attachments, facts: _facts, ...room } = yield* answered(answer);
235
+ return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { attachments }) };
236
236
  }
237
237
  function* movedOutcome(held, move) {
238
238
  const authorities = Array.isArray(held.authorities) ? held.authorities : [];
@@ -391,14 +391,14 @@ export function historyOutcome(status, body, locator, request) {
391
391
  typeof entry.created_at !== 'string') {
392
392
  return unusable();
393
393
  }
394
- const binaryFile = binaryFileOf(entry);
395
- if (binaryFile === null)
394
+ const attachment = attachmentOf(entry);
395
+ if (attachment === null)
396
396
  return unusable();
397
397
  revisions.push({
398
398
  revision: entry.revision,
399
399
  author,
400
400
  time: entry.created_at,
401
- ...(binaryFile === undefined ? {} : { binaryFile }),
401
+ ...(attachment === undefined ? {} : { attachment }),
402
402
  });
403
403
  }
404
404
  const next = held.next_before;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-c341663d60099",
3
+ "version": "0.1.0-c343dc02413f9",
4
4
  "description": "Agents House Adapter for the MD Runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,8 +24,8 @@
24
24
  "LICENSE"
25
25
  ],
26
26
  "dependencies": {
27
- "@agentshouse/mdmodel": "0.1.0-cb39915954ec5",
28
- "@agentshouse/mdruntime": "0.1.0-c61e6fe81fd4d"
27
+ "@agentshouse/mdmodel": "0.1.0-ced713d53efb3",
28
+ "@agentshouse/mdruntime": "0.1.0-c811286aa170b"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
@@ -1,7 +0,0 @@
1
- export declare const OUTPUT_LINES = 20;
2
- export declare const OUTPUT_CHARACTERS = 4000;
3
- export declare const DIFF_CHARACTERS = 10000;
4
- export declare const FIRST_PART_CHARACTERS = 2000;
5
- export declare function lastLines(output: string): string;
6
- export declare function firstPart(result: string): string;
7
- export declare function keptDiff(diff: string): string | null;