triangle-utils 1.4.168 → 1.4.170

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,13 +1,13 @@
1
- declare const roles: readonly ["user", "assistant", "system"];
2
- export type Role = typeof roles[number];
3
- export declare function is_role(role: any): role is Role;
1
+ declare const message_roles: readonly ["user", "assistant", "system"];
2
+ export type MessageRole = typeof message_roles[number];
3
+ export declare function is_message_role(message_role: any): message_role is MessageRole;
4
4
  export declare class UtilsBedrock {
5
5
  private readonly bedrock_runtime;
6
6
  private readonly anthropic_bedrock_mantle;
7
7
  private readonly text_decoder;
8
8
  constructor(region: string);
9
9
  claude_converse(model_id: string, messages: {
10
- role: Role;
10
+ role: MessageRole;
11
11
  text: string;
12
12
  pdf?: string;
13
13
  }[], options?: {
@@ -15,10 +15,9 @@ export declare class UtilsBedrock {
15
15
  max_num_tokens?: number;
16
16
  verbosity?: number;
17
17
  json_format?: Record<string, any>;
18
- cache_period?: "5m" | "1h";
19
18
  }): Promise<string | undefined>;
20
19
  claude_invoke(model_id: string, messages: {
21
- role: Role;
20
+ role: MessageRole;
22
21
  text: string;
23
22
  pdf?: string;
24
23
  }[], options?: {
@@ -26,12 +25,7 @@ export declare class UtilsBedrock {
26
25
  max_num_tokens?: number;
27
26
  verbosity?: number;
28
27
  json_format?: Record<string, any>;
29
- web?: boolean;
30
- cache_period?: "5m" | "1h";
31
28
  }): Promise<string | undefined>;
32
- nova_invoke(model_id: string, prompt: string): Promise<string | undefined>;
33
- llama_invoke(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
34
- gpt_converse(model_id: string, prompt: string, temperature?: number, max_gen_len?: number, top_p?: number): Promise<string | undefined>;
35
29
  titan_invoke(text: string): Promise<number[] | undefined>;
36
30
  cohere_invoke(model_id: string, text: string, options?: {
37
31
  input_type_id?: string;
@@ -1,8 +1,8 @@
1
1
  import { BedrockRuntime } from "@aws-sdk/client-bedrock-runtime";
2
2
  import { AnthropicBedrockMantle } from "@anthropic-ai/bedrock-sdk";
3
- const roles = ["user", "assistant", "system"];
4
- export function is_role(role) {
5
- return roles.includes(role);
3
+ const message_roles = ["user", "assistant", "system"];
4
+ export function is_message_role(message_role) {
5
+ return message_roles.includes(message_role);
6
6
  }
7
7
  export class UtilsBedrock {
8
8
  bedrock_runtime;
@@ -33,8 +33,7 @@ export class UtilsBedrock {
33
33
  data: message.pdf
34
34
  },
35
35
  title: "Attachment",
36
- citations: { "enabled": false },
37
- cache_control: { "type": "ephemeral" }
36
+ citations: { "enabled": false }
38
37
  });
39
38
  }
40
39
  message_params.push({
@@ -97,8 +96,7 @@ export class UtilsBedrock {
97
96
  data: message.pdf
98
97
  },
99
98
  title: "Attachment",
100
- citations: { "enabled": false },
101
- cache_control: { "type": "ephemeral" }
99
+ citations: { "enabled": false }
102
100
  });
103
101
  }
104
102
  message_params.push({
@@ -145,91 +143,88 @@ export class UtilsBedrock {
145
143
  }
146
144
  return undefined;
147
145
  }
148
- async nova_invoke(model_id, prompt) {
149
- for (let i = 0; i < 3; i++) {
150
- try {
151
- const response = await this.bedrock_runtime.invokeModel({
152
- modelId: model_id,
153
- body: JSON.stringify({
154
- messages: [{
155
- role: "user",
156
- content: [{ text: prompt }]
157
- }]
158
- })
159
- });
160
- const body = JSON.parse(this.text_decoder.decode(response.body));
161
- return body.output.message.content[0].text;
162
- }
163
- catch (error) {
164
- if (error instanceof Error) {
165
- console.log(error.stack);
166
- }
167
- console.log("Failed to get from Bedrock.");
168
- }
169
- }
170
- console.log("Failed to get from Bedrock, quitting.");
171
- return undefined;
172
- }
173
- async llama_invoke(model_id, prompt, temperature = 0.5, max_gen_len = 512, top_p = 0.9) {
174
- for (let i = 0; i < 3; i++) {
175
- try {
176
- const output = await this.bedrock_runtime.invokeModel({
177
- modelId: model_id,
178
- body: JSON.stringify({
179
- prompt: prompt,
180
- temperature: temperature,
181
- top_p: top_p,
182
- max_gen_len: max_gen_len
183
- }),
184
- contentType: "application/json"
185
- });
186
- const response = JSON.parse(this.text_decoder.decode(output.body));
187
- return response.generation;
188
- }
189
- catch (error) {
190
- if (error instanceof Error) {
191
- console.log(error.stack);
192
- }
193
- console.log("Failed to get from Bedrock.");
194
- }
195
- }
196
- console.log("Failed to get from Bedrock, quitting.");
197
- return undefined;
198
- }
199
- async gpt_converse(model_id, prompt, temperature = 0.5, max_gen_len = 512, top_p = 0.9) {
200
- for (let i = 0; i < 3; i++) {
201
- try {
202
- const response = await this.bedrock_runtime.converse({
203
- modelId: model_id,
204
- messages: [
205
- { role: "user", content: [{ text: prompt }] }
206
- ],
207
- inferenceConfig: {
208
- temperature: temperature,
209
- topP: top_p,
210
- maxTokens: max_gen_len
211
- }
212
- });
213
- const output = response.output;
214
- if (output === undefined || output.message === undefined || output.message.content === undefined) {
215
- continue;
216
- }
217
- for (const c of output.message.content) {
218
- if (c.text !== undefined) {
219
- return c.text;
220
- }
221
- }
222
- }
223
- catch (error) {
224
- if (error instanceof Error) {
225
- console.log(error.stack);
226
- }
227
- console.log("Failed to get from Bedrock.");
228
- }
229
- }
230
- console.log("Failed to get from Bedrock, quitting.");
231
- return undefined;
232
- }
146
+ // async nova_invoke(model_id : string, prompt : string) : Promise<string | undefined> {
147
+ // for (let i = 0; i < 3; i++) {
148
+ // try {
149
+ // const response = await this.bedrock_runtime.invokeModel({
150
+ // modelId : model_id,
151
+ // body : JSON.stringify({
152
+ // messages : [{
153
+ // role : "user",
154
+ // content : [{ text : prompt }]
155
+ // }]
156
+ // })
157
+ // })
158
+ // const body = JSON.parse(this.text_decoder.decode(response.body))
159
+ // return body.output.message.content[0].text
160
+ // } catch (error) {
161
+ // if (error instanceof Error) {
162
+ // console.log(error.stack)
163
+ // }
164
+ // console.log("Failed to get from Bedrock.")
165
+ // }
166
+ // }
167
+ // console.log("Failed to get from Bedrock, quitting.")
168
+ // return undefined
169
+ // }
170
+ // async llama_invoke(model_id : string, prompt : string, temperature : number = 0.5, max_gen_len : number = 512, top_p : number = 0.9) : Promise<string | undefined> {
171
+ // for (let i = 0; i < 3; i++) {
172
+ // try {
173
+ // const output = await this.bedrock_runtime.invokeModel({
174
+ // modelId : model_id,
175
+ // body : JSON.stringify({
176
+ // prompt : prompt,
177
+ // temperature : temperature,
178
+ // top_p : top_p,
179
+ // max_gen_len : max_gen_len
180
+ // }),
181
+ // contentType : "application/json"
182
+ // })
183
+ // const response = JSON.parse(this.text_decoder.decode(output.body))
184
+ // return response.generation
185
+ // } catch (error) {
186
+ // if (error instanceof Error) {
187
+ // console.log(error.stack)
188
+ // }
189
+ // console.log("Failed to get from Bedrock.")
190
+ // }
191
+ // }
192
+ // console.log("Failed to get from Bedrock, quitting.")
193
+ // return undefined
194
+ // }
195
+ // async gpt_converse(model_id : string, prompt : string, temperature : number = 0.5, max_gen_len : number = 512, top_p : number = 0.9) : Promise<string | undefined> {
196
+ // for (let i = 0; i < 3; i++) {
197
+ // try {
198
+ // const response = await this.bedrock_runtime.converse({
199
+ // modelId : model_id,
200
+ // messages : [
201
+ // { role : "user", content : [ { text : prompt } ] }
202
+ // ],
203
+ // inferenceConfig : {
204
+ // temperature : temperature,
205
+ // topP : top_p,
206
+ // maxTokens : max_gen_len
207
+ // }
208
+ // })
209
+ // const output = response.output
210
+ // if (output === undefined || output.message === undefined || output.message.content === undefined) {
211
+ // continue
212
+ // }
213
+ // for (const c of output.message.content) {
214
+ // if (c.text !== undefined) {
215
+ // return c.text
216
+ // }
217
+ // }
218
+ // } catch (error) {
219
+ // if (error instanceof Error) {
220
+ // console.log(error.stack)
221
+ // }
222
+ // console.log("Failed to get from Bedrock.")
223
+ // }
224
+ // }
225
+ // console.log("Failed to get from Bedrock, quitting.")
226
+ // return undefined
227
+ // }
233
228
  async titan_invoke(text) {
234
229
  for (let i = 0; i < 3; i++) {
235
230
  try {
@@ -31,7 +31,7 @@ export class UtilsBrave {
31
31
  if (!Array.isArray(results)) {
32
32
  return undefined;
33
33
  }
34
- return body.results;
34
+ return results;
35
35
  }
36
36
  catch (error) {
37
37
  console.log("Failed to Brave:", error.stack);
@@ -66,7 +66,7 @@ export class UtilsBrave {
66
66
  if (!Array.isArray(results)) {
67
67
  return undefined;
68
68
  }
69
- return body.results;
69
+ return results;
70
70
  }
71
71
  catch (error) {
72
72
  console.log("Failed to Brave:", error.stack);
package/dist/src/f.js CHANGED
@@ -83,5 +83,21 @@ const utils = new TriangleUtils(config);
83
83
  // .then(response => console.log(response))
84
84
  // await utils.s3.get_download_url("s3://triangle-675045717295-us-east-1-an/tenant_documents/a3a9627f-a94d-4d47-a110-307a6f5563af/a146d789-da40-4e3c-a132-8b7110f3f7df.pdf", { name : "hye.pdf" })
85
85
  // .then(response => console.log(response))
86
- await utils.brave.web_search("press releases site:https://cohen.house.gov/", { min_date: "2026-09-03", max_date: "2026-09-05" })
87
- .then(console.log);
86
+ await utils.bedrock.claude_invoke("global.anthropic.claude-haiku-4-5-20251001-v1:0", [
87
+ {
88
+ role: "user",
89
+ text: "ayo"
90
+ }
91
+ ], {
92
+ json_format: {
93
+ type: "object",
94
+ properties: {
95
+ relevance: {
96
+ type: "string"
97
+ }
98
+ },
99
+ required: ["relevance"],
100
+ additionalProperties: false
101
+ },
102
+ verbosity: 5
103
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.4.168",
3
+ "version": "1.4.170",
4
4
  "main": "dist/src/index.js",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "directories": {
@@ -2,12 +2,12 @@ import { BedrockRuntime, InvokeModelCommandInput } from "@aws-sdk/client-bedrock
2
2
  import { AnthropicBedrockMantle } from "@anthropic-ai/bedrock-sdk"
3
3
  import { ContentBlockParam, MessageCreateParams, MessageParam, OutputConfig } from "@anthropic-ai/sdk/resources"
4
4
 
5
- const roles = ["user", "assistant", "system"] as const
5
+ const message_roles = ["user", "assistant", "system"] as const
6
6
 
7
- export type Role = typeof roles[number]
7
+ export type MessageRole = typeof message_roles[number]
8
8
 
9
- export function is_role(role : any) : role is Role {
10
- return roles.includes(role)
9
+ export function is_message_role(message_role : any) : message_role is MessageRole {
10
+ return message_roles.includes(message_role)
11
11
  }
12
12
 
13
13
  export class UtilsBedrock {
@@ -25,13 +25,12 @@ export class UtilsBedrock {
25
25
 
26
26
  async claude_converse(
27
27
  model_id : string,
28
- messages : { role : Role, text : string, pdf? : string }[],
28
+ messages : { role : MessageRole, text : string, pdf? : string }[],
29
29
  options : {
30
30
  system_prompt? : string,
31
31
  max_num_tokens? : number,
32
32
  verbosity? : number,
33
- json_format? : Record<string, any>,
34
- cache_period? : "5m" | "1h"
33
+ json_format? : Record<string, any>
35
34
  } = {}
36
35
  ) {
37
36
  const verbosity = options.verbosity || 0
@@ -53,8 +52,7 @@ export class UtilsBedrock {
53
52
  data: message.pdf
54
53
  },
55
54
  title: "Attachment",
56
- citations: { "enabled": false },
57
- cache_control: {"type": "ephemeral"}
55
+ citations: { "enabled" : false }
58
56
  })
59
57
  }
60
58
  message_params.push({
@@ -100,14 +98,12 @@ export class UtilsBedrock {
100
98
 
101
99
  async claude_invoke(
102
100
  model_id : string,
103
- messages : { role : Role, text : string, pdf? : string }[],
101
+ messages : { role : MessageRole, text : string, pdf? : string }[],
104
102
  options : {
105
103
  system_prompt? : string,
106
104
  max_num_tokens? : number,
107
105
  verbosity? : number,
108
- json_format? : Record<string, any>,
109
- web? : boolean,
110
- cache_period? : "5m" | "1h"
106
+ json_format? : Record<string, any>
111
107
  } = {}
112
108
  ) : Promise<string | undefined> {
113
109
  const verbosity = options.verbosity || 0
@@ -129,8 +125,7 @@ export class UtilsBedrock {
129
125
  data: message.pdf
130
126
  },
131
127
  title: "Attachment",
132
- citations: { "enabled": false },
133
- cache_control: {"type": "ephemeral"}
128
+ citations: { "enabled" : false }
134
129
  })
135
130
  }
136
131
  message_params.push({
@@ -177,90 +172,90 @@ export class UtilsBedrock {
177
172
  return undefined
178
173
  }
179
174
 
180
- async nova_invoke(model_id : string, prompt : string) : Promise<string | undefined> {
181
- for (let i = 0; i < 3; i++) {
182
- try {
183
- const response = await this.bedrock_runtime.invokeModel({
184
- modelId : model_id,
185
- body : JSON.stringify({
186
- messages : [{
187
- role : "user",
188
- content : [{ text : prompt }]
189
- }]
190
- })
191
- })
192
- const body = JSON.parse(this.text_decoder.decode(response.body))
193
- return body.output.message.content[0].text
194
- } catch (error) {
195
- if (error instanceof Error) {
196
- console.log(error.stack)
197
- }
198
- console.log("Failed to get from Bedrock.")
199
- }
200
- }
201
- console.log("Failed to get from Bedrock, quitting.")
202
- return undefined
203
- }
175
+ // async nova_invoke(model_id : string, prompt : string) : Promise<string | undefined> {
176
+ // for (let i = 0; i < 3; i++) {
177
+ // try {
178
+ // const response = await this.bedrock_runtime.invokeModel({
179
+ // modelId : model_id,
180
+ // body : JSON.stringify({
181
+ // messages : [{
182
+ // role : "user",
183
+ // content : [{ text : prompt }]
184
+ // }]
185
+ // })
186
+ // })
187
+ // const body = JSON.parse(this.text_decoder.decode(response.body))
188
+ // return body.output.message.content[0].text
189
+ // } catch (error) {
190
+ // if (error instanceof Error) {
191
+ // console.log(error.stack)
192
+ // }
193
+ // console.log("Failed to get from Bedrock.")
194
+ // }
195
+ // }
196
+ // console.log("Failed to get from Bedrock, quitting.")
197
+ // return undefined
198
+ // }
204
199
 
205
- async llama_invoke(model_id : string, prompt : string, temperature : number = 0.5, max_gen_len : number = 512, top_p : number = 0.9) : Promise<string | undefined> {
206
- for (let i = 0; i < 3; i++) {
207
- try {
208
- const output = await this.bedrock_runtime.invokeModel({
209
- modelId : model_id,
210
- body : JSON.stringify({
211
- prompt : prompt,
212
- temperature : temperature,
213
- top_p : top_p,
214
- max_gen_len : max_gen_len
215
- }),
216
- contentType : "application/json"
217
- })
218
- const response = JSON.parse(this.text_decoder.decode(output.body))
219
- return response.generation
220
- } catch (error) {
221
- if (error instanceof Error) {
222
- console.log(error.stack)
223
- }
224
- console.log("Failed to get from Bedrock.")
225
- }
226
- }
227
- console.log("Failed to get from Bedrock, quitting.")
228
- return undefined
229
- }
200
+ // async llama_invoke(model_id : string, prompt : string, temperature : number = 0.5, max_gen_len : number = 512, top_p : number = 0.9) : Promise<string | undefined> {
201
+ // for (let i = 0; i < 3; i++) {
202
+ // try {
203
+ // const output = await this.bedrock_runtime.invokeModel({
204
+ // modelId : model_id,
205
+ // body : JSON.stringify({
206
+ // prompt : prompt,
207
+ // temperature : temperature,
208
+ // top_p : top_p,
209
+ // max_gen_len : max_gen_len
210
+ // }),
211
+ // contentType : "application/json"
212
+ // })
213
+ // const response = JSON.parse(this.text_decoder.decode(output.body))
214
+ // return response.generation
215
+ // } catch (error) {
216
+ // if (error instanceof Error) {
217
+ // console.log(error.stack)
218
+ // }
219
+ // console.log("Failed to get from Bedrock.")
220
+ // }
221
+ // }
222
+ // console.log("Failed to get from Bedrock, quitting.")
223
+ // return undefined
224
+ // }
230
225
 
231
- async gpt_converse(model_id : string, prompt : string, temperature : number = 0.5, max_gen_len : number = 512, top_p : number = 0.9) : Promise<string | undefined> {
232
- for (let i = 0; i < 3; i++) {
233
- try {
234
- const response = await this.bedrock_runtime.converse({
235
- modelId : model_id,
236
- messages : [
237
- { role : "user", content : [ { text : prompt } ] }
238
- ],
239
- inferenceConfig : {
240
- temperature : temperature,
241
- topP : top_p,
242
- maxTokens : max_gen_len
243
- }
244
- })
245
- const output = response.output
246
- if (output === undefined || output.message === undefined || output.message.content === undefined) {
247
- continue
248
- }
249
- for (const c of output.message.content) {
250
- if (c.text !== undefined) {
251
- return c.text
252
- }
253
- }
254
- } catch (error) {
255
- if (error instanceof Error) {
256
- console.log(error.stack)
257
- }
258
- console.log("Failed to get from Bedrock.")
259
- }
260
- }
261
- console.log("Failed to get from Bedrock, quitting.")
262
- return undefined
263
- }
226
+ // async gpt_converse(model_id : string, prompt : string, temperature : number = 0.5, max_gen_len : number = 512, top_p : number = 0.9) : Promise<string | undefined> {
227
+ // for (let i = 0; i < 3; i++) {
228
+ // try {
229
+ // const response = await this.bedrock_runtime.converse({
230
+ // modelId : model_id,
231
+ // messages : [
232
+ // { role : "user", content : [ { text : prompt } ] }
233
+ // ],
234
+ // inferenceConfig : {
235
+ // temperature : temperature,
236
+ // topP : top_p,
237
+ // maxTokens : max_gen_len
238
+ // }
239
+ // })
240
+ // const output = response.output
241
+ // if (output === undefined || output.message === undefined || output.message.content === undefined) {
242
+ // continue
243
+ // }
244
+ // for (const c of output.message.content) {
245
+ // if (c.text !== undefined) {
246
+ // return c.text
247
+ // }
248
+ // }
249
+ // } catch (error) {
250
+ // if (error instanceof Error) {
251
+ // console.log(error.stack)
252
+ // }
253
+ // console.log("Failed to get from Bedrock.")
254
+ // }
255
+ // }
256
+ // console.log("Failed to get from Bedrock, quitting.")
257
+ // return undefined
258
+ // }
264
259
 
265
260
  async titan_invoke(text : string) : Promise<number[] | undefined> {
266
261
  for (let i = 0; i < 3; i++) {
package/src/UtilsBrave.ts CHANGED
@@ -38,7 +38,7 @@ export class UtilsBrave {
38
38
  if (!Array.isArray(results)) {
39
39
  return undefined
40
40
  }
41
- return body.results
41
+ return results
42
42
  } catch (error : any) {
43
43
  console.log("Failed to Brave:", error.stack)
44
44
  }
@@ -77,7 +77,7 @@ export class UtilsBrave {
77
77
  if (!Array.isArray(results)) {
78
78
  return undefined
79
79
  }
80
- return body.results
80
+ return results
81
81
  } catch (error : any) {
82
82
  console.log("Failed to Brave:", error.stack)
83
83
  }
package/src/f.ts CHANGED
@@ -107,5 +107,24 @@ const utils = new TriangleUtils(config)
107
107
  // .then(response => console.log(response))
108
108
 
109
109
 
110
- await utils.brave.web_search("press releases site:https://cohen.house.gov/", { min_date : "2026-09-03", max_date : "2026-09-05" })
111
- .then(console.log)
110
+ await utils.bedrock.claude_invoke("global.anthropic.claude-haiku-4-5-20251001-v1:0",
111
+ [
112
+ {
113
+ role : "user",
114
+ text : "ayo"
115
+ }
116
+ ],
117
+ {
118
+ json_format : {
119
+ type : "object",
120
+ properties : {
121
+ relevance : {
122
+ type : "string"
123
+ }
124
+ },
125
+ required : ["relevance"],
126
+ additionalProperties : false
127
+ },
128
+ verbosity : 5
129
+ }
130
+ )