fawn-memory 0.0.3 → 0.0.6

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.
@@ -0,0 +1,25 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ export type DateVal = {
5
+ day: number;
6
+ month: number;
7
+ year: number;
8
+ };
9
+
10
+ export type TimeVal = {
11
+ // In 24 hour form
12
+ hour: number;
13
+ minute: number;
14
+ seconds: number;
15
+ };
16
+
17
+ export type DateTime = {
18
+ date: DateVal;
19
+ time?: TimeVal | undefined;
20
+ };
21
+
22
+ export type DateTimeRange = {
23
+ startDate: DateTime;
24
+ stopDate?: DateTime | undefined;
25
+ };
@@ -1,17 +1,67 @@
1
- import type { TypeChatLanguageModel } from 'typechat';
2
- export type LLMProviderType = 'openai' | 'claude';
1
+ import type { TypeChatLanguageModel, PromptSection, Result } from 'typechat';
2
+ import { success, error } from 'typechat';
3
+ export type { TypeChatLanguageModel, PromptSection, Result };
4
+ export { success, error };
5
+ /**
6
+ * Built-in provider types. Custom providers can use any string.
7
+ */
8
+ export type BuiltInLLMProviderType = 'openai' | 'claude';
3
9
  export interface LLMProviderConfig {
4
- provider: LLMProviderType;
5
- apiKey: string;
10
+ provider: string;
11
+ apiKey?: string;
6
12
  model?: string;
7
13
  }
14
+ /**
15
+ * LLM Provider interface.
16
+ * Implement this interface to create custom LLM providers.
17
+ */
8
18
  export interface LLMProvider {
9
- readonly name: LLMProviderType;
19
+ readonly name: string;
10
20
  readonly model: string;
11
21
  getLanguageModel(): TypeChatLanguageModel;
12
22
  }
23
+ /**
24
+ * Creates an OpenAI LLM provider.
25
+ */
13
26
  export declare function createOpenAIProvider(apiKey: string, model?: string): LLMProvider;
27
+ /**
28
+ * Helper function to extract string content from a PromptSection.
29
+ * Useful for custom provider implementations.
30
+ */
31
+ export declare function getContentAsString(content: PromptSection['content']): string;
32
+ /**
33
+ * Creates a Claude/Anthropic LLM provider.
34
+ */
14
35
  export declare function createClaudeProvider(apiKey: string, model?: string): LLMProvider;
36
+ /**
37
+ * Creates a built-in LLM provider based on configuration.
38
+ * For custom providers, implement the LLMProvider interface directly.
39
+ */
15
40
  export declare function createLLMProvider(config: LLMProviderConfig): LLMProvider;
41
+ /**
42
+ * Creates a built-in LLM provider from environment variables.
43
+ * For custom providers, implement the LLMProvider interface directly.
44
+ *
45
+ * Environment variables:
46
+ * LLM_PROVIDER: 'openai' | 'claude' (default: 'openai')
47
+ * LLM_MODEL: Model name override (optional)
48
+ *
49
+ * For OpenAI:
50
+ * OPENAI_API_KEY or OPENAI_SDK_KEY: API key
51
+ *
52
+ * For Claude:
53
+ * ANTHROPIC_API_KEY: API key
54
+ */
16
55
  export declare function createLLMProviderFromEnv(): LLMProvider;
56
+ /**
57
+ * Creates a custom TypeChatLanguageModel with default retry settings.
58
+ * Use this helper when implementing custom LLM providers.
59
+ *
60
+ * @param completeFn - The completion function that calls your LLM
61
+ * @param options - Optional retry configuration
62
+ */
63
+ export declare function createCustomLanguageModel(completeFn: (prompt: string | PromptSection[]) => Promise<Result<string>>, options?: {
64
+ retryMaxAttempts?: number;
65
+ retryPauseMs?: number;
66
+ }): TypeChatLanguageModel;
17
67
  //# sourceMappingURL=llmProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"llmProvider.d.ts","sourceRoot":"","sources":["../../src/knowpro/llmProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAyB,MAAM,UAAU,CAAC;AAG7E,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAElD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,M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GAAG,MAAM,CAa5E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,KAAK,GAAE,MAAmC,GACzC,WAAW,CA0Db;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW,CAexE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,IAAI,WAAW,CAgBtD;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EACzE,OAAO,CAAC,EAAE;IACR,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACA,qBAAqB,CAMvB"}
