wirejs-deploy-amplify-basic 0.1.163-llm → 0.1.165

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.
@@ -51,6 +51,10 @@ function createContext(event: APIGatewayProxyEventV2) {
51
51
  description: 'HTTP origin (base address) for machines outside your network to use. Only populated for `npm run start:public`, and only accessible in environments that support NAT-PMP.',
52
52
  value: location.origin
53
53
  }),
54
+ new SystemAttribute('wirejs', 'aws-region', {
55
+ description: 'AWS region where the application is deployed.',
56
+ value: env.AWS_REGION || 'unknown'
57
+ }),
54
58
  ]
55
59
  });
56
60
  } catch {
@@ -3,6 +3,6 @@
3
3
  "dependencies": {
4
4
  "jsdom": "^25.0.1",
5
5
  "wirejs-dom": "^1.0.44",
6
- "wirejs-resources": "^0.1.163-llm"
6
+ "wirejs-resources": "^0.1.165"
7
7
  }
8
8
  }
package/build.js CHANGED
@@ -103,64 +103,6 @@ async function discoverResources() {
103
103
  );
104
104
  }
105
105
 
106
- // /**
107
- // *
108
- // * @returns {string[]}
109
- // */
110
- // function discoverApiDeps() {
111
- // return execSync(`npm ls --omit=dev --all --parseable -w ./api`)
112
- // .toString()
113
- // .split('\n')
114
- // .map(line => line.trim())
115
- // .filter(line => line.includes('node_modules'));
116
- // }
117
-
118
- // async function installApiDeps() {
119
- // console.log("adding deps to package.json");
120
- // // add deps used by Amplify to deploy backend
121
- // const packageData = JSON.parse(
122
- // await fs.promises.readFile(path.join(LAMBDA_BUILD_DIR, 'package.json'))
123
- // );
124
- // packageData.dependencies = {
125
- // 'jose': '^6.1.0',
126
- // ...(packageData.dependencies || {}),
127
- // 'wirejs-resources': `file:${SELF_DIR}`
128
- // };
129
- // await fs.promises.writeFile(
130
- // path.join(LAMBDA_BUILD_DIR, 'package.json'),
131
- // JSON.stringify(packageData, null, 2)
132
- // );
133
-
134
- // console.log("installing all deps")
135
-
136
- // // install all
137
- // execSync('npm i');
138
-
139
- // console.log("done installing deps");
140
- // }
141
-
142
- // /**
143
- // *
144
- // * @param {string[]} deps
145
- // */
146
- // async function prepareApiLambda(deps) {
147
- // await copy
148
- // (path.join(CWD, 'api', 'dist'),
149
- // path.join(LAMBDA_BUILD_DIR, 'dist')
150
- // );
151
- // await copy(
152
- // path.join(CWD, 'api', 'dist', 'package.json'),
153
- // path.join(LAMBDA_BUILD_DIR, 'dist', 'package.json')
154
- // );
155
-
156
- // buildSync({
157
- // entryPoints: path.join(LAMBDA_BUILD_DIR, 'handler.ts'),
158
- // bundle: true,
159
- // packages: 'external',
160
- // outfile: 'handler.js',
161
- // });
162
- // }
163
-
164
106
  async function deployFrontend() {
165
107
  console.log("copying frontend assets");
166
108
  await copy(PROJECT_DIST_DIR, STATIC_DIR);
@@ -9,6 +9,8 @@ export declare class LLM extends BaseLLM {
9
9
  });
10
10
  private createBedrockInstructionMessage;
11
11
  private convertToBedrockFormat;
12
+ private getModelAliases;
13
+ private getRegionalPrefix;
12
14
  private getModelId;
13
15
  private invokeBedrock;
14
16
  private streamBedrock;
@@ -1,6 +1,7 @@
1
1
  import { LLM as BaseLLM } from 'wirejs-resources';
2
2
  import { BedrockRuntimeClient, ConverseCommand, ConverseStreamCommand, } from '@aws-sdk/client-bedrock-runtime';
3
3
  import { defaultProvider } from '@aws-sdk/credential-provider-node';
4
+ import { env } from 'process';
4
5
  export class LLM extends BaseLLM {
5
6
  bedrockClient;
6
7
  constructor(scope, id, options) {
@@ -53,19 +54,60 @@ export class LLM extends BaseLLM {
53
54
  }
54
55
  });
55
56
  }
