@deepagents/context 0.32.0 → 0.34.0

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/browser.js CHANGED
@@ -900,27 +900,113 @@ async function estimate(modelId, renderer, ...fragments) {
900
900
  }
901
901
 
902
902
  // packages/context/src/lib/fragments/message/user.ts
903
- import { generateId as generateId2, isTextUIPart } from "ai";
903
+ import { generateId as generateId2 } from "ai";
904
+
905
+ // packages/context/src/lib/text.ts
906
+ import { isTextUIPart } from "ai";
907
+ function getTextParts(message2) {
908
+ return message2.parts.filter(isTextUIPart).map((part) => part.text);
909
+ }
910
+ function extractPlainText(message2) {
911
+ return getTextParts(message2).join(" ");
912
+ }
913
+
914
+ // packages/context/src/lib/fragments/message/user.ts
904
915
  function everyNTurns(n) {
905
- return (turn) => turn % n === 0;
916
+ return ({ turn }) => turn % n === 0;
906
917
  }
907
918
  function once() {
908
- return (turn) => turn === 1;
919
+ return ({ turn }) => turn === 1;
909
920
  }
910
921
  function firstN(n) {
911
- return (turn) => turn <= n;
922
+ return ({ turn }) => turn <= n;
912
923
  }
913
924
  function afterTurn(n) {
914
- return (turn) => turn > n;
925
+ return ({ turn }) => turn > n;
915
926
  }
916
927
  function and(...predicates) {
917
- return (turn) => predicates.every((p) => p(turn));
928
+ return (ctx) => predicates.every((p) => p(ctx));
918
929
  }
919
930
  function or(...predicates) {
920
- return (turn) => predicates.some((p) => p(turn));
931
+ return (ctx) => predicates.some((p) => p(ctx));
921
932
  }
922
933
  function not(predicate) {
923
- return (turn) => !predicate(turn);
934
+ return (ctx) => !predicate(ctx);
935
+ }
936
+ function contentIncludes(keywords) {
937
+ const lower = keywords.map((k) => k.toLowerCase());
938
+ return (ctx) => {
939
+ const text = ctx.content.toLowerCase();
940
+ return lower.some((kw) => text.includes(kw));
941
+ };
942
+ }
943
+ function contentPattern(pattern) {
944
+ return (ctx) => {
945
+ pattern.lastIndex = 0;
946
+ return pattern.test(ctx.content);
947
+ };
948
+ }
949
+ function toDateParts(date, tz) {
950
+ const parts = new Intl.DateTimeFormat("en-CA", {
951
+ timeZone: tz,
952
+ year: "numeric",
953
+ month: "2-digit",
954
+ day: "2-digit",
955
+ hour: "2-digit",
956
+ hourCycle: "h23"
957
+ }).formatToParts(date);
958
+ const get = (type) => parts.find((p) => p.type === type).value;
959
+ return {
960
+ year: get("year"),
961
+ month: get("month"),
962
+ day: get("day"),
963
+ hour: get("hour")
964
+ };
965
+ }
966
+ function temporalChanged(ctx, tz, getKey) {
967
+ if (ctx.lastMessageAt === void 0) return true;
968
+ const nowParts = toDateParts(/* @__PURE__ */ new Date(), tz);
969
+ const prevParts = toDateParts(new Date(ctx.lastMessageAt), tz);
970
+ return getKey(nowParts) !== getKey(prevParts);
971
+ }
972
+ function getSeason(month) {
973
+ if (month >= 2 && month <= 4) return "Spring";
974
+ if (month >= 5 && month <= 7) return "Summer";
975
+ if (month >= 8 && month <= 10) return "Fall";
976
+ return "Winter";
977
+ }
978
+ function isoWeekKey(parts) {
979
+ const d = new Date(
980
+ Date.UTC(
981
+ parseInt(parts.year),
982
+ parseInt(parts.month) - 1,
983
+ parseInt(parts.day)
984
+ )
985
+ );
986
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
987
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
988
+ const weekNo = Math.ceil(
989
+ ((d.getTime() - yearStart.getTime()) / 864e5 + 1) / 7
990
+ );
991
+ return `${d.getUTCFullYear()}-W${String(weekNo).padStart(2, "0")}`;
992
+ }
993
+ function dayChanged(tz = "UTC") {
994
+ return (ctx) => temporalChanged(ctx, tz, (p) => `${p.year}-${p.month}-${p.day}`);
995
+ }
996
+ function hourChanged(tz = "UTC") {
997
+ return (ctx) => temporalChanged(ctx, tz, (p) => `${p.year}-${p.month}-${p.day}-${p.hour}`);
998
+ }
999
+ function monthChanged(tz = "UTC") {
1000
+ return (ctx) => temporalChanged(ctx, tz, (p) => `${p.year}-${p.month}`);
1001
+ }
1002
+ function yearChanged(tz = "UTC") {
1003
+ return (ctx) => temporalChanged(ctx, tz, (p) => p.year);
1004
+ }
1005
+ function seasonChanged(tz = "UTC") {
1006
+ return (ctx) => temporalChanged(ctx, tz, (p) => getSeason(parseInt(p.month) - 1));
1007
+ }
1008
+ function weekChanged(tz = "UTC") {
1009
+ return (ctx) => temporalChanged(ctx, tz, isoWeekKey);
924
1010
  }