@@ -1,5 +1,9 @@
1
1
  import Anthropic from '@anthropic-ai/sdk';
2
2
  import { createOpenAILanguageModel, success, error } from 'typechat';
3
+ export { success, error };
4
+ /**
5
+ * Creates an OpenAI LLM provider.
6
+ */
3
7
  export function createOpenAIProvider(apiKey, model = 'gpt-4o') {
4
8
  const languageModel = createOpenAILanguageModel(apiKey, model);
5
9
  return {
@@ -8,7 +12,11 @@ export function createOpenAIProvider(apiKey, model = 'gpt-4o') {
8
12
  getLanguageModel: () => languageModel
9
13
  };
10
14
  }
11
- function getContentAsString(content) {
15
+ /**
16
+ * Helper function to extract string content from a PromptSection.
17
+ * Useful for custom provider implementations.
18
+ */
19
+ export function getContentAsString(content) {
12
20
  if (typeof content === 'string') {
13
21
  return content;
14
22
  }
@@ -22,6 +30,9 @@ function getContentAsString(content) {
22
30
  return '';
23
31
  }).join('');
24
32
  }
33
+ /**
34
+ * Creates a Claude/Anthropic LLM provider.
35
+ */
25
36
  export function createClaudeProvider(apiKey, model = 'claude-sonnet-4-20250514') {
26
37
  const client = new Anthropic({ apiKey });
27
38
  const languageModel = {
@@ -77,18 +88,43 @@ export function createClaudeProvider(apiKey, model = 'claude-sonnet-4-20250514')
77
88
  getLanguageModel: () => languageModel
78
89
  };
79
90
  }
91
+ /**
92
+ * Creates a built-in LLM provider based on configuration.
93
+ * For custom providers, implement the LLMProvider interface directly.
94
+ */
80
95
  export function createLLMProvider(config) {
81
96
  switch (config.provider) {
82
97
  case 'openai':
98
+ if (!config.apiKey) {
99
+ throw new Error('OpenAI provider requires apiKey');
100
+ }
83
101
  return createOpenAIProvider(config.apiKey, config.model);
84
102
  case 'claude':
103
+ if (!config.apiKey) {
104
+ throw new Error('Claude provider requires apiKey');
105
+ }
85
106
  return createClaudeProvider(config.apiKey, config.model);
86
107
  default:
87
- throw new Error(`Unknown provider: ${config.provider}`);
108
+ throw new Error(`Unknown built-in provider: ${config.provider}. For custom providers, implement LLMProvider directly.`);
88
109
  }
89
110
  }
111
+ /**
112
+ * Creates a built-in LLM provider from environment variables.
113
+ * For custom providers, implement the LLMProvider interface directly.
114
+ *
115
+ * Environment variables:
116
+ * LLM_PROVIDER: 'openai' | 'claude' (default: 'openai')
117
+ * LLM_MODEL: Model name override (optional)
118
+ *
119
+ * For OpenAI:
120
+ * OPENAI_API_KEY or OPENAI_SDK_KEY: API key
121
+ *
122
+ * For Claude:
123
+ * ANTHROPIC_API_KEY: API key
124
+ */
90
125
  export function createLLMProviderFromEnv() {
91
126
  const provider = (process.env.LLM_PROVIDER || 'openai');
127
+ const model = process.env.LLM_MODEL;
92
128
  let apiKey;
93
129
  if (provider === 'claude') {
94
130
  apiKey = process.env.ANTHROPIC_API_KEY;
@@ -96,10 +132,23 @@ export function createLLMProviderFromEnv() {
96
132
  else {
97
133
  apiKey = process.env.OPENAI_API_KEY || process.env.OPENAI_SDK_KEY;
98
134
  }
99
- const model = process.env.LLM_MODEL;
100
135
  if (!apiKey) {
101
136
  throw new Error(`Missing API key for provider: ${provider}`);
102
137
  }
103
138
  return createLLMProvider({ provider, apiKey, model });
104
139
  }
140
+ /**
141
+ * Creates a custom TypeChatLanguageModel with default retry settings.
142
+ * Use this helper when implementing custom LLM providers.
143
+ *
144
+ * @param completeFn - The completion function that calls your LLM
145
+ * @param options - Optional retry configuration
146
+ */
147
+ export function createCustomLanguageModel(completeFn, options) {
148
+ return {
149
+ retryMaxAttempts: options?.retryMaxAttempts ?? 3,
150
+ retryPauseMs: options?.retryPauseMs ?? 1000,
151
+ complete: completeFn,
152
+ };
153
+ }
105
154
  //# sourceMappingURL=llmProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"llmProvider.js","sourceRoot":"","sources":["../../src/knowpro/llmProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAgBrE,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,QAAgB,QAAQ;IAExB,MAAM,aAAa,GAAG,yBAAyB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,KAAK;QACL,gBAAgB,EAAE,GAAG,EAAE,CAAC,aAAa;KACtC,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAiC;IAC3D,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;QACrB,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC1B,OAAO,CAAC,CAAC;QACX,CAAC;QACD,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO,CAAC,CAAC,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,QAAgB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;AACH,MAAM,UAAU,yBAAyB,CACvC,UAAyE,EACzE,OAGC;IAED,OAAO;QACL,gBAAgB,EAAE,OAAO,EAAE,gBAAgB,IAAI,CAAC;QAChD,YAAY,EAAE,OAAO,EAAE,YAAY,IAAI,IAAI;QAC3C,QAAQ,EAAE,UAAU;KACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,92 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+
4
+ import type { DateTimeRange } from "./dateTimeSchema.js";
5
+
6
+ export type FacetTerm = {
7
+ // the name of the facet, such as "color", "profession", "patent number"; "*" means match any facet name
8
+ facetName: string;
9
+ // the value of the facet, such as "red", "writer"; "*" means match any facet value
10
+ facetValue: string;
11
+ };
12
+
13
+ // Use to find information about specific, tangible people, places, institutions or things only..
14
+ // This includes entities with particular facets
15
+ // Abstract concepts or topics are not entityTerms. Use string for them
16
+ // Any terms will match fuzzily.
17
+ export type EntityTerm = {
18
+ // the name of the entity or thing such as "Bach", "Great Gatsby", "frog" or "piano" or "we", "I"; "*" means match any entity name
19
+ name: string;
20
+ isNamePronoun: boolean;
21
+ // the specific types of the entity such as "book", "movie", "song", "speaker", "person", "artist", "animal", "instrument", "school", "room", "museum", "food" etc.
22
+ // Generic types like "object", "thing" etc. are NOT allowed
23
+ // An entity can have multiple types; entity types should be single words
24
+ type?: string[];
25
+ // Facet terms search for properties or attributes of the entity.
26
+ // Eg: color(blue), profession(writer), author(*), aunt(Agatha), weight(4kg), phoneNumber(...), etc.
27
+ facets?: FacetTerm[];
28
+ };
29
+
30
+ // Use for action verbs only. Ensure nouns are not misinterpreted as verbs
31
+ export type VerbsTerm = {
32
+ words: string[]; // individual words in single verb or compound verb
33
+ tense: "Past" | "Present" | "Future";
34
+ };
35
+
36
+ export type ActionTerm = {
37
+ // Action verbs describing the interaction
38
+ actionVerbs?: VerbsTerm | undefined;
39
+ // The origin of the action or information, typically the entity performing the action
40
+ actorEntities: EntityTerm[] | "*";
41
+ // the recipient or target of the action or information
42
+ // Action verbs can imply relevant facet names on the targetEntity. E.g. write -> writer, sing -> singer etc.
43
+ targetEntities?: EntityTerm[];
44
+ // additional entities participating in the action.
45
+ // E.g. in the phrase "Jane ate the spaghetti with the fork", "the fork" would be an additional entity
46
+ // E.g. in the phrase "Did Jane speak about Bach with Nina", "Bach" would be the additional entity
47
+ additionalEntities?: EntityTerm[];
48
+ // Is the intent of the phrase translated to this ActionTerm to actually get information about a specific entities?
49
+ // Examples:
50
+ // true: if asking for specific information about an entity, such as "What did Mia say her phone number was?"
51
+ // false if involves actions and interactions between entities, such as "What phone number did Mia mention in her note to Jane?"
52
+ isInformational: boolean;
53
+ };
54
+
55
+ export type ScopeFilter = {
56
+ // Search terms to use to limit search
57
+ entitySearchTerms?: EntityTerm[] | undefined;
58
+ // Use only if request explicitly asks for time range, particular year, month etc.
59
+ timeRange?: DateTimeRange | undefined; // in this time range
60
+ };
61
+
62
+ //
63
+ // Search a search engine using filters:
64
+ // entitySearchTerms cannot contain entities already in actionSearchTerms
65
+ export type SearchFilter = {
66
+ // Use actionSearchTerm for queries involving actions and interactions between entities.
67
+ actionSearchTerm?: ActionTerm;
68
+ // Use entitySearchTerms for queries asking for specific information about entities and their attributes.
69
+ // E.g. "What is Mia's phone number?" or "Where did Jane study?"
70
+ entitySearchTerms?: EntityTerm[];
71
+ // searchTerms:
72
+ // Concepts, topics or other terms that don't fit (or are not already handled by) ActionTerms or EntityTerms.
73
+ // - Do not use noisy searchTerms like "topic", "topics", "subject", "discussion" etc. even if they are mentioned in the user request
74
+ // - Phrases like 'email address' or 'first name' are a single term
75
+ // - use empty searchTerms array when use asks for summaries
76
+ searchTerms?: string[];
77
+ // Use to limit matches to particular sub-set of a conversation, document, etc
78
+ // E.g. if the user request specifies a particular section or context, use scopeSubQuery to limit the search.
79
+ scopeSubQuery?: ScopeFilter | undefined;
80
+ };
81
+
82
+ export type SearchExpr = {
83
+ rewrittenQuery: string;
84
+ // Translate rewritten query into filters
85
+ filters: SearchFilter[];
86
+ };
87
+
88
+ export type SearchQuery = {
89
+ // One expression for each search required by user request
90
+ // Each SearchExpr runs independently, so make them standalone by resolving references like 'it', 'that', 'them' etc.
91
+ searchExpressions: SearchExpr[];
92
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fawn-memory",
3
- "version": "0.0.3",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "dist"
11
11
  ],
12
12
  "scripts": {
13
- "build": "tsc -p tsconfig.build.json",
13
+ "build": "tsc -p tsconfig.build.json && shx cp src/knowpro/dateTimeSchema.ts src/knowpro/searchQuerySchema.ts dist/knowpro/",
14
14
  "dev": "tsx src/index.ts",
15
15
  "lint": "eslint .",
16
16
  "clean": "rimraf dist",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a",
25
25
  "devDependencies": {
26
+ "shx": "^0.3.4",
26
27
  "@eslint/js": "^9.39.2",
27
28
  "@types/node": "^25.0.2",
28
29
  "@typescript-eslint/eslint-plugin": "^8.50.0",