56
- getModelId(model) {
57
- // small set of convenience identifier aliases. maybe worth breaking out into
58
- // a larger, shared, canonical JSON later?
59
- const modelMap = {
60
- 'claude': 'anthropic.claude-3-haiku-20240307-v1:0',
61
- 'claude-haiku': 'anthropic.claude-3-haiku-20240307-v1:0',
62
- 'claude-sonnet': 'anthropic.claude-3-sonnet-20240229-v1:0',
63
- 'claude-opus': 'anthropic.claude-3-opus-20240229-v1:0',
64
- 'llama2': 'meta.llama2-70b-chat-v1',
65
- 'llama3': 'meta.llama3-70b-instruct-v1:0',
66
- 'llama3.2': 'meta.llama3-2-90b-instruct-v1:0'
57
+ getModelAliases() {
58
+ return {
59
+ // Anthropic Claude
60
+ 'anthropic.claude-3-5-sonnet-20241022-v2:0': ['claude', 'claude-3.5-sonnet'],
61
+ 'anthropic.claude-3-sonnet-20240229-v1:0': ['claude-3-sonnet'],
62
+ 'anthropic.claude-3-5-haiku-20241022-v1:0': ['claude-3.5-haiku'],
63
+ 'anthropic.claude-3-haiku-20240307-v1:0': ['claude-3-haiku'],
64
+ 'anthropic.claude-3-opus-20240229-v1:0': ['claude-3-opus'],
65
+ // Meta Llama
66
+ 'meta.llama3-2-90b-instruct-v1:0': ['llama3.2'],
67
+ 'meta.llama3-2-8b-instruct-v1:0': ['llama3.2-8b'],
68
+ 'meta.llama3-1-405b-instruct-v1:0': ['llama3.1'],
69
+ 'meta.llama3-70b-instruct-v1:0': ['llama3'],
70
+ // Mistral
71
+ 'mistral.mistral-large-2407-v1:0': ['mistral-large', 'mistral'],
72
+ 'mistral.mistral-7b-instruct-v0:2': ['mistral-7b'],
73
+ // Amazon Nova (newer)
74
+ 'amazon.nova-pro-v1:0': ['nova-pro'],
75
+ 'amazon.nova-lite-v1:0': ['nova-lite'],
76
+ 'amazon.nova-micro-v1:0': ['nova-micro']
67
77
  };
68
- return modelMap[model] || model;
78
+ }
79
+ getRegionalPrefix() {
80
+ const region = env.AWS_REGION || 'us-east-1';
81
+ if (region.startsWith('us-')) {
82
+ return 'us';
83
+ }
84
+ else if (region.startsWith('eu-')) {
85
+ return 'eu';
86
+ }
87
+ else if (region.startsWith('ap-')) {
88
+ return 'ap';
89
+ }
90
+ else if (region.startsWith('ca-')) {
91
+ return 'us'; // Canada uses US prefix
92
+ }
93
+ else if (region.startsWith('sa-')) {
94
+ return 'us'; // South America uses US prefix
95
+ }
96
+ // Default to US for unknown regions
97
+ return 'us';
98
+ }
99
+ getModelId(model) {
100
+ const normalized = model.trim().toLowerCase();
101
+ const modelAliases = this.getModelAliases();
102
+ for (const [canonicalModelId, aliases] of Object.entries(modelAliases)) {
103
+ if (normalized === canonicalModelId || aliases.includes(normalized)) {
104
+ const regionalPrefix = this.getRegionalPrefix();
105
+ return `${regionalPrefix}.${canonicalModelId}`;
106
+ }
107
+ }
108
+ // For unknown models, still apply regional prefix if it looks like a standard model ID
109
+ const regionalPrefix = this.getRegionalPrefix();
110
+ return `${regionalPrefix}.${model}`;
69
111
  }
70
112
  async invokeBedrock(modelId, systemPrompt, messages, stream, tools, abortSignal) {
71
113
  const toolConfig = tools && tools.length > 0 ? {
@@ -237,15 +279,16 @@ export class LLM extends BaseLLM {
237
279
  async continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, models, tools, }) {
238
280
  const controller = new AbortController();
239
281
  let timeoutId;
282
+ const intendedModels = models ?? this.models;
240
283
  if (timeoutSeconds) {
241
284
  timeoutId = setTimeout(() => {
242
285
  controller.abort();
243
286
  }, timeoutSeconds * 1000);
244
287
  }
245
288
  try {
246
- // models are expected to be given in priority order. first one that doesn't
247
- // throw a fit wins.
248
- for (const model of models ?? this.models) {
289
+ // models are expected to be given in priority order.
290
+ // first one that doesn't throw a fit wins.
291
+ for (const model of intendedModels) {
249
292
  try {
250
293
  const result = await this.invokeModel(model, (systemPrompt ?? this.systemPrompt) ?? '', history, onChunk, controller.signal, tools ?? this.tools);
251
294
  if (!result)
@@ -279,13 +322,14 @@ export class LLM extends BaseLLM {
279
322
  if (timeoutId) {
280
323
  clearTimeout(timeoutId);
281
324
  }
282
- const message = this.createBedrockInstructionMessage(`None of the attempted models are not available in your AWS account. ` +
283
- `Please enable it in the AWS Bedrock console:\n\n` +
325
+ const message = this.createBedrockInstructionMessage(`None of the attempted models are suitable for this request. ` +
326
+ `Review CloudWatch logs to see the reason why. If necessary:\n\n` +
284
327
  `1. Go to AWS Bedrock Console (https://console.aws.amazon.com/bedrock/)\n` +
285
328
  `2. Navigate to "Model access"\n` +
286
- `3. Request access to the model\n` +
287
- `4. Accept the End User License Agreement (EULA)\n\n` +
288
- `Available models attempted: ${this.models.join(', ')}\n`);
329
+ `3. Request access to and accept the model's End User License Agreement (EULA)\n\n` +
330
+ `Models attempted: ${intendedModels.join(', ')}\n\n` +
331
+ `Note: The following friendly aliases are available:\n` +
332
+ `${Object.entries(this.getModelAliases()).map(([name, aliases]) => `${name}: ${aliases.join(', ')}`).join('\n')}`);
289
333
  if (onChunk) {
290
334
  try {
291
335
  await onChunk({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.1.163-llm",
3
+ "version": "0.1.165",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -44,7 +44,7 @@
44
44
  "recursive-copy": "^2.0.14",
45
45
  "rimraf": "^6.0.1",
46
46
  "wirejs-dom": "^1.0.44",
47
- "wirejs-resources": "^0.1.163-llm"
47
+ "wirejs-resources": "^0.1.165"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@aws-amplify/backend": "^1.14.0",