925
1011
  function isConditionalReminder(fragment2) {
926
1012
  return fragment2.name === "reminder" && !!fragment2.metadata?.reminder;
@@ -996,9 +1082,6 @@ function stripReminders(message2) {
996
1082
  }
997
1083
  return nextMessage;
998
1084
  }
999
- function extractPlainText(message2) {
1000
- return message2.parts.filter(isTextUIPart).map((part) => part.text).join(" ");
1001
- }
1002
1085
  function isRecord(value) {
1003
1086
  return typeof value === "object" && value !== null && !Array.isArray(value);
1004
1087
  }
@@ -2236,13 +2319,15 @@ export {
2236
2319
  assistant,
2237
2320
  assistantText,
2238
2321
  clarification,
2322
+ contentIncludes,
2323
+ contentPattern,
2239
2324
  correction,
2325
+ dayChanged,
2240
2326
  defaultTokenizer,
2241
2327
  estimate,
2242
2328
  everyNTurns,
2243
2329
  example,
2244
2330
  explain,
2245
- extractPlainText,
2246
2331
  fail,
2247
2332
  firstN,
2248
2333
  fragment,
@@ -2251,19 +2336,23 @@ export {
2251
2336
  getFragmentData,
2252
2337
  getModelsRegistry,
2253
2338
  getReminderRanges,
2339
+ getSeason,
2254
2340
  glossary,
2255
2341
  guardrail,
2256
2342
  hint,
2343
+ hourChanged,
2257
2344
  identity,
2258
2345
  isConditionalReminder,
2259
2346
  isFragment,
2260
2347
  isFragmentObject,
2261
2348
  isLazyFragment,
2262
2349
  isMessageFragment,
2350
+ isRecord,
2263
2351
  lastAssistantMessage,
2264
2352
  mergeMessageMetadata,
2265
2353
  mergeReminderMetadata,
2266
2354
  message,
2355
+ monthChanged,
2267
2356
  not,
2268
2357
  once,
2269
2358
  or,
@@ -2280,6 +2369,7 @@ export {
2280
2369
  resolveReminderText,
2281
2370
  role,
2282
2371
  runGuardrailChain,
2372
+ seasonChanged,
2283
2373
  soul,
2284
2374
  stop,
2285
2375
  stripReminders,
@@ -2289,6 +2379,8 @@ export {
2289
2379
  toFragment,
2290
2380
  user,
2291
2381
  visualizeGraph,
2292
- workflow
2382
+ weekChanged,
2383
+ workflow,
2384
+ yearChanged
2293
2385
  };
2294
2386
  //# sourceMappingURL=browser.js.map