@agent-assistant/traits 0.1.0 → 0.1.1

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,2 @@
1
+ export type { AssistantTraits, SurfaceFormattingTraits, TraitsProvider, } from './types.js';
2
+ export { createTraitsProvider, TraitsValidationError } from './traits.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { createTraitsProvider, TraitsValidationError } from './traits.js';
@@ -0,0 +1,7 @@
1
+ import type { AssistantTraits, SurfaceFormattingTraits, TraitsField, TraitsProvider } from './types.js';
2
+ export declare class TraitsValidationError extends Error {
3
+ readonly field: TraitsField;
4
+ readonly invalidValue: unknown;
5
+ constructor(field: TraitsField, invalidValue: unknown, message: string);
6
+ }
7
+ export declare function createTraitsProvider(traits: AssistantTraits, surfaceFormatting?: SurfaceFormattingTraits): TraitsProvider;
package/dist/traits.js ADDED
@@ -0,0 +1,87 @@
1
+ const KNOWN_VOICES = new Set(['concise', 'conversational', 'formal', 'technical']);
2
+ const KNOWN_FORMALITY = new Set(['casual', 'professional', 'academic']);
3
+ const KNOWN_PROACTIVITY = new Set(['low', 'medium', 'high']);
4
+ const KNOWN_RISK_POSTURES = new Set(['cautious', 'moderate', 'assertive']);
5
+ export class TraitsValidationError extends Error {
6
+ field;
7
+ invalidValue;
8
+ constructor(field, invalidValue, message) {
9
+ super(message);
10
+ this.name = 'TraitsValidationError';
11
+ this.field = field;
12
+ this.invalidValue = invalidValue;
13
+ Object.setPrototypeOf(this, new.target.prototype);
14
+ }
15
+ }
16
+ function isNonEmptyString(value) {
17
+ return typeof value === 'string' && value.trim().length > 0;
18
+ }
19
+ function assertKnownStringValue(field, value, allowedValues) {
20
+ if (!isNonEmptyString(value) || !allowedValues.has(value)) {
21
+ throw new TraitsValidationError(field, value, `${field} must be one of: ${Array.from(allowedValues).map((entry) => `'${entry}'`).join(', ')}; got ${JSON.stringify(value)}`);
22
+ }
23
+ }
24
+ function validateAssistantTraits(traits) {
25
+ if (!isNonEmptyString(traits.voice)) {
26
+ throw new TraitsValidationError('voice', traits.voice, 'voice must be a non-empty string');
27
+ }
28
+ if (!KNOWN_VOICES.has(traits.voice)) {
29
+ console.warn(`Unknown assistant trait voice '${traits.voice}' accepted. Known values: ${Array.from(KNOWN_VOICES).join(', ')}`);
30
+ }
31
+ assertKnownStringValue('formality', traits.formality, KNOWN_FORMALITY);
32
+ assertKnownStringValue('proactivity', traits.proactivity, KNOWN_PROACTIVITY);
33
+ assertKnownStringValue('riskPosture', traits.riskPosture, KNOWN_RISK_POSTURES);
34
+ if (traits.domain !== undefined && !isNonEmptyString(traits.domain)) {
35
+ throw new TraitsValidationError('domain', traits.domain, 'domain must be a non-empty string when provided');
36
+ }
37
+ if (traits.vocabulary !== undefined) {
38
+ if (!Array.isArray(traits.vocabulary) || traits.vocabulary.length === 0) {
39
+ throw new TraitsValidationError('vocabulary', traits.vocabulary, 'vocabulary must be a non-empty array of non-empty strings when provided');
40
+ }
41
+ const hasInvalidEntry = traits.vocabulary.some((entry) => !isNonEmptyString(entry));
42
+ if (hasInvalidEntry) {
43
+ throw new TraitsValidationError('vocabulary', traits.vocabulary, 'vocabulary must contain only non-empty strings');
44
+ }
45
+ }
46
+ }
47
+ function validateSurfaceFormattingTraits(surfaceFormatting) {
48
+ if (surfaceFormatting.preferredResponseLength !== undefined
49
+ && (!Number.isInteger(surfaceFormatting.preferredResponseLength)
50
+ || surfaceFormatting.preferredResponseLength <= 0)) {
51
+ throw new TraitsValidationError('preferredResponseLength', surfaceFormatting.preferredResponseLength, 'preferredResponseLength must be a positive integer when provided');
52
+ }
53
+ if (surfaceFormatting.preferRichBlocks !== undefined
54
+ && typeof surfaceFormatting.preferRichBlocks !== 'boolean') {
55
+ throw new TraitsValidationError('preferRichBlocks', surfaceFormatting.preferRichBlocks, 'preferRichBlocks must be a boolean when provided');
56
+ }
57
+ if (surfaceFormatting.preferMarkdown !== undefined
58
+ && typeof surfaceFormatting.preferMarkdown !== 'boolean') {
59
+ throw new TraitsValidationError('preferMarkdown', surfaceFormatting.preferMarkdown, 'preferMarkdown must be a boolean when provided');
60
+ }
61
+ }
62
+ function freezeTraits(traits) {
63
+ const vocabulary = traits.vocabulary === undefined ? undefined : [...traits.vocabulary];
64
+ if (vocabulary !== undefined) {
65
+ Object.freeze(vocabulary);
66
+ }
67
+ return Object.freeze({
68
+ ...traits,
69
+ ...(vocabulary === undefined ? {} : { vocabulary }),
70
+ });
71
+ }
72
+ function freezeSurfaceFormatting(surfaceFormatting) {
73
+ return Object.freeze({ ...surfaceFormatting });
74
+ }
75
+ export function createTraitsProvider(traits, surfaceFormatting) {
76
+ validateAssistantTraits(traits);
77
+ if (surfaceFormatting !== undefined) {
78
+ validateSurfaceFormattingTraits(surfaceFormatting);
79
+ }
80
+ const provider = {
81
+ traits: freezeTraits(traits),
82
+ ...(surfaceFormatting === undefined
83
+ ? {}
84
+ : { surfaceFormatting: freezeSurfaceFormatting(surfaceFormatting) }),
85
+ };
86
+ return Object.freeze(provider);
87
+ }
@@ -0,0 +1,18 @@
1
+ export interface AssistantTraits {
2
+ voice: string;
3
+ formality: string;
4
+ proactivity: string;
5
+ riskPosture: string;
6
+ domain?: string;
7
+ vocabulary?: string[];
8
+ }
9
+ export interface SurfaceFormattingTraits {
10
+ preferredResponseLength?: number;
11
+ preferRichBlocks?: boolean;
12
+ preferMarkdown?: boolean;
13
+ }
14
+ export interface TraitsProvider {
15
+ readonly traits: Readonly<AssistantTraits>;
16
+ readonly surfaceFormatting?: Readonly<SurfaceFormattingTraits>;
17
+ }
18
+ export type TraitsField = keyof AssistantTraits | keyof SurfaceFormattingTraits;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-assistant/traits",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Validated immutable assistant traits for Agent Assistant SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",