@ai-matrx/records 0.72.14 → 0.72.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/app-table/index.d.cts +3 -3
  3. package/dist/app-table/index.d.ts +3 -3
  4. package/dist/core/index.d.cts +5 -5
  5. package/dist/core/index.d.ts +5 -5
  6. package/dist/{declareTable-Br8pE4fr.d.cts → declareTable-CLvpMdgJ.d.cts} +2 -2
  7. package/dist/{declareTable-DM6z1tc-.d.ts → declareTable-DY3oN4rq.d.ts} +2 -2
  8. package/dist/index.d.cts +3 -3
  9. package/dist/index.d.ts +3 -3
  10. package/dist/memory/index.cjs +2681 -0
  11. package/dist/memory/index.cjs.map +1 -0
  12. package/dist/memory/index.d.cts +126 -0
  13. package/dist/memory/index.d.ts +126 -0
  14. package/dist/memory/index.js +2658 -0
  15. package/dist/memory/index.js.map +1 -0
  16. package/dist/{ports-DKBvsoya.d.cts → ports-DKOk7AT2.d.cts} +1 -1
  17. package/dist/{ports-Bhu2Q3V0.d.ts → ports-Df3VghxK.d.ts} +1 -1
  18. package/dist/{table-kind-D6Lz7ebE.d.ts → table-kind-CD9B1vtx.d.ts} +1 -1
  19. package/dist/{table-kind-D6VOew74.d.cts → table-kind-e-g5kGXV.d.cts} +1 -1
  20. package/dist/templates/index.cjs +44 -17
  21. package/dist/templates/index.cjs.map +1 -1
  22. package/dist/templates/index.d.cts +18 -1176
  23. package/dist/templates/index.d.ts +18 -1176
  24. package/dist/templates/index.js +44 -17
  25. package/dist/templates/index.js.map +1 -1
  26. package/dist/{validate-QtFxMmJc.d.ts → types-Ba11aOEO.d.ts} +1 -42
  27. package/dist/{validate-DUSrx-9E.d.cts → types-BtEKp3ot.d.cts} +1 -42
  28. package/dist/types-DxVoKKpL.d.ts +1186 -0
  29. package/dist/types-dlj1-2t2.d.cts +1186 -0
  30. package/dist/use-cases/index.d.cts +3 -2
  31. package/dist/use-cases/index.d.ts +3 -2
  32. package/dist/validate-CMb7R_ke.d.cts +44 -0
  33. package/dist/validate-E-g4LAZ6.d.ts +44 -0
  34. package/package.json +13 -1
@@ -4998,7 +4998,8 @@ function validateTemplate(raw, options = {}) {
4998
4998
  const at = `tables (${t.token}).fields (${f.key})`;
4999
4999
  const text2 = `${f.key} ${norm(f.label)}`;
5000
5000
  const e = effective(t.token, f);
5001
- const criminalCharges = /(^|_)charges?($|_)/.test(f.key) && behaviorOf(f) === "text";
5001
+ const billingTable = /(invoice|bill|statement|receipt|payment|charge|fee|order|account)/i.test(`${t.token} ${t.labelSingular}`);
5002
+ const criminalCharges = /(^|_)charges?($|_)/.test(f.key) && behaviorOf(f) === "text" && !billingTable;
5002
5003
  const phoneLike = behaviorOf(f) === "text" && /\b(cell|mobile|phone)\b/.test(norm(f.label));
5003
5004
  const personal = PERSONAL_ONLY.test(f.key) || /\b(medical conditions?|medications?|diagnos[ie]s)\b/.test(norm(f.label));
5004
5005
  const floored = (RESTRICTED_KEY.test(f.key) || RESTRICTED_LABEL.test(norm(f.label)) || criminalCharges) && (!personal || holdsPeople(t));
@@ -5302,7 +5303,8 @@ ${e.body}`.matchAll(MERGE_TOKEN)].map((m) => m[1]));
5302
5303
  const qq = agent.question;
5303
5304
  const ask = norm(qq.ask);
5304
5305
  const words = (t) => norm(t).split(" ").filter((w) => w.length >= 4);
5305
- const mentions = (t) => words(t).some((w) => ask.includes(w.replace(/s$/, "")));
5306
+ const askWords = new Set(ask.split(" "));
5307
+ const mentions = (t) => !!norm(t) && ask.includes(norm(t)) || words(t).some((w) => ask.includes(w.replace(/s$/, ""))) || words(t).length === 0 && norm(t).split(" ").filter(Boolean).some((w) => w.length >= 3 && (askWords.has(w) || askWords.has(`${w}s`)));
5306
5308
  for (const [k, v] of Object.entries(qq.expect.filter ?? {})) {
5307
5309
  if (typeof v === "string" && !mentions(v) && !ask.includes(norm(v))) say("agent.question.ask", `It filters on ${k} = "${v}", and the question never says so.`);
5308
5310
  }
@@ -5383,7 +5385,8 @@ ${e.body}`.matchAll(MERGE_TOKEN)].map((m) => m[1]));
5383
5385
  const named = (t) => {
5384
5386
  if (!t) return false;
5385
5387
  if (says.includes(norm(t))) return true;
5386
- const words = [...new Set(norm(t).split(" ").filter((w) => w.length >= 4))];
5388
+ const long = [...new Set(norm(t).split(" ").filter((w) => w.length >= 4))];
5389
+ const words = long.length ? long : [...new Set(norm(t).split(" ").filter((w) => w.length >= 2))];
5387
5390
  const said = new Set(says.split(" "));
5388
5391
  return words.length > 0 && words.filter((w) => said.has(w) || said.has(`${w}s`)).length >= Math.min(2, words.length);
5389
5392
  };
