wirejs-deploy-amplify-basic 0.1.162-llm → 0.1.164

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.
@@ -1,3 +1,4 @@
1
+ import fs from 'fs';
1
2
  import path from 'path';
2
3
  import { randomUUID } from 'crypto';
3
4
  import {
@@ -14,7 +15,7 @@ import { Bucket, BlockPublicAccess } from 'aws-cdk-lib/aws-s3';
14
15
  import { Table, AttributeType, BillingMode } from 'aws-cdk-lib/aws-dynamodb';
15
16
  import { AnyPrincipal, PolicyStatement } from 'aws-cdk-lib/aws-iam';
16
17
 
17
- import { TableDefinition, indexName } from 'wirejs-resources';
18
+ import { TableDefinition, indexName, DeploymentConfig } from 'wirejs-resources';
18
19
  import { TableIndexes } from './constructs/table-indexes';
19
20
  import { RealtimeService } from './constructs/realtime-service';
20
21
  import { auth } from './auth/resource';
@@ -22,13 +23,14 @@ import { auth } from './auth/resource';
22
23
  // @ts-ignore
23
24
  import generatedResources from './generated-resources';
24
25
  import { copyFileSync } from 'fs';
25
- import { cwd } from 'process';
26
+ import { config, cwd } from 'process';
26
27
 
27
28
  const __filename = import.meta.url.replace(/^file:/, '');
28
29
  const __dirname = path.dirname(__filename);
29
30
 
30
31
  const generated: any[] = generatedResources;
31
32
 
33
+ const CONFIG_PATH = path.join(cwd(), 'deployment-config.ts');
32
34
  const APP_ID = process.env.AWS_APP_ID ?? process.env.PWD?.replace(/[^a-zA-Z0-9-_]/g, '_');
33
35
  const BRANCH_ID = process.env.AWS_BRANCH ?? process.env.USER ?? 'anonymous';
34
36
  const TABLE_NAME_PREFIX = `${APP_ID}-${BRANCH_ID}-`;
@@ -49,19 +51,31 @@ copyFileSync(
49
51
  path.join(cwd(), 'api', 'wirejs-handler.ts')
50
52
  );
51
53
 
54
+ let cfg: DeploymentConfig = {};
55
+ if (fs.existsSync(CONFIG_PATH)) {
56
+ cfg = (await import(CONFIG_PATH)).default as DeploymentConfig;
57
+ console.log("\nDeployment config found: ", JSON.stringify(cfg), "\n");
58
+ } else {
59
+ console.log('\nNo deployment config found. Using defaults.\n')
60
+ }
61
+
52
62
  const api = new NodejsFunction(backend.stack, 'ApiHandler', {
53
- runtime: Runtime.NODEJS_22_X,
54
- memorySize: 2 * 1024,
63
+ runtime: {
64
+ 20: Runtime.NODEJS_20_X,
65
+ 22: Runtime.NODEJS_22_X,
66
+ 24: Runtime.NODEJS_24_X,
67
+ }[cfg.runtimeNodeVersion ?? 24],
68
+ memorySize: cfg.runtimeDesiredMemoryMB ?? 2 * 1024,
55
69
  handler: 'handler',
56
70
  entry: path.join(cwd(), 'api', 'wirejs-handler.ts'),
57
71
  bundling: {
58
- nodeModules: ['jsdom'],
59
- format: OutputFormat.CJS,
60
- minify: false,
61
- sourceMap: true,
72
+ nodeModules: cfg.bundleNodeModules ?? ['jsdom'],
73
+ format: cfg.bundleFormat === 'esm' ? OutputFormat.ESM : OutputFormat.CJS,
74
+ minify: Boolean(cfg.bundleMinify),
75
+
62
76
  },
63
77
  depsLockFilePath: path.join(cwd(), 'package-lock.json'),
64
- timeout: Duration.minutes(15)
78
+ timeout: Duration.seconds(cfg.runtimeTimeoutSeconds ?? 15 * 60),
65
79
  });
66
80
 
67
81
  /**
@@ -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.162-llm"
6
+ "wirejs-resources": "^0.1.164"
7
7
  }
8
8
  }
@@ -9,6 +9,7 @@ export declare class LLM extends BaseLLM {
9
9
  });
10
10
  private createBedrockInstructionMessage;
11
11
  private convertToBedrockFormat;
12
+ private getModelAliases;
12
13
  private getModelId;
13
14
  private invokeBedrock;
14
15
  private streamBedrock;
@@ -53,19 +53,37 @@ export class LLM extends BaseLLM {
53
53
  }
54
54
  });
55
55
  }
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'
56
+ getModelAliases() {
57
+ return {
58
+ // Anthropic Claude
59
+ 'anthropic.claude-3-5-sonnet-20241022-v2:0': ['claude', 'claude-3.5-sonnet'],
60
+ 'anthropic.claude-3-sonnet-20240229-v1:0': ['claude-3-sonnet'],
61
+ 'anthropic.claude-3-5-haiku-20241022-v1:0': ['claude-3.5-haiku'],
62
+ 'anthropic.claude-3-haiku-20240307-v1:0': ['claude-3-haiku'],
63
+ 'anthropic.claude-3-opus-20240229-v1:0': ['claude-3-opus'],
64
+ // Meta Llama
65
+ 'meta.llama3-2-90b-instruct-v1:0': ['llama3.2'],
66
+ 'meta.llama3-2-8b-instruct-v1:0': ['llama3.2-8b'],
67
+ 'meta.llama3-1-405b-instruct-v1:0': ['llama3.1'],
68
+ 'meta.llama3-70b-instruct-v1:0': ['llama3'],
69
+ // Mistral
70
+ 'mistral.mistral-large-2407-v1:0': ['mistral-large', 'mistral'],
71
+ 'mistral.mistral-7b-instruct-v0:2': ['mistral-7b'],
72
+ // Amazon Nova (newer)
73
+ 'amazon.nova-pro-v1:0': ['nova-pro'],
74
+ 'amazon.nova-lite-v1:0': ['nova-lite'],
75
+ 'amazon.nova-micro-v1:0': ['nova-micro']
67
76
  };
68
- return modelMap[model] || model;
77
+ }
78
+ getModelId(model) {
79
+ const normalized = model.trim().toLowerCase();
80
+ const modelAliases = this.getModelAliases();
81
+ for (const [canonicalModelId, aliases] of Object.entries(modelAliases)) {
82
+ if (normalized === canonicalModelId || aliases.includes(normalized)) {
83
+ return canonicalModelId;
84
+ }
85
+ }
86
+ return model;
69
87
  }
70
88
  async invokeBedrock(modelId, systemPrompt, messages, stream, tools, abortSignal) {
71
89
  const toolConfig = tools && tools.length > 0 ? {
@@ -237,15 +255,16 @@ export class LLM extends BaseLLM {
237
255
  async continueConversation({ history, onChunk, timeoutSeconds, systemPrompt, models, tools, }) {
238
256
  const controller = new AbortController();
239
257
  let timeoutId;
258
+ const intendedModels = models ?? this.models;
240
259
  if (timeoutSeconds) {
241
260
  timeoutId = setTimeout(() => {
242
261
  controller.abort();
243
262
  }, timeoutSeconds * 1000);
244
263
  }
245
264
  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) {
265
+ // models are expected to be given in priority order.
266
+ // first one that doesn't throw a fit wins.
267
+ for (const model of intendedModels) {
249
268
  try {
250
269
  const result = await this.invokeModel(model, (systemPrompt ?? this.systemPrompt) ?? '', history, onChunk, controller.signal, tools ?? this.tools);
251
270
  if (!result)
@@ -279,13 +298,14 @@ export class LLM extends BaseLLM {
279
298
  if (timeoutId) {
280
299
  clearTimeout(timeoutId);
281
300
  }
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` +
301
+ const message = this.createBedrockInstructionMessage(`None of the attempted models are suitable for this request. ` +
302
+ `Review CloudWatch logs to see the reason why. If necessary:\n\n` +
284
303
  `1. Go to AWS Bedrock Console (https://console.aws.amazon.com/bedrock/)\n` +
285
304
  `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`);
305
+ `3. Request access to and accept the model's End User License Agreement (EULA)\n\n` +
306
+ `Models attempted: ${intendedModels.join(', ')}\n\n` +
307
+ `Note: The following friendly aliases are available:\n` +
308
+ `${Object.entries(this.getModelAliases()).map(([name, aliases]) => `${name}: ${aliases.join(', ')}`).join('\n')}`);
289
309
  if (onChunk) {
290
310
  try {
291
311
  await onChunk({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wirejs-deploy-amplify-basic",
3
- "version": "0.1.162-llm",
3
+ "version": "0.1.164",
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.162-llm"
47
+ "wirejs-resources": "^0.1.164"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@aws-amplify/backend": "^1.14.0",