|
| 1 | +package client |
| 2 | + |
| 3 | +import "time" |
| 4 | + |
| 5 | +type ResourceType struct { |
| 6 | + // ID is a generated ID for the resource type. |
| 7 | + ID string `json:"id"` |
| 8 | + |
| 9 | + // DisplayName is a freetext human-readable name for the resource type. |
| 10 | + DisplayName string `json:"display_name"` |
| 11 | + |
| 12 | + // Description is an optional freetext human-readable description of the resource type. |
| 13 | + Description string `json:"description"` |
| 14 | + |
| 15 | + // Scope determines when in the conversation the resource is fetched and used. |
| 16 | + Scope Scope `json:"scope"` |
| 17 | + |
| 18 | + // RefreshStrategy determines how often the resource is re-fetched. |
| 19 | + RefreshStrategy RefreshStrategy `json:"refresh_strategy"` |
| 20 | + |
| 21 | + // SourceConfig defines how the resource is fetched. If not set, the type can still be used in testing environments |
| 22 | + // with mocked data. |
| 23 | + SourceConfig *SourceConfig `json:"source_config,omitempty"` |
| 24 | + |
| 25 | + // Schema is the JSON schema for the resource type, optionally including attribute descriptions from the source if |
| 26 | + // IncludeDescriptions is true on read. |
| 27 | + Schema *Schema `json:"schema,omitempty"` |
| 28 | + |
| 29 | + // IsEnabled indicates whether the resource type has been configured as enabled or not. |
| 30 | + IsEnabled bool `json:"is_enabled"` |
| 31 | + |
| 32 | + Created time.Time `json:"created"` |
| 33 | + Updated time.Time `json:"updated"` |
| 34 | +} |
| 35 | +type SourceConfig struct { |
| 36 | + // SourceID identifies the source which should be used to fetch the resource data. |
| 37 | + SourceID string `json:"source_id"` |
| 38 | + |
| 39 | + // Attributes defines the *top-level* fields names to be used from the source data. Eg. for a payload like this: |
| 40 | + // |
| 41 | + // ``` |
| 42 | + // { |
| 43 | + // "id": 123, |
| 44 | + // "name": "foo", |
| 45 | + // "items": [ |
| 46 | + // { |
| 47 | + // "id": 1, |
| 48 | + // "name": "bar" |
| 49 | + // }, |
| 50 | + // { |
| 51 | + // "id": 2, |
| 52 | + // "name": "baz" |
| 53 | + // } |
| 54 | + // ], |
| 55 | + // "nested": { |
| 56 | + // "id": 456, |
| 57 | + // "name": "qux" |
| 58 | + // } |
| 59 | + // } |
| 60 | + // ``` |
| 61 | + // |
| 62 | + // The following attributes would be valid: |
| 63 | + // - "id" |
| 64 | + // - "name" |
| 65 | + // - "items" |
| 66 | + // - "nested" |
| 67 | + // The following attributes would be invalid: |
| 68 | + // - "items[*].id" |
| 69 | + // - "nested.id" |
| 70 | + Attributes []string `json:"attributes"` |
| 71 | + |
| 72 | + // Cache determines how long we'll consider data from the source be valid before refreshing it. It's either a |
| 73 | + // duration string (e.g. "5m") or CacheNever if the resource is refreshed on every turn. The default is 1 minute. |
| 74 | + Cache string `json:"cache"` |
| 75 | +} |
| 76 | + |
| 77 | +// CacheNever means the pull resource will be refreshed on every turn of the |
| 78 | +// conversation. |
| 79 | +const CacheNever = "never" |
| 80 | + |
| 81 | +type Scope string |
| 82 | + |
| 83 | +const ( |
| 84 | + // ScopeGlobal means the resource is available throughout the conversation and in all procedures. |
| 85 | + ScopeGlobal Scope = "global" |
| 86 | + |
| 87 | + // ScopeLocal means the resource is available only in procedures that explicitly use it, only fetched when it's used. |
| 88 | + ScopeLocal Scope = "local" |
| 89 | +) |
| 90 | + |
| 91 | +type RefreshStrategy string |
| 92 | + |
| 93 | +const ( |
| 94 | + // RefreshStrategyDynamic means the resource value can change, so this is re-fetched throughout the conversation. |
| 95 | + RefreshStrategyDynamic RefreshStrategy = "dynamic" |
| 96 | + |
| 97 | + // RefreshStrategyStatic means the resource is fetched once at the start of the conversation (global) or when it's first used in a procedure (local). |
| 98 | + RefreshStrategyStatic RefreshStrategy = "static" |
| 99 | +) |
0 commit comments