@@ -5933,7 +5936,14 @@ function compileInstallPlan(written) {
5933
5936
  const attachments = written.attachments ?? [];
5934
5937
  const attachmentKeys = new Set(attachments.map((a) => a.key));
5935
5938
  const spec = tokenizeValues({ ...written, attachments: void 0 }, attachmentKeys);
5936
- const tables = allTables(spec);
5939
+ const bound = new Map(allTables(spec).filter((t) => t.bindsTo?.tableId).map((t) => [t.token, t.bindsTo]));
5940
+ const has = (token, key) => bound.get(token)?.fields.includes(key) ?? false;
5941
+ const tables = allTables(spec).map((t) => {
5942
+ if (bound.has(t.token)) return { ...t, rows: [] };
5943
+ const toBound = t.fields.filter((f) => f.parityType === "relation" && f.relationTarget && bound.has(f.relationTarget)).map((f) => f.key);
5944
+ if (!toBound.length) return t;
5945
+ return { ...t, rows: t.rows.map((r) => ({ ...r, values: Object.fromEntries(Object.entries(r.values ?? {}).filter(([k]) => !toBound.includes(k))) })) };
5946
+ });
5937
5947
  const steps = [];
5938
5948
  const tableRef = (token) => {
5939
5949
  if (!tables.some((t) => t.token === token)) throw new Error(`The template names a table "${token}" it does not have.`);
@@ -5963,6 +5973,18 @@ function compileInstallPlan(written) {
5963
5973
  }
5964
5974
  }
5965
5975
  for (const t of tables) {
5976
+ if (bound.has(t.token)) {
5977
+ for (const f of t.fields.filter((x) => !DERIVED.has(x.parityType) && x.parityType !== "formula" && x.parityType !== "relation" && !isSelfDeclaredField(x) && !has(t.token, x.key))) {
5978
+ steps.push({
5979
+ label: `bound.${t.token}.${f.key}`,
5980
+ door: "field_declare",
5981
+ args: { p_organization_id: "${org}", p_table_id: tableRef(t.token), p_spec: selfDeclaredFieldSpec(f) },
5982
+ save: { [`fields.${t.token}.${f.key}`]: [] },
5983
+ made: [{ kind: "field", ref: `fields.${t.token}.${f.key}`, table: `tables.${t.token}` }]
5984
+ });
5985
+ }
5986
+ continue;
5987
+ }
5966
5988
  steps.push({
5967
5989
  label: `tables.${t.token}`,
5968
5990
  door: "table_from_example",
@@ -5973,7 +5995,7 @@ function compileInstallPlan(written) {
5973
5995
  }
5974
5996
  steps.push(...membersAddRowsSteps(spec, tableRef));
5975
5997
  for (const t of tables) {
5976
- for (const f of t.fields.filter((x) => x.parityType === "relation" && x.relationTarget)) {
5998
+ for (const f of t.fields.filter((x) => x.parityType === "relation" && x.relationTarget && !has(t.token, x.key))) {
5977
5999
  steps.push({
5978
6000
  label: `relations.${t.token}.${f.key}`,
5979
6001
  door: "field_declare",
@@ -5984,7 +6006,7 @@ function compileInstallPlan(written) {
5984
6006
  }
5985
6007
  }
5986
6008
  for (const t of tables) {
5987
- for (const f of t.fields.filter(isSelfDeclaredField)) {
6009
+ for (const f of t.fields.filter((x) => isSelfDeclaredField(x) && !has(t.token, x.key))) {
5988
6010
  steps.push({
5989
6011
  label: `self_declared.${t.token}.${f.key}`,
5990
6012
  door: "field_declare",
@@ -6020,7 +6042,7 @@ function compileInstallPlan(written) {
6020
6042
  }
6021
6043
  }
6022
6044
  for (const t of tables) {
6023
- for (const f of t.fields.filter((x) => DERIVED.has(x.parityType))) {
6045
+ for (const f of t.fields.filter((x) => DERIVED.has(x.parityType) && !has(t.token, x.key))) {
6024
6046
  steps.push({
6025
6047
  label: `derived.${t.token}.${f.key}`,
6026
6048
  door: "field_declare",
@@ -6031,7 +6053,7 @@ function compileInstallPlan(written) {
6031
6053
  }
6032
6054
  }
6033
6055
  for (const t of tables) {
6034
- for (const f of formulaOrder(t)) {
6056
+ for (const f of formulaOrder(t).filter((x) => !has(t.token, x.key))) {
6035
6057
  steps.push({
6036
6058
  label: `formula.${t.token}.${f.key}`,
6037
6059
  door: "field_declare",
@@ -6057,7 +6079,7 @@ function compileInstallPlan(written) {
6057
6079
  saveEach: { array: [], key: ["data", "key"], value: ["id"], prefix: `fields.${token}.` }
6058
6080
  });
6059
6081
  }
6060
- for (const d of spec.dimensions) {
6082
+ for (const d of spec.dimensions.filter((x) => !bound.has(x.table))) {
6061
6083
  const overrides = {};
6062
6084
  if (d.dimensions) overrides["dimensions"] = d.dimensions;
6063
6085
  if (d.measures) overrides["measures"] = d.measures;
@@ -6214,18 +6236,22 @@ function compileInstallPlan(written) {
6214
6236
  });
6215
6237
  }
6216
6238
  const host = compileHostExtras(spec);
6239
+ const agent = spec.agent;
6217
6240
  return {
6218
6241
  planVersion: INSTALL_PLAN_VERSION,
6219
6242
  timezone: spec.business.timezone || "UTC",
6220
6243
  steps,
6221
- agent: {
6222
- platformAgent: spec.agent.platformAgent,
6223
- name: spec.agent.name,
6224
- bindings: spec.agent.variables.map((v) => {
6225
- const binding = host.agentBindings.get(v.name);
6226
- return { variable: v.name, tableToken: v.table, describes: v.describes, ...binding ? { binding } : {} };
6227
- })
6228
- },
6244
+ ...agent?.platformAgent ? {
6245
+ agent: {
6246
+ platformAgent: agent.platformAgent,
6247
+ name: agent.name,
6248
+ bindings: (agent.variables ?? []).map((v) => {
6249
+ const binding = host.agentBindings.get(v.name);
6250
+ return { variable: v.name, tableToken: v.table, describes: v.describes, ...binding ? { binding } : {} };
6251
+ })
6252
+ }
6253
+ } : {},
6254
+ ...bound.size ? { ids: Object.fromEntries([...bound].map(([token, b]) => [`ref:tables.${token}`, b.tableId])) } : {},
6229
6255
  ...host.extras
6230
6256
  };
6231
6257
  }
@@ -6285,6 +6311,7 @@ export {
6285
6311
  RECORDS_UI_FIELD_SURFACES,
6286
6312
  RECORDS_UI_VIEW_LAYOUTS,
6287
6313
  RELATIVE_DATE,
6314
+ RESOLVABLE_FIELD_TYPE_WORDS,
6288
6315
  SERVER_DATE_GRAMMAR,
6289
6316
  SHARED_BLOCKS,
6290
6317
  SHARED_BLOCK_IDS,