@agentshouse/mdruntime 0.1.0-alpha.22 → 0.1.0-alpha.23

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/index.d.ts CHANGED
@@ -2,7 +2,6 @@ export type { AcceptedMessage, ActionDeclaration, ActionRequest, ActionResult, A
2
2
  export type { Change, ChangeBatch, Precondition, WrittenBy } from './change.js';
3
3
  export type { ChatDraft, ChatDraftSurface, ConversationEntry, ConversationOptions, ConversationSurface, ConversationView, GrowingText, } from './conversation.js';
4
4
  export type { ChatDraftFile, FileDeclaration } from './file.js';
5
- export type { MdType } from './collection.js';
6
5
  export type { AppRoom, AppSlot, AppSlotEntry, AppTypedSelection, ConnectionRefusal, ConnectionRefusalReason, DraftEntry, DraftSurface, HistoryQuery, MdRuntime, MdRuntimeOptions, PresentationSurface, QueueSurface, RoomTypes, SaveResult, } from './connection.js';
7
6
  export type { AcceptedOutcome, AffectedState, CallResult, QueueEntry, QueueOutcome, SubmissionOutcome, } from './outcome.js';
8
7
  export type { SaveRefusal } from './save.js';
@@ -11,7 +10,7 @@ export { createMdRuntime } from './connection.js';
11
10
  export type { RuntimeShell } from './durability.js';
12
11
  export type { AttentionEntry, SyncStatus } from './status.js';
13
12
  export type { Backlink, QueryDocument, QueryGroup, QueryOptions, QueryResult, Selector, } from '@agentshouse/query';
14
- export type { AttachedModelBinding, ModelIdentity, ModelSnapshot, ModelState, ModelResult, ModelValidation, TypesResult, ValidationReceipt, } from './model.js';
13
+ export type { MdType, ModelIdentity, ModelSnapshot, ModelState, ModelResult, TypesResult, ValidationReceipt, } from './model.js';
15
14
  export type { OperationScopes, ReplicaAdmission, ScopedRefusal } from './adapter.js';
16
15
  export type { QueryBinding, QueryInput } from './query.js';
17
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf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AM,WAAW,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EACV,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,WAAW,EACX,QAAQ,GACT,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,UAAU,EACV,WAAW,EACX,eAAe,EACf,WAAW,EACX,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACrF,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,SAAS,EACT,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,YAAY,EACZ,eAAe,EACf,cAAc,EACd,SAAS,EACT,aAAa,EACb,eAAe,EACf,WAAW,EACX,cAAc,EACd,aAAa,EACb,SAAS,EACT,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,oBAAoB,EACpB,cAAc,GACf,MAAM,cAAc,C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/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/index.ts"],"sourcesContent":["export type {\n AcceptedMessage,\n ActionDeclaration,\n ActionRequest,\n ActionResult,\n Adapter,\n AdapterFailure,\n Authorization,\n BootstrapPage,\n BootstrapRequest,\n BootstrapResult,\n Capability,\n ContractUnavailable,\n ConversationAction,\n ConversationCards,\n ConversationEvent,\n ConversationHistoryPage,\n ConversationHistoryRequest,\n ConversationMessage,\n ConversationStream,\n DiscoverResult,\n DiscoveredRoom,\n Discovery,\n HistoryRequest,\n HistoryResult,\n HistoryRetention,\n HistoryRevision,\n MdModelIdentity,\n ModelRequest,\n MutationRequest,\n MutationResult,\n PageToken,\n ProviderLimit,\n ProviderRefusal,\n RefreshPage,\n RefreshRequest,\n RefreshResult,\n Retention,\n RetryableRefusal,\n RevokedAuthorization,\n RoomNotReadable,\n RoomVersionNotification,\n SelectedRooms,\n TransportUncertainty,\n TypedSelection,\n} from './adapter.js';\nexport type { Change, ChangeBatch, Precondition, WrittenBy } from './change.js';\nexport type {\n ChatDraft,\n ChatDraftSurface,\n ConversationEntry,\n ConversationOptions,\n ConversationSurface,\n ConversationView,\n GrowingText,\n} from './conversation.js';\nexport type { ChatDraftFile, FileDeclaration } from './file.js';\nexport type { MdType } from './collection.js';\nexport type {\n AppRoom,\n AppSlot,\n AppSlotEntry,\n AppTypedSelection,\n ConnectionRefusal,\n ConnectionRefusalReason,\n DraftEntry,\n DraftSurface,\n HistoryQuery,\n MdRuntime,\n MdRuntimeOptions,\n PresentationSurface,\n QueueSurface,\n RoomTypes,\n SaveResult,\n} from './connection.js';\nexport type {\n AcceptedOutcome,\n AffectedState,\n CallResult,\n QueueEntry,\n QueueOutcome,\n SubmissionOutcome,\n} from './outcome.js';\nexport type { SaveRefusal } from './save.js';\nexport { changeBatchIdentity } from './identity.js';\nexport { createMdRuntime } from './connection.js';\nexport type { RuntimeShell } from './durability.js';\nexport type { AttentionEntry, SyncStatus } from './status.js';\nexport type {\n Backlink,\n QueryDocument,\n QueryGroup,\n QueryOptions,\n QueryResult,\n Selector,\n} from '@agentshouse/query';\n\nexport type {\n AttachedModelBinding,\n ModelIdentity,\n ModelSnapshot,\n ModelState,\n ModelResult,\n ModelValidation,\n TypesResult,\n ValidationReceipt,\n} from './model.js';\nexport type { OperationScopes, ReplicaAdmission, ScopedRefusal } from './adapter.js';\nexport type { QueryBinding, QueryInput } from './query.js';\n"],"names":["changeBatchIdentity","createMdRuntime"],"mappings":"AAoFA,SAASA,mBAAmB,QAAQ,gBAAgB;AACpD,SAASC,eAAe,QAAQ,kBAAkB"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/index.ts"],"sourcesContent":["export type {\n AcceptedMessage,\n ActionDeclaration,\n ActionRequest,\n ActionResult,\n Adapter,\n AdapterFailure,\n Authorization,\n BootstrapPage,\n BootstrapRequest,\n BootstrapResult,\n Capability,\n ContractUnavailable,\n ConversationAction,\n ConversationCards,\n ConversationEvent,\n ConversationHistoryPage,\n ConversationHistoryRequest,\n ConversationMessage,\n ConversationStream,\n DiscoverResult,\n DiscoveredRoom,\n Discovery,\n HistoryRequest,\n HistoryResult,\n HistoryRetention,\n HistoryRevision,\n MdModelIdentity,\n ModelRequest,\n MutationRequest,\n MutationResult,\n PageToken,\n ProviderLimit,\n ProviderRefusal,\n RefreshPage,\n RefreshRequest,\n RefreshResult,\n Retention,\n RetryableRefusal,\n RevokedAuthorization,\n RoomNotReadable,\n RoomVersionNotification,\n SelectedRooms,\n TransportUncertainty,\n TypedSelection,\n} from './adapter.js';\nexport type { Change, ChangeBatch, Precondition, WrittenBy } from './change.js';\nexport type {\n ChatDraft,\n ChatDraftSurface,\n ConversationEntry,\n ConversationOptions,\n ConversationSurface,\n ConversationView,\n GrowingText,\n} from './conversation.js';\nexport type { ChatDraftFile, FileDeclaration } from './file.js';\nexport type {\n AppRoom,\n AppSlot,\n AppSlotEntry,\n AppTypedSelection,\n ConnectionRefusal,\n ConnectionRefusalReason,\n DraftEntry,\n DraftSurface,\n HistoryQuery,\n MdRuntime,\n MdRuntimeOptions,\n PresentationSurface,\n QueueSurface,\n RoomTypes,\n SaveResult,\n} from './connection.js';\nexport type {\n AcceptedOutcome,\n AffectedState,\n CallResult,\n QueueEntry,\n QueueOutcome,\n SubmissionOutcome,\n} from './outcome.js';\nexport type { SaveRefusal } from './save.js';\nexport { changeBatchIdentity } from './identity.js';\nexport { createMdRuntime } from './connection.js';\nexport type { RuntimeShell } from './durability.js';\nexport type { AttentionEntry, SyncStatus } from './status.js';\nexport type {\n Backlink,\n QueryDocument,\n QueryGroup,\n QueryOptions,\n QueryResult,\n Selector,\n} from '@agentshouse/query';\n\nexport type {\n MdType,\n ModelIdentity,\n ModelSnapshot,\n ModelState,\n ModelResult,\n TypesResult,\n ValidationReceipt,\n} from './model.js';\nexport type { OperationScopes, ReplicaAdmission, ScopedRefusal } from './adapter.js';\nexport type { QueryBinding, QueryInput } from './query.js';\n"],"names":["changeBatchIdentity","createMdRuntime"],"mappings":"AAmFA,SAASA,mBAAmB,QAAQ,gBAAgB;AACpD,SAASC,eAAe,QAAQ,kBAAkB"}
package/dist/model.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import type { Validation } from '@agentshouse/mdmodel';
2
- import type { MdType } from './collection.js';
1
+ import type { Definition, FieldSpec, SectionSpec, VerifiedModel } from '@agentshouse/mdmodel';
3
2
  export type ModelIdentity = {
4
3
  identity: string;
5
4
  version: string;
@@ -7,7 +6,7 @@ export type ModelIdentity = {
7
6
  export type ModelSnapshot = ModelIdentity & {
8
7
  definitions: Readonly<Record<string, string>>;
9
8
  };
10
- export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | 'version-changed' | 'invalid' | 'binding-unavailable';
9
+ export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | 'version-changed' | 'invalid';
11
10
  export type ModelResult = {
12
11
  kind: 'model';
13
12
  snapshot: ModelSnapshot;
@@ -19,6 +18,12 @@ export type ModelResult = {
19
18
  } | {
20
19
  kind: 'revoked-authorization';
21
20
  };
21
+ export type MdType = {
22
+ name: string;
23
+ path: string;
24
+ fields: Readonly<Record<string, FieldSpec>>;
25
+ sections: Readonly<Record<string, SectionSpec>>;
26
+ };
22
27
  export type ModelState = {
23
28
  status: 'unavailable';
24
29
  reason: ModelUnavailableReason;
@@ -26,7 +31,7 @@ export type ModelState = {
26
31
  status: 'current' | 'cached';
27
32
  snapshot: ModelSnapshot;
28
33
  verifiedWith: ModelIdentity;
29
- types: readonly MdType[];
34
+ types: VerifiedModel['types'];
30
35
  };
31
36
  export type TypesResult = {
32
37
  status: 'unavailable';
@@ -38,32 +43,13 @@ export type TypesResult = {
38
43
  verifiedWith: ModelIdentity;
39
44
  types: readonly MdType[];
40
45
  };
41
- export type ModelValidation = {
42
- verdict: 'accept';
43
- } | (Extract<Validation, {
44
- verdict: 'refuse';
45
- }> & {
46
- source: 'content' | 'model';
47
- });
48
- export type AttachedModelBinding = {
49
- verify(snapshot: ModelSnapshot): {
50
- kind: 'verified';
51
- types: readonly MdType[];
52
- } | {
53
- kind: 'invalid';
54
- };
55
- validate(input: {
56
- model: ModelSnapshot;
57
- documents: Readonly<Record<string, string>>;
58
- binaryTargets: readonly string[];
59
- }): ModelValidation;
60
- };
61
46
  export type ValidationReceipt = {
62
47
  identity: string;
63
48
  version: string;
64
49
  source: 'current' | 'cached';
65
50
  };
66
51
  export declare const NO_MODEL: ModelState;
52
+ export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
67
53
  export declare function modelTypes(state: ModelState): TypesResult;
68
54
  export declare function cached(state: ModelState): ModelState;
69
55
  export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,E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,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B,CAAC;AACN,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAA;CAAE,CAAC;AACpG,eAAO,MAAM,QAAQ,EAAE,UAA8D,CAAC;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAGhG;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAqBzD;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAEpD;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAE5E"}
package/dist/model.js CHANGED
@@ -2,6 +2,10 @@ export const NO_MODEL = {
2
2
  status: 'unavailable',
3
3
  reason: 'not-acquired'
4
4
  };
5
+ export function definitionOf(state, type) {
6
+ if (state.status === 'unavailable' || type === undefined) return undefined;
7
+ return Object.hasOwn(state.types, type) ? state.types[type] : undefined;
8
+ }
5
9
  export function modelTypes(state) {
6
10
  return state.status === 'unavailable' ? {
7
11
  ...state
@@ -12,7 +16,12 @@ export function modelTypes(state) {
12
16
  verifiedWith: {
13
17
  ...state.verifiedWith
14
18
  },
15
- types: structuredClone(state.types)
19
+ types: structuredClone(Object.values(state.types).sort((left, right)=>left.address < right.address ? -1 : left.address > right.address ? 1 : 0).map(({ name, address, fields, sections })=>({
20
+ name,
21
+ path: address,
22
+ fields,
23
+ sections
24
+ })))
16
25
  };
17
26
  }
18
27
  export function cached(state) {
package/dist/model.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/model.ts"],"sourcesContent":["import type { Validation } from '@agentshouse/mdmodel';\nimport type { MdType } from './collection.js';\n\nexport type ModelIdentity = { identity: string; version: string };\nexport type ModelSnapshot = ModelIdentity & { definitions: Readonly<Record<string, string>> };\nexport type ModelUnavailableReason =\n | 'not-readable'\n | 'revoked'\n | 'not-acquired'\n | 'version-changed'\n | 'invalid'\n | 'binding-unavailable';\nexport type ModelResult =\n | { kind: 'model'; snapshot: ModelSnapshot }\n | { kind: 'model-unavailable'; reason: ModelUnavailableReason }\n | { kind: 'transport-uncertainty' }\n | { kind: 'revoked-authorization' };\nexport type ModelState =\n | { status: 'unavailable'; reason: ModelUnavailableReason }\n | {\n status: 'current' | 'cached';\n snapshot: ModelSnapshot;\n verifiedWith: ModelIdentity;\n types: readonly MdType[];\n };\nexport type TypesResult =\n | { status: 'unavailable'; reason: ModelUnavailableReason }\n | {\n status: 'current' | 'cached';\n identity: string;\n version: string;\n verifiedWith: ModelIdentity;\n types: readonly MdType[];\n };\nexport type ModelValidation =\n | { verdict: 'accept' }\n | (Extract<Validation, { verdict: 'refuse' }> & { source: 'content' | 'model' });\nexport type AttachedModelBinding = {\n verify(\n snapshot: ModelSnapshot,\n ): { kind: 'verified'; types: readonly MdType[] } | { kind: 'invalid' };\n validate(input: {\n model: ModelSnapshot;\n documents: Readonly<Record<string, string>>;\n binaryTargets: readonly string[];\n }): ModelValidation;\n};\nexport type ValidationReceipt = { identity: string; version: string; source: 'current' | 'cached' };\nexport const NO_MODEL: ModelState = { status: 'unavailable', reason: 'not-acquired' };\nexport function modelTypes(state: ModelState): TypesResult {\n return state.status === 'unavailable'\n ? { ...state }\n : {\n status: state.status,\n identity: state.snapshot.identity,\n version: state.snapshot.version,\n verifiedWith: { ...state.verifiedWith },\n types: structuredClone(state.types),\n };\n}\nexport function cached(state: ModelState): ModelState {\n return state.status === 'unavailable' ? state : { ...state, status: 'cached' };\n}\nexport function sameModel(left: ModelIdentity, right: ModelIdentity): boolean {\n return left.identity === right.identity && left.version === right.version;\n}\n"],"names":["NO_MODEL","status","reason","modelTypes","state","identity","snapshot","version","verifiedWith","types","structuredClone","cached","sameModel","left","right"],"mappings":"AAgDA,OAAO,MAAMA,WAAuB;IAAEC,QAAQ;IAAeC,QAAQ;AAAe,EAAE;AACtF,OAAO,SAASC,WAAWC,KAAiB;IAC1C,OAAOA,MAAMH,MAAM,KAAK,gBACpB;QAAE,GAAGG,KAAK;IAAC,IACX;QACEH,QAAQG,MAAMH,MAAM;QACpBI,UAAUD,MAAME,QAAQ,CAACD,QAAQ;QACjCE,SAASH,MAAME,QAAQ,CAACC,OAAO;QAC/BC,cAAc;YAAE,GAAGJ,MAAMI,YAAY;QAAC;QACtCC,OAAOC,gBAAgBN,MAAMK,KAAK;IACpC;AACN;AACA,OAAO,SAASE,OAAOP,KAAiB;IACtC,OAAOA,MAAMH,MAAM,KAAK,gBAAgBG,QAAQ;QAAE,GAAGA,KAAK;QAAEH,QAAQ;IAAS;AAC/E;AACA,OAAO,SAASW,UAAUC,IAAmB,EAAEC,KAAoB;IACjE,OAAOD,KAAKR,QAAQ,KAAKS,MAAMT,QAAQ,IAAIQ,KAAKN,OAAO,KAAKO,MAAMP,OAAO;AAC3E"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/model.ts"],"sourcesContent":["import type { Definition, FieldSpec, SectionSpec, VerifiedModel } from '@agentshouse/mdmodel';\n\nexport type ModelIdentity = { identity: string; version: string };\nexport type ModelSnapshot = ModelIdentity & { definitions: Readonly<Record<string, string>> };\nexport type ModelUnavailableReason =\n | 'not-readable'\n | 'revoked'\n | 'not-acquired'\n | 'version-changed'\n | 'invalid';\nexport type ModelResult =\n | { kind: 'model'; snapshot: ModelSnapshot }\n | { kind: 'model-unavailable'; reason: ModelUnavailableReason }\n | { kind: 'transport-uncertainty' }\n | { kind: 'revoked-authorization' };\nexport type MdType = {\n name: string;\n path: string;\n fields: Readonly<Record<string, FieldSpec>>;\n sections: Readonly<Record<string, SectionSpec>>;\n};\nexport type ModelState =\n | { status: 'unavailable'; reason: ModelUnavailableReason }\n | {\n status: 'current' | 'cached';\n snapshot: ModelSnapshot;\n verifiedWith: ModelIdentity;\n types: VerifiedModel['types'];\n };\nexport type TypesResult =\n | { status: 'unavailable'; reason: ModelUnavailableReason }\n | {\n status: 'current' | 'cached';\n identity: string;\n version: string;\n verifiedWith: ModelIdentity;\n types: readonly MdType[];\n };\nexport type ValidationReceipt = { identity: string; version: string; source: 'current' | 'cached' };\nexport const NO_MODEL: ModelState = { status: 'unavailable', reason: 'not-acquired' };\nexport function definitionOf(state: ModelState, type: string | undefined): Definition | undefined {\n if (state.status === 'unavailable' || type === undefined) return undefined;\n return Object.hasOwn(state.types, type) ? state.types[type] : undefined;\n}\nexport function modelTypes(state: ModelState): TypesResult {\n return state.status === 'unavailable'\n ? { ...state }\n : {\n status: state.status,\n identity: state.snapshot.identity,\n version: state.snapshot.version,\n verifiedWith: { ...state.verifiedWith },\n types: structuredClone(\n Object.values(state.types)\n .sort((left, right) =>\n left.address < right.address ? -1 : left.address > right.address ? 1 : 0,\n )\n .map(({ name, address, fields, sections }) => ({\n name,\n path: address,\n fields,\n sections,\n })),\n ),\n };\n}\nexport function cached(state: ModelState): ModelState {\n return state.status === 'unavailable' ? state : { ...state, status: 'cached' };\n}\nexport function sameModel(left: ModelIdentity, right: ModelIdentity): boolean {\n return left.identity === right.identity && left.version === right.version;\n}\n"],"names":["NO_MODEL","status","reason","definitionOf","state","type","undefined","Object","hasOwn","types","modelTypes","identity","snapshot","version","verifiedWith","structuredClone","values","sort","left","right","address","map","name","fields","sections","path","cached","sameModel"],"mappings":"AAuCA,OAAO,MAAMA,WAAuB;IAAEC,QAAQ;IAAeC,QAAQ;AAAe,EAAE;AACtF,OAAO,SAASC,aAAaC,KAAiB,EAAEC,IAAwB;IACtE,IAAID,MAAMH,MAAM,KAAK,iBAAiBI,SAASC,WAAW,OAAOA;IACjE,OAAOC,OAAOC,MAAM,CAACJ,MAAMK,KAAK,EAAEJ,QAAQD,MAAMK,KAAK,CAACJ,KAAK,GAAGC;AAChE;AACA,OAAO,SAASI,WAAWN,KAAiB;IAC1C,OAAOA,MAAMH,MAAM,KAAK,gBACpB;QAAE,GAAGG,KAAK;IAAC,IACX;QACEH,QAAQG,MAAMH,MAAM;QACpBU,UAAUP,MAAMQ,QAAQ,CAACD,QAAQ;QACjCE,SAAST,MAAMQ,QAAQ,CAACC,OAAO;QAC/BC,cAAc;YAAE,GAAGV,MAAMU,YAAY;QAAC;QACtCL,OAAOM,gBACLR,OAAOS,MAAM,CAACZ,MAAMK,KAAK,EACtBQ,IAAI,CAAC,CAACC,MAAMC,QACXD,KAAKE,OAAO,GAAGD,MAAMC,OAAO,GAAG,CAAC,IAAIF,KAAKE,OAAO,GAAGD,MAAMC,OAAO,GAAG,IAAI,GAExEC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEF,OAAO,EAAEG,MAAM,EAAEC,QAAQ,EAAE,GAAM,CAAA;gBAC7CF;gBACAG,MAAML;gBACNG;gBACAC;YACF,CAAA;IAEN;AACN;AACA,OAAO,SAASE,OAAOtB,KAAiB;IACtC,OAAOA,MAAMH,MAAM,KAAK,gBAAgBG,QAAQ;QAAE,GAAGA,KAAK;QAAEH,QAAQ;IAAS;AAC/E;AACA,OAAO,SAAS0B,UAAUT,IAAmB,EAAEC,KAAoB;IACjE,OAAOD,KAAKP,QAAQ,KAAKQ,MAAMR,QAAQ,IAAIO,KAAKL,OAAO,KAAKM,MAAMN,OAAO;AAC3E"}
package/dist/refresh.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { AttachedModelBinding } from './model.js';
2
1
  import type { Adapter, AdapterFailure, Authorization } from './adapter.js';
3
2
  import { type ConfirmedLayer } from './replica.js';
4
3
  import { type Unconfirmed } from './transfer.js';
@@ -10,5 +9,5 @@ export type RefreshOutcome = {
10
9
  } | {
11
10
  kind: 'beyond-horizon';
12
11
  } | Unconfirmed | AdapterFailure;
13
- export declare function refreshRoom(adapter: Adapter, authorization: Authorization, confirmed: ConfirmedLayer, binding: AttachedModelBinding | null): Promise<RefreshOutcome>;
12
+ export declare function refreshRoom(adapter: Adapter, authorization: Authorization, confirmed: ConfirmedLayer): Promise<RefreshOutcome>;
14
13
  //# sourceMappingURL=refresh.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;AACxF,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B,WAAW,GACX,cAAc,CAAC;AAEnB,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,oBAAoB,GAAG,IAAI,GACnC,OAAO,CAAC,cAAc,CAAC,CAuDzB"}
1
+ {"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;AACxF,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B,WAAW,GACX,cAAc,CAAC;AAEnB,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,cAAc,GACxB,OAAO,CAAC,cAAc,CAAC,CAsDzB"}
package/dist/refresh.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readStaged } from './replica.js';
2
2
  import { unconfirmed } from './transfer.js';
3
- export async function refreshRoom(adapter, authorization, confirmed, binding) {
3
+ export async function refreshRoom(adapter, authorization, confirmed) {
4
4
  const locator = confirmed.record.locator;
5
5
  const fromRoomVersion = confirmed.record.roomVersion;
6
6
  const first = await adapter.refresh(authorization, {
@@ -55,7 +55,7 @@ export async function refreshRoom(adapter, authorization, confirmed, binding) {
55
55
  ...binaryTargets
56
56
  ].sort(),
57
57
  revisions
58
- }, binding, confirmed);
58
+ }, confirmed);
59
59
  return advanced === null ? unconfirmed : {
60
60
  kind: 'advanced',
61
61
  confirmed: advanced
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/refresh.ts"],"sourcesContent":["import type { AttachedModelBinding } from './model.js';\nimport type { Adapter, AdapterFailure, Authorization, RefreshPage } from './adapter.js';\nimport { readStaged, type ConfirmedLayer } from './replica.js';\nimport { unconfirmed, type Unconfirmed } from './transfer.js';\n\nexport type RefreshOutcome =\n | { kind: 'still-current' }\n | { kind: 'advanced'; confirmed: ConfirmedLayer }\n | { kind: 'beyond-horizon' }\n | Unconfirmed\n | AdapterFailure;\n\nexport async function refreshRoom(\n adapter: Adapter,\n authorization: Authorization,\n confirmed: ConfirmedLayer,\n binding: AttachedModelBinding | null,\n): Promise<RefreshOutcome> {\n const locator = confirmed.record.locator;\n const fromRoomVersion = confirmed.record.roomVersion;\n const first = await adapter.refresh(authorization, {\n locator,\n selection: confirmed.record.replica.selection,\n fromRoomVersion,\n });\n if (first.kind !== 'net-advancement') return first;\n const roomVersion = first.roomVersion;\n const documents: Record<string, string> = { ...confirmed.record.documents };\n const revisions: Record<string, string> = { ...confirmed.record.revisions };\n const binaryTargets = new Set(confirmed.record.binaryTargets);\n const stage = (page: RefreshPage) => {\n Object.assign(documents, page.documents);\n Object.assign(revisions, page.revisions);\n for (const path of Object.keys(page.documents)) binaryTargets.delete(path);\n for (const target of page.binaryTargets) {\n delete documents[target];\n delete revisions[target];\n binaryTargets.add(target);\n }\n for (const path of page.removals) {\n delete documents[path];\n delete revisions[path];\n binaryTargets.delete(path);\n }\n };\n stage(first);\n let pageToken = first.pageToken;\n while (pageToken !== undefined) {\n const page = await adapter.refresh(authorization, {\n locator,\n selection: confirmed.record.replica.selection,\n fromRoomVersion,\n pageToken,\n });\n if (page.kind === 'still-current' || page.kind === 'beyond-horizon') return unconfirmed;\n if (page.kind !== 'net-advancement') return page;\n if (page.roomVersion !== roomVersion) return unconfirmed;\n stage(page);\n pageToken = page.pageToken;\n }\n const advanced = readStaged(\n {\n ...confirmed.record,\n roomVersion,\n documents,\n binaryTargets: [...binaryTargets].sort(),\n revisions,\n },\n binding,\n confirmed,\n );\n return advanced === null ? unconfirmed : { kind: 'advanced', confirmed: advanced };\n}\n"],"names":["readStaged","unconfirmed","refreshRoom","adapter","authorization","confirmed","binding","locator","record","fromRoomVersion","roomVersion","first","refresh","selection","replica","kind","documents","revisions","binaryTargets","Set","stage","page","Object","assign","path","keys","delete","target","add","removals","pageToken","undefined","advanced","sort"],"mappings":"AAEA,SAASA,UAAU,QAA6B,eAAe;AAC/D,SAASC,WAAW,QAA0B,gBAAgB;AAS9D,OAAO,eAAeC,YACpBC,OAAgB,EAChBC,aAA4B,EAC5BC,SAAyB,EACzBC,OAAoC;IAEpC,MAAMC,UAAUF,UAAUG,MAAM,CAACD,OAAO;IACxC,MAAME,kBAAkBJ,UAAUG,MAAM,CAACE,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AmB,OAAOM;QAC5C,IAAIA,KAAKX,WAAW,KAAKA,aAAa,OAAOT;QAC7CmB,MAAMC;QACNS,YAAYT,KAAKS,SAAS;IAC5B;IACA,MAAME,WAAWhC,WACf;QACE,GAAGK,UAAUG,MAAM;QACnBE;QACAM;QACAE,eAAe;eAAIA;SAAc,CAACe,IAAI;QACtChB;IACF,GACAX,SACAD;IAEF,OAAO2B,aAAa,OAAO/B,cAAc;QAAEc,MAAM;QAAYV,WAAW2B;IAAS;AACnF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/refresh.ts"],"sourcesContent":["import type { Adapter, AdapterFailure, Authorization, RefreshPage } from './adapter.js';\nimport { readStaged, type ConfirmedLayer } from './replica.js';\nimport { unconfirmed, type Unconfirmed } from './transfer.js';\n\nexport type RefreshOutcome =\n | { kind: 'still-current' }\n | { kind: 'advanced'; confirmed: ConfirmedLayer }\n | { kind: 'beyond-horizon' }\n | Unconfirmed\n | AdapterFailure;\n\nexport async function refreshRoom(\n adapter: Adapter,\n authorization: Authorization,\n confirmed: ConfirmedLayer,\n): Promise<RefreshOutcome> {\n const locator = confirmed.record.locator;\n const fromRoomVersion = confirmed.record.roomVersion;\n const first = await adapter.refresh(authorization, {\n locator,\n selection: confirmed.record.replica.selection,\n fromRoomVersion,\n });\n if (first.kind !== 'net-advancement') return first;\n const roomVersion = first.roomVersion;\n const documents: Record<string, string> = { ...confirmed.record.documents };\n const revisions: Record<string, string> = { ...confirmed.record.revisions };\n const binaryTargets = new Set(confirmed.record.binaryTargets);\n const stage = (page: RefreshPage) => {\n Object.assign(documents, page.documents);\n Object.assign(revisions, page.revisions);\n for (const path of Object.keys(page.documents)) binaryTargets.delete(path);\n for (const target of page.binaryTargets) {\n delete documents[target];\n delete revisions[target];\n binaryTargets.add(target);\n }\n for (const path of page.removals) {\n delete documents[path];\n delete revisions[path];\n binaryTargets.delete(path);\n }\n };\n stage(first);\n let pageToken = first.pageToken;\n while (pageToken !== undefined) {\n const page = await adapter.refresh(authorization, {\n locator,\n selection: confirmed.record.replica.selection,\n fromRoomVersion,\n pageToken,\n });\n if (page.kind === 'still-current' || page.kind === 'beyond-horizon') return unconfirmed;\n if (page.kind !== 'net-advancement') return page;\n if (page.roomVersion !== roomVersion) return unconfirmed;\n stage(page);\n pageToken = page.pageToken;\n }\n const advanced = readStaged(\n {\n ...confirmed.record,\n roomVersion,\n documents,\n binaryTargets: [...binaryTargets].sort(),\n revisions,\n },\n confirmed,\n );\n return advanced === null ? unconfirmed : { kind: 'advanced', confirmed: advanced };\n}\n"],"names":["readStaged","unconfirmed","refreshRoom","adapter","authorization","confirmed","locator","record","fromRoomVersion","roomVersion","first","refresh","selection","replica","kind","documents","revisions","binaryTargets","Set","stage","page","Object","assign","path","keys","delete","target","add","removals","pageToken","undefined","advanced","sort"],"mappings":"AACA,SAASA,UAAU,QAA6B,eAAe;AAC/D,SAASC,WAAW,QAA0B,gBAAgB;AAS9D,OAAO,eAAeC,YACpBC,OAAgB,EAChBC,aAA4B,EAC5BC,SAAyB;IAEzB,MAAMC,UAAUD,UAAUE,MAAM,CAACD,OAAO;IACxC,MAAME,kBAAkBH,UAAUE,MAAM,CAACE,WAAW;IACpD,MAAMC,QAAQ,MAAMP,QAAQQ,OAAO,CAACP,eAAe;QACjDE;QACAM,WAAWP,UAAUE,MAAM,CAACM,OAAO,CAACD,SAAS;QAC7CJ;IACF;IACA,IAAIE,MAAMI,IAAI,KAAK,mBAAmB,OAAOJ;IAC7C,MAAMD,cAAcC,MAAMD,WAAW;IACrC,MAAMM,YAAoC;QAAE,GAAGV,UAAUE,MAAM,CAACQ,SAAS;IAAC;IAC1E,MAAMC,YAAoC;QAAE,GAAGX,UAAUE,MAAM,CAACS,SAAS;IAAC;IAC1E,MAAMC,gBAAgB,IAAIC,IAAIb,UAAUE,MAAM,CAACU,aAAa;IAC5D,MAAME,QAAQ,CAACC;QACbC,OAAOC,MAAM,CAACP,WAAWK,KAAKL,SAAS;QACvCM,OAAOC,MAAM,CAACN,WAAWI,KAAKJ,SAAS;QACvC,KAAK,MAAMO,QAAQF,OAAOG,IAAI,CAACJ,KAAKL,SAAS,EAAGE,cAAcQ,MAAM,CAACF;QACrE,KAAK,MAAMG,UAAUN,KAAKH,aAAa,CAAE;YACvC,OAAOF,SAAS,CAACW,OAAO;YACxB,OAAOV,SAAS,CAACU,OAAO;YACxBT,cAAcU,GAAG,CAACD;QACpB;QACA,KAAK,MAAMH,QAAQH,KAAKQ,QAAQ,CAAE;YAChC,OAAOb,SAAS,CAACQ,KAAK;YACtB,OAAOP,SAAS,CAACO,KAAK;YACtBN,cAAcQ,MAAM,CAACF;QACvB;IACF;IACAJ,MAAMT;IACN,IAAImB,YAAYnB,MAAMmB,SAAS;IAC/B,MAAOA,cAAcC,UAAW;QAC9B,MAAMV,OAAO,MAAMjB,QAAQQ,OAAO,CAACP,eAAe;YAChDE;YACAM,WAAWP,UAAUE,MAAM,CAACM,OAAO,CAACD,SAAS;YAC7CJ;YACAqB;QACF;QACA,IAAIT,KAAKN,IAAI,KAAK,mBAAmBM,KAAKN,IAAI,KAAK,kBAAkB,OAAOb;QAC5E,IAAImB,KAAKN,IAAI,KAAK,mBAAmB,OAAOM;QAC5C,IAAIA,KAAKX,WAAW,KAAKA,aAAa,OAAOR;QAC7CkB,MAAMC;QACNS,YAAYT,KAAKS,SAAS;IAC5B;IACA,MAAME,WAAW/B,WACf;QACE,GAAGK,UAAUE,MAAM;QACnBE;QACAM;QACAE,eAAe;eAAIA;SAAc,CAACe,IAAI;QACtChB;IACF,GACAX;IAEF,OAAO0B,aAAa,OAAO9B,cAAc;QAAEa,MAAM;QAAYT,WAAW0B;IAAS;AACnF"}
package/dist/replica.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { AttachedModelBinding } from './model.js';
2
1
  import { type ChangeBatch } from './change.js';
3
2
  import { type Collection, type Composition } from './collection.js';
4
3
  import { type Layer } from './overlay.js';
@@ -26,8 +25,8 @@ type ReplayStep = {
26
25
  };
27
26
  export declare function compositionOf(record: ReplicaRecord): Composition;
28
27
  export declare function readConfirmed(record: ReplicaRecord, previous?: ConfirmedLayer): ConfirmedLayer | null;
29
- export declare function readStaged(record: ReplicaRecord, binding: AttachedModelBinding | null, previous?: ConfirmedLayer): ConfirmedLayer | null;
30
- export declare function applyReturned(confirmed: ConfirmedLayer, documents: Readonly<Record<string, string>>, revisions: Readonly<Record<string, string>>, removals: readonly string[], roomVersion: string, binding: AttachedModelBinding | null): ConfirmedLayer | null;
28
+ export declare function readStaged(record: ReplicaRecord, previous?: ConfirmedLayer): ConfirmedLayer | null;
29
+ export declare function applyReturned(confirmed: ConfirmedLayer, documents: Readonly<Record<string, string>>, revisions: Readonly<Record<string, string>>, removals: readonly string[], roomVersion: string): ConfirmedLayer | null;
31
30
  export declare function replicaOf(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], rewriting: Rewriting, previous?: Replica): Replica;
32
31
  export {};
33
32
  //# sourceMappingURL=replica.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replica.d.ts","sourceRoot":"","sources":["../src/replica.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAa,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAA0C,KAAK,KAAK,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG;IACjC,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,M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C,MAAM,EAAE,MAAM,CAAC,CAAC,EAC3C,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC3C,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,WAAW,EAAE,MAAM,GAClB,cAAc,GAAG,IAAI,CAmBvB;AAuDD,wBAAgB,SAAS,CACvB,SAAS,EAAE,cAAc,EACzB,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,SAAS,EAAE,SAAS,EACpB,QAAQ,CAAC,EAAE,OAAO,GACjB,OAAO,CA2CT"}
package/dist/replica.js CHANGED
@@ -22,14 +22,14 @@ export function readConfirmed(record, previous) {
22
22
  collection
23
23
  };
24
24
  }
25
- export function readStaged(record, binding, previous) {
26
- if (binding !== null && (record.model.status === 'current' || record.selectionModel.status === 'current') && (previous === undefined || !sameLayerText(record, previous.record) || record.model !== previous.record.model || record.selectionModel !== previous.record.selectionModel)) {
27
- const verdict = validateCollection(record.documents, record.binaryTargets, compositionOf(record), binding);
25
+ export function readStaged(record, previous) {
26
+ if ((record.model.status === 'current' || record.selectionModel.status === 'current') && (previous === undefined || !sameLayerText(record, previous.record) || record.model !== previous.record.model || record.selectionModel !== previous.record.selectionModel)) {
27
+ const verdict = validateCollection(record.documents, record.binaryTargets, compositionOf(record));
28
28
  if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') return null;
29
29
  }
30
30
  return readConfirmed(record, previous);
31
31
  }
32
- export function applyReturned(confirmed, documents, revisions, removals, roomVersion, binding) {
32
+ export function applyReturned(confirmed, documents, revisions, removals, roomVersion) {
33
33
  const nextDocuments = {
34
34
  ...confirmed.record.documents,
35
35
  ...documents
@@ -52,7 +52,7 @@ export function applyReturned(confirmed, documents, revisions, removals, roomVer
52
52
  binaryTargets: [
53
53
  ...binaryTargets
54
54
  ].sort()
55
- }, binding, confirmed);
55
+ }, confirmed);
56
56
  }
57
57
  function predicted(confirmed, batches, previous) {
58
58
  const composition = compositionOf(confirmed.record);
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/replica.ts"],"sourcesContent":["import type { AttachedModelBinding } from './model.js';\nimport { immutable, type ChangeBatch } from './change.js';\nimport {\n parseCollection,\n readCollection,\n validateCollection,\n type Collection,\n type Composition,\n} from './collection.js';\nimport { overlay, overlayChanged, sameLayerText, type Layer } from './overlay.js';\nimport { providerRewritten, type Rewriting } from './save.js';\nimport type { ReplicaRecord } from './store.js';\n\nexport type ConfirmedLayer = {\n record: ReplicaRecord;\n collection: Collection;\n};\n\nexport type VisibleLayer = Layer & {\n collection: Collection;\n};\n\nexport type Replica = {\n confirmed: ConfirmedLayer;\n queue: readonly ChangeBatch[];\n visible: VisibleLayer;\n replay: readonly ReplayStep[];\n};\n\ntype ReplayStep = {\n id: string;\n before: Layer;\n after: Layer;\n effective: ChangeBatch;\n collection?: Collection;\n};\n\nexport function compositionOf(record: ReplicaRecord): Composition {\n return {\n collectionRoot: record.collectionRoot,\n model: record.model,\n selection:\n record.typedSelection === null\n ? null\n : { roots: record.typedSelection.roots, model: record.selectionModel },\n };\n}\n\nexport function readConfirmed(\n record: ReplicaRecord,\n previous?: ConfirmedLayer,\n): ConfirmedLayer | null {\n const collection = readCollection(\n record.documents,\n compositionOf(record),\n previous === undefined\n ? undefined\n : { text: previous.record.documents, collection: previous.collection },\n );\n return collection === null ? null : { record, collection };\n}\n\nexport function readStaged(\n record: ReplicaRecord,\n binding: AttachedModelBinding | null,\n previous?: ConfirmedLayer,\n): ConfirmedLayer | null {\n if (\n binding !== null &&\n (record.model.status === 'current' || record.selectionModel.status === 'current') &&\n (previous === undefined ||\n !sameLayerText(record, previous.record) ||\n record.model !== previous.record.model ||\n record.selectionModel !== previous.record.selectionModel)\n ) {\n const verdict = validateCollection(\n record.documents,\n record.binaryTargets,\n compositionOf(record),\n binding,\n );\n if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') return null;\n }\n return readConfirmed(record, previous);\n}\n\nexport function applyReturned(\n confirmed: ConfirmedLayer,\n documents: Readonly<Record<string, string>>,\n revisions: Readonly<Record<string, string>>,\n removals: readonly string[],\n roomVersion: string,\n binding: AttachedModelBinding | null,\n): ConfirmedLayer | null {\n const nextDocuments = { ...confirmed.record.documents, ...documents };\n const nextRevisions = { ...confirmed.record.revisions, ...revisions };\n const binaryTargets = new Set(confirmed.record.binaryTargets);\n for (const path of removals) {\n delete nextDocuments[path];\n delete nextRevisions[path];\n binaryTargets.delete(path);\n }\n return readStaged(\n {\n ...confirmed.record,\n roomVersion,\n documents: nextDocuments,\n revisions: nextRevisions,\n binaryTargets: [...binaryTargets].sort(),\n },\n binding,\n confirmed,\n );\n}\n\nfunction predicted(\n confirmed: ConfirmedLayer,\n batches: readonly ChangeBatch[],\n previous?: Replica,\n): { layer: Layer; replay: readonly ReplayStep[] } {\n const composition = compositionOf(confirmed.record);\n let layer: Layer = confirmed.record;\n const replay: ReplayStep[] = [];\n const prior = new Map(previous?.replay.map((step) => [step.id, step]) ?? []);\n for (const batch of batches) {\n const before = layer;\n const old = prior.get(batch.id);\n const hasMove = batch.changes.some((change) => change.kind === 'move');\n const reuseRewrite =\n old?.collection !== undefined &&\n sameLayerText(before, old.before) &&\n old.collection.composition.collectionRoot === composition.collectionRoot &&\n old.collection.composition.model === composition.model &&\n old.collection.composition.selection?.model === composition.selection?.model &&\n JSON.stringify(old.collection.composition.selection?.roots) ===\n JSON.stringify(composition.selection?.roots);\n const collection = hasMove\n ? reuseRewrite\n ? old.collection\n : parseCollection(\n before.documents,\n composition,\n old?.collection === undefined\n ? { text: confirmed.record.documents, collection: confirmed.collection }\n : { text: old.before.documents, collection: old.collection },\n )\n : undefined;\n const effective =\n collection === undefined\n ? batch\n : reuseRewrite\n ? old.effective\n : providerRewritten(batch, { ...before, collection });\n layer =\n old === undefined\n ? overlay(before, [effective])\n : overlayChanged(before, [effective], old.before, [old.effective], old.after);\n replay.push({\n id: batch.id,\n before,\n after: layer,\n effective,\n ...(collection === undefined ? {} : { collection }),\n });\n }\n return { layer, replay };\n}\n\nexport function replicaOf(\n confirmed: ConfirmedLayer,\n queue: readonly ChangeBatch[],\n rewriting: Rewriting,\n previous?: Replica,\n): Replica {\n const batches = Object.freeze(queue.map(immutable));\n if (batches.length === 0) {\n return {\n confirmed,\n queue: batches,\n visible: {\n documents: confirmed.record.documents,\n binaryTargets: confirmed.record.binaryTargets,\n revisions: confirmed.record.revisions,\n collection: confirmed.collection,\n },\n replay: [],\n };\n }\n const predictedState = rewriting === 'provider' ? predicted(confirmed, batches, previous) : null;\n const layer =\n rewriting === 'provider'\n ? predictedState!.layer\n : previous === undefined\n ? overlay(confirmed.record, batches)\n : overlayChanged(\n confirmed.record,\n batches,\n previous.confirmed.record,\n previous.queue,\n previous.visible,\n );\n return {\n confirmed,\n queue: batches,\n replay: predictedState?.replay ?? [],\n visible: {\n ...layer,\n collection: parseCollection(\n layer.documents,\n compositionOf(confirmed.record),\n previous === undefined\n ? undefined\n : { text: previous.visible.documents, collection: previous.visible.collection },\n ),\n },\n };\n}\n"],"names":["immutable","parseCollection","readCollection","validateCollection","overlay","overlayChanged","sameLayerText","providerRewritten","compositionOf","record","collectionRoot","model","selection","typedSelection","roots","selectionModel","readConfirmed","previous","collection","documents","undefined","text","readStaged","binding","status","verdict","binaryTargets","rule","applyReturned","confirmed","revisions","removals","roomVersion","nextDocuments","nextRevisions","Set","path","delete","sort","predicted","batches","composition","layer","replay","prior","Map","map","step","id","batch","before","old","get","hasMove","changes","some","change","kind","reuseRewrite","JSON","stringify","effective","after","push","replicaOf","queue","rewriting","Object","freeze","length","visible","predictedState"],"mappings":"AACA,SAASA,SAAS,QAA0B,cAAc;AAC1D,SACEC,eAAe,EACfC,cAAc,EACdC,kBAAkB,QAGb,kBAAkB;AACzB,SAASC,OAAO,EAAEC,cAAc,EAAEC,aAAa,QAAoB,eAAe;AAClF,SAASC,iBAAiB,QAAwB,YAAY;AA2B9D,OAAO,SAASC,cAAcC,MAAqB;IACjD,OAAO;QAC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;IACF;IACA,MAAM4B,iBAAiBL,cAAc,aAAa3B,UAAUV,WAAWW,SAASvB,YAAY;IAC5F,MAAMyB,QACJwB,cAAc,aACVK,eAAgB7B,KAAK,GACrBzB,aAAaG,YACXhB,QAAQyB,UAAUpB,MAAM,EAAE+B,WAC1BnC,eACEwB,UAAUpB,MAAM,EAChB+B,SACAvB,SAASY,SAAS,CAACpB,MAAM,EACzBQ,SAASgD,KAAK,EACdhD,SAASqD,OAAO;IAE1B,OAAO;QACLzC;QACAoC,OAAOzB;QACPG,QAAQ4B,gBAAgB5B,UAAU,EAAE;QACpC2B,SAAS;YACP,GAAG5B,KAAK;YACRxB,YAAYjB,gBACVyC,MAAMvB,SAAS,EACfX,cAAcqB,UAAUpB,MAAM,GAC9BQ,aAAaG,YACTA,YACA;gBAAEC,MAAMJ,SAASqD,OAAO,CAACnD,SAAS;gBAAED,YAAYD,SAASqD,OAAO,CAACpD,UAAU;YAAC;QAEpF;IACF;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/replica.ts"],"sourcesContent":["import { immutable, type ChangeBatch } from './change.js';\nimport {\n parseCollection,\n readCollection,\n validateCollection,\n type Collection,\n type Composition,\n} from './collection.js';\nimport { overlay, overlayChanged, sameLayerText, type Layer } from './overlay.js';\nimport { providerRewritten, type Rewriting } from './save.js';\nimport type { ReplicaRecord } from './store.js';\n\nexport type ConfirmedLayer = {\n record: ReplicaRecord;\n collection: Collection;\n};\n\nexport type VisibleLayer = Layer & {\n collection: Collection;\n};\n\nexport type Replica = {\n confirmed: ConfirmedLayer;\n queue: readonly ChangeBatch[];\n visible: VisibleLayer;\n replay: readonly ReplayStep[];\n};\n\ntype ReplayStep = {\n id: string;\n before: Layer;\n after: Layer;\n effective: ChangeBatch;\n collection?: Collection;\n};\n\nexport function compositionOf(record: ReplicaRecord): Composition {\n return {\n collectionRoot: record.collectionRoot,\n model: record.model,\n selection:\n record.typedSelection === null\n ? null\n : { roots: record.typedSelection.roots, model: record.selectionModel },\n };\n}\n\nexport function readConfirmed(\n record: ReplicaRecord,\n previous?: ConfirmedLayer,\n): ConfirmedLayer | null {\n const collection = readCollection(\n record.documents,\n compositionOf(record),\n previous === undefined\n ? undefined\n : { text: previous.record.documents, collection: previous.collection },\n );\n return collection === null ? null : { record, collection };\n}\n\nexport function readStaged(\n record: ReplicaRecord,\n previous?: ConfirmedLayer,\n): ConfirmedLayer | null {\n if (\n (record.model.status === 'current' || record.selectionModel.status === 'current') &&\n (previous === undefined ||\n !sameLayerText(record, previous.record) ||\n record.model !== previous.record.model ||\n record.selectionModel !== previous.record.selectionModel)\n ) {\n const verdict = validateCollection(\n record.documents,\n record.binaryTargets,\n compositionOf(record),\n );\n if (verdict.verdict === 'refuse' && verdict.rule !== 'model-unavailable') return null;\n }\n return readConfirmed(record, previous);\n}\n\nexport function applyReturned(\n confirmed: ConfirmedLayer,\n documents: Readonly<Record<string, string>>,\n revisions: Readonly<Record<string, string>>,\n removals: readonly string[],\n roomVersion: string,\n): ConfirmedLayer | null {\n const nextDocuments = { ...confirmed.record.documents, ...documents };\n const nextRevisions = { ...confirmed.record.revisions, ...revisions };\n const binaryTargets = new Set(confirmed.record.binaryTargets);\n for (const path of removals) {\n delete nextDocuments[path];\n delete nextRevisions[path];\n binaryTargets.delete(path);\n }\n return readStaged(\n {\n ...confirmed.record,\n roomVersion,\n documents: nextDocuments,\n revisions: nextRevisions,\n binaryTargets: [...binaryTargets].sort(),\n },\n confirmed,\n );\n}\n\nfunction predicted(\n confirmed: ConfirmedLayer,\n batches: readonly ChangeBatch[],\n previous?: Replica,\n): { layer: Layer; replay: readonly ReplayStep[] } {\n const composition = compositionOf(confirmed.record);\n let layer: Layer = confirmed.record;\n const replay: ReplayStep[] = [];\n const prior = new Map(previous?.replay.map((step) => [step.id, step]) ?? []);\n for (const batch of batches) {\n const before = layer;\n const old = prior.get(batch.id);\n const hasMove = batch.changes.some((change) => change.kind === 'move');\n const reuseRewrite =\n old?.collection !== undefined &&\n sameLayerText(before, old.before) &&\n old.collection.composition.collectionRoot === composition.collectionRoot &&\n old.collection.composition.model === composition.model &&\n old.collection.composition.selection?.model === composition.selection?.model &&\n JSON.stringify(old.collection.composition.selection?.roots) ===\n JSON.stringify(composition.selection?.roots);\n const collection = hasMove\n ? reuseRewrite\n ? old.collection\n : parseCollection(\n before.documents,\n composition,\n old?.collection === undefined\n ? { text: confirmed.record.documents, collection: confirmed.collection }\n : { text: old.before.documents, collection: old.collection },\n )\n : undefined;\n const effective =\n collection === undefined\n ? batch\n : reuseRewrite\n ? old.effective\n : providerRewritten(batch, { ...before, collection });\n layer =\n old === undefined\n ? overlay(before, [effective])\n : overlayChanged(before, [effective], old.before, [old.effective], old.after);\n replay.push({\n id: batch.id,\n before,\n after: layer,\n effective,\n ...(collection === undefined ? {} : { collection }),\n });\n }\n return { layer, replay };\n}\n\nexport function replicaOf(\n confirmed: ConfirmedLayer,\n queue: readonly ChangeBatch[],\n rewriting: Rewriting,\n previous?: Replica,\n): Replica {\n const batches = Object.freeze(queue.map(immutable));\n if (batches.length === 0) {\n return {\n confirmed,\n queue: batches,\n visible: {\n documents: confirmed.record.documents,\n binaryTargets: confirmed.record.binaryTargets,\n revisions: confirmed.record.revisions,\n collection: confirmed.collection,\n },\n replay: [],\n };\n }\n const predictedState = rewriting === 'provider' ? predicted(confirmed, batches, previous) : null;\n const layer =\n rewriting === 'provider'\n ? predictedState!.layer\n : previous === undefined\n ? overlay(confirmed.record, batches)\n : overlayChanged(\n confirmed.record,\n batches,\n previous.confirmed.record,\n previous.queue,\n previous.visible,\n );\n return {\n confirmed,\n queue: batches,\n replay: predictedState?.replay ?? [],\n visible: {\n ...layer,\n collection: parseCollection(\n layer.documents,\n compositionOf(confirmed.record),\n previous === undefined\n ? undefined\n : { text: previous.visible.documents, collection: previous.visible.collection },\n ),\n },\n };\n}\n"],"names":["immutable","parseCollection","readCollection","validateCollection","overlay","overlayChanged","sameLayerText","providerRewritten","compositionOf","record","collectionRoot","model","selection","typedSelection","roots","selectionModel","readConfirmed","previous","collection","documents","undefined","text","readStaged","status","verdict","binaryTargets","rule","applyReturned","confirmed","revisions","removals","roomVersion","nextDocuments","nextRevisions","Set","path","delete","sort","predicted","batches","composition","layer","replay","prior","Map","map","step","id","batch","before","old","get","hasMove","changes","some","change","kind","reuseRewrite","JSON","stringify","effective","after","push","replicaOf","queue","rewriting","Object","freeze","length","visible","predictedState"],"mappings":"AAAA,SAASA,SAAS,QAA0B,cAAc;AAC1D,SACEC,eAAe,EACfC,cAAc,EACdC,kBAAkB,QAGb,kBAAkB;AACzB,SAASC,OAAO,EAAEC,cAAc,EAAEC,aAAa,QAAoB,eAAe;AAClF,SAASC,iBAAiB,QAAwB,YAAY;AA2B9D,OAAO,SAASC,cAAcC,MAAqB;IACjD,OAAO;QACLC,gBAAgBD,OAAOC,cAAc;QACrCC,OAAOF,OAAOE,KAAK;QACnBC,WACEH,OAAOI,cAAc,KAAK,OACtB,OACA;YAAEC,OAAOL,OAAOI,cAAc,CAACC,KAAK;YAAEH,OAAOF,OAAOM,cAAc;QAAC;IAC3E;AACF;AAEA,OAAO,SAASC,cACdP,MAAqB,EACrBQ,QAAyB;IAEzB,MAAMC,aAAahB,eACjBO,OAAOU,SAAS,EAChBX,cAAcC,SACdQ,aAAaG,YACTA,YACA;QAAEC,MAAMJ,SAASR,MAAM,CAACU,SAAS;QAAED,YAAYD,SAASC,UAAU;IAAC;IAEzE,OAAOA,eAAe,OAAO,OAAO;QAAET;QAAQS;IAAW;AAC3D;AAEA,OAAO,SAASI,WACdb,MAAqB,EACrBQ,QAAyB;IAEzB,IACE,AAACR,CAAAA,OAAOE,KAAK,CAACY,MAAM,KAAK,aAAad,OAAOM,cAAc,CAACQ,MAAM,KAAK,SAAQ,KAC9EN,CAAAA,aAAaG,aACZ,CAACd,cAAcG,QAAQQ,SAASR,MAAM,KACtCA,OAAOE,KAAK,KAAKM,SAASR,MAAM,CAACE,KAAK,IACtCF,OAAOM,cAAc,KAAKE,SAASR,M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AAOC;IAAO;AACzB;AAEA,OAAO,SAASqB,UACdnC,SAAyB,EACzBoC,KAA6B,EAC7BC,SAAoB,EACpBhD,QAAkB;IAElB,MAAMsB,UAAU2B,OAAOC,MAAM,CAACH,MAAMnB,GAAG,CAAC7C;IACxC,IAAIuC,QAAQ6B,MAAM,KAAK,GAAG;QACxB,OAAO;YACLxC;YACAoC,OAAOzB;YACP8B,SAAS;gBACPlD,WAAWS,UAAUnB,MAAM,CAACU,SAAS;gBACrCM,eAAeG,UAAUnB,MAAM,CAACgB,aAAa;gBAC7CI,WAAWD,UAAUnB,MAAM,CAACoB,SAAS;gBACrCX,YAAYU,UAAUV,UAAU;YAClC;YACAwB,QAAQ,EAAE;QACZ;IACF;IACA,MAAM4B,iBAAiBL,cAAc,aAAa3B,UAAUV,WAAWW,SAAStB,YAAY;IAC5F,MAAMwB,QACJwB,cAAc,aACVK,eAAgB7B,KAAK,GACrBxB,aAAaG,YACXhB,QAAQwB,UAAUnB,MAAM,EAAE8B,WAC1BlC,eACEuB,UAAUnB,MAAM,EAChB8B,SACAtB,SAASW,SAAS,CAACnB,MAAM,EACzBQ,SAAS+C,KAAK,EACd/C,SAASoD,OAAO;IAE1B,OAAO;QACLzC;QACAoC,OAAOzB;QACPG,QAAQ4B,gBAAgB5B,UAAU,EAAE;QACpC2B,SAAS;YACP,GAAG5B,KAAK;YACRvB,YAAYjB,gBACVwC,MAAMtB,SAAS,EACfX,cAAcoB,UAAUnB,MAAM,GAC9BQ,aAAaG,YACTA,YACA;gBAAEC,MAAMJ,SAASoD,OAAO,CAAClD,SAAS;gBAAED,YAAYD,SAASoD,OAAO,CAACnD,UAAU;YAAC;QAEpF;IACF;AACF"}
package/dist/save.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import type { AttachedModelBinding } from './model.js';
2
1
  import type { ProviderLimit } from './adapter.js';
3
2
  import { type Change, type ChangeBatch, type WrittenBy } from './change.js';
4
3
  import { type Composition } from './collection.js';
5
4
  import type { VisibleLayer } from './replica.js';
6
5
  export type SaveRefusal = {
7
- source?: 'model';
8
6
  rule: string;
9
7
  file?: string;
10
8
  location?: string;
@@ -16,7 +14,6 @@ export type SaveInput = {
16
14
  rewriting: Rewriting;
17
15
  baseRoomVersion: string;
18
16
  operations: import('./adapter.js').OperationScopes;
19
- binding: AttachedModelBinding | null;
20
17
  providerOwnedPaths: readonly string[];
21
18
  providerLimits: readonly ProviderLimit[];
22
19
  visible: VisibleLayer;
@@ -1 +1 @@
1
- {"version":3,"file":"save.d.ts","sourceRoot":"","sources":["../src/save.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAc,MAAM,YAAY,CAAC;AAEnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,WAAW,EAEhB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAML,KAAK,WAAW,EAEjB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,SAAS,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,OAAO,cAAc,EAAE,eAAe,CAAC;IACnD,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACrC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,cAAc,EAA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B,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,cAAc,EAAE,SAAS,aAAa,EAAE,CAAC;IACzC,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAgN9C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,GAAG,WAAW,CAOxF;AAqLD,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,WAAW,CAgGxD"}
package/dist/save.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { definitionOf } from './model.js';
1
2
  import { apply, links, parse, serialize } from '@agentshouse/mdmodel';
2
3
  import { immutable } from './change.js';
3
- import { governing, parseCollection, typesAt, validateCollection } from './collection.js';
4
+ import { governing, parseCollection, validateCollection } from './collection.js';
4
5
  import { changeBatchIdentity } from './identity.js';
5
6
  import { overlay } from './overlay.js';
6
7
  import { beneath, covered, normalize, relative, resolve } from './paths.js';
@@ -84,12 +85,7 @@ function expand(changes, visible) {
84
85
  };
85
86
  }
86
87
  function referenceField(spec) {
87
- if (typeof spec !== 'object' || spec === null) return false;
88
- const declared = spec;
89
- return declared.kind === 'reference' || declared.kind === 'list' && declared.of === 'reference';
90
- }
91
- function definitionOf(types, type) {
92
- return types.find((declared)=>declared.name === type);
88
+ return spec.kind === 'reference' || spec.kind === 'list' && spec.of.kind === 'reference';
93
89
  }
94
90
  function retarget(value, from, to, moves) {
95
91
  if (Array.isArray(value)) {
@@ -216,7 +212,7 @@ function rewrites(changes, visible) {
216
212
  for (const [path, document] of Object.entries(visible.collection.documents)){
217
213
  if (settled.has(path)) continue;
218
214
  const moved = moves.get(path) ?? path;
219
- const definition = definitionOf(typesAt(visible.collection.composition, path), document.type);
215
+ const definition = definitionOf(governing(visible.collection.composition, path), document.type);
220
216
  for (const [name, spec] of Object.entries(definition?.fields ?? {})){
221
217
  if (!referenceField(spec) || settled.has(`${path} ${name}`)) continue;
222
218
  const value = retarget(document.fields[name], path, moved, moves);
@@ -288,7 +284,7 @@ function incoming(collection, removed) {
288
284
  found.set(target, referrers);
289
285
  };
290
286
  for (const [path, document] of Object.entries(collection.documents)){
291
- const definition = definitionOf(typesAt(collection.composition, path), document.type);
287
+ const definition = definitionOf(governing(collection.composition, path), document.type);
292
288
  for (const [name, spec] of Object.entries(definition?.fields ?? {})){
293
289
  if (!referenceField(spec)) continue;
294
290
  for (const target of targets(document.fields[name], path))note(target, path);
@@ -320,29 +316,15 @@ function affected(change) {
320
316
  change.path
321
317
  ];
322
318
  }
323
- function definitionAddresses(composition) {
324
- const addresses = new Set();
325
- if (composition.model.status !== 'unavailable') {
326
- for (const path of Object.keys(composition.model.snapshot.definitions))addresses.add(path);
327
- }
328
- if (composition.selection !== null && composition.selection.model.status !== 'unavailable') {
329
- for (const path of Object.keys(composition.selection.model.snapshot.definitions)){
330
- addresses.add(path);
331
- }
332
- }
333
- return addresses;
334
- }
335
319
  function guard(changes, input) {
336
320
  const existing = new Set([
337
321
  ...Object.keys(input.visible.documents),
338
322
  ...input.visible.binaryTargets
339
323
  ]);
340
- const definitions = definitionAddresses(input.composition);
341
324
  for (const change of changes){
342
325
  for (const path of affected(change)){
343
326
  const normalized = normalize(path);
344
327
  if (normalized === null || normalized === '') return refuse('room-root', path);
345
- if (definitions.has(normalized)) return refuse('model-definition', normalized);
346
328
  if (covered(input.providerOwnedPaths, normalized)) {
347
329
  return refuse('provider-owned-path', normalized);
348
330
  }
@@ -511,18 +493,13 @@ export function buildBatch(input) {
511
493
  ].filter((path)=>typed(input.visible.documents[path]) || typed(resulting.documents[path]));
512
494
  const needsModel = typedPaths.length > 0;
513
495
  const withoutModel = typedPaths.find((path)=>governing(input.composition, path).status === 'unavailable');
514
- if (needsModel && (withoutModel !== undefined || input.binding === null)) {
515
- return refuse('model-unavailable', withoutModel ?? typedPaths[0]);
516
- }
496
+ if (withoutModel !== undefined) return refuse('model-unavailable', withoutModel);
517
497
  const validationText = needsModel ? resulting.documents : Object.fromEntries(Object.entries(resulting.documents).filter(([path])=>predicted.changes.some((change)=>affected(change).includes(path))));
518
- const verdict = validateCollection(validationText, resulting.binaryTargets, input.composition, input.binding);
498
+ const verdict = validateCollection(validationText, resulting.binaryTargets, input.composition);
519
499
  if (verdict.verdict === 'refuse') {
520
500
  return {
521
501
  kind: 'refused',
522
502
  refusal: {
523
- ...verdict.source === 'model' ? {
524
- source: 'model'
525
- } : {},
526
503
  rule: verdict.rule,
527
504
  file: verdict.file,
528
505
  ...verdict.location === undefined ? {} : {